@ultimat3/effects 0.0.0-stage → 31.52.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 (71) hide show
  1. package/CATALOG.md +169 -0
  2. package/CLAUDE.md +29 -0
  3. package/LICENSE +21 -0
  4. package/README.md +64 -2
  5. package/package.json +56 -4
  6. package/src/_effect.scss +53 -0
  7. package/src/aurora/Aurora.module.scss +56 -0
  8. package/src/aurora/Aurora.tsx +35 -0
  9. package/src/aurora/aurora-view.ts +32 -0
  10. package/src/backend.ts +34 -0
  11. package/src/canvas-mount.ts +61 -0
  12. package/src/count-up/CountUp.tsx +51 -0
  13. package/src/count-up/count-up-run.ts +59 -0
  14. package/src/count-up/count-up-view.ts +56 -0
  15. package/src/css-pause.ts +50 -0
  16. package/src/effect-canvas/EffectCanvas.module.scss +23 -0
  17. package/src/effect-canvas/EffectCanvas.tsx +51 -0
  18. package/src/effect-canvas/effect-canvas-view.ts +33 -0
  19. package/src/effect-host.ts +54 -0
  20. package/src/effect-mount.ts +114 -0
  21. package/src/errors.ts +33 -0
  22. package/src/glass-surface/GlassSurface.module.scss +25 -0
  23. package/src/glass-surface/GlassSurface.tsx +29 -0
  24. package/src/glass-surface/glass-surface-view.ts +33 -0
  25. package/src/gradient-orbs/GradientOrbs.module.scss +49 -0
  26. package/src/gradient-orbs/GradientOrbs.tsx +41 -0
  27. package/src/gradient-orbs/gradient-orbs-view.ts +77 -0
  28. package/src/grid-glow/GridGlow.module.scss +50 -0
  29. package/src/grid-glow/GridGlow.tsx +39 -0
  30. package/src/grid-glow/grid-glow-view.ts +40 -0
  31. package/src/index.ts +45 -0
  32. package/src/marquee/Marquee.module.scss +52 -0
  33. package/src/marquee/Marquee.tsx +31 -0
  34. package/src/marquee/marquee-view.ts +25 -0
  35. package/src/mosaic-grid/MosaicGrid.module.scss +39 -0
  36. package/src/mosaic-grid/MosaicGrid.tsx +59 -0
  37. package/src/mosaic-grid/mosaic-grid-view.ts +96 -0
  38. package/src/motion-port.ts +22 -0
  39. package/src/noise/Noise.module.scss +22 -0
  40. package/src/noise/Noise.tsx +49 -0
  41. package/src/noise/noise-view.ts +38 -0
  42. package/src/palette.ts +41 -0
  43. package/src/pixel-budget.ts +42 -0
  44. package/src/props.ts +61 -0
  45. package/src/shader-background/ShaderBackground.module.scss +70 -0
  46. package/src/shader-background/ShaderBackground.tsx +60 -0
  47. package/src/shader-background/load-preset.ts +19 -0
  48. package/src/shader-background/presets/dots.ts +59 -0
  49. package/src/shader-background/presets/grain.ts +59 -0
  50. package/src/shader-background/presets/mesh.ts +78 -0
  51. package/src/shader-background/shader-background-canvas.ts +116 -0
  52. package/src/shader-background/shader-background-view.ts +98 -0
  53. package/src/shader-background/uniform-pack.ts +11 -0
  54. package/src/shader-load.ts +17 -0
  55. package/src/shader-mount.ts +197 -0
  56. package/src/shimmer/Shimmer.module.scss +23 -0
  57. package/src/shimmer/Shimmer.tsx +19 -0
  58. package/src/spotlight-card/SpotlightCard.module.scss +29 -0
  59. package/src/spotlight-card/SpotlightCard.tsx +28 -0
  60. package/src/spotlight-card/spotlight-card-view.ts +37 -0
  61. package/src/spotlight-card/spotlight-wire.ts +34 -0
  62. package/src/text-reveal/TextReveal.module.scss +47 -0
  63. package/src/text-reveal/TextReveal.tsx +48 -0
  64. package/src/text-reveal/text-reveal-view.ts +38 -0
  65. package/src/tilt/Tilt.module.scss +18 -0
  66. package/src/tilt/Tilt.tsx +30 -0
  67. package/src/tilt/tilt-view.ts +64 -0
  68. package/src/tilt/tilt-wire.ts +50 -0
  69. package/src/use-css-pause.ts +35 -0
  70. package/src/use-effect-mount.ts +35 -0
  71. package/src/visibility.ts +26 -0
@@ -0,0 +1,48 @@
1
+ // Text that arrives piece by piece. One readable node carries the words; the animated split is its
2
+ // `aria-hidden` twin, so a screen reader hears the sentence once and unbroken.
3
+
4
+ import { cx, useUi } from '@ultimat3/ui';
5
+ import type { JSX } from 'solid-js';
6
+ import styles from './TextReveal.module.scss';
7
+ import { type RevealBy, revealStepMs, splitReveal, TEXT_REVEAL_BACKEND } from './text-reveal-view';
8
+
9
+ export interface TextRevealProps {
10
+ /** Already-translated text. */
11
+ text: string;
12
+ by?: RevealBy | undefined;
13
+ /** Locale override; defaults to the page's (`useUi().locale`). */
14
+ locale?: string | undefined;
15
+ /** Milliseconds between pieces; shrunk for long texts. */
16
+ stepMs?: number | undefined;
17
+ class?: string | undefined;
18
+ }
19
+
20
+ export function TextReveal(props: TextRevealProps): JSX.Element {
21
+ const by = props.by ?? 'word';
22
+ const pieces = splitReveal(props.text, by, props.locale ?? useUi().locale);
23
+ const step = revealStepMs(pieces.filter((piece) => piece.animate).length, props.stepMs);
24
+ let index = 0;
25
+ return (
26
+ <span
27
+ class={cx(styles['root'], props.class)}
28
+ data-effect-backend={TEXT_REVEAL_BACKEND}
29
+ style={{ '--reveal-step': `${step}ms` }}
30
+ >
31
+ <span class={styles['text']}>{props.text}</span>
32
+ <span aria-hidden="true">
33
+ {pieces.map((piece) =>
34
+ piece.animate ? (
35
+ <span
36
+ class={cx(styles['piece'], by === 'line' && styles['line'])}
37
+ style={{ '--i': index++ }}
38
+ >
39
+ {piece.text}
40
+ </span>
41
+ ) : (
42
+ <span class={styles['rest']}>{piece.text}</span>
43
+ ),
44
+ )}
45
+ </span>
46
+ </span>
47
+ );
48
+ }
@@ -0,0 +1,38 @@
1
+ // Splits text into the pieces that animate. `Intl.Segmenter` with the reader's locale, because
2
+ // "words" in Thai or Japanese have no spaces and a flag or a ZWJ emoji is one character, not
3
+ // several UTF-16 units.
4
+
5
+ import { EffectsInvalidValueError } from '../errors';
6
+
7
+ export const TEXT_REVEAL_BACKEND = 'css';
8
+ export type RevealBy = 'word' | 'line' | 'char';
9
+
10
+ export interface RevealPiece {
11
+ readonly text: string;
12
+ /** Whitespace and punctuation-only runs are laid out but never staggered. */
13
+ readonly animate: boolean;
14
+ }
15
+
16
+ export function splitReveal(text: string, by: RevealBy, locale: string): readonly RevealPiece[] {
17
+ if (by === 'line') {
18
+ return text.split('\n').map((line) => ({ text: line, animate: line.trim() !== '' }));
19
+ }
20
+ const segmenter = new Intl.Segmenter(locale, {
21
+ granularity: by === 'word' ? 'word' : 'grapheme',
22
+ });
23
+ return Array.from(segmenter.segment(text), (part) => ({
24
+ text: part.segment,
25
+ animate: by === 'word' ? part.isWordLike === true : part.segment.trim() !== '',
26
+ }));
27
+ }
28
+
29
+ /** Per-piece delay (ms), shrunk so a long text never takes more than `maxTotalMs` to finish. */
30
+ export function revealStepMs(count: number, stepMs = 40, maxTotalMs = 900): number {
31
+ if (!Number.isFinite(stepMs) || stepMs < 0) {
32
+ throw new EffectsInvalidValueError({
33
+ cause: `TextReveal stepMs must be a finite number >= 0, got ${String(stepMs)}.`,
34
+ fix: '<TextReveal text="Hello" stepMs={40} /> // stepMs >= 0, or omit stepMs',
35
+ });
36
+ }
37
+ return count <= 1 ? stepMs : Math.min(stepMs, maxTotalMs / (count - 1));
38
+ }
@@ -0,0 +1,18 @@
1
+ @use '@ultimat3/ui/tokens' as t;
2
+
3
+ .tilt {
4
+ display: block;
5
+ transform-style: preserve-3d;
6
+ transform: perspective(var(--tilt-perspective, 60rem)) rotateX(var(--tilt-x, 0deg))
7
+ rotateY(var(--tilt-y, 0deg));
8
+ transition: transform t.duration(fast) t.easing(out);
9
+ will-change: transform;
10
+ }
11
+
12
+ // Without a fine pointer there is nothing to follow; the script also refuses, this is the floor.
13
+ @media (hover: none), (pointer: coarse) {
14
+ .tilt {
15
+ transform: none;
16
+ will-change: auto;
17
+ }
18
+ }
@@ -0,0 +1,30 @@
1
+ // A wrapper that leans toward the pointer. Off — not merely softer — for a coarse pointer, inside
2
+ // a modal's focus trap, and whenever motion is not allowed; the angle never passes `TILT_MAX_DEG`.
3
+
4
+ import { cx } from '@ultimat3/ui';
5
+ import type { JSX } from 'solid-js';
6
+ import { browserHost } from '../effect-host';
7
+ import styles from './Tilt.module.scss';
8
+ import { TILT_BACKEND, tiltCap } from './tilt-view';
9
+ import { tiltMove, tiltRest } from './tilt-wire';
10
+
11
+ export interface TiltProps {
12
+ /** Degrees at the card's corner, capped at `TILT_MAX_DEG` (15). */
13
+ maxAngle?: number | undefined;
14
+ children?: JSX.Element | undefined;
15
+ class?: string | undefined;
16
+ }
17
+
18
+ export function Tilt(props: TiltProps): JSX.Element {
19
+ const cap = tiltCap(props.maxAngle);
20
+ return (
21
+ <div
22
+ class={cx(styles['tilt'], props.class)}
23
+ data-effect-backend={TILT_BACKEND}
24
+ onPointerMove={(event) => tiltMove(event.currentTarget, event, cap, browserHost())}
25
+ onPointerLeave={(event) => tiltRest(event.currentTarget)}
26
+ >
27
+ {props.children}
28
+ </div>
29
+ );
30
+ }
@@ -0,0 +1,64 @@
1
+ // Tilt's rules as pure functions: the angle cap, the angles for a pointer, and when tilt is off
2
+ // at all. A tilt that fights a modal's focus trap or a finger's scroll is worse than none.
3
+
4
+ import { EffectsInvalidValueError } from '../errors';
5
+
6
+ export const TILT_BACKEND = 'static';
7
+ export const TILT_DEFAULT_DEG = 8;
8
+ /** The hard ceiling: past this a card stops reading as a surface and starts to smear. */
9
+ export const TILT_MAX_DEG = 15;
10
+
11
+ /** A focus trap's roots: the inert background is the author's, so tilt stays out of them. */
12
+ export const FOCUS_TRAP_SELECTOR = 'dialog[open], [aria-modal="true"], [data-focus-trap]';
13
+
14
+ export interface TiltBox {
15
+ readonly left: number;
16
+ readonly top: number;
17
+ readonly width: number;
18
+ readonly height: number;
19
+ }
20
+
21
+ export interface TiltAngles {
22
+ readonly rotateX: number;
23
+ readonly rotateY: number;
24
+ }
25
+
26
+ export interface TiltEnvironment {
27
+ readonly coarsePointer: boolean;
28
+ readonly insideFocusTrap: boolean;
29
+ readonly motionAllowed: boolean;
30
+ }
31
+
32
+ /** The requested max angle, capped. A non-finite or non-positive value is refused, not clamped. */
33
+ export function tiltCap(requested: number | undefined): number {
34
+ if (requested === undefined) return TILT_DEFAULT_DEG;
35
+ if (!Number.isFinite(requested) || requested <= 0) {
36
+ throw new EffectsInvalidValueError({
37
+ cause: `Tilt maxAngle must be a positive finite number of degrees, got ${String(requested)}.`,
38
+ fix: `<Tilt maxAngle={${TILT_DEFAULT_DEG}} /> // degrees > 0; above ${TILT_MAX_DEG} is capped, or omit maxAngle`,
39
+ });
40
+ }
41
+ return Math.min(requested, TILT_MAX_DEG);
42
+ }
43
+
44
+ const unit = (value: number): number => Math.min(Math.max(value, -1), 1);
45
+
46
+ /** The pointer's offset from the centre, as a fraction of the half-size, times the cap. */
47
+ export function tiltAngles(
48
+ box: TiltBox,
49
+ clientX: number,
50
+ clientY: number,
51
+ cap: number,
52
+ ): TiltAngles {
53
+ if (box.width <= 0 || box.height <= 0) return { rotateX: 0, rotateY: 0 };
54
+ const nx = unit(((clientX - box.left) / box.width) * 2 - 1);
55
+ const ny = unit(((clientY - box.top) / box.height) * 2 - 1);
56
+ return {
57
+ rotateX: Math.round(-ny * cap * 100) / 100 || 0,
58
+ rotateY: Math.round(nx * cap * 100) / 100 || 0,
59
+ };
60
+ }
61
+
62
+ export function tiltEnabled(env: TiltEnvironment): boolean {
63
+ return env.motionAllowed && !env.coarsePointer && !env.insideFocusTrap;
64
+ }
@@ -0,0 +1,50 @@
1
+ // Tilt's pointer handling over an element, host-injected so the motion gate is the port's.
2
+
3
+ import type { EffectHost } from '../effect-host';
4
+ import { FOCUS_TRAP_SELECTOR, tiltAngles, tiltEnabled } from './tilt-view';
5
+
6
+ export interface TiltTarget {
7
+ closest(selector: string): unknown;
8
+ getBoundingClientRect(): { left: number; top: number; width: number; height: number };
9
+ readonly style: {
10
+ setProperty(name: string, value: string): void;
11
+ removeProperty(name: string): void;
12
+ };
13
+ }
14
+
15
+ export interface TiltPointer {
16
+ readonly pointerType: string;
17
+ readonly clientX: number;
18
+ readonly clientY: number;
19
+ }
20
+
21
+ export function tiltRest(el: TiltTarget): void {
22
+ el.style.removeProperty('--tilt-x');
23
+ el.style.removeProperty('--tilt-y');
24
+ }
25
+
26
+ /** Leans toward the pointer, or lays the element flat when tilt is off for this pointer/page. */
27
+ export function tiltMove(
28
+ el: TiltTarget,
29
+ pointer: TiltPointer,
30
+ cap: number,
31
+ host: EffectHost,
32
+ ): void {
33
+ const on = tiltEnabled({
34
+ coarsePointer: pointer.pointerType !== 'mouse' && pointer.pointerType !== 'pen',
35
+ insideFocusTrap: el.closest(FOCUS_TRAP_SELECTOR) !== null,
36
+ motionAllowed: host.motion.allowed(),
37
+ });
38
+ if (!on) {
39
+ tiltRest(el);
40
+ return;
41
+ }
42
+ const { rotateX, rotateY } = tiltAngles(
43
+ el.getBoundingClientRect(),
44
+ pointer.clientX,
45
+ pointer.clientY,
46
+ cap,
47
+ );
48
+ el.style.setProperty('--tilt-x', `${rotateX}deg`);
49
+ el.style.setProperty('--tilt-y', `${rotateY}deg`);
50
+ }
@@ -0,0 +1,35 @@
1
+ // The Solid shell around `mountCssPause`, for an entry that animates in CSS alone: the label as a
2
+ // signal, a ref for the root, and the pause mounted once from an effect. It reaches ui's motion
3
+ // gate and `inView` directly — never the frame loop, the canvas or the shader mount.
4
+
5
+ import { solid } from '@ultimat3/ui';
6
+ import { motionAllowed, onMotionChange } from '@ultimat3/ui/motion';
7
+ import type { EffectBackend } from './backend';
8
+ import { mountCssPause } from './css-pause';
9
+ import { observeVisibility } from './visibility';
10
+
11
+ export interface CssPauseBinding {
12
+ readonly backend: () => EffectBackend;
13
+ readonly root: (el: HTMLElement) => void;
14
+ }
15
+
16
+ export function useCssPause(server: EffectBackend): CssPauseBinding {
17
+ const rt = solid();
18
+ const [backend, setBackend] = rt.createSignal<EffectBackend>(server);
19
+ let rootEl: HTMLElement | undefined;
20
+ rt.createEffect(() => {
21
+ if (rootEl === undefined) return;
22
+ const env = {
23
+ observeVisible: observeVisibility,
24
+ allowed: () => motionAllowed(),
25
+ onChange: (listener: () => void) => onMotionChange(() => listener()),
26
+ };
27
+ rt.onCleanup(mountCssPause(rootEl, env, setBackend));
28
+ });
29
+ return {
30
+ backend,
31
+ root: (el) => {
32
+ rootEl = el;
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,35 @@
1
+ // The Solid shell around `mountEffect`: the backend label as a signal (the server's answer until
2
+ // the island mounts), refs for the root and the canvas, and the mount run once from an effect so a
3
+ // server render never reaches a browser API. Every animated entry's `.tsx` calls this and nothing
4
+ // else that touches the DOM.
5
+
6
+ import { solid } from '@ultimat3/ui';
7
+ import type { EffectBackend } from './backend';
8
+ import { browserHost } from './effect-host';
9
+ import { type EffectSpec, mountEffect } from './effect-mount';
10
+
11
+ export interface EffectBinding {
12
+ readonly backend: () => EffectBackend;
13
+ readonly root: (el: HTMLElement) => void;
14
+ readonly canvas: (el: HTMLCanvasElement) => void;
15
+ }
16
+
17
+ export function useEffectMount(spec: EffectSpec, server: EffectBackend): EffectBinding {
18
+ const rt = solid();
19
+ const [backend, setBackend] = rt.createSignal<EffectBackend>(server);
20
+ let rootEl: HTMLElement | undefined;
21
+ let canvasEl: HTMLCanvasElement | undefined;
22
+ rt.createEffect(() => {
23
+ if (rootEl === undefined) return;
24
+ rt.onCleanup(mountEffect(rootEl, canvasEl, spec, browserHost(), setBackend));
25
+ });
26
+ return {
27
+ backend,
28
+ root: (el) => {
29
+ rootEl = el;
30
+ },
31
+ canvas: (el) => {
32
+ canvasEl = el;
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,26 @@
1
+ // Whether an element is worth animating: on screen (ui's one IntersectionObserver module, `inView`)
2
+ // AND in a visible tab. One function, used by the effect host and by the CSS-only pause.
3
+
4
+ import { inView } from '@ultimat3/ui/motion';
5
+
6
+ export function observeVisibility(el: Element, onVisible: (visible: boolean) => void): () => void {
7
+ let onScreen = false;
8
+ const report = (): void => onVisible(onScreen && !document.hidden);
9
+ const stopInView = inView(
10
+ el,
11
+ () => {
12
+ onScreen = true;
13
+ report();
14
+ return () => {
15
+ onScreen = false;
16
+ report();
17
+ };
18
+ },
19
+ { once: false },
20
+ );
21
+ document.addEventListener('visibilitychange', report);
22
+ return () => {
23
+ stopInView();
24
+ document.removeEventListener('visibilitychange', report);
25
+ };
26
+ }