@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.
- package/CATALOG.md +169 -0
- package/CLAUDE.md +29 -0
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/package.json +56 -4
- package/src/_effect.scss +53 -0
- package/src/aurora/Aurora.module.scss +56 -0
- package/src/aurora/Aurora.tsx +35 -0
- package/src/aurora/aurora-view.ts +32 -0
- package/src/backend.ts +34 -0
- package/src/canvas-mount.ts +61 -0
- package/src/count-up/CountUp.tsx +51 -0
- package/src/count-up/count-up-run.ts +59 -0
- package/src/count-up/count-up-view.ts +56 -0
- package/src/css-pause.ts +50 -0
- package/src/effect-canvas/EffectCanvas.module.scss +23 -0
- package/src/effect-canvas/EffectCanvas.tsx +51 -0
- package/src/effect-canvas/effect-canvas-view.ts +33 -0
- package/src/effect-host.ts +54 -0
- package/src/effect-mount.ts +114 -0
- package/src/errors.ts +33 -0
- package/src/glass-surface/GlassSurface.module.scss +25 -0
- package/src/glass-surface/GlassSurface.tsx +29 -0
- package/src/glass-surface/glass-surface-view.ts +33 -0
- package/src/gradient-orbs/GradientOrbs.module.scss +49 -0
- package/src/gradient-orbs/GradientOrbs.tsx +41 -0
- package/src/gradient-orbs/gradient-orbs-view.ts +77 -0
- package/src/grid-glow/GridGlow.module.scss +50 -0
- package/src/grid-glow/GridGlow.tsx +39 -0
- package/src/grid-glow/grid-glow-view.ts +40 -0
- package/src/index.ts +45 -0
- package/src/marquee/Marquee.module.scss +52 -0
- package/src/marquee/Marquee.tsx +31 -0
- package/src/marquee/marquee-view.ts +25 -0
- package/src/mosaic-grid/MosaicGrid.module.scss +39 -0
- package/src/mosaic-grid/MosaicGrid.tsx +59 -0
- package/src/mosaic-grid/mosaic-grid-view.ts +96 -0
- package/src/motion-port.ts +22 -0
- package/src/noise/Noise.module.scss +22 -0
- package/src/noise/Noise.tsx +49 -0
- package/src/noise/noise-view.ts +38 -0
- package/src/palette.ts +41 -0
- package/src/pixel-budget.ts +42 -0
- package/src/props.ts +61 -0
- package/src/shader-background/ShaderBackground.module.scss +70 -0
- package/src/shader-background/ShaderBackground.tsx +60 -0
- package/src/shader-background/load-preset.ts +19 -0
- package/src/shader-background/presets/dots.ts +59 -0
- package/src/shader-background/presets/grain.ts +59 -0
- package/src/shader-background/presets/mesh.ts +78 -0
- package/src/shader-background/shader-background-canvas.ts +116 -0
- package/src/shader-background/shader-background-view.ts +98 -0
- package/src/shader-background/uniform-pack.ts +11 -0
- package/src/shader-load.ts +17 -0
- package/src/shader-mount.ts +197 -0
- package/src/shimmer/Shimmer.module.scss +23 -0
- package/src/shimmer/Shimmer.tsx +19 -0
- package/src/spotlight-card/SpotlightCard.module.scss +29 -0
- package/src/spotlight-card/SpotlightCard.tsx +28 -0
- package/src/spotlight-card/spotlight-card-view.ts +37 -0
- package/src/spotlight-card/spotlight-wire.ts +34 -0
- package/src/text-reveal/TextReveal.module.scss +47 -0
- package/src/text-reveal/TextReveal.tsx +48 -0
- package/src/text-reveal/text-reveal-view.ts +38 -0
- package/src/tilt/Tilt.module.scss +18 -0
- package/src/tilt/Tilt.tsx +30 -0
- package/src/tilt/tilt-view.ts +64 -0
- package/src/tilt/tilt-wire.ts +50 -0
- package/src/use-css-pause.ts +35 -0
- package/src/use-effect-mount.ts +35 -0
- package/src/visibility.ts +26 -0
package/CATALOG.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<!-- GENERATED by @ultimat3/ui's catalog builder from @ultimat3/effects's components. Do not edit by hand. -->
|
|
2
|
+
|
|
3
|
+
# @ultimat3/effects catalog
|
|
4
|
+
|
|
5
|
+
Every component, projected from source. Import all of it from `@ultimat3/effects`.
|
|
6
|
+
|
|
7
|
+
14 components: `Aurora` · `CountUp` · `EffectCanvas` · `GlassSurface` · `GradientOrbs` · `GridGlow` · `Marquee` · `MosaicGrid` · `Noise` · `ShaderBackground` · `Shimmer` · `SpotlightCard` · `TextReveal` · `Tilt`
|
|
8
|
+
|
|
9
|
+
## Components
|
|
10
|
+
|
|
11
|
+
### Aurora
|
|
12
|
+
|
|
13
|
+
Northern-lights bands behind a hero, in CSS alone: three role-coloured radial gradients drifting on transform. 0 B of JavaScript on a `site/` page; under reduced motion the global rule stills the drift and the bands' base position (frame 0) is what remains.
|
|
14
|
+
|
|
15
|
+
| Prop | Type | Required | Notes |
|
|
16
|
+
|---|---|---|---|
|
|
17
|
+
| `roles` | `readonly ColorRole[]` | — | Exactly three colour roles, one per band. Default `['accent', 'info', 'success']`. |
|
|
18
|
+
| `intensity` | `number` | — | Band opacity, 0..1. Default 0.5. |
|
|
19
|
+
| `speed` | `number` | — | Drift speed multiplier, 0.25..4. Default 1. |
|
|
20
|
+
| `children` | `JSX.Element` | — | What the aurora sits behind. |
|
|
21
|
+
| `class` | `string` | — | |
|
|
22
|
+
|
|
23
|
+
### CountUp
|
|
24
|
+
|
|
25
|
+
A number that counts to its value. The server renders the FINAL text, so without script, under reduced motion and for a crawler the figure is already right; the tween is an enhancement.
|
|
26
|
+
|
|
27
|
+
| Prop | Type | Required | Notes |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| `value` | `CountTarget` | yes | The final value: a number, or a `Money` (counted in minor units, formatted by currency). |
|
|
30
|
+
| `from` | `number` | — | |
|
|
31
|
+
| `ms` | `number` | — | Tween length in ms; 0 shows the value at once. |
|
|
32
|
+
| `format` | `Intl.NumberFormatOptions` | — | `Intl.NumberFormat` options for a plain number. |
|
|
33
|
+
| `class` | `string` | — | |
|
|
34
|
+
|
|
35
|
+
### EffectCanvas
|
|
36
|
+
|
|
37
|
+
The escape hatch for an effect the catalogue does not have: an app's own Canvas2D `draw` or WebGL2 `shader`, mounted on the same budget, pause and lost-context rules as every built-in. `fallback` is REQUIRED by type — it is the server frame, the reduced-motion frame, the no-GPU frame.
|
|
38
|
+
|
|
39
|
+
| Prop | Type | Required | Notes |
|
|
40
|
+
|---|---|---|---|
|
|
41
|
+
| `fallback` | `JSX.Element` | yes | What shows before an island draws, under reduced motion, and with no usable context. |
|
|
42
|
+
| `roles` | `readonly ColorRole[]` | — | Roles resolved to channels for `draw`/`shader`, 1..8. Default `['accent']`. |
|
|
43
|
+
| `speed` | `number` | — | Time multiplier, 0.25..4. Default 1. |
|
|
44
|
+
| `children` | `JSX.Element` | — | |
|
|
45
|
+
| `class` | `string` | — | |
|
|
46
|
+
| `draw` | `(colours: () => readonly Rgb[]) => CanvasDraw \| ((colours: () => readonly Rgb[]) => CanvasDraw)` | — | |
|
|
47
|
+
| `shader` | `((colours: () => readonly Rgb[]) => Promise<ShaderProgram>) \| (colours: () => readonly Rgb[]) => Promise<ShaderProgram>` | — | |
|
|
48
|
+
|
|
49
|
+
### GlassSurface
|
|
50
|
+
|
|
51
|
+
A translucent pane over whatever is behind it, with the palette's text contrast kept (the alpha has a measured floor) and an opaque fill under `prefers-reduced-transparency`.
|
|
52
|
+
|
|
53
|
+
| Prop | Type | Required | Notes |
|
|
54
|
+
|---|---|---|---|
|
|
55
|
+
| `alpha` | `number` | — | Pane opacity 0-1; never below the contrast-measured floor. |
|
|
56
|
+
| `children` | `JSX.Element` | — | |
|
|
57
|
+
| `class` | `string` | — | |
|
|
58
|
+
|
|
59
|
+
### GradientOrbs
|
|
60
|
+
|
|
61
|
+
Soft role-coloured orbs drifting behind a surface, moved on transform and opacity only. The server frame floats in CSS; in an island the drift also holds offscreen and in a hidden tab.
|
|
62
|
+
|
|
63
|
+
| Prop | Type | Required | Notes |
|
|
64
|
+
|---|---|---|---|
|
|
65
|
+
| `roles` | `readonly ColorRole[]` | — | One orb per role, 1..6. Default `['accent', 'info', 'chart-3']`. |
|
|
66
|
+
| `speed` | `number` | — | Drift speed multiplier, 0.25..4. Default 1. |
|
|
67
|
+
| `intensity` | `number` | — | Orb opacity, 0..1. Default 0.6. |
|
|
68
|
+
| `children` | `JSX.Element` | — | What the orbs sit behind. |
|
|
69
|
+
| `class` | `string` | — | |
|
|
70
|
+
|
|
71
|
+
### GridGlow
|
|
72
|
+
|
|
73
|
+
The instrument-panel ground: ui's `grid-texture` with an accent glow drifting across it, in CSS alone. Both are withdrawn under `prefers-contrast: more` and `forced-colors`, where texture behind text is noise.
|
|
74
|
+
|
|
75
|
+
| Prop | Type | Required | Notes |
|
|
76
|
+
|---|---|---|---|
|
|
77
|
+
| `role` | `ColorRole` | — | The glow's colour role. Default `'accent'`. |
|
|
78
|
+
| `speed` | `number` | — | Glow drift speed multiplier, 0.25..4. Default 1. |
|
|
79
|
+
| `scanlines` | `boolean` | — | Horizontal scanlines over the grid. Default false. |
|
|
80
|
+
| `glow` | `boolean` | — | The drifting glow. Default true; false leaves the still grid. |
|
|
81
|
+
| `children` | `JSX.Element` | — | What the grid sits behind. |
|
|
82
|
+
| `class` | `string` | — | |
|
|
83
|
+
|
|
84
|
+
### Marquee
|
|
85
|
+
|
|
86
|
+
An endless strip. The duplicate track is `aria-hidden` and `inert` (a link inside must not be tabbable twice); pausing and RTL are CSS, so the strip needs no script.
|
|
87
|
+
|
|
88
|
+
| Prop | Type | Required | Notes |
|
|
89
|
+
|---|---|---|---|
|
|
90
|
+
| `children` | `() => JSX.Element` | yes | Called once per track: a DOM node can only live in one place. |
|
|
91
|
+
| `seconds` | `number` | — | Seconds for one loop. |
|
|
92
|
+
| `reverse` | `boolean` | — | |
|
|
93
|
+
| `class` | `string` | — | |
|
|
94
|
+
|
|
95
|
+
### MosaicGrid
|
|
96
|
+
|
|
97
|
+
A holographic tile wall: tiles shifting between two colour roles. The server renders frame 0 as real tiles (no blank canvas, no script needed); an island redraws the same function on a Canvas2D that `frameLoop` pauses offscreen, in a hidden tab and under reduced motion.
|
|
98
|
+
|
|
99
|
+
| Prop | Type | Required | Notes |
|
|
100
|
+
|---|---|---|---|
|
|
101
|
+
| `cols` | `number` | — | Tiles across, 4..32. Default 16. |
|
|
102
|
+
| `rows` | `number` | — | Tiles down, 3..20. Default 9. |
|
|
103
|
+
| `roles` | `readonly ColorRole[]` | — | The two colour roles tiles shift between. Default `['accent', 'info']`. |
|
|
104
|
+
| `speed` | `number` | — | Shift speed multiplier, 0.25..4. Default 1. |
|
|
105
|
+
| `children` | `JSX.Element` | — | What the mosaic sits behind. |
|
|
106
|
+
| `class` | `string` | — | |
|
|
107
|
+
|
|
108
|
+
### Noise
|
|
109
|
+
|
|
110
|
+
Film grain over a surface: an SVG turbulence filter tinted with a colour role. Static by nature (no animation, no frame loop, no script), so it costs a `site/` page nothing and has no motion for reduced motion to take away.
|
|
111
|
+
|
|
112
|
+
| Prop | Type | Required | Notes |
|
|
113
|
+
|---|---|---|---|
|
|
114
|
+
| `opacity` | `number` | — | Grain opacity, 0..1. Default 0.12. |
|
|
115
|
+
| `role` | `ColorRole` | — | The grain's colour role. Default `'fg'`. |
|
|
116
|
+
| `children` | `JSX.Element` | — | What the grain lies over. |
|
|
117
|
+
| `class` | `string` | — | |
|
|
118
|
+
|
|
119
|
+
### ShaderBackground
|
|
120
|
+
|
|
121
|
+
A GPU background behind a hero: `mesh`, `grain` or `dots`, our own GLSL on our own WebGL2 mount. The server paints frame 0 in CSS (no script, no flash); an island fetches only its preset's chunk, draws on WebGL2 or else Canvas2D, and falls back to that frame under reduced motion.
|
|
122
|
+
|
|
123
|
+
| Prop | Type | Required | Notes |
|
|
124
|
+
|---|---|---|---|
|
|
125
|
+
| `preset` | `ShaderPreset` | — | Which shader. Default `'mesh'`. |
|
|
126
|
+
| `roles` | `readonly ColorRole[]` | — | `[ground, a, b, c]`: four colour roles. Default `['bg-soft', 'accent', 'info', 'chart-3']`. |
|
|
127
|
+
| `speed` | `number` | — | Animation speed multiplier, 0.25..4. Default 1. |
|
|
128
|
+
| `children` | `JSX.Element` | — | What the background sits behind. |
|
|
129
|
+
| `class` | `string` | — | |
|
|
130
|
+
|
|
131
|
+
### Shimmer
|
|
132
|
+
|
|
133
|
+
Text with the shared highlight sweep. The sweep is ui's `@mixin shimmer` (the one Skeleton paints); this component only clips it to the glyphs.
|
|
134
|
+
|
|
135
|
+
| Prop | Type | Required | Notes |
|
|
136
|
+
|---|---|---|---|
|
|
137
|
+
| `children` | `JSX.Element` | — | |
|
|
138
|
+
| `class` | `string` | — | |
|
|
139
|
+
|
|
140
|
+
### SpotlightCard
|
|
141
|
+
|
|
142
|
+
A surface with a highlight that follows the pointer and, for a keyboard user, the focused control. The highlight is CSS; the script only writes two custom properties.
|
|
143
|
+
|
|
144
|
+
| Prop | Type | Required | Notes |
|
|
145
|
+
|---|---|---|---|
|
|
146
|
+
| `children` | `JSX.Element` | — | |
|
|
147
|
+
| `class` | `string` | — | |
|
|
148
|
+
|
|
149
|
+
### TextReveal
|
|
150
|
+
|
|
151
|
+
Text that arrives piece by piece. One readable node carries the words; the animated split is its `aria-hidden` twin, so a screen reader hears the sentence once and unbroken.
|
|
152
|
+
|
|
153
|
+
| Prop | Type | Required | Notes |
|
|
154
|
+
|---|---|---|---|
|
|
155
|
+
| `text` | `string` | yes | Already-translated text. |
|
|
156
|
+
| `by` | `RevealBy` | — | |
|
|
157
|
+
| `locale` | `string` | — | Locale override; defaults to the page's (`useUi().locale`). |
|
|
158
|
+
| `stepMs` | `number` | — | Milliseconds between pieces; shrunk for long texts. |
|
|
159
|
+
| `class` | `string` | — | |
|
|
160
|
+
|
|
161
|
+
### Tilt
|
|
162
|
+
|
|
163
|
+
A wrapper that leans toward the pointer. Off — not merely softer — for a coarse pointer, inside a modal's focus trap, and whenever motion is not allowed; the angle never passes `TILT_MAX_DEG`.
|
|
164
|
+
|
|
165
|
+
| Prop | Type | Required | Notes |
|
|
166
|
+
|---|---|---|---|
|
|
167
|
+
| `maxAngle` | `number` | — | Degrees at the card's corner, capped at `TILT_MAX_DEG` (15). |
|
|
168
|
+
| `children` | `JSX.Element` | — | |
|
|
169
|
+
| `class` | `string` | — | |
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @ultimat3/effects — boundary
|
|
2
|
+
|
|
3
|
+
Tier 5 (its floor: it imports `ui`, tier 4). Imports `core`, `money`, `ui`, `ui/motion`. Never sideways, never upward. Nothing in the framework imports it.
|
|
4
|
+
|
|
5
|
+
## Ideas only — never code (non-negotiable)
|
|
6
|
+
|
|
7
|
+
Every engine here is OURS. React Bits, Paper Shaders, shaders.com, Motion, ogl, 21st.dev, reui and
|
|
8
|
+
shadcn are studied for behaviour and technique ONLY. **React Bits source is never opened** (MIT +
|
|
9
|
+
Commons Clause forbids redistributing "a ported version"): study it running in a browser. No file
|
|
10
|
+
here is copied, ported or transliterated from any of them, and no runtime dependency beyond
|
|
11
|
+
`@ultimat3/*` is added. GLSL is written from scratch from published maths (value noise, smoothstep
|
|
12
|
+
falloff, CSS gradient-line geometry).
|
|
13
|
+
|
|
14
|
+
| Rule | Detail |
|
|
15
|
+
|---|---|
|
|
16
|
+
| Exports | `src/index.ts`, explicit, no `export *` |
|
|
17
|
+
| Errors | `src/errors.ts`, `EffectsInvalidValueError` (`X_EFFECTS_INVALID_VALUE`) from every prop screen (`props.ts`); never a bare `Error`. No code for "no WebGL2": it is a backend |
|
|
18
|
+
| Files | one responsibility each, < 200 lines, tests beside the source |
|
|
19
|
+
| Tier label | every root carries `data-effect-backend` (`static`/`css`/`canvas`/`webgl2`), decided ONLY by `backend.ts`'s `pickBackend` |
|
|
20
|
+
| First frame | the server frame is computed by the same function as animated frame 0 (`meshPoints(0)`, `mosaicCell(c, r, 0)`, `dotsRamp(0) = 0`); the canvas never flashes in over a different picture |
|
|
21
|
+
| Colour | role tokens only: `var(--color-<role>)` in sheets and inline custom properties, `resolvePalette()` (resolved `--color-*` channels) for canvas and GLSL. Re-read on a theme change |
|
|
22
|
+
| Pause | frames run through `frameLoop` (`motion-port.ts`); on-screen is ui's `inView` (`effect-host.ts`), never a second IntersectionObserver; CSS animations hold under `data-effect-paused` (`_effect.scss`); `html[data-motion='paused']` is ui's global guard, landing them on frame 0 |
|
|
23
|
+
| Pixels | `EFFECT_PIXELS` is the one DPR floor/cap/pixel-ceiling token; no mount picks its own |
|
|
24
|
+
| Network | none, from any entry: `network-seal.test.ts` mounts all fourteen for 1,000 frames with the four APIs sealed |
|
|
25
|
+
| GLSL | only in `src/shader-background/presets/*.ts`, each loaded by its own literal `import()` (`load-preset.ts`); `shader-mount.ts` is lazy too. The vertex shader is duplicated per preset on purpose (a shared module would be a fourth chunk) |
|
|
26
|
+
| Accessibility | the decorative layer (and any canvas) is `aria-hidden="true"`; content sits outside it |
|
|
27
|
+
| Tests | rules in `*-view.ts` (pure), wiring through `mount-harness-fixture.ts` (islands) and `@ultimat3/core/render-nodes` (server frame); `fake-host-fixture.ts` is the fake GL/2D/host. Fixtures are TEST-ONLY |
|
|
28
|
+
|
|
29
|
+
Commands: `bun test ./packages/effects/` (the `./` matters), `bun run --filter @ultimat3/effects catalog` (CATALOG.md is gated by `catalog.test.ts`).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 developerz.ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ultimat3/effects
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Server-rendered-first visual effects for Ultimate apps: six backgrounds, seven interaction and
|
|
4
|
+
text effects, and `EffectCanvas` for your own. Every entry renders a real frame on the server,
|
|
5
|
+
works with scripting off, honours reduced motion and `MotionToggle`, draws colour from role tokens
|
|
6
|
+
only, and makes zero network requests. Apps that never import it pay 0 B.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
bun add @ultimat3/effects
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { Aurora, ShaderBackground } from '@ultimat3/effects';
|
|
14
|
+
import type { JSX } from 'solid-js';
|
|
15
|
+
|
|
16
|
+
// CSS only: 0 B of JavaScript on a site/ page.
|
|
17
|
+
export const Hero = (props: { title: string }): JSX.Element => (
|
|
18
|
+
<Aurora intensity={0.6}>
|
|
19
|
+
<h1>{props.title}</h1>
|
|
20
|
+
</Aurora>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// An island: WebGL2, else Canvas2D, else the server frame.
|
|
24
|
+
export const Backdrop = (props: { children: JSX.Element }): JSX.Element => (
|
|
25
|
+
<ShaderBackground preset="mesh">{props.children}</ShaderBackground>
|
|
26
|
+
);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Guide: [Effects](https://github.com/developerz-ai/ultimate/wiki/Effects) · props: [CATALOG.md](CATALOG.md).
|
|
30
|
+
|
|
31
|
+
## The tier contract
|
|
32
|
+
|
|
33
|
+
Every root carries `data-effect-backend`:
|
|
34
|
+
|
|
35
|
+
| Value | When |
|
|
36
|
+
|---|---|
|
|
37
|
+
| `static` | reduced motion, `html[data-motion="paused"]`, or an entry whose frame does not animate |
|
|
38
|
+
| `css` | the server frame animates in CSS (any page, any island before it mounts) |
|
|
39
|
+
| `canvas` | an island with no WebGL2 (or an entry that only draws 2D) |
|
|
40
|
+
| `webgl2` | an island whose WebGL2 context compiled the program and is not lost |
|
|
41
|
+
|
|
42
|
+
## What it owns
|
|
43
|
+
|
|
44
|
+
| Module | Owns |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `src/backend.ts` | the one backend decision (`pickBackend`) |
|
|
47
|
+
| `src/shader-mount.ts` | our WebGL2 mount: compile/link, uniforms, one full-screen triangle, context loss and restore, dispose. No GLSL |
|
|
48
|
+
| `src/canvas-mount.ts` | the Canvas2D twin: same clock, budget and loop |
|
|
49
|
+
| `src/effect-mount.ts` | what every animated entry's island effect calls: palette → backend → mount → relabel → release |
|
|
50
|
+
| `src/use-effect-mount.ts` | the Solid shell around it (signal + refs + one effect) |
|
|
51
|
+
| `src/effect-host.ts` · `src/motion-port.ts` | the browser, injected: `frameLoop`, `motionAllowed`, `onMotionChange` and `inView` from `@ultimat3/ui/motion` |
|
|
52
|
+
| `src/pixel-budget.ts` | `EFFECT_PIXELS`: the DPR floor, DPR cap and pixel ceiling, one token |
|
|
53
|
+
| `src/palette.ts` · `src/props.ts` | resolved role channels; the prop screens (`X_EFFECTS_INVALID_VALUE`) |
|
|
54
|
+
| `src/<entry>/` | `<Name>.tsx` (markup) + `<Name>.module.scss` + `<name>-view.ts` (the rules, pure) |
|
|
55
|
+
| `src/shader-background/presets/` | one GLSL ES 3.00 program per preset, each its own lazy chunk |
|
|
56
|
+
|
|
57
|
+
## Boundary
|
|
58
|
+
|
|
59
|
+
Tier 5. Imports `@ultimat3/core`, `@ultimat3/money`, `@ultimat3/ui` (and `@ultimat3/ui/motion`).
|
|
60
|
+
Enforced by `bun run boundaries`.
|
|
61
|
+
|
|
62
|
+
## Errors
|
|
63
|
+
|
|
64
|
+
`X_EFFECTS_INVALID_VALUE` — a prop outside the range the entry can draw. "No WebGL2" is never an
|
|
65
|
+
error: it is a backend.
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/effects",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "31.52.0",
|
|
4
|
+
"description": "Server-rendered-first visual effects: backgrounds, shaders, interaction and text, each with a static frame and zero network",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ultimate",
|
|
7
|
+
"bun",
|
|
8
|
+
"framework",
|
|
9
|
+
"effects",
|
|
10
|
+
"webgl2",
|
|
11
|
+
"solidjs",
|
|
12
|
+
"animation"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/developerz-ai/ultimate/wiki/Effects",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": [
|
|
18
|
+
"./src/errors.ts",
|
|
19
|
+
"**/*.scss"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/developerz-ai/ultimate.git",
|
|
24
|
+
"directory": "packages/effects"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"provenance": true
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./src/index.ts"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"src",
|
|
35
|
+
"!src/**/*.test.ts",
|
|
36
|
+
"!src/**/*-fixture.ts",
|
|
37
|
+
"CATALOG.md",
|
|
38
|
+
"CLAUDE.md",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"bun": ">=1.4.4"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
47
|
+
"test": "bun test",
|
|
48
|
+
"catalog": "bun run ../ui/src/catalog/build-catalog.ts . 'src/*/[A-Z]*.tsx' @ultimat3/effects"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@ultimat3/core": "31.52.0",
|
|
52
|
+
"@ultimat3/money": "31.52.0",
|
|
53
|
+
"@ultimat3/ui": "31.52.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"solid-js": "^1.9.18"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/_effect.scss
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// The frame every background shares: a root that stacks, a decorative layer under the content, a
|
|
2
|
+
// canvas that shows only while a canvas backend draws, and the offscreen pause a CSS animation
|
|
3
|
+
// obeys (`data-effect-paused`). `MotionToggle`'s `html[data-motion='paused']` needs no rule here:
|
|
4
|
+
// ui's `_motion.scss` guards land every animation on its end state, which is frame 0 (no fill).
|
|
5
|
+
|
|
6
|
+
/// The entry's root: its own stacking context, so the layer never escapes behind the page.
|
|
7
|
+
@mixin root {
|
|
8
|
+
position: relative;
|
|
9
|
+
isolation: isolate;
|
|
10
|
+
overflow: clip;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/// The decorative layer, under the content (an earlier positioned sibling paints first).
|
|
14
|
+
@mixin layer {
|
|
15
|
+
position: absolute;
|
|
16
|
+
inset: 0;
|
|
17
|
+
overflow: clip;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// The content above the layer.
|
|
22
|
+
@mixin content {
|
|
23
|
+
position: relative;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// The canvas fills the layer and is shown only while a canvas backend owns it; under `static`
|
|
27
|
+
/// and `css` the server frame beneath is what the reader sees.
|
|
28
|
+
@mixin canvas($root) {
|
|
29
|
+
position: absolute;
|
|
30
|
+
inset: 0;
|
|
31
|
+
inline-size: 100%;
|
|
32
|
+
block-size: 100%;
|
|
33
|
+
visibility: hidden;
|
|
34
|
+
|
|
35
|
+
#{$root}:is([data-effect-backend='canvas'], [data-effect-backend='webgl2']) & {
|
|
36
|
+
visibility: visible;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// The server frame under a canvas: hidden while a canvas backend draws, so a canvas that clears
|
|
41
|
+
/// to transparent (tile gaps, an app's own `draw`) never shows a stale frame through it.
|
|
42
|
+
@mixin frame($root) {
|
|
43
|
+
#{$root}:is([data-effect-backend='canvas'], [data-effect-backend='webgl2']) & {
|
|
44
|
+
visibility: hidden;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Holds this element's CSS animation while its root is offscreen or in a hidden tab.
|
|
49
|
+
@mixin pausable($root) {
|
|
50
|
+
#{$root}[data-effect-paused] & {
|
|
51
|
+
animation-play-state: paused;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
@use '@ultimat3/ui/tokens' as t;
|
|
2
|
+
@use '../effect' as fx;
|
|
3
|
+
|
|
4
|
+
// One drift cycle, scaled by `--fx-speed`. The base (no transform) is frame 0: the server's frame,
|
|
5
|
+
// and the frame the global reduced-motion rule leaves.
|
|
6
|
+
@keyframes aurora-drift {
|
|
7
|
+
50% {
|
|
8
|
+
transform: translate3d(8%, -6%, 0) rotate(8deg) scale(1.15);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
to {
|
|
12
|
+
transform: translate3d(-6%, 4%, 0) rotate(-6deg) scale(0.95);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.root {
|
|
17
|
+
@include fx.root;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.layer {
|
|
21
|
+
@include fx.layer;
|
|
22
|
+
opacity: var(--fx-intensity, 0.5);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.content {
|
|
26
|
+
@include fx.content;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.band {
|
|
30
|
+
@include fx.pausable('.root');
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset: -25%;
|
|
33
|
+
animation: aurora-drift calc(#{t.duration(slower)} * 30 / var(--fx-speed, 1)) t.easing(in-out)
|
|
34
|
+
infinite alternate;
|
|
35
|
+
will-change: transform;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.band-0 {
|
|
39
|
+
background: radial-gradient(ellipse 55% 35% at 25% 30%, rgb(var(--fx-c0)), transparent 70%);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.band-1 {
|
|
43
|
+
background: radial-gradient(ellipse 50% 30% at 70% 25%, rgb(var(--fx-c1)), transparent 70%);
|
|
44
|
+
animation-delay: calc(#{t.duration(slower)} * -10 / var(--fx-speed, 1));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.band-2 {
|
|
48
|
+
background: radial-gradient(ellipse 60% 30% at 50% 70%, rgb(var(--fx-c2)), transparent 70%);
|
|
49
|
+
animation-delay: calc(#{t.duration(slower)} * -20 / var(--fx-speed, 1));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@media (forced-colors: active) {
|
|
53
|
+
.layer {
|
|
54
|
+
display: none;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Northern-lights bands behind a hero, in CSS alone: three role-coloured radial gradients drifting
|
|
2
|
+
// on transform. 0 B of JavaScript on a `site/` page; under reduced motion the global rule stills
|
|
3
|
+
// the drift and the bands' base position (frame 0) is what remains.
|
|
4
|
+
|
|
5
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
6
|
+
import { cx } from '@ultimat3/ui';
|
|
7
|
+
import type { JSX } from 'solid-js';
|
|
8
|
+
import styles from './Aurora.module.scss';
|
|
9
|
+
import { AURORA_BACKEND, auroraVars } from './aurora-view';
|
|
10
|
+
|
|
11
|
+
export interface AuroraProps {
|
|
12
|
+
/** Exactly three colour roles, one per band. Default `['accent', 'info', 'success']`. */
|
|
13
|
+
roles?: readonly ColorRole[] | undefined;
|
|
14
|
+
/** Band opacity, 0..1. Default 0.5. */
|
|
15
|
+
intensity?: number | undefined;
|
|
16
|
+
/** Drift speed multiplier, 0.25..4. Default 1. */
|
|
17
|
+
speed?: number | undefined;
|
|
18
|
+
/** What the aurora sits behind. */
|
|
19
|
+
children?: JSX.Element | undefined;
|
|
20
|
+
class?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Aurora(props: AuroraProps): JSX.Element {
|
|
24
|
+
const vars = auroraVars(props);
|
|
25
|
+
return (
|
|
26
|
+
<div class={cx(styles['root'], props.class)} style={vars} data-effect-backend={AURORA_BACKEND}>
|
|
27
|
+
<div class={styles['layer']} aria-hidden="true">
|
|
28
|
+
<span class={cx(styles['band'], styles['band-0'])} />
|
|
29
|
+
<span class={cx(styles['band'], styles['band-1'])} />
|
|
30
|
+
<span class={cx(styles['band'], styles['band-2'])} />
|
|
31
|
+
</div>
|
|
32
|
+
<div class={styles['content']}>{props.children}</div>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Aurora's rules: the validated props as the custom properties its stylesheet animates. Pure, so
|
|
2
|
+
// the server frame and every test read the same numbers; the sheet does the motion.
|
|
3
|
+
|
|
4
|
+
import type { ColorRole } from '@ultimat3/ui';
|
|
5
|
+
import type { EffectBackend } from '../backend';
|
|
6
|
+
import { rangeProp, rolesProp, roleVars } from '../props';
|
|
7
|
+
|
|
8
|
+
/** CSS all the way: the server frame animates in CSS and nothing mounts in an island. */
|
|
9
|
+
export const AURORA_BACKEND: EffectBackend = 'css';
|
|
10
|
+
|
|
11
|
+
export const AURORA_ROLES: readonly ColorRole[] = ['accent', 'info', 'success'];
|
|
12
|
+
export const AURORA_BANDS = 3;
|
|
13
|
+
|
|
14
|
+
export interface AuroraInput {
|
|
15
|
+
readonly roles?: readonly ColorRole[] | undefined;
|
|
16
|
+
readonly intensity?: number | undefined;
|
|
17
|
+
readonly speed?: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function auroraVars(input: AuroraInput): Record<string, string> {
|
|
21
|
+
const roles = rolesProp('Aurora', input.roles, AURORA_ROLES, {
|
|
22
|
+
min: AURORA_BANDS,
|
|
23
|
+
max: AURORA_BANDS,
|
|
24
|
+
});
|
|
25
|
+
const intensity = rangeProp('Aurora', 'intensity', input.intensity, {
|
|
26
|
+
min: 0,
|
|
27
|
+
max: 1,
|
|
28
|
+
fallback: 0.5,
|
|
29
|
+
});
|
|
30
|
+
const speed = rangeProp('Aurora', 'speed', input.speed, { min: 0.25, max: 4, fallback: 1 });
|
|
31
|
+
return { ...roleVars(roles), '--fx-intensity': String(intensity), '--fx-speed': String(speed) };
|
|
32
|
+
}
|
package/src/backend.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Which tier draws an effect: the one decision behind `data-effect-backend`. Static under reduced
|
|
2
|
+
// motion or a user pause; CSS before hydration (or when that is all an entry has); then the best
|
|
3
|
+
// context the island actually got. "No WebGL2" is a backend, never an error.
|
|
4
|
+
|
|
5
|
+
export const EFFECT_BACKENDS = ['static', 'css', 'canvas', 'webgl2'] as const;
|
|
6
|
+
|
|
7
|
+
export type EffectBackend = (typeof EFFECT_BACKENDS)[number];
|
|
8
|
+
|
|
9
|
+
/** The richest tier an entry can draw with. A canvas entry never climbs to WebGL2. */
|
|
10
|
+
export type EffectWants = 'css' | 'canvas' | 'webgl2';
|
|
11
|
+
|
|
12
|
+
export interface BackendInput {
|
|
13
|
+
/** `motionAllowed()`: false under `prefers-reduced-motion`, `data-motion="paused"`. */
|
|
14
|
+
readonly motion: boolean;
|
|
15
|
+
/** An island after mount. A server render, or an island before it, is not. */
|
|
16
|
+
readonly hydrated: boolean;
|
|
17
|
+
/** Whether the entry's own stylesheet animates its server frame. */
|
|
18
|
+
readonly css: boolean;
|
|
19
|
+
readonly wants: EffectWants;
|
|
20
|
+
readonly webgl2: boolean;
|
|
21
|
+
readonly canvas: boolean;
|
|
22
|
+
/** A WebGL2 context the browser took back. The canvas is spoken for: no 2D on it either. */
|
|
23
|
+
readonly lost: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function pickBackend(input: BackendInput): EffectBackend {
|
|
27
|
+
const frame: EffectBackend = input.css ? 'css' : 'static';
|
|
28
|
+
if (!input.motion) return 'static';
|
|
29
|
+
if (!input.hydrated || input.wants === 'css') return frame;
|
|
30
|
+
if (input.lost) return frame;
|
|
31
|
+
if (input.wants === 'webgl2' && input.webgl2) return 'webgl2';
|
|
32
|
+
if (input.canvas) return 'canvas';
|
|
33
|
+
return frame;
|
|
34
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// The Canvas2D twin of `shader-mount.ts`: the same clock, pixel budget and frame loop, drawing
|
|
2
|
+
// with a function instead of a program. What an island without WebGL2 animates with, and what
|
|
3
|
+
// `EffectCanvas` hands an app's own `draw`.
|
|
4
|
+
|
|
5
|
+
import type { EffectHost } from './effect-host';
|
|
6
|
+
import { backingSize, EFFECT_PIXELS, type PixelBudget } from './pixel-budget';
|
|
7
|
+
|
|
8
|
+
export interface CanvasFrame {
|
|
9
|
+
/** Seconds of animation since frame 0, already scaled by speed. */
|
|
10
|
+
readonly time: number;
|
|
11
|
+
/** CSS pixels: the context is pre-scaled, so a draw never multiplies by the ratio itself. */
|
|
12
|
+
readonly width: number;
|
|
13
|
+
readonly height: number;
|
|
14
|
+
/** Backing pixels per CSS pixel, already applied to the context's transform. */
|
|
15
|
+
readonly scale: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type CanvasDraw = (ctx: CanvasRenderingContext2D, frame: CanvasFrame) => void;
|
|
19
|
+
|
|
20
|
+
export interface CanvasMountOptions {
|
|
21
|
+
readonly speed: number;
|
|
22
|
+
readonly budget?: PixelBudget | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const MAX_STEP_MS = 100;
|
|
26
|
+
|
|
27
|
+
/** `undefined` when the canvas has no 2D context to give (already WebGL's, or none at all). */
|
|
28
|
+
export function mountCanvas(
|
|
29
|
+
canvas: HTMLCanvasElement,
|
|
30
|
+
draw: CanvasDraw,
|
|
31
|
+
host: EffectHost,
|
|
32
|
+
options: CanvasMountOptions,
|
|
33
|
+
): (() => void) | undefined {
|
|
34
|
+
const ctx = canvas.getContext('2d');
|
|
35
|
+
if (ctx === null) return undefined;
|
|
36
|
+
const budget = options.budget ?? EFFECT_PIXELS;
|
|
37
|
+
let box: readonly [number, number] = [0, 0];
|
|
38
|
+
let elapsed = 0;
|
|
39
|
+
let last: number | undefined;
|
|
40
|
+
|
|
41
|
+
const tick = (): void => {
|
|
42
|
+
const now = host.now();
|
|
43
|
+
elapsed += last === undefined ? 0 : Math.min(now - last, MAX_STEP_MS) * options.speed;
|
|
44
|
+
last = now;
|
|
45
|
+
const size = backingSize(box[0], box[1], host.dpr(), budget);
|
|
46
|
+
if (canvas.width !== size.width) canvas.width = size.width;
|
|
47
|
+
if (canvas.height !== size.height) canvas.height = size.height;
|
|
48
|
+
ctx.setTransform(size.scale, 0, 0, size.scale, 0, 0);
|
|
49
|
+
ctx.clearRect(0, 0, box[0], box[1]);
|
|
50
|
+
draw(ctx, { time: elapsed / 1000, width: box[0], height: box[1], scale: size.scale });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const unobserve = host.observeSize(canvas, (width, height) => {
|
|
54
|
+
box = [width, height];
|
|
55
|
+
});
|
|
56
|
+
const stop = host.motion.loop(tick, canvas);
|
|
57
|
+
return () => {
|
|
58
|
+
stop();
|
|
59
|
+
unobserve();
|
|
60
|
+
};
|
|
61
|
+
}
|