@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.
- package/CHANGELOG.md +597 -0
- package/LICENSE +21 -0
- package/README.md +292 -2
- package/README.zh-CN.md +307 -0
- package/SKILL.md +261 -0
- package/cordis.patch.yml +9 -0
- package/demo-prompts.md +118 -0
- package/lib/assets/echarts-core.js +43 -0
- package/lib/assets/echarts-full.js +72 -0
- package/lib/assets/mermaid.js +3591 -0
- package/lib/assets/standalone-runtime.js +1506 -0
- package/lib/assets/three.js +3844 -0
- package/lib/client.js +405 -0
- package/lib/index.js +5187 -0
- package/lib/invariant.js +19 -0
- package/lib/types/client/EChartNode.d.ts +13 -0
- package/lib/types/client/ErrorBoundary.d.ts +30 -0
- package/lib/types/client/GenuiBlock.d.ts +9 -0
- package/lib/types/client/PlotBlock.d.ts +44 -0
- package/lib/types/client/TemplateDrawer.d.ts +7 -0
- package/lib/types/client/achievement-store.d.ts +35 -0
- package/lib/types/client/achievement-toast.d.ts +2 -0
- package/lib/types/client/achievements.d.ts +63 -0
- package/lib/types/client/action-context.d.ts +7 -0
- package/lib/types/client/artifact/ExportableGenuiBlock.d.ts +6 -0
- package/lib/types/client/artifact/create.d.ts +5 -0
- package/lib/types/client/artifact/download.d.ts +9 -0
- package/lib/types/client/artifact/html.d.ts +5 -0
- package/lib/types/client/artifact/index.d.ts +8 -0
- package/lib/types/client/artifact/json.d.ts +3 -0
- package/lib/types/client/artifact/parse.d.ts +3 -0
- package/lib/types/client/artifact/portability.d.ts +4 -0
- package/lib/types/client/artifact/standalone-theme.d.ts +2 -0
- package/lib/types/client/artifact/types.d.ts +33 -0
- package/lib/types/client/asset-echarts-core.d.ts +1 -0
- package/lib/types/client/asset-echarts.d.ts +17 -0
- package/lib/types/client/asset-loader.d.ts +33 -0
- package/lib/types/client/asset-mermaid.d.ts +1 -0
- package/lib/types/client/asset-three.d.ts +1 -0
- package/lib/types/client/blocks/advanced.d.ts +101 -0
- package/lib/types/client/blocks/basic.d.ts +22 -0
- package/lib/types/client/blocks/charts.d.ts +53 -0
- package/lib/types/client/blocks/checkbox.d.ts +17 -0
- package/lib/types/client/blocks/diagram/geometry.d.ts +73 -0
- package/lib/types/client/blocks/diagram/index.d.ts +5 -0
- package/lib/types/client/blocks/diagram/layout.d.ts +41 -0
- package/lib/types/client/blocks/diagram/theme.d.ts +37 -0
- package/lib/types/client/blocks/forms.d.ts +77 -0
- package/lib/types/client/blocks/image.d.ts +6 -0
- package/lib/types/client/blocks/render-node.d.ts +10 -0
- package/lib/types/client/blocks/state.d.ts +63 -0
- package/lib/types/client/blocks/svg.d.ts +4 -0
- package/lib/types/client/dom-fence.d.ts +30 -0
- package/lib/types/client/echarts-engine.d.ts +4 -0
- package/lib/types/client/echarts-lazy.d.ts +18 -0
- package/lib/types/client/embed.d.ts +10 -0
- package/lib/types/client/fence-render.d.ts +106 -0
- package/lib/types/client/gallery.d.ts +7 -0
- package/lib/types/client/genui-runtime/diagnostics.d.ts +18 -0
- package/lib/types/client/genui-runtime/index.d.ts +1 -0
- package/lib/types/client/genui-runtime/limits.d.ts +54 -0
- package/lib/types/client/genui-runtime/normalize.d.ts +15 -0
- package/lib/types/client/genui-runtime/schema.d.ts +87 -0
- package/lib/types/client/genui-runtime/value-utils.d.ts +18 -0
- package/lib/types/client/guard.d.ts +144 -0
- package/lib/types/client/i18n/en.d.ts +307 -0
- package/lib/types/client/i18n/index.d.ts +44 -0
- package/lib/types/client/i18n/runtime.d.ts +64 -0
- package/lib/types/client/i18n/zh.d.ts +8 -0
- package/lib/types/client/index.d.ts +36 -0
- package/lib/types/client/inline.d.ts +5 -0
- package/lib/types/client/interaction-store.d.ts +48 -0
- package/lib/types/client/mermaid-core.d.ts +8 -0
- package/lib/types/client/mermaid-lazy.d.ts +9 -0
- package/lib/types/client/mermaid-safe.d.ts +52 -0
- package/lib/types/client/panel-command.d.ts +34 -0
- package/lib/types/client/panel-store.d.ts +94 -0
- package/lib/types/client/panel.d.ts +18 -0
- package/lib/types/client/parse-partial.d.ts +63 -0
- package/lib/types/client/primitive-adapter.d.ts +4 -0
- package/lib/types/client/primitive-labels.d.ts +18 -0
- package/lib/types/client/safe-math.d.ts +43 -0
- package/lib/types/client/scene3d-core.d.ts +21 -0
- package/lib/types/client/scene3d-lazy.d.ts +8 -0
- package/lib/types/client/session-resolver.d.ts +8 -0
- package/lib/types/client/source-fence.d.ts +29 -0
- package/lib/types/client/spec.d.ts +709 -0
- package/lib/types/client/standalone/asset-loader.d.ts +2 -0
- package/lib/types/client/standalone/bootstrap-types.d.ts +9 -0
- package/lib/types/client/standalone/katex-style.d.ts +1 -0
- package/lib/types/client/standalone/primitive-adapter.d.ts +54 -0
- package/lib/types/client/standalone/runtime.d.ts +2 -0
- package/lib/types/client/submission-registry.d.ts +51 -0
- package/lib/types/client/svg-fence.d.ts +2 -0
- package/lib/types/client/table-details.d.ts +20 -0
- package/lib/types/client/templates.d.ts +41 -0
- package/lib/types/client/toolview.d.ts +7 -0
- package/lib/types/client/walk-spec.d.ts +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/plugin/chart-contract.d.ts +9 -0
- package/lib/types/plugin/fence-feedback.d.ts +151 -0
- package/lib/types/plugin/genui-diagnostic.d.ts +13 -0
- package/lib/types/plugin/index.d.ts +35 -0
- package/lib/types/plugin/inline-content-diagnostic.d.ts +8 -0
- package/lib/types/plugin/invariant.d.ts +15 -0
- package/lib/types/plugin/tool.d.ts +27 -0
- package/lib/types/shared/fence-repair.d.ts +78 -0
- package/lib/types/shared/fence-resolve.d.ts +39 -0
- package/package.json +249 -4
- package/src/client/EChartNode.tsx +466 -0
- package/src/client/ErrorBoundary.tsx +67 -0
- package/src/client/GenuiBlock.module.css +2221 -0
- package/src/client/GenuiBlock.tsx +235 -0
- package/src/client/PlotBlock.module.css +171 -0
- package/src/client/PlotBlock.tsx +492 -0
- package/src/client/TemplateDrawer.module.css +152 -0
- package/src/client/TemplateDrawer.tsx +147 -0
- package/src/client/achievement-store.ts +151 -0
- package/src/client/achievement-toast.tsx +71 -0
- package/src/client/achievements.ts +160 -0
- package/src/client/action-context.ts +32 -0
- package/src/client/artifact/ArtifactExport.module.css +64 -0
- package/src/client/artifact/ExportableGenuiBlock.tsx +100 -0
- package/src/client/artifact/create.ts +69 -0
- package/src/client/artifact/download.ts +42 -0
- package/src/client/artifact/html.ts +157 -0
- package/src/client/artifact/index.ts +15 -0
- package/src/client/artifact/json.ts +6 -0
- package/src/client/artifact/parse.ts +32 -0
- package/src/client/artifact/portability.ts +47 -0
- package/src/client/artifact/standalone-theme.ts +94 -0
- package/src/client/artifact/types.ts +44 -0
- package/src/client/asset-echarts-core.ts +39 -0
- package/src/client/asset-echarts.ts +27 -0
- package/src/client/asset-loader.ts +96 -0
- package/src/client/asset-mermaid.ts +13 -0
- package/src/client/asset-three.ts +12 -0
- package/src/client/blocks/advanced.tsx +537 -0
- package/src/client/blocks/basic.tsx +121 -0
- package/src/client/blocks/charts.tsx +999 -0
- package/src/client/blocks/checkbox.tsx +61 -0
- package/src/client/blocks/diagram/geometry.ts +151 -0
- package/src/client/blocks/diagram/index.tsx +293 -0
- package/src/client/blocks/diagram/layout.ts +202 -0
- package/src/client/blocks/diagram/theme.ts +127 -0
- package/src/client/blocks/forms.tsx +531 -0
- package/src/client/blocks/image.tsx +28 -0
- package/src/client/blocks/render-node.tsx +494 -0
- package/src/client/blocks/state.ts +65 -0
- package/src/client/blocks/svg.tsx +66 -0
- package/src/client/dom-fence.tsx +1123 -0
- package/src/client/echarts-engine.ts +9 -0
- package/src/client/echarts-lazy.ts +41 -0
- package/src/client/embed.ts +19 -0
- package/src/client/fence-render.tsx +266 -0
- package/src/client/gallery.ts +215 -0
- package/src/client/genui-runtime/diagnostics.ts +165 -0
- package/src/client/genui-runtime/index.ts +1 -0
- package/src/client/genui-runtime/limits.ts +54 -0
- package/src/client/genui-runtime/normalize.ts +329 -0
- package/src/client/genui-runtime/schema.ts +352 -0
- package/src/client/genui-runtime/value-utils.ts +67 -0
- package/src/client/guard.ts +1965 -0
- package/src/client/i18n/en.ts +335 -0
- package/src/client/i18n/index.ts +125 -0
- package/src/client/i18n/runtime.ts +130 -0
- package/src/client/i18n/zh.ts +330 -0
- package/src/client/index.tsx +228 -0
- package/src/client/inline.ts +106 -0
- package/src/client/interaction-store.ts +127 -0
- package/src/client/mermaid-core.ts +158 -0
- package/src/client/mermaid-lazy.ts +31 -0
- package/src/client/mermaid-safe.ts +122 -0
- package/src/client/panel-command.ts +138 -0
- package/src/client/panel-store.ts +471 -0
- package/src/client/panel.tsx +287 -0
- package/src/client/parse-partial.ts +170 -0
- package/src/client/primitive-adapter.ts +13 -0
- package/src/client/primitive-labels.ts +55 -0
- package/src/client/safe-math.ts +298 -0
- package/src/client/scene3d-core.ts +195 -0
- package/src/client/scene3d-lazy.ts +26 -0
- package/src/client/session-resolver.ts +33 -0
- package/src/client/source-fence.ts +70 -0
- package/src/client/spec.ts +896 -0
- package/src/client/standalone/asset-loader.ts +9 -0
- package/src/client/standalone/bootstrap-types.ts +11 -0
- package/src/client/standalone/katex-style.ts +1 -0
- package/src/client/standalone/primitive-adapter.tsx +94 -0
- package/src/client/standalone/runtime.tsx +27 -0
- package/src/client/submission-registry.ts +150 -0
- package/src/client/svg-fence.tsx +39 -0
- package/src/client/table-details.ts +151 -0
- package/src/client/templates.ts +322 -0
- package/src/client/toolview.tsx +67 -0
- package/src/client/walk-spec.ts +43 -0
- package/src/css-modules.d.ts +5 -0
- package/src/index.ts +9 -0
- package/src/plugin/chart-contract.ts +13 -0
- package/src/plugin/fence-feedback.ts +655 -0
- package/src/plugin/genui-diagnostic.ts +112 -0
- package/src/plugin/index.ts +224 -0
- package/src/plugin/inline-content-diagnostic.ts +178 -0
- package/src/plugin/invariant.ts +30 -0
- package/src/plugin/node-shims.d.ts +31 -0
- package/src/plugin/tool.ts +424 -0
- package/src/shared/fence-repair.ts +536 -0
- package/src/shared/fence-resolve.ts +80 -0
- package/tsconfig.json +35 -0
- package/tsdown.config.ts +275 -0
|
@@ -0,0 +1,202 @@
|
|
|
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, GenuiDiagramKind, GenuiDiagramNode } from '../../spec.ts'
|
|
19
|
+
import { Box } from './geometry.ts'
|
|
20
|
+
|
|
21
|
+
export interface LayoutNode {
|
|
22
|
+
node: GenuiDiagramNode
|
|
23
|
+
box: Box
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface LayoutEdge {
|
|
27
|
+
edge: GenuiDiagramEdge
|
|
28
|
+
/** Resolved box references for routing. */
|
|
29
|
+
fromId: string
|
|
30
|
+
toId: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface DiagramLayout {
|
|
34
|
+
nodes: LayoutNode[]
|
|
35
|
+
edges: LayoutEdge[]
|
|
36
|
+
/** Canvas size (width/height). */
|
|
37
|
+
width: number
|
|
38
|
+
height: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Coordinate-mode kinds: nodes carry explicit positions. */
|
|
42
|
+
const COORDINATE_KINDS: readonly GenuiDiagramKind[] = [
|
|
43
|
+
'architecture', 'it-state', 'high-level', 'process', 'medallion', 'data-flow', 'dp-integration',
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const GAP = 32 // editorial gap between nodes
|
|
47
|
+
const NODE_W = 128
|
|
48
|
+
const NODE_H = 64
|
|
49
|
+
const MARGIN = 40
|
|
50
|
+
|
|
51
|
+
function isCoord(kind: GenuiDiagramKind): boolean {
|
|
52
|
+
return COORDINATE_KINDS.includes(kind)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Default box for a node without coordinates. */
|
|
56
|
+
function defaultBox(i: number, cols: number): Box {
|
|
57
|
+
const col = i % cols
|
|
58
|
+
const row = Math.floor(i / cols)
|
|
59
|
+
return {
|
|
60
|
+
x: MARGIN + col * (NODE_W + GAP),
|
|
61
|
+
y: MARGIN + row * (NODE_H + GAP),
|
|
62
|
+
w: NODE_W,
|
|
63
|
+
h: NODE_H,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Simple top-down flow layout: nodes in a column, one per row. */
|
|
68
|
+
function columnLayout(nodes: GenuiDiagramNode[]): LayoutNode[] {
|
|
69
|
+
return nodes.map((node, i) => ({
|
|
70
|
+
node,
|
|
71
|
+
box: { x: MARGIN, y: MARGIN + i * (NODE_H + GAP), w: NODE_W, h: NODE_H },
|
|
72
|
+
}))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Simple left-right flow layout: nodes in a row. */
|
|
76
|
+
function rowLayout(nodes: GenuiDiagramNode[]): LayoutNode[] {
|
|
77
|
+
return nodes.map((node, i) => ({
|
|
78
|
+
node,
|
|
79
|
+
box: { x: MARGIN + i * (NODE_W + GAP), y: MARGIN, w: NODE_W, h: NODE_H },
|
|
80
|
+
}))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Layered horizontal layout (layers, pyramid, gantt phases): stacked rows. */
|
|
84
|
+
function layerLayout(nodes: GenuiDiagramNode[], perRow = 3): LayoutNode[] {
|
|
85
|
+
return nodes.map((node, i) => {
|
|
86
|
+
const row = Math.floor(i / perRow)
|
|
87
|
+
const col = i % perRow
|
|
88
|
+
return {
|
|
89
|
+
node,
|
|
90
|
+
box: {
|
|
91
|
+
x: MARGIN + col * (NODE_W + GAP),
|
|
92
|
+
y: MARGIN + row * (NODE_H + GAP),
|
|
93
|
+
w: NODE_W,
|
|
94
|
+
h: NODE_H,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Tree layout: level = depth, children fan out horizontally under the parent. */
|
|
101
|
+
function treeLayout(nodes: GenuiDiagramNode[], parentOf: (id: string) => string | undefined): LayoutNode[] {
|
|
102
|
+
const byId = new Map(nodes.map(n => [n.id, n]))
|
|
103
|
+
const childrenOf = new Map<string, string[]>()
|
|
104
|
+
const roots: string[] = []
|
|
105
|
+
for (const n of nodes) {
|
|
106
|
+
const p = parentOf(n.id)
|
|
107
|
+
if (p === undefined || !byId.has(p)) {
|
|
108
|
+
roots.push(n.id)
|
|
109
|
+
} else {
|
|
110
|
+
const list = childrenOf.get(p) ?? []
|
|
111
|
+
list.push(n.id)
|
|
112
|
+
childrenOf.set(p, list)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const placed = new Map<string, Box>()
|
|
116
|
+
const depthOf = new Map<string, number>()
|
|
117
|
+
|
|
118
|
+
// measure: leaf width = 1; parent width = sum of children widths.
|
|
119
|
+
const measure = (id: string, depth: number): number => {
|
|
120
|
+
depthOf.set(id, depth)
|
|
121
|
+
const kids = childrenOf.get(id) ?? []
|
|
122
|
+
if (kids.length === 0) return 1
|
|
123
|
+
return kids.reduce((sum, k) => sum + measure(k, depth + 1), 0)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// assign: place children left→right, then center the parent above them.
|
|
127
|
+
const assign = (id: string, left: number): number => {
|
|
128
|
+
const depth = depthOf.get(id) ?? 0
|
|
129
|
+
const kids = childrenOf.get(id) ?? []
|
|
130
|
+
const w = NODE_W
|
|
131
|
+
let cursor = left
|
|
132
|
+
if (kids.length === 0) {
|
|
133
|
+
placed.set(id, { x: left, y: MARGIN + depth * (NODE_H + GAP * 1.5), w, h: NODE_H })
|
|
134
|
+
return left + w
|
|
135
|
+
}
|
|
136
|
+
for (const k of kids) cursor = assign(k, cursor)
|
|
137
|
+
const first = placed.get(kids[0]!)!
|
|
138
|
+
const last = placed.get(kids[kids.length - 1]!)!
|
|
139
|
+
const cx = (first.x + last.x + last.w) / 2 - w / 2
|
|
140
|
+
placed.set(id, { x: Math.max(left, cx), y: MARGIN + depth * (NODE_H + GAP * 1.5), w, h: NODE_H })
|
|
141
|
+
return cursor
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let left = MARGIN
|
|
145
|
+
for (const r of roots) {
|
|
146
|
+
left = assign(r, left) + GAP
|
|
147
|
+
}
|
|
148
|
+
return nodes.map(n => ({ node: n, box: placed.get(n.id) ?? { x: MARGIN, y: MARGIN, w: NODE_W, h: NODE_H } }))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Resolve a diagram spec into a positioned layout. `parentOf` lets tree-like
|
|
153
|
+
* kinds pass their hierarchy; other rule kinds use a generic grid.
|
|
154
|
+
*/
|
|
155
|
+
export function resolveLayout(
|
|
156
|
+
diagram: GenuiDiagram,
|
|
157
|
+
parentOf?: (id: string) => string | undefined,
|
|
158
|
+
): DiagramLayout {
|
|
159
|
+
const nodes = diagram.nodes
|
|
160
|
+
const edges = diagram.edges ?? []
|
|
161
|
+
|
|
162
|
+
let placed: LayoutNode[]
|
|
163
|
+
if (isCoord(diagram.kind)) {
|
|
164
|
+
placed = nodes.map((node, i) => ({
|
|
165
|
+
node,
|
|
166
|
+
box: {
|
|
167
|
+
x: node.x ?? MARGIN + (i % 3) * (NODE_W + GAP),
|
|
168
|
+
y: node.y ?? MARGIN + Math.floor(i / 3) * (NODE_H + GAP),
|
|
169
|
+
w: node.w ?? NODE_W,
|
|
170
|
+
h: node.h ?? NODE_H,
|
|
171
|
+
},
|
|
172
|
+
}))
|
|
173
|
+
} else if (diagram.kind === 'tree' || diagram.kind === 'org-chart' || diagram.kind === 'nested') {
|
|
174
|
+
placed = treeLayout(nodes, parentOf ?? (() => undefined))
|
|
175
|
+
} else if (diagram.kind === 'layers' || diagram.kind === 'pyramid' || diagram.kind === 'gantt') {
|
|
176
|
+
placed = layerLayout(nodes)
|
|
177
|
+
} else if (diagram.kind === 'flowchart' || diagram.kind === 'process' || diagram.kind === 'sequence') {
|
|
178
|
+
// Directed flows read top-down.
|
|
179
|
+
placed = columnLayout(nodes)
|
|
180
|
+
} else if (diagram.kind === 'timeline' || diagram.kind === 'line' || diagram.kind === 'scatter' || diagram.kind === 'bar') {
|
|
181
|
+
placed = rowLayout(nodes)
|
|
182
|
+
} else {
|
|
183
|
+
placed = nodes.map((node, i) => ({ node, box: defaultBox(i, 3) }))
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Canvas bounds.
|
|
187
|
+
let width = 0
|
|
188
|
+
let height = 0
|
|
189
|
+
for (const l of placed) {
|
|
190
|
+
width = Math.max(width, l.box.x + l.box.w)
|
|
191
|
+
height = Math.max(height, l.box.y + l.box.h)
|
|
192
|
+
}
|
|
193
|
+
width = Math.max(320, Math.ceil((width + MARGIN) / 4) * 4)
|
|
194
|
+
// Hug the content: the old 200px floor plus the legend strip made a 4-node
|
|
195
|
+
// single row render inside a canvas twice its needed height, and the SVG
|
|
196
|
+
// scales to the container width, so the empty band was amplified on screen.
|
|
197
|
+
height = Math.max(96, Math.ceil((height + MARGIN) / 4) * 4)
|
|
198
|
+
|
|
199
|
+
const edgesOut: LayoutEdge[] = edges.map(e => ({ edge: e, fromId: e.from, toId: e.to }))
|
|
200
|
+
|
|
201
|
+
return { nodes: placed, edges: edgesOut, width, height }
|
|
202
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
|
|
14
|
+
export interface DiagramPalette {
|
|
15
|
+
paper: string
|
|
16
|
+
paper2: string
|
|
17
|
+
ink: string
|
|
18
|
+
muted: string
|
|
19
|
+
soft: string
|
|
20
|
+
rule: string
|
|
21
|
+
accent: string
|
|
22
|
+
accentTint: string
|
|
23
|
+
link: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** diagram-design default skin (style-guide.md § Tokens). */
|
|
27
|
+
const LIGHT: DiagramPalette = {
|
|
28
|
+
paper: '#f5f5f5',
|
|
29
|
+
paper2: '#ececec',
|
|
30
|
+
ink: '#2d3142',
|
|
31
|
+
muted: '#4f5d75',
|
|
32
|
+
soft: '#7a8399',
|
|
33
|
+
rule: 'rgba(45,49,66,0.12)',
|
|
34
|
+
accent: '#eb6c36',
|
|
35
|
+
accentTint: 'rgba(235,108,54,0.08)',
|
|
36
|
+
link: '#2e5aa8',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Dark inversion: jet-black paper, white-smoke ink, silver muted. */
|
|
40
|
+
const DARK: DiagramPalette = {
|
|
41
|
+
paper: '#2d3142',
|
|
42
|
+
paper2: '#393e53',
|
|
43
|
+
ink: '#f5f5f5',
|
|
44
|
+
muted: '#bfc0c0',
|
|
45
|
+
soft: '#8e98ac',
|
|
46
|
+
rule: 'rgba(245,245,245,0.12)',
|
|
47
|
+
accent: '#f08a59',
|
|
48
|
+
accentTint: 'rgba(240,138,89,0.10)',
|
|
49
|
+
link: '#6a95d8',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Native SVG paint values keep inherited host tokens live across theme changes. */
|
|
53
|
+
export function hostPalette(): DiagramPalette {
|
|
54
|
+
const accent = 'var(--dsw-alias-state-business-primary, #4f8ef7)'
|
|
55
|
+
return {
|
|
56
|
+
paper: 'var(--dsw-alias-bg-layer-2, #ffffff)',
|
|
57
|
+
paper2: 'var(--dsw-alias-bg-layer-3, #f5f5f5)',
|
|
58
|
+
ink: 'var(--dsw-alias-label-primary, #2d3142)',
|
|
59
|
+
muted: 'var(--dsw-alias-label-secondary, #4f5d75)',
|
|
60
|
+
soft: 'var(--dsw-alias-label-tertiary, #7a8399)',
|
|
61
|
+
rule: 'var(--dsw-alias-border-l2, rgba(45,49,66,0.12))',
|
|
62
|
+
accent,
|
|
63
|
+
accentTint: `color-mix(in srgb, ${accent} 10%, transparent)`,
|
|
64
|
+
link: accent,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Resolve the active palette from variant + optional theme overrides. */
|
|
69
|
+
export function resolvePalette(variant: GenuiDiagramVariant | undefined, theme: GenuiDiagramTheme | undefined): DiagramPalette {
|
|
70
|
+
// No explicit variant -> follow the host theme; an explicit variant keeps the
|
|
71
|
+
// editorial skin (that is what the field is for).
|
|
72
|
+
const base = variant === undefined ? hostPalette() : variant === 'dark' ? DARK : LIGHT
|
|
73
|
+
if (theme === undefined) return base
|
|
74
|
+
return {
|
|
75
|
+
paper: theme.paper ?? base.paper,
|
|
76
|
+
paper2: theme['paper-2'] ?? base.paper2,
|
|
77
|
+
ink: theme.ink ?? base.ink,
|
|
78
|
+
muted: theme.muted ?? base.muted,
|
|
79
|
+
soft: theme.soft ?? base.soft,
|
|
80
|
+
rule: theme.rule ?? base.rule,
|
|
81
|
+
accent: theme.accent ?? base.accent,
|
|
82
|
+
accentTint: theme['accent-tint'] ?? base.accentTint,
|
|
83
|
+
link: theme.link ?? base.link,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Node treatment → { fill, stroke, dashed } per diagram-design §5. */
|
|
88
|
+
export function nodeTreatment(type: string | undefined, p: DiagramPalette): { fill: string; stroke: string; dashed?: boolean } {
|
|
89
|
+
switch (type) {
|
|
90
|
+
case 'focal': return { fill: p.accentTint, stroke: p.accent }
|
|
91
|
+
case 'store': return { fill: inkAt(p.ink, 0.05), stroke: p.muted }
|
|
92
|
+
case 'external': return { fill: inkAt(p.ink, 0.03), stroke: inkAt(p.ink, 0.30) }
|
|
93
|
+
case 'input': return { fill: inkAt(p.muted, 0.10), stroke: p.soft }
|
|
94
|
+
case 'optional': return { fill: inkAt(p.ink, 0.02), stroke: inkAt(p.ink, 0.20), dashed: true }
|
|
95
|
+
case 'security': return { fill: inkAt(p.accent, 0.05), stroke: inkAt(p.accent, 0.50), dashed: true }
|
|
96
|
+
default: return { fill: p.paper, stroke: p.ink }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Edge stroke color per semantic kind. */
|
|
101
|
+
export function edgeStroke(kind: string | undefined, p: DiagramPalette): string {
|
|
102
|
+
switch (kind) {
|
|
103
|
+
case 'accent': return p.accent
|
|
104
|
+
case 'link': return p.link
|
|
105
|
+
default: return p.muted
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Apply opacity while retaining live host-token references. */
|
|
110
|
+
export function inkAt(color: string, opacity: number): string {
|
|
111
|
+
if (color.startsWith('var(')) return `color-mix(in srgb, ${color} ${opacity * 100}%, transparent)`
|
|
112
|
+
if (color.startsWith('#')) {
|
|
113
|
+
const hex = color.slice(1)
|
|
114
|
+
const full = hex.length === 3 ? hex.split('').map(c => c + c).join('') : hex
|
|
115
|
+
const r = parseInt(full.slice(0, 2), 16)
|
|
116
|
+
const g = parseInt(full.slice(2, 4), 16)
|
|
117
|
+
const b = parseInt(full.slice(4, 6), 16)
|
|
118
|
+
return `rgba(${r},${g},${b},${opacity})`
|
|
119
|
+
}
|
|
120
|
+
// rgba(...) input: replace the alpha component.
|
|
121
|
+
return color.replace(/rgba?\(([^)]*)\)/, (_, inner: string) => {
|
|
122
|
+
const parts = inner.split(',').map(s => s.trim())
|
|
123
|
+
if (parts.length === 3) return `rgba(${parts.join(',')},${opacity})`
|
|
124
|
+
if (parts.length === 4) return `rgba(${parts[0]},${parts[1]},${parts[2]},${opacity})`
|
|
125
|
+
return color
|
|
126
|
+
})
|
|
127
|
+
}
|