@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/elements/Shapes.tsx
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
-
import { memo, useId, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import type { CSSProperties, ReactNode } from 'react';
|
|
4
|
-
import { useInView } from '../modules/ScrollSteps.hooks.ts';
|
|
5
|
-
import { shiftHex } from '../utils/color.ts';
|
|
6
|
-
import { createRandom } from '../utils/random.ts';
|
|
7
|
-
import { brushPath, brushRows, brushWidth, pixelateCells, pixelateTile, shapeOutline } from './Shapes.helpers.ts';
|
|
8
|
-
import { SHAPE_STATES, usePulseHalos, useRevealed, useShapeState } from './Shapes.hooks.ts';
|
|
9
|
-
import type { ShapeEffect, ShapeProps } from './Shapes.types.ts';
|
|
10
|
-
|
|
11
|
-
export type { ShapeEffect, ShapeIcon, ShapeKind, ShapeLineStyle, ShapeProps, ShapeState } from './Shapes.types.ts';
|
|
12
|
-
|
|
13
|
-
const SHAPE = {
|
|
14
|
-
/** Brush passes across a square shape box; more rows = thinner, more visible strokes. */
|
|
15
|
-
brushRows: 5,
|
|
16
|
-
/** Cells per side of the repeating pixelate tile, and how far (0..1 of full white or black) a cell may shade from the paint. */
|
|
17
|
-
pixelTile: 8,
|
|
18
|
-
pixelShade: 0.14,
|
|
19
|
-
/** Hatch streaks: about how many rows of them span the shape's height, how many times longer than tall they run, and the noise threshold they are cut at from intensity 0 to 1 (lower cuts more). */
|
|
20
|
-
hatchRows: 28,
|
|
21
|
-
hatchStretch: 40,
|
|
22
|
-
hatchThreshold: [0.72, 0.5],
|
|
23
|
-
/** Sweep timing in seconds and its easing. */
|
|
24
|
-
paintDuration: 1.3,
|
|
25
|
-
easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
|
26
|
-
defaultEffect: { name: 'grain', intensity: 0.6 } as ShapeEffect,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
* A painted illustration shape in two layers, each laid down as one hand-swept brush stroke
|
|
31
|
-
* with a texture `effect` (film grain, a pixelate mosaic of cells a shade lighter or darker
|
|
32
|
-
* than the paint, which sweeps in with it, or the ragged streaks of a woodcut print): a flat
|
|
33
|
-
* `baseColor` base, and over it the active `color` as a gradient (or flat; always flat under a
|
|
34
|
-
* mosaic). The shape is a built-in one or a custom icon path. `state` says which layers show:
|
|
35
|
-
* `empty`, `base`, or `active`. A state change sweeps one layer in (or out again, going the
|
|
36
|
-
* other way); a change that skips a state, or arrives mid-sweep, waits for the running sweep
|
|
37
|
-
* and then takes the next step, so a shape sent from empty to active always finishes painting
|
|
38
|
-
* its base before the active layer starts. The edge is `rounded`, `straight`, or a hand-drawn
|
|
39
|
-
* `sketch` wobble, and the shape is drawn inside `size` × `height` (square unless `height` is
|
|
40
|
-
* given) with a `padding` margin (10% a side by default) so the wobble, brush overspill and
|
|
41
|
-
* filters are not clipped; `padding: 0` makes those the painted size. With `reveal` the shape
|
|
42
|
-
* starts empty and paints up to `state` on mount, or once it has scrolled into view (and
|
|
43
|
-
* stays painted from then on). Every wobble comes from `seed`, so the same props always give
|
|
44
|
-
* the same picture, on the server too.
|
|
45
|
-
*/
|
|
46
|
-
export const Shape = memo((p: ShapeProps) => {
|
|
47
|
-
const {
|
|
48
|
-
shape,
|
|
49
|
-
state,
|
|
50
|
-
baseColor,
|
|
51
|
-
color,
|
|
52
|
-
size = 160,
|
|
53
|
-
height = size,
|
|
54
|
-
padding = 0.1,
|
|
55
|
-
line = 'rounded',
|
|
56
|
-
effect = SHAPE.defaultEffect,
|
|
57
|
-
gradient = true,
|
|
58
|
-
animate = true,
|
|
59
|
-
reveal,
|
|
60
|
-
delay = 0,
|
|
61
|
-
revealDelay = 0,
|
|
62
|
-
seed = 1,
|
|
63
|
-
className,
|
|
64
|
-
stateClassName,
|
|
65
|
-
style,
|
|
66
|
-
} = p;
|
|
67
|
-
const id = useId().replace(/[^a-zA-Z0-9]/g, '');
|
|
68
|
-
const ids = { gradient: `${id}g`, grain: `${id}n`, hatch: `${id}h`, pixel: `${id}p`, rough: `${id}r`, clip: `${id}c` };
|
|
69
|
-
const intensity = effect ? Math.min(1, Math.max(0, effect.intensity)) : 0;
|
|
70
|
-
const grain = effect?.name === 'grain' ? intensity : 0;
|
|
71
|
-
const hatch = effect?.name === 'hatch' ? intensity : 0;
|
|
72
|
-
const pixelate = effect?.name === 'pixelate';
|
|
73
|
-
const sketch = line === 'sketch';
|
|
74
|
-
// A custom icon is keyed by its data, so a fresh object with the same path recomputes nothing.
|
|
75
|
-
const kindKey = typeof shape === 'string' ? shape : `${shape.viewBox ?? 24}|${shape.d}`;
|
|
76
|
-
|
|
77
|
-
// The box the shape is painted in, inset by the padding, and the brush passes it takes.
|
|
78
|
-
const inset = 0.5 - Math.min(0.45, Math.max(0, padding));
|
|
79
|
-
const box = { cx: size / 2, cy: height / 2, rx: size * inset, ry: height * inset };
|
|
80
|
-
const rows = brushRows(box, SHAPE.brushRows);
|
|
81
|
-
// Geometry is seeded, so it only changes when the props that shape it change.
|
|
82
|
-
const geometry = useMemo(() => {
|
|
83
|
-
const random = createRandom(seed);
|
|
84
|
-
return {
|
|
85
|
-
outline: shapeOutline(shape, line, box, random),
|
|
86
|
-
brush: brushPath(box, rows, random),
|
|
87
|
-
pixels: pixelateTile(SHAPE.pixelTile, SHAPE.pixelTile, random),
|
|
88
|
-
};
|
|
89
|
-
}, [kindKey, line, box.cx, box.cy, box.rx, box.ry, rows, seed]);
|
|
90
|
-
// The mosaic: `cell` px squares, in a tile that repeats over the shape.
|
|
91
|
-
const cell = size / pixelateCells(intensity);
|
|
92
|
-
const tile = cell * SHAPE.pixelTile;
|
|
93
|
-
// The streaks' noise: rows of streaks over the height, stretched sideways, cut at a threshold set by the intensity.
|
|
94
|
-
const hatchFrequency = `${SHAPE.hatchRows / height / SHAPE.hatchStretch} ${SHAPE.hatchRows / height}`;
|
|
95
|
-
const hatchCut = SHAPE.hatchThreshold[0] + (SHAPE.hatchThreshold[1] - SHAPE.hatchThreshold[0]) * hatch;
|
|
96
|
-
// Which texture filter the paint goes through, if any.
|
|
97
|
-
const paintFilter = grain > 0 ? ids.grain : hatch > 0 ? ids.hatch : null;
|
|
98
|
-
// Shades are derived only from a hex `color`; any other CSS color (a `var()`, `rgb()`) is used as is.
|
|
99
|
-
const hex = /^#[0-9a-f]{3,8}$/i.test(color);
|
|
100
|
-
const stops = gradient && hex && !pixelate ? [shiftHex(color, -0.12), shiftHex(color, 0.22, -8)] : [color, color];
|
|
101
|
-
|
|
102
|
-
const ref = useRef<SVGSVGElement>(null);
|
|
103
|
-
// Until a `view` reveal has seen the shape (plus `revealDelay`), it is painted toward `empty`; then toward `state`.
|
|
104
|
-
const seen = useInView(ref, { once: true, disabled: reveal !== 'view' }) || reveal !== 'view';
|
|
105
|
-
const revealed = useRevealed(seen, reveal === 'view' ? revealDelay * 1000 : 0);
|
|
106
|
-
const { shown, animating } = useShapeState(revealed ? state : 'empty', (delay + SHAPE.paintDuration) * 1000, animate, !!reveal, ref);
|
|
107
|
-
const baseDrawn = SHAPE_STATES.indexOf(shown) >= 1;
|
|
108
|
-
const activeDrawn = shown === 'active';
|
|
109
|
-
const stateClass = animating && stateClassName?.animating !== undefined ? stateClassName.animating : stateClassName?.[shown];
|
|
110
|
-
|
|
111
|
-
/*
|
|
112
|
-
* A mosaic pattern to paint a layer with: the layer's color under the shaded cells, so the
|
|
113
|
-
* pixels are part of the paint and sweep in with it.
|
|
114
|
-
*/
|
|
115
|
-
const mosaic = (key: string, fill: string) => (
|
|
116
|
-
<pattern
|
|
117
|
-
id={ids.pixel + key}
|
|
118
|
-
patternUnits="userSpaceOnUse"
|
|
119
|
-
width={tile}
|
|
120
|
-
height={tile}
|
|
121
|
-
>
|
|
122
|
-
<rect
|
|
123
|
-
width={tile}
|
|
124
|
-
height={tile}
|
|
125
|
-
style={{ fill }}
|
|
126
|
-
/>
|
|
127
|
-
{geometry.pixels.map(({ col, row, shade }) => (
|
|
128
|
-
<rect
|
|
129
|
-
key={`${col}-${row}`}
|
|
130
|
-
x={col * cell}
|
|
131
|
-
y={row * cell}
|
|
132
|
-
width={cell}
|
|
133
|
-
height={cell}
|
|
134
|
-
fill={shade < 0 ? '#000' : '#fff'}
|
|
135
|
-
opacity={Math.abs(shade) * SHAPE.pixelShade}
|
|
136
|
-
/>
|
|
137
|
-
))}
|
|
138
|
-
</pattern>
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
/*
|
|
142
|
-
* One layer: the brush stroke clipped to the shape, drawn in (or out) by its dash offset,
|
|
143
|
-
* which transitions between hidden (1) and drawn (0). A hidden layer is also made
|
|
144
|
-
* invisible once its sweep is over, because the round cap of the dash boundary sitting on
|
|
145
|
-
* the path's start would otherwise still paint a blob of the color at that corner; it is
|
|
146
|
-
* made visible again the instant it starts sweeping in. In sketch style the clipped edge
|
|
147
|
-
* is roughened after clipping, so it reads as paint rather than a vector cut.
|
|
148
|
-
*/
|
|
149
|
-
const layer = (drawn: boolean, key: string, stroke: string) => (
|
|
150
|
-
<g filter={sketch ? `url(#${ids.rough})` : undefined}>
|
|
151
|
-
<g clipPath={`url(#${ids.clip})`}>
|
|
152
|
-
<path
|
|
153
|
-
d={geometry.brush}
|
|
154
|
-
fill="none"
|
|
155
|
-
strokeWidth={brushWidth(box, rows)}
|
|
156
|
-
strokeLinecap="round"
|
|
157
|
-
strokeLinejoin="round"
|
|
158
|
-
pathLength={1}
|
|
159
|
-
strokeDasharray="1 1"
|
|
160
|
-
// As style, not presentation attributes, so a `var()` color resolves and the offset transitions.
|
|
161
|
-
style={
|
|
162
|
-
{
|
|
163
|
-
stroke: pixelate ? `url(#${ids.pixel}${key})` : stroke,
|
|
164
|
-
strokeDashoffset: drawn ? 0 : 1,
|
|
165
|
-
visibility: drawn ? 'visible' : 'hidden',
|
|
166
|
-
transition: animate
|
|
167
|
-
? `stroke-dashoffset ${SHAPE.paintDuration}s ${SHAPE.easing} ${delay}s, visibility 0s linear ${drawn ? 0 : delay + SHAPE.paintDuration}s`
|
|
168
|
-
: 'none',
|
|
169
|
-
} as CSSProperties
|
|
170
|
-
}
|
|
171
|
-
filter={paintFilter ? `url(#${paintFilter})` : undefined}
|
|
172
|
-
/>
|
|
173
|
-
</g>
|
|
174
|
-
</g>
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
return (
|
|
178
|
-
<svg
|
|
179
|
-
ref={ref}
|
|
180
|
-
viewBox={`0 0 ${size} ${height}`}
|
|
181
|
-
width={size}
|
|
182
|
-
height={height}
|
|
183
|
-
className={cn(className, stateClass)}
|
|
184
|
-
style={style}
|
|
185
|
-
aria-hidden="true"
|
|
186
|
-
>
|
|
187
|
-
<defs>
|
|
188
|
-
<linearGradient
|
|
189
|
-
id={ids.gradient}
|
|
190
|
-
x1="0"
|
|
191
|
-
y1="1"
|
|
192
|
-
x2="1"
|
|
193
|
-
y2="0"
|
|
194
|
-
>
|
|
195
|
-
{/* Colors go in `style`, not presentation attributes, so a `var()` color resolves. */}
|
|
196
|
-
<stop
|
|
197
|
-
offset="0"
|
|
198
|
-
style={{ stopColor: stops[0] }}
|
|
199
|
-
/>
|
|
200
|
-
<stop
|
|
201
|
-
offset="1"
|
|
202
|
-
style={{ stopColor: stops[1] }}
|
|
203
|
-
/>
|
|
204
|
-
</linearGradient>
|
|
205
|
-
{pixelate && mosaic('b', baseColor)}
|
|
206
|
-
{pixelate && mosaic('a', color)}
|
|
207
|
-
{grain > 0 && (
|
|
208
|
-
<filter
|
|
209
|
-
id={ids.grain}
|
|
210
|
-
x="-20%"
|
|
211
|
-
y="-20%"
|
|
212
|
-
width="140%"
|
|
213
|
-
height="140%"
|
|
214
|
-
>
|
|
215
|
-
<feTurbulence
|
|
216
|
-
type="fractalNoise"
|
|
217
|
-
baseFrequency="1.1"
|
|
218
|
-
numOctaves="3"
|
|
219
|
-
seed={seed}
|
|
220
|
-
result="noise"
|
|
221
|
-
/>
|
|
222
|
-
{/* Threshold the noise into a speckle alpha; the intercept sets how much of the paint the speckle covers. */}
|
|
223
|
-
<feColorMatrix
|
|
224
|
-
in="noise"
|
|
225
|
-
type="matrix"
|
|
226
|
-
values={`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.6 ${0.4 + 0.85 * grain}`}
|
|
227
|
-
result="speckle"
|
|
228
|
-
/>
|
|
229
|
-
<feComposite
|
|
230
|
-
in="speckle"
|
|
231
|
-
in2="SourceGraphic"
|
|
232
|
-
operator="in"
|
|
233
|
-
result="speckleInShape"
|
|
234
|
-
/>
|
|
235
|
-
<feBlend
|
|
236
|
-
in="SourceGraphic"
|
|
237
|
-
in2="speckleInShape"
|
|
238
|
-
mode="multiply"
|
|
239
|
-
/>
|
|
240
|
-
</filter>
|
|
241
|
-
)}
|
|
242
|
-
{hatch > 0 && (
|
|
243
|
-
<filter
|
|
244
|
-
id={ids.hatch}
|
|
245
|
-
x="-10%"
|
|
246
|
-
y="-10%"
|
|
247
|
-
width="120%"
|
|
248
|
-
height="120%"
|
|
249
|
-
>
|
|
250
|
-
{/* Noise stretched sideways into streaks, thresholded into a mask that is cut out of the paint, leaving bare paper. */}
|
|
251
|
-
<feTurbulence
|
|
252
|
-
type="fractalNoise"
|
|
253
|
-
baseFrequency={hatchFrequency}
|
|
254
|
-
numOctaves="2"
|
|
255
|
-
seed={seed + 1}
|
|
256
|
-
result="streaks"
|
|
257
|
-
/>
|
|
258
|
-
<feColorMatrix
|
|
259
|
-
in="streaks"
|
|
260
|
-
type="matrix"
|
|
261
|
-
values={`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 ${-14 * hatchCut}`}
|
|
262
|
-
result="cut"
|
|
263
|
-
/>
|
|
264
|
-
<feComposite
|
|
265
|
-
in="SourceGraphic"
|
|
266
|
-
in2="cut"
|
|
267
|
-
operator="out"
|
|
268
|
-
/>
|
|
269
|
-
</filter>
|
|
270
|
-
)}
|
|
271
|
-
{sketch && (
|
|
272
|
-
<filter
|
|
273
|
-
id={ids.rough}
|
|
274
|
-
x="-10%"
|
|
275
|
-
y="-10%"
|
|
276
|
-
width="120%"
|
|
277
|
-
height="120%"
|
|
278
|
-
>
|
|
279
|
-
<feTurbulence
|
|
280
|
-
type="fractalNoise"
|
|
281
|
-
baseFrequency="0.04 0.09"
|
|
282
|
-
numOctaves="3"
|
|
283
|
-
seed={seed + 2}
|
|
284
|
-
result="warp"
|
|
285
|
-
/>
|
|
286
|
-
<feDisplacementMap
|
|
287
|
-
in="SourceGraphic"
|
|
288
|
-
in2="warp"
|
|
289
|
-
scale={Math.min(size, height) * 0.05}
|
|
290
|
-
xChannelSelector="R"
|
|
291
|
-
yChannelSelector="G"
|
|
292
|
-
/>
|
|
293
|
-
</filter>
|
|
294
|
-
)}
|
|
295
|
-
<clipPath id={ids.clip}>
|
|
296
|
-
<path
|
|
297
|
-
d={geometry.outline.d}
|
|
298
|
-
transform={geometry.outline.transform}
|
|
299
|
-
/>
|
|
300
|
-
</clipPath>
|
|
301
|
-
</defs>
|
|
302
|
-
|
|
303
|
-
{/* The base layer, flat; then the active layer over it. */}
|
|
304
|
-
{layer(baseDrawn, 'b', baseColor)}
|
|
305
|
-
{layer(activeDrawn, 'a', `url(#${ids.gradient})`)}
|
|
306
|
-
</svg>
|
|
307
|
-
);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Markers
|
|
312
|
-
*/
|
|
313
|
-
|
|
314
|
-
/** A bold check mark, drawn in a `MARKER_CHECK_BOX` square. */
|
|
315
|
-
const MARKER_CHECK_BOX = 24;
|
|
316
|
-
const MARKER_CHECK_PATH =
|
|
317
|
-
'M23.48925781,2.43798828c-.09765625-.60839844-.42675781-1.14160156-.91210938-1.49072266l-.02246094-.01757812c-1.03027344-.74755859-2.47363281-.52050781-3.23046875.52001953L7.71386719,17.64550781l-3.30224609-3.30175781c-.93457031-.87109375-2.40185547-.81933594-3.27050781.11621094-.82470703.88476562-.82470703,2.27050781.02392578,3.1796875l5.21386719,5.22265625c.453125.43164062,1.03466797.64550781,1.61523438.64550781.61767578,0,1.23388672-.2421875,1.69091797-.72167969.06640625-.06933594.12841797-.14257812.19433594-.23144531L23.08300781,4.15527344c.36035156-.49951172.50488281-1.109375.40625-1.71728516Z';
|
|
318
|
-
|
|
319
|
-
/*
|
|
320
|
-
* A marker for a point, such as the pin a `<DotsBoard.Item>` puts on its dot: by default a
|
|
321
|
-
* small disc, or, as a `check`, a check mark `size` px square, either in `color` on a halo
|
|
322
|
-
* `haloWidth` px bigger all round, translucent by default so what is under it shows through.
|
|
323
|
-
* The halo is drawn outside the marker's box, so it centers on the point by its `size`.
|
|
324
|
-
*/
|
|
325
|
-
export const Marker = memo(
|
|
326
|
-
(p: {
|
|
327
|
-
shape?: 'dot' | 'check';
|
|
328
|
-
size?: number;
|
|
329
|
-
color?: string;
|
|
330
|
-
haloColor?: string;
|
|
331
|
-
haloWidth?: number;
|
|
332
|
-
className?: string;
|
|
333
|
-
style?: CSSProperties;
|
|
334
|
-
}) => {
|
|
335
|
-
const {
|
|
336
|
-
shape = 'dot',
|
|
337
|
-
size = shape === 'check' ? 14 : 8,
|
|
338
|
-
color = 'rgba(0, 0, 0, 0.4)',
|
|
339
|
-
haloColor = 'rgba(0, 0, 0, 0.1)',
|
|
340
|
-
haloWidth = 2,
|
|
341
|
-
className,
|
|
342
|
-
style,
|
|
343
|
-
} = p;
|
|
344
|
-
|
|
345
|
-
if (shape === 'check') {
|
|
346
|
-
// The halo is the same path stroked underneath: a stroke straddles the edge, so twice the halo's width, in the box's units.
|
|
347
|
-
const haloStroke = (2 * haloWidth * MARKER_CHECK_BOX) / size;
|
|
348
|
-
return (
|
|
349
|
-
<svg
|
|
350
|
-
className={cn('bl', className)}
|
|
351
|
-
width={size}
|
|
352
|
-
height={size}
|
|
353
|
-
viewBox={`0 0 ${MARKER_CHECK_BOX} ${MARKER_CHECK_BOX}`}
|
|
354
|
-
style={{ overflow: 'visible', ...style }}
|
|
355
|
-
aria-hidden="true"
|
|
356
|
-
>
|
|
357
|
-
{haloWidth > 0 && (
|
|
358
|
-
<path
|
|
359
|
-
d={MARKER_CHECK_PATH}
|
|
360
|
-
fill="none"
|
|
361
|
-
stroke={haloColor}
|
|
362
|
-
strokeWidth={haloStroke}
|
|
363
|
-
strokeLinejoin="round"
|
|
364
|
-
/>
|
|
365
|
-
)}
|
|
366
|
-
<path
|
|
367
|
-
d={MARKER_CHECK_PATH}
|
|
368
|
-
fill={color}
|
|
369
|
-
/>
|
|
370
|
-
</svg>
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return (
|
|
375
|
-
<span
|
|
376
|
-
className={cn('bl', className)}
|
|
377
|
-
style={{
|
|
378
|
-
width: size,
|
|
379
|
-
height: size,
|
|
380
|
-
borderRadius: '50%',
|
|
381
|
-
backgroundColor: color,
|
|
382
|
-
boxShadow: haloWidth > 0 ? `0 0 0 ${haloWidth}px ${haloColor}` : undefined,
|
|
383
|
-
...style,
|
|
384
|
-
}}
|
|
385
|
-
/>
|
|
386
|
-
);
|
|
387
|
-
},
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
/** How many pulses are growing at once, each a `duration / halos` behind the last, the ease they grow (and fade) with, and how the dot and its own halo turn to the hover color and back. */
|
|
391
|
-
const MARKER_PULSE = {
|
|
392
|
-
halos: 2,
|
|
393
|
-
easing: 'cubic-bezier(0.2, 0.6, 0.4, 1)',
|
|
394
|
-
colorTransition: 'background-color 0.4s ease-out, box-shadow 0.4s ease-out',
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
/*
|
|
398
|
-
* A `<Marker>` dot that pulses: a flat halo in `pulseColor` grows out from under it to
|
|
399
|
-
* `pulseSize` px across (64 by default), fading out as it grows, while the next halo starts
|
|
400
|
-
* growing behind it, one after another every `duration / 2` seconds for as long as it is
|
|
401
|
-
* mounted. Like the dot's own halo, the pulses are drawn outside its box, so it centers on the
|
|
402
|
-
* point by its `size`. They run as Web Animations, so no stylesheet is needed; before
|
|
403
|
-
* hydration, without the API, or with reduced motion, only the dot shows. When `hoverable`
|
|
404
|
-
* (or given `hoverContent`), a pointer over the pulse stops it: no new halo starts and the ones
|
|
405
|
-
* under way finish their cycle, while the dot and its own halo turn `hoverColor` at once, one
|
|
406
|
-
* color, until the pointer leaves and the pulse carries on (the dot turning back). Meanwhile
|
|
407
|
-
* `hoverContent` shows centered above the pulse, and keeps it stopped while the pointer is over
|
|
408
|
-
* it too.
|
|
409
|
-
*/
|
|
410
|
-
export const PulsingMarker = memo(
|
|
411
|
-
(p: {
|
|
412
|
-
size?: number;
|
|
413
|
-
color?: string;
|
|
414
|
-
haloColor?: string;
|
|
415
|
-
haloWidth?: number;
|
|
416
|
-
pulseColor?: string;
|
|
417
|
-
pulseSize?: number;
|
|
418
|
-
/** Seconds one halo takes to grow to `pulseSize` and fade out. */
|
|
419
|
-
duration?: number;
|
|
420
|
-
/** Hold the pulse at full size while the pointer is over it. On whenever `hoverContent` is given. */
|
|
421
|
-
hoverable?: boolean;
|
|
422
|
-
/** Shown centered above the pulse while the pointer is over it. */
|
|
423
|
-
hoverContent?: ReactNode;
|
|
424
|
-
/** The one color the dot and its own halo turn while the pointer is over the pulse. */
|
|
425
|
-
hoverColor?: string;
|
|
426
|
-
className?: string;
|
|
427
|
-
}) => {
|
|
428
|
-
const {
|
|
429
|
-
size = 8,
|
|
430
|
-
color,
|
|
431
|
-
haloColor,
|
|
432
|
-
haloWidth,
|
|
433
|
-
pulseColor = 'rgb(var(--color-marketing))',
|
|
434
|
-
hoverColor = 'rgb(var(--color-marketing-intense))',
|
|
435
|
-
pulseSize = 64,
|
|
436
|
-
duration = 4,
|
|
437
|
-
hoverContent,
|
|
438
|
-
hoverable = hoverContent != null,
|
|
439
|
-
className,
|
|
440
|
-
} = p;
|
|
441
|
-
const halosRef = useRef<(HTMLSpanElement | null)[]>([]);
|
|
442
|
-
const [hovered, setHovered] = useState(false);
|
|
443
|
-
usePulseHalos(halosRef, size, pulseSize, duration * 1000, MARKER_PULSE.easing, hovered);
|
|
444
|
-
// The pulse's full disc, centered on the dot.
|
|
445
|
-
const pulseBox = {
|
|
446
|
-
left: (size - pulseSize) / 2,
|
|
447
|
-
top: (size - pulseSize) / 2,
|
|
448
|
-
width: pulseSize,
|
|
449
|
-
height: pulseSize,
|
|
450
|
-
borderRadius: '50%',
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
return (
|
|
454
|
-
<span
|
|
455
|
-
className={cn('rel bl', className)}
|
|
456
|
-
style={{ width: size, height: size }}
|
|
457
|
-
onPointerEnter={hoverable ? () => setHovered(true) : undefined}
|
|
458
|
-
onPointerLeave={hoverable ? () => setHovered(false) : undefined}
|
|
459
|
-
>
|
|
460
|
-
{/* The hover target: the whole pulse, not just the dot. */}
|
|
461
|
-
{hoverable && (
|
|
462
|
-
<span
|
|
463
|
-
className="abs"
|
|
464
|
-
style={pulseBox}
|
|
465
|
-
/>
|
|
466
|
-
)}
|
|
467
|
-
{/* Hidden until animated; each halo is one flat disc, so its whole color fades at once. */}
|
|
468
|
-
{Array.from({ length: MARKER_PULSE.halos }, (_, i) => (
|
|
469
|
-
<span
|
|
470
|
-
key={i}
|
|
471
|
-
ref={(el) => {
|
|
472
|
-
halosRef.current[i] = el;
|
|
473
|
-
}}
|
|
474
|
-
className="abs noclick"
|
|
475
|
-
style={{ ...pulseBox, backgroundColor: pulseColor, opacity: 0 }}
|
|
476
|
-
/>
|
|
477
|
-
))}
|
|
478
|
-
{/* Positioned, so the dot paints over the halos. */}
|
|
479
|
-
<Marker
|
|
480
|
-
size={size}
|
|
481
|
-
color={hovered ? hoverColor : color}
|
|
482
|
-
haloColor={hovered ? hoverColor : haloColor}
|
|
483
|
-
haloWidth={haloWidth}
|
|
484
|
-
className="rel"
|
|
485
|
-
style={{ transition: MARKER_PULSE.colorTransition }}
|
|
486
|
-
/>
|
|
487
|
-
{/* Right on top of the pulse, so the pointer can move onto it without letting go. */}
|
|
488
|
-
{hovered && hoverContent != null && (
|
|
489
|
-
<span
|
|
490
|
-
className="abs bl"
|
|
491
|
-
style={{
|
|
492
|
-
left: '50%',
|
|
493
|
-
bottom: (size + pulseSize) / 2,
|
|
494
|
-
width: 'max-content',
|
|
495
|
-
lineHeight: 'normal',
|
|
496
|
-
transform: 'translateX(-50%)',
|
|
497
|
-
}}
|
|
498
|
-
>
|
|
499
|
-
{hoverContent}
|
|
500
|
-
</span>
|
|
501
|
-
)}
|
|
502
|
-
</span>
|
|
503
|
-
);
|
|
504
|
-
},
|
|
505
|
-
);
|
package/elements/Shapes.types.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { CSSProperties } from 'react';
|
|
2
|
-
|
|
3
|
-
/** A custom silhouette: a closed SVG path (nonzero fill, so wind holes the other way round) drawn in a square `viewBox` (24 by default), fitted to the largest square in the shape box. */
|
|
4
|
-
export interface ShapeIcon {
|
|
5
|
-
d: string;
|
|
6
|
-
viewBox?: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Built-in shape names, or a custom silhouette. */
|
|
10
|
-
export type ShapeKind = 'square' | 'circle' | 'triangle' | 'blob' | ShapeIcon;
|
|
11
|
-
|
|
12
|
-
/** The outline the paint is clipped to: path data, and the transform that fits a custom icon into the box. */
|
|
13
|
-
export interface ShapeOutline {
|
|
14
|
-
d: string;
|
|
15
|
-
transform?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** How the shape's edge is cut: rounded corners, straight ones, or a hand-drawn wobble. */
|
|
19
|
-
export type ShapeLineStyle = 'rounded' | 'straight' | 'sketch';
|
|
20
|
-
|
|
21
|
-
/** What is painted: nothing, the base layer alone, or the active layer over the base. */
|
|
22
|
-
export type ShapeState = 'empty' | 'base' | 'active';
|
|
23
|
-
|
|
24
|
-
/** A texture on the paint. `intensity` runs 0..1: for `grain`, how much of the paint the speckle covers; for `pixelate`, how fine the mosaic is (0 = two cells across the shape, 1 = thirty-two); for `hatch` (a woodcut print: ragged streaks of bare paper across the ink), how much of the paint the streaks take. */
|
|
25
|
-
export interface ShapeEffect {
|
|
26
|
-
name: 'grain' | 'pixelate' | 'hatch';
|
|
27
|
-
intensity: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface ShapeProps {
|
|
31
|
-
shape: ShapeKind;
|
|
32
|
-
/** Which layers show. Each change paints one layer in (or out) with the brush sweep; a further change waits for that sweep to finish. */
|
|
33
|
-
state: ShapeState;
|
|
34
|
-
/** Flat color of the base layer, painted first. */
|
|
35
|
-
baseColor: string;
|
|
36
|
-
/** Color of the active layer, painted over the base. A hex color also gives the gradient shades; any other CSS color (`rgb(var(--x))`) is used flat. */
|
|
37
|
-
color: string;
|
|
38
|
-
/** Rendered width in CSS pixels (and height, unless `height` is given); the shape itself spans `size × (1 − 2 × padding)`. */
|
|
39
|
-
size?: number;
|
|
40
|
-
/** Rendered height in CSS pixels, for a shape that is not square: a `square` becomes a rectangle, a `circle` an ellipse, the others stretch to fit. */
|
|
41
|
-
height?: number;
|
|
42
|
-
/** Fraction of `size` kept clear on each side (default 0.1) so sketch wobble, brush overspill and filters are not clipped; `0` paints edge to edge. */
|
|
43
|
-
padding?: number;
|
|
44
|
-
line?: ShapeLineStyle;
|
|
45
|
-
/** Texture on the paint: film `grain`, a `pixelate` mosaic of cells a shade lighter or darker than the paint, or woodcut `hatch` streaks; `null` for none. Defaults to grain at 0.6. */
|
|
46
|
-
effect?: ShapeEffect | null;
|
|
47
|
-
/** Whether the active layer is a gradient (default) or flat; always flat under a pixelate mosaic. */
|
|
48
|
-
gradient?: boolean;
|
|
49
|
-
/** Whether state changes paint in and out with a brush sweep (default); off, the shape switches state at once. */
|
|
50
|
-
animate?: boolean;
|
|
51
|
-
/** Start empty and paint up to `state` on mount, or (`view`) once the shape has scrolled into view, instead of appearing already painted. */
|
|
52
|
-
reveal?: 'mount' | 'view';
|
|
53
|
-
/** Seconds each sweep waits before it starts. */
|
|
54
|
-
delay?: number;
|
|
55
|
-
/** Seconds a `view` reveal waits after the shape has scrolled into view before it starts painting; later sweeps are not delayed. */
|
|
56
|
-
revealDelay?: number;
|
|
57
|
-
/** Stable source for the sketch jitter and brush wobble, so re-renders never twitch. */
|
|
58
|
-
seed?: number;
|
|
59
|
-
className?: string;
|
|
60
|
-
/** Extra class per state, added to `className` for whichever state is currently painted (it follows the sweeps, so it switches as each step lands, not when `state` is set). `animating`, if given, is used in place of the state's class for as long as a sweep is running. */
|
|
61
|
-
stateClassName?: Partial<Record<ShapeState | 'animating', string>>;
|
|
62
|
-
style?: CSSProperties;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** A closed outline as absolute points inside the component's viewBox. */
|
|
66
|
-
export type ShapePoints = [number, number][];
|
|
67
|
-
|
|
68
|
-
/** The box a shape is drawn in: its center and half-extents inside the viewBox. */
|
|
69
|
-
export interface ShapeBox {
|
|
70
|
-
cx: number;
|
|
71
|
-
cy: number;
|
|
72
|
-
rx: number;
|
|
73
|
-
ry: number;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** One cell of a pixelate mosaic: its grid position and how far (−1..1) it is shaded from the paint, darker below zero. */
|
|
77
|
-
export interface PixelCell {
|
|
78
|
-
col: number;
|
|
79
|
-
row: number;
|
|
80
|
-
shade: number;
|
|
81
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createRandom, jitter } from '../utils/random.ts';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* A small rotation in degrees for each of `count` stacked items: seeded, so the same stack
|
|
5
|
-
* always leans the same way, within `±spread`, and never the same twice in a row (a repeat
|
|
6
|
-
* would make two items read as one), with the top item kept nearest to straight so the stack
|
|
7
|
-
* looks squared-up rather than scattered.
|
|
8
|
-
*/
|
|
9
|
-
export function getStackAngles(count: number, spread: number, seed: number): number[] {
|
|
10
|
-
if (count === 0) return [];
|
|
11
|
-
if (spread <= 0) return Array.from({ length: count }, () => 0);
|
|
12
|
-
const random = createRandom(seed);
|
|
13
|
-
const angles: number[] = [];
|
|
14
|
-
for (let i = 0; i < count - 1; i++) {
|
|
15
|
-
let angle = jitter(random, spread);
|
|
16
|
-
// Re-draw if it lands within a fifth of the spread of the item beneath.
|
|
17
|
-
if (i > 0 && Math.abs(angle - angles[i - 1]) < spread * 0.2) angle = jitter(random, spread);
|
|
18
|
-
angles.push(angle);
|
|
19
|
-
}
|
|
20
|
-
angles.push(jitter(random, spread * 0.25));
|
|
21
|
-
return angles;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/*
|
|
25
|
-
* The transform origin, in an item's own frame, that lands on the stack's pivot once the item
|
|
26
|
-
* is shifted by (`x`, `y`) px and turned by `rotate` degrees about that pivot: the pivot
|
|
27
|
-
* pulled back by the shift, turned the other way (`translate(x, y) rotate(r)` turns first,
|
|
28
|
-
* then shifts). As `calc()` lengths, so a percentage pivot stays a percentage.
|
|
29
|
-
*/
|
|
30
|
-
export function getPinnedOrigin(originX: string, originY: string, x: number, y: number, rotate: number) {
|
|
31
|
-
const a = (rotate * Math.PI) / 180;
|
|
32
|
-
const dx = x * Math.cos(a) + y * Math.sin(a);
|
|
33
|
-
const dy = -x * Math.sin(a) + y * Math.cos(a);
|
|
34
|
-
return `calc(${originX} - ${round(dx)}px) calc(${originY} - ${round(dy)}px)`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/*
|
|
38
|
-
* To a hundredth of a pixel, so the style string stays short.
|
|
39
|
-
*/
|
|
40
|
-
function round(value: number) {
|
|
41
|
-
return Math.round(value * 100) / 100;
|
|
42
|
-
}
|