@uxfront/scene 0.3.0 → 0.4.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 +10 -8
- package/dist/experience.js +4 -5
- package/dist/gl/stage.d.ts +16 -4
- package/dist/gl/stage.js +22 -3
- package/dist/gl/types.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,13 +54,15 @@ experience.destroy();
|
|
|
54
54
|
|
|
55
55
|
### Page contract
|
|
56
56
|
|
|
57
|
-
| Markup | Effect
|
|
58
|
-
| -------------------------------------------- |
|
|
59
|
-
| `[data-stage]` under `root` | One section per formation, in DOM order.
|
|
60
|
-
| `data-steps="n"` on a section | While
|
|
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
|
-
| `[data-progress]` under `root` | Gets `--ux-progress`: page scroll, 0 → 1.
|
|
57
|
+
| Markup | Effect |
|
|
58
|
+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `[data-stage]` under `root` | One section per formation, in DOM order, about a screen tall. It holds its formation while it fills the screen, give or take `HOLD_MARGIN`. |
|
|
60
|
+
| `data-steps="n"` on a section | While it holds its formation, 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
|
+
| `[data-progress]` under `root` | Gets `--ux-progress`: page scroll, 0 → 1. |
|
|
64
|
+
|
|
65
|
+
Sections scroll freely, so don't pin them: the copy should move with the page. The scene holds a formation from a quarter of a screen (`HOLD_MARGIN`) before its section fills the screen until a quarter after, and morphs into the next formation in between, while both sections share the screen.
|
|
64
66
|
|
|
65
67
|
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
68
|
|
|
@@ -122,7 +124,7 @@ Particle $main(uint id, float sel, Frame f) {
|
|
|
122
124
|
|
|
123
125
|
- `$name` identifiers are private: the scene rewrites them to `key_name`, so formations never clash.
|
|
124
126
|
- `$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.
|
|
125
|
-
- `Frame f` holds `local` (progress while
|
|
127
|
+
- `Frame f` holds `local` (progress while the section holds the formation: 0 before, 1 after), `approach` (0 → 1 while the section scrolls in) and `time`.
|
|
126
128
|
- Shared helpers: `hashU`, `rnd`, `seedOf`, `gauss`, `noised`, `curl`, `bitangent`, `bezier3`, `rrectPoint`, `shapePoint`, `PI`, `TAU` and `FLOOR_Y`.
|
|
127
129
|
- `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
130
|
- A formation that follows the prism can take its `RAILS` and `SPECTRUM` from `@uxfront/scene/formations`, so rail `i` keeps its colour.
|
package/dist/experience.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clamp, damp, projectToScreen } from "./gl/math.js";
|
|
2
|
-
import { progressOf, stageAt } from "./gl/stage.js";
|
|
2
|
+
import { localOf, progressOf, sectionSpan, stageAt } from "./gl/stage.js";
|
|
3
3
|
//#region src/experience.ts
|
|
4
4
|
const initialExperienceState = () => ({
|
|
5
5
|
chapter: 0,
|
|
@@ -73,11 +73,9 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
73
73
|
const scrollY = window.scrollY;
|
|
74
74
|
sections = Array.from(root.querySelectorAll("[data-stage]")).map((el) => {
|
|
75
75
|
const rect = el.getBoundingClientRect();
|
|
76
|
-
const start = rect.top + scrollY;
|
|
77
76
|
return {
|
|
78
77
|
el,
|
|
79
|
-
|
|
80
|
-
end: Math.max(start, start + rect.height - viewport)
|
|
78
|
+
...sectionSpan(rect.top + scrollY, rect.height, viewport, maxScroll)
|
|
81
79
|
};
|
|
82
80
|
});
|
|
83
81
|
engine?.resize();
|
|
@@ -196,7 +194,8 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
196
194
|
if (section) {
|
|
197
195
|
const steps = Number(section.dataset.steps || 0);
|
|
198
196
|
if (steps > 0) {
|
|
199
|
-
const
|
|
197
|
+
const read = clamp(localOf(held, stage, local), 0, .999);
|
|
198
|
+
const step = String(Math.min(steps - 1, Math.floor(read * steps)));
|
|
200
199
|
if (section.dataset.step !== step) section.dataset.step = step;
|
|
201
200
|
}
|
|
202
201
|
}
|
package/dist/gl/stage.d.ts
CHANGED
|
@@ -12,14 +12,26 @@ export declare const presenceOf: (k: number, stage: number) => number;
|
|
|
12
12
|
export declare const approachOf: (k: number, stage: number) => number;
|
|
13
13
|
export declare function progressOf(k: number, stage: number, local: number, time: number): FormationProgress;
|
|
14
14
|
export interface SectionSpan {
|
|
15
|
-
/** Scroll offset at which the section
|
|
15
|
+
/** Scroll offset at which the section starts holding its formation. */
|
|
16
16
|
start: number;
|
|
17
|
-
/** Scroll offset at which
|
|
17
|
+
/** Scroll offset at which it stops. */
|
|
18
18
|
end: number;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* and
|
|
21
|
+
* How far, in viewport heights, a section holds its formation before it
|
|
22
|
+
* fills the viewport and after it starts to leave. The rest of the scroll
|
|
23
|
+
* between two sections morphs one formation into the next.
|
|
24
|
+
*/
|
|
25
|
+
export declare const HOLD_MARGIN = .25;
|
|
26
|
+
/**
|
|
27
|
+
* The span over which a section holds its formation: while it fills the
|
|
28
|
+
* viewport, plus `HOLD_MARGIN` on either side, within the page's scroll range.
|
|
29
|
+
* The page scrolls freely: the copy moves with it while the formation holds.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sectionSpan(top: number, height: number, viewport: number, maxScroll: number): SectionSpan;
|
|
32
|
+
/**
|
|
33
|
+
* Scroll → stage. A section holds its formation across its span (local 0 → 1)
|
|
34
|
+
* and morphs into the next one between the two spans.
|
|
23
35
|
*/
|
|
24
36
|
export declare function stageAt(sections: SectionSpan[], y: number): {
|
|
25
37
|
stage: number;
|
package/dist/gl/stage.js
CHANGED
|
@@ -20,8 +20,27 @@ function progressOf(k, stage, local, time) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
* and
|
|
23
|
+
* How far, in viewport heights, a section holds its formation before it
|
|
24
|
+
* fills the viewport and after it starts to leave. The rest of the scroll
|
|
25
|
+
* between two sections morphs one formation into the next.
|
|
26
|
+
*/
|
|
27
|
+
const HOLD_MARGIN = .25;
|
|
28
|
+
/**
|
|
29
|
+
* The span over which a section holds its formation: while it fills the
|
|
30
|
+
* viewport, plus `HOLD_MARGIN` on either side, within the page's scroll range.
|
|
31
|
+
* The page scrolls freely: the copy moves with it while the formation holds.
|
|
32
|
+
*/
|
|
33
|
+
function sectionSpan(top, height, viewport, maxScroll) {
|
|
34
|
+
const margin = viewport * HOLD_MARGIN;
|
|
35
|
+
const start = clamp(top - margin, 0, maxScroll);
|
|
36
|
+
return {
|
|
37
|
+
start,
|
|
38
|
+
end: clamp(top + height - viewport + margin, start, maxScroll)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Scroll → stage. A section holds its formation across its span (local 0 → 1)
|
|
43
|
+
* and morphs into the next one between the two spans.
|
|
25
44
|
*/
|
|
26
45
|
function stageAt(sections, y) {
|
|
27
46
|
for (let k = 0; k < sections.length; k++) {
|
|
@@ -52,4 +71,4 @@ function stageAt(sections, y) {
|
|
|
52
71
|
};
|
|
53
72
|
}
|
|
54
73
|
//#endregion
|
|
55
|
-
export { approachOf, localOf, presenceOf, progressOf, stageAt };
|
|
74
|
+
export { HOLD_MARGIN, approachOf, localOf, presenceOf, progressOf, sectionSpan, stageAt };
|
package/dist/gl/types.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface FormationLook {
|
|
|
29
29
|
export interface FormationProgress {
|
|
30
30
|
/** Scene stage: a formation index plus the progress of the morph to the next one. */
|
|
31
31
|
stage: number;
|
|
32
|
-
/** Progress through the formation while its section
|
|
32
|
+
/** Progress through the formation while its section holds it: 0 before, 1 after. */
|
|
33
33
|
local: number;
|
|
34
34
|
/** 0 → 1 while the formation's section scrolls in, 1 from then on. */
|
|
35
35
|
approach: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ import { ShaderPart, composeParticleShader, namespaceGlsl } from "./gl/compose.j
|
|
|
6
6
|
import { BASE_PARTICLES, FLOOR_Y } from "./gl/constants.js";
|
|
7
7
|
import { defineFormation, mergeViews } from "./gl/formation.js";
|
|
8
8
|
import { glslArray, glslFloat, glslVec } from "./gl/glsl.js";
|
|
9
|
-
import { SectionSpan, approachOf, localOf, presenceOf, progressOf, stageAt } from "./gl/stage.js";
|
|
9
|
+
import { HOLD_MARGIN, SectionSpan, approachOf, localOf, presenceOf, progressOf, sectionSpan, stageAt } from "./gl/stage.js";
|
|
10
10
|
import { STACKED_QUERY } from "./layout.js";
|
|
11
|
-
export { type AnchorDef, BASE_PARTICLES, type Experience, type ExperienceOptions, type ExperienceState, FLOOR_Y, type Formation, type FormationDef, type FormationFrame, type FormationLook, type FormationOptions, type FormationProgress, type FormationShader, type FormationViews, type GlStatus, type Mat4, type PackedShapes, STACKED_QUERY, type SectionSpan, type ShaderPart, type Shape, type StageView, type Uniforms, type Vec2, type Vec3, type Vec4, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslArray, glslFloat, glslVec, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, smoothstep, stageAt };
|
|
11
|
+
export { type AnchorDef, BASE_PARTICLES, type Experience, type ExperienceOptions, type ExperienceState, FLOOR_Y, type Formation, type FormationDef, type FormationFrame, type FormationLook, type FormationOptions, type FormationProgress, type FormationShader, type FormationViews, type GlStatus, HOLD_MARGIN, type Mat4, type PackedShapes, STACKED_QUERY, type SectionSpan, type ShaderPart, type Shape, type StageView, type Uniforms, type Vec2, type Vec3, type Vec4, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslArray, glslFloat, glslVec, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, sectionSpan, smoothstep, stageAt };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clamp, damp, lerp, lerp3, projectToScreen, smoothstep } from "./gl/math.js";
|
|
2
|
-
import { approachOf, localOf, presenceOf, progressOf, stageAt } from "./gl/stage.js";
|
|
2
|
+
import { HOLD_MARGIN, approachOf, localOf, presenceOf, progressOf, sectionSpan, stageAt } from "./gl/stage.js";
|
|
3
3
|
import { createExperience, initialExperienceState } from "./experience.js";
|
|
4
4
|
import { BASE_PARTICLES, FLOOR_Y } from "./gl/constants.js";
|
|
5
5
|
import { packShapes } from "./gl/shapes.js";
|
|
@@ -7,4 +7,4 @@ import { glslArray, glslFloat, glslVec } from "./gl/glsl.js";
|
|
|
7
7
|
import { composeParticleShader, namespaceGlsl } from "./gl/compose.js";
|
|
8
8
|
import { defineFormation, mergeViews } from "./gl/formation.js";
|
|
9
9
|
import { STACKED_QUERY } from "./layout.js";
|
|
10
|
-
export { BASE_PARTICLES, FLOOR_Y, STACKED_QUERY, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslArray, glslFloat, glslVec, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, smoothstep, stageAt };
|
|
10
|
+
export { BASE_PARTICLES, FLOOR_Y, HOLD_MARGIN, STACKED_QUERY, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslArray, glslFloat, glslVec, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, sectionSpan, smoothstep, stageAt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxfront/scene",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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",
|