@sparkelf/dsh-genui 0.0.0-stage → 0.11.4-patch.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 (210) hide show
  1. package/CHANGELOG.md +597 -0
  2. package/LICENSE +21 -0
  3. package/README.md +292 -2
  4. package/README.zh-CN.md +307 -0
  5. package/SKILL.md +261 -0
  6. package/cordis.patch.yml +9 -0
  7. package/demo-prompts.md +118 -0
  8. package/lib/assets/echarts-core.js +43 -0
  9. package/lib/assets/echarts-full.js +72 -0
  10. package/lib/assets/mermaid.js +3591 -0
  11. package/lib/assets/standalone-runtime.js +1506 -0
  12. package/lib/assets/three.js +3844 -0
  13. package/lib/client.js +405 -0
  14. package/lib/index.js +5187 -0
  15. package/lib/invariant.js +19 -0
  16. package/lib/types/client/EChartNode.d.ts +13 -0
  17. package/lib/types/client/ErrorBoundary.d.ts +30 -0
  18. package/lib/types/client/GenuiBlock.d.ts +9 -0
  19. package/lib/types/client/PlotBlock.d.ts +44 -0
  20. package/lib/types/client/TemplateDrawer.d.ts +7 -0
  21. package/lib/types/client/achievement-store.d.ts +35 -0
  22. package/lib/types/client/achievement-toast.d.ts +2 -0
  23. package/lib/types/client/achievements.d.ts +63 -0
  24. package/lib/types/client/action-context.d.ts +7 -0
  25. package/lib/types/client/artifact/ExportableGenuiBlock.d.ts +6 -0
  26. package/lib/types/client/artifact/create.d.ts +5 -0
  27. package/lib/types/client/artifact/download.d.ts +9 -0
  28. package/lib/types/client/artifact/html.d.ts +5 -0
  29. package/lib/types/client/artifact/index.d.ts +8 -0
  30. package/lib/types/client/artifact/json.d.ts +3 -0
  31. package/lib/types/client/artifact/parse.d.ts +3 -0
  32. package/lib/types/client/artifact/portability.d.ts +4 -0
  33. package/lib/types/client/artifact/standalone-theme.d.ts +2 -0
  34. package/lib/types/client/artifact/types.d.ts +33 -0
  35. package/lib/types/client/asset-echarts-core.d.ts +1 -0
  36. package/lib/types/client/asset-echarts.d.ts +17 -0
  37. package/lib/types/client/asset-loader.d.ts +33 -0
  38. package/lib/types/client/asset-mermaid.d.ts +1 -0
  39. package/lib/types/client/asset-three.d.ts +1 -0
  40. package/lib/types/client/blocks/advanced.d.ts +101 -0
  41. package/lib/types/client/blocks/basic.d.ts +22 -0
  42. package/lib/types/client/blocks/charts.d.ts +53 -0
  43. package/lib/types/client/blocks/checkbox.d.ts +17 -0
  44. package/lib/types/client/blocks/diagram/geometry.d.ts +73 -0
  45. package/lib/types/client/blocks/diagram/index.d.ts +5 -0
  46. package/lib/types/client/blocks/diagram/layout.d.ts +41 -0
  47. package/lib/types/client/blocks/diagram/theme.d.ts +37 -0
  48. package/lib/types/client/blocks/forms.d.ts +77 -0
  49. package/lib/types/client/blocks/image.d.ts +6 -0
  50. package/lib/types/client/blocks/render-node.d.ts +10 -0
  51. package/lib/types/client/blocks/state.d.ts +63 -0
  52. package/lib/types/client/blocks/svg.d.ts +4 -0
  53. package/lib/types/client/dom-fence.d.ts +30 -0
  54. package/lib/types/client/echarts-engine.d.ts +4 -0
  55. package/lib/types/client/echarts-lazy.d.ts +18 -0
  56. package/lib/types/client/embed.d.ts +10 -0
  57. package/lib/types/client/fence-render.d.ts +106 -0
  58. package/lib/types/client/gallery.d.ts +7 -0
  59. package/lib/types/client/genui-runtime/diagnostics.d.ts +18 -0
  60. package/lib/types/client/genui-runtime/index.d.ts +1 -0
  61. package/lib/types/client/genui-runtime/limits.d.ts +54 -0
  62. package/lib/types/client/genui-runtime/normalize.d.ts +15 -0
  63. package/lib/types/client/genui-runtime/schema.d.ts +87 -0
  64. package/lib/types/client/genui-runtime/value-utils.d.ts +18 -0
  65. package/lib/types/client/guard.d.ts +144 -0
  66. package/lib/types/client/i18n/en.d.ts +307 -0
  67. package/lib/types/client/i18n/index.d.ts +44 -0
  68. package/lib/types/client/i18n/runtime.d.ts +64 -0
  69. package/lib/types/client/i18n/zh.d.ts +8 -0
  70. package/lib/types/client/index.d.ts +36 -0
  71. package/lib/types/client/inline.d.ts +5 -0
  72. package/lib/types/client/interaction-store.d.ts +48 -0
  73. package/lib/types/client/mermaid-core.d.ts +8 -0
  74. package/lib/types/client/mermaid-lazy.d.ts +9 -0
  75. package/lib/types/client/mermaid-safe.d.ts +52 -0
  76. package/lib/types/client/panel-command.d.ts +34 -0
  77. package/lib/types/client/panel-store.d.ts +94 -0
  78. package/lib/types/client/panel.d.ts +18 -0
  79. package/lib/types/client/parse-partial.d.ts +63 -0
  80. package/lib/types/client/primitive-adapter.d.ts +4 -0
  81. package/lib/types/client/primitive-labels.d.ts +18 -0
  82. package/lib/types/client/safe-math.d.ts +43 -0
  83. package/lib/types/client/scene3d-core.d.ts +21 -0
  84. package/lib/types/client/scene3d-lazy.d.ts +8 -0
  85. package/lib/types/client/session-resolver.d.ts +8 -0
  86. package/lib/types/client/source-fence.d.ts +29 -0
  87. package/lib/types/client/spec.d.ts +709 -0
  88. package/lib/types/client/standalone/asset-loader.d.ts +2 -0
  89. package/lib/types/client/standalone/bootstrap-types.d.ts +9 -0
  90. package/lib/types/client/standalone/katex-style.d.ts +1 -0
  91. package/lib/types/client/standalone/primitive-adapter.d.ts +54 -0
  92. package/lib/types/client/standalone/runtime.d.ts +2 -0
  93. package/lib/types/client/submission-registry.d.ts +51 -0
  94. package/lib/types/client/svg-fence.d.ts +2 -0
  95. package/lib/types/client/table-details.d.ts +20 -0
  96. package/lib/types/client/templates.d.ts +41 -0
  97. package/lib/types/client/toolview.d.ts +7 -0
  98. package/lib/types/client/walk-spec.d.ts +3 -0
  99. package/lib/types/index.d.ts +1 -0
  100. package/lib/types/plugin/chart-contract.d.ts +9 -0
  101. package/lib/types/plugin/fence-feedback.d.ts +151 -0
  102. package/lib/types/plugin/genui-diagnostic.d.ts +13 -0
  103. package/lib/types/plugin/index.d.ts +35 -0
  104. package/lib/types/plugin/inline-content-diagnostic.d.ts +8 -0
  105. package/lib/types/plugin/invariant.d.ts +15 -0
  106. package/lib/types/plugin/tool.d.ts +27 -0
  107. package/lib/types/shared/fence-repair.d.ts +78 -0
  108. package/lib/types/shared/fence-resolve.d.ts +39 -0
  109. package/package.json +249 -4
  110. package/src/client/EChartNode.tsx +466 -0
  111. package/src/client/ErrorBoundary.tsx +67 -0
  112. package/src/client/GenuiBlock.module.css +2221 -0
  113. package/src/client/GenuiBlock.tsx +235 -0
  114. package/src/client/PlotBlock.module.css +171 -0
  115. package/src/client/PlotBlock.tsx +492 -0
  116. package/src/client/TemplateDrawer.module.css +152 -0
  117. package/src/client/TemplateDrawer.tsx +147 -0
  118. package/src/client/achievement-store.ts +151 -0
  119. package/src/client/achievement-toast.tsx +71 -0
  120. package/src/client/achievements.ts +160 -0
  121. package/src/client/action-context.ts +32 -0
  122. package/src/client/artifact/ArtifactExport.module.css +64 -0
  123. package/src/client/artifact/ExportableGenuiBlock.tsx +100 -0
  124. package/src/client/artifact/create.ts +69 -0
  125. package/src/client/artifact/download.ts +42 -0
  126. package/src/client/artifact/html.ts +157 -0
  127. package/src/client/artifact/index.ts +15 -0
  128. package/src/client/artifact/json.ts +6 -0
  129. package/src/client/artifact/parse.ts +32 -0
  130. package/src/client/artifact/portability.ts +47 -0
  131. package/src/client/artifact/standalone-theme.ts +94 -0
  132. package/src/client/artifact/types.ts +44 -0
  133. package/src/client/asset-echarts-core.ts +39 -0
  134. package/src/client/asset-echarts.ts +27 -0
  135. package/src/client/asset-loader.ts +96 -0
  136. package/src/client/asset-mermaid.ts +13 -0
  137. package/src/client/asset-three.ts +12 -0
  138. package/src/client/blocks/advanced.tsx +537 -0
  139. package/src/client/blocks/basic.tsx +121 -0
  140. package/src/client/blocks/charts.tsx +999 -0
  141. package/src/client/blocks/checkbox.tsx +61 -0
  142. package/src/client/blocks/diagram/geometry.ts +151 -0
  143. package/src/client/blocks/diagram/index.tsx +293 -0
  144. package/src/client/blocks/diagram/layout.ts +202 -0
  145. package/src/client/blocks/diagram/theme.ts +127 -0
  146. package/src/client/blocks/forms.tsx +531 -0
  147. package/src/client/blocks/image.tsx +28 -0
  148. package/src/client/blocks/render-node.tsx +494 -0
  149. package/src/client/blocks/state.ts +65 -0
  150. package/src/client/blocks/svg.tsx +66 -0
  151. package/src/client/dom-fence.tsx +1123 -0
  152. package/src/client/echarts-engine.ts +9 -0
  153. package/src/client/echarts-lazy.ts +41 -0
  154. package/src/client/embed.ts +19 -0
  155. package/src/client/fence-render.tsx +266 -0
  156. package/src/client/gallery.ts +215 -0
  157. package/src/client/genui-runtime/diagnostics.ts +165 -0
  158. package/src/client/genui-runtime/index.ts +1 -0
  159. package/src/client/genui-runtime/limits.ts +54 -0
  160. package/src/client/genui-runtime/normalize.ts +329 -0
  161. package/src/client/genui-runtime/schema.ts +352 -0
  162. package/src/client/genui-runtime/value-utils.ts +67 -0
  163. package/src/client/guard.ts +1965 -0
  164. package/src/client/i18n/en.ts +335 -0
  165. package/src/client/i18n/index.ts +125 -0
  166. package/src/client/i18n/runtime.ts +130 -0
  167. package/src/client/i18n/zh.ts +330 -0
  168. package/src/client/index.tsx +228 -0
  169. package/src/client/inline.ts +106 -0
  170. package/src/client/interaction-store.ts +127 -0
  171. package/src/client/mermaid-core.ts +158 -0
  172. package/src/client/mermaid-lazy.ts +31 -0
  173. package/src/client/mermaid-safe.ts +122 -0
  174. package/src/client/panel-command.ts +138 -0
  175. package/src/client/panel-store.ts +471 -0
  176. package/src/client/panel.tsx +287 -0
  177. package/src/client/parse-partial.ts +170 -0
  178. package/src/client/primitive-adapter.ts +13 -0
  179. package/src/client/primitive-labels.ts +55 -0
  180. package/src/client/safe-math.ts +298 -0
  181. package/src/client/scene3d-core.ts +195 -0
  182. package/src/client/scene3d-lazy.ts +26 -0
  183. package/src/client/session-resolver.ts +33 -0
  184. package/src/client/source-fence.ts +70 -0
  185. package/src/client/spec.ts +896 -0
  186. package/src/client/standalone/asset-loader.ts +9 -0
  187. package/src/client/standalone/bootstrap-types.ts +11 -0
  188. package/src/client/standalone/katex-style.ts +1 -0
  189. package/src/client/standalone/primitive-adapter.tsx +94 -0
  190. package/src/client/standalone/runtime.tsx +27 -0
  191. package/src/client/submission-registry.ts +150 -0
  192. package/src/client/svg-fence.tsx +39 -0
  193. package/src/client/table-details.ts +151 -0
  194. package/src/client/templates.ts +322 -0
  195. package/src/client/toolview.tsx +67 -0
  196. package/src/client/walk-spec.ts +43 -0
  197. package/src/css-modules.d.ts +5 -0
  198. package/src/index.ts +9 -0
  199. package/src/plugin/chart-contract.ts +13 -0
  200. package/src/plugin/fence-feedback.ts +655 -0
  201. package/src/plugin/genui-diagnostic.ts +112 -0
  202. package/src/plugin/index.ts +224 -0
  203. package/src/plugin/inline-content-diagnostic.ts +178 -0
  204. package/src/plugin/invariant.ts +30 -0
  205. package/src/plugin/node-shims.d.ts +31 -0
  206. package/src/plugin/tool.ts +424 -0
  207. package/src/shared/fence-repair.ts +536 -0
  208. package/src/shared/fence-resolve.ts +80 -0
  209. package/tsconfig.json +35 -0
  210. package/tsdown.config.ts +275 -0
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Editorial diagram geometry: the mandatory orthogonal-connector system from
3
+ * diagram-design §6, ported to pure functions producing SVG path strings.
4
+ *
5
+ * Rules enforced here (the "non-negotiable" list):
6
+ * 1. Rounded right-angle (orthogonal) elbows with r=8 — never diagonal lines
7
+ * between off-axis nodes.
8
+ * 2. Edge labels sit 6–10px off the stroke behind an opaque mask.
9
+ * 3. No two connectors share a path — parallel connectors offset ≥12px.
10
+ * 4. Shared-edge attach points fan ≥12px apart.
11
+ * 5. A connector never passes behind a non-endpoint box (dashed-transit
12
+ * exception only when geometrically unavoidable).
13
+ * 6. Label masks never overlap nodes (nodes paint after labels).
14
+ * @module @changfenhuang/dsh-genui/client/blocks/diagram/geometry
15
+ */
16
+ /** Axis-aligned box. */
17
+ export interface Box {
18
+ x: number;
19
+ y: number;
20
+ w: number;
21
+ h: number;
22
+ }
23
+ export interface Point {
24
+ x: number;
25
+ y: number;
26
+ }
27
+ export type Port = 'left' | 'right' | 'top' | 'bottom';
28
+ /** Attachment on a box edge. */
29
+ export interface Attach {
30
+ x: number;
31
+ y: number;
32
+ port: Port;
33
+ }
34
+ /** Center of a box. */
35
+ export declare function center(b: Box): Point;
36
+ /**
37
+ * Pick the attach point on `from` toward `to`. Port choice follows the
38
+ * dominant axis: mostly-horizontal travel uses left/right ports, mostly-
39
+ * vertical uses top/bottom. An explicit `prefer` overrides the heuristic.
40
+ */
41
+ export declare function attachPoint(box: Box, toward: Box, prefer: Port | undefined): Attach;
42
+ /**
43
+ * Build an orthogonal path between two attach points. Same-axis endpoints use
44
+ * a straight segment (the one sanctioned case); every bend is a quarter arc
45
+ * of radius R.
46
+ */
47
+ export declare function orthogonalPath(a: Attach, b: Attach): string;
48
+ /**
49
+ * Route a connector between two boxes with default port selection, returning
50
+ * the path plus both attach points (for label placement and fan offsets).
51
+ */
52
+ export declare function routeEdge(from: Box, to: Box, opts?: {
53
+ fromPort?: Port;
54
+ toPort?: Port;
55
+ }): {
56
+ d: string;
57
+ a: Attach;
58
+ b: Attach;
59
+ };
60
+ /** Fan an attach point along a box edge (≥12px apart via the (k+1)/(n+1) rule). */
61
+ export declare function fanPoint(box: Box, edge: 'top' | 'bottom' | 'left' | 'right', index: number, count: number): Attach;
62
+ /**
63
+ * Edge-label geometry: centered on the dominant segment, offset 6–10px from
64
+ * the stroke so the connector stays visible.
65
+ */
66
+ export declare function labelGeometry(a: Attach, b: Attach): {
67
+ cx: number;
68
+ cy: number;
69
+ maskY: number;
70
+ vertical: boolean;
71
+ };
72
+ /** Hop / bridge arc for a crossing connector (applied to the less important edge). */
73
+ export declare function bridgePath(cx: number, cy: number, horizontal: boolean): string;
@@ -0,0 +1,5 @@
1
+ import type { GenuiDiagram } from '../../spec.ts';
2
+ /** The `diagram` node renderer. */
3
+ export declare function DiagramNode({ node }: {
4
+ node: GenuiDiagram;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Editorial diagram layout: resolves a `diagram` spec into positioned boxes
3
+ * and routed edges. Two layout modes mirror diagram-design's grammar:
4
+ *
5
+ * - Coordinate kinds (architecture, it-state, high-level, process,
6
+ * medallion, data-flow, dp-integration): the spec carries x/y/w/h per
7
+ * node; this module passes them through (4px-grid already enforced by the
8
+ * guard) and routes edges.
9
+ * - Rule kinds (flowchart, sequence, state, er, timeline, swimlane,
10
+ * quadrant, radar, loop, nested, tree, org-chart, layers, venn, pyramid,
11
+ * bar, line, gantt, scatter, dp-security-matrix): the spec carries data
12
+ * only; this module lays the nodes out on the editorial grid.
13
+ *
14
+ * The output is a plain layout object consumed by the SVG renderer — no
15
+ * React, no DOM, fully unit-testable.
16
+ * @module @changfenhuang/dsh-genui/client/blocks/diagram/layout
17
+ */
18
+ import type { GenuiDiagram, GenuiDiagramEdge, GenuiDiagramNode } from '../../spec.ts';
19
+ import { Box } from './geometry.ts';
20
+ export interface LayoutNode {
21
+ node: GenuiDiagramNode;
22
+ box: Box;
23
+ }
24
+ export interface LayoutEdge {
25
+ edge: GenuiDiagramEdge;
26
+ /** Resolved box references for routing. */
27
+ fromId: string;
28
+ toId: string;
29
+ }
30
+ export interface DiagramLayout {
31
+ nodes: LayoutNode[];
32
+ edges: LayoutEdge[];
33
+ /** Canvas size (width/height). */
34
+ width: number;
35
+ height: number;
36
+ }
37
+ /**
38
+ * Resolve a diagram spec into a positioned layout. `parentOf` lets tree-like
39
+ * kinds pass their hierarchy; other rule kinds use a generic grid.
40
+ */
41
+ export declare function resolveLayout(diagram: GenuiDiagram, parentOf?: (id: string) => string | undefined): DiagramLayout;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Editorial diagram theme: the diagram-design semantic-token system ported
3
+ * into the dsh-genui renderer. Every diagram draws from these roles — never
4
+ * from inline hex in the layout code — and a spec-level `theme` override
5
+ * merges over the defaults, mirroring diagram-design's style-guide.md.
6
+ *
7
+ * Two skins ship: light and dark (the dark palette is the jet-black
8
+ * inversion, same roles). The `editorial` variant is the full skin and
9
+ * defaults to light unless the host theme is dark.
10
+ * @module @changfenhuang/dsh-genui/client/blocks/diagram/theme
11
+ */
12
+ import type { GenuiDiagramTheme, GenuiDiagramVariant } from '../../spec.ts';
13
+ export interface DiagramPalette {
14
+ paper: string;
15
+ paper2: string;
16
+ ink: string;
17
+ muted: string;
18
+ soft: string;
19
+ rule: string;
20
+ accent: string;
21
+ accentTint: string;
22
+ link: string;
23
+ }
24
+ /** Native SVG paint values keep inherited host tokens live across theme changes. */
25
+ export declare function hostPalette(): DiagramPalette;
26
+ /** Resolve the active palette from variant + optional theme overrides. */
27
+ export declare function resolvePalette(variant: GenuiDiagramVariant | undefined, theme: GenuiDiagramTheme | undefined): DiagramPalette;
28
+ /** Node treatment → { fill, stroke, dashed } per diagram-design §5. */
29
+ export declare function nodeTreatment(type: string | undefined, p: DiagramPalette): {
30
+ fill: string;
31
+ stroke: string;
32
+ dashed?: boolean;
33
+ };
34
+ /** Edge stroke color per semantic kind. */
35
+ export declare function edgeStroke(kind: string | undefined, p: DiagramPalette): string;
36
+ /** Apply opacity while retaining live host-token references. */
37
+ export declare function inkAt(color: string, opacity: number): string;
@@ -0,0 +1,77 @@
1
+ import type { RadioSubmissionMember } from '../submission-registry.ts';
2
+ import type { AnswersState, GenuiBlockProps } from './state.ts';
3
+ import type { GenuiInput, GenuiRadio, GenuiSelect, GenuiSlider, GenuiSubmit, GenuiSwitch, GenuiTextarea } from '../spec.ts';
4
+ export declare function RadioNode({ node, onAction, answers }: {
5
+ node: GenuiRadio;
6
+ onAction?: GenuiBlockProps['onAction'];
7
+ answers?: AnswersState | undefined;
8
+ }): import("react").JSX.Element;
9
+ /** 根据静态 radio member 获取正确选项的标签。 */
10
+ export declare function correctLabelOf(m: RadioSubmissionMember): string | undefined;
11
+ /** 汇总当前 block 的表单状态,并根据 resolver 的结果提交或本地判卷。 */
12
+ export declare function SubmitNode({ node, onAction, answers }: {
13
+ node: GenuiSubmit;
14
+ onAction?: GenuiBlockProps['onAction'];
15
+ answers?: AnswersState | undefined;
16
+ }): import("react").JSX.Element;
17
+ /** Switch: toggle with local state. */
18
+ export declare function SwitchNode({ node, onAction }: {
19
+ node: GenuiSwitch;
20
+ onAction?: GenuiBlockProps['onAction'];
21
+ }): import("react").JSX.Element;
22
+ /** Slider: range input for numeric form values (v2.9). Field-aligned: with an
23
+ * `id` the value persists across refresh and joins the sibling submit's
24
+ * `fields` collection (stored as the numeric string); a model-provided
25
+ * default registers at mount; a restored durable value wins. Dragging fires
26
+ * the action (block-level debounce collapses the drag into one delivery). */
27
+ export declare function SliderNode({ node, onAction, answers }: {
28
+ node: GenuiSlider;
29
+ onAction?: GenuiBlockProps['onAction'];
30
+ answers?: AnswersState | undefined;
31
+ }): import("react").JSX.Element;
32
+ /** Reuse the DSH main input's three-layer IME protection (verified in the
33
+ * host InputBar): composition start arms a ref, composition end clears it
34
+ * 10ms later (Safari sends the closing keydown BEFORE compositionend), and
35
+ * every submit keydown re-checks the ref, the native `isComposing` flag,
36
+ * and `keyCode === 229`. A Chinese selection Enter must never submit. */
37
+ export declare function useImeComposing(): {
38
+ isComposing: () => boolean;
39
+ onCompositionStart: () => void;
40
+ onCompositionEnd: () => void;
41
+ };
42
+ export declare function isImeSubmitKeydown(e: React.KeyboardEvent): boolean;
43
+ /** Select: single choice from a dropdown, field-aligned (v2.8). With an `id`
44
+ * the chosen option persists across refresh and joins the sibling submit's
45
+ * `fields` collection; a model-provided `selected` default registers at
46
+ * mount; a restored durable value wins over both. Without any default a
47
+ * placeholder option shows — nothing is silently pre-registered (same
48
+ * philosophy as radio). */
49
+ export declare function SelectNode({ node, onAction, answers }: {
50
+ node: GenuiSelect;
51
+ onAction?: GenuiBlockProps['onAction'];
52
+ answers?: AnswersState | undefined;
53
+ }): import("react").JSX.Element;
54
+ /** Input: single-line field. Controlled (value tracked for persistence and
55
+ * submit collection when `id` is set). With `action`: Enter submits
56
+ * immediately (`{type:'input', value, submit:true}`), blur sends too —
57
+ * the user never has to click elsewhere for the value to reach the model.
58
+ * Enter during IME composition never submits. `inputType: 'password'`
59
+ * stays masked; its value is never persisted and never joins submit
60
+ * collection (secrets stay out of localStorage), while its own `action`
61
+ * still delivers on explicit user submit. */
62
+ export declare function InputNode({ node, onAction, answers }: {
63
+ node: GenuiInput;
64
+ onAction?: GenuiBlockProps['onAction'];
65
+ answers?: AnswersState | undefined;
66
+ }): import("react").JSX.Element;
67
+ /** Textarea: multi-line input; with `action`, blurring sends the value and
68
+ * Ctrl/Cmd+Enter submits immediately. Controlled when `id` is set (durable
69
+ * value + submit collection). Ctrl/Cmd+Enter during IME composition never
70
+ * submits. */
71
+ export declare function TextareaNode({ node, onAction, answers }: {
72
+ node: GenuiTextarea;
73
+ onAction?: GenuiBlockProps['onAction'];
74
+ answers?: AnswersState | undefined;
75
+ }): import("react").JSX.Element;
76
+ /** Accordion: collapsible sections with local open state. Headings and
77
+ * bodies are wired via useId (`aria-controls`/`aria-labelledby`). */
@@ -0,0 +1,6 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { GenuiImage } from '../spec.ts';
3
+ /** Native image display; source safety is enforced by repairGenuiSpec/safeMediaSrc. */
4
+ export declare function ImageNode({ node }: {
5
+ node: GenuiImage;
6
+ }): ReactNode;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The recursive render dispatcher: maps the white-listed GenuiNode union to
3
+ * concrete components. Leaf cases render inline; compound families live in
4
+ * the sibling block modules. Depth-guarded against pathological specs.
5
+ * @module @changfenhuang/dsh-genui/client/blocks/render-node
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import type { GenuiNode } from '../spec.ts';
9
+ import type { AnswersState, GenuiBlockProps } from './state.ts';
10
+ export declare function renderNode(node: GenuiNode, key: number, onAction: GenuiBlockProps['onAction'] | undefined, depth?: number, answers?: AnswersState): ReactNode;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Shared block-level state types: the block props contract and the answers
3
+ * registry (grouped radios / checkboxes → submit aggregation). Lives OUTSIDE
4
+ * GenuiBlock.tsx so the per-family block modules can import the types without
5
+ * a cycle back into the block shell.
6
+ * @module @changfenhuang/dsh-genui/client/blocks/state
7
+ */
8
+ import type { GenuiSpec } from '../spec.ts';
9
+ import type { BlockInteractionState } from '../interaction-store.ts';
10
+ import type { SubmissionRegistry } from '../submission-registry.ts';
11
+ export interface GenuiBlockProps {
12
+ /** Parsed spec to render. */
13
+ spec: GenuiSpec;
14
+ /**
15
+ * v2: optional action callback. Interactive components carrying an
16
+ * `action` field fire it (button click, switch toggle, form submit);
17
+ * absent = components are display-only (v1 behavior).
18
+ */
19
+ onAction?: ((action: string, payload: Record<string, unknown>) => void) | undefined;
20
+ /**
21
+ * v2.7: durable-state key (session + slot + content fingerprint). When set,
22
+ * interaction state (radio answers, checkbox groups, submit lock, field
23
+ * values) persists to localStorage and restores on refresh / re-render of
24
+ * the same content. Changing an existing key starts a fresh interaction
25
+ * lifetime; a streaming instance adopts its first key without losing input.
26
+ * GenuiBlock owns the matching React identity.
27
+ */
28
+ stateKey?: string | undefined;
29
+ /** Animate newly arriving items; settled message replays opt out. */
30
+ animateEntrance?: boolean | undefined;
31
+ /** Native hosts own durable state instead of the browser store. Read once per stateKey. */
32
+ initialState?: BlockInteractionState | undefined;
33
+ onStateChange?: ((state: BlockInteractionState) => void) | undefined;
34
+ /** Observe the current secret-free durable state without changing persistence ownership. */
35
+ onStateSnapshot?: ((state: BlockInteractionState) => void) | undefined;
36
+ }
37
+ /** Block-wide aggregation state. Grouped radios store one selected label in
38
+ * `answers`; grouped checkboxes store a selected-label array in
39
+ * `multiAnswers`. Keeping the registries separate preserves the existing
40
+ * radio/local-grading string contract while allowing submit to expose one
41
+ * unified `answers` payload (`string | string[]`). */
42
+ export interface AnswersState {
43
+ answers: Record<string, string>;
44
+ /** Grouped checkbox selections. An empty array is meaningful: the user
45
+ * explicitly cleared the group, so model-provided `checked` defaults must
46
+ * not reappear after a durable restore. */
47
+ multiAnswers: Record<string, string[]>;
48
+ /** Field values by id (input/textarea with an `id`), collected by submit. */
49
+ fields: Record<string, string>;
50
+ /** Field ids whose value must never be persisted or collected (secrets). */
51
+ secretFields: ReadonlySet<string>;
52
+ registry: SubmissionRegistry;
53
+ /** True after a local grading: questions are locked until 重新作答. */
54
+ locked: boolean;
55
+ /** Bumped by every reset; radios use it as their remount key. */
56
+ round: number;
57
+ setAnswer: (group: string, choice: string) => void;
58
+ setMultiAnswer: (group: string, choice: string, checked: boolean) => void;
59
+ setField: (id: string, value: string) => void;
60
+ registerSecretField: (id: string) => void;
61
+ clear: () => void;
62
+ setLocked: (locked: boolean) => void;
63
+ }
@@ -0,0 +1,4 @@
1
+ import type { GenuiSvg } from '../spec.ts';
2
+ export declare function SvgNode({ node }: {
3
+ node: GenuiSvg;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { type Root } from 'react-dom/client';
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import type { SessionId } from '@deepseek-ai/dsh-session/types';
4
+ /** Override the React root factory (tests / tuning). */
5
+ export declare function setDomRootFactory(factory: (container: HTMLElement) => Root): void;
6
+ /**
7
+ * Resolve source language for the host code surface at its assistant-row ordinal.
8
+ *
9
+ * @param ctx - active plugin context
10
+ * @param block - host Markdown CodeBlock element
11
+ * @returns source language, null for an unlabelled fence, or undefined when unavailable
12
+ */
13
+ export declare function sourceLanguageOf(ctx: Context, block: Element): string | null | undefined;
14
+ /**
15
+ * Resolve a host CodeBlock's zero-based ordinal among assistant Markdown surfaces.
16
+ *
17
+ * @param row - owning assistant row
18
+ * @param block - host Markdown CodeBlock element
19
+ * @returns source-order ordinal or -1 when the element is not a host code surface
20
+ */
21
+ export declare function hostFenceIndexOf(row: Element, block: Element): number;
22
+ /**
23
+ * Install the DOM render channel. Returns a disposer that restores every
24
+ * taken-over block and disconnects the observers.
25
+ *
26
+ * @param ctx - the client context (sessions service for the current session).
27
+ * @param sendAction - plugin-owned relay: (sessionId, action, payload) → the
28
+ * scoped conversation send carrying the `[genui-action]` prompt.
29
+ */
30
+ export declare function installDomFenceRenderer(ctx: Context, sendAction: (sessionId: SessionId, action: string, payload: Record<string, unknown>) => void): () => void;
@@ -0,0 +1,4 @@
1
+ import type { GenuiEChart } from './spec.ts';
2
+ export declare const CORE_PRESETS: ReadonlySet<string>;
3
+ /** 依照 renderer 共用的 preset 规则选择 ECharts 资源。 */
4
+ export declare function echartEngineFor(node: GenuiEChart): 'echarts-core' | 'echarts-full';
@@ -0,0 +1,18 @@
1
+ export { CORE_PRESETS } from './echarts-engine.ts';
2
+ /** The ECharts instance surface (the subset the component uses). */
3
+ export interface EChartsInstance {
4
+ setOption: (opt: unknown, notMerge?: boolean) => void;
5
+ resize: () => void;
6
+ dispose: () => void;
7
+ }
8
+ /**
9
+ * Create an ECharts instance on `el` with the given option (engine loaded on
10
+ * demand). The caller owns the returned instance and must dispose it.
11
+ * @param el - the DOM node to host the chart canvas.
12
+ * @param option - the ECharts option object.
13
+ * @param opts - optional height override.
14
+ * @returns the ECharts instance (setOption/resize/dispose).
15
+ */
16
+ export declare function createChart(el: HTMLElement, option: unknown, opts?: {
17
+ height?: number;
18
+ }, engine?: 'core' | 'full'): Promise<EChartsInstance>;
@@ -0,0 +1,10 @@
1
+ /** Public bundler entry for hosts that embed GenUI without the DSH plugin runtime. */
2
+ export { GenuiBlock } from './GenuiBlock.tsx';
3
+ export { GenuiActionContext } from './action-context.ts';
4
+ export { ErrorBoundary } from './ErrorBoundary.tsx';
5
+ export { isRenderableProcess, processGenuiSpec } from './guard.ts';
6
+ export { setGenuiAssetBase } from './asset-loader.ts';
7
+ export type { GenuiSpec } from './spec.ts';
8
+ export type { BlockInteractionState } from './interaction-store.ts';
9
+ export { analyzeGenuiPortability, buildStandaloneHtml, createGenuiArtifact, downloadGenuiArtifactHtml, downloadGenuiArtifactJson, parseGenuiArtifact, serializeGenuiArtifact, } from './artifact/index.ts';
10
+ export type { GenuiArtifactV1, GenuiPortabilityReport } from './artifact/index.ts';
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The dsh-ui fence render pipeline, shared by both render channels:
3
+ *
4
+ * - **Registry channel** (contract hosts): the host's MarkdownText resolves
5
+ * ```dsh-ui fences through the fence-registry extension point and calls
6
+ * {@link renderGenuiFence} with a session-scoped context (sessionId + the
7
+ * settled source identity). An unrepairable body renders {@link FenceFallback}.
8
+ * - **DOM channel** (pristine hosts, no extension point): the DOM observer
9
+ * (`dom-fence.ts`) finds stock code blocks labelled `dsh-ui` and mounts
10
+ * {@link renderResolvedFenceNode} into its own React root, wrapped in the
11
+ * plugin-owned action context. An unrepairable body returns `null` so the
12
+ * stock code block stays visible, with {@link FenceDiagnostic} mounted above
13
+ * it so the defect is never silent (issue #158).
14
+ *
15
+ * Structural types are declared locally on purpose: the context contract is
16
+ * a data shape, and pristine hosts do not export the host-side type names.
17
+ */
18
+ import { type Key, type ReactNode } from 'react';
19
+ import type { GenuiSpec } from './spec.ts';
20
+ /** Settled fence source identity (data shape, host-independent). */
21
+ export interface GenuiFenceSource {
22
+ /** Stable structural id, e.g. `['assistant', seq, block, fence]` or `dom:<anchor>:<i>`. */
23
+ readonly id: string;
24
+ /** Three-part order: [messageSeq, textBlockIndex, fenceIndex]. */
25
+ readonly order: readonly [number, number, number];
26
+ }
27
+ /** Context a fence renderer receives beside the raw source and React key. */
28
+ export interface GenuiFenceContext {
29
+ /** Owning session route; absent outside a session-scoped render. */
30
+ readonly sessionId?: string;
31
+ /** Present only for settled/interrupted renders with a stable identity. */
32
+ readonly source?: GenuiFenceSource;
33
+ }
34
+ /**
35
+ * Fallback for a ```dsh-ui fence whose body has no finished component yet.
36
+ * Two very different situations land here and they must not be conflated:
37
+ *
38
+ * 1. **Streaming partial** — the reply is still being written and the JSON
39
+ * simply is not complete. The host marks the streaming message with
40
+ * `[data-streaming]` on the AssistantMarkdown root, which is an ancestor
41
+ * of every fence. While that marker is present, a plain code block is the
42
+ * correct rendering (partial JSON must never look like an error).
43
+ *
44
+ * 2. **Settled defect** — the message is finished but the body still does
45
+ * not parse as JSON (a malformed fence like a missing `}`) or violates the
46
+ * native chart contract. This used to fail silently: the fence degraded to
47
+ * a code block with no hint, and the author had no way to know the UI never
48
+ * rendered. Once the streaming marker is gone, surface a compact diagnostic
49
+ * so the defect is visible instead of silent.
50
+ */
51
+ /**
52
+ * Explain why a ```dsh-ui body cannot render, as the one-line message both
53
+ * channels show. Returns null when there is nothing to report (the body is
54
+ * renderable, or it is an empty/streaming half).
55
+ *
56
+ * @param raw - the raw fence body.
57
+ * @param options - whether settled-only structural repair may be used.
58
+ * @returns the diagnostic text, or null.
59
+ */
60
+ export declare function describeFenceFailure(raw: string, options?: {
61
+ settled?: boolean;
62
+ }): string | null;
63
+ /**
64
+ * The visible diagnostic for a settled, unrenderable ```dsh-ui body.
65
+ *
66
+ * Shared by both channels: the registry channel renders it above its own
67
+ * fallback code block, the DOM channel above the host's stock code block. A
68
+ * fence that keeps degrading to raw JSON must say why it degraded — the
69
+ * console-only path left the defect invisible (issues #158/#172).
70
+ *
71
+ * @param raw - the raw fence body.
72
+ * @returns the alert strip, or null when the body has nothing to report.
73
+ */
74
+ export declare function FenceDiagnostic({ raw, settled }: {
75
+ raw: string;
76
+ settled?: boolean;
77
+ }): ReactNode;
78
+ /**
79
+ * Resolve a raw fence body to a guarded spec.
80
+ *
81
+ * - Tier-1 repair (quote escape + trailing commas): safe at any time —
82
+ * adopted only when the whole body parses, so a still-growing streaming
83
+ * half keeps falling back to the code block, never flashing a banner.
84
+ * - Tier-2 completion (missing quotes/brackets): settled renders only —
85
+ * `context.source` exists exclusively once the message finished, so
86
+ * streaming halves are never completed early.
87
+ * - Native chart semantics are checked before repair on every candidate so
88
+ * aliases, empty collections, or line/donut series cannot repair into a
89
+ * default/blank chart.
90
+ */
91
+ export declare function resolveGenuiSpec(raw: string, context?: GenuiFenceContext): GenuiSpec | null;
92
+ /**
93
+ * The resolved fence render for the DOM channel: `null` when the body is
94
+ * unrepairable (the stock code block stays visible), otherwise the panel
95
+ * publisher (`panel:true`; renders nothing in the flow — mounted as an empty
96
+ * root so the taken-over block is hidden) or the inline GenuiBlock tree.
97
+ * Shared verbatim by both channels.
98
+ */
99
+ export declare function renderResolvedFenceNode(raw: string, key: Key, context?: GenuiFenceContext): ReactNode | null;
100
+ /**
101
+ * Registry-channel fence renderer (contract hosts): like the resolved node,
102
+ * but an unrepairable body renders the fallback code block + settled
103
+ * diagnostic — the host replaced its own block with our output — and an
104
+ * unpublishable `panel:true` fence renders `null` (nothing in the flow).
105
+ */
106
+ export declare function renderGenuiFence(raw: string, key: Key, context?: GenuiFenceContext): ReactNode;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * GenUI gallery: canonical broad-coverage sample of built-in node types.
3
+ * Docs, demos, and renderer tests reuse it as the component gallery fence.
4
+ */
5
+ import type { GenuiSpec } from './spec.ts';
6
+ /** Canonical gallery spec for the built-in GenUI component vocabulary. */
7
+ export declare const gallerySpec: GenuiSpec;
@@ -0,0 +1,18 @@
1
+ export interface GenuiDiagnostic {
2
+ readonly kind: 'alias' | 'unknown-field';
3
+ readonly path: string;
4
+ readonly message: string;
5
+ readonly type?: string;
6
+ readonly field?: string;
7
+ readonly canonical?: string;
8
+ }
9
+ /**
10
+ * Diagnose unknown direct fields on native nodes.
11
+ *
12
+ * Unknown types are intentionally skipped so custom renderers retain their
13
+ * opaque extension payloads. Native unknown fields are warnings, not errors.
14
+ *
15
+ * @param value - Canonical or raw GenUI value.
16
+ * @returns Stable field diagnostics in tree order.
17
+ */
18
+ export declare function diagnoseUnknownGenuiFields(value: unknown): GenuiDiagnostic[];
@@ -0,0 +1 @@
1
+ export { GENUI_LIMITS } from './limits.ts';
@@ -0,0 +1,54 @@
1
+ /** Resource limits shared by GenUI repair, validation, and rendering. */
2
+ export declare const GENUI_LIMITS: {
3
+ /** Maximum nesting depth of the component tree. */
4
+ readonly maxDepth: 8;
5
+ /** Maximum total nodes across the whole spec. */
6
+ readonly maxNodes: 200;
7
+ /** Maximum length of any plain string field. */
8
+ readonly maxString: 2000;
9
+ /** Maximum length of a `code` body. */
10
+ readonly maxCode: 12000;
11
+ /** Maximum length of a mermaid source. */
12
+ readonly maxMermaid: 8000;
13
+ /** Maximum `grid` columns. */
14
+ readonly maxGridCols: 12;
15
+ /** Maximum `tabs` count. */
16
+ readonly maxTabs: 12;
17
+ /** Maximum `accordion` items. */
18
+ readonly maxAccordionItems: 24;
19
+ /** Maximum `list` items. */
20
+ readonly maxListItems: 50;
21
+ /** Maximum `select`/`radio` options. */
22
+ readonly maxOptions: 50;
23
+ /** Maximum `table` rows / columns. */
24
+ readonly maxTableRows: 50;
25
+ readonly maxTableCols: 12;
26
+ /** Maximum `chart` data points per series. */
27
+ readonly maxChartPoints: 60;
28
+ /** Maximum `plot` series and per-series parameters. */
29
+ readonly maxPlotSeries: 8;
30
+ readonly maxPlotParams: 6;
31
+ /** Maximum `scene3d` meshes. */
32
+ readonly maxMeshes: 5;
33
+ /** Maximum `quiz` options. */
34
+ readonly maxQuizOptions: 8;
35
+ /** Maximum `steps` / `timeline` / `breadcrumb` / `keyvalue` entries. */
36
+ readonly maxSteps: 24;
37
+ readonly maxTimelineItems: 24;
38
+ readonly maxBreadcrumbItems: 12;
39
+ readonly maxKeyValuePairs: 24;
40
+ /** Maximum `file-tree` nesting. */
41
+ readonly maxTreeDepth: 6;
42
+ /** Maximum `diagram` nodes / edges / zones / focal accents. */
43
+ readonly maxDiagramNodes: 9;
44
+ readonly maxDiagramEdges: 12;
45
+ readonly maxDiagramZones: 3;
46
+ readonly maxDiagramFocal: 2;
47
+ readonly maxDiagramLabel: 14;
48
+ /** Maximum depth of an `echart` option object. */
49
+ readonly maxEChartOptionDepth: 10;
50
+ /** Maximum length of any single array inside an `echart` option. */
51
+ readonly maxEChartArrayLen: 500;
52
+ /** Maximum entries traversed while sanitizing an `echart` option. */
53
+ readonly maxEChartOptionNodes: 2000;
54
+ };
@@ -0,0 +1,15 @@
1
+ import type { GenuiDiagnostic } from './diagnostics.ts';
2
+ /**
3
+ * Normalize a raw GenUI value into canonical field names.
4
+ *
5
+ * Only deterministic aliases and structural aliases are changed. Resource
6
+ * limits, type repair, security filtering, and semantic validation remain in
7
+ * the guard layer. Unknown component types are returned opaque.
8
+ *
9
+ * @param value - Raw GenUI spec or bare native component.
10
+ * @returns Canonical value and stable alias diagnostics.
11
+ */
12
+ export declare function normalizeGenuiSpec(value: unknown): {
13
+ value: unknown;
14
+ warnings: GenuiDiagnostic[];
15
+ };