@jsb188/gfx 1.1.2

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.
Files changed (65) hide show
  1. package/README.md +522 -0
  2. package/elements/Shapes.helpers.ts +204 -0
  3. package/elements/Shapes.hooks.ts +171 -0
  4. package/elements/Shapes.tsx +505 -0
  5. package/elements/Shapes.types.ts +81 -0
  6. package/elements/Stack.helpers.ts +42 -0
  7. package/elements/Stack.tsx +143 -0
  8. package/elements/Text.helpers.ts +45 -0
  9. package/elements/Text.hooks.ts +197 -0
  10. package/elements/Text.tsx +98 -0
  11. package/libs/chain.ts +174 -0
  12. package/libs/dotGrid.helpers.ts +53 -0
  13. package/libs/dotGrid.ts +954 -0
  14. package/libs/effects/dotEffects.ts +136 -0
  15. package/libs/effects/effectQuad.ts +146 -0
  16. package/libs/effects/effectRegion.ts +299 -0
  17. package/libs/effects/imageEffects.ts +599 -0
  18. package/libs/effects/index.ts +8 -0
  19. package/libs/effects/ripple.ts +160 -0
  20. package/libs/glsl.ts +134 -0
  21. package/libs/passes.ts +374 -0
  22. package/libs/pointer.ts +151 -0
  23. package/libs/runtime.ts +329 -0
  24. package/libs/texture.ts +160 -0
  25. package/libs/types.ts +94 -0
  26. package/libs/uniforms.ts +32 -0
  27. package/main.ts +4 -0
  28. package/modules/Carousel.helpers.ts +316 -0
  29. package/modules/Carousel.hooks.ts +520 -0
  30. package/modules/Carousel.tsx +631 -0
  31. package/modules/Dots.tsx +269 -0
  32. package/modules/DotsBoard.helpers.ts +388 -0
  33. package/modules/DotsBoard.hooks.ts +144 -0
  34. package/modules/DotsBoard.strings.ts +649 -0
  35. package/modules/DotsBoard.types.ts +240 -0
  36. package/modules/DotsBoardCanvas.hooks.ts +49 -0
  37. package/modules/DotsBoardCanvas.tsx +190 -0
  38. package/modules/DotsBoardElements.tsx +330 -0
  39. package/modules/Gallery.helpers.ts +32 -0
  40. package/modules/Gallery.hooks.ts +149 -0
  41. package/modules/Gallery.tsx +194 -0
  42. package/modules/GfxCanvas.hooks.ts +12 -0
  43. package/modules/GfxCanvas.tsx +189 -0
  44. package/modules/Hero.tsx +90 -0
  45. package/modules/KineticHeader.helpers.ts +44 -0
  46. package/modules/KineticHeader.hooks.ts +206 -0
  47. package/modules/KineticHeader.tsx +305 -0
  48. package/modules/KineticHeader.types.ts +56 -0
  49. package/modules/ScrollSteps.hooks.ts +138 -0
  50. package/modules/ScrollSteps.tsx +98 -0
  51. package/package.json +52 -0
  52. package/scenes/Carousel.ts +277 -0
  53. package/scenes/DotsBoard.helpers.ts +12 -0
  54. package/scenes/DotsBoard.ts +245 -0
  55. package/scenes/Hero.ts +280 -0
  56. package/tsconfig.json +13 -0
  57. package/utils/align.ts +18 -0
  58. package/utils/color.ts +112 -0
  59. package/utils/dotEffectSpecs.ts +79 -0
  60. package/utils/dotGridSpecs.ts +469 -0
  61. package/utils/easing.ts +18 -0
  62. package/utils/imageEffectSpecs.ts +89 -0
  63. package/utils/motion.ts +88 -0
  64. package/utils/random.ts +22 -0
  65. package/utils/strings.ts +116 -0
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Small deterministic PRNG (Park–Miller): a given seed always produces the same sequence,
3
+ * across renders and on the server, so seeded wobble never twitches or fails hydration.
4
+ */
5
+ export function createRandom(seed: number): () => number {
6
+ let state = (Math.abs(Math.floor(seed)) % 2147483646) + 1;
7
+ const next = () => {
8
+ state = (state * 16807) % 2147483647;
9
+ return state / 2147483647;
10
+ };
11
+ // A small seed's first outputs are tiny (seed × 16807 / 2³¹), which would make every
12
+ // seeded sequence start at the bottom of its range; spin past them.
13
+ for (let i = 0; i < 3; i++) next();
14
+ return next;
15
+ }
16
+
17
+ /*
18
+ * Random value in `-amount..amount`.
19
+ */
20
+ export function jitter(random: () => number, amount: number): number {
21
+ return (random() - 0.5) * 2 * amount;
22
+ }
@@ -0,0 +1,116 @@
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
+ }