ice-entity-designer-dsl 0.0.13 → 0.0.15
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 +9 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/compiler/powerToScene.d.ts +34 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/runtime/renderDsl.d.ts +9 -1
- package/dist/types/types.d.ts +49 -0
- package/dist/types/validate.d.ts +8 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -28,9 +28,16 @@ The package contains:
|
|
|
28
28
|
- structural validator
|
|
29
29
|
- compilers from DSL to Entity/Relation or FlowNode/FlowEdge props (shared layered layout)
|
|
30
30
|
- browser runtime that renders DSL through `ice-entity-designer`
|
|
31
|
+
- power documents (`kind: 'power'`): one-line diagrams — equipment types mirror `ice-entity-designer`'s
|
|
32
|
+
power pack, `attachedTo` expresses busbar T-connection, `voltageLevel` drives the colour code;
|
|
33
|
+
semantic checks (voltage consistency / busbar feed / 五防) live in `result.designer.validatePower()`
|
|
31
34
|
- browser examples with a JSON editor (`examples/entity-editor-dsl.html`,
|
|
32
35
|
`examples/flowchart-dsl.html`, `examples/bpmn-dsl.html`, `examples/uml-dsl.html`,
|
|
33
|
-
`examples/statechart-dsl.html`, `examples/gantt-dsl.html`)
|
|
36
|
+
`examples/statechart-dsl.html`, `examples/gantt-dsl.html`, `examples/power-dsl.html`)
|
|
37
|
+
- the four new diagram examples (BPMN / UML / statechart / gantt) share
|
|
38
|
+
`examples/canvas-interactions.js`: canvas fills the preview pane, wheel zooms at the
|
|
39
|
+
cursor (`ICE.zoomAt`), dragging blank space (or any middle-button drag) pans, plus
|
|
40
|
+
「适应视图 / 复位视图」 buttons
|
|
34
41
|
|
|
35
42
|
## Install
|
|
36
43
|
|
|
@@ -261,6 +268,7 @@ intermediate / end) + `trigger`, gateways carry `gatewayType` (exclusive / paral
|
|
|
261
268
|
Open `examples/entity-editor-dsl.html` (ER), `examples/flowchart-dsl.html`
|
|
262
269
|
(flowchart), `examples/bpmn-dsl.html` (BPMN), `examples/uml-dsl.html` (UML),
|
|
263
270
|
`examples/statechart-dsl.html` (statechart) or `examples/gantt-dsl.html` (gantt) after building.
|
|
271
|
+
渲染结果可以滚轮缩放、空白处拖拽平移,工具栏还有「适应视图 / 复位视图」。
|
|
264
272
|
|
|
265
273
|
## Agent discovery
|
|
266
274
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("ice-entity-designer");function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const t=["terminator","process","decision","io"],i=["T","R","B","L","C"],r=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],o=["start","intermediate","end"],n=["none","message","timer","error","terminate"],s=["exclusive","parallel","inclusive","event"],a=["none","user","service","script","send","receive","manual"],d=["sequence","message","association"],p=["initial","final","state","composite"],l=["class","interface","enum"],h=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,r)=>{const o=`entities[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${o}.fields[${i}].name must be a non-empty string`)}):t.push(o+".fields must be an array")):t.push(o+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const r=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(r+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(r+".target must be a non-empty string")):t.push(r+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,p=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,d)=>{const l=`nodes[${d}]`;if(!e||"object"!=typeof e)return void t.push(l+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${l}.id is duplicated: ${e.id}`):(i.add(e.id),p.set(e.id,e.kind||"task")):t.push(l+".id must be a non-empty string"),void 0!==e.kind&&-1===r.indexOf(e.kind)&&t.push(`${l}.kind must be one of ${r.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${l}.${i} must be a number when present`)});[["eventKind",o],["trigger",n],["gatewayType",s],["taskType",a]].forEach(([i,r])=>{const o=e[i];void 0!==o&&-1===r.indexOf(o)&&t.push(`${l}.${i} must be one of ${r.join("/")}`)})}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const o=`nodes[${r}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(o+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(o+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(o+".parent must not reference itself");const n=p.get(e.parent);"pool"===e.kind?t.push(o+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==n?t.push(o+".parent must reference a pool"):"pool"!==n&&"lane"!==n&&t.push(o+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===d.indexOf(n)&&t.push(`${o}.type must be one of ${d.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(o+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(o+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const r=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&r.push("Unsupported schemaVersion: "+e.schemaVersion);const o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const n=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?r.push(`${n}.id is duplicated: ${e.id}`):o.add(e.id):r.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===t.indexOf(e.kind)&&r.push(`${n}.kind must be one of ${t.join("/")}`),["left","top","width","height"].forEach(t=>{const i=e[t];void 0!==i&&"number"!=typeof i&&r.push(`${n}.${t} must be a number when present`)})):r.push(n+" must be an object")}):r.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,t)=>{const n=`edges[${t}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&o.has(e.source)||r.push(n+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||r.push(n+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&r.push(n+".label must be a string when present"),void 0!==e.sourcePort&&-1===i.indexOf(e.sourcePort)&&r.push(`${n}.sourcePort must be one of ${i.join("/")}`),void 0!==e.targetPort&&-1===i.indexOf(e.targetPort)&&r.push(`${n}.targetPort must be one of ${i.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&r.push(n+'.linkShape must be "visio" or "bezier" when present')):r.push(n+" must be an object")}):r.push("edges must be an array when present"),{valid:0===r.length,errors:r}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),void 0!==e.kind&&-1===l.indexOf(e.kind)&&t.push(`${o}.kind must be one of ${l.join("/")}`),["attributes","methods"].forEach(i=>{const r=e[i];void 0!==r&&(Array.isArray(r)&&!r.some(e=>"string"!=typeof e)||t.push(`${o}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${o}.${i} must be a number when present`)})):t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(o+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===h.indexOf(n)&&t.push(`${o}.type must be one of ${h.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(o+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,r=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),r.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===p.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${p.join("/")}`),["left","top","width","height"].forEach(i=>{const r=e[i];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,o)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${o}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==r.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const r=e[i];void 0!==r&&"string"!=typeof r&&t.push(`${o}.${i} must be a string when present`)})):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const o=`nodes[${r}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${o}.id is duplicated: ${e.id}`):i.add(e.id):t.push(o+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(o+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(o+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(o+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(o+".row must be a number >= 0 when present")}else t.push(o+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const o=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(o+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(o+".target must reference an existing task id")):t.push(o+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const r=Number(i.gapX)||90,o=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const p=new Map,l=new Map;e.forEach(e=>{p.set(e.id,0),l.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(p.set(e.targetId,(p.get(e.targetId)||0)+1),l.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(p.get(e.id)||0)&&(h.set(e.id,0),c.push(e.id))}),c.length||(h.set(e[0].id,0),c.push(e[0].id));let u=e.length*e.length+e.length;for(;c.length&&u-- >0;){const e=c.shift(),t=h.get(e)||0;(l.get(e)||[]).forEach(e=>{const i=t+1;(void 0===h.get(e)?-1:h.get(e))<i&&(h.set(e,i),c.push(e))})}e.forEach(e=>{h.has(e.id)||h.set(e.id,0)});const m=new Map;e.forEach(e=>{const t=h.get(e.id)||0;m.has(t)||m.set(t,[]),m.get(t).push(e)});const f=[...m.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=f.map(e=>Math.max(...m.get(e).map(e=>e.width)));let t=0;f.forEach((i,n)=>{const s=m.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+o}),t+=e[n]+r})}else{const e=f.map(e=>Math.max(...m.get(e).map(e=>e.height)));let t=0;f.forEach((i,n)=>{const s=m.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+r}),t+=e[n]+o})}const g=Math.min(...e.map(e=>a.get(e.id).left)),y=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-y}),a}const c={terminator:{width:e.FLOW_NODE_KINDS.terminator.width,height:e.FLOW_NODE_KINDS.terminator.height,fill:e.FLOW_NODE_KINDS.terminator.fill,stroke:e.FLOW_NODE_KINDS.terminator.stroke},process:{width:e.FLOW_NODE_KINDS.process.width,height:e.FLOW_NODE_KINDS.process.height,fill:e.FLOW_NODE_KINDS.process.fill,stroke:e.FLOW_NODE_KINDS.process.stroke},decision:{width:e.FLOW_NODE_KINDS.decision.width,height:e.FLOW_NODE_KINDS.decision.height,fill:e.FLOW_NODE_KINDS.decision.fill,stroke:e.FLOW_NODE_KINDS.decision.stroke},io:{width:e.FLOW_NODE_KINDS.io.width,height:e.FLOW_NODE_KINDS.io.height,fill:e.FLOW_NODE_KINDS.io.fill,stroke:e.FLOW_NODE_KINDS.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&c[e.kind]?e.kind:"process"}(e),i=c[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(r=e,r.title||r.name||r.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var r}),r=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),o=t.layout||"layered";return"none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,r){const o=layeredLayout(e,t,{gapX:i,gapY:r});e.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,r,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:r,layout:o,options:t}}const u={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},m=Number(e.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,f=Number(e.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,g=Number(e.FLOW_NODE_KINDS.bpmnLane.height)||130,y=Number(e.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(t){const i=t.kind||"task",r=function presetOf(t){return e.FLOW_NODE_KINDS[t]||e.FLOW_NODE_KINDS.bpmnTask}(u[i]||"bpmnTask"),o={id:t.id,typeId:"FlowNode",kind:u[i]||"bpmnTask",title:t.title||t.name||t.id,left:"number"==typeof t.left?t.left:0,top:"number"==typeof t.top?t.top:0,width:"number"==typeof t.width?t.width:r.width,height:"number"==typeof t.height?t.height:r.height,fillColor:t.fillColor,strokeColor:t.strokeColor,dslKind:i,parent:t.parent,explicitLeft:"number"==typeof t.left,explicitTop:"number"==typeof t.top,explicitWidth:"number"==typeof t.width,explicitHeight:"number"==typeof t.height};return"event"===i&&(o.eventKind=t.eventKind||r.eventKind||"start",o.trigger=t.trigger||r.trigger||"none"),"gateway"===i&&(o.gatewayType=t.gatewayType||r.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(o.taskType=t.taskType||r.taskType||"none"),o}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const r=1===t.length?t[0]:null,o=[];return e.forEach(e=>{(e=>{let t=o.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},o.push(t)),t})((e.parent?i.get(e.parent):void 0)||r).nodes.push(e)}),o}function layoutGroups(e,t,i,r){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const o=layeredLayout(e.nodes,t,{gapX:i,gapY:r,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=o.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,r=-1/0,o=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),r=Math.max(r,e.left+e.width),o=Math.max(o,e.top+e.height)}),{minX:t,minY:i,maxX:r,maxY:o}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),r=i.filter(e=>"pool"===e.dslKind),o=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let r=e.parent;r||1!==t.length||(r=t[0].id),r&&i.set(e.id,r)}),i}(o,r),lanesOf=e=>o.filter(t=>d.get(t.id)===e);let p=[];"none"!==a&&(p=buildGroups(n,r.concat(o)),layoutGroups(p,s,Number(t.gapX)||90,Number(t.gapY)||60)),o.forEach(e=>{const t=p.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),g))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+f+56,y)))}),r.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),y);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=m+t.reduce((e,t)=>e+t.height,0)))}const i=p.filter(t=>t.owner===e)[0],r=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(r?r.maxX-r.minX:0),y))),e.explicitHeight||(e.height=Math.round(Math.max((r?r.maxY-r.minY:0)+m+56,160)))});let l=60;r.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=l),l=Math.max(l,e.top+e.height+60)}),r.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+m,r=Math.max(e.height-m,1),o=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(r-o,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||g)),a=t.top+t.height})});let h=60;o.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),p.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let r=80,o=80;i&&(r=i.left+28,o=i.top+28,"pool"===i.dslKind?o+=m:r+=f),e.nodes.forEach(e=>{e.left=Math.round(r+(e.left-t.minX)),e.top=Math.round(o+(e.top-t.minY))})});return{kind:"bpmn",nodes:r.concat(o).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),r=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),o=t.layout||"layered";if("none"!==o&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,r.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:r,layout:o,options:t}}const b={width:160,height:64},w={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,r="composite"===t?w:i?{width:24,height:24}:b;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:r.width,height:"number"==typeof e.height?e.height:r.height}}),r=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),o=t.layout||"auto",n=new Set;if("none"!==o){const e=new Map;i.forEach(t=>e.set(t.id,t));const o=i.filter(t=>!(t.parent&&e.has(t.parent)));if(o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=r.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(o,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});o.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...o.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let r=56,a=56,d=0,p=56;const l=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(r>56&&r+e.width>56+l&&(r=56,a=p+40),n.add(e.id),e.left=r,e.top=a,r+=e.width+40,d=Math.max(d,r),p=Math.max(p,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,p+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,r)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=r,offsetChildren(e,t,r))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:r,layout:o,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderGanttDsl(t,i){const r=compileGanttDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.GanttDesigner(n);return o.dayWidth&&s.setDayWidth(o.dayWidth),r.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),r.edges.forEach(e=>{s.createDependency(e)}),s.select(null),o.autoSchedule&&s.autoSchedule(),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderStatechartDsl(t,i){const r=compileStatechartDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.StatechartDesigner(n);return r.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{s.createTransition(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"statechart",ice:n,designer:s}}function renderUmlDsl(t,i){const r=compileUmlDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.UmlDesigner(n);return r.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),r.edges.forEach(e=>{s.createRelation(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:n,designer:s}}function renderBpmnDsl(t,i){const r=compileBpmnDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.BpmnDesigner(n);return r.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),s.createNode(e.kind,t)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:n,designer:s}}function renderFlowDsl(t,i){const r=compileFlowDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.FlowDesigner(n);return r.nodes.forEach(e=>{s.createNode(e.kind,e)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:n,designer:s}}exports.DSL_SCHEMA_VERSION=1,exports.compileBpmnDsl=compileBpmnDsl,exports.compileDsl=compileDsl,exports.compileFlowDsl=compileFlowDsl,exports.compileGanttDsl=compileGanttDsl,exports.compileStatechartDsl=compileStatechartDsl,exports.compileUmlDsl=compileUmlDsl,exports.isBpmnDsl=isBpmnDsl,exports.isFlowDsl=isFlowDsl,exports.isGanttDsl=isGanttDsl,exports.isStatechartDsl=isStatechartDsl,exports.isUmlDsl=isUmlDsl,exports.layeredLayout=layeredLayout,exports.renderBpmnDsl=renderBpmnDsl,exports.renderDsl=function renderDsl(t,i){const r=validateDsl(i);if(!r.valid)throw new Error(r.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(t,i):isStatechartDsl(i)?renderStatechartDsl(t,i):isUmlDsl(i)?renderUmlDsl(t,i):isBpmnDsl(i)?renderBpmnDsl(t,i):isFlowDsl(i)?renderFlowDsl(t,i):function renderErDsl(t,i){const r=compileDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.EntityDesigner(n);r.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const r=new Map;return e.entities.forEach(e=>{r.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=r.get(e.sourceId),o=r.get(e.targetId);let n="R",s="L";if(t&&o){const e=o.center[0]-t.center[0],i=o.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,r,o.routeType).forEach(e=>{s.createRelation(e)}),("layered"===r.layout||"horizontal"===r.layout)&&new e.ICELayeredLayout({gapX:o.gapX||120,gapY:o.gapY||50}).layoutContainer(n);o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):o.fitViewport&&function fitViewport(e,t,i){const r=t.entities||[];let o=1/0,n=1/0,s=-1/0,a=-1/0;r.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();o=Math.min(o,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-o,p=a-n,l=e.canvasWidth||0,h=e.canvasHeight||0;if(!l||!h||d<=0||p<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,l-2*c),m=Math.max(1,h-2*c),f=Math.min(u/d,m/p,1),g=(l-d*f)/2-o*f,y=(h-p*f)/2-n*f;e.setViewport(f,g,y)}(n,s,o.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(t,i)},exports.renderFlowDsl=renderFlowDsl,exports.renderGanttDsl=renderGanttDsl,exports.renderStatechartDsl=renderStatechartDsl,exports.renderUmlDsl=renderUmlDsl,exports.validateBpmnDsl=validateBpmnDsl,exports.validateDsl=validateDsl,exports.validateFlowDsl=validateFlowDsl,exports.validateGanttDsl=validateGanttDsl,exports.validateStatechartDsl=validateStatechartDsl,exports.validateUmlDsl=validateUmlDsl;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("ice-entity-designer");function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const t=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"];function isPowerDsl(e){return!!e&&"object"==typeof e&&"power"===e.kind}const o=["terminator","process","decision","io"],r=["T","R","B","L","C"],i=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],n=["start","intermediate","end"],s=["none","message","timer","error","terminate"],a=["exclusive","parallel","inclusive","event"],d=["none","user","service","script","send","receive","manual"],l=["sequence","message","association"],p=["initial","final","state","composite"],c=["class","interface","enum"],h=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isPowerDsl(e)?validatePowerDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const o=new Set;e.entities.forEach((e,r)=>{const i=`entities[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${i}.id is duplicated: ${e.id}`):o.add(e.id):t.push(i+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,o)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${i}.fields[${o}].name must be a non-empty string`)}):t.push(i+".fields must be an array")):t.push(i+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,o)=>{const r=`relations[${o}]`;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 o=new Set,r=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()?o.has(e.id)?t.push(`${p}.id is duplicated: ${e.id}`):(o.add(e.id),r.set(e.id,e.kind||"task")):t.push(p+".id must be a non-empty string"),void 0!==e.kind&&-1===i.indexOf(e.kind)&&t.push(`${p}.kind must be one of ${i.join("/")}`),["left","top","width","height"].forEach(o=>{const r=e[o];void 0!==r&&"number"!=typeof r&&t.push(`${p}.${o} must be a number when present`)});[["eventKind",n],["trigger",s],["gatewayType",a],["taskType",d]].forEach(([o,r])=>{const i=e[o];void 0!==i&&-1===r.indexOf(i)&&t.push(`${p}.${o} must be one of ${r.join("/")}`)})}),e.nodes.forEach((e,i)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${i}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!o.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=r.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,r)=>{const i=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(i+" must be an object");"string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(i+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||t.push(i+".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(`${i}.type must be one of ${l.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(i+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(i+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(i+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const 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):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===o.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${o.join("/")}`),["left","top","width","height"].forEach(o=>{const r=e[o];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${o} 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===r.indexOf(e.sourcePort)&&t.push(`${n}.sourcePort must be one of ${r.join("/")}`),void 0!==e.targetPort&&-1===r.indexOf(e.targetPort)&&t.push(`${n}.targetPort must be one of ${r.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 o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const i=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${i}.id is duplicated: ${e.id}`):o.add(e.id):t.push(i+".id must be a non-empty string"),void 0!==e.kind&&-1===c.indexOf(e.kind)&&t.push(`${i}.kind must be one of ${c.join("/")}`),["attributes","methods"].forEach(o=>{const r=e[o];void 0!==r&&(Array.isArray(r)&&!r.some(e=>"string"!=typeof e)||t.push(`${i}.${o} must be an array of strings when present`))}),["left","top","width","height"].forEach(o=>{const r=e[o];void 0!==r&&"number"!=typeof r&&t.push(`${i}.${o} must be a number when present`)})):t.push(i+" 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 i=`edges[${r}]`;if(!e||"object"!=typeof e)return void t.push(i+" must be an object");"string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(i+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||t.push(i+".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(`${i}.type must be one of ${h.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(i+".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 o=new Set,r=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,i)=>{const n=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(o.add(e.id),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(o=>{const r=e[o];void 0!==r&&"number"!=typeof r&&t.push(`${n}.${o} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,i)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${i}]`;"string"==typeof e.parent&&e.parent.trim()&&o.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 i=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(i+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||t.push(i+".target must reference an existing node id"),["event","guard","action","label"].forEach(o=>{const r=e[o];void 0!==r&&"string"!=typeof r&&t.push(`${i}.${o} must be a string when present`)})):t.push(i+" 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 o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,r)=>{const i=`nodes[${r}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${i}.id is duplicated: ${e.id}`):o.add(e.id):t.push(i+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(i+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(i+".days must be a number >= 1 when present"),void 0!==e.progress){const o=Number(e.progress);o>=0&&o<=1||t.push(i+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(i+".row must be a number >= 0 when present")}else t.push(i+" 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 i=`edges[${r}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(i+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||t.push(i+".target must reference an existing task id")):t.push(i+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validatePowerDsl(e){const o=[],r=Array.isArray(e.nodes)?e.nodes:[];Array.isArray(e.nodes)||o.push("nodes must be an array");const i=new Set;return r.forEach((e,r)=>{const n=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id?i.has(e.id)?o.push("duplicated node id: "+e.id):i.add(e.id):o.push(n+".id must be a non-empty string"),-1===t.indexOf(e.kind)&&o.push(`${n}.kind must be one of ${t.join(" / ")}`),void 0===e.voltageLevel||/^\d+(\.\d+)?kV$/.test(String(e.voltageLevel))||o.push(n+'.voltageLevel must look like "110kV"')):o.push(n+" must be an object")}),r.forEach((e,t)=>{if(!e||void 0===e.attachedTo)return;const i=r.find(t=>t&&t.id===e.attachedTo);i?"busbar"!==i.kind&&o.push(`nodes[${t}].attachedTo must point at a busbar: ${e.attachedTo} is ${i.kind}`):o.push(`nodes[${t}].attachedTo references an unknown node: ${e.attachedTo}`)}),(e.edges||[]).forEach((e,t)=>{const r=`edges[${t}]`;e&&"object"==typeof e?(i.has(e.source)||o.push(`${r}.source references an unknown node: ${e.source}`),i.has(e.target)||o.push(`${r}.target references an unknown node: ${e.target}`),e.source===e.target&&o.push(r+" must not connect a node to itself")):o.push(r+" must be an object")}),{valid:0===o.length,errors:o}}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,o={}){const r=Number(o.gapX)||90,i=Number(o.gapY)||90,n=void 0===o.originX?80:o.originX,s=void 0===o.originY?80:o.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const l=new Map,p=new Map;e.forEach(e=>{l.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(l.set(e.targetId,(l.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const c=new Map,h=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(c.set(e.id,0),h.push(e.id))}),h.length||(c.set(e[0].id,0),h.push(e[0].id));let u=e.length*e.length+e.length;for(;h.length&&u-- >0;){const e=h.shift(),t=c.get(e)||0;(p.get(e)||[]).forEach(e=>{const o=t+1;(void 0===c.get(e)?-1:c.get(e))<o&&(c.set(e,o),h.push(e))})}e.forEach(e=>{c.has(e.id)||c.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=c.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===o.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((o,n)=>{const s=f.get(o);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*i)/2;s.forEach(o=>{a.set(o.id,{left:Math.round(t+(e[n]-o.width)/2),top:Math.round(d)}),d+=o.height+i}),t+=e[n]+r})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((o,n)=>{const s=f.get(o);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*r)/2;s.forEach(o=>{a.set(o.id,{left:Math.round(d),top:Math.round(t+(e[n]-o.height)/2)}),d+=o.width+r}),t+=e[n]+i})}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: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||{},o=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&u[e.kind]?e.kind:"process"}(e),o=u[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:o.width,height:"number"==typeof e.height?e.height:o.height,fillColor:e.fillColor||o.fill,strokeColor:e.strokeColor||o.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"})),i=t.layout||"layered";return"none"!==i&&o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,o,r){const i=layeredLayout(e,t,{gapX:o,gapY:r});e.forEach(e=>{const t=i.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(o,r,Number(t.gapX)||90,Number(t.gapY)||90)),o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:o,edges:r,layout:i,options:t}}const f={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},m=Number(e.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,g=Number(e.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,y=Number(e.FLOW_NODE_KINDS.bpmnLane.height)||130,b=Number(e.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(t){const o=t.kind||"task",r=function presetOf(t){return e.FLOW_NODE_KINDS[t]||e.FLOW_NODE_KINDS.bpmnTask}(f[o]||"bpmnTask"),i={id:t.id,typeId:"FlowNode",kind:f[o]||"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:o,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"===o&&(i.eventKind=t.eventKind||r.eventKind||"start",i.trigger=t.trigger||r.trigger||"none"),"gateway"===o&&(i.gatewayType=t.gatewayType||r.gatewayType||"exclusive"),"task"!==o&&"subprocess"!==o||(i.taskType=t.taskType||r.taskType||"none"),i}function buildGroups(e,t){const o=new Map;t.forEach(e=>o.set(e.id,e));const r=1===t.length?t[0]:null,i=[];return e.forEach(e=>{(e=>{let t=i.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},i.push(t)),t})((e.parent?o.get(e.parent):void 0)||r).nodes.push(e)}),i}function layoutGroups(e,t,o,r){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const i=layeredLayout(e.nodes,t,{gapX:o,gapY:r,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=i.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,o=1/0,r=-1/0,i=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),o=Math.min(o,e.top),r=Math.max(r,e.left+e.width),i=Math.max(i,e.top+e.height)}),{minX:t,minY:o,maxX:r,maxY:i}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},o=(e.nodes||[]).map(toWorkingNode),r=o.filter(e=>"pool"===e.dslKind),i=o.filter(e=>"lane"===e.dslKind),n=o.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 o=new Map;return e.forEach(e=>{let r=e.parent;r||1!==t.length||(r=t[0].id),r&&o.set(e.id,r)}),o}(i,r),lanesOf=e=>i.filter(t=>d.get(t.id)===e);let l=[];"none"!==a&&(l=buildGroups(n,r.concat(i)),layoutGroups(l,s,Number(t.gapX)||90,Number(t.gapY)||60)),i.forEach(e=>{const t=l.filter(t=>t.owner===e)[0],o=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(o?o.maxY-o.minY:0),y))),e.explicitWidth||(e.width=Math.round(Math.max((o?o.maxX-o.minX:0)+g+56,b)))}),r.forEach(e=>{const t=lanesOf(e.id);if(t.length){const o=t.reduce((e,t)=>Math.max(e,t.width),b);return e.explicitWidth||(e.width=o),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 o=l.filter(t=>t.owner===e)[0],r=o?o.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(r?r.maxX-r.minX:0),b))),e.explicitHeight||(e.height=Math.round(Math.max((r?r.maxY-r.minY:0)+m+56,160)))});let p=60;r.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=p),p=Math.max(p,e.top+e.height+60)}),r.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const o=e.top+m,r=Math.max(e.height-m,1),i=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(r-i,0)/n.length:0;let a=o;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 c=60;i.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=c,c=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const o=e.owner;let r=80,i=80;o&&(r=o.left+28,i=o.top+28,"pool"===o.dslKind?i+=m:r+=g),e.nodes.forEach(e=>{e.left=Math.round(r+(e.left-t.minX)),e.top=Math.round(i+(e.top-t.minY))})});return{kind:"bpmn",nodes:r.concat(i).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||{},o=(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||""})),i=t.layout||"layered";if("none"!==i&&o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(o,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"});o.forEach(t=>{const o=e.get(t.id);o&&(t.left=o.left,t.top=o.top)})}return o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:o,edges:r,layout:i,options:t}}const w={width:160,height:64},v={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},o=(e.nodes||[]).map(e=>{const t=e.kind||"state",o="initial"===t||"final"===t,r="composite"===t?v:o?{width:24,height:24}:w;return{id:e.id,kind:t,title:e.title||e.name||(o?"":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})),i=t.layout||"auto",n=new Set;if("none"!==i){const e=new Map;o.forEach(t=>e.set(t.id,t));const i=o.filter(t=>!(t.parent&&e.has(t.parent)));if(i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let o=e.get(t);for(;o&&o.parent&&e.has(o.parent);)o=e.get(o.parent);return o?o.id:t},o=r.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(i,o,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});i.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;o.filter(e=>"composite"===e.kind).forEach(e=>{const t=o.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...i.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let r=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(r>56&&r+e.width>56+p&&(r=56,a=l+40),n.add(e.id),e.left=r,e.top=a,r+=e.width+40,d=Math.max(d,r),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,r)=>{o.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=r,offsetChildren(e,t,r))})};o.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:o,edges:r,layout:i,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function compilePowerDsl(e){const t=e.options||{},o=(e.nodes||[]).map((e,t)=>{const o=function defaultPlacement(e){return{left:120+e%6*200,top:120+160*Math.floor(e/6)}}(t);return{id:e.id,kind:e.kind,title:e.title||e.name||e.id,voltageLevel:String(e.voltageLevel||""),left:"number"==typeof e.left?e.left:o.left,top:"number"==typeof e.top?e.top:o.top,width:e.width,height:e.height,switchState:e.switchState,source:!!e.source}}),r=new Map;o.forEach(e=>r.set(e.id,e));return{kind:"power",nodes:o,edges:(e.edges||[]).map((e,t)=>({id:e.id||"conductor-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",voltageLevel:e.voltageLevel||(r.get(e.source)||{}).voltageLevel||""})),attachments:(e.nodes||[]).filter(e=>!!e.attachedTo).map(e=>({deviceId:e.id,busId:String(e.attachedTo)})),options:t}}function renderGanttDsl(t,o){const r=compileGanttDsl(o),i=r.options||{},n=(new e.ICE).init(t),s=new e.GanttDesigner(n);return i.dayWidth&&s.setDayWidth(i.dayWidth),r.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),r.edges.forEach(e=>{s.createDependency(e)}),s.select(null),i.autoSchedule&&s.autoSchedule(),i.viewport?n.setViewport(i.viewport.scale,i.viewport.tx,i.viewport.ty):!1!==i.fitViewport&&s.fitViewport(i.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderPowerDsl(t,o){const r=compilePowerDsl(o),i=r.options||{},n=(new e.ICE).init(t),s=new e.PowerDesigner(n);i.voltageColors&&s.setVoltageColors(i.voltageColors);const a=new Map;return r.nodes.forEach(e=>{const t=s.createSymbol(e.kind,{name:e.title,voltageLevel:e.voltageLevel,left:e.left,top:e.top,width:e.width,height:e.height,switchState:e.switchState});e.source&&t.setState({energizedSource:!0}),a.set(e.id,t)}),r.attachments.forEach(e=>{const t=a.get(e.deviceId),o=a.get(e.busId);t&&o&&s.attachToBus(t,o)}),r.edges.forEach(e=>{const t=a.get(e.sourceId),o=a.get(e.targetId);t&&o&&s.createLine({sourceId:t.state.id,targetId:o.state.id,sourcePort:e.sourcePort,targetPort:e.targetPort,voltageLevel:e.voltageLevel})}),s.select(null),s.applyTopology(),!1!==i.fitViewport&&s.fitViewport(i.fitViewportPadding),s.resetHistory(),{kind:"power",ice:n,designer:s}}function renderStatechartDsl(t,o){const r=compileStatechartDsl(o),i=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),i.viewport?n.setViewport(i.viewport.scale,i.viewport.tx,i.viewport.ty):!1!==i.fitViewport&&s.fitViewport(i.fitViewportPadding),s.resetHistory(),{kind:"statechart",ice:n,designer:s}}function renderUmlDsl(t,o){const r=compileUmlDsl(o),i=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),i.viewport?n.setViewport(i.viewport.scale,i.viewport.tx,i.viewport.ty):!1!==i.fitViewport&&s.fitViewport(i.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:n,designer:s}}function renderBpmnDsl(t,o){const r=compileBpmnDsl(o),i=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(o=>{void 0!==e[o]&&(t[o]=e[o])}),s.createNode(e.kind,t)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),i.viewport?n.setViewport(i.viewport.scale,i.viewport.tx,i.viewport.ty):!1!==i.fitViewport&&s.fitViewport(i.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:n,designer:s}}function renderFlowDsl(t,o){const r=compileFlowDsl(o),i=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),i.viewport?n.setViewport(i.viewport.scale,i.viewport.tx,i.viewport.ty):!1!==i.fitViewport&&s.fitViewport(i.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:n,designer:s}}exports.DSL_SCHEMA_VERSION=1,exports.POWER_DSL_KINDS=t,exports.compileBpmnDsl=compileBpmnDsl,exports.compileDsl=compileDsl,exports.compileFlowDsl=compileFlowDsl,exports.compileGanttDsl=compileGanttDsl,exports.compilePowerDsl=compilePowerDsl,exports.compileStatechartDsl=compileStatechartDsl,exports.compileUmlDsl=compileUmlDsl,exports.isBpmnDsl=isBpmnDsl,exports.isFlowDsl=isFlowDsl,exports.isGanttDsl=isGanttDsl,exports.isPowerDsl=isPowerDsl,exports.isStatechartDsl=isStatechartDsl,exports.isUmlDsl=isUmlDsl,exports.layeredLayout=layeredLayout,exports.renderBpmnDsl=renderBpmnDsl,exports.renderDsl=function renderDsl(t,o){const r=validateDsl(o);if(!r.valid)throw new Error(r.errors.join("\n"));return isGanttDsl(o)?renderGanttDsl(t,o):isPowerDsl(o)?renderPowerDsl(t,o):isStatechartDsl(o)?renderStatechartDsl(t,o):isUmlDsl(o)?renderUmlDsl(t,o):isBpmnDsl(o)?renderBpmnDsl(t,o):isFlowDsl(o)?renderFlowDsl(t,o):function renderErDsl(t,o){const r=compileDsl(o),i=r.options||{},n=(new e.ICE).init(t),s=new e.EntityDesigner(n);r.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,o){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),i=r.get(e.targetId);let n="R",s="L";if(t&&i){const e=i.center[0]-t.center[0],o=i.center[1]-t.center[1];Math.abs(e)>Math.abs(o)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=o>=0?"B":"T",s=o>=0?"T":"B")}return{...e,routeType:e.routeType||o||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,r,i.routeType).forEach(e=>{s.createRelation(e)}),("layered"===r.layout||"horizontal"===r.layout)&&new e.ICELayeredLayout({gapX:i.gapX||120,gapY:i.gapY||50}).layoutContainer(n);i.viewport?n.setViewport(i.viewport.scale,i.viewport.tx,i.viewport.ty):i.fitViewport&&function fitViewport(e,t,o){const r=t.entities||[];let i=1/0,n=1/0,s=-1/0,a=-1/0;r.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();i=Math.min(i,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-i,l=a-n,p=e.canvasWidth||0,c=e.canvasHeight||0;if(!p||!c||d<=0||l<=0)return;const h=Number.isFinite(o)&&o>=0?o:40,u=Math.max(1,p-2*h),f=Math.max(1,c-2*h),m=Math.min(u/d,f/l,1),g=(p-d*m)/2-i*m,y=(c-l*m)/2-n*m;e.setViewport(m,g,y)}(n,s,i.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(t,o)},exports.renderFlowDsl=renderFlowDsl,exports.renderGanttDsl=renderGanttDsl,exports.renderPowerDsl=renderPowerDsl,exports.renderStatechartDsl=renderStatechartDsl,exports.renderUmlDsl=renderUmlDsl,exports.validateBpmnDsl=validateBpmnDsl,exports.validateDsl=validateDsl,exports.validateFlowDsl=validateFlowDsl,exports.validateGanttDsl=validateGanttDsl,exports.validatePowerDsl=validatePowerDsl,exports.validateStatechartDsl=validateStatechartDsl,exports.validateUmlDsl=validateUmlDsl;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FLOW_NODE_KINDS as e,ICE as t,GanttDesigner as i,StatechartDesigner as o,UmlDesigner as r,BpmnDesigner as n,FlowDesigner as s,EntityDesigner as a,ICELayeredLayout as d}from"ice-entity-designer";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const p=1,l=["terminator","process","decision","io"],h=["T","R","B","L","C"],c=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],u=["start","intermediate","end"],f=["none","message","timer","error","terminate"],m=["exclusive","parallel","inclusive","event"],g=["none","user","service","script","send","receive","manual"],y=["sequence","message","association"],b=["initial","final","state","composite"],w=["class","interface","enum"],v=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,o)=>{const r=`entities[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${r}.fields[${i}].name must be a non-empty string`)}):t.push(r+".fields must be an array")):t.push(r+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const o=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(o+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(o+".target must be a non-empty string")):t.push(o+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,r)=>{const n=`nodes[${r}]`;if(!e||"object"!=typeof e)return void t.push(n+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"task")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===c.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${c.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)});[["eventKind",u],["trigger",f],["gatewayType",m],["taskType",g]].forEach(([i,o])=>{const r=e[i];void 0!==r&&-1===o.indexOf(r)&&t.push(`${n}.${i} must be one of ${o.join("/")}`)})}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=o.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===y.indexOf(n)&&t.push(`${r}.type must be one of ${y.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(r+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(r+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===l.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${l.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${r}.${i} must be a number when present`)})):t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present"),void 0!==e.sourcePort&&-1===h.indexOf(e.sourcePort)&&t.push(`${r}.sourcePort must be one of ${h.join("/")}`),void 0!==e.targetPort&&-1===h.indexOf(e.targetPort)&&t.push(`${r}.targetPort must be one of ${h.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(r+'.linkShape must be "visio" or "bezier" when present')):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===w.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${w.join("/")}`),["attributes","methods"].forEach(i=>{const o=e[i];void 0!==o&&(Array.isArray(o)&&!o.some(e=>"string"!=typeof e)||t.push(`${r}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${r}.${i} must be a number when present`)})):t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===v.indexOf(n)&&t.push(`${r}.type must be one of ${v.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,r)=>{const n=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===b.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${b.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==o.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const o=e[i];void 0!==o&&"string"!=typeof o&&t.push(`${r}.${i} must be a string when present`)})):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(r+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(r+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(r+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(r+".row must be a number >= 0 when present")}else t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing task id")):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const o=Number(i.gapX)||90,r=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const p=new Map,l=new Map;e.forEach(e=>{p.set(e.id,0),l.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(p.set(e.targetId,(p.get(e.targetId)||0)+1),l.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(p.get(e.id)||0)&&(h.set(e.id,0),c.push(e.id))}),c.length||(h.set(e[0].id,0),c.push(e[0].id));let u=e.length*e.length+e.length;for(;c.length&&u-- >0;){const e=c.shift(),t=h.get(e)||0;(l.get(e)||[]).forEach(e=>{const i=t+1;(void 0===h.get(e)?-1:h.get(e))<i&&(h.set(e,i),c.push(e))})}e.forEach(e=>{h.has(e.id)||h.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=h.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+r}),t+=e[n]+o})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+o}),t+=e[n]+r})}const g=Math.min(...e.map(e=>a.get(e.id).left)),y=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-y}),a}const N={terminator:{width:e.terminator.width,height:e.terminator.height,fill:e.terminator.fill,stroke:e.terminator.stroke},process:{width:e.process.width,height:e.process.height,fill:e.process.fill,stroke:e.process.stroke},decision:{width:e.decision.width,height:e.decision.height,fill:e.decision.fill,stroke:e.decision.stroke},io:{width:e.io.width,height:e.io.height,fill:e.io.fill,stroke:e.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&N[e.kind]?e.kind:"process"}(e),i=N[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(o=e,o.title||o.name||o.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var o}),o=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),r=t.layout||"layered";return"none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,o){const r=layeredLayout(e,t,{gapX:i,gapY:o});e.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,o,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:o,layout:r,options:t}}const k={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},D=Number(e.bpmnPool.bandSize)||32,x=Number(e.bpmnLane.bandSize)||32,E=Number(e.bpmnLane.height)||130,M=Number(e.bpmnPool.width)||900;function toWorkingNode(t){const i=t.kind||"task",o=function presetOf(t){return e[t]||e.bpmnTask}(k[i]||"bpmnTask"),r={id:t.id,typeId:"FlowNode",kind:k[i]||"bpmnTask",title:t.title||t.name||t.id,left:"number"==typeof t.left?t.left:0,top:"number"==typeof t.top?t.top:0,width:"number"==typeof t.width?t.width:o.width,height:"number"==typeof t.height?t.height:o.height,fillColor:t.fillColor,strokeColor:t.strokeColor,dslKind:i,parent:t.parent,explicitLeft:"number"==typeof t.left,explicitTop:"number"==typeof t.top,explicitWidth:"number"==typeof t.width,explicitHeight:"number"==typeof t.height};return"event"===i&&(r.eventKind=t.eventKind||o.eventKind||"start",r.trigger=t.trigger||o.trigger||"none"),"gateway"===i&&(r.gatewayType=t.gatewayType||o.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(r.taskType=t.taskType||o.taskType||"none"),r}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const o=1===t.length?t[0]:null,r=[];return e.forEach(e=>{(e=>{let t=r.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},r.push(t)),t})((e.parent?i.get(e.parent):void 0)||o).nodes.push(e)}),r}function layoutGroups(e,t,i,o){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const r=layeredLayout(e.nodes,t,{gapX:i,gapY:o,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,o=-1/0,r=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),o=Math.max(o,e.left+e.width),r=Math.max(r,e.top+e.height)}),{minX:t,minY:i,maxX:o,maxY:r}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),o=i.filter(e=>"pool"===e.dslKind),r=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let o=e.parent;o||1!==t.length||(o=t[0].id),o&&i.set(e.id,o)}),i}(r,o),lanesOf=e=>r.filter(t=>d.get(t.id)===e);let p=[];"none"!==a&&(p=buildGroups(n,o.concat(r)),layoutGroups(p,s,Number(t.gapX)||90,Number(t.gapY)||60)),r.forEach(e=>{const t=p.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),E))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+x+56,M)))}),o.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),M);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=D+t.reduce((e,t)=>e+t.height,0)))}const i=p.filter(t=>t.owner===e)[0],o=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(o?o.maxX-o.minX:0),M))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+D+56,160)))});let l=60;o.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=l),l=Math.max(l,e.top+e.height+60)}),o.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+D,o=Math.max(e.height-D,1),r=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(o-r,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||E)),a=t.top+t.height})});let h=60;r.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),p.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let o=80,r=80;i&&(o=i.left+28,r=i.top+28,"pool"===i.dslKind?r+=D:o+=x),e.nodes.forEach(e=>{e.left=Math.round(o+(e.left-t.minX)),e.top=Math.round(r+(e.top-t.minY))})});return{kind:"bpmn",nodes:o.concat(r).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),o=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),r=t.layout||"layered";if("none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,o.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:o,layout:r,options:t}}const $={width:160,height:64},j={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,o="composite"===t?j:i?{width:24,height:24}:$;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height}}),o=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),r=t.layout||"auto",n=new Set;if("none"!==r){const e=new Map;i.forEach(t=>e.set(t.id,t));const r=i.filter(t=>!(t.parent&&e.has(t.parent)));if(r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=o.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(r,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});r.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...r.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let o=56,a=56,d=0,p=56;const l=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(o>56&&o+e.width>56+l&&(o=56,a=p+40),n.add(e.id),e.left=o,e.top=a,o+=e.width+40,d=Math.max(d,o),p=Math.max(p,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,p+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,o)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=o,offsetChildren(e,t,o))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:o,layout:r,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),r=o.options||{},n=(new t).init(e),s=new a(n);o.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const o=new Map;return e.entities.forEach(e=>{o.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=o.get(e.sourceId),r=o.get(e.targetId);let n="R",s="L";if(t&&r){const e=r.center[0]-t.center[0],i=r.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,o,r.routeType).forEach(e=>{s.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new d({gapX:r.gapX||120,gapY:r.gapY||50}).layoutContainer(n);r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):r.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let r=1/0,n=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();r=Math.min(r,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-r,p=a-n,l=e.canvasWidth||0,h=e.canvasHeight||0;if(!l||!h||d<=0||p<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,l-2*c),f=Math.max(1,h-2*c),m=Math.min(u/d,f/p,1),g=(l-d*m)/2-r*m,y=(h-p*m)/2-n*m;e.setViewport(m,g,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(e,i)}function renderGanttDsl(e,o){const r=compileGanttDsl(o),n=r.options||{},s=(new t).init(e),a=new i(s);return n.dayWidth&&a.setDayWidth(n.dayWidth),r.nodes.forEach(e=>{a.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),r.edges.forEach(e=>{a.createDependency(e)}),a.select(null),n.autoSchedule&&a.autoSchedule(),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"gantt",ice:s,designer:a}}function renderStatechartDsl(e,i){const r=compileStatechartDsl(i),n=r.options||{},s=(new t).init(e),a=new o(s);return r.nodes.forEach(e=>{a.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{a.createTransition(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"statechart",ice:s,designer:a}}function renderUmlDsl(e,i){const o=compileUmlDsl(i),n=o.options||{},s=(new t).init(e),a=new r(s);return o.nodes.forEach(e=>{a.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),o.edges.forEach(e=>{a.createRelation(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"uml",ice:s,designer:a}}function renderBpmnDsl(e,i){const o=compileBpmnDsl(i),r=o.options||{},s=(new t).init(e),a=new n(s);return o.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),a.createNode(e.kind,t)}),o.edges.forEach(e=>{a.createEdge(e)}),a.select(null),r.viewport?s.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&a.fitViewport(r.fitViewportPadding),a.resetHistory(),{kind:"bpmn",ice:s,designer:a}}function renderFlowDsl(e,i){const o=compileFlowDsl(i),r=o.options||{},n=(new t).init(e),a=new s(n);return o.nodes.forEach(e=>{a.createNode(e.kind,e)}),o.edges.forEach(e=>{a.createEdge(e)}),a.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&a.fitViewport(r.fitViewportPadding),a.resetHistory(),{kind:"flowchart",ice:n,designer:a}}export{p as DSL_SCHEMA_VERSION,compileBpmnDsl,compileDsl,compileFlowDsl,compileGanttDsl,compileStatechartDsl,compileUmlDsl,isBpmnDsl,isFlowDsl,isGanttDsl,isStatechartDsl,isUmlDsl,layeredLayout,renderBpmnDsl,renderDsl,renderFlowDsl,renderGanttDsl,renderStatechartDsl,renderUmlDsl,validateBpmnDsl,validateDsl,validateFlowDsl,validateGanttDsl,validateStatechartDsl,validateUmlDsl};
|
|
1
|
+
import{FLOW_NODE_KINDS as e,ICE as t,GanttDesigner as o,PowerDesigner as i,StatechartDesigner as r,UmlDesigner as n,BpmnDesigner as s,FlowDesigner as a,EntityDesigner as d,ICELayeredLayout as l}from"ice-entity-designer";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const p=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"];function isPowerDsl(e){return!!e&&"object"==typeof e&&"power"===e.kind}const c=1,h=["terminator","process","decision","io"],u=["T","R","B","L","C"],f=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],g=["start","intermediate","end"],m=["none","message","timer","error","terminate"],y=["exclusive","parallel","inclusive","event"],b=["none","user","service","script","send","receive","manual"],w=["sequence","message","association"],v=["initial","final","state","composite"],k=["class","interface","enum"],N=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isPowerDsl(e)?validatePowerDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const o=new Set;e.entities.forEach((e,i)=>{const r=`entities[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):o.add(e.id):t.push(r+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,o)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${r}.fields[${o}].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,o)=>{const i=`relations[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(i+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(i+".target must be a non-empty string")):t.push(i+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const o=new Set,i=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()?o.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(o.add(e.id),i.set(e.id,e.kind||"task")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===f.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${f.join("/")}`),["left","top","width","height"].forEach(o=>{const i=e[o];void 0!==i&&"number"!=typeof i&&t.push(`${n}.${o} must be a number when present`)});[["eventKind",g],["trigger",m],["gatewayType",y],["taskType",b]].forEach(([o,i])=>{const r=e[o];void 0!==r&&-1===i.indexOf(r)&&t.push(`${n}.${o} must be one of ${i.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(!o.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=i.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const r=`edges[${i}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.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===w.indexOf(n)&&t.push(`${r}.type must be one of ${w.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 o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const r=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):o.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("/")}`),["left","top","width","height"].forEach(o=>{const i=e[o];void 0!==i&&"number"!=typeof i&&t.push(`${r}.${o} 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()&&o.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.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===u.indexOf(e.sourcePort)&&t.push(`${r}.sourcePort must be one of ${u.join("/")}`),void 0!==e.targetPort&&-1===u.indexOf(e.targetPort)&&t.push(`${r}.targetPort must be one of ${u.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 o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const r=`nodes[${i}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):o.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===k.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${k.join("/")}`),["attributes","methods"].forEach(o=>{const i=e[o];void 0!==i&&(Array.isArray(i)&&!i.some(e=>"string"!=typeof e)||t.push(`${r}.${o} must be an array of strings when present`))}),["left","top","width","height"].forEach(o=>{const i=e[o];void 0!==i&&"number"!=typeof i&&t.push(`${r}.${o} 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}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.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===N.indexOf(n)&&t.push(`${r}.type must be one of ${N.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 o=new Set,i=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()?o.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(o.add(e.id),i.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===v.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${v.join("/")}`),["left","top","width","height"].forEach(o=>{const i=e[o];void 0!==i&&"number"!=typeof i&&t.push(`${n}.${o} 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()&&o.has(e.parent)?e.parent!==e.id?"composite"!==i.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const r=`edges[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&o.has(e.target)||t.push(r+".target must reference an existing node id"),["event","guard","action","label"].forEach(o=>{const i=e[o];void 0!==i&&"string"!=typeof i&&t.push(`${r}.${o} 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 o=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const r=`nodes[${i}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?o.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):o.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 o=Number(e.progress);o>=0&&o<=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,i)=>{const r=`edges[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&o.has(e.source)||t.push(r+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&o.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 validatePowerDsl(e){const t=[],o=Array.isArray(e.nodes)?e.nodes:[];Array.isArray(e.nodes)||t.push("nodes must be an array");const i=new Set;return o.forEach((e,o)=>{const r=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id?i.has(e.id)?t.push("duplicated node id: "+e.id):i.add(e.id):t.push(r+".id must be a non-empty string"),-1===p.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${p.join(" / ")}`),void 0===e.voltageLevel||/^\d+(\.\d+)?kV$/.test(String(e.voltageLevel))||t.push(r+'.voltageLevel must look like "110kV"')):t.push(r+" must be an object")}),o.forEach((e,i)=>{if(!e||void 0===e.attachedTo)return;const r=o.find(t=>t&&t.id===e.attachedTo);r?"busbar"!==r.kind&&t.push(`nodes[${i}].attachedTo must point at a busbar: ${e.attachedTo} is ${r.kind}`):t.push(`nodes[${i}].attachedTo references an unknown node: ${e.attachedTo}`)}),(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?(i.has(e.source)||t.push(`${r}.source references an unknown node: ${e.source}`),i.has(e.target)||t.push(`${r}.target references an unknown node: ${e.target}`),e.source===e.target&&t.push(r+" must not connect a node to itself")):t.push(r+" must be an object")}),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,o={}){const i=Number(o.gapX)||90,r=Number(o.gapY)||90,n=void 0===o.originX?80:o.originX,s=void 0===o.originY?80:o.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const l=new Map,p=new Map;e.forEach(e=>{l.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(l.set(e.targetId,(l.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const c=new Map,h=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(c.set(e.id,0),h.push(e.id))}),h.length||(c.set(e[0].id,0),h.push(e[0].id));let u=e.length*e.length+e.length;for(;h.length&&u-- >0;){const e=h.shift(),t=c.get(e)||0;(p.get(e)||[]).forEach(e=>{const o=t+1;(void 0===c.get(e)?-1:c.get(e))<o&&(c.set(e,o),h.push(e))})}e.forEach(e=>{c.has(e.id)||c.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=c.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const g=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===o.direction){const e=g.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;g.forEach((o,n)=>{const s=f.get(o);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*r)/2;s.forEach(o=>{a.set(o.id,{left:Math.round(t+(e[n]-o.width)/2),top:Math.round(d)}),d+=o.height+r}),t+=e[n]+i})}else{const e=g.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;g.forEach((o,n)=>{const s=f.get(o);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*i)/2;s.forEach(o=>{a.set(o.id,{left:Math.round(d),top:Math.round(t+(e[n]-o.height)/2)}),d+=o.width+i}),t+=e[n]+r})}const m=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-m,e.top+=s-y}),a}const D={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||{},o=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&D[e.kind]?e.kind:"process"}(e),o=D[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(i=e,i.title||i.name||i.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height,fillColor:e.fillColor||o.fill,strokeColor:e.strokeColor||o.stroke};var i}),i=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),r=t.layout||"layered";return"none"!==r&&o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,o,i){const r=layeredLayout(e,t,{gapX:o,gapY:i});e.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(o,i,Number(t.gapX)||90,Number(t.gapY)||90)),o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:o,edges:i,layout:r,options:t}}const x={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},E=Number(e.bpmnPool.bandSize)||32,$=Number(e.bpmnLane.bandSize)||32,S=Number(e.bpmnLane.height)||130,j=Number(e.bpmnPool.width)||900;function toWorkingNode(t){const o=t.kind||"task",i=function presetOf(t){return e[t]||e.bpmnTask}(x[o]||"bpmnTask"),r={id:t.id,typeId:"FlowNode",kind:x[o]||"bpmnTask",title:t.title||t.name||t.id,left:"number"==typeof t.left?t.left:0,top:"number"==typeof t.top?t.top:0,width:"number"==typeof t.width?t.width:i.width,height:"number"==typeof t.height?t.height:i.height,fillColor:t.fillColor,strokeColor:t.strokeColor,dslKind:o,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"===o&&(r.eventKind=t.eventKind||i.eventKind||"start",r.trigger=t.trigger||i.trigger||"none"),"gateway"===o&&(r.gatewayType=t.gatewayType||i.gatewayType||"exclusive"),"task"!==o&&"subprocess"!==o||(r.taskType=t.taskType||i.taskType||"none"),r}function buildGroups(e,t){const o=new Map;t.forEach(e=>o.set(e.id,e));const i=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?o.get(e.parent):void 0)||i).nodes.push(e)}),r}function layoutGroups(e,t,o,i){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const r=layeredLayout(e.nodes,t,{gapX:o,gapY:i,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,o=1/0,i=-1/0,r=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),o=Math.min(o,e.top),i=Math.max(i,e.left+e.width),r=Math.max(r,e.top+e.height)}),{minX:t,minY:o,maxX:i,maxY:r}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},o=(e.nodes||[]).map(toWorkingNode),i=o.filter(e=>"pool"===e.dslKind),r=o.filter(e=>"lane"===e.dslKind),n=o.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 o=new Map;return e.forEach(e=>{let i=e.parent;i||1!==t.length||(i=t[0].id),i&&o.set(e.id,i)}),o}(r,i),lanesOf=e=>r.filter(t=>d.get(t.id)===e);let l=[];"none"!==a&&(l=buildGroups(n,i.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],o=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(o?o.maxY-o.minY:0),S))),e.explicitWidth||(e.width=Math.round(Math.max((o?o.maxX-o.minX:0)+$+56,j)))}),i.forEach(e=>{const t=lanesOf(e.id);if(t.length){const o=t.reduce((e,t)=>Math.max(e,t.width),j);return e.explicitWidth||(e.width=o),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=E+t.reduce((e,t)=>e+t.height,0)))}const o=l.filter(t=>t.owner===e)[0],i=o?o.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(i?i.maxX-i.minX:0),j))),e.explicitHeight||(e.height=Math.round(Math.max((i?i.maxY-i.minY:0)+E+56,160)))});let p=60;i.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=p),p=Math.max(p,e.top+e.height+60)}),i.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const o=e.top+E,i=Math.max(e.height-E,1),r=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(i-r,0)/n.length:0;let a=o;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||S)),a=t.top+t.height})});let c=60;r.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=c,c=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const o=e.owner;let i=80,r=80;o&&(i=o.left+28,r=o.top+28,"pool"===o.dslKind?r+=E:i+=$),e.nodes.forEach(e=>{e.left=Math.round(i+(e.left-t.minX)),e.top=Math.round(r+(e.top-t.minY))})});return{kind:"bpmn",nodes:i.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||{},o=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),i=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),r=t.layout||"layered";if("none"!==r&&o.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(o,i.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});o.forEach(t=>{const o=e.get(t.id);o&&(t.left=o.left,t.top=o.top)})}return o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:o,edges:i,layout:r,options:t}}const M={width:160,height:64},T={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},o=(e.nodes||[]).map(e=>{const t=e.kind||"state",o="initial"===t||"final"===t,i="composite"===t?T:o?{width:24,height:24}:M;return{id:e.id,kind:t,title:e.title||e.name||(o?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height}}),i=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),r=t.layout||"auto",n=new Set;if("none"!==r){const e=new Map;o.forEach(t=>e.set(t.id,t));const r=o.filter(t=>!(t.parent&&e.has(t.parent)));if(r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let o=e.get(t);for(;o&&o.parent&&e.has(o.parent);)o=e.get(o.parent);return o?o.id:t},o=i.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(r,o,{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;o.filter(e=>"composite"===e.kind).forEach(e=>{const t=o.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 i=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(i>56&&i+e.width>56+p&&(i=56,a=l+40),n.add(e.id),e.left=i,e.top=a,i+=e.width+40,d=Math.max(d,i),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),o.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,i)=>{o.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=i,offsetChildren(e,t,i))})};o.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:o,edges:i,layout:r,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function compilePowerDsl(e){const t=e.options||{},o=(e.nodes||[]).map((e,t)=>{const o=function defaultPlacement(e){return{left:120+e%6*200,top:120+160*Math.floor(e/6)}}(t);return{id:e.id,kind:e.kind,title:e.title||e.name||e.id,voltageLevel:String(e.voltageLevel||""),left:"number"==typeof e.left?e.left:o.left,top:"number"==typeof e.top?e.top:o.top,width:e.width,height:e.height,switchState:e.switchState,source:!!e.source}}),i=new Map;o.forEach(e=>i.set(e.id,e));return{kind:"power",nodes:o,edges:(e.edges||[]).map((e,t)=>({id:e.id||"conductor-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",voltageLevel:e.voltageLevel||(i.get(e.source)||{}).voltageLevel||""})),attachments:(e.nodes||[]).filter(e=>!!e.attachedTo).map(e=>({deviceId:e.id,busId:String(e.attachedTo)})),options:t}}function renderDsl(e,o){const i=validateDsl(o);if(!i.valid)throw new Error(i.errors.join("\n"));return isGanttDsl(o)?renderGanttDsl(e,o):isPowerDsl(o)?renderPowerDsl(e,o):isStatechartDsl(o)?renderStatechartDsl(e,o):isUmlDsl(o)?renderUmlDsl(e,o):isBpmnDsl(o)?renderBpmnDsl(e,o):isFlowDsl(o)?renderFlowDsl(e,o):function renderErDsl(e,o){const i=compileDsl(o),r=i.options||{},n=(new t).init(e),s=new d(n);i.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,o){const i=new Map;return e.entities.forEach(e=>{i.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=i.get(e.sourceId),r=i.get(e.targetId);let n="R",s="L";if(t&&r){const e=r.center[0]-t.center[0],o=r.center[1]-t.center[1];Math.abs(e)>Math.abs(o)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=o>=0?"B":"T",s=o>=0?"T":"B")}return{...e,routeType:e.routeType||o||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,i,r.routeType).forEach(e=>{s.createRelation(e)}),("layered"===i.layout||"horizontal"===i.layout)&&new l({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,o){const i=t.entities||[];let r=1/0,n=1/0,s=-1/0,a=-1/0;i.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,c=e.canvasHeight||0;if(!p||!c||d<=0||l<=0)return;const h=Number.isFinite(o)&&o>=0?o:40,u=Math.max(1,p-2*h),f=Math.max(1,c-2*h),g=Math.min(u/d,f/l,1),m=(p-d*g)/2-r*g,y=(c-l*g)/2-n*g;e.setViewport(g,m,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(e,o)}function renderGanttDsl(e,i){const r=compileGanttDsl(i),n=r.options||{},s=(new t).init(e),a=new o(s);return n.dayWidth&&a.setDayWidth(n.dayWidth),r.nodes.forEach(e=>{a.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),r.edges.forEach(e=>{a.createDependency(e)}),a.select(null),n.autoSchedule&&a.autoSchedule(),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"gantt",ice:s,designer:a}}function renderPowerDsl(e,o){const r=compilePowerDsl(o),n=r.options||{},s=(new t).init(e),a=new i(s);n.voltageColors&&a.setVoltageColors(n.voltageColors);const d=new Map;return r.nodes.forEach(e=>{const t=a.createSymbol(e.kind,{name:e.title,voltageLevel:e.voltageLevel,left:e.left,top:e.top,width:e.width,height:e.height,switchState:e.switchState});e.source&&t.setState({energizedSource:!0}),d.set(e.id,t)}),r.attachments.forEach(e=>{const t=d.get(e.deviceId),o=d.get(e.busId);t&&o&&a.attachToBus(t,o)}),r.edges.forEach(e=>{const t=d.get(e.sourceId),o=d.get(e.targetId);t&&o&&a.createLine({sourceId:t.state.id,targetId:o.state.id,sourcePort:e.sourcePort,targetPort:e.targetPort,voltageLevel:e.voltageLevel})}),a.select(null),a.applyTopology(),!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"power",ice:s,designer:a}}function renderStatechartDsl(e,o){const i=compileStatechartDsl(o),n=i.options||{},s=(new t).init(e),a=new r(s);return i.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})}),i.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,o){const i=compileUmlDsl(o),r=i.options||{},s=(new t).init(e),a=new n(s);return i.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})}),i.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,o){const i=compileBpmnDsl(o),r=i.options||{},n=(new t).init(e),a=new s(n);return i.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(o=>{void 0!==e[o]&&(t[o]=e[o])}),a.createNode(e.kind,t)}),i.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:"bpmn",ice:n,designer:a}}function renderFlowDsl(e,o){const i=compileFlowDsl(o),r=i.options||{},n=(new t).init(e),s=new a(n);return i.nodes.forEach(e=>{s.createNode(e.kind,e)}),i.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}}export{c as DSL_SCHEMA_VERSION,p as POWER_DSL_KINDS,compileBpmnDsl,compileDsl,compileFlowDsl,compileGanttDsl,compilePowerDsl,compileStatechartDsl,compileUmlDsl,isBpmnDsl,isFlowDsl,isGanttDsl,isPowerDsl,isStatechartDsl,isUmlDsl,layeredLayout,renderBpmnDsl,renderDsl,renderFlowDsl,renderGanttDsl,renderPowerDsl,renderStatechartDsl,renderUmlDsl,validateBpmnDsl,validateDsl,validateFlowDsl,validateGanttDsl,validatePowerDsl,validateStatechartDsl,validateUmlDsl};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ice-entity-designer")):"function"==typeof define&&define.amd?define(["exports","ice-entity-designer"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ICEDSL={},e.IED)}(this,(function(e,t){"use strict";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const i=["terminator","process","decision","io"],o=["T","R","B","L","C"],r=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],n=["start","intermediate","end"],s=["none","message","timer","error","terminate"],a=["exclusive","parallel","inclusive","event"],d=["none","user","service","script","send","receive","manual"],l=["sequence","message","association"],p=["initial","final","state","composite"],h=["class","interface","enum"],c=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const i=new Set;e.entities.forEach((e,o)=>{const r=`entities[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),Array.isArray(e.fields)?e.fields.forEach((e,i)=>{e&&"object"==typeof e&&"string"==typeof e.name&&e.name.trim()||t.push(`${r}.fields[${i}].name must be a non-empty string`)}):t.push(r+".fields must be an array")):t.push(r+" must be an object")})}else t.push("entities must be an array");void 0===e.relations||Array.isArray(e.relations)?(e.relations||[]).forEach((e,i)=>{const o=`relations[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()||t.push(o+".source must be a non-empty string"),"string"==typeof e.target&&e.target.trim()||t.push(o+".target must be a non-empty string")):t.push(o+" must be an object")}):t.push("relations must be an array");return{valid:0===t.length,errors:t}}(e)}function validateBpmnDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,l)=>{const p=`nodes[${l}]`;if(!e||"object"!=typeof e)return void t.push(p+" must be an object");"string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${p}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"task")):t.push(p+".id must be a non-empty string"),void 0!==e.kind&&-1===r.indexOf(e.kind)&&t.push(`${p}.kind must be one of ${r.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${p}.${i} must be a number when present`)});[["eventKind",n],["trigger",s],["gatewayType",a],["taskType",d]].forEach(([i,o])=>{const r=e[i];void 0!==r&&-1===o.indexOf(r)&&t.push(`${p}.${i} must be one of ${o.join("/")}`)})}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;if("string"!=typeof e.parent||!e.parent.trim())return void t.push(n+".parent must be a non-empty string when present");if(!i.has(e.parent))return void t.push(n+".parent must reference an existing node id");if(e.parent===e.id)return void t.push(n+".parent must not reference itself");const s=o.get(e.parent);"pool"===e.kind?t.push(n+".parent is not allowed on a pool (池是最外层容器)"):"lane"===e.kind&&"pool"!==s?t.push(n+".parent must reference a pool"):"pool"!==s&&"lane"!==s&&t.push(n+".parent must reference a pool or a lane")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.flowType;void 0!==n&&-1===l.indexOf(n)&&t.push(`${r}.type must be one of ${l.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present"),void 0!==e.condition&&"string"!=typeof e.condition&&t.push(r+".condition must be a string when present"),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(r+'.linkShape must be "visio" or "bezier" when present')}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateFlowDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const r=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?r.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):r.add(e.id):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===i.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${i.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,i)=>{const n=`edges[${i}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&r.has(e.source)||t.push(n+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&r.has(e.target)||t.push(n+".target must reference an existing node id"),void 0!==e.label&&"string"!=typeof e.label&&t.push(n+".label must be a string when present"),void 0!==e.sourcePort&&-1===o.indexOf(e.sourcePort)&&t.push(`${n}.sourcePort must be one of ${o.join("/")}`),void 0!==e.targetPort&&-1===o.indexOf(e.targetPort)&&t.push(`${n}.targetPort must be one of ${o.join("/")}`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(n+'.linkShape must be "visio" or "bezier" when present')):t.push(n+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateUmlDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),void 0!==e.kind&&-1===h.indexOf(e.kind)&&t.push(`${r}.kind must be one of ${h.join("/")}`),["attributes","methods"].forEach(i=>{const o=e[i];void 0!==o&&(Array.isArray(o)&&!o.some(e=>"string"!=typeof e)||t.push(`${r}.${i} must be an array of strings when present`))}),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${r}.${i} must be a number when present`)})):t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;if(!e||"object"!=typeof e)return void t.push(r+" must be an object");"string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id");const n=void 0!==e.type?e.type:e.relation;void 0!==n&&-1===c.indexOf(n)&&t.push(`${r}.type must be one of ${c.join("/")}`),void 0!==e.label&&"string"!=typeof e.label&&t.push(r+".label must be a string when present")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateStatechartDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set,o=new Map;return Array.isArray(e.nodes)?(e.nodes.forEach((e,r)=>{const n=`nodes[${r}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${n}.id is duplicated: ${e.id}`):(i.add(e.id),o.set(e.id,e.kind||"state")):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===p.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${p.join("/")}`),["left","top","width","height"].forEach(i=>{const o=e[i];void 0!==o&&"number"!=typeof o&&t.push(`${n}.${i} must be a number when present`)})):t.push(n+" must be an object")}),e.nodes.forEach((e,r)=>{if(!e||"object"!=typeof e||void 0===e.parent)return;const n=`nodes[${r}]`;"string"==typeof e.parent&&e.parent.trim()&&i.has(e.parent)?e.parent!==e.id?"composite"!==o.get(e.parent)&&t.push(n+".parent must reference a composite state"):t.push(n+".parent must not reference itself"):t.push(n+".parent must reference an existing node id")})):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing node id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing node id"),["event","guard","action","label"].forEach(i=>{const o=e[i];void 0!==o&&"string"!=typeof o&&t.push(`${r}.${i} must be a string when present`)})):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function validateGanttDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);const i=new Set;return Array.isArray(e.nodes)?e.nodes.forEach((e,o)=>{const r=`nodes[${o}]`;if(e&&"object"==typeof e){if("string"==typeof e.id&&e.id.trim()?i.has(e.id)?t.push(`${r}.id is duplicated: ${e.id}`):i.add(e.id):t.push(r+".id must be a non-empty string"),"string"==typeof e.start&&/^\d{4}-\d{2}-\d{2}$/.test(e.start)||t.push(r+'.start must be a "YYYY-MM-DD" string'),void 0===e.days||Number(e.days)>=1||t.push(r+".days must be a number >= 1 when present"),void 0!==e.progress){const i=Number(e.progress);i>=0&&i<=1||t.push(r+".progress must be between 0 and 1 when present")}void 0===e.row||Number(e.row)>=0||t.push(r+".row must be a number >= 0 when present")}else t.push(r+" must be an object")}):t.push("nodes must be an array"),void 0===e.edges||Array.isArray(e.edges)?(e.edges||[]).forEach((e,o)=>{const r=`edges[${o}]`;e&&"object"==typeof e?("string"==typeof e.source&&e.source.trim()&&i.has(e.source)||t.push(r+".source must reference an existing task id"),"string"==typeof e.target&&e.target.trim()&&i.has(e.target)||t.push(r+".target must reference an existing task id")):t.push(r+" must be an object")}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const o=Number(i.gapX)||90,r=Number(i.gapY)||90,n=void 0===i.originX?80:i.originX,s=void 0===i.originY?80:i.originY,a=new Map;if(!e.length)return a;const d=new Map;e.forEach(e=>d.set(e.id,e));const l=new Map,p=new Map;e.forEach(e=>{l.set(e.id,0),p.set(e.id,[])}),t.forEach(e=>{d.has(e.sourceId)&&d.has(e.targetId)&&(l.set(e.targetId,(l.get(e.targetId)||0)+1),p.get(e.sourceId).push(e.targetId))});const h=new Map,c=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(h.set(e.id,0),c.push(e.id))}),c.length||(h.set(e[0].id,0),c.push(e[0].id));let u=e.length*e.length+e.length;for(;c.length&&u-- >0;){const e=c.shift(),t=h.get(e)||0;(p.get(e)||[]).forEach(e=>{const i=t+1;(void 0===h.get(e)?-1:h.get(e))<i&&(h.set(e,i),c.push(e))})}e.forEach(e=>{h.has(e.id)||h.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=h.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*r)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(t+(e[n]-i.width)/2),top:Math.round(d)}),d+=i.height+r}),t+=e[n]+o})}else{const e=m.map(e=>Math.max(...f.get(e).map(e=>e.height)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.width,0)+Math.max(s.length-1,0)*o)/2;s.forEach(i=>{a.set(i.id,{left:Math.round(d),top:Math.round(t+(e[n]-i.height)/2)}),d+=i.width+o}),t+=e[n]+r})}const g=Math.min(...e.map(e=>a.get(e.id).left)),y=Math.min(...e.map(e=>a.get(e.id).top));return a.forEach(e=>{e.left+=n-g,e.top+=s-y}),a}const u={terminator:{width:t.FLOW_NODE_KINDS.terminator.width,height:t.FLOW_NODE_KINDS.terminator.height,fill:t.FLOW_NODE_KINDS.terminator.fill,stroke:t.FLOW_NODE_KINDS.terminator.stroke},process:{width:t.FLOW_NODE_KINDS.process.width,height:t.FLOW_NODE_KINDS.process.height,fill:t.FLOW_NODE_KINDS.process.fill,stroke:t.FLOW_NODE_KINDS.process.stroke},decision:{width:t.FLOW_NODE_KINDS.decision.width,height:t.FLOW_NODE_KINDS.decision.height,fill:t.FLOW_NODE_KINDS.decision.fill,stroke:t.FLOW_NODE_KINDS.decision.stroke},io:{width:t.FLOW_NODE_KINDS.io.width,height:t.FLOW_NODE_KINDS.io.height,fill:t.FLOW_NODE_KINDS.io.fill,stroke:t.FLOW_NODE_KINDS.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&u[e.kind]?e.kind:"process"}(e),i=u[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(o=e,o.title||o.name||o.id),left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:i.width,height:"number"==typeof e.height?e.height:i.height,fillColor:e.fillColor||i.fill,strokeColor:e.strokeColor||i.stroke};var o}),o=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",label:e.label||"",linkShape:e.linkShape||"visio"})),r=t.layout||"layered";return"none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))&&(i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),function autoLayout(e,t,i,o){const r=layeredLayout(e,t,{gapX:i,gapY:o});e.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)})}(i,o,Number(t.gapX)||90,Number(t.gapY)||90)),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"flowchart",nodes:i,edges:o,layout:r,options:t}}const f={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},m=Number(t.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,g=Number(t.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,y=Number(t.FLOW_NODE_KINDS.bpmnLane.height)||130,b=Number(t.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(e){const i=e.kind||"task",o=function presetOf(e){return t.FLOW_NODE_KINDS[e]||t.FLOW_NODE_KINDS.bpmnTask}(f[i]||"bpmnTask"),r={id:e.id,typeId:"FlowNode",kind:f[i]||"bpmnTask",title:e.title||e.name||e.id,left:"number"==typeof e.left?e.left:0,top:"number"==typeof e.top?e.top:0,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height,fillColor:e.fillColor,strokeColor:e.strokeColor,dslKind:i,parent:e.parent,explicitLeft:"number"==typeof e.left,explicitTop:"number"==typeof e.top,explicitWidth:"number"==typeof e.width,explicitHeight:"number"==typeof e.height};return"event"===i&&(r.eventKind=e.eventKind||o.eventKind||"start",r.trigger=e.trigger||o.trigger||"none"),"gateway"===i&&(r.gatewayType=e.gatewayType||o.gatewayType||"exclusive"),"task"!==i&&"subprocess"!==i||(r.taskType=e.taskType||o.taskType||"none"),r}function buildGroups(e,t){const i=new Map;t.forEach(e=>i.set(e.id,e));const o=1===t.length?t[0]:null,r=[];return e.forEach(e=>{(e=>{let t=r.filter(t=>t.owner===e)[0];return t||(t={owner:e,nodes:[],box:null,didLayout:!1},r.push(t)),t})((e.parent?i.get(e.parent):void 0)||o).nodes.push(e)}),r}function layoutGroups(e,t,i,o){e.forEach(e=>{if(e.nodes.some(e=>!e.explicitLeft||!e.explicitTop)){const r=layeredLayout(e.nodes,t,{gapX:i,gapY:o,originX:0,originY:0,direction:"horizontal"});e.nodes.forEach(e=>{const t=r.get(e.id);t&&(e.left=t.left,e.top=t.top)}),e.didLayout=!0}e.box=function unionBox(e){if(!e.length)return null;let t=1/0,i=1/0,o=-1/0,r=-1/0;return e.forEach(e=>{t=Math.min(t,e.left),i=Math.min(i,e.top),o=Math.max(o,e.left+e.width),r=Math.max(r,e.top+e.height)}),{minX:t,minY:i,maxX:o,maxY:r}}(e.nodes)})}function compileBpmnDsl(e){const t=e.options||{},i=(e.nodes||[]).map(toWorkingNode),o=i.filter(e=>"pool"===e.dslKind),r=i.filter(e=>"lane"===e.dslKind),n=i.filter(e=>!function isContainer(e){return"pool"===e.dslKind||"lane"===e.dslKind}(e)),s=(e.edges||[]).map((e,t)=>({id:e.id||"edge-"+t,sourceId:e.source,targetId:e.target,flowType:e.type||e.flowType||"sequence",label:e.label||"",condition:e.condition||"",isDefault:!!e.isDefault,linkShape:e.linkShape||"visio"})),a=t.layout||"auto",d=function resolveLaneOwners(e,t){const i=new Map;return e.forEach(e=>{let o=e.parent;o||1!==t.length||(o=t[0].id),o&&i.set(e.id,o)}),i}(r,o),lanesOf=e=>r.filter(t=>d.get(t.id)===e);let l=[];"none"!==a&&(l=buildGroups(n,o.concat(r)),layoutGroups(l,s,Number(t.gapX)||90,Number(t.gapY)||60)),r.forEach(e=>{const t=l.filter(t=>t.owner===e)[0],i=t?t.box:null;e.explicitHeight||(e.height=Math.round(Math.max(56+(i?i.maxY-i.minY:0),y))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+g+56,b)))}),o.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),b);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=m+t.reduce((e,t)=>e+t.height,0)))}const i=l.filter(t=>t.owner===e)[0],o=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(o?o.maxX-o.minX:0),b))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+m+56,160)))});let p=60;o.forEach(e=>{e.explicitLeft||(e.left=60),e.explicitTop||(e.top=p),p=Math.max(p,e.top+e.height+60)}),o.forEach(e=>{const t=lanesOf(e.id);if(!t.length)return;const i=e.top+m,o=Math.max(e.height-m,1),r=t.reduce((e,t)=>e+(t.explicitHeight?t.height:0),0),n=t.filter(e=>!e.explicitHeight),s=n.length?Math.max(o-r,0)/n.length:0;let a=i;t.forEach(t=>{t.explicitLeft||(t.left=e.left),t.explicitTop||(t.top=a),!t.explicitHeight&&e.explicitHeight&&(t.height=Math.round(s||y)),a=t.top+t.height})});let h=60;r.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=h,h=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let o=80,r=80;i&&(o=i.left+28,r=i.top+28,"pool"===i.dslKind?r+=m:o+=g),e.nodes.forEach(e=>{e.left=Math.round(o+(e.left-t.minX)),e.top=Math.round(r+(e.top-t.minY))})});return{kind:"bpmn",nodes:o.concat(r).concat(n).map(e=>{const t={id:e.id,typeId:"FlowNode",kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};return void 0!==e.eventKind&&(t.eventKind=e.eventKind),void 0!==e.trigger&&(t.trigger=e.trigger),void 0!==e.gatewayType&&(t.gatewayType=e.gatewayType),void 0!==e.taskType&&(t.taskType=e.taskType),void 0!==e.fillColor&&(t.fillColor=e.fillColor),void 0!==e.strokeColor&&(t.strokeColor=e.strokeColor),t}),edges:s,layout:a,options:t}}function compileUmlDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{return{id:e.id,kind:(t=e,t.kind||"class"),className:e.title||e.name||e.id,abstract:!!e.abstract,attributes:Array.isArray(e.attributes)?e.attributes.map(e=>String(e)):[],methods:Array.isArray(e.methods)?e.methods.map(e=>String(e)):[],left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:240,height:"number"==typeof e.height?e.height:120+24*(e.attributes?e.attributes.length:0)+24*(e.methods?e.methods.length:0)};var t}),o=(e.edges||[]).map((e,t)=>({id:e.id||"relation-"+t,sourceId:e.source,targetId:e.target,relationKind:e.type||e.relation||"association",label:e.label||""})),r=t.layout||"layered";if("none"!==r&&i.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const e=layeredLayout(i,o.filter(e=>"inheritance"===e.relationKind||"realization"===e.relationKind).map(e=>({sourceId:e.targetId,targetId:e.sourceId})),{gapX:Number(t.gapX)||80,gapY:Number(t.gapY)||110,originX:80,originY:80,direction:"vertical"});i.forEach(t=>{const i=e.get(t.id);i&&(t.left=i.left,t.top=i.top)})}return i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)}),{kind:"uml",nodes:i,edges:o,layout:r,options:t}}const w={width:160,height:64},D={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,o="composite"===t?D:i?{width:24,height:24}:w;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height}}),o=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),r=t.layout||"auto",n=new Set;if("none"!==r){const e=new Map;i.forEach(t=>e.set(t.id,t));const r=i.filter(t=>!(t.parent&&e.has(t.parent)));if(r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=o.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(r,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});r.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...r.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let o=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(o>56&&o+e.width>56+p&&(o=56,a=l+40),n.add(e.id),e.left=o,e.top=a,o+=e.width+40,d=Math.max(d,o),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,o)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=o,offsetChildren(e,t,o))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:o,layout:r,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderGanttDsl(e,i){const o=compileGanttDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.GanttDesigner(n);return r.dayWidth&&s.setDayWidth(r.dayWidth),o.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),o.edges.forEach(e=>{s.createDependency(e)}),s.select(null),r.autoSchedule&&s.autoSchedule(),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderStatechartDsl(e,i){const o=compileStatechartDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.StatechartDesigner(n);return o.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),o.edges.forEach(e=>{s.createTransition(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"statechart",ice:n,designer:s}}function renderUmlDsl(e,i){const o=compileUmlDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.UmlDesigner(n);return o.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),o.edges.forEach(e=>{s.createRelation(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:n,designer:s}}function renderBpmnDsl(e,i){const o=compileBpmnDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.BpmnDesigner(n);return o.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),s.createNode(e.kind,t)}),o.edges.forEach(e=>{s.createEdge(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:n,designer:s}}function renderFlowDsl(e,i){const o=compileFlowDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.FlowDesigner(n);return o.nodes.forEach(e=>{s.createNode(e.kind,e)}),o.edges.forEach(e=>{s.createEdge(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:n,designer:s}}e.DSL_SCHEMA_VERSION=1,e.compileBpmnDsl=compileBpmnDsl,e.compileDsl=compileDsl,e.compileFlowDsl=compileFlowDsl,e.compileGanttDsl=compileGanttDsl,e.compileStatechartDsl=compileStatechartDsl,e.compileUmlDsl=compileUmlDsl,e.isBpmnDsl=isBpmnDsl,e.isFlowDsl=isFlowDsl,e.isGanttDsl=isGanttDsl,e.isStatechartDsl=isStatechartDsl,e.isUmlDsl=isUmlDsl,e.layeredLayout=layeredLayout,e.renderBpmnDsl=renderBpmnDsl,e.renderDsl=function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.EntityDesigner(n);o.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const o=new Map;return e.entities.forEach(e=>{o.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=o.get(e.sourceId),r=o.get(e.targetId);let n="R",s="L";if(t&&r){const e=r.center[0]-t.center[0],i=r.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,o,r.routeType).forEach(e=>{s.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new t.ICELayeredLayout({gapX:r.gapX||120,gapY:r.gapY||50}).layoutContainer(n);r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):r.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let r=1/0,n=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();r=Math.min(r,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-r,l=a-n,p=e.canvasWidth||0,h=e.canvasHeight||0;if(!p||!h||d<=0||l<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,p-2*c),f=Math.max(1,h-2*c),m=Math.min(u/d,f/l,1),g=(p-d*m)/2-r*m,y=(h-l*m)/2-n*m;e.setViewport(m,g,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(e,i)},e.renderFlowDsl=renderFlowDsl,e.renderGanttDsl=renderGanttDsl,e.renderStatechartDsl=renderStatechartDsl,e.renderUmlDsl=renderUmlDsl,e.validateBpmnDsl=validateBpmnDsl,e.validateDsl=validateDsl,e.validateFlowDsl=validateFlowDsl,e.validateGanttDsl=validateGanttDsl,e.validateStatechartDsl=validateStatechartDsl,e.validateUmlDsl=validateUmlDsl,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ice-entity-designer")):"function"==typeof define&&define.amd?define(["exports","ice-entity-designer"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ICEDSL={},e.IED)}(this,(function(e,t){"use strict";function isFlowDsl(e){return!!e&&"object"==typeof e&&"flowchart"===e.kind}function isBpmnDsl(e){return!!e&&"object"==typeof e&&"bpmn"===e.kind}function isUmlDsl(e){return!!e&&"object"==typeof e&&"uml"===e.kind}function isStatechartDsl(e){return!!e&&"object"==typeof e&&"statechart"===e.kind}function isGanttDsl(e){return!!e&&"object"==typeof e&&"gantt"===e.kind}const i=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"];function isPowerDsl(e){return!!e&&"object"==typeof e&&"power"===e.kind}const o=["terminator","process","decision","io"],r=["T","R","B","L","C"],n=["pool","lane","task","event","gateway","subprocess","dataObject","annotation"],s=["start","intermediate","end"],a=["none","message","timer","error","terminate"],d=["exclusive","parallel","inclusive","event"],l=["none","user","service","script","send","receive","manual"],p=["sequence","message","association"],c=["initial","final","state","composite"],h=["class","interface","enum"],u=["inheritance","realization","association","aggregation","composition","dependency"];function validateDsl(e){return isGanttDsl(e)?validateGanttDsl(e):isPowerDsl(e)?validatePowerDsl(e):isStatechartDsl(e)?validateStatechartDsl(e):isUmlDsl(e)?validateUmlDsl(e):isBpmnDsl(e)?validateBpmnDsl(e):isFlowDsl(e)?validateFlowDsl(e):function validateErDsl(e){const t=[];if(!e||"object"!=typeof e||Array.isArray(e))return{valid:!1,errors:["DSL root must be an object"]};void 0!==e.schemaVersion&&1!==e.schemaVersion&&t.push("Unsupported schemaVersion: "+e.schemaVersion);if(Array.isArray(e.entities)){const 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 p=`nodes[${r}]`;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",s],["trigger",a],["gatewayType",d],["taskType",l]].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===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"),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,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):t.push(n+".id must be a non-empty string"),void 0!==e.kind&&-1===o.indexOf(e.kind)&&t.push(`${n}.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(`${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===r.indexOf(e.sourcePort)&&t.push(`${n}.sourcePort must be one of ${r.join("/")}`),void 0!==e.targetPort&&-1===r.indexOf(e.targetPort)&&t.push(`${n}.targetPort must be one of ${r.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===u.indexOf(n)&&t.push(`${r}.type must be one of ${u.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===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`)})):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 validatePowerDsl(e){const t=[],o=Array.isArray(e.nodes)?e.nodes:[];Array.isArray(e.nodes)||t.push("nodes must be an array");const r=new Set;return o.forEach((e,o)=>{const n=`nodes[${o}]`;e&&"object"==typeof e?("string"==typeof e.id&&e.id?r.has(e.id)?t.push("duplicated node id: "+e.id):r.add(e.id):t.push(n+".id must be a non-empty string"),-1===i.indexOf(e.kind)&&t.push(`${n}.kind must be one of ${i.join(" / ")}`),void 0===e.voltageLevel||/^\d+(\.\d+)?kV$/.test(String(e.voltageLevel))||t.push(n+'.voltageLevel must look like "110kV"')):t.push(n+" must be an object")}),o.forEach((e,i)=>{if(!e||void 0===e.attachedTo)return;const r=o.find(t=>t&&t.id===e.attachedTo);r?"busbar"!==r.kind&&t.push(`nodes[${i}].attachedTo must point at a busbar: ${e.attachedTo} is ${r.kind}`):t.push(`nodes[${i}].attachedTo references an unknown node: ${e.attachedTo}`)}),(e.edges||[]).forEach((e,i)=>{const o=`edges[${i}]`;e&&"object"==typeof e?(r.has(e.source)||t.push(`${o}.source references an unknown node: ${e.source}`),r.has(e.target)||t.push(`${o}.target references an unknown node: ${e.target}`),e.source===e.target&&t.push(o+" must not connect a node to itself")):t.push(o+" must be an object")}),{valid:0===t.length,errors:t}}function entityName(e){return e.entityName||e.name||e.id}function relationType(e){return e.relationType||e.type||"one-to-many"}function compileDsl(e){if(isFlowDsl(e))throw new Error("compileDsl() 只处理 ER 文档;流程图文档请使用 compileFlowDsl()");if(!e||!Array.isArray(e.entities))throw new Error("ER 文档必须包含 entities 数组");return{entities:e.entities.map(e=>({id:e.id,entityName:entityName(e),fields:e.fields||[],left:e.left,top:e.top,width:e.width,height:e.height,style:e.style,headerStyle:e.headerStyle,fieldStyle:e.fieldStyle,dividerStyle:e.dividerStyle,draggable:e.draggable,interactive:e.interactive})),relations:(e.relations||[]).map((e,t)=>({id:e.id||"relation-"+t,relationType:relationType(e),sourceId:e.source,targetId:e.target,sourceField:e.sourceField||"id",targetField:e.targetField||"id",nullable:e.nullable,onDelete:e.onDelete,onUpdate:e.onUpdate,joinTableName:e.joinTableName,fromKey:e.fromKey,toKey:e.toKey,sourceCardinality:e.sourceCardinality,targetCardinality:e.targetCardinality,label:e.label,style:e.style,arrow:e.arrow,linkShape:e.linkShape,routeType:e.routeType,routeOffset:e.routeOffset,curveType:e.curveType,lineDash:e.lineDash})),layout:e.layout,options:e.options}}function layeredLayout(e,t,i={}){const 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 c=new Map,h=[];e.forEach(e=>{0===(l.get(e.id)||0)&&(c.set(e.id,0),h.push(e.id))}),h.length||(c.set(e[0].id,0),h.push(e[0].id));let u=e.length*e.length+e.length;for(;h.length&&u-- >0;){const e=h.shift(),t=c.get(e)||0;(p.get(e)||[]).forEach(e=>{const i=t+1;(void 0===c.get(e)?-1:c.get(e))<i&&(c.set(e,i),h.push(e))})}e.forEach(e=>{c.has(e.id)||c.set(e.id,0)});const f=new Map;e.forEach(e=>{const t=c.get(e.id)||0;f.has(t)||f.set(t,[]),f.get(t).push(e)});const m=[...f.keys()].sort((e,t)=>e-t);if("horizontal"===i.direction){const e=m.map(e=>Math.max(...f.get(e).map(e=>e.width)));let t=0;m.forEach((i,n)=>{const s=f.get(i);let d=-(s.reduce((e,t)=>e+t.height,0)+Math.max(s.length-1,0)*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 f={terminator:{width:t.FLOW_NODE_KINDS.terminator.width,height:t.FLOW_NODE_KINDS.terminator.height,fill:t.FLOW_NODE_KINDS.terminator.fill,stroke:t.FLOW_NODE_KINDS.terminator.stroke},process:{width:t.FLOW_NODE_KINDS.process.width,height:t.FLOW_NODE_KINDS.process.height,fill:t.FLOW_NODE_KINDS.process.fill,stroke:t.FLOW_NODE_KINDS.process.stroke},decision:{width:t.FLOW_NODE_KINDS.decision.width,height:t.FLOW_NODE_KINDS.decision.height,fill:t.FLOW_NODE_KINDS.decision.fill,stroke:t.FLOW_NODE_KINDS.decision.stroke},io:{width:t.FLOW_NODE_KINDS.io.width,height:t.FLOW_NODE_KINDS.io.height,fill:t.FLOW_NODE_KINDS.io.fill,stroke:t.FLOW_NODE_KINDS.io.stroke}};function compileFlowDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=function nodeKind$1(e){return e.kind&&f[e.kind]?e.kind:"process"}(e),i=f[t];return{id:e.id,typeId:"FlowNode",kind:t,title:(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 m={pool:"bpmnPool",lane:"bpmnLane",task:"bpmnTask",event:"bpmnEvent",gateway:"bpmnGateway",subprocess:"bpmnSubprocess",dataObject:"bpmnDataObject",annotation:"bpmnAnnotation"},g=Number(t.FLOW_NODE_KINDS.bpmnPool.bandSize)||32,y=Number(t.FLOW_NODE_KINDS.bpmnLane.bandSize)||32,b=Number(t.FLOW_NODE_KINDS.bpmnLane.height)||130,w=Number(t.FLOW_NODE_KINDS.bpmnPool.width)||900;function toWorkingNode(e){const i=e.kind||"task",o=function presetOf(e){return t.FLOW_NODE_KINDS[e]||t.FLOW_NODE_KINDS.bpmnTask}(m[i]||"bpmnTask"),r={id:e.id,typeId:"FlowNode",kind:m[i]||"bpmnTask",title:e.title||e.name||e.id,left:"number"==typeof e.left?e.left:0,top:"number"==typeof e.top?e.top:0,width:"number"==typeof e.width?e.width: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),b))),e.explicitWidth||(e.width=Math.round(Math.max((i?i.maxX-i.minX:0)+y+56,w)))}),o.forEach(e=>{const t=lanesOf(e.id);if(t.length){const i=t.reduce((e,t)=>Math.max(e,t.width),w);return e.explicitWidth||(e.width=i),e.explicitWidth&&t.forEach(t=>{t.explicitWidth||(t.width=e.width)}),void(e.explicitHeight||(e.height=g+t.reduce((e,t)=>e+t.height,0)))}const i=l.filter(t=>t.owner===e)[0],o=i?i.box:null;e.explicitWidth||(e.width=Math.round(Math.max(56+(o?o.maxX-o.minX:0),w))),e.explicitHeight||(e.height=Math.round(Math.max((o?o.maxY-o.minY:0)+g+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+g,o=Math.max(e.height-g,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||b)),a=t.top+t.height})});let c=60;r.forEach(e=>{d.get(e.id)||(e.explicitLeft||(e.left=60),e.explicitTop||(e.top=c,c=e.top+e.height+60))}),l.forEach(e=>{const t=e.box;if(!t||!e.didLayout)return;const i=e.owner;let o=80,r=80;i&&(o=i.left+28,r=i.top+28,"pool"===i.dslKind?r+=g:o+=y),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 v={width:160,height:64},D={width:500,height:200};function compileStatechartDsl(e){const t=e.options||{},i=(e.nodes||[]).map(e=>{const t=e.kind||"state",i="initial"===t||"final"===t,o="composite"===t?D:i?{width:24,height:24}:v;return{id:e.id,kind:t,title:e.title||e.name||(i?"":e.id),parent:e.parent,left:"number"==typeof e.left?e.left:Number.NaN,top:"number"==typeof e.top?e.top:Number.NaN,width:"number"==typeof e.width?e.width:o.width,height:"number"==typeof e.height?e.height:o.height}}),o=(e.edges||[]).map((e,t)=>({id:e.id||"transition-"+t,sourceId:e.source,targetId:e.target,event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label})),r=t.layout||"auto",n=new Set;if("none"!==r){const e=new Map;i.forEach(t=>e.set(t.id,t));const r=i.filter(t=>!(t.parent&&e.has(t.parent)));if(r.some(e=>Number.isNaN(e.left)||Number.isNaN(e.top))){const containerOf=t=>{let i=e.get(t);for(;i&&i.parent&&e.has(i.parent);)i=e.get(i.parent);return i?i.id:t},i=o.map(e=>({sourceId:containerOf(e.sourceId),targetId:containerOf(e.targetId)})).filter(e=>e.sourceId!==e.targetId),n=layeredLayout(r,i,{gapX:Number(t.gapX)||110,gapY:Number(t.gapY)||80,originX:80,originY:80,direction:"horizontal"});r.forEach(e=>{const t=n.get(e.id);t&&(e.left=t.left,e.top=t.top)})}let s=0;i.filter(e=>"composite"===e.kind).forEach(e=>{const t=i.filter(t=>t.parent===e.id);if(Number.isNaN(e.left)&&(e.left=80),Number.isNaN(e.top)){const t=Math.max(...r.filter(t=>t!==e&&!Number.isNaN(t.top)).map(e=>e.top+e.height),0);e.top=Math.max(t+60,80)+s,s+=e.height+60}if(!t.length)return;let o=56,a=56,d=0,l=56;const p=e.width-112;t.forEach(e=>{(Number.isNaN(e.left)||Number.isNaN(e.top))&&(o>56&&o+e.width>56+p&&(o=56,a=l+40),n.add(e.id),e.left=o,e.top=a,o+=e.width+40,d=Math.max(d,o),l=Math.max(l,a+e.height))}),e.width=Math.max(e.width,d+56),e.height=Math.max(e.height,l+56)}),i.forEach(e=>{Number.isNaN(e.left)&&(e.left=0),Number.isNaN(e.top)&&(e.top=0)});const offsetChildren=(e,t,o)=>{i.filter(t=>t.parent===e.id).forEach(e=>{n.has(e.id)&&(e.left+=t,e.top+=o,offsetChildren(e,t,o))})};i.filter(e=>"composite"===e.kind).forEach(e=>offsetChildren(e,e.left,e.top))}return{kind:"statechart",nodes:i,edges:o,layout:r,options:t}}function compileGanttDsl(e){const t=e.options||{};return{kind:"gantt",nodes:(e.nodes||[]).map((e,t)=>({id:e.id,title:e.title||e.name||e.id,start:String(e.start||""),days:"number"==typeof e.days?e.days:1,progress:"number"==typeof e.progress?e.progress:0,row:"number"==typeof e.row?e.row:t,resource:String(e.resource||"")})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function compilePowerDsl(e){const t=e.options||{},i=(e.nodes||[]).map((e,t)=>{const i=function defaultPlacement(e){return{left:120+e%6*200,top:120+160*Math.floor(e/6)}}(t);return{id:e.id,kind:e.kind,title:e.title||e.name||e.id,voltageLevel:String(e.voltageLevel||""),left:"number"==typeof e.left?e.left:i.left,top:"number"==typeof e.top?e.top:i.top,width:e.width,height:e.height,switchState:e.switchState,source:!!e.source}}),o=new Map;i.forEach(e=>o.set(e.id,e));return{kind:"power",nodes:i,edges:(e.edges||[]).map((e,t)=>({id:e.id||"conductor-"+t,sourceId:e.source,targetId:e.target,sourcePort:e.sourcePort||"B",targetPort:e.targetPort||"T",voltageLevel:e.voltageLevel||(o.get(e.source)||{}).voltageLevel||""})),attachments:(e.nodes||[]).filter(e=>!!e.attachedTo).map(e=>({deviceId:e.id,busId:String(e.attachedTo)})),options:t}}function renderGanttDsl(e,i){const o=compileGanttDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.GanttDesigner(n);return r.dayWidth&&s.setDayWidth(r.dayWidth),o.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row,resource:e.resource})}),o.edges.forEach(e=>{s.createDependency(e)}),s.select(null),r.autoSchedule&&s.autoSchedule(),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderPowerDsl(e,i){const o=compilePowerDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.PowerDesigner(n);r.voltageColors&&s.setVoltageColors(r.voltageColors);const a=new Map;return o.nodes.forEach(e=>{const t=s.createSymbol(e.kind,{name:e.title,voltageLevel:e.voltageLevel,left:e.left,top:e.top,width:e.width,height:e.height,switchState:e.switchState});e.source&&t.setState({energizedSource:!0}),a.set(e.id,t)}),o.attachments.forEach(e=>{const t=a.get(e.deviceId),i=a.get(e.busId);t&&i&&s.attachToBus(t,i)}),o.edges.forEach(e=>{const t=a.get(e.sourceId),i=a.get(e.targetId);t&&i&&s.createLine({sourceId:t.state.id,targetId:i.state.id,sourcePort:e.sourcePort,targetPort:e.targetPort,voltageLevel:e.voltageLevel})}),s.select(null),s.applyTopology(),!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"power",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.POWER_DSL_KINDS=i,e.compileBpmnDsl=compileBpmnDsl,e.compileDsl=compileDsl,e.compileFlowDsl=compileFlowDsl,e.compileGanttDsl=compileGanttDsl,e.compilePowerDsl=compilePowerDsl,e.compileStatechartDsl=compileStatechartDsl,e.compileUmlDsl=compileUmlDsl,e.isBpmnDsl=isBpmnDsl,e.isFlowDsl=isFlowDsl,e.isGanttDsl=isGanttDsl,e.isPowerDsl=isPowerDsl,e.isStatechartDsl=isStatechartDsl,e.isUmlDsl=isUmlDsl,e.layeredLayout=layeredLayout,e.renderBpmnDsl=renderBpmnDsl,e.renderDsl=function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isPowerDsl(i)?renderPowerDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const 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,c=e.canvasHeight||0;if(!p||!c||d<=0||l<=0)return;const h=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,p-2*h),f=Math.max(1,c-2*h),m=Math.min(u/d,f/l,1),g=(p-d*m)/2-r*m,y=(c-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.renderPowerDsl=renderPowerDsl,e.renderStatechartDsl=renderStatechartDsl,e.renderUmlDsl=renderUmlDsl,e.validateBpmnDsl=validateBpmnDsl,e.validateDsl=validateDsl,e.validateFlowDsl=validateFlowDsl,e.validateGanttDsl=validateGanttDsl,e.validatePowerDsl=validatePowerDsl,e.validateStatechartDsl=validateStatechartDsl,e.validateUmlDsl=validateUmlDsl,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DslPowerDocument } from '../types';
|
|
2
|
+
export declare type CompiledPowerNode = {
|
|
3
|
+
id: string;
|
|
4
|
+
kind: string;
|
|
5
|
+
title: string;
|
|
6
|
+
voltageLevel: string;
|
|
7
|
+
left: number;
|
|
8
|
+
top: number;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
switchState?: 'open' | 'closed';
|
|
12
|
+
source: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare type CompiledPowerEdge = {
|
|
15
|
+
id: string;
|
|
16
|
+
sourceId: string;
|
|
17
|
+
targetId: string;
|
|
18
|
+
sourcePort: string;
|
|
19
|
+
targetPort: string;
|
|
20
|
+
voltageLevel: string;
|
|
21
|
+
};
|
|
22
|
+
export declare type CompiledPowerAttachment = {
|
|
23
|
+
deviceId: string;
|
|
24
|
+
busId: string;
|
|
25
|
+
};
|
|
26
|
+
export declare type CompiledPowerScene = {
|
|
27
|
+
kind: 'power';
|
|
28
|
+
nodes: CompiledPowerNode[];
|
|
29
|
+
edges: CompiledPowerEdge[];
|
|
30
|
+
/** 母线 T 接:渲染时对每一条调用 `designer.attachToBus(device, bus)` */
|
|
31
|
+
attachments: CompiledPowerAttachment[];
|
|
32
|
+
options?: Record<string, any>;
|
|
33
|
+
};
|
|
34
|
+
export declare function compilePowerDsl(dsl: DslPowerDocument): CompiledPowerScene;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './types';
|
|
2
|
-
export { DSL_SCHEMA_VERSION, validateDsl, validateFlowDsl, validateBpmnDsl, validateUmlDsl, validateStatechartDsl, validateGanttDsl, } from './validate';
|
|
2
|
+
export { DSL_SCHEMA_VERSION, validateDsl, validateFlowDsl, validateBpmnDsl, validateUmlDsl, validateStatechartDsl, validateGanttDsl, validatePowerDsl, } from './validate';
|
|
3
3
|
export { compileDsl } from './compiler/dslToScene';
|
|
4
4
|
export type { CompiledScene } from './compiler/dslToScene';
|
|
5
5
|
export { compileFlowDsl } from './compiler/flowToScene';
|
|
@@ -13,6 +13,7 @@ export type { CompiledUmlScene, CompiledUmlNode, CompiledUmlEdge } from './compi
|
|
|
13
13
|
export { compileStatechartDsl } from './compiler/statechartToScene';
|
|
14
14
|
export type { CompiledStatechartScene, CompiledStatechartNode, CompiledStatechartEdge } from './compiler/statechartToScene';
|
|
15
15
|
export { compileGanttDsl } from './compiler/ganttToScene';
|
|
16
|
+
export { compilePowerDsl } from './compiler/powerToScene';
|
|
16
17
|
export type { CompiledGanttScene, CompiledGanttTask, CompiledGanttDependency } from './compiler/ganttToScene';
|
|
17
|
-
export { renderDsl, renderFlowDsl, renderBpmnDsl, renderUmlDsl, renderStatechartDsl, renderGanttDsl } from './runtime/renderDsl';
|
|
18
|
+
export { renderDsl, renderFlowDsl, renderBpmnDsl, renderUmlDsl, renderStatechartDsl, renderGanttDsl, renderPowerDsl } from './runtime/renderDsl';
|
|
18
19
|
export type { RenderDslResult, RenderErDslResult, RenderFlowDslResult, RenderBpmnDslResult, RenderUmlDslResult, RenderStatechartDslResult, RenderGanttDslResult, } from './runtime/renderDsl';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DslBpmnDocument, DslGanttDocument, DslDocument, DslFlowDocument, DslStatechartDocument, DslUmlDocument } from '../types';
|
|
1
|
+
import type { DslPowerDocument, DslBpmnDocument, DslGanttDocument, DslDocument, DslFlowDocument, DslStatechartDocument, DslUmlDocument } from '../types';
|
|
2
2
|
export declare type RenderErDslResult = {
|
|
3
3
|
kind: 'entity';
|
|
4
4
|
ice: any;
|
|
@@ -48,6 +48,14 @@ export declare function renderGanttDsl(canvasOrId: any, dsl: DslGanttDocument):
|
|
|
48
48
|
*
|
|
49
49
|
* 语义校验用 `designer.validateStatechart()`;矢量导出用 `designer.toSvg()`。
|
|
50
50
|
*/
|
|
51
|
+
/**
|
|
52
|
+
* 渲染电力一次系统图(单线图)文档。
|
|
53
|
+
*
|
|
54
|
+
* 与其它文档类型一致:DSL 只描述模型(设备 + 导体 + 母线 T 接),渲染交给
|
|
55
|
+
* ice-entity-designer 的 `PowerDesigner` —— 色标、拓扑(带电范围)、五防校验都在那边。
|
|
56
|
+
* 语义校验用 `designer.validatePower()`;矢量导出用 `designer.toSvg()`。
|
|
57
|
+
*/
|
|
58
|
+
export declare function renderPowerDsl(canvasOrId: any, dsl: DslPowerDocument): any;
|
|
51
59
|
export declare function renderStatechartDsl(canvasOrId: any, dsl: DslStatechartDocument): RenderStatechartDslResult;
|
|
52
60
|
/**
|
|
53
61
|
* 渲染 UML 类图文档:类是复合组件(成员由 state 派生),关系是六种记法之一。
|
package/dist/types/types.d.ts
CHANGED
|
@@ -345,3 +345,52 @@ export declare type DslGanttDocument = {
|
|
|
345
345
|
};
|
|
346
346
|
/** 运行时判别:带 kind: 'gantt' 的按甘特文档处理 */
|
|
347
347
|
export declare function isGanttDsl(dsl: any): dsl is DslGanttDocument;
|
|
348
|
+
/** 一次设备类型:与 ice-entity-designer 的 POWER_SYMBOL_KINDS 对齐(DSL 侧保持独立副本,
|
|
349
|
+
* 避免把渲染层依赖带进校验层;两边不一致时以 IED 为准并在 DSL 升级时同步) */
|
|
350
|
+
export declare const POWER_DSL_KINDS: readonly ["busbar", "breaker", "disconnector", "loadSwitch", "earthingSwitch", "earth", "currentTransformer", "voltageTransformer", "transformer", "fuse", "arrester", "reactor", "generator", "motor", "load", "capacitor", "arcSuppressionCoil", "threeWindingTransformer", "groundingTransformer", "groundingResistor", "cable", "cableTermination", "cubicle"];
|
|
351
|
+
export declare type PowerDslKind = (typeof POWER_DSL_KINDS)[number];
|
|
352
|
+
export declare type DslPowerNode = {
|
|
353
|
+
id: string;
|
|
354
|
+
/** 设备类型 */
|
|
355
|
+
kind: PowerDslKind;
|
|
356
|
+
/** 设备名 / 调度编号(画在符号上方) */
|
|
357
|
+
name?: string;
|
|
358
|
+
title?: string;
|
|
359
|
+
/** 电压等级:'110kV' / '10kV' …(决定色标与语义校验) */
|
|
360
|
+
voltageLevel?: string;
|
|
361
|
+
/** 挂在哪条母线上(母线 T 接;目标必须是本文件里的母线节点) */
|
|
362
|
+
attachedTo?: string;
|
|
363
|
+
/** 坐标(省略时按声明顺序给默认网格) */
|
|
364
|
+
left?: number;
|
|
365
|
+
top?: number;
|
|
366
|
+
width?: number;
|
|
367
|
+
height?: number;
|
|
368
|
+
/** 运行态:开关的分 / 合 */
|
|
369
|
+
switchState?: 'open' | 'closed';
|
|
370
|
+
/** 电源点(发电机 / 进线 / 主变电源侧) */
|
|
371
|
+
source?: boolean;
|
|
372
|
+
};
|
|
373
|
+
export declare type DslPowerEdge = {
|
|
374
|
+
id?: string;
|
|
375
|
+
source: string;
|
|
376
|
+
target: string;
|
|
377
|
+
sourcePort?: 'T' | 'R' | 'B' | 'L' | 'C';
|
|
378
|
+
targetPort?: 'T' | 'R' | 'B' | 'L' | 'C';
|
|
379
|
+
/** 导体电压等级(省略时取两端的等级) */
|
|
380
|
+
voltageLevel?: string;
|
|
381
|
+
};
|
|
382
|
+
export declare type DslPowerDocumentOptions = {
|
|
383
|
+
/** 电压等级色标覆盖 */
|
|
384
|
+
voltageColors?: Record<string, string>;
|
|
385
|
+
fitViewport?: boolean;
|
|
386
|
+
fitViewportPadding?: number;
|
|
387
|
+
};
|
|
388
|
+
export declare type DslPowerDocument = {
|
|
389
|
+
schemaVersion?: number;
|
|
390
|
+
kind: 'power';
|
|
391
|
+
nodes: DslPowerNode[];
|
|
392
|
+
edges?: DslPowerEdge[];
|
|
393
|
+
options?: DslPowerDocumentOptions;
|
|
394
|
+
};
|
|
395
|
+
/** 运行时判别:带 kind: 'power' 的按电力一次系统图文档处理 */
|
|
396
|
+
export declare function isPowerDsl(dsl: any): dsl is DslPowerDocument;
|
package/dist/types/validate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DslBpmnDocument, DslGanttDocument, DslStatechartDocument, DslUmlDocument, DslDocument, DslFlowDocument, DslValidationResult } from './types';
|
|
1
|
+
import type { DslPowerDocument, DslBpmnDocument, DslGanttDocument, DslStatechartDocument, DslUmlDocument, DslDocument, DslFlowDocument, DslValidationResult } from './types';
|
|
2
2
|
export declare const DSL_SCHEMA_VERSION = 1;
|
|
3
3
|
/**
|
|
4
4
|
* 校验一份 DSL 文档:ER(entities/relations)、流程图(kind: 'flowchart')
|
|
@@ -33,3 +33,10 @@ export declare function validateStatechartDsl(dsl: DslStatechartDocument): DslVa
|
|
|
33
33
|
* 语义检查(依赖成环等)交给 `GanttDesigner.validateGantt()`。
|
|
34
34
|
*/
|
|
35
35
|
export declare function validateGanttDsl(dsl: DslGanttDocument): DslValidationResult;
|
|
36
|
+
/**
|
|
37
|
+
* 电力一次系统图文档的结构校验(语义校验在 designer:`validatePower()`)。
|
|
38
|
+
*
|
|
39
|
+
* 这里只查「结构」:id 唯一、kind 合法、端点存在、母线 T 接指向母线、电压等级格式。
|
|
40
|
+
* 电压等级一致性、母线进线、五防这些**语义**规则属于设计器(`renderPowerDsl` 返回的 designer)。
|
|
41
|
+
*/
|
|
42
|
+
export declare function validatePowerDsl(dsl: DslPowerDocument): DslValidationResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ice-entity-designer-dsl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
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.39"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/core": "7.17.8",
|