unfold-nav 0.1.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.
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Anything that can be rendered as an icon:
3
+ * - inline SVG / HTML markup: `'<svg …>…</svg>'` (treated as trusted markup)
4
+ * - an image URL: `'/icons/home.svg'`, `'https://…/a.png'`, `'data:image/…'`
5
+ * - an emoji or short text: `'🏠'`, `'A'`
6
+ * - a name your `iconResolver` understands: `'home'`
7
+ * - a DOM node (cloned per use) or a function returning one of the above
8
+ */
9
+ export type IconSource = string | Node | (() => Node | string);
10
+ export interface NavPage {
11
+ /** Stable id. Generated from the tree position when omitted. */
12
+ id?: string;
13
+ label: string;
14
+ /** Where selecting the page goes. Pages without `href` act as groups (or as actions, see `unfold-select`). */
15
+ href?: string;
16
+ /** `_blank` opens in a new tab. */
17
+ target?: string;
18
+ icon?: IconSource;
19
+ /** Shown under the label while the page is highlighted, and exposed to screen readers. */
20
+ description?: string;
21
+ /** Per-node accent colour (any CSS colour). */
22
+ color?: string;
23
+ disabled?: boolean;
24
+ children?: NavPage[];
25
+ /** Free-form payload, handed back in events. */
26
+ data?: unknown;
27
+ }
28
+ export type Position = 'top-left' | 'top' | 'top-right' | 'left' | 'center' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right'
29
+ /** Render the button in document flow (e.g. inside a header); the graph still unfolds in a top-layer overlay. */
30
+ | 'inline';
31
+ export type LabelMode = 'auto' | 'always' | 'hover' | 'none';
32
+ export type DockStyle = 'float' | 'bar';
33
+ export type ArrowKeys = 'tree' | 'spatial';
34
+ /** Text the component speaks or shows. Override for other languages. `{label}` is replaced. */
35
+ export interface UnfoldNavStrings {
36
+ /** Accessible name of the list of pages. */
37
+ pages: string;
38
+ /** The centre button at the top level. */
39
+ close: string;
40
+ /** The centre button one level down. */
41
+ backToTop: string;
42
+ /** The centre button deeper down; `{label}` is the page it goes back to. */
43
+ back: string;
44
+ }
45
+ export type EdgeStyle = 'curved' | 'straight' | 'step' | 'none';
46
+ export type Theme = 'auto' | 'light' | 'dark';
47
+ export interface SelectDetail {
48
+ page: NavPage;
49
+ /** Pages from the top level down to (and including) the selected page. */
50
+ trail: NavPage[];
51
+ /** How the selection happened. */
52
+ via: 'release' | 'click' | 'keyboard';
53
+ }
54
+ export interface UnfoldNavOptions {
55
+ /** The site map: an array of top-level pages, or a single root page whose children are the top level. */
56
+ pages: NavPage[] | NavPage;
57
+ /** Where the button sits. Default `bottom-right`. */
58
+ position: Position;
59
+ /**
60
+ * `float`: the button floats over the page. `bar`: it sits in a strip along its edge.
61
+ * Use the published `--unfold-inset-*` values for page padding to keep content clear.
62
+ */
63
+ dock: DockStyle;
64
+ /** Distance from the viewport edge in px (`number` or `{ x, y }`). Default 24. */
65
+ offset: number | {
66
+ x: number;
67
+ y: number;
68
+ };
69
+ /** Press duration (ms) before the graph opens in drag mode. Default 220. */
70
+ holdDelay: number;
71
+ /** Dwell time (ms) over a branch before it unfolds while dragging. Default 140. */
72
+ expandDelay: number;
73
+ /** A short tap opens the graph in tap-through mode. Default true. */
74
+ openOnTap: boolean;
75
+ /** Diameter of page nodes in px. Default 52. */
76
+ nodeSize: number;
77
+ /** Diameter of the button in px. Default 60. */
78
+ triggerSize: number;
79
+ /** Preferred distance between a node and its children in px. Default 96. */
80
+ spacing: number;
81
+ /** Minimum free space between neighbouring nodes in px. Default 16. */
82
+ gap: number;
83
+ /** `auto`: labels for the level you're on + highlighted node. `always`, `hover` or `none`. Default `auto`. */
84
+ labels: LabelMode;
85
+ edges: EdgeStyle;
86
+ /** Dim and blur the page behind the graph. Default true. */
87
+ backdrop: boolean;
88
+ /** Vibrate on open / highlight where supported. Default true. */
89
+ haptics: boolean;
90
+ theme: Theme;
91
+ /** URL of the current page. `undefined` = use `location`, `null` = none. */
92
+ current: string | null | undefined;
93
+ /** Accessible name of the button and the navigation dialog. Default `Navigation`. */
94
+ label: string;
95
+ /**
96
+ * `tree` (default): the standard tree keys: Up/Down previous/next, Right opens a branch or enters it,
97
+ * Left closes it or goes to the parent. `spatial`: arrows move to the nearest page in that direction.
98
+ */
99
+ arrowKeys: ArrowKeys;
100
+ /** Override the built-in text (for other languages). */
101
+ strings: Partial<UnfoldNavStrings>;
102
+ /** Icon for the button. Defaults to a small graph glyph. */
103
+ triggerIcon: IconSource | undefined;
104
+ /** Turn icon names (`icon: 'home'`) into markup or nodes, e.g. from an icon library. */
105
+ iconResolver: ((name: string, page?: NavPage) => Node | string | null | undefined) | undefined;
106
+ /** Custom navigation for client-side routers. Called instead of `location.assign`. */
107
+ navigate: ((page: NavPage, detail: SelectDetail) => void) | undefined;
108
+ }