@airalogy/aimd-recorder 1.17.0 → 1.19.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 (112) hide show
  1. package/README.md +42 -10
  2. package/README.zh-CN.md +42 -10
  3. package/dist/AimdCodeField-BQUuM-EF.js +182 -0
  4. package/dist/{AimdDnaSequenceField-D6ZgCDpp.js → AimdDnaSequenceField-TBKunqU_.js} +2 -2
  5. package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-B5Tq4zPV.js → AimdEditor.vue_vue_type_style_index_0_lang-tdh0dJNa.js} +3922 -3829
  6. package/dist/AimdMarkdownField-DmNX2g4j.js +254 -0
  7. package/dist/AimdMarkdownNoteField-B5ruzmwS.js +259 -0
  8. package/dist/{_commonjsHelpers-CZXJ37nu.js → _commonjsHelpers-B5RozER-.js} +2 -2
  9. package/dist/aimd-recorder.css +1 -1
  10. package/dist/arc-B-vsgEXF.js +83 -0
  11. package/dist/architectureDiagram-3BPJPVTR-BwPNOtNH.js +4692 -0
  12. package/dist/blockDiagram-GPEHLZMM-CMUI4kKc.js +2425 -0
  13. package/dist/c4Diagram-AAUBKEIU-Cpmfsy_s.js +1577 -0
  14. package/dist/channel-DlMAXHQK.js +5 -0
  15. package/dist/chunk-2J33WTMH-DP9BS2ux.js +19 -0
  16. package/dist/chunk-4BX2VUAB-ncsOeLMb.js +8 -0
  17. package/dist/chunk-55IACEB6-C7wHk4B7.js +8 -0
  18. package/dist/chunk-727SXJPM-Caa5aVUO.js +1528 -0
  19. package/dist/chunk-AQP2D5EJ-CL8egKqD.js +1387 -0
  20. package/dist/chunk-FMBD7UC4-heVR6BSA.js +19 -0
  21. package/dist/chunk-ND2GUHAM-BYH-wC2J.js +68 -0
  22. package/dist/chunk-QZHKN3VN-Bx2K7vkq.js +15 -0
  23. package/dist/classDiagram-4FO5ZUOK-BLLfLYy0.js +16 -0
  24. package/dist/classDiagram-v2-Q7XG4LA2-BLLfLYy0.js +16 -0
  25. package/dist/components.js +3776 -2247
  26. package/dist/composables.js +96 -70
  27. package/dist/cose-bilkent-S5V4N54A-E1YmM_xr.js +2609 -0
  28. package/dist/cytoscape.esm-r59gEWFs.js +18710 -0
  29. package/dist/dagre-BM42HDAG-BsXpQirH.js +445 -0
  30. package/dist/defaultLocale-BgPVtth8.js +171 -0
  31. package/dist/diagram-2AECGRRQ-CamqbWlY.js +217 -0
  32. package/dist/diagram-5GNKFQAL-DZyRFcOC.js +123 -0
  33. package/dist/diagram-KO2AKTUF-CmkGcy7R.js +461 -0
  34. package/dist/diagram-LMA3HP47-IdDwQPZ-.js +142 -0
  35. package/dist/diagram-OG6HWLK6-t0LBcUIU.js +528 -0
  36. package/dist/erDiagram-TEJ5UH35-DJBY2iZG.js +899 -0
  37. package/dist/flowDiagram-I6XJVG4X-DE4MzPPk.js +1628 -0
  38. package/dist/ganttDiagram-6RSMTGT7-CmAc35Yw.js +2707 -0
  39. package/dist/gitGraphDiagram-PVQCEYII-DDQZ5flw.js +815 -0
  40. package/dist/graph-BsJ8-1Pq.js +1510 -0
  41. package/dist/index.js +110 -83
  42. package/dist/infoDiagram-5YYISTIA-DSZjFR5g.js +24 -0
  43. package/dist/init-DjUOC4st.js +16 -0
  44. package/dist/ishikawaDiagram-YF4QCWOH-DCO9dx2L.js +621 -0
  45. package/dist/journeyDiagram-JHISSGLW-b-PpuBqg.js +834 -0
  46. package/dist/kanban-definition-UN3LZRKU-BjclDuJZ.js +724 -0
  47. package/dist/katex-DNob3HGn.js +11690 -0
  48. package/dist/layout-D4wqKu72.js +1703 -0
  49. package/dist/linear-Voc3BJib.js +259 -0
  50. package/dist/mermaid.core-Dt_VbeGP.js +15940 -0
  51. package/dist/mindmap-definition-RKZ34NQL-B3vrXRVY.js +827 -0
  52. package/dist/ordinal-B6-f3MAq.js +61 -0
  53. package/dist/pieDiagram-4H26LBE5-DFpWxSxk.js +163 -0
  54. package/dist/quadrantDiagram-W4KKPZXB-BYHcrGoB.js +1024 -0
  55. package/dist/record.js +1199 -0
  56. package/dist/requirementDiagram-4Y6WPE33-C-FgWrRz.js +882 -0
  57. package/dist/sankeyDiagram-5OEKKPKP-IwN0Evji.js +847 -0
  58. package/dist/sequenceDiagram-3UESZ5HK-_OnqhBO2.js +2891 -0
  59. package/dist/stateDiagram-AJRCARHV-BRLv0Zcw.js +263 -0
  60. package/dist/stateDiagram-v2-BHNVJYJU-BofX0AdS.js +16 -0
  61. package/dist/timeline-definition-PNZ67QCA-C-DpPLpw.js +1055 -0
  62. package/dist/{useFieldRendering-xLajJhyA.js → useCodeBlockRendering-DoTZaJTW.js} +1528 -1725
  63. package/dist/useMonacoAutoHeight-D4T-El3J.js +66 -0
  64. package/dist/vennDiagram-CIIHVFJN-zTHQR9Oq.js +1557 -0
  65. package/dist/wardley-L42UT6IY-D7b2ujEZ.js +22512 -0
  66. package/dist/wardleyDiagram-YWT4CUSO-au5koizO.js +675 -0
  67. package/dist/xychartDiagram-2RQKCTM6-BNf12P8z.js +1342 -0
  68. package/package.json +13 -8
  69. package/src/__tests__/assigner-graph.test.ts +82 -0
  70. package/src/__tests__/assigner-runner-dependent-data.test.ts +32 -0
  71. package/src/__tests__/markdown-field.test.ts +150 -1
  72. package/src/__tests__/markdown-note-field.test.ts +86 -3
  73. package/src/__tests__/recorder-assigner-control.test.ts +993 -0
  74. package/src/__tests__/recorder-editor.test.ts +17 -0
  75. package/src/__tests__/recorder-markdown-assigner-integration.test.ts +49 -0
  76. package/src/__tests__/step-field.test.ts +47 -1
  77. package/src/__tests__/type-plugins.test.ts +1 -0
  78. package/src/__tests__/var-field-render.test.ts +806 -1
  79. package/src/components/AimdAssignerGraph.vue +816 -0
  80. package/src/components/AimdCodeField.vue +24 -5
  81. package/src/components/AimdMarkdownField.vue +556 -11
  82. package/src/components/AimdMarkdownNoteField.vue +241 -30
  83. package/src/components/AimdRecorder.vue +1619 -99
  84. package/src/components/AimdRecorderEditor.vue +276 -8
  85. package/src/components/AimdRecorderWysiwygFieldHost.vue +6 -0
  86. package/src/components/AimdRecorderWysiwygSurface.vue +32 -0
  87. package/src/components/AimdStepCheckField.vue +82 -18
  88. package/src/components/AimdVarField.vue +694 -25
  89. package/src/components/AimdVarTableField.vue +325 -138
  90. package/src/components/icons/AimdAssignerCalculatorIcon.vue +18 -0
  91. package/src/components/icons/AimdAssignerCloudStatusIcon.vue +22 -0
  92. package/src/components/index.ts +9 -1
  93. package/src/components/recorderMilkdownPlugin.ts +14 -0
  94. package/src/composables/__tests__/useRecordState.test.ts +86 -0
  95. package/src/composables/__tests__/useVarHelpers.test.ts +175 -0
  96. package/src/composables/index.ts +28 -1
  97. package/src/composables/useAssignerRunner.ts +376 -0
  98. package/src/composables/useCodeBlockRendering.ts +51 -0
  99. package/src/composables/useFieldRendering.ts +32 -4
  100. package/src/composables/useMonacoAutoHeight.ts +127 -0
  101. package/src/composables/useRecordState.ts +22 -3
  102. package/src/composables/useVarHelpers.ts +237 -32
  103. package/src/index.ts +20 -1
  104. package/src/locales.ts +45 -0
  105. package/src/record/index.ts +120 -0
  106. package/src/styles/aimd.css +216 -1
  107. package/src/type-plugins.ts +7 -0
  108. package/src/type-utils.ts +1 -3
  109. package/src/types.ts +130 -2
  110. package/dist/AimdCodeField-DC3DPvgc.js +0 -172
  111. package/dist/AimdMarkdownField-BJ20QtO8.js +0 -67
  112. package/dist/AimdMarkdownNoteField-DwAQhoyk.js +0 -186
@@ -0,0 +1,816 @@
1
+ <script setup lang="ts">
2
+ import { computed, getCurrentInstance, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue"
3
+ import type {
4
+ AimdAssignerGraphData,
5
+ AimdAssignerGraphLabels,
6
+ AimdAssignerGraphNode,
7
+ AimdAssignerGraphNodeType,
8
+ AimdAssignerNodeSchemaInfo,
9
+ } from "../types"
10
+
11
+ defineOptions({ name: "AimdAssignerGraph" })
12
+
13
+ interface Props {
14
+ assignerGraph?: AimdAssignerGraphData | null
15
+ nodeSchemaMap?: Record<string, AimdAssignerNodeSchemaInfo | undefined>
16
+ height?: string
17
+ loading?: boolean
18
+ showToolbar?: boolean
19
+ showLegend?: boolean
20
+ allowFullscreen?: boolean
21
+ labels?: Partial<AimdAssignerGraphLabels>
22
+ }
23
+
24
+ const props = withDefaults(defineProps<Props>(), {
25
+ assignerGraph: null,
26
+ nodeSchemaMap: () => ({}),
27
+ height: "600px",
28
+ loading: false,
29
+ showToolbar: true,
30
+ showLegend: true,
31
+ allowFullscreen: true,
32
+ labels: () => ({}),
33
+ })
34
+
35
+ const emit = defineEmits<{
36
+ (e: "nodeClick", nodeName: string, nodeType: AimdAssignerGraphNodeType, event: MouseEvent): void
37
+ }>()
38
+
39
+ const DEFAULT_LABELS: AimdAssignerGraphLabels = {
40
+ zoomIn: "Zoom in",
41
+ zoomOut: "Zoom out",
42
+ fitView: "Fit view",
43
+ fullscreen: "Fullscreen",
44
+ close: "Close",
45
+ showTitle: "Show title",
46
+ showName: "Show name",
47
+ dependentField: "Dependent field",
48
+ assigner: "Assigner",
49
+ assignedField: "Assigned field",
50
+ empty: "No assigner graph available",
51
+ loading: "Loading assigner graph",
52
+ fullscreenTitle: "Assigner topology",
53
+ }
54
+
55
+ const NODE_HEIGHT = 48
56
+ const COLUMN_GAP = 260
57
+ const ROW_GAP = 86
58
+ const GRAPH_MARGIN = 36
59
+ const MIN_NODE_WIDTH = 132
60
+ const MAX_NODE_WIDTH = 232
61
+ const MAX_LABEL_CHARS = 28
62
+
63
+ interface LayoutNode {
64
+ name: string
65
+ type: AimdAssignerGraphNodeType
66
+ label: string
67
+ fullLabel: string
68
+ schemaInfo?: AimdAssignerNodeSchemaInfo
69
+ x: number
70
+ y: number
71
+ width: number
72
+ height: number
73
+ highlighted: boolean
74
+ dimmed: boolean
75
+ }
76
+
77
+ interface LayoutEdge {
78
+ from: string
79
+ to: string
80
+ path: string
81
+ highlighted: boolean
82
+ dimmed: boolean
83
+ }
84
+
85
+ interface LayoutGraph {
86
+ nodes: LayoutNode[]
87
+ edges: LayoutEdge[]
88
+ width: number
89
+ height: number
90
+ }
91
+
92
+ const canvasRef = ref<HTMLElement | null>(null)
93
+ const selectedNodeName = ref<string | null>(null)
94
+ const zoom = ref(1)
95
+ const showTitle = ref(false)
96
+ const fullscreen = ref(false)
97
+ const graphInstanceId = `aimd-assigner-graph-${getCurrentInstance()?.uid ?? "0"}`
98
+ const markerId = `${graphInstanceId}-arrow`
99
+ const highlightedMarkerId = `${graphInstanceId}-arrow-highlighted`
100
+ let resizeObserver: ResizeObserver | null = null
101
+
102
+ const resolvedLabels = computed<AimdAssignerGraphLabels>(() => ({
103
+ ...DEFAULT_LABELS,
104
+ ...props.labels,
105
+ }))
106
+
107
+ const normalizedNodes = computed<AimdAssignerGraphNode[]>(() => {
108
+ const graph = props.assignerGraph
109
+ if (!graph) return []
110
+
111
+ const nodesByName = new Map<string, AimdAssignerGraphNode>()
112
+ for (const node of graph.nodes) {
113
+ if (!node?.name) continue
114
+ nodesByName.set(node.name, node)
115
+ }
116
+ for (const [from, to] of graph.edges) {
117
+ if (from && !nodesByName.has(from)) {
118
+ nodesByName.set(from, { name: from, type: "dependent_field" })
119
+ }
120
+ if (to && !nodesByName.has(to)) {
121
+ nodesByName.set(to, { name: to, type: "assigned_field" })
122
+ }
123
+ }
124
+ return [...nodesByName.values()]
125
+ })
126
+
127
+ const adjacencyMap = computed(() => {
128
+ const map = new Map<string, { inputs: string[], outputs: string[] }>()
129
+ for (const node of normalizedNodes.value) {
130
+ map.set(node.name, { inputs: [], outputs: [] })
131
+ }
132
+ for (const [from, to] of props.assignerGraph?.edges ?? []) {
133
+ map.get(from)?.outputs.push(to)
134
+ map.get(to)?.inputs.push(from)
135
+ }
136
+ return map
137
+ })
138
+
139
+ const highlightedNames = computed(() => {
140
+ if (!selectedNodeName.value) return new Set<string>()
141
+
142
+ const selected = selectedNodeName.value
143
+ const selectedNode = normalizedNodes.value.find(node => node.name === selected)
144
+ const highlighted = new Set<string>()
145
+ if (!selectedNode) return highlighted
146
+
147
+ if (selectedNode.type === "assigner") {
148
+ highlighted.add(selected)
149
+ const adjacent = adjacencyMap.value.get(selected)
150
+ adjacent?.inputs.forEach(name => highlighted.add(name))
151
+ adjacent?.outputs.forEach(name => highlighted.add(name))
152
+ return highlighted
153
+ }
154
+
155
+ collectUpstream(selected, highlighted)
156
+ collectDownstream(selected, highlighted)
157
+ return highlighted
158
+ })
159
+
160
+ const layoutGraph = computed<LayoutGraph>(() => {
161
+ const nodes = normalizedNodes.value
162
+ if (!nodes.length) {
163
+ return { nodes: [], edges: [], width: 480, height: 320 }
164
+ }
165
+
166
+ const ranks = computeNodeRanks(nodes, props.assignerGraph?.edges ?? [])
167
+ const buckets = new Map<number, AimdAssignerGraphNode[]>()
168
+ for (const node of nodes) {
169
+ const rank = ranks.get(node.name) ?? 0
170
+ const bucket = buckets.get(rank) ?? []
171
+ bucket.push(node)
172
+ buckets.set(rank, bucket)
173
+ }
174
+
175
+ const layoutNodes: LayoutNode[] = []
176
+ let maxRank = 0
177
+ let maxRows = 1
178
+ for (const [rank, bucket] of buckets) {
179
+ maxRank = Math.max(maxRank, rank)
180
+ maxRows = Math.max(maxRows, bucket.length)
181
+ const sortedBucket = [...bucket].sort(compareGraphNodes)
182
+ sortedBucket.forEach((node, rowIndex) => {
183
+ const schemaInfo = props.nodeSchemaMap[node.name]
184
+ const fullLabel = getNodeDisplayLabel(node, schemaInfo)
185
+ const label = truncateLabel(fullLabel)
186
+ const width = getNodeWidth(label)
187
+ const hasSelection = selectedNodeName.value !== null
188
+ const highlighted = hasSelection && highlightedNames.value.has(node.name)
189
+ layoutNodes.push({
190
+ name: node.name,
191
+ type: node.type,
192
+ label,
193
+ fullLabel,
194
+ schemaInfo,
195
+ x: GRAPH_MARGIN + rank * COLUMN_GAP,
196
+ y: GRAPH_MARGIN + rowIndex * ROW_GAP,
197
+ width,
198
+ height: NODE_HEIGHT,
199
+ highlighted,
200
+ dimmed: hasSelection && !highlighted,
201
+ })
202
+ })
203
+ }
204
+
205
+ const nodeByName = new Map(layoutNodes.map(node => [node.name, node]))
206
+ const layoutEdges = (props.assignerGraph?.edges ?? [])
207
+ .map(([from, to]) => {
208
+ const fromNode = nodeByName.get(from)
209
+ const toNode = nodeByName.get(to)
210
+ if (!fromNode || !toNode) return null
211
+ const hasSelection = selectedNodeName.value !== null
212
+ const highlighted = hasSelection && highlightedNames.value.has(from) && highlightedNames.value.has(to)
213
+ return {
214
+ from,
215
+ to,
216
+ path: createEdgePath(fromNode, toNode),
217
+ highlighted,
218
+ dimmed: hasSelection && !highlighted,
219
+ } satisfies LayoutEdge
220
+ })
221
+ .filter((edge): edge is LayoutEdge => edge !== null)
222
+
223
+ return {
224
+ nodes: layoutNodes,
225
+ edges: layoutEdges,
226
+ width: GRAPH_MARGIN * 2 + maxRank * COLUMN_GAP + MAX_NODE_WIDTH,
227
+ height: GRAPH_MARGIN * 2 + (maxRows - 1) * ROW_GAP + NODE_HEIGHT,
228
+ }
229
+ })
230
+
231
+ const zoomPercent = computed(() => `${Math.round(zoom.value * 100)}%`)
232
+ const graphStyle = computed(() => ({
233
+ "--aimd-assigner-graph-height": fullscreen.value ? "100vh" : props.height,
234
+ }))
235
+ const svgWidth = computed(() => Math.max(layoutGraph.value.width * zoom.value, 1))
236
+ const svgHeight = computed(() => Math.max(layoutGraph.value.height * zoom.value, 1))
237
+
238
+ function nodeTypeRank(type: AimdAssignerGraphNodeType): number {
239
+ if (type === "dependent_field") return 0
240
+ if (type === "assigner") return 1
241
+ return 2
242
+ }
243
+
244
+ function compareGraphNodes(a: AimdAssignerGraphNode, b: AimdAssignerGraphNode): number {
245
+ const typeDiff = nodeTypeRank(a.type) - nodeTypeRank(b.type)
246
+ if (typeDiff !== 0) return typeDiff
247
+ return a.name.localeCompare(b.name)
248
+ }
249
+
250
+ function computeNodeRanks(
251
+ nodes: AimdAssignerGraphNode[],
252
+ edges: Array<[string, string]>,
253
+ ): Map<string, number> {
254
+ const nodeNames = new Set(nodes.map(node => node.name))
255
+ const outgoing = new Map<string, string[]>()
256
+ const incomingCount = new Map<string, number>()
257
+ const ranks = new Map<string, number>()
258
+
259
+ for (const node of nodes) {
260
+ outgoing.set(node.name, [])
261
+ incomingCount.set(node.name, 0)
262
+ ranks.set(node.name, 0)
263
+ }
264
+
265
+ for (const [from, to] of edges) {
266
+ if (!nodeNames.has(from) || !nodeNames.has(to)) continue
267
+ outgoing.get(from)?.push(to)
268
+ incomingCount.set(to, (incomingCount.get(to) ?? 0) + 1)
269
+ }
270
+
271
+ const queue = nodes
272
+ .filter(node => (incomingCount.get(node.name) ?? 0) === 0)
273
+ .sort(compareGraphNodes)
274
+ .map(node => node.name)
275
+ const visited = new Set<string>()
276
+
277
+ while (queue.length > 0) {
278
+ const current = queue.shift()!
279
+ if (visited.has(current)) continue
280
+ visited.add(current)
281
+ const nextRank = (ranks.get(current) ?? 0) + 1
282
+ for (const next of outgoing.get(current) ?? []) {
283
+ ranks.set(next, Math.max(ranks.get(next) ?? 0, nextRank))
284
+ incomingCount.set(next, Math.max(0, (incomingCount.get(next) ?? 0) - 1))
285
+ if ((incomingCount.get(next) ?? 0) === 0) {
286
+ queue.push(next)
287
+ }
288
+ }
289
+ }
290
+
291
+ return ranks
292
+ }
293
+
294
+ function getNodeDisplayLabel(node: AimdAssignerGraphNode, schemaInfo?: AimdAssignerNodeSchemaInfo): string {
295
+ if (showTitle.value && schemaInfo?.title) {
296
+ return schemaInfo.title
297
+ }
298
+ return node.name
299
+ }
300
+
301
+ function truncateLabel(label: string): string {
302
+ if (label.length <= MAX_LABEL_CHARS) return label
303
+ return `${label.slice(0, MAX_LABEL_CHARS - 1)}...`
304
+ }
305
+
306
+ function getNodeWidth(label: string): number {
307
+ const estimated = label.length * 8.5 + 36
308
+ return Math.max(MIN_NODE_WIDTH, Math.min(MAX_NODE_WIDTH, estimated))
309
+ }
310
+
311
+ function createEdgePath(fromNode: LayoutNode, toNode: LayoutNode): string {
312
+ const sourceX = fromNode.x + fromNode.width
313
+ const sourceY = fromNode.y + fromNode.height / 2
314
+ const targetX = toNode.x
315
+ const targetY = toNode.y + toNode.height / 2
316
+ const offset = Math.max(54, Math.min(110, Math.abs(targetX - sourceX) / 2))
317
+ return `M ${sourceX} ${sourceY} C ${sourceX + offset} ${sourceY}, ${targetX - offset} ${targetY}, ${targetX} ${targetY}`
318
+ }
319
+
320
+ function collectUpstream(name: string, visited: Set<string>) {
321
+ if (visited.has(name)) return
322
+ visited.add(name)
323
+ for (const input of adjacencyMap.value.get(name)?.inputs ?? []) {
324
+ collectUpstream(input, visited)
325
+ }
326
+ }
327
+
328
+ function collectDownstream(name: string, visited: Set<string>) {
329
+ if (visited.has(name)) return
330
+ visited.add(name)
331
+ for (const output of adjacencyMap.value.get(name)?.outputs ?? []) {
332
+ collectDownstream(output, visited)
333
+ }
334
+ }
335
+
336
+ function getNodeTooltip(node: LayoutNode): string {
337
+ const details = [node.fullLabel]
338
+ if (node.schemaInfo?.type) details.push(node.schemaInfo.type)
339
+ if (node.schemaInfo?.format) details.push(node.schemaInfo.format)
340
+ if (node.schemaInfo?.description) details.push(node.schemaInfo.description)
341
+ return details.join("\n")
342
+ }
343
+
344
+ function onNodeClick(node: LayoutNode, event: MouseEvent) {
345
+ selectedNodeName.value = selectedNodeName.value === node.name ? null : node.name
346
+ emit("nodeClick", node.name, node.type, event)
347
+ }
348
+
349
+ function onNodeKeyboard(node: LayoutNode, event: KeyboardEvent) {
350
+ selectedNodeName.value = selectedNodeName.value === node.name ? null : node.name
351
+ emit("nodeClick", node.name, node.type, event as unknown as MouseEvent)
352
+ }
353
+
354
+ function clearSelection() {
355
+ selectedNodeName.value = null
356
+ }
357
+
358
+ function clampZoom(value: number): number {
359
+ return Math.max(0.25, Math.min(2.5, value))
360
+ }
361
+
362
+ function zoomIn() {
363
+ zoom.value = clampZoom(zoom.value * 1.18)
364
+ }
365
+
366
+ function zoomOut() {
367
+ zoom.value = clampZoom(zoom.value / 1.18)
368
+ }
369
+
370
+ function fitView() {
371
+ const viewport = canvasRef.value
372
+ if (!viewport) {
373
+ zoom.value = 1
374
+ return
375
+ }
376
+ const widthRatio = (viewport.clientWidth - 24) / layoutGraph.value.width
377
+ const heightRatio = (viewport.clientHeight - 24) / layoutGraph.value.height
378
+ zoom.value = clampZoom(Math.min(1, widthRatio, heightRatio) || 1)
379
+ viewport.scrollTo({ left: 0, top: 0 })
380
+ }
381
+
382
+ function toggleDisplayMode() {
383
+ showTitle.value = !showTitle.value
384
+ }
385
+
386
+ function toggleFullscreen() {
387
+ fullscreen.value = !fullscreen.value
388
+ nextTick(() => fitView())
389
+ }
390
+
391
+ function onKeydown(event: KeyboardEvent) {
392
+ if (event.key === "Escape" && fullscreen.value) {
393
+ fullscreen.value = false
394
+ }
395
+ }
396
+
397
+ watch(() => props.assignerGraph, () => {
398
+ selectedNodeName.value = null
399
+ nextTick(() => fitView())
400
+ })
401
+
402
+ watch(showTitle, () => {
403
+ nextTick(() => fitView())
404
+ })
405
+
406
+ onMounted(() => {
407
+ nextTick(() => fitView())
408
+ window.addEventListener("keydown", onKeydown)
409
+ if (typeof ResizeObserver !== "undefined" && canvasRef.value) {
410
+ resizeObserver = new ResizeObserver(() => fitView())
411
+ resizeObserver.observe(canvasRef.value)
412
+ }
413
+ })
414
+
415
+ onBeforeUnmount(() => {
416
+ window.removeEventListener("keydown", onKeydown)
417
+ resizeObserver?.disconnect()
418
+ })
419
+
420
+ defineExpose({
421
+ zoomIn,
422
+ zoomOut,
423
+ fitView,
424
+ toggleDisplayMode,
425
+ showTitle,
426
+ fullscreen,
427
+ })
428
+ </script>
429
+
430
+ <template>
431
+ <div
432
+ class="aimd-assigner-graph"
433
+ :class="{ 'aimd-assigner-graph--fullscreen': fullscreen }"
434
+ :style="graphStyle"
435
+ >
436
+ <div v-if="showToolbar" class="aimd-assigner-graph__toolbar">
437
+ <div class="aimd-assigner-graph__toolbar-group">
438
+ <button type="button" class="aimd-assigner-graph__icon-btn" :title="resolvedLabels.zoomIn" :aria-label="resolvedLabels.zoomIn" @click="zoomIn">
439
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M11 5v12M5 11h12" /><circle cx="11" cy="11" r="7" /><path d="M16.5 16.5 21 21" /></svg>
440
+ </button>
441
+ <button type="button" class="aimd-assigner-graph__icon-btn" :title="resolvedLabels.fitView" :aria-label="resolvedLabels.fitView" @click="fitView">
442
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" /></svg>
443
+ </button>
444
+ <button type="button" class="aimd-assigner-graph__icon-btn" :title="resolvedLabels.zoomOut" :aria-label="resolvedLabels.zoomOut" @click="zoomOut">
445
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 11h12" /><circle cx="11" cy="11" r="7" /><path d="M16.5 16.5 21 21" /></svg>
446
+ </button>
447
+ <span class="aimd-assigner-graph__zoom">{{ zoomPercent }}</span>
448
+ </div>
449
+
450
+ <button type="button" class="aimd-assigner-graph__mode-btn" @click="toggleDisplayMode">
451
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 6h16M4 12h10M4 18h16" /></svg>
452
+ {{ showTitle ? resolvedLabels.showName : resolvedLabels.showTitle }}
453
+ </button>
454
+
455
+ <button
456
+ v-if="allowFullscreen"
457
+ type="button"
458
+ class="aimd-assigner-graph__mode-btn aimd-assigner-graph__fullscreen-btn"
459
+ @click="toggleFullscreen"
460
+ >
461
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5" /></svg>
462
+ {{ fullscreen ? resolvedLabels.close : resolvedLabels.fullscreen }}
463
+ </button>
464
+ </div>
465
+
466
+ <div v-if="showLegend" class="aimd-assigner-graph__legend">
467
+ <span class="aimd-assigner-graph__legend-item">
468
+ <span class="aimd-assigner-graph__legend-swatch aimd-assigner-graph__legend-swatch--dependent-field" />
469
+ {{ resolvedLabels.dependentField }}
470
+ </span>
471
+ <span class="aimd-assigner-graph__legend-item">
472
+ <span class="aimd-assigner-graph__legend-swatch aimd-assigner-graph__legend-swatch--assigner" />
473
+ {{ resolvedLabels.assigner }}
474
+ </span>
475
+ <span class="aimd-assigner-graph__legend-item">
476
+ <span class="aimd-assigner-graph__legend-swatch aimd-assigner-graph__legend-swatch--assigned-field" />
477
+ {{ resolvedLabels.assignedField }}
478
+ </span>
479
+ </div>
480
+
481
+ <div ref="canvasRef" class="aimd-assigner-graph__canvas" @click.self="clearSelection">
482
+ <div v-if="loading" class="aimd-assigner-graph__state">
483
+ <span class="aimd-assigner-graph__spinner" aria-hidden="true" />
484
+ {{ resolvedLabels.loading }}
485
+ </div>
486
+ <div v-else-if="layoutGraph.nodes.length === 0" class="aimd-assigner-graph__state">
487
+ {{ resolvedLabels.empty }}
488
+ </div>
489
+ <svg
490
+ v-else
491
+ class="aimd-assigner-graph__svg"
492
+ :width="svgWidth"
493
+ :height="svgHeight"
494
+ :viewBox="`0 0 ${layoutGraph.width} ${layoutGraph.height}`"
495
+ role="img"
496
+ :aria-label="resolvedLabels.fullscreenTitle"
497
+ >
498
+ <defs>
499
+ <marker :id="markerId" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
500
+ <path d="M 0 0 L 10 5 L 0 10 z" class="aimd-assigner-graph__marker" />
501
+ </marker>
502
+ <marker :id="highlightedMarkerId" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
503
+ <path d="M 0 0 L 10 5 L 0 10 z" class="aimd-assigner-graph__marker aimd-assigner-graph__marker--highlighted" />
504
+ </marker>
505
+ </defs>
506
+
507
+ <g class="aimd-assigner-graph__edges">
508
+ <path
509
+ v-for="edge in layoutGraph.edges"
510
+ :key="`${edge.from}->${edge.to}`"
511
+ class="aimd-assigner-graph__edge"
512
+ :class="{
513
+ 'aimd-assigner-graph__edge--highlighted': edge.highlighted,
514
+ 'aimd-assigner-graph__edge--dimmed': edge.dimmed,
515
+ }"
516
+ :d="edge.path"
517
+ fill="none"
518
+ :marker-end="`url(#${edge.highlighted ? highlightedMarkerId : markerId})`"
519
+ />
520
+ </g>
521
+
522
+ <g class="aimd-assigner-graph__nodes">
523
+ <g
524
+ v-for="node in layoutGraph.nodes"
525
+ :key="node.name"
526
+ class="aimd-assigner-graph__node"
527
+ :class="[
528
+ `aimd-assigner-graph__node--${node.type.replace('_', '-')}`,
529
+ {
530
+ 'aimd-assigner-graph__node--highlighted': node.highlighted,
531
+ 'aimd-assigner-graph__node--dimmed': node.dimmed,
532
+ },
533
+ ]"
534
+ :transform="`translate(${node.x} ${node.y})`"
535
+ tabindex="0"
536
+ role="button"
537
+ :aria-label="node.fullLabel"
538
+ @click.stop="onNodeClick(node, $event)"
539
+ @keydown.enter.prevent="onNodeKeyboard(node, $event)"
540
+ @keydown.space.prevent="onNodeKeyboard(node, $event)"
541
+ >
542
+ <title>{{ getNodeTooltip(node) }}</title>
543
+ <rect
544
+ class="aimd-assigner-graph__node-shape"
545
+ :width="node.width"
546
+ :height="node.height"
547
+ :rx="node.type === 'assigner' ? node.height / 2 : 8"
548
+ />
549
+ <text
550
+ class="aimd-assigner-graph__node-label"
551
+ :x="node.width / 2"
552
+ :y="node.height / 2"
553
+ dominant-baseline="middle"
554
+ text-anchor="middle"
555
+ >
556
+ {{ node.label }}
557
+ </text>
558
+ </g>
559
+ </g>
560
+ </svg>
561
+ </div>
562
+ </div>
563
+ </template>
564
+
565
+ <style scoped>
566
+ .aimd-assigner-graph {
567
+ display: flex;
568
+ flex-direction: column;
569
+ min-height: 360px;
570
+ height: var(--aimd-assigner-graph-height);
571
+ border: 1px solid #dbe3ef;
572
+ border-radius: 8px;
573
+ background: #ffffff;
574
+ color: #1f2937;
575
+ overflow: hidden;
576
+ }
577
+
578
+ .aimd-assigner-graph--fullscreen {
579
+ position: fixed;
580
+ inset: 12px;
581
+ z-index: 1000;
582
+ height: auto;
583
+ box-shadow: 0 24px 72px rgba(15, 23, 42, 0.22);
584
+ }
585
+
586
+ .aimd-assigner-graph__toolbar {
587
+ display: flex;
588
+ align-items: center;
589
+ gap: 10px;
590
+ padding: 8px 12px;
591
+ border-bottom: 1px solid #e2e8f0;
592
+ background: #f8fafc;
593
+ }
594
+
595
+ .aimd-assigner-graph__toolbar-group {
596
+ display: inline-flex;
597
+ align-items: center;
598
+ gap: 4px;
599
+ }
600
+
601
+ .aimd-assigner-graph__icon-btn,
602
+ .aimd-assigner-graph__mode-btn {
603
+ display: inline-flex;
604
+ align-items: center;
605
+ justify-content: center;
606
+ gap: 6px;
607
+ min-height: 30px;
608
+ border: 1px solid #cbd5e1;
609
+ border-radius: 6px;
610
+ background: #ffffff;
611
+ color: #334155;
612
+ cursor: pointer;
613
+ font: inherit;
614
+ font-size: 13px;
615
+ line-height: 1;
616
+ }
617
+
618
+ .aimd-assigner-graph__icon-btn {
619
+ width: 30px;
620
+ padding: 0;
621
+ }
622
+
623
+ .aimd-assigner-graph__mode-btn {
624
+ padding: 0 10px;
625
+ }
626
+
627
+ .aimd-assigner-graph__fullscreen-btn {
628
+ margin-left: auto;
629
+ }
630
+
631
+ .aimd-assigner-graph__icon-btn:hover,
632
+ .aimd-assigner-graph__mode-btn:hover {
633
+ border-color: #94a3b8;
634
+ background: #f1f5f9;
635
+ }
636
+
637
+ .aimd-assigner-graph__icon-btn svg,
638
+ .aimd-assigner-graph__mode-btn svg {
639
+ width: 15px;
640
+ height: 15px;
641
+ fill: none;
642
+ stroke: currentColor;
643
+ stroke-width: 2;
644
+ stroke-linecap: round;
645
+ stroke-linejoin: round;
646
+ }
647
+
648
+ .aimd-assigner-graph__zoom {
649
+ min-width: 42px;
650
+ color: #64748b;
651
+ font-size: 12px;
652
+ font-variant-numeric: tabular-nums;
653
+ text-align: center;
654
+ }
655
+
656
+ .aimd-assigner-graph__legend {
657
+ display: flex;
658
+ flex-wrap: wrap;
659
+ gap: 16px;
660
+ padding: 8px 12px;
661
+ border-bottom: 1px solid #e2e8f0;
662
+ background: #ffffff;
663
+ color: #64748b;
664
+ font-size: 13px;
665
+ }
666
+
667
+ .aimd-assigner-graph__legend-item {
668
+ display: inline-flex;
669
+ align-items: center;
670
+ gap: 6px;
671
+ }
672
+
673
+ .aimd-assigner-graph__legend-swatch {
674
+ width: 28px;
675
+ height: 17px;
676
+ border: 1.5px solid currentColor;
677
+ border-radius: 5px;
678
+ }
679
+
680
+ .aimd-assigner-graph__legend-swatch--dependent-field {
681
+ background: #eff6ff;
682
+ color: #60a5fa;
683
+ }
684
+
685
+ .aimd-assigner-graph__legend-swatch--assigner {
686
+ border-radius: 999px;
687
+ background: #fdf2f8;
688
+ color: #ec4899;
689
+ }
690
+
691
+ .aimd-assigner-graph__legend-swatch--assigned-field {
692
+ background: #f0fdf4;
693
+ color: #22c55e;
694
+ }
695
+
696
+ .aimd-assigner-graph__canvas {
697
+ position: relative;
698
+ flex: 1;
699
+ min-height: 0;
700
+ overflow: auto;
701
+ background: #f8fafc;
702
+ }
703
+
704
+ .aimd-assigner-graph__state {
705
+ position: absolute;
706
+ inset: 0;
707
+ display: flex;
708
+ align-items: center;
709
+ justify-content: center;
710
+ gap: 8px;
711
+ color: #64748b;
712
+ font-size: 14px;
713
+ }
714
+
715
+ .aimd-assigner-graph__spinner {
716
+ width: 16px;
717
+ height: 16px;
718
+ border: 2px solid rgba(37, 99, 235, 0.2);
719
+ border-top-color: #2563eb;
720
+ border-radius: 999px;
721
+ animation: aimd-assigner-graph-spin 0.8s linear infinite;
722
+ }
723
+
724
+ .aimd-assigner-graph__svg {
725
+ display: block;
726
+ }
727
+
728
+ .aimd-assigner-graph__edge {
729
+ stroke: #94a3b8;
730
+ stroke-width: 1.4;
731
+ opacity: 1;
732
+ transition: opacity 0.16s ease, stroke 0.16s ease, stroke-width 0.16s ease;
733
+ }
734
+
735
+ .aimd-assigner-graph__edge--highlighted {
736
+ stroke: #f59e0b;
737
+ stroke-width: 2.2;
738
+ }
739
+
740
+ .aimd-assigner-graph__edge--dimmed {
741
+ opacity: 0.16;
742
+ }
743
+
744
+ .aimd-assigner-graph__marker {
745
+ fill: #94a3b8;
746
+ }
747
+
748
+ .aimd-assigner-graph__marker--highlighted {
749
+ fill: #f59e0b;
750
+ }
751
+
752
+ .aimd-assigner-graph__node {
753
+ cursor: pointer;
754
+ outline: none;
755
+ transition: opacity 0.16s ease;
756
+ }
757
+
758
+ .aimd-assigner-graph__node--dimmed {
759
+ opacity: 0.32;
760
+ }
761
+
762
+ .aimd-assigner-graph__node-shape {
763
+ fill: #ffffff;
764
+ stroke: #94a3b8;
765
+ stroke-width: 1.8;
766
+ filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.08));
767
+ transition: fill 0.16s ease, stroke 0.16s ease, stroke-width 0.16s ease;
768
+ }
769
+
770
+ .aimd-assigner-graph__node--dependent-field .aimd-assigner-graph__node-shape {
771
+ fill: #eff6ff;
772
+ stroke: #60a5fa;
773
+ }
774
+
775
+ .aimd-assigner-graph__node--assigner .aimd-assigner-graph__node-shape {
776
+ fill: #fdf2f8;
777
+ stroke: #ec4899;
778
+ }
779
+
780
+ .aimd-assigner-graph__node--assigned-field .aimd-assigner-graph__node-shape {
781
+ fill: #f0fdf4;
782
+ stroke: #22c55e;
783
+ }
784
+
785
+ .aimd-assigner-graph__node--highlighted .aimd-assigner-graph__node-shape,
786
+ .aimd-assigner-graph__node:focus-visible .aimd-assigner-graph__node-shape {
787
+ stroke: #f59e0b;
788
+ stroke-width: 2.4;
789
+ }
790
+
791
+ .aimd-assigner-graph__node-label {
792
+ fill: #334155;
793
+ font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
794
+ font-size: 13px;
795
+ font-weight: 600;
796
+ pointer-events: none;
797
+ }
798
+
799
+ .aimd-assigner-graph__node--dependent-field .aimd-assigner-graph__node-label {
800
+ fill: #1d4ed8;
801
+ }
802
+
803
+ .aimd-assigner-graph__node--assigner .aimd-assigner-graph__node-label {
804
+ fill: #be185d;
805
+ }
806
+
807
+ .aimd-assigner-graph__node--assigned-field .aimd-assigner-graph__node-label {
808
+ fill: #15803d;
809
+ }
810
+
811
+ @keyframes aimd-assigner-graph-spin {
812
+ to {
813
+ transform: rotate(360deg);
814
+ }
815
+ }
816
+ </style>