@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/strings.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The geometry of a string hung between points (`DotsBoard`'s connections): the quadratic curve
|
|
3
|
-
* that sags under gravity between two pins, and the SVG path of a whole string through several.
|
|
4
|
-
* No OGL, safe for route bundles.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Types
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export interface Point {
|
|
12
|
-
x: number;
|
|
13
|
-
y: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Helpers
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
* Rest position of a string's bend between two points: the quadratic control point that makes
|
|
22
|
-
* the curve sag by `slack × length` straight down at its middle, but never more than `maxSag`
|
|
23
|
-
* pixels, so a long stretch hangs no lower than the short ones.
|
|
24
|
-
*/
|
|
25
|
-
export function getStringRestControl(a: Point, b: Point, slack: number, maxSag = Number.POSITIVE_INFINITY): Point {
|
|
26
|
-
const sag = Math.min(slack * Math.hypot(b.x - a.x, b.y - a.y), maxSag);
|
|
27
|
-
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 + 2 * sag };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
* The point at `t` (0..1) along a quadratic curve from `a` to `b` through control `c`.
|
|
32
|
-
*/
|
|
33
|
-
export function getQuadraticPoint(a: Point, c: Point, b: Point, t: number): Point {
|
|
34
|
-
const u = 1 - t;
|
|
35
|
-
return {
|
|
36
|
-
x: u * u * a.x + 2 * u * t * c.x + t * t * b.x,
|
|
37
|
-
y: u * u * a.y + 2 * u * t * c.y + t * t * b.y,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* The point `t` (0..1) of the way from `a` to `b`.
|
|
43
|
-
*/
|
|
44
|
-
export function lerpPoint(a: Point, b: Point, t: number): Point {
|
|
45
|
-
return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/*
|
|
49
|
-
* SVG path of one string through several points: a quadratic piece from each point to the
|
|
50
|
-
* next through the bend between them (`bends[i]` joins `points[i]` to `points[i + 1]`), as one
|
|
51
|
-
* continuous stroke. Rounded to a tenth of a unit, so a still string produces the same text
|
|
52
|
-
* each frame.
|
|
53
|
-
*/
|
|
54
|
-
export function buildStringPath(points: Point[], bends: Point[]) {
|
|
55
|
-
if (points.length < 2) return '';
|
|
56
|
-
let d = `M${round(points[0].x)} ${round(points[0].y)}`;
|
|
57
|
-
for (let i = 1; i < points.length; i++) {
|
|
58
|
-
const bend = bends[i - 1];
|
|
59
|
-
d += `Q${round(bend.x)} ${round(bend.y)} ${round(points[i].x)} ${round(points[i].y)}`;
|
|
60
|
-
}
|
|
61
|
-
return d;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/*
|
|
65
|
-
* Where a straight move from `from` to `to` (a pointer between two events) crosses the
|
|
66
|
-
* quadratic curve from `a` to `b` through control `c`: the curve's `t` (0..1) at the crossing,
|
|
67
|
-
* or null when the move does not cross it. The curve is walked as `segments` straight pieces.
|
|
68
|
-
*/
|
|
69
|
-
export function getStringCrossing(a: Point, c: Point, b: Point, from: Point, to: Point, segments = 12): number | null {
|
|
70
|
-
let prev = a;
|
|
71
|
-
for (let i = 1; i <= segments; i++) {
|
|
72
|
-
const t = i / segments;
|
|
73
|
-
const next = getQuadraticPoint(a, c, b, t);
|
|
74
|
-
const hit = getSegmentIntersection(prev, next, from, to);
|
|
75
|
-
if (hit !== null) return (i - 1 + hit) / segments;
|
|
76
|
-
prev = next;
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/*
|
|
82
|
-
* The point of the quadratic curve from `a` to `b` through control `c` nearest to `point`, as
|
|
83
|
-
* the curve's `t` (0..1) and the distance to it, found among `segments + 1` samples.
|
|
84
|
-
*/
|
|
85
|
-
export function getNearestStringPoint(a: Point, c: Point, b: Point, point: Point, segments = 24) {
|
|
86
|
-
let best = { t: 0, distance: Number.POSITIVE_INFINITY };
|
|
87
|
-
for (let i = 0; i <= segments; i++) {
|
|
88
|
-
const t = i / segments;
|
|
89
|
-
const at = getQuadraticPoint(a, c, b, t);
|
|
90
|
-
const distance = Math.hypot(at.x - point.x, at.y - point.y);
|
|
91
|
-
if (distance < best.distance) best = { t, distance };
|
|
92
|
-
}
|
|
93
|
-
return best;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/*
|
|
97
|
-
* Where segment `p1`→`p2` meets segment `q1`→`q2`, as the fraction along the first (0..1), or
|
|
98
|
-
* null when they do not meet (parallel ones never do).
|
|
99
|
-
*/
|
|
100
|
-
export function getSegmentIntersection(p1: Point, p2: Point, q1: Point, q2: Point): number | null {
|
|
101
|
-
const rx = p2.x - p1.x;
|
|
102
|
-
const ry = p2.y - p1.y;
|
|
103
|
-
const sx = q2.x - q1.x;
|
|
104
|
-
const sy = q2.y - q1.y;
|
|
105
|
-
const denominator = rx * sy - ry * sx;
|
|
106
|
-
if (denominator === 0) return null;
|
|
107
|
-
const dx = q1.x - p1.x;
|
|
108
|
-
const dy = q1.y - p1.y;
|
|
109
|
-
const t = (dx * sy - dy * sx) / denominator;
|
|
110
|
-
const u = (dx * ry - dy * rx) / denominator;
|
|
111
|
-
return t >= 0 && t <= 1 && u >= 0 && u <= 1 ? t : null;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function round(value: number) {
|
|
115
|
-
return Math.round(value * 10) / 10;
|
|
116
|
-
}
|