@mcpview/components 0.0.0-stage → 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.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +593 -2
  3. package/esm/_dnt.polyfills.d.ts +12 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +15 -0
  6. package/esm/fonts.d.ts +13 -0
  7. package/esm/fonts.d.ts.map +1 -0
  8. package/esm/fonts.js +12 -0
  9. package/esm/layout.d.ts +14 -0
  10. package/esm/layout.d.ts.map +1 -0
  11. package/esm/layout.js +13 -0
  12. package/esm/mod.d.ts +19 -0
  13. package/esm/mod.d.ts.map +1 -0
  14. package/esm/mod.js +14 -0
  15. package/esm/package.json +3 -0
  16. package/esm/preact-components.d.ts +22 -0
  17. package/esm/preact-components.d.ts.map +1 -0
  18. package/esm/preact-components.js +20 -0
  19. package/esm/preact.d.ts +10 -0
  20. package/esm/preact.d.ts.map +1 -0
  21. package/esm/preact.js +9 -0
  22. package/esm/src/component-primitives.d.ts +41 -0
  23. package/esm/src/component-primitives.d.ts.map +1 -0
  24. package/esm/src/component-primitives.js +121 -0
  25. package/esm/src/components.d.ts +50 -0
  26. package/esm/src/components.d.ts.map +1 -0
  27. package/esm/src/components.js +283 -0
  28. package/esm/src/font-families.d.ts +16 -0
  29. package/esm/src/font-families.d.ts.map +1 -0
  30. package/esm/src/font-families.js +11 -0
  31. package/esm/src/fonts-data.d.ts +2 -0
  32. package/esm/src/fonts-data.d.ts.map +1 -0
  33. package/esm/src/fonts-data.js +42 -0
  34. package/esm/src/fonts.d.ts +12 -0
  35. package/esm/src/fonts.d.ts.map +1 -0
  36. package/esm/src/fonts.js +19 -0
  37. package/esm/src/i18n.d.ts +44 -0
  38. package/esm/src/i18n.d.ts.map +1 -0
  39. package/esm/src/i18n.js +98 -0
  40. package/esm/src/layout/hooks.d.ts +60 -0
  41. package/esm/src/layout/hooks.d.ts.map +1 -0
  42. package/esm/src/layout/hooks.js +121 -0
  43. package/esm/src/layout/mod.d.ts +6 -0
  44. package/esm/src/layout/mod.d.ts.map +1 -0
  45. package/esm/src/layout/mod.js +3 -0
  46. package/esm/src/layout/viewer-layout.d.ts +82 -0
  47. package/esm/src/layout/viewer-layout.d.ts.map +1 -0
  48. package/esm/src/layout/viewer-layout.js +74 -0
  49. package/esm/src/preact/components.d.ts +215 -0
  50. package/esm/src/preact/components.d.ts.map +1 -0
  51. package/esm/src/preact/components.js +176 -0
  52. package/esm/src/preact/focused-view.d.ts +42 -0
  53. package/esm/src/preact/focused-view.d.ts.map +1 -0
  54. package/esm/src/preact/focused-view.js +20 -0
  55. package/esm/src/preact/mod.d.ts +6 -0
  56. package/esm/src/preact/mod.d.ts.map +1 -0
  57. package/esm/src/preact/mod.js +3 -0
  58. package/esm/src/preact/plots.d.ts +130 -0
  59. package/esm/src/preact/plots.d.ts.map +1 -0
  60. package/esm/src/preact/plots.js +166 -0
  61. package/esm/src/preact/semantic-element.d.ts +103 -0
  62. package/esm/src/preact/semantic-element.d.ts.map +1 -0
  63. package/esm/src/preact/semantic-element.js +103 -0
  64. package/esm/src/preact/structural.d.ts +178 -0
  65. package/esm/src/preact/structural.d.ts.map +1 -0
  66. package/esm/src/preact/structural.js +147 -0
  67. package/esm/src/preact/surface.d.ts +37 -0
  68. package/esm/src/preact/surface.d.ts.map +1 -0
  69. package/esm/src/preact/surface.js +47 -0
  70. package/esm/src/surface-app.d.ts +188 -0
  71. package/esm/src/surface-app.d.ts.map +1 -0
  72. package/esm/src/surface-app.js +374 -0
  73. package/esm/src/theme.d.ts +65 -0
  74. package/esm/src/theme.d.ts.map +1 -0
  75. package/esm/src/theme.js +1964 -0
  76. package/esm/surface.d.ts +12 -0
  77. package/esm/surface.d.ts.map +1 -0
  78. package/esm/surface.js +10 -0
  79. package/package.json +68 -4
  80. package/script/_dnt.polyfills.d.ts +12 -0
  81. package/script/_dnt.polyfills.d.ts.map +1 -0
  82. package/script/_dnt.polyfills.js +16 -0
  83. package/script/fonts.d.ts +13 -0
  84. package/script/fonts.d.ts.map +1 -0
  85. package/script/fonts.js +19 -0
  86. package/script/layout.d.ts +14 -0
  87. package/script/layout.d.ts.map +1 -0
  88. package/script/layout.js +29 -0
  89. package/script/mod.d.ts +19 -0
  90. package/script/mod.d.ts.map +1 -0
  91. package/script/mod.js +40 -0
  92. package/script/package.json +3 -0
  93. package/script/preact-components.d.ts +22 -0
  94. package/script/preact-components.d.ts.map +1 -0
  95. package/script/preact-components.js +68 -0
  96. package/script/preact.d.ts +10 -0
  97. package/script/preact.d.ts.map +1 -0
  98. package/script/preact.js +25 -0
  99. package/script/src/component-primitives.d.ts +41 -0
  100. package/script/src/component-primitives.d.ts.map +1 -0
  101. package/script/src/component-primitives.js +127 -0
  102. package/script/src/components.d.ts +50 -0
  103. package/script/src/components.d.ts.map +1 -0
  104. package/script/src/components.js +297 -0
  105. package/script/src/font-families.d.ts +16 -0
  106. package/script/src/font-families.d.ts.map +1 -0
  107. package/script/src/font-families.js +14 -0
  108. package/script/src/fonts-data.d.ts +2 -0
  109. package/script/src/fonts-data.d.ts.map +1 -0
  110. package/script/src/fonts-data.js +45 -0
  111. package/script/src/fonts.d.ts +12 -0
  112. package/script/src/fonts.d.ts.map +1 -0
  113. package/script/src/fonts.js +24 -0
  114. package/script/src/i18n.d.ts +44 -0
  115. package/script/src/i18n.d.ts.map +1 -0
  116. package/script/src/i18n.js +102 -0
  117. package/script/src/layout/hooks.d.ts +60 -0
  118. package/script/src/layout/hooks.d.ts.map +1 -0
  119. package/script/src/layout/hooks.js +126 -0
  120. package/script/src/layout/mod.d.ts +6 -0
  121. package/script/src/layout/mod.d.ts.map +1 -0
  122. package/script/src/layout/mod.js +17 -0
  123. package/script/src/layout/viewer-layout.d.ts +82 -0
  124. package/script/src/layout/viewer-layout.d.ts.map +1 -0
  125. package/script/src/layout/viewer-layout.js +83 -0
  126. package/script/src/preact/components.d.ts +215 -0
  127. package/script/src/preact/components.d.ts.map +1 -0
  128. package/script/src/preact/components.js +199 -0
  129. package/script/src/preact/focused-view.d.ts +42 -0
  130. package/script/src/preact/focused-view.d.ts.map +1 -0
  131. package/script/src/preact/focused-view.js +24 -0
  132. package/script/src/preact/mod.d.ts +6 -0
  133. package/script/src/preact/mod.d.ts.map +1 -0
  134. package/script/src/preact/mod.js +55 -0
  135. package/script/src/preact/plots.d.ts +130 -0
  136. package/script/src/preact/plots.d.ts.map +1 -0
  137. package/script/src/preact/plots.js +171 -0
  138. package/script/src/preact/semantic-element.d.ts +103 -0
  139. package/script/src/preact/semantic-element.d.ts.map +1 -0
  140. package/script/src/preact/semantic-element.js +115 -0
  141. package/script/src/preact/structural.d.ts +178 -0
  142. package/script/src/preact/structural.d.ts.map +1 -0
  143. package/script/src/preact/structural.js +158 -0
  144. package/script/src/preact/surface.d.ts +37 -0
  145. package/script/src/preact/surface.d.ts.map +1 -0
  146. package/script/src/preact/surface.js +53 -0
  147. package/script/src/surface-app.d.ts +188 -0
  148. package/script/src/surface-app.d.ts.map +1 -0
  149. package/script/src/surface-app.js +379 -0
  150. package/script/src/theme.d.ts +65 -0
  151. package/script/src/theme.d.ts.map +1 -0
  152. package/script/src/theme.js +1968 -0
  153. package/script/surface.d.ts +12 -0
  154. package/script/surface.d.ts.map +1 -0
  155. package/script/surface.js +15 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Casys AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,594 @@
1
- # Temporary Holding Version
1
+ # @mcpview/components
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional presentation runtime and light-first component kit for MCP Apps. It gives provider-owned
4
+ viewers a shared visual grammar without moving their data, semantics, or rendering authority into
5
+ the host.
6
+
7
+ The intended unit is a small recorded view: one run, artifact, requirement, metric, or other bounded
8
+ object. A provider may export several whole-view resources; it should not turn one viewer into a
9
+ dashboard that contains every provider capability. In a composed host such as the Digital Thread
10
+ Whiteboard, `chip`, `row`, and `card` densities project the same semantic object while the
11
+ whole-view App remains the exact viewer opened for that object.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ # Deno (JSR)
17
+ deno add jsr:@mcpview/components
18
+
19
+ # Node (npm)
20
+ npm i @mcpview/components
21
+ ```
22
+
23
+ ## Package boundary
24
+
25
+ - `@mcpview/contracts` is dependency-free and owns serializable contracts.
26
+ - `@mcpview/view` owns the MCP App lifecycle and transport.
27
+ - `@mcpview/components` is optional. Apps that do not want the kit do not import it.
28
+ - Providers resolve references and validate values, units, limits, verdicts, and provenance. The
29
+ components display those values and never infer them.
30
+ - The host composes and opens recorded views. It does not become a native CAD, Modelica, FEA, or
31
+ SysML renderer.
32
+
33
+ The package root is renderer-neutral and carries no MCP Apps runtime: `@mcpview/view` and
34
+ `@modelcontextprotocol/ext-apps` are reached only through the `/surface` entry, which owns the App
35
+ lifecycle. The responsive layout decision and its hooks live in the `/layout` entry, which takes the
36
+ host context as a value and loads no App runtime. The embedded webfonts are reached only through the
37
+ `/fonts` entry. Preact is an optional peer and is loaded only through the Preact subpaths and
38
+ `/layout`, whose hooks are Preact:
39
+
40
+ ```ts
41
+ import { defineComponentRegistry, installMcpViewTheme } from "@mcpview/components";
42
+ import {
43
+ ArtifactRow,
44
+ BadgeGroup,
45
+ Card,
46
+ CodeBlock,
47
+ CollectionCard,
48
+ DrillHint,
49
+ ElementBody,
50
+ ElementIdent,
51
+ ElementLimit,
52
+ ElementProvenance,
53
+ ElementReading,
54
+ InlineCode,
55
+ IntervalPlot,
56
+ LimitGauge,
57
+ NoticeGroup,
58
+ PathBar,
59
+ renderStatusMessage,
60
+ Row,
61
+ SemanticElement,
62
+ SemanticList,
63
+ SeriesChart,
64
+ Skeleton,
65
+ Slot3D,
66
+ Sparkline,
67
+ StaleBanner,
68
+ TextInput,
69
+ TreeList,
70
+ TypeBadge,
71
+ } from "@mcpview/components/preact";
72
+ ```
73
+
74
+ ## Presentation vocabulary
75
+
76
+ Primitives:
77
+
78
+ - `Card`, `Badge`, `BadgeGroup`, `Button`, `Toolbar`, `Stack`, `Row`, `TextInput`, `InlineCode`,
79
+ `CodeBlock`, `Skeleton`
80
+ - `Metric`, `MetricGrid`, `KeyValueList`, `DataTable`
81
+ - `Message`, `StateMessage`, `EmptyState`, `CrossSelection`, `NoticeGroup`
82
+
83
+ Reusable structures:
84
+
85
+ - `PathBar` for local navigation inside one bounded view; a path of one item renders nothing. New
86
+ optional props: `maxVisible` (inline capacity before leading items collapse; default three),
87
+ `collapsedLabel` (accessible name of the collapsed disclosure), `backLabel` (leading step-out
88
+ control), and `PathBarItem.detail` (recorded state of a kept level, revealed in the collapsed
89
+ disclosure).
90
+ - `LimitGauge` for caller-supplied readings, bounds, labels, and tone
91
+ - `ArtifactRow` for immutable artifact identity and literal verification status
92
+ - `DrillHint` for one available drill-down, in direction `"in-view"` or `"to-model"`. Without a
93
+ callback the hint degrades to plain text so a host that cannot follow it never advertises a step
94
+ that does not exist.
95
+ - `TypeBadge` names what kind of view one level is (`"list"`, `"chart"`, or `"record"`); the caller
96
+ supplies all wording.
97
+ - `StaleBanner` marks surrounding values as recorded earlier without hiding or replacing them. Tone
98
+ defaults to `"warning"`; `"danger"` promotes the ARIA role to `alert`.
99
+ - `Slot3D` reserves a bounded area for a provider-owned renderer; without `children` the slot stays
100
+ visibly reserved. The kit renders no geometry.
101
+ - `TreeList` for a controlled hierarchy with caller-owned type wording and coverage labels;
102
+ expansion and selection state are fully caller-managed.
103
+
104
+ Numeric evidence:
105
+
106
+ - `Sparkline` for the compact shape of one recorded series, readable at chip and row density.
107
+ Requires at least two finite samples already ordered by the caller. `variant="inline"` (default)
108
+ keeps the compact mark; `variant="block"` shows the caller-supplied label and summary above a
109
+ full-width, `2.5rem`-high plot.
110
+ - `SeriesChart` for a multi-series plot on a shared finite scale. Each series requires a `mark`
111
+ field (`"line"` or `"bar"`): `"line"` connects samples with a polyline — an assertion that the
112
+ quantity existed between them; `"bar"` draws each recorded sample as an isolated mark and claims
113
+ nothing about the interval. The optional `onScrub` callback reports the pointer position on the
114
+ shared x scale (`undefined` when the pointer leaves); a series with no recorded point at that
115
+ position is absent from the readout rather than filled. The kit never interpolates, aligns to a
116
+ nearest neighbour, draws a continuity it has not measured, or invents a value — the provider
117
+ declares both the mark shape and which sample a position corresponds to. `legend?: boolean`
118
+ defaults to `true` and shows a legend for two or more series, using each caller-supplied series
119
+ label with a line or square swatch matching its mark. Set `legend={false}` to hide it. Optional
120
+ `yTicks?: readonly { value: number; label: string }[]` places caller-formatted labels on the y
121
+ scale with subtle horizontal grid lines; omitting `yTicks` keeps the plot free of grid lines.
122
+ Every tick value must be finite and within the inclusive `yMin`–`yMax` bounds. The CSS properties
123
+ `--mcp-view-series-chart-bar-width` (default `8px`) and `--mcp-view-series-chart-height` (default
124
+ `10rem`) control bar width and plot height.
125
+ - `IntervalPlot` for caller-declared deviation intervals laid out against a shared zero line. The
126
+ scale must contain zero; every bound and label is caller-supplied. Labels, interval tracks, and
127
+ readings share aligned columns across rows, including at narrow widths.
128
+
129
+ `Sparkline` and `SeriesChart` series also accept `"accent"` and `"brand"` tones. These plot-specific
130
+ choices use `--mcp-view-accent` and `--mcp-view-brand`, respectively, and do not extend
131
+ `PresentationTone` for other components.
132
+
133
+ Semantic composition:
134
+
135
+ - `SemanticElement` with `chip | row | card` density and kit-owned explicit selection
136
+ - `SemanticList` for a bounded, optionally scrollable group of row-density semantic objects
137
+ - `CollectionCard` composing `Card` and `SemanticList` into one outer-border collection
138
+ - required `ElementIdent`
139
+ - optional `ElementReading` or caller-declared `ElementLimit`, plus `ElementBody`, `ElementVerdict`,
140
+ and `ElementProvenance`
141
+ - `ElementSection` for one titled group inside the body
142
+
143
+ `viewer` is deliberately not a `SemanticElement` density. It is the provider's whole-view App,
144
+ usually composed from one `card` plus an optional `PathBar`.
145
+
146
+ ```tsx
147
+ <SemanticElement
148
+ reference={{ domain: "cad", kind: "artifact", id: "bracket.step" }}
149
+ density="card"
150
+ tone="warning"
151
+ ident={<ElementIdent marker="STEP" label="Bracket" detail="revision 4" />}
152
+ reading={<ElementReading label="Minimum thickness" value="0.84" unit="mm" />}
153
+ provenance={<ElementProvenance label="SHA-256" value={digest} />}
154
+ />;
155
+ ```
156
+
157
+ The semantic reference is structured but never dereferenced by the component. Likewise, `LimitGauge`
158
+ never derives whether a value passes a limit, and `ArtifactRow` never claims a digest was verified
159
+ unless the caller supplies that recorded status.
160
+
161
+ Use `ElementLimit` when the record contains only an authored bound. It displays the supplied
162
+ operator, value, and unit without inventing a measurement, range, satisfaction state, or verdict.
163
+
164
+ ## System states
165
+
166
+ Three components express a view's readiness without hiding or fabricating content.
167
+
168
+ `Skeleton` is a frame-first loading placeholder: it draws the structure before values arrive so
169
+ layout does not shift on load. The caller supplies an accessible label and an optional line count
170
+ (default three).
171
+
172
+ `StaleBanner` keeps dated values visible while flagging that the snapshot is not current. The caller
173
+ formats the message, including the recorded instant. The banner never refetches or replaces a value
174
+ with a gap.
175
+
176
+ `DrillHint` without a callback degrades to plain text. A host that cannot follow a drill-down step
177
+ omits `onActivate`; the hint stays visible but renders no affordance. Providers declare every
178
+ available next step without advertising actions the host cannot execute.
179
+
180
+ `NoticeGroup` gathers short notices under a single severity heading. It renders nothing when there
181
+ are no items and no `omittedLabel`, so the caller never has to guard the call site. Truncation is
182
+ stated by the caller via `omittedLabel`: the group displays only the items it was handed and never
183
+ counts what it was not given.
184
+
185
+ ## Imperative bridge
186
+
187
+ `renderStatusMessage(detail, options?)` renders a `StateMessage` into a real DOM node and returns
188
+ it. `defineView` must return a native element, so every viewer built on it previously wrote its own
189
+ Preact-to-DOM bridge; those bridges drifted in tone, ARIA role, and class. `renderStatusMessage` is
190
+ that bridge, made canonical. Without `container` it returns the rendered `.mcp-view-state` element,
191
+ so what you mount carries the class, the tone and the alert role; `className` lands on that same
192
+ node. Pass `container` to render into a node you already own, which is then what comes back. It
193
+ lives in the pure presentation module `@mcpview/components/preact/components` and does not import
194
+ `@mcpview/view`, so it is reachable from any entry that does not need the surface lifecycle.
195
+
196
+ Without `container` it returns the rendered `.mcp-view-state` element; with one it renders into the
197
+ node you passed and returns that.
198
+
199
+ ## Viewer layout
200
+
201
+ `useViewerLayout(hints, options?)` (`/layout` entry) decides one of three treatments for one viewer
202
+ root — `"wide" | "panel" | "mobile"` — from the host's word first, the browser's measure as fallback
203
+ and an explicit override on top. The three treatments are two contexts under one breakpoint
204
+ (`NARROW_BREAKPOINT`, 480px), not a width scale: under it, a finger without hover picks `mobile`,
205
+ anything else `panel`; a tablet under a finger but with room keeps `wide`. The hook measures the
206
+ element you attach `ref` to, not the window, because an iframe's width says nothing about the
207
+ screen's; the host's declared `containerDimensions.width` (then `maxWidth`) outranks that measure
208
+ because it describes the room actually granted. `boundsStyle` bounds the root on the host's declared
209
+ `height` (else `maxHeight`) instead of `100vh`, and is `undefined` when the host declares none so
210
+ the viewer stays intrinsic and lets the host auto-resize.
211
+
212
+ ```tsx
213
+ import { useViewerLayout } from "@mcpview/components/layout";
214
+
215
+ const Viewer = ({ data, context }: PreactSurfaceComponentProps<RunModel>) => {
216
+ const { ref, layout, boundsStyle } = useViewerLayout<HTMLDivElement>(context.hostContext);
217
+ return (
218
+ <div ref={ref} data-layout={layout} style={boundsStyle}>
219
+ {layout === "wide"
220
+ ? <RunTable data={data} />
221
+ : <RunRows data={data} touch={layout === "mobile"} />}
222
+ </div>
223
+ );
224
+ };
225
+ ```
226
+
227
+ `hints` is any `{ deviceCapabilities?, containerDimensions? }` — the kit's `McpViewHostContext`
228
+ satisfies it structurally, so the entry never imports `@mcpview/view`. Touch follows the host's
229
+ `deviceCapabilities` (`touch && hover !== true`: a touch-screen laptop driven by a mouse is no
230
+ phone) and only falls back to `matchMedia("(pointer: coarse)")` when the host says nothing.
231
+ `?layout=mobile` in the page query string forces a treatment for reviewing it without the matching
232
+ device; pass `{ forced: null }` to ignore the URL, or `{ forced: "panel" }` to pin one. The decision
233
+ itself — `resolveViewerLayout`, `layoutWidth`, `touchInput`, `layoutFromSearch`, `viewerBoundsStyle`
234
+ — is exported pure, and the two measuring hooks, `useContainerWidth()` and `useCoarsePointer()`, are
235
+ exported on their own.
236
+
237
+ ## Focused viewers and technical details
238
+
239
+ `FocusedView` keeps one primary visualization or reading prominent and puts optional technical
240
+ metadata behind a closed `Disclosure`. Its `status` slot stays outside that disclosure: warnings,
241
+ unavailable evidence and literal verification state remain visible. The existing surface supplies
242
+ the frame, so the preset adds no card, shadow or application chrome.
243
+
244
+ ```tsx
245
+ import { FocusedView } from "@mcpview/components/preact/components";
246
+
247
+ <FocusedView
248
+ label={labels.geometry}
249
+ hostContext={context.hostContext}
250
+ status={<StateMessage title={recorded.status}>{recorded.message}</StateMessage>}
251
+ primary={<GeometryCanvas geometry={recorded.geometry} />}
252
+ detailsLabel={labels.technicalDetails}
253
+ details={<KeyValueList layout="facts" items={recorded.provenance} />}
254
+ />;
255
+ ```
256
+
257
+ The preset calls `useViewerLayout` with the host hints and applies its container ref, `data-layout`
258
+ and height bounds. At a narrow desktop width it uses `panel`; under a finger it uses `mobile` with a
259
+ larger disclosure target. Pass `layout` only to review a forced treatment. The primary remains
260
+ provider-owned; the preset never invents a preview, a status or an evidence value.
261
+
262
+ Use `Disclosure` on its own for an inline technical section: `label` is supplied by the caller,
263
+ `children` hold the detail, and optional `open` / `onToggle(open)` expose its native state. Native
264
+ `details` / `summary` provide keyboard behavior and expanded state. Omit `open` to start closed.
265
+ `FocusedView` requires a `detailsLabel` whenever it receives `details`; omit both to render no
266
+ technical control. Keep consequential state in `status` or `primary`.
267
+
268
+ ## Theme
269
+
270
+ `installMcpViewTheme()` installs the shared CSS once. The defaults are light-first and include an
271
+ explicit dark mapping (`:root[data-theme="dark"]`, or `prefers-color-scheme` unless the host pins
272
+ `data-theme="light"`). The surface is the one frame a viewer shows — border, radius, panel and a 2px
273
+ accent→brand rule — and its stacked components are separated by hairlines, so a `stack` surface
274
+ defaults to `gap: "none"`. Inside, values sit in hairline cells rather than filled tiles.
275
+
276
+ Typography has three roles: the heading face for titles and large values, the body face for prose,
277
+ and the mono face for labels, keys, units, markers, verdicts, provenance and identifiers. Sizes come
278
+ from a px scale (`--mcp-view-size-micro` 10px … `--mcp-view-size-metric` 22px) so a host that
279
+ rescales `rem` cannot squash the datasheet. The preferred faces mirror the v2 reference
280
+ (`Space Grotesk`, `Work Sans`, `JetBrains Mono`) and fall back to native families; the theme itself
281
+ neither embeds fonts nor makes a network font request. Apps can override the stable variables
282
+ exported as `MCP_VIEW_THEME_TOKENS`:
283
+
284
+ ```css
285
+ :root {
286
+ --mcp-view-accent: #0d7c8a;
287
+ --mcp-view-brand: #8a4fa3;
288
+ --mcp-view-font-heading: "Space Grotesk", "Avenir Next", sans-serif;
289
+ --mcp-view-font-body: "Work Sans", Avenir, sans-serif;
290
+ --mcp-view-font-mono: "JetBrains Mono", "SFMono-Regular", monospace;
291
+ --mcp-view-radius: 8px;
292
+ }
293
+ ```
294
+
295
+ ### Embedded fonts
296
+
297
+ A viewer bundled into one HTML file and opened inside a host iframe usually has neither network
298
+ access nor a CSP that allows font requests, so the preferred faces would silently fall back. The
299
+ `/fonts` entry embeds them (three variable faces, latin subset, ~137 KB of base64 woff2, SIL Open
300
+ Font License 1.1). It is opt-in: import it only from the viewer bundle that wants it.
301
+
302
+ ```ts
303
+ import { installMcpViewTheme } from "@mcpview/components";
304
+ import { installMcpViewFonts } from "@mcpview/components/fonts";
305
+
306
+ installMcpViewFonts();
307
+ installMcpViewTheme();
308
+ ```
309
+
310
+ `MCP_VIEW_FONT_FAMILIES` lists the families, their weight range and the theme role each serves. The
311
+ payload lives in `src/fonts-data.ts`, generated by `deno task fonts:fetch` and drift-checked by
312
+ `deno task fonts:check`.
313
+
314
+ ## Surface App
315
+
316
+ `startSurfaceApp()` (`/surface` entry) runs the whole result-driven App lifecycle for a component
317
+ registry: it opens on a loading status, projects every tool result into one `SurfaceDisplayState`,
318
+ mounts the host-selected surface (or the registry default), remounts it when the host context
319
+ changes, guards overtaken mounts, and converts every failure into a status instead of a blank page.
320
+ A viewer supplies its registry, the projection and how a status is rendered; everything else —
321
+ `strict`, `theme`, the status labels, `onError`, `viewerSession` — has a documented default.
322
+
323
+ ```ts
324
+ import { createTranslator } from "@mcpview/components";
325
+ import { startSurfaceApp } from "@mcpview/components/surface";
326
+
327
+ const messages = createTranslator({
328
+ defaultLocale: "en",
329
+ messages: {
330
+ solvingTitle: "Solving",
331
+ solvingMessage: "The run is still open.",
332
+ },
333
+ translations: {
334
+ fr: {
335
+ solvingTitle: "Résolution",
336
+ solvingMessage: "L’exécution est encore ouverte.",
337
+ },
338
+ },
339
+ });
340
+
341
+ const app = await startSurfaceApp<RunModel>({
342
+ root,
343
+ info: { name: "Run viewer", version: "1.0.0" },
344
+ registry,
345
+ strict: true,
346
+ documentLanguage: messages.locale,
347
+ fromToolResult: async (result, host) => {
348
+ if (result.isError) return { kind: "error", message: toolErrorMessage(result) };
349
+ const model = parseRun(result.structuredContent);
350
+ if (!model) return { kind: "empty" };
351
+ if (model.pending) {
352
+ return {
353
+ kind: "notice",
354
+ title: (locale) => messages(locale)("solvingTitle"),
355
+ message: (locale) => messages(locale)("solvingMessage"),
356
+ busy: true,
357
+ };
358
+ }
359
+ return { kind: "result", result: model };
360
+ },
361
+ renderStatus: (status) => renderMyStatus(status),
362
+ });
363
+ ```
364
+
365
+ The projection may return a promise and may read server resources through `host.readServerResource`.
366
+ Without a projection, `validate` (a type guard) is applied to `structuredContent` with a JSON-text
367
+ fallback; passing both is refused with `SURFACE_APP_PROJECTION_CONFLICT`.
368
+
369
+ Every non-result state reaches `renderStatus` as one `SurfaceStatus` — `kind`, `message`, `title?`,
370
+ `tone`, `busy` and the caller's optional `code`:
371
+
372
+ | `kind` | When | `tone` | `busy` |
373
+ | ------------------ | ------------------------------------------------ | --------- | ------- |
374
+ | `loading` | before the first result, and on tool input | `info` | `true` |
375
+ | `empty` | `{ kind: "empty" }` or a rejected `validate` | `neutral` | `false` |
376
+ | `error` | `{ kind: "error" }`, a rejected session | `danger` | `false` |
377
+ | `notice` | `{ kind: "notice" }`, defaults `neutral`/`false` | given | given |
378
+ | `surface-required` | component-only registry without a host selection | `warning` | `false` |
379
+
380
+ `code` is passed through from a `notice` or `error` state and never invented, so a viewer can key
381
+ its own recovery hints on it. A projection that throws becomes a `Result rejected` error status and
382
+ wipes the previous result; to keep the last good values under the failure, return a `result` that
383
+ carries it — the scaffold does exactly that. A mount that fails or a malformed host selection stays
384
+ on the surface route as `Surface failed` or `Surface invalid`, so a corrected selection can recover
385
+ in place. All three are reported to `onError` (default `console.error`) and the App keeps running.
386
+
387
+ `surfaceFor(data)` lets a result own its composition: a returned surface is mounted as is, with
388
+ neither the host selection nor the registry default consulted, so a recorded session that replaces
389
+ the whole read model composes itself while live results keep following the host. `undefined` keeps
390
+ the host flow. It is asked on every mount of that result, remounts included; a malformed owned
391
+ surface stays on the route as `Surface invalid` and names its owner. `onTeardown` runs once when the
392
+ host tears the App down or `dispose()` runs, before the surface is disposed — the place to close
393
+ what the App holds outside its surface, such as a bridge to the parent page. Its throw goes to
394
+ `onError`.
395
+
396
+ The projection and the session subscription are registered before the App connects, so nothing the
397
+ host sends during the handshake is lost. The host context is re-applied on every
398
+ `hostcontextchanged`, including the notifications the runtime replays from the handshake; the
399
+ surface is remounted only while the surface route holds a result (a surface-route failure included)
400
+ and the context object actually moved — never while a status is shown or a transition is in flight.
401
+ `theme: false` skips the theme install at boot only — primitives still install it when they mount.
402
+
403
+ For a renderer that already follows the CSS theme tokens, `themeUpdates: "in-place"` keeps that
404
+ renderer mounted when only the host theme changes. This preserves local camera or interaction state.
405
+ Hosts that resend a complete JSON snapshot with new object identities but the same non-theme values
406
+ do not remount: comparison is structural (object key order ignored, array order kept). The default
407
+ remains `"remount"`; do not opt in if a component reads theme colors only at mount. Locale,
408
+ dimensions, styles, component selection and other value changes still remount normally in either
409
+ mode.
410
+
411
+ Generic loading, empty and failure headings follow the host locale, including `Result rejected` and
412
+ `Session rejected` after a locale change while that status is visible. `loadingLabel`, `emptyLabel`
413
+ and `surfaceRequiredLabel` also accept `(locale) => string`. `error` and `notice` `title`/`message`
414
+ accept the same `SurfaceLabel` callbacks, resolved on each visible status render so a provider
415
+ dictionary can follow the host locale without re-running `fromToolResult`, session projection or
416
+ resource reads. Literal titles, messages and `code` stay unchanged.
417
+ `documentLanguage: messages.locale` sets `document.documentElement.lang` to the selected dictionary
418
+ at boot and on locale changes; omit it to leave the document language untouched. The `messages`
419
+ option accepts a `createTranslator` catalog for additional languages. Domain values, contract
420
+ states, raw provider messages, codes, identifiers, numbers and units remain literal. Tool-result and
421
+ session projections receive `host.locale` for interface wording, never for interpreting or
422
+ validating domain values.
423
+
424
+ `startPreactSurfaceApp()` (`/preact`) is the same App with statuses rendered through
425
+ `renderStatusMessage`, plus `statusClassName` for viewer-owned styling hooks; its shell keeps the
426
+ `mcp-view-preact-surface` class 0.5 viewers style (the core default is `mcp-view-surface-shell`).
427
+ Both return a `SurfaceAppHandle` whose `show(state)` drives the App from outside the MCP lifecycle
428
+ and whose `dispose()` tears it down. Option conflicts throw `SurfaceAppError`, a `TypeError` with a
429
+ stable `code` (`SURFACE_APP_PROJECTION_CONFLICT`) and a `data.recovery` sentence; `show()` on a
430
+ handle the host already tore down rejects with `SURFACE_APP_CLOSED`.
431
+
432
+ Whole-view recorded sessions are declared in `@mcpview/contracts` and consumed through the core
433
+ resource lifecycle. `viewerSession` pairs a `validate` guard with a `toState` projection; the App
434
+ subscribes before it connects and the runtime buffers what arrives during the handshake, so a
435
+ one-shot session cannot be lost and no individual component claims `viewer.session.apply`. The 0.6
436
+ `validateSession`/`mapSessionToData`/`onInvalidSession` options of `startPreactSurfaceApp()` are
437
+ gone in 0.7.0; `viewerSession: { validate, toState, onInvalid }` is the one form.
438
+
439
+ ## Common compositions
440
+
441
+ The kit stays small and non-prescriptive, leaving assembly to the caller. When multiple viewers
442
+ build the same assembly from the same primitives, this section is what they should have found first.
443
+
444
+ For a whole-view App, place a `PathBar` before one `SemanticElement density="card"`. Put numeric
445
+ evidence inside its `ElementBody` or an `ElementSection`: a bare plot directly in
446
+ `.mcp-view-surface-stack` touches the frame edge. The card body supplies the surrounding space.
447
+
448
+ ### Named quantity section
449
+
450
+ `Card` + `MetricGrid` carries one named group of measurements. Repeat the pattern for each domain
451
+ region; `EmptyState` handles the no-data case without shifting layout.
452
+
453
+ ```tsx
454
+ <Card title="Load margins">
455
+ {items.length === 0 ? <EmptyState>No values recorded.</EmptyState> : <MetricGrid items={items} />}
456
+ </Card>;
457
+ ```
458
+
459
+ ### Datasheet body
460
+
461
+ A card-density `SemanticElement` reads as a datasheet only while every figure has one place. The
462
+ readings strip is the headline, so it shows either every measurement or none — a subset picked by
463
+ position is not a headline. Its tiles wrap into rows and a short last row widens them, so five
464
+ readings are four and one wide, never four and a hole. The body is `ElementSection`s, each naming
465
+ what it holds: measurements in a `DataTable` (one row per quantity, the unit in its own column),
466
+ documentary facts in a `KeyValueList layout="facts"`, artifacts in an `ArtifactRow`. Labels are
467
+ worded for the reader, never raw field names. One fingerprint closes the sheet in
468
+ `ElementProvenance`; nothing shown in a section is repeated there.
469
+
470
+ ```tsx
471
+ <SemanticElement
472
+ reference={reference}
473
+ density="card"
474
+ ident={<ElementIdent marker="OP" label="Operating point" detail="Admitted result · r150" />}
475
+ reading={observables.length <= READING_STRIP_LIMIT ? observables.map(toReading) : []}
476
+ body={
477
+ <ElementBody>
478
+ {observables.length > READING_STRIP_LIMIT && (
479
+ <ElementSection title="Observables">
480
+ <DataTable
481
+ label="Observables"
482
+ rows={observables}
483
+ columns={QUANTITY_COLUMNS}
484
+ rowKey={rowKey}
485
+ />
486
+ </ElementSection>
487
+ )}
488
+ <ElementSection title="Provenance">
489
+ <KeyValueList layout="facts" items={provenanceFacts} />
490
+ <ArtifactRow label="Admitted result" uri={artifact.id} fingerprint={artifact.fingerprint} />
491
+ </ElementSection>
492
+ </ElementBody>
493
+ }
494
+ provenance={<ElementProvenance label="Projection" value={projectionFingerprint} />}
495
+ />;
496
+ ```
497
+
498
+ ### Artifact collection
499
+
500
+ `CollectionCard` + `ArtifactRow` keeps a single outer border for a bounded list of immutable
501
+ artifacts. Thread the count through `eyebrow` or `actions`; `EmptyState` fills the list body when
502
+ there is nothing to show. `CollectionCard` is available since 0.3.x; the `eyebrow` slot on `Card`
503
+ accepts any `ComponentChildren`, so a plain count string requires no extra component.
504
+
505
+ ```tsx
506
+ <CollectionCard
507
+ label="Build artifacts"
508
+ title="Artifacts"
509
+ eyebrow={artifacts.length > 0 ? `${artifacts.length} items` : undefined}
510
+ >
511
+ {artifacts.length === 0
512
+ ? <EmptyState>No artifacts recorded.</EmptyState>
513
+ : artifacts.map((a) => (
514
+ <ArtifactRow
515
+ key={a.uri}
516
+ label={a.label}
517
+ uri={a.uri}
518
+ verification={a.verification}
519
+ />
520
+ ))}
521
+ </CollectionCard>;
522
+ ```
523
+
524
+ ## Contributing interface translations
525
+
526
+ English is the default and reference language. French is an optional existing translation;
527
+ additional languages are contributions, not a prerequisite for building or improving a viewer.
528
+
529
+ `createTranslator` is a small renderer-neutral dictionary helper from the package root. Keep stable
530
+ keys in a complete base dictionary, and add language dictionaries as partial overrides. Select the
531
+ translator from the current host locale when rendering, so the same recorded result can change its
532
+ interface language without changing its data.
533
+
534
+ ```ts
535
+ import { createTranslator } from "@mcpview/components";
536
+
537
+ const en = {
538
+ technicalDetails: "Technical details",
539
+ revisionLabel: "Revision {revision}",
540
+ };
541
+ const fr: Partial<Record<keyof typeof en, string>> = {
542
+ technicalDetails: "Détails techniques",
543
+ revisionLabel: "Révision {revision}",
544
+ };
545
+ const messages = createTranslator({ defaultLocale: "en", messages: en, translations: { fr } });
546
+ const t = messages(context.hostContext.locale);
547
+ t("technicalDetails");
548
+ t("revisionLabel", { revision: 17 });
549
+ messages.locale("fr-CA"); // "fr" — the dictionary actually selected
550
+ ```
551
+
552
+ Lookup falls back **per key** through the exact locale, its language parents, then the base
553
+ dictionary: with an English base, `fr-CA` → `fr` → English. A missing entry in a partial dictionary
554
+ does not hide the base text. An absent or invalid host locale uses the configured default locale;
555
+ there is no global mutable locale. `messages.locale(hostLocale)` uses that same chain and returns
556
+ the exact registered locale, the matched parent, or the canonical default — pass it as
557
+ `documentLanguage` so `document.documentElement.lang` names the selected dictionary. Keep
558
+ interpolation names such as `{revision}` intact. Render returned messages as text, never as HTML.
559
+
560
+ Translate interface labels and helper text only. Preserve authored names, payload values, units,
561
+ identifiers, digests, server messages and literal contract states such as `documentary`,
562
+ `unverified`, `unresolved` or `TRACE GAP`. Use `Intl.NumberFormat` and `Intl.DateTimeFormat` with
563
+ the host locale for presentation; formatting must not convert units or overwrite the stored
564
+ evidence.
565
+
566
+ For a new locale contribution, use this short PR checklist:
567
+
568
+ - Name the locale tag and the dictionary being extended (shared interface or a particular MCP).
569
+ - Keep existing keys stable; add any new key to the base dictionary first.
570
+ - List deliberately missing translations and preserve every interpolation placeholder.
571
+ - Include one small example showing a translated label and fallback for an untranslated key.
572
+ - Check the changed wording in a narrow viewer, including accessible labels and technical details.
573
+ - Confirm that authored data and contract states retain their original bytes and meaning.
574
+
575
+ The kit exports its English and French interface dictionaries as `MCP_VIEW_MESSAGES_EN` and
576
+ `MCP_VIEW_MESSAGES_FR`. MCPs keep their domain-specific interface dictionaries beside their viewers;
577
+ they can reuse the same helper without importing a new localization runtime.
578
+
579
+ ## Result-viewer scaffold (Deno/JSR only)
580
+
581
+ The project generator intentionally uses Deno filesystem APIs and `deno fmt`. The generated
582
+ `src/main.ts` is a component registry plus one `fromToolResult` projection handed to
583
+ `startSurfaceApp()` from `@mcpview/components/surface`; it hand-rolls no App lifecycle. Its
584
+ `build.ts` accepts `MCP_VIEW_MODULE` and `MCP_VIEW_COMPONENTS_MODULE` overrides (the `mod.ts` of a
585
+ local checkout); the `/surface` entry is derived from the latter unless
586
+ `MCP_VIEW_COMPONENTS_SURFACE_MODULE` names it. Run the generator from JSR:
587
+
588
+ ```sh
589
+ deno run -A jsr:@mcpview/components@0.11.0/scaffold result-viewer ./result-viewer
590
+ ```
591
+
592
+ The npm package contains only the runtime and presentation entry points. It does not export or ship
593
+ `@mcpview/components/scaffold`; Node ESM imports and CommonJS requires of that subpath are expected
594
+ to fail with `ERR_PACKAGE_PATH_NOT_EXPORTED` rather than loading a Deno-only module.
@@ -0,0 +1,12 @@
1
+ declare global {
2
+ interface Object {
3
+ /**
4
+ * Determines whether an object has a property with the specified name.
5
+ * @param o An object.
6
+ * @param v A property name.
7
+ */
8
+ hasOwn(o: object, v: PropertyKey): boolean;
9
+ }
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
2
+ if (!Object.hasOwn) {
3
+ Object.defineProperty(Object, "hasOwn", {
4
+ value: function (object, property) {
5
+ if (object == null) {
6
+ throw new TypeError("Cannot convert undefined or null to object");
7
+ }
8
+ return Object.prototype.hasOwnProperty.call(Object(object), property);
9
+ },
10
+ configurable: true,
11
+ enumerable: false,
12
+ writable: true,
13
+ });
14
+ }
15
+ export {};
package/esm/fonts.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Embedded webfaces for the shared theme.
3
+ *
4
+ * Import as `@mcpview/components/fonts`. Opt-in and ~140 KB: a viewer
5
+ * that must render identically inside a host iframe without network access
6
+ * calls `installMcpViewFonts()` next to `installMcpViewTheme()`; one that can
7
+ * rely on system faces leaves this entry out of its bundle.
8
+ *
9
+ * @module
10
+ */
11
+ import "./_dnt.polyfills.js";
12
+ export { installMcpViewFonts, MCP_VIEW_FONT_FAMILIES, MCP_VIEW_FONTS_CSS, MCP_VIEW_FONTS_STYLE_ID, type McpViewFontFamily, } from "./src/fonts.js";
13
+ //# sourceMappingURL=fonts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fonts.d.ts","sourceRoot":"","sources":["../src/fonts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,qBAAqB,CAAC;AAG7B,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC"}