@zh-xx/antu 0.9.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
1
+ // Declarations of `@zh-xx/antu/embed` (src/embed/index.js). The contract is in spec/embed.md;
2
+ // test/embed.test.mjs checks that every function the module exports is declared here and nothing else.
3
+
4
+ /** An Antu JSON: the envelope (`type`, `specVersion`, `title`) and the content of its type */
5
+ export interface AntuSpec {
6
+ type: string
7
+ specVersion?: number
8
+ title?: string
9
+ [field: string]: unknown
10
+ }
11
+
12
+ export type AntuTheme = 'document' | 'modern' | 'legal'
13
+ export type AntuLang = 'zh' | 'en'
14
+
15
+ /** A source as written in the spec's `sources` (`loc` is shaped by the source's `type`, e.g. a contract's { file, clause, page }) */
16
+ export interface AntuSource {
17
+ id: string
18
+ type?: string
19
+ name?: string
20
+ loc?: Record<string, unknown>
21
+ [field: string]: unknown
22
+ }
23
+
24
+ export type AntuEvent =
25
+ | {
26
+ /** The reader pinned an item's card open, or closed it (`id` null) */
27
+ type: 'select'
28
+ /** The item's id in the spec; a canvas node's own id when it is not one item (a run of events on the scale) */
29
+ id: string | null
30
+ /** The top-level array the item is in (`nodes`, `rules`, `events`, `entities`, …); null when none */
31
+ collection: string | null
32
+ sourceIds: string[]
33
+ /** The item's sources as written in `sources` */
34
+ sources: AntuSource[]
35
+ }
36
+ | { type: 'kindchange'; kind: string }
37
+ | { type: 'invalid'; errors: string[] }
38
+
39
+ export interface AntuPrefsStore {
40
+ read(): Record<string, unknown>
41
+ /** Merge the patch into what is kept */
42
+ write(patch: Record<string, unknown>): void
43
+ }
44
+
45
+ export interface MountOptions {
46
+ /** The kind it opens in, until the reader picks another. Not a kind of the spec's type: `mount` throws. */
47
+ kind?: string
48
+ /** The kinds the reader may pick from; one fixes the kind. A name that is not a kind of the type: `mount` throws. */
49
+ kinds?: string[]
50
+ /** The theme it opens in (the reader can still switch, unless the label card is left out) */
51
+ theme?: AntuTheme
52
+ /** The language of the page's own words; the case is never translated. Default: the browser's. */
53
+ lang?: AntuLang
54
+ /** Pieces of the page's chrome to leave out; all shown by default */
55
+ ui?: { header?: boolean; capsule?: boolean; minimap?: boolean; zoom?: boolean }
56
+ /** Where the reader's choices are kept: 'none' (default) while mounted only, 'local' in the viewer page's localStorage key, or the host's store */
57
+ prefs?: 'none' | 'local' | AntuPrefsStore
58
+ onEvent?: (event: AntuEvent) => void
59
+ }
60
+
61
+ export interface AntuHandle {
62
+ /** Resolves once the diagram is drawn and fitted; rejects (with `errors`) when the spec is not valid */
63
+ readonly ready: Promise<void>
64
+ /** Draw another spec in the same place */
65
+ update(spec: AntuSpec): void
66
+ /** False when `kind` is not a kind of the type (or not in `kinds`) */
67
+ setKind(kind: string): boolean
68
+ setTheme(theme: AntuTheme): boolean
69
+ setLang(lang: AntuLang): boolean
70
+ fitView(): void
71
+ /** The PNG the page's own export makes (no label card, a white margin), not saved anywhere. Waits until the spec now mounted is drawn; rejects (with `errors`) while it is not valid. */
72
+ exportPng(options?: { pixelRatio?: number }): Promise<Blob>
73
+ /** Take the diagram off the element */
74
+ destroy(): void
75
+ }
76
+
77
+ /** Draw `spec` inside `element` (in a shadow root; the element needs a height). Throws if one is already mounted there, or if `kind`/`kinds` name a way of drawing the spec's type does not have. */
78
+ export function mount(element: HTMLElement, spec: AntuSpec, options?: MountOptions): AntuHandle
79
+
80
+ /** Check a spec the way the diagram checks it before drawing; each error names its field */
81
+ export function validate(spec: unknown): { ok: boolean; errors: string[] }
82
+
83
+ /** The kinds a type can be drawn in, the first being the one it opens in */
84
+ export function kindsOf(type: string): string[]