@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
@@ -0,0 +1,50 @@
1
+ /** Renderer-neutral component catalog and surface runtime for MCP Apps. */
2
+ import type { AppContext } from "@mcpview/view";
3
+ import { type AdvertisedComponentCatalog, type ComponentSurface, type JsonValue, type ViewComponentDescriptor } from "@mcpview/contracts";
4
+ export { CASYS_COMPONENT_CATALOG_CAPABILITY_KEY, CASYS_SURFACE_CONTEXT_KEY, readSurfaceContext, } from "@mcpview/contracts";
5
+ export type { AdvertisedComponentCatalog, ComponentSurface, ComponentSurfaceItem, ComponentSurfaceLayout, JsonValue, SurfaceContext, SurfaceGap, SurfaceLayoutType, ViewComponentDescriptor, ViewComponentEventPorts, } from "@mcpview/contracts";
6
+ export type McpViewHostContext = AppContext<unknown>["hostContext"];
7
+ export type ComponentCleanup = () => void | Promise<void>;
8
+ export interface ViewComponentMountContext<TData, TAppContext> {
9
+ readonly data: TData;
10
+ readonly props: Readonly<Record<string, JsonValue>>;
11
+ readonly instanceId: string;
12
+ readonly appContext: TAppContext;
13
+ readonly hostContext: McpViewHostContext;
14
+ }
15
+ export interface ViewComponentDefinition<TData = unknown, TAppContext = unknown> {
16
+ readonly descriptor: ViewComponentDescriptor;
17
+ mount(target: HTMLElement, context: ViewComponentMountContext<TData, TAppContext>): void | ComponentCleanup | Promise<void | ComponentCleanup>;
18
+ }
19
+ export interface ViewComponentRegistry<TData = unknown, TAppContext = unknown> {
20
+ readonly components: Readonly<Record<string, ViewComponentDefinition<TData, TAppContext>>>;
21
+ /** Omit for component-only Apps that are meaningful only inside a host composition. */
22
+ readonly defaultSurface?: ComponentSurface;
23
+ }
24
+ export interface MountedComponentSurface {
25
+ readonly surface: ComponentSurface;
26
+ dispose(): Promise<void>;
27
+ }
28
+ export interface MountComponentSurfaceOptions<TData, TAppContext> {
29
+ readonly root: HTMLElement;
30
+ readonly registry: ViewComponentRegistry<TData, TAppContext>;
31
+ readonly data: TData;
32
+ readonly appContext: TAppContext;
33
+ readonly hostContext: McpViewHostContext;
34
+ /** Explicit surface wins; otherwise the negotiated or default surface is used. */
35
+ readonly surface?: ComponentSurface;
36
+ }
37
+ export declare function defineViewComponent<TData = unknown, TAppContext = unknown>(definition: ViewComponentDefinition<TData, TAppContext>): ViewComponentDefinition<TData, TAppContext>;
38
+ export declare function defineComponentRegistry<TData = unknown, TAppContext = unknown>(registry: ViewComponentRegistry<TData, TAppContext>): ViewComponentRegistry<TData, TAppContext>;
39
+ export declare function defineComponentSurface(surface: ComponentSurface): ComponentSurface;
40
+ /** Build the serializable value advertised in `AppConfig.capabilities.experimental`. */
41
+ export declare function componentCatalogCapabilities<TData, TAppContext>(registry: ViewComponentRegistry<TData, TAppContext>): Record<string, object>;
42
+ export declare function advertisedComponentCatalog<TData, TAppContext>(registry: ViewComponentRegistry<TData, TAppContext>): AdvertisedComponentCatalog;
43
+ /** Expose only surface identity/status for CSS and diagnostics, never component internals. */
44
+ export declare function applySurfaceContext(hostContext: McpViewHostContext, target: {
45
+ dataset: Record<string, string | undefined>;
46
+ }): void;
47
+ export declare function activeComponentSurface<TData, TAppContext>(registry: ViewComponentRegistry<TData, TAppContext>, hostContext: McpViewHostContext): ComponentSurface | undefined;
48
+ /** Mount one declarative surface and return deterministic aggregate cleanup. */
49
+ export declare function mountComponentSurface<TData, TAppContext>(options: MountComponentSurfaceOptions<TData, TAppContext>): Promise<MountedComponentSurface>;
50
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/src/components.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,KAAK,0BAA0B,EAE/B,KAAK,gBAAgB,EAErB,KAAK,SAAS,EAGd,KAAK,uBAAuB,EAE7B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,sCAAsC,EACtC,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,SAAS,EACT,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1D,MAAM,WAAW,yBAAyB,CAAC,KAAK,EAAE,WAAW;IAC3D,QAAQ,CAAC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EAC5D,OAAO,EAAE,4BAA4B,CAAC,KAAK,EAAE,WAAW,CAAC,GACxD,OAAO,CAAC,uBAAuB,CAAC,CAmDlC"}
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ /** Renderer-neutral component catalog and surface runtime for MCP Apps. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.readSurfaceContext = exports.CASYS_SURFACE_CONTEXT_KEY = exports.CASYS_COMPONENT_CATALOG_CAPABILITY_KEY = void 0;
5
+ exports.defineViewComponent = defineViewComponent;
6
+ exports.defineComponentRegistry = defineComponentRegistry;
7
+ exports.defineComponentSurface = defineComponentSurface;
8
+ exports.componentCatalogCapabilities = componentCatalogCapabilities;
9
+ exports.advertisedComponentCatalog = advertisedComponentCatalog;
10
+ exports.applySurfaceContext = applySurfaceContext;
11
+ exports.activeComponentSurface = activeComponentSurface;
12
+ exports.mountComponentSurface = mountComponentSurface;
13
+ const contracts_1 = require("@mcpview/contracts");
14
+ var contracts_2 = require("@mcpview/contracts");
15
+ Object.defineProperty(exports, "CASYS_COMPONENT_CATALOG_CAPABILITY_KEY", { enumerable: true, get: function () { return contracts_2.CASYS_COMPONENT_CATALOG_CAPABILITY_KEY; } });
16
+ Object.defineProperty(exports, "CASYS_SURFACE_CONTEXT_KEY", { enumerable: true, get: function () { return contracts_2.CASYS_SURFACE_CONTEXT_KEY; } });
17
+ Object.defineProperty(exports, "readSurfaceContext", { enumerable: true, get: function () { return contracts_2.readSurfaceContext; } });
18
+ function defineViewComponent(definition) {
19
+ const descriptor = normalizedDescriptor(definition.descriptor);
20
+ if (typeof definition.mount !== "function") {
21
+ throw new TypeError("View component must declare a mount function");
22
+ }
23
+ return Object.freeze({ ...definition, descriptor });
24
+ }
25
+ function defineComponentRegistry(registry) {
26
+ const entries = Object.entries(registry.components ?? {});
27
+ if (entries.length === 0) {
28
+ throw new TypeError("Component registry must declare at least one component");
29
+ }
30
+ for (const [id, component] of entries) {
31
+ validateComponentId(id, "Component registry key");
32
+ validateDescriptor(component.descriptor);
33
+ if (typeof component.mount !== "function") {
34
+ throw new TypeError(`Component ${JSON.stringify(id)} must declare a mount function`);
35
+ }
36
+ }
37
+ const surface = registry.defaultSurface === undefined
38
+ ? undefined
39
+ : defineComponentSurface(registry.defaultSurface);
40
+ if (surface) {
41
+ validateSurfaceComponents(surface, new Set(entries.map(([id]) => id)));
42
+ }
43
+ Object.freeze(registry.components);
44
+ return Object.freeze({
45
+ ...registry,
46
+ ...(surface ? { defaultSurface: surface } : {}),
47
+ });
48
+ }
49
+ function defineComponentSurface(surface) {
50
+ validateLayout(surface?.layout);
51
+ if (!Array.isArray(surface?.components) || surface.components.length === 0) {
52
+ throw new TypeError("Component surface must contain at least one component");
53
+ }
54
+ const instanceIds = new Set();
55
+ const components = surface.components.map((item) => {
56
+ validateComponentId(item.id, "Surface component id");
57
+ validateComponentId(item.component, "Surface component key");
58
+ if (instanceIds.has(item.id)) {
59
+ throw new TypeError(`Duplicate surface component id ${JSON.stringify(item.id)}`);
60
+ }
61
+ instanceIds.add(item.id);
62
+ if (item.area !== undefined && !/^[A-Za-z][A-Za-z0-9_-]*$/.test(item.area)) {
63
+ throw new TypeError(`Invalid surface grid area ${JSON.stringify(item.area)}`);
64
+ }
65
+ if (item.props !== undefined)
66
+ validateJsonValue(item.props, `props for ${item.id}`);
67
+ return Object.freeze({
68
+ ...item,
69
+ ...(item.props ? { props: Object.freeze({ ...item.props }) } : {}),
70
+ });
71
+ });
72
+ return Object.freeze({
73
+ layout: Object.freeze({ ...surface.layout }),
74
+ components: Object.freeze(components),
75
+ });
76
+ }
77
+ /** Build the serializable value advertised in `AppConfig.capabilities.experimental`. */
78
+ function componentCatalogCapabilities(registry) {
79
+ return {
80
+ [contracts_1.CASYS_COMPONENT_CATALOG_CAPABILITY_KEY]: advertisedComponentCatalog(registry),
81
+ };
82
+ }
83
+ function advertisedComponentCatalog(registry) {
84
+ const components = Object.fromEntries(Object.entries(registry.components).map(([id, definition]) => [
85
+ id,
86
+ normalizedDescriptor(definition.descriptor),
87
+ ]));
88
+ return Object.freeze({
89
+ components: Object.freeze(components),
90
+ ...(registry.defaultSurface ? { defaultSurface: registry.defaultSurface } : {}),
91
+ });
92
+ }
93
+ /** Expose only surface identity/status for CSS and diagnostics, never component internals. */
94
+ function applySurfaceContext(hostContext, target) {
95
+ const surface = (0, contracts_1.readSurfaceContext)(hostContext);
96
+ assignDataset(target.dataset, "casysSurfaceInstance", surface?.instanceId);
97
+ assignDataset(target.dataset, "casysSurfaceStatus", surface?.status);
98
+ assignDataset(target.dataset, "casysSurfaceSource", surface?.source);
99
+ }
100
+ function activeComponentSurface(registry, hostContext) {
101
+ const context = (0, contracts_1.readSurfaceContext)(hostContext);
102
+ return context?.status === "ready" && context.surface
103
+ ? defineComponentSurface(context.surface)
104
+ : registry.defaultSurface;
105
+ }
106
+ /** Mount one declarative surface and return deterministic aggregate cleanup. */
107
+ async function mountComponentSurface(options) {
108
+ const selected = options.surface ??
109
+ activeComponentSurface(options.registry, options.hostContext);
110
+ if (!selected) {
111
+ throw new TypeError("Component-only App requires a host-selected surface");
112
+ }
113
+ const surface = defineComponentSurface(selected);
114
+ validateSurfaceComponents(surface, new Set(Object.keys(options.registry.components)));
115
+ const container = document.createElement("div");
116
+ container.className = `mcp-view-surface mcp-view-surface-${surface.layout.type}`;
117
+ container.dataset.surfaceLayout = surface.layout.type;
118
+ applySurfaceLayout(container, surface.layout);
119
+ const cleanups = [];
120
+ try {
121
+ for (const item of surface.components) {
122
+ const definition = options.registry.components[item.component];
123
+ const slot = document.createElement("section");
124
+ slot.className = "mcp-view-component";
125
+ slot.dataset.component = item.component;
126
+ slot.dataset.componentId = item.id;
127
+ if (item.area)
128
+ slot.style.gridArea = item.area;
129
+ container.append(slot);
130
+ const cleanup = await definition.mount(slot, {
131
+ data: options.data,
132
+ props: item.props ?? {},
133
+ instanceId: item.id,
134
+ appContext: options.appContext,
135
+ hostContext: options.hostContext,
136
+ });
137
+ if (typeof cleanup === "function")
138
+ cleanups.push(cleanup);
139
+ }
140
+ }
141
+ catch (error) {
142
+ await disposeAll(cleanups);
143
+ throw error;
144
+ }
145
+ options.root.replaceChildren(container);
146
+ let disposed = false;
147
+ return {
148
+ surface,
149
+ async dispose() {
150
+ if (disposed)
151
+ return;
152
+ disposed = true;
153
+ await disposeAll(cleanups);
154
+ if (container.parentNode === options.root)
155
+ options.root.replaceChildren();
156
+ },
157
+ };
158
+ }
159
+ function applySurfaceLayout(target, layout) {
160
+ const gaps = {
161
+ none: "0",
162
+ xs: "0.25rem",
163
+ sm: "0.5rem",
164
+ md: "1rem",
165
+ lg: "1.5rem",
166
+ };
167
+ target.style.display = "grid";
168
+ // Stacked components are separated by the theme's hairlines; rows and grids keep a gap.
169
+ target.style.gap = gaps[layout.gap ?? (layout.type === "stack" ? "none" : "md")];
170
+ target.style.minWidth = "0";
171
+ if (layout.type === "row") {
172
+ target.style.gridAutoFlow = "column";
173
+ target.style.gridAutoColumns = "minmax(0, 1fr)";
174
+ }
175
+ else if (layout.type === "grid") {
176
+ target.style.gridTemplateColumns = `repeat(${layout.columns ?? 2}, minmax(0, 1fr))`;
177
+ }
178
+ else {
179
+ target.style.gridTemplateColumns = "minmax(0, 1fr)";
180
+ }
181
+ }
182
+ function validateLayout(layout) {
183
+ if (!layout || !["stack", "row", "grid"].includes(layout.type)) {
184
+ throw new TypeError("Surface layout type must be stack, row, or grid");
185
+ }
186
+ if (layout.columns !== undefined &&
187
+ (!Number.isInteger(layout.columns) || layout.columns < 1 || layout.columns > 12)) {
188
+ throw new TypeError("Surface grid columns must be an integer from 1 to 12");
189
+ }
190
+ if (layout.type !== "grid" && layout.columns !== undefined) {
191
+ throw new TypeError("Surface columns are valid only for grid layouts");
192
+ }
193
+ if (layout.gap !== undefined && !["none", "xs", "sm", "md", "lg"].includes(layout.gap)) {
194
+ throw new TypeError("Surface gap must be none, xs, sm, md, or lg");
195
+ }
196
+ }
197
+ function validateSurfaceComponents(surface, known) {
198
+ const missing = [
199
+ ...new Set(surface.components
200
+ .map((item) => item.component)
201
+ .filter((component) => !known.has(component))),
202
+ ];
203
+ if (missing.length > 0) {
204
+ throw new TypeError(`Unknown surface components: ${missing.join(", ")}`);
205
+ }
206
+ }
207
+ function validateDescriptor(descriptor) {
208
+ if (!descriptor || typeof descriptor.title !== "string" || !descriptor.title.trim()) {
209
+ throw new TypeError("View component descriptor must have a non-empty title");
210
+ }
211
+ if (descriptor.description !== undefined && typeof descriptor.description !== "string") {
212
+ throw new TypeError("View component description must be a string");
213
+ }
214
+ validateEventPorts(descriptor.events);
215
+ }
216
+ function normalizedDescriptor(descriptor) {
217
+ validateDescriptor(descriptor);
218
+ const events = descriptor.events === undefined ? undefined : Object.freeze({
219
+ ...(descriptor.events.emits ? { emits: Object.freeze([...descriptor.events.emits]) } : {}),
220
+ ...(descriptor.events.accepts
221
+ ? { accepts: Object.freeze([...descriptor.events.accepts]) }
222
+ : {}),
223
+ });
224
+ return Object.freeze({
225
+ title: descriptor.title,
226
+ ...(descriptor.description !== undefined ? { description: descriptor.description } : {}),
227
+ ...(events ? { events } : {}),
228
+ });
229
+ }
230
+ function validateEventPorts(ports) {
231
+ if (ports === undefined)
232
+ return;
233
+ if (!ports || typeof ports !== "object" || Array.isArray(ports)) {
234
+ throw new TypeError("View component events must be an object");
235
+ }
236
+ validateEventNames(ports.emits, "emits");
237
+ validateEventNames(ports.accepts, "accepts");
238
+ }
239
+ function validateEventNames(names, field) {
240
+ if (names === undefined)
241
+ return;
242
+ if (!Array.isArray(names)) {
243
+ throw new TypeError(`View component ${field} must be an array`);
244
+ }
245
+ const seen = new Set();
246
+ for (const name of names) {
247
+ if (typeof name !== "string" || !name.trim()) {
248
+ throw new TypeError(`View component ${field} names must be non-empty strings`);
249
+ }
250
+ if (seen.has(name)) {
251
+ throw new TypeError(`Duplicate View component ${field} name ${JSON.stringify(name)}`);
252
+ }
253
+ seen.add(name);
254
+ }
255
+ }
256
+ function validateComponentId(value, label) {
257
+ if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/.test(value)) {
258
+ throw new TypeError(`${label} is invalid: ${JSON.stringify(value)}`);
259
+ }
260
+ }
261
+ function validateJsonValue(value, label) {
262
+ if (value === null || typeof value === "string" || typeof value === "boolean" ||
263
+ (typeof value === "number" && Number.isFinite(value)))
264
+ return;
265
+ if (Array.isArray(value)) {
266
+ for (const entry of value)
267
+ validateJsonValue(entry, label);
268
+ return;
269
+ }
270
+ if (value && typeof value === "object") {
271
+ for (const entry of Object.values(value))
272
+ validateJsonValue(entry, label);
273
+ return;
274
+ }
275
+ throw new TypeError(`${label} must contain only JSON values`);
276
+ }
277
+ async function disposeAll(cleanups) {
278
+ const errors = [];
279
+ for (const cleanup of [...cleanups].reverse()) {
280
+ try {
281
+ await cleanup();
282
+ }
283
+ catch (error) {
284
+ errors.push(error);
285
+ }
286
+ }
287
+ if (errors.length === 1)
288
+ throw errors[0];
289
+ if (errors.length > 1)
290
+ throw new AggregateError(errors, "Component cleanup failed");
291
+ }
292
+ function assignDataset(dataset, key, value) {
293
+ if (value === undefined)
294
+ delete dataset[key];
295
+ else
296
+ dataset[key] = value;
297
+ }
@@ -0,0 +1,16 @@
1
+ /** The families the shared theme names first; the generator and the entry share them. */
2
+ export interface McpViewFontFamily {
3
+ /** Family name as the theme's font stacks quote it. */
4
+ readonly family: string;
5
+ /** Variable weight range the embedded face covers, css2 syntax. */
6
+ readonly weights: `${number}..${number}`;
7
+ /** Theme role the family is the first choice for. */
8
+ readonly role: "heading" | "body" | "mono";
9
+ }
10
+ /**
11
+ * The three families `MCP_VIEW_THEME_CSS` names first in its stacks. The theme
12
+ * falls back to system faces without them; embedding is what keeps a viewer
13
+ * rendering the same inside a host iframe with no network or a strict CSP.
14
+ */
15
+ export declare const MCP_VIEW_FONT_FAMILIES: readonly McpViewFontFamily[];
16
+ //# sourceMappingURL=font-families.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font-families.d.ts","sourceRoot":"","sources":["../../src/src/font-families.ts"],"names":[],"mappings":"AAAA,yFAAyF;AAEzF,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,GAAG,MAAM,KAAK,MAAM,EAAE,CAAC;IACzC,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;CAC5C;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,iBAAiB,EAI9D,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /** The families the shared theme names first; the generator and the entry share them. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MCP_VIEW_FONT_FAMILIES = void 0;
5
+ /**
6
+ * The three families `MCP_VIEW_THEME_CSS` names first in its stacks. The theme
7
+ * falls back to system faces without them; embedding is what keeps a viewer
8
+ * rendering the same inside a host iframe with no network or a strict CSP.
9
+ */
10
+ exports.MCP_VIEW_FONT_FAMILIES = [
11
+ { family: "Space Grotesk", weights: "500..600", role: "heading" },
12
+ { family: "Work Sans", weights: "400..500", role: "body" },
13
+ { family: "JetBrains Mono", weights: "400..600", role: "mono" },
14
+ ];
@@ -0,0 +1,2 @@
1
+ export declare const MCP_VIEW_FONTS_CSS: string;
2
+ //# sourceMappingURL=fonts-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fonts-data.d.ts","sourceRoot":"","sources":["../../src/src/fonts-data.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,EAAE,MAwChC,CAAC"}