@draftably/runtime 0.3.0 → 0.5.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.
Files changed (38) hide show
  1. package/README.md +2 -1
  2. package/dist/assets/render.worker-D11vTqoO.js +8548 -0
  3. package/dist/compile-BAIrdu-8.js +7405 -0
  4. package/dist/element.js +275 -125
  5. package/dist/{font-data-DLXJur0j.js → font-data-DME3E71S.js} +1 -1
  6. package/dist/geometry-DfUVE8b2.js +79 -0
  7. package/dist/graph.js +336 -373
  8. package/dist/host.css +37 -0
  9. package/dist/host.js +24 -0
  10. package/dist/index.js +3 -3
  11. package/dist/render-CsJYFD3o.js +1188 -0
  12. package/dist/types/src/dsl/cells.d.ts +1 -0
  13. package/dist/types/src/dsl/compile.d.ts +2 -1
  14. package/dist/types/src/dsl/legend-notes.d.ts +14 -0
  15. package/dist/types/src/dsl/syntax.d.ts +2 -0
  16. package/dist/types/src/model/appearance.d.ts +27 -1
  17. package/dist/types/src/model/colors.d.ts +10 -2
  18. package/dist/types/src/model/labels.d.ts +22 -6
  19. package/dist/types/src/runtime/anchors.d.ts +46 -0
  20. package/dist/types/src/runtime/camera.d.ts +41 -0
  21. package/dist/types/src/runtime/color-scheme.d.ts +15 -0
  22. package/dist/types/src/runtime/element-base.d.ts +40 -0
  23. package/dist/types/src/runtime/element.d.ts +7 -0
  24. package/dist/types/src/runtime/geometry.d.ts +72 -0
  25. package/dist/types/src/runtime/host.d.ts +78 -0
  26. package/dist/types/src/runtime/index.d.ts +1 -0
  27. package/dist/types/src/runtime/page-shared.d.ts +24 -0
  28. package/dist/types/src/runtime/schemes.d.ts +2 -0
  29. package/dist/types/src/runtime/svg-renderer.d.ts +12 -0
  30. package/dist/types/src/runtime/types.d.ts +13 -0
  31. package/dist/types/src/runtime/viewer.d.ts +41 -7
  32. package/dist/version-CO7i33cq.js +4 -0
  33. package/dist/viewer.css +72 -9
  34. package/dist/viewer.js +713 -346
  35. package/package.json +6 -1
  36. package/dist/assets/render.worker-dvseyGmC.js +0 -8310
  37. package/dist/compile-Csfz4rk4.js +0 -7267
  38. package/dist/render-Dgo42PR4.js +0 -1146
@@ -1,11 +1,13 @@
1
+ import { type Camera, type CameraReason, type FrameOptions, type MoveResult } from './camera.js';
2
+ import { type Anchor, type DraftSlot } from './anchors.js';
3
+ import { type Geometry } from './geometry.js';
1
4
  import { fontMetricsVersion, runtimeVersion } from './version.js';
2
5
  import type { CommonRenderOptions, Diagnostic, LinkPolicy, RenderFailure, RenderResult } from './types.js';
3
6
  export { fontMetricsVersion, runtimeVersion };
4
- export interface Camera {
5
- centerX: number;
6
- centerY: number;
7
- zoom: number;
8
- }
7
+ export type { Camera, CameraReason, FrameOptions, MoveResult } from './camera.js';
8
+ export type { Box, EdgeOut, Geometry, PlacedBox } from './geometry.js';
9
+ export type { Anchor, DraftSlot } from './anchors.js';
10
+ export { ZOOM_MAX, ZOOM_MIN } from './camera.js';
9
11
  export type ViewerExecution = {
10
12
  mode: 'worker';
11
13
  createWorker?: () => Worker;
@@ -25,6 +27,8 @@ export interface ViewerOptions {
25
27
  */
26
28
  outline?: 'visible' | 'hidden';
27
29
  execution?: ViewerExecution;
30
+ /** `auto` (default) hides slot bodies and shows titles again below a zoom of 0.4. */
31
+ detail?: 'auto' | 'full';
28
32
  render?: ViewerRenderOptions;
29
33
  }
30
34
  export interface UpdateOptions {
@@ -48,20 +52,27 @@ export type UpdateResult = {
48
52
  revision: number;
49
53
  };
50
54
  export interface ViewerEvents {
55
+ /** After each commit, after `anchor()`, and with `[]` before `destroy` detaches the targets. */
56
+ anchors: {
57
+ anchors: readonly Anchor[];
58
+ };
59
+ /** After each commit: the drawing, and where each item is (`null` for compare and states). */
51
60
  render: {
52
61
  revision: number;
53
62
  value: Extract<RenderResult, {
54
63
  ok: true;
55
64
  }>['value'];
65
+ geometry: Geometry | null;
56
66
  };
57
67
  diagnostics: {
58
68
  revision: number;
59
69
  diagnostics: readonly Diagnostic[];
60
70
  stale: boolean;
61
71
  };
72
+ /** At most once per animation frame, with the latest reason. */
62
73
  camera: {
63
74
  camera: Camera;
64
- reason: 'user' | 'resize' | 'fit' | 'api';
75
+ reason: CameraReason;
65
76
  };
66
77
  itemactivate: {
67
78
  id: string;
@@ -69,20 +80,43 @@ export interface ViewerEvents {
69
80
  input: 'pointer' | 'keyboard';
70
81
  revision: number;
71
82
  };
83
+ /** `preventDefault()` stops the viewer opening the link. */
72
84
  link: {
73
85
  itemId: string;
74
86
  href: string;
75
87
  target: '_self' | '_blank';
76
88
  preventDefault(): void;
77
89
  };
90
+ /** A right-click or the menu key; `id` is null on the background. `preventDefault()` stops the browser's menu. */
91
+ contextmenu: {
92
+ id: string | null;
93
+ kind?: ItemKind;
94
+ clientX: number;
95
+ clientY: number;
96
+ preventDefault(): void;
97
+ };
78
98
  }
99
+ export type ItemKind = 'node' | 'group' | 'edge';
79
100
  export interface ViewerHandle {
101
+ /** Resolves after the first commit or failure; then after each later one. */
102
+ readonly ready: Promise<UpdateResult>;
80
103
  update(source: string, options?: UpdateOptions): Promise<UpdateResult>;
104
+ /** Where each item is drawn, in world units. `null` before the first commit, and for compare and states. The same object for one revision. */
105
+ geometry(): Geometry | null;
81
106
  on<K extends keyof ViewerEvents>(type: K, listener: (event: ViewerEvents[K]) => void): () => void;
82
107
  getCamera(): Camera;
108
+ /** Zoom is clamped to `ZOOM_MIN`–`ZOOM_MAX`. */
83
109
  setCamera(camera: Camera): void;
84
- fit(): void;
110
+ /** Frame these items, or the whole drawing without ids. At most actual size by default. */
111
+ fit(ids?: readonly string[], options?: FrameOptions): MoveResult;
112
+ /** The least move that shows the item; zooms out only if it does not fit. */
113
+ reveal(id: string, options?: FrameOptions): MoveResult;
85
114
  focusItem(id: string): boolean;
115
+ /**
116
+ * Plain-DOM hosts only: keep a target for each slot (`body:<id>`, `overlay:<id>`). Targets come
117
+ * in the `anchors` event; put content in them. The elements set this from their marked children.
118
+ */
119
+ anchor(slots: readonly DraftSlot[]): void;
86
120
  destroy(): void;
87
121
  }
88
122
  export declare function mountViewer(host: HTMLElement, options?: ViewerOptions): ViewerHandle;
@@ -0,0 +1,4 @@
1
+ const n = "0.5.0", o = n;
2
+ export {
3
+ o as r
4
+ };
package/dist/viewer.css CHANGED
@@ -1,7 +1,16 @@
1
+ /*
2
+ * Public tokens: set any --draft-* property on the element or an ancestor, and it wins.
3
+ * They inherit through the shadow root; the defaults below apply only when unset.
4
+ */
1
5
  .draft-viewer {
2
- --dv-border: #cbd5e1;
3
- --dv-ink: #1e293b;
4
- --dv-bg: #fff;
6
+ /* The viewer sets color-scheme from the page; each default has a dark value. */
7
+ --dv-border: var(--draft-border, light-dark(#cbd5e1, #3d4450));
8
+ --dv-ink: var(--draft-ink, light-dark(#1e293b, #e7eaef));
9
+ --dv-bg: var(--draft-bg, light-dark(#fff, #16191e));
10
+ --dv-focus: var(--draft-focus, light-dark(#2563eb, #7fa4e6));
11
+ --dv-shadow: var(--draft-shadow, light-dark(rgb(15 23 42 / 0.12), rgb(0 0 0 / 0.4)));
12
+ --dv-warning-ink: var(--draft-warning-ink, light-dark(#9a3412, #fdba74));
13
+ --dv-warning-bg: var(--draft-warning-bg, light-dark(#fff7ed, #431407));
5
14
  position: relative;
6
15
  display: grid;
7
16
  grid-template-rows: auto minmax(8rem, 1fr) auto auto;
@@ -15,9 +24,13 @@
15
24
  font:
16
25
  14px/1.45 system-ui,
17
26
  sans-serif;
18
- overflow: hidden;
27
+ overflow: clip;
28
+ }
29
+ .draft-viewer__toolbar[hidden] {
30
+ display: none;
19
31
  }
20
32
  .draft-viewer__toolbar {
33
+ grid-row: 1;
21
34
  display: flex;
22
35
  flex-wrap: wrap;
23
36
  align-items: center;
@@ -35,12 +48,14 @@
35
48
  }
36
49
  .draft-viewer button:focus-visible,
37
50
  .draft-viewer__viewport:focus-visible {
38
- outline: 3px solid #2563eb;
51
+ outline: 3px solid var(--dv-focus);
39
52
  outline-offset: 2px;
40
53
  }
41
54
  .draft-viewer__viewport {
55
+ grid-row: 2;
42
56
  position: relative;
43
- overflow: hidden;
57
+ /* clip, not hidden: focus on off-screen slot content must not scroll the drawing away. */
58
+ overflow: clip;
44
59
  min-height: 8rem;
45
60
  touch-action: none;
46
61
  cursor: grab;
@@ -55,10 +70,12 @@
55
70
  overflow: visible;
56
71
  }
57
72
  .draft-viewer__status {
73
+ grid-row: 3;
58
74
  margin: 0;
59
75
  padding: 0.35rem 0.65rem;
60
76
  }
61
77
  .draft-viewer__outline {
78
+ grid-row: 4;
62
79
  margin: 0;
63
80
  padding: 0.4rem 0.8rem 0.6rem 2rem;
64
81
  max-height: 7rem;
@@ -85,11 +102,11 @@
85
102
  position: absolute;
86
103
  inset: auto 0 0;
87
104
  background: var(--dv-bg);
88
- box-shadow: 0 -4px 12px rgb(15 23 42 / 0.12);
105
+ box-shadow: 0 -4px 12px var(--dv-shadow);
89
106
  }
90
107
  .draft-viewer--stale .draft-viewer__status {
91
- color: #9a3412;
92
- background: #fff7ed;
108
+ color: var(--dv-warning-ink);
109
+ background: var(--dv-warning-bg);
93
110
  }
94
111
  .draft-viewer__status:empty {
95
112
  display: none;
@@ -108,3 +125,49 @@
108
125
  padding-inline: 0.45rem;
109
126
  }
110
127
  }
128
+
129
+ /* The anchor layer: slot targets above the drawing. Slot content takes no pointer input unless
130
+ it is marked data-draft-input. */
131
+ .draft-anchors {
132
+ position: absolute;
133
+ inset: 0;
134
+ pointer-events: none;
135
+ overflow: visible;
136
+ }
137
+ .draft-anchors__bodies {
138
+ position: absolute;
139
+ left: 0;
140
+ top: 0;
141
+ width: 0;
142
+ height: 0;
143
+ transform-origin: 0 0;
144
+ }
145
+ .draft-anchors__overlays {
146
+ position: absolute;
147
+ inset: 0;
148
+ }
149
+ .draft-anchor {
150
+ position: absolute;
151
+ box-sizing: border-box;
152
+ pointer-events: none;
153
+ }
154
+ /* Marked content in a mountViewer target, in the page's DOM. The element's slotted content gets the
155
+ same rule from host.css, because these selectors do not reach into slots. */
156
+ .draft-anchor [data-draft-input] {
157
+ pointer-events: auto;
158
+ }
159
+ .draft-anchor--body {
160
+ overflow: clip;
161
+ }
162
+ .draft-anchor--overlay {
163
+ left: 0;
164
+ top: 0;
165
+ overflow: visible;
166
+ }
167
+ .draft-anchors[data-draft-detail='low'] .draft-anchors__bodies {
168
+ visibility: hidden;
169
+ }
170
+ /* A body replaces its node's drawn title; the title stays for screen readers. */
171
+ .draft-viewer__viewport[data-draft-detail='full'] [data-draft-body] text {
172
+ opacity: 0;
173
+ }