ice-entity-designer-dsl 0.0.14 → 0.0.16
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/README.md +53 -13
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/compiler/powerToScene.d.ts +34 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/runtime/exportDsl.d.ts +10 -0
- package/dist/types/runtime/renderDsl.d.ts +21 -1
- package/dist/types/types.d.ts +49 -0
- package/dist/types/validate.d.ts +8 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
JSON-first DSL for AI agents to drive `ice-entity-designer` without learning the imperative canvas API.
|
|
4
4
|
|
|
5
|
-
One document
|
|
5
|
+
One JSON DSL, seven document kinds — the same document drives rendering, validation and export:
|
|
6
6
|
|
|
7
7
|
- **ER document** (`entities` / `relations`): entity-relation models and database schemas.
|
|
8
8
|
- **Flowchart document** (`kind: "flowchart"` with `nodes` / `edges`): process flows,
|
|
@@ -21,28 +21,35 @@ One document kind, three shapes:
|
|
|
21
21
|
states, **composite states** (containers — children follow when you drag the parent) and
|
|
22
22
|
transitions labelled `event [guard] / action`. Coordinates are optional — the flow lays
|
|
23
23
|
out left to right.
|
|
24
|
+
- **Power document** (`kind: "power"`): one-line diagrams — equipment kinds mirror
|
|
25
|
+
`ice-entity-designer`'s power pack, `attachedTo` expresses a busbar T-connection and
|
|
26
|
+
`voltageLevel` drives the colour code. Semantic checks (voltage consistency / busbar feed /
|
|
27
|
+
五防) live in `result.designer.validatePower()`. Coordinates are optional.
|
|
24
28
|
|
|
25
29
|
The package contains:
|
|
26
30
|
|
|
27
|
-
- DSL types and schema
|
|
28
|
-
-
|
|
29
|
-
|
|
31
|
+
- DSL types and schema, plus a structural validator that dispatches on `kind`
|
|
32
|
+
- compilers from DSL to component props: `compileDsl` (ER) / `compileFlowDsl` / `compileBpmnDsl` /
|
|
33
|
+
`compileUmlDsl` / `compileStatechartDsl` / `compileGanttDsl` / `compilePowerDsl`, sharing one
|
|
34
|
+
layered layout
|
|
30
35
|
- browser runtime that renders DSL through `ice-entity-designer`
|
|
31
36
|
- browser examples with a JSON editor (`examples/entity-editor-dsl.html`,
|
|
32
37
|
`examples/flowchart-dsl.html`, `examples/bpmn-dsl.html`, `examples/uml-dsl.html`,
|
|
33
|
-
`examples/statechart-dsl.html`, `examples/gantt-dsl.html`)
|
|
34
|
-
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
「适应视图 / 复位视图」 buttons
|
|
38
|
+
`examples/statechart-dsl.html`, `examples/gantt-dsl.html`, `examples/power-dsl.html`)
|
|
39
|
+
- all diagram examples share `examples/canvas-interactions.js`: canvas fills the preview
|
|
40
|
+
pane, wheel zooms at the cursor (`ICE.zoomAt`), dragging blank space (or any middle-button
|
|
41
|
+
drag) pans, plus 「适应视图 / 复位视图」 buttons
|
|
38
42
|
|
|
39
43
|
## Install
|
|
40
44
|
|
|
41
45
|
```bash
|
|
42
|
-
npm install
|
|
43
|
-
npm run build
|
|
46
|
+
npm install ice-entity-designer-dsl
|
|
44
47
|
```
|
|
45
48
|
|
|
49
|
+
This installs `ice-entity-designer` as well (the DSL runtime renders through it; the engine
|
|
50
|
+
kernel ships bundled in that package). For the browser build, load
|
|
51
|
+
`node_modules/ice-entity-designer/dist/index.umd.js` first, then `dist/index.umd.js` — see below.
|
|
52
|
+
|
|
46
53
|
## Browser usage
|
|
47
54
|
|
|
48
55
|
```html
|
|
@@ -248,25 +255,58 @@ intermediate / end) + `trigger`, gateways carry `gatewayType` (exclusive / paral
|
|
|
248
255
|
|
|
249
256
|
## API
|
|
250
257
|
|
|
251
|
-
- `validateDsl(dsl)` —— ER / flowchart / BPMN / UML / statechart / gantt documents (dispatches on `kind`); `validateFlowDsl(dsl)` / `validateBpmnDsl(dsl)` / `validateUmlDsl(dsl)` / `validateStatechartDsl(dsl)` / `validateGanttDsl(dsl)` for one kind only
|
|
258
|
+
- `validateDsl(dsl)` —— ER / flowchart / BPMN / UML / statechart / gantt / power documents (dispatches on `kind`); `validateFlowDsl(dsl)` / `validateBpmnDsl(dsl)` / `validateUmlDsl(dsl)` / `validateStatechartDsl(dsl)` / `validateGanttDsl(dsl)` / `validatePowerDsl(dsl)` for one kind only
|
|
252
259
|
- `compileDsl(dsl)` —— ER document → `Entity` / `Relation` props
|
|
253
260
|
- `compileFlowDsl(dsl)` —— flowchart document → `FlowNode` / `FlowEdge` props (with layered auto-layout)
|
|
254
261
|
- `compileBpmnDsl(dsl)` —— BPMN document → `FlowNode` / `FlowEdge` props (container auto-geometry + container-scoped auto-layout)
|
|
255
262
|
- `compileUmlDsl(dsl)` —— UML document → `UmlClass` / `UmlRelation` props (inheritance-driven layering)
|
|
256
263
|
- `compileStatechartDsl(dsl)` —— statechart document → `StateNode` / `StateTransition` props (flow layering + composite auto-sizing)
|
|
257
264
|
- `compileGanttDsl(dsl)` —— gantt document → `GanttTask` / `GanttDependency` props (no coordinates; rows filled in)
|
|
265
|
+
- `compilePowerDsl(dsl)` —— power document → `PowerSymbol` / `PowerLine` props (busbar T-connections resolved, voltage colour code applied)
|
|
258
266
|
- `layeredLayout(items, edges, options)` —— the shared layered layout (`direction: "vertical" | "horizontal"`)
|
|
259
267
|
- `renderDsl(canvasOrId, dsl)` —— renders any kind, returns `{ kind, ice, designer }`
|
|
268
|
+
- `renderPowerDsl(canvasOrId, dsl)` —— power documents specifically (`renderFlowDsl` / `renderBpmnDsl` / `renderUmlDsl` / `renderStatechartDsl` / `renderGanttDsl` are the per-kind equivalents)
|
|
260
269
|
- Export: `result.designer.toSvg(options)` (flowchart / BPMN) or `IED.exportSvg(result.ice, options)`; `options` = `{ area: 'content' | 'viewport', padding, scale, background, includeTools }`. The SVG is regenerated from the component tree + path commands, so it matches the canvas (geometry, styles, opacity, shadows, link labels) and can be rasterised to PNG/PDF by any external tool.
|
|
261
270
|
- `DSL_SCHEMA_VERSION`
|
|
262
271
|
|
|
272
|
+
## Round-trip: render → edit → `toDsl()`
|
|
273
|
+
|
|
274
|
+
`renderDsl()` 返回的对象自带 `toDsl()`,用来把**用户改过的实例**写回成同一份 DSL 文档:
|
|
275
|
+
|
|
276
|
+
```js
|
|
277
|
+
const result = ICEDSL.renderDsl('canvas', doc);
|
|
278
|
+
|
|
279
|
+
// 用户在画布上拖动 / 改名 / 分合 / 增删……
|
|
280
|
+
result.designer.updateNode('check', { title: '库存够吗?', left: 500, top: 480 });
|
|
281
|
+
|
|
282
|
+
const edited = result.toDsl(); // 同一份 DSL:位置与语义改动都在
|
|
283
|
+
ICEDSL.validateDsl(edited).valid; // true —— 导出结果永远能过校验
|
|
284
|
+
ICEDSL.renderDsl('canvas', edited); // 也能直接再渲染一遍
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
单独使用时是 `toDsl(resultOrDesigner, { kind? })`(不传 `kind` 时按图元自动判别)。
|
|
288
|
+
|
|
289
|
+
契约(7 种 `kind` 都有测试兜底):
|
|
290
|
+
|
|
291
|
+
- **id 保真**:Agent 产出时用的 `id` 原样带回(导出顺序 = 实例顺序,BPMN 会把池/泳道排在业务图元之前);
|
|
292
|
+
文档里没写 `id` 的连线会拿到 `edge-0` 这类稳定 id,而不是每次重新生成的随机 UUID;
|
|
293
|
+
- **坐标是绝对坐标**:嵌套容器(BPMN 池 / 泳道、状态机复合状态)的相对坐标已沿父链还原;
|
|
294
|
+
- **只导出 DSL 词汇表里的字段**:引擎内部字段(zIndex、变换矩阵等)不外泄;
|
|
295
|
+
- **必过校验、必须可序列化**:结果里没有 `undefined`,`JSON.parse(JSON.stringify(doc))` 无损往返;
|
|
296
|
+
- **再渲染等价**:把导出的文档再渲染一遍,节点 id 与位置与上一遍一致;
|
|
297
|
+
- **推断不出来就报错**:实例里没有任何可识别图元时,`toDsl()` 抛错并提示显式传 `kind`,不会悄悄当成 ER 文档。
|
|
298
|
+
|
|
263
299
|
## Example
|
|
264
300
|
|
|
265
301
|
Open `examples/entity-editor-dsl.html` (ER), `examples/flowchart-dsl.html`
|
|
266
302
|
(flowchart), `examples/bpmn-dsl.html` (BPMN), `examples/uml-dsl.html` (UML),
|
|
267
|
-
`examples/statechart-dsl.html` (statechart)
|
|
303
|
+
`examples/statechart-dsl.html` (statechart), `examples/gantt-dsl.html` (gantt) or
|
|
304
|
+
`examples/power-dsl.html` (power one-line diagram) after building.
|
|
268
305
|
渲染结果可以滚轮缩放、空白处拖拽平移,工具栏还有「适应视图 / 复位视图」。
|
|
269
306
|
|
|
307
|
+
每个示例页渲染出来的实例都带 `toDsl()`:在浏览器控制台执行
|
|
308
|
+
`window.__dslResult.toDsl()` 就能看到当前的 DSL 文档(改过的位置与语义都在里面)。
|
|
309
|
+
|
|
270
310
|
## Agent discovery
|
|
271
311
|
|
|
272
312
|
Agents can use this project through:
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("ice-entity-designer");function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const t=["terminator","process","decision","io"],i=["T","R","B","L","C"],r=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],o=["start","intermediate","end"],n=["none","message","timer","error","terminate"],s=["exclusive","parallel","inclusive","event"],a=["none","user","service","script","send","receive","manual"],d=["sequence","message","association"],p=["initial","final","state","composite"],l=["class","interface","enum"],h=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,r)=>{const o=`entities[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${o}.fields[${i}].name must be a non-empty string`)}):t.push(o+".fields must be an array")):t.push(o+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const r=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(r+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(r+".target must be a non-empty string")):t.push(r+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,p=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,d)=>{const l=`nodes[${d}]`;if(!e||"object"!=typeof e)return void t.push(l+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${l}.id is duplicated: ${e.id}`):(i.add(e.id),p.set(e.id,e.kind||"task")):t.push(l+".id must be a non-empty string"),void 0!==e.kind&&-1===r.indexOf(e.kind)&&t.push(`${l}.kind must be one of ${r.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${l}.${i} must be a number when present`)});[["eventKind",o],["trigger",n],["gatewayType",s],["taskType",a]].forEach(([i,r])=>{const o=e[i];void 0!==o&&-1===r.indexOf(o)&&t.push(`${l}.${i} must be one of ${r.join("/")}`)})}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const o=`nodes[${r}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(o+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(o+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(o+".parent must not reference itself");const n=p.get(e.parent);"pool"===e.kind?t.push(o+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==n?t.push(o+".parent must reference a pool"):"pool"!==n&&"lane"!==n&&t.push(o+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===d.indexOf(n)&&t.push(`${o}.type must be one of ${d.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(o+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(o+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const r=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&r.push("Unsupported schemaVersion: "+e.schemaVersion);const o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const n=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?r.push(`${n}.id is duplicated: ${e.id}`):o.add(e.id):r.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===t.indexOf(e.kind)&&r.push(`${n}.kind must be one of ${t.join("/")}`),["left","top","width","height"].forEach(t=>{const i=e[t];void 0!==i&&"number"!=typeof i&&r.push(`${n}.${t} must be a number when present`)})):r.push(n+" must be an object")}):r.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,t)=>{const n=`edges[${t}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&o.has(e.source)||r.push(n+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||r.push(n+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&r.push(n+".label must be a string when present"),void 0!==e.sourcePort&&-1===i.indexOf(e.sourcePort)&&r.push(`${n}.sourcePort must be one of ${i.join("/")}`),void 0!==e.targetPort&&-1===i.indexOf(e.targetPort)&&r.push(`${n}.targetPort must be one of ${i.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&r.push(n+'.linkShape must be "visio" or "bezier" when present')):r.push(n+" must be an object")}):r.push("edges must be an array when present"),{valid:0===r.length,errors:r}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),void 0!==e.kind&&-1===l.indexOf(e.kind)&&t.push(`${o}.kind must be one of ${l.join("/")}`),["attributes","methods"].forEach(i=>{const r=e[i];void 0!==r&&(Array.isArray(r)&&!r.some(e=>"string"!=typeof e)||t.push(`${o}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${o}.${i} must be a number when present`)})):t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===h.indexOf(n)&&t.push(`${o}.type must be one of ${h.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,r=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),r.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===p.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${p.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==r.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const r=e[i];void 0!==r&&"string"!=typeof r&&t.push(`${o}.${i} must be a string when present`)})):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(o+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(o+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(o+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(o+".row must be a number >= 0 when present")}else t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing task id")):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const r=Number(i.gapX)||90,o=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const p=new Map,l=new Map;e.forEach(e=>{p.set(e.id,0),l.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(p.set(e.targetId,(p.get(e.targetId)||0)+1),l.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(p.get(e.id)||0)&&(h.set(e.id,0),c.push(e.id))}),c.length||(h.set(e[0].id,0),c.push(e[0].id));let u=e.length*e.length+e.length;for(;c.length&&u-- >0;){const e=c.shift(),t=h.get(e)||0;(l.get(e)||[]).forEach(e=>{const i=t+1;(void 0===h.get(e)?-1:h.get(e))<i&&(h.set(e,i),c.push(e))})}e.forEach(e=>{h.has(e.id)||h.set(e.id,0)});const m=new Map;e.forEach(e=>{const t=h.get(e.id)||0;m.has(t)||m.set(t,[]),m.get(t).push(e)});const f=[...m.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=f.map(e=>Math.max(...m.get(e).map(e=>e.width)));let t=0;f.forEach((i,n)=>{const s=m.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+o}),t+=e[n]+r})}else{const e=f.map(e=>Math.max(...m.get(e).map(e=>e.height)));let t=0;f.forEach((i,n)=>{const s=m.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+r}),t+=e[n]+o})}const g=Math.min(...e.map(e=>a.get(e.id).left)),y=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-y}),a}const c={terminator:{width:e.FLOW_NODE_KINDS.terminator.width,height:e.FLOW_NODE_KINDS.terminator.height,fill:e.FLOW_NODE_KINDS.terminator.fill,stroke:e.FLOW_NODE_KINDS.terminator.stroke},process:{width:e.FLOW_NODE_KINDS.process.width,height:e.FLOW_NODE_KINDS.process.height,fill:e.FLOW_NODE_KINDS.process.fill,stroke:e.FLOW_NODE_KINDS.process.stroke},decision:{width:e.FLOW_NODE_KINDS.decision.width,height:e.FLOW_NODE_KINDS.decision.height,fill:e.FLOW_NODE_KINDS.decision.fill,stroke:e.FLOW_NODE_KINDS.decision.stroke},io:{width:e.FLOW_NODE_KINDS.io.width,height:e.FLOW_NODE_KINDS.io.height,fill:e.FLOW_NODE_KINDS.io.fill,stroke:e.FLOW_NODE_KINDS.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&c[e.kind]?e.kind:"process"}(e),i=c[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(r=e,r.title||r.name||r.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var r}),r=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),o=t.layout||"layered";return"none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,r){const o=layeredLayout(e,t,{gapX:i,gapY:r});e.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,r,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:r,layout:o,options:t}}const u={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},m=Number(e.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,f=Number(e.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,g=Number(e.FLOW_NODE_KINDS.bpmnLane.height)||130,y=Number(e.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(t){const i=t.kind||"task",r=function presetOf(t){return e.FLOW_NODE_KINDS[t]||e.FLOW_NODE_KINDS.bpmnTask}(u[i]||"bpmnTask"),o={id:t.id,typeId:"FlowNode",kind:u[i]||"bpmnTask",title:t.title||t.name||t.id,left:"number"==typeof t.left?t.left:0,top:"number"==typeof t.top?t.top:0,width:"number"==typeof t.width?t.width:r.width,height:"number"==typeof t.height?t.height:r.height,fillColor:t.fillColor,strokeColor:t.strokeColor,dslKind:i,parent:t.parent,explicitLeft:"number"==typeof t.left,explicitTop:"number"==typeof t.top,explicitWidth:"number"==typeof t.width,explicitHeight:"number"==typeof t.height};return"event"===i&&(o.eventKind=t.eventKind||r.eventKind||"start",o.trigger=t.trigger||r.trigger||"none"),"gateway"===i&&(o.gatewayType=t.gatewayType||r.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(o.taskType=t.taskType||r.taskType||"none"),o}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const r=1===t.length?t[0]:null,o=[];return e.forEach(e=>{(e=>{let t=o.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},o.push(t)),t})((e.parent?i.get(e.parent):void 0)||r).nodes.push(e)}),o}function layoutGroups(e,t,i,r){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const o=layeredLayout(e.nodes,t,{gapX:i,gapY:r,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,r=-1/0,o=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),r=Math.max(r,e.left+e.width),o=Math.max(o,e.top+e.height)}),{minX:t,minY:i,maxX:r,maxY:o}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),r=i.filter(e=>"pool"===e.dslKind),o=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let r=e.parent;r||1!==t.length||(r=t[0].id),r&&i.set(e.id,r)}),i}(o,r),lanesOf=e=>o.filter(t=>d.get(t.id)===e);let p=[];"none"!==a&&(p=buildGroups(n,r.concat(o)),layoutGroups(p,s,Number(t.gapX)||90,Number(t.gapY)||60)),o.forEach(e=>{const t=p.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),g))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+f+56,y)))}),r.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),y);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=m+t.reduce((e,t)=>e+t.height,0)))}const i=p.filter(t=>t.owner===e)[0],r=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(r?r.maxX-r.minX:0),y))),e.explicitHeight||(e.height=Math.round(Math.max((r?r.maxY-r.minY:0)+m+56,160)))});let l=60;r.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=l),l=Math.max(l,e.top+e.height+60)}),r.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+m,r=Math.max(e.height-m,1),o=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(r-o,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||g)),a=t.top+t.height})});let h=60;o.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),p.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let r=80,o=80;i&&(r=i.left+28,o=i.top+28,"pool"===i.dslKind?o+=m:r+=f),e.nodes.forEach(e=>{e.left=Math.round(r+(e.left-t.minX)),e.top=Math.round(o+(e.top-t.minY))})});return{kind:"bpmn",nodes:r.concat(o).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),r=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),o=t.layout||"layered";if("none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,r.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:r,layout:o,options:t}}const b={width:160,height:64},w={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,r="composite"===t?w:i?{width:24,height:24}:b;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:r.width,height:"number"==typeof e.height?e.height:r.height}}),r=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),o=t.layout||"auto",n=new Set;if("none"!==o){const e=new Map;i.forEach(t=>e.set(t.id,t));const o=i.filter(t=>!(t.parent&&e.has(t.parent)));if(o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=r.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(o,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});o.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...o.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let r=56,a=56,d=0,p=56;const l=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(r>56&&r+e.width>56+l&&(r=56,a=p+40),n.add(e.id),e.left=r,e.top=a,r+=e.width+40,d=Math.max(d,r),p=Math.max(p,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,p+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,r)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=r,offsetChildren(e,t,r))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:r,layout:o,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderGanttDsl(t,i){const r=compileGanttDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.GanttDesigner(n);return o.dayWidth&&s.setDayWidth(o.dayWidth),r.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),r.edges.forEach(e=>{s.createDependency(e)}),s.select(null),o.autoSchedule&&s.autoSchedule(),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderStatechartDsl(t,i){const r=compileStatechartDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.StatechartDesigner(n);return r.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{s.createTransition(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"statechart",ice:n,designer:s}}function renderUmlDsl(t,i){const r=compileUmlDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.UmlDesigner(n);return r.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),r.edges.forEach(e=>{s.createRelation(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:n,designer:s}}function renderBpmnDsl(t,i){const r=compileBpmnDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.BpmnDesigner(n);return r.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),s.createNode(e.kind,t)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:n,designer:s}}function renderFlowDsl(t,i){const r=compileFlowDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.FlowDesigner(n);return r.nodes.forEach(e=>{s.createNode(e.kind,e)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:n,designer:s}}exports.DSL_SCHEMA_VERSION=1,exports.compileBpmnDsl=compileBpmnDsl,exports.compileDsl=compileDsl,exports.compileFlowDsl=compileFlowDsl,exports.compileGanttDsl=compileGanttDsl,exports.compileStatechartDsl=compileStatechartDsl,exports.compileUmlDsl=compileUmlDsl,exports.isBpmnDsl=isBpmnDsl,exports.isFlowDsl=isFlowDsl,exports.isGanttDsl=isGanttDsl,exports.isStatechartDsl=isStatechartDsl,exports.isUmlDsl=isUmlDsl,exports.layeredLayout=layeredLayout,exports.renderBpmnDsl=renderBpmnDsl,exports.renderDsl=function renderDsl(t,i){const r=validateDsl(i);if(!r.valid)throw new Error(r.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(t,i):isStatechartDsl(i)?renderStatechartDsl(t,i):isUmlDsl(i)?renderUmlDsl(t,i):isBpmnDsl(i)?renderBpmnDsl(t,i):isFlowDsl(i)?renderFlowDsl(t,i):function renderErDsl(t,i){const r=compileDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.EntityDesigner(n);r.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const r=new Map;return e.entities.forEach(e=>{r.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=r.get(e.sourceId),o=r.get(e.targetId);let n="R",s="L";if(t&&o){const e=o.center[0]-t.center[0],i=o.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,r,o.routeType).forEach(e=>{s.createRelation(e)}),("layered"===r.layout||"horizontal"===r.layout)&&new e.ICELayeredLayout({gapX:o.gapX||120,gapY:o.gapY||50}).layoutContainer(n);o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):o.fitViewport&&function fitViewport(e,t,i){const r=t.entities||[];let o=1/0,n=1/0,s=-1/0,a=-1/0;r.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();o=Math.min(o,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-o,p=a-n,l=e.canvasWidth||0,h=e.canvasHeight||0;if(!l||!h||d<=0||p<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,l-2*c),m=Math.max(1,h-2*c),f=Math.min(u/d,m/p,1),g=(l-d*f)/2-o*f,y=(h-p*f)/2-n*f;e.setViewport(f,g,y)}(n,s,o.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(t,i)},exports.renderFlowDsl=renderFlowDsl,exports.renderGanttDsl=renderGanttDsl,exports.renderStatechartDsl=renderStatechartDsl,exports.renderUmlDsl=renderUmlDsl,exports.validateBpmnDsl=validateBpmnDsl,exports.validateDsl=validateDsl,exports.validateFlowDsl=validateFlowDsl,exports.validateGanttDsl=validateGanttDsl,exports.validateStatechartDsl=validateStatechartDsl,exports.validateUmlDsl=validateUmlDsl;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("ice-entity-designer");function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const t=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"];function isPowerDsl(e){return!!e&&"object"==typeof e&&"power"===e.kind}const r=["terminator","process","decision","io"],i=["T","R","B","L","C"],o=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],n=["start","intermediate","end"],s=["none","message","timer","error","terminate"],a=["exclusive","parallel","inclusive","event"],d=["none","user","service","script","send","receive","manual"],l=["sequence","message","association"],p=["initial","final","state","composite"],c=["class","interface","enum"],u=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isPowerDsl(e)?validatePowerDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const r=new Set;e.entities.forEach((e,i)=>{const o=`entities[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?r.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):r.add(e.id):t.push(o+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,r)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${o}.fields[${r}].name must be a non-empty string`)}):t.push(o+".fields must be an array")):t.push(o+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,r)=>{const i=`relations[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(i+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(i+".target must be a non-empty string")):t.push(i+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const r=new Set,i=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,l)=>{const p=`nodes[${l}]`;if(!e||"object"!=typeof e)return void t.push(p+" must be an object");"string"==typeof e.id&&e.id.trim()?r.has(e.id)?t.push(`${p}.id is duplicated: ${e.id}`):(r.add(e.id),i.set(e.id,e.kind||"task")):t.push(p+".id must be a non-empty string"),void 0!==e.kind&&-1===o.indexOf(e.kind)&&t.push(`${p}.kind must be one of ${o.join("/")}`),["left","top","width","height"].forEach(r=>{const i=e[r];void 0!==i&&"number"!=typeof i&&t.push(`${p}.${r} must be a number when present`)});[["eventKind",n],["trigger",s],["gatewayType",a],["taskType",d]].forEach(([r,i])=>{const o=e[r];void 0!==o&&-1===i.indexOf(o)&&t.push(`${p}.${r} must be one of ${i.join("/")}`)})}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!r.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=i.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const o=`edges[${i}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&r.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&r.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===l.indexOf(n)&&t.push(`${o}.type must be one of ${l.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(o+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(o+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const n=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):o.add(e.id):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===r.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${r.join("/")}`),["left","top","width","height"].forEach(r=>{const i=e[r];void 0!==i&&"number"!=typeof i&&t.push(`${n}.${r} must be a number when present`)})):t.push(n+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const n=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(n+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||t.push(n+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present"),void 0!==e.sourcePort&&-1===i.indexOf(e.sourcePort)&&t.push(`${n}.sourcePort must be one of ${i.join("/")}`),void 0!==e.targetPort&&-1===i.indexOf(e.targetPort)&&t.push(`${n}.targetPort must be one of ${i.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(n+'.linkShape must be "visio" or "bezier" when present')):t.push(n+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const r=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const o=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?r.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):r.add(e.id):t.push(o+".id must be a non-empty string"),void 0!==e.kind&&-1===c.indexOf(e.kind)&&t.push(`${o}.kind must be one of ${c.join("/")}`),["attributes","methods"].forEach(r=>{const i=e[r];void 0!==i&&(Array.isArray(i)&&!i.some(e=>"string"!=typeof e)||t.push(`${o}.${r} must be an array of strings when present`))}),["left","top","width","height"].forEach(r=>{const i=e[r];void 0!==i&&"number"!=typeof i&&t.push(`${o}.${r} must be a number when present`)})):t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const o=`edges[${i}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&r.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&r.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===u.indexOf(n)&&t.push(`${o}.type must be one of ${u.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const r=new Set,i=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?r.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(r.add(e.id),i.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===p.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${p.join("/")}`),["left","top","width","height"].forEach(r=>{const i=e[r];void 0!==i&&"number"!=typeof i&&t.push(`${n}.${r} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;"string"==typeof e.parent&&e.parent.trim()&&r.has(e.parent)?e.parent!==e.id?"composite"!==i.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const o=`edges[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&r.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&r.has(e.target)||t.push(o+".target must reference an existing node id"),["event","guard","action","label"].forEach(r=>{const i=e[r];void 0!==i&&"string"!=typeof i&&t.push(`${o}.${r} must be a string when present`)})):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const r=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const o=`nodes[${i}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?r.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):r.add(e.id):t.push(o+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(o+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(o+".days must be a number >= 1 when present"),void 0!==e.progress){const r=Number(e.progress);r>=0&&r<=1||t.push(o+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(o+".row must be a number >= 0 when present")}else t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const o=`edges[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&r.has(e.source)||t.push(o+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&r.has(e.target)||t.push(o+".target must reference an existing task id")):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validatePowerDsl(e){const r=[],i=Array.isArray(e.nodes)?e.nodes:[];Array.isArray(e.nodes)||r.push("nodes must be an array");const o=new Set;return i.forEach((e,i)=>{const n=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id?o.has(e.id)?r.push("duplicated node id: "+e.id):o.add(e.id):r.push(n+".id must be a non-empty string"),-1===t.indexOf(e.kind)&&r.push(`${n}.kind must be one of ${t.join(" / ")}`),void 0===e.voltageLevel||/^\d+(\.\d+)?kV$/.test(String(e.voltageLevel))||r.push(n+'.voltageLevel must look like "110kV"')):r.push(n+" must be an object")}),i.forEach((e,t)=>{if(!e||void 0===e.attachedTo)return;const o=i.find(t=>t&&t.id===e.attachedTo);o?"busbar"!==o.kind&&r.push(`nodes[${t}].attachedTo must point at a busbar: ${e.attachedTo} is ${o.kind}`):r.push(`nodes[${t}].attachedTo references an unknown node: ${e.attachedTo}`)}),(e.edges||[]).forEach((e,t)=>{const i=`edges[${t}]`;e&&"object"==typeof e?(o.has(e.source)||r.push(`${i}.source references an unknown node: ${e.source}`),o.has(e.target)||r.push(`${i}.target references an unknown node: ${e.target}`),e.source===e.target&&r.push(i+" must not connect a node to itself")):r.push(i+" must be an object")}),{valid:0===r.length,errors:r}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,r={}){const i=Number(r.gapX)||90,o=Number(r.gapY)||90,n=void 0===r.originX?80:r.originX,s=void 0===r.originY?80:r.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const l=new Map,p=new Map;e.forEach(e=>{l.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(l.set(e.targetId,(l.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const c=new Map,u=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(c.set(e.id,0),u.push(e.id))}),u.length||(c.set(e[0].id,0),u.push(e[0].id));let h=e.length*e.length+e.length;for(;u.length&&h-- >0;){const e=u.shift(),t=c.get(e)||0;(p.get(e)||[]).forEach(e=>{const r=t+1;(void 0===c.get(e)?-1:c.get(e))<r&&(c.set(e,r),u.push(e))})}e.forEach(e=>{c.has(e.id)||c.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=c.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===r.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((r,n)=>{const s=f.get(r);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*o)/2;s.forEach(r=>{a.set(r.id,{left:Math.round(t+(e[n]-r.width)/2),top:Math.round(d)}),d+=r.height+o}),t+=e[n]+i})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((r,n)=>{const s=f.get(r);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*i)/2;s.forEach(r=>{a.set(r.id,{left:Math.round(d),top:Math.round(t+(e[n]-r.height)/2)}),d+=r.width+i}),t+=e[n]+o})}const g=Math.min(...e.map(e=>a.get(e.id).left)),b=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-b}),a}const h={terminator:{width:e.FLOW_NODE_KINDS.terminator.width,height:e.FLOW_NODE_KINDS.terminator.height,fill:e.FLOW_NODE_KINDS.terminator.fill,stroke:e.FLOW_NODE_KINDS.terminator.stroke},process:{width:e.FLOW_NODE_KINDS.process.width,height:e.FLOW_NODE_KINDS.process.height,fill:e.FLOW_NODE_KINDS.process.fill,stroke:e.FLOW_NODE_KINDS.process.stroke},decision:{width:e.FLOW_NODE_KINDS.decision.width,height:e.FLOW_NODE_KINDS.decision.height,fill:e.FLOW_NODE_KINDS.decision.fill,stroke:e.FLOW_NODE_KINDS.decision.stroke},io:{width:e.FLOW_NODE_KINDS.io.width,height:e.FLOW_NODE_KINDS.io.height,fill:e.FLOW_NODE_KINDS.io.fill,stroke:e.FLOW_NODE_KINDS.io.stroke}};function compileFlowDsl(e){const t=e.options||{},r=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&h[e.kind]?e.kind:"process"}(e),r=h[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(i=e,i.title||i.name||i.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:r.width,height:"number"==typeof e.height?e.height:r.height,fillColor:e.fillColor||r.fill,strokeColor:e.strokeColor||r.stroke};var i}),i=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),o=t.layout||"layered";return"none"!==o&&r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(r.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,r,i){const o=layeredLayout(e,t,{gapX:r,gapY:i});e.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(r,i,Number(t.gapX)||90,Number(t.gapY)||90)),r.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:r,edges:i,layout:o,options:t}}const f={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},m=Number(e.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,g=Number(e.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,b=Number(e.FLOW_NODE_KINDS.bpmnLane.height)||130,y=Number(e.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(t){const r=t.kind||"task",i=function presetOf(t){return e.FLOW_NODE_KINDS[t]||e.FLOW_NODE_KINDS.bpmnTask}(f[r]||"bpmnTask"),o={id:t.id,typeId:"FlowNode",kind:f[r]||"bpmnTask",title:t.title||t.name||t.id,left:"number"==typeof t.left?t.left:0,top:"number"==typeof t.top?t.top:0,width:"number"==typeof t.width?t.width:i.width,height:"number"==typeof t.height?t.height:i.height,fillColor:t.fillColor,strokeColor:t.strokeColor,dslKind:r,parent:t.parent,explicitLeft:"number"==typeof t.left,explicitTop:"number"==typeof t.top,explicitWidth:"number"==typeof t.width,explicitHeight:"number"==typeof t.height};return"event"===r&&(o.eventKind=t.eventKind||i.eventKind||"start",o.trigger=t.trigger||i.trigger||"none"),"gateway"===r&&(o.gatewayType=t.gatewayType||i.gatewayType||"exclusive"),"task"!==r&&"subprocess"!==r||(o.taskType=t.taskType||i.taskType||"none"),o}function buildGroups(e,t){const r=new Map;t.forEach(e=>r.set(e.id,e));const i=1===t.length?t[0]:null,o=[];return e.forEach(e=>{(e=>{let t=o.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},o.push(t)),t})((e.parent?r.get(e.parent):void 0)||i).nodes.push(e)}),o}function layoutGroups(e,t,r,i){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const o=layeredLayout(e.nodes,t,{gapX:r,gapY:i,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,r=1/0,i=-1/0,o=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),r=Math.min(r,e.top),i=Math.max(i,e.left+e.width),o=Math.max(o,e.top+e.height)}),{minX:t,minY:r,maxX:i,maxY:o}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},r=(e.nodes||[]).map(toWorkingNode),i=r.filter(e=>"pool"===e.dslKind),o=r.filter(e=>"lane"===e.dslKind),n=r.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const r=new Map;return e.forEach(e=>{let i=e.parent;i||1!==t.length||(i=t[0].id),i&&r.set(e.id,i)}),r}(o,i),lanesOf=e=>o.filter(t=>d.get(t.id)===e);let l=[];"none"!==a&&(l=buildGroups(n,i.concat(o)),layoutGroups(l,s,Number(t.gapX)||90,Number(t.gapY)||60)),o.forEach(e=>{const t=l.filter(t=>t.owner===e)[0],r=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(r?r.maxY-r.minY:0),b))),e.explicitWidth||(e.width=Math.round(Math.max((r?r.maxX-r.minX:0)+g+56,y)))}),i.forEach(e=>{const t=lanesOf(e.id);if(t.length){const r=t.reduce((e,t)=>Math.max(e,t.width),y);return e.explicitWidth||(e.width=r),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=m+t.reduce((e,t)=>e+t.height,0)))}const r=l.filter(t=>t.owner===e)[0],i=r?r.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(i?i.maxX-i.minX:0),y))),e.explicitHeight||(e.height=Math.round(Math.max((i?i.maxY-i.minY:0)+m+56,160)))});let p=60;i.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=p),p=Math.max(p,e.top+e.height+60)}),i.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const r=e.top+m,i=Math.max(e.height-m,1),o=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(i-o,0)/n.length:0;let a=r;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||b)),a=t.top+t.height})});let c=60;o.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=c,c=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const r=e.owner;let i=80,o=80;r&&(i=r.left+28,o=r.top+28,"pool"===r.dslKind?o+=m:i+=g),e.nodes.forEach(e=>{e.left=Math.round(i+(e.left-t.minX)),e.top=Math.round(o+(e.top-t.minY))})});return{kind:"bpmn",nodes:i.concat(o).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},r=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),i=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),o=t.layout||"layered";if("none"!==o&&r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){r.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(r,i.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});r.forEach(t=>{const r=e.get(t.id);r&&(t.left=r.left,t.top=r.top)})}return r.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:r,edges:i,layout:o,options:t}}const w={width:160,height:64},v={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},r=(e.nodes||[]).map(e=>{const t=e.kind||"state",r="initial"===t||"final"===t,i="composite"===t?v:r?{width:24,height:24}:w;return{id:e.id,kind:t,title:e.title||e.name||(r?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height}}),i=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),o=t.layout||"auto",n=new Set;if("none"!==o){const e=new Map;r.forEach(t=>e.set(t.id,t));const o=r.filter(t=>!(t.parent&&e.has(t.parent)));if(o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let r=e.get(t);for(;r&&r.parent&&e.has(r.parent);)r=e.get(r.parent);return r?r.id:t},r=i.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(o,r,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});o.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;r.filter(e=>"composite"===e.kind).forEach(e=>{const t=r.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...o.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let i=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(i>56&&i+e.width>56+p&&(i=56,a=l+40),n.add(e.id),e.left=i,e.top=a,i+=e.width+40,d=Math.max(d,i),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),r.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,i)=>{r.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=i,offsetChildren(e,t,i))})};r.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:r,edges:i,layout:o,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function compilePowerDsl(e){const t=e.options||{},r=(e.nodes||[]).map((e,t)=>{const r=function defaultPlacement(e){return{left:120+e%6*200,top:120+160*Math.floor(e/6)}}(t);return{id:e.id,kind:e.kind,title:e.title||e.name||e.id,voltageLevel:String(e.voltageLevel||""),left:"number"==typeof e.left?e.left:r.left,top:"number"==typeof e.top?e.top:r.top,width:e.width,height:e.height,switchState:e.switchState,source:!!e.source}}),i=new Map;r.forEach(e=>i.set(e.id,e));return{kind:"power",nodes:r,edges:(e.edges||[]).map((e,t)=>({id:e.id||"conductor-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",voltageLevel:e.voltageLevel||(i.get(e.source)||{}).voltageLevel||""})),attachments:(e.nodes||[]).filter(e=>!!e.attachedTo).map(e=>({deviceId:e.id,busId:String(e.attachedTo)})),options:t}}const D={bpmnPool:"pool",bpmnLane:"lane",bpmnTask:"task",bpmnEvent:"event",bpmnGateway:"gateway",bpmnSubprocess:"subprocess",bpmnDataObject:"dataObject",bpmnAnnotation:"annotation"},O=["terminator","process","decision","io"],x=["class","interface","enum"],k=["initial","final","state","composite"];function stateOf(e){return e&&e.state||{}}function linkOf(e,t){const r=e.links;return r&&r[t]||{}}function absolutePosition(e){let t=0,r=0,i=e;for(;i&&i.state&&"number"==typeof i.state.left;)t+=i.state.left||0,r+=i.state.top||0,i=i.parentNode;return{left:Math.round(t),top:Math.round(r)}}function parentIdOf(e){const t=e&&e.parentNode,r=t&&t.state?t.state.id:void 0;return"string"==typeof r&&r.length>0?r:void 0}function numberOf(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function textOf(e){return"string"==typeof e&&e.length>0?e:void 0}function clean(e){const t={};return Object.keys(e).forEach(r=>{void 0!==e[r]&&(t[r]=e[r])}),t}function nodesOf(e){return e&&Array.isArray(e.nodes)?e.nodes:[]}function edgesOf(e){return e&&Array.isArray(e.edges)?e.edges:[]}function baseOf(e){const t=stateOf(e),r=absolutePosition(e);return{id:t.id,title:textOf(t.title),left:r.left,top:r.top}}function toDsl(e,r={}){const i=e&&e.designer?e.designer:e,o=r.kind||e&&e.kind||function detectKind(e){if(!e)return;if(Array.isArray(e.entities))return"entity";if(void 0!==e.originDate||void 0!==e.dayWidth)return"gantt";const r=nodesOf(e)[0],i=r?String(stateOf(r).kind||""):"";return i.startsWith("bpmn")?"bpmn":x.indexOf(i)>=0?"uml":k.indexOf(i)>=0?"statechart":t.indexOf(i)>=0?"power":O.indexOf(i)>=0?"flowchart":void 0}(i);if(!o)throw new Error("toDsl(): 无法推断文档类型(实例里没有可识别的图元)。请显式传入 kind:'flowchart' | 'bpmn' | 'uml' | 'statechart' | 'gantt' | 'power' | 'entity'。");switch(o){case"flowchart":return function exportFlow(e){return{schemaVersion:1,kind:"flowchart",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:t.kind,width:numberOf(t.width),height:numberOf(t.height),fillColor:textOf(t.fillColor),strokeColor:textOf(t.strokeColor)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),r=linkOf(t,"start"),i=linkOf(t,"end");return clean({id:t.id,source:r.id,target:i.id,sourcePort:r.position,targetPort:i.position,label:textOf(t.label)||"",linkShape:textOf(t.linkShape)})})}}(i);case"bpmn":return function exportBpmn(e){return{schemaVersion:1,kind:"bpmn",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:D[t.kind]||"task",parent:parentIdOf(e),width:numberOf(t.width),height:numberOf(t.height),eventKind:textOf(t.eventKind),trigger:textOf(t.trigger),gatewayType:textOf(t.gatewayType),taskType:textOf(t.taskType),fillColor:textOf(t.fillColor),strokeColor:textOf(t.strokeColor)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),r=linkOf(t,"start"),i=linkOf(t,"end");return clean({id:t.id,source:r.id,target:i.id,type:textOf(t.flowType)||"sequence",label:textOf(t.label),condition:textOf(t.condition),isDefault:!0===t.isDefault||void 0,linkShape:textOf(t.linkShape)})})}}(i);case"uml":return function exportUml(e){return{schemaVersion:1,kind:"uml",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:textOf(t.kind)||"class",title:textOf(t.className)||textOf(t.title),abstract:!0===t.abstract||void 0,attributes:Array.isArray(t.attributes)?t.attributes.map(e=>String(e)):[],methods:Array.isArray(t.methods)?t.methods.map(e=>String(e)):[],width:numberOf(t.width),height:numberOf(t.height)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),r=linkOf(t,"start"),i=linkOf(t,"end");return clean({id:t.id,source:r.id,target:i.id,type:textOf(t.relationKind)||"association",label:textOf(t.label)})})}}(i);case"statechart":return function exportStatechart(e){return{schemaVersion:1,kind:"statechart",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:textOf(t.kind)||"state",parent:parentIdOf(e),width:numberOf(t.width),height:numberOf(t.height)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),r=linkOf(t,"start"),i=linkOf(t,"end");return clean({id:t.id,source:r.id,target:i.id,event:textOf(t.event),guard:textOf(t.guard),action:textOf(t.action),label:textOf(t.label)})})}}(i);case"gantt":return function exportGantt(e){return{schemaVersion:1,kind:"gantt",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({id:t.id,title:textOf(t.title),start:textOf(t.start),days:numberOf(t.days),progress:numberOf(t.progress),row:numberOf(t.row),resource:textOf(t.resource)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),r=linkOf(t,"start"),i=linkOf(t,"end");return clean({id:t.id,source:r.id,target:i.id})})}}(i);case"power":return function exportPower(e){return{schemaVersion:1,kind:"power",nodes:nodesOf(e).map(e=>{const t=stateOf(e),r=absolutePosition(e);return clean({id:t.id,kind:t.kind,title:textOf(t.title)||textOf(t.name),voltageLevel:textOf(t.voltageLevel),left:r.left,top:r.top,width:numberOf(t.width),height:numberOf(t.height),switchState:textOf(t.switchState),source:!0===t.source||!0===t.energizedSource||void 0,attachedTo:textOf(t.attachedBusId)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),r=linkOf(t,"start"),i=linkOf(t,"end");return clean({id:t.id,source:r.id,target:i.id,sourcePort:r.position,targetPort:i.position,voltageLevel:textOf(t.voltageLevel)})})}}(i);case"entity":case"er":default:return function exportEr(e){const t=e&&Array.isArray(e.entities)?e.entities:[],r=e&&Array.isArray(e.relations)?e.relations:[];return{schemaVersion:1,entities:t.map(e=>{const t=stateOf(e),r=absolutePosition(e);return clean({id:t.id,name:textOf(t.entityName),fields:Array.isArray(t.fields)?t.fields:[],left:r.left,top:r.top})}),relations:r.map(e=>{const t=stateOf(e),r=linkOf(t,"start"),i=linkOf(t,"end");return clean({id:t.id,source:r.id,target:i.id,type:t.relationType,sourceField:textOf(t.sourceField),targetField:textOf(t.targetField),label:textOf(t.label),onDelete:textOf(t.onDelete),onUpdate:textOf(t.onUpdate),joinTableName:textOf(t.joinTableName),nullable:"boolean"==typeof t.nullable?t.nullable:void 0,sourceCardinality:textOf(t.sourceCardinality),targetCardinality:textOf(t.targetCardinality),linkShape:textOf(t.linkShape)})})}}(i)}}function withDsl(e){return Object.assign(e,{toDsl:()=>toDsl(e)})}function renderGanttDsl(t,r){const i=compileGanttDsl(r),o=i.options||{},n=(new e.ICE).init(t),s=new e.GanttDesigner(n);return o.dayWidth&&s.setDayWidth(o.dayWidth),i.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),i.edges.forEach(e=>{s.createDependency(e)}),s.select(null),o.autoSchedule&&s.autoSchedule(),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"gantt",ice:n,designer:s})}function renderPowerDsl(t,r){const i=compilePowerDsl(r),o=i.options||{},n=(new e.ICE).init(t),s=new e.PowerDesigner(n);o.voltageColors&&s.setVoltageColors(o.voltageColors);const a=new Map;return i.nodes.forEach(e=>{const t=s.createSymbol(e.kind,{id:e.id,title:e.title,name:e.title,voltageLevel:e.voltageLevel,left:e.left,top:e.top,width:e.width,height:e.height,switchState:e.switchState});e.source&&t.setState({energizedSource:!0}),a.set(e.id,t)}),i.attachments.forEach(e=>{const t=a.get(e.deviceId),r=a.get(e.busId);t&&r&&s.attachToBus(t,r)}),i.edges.forEach(e=>{const t=a.get(e.sourceId),r=a.get(e.targetId);t&&r&&s.createLine({sourceId:t.state.id,targetId:r.state.id,sourcePort:e.sourcePort,targetPort:e.targetPort,voltageLevel:e.voltageLevel})}),s.select(null),s.applyTopology(),!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"power",ice:n,designer:s})}function renderStatechartDsl(t,r){const i=compileStatechartDsl(r),o=i.options||{},n=(new e.ICE).init(t),s=new e.StatechartDesigner(n);return i.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),i.edges.forEach(e=>{s.createTransition(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"statechart",ice:n,designer:s})}function renderUmlDsl(t,r){const i=compileUmlDsl(r),o=i.options||{},n=(new e.ICE).init(t),s=new e.UmlDesigner(n);return i.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),i.edges.forEach(e=>{s.createRelation(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"uml",ice:n,designer:s})}function renderBpmnDsl(t,r){const i=compileBpmnDsl(r),o=i.options||{},n=(new e.ICE).init(t),s=new e.BpmnDesigner(n);return i.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(r=>{void 0!==e[r]&&(t[r]=e[r])}),s.createNode(e.kind,t)}),i.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"bpmn",ice:n,designer:s})}function renderFlowDsl(t,r){const i=compileFlowDsl(r),o=i.options||{},n=(new e.ICE).init(t),s=new e.FlowDesigner(n);return i.nodes.forEach(e=>{s.createNode(e.kind,e)}),i.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"flowchart",ice:n,designer:s})}exports.DSL_SCHEMA_VERSION=1,exports.POWER_DSL_KINDS=t,exports.compileBpmnDsl=compileBpmnDsl,exports.compileDsl=compileDsl,exports.compileFlowDsl=compileFlowDsl,exports.compileGanttDsl=compileGanttDsl,exports.compilePowerDsl=compilePowerDsl,exports.compileStatechartDsl=compileStatechartDsl,exports.compileUmlDsl=compileUmlDsl,exports.isBpmnDsl=isBpmnDsl,exports.isFlowDsl=isFlowDsl,exports.isGanttDsl=isGanttDsl,exports.isPowerDsl=isPowerDsl,exports.isStatechartDsl=isStatechartDsl,exports.isUmlDsl=isUmlDsl,exports.layeredLayout=layeredLayout,exports.renderBpmnDsl=renderBpmnDsl,exports.renderDsl=function renderDsl(t,r){const i=validateDsl(r);if(!i.valid)throw new Error(i.errors.join("\n"));return isGanttDsl(r)?renderGanttDsl(t,r):isPowerDsl(r)?renderPowerDsl(t,r):isStatechartDsl(r)?renderStatechartDsl(t,r):isUmlDsl(r)?renderUmlDsl(t,r):isBpmnDsl(r)?renderBpmnDsl(t,r):isFlowDsl(r)?renderFlowDsl(t,r):function renderErDsl(t,r){const i=compileDsl(r),o=i.options||{},n=(new e.ICE).init(t),s=new e.EntityDesigner(n);i.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,r){const i=new Map;return e.entities.forEach(e=>{i.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=i.get(e.sourceId),o=i.get(e.targetId);let n="R",s="L";if(t&&o){const e=o.center[0]-t.center[0],r=o.center[1]-t.center[1];Math.abs(e)>Math.abs(r)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=r>=0?"B":"T",s=r>=0?"T":"B")}return{...e,routeType:e.routeType||r||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,i,o.routeType).forEach(e=>{s.createRelation(e)}),("layered"===i.layout||"horizontal"===i.layout)&&new e.ICELayeredLayout({gapX:o.gapX||120,gapY:o.gapY||50}).layoutContainer(n);o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):o.fitViewport&&function fitViewport(e,t,r){const i=t.entities||[];let o=1/0,n=1/0,s=-1/0,a=-1/0;i.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();o=Math.min(o,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-o,l=a-n,p=e.canvasWidth||0,c=e.canvasHeight||0;if(!p||!c||d<=0||l<=0)return;const u=Number.isFinite(r)&&r>=0?r:40,h=Math.max(1,p-2*u),f=Math.max(1,c-2*u),m=Math.min(h/d,f/l,1),g=(p-d*m)/2-o*m,b=(c-l*m)/2-n*m;e.setViewport(m,g,b)}(n,s,o.fitViewportPadding);return withDsl({kind:"entity",ice:n,designer:s})}(t,r)},exports.renderFlowDsl=renderFlowDsl,exports.renderGanttDsl=renderGanttDsl,exports.renderPowerDsl=renderPowerDsl,exports.renderStatechartDsl=renderStatechartDsl,exports.renderUmlDsl=renderUmlDsl,exports.toDsl=toDsl,exports.validateBpmnDsl=validateBpmnDsl,exports.validateDsl=validateDsl,exports.validateFlowDsl=validateFlowDsl,exports.validateGanttDsl=validateGanttDsl,exports.validatePowerDsl=validatePowerDsl,exports.validateStatechartDsl=validateStatechartDsl,exports.validateUmlDsl=validateUmlDsl;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FLOW_NODE_KINDS as e,ICE as t,GanttDesigner as i,StatechartDesigner as o,UmlDesigner as r,BpmnDesigner as n,FlowDesigner as s,EntityDesigner as a,ICELayeredLayout as d}from"ice-entity-designer";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const p=1,l=["terminator","process","decision","io"],h=["T","R","B","L","C"],c=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],u=["start","intermediate","end"],f=["none","message","timer","error","terminate"],m=["exclusive","parallel","inclusive","event"],g=["none","user","service","script","send","receive","manual"],y=["sequence","message","association"],b=["initial","final","state","composite"],w=["class","interface","enum"],v=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,o)=>{const r=`entities[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${r}.fields[${i}].name must be a non-empty string`)}):t.push(r+".fields must be an array")):t.push(r+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const o=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(o+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(o+".target must be a non-empty string")):t.push(o+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,r)=>{const n=`nodes[${r}]`;if(!e||"object"!=typeof e)return void t.push(n+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"task")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===c.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${c.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)});[["eventKind",u],["trigger",f],["gatewayType",m],["taskType",g]].forEach(([i,o])=>{const r=e[i];void 0!==r&&-1===o.indexOf(r)&&t.push(`${n}.${i} must be one of ${o.join("/")}`)})}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=o.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===y.indexOf(n)&&t.push(`${r}.type must be one of ${y.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(r+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(r+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===l.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${l.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${r}.${i} must be a number when present`)})):t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present"),void 0!==e.sourcePort&&-1===h.indexOf(e.sourcePort)&&t.push(`${r}.sourcePort must be one of ${h.join("/")}`),void 0!==e.targetPort&&-1===h.indexOf(e.targetPort)&&t.push(`${r}.targetPort must be one of ${h.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(r+'.linkShape must be "visio" or "bezier" when present')):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===w.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${w.join("/")}`),["attributes","methods"].forEach(i=>{const o=e[i];void 0!==o&&(Array.isArray(o)&&!o.some(e=>"string"!=typeof e)||t.push(`${r}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${r}.${i} must be a number when present`)})):t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===v.indexOf(n)&&t.push(`${r}.type must be one of ${v.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,r)=>{const n=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===b.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${b.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==o.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const o=e[i];void 0!==o&&"string"!=typeof o&&t.push(`${r}.${i} must be a string when present`)})):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(r+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(r+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(r+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(r+".row must be a number >= 0 when present")}else t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing task id")):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const o=Number(i.gapX)||90,r=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const p=new Map,l=new Map;e.forEach(e=>{p.set(e.id,0),l.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(p.set(e.targetId,(p.get(e.targetId)||0)+1),l.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(p.get(e.id)||0)&&(h.set(e.id,0),c.push(e.id))}),c.length||(h.set(e[0].id,0),c.push(e[0].id));let u=e.length*e.length+e.length;for(;c.length&&u-- >0;){const e=c.shift(),t=h.get(e)||0;(l.get(e)||[]).forEach(e=>{const i=t+1;(void 0===h.get(e)?-1:h.get(e))<i&&(h.set(e,i),c.push(e))})}e.forEach(e=>{h.has(e.id)||h.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=h.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+r}),t+=e[n]+o})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+o}),t+=e[n]+r})}const g=Math.min(...e.map(e=>a.get(e.id).left)),y=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-y}),a}const N={terminator:{width:e.terminator.width,height:e.terminator.height,fill:e.terminator.fill,stroke:e.terminator.stroke},process:{width:e.process.width,height:e.process.height,fill:e.process.fill,stroke:e.process.stroke},decision:{width:e.decision.width,height:e.decision.height,fill:e.decision.fill,stroke:e.decision.stroke},io:{width:e.io.width,height:e.io.height,fill:e.io.fill,stroke:e.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&N[e.kind]?e.kind:"process"}(e),i=N[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(o=e,o.title||o.name||o.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var o}),o=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),r=t.layout||"layered";return"none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,o){const r=layeredLayout(e,t,{gapX:i,gapY:o});e.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,o,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:o,layout:r,options:t}}const k={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},D=Number(e.bpmnPool.bandSize)||32,x=Number(e.bpmnLane.bandSize)||32,E=Number(e.bpmnLane.height)||130,M=Number(e.bpmnPool.width)||900;function toWorkingNode(t){const i=t.kind||"task",o=function presetOf(t){return e[t]||e.bpmnTask}(k[i]||"bpmnTask"),r={id:t.id,typeId:"FlowNode",kind:k[i]||"bpmnTask",title:t.title||t.name||t.id,left:"number"==typeof t.left?t.left:0,top:"number"==typeof t.top?t.top:0,width:"number"==typeof t.width?t.width:o.width,height:"number"==typeof t.height?t.height:o.height,fillColor:t.fillColor,strokeColor:t.strokeColor,dslKind:i,parent:t.parent,explicitLeft:"number"==typeof t.left,explicitTop:"number"==typeof t.top,explicitWidth:"number"==typeof t.width,explicitHeight:"number"==typeof t.height};return"event"===i&&(r.eventKind=t.eventKind||o.eventKind||"start",r.trigger=t.trigger||o.trigger||"none"),"gateway"===i&&(r.gatewayType=t.gatewayType||o.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(r.taskType=t.taskType||o.taskType||"none"),r}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const o=1===t.length?t[0]:null,r=[];return e.forEach(e=>{(e=>{let t=r.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},r.push(t)),t})((e.parent?i.get(e.parent):void 0)||o).nodes.push(e)}),r}function layoutGroups(e,t,i,o){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const r=layeredLayout(e.nodes,t,{gapX:i,gapY:o,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,o=-1/0,r=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),o=Math.max(o,e.left+e.width),r=Math.max(r,e.top+e.height)}),{minX:t,minY:i,maxX:o,maxY:r}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),o=i.filter(e=>"pool"===e.dslKind),r=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let o=e.parent;o||1!==t.length||(o=t[0].id),o&&i.set(e.id,o)}),i}(r,o),lanesOf=e=>r.filter(t=>d.get(t.id)===e);let p=[];"none"!==a&&(p=buildGroups(n,o.concat(r)),layoutGroups(p,s,Number(t.gapX)||90,Number(t.gapY)||60)),r.forEach(e=>{const t=p.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),E))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+x+56,M)))}),o.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),M);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=D+t.reduce((e,t)=>e+t.height,0)))}const i=p.filter(t=>t.owner===e)[0],o=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(o?o.maxX-o.minX:0),M))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+D+56,160)))});let l=60;o.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=l),l=Math.max(l,e.top+e.height+60)}),o.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+D,o=Math.max(e.height-D,1),r=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(o-r,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||E)),a=t.top+t.height})});let h=60;r.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),p.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let o=80,r=80;i&&(o=i.left+28,r=i.top+28,"pool"===i.dslKind?r+=D:o+=x),e.nodes.forEach(e=>{e.left=Math.round(o+(e.left-t.minX)),e.top=Math.round(r+(e.top-t.minY))})});return{kind:"bpmn",nodes:o.concat(r).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),o=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),r=t.layout||"layered";if("none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,o.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:o,layout:r,options:t}}const $={width:160,height:64},j={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,o="composite"===t?j:i?{width:24,height:24}:$;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height}}),o=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),r=t.layout||"auto",n=new Set;if("none"!==r){const e=new Map;i.forEach(t=>e.set(t.id,t));const r=i.filter(t=>!(t.parent&&e.has(t.parent)));if(r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=o.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(r,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});r.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...r.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let o=56,a=56,d=0,p=56;const l=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(o>56&&o+e.width>56+l&&(o=56,a=p+40),n.add(e.id),e.left=o,e.top=a,o+=e.width+40,d=Math.max(d,o),p=Math.max(p,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,p+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,o)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=o,offsetChildren(e,t,o))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:o,layout:r,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),r=o.options||{},n=(new t).init(e),s=new a(n);o.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const o=new Map;return e.entities.forEach(e=>{o.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=o.get(e.sourceId),r=o.get(e.targetId);let n="R",s="L";if(t&&r){const e=r.center[0]-t.center[0],i=r.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,o,r.routeType).forEach(e=>{s.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new d({gapX:r.gapX||120,gapY:r.gapY||50}).layoutContainer(n);r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):r.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let r=1/0,n=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();r=Math.min(r,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-r,p=a-n,l=e.canvasWidth||0,h=e.canvasHeight||0;if(!l||!h||d<=0||p<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,l-2*c),f=Math.max(1,h-2*c),m=Math.min(u/d,f/p,1),g=(l-d*m)/2-r*m,y=(h-p*m)/2-n*m;e.setViewport(m,g,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(e,i)}function renderGanttDsl(e,o){const r=compileGanttDsl(o),n=r.options||{},s=(new t).init(e),a=new i(s);return n.dayWidth&&a.setDayWidth(n.dayWidth),r.nodes.forEach(e=>{a.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),r.edges.forEach(e=>{a.createDependency(e)}),a.select(null),n.autoSchedule&&a.autoSchedule(),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"gantt",ice:s,designer:a}}function renderStatechartDsl(e,i){const r=compileStatechartDsl(i),n=r.options||{},s=(new t).init(e),a=new o(s);return r.nodes.forEach(e=>{a.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{a.createTransition(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"statechart",ice:s,designer:a}}function renderUmlDsl(e,i){const o=compileUmlDsl(i),n=o.options||{},s=(new t).init(e),a=new r(s);return o.nodes.forEach(e=>{a.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),o.edges.forEach(e=>{a.createRelation(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"uml",ice:s,designer:a}}function renderBpmnDsl(e,i){const o=compileBpmnDsl(i),r=o.options||{},s=(new t).init(e),a=new n(s);return o.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),a.createNode(e.kind,t)}),o.edges.forEach(e=>{a.createEdge(e)}),a.select(null),r.viewport?s.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&a.fitViewport(r.fitViewportPadding),a.resetHistory(),{kind:"bpmn",ice:s,designer:a}}function renderFlowDsl(e,i){const o=compileFlowDsl(i),r=o.options||{},n=(new t).init(e),a=new s(n);return o.nodes.forEach(e=>{a.createNode(e.kind,e)}),o.edges.forEach(e=>{a.createEdge(e)}),a.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&a.fitViewport(r.fitViewportPadding),a.resetHistory(),{kind:"flowchart",ice:n,designer:a}}export{p as DSL_SCHEMA_VERSION,compileBpmnDsl,compileDsl,compileFlowDsl,compileGanttDsl,compileStatechartDsl,compileUmlDsl,isBpmnDsl,isFlowDsl,isGanttDsl,isStatechartDsl,isUmlDsl,layeredLayout,renderBpmnDsl,renderDsl,renderFlowDsl,renderGanttDsl,renderStatechartDsl,renderUmlDsl,validateBpmnDsl,validateDsl,validateFlowDsl,validateGanttDsl,validateStatechartDsl,validateUmlDsl};
|
|
1
|
+
import{FLOW_NODE_KINDS as e,ICE as t,GanttDesigner as i,PowerDesigner as r,StatechartDesigner as o,UmlDesigner as n,BpmnDesigner as s,FlowDesigner as a,EntityDesigner as d,ICELayeredLayout as l}from"ice-entity-designer";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const p=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"];function isPowerDsl(e){return!!e&&"object"==typeof e&&"power"===e.kind}const c=1,u=["terminator","process","decision","io"],h=["T","R","B","L","C"],f=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],m=["start","intermediate","end"],g=["none","message","timer","error","terminate"],b=["exclusive","parallel","inclusive","event"],y=["none","user","service","script","send","receive","manual"],w=["sequence","message","association"],v=["initial","final","state","composite"],k=["class","interface","enum"],x=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isPowerDsl(e)?validatePowerDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,r)=>{const o=`entities[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${o}.fields[${i}].name must be a non-empty string`)}):t.push(o+".fields must be an array")):t.push(o+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const r=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(r+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(r+".target must be a non-empty string")):t.push(r+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,r=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;if(!e||"object"!=typeof e)return void t.push(n+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),r.set(e.id,e.kind||"task")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===f.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${f.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${i} must be a number when present`)});[["eventKind",m],["trigger",g],["gatewayType",b],["taskType",y]].forEach(([i,r])=>{const o=e[i];void 0!==o&&-1===r.indexOf(o)&&t.push(`${n}.${i} must be one of ${r.join("/")}`)})}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=r.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===w.indexOf(n)&&t.push(`${o}.type must be one of ${w.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(o+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(o+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),void 0!==e.kind&&-1===u.indexOf(e.kind)&&t.push(`${o}.kind must be one of ${u.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${o}.${i} must be a number when present`)})):t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present"),void 0!==e.sourcePort&&-1===h.indexOf(e.sourcePort)&&t.push(`${o}.sourcePort must be one of ${h.join("/")}`),void 0!==e.targetPort&&-1===h.indexOf(e.targetPort)&&t.push(`${o}.targetPort must be one of ${h.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(o+'.linkShape must be "visio" or "bezier" when present')):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),void 0!==e.kind&&-1===k.indexOf(e.kind)&&t.push(`${o}.kind must be one of ${k.join("/")}`),["attributes","methods"].forEach(i=>{const r=e[i];void 0!==r&&(Array.isArray(r)&&!r.some(e=>"string"!=typeof e)||t.push(`${o}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${o}.${i} must be a number when present`)})):t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===x.indexOf(n)&&t.push(`${o}.type must be one of ${x.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,r=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),r.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===v.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${v.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==r.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const r=e[i];void 0!==r&&"string"!=typeof r&&t.push(`${o}.${i} must be a string when present`)})):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(o+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(o+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(o+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(o+".row must be a number >= 0 when present")}else t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing task id")):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validatePowerDsl(e){const t=[],i=Array.isArray(e.nodes)?e.nodes:[];Array.isArray(e.nodes)||t.push("nodes must be an array");const r=new Set;return i.forEach((e,i)=>{const o=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id?r.has(e.id)?t.push("duplicated node id: "+e.id):r.add(e.id):t.push(o+".id must be a non-empty string"),-1===p.indexOf(e.kind)&&t.push(`${o}.kind must be one of ${p.join(" / ")}`),void 0===e.voltageLevel||/^\d+(\.\d+)?kV$/.test(String(e.voltageLevel))||t.push(o+'.voltageLevel must look like "110kV"')):t.push(o+" must be an object")}),i.forEach((e,r)=>{if(!e||void 0===e.attachedTo)return;const o=i.find(t=>t&&t.id===e.attachedTo);o?"busbar"!==o.kind&&t.push(`nodes[${r}].attachedTo must point at a busbar: ${e.attachedTo} is ${o.kind}`):t.push(`nodes[${r}].attachedTo references an unknown node: ${e.attachedTo}`)}),(e.edges||[]).forEach((e,i)=>{const o=`edges[${i}]`;e&&"object"==typeof e?(r.has(e.source)||t.push(`${o}.source references an unknown node: ${e.source}`),r.has(e.target)||t.push(`${o}.target references an unknown node: ${e.target}`),e.source===e.target&&t.push(o+" must not connect a node to itself")):t.push(o+" must be an object")}),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const r=Number(i.gapX)||90,o=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const l=new Map,p=new Map;e.forEach(e=>{l.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(l.set(e.targetId,(l.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const c=new Map,u=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(c.set(e.id,0),u.push(e.id))}),u.length||(c.set(e[0].id,0),u.push(e[0].id));let h=e.length*e.length+e.length;for(;u.length&&h-- >0;){const e=u.shift(),t=c.get(e)||0;(p.get(e)||[]).forEach(e=>{const i=t+1;(void 0===c.get(e)?-1:c.get(e))<i&&(c.set(e,i),u.push(e))})}e.forEach(e=>{c.has(e.id)||c.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=c.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+o}),t+=e[n]+r})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+r}),t+=e[n]+o})}const g=Math.min(...e.map(e=>a.get(e.id).left)),b=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-b}),a}const O={terminator:{width:e.terminator.width,height:e.terminator.height,fill:e.terminator.fill,stroke:e.terminator.stroke},process:{width:e.process.width,height:e.process.height,fill:e.process.fill,stroke:e.process.stroke},decision:{width:e.decision.width,height:e.decision.height,fill:e.decision.fill,stroke:e.decision.stroke},io:{width:e.io.width,height:e.io.height,fill:e.io.fill,stroke:e.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&O[e.kind]?e.kind:"process"}(e),i=O[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(r=e,r.title||r.name||r.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var r}),r=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),o=t.layout||"layered";return"none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,r){const o=layeredLayout(e,t,{gapX:i,gapY:r});e.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,r,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:r,layout:o,options:t}}const D={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},N=Number(e.bpmnPool.bandSize)||32,E=Number(e.bpmnLane.bandSize)||32,S=Number(e.bpmnLane.height)||130,$=Number(e.bpmnPool.width)||900;function toWorkingNode(t){const i=t.kind||"task",r=function presetOf(t){return e[t]||e.bpmnTask}(D[i]||"bpmnTask"),o={id:t.id,typeId:"FlowNode",kind:D[i]||"bpmnTask",title:t.title||t.name||t.id,left:"number"==typeof t.left?t.left:0,top:"number"==typeof t.top?t.top:0,width:"number"==typeof t.width?t.width:r.width,height:"number"==typeof t.height?t.height:r.height,fillColor:t.fillColor,strokeColor:t.strokeColor,dslKind:i,parent:t.parent,explicitLeft:"number"==typeof t.left,explicitTop:"number"==typeof t.top,explicitWidth:"number"==typeof t.width,explicitHeight:"number"==typeof t.height};return"event"===i&&(o.eventKind=t.eventKind||r.eventKind||"start",o.trigger=t.trigger||r.trigger||"none"),"gateway"===i&&(o.gatewayType=t.gatewayType||r.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(o.taskType=t.taskType||r.taskType||"none"),o}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const r=1===t.length?t[0]:null,o=[];return e.forEach(e=>{(e=>{let t=o.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},o.push(t)),t})((e.parent?i.get(e.parent):void 0)||r).nodes.push(e)}),o}function layoutGroups(e,t,i,r){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const o=layeredLayout(e.nodes,t,{gapX:i,gapY:r,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,r=-1/0,o=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),r=Math.max(r,e.left+e.width),o=Math.max(o,e.top+e.height)}),{minX:t,minY:i,maxX:r,maxY:o}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),r=i.filter(e=>"pool"===e.dslKind),o=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let r=e.parent;r||1!==t.length||(r=t[0].id),r&&i.set(e.id,r)}),i}(o,r),lanesOf=e=>o.filter(t=>d.get(t.id)===e);let l=[];"none"!==a&&(l=buildGroups(n,r.concat(o)),layoutGroups(l,s,Number(t.gapX)||90,Number(t.gapY)||60)),o.forEach(e=>{const t=l.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),S))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+E+56,$)))}),r.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),$);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=N+t.reduce((e,t)=>e+t.height,0)))}const i=l.filter(t=>t.owner===e)[0],r=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(r?r.maxX-r.minX:0),$))),e.explicitHeight||(e.height=Math.round(Math.max((r?r.maxY-r.minY:0)+N+56,160)))});let p=60;r.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=p),p=Math.max(p,e.top+e.height+60)}),r.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+N,r=Math.max(e.height-N,1),o=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(r-o,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||S)),a=t.top+t.height})});let c=60;o.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=c,c=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let r=80,o=80;i&&(r=i.left+28,o=i.top+28,"pool"===i.dslKind?o+=N:r+=E),e.nodes.forEach(e=>{e.left=Math.round(r+(e.left-t.minX)),e.top=Math.round(o+(e.top-t.minY))})});return{kind:"bpmn",nodes:r.concat(o).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),r=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),o=t.layout||"layered";if("none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,r.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:r,layout:o,options:t}}const T={width:160,height:64},j={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,r="composite"===t?j:i?{width:24,height:24}:T;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:r.width,height:"number"==typeof e.height?e.height:r.height}}),r=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),o=t.layout||"auto",n=new Set;if("none"!==o){const e=new Map;i.forEach(t=>e.set(t.id,t));const o=i.filter(t=>!(t.parent&&e.has(t.parent)));if(o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=r.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(o,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});o.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...o.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let r=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(r>56&&r+e.width>56+p&&(r=56,a=l+40),n.add(e.id),e.left=r,e.top=a,r+=e.width+40,d=Math.max(d,r),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,r)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=r,offsetChildren(e,t,r))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:r,layout:o,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function compilePowerDsl(e){const t=e.options||{},i=(e.nodes||[]).map((e,t)=>{const i=function defaultPlacement(e){return{left:120+e%6*200,top:120+160*Math.floor(e/6)}}(t);return{id:e.id,kind:e.kind,title:e.title||e.name||e.id,voltageLevel:String(e.voltageLevel||""),left:"number"==typeof e.left?e.left:i.left,top:"number"==typeof e.top?e.top:i.top,width:e.width,height:e.height,switchState:e.switchState,source:!!e.source}}),r=new Map;i.forEach(e=>r.set(e.id,e));return{kind:"power",nodes:i,edges:(e.edges||[]).map((e,t)=>({id:e.id||"conductor-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",voltageLevel:e.voltageLevel||(r.get(e.source)||{}).voltageLevel||""})),attachments:(e.nodes||[]).filter(e=>!!e.attachedTo).map(e=>({deviceId:e.id,busId:String(e.attachedTo)})),options:t}}const A={bpmnPool:"pool",bpmnLane:"lane",bpmnTask:"task",bpmnEvent:"event",bpmnGateway:"gateway",bpmnSubprocess:"subprocess",bpmnDataObject:"dataObject",bpmnAnnotation:"annotation"},M=["terminator","process","decision","io"],V=["class","interface","enum"],P=["initial","final","state","composite"];function stateOf(e){return e&&e.state||{}}function linkOf(e,t){const i=e.links;return i&&i[t]||{}}function absolutePosition(e){let t=0,i=0,r=e;for(;r&&r.state&&"number"==typeof r.state.left;)t+=r.state.left||0,i+=r.state.top||0,r=r.parentNode;return{left:Math.round(t),top:Math.round(i)}}function parentIdOf(e){const t=e&&e.parentNode,i=t&&t.state?t.state.id:void 0;return"string"==typeof i&&i.length>0?i:void 0}function numberOf(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function textOf(e){return"string"==typeof e&&e.length>0?e:void 0}function clean(e){const t={};return Object.keys(e).forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),t}function nodesOf(e){return e&&Array.isArray(e.nodes)?e.nodes:[]}function edgesOf(e){return e&&Array.isArray(e.edges)?e.edges:[]}function baseOf(e){const t=stateOf(e),i=absolutePosition(e);return{id:t.id,title:textOf(t.title),left:i.left,top:i.top}}function toDsl(e,t={}){const i=e&&e.designer?e.designer:e,r=t.kind||e&&e.kind||function detectKind(e){if(!e)return;if(Array.isArray(e.entities))return"entity";if(void 0!==e.originDate||void 0!==e.dayWidth)return"gantt";const t=nodesOf(e)[0],i=t?String(stateOf(t).kind||""):"";return i.startsWith("bpmn")?"bpmn":V.indexOf(i)>=0?"uml":P.indexOf(i)>=0?"statechart":p.indexOf(i)>=0?"power":M.indexOf(i)>=0?"flowchart":void 0}(i);if(!r)throw new Error("toDsl(): 无法推断文档类型(实例里没有可识别的图元)。请显式传入 kind:'flowchart' | 'bpmn' | 'uml' | 'statechart' | 'gantt' | 'power' | 'entity'。");switch(r){case"flowchart":return function exportFlow(e){return{schemaVersion:1,kind:"flowchart",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:t.kind,width:numberOf(t.width),height:numberOf(t.height),fillColor:textOf(t.fillColor),strokeColor:textOf(t.strokeColor)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,sourcePort:i.position,targetPort:r.position,label:textOf(t.label)||"",linkShape:textOf(t.linkShape)})})}}(i);case"bpmn":return function exportBpmn(e){return{schemaVersion:1,kind:"bpmn",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:A[t.kind]||"task",parent:parentIdOf(e),width:numberOf(t.width),height:numberOf(t.height),eventKind:textOf(t.eventKind),trigger:textOf(t.trigger),gatewayType:textOf(t.gatewayType),taskType:textOf(t.taskType),fillColor:textOf(t.fillColor),strokeColor:textOf(t.strokeColor)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,type:textOf(t.flowType)||"sequence",label:textOf(t.label),condition:textOf(t.condition),isDefault:!0===t.isDefault||void 0,linkShape:textOf(t.linkShape)})})}}(i);case"uml":return function exportUml(e){return{schemaVersion:1,kind:"uml",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:textOf(t.kind)||"class",title:textOf(t.className)||textOf(t.title),abstract:!0===t.abstract||void 0,attributes:Array.isArray(t.attributes)?t.attributes.map(e=>String(e)):[],methods:Array.isArray(t.methods)?t.methods.map(e=>String(e)):[],width:numberOf(t.width),height:numberOf(t.height)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,type:textOf(t.relationKind)||"association",label:textOf(t.label)})})}}(i);case"statechart":return function exportStatechart(e){return{schemaVersion:1,kind:"statechart",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:textOf(t.kind)||"state",parent:parentIdOf(e),width:numberOf(t.width),height:numberOf(t.height)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,event:textOf(t.event),guard:textOf(t.guard),action:textOf(t.action),label:textOf(t.label)})})}}(i);case"gantt":return function exportGantt(e){return{schemaVersion:1,kind:"gantt",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({id:t.id,title:textOf(t.title),start:textOf(t.start),days:numberOf(t.days),progress:numberOf(t.progress),row:numberOf(t.row),resource:textOf(t.resource)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id})})}}(i);case"power":return function exportPower(e){return{schemaVersion:1,kind:"power",nodes:nodesOf(e).map(e=>{const t=stateOf(e),i=absolutePosition(e);return clean({id:t.id,kind:t.kind,title:textOf(t.title)||textOf(t.name),voltageLevel:textOf(t.voltageLevel),left:i.left,top:i.top,width:numberOf(t.width),height:numberOf(t.height),switchState:textOf(t.switchState),source:!0===t.source||!0===t.energizedSource||void 0,attachedTo:textOf(t.attachedBusId)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,sourcePort:i.position,targetPort:r.position,voltageLevel:textOf(t.voltageLevel)})})}}(i);case"entity":case"er":default:return function exportEr(e){const t=e&&Array.isArray(e.entities)?e.entities:[],i=e&&Array.isArray(e.relations)?e.relations:[];return{schemaVersion:1,entities:t.map(e=>{const t=stateOf(e),i=absolutePosition(e);return clean({id:t.id,name:textOf(t.entityName),fields:Array.isArray(t.fields)?t.fields:[],left:i.left,top:i.top})}),relations:i.map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,type:t.relationType,sourceField:textOf(t.sourceField),targetField:textOf(t.targetField),label:textOf(t.label),onDelete:textOf(t.onDelete),onUpdate:textOf(t.onUpdate),joinTableName:textOf(t.joinTableName),nullable:"boolean"==typeof t.nullable?t.nullable:void 0,sourceCardinality:textOf(t.sourceCardinality),targetCardinality:textOf(t.targetCardinality),linkShape:textOf(t.linkShape)})})}}(i)}}function withDsl(e){return Object.assign(e,{toDsl:()=>toDsl(e)})}function renderDsl(e,i){const r=validateDsl(i);if(!r.valid)throw new Error(r.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isPowerDsl(i)?renderPowerDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const r=compileDsl(i),o=r.options||{},n=(new t).init(e),s=new d(n);r.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const r=new Map;return e.entities.forEach(e=>{r.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=r.get(e.sourceId),o=r.get(e.targetId);let n="R",s="L";if(t&&o){const e=o.center[0]-t.center[0],i=o.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,r,o.routeType).forEach(e=>{s.createRelation(e)}),("layered"===r.layout||"horizontal"===r.layout)&&new l({gapX:o.gapX||120,gapY:o.gapY||50}).layoutContainer(n);o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):o.fitViewport&&function fitViewport(e,t,i){const r=t.entities||[];let o=1/0,n=1/0,s=-1/0,a=-1/0;r.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();o=Math.min(o,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-o,l=a-n,p=e.canvasWidth||0,c=e.canvasHeight||0;if(!p||!c||d<=0||l<=0)return;const u=Number.isFinite(i)&&i>=0?i:40,h=Math.max(1,p-2*u),f=Math.max(1,c-2*u),m=Math.min(h/d,f/l,1),g=(p-d*m)/2-o*m,b=(c-l*m)/2-n*m;e.setViewport(m,g,b)}(n,s,o.fitViewportPadding);return withDsl({kind:"entity",ice:n,designer:s})}(e,i)}function renderGanttDsl(e,r){const o=compileGanttDsl(r),n=o.options||{},s=(new t).init(e),a=new i(s);return n.dayWidth&&a.setDayWidth(n.dayWidth),o.nodes.forEach(e=>{a.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),o.edges.forEach(e=>{a.createDependency(e)}),a.select(null),n.autoSchedule&&a.autoSchedule(),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),withDsl({kind:"gantt",ice:s,designer:a})}function renderPowerDsl(e,i){const o=compilePowerDsl(i),n=o.options||{},s=(new t).init(e),a=new r(s);n.voltageColors&&a.setVoltageColors(n.voltageColors);const d=new Map;return o.nodes.forEach(e=>{const t=a.createSymbol(e.kind,{id:e.id,title:e.title,name:e.title,voltageLevel:e.voltageLevel,left:e.left,top:e.top,width:e.width,height:e.height,switchState:e.switchState});e.source&&t.setState({energizedSource:!0}),d.set(e.id,t)}),o.attachments.forEach(e=>{const t=d.get(e.deviceId),i=d.get(e.busId);t&&i&&a.attachToBus(t,i)}),o.edges.forEach(e=>{const t=d.get(e.sourceId),i=d.get(e.targetId);t&&i&&a.createLine({sourceId:t.state.id,targetId:i.state.id,sourcePort:e.sourcePort,targetPort:e.targetPort,voltageLevel:e.voltageLevel})}),a.select(null),a.applyTopology(),!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),withDsl({kind:"power",ice:s,designer:a})}function renderStatechartDsl(e,i){const r=compileStatechartDsl(i),n=r.options||{},s=(new t).init(e),a=new o(s);return r.nodes.forEach(e=>{a.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{a.createTransition(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),withDsl({kind:"statechart",ice:s,designer:a})}function renderUmlDsl(e,i){const r=compileUmlDsl(i),o=r.options||{},s=(new t).init(e),a=new n(s);return r.nodes.forEach(e=>{a.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),r.edges.forEach(e=>{a.createRelation(e)}),a.select(null),o.viewport?s.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&a.fitViewport(o.fitViewportPadding),a.resetHistory(),withDsl({kind:"uml",ice:s,designer:a})}function renderBpmnDsl(e,i){const r=compileBpmnDsl(i),o=r.options||{},n=(new t).init(e),a=new s(n);return r.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),a.createNode(e.kind,t)}),r.edges.forEach(e=>{a.createEdge(e)}),a.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&a.fitViewport(o.fitViewportPadding),a.resetHistory(),withDsl({kind:"bpmn",ice:n,designer:a})}function renderFlowDsl(e,i){const r=compileFlowDsl(i),o=r.options||{},n=(new t).init(e),s=new a(n);return r.nodes.forEach(e=>{s.createNode(e.kind,e)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"flowchart",ice:n,designer:s})}export{c as DSL_SCHEMA_VERSION,p as POWER_DSL_KINDS,compileBpmnDsl,compileDsl,compileFlowDsl,compileGanttDsl,compilePowerDsl,compileStatechartDsl,compileUmlDsl,isBpmnDsl,isFlowDsl,isGanttDsl,isPowerDsl,isStatechartDsl,isUmlDsl,layeredLayout,renderBpmnDsl,renderDsl,renderFlowDsl,renderGanttDsl,renderPowerDsl,renderStatechartDsl,renderUmlDsl,toDsl,validateBpmnDsl,validateDsl,validateFlowDsl,validateGanttDsl,validatePowerDsl,validateStatechartDsl,validateUmlDsl};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ice-entity-designer")):"function"==typeof define&&define.amd?define(["exports","ice-entity-designer"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ICEDSL={},e.IED)}(this,(function(e,t){"use strict";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const i=["terminator","process","decision","io"],o=["T","R","B","L","C"],r=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],n=["start","intermediate","end"],s=["none","message","timer","error","terminate"],a=["exclusive","parallel","inclusive","event"],d=["none","user","service","script","send","receive","manual"],l=["sequence","message","association"],p=["initial","final","state","composite"],h=["class","interface","enum"],c=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,o)=>{const r=`entities[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${r}.fields[${i}].name must be a non-empty string`)}):t.push(r+".fields must be an array")):t.push(r+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const o=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(o+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(o+".target must be a non-empty string")):t.push(o+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,l)=>{const p=`nodes[${l}]`;if(!e||"object"!=typeof e)return void t.push(p+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${p}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"task")):t.push(p+".id must be a non-empty string"),void 0!==e.kind&&-1===r.indexOf(e.kind)&&t.push(`${p}.kind must be one of ${r.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${p}.${i} must be a number when present`)});[["eventKind",n],["trigger",s],["gatewayType",a],["taskType",d]].forEach(([i,o])=>{const r=e[i];void 0!==r&&-1===o.indexOf(r)&&t.push(`${p}.${i} must be one of ${o.join("/")}`)})}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=o.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===l.indexOf(n)&&t.push(`${r}.type must be one of ${l.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(r+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(r+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const r=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?r.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):r.add(e.id):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===i.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${i.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const n=`edges[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&r.has(e.source)||t.push(n+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&r.has(e.target)||t.push(n+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present"),void 0!==e.sourcePort&&-1===o.indexOf(e.sourcePort)&&t.push(`${n}.sourcePort must be one of ${o.join("/")}`),void 0!==e.targetPort&&-1===o.indexOf(e.targetPort)&&t.push(`${n}.targetPort must be one of ${o.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(n+'.linkShape must be "visio" or "bezier" when present')):t.push(n+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===h.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${h.join("/")}`),["attributes","methods"].forEach(i=>{const o=e[i];void 0!==o&&(Array.isArray(o)&&!o.some(e=>"string"!=typeof e)||t.push(`${r}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${r}.${i} must be a number when present`)})):t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===c.indexOf(n)&&t.push(`${r}.type must be one of ${c.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,r)=>{const n=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===p.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${p.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==o.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const o=e[i];void 0!==o&&"string"!=typeof o&&t.push(`${r}.${i} must be a string when present`)})):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(r+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(r+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(r+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(r+".row must be a number >= 0 when present")}else t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing task id")):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const o=Number(i.gapX)||90,r=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const l=new Map,p=new Map;e.forEach(e=>{l.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(l.set(e.targetId,(l.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(h.set(e.id,0),c.push(e.id))}),c.length||(h.set(e[0].id,0),c.push(e[0].id));let u=e.length*e.length+e.length;for(;c.length&&u-- >0;){const e=c.shift(),t=h.get(e)||0;(p.get(e)||[]).forEach(e=>{const i=t+1;(void 0===h.get(e)?-1:h.get(e))<i&&(h.set(e,i),c.push(e))})}e.forEach(e=>{h.has(e.id)||h.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=h.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+r}),t+=e[n]+o})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+o}),t+=e[n]+r})}const g=Math.min(...e.map(e=>a.get(e.id).left)),y=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-y}),a}const u={terminator:{width:t.FLOW_NODE_KINDS.terminator.width,height:t.FLOW_NODE_KINDS.terminator.height,fill:t.FLOW_NODE_KINDS.terminator.fill,stroke:t.FLOW_NODE_KINDS.terminator.stroke},process:{width:t.FLOW_NODE_KINDS.process.width,height:t.FLOW_NODE_KINDS.process.height,fill:t.FLOW_NODE_KINDS.process.fill,stroke:t.FLOW_NODE_KINDS.process.stroke},decision:{width:t.FLOW_NODE_KINDS.decision.width,height:t.FLOW_NODE_KINDS.decision.height,fill:t.FLOW_NODE_KINDS.decision.fill,stroke:t.FLOW_NODE_KINDS.decision.stroke},io:{width:t.FLOW_NODE_KINDS.io.width,height:t.FLOW_NODE_KINDS.io.height,fill:t.FLOW_NODE_KINDS.io.fill,stroke:t.FLOW_NODE_KINDS.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&u[e.kind]?e.kind:"process"}(e),i=u[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(o=e,o.title||o.name||o.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var o}),o=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),r=t.layout||"layered";return"none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,o){const r=layeredLayout(e,t,{gapX:i,gapY:o});e.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,o,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:o,layout:r,options:t}}const f={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},m=Number(t.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,g=Number(t.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,y=Number(t.FLOW_NODE_KINDS.bpmnLane.height)||130,b=Number(t.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(e){const i=e.kind||"task",o=function presetOf(e){return t.FLOW_NODE_KINDS[e]||t.FLOW_NODE_KINDS.bpmnTask}(f[i]||"bpmnTask"),r={id:e.id,typeId:"FlowNode",kind:f[i]||"bpmnTask",title:e.title||e.name||e.id,left:"number"==typeof e.left?e.left:0,top:"number"==typeof e.top?e.top:0,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height,fillColor:e.fillColor,strokeColor:e.strokeColor,dslKind:i,parent:e.parent,explicitLeft:"number"==typeof e.left,explicitTop:"number"==typeof e.top,explicitWidth:"number"==typeof e.width,explicitHeight:"number"==typeof e.height};return"event"===i&&(r.eventKind=e.eventKind||o.eventKind||"start",r.trigger=e.trigger||o.trigger||"none"),"gateway"===i&&(r.gatewayType=e.gatewayType||o.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(r.taskType=e.taskType||o.taskType||"none"),r}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const o=1===t.length?t[0]:null,r=[];return e.forEach(e=>{(e=>{let t=r.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},r.push(t)),t})((e.parent?i.get(e.parent):void 0)||o).nodes.push(e)}),r}function layoutGroups(e,t,i,o){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const r=layeredLayout(e.nodes,t,{gapX:i,gapY:o,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,o=-1/0,r=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),o=Math.max(o,e.left+e.width),r=Math.max(r,e.top+e.height)}),{minX:t,minY:i,maxX:o,maxY:r}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),o=i.filter(e=>"pool"===e.dslKind),r=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let o=e.parent;o||1!==t.length||(o=t[0].id),o&&i.set(e.id,o)}),i}(r,o),lanesOf=e=>r.filter(t=>d.get(t.id)===e);let l=[];"none"!==a&&(l=buildGroups(n,o.concat(r)),layoutGroups(l,s,Number(t.gapX)||90,Number(t.gapY)||60)),r.forEach(e=>{const t=l.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),y))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+g+56,b)))}),o.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),b);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=m+t.reduce((e,t)=>e+t.height,0)))}const i=l.filter(t=>t.owner===e)[0],o=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(o?o.maxX-o.minX:0),b))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+m+56,160)))});let p=60;o.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=p),p=Math.max(p,e.top+e.height+60)}),o.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+m,o=Math.max(e.height-m,1),r=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(o-r,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||y)),a=t.top+t.height})});let h=60;r.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let o=80,r=80;i&&(o=i.left+28,r=i.top+28,"pool"===i.dslKind?r+=m:o+=g),e.nodes.forEach(e=>{e.left=Math.round(o+(e.left-t.minX)),e.top=Math.round(r+(e.top-t.minY))})});return{kind:"bpmn",nodes:o.concat(r).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),o=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),r=t.layout||"layered";if("none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,o.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:o,layout:r,options:t}}const w={width:160,height:64},D={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,o="composite"===t?D:i?{width:24,height:24}:w;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height}}),o=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),r=t.layout||"auto",n=new Set;if("none"!==r){const e=new Map;i.forEach(t=>e.set(t.id,t));const r=i.filter(t=>!(t.parent&&e.has(t.parent)));if(r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=o.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(r,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});r.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...r.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let o=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(o>56&&o+e.width>56+p&&(o=56,a=l+40),n.add(e.id),e.left=o,e.top=a,o+=e.width+40,d=Math.max(d,o),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,o)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=o,offsetChildren(e,t,o))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:o,layout:r,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderGanttDsl(e,i){const o=compileGanttDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.GanttDesigner(n);return r.dayWidth&&s.setDayWidth(r.dayWidth),o.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),o.edges.forEach(e=>{s.createDependency(e)}),s.select(null),r.autoSchedule&&s.autoSchedule(),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderStatechartDsl(e,i){const o=compileStatechartDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.StatechartDesigner(n);return o.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),o.edges.forEach(e=>{s.createTransition(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"statechart",ice:n,designer:s}}function renderUmlDsl(e,i){const o=compileUmlDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.UmlDesigner(n);return o.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),o.edges.forEach(e=>{s.createRelation(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:n,designer:s}}function renderBpmnDsl(e,i){const o=compileBpmnDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.BpmnDesigner(n);return o.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),s.createNode(e.kind,t)}),o.edges.forEach(e=>{s.createEdge(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:n,designer:s}}function renderFlowDsl(e,i){const o=compileFlowDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.FlowDesigner(n);return o.nodes.forEach(e=>{s.createNode(e.kind,e)}),o.edges.forEach(e=>{s.createEdge(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:n,designer:s}}e.DSL_SCHEMA_VERSION=1,e.compileBpmnDsl=compileBpmnDsl,e.compileDsl=compileDsl,e.compileFlowDsl=compileFlowDsl,e.compileGanttDsl=compileGanttDsl,e.compileStatechartDsl=compileStatechartDsl,e.compileUmlDsl=compileUmlDsl,e.isBpmnDsl=isBpmnDsl,e.isFlowDsl=isFlowDsl,e.isGanttDsl=isGanttDsl,e.isStatechartDsl=isStatechartDsl,e.isUmlDsl=isUmlDsl,e.layeredLayout=layeredLayout,e.renderBpmnDsl=renderBpmnDsl,e.renderDsl=function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.EntityDesigner(n);o.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const o=new Map;return e.entities.forEach(e=>{o.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=o.get(e.sourceId),r=o.get(e.targetId);let n="R",s="L";if(t&&r){const e=r.center[0]-t.center[0],i=r.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,o,r.routeType).forEach(e=>{s.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new t.ICELayeredLayout({gapX:r.gapX||120,gapY:r.gapY||50}).layoutContainer(n);r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):r.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let r=1/0,n=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();r=Math.min(r,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-r,l=a-n,p=e.canvasWidth||0,h=e.canvasHeight||0;if(!p||!h||d<=0||l<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,p-2*c),f=Math.max(1,h-2*c),m=Math.min(u/d,f/l,1),g=(p-d*m)/2-r*m,y=(h-l*m)/2-n*m;e.setViewport(m,g,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(e,i)},e.renderFlowDsl=renderFlowDsl,e.renderGanttDsl=renderGanttDsl,e.renderStatechartDsl=renderStatechartDsl,e.renderUmlDsl=renderUmlDsl,e.validateBpmnDsl=validateBpmnDsl,e.validateDsl=validateDsl,e.validateFlowDsl=validateFlowDsl,e.validateGanttDsl=validateGanttDsl,e.validateStatechartDsl=validateStatechartDsl,e.validateUmlDsl=validateUmlDsl,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ice-entity-designer")):"function"==typeof define&&define.amd?define(["exports","ice-entity-designer"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ICEDSL={},e.IED)}(this,(function(e,t){"use strict";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const i=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"];function isPowerDsl(e){return!!e&&"object"==typeof e&&"power"===e.kind}const r=["terminator","process","decision","io"],o=["T","R","B","L","C"],n=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],s=["start","intermediate","end"],a=["none","message","timer","error","terminate"],d=["exclusive","parallel","inclusive","event"],l=["none","user","service","script","send","receive","manual"],p=["sequence","message","association"],c=["initial","final","state","composite"],u=["class","interface","enum"],h=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isPowerDsl(e)?validatePowerDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,r)=>{const o=`entities[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${o}.fields[${i}].name must be a non-empty string`)}):t.push(o+".fields must be an array")):t.push(o+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const r=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(r+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(r+".target must be a non-empty string")):t.push(r+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,r=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,o)=>{const p=`nodes[${o}]`;if(!e||"object"!=typeof e)return void t.push(p+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${p}.id is duplicated: ${e.id}`):(i.add(e.id),r.set(e.id,e.kind||"task")):t.push(p+".id must be a non-empty string"),void 0!==e.kind&&-1===n.indexOf(e.kind)&&t.push(`${p}.kind must be one of ${n.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${p}.${i} must be a number when present`)});[["eventKind",s],["trigger",a],["gatewayType",d],["taskType",l]].forEach(([i,r])=>{const o=e[i];void 0!==o&&-1===r.indexOf(o)&&t.push(`${p}.${i} must be one of ${r.join("/")}`)})}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=r.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===p.indexOf(n)&&t.push(`${o}.type must be one of ${p.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(o+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(o+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):i.add(e.id):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===r.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${r.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const n=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(n+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(n+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present"),void 0!==e.sourcePort&&-1===o.indexOf(e.sourcePort)&&t.push(`${n}.sourcePort must be one of ${o.join("/")}`),void 0!==e.targetPort&&-1===o.indexOf(e.targetPort)&&t.push(`${n}.targetPort must be one of ${o.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(n+'.linkShape must be "visio" or "bezier" when present')):t.push(n+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),void 0!==e.kind&&-1===u.indexOf(e.kind)&&t.push(`${o}.kind must be one of ${u.join("/")}`),["attributes","methods"].forEach(i=>{const r=e[i];void 0!==r&&(Array.isArray(r)&&!r.some(e=>"string"!=typeof e)||t.push(`${o}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${o}.${i} must be a number when present`)})):t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===h.indexOf(n)&&t.push(`${o}.type must be one of ${h.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,r=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),r.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===c.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${c.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==r.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const r=e[i];void 0!==r&&"string"!=typeof r&&t.push(`${o}.${i} must be a string when present`)})):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(o+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(o+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(o+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(o+".row must be a number >= 0 when present")}else t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing task id")):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validatePowerDsl(e){const t=[],r=Array.isArray(e.nodes)?e.nodes:[];Array.isArray(e.nodes)||t.push("nodes must be an array");const o=new Set;return r.forEach((e,r)=>{const n=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id?o.has(e.id)?t.push("duplicated node id: "+e.id):o.add(e.id):t.push(n+".id must be a non-empty string"),-1===i.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${i.join(" / ")}`),void 0===e.voltageLevel||/^\d+(\.\d+)?kV$/.test(String(e.voltageLevel))||t.push(n+'.voltageLevel must look like "110kV"')):t.push(n+" must be an object")}),r.forEach((e,i)=>{if(!e||void 0===e.attachedTo)return;const o=r.find(t=>t&&t.id===e.attachedTo);o?"busbar"!==o.kind&&t.push(`nodes[${i}].attachedTo must point at a busbar: ${e.attachedTo} is ${o.kind}`):t.push(`nodes[${i}].attachedTo references an unknown node: ${e.attachedTo}`)}),(e.edges||[]).forEach((e,i)=>{const r=`edges[${i}]`;e&&"object"==typeof e?(o.has(e.source)||t.push(`${r}.source references an unknown node: ${e.source}`),o.has(e.target)||t.push(`${r}.target references an unknown node: ${e.target}`),e.source===e.target&&t.push(r+" must not connect a node to itself")):t.push(r+" must be an object")}),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const r=Number(i.gapX)||90,o=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const l=new Map,p=new Map;e.forEach(e=>{l.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(l.set(e.targetId,(l.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const c=new Map,u=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(c.set(e.id,0),u.push(e.id))}),u.length||(c.set(e[0].id,0),u.push(e[0].id));let h=e.length*e.length+e.length;for(;u.length&&h-- >0;){const e=u.shift(),t=c.get(e)||0;(p.get(e)||[]).forEach(e=>{const i=t+1;(void 0===c.get(e)?-1:c.get(e))<i&&(c.set(e,i),u.push(e))})}e.forEach(e=>{c.has(e.id)||c.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=c.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+o}),t+=e[n]+r})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+r}),t+=e[n]+o})}const g=Math.min(...e.map(e=>a.get(e.id).left)),y=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-y}),a}const f={terminator:{width:t.FLOW_NODE_KINDS.terminator.width,height:t.FLOW_NODE_KINDS.terminator.height,fill:t.FLOW_NODE_KINDS.terminator.fill,stroke:t.FLOW_NODE_KINDS.terminator.stroke},process:{width:t.FLOW_NODE_KINDS.process.width,height:t.FLOW_NODE_KINDS.process.height,fill:t.FLOW_NODE_KINDS.process.fill,stroke:t.FLOW_NODE_KINDS.process.stroke},decision:{width:t.FLOW_NODE_KINDS.decision.width,height:t.FLOW_NODE_KINDS.decision.height,fill:t.FLOW_NODE_KINDS.decision.fill,stroke:t.FLOW_NODE_KINDS.decision.stroke},io:{width:t.FLOW_NODE_KINDS.io.width,height:t.FLOW_NODE_KINDS.io.height,fill:t.FLOW_NODE_KINDS.io.fill,stroke:t.FLOW_NODE_KINDS.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&f[e.kind]?e.kind:"process"}(e),i=f[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(r=e,r.title||r.name||r.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var r}),r=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),o=t.layout||"layered";return"none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,r){const o=layeredLayout(e,t,{gapX:i,gapY:r});e.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,r,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:r,layout:o,options:t}}const m={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},g=Number(t.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,y=Number(t.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,b=Number(t.FLOW_NODE_KINDS.bpmnLane.height)||130,w=Number(t.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(e){const i=e.kind||"task",r=function presetOf(e){return t.FLOW_NODE_KINDS[e]||t.FLOW_NODE_KINDS.bpmnTask}(m[i]||"bpmnTask"),o={id:e.id,typeId:"FlowNode",kind:m[i]||"bpmnTask",title:e.title||e.name||e.id,left:"number"==typeof e.left?e.left:0,top:"number"==typeof e.top?e.top:0,width:"number"==typeof e.width?e.width:r.width,height:"number"==typeof e.height?e.height:r.height,fillColor:e.fillColor,strokeColor:e.strokeColor,dslKind:i,parent:e.parent,explicitLeft:"number"==typeof e.left,explicitTop:"number"==typeof e.top,explicitWidth:"number"==typeof e.width,explicitHeight:"number"==typeof e.height};return"event"===i&&(o.eventKind=e.eventKind||r.eventKind||"start",o.trigger=e.trigger||r.trigger||"none"),"gateway"===i&&(o.gatewayType=e.gatewayType||r.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(o.taskType=e.taskType||r.taskType||"none"),o}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const r=1===t.length?t[0]:null,o=[];return e.forEach(e=>{(e=>{let t=o.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},o.push(t)),t})((e.parent?i.get(e.parent):void 0)||r).nodes.push(e)}),o}function layoutGroups(e,t,i,r){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const o=layeredLayout(e.nodes,t,{gapX:i,gapY:r,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,r=-1/0,o=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),r=Math.max(r,e.left+e.width),o=Math.max(o,e.top+e.height)}),{minX:t,minY:i,maxX:r,maxY:o}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),r=i.filter(e=>"pool"===e.dslKind),o=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let r=e.parent;r||1!==t.length||(r=t[0].id),r&&i.set(e.id,r)}),i}(o,r),lanesOf=e=>o.filter(t=>d.get(t.id)===e);let l=[];"none"!==a&&(l=buildGroups(n,r.concat(o)),layoutGroups(l,s,Number(t.gapX)||90,Number(t.gapY)||60)),o.forEach(e=>{const t=l.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),b))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+y+56,w)))}),r.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),w);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=g+t.reduce((e,t)=>e+t.height,0)))}const i=l.filter(t=>t.owner===e)[0],r=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(r?r.maxX-r.minX:0),w))),e.explicitHeight||(e.height=Math.round(Math.max((r?r.maxY-r.minY:0)+g+56,160)))});let p=60;r.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=p),p=Math.max(p,e.top+e.height+60)}),r.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+g,r=Math.max(e.height-g,1),o=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(r-o,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||b)),a=t.top+t.height})});let c=60;o.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=c,c=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let r=80,o=80;i&&(r=i.left+28,o=i.top+28,"pool"===i.dslKind?o+=g:r+=y),e.nodes.forEach(e=>{e.left=Math.round(r+(e.left-t.minX)),e.top=Math.round(o+(e.top-t.minY))})});return{kind:"bpmn",nodes:r.concat(o).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),r=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),o=t.layout||"layered";if("none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,r.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:r,layout:o,options:t}}const v={width:160,height:64},D={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,r="composite"===t?D:i?{width:24,height:24}:v;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:r.width,height:"number"==typeof e.height?e.height:r.height}}),r=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),o=t.layout||"auto",n=new Set;if("none"!==o){const e=new Map;i.forEach(t=>e.set(t.id,t));const o=i.filter(t=>!(t.parent&&e.has(t.parent)));if(o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=r.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(o,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});o.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...o.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let r=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(r>56&&r+e.width>56+p&&(r=56,a=l+40),n.add(e.id),e.left=r,e.top=a,r+=e.width+40,d=Math.max(d,r),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,r)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=r,offsetChildren(e,t,r))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:r,layout:o,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function compilePowerDsl(e){const t=e.options||{},i=(e.nodes||[]).map((e,t)=>{const i=function defaultPlacement(e){return{left:120+e%6*200,top:120+160*Math.floor(e/6)}}(t);return{id:e.id,kind:e.kind,title:e.title||e.name||e.id,voltageLevel:String(e.voltageLevel||""),left:"number"==typeof e.left?e.left:i.left,top:"number"==typeof e.top?e.top:i.top,width:e.width,height:e.height,switchState:e.switchState,source:!!e.source}}),r=new Map;i.forEach(e=>r.set(e.id,e));return{kind:"power",nodes:i,edges:(e.edges||[]).map((e,t)=>({id:e.id||"conductor-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",voltageLevel:e.voltageLevel||(r.get(e.source)||{}).voltageLevel||""})),attachments:(e.nodes||[]).filter(e=>!!e.attachedTo).map(e=>({deviceId:e.id,busId:String(e.attachedTo)})),options:t}}const O={bpmnPool:"pool",bpmnLane:"lane",bpmnTask:"task",bpmnEvent:"event",bpmnGateway:"gateway",bpmnSubprocess:"subprocess",bpmnDataObject:"dataObject",bpmnAnnotation:"annotation"},k=["terminator","process","decision","io"],N=["class","interface","enum"],x=["initial","final","state","composite"];function stateOf(e){return e&&e.state||{}}function linkOf(e,t){const i=e.links;return i&&i[t]||{}}function absolutePosition(e){let t=0,i=0,r=e;for(;r&&r.state&&"number"==typeof r.state.left;)t+=r.state.left||0,i+=r.state.top||0,r=r.parentNode;return{left:Math.round(t),top:Math.round(i)}}function parentIdOf(e){const t=e&&e.parentNode,i=t&&t.state?t.state.id:void 0;return"string"==typeof i&&i.length>0?i:void 0}function numberOf(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function textOf(e){return"string"==typeof e&&e.length>0?e:void 0}function clean(e){const t={};return Object.keys(e).forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),t}function nodesOf(e){return e&&Array.isArray(e.nodes)?e.nodes:[]}function edgesOf(e){return e&&Array.isArray(e.edges)?e.edges:[]}function baseOf(e){const t=stateOf(e),i=absolutePosition(e);return{id:t.id,title:textOf(t.title),left:i.left,top:i.top}}function toDsl(e,t={}){const r=e&&e.designer?e.designer:e,o=t.kind||e&&e.kind||function detectKind(e){if(!e)return;if(Array.isArray(e.entities))return"entity";if(void 0!==e.originDate||void 0!==e.dayWidth)return"gantt";const t=nodesOf(e)[0],r=t?String(stateOf(t).kind||""):"";return r.startsWith("bpmn")?"bpmn":N.indexOf(r)>=0?"uml":x.indexOf(r)>=0?"statechart":i.indexOf(r)>=0?"power":k.indexOf(r)>=0?"flowchart":void 0}(r);if(!o)throw new Error("toDsl(): 无法推断文档类型(实例里没有可识别的图元)。请显式传入 kind:'flowchart' | 'bpmn' | 'uml' | 'statechart' | 'gantt' | 'power' | 'entity'。");switch(o){case"flowchart":return function exportFlow(e){return{schemaVersion:1,kind:"flowchart",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:t.kind,width:numberOf(t.width),height:numberOf(t.height),fillColor:textOf(t.fillColor),strokeColor:textOf(t.strokeColor)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,sourcePort:i.position,targetPort:r.position,label:textOf(t.label)||"",linkShape:textOf(t.linkShape)})})}}(r);case"bpmn":return function exportBpmn(e){return{schemaVersion:1,kind:"bpmn",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:O[t.kind]||"task",parent:parentIdOf(e),width:numberOf(t.width),height:numberOf(t.height),eventKind:textOf(t.eventKind),trigger:textOf(t.trigger),gatewayType:textOf(t.gatewayType),taskType:textOf(t.taskType),fillColor:textOf(t.fillColor),strokeColor:textOf(t.strokeColor)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,type:textOf(t.flowType)||"sequence",label:textOf(t.label),condition:textOf(t.condition),isDefault:!0===t.isDefault||void 0,linkShape:textOf(t.linkShape)})})}}(r);case"uml":return function exportUml(e){return{schemaVersion:1,kind:"uml",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:textOf(t.kind)||"class",title:textOf(t.className)||textOf(t.title),abstract:!0===t.abstract||void 0,attributes:Array.isArray(t.attributes)?t.attributes.map(e=>String(e)):[],methods:Array.isArray(t.methods)?t.methods.map(e=>String(e)):[],width:numberOf(t.width),height:numberOf(t.height)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,type:textOf(t.relationKind)||"association",label:textOf(t.label)})})}}(r);case"statechart":return function exportStatechart(e){return{schemaVersion:1,kind:"statechart",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({...baseOf(e),kind:textOf(t.kind)||"state",parent:parentIdOf(e),width:numberOf(t.width),height:numberOf(t.height)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,event:textOf(t.event),guard:textOf(t.guard),action:textOf(t.action),label:textOf(t.label)})})}}(r);case"gantt":return function exportGantt(e){return{schemaVersion:1,kind:"gantt",nodes:nodesOf(e).map(e=>{const t=stateOf(e);return clean({id:t.id,title:textOf(t.title),start:textOf(t.start),days:numberOf(t.days),progress:numberOf(t.progress),row:numberOf(t.row),resource:textOf(t.resource)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id})})}}(r);case"power":return function exportPower(e){return{schemaVersion:1,kind:"power",nodes:nodesOf(e).map(e=>{const t=stateOf(e),i=absolutePosition(e);return clean({id:t.id,kind:t.kind,title:textOf(t.title)||textOf(t.name),voltageLevel:textOf(t.voltageLevel),left:i.left,top:i.top,width:numberOf(t.width),height:numberOf(t.height),switchState:textOf(t.switchState),source:!0===t.source||!0===t.energizedSource||void 0,attachedTo:textOf(t.attachedBusId)})}),edges:edgesOf(e).map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,sourcePort:i.position,targetPort:r.position,voltageLevel:textOf(t.voltageLevel)})})}}(r);case"entity":case"er":default:return function exportEr(e){const t=e&&Array.isArray(e.entities)?e.entities:[],i=e&&Array.isArray(e.relations)?e.relations:[];return{schemaVersion:1,entities:t.map(e=>{const t=stateOf(e),i=absolutePosition(e);return clean({id:t.id,name:textOf(t.entityName),fields:Array.isArray(t.fields)?t.fields:[],left:i.left,top:i.top})}),relations:i.map(e=>{const t=stateOf(e),i=linkOf(t,"start"),r=linkOf(t,"end");return clean({id:t.id,source:i.id,target:r.id,type:t.relationType,sourceField:textOf(t.sourceField),targetField:textOf(t.targetField),label:textOf(t.label),onDelete:textOf(t.onDelete),onUpdate:textOf(t.onUpdate),joinTableName:textOf(t.joinTableName),nullable:"boolean"==typeof t.nullable?t.nullable:void 0,sourceCardinality:textOf(t.sourceCardinality),targetCardinality:textOf(t.targetCardinality),linkShape:textOf(t.linkShape)})})}}(r)}}function withDsl(e){return Object.assign(e,{toDsl:()=>toDsl(e)})}function renderGanttDsl(e,i){const r=compileGanttDsl(i),o=r.options||{},n=(new t.ICE).init(e),s=new t.GanttDesigner(n);return o.dayWidth&&s.setDayWidth(o.dayWidth),r.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),r.edges.forEach(e=>{s.createDependency(e)}),s.select(null),o.autoSchedule&&s.autoSchedule(),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"gantt",ice:n,designer:s})}function renderPowerDsl(e,i){const r=compilePowerDsl(i),o=r.options||{},n=(new t.ICE).init(e),s=new t.PowerDesigner(n);o.voltageColors&&s.setVoltageColors(o.voltageColors);const a=new Map;return r.nodes.forEach(e=>{const t=s.createSymbol(e.kind,{id:e.id,title:e.title,name:e.title,voltageLevel:e.voltageLevel,left:e.left,top:e.top,width:e.width,height:e.height,switchState:e.switchState});e.source&&t.setState({energizedSource:!0}),a.set(e.id,t)}),r.attachments.forEach(e=>{const t=a.get(e.deviceId),i=a.get(e.busId);t&&i&&s.attachToBus(t,i)}),r.edges.forEach(e=>{const t=a.get(e.sourceId),i=a.get(e.targetId);t&&i&&s.createLine({sourceId:t.state.id,targetId:i.state.id,sourcePort:e.sourcePort,targetPort:e.targetPort,voltageLevel:e.voltageLevel})}),s.select(null),s.applyTopology(),!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"power",ice:n,designer:s})}function renderStatechartDsl(e,i){const r=compileStatechartDsl(i),o=r.options||{},n=(new t.ICE).init(e),s=new t.StatechartDesigner(n);return r.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{s.createTransition(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"statechart",ice:n,designer:s})}function renderUmlDsl(e,i){const r=compileUmlDsl(i),o=r.options||{},n=(new t.ICE).init(e),s=new t.UmlDesigner(n);return r.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),r.edges.forEach(e=>{s.createRelation(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"uml",ice:n,designer:s})}function renderBpmnDsl(e,i){const r=compileBpmnDsl(i),o=r.options||{},n=(new t.ICE).init(e),s=new t.BpmnDesigner(n);return r.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),s.createNode(e.kind,t)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"bpmn",ice:n,designer:s})}function renderFlowDsl(e,i){const r=compileFlowDsl(i),o=r.options||{},n=(new t.ICE).init(e),s=new t.FlowDesigner(n);return r.nodes.forEach(e=>{s.createNode(e.kind,e)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),withDsl({kind:"flowchart",ice:n,designer:s})}e.DSL_SCHEMA_VERSION=1,e.POWER_DSL_KINDS=i,e.compileBpmnDsl=compileBpmnDsl,e.compileDsl=compileDsl,e.compileFlowDsl=compileFlowDsl,e.compileGanttDsl=compileGanttDsl,e.compilePowerDsl=compilePowerDsl,e.compileStatechartDsl=compileStatechartDsl,e.compileUmlDsl=compileUmlDsl,e.isBpmnDsl=isBpmnDsl,e.isFlowDsl=isFlowDsl,e.isGanttDsl=isGanttDsl,e.isPowerDsl=isPowerDsl,e.isStatechartDsl=isStatechartDsl,e.isUmlDsl=isUmlDsl,e.layeredLayout=layeredLayout,e.renderBpmnDsl=renderBpmnDsl,e.renderDsl=function renderDsl(e,i){const r=validateDsl(i);if(!r.valid)throw new Error(r.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isPowerDsl(i)?renderPowerDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const r=compileDsl(i),o=r.options||{},n=(new t.ICE).init(e),s=new t.EntityDesigner(n);r.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const r=new Map;return e.entities.forEach(e=>{r.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=r.get(e.sourceId),o=r.get(e.targetId);let n="R",s="L";if(t&&o){const e=o.center[0]-t.center[0],i=o.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,r,o.routeType).forEach(e=>{s.createRelation(e)}),("layered"===r.layout||"horizontal"===r.layout)&&new t.ICELayeredLayout({gapX:o.gapX||120,gapY:o.gapY||50}).layoutContainer(n);o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):o.fitViewport&&function fitViewport(e,t,i){const r=t.entities||[];let o=1/0,n=1/0,s=-1/0,a=-1/0;r.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();o=Math.min(o,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-o,l=a-n,p=e.canvasWidth||0,c=e.canvasHeight||0;if(!p||!c||d<=0||l<=0)return;const u=Number.isFinite(i)&&i>=0?i:40,h=Math.max(1,p-2*u),f=Math.max(1,c-2*u),m=Math.min(h/d,f/l,1),g=(p-d*m)/2-o*m,y=(c-l*m)/2-n*m;e.setViewport(m,g,y)}(n,s,o.fitViewportPadding);return withDsl({kind:"entity",ice:n,designer:s})}(e,i)},e.renderFlowDsl=renderFlowDsl,e.renderGanttDsl=renderGanttDsl,e.renderPowerDsl=renderPowerDsl,e.renderStatechartDsl=renderStatechartDsl,e.renderUmlDsl=renderUmlDsl,e.toDsl=toDsl,e.validateBpmnDsl=validateBpmnDsl,e.validateDsl=validateDsl,e.validateFlowDsl=validateFlowDsl,e.validateGanttDsl=validateGanttDsl,e.validatePowerDsl=validatePowerDsl,e.validateStatechartDsl=validateStatechartDsl,e.validateUmlDsl=validateUmlDsl,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DslPowerDocument } from '../types';
|
|
2
|
+
export declare type CompiledPowerNode = {
|
|
3
|
+
id: string;
|
|
4
|
+
kind: string;
|
|
5
|
+
title: string;
|
|
6
|
+
voltageLevel: string;
|
|
7
|
+
left: number;
|
|
8
|
+
top: number;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
switchState?: 'open' | 'closed';
|
|
12
|
+
source: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare type CompiledPowerEdge = {
|
|
15
|
+
id: string;
|
|
16
|
+
sourceId: string;
|
|
17
|
+
targetId: string;
|
|
18
|
+
sourcePort: string;
|
|
19
|
+
targetPort: string;
|
|
20
|
+
voltageLevel: string;
|
|
21
|
+
};
|
|
22
|
+
export declare type CompiledPowerAttachment = {
|
|
23
|
+
deviceId: string;
|
|
24
|
+
busId: string;
|
|
25
|
+
};
|
|
26
|
+
export declare type CompiledPowerScene = {
|
|
27
|
+
kind: 'power';
|
|
28
|
+
nodes: CompiledPowerNode[];
|
|
29
|
+
edges: CompiledPowerEdge[];
|
|
30
|
+
/** 母线 T 接:渲染时对每一条调用 `designer.attachToBus(device, bus)` */
|
|
31
|
+
attachments: CompiledPowerAttachment[];
|
|
32
|
+
options?: Record<string, any>;
|
|
33
|
+
};
|
|
34
|
+
export declare function compilePowerDsl(dsl: DslPowerDocument): CompiledPowerScene;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './types';
|
|
2
|
-
export { DSL_SCHEMA_VERSION, validateDsl, validateFlowDsl, validateBpmnDsl, validateUmlDsl, validateStatechartDsl, validateGanttDsl, } from './validate';
|
|
2
|
+
export { DSL_SCHEMA_VERSION, validateDsl, validateFlowDsl, validateBpmnDsl, validateUmlDsl, validateStatechartDsl, validateGanttDsl, validatePowerDsl, } from './validate';
|
|
3
3
|
export { compileDsl } from './compiler/dslToScene';
|
|
4
4
|
export type { CompiledScene } from './compiler/dslToScene';
|
|
5
5
|
export { compileFlowDsl } from './compiler/flowToScene';
|
|
@@ -13,6 +13,8 @@ export type { CompiledUmlScene, CompiledUmlNode, CompiledUmlEdge } from './compi
|
|
|
13
13
|
export { compileStatechartDsl } from './compiler/statechartToScene';
|
|
14
14
|
export type { CompiledStatechartScene, CompiledStatechartNode, CompiledStatechartEdge } from './compiler/statechartToScene';
|
|
15
15
|
export { compileGanttDsl } from './compiler/ganttToScene';
|
|
16
|
+
export { compilePowerDsl } from './compiler/powerToScene';
|
|
16
17
|
export type { CompiledGanttScene, CompiledGanttTask, CompiledGanttDependency } from './compiler/ganttToScene';
|
|
17
|
-
export { renderDsl, renderFlowDsl, renderBpmnDsl, renderUmlDsl, renderStatechartDsl, renderGanttDsl } from './runtime/renderDsl';
|
|
18
|
+
export { renderDsl, renderFlowDsl, renderBpmnDsl, renderUmlDsl, renderStatechartDsl, renderGanttDsl, renderPowerDsl } from './runtime/renderDsl';
|
|
19
|
+
export { toDsl } from './runtime/exportDsl';
|
|
18
20
|
export type { RenderDslResult, RenderErDslResult, RenderFlowDslResult, RenderBpmnDslResult, RenderUmlDslResult, RenderStatechartDslResult, RenderGanttDslResult, } from './runtime/renderDsl';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DslDocument } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 把可编辑实例写回 DSL 文档。
|
|
4
|
+
*
|
|
5
|
+
* @param input `renderDsl()` 的返回值,或任意 designer 实例
|
|
6
|
+
* @param options `{ kind }` 强制指定文档类型(推断不出来时用)
|
|
7
|
+
*/
|
|
8
|
+
export declare function toDsl(input: any, options?: {
|
|
9
|
+
kind?: string;
|
|
10
|
+
}): DslDocument;
|
|
@@ -1,33 +1,45 @@
|
|
|
1
|
-
import type { DslBpmnDocument, DslGanttDocument, DslDocument, DslFlowDocument, DslStatechartDocument, DslUmlDocument } from '../types';
|
|
1
|
+
import type { DslPowerDocument, DslBpmnDocument, DslGanttDocument, DslDocument, DslFlowDocument, DslStatechartDocument, DslUmlDocument } from '../types';
|
|
2
2
|
export declare type RenderErDslResult = {
|
|
3
3
|
kind: 'entity';
|
|
4
4
|
ice: any;
|
|
5
5
|
designer: any;
|
|
6
|
+
/** 把当前(可能已被用户编辑过的)实例写回同一份 DSL 文档 */
|
|
7
|
+
toDsl: () => any;
|
|
6
8
|
};
|
|
7
9
|
export declare type RenderFlowDslResult = {
|
|
8
10
|
kind: 'flowchart';
|
|
9
11
|
ice: any;
|
|
10
12
|
designer: any;
|
|
13
|
+
/** 把当前(可能已被用户编辑过的)实例写回同一份 DSL 文档 */
|
|
14
|
+
toDsl: () => any;
|
|
11
15
|
};
|
|
12
16
|
export declare type RenderBpmnDslResult = {
|
|
13
17
|
kind: 'bpmn';
|
|
14
18
|
ice: any;
|
|
15
19
|
designer: any;
|
|
20
|
+
/** 把当前(可能已被用户编辑过的)实例写回同一份 DSL 文档 */
|
|
21
|
+
toDsl: () => any;
|
|
16
22
|
};
|
|
17
23
|
export declare type RenderUmlDslResult = {
|
|
18
24
|
kind: 'uml';
|
|
19
25
|
ice: any;
|
|
20
26
|
designer: any;
|
|
27
|
+
/** 把当前(可能已被用户编辑过的)实例写回同一份 DSL 文档 */
|
|
28
|
+
toDsl: () => any;
|
|
21
29
|
};
|
|
22
30
|
export declare type RenderGanttDslResult = {
|
|
23
31
|
kind: 'gantt';
|
|
24
32
|
ice: any;
|
|
25
33
|
designer: any;
|
|
34
|
+
/** 把当前(可能已被用户编辑过的)实例写回同一份 DSL 文档 */
|
|
35
|
+
toDsl: () => any;
|
|
26
36
|
};
|
|
27
37
|
export declare type RenderStatechartDslResult = {
|
|
28
38
|
kind: 'statechart';
|
|
29
39
|
ice: any;
|
|
30
40
|
designer: any;
|
|
41
|
+
/** 把当前(可能已被用户编辑过的)实例写回同一份 DSL 文档 */
|
|
42
|
+
toDsl: () => any;
|
|
31
43
|
};
|
|
32
44
|
export declare type RenderDslResult = RenderErDslResult | RenderFlowDslResult | RenderBpmnDslResult | RenderUmlDslResult | RenderStatechartDslResult | RenderGanttDslResult;
|
|
33
45
|
/**
|
|
@@ -48,6 +60,14 @@ export declare function renderGanttDsl(canvasOrId: any, dsl: DslGanttDocument):
|
|
|
48
60
|
*
|
|
49
61
|
* 语义校验用 `designer.validateStatechart()`;矢量导出用 `designer.toSvg()`。
|
|
50
62
|
*/
|
|
63
|
+
/**
|
|
64
|
+
* 渲染电力一次系统图(单线图)文档。
|
|
65
|
+
*
|
|
66
|
+
* 与其它文档类型一致:DSL 只描述模型(设备 + 导体 + 母线 T 接),渲染交给
|
|
67
|
+
* ice-entity-designer 的 `PowerDesigner` —— 色标、拓扑(带电范围)、五防校验都在那边。
|
|
68
|
+
* 语义校验用 `designer.validatePower()`;矢量导出用 `designer.toSvg()`。
|
|
69
|
+
*/
|
|
70
|
+
export declare function renderPowerDsl(canvasOrId: any, dsl: DslPowerDocument): any;
|
|
51
71
|
export declare function renderStatechartDsl(canvasOrId: any, dsl: DslStatechartDocument): RenderStatechartDslResult;
|
|
52
72
|
/**
|
|
53
73
|
* 渲染 UML 类图文档:类是复合组件(成员由 state 派生),关系是六种记法之一。
|
package/dist/types/types.d.ts
CHANGED
|
@@ -345,3 +345,52 @@ export declare type DslGanttDocument = {
|
|
|
345
345
|
};
|
|
346
346
|
/** 运行时判别:带 kind: 'gantt' 的按甘特文档处理 */
|
|
347
347
|
export declare function isGanttDsl(dsl: any): dsl is DslGanttDocument;
|
|
348
|
+
/** 一次设备类型:与 ice-entity-designer 的 POWER_SYMBOL_KINDS 对齐(DSL 侧保持独立副本,
|
|
349
|
+
* 避免把渲染层依赖带进校验层;两边不一致时以 IED 为准并在 DSL 升级时同步) */
|
|
350
|
+
export declare const POWER_DSL_KINDS: readonly ["busbar", "breaker", "disconnector", "loadSwitch", "earthingSwitch", "earth", "currentTransformer", "voltageTransformer", "transformer", "fuse", "arrester", "reactor", "generator", "motor", "load", "capacitor", "arcSuppressionCoil", "threeWindingTransformer", "groundingTransformer", "groundingResistor", "cable", "cableTermination", "cubicle"];
|
|
351
|
+
export declare type PowerDslKind = (typeof POWER_DSL_KINDS)[number];
|
|
352
|
+
export declare type DslPowerNode = {
|
|
353
|
+
id: string;
|
|
354
|
+
/** 设备类型 */
|
|
355
|
+
kind: PowerDslKind;
|
|
356
|
+
/** 设备名 / 调度编号(画在符号上方) */
|
|
357
|
+
name?: string;
|
|
358
|
+
title?: string;
|
|
359
|
+
/** 电压等级:'110kV' / '10kV' …(决定色标与语义校验) */
|
|
360
|
+
voltageLevel?: string;
|
|
361
|
+
/** 挂在哪条母线上(母线 T 接;目标必须是本文件里的母线节点) */
|
|
362
|
+
attachedTo?: string;
|
|
363
|
+
/** 坐标(省略时按声明顺序给默认网格) */
|
|
364
|
+
left?: number;
|
|
365
|
+
top?: number;
|
|
366
|
+
width?: number;
|
|
367
|
+
height?: number;
|
|
368
|
+
/** 运行态:开关的分 / 合 */
|
|
369
|
+
switchState?: 'open' | 'closed';
|
|
370
|
+
/** 电源点(发电机 / 进线 / 主变电源侧) */
|
|
371
|
+
source?: boolean;
|
|
372
|
+
};
|
|
373
|
+
export declare type DslPowerEdge = {
|
|
374
|
+
id?: string;
|
|
375
|
+
source: string;
|
|
376
|
+
target: string;
|
|
377
|
+
sourcePort?: 'T' | 'R' | 'B' | 'L' | 'C';
|
|
378
|
+
targetPort?: 'T' | 'R' | 'B' | 'L' | 'C';
|
|
379
|
+
/** 导体电压等级(省略时取两端的等级) */
|
|
380
|
+
voltageLevel?: string;
|
|
381
|
+
};
|
|
382
|
+
export declare type DslPowerDocumentOptions = {
|
|
383
|
+
/** 电压等级色标覆盖 */
|
|
384
|
+
voltageColors?: Record<string, string>;
|
|
385
|
+
fitViewport?: boolean;
|
|
386
|
+
fitViewportPadding?: number;
|
|
387
|
+
};
|
|
388
|
+
export declare type DslPowerDocument = {
|
|
389
|
+
schemaVersion?: number;
|
|
390
|
+
kind: 'power';
|
|
391
|
+
nodes: DslPowerNode[];
|
|
392
|
+
edges?: DslPowerEdge[];
|
|
393
|
+
options?: DslPowerDocumentOptions;
|
|
394
|
+
};
|
|
395
|
+
/** 运行时判别:带 kind: 'power' 的按电力一次系统图文档处理 */
|
|
396
|
+
export declare function isPowerDsl(dsl: any): dsl is DslPowerDocument;
|
package/dist/types/validate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DslBpmnDocument, DslGanttDocument, DslStatechartDocument, DslUmlDocument, DslDocument, DslFlowDocument, DslValidationResult } from './types';
|
|
1
|
+
import type { DslPowerDocument, DslBpmnDocument, DslGanttDocument, DslStatechartDocument, DslUmlDocument, DslDocument, DslFlowDocument, DslValidationResult } from './types';
|
|
2
2
|
export declare const DSL_SCHEMA_VERSION = 1;
|
|
3
3
|
/**
|
|
4
4
|
* 校验一份 DSL 文档:ER(entities/relations)、流程图(kind: 'flowchart')
|
|
@@ -33,3 +33,10 @@ export declare function validateStatechartDsl(dsl: DslStatechartDocument): DslVa
|
|
|
33
33
|
* 语义检查(依赖成环等)交给 `GanttDesigner.validateGantt()`。
|
|
34
34
|
*/
|
|
35
35
|
export declare function validateGanttDsl(dsl: DslGanttDocument): DslValidationResult;
|
|
36
|
+
/**
|
|
37
|
+
* 电力一次系统图文档的结构校验(语义校验在 designer:`validatePower()`)。
|
|
38
|
+
*
|
|
39
|
+
* 这里只查「结构」:id 唯一、kind 合法、端点存在、母线 T 接指向母线、电压等级格式。
|
|
40
|
+
* 电压等级一致性、母线进线、五防这些**语义**规则属于设计器(`renderPowerDsl` 返回的 designer)。
|
|
41
|
+
*/
|
|
42
|
+
export declare function validatePowerDsl(dsl: DslPowerDocument): DslValidationResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ice-entity-designer-dsl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "A JSON-first DSL layer for AI agents to drive ice-entity-designer.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"types:check": "tsc --noEmit"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"ice-entity-designer": "^0.0.
|
|
22
|
+
"ice-entity-designer": "^0.0.40"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/core": "7.17.8",
|