scroll-arrows 0.1.3 → 0.3.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 +123 -5
- package/dist/{chunk-GKWBGFLA.js → chunk-GX722UDR.js} +314 -52
- package/dist/index.cjs +316 -49
- package/dist/index.d.cts +78 -3
- package/dist/index.d.ts +78 -3
- package/dist/index.js +6 -3
- package/dist/react.cjs +336 -49
- package/dist/react.d.cts +20 -2
- package/dist/react.d.ts +20 -2
- package/dist/react.js +25 -2
- package/dist/types-CgHPWybd.d.cts +196 -0
- package/dist/types-CgHPWybd.d.ts +196 -0
- package/package.json +1 -1
- package/dist/types-CDd8JqZX.d.cts +0 -104
- package/dist/types-CDd8JqZX.d.ts +0 -104
package/dist/react.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
|
-
import { S as ScrollArrowOptions } from './types-
|
|
2
|
+
import { S as ScrollArrowOptions, a as ScrollArrowGroupOptions } from './types-CgHPWybd.cjs';
|
|
3
3
|
|
|
4
4
|
type Anchor = RefObject<Element | null> | Element | string;
|
|
5
5
|
interface UseScrollArrowOptions extends Omit<ScrollArrowOptions, 'start' | 'end'> {
|
|
@@ -16,5 +16,23 @@ declare function useScrollArrow(options: UseScrollArrowOptions): void;
|
|
|
16
16
|
type ScrollArrowProps = UseScrollArrowOptions;
|
|
17
17
|
/** Declarative component form. Renders nothing itself. */
|
|
18
18
|
declare function ScrollArrowLine(props: ScrollArrowProps): null;
|
|
19
|
+
/** One arrow in a group, with React-ref anchors. */
|
|
20
|
+
interface GroupArrow extends Omit<ScrollArrowOptions, 'start' | 'end'> {
|
|
21
|
+
start: Anchor;
|
|
22
|
+
end: Anchor;
|
|
23
|
+
}
|
|
24
|
+
interface UseScrollArrowGroupOptions extends Omit<ScrollArrowGroupOptions, 'arrows'> {
|
|
25
|
+
arrows: GroupArrow[];
|
|
26
|
+
/** Re-create the group when any value here changes. */
|
|
27
|
+
deps?: unknown[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Imperatively manage a staggered ScrollArrowGroup tied to element refs.
|
|
31
|
+
* Returns nothing; the arrows live in an overlay <svg>, not the React tree.
|
|
32
|
+
*/
|
|
33
|
+
declare function useScrollArrowGroup(options: UseScrollArrowGroupOptions): void;
|
|
34
|
+
type ScrollArrowGroupProps = UseScrollArrowGroupOptions;
|
|
35
|
+
/** Declarative group form. Renders nothing itself. */
|
|
36
|
+
declare function ScrollArrowGroupLines(props: ScrollArrowGroupProps): null;
|
|
19
37
|
|
|
20
|
-
export { ScrollArrowLine, ScrollArrowOptions, type ScrollArrowProps, type UseScrollArrowOptions, useScrollArrow };
|
|
38
|
+
export { type GroupArrow, ScrollArrowGroupLines, ScrollArrowGroupOptions, type ScrollArrowGroupProps, ScrollArrowLine, ScrollArrowOptions, type ScrollArrowProps, type UseScrollArrowGroupOptions, type UseScrollArrowOptions, useScrollArrow, useScrollArrowGroup };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
|
-
import { S as ScrollArrowOptions } from './types-
|
|
2
|
+
import { S as ScrollArrowOptions, a as ScrollArrowGroupOptions } from './types-CgHPWybd.js';
|
|
3
3
|
|
|
4
4
|
type Anchor = RefObject<Element | null> | Element | string;
|
|
5
5
|
interface UseScrollArrowOptions extends Omit<ScrollArrowOptions, 'start' | 'end'> {
|
|
@@ -16,5 +16,23 @@ declare function useScrollArrow(options: UseScrollArrowOptions): void;
|
|
|
16
16
|
type ScrollArrowProps = UseScrollArrowOptions;
|
|
17
17
|
/** Declarative component form. Renders nothing itself. */
|
|
18
18
|
declare function ScrollArrowLine(props: ScrollArrowProps): null;
|
|
19
|
+
/** One arrow in a group, with React-ref anchors. */
|
|
20
|
+
interface GroupArrow extends Omit<ScrollArrowOptions, 'start' | 'end'> {
|
|
21
|
+
start: Anchor;
|
|
22
|
+
end: Anchor;
|
|
23
|
+
}
|
|
24
|
+
interface UseScrollArrowGroupOptions extends Omit<ScrollArrowGroupOptions, 'arrows'> {
|
|
25
|
+
arrows: GroupArrow[];
|
|
26
|
+
/** Re-create the group when any value here changes. */
|
|
27
|
+
deps?: unknown[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Imperatively manage a staggered ScrollArrowGroup tied to element refs.
|
|
31
|
+
* Returns nothing; the arrows live in an overlay <svg>, not the React tree.
|
|
32
|
+
*/
|
|
33
|
+
declare function useScrollArrowGroup(options: UseScrollArrowGroupOptions): void;
|
|
34
|
+
type ScrollArrowGroupProps = UseScrollArrowGroupOptions;
|
|
35
|
+
/** Declarative group form. Renders nothing itself. */
|
|
36
|
+
declare function ScrollArrowGroupLines(props: ScrollArrowGroupProps): null;
|
|
19
37
|
|
|
20
|
-
export { ScrollArrowLine, ScrollArrowOptions, type ScrollArrowProps, type UseScrollArrowOptions, useScrollArrow };
|
|
38
|
+
export { type GroupArrow, ScrollArrowGroupLines, ScrollArrowGroupOptions, type ScrollArrowGroupProps, ScrollArrowLine, ScrollArrowOptions, type ScrollArrowProps, type UseScrollArrowGroupOptions, type UseScrollArrowOptions, useScrollArrow, useScrollArrowGroup };
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ScrollArrow } from './chunk-
|
|
1
|
+
import { ScrollArrow, ScrollArrowGroup } from './chunk-GX722UDR.js';
|
|
2
2
|
import { useRef, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
function read(a) {
|
|
@@ -25,7 +25,30 @@ function ScrollArrowLine(props) {
|
|
|
25
25
|
useScrollArrow(props);
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
|
+
function useScrollArrowGroup(options) {
|
|
29
|
+
const groupRef = useRef(null);
|
|
30
|
+
const { arrows, deps = [], ...rest } = options;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const resolved = arrows.map((a) => {
|
|
33
|
+
const s = read(a.start);
|
|
34
|
+
const e = read(a.end);
|
|
35
|
+
if (!s || !e) return null;
|
|
36
|
+
return { ...a, start: s, end: e };
|
|
37
|
+
}).filter((a) => a !== null);
|
|
38
|
+
if (resolved.length === 0) return;
|
|
39
|
+
const group = new ScrollArrowGroup({ ...rest, arrows: resolved });
|
|
40
|
+
groupRef.current = group;
|
|
41
|
+
return () => {
|
|
42
|
+
group.destroy();
|
|
43
|
+
groupRef.current = null;
|
|
44
|
+
};
|
|
45
|
+
}, deps);
|
|
46
|
+
}
|
|
47
|
+
function ScrollArrowGroupLines(props) {
|
|
48
|
+
useScrollArrowGroup(props);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
28
51
|
|
|
29
|
-
export { ScrollArrowLine, useScrollArrow };
|
|
52
|
+
export { ScrollArrowGroupLines, ScrollArrowLine, useScrollArrow, useScrollArrowGroup };
|
|
30
53
|
//# sourceMappingURL=react.js.map
|
|
31
54
|
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
/** Which edge of an element the arrow attaches to. `auto` picks the best side. */
|
|
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';
|
|
14
|
+
/** Anything we can resolve to a live DOM element. */
|
|
15
|
+
type ElementRef = Element | string;
|
|
16
|
+
/**
|
|
17
|
+
* Where a label sits along the line: a keyword, a `0..1` fraction, or a
|
|
18
|
+
* percentage string like `'25%'`. A dynamically built percentage string is
|
|
19
|
+
* typed as `string`, so cast it (`pct as LabelPosition`) — any unrecognized
|
|
20
|
+
* value falls back to the default at runtime.
|
|
21
|
+
*/
|
|
22
|
+
type LabelPosition = 'start' | 'middle' | 'end' | number | `${number}%`;
|
|
23
|
+
interface ScrollOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The element whose travel through the viewport drives the draw.
|
|
26
|
+
* Defaults to the midpoint between `start` and `end`.
|
|
27
|
+
*/
|
|
28
|
+
target?: ElementRef;
|
|
29
|
+
/**
|
|
30
|
+
* Draw window expressed as fractions of viewport height for the target's
|
|
31
|
+
* top edge. `[0.85, 0.35]` means: empty at 85% down the viewport, fully
|
|
32
|
+
* drawn by 35% down. First value should be larger than the second.
|
|
33
|
+
*/
|
|
34
|
+
range?: [number, number];
|
|
35
|
+
}
|
|
36
|
+
interface ScrollArrowOptions {
|
|
37
|
+
/** Element the arrow starts from. */
|
|
38
|
+
start: ElementRef;
|
|
39
|
+
/** Element the arrow points to. */
|
|
40
|
+
end: ElementRef;
|
|
41
|
+
/**
|
|
42
|
+
* Where the overlay <svg> mounts. Defaults to document.body. Arrows are
|
|
43
|
+
* positioned in document coordinates so they stay glued while scrolling.
|
|
44
|
+
*/
|
|
45
|
+
container?: Element;
|
|
46
|
+
/**
|
|
47
|
+
* The headline knob. 0 = clean straight line, 1 = maximally scratchy and
|
|
48
|
+
* curvy. Maps onto roughjs roughness/bowing plus path curvature.
|
|
49
|
+
*/
|
|
50
|
+
roughness?: number;
|
|
51
|
+
/** Stroke color. CSS color string. Default: currentColor of container. */
|
|
52
|
+
stroke?: string;
|
|
53
|
+
/** Stroke width in px. Default 2. */
|
|
54
|
+
strokeWidth?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Deterministic seed so a given arrow keeps the same scribble between
|
|
57
|
+
* renders. Default: derived from start/end so it's stable but unique.
|
|
58
|
+
*/
|
|
59
|
+
seed?: number;
|
|
60
|
+
/** Force a start edge. Default "auto". */
|
|
61
|
+
startSocket?: Socket;
|
|
62
|
+
/** Force an end edge. Default "auto". */
|
|
63
|
+
endSocket?: Socket;
|
|
64
|
+
/**
|
|
65
|
+
* Slide the start attach point along its edge, as a fraction of the edge
|
|
66
|
+
* length: `0` (default) = centered, `-0.5`/`+0.5` = the corners. Use to fan
|
|
67
|
+
* out several arrows that leave the same element so they don't stack on one
|
|
68
|
+
* point (e.g. `-0.25`, `0`, `+0.25` for three siblings).
|
|
69
|
+
*/
|
|
70
|
+
startSocketOffset?: number;
|
|
71
|
+
/** Slide the end attach point along its edge. See `startSocketOffset`. */
|
|
72
|
+
endSocketOffset?: number;
|
|
73
|
+
/** Extra bow of the underlying curve, 0..1. Folded into roughness if unset. */
|
|
74
|
+
curvature?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Routing style. `"curved"` (default) is the smooth bezier with obstacle
|
|
77
|
+
* avoidance; `"elbow"` draws right-angle connectors for tree/org-chart
|
|
78
|
+
* diagrams. Elbow mode ignores `avoid` and `curvature`. Pair with explicit
|
|
79
|
+
* `startSocket`/`endSocket` for predictable bracket shapes.
|
|
80
|
+
*/
|
|
81
|
+
route?: Route;
|
|
82
|
+
/**
|
|
83
|
+
* Pin the stroke's endpoints to the anchor sockets so the arrow always lands
|
|
84
|
+
* on its targets, even at high roughness. Set false to let the scratchy ends
|
|
85
|
+
* wander off the anchors. Default true.
|
|
86
|
+
*/
|
|
87
|
+
anchorEnds?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Element(s) the arrow should bend around instead of crossing. Single-bend
|
|
90
|
+
* routing — picks the worst blocker and bows the curve clear of it.
|
|
91
|
+
*/
|
|
92
|
+
avoid?: ElementRef | ElementRef[];
|
|
93
|
+
/** Gap to keep between the curve and avoided boxes, px. Default 14. */
|
|
94
|
+
avoidPadding?: number;
|
|
95
|
+
/** Which ends get an arrowhead. Default "end". */
|
|
96
|
+
head?: ArrowHead;
|
|
97
|
+
/** Arrowhead length in px. Default 14. */
|
|
98
|
+
headSize?: number;
|
|
99
|
+
/** Text to place along the line. Omit for no label. */
|
|
100
|
+
label?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Where the label sits *along* the line. Accepts:
|
|
103
|
+
* - a keyword: `'start'`, `'middle'`, or `'end'`;
|
|
104
|
+
* - a `0..1` fraction (`0` = start, `1` = end); or
|
|
105
|
+
* - a percentage string like `'25%'`.
|
|
106
|
+
* Default `'middle'`. For sideways placement see `labelOffset`.
|
|
107
|
+
*/
|
|
108
|
+
labelAt?: LabelPosition;
|
|
109
|
+
/**
|
|
110
|
+
* How far the label sits *perpendicular* to the line, in px (sideways, not
|
|
111
|
+
* along it). Positive sits to the left of the draw direction, negative to the
|
|
112
|
+
* right; 0 sits on the line. Default 0.
|
|
113
|
+
*/
|
|
114
|
+
labelOffset?: number;
|
|
115
|
+
/** Label text color. Default: stroke color. */
|
|
116
|
+
labelColor?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Color painted behind the label to mask the line (the excalidraw "gap"
|
|
119
|
+
* look). Default: the container's background-color. Pass "none" to disable.
|
|
120
|
+
*/
|
|
121
|
+
labelBackground?: string;
|
|
122
|
+
/** CSS `font` shorthand for the label. Default "600 16px sans-serif". */
|
|
123
|
+
font?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Scroll behavior. Pass `false` to drive progress manually via
|
|
126
|
+
* `setProgress()`. Default: auto scroll window.
|
|
127
|
+
*/
|
|
128
|
+
scroll?: ScrollOptions | false;
|
|
129
|
+
/**
|
|
130
|
+
* Multiplier on draw rate. >1 finishes the stroke earlier in the scroll
|
|
131
|
+
* window, <1 lingers. Default 1.
|
|
132
|
+
*/
|
|
133
|
+
speed?: number;
|
|
134
|
+
/** Easing applied to scroll progress before drawing. Default easeInOutCubic. */
|
|
135
|
+
easing?: (t: number) => number;
|
|
136
|
+
/** Start fully drawn instead of empty. Useful with `scroll:false`. Default 0. */
|
|
137
|
+
progress?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Auto-respect `prefers-reduced-motion: reduce`. When the user prefers reduced
|
|
140
|
+
* motion, the arrow renders fully drawn and static (no scroll animation),
|
|
141
|
+
* while still tracking layout. Set false to keep the scroll animation
|
|
142
|
+
* regardless of the OS setting. Default true. Evaluated once at construction.
|
|
143
|
+
*/
|
|
144
|
+
respectReducedMotion?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Initial enabled state. When `false`, the arrow is created hidden and draws
|
|
147
|
+
* nothing until `setEnabled(true)` is called. Use with a `matchMedia` listener
|
|
148
|
+
* to switch arrows off below a breakpoint (where the diagram reflows) without
|
|
149
|
+
* destroying and rebuilding them. Default true.
|
|
150
|
+
*/
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A coordinated set of arrows that draw in a staggered sequence, driven by one
|
|
155
|
+
* shared scroll trigger (or manually). Each arrow gets a slice of the group's
|
|
156
|
+
* progress so they reveal as `A then B then C` rather than independently.
|
|
157
|
+
*/
|
|
158
|
+
interface ScrollArrowGroupOptions {
|
|
159
|
+
/**
|
|
160
|
+
* The arrows in the group, in reveal order. Each entry takes the usual
|
|
161
|
+
* per-arrow options (roughness, stroke, label, ...); the group forces
|
|
162
|
+
* `scroll: false` on each and drives their progress itself.
|
|
163
|
+
*/
|
|
164
|
+
arrows: ScrollArrowOptions[];
|
|
165
|
+
/**
|
|
166
|
+
* How sequential the reveal is, 0..1. `1` (default) draws each arrow in its
|
|
167
|
+
* own non-overlapping slice (`A` finishes before `B` starts). `0` draws them
|
|
168
|
+
* all at once. Values between overlap the slices.
|
|
169
|
+
*/
|
|
170
|
+
stagger?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Shared scroll behavior for the whole group. Pass `false` to drive the group
|
|
173
|
+
* manually via `setProgress()`. The `target` defaults to a synthetic rect
|
|
174
|
+
* spanning every arrow's endpoints, so the group reveals as it scrolls in.
|
|
175
|
+
*/
|
|
176
|
+
scroll?: ScrollOptions | false;
|
|
177
|
+
/** Multiplier on the group's draw rate. See `ScrollArrowOptions.speed`. Default 1. */
|
|
178
|
+
speed?: number;
|
|
179
|
+
/** Easing applied to the group's overall progress before slicing. Default linear. */
|
|
180
|
+
easing?: (t: number) => number;
|
|
181
|
+
/**
|
|
182
|
+
* Auto-respect `prefers-reduced-motion: reduce` for the whole group. When the
|
|
183
|
+
* user prefers reduced motion, every arrow renders fully drawn and static (no
|
|
184
|
+
* scroll animation). Set false to keep the staggered scroll reveal regardless
|
|
185
|
+
* of the OS setting. Default true. Evaluated once at construction.
|
|
186
|
+
*/
|
|
187
|
+
respectReducedMotion?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Initial enabled state for the whole group. When `false`, every arrow starts
|
|
190
|
+
* hidden until `setEnabled(true)`. Pairs with a `matchMedia` listener for
|
|
191
|
+
* breakpoint-aware diagrams. Default true.
|
|
192
|
+
*/
|
|
193
|
+
enabled?: boolean;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type { ArrowHead as A, ElementRef as E, LabelPosition as L, Point as P, ScrollArrowOptions as S, ScrollArrowGroupOptions as a, ScrollOptions as b, Socket as c };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
/** Which edge of an element the arrow attaches to. `auto` picks the best side. */
|
|
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';
|
|
14
|
+
/** Anything we can resolve to a live DOM element. */
|
|
15
|
+
type ElementRef = Element | string;
|
|
16
|
+
/**
|
|
17
|
+
* Where a label sits along the line: a keyword, a `0..1` fraction, or a
|
|
18
|
+
* percentage string like `'25%'`. A dynamically built percentage string is
|
|
19
|
+
* typed as `string`, so cast it (`pct as LabelPosition`) — any unrecognized
|
|
20
|
+
* value falls back to the default at runtime.
|
|
21
|
+
*/
|
|
22
|
+
type LabelPosition = 'start' | 'middle' | 'end' | number | `${number}%`;
|
|
23
|
+
interface ScrollOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The element whose travel through the viewport drives the draw.
|
|
26
|
+
* Defaults to the midpoint between `start` and `end`.
|
|
27
|
+
*/
|
|
28
|
+
target?: ElementRef;
|
|
29
|
+
/**
|
|
30
|
+
* Draw window expressed as fractions of viewport height for the target's
|
|
31
|
+
* top edge. `[0.85, 0.35]` means: empty at 85% down the viewport, fully
|
|
32
|
+
* drawn by 35% down. First value should be larger than the second.
|
|
33
|
+
*/
|
|
34
|
+
range?: [number, number];
|
|
35
|
+
}
|
|
36
|
+
interface ScrollArrowOptions {
|
|
37
|
+
/** Element the arrow starts from. */
|
|
38
|
+
start: ElementRef;
|
|
39
|
+
/** Element the arrow points to. */
|
|
40
|
+
end: ElementRef;
|
|
41
|
+
/**
|
|
42
|
+
* Where the overlay <svg> mounts. Defaults to document.body. Arrows are
|
|
43
|
+
* positioned in document coordinates so they stay glued while scrolling.
|
|
44
|
+
*/
|
|
45
|
+
container?: Element;
|
|
46
|
+
/**
|
|
47
|
+
* The headline knob. 0 = clean straight line, 1 = maximally scratchy and
|
|
48
|
+
* curvy. Maps onto roughjs roughness/bowing plus path curvature.
|
|
49
|
+
*/
|
|
50
|
+
roughness?: number;
|
|
51
|
+
/** Stroke color. CSS color string. Default: currentColor of container. */
|
|
52
|
+
stroke?: string;
|
|
53
|
+
/** Stroke width in px. Default 2. */
|
|
54
|
+
strokeWidth?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Deterministic seed so a given arrow keeps the same scribble between
|
|
57
|
+
* renders. Default: derived from start/end so it's stable but unique.
|
|
58
|
+
*/
|
|
59
|
+
seed?: number;
|
|
60
|
+
/** Force a start edge. Default "auto". */
|
|
61
|
+
startSocket?: Socket;
|
|
62
|
+
/** Force an end edge. Default "auto". */
|
|
63
|
+
endSocket?: Socket;
|
|
64
|
+
/**
|
|
65
|
+
* Slide the start attach point along its edge, as a fraction of the edge
|
|
66
|
+
* length: `0` (default) = centered, `-0.5`/`+0.5` = the corners. Use to fan
|
|
67
|
+
* out several arrows that leave the same element so they don't stack on one
|
|
68
|
+
* point (e.g. `-0.25`, `0`, `+0.25` for three siblings).
|
|
69
|
+
*/
|
|
70
|
+
startSocketOffset?: number;
|
|
71
|
+
/** Slide the end attach point along its edge. See `startSocketOffset`. */
|
|
72
|
+
endSocketOffset?: number;
|
|
73
|
+
/** Extra bow of the underlying curve, 0..1. Folded into roughness if unset. */
|
|
74
|
+
curvature?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Routing style. `"curved"` (default) is the smooth bezier with obstacle
|
|
77
|
+
* avoidance; `"elbow"` draws right-angle connectors for tree/org-chart
|
|
78
|
+
* diagrams. Elbow mode ignores `avoid` and `curvature`. Pair with explicit
|
|
79
|
+
* `startSocket`/`endSocket` for predictable bracket shapes.
|
|
80
|
+
*/
|
|
81
|
+
route?: Route;
|
|
82
|
+
/**
|
|
83
|
+
* Pin the stroke's endpoints to the anchor sockets so the arrow always lands
|
|
84
|
+
* on its targets, even at high roughness. Set false to let the scratchy ends
|
|
85
|
+
* wander off the anchors. Default true.
|
|
86
|
+
*/
|
|
87
|
+
anchorEnds?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Element(s) the arrow should bend around instead of crossing. Single-bend
|
|
90
|
+
* routing — picks the worst blocker and bows the curve clear of it.
|
|
91
|
+
*/
|
|
92
|
+
avoid?: ElementRef | ElementRef[];
|
|
93
|
+
/** Gap to keep between the curve and avoided boxes, px. Default 14. */
|
|
94
|
+
avoidPadding?: number;
|
|
95
|
+
/** Which ends get an arrowhead. Default "end". */
|
|
96
|
+
head?: ArrowHead;
|
|
97
|
+
/** Arrowhead length in px. Default 14. */
|
|
98
|
+
headSize?: number;
|
|
99
|
+
/** Text to place along the line. Omit for no label. */
|
|
100
|
+
label?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Where the label sits *along* the line. Accepts:
|
|
103
|
+
* - a keyword: `'start'`, `'middle'`, or `'end'`;
|
|
104
|
+
* - a `0..1` fraction (`0` = start, `1` = end); or
|
|
105
|
+
* - a percentage string like `'25%'`.
|
|
106
|
+
* Default `'middle'`. For sideways placement see `labelOffset`.
|
|
107
|
+
*/
|
|
108
|
+
labelAt?: LabelPosition;
|
|
109
|
+
/**
|
|
110
|
+
* How far the label sits *perpendicular* to the line, in px (sideways, not
|
|
111
|
+
* along it). Positive sits to the left of the draw direction, negative to the
|
|
112
|
+
* right; 0 sits on the line. Default 0.
|
|
113
|
+
*/
|
|
114
|
+
labelOffset?: number;
|
|
115
|
+
/** Label text color. Default: stroke color. */
|
|
116
|
+
labelColor?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Color painted behind the label to mask the line (the excalidraw "gap"
|
|
119
|
+
* look). Default: the container's background-color. Pass "none" to disable.
|
|
120
|
+
*/
|
|
121
|
+
labelBackground?: string;
|
|
122
|
+
/** CSS `font` shorthand for the label. Default "600 16px sans-serif". */
|
|
123
|
+
font?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Scroll behavior. Pass `false` to drive progress manually via
|
|
126
|
+
* `setProgress()`. Default: auto scroll window.
|
|
127
|
+
*/
|
|
128
|
+
scroll?: ScrollOptions | false;
|
|
129
|
+
/**
|
|
130
|
+
* Multiplier on draw rate. >1 finishes the stroke earlier in the scroll
|
|
131
|
+
* window, <1 lingers. Default 1.
|
|
132
|
+
*/
|
|
133
|
+
speed?: number;
|
|
134
|
+
/** Easing applied to scroll progress before drawing. Default easeInOutCubic. */
|
|
135
|
+
easing?: (t: number) => number;
|
|
136
|
+
/** Start fully drawn instead of empty. Useful with `scroll:false`. Default 0. */
|
|
137
|
+
progress?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Auto-respect `prefers-reduced-motion: reduce`. When the user prefers reduced
|
|
140
|
+
* motion, the arrow renders fully drawn and static (no scroll animation),
|
|
141
|
+
* while still tracking layout. Set false to keep the scroll animation
|
|
142
|
+
* regardless of the OS setting. Default true. Evaluated once at construction.
|
|
143
|
+
*/
|
|
144
|
+
respectReducedMotion?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Initial enabled state. When `false`, the arrow is created hidden and draws
|
|
147
|
+
* nothing until `setEnabled(true)` is called. Use with a `matchMedia` listener
|
|
148
|
+
* to switch arrows off below a breakpoint (where the diagram reflows) without
|
|
149
|
+
* destroying and rebuilding them. Default true.
|
|
150
|
+
*/
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A coordinated set of arrows that draw in a staggered sequence, driven by one
|
|
155
|
+
* shared scroll trigger (or manually). Each arrow gets a slice of the group's
|
|
156
|
+
* progress so they reveal as `A then B then C` rather than independently.
|
|
157
|
+
*/
|
|
158
|
+
interface ScrollArrowGroupOptions {
|
|
159
|
+
/**
|
|
160
|
+
* The arrows in the group, in reveal order. Each entry takes the usual
|
|
161
|
+
* per-arrow options (roughness, stroke, label, ...); the group forces
|
|
162
|
+
* `scroll: false` on each and drives their progress itself.
|
|
163
|
+
*/
|
|
164
|
+
arrows: ScrollArrowOptions[];
|
|
165
|
+
/**
|
|
166
|
+
* How sequential the reveal is, 0..1. `1` (default) draws each arrow in its
|
|
167
|
+
* own non-overlapping slice (`A` finishes before `B` starts). `0` draws them
|
|
168
|
+
* all at once. Values between overlap the slices.
|
|
169
|
+
*/
|
|
170
|
+
stagger?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Shared scroll behavior for the whole group. Pass `false` to drive the group
|
|
173
|
+
* manually via `setProgress()`. The `target` defaults to a synthetic rect
|
|
174
|
+
* spanning every arrow's endpoints, so the group reveals as it scrolls in.
|
|
175
|
+
*/
|
|
176
|
+
scroll?: ScrollOptions | false;
|
|
177
|
+
/** Multiplier on the group's draw rate. See `ScrollArrowOptions.speed`. Default 1. */
|
|
178
|
+
speed?: number;
|
|
179
|
+
/** Easing applied to the group's overall progress before slicing. Default linear. */
|
|
180
|
+
easing?: (t: number) => number;
|
|
181
|
+
/**
|
|
182
|
+
* Auto-respect `prefers-reduced-motion: reduce` for the whole group. When the
|
|
183
|
+
* user prefers reduced motion, every arrow renders fully drawn and static (no
|
|
184
|
+
* scroll animation). Set false to keep the staggered scroll reveal regardless
|
|
185
|
+
* of the OS setting. Default true. Evaluated once at construction.
|
|
186
|
+
*/
|
|
187
|
+
respectReducedMotion?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Initial enabled state for the whole group. When `false`, every arrow starts
|
|
190
|
+
* hidden until `setEnabled(true)`. Pairs with a `matchMedia` listener for
|
|
191
|
+
* breakpoint-aware diagrams. Default true.
|
|
192
|
+
*/
|
|
193
|
+
enabled?: boolean;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type { ArrowHead as A, ElementRef as E, LabelPosition as L, Point as P, ScrollArrowOptions as S, ScrollArrowGroupOptions as a, ScrollOptions as b, Socket as c };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scroll-arrows",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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,
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
type Point = {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
};
|
|
5
|
-
/** Which edge of an element the arrow attaches to. `auto` picks the best side. */
|
|
6
|
-
type Socket = 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'center';
|
|
7
|
-
type ArrowHead = 'start' | 'end' | 'both' | 'none';
|
|
8
|
-
/** Anything we can resolve to a live DOM element. */
|
|
9
|
-
type ElementRef = Element | string;
|
|
10
|
-
interface ScrollOptions {
|
|
11
|
-
/**
|
|
12
|
-
* The element whose travel through the viewport drives the draw.
|
|
13
|
-
* Defaults to the midpoint between `start` and `end`.
|
|
14
|
-
*/
|
|
15
|
-
target?: ElementRef;
|
|
16
|
-
/**
|
|
17
|
-
* Draw window expressed as fractions of viewport height for the target's
|
|
18
|
-
* top edge. `[0.85, 0.35]` means: empty at 85% down the viewport, fully
|
|
19
|
-
* drawn by 35% down. First value should be larger than the second.
|
|
20
|
-
*/
|
|
21
|
-
range?: [number, number];
|
|
22
|
-
}
|
|
23
|
-
interface ScrollArrowOptions {
|
|
24
|
-
/** Element the arrow starts from. */
|
|
25
|
-
start: ElementRef;
|
|
26
|
-
/** Element the arrow points to. */
|
|
27
|
-
end: ElementRef;
|
|
28
|
-
/**
|
|
29
|
-
* Where the overlay <svg> mounts. Defaults to document.body. Arrows are
|
|
30
|
-
* positioned in document coordinates so they stay glued while scrolling.
|
|
31
|
-
*/
|
|
32
|
-
container?: Element;
|
|
33
|
-
/**
|
|
34
|
-
* The headline knob. 0 = clean straight line, 1 = maximally scratchy and
|
|
35
|
-
* curvy. Maps onto roughjs roughness/bowing plus path curvature.
|
|
36
|
-
*/
|
|
37
|
-
roughness?: number;
|
|
38
|
-
/** Stroke color. CSS color string. Default: currentColor of container. */
|
|
39
|
-
stroke?: string;
|
|
40
|
-
/** Stroke width in px. Default 2. */
|
|
41
|
-
strokeWidth?: number;
|
|
42
|
-
/**
|
|
43
|
-
* Deterministic seed so a given arrow keeps the same scribble between
|
|
44
|
-
* renders. Default: derived from start/end so it's stable but unique.
|
|
45
|
-
*/
|
|
46
|
-
seed?: number;
|
|
47
|
-
/** Force a start edge. Default "auto". */
|
|
48
|
-
startSocket?: Socket;
|
|
49
|
-
/** Force an end edge. Default "auto". */
|
|
50
|
-
endSocket?: Socket;
|
|
51
|
-
/** Extra bow of the underlying curve, 0..1. Folded into roughness if unset. */
|
|
52
|
-
curvature?: number;
|
|
53
|
-
/**
|
|
54
|
-
* Pin the stroke's endpoints to the anchor sockets so the arrow always lands
|
|
55
|
-
* on its targets, even at high roughness. Set false to let the scratchy ends
|
|
56
|
-
* wander off the anchors. Default true.
|
|
57
|
-
*/
|
|
58
|
-
anchorEnds?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Element(s) the arrow should bend around instead of crossing. Single-bend
|
|
61
|
-
* routing — picks the worst blocker and bows the curve clear of it.
|
|
62
|
-
*/
|
|
63
|
-
avoid?: ElementRef | ElementRef[];
|
|
64
|
-
/** Gap to keep between the curve and avoided boxes, px. Default 14. */
|
|
65
|
-
avoidPadding?: number;
|
|
66
|
-
/** Which ends get an arrowhead. Default "end". */
|
|
67
|
-
head?: ArrowHead;
|
|
68
|
-
/** Arrowhead length in px. Default 14. */
|
|
69
|
-
headSize?: number;
|
|
70
|
-
/** Text to place along the line. Omit for no label. */
|
|
71
|
-
label?: string;
|
|
72
|
-
/** Position of the label along the line, 0 (start) .. 1 (end). Default 0.5. */
|
|
73
|
-
labelAt?: number;
|
|
74
|
-
/**
|
|
75
|
-
* Perpendicular offset from the line in px. Positive sits to the left of the
|
|
76
|
-
* draw direction, negative to the right; 0 sits on the line. Default 0.
|
|
77
|
-
*/
|
|
78
|
-
labelOffset?: number;
|
|
79
|
-
/** Label text color. Default: stroke color. */
|
|
80
|
-
labelColor?: string;
|
|
81
|
-
/**
|
|
82
|
-
* Color painted behind the label to mask the line (the excalidraw "gap"
|
|
83
|
-
* look). Default: the container's background-color. Pass "none" to disable.
|
|
84
|
-
*/
|
|
85
|
-
labelBackground?: string;
|
|
86
|
-
/** CSS `font` shorthand for the label. Default "600 16px sans-serif". */
|
|
87
|
-
font?: string;
|
|
88
|
-
/**
|
|
89
|
-
* Scroll behavior. Pass `false` to drive progress manually via
|
|
90
|
-
* `setProgress()`. Default: auto scroll window.
|
|
91
|
-
*/
|
|
92
|
-
scroll?: ScrollOptions | false;
|
|
93
|
-
/**
|
|
94
|
-
* Multiplier on draw rate. >1 finishes the stroke earlier in the scroll
|
|
95
|
-
* window, <1 lingers. Default 1.
|
|
96
|
-
*/
|
|
97
|
-
speed?: number;
|
|
98
|
-
/** Easing applied to scroll progress before drawing. Default easeInOutCubic. */
|
|
99
|
-
easing?: (t: number) => number;
|
|
100
|
-
/** Start fully drawn instead of empty. Useful with `scroll:false`. Default 0. */
|
|
101
|
-
progress?: number;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export type { ArrowHead as A, ElementRef as E, Point as P, ScrollArrowOptions as S, ScrollOptions as a, Socket as b };
|