use-scroll-animate 6.1.1 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/chunks/{base-Yno7N2eC.js → base-C_3cAoRz.js} +2 -2
- package/dist/chunks/{base-Yno7N2eC.js.map → base-C_3cAoRz.js.map} +1 -1
- package/dist/chunks/{core-CUGCsMsJ.js → core-VEBw36QK.js} +2 -2
- package/dist/chunks/{core-CUGCsMsJ.js.map → core-VEBw36QK.js.map} +1 -1
- package/dist/chunks/{core-BIOaYdgN.js → core-ps8uvYuN.js} +2 -2
- package/dist/chunks/{core-BIOaYdgN.js.map → core-ps8uvYuN.js.map} +1 -1
- package/dist/chunks/{fx-BqDeFywO.js → fx-Bs6IrV4Q.js} +2 -2
- package/dist/chunks/{fx-BqDeFywO.js.map → fx-Bs6IrV4Q.js.map} +1 -1
- package/dist/chunks/generative-D2YyhaeO.js +336 -0
- package/dist/chunks/generative-D2YyhaeO.js.map +1 -0
- package/dist/chunks/generative-DzIZq-_g.cjs +348 -0
- package/dist/chunks/generative-DzIZq-_g.cjs.map +1 -0
- package/dist/chunks/gpu-Bu7qwugO.js +380 -0
- package/dist/chunks/gpu-Bu7qwugO.js.map +1 -0
- package/dist/chunks/gpu-CenK2l6b.cjs +387 -0
- package/dist/chunks/gpu-CenK2l6b.cjs.map +1 -0
- package/dist/chunks/registry-CKNLQpwd.js +121 -0
- package/dist/chunks/registry-CKNLQpwd.js.map +1 -0
- package/dist/chunks/registry-DehBVRDV.cjs +131 -0
- package/dist/chunks/registry-DehBVRDV.cjs.map +1 -0
- package/dist/chunks/{spring-DfQO5USi.js → spring-CbvHfVtP.js} +2 -2
- package/dist/chunks/{spring-DfQO5USi.js.map → spring-CbvHfVtP.js.map} +1 -1
- package/dist/chunks/{variants-VNscPeTD.js → variants-DRlKVHvu.js} +2 -2
- package/dist/chunks/{variants-VNscPeTD.js.map → variants-DRlKVHvu.js.map} +1 -1
- package/dist/components/a11y.js +2 -2
- package/dist/components/angular.cjs +1 -0
- package/dist/components/angular.cjs.map +1 -1
- package/dist/components/angular.js +7 -6
- package/dist/components/angular.js.map +1 -1
- package/dist/components/background.js +2 -2
- package/dist/components/bridge.js +1 -1
- package/dist/components/cards.js +2 -2
- package/dist/components/click.js +3 -3
- package/dist/components/depth.js +3 -3
- package/dist/components/effects.cjs +71 -403
- package/dist/components/effects.cjs.map +1 -1
- package/dist/components/effects.js +8 -339
- package/dist/components/effects.js.map +1 -1
- package/dist/components/feedback.js +1 -1
- package/dist/components/fx-gpu.cjs +12 -0
- package/dist/components/fx-gpu.cjs.map +1 -0
- package/dist/components/fx-gpu.d.cts +63 -0
- package/dist/components/fx-gpu.d.ts +63 -0
- package/dist/components/fx-gpu.js +5 -0
- package/dist/components/fx-gpu.js.map +1 -0
- package/dist/components/fx.cjs +13 -133
- package/dist/components/fx.cjs.map +1 -1
- package/dist/components/fx.js +6 -125
- package/dist/components/fx.js.map +1 -1
- package/dist/components/fx2.cjs +25 -0
- package/dist/components/fx2.cjs.map +1 -0
- package/dist/components/fx2.d.cts +136 -0
- package/dist/components/fx2.d.ts +136 -0
- package/dist/components/fx2.js +17 -0
- package/dist/components/fx2.js.map +1 -0
- package/dist/components/gesture.js +4 -4
- package/dist/components/interaction.js +1 -1
- package/dist/components/layout.js +1 -1
- package/dist/components/lite.cjs +5 -9
- package/dist/components/lite.cjs.map +1 -1
- package/dist/components/lite.js +5 -9
- package/dist/components/lite.js.map +1 -1
- package/dist/components/packs.js +1 -1
- package/dist/components/page.js +3 -3
- package/dist/components/perf.js +2 -2
- package/dist/components/physics.js +3 -3
- package/dist/components/reveal.js +1 -1
- package/dist/components/solid.cjs +1 -0
- package/dist/components/solid.cjs.map +1 -1
- package/dist/components/solid.js +7 -6
- package/dist/components/solid.js.map +1 -1
- package/dist/components/svelte.cjs +1 -0
- package/dist/components/svelte.cjs.map +1 -1
- package/dist/components/svelte.js +7 -6
- package/dist/components/svelte.js.map +1 -1
- package/dist/components/svg.js +1 -1
- package/dist/components/text.js +2 -2
- package/dist/components/timeline.js +3 -3
- package/dist/components/transitions.js +1 -1
- package/dist/components/ui.js +4 -4
- package/dist/components/vue.cjs +1 -0
- package/dist/components/vue.cjs.map +1 -1
- package/dist/components/vue.js +7 -6
- package/dist/components/vue.js.map +1 -1
- package/dist/components/webgl.js +1 -1
- package/dist/components/widgets.cjs +591 -0
- package/dist/components/widgets.cjs.map +1 -0
- package/dist/components/widgets.d.cts +110 -0
- package/dist/components/widgets.d.ts +110 -0
- package/dist/components/widgets.js +581 -0
- package/dist/components/widgets.js.map +1 -0
- package/dist/components.cjs +10 -9
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +10 -9
- package/dist/components.js.map +1 -1
- package/dist/components.umd.js +2 -2
- package/dist/components.umd.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/widgets.umd.js +2 -0
- package/dist/widgets.umd.js.map +1 -0
- package/docs/ROADMAP.md +10 -11
- package/docs/components.md +29 -0
- package/package.json +31 -1
|
@@ -1,56 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { registerBuiltinEffects } from './fx.js';
|
|
2
|
+
import { P as PALETTE, b as overlay, a as all, o as origin, s as spawn, r as rand, c as canvasBackground, h as hexRgb, f as fxLayer, G as GENERATIVE_FX } from '../chunks/generative-D2YyhaeO.js';
|
|
3
|
+
export { n as noise2 } from '../chunks/generative-D2YyhaeO.js';
|
|
4
|
+
import { x as defineElement, p as prefersReducedMotion, u as adoptStyles } from '../chunks/base-C_3cAoRz.js';
|
|
5
|
+
import { p as playEffect, b as bindEffect, c as registerEffects } from '../chunks/registry-CKNLQpwd.js';
|
|
3
6
|
import { applyMotionTokens, motionTokensToVars, mergeMotionTokens } from './tokens.js';
|
|
4
|
-
import { T as TIMELINE_PRESETS } from '../chunks/core-
|
|
5
|
-
import '../chunks/fx-
|
|
6
|
-
|
|
7
|
-
let layer = null;
|
|
8
|
-
/** A fixed, pointer-transparent, aria-hidden layer for transient particles. */
|
|
9
|
-
function fxLayer() {
|
|
10
|
-
if (layer?.isConnected)
|
|
11
|
-
return layer;
|
|
12
|
-
layer = document.createElement('div');
|
|
13
|
-
layer.setAttribute('aria-hidden', 'true');
|
|
14
|
-
layer.setAttribute('data-usa-fx-layer', '');
|
|
15
|
-
layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;overflow:hidden;z-index:2147483000;contain:strict';
|
|
16
|
-
document.body.appendChild(layer);
|
|
17
|
-
return layer;
|
|
18
|
-
}
|
|
19
|
-
/** Client point of the triggering pointer event, or the element's center. */
|
|
20
|
-
function origin(el, ctx) {
|
|
21
|
-
const e = ctx.event;
|
|
22
|
-
const r = el.getBoundingClientRect();
|
|
23
|
-
return e && typeof e.clientX === 'number' && (e.clientX || e.clientY) ? { x: e.clientX, y: e.clientY } : { x: r.left + r.width / 2, y: r.top + r.height / 2 };
|
|
24
|
-
}
|
|
25
|
-
/** Spawn an absolutely positioned node in the fx layer at (x, y); removed when its animation ends. */
|
|
26
|
-
function spawn(x, y, css, ctx, frames, opts, text = '') {
|
|
27
|
-
const n = document.createElement('span');
|
|
28
|
-
n.style.cssText = `position:absolute;left:${x}px;top:${y}px;${css}`;
|
|
29
|
-
if (text)
|
|
30
|
-
n.textContent = text;
|
|
31
|
-
fxLayer().appendChild(n);
|
|
32
|
-
const a = ctx.animate(n, frames, { fill: 'forwards', ...opts });
|
|
33
|
-
const rm = () => n.remove();
|
|
34
|
-
if (a)
|
|
35
|
-
a.finished.then(rm, rm);
|
|
36
|
-
else
|
|
37
|
-
rm();
|
|
38
|
-
return a;
|
|
39
|
-
}
|
|
40
|
-
/** An overlay child covering `el` (makes `el` a positioning context). Returns it and a remover. */
|
|
41
|
-
function overlay(el, css) {
|
|
42
|
-
const o = document.createElement('span');
|
|
43
|
-
o.setAttribute('aria-hidden', 'true');
|
|
44
|
-
o.style.cssText = `position:absolute;inset:0;pointer-events:none;border-radius:inherit;${css}`;
|
|
45
|
-
if (getComputedStyle(el).position === 'static')
|
|
46
|
-
el.style.position = 'relative';
|
|
47
|
-
el.appendChild(o);
|
|
48
|
-
return [o, () => o.remove()];
|
|
49
|
-
}
|
|
50
|
-
const PALETTE = ['#7c5cff', '#ff5c8a', '#22d3ee', '#facc15', '#34d399'];
|
|
51
|
-
const rand = (a, b) => a + Math.random() * (b - a);
|
|
52
|
-
/** Wait for all animations (ignoring nulls). */
|
|
53
|
-
const all = (anims) => Promise.all(anims.filter(Boolean).map((a) => a.finished.catch(() => undefined)));
|
|
7
|
+
import { T as TIMELINE_PRESETS } from '../chunks/core-VEBw36QK.js';
|
|
8
|
+
import '../chunks/fx-Bs6IrV4Q.js';
|
|
54
9
|
|
|
55
10
|
const CARD_FX = [
|
|
56
11
|
{
|
|
@@ -827,292 +782,6 @@ function defineStory(tag = 'usa-story') {
|
|
|
827
782
|
}, { id: 'usa-story', text: CSS });
|
|
828
783
|
}
|
|
829
784
|
|
|
830
|
-
/** Deterministic smooth pseudo-noise in [-1, 1] (sum of sines — cheap, no tables). */
|
|
831
|
-
function noise2(x, y, t = 0) {
|
|
832
|
-
return (Math.sin(x * 1.7 + t) * Math.cos(y * 1.3 - t * 0.7) + Math.sin((x + y) * 0.9 + t * 0.5) * 0.5 + Math.cos(x * 0.6 - y * 1.1 - t * 0.3) * 0.5) / 2;
|
|
833
|
-
}
|
|
834
|
-
/** Hex `#rrggbb` → [r, g, b]. */
|
|
835
|
-
function hexRgb(hex) {
|
|
836
|
-
const m = /^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i.exec(hex.trim());
|
|
837
|
-
return m ? [parseInt(m[1], 16), parseInt(m[2], 16), parseInt(m[3], 16)] : [124, 92, 255];
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* Mount a generative canvas behind `el` and run `spec` on it. Returns the
|
|
841
|
-
* cleanup. Exposed for custom generative effects.
|
|
842
|
-
*/
|
|
843
|
-
function canvasBackground(el, fx, spec, o) {
|
|
844
|
-
const canvas = document.createElement('canvas');
|
|
845
|
-
canvas.setAttribute('aria-hidden', 'true');
|
|
846
|
-
canvas.setAttribute('data-usa-fx-canvas', '');
|
|
847
|
-
canvas.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:-1;border-radius:inherit';
|
|
848
|
-
const restore = [];
|
|
849
|
-
const set = (k, v) => {
|
|
850
|
-
restore.push([k, el.style[k]]);
|
|
851
|
-
el.style[k] = v;
|
|
852
|
-
};
|
|
853
|
-
if (getComputedStyle(el).position === 'static')
|
|
854
|
-
set('position', 'relative');
|
|
855
|
-
set('isolation', 'isolate');
|
|
856
|
-
el.prepend(canvas);
|
|
857
|
-
const ctx = canvas.getContext('2d');
|
|
858
|
-
let raf = 0;
|
|
859
|
-
let visible = true;
|
|
860
|
-
let quality = Math.min(1, Math.max(0.35, Number(o.quality) || 1));
|
|
861
|
-
let w = 0;
|
|
862
|
-
let h = 0;
|
|
863
|
-
let state = null;
|
|
864
|
-
const t0 = performance.now();
|
|
865
|
-
let last = t0;
|
|
866
|
-
let slow = 0;
|
|
867
|
-
let fast = 0;
|
|
868
|
-
const resize = () => {
|
|
869
|
-
const r = el.getBoundingClientRect();
|
|
870
|
-
w = Math.max(1, Math.round(r.width));
|
|
871
|
-
h = Math.max(1, Math.round(r.height));
|
|
872
|
-
const dpr = Math.min(2, (typeof devicePixelRatio === 'number' ? devicePixelRatio : 1) || 1) * quality;
|
|
873
|
-
canvas.width = Math.max(1, Math.round(w * dpr));
|
|
874
|
-
canvas.height = Math.max(1, Math.round(h * dpr));
|
|
875
|
-
if (ctx)
|
|
876
|
-
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
877
|
-
state = spec.init ? spec.init(w, h, o) : {};
|
|
878
|
-
};
|
|
879
|
-
const frame = (now) => {
|
|
880
|
-
raf = 0;
|
|
881
|
-
if (!ctx)
|
|
882
|
-
return;
|
|
883
|
-
const dt = now - last;
|
|
884
|
-
last = now;
|
|
885
|
-
// adaptive quality: sustained slow frames lower the render scale, fast ones raise it
|
|
886
|
-
if (dt > 28)
|
|
887
|
-
slow++;
|
|
888
|
-
else if (dt < 18)
|
|
889
|
-
fast++;
|
|
890
|
-
if (slow > 20 && quality > 0.35) {
|
|
891
|
-
quality = Math.max(0.35, quality - 0.15);
|
|
892
|
-
slow = fast = 0;
|
|
893
|
-
resize();
|
|
894
|
-
}
|
|
895
|
-
else if (fast > 240 && quality < 1) {
|
|
896
|
-
quality = Math.min(1, quality + 0.15);
|
|
897
|
-
slow = fast = 0;
|
|
898
|
-
resize();
|
|
899
|
-
}
|
|
900
|
-
spec.draw({ ctx, w, h, t: (now - t0) / 1000, quality, state, o });
|
|
901
|
-
if (visible && !document.hidden)
|
|
902
|
-
raf = requestAnimationFrame(frame);
|
|
903
|
-
};
|
|
904
|
-
const start = () => {
|
|
905
|
-
if (!raf && ctx && !fx.reduced) {
|
|
906
|
-
last = performance.now();
|
|
907
|
-
raf = requestAnimationFrame(frame);
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
resize();
|
|
911
|
-
if (ctx)
|
|
912
|
-
spec.draw({ ctx, w, h, t: 0, quality, state, o }); // first / static frame
|
|
913
|
-
const io = typeof IntersectionObserver === 'function' ? new IntersectionObserver((es) => {
|
|
914
|
-
visible = es.some((e) => e.isIntersecting);
|
|
915
|
-
if (visible)
|
|
916
|
-
start();
|
|
917
|
-
}) : null;
|
|
918
|
-
io?.observe(el);
|
|
919
|
-
const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(() => {
|
|
920
|
-
resize();
|
|
921
|
-
if (ctx && fx.reduced)
|
|
922
|
-
spec.draw({ ctx, w, h, t: 0, quality, state, o });
|
|
923
|
-
}) : null;
|
|
924
|
-
ro?.observe(el);
|
|
925
|
-
const vis = () => !document.hidden && visible && start();
|
|
926
|
-
document.addEventListener('visibilitychange', vis);
|
|
927
|
-
start();
|
|
928
|
-
return () => {
|
|
929
|
-
cancelAnimationFrame(raf);
|
|
930
|
-
raf = 0;
|
|
931
|
-
io?.disconnect();
|
|
932
|
-
ro?.disconnect();
|
|
933
|
-
document.removeEventListener('visibilitychange', vis);
|
|
934
|
-
canvas.remove();
|
|
935
|
-
for (const [k, v] of restore)
|
|
936
|
-
el.style[k] = v;
|
|
937
|
-
};
|
|
938
|
-
}
|
|
939
|
-
const gen = (name, description, defaults, spec) => ({
|
|
940
|
-
name,
|
|
941
|
-
kind: 'background',
|
|
942
|
-
description,
|
|
943
|
-
reduced: 'run',
|
|
944
|
-
defaults: { colors: PALETTE, background: '#0b0d12', speed: 1, quality: 1, ...defaults },
|
|
945
|
-
run: (el, o, ctx) => canvasBackground(el, ctx, spec, o),
|
|
946
|
-
});
|
|
947
|
-
/** Low-resolution scalar field → ImageData, drawn scaled up (used by voronoi / metaballs / contours). */
|
|
948
|
-
function field(f, cell, px) {
|
|
949
|
-
const step = Math.max(2, Math.round(cell / f.quality));
|
|
950
|
-
const cw = Math.max(1, Math.ceil(f.w / step));
|
|
951
|
-
const ch = Math.max(1, Math.ceil(f.h / step));
|
|
952
|
-
const st = f.state;
|
|
953
|
-
if (!st.buf || st.buf.width !== cw || st.buf.height !== ch) {
|
|
954
|
-
st.buf = document.createElement('canvas');
|
|
955
|
-
st.buf.width = cw;
|
|
956
|
-
st.buf.height = ch;
|
|
957
|
-
st.bctx = st.buf.getContext('2d');
|
|
958
|
-
st.img = st.bctx?.createImageData(cw, ch);
|
|
959
|
-
}
|
|
960
|
-
if (!st.bctx || !st.img)
|
|
961
|
-
return;
|
|
962
|
-
const d = st.img.data;
|
|
963
|
-
for (let y = 0; y < ch; y++)
|
|
964
|
-
for (let x = 0; x < cw; x++)
|
|
965
|
-
px(x * step, y * step, d, (y * cw + x) * 4);
|
|
966
|
-
st.bctx.putImageData(st.img, 0, 0);
|
|
967
|
-
f.ctx.imageSmoothingEnabled = true;
|
|
968
|
-
f.ctx.drawImage(st.buf, 0, 0, f.w, f.h);
|
|
969
|
-
}
|
|
970
|
-
const GENERATIVE_FX = [
|
|
971
|
-
gen('flow-field', 'Particles drift along a slowly changing flow field, leaving silky trails.', { count: 600, fade: 0.06 }, {
|
|
972
|
-
init: (w, h, o) => ({ p: Array.from({ length: o.count }, () => [Math.random() * w, Math.random() * h]) }),
|
|
973
|
-
draw: ({ ctx, w, h, t, state, o, quality }) => {
|
|
974
|
-
ctx.fillStyle = o.background;
|
|
975
|
-
ctx.globalAlpha = t === 0 ? 1 : o.fade;
|
|
976
|
-
ctx.fillRect(0, 0, w, h);
|
|
977
|
-
ctx.globalAlpha = 0.8;
|
|
978
|
-
const n = Math.round(state.p.length * quality);
|
|
979
|
-
const steps = t === 0 ? 40 : 1;
|
|
980
|
-
for (let i = 0; i < n; i++) {
|
|
981
|
-
const q = state.p[i];
|
|
982
|
-
ctx.fillStyle = o.colors[i % o.colors.length];
|
|
983
|
-
for (let s = 0; s < steps; s++) {
|
|
984
|
-
const a = noise2(q[0] * 0.004, q[1] * 0.004, t * 0.15 * o.speed) * Math.PI * 2;
|
|
985
|
-
q[0] += Math.cos(a) * 1.2 * o.speed;
|
|
986
|
-
q[1] += Math.sin(a) * 1.2 * o.speed;
|
|
987
|
-
if (q[0] < 0 || q[0] > w || q[1] < 0 || q[1] > h)
|
|
988
|
-
(q[0] = Math.random() * w), (q[1] = Math.random() * h);
|
|
989
|
-
ctx.fillRect(q[0], q[1], 1.4, 1.4);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
ctx.globalAlpha = 1;
|
|
993
|
-
},
|
|
994
|
-
}),
|
|
995
|
-
gen('voronoi', 'Drifting Voronoi cells in the palette, with darker borders.', { seeds: 14, cell: 6 }, {
|
|
996
|
-
init: (w, h, o) => ({ s: Array.from({ length: o.seeds }, (_, i) => ({ x: Math.random() * w, y: Math.random() * h, vx: Math.random() - 0.5, vy: Math.random() - 0.5, c: hexRgb(o.colors[i % o.colors.length]) })) }),
|
|
997
|
-
draw: (f) => {
|
|
998
|
-
const { w, h, state, o } = f;
|
|
999
|
-
for (const s of state.s) {
|
|
1000
|
-
s.x += s.vx * o.speed;
|
|
1001
|
-
s.y += s.vy * o.speed;
|
|
1002
|
-
if (s.x < 0 || s.x > w)
|
|
1003
|
-
s.vx *= -1;
|
|
1004
|
-
if (s.y < 0 || s.y > h)
|
|
1005
|
-
s.vy *= -1;
|
|
1006
|
-
}
|
|
1007
|
-
field(f, o.cell, (x, y, d, i) => {
|
|
1008
|
-
let b = Infinity;
|
|
1009
|
-
let b2 = Infinity;
|
|
1010
|
-
let c = state.s[0].c;
|
|
1011
|
-
for (const s of state.s) {
|
|
1012
|
-
const dd = (s.x - x) ** 2 + (s.y - y) ** 2;
|
|
1013
|
-
if (dd < b)
|
|
1014
|
-
(b2 = b), (b = dd), (c = s.c);
|
|
1015
|
-
else if (dd < b2)
|
|
1016
|
-
b2 = dd;
|
|
1017
|
-
}
|
|
1018
|
-
const edge = Math.sqrt(b2) - Math.sqrt(b) < 6 ? 0.55 : 1;
|
|
1019
|
-
d[i] = c[0] * edge;
|
|
1020
|
-
d[i + 1] = c[1] * edge;
|
|
1021
|
-
d[i + 2] = c[2] * edge;
|
|
1022
|
-
d[i + 3] = 255;
|
|
1023
|
-
});
|
|
1024
|
-
},
|
|
1025
|
-
}),
|
|
1026
|
-
gen('mesh-gradient', 'Soft blobs of colour orbit and blend into a living mesh gradient.', { blobs: 4, blur: 0.65 }, {
|
|
1027
|
-
draw: ({ ctx, w, h, t, o }) => {
|
|
1028
|
-
ctx.fillStyle = o.background;
|
|
1029
|
-
ctx.fillRect(0, 0, w, h);
|
|
1030
|
-
const r = Math.max(w, h) * o.blur;
|
|
1031
|
-
for (let i = 0; i < o.blobs; i++) {
|
|
1032
|
-
const a = t * 0.25 * o.speed + (i * Math.PI * 2) / o.blobs;
|
|
1033
|
-
const x = w / 2 + Math.cos(a * (1 + i * 0.13)) * w * 0.32;
|
|
1034
|
-
const y = h / 2 + Math.sin(a * (0.8 + i * 0.11)) * h * 0.32;
|
|
1035
|
-
const [cr, cg, cb] = hexRgb(o.colors[i % o.colors.length]);
|
|
1036
|
-
const g = ctx.createRadialGradient(x, y, 0, x, y, r);
|
|
1037
|
-
g.addColorStop(0, `rgba(${cr},${cg},${cb},0.7)`);
|
|
1038
|
-
g.addColorStop(1, `rgba(${cr},${cg},${cb},0)`);
|
|
1039
|
-
ctx.fillStyle = g;
|
|
1040
|
-
ctx.fillRect(0, 0, w, h);
|
|
1041
|
-
}
|
|
1042
|
-
},
|
|
1043
|
-
}),
|
|
1044
|
-
gen('starfield', 'Stars stream toward the viewer (warp speed with `speed: 4`).', { stars: 400, color: '#ffffff' }, {
|
|
1045
|
-
init: (_w, _h, o) => ({ s: Array.from({ length: o.stars }, () => [Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random()]) }),
|
|
1046
|
-
draw: ({ ctx, w, h, t, state, o, quality }) => {
|
|
1047
|
-
ctx.fillStyle = o.background;
|
|
1048
|
-
ctx.fillRect(0, 0, w, h);
|
|
1049
|
-
ctx.fillStyle = o.color;
|
|
1050
|
-
const n = Math.round(state.s.length * quality);
|
|
1051
|
-
for (let i = 0; i < n; i++) {
|
|
1052
|
-
const s = state.s[i];
|
|
1053
|
-
if (t > 0)
|
|
1054
|
-
s[2] -= 0.004 * o.speed;
|
|
1055
|
-
if (s[2] <= 0.01)
|
|
1056
|
-
(s[0] = Math.random() * 2 - 1), (s[1] = Math.random() * 2 - 1), (s[2] = 1);
|
|
1057
|
-
const x = w / 2 + (s[0] / s[2]) * w * 0.5;
|
|
1058
|
-
const y = h / 2 + (s[1] / s[2]) * h * 0.5;
|
|
1059
|
-
if (x < 0 || x > w || y < 0 || y > h)
|
|
1060
|
-
continue;
|
|
1061
|
-
const size = (1 - s[2]) * 2.6;
|
|
1062
|
-
ctx.globalAlpha = Math.min(1, (1 - s[2]) * 1.6);
|
|
1063
|
-
ctx.fillRect(x, y, size, size);
|
|
1064
|
-
}
|
|
1065
|
-
ctx.globalAlpha = 1;
|
|
1066
|
-
},
|
|
1067
|
-
}),
|
|
1068
|
-
gen('metaballs', 'Gooey blobs that merge and split (low-resolution field, scaled up).', { balls: 6, cell: 5, threshold: 1 }, {
|
|
1069
|
-
init: (w, h, o) => ({ b: Array.from({ length: o.balls }, () => ({ x: Math.random() * w, y: Math.random() * h, vx: (Math.random() - 0.5) * 1.6, vy: (Math.random() - 0.5) * 1.6, r: Math.min(w, h) * (0.08 + Math.random() * 0.08) })) }),
|
|
1070
|
-
draw: (f) => {
|
|
1071
|
-
const { w, h, state, o } = f;
|
|
1072
|
-
for (const b of state.b) {
|
|
1073
|
-
b.x += b.vx * o.speed;
|
|
1074
|
-
b.y += b.vy * o.speed;
|
|
1075
|
-
if (b.x < 0 || b.x > w)
|
|
1076
|
-
b.vx *= -1;
|
|
1077
|
-
if (b.y < 0 || b.y > h)
|
|
1078
|
-
b.vy *= -1;
|
|
1079
|
-
}
|
|
1080
|
-
const [ar, ag, ab] = hexRgb(o.colors[0]);
|
|
1081
|
-
const [br, bg, bb] = hexRgb(o.colors[1] || o.colors[0]);
|
|
1082
|
-
const [kr, kg, kb] = hexRgb(o.background);
|
|
1083
|
-
field(f, o.cell, (x, y, d, i) => {
|
|
1084
|
-
let v = 0;
|
|
1085
|
-
for (const b of state.b)
|
|
1086
|
-
v += (b.r * b.r) / ((b.x - x) ** 2 + (b.y - y) ** 2 + 1);
|
|
1087
|
-
const inside = v >= o.threshold;
|
|
1088
|
-
const k = Math.min(1, (v - o.threshold) * 0.8);
|
|
1089
|
-
d[i] = inside ? ar + (br - ar) * k : kr;
|
|
1090
|
-
d[i + 1] = inside ? ag + (bg - ag) * k : kg;
|
|
1091
|
-
d[i + 2] = inside ? ab + (bb - ab) * k : kb;
|
|
1092
|
-
d[i + 3] = 255;
|
|
1093
|
-
});
|
|
1094
|
-
},
|
|
1095
|
-
}),
|
|
1096
|
-
gen('contours', 'Topographic contour lines over a slowly shifting height field.', { levels: 9, cell: 4, color: '#7c5cff' }, {
|
|
1097
|
-
draw: (f) => {
|
|
1098
|
-
const { t, o } = f;
|
|
1099
|
-
const [lr, lg, lb] = hexRgb(o.color);
|
|
1100
|
-
const [kr, kg, kb] = hexRgb(o.background);
|
|
1101
|
-
const z = (x, y) => (noise2(x * 0.006, y * 0.006, t * 0.2 * o.speed) + 1) / 2;
|
|
1102
|
-
const step = Math.max(2, Math.round(o.cell / f.quality));
|
|
1103
|
-
field(f, o.cell, (x, y, d, i) => {
|
|
1104
|
-
const a = Math.floor(z(x, y) * o.levels);
|
|
1105
|
-
const line = a !== Math.floor(z(x + step, y) * o.levels) || a !== Math.floor(z(x, y + step) * o.levels);
|
|
1106
|
-
const shade = 0.12 + (a / o.levels) * 0.18;
|
|
1107
|
-
d[i] = line ? lr : kr + (lr - kr) * shade;
|
|
1108
|
-
d[i + 1] = line ? lg : kg + (lg - kg) * shade;
|
|
1109
|
-
d[i + 2] = line ? lb : kb + (lb - kb) * shade;
|
|
1110
|
-
d[i + 3] = 255;
|
|
1111
|
-
});
|
|
1112
|
-
},
|
|
1113
|
-
}),
|
|
1114
|
-
];
|
|
1115
|
-
|
|
1116
785
|
let actx = null;
|
|
1117
786
|
let current = null;
|
|
1118
787
|
const mediaSources = new WeakMap();
|
|
@@ -2527,5 +2196,5 @@ function registerAllEffects() {
|
|
|
2527
2196
|
registerEffects(defs);
|
|
2528
2197
|
}
|
|
2529
2198
|
|
|
2530
|
-
export { ANIMATION_FORMAT, AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, MICRO_FX, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, THEMES, THEME_FX, THEME_NAMES, THEME_ROLES, angleDelta, applyTheme, bindBeat, bindGesture, bounceKeyframes, bumpCount, canvasBackground, createBeatDetector, createPlayer, defineAudio, defineEffectElements, defineGestureFx, definePlayer, defineStory, defineTheme, disableAudio, enableAudio, flingVelocity, formatCount, fxLayer, getAudio, hexRgb,
|
|
2199
|
+
export { ANIMATION_FORMAT, AUDIO_FX, CARD_FX, CLICK_FX, CURSOR_FX, EFFECT_PACKS, GENERATIVE_FX, GESTURES, MICRO_FX, PAGE_FX, PHYSICS_FX, STORY_TEMPLATES, THEMES, THEME_FX, THEME_NAMES, THEME_ROLES, angleDelta, applyTheme, bindBeat, bindGesture, bounceKeyframes, bumpCount, canvasBackground, createBeatDetector, createPlayer, defineAudio, defineEffectElements, defineGestureFx, definePlayer, defineStory, defineTheme, disableAudio, enableAudio, flingVelocity, formatCount, fxLayer, getAudio, hexRgb, normalizeAnimation, onBeat, playThemeEffect, registerAllEffects, registerAudioEffects, registerCardClickEffects, registerCursorEffects, registerGenerativeEffects, registerMicroEffects, registerPageEffects, registerPhysicsEffects, solveSpring, springKeyframes, storyProgress, swapLabel, themeCss, themePreset, themeVars, togglePressed };
|
|
2531
2200
|
//# sourceMappingURL=effects.js.map
|