use-scroll-animate 4.7.0 → 4.9.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.
Files changed (132) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +1 -1
  3. package/README_ja.md +1 -1
  4. package/README_zh.md +1 -1
  5. package/bin/usa-codemod-5.mjs +79 -0
  6. package/dist/chunks/{base-CxYU2NK_.cjs → base-BvpQ4Ggj.cjs} +30 -1
  7. package/dist/chunks/base-BvpQ4Ggj.cjs.map +1 -0
  8. package/dist/chunks/{base-CZiIAMBc.js → base-DbbRUxaa.js} +29 -2
  9. package/dist/chunks/base-DbbRUxaa.js.map +1 -0
  10. package/dist/chunks/{core-CJHJeMI_.js → core-BVTuet9o.js} +2 -2
  11. package/dist/chunks/{core-CJHJeMI_.js.map → core-BVTuet9o.js.map} +1 -1
  12. package/dist/chunks/{core-HLqH3qkA.cjs → core-BWO7JKJ5.cjs} +2 -2
  13. package/dist/chunks/{core-HLqH3qkA.cjs.map → core-BWO7JKJ5.cjs.map} +1 -1
  14. package/dist/chunks/{core-CctNfzuP.cjs → core-CCAM3nKw.cjs} +2 -2
  15. package/dist/chunks/{core-CctNfzuP.cjs.map → core-CCAM3nKw.cjs.map} +1 -1
  16. package/dist/chunks/{core-COi3DrLx.js → core-CcaSsbV8.js} +2 -2
  17. package/dist/chunks/{core-COi3DrLx.js.map → core-CcaSsbV8.js.map} +1 -1
  18. package/dist/chunks/{index-tags-BQh_uGqH.cjs → index-tags-CIRY2KnU.cjs} +2 -2
  19. package/dist/chunks/{index-tags-BQh_uGqH.cjs.map → index-tags-CIRY2KnU.cjs.map} +1 -1
  20. package/dist/chunks/{index-tags-43Xtd01A.js → index-tags-Dh8nwXqw.js} +2 -2
  21. package/dist/chunks/{index-tags-43Xtd01A.js.map → index-tags-Dh8nwXqw.js.map} +1 -1
  22. package/dist/chunks/{spring-BS5tg6aK.js → spring-B6w7mVCU.js} +2 -2
  23. package/dist/chunks/{spring-BS5tg6aK.js.map → spring-B6w7mVCU.js.map} +1 -1
  24. package/dist/chunks/{spring-Dkpygsuj.cjs → spring-fFkqE9J0.cjs} +2 -2
  25. package/dist/chunks/{spring-Dkpygsuj.cjs.map → spring-fFkqE9J0.cjs.map} +1 -1
  26. package/dist/chunks/{variants-CfJzrzMh.cjs → variants-C8xj8gfd.cjs} +2 -2
  27. package/dist/chunks/{variants-CfJzrzMh.cjs.map → variants-C8xj8gfd.cjs.map} +1 -1
  28. package/dist/chunks/{variants-D9n-3x27.js → variants-Cal4DB0E.js} +2 -2
  29. package/dist/chunks/{variants-D9n-3x27.js.map → variants-Cal4DB0E.js.map} +1 -1
  30. package/dist/components/a11y.cjs +38 -2
  31. package/dist/components/a11y.cjs.map +1 -1
  32. package/dist/components/a11y.d.cts +13 -3
  33. package/dist/components/a11y.d.ts +13 -3
  34. package/dist/components/a11y.js +38 -4
  35. package/dist/components/a11y.js.map +1 -1
  36. package/dist/components/angular.cjs +6 -6
  37. package/dist/components/angular.d.cts +2 -1
  38. package/dist/components/angular.d.ts +2 -1
  39. package/dist/components/angular.js +6 -6
  40. package/dist/components/background.cjs +2 -2
  41. package/dist/components/background.js +3 -3
  42. package/dist/components/bridge.cjs +1 -1
  43. package/dist/components/bridge.js +1 -1
  44. package/dist/components/cards.cjs +2 -2
  45. package/dist/components/cards.js +3 -3
  46. package/dist/components/click.cjs +2 -2
  47. package/dist/components/click.js +3 -3
  48. package/dist/components/depth.cjs +3 -3
  49. package/dist/components/depth.js +4 -4
  50. package/dist/components/feedback.cjs +1 -1
  51. package/dist/components/feedback.js +2 -2
  52. package/dist/components/gesture.cjs +3 -3
  53. package/dist/components/gesture.js +5 -5
  54. package/dist/components/interaction.cjs +1 -1
  55. package/dist/components/interaction.js +2 -2
  56. package/dist/components/jsx.d.cts +1 -1
  57. package/dist/components/jsx.d.ts +1 -1
  58. package/dist/components/layout.cjs +1 -1
  59. package/dist/components/layout.js +2 -2
  60. package/dist/components/lazy.cjs +1 -1
  61. package/dist/components/lazy.d.cts +1 -1
  62. package/dist/components/lazy.d.ts +1 -1
  63. package/dist/components/lazy.js +1 -1
  64. package/dist/components/lite.cjs +259 -12
  65. package/dist/components/lite.cjs.map +1 -1
  66. package/dist/components/lite.js +250 -13
  67. package/dist/components/lite.js.map +1 -1
  68. package/dist/components/packs.cjs +1 -1
  69. package/dist/components/packs.js +2 -2
  70. package/dist/components/page.cjs +12 -4
  71. package/dist/components/page.cjs.map +1 -1
  72. package/dist/components/page.js +13 -5
  73. package/dist/components/page.js.map +1 -1
  74. package/dist/components/perf.cjs +2 -2
  75. package/dist/components/perf.d.cts +1 -1
  76. package/dist/components/perf.d.ts +1 -1
  77. package/dist/components/perf.js +3 -3
  78. package/dist/components/physics.cjs +2 -2
  79. package/dist/components/physics.js +4 -4
  80. package/dist/components/react.cjs +1 -1
  81. package/dist/components/react.js +1 -1
  82. package/dist/components/reveal.cjs +1 -1
  83. package/dist/components/reveal.js +2 -2
  84. package/dist/components/solid.cjs +6 -6
  85. package/dist/components/solid.d.cts +2 -1
  86. package/dist/components/solid.d.ts +2 -1
  87. package/dist/components/solid.js +6 -6
  88. package/dist/components/svelte.cjs +6 -6
  89. package/dist/components/svelte.d.cts +2 -1
  90. package/dist/components/svelte.d.ts +2 -1
  91. package/dist/components/svelte.js +6 -6
  92. package/dist/components/svg.cjs +1 -1
  93. package/dist/components/svg.js +2 -2
  94. package/dist/components/text.cjs +2 -2
  95. package/dist/components/text.js +3 -3
  96. package/dist/components/timeline.cjs +4 -2
  97. package/dist/components/timeline.cjs.map +1 -1
  98. package/dist/components/timeline.js +6 -4
  99. package/dist/components/timeline.js.map +1 -1
  100. package/dist/components/transitions.cjs +1 -1
  101. package/dist/components/transitions.js +2 -2
  102. package/dist/components/ui.cjs +3 -3
  103. package/dist/components/ui.js +5 -5
  104. package/dist/components/vue.cjs +6 -6
  105. package/dist/components/vue.d.cts +2 -1
  106. package/dist/components/vue.d.ts +2 -1
  107. package/dist/components/vue.js +6 -6
  108. package/dist/components/webgl.cjs +185 -11
  109. package/dist/components/webgl.cjs.map +1 -1
  110. package/dist/components/webgl.css +1 -1
  111. package/dist/components/webgl.d.cts +59 -5
  112. package/dist/components/webgl.d.ts +59 -5
  113. package/dist/components/webgl.js +179 -13
  114. package/dist/components/webgl.js.map +1 -1
  115. package/dist/components.cjs +16 -6
  116. package/dist/components.cjs.map +1 -1
  117. package/dist/components.css +1 -1
  118. package/dist/components.d.cts +70 -6
  119. package/dist/components.d.ts +70 -6
  120. package/dist/components.js +10 -10
  121. package/dist/components.umd.js +2 -2
  122. package/dist/components.umd.js.map +1 -1
  123. package/dist/index.cjs +2 -2
  124. package/dist/index.js +2 -2
  125. package/dist/index.umd.js.map +1 -1
  126. package/docs/ROADMAP.md +2 -2
  127. package/docs/components.md +7 -0
  128. package/docs/deprecations.md +6 -0
  129. package/docs/upgrading-5.md +31 -0
  130. package/package.json +5 -1
  131. package/dist/chunks/base-CZiIAMBc.js.map +0 -1
  132. package/dist/chunks/base-CxYU2NK_.cjs.map +0 -1
@@ -14,6 +14,13 @@ const MOTION_SCALE = { off: 0, low: 0.6, normal: 1, high: 1.25 };
14
14
  const config = { injectStyles: true, reducedMotion: 'user', motionIntensity: 'normal', motionSensitivity: 'full' };
15
15
  /** Change global component settings (call before `define*()` for `injectStyles`). */
16
16
  function configureComponents(options) {
17
+ if (!quiet) {
18
+ // 4.9: removed in 5.0 (see docs/upgrading-5.md, `npx usa-codemod-5`)
19
+ if (options.motionIntensity === 'off')
20
+ deprecate('intensity-off', "motionIntensity: 'off' is deprecated and will be removed in 5.0 — use motionSensitivity: 'minimal' (setMotionSensitivity('minimal')) instead.");
21
+ if (options.reducedMotion === 'no-preference')
22
+ deprecate('reduced-no-preference', "reducedMotion: 'no-preference' is deprecated and will be removed in 5.0 — the OS setting is always respected; use 'user' (default) or 'reduce'.");
23
+ }
17
24
  Object.assign(config, options);
18
25
  if (options.motionIntensity && typeof document !== 'undefined') {
19
26
  document.documentElement.style.setProperty('--usa-motion', String(MOTION_SCALE[options.motionIntensity] ?? 1));
@@ -58,6 +65,17 @@ function adaptKeyframes(frames, level = config.motionSensitivity) {
58
65
  return out;
59
66
  });
60
67
  }
68
+ let quiet = 0;
69
+ /** Run `fn` without 4.9 deprecation warnings (library-internal calls). */
70
+ function withoutDeprecations(fn) {
71
+ quiet++;
72
+ try {
73
+ return fn();
74
+ }
75
+ finally {
76
+ quiet--;
77
+ }
78
+ }
61
79
  /** The current global motion intensity. */
62
80
  function getMotionIntensity() {
63
81
  return config.motionIntensity;
@@ -361,6 +379,15 @@ const EASE_OUT = 'cubic-bezier(0.22, 1, 0.36, 1)';
361
379
  const EASE_SPRING = 'cubic-bezier(0.34, 1.56, 0.64, 1)';
362
380
  /** Windows Fluent "decelerate" / "point-to-point" curves. */
363
381
  const FLUENT_DECELERATE = 'cubic-bezier(0.1, 0.9, 0.2, 1)';
382
+ const warned = new Set();
383
+ /** Log a deprecation once per key (console.warn). */
384
+ function deprecate(key, message) {
385
+ if (warned.has(key))
386
+ return;
387
+ warned.add(key);
388
+ if (typeof console !== 'undefined')
389
+ console.warn(`[use-scroll-animate] ${message}`);
390
+ }
364
391
  /**
365
392
  * The `kind` attribute of `<usa-spinner>`, `<usa-check>`, `<usa-dialog>` and
366
393
  * `<usa-acrylic>` (3.0: `variant` only selects a style variant).
@@ -388,7 +415,7 @@ const COMPONENT_CATEGORIES = {
388
415
  timeline: ['usa-timeline'],
389
416
  gesture: ['usa-swipeable', 'usa-pinch-zoom'],
390
417
  svg: ['usa-draw', 'usa-morph', 'usa-mask-reveal', 'usa-anim-icon'],
391
- webgl: ['usa-shader', 'usa-distort', 'usa-liquid'],
418
+ webgl: ['usa-shader', 'usa-distort', 'usa-liquid', 'usa-post-fx'],
392
419
  depth: ['usa-cube', 'usa-depth'],
393
420
  layout: ['usa-auto-animate', 'usa-masonry'],
394
421
  packs: ['usa-pack'],
@@ -7946,6 +7973,7 @@ var css$7 = "";
7946
7973
 
7947
7974
  const LEVELS = ['off', 'low', 'normal', 'high'];
7948
7975
  const KEY$1 = 'usa:motion';
7976
+ let fromSwitch = false;
7949
7977
  /**
7950
7978
  * Set the global motion intensity for every `<usa-*>` component:
7951
7979
  * `'off'` (like reduced motion), `'low'`, `'normal'` (default), `'high'`.
@@ -7955,7 +7983,9 @@ const KEY$1 = 'usa:motion';
7955
7983
  function setMotionIntensity(level, persist = false) {
7956
7984
  if (!LEVELS.includes(level))
7957
7985
  return;
7958
- configureComponents({ motionIntensity: level });
7986
+ if (level === 'off' && !fromSwitch)
7987
+ deprecate('set-intensity-off', "setMotionIntensity('off') is deprecated and will be removed in 5.0 — use setMotionSensitivity('minimal') from use-scroll-animate/components/a11y.");
7988
+ withoutDeprecations(() => configureComponents({ motionIntensity: level }));
7959
7989
  if (persist) {
7960
7990
  try {
7961
7991
  localStorage.setItem(KEY$1, level);
@@ -7971,12 +8001,15 @@ function setMotionIntensity(level, persist = false) {
7971
8001
  function restoreMotionIntensity() {
7972
8002
  try {
7973
8003
  const v = localStorage.getItem(KEY$1);
7974
- if (v && LEVELS.includes(v))
8004
+ if (v && LEVELS.includes(v)) {
8005
+ fromSwitch = true;
7975
8006
  setMotionIntensity(v);
8007
+ }
7976
8008
  }
7977
8009
  catch {
7978
8010
  /* ignore */
7979
8011
  }
8012
+ fromSwitch = false;
7980
8013
  return getMotionIntensity();
7981
8014
  }
7982
8015
  function defineMotionSwitch(tag = 'usa-motion-switch') {
@@ -7985,7 +8018,9 @@ function defineMotionSwitch(tag = 'usa-motion-switch') {
7985
8018
  return getMotionIntensity();
7986
8019
  }
7987
8020
  set value(v) {
8021
+ fromSwitch = true;
7988
8022
  setMotionIntensity(v, true);
8023
+ fromSwitch = false;
7989
8024
  this.sync();
7990
8025
  }
7991
8026
  mount() {
@@ -8176,6 +8211,8 @@ function defineTimeline(tag = 'usa-timeline') {
8176
8211
  // (0–0.95) or `scrub="js"` opt into the JS engine, `scrub="scroll"`
8177
8212
  // follows this element's own scroll position.
8178
8213
  const v = this.str('scrub');
8214
+ if (v === 'js')
8215
+ deprecate('timeline-scrub-js', '<usa-timeline scrub="js"> is deprecated and will be removed in 5.0 — the JS engine is picked automatically where native scroll timelines are missing; add smooth="…" to opt into smoothing.');
8179
8216
  const stop = tl.scrub(this, { smooth: this.num('smooth', 0), engine: v === 'js' ? 'js' : 'auto', source: v === 'scroll' ? 'scroll' : 'view' });
8180
8217
  this.toggleAttribute('data-native', stop.native);
8181
8218
  this.onCleanup(stop);
@@ -8953,6 +8990,12 @@ const SHADERS = {
8953
8990
  waves: 'void main(){vec2 u=v_uv;float t=u_time*.4;float w=0.;for(int i=0;i<4;i++){float f=float(i)+1.;w+=sin(u.x*6.*f+t*f)*.08/f;}float l=smoothstep(.0,.02,abs(u.y-.5-w));vec3 col=mix(vec3(.2,.5,1.),vec3(.04,.06,.15),l)+vec3(.1,.0,.2)*u.y;gl_FragColor=vec4(col,1.);}',
8954
8991
  aurora: 'void main(){vec2 u=v_uv;float t=u_time*.2;float b=0.;for(int i=0;i<3;i++){float f=float(i);b+=.4/abs((u.y-.6+.15*sin(u.x*3.+t+f*1.7))*(8.+f*4.));}vec3 col=vec3(.02,.03,.08)+b*mix(vec3(.1,.9,.6),vec3(.6,.3,1.),u.x)*.35;gl_FragColor=vec4(col,1.);}',
8955
8992
  distort: 'void main(){vec2 u=v_uv;vec2 d=u-u_mouse;float r=length(d);float k=u_hover*.08*exp(-r*r*18.);u-=normalize(d+1e-4)*k;float s=u_hover*.006;vec3 col=vec3(texture2D(u_tex,u+vec2(s,0.)).r,texture2D(u_tex,u).g,texture2D(u_tex,u-vec2(s,0.)).b);gl_FragColor=vec4(col,1.);}',
8993
+ // 4.8 particle presets (procedural, one quad: no buffers, no per-particle JS)
8994
+ snow: 'float h(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}void main(){vec2 u=v_uv;u.x*=u_resolution.x/max(u_resolution.y,1.);vec3 col=mix(vec3(.05,.08,.16),vec3(.12,.16,.3),v_uv.y);for(int l=0;l<3;l++){float s=8.+float(l)*7.;vec2 q=u*s;q.y+=u_time*(.6+float(l)*.35);q.x+=sin(q.y*.7+float(l))*.3;vec2 id=floor(q);vec2 f=fract(q)-.5;float r=h(id);if(r>.6){vec2 o=vec2(h(id+3.)-.5,h(id+7.)-.5)*.6;float d=length(f-o);col+=smoothstep(.09-float(l)*.02,0.,d)*(.5+.5*r);}}gl_FragColor=vec4(col,1.);}',
8995
+ fireflies: 'float h(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}void main(){vec2 u=v_uv;u.x*=u_resolution.x/max(u_resolution.y,1.);vec3 col=vec3(.02,.04,.03);for(int l=0;l<2;l++){vec2 q=u*(5.+float(l)*4.);vec2 id=floor(q);vec2 f=fract(q)-.5;float r=h(id+float(l)*13.);vec2 o=.35*vec2(sin(u_time*(.4+r)+r*6.28),cos(u_time*(.3+r)+r*12.));float d=length(f-o);float tw=.5+.5*sin(u_time*3.*r+r*20.);col+=vec3(1.,.85,.3)*smoothstep(.12,0.,d)*tw*step(.45,r);}gl_FragColor=vec4(col,1.);}',
8996
+ stars: 'float h(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}void main(){vec2 c=v_uv-.5;c.x*=u_resolution.x/max(u_resolution.y,1.);vec3 col=vec3(.01,.01,.04);for(int l=0;l<4;l++){float z=fract(float(l)*.25+u_time*.05);float sc=mix(20.,.5,z);vec2 q=c*sc+float(l)*7.;vec2 id=floor(q);vec2 f=fract(q)-.5;float r=h(id);float d=length(f-(vec2(h(id+1.),h(id+2.))-.5)*.7);col+=vec3(.8,.9,1.)*smoothstep(.06,0.,d)*step(.8,r)*smoothstep(0.,.5,z)*smoothstep(1.,.8,z)*2.;}gl_FragColor=vec4(col,1.);}',
8997
+ bokeh: 'float h(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}void main(){vec2 u=v_uv;u.x*=u_resolution.x/max(u_resolution.y,1.);vec3 col=mix(vec3(.08,.03,.12),vec3(.02,.05,.12),v_uv.y);for(int l=0;l<3;l++){vec2 q=u*(2.5+float(l)*1.5);q.y-=u_time*.05*(1.+float(l));vec2 id=floor(q);vec2 f=fract(q)-.5;float r=h(id+float(l)*5.);float d=length(f-(vec2(h(id+4.),h(id+9.))-.5)*.5);vec3 tint=.5+.5*cos(r*6.28+vec3(0.,2.,4.));col+=tint*smoothstep(.3,.26,d)*.18*step(.35,r);}gl_FragColor=vec4(col,1.);}',
8998
+ rain: 'float h(float n){return fract(sin(n)*43758.5453);}void main(){vec2 u=v_uv;vec3 col=mix(vec3(.04,.06,.1),vec3(.1,.13,.2),u.y);float n=floor(u.x*120.);float sp=.8+h(n)*1.2;float y=fract(u.y+u_time*sp+h(n+1.));float drop=smoothstep(.0,.08,y)*smoothstep(.16,.08,y)*step(.7,h(n+2.));col+=vec3(.5,.6,.8)*drop*.6;gl_FragColor=vec4(col,1.);}',
8956
8999
  liquid: 'void main(){vec2 u=v_uv;vec2 o=vec2(0.);for(int i=0;i<4;i++){vec4 r=u_ripples[i];if(r.w>0.){float d=distance(u,r.xy);float w=sin(d*60.-r.z*12.)*exp(-d*6.)*exp(-r.z*1.6)*r.w*.02;o+=normalize(u-r.xy+1e-4)*w;}}o+=vec2(sin(u.y*10.+u_time),cos(u.x*10.+u_time))*.002*u_hover;gl_FragColor=texture2D(u_tex,u+o);}',
8957
9000
  };
8958
9001
  /** Full fragment source for a preset or custom body (adds the shared header). */
@@ -9012,9 +9055,10 @@ function glQuad(canvas, frag) {
9012
9055
  const U = (n) => g.getUniformLocation(prog, n);
9013
9056
  const uT = U('u_time'), uR = U('u_resolution'), uM = U('u_mouse'), uH = U('u_hover'), uRp = U('u_ripples');
9014
9057
  let tex = null;
9058
+ const extraLoc = {};
9015
9059
  const quad = {
9016
- resize() {
9017
- const dpr = Math.min(2, (typeof devicePixelRatio === 'number' && devicePixelRatio) || 1);
9060
+ resize(scale = 1) {
9061
+ const dpr = Math.min(2, (typeof devicePixelRatio === 'number' && devicePixelRatio) || 1) * Math.min(1, Math.max(0.25, scale));
9018
9062
  const w = Math.max(1, Math.round((canvas.clientWidth || 300) * dpr));
9019
9063
  const h = Math.max(1, Math.round((canvas.clientHeight || 150) * dpr));
9020
9064
  if (canvas.width !== w || canvas.height !== h)
@@ -9037,6 +9081,9 @@ function glQuad(canvas, frag) {
9037
9081
  g.uniform1f(uH, u.hover ?? 0);
9038
9082
  if (uRp)
9039
9083
  g.uniform4fv(uRp, new Float32Array((u.ripples ?? []).concat(Array(16).fill(0)).slice(0, 16)));
9084
+ if (u.extra)
9085
+ for (const [k, v] of Object.entries(u.extra))
9086
+ g.uniform1f((extraLoc[k] ?? (extraLoc[k] = U(k))), v);
9040
9087
  g.drawArrays(g.TRIANGLES, 0, 6);
9041
9088
  },
9042
9089
  dispose() {
@@ -9051,6 +9098,131 @@ function glQuad(canvas, frag) {
9051
9098
  return quad;
9052
9099
  }
9053
9100
 
9101
+ /**
9102
+ * 4.8 — WebGL preset library on `glQuad()`: particle presets (`snow`,
9103
+ * `fireflies`, `stars`, `bokeh`, `rain` — usable as `<usa-shader preset>`),
9104
+ * chainable post-processing passes for images (`<usa-post-fx>`), one CSS
9105
+ * fallback per preset, and an adaptive quality governor (fps + battery).
9106
+ */
9107
+ const PARTICLE_PRESETS = ['snow', 'fireflies', 'stars', 'bokeh', 'rain'];
9108
+ /** Post-processing passes: `vec3 fx(vec3 c, vec2 uv)` bodies, applied in order. `u_intensity` 0–1. */
9109
+ const POST_EFFECTS = {
9110
+ vignette: 'c*=mix(1.,smoothstep(.85,.25,length(uv-.5)),u_intensity);',
9111
+ grain: 'c+=(fract(sin(dot(uv*u_resolution+u_time,vec2(12.9898,78.233)))*43758.5453)-.5)*.18*u_intensity;',
9112
+ chromatic: 'float s=.008*u_intensity;c=vec3(texture2D(u_tex,uv+vec2(s,0.)).r,c.g,texture2D(u_tex,uv-vec2(s,0.)).b);',
9113
+ scanlines: 'c*=1.-.25*u_intensity*step(.5,fract(uv.y*u_resolution.y*.5));',
9114
+ crt: 'vec2 d=uv-.5;float r=dot(d,d);c*=1.-.6*u_intensity*r;c*=.92+.08*sin(uv.y*u_resolution.y*3.14159);c.r*=1.+.05*u_intensity;',
9115
+ bloom: 'vec3 b=vec3(0.);for(int i=0;i<8;i++){float a=float(i)*.785;b+=max(texture2D(u_tex,uv+vec2(cos(a),sin(a))*.012).rgb-.6,0.);}c+=b*.35*u_intensity;',
9116
+ pixelate: 'float px=mix(1.,48.,u_intensity);vec2 g=floor(uv*u_resolution/px)*px/u_resolution;c=texture2D(u_tex,g+.5*px/u_resolution).rgb;',
9117
+ duotone: 'float l=dot(c,vec3(.299,.587,.114));c=mix(c,mix(vec3(.12,.05,.35),vec3(1.,.55,.4),l),u_intensity);',
9118
+ glitch: 'float k=step(.97,fract(sin(floor(uv.y*24.)+floor(u_time*6.))*4375.5));c=mix(c,texture2D(u_tex,uv+vec2(k*.04*u_intensity,0.)).rgb,k);',
9119
+ };
9120
+ /** One fragment shader running the passes in order over `u_tex` (pixel-sampling passes read the source). */
9121
+ function postFxShader(effects) {
9122
+ const list = effects.filter((e) => POST_EFFECTS[e]);
9123
+ const body = list.map((e) => `{${POST_EFFECTS[e]}}`).join('');
9124
+ return `uniform float u_intensity;void main(){vec2 uv=v_uv;vec3 c=texture2D(u_tex,uv).rgb;${body}gl_FragColor=vec4(clamp(c,0.,1.),1.);}`;
9125
+ }
9126
+ /** The unified CSS fallback (no WebGL / reduced data): a still background or image filter per preset. */
9127
+ const GL_FALLBACKS = {
9128
+ gradient: 'linear-gradient(120deg,#6366f1,#ec4899 50%,#22d3ee)',
9129
+ plasma: 'conic-gradient(from 90deg,#f43f5e,#a855f7,#06b6d4,#f43f5e)',
9130
+ waves: 'linear-gradient(#0a0f26,#1e3a8a)',
9131
+ aurora: 'radial-gradient(120% 60% at 30% 40%,#10b98155,transparent),radial-gradient(100% 50% at 70% 50%,#8b5cf655,transparent),#05070f',
9132
+ snow: 'radial-gradient(2px 2px at 20% 30%,#fff,transparent),radial-gradient(2px 2px at 70% 60%,#fff,transparent),radial-gradient(1.5px 1.5px at 40% 80%,#fff,transparent),linear-gradient(#0d1428,#1f2a4d)',
9133
+ fireflies: 'radial-gradient(3px 3px at 25% 40%,#fde68a,transparent),radial-gradient(3px 3px at 65% 70%,#fde68a,transparent),#05090a',
9134
+ stars: 'radial-gradient(1px 1px at 10% 20%,#fff,transparent),radial-gradient(1px 1px at 80% 30%,#fff,transparent),radial-gradient(1.5px 1.5px at 50% 70%,#cfe0ff,transparent),#02020a',
9135
+ bokeh: 'radial-gradient(40px 40px at 30% 40%,#f472b633,transparent),radial-gradient(60px 60px at 70% 60%,#60a5fa33,transparent),#140820',
9136
+ rain: 'repeating-linear-gradient(100deg,#ffffff10 0 1px,transparent 1px 14px),linear-gradient(#0a0f1a,#1a2133)',
9137
+ // post-fx fallbacks are CSS filters on the <img>
9138
+ 'post:duotone': 'grayscale(1) sepia(.6) hue-rotate(220deg) saturate(2)',
9139
+ 'post:vignette': 'brightness(.95) contrast(1.05)',
9140
+ 'post:crt': 'contrast(1.15) saturate(1.2)',
9141
+ 'post:bloom': 'brightness(1.08) saturate(1.15)',
9142
+ };
9143
+ /** CSS fallback for a shader preset / post effect list. */
9144
+ function glFallbackCss(preset, post = false) {
9145
+ if (post)
9146
+ return preset.split(/\s+/).map((e) => GL_FALLBACKS[`post:${e}`]).filter(Boolean).join(' ');
9147
+ return GL_FALLBACKS[preset] || GL_FALLBACKS.gradient;
9148
+ }
9149
+ /**
9150
+ * Adaptive quality for GL loops: measures fps, steps the resolution scale
9151
+ * down (1 → 0.5 → 0.35) after two slow seconds and back up after five good
9152
+ * ones, and caps the frame rate in battery-saver mode. Pure — feed it times.
9153
+ */
9154
+ function glGovernor(options = {}) {
9155
+ const { minFps = 40, saverFps = 30 } = options;
9156
+ const STEPS = [1, 0.5, 0.35];
9157
+ let step = 0;
9158
+ let frames = 0;
9159
+ let winStart = -1;
9160
+ let last = -Infinity;
9161
+ let slow = 0;
9162
+ let good = 0;
9163
+ let fps = 60;
9164
+ const g = {
9165
+ saver: false,
9166
+ get scale() {
9167
+ return Math.min(STEPS[step], g.saver ? 0.6 : 1);
9168
+ },
9169
+ get fps() {
9170
+ return fps;
9171
+ },
9172
+ tick(t) {
9173
+ if (winStart < 0)
9174
+ winStart = t;
9175
+ if (g.saver && t - last < 1000 / saverFps - 1)
9176
+ return false;
9177
+ last = t;
9178
+ frames++;
9179
+ if (t - winStart >= 1000) {
9180
+ fps = Math.round((frames * 1000) / (t - winStart));
9181
+ frames = 0;
9182
+ winStart = t;
9183
+ const before = g.scale;
9184
+ if (fps < minFps && !g.saver) {
9185
+ good = 0;
9186
+ if (++slow >= 2 && step < STEPS.length - 1)
9187
+ ((step++), (slow = 0));
9188
+ }
9189
+ else {
9190
+ slow = 0;
9191
+ if (++good >= 5 && step > 0)
9192
+ ((step--), (good = 0));
9193
+ }
9194
+ if (g.scale !== before)
9195
+ g.onScale?.(g.scale);
9196
+ }
9197
+ return true;
9198
+ },
9199
+ };
9200
+ return g;
9201
+ }
9202
+ /** Watch the Battery Status API (where available) and Save-Data; calls `cb(true)` in saver conditions. Returns a stop function. */
9203
+ function watchPowerSaver(cb) {
9204
+ let stopped = false;
9205
+ const nav = (typeof navigator !== 'undefined' ? navigator : {});
9206
+ const saveData = !!nav.connection?.saveData;
9207
+ if (saveData)
9208
+ cb(true);
9209
+ if (typeof nav.getBattery !== 'function')
9210
+ return () => undefined;
9211
+ let battery = null;
9212
+ const update = () => !stopped && cb(saveData || (!!battery && !battery.charging && battery.level <= 0.2));
9213
+ nav.getBattery().then((b) => {
9214
+ battery = b;
9215
+ update();
9216
+ b.addEventListener?.('levelchange', update);
9217
+ b.addEventListener?.('chargingchange', update);
9218
+ }, () => undefined);
9219
+ return () => {
9220
+ stopped = true;
9221
+ battery?.removeEventListener?.('levelchange', update);
9222
+ battery?.removeEventListener?.('chargingchange', update);
9223
+ };
9224
+ }
9225
+
9054
9226
  var css$2 = "";
9055
9227
 
9056
9228
  function make(kind) {
@@ -9064,15 +9236,23 @@ function make(kind) {
9064
9236
  this._hover = 0;
9065
9237
  this._hoverTo = 0;
9066
9238
  this._ripples = [];
9239
+ this._scale = 1;
9067
9240
  }
9068
9241
  static get observedAttributes() {
9069
- return kind === 'shader' ? ['preset', 'speed'] : ['src'];
9242
+ return kind === 'shader' ? ['preset', 'speed', 'quality'] : kind === 'post' ? ['effects', 'intensity', 'quality'] : ['src'];
9070
9243
  }
9071
9244
  get active() {
9072
9245
  return !!this._q;
9073
9246
  }
9074
9247
  fallback(reason) {
9075
9248
  this.setAttribute('data-fallback', reason);
9249
+ // 4.8 unified fallback: a still CSS rendering of the preset / effects
9250
+ if (reason !== 'off') {
9251
+ if (kind === 'shader')
9252
+ this.style.setProperty('--usa-gl-fallback', glFallbackCss(this.str('preset', 'gradient')));
9253
+ if (kind === 'post')
9254
+ this.style.setProperty('--usa-gl-filter', glFallbackCss(this.str('effects', 'vignette grain'), true) || 'none');
9255
+ }
9076
9256
  this._c?.remove();
9077
9257
  this._c = null;
9078
9258
  this._q?.dispose();
@@ -9090,12 +9270,13 @@ function make(kind) {
9090
9270
  mouse: this._mouse,
9091
9271
  hover: this._hover,
9092
9272
  ripples: this._ripples.flatMap((r) => [r.x, r.y, (t - r.t) / 1000, this.num('strength', 1)]),
9273
+ extra: kind === 'post' ? { u_intensity: clamp(this.num('intensity', 0.6), 0, 1) } : undefined,
9093
9274
  });
9094
9275
  }
9095
9276
  mount() {
9096
9277
  this.removeAttribute('data-fallback');
9097
9278
  const custom = this.querySelector('script[type="x-shader/x-fragment"]');
9098
- const frag = kind === 'shader' ? custom?.textContent || this.str('preset', 'gradient') : kind;
9279
+ const frag = kind === 'shader' ? custom?.textContent || this.str('preset', 'gradient') : kind === 'post' ? postFxShader(this.str('effects', 'vignette grain').split(/[\s,]+/)) : kind;
9099
9280
  const img = kind === 'shader' ? null : this.querySelector('img');
9100
9281
  if (kind !== 'shader' && !img)
9101
9282
  return this.fallback('no-image');
@@ -9120,7 +9301,7 @@ function make(kind) {
9120
9301
  }
9121
9302
  };
9122
9303
  const draw = () => {
9123
- q.resize();
9304
+ q.resize(this._scale);
9124
9305
  this.frame();
9125
9306
  };
9126
9307
  if (img && !(img.complete && img.naturalWidth)) {
@@ -9134,7 +9315,7 @@ function make(kind) {
9134
9315
  this.setAttribute('data-active', '');
9135
9316
  this.onCleanup(() => this.removeAttribute('data-active'));
9136
9317
  draw();
9137
- if (kind !== 'shader') {
9318
+ if (kind === 'distort' || kind === 'liquid') {
9138
9319
  const pos = (e) => {
9139
9320
  const r = this.getBoundingClientRect();
9140
9321
  this._mouse = [clamp((e.clientX - r.left) / (r.width || 1), 0, 1), clamp(1 - (e.clientY - r.top) / (r.height || 1), 0, 1)];
@@ -9151,7 +9332,7 @@ function make(kind) {
9151
9332
  // 4.0.1: also follow the element's own size (grid reflow, card expand…)
9152
9333
  if (typeof ResizeObserver !== 'undefined') {
9153
9334
  const ro = new ResizeObserver(() => {
9154
- q.resize();
9335
+ q.resize(this._scale);
9155
9336
  if (!this._id)
9156
9337
  this.frame();
9157
9338
  });
@@ -9160,9 +9341,20 @@ function make(kind) {
9160
9341
  }
9161
9342
  if (this.reduced)
9162
9343
  return; // one static frame, no loop
9344
+ // 4.8 adaptive quality: fps-driven resolution steps + battery saver frame cap
9345
+ const gov = glGovernor();
9346
+ const auto = this.str('quality', 'auto') !== 'high';
9347
+ gov.onScale = (sc) => {
9348
+ this._scale = sc;
9349
+ this.setAttribute('data-quality', String(sc));
9350
+ q.resize(sc);
9351
+ };
9352
+ if (auto)
9353
+ this.onCleanup(watchPowerSaver((saver) => ((gov.saver = saver), gov.onScale?.(gov.scale))));
9163
9354
  let visible = false;
9164
9355
  const loop = () => {
9165
- this.frame();
9356
+ if (!auto || gov.tick(now()))
9357
+ this.frame();
9166
9358
  this._id = raf(loop);
9167
9359
  };
9168
9360
  const sync = () => {
@@ -9173,7 +9365,7 @@ function make(kind) {
9173
9365
  };
9174
9366
  this.inView((v) => ((visible = v), sync()));
9175
9367
  this.listen(document, 'visibilitychange', sync);
9176
- this.listen(window, 'resize', () => q.resize(), { passive: true });
9368
+ this.listen(window, 'resize', () => q.resize(this._scale), { passive: true });
9177
9369
  this.onCleanup(() => caf(this._id));
9178
9370
  }
9179
9371
  };
@@ -9201,6 +9393,16 @@ function defineDistort(tag = 'usa-distort') {
9201
9393
  function defineLiquid(tag = 'usa-liquid') {
9202
9394
  return defineElement(tag, make('liquid'), { id: 'webgl', text: css$2 });
9203
9395
  }
9396
+ /**
9397
+ * `<usa-post-fx effects="vignette grain crt" intensity="0.6">` — GPU
9398
+ * post-processing over the `<img>` inside (4.8): `vignette` · `grain` ·
9399
+ * `chromatic` · `scanlines` · `crt` · `bloom` · `pixelate` · `duotone` ·
9400
+ * `glitch`, chained in order. `quality="high"` disables adaptive quality.
9401
+ * Fallback: the image with an approximate CSS filter.
9402
+ */
9403
+ function definePostFx(tag = 'usa-post-fx') {
9404
+ return defineElement(tag, make('post'), { id: 'webgl', text: css$2 });
9405
+ }
9204
9406
 
9205
9407
  /**
9206
9408
  * use-scroll-animate/components/webgl — lightweight canvas / WebGL (v3.4).
@@ -9213,6 +9415,7 @@ function defineWebglComponents() {
9213
9415
  defineShader();
9214
9416
  defineDistort();
9215
9417
  defineLiquid();
9418
+ definePostFx();
9216
9419
  }
9217
9420
 
9218
9421
  var css$1 = "";
@@ -9876,6 +10079,40 @@ function definePacksComponents() {
9876
10079
  definePack();
9877
10080
  }
9878
10081
 
10082
+ /**
10083
+ * 4.9 — the 5.0 modern-browser baseline. `baselineReport()` lists which
10084
+ * required / progressive features this browser has; `warnBaseline()` logs
10085
+ * once in development when a required one is missing.
10086
+ */
10087
+ /** Required in 5.0: Custom Elements, WAAPI, IntersectionObserver, ResizeObserver, adoptedStyleSheets. Progressive: View Transitions, scroll-driven animations, WebGL. */
10088
+ function baselineReport() {
10089
+ const w = (typeof window !== 'undefined' ? window : {});
10090
+ const d = (typeof document !== 'undefined' ? document : {});
10091
+ const css = (q) => typeof w.CSS?.supports === 'function' && w.CSS.supports(q);
10092
+ return [
10093
+ { id: 'custom-elements', required: true, supported: !!w.customElements },
10094
+ { id: 'web-animations', required: true, supported: typeof w.Element?.prototype?.animate === 'function' },
10095
+ { id: 'intersection-observer', required: true, supported: typeof w.IntersectionObserver === 'function' },
10096
+ { id: 'resize-observer', required: true, supported: typeof w.ResizeObserver === 'function' },
10097
+ { id: 'adopted-stylesheets', required: true, supported: 'adoptedStyleSheets' in d },
10098
+ { id: 'view-transitions', required: false, supported: typeof d.startViewTransition === 'function' },
10099
+ { id: 'scroll-driven-animations', required: false, supported: css('animation-timeline: view()') },
10100
+ { id: 'webgl', required: false, supported: !!(d.createElement && (() => { try {
10101
+ return d.createElement('canvas').getContext('webgl');
10102
+ }
10103
+ catch {
10104
+ return null;
10105
+ } })()) },
10106
+ ];
10107
+ }
10108
+ /** Log (once) which required 5.0 features are missing here. Returns the missing ids. */
10109
+ function warnBaseline() {
10110
+ const missing = baselineReport().filter((f) => f.required && !f.supported).map((f) => f.id);
10111
+ if (missing.length)
10112
+ deprecate('baseline', `this browser lacks ${missing.join(', ')}; use-scroll-animate 5.0 requires them (modern-browser baseline, see docs/upgrading-5.md).`);
10113
+ return missing;
10114
+ }
10115
+
9879
10116
  /**
9880
10117
  * use-scroll-animate/components/a11y — accessibility toolkit (4.4).
9881
10118
  *
@@ -10312,6 +10549,7 @@ exports.CARD_EFFECTS = CARD_EFFECTS;
10312
10549
  exports.CLICK_EFFECTS = CLICK_EFFECTS;
10313
10550
  exports.COMPONENT_CATEGORIES = COMPONENT_CATEGORIES;
10314
10551
  exports.CURSOR_MODES = CURSOR_MODES;
10552
+ exports.GL_FALLBACKS = GL_FALLBACKS;
10315
10553
  exports.JOINING_SCRIPT = JOINING_SCRIPT;
10316
10554
  exports.LIVE_REGION_IDS = LIVE_REGION_IDS;
10317
10555
  exports.MASK_SHAPES = MASK_SHAPES;
@@ -10323,6 +10561,8 @@ exports.MOTION_TOKENS = MOTION_TOKENS;
10323
10561
  exports.PACKS = PACKS;
10324
10562
  exports.PACK_PRIMITIVES = PACK_PRIMITIVES;
10325
10563
  exports.PAGE_EFFECTS = PAGE_EFFECTS;
10564
+ exports.PARTICLE_PRESETS = PARTICLE_PRESETS;
10565
+ exports.POST_EFFECTS = POST_EFFECTS;
10326
10566
  exports.REVEAL_EFFECTS = REVEAL_EFFECTS;
10327
10567
  exports.SENSITIVITY_CSS = SENSITIVITY_CSS;
10328
10568
  exports.SHADERS = SHADERS;
@@ -10344,6 +10584,7 @@ exports.applyPack = applyPack;
10344
10584
  exports.auditMotionA11y = auditMotionA11y;
10345
10585
  exports.autoAnimate = autoAnimate;
10346
10586
  exports.autoDegrade = autoDegrade;
10587
+ exports.baselineReport = baselineReport;
10347
10588
  exports.burst = burst;
10348
10589
  exports.categoryOf = categoryOf;
10349
10590
  exports.confetti = confetti;
@@ -10417,6 +10658,7 @@ exports.defineParticles = defineParticles;
10417
10658
  exports.definePhysicsComponents = definePhysicsComponents;
10418
10659
  exports.definePinchZoom = definePinchZoom;
10419
10660
  exports.definePopover = definePopover;
10661
+ exports.definePostFx = definePostFx;
10420
10662
  exports.definePress = definePress;
10421
10663
  exports.defineProgress = defineProgress;
10422
10664
  exports.definePullRefresh = definePullRefresh;
@@ -10471,6 +10713,8 @@ exports.gesture = gesture;
10471
10713
  exports.getMotionIntensity = getMotionIntensity;
10472
10714
  exports.getMotionSensitivity = getMotionSensitivity;
10473
10715
  exports.getMotionTokens = getMotionTokens;
10716
+ exports.glFallbackCss = glFallbackCss;
10717
+ exports.glGovernor = glGovernor;
10474
10718
  exports.glQuad = glQuad;
10475
10719
  exports.graphemes = graphemes;
10476
10720
  exports.haptic = haptic;
@@ -10500,6 +10744,7 @@ exports.parseEasing = parseEasing;
10500
10744
  exports.parseNativeSettings = parseNativeSettings;
10501
10745
  exports.pathsCompatible = pathsCompatible;
10502
10746
  exports.pinchScale = pinchScale;
10747
+ exports.postFxShader = postFxShader;
10503
10748
  exports.postToNative = postToNative;
10504
10749
  exports.prefersReducedMotion = prefersReducedMotion;
10505
10750
  exports.projectInertia = projectInertia;
@@ -10544,4 +10789,6 @@ exports.themeTransition = themeTransition;
10544
10789
  exports.timeline = timeline;
10545
10790
  exports.toast = toast;
10546
10791
  exports.viewTransition = viewTransition;
10792
+ exports.warnBaseline = warnBaseline;
10793
+ exports.watchPowerSaver = watchPowerSaver;
10547
10794
  //# sourceMappingURL=lite.cjs.map