@deltarobotics/uhd-viewer 0.0.0-stage → 0.2.1

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 (101) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +22 -0
  4. package/README.md +168 -2
  5. package/bin/serve.d.mts +62 -0
  6. package/bin/serve.mjs +257 -0
  7. package/bin/uhd-viewer.mjs +75 -0
  8. package/dist/app/assets/KodeMono-Bold-DdIivhPN.woff2 +0 -0
  9. package/dist/app/assets/KodeMono-Medium-CVnTuv5A.ttf +0 -0
  10. package/dist/app/assets/KodeMono-Regular-Bdr_-rJX.woff2 +0 -0
  11. package/dist/app/assets/KodeMono-SemiBold-JAfn5Dpm.ttf +0 -0
  12. package/dist/app/assets/index-CEJyT8hF.css +2 -0
  13. package/dist/app/assets/index-DWZ-48wc.js +3853 -0
  14. package/dist/app/index.html +16 -0
  15. package/dist/components/components.css +6372 -0
  16. package/dist/components/index.d.ts +1 -0
  17. package/dist/components/index.js +26609 -0
  18. package/dist/components/index.js.map +1 -0
  19. package/dist/components/types/uhd-viewer/src/api.d.ts +286 -0
  20. package/dist/components/types/uhd-viewer/src/cad/CadView.d.ts +52 -0
  21. package/dist/components/types/uhd-viewer/src/cad/ModelView.d.ts +30 -0
  22. package/dist/components/types/uhd-viewer/src/cad/explode.d.ts +110 -0
  23. package/dist/components/types/uhd-viewer/src/cad/explodeSample.d.ts +25 -0
  24. package/dist/components/types/uhd-viewer/src/cad/findings.d.ts +41 -0
  25. package/dist/components/types/uhd-viewer/src/cad/labels.d.ts +76 -0
  26. package/dist/components/types/uhd-viewer/src/cad/model.d.ts +132 -0
  27. package/dist/components/types/uhd-viewer/src/cad/row.d.ts +15 -0
  28. package/dist/components/types/uhd-viewer/src/cad/scene.d.ts +95 -0
  29. package/dist/components/types/uhd-viewer/src/cad/scope.d.ts +89 -0
  30. package/dist/components/types/uhd-viewer/src/canvas/Canvas.d.ts +90 -0
  31. package/dist/components/types/uhd-viewer/src/canvas/Icon.d.ts +5 -0
  32. package/dist/components/types/uhd-viewer/src/canvas/LinkEdge.d.ts +40 -0
  33. package/dist/components/types/uhd-viewer/src/canvas/Port.d.ts +18 -0
  34. package/dist/components/types/uhd-viewer/src/canvas/actions.d.ts +5 -0
  35. package/dist/components/types/uhd-viewer/src/canvas/geometry.d.ts +72 -0
  36. package/dist/components/types/uhd-viewer/src/canvas/interaction.d.ts +162 -0
  37. package/dist/components/types/uhd-viewer/src/canvas/nodes.d.ts +43 -0
  38. package/dist/components/types/uhd-viewer/src/canvas/reveal.d.ts +55 -0
  39. package/dist/components/types/uhd-viewer/src/canvas/rightDrag.d.ts +51 -0
  40. package/dist/components/types/uhd-viewer/src/canvas/routing.d.ts +28 -0
  41. package/dist/components/types/uhd-viewer/src/chrome/ArtifactCards.d.ts +30 -0
  42. package/dist/components/types/uhd-viewer/src/chrome/Artifacts.d.ts +44 -0
  43. package/dist/components/types/uhd-viewer/src/chrome/BoardInspector.d.ts +53 -0
  44. package/dist/components/types/uhd-viewer/src/chrome/Chrome.d.ts +126 -0
  45. package/dist/components/types/uhd-viewer/src/chrome/Evidence.d.ts +20 -0
  46. package/dist/components/types/uhd-viewer/src/chrome/InterfaceCards.d.ts +66 -0
  47. package/dist/components/types/uhd-viewer/src/chrome/PairView.d.ts +37 -0
  48. package/dist/components/types/uhd-viewer/src/chrome/Sections.d.ts +128 -0
  49. package/dist/components/types/uhd-viewer/src/components.d.ts +60 -0
  50. package/dist/components/types/uhd-viewer/src/host/channel.d.ts +49 -0
  51. package/dist/components/types/uhd-viewer/src/host/context.d.ts +29 -0
  52. package/dist/components/types/uhd-viewer/src/host/protocol.d.ts +22 -0
  53. package/dist/components/types/uhd-viewer/src/host/targets.d.ts +101 -0
  54. package/dist/components/types/uhd-viewer/src/layout/board-layout.d.ts +69 -0
  55. package/dist/components/types/uhd-viewer/src/layout/card-body.d.ts +64 -0
  56. package/dist/components/types/uhd-viewer/src/layout/layout.d.ts +94 -0
  57. package/dist/components/types/uhd-viewer/src/layout/module-layout.d.ts +32 -0
  58. package/dist/components/types/uhd-viewer/src/layout/router.d.ts +55 -0
  59. package/dist/components/types/uhd-viewer/src/layout/taps.d.ts +20 -0
  60. package/dist/components/types/uhd-viewer/src/model/artifacts.d.ts +129 -0
  61. package/dist/components/types/uhd-viewer/src/model/classification.d.ts +41 -0
  62. package/dist/components/types/uhd-viewer/src/model/diagnostics.d.ts +27 -0
  63. package/dist/components/types/uhd-viewer/src/model/evidence.d.ts +63 -0
  64. package/dist/components/types/uhd-viewer/src/model/from-uhd.d.ts +58 -0
  65. package/dist/components/types/uhd-viewer/src/model/hierarchy.d.ts +173 -0
  66. package/dist/components/types/uhd-viewer/src/model/isolate.d.ts +33 -0
  67. package/dist/components/types/uhd-viewer/src/model/level.d.ts +7 -0
  68. package/dist/components/types/uhd-viewer/src/model/nets.d.ts +53 -0
  69. package/dist/components/types/uhd-viewer/src/model/outputs.d.ts +79 -0
  70. package/dist/components/types/uhd-viewer/src/model/slots.d.ts +184 -0
  71. package/dist/components/types/uhd-viewer/src/model/types.d.ts +213 -0
  72. package/dist/components/types/uhd-viewer/src/options.d.ts +27 -0
  73. package/dist/components/types/uhd-viewer/src/source/source.d.ts +109 -0
  74. package/dist/components/types/uhd-viewer/src/source/tolerant.d.ts +45 -0
  75. package/dist/components/types/uhd-viewer/src/theme/ThemeProvider.d.ts +33 -0
  76. package/dist/components/types/uhd-viewer/src/theme/adapters.d.ts +28 -0
  77. package/dist/components/types/uhd-viewer/src/theme/resolve.d.ts +19 -0
  78. package/dist/components/types/uhd-viewer/src/theme/themes.d.ts +67 -0
  79. package/dist/components/types/uhd-viewer/src/theme/tokens.d.ts +175 -0
  80. package/dist/components/types/uhd-viewer/src/ui/Inspector.d.ts +45 -0
  81. package/dist/components/types/uhd-viewer/src/ui/Legend.d.ts +59 -0
  82. package/dist/components/types/uhd-viewer/src/ui/ScrollArea.d.ts +16 -0
  83. package/dist/components/types/uhd-viewer/src/ui/Toolbar.d.ts +49 -0
  84. package/dist/components/types/uhd-viewer/src/ui/Tooltips.d.ts +3 -0
  85. package/dist/components/types/uhd-viewer/src/ui/cx.d.ts +2 -0
  86. package/dist/components/types/uhd-viewer/src/ui/legendFit.d.ts +55 -0
  87. package/dist/components/types/uhd-viewer/src/viewer/controller.d.ts +219 -0
  88. package/dist/components/types/uhd-viewer/src/viewer/details.d.ts +81 -0
  89. package/dist/components/types/uhd-viewer/src/viewer/hierarchy.d.ts +82 -0
  90. package/dist/components/types/uhd-viewer/src/viewer/mount.d.ts +12 -0
  91. package/dist/components/types/uhd-viewer/src/viewer/views.d.ts +187 -0
  92. package/dist/headless/index.d.ts +71 -0
  93. package/dist/headless/index.js +7425 -0
  94. package/dist/headless/index.js.map +1 -0
  95. package/dist/lib/api.d.ts +252 -0
  96. package/dist/lib/uhd-viewer.css +3 -0
  97. package/dist/lib/uhd-viewer.d.ts +4 -0
  98. package/dist/lib/uhd-viewer.js +97787 -0
  99. package/package.json +110 -4
  100. package/src/styles/fonts/OFL.txt +93 -0
  101. package/src/styles/tailwind-theme.css +48 -0
@@ -0,0 +1,252 @@
1
+ /**
2
+ * The viewer's public contract for hosts (docs: protoboard-cli/docs/specs/uhd-boundary.md,
3
+ * "The viewer contract"). A host gives the viewer a UHD bundle, may replace or
4
+ * extend how artifact files resolve, may add diagnostics of its own, and may
5
+ * take over saving the layout the user edits. Nothing here names a host.
6
+ *
7
+ * This file holds types only, so the published declarations stay small.
8
+ */
9
+ import type { UhdBundle, UhdBundleDiagnostic } from "@deltarobotics/uhd";
10
+
11
+ /** URL for a definition's artifact file path, or undefined if it cannot be resolved. */
12
+ export type ArtifactResolver = (definitionId: string, filePath: string) => string | undefined;
13
+
14
+ /** A link's hand layout on one drill level. */
15
+ export interface LinkLayout {
16
+ /** Pinned waypoints [x, y] in absolute canvas coordinates (the router passes through them in order). */
17
+ waypoints?: [number, number][];
18
+ /** Label + toggle position as a fraction along the route (0..1). */
19
+ labelT?: number;
20
+ /** Label on the other side of the line (below a horizontal stretch, left of a vertical one). */
21
+ labelFlip?: boolean;
22
+ /** Harness name tab position as a fraction along the route (absent: placed automatically). */
23
+ tabT?: number;
24
+ /** Tab on the same side as the label (it defaults to the opposite side). */
25
+ tabFlip?: boolean;
26
+ }
27
+
28
+ /**
29
+ * Layout edits made in the viewer, on top of the bundle's display hints.
30
+ * Both maps are keyed by drill level (instance path joined with "/", "" = top).
31
+ */
32
+ export interface ViewerLayout {
33
+ /** Dragged node positions: top-level nodes absolute, nodes inside a container relative to it. */
34
+ positions: Record<string, Record<string, { x: number; y: number }>>;
35
+ /** Pinned waypoints and label/tab positions by link id. */
36
+ links: Record<string, Record<string, LinkLayout>>;
37
+ }
38
+
39
+ /** A view of the diagram: the pan offset in pixels and the zoom factor. */
40
+ export interface ViewerViewport {
41
+ x: number;
42
+ y: number;
43
+ zoom: number;
44
+ }
45
+
46
+ /** The tones a mark can take; each is a token of the theme (`--uhd-mark-<tone>`). */
47
+ export type NodeMarkTone = "neutral" | "info" | "ok" | "warning" | "error";
48
+
49
+ /** A host's mark on a module (`ViewerOptions.nodeMarks`). */
50
+ export interface NodeMark {
51
+ tone: NodeMarkTone;
52
+ /** What the mark means, for the tooltip. */
53
+ label?: string;
54
+ /** `"ring"`: the tone as a dashed ring instead of a filled dot, for a module that stands for something not chosen yet. Default: a dot. */
55
+ shape?: "dot" | "ring";
56
+ }
57
+
58
+ export interface ViewerOptions {
59
+ /** The bundle itself. Relative artifact paths resolve against `bundleUrl` when both are given. */
60
+ bundle?: UhdBundle;
61
+ /** Where to fetch the bundle from (used when `bundle` is not given). */
62
+ bundleUrl?: string;
63
+ /**
64
+ * Replaces or extends artifact resolution. `fallback` is the default
65
+ * resolver (the bundle's per-definition artifact bases).
66
+ */
67
+ resolveArtifact?: (definitionId: string, filePath: string, fallback: ArtifactResolver) => string | undefined;
68
+ /**
69
+ * Findings from the host, listed in the checks panel next to the bundle's
70
+ * own. Like the bundle's, they describe the nominal build and are shown for
71
+ * the nominal scenario only.
72
+ */
73
+ diagnostics?: UhdBundleDiagnostic[];
74
+ /**
75
+ * A mark per definition, by definition id: the dot in the corner of every
76
+ * module card drawn from that definition takes the mark's tone and says its
77
+ * label on hover. For what the host knows about a part and the bundle does
78
+ * not (where it comes from, whether it was reviewed). A module with no mark
79
+ * keeps the dot of its links' state.
80
+ */
81
+ nodeMarks?: Record<string, NodeMark>;
82
+ /**
83
+ * The layout edits to show (only used together with `onLayoutChange`). A
84
+ * different layout passed later through `update` replaces the viewer's
85
+ * current edits, for example after the host's saved layout changed on disk.
86
+ * Passing back what `onLayoutChange` sent changes nothing.
87
+ */
88
+ layout?: ViewerLayout;
89
+ /**
90
+ * Called (debounced) with the whole edited layout after every change. When
91
+ * given, the host owns the layout and the viewer stops keeping it in local
92
+ * storage.
93
+ */
94
+ onLayoutChange?: (layout: ViewerLayout) => void;
95
+
96
+ // ---- the host message channel (docs: README, "Host messages") ----------
97
+ /** The viewer has a model on screen and takes host messages from now on. */
98
+ onReady?: () => void;
99
+ /** Every change of the selection, in the diagram or the 3D view (null: nothing selected). */
100
+ onSelectionChanged?: (selection: ViewerSelection | null) => void;
101
+ /**
102
+ * The user asked to see where a module is defined (the inspector's OPEN
103
+ * SOURCE, a node's context menu). Given: the viewer offers these actions.
104
+ */
105
+ onOpenSource?: (request: { defId: string; instancePath?: string }) => void;
106
+ /**
107
+ * The user picked an artifact file in the inspector. Given: the host opens
108
+ * it; otherwise the viewer opens the file's URL in a new tab.
109
+ */
110
+ onOpenArtifact?: (request: { defId: string; artifactId: string }) => void;
111
+ /**
112
+ * The user asked to open a module on its own (a double-click on it, OPEN IN
113
+ * NEW TAB in its context menu): `path` is its instance path from the root.
114
+ * Given: double-click opens the module there (a host's new tab or window),
115
+ * and expanding it in place moves to the context menu. Not given:
116
+ * double-click expands the module in place.
117
+ */
118
+ onOpenModule?: (request: { path: string }) => void;
119
+ /**
120
+ * The user asked for the pair view of a link (the inspector's pair
121
+ * preview). Given: the host shows it (its own tab or window); otherwise
122
+ * the viewer opens it over the diagram. `linkId` is the link as a
123
+ * selection names it, `a` and `b` the instance paths of the two modules it
124
+ * joins.
125
+ */
126
+ onOpenPair?: (request: { linkId: string; a: string; b: string }) => void;
127
+ /**
128
+ * The user asked to inspect a module (INSPECT in its context menu): `path`
129
+ * is its instance path from the root. Given: the host shows it in an
130
+ * inspector of its own; otherwise the viewer opens its own panel. The
131
+ * module is selected either way (`onSelectionChanged` says so first).
132
+ */
133
+ onInspect?: (request: { path: string; defId?: string }) => void;
134
+ /**
135
+ * Where the user left the view of each drill level (keyed like the layout;
136
+ * only used together with `onViewportChange`). A level with a viewport
137
+ * opens on it; a level with none is fitted to the diagram.
138
+ */
139
+ viewports?: Record<string, ViewerViewport>;
140
+ /**
141
+ * Called with every level's viewport after the user pans or zooms (a fit
142
+ * the user asks for drops that level's entry). When given, the host keeps
143
+ * the viewports and the viewer stops keeping them in local storage.
144
+ */
145
+ onViewportChange?: (viewports: Record<string, ViewerViewport>) => void;
146
+ /**
147
+ * Talk to the parent window over `postMessage` (the viewer in a frame):
148
+ * host messages are accepted from `window.parent` only, and only from the
149
+ * listed origins (exact origins, `scheme://*`, or `*`; default: the page's
150
+ * own origin); events are posted to the parent, at its origin. Open actions
151
+ * then go to the parent. `true` uses the defaults. Off unless given.
152
+ */
153
+ parentWindow?: boolean | { origins?: string[] };
154
+
155
+ /**
156
+ * How the viewer looks: its own `"dark"` (default) or `"light"` theme,
157
+ * `"system"` (whichever the system prefers), `"vscode"` (follows the VS Code
158
+ * colour theme of the webview it runs in, high contrast included), a theme
159
+ * of the host's (tokens it leaves out come from the default), or an adapter
160
+ * that tells the viewer when the host's theme changes.
161
+ */
162
+ theme?: ViewerThemeOption;
163
+ }
164
+
165
+ /** A theme: values for the viewer's semantic tokens (docs: README, "Theming"). */
166
+ export interface ViewerTheme {
167
+ id: string;
168
+ label: string;
169
+ scheme: "dark" | "light" | "high-contrast" | "high-contrast-light";
170
+ /** Token values by token name (`accent`, `surface`, `textMuted`, …): any CSS value, `var(...)` included. */
171
+ tokens: Partial<Record<string, string>>;
172
+ }
173
+
174
+ /** Where a host's theme comes from, when it can change while the viewer is open. */
175
+ export interface ViewerThemeAdapter {
176
+ id: string;
177
+ current(): ViewerTheme;
178
+ subscribe?(onChange: (theme: ViewerTheme) => void): () => void;
179
+ }
180
+
181
+ export type ViewerThemeOption = "dark" | "light" | "system" | "vscode" | ViewerTheme | ViewerThemeAdapter;
182
+
183
+ /** What a view shows: the diagram or the assembled 3D model. */
184
+ export type ViewerView = "diagram" | "3d";
185
+
186
+ /**
187
+ * A selection as the host sees it. Ids are canonical paths from the root
188
+ * system: a module's instance path (`arm_fl/motor`), a link's owner path and
189
+ * id (`stack/fc_esc`, as UHD's system checks name links).
190
+ */
191
+ export interface ViewerSelection {
192
+ kind: "node" | "link";
193
+ id: string;
194
+ /** The selected module's definition id (a link's: the module that declares it). */
195
+ defId?: string;
196
+ /**
197
+ * Modules selected together (a selection box, Shift- or Ctrl-click, select all), two or more: every one, by
198
+ * path from the root. `id` is the first of them.
199
+ */
200
+ ids?: string[];
201
+ }
202
+
203
+ /** Host → viewer messages (`window.postMessage`, or the handle's methods). */
204
+ export type ViewerHostMessage =
205
+ /** Drill to the level that holds the module, select it and centre it. */
206
+ | { type: "uhd-viewer:focus"; path: string }
207
+ /**
208
+ * Select on the current level (the first id that is there; none: clear the
209
+ * selection). The diagram pans (zooming out only if it must) to bring the
210
+ * selection into view when it is not; `reveal: false` leaves the view where it is.
211
+ */
212
+ | { type: "uhd-viewer:select"; ids: string[]; reveal?: boolean }
213
+ /** Show the level of this instance path ("" is the root system). */
214
+ | { type: "uhd-viewer:drill"; path: string }
215
+ | { type: "uhd-viewer:setView"; view: ViewerView };
216
+
217
+ /** Viewer → host events (posted to the parent window, or the options' callbacks). */
218
+ export type ViewerEvent =
219
+ | { type: "uhd-viewer:ready" }
220
+ | { type: "uhd-viewer:selectionChanged"; selection: ViewerSelection | null }
221
+ | { type: "uhd-viewer:openSource"; defId: string; instancePath?: string }
222
+ | { type: "uhd-viewer:openArtifact"; defId: string; artifactId: string }
223
+ | { type: "uhd-viewer:openModule"; path: string }
224
+ | { type: "uhd-viewer:openPair"; linkId: string; a: string; b: string }
225
+ | { type: "uhd-viewer:inspect"; path: string; defId?: string };
226
+
227
+ export interface ViewerHandle {
228
+ /**
229
+ * Re-renders with changed options (a rebuilt bundle, new host diagnostics, a
230
+ * changed layout). The change is merged into the current options; giving
231
+ * `bundleUrl` without `bundle` drops a bundle given earlier and loads from
232
+ * the URL.
233
+ */
234
+ update(options: Partial<ViewerOptions>): void;
235
+ unmount(): void;
236
+ /** Drill to the level that holds the module at `path`, select it and centre it. */
237
+ focus(path: string): void;
238
+ /**
239
+ * Select on the current level: the first of `ids` drawn there (an empty list
240
+ * clears the selection), brought into view unless `reveal` is false.
241
+ */
242
+ select(ids: string[], options?: { reveal?: boolean }): void;
243
+ /** Show the level of an instance path ("" is the root system). */
244
+ drill(path: string): void;
245
+ setView(view: ViewerView): void;
246
+ /**
247
+ * Apply a host message object, as it arrives over `postMessage`. Returns
248
+ * false when it is not a valid viewer message. Messages sent before the
249
+ * model is on screen wait for it.
250
+ */
251
+ post(message: unknown): boolean;
252
+ }