@inkbar/core 0.5.0 → 0.6.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 +73 -1
- package/dist/dom.d.mts +477 -41
- package/dist/dom.d.mts.map +1 -1
- package/dist/dom.mjs +1338 -259
- package/dist/dom.mjs.map +1 -1
- package/dist/index.d.mts +16 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +181 -25
- package/dist/index.mjs.map +1 -1
- package/dist/{signatures-BwaXi7C8.d.mts → signatures-By4B40DP.d.mts} +86 -4
- package/dist/signatures-By4B40DP.d.mts.map +1 -0
- package/dist/{signatures-CMapTKrC.mjs → signatures-D68fuLlt.mjs} +268 -50
- package/dist/signatures-D68fuLlt.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/signatures-BwaXi7C8.d.mts.map +0 -1
- package/dist/signatures-CMapTKrC.mjs.map +0 -1
package/dist/dom.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as OpenOptions, E as InkStatus,
|
|
1
|
+
import { B as PluginHistory, D as OpenOptions, E as InkStatus, Et as FreeTextAnnotation, Gt as NoteAnnotation, M as InkError, Rt as LineEnding, T as InkDocument, U as AnnotationEdit, W as AnnotationStore, X as RecordChange, Y as RecordBase, Z as RecordStore, _ as StyleGroup, _n as PdfAssets, _t as AnnotationInput, a as SignatureStore, b as ToolStyle, bn as Quad, cn as TextMarkupAnnotation, dt as cssVariableDefaults, g as ScopedToolStyle, hn as PageInfo, i as SignatureOptions, j as DocumentSource, m as CurrentStyle, mt as Annotation, o as SignatureTemplate, r as SignatureLibrary, un as Readable, ut as AnnotationDefaults, v as StyleKey, vn as Matrix, xn as Rect, xt as AnnotationType, y as StyleProps, yn as Point } from "./signatures-By4B40DP.mjs";
|
|
2
2
|
import { IconNode } from "@inkbar/icons";
|
|
3
3
|
//#region src/dom/transform.d.ts
|
|
4
4
|
type ViewRotation = 0 | 90 | 180 | 270;
|
|
@@ -136,7 +136,9 @@ interface Viewport {
|
|
|
136
136
|
behavior?: ScrollBehavior;
|
|
137
137
|
}): void;
|
|
138
138
|
/** Scrolls so `rect` (user space on `page`) is visible, centring it when it was not. */
|
|
139
|
-
scrollToRect(page: number, rect: Rect
|
|
139
|
+
scrollToRect(page: number, rect: Rect, opts?: {
|
|
140
|
+
behavior?: ScrollBehavior;
|
|
141
|
+
}): void;
|
|
140
142
|
transformFor(page: number): PageTransform;
|
|
141
143
|
hostFor(page: number): HTMLElement | undefined;
|
|
142
144
|
/** The mounted page under a viewport (client) point, if any. */
|
|
@@ -298,43 +300,184 @@ export declare function createOverlay(opts: OverlayOptions): Overlay;
|
|
|
298
300
|
*/
|
|
299
301
|
export declare function renderAnnotationContent(el: HTMLElement, a: Annotation, t: PageTransform): void;
|
|
300
302
|
//#endregion
|
|
301
|
-
//#region src/dom/
|
|
302
|
-
interface
|
|
303
|
-
|
|
304
|
-
/**
|
|
303
|
+
//#region src/dom/plugins/api/command.d.ts
|
|
304
|
+
interface CommandOptions {
|
|
305
|
+
icon?: IconNode;
|
|
306
|
+
/** Default: a document is open and ready. */
|
|
307
|
+
enabled?: Readable<boolean>;
|
|
308
|
+
/** The status after a failure. Default: "Something went wrong." */
|
|
309
|
+
errorStatus?: string;
|
|
310
|
+
}
|
|
311
|
+
type CommandRun = (run: {
|
|
312
|
+
/** The document open when the command started. */
|
|
313
|
+
doc: InkDocument;
|
|
314
|
+
/** Aborts when that document closes or another opens. */
|
|
315
|
+
signal: AbortSignal;
|
|
316
|
+
}) => string | void | Promise<string | void>;
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/dom/plugins/api/links.d.ts
|
|
319
|
+
/** What `add` takes for annotations of type `K`. */
|
|
320
|
+
type AnnotationInputOf<K extends AnnotationType> = AnnotationInput extends (infer I) ? I extends {
|
|
321
|
+
type: infer U;
|
|
322
|
+
} ? K extends U ? I & {
|
|
323
|
+
type: K;
|
|
324
|
+
} : never : never : never;
|
|
325
|
+
type OmitEach<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
326
|
+
interface AnnotationLinkSpec<T extends RecordBase, K extends AnnotationType> {
|
|
327
|
+
/** The annotation's fields for `record`. Without a colour it gets the type's default. */
|
|
328
|
+
from(record: T): OmitEach<AnnotationInputOf<K>, 'type' | 'color'> & {
|
|
329
|
+
color?: string;
|
|
330
|
+
};
|
|
331
|
+
/** Runs once per linked annotation the user removes, inside that edit's undo step. */
|
|
332
|
+
onRemoved?(record: T, annotation: Annotation): void;
|
|
333
|
+
/** Runs for each user update of a linked annotation, inside that edit's undo step. */
|
|
334
|
+
onChanged?(record: T, annotation: Annotation): void;
|
|
335
|
+
}
|
|
336
|
+
interface AnnotationLink<T extends RecordBase> {
|
|
337
|
+
/** Adds an annotation made from `record` and linked to it; `undefined` with no document open. */
|
|
338
|
+
add(record: T): Annotation | undefined;
|
|
339
|
+
/** The annotations of this link's type linked to `record`, in document order. */
|
|
340
|
+
of(record: T): Annotation[];
|
|
341
|
+
}
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/dom/plugins/api/records.d.ts
|
|
344
|
+
interface Records<T extends RecordBase> {
|
|
345
|
+
/** The open document's records; `[]` while none is open. Emits when the document changes. */
|
|
346
|
+
readonly list: Readable<readonly T[]>;
|
|
347
|
+
all(): readonly T[];
|
|
348
|
+
find(id: string): T | undefined;
|
|
349
|
+
has(id: string): boolean;
|
|
350
|
+
/** Records whose fields equal (===) every field of `match`, or that pass it. */
|
|
351
|
+
where(match: Partial<T> | ((record: T) => boolean)): T[];
|
|
352
|
+
/**
|
|
353
|
+
* Returns the stored record, or `undefined` with no document open. Throws
|
|
354
|
+
* `InkError('DuplicateId')` when the id is taken; `addMissing` skips taken ids.
|
|
355
|
+
*
|
|
356
|
+
* Every write is one undo step, and `plugin.batch` makes several one step. A write after an
|
|
357
|
+
* `await` goes to whatever document is open then: inside a command, write through `in(doc)`.
|
|
358
|
+
*/
|
|
359
|
+
add(record: T): T | undefined;
|
|
360
|
+
/** Adds the records whose ids are not present yet, in one undo step; returns those added. */
|
|
361
|
+
addMissing(records: readonly T[]): T[];
|
|
362
|
+
update(id: string, patch: Partial<Omit<T, 'id'>>): T | undefined;
|
|
363
|
+
remove(id: string): T | undefined;
|
|
364
|
+
/**
|
|
365
|
+
* The same handle bound to `doc`'s store, as it is when called. Empty and inert once `doc`
|
|
366
|
+
* closes, and from the start when `doc` is not the open document.
|
|
367
|
+
*/
|
|
368
|
+
in(doc: InkDocument): Records<T>;
|
|
369
|
+
/** The underlying store, or null; for anything the handle lacks. */
|
|
370
|
+
store(): RecordStore<T> | null;
|
|
371
|
+
/**
|
|
372
|
+
* Links these records to the `type` annotations made from them, as
|
|
373
|
+
* `custom.<plugin>.<records name> = <record id>`. A record may have several. Each call listens
|
|
374
|
+
* for annotation edits for the viewer's lifetime: call it in `setup`.
|
|
375
|
+
*/
|
|
376
|
+
annotates<K extends AnnotationType>(type: K, spec: AnnotationLinkSpec<T, K>): AnnotationLink<T>;
|
|
377
|
+
}
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/dom/plugins/api/card.d.ts
|
|
380
|
+
/** What a mark's card shows. The theme styles it; `className` adds a class of your own. */
|
|
381
|
+
interface CardSpec {
|
|
382
|
+
/** The card's heading (`.ink-card-title`). */
|
|
383
|
+
title: string;
|
|
384
|
+
/** The dialog's accessible name. Default: `title`. */
|
|
385
|
+
label?: string;
|
|
386
|
+
/** A short line under the title (`.ink-card-meta`). */
|
|
387
|
+
meta?: string;
|
|
388
|
+
/** A CSS colour for a dot before `meta` (`.ink-card-swatch`). */
|
|
389
|
+
swatch?: string;
|
|
390
|
+
/** Text under the meta line (`.ink-card-body`). */
|
|
391
|
+
body?: string;
|
|
392
|
+
/**
|
|
393
|
+
* One button per key, in order (`.ink-card-actions`). The first takes focus on open and is
|
|
394
|
+
* styled as the primary action. Each action runs synchronously in one undo step: writes after
|
|
395
|
+
* an `await` fall outside it. When an action removes the mark, focus moves to the next of this
|
|
396
|
+
* `marks()` handle's marks, else the previous, else the viewport.
|
|
397
|
+
*/
|
|
398
|
+
actions: Record<string, () => void>;
|
|
399
|
+
/** Classes added to the card. */
|
|
400
|
+
className?: string;
|
|
401
|
+
}
|
|
402
|
+
//#endregion
|
|
403
|
+
//#region src/dom/plugins/api/marks.d.ts
|
|
404
|
+
interface MarksOptions<T extends RecordBase & {
|
|
305
405
|
page: number;
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
decorate?: DecorateAnnotation;
|
|
314
|
-
/** Defaults to `window.devicePixelRatio`. */
|
|
315
|
-
devicePixelRatio?: number;
|
|
406
|
+
}> {
|
|
407
|
+
/** Where the record's mark goes on its page, in user space. */
|
|
408
|
+
rect(record: T): Rect;
|
|
409
|
+
/** The mark's accessible name. */
|
|
410
|
+
label(record: T): string;
|
|
411
|
+
/** Only records that pass get a mark. Default: all. */
|
|
412
|
+
where?(record: T): boolean;
|
|
316
413
|
/**
|
|
317
|
-
*
|
|
318
|
-
*
|
|
414
|
+
* Inline style for the mark, camel-case properties and `--custom` properties alike. Core draws
|
|
415
|
+
* nothing else: the look is the plugin's CSS.
|
|
319
416
|
*/
|
|
320
|
-
|
|
417
|
+
style?(record: T): Partial<CSSStyleDeclaration> & {
|
|
418
|
+
[property: `--${string}`]: string;
|
|
419
|
+
};
|
|
420
|
+
/** Classes every mark gets. */
|
|
421
|
+
className?: string;
|
|
321
422
|
/**
|
|
322
|
-
*
|
|
323
|
-
*
|
|
423
|
+
* More attributes (`data-*`, `aria-*`). `data-record`, `data-plugin` and `aria-label` stay
|
|
424
|
+
* core's, and so do `aria-haspopup` and `aria-expanded` on a mark with a card; `style`,
|
|
425
|
+
* `class` and `type` are skipped (use `style` and `className`).
|
|
324
426
|
*/
|
|
325
|
-
|
|
427
|
+
attrs?(record: T): Record<string, string>;
|
|
428
|
+
/**
|
|
429
|
+
* The card a mark opens when activated: a popover next to it, styled by the theme. Each
|
|
430
|
+
* action is one undo step. The mark gets `aria-haspopup="dialog"`, and `aria-expanded` true
|
|
431
|
+
* while its card is open.
|
|
432
|
+
*/
|
|
433
|
+
card?(record: T): CardSpec;
|
|
434
|
+
/** Runs when the mark is clicked, or activated with Enter or Space, after `card` opens. */
|
|
435
|
+
onActivate?(record: T, mark: HTMLButtonElement): void;
|
|
326
436
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
437
|
+
interface MarksHandle {
|
|
438
|
+
/** Redraws every mark, for marks that read state outside the records. */
|
|
439
|
+
refresh(): void;
|
|
440
|
+
/**
|
|
441
|
+
* From now on, when records start to get a mark (added, or changed to pass `where`), the
|
|
442
|
+
* viewer scrolls to the first of them in reading order, unless it is in view already. Records
|
|
443
|
+
* a document opens with, and undo and redo, never scroll. Focus stays where it is. Returns
|
|
444
|
+
* the handle.
|
|
445
|
+
*/
|
|
446
|
+
scrollToFirst(): MarksHandle;
|
|
447
|
+
}
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/dom/plugins/api/api.d.ts
|
|
450
|
+
interface PluginOptions {
|
|
451
|
+
/** Store options by records name; `plugin.records(name)` picks them up. */
|
|
452
|
+
records?: Record<string, PluginStoreOptions<any>>;
|
|
453
|
+
}
|
|
454
|
+
interface PluginApi extends PluginContext {
|
|
455
|
+
/**
|
|
456
|
+
* A handle on the store `<plugin>.<name>` that follows the open document. Its options are
|
|
457
|
+
* `opts` when given, else the host's `options.records[name]`. Call it once per name in
|
|
458
|
+
* setup and keep the handle: a second call for the same name throws `InkError('DuplicateId')`.
|
|
459
|
+
*/
|
|
460
|
+
records<T extends RecordBase>(name: string, opts?: PluginStoreOptions<T>): Records<T>;
|
|
461
|
+
/** Makes everything `fn` changes one undo step: `history.batch`. */
|
|
462
|
+
batch(fn: () => void): void;
|
|
463
|
+
/**
|
|
464
|
+
* Registers `<plugin>.<id>`. `run` gets the document open when it started and a signal that
|
|
465
|
+
* aborts when that document closes or another opens. A returned string becomes the command's
|
|
466
|
+
* status and `undefined` clears it; a failure is logged once and sets `errorStatus` (default
|
|
467
|
+
* "Something went wrong."). The status clears when the document changes.
|
|
468
|
+
*
|
|
469
|
+
* Inside a command, write through `records.in(doc)`.
|
|
470
|
+
*/
|
|
471
|
+
command(id: string, label: string, run: CommandRun, opts?: CommandOptions): Command;
|
|
472
|
+
/**
|
|
473
|
+
* Draws a `<button>` for each record that passes `where`, on page `record.page` at
|
|
474
|
+
* `rect(record)`, in a layer of its own. The marks redraw when the records change; call
|
|
475
|
+
* `refresh()` when they read state of your own that changed.
|
|
476
|
+
*/
|
|
477
|
+
marks<T extends RecordBase & {
|
|
478
|
+
page: number;
|
|
479
|
+
}>(records: Records<T>, opts: MarksOptions<T>): MarksHandle;
|
|
335
480
|
}
|
|
336
|
-
/** Canvas, text layer and annotation overlay for one page, stacked in that order. */
|
|
337
|
-
export declare function createPageMount(opts: PageMountOptions): PageMount;
|
|
338
481
|
//#endregion
|
|
339
482
|
//#region src/dom/tools/options.d.ts
|
|
340
483
|
interface ToolOptions {
|
|
@@ -395,6 +538,10 @@ interface ToolContext {
|
|
|
395
538
|
}
|
|
396
539
|
interface Tool<O extends object = object> {
|
|
397
540
|
id: ToolId;
|
|
541
|
+
/** The accessible name a toolbar button shows for a tool core has no label for. */
|
|
542
|
+
label?: string;
|
|
543
|
+
/** The icon a toolbar button shows for a tool core has no icon for. */
|
|
544
|
+
icon?: IconNode;
|
|
398
545
|
/** Default sticky. */
|
|
399
546
|
kind?: ToolKind;
|
|
400
547
|
cursor: string;
|
|
@@ -455,6 +602,261 @@ export declare function hitFor(ctx: ToolContext, e: {
|
|
|
455
602
|
clientY: number;
|
|
456
603
|
}): PageHit | undefined;
|
|
457
604
|
//#endregion
|
|
605
|
+
//#region src/dom/plugins/define.d.ts
|
|
606
|
+
interface InkPlugin {
|
|
607
|
+
/** Lower-case kebab (/^[a-z][a-z0-9-]*$/); the namespace for everything the plugin adds. */
|
|
608
|
+
readonly id: string;
|
|
609
|
+
/** Runs once per viewer. The returned function runs when the viewer is destroyed. */
|
|
610
|
+
setup(ctx: PluginContext): void | (() => void);
|
|
611
|
+
}
|
|
612
|
+
interface CommandSpec {
|
|
613
|
+
/** Namespaced to `<plugin>.<id>`. */
|
|
614
|
+
id: string;
|
|
615
|
+
/** Names the command's button; must not be empty (`InkError('InvalidCommandLabel')`). */
|
|
616
|
+
label: string;
|
|
617
|
+
icon?: IconNode;
|
|
618
|
+
/** Default: a document is open and ready. */
|
|
619
|
+
enabled?: Readable<boolean>;
|
|
620
|
+
/** A short progress or result message, announced in a live region by the command button. */
|
|
621
|
+
status?: Readable<string>;
|
|
622
|
+
/** May be async: the command is busy until the promise settles. */
|
|
623
|
+
run(): void | Promise<void>;
|
|
624
|
+
}
|
|
625
|
+
interface Command {
|
|
626
|
+
/** `<plugin>.<spec id>`. */
|
|
627
|
+
readonly id: string;
|
|
628
|
+
readonly label: string;
|
|
629
|
+
readonly icon: IconNode | undefined;
|
|
630
|
+
/** The spec's `enabled` (or a ready document), and not busy. */
|
|
631
|
+
readonly enabled: Readable<boolean>;
|
|
632
|
+
/** True while the promise `run` returned is pending. */
|
|
633
|
+
readonly busy: Readable<boolean>;
|
|
634
|
+
/** The spec's status, or `''` without one. */
|
|
635
|
+
readonly status: Readable<string>;
|
|
636
|
+
/**
|
|
637
|
+
* Does nothing while busy or disabled. Never rejects: a failure is logged, and one caused by
|
|
638
|
+
* the document closing mid-run (`DocumentDestroyed`) is dropped silently.
|
|
639
|
+
*/
|
|
640
|
+
run(): Promise<void>;
|
|
641
|
+
}
|
|
642
|
+
interface LayerSpec {
|
|
643
|
+
/** Draw into `el` for `page`. Called on mount, on every transform change and on invalidate. */
|
|
644
|
+
render(el: HTMLElement, page: number, transform: PageTransform): void;
|
|
645
|
+
/** Optional teardown when the page unmounts. */
|
|
646
|
+
destroy?(el: HTMLElement, page: number): void;
|
|
647
|
+
}
|
|
648
|
+
interface PluginLayerHandle {
|
|
649
|
+
/** Redraws `page`, or every mounted page without one. */
|
|
650
|
+
invalidate(page?: number): void;
|
|
651
|
+
}
|
|
652
|
+
interface PluginStoreOptions<T extends RecordBase> {
|
|
653
|
+
/** The records a store starts with, called once for each document that opens. */
|
|
654
|
+
initial?: (doc: InkDocument) => readonly T[];
|
|
655
|
+
/** Called after every change with the list as it now stands. */
|
|
656
|
+
onChange?: (list: readonly T[], change: RecordChange<T>) => void;
|
|
657
|
+
}
|
|
658
|
+
interface PluginContext {
|
|
659
|
+
/** The plugin's id. */
|
|
660
|
+
readonly id: string;
|
|
661
|
+
readonly document: Readable<InkDocument | null>;
|
|
662
|
+
/**
|
|
663
|
+
* The viewer's active history. `batch` makes everything `fn` changes, annotations and plugin
|
|
664
|
+
* records alike, one undo step. Stores from `store` are tracked for you, and `onAnnotationEdit`
|
|
665
|
+
* runs inside the edit's step.
|
|
666
|
+
*/
|
|
667
|
+
readonly history: {
|
|
668
|
+
batch(fn: () => void): void;
|
|
669
|
+
};
|
|
670
|
+
/** The id of the activated annotation, or null. */
|
|
671
|
+
readonly activated: Readable<string | null>;
|
|
672
|
+
setActivated(id: string | null): void;
|
|
673
|
+
/** The viewport container, or null while none is mounted. */
|
|
674
|
+
readonly root: Readable<HTMLElement | null>;
|
|
675
|
+
commands: {
|
|
676
|
+
add(spec: CommandSpec): Command;
|
|
677
|
+
};
|
|
678
|
+
/** The tool's id becomes `<plugin>.<id>`. */
|
|
679
|
+
tools: {
|
|
680
|
+
add(tool: Tool): void;
|
|
681
|
+
};
|
|
682
|
+
/** Composed after the host's own decoration and earlier plugins'; earlier ones win per key. */
|
|
683
|
+
decorate(fn: DecorateAnnotation): void;
|
|
684
|
+
/**
|
|
685
|
+
* Runs every decoration again for the open document's annotations. Decorations re-apply when
|
|
686
|
+
* the annotations change; call this when one reads state of your own that changed instead.
|
|
687
|
+
*/
|
|
688
|
+
redecorate(): void;
|
|
689
|
+
/**
|
|
690
|
+
* A record store keyed `<plugin>.<name>`, created for each document that opens and tracked by
|
|
691
|
+
* its history; null while no document is open. Inkbar keeps no plugin data: pass `initial`
|
|
692
|
+
* and `onChange` to load and save it.
|
|
693
|
+
*/
|
|
694
|
+
store<T extends RecordBase>(name: string, opts?: PluginStoreOptions<T>): Readable<RecordStore<T> | null>;
|
|
695
|
+
/** Runs for each document that opens; the returned function runs when it closes. */
|
|
696
|
+
onDocument(fn: (doc: InkDocument) => void | (() => void)): void;
|
|
697
|
+
/**
|
|
698
|
+
* Runs for every user add, update and remove of an annotation, inside that edit's undo step,
|
|
699
|
+
* so store changes made here undo with it. Never runs for undo and redo.
|
|
700
|
+
*/
|
|
701
|
+
onAnnotationEdit(fn: (edit: AnnotationEdit) => void): void;
|
|
702
|
+
/** Adds a layer drawn on every mounted page, above the annotations. */
|
|
703
|
+
layer(spec: LayerSpec): PluginLayerHandle;
|
|
704
|
+
/**
|
|
705
|
+
* Scrolls the viewer so `rect` (user space on `page`) is in view, centring it when it was
|
|
706
|
+
* not. Moves no focus. Does nothing while no document is shown.
|
|
707
|
+
*/
|
|
708
|
+
scrollTo(page: number, rect: Rect, opts?: {
|
|
709
|
+
behavior?: ScrollBehavior;
|
|
710
|
+
}): void;
|
|
711
|
+
}
|
|
712
|
+
/** A factory's parameters: its options, optional only when `O` has no required field. */
|
|
713
|
+
type PluginFactoryArgs<O> = {} extends O ? [options?: O & PluginOptions] : [options: O & PluginOptions];
|
|
714
|
+
/**
|
|
715
|
+
* Checks the plugin's id and returns the plugin unchanged. Throws `InkError('InvalidPluginId')`
|
|
716
|
+
* for an id that is not lower-case kebab.
|
|
717
|
+
*/
|
|
718
|
+
export declare function definePlugin(plugin: InkPlugin): InkPlugin;
|
|
719
|
+
/**
|
|
720
|
+
* Checks the id now and returns a factory: `factory(options)` is a plugin whose setup receives
|
|
721
|
+
* the plugin API and those options. Each call makes an independent plugin. The options may be
|
|
722
|
+
* left out only when every field of `O` is optional.
|
|
723
|
+
*/
|
|
724
|
+
export declare function definePlugin<O extends object = object>(id: string, setup: (plugin: PluginApi, options: O & PluginOptions) => void | (() => void)): (...args: PluginFactoryArgs<O>) => InkPlugin;
|
|
725
|
+
//#endregion
|
|
726
|
+
//#region src/dom/plugins/commands.d.ts
|
|
727
|
+
/**
|
|
728
|
+
* The error for a command id no plugin registered, naming the ids that were. Bindings log it
|
|
729
|
+
* rather than throw, and show the control as it is before the plugins are set up.
|
|
730
|
+
*/
|
|
731
|
+
export declare function unknownCommand(id: string, registered: readonly string[]): InkError;
|
|
732
|
+
//#endregion
|
|
733
|
+
//#region src/dom/plugins/layer.d.ts
|
|
734
|
+
/** A layer as the host keeps it: the plugin's spec and the id of the plugin that added it. */
|
|
735
|
+
type PluginLayer = LayerSpec & {
|
|
736
|
+
readonly plugin: string;
|
|
737
|
+
};
|
|
738
|
+
/**
|
|
739
|
+
* What a layer source reports: a layer was added, or one asked to redraw.
|
|
740
|
+
*
|
|
741
|
+
* @internal For bindings, which mount plugin layers; not for plugin authors.
|
|
742
|
+
*/
|
|
743
|
+
type LayerEvent = {
|
|
744
|
+
type: 'add';
|
|
745
|
+
layer: PluginLayer;
|
|
746
|
+
} | {
|
|
747
|
+
type: 'invalidate';
|
|
748
|
+
layer: PluginLayer;
|
|
749
|
+
page?: number | undefined;
|
|
750
|
+
};
|
|
751
|
+
/**
|
|
752
|
+
* Where page layers come from: a plugin host.
|
|
753
|
+
*
|
|
754
|
+
* @internal For bindings, which mount plugin layers; not for plugin authors.
|
|
755
|
+
*/
|
|
756
|
+
interface LayerSource {
|
|
757
|
+
readonly layers: readonly PluginLayer[];
|
|
758
|
+
/** Calls `listener` for every layer added and every invalidate; returns a stop function. */
|
|
759
|
+
watchLayers(listener: (event: LayerEvent) => void): () => void;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* One page's plugin layers, made by `PluginLayers.mount`.
|
|
763
|
+
*
|
|
764
|
+
* @internal For bindings, which mount plugin layers; not for plugin authors.
|
|
765
|
+
*/
|
|
766
|
+
interface PageLayers {
|
|
767
|
+
update(transform: PageTransform): void;
|
|
768
|
+
destroy(): void;
|
|
769
|
+
}
|
|
770
|
+
/** The plugin layers of one viewer's pages; see `createPluginLayers`. */
|
|
771
|
+
interface PluginLayers {
|
|
772
|
+
mount(page: number, host: HTMLElement, transform: PageTransform): PageLayers;
|
|
773
|
+
/** Stops following the source. Pages still mounted keep their layers until they unmount. */
|
|
774
|
+
destroy(): void;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Mounts `source`'s layers on the pages the engine mounts, and follows it: a layer added later
|
|
778
|
+
* is drawn on every mounted page, and an invalidate redraws its page, or all of them.
|
|
779
|
+
*
|
|
780
|
+
* @internal For bindings, which mount plugin layers; plugin authors add a layer with
|
|
781
|
+
* `ctx.layer`.
|
|
782
|
+
*/
|
|
783
|
+
export declare function createPluginLayers(source: LayerSource): PluginLayers;
|
|
784
|
+
//#endregion
|
|
785
|
+
//#region src/dom/plugins/host.d.ts
|
|
786
|
+
interface PluginHostOptions {
|
|
787
|
+
plugins: readonly InkPlugin[];
|
|
788
|
+
document: Readable<InkDocument | null>;
|
|
789
|
+
/** The binding's active history, read when a document opens. */
|
|
790
|
+
history: () => PluginHistory;
|
|
791
|
+
activated: Readable<string | null>;
|
|
792
|
+
setActivated(id: string | null): void;
|
|
793
|
+
root: Readable<HTMLElement | null>;
|
|
794
|
+
/** The host's own decoration, read on each call. */
|
|
795
|
+
decorate?: () => DecorateAnnotation | undefined;
|
|
796
|
+
/** The viewer's viewport, read on each call; without one, `ctx.scrollTo` does nothing. */
|
|
797
|
+
viewport?: () => Viewport | null | undefined;
|
|
798
|
+
}
|
|
799
|
+
interface PluginHost extends LayerSource {
|
|
800
|
+
readonly commands: ReadonlyMap<string, Command>;
|
|
801
|
+
command(id: string): Command | undefined;
|
|
802
|
+
readonly tools: readonly Tool[];
|
|
803
|
+
/** The host's decoration first, then each plugin's in order; earlier ones win per key. */
|
|
804
|
+
decorate: DecorateAnnotation;
|
|
805
|
+
/** Every layer added so far; `watchLayers` reports the ones added later and invalidates. */
|
|
806
|
+
readonly layers: readonly PluginLayer[];
|
|
807
|
+
/** Calls `listener` on every `ctx.redecorate()`; returns a stop function. */
|
|
808
|
+
watchRedecorate(listener: () => void): () => void;
|
|
809
|
+
destroy(): void;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* @internal For bindings and `createViewer`, which place a viewer's plugins; plugin authors use
|
|
813
|
+
* `definePlugin` and never call it.
|
|
814
|
+
*/
|
|
815
|
+
export declare function createPluginHost(opts: PluginHostOptions): PluginHost;
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/dom/page-mount.d.ts
|
|
818
|
+
interface PageMountOptions {
|
|
819
|
+
document: InkDocument;
|
|
820
|
+
/** Zero-based page index. */
|
|
821
|
+
page: number;
|
|
822
|
+
/** The page host (`div.ink-page`) from the viewport's `onMount`. */
|
|
823
|
+
host: HTMLElement;
|
|
824
|
+
transform: PageTransform;
|
|
825
|
+
store: AnnotationStore;
|
|
826
|
+
onActivate?(id: string): void;
|
|
827
|
+
isCustom?(a: Annotation): boolean;
|
|
828
|
+
/** The app's data attributes and classes for each annotation element (see `OverlayOptions`). */
|
|
829
|
+
decorate?: DecorateAnnotation;
|
|
830
|
+
/** Defaults to `window.devicePixelRatio`. */
|
|
831
|
+
devicePixelRatio?: number;
|
|
832
|
+
/** Plugin layers, mounted above the overlay. The engine passes them for its pages only. */
|
|
833
|
+
layers?: PluginLayers;
|
|
834
|
+
/**
|
|
835
|
+
* Canvas and text layer failures, with the layer that failed (cancellations are not
|
|
836
|
+
* reported).
|
|
837
|
+
*/
|
|
838
|
+
onError?(error: unknown, layer: PageLayer): void;
|
|
839
|
+
/**
|
|
840
|
+
* A layer finished without error: the canvas painted, or the text layer mounted or applied
|
|
841
|
+
* an update. Pair it with `onError` to tell when a failed layer has recovered.
|
|
842
|
+
*/
|
|
843
|
+
onRendered?(layer: PageLayer): void;
|
|
844
|
+
}
|
|
845
|
+
/** The page layers that can fail and recover: the canvas and the text layer. */
|
|
846
|
+
type PageLayer = 'canvas' | 'text';
|
|
847
|
+
interface PageMount {
|
|
848
|
+
readonly renderer: PageRenderer;
|
|
849
|
+
readonly textLayer: TextLayerHandle;
|
|
850
|
+
readonly overlay: Overlay;
|
|
851
|
+
update(transform: PageTransform): void;
|
|
852
|
+
destroy(): void;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Canvas, text layer, annotation overlay and any plugin layers for one page, stacked in that
|
|
856
|
+
* order.
|
|
857
|
+
*/
|
|
858
|
+
export declare function createPageMount(opts: PageMountOptions): PageMount;
|
|
859
|
+
//#endregion
|
|
458
860
|
//#region src/dom/tools/freetext.d.ts
|
|
459
861
|
/** Width of a box placed with a click or Enter, user-space points. */
|
|
460
862
|
export declare const DEFAULT_FREETEXT_WIDTH = 144;
|
|
@@ -967,17 +1369,26 @@ interface PopoverOptions {
|
|
|
967
1369
|
*/
|
|
968
1370
|
onDismiss(): void;
|
|
969
1371
|
}
|
|
970
|
-
/** A panel anchored to one annotation at a time; see `createPopover`. */
|
|
1372
|
+
/** A panel anchored to one annotation, or one element, at a time; see `createPopover`. */
|
|
971
1373
|
interface Popover {
|
|
972
1374
|
/** The panel element, on `<body>`. Fill it with the card's content. */
|
|
973
1375
|
readonly panel: HTMLElement;
|
|
974
|
-
/**
|
|
1376
|
+
/**
|
|
1377
|
+
* The anchored annotation's element (or the element passed to `showAt`), or null while it is
|
|
1378
|
+
* not in the DOM (page unmounted).
|
|
1379
|
+
*/
|
|
975
1380
|
readonly anchor: HTMLElement | null;
|
|
976
1381
|
/**
|
|
977
1382
|
* Anchors the panel to annotation `id`. The panel shows whenever that annotation's element
|
|
978
1383
|
* is in the DOM, and follows it when it is replaced.
|
|
979
1384
|
*/
|
|
980
1385
|
show(id: string): void;
|
|
1386
|
+
/**
|
|
1387
|
+
* Anchors the panel to `el`, for anchors that are not annotations (a plugin layer's mark).
|
|
1388
|
+
* The panel shows while `el` is under the viewer root and hides while it is not. On hide,
|
|
1389
|
+
* focus returns to `el` when it is still connected, else through `focusReturn`.
|
|
1390
|
+
*/
|
|
1391
|
+
showAt(el: HTMLElement): void;
|
|
981
1392
|
/** Hides the panel, then returns focus through `focusReturn`. */
|
|
982
1393
|
hide(): void;
|
|
983
1394
|
/** Removes the panel and its listeners. */
|
|
@@ -991,7 +1402,7 @@ export declare function placePanel(panel: HTMLElement, anchor: DOMRect): void;
|
|
|
991
1402
|
/**
|
|
992
1403
|
* Creates a non-modal `role="dialog"` panel on `<body>`, marked `data-ink-popover` so the theme
|
|
993
1404
|
* gives it its tokens, that an app anchors to an annotation with `show(id)` (for instance on
|
|
994
|
-
* `viewer.activated`)
|
|
1405
|
+
* `viewer.activated`), or to any element in the viewer with `showAt(el)`. The panel follows the annotation's element as pages mount and unmount:
|
|
995
1406
|
* it hides while the element is gone and comes back with it. Tab loops inside the panel, and
|
|
996
1407
|
* Escape or a press outside calls `onDismiss`. Call `destroy` when done.
|
|
997
1408
|
*/
|
|
@@ -1065,6 +1476,12 @@ interface MountViewerOptions {
|
|
|
1065
1476
|
* classes cannot be overridden.
|
|
1066
1477
|
*/
|
|
1067
1478
|
decorateAnnotation?: DecorateAnnotation;
|
|
1479
|
+
/**
|
|
1480
|
+
* The viewer's plugins. Their tools join `tools`, their layers are drawn on every page the
|
|
1481
|
+
* engine mounts, and the host's `decorate` replaces `decorateAnnotation`: build the host with
|
|
1482
|
+
* the app's decoration (its `decorate` option) so the two compose.
|
|
1483
|
+
*/
|
|
1484
|
+
plugins?: PluginHost;
|
|
1068
1485
|
onActivate?(id: string): void;
|
|
1069
1486
|
/**
|
|
1070
1487
|
* After every (re)build: subscribe to the new viewport and controller here. It fires inside
|
|
@@ -1115,8 +1532,9 @@ interface ViewerEngine {
|
|
|
1115
1532
|
customAnnotations?: boolean;
|
|
1116
1533
|
}): void;
|
|
1117
1534
|
/**
|
|
1118
|
-
* Runs `decorateAnnotation` again for every mounted annotation
|
|
1119
|
-
* anything else. Call it when the decorations would change but
|
|
1535
|
+
* Runs `decorateAnnotation` (or the plugins' `decorate`) again for every mounted annotation
|
|
1536
|
+
* element, without re-rendering anything else. Call it when the decorations would change but
|
|
1537
|
+
* no annotation did.
|
|
1120
1538
|
*/
|
|
1121
1539
|
redecorate(): void;
|
|
1122
1540
|
destroy(): void;
|
|
@@ -1129,7 +1547,7 @@ export declare function mountViewer(opts: MountViewerOptions): ViewerEngine;
|
|
|
1129
1547
|
* (bound to one document's store, so each engine makes its own), and the tool options and
|
|
1130
1548
|
* signature library (one for the viewer's life).
|
|
1131
1549
|
*/
|
|
1132
|
-
interface CreateViewerOptions extends Omit<MountViewerOptions, 'container' | 'document' | 'toolStyle' | 'toolHistory' | 'toolOptions' | 'signatureLibrary'> {
|
|
1550
|
+
interface CreateViewerOptions extends Omit<MountViewerOptions, 'container' | 'document' | 'toolStyle' | 'toolHistory' | 'toolOptions' | 'signatureLibrary' | 'plugins'> {
|
|
1133
1551
|
source: DocumentSource;
|
|
1134
1552
|
assets: PdfAssets;
|
|
1135
1553
|
/** User password for encrypted files. `open` can pass its own for one load. */
|
|
@@ -1137,6 +1555,12 @@ interface CreateViewerOptions extends Omit<MountViewerOptions, 'container' | 'do
|
|
|
1137
1555
|
/** Default: read from the theme's CSS variables on the viewer root. */
|
|
1138
1556
|
defaults?: AnnotationDefaults;
|
|
1139
1557
|
history?: OpenOptions['history'];
|
|
1558
|
+
/**
|
|
1559
|
+
* Plugins, set up once for the viewer's life. Their tools join the viewer's tools, their
|
|
1560
|
+
* decoration and page layers apply to every document, and their commands are placed with
|
|
1561
|
+
* `createCommandButton`.
|
|
1562
|
+
*/
|
|
1563
|
+
plugins?: readonly InkPlugin[];
|
|
1140
1564
|
/** The thread popover for notes and text markup. Default true. */
|
|
1141
1565
|
threads?: boolean;
|
|
1142
1566
|
onReady?(this: void, doc: InkDocument): void;
|
|
@@ -1167,6 +1591,10 @@ interface Viewer {
|
|
|
1167
1591
|
* not in the open document's annotations is ignored.
|
|
1168
1592
|
*/
|
|
1169
1593
|
setActivated(id: string | null): void;
|
|
1594
|
+
/** The plugins' commands by namespaced id (`sandbox.suggest`); place one with `createCommandButton`. */
|
|
1595
|
+
readonly commands: {
|
|
1596
|
+
get(id: string): Command | undefined;
|
|
1597
|
+
};
|
|
1170
1598
|
/**
|
|
1171
1599
|
* Opens another document in place; the previous one is destroyed. Latest call wins.
|
|
1172
1600
|
* `password` is used for this load only; without it, the constructor's `password` applies.
|
|
@@ -1199,12 +1627,20 @@ export declare function createUndo(viewer: Viewer): HTMLButtonElement;
|
|
|
1199
1627
|
/** Redoes the last undone change; disabled when there is none. */
|
|
1200
1628
|
export declare function createRedo(viewer: Viewer): HTMLButtonElement;
|
|
1201
1629
|
/**
|
|
1202
|
-
* Sets the tool; pressed while it is the active one. A host tool's button
|
|
1203
|
-
*
|
|
1630
|
+
* Sets the tool; pressed while it is the active one. A host or plugin tool's button takes the
|
|
1631
|
+
* tool's own `label` and `icon`; `opts.label` wins, and without either it is named by the tool id.
|
|
1204
1632
|
*/
|
|
1205
1633
|
export declare function createToolButton(viewer: Viewer, tool: ToolId, opts?: {
|
|
1206
1634
|
label?: string;
|
|
1207
1635
|
}): HTMLButtonElement;
|
|
1636
|
+
/**
|
|
1637
|
+
* A plugin command as a button with its status text beside it. The button is named by the
|
|
1638
|
+
* command's label and disabled while the command is, except while it runs: then it keeps focus,
|
|
1639
|
+
* with `aria-busy` and `aria-disabled`, and a press does nothing. The status is a live region. A command without an icon shows its label as the button's text. For an id no
|
|
1640
|
+
* plugin registered it logs `InkError('UnknownCommand')` to the console and returns the same
|
|
1641
|
+
* markup disabled, `aria-hidden` and unnamed.
|
|
1642
|
+
*/
|
|
1643
|
+
export declare function createCommandButton(viewer: Viewer, id: string): HTMLElement;
|
|
1208
1644
|
export declare function createZoomIn(viewer: Viewer): HTMLButtonElement;
|
|
1209
1645
|
export declare function createZoomOut(viewer: Viewer): HTMLButtonElement;
|
|
1210
1646
|
/** Fit width, fit page and the zoom levels; a zoom between levels gets an option of its own. */
|
|
@@ -1411,5 +1847,5 @@ export declare function createSignatureDialog(viewer: Viewer, opts?: SignatureDi
|
|
|
1411
1847
|
export declare function createSignaturePreview(t: SignatureTemplate): HTMLElement;
|
|
1412
1848
|
export declare function createSignatureMenu(viewer: Viewer, opts?: SignatureDialogOptions): HTMLElement;
|
|
1413
1849
|
//#endregion
|
|
1414
|
-
export { type AnnotationDecoration, type AnnotationSlotProps, type AnnotationState, type ArrowheadChoice, type BuiltinToolId, type ColorMenuModel, type ColorMenuOptions, type ColorMenuSwatch, type ColorProperty, type ColorTrigger, type CreateViewerOptions, type CssLayout, type CssLayoutInput, type CssPageBox, type CssRect, type CurrentStyle, type DecorateAnnotation, type EditorCloseReason, type FocusReturn, type FocusReturnOptions, type FreeTextEditor, type FreeTextEditorOptions, type HighlightMenuItem, type HighlightMenuModel, type HighlightOptions, type LayoutMode, type LineStyleMenuItem, type LineStyleMenuModel, type LineStyleMenuSection, type MarkupKind, type Menu, type MenuOptions, type MountViewerOptions, type Overlay, type OverlayOptions, type PageHit, type PageLayer, type PageMount, type PageMountOptions, type PageRenderer, type PageRendererOptions, type PageTransform, type Palette, type Popover, type PopoverOptions, type ScopedToolStyle, type SelectionQuads, type ShapeKind, type ShapeMenuItem, type ShapeMenuModel, type ShapeOptions, type SignatureDialog, type SignatureDialogOptions, type SignatureDraft, type SignatureDraftState, type SignatureMenuItem, type SignatureMenuModel, type SignatureOptions, type SignaturePad, type SignatureTab, type StyleGroup, type StyleKey, type StyleProps, type TextAlignChoice, type TextAlignKey, type TextLayerHandle, type TextLayerOptions, type TextStyleMenuModel, type TextStyleToggle, type TextToggleKey, type ThreadPopoverSlotProps, type Tool, type ToolContext, type ToolController, type ToolControllerOptions, type ToolId, type ToolKind, type ToolOptions, type ToolStyle, type ToolStyleTracker, type TypedSignatureOptions, type ViewRotation, type Viewer, type ViewerEngine, type Viewport, type ViewportHit, type ViewportKeysOptions, type ViewportOptions, type ZoomValue, cssVariableDefaults };
|
|
1850
|
+
export { type AnnotationDecoration, type AnnotationInputOf, type AnnotationLink, type AnnotationLinkSpec, type AnnotationSlotProps, type AnnotationState, type ArrowheadChoice, type BuiltinToolId, type CardSpec, type ColorMenuModel, type ColorMenuOptions, type ColorMenuSwatch, type ColorProperty, type ColorTrigger, type Command, type CommandOptions, type CommandRun, type CommandSpec, type CreateViewerOptions, type CssLayout, type CssLayoutInput, type CssPageBox, type CssRect, type CurrentStyle, type DecorateAnnotation, type EditorCloseReason, type FocusReturn, type FocusReturnOptions, type FreeTextEditor, type FreeTextEditorOptions, type HighlightMenuItem, type HighlightMenuModel, type HighlightOptions, type InkPlugin, type LayerEvent, type LayerSource, type LayerSpec, type LayoutMode, type LineStyleMenuItem, type LineStyleMenuModel, type LineStyleMenuSection, type MarksHandle, type MarksOptions, type MarkupKind, type Menu, type MenuOptions, type MountViewerOptions, type Overlay, type OverlayOptions, type PageHit, type PageLayer, type PageLayers, type PageMount, type PageMountOptions, type PageRenderer, type PageRendererOptions, type PageTransform, type Palette, type PluginApi, type PluginContext, type PluginHost, type PluginHostOptions, type PluginLayer, type PluginLayerHandle, type PluginLayers, type PluginOptions, type PluginStoreOptions, type Popover, type PopoverOptions, type Records, type ScopedToolStyle, type SelectionQuads, type ShapeKind, type ShapeMenuItem, type ShapeMenuModel, type ShapeOptions, type SignatureDialog, type SignatureDialogOptions, type SignatureDraft, type SignatureDraftState, type SignatureMenuItem, type SignatureMenuModel, type SignatureOptions, type SignaturePad, type SignatureTab, type StyleGroup, type StyleKey, type StyleProps, type TextAlignChoice, type TextAlignKey, type TextLayerHandle, type TextLayerOptions, type TextStyleMenuModel, type TextStyleToggle, type TextToggleKey, type ThreadPopoverSlotProps, type Tool, type ToolContext, type ToolController, type ToolControllerOptions, type ToolId, type ToolKind, type ToolOptions, type ToolStyle, type ToolStyleTracker, type TypedSignatureOptions, type ViewRotation, type Viewer, type ViewerEngine, type Viewport, type ViewportHit, type ViewportKeysOptions, type ViewportOptions, type ZoomValue, cssVariableDefaults };
|
|
1415
1851
|
//# sourceMappingURL=dom.d.mts.map
|