scroll-arrows 0.1.0 → 0.2.0
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 +141 -14
- package/dist/{chunk-HLZXSGP5.js → chunk-LIT577GH.js} +288 -43
- package/dist/index.cjs +290 -40
- package/dist/index.d.cts +69 -3
- package/dist/index.d.ts +69 -3
- package/dist/index.js +6 -3
- package/dist/react.cjs +310 -40
- package/dist/react.d.cts +22 -5
- package/dist/react.d.ts +22 -5
- package/dist/react.js +25 -2
- package/dist/{types-DehQP2Hx.d.cts → types-Cpvz9wtr.d.cts} +81 -3
- package/dist/{types-DehQP2Hx.d.ts → types-Cpvz9wtr.d.ts} +81 -3
- package/package.json +14 -3
|
@@ -3,8 +3,14 @@ type Point = {
|
|
|
3
3
|
y: number;
|
|
4
4
|
};
|
|
5
5
|
/** Which edge of an element the arrow attaches to. `auto` picks the best side. */
|
|
6
|
-
type Socket =
|
|
7
|
-
type ArrowHead =
|
|
6
|
+
type Socket = 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'center';
|
|
7
|
+
type ArrowHead = 'start' | 'end' | 'both' | 'none';
|
|
8
|
+
/**
|
|
9
|
+
* Line routing style. `curved` (default) is the smooth bezier with single-bend
|
|
10
|
+
* obstacle avoidance. `elbow` draws right-angle connectors (tree/org-chart
|
|
11
|
+
* brackets); `elbow` ignores `avoid`/`curvature`.
|
|
12
|
+
*/
|
|
13
|
+
type Route = 'curved' | 'elbow';
|
|
8
14
|
/** Anything we can resolve to a live DOM element. */
|
|
9
15
|
type ElementRef = Element | string;
|
|
10
16
|
interface ScrollOptions {
|
|
@@ -48,8 +54,24 @@ interface ScrollArrowOptions {
|
|
|
48
54
|
startSocket?: Socket;
|
|
49
55
|
/** Force an end edge. Default "auto". */
|
|
50
56
|
endSocket?: Socket;
|
|
57
|
+
/**
|
|
58
|
+
* Slide the start attach point along its edge, as a fraction of the edge
|
|
59
|
+
* length: `0` (default) = centered, `-0.5`/`+0.5` = the corners. Use to fan
|
|
60
|
+
* out several arrows that leave the same element so they don't stack on one
|
|
61
|
+
* point (e.g. `-0.25`, `0`, `+0.25` for three siblings).
|
|
62
|
+
*/
|
|
63
|
+
startSocketOffset?: number;
|
|
64
|
+
/** Slide the end attach point along its edge. See `startSocketOffset`. */
|
|
65
|
+
endSocketOffset?: number;
|
|
51
66
|
/** Extra bow of the underlying curve, 0..1. Folded into roughness if unset. */
|
|
52
67
|
curvature?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Routing style. `"curved"` (default) is the smooth bezier with obstacle
|
|
70
|
+
* avoidance; `"elbow"` draws right-angle connectors for tree/org-chart
|
|
71
|
+
* diagrams. Elbow mode ignores `avoid` and `curvature`. Pair with explicit
|
|
72
|
+
* `startSocket`/`endSocket` for predictable bracket shapes.
|
|
73
|
+
*/
|
|
74
|
+
route?: Route;
|
|
53
75
|
/**
|
|
54
76
|
* Pin the stroke's endpoints to the anchor sockets so the arrow always lands
|
|
55
77
|
* on its targets, even at high roughness. Set false to let the scratchy ends
|
|
@@ -99,6 +121,62 @@ interface ScrollArrowOptions {
|
|
|
99
121
|
easing?: (t: number) => number;
|
|
100
122
|
/** Start fully drawn instead of empty. Useful with `scroll:false`. Default 0. */
|
|
101
123
|
progress?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Auto-respect `prefers-reduced-motion: reduce`. When the user prefers reduced
|
|
126
|
+
* motion, the arrow renders fully drawn and static (no scroll animation),
|
|
127
|
+
* while still tracking layout. Set false to keep the scroll animation
|
|
128
|
+
* regardless of the OS setting. Default true. Evaluated once at construction.
|
|
129
|
+
*/
|
|
130
|
+
respectReducedMotion?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Initial enabled state. When `false`, the arrow is created hidden and draws
|
|
133
|
+
* nothing until `setEnabled(true)` is called. Use with a `matchMedia` listener
|
|
134
|
+
* to switch arrows off below a breakpoint (where the diagram reflows) without
|
|
135
|
+
* destroying and rebuilding them. Default true.
|
|
136
|
+
*/
|
|
137
|
+
enabled?: boolean;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A coordinated set of arrows that draw in a staggered sequence, driven by one
|
|
141
|
+
* shared scroll trigger (or manually). Each arrow gets a slice of the group's
|
|
142
|
+
* progress so they reveal as `A then B then C` rather than independently.
|
|
143
|
+
*/
|
|
144
|
+
interface ScrollArrowGroupOptions {
|
|
145
|
+
/**
|
|
146
|
+
* The arrows in the group, in reveal order. Each entry takes the usual
|
|
147
|
+
* per-arrow options (roughness, stroke, label, ...); the group forces
|
|
148
|
+
* `scroll: false` on each and drives their progress itself.
|
|
149
|
+
*/
|
|
150
|
+
arrows: ScrollArrowOptions[];
|
|
151
|
+
/**
|
|
152
|
+
* How sequential the reveal is, 0..1. `1` (default) draws each arrow in its
|
|
153
|
+
* own non-overlapping slice (`A` finishes before `B` starts). `0` draws them
|
|
154
|
+
* all at once. Values between overlap the slices.
|
|
155
|
+
*/
|
|
156
|
+
stagger?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Shared scroll behavior for the whole group. Pass `false` to drive the group
|
|
159
|
+
* manually via `setProgress()`. The `target` defaults to a synthetic rect
|
|
160
|
+
* spanning every arrow's endpoints, so the group reveals as it scrolls in.
|
|
161
|
+
*/
|
|
162
|
+
scroll?: ScrollOptions | false;
|
|
163
|
+
/** Multiplier on the group's draw rate. See `ScrollArrowOptions.speed`. Default 1. */
|
|
164
|
+
speed?: number;
|
|
165
|
+
/** Easing applied to the group's overall progress before slicing. Default linear. */
|
|
166
|
+
easing?: (t: number) => number;
|
|
167
|
+
/**
|
|
168
|
+
* Auto-respect `prefers-reduced-motion: reduce` for the whole group. When the
|
|
169
|
+
* user prefers reduced motion, every arrow renders fully drawn and static (no
|
|
170
|
+
* scroll animation). Set false to keep the staggered scroll reveal regardless
|
|
171
|
+
* of the OS setting. Default true. Evaluated once at construction.
|
|
172
|
+
*/
|
|
173
|
+
respectReducedMotion?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Initial enabled state for the whole group. When `false`, every arrow starts
|
|
176
|
+
* hidden until `setEnabled(true)`. Pairs with a `matchMedia` listener for
|
|
177
|
+
* breakpoint-aware diagrams. Default true.
|
|
178
|
+
*/
|
|
179
|
+
enabled?: boolean;
|
|
102
180
|
}
|
|
103
181
|
|
|
104
|
-
export type { ArrowHead as A, ElementRef as E, Point as P, ScrollArrowOptions as S,
|
|
182
|
+
export type { ArrowHead as A, ElementRef as E, Point as P, ScrollArrowOptions as S, ScrollArrowGroupOptions as a, ScrollOptions as b, Socket as c };
|
|
@@ -3,8 +3,14 @@ type Point = {
|
|
|
3
3
|
y: number;
|
|
4
4
|
};
|
|
5
5
|
/** Which edge of an element the arrow attaches to. `auto` picks the best side. */
|
|
6
|
-
type Socket =
|
|
7
|
-
type ArrowHead =
|
|
6
|
+
type Socket = 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'center';
|
|
7
|
+
type ArrowHead = 'start' | 'end' | 'both' | 'none';
|
|
8
|
+
/**
|
|
9
|
+
* Line routing style. `curved` (default) is the smooth bezier with single-bend
|
|
10
|
+
* obstacle avoidance. `elbow` draws right-angle connectors (tree/org-chart
|
|
11
|
+
* brackets); `elbow` ignores `avoid`/`curvature`.
|
|
12
|
+
*/
|
|
13
|
+
type Route = 'curved' | 'elbow';
|
|
8
14
|
/** Anything we can resolve to a live DOM element. */
|
|
9
15
|
type ElementRef = Element | string;
|
|
10
16
|
interface ScrollOptions {
|
|
@@ -48,8 +54,24 @@ interface ScrollArrowOptions {
|
|
|
48
54
|
startSocket?: Socket;
|
|
49
55
|
/** Force an end edge. Default "auto". */
|
|
50
56
|
endSocket?: Socket;
|
|
57
|
+
/**
|
|
58
|
+
* Slide the start attach point along its edge, as a fraction of the edge
|
|
59
|
+
* length: `0` (default) = centered, `-0.5`/`+0.5` = the corners. Use to fan
|
|
60
|
+
* out several arrows that leave the same element so they don't stack on one
|
|
61
|
+
* point (e.g. `-0.25`, `0`, `+0.25` for three siblings).
|
|
62
|
+
*/
|
|
63
|
+
startSocketOffset?: number;
|
|
64
|
+
/** Slide the end attach point along its edge. See `startSocketOffset`. */
|
|
65
|
+
endSocketOffset?: number;
|
|
51
66
|
/** Extra bow of the underlying curve, 0..1. Folded into roughness if unset. */
|
|
52
67
|
curvature?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Routing style. `"curved"` (default) is the smooth bezier with obstacle
|
|
70
|
+
* avoidance; `"elbow"` draws right-angle connectors for tree/org-chart
|
|
71
|
+
* diagrams. Elbow mode ignores `avoid` and `curvature`. Pair with explicit
|
|
72
|
+
* `startSocket`/`endSocket` for predictable bracket shapes.
|
|
73
|
+
*/
|
|
74
|
+
route?: Route;
|
|
53
75
|
/**
|
|
54
76
|
* Pin the stroke's endpoints to the anchor sockets so the arrow always lands
|
|
55
77
|
* on its targets, even at high roughness. Set false to let the scratchy ends
|
|
@@ -99,6 +121,62 @@ interface ScrollArrowOptions {
|
|
|
99
121
|
easing?: (t: number) => number;
|
|
100
122
|
/** Start fully drawn instead of empty. Useful with `scroll:false`. Default 0. */
|
|
101
123
|
progress?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Auto-respect `prefers-reduced-motion: reduce`. When the user prefers reduced
|
|
126
|
+
* motion, the arrow renders fully drawn and static (no scroll animation),
|
|
127
|
+
* while still tracking layout. Set false to keep the scroll animation
|
|
128
|
+
* regardless of the OS setting. Default true. Evaluated once at construction.
|
|
129
|
+
*/
|
|
130
|
+
respectReducedMotion?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Initial enabled state. When `false`, the arrow is created hidden and draws
|
|
133
|
+
* nothing until `setEnabled(true)` is called. Use with a `matchMedia` listener
|
|
134
|
+
* to switch arrows off below a breakpoint (where the diagram reflows) without
|
|
135
|
+
* destroying and rebuilding them. Default true.
|
|
136
|
+
*/
|
|
137
|
+
enabled?: boolean;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A coordinated set of arrows that draw in a staggered sequence, driven by one
|
|
141
|
+
* shared scroll trigger (or manually). Each arrow gets a slice of the group's
|
|
142
|
+
* progress so they reveal as `A then B then C` rather than independently.
|
|
143
|
+
*/
|
|
144
|
+
interface ScrollArrowGroupOptions {
|
|
145
|
+
/**
|
|
146
|
+
* The arrows in the group, in reveal order. Each entry takes the usual
|
|
147
|
+
* per-arrow options (roughness, stroke, label, ...); the group forces
|
|
148
|
+
* `scroll: false` on each and drives their progress itself.
|
|
149
|
+
*/
|
|
150
|
+
arrows: ScrollArrowOptions[];
|
|
151
|
+
/**
|
|
152
|
+
* How sequential the reveal is, 0..1. `1` (default) draws each arrow in its
|
|
153
|
+
* own non-overlapping slice (`A` finishes before `B` starts). `0` draws them
|
|
154
|
+
* all at once. Values between overlap the slices.
|
|
155
|
+
*/
|
|
156
|
+
stagger?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Shared scroll behavior for the whole group. Pass `false` to drive the group
|
|
159
|
+
* manually via `setProgress()`. The `target` defaults to a synthetic rect
|
|
160
|
+
* spanning every arrow's endpoints, so the group reveals as it scrolls in.
|
|
161
|
+
*/
|
|
162
|
+
scroll?: ScrollOptions | false;
|
|
163
|
+
/** Multiplier on the group's draw rate. See `ScrollArrowOptions.speed`. Default 1. */
|
|
164
|
+
speed?: number;
|
|
165
|
+
/** Easing applied to the group's overall progress before slicing. Default linear. */
|
|
166
|
+
easing?: (t: number) => number;
|
|
167
|
+
/**
|
|
168
|
+
* Auto-respect `prefers-reduced-motion: reduce` for the whole group. When the
|
|
169
|
+
* user prefers reduced motion, every arrow renders fully drawn and static (no
|
|
170
|
+
* scroll animation). Set false to keep the staggered scroll reveal regardless
|
|
171
|
+
* of the OS setting. Default true. Evaluated once at construction.
|
|
172
|
+
*/
|
|
173
|
+
respectReducedMotion?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Initial enabled state for the whole group. When `false`, every arrow starts
|
|
176
|
+
* hidden until `setEnabled(true)`. Pairs with a `matchMedia` listener for
|
|
177
|
+
* breakpoint-aware diagrams. Default true.
|
|
178
|
+
*/
|
|
179
|
+
enabled?: boolean;
|
|
102
180
|
}
|
|
103
181
|
|
|
104
|
-
export type { ArrowHead as A, ElementRef as E, Point as P, ScrollArrowOptions as S,
|
|
182
|
+
export type { ArrowHead as A, ElementRef as E, Point as P, ScrollArrowOptions as S, ScrollArrowGroupOptions as a, ScrollOptions as b, Socket as c };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scroll-arrows",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Hand-drawn arrows that draw themselves between two elements as you scroll. Roughness goes from clean straight lines to scratchy and curvy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"author": "Dan
|
|
8
|
+
"author": "Dan (https://github.com/dancj)",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/dancj/scroll-arrows.git"
|
|
@@ -54,11 +54,16 @@
|
|
|
54
54
|
"build": "tsup",
|
|
55
55
|
"dev": "tsup --watch",
|
|
56
56
|
"demo": "vite demo",
|
|
57
|
+
"gen:hero": "node scripts/genHeroSvg.mjs",
|
|
57
58
|
"typecheck": "tsc --noEmit",
|
|
59
|
+
"lint": "eslint .",
|
|
60
|
+
"lint:fix": "eslint . --fix",
|
|
61
|
+
"format": "prettier --write .",
|
|
62
|
+
"format:check": "prettier --check .",
|
|
58
63
|
"test": "vitest run",
|
|
59
64
|
"test:watch": "vitest",
|
|
60
65
|
"coverage": "vitest run --coverage",
|
|
61
|
-
"prepublishOnly": "npm run typecheck && npm run coverage && npm run build"
|
|
66
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm run coverage && npm run build"
|
|
62
67
|
},
|
|
63
68
|
"dependencies": {
|
|
64
69
|
"roughjs": "^4.6.6"
|
|
@@ -72,12 +77,18 @@
|
|
|
72
77
|
}
|
|
73
78
|
},
|
|
74
79
|
"devDependencies": {
|
|
80
|
+
"@eslint/js": "^9.39.4",
|
|
75
81
|
"@types/react": "^18.3.0",
|
|
76
82
|
"@vitest/coverage-v8": "^2.1.0",
|
|
83
|
+
"eslint": "^9.39.4",
|
|
84
|
+
"eslint-config-prettier": "^9.1.2",
|
|
85
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
77
86
|
"jsdom": "^25.0.0",
|
|
87
|
+
"prettier": "^3.8.4",
|
|
78
88
|
"react": "^18.3.0",
|
|
79
89
|
"tsup": "^8.0.0",
|
|
80
90
|
"typescript": "^5.4.0",
|
|
91
|
+
"typescript-eslint": "^8.61.1",
|
|
81
92
|
"vite": "^5.0.0",
|
|
82
93
|
"vitest": "^2.1.0"
|
|
83
94
|
}
|