@uxfront/scene 0.1.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 (51) hide show
  1. package/README.md +128 -0
  2. package/dist/experience.d.ts +40 -0
  3. package/dist/experience.js +306 -0
  4. package/dist/formations/corridor/index.d.ts +8 -0
  5. package/dist/formations/corridor/index.js +52 -0
  6. package/dist/formations/corridor/shader.js +37 -0
  7. package/dist/formations/index.d.ts +11 -0
  8. package/dist/formations/index.js +11 -0
  9. package/dist/formations/ink/index.d.ts +10 -0
  10. package/dist/formations/ink/index.js +53 -0
  11. package/dist/formations/ink/shader.js +177 -0
  12. package/dist/formations/monolith/index.d.ts +5 -0
  13. package/dist/formations/monolith/index.js +49 -0
  14. package/dist/formations/monolith/mark.js +89 -0
  15. package/dist/formations/monolith/shader.js +120 -0
  16. package/dist/formations/plates/art.d.ts +46 -0
  17. package/dist/formations/plates/art.js +238 -0
  18. package/dist/formations/plates/geometry.d.ts +5 -0
  19. package/dist/formations/plates/geometry.js +8 -0
  20. package/dist/formations/plates/index.d.ts +13 -0
  21. package/dist/formations/plates/index.js +67 -0
  22. package/dist/formations/plates/shader.js +97 -0
  23. package/dist/formations/prism/geometry.d.ts +4 -0
  24. package/dist/formations/prism/geometry.js +15 -0
  25. package/dist/formations/prism/index.d.ts +9 -0
  26. package/dist/formations/prism/index.js +64 -0
  27. package/dist/formations/prism/shader.js +140 -0
  28. package/dist/formations/tokens/geometry.d.ts +4 -0
  29. package/dist/formations/tokens/geometry.js +22 -0
  30. package/dist/formations/tokens/index.d.ts +18 -0
  31. package/dist/formations/tokens/index.js +79 -0
  32. package/dist/formations/tokens/shader.js +125 -0
  33. package/dist/gl/compose.d.ts +14 -0
  34. package/dist/gl/compose.js +52 -0
  35. package/dist/gl/constants.d.ts +6 -0
  36. package/dist/gl/constants.js +7 -0
  37. package/dist/gl/engine.js +559 -0
  38. package/dist/gl/formation.d.ts +7 -0
  39. package/dist/gl/formation.js +39 -0
  40. package/dist/gl/glsl.d.ts +9 -0
  41. package/dist/gl/glsl.js +419 -0
  42. package/dist/gl/math.d.ts +16 -0
  43. package/dist/gl/math.js +102 -0
  44. package/dist/gl/stage.d.ts +28 -0
  45. package/dist/gl/stage.js +55 -0
  46. package/dist/gl/types.d.ts +103 -0
  47. package/dist/index.d.ts +10 -0
  48. package/dist/index.js +9 -0
  49. package/dist/layout.d.ts +9 -0
  50. package/dist/layout.js +10 -0
  51. package/package.json +51 -0
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # @uxfront/scene
2
+
3
+ The scroll-driven WebGL particle scene behind the uxfront.com family of homepages (UXFront, Open Components, Unframework, Styleframe, Inkline). One GPU particle system turns into a new **formation** for each section of the page as you scroll. The package has no framework dependency: `@uxfront/ui` wraps it in Vue components, and any other page can drive it directly.
4
+
5
+ - **A pipeline.** Morphs between formations under curl noise, an intro that rises from a floor line, a cursor lens, a click shockwave, a mirror floor, light trails, bloom and a filmic composite.
6
+ - **A catalog.** Six formations: `monolith`, `plates`, `prism`, `tokens`, `ink` and `corridor`.
7
+ - **A controller.** `createExperience` maps the page's sections to formations, runs Lenis smooth scrolling, reveals copy, steps through highlights and pins DOM labels to the formations.
8
+
9
+ Pages stay fast. The engine and each formation's GLSL are separate chunks, imported only once the page is idle. Shaders compile without blocking the main thread. Slow GPUs get fewer particles at a lower resolution, and without a capable GPU (no WebGL2, a software rasterizer, a lost context) the state switches to `"fallback"`, so the page can show a static image instead.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ pnpm add @uxfront/scene
15
+ ```
16
+
17
+ In a Nuxt app, use `@uxfront/layer-ui` instead: it wires up everything below.
18
+
19
+ ## Usage
20
+
21
+ Mark up one section per formation, in order, then start the experience on the client:
22
+
23
+ ```html
24
+ <canvas id="stage" style="position: fixed; inset: 0; width: 100%; height: 100lvh"></canvas>
25
+ <main id="page">
26
+ <section data-stage>…</section>
27
+ <section data-stage data-steps="3">…</section>
28
+ <section data-stage>…</section>
29
+ </main>
30
+ ```
31
+
32
+ ```ts
33
+ import { createExperience } from "@uxfront/scene";
34
+ import { corridor, monolith, plates } from "@uxfront/scene/formations";
35
+
36
+ const experience = createExperience({
37
+ root: document.getElementById("page")!,
38
+ canvas: document.querySelector("canvas")!,
39
+ formations: [
40
+ monolith({ label: "Foundation" }),
41
+ plates({ label: "Open Components" }),
42
+ corridor({ label: "Build on it" }),
43
+ ],
44
+ });
45
+
46
+ experience.subscribe(({ chapter, status, motion }) => {
47
+ // Update a HUD, a nav, the fallback…
48
+ });
49
+ experience.setMotion(false); // pause the clock and smooth scrolling
50
+ experience.destroy();
51
+ ```
52
+
53
+ `state` holds `chapter` (the formation held), `activeId` (its section's `id`), `status` (`idle`, `loading`, `ready` or `fallback`), `motion`, `particles` and `fps`. Motion starts off when the visitor prefers reduced motion.
54
+
55
+ ### Page contract
56
+
57
+ | Markup | Effect |
58
+ | -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
59
+ | `[data-stage]` under `root` | One section per formation, in DOM order. A section holds its formation while pinned, and the next one morphs in as it scrolls in. |
60
+ | `data-steps="n"` on a section | While pinned, the section gets `data-step="0…n-1"` as it is read, to highlight `[data-step-item]`s. |
61
+ | `[data-reveal]` under `root` | Gets `.is-in` once scrolled into view. |
62
+ | `[data-anchor="key:id"]` under `anchorRoots` | Positioned (`transform`, `opacity`, `visibility`) over the formation's anchor while it shows. |
63
+ | `--ux-progress` on `root` | Page scroll, 0 → 1. |
64
+
65
+ Portrait, squarish and small screens use each formation's `mobile` framing, which leaves the top of the screen to the formation. Lay the copy out with the same breakpoints, exported as `STACKED_QUERY`.
66
+
67
+ ## Catalog
68
+
69
+ Every factory takes `{ label, key?, views?, look? }`. `label` is shown in the HUD. `views` overrides the framing, for example to put a formation on the other side of the copy: `tokens({ label, views: { desktop: { shift: [0.42, 0.02] } } })`. `key` is only needed to use the same formation twice.
70
+
71
+ | Formation | Shows | Anchors |
72
+ | ---------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------- |
73
+ | `monolith` | A 1:4:9 slab of light over a mirror floor, the UXFront mark inlaid in it. | None |
74
+ | `plates` | Three glass plates with line art, drifting apart. `art` swaps the drawings. | `plates:0`–`plates:2`, at the plates' edges |
75
+ | `prism` | A beam split into seven rails that grow as the chapter is read. | `prism:0`–`prism:6`, at the rails' ends |
76
+ | `tokens` | A framed token matrix re-themed in waves. `next()` skips to the next theme. | `tokens:theme`, writes into `[data-theme-name]` |
77
+ | `ink` | Coloured inks poured into water. Scrolling speeds the pour up, or drives it without motion. | None |
78
+ | `corridor` | A corridor of streaking light with long trails. Suits a closing section. | None |
79
+
80
+ ## Writing a formation
81
+
82
+ A formation is a small synchronous description plus a lazily loaded shader:
83
+
84
+ ```ts
85
+ import { defineFormation } from "@uxfront/scene";
86
+
87
+ export const rings = (label: string) =>
88
+ defineFormation({
89
+ key: "rings",
90
+ label,
91
+ views: {
92
+ desktop: { eye: [0, 1, 10], target: [0, 0, 0], fov: 30, span: [2, 2], shift: [0.3, 0] },
93
+ mobile: { eye: [0, 1, 10], target: [0, 0, 0], fov: 34, span: [2, 2], shift: [0, 0.5] },
94
+ },
95
+ look: { bloom: 1.1 },
96
+ shader: () => import("./rings.shader").then((m) => m.shader),
97
+ });
98
+ ```
99
+
100
+ ```ts
101
+ // rings.shader.ts
102
+ import type { FormationShader } from "@uxfront/scene";
103
+
104
+ export const shader: FormationShader = {
105
+ glsl: /* glsl */ `
106
+ uniform float $spin;
107
+
108
+ Particle $main(uint id, float sel, Frame f) {
109
+ uint s = seedOf(id, 0x5EEDu);
110
+ float a = rnd(s) * TAU + $spin * f.time;
111
+ Particle P = blank();
112
+ P.pos = vec3(cos(a), sin(a), 0.0) * mix(1.0, 2.0, f.local);
113
+ P.col = vec3(0.7, 0.8, 1.0) * 0.1;
114
+ return P;
115
+ }
116
+ `,
117
+ setup: ({ gl, get }) => gl.uniform1f(get("spin"), 0.2),
118
+ };
119
+ ```
120
+
121
+ - `$name` identifiers are private: the scene rewrites them to `key_name`, so formations never clash.
122
+ - `$main` returns the position, colour, size and `refl` (mirror reflectivity) of particle `id`. `sel` spreads evenly over [0, 1) across the particles, to split them between the parts of a formation.
123
+ - `Frame f` holds `local` (progress while pinned: 0 before, 1 after), `approach` (0 → 1 while the section scrolls in) and `time`.
124
+ - Shared helpers: `hashU`, `rnd`, `seedOf`, `gauss`, `noised`, `curl`, `bitangent`, `bezier3`, `rrectPoint`, `PI`, `TAU` and `FLOOR_Y`.
125
+ - `setup` uploads uniforms once. `update(uniforms, frame)` runs every frame with the formation's `local`, `approach`, `presence`, `time`, `dt`, `motion` and `scrolled`.
126
+ - `anchors` pin DOM labels: `place(progress, out)` writes a world position and returns extra visibility, and `render(el, progress)` can update the label's content.
127
+
128
+ `composeParticleShader` builds the complete vertex shader, handy for testing a formation's GLSL.
@@ -0,0 +1,40 @@
1
+ import { Formation } from "./gl/types.js";
2
+ //#region src/experience.d.ts
3
+ export type GlStatus = "idle" | "loading" | "ready" | "fallback";
4
+ export interface ExperienceState {
5
+ /** Index of the formation (and section) currently held. */
6
+ chapter: number;
7
+ /** `id` of the section currently held, if it has one. */
8
+ activeId: string | null;
9
+ status: GlStatus;
10
+ /** False when the visitor prefers reduced motion or paused it. */
11
+ motion: boolean;
12
+ particles: number;
13
+ fps: number;
14
+ }
15
+ export interface ExperienceOptions {
16
+ /**
17
+ * Holds the `[data-stage]` sections, one per formation in DOM order, and the
18
+ * `[data-reveal]` blocks. Receives `--ux-progress` (page scroll, 0 → 1).
19
+ */
20
+ root: HTMLElement;
21
+ canvas: HTMLCanvasElement;
22
+ formations: readonly Formation[];
23
+ /** Layers holding the `[data-anchor]` labels pinned to the formations. */
24
+ anchorRoots?: readonly HTMLElement[];
25
+ }
26
+ export interface Experience {
27
+ readonly state: Readonly<ExperienceState>;
28
+ /** Called after every change of `state`. Returns an unsubscribe function. */
29
+ subscribe(listener: (state: Readonly<ExperienceState>) => void): () => void;
30
+ setMotion(on: boolean): void;
31
+ destroy(): void;
32
+ }
33
+ export declare const initialExperienceState: () => ExperienceState;
34
+ /**
35
+ * Drives a page: smooth scroll, the scroll → formation mapping, reveals and
36
+ * step highlights, pointer input, the GPU engine (booted once the page is
37
+ * idle) and the labels pinned to the formations. Client-only.
38
+ */
39
+ export declare function createExperience({ root, canvas, formations, anchorRoots }: ExperienceOptions): Experience;
40
+ //#endregion
@@ -0,0 +1,306 @@
1
+ import { clamp, damp, projectToScreen } from "./gl/math.js";
2
+ import { progressOf, stageAt } from "./gl/stage.js";
3
+ import Lenis from "lenis";
4
+ //#region src/experience.ts
5
+ const initialExperienceState = () => ({
6
+ chapter: 0,
7
+ activeId: null,
8
+ status: "idle",
9
+ motion: true,
10
+ particles: 0,
11
+ fps: 0
12
+ });
13
+ const STATE_KEYS = [
14
+ "chapter",
15
+ "activeId",
16
+ "status",
17
+ "motion",
18
+ "particles",
19
+ "fps"
20
+ ];
21
+ const INTERACTIVE = "a, button, input, select, textarea, label, summary";
22
+ function detectQuality() {
23
+ if (Math.min(screen.width, screen.height) < 700) return "low";
24
+ if (matchMedia("(pointer: coarse)").matches) return "medium";
25
+ if ((navigator.hardwareConcurrency || 4) <= 4) return "medium";
26
+ return "high";
27
+ }
28
+ function whenIdle(callback) {
29
+ const schedule = () => {
30
+ if ("requestIdleCallback" in window) requestIdleCallback(callback, { timeout: 1500 });
31
+ else setTimeout(callback, 200);
32
+ };
33
+ if (document.readyState === "complete") schedule();
34
+ else window.addEventListener("load", schedule, { once: true });
35
+ }
36
+ /**
37
+ * Drives a page: smooth scroll, the scroll → formation mapping, reveals and
38
+ * step highlights, pointer input, the GPU engine (booted once the page is
39
+ * idle) and the labels pinned to the formations. Client-only.
40
+ */
41
+ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
42
+ const reducedQuery = matchMedia("(prefers-reduced-motion: reduce)");
43
+ const state = {
44
+ ...initialExperienceState(),
45
+ motion: !reducedQuery.matches
46
+ };
47
+ const listeners = /* @__PURE__ */ new Set();
48
+ const set = (patch) => {
49
+ const next = {
50
+ ...state,
51
+ ...patch
52
+ };
53
+ if (STATE_KEYS.every((key) => next[key] === state[key])) return;
54
+ Object.assign(state, next);
55
+ listeners.forEach((listener) => listener(state));
56
+ };
57
+ let engine = null;
58
+ let lenis = null;
59
+ let disposed = false;
60
+ let sections = [];
61
+ let viewport = window.innerHeight;
62
+ const syncLenis = () => {
63
+ if (state.motion && !lenis) lenis = new Lenis({
64
+ autoRaf: false,
65
+ anchors: true,
66
+ lerp: .085,
67
+ wheelMultiplier: .9
68
+ });
69
+ else if (!state.motion && lenis) {
70
+ lenis.destroy();
71
+ lenis = null;
72
+ }
73
+ };
74
+ syncLenis();
75
+ const setMotion = (on) => {
76
+ set({ motion: on });
77
+ syncLenis();
78
+ };
79
+ const onReducedChange = () => setMotion(!reducedQuery.matches);
80
+ reducedQuery.addEventListener("change", onReducedChange);
81
+ const measure = () => {
82
+ viewport = window.innerHeight;
83
+ const scrollY = window.scrollY;
84
+ sections = Array.from(root.querySelectorAll("[data-stage]")).map((el) => {
85
+ const rect = el.getBoundingClientRect();
86
+ const start = rect.top + scrollY;
87
+ return {
88
+ el,
89
+ start,
90
+ end: Math.max(start, start + rect.height - viewport)
91
+ };
92
+ });
93
+ engine?.resize();
94
+ };
95
+ const resizeObserver = new ResizeObserver(measure);
96
+ resizeObserver.observe(document.body);
97
+ window.addEventListener("resize", measure);
98
+ measure();
99
+ if (sections.length !== formations.length) console.warn(`[@uxfront/scene] ${sections.length} [data-stage] sections for ${formations.length} formations: each formation needs one section.`);
100
+ const revealObserver = new IntersectionObserver((entries) => {
101
+ for (const entry of entries) {
102
+ if (!entry.isIntersecting) continue;
103
+ entry.target.classList.add("is-in");
104
+ revealObserver.unobserve(entry.target);
105
+ }
106
+ }, { rootMargin: "0px 0px -12% 0px" });
107
+ root.querySelectorAll("[data-reveal]").forEach((el) => revealObserver.observe(el));
108
+ let pointerX = 0;
109
+ let pointerY = 0;
110
+ let pointerActive = false;
111
+ const onPointerMove = (event) => {
112
+ pointerX = event.clientX / window.innerWidth * 2 - 1;
113
+ pointerY = 1 - event.clientY / window.innerHeight * 2;
114
+ pointerActive = event.pointerType !== "touch";
115
+ };
116
+ const onPointerLeave = () => {
117
+ pointerActive = false;
118
+ };
119
+ const onClick = (event) => {
120
+ if (!state.motion || event.target instanceof Element && event.target.closest(INTERACTIVE)) return;
121
+ engine?.shock(event.clientX / window.innerWidth * 2 - 1, 1 - event.clientY / window.innerHeight * 2);
122
+ };
123
+ window.addEventListener("pointermove", onPointerMove, { passive: true });
124
+ window.addEventListener("click", onClick);
125
+ document.documentElement.addEventListener("pointerleave", onPointerLeave);
126
+ window.addEventListener("blur", onPointerLeave);
127
+ const anchorEls = /* @__PURE__ */ new Map();
128
+ for (const layer of anchorRoots) layer.querySelectorAll("[data-anchor]").forEach((el) => {
129
+ anchorEls.set(el.dataset.anchor, el);
130
+ });
131
+ const pins = formations.flatMap((formation, index) => formation.anchors.flatMap((anchor) => {
132
+ const el = anchorEls.get(anchor.id);
133
+ return el ? [{
134
+ el,
135
+ anchor,
136
+ index
137
+ }] : [];
138
+ }));
139
+ const anchorPos = [
140
+ 0,
141
+ 0,
142
+ 0
143
+ ];
144
+ const screenPos = [
145
+ 0,
146
+ 0,
147
+ 0
148
+ ];
149
+ const updateAnchors = (stage, local) => {
150
+ const width = canvas.clientWidth;
151
+ const height = canvas.clientHeight;
152
+ const time = engine?.time ?? 0;
153
+ for (const { el, anchor, index } of pins) {
154
+ const progress = progressOf(index, stage, local, time);
155
+ let visible = engine ? progress.presence * progress.presence : 0;
156
+ if (visible > .001) {
157
+ visible *= anchor.place(progress, anchorPos);
158
+ if (!projectToScreen(screenPos, engine.viewProjection, anchorPos, width, height)) visible = 0;
159
+ }
160
+ if (visible > .001) {
161
+ el.style.transform = `translate3d(${screenPos[0].toFixed(1)}px, ${screenPos[1].toFixed(1)}px, 0)`;
162
+ el.style.opacity = visible.toFixed(3);
163
+ el.style.visibility = "visible";
164
+ } else if (el.style.visibility !== "hidden") el.style.visibility = "hidden";
165
+ if (anchor.render && progress.presence > 0) anchor.render(el, progress);
166
+ }
167
+ };
168
+ let raf = 0;
169
+ let last = performance.now();
170
+ let stage = -1;
171
+ let local = 0;
172
+ let lastScrollY = window.scrollY;
173
+ let activeSection = null;
174
+ let statsClock = 0;
175
+ const html = document.documentElement;
176
+ const tick = (now) => {
177
+ raf = requestAnimationFrame(tick);
178
+ const dt = Math.min(.1, Math.max(0, (now - last) / 1e3));
179
+ last = now;
180
+ lenis?.raf(now);
181
+ const scrollY = window.scrollY;
182
+ const scrolled = Math.abs(scrollY - lastScrollY) / viewport;
183
+ lastScrollY = scrollY;
184
+ const target = stageAt(sections, scrollY);
185
+ if (stage < 0 || !state.motion) {
186
+ stage = target.stage;
187
+ local = target.local;
188
+ } else {
189
+ stage = damp(stage, target.stage, 5, dt);
190
+ local = damp(local, target.local, 6, dt);
191
+ if (Math.abs(stage - target.stage) < 5e-4) stage = target.stage;
192
+ }
193
+ const held = Math.round(stage);
194
+ const section = sections[held]?.el ?? null;
195
+ set({
196
+ chapter: held,
197
+ activeId: section?.id || null
198
+ });
199
+ const maxScroll = Math.max(1, html.scrollHeight - viewport);
200
+ root.style.setProperty("--ux-progress", clamp(scrollY / maxScroll, 0, 1).toFixed(4));
201
+ if (section !== activeSection) {
202
+ activeSection?.removeAttribute("data-step");
203
+ activeSection = section;
204
+ }
205
+ if (section) {
206
+ const steps = Number(section.dataset.steps || 0);
207
+ if (steps > 0) {
208
+ const step = String(Math.min(steps - 1, Math.floor(clamp(local, 0, .999) * steps)));
209
+ if (section.dataset.step !== step) section.dataset.step = step;
210
+ }
211
+ }
212
+ if (engine) {
213
+ engine.render({
214
+ stage: clamp(stage, 0, formations.length - 1),
215
+ local,
216
+ scrolled,
217
+ pointerX,
218
+ pointerY,
219
+ pointerActive,
220
+ motion: state.motion
221
+ }, dt);
222
+ statsClock += dt;
223
+ if (statsClock > .5) {
224
+ statsClock = 0;
225
+ set({
226
+ fps: engine.fps,
227
+ particles: engine.particles
228
+ });
229
+ }
230
+ }
231
+ updateAnchors(stage, local);
232
+ };
233
+ raf = requestAnimationFrame(tick);
234
+ const boot = async () => {
235
+ if (disposed) return;
236
+ if (typeof WebGL2RenderingContext === "undefined") {
237
+ set({ status: "fallback" });
238
+ return;
239
+ }
240
+ set({ status: "loading" });
241
+ try {
242
+ const [{ createEngine }, shaders] = await Promise.all([import("./gl/engine.js"), Promise.all(formations.map((formation) => formation.shader()))]);
243
+ if (disposed) return;
244
+ const created = await createEngine(canvas, {
245
+ formations,
246
+ shaders,
247
+ quality: detectQuality(),
248
+ reducedMotion: !state.motion,
249
+ onContextLost: () => {
250
+ engine?.destroy();
251
+ engine = null;
252
+ set({ status: "fallback" });
253
+ }
254
+ });
255
+ if (disposed) {
256
+ created?.destroy();
257
+ return;
258
+ }
259
+ if (!created) {
260
+ set({ status: "fallback" });
261
+ return;
262
+ }
263
+ engine = created;
264
+ set({
265
+ status: "ready",
266
+ particles: created.particles
267
+ });
268
+ } catch (error) {
269
+ console.warn(error);
270
+ set({ status: "fallback" });
271
+ }
272
+ };
273
+ const onContextRestored = () => void boot();
274
+ canvas.addEventListener("webglcontextrestored", onContextRestored);
275
+ whenIdle(() => void boot());
276
+ return {
277
+ state,
278
+ subscribe(listener) {
279
+ listeners.add(listener);
280
+ return () => {
281
+ listeners.delete(listener);
282
+ };
283
+ },
284
+ setMotion,
285
+ destroy() {
286
+ disposed = true;
287
+ listeners.clear();
288
+ cancelAnimationFrame(raf);
289
+ reducedQuery.removeEventListener("change", onReducedChange);
290
+ resizeObserver.disconnect();
291
+ revealObserver.disconnect();
292
+ window.removeEventListener("resize", measure);
293
+ window.removeEventListener("pointermove", onPointerMove);
294
+ window.removeEventListener("click", onClick);
295
+ document.documentElement.removeEventListener("pointerleave", onPointerLeave);
296
+ window.removeEventListener("blur", onPointerLeave);
297
+ canvas.removeEventListener("webglcontextrestored", onContextRestored);
298
+ lenis?.destroy();
299
+ lenis = null;
300
+ engine?.destroy();
301
+ engine = null;
302
+ }
303
+ };
304
+ }
305
+ //#endregion
306
+ export { createExperience, initialExperienceState };
@@ -0,0 +1,8 @@
1
+ import { Formation, FormationOptions } from "../../gl/types.js";
2
+ //#region src/formations/corridor/index.d.ts
3
+ /**
4
+ * A corridor of streaking light the camera looks down, with long trails.
5
+ * Frames centred copy, so it suits a closing section.
6
+ */
7
+ export declare function corridor(options: FormationOptions): Formation;
8
+ //#endregion
@@ -0,0 +1,52 @@
1
+ import { defineFormation, mergeViews } from "../../gl/formation.js";
2
+ //#region src/formations/corridor/index.ts
3
+ /**
4
+ * A corridor of streaking light the camera looks down, with long trails.
5
+ * Frames centred copy, so it suits a closing section.
6
+ */
7
+ function corridor(options) {
8
+ return defineFormation({
9
+ key: options.key ?? "corridor",
10
+ label: options.label,
11
+ views: mergeViews({
12
+ desktop: {
13
+ eye: [
14
+ 0,
15
+ 0,
16
+ 7
17
+ ],
18
+ target: [
19
+ 0,
20
+ 0,
21
+ -12
22
+ ],
23
+ fov: 56,
24
+ span: [0, 0],
25
+ shift: [0, 0]
26
+ },
27
+ mobile: {
28
+ eye: [
29
+ 0,
30
+ 0,
31
+ 7
32
+ ],
33
+ target: [
34
+ 0,
35
+ 0,
36
+ -12
37
+ ],
38
+ fov: 64,
39
+ span: [0, 0],
40
+ shift: [0, 0]
41
+ }
42
+ }, options.views),
43
+ look: {
44
+ bloom: 1.2,
45
+ trail: .86,
46
+ ...options.look
47
+ },
48
+ shader: () => import("./shader.js").then((m) => m.shader)
49
+ });
50
+ }
51
+ //#endregion
52
+ export { corridor };
@@ -0,0 +1,37 @@
1
+ //#region src/formations/corridor/shader.ts
2
+ const shader = { glsl: `
3
+ vec3 $palette(float t) {
4
+ return 0.5 + 0.5 * cos(TAU * (t + vec3(0.0, 0.33, 0.67)));
5
+ }
6
+
7
+ Particle $main(uint id, float sel, Frame f) {
8
+ float local = f.local;
9
+ float time = f.time;
10
+ uint s = seedOf(id, 0x3C6EF372u);
11
+ float a = rnd(s);
12
+ float b = rnd(s);
13
+ float c = rnd(s);
14
+ Particle P = blank();
15
+ float side = (id & 1u) == 0u ? -1.0 : 1.0;
16
+ float rows = 40.0;
17
+ float row = floor(a * rows);
18
+ float rowSeed = fract(row * 0.618 + side * 0.31);
19
+ float speed = mix(0.045, 0.1, local) * (0.75 + 0.5 * rowSeed);
20
+ float lane = fract(b + time * speed);
21
+ float z = mix(-36.0, 7.5, lane);
22
+ vec3 p;
23
+ if (sel < 0.82) p = vec3(side * 1.3, (row + 0.5) / rows * 3.4 - 1.7, z);
24
+ else p = vec3((row + 0.5) / rows * 2.6 - 1.3, side * 1.7, z);
25
+ // Light travels in packets: bright clusters along each lane.
26
+ float packet = smoothstep(0.78, 1.0, fract(b * 5.0 + rowSeed * 3.0));
27
+ vec3 hue = $palette(fract(rowSeed * 0.8 + time * 0.02));
28
+ vec3 col = mix(vec3(0.62, 0.7, 1.0), hue, 0.55 * packet + 0.15);
29
+ float fade = smoothstep(-36.0, -20.0, z) * (1.0 - smoothstep(2.5, 7.0, z));
30
+ P.pos = p;
31
+ P.col = col * (0.035 + packet * 0.6) * fade;
32
+ P.size = mix(0.8, 1.0, c);
33
+ return P;
34
+ }
35
+ ` };
36
+ //#endregion
37
+ export { shader };
@@ -0,0 +1,11 @@
1
+ import { corridor } from "./corridor/index.js";
2
+ import { ink } from "./ink/index.js";
3
+ import { monolith } from "./monolith/index.js";
4
+ import { OPEN_COMPONENTS_ART, PlateShape, circle, disc, plateBorder, rrect, seg } from "./plates/art.js";
5
+ import { PlatesOptions, plates } from "./plates/index.js";
6
+ import { PLATE } from "./plates/geometry.js";
7
+ import { prism } from "./prism/index.js";
8
+ import { RAILS } from "./prism/geometry.js";
9
+ import { THEMES, Theme } from "./tokens/geometry.js";
10
+ import { TokensFormation, tokens } from "./tokens/index.js";
11
+ export { OPEN_COMPONENTS_ART, PLATE, type PlateShape, type PlatesOptions, RAILS, THEMES, type Theme, type TokensFormation, circle, corridor, disc, ink, monolith, plateBorder, plates, prism, rrect, seg, tokens };
@@ -0,0 +1,11 @@
1
+ import { corridor } from "./corridor/index.js";
2
+ import { ink } from "./ink/index.js";
3
+ import { monolith } from "./monolith/index.js";
4
+ import { PLATE } from "./plates/geometry.js";
5
+ import { plates } from "./plates/index.js";
6
+ import { OPEN_COMPONENTS_ART, circle, disc, plateBorder, rrect, seg } from "./plates/art.js";
7
+ import { RAILS } from "./prism/geometry.js";
8
+ import { prism } from "./prism/index.js";
9
+ import { THEMES } from "./tokens/geometry.js";
10
+ import { tokens } from "./tokens/index.js";
11
+ export { OPEN_COMPONENTS_ART, PLATE, RAILS, THEMES, circle, corridor, disc, ink, monolith, plateBorder, plates, prism, rrect, seg, tokens };
@@ -0,0 +1,10 @@
1
+ import { Formation, FormationOptions } from "../../gl/types.js";
2
+ //#region src/formations/ink/index.d.ts
3
+ /**
4
+ * Coloured inks poured into still water, curling as they sink. The water
5
+ * starts clear each time the formation scrolls into view, and scrolling while
6
+ * it shows speeds the pour up, so it can't be scrolled past before it pours.
7
+ * Without motion it shows poured, and sinks only as the page scrolls.
8
+ */
9
+ export declare function ink(options: FormationOptions): Formation;
10
+ //#endregion
@@ -0,0 +1,53 @@
1
+ import { defineFormation, mergeViews } from "../../gl/formation.js";
2
+ //#region src/formations/ink/index.ts
3
+ /**
4
+ * Coloured inks poured into still water, curling as they sink. The water
5
+ * starts clear each time the formation scrolls into view, and scrolling while
6
+ * it shows speeds the pour up, so it can't be scrolled past before it pours.
7
+ * Without motion it shows poured, and sinks only as the page scrolls.
8
+ */
9
+ function ink(options) {
10
+ return defineFormation({
11
+ key: options.key ?? "ink",
12
+ label: options.label,
13
+ views: mergeViews({
14
+ desktop: {
15
+ eye: [
16
+ .5,
17
+ 1.9,
18
+ 9.4
19
+ ],
20
+ target: [
21
+ .5,
22
+ -.45,
23
+ 0
24
+ ],
25
+ fov: 30,
26
+ span: [3.4, 2.2],
27
+ shift: [.24, .02]
28
+ },
29
+ mobile: {
30
+ eye: [
31
+ .5,
32
+ 1.9,
33
+ 9.4
34
+ ],
35
+ target: [
36
+ .5,
37
+ -.45,
38
+ 0
39
+ ],
40
+ fov: 34,
41
+ span: [3.2, 2.1],
42
+ shift: [0, .5]
43
+ }
44
+ }, options.views),
45
+ look: {
46
+ bloom: 1.1,
47
+ ...options.look
48
+ },
49
+ shader: () => import("./shader.js").then((m) => m.createShader())
50
+ });
51
+ }
52
+ //#endregion
53
+ export { ink };