@uxfront/scene 0.1.0 → 0.2.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/README.md CHANGED
@@ -3,7 +3,7 @@
3
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
4
 
5
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`.
6
+ - **A catalog.** Eight formations: `monolith`, `plates`, `prism`, `tokens`, `ink`, `corridor`, `stack` and `threshold`.
7
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
8
 
9
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.
@@ -68,14 +68,16 @@ Portrait, squarish and small screens use each formation's `mobile` framing, whic
68
68
 
69
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
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 |
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
+ | `stack` | Seven glass cards dealt as the chapter is read, one per rail, each holding the same component. `art` swaps it. | `stack:0`–`stack:6`, in the cards' headers |
80
+ | `threshold` | The prism's seven beams cross a soap film of light and converge into one white stream. | `threshold:stream`, above the stream |
79
81
 
80
82
  ## Writing a formation
81
83
 
@@ -121,7 +123,9 @@ Particle $main(uint id, float sel, Frame f) {
121
123
  - `$name` identifiers are private: the scene rewrites them to `key_name`, so formations never clash.
122
124
  - `$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
125
  - `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`.
126
+ - Shared helpers: `hashU`, `rnd`, `seedOf`, `gauss`, `noised`, `curl`, `bitangent`, `bezier3`, `rrectPoint`, `shapePoint`, `PI`, `TAU` and `FLOOR_Y`.
127
+ - `glslFloat`, `glslVec` and `glslArray` write numbers into the GLSL as constants. `packShapes` packs line art (segments, rounded rectangles, circles, discs and fills) into rows for `shapePoint`, which places a particle on it. `stack` and `plates` draw their art this way.
128
+ - A formation that follows the prism can take its `RAILS` and `SPECTRUM` from `@uxfront/scene/formations`, so rail `i` keeps its colour.
125
129
  - `setup` uploads uniforms once. `update(uniforms, frame)` runs every frame with the formation's `local`, `approach`, `presence`, `time`, `dt`, `motion` and `scrolled`.
126
130
  - `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
131
 
@@ -1,11 +1,16 @@
1
1
  import { corridor } from "./corridor/index.js";
2
2
  import { ink } from "./ink/index.js";
3
3
  import { monolith } from "./monolith/index.js";
4
- import { OPEN_COMPONENTS_ART, PlateShape, circle, disc, plateBorder, rrect, seg } from "./plates/art.js";
4
+ import { OPEN_COMPONENTS_ART, PlateShape, circle, disc, fill, plateBorder, rrect, seg } from "./plates/art.js";
5
5
  import { PlatesOptions, plates } from "./plates/index.js";
6
6
  import { PLATE } from "./plates/geometry.js";
7
7
  import { prism } from "./prism/index.js";
8
8
  import { RAILS } from "./prism/geometry.js";
9
+ import { SPECTRUM } from "./prism/spectrum.js";
10
+ import { CARD_ROLE, CardRole, CardShape, KNOB_TRAVEL, SIGN_UP_FORM_ART } from "./stack/art.js";
11
+ import { StackOptions, stack } from "./stack/index.js";
12
+ import { CARD, CARD_NAME } from "./stack/geometry.js";
13
+ import { threshold } from "./threshold/index.js";
9
14
  import { THEMES, Theme } from "./tokens/geometry.js";
10
15
  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 };
16
+ export { CARD, CARD_NAME, CARD_ROLE, type CardRole, type CardShape, KNOB_TRAVEL, OPEN_COMPONENTS_ART, PLATE, type PlateShape, type PlatesOptions, RAILS, SIGN_UP_FORM_ART, SPECTRUM, type StackOptions, THEMES, type Theme, type TokensFormation, circle, corridor, disc, fill, ink, monolith, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
@@ -3,9 +3,14 @@ import { ink } from "./ink/index.js";
3
3
  import { monolith } from "./monolith/index.js";
4
4
  import { PLATE } from "./plates/geometry.js";
5
5
  import { plates } from "./plates/index.js";
6
- import { OPEN_COMPONENTS_ART, circle, disc, plateBorder, rrect, seg } from "./plates/art.js";
6
+ import { OPEN_COMPONENTS_ART, circle, disc, fill, plateBorder, rrect, seg } from "./plates/art.js";
7
7
  import { RAILS } from "./prism/geometry.js";
8
8
  import { prism } from "./prism/index.js";
9
+ import { SPECTRUM } from "./prism/spectrum.js";
10
+ import { CARD, CARD_NAME } from "./stack/geometry.js";
11
+ import { stack } from "./stack/index.js";
12
+ import { CARD_ROLE, KNOB_TRAVEL, SIGN_UP_FORM_ART } from "./stack/art.js";
13
+ import { threshold } from "./threshold/index.js";
9
14
  import { THEMES } from "./tokens/geometry.js";
10
15
  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 };
16
+ export { CARD, CARD_NAME, CARD_ROLE, KNOB_TRAVEL, OPEN_COMPONENTS_ART, PLATE, RAILS, SIGN_UP_FORM_ART, SPECTRUM, THEMES, circle, corridor, disc, fill, ink, monolith, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
@@ -1,35 +1,13 @@
1
1
  import { Vec2 } from "../../gl/math.js";
2
+ import { Shape } from "../../gl/shapes.js";
2
3
  //#region src/formations/plates/art.d.ts
3
4
  /**
4
5
  * Plate artwork, drawn by the shader from a uniform table. Coordinates are
5
6
  * plate-local (`PLATE` half extents): u to the right, v away from the viewer.
6
7
  * `plate` is 0 (top), 1 or 2 (bottom).
7
8
  */
8
- export type PlateShape = {
9
- kind: "seg";
9
+ export type PlateShape = Shape & {
10
10
  plate: number;
11
- a: Vec2;
12
- b: Vec2;
13
- bright: number;
14
- } | {
15
- kind: "rrect";
16
- plate: number;
17
- c: Vec2;
18
- h: Vec2;
19
- r: number;
20
- bright: number;
21
- } | {
22
- kind: "circle";
23
- plate: number;
24
- c: Vec2;
25
- r: number;
26
- bright: number;
27
- } | {
28
- kind: "disc";
29
- plate: number;
30
- c: Vec2;
31
- r: number;
32
- bright: number;
33
11
  };
34
12
  /** A line segment. */
35
13
  export declare const seg: (plate: number, a: Vec2, b: Vec2, bright?: number) => PlateShape;
@@ -39,6 +17,8 @@ export declare const rrect: (plate: number, c: Vec2, h: Vec2, r: number, bright?
39
17
  export declare const circle: (plate: number, c: Vec2, r: number, bright?: number) => PlateShape;
40
18
  /** A filled disc. */
41
19
  export declare const disc: (plate: number, c: Vec2, r: number, bright?: number) => PlateShape;
20
+ /** A filled rounded rectangle: centre, half size and corner radius. */
21
+ export declare const fill: (plate: number, c: Vec2, h: Vec2, r: number, bright?: number) => PlateShape;
42
22
  /** The plate's own border. */
43
23
  export declare const plateBorder: (plate: number, bright: number) => PlateShape;
44
24
  /** Open Components: an interface (UX), its API (DX) and its semantic tree (AX). */
@@ -1,3 +1,4 @@
1
+ import { packShapes } from "../../gl/shapes.js";
1
2
  import { PLATE } from "./geometry.js";
2
3
  //#region src/formations/plates/art.ts
3
4
  /** A line segment. */
@@ -33,6 +34,15 @@ const disc = (plate, c, r, bright = 1) => ({
33
34
  r,
34
35
  bright
35
36
  });
37
+ /** A filled rounded rectangle: centre, half size and corner radius. */
38
+ const fill = (plate, c, h, r, bright = .3) => ({
39
+ kind: "fill",
40
+ plate,
41
+ c,
42
+ h,
43
+ r,
44
+ bright
45
+ });
36
46
  /** The plate's own border. */
37
47
  const plateBorder = (plate, bright) => rrect(plate, [0, 0], PLATE, .14, bright);
38
48
  const uxPlate = [
@@ -141,98 +151,24 @@ const OPEN_COMPONENTS_ART = [
141
151
  ...dxPlate,
142
152
  ...axPlate
143
153
  ];
144
- const shapeWeight = (shape) => {
145
- if (shape.kind === "seg") return Math.hypot(shape.b[0] - shape.a[0], shape.b[1] - shape.a[1]);
146
- if (shape.kind === "rrect") {
147
- const r = Math.min(shape.r, shape.h[0], shape.h[1]);
148
- return 4 * (shape.h[0] + shape.h[1]) - 8 * r + 2 * Math.PI * r;
149
- }
150
- if (shape.kind === "circle") return 2 * Math.PI * shape.r;
151
- return Math.PI * shape.r * shape.r * 24;
152
- };
153
- /**
154
- * Packs plate artwork into uniform arrays. Particles pick a shape by
155
- * binary-searching the CDF, so every line gets the same particle density.
156
- */
154
+ /** Packs plate artwork into uniform arrays, the plate in each shape's tag. */
157
155
  function buildShapeTable(shapes) {
158
156
  if (shapes.length === 0) throw new Error("Plate artwork needs at least one shape");
159
157
  if (shapes.length > 64) throw new Error(`Plate artwork is limited to 64 shapes`);
158
+ const packed = packShapes(shapes, (shape) => shape.plate);
160
159
  const a = /* @__PURE__ */ new Float32Array(256);
161
160
  const b = /* @__PURE__ */ new Float32Array(256);
162
161
  const cdf = /* @__PURE__ */ new Float32Array(64);
163
- const weights = shapes.map(shapeWeight);
164
- const totalWeight = weights.reduce((sum, w) => sum + w, 0);
165
- let running = 0;
166
- shapes.forEach((shape, i) => {
167
- running += weights[i];
168
- cdf[i] = running / totalWeight;
169
- const o = i * 4;
170
- switch (shape.kind) {
171
- case "seg":
172
- a.set([
173
- shape.a[0],
174
- shape.a[1],
175
- shape.b[0],
176
- shape.b[1]
177
- ], o);
178
- b.set([
179
- 0,
180
- 0,
181
- shape.plate,
182
- shape.bright
183
- ], o);
184
- break;
185
- case "rrect":
186
- a.set([
187
- shape.c[0],
188
- shape.c[1],
189
- shape.h[0],
190
- shape.h[1]
191
- ], o);
192
- b.set([
193
- 1,
194
- shape.r,
195
- shape.plate,
196
- shape.bright
197
- ], o);
198
- break;
199
- case "circle":
200
- a.set([
201
- shape.c[0],
202
- shape.c[1],
203
- shape.r,
204
- 0
205
- ], o);
206
- b.set([
207
- 2,
208
- 0,
209
- shape.plate,
210
- shape.bright
211
- ], o);
212
- break;
213
- case "disc":
214
- a.set([
215
- shape.c[0],
216
- shape.c[1],
217
- shape.r,
218
- 0
219
- ], o);
220
- b.set([
221
- 3,
222
- 0,
223
- shape.plate,
224
- shape.bright
225
- ], o);
226
- }
227
- });
228
- cdf[shapes.length - 1] = 1.0001;
162
+ a.set(packed.a.flat());
163
+ b.set(packed.b.flat());
164
+ cdf.set(packed.cdf);
229
165
  return {
230
166
  a,
231
167
  b,
232
168
  cdf,
233
169
  count: shapes.length,
234
- totalWeight
170
+ totalWeight: packed.totalWeight
235
171
  };
236
172
  }
237
173
  //#endregion
238
- export { OPEN_COMPONENTS_ART, buildShapeTable, circle, disc, plateBorder, rrect, seg };
174
+ export { OPEN_COMPONENTS_ART, buildShapeTable, circle, disc, fill, plateBorder, rrect, seg };
@@ -65,12 +65,7 @@ Particle $main(uint id, float sel, Frame f) {
65
65
  int i = $findShape(a);
66
66
  vec4 A = $shapeA[i];
67
67
  vec4 B = $shapeB[i];
68
- int type = int(B.x + 0.5);
69
- vec2 q;
70
- if (type == 0) q = mix(A.xy, A.zw, b);
71
- else if (type == 1) q = rrectPoint(A, B.y, b);
72
- else if (type == 2) q = A.xy + A.z * vec2(cos(b * TAU), sin(b * TAU));
73
- else q = A.xy + A.z * sqrt(c) * vec2(cos(b * TAU), sin(b * TAU));
68
+ vec2 q = shapePoint(A, B, b, c);
74
69
  int k = int(B.z + 0.5);
75
70
  float glint = exp(-pow((q.x - sweep) * 3.0, 2.0));
76
71
  P.pos = vec3(q.x, sep * (1.0 - float(k)), -q.y);
@@ -1,5 +1,6 @@
1
- import { glslFloat } from "../../gl/glsl.js";
1
+ import { glslArray, glslFloat, glslVec } from "../../gl/glsl.js";
2
2
  import { RAIL_APPROACH, RAIL_X0, RAIL_X1 } from "./geometry.js";
3
+ import { SPECTRUM } from "./spectrum.js";
3
4
  //#region src/formations/prism/shader.ts
4
5
  const shader = { glsl: `
5
6
  const vec2 $PA = vec2(0.0, 1.097);
@@ -12,15 +13,7 @@ const float $RAIL_X1 = ${glslFloat(RAIL_X1)};
12
13
 
13
14
  // Angular, Svelte, Astro, Vue, React, Solid, Qwik: the spectrum happens to
14
15
  // land close to each framework's own colour.
15
- const vec3 $SPECTRUM[7] = vec3[7](
16
- vec3(1.0, 0.13, 0.16),
17
- vec3(1.0, 0.4, 0.06),
18
- vec3(1.0, 0.8, 0.14),
19
- vec3(0.2, 1.0, 0.45),
20
- vec3(0.16, 0.75, 1.0),
21
- vec3(0.25, 0.36, 1.0),
22
- vec3(0.64, 0.26, 1.0)
23
- );
16
+ const vec3 $SPECTRUM[7] = ${glslArray("vec3", SPECTRUM.map(glslVec))};
24
17
 
25
18
  // Rails start growing as the chapter scrolls in (see railProgress).
26
19
  float $progress(Frame f) {
@@ -0,0 +1,10 @@
1
+ import { Vec3 } from "../../gl/math.js";
2
+ //#region src/formations/prism/spectrum.d.ts
3
+ /**
4
+ * The prism's spectrum, one colour per rail, top to bottom (see `RAILS`). In
5
+ * that order it lands close to the colours of Angular, Svelte, Astro, Vue,
6
+ * React, Solid and Qwik. Formations that follow the prism keep each rail's
7
+ * colour.
8
+ */
9
+ export declare const SPECTRUM: readonly Vec3[];
10
+ //#endregion
@@ -0,0 +1,46 @@
1
+ //#region src/formations/prism/spectrum.ts
2
+ /**
3
+ * The prism's spectrum, one colour per rail, top to bottom (see `RAILS`). In
4
+ * that order it lands close to the colours of Angular, Svelte, Astro, Vue,
5
+ * React, Solid and Qwik. Formations that follow the prism keep each rail's
6
+ * colour.
7
+ */
8
+ const SPECTRUM = [
9
+ [
10
+ 1,
11
+ .13,
12
+ .16
13
+ ],
14
+ [
15
+ 1,
16
+ .4,
17
+ .06
18
+ ],
19
+ [
20
+ 1,
21
+ .8,
22
+ .14
23
+ ],
24
+ [
25
+ .2,
26
+ 1,
27
+ .45
28
+ ],
29
+ [
30
+ .16,
31
+ .75,
32
+ 1
33
+ ],
34
+ [
35
+ .25,
36
+ .36,
37
+ 1
38
+ ],
39
+ [
40
+ .64,
41
+ .26,
42
+ 1
43
+ ]
44
+ ];
45
+ //#endregion
46
+ export { SPECTRUM };
@@ -0,0 +1,34 @@
1
+ import { Shape } from "../../gl/shapes.js";
2
+ //#region src/formations/stack/art.d.ts
3
+ /**
4
+ * What a shape does while the formation plays. Every card fills its form in on
5
+ * the same beat, because every card holds the same component: the `typing`
6
+ * line grows as the email is typed, with its `caret`, the toggle switches on
7
+ * (its `track` lights up and its `knob` slides `KNOB_TRAVEL` to the right) and
8
+ * the `button` is pressed.
9
+ */
10
+ export declare const CARD_ROLE: {
11
+ readonly still: 0;
12
+ readonly knob: 1;
13
+ readonly track: 2;
14
+ readonly button: 3;
15
+ readonly typing: 4;
16
+ readonly caret: 5;
17
+ };
18
+ export type CardRole = (typeof CARD_ROLE)[keyof typeof CARD_ROLE];
19
+ /**
20
+ * Card artwork, in card-local art units (`CARD` half extents): x to the
21
+ * right, y up. The formation draws the card's border itself.
22
+ */
23
+ export type CardShape = Shape & {
24
+ role?: CardRole;
25
+ };
26
+ /** How far a toggle's knob slides when it switches on. */
27
+ export declare const KNOB_TRAVEL = .08;
28
+ /**
29
+ * Unframework: one component, the same on every card. A sign-up form, with a
30
+ * header (the part that shows above the card in front), first and last name,
31
+ * an email, a "remember me" toggle, and cancel and submit buttons.
32
+ */
33
+ export declare const SIGN_UP_FORM_ART: CardShape[];
34
+ //#endregion
@@ -0,0 +1,171 @@
1
+ import { CARD_NAME } from "./geometry.js";
2
+ //#region src/formations/stack/art.ts
3
+ /**
4
+ * What a shape does while the formation plays. Every card fills its form in on
5
+ * the same beat, because every card holds the same component: the `typing`
6
+ * line grows as the email is typed, with its `caret`, the toggle switches on
7
+ * (its `track` lights up and its `knob` slides `KNOB_TRAVEL` to the right) and
8
+ * the `button` is pressed.
9
+ */
10
+ const CARD_ROLE = {
11
+ still: 0,
12
+ knob: 1,
13
+ track: 2,
14
+ button: 3,
15
+ typing: 4,
16
+ caret: 5
17
+ };
18
+ /** How far a toggle's knob slides when it switches on. */
19
+ const KNOB_TRAVEL = .08;
20
+ /** The email being typed: where the text starts, and how long it gets. */
21
+ const TYPED_FROM = [-.53, -.1];
22
+ const TYPED_LENGTH = .46;
23
+ const FIELD_H = .052;
24
+ const ACTIONS_Y = -.36;
25
+ const TOGGLE = [-.5, ACTIONS_Y];
26
+ const CANCEL = [.2, ACTIONS_Y];
27
+ const SUBMIT = [.47, ACTIONS_Y];
28
+ const BUTTON_H = [.12, .058];
29
+ /** A labelled text field: the label above, the input and its placeholder. */
30
+ const field = (x, y, halfWidth, placeholder) => [
31
+ {
32
+ kind: "seg",
33
+ a: [x - halfWidth + .01, y + .1],
34
+ b: [x - halfWidth + .15, y + .1],
35
+ bright: .55
36
+ },
37
+ {
38
+ kind: "rrect",
39
+ c: [x, y],
40
+ h: [halfWidth, FIELD_H],
41
+ r: .03,
42
+ bright: .7
43
+ },
44
+ ...placeholder > 0 ? [{
45
+ kind: "seg",
46
+ a: [x - halfWidth + .05, y],
47
+ b: [x - halfWidth + .05 + placeholder, y],
48
+ bright: .25
49
+ }] : []
50
+ ];
51
+ /**
52
+ * Unframework: one component, the same on every card. A sign-up form, with a
53
+ * header (the part that shows above the card in front), first and last name,
54
+ * an email, a "remember me" toggle, and cancel and submit buttons.
55
+ */
56
+ const SIGN_UP_FORM_ART = [
57
+ {
58
+ kind: "circle",
59
+ c: [-.55, .415],
60
+ r: .045,
61
+ bright: 1
62
+ },
63
+ {
64
+ kind: "disc",
65
+ c: [-.55, .415],
66
+ r: .016,
67
+ bright: .9
68
+ },
69
+ {
70
+ kind: "seg",
71
+ a: [CARD_NAME[0], .385],
72
+ b: [-.12, .385],
73
+ bright: .45
74
+ },
75
+ {
76
+ kind: "disc",
77
+ c: [.56, .415],
78
+ r: .02,
79
+ bright: 1.2
80
+ },
81
+ {
82
+ kind: "seg",
83
+ a: [-.6, .3],
84
+ b: [.6, .3],
85
+ bright: .25
86
+ },
87
+ ...field(-.29, .12, .27, .16),
88
+ ...field(.29, .12, .27, .12),
89
+ ...field(0, -.1, .58, 0),
90
+ {
91
+ kind: "seg",
92
+ a: TYPED_FROM,
93
+ b: [TYPED_FROM[0] + TYPED_LENGTH, TYPED_FROM[1]],
94
+ bright: .9,
95
+ role: CARD_ROLE.typing
96
+ },
97
+ {
98
+ kind: "seg",
99
+ a: [TYPED_FROM[0] + .012, TYPED_FROM[1] - .03],
100
+ b: [TYPED_FROM[0] + .012, TYPED_FROM[1] + .03],
101
+ bright: 1.2,
102
+ role: CARD_ROLE.caret
103
+ },
104
+ {
105
+ kind: "fill",
106
+ c: TOGGLE,
107
+ h: [.085, .045],
108
+ r: .045,
109
+ bright: .3,
110
+ role: CARD_ROLE.track
111
+ },
112
+ {
113
+ kind: "rrect",
114
+ c: TOGGLE,
115
+ h: [.085, .045],
116
+ r: .045,
117
+ bright: .8,
118
+ role: CARD_ROLE.track
119
+ },
120
+ {
121
+ kind: "disc",
122
+ c: [TOGGLE[0] - KNOB_TRAVEL / 2, TOGGLE[1]],
123
+ r: .03,
124
+ bright: 1.3,
125
+ role: CARD_ROLE.knob
126
+ },
127
+ {
128
+ kind: "seg",
129
+ a: [-.38, ACTIONS_Y],
130
+ b: [-.14, ACTIONS_Y],
131
+ bright: .55
132
+ },
133
+ {
134
+ kind: "rrect",
135
+ c: CANCEL,
136
+ h: BUTTON_H,
137
+ r: BUTTON_H[1],
138
+ bright: .6
139
+ },
140
+ {
141
+ kind: "seg",
142
+ a: [CANCEL[0] - .05, ACTIONS_Y],
143
+ b: [CANCEL[0] + .05, ACTIONS_Y],
144
+ bright: .5
145
+ },
146
+ {
147
+ kind: "fill",
148
+ c: SUBMIT,
149
+ h: BUTTON_H,
150
+ r: BUTTON_H[1],
151
+ bright: .35,
152
+ role: CARD_ROLE.button
153
+ },
154
+ {
155
+ kind: "rrect",
156
+ c: SUBMIT,
157
+ h: BUTTON_H,
158
+ r: BUTTON_H[1],
159
+ bright: 1.1,
160
+ role: CARD_ROLE.button
161
+ },
162
+ {
163
+ kind: "seg",
164
+ a: [SUBMIT[0] - .05, ACTIONS_Y],
165
+ b: [SUBMIT[0] + .05, ACTIONS_Y],
166
+ bright: 1,
167
+ role: CARD_ROLE.button
168
+ }
169
+ ];
170
+ //#endregion
171
+ export { CARD_ROLE, KNOB_TRAVEL, SIGN_UP_FORM_ART };
@@ -0,0 +1,10 @@
1
+ import { Vec2 } from "../../gl/math.js";
2
+ //#region src/formations/stack/geometry.d.ts
3
+ /** Half size of a card, in art units (see `art.ts`). */
4
+ export declare const CARD: Vec2;
5
+ /**
6
+ * Where the card's label goes, in its header, in art units: anchors `stack:0`
7
+ * to `stack:6` sit just before it, so the artwork leaves the spot empty.
8
+ */
9
+ export declare const CARD_NAME: Vec2;
10
+ //#endregion
@@ -0,0 +1,48 @@
1
+ import { lerp, smoothstep } from "../../gl/math.js";
2
+ import "../prism/geometry.js";
3
+ //#region src/formations/stack/geometry.ts
4
+ /** One card per rail of the prism, front to back in its order: rail `i` flows into card `i`. */
5
+ const CARDS = 7;
6
+ /** Half size of a card, in art units (see `art.ts`). */
7
+ const CARD = [.64, .52];
8
+ /** Corner radius of a card's border, in art units. */
9
+ const CARD_CORNER = .06;
10
+ /**
11
+ * Where the card's label goes, in its header, in art units: anchors `stack:0`
12
+ * to `stack:6` sit just before it, so the artwork leaves the spot empty.
13
+ */
14
+ const CARD_NAME = [-.46, .44];
15
+ /** World units per art unit. */
16
+ const CARD_SCALE = 1.4;
17
+ /** Centre of the front card, the first one dealt. */
18
+ const FRONT = [
19
+ 0,
20
+ -.4,
21
+ 0
22
+ ];
23
+ /**
24
+ * From one card to the card behind it: up and to the right at about 45°, and
25
+ * away, so each card peeks out above and beside the one in front of it.
26
+ */
27
+ const BEHIND = [
28
+ .33,
29
+ .28,
30
+ -.5
31
+ ];
32
+ /** Cards are dealt one after another as the chapter is read, like the prism's rails. */
33
+ const cardReach = (index, progress) => smoothstep(index * .08, index * .08 + .45, progress);
34
+ /** Share of the dealing that happens while the chapter scrolls in. */
35
+ const CARD_APPROACH = .35;
36
+ /** Deal progress: starts with the morph into the formation, not once it's held. */
37
+ const cardProgress = (approach, local) => approach < 1 ? approach * CARD_APPROACH : lerp(CARD_APPROACH, 1, local);
38
+ /** The stack floats. The engine clock only runs with motion on. */
39
+ const stackBob = (time) => Math.sin(time * .7) * .03;
40
+ /** Where the point `q` (card-local, in art units) of a card at rest is in the world. */
41
+ function cardPoint(index, q, time, out) {
42
+ out[0] = FRONT[0] + index * BEHIND[0] + q[0] * CARD_SCALE;
43
+ out[1] = FRONT[1] + index * BEHIND[1] + q[1] * CARD_SCALE + stackBob(time);
44
+ out[2] = FRONT[2] + index * BEHIND[2];
45
+ return out;
46
+ }
47
+ //#endregion
48
+ export { BEHIND, CARD, CARDS, CARD_APPROACH, CARD_CORNER, CARD_NAME, CARD_SCALE, FRONT, cardPoint, cardProgress, cardReach, stackBob };
@@ -0,0 +1,25 @@
1
+ import { Formation, FormationOptions } from "../../gl/types.js";
2
+ import { CardShape } from "./art.js";
3
+ //#region src/formations/stack/index.d.ts
4
+ export interface StackOptions extends FormationOptions {
5
+ /**
6
+ * What every card holds, in card-local art units (`CARD` half extents), x to
7
+ * the right and y up, with `role`s to bring it to life. Leave `CARD_NAME`
8
+ * free for the label. Defaults to Unframework's sign-up form.
9
+ */
10
+ art?: CardShape[];
11
+ }
12
+ /**
13
+ * A stack of seven glass cards, one per rail of the prism, each holding the
14
+ * same component, drawn in light and tinted in its rail's colour. They're
15
+ * dealt one after another as the chapter is read: the first lands in front,
16
+ * and each next one fans out from behind the one before it. The component
17
+ * plays on the same beat on all of them: the default sign-up form types its
18
+ * email, switches "remember me" on and presses submit. Follows the prism:
19
+ * rail `i` flows into card `i`.
20
+ *
21
+ * Anchors `stack:0` to `stack:6` sit in the cards' headers, front to back,
22
+ * where the name goes, and show once each card is in place.
23
+ */
24
+ export declare function stack(options: StackOptions): Formation;
25
+ //#endregion