@zh-xx/antu 0.14.0 → 0.16.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.
@@ -9,9 +9,36 @@ export interface AntuSpec {
9
9
  [field: string]: unknown
10
10
  }
11
11
 
12
- export type AntuTheme = 'document' | 'modern' | 'legal'
12
+ export type AntuTheme = 'document' | 'modern' | 'legal' | 'dark'
13
13
  export type AntuLang = 'zh' | 'en'
14
14
 
15
+ /**
16
+ * How a mounted diagram opens and what it shows (issue 200). Every value a reader can change may be set here:
17
+ * the theme and language, the label card and dock folds, and every switch of the flowchart and route map.
18
+ * Unknown keys, wrong types and values outside an enum make `mount` throw.
19
+ */
20
+ export interface AntuViewState {
21
+ theme?: AntuTheme
22
+ lang?: AntuLang
23
+ shell?: { headerFolded?: boolean; dockFolded?: boolean }
24
+ view?: {
25
+ flow?: {
26
+ states?: boolean
27
+ conditions?: boolean
28
+ detail?: boolean
29
+ mainLine?: boolean
30
+ stages?: boolean
31
+ rules?: boolean
32
+ orientation?: 'vertical' | 'horizontal'
33
+ linkStyle?: 'straight' | 'curved'
34
+ }
35
+ route?: { labels?: boolean; states?: boolean }
36
+ }
37
+ }
38
+
39
+ /** The names `persist` may list: one per prefs key whose write may reach the host's store */
40
+ export type AntuPersistName = 'theme' | 'lang' | 'kind' | 'shell.headerFolded' | 'shell.dockFolded' | 'view.flow' | 'view.route'
41
+
15
42
  /** 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
43
  export interface AntuSource {
17
44
  id: string
@@ -34,6 +61,7 @@ export type AntuEvent =
34
61
  sources: AntuSource[]
35
62
  }
36
63
  | { type: 'kindchange'; kind: string }
64
+ | { type: 'themechange'; theme: AntuTheme }
37
65
  | { type: 'invalid'; errors: string[] }
38
66
 
39
67
  export interface AntuPrefsStore {
@@ -51,12 +79,27 @@ export interface MountOptions {
51
79
  theme?: AntuTheme
52
80
  /** The language of the page's own words; the case is never translated. Default: the browser's. */
53
81
  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 }
82
+ /**
83
+ * Pieces of the page's chrome to leave out; all shown by default.
84
+ * `panOnScroll: false` lets the wheel scroll the host page (a chat card).
85
+ * `panOnDrag: false` stops press-and-drag from panning. See `cardUi`.
86
+ */
87
+ ui?: {
88
+ header?: boolean
89
+ capsule?: boolean
90
+ minimap?: boolean
91
+ zoom?: boolean
92
+ panOnScroll?: boolean
93
+ panOnDrag?: boolean
94
+ }
56
95
  /** 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
96
  prefs?: 'none' | 'local' | AntuPrefsStore
58
- /** How it opens, ahead of the reader's stored choices (the reader can still change it). An unknown key or a wrong value: `mount` throws. */
59
- initial?: { headerFolded?: boolean }
97
+ /** How it opens, ahead of the reader's stored choices (the reader can still change it). `headerFolded` is the old alias of `shell.headerFolded`. An unknown key or a wrong value: `mount` throws. */
98
+ initial?: AntuViewState & { headerFolded?: boolean }
99
+ /** Values forced for this mount; their controls are hidden (a locked `shell.dockFolded: true` hides the dock). An unknown key or a wrong value: `mount` throws. */
100
+ locked?: AntuViewState
101
+ /** Which of the reader's changes reach the prefs store: true (all, the default), false (none, kept while mounted), or a list of names. An unknown name or a wrong type: `mount` throws. */
102
+ persist?: boolean | AntuPersistName[]
60
103
  onEvent?: (event: AntuEvent) => void
61
104
  }
62
105
 
@@ -85,6 +128,18 @@ export interface AntuHandle {
85
128
  /** 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. */
86
129
  export function mount(element: HTMLElement, spec: AntuSpec, options?: MountOptions): AntuHandle
87
130
 
131
+ /**
132
+ * Recommended `ui` for a chat card: no label card, capsule, minimap or zoom buttons, and the wheel
133
+ * does not pan the diagram (the host page can still scroll). Spread into `mount(…, { ui: { …cardUi } })`.
134
+ */
135
+ export declare const cardUi: Readonly<{
136
+ header: false
137
+ capsule: false
138
+ minimap: false
139
+ zoom: false
140
+ panOnScroll: false
141
+ }>
142
+
88
143
  /** Check a spec the way the diagram checks it before drawing; each error names its field */
89
144
  export function validate(spec: unknown): { ok: boolean; errors: string[] }
90
145
 
@@ -93,3 +148,12 @@ export function normalize(spec: unknown): { spec: unknown; changes: string[] }
93
148
 
94
149
  /** The kinds a type can be drawn in, the first being the one it opens in */
95
150
  export function kindsOf(type: string): string[]
151
+
152
+ /**
153
+ * A small sketch of a kind as one `<svg viewBox="0 0 80 48">` string, for a host that draws its own picker. Its colours are CSS
154
+ * variables to set where the markup goes: `--antu-text-3` (ink), `--antu-line` (the tint of the boxes) and `--antu-bg` (the ground it sits on: a few sketches paint with it and it falls back to white, so a dark host must set it). `null` for a kind with no sketch.
155
+ */
156
+ export function kindIcon(kind: string): string | null
157
+
158
+ /** The name of a kind as the page's picker shows it, in `zh` or `en` (anything else gives English); `null` for an unknown kind */
159
+ export function kindLabel(kind: string, lang?: AntuLang): string | null