| index e89cd4c..e56308a 100644 |
| --- a/internal/docs/brand/pointer.js |
| +++ b/internal/docs/brand/pointer.js |
| @@ -12,6 +12,12 @@ |
| pointer leaves, and every property has a default in the stylesheet, |
| so deleting this file and its tag leaves the still design. |
| |
| + A press throws a few sparks from where it landed, out of the same |
| + light: a handful of specks in a layer of their own over the page |
| + (so no control's overflow clips them and no layout moves), each |
| + animated once with the Web Animations API and removed when it ends. |
| + Pressing a rastrillo button sparks too. |
| + |
| It never runs for touch, under reduced motion or forced colours, or |
| without a hovering pointer; one animation frame per move at most. */ |
| (function () { |
| @@ -21,7 +27,9 @@ |
| var PROPS = ["--rst-mx", "--rst-my", "--docs-tx", "--docs-ty"]; |
| var quiet = [matchMedia("(prefers-reduced-motion: reduce)"), matchMedia("(forced-colors: active)")]; |
| var hover = matchMedia("(hover: hover)"); |
| - var lit = null, pending = null, raf = 0, listening = false; |
| + var PRESSED = LIT + ",[rst-btn]"; |
| + var SPARKS = 7; |
| + var lit = null, pending = null, raf = 0, listening = false, layer = null; |
| |
| function clear() { |
| if (!lit) return; |
| @@ -53,6 +61,34 @@ |
| function out(e) { |
| if (!e.relatedTarget) clear(); |
| } |
| + function spark(e) { |
| + if (e.button !== 0 || (e.pointerType && e.pointerType !== "mouse" && e.pointerType !== "pen")) return; |
| + var el = e.target && e.target.closest ? e.target.closest(PRESSED) : null; |
| + if (!el || el.disabled || !document.body.animate) return; |
| + if (!layer || !layer.isConnected) { |
| + layer = document.createElement("div"); |
| + layer.setAttribute("docs-sparks", ""); |
| + layer.setAttribute("aria-hidden", "true"); |
| + document.body.appendChild(layer); |
| + } |
| + for (var i = 0; i < SPARKS; i++) { |
| + var a = (i / SPARKS) * Math.PI * 2 + Math.random() * 0.7; |
| + var d = 16 + Math.random() * 16; |
| + var dot = document.createElement("span"); |
| + dot.style.left = e.clientX + "px"; |
| + dot.style.top = e.clientY + "px"; |
| + layer.appendChild(dot); |
| + var dx = (Math.cos(a) * d).toFixed(1), dy = (Math.sin(a) * d).toFixed(1); |
| + dot.animate([ |
| + { transform: "translate(-50%, -50%) scale(1)", opacity: 1 }, |
| + { transform: "translate(calc(-50% + " + dx * 0.55 + "px), calc(-50% + " + dy * 0.55 + "px)) scale(0.9)", opacity: 1, offset: 0.35 }, |
| + { transform: "translate(calc(-50% + " + dx + "px), calc(-50% + " + dy + "px)) scale(0.2)", opacity: 0 }, |
| + ], { duration: 480 + Math.random() * 220, easing: "cubic-bezier(.2, .65, .3, 1)" }).onfinish = remove(dot); |
| + } |
| + } |
| + function remove(dot) { |
| + return function () { dot.remove(); }; |
| + } |
| function sync() { |
| var want = hover.matches && !quiet[0].matches && !quiet[1].matches; |
| if (want === listening) return; |
| @@ -60,9 +96,11 @@ |
| if (want) { |
| document.addEventListener("pointermove", move, { passive: true }); |
| document.addEventListener("pointerout", out, { passive: true }); |
| + document.addEventListener("pointerdown", spark, { passive: true }); |
| } else { |
| document.removeEventListener("pointermove", move); |
| document.removeEventListener("pointerout", out); |
| + document.removeEventListener("pointerdown", spark); |
| clear(); |
| } |
| } |