ice-entity-designer-dsl 0.0.9 → 0.0.11
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 +74 -3
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/compiler/ganttToScene.d.ts +30 -0
- package/dist/types/compiler/statechartToScene.d.ts +37 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/runtime/renderDsl.d.ts +24 -2
- package/dist/types/types.d.ts +91 -2
- package/dist/types/validate.d.ts +12 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,6 +14,13 @@ One document kind, three shapes:
|
|
|
14
14
|
enums with free-text members (`- id: string`, `+ pay(): void`), plus the six relation
|
|
15
15
|
kinds (inheritance / realization / association / aggregation / composition /
|
|
16
16
|
dependency). Coordinates are optional — inheritance drives a top-down layering.
|
|
17
|
+
- **Gantt** (`kind: "gantt"` with `nodes` / `edges`): a schedule — each task carries `start`
|
|
18
|
+
(`YYYY-MM-DD`), `days` and `progress`; edges are finish-to-start dependencies. **No
|
|
19
|
+
coordinates at all**: the horizontal axis is time, the vertical axis is declaration order.
|
|
20
|
+
- **Statechart** (`kind: "statechart"` with `nodes` / `edges`): initial/final pseudo-states,
|
|
21
|
+
states, **composite states** (containers — children follow when you drag the parent) and
|
|
22
|
+
transitions labelled `event [guard] / action`. Coordinates are optional — the flow lays
|
|
23
|
+
out left to right.
|
|
17
24
|
|
|
18
25
|
The package contains:
|
|
19
26
|
|
|
@@ -22,7 +29,8 @@ The package contains:
|
|
|
22
29
|
- compilers from DSL to Entity/Relation or FlowNode/FlowEdge props (shared layered layout)
|
|
23
30
|
- browser runtime that renders DSL through `ice-entity-designer`
|
|
24
31
|
- browser examples with a JSON editor (`examples/entity-editor-dsl.html`,
|
|
25
|
-
`examples/flowchart-dsl.html`, `examples/bpmn-dsl.html`, `examples/uml-dsl.html
|
|
32
|
+
`examples/flowchart-dsl.html`, `examples/bpmn-dsl.html`, `examples/uml-dsl.html`,
|
|
33
|
+
`examples/statechart-dsl.html`, `examples/gantt-dsl.html`)
|
|
26
34
|
|
|
27
35
|
## Install
|
|
28
36
|
|
|
@@ -129,6 +137,66 @@ const xml = IED.toBpmnXml(result.designer); // BPMN 2.0 + BPMNDI(互操作格
|
|
|
129
137
|
const svg = result.designer.toSvg(); // 矢量 SVG(与画布同一口径,放大不糊)
|
|
130
138
|
```
|
|
131
139
|
|
|
140
|
+
### Gantt usage
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
const plan = {
|
|
144
|
+
schemaVersion: 1,
|
|
145
|
+
kind: 'gantt',
|
|
146
|
+
nodes: [
|
|
147
|
+
{ id: 'review', title: '需求评审', start: '2026-03-02', days: 4, progress: 1 },
|
|
148
|
+
{ id: 'design', title: '交互设计', start: '2026-03-05', days: 6, progress: 0.8 },
|
|
149
|
+
{ id: 'frontend', title: '前端开发', start: '2026-03-10', days: 12, progress: 0.35 },
|
|
150
|
+
],
|
|
151
|
+
edges: [
|
|
152
|
+
{ source: 'review', target: 'design' }, // 完成 → 开始
|
|
153
|
+
{ source: 'design', target: 'frontend' },
|
|
154
|
+
],
|
|
155
|
+
options: { dayWidth: 28, fitViewport: true },
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const result = ICEDSL.renderDsl('canvas', plan);
|
|
159
|
+
// result.kind === 'gantt'; result.designer is a GanttDesigner
|
|
160
|
+
result.designer.validateGantt(); // 依赖成环 / 进度越界 / 天数非法
|
|
161
|
+
result.designer.toSvg(); // 矢量导出(含日期刻度与进度)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Fields: `start` (`YYYY-MM-DD`, required), `days` (default 1), `progress` (0..1, default 0),
|
|
165
|
+
`row` (defaults to declaration order). **Do not invent coordinates** — the timeline is derived;
|
|
166
|
+
dragging a bar in the editor snaps it to whole days.
|
|
167
|
+
|
|
168
|
+
### Statechart usage
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
const chart = {
|
|
172
|
+
schemaVersion: 1,
|
|
173
|
+
kind: 'statechart',
|
|
174
|
+
nodes: [
|
|
175
|
+
{ id: 'start', kind: 'initial' },
|
|
176
|
+
{ id: 'pending', title: '待支付' },
|
|
177
|
+
{ id: 'paid', title: '已支付' },
|
|
178
|
+
{ id: 'processing', kind: 'composite', title: '订单处理' },
|
|
179
|
+
{ id: 'stock', title: '库存校验', parent: 'processing' }, // 子状态:进复合状态
|
|
180
|
+
{ id: 'done', kind: 'final' },
|
|
181
|
+
],
|
|
182
|
+
edges: [
|
|
183
|
+
{ source: 'start', target: 'pending' },
|
|
184
|
+
{ source: 'pending', target: 'paid', event: '支付成功', guard: '金额 > 0', action: '生成订单' },
|
|
185
|
+
{ source: 'paid', target: 'stock', event: '进入处理' },
|
|
186
|
+
{ source: 'stock', target: 'done', event: '已发货' },
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const result = ICEDSL.renderDsl('canvas', chart);
|
|
191
|
+
// result.kind === 'statechart'; result.designer is a StatechartDesigner
|
|
192
|
+
result.designer.validateStatechart(); // 缺初始状态 / 终态出边 / 孤立节点 / 不可达
|
|
193
|
+
result.designer.toSvg(); // 矢量导出(实心箭头也是填充路径)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Node kinds: `initial` (filled dot) / `final` (bullseye) / `state` (rounded box, default) /
|
|
197
|
+
`composite` (container; children declared with `parent`). Transition labels are composed
|
|
198
|
+
from `event` / `guard` / `action` (missing parts are omitted).
|
|
199
|
+
|
|
132
200
|
### UML usage
|
|
133
201
|
|
|
134
202
|
```js
|
|
@@ -169,11 +237,13 @@ intermediate / end) + `trigger`, gateways carry `gatewayType` (exclusive / paral
|
|
|
169
237
|
|
|
170
238
|
## API
|
|
171
239
|
|
|
172
|
-
- `validateDsl(dsl)` —— ER / flowchart / BPMN / UML documents (dispatches on `kind`); `validateFlowDsl(dsl)` / `validateBpmnDsl(dsl)` / `validateUmlDsl(dsl)` for one kind only
|
|
240
|
+
- `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
|
|
173
241
|
- `compileDsl(dsl)` —— ER document → `Entity` / `Relation` props
|
|
174
242
|
- `compileFlowDsl(dsl)` —— flowchart document → `FlowNode` / `FlowEdge` props (with layered auto-layout)
|
|
175
243
|
- `compileBpmnDsl(dsl)` —— BPMN document → `FlowNode` / `FlowEdge` props (container auto-geometry + container-scoped auto-layout)
|
|
176
244
|
- `compileUmlDsl(dsl)` —— UML document → `UmlClass` / `UmlRelation` props (inheritance-driven layering)
|
|
245
|
+
- `compileStatechartDsl(dsl)` —— statechart document → `StateNode` / `StateTransition` props (flow layering + composite auto-sizing)
|
|
246
|
+
- `compileGanttDsl(dsl)` —— gantt document → `GanttTask` / `GanttDependency` props (no coordinates; rows filled in)
|
|
177
247
|
- `layeredLayout(items, edges, options)` —— the shared layered layout (`direction: "vertical" | "horizontal"`)
|
|
178
248
|
- `renderDsl(canvasOrId, dsl)` —— renders any kind, returns `{ kind, ice, designer }`
|
|
179
249
|
- 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.
|
|
@@ -182,7 +252,8 @@ intermediate / end) + `trigger`, gateways carry `gatewayType` (exclusive / paral
|
|
|
182
252
|
## Example
|
|
183
253
|
|
|
184
254
|
Open `examples/entity-editor-dsl.html` (ER), `examples/flowchart-dsl.html`
|
|
185
|
-
(flowchart), `examples/bpmn-dsl.html` (BPMN)
|
|
255
|
+
(flowchart), `examples/bpmn-dsl.html` (BPMN), `examples/uml-dsl.html` (UML),
|
|
256
|
+
`examples/statechart-dsl.html` (statechart) or `examples/gantt-dsl.html` (gantt) after building.
|
|
186
257
|
|
|
187
258
|
## Agent discovery
|
|
188
259
|
|
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}const t=["terminator","process","decision","io"],i=["T","R","B","L","C"],o=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],r=["start","intermediate","end"],n=["none","message","timer","error","terminate"],s=["exclusive","parallel","inclusive","event"],a=["none","user","service","script","send","receive","manual"],l=["sequence","message","association"],d=["class","interface","enum"],p=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return 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,d=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),d.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(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${p}.${i} must be a number when present`)});[["eventKind",r],["trigger",n],["gatewayType",s],["taskType",a]].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,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const r=`nodes[${o}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(r+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(r+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(r+".parent must not reference itself");const n=d.get(e.parent);"pool"===e.kind?t.push(r+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==n?t.push(r+".parent must reference a pool"):"pool"!==n&&"lane"!==n&&t.push(r+".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 o=[];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&&o.push("Unsupported schemaVersion: "+e.schemaVersion);const r=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()?r.has(e.id)?o.push(`${n}.id is duplicated: ${e.id}`):r.add(e.id):o.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===t.indexOf(e.kind)&&o.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&&o.push(`${n}.${t} must be a number when present`)})):o.push(n+" must be an object")}):o.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()&&r.has(e.source)||o.push(n+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&r.has(e.target)||o.push(n+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&o.push(n+".label must be a string when present"),void 0!==e.sourcePort&&-1===i.indexOf(e.sourcePort)&&o.push(`${n}.sourcePort must be one of ${i.join("/")}`),void 0!==e.targetPort&&-1===i.indexOf(e.targetPort)&&o.push(`${n}.targetPort must be one of ${i.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&o.push(n+'.linkShape must be "visio" or "bezier" when present')):o.push(n+" must be an object")}):o.push("edges must be an array when present"),{valid:0===o.length,errors:o}}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===d.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${d.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===p.indexOf(n)&&t.push(`${r}.type must be one of ${p.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 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 l=new Map;e.forEach(e=>l.set(e.id,e));const d=new Map,p=new Map;e.forEach(e=>{d.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{l.has(e.sourceId)&&l.has(e.targetId)&&(d.set(e.targetId,(d.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(d.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 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 l=-(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(l)}),l+=i.height+r}),t+=e[n]+o})}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 l=-(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(l),top:Math.round(t+(e[n]-i.height)/2)}),l+=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 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||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&h[e.kind]?e.kind:"process"}(e),i=h[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 c={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},u=Number(e.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,m=Number(e.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,f=Number(e.FLOW_NODE_KINDS.bpmnLane.height)||130,g=Number(e.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(t){const i=t.kind||"task",o=function presetOf(t){return e.FLOW_NODE_KINDS[t]||e.FLOW_NODE_KINDS.bpmnTask}(c[i]||"bpmnTask"),r={id:t.id,typeId:"FlowNode",kind:c[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",l=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=>l.get(t.id)===e);let d=[];"none"!==a&&(d=buildGroups(n,o.concat(r)),layoutGroups(d,s,Number(t.gapX)||90,Number(t.gapY)||60)),r.forEach(e=>{const t=d.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),f))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+m+56,g)))}),o.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),g);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=u+t.reduce((e,t)=>e+t.height,0)))}const i=d.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),g))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+u+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+u,o=Math.max(e.height-u,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||f)),a=t.top+t.height})});let h=60;r.forEach(e=>{l.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),d.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+=u:o+=m),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}}function renderUmlDsl(t,i){const o=compileUmlDsl(i),r=o.options||{},n=(new e.ICE).init(t),s=new e.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(t,i){const o=compileBpmnDsl(i),r=o.options||{},n=(new e.ICE).init(t),s=new e.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(t,i){const o=compileFlowDsl(i),r=o.options||{},n=(new e.ICE).init(t),s=new e.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}}exports.DSL_SCHEMA_VERSION=1,exports.compileBpmnDsl=compileBpmnDsl,exports.compileDsl=compileDsl,exports.compileFlowDsl=compileFlowDsl,exports.compileUmlDsl=compileUmlDsl,exports.isBpmnDsl=isBpmnDsl,exports.isFlowDsl=isFlowDsl,exports.isUmlDsl=isUmlDsl,exports.layeredLayout=layeredLayout,exports.renderBpmnDsl=renderBpmnDsl,exports.renderDsl=function renderDsl(t,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isUmlDsl(i)?renderUmlDsl(t,i):isBpmnDsl(i)?renderBpmnDsl(t,i):isFlowDsl(i)?renderFlowDsl(t,i):function renderErDsl(t,i){const o=compileDsl(i),r=o.options||{},n=(new e.ICE).init(t),s=new e.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 e.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 l=s-r,d=a-n,p=e.canvasWidth||0,h=e.canvasHeight||0;if(!p||!h||l<=0||d<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,p-2*c),m=Math.max(1,h-2*c),f=Math.min(u/l,m/d,1),g=(p-l*f)/2-r*f,y=(h-d*f)/2-n*f;e.setViewport(f,g,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(t,i)},exports.renderFlowDsl=renderFlowDsl,exports.renderUmlDsl=renderUmlDsl,exports.validateBpmnDsl=validateBpmnDsl,exports.validateDsl=validateDsl,exports.validateFlowDsl=validateFlowDsl,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=["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})),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})}),r.edges.forEach(e=>{s.createDependency(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:"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;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FLOW_NODE_KINDS as e,ICE as t,UmlDesigner as i,BpmnDesigner as o,FlowDesigner as n,EntityDesigner as r,ICELayeredLayout as s}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}const a=1,l=["terminator","process","decision","io"],d=["T","R","B","L","C"],p=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],h=["start","intermediate","end"],c=["none","message","timer","error","terminate"],u=["exclusive","parallel","inclusive","event"],f=["none","user","service","script","send","receive","manual"],m=["sequence","message","association"],g=["class","interface","enum"],y=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return 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 n=`entities[${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"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${n}.fields[${i}].name must be a non-empty string`)}):t.push(n+".fields must be an array")):t.push(n+" 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,n)=>{const r=`nodes[${n}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"task")):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===p.indexOf(e.kind)&&t.push(`${r}.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(`${r}.${i} must be a number when present`)});[["eventKind",h],["trigger",c],["gatewayType",u],["taskType",f]].forEach(([i,o])=>{const n=e[i];void 0!==n&&-1===o.indexOf(n)&&t.push(`${r}.${i} must be one of ${o.join("/")}`)})}),e.nodes.forEach((e,n)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const r=`nodes[${n}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(r+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(r+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(r+".parent must not reference itself");const s=o.get(e.parent);"pool"===e.kind?t.push(r+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(r+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(r+".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 n=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(n+" must be an object");"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");const r=void 0!==e.type?e.type:e.flowType;void 0!==r&&-1===m.indexOf(r)&&t.push(`${n}.type must be one of ${m.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(n+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(n+'.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===l.indexOf(e.kind)&&t.push(`${n}.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(`${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,o)=>{const n=`edges[${o}]`;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===d.indexOf(e.sourcePort)&&t.push(`${n}.sourcePort must be one of ${d.join("/")}`),void 0!==e.targetPort&&-1===d.indexOf(e.targetPort)&&t.push(`${n}.targetPort must be one of ${d.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 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===g.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${g.join("/")}`),["attributes","methods"].forEach(i=>{const o=e[i];void 0!==o&&(Array.isArray(o)&&!o.some(e=>"string"!=typeof e)||t.push(`${n}.${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(`${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,o)=>{const n=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(n+" must be an object");"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");const r=void 0!==e.type?e.type:e.relation;void 0!==r&&-1===y.indexOf(r)&&t.push(`${n}.type must be one of ${y.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present")}):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,n=Number(i.gapY)||90,r=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const l=new Map;e.forEach(e=>l.set(e.id,e));const d=new Map,p=new Map;e.forEach(e=>{d.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{l.has(e.sourceId)&&l.has(e.targetId)&&(d.set(e.targetId,(d.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(d.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,r)=>{const s=f.get(i);let l=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*n)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[r]-i.width)/2),top:Math.round(l)}),l+=i.height+n}),t+=e[r]+o})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,r)=>{const s=f.get(i);let l=-(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(l),top:Math.round(t+(e[r]-i.height)/2)}),l+=i.width+o}),t+=e[r]+n})}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+=r-g,e.top+=s-y}),a}const b={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&&b[e.kind]?e.kind:"process"}(e),i=b[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"})),n=t.layout||"layered";return"none"!==n&&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 n=layeredLayout(e,t,{gapX:i,gapY:o});e.forEach(e=>{const t=n.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:n,options:t}}const w={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},v=Number(e.bpmnPool.bandSize)||32,k=Number(e.bpmnLane.bandSize)||32,x=Number(e.bpmnLane.height)||130,N=Number(e.bpmnPool.width)||900;function toWorkingNode(t){const i=t.kind||"task",o=function presetOf(t){return e[t]||e.bpmnTask}(w[i]||"bpmnTask"),n={id:t.id,typeId:"FlowNode",kind:w[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&&(n.eventKind=t.eventKind||o.eventKind||"start",n.trigger=t.trigger||o.trigger||"none"),"gateway"===i&&(n.gatewayType=t.gatewayType||o.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(n.taskType=t.taskType||o.taskType||"none"),n}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const o=1===t.length?t[0]:null,n=[];return e.forEach(e=>{(e=>{let t=n.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},n.push(t)),t})((e.parent?i.get(e.parent):void 0)||o).nodes.push(e)}),n}function layoutGroups(e,t,i,o){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const n=layeredLayout(e.nodes,t,{gapX:i,gapY:o,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=n.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,n=-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),n=Math.max(n,e.top+e.height)}),{minX:t,minY:i,maxX:o,maxY:n}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),o=i.filter(e=>"pool"===e.dslKind),n=i.filter(e=>"lane"===e.dslKind),r=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",l=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}(n,o),lanesOf=e=>n.filter(t=>l.get(t.id)===e);let d=[];"none"!==a&&(d=buildGroups(r,o.concat(n)),layoutGroups(d,s,Number(t.gapX)||90,Number(t.gapY)||60)),n.forEach(e=>{const t=d.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),x))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+k+56,N)))}),o.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),N);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=v+t.reduce((e,t)=>e+t.height,0)))}const i=d.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),N))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+v+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+v,o=Math.max(e.height-v,1),n=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),r=t.filter(e=>!e.explicitHeight),s=r.length?Math.max(o-n,0)/r.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||x)),a=t.top+t.height})});let h=60;n.forEach(e=>{l.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),d.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let o=80,n=80;i&&(o=i.left+28,n=i.top+28,"pool"===i.dslKind?n+=v:o+=k),e.nodes.forEach(e=>{e.left=Math.round(o+(e.left-t.minX)),e.top=Math.round(n+(e.top-t.minY))})});return{kind:"bpmn",nodes:o.concat(n).concat(r).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||""})),n=t.layout||"layered";if("none"!==n&&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:n,options:t}}function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),n=o.options||{},a=(new t).init(e),l=new r(a);o.entities.forEach(e=>{l.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),n=o.get(e.targetId);let r="R",s="L";if(t&&n){const e=n.center[0]-t.center[0],i=n.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(r=e>=0?"R":"L",s=e>=0?"L":"R"):(r=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:r},end:{id:e.targetId,position:s}}}})}(l,o,n.routeType).forEach(e=>{l.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new s({gapX:n.gapX||120,gapY:n.gapY||50}).layoutContainer(a);n.viewport?a.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):n.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let n=1/0,r=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();n=Math.min(n,t.minX),r=Math.min(r,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const l=s-n,d=a-r,p=e.canvasWidth||0,h=e.canvasHeight||0;if(!p||!h||l<=0||d<=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/l,f/d,1),g=(p-l*m)/2-n*m,y=(h-d*m)/2-r*m;e.setViewport(m,g,y)}(a,l,n.fitViewportPadding);return{kind:"entity",ice:a,designer:l}}(e,i)}function renderUmlDsl(e,o){const n=compileUmlDsl(o),r=n.options||{},s=(new t).init(e),a=new i(s);return n.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})}),n.edges.forEach(e=>{a.createRelation(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:"uml",ice:s,designer:a}}function renderBpmnDsl(e,i){const n=compileBpmnDsl(i),r=n.options||{},s=(new t).init(e),a=new o(s);return n.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)}),n.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||{},s=(new t).init(e),a=new n(s);return o.nodes.forEach(e=>{a.createNode(e.kind,e)}),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:"flowchart",ice:s,designer:a}}export{a as DSL_SCHEMA_VERSION,compileBpmnDsl,compileDsl,compileFlowDsl,compileUmlDsl,isBpmnDsl,isFlowDsl,isUmlDsl,layeredLayout,renderBpmnDsl,renderDsl,renderFlowDsl,renderUmlDsl,validateBpmnDsl,validateDsl,validateFlowDsl,validateUmlDsl};
|
|
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})),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})}),r.edges.forEach(e=>{a.createDependency(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:"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};
|
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}const i=["terminator","process","decision","io"],o=["T","R","B","L","C"],n=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],r=["start","intermediate","end"],s=["none","message","timer","error","terminate"],a=["exclusive","parallel","inclusive","event"],l=["none","user","service","script","send","receive","manual"],d=["sequence","message","association"],p=["class","interface","enum"],h=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return 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 n=`entities[${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"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${n}.fields[${i}].name must be a non-empty string`)}):t.push(n+".fields must be an array")):t.push(n+" 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,d)=>{const p=`nodes[${d}]`;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===n.indexOf(e.kind)&&t.push(`${p}.kind must be one of ${n.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",r],["trigger",s],["gatewayType",a],["taskType",l]].forEach(([i,o])=>{const n=e[i];void 0!==n&&-1===o.indexOf(n)&&t.push(`${p}.${i} must be one of ${o.join("/")}`)})}),e.nodes.forEach((e,n)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const r=`nodes[${n}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(r+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(r+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(r+".parent must not reference itself");const s=o.get(e.parent);"pool"===e.kind?t.push(r+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(r+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(r+".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 n=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(n+" must be an object");"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");const r=void 0!==e.type?e.type:e.flowType;void 0!==r&&-1===d.indexOf(r)&&t.push(`${n}.type must be one of ${d.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(n+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(n+'.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 n=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()?n.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):n.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===i.indexOf(e.kind)&&t.push(`${r}.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(`${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,i)=>{const r=`edges[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&n.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&n.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===o.indexOf(e.sourcePort)&&t.push(`${r}.sourcePort must be one of ${o.join("/")}`),void 0!==e.targetPort&&-1===o.indexOf(e.targetPort)&&t.push(`${r}.targetPort must be one of ${o.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 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===p.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${p.join("/")}`),["attributes","methods"].forEach(i=>{const o=e[i];void 0!==o&&(Array.isArray(o)&&!o.some(e=>"string"!=typeof e)||t.push(`${n}.${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(`${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,o)=>{const n=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(n+" must be an object");"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");const r=void 0!==e.type?e.type:e.relation;void 0!==r&&-1===h.indexOf(r)&&t.push(`${n}.type must be one of ${h.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present")}):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,n=Number(i.gapY)||90,r=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const l=new Map;e.forEach(e=>l.set(e.id,e));const d=new Map,p=new Map;e.forEach(e=>{d.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{l.has(e.sourceId)&&l.has(e.targetId)&&(d.set(e.targetId,(d.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(d.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,r)=>{const s=f.get(i);let l=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*n)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[r]-i.width)/2),top:Math.round(l)}),l+=i.height+n}),t+=e[r]+o})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,r)=>{const s=f.get(i);let l=-(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(l),top:Math.round(t+(e[r]-i.height)/2)}),l+=i.width+o}),t+=e[r]+n})}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+=r-g,e.top+=s-y}),a}const c={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&&c[e.kind]?e.kind:"process"}(e),i=c[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"})),n=t.layout||"layered";return"none"!==n&&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 n=layeredLayout(e,t,{gapX:i,gapY:o});e.forEach(e=>{const t=n.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:n,options:t}}const u={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},f=Number(t.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,m=Number(t.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,g=Number(t.FLOW_NODE_KINDS.bpmnLane.height)||130,y=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}(u[i]||"bpmnTask"),n={id:e.id,typeId:"FlowNode",kind:u[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&&(n.eventKind=e.eventKind||o.eventKind||"start",n.trigger=e.trigger||o.trigger||"none"),"gateway"===i&&(n.gatewayType=e.gatewayType||o.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(n.taskType=e.taskType||o.taskType||"none"),n}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const o=1===t.length?t[0]:null,n=[];return e.forEach(e=>{(e=>{let t=n.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},n.push(t)),t})((e.parent?i.get(e.parent):void 0)||o).nodes.push(e)}),n}function layoutGroups(e,t,i,o){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const n=layeredLayout(e.nodes,t,{gapX:i,gapY:o,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=n.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,n=-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),n=Math.max(n,e.top+e.height)}),{minX:t,minY:i,maxX:o,maxY:n}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),o=i.filter(e=>"pool"===e.dslKind),n=i.filter(e=>"lane"===e.dslKind),r=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",l=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}(n,o),lanesOf=e=>n.filter(t=>l.get(t.id)===e);let d=[];"none"!==a&&(d=buildGroups(r,o.concat(n)),layoutGroups(d,s,Number(t.gapX)||90,Number(t.gapY)||60)),n.forEach(e=>{const t=d.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)+m+56,y)))}),o.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=f+t.reduce((e,t)=>e+t.height,0)))}const i=d.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),y))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+f+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+f,o=Math.max(e.height-f,1),n=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),r=t.filter(e=>!e.explicitHeight),s=r.length?Math.max(o-n,0)/r.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;n.forEach(e=>{l.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),d.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let o=80,n=80;i&&(o=i.left+28,n=i.top+28,"pool"===i.dslKind?n+=f:o+=m),e.nodes.forEach(e=>{e.left=Math.round(o+(e.left-t.minX)),e.top=Math.round(n+(e.top-t.minY))})});return{kind:"bpmn",nodes:o.concat(n).concat(r).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||""})),n=t.layout||"layered";if("none"!==n&&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:n,options:t}}function renderUmlDsl(e,i){const o=compileUmlDsl(i),n=o.options||{},r=(new t.ICE).init(e),s=new t.UmlDesigner(r);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),n.viewport?r.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&s.fitViewport(n.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:r,designer:s}}function renderBpmnDsl(e,i){const o=compileBpmnDsl(i),n=o.options||{},r=(new t.ICE).init(e),s=new t.BpmnDesigner(r);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),n.viewport?r.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&s.fitViewport(n.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:r,designer:s}}function renderFlowDsl(e,i){const o=compileFlowDsl(i),n=o.options||{},r=(new t.ICE).init(e),s=new t.FlowDesigner(r);return o.nodes.forEach(e=>{s.createNode(e.kind,e)}),o.edges.forEach(e=>{s.createEdge(e)}),s.select(null),n.viewport?r.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&s.fitViewport(n.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:r,designer:s}}e.DSL_SCHEMA_VERSION=1,e.compileBpmnDsl=compileBpmnDsl,e.compileDsl=compileDsl,e.compileFlowDsl=compileFlowDsl,e.compileUmlDsl=compileUmlDsl,e.isBpmnDsl=isBpmnDsl,e.isFlowDsl=isFlowDsl,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 isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),n=o.options||{},r=(new t.ICE).init(e),s=new t.EntityDesigner(r);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),n=o.get(e.targetId);let r="R",s="L";if(t&&n){const e=n.center[0]-t.center[0],i=n.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(r=e>=0?"R":"L",s=e>=0?"L":"R"):(r=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:r},end:{id:e.targetId,position:s}}}})}(s,o,n.routeType).forEach(e=>{s.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new t.ICELayeredLayout({gapX:n.gapX||120,gapY:n.gapY||50}).layoutContainer(r);n.viewport?r.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):n.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let n=1/0,r=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();n=Math.min(n,t.minX),r=Math.min(r,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const l=s-n,d=a-r,p=e.canvasWidth||0,h=e.canvasHeight||0;if(!p||!h||l<=0||d<=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/l,f/d,1),g=(p-l*m)/2-n*m,y=(h-d*m)/2-r*m;e.setViewport(m,g,y)}(r,s,n.fitViewportPadding);return{kind:"entity",ice:r,designer:s}}(e,i)},e.renderFlowDsl=renderFlowDsl,e.renderUmlDsl=renderUmlDsl,e.validateBpmnDsl=validateBpmnDsl,e.validateDsl=validateDsl,e.validateFlowDsl=validateFlowDsl,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=["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})),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})}),o.edges.forEach(e=>{s.createDependency(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:"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})}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DslGanttDocument } from '../types';
|
|
2
|
+
export declare type CompiledGanttTask = {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
start: string;
|
|
6
|
+
days: number;
|
|
7
|
+
progress: number;
|
|
8
|
+
row: number;
|
|
9
|
+
};
|
|
10
|
+
export declare type CompiledGanttDependency = {
|
|
11
|
+
id: string;
|
|
12
|
+
sourceId: string;
|
|
13
|
+
targetId: string;
|
|
14
|
+
};
|
|
15
|
+
export declare type CompiledGanttScene = {
|
|
16
|
+
kind: 'gantt';
|
|
17
|
+
nodes: CompiledGanttTask[];
|
|
18
|
+
edges: CompiledGanttDependency[];
|
|
19
|
+
options?: Record<string, any>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 甘特文档 → `GanttTask` / `GanttDependency` 构造参数。
|
|
23
|
+
*
|
|
24
|
+
* 与其它文档类型不同,这里**没有几何布局**:横轴是时间(`start` × `days`),
|
|
25
|
+
* 纵轴是行(`row` 或声明顺序)。任务条的位置完全由设计器按 `dayWidth` 与项目起点算出来,
|
|
26
|
+
* 所以文档里不需要(也不应该)写坐标 —— 手写坐标反而会与日期打架。
|
|
27
|
+
*
|
|
28
|
+
* 唯一做的“归一化”是把行号补全(缺省按声明顺序),以及把缺省值补齐。
|
|
29
|
+
*/
|
|
30
|
+
export declare function compileGanttDsl(dsl: DslGanttDocument): CompiledGanttScene;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DslStatechartDocument, DslStatechartNodeKind } from '../types';
|
|
2
|
+
export declare type CompiledStatechartNode = {
|
|
3
|
+
id: string;
|
|
4
|
+
kind: DslStatechartNodeKind;
|
|
5
|
+
title: string;
|
|
6
|
+
parent?: string;
|
|
7
|
+
left: number;
|
|
8
|
+
top: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
export declare type CompiledStatechartEdge = {
|
|
13
|
+
id: string;
|
|
14
|
+
sourceId: string;
|
|
15
|
+
targetId: string;
|
|
16
|
+
event: string;
|
|
17
|
+
guard: string;
|
|
18
|
+
action: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare type CompiledStatechartScene = {
|
|
22
|
+
kind: 'statechart';
|
|
23
|
+
nodes: CompiledStatechartNode[];
|
|
24
|
+
edges: CompiledStatechartEdge[];
|
|
25
|
+
layout: string;
|
|
26
|
+
options?: Record<string, any>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* 状态机 DSL → `StateNode` / `StateTransition` 构造参数。
|
|
30
|
+
*
|
|
31
|
+
* 自动排布分两层(与 BPMN 的池/泳道同思路):
|
|
32
|
+
* 1. **根级节点**按转移流做横向分层(状态机读起来自左而右);
|
|
33
|
+
* 2. **子状态**留在所属复合状态里,按简单流式(左→右、超宽换行)落位,复合状态按内容自适应尺寸。
|
|
34
|
+
*
|
|
35
|
+
* 只要给了坐标(编辑器导出)编译过程就是恒等的。
|
|
36
|
+
*/
|
|
37
|
+
export declare function compileStatechartDsl(dsl: DslStatechartDocument): CompiledStatechartScene;
|
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 } from './validate';
|
|
2
|
+
export { DSL_SCHEMA_VERSION, validateDsl, validateFlowDsl, validateBpmnDsl, validateUmlDsl, validateStatechartDsl, validateGanttDsl, } from './validate';
|
|
3
3
|
export { compileDsl } from './compiler/dslToScene';
|
|
4
4
|
export type { CompiledScene } from './compiler/dslToScene';
|
|
5
5
|
export { compileFlowDsl } from './compiler/flowToScene';
|
|
@@ -10,5 +10,9 @@ export { layeredLayout } from './compiler/layout';
|
|
|
10
10
|
export type { LayoutItem, LayoutEdge, LayoutOptions } from './compiler/layout';
|
|
11
11
|
export { compileUmlDsl } from './compiler/umlToScene';
|
|
12
12
|
export type { CompiledUmlScene, CompiledUmlNode, CompiledUmlEdge } from './compiler/umlToScene';
|
|
13
|
-
export {
|
|
14
|
-
export type {
|
|
13
|
+
export { compileStatechartDsl } from './compiler/statechartToScene';
|
|
14
|
+
export type { CompiledStatechartScene, CompiledStatechartNode, CompiledStatechartEdge } from './compiler/statechartToScene';
|
|
15
|
+
export { compileGanttDsl } from './compiler/ganttToScene';
|
|
16
|
+
export type { CompiledGanttScene, CompiledGanttTask, CompiledGanttDependency } from './compiler/ganttToScene';
|
|
17
|
+
export { renderDsl, renderFlowDsl, renderBpmnDsl, renderUmlDsl, renderStatechartDsl, renderGanttDsl } from './runtime/renderDsl';
|
|
18
|
+
export type { RenderDslResult, RenderErDslResult, RenderFlowDslResult, RenderBpmnDslResult, RenderUmlDslResult, RenderStatechartDslResult, RenderGanttDslResult, } from './runtime/renderDsl';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DslBpmnDocument, DslDocument, DslFlowDocument, DslUmlDocument } from '../types';
|
|
1
|
+
import type { DslBpmnDocument, DslGanttDocument, DslDocument, DslFlowDocument, DslStatechartDocument, DslUmlDocument } from '../types';
|
|
2
2
|
export declare type RenderErDslResult = {
|
|
3
3
|
kind: 'entity';
|
|
4
4
|
ice: any;
|
|
@@ -19,7 +19,17 @@ export declare type RenderUmlDslResult = {
|
|
|
19
19
|
ice: any;
|
|
20
20
|
designer: any;
|
|
21
21
|
};
|
|
22
|
-
export declare type
|
|
22
|
+
export declare type RenderGanttDslResult = {
|
|
23
|
+
kind: 'gantt';
|
|
24
|
+
ice: any;
|
|
25
|
+
designer: any;
|
|
26
|
+
};
|
|
27
|
+
export declare type RenderStatechartDslResult = {
|
|
28
|
+
kind: 'statechart';
|
|
29
|
+
ice: any;
|
|
30
|
+
designer: any;
|
|
31
|
+
};
|
|
32
|
+
export declare type RenderDslResult = RenderErDslResult | RenderFlowDslResult | RenderBpmnDslResult | RenderUmlDslResult | RenderStatechartDslResult | RenderGanttDslResult;
|
|
23
33
|
/**
|
|
24
34
|
* 渲染一份 DSL 文档:ER 文档(entities/relations)或流程图文档(kind: 'flowchart')。
|
|
25
35
|
*
|
|
@@ -27,6 +37,18 @@ export declare type RenderDslResult = RenderErDslResult | RenderFlowDslResult |
|
|
|
27
37
|
* `designer` 分别是 `EntityDesigner` / `FlowDesigner` 实例。
|
|
28
38
|
*/
|
|
29
39
|
export declare function renderDsl(canvasOrId: any, dsl: DslDocument): RenderDslResult;
|
|
40
|
+
/**
|
|
41
|
+
* 渲染甘特文档:任务条的位置由「起始日期 × 每日像素」算出(文档里不写坐标)。
|
|
42
|
+
*
|
|
43
|
+
* 语义校验用 `designer.validateGantt()`;矢量导出用 `designer.toSvg()`。
|
|
44
|
+
*/
|
|
45
|
+
export declare function renderGanttDsl(canvasOrId: any, dsl: DslGanttDocument): RenderGanttDslResult;
|
|
46
|
+
/**
|
|
47
|
+
* 渲染状态机文档:伪状态 / 状态 / 复合状态(容器)+ 转移。
|
|
48
|
+
*
|
|
49
|
+
* 语义校验用 `designer.validateStatechart()`;矢量导出用 `designer.toSvg()`。
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderStatechartDsl(canvasOrId: any, dsl: DslStatechartDocument): RenderStatechartDslResult;
|
|
30
52
|
/**
|
|
31
53
|
* 渲染 UML 类图文档:类是复合组件(成员由 state 派生),关系是六种记法之一。
|
|
32
54
|
*
|
package/dist/types/types.d.ts
CHANGED
|
@@ -189,8 +189,8 @@ export declare type DslBpmnDocument = {
|
|
|
189
189
|
edges?: DslBpmnEdge[];
|
|
190
190
|
options?: DslBpmnDocumentOptions;
|
|
191
191
|
};
|
|
192
|
-
/** 一份 DSL 文档:ER
|
|
193
|
-
export declare type DslDocument = DslErDocument | DslFlowDocument | DslBpmnDocument | DslUmlDocument;
|
|
192
|
+
/** 一份 DSL 文档:ER(默认)、流程图、BPMN、UML 或 状态机 */
|
|
193
|
+
export declare type DslDocument = DslErDocument | DslFlowDocument | DslBpmnDocument | DslUmlDocument | DslStatechartDocument | DslGanttDocument;
|
|
194
194
|
export declare type DslValidationResult = {
|
|
195
195
|
valid: boolean;
|
|
196
196
|
errors: string[];
|
|
@@ -252,3 +252,92 @@ export declare type DslUmlDocument = {
|
|
|
252
252
|
};
|
|
253
253
|
/** 运行时判别:带 kind: 'uml' 的按类图文档处理 */
|
|
254
254
|
export declare function isUmlDsl(dsl: any): dsl is DslUmlDocument;
|
|
255
|
+
export declare type DslStatechartNodeKind = 'initial' | 'final' | 'state' | 'composite';
|
|
256
|
+
export declare type DslStatechartNode = {
|
|
257
|
+
id: string;
|
|
258
|
+
/** 节点类型,默认 state */
|
|
259
|
+
kind?: DslStatechartNodeKind;
|
|
260
|
+
/** 状态名(title / name 二者取一) */
|
|
261
|
+
title?: string;
|
|
262
|
+
name?: string;
|
|
263
|
+
/** 归属容器:子状态写所属复合状态的 id;缺省时按坐标自动嵌套 */
|
|
264
|
+
parent?: string;
|
|
265
|
+
left?: number;
|
|
266
|
+
top?: number;
|
|
267
|
+
width?: number;
|
|
268
|
+
height?: number;
|
|
269
|
+
};
|
|
270
|
+
export declare type DslStatechartEdge = {
|
|
271
|
+
id?: string;
|
|
272
|
+
source: string;
|
|
273
|
+
target: string;
|
|
274
|
+
/** 触发事件 */
|
|
275
|
+
event?: string;
|
|
276
|
+
/** 守卫条件(画成 `[guard]`) */
|
|
277
|
+
guard?: string;
|
|
278
|
+
/** 动作(画成 `/ action`) */
|
|
279
|
+
action?: string;
|
|
280
|
+
/** 显式标签(给了就不由 event/guard/action 拼) */
|
|
281
|
+
label?: string;
|
|
282
|
+
};
|
|
283
|
+
export declare type DslStatechartDocumentOptions = {
|
|
284
|
+
fitViewport?: boolean;
|
|
285
|
+
fitViewportPadding?: number;
|
|
286
|
+
viewport?: {
|
|
287
|
+
scale: number;
|
|
288
|
+
tx: number;
|
|
289
|
+
ty: number;
|
|
290
|
+
};
|
|
291
|
+
/** 缺坐标时是否自动排布(转移流向自左而右),默认 auto */
|
|
292
|
+
layout?: 'auto' | 'none';
|
|
293
|
+
gapX?: number;
|
|
294
|
+
gapY?: number;
|
|
295
|
+
};
|
|
296
|
+
export declare type DslStatechartDocument = {
|
|
297
|
+
schemaVersion?: number;
|
|
298
|
+
kind: 'statechart';
|
|
299
|
+
nodes: DslStatechartNode[];
|
|
300
|
+
edges?: DslStatechartEdge[];
|
|
301
|
+
options?: DslStatechartDocumentOptions;
|
|
302
|
+
};
|
|
303
|
+
/** 运行时判别:带 kind: 'statechart' 的按状态机文档处理 */
|
|
304
|
+
export declare function isStatechartDsl(dsl: any): dsl is DslStatechartDocument;
|
|
305
|
+
export declare type DslGanttTask = {
|
|
306
|
+
id: string;
|
|
307
|
+
/** 任务名(title / name 二者取一) */
|
|
308
|
+
title?: string;
|
|
309
|
+
name?: string;
|
|
310
|
+
/** 起始日期 `YYYY-MM-DD` */
|
|
311
|
+
start: string;
|
|
312
|
+
/** 持续天数,默认 1 */
|
|
313
|
+
days?: number;
|
|
314
|
+
/** 完成度 0..1,默认 0 */
|
|
315
|
+
progress?: number;
|
|
316
|
+
/** 行号(0 起);缺省按声明顺序 */
|
|
317
|
+
row?: number;
|
|
318
|
+
};
|
|
319
|
+
export declare type DslGanttDependency = {
|
|
320
|
+
id?: string;
|
|
321
|
+
source: string;
|
|
322
|
+
target: string;
|
|
323
|
+
};
|
|
324
|
+
export declare type DslGanttDocumentOptions = {
|
|
325
|
+
fitViewport?: boolean;
|
|
326
|
+
fitViewportPadding?: number;
|
|
327
|
+
viewport?: {
|
|
328
|
+
scale: number;
|
|
329
|
+
tx: number;
|
|
330
|
+
ty: number;
|
|
331
|
+
};
|
|
332
|
+
/** 每天多少像素,默认 28 */
|
|
333
|
+
dayWidth?: number;
|
|
334
|
+
};
|
|
335
|
+
export declare type DslGanttDocument = {
|
|
336
|
+
schemaVersion?: number;
|
|
337
|
+
kind: 'gantt';
|
|
338
|
+
nodes: DslGanttTask[];
|
|
339
|
+
edges?: DslGanttDependency[];
|
|
340
|
+
options?: DslGanttDocumentOptions;
|
|
341
|
+
};
|
|
342
|
+
/** 运行时判别:带 kind: 'gantt' 的按甘特文档处理 */
|
|
343
|
+
export declare function isGanttDsl(dsl: any): dsl is DslGanttDocument;
|
package/dist/types/validate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DslBpmnDocument, DslUmlDocument, DslDocument, DslFlowDocument, DslValidationResult } from './types';
|
|
1
|
+
import type { 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')
|
|
@@ -22,3 +22,14 @@ export declare function validateFlowDsl(dsl: DslFlowDocument): DslValidationResu
|
|
|
22
22
|
* 结构在 DSL 侧、语义在设计师侧,不重复实现。
|
|
23
23
|
*/
|
|
24
24
|
export declare function validateUmlDsl(dsl: DslUmlDocument): DslValidationResult;
|
|
25
|
+
/**
|
|
26
|
+
* 状态机文档校验:结构 + 词汇表 + 端点存在 + parent 合法性(子状态只能挂复合状态)。
|
|
27
|
+
* 语义检查(初始状态、终态出边、可达性)交给 `StatechartDesigner.validateStatechart()`。
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateStatechartDsl(dsl: DslStatechartDocument): DslValidationResult;
|
|
30
|
+
/**
|
|
31
|
+
* 甘特文档校验:结构 + 日期格式 + 数值范围 + 依赖端点。
|
|
32
|
+
*
|
|
33
|
+
* 语义检查(依赖成环等)交给 `GanttDesigner.validateGantt()`。
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateGanttDsl(dsl: DslGanttDocument): 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.11",
|
|
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.26"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/core": "7.17.8",
|