@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
package/utils/dotGridSpecs.ts
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Dot grid options, their defaults, a matching static SVG tile
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Dot grid options, their defaults, and a matching static SVG tile. This module has no
|
|
3
|
+
* runtime dependency on OGL, so route bundles can import it to render a CSS fallback of the
|
|
4
|
+
* same grid before (or without) the engine.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { DOT_EFFECT_DEFAULTS, DOT_SHAPES, resolveDotEffectOptions } from './dotEffectSpecs.ts';
|
|
11
|
-
import type { DotEffectOptions, DotShape } from './dotEffectSpecs.ts';
|
|
12
|
-
|
|
13
|
-
export { DOT_SHAPES, DOT_EFFECTS } from './dotEffectSpecs.ts';
|
|
14
|
-
export type { DotEffect, DotEffectSelection, DotEffectOptions, DotShape } from './dotEffectSpecs.ts';
|
|
15
|
-
|
|
16
|
-
/** Where the grid is anchored along each axis, like the keywords of CSS `mask-position`. */
|
|
17
|
-
export const DOT_ALIGN_X = ALIGN_X;
|
|
18
|
-
export const DOT_ALIGN_Y = ALIGN_Y;
|
|
19
|
-
export type DotAlignX = AlignX;
|
|
20
|
-
export type DotAlignY = AlignY;
|
|
21
|
-
/** A dot center a number of CSS pixels in from one edge; `{ left }` / `{ top }` are the same as a bare number. */
|
|
22
|
-
export type DotAlignXOffset = { left: number } | { right: number };
|
|
23
|
-
export type DotAlignYOffset = { top: number } | { bottom: number };
|
|
24
|
-
/** Any anchor along either axis, as the grid helpers accept it. */
|
|
25
|
-
export type DotAlign = DotAlignX | DotAlignY | number | DotAlignXOffset | DotAlignYOffset;
|
|
7
|
+
/** Shapes a dot can take; `size` is the shape's bounding diameter either way. */
|
|
8
|
+
export const DOT_SHAPES = ['circle', 'rounded_square'] as const;
|
|
9
|
+
export type DotShape = (typeof DOT_SHAPES)[number];
|
|
26
10
|
|
|
27
11
|
/** The grid at rest. */
|
|
28
12
|
export interface DotStyle {
|
|
@@ -36,20 +20,14 @@ export interface DotStyle {
|
|
|
36
20
|
color?: string;
|
|
37
21
|
/** 0..1 opacity of the dots. */
|
|
38
22
|
opacity?: number;
|
|
39
|
-
/** Horizontal anchor: `center` puts a column on the middle of the area; `left` hides the first column just past the left edge (its center one `size` out, so the first visible column is about a spacing in); `right` sets the last column flush against the right edge; a number (or `{ left }`) puts a column's center that many CSS pixels from the left edge, `{ right }` that many from the right edge. */
|
|
40
|
-
alignX?: DotAlignX | number | DotAlignXOffset;
|
|
41
|
-
/** Vertical anchor: `center` puts a row on the middle of the area; `top` hides the first row just past the top edge (its center one `size` up, so the first visible row is about a spacing down); `bottom` sets the last row flush against the bottom edge; a number (or `{ top }`) puts a row's center that many CSS pixels from the top edge, `{ bottom }` that many from the bottom edge. */
|
|
42
|
-
alignY?: DotAlignY | number | DotAlignYOffset;
|
|
43
23
|
}
|
|
44
24
|
|
|
45
25
|
/** How a moving cursor throws the dots, and how they come back. */
|
|
46
26
|
export interface DotKick {
|
|
47
|
-
/** Radius in CSS pixels around the
|
|
27
|
+
/** Radius in CSS pixels around the cursor within which its movement kicks the dots. */
|
|
48
28
|
radius?: number;
|
|
49
|
-
/** A fast swipe throws dots about `radius × strength` pixels; negative pulls
|
|
29
|
+
/** A fast swipe throws the dots at its centre about `radius × strength` pixels; negative pulls them toward the cursor's path. */
|
|
50
30
|
strength?: number;
|
|
51
|
-
/** Extra per-dot variation in strength and direction, from 0 (default) to 1; stable across hover frames. */
|
|
52
|
-
randomness?: number;
|
|
53
31
|
/** Milliseconds for a thrown dot to settle back home. */
|
|
54
32
|
bounceDuration?: number;
|
|
55
33
|
/** 0..1 how springy the return is: 0 glides back with no overshoot, 1 rings for the whole duration. */
|
|
@@ -66,59 +44,38 @@ export interface ThrownDotStyle {
|
|
|
66
44
|
scale?: number;
|
|
67
45
|
}
|
|
68
46
|
|
|
69
|
-
/**
|
|
70
|
-
export interface DotPulse
|
|
71
|
-
/** About how many dots
|
|
47
|
+
/** Ambient animation: every cycle a random handful of dots swell and shrink back. Starts only once any reveal has finished. */
|
|
48
|
+
export interface DotPulse {
|
|
49
|
+
/** About how many dots pulse per cycle. */
|
|
72
50
|
count?: number;
|
|
73
51
|
/** Milliseconds per cycle; a new random set is picked each cycle. */
|
|
74
52
|
interval?: number;
|
|
53
|
+
/** Milliseconds one dot takes to swell and return; capped at `interval`. */
|
|
54
|
+
duration?: number;
|
|
55
|
+
/** Size multiplier at the peak of a pulse. */
|
|
56
|
+
scale?: number;
|
|
57
|
+
/** 0..1 opacity at the peak of a pulse; defaults to the resting opacity. */
|
|
58
|
+
opacity?: number;
|
|
59
|
+
/** Shape a pulsing dot morphs into at its peak; defaults to `dots.shape`. */
|
|
60
|
+
shape?: DotShape;
|
|
75
61
|
}
|
|
76
62
|
|
|
77
|
-
/**
|
|
78
|
-
export interface DotClick extends DotEffectOptions {
|
|
79
|
-
/** Ripple-click impulse strength, independent of cursor kicks; 0 (default) disables it, negative pulls inward. */
|
|
80
|
-
kickStrength?: number;
|
|
81
|
-
/** Radius in CSS pixels of the ripple-click impulse, independent of the visual ripple and cursor; defaults to 80. */
|
|
82
|
-
kickRadius?: number;
|
|
83
|
-
/** Extra per-click variation in each dot's impulse strength and direction, from 0 (default) to 1. */
|
|
84
|
-
kickRandomness?: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** An effect across the resting grid, repeated without pointer interaction after the reveal. */
|
|
88
|
-
export interface DotRest extends DotEffectOptions {
|
|
89
|
-
/** Milliseconds between cycles; duration is capped at this interval. */
|
|
90
|
-
interval?: number;
|
|
91
|
-
/** Center of the area, or a new random point inside it each cycle. */
|
|
92
|
-
origin?: 'center' | 'random';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** A fade along the bottom edge, this many CSS pixels high: to transparent, or with `color` (hex) to that flat color. */
|
|
96
|
-
export type DotFade = number | { height: number; color?: string };
|
|
97
|
-
|
|
98
|
-
/** Intro: shrink a filled area into dots, or grow dots from an empty background. */
|
|
63
|
+
/** Intro: the dots start large enough to fill the whole area, then shrink to their size. */
|
|
99
64
|
export interface DotReveal {
|
|
100
|
-
/**
|
|
101
|
-
effect?: 'fade_out' | 'appear';
|
|
102
|
-
/** Starting diameter in CSS pixels for `appear`. Defaults to 0 (an empty background). */
|
|
103
|
-
initialSize?: number;
|
|
104
|
-
/** Peak diameter in CSS pixels for `appear`, then shrink to `dots.size`. Defaults to `dots.size`; smaller values are clamped to it. */
|
|
105
|
-
appearSize?: number;
|
|
106
|
-
/** Milliseconds the initial state holds before the dots animate. */
|
|
65
|
+
/** Milliseconds the filled state holds before the dots start shrinking. */
|
|
107
66
|
delay?: number;
|
|
108
|
-
/** Milliseconds
|
|
67
|
+
/** Milliseconds the shrink takes. */
|
|
109
68
|
duration?: number;
|
|
110
69
|
/** Scale the overlay image starts at on mount (1.25 = 125%), easing to 1 over `zoomDuration`; 1 for no zoom. Runs independently of `delay`: the dots start shrinking when the delay is up whether or not the zoom has finished. Only with an image. */
|
|
111
70
|
zoomOnMount?: number;
|
|
112
71
|
/** Milliseconds the zoom to 100% takes. */
|
|
113
72
|
zoomDuration?: number;
|
|
114
|
-
/** A bottom fade for `fade_out`'s filled state; it holds through the shrink and then hands over to the dots' fade. `appear` uses the dots' fade throughout. */
|
|
115
|
-
fadeBottom?: DotFade;
|
|
116
73
|
}
|
|
117
74
|
|
|
118
75
|
/** Resolved options are themselves valid options, so a scene can hand them straight to the grid. */
|
|
119
76
|
export interface DotGridOptions {
|
|
120
77
|
dots?: DotStyle;
|
|
121
|
-
/** `false`
|
|
78
|
+
/** `false` for a static grid. */
|
|
122
79
|
kick?: DotKick | false | null;
|
|
123
80
|
/** `false` (or omitted) leaves thrown dots looking like resting ones. */
|
|
124
81
|
thrown?: ThrownDotStyle | false | null;
|
|
@@ -126,57 +83,28 @@ export interface DotGridOptions {
|
|
|
126
83
|
reveal?: DotReveal | boolean | null;
|
|
127
84
|
/** `true` for the defaults; `false` (or omitted) for no pulsing. */
|
|
128
85
|
pulse?: DotPulse | boolean | null;
|
|
129
|
-
/** `true` for the default ripple; `false` (or omitted) disables click effects. */
|
|
130
|
-
click?: DotClick | boolean | null;
|
|
131
|
-
/** Ambient effects across resting dots; omitted or false leaves the grid at rest. */
|
|
132
|
-
rest?: DotRest | boolean | null;
|
|
133
86
|
}
|
|
134
87
|
|
|
135
88
|
export interface ResolvedDotGridOptions {
|
|
136
89
|
dots: Required<DotStyle>;
|
|
137
|
-
/** Null when
|
|
90
|
+
/** Null when the grid is static. */
|
|
138
91
|
kick: Required<DotKick> | null;
|
|
139
92
|
/** Null when thrown dots keep the resting look. */
|
|
140
93
|
thrown: (Required<Omit<ThrownDotStyle, 'color'>> & { color: string | null }) | null;
|
|
141
|
-
/** Null when there is no intro.
|
|
142
|
-
reveal:
|
|
94
|
+
/** Null when there is no intro. */
|
|
95
|
+
reveal: Required<DotReveal> | null;
|
|
143
96
|
/** Null when nothing pulses. */
|
|
144
97
|
pulse: Required<DotPulse> | null;
|
|
145
|
-
/** Null when clicks have no effect. */
|
|
146
|
-
click: Required<DotClick> | null;
|
|
147
|
-
/** Null when there is no animation across the resting grid. */
|
|
148
|
-
rest: Required<DotRest> | null;
|
|
149
98
|
}
|
|
150
99
|
|
|
151
100
|
/** Matches the `.pattern_speckle` mask tile: a 7×7 tile with a centered 2.25px dot. */
|
|
152
101
|
export const DOT_GRID_DEFAULTS = {
|
|
153
|
-
dots: {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
spacing: 7,
|
|
157
|
-
color: '#ffffff',
|
|
158
|
-
opacity: 1,
|
|
159
|
-
alignX: 'center' as DotAlignX | number | DotAlignXOffset,
|
|
160
|
-
alignY: 'center' as DotAlignY | number | DotAlignYOffset,
|
|
161
|
-
},
|
|
162
|
-
kick: { radius: 80, strength: 1, randomness: 0, bounceDuration: 1200, bounciness: 0.5 },
|
|
163
|
-
reveal: { effect: 'fade_out' as const, initialSize: 0, delay: 1000, duration: 800, zoomOnMount: 1, zoomDuration: 1000 },
|
|
102
|
+
dots: { size: 2.25, shape: 'circle' as DotShape, spacing: 7, color: '#ffffff', opacity: 1 },
|
|
103
|
+
kick: { radius: 80, strength: 1, bounceDuration: 1200, bounciness: 0.5 },
|
|
104
|
+
reveal: { delay: 1000, duration: 800, zoomOnMount: 1, zoomDuration: 1000 },
|
|
164
105
|
pulse: { count: 20, interval: 3000, duration: 1500, scale: 3 },
|
|
165
|
-
click: { ...DOT_EFFECT_DEFAULTS, kickStrength: 0, kickRadius: 80, kickRandomness: 0 },
|
|
166
|
-
rest: { interval: 6000, duration: 1800, scale: 2, origin: 'center' as const },
|
|
167
106
|
};
|
|
168
107
|
|
|
169
|
-
/*
|
|
170
|
-
* A bottom fade's height in CSS pixels (0 without one) and the flat color it fades to (null
|
|
171
|
-
* for transparent).
|
|
172
|
-
*/
|
|
173
|
-
export function resolveDotFade(fade: DotFade | undefined) {
|
|
174
|
-
return {
|
|
175
|
-
height: Math.max(0, (typeof fade === 'number' ? fade : fade?.height) ?? 0),
|
|
176
|
-
color: (typeof fade === 'object' && fade.color) || null,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
108
|
/*
|
|
181
109
|
* Clamp a number into a range, falling back to a default when it is not given.
|
|
182
110
|
*/
|
|
@@ -184,64 +112,32 @@ function clampOption(value: number | undefined, fallback: number, min: number, m
|
|
|
184
112
|
return Math.min(max, Math.max(min, value ?? fallback));
|
|
185
113
|
}
|
|
186
114
|
|
|
187
|
-
/*
|
|
188
|
-
* The pixel offset of an `{ edge: px }` anchor when it names one of `edges` with a finite
|
|
189
|
-
* number, or null when it is anything else.
|
|
190
|
-
*/
|
|
191
|
-
function getAlignOffset(value: unknown, edges: readonly string[]): { edge: string; offset: number } | null {
|
|
192
|
-
if (!value || typeof value !== 'object') return null;
|
|
193
|
-
for (const edge of edges) {
|
|
194
|
-
const offset = (value as Record<string, unknown>)[edge];
|
|
195
|
-
if (typeof offset === 'number' && Number.isFinite(offset)) return { edge, offset };
|
|
196
|
-
}
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/*
|
|
201
|
-
* An alignment as given, when it is one of the keywords, a finite pixel offset, or an
|
|
202
|
-
* `{ edge: px }` offset from the axis's start or end edge; the default otherwise.
|
|
203
|
-
*/
|
|
204
|
-
function resolveAlign<T extends string, O>(value: T | number | O | undefined, keywords: readonly T[], fallback: T | number | O) {
|
|
205
|
-
if (typeof value === 'number') return Number.isFinite(value) ? value : fallback;
|
|
206
|
-
if (getAlignOffset(value, keywords)) return value as O;
|
|
207
|
-
return typeof value === 'string' && keywords.includes(value as T) ? (value as T) : fallback;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
115
|
/*
|
|
211
116
|
* Fill in defaults and clamp to values the renderer can lay out (a zero spacing would mean an
|
|
212
117
|
* infinite grid). A kick with a non-positive radius or zero strength is off; the strength
|
|
213
118
|
* keeps its sign so negative pulls dots toward the cursor.
|
|
214
119
|
*/
|
|
215
120
|
export function resolveDotGridOptions(options: DotGridOptions = {}): ResolvedDotGridOptions {
|
|
216
|
-
const { dots = {}, kick = {}, thrown = false, reveal = false, pulse = false
|
|
121
|
+
const { dots = {}, kick = {}, thrown = false, reveal = false, pulse = false } = options;
|
|
217
122
|
const shape = dots.shape && DOT_SHAPES.includes(dots.shape) ? dots.shape : DOT_GRID_DEFAULTS.dots.shape;
|
|
218
|
-
const revealOptions = reveal === true ? {} : reveal;
|
|
219
|
-
const revealFade = resolveDotFade(revealOptions ? revealOptions.fadeBottom : undefined);
|
|
220
123
|
const pulseOptions = pulse === true ? {} : pulse;
|
|
221
|
-
const clickOptions = click === true ? {} : click;
|
|
222
|
-
const restOptions = rest === true ? {} : rest;
|
|
223
|
-
const restInterval = restOptions ? clampOption(restOptions.interval, DOT_GRID_DEFAULTS.rest.interval, 1) : 0;
|
|
224
124
|
const pulseInterval = pulseOptions ? clampOption(pulseOptions.interval, DOT_GRID_DEFAULTS.pulse.interval, 1) : 0;
|
|
225
125
|
const opacity = clampOption(dots.opacity, DOT_GRID_DEFAULTS.dots.opacity, 0, 1);
|
|
226
|
-
const dotSize = clampOption(dots.size, DOT_GRID_DEFAULTS.dots.size, 0);
|
|
227
126
|
const kickRadius = kick ? clampOption(kick.radius, DOT_GRID_DEFAULTS.kick.radius, 0) : 0;
|
|
228
127
|
const kickStrength = kick ? (kick.strength ?? DOT_GRID_DEFAULTS.kick.strength) : 0;
|
|
229
128
|
return {
|
|
230
129
|
dots: {
|
|
231
|
-
size:
|
|
130
|
+
size: clampOption(dots.size, DOT_GRID_DEFAULTS.dots.size, 0),
|
|
232
131
|
shape,
|
|
233
132
|
spacing: clampOption(dots.spacing, DOT_GRID_DEFAULTS.dots.spacing, 1),
|
|
234
133
|
color: dots.color ?? DOT_GRID_DEFAULTS.dots.color,
|
|
235
134
|
opacity,
|
|
236
|
-
alignX: resolveAlign(dots.alignX, DOT_ALIGN_X, DOT_GRID_DEFAULTS.dots.alignX),
|
|
237
|
-
alignY: resolveAlign(dots.alignY, DOT_ALIGN_Y, DOT_GRID_DEFAULTS.dots.alignY),
|
|
238
135
|
},
|
|
239
136
|
kick:
|
|
240
137
|
kick && kickRadius > 0 && kickStrength !== 0
|
|
241
138
|
? {
|
|
242
139
|
radius: kickRadius,
|
|
243
140
|
strength: kickStrength,
|
|
244
|
-
randomness: clampOption(kick.randomness, DOT_GRID_DEFAULTS.kick.randomness, 0, 1),
|
|
245
141
|
bounceDuration: clampOption(kick.bounceDuration, DOT_GRID_DEFAULTS.kick.bounceDuration, 50),
|
|
246
142
|
bounciness: clampOption(kick.bounciness, DOT_GRID_DEFAULTS.kick.bounciness, 0, 1),
|
|
247
143
|
}
|
|
@@ -253,47 +149,22 @@ export function resolveDotGridOptions(options: DotGridOptions = {}): ResolvedDot
|
|
|
253
149
|
scale: clampOption(thrown.scale, 1, 0),
|
|
254
150
|
}
|
|
255
151
|
: null,
|
|
256
|
-
reveal:
|
|
152
|
+
reveal: reveal
|
|
257
153
|
? {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
duration: clampOption(revealOptions.duration, DOT_GRID_DEFAULTS.reveal.duration, 1),
|
|
263
|
-
zoomOnMount: clampOption(revealOptions.zoomOnMount, DOT_GRID_DEFAULTS.reveal.zoomOnMount, 0.01),
|
|
264
|
-
zoomDuration: clampOption(revealOptions.zoomDuration, DOT_GRID_DEFAULTS.reveal.zoomDuration, 1),
|
|
265
|
-
fadeBottom: revealFade.height,
|
|
266
|
-
fadeColor: revealFade.color,
|
|
154
|
+
delay: clampOption(reveal === true ? undefined : reveal.delay, DOT_GRID_DEFAULTS.reveal.delay, 0),
|
|
155
|
+
duration: clampOption(reveal === true ? undefined : reveal.duration, DOT_GRID_DEFAULTS.reveal.duration, 1),
|
|
156
|
+
zoomOnMount: clampOption(reveal === true ? undefined : reveal.zoomOnMount, DOT_GRID_DEFAULTS.reveal.zoomOnMount, 0.01),
|
|
157
|
+
zoomDuration: clampOption(reveal === true ? undefined : reveal.zoomDuration, DOT_GRID_DEFAULTS.reveal.zoomDuration, 1),
|
|
267
158
|
}
|
|
268
159
|
: null,
|
|
269
160
|
pulse: pulseOptions
|
|
270
161
|
? {
|
|
271
|
-
...resolveDotEffectOptions(pulseOptions, {
|
|
272
|
-
...DOT_GRID_DEFAULTS.pulse,
|
|
273
|
-
effect: 'swell',
|
|
274
|
-
shape,
|
|
275
|
-
opacity,
|
|
276
|
-
radius: (dots.spacing ?? DOT_GRID_DEFAULTS.dots.spacing) * 3,
|
|
277
|
-
}),
|
|
278
162
|
count: clampOption(pulseOptions.count, DOT_GRID_DEFAULTS.pulse.count, 0),
|
|
279
163
|
interval: pulseInterval,
|
|
280
164
|
duration: clampOption(pulseOptions.duration, DOT_GRID_DEFAULTS.pulse.duration, 1, pulseInterval),
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
? {
|
|
285
|
-
...resolveDotEffectOptions(clickOptions, { shape, opacity }),
|
|
286
|
-
kickStrength: clampOption(clickOptions.kickStrength, DOT_GRID_DEFAULTS.click.kickStrength, Number.NEGATIVE_INFINITY),
|
|
287
|
-
kickRadius: clampOption(clickOptions.kickRadius, DOT_GRID_DEFAULTS.click.kickRadius, 0),
|
|
288
|
-
kickRandomness: clampOption(clickOptions.kickRandomness, DOT_GRID_DEFAULTS.click.kickRandomness, 0, 1),
|
|
289
|
-
}
|
|
290
|
-
: null,
|
|
291
|
-
rest: restOptions
|
|
292
|
-
? {
|
|
293
|
-
...resolveDotEffectOptions(restOptions, { ...DOT_GRID_DEFAULTS.rest, shape, opacity }),
|
|
294
|
-
interval: restInterval,
|
|
295
|
-
duration: clampOption(restOptions.duration, DOT_GRID_DEFAULTS.rest.duration, 1, restInterval),
|
|
296
|
-
origin: restOptions.origin === 'random' ? 'random' : DOT_GRID_DEFAULTS.rest.origin,
|
|
165
|
+
scale: clampOption(pulseOptions.scale, DOT_GRID_DEFAULTS.pulse.scale, 0),
|
|
166
|
+
opacity: clampOption(pulseOptions.opacity, opacity, 0, 1),
|
|
167
|
+
shape: pulseOptions.shape && DOT_SHAPES.includes(pulseOptions.shape) ? pulseOptions.shape : shape,
|
|
297
168
|
}
|
|
298
169
|
: null,
|
|
299
170
|
};
|
|
@@ -309,16 +180,13 @@ export function isDotGridInteractive(options: ResolvedDotGridOptions) {
|
|
|
309
180
|
/** Corner radius of a rounded square as a fraction of its half-size. */
|
|
310
181
|
export const DOT_ROUNDED_SQUARE_CORNER = 0.5;
|
|
311
182
|
|
|
312
|
-
/** Ring hole radius as a fraction of the dot's outer radius, shared by SVG and WebGL. */
|
|
313
|
-
export const DOT_RING_INNER_RADIUS = 0.6;
|
|
314
|
-
|
|
315
183
|
/*
|
|
316
184
|
* Dot diameter in CSS pixels at which a square grid leaves no pixel uncovered, plus a little
|
|
317
185
|
* for the anti-aliased rim. A circle must reach the cell corners, √2 × spacing away; a rounded
|
|
318
186
|
* square only needs to span the cell plus what its rounded corners cut away.
|
|
319
187
|
*/
|
|
320
188
|
export function getDotGridCoverSize(spacing: number, shape: DotShape) {
|
|
321
|
-
if (shape === 'rounded_square'
|
|
189
|
+
if (shape === 'rounded_square') {
|
|
322
190
|
// Half-size h covers the corner (spacing/2, spacing/2) when (spacing/2 - h + c)·√2 ≤ c, c = corner·h.
|
|
323
191
|
const corner = DOT_ROUNDED_SQUARE_CORNER;
|
|
324
192
|
return spacing / (1 - corner * (1 - Math.SQRT1_2)) + 1;
|
|
@@ -326,144 +194,18 @@ export function getDotGridCoverSize(spacing: number, shape: DotShape) {
|
|
|
326
194
|
return spacing * Math.SQRT2 + 1;
|
|
327
195
|
}
|
|
328
196
|
|
|
329
|
-
/*
|
|
330
|
-
* Whether an anchor is measured from the axis's end edge (`right` / `bottom`, as a keyword or
|
|
331
|
-
* an `{ edge: px }` offset).
|
|
332
|
-
*/
|
|
333
|
-
function isEndAlign(align: DotAlign): boolean {
|
|
334
|
-
return align === 'right' || align === 'bottom' || getAlignOffset(align, ['right', 'bottom']) !== null;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/*
|
|
338
|
-
* The coordinate along one axis (CSS pixels from the area's start edge) of a dot center the
|
|
339
|
-
* grid passes through, for an area `extent` long: the middle for `center`; one `size` before
|
|
340
|
-
* the start edge for `left` / `top`, so that dot is hidden and the next one sits about a
|
|
341
|
-
* spacing in; half a `size` before the end edge for `right` / `bottom`, so that dot sits flush
|
|
342
|
-
* against it; a number (or `{ left }` / `{ top }`) as it is; `{ right }` / `{ bottom }` that
|
|
343
|
-
* many pixels before the end edge. The other dots follow at `spacing` steps either way.
|
|
344
|
-
*/
|
|
345
|
-
export function getDotGridAnchor(align: DotAlign, size: number, extent: number) {
|
|
346
|
-
if (typeof align === 'number') return align;
|
|
347
|
-
const offset = getAlignOffset(align, ['left', 'top', 'right', 'bottom']);
|
|
348
|
-
if (offset) return isEndAlign(align) ? extent - offset.offset : offset.offset;
|
|
349
|
-
if (align === 'left' || align === 'top') return -size;
|
|
350
|
-
if (align === 'right' || align === 'bottom') return extent - size / 2;
|
|
351
|
-
return extent / 2;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/*
|
|
355
|
-
* The dot center nearest to `coordinate` along one axis, on the grid `getDotGridAnchor`
|
|
356
|
-
* anchors for an area `extent` long.
|
|
357
|
-
*/
|
|
358
|
-
export function getNearestDotGridCenter(coordinate: number, align: DotAlign, size: number, spacing: number, extent: number) {
|
|
359
|
-
const anchor = getDotGridAnchor(align, size, extent);
|
|
360
|
-
return anchor + Math.round((coordinate - anchor) / spacing) * spacing;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/*
|
|
364
|
-
* The CSS `mask-position` (or `background-position`) that lays `makeDotGridTileUrl`'s tile,
|
|
365
|
-
* repeated at `spacing × spacing`, on the same dots as `getDotGridAnchor` would for either
|
|
366
|
-
* axis, without knowing the area's size: the tile's dot is centered, so `center` is exact, a
|
|
367
|
-
* start-edge or pixel anchor puts the first tile half a spacing before the anchor, and an
|
|
368
|
-
* end-edge anchor moves the last tile past the end edge by half a spacing less its anchor's
|
|
369
|
-
* distance from that edge (half a dot for the keyword, the given pixels for `{ right }` /
|
|
370
|
-
* `{ bottom }`).
|
|
371
|
-
*/
|
|
372
|
-
export function getDotGridMaskPosition({ size, spacing, alignX, alignY }: Required<DotStyle>) {
|
|
373
|
-
const axis = (align: DotAlign) => {
|
|
374
|
-
if (align === 'center') return 'center';
|
|
375
|
-
// A tile position of 100% puts the last tile's end on the end edge, so its dot center
|
|
376
|
-
// sits half a spacing before it; the anchor (negative, relative to the edge) is the rest.
|
|
377
|
-
if (isEndAlign(align)) return `calc(100% + ${spacing / 2 + getDotGridAnchor(align, size, 0)}px)`;
|
|
378
|
-
return `${getDotGridAnchor(align, size, 0) - spacing / 2}px`;
|
|
379
|
-
};
|
|
380
|
-
return `${axis(alignX)} ${axis(alignY)}`;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
197
|
/*
|
|
384
198
|
* One tile of the grid as an SVG data URL, for `mask-image` or `background-image`. Repeat
|
|
385
|
-
* it at `spacing × spacing`
|
|
386
|
-
*
|
|
199
|
+
* it at `spacing × spacing` with `center` positioning and it lines up exactly with the WebGL
|
|
200
|
+
* grid, which also centers a dot on the canvas.
|
|
387
201
|
*/
|
|
388
202
|
export function makeDotGridTileUrl({ size, shape, spacing }: Pick<Required<DotStyle>, 'size' | 'shape' | 'spacing'>) {
|
|
389
203
|
const half = spacing / 2;
|
|
390
204
|
const r = size / 2;
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const outline = shape === 'ring_rectangle' ? ` fill="none" stroke="black" stroke-width="${stroke}"` : '';
|
|
396
|
-
dot = `<rect x="${half - r + inset}" y="${half - r + inset}" width="${size - inset * 2}" height="${size - inset * 2}" rx="${r * DOT_ROUNDED_SQUARE_CORNER - inset}"${outline}/>`;
|
|
397
|
-
} else if (shape === 'ring') {
|
|
398
|
-
dot = `<circle cx="${half}" cy="${half}" r="${r - stroke / 2}" fill="none" stroke="black" stroke-width="${stroke}"/>`;
|
|
399
|
-
} else {
|
|
400
|
-
dot = `<circle cx="${half}" cy="${half}" r="${r}"/>`;
|
|
401
|
-
}
|
|
205
|
+
const dot =
|
|
206
|
+
shape === 'rounded_square'
|
|
207
|
+
? `<rect x="${half - r}" y="${half - r}" width="${size}" height="${size}" rx="${r * DOT_ROUNDED_SQUARE_CORNER}"/>`
|
|
208
|
+
: `<circle cx="${half}" cy="${half}" r="${r}"/>`;
|
|
402
209
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${spacing} ${spacing}">${dot}</svg>`;
|
|
403
210
|
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
404
211
|
}
|
|
405
|
-
|
|
406
|
-
/*
|
|
407
|
-
* A mask that fades an element to transparent over the bottom `fadeBottom` pixels, for a
|
|
408
|
-
* static stand-in that must match the canvas's bottom fade. To fade to a color instead, give
|
|
409
|
-
* the element's parent that color as its background.
|
|
410
|
-
*/
|
|
411
|
-
export function getBottomFadeMaskStyle(fadeBottom: number): CSSProperties | undefined {
|
|
412
|
-
if (fadeBottom <= 0) return undefined;
|
|
413
|
-
return { maskImage: `linear-gradient(to bottom, #000 calc(100% - ${fadeBottom}px), transparent)` };
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/*
|
|
417
|
-
* CSS that draws a resting dot grid with no WebGL: the element's background masked by the
|
|
418
|
-
* grid's SVG tile, repeated at the dot spacing and anchored per `alignX` / `alignY` so it lines
|
|
419
|
-
* up with the canvas grid. `fadeBottom` fades the dots over that many pixels along the bottom
|
|
420
|
-
* edge: to transparent through a second mask layer, or to `fadeColor` through a background
|
|
421
|
-
* gradient over the element's own background (which an image placeholder covers, so that one
|
|
422
|
-
* only fades to transparent). Set the color as the element's background separately, since an
|
|
423
|
-
* image may be what shows through the mask.
|
|
424
|
-
*/
|
|
425
|
-
export function getDotGridMaskStyle(dots: Required<DotStyle>, fadeBottom = 0, fadeColor: string | null = null): CSSProperties {
|
|
426
|
-
const position = getDotGridMaskPosition(dots);
|
|
427
|
-
if (fadeBottom > 0 && fadeColor) {
|
|
428
|
-
return {
|
|
429
|
-
opacity: dots.opacity,
|
|
430
|
-
backgroundImage: `linear-gradient(to bottom, transparent calc(100% - ${fadeBottom}px), ${fadeColor})`,
|
|
431
|
-
maskImage: `url("${makeDotGridTileUrl(dots)}")`,
|
|
432
|
-
maskRepeat: 'repeat',
|
|
433
|
-
maskSize: `${dots.spacing}px ${dots.spacing}px`,
|
|
434
|
-
maskPosition: position,
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
const fadeMask = fadeBottom > 0 ? `, linear-gradient(to bottom, #000 calc(100% - ${fadeBottom}px), transparent)` : '';
|
|
438
|
-
return {
|
|
439
|
-
opacity: dots.opacity,
|
|
440
|
-
maskImage: `url("${makeDotGridTileUrl(dots)}")${fadeMask}`,
|
|
441
|
-
maskRepeat: fadeMask ? 'repeat, no-repeat' : 'repeat',
|
|
442
|
-
maskSize: `${dots.spacing}px ${dots.spacing}px${fadeMask ? ', 100% 100%' : ''}`,
|
|
443
|
-
maskPosition: fadeMask ? `${position}, center` : position,
|
|
444
|
-
maskComposite: fadeMask ? 'intersect' : undefined,
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/*
|
|
449
|
-
* The same grid for a layer whose top-left corner rests `offset` pixels into an area
|
|
450
|
-
* `width` × `height` (a `<DotsBoard.Sticky>` inside its board): the area's anchor dot, taken
|
|
451
|
-
* into the layer's pixels, positions the tile so the layer's dots fall exactly on the area's.
|
|
452
|
-
* Numeric, so it needs the area measured; until then it is `getDotGridMaskStyle`, which can be
|
|
453
|
-
* off by up to half a spacing.
|
|
454
|
-
*/
|
|
455
|
-
export function getDotGridLayerMaskStyle(
|
|
456
|
-
dots: Required<DotStyle>,
|
|
457
|
-
offset: { left: number; top: number },
|
|
458
|
-
width: number,
|
|
459
|
-
height: number,
|
|
460
|
-
): CSSProperties {
|
|
461
|
-
if (!width || !height) return getDotGridMaskStyle(dots);
|
|
462
|
-
const { size, spacing, alignX, alignY } = dots;
|
|
463
|
-
// The tile's dot is at its center, so the tile starts half a spacing before any dot center;
|
|
464
|
-
// wrapped into the first tile so the position stays small.
|
|
465
|
-
const tileStart = (anchor: number) => ((((anchor - spacing / 2) % spacing) + spacing) % spacing) - spacing;
|
|
466
|
-
const x = tileStart(getDotGridAnchor(alignX, size, width) - offset.left);
|
|
467
|
-
const y = tileStart(getDotGridAnchor(alignY, size, height) - offset.top);
|
|
468
|
-
return { ...getDotGridMaskStyle(dots), maskPosition: `${x}px ${y}px` };
|
|
469
|
-
}
|