@uxfront/scene 0.5.1 → 0.5.2

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/README.md CHANGED
@@ -23,9 +23,9 @@ Mark up one section per formation, in order, then start the experience on the cl
23
23
  ```html
24
24
  <canvas id="stage" style="position: fixed; inset: 0; width: 100%; height: 100lvh"></canvas>
25
25
  <main id="page">
26
- <section data-stage>…</section>
27
- <section data-stage data-steps="3">…</section>
28
- <section data-stage>…</section>
26
+ <section data-stage>…</section>
27
+ <section data-stage data-steps="3">…</section>
28
+ <section data-stage>…</section>
29
29
  </main>
30
30
  ```
31
31
 
@@ -34,17 +34,17 @@ import { createExperience } from "@uxfront/scene";
34
34
  import { corridor, monolith, plates } from "@uxfront/scene/formations";
35
35
 
36
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
- ],
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
44
  });
45
45
 
46
46
  experience.subscribe(({ chapter, status, motion }) => {
47
- // Update a HUD, a nav, the fallback…
47
+ // Update a HUD, a nav, the fallback…
48
48
  });
49
49
  experience.setMotion(false); // pause the clock
50
50
  experience.destroy();
@@ -69,19 +69,19 @@ To fade an element's content in once the particles have gathered around it, read
69
69
 
70
70
  ```html
71
71
  <section data-stage>
72
- <img data-outline src="/figma.png" alt="The Figma plugin beside a component's code" />
72
+ <img data-outline src="/figma.png" alt="The Figma plugin beside a component's code" />
73
73
  </section>
74
74
  ```
75
75
 
76
76
  ```ts
77
77
  experience.subscribe(({ status }) => {
78
- document.body.toggleAttribute("data-scene-ready", status === "ready");
78
+ document.body.toggleAttribute("data-scene-ready", status === "ready");
79
79
  });
80
80
  ```
81
81
 
82
82
  ```css
83
83
  [data-scene-ready] [data-outline] {
84
- opacity: var(--ux-reveal, 1);
84
+ opacity: var(--ux-reveal, 1);
85
85
  }
86
86
  ```
87
87
 
@@ -99,7 +99,7 @@ The scene's frame is never squarer than 5:4 of the screen's height, since the fo
99
99
 
100
100
  ```css
101
101
  :root:has(.ux-site) {
102
- --ux-frame: 1200px;
102
+ --ux-frame: 1200px;
103
103
  }
104
104
  ```
105
105
 
@@ -143,9 +143,9 @@ import { monolith, plates } from "@uxfront/scene/formations";
143
143
  const hero = hold(plates({ label: "Open Components" }), 1);
144
144
  // Dims the monolith to half its brightness.
145
145
  const dimmed = wrapMain(
146
- monolith({ label: "Foundation" }),
147
- "lit",
148
- ` Particle P = $lit(id, sel, f);
146
+ monolith({ label: "Foundation" }),
147
+ "lit",
148
+ ` Particle P = $lit(id, sel, f);
149
149
  P.col *= 0.5;
150
150
  return P;`,
151
151
  );
@@ -171,16 +171,16 @@ A formation is a small synchronous description plus a lazily loaded shader:
171
171
  import { defineFormation } from "@uxfront/scene";
172
172
 
173
173
  export const rings = (label: string) =>
174
- defineFormation({
175
- key: "rings",
176
- label,
177
- views: {
178
- desktop: { eye: [0, 1, 10], target: [0, 0, 0], fov: 30, span: [2, 2], shift: [0.3, 0] },
179
- mobile: { eye: [0, 1, 10], target: [0, 0, 0], fov: 34, span: [2, 2], shift: [0, 0.5] },
180
- },
181
- look: { bloom: 1.1 },
182
- shader: () => import("./rings.shader").then((m) => m.shader),
183
- });
174
+ defineFormation({
175
+ key: "rings",
176
+ label,
177
+ views: {
178
+ desktop: { eye: [0, 1, 10], target: [0, 0, 0], fov: 30, span: [2, 2], shift: [0.3, 0] },
179
+ mobile: { eye: [0, 1, 10], target: [0, 0, 0], fov: 34, span: [2, 2], shift: [0, 0.5] },
180
+ },
181
+ look: { bloom: 1.1 },
182
+ shader: () => import("./rings.shader").then((m) => m.shader),
183
+ });
184
184
  ```
185
185
 
186
186
  ```ts
@@ -188,7 +188,7 @@ export const rings = (label: string) =>
188
188
  import type { FormationShader } from "@uxfront/scene";
189
189
 
190
190
  export const shader: FormationShader = {
191
- glsl: /* glsl */ `
191
+ glsl: /* glsl */ `
192
192
  uniform float $spin;
193
193
 
194
194
  Particle $main(uint id, float sel, Frame f) {
@@ -200,7 +200,7 @@ Particle $main(uint id, float sel, Frame f) {
200
200
  return P;
201
201
  }
202
202
  `,
203
- setup: ({ gl, get }) => gl.uniform1f(get("spin"), 0.2),
203
+ setup: ({ gl, get }) => gl.uniform1f(get("spin"), 0.2),
204
204
  };
205
205
  ```
206
206
 
@@ -20,9 +20,9 @@ export interface ExperienceOptions {
20
20
  */
21
21
  root: HTMLElement;
22
22
  canvas: HTMLCanvasElement;
23
- formations: readonly Formation[];
23
+ formations: ReadonlyArray<Formation>;
24
24
  /** Layers holding the `[data-anchor]` labels pinned to the formations. */
25
- anchorRoots?: readonly HTMLElement[];
25
+ anchorRoots?: ReadonlyArray<HTMLElement>;
26
26
  }
27
27
  export interface Experience {
28
28
  readonly state: Readonly<ExperienceState>;
@@ -146,7 +146,8 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
146
146
  window.addEventListener("blur", onPointerLeave);
147
147
  const anchorEls = /* @__PURE__ */ new Map();
148
148
  for (const layer of anchorRoots) layer.querySelectorAll("[data-anchor]").forEach((el) => {
149
- anchorEls.set(el.dataset.anchor, el);
149
+ const id = el.dataset.anchor;
150
+ if (id !== void 0) anchorEls.set(id, el);
150
151
  });
151
152
  const pins = formations.flatMap((formation, index) => formation.anchors.flatMap((anchor) => {
152
153
  const el = anchorEls.get(anchor.id);
@@ -171,7 +172,7 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
171
172
  for (const { el, anchor, index } of pins) {
172
173
  const progress = progressOf(index, stage, local, time);
173
174
  let visible = engine ? progress.presence * progress.presence : 0;
174
- if (visible > .001) {
175
+ if (engine && visible > .001) {
175
176
  visible *= anchor.place(progress, anchorPos);
176
177
  if (!projectToScreen(screenPos, engine.viewProjection, anchorPos, canvasWidth, canvasHeight)) visible = 0;
177
178
  }
@@ -22,5 +22,5 @@ export declare const fill: (plate: number, c: Vec2, h: Vec2, r: number, bright?:
22
22
  /** The plate's own border. */
23
23
  export declare const plateBorder: (plate: number, bright: number) => PlateShape;
24
24
  /** Open Components: an interface (UX), its API (DX) and its semantic tree (AX). */
25
- export declare const OPEN_COMPONENTS_ART: PlateShape[];
25
+ export declare const OPEN_COMPONENTS_ART: Array<PlateShape>;
26
26
  //#endregion
@@ -3,7 +3,7 @@ import { PlateShape } from "./art.js";
3
3
  //#region src/formations/plates/index.d.ts
4
4
  export interface PlatesOptions extends FormationOptions {
5
5
  /** Artwork on the three plates. Defaults to Open Components' UX, DX and AX plates. */
6
- art?: PlateShape[];
6
+ art?: Array<PlateShape>;
7
7
  }
8
8
  /**
9
9
  * Three glass plates drifting apart as the chapter is read, each drawn with
@@ -6,5 +6,5 @@ import { Vec3 } from "../../gl/math.js";
6
6
  * React, Solid and Qwik. Formations that follow the prism keep each rail's
7
7
  * colour.
8
8
  */
9
- export declare const SPECTRUM: readonly Vec3[];
9
+ export declare const SPECTRUM: ReadonlyArray<Vec3>;
10
10
  //#endregion
@@ -30,5 +30,5 @@ export declare const KNOB_TRAVEL = .08;
30
30
  * header (the part that shows above the card in front), first and last name,
31
31
  * an email, a "remember me" toggle, and cancel and submit buttons.
32
32
  */
33
- export declare const SIGN_UP_FORM_ART: CardShape[];
33
+ export declare const SIGN_UP_FORM_ART: Array<CardShape>;
34
34
  //#endregion
@@ -7,7 +7,7 @@ export interface StackOptions extends FormationOptions {
7
7
  * the right and y up, with `role`s to bring it to life. Leave `CARD_NAME`
8
8
  * free for the label. Defaults to Unframework's sign-up form.
9
9
  */
10
- art?: CardShape[];
10
+ art?: Array<CardShape>;
11
11
  }
12
12
  /**
13
13
  * A stack of seven glass cards, one per rail of the prism, each holding the
@@ -2,7 +2,7 @@ import { Formation, FormationOptions } from "../../gl/types.js";
2
2
  import { Theme } from "./geometry.js";
3
3
  //#region src/formations/tokens/index.d.ts
4
4
  export interface TokensFormation extends Formation {
5
- readonly themes: readonly Theme[];
5
+ readonly themes: ReadonlyArray<Theme>;
6
6
  /**
7
7
  * Lands the whole matrix on the next theme. The shader eases there, so the
8
8
  * change sweeps across as one more wave.
@@ -62,7 +62,7 @@ function tokens(options) {
62
62
  render: (el, { time, local }) => {
63
63
  const label = el.querySelector("[data-theme-name]");
64
64
  if (!label) return;
65
- const name = THEMES[themeStep(themePhase(time, local, state.shift)) % THEMES.length];
65
+ const name = THEMES[themeStep(themePhase(time, local, state.shift)) % THEMES.length] ?? THEMES[0];
66
66
  if (label.textContent !== name) label.textContent = name;
67
67
  }
68
68
  }],
@@ -10,5 +10,5 @@ export declare function namespaceGlsl(key: string, glsl: string): string;
10
10
  * (namespaced by its key), a dispatcher that picks formation `k`, and the
11
11
  * pipeline's `main()`, which morphs between neighbouring formations.
12
12
  */
13
- export declare function composeParticleShader(parts: readonly ShaderPart[]): string;
13
+ export declare function composeParticleShader(parts: ReadonlyArray<ShaderPart>): string;
14
14
  //#endregion
@@ -5,7 +5,7 @@ const PRIVATE = /\$([A-Za-z][A-Za-z0-9_]*)/g;
5
5
  const MAIN = /\bParticle\s+\$main\s*\(/;
6
6
  /** Rewrites a formation's `$name` identifiers to `key_name`. */
7
7
  function namespaceGlsl(key, glsl) {
8
- const out = glsl.replace(PRIVATE, (_, name) => `${key}_${name}`);
8
+ const out = glsl.replaceAll(PRIVATE, (_, name) => `${key}_${name}`);
9
9
  if (out.includes("$")) throw new Error(`Formation "${key}": "$" must start a private identifier, like $main.`);
10
10
  return out;
11
11
  }
package/dist/gl/engine.js CHANGED
@@ -95,7 +95,9 @@ function trailOf(look, boost, intro) {
95
95
  aberration: .012 + speed * .03
96
96
  };
97
97
  }
98
- const nextFrame = () => new Promise((resolve) => requestAnimationFrame(resolve));
98
+ const nextFrame = () => new Promise((resolve) => {
99
+ requestAnimationFrame(resolve);
100
+ });
99
101
  /**
100
102
  * Waits for the driver to finish compiling without ever blocking the main
101
103
  * thread on a status query (KHR_parallel_shader_compile).
@@ -353,7 +355,7 @@ async function createEngine(canvas, options) {
353
355
  const yaw = (motion ? Math.sin(time * .11) * .06 : 0) + pointerX * .1;
354
356
  const pitch = (motion ? Math.sin(time * .07) * .02 : 0) + pointerY * .05;
355
357
  let ox = eye[0] - target[0];
356
- let oy = eye[1] - target[1];
358
+ const oy = eye[1] - target[1];
357
359
  let oz = eye[2] - target[2];
358
360
  const cy = Math.cos(yaw);
359
361
  const sy = Math.sin(yaw);
package/dist/gl/glsl.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  /** Formats a number as a GLSL float literal, for constants interpolated into shaders. */
8
8
  export declare const glslFloat: (n: number) => string;
9
9
  /** Formats two to four numbers as a GLSL vector literal, like `vec3(1.0, 0.5, 0.0)`. */
10
- export declare const glslVec: (values: readonly number[]) => string;
10
+ export declare const glslVec: (values: ReadonlyArray<number>) => string;
11
11
  /** Formats GLSL literals of one type as an array constructor, like `float[2](0.5, 1.0)`. */
12
- export declare const glslArray: (type: string, items: readonly string[]) => string;
12
+ export declare const glslArray: (type: string, items: ReadonlyArray<string>) => string;
13
13
  //#endregion
@@ -36,11 +36,11 @@ export type Shape = {
36
36
  };
37
37
  export interface PackedShapes {
38
38
  /** Geometry: `seg` a.xy, b.xy; `rrect` and `fill` centre, half size; `circle` and `disc` centre, radius. */
39
- a: Vec4[];
39
+ a: Array<Vec4>;
40
40
  /** Kind, corner radius, tag, brightness. */
41
- b: Vec4[];
41
+ b: Array<Vec4>;
42
42
  /** Cumulative share of the particles, by line length (or area, for fills). The last one is past 1. */
43
- cdf: number[];
43
+ cdf: Array<number>;
44
44
  /** Divide by it to keep the lines' brightness independent of how much art there is. */
45
45
  totalWeight: number;
46
46
  }
@@ -49,5 +49,5 @@ export interface PackedShapes {
49
49
  * Particles pick a shape by the CDF, so every line gets the same particle
50
50
  * density. `tag` fills the free slot, `B.z`, like the plate a shape is on.
51
51
  */
52
- export declare function packShapes<S extends Shape>(shapes: readonly S[], tag?: (shape: S) => number): PackedShapes;
52
+ export declare function packShapes<S extends Shape>(shapes: ReadonlyArray<S>, tag?: (shape: S) => number): PackedShapes;
53
53
  //#endregion
@@ -29,14 +29,16 @@ export declare const HOLD_MARGIN = .25;
29
29
  * The page scrolls freely: the copy moves with it while the formation holds.
30
30
  */
31
31
  export declare function sectionSpan(top: number, height: number, viewport: number, maxScroll: number): SectionSpan;
32
+ /** Where a scroll position falls: the formation (a fraction between two) and its progress. */
33
+ export interface StagePosition {
34
+ stage: number;
35
+ local: number;
36
+ }
32
37
  /**
33
38
  * Scroll → stage. A section holds its formation across its span (local 0 → 1)
34
39
  * and morphs into the next one between the two spans.
35
40
  */
36
- export declare function stageAt(sections: SectionSpan[], y: number): {
37
- stage: number;
38
- local: number;
39
- };
41
+ export declare function stageAt(sections: Array<SectionSpan>, y: number): StagePosition;
40
42
  /**
41
43
  * The item a section with `steps` items highlights at scroll offset `y`, or
42
44
  * -1 for none. An item is on screen once its bottom (`bottoms`, page offsets
@@ -46,5 +48,5 @@ export declare function stageAt(sections: SectionSpan[], y: number): {
46
48
  * still below the fold for much of the span. Past the span, the section stays
47
49
  * on its last step.
48
50
  */
49
- export declare function stepAt(y: number, span: SectionSpan, steps: number, bottoms: number[], reach: number): number;
51
+ export declare function stepAt(y: number, span: SectionSpan, steps: number, bottoms: Array<number>, reach: number): number;
50
52
  //#endregion
@@ -116,15 +116,15 @@ export interface FormationDef {
116
116
  label: string;
117
117
  views: FormationViews;
118
118
  look?: Partial<FormationLook>;
119
- anchors?: AnchorDef[];
119
+ anchors?: Array<AnchorDef>;
120
120
  /** Loads the shader. Use a dynamic `import()`, so the GLSL stays out of the page's bundle. */
121
121
  shader: () => Promise<FormationShader>;
122
122
  }
123
123
  export interface Formation extends FormationDef {
124
124
  look: FormationLook;
125
- anchors: AnchorDef[];
125
+ anchors: Array<AnchorDef>;
126
126
  }
127
- type DeepPartial<T> = { [K in keyof T]?: T[K] extends number[] ? T[K] : DeepPartial<T[K]>; };
127
+ type DeepPartial<T> = { [K in keyof T]?: T[K] extends Array<number> ? T[K] : DeepPartial<T[K]>; };
128
128
  /** What every catalog formation accepts. */
129
129
  export interface FormationOptions {
130
130
  label: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxfront/scene",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "The scroll-driven WebGL particle scene behind the uxfront.com family of homepages: a pluggable formation pipeline, a formation catalog and a framework-agnostic scroll controller.",
5
5
  "keywords": [
6
6
  "particles",
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "devDependencies": {
39
- "@uxfront/typescript-config": "0.1.0",
39
+ "@uxfront/typescript-config": "0.2.1",
40
40
  "tsdown": "^0.23.0",
41
41
  "vitest": "^5.0.1"
42
42
  },