nimbus-docs 0.1.6 → 0.1.7

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,205 @@
1
+ import { ReactNode, RefObject } from "react";
2
+ import { ClassValue } from "clsx";
3
+
4
+ //#region src/react/diagram.d.ts
5
+ type Depth = "intuition" | "working" | "mechanism";
6
+ type ReducedMotionMode = "respect" | "ignore";
7
+ type DiagramPhase = "idle" | "ready" | "playing" | "paused";
8
+ interface DiagramContextValue {
9
+ /** Stable per-instance id from useId. */
10
+ id: string;
11
+ /** Derived lifecycle state. */
12
+ phase: DiagramPhase;
13
+ /** True when the diagram should be advancing animation. */
14
+ playing: boolean;
15
+ /** Element intersects the viewport (direct IntersectionObserver). */
16
+ visible: boolean;
17
+ /** Browser tab is visible (Page Visibility API). */
18
+ tabVisible: boolean;
19
+ /** Reduced-motion is in effect (OS + reducedMotion="respect" mode). */
20
+ reducedMotion: boolean;
21
+ /** Reader's depth setting. Stub until the depth dial ships. */
22
+ depth: Depth;
23
+ /** Theme tokens. Stub until row 4 wires real values. */
24
+ theme: {
25
+ id: string;
26
+ };
27
+ /** Trigger a reset — bumps the subtree key; children's useState resets. */
28
+ reset: () => void;
29
+ /** Toggle play/pause from user action. */
30
+ toggle: () => void;
31
+ }
32
+ declare function useDiagram(): DiagramContextValue | null;
33
+ /**
34
+ * Returns the wrapper context, or a default + one-time dev warning when
35
+ * called outside a `<Diagram>`. Used by every hook in nimbus-docs/react
36
+ * so authors can prototype without forgetting the wrapper.
37
+ */
38
+ declare function useDiagramOrDefault(hookName: string): DiagramContextValue;
39
+ interface DiagramProps {
40
+ children: ReactNode;
41
+ fallback?: string;
42
+ pauseWhenOffscreen?: boolean;
43
+ reducedMotion?: ReducedMotionMode;
44
+ /** Forwarded; Astro's client:* directive dictates the actual hydration timing. */
45
+ hydration?: "visible" | "idle" | "load";
46
+ /** Wrap children in an error boundary that exposes a Reset button on render failure. Default: true. */
47
+ errorBoundary?: boolean;
48
+ /** Listen for space (toggle) / r (reset) keypresses bubbling from inside the region. Skipped when target is an interactive element. Default: true. */
49
+ keyboard?: boolean;
50
+ /** ARIA region label. */
51
+ label?: string;
52
+ className?: string;
53
+ }
54
+ declare function DiagramRoot(props: DiagramProps): any;
55
+ declare const Diagram: typeof DiagramRoot;
56
+ //#endregion
57
+ //#region src/react/registry.d.ts
58
+ /**
59
+ * Page-scoped Diagram registry.
60
+ *
61
+ * Module-level singleton — shared across Astro islands because Vite
62
+ * de-duplicates module imports per page (both in dev HMR and in prod
63
+ * via shared chunks). React Context cannot bridge separate islands;
64
+ * a plain singleton can.
65
+ *
66
+ * Subscribed via useSyncExternalStore from <DiagramPauseAll>.
67
+ */
68
+ interface RegistryEntry {
69
+ id: string;
70
+ toggle: () => void;
71
+ }
72
+ declare class DiagramRegistry {
73
+ private entries;
74
+ private listeners;
75
+ /** Bumped on every membership change — useSyncExternalStore snapshot key. */
76
+ private version;
77
+ register(entry: RegistryEntry): () => void;
78
+ toggleAll(): void;
79
+ count: () => number;
80
+ getVersion: () => number;
81
+ subscribe: (listener: () => void) => (() => void);
82
+ private notify;
83
+ }
84
+ declare const diagramRegistry: DiagramRegistry;
85
+ //#endregion
86
+ //#region src/react/hooks/use-phase.d.ts
87
+ interface UsePhaseStepBase {
88
+ /** Stable step id; appears as `current`. */
89
+ id: string;
90
+ /** Milliseconds to hold this step before advancing. */
91
+ hold: number;
92
+ }
93
+ interface UsePhaseStep<C extends Record<string, unknown> = Record<string, never>> extends UsePhaseStepBase {
94
+ /**
95
+ * Predicate gate. When false, this step is skipped for the current cycle.
96
+ * Receives `{ cycle, current, ...context }` where `current` is the id of
97
+ * the previous step that survived the predicate pass (empty string at
98
+ * cycle start).
99
+ */
100
+ when?: (ctx: {
101
+ cycle: number;
102
+ current: string;
103
+ } & C) => boolean;
104
+ }
105
+ interface UsePhaseOptions<C extends Record<string, unknown> = Record<string, never>> {
106
+ steps: UsePhaseStep<C>[];
107
+ /** Values made available to each step's `when` predicate. */
108
+ context?: C;
109
+ /** When true (default), the sequence restarts after the last step. */
110
+ loop?: boolean;
111
+ }
112
+ interface UsePhaseReturn {
113
+ /** Id of the currently-active step. Empty string if `steps` is empty. */
114
+ current: string;
115
+ /** Index into the *filtered* sequence for the current cycle. */
116
+ index: number;
117
+ /** How many times the sequence has fully completed. Starts at 0. */
118
+ cycle: number;
119
+ /** Advance one step (or wrap to next cycle if at the end). */
120
+ advance: () => void;
121
+ /** Jump to a named step in the current cycle's sequence. */
122
+ goto: (id: string) => void;
123
+ /** Reset cycle and index to 0. */
124
+ reset: () => void;
125
+ }
126
+ /**
127
+ * Predicate-gated phase walker. Reads `playing` / `visible` / `tabVisible`
128
+ * / `reducedMotion` from the surrounding `<Diagram>` and pauses
129
+ * automatically when any gate fails.
130
+ *
131
+ * Steps may carry a `when(ctx)` predicate that filters them out for a
132
+ * given cycle. Mode toggles, branches, alternating loops — anything
133
+ * cycle-dependent — composes via the predicate plus user-supplied
134
+ * `context`.
135
+ */
136
+ declare function usePhase<C extends Record<string, unknown> = Record<string, never>>({
137
+ steps,
138
+ context,
139
+ loop
140
+ }: UsePhaseOptions<C>): UsePhaseReturn;
141
+ //#endregion
142
+ //#region src/react/hooks/use-measure.d.ts
143
+ interface UseMeasureOptions {
144
+ /**
145
+ * Additional dependencies that should re-trigger measurement when they
146
+ * change. Use when component state changes the layout in a way the
147
+ * container's ResizeObserver might miss — e.g. an animated CSS `gap`
148
+ * that grows the container only as the transition progresses, or a
149
+ * state-driven layout swap that doesn't change the container's size.
150
+ */
151
+ deps?: unknown[];
152
+ }
153
+ /**
154
+ * DOM rect + optional selector callback. The selector receives the
155
+ * observed element and its rect, and returns whatever derived geometry
156
+ * the author needs (NodeRect, EdgeData, etc.). Subsumes momito's
157
+ * `useWeldedMeasure` pattern.
158
+ *
159
+ * For multi-element measurements (e.g. measuring a container plus 5
160
+ * child nodes), pass the container ref and read the other refs from
161
+ * closure inside the selector. The selector recomputes when the
162
+ * container resizes — which it typically does when children grow
163
+ * because the container's intrinsic size is content-derived. For
164
+ * state-driven re-layouts that the ResizeObserver might miss, pass
165
+ * `options.deps`.
166
+ */
167
+ declare function useMeasure<T extends HTMLElement | SVGElement, R = DOMRectReadOnly>(ref: RefObject<T | null>, selector?: (el: T, rect: DOMRectReadOnly) => R, options?: UseMeasureOptions): {
168
+ rect: DOMRectReadOnly | null;
169
+ selected: R | null;
170
+ };
171
+ //#endregion
172
+ //#region src/react/hooks/use-tab-indicator.d.ts
173
+ interface UseTabIndicatorReturn {
174
+ /** Inline rect of the active tab, relative to the container. Null until first measure. */
175
+ style: {
176
+ top: number;
177
+ left: number;
178
+ width: number;
179
+ height: number;
180
+ } | null;
181
+ }
182
+ /**
183
+ * Headless sliding-indicator measurement for a tab group.
184
+ *
185
+ * Pure state + lifecycle — no DOM produced, no styling assumed. The
186
+ * consumer renders the indicator however it wants, applying `style`
187
+ * positionally.
188
+ *
189
+ * Re-measures on `activeId` change and on container resize. Returns
190
+ * `null` style when `activeId` is null or its tab ref isn't mounted —
191
+ * consumer renders nothing in that case, which also prevents a
192
+ * "mount-from-zero" transition the first time the indicator appears.
193
+ */
194
+ declare function useTabIndicator(containerRef: RefObject<HTMLElement | null>, getTab: (id: string) => HTMLElement | null, activeId: string | null): UseTabIndicatorReturn;
195
+ //#endregion
196
+ //#region src/react/cn.d.ts
197
+ /**
198
+ * Compose class names with Tailwind conflict resolution. Vendored into
199
+ * lab/diagram so the framework-surface files don't depend on apps/www's
200
+ * `@/lib/cn` alias — keeps the lift to `nimbus-docs/react` verbatim.
201
+ */
202
+ declare function cn(...inputs: ClassValue[]): string;
203
+ //#endregion
204
+ export { type Depth, Diagram, type DiagramContextValue, type DiagramPhase, type DiagramProps, type ReducedMotionMode, type UseMeasureOptions, type UsePhaseOptions, type UsePhaseReturn, type UsePhaseStep, type UseTabIndicatorReturn, cn, diagramRegistry, useDiagram, useDiagramOrDefault, useMeasure, usePhase, useTabIndicator };
205
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","names":[],"sources":["../src/react/diagram.tsx","../src/react/registry.ts","../src/react/hooks/use-phase.ts","../src/react/hooks/use-measure.ts","../src/react/hooks/use-tab-indicator.ts","../src/react/cn.ts"],"mappings":";;;;KAuBY,KAAA;AAAA,KACA,iBAAA;AAAA,KACA,YAAA;AAAA,UAEK,mBAAA;EAJA;EAMf,EAAA;EANe;EAQf,KAAA,EAAO,YAAA;EAPG;EASV,OAAA;;EAEA,OAAA;EAX2B;EAa3B,UAAA;EAZsB;EActB,aAAA;EAdsB;EAgBtB,KAAA,EAAO,KAAA;EAdQ;EAgBf,KAAA;IAAS,EAAA;EAAA;EAdT;EAgBA,KAAA;EAdO;EAgBP,MAAA;AAAA;AAAA,iBA6Dc,UAAA,CAAA,GAAc,mBAAA;;;;;;iBAwBd,mBAAA,CAAoB,QAAA,WAAmB,mBAAA;AAAA,UAkCtC,YAAA;EACf,QAAA,EAAU,SAAA;EACV,QAAA;EACA,kBAAA;EACA,aAAA,GAAgB,iBAAA;;EAEhB,SAAA;EAhE+C;EAkE/C,aAAA;EA1CiC;EA4CjC,QAAA;EA5CkC;EA8ClC,KAAA;EACA,SAAA;AAAA;AAAA,iBA0FO,WAAA,CAAY,KAAA,EAAO,YAAA;AAAA,cAuMf,OAAA,SAAO,WAAA;;;;;;;AA7bpB;;;;;AACA;UCbU,aAAA;EACR,EAAA;EACA,MAAA;AAAA;AAAA,cAGI,eAAA;EAAA,QACI,OAAA;EAAA,QACA,SAAA;EDOc;EAAA,QCLd,OAAA;EAER,QAAA,CAAS,KAAA,EAAO,aAAA;EAWhB,SAAA,CAAA;EAOA,KAAA;EAEA,UAAA;EAEA,SAAA,GAAa,QAAA;EAAA,QAOL,MAAA;AAAA;AAAA,cAKG,eAAA,EAAe,eAAA;;;UCnDX,gBAAA;;EAEf,EAAA;;EAEA,IAAA;AAAA;AAAA,UAGe,YAAA,WAAuB,MAAA,oBAA0B,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