@docentjs/dom 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.
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/index.cjs +1274 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +293 -0
- package/dist/index.d.ts +293 -0
- package/dist/index.js +1238 -0
- package/dist/index.js.map +1 -0
- package/dist/themes.cjs +45 -0
- package/dist/themes.cjs.map +1 -0
- package/dist/themes.d.cts +11 -0
- package/dist/themes.d.ts +11 -0
- package/dist/themes.js +40 -0
- package/dist/themes.js.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Alignment, ControllerOptions, Labels, Media, Placement, RenderContext, Renderer, Side, StorageAdapter, Target, TargetSpec, Theme, Tour, TourController, defineTour } from "@docentjs/core";
|
|
2
|
+
//#region src/content.d.ts
|
|
3
|
+
export declare function isSafeUrl(url: string): boolean;
|
|
4
|
+
export declare function renderBody(doc: Document, body: string, format?: 'text' | 'markdown'): DocumentFragment;
|
|
5
|
+
export declare function renderMedia(doc: Document, media: Media): HTMLElement | null;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/theme.d.ts
|
|
8
|
+
/** Token → CSS custom property (without the `--docent-` prefix). */
|
|
9
|
+
export declare const THEME_VARS: Record<keyof Theme, string>;
|
|
10
|
+
/** Write theme tokens as inline custom properties on an element. Clears unset ones. */
|
|
11
|
+
export declare function applyTheme(el: HTMLElement, theme: Theme | undefined): void;
|
|
12
|
+
export declare function mergeThemes(...themes: Array<Theme | undefined>): Theme;
|
|
13
|
+
/**
|
|
14
|
+
* Regions of the built-in popover that can be replaced. Custom content is
|
|
15
|
+
* projected through native Shadow DOM slots, so it lives in the page's DOM
|
|
16
|
+
* and keeps the page's CSS and framework behaviour.
|
|
17
|
+
*/
|
|
18
|
+
type SlotName = 'header' | 'title' | 'close' | 'body' | 'media' | 'footer' | 'progress' | 'buttons';
|
|
19
|
+
/**
|
|
20
|
+
* What a slot renderer returns:
|
|
21
|
+
* - a `Node` replaces the region,
|
|
22
|
+
* - a string replaces it with text,
|
|
23
|
+
* - `null` removes the region,
|
|
24
|
+
* - `undefined` keeps the default.
|
|
25
|
+
*/
|
|
26
|
+
type SlotContent = Node | string | null | undefined;
|
|
27
|
+
type SlotRenderer = (ctx: RenderContext, doc: Document) => SlotContent;
|
|
28
|
+
type PopoverSlots = Partial<Record<SlotName, SlotRenderer>>;
|
|
29
|
+
/**
|
|
30
|
+
* A named bundle of theme, slots and CSS. Tours pick one by name through
|
|
31
|
+
* `options.template`, which keeps the JSON builder-friendly while the code
|
|
32
|
+
* that defines the template stays in the app.
|
|
33
|
+
*/
|
|
34
|
+
interface PopoverTemplate {
|
|
35
|
+
theme?: Theme;
|
|
36
|
+
slots?: PopoverSlots;
|
|
37
|
+
/** Extra CSS injected into the shadow root while this template is active. */
|
|
38
|
+
css?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Replace the whole popover. The renderer still draws the overlay and
|
|
42
|
+
* spotlight, positions `container`, sets `data-side` and `--docent-arrow`
|
|
43
|
+
* on it, and handles keyboard, focus and state. You draw everything inside.
|
|
44
|
+
*/
|
|
45
|
+
interface HeadlessPopover {
|
|
46
|
+
/** Render the step into `container`. Return a cleanup to run before the next step. */
|
|
47
|
+
render(ctx: RenderContext, container: HTMLElement): undefined | (() => void);
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/renderer.d.ts
|
|
51
|
+
interface DomRendererOptions {
|
|
52
|
+
/** Document to render into. Defaults to the global document. */
|
|
53
|
+
document?: Document;
|
|
54
|
+
/** Override button and progress labels for every tour. */
|
|
55
|
+
labels?: Labels;
|
|
56
|
+
/** Distance between target and popover, in px. */
|
|
57
|
+
gap?: number;
|
|
58
|
+
/** Spotlight defaults when a tour sets none. */
|
|
59
|
+
spotlight?: {
|
|
60
|
+
padding?: number;
|
|
61
|
+
radius?: number;
|
|
62
|
+
};
|
|
63
|
+
/** Base theme tokens. Tours and templates layer on top. */
|
|
64
|
+
theme?: Theme;
|
|
65
|
+
/** Replace regions of the built-in popover. */
|
|
66
|
+
slots?: PopoverSlots;
|
|
67
|
+
/** Named templates that tours select with `options.template`. */
|
|
68
|
+
templates?: Record<string, PopoverTemplate>;
|
|
69
|
+
/** Template to use when a tour names none. */
|
|
70
|
+
template?: string;
|
|
71
|
+
/** Bring your own popover. Overlay, spotlight, positioning and keys stay. */
|
|
72
|
+
headless?: HeadlessPopover;
|
|
73
|
+
/** Extra CSS injected into the shadow root. */
|
|
74
|
+
css?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Below this viewport width the popover docks to the bottom edge as a sheet
|
|
77
|
+
* instead of floating beside the target. Default 480; 0 disables.
|
|
78
|
+
*/
|
|
79
|
+
sheetBreakpoint?: number;
|
|
80
|
+
/** Scroll past sticky/fixed headers and footers that cover the target. Default true. */
|
|
81
|
+
avoidOcclusion?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export declare class DomRenderer implements Renderer {
|
|
84
|
+
private readonly doc;
|
|
85
|
+
private readonly options;
|
|
86
|
+
private host;
|
|
87
|
+
private shadow;
|
|
88
|
+
private overlay;
|
|
89
|
+
private templateStyle;
|
|
90
|
+
private popover;
|
|
91
|
+
private arrow;
|
|
92
|
+
private headlessContainer;
|
|
93
|
+
private ctx;
|
|
94
|
+
private target;
|
|
95
|
+
private cleanups;
|
|
96
|
+
private frame;
|
|
97
|
+
private previousFocus;
|
|
98
|
+
/** Set once per step after the sheet has scrolled the target clear. */
|
|
99
|
+
private sheetAdjusted;
|
|
100
|
+
constructor(options?: DomRendererOptions);
|
|
101
|
+
hasTarget(target: Target): boolean;
|
|
102
|
+
waitForTarget(target: Target, timeoutMs: number, signal: AbortSignal): Promise<boolean>;
|
|
103
|
+
currentRoute(): string;
|
|
104
|
+
show(ctx: RenderContext): void;
|
|
105
|
+
hide(): void;
|
|
106
|
+
/** Re-measure and re-position everything. Safe to call often. */
|
|
107
|
+
update(): void;
|
|
108
|
+
/**
|
|
109
|
+
* The visible area in layout-viewport coordinates. Uses the visual viewport
|
|
110
|
+
* so pinch zoom, the on-screen keyboard and pages that overflow on mobile
|
|
111
|
+
* (where `innerWidth` grows past the screen) all position correctly.
|
|
112
|
+
*/
|
|
113
|
+
private viewport;
|
|
114
|
+
private isSheet;
|
|
115
|
+
/** In sheet mode, scroll once so the target is not hidden behind the sheet. */
|
|
116
|
+
private keepClearOfSheet;
|
|
117
|
+
/** Run after a smooth scroll settles (scrollend, or a short fallback), or right away. */
|
|
118
|
+
private afterScroll;
|
|
119
|
+
private template;
|
|
120
|
+
private buildDefault;
|
|
121
|
+
private buildHeadless;
|
|
122
|
+
private setTemplateCss;
|
|
123
|
+
private mount;
|
|
124
|
+
private teardownStep;
|
|
125
|
+
private blocksInteraction;
|
|
126
|
+
/** Returns true when a smooth scroll was started (callers must wait for it to settle). */
|
|
127
|
+
private scrollIntoView;
|
|
128
|
+
private scheduleUpdate;
|
|
129
|
+
private listen;
|
|
130
|
+
private onKeydown;
|
|
131
|
+
/** Keep Tab cycling inside the popover when focus is already in it. */
|
|
132
|
+
private trapTab;
|
|
133
|
+
private wireAdvance;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/create.d.ts
|
|
137
|
+
interface CreateTourOptions extends Omit<ControllerOptions, 'tour' | 'renderer'> {
|
|
138
|
+
renderer?: DomRendererOptions;
|
|
139
|
+
/** Follow browser navigation to pause and resume route-bound steps. Default true. */
|
|
140
|
+
followRoutes?: boolean;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A controller pre-wired for the browser: DOM renderer, localStorage
|
|
144
|
+
* persistence and route change tracking.
|
|
145
|
+
*/
|
|
146
|
+
export declare class DomTourController extends TourController {
|
|
147
|
+
private readonly cleanups;
|
|
148
|
+
constructor(tour: Tour, options?: CreateTourOptions);
|
|
149
|
+
destroy(): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
/** Create a browser-ready tour. Call `.start()` or `.resume()` on the result. */
|
|
152
|
+
export declare function createTour(tour: Tour, options?: CreateTourOptions): DomTourController;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/position.d.ts
|
|
155
|
+
interface Rect {
|
|
156
|
+
x: number;
|
|
157
|
+
y: number;
|
|
158
|
+
width: number;
|
|
159
|
+
height: number;
|
|
160
|
+
}
|
|
161
|
+
interface Size {
|
|
162
|
+
width: number;
|
|
163
|
+
height: number;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The visible area, in the same coordinate space as the anchor. `x`/`y` are
|
|
167
|
+
* the visual viewport's offset within the layout viewport (non-zero when the
|
|
168
|
+
* page is pinch-zoomed or overflows horizontally on mobile).
|
|
169
|
+
*/
|
|
170
|
+
interface Viewport extends Size {
|
|
171
|
+
x?: number;
|
|
172
|
+
y?: number;
|
|
173
|
+
}
|
|
174
|
+
interface PositionInput {
|
|
175
|
+
/** The spotlighted area, in viewport coordinates. */
|
|
176
|
+
anchor: Rect;
|
|
177
|
+
floating: Size;
|
|
178
|
+
viewport: Viewport;
|
|
179
|
+
placement: Placement;
|
|
180
|
+
/** Distance between anchor and popover. */
|
|
181
|
+
gap?: number;
|
|
182
|
+
/** Minimum distance from the viewport edges. */
|
|
183
|
+
edgePadding?: number;
|
|
184
|
+
/** Arrow size; keeps the arrow clear of the popover corners. */
|
|
185
|
+
arrowSize?: number;
|
|
186
|
+
}
|
|
187
|
+
interface PositionResult {
|
|
188
|
+
x: number;
|
|
189
|
+
y: number;
|
|
190
|
+
side: Side;
|
|
191
|
+
align: Alignment;
|
|
192
|
+
/** Arrow offset along the popover's cross axis, from its top-left corner. */
|
|
193
|
+
arrow: number;
|
|
194
|
+
}
|
|
195
|
+
export declare function parsePlacement(placement: Placement): {
|
|
196
|
+
side: Side | 'auto';
|
|
197
|
+
align: Alignment;
|
|
198
|
+
};
|
|
199
|
+
/** Free space between the anchor and the viewport edge on each side. */
|
|
200
|
+
export declare function availableSpace(anchor: Rect, viewport: Viewport): Record<Side, number>;
|
|
201
|
+
export declare function computePosition(input: PositionInput): PositionResult;
|
|
202
|
+
/** Centre a popover in the viewport, for steps without a target. */
|
|
203
|
+
export declare function centerPosition(floating: Size, viewport: Viewport): {
|
|
204
|
+
x: number;
|
|
205
|
+
y: number;
|
|
206
|
+
};
|
|
207
|
+
/** Grow a rect on every side. */
|
|
208
|
+
export declare function inflate(rect: Rect, by: number): Rect;
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/occlusion.d.ts
|
|
211
|
+
interface Occluder {
|
|
212
|
+
el: Element;
|
|
213
|
+
rect: DOMRect;
|
|
214
|
+
/** Which edge of the target it covers. */
|
|
215
|
+
edge: 'top' | 'bottom';
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Find a pinned element covering the target's top or bottom edge.
|
|
219
|
+
* `ignore` is our own host, which sits above everything.
|
|
220
|
+
*/
|
|
221
|
+
export declare function findOccluder(target: Element, ignore: Element | null, viewport: Viewport): Occluder | null;
|
|
222
|
+
/**
|
|
223
|
+
* Scroll so nothing pinned covers the target. Returns true if it scrolled.
|
|
224
|
+
* Runs at most twice to handle a header and a footer together.
|
|
225
|
+
*/
|
|
226
|
+
export declare function uncover(target: Element, ignore: Element | null, viewport: Viewport, margin?: number): boolean;
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/overlay.d.ts
|
|
229
|
+
export declare function holePath(viewport: Size, hole: Rect, radius: number): string;
|
|
230
|
+
interface OverlayUpdate {
|
|
231
|
+
/** Target rect in viewport coordinates, or `null` for a modal step. */
|
|
232
|
+
target: Rect | null;
|
|
233
|
+
padding: number;
|
|
234
|
+
radius: number;
|
|
235
|
+
}
|
|
236
|
+
export declare class Overlay {
|
|
237
|
+
readonly el: HTMLDivElement;
|
|
238
|
+
readonly blocker: HTMLDivElement;
|
|
239
|
+
private lastHole;
|
|
240
|
+
constructor(doc: Document);
|
|
241
|
+
/** Current hole, padded, in viewport coordinates. */
|
|
242
|
+
get hole(): Rect | null;
|
|
243
|
+
update(viewport: Size, { target, padding, radius }: OverlayUpdate, block: boolean): void;
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/popover.d.ts
|
|
247
|
+
export declare const DEFAULT_LABELS: Required<Labels>;
|
|
248
|
+
interface PopoverParts {
|
|
249
|
+
el: HTMLDivElement;
|
|
250
|
+
arrow: HTMLDivElement;
|
|
251
|
+
/** Element to focus when the step opens. */
|
|
252
|
+
initialFocus: HTMLElement;
|
|
253
|
+
/** Light-DOM nodes to append to the shadow host so they project into slots. */
|
|
254
|
+
slotted: Element[];
|
|
255
|
+
}
|
|
256
|
+
export declare function formatProgress(template: string, current: number, total: number): string;
|
|
257
|
+
/**
|
|
258
|
+
* Resolve slot overrides into light-DOM elements carrying `slot="<name>"`.
|
|
259
|
+
* A `null` result projects an empty element, which suppresses the fallback.
|
|
260
|
+
*/
|
|
261
|
+
export declare function resolveSlots(doc: Document, slots: PopoverSlots, ctx: RenderContext): Element[];
|
|
262
|
+
export declare function buildPopover(doc: Document, ctx: RenderContext, labels?: Labels, slots?: PopoverSlots): PopoverParts;
|
|
263
|
+
/** Wrapper used in headless mode: a positioned shell that projects the app's own popover. */
|
|
264
|
+
export declare function buildHeadlessShell(doc: Document): {
|
|
265
|
+
el: HTMLDivElement;
|
|
266
|
+
arrow: HTMLDivElement;
|
|
267
|
+
};
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/storage.d.ts
|
|
270
|
+
/**
|
|
271
|
+
* `localStorage`-backed adapter. Falls back to memory when storage is
|
|
272
|
+
* unavailable (private mode, blocked cookies, SSR).
|
|
273
|
+
*/
|
|
274
|
+
export declare function createLocalStorage(storage?: Storage): StorageAdapter;
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/target.d.ts
|
|
277
|
+
type QueryRoot = Document | DocumentFragment | Element;
|
|
278
|
+
/** Attribute that `{ name }` targets resolve through. */
|
|
279
|
+
export declare const NAME_ATTRIBUTE = "data-docent";
|
|
280
|
+
export declare function toSpec(target: Target): TargetSpec;
|
|
281
|
+
/** Selectors to try, in order, for a target. */
|
|
282
|
+
export declare function candidateSelectors(target: Target): string[];
|
|
283
|
+
/** Query the root, then every open shadow root beneath it. */
|
|
284
|
+
export declare function queryAllDeep(root: QueryRoot, selector: string): Element[];
|
|
285
|
+
export declare function resolveTarget(target: Target, root?: QueryRoot): Element | null;
|
|
286
|
+
/**
|
|
287
|
+
* Resolve now, or watch the DOM until the target appears, the timeout passes,
|
|
288
|
+
* or the signal aborts. Resolves `null` when it never shows up.
|
|
289
|
+
*/
|
|
290
|
+
export declare function waitForTarget(target: Target, timeoutMs: number, signal?: AbortSignal, root?: QueryRoot): Promise<Element | null>;
|
|
291
|
+
//#endregion
|
|
292
|
+
export { type CreateTourOptions, type DomRendererOptions, type HeadlessPopover, type Occluder, type PopoverSlots, type PopoverTemplate, type PositionInput, type PositionResult, type QueryRoot, type Rect, type Size, type SlotContent, type SlotName, type SlotRenderer, defineTour };
|
|
293
|
+
//# sourceMappingURL=index.d.ts.map
|