ice-entity-designer-dsl 0.0.11 → 0.0.12

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 CHANGED
@@ -157,10 +157,15 @@ const plan = {
157
157
 
158
158
  const result = ICEDSL.renderDsl('canvas', plan);
159
159
  // result.kind === 'gantt'; result.designer is a GanttDesigner
160
- result.designer.validateGantt(); // 依赖成环 / 进度越界 / 天数非法
160
+ result.designer.validateGantt(); // 依赖成环 / 进度越界 / 天数非法 / 资源冲突
161
+ result.designer.autoSchedule(); // 自动排程:按依赖推到「前置结束之后」(只推后不提前)
162
+ result.designer.criticalPath(); // 关键路径
161
163
  result.designer.toSvg(); // 矢量导出(含日期刻度与进度)
162
164
  ```
163
165
 
166
+ `options.autoSchedule: true` 可以让**渲染时**就按依赖把排期推到最早可行(文档里写的日期当作下界),
167
+ `resource` 字段用于资源冲突检查(同一负责人时间重叠会在 `validateGantt()` 里报出)。
168
+
164
169
  Fields: `start` (`YYYY-MM-DD`, required), `days` (default 1), `progress` (0..1, default 0),
165
170
  `row` (defaults to declaration order). **Do not invent coordinates** — the timeline is derived;
166
171
  dragging a bar in the editor snaps it to whole days.
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})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderGanttDsl(t,i){const r=compileGanttDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.GanttDesigner(n);return o.dayWidth&&s.setDayWidth(o.dayWidth),r.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row})}),r.edges.forEach(e=>{s.createDependency(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderStatechartDsl(t,i){const r=compileStatechartDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.StatechartDesigner(n);return r.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{s.createTransition(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"statechart",ice:n,designer:s}}function renderUmlDsl(t,i){const r=compileUmlDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.UmlDesigner(n);return r.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),r.edges.forEach(e=>{s.createRelation(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:n,designer:s}}function renderBpmnDsl(t,i){const r=compileBpmnDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.BpmnDesigner(n);return r.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),s.createNode(e.kind,t)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:n,designer:s}}function renderFlowDsl(t,i){const r=compileFlowDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.FlowDesigner(n);return r.nodes.forEach(e=>{s.createNode(e.kind,e)}),r.edges.forEach(e=>{s.createEdge(e)}),s.select(null),o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):!1!==o.fitViewport&&s.fitViewport(o.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:n,designer:s}}exports.DSL_SCHEMA_VERSION=1,exports.compileBpmnDsl=compileBpmnDsl,exports.compileDsl=compileDsl,exports.compileFlowDsl=compileFlowDsl,exports.compileGanttDsl=compileGanttDsl,exports.compileStatechartDsl=compileStatechartDsl,exports.compileUmlDsl=compileUmlDsl,exports.isBpmnDsl=isBpmnDsl,exports.isFlowDsl=isFlowDsl,exports.isGanttDsl=isGanttDsl,exports.isStatechartDsl=isStatechartDsl,exports.isUmlDsl=isUmlDsl,exports.layeredLayout=layeredLayout,exports.renderBpmnDsl=renderBpmnDsl,exports.renderDsl=function renderDsl(t,i){const r=validateDsl(i);if(!r.valid)throw new Error(r.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(t,i):isStatechartDsl(i)?renderStatechartDsl(t,i):isUmlDsl(i)?renderUmlDsl(t,i):isBpmnDsl(i)?renderBpmnDsl(t,i):isFlowDsl(i)?renderFlowDsl(t,i):function renderErDsl(t,i){const r=compileDsl(i),o=r.options||{},n=(new e.ICE).init(t),s=new e.EntityDesigner(n);r.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const r=new Map;return e.entities.forEach(e=>{r.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=r.get(e.sourceId),o=r.get(e.targetId);let n="R",s="L";if(t&&o){const e=o.center[0]-t.center[0],i=o.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,r,o.routeType).forEach(e=>{s.createRelation(e)}),("layered"===r.layout||"horizontal"===r.layout)&&new e.ICELayeredLayout({gapX:o.gapX||120,gapY:o.gapY||50}).layoutContainer(n);o.viewport?n.setViewport(o.viewport.scale,o.viewport.tx,o.viewport.ty):o.fitViewport&&function fitViewport(e,t,i){const r=t.entities||[];let o=1/0,n=1/0,s=-1/0,a=-1/0;r.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();o=Math.min(o,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-o,p=a-n,l=e.canvasWidth||0,h=e.canvasHeight||0;if(!l||!h||d<=0||p<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,l-2*c),m=Math.max(1,h-2*c),f=Math.min(u/d,m/p,1),g=(l-d*f)/2-o*f,y=(h-p*f)/2-n*f;e.setViewport(f,g,y)}(n,s,o.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(t,i)},exports.renderFlowDsl=renderFlowDsl,exports.renderGanttDsl=renderGanttDsl,exports.renderStatechartDsl=renderStatechartDsl,exports.renderUmlDsl=renderUmlDsl,exports.validateBpmnDsl=validateBpmnDsl,exports.validateDsl=validateDsl,exports.validateFlowDsl=validateFlowDsl,exports.validateGanttDsl=validateGanttDsl,exports.validateStatechartDsl=validateStatechartDsl,exports.validateUmlDsl=validateUmlDsl;
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;
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})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),r=o.options||{},n=(new t).init(e),s=new a(n);o.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const o=new Map;return e.entities.forEach(e=>{o.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=o.get(e.sourceId),r=o.get(e.targetId);let n="R",s="L";if(t&&r){const e=r.center[0]-t.center[0],i=r.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,o,r.routeType).forEach(e=>{s.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new d({gapX:r.gapX||120,gapY:r.gapY||50}).layoutContainer(n);r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):r.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let r=1/0,n=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();r=Math.min(r,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-r,p=a-n,l=e.canvasWidth||0,h=e.canvasHeight||0;if(!l||!h||d<=0||p<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,l-2*c),f=Math.max(1,h-2*c),m=Math.min(u/d,f/p,1),g=(l-d*m)/2-r*m,y=(h-p*m)/2-n*m;e.setViewport(m,g,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(e,i)}function renderGanttDsl(e,o){const r=compileGanttDsl(o),n=r.options||{},s=(new t).init(e),a=new i(s);return n.dayWidth&&a.setDayWidth(n.dayWidth),r.nodes.forEach(e=>{a.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row})}),r.edges.forEach(e=>{a.createDependency(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"gantt",ice:s,designer:a}}function renderStatechartDsl(e,i){const r=compileStatechartDsl(i),n=r.options||{},s=(new t).init(e),a=new o(s);return r.nodes.forEach(e=>{a.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),r.edges.forEach(e=>{a.createTransition(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"statechart",ice:s,designer:a}}function renderUmlDsl(e,i){const o=compileUmlDsl(i),n=o.options||{},s=(new t).init(e),a=new r(s);return o.nodes.forEach(e=>{a.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),o.edges.forEach(e=>{a.createRelation(e)}),a.select(null),n.viewport?s.setViewport(n.viewport.scale,n.viewport.tx,n.viewport.ty):!1!==n.fitViewport&&a.fitViewport(n.fitViewportPadding),a.resetHistory(),{kind:"uml",ice:s,designer:a}}function renderBpmnDsl(e,i){const o=compileBpmnDsl(i),r=o.options||{},s=(new t).init(e),a=new n(s);return o.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),a.createNode(e.kind,t)}),o.edges.forEach(e=>{a.createEdge(e)}),a.select(null),r.viewport?s.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&a.fitViewport(r.fitViewportPadding),a.resetHistory(),{kind:"bpmn",ice:s,designer:a}}function renderFlowDsl(e,i){const o=compileFlowDsl(i),r=o.options||{},n=(new t).init(e),a=new s(n);return o.nodes.forEach(e=>{a.createNode(e.kind,e)}),o.edges.forEach(e=>{a.createEdge(e)}),a.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&a.fitViewport(r.fitViewportPadding),a.resetHistory(),{kind:"flowchart",ice:n,designer:a}}export{p as DSL_SCHEMA_VERSION,compileBpmnDsl,compileDsl,compileFlowDsl,compileGanttDsl,compileStatechartDsl,compileUmlDsl,isBpmnDsl,isFlowDsl,isGanttDsl,isStatechartDsl,isUmlDsl,layeredLayout,renderBpmnDsl,renderDsl,renderFlowDsl,renderGanttDsl,renderStatechartDsl,renderUmlDsl,validateBpmnDsl,validateDsl,validateFlowDsl,validateGanttDsl,validateStatechartDsl,validateUmlDsl};
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};
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})),edges:(e.edges||[]).map((e,t)=>({id:e.id||"dependency-"+t,sourceId:e.source,targetId:e.target})),options:t}}function renderGanttDsl(e,i){const o=compileGanttDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.GanttDesigner(n);return r.dayWidth&&s.setDayWidth(r.dayWidth),o.nodes.forEach(e=>{s.createTask({id:e.id,title:e.title,start:e.start,days:e.days,progress:e.progress,row:e.row})}),o.edges.forEach(e=>{s.createDependency(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"gantt",ice:n,designer:s}}function renderStatechartDsl(e,i){const o=compileStatechartDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.StatechartDesigner(n);return o.nodes.forEach(e=>{s.createState({id:e.id,kind:e.kind,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height})}),o.edges.forEach(e=>{s.createTransition(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"statechart",ice:n,designer:s}}function renderUmlDsl(e,i){const o=compileUmlDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.UmlDesigner(n);return o.nodes.forEach(e=>{s.createClass({id:e.id,kind:e.kind,className:e.className,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:e.left,top:e.top,width:e.width})}),o.edges.forEach(e=>{s.createRelation(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"uml",ice:n,designer:s}}function renderBpmnDsl(e,i){const o=compileBpmnDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.BpmnDesigner(n);return o.nodes.forEach(e=>{const t={id:e.id,title:e.title,left:e.left,top:e.top,width:e.width,height:e.height};["eventKind","trigger","gatewayType","taskType","fillColor","strokeColor"].forEach(i=>{void 0!==e[i]&&(t[i]=e[i])}),s.createNode(e.kind,t)}),o.edges.forEach(e=>{s.createEdge(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"bpmn",ice:n,designer:s}}function renderFlowDsl(e,i){const o=compileFlowDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.FlowDesigner(n);return o.nodes.forEach(e=>{s.createNode(e.kind,e)}),o.edges.forEach(e=>{s.createEdge(e)}),s.select(null),r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):!1!==r.fitViewport&&s.fitViewport(r.fitViewportPadding),s.resetHistory(),{kind:"flowchart",ice:n,designer:s}}e.DSL_SCHEMA_VERSION=1,e.compileBpmnDsl=compileBpmnDsl,e.compileDsl=compileDsl,e.compileFlowDsl=compileFlowDsl,e.compileGanttDsl=compileGanttDsl,e.compileStatechartDsl=compileStatechartDsl,e.compileUmlDsl=compileUmlDsl,e.isBpmnDsl=isBpmnDsl,e.isFlowDsl=isFlowDsl,e.isGanttDsl=isGanttDsl,e.isStatechartDsl=isStatechartDsl,e.isUmlDsl=isUmlDsl,e.layeredLayout=layeredLayout,e.renderBpmnDsl=renderBpmnDsl,e.renderDsl=function renderDsl(e,i){const o=validateDsl(i);if(!o.valid)throw new Error(o.errors.join("\n"));return isGanttDsl(i)?renderGanttDsl(e,i):isStatechartDsl(i)?renderStatechartDsl(e,i):isUmlDsl(i)?renderUmlDsl(e,i):isBpmnDsl(i)?renderBpmnDsl(e,i):isFlowDsl(i)?renderFlowDsl(e,i):function renderErDsl(e,i){const o=compileDsl(i),r=o.options||{},n=(new t.ICE).init(e),s=new t.EntityDesigner(n);o.entities.forEach(e=>{s.createEntity(e)}),function positionLinks(e,t,i){const o=new Map;return e.entities.forEach(e=>{o.set(e.state.id,e.getMinBoundingBox(!0))}),t.relations.map(e=>{const t=o.get(e.sourceId),r=o.get(e.targetId);let n="R",s="L";if(t&&r){const e=r.center[0]-t.center[0],i=r.center[1]-t.center[1];Math.abs(e)>Math.abs(i)?(n=e>=0?"R":"L",s=e>=0?"L":"R"):(n=i>=0?"B":"T",s=i>=0?"T":"B")}return{...e,routeType:e.routeType||i||"orthogonal",linkShape:e.linkShape||"visio",links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}}}})}(s,o,r.routeType).forEach(e=>{s.createRelation(e)}),("layered"===o.layout||"horizontal"===o.layout)&&new t.ICELayeredLayout({gapX:r.gapX||120,gapY:r.gapY||50}).layoutContainer(n);r.viewport?n.setViewport(r.viewport.scale,r.viewport.tx,r.viewport.ty):r.fitViewport&&function fitViewport(e,t,i){const o=t.entities||[];let r=1/0,n=1/0,s=-1/0,a=-1/0;o.forEach(e=>{const t=e.getMinBoundingBox(!0).getMinAndMaxPoint();r=Math.min(r,t.minX),n=Math.min(n,t.minY),s=Math.max(s,t.maxX),a=Math.max(a,t.maxY)});const d=s-r,l=a-n,p=e.canvasWidth||0,h=e.canvasHeight||0;if(!p||!h||d<=0||l<=0)return;const c=Number.isFinite(i)&&i>=0?i:40,u=Math.max(1,p-2*c),f=Math.max(1,h-2*c),m=Math.min(u/d,f/l,1),g=(p-d*m)/2-r*m,y=(h-l*m)/2-n*m;e.setViewport(m,g,y)}(n,s,r.fitViewportPadding);return{kind:"entity",ice:n,designer:s}}(e,i)},e.renderFlowDsl=renderFlowDsl,e.renderGanttDsl=renderGanttDsl,e.renderStatechartDsl=renderStatechartDsl,e.renderUmlDsl=renderUmlDsl,e.validateBpmnDsl=validateBpmnDsl,e.validateDsl=validateDsl,e.validateFlowDsl=validateFlowDsl,e.validateGanttDsl=validateGanttDsl,e.validateStatechartDsl=validateStatechartDsl,e.validateUmlDsl=validateUmlDsl,Object.defineProperty(e,"__esModule",{value:!0})}));
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})}));
@@ -6,6 +6,7 @@ export declare type CompiledGanttTask = {
6
6
  days: number;
7
7
  progress: number;
8
8
  row: number;
9
+ resource: string;
9
10
  };
10
11
  export declare type CompiledGanttDependency = {
11
12
  id: string;
@@ -315,6 +315,8 @@ export declare type DslGanttTask = {
315
315
  progress?: number;
316
316
  /** 行号(0 起);缺省按声明顺序 */
317
317
  row?: number;
318
+ /** 负责人 / 资源名(用于资源冲突检查;空表示不参与) */
319
+ resource?: string;
318
320
  };
319
321
  export declare type DslGanttDependency = {
320
322
  id?: string;
@@ -331,6 +333,8 @@ export declare type DslGanttDocumentOptions = {
331
333
  };
332
334
  /** 每天多少像素,默认 28 */
333
335
  dayWidth?: number;
336
+ /** 渲染时按依赖自动排程(把任务推到前置结束之后),默认 false */
337
+ autoSchedule?: boolean;
334
338
  };
335
339
  export declare type DslGanttDocument = {
336
340
  schemaVersion?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ice-entity-designer-dsl",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
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.26"
22
+ "ice-entity-designer": "^0.0.27"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@babel/core": "7.17.8",