@inkbar/core 0.4.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 +90 -7
- package/dist/dom.d.mts +610 -58
- package/dist/dom.d.mts.map +1 -1
- package/dist/dom.mjs +2387 -929
- package/dist/dom.mjs.map +1 -1
- package/dist/index.d.mts +17 -37
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +181 -25
- package/dist/index.mjs.map +1 -1
- package/dist/{signatures-BHYKTwYE.d.mts → signatures-By4B40DP.d.mts} +706 -620
- package/dist/signatures-By4B40DP.d.mts.map +1 -0
- package/dist/{signatures-DF2VmNVa.mjs → signatures-D68fuLlt.mjs} +1333 -325
- package/dist/signatures-D68fuLlt.mjs.map +1 -0
- package/package.json +4 -7
- package/dist/signatures-BHYKTwYE.d.mts.map +0 -1
- package/dist/signatures-DF2VmNVa.mjs.map +0 -1
- package/schema.json +0 -1356
package/dist/dom.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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. */
|
|
@@ -256,16 +258,38 @@ interface OverlayOptions {
|
|
|
256
258
|
document?: InkDocument;
|
|
257
259
|
/** Fixed device pixel ratio for loupes; `window.devicePixelRatio` when omitted. */
|
|
258
260
|
devicePixelRatio?: number;
|
|
261
|
+
/**
|
|
262
|
+
* The app's own data attributes, classes and description for an annotation's element, read
|
|
263
|
+
* whenever the annotations change and on `redecorate`. Core's own attributes and `ink-`
|
|
264
|
+
* classes win over them.
|
|
265
|
+
*/
|
|
266
|
+
decorate?: DecorateAnnotation;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Data attributes, classes and a description an app adds to an annotation's element, to style
|
|
270
|
+
* or find its own marks. Each `data` key is written as `data-<key>`.
|
|
271
|
+
*/
|
|
272
|
+
interface AnnotationDecoration {
|
|
273
|
+
/** Written as data-<key>; keys are lower-case kebab (/^[a-z][a-z0-9-]*$/). */
|
|
274
|
+
data?: Readonly<Record<string, string>>;
|
|
275
|
+
classes?: readonly string[];
|
|
276
|
+
/**
|
|
277
|
+
* Extra words screen readers announce after the element's label, such as "Needs review".
|
|
278
|
+
* Written as `aria-description`.
|
|
279
|
+
*/
|
|
280
|
+
description?: string;
|
|
259
281
|
}
|
|
282
|
+
/** Returns the decoration for an annotation's element, or undefined for none. */
|
|
283
|
+
type DecorateAnnotation = (annotation: Annotation) => AnnotationDecoration | undefined;
|
|
260
284
|
interface Overlay {
|
|
261
285
|
readonly element: HTMLElement;
|
|
262
286
|
/** Repositions every element and redraws content for a new zoom or rotation. */
|
|
263
287
|
update(transform: PageTransform): void;
|
|
264
288
|
elementFor(id: string): HTMLElement | undefined;
|
|
289
|
+
/** Runs `decorate` again for every element, for when its output changed but no annotation did. */
|
|
290
|
+
redecorate(): void;
|
|
265
291
|
destroy(): void;
|
|
266
292
|
}
|
|
267
|
-
/** The `data-confidence` bucket for a suggested redaction; undefined for everything else. */
|
|
268
|
-
export declare function confidenceAttr(a: Annotation): 'low' | 'medium' | 'high' | undefined;
|
|
269
293
|
export declare function createOverlay(opts: OverlayOptions): Overlay;
|
|
270
294
|
//#endregion
|
|
271
295
|
//#region src/dom/overlay-render.d.ts
|
|
@@ -276,41 +300,184 @@ export declare function createOverlay(opts: OverlayOptions): Overlay;
|
|
|
276
300
|
*/
|
|
277
301
|
export declare function renderAnnotationContent(el: HTMLElement, a: Annotation, t: PageTransform): void;
|
|
278
302
|
//#endregion
|
|
279
|
-
//#region src/dom/
|
|
280
|
-
interface
|
|
281
|
-
|
|
282
|
-
/**
|
|
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 & {
|
|
283
405
|
page: number;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
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;
|
|
292
413
|
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
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.
|
|
295
416
|
*/
|
|
296
|
-
|
|
417
|
+
style?(record: T): Partial<CSSStyleDeclaration> & {
|
|
418
|
+
[property: `--${string}`]: string;
|
|
419
|
+
};
|
|
420
|
+
/** Classes every mark gets. */
|
|
421
|
+
className?: string;
|
|
297
422
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
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`).
|
|
300
426
|
*/
|
|
301
|
-
|
|
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;
|
|
302
436
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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;
|
|
311
480
|
}
|
|
312
|
-
/** Canvas, text layer and annotation overlay for one page, stacked in that order. */
|
|
313
|
-
export declare function createPageMount(opts: PageMountOptions): PageMount;
|
|
314
481
|
//#endregion
|
|
315
482
|
//#region src/dom/tools/options.d.ts
|
|
316
483
|
interface ToolOptions {
|
|
@@ -328,6 +495,11 @@ export declare function createToolOptions(tools?: readonly Tool[]): ToolOptions;
|
|
|
328
495
|
type BuiltinToolId = 'select-text' | 'select' | 'highlight' | 'redact-area' | 'note' | 'shape' | 'freetext' | 'draw' | 'sketch' | 'signature';
|
|
329
496
|
/** A built-in tool's id, or any id a host registers its own tool under. */
|
|
330
497
|
type ToolId = BuiltinToolId | (string & {});
|
|
498
|
+
/**
|
|
499
|
+
* A one-shot tool switches back to `select-text` once it has made something and the user moves
|
|
500
|
+
* on; a sticky tool stays on. A tool without a kind is sticky.
|
|
501
|
+
*/
|
|
502
|
+
type ToolKind = 'one-shot' | 'sticky';
|
|
331
503
|
interface PageHit extends ViewportHit {
|
|
332
504
|
/** Pointer position in user space. */
|
|
333
505
|
user: Point;
|
|
@@ -356,9 +528,22 @@ interface ToolContext {
|
|
|
356
528
|
};
|
|
357
529
|
/** The signature templates the `signature` tool places. Without it, it places nothing. */
|
|
358
530
|
signatures?: SignatureLibrary | undefined;
|
|
531
|
+
/**
|
|
532
|
+
* A one-shot tool reports what it just made, already added and selected. Does nothing under
|
|
533
|
+
* a sticky tool or with an empty list.
|
|
534
|
+
*/
|
|
535
|
+
made(ids: readonly string[]): void;
|
|
536
|
+
/** Clears the selection and switches to `select-text`. */
|
|
537
|
+
done(): void;
|
|
359
538
|
}
|
|
360
539
|
interface Tool<O extends object = object> {
|
|
361
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;
|
|
545
|
+
/** Default sticky. */
|
|
546
|
+
kind?: ToolKind;
|
|
362
547
|
cursor: string;
|
|
363
548
|
/** Style group the tool creates into; select tools have none. */
|
|
364
549
|
styleGroup?: StyleGroup;
|
|
@@ -395,8 +580,11 @@ interface ToolController {
|
|
|
395
580
|
destroy(): void;
|
|
396
581
|
}
|
|
397
582
|
interface ToolControllerOptions {
|
|
398
|
-
/**
|
|
399
|
-
|
|
583
|
+
/**
|
|
584
|
+
* The controller adds `options`, `made` and `done`; `toolStyle` defaults to one of the
|
|
585
|
+
* controller's own.
|
|
586
|
+
*/
|
|
587
|
+
ctx: Omit<ToolContext, 'toolStyle' | 'options' | 'made' | 'done'> & {
|
|
400
588
|
toolStyle?: ToolStyle;
|
|
401
589
|
};
|
|
402
590
|
/** Default `'select-text'`. */
|
|
@@ -414,6 +602,261 @@ export declare function hitFor(ctx: ToolContext, e: {
|
|
|
414
602
|
clientY: number;
|
|
415
603
|
}): PageHit | undefined;
|
|
416
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
|
|
417
860
|
//#region src/dom/tools/freetext.d.ts
|
|
418
861
|
/** Width of a box placed with a click or Enter, user-space points. */
|
|
419
862
|
export declare const DEFAULT_FREETEXT_WIDTH = 144;
|
|
@@ -628,9 +1071,11 @@ interface ColorMenuModel {
|
|
|
628
1071
|
}
|
|
629
1072
|
/**
|
|
630
1073
|
* What a colour menu shows for a style: the palette with the matching swatch checked, "No fill"
|
|
631
|
-
* for `fill`, and the trigger's swatch. Shared by the bindings and the vanilla menu.
|
|
1074
|
+
* for `fill`, and the trigger's swatch. Shared by the bindings and the vanilla menu. `fallback`
|
|
1075
|
+
* is the colour new annotations get while the style leaves it unset: the trigger shows it
|
|
1076
|
+
* rather than an empty swatch.
|
|
632
1077
|
*/
|
|
633
|
-
export declare function colorMenuModel(property: ColorProperty, current: CurrentStyle, supported: ReadonlySet<StyleKey
|
|
1078
|
+
export declare function colorMenuModel(property: ColorProperty, current: CurrentStyle, supported: ReadonlySet<StyleKey>, fallback?: string): ColorMenuModel;
|
|
634
1079
|
/** A typed size as the menu stores it: a whole number of points within the range. */
|
|
635
1080
|
export declare function clampFontSize(size: number): number;
|
|
636
1081
|
type TextToggleKey = 'bold' | 'italic' | 'underline';
|
|
@@ -739,10 +1184,6 @@ interface AnnotationSlotProps {
|
|
|
739
1184
|
locked: boolean;
|
|
740
1185
|
select: () => void;
|
|
741
1186
|
remove: () => void;
|
|
742
|
-
/** Turns a suggested redaction into the user's own. No-op for anything else. */
|
|
743
|
-
accept: () => void;
|
|
744
|
-
/** Removes a suggested redaction. No-op for anything else. */
|
|
745
|
-
dismiss: () => void;
|
|
746
1187
|
}
|
|
747
1188
|
/** The thread popover's accessible name: "Note thread" for a note, "Comment thread" for markup. */
|
|
748
1189
|
export declare function threadPopoverLabel(root: Pick<Annotation, 'type'>): string;
|
|
@@ -760,15 +1201,6 @@ interface ThreadPopoverSlotProps {
|
|
|
760
1201
|
remove: () => void;
|
|
761
1202
|
close: () => void;
|
|
762
1203
|
}
|
|
763
|
-
/** What a host-rendered suggestion card receives. */
|
|
764
|
-
interface SuggestionCardSlotProps {
|
|
765
|
-
annotation: RedactAnnotation;
|
|
766
|
-
suggestion: Suggestion | undefined;
|
|
767
|
-
bucket: ConfidenceBucket | undefined;
|
|
768
|
-
accept: () => void;
|
|
769
|
-
dismiss: () => void;
|
|
770
|
-
close: () => void;
|
|
771
|
-
}
|
|
772
1204
|
/** The signature controls' words, shared so every binding announces the same names. */
|
|
773
1205
|
export declare const SIGNATURE_LABELS: {
|
|
774
1206
|
/** The menu's group and main button. */
|
|
@@ -828,19 +1260,30 @@ interface FreeTextEditor {
|
|
|
828
1260
|
/** Closes the editor, handing its text to `commit` (true) or calling `cancel` (false). */
|
|
829
1261
|
close(commit: boolean): void;
|
|
830
1262
|
}
|
|
1263
|
+
/**
|
|
1264
|
+
* What closed an editor: Escape, a press outside it, focus leaving it, or a call to `close`
|
|
1265
|
+
* (a redraw, the page unmounting, the box being removed, a tool switch).
|
|
1266
|
+
*/
|
|
1267
|
+
type EditorCloseReason = 'escape' | 'press' | 'focus' | 'api';
|
|
831
1268
|
interface FreeTextEditorOptions {
|
|
832
1269
|
transform: PageTransform;
|
|
833
1270
|
/**
|
|
834
1271
|
* The edited text and the box's rect, grown to fit it (`grownFreeText`), in user space.
|
|
835
1272
|
* `grown` is the growth alone, in CSS px (0 when the box kept its height), for a caller whose
|
|
836
|
-
* box may have moved or been resized while the editor was open.
|
|
1273
|
+
* box may have moved or been resized while the editor was open. `how` says what closed it.
|
|
837
1274
|
*/
|
|
838
|
-
commit(contents: string, rect: Rect, grown: number): void;
|
|
1275
|
+
commit(contents: string, rect: Rect, grown: number, how: EditorCloseReason): void;
|
|
839
1276
|
cancel(): void;
|
|
1277
|
+
/** Where to put the caret, a client point (a click on the box); at the end when absent. */
|
|
1278
|
+
caret?: {
|
|
1279
|
+
clientX: number;
|
|
1280
|
+
clientY: number;
|
|
1281
|
+
} | undefined;
|
|
840
1282
|
}
|
|
841
1283
|
/**
|
|
842
1284
|
* Opens an editor on `el`, the overlay element showing `a` (or a stand-in for a box not in the
|
|
843
|
-
* store yet)
|
|
1285
|
+
* store yet), with the caret at `opts.caret` or after the text. `Escape` commits; a press
|
|
1286
|
+
* outside the editor, or focus leaving it, commits too.
|
|
844
1287
|
* Closing while the editor has focus hands focus to `el`. Keys typed in the
|
|
845
1288
|
* editor stop there, so no viewport or tool shortcut sees them. Opening a second editor on the
|
|
846
1289
|
* same element commits the first.
|
|
@@ -908,6 +1351,63 @@ interface FocusReturn {
|
|
|
908
1351
|
}
|
|
909
1352
|
export declare function createFocusReturn(opts: FocusReturnOptions): FocusReturn;
|
|
910
1353
|
//#endregion
|
|
1354
|
+
//#region src/dom/viewer/popover.d.ts
|
|
1355
|
+
/** Options for `createPopover`. */
|
|
1356
|
+
interface PopoverOptions {
|
|
1357
|
+
/** The viewer root (`[data-ink-root]`): anchors are looked up and focus returns inside it. */
|
|
1358
|
+
root: HTMLElement;
|
|
1359
|
+
/**
|
|
1360
|
+
* Attributes for the panel, such as `class`, `aria-label` or the app's own `data-*` keys.
|
|
1361
|
+
* `role` and `data-ink-popover` are always set by `createPopover`.
|
|
1362
|
+
*/
|
|
1363
|
+
attrs: Record<string, string>;
|
|
1364
|
+
/** Where focus goes when the panel hides: `createFocusReturn` over the same root. */
|
|
1365
|
+
focusReturn: FocusReturn;
|
|
1366
|
+
/**
|
|
1367
|
+
* Called on Escape inside the panel or the viewer, and on a press outside the panel that will
|
|
1368
|
+
* not activate another annotation. Hide the panel (or clear the activation) here.
|
|
1369
|
+
*/
|
|
1370
|
+
onDismiss(): void;
|
|
1371
|
+
}
|
|
1372
|
+
/** A panel anchored to one annotation, or one element, at a time; see `createPopover`. */
|
|
1373
|
+
interface Popover {
|
|
1374
|
+
/** The panel element, on `<body>`. Fill it with the card's content. */
|
|
1375
|
+
readonly panel: HTMLElement;
|
|
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
|
+
*/
|
|
1380
|
+
readonly anchor: HTMLElement | null;
|
|
1381
|
+
/**
|
|
1382
|
+
* Anchors the panel to annotation `id`. The panel shows whenever that annotation's element
|
|
1383
|
+
* is in the DOM, and follows it when it is replaced.
|
|
1384
|
+
*/
|
|
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;
|
|
1392
|
+
/** Hides the panel, then returns focus through `focusReturn`. */
|
|
1393
|
+
hide(): void;
|
|
1394
|
+
/** Removes the panel and its listeners. */
|
|
1395
|
+
destroy(): void;
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Positions `panel` (fixed) below the `anchor` rectangle, or above it when only that fits,
|
|
1399
|
+
* kept inside the window. For panels anchored to something other than an annotation.
|
|
1400
|
+
*/
|
|
1401
|
+
export declare function placePanel(panel: HTMLElement, anchor: DOMRect): void;
|
|
1402
|
+
/**
|
|
1403
|
+
* Creates a non-modal `role="dialog"` panel on `<body>`, marked `data-ink-popover` so the theme
|
|
1404
|
+
* gives it its tokens, that an app anchors to an annotation with `show(id)` (for instance on
|
|
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:
|
|
1406
|
+
* it hides while the element is gone and comes back with it. Tab loops inside the panel, and
|
|
1407
|
+
* Escape or a press outside calls `onDismiss`. Call `destroy` when done.
|
|
1408
|
+
*/
|
|
1409
|
+
export declare function createPopover(opts: PopoverOptions): Popover;
|
|
1410
|
+
//#endregion
|
|
911
1411
|
//#region src/dom/viewer-engine.d.ts
|
|
912
1412
|
interface MountViewerOptions {
|
|
913
1413
|
container: HTMLElement;
|
|
@@ -968,6 +1468,20 @@ interface MountViewerOptions {
|
|
|
968
1468
|
signatureFonts?: string[];
|
|
969
1469
|
/** Annotation content is rendered by the host (custom slots). Changing it needs `rebuild`. */
|
|
970
1470
|
customAnnotations?: boolean;
|
|
1471
|
+
/**
|
|
1472
|
+
* The app's own data attributes, classes and description for each annotation element, to
|
|
1473
|
+
* style or find its marks: `{ data: { 'my-flag': 'on' } }` writes `data-my-flag="on"`.
|
|
1474
|
+
* Decorations re-apply whenever the annotations change; when the function's output changes
|
|
1475
|
+
* for another reason (app state it reads), call `redecorate()`. Core's attributes and `ink-`
|
|
1476
|
+
* classes cannot be overridden.
|
|
1477
|
+
*/
|
|
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;
|
|
971
1485
|
onActivate?(id: string): void;
|
|
972
1486
|
/**
|
|
973
1487
|
* After every (re)build: subscribe to the new viewport and controller here. It fires inside
|
|
@@ -1017,6 +1531,12 @@ interface ViewerEngine {
|
|
|
1017
1531
|
buffer?: number;
|
|
1018
1532
|
customAnnotations?: boolean;
|
|
1019
1533
|
}): void;
|
|
1534
|
+
/**
|
|
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.
|
|
1538
|
+
*/
|
|
1539
|
+
redecorate(): void;
|
|
1020
1540
|
destroy(): void;
|
|
1021
1541
|
}
|
|
1022
1542
|
export declare function mountViewer(opts: MountViewerOptions): ViewerEngine;
|
|
@@ -1027,7 +1547,7 @@ export declare function mountViewer(opts: MountViewerOptions): ViewerEngine;
|
|
|
1027
1547
|
* (bound to one document's store, so each engine makes its own), and the tool options and
|
|
1028
1548
|
* signature library (one for the viewer's life).
|
|
1029
1549
|
*/
|
|
1030
|
-
interface CreateViewerOptions extends Omit<MountViewerOptions, 'container' | 'document' | 'toolStyle' | 'toolHistory' | 'toolOptions' | 'signatureLibrary'> {
|
|
1550
|
+
interface CreateViewerOptions extends Omit<MountViewerOptions, 'container' | 'document' | 'toolStyle' | 'toolHistory' | 'toolOptions' | 'signatureLibrary' | 'plugins'> {
|
|
1031
1551
|
source: DocumentSource;
|
|
1032
1552
|
assets: PdfAssets;
|
|
1033
1553
|
/** User password for encrypted files. `open` can pass its own for one load. */
|
|
@@ -1035,10 +1555,14 @@ interface CreateViewerOptions extends Omit<MountViewerOptions, 'container' | 'do
|
|
|
1035
1555
|
/** Default: read from the theme's CSS variables on the viewer root. */
|
|
1036
1556
|
defaults?: AnnotationDefaults;
|
|
1037
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[];
|
|
1038
1564
|
/** The thread popover for notes and text markup. Default true. */
|
|
1039
1565
|
threads?: boolean;
|
|
1040
|
-
/** Suggested-redaction card. Default true. */
|
|
1041
|
-
suggestions?: boolean;
|
|
1042
1566
|
onReady?(this: void, doc: InkDocument): void;
|
|
1043
1567
|
onError?(this: void, error: InkError): void;
|
|
1044
1568
|
}
|
|
@@ -1055,6 +1579,22 @@ interface Viewer {
|
|
|
1055
1579
|
*/
|
|
1056
1580
|
readonly viewport: Readable<Viewport | null>;
|
|
1057
1581
|
readonly tools: Readable<ToolController | null>;
|
|
1582
|
+
/**
|
|
1583
|
+
* The activated annotation's id: the one last clicked, or activated with Enter or Space.
|
|
1584
|
+
* The note thread opens from it, and an app can anchor its own popover (`createPopover`) to
|
|
1585
|
+
* it. `null` when none is, and again once that annotation is removed or the document closes.
|
|
1586
|
+
*/
|
|
1587
|
+
readonly activated: Readable<string | null>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Activates annotation `id`, or clears the activation with `null` (closing the thread
|
|
1590
|
+
* popover). Unlike a click, it does not select the annotation or call `onActivate`. An id
|
|
1591
|
+
* not in the open document's annotations is ignored.
|
|
1592
|
+
*/
|
|
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
|
+
};
|
|
1058
1598
|
/**
|
|
1059
1599
|
* Opens another document in place; the previous one is destroyed. Latest call wins.
|
|
1060
1600
|
* `password` is used for this load only; without it, the constructor's `password` applies.
|
|
@@ -1087,12 +1627,20 @@ export declare function createUndo(viewer: Viewer): HTMLButtonElement;
|
|
|
1087
1627
|
/** Redoes the last undone change; disabled when there is none. */
|
|
1088
1628
|
export declare function createRedo(viewer: Viewer): HTMLButtonElement;
|
|
1089
1629
|
/**
|
|
1090
|
-
* Sets the tool; pressed while it is the active one. A host tool's button
|
|
1091
|
-
*
|
|
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.
|
|
1092
1632
|
*/
|
|
1093
1633
|
export declare function createToolButton(viewer: Viewer, tool: ToolId, opts?: {
|
|
1094
1634
|
label?: string;
|
|
1095
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;
|
|
1096
1644
|
export declare function createZoomIn(viewer: Viewer): HTMLButtonElement;
|
|
1097
1645
|
export declare function createZoomOut(viewer: Viewer): HTMLButtonElement;
|
|
1098
1646
|
/** Fit width, fit page and the zoom levels; a zoom between levels gets an option of its own. */
|
|
@@ -1123,6 +1671,8 @@ interface ColorMenuOptions {
|
|
|
1123
1671
|
* colour whatever tool is active, and recolours the selection only when it is all in the group.
|
|
1124
1672
|
*/
|
|
1125
1673
|
group?: StyleGroup;
|
|
1674
|
+
/** The colour new annotations get while the style leaves it unset; the trigger shows it. */
|
|
1675
|
+
fallback?: Readable<string | undefined>;
|
|
1126
1676
|
}
|
|
1127
1677
|
/** A button that opens a colour menu for one colour property of the selection or tool. */
|
|
1128
1678
|
export declare function createColorMenu(viewer: Viewer, opts: ColorMenuOptions): HTMLButtonElement;
|
|
@@ -1156,6 +1706,8 @@ interface MenuOptions {
|
|
|
1156
1706
|
* focusable one.
|
|
1157
1707
|
*/
|
|
1158
1708
|
role?: 'menu' | 'dialog';
|
|
1709
|
+
/** The element the panel lines up under. Default `trigger`; a split button passes itself. */
|
|
1710
|
+
anchor?: HTMLElement;
|
|
1159
1711
|
/**
|
|
1160
1712
|
* Whether `target` belongs to a menu nested in this one (its panel sits outside this panel
|
|
1161
1713
|
* in the DOM). Presses, focus and Escape inside it neither dismiss this menu nor close it.
|
|
@@ -1295,5 +1847,5 @@ export declare function createSignatureDialog(viewer: Viewer, opts?: SignatureDi
|
|
|
1295
1847
|
export declare function createSignaturePreview(t: SignatureTemplate): HTMLElement;
|
|
1296
1848
|
export declare function createSignatureMenu(viewer: Viewer, opts?: SignatureDialogOptions): HTMLElement;
|
|
1297
1849
|
//#endregion
|
|
1298
|
-
export { 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 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 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
|
|
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 };
|
|
1299
1851
|
//# sourceMappingURL=dom.d.mts.map
|