@jsb188/gfx 1.1.2 → 1.1.11
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 +54 -248
- package/libs/dotGrid.ts +77 -480
- package/libs/effects/effectQuad.ts +2 -8
- package/libs/pointer.ts +0 -6
- package/libs/runtime.ts +4 -6
- package/libs/types.ts +1 -8
- package/main.ts +0 -2
- package/modules/Carousel.helpers.ts +0 -234
- package/modules/Carousel.tsx +29 -135
- package/modules/DotsArea.tsx +120 -0
- package/modules/GfxCanvas.tsx +2 -10
- package/modules/ScrollSteps.tsx +52 -7
- package/modules/VisionBoard.helpers.ts +561 -0
- package/modules/VisionBoard.tsx +358 -0
- package/modules/VisionBoard.types.ts +88 -0
- package/package.json +5 -15
- package/scenes/Carousel.ts +18 -99
- package/scenes/DotsArea.ts +208 -0
- package/tsconfig.json +1 -1
- package/utils/color.ts +2 -64
- package/utils/dotGridSpecs.ts +46 -304
- package/elements/Shapes.helpers.ts +0 -204
- package/elements/Shapes.hooks.ts +0 -171
- package/elements/Shapes.tsx +0 -505
- package/elements/Shapes.types.ts +0 -81
- package/elements/Stack.helpers.ts +0 -42
- package/elements/Stack.tsx +0 -143
- package/elements/Text.helpers.ts +0 -45
- package/elements/Text.hooks.ts +0 -197
- package/elements/Text.tsx +0 -98
- package/libs/dotGrid.helpers.ts +0 -53
- package/libs/effects/dotEffects.ts +0 -136
- package/modules/Carousel.hooks.ts +0 -520
- package/modules/Dots.tsx +0 -269
- package/modules/DotsBoard.helpers.ts +0 -388
- package/modules/DotsBoard.hooks.ts +0 -144
- package/modules/DotsBoard.strings.ts +0 -649
- package/modules/DotsBoard.types.ts +0 -240
- package/modules/DotsBoardCanvas.hooks.ts +0 -49
- package/modules/DotsBoardCanvas.tsx +0 -190
- package/modules/DotsBoardElements.tsx +0 -330
- package/modules/Gallery.helpers.ts +0 -32
- package/modules/Gallery.hooks.ts +0 -149
- package/modules/Gallery.tsx +0 -194
- package/modules/KineticHeader.helpers.ts +0 -44
- package/modules/KineticHeader.hooks.ts +0 -206
- package/modules/KineticHeader.tsx +0 -305
- package/modules/KineticHeader.types.ts +0 -56
- package/modules/ScrollSteps.hooks.ts +0 -138
- package/scenes/DotsBoard.helpers.ts +0 -12
- package/scenes/DotsBoard.ts +0 -245
- package/utils/align.ts +0 -18
- package/utils/dotEffectSpecs.ts +0 -79
- package/utils/motion.ts +0 -88
- package/utils/random.ts +0 -22
- package/utils/strings.ts +0 -116
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { jitter } from '../utils/random.ts';
|
|
2
|
-
import type { PixelCell, ShapeBox, ShapeIcon, ShapeKind, ShapeLineStyle, ShapeOutline, ShapePoints } from './Shapes.types.ts';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Outline
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* A coordinate to a thousandth of a pixel: `Math.sin` / `Math.cos` differ in their last digits
|
|
10
|
-
* between the server's and the browser's V8, so full-precision path data fails hydration.
|
|
11
|
-
*/
|
|
12
|
-
function fix(value: number): number {
|
|
13
|
-
return Math.round(value * 1000) / 1000;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
* Outline points for a built-in shape filling `box`, each point displaced by up to `wobble` pixels.
|
|
18
|
-
*/
|
|
19
|
-
export function shapePoints(kind: Exclude<ShapeKind, ShapeIcon>, box: ShapeBox, wobble: number, random: () => number): ShapePoints {
|
|
20
|
-
const { cx, cy, rx, ry } = box;
|
|
21
|
-
const wobbled = (points: [number, number][]): ShapePoints =>
|
|
22
|
-
points.map(([x, y]) => [fix(x + jitter(random, wobble)), fix(y + jitter(random, wobble))]);
|
|
23
|
-
// Points around an ellipse in the box, `scaleAt` stretching its radius per angle.
|
|
24
|
-
const around = (count: number, scaleAt: (angle: number) => number): ShapePoints =>
|
|
25
|
-
wobbled(
|
|
26
|
-
Array.from({ length: count }, (_, i) => {
|
|
27
|
-
const angle = (i / count) * Math.PI * 2;
|
|
28
|
-
const scale = scaleAt(angle);
|
|
29
|
-
return [cx + Math.cos(angle) * rx * scale, cy + Math.sin(angle) * ry * scale];
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
|
-
switch (kind) {
|
|
33
|
-
case 'square':
|
|
34
|
-
return wobbled([
|
|
35
|
-
[cx - rx, cy - ry],
|
|
36
|
-
[cx + rx, cy - ry],
|
|
37
|
-
[cx + rx, cy + ry],
|
|
38
|
-
[cx - rx, cy + ry],
|
|
39
|
-
]);
|
|
40
|
-
case 'triangle': {
|
|
41
|
-
// Sitting on its base and vertically centered on the box, a little wider than it.
|
|
42
|
-
const h = ry * 1.9;
|
|
43
|
-
const top = cy - h / 2;
|
|
44
|
-
return wobbled([
|
|
45
|
-
[cx, top],
|
|
46
|
-
[cx + rx * 1.08, top + h],
|
|
47
|
-
[cx - rx * 1.08, top + h],
|
|
48
|
-
]);
|
|
49
|
-
}
|
|
50
|
-
case 'circle':
|
|
51
|
-
return around(24, () => 1);
|
|
52
|
-
case 'blob':
|
|
53
|
-
return around(20, (a) => 1 + Math.sin(a * 3) * 0.14 + Math.cos(a * 2) * 0.1);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/*
|
|
58
|
-
* Closed path through the points with straight segments.
|
|
59
|
-
*/
|
|
60
|
-
function straightPath(points: ShapePoints): string {
|
|
61
|
-
return `M${points.map((p) => p.join(' ')).join('L')}Z`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/*
|
|
65
|
-
* Closed path through the points as a smooth curve (quadratics through segment midpoints).
|
|
66
|
-
*/
|
|
67
|
-
function smoothPath(points: ShapePoints): string {
|
|
68
|
-
const first = points[0];
|
|
69
|
-
const last = points[points.length - 1];
|
|
70
|
-
let d = `M${fix((first[0] + last[0]) / 2)} ${fix((first[1] + last[1]) / 2)}`;
|
|
71
|
-
for (let i = 0; i < points.length; i++) {
|
|
72
|
-
const a = points[i];
|
|
73
|
-
const b = points[(i + 1) % points.length];
|
|
74
|
-
d += `Q${a.join(' ')} ${fix((a[0] + b[0]) / 2)} ${fix((a[1] + b[1]) / 2)}`;
|
|
75
|
-
}
|
|
76
|
-
return `${d}Z`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/*
|
|
80
|
-
* Closed polygon whose corners are cut with a quadratic of `cornerRadius` pixels.
|
|
81
|
-
*/
|
|
82
|
-
function roundedPolygonPath(points: ShapePoints, cornerRadius: number): string {
|
|
83
|
-
const n = points.length;
|
|
84
|
-
let d = '';
|
|
85
|
-
for (let i = 0; i < n; i++) {
|
|
86
|
-
const prev = points[(i - 1 + n) % n];
|
|
87
|
-
const v = points[i];
|
|
88
|
-
const next = points[(i + 1) % n];
|
|
89
|
-
const toward = (target: [number, number]): [number, number] => {
|
|
90
|
-
const dx = target[0] - v[0];
|
|
91
|
-
const dy = target[1] - v[1];
|
|
92
|
-
const len = Math.hypot(dx, dy) || 1;
|
|
93
|
-
const t = Math.min(cornerRadius, len / 2) / len;
|
|
94
|
-
return [fix(v[0] + dx * t), fix(v[1] + dy * t)];
|
|
95
|
-
};
|
|
96
|
-
const a = toward(prev);
|
|
97
|
-
const b = toward(next);
|
|
98
|
-
d += `${i === 0 ? 'M' : 'L'}${a.join(' ')}Q${v.join(' ')} ${b.join(' ')}`;
|
|
99
|
-
}
|
|
100
|
-
return `${d}Z`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/*
|
|
104
|
-
* The outline for a shape filling `box` in the given line style: a custom icon's own path,
|
|
105
|
-
* scaled by a transform (never by rewriting its data, which would break arc flags) into the
|
|
106
|
-
* largest square centered in the box; an exact ellipse for a clean circle; a smooth curve
|
|
107
|
-
* through the points of a curved shape; and a polygon with rounded or sharp corners
|
|
108
|
-
* otherwise. `sketch` wobbles every point of a built-in shape first (an icon keeps its path;
|
|
109
|
-
* the sketch filter roughens its edge).
|
|
110
|
-
*/
|
|
111
|
-
export function shapeOutline(kind: ShapeKind, line: ShapeLineStyle, box: ShapeBox, random: () => number): ShapeOutline {
|
|
112
|
-
const { cx, cy, rx, ry } = box;
|
|
113
|
-
const r = Math.min(rx, ry);
|
|
114
|
-
if (typeof kind === 'object') {
|
|
115
|
-
const scale = (r * 2) / (kind.viewBox ?? 24);
|
|
116
|
-
return { d: kind.d, transform: `translate(${fix(cx - r)} ${fix(cy - r)}) scale(${fix(scale)})` };
|
|
117
|
-
}
|
|
118
|
-
if (kind === 'circle' && line !== 'sketch') {
|
|
119
|
-
return { d: `M${cx - rx} ${cy}a${rx} ${ry} 0 1 0 ${rx * 2} 0a${rx} ${ry} 0 1 0 ${-rx * 2} 0Z` };
|
|
120
|
-
}
|
|
121
|
-
const points = shapePoints(kind, box, line === 'sketch' ? r * 0.045 : 0, random);
|
|
122
|
-
if (kind === 'circle' || kind === 'blob') return { d: smoothPath(points) };
|
|
123
|
-
if (line === 'rounded') return { d: roundedPolygonPath(points, r * 0.16) };
|
|
124
|
-
return { d: straightPath(points) };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Brush
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
/*
|
|
132
|
-
* How many brush passes a box takes: `rows` for a square, more for a taller box so the
|
|
133
|
-
* passes stay about as thick.
|
|
134
|
-
*/
|
|
135
|
-
export function brushRows(box: ShapeBox, rows: number): number {
|
|
136
|
-
return Math.max(3, Math.round((rows * box.ry) / box.rx));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/*
|
|
140
|
-
* Stroke width that makes `rows` brush passes over a box `ry` tall overlap into solid cover.
|
|
141
|
-
*/
|
|
142
|
-
export function brushWidth(box: ShapeBox, rows: number): number {
|
|
143
|
-
return ((box.ry * 1.12 * 2) / rows) * 1.5;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/*
|
|
147
|
-
* A single brush stroke that sweeps down the shape box in wobbly horizontal passes, wide enough
|
|
148
|
-
* (see `brushWidth`) to leave no gaps. Clipped to the shape by the caller.
|
|
149
|
-
*/
|
|
150
|
-
export function brushPath(box: ShapeBox, rows: number, random: () => number): string {
|
|
151
|
-
const { cx, cy, rx, ry } = box;
|
|
152
|
-
const reachX = rx * 1.12;
|
|
153
|
-
const reachY = ry * 1.12;
|
|
154
|
-
const step = (reachY * 2) / rows;
|
|
155
|
-
let d = '';
|
|
156
|
-
for (let i = 0; i <= rows; i++) {
|
|
157
|
-
const y = fix(cy - reachY + i * step + jitter(random, step * 0.12));
|
|
158
|
-
const from = fix((i % 2 ? cx + reachX : cx - reachX) + jitter(random, rx * 0.08));
|
|
159
|
-
const to = fix((i % 2 ? cx - reachX : cx + reachX) + jitter(random, rx * 0.08));
|
|
160
|
-
d += `${i ? 'L' : 'M'}${from} ${y}Q${fix((from + to) / 2)} ${fix(y + jitter(random, step * 0.22))} ${to} ${y}`;
|
|
161
|
-
}
|
|
162
|
-
return d;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Pixelate
|
|
167
|
-
*/
|
|
168
|
-
|
|
169
|
-
/*
|
|
170
|
-
* How many mosaic cells span the shape's width for a pixelate `intensity`: two at 0, many at
|
|
171
|
-
* 1. The cell size follows from the shape's size, so the look scales with it.
|
|
172
|
-
*/
|
|
173
|
-
export function pixelateCells(intensity: number): number {
|
|
174
|
-
return Math.round(2 + 30 * Math.min(1, Math.max(0, intensity)));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/*
|
|
178
|
-
* The cells of one repeating mosaic tile, `columns × rows` of them, each shaded by a seeded
|
|
179
|
-
* random amount either way of the paint; the tile repeats over the shape, so a modest tile
|
|
180
|
-
* keeps the markup small.
|
|
181
|
-
*/
|
|
182
|
-
export function pixelateTile(columns: number, rows: number, random: () => number): PixelCell[] {
|
|
183
|
-
const cells: PixelCell[] = [];
|
|
184
|
-
for (let row = 0; row < rows; row++) {
|
|
185
|
-
for (let col = 0; col < columns; col++) cells.push({ col, row, shade: jitter(random, 1) });
|
|
186
|
-
}
|
|
187
|
-
return cells;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Pulse
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
|
-
/*
|
|
195
|
-
* One pulse of a `<PulsingMarker>` halo: from the dot's `size` to `pulseSize` across, lit while
|
|
196
|
-
* it grows and fading out in the second half, as the next halo comes up.
|
|
197
|
-
*/
|
|
198
|
-
export function pulseHaloKeyframes(size: number, pulseSize: number): Keyframe[] {
|
|
199
|
-
return [
|
|
200
|
-
{ transform: `scale(${size / pulseSize})`, opacity: 1 },
|
|
201
|
-
{ opacity: 0.7, offset: 0.5 },
|
|
202
|
-
{ transform: 'scale(1)', opacity: 0 },
|
|
203
|
-
];
|
|
204
|
-
}
|
package/elements/Shapes.hooks.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import type { RefObject } from 'react';
|
|
3
|
-
import { prefersReducedMotion } from '../utils/motion.ts';
|
|
4
|
-
import { pulseHaloKeyframes } from './Shapes.helpers.ts';
|
|
5
|
-
import type { ShapeState } from './Shapes.types.ts';
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
* Whether a reveal may start: `false` until `seen` has been true for `delayMs`, then `true`
|
|
9
|
-
* for good, so a shape that has scrolled into view waits a beat before it paints in.
|
|
10
|
-
*/
|
|
11
|
-
export function useRevealed(seen: boolean, delayMs: number) {
|
|
12
|
-
const [revealed, setRevealed] = useState(seen && delayMs <= 0);
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (!seen || revealed) return;
|
|
16
|
-
if (delayMs <= 0) {
|
|
17
|
-
setRevealed(true);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const timer = setTimeout(() => setRevealed(true), delayMs);
|
|
21
|
-
return () => clearTimeout(timer);
|
|
22
|
-
}, [seen, revealed, delayMs]);
|
|
23
|
-
|
|
24
|
-
return revealed;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** The states in painting order: each step from one to the next paints one layer in, or back out. */
|
|
28
|
-
export const SHAPE_STATES: ShapeState[] = ['empty', 'base', 'active'];
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
* The state a shape is currently painted toward, walking one step at a time toward `target`,
|
|
32
|
-
* and whether a step is under way: a step starts a layer's sweep and holds for `stepMs`, and
|
|
33
|
-
* only then is the (latest) target looked at again, so a sweep always finishes before the
|
|
34
|
-
* next begins, whichever way the target moved in the meantime. With `startEmpty` the walk
|
|
35
|
-
* starts from `empty`; otherwise the shape mounts already at `target`. `ref` is the element
|
|
36
|
-
* the sweeps run on; its style is flushed before each step so the transition has a starting
|
|
37
|
-
* value to leave from. With `animate` off the shape simply shows `target`, never stepping.
|
|
38
|
-
*/
|
|
39
|
-
export function useShapeState(
|
|
40
|
-
target: ShapeState,
|
|
41
|
-
stepMs: number,
|
|
42
|
-
animate: boolean,
|
|
43
|
-
startEmpty: boolean,
|
|
44
|
-
ref: RefObject<Element | null>,
|
|
45
|
-
) {
|
|
46
|
-
const [shown, setShown] = useState<ShapeState>(startEmpty ? 'empty' : target);
|
|
47
|
-
const [animating, setAnimating] = useState(false);
|
|
48
|
-
// What the running step will read when it lands, and the step's timer.
|
|
49
|
-
const latest = useRef({ target, stepMs, shown });
|
|
50
|
-
const timer = useRef<number | null>(null);
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
latest.current.target = target;
|
|
54
|
-
latest.current.stepMs = stepMs;
|
|
55
|
-
}, [target, stepMs]);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (!animate) {
|
|
59
|
-
latest.current.shown = target;
|
|
60
|
-
setShown(target);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// A step is under way; its timer takes the next one.
|
|
64
|
-
if (timer.current !== null) return;
|
|
65
|
-
const step = () => {
|
|
66
|
-
const { target: want, shown: from, stepMs: hold } = latest.current;
|
|
67
|
-
if (from === want) {
|
|
68
|
-
setAnimating(false);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const at = SHAPE_STATES.indexOf(from);
|
|
72
|
-
const next = SHAPE_STATES[at + (SHAPE_STATES.indexOf(want) > at ? 1 : -1)];
|
|
73
|
-
// Commit the current state's style (on mount it may never have been painted), so the sweep transitions from it.
|
|
74
|
-
void ref.current?.getBoundingClientRect();
|
|
75
|
-
latest.current.shown = next;
|
|
76
|
-
setShown(next);
|
|
77
|
-
setAnimating(true);
|
|
78
|
-
timer.current = window.setTimeout(() => {
|
|
79
|
-
timer.current = null;
|
|
80
|
-
step();
|
|
81
|
-
}, hold);
|
|
82
|
-
};
|
|
83
|
-
step();
|
|
84
|
-
}, [target, animate]);
|
|
85
|
-
|
|
86
|
-
// Forget the step's timer along with clearing it, so a remount (Strict Mode, Fast Refresh) walks on
|
|
87
|
-
// from `shown` instead of waiting forever for a timer that will never fire.
|
|
88
|
-
useEffect(
|
|
89
|
-
() => () => {
|
|
90
|
-
if (timer.current !== null) clearTimeout(timer.current);
|
|
91
|
-
timer.current = null;
|
|
92
|
-
},
|
|
93
|
-
[],
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
return { shown, animating };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/*
|
|
100
|
-
* Runs a `<PulsingMarker>`'s halos as Web Animations: each grows from the dot's `size` to
|
|
101
|
-
* `pulseSize` over `durationMs` and fades out, the halos staggered evenly through the cycle,
|
|
102
|
-
* over and over. While `held`, no new halo starts: each one finishes the cycle it is in, and
|
|
103
|
-
* then the pulse is still. Released, the pulse carries on: a halo still
|
|
104
|
-
* finishing its cycle simply keeps going, and the others wait for their turn at the usual
|
|
105
|
-
* spacing, so none pops in mid-growth.
|
|
106
|
-
*/
|
|
107
|
-
export function usePulseHalos(
|
|
108
|
-
halosRef: RefObject<(HTMLElement | null)[]>,
|
|
109
|
-
size: number,
|
|
110
|
-
pulseSize: number,
|
|
111
|
-
durationMs: number,
|
|
112
|
-
easing: string,
|
|
113
|
-
held: boolean,
|
|
114
|
-
) {
|
|
115
|
-
const loopsRef = useRef<(Animation | null)[]>([]);
|
|
116
|
-
// Whether the pulse was stopped, so only a release (not the first render) restarts it.
|
|
117
|
-
const heldRef = useRef(false);
|
|
118
|
-
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
if (prefersReducedMotion()) return;
|
|
121
|
-
const halos = halosRef.current;
|
|
122
|
-
loopsRef.current = halos.map((el, i) => {
|
|
123
|
-
if (!el || typeof el.animate !== 'function') return null;
|
|
124
|
-
const animation = el.animate(pulseHaloKeyframes(size, pulseSize), { duration: durationMs, iterations: Infinity, easing });
|
|
125
|
-
// Each halo starts its turn a share of the cycle after the last; before it, the halo's hidden base style shows.
|
|
126
|
-
animation.currentTime = (-i * durationMs) / halos.length;
|
|
127
|
-
return animation;
|
|
128
|
-
});
|
|
129
|
-
return () => {
|
|
130
|
-
for (const animation of loopsRef.current) animation?.cancel();
|
|
131
|
-
loopsRef.current = [];
|
|
132
|
-
};
|
|
133
|
-
}, [size, pulseSize, durationMs, easing]);
|
|
134
|
-
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
const loops = loopsRef.current;
|
|
137
|
-
if (!loops.some(Boolean)) return;
|
|
138
|
-
|
|
139
|
-
const wasHeld = heldRef.current;
|
|
140
|
-
heldRef.current = held;
|
|
141
|
-
if (held) {
|
|
142
|
-
// Each halo ends after the cycle it is in; one still waiting for its first turn never starts.
|
|
143
|
-
for (const loop of loops) {
|
|
144
|
-
if (!loop) continue;
|
|
145
|
-
const time = Number(loop.currentTime ?? 0);
|
|
146
|
-
if (time < 0) loop.pause();
|
|
147
|
-
else loop.effect?.updateTiming({ iterations: Math.floor(time / durationMs) + 1 });
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!wasHeld) return;
|
|
153
|
-
const count = loops.length;
|
|
154
|
-
const isRunning = (loop: Animation | null) => !!loop && loop.playState === 'running' && Number(loop.currentTime) >= 0;
|
|
155
|
-
// Where the first halo would be in the pulse: kept from a halo still finishing its cycle, or starting afresh.
|
|
156
|
-
const runningAt = loops.findIndex(isRunning);
|
|
157
|
-
const base = runningAt < 0 ? 0 : Number(loops[runningAt]?.currentTime) + (runningAt * durationMs) / count;
|
|
158
|
-
const running = loops.map(isRunning);
|
|
159
|
-
loops.forEach((loop, i) => {
|
|
160
|
-
if (!loop) return;
|
|
161
|
-
loop.effect?.updateTiming({ iterations: Infinity });
|
|
162
|
-
// Played first: `play()` rewinds a time before the start to 0.
|
|
163
|
-
loop.play();
|
|
164
|
-
if (!running[i]) {
|
|
165
|
-
// Wait (before its active phase, so hidden) until its place in the spacing next comes round to the start of a cycle.
|
|
166
|
-
const phase = (((base - (i * durationMs) / count) % durationMs) + durationMs) % durationMs;
|
|
167
|
-
loop.currentTime = phase === 0 ? 0 : phase - durationMs;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}, [held]);
|
|
171
|
-
}
|