ice-entity-designer 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.mjs +1 -1
- package/dist/types/designer/EntityDesigner.d.mts +23 -0
- package/dist/types/designer/EntityDesigner.d.ts +23 -0
- package/dist/types/flow/FlowNode.d.mts +22 -0
- package/dist/types/flow/FlowNode.d.ts +22 -0
- package/dist/types/statechart/StateNode.d.mts +10 -0
- package/dist/types/statechart/StateNode.d.ts +10 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
"use strict";var e,t,i=require("ice-render"),n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s,r,a,o,l,h,d,c,u,p,f,g,m,y,_,b,v,k,w,S,C,x,I,T,E,P,M,D,$,B,N,O,L,z,A,W,q,j,F,R,H,G,U,K,V,Y,X,J,Q,Z,ee,te,ie,ne,se,re,ae,oe,le,he,de,ce,ue,pe,fe,ge,me,ye,_e,be,ve,ke,we,Se,Ce,xe,Ie,Te,Ee,Pe,Me,De,$e,Be,Ne,Oe,Le,ze,Ae,We,qe,je,Fe,Re,He,Ge,Ue,Ke,Ve=getDefaultExportFromCjs(function requireIsNil(){return t?e:(t=1,e=function isNil(e){return null==e})}());function requireEq(){if(o)return a;return o=1,a=function eq(e,t){return e===t||e!=e&&t!=t}}function require_assocIndexOf(){if(h)return l;h=1;var e=requireEq();return l=function assocIndexOf(t,i){for(var n=t.length;n--;)if(e(t[n][0],i))return n;return-1}}function require_ListCache(){if(b)return _;b=1;var e=function require_listCacheClear(){return r?s:(r=1,s=function listCacheClear(){this.__data__=[],this.size=0})}(),t=function require_listCacheDelete(){if(c)return d;c=1;var e=require_assocIndexOf(),t=Array.prototype.splice;return d=function listCacheDelete(i){var n=this.__data__,s=e(n,i);return!(s<0||(s==n.length-1?n.pop():t.call(n,s,1),--this.size,0))}}(),i=function require_listCacheGet(){if(p)return u;p=1;var e=require_assocIndexOf();return u=function listCacheGet(t){var i=this.__data__,n=e(i,t);return n<0?void 0:i[n][1]}}(),n=function require_listCacheHas(){if(g)return f;g=1;var e=require_assocIndexOf();return f=function listCacheHas(t){return e(this.__data__,t)>-1}}(),a=function require_listCacheSet(){if(y)return m;y=1;var e=require_assocIndexOf();return m=function listCacheSet(t,i){var n=this.__data__,s=e(n,t);return s<0?(++this.size,n.push([t,i])):n[s][1]=i,this}}();function ListCache(e){var t=-1,i=null==e?0:e.length;for(this.clear();++t<i;){var n=e[t];this.set(n[0],n[1])}}return ListCache.prototype.clear=e,ListCache.prototype.delete=t,ListCache.prototype.get=i,ListCache.prototype.has=n,ListCache.prototype.set=a,_=ListCache}function require_freeGlobal(){if(P)return E;P=1;var e="object"==typeof n&&n&&n.Object===Object&&n;return E=e}function require_root(){if(D)return M;D=1;var e=require_freeGlobal(),t="object"==typeof self&&self&&self.Object===Object&&self,i=e||t||Function("return this")();return M=i}function require_Symbol(){if(B)return $;B=1;var e=require_root().Symbol;return $=e}function require_baseGetTag(){if(W)return A;W=1;var e=require_Symbol(),t=function require_getRawTag(){if(O)return N;O=1;var e=require_Symbol(),t=Object.prototype,i=t.hasOwnProperty,n=t.toString,s=e?e.toStringTag:void 0;return N=function getRawTag(e){var t=i.call(e,s),r=e[s];try{e[s]=void 0;var a=!0}catch(e){}var o=n.call(e);return a&&(t?e[s]=r:delete e[s]),o}}(),i=function require_objectToString(){if(z)return L;z=1;var e=Object.prototype.toString;return L=function objectToString(t){return e.call(t)}}(),n=e?e.toStringTag:void 0;return A=function baseGetTag(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":n&&n in Object(e)?t(e):i(e)}}function requireIsObject(){if(j)return q;return j=1,q=function isObject(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}}function requireIsFunction(){if(R)return F;R=1;var e=require_baseGetTag(),t=requireIsObject();return F=function isFunction(i){if(!t(i))return!1;var n=e(i);return"[object Function]"==n||"[object GeneratorFunction]"==n||"[object AsyncFunction]"==n||"[object Proxy]"==n}}function require_isMasked(){if(K)return U;K=1;var e,t=function require_coreJsData(){if(G)return H;G=1;var e=require_root()["__core-js_shared__"];return H=e}(),i=(e=/[^.]+$/.exec(t&&t.keys&&t.keys.IE_PROTO||""))?"Symbol(src)_1."+e:"";return U=function isMasked(e){return!!i&&i in e}}function require_baseIsNative(){if(J)return X;J=1;var e=requireIsFunction(),t=require_isMasked(),i=requireIsObject(),n=function require_toSource(){if(Y)return V;Y=1;var e=Function.prototype.toString;return V=function toSource(t){if(null!=t){try{return e.call(t)}catch(e){}try{return t+""}catch(e){}}return""}}(),s=/^\[object .+?Constructor\]$/,r=Function.prototype,a=Object.prototype,o=r.toString,l=a.hasOwnProperty,h=RegExp("^"+o.call(l).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");return X=function baseIsNative(r){return!(!i(r)||t(r))&&(e(r)?h:s).test(n(r))}}function require_getNative(){if(te)return ee;te=1;var e=require_baseIsNative(),t=function require_getValue(){return Z?Q:(Z=1,Q=function getValue(e,t){return null==e?void 0:e[t]})}();return ee=function getNative(i,n){var s=t(i,n);return e(s)?s:void 0}}function require_Map(){if(ne)return ie;ne=1;var e=require_getNative()(require_root(),"Map");return ie=e}function require_nativeCreate(){if(re)return se;re=1;var e=require_getNative()(Object,"create");return se=e}function require_Hash(){if(ye)return me;ye=1;var e=function require_hashClear(){if(oe)return ae;oe=1;var e=require_nativeCreate();return ae=function hashClear(){this.__data__=e?e(null):{},this.size=0}}(),t=function require_hashDelete(){return he?le:(he=1,le=function hashDelete(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t})}(),i=function require_hashGet(){if(ce)return de;ce=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return de=function hashGet(i){var n=this.__data__;if(e){var s=n[i];return"__lodash_hash_undefined__"===s?void 0:s}return t.call(n,i)?n[i]:void 0}}(),n=function require_hashHas(){if(pe)return ue;pe=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return ue=function hashHas(i){var n=this.__data__;return e?void 0!==n[i]:t.call(n,i)}}(),s=function require_hashSet(){if(ge)return fe;ge=1;var e=require_nativeCreate();return fe=function hashSet(t,i){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=e&&void 0===i?"__lodash_hash_undefined__":i,this}}();function Hash(e){var t=-1,i=null==e?0:e.length;for(this.clear();++t<i;){var n=e[t];this.set(n[0],n[1])}}return Hash.prototype.clear=e,Hash.prototype.delete=t,Hash.prototype.get=i,Hash.prototype.has=n,Hash.prototype.set=s,me=Hash}function require_getMapData(){if(Se)return we;Se=1;var e=function require_isKeyable(){return ke?ve:(ke=1,ve=function isKeyable(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e})}();return we=function getMapData(t,i){var n=t.__data__;return e(i)?n["string"==typeof i?"string":"hash"]:n.map}}function require_MapCache(){if(Be)return $e;Be=1;var e=function require_mapCacheClear(){if(be)return _e;be=1;var e=require_Hash(),t=require_ListCache(),i=require_Map();return _e=function mapCacheClear(){this.size=0,this.__data__={hash:new e,map:new(i||t),string:new e}}}(),t=function require_mapCacheDelete(){if(xe)return Ce;xe=1;var e=require_getMapData();return Ce=function mapCacheDelete(t){var i=e(this,t).delete(t);return this.size-=i?1:0,i}}(),i=function require_mapCacheGet(){if(Te)return Ie;Te=1;var e=require_getMapData();return Ie=function mapCacheGet(t){return e(this,t).get(t)}}(),n=function require_mapCacheHas(){if(Pe)return Ee;Pe=1;var e=require_getMapData();return Ee=function mapCacheHas(t){return e(this,t).has(t)}}(),s=function require_mapCacheSet(){if(De)return Me;De=1;var e=require_getMapData();return Me=function mapCacheSet(t,i){var n=e(this,t),s=n.size;return n.set(t,i),this.size+=n.size==s?0:1,this}}();function MapCache(e){var t=-1,i=null==e?0:e.length;for(this.clear();++t<i;){var n=e[t];this.set(n[0],n[1])}}return MapCache.prototype.clear=e,MapCache.prototype.delete=t,MapCache.prototype.get=i,MapCache.prototype.has=n,MapCache.prototype.set=s,$e=MapCache}function require_Stack(){if(ze)return Le;ze=1;var e=require_ListCache(),t=function require_stackClear(){if(k)return v;k=1;var e=require_ListCache();return v=function stackClear(){this.__data__=new e,this.size=0}}(),i=function require_stackDelete(){return S?w:(S=1,w=function stackDelete(e){var t=this.__data__,i=t.delete(e);return this.size=t.size,i})}(),n=function require_stackGet(){return x?C:(x=1,C=function stackGet(e){return this.__data__.get(e)})}(),s=function require_stackHas(){return T?I:(T=1,I=function stackHas(e){return this.__data__.has(e)})}(),r=function require_stackSet(){if(Oe)return Ne;Oe=1;var e=require_ListCache(),t=require_Map(),i=require_MapCache();return Ne=function stackSet(n,s){var r=this.__data__;if(r instanceof e){var a=r.__data__;if(!t||a.length<199)return a.push([n,s]),this.size=++r.size,this;r=this.__data__=new i(a)}return r.set(n,s),this.size=r.size,this}}();function Stack(t){var i=this.__data__=new e(t);this.size=i.size}return Stack.prototype.clear=t,Stack.prototype.delete=i,Stack.prototype.get=n,Stack.prototype.has=s,Stack.prototype.set=r,Le=Stack}function require_defineProperty(){if(We)return Ae;We=1;var e=require_getNative(),t=function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch(e){}}();return Ae=t}function require_baseAssignValue(){if(je)return qe;je=1;var e=require_defineProperty();return qe=function baseAssignValue(t,i,n){"__proto__"==i&&e?e(t,i,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[i]=n}}function require_assignMergeValue(){if(Re)return Fe;Re=1;var e=require_baseAssignValue(),t=requireEq();return Fe=function assignMergeValue(i,n,s){(void 0!==s&&!t(i[n],s)||void 0===s&&!(n in i))&&e(i,n,s)}}function require_baseFor(){if(Ke)return Ue;Ke=1;var e=function require_createBaseFor(){return Ge?He:(Ge=1,He=function createBaseFor(e){return function(t,i,n){for(var s=-1,r=Object(t),a=n(t),o=a.length;o--;){var l=a[e?o:++s];if(!1===i(r[l],l,r))break}return t}})}()();return Ue=e}var Ye,Xe,Je,Qe,Ze,et,tt,it,nt,st,rt,at,ot,lt,ht,dt,ct,ut,pt,ft,gt,mt,yt,_t,bt,vt,kt,wt,St,Ct,xt,It,Tt,Et={exports:{}};function require_cloneArrayBuffer(){if(Ze)return Qe;Ze=1;var e=function require_Uint8Array(){if(Je)return Xe;Je=1;var e=require_root().Uint8Array;return Xe=e}();return Qe=function cloneArrayBuffer(t){var i=new t.constructor(t.byteLength);return new e(i).set(new e(t)),i}}function require_getPrototype(){if(ht)return lt;ht=1;var e=function require_overArg(){return ot?at:(ot=1,at=function overArg(e,t){return function(i){return e(t(i))}})}()(Object.getPrototypeOf,Object);return lt=e}function require_isPrototype(){if(ct)return dt;ct=1;var e=Object.prototype;return dt=function isPrototype(t){var i=t&&t.constructor;return t===("function"==typeof i&&i.prototype||e)}}function require_initCloneObject(){if(pt)return ut;pt=1;var e=function require_baseCreate(){if(rt)return st;rt=1;var e=requireIsObject(),t=Object.create,i=function(){function object(){}return function(i){if(!e(i))return{};if(t)return t(i);object.prototype=i;var n=new object;return object.prototype=void 0,n}}();return st=i}(),t=require_getPrototype(),i=require_isPrototype();return ut=function initCloneObject(n){return"function"!=typeof n.constructor||i(n)?{}:e(t(n))}}function requireIsObjectLike(){if(gt)return ft;return gt=1,ft=function isObjectLike(e){return null!=e&&"object"==typeof e}}function requireIsArguments(){if(bt)return _t;bt=1;var e=function require_baseIsArguments(){if(yt)return mt;yt=1;var e=require_baseGetTag(),t=requireIsObjectLike();return mt=function baseIsArguments(i){return t(i)&&"[object Arguments]"==e(i)}}(),t=requireIsObjectLike(),i=Object.prototype,n=i.hasOwnProperty,s=i.propertyIsEnumerable,r=e(function(){return arguments}())?e:function(e){return t(e)&&n.call(e,"callee")&&!s.call(e,"callee")};return _t=r}function requireIsArray(){if(kt)return vt;kt=1;var e=Array.isArray;return vt=e}function requireIsLength(){if(St)return wt;St=1;return wt=function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}}function requireIsArrayLike(){if(xt)return Ct;xt=1;var e=requireIsFunction(),t=requireIsLength();return Ct=function isArrayLike(i){return null!=i&&t(i.length)&&!e(i)}}var Pt,Mt,Dt,$t,Bt,Nt,Ot,Lt,zt,At={exports:{}};function requireIsBuffer(){return Dt||(Dt=1,function(e,t){var i=require_root(),n=function requireStubFalse(){return Mt?Pt:(Mt=1,Pt=function stubFalse(){return!1})}(),s=t&&!t.nodeType&&t,r=s&&e&&!e.nodeType&&e,a=r&&r.exports===s?i.Buffer:void 0,o=(a?a.isBuffer:void 0)||n;e.exports=o}(At,At.exports)),At.exports}var Wt,qt,jt,Ft,Rt,Ht,Gt,Ut,Kt,Vt,Yt,Xt,Jt,Qt,Zt,ei,ti,ii,ni,si,ri,ai,oi,li,hi,di,ci,ui,pi,fi,gi,mi,yi,_i,bi,vi,ki,wi,Si,Ci,xi,Ii,Ti,Ei,Pi,Mi,Di,$i,Bi,Ni={exports:{}};function requireIsTypedArray(){if(jt)return qt;jt=1;var e=function require_baseIsTypedArray(){if(Ot)return Nt;Ot=1;var e=require_baseGetTag(),t=requireIsLength(),i=requireIsObjectLike(),n={};return n["[object Float32Array]"]=n["[object Float64Array]"]=n["[object Int8Array]"]=n["[object Int16Array]"]=n["[object Int32Array]"]=n["[object Uint8Array]"]=n["[object Uint8ClampedArray]"]=n["[object Uint16Array]"]=n["[object Uint32Array]"]=!0,n["[object Arguments]"]=n["[object Array]"]=n["[object ArrayBuffer]"]=n["[object Boolean]"]=n["[object DataView]"]=n["[object Date]"]=n["[object Error]"]=n["[object Function]"]=n["[object Map]"]=n["[object Number]"]=n["[object Object]"]=n["[object RegExp]"]=n["[object Set]"]=n["[object String]"]=n["[object WeakMap]"]=!1,Nt=function baseIsTypedArray(s){return i(s)&&t(s.length)&&!!n[e(s)]}}(),t=function require_baseUnary(){return zt?Lt:(zt=1,Lt=function baseUnary(e){return function(t){return e(t)}})}(),i=function require_nodeUtil(){return Wt||(Wt=1,function(e,t){var i=require_freeGlobal(),n=t&&!t.nodeType&&t,s=n&&e&&!e.nodeType&&e,r=s&&s.exports===n&&i.process,a=function(){try{return s&&s.require&&s.require("util").types||r&&r.binding&&r.binding("util")}catch(e){}}();e.exports=a}(Ni,Ni.exports)),Ni.exports}(),n=i&&i.isTypedArray,s=n?t(n):e;return qt=s}function require_safeGet(){if(Rt)return Ft;return Rt=1,Ft=function safeGet(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}}function require_copyObject(){if(Kt)return Ut;Kt=1;var e=function require_assignValue(){if(Gt)return Ht;Gt=1;var e=require_baseAssignValue(),t=requireEq(),i=Object.prototype.hasOwnProperty;return Ht=function assignValue(n,s,r){var a=n[s];i.call(n,s)&&t(a,r)&&(void 0!==r||s in n)||e(n,s,r)}}(),t=require_baseAssignValue();return Ut=function copyObject(i,n,s,r){var a=!s;s||(s={});for(var o=-1,l=n.length;++o<l;){var h=n[o],d=r?r(s[h],i[h],h,s,i):void 0;void 0===d&&(d=i[h]),a?t(s,h,d):e(s,h,d)}return s}}function require_isIndex(){if(Jt)return Xt;Jt=1;var e=/^(?:0|[1-9]\d*)$/;return Xt=function isIndex(t,i){var n=typeof t;return!!(i=null==i?9007199254740991:i)&&("number"==n||"symbol"!=n&&e.test(t))&&t>-1&&t%1==0&&t<i}}function require_arrayLikeKeys(){if(Zt)return Qt;Zt=1;var e=function require_baseTimes(){return Yt?Vt:(Yt=1,Vt=function baseTimes(e,t){for(var i=-1,n=Array(e);++i<e;)n[i]=t(i);return n})}(),t=requireIsArguments(),i=requireIsArray(),n=requireIsBuffer(),s=require_isIndex(),r=requireIsTypedArray(),a=Object.prototype.hasOwnProperty;return Qt=function arrayLikeKeys(o,l){var h=i(o),d=!h&&t(o),c=!h&&!d&&n(o),u=!h&&!d&&!c&&r(o),p=h||d||c||u,f=p?e(o.length,String):[],g=f.length;for(var m in o)!l&&!a.call(o,m)||p&&("length"==m||c&&("offset"==m||"parent"==m)||u&&("buffer"==m||"byteLength"==m||"byteOffset"==m)||s(m,g))||f.push(m);return f}}function require_baseKeysIn(){if(ni)return ii;ni=1;var e=requireIsObject(),t=require_isPrototype(),i=function require_nativeKeysIn(){return ti?ei:(ti=1,ei=function nativeKeysIn(e){var t=[];if(null!=e)for(var i in Object(e))t.push(i);return t})}(),n=Object.prototype.hasOwnProperty;return ii=function baseKeysIn(s){if(!e(s))return i(s);var r=t(s),a=[];for(var o in s)("constructor"!=o||!r&&n.call(s,o))&&a.push(o);return a}}function requireKeysIn(){if(ri)return si;ri=1;var e=require_arrayLikeKeys(),t=require_baseKeysIn(),i=requireIsArrayLike();return si=function keysIn(n){return i(n)?e(n,!0):t(n)}}function require_baseMergeDeep(){if(hi)return li;hi=1;var e=require_assignMergeValue(),t=function require_cloneBuffer(){return Ye||(Ye=1,function(e,t){var i=require_root(),n=t&&!t.nodeType&&t,s=n&&e&&!e.nodeType&&e,r=s&&s.exports===n?i.Buffer:void 0,a=r?r.allocUnsafe:void 0;e.exports=function cloneBuffer(e,t){if(t)return e.slice();var i=e.length,n=a?a(i):new e.constructor(i);return e.copy(n),n}}(Et,Et.exports)),Et.exports}(),i=function require_cloneTypedArray(){if(tt)return et;tt=1;var e=require_cloneArrayBuffer();return et=function cloneTypedArray(t,i){var n=i?e(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}}(),n=function require_copyArray(){return nt?it:(nt=1,it=function copyArray(e,t){var i=-1,n=e.length;for(t||(t=Array(n));++i<n;)t[i]=e[i];return t})}(),s=require_initCloneObject(),r=requireIsArguments(),a=requireIsArray(),o=function requireIsArrayLikeObject(){if(Tt)return It;Tt=1;var e=requireIsArrayLike(),t=requireIsObjectLike();return It=function isArrayLikeObject(i){return t(i)&&e(i)}}(),l=requireIsBuffer(),h=requireIsFunction(),d=requireIsObject(),c=function requireIsPlainObject(){if(Bt)return $t;Bt=1;var e=require_baseGetTag(),t=require_getPrototype(),i=requireIsObjectLike(),n=Function.prototype,s=Object.prototype,r=n.toString,a=s.hasOwnProperty,o=r.call(Object);return $t=function isPlainObject(n){if(!i(n)||"[object Object]"!=e(n))return!1;var s=t(n);if(null===s)return!0;var l=a.call(s,"constructor")&&s.constructor;return"function"==typeof l&&l instanceof l&&r.call(l)==o}}(),u=requireIsTypedArray(),p=require_safeGet(),f=function requireToPlainObject(){if(oi)return ai;oi=1;var e=require_copyObject(),t=requireKeysIn();return ai=function toPlainObject(i){return e(i,t(i))}}();return li=function baseMergeDeep(g,m,y,_,b,v,k){var w=p(g,y),S=p(m,y),C=k.get(S);if(C)e(g,y,C);else{var x=v?v(w,S,y+"",g,m,k):void 0,I=void 0===x;if(I){var T=a(S),E=!T&&l(S),P=!T&&!E&&u(S);x=S,T||E||P?a(w)?x=w:o(w)?x=n(w):E?(I=!1,x=t(S,!0)):P?(I=!1,x=i(S,!0)):x=[]:c(S)||r(S)?(x=w,r(w)?x=f(w):d(w)&&!h(w)||(x=s(S))):I=!1}I&&(k.set(S,x),b(x,S,_,v,k),k.delete(S)),e(g,y,x)}}}function requireIdentity(){if(pi)return ui;return pi=1,ui=function identity(e){return e}}function require_overRest(){if(yi)return mi;yi=1;var e=function require_apply(){return gi?fi:(gi=1,fi=function apply(e,t,i){switch(i.length){case 0:return e.call(t);case 1:return e.call(t,i[0]);case 2:return e.call(t,i[0],i[1]);case 3:return e.call(t,i[0],i[1],i[2])}return e.apply(t,i)})}(),t=Math.max;return mi=function overRest(i,n,s){return n=t(void 0===n?i.length-1:n,0),function(){for(var r=arguments,a=-1,o=t(r.length-n,0),l=Array(o);++a<o;)l[a]=r[n+a];a=-1;for(var h=Array(n+1);++a<n;)h[a]=r[a];return h[n]=s(l),e(i,this,h)}},mi}function require_baseSetToString(){if(ki)return vi;ki=1;var e=function requireConstant(){return bi?_i:(bi=1,_i=function constant(e){return function(){return e}})}(),t=require_defineProperty(),i=requireIdentity();return vi=t?function(i,n){return t(i,"toString",{configurable:!0,enumerable:!1,value:e(n),writable:!0})}:i}function require_setToString(){if(xi)return Ci;xi=1;var e=require_baseSetToString(),t=function require_shortOut(){if(Si)return wi;Si=1;var e=Date.now;return wi=function shortOut(t){var i=0,n=0;return function(){var s=e(),r=16-(s-n);if(n=s,r>0){if(++i>=800)return arguments[0]}else i=0;return t.apply(void 0,arguments)}},wi}(),i=t(e);return Ci=i}function require_createAssigner(){if(Di)return Mi;Di=1;var e=function require_baseRest(){if(Ti)return Ii;Ti=1;var e=requireIdentity(),t=require_overRest(),i=require_setToString();return Ii=function baseRest(n,s){return i(t(n,s,e),n+"")}}(),t=function require_isIterateeCall(){if(Pi)return Ei;Pi=1;var e=requireEq(),t=requireIsArrayLike(),i=require_isIndex(),n=requireIsObject();return Ei=function isIterateeCall(s,r,a){if(!n(a))return!1;var o=typeof r;return!!("number"==o?t(a)&&i(r,a.length):"string"==o&&r in a)&&e(a[r],s)}}();return Mi=function createAssigner(i){return e(function(e,n){var s=-1,r=n.length,a=r>1?n[r-1]:void 0,o=r>2?n[2]:void 0;for(a=i.length>3&&"function"==typeof a?(r--,a):void 0,o&&t(n[0],n[1],o)&&(a=r<3?void 0:a,r=1),e=Object(e);++s<r;){var l=n[s];l&&i(e,l,s,a)}return e})}}var Oi=function requireMerge(){if(Bi)return $i;Bi=1;var e=function require_baseMerge(){if(ci)return di;ci=1;var e=require_Stack(),t=require_assignMergeValue(),i=require_baseFor(),n=require_baseMergeDeep(),s=requireIsObject(),r=requireKeysIn(),a=require_safeGet();return di=function baseMerge(o,l,h,d,c){o!==l&&i(l,function(i,r){if(c||(c=new e),s(i))n(o,l,r,h,baseMerge,d,c);else{var u=d?d(a(o,r),i,r+"",o,l,c):void 0;void 0===u&&(u=i),t(o,r,u)}},r)},di}(),t=require_createAssigner()(function(t,i,n){e(t,i,n)});return $i=t}(),Li=getDefaultExportFromCjs(Oi);class Entity extends i.ICEGroup{static typeId="ice-entity-designer:Entity";hasDerivedChildren(){return!0}entityFieldsComponent=[];constructor(e){super(Entity.arrangeParam(e)),this.syncEntityNameAndFields()}static arrangeParam(e){const t=Li({entityName:"Entity Name",fields:[],style:{strokeStyle:"#334155",fillStyle:"#ffffff",radius:8,lineWidth:1.5},headerStyle:{textColor:"#0f172a",backgroundColor:"#f1f5f9",fontSize:18,fontWeight:"bold",paddingTop:12,paddingLeft:14,paddingRight:14,paddingBottom:12},fieldStyle:{textColor:"#334155",fontSize:16,fontWeight:"normal",paddingTop:9,paddingLeft:14,paddingRight:14},dividerStyle:{strokeStyle:"#cbd5e1",fillStyle:"#cbd5e1",lineWidth:1}},e,{transformable:!1});return Ve(t.entityName)&&(t.entityName="Entity Name"),Ve(t.fields)&&(t.fields=[]),t}syncEntityNameAndFields(){if(this.entityNameComponent&&(this.removeChild(this.entityNameComponent),this.entityNameComponent=null),this.headerBackgroundComponent&&(this.removeChild(this.headerBackgroundComponent),this.headerBackgroundComponent=null),this.deviderLine&&(this.removeChild(this.deviderLine),this.deviderLine=null),this.entityFieldsComponent.length&&(this.removeChildren(this.entityFieldsComponent),this.entityFieldsComponent.length=0),this.state.entityName){if(this.entityNameComponent=new i.ICEText({left:0,top:0,text:this.state.entityName,style:{strokeStyle:this.state.headerStyle.textColor,fillStyle:this.state.headerStyle.textColor,fontSize:this.state.headerStyle.fontSize,fontWeight:this.state.headerStyle.fontWeight,paddingTop:this.state.headerStyle.paddingTop,paddingLeft:this.state.headerStyle.paddingLeft,paddingRight:this.state.headerStyle.paddingRight,paddingBottom:this.state.headerStyle.paddingBottom},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1}),this.state.headerStyle.backgroundColor&&"none"!==this.state.headerStyle.backgroundColor){const e=this.state.style.lineWidth||1.5,t=e/2;this.headerBackgroundComponent=new i.ICERect({left:t,top:t,width:Math.max(this.state.width-e,0),height:Math.max(this.entityNameComponent.state.height-t,0),zIndex:(Number(this.entityNameComponent.state.zIndex)||0)-1,origin:"top-left",style:{fillStyle:this.state.headerStyle.backgroundColor,radius:Math.max((this.state.style.radius||0)-t,0),lineWidth:0},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1}),this.addChild(this.headerBackgroundComponent)}this.addChild(this.entityNameComponent),this.deviderLine=new i.ICEPolyLine({left:0,top:0,points:[[0,0],[this.state.width,0]],style:{strokeStyle:this.state.dividerStyle.strokeStyle,fillStyle:this.state.dividerStyle.fillStyle,lineWidth:this.state.dividerStyle.lineWidth},interactive:!1,linkable:!1}),this.addChild(this.deviderLine)}if(!Ve(this.state.fields)){const e=this.state.fields.length;for(let t=0;t<e;t++){const n=this.state.fields[t],s=this.fieldDisplay(n),r=new i.ICEText({left:0,top:0,text:s.text,style:{strokeStyle:this.state.fieldStyle.textColor,fillStyle:this.state.fieldStyle.textColor,fontSize:this.state.fieldStyle.fontSize,fontWeight:this.state.fieldStyle.fontWeight,paddingTop:this.state.fieldStyle.paddingTop,paddingLeft:this.state.fieldStyle.paddingLeft,paddingRight:this.state.fieldStyle.paddingRight,paddingBottom:t===e-1?12:0},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1});this.entityFieldsComponent.push(r)}this.addChildren(this.entityFieldsComponent)}}fieldDisplay(e){const t=[];e.primary&&t.push("PK"),e.foreignKey&&t.push("FK");const i=[];e.unique&&i.push("UQ"),e.autoIncrement&&i.push("AI"),!1===e.nullable&&i.push("NN");const n=t.length?`${t.join(" ")} `:"",s=e.type?`${e.type}${e.length?`(${e.length})`:""}`:"",r=i.length?` ${i.join(" ")}`:"",a=void 0!==e.default?` = ${e.default}`:"",o=e.comment?` // ${e.comment}`:"";return{text:`${n}${e.name}${s?` ${s}`:""}${r}${a}${o}`}}calcComponentParams(){let e=this.state.width,t=0,i=0,n=0;this.entityNameComponent&&(n=this.entityNameComponent.state.height,t=n,e=Math.max(e,this.entityNameComponent.state.width),t+=this.deviderLine.state.height,i=t);for(let i=0;i<this.entityFieldsComponent.length;i++){const n=this.entityFieldsComponent[i];n.state.left=0,n.state.top=t,t+=n.state.height,e=Math.max(e,n.state.width)}if(this.deviderLine&&(this.deviderLine.state.points=[[0,i],[e,i]]),this.headerBackgroundComponent){const t=this.state.style.lineWidth||1.5,i=t/2;this.headerBackgroundComponent.state.left=i,this.headerBackgroundComponent.state.top=i,this.headerBackgroundComponent.state.width=Math.max(e-t,0),this.headerBackgroundComponent.state.height=Math.max(n-i,0)}const s=e,r=Math.max(t,this.state.height);return this.state.width=s,this.state.height=r,{width:s,height:r}}toEntityObject(){const e={name:this.state.entityName,columns:{}};return this.state.fields.forEach(t=>{const i={};void 0!==t.type&&(i.type=t.type),void 0!==t.length&&(i.length=t.length),t.primary&&(i.primary=!0),t.generated&&(i.generated=!0),t.autoIncrement&&(i.generated=!0,i.strategy="increment"),!1===t.nullable&&(i.nullable=!1),t.unique&&(i.unique=!0),void 0!==t.default&&(i.default=t.default),void 0!==t.comment&&(i.comment=t.comment),t.index&&(i.index=!0),e.columns[t.name]=i}),e}setState(e){const t=!Ve(e.fields)||!Ve(e.entityName);super.setState(e),t&&this.syncEntityNameAndFields()}addField(e){const t=[...this.state.fields||[],e];return this.setFields(t),this}removeField(e){const t=(this.state.fields||[]).filter(t=>t.name!==e);return this.setFields(t),this}setFields(e){return this.setState({fields:e}),this}}class Relation extends i.ICEVisioLink{static typeId="ice-entity-designer:Relation";hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=Relation.normalizeLinks(e||{}),i=t.relationType||"one-to-one",n=Relation.composeLabel(t,i);super({title:"Relation",transformable:!1,relationType:i,referencedColumnName:"id",sourceField:"id",targetField:"id",arrow:t.arrow||Relation.defaultArrow(i),...t,label:n,style:{...t.style||{},label:{fontSize:14,fillStyle:"#334155",backgroundColor:"#ffffff",...t.labelStyle||{},...(t.style||{}).label||{}}}})}static defaultArrow(e){switch(e){case"one-to-many":return"end";case"many-to-one":return"start";default:return"none"}}static normalizeLinks(e){if(!e||!e.links)return e||{};const t={top:"T",right:"R",bottom:"B",left:"L",center:"C"},i={...e.links};return i.start&&t[i.start.position]&&(i.start={...i.start,position:t[i.start.position]}),i.end&&t[i.end.position]&&(i.end={...i.end,position:t[i.end.position]}),{...e,links:i}}static cardinalityLabel(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i={"one-to-many":["1","N"],"many-to-one":["N","1"],"many-to-many":["N","N"],"one-to-one":["1","1"]},[n,s]=i[e]||i["one-to-one"];return`${t.sourceCardinality||n} : ${t.targetCardinality||s}`}static composeLabel(e,t){return e.label?e.label:Relation.buildLabel(e,t)}static buildLabel(e,t){const i=[];e.onDelete&&i.push(`ON DELETE ${e.onDelete}`),e.onUpdate&&i.push(`ON UPDATE ${e.onUpdate}`);const n=Relation.cardinalityLabel(t,e);return i.length?`${n} (${i.join(", ")})`:n}toEntityObject(){const{title:e,relationType:t,referencedColumnName:i,sourceField:n,targetField:s,nullable:r,onDelete:a,onUpdate:o,joinTableName:l,fromKey:h,toKey:d}=this.state;let c,u,p,f,g,m;this.state.links&&this.state.links.start&&this.state.links.start.id&&(p=this.state.links.start.id,c=this.ice.findComponent(p),f=c.state.entityName),this.state.links&&this.state.links.end&&this.state.links.end.id&&(g=this.state.links.end.id,u=this.ice.findComponent(g),m=u.state.entityName);return{title:e,fromId:p,fromName:f,toId:g,toName:m,relationType:t,referencedColumnName:i,sourceField:n,targetField:s,nullable:!1!==r&&void 0,onDelete:a,onUpdate:o,joinTableName:l,fromKey:h,toKey:d}}}const zi={selection:{stroke:"#1677ff",fill:"rgba(22,119,255,0.12)",lineWidth:1,lineDash:[]},handle:{fill:"#1677ff",stroke:"#ffffff",activeFill:"#faad14",lineWidth:1},linkHook:{fill:"#52c41a",stroke:"#ffffff",lineWidth:1},slot:{fill:"#52c41a",stroke:"#ffffff",hoverFill:"#faad14",lineWidth:1},guide:{color:"#1677ff",lineWidth:1},textSelection:{color:"rgba(22,119,255,0.28)"}},Ai=zi;function designerChromeFromTheme(e){const t=e&&e.semantic||{},i=t.primary||"#0D6EFD",n=t.success||"#198754",s=t.warning||"#FFC107";return{selection:{stroke:i,fill:withAlpha(i,.12),lineWidth:1,lineDash:[]},handle:{fill:i,stroke:"#ffffff",activeFill:s,lineWidth:1},linkHook:{fill:n,stroke:"#ffffff",lineWidth:1},slot:{fill:n,stroke:"#ffffff",hoverFill:s,lineWidth:1},guide:{color:i,lineWidth:1},textSelection:{color:withAlpha(i,.28)}}}function applyDesignerChrome(e){if(!e)return e;if("function"!=typeof e.setThemePatch&&"function"!=typeof e.setChrome)return e;const t=designerChromeFromTheme("function"==typeof e.getTheme?e.getTheme():null);return"function"==typeof e.setThemePatch?(e.setThemePatch("ice-designer",{semantic:{chrome:t}}),function subscribeDesignerChrome(e){if(e.__designerChromeSubscribed||"function"!=typeof e.onThemeChange)return;e.__designerChromeSubscribed=!0,e.onThemeChange(t=>{if(t&&"theme"!==t.kind)return;const i="function"==typeof e.getTheme?e.getTheme():null;e.setThemePatch("ice-designer",{semantic:{chrome:designerChromeFromTheme(i)}})})}(e)):e.setChrome(t),e}function withAlpha(e,t){if("string"!=typeof e)return e;const i=e.trim();if("#"===i.charAt(0)){let e=i.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return i;return`rgba(${parseInt(e.slice(0,2),16)},${parseInt(e.slice(2,4),16)},${parseInt(e.slice(4,6),16)},${t})`}return 0===i.indexOf("rgb(")?i.replace("rgb(","rgba(").replace(")",`,${t})`):i}const Wi=["T","R","B","L"],qi={T:[0,-1],R:[1,0],B:[0,1],L:[-1,0]};function boxOf$1(e){if(!e||"function"!=typeof e.getMaxBoundingBox)return null;const t=e.getMaxBoundingBox(!0).getMinAndMaxPoint();return{minX:t.minX,minY:t.minY,maxX:t.maxX,maxY:t.maxY}}function centerOf(e){return[(e.minX+e.maxX)/2,(e.minY+e.maxY)/2]}function portPoint(e,t){const[i,n]=centerOf(e);return"T"===t?[i,e.minY]:"B"===t?[i,e.maxY]:"L"===t?[e.minX,n]:[e.maxX,n]}function autoPorts(e,t,i){const n=boxOf$1(e),s=boxOf$1(t);if(!n||!s)return{...i};const r=centerOf(n),a=centerOf(s);let o={...i},l=1/0;for(const e of Wi){const t=portPoint(n,e),i=qi[e],h=(a[0]-t[0])*i[0]+(a[1]-t[1])*i[1]>=0;for(const n of Wi){const a=portPoint(s,n),d=qi[n],c=(h?0:1e6)+((r[0]-a[0])*d[0]+(r[1]-a[1])*d[1]>=0?0:1e6)+((a[0]-t[0])*i[0]+(a[1]-t[1])*i[1]>=0&&(t[0]-a[0])*d[0]+(t[1]-a[1])*d[1]>=0?0:1e6)+Math.hypot(t[0]-a[0],t[1]-a[1]);c<l&&(l=c,o={sourcePort:e,targetPort:n})}}return o}function enableDesignerAlignmentGuides(e){return e&&e.alignmentGuide&&"function"==typeof e.alignmentGuide.enable?(e.alignmentGuide.enable({threshold:2}),e):e}function typeIdOf(e){const t=e&&e.constructor;return t&&"string"==typeof t.typeId?t.typeId:void 0}function isEntity(e){return typeIdOf(e)===Entity.typeId}function isRelation(e){return typeIdOf(e)===Relation.typeId}const ji="data",Fi=[{key:"display",type:"boolean"},{key:"zIndex",type:"any"},{key:"opacity",type:"number",doc:"子树不透明度(引擎 1.3 起)"},{key:"transform",type:"object"},{key:"origin",type:"string"},{key:"originX",type:"number"},{key:"originY",type:"number"},{key:"lineDash",type:"array"},{key:"lineDashOffset",type:"number"},{key:"lineDashFlow",type:"boolean"},{key:"lineDashFlowSpeed",type:"number"},{key:"lineBorder",type:"boolean"},{key:"lineBorderWidth",type:"number"},{key:"lineBorderColor",type:"string"},{key:"fill",type:"boolean"},{key:"stroke",type:"boolean"},{key:"linkable",type:"boolean"},{key:"linkEditable",type:"boolean"},{key:"transformable",type:"boolean"},{key:"animations",type:"object"}],Ri=[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"},{key:"left",type:"number"},{key:"top",type:"number"},{key:"width",type:"number"},{key:"height",type:"number"},{key:"relationType",type:"string"},{key:"referencedColumnName",type:"string"},{key:"sourceField",type:"string"},{key:"targetField",type:"string"},{key:"nullable",type:"boolean"},{key:"onDelete",type:"string"},{key:"onUpdate",type:"string"},{key:"joinTableName",type:"string"},{key:"fromKey",type:"string"},{key:"toKey",type:"string"},{key:"sourceCardinality",type:"string"},{key:"targetCardinality",type:"string"},{key:"label",type:"string"},{key:"style.label",type:"object",doc:"标签外观(引擎 2.4 起归到 style.label)"},{key:"style",type:"object"},{key:"arrow",type:"string"},{key:"lineType",type:"string"},{key:"escapeDistance",type:"number"},{key:"routeType",type:"string"},{key:"routeOffset",type:"number"},{key:"curveType",type:"string"},{key:"linkShape",type:"string",doc:"连线形态(visio/bezier)"},{key:"lineDash",type:"array"},{key:"lineWidth",type:"number"},{key:"arrowLength",type:"number"},{key:"arrowAngel",type:"number"},{key:"arrowStyle",type:"string"},{key:"startPoint",type:"array"},{key:"endPoint",type:"array"},{key:"links",type:"object",validate:function validateLinks(e,t,i){["start","end"].forEach(n=>{const s=e[n];void 0!==s&&(s&&"object"==typeof s&&!Array.isArray(s)?(void 0!==s.id&&"string"!=typeof s.id&&i.push(`${t}.${n}.id must be a string when present`),void 0!==s.position&&"string"!=typeof s.position&&i.push(`${t}.${n}.position must be a string when present`)):i.push(`${t}.${n} must be an object when present`))})}},{key:"sourceId",type:"string",doc:"连线起点宿主 id(与 links.start.id 同步)"},{key:"targetId",type:"string",doc:"连线终点宿主 id(与 links.end.id 同步)"},{key:"draggable",type:"boolean"},{key:"interactive",type:"boolean"},{key:"showMinBoundingBox",type:"boolean"},{key:"showMaxBoundingBox",type:"boolean"}],Hi=[...[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"},{key:"left",type:"number"},{key:"top",type:"number"},{key:"width",type:"number"},{key:"height",type:"number"},{key:"entityName",type:"string",required:!0},{key:"fields",type:"array",validate:function validateFields(e,t,i){e.forEach((e,n)=>{e&&"object"==typeof e&&!Array.isArray(e)?void 0!==e.name&&"string"!=typeof e.name&&i.push(`${t}[${n}].name must be a string when present`):i.push(`${t}[${n}] must be an object`)})}},{key:"style",type:"object"},{key:"headerStyle",type:"object"},{key:"fieldStyle",type:"object"},{key:"dividerStyle",type:"object"},{key:"draggable",type:"boolean"},{key:"interactive",type:"boolean"},{key:"showMinBoundingBox",type:"boolean"},{key:"showMaxBoundingBox",type:"boolean"}],...Fi],Gi=[...Ri,...Fi];function pickDocumentNode(e,t){const i={};t.forEach(t=>{const n=e?e[t.key]:void 0;void 0!==n&&(i[t.key]=n)});const n=e?e[ji]:void 0;return void 0!==n&&(i[ji]=n),i}function validateDocumentNode(e,t,i,n){e&&"object"==typeof e&&!Array.isArray(e)?i.forEach(i=>{const s=e[i.key];void 0!==s?!function typeMatches(e,t){switch(t){case void 0:case"any":return!0;case"array":return Array.isArray(e);case"object":return!!e&&"object"==typeof e&&!Array.isArray(e);case"number":return"number"==typeof e;case"boolean":return"boolean"==typeof e;default:return"string"==typeof e}}(s,i.type)?n.push(`${t}.${i.key} must be a ${i.type} when present`):i.validate&&i.validate(s,`${t}.${i.key}`,n):i.required&&n.push(`${t}.${i.key} is required`)}):n.push(`${t} must be an object`)}const Ui=[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"}];function validateProjectSnapshot(e){const t=[];return!e||"object"!=typeof e||Array.isArray(e)?{valid:!1,errors:["root must be an object"]}:(void 0!==e.schemaVersion&&"number"!=typeof e.schemaVersion&&t.push("schemaVersion must be a number when present"),void 0!==e.createTime&&"string"!=typeof e.createTime&&t.push("createTime must be a string when present"),Array.isArray(e.entities)?e.entities.forEach((e,i)=>{validateNode(e,`entities[${i}]`,Entity.typeId,t)}):t.push("entities must be an array"),void 0===e.relations||Array.isArray(e.relations)?Array.isArray(e.relations)&&e.relations.forEach((e,i)=>{validateNode(e,`relations[${i}]`,Relation.typeId,t)}):t.push("relations must be an array when present"),{valid:0===t.length,errors:t})}function validateNode(e,t,i,n){if(!e||"object"!=typeof e||Array.isArray(e))return void n.push(`${t} must be an object`);const s=void 0===e.typeId?i:e.typeId;!function isEntityTypeId(e){return e===Entity.typeId}(s)?!function isRelationTypeId(e){return e===Relation.typeId}(s)?validateDocumentNode(e,t,Ui,n):validateDocumentNode(e,t,Gi,n):validateDocumentNode(e,t,Hi,n)}function validateSchema(e){const t=[],i=e.filter(isEntity),n=e.filter(isRelation),s=new Map;return i.forEach(e=>{const i=(e.state.entityName||"").trim();if(!i)return void t.push({level:"error",message:"存在未命名的 Entity",componentId:e.state.id});s.has(i)||s.set(i,[]),s.get(i).push(e);const n=e.state.fields||[];0===n.length&&t.push({level:"warning",message:`Entity "${i}" 没有任何字段`,componentId:e.state.id});const r=new Set;n.forEach(n=>{const s=(n.name||"").trim();s?r.has(s)?t.push({level:"error",message:`Entity "${i}" 存在重复字段 "${s}"`,componentId:e.state.id}):r.add(s):t.push({level:"error",message:`Entity "${i}" 存在未命名字段`,componentId:e.state.id}),n.type||t.push({level:"warning",message:`Entity "${i}" 的字段 "${s||"(未命名)"}" 未设置类型`,componentId:e.state.id})})}),s.forEach((e,i)=>{e.length>1&&t.push({level:"error",message:`存在重复的 Entity 名称 "${i}"`})}),n.forEach(e=>{const n=e.state.links||{},s=n.start&&n.start.id,r=n.end&&n.end.id,a=e.state.relationType;if(!s||!r)return void t.push({level:"error",message:"存在没有完整起点/终点的 Relation",componentId:e.state.id});const o=i.some(e=>e.state.id===s),l=i.some(e=>e.state.id===r);o&&l||t.push({level:"error",message:"Relation 连接到了不存在的 Entity",componentId:e.state.id}),a?"many-to-many"!==a||e.state.joinTableName||t.push({level:"warning",message:"many-to-many 关系建议设置 joinTableName",componentId:e.state.id}):t.push({level:"error",message:"Relation 未设置关系类型",componentId:e.state.id})}),t}function toWords(e){return function convertToString(e){const t=e||"";return"string"==typeof t?t:String(t)}(e).match(/[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g)||[]}function camelCase(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return function toCamelCase(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i="";for(let n=0,s=e.length;n<s;n++){let s=e[n].toLowerCase();(t||0!==n)&&(s=s.substr(0,1).toUpperCase()+s.substr(1)),i+=s}return i}(toWords(e),t)}var Ki=[],Vi=[],Yi={},Xi={},Ji={};function sanitizeRule(e){return"string"==typeof e?new RegExp("^"+e+"$","i"):e}function restoreCase(e,t){return e===t?t:e===e.toLowerCase()?t.toLowerCase():e===e.toUpperCase()?t.toUpperCase():e[0]===e[0].toUpperCase()?t.charAt(0).toUpperCase()+t.substr(1).toLowerCase():t.toLowerCase()}function replace(e,t){return e.replace(t[0],function(i,n){var s=function interpolate(e,t){return e.replace(/\$(\d{1,2})/g,function(e,i){return t[i]||""})}(t[1],arguments);return restoreCase(""===i?e[n-1]:i,s)})}function sanitizeWord(e,t,i){if(!e.length||Yi.hasOwnProperty(e))return t;for(var n=i.length;n--;){var s=i[n];if(s[0].test(t))return replace(t,s)}return t}function replaceWord(e,t,i){return function(n){var s=n.toLowerCase();return t.hasOwnProperty(s)?restoreCase(n,s):e.hasOwnProperty(s)?restoreCase(n,e[s]):sanitizeWord(s,n,i)}}function checkWord(e,t,i){return function(n){var s=n.toLowerCase();return!!t.hasOwnProperty(s)||!e.hasOwnProperty(s)&&sanitizeWord(s,s,i)===s}}function pluralize(e,t,i){return(i?t+" ":"")+(1===t?pluralize.singular(e):pluralize.plural(e))}pluralize.plural=replaceWord(Ji,Xi,Ki),pluralize.isPlural=checkWord(Ji,Xi,Ki),pluralize.singular=replaceWord(Xi,Ji,Vi),pluralize.isSingular=checkWord(Xi,Ji,Vi),pluralize.addPluralRule=function(e,t){Ki.push([sanitizeRule(e),t])},pluralize.addSingularRule=function(e,t){Vi.push([sanitizeRule(e),t])},pluralize.addUncountableRule=function(e){"string"!=typeof e?(pluralize.addPluralRule(e,"$0"),pluralize.addSingularRule(e,"$0")):Yi[e.toLowerCase()]=!0},pluralize.addIrregularRule=function(e,t){t=t.toLowerCase(),e=e.toLowerCase(),Ji[e]=t,Xi[t]=e},[["I","we"],["me","us"],["he","they"],["she","they"],["them","them"],["myself","ourselves"],["yourself","yourselves"],["itself","themselves"],["herself","themselves"],["himself","themselves"],["themself","themselves"],["is","are"],["was","were"],["has","have"],["this","these"],["that","those"],["echo","echoes"],["dingo","dingoes"],["volcano","volcanoes"],["tornado","tornadoes"],["torpedo","torpedoes"],["genus","genera"],["viscus","viscera"],["stigma","stigmata"],["stoma","stomata"],["dogma","dogmata"],["lemma","lemmata"],["schema","schemata"],["anathema","anathemata"],["ox","oxen"],["axe","axes"],["die","dice"],["yes","yeses"],["foot","feet"],["eave","eaves"],["goose","geese"],["tooth","teeth"],["quiz","quizzes"],["human","humans"],["proof","proofs"],["carve","carves"],["valve","valves"],["looey","looies"],["thief","thieves"],["groove","grooves"],["pickaxe","pickaxes"],["passerby","passersby"]].forEach(function(e){return pluralize.addIrregularRule(e[0],e[1])}),[[/s?$/i,"s"],[/[^\u0000-\u007F]$/i,"$0"],[/([^aeiou]ese)$/i,"$1"],[/(ax|test)is$/i,"$1es"],[/(alias|[^aou]us|t[lm]as|gas|ris)$/i,"$1es"],[/(e[mn]u)s?$/i,"$1s"],[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i,"$1"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1i"],[/(alumn|alg|vertebr)(?:a|ae)$/i,"$1ae"],[/(seraph|cherub)(?:im)?$/i,"$1im"],[/(her|at|gr)o$/i,"$1oes"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,"$1a"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,"$1a"],[/sis$/i,"ses"],[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([^ch][ieo][ln])ey$/i,"$1ies"],[/(x|ch|ss|sh|zz)$/i,"$1es"],[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i,"$1ices"],[/\b((?:tit)?m|l)(?:ice|ouse)$/i,"$1ice"],[/(pe)(?:rson|ople)$/i,"$1ople"],[/(child)(?:ren)?$/i,"$1ren"],[/eaux$/i,"$0"],[/m[ae]n$/i,"men"],["thou","you"]].forEach(function(e){return pluralize.addPluralRule(e[0],e[1])}),[[/s$/i,""],[/(ss)$/i,"$1"],[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i,"$1fe"],[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i,"$1f"],[/ies$/i,"y"],[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i,"$1ie"],[/\b(mon|smil)ies$/i,"$1ey"],[/\b((?:tit)?m|l)ice$/i,"$1ouse"],[/(seraph|cherub)im$/i,"$1"],[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,"$1"],[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,"$1sis"],[/(movie|twelve|abuse|e[mn]u)s$/i,"$1"],[/(test)(?:is|es)$/i,"$1is"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1us"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,"$1um"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,"$1on"],[/(alumn|alg|vertebr)ae$/i,"$1a"],[/(cod|mur|sil|vert|ind)ices$/i,"$1ex"],[/(matr|append)ices$/i,"$1ix"],[/(pe)(rson|ople)$/i,"$1rson"],[/(child)ren$/i,"$1"],[/(eau)x?$/i,"$1"],[/men$/i,"man"]].forEach(function(e){return pluralize.addSingularRule(e[0],e[1])}),["adulthood","advice","agenda","aid","aircraft","alcohol","ammo","analytics","anime","athletics","audio","bison","blood","bream","buffalo","butter","carp","cash","chassis","chess","clothing","cod","commerce","cooperation","corps","debris","diabetes","digestion","elk","energy","equipment","excretion","expertise","firmware","flounder","fun","gallows","garbage","graffiti","hardware","headquarters","health","herpes","highjinks","homework","housework","information","jeans","justice","kudos","labour","literature","machinery","mackerel","mail","media","mews","moose","music","mud","manga","news","only","personnel","pike","plankton","pliers","police","pollution","premises","rain","research","rice","salmon","scissors","series","sewage","shambles","shrimp","software","species","staff","swine","tennis","traffic","transportation","trout","tuna","wealth","welfare","whiting","wildebeest","wildlife","you",/pok[eé]mon$/i,/[^aeiou]ese$/i,/deer$/i,/fish$/i,/measles$/i,/o[iu]s$/i,/pox$/i,/sheep$/i].forEach(pluralize.addUncountableRule);const Qi={number:"int",int:"int",integer:"int",smallint:"smallint",bigint:"bigint",float:"float",double:"double",real:"real",decimal:"decimal",numeric:"numeric",string:"varchar",varchar:"varchar",char:"char",text:"text",boolean:"boolean",bool:"boolean",date:"date",datetime:"datetime",timestamp:"timestamp",time:"time",json:"json",jsonb:"jsonb",uuid:"uuid",enum:"enum",blob:"blob",binary:"blob","simple-array":"simple-array","simple-json":"simple-json"},Zi=["varchar","char","nvarchar","nchar","text","uuid"];function normalizeColumn(e){const t={},i=function mapColumnType(e){if(null==e||""===e)return;const t=String(e).toLowerCase();return Qi[t]||String(e)}(e.type);if(void 0!==i&&(t.type=i),void 0!==e.length&&null!==e.length&&""!==e.length){const n=String(e.length).trim();if("decimal"===i||"numeric"===i){const[e,i]=n.split(",").map(e=>e.trim());e&&(t.precision=Number(e)),i&&(t.scale=Number(i))}else i&&Zi.indexOf(i)>=0&&(t.length=e.length)}return e.primary&&(t.primary=!0),e.generated&&(t.generated=!0),e.autoIncrement&&(t.generated=!0,t.strategy="increment"),void 0!==e.strategy&&(t.strategy=e.strategy),!1===e.nullable&&(t.nullable=!1),e.unique&&(t.unique=!0),void 0!==e.default&&(t.default=e.default),void 0!==e.comment&&(t.comment=e.comment),e.index&&(t.index=!0),t}function normalizeColumns(e){const t={};return Object.keys(e||{}).forEach(i=>{t[i]=normalizeColumn(e[i])}),t}function buildJoinColumn(e,t){return{name:e||t||"id",referencedColumnName:t||"id"}}function toSchemaObject(e){const t=[...e],i=[],n={};for(let e=0;e<t.length;e++){const s=t[e];if(isRelation(s))i.push(s);else if(isEntity(s)){const e=s.toEntityObject();e.columns=normalizeColumns(e.columns),n[s.state.id]=e}}for(let e=0;e<i.length;e++){const t=i[e],{fromId:s,fromName:r,toId:a,toName:o,relationType:l,referencedColumnName:h,sourceField:d,targetField:c,nullable:u,onDelete:p,onUpdate:f,joinTableName:g,fromKey:m,toKey:y}=t.toEntityObject(),_=n[s],b=n[a];if(!_||!b)continue;_.relations||(_.relations={}),b.relations||(b.relations={});const v=m||camelCase(o),k=y||camelCase(r),w={};!1===u&&(w.nullable=!1),p&&(w.onDelete=p),f&&(w.onUpdate=f),"one-to-one"===l?(b.relations[k]={type:l,target:r,joinColumn:buildJoinColumn(c||h,d||h),...w},_.relations[v]={type:l,target:o,inverseSide:k}):"one-to-many"===l?(_.relations[v]={type:l,target:o,inverseSide:k},b.relations[k]={type:"many-to-one",target:r,joinColumn:buildJoinColumn(c||h,d||h),...w}):"many-to-one"===l?(_.relations[v]={type:l,target:o,joinColumn:buildJoinColumn(d||h,c||h),...w},b.relations[k]={type:"one-to-many",target:r,inverseSide:v}):"many-to-many"===l&&(_.relations[`${pluralize(v)}`]={type:l,target:o,joinTable:!g||{name:g}},b.relations[`${pluralize(k)}`]={type:l,target:r,inverseSide:`${pluralize(v)}`})}const s=[];for(const e in n)s.push(n[e]);return s}function toSchemaString(e){return JSON.stringify(toSchemaObject(e))}function registerIEDType(e,t){e.registerType(t.typeId,t)}function createEmptyPath$1(e){const t=e.path2D&&e.path2D.constructor;return t?new t:null}class FlowDiamond extends i.ICEPath{static typeId="ice-entity-designer:FlowDiamond";createPathObject(){const e=this.state.width,t=this.state.height,i=0-this.state.localOrigin[0],n=0-this.state.localOrigin[1],s=createEmptyPath$1(this);return s?(s.moveTo(i+e/2,n),s.lineTo(i+e,n+t/2),s.lineTo(i+e/2,n+t),s.lineTo(i,n+t/2),s.closePath(),this.path2D=s,this.path2D):this.path2D}}class FlowParallelogram extends i.ICEPath{static typeId="ice-entity-designer:FlowParallelogram";createPathObject(){const e=this.state.width,t=this.state.height,i=Math.min(28,.18*e),n=0-this.state.localOrigin[0],s=0-this.state.localOrigin[1],r=createEmptyPath$1(this);return r?(r.moveTo(n+i,s),r.lineTo(n+e,s),r.lineTo(n+e-i,s+t),r.lineTo(n,s+t),r.closePath(),this.path2D=r,this.path2D):this.path2D}}function createEmptyPath(e){const t=e.path2D&&e.path2D.constructor;return t?new t:null}function localBox(e){return{w:e.state.width,h:e.state.height,x:0-e.state.localOrigin[0],y:0-e.state.localOrigin[1]}}class BpmnEventShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnEventShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=i+e/2,a=n+t/2,o=Math.min(e,t)/2,l=this.state.eventKind||"start";s.arc(r,a,o,0,2*Math.PI),"intermediate"!==l&&"end"!==l||(s.moveTo(r+.84*o,a),s.arc(r,a,.84*o,0,2*Math.PI));const h=this.state.trigger||"none";if("message"===h){const e=1.1*o,t=.78*o;s.moveTo(r-e/2,a-t/2),s.lineTo(r+e/2,a-t/2),s.lineTo(r+e/2,a+t/2),s.lineTo(r-e/2,a+t/2),s.closePath(),s.moveTo(r-e/2,a-t/2),s.lineTo(r,a+.08*t),s.lineTo(r+e/2,a-t/2)}else if("timer"===h){const e=.52*o;s.moveTo(r+e,a),s.arc(r,a,e,0,2*Math.PI),s.moveTo(r,a),s.lineTo(r,a-.62*e),s.moveTo(r,a),s.lineTo(r+.5*e,a)}else"error"===h?(s.moveTo(r+.34*o,a-.62*o),s.lineTo(r-.42*o,a+.06*o),s.lineTo(r-.02*o,a+.06*o),s.lineTo(r-.3*o,a+.66*o),s.lineTo(r+.44*o,a-.02*o),s.lineTo(r+.04*o,a-.02*o),s.closePath()):"terminate"===h&&(s.moveTo(r+.5*o,a),s.arc(r,a,.5*o,0,2*Math.PI));return this.path2D=s,this.path2D}}class BpmnGatewayShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnGatewayShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=i+e/2,a=n+t/2,o=e/2,l=t/2;s.moveTo(r,a-l),s.lineTo(r+o,a),s.lineTo(r,a+l),s.lineTo(r-o,a),s.closePath();const h=this.state.gatewayType||"exclusive",d=.42*Math.min(o,l);if("exclusive"===h)s.moveTo(r-d,a-d),s.lineTo(r+d,a+d),s.moveTo(r+d,a-d),s.lineTo(r-d,a+d);else if("parallel"===h)s.moveTo(r-d,a),s.lineTo(r+d,a),s.moveTo(r,a-d),s.lineTo(r,a+d);else if("inclusive"===h)s.moveTo(r+d,a),s.arc(r,a,d,0,2*Math.PI);else if("event"===h){const e=1.15*d;for(let t=0;t<5;t++){const i=-Math.PI/2+t*Math.PI*2/5,n=r+Math.cos(i)*e,o=a+Math.sin(i)*e;0===t?s.moveTo(n,o):s.lineTo(n,o)}s.closePath()}return this.path2D=s,this.path2D}}class BpmnTaskIcon extends i.ICEPath{static typeId="ice-entity-designer:BpmnTaskIcon";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=i+e/2,a=n+t/2,o=Math.min(e,t)/2,l=this.state.taskType||"none";if("user"===l)s.moveTo(r,a-o),s.arc(r,a-.35*o,.34*o,0,2*Math.PI),s.moveTo(r-.62*o,a+.72*o),s.arc(r,a+.72*o,.62*o,Math.PI,0);else if("service"===l){const e=8;for(let t=0;t<e;t++){const i=t*Math.PI*2/e,n=r+Math.cos(i)*o*.55,l=a+Math.sin(i)*o*.55,h=r+Math.cos(i)*o,d=a+Math.sin(i)*o;s.moveTo(n,l),s.lineTo(h,d)}s.moveTo(r+.34*o,a),s.arc(r,a,.34*o,0,2*Math.PI)}else"script"===l?(s.moveTo(r-.7*o,a-.85*o),s.lineTo(r+.7*o,a-.85*o),s.lineTo(r+.7*o,a+.5*o),s.moveTo(r-.7*o,a-.85*o),s.lineTo(r-.7*o,a+.5*o),s.moveTo(r-.7*o,a+.6*o),s.lineTo(r-.25*o,a+.85*o),s.lineTo(r+.25*o,a+.6*o),s.lineTo(r+.7*o,a+.85*o)):"send"===l?(s.moveTo(r-.85*o,a-.55*o),s.lineTo(r+.85*o,a-.55*o),s.lineTo(r+.85*o,a+.55*o),s.lineTo(r-.85*o,a+.55*o),s.closePath(),s.moveTo(r-.85*o,a-.55*o),s.lineTo(r,a+.12*o),s.lineTo(r+.85*o,a-.55*o)):"receive"===l?(s.moveTo(r-.85*o,a-.55*o),s.lineTo(r+.85*o,a-.55*o),s.lineTo(r+.85*o,a+.55*o),s.lineTo(r-.85*o,a+.55*o),s.closePath()):"manual"===l&&(s.moveTo(r-.7*o,a+.6*o),s.lineTo(r-.45*o,a-.5*o),s.lineTo(r+.45*o,a-.5*o),s.lineTo(r+.7*o,a+.6*o),s.closePath());return this.path2D=s,this.path2D}}class BpmnSubprocessMarker extends i.ICEPath{static typeId="ice-entity-designer:BpmnSubprocessMarker";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);return s?(s.moveTo(i,n),s.lineTo(i+e,n),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),s.moveTo(i+e/2,n+.22*t),s.lineTo(i+e/2,n+.78*t),s.moveTo(i+.22*e,n+t/2),s.lineTo(i+.78*e,n+t/2),this.path2D=s,this.path2D):this.path2D}}class BpmnDataObjectShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnDataObjectShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=Math.min(14,.22*e,.32*t);return s.moveTo(i,n),s.lineTo(i+e-r,n),s.lineTo(i+e,n+r),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),s.moveTo(i+e-r,n),s.lineTo(i+e-r,n+r),s.lineTo(i+e,n+r),this.path2D=s,this.path2D}}class BpmnAnnotationShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnAnnotationShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=Math.min(16,.3*e);return s.moveTo(i,n),s.lineTo(i+e,n),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),s.moveTo(i+r,n),s.lineTo(i,n),s.lineTo(i,n+t),s.lineTo(i+r,n+t),this.path2D=s,this.path2D}}class BpmnLaneShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnLaneShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=Math.min(this.state.bandSize||30,.4*e,.4*t);return s.moveTo(i,n),s.lineTo(i+e,n),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),"top"===(this.state.band||"left")?(s.moveTo(i,n+r),s.lineTo(i+e,n+r)):(s.moveTo(i+r,n),s.lineTo(i+r,n+t)),this.path2D=s,this.path2D}}class BpmnFlowMarker extends i.ICEPath{static typeId="ice-entity-designer:BpmnFlowMarker";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);return s?("default"===(this.state.markerType||"conditional")?(s.moveTo(i+.2*e,n+.8*t),s.lineTo(i+.8*e,n+.2*t)):(s.moveTo(i+e/2,n),s.lineTo(i+e,n+t/2),s.lineTo(i+e/2,n+t),s.lineTo(i,n+t/2),s.closePath()),this.path2D=s,this.path2D):this.path2D}}const en={terminator:{label:"开始 / 结束",width:180,height:60,fill:"#dcfce7",stroke:"#16a34a",radius:30,shape:"rect"},process:{label:"处理",width:220,height:80,fill:"#e0e7ff",stroke:"#4f46e5",radius:10,shape:"rect"},decision:{label:"判定",width:200,height:120,fill:"#fef3c7",stroke:"#d97706",shape:"diamond"},io:{label:"输入 / 输出",width:220,height:80,fill:"#e0f2fe",stroke:"#0284c7",shape:"parallelogram"},bpmnEvent:{label:"事件",width:56,height:56,fill:"#ffffff",stroke:"#475569",shape:"event",lineWidth:1.4,eventKind:"start",trigger:"none",labelPlacement:"top-left"},bpmnTask:{label:"任务",width:180,height:90,fill:"#ffffff",stroke:"#64748b",radius:10,shape:"rect",taskType:"none",labelPlacement:"center"},bpmnGateway:{label:"网关",width:70,height:70,fill:"#ffffff",stroke:"#64748b",shape:"gateway",gatewayType:"exclusive",labelPlacement:"top-left"},bpmnSubprocess:{label:"子流程",width:200,height:110,fill:"#ffffff",stroke:"#64748b",radius:10,shape:"rect",labelPlacement:"center"},bpmnDataObject:{label:"数据对象",width:130,height:80,fill:"#ffffff",stroke:"#64748b",shape:"dataObject",labelPlacement:"center"},bpmnAnnotation:{label:"注释",width:200,height:80,fill:"#ffffff",stroke:"#64748b",shape:"annotation",lineDash:[],labelPlacement:"center"},bpmnPool:{label:"池",width:900,height:260,fill:"#f8fafc",stroke:"#94a3b8",shape:"lane",band:"top",bandSize:32,labelPlacement:"top-left"},bpmnLane:{label:"泳道",width:900,height:130,fill:"#ffffff",stroke:"#cbd5e1",shape:"lane",band:"left",bandSize:32,labelPlacement:"top-left",transparent:!0}},tn=["bpmnPool","bpmnLane","bpmnAnnotation","bpmnDataObject"],nn={rect:i.ICERect,diamond:FlowDiamond,parallelogram:FlowParallelogram,event:BpmnEventShape,gateway:BpmnGatewayShape,dataObject:BpmnDataObjectShape,annotation:BpmnAnnotationShape,lane:BpmnLaneShape},sn="#0f172a";class FlowNode extends i.ICEGroup{static typeId="ice-entity-designer:FlowNode";shapeComponent=null;labelComponent=null;decorationComponents=[];hasDerivedChildren(){return!0}getSerializableChildren(){const e=[this.shapeComponent,this.labelComponent,...this.decorationComponents||[]];return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=en[e.kind]?e.kind:"process",i=en[t];super({kind:t,title:i.label,fillColor:i.fill,strokeColor:i.stroke,textColor:sn,fontSize:14,width:i.width,height:i.height,fill:!1,stroke:!1,draggable:!0,interactive:!0,transformable:!1,linkable:-1===tn.indexOf(t),...e}),this.__buildShape()}__buildShape(){this.shapeComponent&&this.removeChild(this.shapeComponent),this.labelComponent&&this.removeChild(this.labelComponent),this.decorationComponents&&this.decorationComponents.length&&(this.removeChildren(this.decorationComponents),this.decorationComponents.length=0);const e=en[this.state.kind]||en.process,t=nn[e.shape]||i.ICERect;this.shapeComponent=new t({left:0,top:0,width:this.state.width,height:this.state.height,radius:e.radius||0,lineWidth:e.lineWidth||1.5,lineDash:this.state.lineDash||e.lineDash||[],eventKind:this.state.eventKind||e.eventKind,trigger:this.state.trigger||e.trigger,gatewayType:this.state.gatewayType||e.gatewayType,taskType:this.state.taskType||e.taskType,band:e.band,bandSize:e.bandSize,fill:!e.transparent,interactive:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fillStyle:this.state.fillColor||e.fill,strokeStyle:this.state.strokeColor||e.stroke,lineWidth:e.lineWidth||1.5}}),this.__buildDecorations(e);const n="top-left"===e.labelPlacement,s="lane"===e.shape&&"left"===e.band,r=s?Math.min(Number(e.bandSize)||30,.4*this.state.width,.4*this.state.height):0,a=s?Math.max(this.state.height-8,r):0;this.labelComponent=new i.ICEText(s?{left:r/2-a/2,top:this.state.height/2-r/2,width:a,height:r,text:String(this.state.title||""),wrap:!0,maxLines:1,ellipsis:"…",transform:{rotate:-90},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fontSize:this.state.fontSize||13,fillStyle:this.state.textColor||sn,textAlign:"center",textBaseline:"middle",fontWeight:"bold"}}:{left:n?10:0,top:n?"top"===e.band?18:16:0,width:n?Math.max(this.state.width-20,20):this.state.width,height:n?18:this.state.height,text:String(this.state.title||""),wrap:!n,maxLines:2,interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fontSize:this.state.fontSize||(n?13:14),fillStyle:this.state.textColor||sn,textAlign:n?"left":"center",textBaseline:"middle",fontWeight:n?"bold":"normal",paddingLeft:n?0:12,paddingRight:n?0:12}}),this.addChild(this.shapeComponent),this.addChild(this.labelComponent)}__buildDecorations(e){const t=this.state.kind,i=[],n=this.state.strokeColor||e.stroke;if("bpmnTask"===t||"bpmnSubprocess"===t){const t=this.state.taskType||e.taskType||"none";"none"!==t&&i.push(new BpmnTaskIcon({left:8,top:8,width:14,height:14,stroke:!0,fill:!1,interactive:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,taskType:t,style:{strokeStyle:n,lineWidth:1.4}}))}"bpmnSubprocess"===t&&i.push(new BpmnSubprocessMarker({left:(this.state.width-14)/2,top:this.state.height-20,width:14,height:14,stroke:!0,fill:!1,interactive:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{strokeStyle:n,lineWidth:1.4}})),i.length&&(i.forEach(e=>this.addChild(e)),this.decorationComponents=i)}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=void 0!==e.kind||void 0!==e.fillColor||void 0!==e.strokeColor||void 0!==e.textColor||void 0!==e.fontSize||void 0!==e.eventKind||void 0!==e.trigger||void 0!==e.gatewayType||void 0!==e.taskType||void 0!==e.width||void 0!==e.height;return this.setState(e),t?this.__buildShape():this.labelComponent&&this.labelComponent.setState({text:String(this.state.title||"")}),this.dirty=!0,this}}class FlowEdge extends i.ICEVisioLink{static typeId="ice-entity-designer:FlowEdge";hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super({title:"Edge",arrow:"end",linkShape:"visio",lineType:"solid",linkable:!1,draggable:!1,interactive:!0,transformable:!1,startPoint:[0,0],endPoint:[10,10],label:"",...e,style:{strokeStyle:"#64748b",fillStyle:"#64748b",lineWidth:1.4,...e.style||{},label:{fontSize:12,fillStyle:"#334155",backgroundColor:"#ffffff",paddingLeft:4,paddingRight:4,...e.labelStyle||{},...(e.style||{}).label||{}}}}),this.applyPatch({flowType:this.state.flowType,condition:this.state.condition,isDefault:this.state.isDefault})}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e&&e.labelStyle&&(e={...e,style:{...this.state.style||{},...e.style||{},label:{...e.labelStyle||{},...(e.style||{}).label||{}}}},delete e.labelStyle);const t={...this.state,...e},i=t.flowType||"sequence",n="message"===i?{lineDash:[7,4],arrowStyle:"hollow",lineWidth:t.lineWidth||1.4}:"association"===i?{lineDash:[2,3],arrow:"none",arrowStyle:"hollow",lineWidth:t.lineWidth||1.2}:{arrow:t.arrow||"end",arrowStyle:"filled",lineDash:[],lineWidth:t.lineWidth||1.4};return this.setState({...e,...n}),this.dirty=!0,this}}class DesignerHighlightLayer{boxes=(()=>new Map)();options={color:"",lineWidth:3,padding:4,radius:6,fill:!1};constructor(e){this.ice=e}get ids(){return Array.from(this.boxes.keys())}set(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.options={...this.options,...t};const i=new Set(e.map(e=>e.id));Array.from(this.boxes.keys()).forEach(e=>{i.has(e)||this.__remove(e)}),e.forEach(e=>this.__place(e)),this.boxes.size||this.__destroy(),this.ice&&"function"==typeof this.ice.requestRepaint&&this.ice.requestRepaint()}clear(){this.boxes.forEach(e=>{this.ice&&"function"==typeof this.ice.removeTool&&this.ice.removeTool(e)}),this.boxes.clear(),this.ice&&"function"==typeof this.ice.requestRepaint&&this.ice.requestRepaint()}__place(e){const t=Number(this.options.padding)||0,n=e.minX-t,s=e.minY-t,r=Math.max(1,e.maxX-e.minX+2*t),a=Math.max(1,e.maxY-e.minY+2*t);let o=this.boxes.get(e.id);if(!o)return o=new i.ICERect({left:n,top:s,width:r,height:a,radius:this.options.radius,fill:!!this.options.fill,stroke:!0,interactive:!1,draggable:!1,transformable:!1,linkable:!1,style:{fillStyle:this.options.fill||"transparent",strokeStyle:this.__color(),lineWidth:this.options.lineWidth}}),o.__iceDesignerHighlight=!0,this.boxes.set(e.id,o),void this.ice.addTool(o);o.setState({left:n,top:s,width:r,height:a,radius:this.options.radius,fill:!!this.options.fill,style:{fillStyle:this.options.fill||"transparent",strokeStyle:this.__color(),lineWidth:this.options.lineWidth}})}__remove(e){const t=this.boxes.get(e);t&&(this.boxes.delete(e),this.ice&&"function"==typeof this.ice.removeTool&&this.ice.removeTool(t))}__destroy(){this.boxes.forEach(e=>{this.ice&&"function"==typeof this.ice.removeTool&&this.ice.removeTool(e)}),this.boxes.clear()}__color(){if(this.options.color)return this.options.color;try{const e=this.ice&&"function"==typeof this.ice.getTheme?this.ice.getTheme():null;return e&&e.semantic&&e.semantic.primary||i.DEFAULT_THEME.semantic.primary}catch{return i.DEFAULT_THEME.semantic.primary}}}function validateFlowSnapshot(e){const t=[];return!e||"object"!=typeof e||Array.isArray(e)?{valid:!1,errors:["root must be an object"]}:void 0!==e.scene?(!e.scene||"object"!=typeof e.scene||Array.isArray(e.scene)?t.push("scene must be an object when present"):Array.isArray(e.scene.childNodes)||t.push("scene.childNodes must be an array"),{valid:0===t.length,errors:t}):(Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const n=`nodes[${i}]`;e&&"object"==typeof e&&!Array.isArray(e)?("string"!=typeof e.id&&t.push(`${n}.id must be a string`),void 0!==e.kind&&"string"!=typeof e.kind&&t.push(`${n}.kind must be a string when present`),void 0!==e.left&&"number"!=typeof e.left&&t.push(`${n}.left must be a number when present`),void 0!==e.top&&"number"!=typeof e.top&&t.push(`${n}.top 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)?Array.isArray(e.edges)&&e.edges.forEach((e,i)=>{const n=`edges[${i}]`;e&&"object"==typeof e&&!Array.isArray(e)?(["sourceId","targetId"].forEach(i=>{void 0!==e[i]&&null!==e[i]&&"string"!=typeof e[i]&&t.push(`${n}.${i} must be a string or null when present`)}),void 0!==e.label&&"string"!=typeof e.label&&t.push(`${n}.label must be a string when present`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(`${n}.linkShape must be "visio" or "bezier" when present`)):t.push(`${n} must be an object`)}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t})}class FlowDesigner{selectedId=null;__undoStack=[];__redoStack=[];__historyEnabled=!0;__maxHistory=100;__listeners=[];__mousedownHandler=e=>this.__handleMouseDown(e);__moveSession=!1;__moveEmitQueued=!1;__highlightOptions={};__beforeMoveHandler=()=>this.__onBeforeMove();__afterMoveHandler=()=>this.__onAfterMove();__mouseupHandler=()=>this.__endMoveSession();constructor(e){applyDesignerChrome(e),enableDesignerAlignmentGuides(e),this.ice=e,this.__highlight=new DesignerHighlightLayer(this.ice),registerIEDType(this.ice,FlowNode),registerIEDType(this.ice,FlowEdge),this.ice.evtBus.on("mousedown",this.__mousedownHandler,this),this.ice.evtBus.on("mouseup",this.__mouseupHandler,this)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===FlowNode.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===FlowEdge.typeId)}__flatten(){const e=[],walk=t=>{t.forEach(t=>{e.push(t),t.childNodes&&t.childNodes.length&&walk(t.childNodes)})};return walk(this.ice.childNodes||[]),e}get selected(){return this.selectedId?this.ice.findComponent(this.selectedId):null}setHighlights(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Object.keys(t).length&&(this.__highlightOptions={...this.__highlightOptions,...t});const i=(null==e?[]:Array.isArray(e)?e:[e]).map(e=>this.__highlightEntry(e)).filter(e=>!!e);return this.__highlight.set(i,this.__highlightOptions),i.length}highlight(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=null==e?null:this.__highlightEntry(e);return!(null!=e&&!i)&&(this.setHighlights(i?[i.id]:null,t),!!i)}clearHighlights(){this.setHighlights(null)}getHighlightedIds(){return this.__highlight.ids}__highlightEntry(e){const t=String(e),i=this.nodes.find(e=>String(e.state?.id)===t)||this.nodes.find(e=>String(e.state?.tag)===t);if(!i)return null;const n=i.getMinBoundingBox(!0).getMinAndMaxPoint();return{id:String(i.state.id),minX:n.minX,minY:n.minY,maxX:n.maxX,maxY:n.maxY}}__syncHighlights(){const e=this.__highlight.ids;e.length&&this.setHighlights(e)}subscribe(e){return"function"!=typeof e?()=>{}:(this.__listeners.push(e),()=>{const t=this.__listeners.indexOf(e);-1!==t&&this.__listeners.splice(t,1)})}__emitChange(){if(this.__syncHighlights(),!this.__listeners.length)return;const e=this.serialize();this.__listeners.slice().forEach(t=>t(e,this))}__attachNodeListeners(e){e&&"function"==typeof e.on&&(e.on("BEFORE_MOVE",this.__beforeMoveHandler,this),e.on("AFTER_MOVE",this.__afterMoveHandler,this))}__detachNodeListeners(e){e&&"function"==typeof e.off&&(e.off("BEFORE_MOVE",this.__beforeMoveHandler,this),e.off("AFTER_MOVE",this.__afterMoveHandler,this))}__onBeforeMove(){this.__moveSession||(this.__moveSession=!0,this.__captureHistory())}__onAfterMove(){if(this.__moveEmitQueued)return;this.__moveEmitQueued=!0;const flush=()=>{this.__moveEmitQueued=!1,this.__emitChange()};"function"==typeof requestAnimationFrame?requestAnimationFrame(flush):setTimeout(flush,16)}__endMoveSession(){this.__moveSession=!1}select(e){return this.selectedId=e,this.__emitChange(),this}__defaultPlacement(e,t){const i=this.nodes;if(!i.length)return{left:120,top:120};let n=1/0,s=-1/0;i.forEach(e=>{const t=e.getMinBoundingBox(!0);n=Math.min(n,t.tl[0]),s=Math.max(s,t.br[1])});const r=i.length;return{left:n+r%4*280,top:s+80+Math.floor(r/4)*(t+90)}}createNode(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new FlowNode({kind:e,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}__slotPoint(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}createEdge(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("连接两端必须是已存在的节点");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"B",targetPort:"T"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=new FlowEdge({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},startPoint:this.__slotPoint(t,s),endPoint:this.__slotPoint(i,r),label:e.label||"",linkShape:e.linkShape||"visio",flowType:e.flowType||"sequence",condition:e.condition||"",isDefault:!!e.isDefault,style:{...e.style||{},...e.labelStyle?{label:e.labelStyle}:{}}});return this.ice.addChild(a),this.selectedId=a.state.id,this.__emitChange(),a}updateNode(e,t){const i=this.ice.findComponent(e);return i&&i.constructor.typeId===FlowNode.typeId&&(this.__captureHistory(),i.applyPatch(t),this.__emitChange()),i}updateEdge(e,t){const i=this.ice.findComponent(e);return i&&i.constructor.typeId===FlowEdge.typeId&&(this.__captureHistory(),"function"==typeof i.applyPatch?i.applyPatch(t):(i.setState(t),i.dirty=!0),this.__emitChange()),i}remove(e){const t=this.ice.findComponent(e);t&&(this.__captureHistory(),-1!==this.nodes.indexOf(t)&&(this.__detachNodeListeners(t),this.edges.filter(t=>{const i=t.state.links||{};return i.start&&i.start.id===e||i.end&&i.end.id===e}).forEach(e=>this.ice.removeChild(e))),t.parentNode&&"function"==typeof t.parentNode.removeChild?t.parentNode.removeChild(t):this.ice.removeChild(t),this.selectedId===e&&(this.selectedId=null),this.__emitChange())}clear(){this.__captureHistory(),this.ice.clearAll(),this.selectedId=null,this.__emitChange()}serialize(){return JSON.stringify(this.toSnapshot())}toSnapshot(){const e=this.__serializer().toJSONObject();return{version:2,kind:"flowchart",createTime:e.createTime,scene:{version:e.version,childNodes:e.childNodes}}}__serializer(){const e=this.ice;return e.serializer||new i.Serializer(e)}__deserializer(){const e=this.ice;return e.deserializer||new i.Deserializer(e)}load(e){if(!e)return{loaded:!1,nodes:0,edges:0,skipped:[]};let t;try{t=JSON.parse(e)}catch(e){throw new Error(`Invalid flow snapshot: 不是合法 JSON(${e instanceof Error?e.message:String(e)})`)}if(!t||"object"!=typeof t)return{loaded:!1,nodes:0,edges:0,skipped:[]};const i=!!t.scene;if(!i&&!Array.isArray(t.nodes))return{loaded:!1,nodes:0,edges:0,skipped:[]};const n=validateFlowSnapshot(t);if(!n.valid)throw new Error(`Invalid flow snapshot:\n${n.errors.join("\n")}`);this.__captureHistory();const s=i?this.__applyEngineScene(t.scene,t.createTime):this.__clearAndBuild(t);return this.__emitChange(),s}__applyEngineScene(e,t){this.ice.clearAll(),this.selectedId=null;const i=this.__deserializer();i.fromJSONObject({version:e.version,createTime:t,childNodes:e.childNodes});const n={loaded:!0,nodes:this.nodes.length,edges:this.edges.length,skipped:[...i.unknownTypes||[]]};return this.nodes.forEach(e=>this.__attachNodeListeners(e)),n}__clearAndBuild(e){this.ice.clearAll(),this.selectedId=null;const t={loaded:!0,nodes:0,edges:0,skipped:[]};return(e.nodes||[]).forEach(e=>{if(void 0!==e.typeId&&this.ice.getType(e.typeId)!==FlowNode)return void t.skipped.push(String(e.typeId));const i=new FlowNode(e);delete i.state.typeId,this.ice.addChild(i),this.__attachNodeListeners(i),t.nodes+=1}),(e.edges||[]).forEach(e=>{if(void 0!==e.typeId&&this.ice.getType(e.typeId)!==FlowEdge)return void t.skipped.push(String(e.typeId));const i=e.sourceId||e.links&&e.links.start&&e.links.start.id||null,n=e.targetId||e.links&&e.links.end&&e.links.end.id||null,s=e.sourcePort||e.links&&e.links.start&&e.links.start.position||"B",r=e.targetPort||e.links&&e.links.end&&e.links.end.position||"T",a=i&&n?{start:{id:i,position:s},end:{id:n,position:r}}:e.links,o=new FlowEdge({...e,links:a,startPoint:e.startPoint||[0,0],endPoint:e.endPoint||[10,10]});delete o.state.typeId,this.ice.addChild(o),t.edges+=1}),t}contentComponents(){return this.nodes}fitViewportAlign="center";fitViewport(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:80;const t=this.contentComponents(),{width:i,height:n}=this.__viewportSize();if(!t.length||!i||!n)return;let s=1/0,r=1/0,a=-1/0,o=-1/0;t.forEach(e=>{const t=e.getMinBoundingBox(!0);s=Math.min(s,t.tl[0]),r=Math.min(r,t.tl[1]),a=Math.max(a,t.br[0]),o=Math.max(o,t.br[1])});const l=Math.max(a-s,1),h=Math.max(o-r,1),d=Math.min((i-2*e)/l,(n-2*e)/h,1.25),c=(i-l*d)/2-s*d,u="start"===this.fitViewportAlign?e-r*d:(n-h*d)/2-r*d;this.ice.setViewport(d,c,u)}__viewportSize(){const e=this.ice,t=e&&e.dpr?e.dpr:1,i=e&&"function"==typeof e.getInputRect?e.getInputRect():null;return{width:i&&i.width>0?i.width:(e?.canvasWidth||0)/t,height:i&&i.height>0?i.height:(e?.canvasHeight||0)/t}}canUndo(){return this.__undoStack.length>0}toSvg(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return i.exportSvg(this.ice,e)}canRedo(){return this.__redoStack.length>0}captureHistory(){this.__captureHistory()}resetHistory(){this.__undoStack.length=0,this.__redoStack.length=0}__captureHistory(){this.__historyEnabled&&(this.__undoStack.push(this.serialize()),this.__undoStack.length>this.__maxHistory&&this.__undoStack.shift(),this.__redoStack.length=0)}__applySnapshot(e){const t=JSON.parse(e);t&&t.scene?this.__applyEngineScene(t.scene):this.__clearAndBuild(t)}undo(){if(!this.canUndo())return;const e=this.serialize(),t=this.__undoStack.pop();this.__redoStack.push(e),this.__historyEnabled=!1;try{this.__applySnapshot(t)}catch(e){throw this.__redoStack.pop(),this.__undoStack.push(t),e}finally{this.__historyEnabled=!0}this.__emitChange()}redo(){if(!this.canRedo())return;const e=this.serialize(),t=this.__redoStack.pop();this.__undoStack.push(e),this.__historyEnabled=!1;try{this.__applySnapshot(t)}catch(e){throw this.__undoStack.pop(),this.__redoStack.push(t),e}finally{this.__historyEnabled=!0}this.__emitChange()}__handleMouseDown(e){const t=e&&e.param&&e.param.component;if(!t)return;let i=t;for(;i;){const e=i.constructor&&i.constructor.typeId;if(e===FlowNode.typeId||e===FlowEdge.typeId)return void this.select(i.state.id);i=i.parentNode}}dispose(){this.ice.evtBus.off("mousedown",this.__mousedownHandler,this),this.ice.evtBus.off("mouseup",this.__mouseupHandler,this),this.nodes.forEach(e=>this.__detachNodeListeners(e))}}function endpointId(e,t){return((e.state.links||{})[t]||{}).id}function boxOf(e){const t=e.getMinBoundingBox(!0);return{x0:t.tl[0],y0:t.tl[1],x1:t.br[0],y1:t.br[1]}}function contains(e,t){const i=(t.x0+t.x1)/2,n=(t.y0+t.y1)/2;return i>=e.x0&&i<=e.x1&&n>=e.y0&&n<=e.y1}function owningPool(e,t){const i=boxOf(e),n=t.filter(e=>"bpmnPool"===e.state.kind);for(const e of n)if(contains(boxOf(e),i))return e;return null}function validateBpmn(e){const t=[],i=e.nodes||[],n=e.edges||[],s=new Map;i.forEach(e=>s.set(e.state.id,e));const r=i.filter(e=>!!e&&-1!==["bpmnEvent","bpmnTask","bpmnGateway","bpmnSubprocess"].indexOf(e.state.kind)),a=n.filter(e=>"sequence"===(e.state.flowType||"sequence")),o=n.filter(e=>"message"===e.state.flowType),l=new Map,h=new Map;r.forEach(e=>{l.set(e.state.id,[]),h.set(e.state.id,[])}),a.forEach(e=>{const t=endpointId(e,"start"),i=endpointId(e,"end"),n=l.get(t),s=h.get(i);n&&n.push(e),s&&s.push(e)}),r.forEach(e=>{const i=e.state.kind,n=e.state.eventKind,s=l.get(e.state.id)||[],r=h.get(e.state.id)||[];if("bpmnEvent"===i&&"start"===n&&(r.length&&t.push({level:"error",code:"start-incoming",componentId:e.state.id,message:`开始事件「${e.state.title}」不能有流入的顺序流`}),s.length||t.push({level:"error",code:"start-no-outgoing",componentId:e.state.id,message:`开始事件「${e.state.title}」缺少流出的顺序流`})),"bpmnEvent"===i&&"end"===n&&(s.length&&t.push({level:"error",code:"end-outgoing",componentId:e.state.id,message:`结束事件「${e.state.title}」不能有流出的顺序流`}),r.length||t.push({level:"warning",code:"end-no-incoming",componentId:e.state.id,message:`结束事件「${e.state.title}」没有流入的顺序流(不可达)`})),"bpmnGateway"===i){const i=e.state.gatewayType||"exclusive";s.length<1&&t.push({level:"error",code:"gateway-no-outgoing",componentId:e.state.id,message:`网关「${e.state.title}」至少要有一条流出顺序流`}),"exclusive"!==i&&s.length<2&&t.push({level:"warning",code:"gateway-too-few-branches",componentId:e.state.id,message:`${{parallel:"并行",inclusive:"包容",event:"事件"}[i]||i}网关「${e.state.title}」通常应有 ≥2 条出边`});const n=s.filter(e=>e.state.isDefault);n.length>1&&t.push({level:"error",code:"gateway-multi-default",componentId:e.state.id,message:`网关「${e.state.title}」只能有一条默认流(当前 ${n.length} 条)`}),n.length&&"exclusive"!==i&&"inclusive"!==i&&t.push({level:"warning",code:"gateway-default-on-and",componentId:e.state.id,message:`并行网关「${e.state.title}」不应设置默认流`})}r.length||s.length||"bpmnPool"===i||"bpmnLane"===i||"bpmnAnnotation"===i||"bpmnEvent"===i&&"start"===n||t.push({level:"warning",code:"isolated-node",componentId:e.state.id,message:`「${e.state.title}」没有连任何顺序流`})});i.filter(e=>"bpmnPool"===e.state.kind).forEach(e=>{const i=boxOf(e),n=r.filter(e=>contains(i,boxOf(e))),s=n.filter(e=>"bpmnEvent"===e.state.kind&&"start"===e.state.eventKind);n.length&&!s.length&&t.push({level:"error",code:"pool-no-start",componentId:e.state.id,message:`池「${e.state.title}」里没有开始事件`})}),a.forEach(e=>{const n=s.get(endpointId(e,"start")),r=s.get(endpointId(e,"end"));if(!n||!r)return;owningPool(n,i)!==owningPool(r,i)&&t.push({level:"error",code:"sequence-flow-cross-pool",componentId:e.state.id,message:`顺序流不能跨池(「${n.state.title}」→「${r.state.title}」);跨参与者请用消息流`})}),o.forEach(e=>{const n=s.get(endpointId(e,"start")),r=s.get(endpointId(e,"end"));if(!n||!r)return;const a=owningPool(n,i),o=owningPool(r,i);a&&o&&a===o&&t.push({level:"warning",code:"message-flow-same-pool",componentId:e.state.id,message:"消息流通常用于跨池(不同参与者)之间的通信"})});const d=new Set,c=r.filter(e=>"bpmnEvent"===e.state.kind&&"start"===e.state.eventKind).map(e=>e.state.id);for(c.forEach(e=>d.add(e));c.length;){const e=c.shift();(l.get(e)||[]).forEach(e=>{const t=endpointId(e,"end");t&&!d.has(t)&&(d.add(t),c.push(t))})}return r.forEach(e=>{d.has(e.state.id)||t.push({level:"warning",code:"unreachable-node",componentId:e.state.id,message:`「${e.state.title}」从开始事件出发不可达`})}),t}class SimTokenDot extends i.ICECircle{static typeId="ice-entity-designer:SimToken";constructor(){super({radius:7,stroke:!1,interactive:!1,zIndex:10000020,...arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}})}}function escapeXml(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function localName(e){return(e&&(e.localName||e.nodeName||"")).split(":").pop()}function rectOf(e){const t=e.getMinBoundingBox(!0);return{x0:t.tl[0],y0:t.tl[1],x1:t.br[0],y1:t.br[1]}}function centerInside(e,t){const i=(t.x0+t.x1)/2,n=(t.y0+t.y1)/2;return i>=e.x0&&i<=e.x1&&n>=e.y0&&n<=e.y1}const rn={class:"",interface:"«interface»",enum:"«enumeration»"};class UmlClass extends i.ICEGroup{static typeId="ice-entity-designer:UmlClass";stereotypeComponent=null;nameComponent=null;headerBackgroundComponent=null;memberComponents=[];dividerComponents=[];hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(UmlClass.arrangeParam(e)),this.syncCompartments()}static arrangeParam(e){const t=Li({kind:"class",className:"Class",attributes:[],methods:[],width:220,height:120,style:{strokeStyle:"#94a3b8",fillStyle:"#ffffff",radius:8,lineWidth:1.25,shadow:"sm"},headerStyle:{textColor:"#1e293b",stereotypeColor:"#6366f1",backgroundColor:"#eef2ff",fontSize:15,fontWeight:"bold",paddingTop:9,paddingBottom:9,paddingLeft:12,paddingRight:12},memberStyle:{textColor:"#475569",fontSize:12.5,paddingTop:5,paddingBottom:3,paddingLeft:12,paddingRight:12},dividerStyle:{strokeStyle:"#e2e8f0",fillStyle:"#e2e8f0",lineWidth:1}},e,{transformable:!1});return Ve(t.className)&&(t.className="Class"),Array.isArray(t.attributes)||(t.attributes=[]),Array.isArray(t.methods)||(t.methods=[]),t}static __layoutKeys=["kind","className","attributes","methods","abstract","width","headerStyle","memberStyle","dividerStyle"];setState(e){const t=!!e&&UmlClass.__layoutKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncCompartments()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}syncCompartments(){this.__clearDerivedChildren();const e=this.state.width,t=this.state.kind||"class",n=rn[t]||(this.state.abstract?"«abstract»":""),s=this.state.headerStyle,r=this.state.memberStyle;let a=0;const o=Number(this.state.zIndex)||0,lineHeight=(e,t,i)=>Math.round(1.35*e+t+i),l=(this.state.style.lineWidth||1.5)/2,h=[];if(n){const t=Math.max((s.fontSize||16)-2,10),r=lineHeight(t,s.paddingTop,0),l=new i.ICEText({zIndex:o+2,left:0,top:a,width:e,height:r,text:n,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:t,fillStyle:s.stereotypeColor||s.textColor,textAlign:"center",textBaseline:"middle"}});this.stereotypeComponent=l,h.push(l),a+=r}const d=lineHeight(s.fontSize||16,n?0:s.paddingTop,s.paddingBottom),c=new i.ICEText({zIndex:o+2,left:0,top:a,width:e,height:d,text:String(this.state.className||""),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:s.fontSize,fillStyle:s.textColor,fontWeight:s.fontWeight,textAlign:"center",textBaseline:"middle",fontStyle:"interface"===t?"italic":"normal"}});this.nameComponent=c,h.push(c),a+=d;const u=a;s.backgroundColor&&"none"!==s.backgroundColor&&(this.headerBackgroundComponent=new i.ICERect({zIndex:o+1,left:l,top:l,width:Math.max(e-2*l,0),height:Math.max(u-l,0),origin:"top-left",radius:Math.max((this.state.style.radius||0)-l,0),stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:s.backgroundColor,lineWidth:0}}),this.addChild(this.headerBackgroundComponent)),h.forEach(e=>this.addChild(e));[this.state.attributes||[],this.state.methods||[]].forEach((t,n)=>{const s=new i.ICEPolyLine({zIndex:o+2,left:0,top:0,points:[[0,a],[e,a]],stroke:!0,interactive:!1,linkable:!1,style:{strokeStyle:this.state.dividerStyle.strokeStyle,fillStyle:this.state.dividerStyle.fillStyle,lineWidth:this.state.dividerStyle.lineWidth}});this.dividerComponents.push(s),this.addChild(s);const l=lineHeight(r.fontSize||13,r.paddingTop,r.paddingBottom);t.length?(t.forEach(t=>{const n=new i.ICEText({zIndex:o+2,left:0,top:a,width:e,height:l,text:String(t),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:r.fontSize,fillStyle:r.textColor,textBaseline:"middle",textAlign:"left",paddingLeft:r.paddingLeft}});this.memberComponents.push(n),this.addChild(n),a+=l}),a+=6):a+=l}),this.state.height=Math.max(Math.round(a),this.state.height||0)}__clearDerivedChildren(){this.headerBackgroundComponent&&(this.removeChild(this.headerBackgroundComponent),this.headerBackgroundComponent=null),this.stereotypeComponent&&(this.removeChild(this.stereotypeComponent),this.stereotypeComponent=null),this.nameComponent&&(this.removeChild(this.nameComponent),this.nameComponent=null),this.memberComponents.length&&(this.removeChildren(this.memberComponents),this.memberComponents.length=0),this.dividerComponents.length&&(this.removeChildren(this.dividerComponents),this.dividerComponents.length=0)}}const an=["inheritance","realization","association","aggregation","composition","dependency"],on={inheritance:{marker:"triangle",markerEnd:"end",filled:!1,dashed:!1},realization:{marker:"triangle",markerEnd:"end",filled:!1,dashed:!0},association:{marker:"none",markerEnd:"end",filled:!1,dashed:!1},aggregation:{marker:"diamond",markerEnd:"start",filled:!1,dashed:!1},composition:{marker:"diamond",markerEnd:"start",filled:!0,dashed:!1},dependency:{marker:"open",markerEnd:"end",filled:!1,dashed:!0}},ln={inheritance:"#6366f1",realization:"#8b5cf6",association:"#64748b",aggregation:"#0d9488",composition:"#0f766e",dependency:"#94a3b8"};class UmlRelation extends i.ICEPolyLine{static typeId="ice-entity-designer:UmlRelation";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(UmlRelation.arrangeParam(e)),this.__applyNotation(),this.setState({keepHistory:!1}),this.paramsDirty=!0}static arrangeParam(e){return Li({transformable:!1,relationKind:"association",label:"",arrowLength:12,fill:!1},e)}setState(e){const t=!!e&&(Object.prototype.hasOwnProperty.call(e,"relationKind")||Object.prototype.hasOwnProperty.call(e,"arrowLength"));super.setState(e),t&&this.state.relationKind&&this.__applyNotation()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}__applyNotation(){const e=this.state.relationKind||"association",t=on[e]||on.association,i=ln[e]||ln.association;this.state.umlMarker=t.marker,this.state.arrowStyle="none"===t.marker?"none":t.filled?"filled":"hollow",this.state.lineDash=t.dashed?this.state.lineDash&&this.state.lineDash.length?this.state.lineDash:[8,5]:[],this.state.arrow="none"===t.marker?"none":t.markerEnd,this.state.style={...this.state.style||{},strokeStyle:i,fillStyle:i,lineWidth:1.4}}calcArrowPoints(){const e=this.__arrowFaceIndexes;e.length=0;const t=this.state.relationKind||"association",i=on[t]||on.association,n=this.state.dots;if(!n||n.length<2||"none"===i.marker)return;const s="start"===i.markerEnd,r=[...s?n[0]:n[n.length-1]],a=[...s?n[1]:n[n.length-2]],o=r[0]-a[0],l=r[1]-a[1],h=Math.hypot(o,l)||1,d=o/h,c=l/h,u=this.state.arrowLength||14,p=.4*u,f=-c,g=d;if("triangle"===i.marker||"open"===i.marker){const t=this.doCalcArrowPoints([r,a]);return void(s?(n.unshift(...t),n.unshift([...r]),e.push(0)):(n.push(...t),n.push([...r]),e.push(n.length-4)))}const m=r[0]-d*(u/2),y=r[1]-c*(u/2),_=[[r[0],r[1]],[m+f*p,y+g*p],[r[0]-d*u,r[1]-c*u],[m-f*p,y-g*p]];s?(n.unshift(_[3],_[2],_[1]),e.push(0)):(n.push(_[1],_[2],_[3],[...r]),e.push(n.length-4))}}function normalizeLabelStyle(e){if(!e||"object"!=typeof e)return e;const t=e.labelStyle,i=e.style||{};if(!t&&i.label)return e;const n={...e,style:{...i,label:{...t||{},...i.label||{}}}};return delete n.labelStyle,n}class StateNode extends i.ICEGroup{static typeId="ice-entity-designer:StateNode";shapeComponent=null;innerRingComponent=null;labelComponent=null;hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(StateNode.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=normalizeLabelStyle(e);const t=e.kind||"state",i="initial"===t||"final"===t;return Li({kind:t,title:"状态",width:i?24:"composite"===t?320:160,height:i?24:"composite"===t?200:64,fill:!1,stroke:!1,style:{strokeStyle:"#94a3b8",fillStyle:"#ffffff",lineWidth:1.25,shadow:"sm",label:{textColor:"#1e293b",fontSize:13.5,fontWeight:"normal",paddingLeft:12,paddingTop:10}}},e,{transformable:!1})}static __shapeKeys=["kind","title","width","height","style"];setState(e){const t=!!e&&StateNode.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}isPseudoState(){return"initial"===this.state.kind||"final"===this.state.kind}syncShape(){this.__clearDerivedChildren();const e=Number(this.state.zIndex)||0,t=this.state.kind||"state",n=this.state.width,s=this.state.height;if("initial"===t)return this.shapeComponent=new i.ICECircle({zIndex:e+1,left:0,top:0,radius:Math.min(n,s)/2,stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.pseudoColor||"#334155"}}),void this.addChild(this.shapeComponent);if("final"===t){const t=Math.min(n,s)/2,r=this.state.style.lineWidth||1.5;return this.shapeComponent=new i.ICECircle({zIndex:e+1,left:0,top:0,radius:t,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.fillStyle||"#ffffff",strokeStyle:this.state.style.pseudoColor||"#334155",lineWidth:r}}),this.innerRingComponent=new i.ICECircle({zIndex:e+2,left:0,top:0,radius:.6*t,stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.pseudoColor||"#334155"}}),this.addChild(this.shapeComponent),void this.addChild(this.innerRingComponent)}this.shapeComponent=new i.ICERect({zIndex:e+1,left:0,top:0,width:n,height:s,radius:"composite"===t?14:12,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.fillStyle||"#ffffff",strokeStyle:this.state.style.strokeStyle||"#334155",lineWidth:this.state.style.lineWidth||1.5,shadow:this.state.style.shadow,lineDash:"composite"===t?[6,5]:[]}}),this.addChild(this.shapeComponent);const r="composite"===t;this.labelComponent=new i.ICEText({zIndex:e+2,left:0,top:0,width:n,height:r?Math.max(this.state.style.label.fontSize+2*this.state.style.label.paddingTop,28):s,text:String(this.state.title||""),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:this.state.style.label.fontSize,fontWeight:this.state.style.label.fontWeight,fillStyle:this.state.style.label.textColor,textAlign:r?"left":"center",textBaseline:r?"top":"middle",paddingLeft:r?this.state.style.label.paddingLeft:0,paddingTop:r?this.state.style.label.paddingTop:0}}),this.addChild(this.labelComponent)}__clearDerivedChildren(){this.shapeComponent&&(this.removeChild(this.shapeComponent),this.shapeComponent=null),this.innerRingComponent&&(this.removeChild(this.innerRingComponent),this.innerRingComponent=null),this.labelComponent&&(this.removeChild(this.labelComponent),this.labelComponent=null)}}class StateTransition extends i.ICEPolyLine{static typeId="ice-entity-designer:StateTransition";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(StateTransition.arrangeParam(e))}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=normalizeLabelStyle(e);const t=Li({transformable:!1,event:"",guard:"",action:"",arrow:"end",arrowStyle:"filled",fill:!1,arrowLength:12,style:{strokeStyle:"#64748b",fillStyle:"#64748b",lineWidth:1.4,label:{fontSize:12.5,fillStyle:"#334155",backgroundColor:"#ffffff"}}},e);return void 0===e.label&&(t.label=StateTransition.composeLabel(t)),t}static composeLabel(e){const t=(e.event||"").trim(),i=(e.guard||"").trim(),n=(e.action||"").trim();let s=t;return i&&(s+=`${s?" ":""}[${i}]`),n&&(s+=`${s?" / ":""}${n}`),s}setState(e){const t=!!e&&["event","guard","action"].some(t=>Object.prototype.hasOwnProperty.call(e,t))&&!Object.prototype.hasOwnProperty.call(e,"label")?{...e,label:StateTransition.composeLabel({...this.state,...e})}:e;super.setState(t)}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}}const hn=/^[A-Za-z_\u4e00-\u9fa5][A-Za-z0-9_\u4e00-\u9fa5-]*$/;function kindOf(e){return e.state.kind||"state"}function isPseudo(e){return"initial"===e||"final"===e}function splitTransitionLabel(e){const t=String(e||"").trim();if(!t)return{event:"",guard:"",action:""};const i=t.indexOf(" / "),n=-1===i?t:t.slice(0,i),s=-1===i?"":t.slice(i+3).trim(),r=/\[([^\]]*)\]\s*$/.exec(n);return r?{event:n.slice(0,r.index).trim(),guard:r[1].trim(),action:s}:{event:n.trim(),guard:"",action:s}}const dn=864e5;function parseDate(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(String(e||"").trim());if(!t)return Number.NaN;const i=Number(t[1]),n=Number(t[2]),s=Number(t[3]);return Date.UTC(i,n-1,s)}function formatDate(e){const t=new Date(e),pad=e=>e<10?`0${e}`:String(e);return`${t.getUTCFullYear()}-${pad(t.getUTCMonth()+1)}-${pad(t.getUTCDate())}`}function addDays(e,t){const i=parseDate(e);return isNaN(i)?e:formatDate(i+t*dn)}function diffDays(e,t){const i=parseDate(e),n=parseDate(t);return isNaN(i)||isNaN(n)?0:Math.round((n-i)/dn)}function tickLabel(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return e;const i=Number(t[2]),n=Number(t[3]);return 1===n?`${i}月`:String(n)}class GanttTask extends i.ICEGroup{static typeId="ice-entity-designer:GanttTask";barComponent=null;progressComponent=null;labelComponent=null;hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(GanttTask.arrangeParam(e)),this.syncBar()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e=normalizeLabelStyle(e),Li({title:"任务",start:"2026-01-01",days:3,progress:0,row:0,resource:"",dayWidth:28,originDate:"2026-01-01",labelColumnWidth:140,rowHeight:36,headerHeight:34,style:{barFill:"#60a5fa",progressFill:"#2563eb",strokeStyle:"#3b82f6",lineWidth:1,label:{textColor:"#ffffff",fontSize:12}},transformable:!1},e)}static __shapeKeys=["title","start","days","progress","row","resource","dayWidth","originDate","labelColumnWidth","rowHeight","headerHeight","style"];setState(e){const t=!!e&&GanttTask.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&(this.syncGeometry(),this.syncBar(),this.trigger("AFTER_MOVE",{left:this.state.left,top:this.state.top,target:this}))}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}setPosition(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const n=this.state.dayWidth||28,s=this.state.labelColumnWidth||0,r=this.state.rowHeight||36,a=this.state.headerHeight||34,o=Math.max(0,Math.round((e-s)/n)),l=Math.max(0,Math.round((t-a)/r));this.state.start=addDays(this.state.originDate,o),this.state.row=l,super.setState({start:this.state.start,row:l}),super.setPosition(s+o*n,a+l*r,i||void 0),this.syncBar()}barLeft(){return this.state.left}progressWidth(){return Math.max(0,Math.min(1,Number(this.state.progress)||0))*this.state.width}syncGeometry(){const e=this.state.dayWidth||28,t=Math.max(1,Number(this.state.days)||1);this.state.width=t*e,this.state.height=Math.max(18,(this.state.rowHeight||36)-14),this.state.left=(this.state.labelColumnWidth||0)+diffDays(this.state.originDate,this.state.start)*e,this.state.top=(this.state.headerHeight||34)+(Number(this.state.row)||0)*(this.state.rowHeight||36)+7}syncBar(){this.__clearDerivedChildren();const e=Number(this.state.zIndex)||0,t=this.state.width,n=this.state.height,s=this.state.style;this.barComponent=new i.ICERect({zIndex:e+1,left:0,top:0,width:t,height:n,radius:Math.min(4,n/2),stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:s.barFill,strokeStyle:s.strokeStyle,lineWidth:s.lineWidth}}),this.addChild(this.barComponent);const r=Math.max(0,Math.min(1,Number(this.state.progress)||0));r>0&&(this.progressComponent=new i.ICERect({zIndex:e+2,left:0,top:0,width:this.progressWidth(),height:n,radius:Math.min(4,n/2),stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:s.progressFill}}),this.addChild(this.progressComponent));const a=Math.round(100*r);this.labelComponent=new i.ICEText({zIndex:e+3,left:0,top:0,width:t,height:n,text:`${this.state.title}(${Math.max(1,Number(this.state.days)||1)} 天)${a>0?` · ${a}%`:""}`,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:this.state.style.label.fontSize,fillStyle:this.state.style.label.textColor,textAlign:"left",textBaseline:"middle",paddingLeft:8}}),this.addChild(this.labelComponent)}__clearDerivedChildren(){[this.barComponent,this.progressComponent,this.labelComponent].forEach(e=>{e&&this.removeChild(e)}),this.barComponent=null,this.progressComponent=null,this.labelComponent=null}}class GanttDependency extends i.ICEPolyLine{static typeId="ice-entity-designer:GanttDependency";constructor(){super(Li({transformable:!1,arrow:"end",arrowStyle:"filled",fill:!1,routeType:"orthogonal",routeOffset:14,arrowLength:12,style:{strokeStyle:"#94a3b8",fillStyle:"#94a3b8",lineWidth:1.3}},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}))}}class GanttRuler extends i.ICEGroup{static typeId="ice-entity-designer:GanttRuler";constructor(){super({left:0,top:0,width:0,height:0,fill:!1,stroke:!1,interactive:!1,draggable:!1,linkable:!1})}hasDerivedChildren(){return!0}sync(e){this.removeChildren([...this.childNodes]);const{dayWidth:t,labelColumnWidth:n,headerHeight:s,rowHeight:r,originDate:a,dayCount:o,tasks:l}=e,h=n+o*t;this.state.width=h,this.state.height=s+l.length*r;const d=Number(this.state.zIndex)||0;if(this.addChild(new i.ICERect({zIndex:d+1,left:0,top:0,width:h,height:this.state.height,stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#ffffff"}})),this.addChild(new i.ICERect({zIndex:d+2,left:0,top:0,width:n,height:this.state.height,stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#f8fafc"}})),this.addChild(new i.ICERect({zIndex:d+2,left:0,top:0,width:h,height:s,stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#f1f5f9"}})),this.addChild(this.__text("任务",0,0,n,s,"#0f172a",13,"center",d+3)),!a)return;for(let e=0;e<o;e++){const r=new Date(Date.parse(`${this.__addDays(a,e)}T00:00:00Z`)).getUTCDay();0!==r&&6!==r||this.addChild(new i.ICERect({zIndex:d+1,left:n+e*t,top:s,width:t,height:Math.max(this.state.height-s,0),stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#f1f5f9"}}))}const c=[];for(let e=0;e<o;e++)c.push(tickLabel(this.__addDays(a,e)));const u=o<=40;c.forEach((e,r)=>{const o=this.__addDays(a,r),l=1===new Date(Date.parse(`${o}T00:00:00Z`)).getUTCDay(),h=o.endsWith("-01"),c=u||l||h,p=n+r*t;this.addChild(new i.ICEPolyLine({zIndex:d+2,points:[[p,s],[p,this.state.height]],linkable:!1,interactive:!1,style:{strokeStyle:h?"#cbd5e1":l?"#e2e8f0":"#f1f5f9",fillStyle:"#e2e8f0",lineWidth:1}})),c&&this.addChild(this.__text(e,p,0,t,s,"#64748b",11,"center",d+3))}),l.forEach((e,t)=>{const a=s+t*r;this.addChild(this.__text(e.title,0,a,n,r,"#334155",13,"left",d+3,12)),this.addChild(new i.ICEPolyLine({zIndex:d+2,points:[[0,a+r],[h,a+r]],linkable:!1,interactive:!1,style:{strokeStyle:"#e2e8f0",fillStyle:"#e2e8f0",lineWidth:1}}))}),this.addChild(new i.ICEPolyLine({zIndex:d+3,points:[[0,s],[h,s]],linkable:!1,interactive:!1,style:{strokeStyle:"#cbd5e1",fillStyle:"#cbd5e1",lineWidth:1}})),this.addChild(new i.ICEPolyLine({zIndex:d+3,points:[[n,0],[n,this.state.height]],linkable:!1,interactive:!1,style:{strokeStyle:"#cbd5e1",fillStyle:"#cbd5e1",lineWidth:1}}))}__addDays(e,t){const i=Date.parse(`${e}T00:00:00Z`),n=new Date(i+24*t*60*60*1e3),pad=e=>e<10?`0${e}`:String(e);return`${n.getUTCFullYear()}-${pad(n.getUTCMonth()+1)}-${pad(n.getUTCDate())}`}__text(e,t,n,s,r,a,o,l,h){let d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:0;return new i.ICEText({zIndex:h,left:t,top:n,width:s,height:r,text:e,stroke:!1,linkable:!1,interactive:!1,style:{fontSize:o,fillStyle:a,textAlign:l,textBaseline:"middle",paddingLeft:d}})}}const cn=/^(gantt|title|dateFormat|axisFormat|excludes|includes|todayMarker|tickInterval|accTitle|accDescr|displayMode|weekday)\b/i,un=/^\d{4}-\d{2}-\d{2}$/,pn=/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/i,fn=/^(done|active|crit|milestone|vert)$/i;const gn=[{level:"500kV",colorName:"淡黄",color:"#f2e394",kv:500},{level:"220kV",colorName:"紫",color:"#8b5cf6",kv:220},{level:"110kV",colorName:"朱红",color:"#e05252",kv:110},{level:"35kV",colorName:"鲜黄",color:"#f5c518",kv:35},{level:"10kV",colorName:"绛红",color:"#9b1c31",kv:10},{level:"6kV",colorName:"深蓝",color:"#1d4ed8",kv:6}],mn="#1f2937";function defaultVoltageColors(){const e={};return gn.forEach(t=>{e[t.level]=t.color}),e}function voltageColorOf(e,t){if(!e)return mn;return(t||defaultVoltageColors())[e]||mn}const yn={busbar:{label:"母线",tag:"W",width:260,height:20,inline:!1},breaker:{label:"断路器",tag:"QF",width:44,height:52,inline:!0},disconnector:{label:"隔离开关",tag:"QS",width:44,height:52,inline:!0},loadSwitch:{label:"负荷开关",tag:"QL",width:44,height:52,inline:!0},earthingSwitch:{label:"接地开关",tag:"QE",width:44,height:60,inline:!0},earth:{label:"接地",tag:"E",width:40,height:34,inline:!1},currentTransformer:{label:"电流互感器",tag:"TA",width:44,height:52,inline:!0},voltageTransformer:{label:"电压互感器",tag:"TV",width:48,height:70,inline:!0},transformer:{label:"变压器",tag:"TM",width:52,height:76,inline:!0},fuse:{label:"熔断器",tag:"FU",width:40,height:56,inline:!0},arrester:{label:"避雷器",tag:"F",width:40,height:62,inline:!1},reactor:{label:"电抗器",tag:"L",width:44,height:56,inline:!0},generator:{label:"发电机",tag:"G",width:52,height:52,inline:!1},motor:{label:"电动机",tag:"M",width:52,height:52,inline:!1},load:{label:"负荷 / 出线",tag:"-",width:40,height:40,inline:!1},capacitor:{label:"并联电容器",tag:"C",width:52,height:56,inline:!0},arcSuppressionCoil:{label:"消弧线圈",tag:"L",width:48,height:76,inline:!0},threeWindingTransformer:{label:"三绕组变压器",tag:"TM",width:56,height:92,inline:!0},groundingTransformer:{label:"接地变压器",tag:"TM",width:56,height:96,inline:!0},groundingResistor:{label:"接地电阻",tag:"R",width:44,height:72,inline:!0},cable:{label:"电缆",tag:"W",width:44,height:72,inline:!0},cableTermination:{label:"电缆终端",tag:"W",width:48,height:64,inline:!0},cubicle:{label:"间隔 / 开关柜(方框)",tag:"GIS",width:200,height:140,inline:!1}},_n={strokeStyle:"#1f2937",lineWidth:1.6,heavyLineWidth:3,tagFontSize:10,tagColor:"#475569",letterFontSize:15,deEnergizedColor:"#94a3b8",nameFontSize:11,nameColor:"#334155",stateFontSize:10},bn=["breaker","disconnector","loadSwitch","earthingSwitch"];function arcPoints(e,t,i,n,s){let r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:16;const a=[];for(let o=0;o<=r;o++){const l=(n+(s-n)*o/r)*Math.PI/180;a.push([e+i*Math.cos(l),t+i*Math.sin(l)])}return a}class PowerSymbol extends i.ICEGroup{static typeId="ice-entity-designer:PowerSymbol";parts=[];hasDerivedChildren(){return!0}getSerializableChildren(){const e=this.parts.map(e=>e.component);return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(PowerSymbol.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.kind||"breaker",i=yn[t]||yn.breaker;return Li({kind:t,tag:i.tag,fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:_n.strokeStyle,lineWidth:_n.lineWidth},tagStyle:{fontSize:_n.tagFontSize,textColor:_n.tagColor},name:"",voltageLevel:"",voltageColors:null,switchState:"open",energized:void 0,transformable:!1,energizedSource:!1,attachedBusId:""},e)}static __shapeKeys=["kind","tag","width","height","style","tagStyle","name","voltageLevel","voltageColors","switchState","energized"];setState(e){const t=!!e&&PowerSymbol.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}part(e){const t=this.parts.find(t=>t.role===e);return t?t.component:null}syncShape(){var e=this;this.__clearParts();const t=this.state.kind||"breaker",n=yn[t]||yn.breaker,s=this.state.width||n.width,r=this.state.height||n.height,a=this.state.style&&this.state.style.lineWidth||_n.lineWidth,o=this.state.style&&this.state.style.strokeStyle||_n.strokeStyle,l=!1===this.state.energized?_n.deEnergizedColor:this.state.voltageLevel?voltageColorOf(this.state.voltageLevel,this.state.voltageColors||void 0):o||mn,h=s/2,d=Number(this.state.zIndex)||0,c=-1!==bn.indexOf(t),u="closed"===this.state.switchState,line=function(t,n){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a;return e.__add(t,new i.ICEPolyLine({zIndex:d+2,points:n,interactive:!1,linkable:!1,style:{strokeStyle:l,fillStyle:l,lineWidth:s}}))},rect=function(t,n,s,r,o){let h=arguments.length>5&&void 0!==arguments[5]&&arguments[5],c=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0;return e.__add(t,new i.ICERect({zIndex:d+2,left:n,top:s,width:r,height:o,radius:c,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:h?l:"#ffffff",strokeStyle:l,lineWidth:a}}))},circle=(e,t,n,s)=>this.__add(e,new i.ICECircle({zIndex:d+2,left:t,top:n,radius:s,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:l,lineWidth:a}})),text=(e,t,n,s,r,a,o)=>this.__add(e,new i.ICEText({zIndex:d+3,left:n,top:s,width:r,height:a,text:t,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:o,fillStyle:l,textAlign:"center",textBaseline:"middle"}}));switch(t){case"busbar":rect("busbar",0,r/2-_n.heavyLineWidth/2,s,_n.heavyLineWidth,!0);break;case"breaker":line("leadTop",[[h,0],[h,.22*r]]),line("arcMark",[[h-7,.22*r-7],[h+7,.22*r+7]]),line("arcMark",[[h+7,.22*r-7],[h-7,.22*r+7]]),line("blade",[[h,.22*r],[h-9,.78*r]]),line("leadBottom",[[h,.78*r],[h,r]]);break;case"disconnector":line("leadTop",[[h,0],[h,.22*r]]),line("contactBar",[[h-9,.22*r],[h+9,.22*r]]),line("blade",[[h,.22*r],[h-9,.78*r]]),line("leadBottom",[[h,.78*r],[h,r]]);break;case"loadSwitch":line("leadTop",[[h,0],[h,.16*r]]),this.__add("contactCircle",new i.ICECircle({zIndex:d+2,left:h,top:.22*r,radius:5,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:l,lineWidth:a}})),line("blade",[[h,.27*r],[h-9,.78*r]]),line("leadBottom",[[h,.78*r],[h,r]]);break;case"earthingSwitch":line("leadTop",[[h,0],[h,.18*r]]),line("blade",[[h,.18*r],[h-9,.5*r]]),line("leadBottom",[[h,.5*r],[h,.62*r]]),this.__earth(h,.62*r,14,l,a);break;case"earth":line("leadTop",[[h,0],[h,.45*r]]),this.__earth(h,.45*r,16,l,a);break;case"currentTransformer":line("leadTop",[[h,0],[h,r]]),circle("winding",h-11,r/2-11,11),line("polarityMark",[[h+9,r/2-4],[h+16,r/2-11],[h+16,r/2+4]]);break;case"voltageTransformer":line("leadTop",[[h,0],[h,.16*r]]),circle("windingPrimary",h-11,.16*r,11),circle("windingSecondary",h-11,.16*r+16,11),line("leadBottom",[[h,.16*r+32],[h,r]]);break;case"transformer":line("leadTop",[[h,0],[h,.16*r]]),circle("windingPrimary",h-12,.16*r,12),circle("windingSecondary",h-12,.16*r+18,12),line("leadBottom",[[h,.16*r+36],[h,r]]),text("windingMarkHigh","△",h-12,.16*r,24,24,11),text("windingMarkLow","Y",h-12,.16*r+18,24,24,11);break;case"fuse":line("leadTop",[[h,0],[h,r]]),rect("fuseBody",h-6,.2*r,12,.6*r);break;case"arrester":line("leadTop",[[h,0],[h,.2*r]]),rect("arresterBody",h-9,.2*r,18,.6*r),line("dischargeArrow",[[h,.3*r],[h,.66*r]]),line("dischargeArrowHead",[[h-5,.56*r],[h,.66*r],[h+5,.56*r]]),line("leadBottom",[[h,.8*r],[h,r]]);break;case"reactor":line("leadTop",[[h,0],[h,.2*r]]),line("coil",arcPoints(h,.2*r+10,10,0,180)),line("coil",arcPoints(h,.2*r+30,10,0,180)),line("leadBottom",[[h,.2*r+40],[h,r]]);break;case"generator":circle("body",h-s/2+2,r/2-Math.min(s,r)/2+2,Math.min(s,r)/2-2),text("letter","G",0,r/2-26,s,52,_n.letterFontSize);break;case"motor":circle("body",h-s/2+2,r/2-Math.min(s,r)/2+2,Math.min(s,r)/2-2),text("letter","M",0,r/2-26,s,52,_n.letterFontSize);break;case"capacitor":line("leadTop",[[h,0],[h,.34*r]]),line("plateTop",[[h-15,.34*r],[h+15,.34*r]]),line("plateBottom",[[h-15,.5*r],[h+15,.5*r]]),line("leadBottom",[[h,.5*r],[h,r]]);break;case"arcSuppressionCoil":line("leadTop",[[h,0],[h,.22*r]]),line("coil",arcPoints(h,.22*r+8,8,180,360)),line("coil",arcPoints(h,.22*r+24,8,180,360)),line("coil",arcPoints(h,.22*r+40,8,180,360)),line("leadBottom",[[h,.22*r+48],[h,.68*r]]),this.__earth(h,.68*r,14,l,a);break;case"threeWindingTransformer":{line("leadTop",[[h,0],[h,.14*r]]);const e=13;circle("windingHigh",h-e,.14*r,e),circle("windingMid",h-e,.14*r+18,e),circle("windingLow",h-e,.14*r+36,e),line("leadBottom",[[h,.14*r+49],[h,r]]);break}case"groundingTransformer":line("leadTop",[[h,0],[h,.16*r]]),circle("windingPrimary",h-12,.16*r,12),circle("windingSecondary",h-12,.16*r+18,12),line("leadBottom",[[h,.16*r+36],[h,.62*r]]),this.__earth(h,.62*r,14,l,a);break;case"groundingResistor":line("leadTop",[[h,0],[h,.24*r]]),rect("resistorBody",h-8,.24*r,16,.34*r),line("leadBottom",[[h,.58*r],[h,.72*r]]),this.__earth(h,.72*r,14,l,a);break;case"cable":line("leadTop",[[h,0],[h,r]]),rect("cableEnvelope",h-10,.3*r,20,.4*r,!1,10);break;case"cableTermination":line("leadTop",[[h,0],[h,r]]),line("terminationFlare",[[h-6,.34*r],[h+6,.34*r],[h+13,.62*r],[h-13,.62*r]]);break;case"cubicle":rect("cabinet",0,0,s,r),line("cabinetDivider",[[0,.24*r],[s,.24*r]]);break;case"load":line("leadTop",[[h,0],[h,.6*r]]),line("arrowHead",[[h-7,.5*r],[h,.66*r],[h+7,.5*r]])}const p=this.state.tag;p&&this.__add("tag",new i.ICEText({zIndex:d+4,left:s+4,top:r/2-8,width:44,height:16,text:String(p),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:this.state.tagStyle&&this.state.tagStyle.fontSize||_n.tagFontSize,fillStyle:this.state.tagStyle&&this.state.tagStyle.textColor||_n.tagColor,textAlign:"left",textBaseline:"middle"}})),this.state.name&&this.__add("nameLabel",new i.ICEText({zIndex:d+4,left:"busbar"===t?4:0,top:"busbar"===t?-18:-20,width:Math.max(s,64),height:16,text:String(this.state.name),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:_n.nameFontSize,fillStyle:_n.nameColor,textAlign:"busbar"===t?"left":"center",textBaseline:"middle"}})),c&&this.__add("stateBadge",new i.ICEText({zIndex:d+4,left:-24,top:r/2-8,width:20,height:16,text:u?"合":"分",stroke:!1,interactive:!1,linkable:!1,style:{fontSize:_n.stateFontSize,fillStyle:l,textAlign:"center",textBaseline:"middle"}}))}__earth(e,t,n,s,r){[n,.62*n,.28*n].forEach((n,a)=>{this.__add("earth",new i.ICEPolyLine({zIndex:(Number(this.state.zIndex)||0)+2,points:[[e-n,t+6*a],[e+n,t+6*a]],interactive:!1,linkable:!1,style:{strokeStyle:s,fillStyle:s,lineWidth:r}}))})}__add(e,t){return this.parts.push({role:e,component:t}),this.addChild(t),t}__clearParts(){const e=this.parts.map(e=>e.component).filter(e=>-1!==this.childNodes.indexOf(e));e.length&&this.removeChildren(e),this.parts=[]}}class PowerLine extends FlowEdge{static typeId="ice-entity-designer:PowerLine";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super({...e,label:e.label||"",style:{...e.style||{}}}),this.setState({keepHistory:!1})}applyVoltageColor(e){const t=voltageColorOf(String(this.state.voltageLevel||""),e);this.setState({keepHistory:!1,style:{...this.state.style||{},strokeStyle:t,fillStyle:t}})}}const vn={contactNO:{label:"常开接点",tag:"52a",width:48,height:24},contactNC:{label:"常闭接点",tag:"52b",width:48,height:24},pushButton:{label:"按钮",tag:"11",width:48,height:40},switchRemoteLocal:{label:"切换开关(远方/就地)",tag:"43",width:64,height:32},linkPlate:{label:"压板(连接片)",tag:"XB",width:56,height:24},indicatorLamp:{label:"信号灯",tag:"HL",width:36,height:36},relayDevice:{label:"保护 / 自动装置",tag:"",width:220,height:90},ctWinding:{label:"互感器二次绕组",tag:"LH",width:48,height:44},terminal:{label:"端子",tag:"",width:28,height:28},earth:{label:"接地",tag:"E",width:40,height:34}},kn={strokeStyle:"#1f2937",lineWidth:1.4,heavyLineWidth:2.6,labelFontSize:10,labelColor:"#475569",tagFontSize:10,tagColor:"#64748b"};class SecondarySymbol extends i.ICEGroup{static typeId="ice-entity-designer:SecondarySymbol";parts=[];hasDerivedChildren(){return!0}getSerializableChildren(){const e=this.parts.map(e=>e.component);return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(SecondarySymbol.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.kind||"contactNO",i=vn[t]||vn.contactNO;return Li({kind:t,tag:i.tag,fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:kn.strokeStyle,lineWidth:kn.lineWidth},transformable:!1,name:"",tagStyle:{fontSize:kn.tagFontSize,textColor:kn.tagColor},switchState:"open"},e)}static __shapeKeys=["kind","tag","width","height","style","tagStyle","name","switchState"];setState(e){const t=!!e&&SecondarySymbol.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}part(e){const t=this.parts.find(t=>t.role===e);return t?t.component:null}syncShape(){var e=this;this.__clearParts();const t=this.state.kind||"contactNO",n=vn[t]||vn.contactNO,s=this.state.width||n.width,r=this.state.height||n.height,a=this.state.style&&this.state.style.strokeStyle||kn.strokeStyle,o=this.state.style&&this.state.style.lineWidth||kn.lineWidth,l=Number(this.state.zIndex)||0,h="closed"===this.state.switchState,d=r/2,line=function(t,n){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o;return e.__add(t,new i.ICEPolyLine({zIndex:l+2,points:n,interactive:!1,linkable:!1,style:{strokeStyle:a,fillStyle:a,lineWidth:s}}))},rect=function(t,n,s,r,h){let d=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;return e.__add(t,new i.ICERect({zIndex:l+2,left:n,top:s,width:r,height:h,radius:d,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:a,lineWidth:o}}))},circle=(e,t,n,s)=>this.__add(e,new i.ICECircle({zIndex:l+2,left:t,top:n,radius:s,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:a,lineWidth:o}})),text=function(t,n,s,r,o,h,d){let c=arguments.length>7&&void 0!==arguments[7]?arguments[7]:a;return e.__add(t,new i.ICEText({zIndex:l+3,left:s,top:r,width:o,height:h,text:n,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:d,fillStyle:c,textAlign:"center",textBaseline:"middle"}}))};switch(t){case"contactNO":line("leadLeft",[[0,d],[.36*s,d]]),line("fixedContact",[[.36*s,d-8],[.36*s,d+8]]),line("movingContact",[[.4*s,d-9],[.68*s,d+5]]),line("leadRight",[[.72*s,d],[s,d]]);break;case"contactNC":line("leadLeft",[[0,d],[.36*s,d]]),line("leadRight",[[.36*s,d],[s,d]]),line("fixedContact",[[.36*s,d-8],[.36*s,d+8]]),line("movingContact",[[.4*s,d-9],[.62*s,d+5]]);break;case"pushButton":line("leadLeft",[[0,d+4],[.36*s,d+4]]),line("fixedContact",[[.36*s,d-4],[.36*s,d+12]]),line("movingContact",[[.4*s,d-5],[.68*s,d+9]]),line("leadRight",[[.72*s,d+4],[s,d+4]]),line("actuator",[[.5*s,2],[.5*s,d-6]]),line("actuatorCap",[[.36*s,2],[.64*s,2]]);break;case"switchRemoteLocal":rect("switchBody",0,0,s,r,4),line("lever",[[.5*s,d+6],[.5*s+(h?10:-10),d-6]]),text("positionText",h?"就地":"远方",0,d+6,s,14,9,kn.labelColor);break;case"linkPlate":line("leadLeft",[[0,d],[.3*s,d]]),line("leadRight",[[.7*s,d],[s,d]]),line("plate",h?[[.3*s,d],[.7*s,d]]:[[.3*s,d-8],[.7*s,d+6]],1.6*o);break;case"indicatorLamp":line("leadTop",[[s/2,0],[s/2,.16*r]]),circle("lamp",4,.16*r,Math.min(s,r)/2-4),line("lampCrossA",[[.34*s,.32*r],[.66*s,.64*r]]),line("lampCrossB",[[.66*s,.32*r],[.34*s,.64*r]]),line("leadBottom",[[s/2,.84*r],[s/2,r]]);break;case"relayDevice":rect("deviceBody",0,0,s,r,4),text("deviceTitle",this.state.name||"装置",0,d-10,s,20,12,a),text("deviceModel",this.state.tag||"",0,d+10,s,16,10,kn.labelColor);break;case"ctWinding":line("leadTop",[[s/2,0],[s/2,.24*r]]),[0,1,2].forEach(e=>{const t=.24*r+10+14*e,i=[];for(let e=0;e<=12;e+=1){const n=(180+180*e/12)*Math.PI/180;i.push([s/2+10*Math.cos(n),t+10*Math.sin(n)])}line("winding",i)}),line("leadBottom",[[s/2,.24*r+52],[s/2,r]]);break;case"terminal":line("leadTop",[[s/2,0],[s/2,.3*r]]),circle("terminalCircle",4,.3*r,Math.min(s,r)/2-4),line("leadBottom",[[s/2,.7*r],[s/2,r]]);break;case"earth":line("leadTop",[[s/2,0],[s/2,.45*r]]);[16,10,4].forEach((e,t)=>{line("earth",[[s/2-e,.45*r+6*t],[s/2+e,.45*r+6*t]])});break}this.state.name&&"relayDevice"!==t&&("terminal"===t?this.__add("nameLabel",new i.ICEText({zIndex:l+4,left:-46,top:d-9,width:40,height:18,text:String(this.state.name),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:kn.labelFontSize,fillStyle:kn.labelColor,textAlign:"right",textBaseline:"middle"}})):text("nameLabel",String(this.state.name),0,-18,Math.max(s,56),16,kn.labelFontSize,kn.labelColor)),this.state.tag&&"relayDevice"!==t&&this.__add("tag",new i.ICEText({zIndex:l+4,left:s+2,top:r/2-8,width:40,height:16,text:String(this.state.tag),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:kn.tagFontSize,fillStyle:this.state.tagStyle&&this.state.tagStyle.textColor||kn.tagColor,textAlign:"left",textBaseline:"middle"}}))}__add(e,t){return this.parts.push({role:e,component:t}),this.addChild(t),t}__clearParts(){const e=this.parts.map(e=>e.component).filter(e=>-1!==this.childNodes.indexOf(e));e.length&&this.removeChildren(e),this.parts=[]}}class TerminalStrip extends i.ICEGroup{static typeId="ice-entity-designer:TerminalStrip";constructor(){super(Li({title:"端子排",width:96,height:240,fill:"#f8fafc",stroke:"#cbd5e1",lineWidth:1,style:{fillStyle:"#f8fafc",strokeStyle:"#cbd5e1",lineWidth:1},transformable:!1,interactive:!1,linkable:!1},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})),this.addChild(new i.ICEText({left:0,top:-20,width:Math.max(this.state.width,60),height:16,text:String(this.state.title||"端子排"),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:kn.labelFontSize,fillStyle:kn.labelColor,textAlign:"center",textBaseline:"middle"}}))}}class SecondaryWire extends FlowEdge{static typeId="ice-entity-designer:SecondaryWire";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super({...e,arrow:e.arrow||"none"}),this.setState({keepHistory:!1})}}const wn={sewage:{label:"污水",color:"#475569",lineType:"solid"},effluent:{label:"出水",color:"#0d9488",lineType:"solid"},recycle:{label:"混合液回流",color:"#0369a1",lineType:"solid"},returnSludge:{label:"回流污泥",color:"#a16207",lineType:"solid"},sludge:{label:"剩余污泥",color:"#92400e",lineType:"solid"},air:{label:"空气",color:"#0891b2",lineType:"dashed"},chemical:{label:"药剂",color:"#7c3aed",lineType:"dashed"},signal:{label:"仪表信号",color:"#9333ea",lineType:"dashdot"},power:{label:"动力回路",color:"#b45309",lineType:"dashdot"}},Sn={barScreen:{label:"格栅",tag:"GR",width:90,height:50,shape:"tank",inline:!1},gritChamber:{label:"曝气沉砂池",tag:"GC",width:120,height:60,shape:"tank",inline:!1},primaryClarifier:{label:"初沉池",tag:"PC",width:110,height:110,shape:"round",inline:!1},anaerobicTank:{label:"厌氧池",tag:"AT",width:120,height:70,shape:"tank",inline:!1},anoxicTank:{label:"缺氧池",tag:"AX",width:120,height:70,shape:"tank",inline:!1},aerobicTank:{label:"好氧池",tag:"AE",width:140,height:70,shape:"tank",inline:!1},secondaryClarifier:{label:"二沉池",tag:"SC",width:120,height:120,shape:"round",inline:!1},coagulationTank:{label:"混凝沉淀池",tag:"CO",width:110,height:70,shape:"tank",inline:!1},filterBed:{label:"滤池",tag:"FL",width:120,height:60,shape:"tank",inline:!1},disinfectionTank:{label:"消毒接触池",tag:"DT",width:130,height:60,shape:"tank",inline:!1},storageTank:{label:"调节 / 事故池",tag:"EQ",width:130,height:70,shape:"tank",inline:!1},deodorizer:{label:"除臭装置",tag:"OD",width:120,height:60,shape:"tank",inline:!1},sludgeThickener:{label:"污泥浓缩池",tag:"ST",width:100,height:100,shape:"round",inline:!1},dewateringMachine:{label:"污泥脱水机",tag:"DW",width:110,height:60,shape:"tank",inline:!1},sludgeSilo:{label:"污泥料仓",tag:"SIL",width:90,height:80,shape:"tank",inline:!1},pump:{label:"水泵",tag:"P",width:44,height:44,shape:"device",inline:!1},submersiblePump:{label:"潜污泵",tag:"P-SB",width:44,height:44,shape:"device",inline:!1},screwPump:{label:"螺杆泵",tag:"P-SC",width:64,height:44,shape:"device",inline:!1},blower:{label:"鼓风机",tag:"B",width:48,height:48,shape:"device",inline:!1},vfd:{label:"变频器",tag:"VFD",width:56,height:40,shape:"device",inline:!1},dosingUnit:{label:"加药装置",tag:"DU",width:60,height:70,shape:"device",inline:!1},valve:{label:"阀门",tag:"V",width:32,height:32,shape:"device",inline:!0},motorValve:{label:"电动阀",tag:"MOV",width:34,height:46,shape:"device",inline:!0},checkValve:{label:"止回阀",tag:"CV",width:32,height:32,shape:"device",inline:!0},flowMeter:{label:"流量计",tag:"FIT",width:36,height:36,shape:"device",inline:!0},levelGauge:{label:"液位计",tag:"LT",width:32,height:32,shape:"device",inline:!1},pressureGauge:{label:"压力表",tag:"PT",width:32,height:32,shape:"device",inline:!1},analyzer:{label:"在线水质分析仪",tag:"AIT",width:36,height:36,shape:"device",inline:!1},inlet:{label:"进水",tag:"IN",width:80,height:36,shape:"boundary",inline:!1},outlet:{label:"出水 / 排放",tag:"OUT",width:80,height:36,shape:"boundary",inline:!1},sludgeOut:{label:"污泥外运",tag:"SO",width:80,height:44,shape:"boundary",inline:!1}},Cn={strokeStyle:"#1f2937",lineWidth:1.4,detailLineWidth:1,waterFill:"#eff6ff",sludgeFill:"#fef3c7",tagFontSize:9.5,tagColor:"#64748b",nameFontSize:12,nameColor:"#1e293b",letterFontSize:14,hollowFill:"#ffffff",idleColor:"#94a3b8"},xn=["sludgeThickener","dewateringMachine","sludgeSilo","screwPump","sludgeOut"],In=["valve","motorValve"];function isWaterValveKind(e){return-1!==In.indexOf(e)}class WaterSymbol extends i.ICEGroup{static typeId="ice-entity-designer:WaterSymbol";parts=[];__originX=0;__originY=0;hasDerivedChildren(){return!0}getSerializableChildren(){const e=this.parts.map(e=>e.component);return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(WaterSymbol.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.kind||"pump",i=Sn[t]||Sn.pump;return Li({kind:t,tag:i.tag,name:"",fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:Cn.strokeStyle,lineWidth:Cn.lineWidth},tagStyle:{fontSize:Cn.tagFontSize,textColor:Cn.tagColor},valveState:"open",idle:!1,transformable:!1},e)}static __shapeKeys=["kind","tag","name","width","height","style","idle","valveState"];setState(e){const t=!!e&&WaterSymbol.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}part(e){const t=this.parts.find(t=>t.role===e);return t?t.component:null}syncShape(){this.__clearParts();const e=this.state.kind||"pump",t=Sn[e]||Sn.pump,i=this.state.width||t.width,n=this.state.height||t.height,s=this.state.style&&this.state.style.strokeStyle||Cn.strokeStyle,r=this.state.idle?Cn.idleColor:s,a=this.state.style&&this.state.style.lineWidth||Cn.lineWidth,o=-1!==xn.indexOf(e)?Cn.sludgeFill:Cn.waterFill,l=i/2,h=n/2,d=Number(this.state.zIndex)||0;switch(this.__originX=l,this.__originY=h,e){case"barScreen":this.__box(0,0,i,n,o,r,a,d);for(let e=1;e<=4;e++){const t=i/5*e-i/2;this.__poly([t,n/2,t+8,-n/2],r,Cn.detailLineWidth,d)}break;case"gritChamber":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/2+10,n/2,0,n/2+14,i/2-10,n/2],r,a,d),this.__circle(-i/4,-n/6,4,"none",r,Cn.detailLineWidth,d),this.__circle(0,n/8,3,"none",r,Cn.detailLineWidth,d),this.__circle(i/5,-n/8,3.5,"none",r,Cn.detailLineWidth,d);break;case"primaryClarifier":case"secondaryClarifier":{const t=Math.min(i,n)/2;this.__circle(0,0,t,o,r,a,d),this.__circle(0,0,t/6,"none",r,Cn.detailLineWidth,d),this.__poly([-t,0,t,0],r,Cn.detailLineWidth,d),"secondaryClarifier"===e&&this.__poly([.6*-t,.6*-t,.6*t,.6*t],r,Cn.detailLineWidth,d);break}case"anaerobicTank":case"anoxicTank":this.__box(0,0,i,n,o,r,a,d),this.__poly([0,-n/2,0,n/2-10],r,Cn.detailLineWidth,d),this.__poly([-10,n/2-10,10,n/2-10],r,Cn.detailLineWidth,d);break;case"aerobicTank":this.__box(0,0,i,n,o,r,a,d);for(let e=0;e<4;e++)this.__circle(-i/4+e*i/6,n/4,3.5,"none",r,Cn.detailLineWidth,d);break;case"coagulationTank":this.__box(0,0,i,n,o,r,a,d),this.__poly([0,-n/2,0,n/2-10],r,Cn.detailLineWidth,d),this.__poly([-10,n/2-10,10,n/2-10],r,Cn.detailLineWidth,d),this.__circle(-i/4,-n/4,3,"none",r,Cn.detailLineWidth,d),this.__circle(-i/4,-n/4+9,2,"none",r,Cn.detailLineWidth,d);break;case"filterBed":this.__box(0,0,i,n,o,r,a,d);for(let e=0;e<6;e++){const t=-i/2+12+e*(i-24)/5;this.__circle(t,n/6,2.5,"none",r,Cn.detailLineWidth,d),this.__circle(t,-n/6,2.5,"none",r,Cn.detailLineWidth,d)}break;case"disinfectionTank":this.__box(0,0,i,n,o,r,a,d);for(let e=1;e<=3;e++){const t=-i/2+e*i/4;this.__poly([t,n/2,t,-n/2+6],r,Cn.detailLineWidth,d)}break;case"sludgeThickener":{const e=Math.min(i,n)/2;this.__circle(0,0,e,o,r,a,d),this.__circle(0,0,e/5,"none",r,Cn.detailLineWidth,d),this.__poly([-e,0,-e/5,0],r,Cn.detailLineWidth,d),this.__poly([e/5,0,e,0],r,Cn.detailLineWidth,d);break}case"dewateringMachine":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/4,-n/6,i/4,-n/6],r,Cn.detailLineWidth,d),this.__poly([-i/4,0,i/4,0],r,Cn.detailLineWidth,d),this.__poly([-i/4,n/6,i/4,n/6],r,Cn.detailLineWidth,d);break;case"pump":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d),this.__closedPoly([0,.6*-e,.6*e,.5*e,.6*-e,.5*e],r,a,d);break}case"blower":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d);for(let t=0;t<3;t++){const i=2*Math.PI*t/3-Math.PI/2;this.__poly([0,0,.85*e*Math.cos(i),.85*e*Math.sin(i)],r,Cn.detailLineWidth,d)}break}case"dosingUnit":this.__box(0,-8,i,n-20,o,r,a,d),this.__closedPoly([0,n/2-16,8,n/2,-8,n/2],r,Cn.detailLineWidth,d),this.__circle(0,n/2-4,2,"none",r,Cn.detailLineWidth,d);break;case"valve":this.__closedPoly([-9,-8,-9,8,0,0],r,a,d),this.__closedPoly([9,-8,9,8,0,0],r,a,d),"closed"===this.state.valveState&&this.__poly([0,-10,0,10],"#dc2626",2,d);break;case"flowMeter":this.__circle(0,0,Math.min(i,n)/2,"none",r,a,d),this.__text(l-7,h-.7*Cn.letterFontSize,14,"F",Cn.letterFontSize,r,"center");break;case"analyzer":this.__circle(0,0,Math.min(i,n)/2,"none",r,a,d),this.__text(l-7,h-.7*Cn.letterFontSize,14,"A",Cn.letterFontSize,r,"center");break;case"storageTank":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/2+6,n/4,i/2-6,n/4],"#93c5fd",Cn.detailLineWidth,d),this.__poly([-i/4,-n/6,-i/8,-n/3,0,-n/6,i/8,-n/3,i/4,-n/6],r,Cn.detailLineWidth,d);break;case"deodorizer":this.__box(0,0,i,n,o,r,a,d);for(let e=0;e<2;e++)for(let t=0;t<4;t++)this.__circle(-i/4+t*(i/6),-n/8+e*(n/4),3,"none",r,Cn.detailLineWidth,d);this.__poly([-i/2,-n/2,-i/2,-n/4],r,a,d);break;case"sludgeSilo":this.__box(0,-n/8,i-20,.6*n,o,r,a,d),this.__poly([-i/2+10,.175*n,0,.42*n,i/2-10,.175*n],r,a,d),this.__poly([0,.42*n,0,n/2-2],r,a,d),this.__poly([-8,-n/8-.3*n,8,-n/8-.3*n],r,Cn.detailLineWidth,d);break;case"submersiblePump":{const e=Math.min(i,n)/2-3;this.__circle(0,-2,e,"none",r,a,d);for(let t=0;t<3;t++){const i=2*Math.PI*t/3-Math.PI/2;this.__poly([0,-2,.8*e*Math.cos(i),.8*e*Math.sin(i)-2],r,Cn.detailLineWidth,d)}this.__poly([-e,e+1,e,e+1],r,a,d);break}case"screwPump":this.__box(0,-3,i,n-14,o,r,a,d);for(let e=1;e<=4;e++){const t=-i/2+i/5*e;this.__poly([t-5,-n/2+5,t+5,n/2-11],r,Cn.detailLineWidth,d)}this.__poly([-i/3,n/2-4,i/3,n/2-4],r,a,d);break;case"vfd":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/4,4,-i/8,-5,0,4,i/8,-5,i/4,4],r,Cn.detailLineWidth,d);break;case"motorValve":this.__closedPoly([-9,8,-9,24,0,16],r,a,d),this.__closedPoly([9,8,9,24,0,16],r,a,d),this.__poly([0,8,0,2],r,Cn.detailLineWidth,d),this.__box(0,-6,22,16,"none",r,Cn.detailLineWidth,d),"closed"===this.state.valveState&&this.__poly([0,6,0,26],"#dc2626",2,d);break;case"checkValve":this.__box(0,0,i-6,n-14,"none",r,a,d),this.__closedPoly([-5,-6,6,0,-5,6],r,Cn.detailLineWidth,d),this.__poly([-i/2+3,0,i/2-3,0],r,Cn.detailLineWidth,d);break;case"levelGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d),this.__poly([.62*-e,6,.2*-e,0,.2*e,10,.62*e,4],r,Cn.detailLineWidth,d),this.__text(l-5,h-1,12,"L",Cn.tagFontSize,r,"center");break}case"pressureGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d),this.__poly([0,6,.5*e,.45*-e],r,Cn.detailLineWidth,d),this.__circle(0,6,2,r,r,Cn.detailLineWidth,d),this.__text(l-5,h-1,12,"P",Cn.tagFontSize,r,"center");break}case"inlet":this.__box(10,0,i-20,n-12,o,r,a,d),this.__closedPoly([-i/2+2,0,-i/2+18,-8,-i/2+18,8],r,a,d);break;case"outlet":this.__box(-10,0,i-20,n-12,o,r,a,d),this.__closedPoly([i/2-2,0,i/2-18,-8,i/2-18,8],r,a,d);break;case"sludgeOut":this.__box(0,0,i,n,o,r,a,d);for(let e=-1;e<=1;e++)this.__poly([10*e-5,n/4,10*e+5,-n/4],r,Cn.detailLineWidth,d);break;default:this.__box(0,0,i,n,o,r,a,d)}const c=Math.max(i+24,90),u=l-c/2;this.state.tag&&this.__text(u,-18,c,String(this.state.tag),Cn.tagFontSize,Cn.tagColor,"center");const p=String(this.state.name||"");p&&this.__text(u,n+14,c,p,Cn.nameFontSize,Cn.nameColor,"center")}__box(e,t,n,s,r,a,o,l){return this.__add("box",new i.ICERect({left:this.__originX+e-n/2,top:this.__originY+t-s/2,width:n,height:s,radius:3,zIndex:l,interactive:!1,linkable:!1,style:{fillStyle:r,strokeStyle:a,lineWidth:o}}))}__circle(e,t,n,s,r,a,o){return this.__add("circle:"+e+","+t,new i.ICECircle({left:this.__originX+e-n,top:this.__originY+t-n,radius:n,zIndex:o,interactive:!1,linkable:!1,style:{fillStyle:"none"===s?Cn.hollowFill:s,strokeStyle:r,lineWidth:a}}))}__closedPoly(e,t,i,n){const s=this.__poly(e,t,i,n),r=e[e.length-2],a=e[e.length-1];return this.__poly([r,a,e[0],e[1]],t,i,n),s}__poly(e,t,n,s){const r=[];for(let t=0;t<e.length;t+=2)r.push([e[t]+this.__originX,e[t+1]+this.__originY]);if(2===r.length&&(Math.abs(r[1][0]-r[0][0])<.01||Math.abs(r[1][1]-r[0][1])<.01)){const[e,a]=r[0],[o,l]=r[1],h=Math.abs(a-l)<.01,d=h?Math.min(e,o):Math.min(e,o)-n/2,c=h?Math.min(a,l)-n/2:Math.min(a,l),u=h?Math.abs(o-e):n,p=h?n:Math.abs(l-a);return this.__add("line:"+s+":"+d+","+c,new i.ICERect({left:d,top:c,width:u,height:p,zIndex:s,interactive:!1,linkable:!1,style:{fillStyle:t,strokeStyle:t,lineWidth:0}}))}return this.__add("poly:"+s+":"+r.length,new i.ICEPolyLine({points:r,zIndex:s,interactive:!1,linkable:!1,arrow:"none",lineType:"solid",style:{strokeStyle:t,lineWidth:n}}))}__text(e,t,n,s,r,a){let o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"center";const l=Math.round(1.4*r);return this.__add("text:"+s,new i.ICEText({left:e,top:t,width:n,height:l,text:s,stroke:!1,interactive:!1,linkable:!1,zIndex:(Number(this.state.zIndex)||0)+4,style:{fontSize:r,fillStyle:a,textAlign:o,textBaseline:"middle"}}))}__add(e,t){return this.addChild(t),this.parts.push({role:e,component:t}),t}__clearParts(){this.parts.forEach(e=>{e.component&&e.component.parentNode===this&&this.removeChild(e.component)}),this.parts=[]}}function dashPatternOf(e,t){const i=Math.max(1,t);return"dashed"===e?[4*i,4*i]:"dashdot"===e?[7*i,3*i,1.5*i,3*i]:[]}function composePipeLabel(e,t){const i=wn[e]||wn.sewage,n=String(t||"").trim();return n?`${n} ${i.label}`:i.label}class WaterPipe extends FlowEdge{static typeId="ice-entity-designer:WaterPipe";applyMediumStyle(){const e=this.state.medium||"sewage",t=wn[e]||wn.sewage,i=void 0===this.state.label||""===this.state.label?composePipeLabel(e,this.state.dn):this.state.label;this.setState({lineType:"solid"===t.lineType?"solid":"dashed",lineDash:dashPatternOf(t.lineType,Number((this.state.style||{}).lineWidth)||1.4),label:i,style:{...this.state.style||{},strokeStyle:t.color,fillStyle:t.color}})}setMedium(e,t){this.setState({medium:e,label:"",dn:void 0===t?this.state.dn:t}),this.applyMediumStyle()}}const Tn={inheritance:"<|--",realization:"<|..",association:"--\x3e",aggregation:"o--",composition:"*--",dependency:"..>"},En=[[/<\|\.\./,"realization"],[/<\|--/,"inheritance"],[/\*--/,"composition"],[/o--/,"aggregation"],[/\.\.>/,"dependency"],[/-->/,"association"]];function quoteIfNeeded(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)?e:`"${e}"`}function unquote(e){const t=e.trim();return/^".*"$/.test(t)?t.slice(1,-1).trim():t}exports.BpmnDesigner=class BpmnDesigner extends FlowDesigner{__markers=(()=>new Map)();__markerSyncing=!1;__nesting=!1;constructor(e){super(e),this.subscribe(()=>this.syncFlowMarkers()),this.syncFlowMarkers()}validateBpmn(){return validateBpmn(this)}createNode(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=super.createNode(e,t);return this.__nestByGeometry(i),i}__nestByGeometry(e){if(this.__nesting)return;if("bpmnPool"===e.state.kind)return void e.setState({zIndex:-3e4});"bpmnLane"===e.state.kind&&e.setState({zIndex:-2e4});const t=e.getMinBoundingBox(!0),i=(t.tl[0]+t.br[0])/2,n=(t.tl[1]+t.br[1])/2,s=this.nodes.filter(t=>t!==e&&("bpmnPool"===t.state.kind||"bpmnLane"===t.state.kind)).filter(e=>{const t=this.__contentBox(e);return i>=t.tl[0]&&i<=t.br[0]&&n>=t.tl[1]&&n<=t.br[1]}).sort((e,t)=>e.state.width*e.state.height-t.state.width*t.state.height)[0];if(s){this.__nesting=!0;try{const t=s.getMinBoundingBox(!0).tl[0],i=s.getMinBoundingBox(!0).tl[1];e.setState({left:e.state.left-t,top:e.state.top-i}),s.adoptChild(e)}finally{this.__nesting=!1}}}__contentBox(e){const t=e.getMinBoundingBox(!0),i=en[e.state.kind]||{},n=i.band,s=i.bandSize||0;return n&&s?{tl:"top"===n?[t.tl[0],t.tl[1]+s]:[t.tl[0]+s,t.tl[1]],br:t.br}:t}syncFlowMarkers(){if(!this.__markerSyncing){this.__markerSyncing=!0;try{const e=new Set;this.edges.forEach(t=>{if(!!("sequence"!==(t.state.flowType||"sequence")||!t.state.condition&&!t.state.isDefault))return;e.add(t.state.id);const i=t.state.points&&t.state.points.length?t.state.points:[t.state.startPoint,t.state.endPoint],n=i[0]||[0,0],s=i[1]||n,r=s[0]-n[0],a=s[1]-n[1],o=Math.max(Math.hypot(r,a),1),l=n[0]+r/o*16-7,h=n[1]+a/o*16-7,d=t.state.isDefault?"default":"conditional",c=t.state.style&&t.state.style.strokeStyle||"#475569";let u=this.__markers.get(t.state.id);u?(u.setState({left:l,top:h,markerType:d,style:{...u.state.style||{},strokeStyle:c}}),u.dirty=!0):(u=new BpmnFlowMarker({left:l,top:h,width:14,height:14,interactive:!1,draggable:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,markerType:d,style:{strokeStyle:c,fillStyle:"#ffffff",lineWidth:1.4}}),this.ice.addTool(u),this.__markers.set(t.state.id,u))}),[...this.__markers.keys()].forEach(t=>{if(!e.has(t)){const e=this.__markers.get(t);this.ice.removeTool(e),this.__markers.delete(t)}})}finally{this.__markerSyncing=!1}}}dispose(){this.__markers.forEach(e=>this.ice.removeTool(e)),this.__markers.clear(),super.dispose()}},exports.BpmnSimulator=class BpmnSimulator{tokens=[];visited=(()=>new Set)();running=!1;finished=!1;started=!1;nodeDurations=(()=>new Map)();nodeDuration=400;edgeDuration=600;seq=0;lastFrameAt=0;frameHandler=null;hostContinuousFrames=null;constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.designer=e,void 0!==t.nodeDuration&&(this.nodeDuration=t.nodeDuration),void 0!==t.edgeDuration&&(this.edgeDuration=t.edgeDuration)}setNodeDuration(e,t){this.nodeDurations.set(e,Math.max(0,Number(t)||0))}setEdgeDuration(e){this.edgeDuration=Math.max(1,Number(e)||600)}isRunning(){return this.running}isFinished(){return this.started&&0===this.tokens.length}getTokens(){return this.tokens}getVisitedNodeIds(){return[...this.visited]}start(){this.stop(),this.started=!0,this.finished=!1;const e=this.designer.nodes.filter(e=>"bpmnEvent"===e.state.kind&&"start"===(e.state.eventKind||"start"));e.forEach(e=>this.__spawn(e.state.id)),e.length||(this.finished=!0),this.running=!0,this.__acquireContinuousFrames(),this.frameHandler=()=>{const e=Date.now(),t=this.lastFrameAt?Math.min(100,e-this.lastFrameAt):16;this.lastFrameAt=e,this.step(t)},this.designer.ice&&this.designer.ice.evtBus&&this.designer.ice.evtBus.on("ICE_FRAME_EVENT",this.frameHandler,this)}stop(){this.frameHandler&&this.designer.ice&&this.designer.ice.evtBus&&this.designer.ice.evtBus.off("ICE_FRAME_EVENT",this.frameHandler,this),this.frameHandler=null,this.__releaseContinuousFrames(),this.tokens.forEach(e=>this.__removeComponent(e)),this.tokens=[],this.running=!1,this.lastFrameAt=0}__acquireContinuousFrames(){const e=this.designer&&this.designer.ice;e&&"function"==typeof e.setContinuousFrames&&(null===this.hostContinuousFrames&&(this.hostContinuousFrames="function"==typeof e.isContinuousFrames&&!!e.isContinuousFrames()),e.setContinuousFrames(!0))}__releaseContinuousFrames(){const e=this.designer&&this.designer.ice;e&&"function"==typeof e.setContinuousFrames&&null!==this.hostContinuousFrames&&(e.setContinuousFrames(this.hostContinuousFrames),this.hostContinuousFrames=null)}reset(){this.stop(),this.visited.clear(),this.started=!1,this.finished=!1}step(e){if(!this.tokens.length)return void(this.started&&(this.finished=!0,this.running=!1));const t=Math.max(0,Number(e)||0),i=[];this.tokens.forEach(e=>{if(e.edgeId)return e.progress+=t/this.edgeDuration,e.progress>=1&&this.__arriveAtNode(e,e.edgeId),this.__syncPosition(e),void(e.nodeId&&i.push(e));e.dwellRemaining-=t,e.dwellRemaining>0?i.push(e):this.__leaveNode(e,i)}),this.tokens=i,this.tokens.length||(this.finished=!0,this.running=!1)}__pickExclusive(e){const t=e.filter(e=>""!==String(e.state.condition||"").trim());if(t.length)return t[0];const i=e.filter(e=>!e.state.isDefault);return i.length?i[0]:e[0]}__spawn(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const n=this.designer.ice.findComponent(e),s={id:"sim-token-"+ ++this.seq,nodeId:e,edgeId:t,progress:i,position:this.__nodePosition(n),dwellRemaining:this.nodeDurations.get(e)||this.nodeDuration,component:null},r=new SimTokenDot({left:s.position[0]-7,top:s.position[1]-7,style:{fillStyle:"#f97316"}});return s.component=r,this.designer.ice.addTool(r),this.visited.add(e),this.tokens.push(s),t&&this.__syncPosition(s),s}__arriveAtNode(e,t){const i=this.designer.ice.findComponent(t),n=i&&i.state.links||{},s=n.end&&n.end.id,r=s?this.designer.ice.findComponent(s):null;e.edgeId=null,e.progress=0,e.nodeId=s,e.position=this.__nodePosition(r),e.dwellRemaining=this.nodeDurations.get(s)||this.nodeDuration,this.visited.add(s);r&&"bpmnEvent"===r.state.kind&&("end"===(r.state.eventKind||"start")||"terminate"===r.state.trigger)&&(e.nodeId="",this.__removeComponent(e)),this.__syncPosition(e)}__leaveNode(e,t){const i=this.designer.ice.findComponent(e.nodeId),n=this.designer.edges.filter(t=>{const i=t.state.links||{};return i.start&&i.start.id===e.nodeId&&"sequence"===(t.state.flowType||"sequence")});if(!i||!n.length)return e.nodeId="",void this.__removeComponent(e);("bpmnGateway"===i.state.kind&&"exclusive"!==i.state.gatewayType?n:[this.__pickExclusive(n)]).forEach((i,n)=>{if(0===n)return e.edgeId=i.state.id,e.progress=0,e.dwellRemaining=0,void t.push(e);const s=this.__spawn(e.nodeId,i.state.id,0);s.dwellRemaining=0,t.push(s)})}__syncPosition(e){if(e.edgeId){const t=this.designer.ice.findComponent(e.edgeId),i=t&&t.state.points||[];e.position=function pointAt(e,t){if(!e||0===e.length)return[0,0];if(1===e.length)return[...e[0]];const i=[];let n=0;for(let t=1;t<e.length;t++){const s=Math.hypot(e[t][0]-e[t-1][0],e[t][1]-e[t-1][1]);i.push(s),n+=s}if(n<=0)return[...e[0]];let s=Math.max(0,Math.min(1,t))*n;for(let t=0;t<i.length;t++){if(s<=i[t]||t===i.length-1){const n=i[t]>0?s/i[t]:0,r=e[t],a=e[t+1];return[r[0]+(a[0]-r[0])*n,r[1]+(a[1]-r[1])*n]}s-=i[t]}return[...e[e.length-1]]}(i,e.progress)}if(e.component){const t=e.component.state.radius||7;e.component.setPosition(e.position[0]-t,e.position[1]-t)}}__nodePosition(e){if(!e)return[0,0];const t=e.getMinBoundingBox(!0);return[t.center[0],t.center[1]]}__removeComponent(e){e.component&&this.designer.ice&&(this.designer.ice.removeTool(e.component),e.component=null)}},exports.DESIGNER_CHROME=Ai,exports.DESIGNER_CHROME_ANTD=zi,exports.Entity=Entity,exports.EntityDesigner=class EntityDesigner{selectedId=null;__changeListeners=[];__mousedownHandler=e=>this.__handleMouseDown(e);__undoStack=[];__redoStack=[];__historyEnabled=!0;__maxHistory=100;constructor(e){this.ice=e,applyDesignerChrome(this.ice),enableDesignerAlignmentGuides(this.ice),registerIEDType(this.ice,Entity),registerIEDType(this.ice,Relation),this.ice.evtBus.on("mousedown",this.__mousedownHandler,this)}get entities(){return this.ice.childNodes.filter(e=>isEntity(e))}get relations(){return this.ice.childNodes.filter(e=>isRelation(e))}get selected(){return this.selectedId?this.ice.findComponent(this.selectedId):null}select(e){return this.selectedId=e,this}createEntity(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.captureHistory();const t=this.entities.length,i=new Entity({left:120+t%4*220,top:120+260*Math.floor(t/4),entityName:"NewEntity",fields:[],...e});return this.ice.addChild(i),this.select(i.state.id),this.__emitChange(),i}createRelation(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.captureHistory();const t=e.sourceId||e.fromId||e.links&&e.links.start&&e.links.start.id,i=e.targetId||e.toId||e.links&&e.links.end&&e.links.end.id,n=t?this.ice.findComponent(t):null,s=i?this.ice.findComponent(i):null,r=autoPorts(n,s,{sourcePort:"R",targetPort:"L"}),a=e.links&&e.links.start&&e.links.start.position||e.startPosition||r.sourcePort,o=e.links&&e.links.end&&e.links.end.position||e.endPosition||r.targetPort,l=e.links||{start:{id:t,position:a},end:{id:i,position:o}},h=n?this.__slotPoint(n,a):null,d=s?this.__slotPoint(s,o):null,c=new Relation({relationType:e.relationType||"one-to-many",sourceField:e.sourceField||"id",targetField:e.targetField||"id",links:l,startPoint:h||[0,0],endPoint:d||[10,10],...e});return this.ice.addChild(c),this.select(c.state.id),this.__emitChange(),c}updateEntity(e,t){const i=this.ice.findComponent(e);return isEntity(i)&&(this.captureHistory(),i.setState(t),this.__emitChange()),i}updateRelation(e,t){const i=this.ice.findComponent(e);if(isRelation(i)){this.captureHistory();const e={...i.state,...t},n=Relation.buildLabel(e,e.relationType||"one-to-one");i.setState({...t,label:n}),this.__emitChange()}return i}removeComponent(e){const t=this.ice.findComponent(e);if(t){if(this.captureHistory(),isEntity(t)){this.relations.filter(t=>{const i=t.state.links||{};return i.start&&i.start.id===e||i.end&&i.end.id===e}).forEach(e=>this.ice.removeChild(e))}this.ice.removeChild(t),this.selectedId===e&&(this.selectedId=null),this.__emitChange()}}toSchemaObject(){return toSchemaObject(this.ice.childNodes)}toSchemaString(){return toSchemaString(this.ice.childNodes)}validate(){return validateSchema(this.ice.childNodes)}serializeProject(){const e={version:1,schemaVersion:1,createTime:i.toIsoTime(this.ice&&this.ice.documentMeta&&this.ice.documentMeta.createTime)||this.__rememberCreateTime(void 0),entities:this.entities.map(e=>this.__entitySnapshot(e)),relations:this.relations.map(e=>this.__relationSnapshot(e))};return JSON.stringify(e)}__rememberCreateTime(e){const t=this.ice;t&&"object"==typeof t&&(t.documentMeta&&"object"==typeof t.documentMeta||(t.documentMeta={}));const n=i.toIsoTime(e);if(n)return t&&t.documentMeta&&(t.documentMeta.createTime=n),n;const s=(new Date).toISOString();return t&&t.documentMeta&&(t.documentMeta.createTime=s),s}loadProject(e){if(!e)return{loaded:!1,entities:0,relations:0,unknownTypes:[],skipped:[]};const t=this.__parseProject(e);if(!t)return{loaded:!1,entities:0,relations:0,unknownTypes:[],skipped:[]};this.captureHistory();const i=this.__applySnapshot(t);return this.__emitChange(),i}__entitySnapshot(e){return pickDocumentNode({...e.state||{},typeId:Entity.typeId},Hi)}__slotPoint(e,t){const i=e.getMinBoundingBox(!0),n=i.center[0],s=i.center[1];switch(t){case"T":return[n,i.tl[1]];case"B":return[n,i.br[1]];case"L":return[i.tl[0],s];case"R":return[i.tr[0],s];default:return[n,s]}}__relationSnapshot(e){return pickDocumentNode({...e.state||{},typeId:Relation.typeId},Gi)}__parseProject(e){const t=JSON.parse(e);if(!t||!Array.isArray(t.entities))return null;if(void 0!==t.schemaVersion&&1!==t.schemaVersion)throw new Error(`Unsupported project schemaVersion: ${t.schemaVersion}`);const i=validateProjectSnapshot(t);if(!i.valid)throw new Error(`Invalid project snapshot:\n${i.errors.join("\n")}`);return t}__applyProject(e){const t=this.__parseProject(e);t&&this.__applySnapshot(t)}__resolveTypeId(e,t){return e&&"string"==typeof e.typeId&&e.typeId?e.typeId:"entities"===t?Entity.typeId:Relation.typeId}__resolveComponentClass(e){const t=this.ice;if("function"==typeof t.getType){const i=t.getType(e);if("function"==typeof i)return i}else if(t.typeMapping&&"function"==typeof t.typeMapping[e])return t.typeMapping[e];return e===Entity.typeId?Entity:e===Relation.typeId?Relation:null}__recordUnknownType(e,t,i,n,s){-1===e.unknownTypes.indexOf(n)&&e.unknownTypes.push(n);const r=s&&"string"==typeof s.id?s.id:void 0;e.skipped.push(void 0===r?{bucket:t,index:i,typeId:n}:{bucket:t,index:i,typeId:n,id:r})}__applySnapshot(e){const t=this.ice.renderer;t&&t.stop();const i={loaded:!0,entities:0,relations:0,unknownTypes:[],skipped:[]};try{this.ice.clearAll(),this.__rememberCreateTime(e&&e.createTime),this.ice.ctx&&"function"==typeof this.ice.ctx.clearRect&&(this.ice.ctx.setTransform(1,0,0,1,0,0),this.ice.ctx.clearRect(0,0,this.ice.canvasWidth||0,this.ice.canvasHeight||0));const createNode=(e,t,n)=>{const s=this.__resolveTypeId(e,t),r=this.__resolveComponentClass(s);if("function"!=typeof r)return this.__recordUnknownType(i,t,n,s,e),null;const a=new r(e);return delete a.state.typeId,delete a.props.typeId,this.ice.addChild(a),a},collect=(e,t,n)=>{const s=createNode(e,t,n);isEntity(s)?i.entities+=1:isRelation(s)&&(i.relations+=1)};e.entities.forEach((e,t)=>collect(e,"entities",t)),(e.relations||[]).forEach((e,t)=>collect(e,"relations",t)),this.selectedId=null}finally{if(t){const e=t.getRenderMode();t.setRenderMode("full"),t.start(),this.ice.dirty=!0,setTimeout(()=>{t.setRenderMode(e)},50)}}return i}__applyHistorySnapshot(e){this.__historyEnabled=!1;try{this.__applyProject(e),this.selectedId=null}finally{this.__historyEnabled=!0}}canUndo(){return this.__undoStack.length>0}canRedo(){return this.__redoStack.length>0}captureHistory(){this.__historyEnabled&&(this.__undoStack.push(this.serializeProject()),this.__undoStack.length>this.__maxHistory&&this.__undoStack.shift(),this.__redoStack.length=0)}undo(){if(!this.canUndo())return;const e=this.serializeProject(),t=this.__undoStack.pop();try{this.__applyHistorySnapshot(t)}catch(e){throw this.__undoStack.push(t),e}this.__redoStack.push(e),this.__emitChange()}redo(){if(!this.canRedo())return;const e=this.serializeProject(),t=this.__redoStack.pop();try{this.__applyHistorySnapshot(t)}catch(e){throw this.__redoStack.push(t),e}this.__undoStack.push(e),this.__emitChange()}subscribe(e){return"function"!=typeof e?()=>{}:(this.__changeListeners.push(e),()=>{const t=this.__changeListeners.indexOf(e);-1!==t&&this.__changeListeners.splice(t,1)})}__emitChange(){if(!this.__changeListeners.length)return;const e=this.serializeProject();this.__changeListeners.slice().forEach(t=>t(e))}dispose(){this.ice.evtBus.off("mousedown",this.__mousedownHandler,this)}__handleMouseDown(e){const t=e&&e.param&&e.param.component;if(!t)return;let i=t;for(;i.parentNode;)i=i.parentNode;(isEntity(i)||isRelation(i))&&this.select(i.state.id)}},exports.FLOW_NODE_KINDS=en,exports.FlowDesigner=FlowDesigner,exports.FlowDiamond=FlowDiamond,exports.FlowEdge=FlowEdge,exports.FlowNode=FlowNode,exports.FlowParallelogram=FlowParallelogram,exports.GanttDependency=GanttDependency,exports.GanttDesigner=class GanttDesigner extends FlowDesigner{labelColumnWidth=140;headerHeight=34;rowHeight=36;dayWidth=28;originDate="";ruler=null;__syncing=!1;constructor(e){super(e),registerIEDType(this.ice,GanttTask),registerIEDType(this.ice,GanttDependency),registerIEDType(this.ice,GanttRuler)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===GanttTask.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===GanttDependency.typeId)}createTask(e){this.__captureHistory();const t=new GanttTask({id:e.id,title:e.title||"任务",start:e.start,days:e.days||3,progress:e.progress||0,resource:e.resource||"",row:void 0===e.row?this.nodes.length:e.row,dayWidth:this.dayWidth,originDate:this.originDate||e.start,labelColumnWidth:this.labelColumnWidth,rowHeight:this.rowHeight,headerHeight:this.headerHeight});return this.ice.addChild(t),this.__attachNodeListeners(t),this.selectedId=t.state.id,this.syncChrome(),this.__emitChange(),t}createDependency(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("依赖两端必须是已存在的任务");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"R",targetPort:"L"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=this.__anchor(t,s),o=this.__anchor(i,r),l=new GanttDependency({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},points:[a,o],startPoint:a,endPoint:o});return this.ice.addChild(l),this.selectedId=l.state.id,this.__emitChange(),l}setDayWidth(e){this.dayWidth=Math.max(4,Math.round(Number(e)||0)||28),this.nodes.forEach(e=>{e.setState({dayWidth:this.dayWidth})}),this.syncChrome(),this.__emitChange()}updateTask(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.ice.findComponent(e);return i&&i.constructor.typeId===GanttTask.typeId?(this.__captureHistory(),i.applyPatch(t),this.syncChrome(),this.__emitChange(),i):null}autoSchedule(){if(this.validateGantt().some(e=>"error"===e.level&&e.message.includes("成环")))return;const e=this.nodes;if(!e.length)return;this.__captureHistory();const t=new Map;e.forEach(e=>t.set(e.state.id,e));const i=new Map;e.forEach(e=>i.set(e.state.id,[])),this.edges.forEach(e=>{const t=e.state.links||{},n=t.start&&t.start.id,s=t.end&&t.end.id;n&&s&&i.has(s)&&i.get(s).push(n)});const n=new Map,s=new Map;e.forEach(e=>{n.set(e.state.id,(i.get(e.state.id)||[]).length),s.set(e.state.id,[])}),i.forEach((e,t)=>{e.forEach(e=>s.get(e).push(t))});const r=e.filter(e=>0===(n.get(e.state.id)||0)).map(e=>e.state.id),a=[];for(;r.length;){const e=r.shift();a.push(e),(s.get(e)||[]).forEach(e=>{n.set(e,(n.get(e)||0)-1),0===(n.get(e)||0)&&r.push(e)})}a.forEach(e=>{const n=t.get(e),s=(i.get(e)||[]).reduce((e,i)=>{const n=t.get(i),s=addDays(n.state.start,Math.max(1,Number(n.state.days)||1));return diffDays(e,s)>0?s:e},n.state.start);diffDays(n.state.start,s)>0&&n.applyPatch({start:s})}),this.syncChrome(),this.__emitChange()}criticalPath(){const e=this.nodes;if(!e.length)return[];const t=new Map;e.forEach(e=>t.set(e.state.id,e));const i=new Map,n=new Map;e.forEach(e=>{i.set(e.state.id,[]),n.set(e.state.id,[])}),this.edges.forEach(e=>{const t=e.state.links||{},s=t.start&&t.start.id,r=t.end&&t.end.id;s&&r&&i.has(r)&&i.has(s)&&(i.get(r).push(s),n.get(s).push(r))});const durationOf=e=>Math.max(1,Number(e.state.days)||1),s=[],r=new Map;e.forEach(e=>r.set(e.state.id,(i.get(e.state.id)||[]).length));const a=e.filter(e=>0===(r.get(e.state.id)||0)).map(e=>e.state.id);for(;a.length;){const e=a.shift();s.push(e),(n.get(e)||[]).forEach(e=>{r.set(e,(r.get(e)||0)-1),0===(r.get(e)||0)&&a.push(e)})}if(s.length!==e.length)return[];const o=new Map;s.forEach(e=>{const n=t.get(e),s=i.get(e)||[];let r=s.length?"":n.state.start;s.forEach(e=>{const i=t.get(e),n=addDays(o.get(e),durationOf(i));(!r||diffDays(r,n)>0)&&(r=n)}),o.set(e,r)});let l="";e.forEach(e=>{const t=addDays(o.get(e.state.id),durationOf(e));(!l||diffDays(l,t)>0)&&(l=t)});const h=new Map;return[...s].reverse().forEach(e=>{const i=t.get(e),s=n.get(e)||[];if(!s.length)return void h.set(e,addDays(l,-durationOf(i)));const r=s.reduce((e,t)=>{const i=h.get(t);return!e||diffDays(i,e)>0?i:e},null);h.set(e,addDays(r,-durationOf(i)))}),e.filter(e=>{const t=h.get(e.state.id);return 0===diffDays(o.get(e.state.id),t)})}computeOrigin(){const e=this.nodes.map(e=>e.state.start).filter(e=>!!e);return e.length?e.reduce((e,t)=>diffDays(e,t)<0?t:e):this.originDate||""}dayCount(){const e=this.nodes;if(!e.length)return 14;let t=this.originDate||e[0].state.start;return e.forEach(e=>{const i=addDays(e.state.start,Math.max(1,Number(e.state.days)||1));diffDays(t,i)>0&&(t=i)}),Math.max(1,diffDays(this.originDate,t)+1)}syncChrome(){if(!this.__syncing){this.__syncing=!0;try{this.originDate=this.computeOrigin();const e=this.nodes;this.ruler||(this.ruler=new GanttRuler,this.ice.addChild(this.ruler)),this.ruler.setState({zIndex:-1e4}),e.forEach((e,t)=>{const i={dayWidth:this.dayWidth,originDate:this.originDate,labelColumnWidth:this.labelColumnWidth,rowHeight:this.rowHeight,headerHeight:this.headerHeight};void 0!==e.state.row&&null!==e.state.row||(i.row=t),e.setState(i)}),this.ruler.sync({dayWidth:this.dayWidth,labelColumnWidth:this.labelColumnWidth,headerHeight:this.headerHeight,rowHeight:this.rowHeight,originDate:this.originDate,dayCount:this.dayCount(),tasks:e.map(e=>({title:e.state.title,row:Number(e.state.row)||0})),totalWidth:0,totalHeight:0}),this.ice.renderer&&this.ice.renderer.markQueueDirty()}finally{this.__syncing=!1}}}validateGantt(){const e=[],t=this.nodes,i=new Map;t.forEach(e=>{const t=String(e.state.resource||"").trim();t&&(i.has(t)||i.set(t,[]),i.get(t).push(e))}),i.forEach((t,i)=>{for(let n=0;n<t.length;n++)for(let s=n+1;s<t.length;s++){const r=t[n],a=t[s],o=addDays(r.state.start,Math.max(1,Number(r.state.days)||1)),l=addDays(a.state.start,Math.max(1,Number(a.state.days)||1));diffDays(r.state.start,l)>0&&diffDays(a.state.start,o)>0&&e.push({level:"warning",message:`资源冲突:「${i}」同时被「${r.state.title}」与「${a.state.title}」占用`,id:a.state.id})}}),t.forEach(t=>{const i=Number(t.state.progress);i>=0&&i<=1||e.push({level:"error",message:`任务「${t.state.title}」的进度必须在 0~1 之间`,id:t.state.id}),Number(t.state.days)>=1||e.push({level:"error",message:`任务「${t.state.title}」的持续天数必须 ≥ 1`,id:t.state.id})});const n=new Set(t.map(e=>e.state.id)),s=new Map;t.forEach(e=>s.set(e.state.id,[])),this.edges.forEach(t=>{const i=t.state.links||{},r=i.start&&i.start.id,a=i.end&&i.end.id;r&&a&&n.has(r)&&n.has(a)?s.get(r).push(a):e.push({level:"error",message:"依赖两端必须都是已存在的任务",id:t.state.id})});const r=new Map,a=[],visit=i=>{r.set(i,1),a.push(i);for(const n of s.get(i)||[]){const s=r.get(n)||0;if(1===s){const s=a.indexOf(n),o=a.slice(s>=0?s:0).concat(n).map(e=>{const i=t.find(t=>t.state.id===e);return i&&i.state.title||e});return e.push({level:"error",message:`依赖成环:${o.join(" → ")}`,id:i}),r.set(i,2),a.pop(),!0}if(0===s&&visit(n))return r.set(i,2),a.pop(),!0}return r.set(i,2),a.pop(),!1};return t.forEach(e=>{0===(r.get(e.state.id)||0)&&visit(e.state.id)}),e}__anchor(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}contentComponents(){return this.ruler?this.nodes.concat([this.ruler]):this.nodes}fitViewportAlign="start"},exports.GanttRuler=GanttRuler,exports.GanttTask=GanttTask,exports.POWER_STYLE=_n,exports.POWER_SYMBOL_KINDS=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"],exports.POWER_SYMBOL_PRESETS=yn,exports.POWER_VOLTAGE_LEVELS=gn,exports.PROJECT_SCHEMA_VERSION=1,exports.PowerDesigner=class PowerDesigner extends FlowDesigner{voltageColors=(()=>defaultVoltageColors())();constructor(e){super(e),registerIEDType(this.ice,PowerSymbol),registerIEDType(this.ice,PowerLine)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===PowerSymbol.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===PowerLine.typeId)}setVoltageColors(e){this.voltageColors={...this.voltageColors,...e||{}},this.nodes.forEach(e=>e.applyPatch({voltageColors:this.voltageColors})),this.edges.forEach(e=>e.applyVoltageColor(this.voltageColors)),this.ice.dirty=!0}createSymbol(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new PowerSymbol({kind:e,voltageColors:this.voltageColors,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}createLine(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("导体两端必须是已存在的设备");this.__captureHistory();const n=e.sourcePort||"B",s=e.targetPort||"T",r=new PowerLine({id:e.id,links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,n),endPoint:this.__slotPoint(i,s),voltageLevel:e.voltageLevel||t.state.voltageLevel||i.state.voltageLevel||"",arrow:"none",linkShape:"visio"});return r.applyVoltageColor(this.voltageColors),this.ice.addChild(r),this.selectedId=r.state.id,this.__emitChange(),r}setSwitchState(e,t){const i=this.__symbolById(e);if(!i)return null;if(-1===bn.indexOf(i.state.kind))throw new Error("只有断路器 / 隔离开关 / 负荷开关 / 接地开关才有分合状态");return this.__captureHistory(),i.applyPatch({switchState:t}),this.applyTopology(),this.__emitChange(),i}setEnergizedSource(e,t){const i=this.__symbolById(e);return i?(this.__captureHistory(),i.setState({energizedSource:!!t}),this.applyTopology(),this.__emitChange(),i):null}applyTopology(){const e=this.topology(),t=new Set(e.energized);return this.nodes.forEach(e=>{const i=t.has(e.state.id);e.state.energized!==i&&e.setState({energized:i})}),this.ice.dirty=!0,e}topology(){const e=this.nodes,t=new Map;e.forEach(e=>t.set(e.state.id,e));const i=this.__buildAdjacency(),isClosed=e=>{const i=t.get(e);return!i||-1===bn.indexOf(i.state.kind)||"closed"===i.state.switchState},n=new Set,s=[];for(e.filter(e=>e.state.energizedSource).forEach(e=>{n.add(e.state.id),s.push(e.state.id)});s.length;){const e=s.shift();(i.get(e)||[]).forEach(i=>{n.has(i)||(-1===bn.indexOf((t.get(i)||{state:{}}).state.kind)||isClosed(i)?(isClosed(e)||e===i)&&(n.add(i),s.push(i)):n.add(i))})}const r=new Set,a=[];return e.forEach(e=>{if(r.has(e.state.id))return;const t=[],n=[e.state.id];for(r.add(e.state.id);n.length;){const e=n.pop();t.push(e),(i.get(e)||[]).forEach(e=>{r.has(e)||(r.add(e),n.push(e))})}a.push(t)}),{energized:Array.from(n),islands:a}}validatePower(){const e=[],t=this.nodes,i=new Map;t.forEach(e=>i.set(e.state.id,e));const n=new Map;t.forEach(t=>{const i=String(t.state.name||"").trim();i&&(n.has(i)?e.push({level:"error",message:`设备编号重复:「${i}」(同一张图上编号必须唯一)`,id:t.state.id}):n.set(i,t))});const s=this.__buildAdjacency();this.edges.forEach(t=>{const n=t.state.links||{},s=i.get(n.start&&n.start.id),r=i.get(n.end&&n.end.id);if(!s||!r)return;const a=String(s.state.voltageLevel||""),o=String(r.state.voltageLevel||"");"transformer"!==s.state.kind&&"transformer"!==r.state.kind&&a&&o&&a!==o&&e.push({level:"error",message:`电压等级不一致:${s.state.name||s.state.kind}(${a}) 与 ${r.state.name||r.state.kind}(${o}) 直接相连,中间没有变压器`,id:t.state.id})});const r=this.topology(),a=t.filter(e=>e.state.energizedSource).map(e=>e.state.id);t.filter(e=>"busbar"===e.state.kind).forEach(t=>{(r.islands.find(e=>-1!==e.indexOf(t.state.id))||[]).some(e=>-1!==a.indexOf(e))||e.push({level:"warning",message:`母线「${t.state.name||"未命名"}」没有进线电源(该连通域里没有电源点)`,id:t.state.id})});t.filter(e=>"breaker"===e.state.kind).filter(e=>function kilovoltsOf(e){const t=/(\d+(?:\.\d+)?)/.exec(String(e||""));return t?Number(t[1]):0}(e.state.voltageLevel)>=110).forEach(t=>{(s.get(t.state.id)||[]).filter(e=>((e,t)=>{const n=new Set([e]);let r=[t];for(let e=0;e<3&&r.length;e+=1){const e=[];for(const t of r){if(n.has(t))continue;n.add(t);const r=i.get(t);if(!r)continue;const a=r.state.kind;if("disconnector"===a)return!0;-1===bn.indexOf(a)&&"busbar"!==a&&(s.get(t)||[]).forEach(t=>e.push(t))}r=e}return!1})(t.state.id,e)).length<2&&e.push({level:"warning",message:`断路器「${t.state.name||"未命名"}」两侧隔离开关不足(检修时需要可见断口)`,id:t.state.id})}),t.forEach(t=>{const i=this.attachedBusOf(t);if(!i)return;const n=String(t.state.voltageLevel||""),s=String(i.state.voltageLevel||"");n&&s&&n!==s&&e.push({level:"error",message:`电压等级不一致:设备「${t.state.name||t.state.kind}」(${n}) 挂到了母线「${i.state.name||"未命名"}」(${s}) 上`,id:t.state.id})});const o=new Set(r.energized);return t.filter(e=>"earthingSwitch"===e.state.kind).forEach(t=>{if(!("closed"===t.state.switchState))return;(s.get(t.state.id)||[]).filter(e=>o.has(e)).length&&e.push({level:"error",message:`带电合接地刀闸:接地开关「${t.state.name||"未命名"}」在合位,且该点带电(五防:禁止带电挂接地线)`,id:t.state.id})}),t.forEach(t=>{const i=this.attachedBusOf(t);i&&!this.isAttachedToBus(t)&&e.push({level:"warning",message:`设备「${t.state.name||t.state.kind}」挂在母线「${i.state.name||"未命名"}」上但已经拖离,需要重新贴合或补一段导体`,id:t.state.id})}),t.forEach(t=>{0===(s.get(t.state.id)||[]).length&&e.push({level:"warning",message:`设备「${t.state.name||t.state.kind}」没有任何连接(孤立设备)`,id:t.state.id})}),e}attachToBus(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n="string"==typeof e?this.__symbolById(e):e,s="string"==typeof t?this.__symbolById(t):t;if(!n||!s)throw new Error("attachToBus:设备与母线都必须已存在");if("busbar"!==s.state.kind)throw new Error("attachToBus:第二个参数必须是母线(busbar)");if(n===s)throw new Error("attachToBus:母线不能挂到自己身上");const r=this.attachedBusOf(n);if(r&&r!==s)throw new Error("attachToBus:设备已经挂在另一条母线上,请先断开");this.__captureHistory();const a=s.getMinBoundingBox(!0),o=n.getMinBoundingBox(!0).tc[0],l=Math.min(Math.max(void 0===i.centerX?o:i.centerX,a.tl[0]+24),a.br[0]-24);return n.setState({attachedBusId:s.state.id,left:l-n.state.width/2,top:(a.tl[1]+a.br[1])/2+3}),this.__watchBusMove(s),this.applyTopology(),this.__emitChange(),n}attachedBusOf(e){const t=e&&e.state&&e.state.attachedBusId;return t?this.__symbolById(t):null}isAttachedToBus(e){const t=this.attachedBusOf(e);if(!t)return!1;const i=t.getMinBoundingBox(!0),n=e.getMinBoundingBox(!0),s=(i.tl[1]+i.br[1])/2+3,r=Math.abs(n.tl[1]-s)<=8,a=n.tc[0]>=i.tl[0]&&n.tc[0]<=i.br[0];return r&&a}detachFromBus(e){const t="string"==typeof e?this.__symbolById(e):e;return t?(this.__captureHistory(),t.setState({attachedBusId:""}),this.applyTopology(),this.__emitChange(),t):null}__watchBusMove(e){e&&!e.__powerBusWatched&&(e.__powerBusWatched=!0,e.on("AFTER_MOVE",()=>{const t=this.nodes.filter(t=>t.state.attachedBusId===e.state.id);if(!t.length)return;const i=e.getMinBoundingBox(!0),n=e.__powerBusLastBox||i,s=i.tl[0]-n.tl[0],r=i.tl[1]-n.tl[1];e.__powerBusLastBox=i,(s||r)&&t.forEach(e=>{e.getMinBoundingBox&&e.setState({left:e.state.left+s,top:e.state.top+r})})},this),e.__powerBusLastBox=e.getMinBoundingBox(!0))}__buildAdjacency(){const e=new Map;this.nodes.forEach(t=>e.set(t.state.id,[]));const link=(t,i)=>{e.has(t)&&e.has(i)&&(e.get(t).push(i),e.get(i).push(t))};return this.edges.forEach(e=>{const t=e.state.links||{},i=t.start&&t.start.id,n=t.end&&t.end.id;i&&n&&link(i,n)}),this.nodes.forEach(e=>{const t=this.attachedBusOf(e);t&&this.isAttachedToBus(e)&&link(t.state.id,e.state.id)}),e}__symbolById(e){return this.nodes.find(t=>t.state.id===e)||null}},exports.PowerLine=PowerLine,exports.PowerSymbol=PowerSymbol,exports.Relation=Relation,exports.SECONDARY_STYLE=kn,exports.SECONDARY_SYMBOL_KINDS=["contactNO","contactNC","pushButton","switchRemoteLocal","linkPlate","indicatorLamp","relayDevice","ctWinding","terminal","earth"],exports.SECONDARY_SYMBOL_PRESETS=vn,exports.STATECHART_NODE_KINDS=["initial","final","state","composite"],exports.SecondaryDesigner=class SecondaryDesigner extends FlowDesigner{constructor(e){super(e),registerIEDType(this.ice,SecondarySymbol),registerIEDType(this.ice,SecondaryWire),registerIEDType(this.ice,TerminalStrip)}get nodes(){return this.__flatten().filter(e=>e.constructor&&(e.constructor.typeId===SecondarySymbol.typeId||e.constructor.typeId===TerminalStrip.typeId))}get symbols(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===SecondarySymbol.typeId)}get terminals(){return this.symbols.filter(e=>"terminal"===e.state.kind)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===SecondaryWire.typeId)}createSymbol(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new SecondarySymbol({kind:e,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}createWire(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=normalizeLabelStyle(e);const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("二次导线两端必须是已存在的元件");this.__captureHistory();const n=e.sourcePort||"B",s=e.targetPort||"T",r=new SecondaryWire({id:e.id,links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,n),endPoint:this.__slotPoint(i,s),label:e.circuitNo||"",circuitNo:e.circuitNo||"",cableNo:e.cableNo||"",style:{strokeStyle:"#475569",fillStyle:"#475569",lineWidth:1.4,...e.style||{},label:{fontSize:11,fillStyle:"#1f2937",backgroundColor:"#ffffff",...(e.style||{}).label||{}}}});return this.ice.addChild(r),this.selectedId=r.state.id,this.__emitChange(),r}createTerminalStrip(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.terminals||[],i=new TerminalStrip({title:e.title||"端子排",left:void 0===e.left?40:e.left,top:void 0===e.top?40:e.top,width:e.width||96,height:Math.max(34*(t.length+1),120)});this.ice.addChild(i);const n=[];return t.forEach((e,t)=>{const s=new SecondarySymbol({kind:"terminal",name:e.no,tag:e.tag||"",left:(i.state.width-28)/2,top:24+34*t});i.addChild(s),this.__attachNodeListeners(s),n.push(s)}),this.selectedId=i.state.id,this.__emitChange(),{strip:i,terminals:n}}validateSecondary(){const e=[];this.edges.forEach(t=>{String(t.state.circuitNo||t.state.label||"").trim()||e.push({level:"error",message:"二次导线缺少回路编号(等电位编号是二次图的读图依据)",id:t.state.id})});const t=new Map;this.edges.forEach(e=>{const i=String(e.state.circuitNo||e.state.label||"").trim(),n=/^([ABC])(\d+)$/.exec(i);if(!n)return;const s=t.get(n[2])||new Set;s.add(n[1]),t.set(n[2],s)}),t.forEach((t,i)=>{["A","B","C"].forEach(n=>{t.has(n)||e.push({level:"error",message:`电流回路编号缺相:${n}${i} 没有对应的回路(三相电流回路必须成组)`})})});const i=new Map;return this.terminals.forEach(t=>{const n=String(t.state.name||"").trim();n&&(i.has(n)?e.push({level:"error",message:`端子号重复:「${n}」在端子排上不唯一`,id:t.state.id}):i.set(n,t))}),this.symbols.some(e=>"earth"===e.state.kind)||e.push({level:"warning",message:"二次回路没有接地:电流回路的 N 侧应接地"}),e}presetOf(e){return vn[e]}},exports.SecondarySymbol=SecondarySymbol,exports.SecondaryWire=SecondaryWire,exports.StateNode=StateNode,exports.StateTransition=StateTransition,exports.StatechartDesigner=class StatechartDesigner extends FlowDesigner{__nesting=!1;constructor(e){super(e),registerIEDType(this.ice,StateNode),registerIEDType(this.ice,StateTransition)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===StateNode.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===StateTransition.typeId)}createState(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.__captureHistory();const t=new StateNode(e);if(void 0===e.left||void 0===e.top){const i=this.__defaultPlacement(t.state.width,t.state.height);t.setState({left:void 0===e.left?i.left:e.left,top:void 0===e.top?i.top:e.top})}return this.ice.addChild(t),this.__attachNodeListeners(t),this.__nestByGeometry(t),this.selectedId=t.state.id,this.__emitChange(),t}createTransition(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("转移两端必须是已存在的状态");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"R",targetPort:"L"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=new StateTransition({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},startPoint:this.__portPoint(t,s),endPoint:this.__portPoint(i,r),event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label,linkShape:e.linkShape||"visio",style:{...e.style||{},...e.labelStyle?{label:e.labelStyle}:{}}});return this.ice.addChild(a),this.selectedId=a.state.id,this.__emitChange(),a}__nestByGeometry(e){if(this.__nesting||e.constructor.typeId!==StateNode.typeId||"composite"===e.state.kind)return;const t=e.getMinBoundingBox(!0),i=(t.tl[0]+t.br[0])/2,n=(t.tl[1]+t.br[1])/2,s=this.nodes.filter(t=>t!==e&&"composite"===t.state.kind).filter(e=>{const t=e.getMinBoundingBox(!0);return i>=t.tl[0]&&i<=t.br[0]&&n>=t.tl[1]&&n<=t.br[1]}).sort((e,t)=>e.state.width*e.state.height-t.state.width*t.state.height)[0];if(s){this.__nesting=!0;try{const t=s.getMinBoundingBox(!0).tl[0],i=s.getMinBoundingBox(!0).tl[1];e.setState({left:e.state.left-t,top:e.state.top-i}),s.adoptChild(e)}finally{this.__nesting=!1}}}validateStatechart(){const e=[],t=this.nodes,i=t.filter(e=>"initial"===e.state.kind);t.length&&0===i.length&&e.push({level:"error",message:"缺少初始状态(initial):状态机没有入口"});const n=new Map,s=new Map;t.forEach(e=>{n.set(e.state.id,[]),s.set(e.state.id,0)}),this.edges.forEach(t=>{const i=t.state.links||{},r=i.start&&i.start.id,a=i.end&&i.end.id;r&&a&&n.has(r)&&n.has(a)?(n.get(r).push(a),s.set(a,(s.get(a)||0)+1)):e.push({level:"error",message:"转移两端必须都是已存在的状态",id:t.state.id})}),t.forEach(t=>{"final"===t.state.kind&&(n.get(t.state.id)||[]).length>0&&e.push({level:"error",message:"终止状态不应有出边",id:t.state.id})});const r=new Set,a=i.map(e=>e.state.id);for(a.forEach(e=>r.add(e));a.length;){const e=a.shift();(n.get(e)||[]).forEach(e=>{r.has(e)||(r.add(e),a.push(e))})}return t.forEach(t=>{if(r.has(t.state.id))return;const i=(e=>{const t=[],walk=e=>{(e||[]).forEach(e=>{e.constructor&&e.constructor.typeId===StateNode.typeId&&t.push(e),walk(e.childNodes)})};return walk(e.childNodes),t})(t);if(i.some(e=>r.has(e.state.id)))return;const a=0===(s.get(t.state.id)||0)&&0===(n.get(t.state.id)||[]).length;if(a&&i.length)return;const o=t.state.title||t.state.kind;e.push({level:"warning",message:a?`状态「${o}」没有任何转移(孤立节点)`:`状态「${o}」从初始状态不可达`,id:t.state.id})}),e}__portPoint(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}},exports.TerminalStrip=TerminalStrip,exports.UML_RELATION_KINDS=an,exports.UML_RELATION_STYLE=on,exports.UmlClass=UmlClass,exports.UmlDesigner=class UmlDesigner extends FlowDesigner{constructor(e){super(e),registerIEDType(this.ice,UmlClass),registerIEDType(this.ice,UmlRelation)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===UmlClass.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===UmlRelation.typeId)}createClass(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.__captureHistory();const t=new UmlClass(e);if(void 0===e.left||void 0===e.top){const i=this.__defaultPlacement(t.state.width,t.state.height);t.setState({left:void 0===e.left?i.left:e.left,top:void 0===e.top?i.top:e.top})}return this.ice.addChild(t),this.__attachNodeListeners(t),this.selectedId=t.state.id,this.__emitChange(),t}createRelation(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("关系两端必须是已存在的类");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"R",targetPort:"L"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=new UmlRelation({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},startPoint:this.__portPoint(t,s),endPoint:this.__portPoint(i,r),relationKind:e.relationKind||"association",label:e.label||"",linkShape:e.linkShape||"visio",style:{...e.style||{},...e.labelStyle?{label:e.labelStyle}:{}}});return this.ice.addChild(a),this.selectedId=a.state.id,this.__emitChange(),a}setRelationKind(e,t){const i=this.ice.findComponent(e);return i&&i.constructor.typeId===UmlRelation.typeId&&(this.__captureHistory(),i.applyPatch({relationKind:t}),this.__emitChange()),i}get relationKinds(){return[...an]}validateUml(){const e=[],t=this.nodes,i=new Map;t.forEach(t=>{const n=String(t.state.className||"").trim();n?(i.has(n)||i.set(n,[]),i.get(n).push(t)):e.push({level:"error",message:"存在未命名的类",id:t.state.id})}),i.forEach((t,i)=>{t.length>1&&e.push({level:"error",message:`类名重复:${i}(${t.length} 个)`,id:t[0].state.id})});const n=new Set(t.map(e=>e.state.id)),s=new Map;this.edges.forEach(t=>{const i=t.state.links||{},r=i.start&&i.start.id,a=i.end&&i.end.id;r&&a&&n.has(r)&&n.has(a)?"inheritance"!==t.state.relationKind&&"realization"!==t.state.relationKind||(s.has(r)||s.set(r,[]),s.get(r).push(a)):e.push({level:"error",message:"关系两端必须都是已存在的类",id:t.state.id})});const r=new Map,a=[],visit=i=>{r.set(i,1),a.push(i);for(const n of s.get(i)||[]){const s=r.get(n)||0;if(1===s){const s=a.indexOf(n),o=a.slice(s>=0?s:0).concat(n).map(e=>{const i=t.find(t=>t.state.id===e);return i?i.state.className:e});return e.push({level:"error",message:`继承关系成环:${o.join(" → ")}`,id:i}),r.set(i,2),a.pop(),!0}if(0===s&&visit(n))return r.set(i,2),a.pop(),!0}return r.set(i,2),a.pop(),!1};return t.forEach(e=>{0===(r.get(e.state.id)||0)&&visit(e.state.id)}),e}static describeRelationKind(e){const t=on[e];if(!t)return"";return`${t.dashed?"虚线":"实线"} + ${"triangle"===t.marker?"空心三角":"diamond"===t.marker?t.filled?"实心菱形":"空心菱形":"open"===t.marker?"开放箭头":"无端点标记"}`}__portPoint(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}},exports.UmlRelation=UmlRelation,exports.WATER_BOUNDARY_KINDS=["inlet","outlet","sludgeOut"],exports.WATER_EQUIPMENT_KINDS=["pump","submersiblePump","screwPump","blower","vfd","dosingUnit","valve","motorValve","checkValve","flowMeter","levelGauge","pressureGauge","analyzer"],exports.WATER_MEDIUM_STYLES=wn,exports.WATER_SLUDGE_KINDS=xn,exports.WATER_STYLE=Cn,exports.WATER_SYMBOL_KINDS=["barScreen","gritChamber","primaryClarifier","anaerobicTank","anoxicTank","aerobicTank","secondaryClarifier","coagulationTank","filterBed","disinfectionTank","storageTank","deodorizer","sludgeThickener","dewateringMachine","sludgeSilo","pump","submersiblePump","screwPump","blower","vfd","dosingUnit","valve","motorValve","checkValve","flowMeter","levelGauge","pressureGauge","analyzer","inlet","outlet","sludgeOut"],exports.WATER_SYMBOL_PRESETS=Sn,exports.WATER_UNIT_KINDS=["barScreen","gritChamber","primaryClarifier","anaerobicTank","anoxicTank","aerobicTank","secondaryClarifier","coagulationTank","filterBed","disinfectionTank","sludgeThickener","dewateringMachine","sludgeSilo","storageTank","deodorizer"],exports.WATER_VALVE_KINDS=In,exports.WaterPipe=WaterPipe,exports.WaterProcessDesigner=class WaterProcessDesigner extends FlowDesigner{constructor(e){super(e),registerIEDType(this.ice,WaterSymbol),registerIEDType(this.ice,WaterPipe)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===WaterSymbol.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===WaterPipe.typeId)}createSymbol(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new WaterSymbol({kind:e,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}createPipe(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("管线两端必须是已存在的符号");this.__captureHistory();const n=e.sourcePort||"B",s=e.targetPort||"T",r=new WaterPipe({id:e.id,links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,n),endPoint:this.__slotPoint(i,s),medium:e.medium||"sewage",dn:e.dn||"",label:e.label,arrow:e.arrow||"end",linkShape:e.linkShape||"visio"});return void 0===e.label&&r.applyMediumStyle(),this.ice.addChild(r),this.selectedId=r.state.id,this.__emitChange(),r}setValveState(e,t){const i=this.__symbolById(e);if(!i)throw new Error("找不到该符号:"+e);if(!isWaterValveKind(i.state.kind))throw new Error("只有阀门(手动阀 / 电动阀)能改开 / 闭状态");return i.applyPatch({valveState:t}),this.ice.dirty=!0,i}traceFlow(e){const t=e?[e]:this.nodes.filter(e=>"inlet"===e.state.kind).map(e=>e.state.id),i=this.__adjacency(),n=new Set(t),s=new Map,r=[...t];let a,o;for(;r.length;){const e=r.shift(),t=this.__symbolById(e);if(t&&(!isWaterValveKind(t.state.kind)||"closed"!==t.state.valveState)){if("outlet"===t.state.kind){a=e;break}(i.get(e)||[]).forEach(t=>{const i=this.__symbolById(t.to);i&&isWaterValveKind(i.state.kind)&&"closed"===i.state.valveState?o||(o=t.to):n.has(t.to)||(n.add(t.to),s.set(t.to,e),r.push(t.to))})}}const l=[];if(a){let e=a;for(;e;)l.unshift(e),e=s.get(e)}const h={connected:!!a,path:l};return a&&(h.outletId=a),!a&&o&&(h.blockedAt=o),h}validateWater(){const e=[],t=this.nodes,i=this.edges,n=new Map;t.forEach(t=>{const i=String(t.state.tag||"").trim();i&&(n.has(i)?e.push({level:"error",code:"duplicate-tag",message:`位号重复:${i}`,id:t.state.id}):n.set(i,t.state.id))});const s=new Map;i.forEach(e=>{[this.__linkId(e,"start"),this.__linkId(e,"end")].forEach(e=>{e&&s.set(e,(s.get(e)||0)+1)})}),t.forEach(t=>{s.get(t.state.id)||e.push({level:"warning",code:"isolated-symbol",message:`「${t.state.name||Sn[t.state.kind]?.label||t.state.kind}」没有任何管线`,id:t.state.id})}),i.forEach(t=>{t.state.medium||e.push({level:"warning",code:"pipe-missing-medium",message:"管线缺少介质标注",id:t.state.id});"signal"===t.state.medium||"power"===t.state.medium||String(t.state.dn||"").trim()||e.push({level:"warning",code:"pipe-missing-dn",message:"管线缺少管径标注(DN)",id:t.state.id})});const r=this.traceFlow();if(r.connected){r.path.some(e=>{const t=this.__symbolById(e);return!!t&&"analyzer"===t.state.kind})||e.push({level:"error",code:"outlet-without-analyzer",message:"出水管线上没有在线水质分析仪(排污许可要求在线监测并联网)"})}else e.push({level:"error",code:"flow-disconnected",message:r.blockedAt?"从进水走不到出水:管线在关断的阀门处断开":"从进水走不到出水:主流程未接通",id:r.blockedAt});const a=i.some(e=>"sludge"===e.state.medium),o=t.some(e=>-1!==["sludgeThickener","dewateringMachine","sludgeOut"].indexOf(e.state.kind));a&&!o&&e.push({level:"warning",code:"sludge-without-disposal",message:"有剩余污泥排出,但图上没有污泥浓缩 / 脱水 / 外运单元"});const l=t.some(e=>"aerobicTank"===e.state.kind),h=t.some(e=>"anoxicTank"===e.state.kind),d=i.some(e=>"recycle"===e.state.medium);return l&&h&&!d&&e.push({level:"warning",code:"aao-missing-recycle",message:"有好氧池与缺氧池,但缺少混合液内回流(好氧 → 缺氧)"}),e}__linkId(e,t){const i=e.state&&e.state.links,n=i&&i[t];return n&&n.id?n.id:null}__adjacency(){const e=new Map;return this.edges.forEach(t=>{const i=this.__linkId(t,"start"),n=this.__linkId(t,"end");i&&n&&(e.has(i)||e.set(i,[]),e.has(n)||e.set(n,[]),e.get(i).push({to:n,pipe:t}),e.get(n).push({to:i,pipe:t}))}),e}__symbolById(e){return this.nodes.filter(t=>t.state.id===e)[0]||null}},exports.WaterSymbol=WaterSymbol,exports.addDays=addDays,exports.applyDesignerChrome=applyDesignerChrome,exports.arrowOf=function arrowOf(e){return Tn[e]||"--\x3e"},exports.composePipeLabel=composePipeLabel,exports.defaultVoltageColors=defaultVoltageColors,exports.designerChromeFromTheme=designerChromeFromTheme,exports.detectUmlDialect=function detectUmlDialect(e){return/@startuml/i.test(e)?"plantuml":/classDiagram/i.test(e)?"mermaid":"unknown"},exports.diffDays=diffDays,exports.eachDay=function eachDay(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:400;const n=parseDate(e),s=parseDate(t);if(isNaN(n)||isNaN(s)||s<n)return[];const r=[];for(let e=n;e<=s&&r.length<i;e+=dn)r.push(formatDate(e));return r},exports.formatDate=formatDate,exports.fromBpmnXml=function fromBpmnXml(e,t){const i=globalThis.DOMParser;if("function"!=typeof i)throw new Error("当前环境没有 DOMParser:请在浏览器(或 jsdom)中导入 BPMN XML");const n=(new i).parseFromString(e,"application/xml"),s=n.getElementsByTagName("parsererror");if(s&&s.length)throw new Error(`BPMN XML 解析失败:${s[0].textContent}`);const r=[],a=Array.prototype.slice.call(n.getElementsByTagName("*")),o=new Map,l=new Map;a.forEach(e=>{const t=localName(e);if("BPMNShape"===t){const t=e.getAttribute("bpmnElement"),i=Array.prototype.slice.call(e.getElementsByTagName("*")).find(e=>"Bounds"===localName(e));t&&i&&o.set(t,{x:Number(i.getAttribute("x"))||0,y:Number(i.getAttribute("y"))||0,width:Number(i.getAttribute("width"))||120,height:Number(i.getAttribute("height"))||80})}else if("BPMNEdge"===t){const t=e.getAttribute("bpmnElement"),i=Array.prototype.slice.call(e.getElementsByTagName("*")).filter(e=>"waypoint"===localName(e)).map(e=>[Number(e.getAttribute("x"))||0,Number(e.getAttribute("y"))||0]);t&&l.set(t,i)}}),t.clear();const h=new Map;let d=0;a.forEach(e=>{const i=localName(e);if("lane"===i){const i=e.getAttribute("id"),n=i?o.get(i):null;if(n){const s=t.createNode("bpmnLane",{title:e.getAttribute("name")||"Lane",left:n.x,top:n.y,width:n.width,height:n.height});i&&h.set(i,s.state.id),d+=1}return}if("participant"!==i)return;const n=e.getAttribute("id"),s=n?o.get(n):null;if(!s)return;const r=t.createNode("bpmnPool",{title:e.getAttribute("name")||"Pool",left:s.x,top:s.y,width:s.width,height:s.height});h.set(n,r.state.id),d+=1,r.setState({zIndex:0})}),a.forEach(e=>{const i=localName(e);if("participant"===i||"laneSet"===i||"process"===i||"collaboration"===i)return;if("lane"===i||"participant"===i)return;const n=function nodeFromElement(e){switch(e){case"startEvent":return{kind:"bpmnEvent",attrs:{eventKind:"start"}};case"endEvent":return{kind:"bpmnEvent",attrs:{eventKind:"end"}};case"intermediateThrowEvent":case"intermediateCatchEvent":return{kind:"bpmnEvent",attrs:{eventKind:"intermediate"}};case"exclusiveGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"exclusive"}};case"parallelGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"parallel"}};case"inclusiveGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"inclusive"}};case"eventBasedGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"event"}};case"subProcess":return{kind:"bpmnSubprocess",attrs:{}};case"dataObjectReference":return{kind:"bpmnDataObject",attrs:{}};case"textAnnotation":return{kind:"bpmnAnnotation",attrs:{}};case"task":return{kind:"bpmnTask",attrs:{taskType:"none"}};case"userTask":return{kind:"bpmnTask",attrs:{taskType:"user"}};case"serviceTask":return{kind:"bpmnTask",attrs:{taskType:"service"}};case"scriptTask":return{kind:"bpmnTask",attrs:{taskType:"script"}};case"sendTask":return{kind:"bpmnTask",attrs:{taskType:"send"}};case"receiveTask":return{kind:"bpmnTask",attrs:{taskType:"receive"}};case"manualTask":return{kind:"bpmnTask",attrs:{taskType:"manual"}};default:return null}}(i);if(!n)return;const s=e.getAttribute("id");if(!s)return;const a=o.get(s);a||r.push(`元素 ${s}(${i})没有 DI 布局信息,已按默认尺寸放在原点附近`);const l={...n.attrs};if("bpmnEvent"===n.kind&&(l.trigger=function triggerOf(e){const t=(e&&e.childNodes?Array.prototype.slice.call(e.childNodes):[]).map(e=>localName(e));return-1!==t.indexOf("messageEventDefinition")?"message":-1!==t.indexOf("timerEventDefinition")?"timer":-1!==t.indexOf("errorEventDefinition")?"error":-1!==t.indexOf("terminateEventDefinition")?"terminate":"none"}(e)),"textAnnotation"===i){const t=Array.prototype.slice.call(e.getElementsByTagName("*")).find(e=>"text"===localName(e));l.title=t&&t.textContent||""}const c=t.createNode(n.kind,{...l,title:e.getAttribute("name")||l.title||"",left:a?a.x:0,top:a?a.y:0,width:a?a.width:void 0,height:a?a.height:void 0});h.set(s,c.state.id),d+=1});let c=0;return a.forEach(e=>{const i=localName(e);if("sequenceFlow"!==i&&"messageFlow"!==i)return;const n=e.getAttribute("sourceRef"),s=e.getAttribute("targetRef"),a=n?h.get(n):null,o=s?h.get(s):null;if(!a||!o)return void r.push(`连线 ${e.getAttribute("id")} 的端点未找到(sourceRef=${n} targetRef=${s})`);const l=Array.prototype.slice.call(e.getElementsByTagName("*")).find(e=>"conditionExpression"===localName(e));t.createEdge({sourceId:a,targetId:o,label:e.getAttribute("name")||"",flowType:"messageFlow"===i?"message":"sequence",isDefault:"true"===e.getAttribute("default"),condition:l?l.textContent:""}),c+=1}),t.resetHistory(),{nodes:d,edges:c,warnings:r}},exports.fromMermaidGantt=function fromMermaidGantt(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n=[],s=[],r=new Map,a=new Map;let o="",l=i.defaultStart||"";String(e||"").split(/\r?\n/).forEach(e=>{const t=e.trim();if(!t)return;if(t.startsWith("%%")){const e=/^%%\s*task\s+(\S+)\s*:\s*(.*)$/i.exec(t);if(e){const t=r.get(e[1])||{};e[2].split(/\s+/).forEach(e=>{const[i,n]=e.split("=");"progress"===i?t.progress=Number(n):"deps"===i&&n&&(t.deps=n.split(",").filter(e=>!!e))}),r.set(e[1],t)}return}if(cn.test(t))return;const i=/^section\s+(.+)$/i.exec(t);if(i)return void(o=i[1].trim());const h=/^(.+?)\s*:\s*(.*)$/.exec(t);if(!h)return void n.push(`不认识的语法,已跳过:${t}`);const d={id:null,title:h[1].trim(),start:null,endDate:null,after:[],days:null,progress:0,resource:o,line:t};h[2].split(",").forEach(e=>{const i=e.trim();if(!i)return;if(fn.test(i))return void(/^done$/i.test(i)?d.progress=1:/^active$/i.test(i)&&(d.progress=.5));const s=/^after\s+(.+)$/i.exec(i);s?d.after=s[1].trim().split(/\s+/).filter(e=>!!e):/^until\s+/i.test(i)?n.push(`暂不支持 until 依赖,已跳过该子句:${t}`):un.test(i)?d.start?d.endDate||(d.endDate=i):d.start=i:pn.test(i)?d.days=function durationToDays(e){const t=pn.exec(e);if(!t)return 1;const i=Number(t[1]);switch(t[2].toLowerCase()){case"w":return Math.max(1,Math.round(7*i));case"d":return Math.max(1,Math.round(i));case"h":return Math.max(1,Math.round(i/24));default:return 1}}(i):d.id?n.push(`无法识别的子句「${i}」,已跳过:${t}`):d.id=i}),s.push(d),d.id&&a.set(d.id,d),!l&&d.start&&(l=d.start)}),t.clear();const h=l||"2026-01-01",d=new Map,c=[];s.forEach(e=>{const i=e.days||(e.start&&e.endDate?Math.max(1,diffDays(e.start,e.endDate)):3),n=t.createTask({title:e.title,start:e.start||h,days:i,progress:e.progress,resource:e.resource});c.push(n),e.id&&d.set(e.id,{node:n,parsed:e})});for(let e=0;e<8;e+=1){let e=!1;if(s.forEach((t,i)=>{if(!t.after.length)return;let n="";t.after.forEach(e=>{const t=d.get(e);if(!t)return;const i=addDays(t.node.state.start,Math.max(1,Number(t.node.state.days)||1));(!n||diffDays(n,i)>0)&&(n=i)}),n&&c[i].state.start!==n&&(c[i].applyPatch({start:n}),e=!0)}),!e)break}d.forEach((e,t)=>{const i=r.get(t);i&&("number"!=typeof i.progress||Number.isNaN(i.progress)||e.node.applyPatch({progress:i.progress}),i.deps&&i.deps.length&&(e.parsed.after=Array.from(new Set([...e.parsed.after,...i.deps]))))});let u=0;return s.forEach(e=>{if(!e.after.length)return;const i=d.get(e.id);i&&Array.from(new Set(e.after)).forEach(s=>{const r=d.get(s);r?(t.createDependency({sourceId:r.node.state.id,targetId:i.node.state.id}),u+=1):n.push(`找不到前置任务「${s}」,已跳过该依赖:${e.line}`)})}),t.select(null),{tasks:c.length,dependencies:u,warnings:n}},exports.fromPlantUml=function fromPlantUml(e,t){const i=[],n=new Map,s=[],r=String(e||"").split(/\r?\n/);let a=null,o=!1;r.forEach(e=>{const t=e.replace(/\s+$/,"").trim();if(!t||t.startsWith("'")||t.startsWith("//")||t.startsWith("%%"))return;if(/^@startuml/i.test(t)||/^@enduml/i.test(t)||/^classDiagram/i.test(t)||/^skinparam/i.test(t)||/^title/i.test(t))return;if(a){if("}"===t)return a=null,void(o=!1);if("--"===t||".."===t||"__"===t)return void(o=!1);const e=n.get(a);return void(o?e.attributes:e.methods).push(t)}const r=/^(abstract\s+class|abstract|class|interface|enum(?:eration)?)\s+(.+?)\s*(\{)?$/i.exec(t);if(r){const e=r[1].toLowerCase(),t=unquote(r[2].replace(/\{.*$/,"")),i=e.startsWith("interface")?"interface":e.startsWith("enum")?"enum":"class";return n.set(t,{kind:i,attributes:[],methods:[],abstract:e.startsWith("abstract")}),void(r[3]&&(a=t,o=!0))}/^(.+?)\s+(<\|--|<\|\.\.|<--|<\.\.|--\*|\*--|--o|o--|-->|\.\.>|--|\.\.)\s+(.+?)(?:\s*:\s*(.*))?$/.exec(t)?s.push(t):i.push(`不认识的语法,已跳过:${t}`)}),t.clear();const l=new Map;let h=0;n.forEach((e,i)=>{const n=t.createClass({kind:e.kind,className:i,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:80+h%3*260*1.4,top:80+280*Math.floor(h/3)});l.set(i,n),h++});let d=0;return s.forEach(e=>{const n=/^(.+?)\s+(<\|--|<\|\.\.|<--|<\.\.|--\*|\*--|--o|o--|-->|\.\.>|--|\.\.)\s+(.+?)(?:\s*:\s*(.*))?$/.exec(e);if(!n)return void i.push(`关系解析失败,已跳过:${e}`);const s=unquote(n[1]),r=n[2],a=unquote(n[3]),o=n[4]||"",h=0===r.indexOf("<"),c=(En.find(e=>{let[t]=e;return t.test(r)})||[/x/,"association"])[1],u=h?a:s,p=h?s:a,f=l.get(u),g=l.get(p);f&&g?(t.createRelation({sourceId:f.state.id,targetId:g.state.id,relationKind:c,label:o}),d++):i.push(`关系两端未定义,已跳过:${e}`)}),{classes:l.size,relations:d,warnings:i}},exports.fromPlantUmlState=function fromPlantUmlState(e,t){const i=[],n=[],s=[],r=[];String(e||"").split(/\r?\n/).forEach(e=>{const t=e.trim();if(!t||t.startsWith("'")||t.startsWith("//")||t.startsWith("%%"))return;if(/^@startuml/i.test(t)||/^@enduml/i.test(t)||/^title\b/i.test(t)||/^skinparam\b/i.test(t)||/^hide\b/i.test(t)||/^scale\b/i.test(t)||/^autoactivate\b/i.test(t)||/^note\b/i.test(t)||/^state\s+<<.*>>$/i.test(t))return;if("}"===t)return void r.pop();const a=/^state\s+(?:"([^"]+)"|([^\s{]+))(?:\s+as\s+([^\s{]+))?\s*(\{)?$/i.exec(t);if(a){const e=void 0!==a[1]?a[1]:a[2],t=a[3]||e,i=r.length?r[r.length-1]:null;return n.push({token:t,title:e,kind:a[4]?"composite":"state",parent:i}),void(a[4]&&r.push(t))}const o=/^(\[\*\]|[^\s]+)\s+(?:-+[a-z]*->|->)\s+(\[\*\]|[^\s]+)\s*(?::\s*(.*))?$/i.exec(t);o?s.push({from:o[1],to:o[2],label:(o[3]||"").trim(),line:t}):i.push(`不认识的语法,已跳过:${t}`)}),t.clear();const a=new Map,o=n.filter(e=>"composite"===e.kind),l=n.filter(e=>"composite"!==e.kind&&!e.parent);o.forEach((e,i)=>{const n=120+i%2*620,s=340+320*Math.floor(i/2),r=t.createState({kind:"composite",title:e.title,left:n,top:s,width:560,height:280});a.set(e.token,r)}),l.forEach((e,i)=>{const n=t.createState({title:e.title,left:120+i%4*280,top:100+140*Math.floor(i/4),width:180,height:64});a.set(e.token,n)}),n.filter(e=>"composite"!==e.kind&&e.parent).forEach(e=>{const s=a.get(e.parent);s||i.push(`找不到父状态「${e.parent}」,已按根级状态导入:${e.title}`);const r=n.filter(t=>t.parent===e.parent&&"composite"!==t.kind).findIndex(t=>t.token===e.token),o=s?s.state.left+24:120,l=s?s.state.top+70:100,h=t.createState({title:e.title,left:o+r%2*260,top:l+90*Math.floor(r/2),width:220,height:60});a.set(e.token,h)});let h=null,d=null;const ensureState=e=>{if(a.has(e))return a.get(e);const i=a.size,n=t.createState({title:e,left:120+i%4*280,top:100+140*Math.floor(i/4),width:180,height:64});return a.set(e,n),n};let c=0;return s.forEach(e=>{const i="[*]"===e.from?(h||(h=t.createState({kind:"initial",left:60,top:120})),h):ensureState(e.from),n="[*]"===e.to?(d||(d=t.createState({kind:"final",left:1160,top:120})),d):ensureState(e.to),s=splitTransitionLabel(e.label);t.createTransition({sourceId:i.state.id,targetId:n.state.id,event:s.event,guard:s.guard,action:s.action}),c+=1}),t.select(null),{states:a.size+(h?1:0)+(d?1:0),transitions:c,warnings:i}},exports.isWaterValveKind=isWaterValveKind,exports.parseDate=parseDate,exports.splitTransitionLabel=splitTransitionLabel,exports.tickLabel=tickLabel,exports.toBpmnXml=function toBpmnXml(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.nodes||[],n=e.edges||[],s=i.filter(e=>"bpmnPool"===e.state.kind),r=i.filter(e=>"bpmnLane"===e.state.kind),a=new Map;i.forEach(e=>a.set(e.state.id,e));const poolOf=e=>{if(!e)return null;const t=rectOf(e);return s.find(e=>centerInside(rectOf(e),t))||null},processIdOf=e=>`Process_${e?e.state.id:"default"}`,idOf=e=>{return t=e.state.id,String(t).replace(/[^A-Za-z0-9_-]/g,"_");var t},o=[],l=[],h=[],d=[],c=[];i.forEach(e=>{const t=function elementNameForNode(e){const t=e.state.kind;if("bpmnEvent"===t){const t=e.state.eventKind||"start";return"end"===t?"endEvent":"intermediate"===t?"intermediateThrowEvent":"startEvent"}if("bpmnGateway"===t)return{exclusive:"exclusiveGateway",parallel:"parallelGateway",inclusive:"inclusiveGateway",event:"eventBasedGateway"}[e.state.gatewayType||"exclusive"];if("bpmnSubprocess"===t)return"subProcess";if("bpmnDataObject"===t)return"dataObjectReference";if("bpmnAnnotation"===t)return"textAnnotation";if("bpmnTask"===t||"process"===t)return{none:"task",user:"userTask",service:"serviceTask",script:"scriptTask",send:"sendTask",receive:"receiveTask",manual:"manualTask"}[e.state.taskType||"none"]||"task";return null}(e);if(t){const i="bpmnEvent"===e.state.kind&&e.state.trigger&&"none"!==e.state.trigger?`<bpmn:${e.state.trigger}EventDefinition id="${idOf(e)}_def" />`:"",n="textAnnotation"===t?` id="${idOf(e)}"><bpmn:text>${escapeXml(e.state.title)}</bpmn:text></bpmn:textAnnotation>`:` id="${idOf(e)}" name="${escapeXml(e.state.title)}">${i}</bpmn:${t}>`,s="textAnnotation"===t?null:`<bpmn:${t}`;o.push(s?`${s}${n}`:`<bpmn:textAnnotation${n}`)}const i=rectOf(e);l.push(` <bpmndi:BPMNShape id="${idOf(e)}_di" bpmnElement="${idOf(e)}">\n <dc:Bounds x="${Math.round(i.x0)}" y="${Math.round(i.y0)}" width="${Math.round(i.x1-i.x0)}" height="${Math.round(i.y1-i.y0)}" />\n </bpmndi:BPMNShape>`)}),n.forEach(e=>{const t=e.state.links||{},i=a.get((t.start||{}).id),n=a.get((t.end||{}).id);if(!i||!n)return;if(poolOf(i)!==poolOf(n)||"message"===e.state.flowType)d.push(` <bpmn:messageFlow id="${idOf(e)}" name="${escapeXml(e.state.label)}" sourceRef="${idOf(i)}" targetRef="${idOf(n)}" />`);else{const t=e.state.condition?`\n <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${escapeXml(e.state.condition)}</bpmn:conditionExpression>\n `:"";h.push(` <bpmn:sequenceFlow id="${idOf(e)}" name="${escapeXml(e.state.label)}" sourceRef="${idOf(i)}" targetRef="${idOf(n)}"${e.state.isDefault?' default="true"':""}>${t}</bpmn:sequenceFlow>`)}const s=(e.state.points&&e.state.points.length?e.state.points:[e.state.startPoint,e.state.endPoint]).filter(Boolean);c.push(` <bpmndi:BPMNEdge id="${idOf(e)}_di" bpmnElement="${idOf(e)}">\n`+s.map(e=>` <di:waypoint x="${Math.round(e[0])}" y="${Math.round(e[1])}" />`).join("\n")+"\n </bpmndi:BPMNEdge>")});const u=[];return s.forEach(e=>{const t=r.filter(t=>centerInside(rectOf(e),rectOf(t))),i=t.length?`\n <bpmn:laneSet id="${idOf(e)}_lanes">\n`+t.map(e=>` <bpmn:lane id="${idOf(e)}" name="${escapeXml(e.state.title)}" />`).join("\n")+"\n </bpmn:laneSet>":"";u.push(` <bpmn:process id="${processIdOf(e)}" name="${escapeXml(e.state.title)}" isExecutable="false">${i}\n \x3c!-- 该池内的流元素与顺序流由下面的 collaboration/di 段按 id 关联 --\x3e\n </bpmn:process>`)}),u.push(' <bpmn:process id="Process_default" isExecutable="false" />'),`<?xml version="1.0" encoding="UTF-8"?>\n<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://ice-render/bpmn">\n <bpmn:collaboration id="Collaboration_1">\n${s.map(e=>` <bpmn:participant id="${idOf(e)}" name="${escapeXml(e.state.title)}" processRef="${processIdOf(e)}" />`).join("\n")}\n </bpmn:collaboration>\n`+u.join("\n")+"\n \x3c!-- 流元素 --\x3e\n"+o.map(e=>` ${e}`).join("\n")+"\n \x3c!-- 连线 --\x3e\n"+h.join("\n")+"\n"+d.join("\n")+`\n <bpmndi:BPMNDiagram id="BPMNDiagram_1" name="${escapeXml(t.name||"BPMN Diagram")}">\n <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">\n`+l.join("\n")+(c.length?"\n"+c.join("\n"):"")+"\n </bpmndi:BPMNPlane>\n </bpmndi:BPMNDiagram>\n</bpmn:definitions>\n"},exports.toMermaidGantt=function toMermaidGantt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.nodes||[],n=new Map;i.forEach((e,t)=>n.set(e.state.id,`t${t+1}`));const s=new Map;(e.edges||[]).forEach(e=>{const t=e.state.links||{},i=t.start&&t.start.id,r=t.end&&t.end.id;i&&r&&n.has(r)&&s.set(r,[...s.get(r)||[],i])});const r=["gantt"];t.title&&r.push(` title ${t.title}`),r.push(" dateFormat YYYY-MM-DD"),r.push(" axisFormat %m-%d");const emit=t=>{const i=n.get(t.state.id),a=Number(t.state.progress)||0,o=s.get(t.state.id)||[],l=[];a>=1?l.push("done"):a>0&&l.push("active");const h=1===o.length?n.get(o[0]):null,d=1===o.length?(e.nodes||[]).find(e=>e.state.id===o[0]):null,c=d&&h?addDays(d.state.start,Math.max(1,Math.round(Number(d.state.days)||1))):null,u=!!h&&c===String(t.state.start||""),p=u?`after ${h}`:String(t.state.start||""),f=Math.max(1,Math.round(Number(t.state.days)||1));r.push(` ${t.state.title} :${l.length?`${l.join(", ")}, `:""}${i}, ${p}, ${f}d`);const g=[];a>0&&a<1&&g.push(`progress=${a}`),o.length&&!u&&g.push(`deps=${o.map(e=>n.get(e)).join(",")}`),g.length&&r.push(` %% task ${i}: ${g.join(" ")}`)},a=[];return i.forEach(e=>{const t=String(e.state.resource||"");t&&-1===a.indexOf(t)&&a.push(t)}),i.filter(e=>!String(e.state.resource||"")).forEach(emit),a.forEach(e=>{r.push(""),r.push(` section ${e}`),i.filter(t=>String(t.state.resource||"")===e).forEach(emit)}),r.join("\n")},exports.toPlantUml=function toPlantUml(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=["@startuml"];t.title&&i.push(`title ${t.title}`),i.push("skinparam classAttributeIconSize 0");const n=e.nodes;n.forEach(e=>{const t=e.state.kind||"class",n="interface"===t?"interface":"enum"===t?"enum":e.state.abstract?"abstract class":"class",s=quoteIfNeeded(String(e.state.className||"Class"));[...e.state.attributes||[],...e.state.methods||[]].length?(i.push(`${n} ${s} {`),(e.state.attributes||[]).forEach(e=>i.push(` ${e}`)),(e.state.methods||[]).length&&(i.push(" --"),(e.state.methods||[]).forEach(e=>i.push(` ${e}`))),i.push("}")):i.push(`${n} ${s}`)});const s=new Map;return n.forEach(e=>s.set(e.state.id,e)),e.edges.forEach(e=>{const t=e.state.links||{},n=t.start&&t.start.id,r=t.end&&t.end.id,a=s.get(n),o=s.get(r);if(!a||!o)return;const l=e.state.relationKind||"association",h=Tn[l]||"--\x3e",d=e.state.label?` : ${e.state.label}`:"",c=0===h.indexOf("<"),u=quoteIfNeeded(String((c?o:a).state.className)),p=quoteIfNeeded(String((c?a:o).state.className));i.push(`${u} ${h} ${p}${d}`)}),i.push("@enduml"),i.join("\n")},exports.toPlantUmlState=function toPlantUmlState(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.nodes||[],n=["@startuml"];t.title&&n.push(`title ${t.title}`);const s=new Map;i.forEach(e=>s.set(e.state.id,e));const r=new Map;i.forEach(e=>{const t=String(e.state.title||"");t&&r.set(t,(r.get(t)||0)+1)});const a=new Map;let o=0;const declaration=e=>{const t=String(e.state.title||"");if(!(!hn.test(t)||(r.get(t)||0)>1))return`state ${t}`;o+=1;const i=`S${o}`;return a.set(e.state.id,i),`state "${t}" as ${i}`},reference=e=>a.get(e.state.id)||String(e.state.title||""),l=new Set;return i.filter(e=>"composite"===kindOf(e)).forEach(e=>{const t=i.filter(t=>!isPseudo(kindOf(t))&&function nearestStateAncestor(e){let t=e.parentNode;for(;t;){if(t.constructor&&"ice-entity-designer:StateNode"===t.constructor.typeId)return t;t=t.parentNode}return null}(t)===e);t.forEach(e=>l.add(e.state.id)),n.push(`${declaration(e)} {`),t.forEach(e=>n.push(` ${declaration(e)}`)),n.push("}")}),i.forEach(e=>{const t=kindOf(e);isPseudo(t)||"composite"===t||l.has(e.state.id)||n.push(declaration(e))}),(e.edges||[]).forEach(e=>{const t=e.state.links||{},i=s.get(t.start&&t.start.id),r=s.get(t.end&&t.end.id);if(!i||!r)return;const a="initial"===kindOf(i)?"[*]":reference(i),o="final"===kindOf(r)?"[*]":reference(r),l=e.state.label?` : ${e.state.label}`:"";n.push(`${a} --\x3e ${o}${l}`)}),n.push("@enduml"),n.join("\n")},exports.toSchemaObject=toSchemaObject,exports.toSchemaString=toSchemaString,exports.validateBpmn=validateBpmn,exports.validateFlowSnapshot=validateFlowSnapshot,exports.validateProjectSnapshot=validateProjectSnapshot,exports.validateSchema=validateSchema,exports.voltageColorOf=voltageColorOf,Object.keys(i).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})});
|
|
25
|
+
"use strict";var e,t,i=require("ice-render"),n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s,r,a,o,l,h,d,c,u,p,f,g,m,y,_,b,v,k,w,S,C,x,T,I,E,P,M,D,$,N,B,O,L,z,A,W,q,j,F,R,H,G,U,V,K,Y,X,J,Q,Z,ee,te,ie,ne,se,re,ae,oe,le,he,de,ce,ue,pe,fe,ge,me,ye,_e,be,ve,ke,we,Se,Ce,xe,Te,Ie,Ee,Pe,Me,De,$e,Ne,Be,Oe,Le,ze,Ae,We,qe,je,Fe,Re,He,Ge,Ue,Ve,Ke=getDefaultExportFromCjs(function requireIsNil(){return t?e:(t=1,e=function isNil(e){return null==e})}());function requireEq(){if(o)return a;return o=1,a=function eq(e,t){return e===t||e!=e&&t!=t}}function require_assocIndexOf(){if(h)return l;h=1;var e=requireEq();return l=function assocIndexOf(t,i){for(var n=t.length;n--;)if(e(t[n][0],i))return n;return-1}}function require_ListCache(){if(b)return _;b=1;var e=function require_listCacheClear(){return r?s:(r=1,s=function listCacheClear(){this.__data__=[],this.size=0})}(),t=function require_listCacheDelete(){if(c)return d;c=1;var e=require_assocIndexOf(),t=Array.prototype.splice;return d=function listCacheDelete(i){var n=this.__data__,s=e(n,i);return!(s<0||(s==n.length-1?n.pop():t.call(n,s,1),--this.size,0))}}(),i=function require_listCacheGet(){if(p)return u;p=1;var e=require_assocIndexOf();return u=function listCacheGet(t){var i=this.__data__,n=e(i,t);return n<0?void 0:i[n][1]}}(),n=function require_listCacheHas(){if(g)return f;g=1;var e=require_assocIndexOf();return f=function listCacheHas(t){return e(this.__data__,t)>-1}}(),a=function require_listCacheSet(){if(y)return m;y=1;var e=require_assocIndexOf();return m=function listCacheSet(t,i){var n=this.__data__,s=e(n,t);return s<0?(++this.size,n.push([t,i])):n[s][1]=i,this}}();function ListCache(e){var t=-1,i=null==e?0:e.length;for(this.clear();++t<i;){var n=e[t];this.set(n[0],n[1])}}return ListCache.prototype.clear=e,ListCache.prototype.delete=t,ListCache.prototype.get=i,ListCache.prototype.has=n,ListCache.prototype.set=a,_=ListCache}function require_freeGlobal(){if(P)return E;P=1;var e="object"==typeof n&&n&&n.Object===Object&&n;return E=e}function require_root(){if(D)return M;D=1;var e=require_freeGlobal(),t="object"==typeof self&&self&&self.Object===Object&&self,i=e||t||Function("return this")();return M=i}function require_Symbol(){if(N)return $;N=1;var e=require_root().Symbol;return $=e}function require_baseGetTag(){if(W)return A;W=1;var e=require_Symbol(),t=function require_getRawTag(){if(O)return B;O=1;var e=require_Symbol(),t=Object.prototype,i=t.hasOwnProperty,n=t.toString,s=e?e.toStringTag:void 0;return B=function getRawTag(e){var t=i.call(e,s),r=e[s];try{e[s]=void 0;var a=!0}catch(e){}var o=n.call(e);return a&&(t?e[s]=r:delete e[s]),o}}(),i=function require_objectToString(){if(z)return L;z=1;var e=Object.prototype.toString;return L=function objectToString(t){return e.call(t)}}(),n=e?e.toStringTag:void 0;return A=function baseGetTag(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":n&&n in Object(e)?t(e):i(e)}}function requireIsObject(){if(j)return q;return j=1,q=function isObject(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}}function requireIsFunction(){if(R)return F;R=1;var e=require_baseGetTag(),t=requireIsObject();return F=function isFunction(i){if(!t(i))return!1;var n=e(i);return"[object Function]"==n||"[object GeneratorFunction]"==n||"[object AsyncFunction]"==n||"[object Proxy]"==n}}function require_isMasked(){if(V)return U;V=1;var e,t=function require_coreJsData(){if(G)return H;G=1;var e=require_root()["__core-js_shared__"];return H=e}(),i=(e=/[^.]+$/.exec(t&&t.keys&&t.keys.IE_PROTO||""))?"Symbol(src)_1."+e:"";return U=function isMasked(e){return!!i&&i in e}}function require_baseIsNative(){if(J)return X;J=1;var e=requireIsFunction(),t=require_isMasked(),i=requireIsObject(),n=function require_toSource(){if(Y)return K;Y=1;var e=Function.prototype.toString;return K=function toSource(t){if(null!=t){try{return e.call(t)}catch(e){}try{return t+""}catch(e){}}return""}}(),s=/^\[object .+?Constructor\]$/,r=Function.prototype,a=Object.prototype,o=r.toString,l=a.hasOwnProperty,h=RegExp("^"+o.call(l).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");return X=function baseIsNative(r){return!(!i(r)||t(r))&&(e(r)?h:s).test(n(r))}}function require_getNative(){if(te)return ee;te=1;var e=require_baseIsNative(),t=function require_getValue(){return Z?Q:(Z=1,Q=function getValue(e,t){return null==e?void 0:e[t]})}();return ee=function getNative(i,n){var s=t(i,n);return e(s)?s:void 0}}function require_Map(){if(ne)return ie;ne=1;var e=require_getNative()(require_root(),"Map");return ie=e}function require_nativeCreate(){if(re)return se;re=1;var e=require_getNative()(Object,"create");return se=e}function require_Hash(){if(ye)return me;ye=1;var e=function require_hashClear(){if(oe)return ae;oe=1;var e=require_nativeCreate();return ae=function hashClear(){this.__data__=e?e(null):{},this.size=0}}(),t=function require_hashDelete(){return he?le:(he=1,le=function hashDelete(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t})}(),i=function require_hashGet(){if(ce)return de;ce=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return de=function hashGet(i){var n=this.__data__;if(e){var s=n[i];return"__lodash_hash_undefined__"===s?void 0:s}return t.call(n,i)?n[i]:void 0}}(),n=function require_hashHas(){if(pe)return ue;pe=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return ue=function hashHas(i){var n=this.__data__;return e?void 0!==n[i]:t.call(n,i)}}(),s=function require_hashSet(){if(ge)return fe;ge=1;var e=require_nativeCreate();return fe=function hashSet(t,i){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=e&&void 0===i?"__lodash_hash_undefined__":i,this}}();function Hash(e){var t=-1,i=null==e?0:e.length;for(this.clear();++t<i;){var n=e[t];this.set(n[0],n[1])}}return Hash.prototype.clear=e,Hash.prototype.delete=t,Hash.prototype.get=i,Hash.prototype.has=n,Hash.prototype.set=s,me=Hash}function require_getMapData(){if(Se)return we;Se=1;var e=function require_isKeyable(){return ke?ve:(ke=1,ve=function isKeyable(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e})}();return we=function getMapData(t,i){var n=t.__data__;return e(i)?n["string"==typeof i?"string":"hash"]:n.map}}function require_MapCache(){if(Ne)return $e;Ne=1;var e=function require_mapCacheClear(){if(be)return _e;be=1;var e=require_Hash(),t=require_ListCache(),i=require_Map();return _e=function mapCacheClear(){this.size=0,this.__data__={hash:new e,map:new(i||t),string:new e}}}(),t=function require_mapCacheDelete(){if(xe)return Ce;xe=1;var e=require_getMapData();return Ce=function mapCacheDelete(t){var i=e(this,t).delete(t);return this.size-=i?1:0,i}}(),i=function require_mapCacheGet(){if(Ie)return Te;Ie=1;var e=require_getMapData();return Te=function mapCacheGet(t){return e(this,t).get(t)}}(),n=function require_mapCacheHas(){if(Pe)return Ee;Pe=1;var e=require_getMapData();return Ee=function mapCacheHas(t){return e(this,t).has(t)}}(),s=function require_mapCacheSet(){if(De)return Me;De=1;var e=require_getMapData();return Me=function mapCacheSet(t,i){var n=e(this,t),s=n.size;return n.set(t,i),this.size+=n.size==s?0:1,this}}();function MapCache(e){var t=-1,i=null==e?0:e.length;for(this.clear();++t<i;){var n=e[t];this.set(n[0],n[1])}}return MapCache.prototype.clear=e,MapCache.prototype.delete=t,MapCache.prototype.get=i,MapCache.prototype.has=n,MapCache.prototype.set=s,$e=MapCache}function require_Stack(){if(ze)return Le;ze=1;var e=require_ListCache(),t=function require_stackClear(){if(k)return v;k=1;var e=require_ListCache();return v=function stackClear(){this.__data__=new e,this.size=0}}(),i=function require_stackDelete(){return S?w:(S=1,w=function stackDelete(e){var t=this.__data__,i=t.delete(e);return this.size=t.size,i})}(),n=function require_stackGet(){return x?C:(x=1,C=function stackGet(e){return this.__data__.get(e)})}(),s=function require_stackHas(){return I?T:(I=1,T=function stackHas(e){return this.__data__.has(e)})}(),r=function require_stackSet(){if(Oe)return Be;Oe=1;var e=require_ListCache(),t=require_Map(),i=require_MapCache();return Be=function stackSet(n,s){var r=this.__data__;if(r instanceof e){var a=r.__data__;if(!t||a.length<199)return a.push([n,s]),this.size=++r.size,this;r=this.__data__=new i(a)}return r.set(n,s),this.size=r.size,this}}();function Stack(t){var i=this.__data__=new e(t);this.size=i.size}return Stack.prototype.clear=t,Stack.prototype.delete=i,Stack.prototype.get=n,Stack.prototype.has=s,Stack.prototype.set=r,Le=Stack}function require_defineProperty(){if(We)return Ae;We=1;var e=require_getNative(),t=function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch(e){}}();return Ae=t}function require_baseAssignValue(){if(je)return qe;je=1;var e=require_defineProperty();return qe=function baseAssignValue(t,i,n){"__proto__"==i&&e?e(t,i,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[i]=n}}function require_assignMergeValue(){if(Re)return Fe;Re=1;var e=require_baseAssignValue(),t=requireEq();return Fe=function assignMergeValue(i,n,s){(void 0!==s&&!t(i[n],s)||void 0===s&&!(n in i))&&e(i,n,s)}}function require_baseFor(){if(Ve)return Ue;Ve=1;var e=function require_createBaseFor(){return Ge?He:(Ge=1,He=function createBaseFor(e){return function(t,i,n){for(var s=-1,r=Object(t),a=n(t),o=a.length;o--;){var l=a[e?o:++s];if(!1===i(r[l],l,r))break}return t}})}()();return Ue=e}var Ye,Xe,Je,Qe,Ze,et,tt,it,nt,st,rt,at,ot,lt,ht,dt,ct,ut,pt,ft,gt,mt,yt,_t,bt,vt,kt,wt,St,Ct,xt,Tt,It,Et={exports:{}};function require_cloneArrayBuffer(){if(Ze)return Qe;Ze=1;var e=function require_Uint8Array(){if(Je)return Xe;Je=1;var e=require_root().Uint8Array;return Xe=e}();return Qe=function cloneArrayBuffer(t){var i=new t.constructor(t.byteLength);return new e(i).set(new e(t)),i}}function require_getPrototype(){if(ht)return lt;ht=1;var e=function require_overArg(){return ot?at:(ot=1,at=function overArg(e,t){return function(i){return e(t(i))}})}()(Object.getPrototypeOf,Object);return lt=e}function require_isPrototype(){if(ct)return dt;ct=1;var e=Object.prototype;return dt=function isPrototype(t){var i=t&&t.constructor;return t===("function"==typeof i&&i.prototype||e)}}function require_initCloneObject(){if(pt)return ut;pt=1;var e=function require_baseCreate(){if(rt)return st;rt=1;var e=requireIsObject(),t=Object.create,i=function(){function object(){}return function(i){if(!e(i))return{};if(t)return t(i);object.prototype=i;var n=new object;return object.prototype=void 0,n}}();return st=i}(),t=require_getPrototype(),i=require_isPrototype();return ut=function initCloneObject(n){return"function"!=typeof n.constructor||i(n)?{}:e(t(n))}}function requireIsObjectLike(){if(gt)return ft;return gt=1,ft=function isObjectLike(e){return null!=e&&"object"==typeof e}}function requireIsArguments(){if(bt)return _t;bt=1;var e=function require_baseIsArguments(){if(yt)return mt;yt=1;var e=require_baseGetTag(),t=requireIsObjectLike();return mt=function baseIsArguments(i){return t(i)&&"[object Arguments]"==e(i)}}(),t=requireIsObjectLike(),i=Object.prototype,n=i.hasOwnProperty,s=i.propertyIsEnumerable,r=e(function(){return arguments}())?e:function(e){return t(e)&&n.call(e,"callee")&&!s.call(e,"callee")};return _t=r}function requireIsArray(){if(kt)return vt;kt=1;var e=Array.isArray;return vt=e}function requireIsLength(){if(St)return wt;St=1;return wt=function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}}function requireIsArrayLike(){if(xt)return Ct;xt=1;var e=requireIsFunction(),t=requireIsLength();return Ct=function isArrayLike(i){return null!=i&&t(i.length)&&!e(i)}}var Pt,Mt,Dt,$t,Nt,Bt,Ot,Lt,zt,At={exports:{}};function requireIsBuffer(){return Dt||(Dt=1,function(e,t){var i=require_root(),n=function requireStubFalse(){return Mt?Pt:(Mt=1,Pt=function stubFalse(){return!1})}(),s=t&&!t.nodeType&&t,r=s&&e&&!e.nodeType&&e,a=r&&r.exports===s?i.Buffer:void 0,o=(a?a.isBuffer:void 0)||n;e.exports=o}(At,At.exports)),At.exports}var Wt,qt,jt,Ft,Rt,Ht,Gt,Ut,Vt,Kt,Yt,Xt,Jt,Qt,Zt,ei,ti,ii,ni,si,ri,ai,oi,li,hi,di,ci,ui,pi,fi,gi,mi,yi,_i,bi,vi,ki,wi,Si,Ci,xi,Ti,Ii,Ei,Pi,Mi,Di,$i,Ni,Bi={exports:{}};function requireIsTypedArray(){if(jt)return qt;jt=1;var e=function require_baseIsTypedArray(){if(Ot)return Bt;Ot=1;var e=require_baseGetTag(),t=requireIsLength(),i=requireIsObjectLike(),n={};return n["[object Float32Array]"]=n["[object Float64Array]"]=n["[object Int8Array]"]=n["[object Int16Array]"]=n["[object Int32Array]"]=n["[object Uint8Array]"]=n["[object Uint8ClampedArray]"]=n["[object Uint16Array]"]=n["[object Uint32Array]"]=!0,n["[object Arguments]"]=n["[object Array]"]=n["[object ArrayBuffer]"]=n["[object Boolean]"]=n["[object DataView]"]=n["[object Date]"]=n["[object Error]"]=n["[object Function]"]=n["[object Map]"]=n["[object Number]"]=n["[object Object]"]=n["[object RegExp]"]=n["[object Set]"]=n["[object String]"]=n["[object WeakMap]"]=!1,Bt=function baseIsTypedArray(s){return i(s)&&t(s.length)&&!!n[e(s)]}}(),t=function require_baseUnary(){return zt?Lt:(zt=1,Lt=function baseUnary(e){return function(t){return e(t)}})}(),i=function require_nodeUtil(){return Wt||(Wt=1,function(e,t){var i=require_freeGlobal(),n=t&&!t.nodeType&&t,s=n&&e&&!e.nodeType&&e,r=s&&s.exports===n&&i.process,a=function(){try{return s&&s.require&&s.require("util").types||r&&r.binding&&r.binding("util")}catch(e){}}();e.exports=a}(Bi,Bi.exports)),Bi.exports}(),n=i&&i.isTypedArray,s=n?t(n):e;return qt=s}function require_safeGet(){if(Rt)return Ft;return Rt=1,Ft=function safeGet(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}}function require_copyObject(){if(Vt)return Ut;Vt=1;var e=function require_assignValue(){if(Gt)return Ht;Gt=1;var e=require_baseAssignValue(),t=requireEq(),i=Object.prototype.hasOwnProperty;return Ht=function assignValue(n,s,r){var a=n[s];i.call(n,s)&&t(a,r)&&(void 0!==r||s in n)||e(n,s,r)}}(),t=require_baseAssignValue();return Ut=function copyObject(i,n,s,r){var a=!s;s||(s={});for(var o=-1,l=n.length;++o<l;){var h=n[o],d=r?r(s[h],i[h],h,s,i):void 0;void 0===d&&(d=i[h]),a?t(s,h,d):e(s,h,d)}return s}}function require_isIndex(){if(Jt)return Xt;Jt=1;var e=/^(?:0|[1-9]\d*)$/;return Xt=function isIndex(t,i){var n=typeof t;return!!(i=null==i?9007199254740991:i)&&("number"==n||"symbol"!=n&&e.test(t))&&t>-1&&t%1==0&&t<i}}function require_arrayLikeKeys(){if(Zt)return Qt;Zt=1;var e=function require_baseTimes(){return Yt?Kt:(Yt=1,Kt=function baseTimes(e,t){for(var i=-1,n=Array(e);++i<e;)n[i]=t(i);return n})}(),t=requireIsArguments(),i=requireIsArray(),n=requireIsBuffer(),s=require_isIndex(),r=requireIsTypedArray(),a=Object.prototype.hasOwnProperty;return Qt=function arrayLikeKeys(o,l){var h=i(o),d=!h&&t(o),c=!h&&!d&&n(o),u=!h&&!d&&!c&&r(o),p=h||d||c||u,f=p?e(o.length,String):[],g=f.length;for(var m in o)!l&&!a.call(o,m)||p&&("length"==m||c&&("offset"==m||"parent"==m)||u&&("buffer"==m||"byteLength"==m||"byteOffset"==m)||s(m,g))||f.push(m);return f}}function require_baseKeysIn(){if(ni)return ii;ni=1;var e=requireIsObject(),t=require_isPrototype(),i=function require_nativeKeysIn(){return ti?ei:(ti=1,ei=function nativeKeysIn(e){var t=[];if(null!=e)for(var i in Object(e))t.push(i);return t})}(),n=Object.prototype.hasOwnProperty;return ii=function baseKeysIn(s){if(!e(s))return i(s);var r=t(s),a=[];for(var o in s)("constructor"!=o||!r&&n.call(s,o))&&a.push(o);return a}}function requireKeysIn(){if(ri)return si;ri=1;var e=require_arrayLikeKeys(),t=require_baseKeysIn(),i=requireIsArrayLike();return si=function keysIn(n){return i(n)?e(n,!0):t(n)}}function require_baseMergeDeep(){if(hi)return li;hi=1;var e=require_assignMergeValue(),t=function require_cloneBuffer(){return Ye||(Ye=1,function(e,t){var i=require_root(),n=t&&!t.nodeType&&t,s=n&&e&&!e.nodeType&&e,r=s&&s.exports===n?i.Buffer:void 0,a=r?r.allocUnsafe:void 0;e.exports=function cloneBuffer(e,t){if(t)return e.slice();var i=e.length,n=a?a(i):new e.constructor(i);return e.copy(n),n}}(Et,Et.exports)),Et.exports}(),i=function require_cloneTypedArray(){if(tt)return et;tt=1;var e=require_cloneArrayBuffer();return et=function cloneTypedArray(t,i){var n=i?e(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}}(),n=function require_copyArray(){return nt?it:(nt=1,it=function copyArray(e,t){var i=-1,n=e.length;for(t||(t=Array(n));++i<n;)t[i]=e[i];return t})}(),s=require_initCloneObject(),r=requireIsArguments(),a=requireIsArray(),o=function requireIsArrayLikeObject(){if(It)return Tt;It=1;var e=requireIsArrayLike(),t=requireIsObjectLike();return Tt=function isArrayLikeObject(i){return t(i)&&e(i)}}(),l=requireIsBuffer(),h=requireIsFunction(),d=requireIsObject(),c=function requireIsPlainObject(){if(Nt)return $t;Nt=1;var e=require_baseGetTag(),t=require_getPrototype(),i=requireIsObjectLike(),n=Function.prototype,s=Object.prototype,r=n.toString,a=s.hasOwnProperty,o=r.call(Object);return $t=function isPlainObject(n){if(!i(n)||"[object Object]"!=e(n))return!1;var s=t(n);if(null===s)return!0;var l=a.call(s,"constructor")&&s.constructor;return"function"==typeof l&&l instanceof l&&r.call(l)==o}}(),u=requireIsTypedArray(),p=require_safeGet(),f=function requireToPlainObject(){if(oi)return ai;oi=1;var e=require_copyObject(),t=requireKeysIn();return ai=function toPlainObject(i){return e(i,t(i))}}();return li=function baseMergeDeep(g,m,y,_,b,v,k){var w=p(g,y),S=p(m,y),C=k.get(S);if(C)e(g,y,C);else{var x=v?v(w,S,y+"",g,m,k):void 0,T=void 0===x;if(T){var I=a(S),E=!I&&l(S),P=!I&&!E&&u(S);x=S,I||E||P?a(w)?x=w:o(w)?x=n(w):E?(T=!1,x=t(S,!0)):P?(T=!1,x=i(S,!0)):x=[]:c(S)||r(S)?(x=w,r(w)?x=f(w):d(w)&&!h(w)||(x=s(S))):T=!1}T&&(k.set(S,x),b(x,S,_,v,k),k.delete(S)),e(g,y,x)}}}function requireIdentity(){if(pi)return ui;return pi=1,ui=function identity(e){return e}}function require_overRest(){if(yi)return mi;yi=1;var e=function require_apply(){return gi?fi:(gi=1,fi=function apply(e,t,i){switch(i.length){case 0:return e.call(t);case 1:return e.call(t,i[0]);case 2:return e.call(t,i[0],i[1]);case 3:return e.call(t,i[0],i[1],i[2])}return e.apply(t,i)})}(),t=Math.max;return mi=function overRest(i,n,s){return n=t(void 0===n?i.length-1:n,0),function(){for(var r=arguments,a=-1,o=t(r.length-n,0),l=Array(o);++a<o;)l[a]=r[n+a];a=-1;for(var h=Array(n+1);++a<n;)h[a]=r[a];return h[n]=s(l),e(i,this,h)}},mi}function require_baseSetToString(){if(ki)return vi;ki=1;var e=function requireConstant(){return bi?_i:(bi=1,_i=function constant(e){return function(){return e}})}(),t=require_defineProperty(),i=requireIdentity();return vi=t?function(i,n){return t(i,"toString",{configurable:!0,enumerable:!1,value:e(n),writable:!0})}:i}function require_setToString(){if(xi)return Ci;xi=1;var e=require_baseSetToString(),t=function require_shortOut(){if(Si)return wi;Si=1;var e=Date.now;return wi=function shortOut(t){var i=0,n=0;return function(){var s=e(),r=16-(s-n);if(n=s,r>0){if(++i>=800)return arguments[0]}else i=0;return t.apply(void 0,arguments)}},wi}(),i=t(e);return Ci=i}function require_createAssigner(){if(Di)return Mi;Di=1;var e=function require_baseRest(){if(Ii)return Ti;Ii=1;var e=requireIdentity(),t=require_overRest(),i=require_setToString();return Ti=function baseRest(n,s){return i(t(n,s,e),n+"")}}(),t=function require_isIterateeCall(){if(Pi)return Ei;Pi=1;var e=requireEq(),t=requireIsArrayLike(),i=require_isIndex(),n=requireIsObject();return Ei=function isIterateeCall(s,r,a){if(!n(a))return!1;var o=typeof r;return!!("number"==o?t(a)&&i(r,a.length):"string"==o&&r in a)&&e(a[r],s)}}();return Mi=function createAssigner(i){return e(function(e,n){var s=-1,r=n.length,a=r>1?n[r-1]:void 0,o=r>2?n[2]:void 0;for(a=i.length>3&&"function"==typeof a?(r--,a):void 0,o&&t(n[0],n[1],o)&&(a=r<3?void 0:a,r=1),e=Object(e);++s<r;){var l=n[s];l&&i(e,l,s,a)}return e})}}var Oi=function requireMerge(){if(Ni)return $i;Ni=1;var e=function require_baseMerge(){if(ci)return di;ci=1;var e=require_Stack(),t=require_assignMergeValue(),i=require_baseFor(),n=require_baseMergeDeep(),s=requireIsObject(),r=requireKeysIn(),a=require_safeGet();return di=function baseMerge(o,l,h,d,c){o!==l&&i(l,function(i,r){if(c||(c=new e),s(i))n(o,l,r,h,baseMerge,d,c);else{var u=d?d(a(o,r),i,r+"",o,l,c):void 0;void 0===u&&(u=i),t(o,r,u)}},r)},di}(),t=require_createAssigner()(function(t,i,n){e(t,i,n)});return $i=t}(),Li=getDefaultExportFromCjs(Oi);class Entity extends i.ICEGroup{static typeId="ice-entity-designer:Entity";hasDerivedChildren(){return!0}entityFieldsComponent=[];constructor(e){super(Entity.arrangeParam(e)),this.syncEntityNameAndFields()}static arrangeParam(e){const t=Li({entityName:"Entity Name",fields:[],style:{strokeStyle:"#334155",fillStyle:"#ffffff",radius:8,lineWidth:1.5},headerStyle:{textColor:"#0f172a",backgroundColor:"#f1f5f9",fontSize:18,fontWeight:"bold",paddingTop:12,paddingLeft:14,paddingRight:14,paddingBottom:12},fieldStyle:{textColor:"#334155",fontSize:16,fontWeight:"normal",paddingTop:9,paddingLeft:14,paddingRight:14},dividerStyle:{strokeStyle:"#cbd5e1",fillStyle:"#cbd5e1",lineWidth:1}},e,{transformable:!1});return Ke(t.entityName)&&(t.entityName="Entity Name"),Ke(t.fields)&&(t.fields=[]),t}syncEntityNameAndFields(){if(this.entityNameComponent&&(this.removeChild(this.entityNameComponent),this.entityNameComponent=null),this.headerBackgroundComponent&&(this.removeChild(this.headerBackgroundComponent),this.headerBackgroundComponent=null),this.deviderLine&&(this.removeChild(this.deviderLine),this.deviderLine=null),this.entityFieldsComponent.length&&(this.removeChildren(this.entityFieldsComponent),this.entityFieldsComponent.length=0),this.state.entityName){if(this.entityNameComponent=new i.ICEText({left:0,top:0,text:this.state.entityName,style:{strokeStyle:this.state.headerStyle.textColor,fillStyle:this.state.headerStyle.textColor,fontSize:this.state.headerStyle.fontSize,fontWeight:this.state.headerStyle.fontWeight,paddingTop:this.state.headerStyle.paddingTop,paddingLeft:this.state.headerStyle.paddingLeft,paddingRight:this.state.headerStyle.paddingRight,paddingBottom:this.state.headerStyle.paddingBottom},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1}),this.state.headerStyle.backgroundColor&&"none"!==this.state.headerStyle.backgroundColor){const e=this.state.style.lineWidth||1.5,t=e/2;this.headerBackgroundComponent=new i.ICERect({left:t,top:t,width:Math.max(this.state.width-e,0),height:Math.max(this.entityNameComponent.state.height-t,0),zIndex:(Number(this.entityNameComponent.state.zIndex)||0)-1,origin:"top-left",style:{fillStyle:this.state.headerStyle.backgroundColor,radius:Math.max((this.state.style.radius||0)-t,0),lineWidth:0},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1}),this.addChild(this.headerBackgroundComponent)}this.addChild(this.entityNameComponent),this.deviderLine=new i.ICEPolyLine({left:0,top:0,points:[[0,0],[this.state.width,0]],style:{strokeStyle:this.state.dividerStyle.strokeStyle,fillStyle:this.state.dividerStyle.fillStyle,lineWidth:this.state.dividerStyle.lineWidth},interactive:!1,linkable:!1}),this.addChild(this.deviderLine)}if(!Ke(this.state.fields)){const e=this.state.fields.length;for(let t=0;t<e;t++){const n=this.state.fields[t],s=this.fieldDisplay(n),r=new i.ICEText({left:0,top:0,text:s.text,style:{strokeStyle:this.state.fieldStyle.textColor,fillStyle:this.state.fieldStyle.textColor,fontSize:this.state.fieldStyle.fontSize,fontWeight:this.state.fieldStyle.fontWeight,paddingTop:this.state.fieldStyle.paddingTop,paddingLeft:this.state.fieldStyle.paddingLeft,paddingRight:this.state.fieldStyle.paddingRight,paddingBottom:t===e-1?12:0},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1});this.entityFieldsComponent.push(r)}this.addChildren(this.entityFieldsComponent)}}fieldDisplay(e){const t=[];e.primary&&t.push("PK"),e.foreignKey&&t.push("FK");const i=[];e.unique&&i.push("UQ"),e.autoIncrement&&i.push("AI"),!1===e.nullable&&i.push("NN");const n=t.length?`${t.join(" ")} `:"",s=e.type?`${e.type}${e.length?`(${e.length})`:""}`:"",r=i.length?` ${i.join(" ")}`:"",a=void 0!==e.default?` = ${e.default}`:"",o=e.comment?` // ${e.comment}`:"";return{text:`${n}${e.name}${s?` ${s}`:""}${r}${a}${o}`}}calcComponentParams(){let e=this.state.width,t=0,i=0,n=0;this.entityNameComponent&&(n=this.entityNameComponent.state.height,t=n,e=Math.max(e,this.entityNameComponent.state.width),t+=this.deviderLine.state.height,i=t);for(let i=0;i<this.entityFieldsComponent.length;i++){const n=this.entityFieldsComponent[i];n.state.left=0,n.state.top=t,t+=n.state.height,e=Math.max(e,n.state.width)}if(this.deviderLine&&(this.deviderLine.state.points=[[0,i],[e,i]]),this.headerBackgroundComponent){const t=this.state.style.lineWidth||1.5,i=t/2;this.headerBackgroundComponent.state.left=i,this.headerBackgroundComponent.state.top=i,this.headerBackgroundComponent.state.width=Math.max(e-t,0),this.headerBackgroundComponent.state.height=Math.max(n-i,0)}const s=e,r=Math.max(t,this.state.height);return this.state.width=s,this.state.height=r,{width:s,height:r}}toEntityObject(){const e={name:this.state.entityName,columns:{}};return this.state.fields.forEach(t=>{const i={};void 0!==t.type&&(i.type=t.type),void 0!==t.length&&(i.length=t.length),t.primary&&(i.primary=!0),t.generated&&(i.generated=!0),t.autoIncrement&&(i.generated=!0,i.strategy="increment"),!1===t.nullable&&(i.nullable=!1),t.unique&&(i.unique=!0),void 0!==t.default&&(i.default=t.default),void 0!==t.comment&&(i.comment=t.comment),t.index&&(i.index=!0),e.columns[t.name]=i}),e}setState(e){const t=!Ke(e.fields)||!Ke(e.entityName);super.setState(e),t&&this.syncEntityNameAndFields()}addField(e){const t=[...this.state.fields||[],e];return this.setFields(t),this}removeField(e){const t=(this.state.fields||[]).filter(t=>t.name!==e);return this.setFields(t),this}setFields(e){return this.setState({fields:e}),this}}class Relation extends i.ICEVisioLink{static typeId="ice-entity-designer:Relation";hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=Relation.normalizeLinks(e||{}),i=t.relationType||"one-to-one",n=Relation.composeLabel(t,i);super({title:"Relation",transformable:!1,relationType:i,referencedColumnName:"id",sourceField:"id",targetField:"id",arrow:t.arrow||Relation.defaultArrow(i),...t,label:n,style:{...t.style||{},label:{fontSize:14,fillStyle:"#334155",backgroundColor:"#ffffff",...t.labelStyle||{},...(t.style||{}).label||{}}}})}static defaultArrow(e){switch(e){case"one-to-many":return"end";case"many-to-one":return"start";default:return"none"}}static normalizeLinks(e){if(!e||!e.links)return e||{};const t={top:"T",right:"R",bottom:"B",left:"L",center:"C"},i={...e.links};return i.start&&t[i.start.position]&&(i.start={...i.start,position:t[i.start.position]}),i.end&&t[i.end.position]&&(i.end={...i.end,position:t[i.end.position]}),{...e,links:i}}static cardinalityLabel(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i={"one-to-many":["1","N"],"many-to-one":["N","1"],"many-to-many":["N","N"],"one-to-one":["1","1"]},[n,s]=i[e]||i["one-to-one"];return`${t.sourceCardinality||n} : ${t.targetCardinality||s}`}static composeLabel(e,t){return e.label?e.label:Relation.buildLabel(e,t)}static buildLabel(e,t){const i=[];e.onDelete&&i.push(`ON DELETE ${e.onDelete}`),e.onUpdate&&i.push(`ON UPDATE ${e.onUpdate}`);const n=Relation.cardinalityLabel(t,e);return i.length?`${n} (${i.join(", ")})`:n}toEntityObject(){const{title:e,relationType:t,referencedColumnName:i,sourceField:n,targetField:s,nullable:r,onDelete:a,onUpdate:o,joinTableName:l,fromKey:h,toKey:d}=this.state;let c,u,p,f,g,m;this.state.links&&this.state.links.start&&this.state.links.start.id&&(p=this.state.links.start.id,c=this.ice.findComponent(p),f=c.state.entityName),this.state.links&&this.state.links.end&&this.state.links.end.id&&(g=this.state.links.end.id,u=this.ice.findComponent(g),m=u.state.entityName);return{title:e,fromId:p,fromName:f,toId:g,toName:m,relationType:t,referencedColumnName:i,sourceField:n,targetField:s,nullable:!1!==r&&void 0,onDelete:a,onUpdate:o,joinTableName:l,fromKey:h,toKey:d}}}const zi={selection:{stroke:"#1677ff",fill:"rgba(22,119,255,0.12)",lineWidth:1,lineDash:[]},handle:{fill:"#1677ff",stroke:"#ffffff",activeFill:"#faad14",lineWidth:1},linkHook:{fill:"#52c41a",stroke:"#ffffff",lineWidth:1},slot:{fill:"#52c41a",stroke:"#ffffff",hoverFill:"#faad14",lineWidth:1},guide:{color:"#1677ff",lineWidth:1},textSelection:{color:"rgba(22,119,255,0.28)"}},Ai=zi;function designerChromeFromTheme(e){const t=e&&e.semantic||{},i=t.primary||"#0D6EFD",n=t.success||"#198754",s=t.warning||"#FFC107";return{selection:{stroke:i,fill:withAlpha(i,.12),lineWidth:1,lineDash:[]},handle:{fill:i,stroke:"#ffffff",activeFill:s,lineWidth:1},linkHook:{fill:n,stroke:"#ffffff",lineWidth:1},slot:{fill:n,stroke:"#ffffff",hoverFill:s,lineWidth:1},guide:{color:i,lineWidth:1},textSelection:{color:withAlpha(i,.28)}}}function applyDesignerChrome(e){if(!e)return e;if("function"!=typeof e.setThemePatch&&"function"!=typeof e.setChrome)return e;const t=designerChromeFromTheme("function"==typeof e.getTheme?e.getTheme():null);return"function"==typeof e.setThemePatch?(e.setThemePatch("ice-designer",{semantic:{chrome:t}}),function subscribeDesignerChrome(e){if(e.__designerChromeSubscribed||"function"!=typeof e.onThemeChange)return;e.__designerChromeSubscribed=!0,e.onThemeChange(t=>{if(t&&"theme"!==t.kind)return;const i="function"==typeof e.getTheme?e.getTheme():null;e.setThemePatch("ice-designer",{semantic:{chrome:designerChromeFromTheme(i)}})})}(e)):e.setChrome(t),e}function withAlpha(e,t){if("string"!=typeof e)return e;const i=e.trim();if("#"===i.charAt(0)){let e=i.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return i;return`rgba(${parseInt(e.slice(0,2),16)},${parseInt(e.slice(2,4),16)},${parseInt(e.slice(4,6),16)},${t})`}return 0===i.indexOf("rgb(")?i.replace("rgb(","rgba(").replace(")",`,${t})`):i}const Wi=["T","R","B","L"],qi={T:[0,-1],R:[1,0],B:[0,1],L:[-1,0]};function boxOf$1(e){if(!e||"function"!=typeof e.getMaxBoundingBox)return null;const t=e.getMaxBoundingBox(!0).getMinAndMaxPoint();return{minX:t.minX,minY:t.minY,maxX:t.maxX,maxY:t.maxY}}function centerOf(e){return[(e.minX+e.maxX)/2,(e.minY+e.maxY)/2]}function portPoint(e,t){const[i,n]=centerOf(e);return"T"===t?[i,e.minY]:"B"===t?[i,e.maxY]:"L"===t?[e.minX,n]:[e.maxX,n]}function autoPorts(e,t,i){const n=boxOf$1(e),s=boxOf$1(t);if(!n||!s)return{...i};const r=centerOf(n),a=centerOf(s);let o={...i},l=1/0;for(const e of Wi){const t=portPoint(n,e),i=qi[e],h=(a[0]-t[0])*i[0]+(a[1]-t[1])*i[1]>=0;for(const n of Wi){const a=portPoint(s,n),d=qi[n],c=(h?0:1e6)+((r[0]-a[0])*d[0]+(r[1]-a[1])*d[1]>=0?0:1e6)+((a[0]-t[0])*i[0]+(a[1]-t[1])*i[1]>=0&&(t[0]-a[0])*d[0]+(t[1]-a[1])*d[1]>=0?0:1e6)+Math.hypot(t[0]-a[0],t[1]-a[1]);c<l&&(l=c,o={sourcePort:e,targetPort:n})}}return o}function enableDesignerAlignmentGuides(e){return e&&e.alignmentGuide&&"function"==typeof e.alignmentGuide.enable?(e.alignmentGuide.enable({threshold:2}),e):e}function typeIdOf(e){const t=e&&e.constructor;return t&&"string"==typeof t.typeId?t.typeId:void 0}function isEntity(e){return typeIdOf(e)===Entity.typeId}function isRelation(e){return typeIdOf(e)===Relation.typeId}const ji="data",Fi=[{key:"display",type:"boolean"},{key:"zIndex",type:"any"},{key:"opacity",type:"number",doc:"子树不透明度(引擎 1.3 起)"},{key:"transform",type:"object"},{key:"origin",type:"string"},{key:"originX",type:"number"},{key:"originY",type:"number"},{key:"lineDash",type:"array"},{key:"lineDashOffset",type:"number"},{key:"lineDashFlow",type:"boolean"},{key:"lineDashFlowSpeed",type:"number"},{key:"lineBorder",type:"boolean"},{key:"lineBorderWidth",type:"number"},{key:"lineBorderColor",type:"string"},{key:"fill",type:"boolean"},{key:"stroke",type:"boolean"},{key:"linkable",type:"boolean"},{key:"linkEditable",type:"boolean"},{key:"transformable",type:"boolean"},{key:"animations",type:"object"}],Ri=[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"},{key:"left",type:"number"},{key:"top",type:"number"},{key:"width",type:"number"},{key:"height",type:"number"},{key:"relationType",type:"string"},{key:"referencedColumnName",type:"string"},{key:"sourceField",type:"string"},{key:"targetField",type:"string"},{key:"nullable",type:"boolean"},{key:"onDelete",type:"string"},{key:"onUpdate",type:"string"},{key:"joinTableName",type:"string"},{key:"fromKey",type:"string"},{key:"toKey",type:"string"},{key:"sourceCardinality",type:"string"},{key:"targetCardinality",type:"string"},{key:"label",type:"string"},{key:"style.label",type:"object",doc:"标签外观(引擎 2.4 起归到 style.label)"},{key:"style",type:"object"},{key:"arrow",type:"string"},{key:"lineType",type:"string"},{key:"escapeDistance",type:"number"},{key:"routeType",type:"string"},{key:"routeOffset",type:"number"},{key:"curveType",type:"string"},{key:"linkShape",type:"string",doc:"连线形态(visio/bezier)"},{key:"lineDash",type:"array"},{key:"lineWidth",type:"number"},{key:"arrowLength",type:"number"},{key:"arrowAngel",type:"number"},{key:"arrowStyle",type:"string"},{key:"startPoint",type:"array"},{key:"endPoint",type:"array"},{key:"links",type:"object",validate:function validateLinks(e,t,i){["start","end"].forEach(n=>{const s=e[n];void 0!==s&&(s&&"object"==typeof s&&!Array.isArray(s)?(void 0!==s.id&&"string"!=typeof s.id&&i.push(`${t}.${n}.id must be a string when present`),void 0!==s.position&&"string"!=typeof s.position&&i.push(`${t}.${n}.position must be a string when present`)):i.push(`${t}.${n} must be an object when present`))})}},{key:"sourceId",type:"string",doc:"连线起点宿主 id(与 links.start.id 同步)"},{key:"targetId",type:"string",doc:"连线终点宿主 id(与 links.end.id 同步)"},{key:"draggable",type:"boolean"},{key:"interactive",type:"boolean"},{key:"showMinBoundingBox",type:"boolean"},{key:"showMaxBoundingBox",type:"boolean"}],Hi=[...[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"},{key:"left",type:"number"},{key:"top",type:"number"},{key:"width",type:"number"},{key:"height",type:"number"},{key:"entityName",type:"string",required:!0},{key:"fields",type:"array",validate:function validateFields(e,t,i){e.forEach((e,n)=>{e&&"object"==typeof e&&!Array.isArray(e)?void 0!==e.name&&"string"!=typeof e.name&&i.push(`${t}[${n}].name must be a string when present`):i.push(`${t}[${n}] must be an object`)})}},{key:"style",type:"object"},{key:"headerStyle",type:"object"},{key:"fieldStyle",type:"object"},{key:"dividerStyle",type:"object"},{key:"draggable",type:"boolean"},{key:"interactive",type:"boolean"},{key:"showMinBoundingBox",type:"boolean"},{key:"showMaxBoundingBox",type:"boolean"}],...Fi],Gi=[...Ri,...Fi];function pickDocumentNode(e,t){const i={};t.forEach(t=>{const n=e?e[t.key]:void 0;void 0!==n&&(i[t.key]=n)});const n=e?e[ji]:void 0;return void 0!==n&&(i[ji]=n),i}function validateDocumentNode(e,t,i,n){e&&"object"==typeof e&&!Array.isArray(e)?i.forEach(i=>{const s=e[i.key];void 0!==s?!function typeMatches(e,t){switch(t){case void 0:case"any":return!0;case"array":return Array.isArray(e);case"object":return!!e&&"object"==typeof e&&!Array.isArray(e);case"number":return"number"==typeof e;case"boolean":return"boolean"==typeof e;default:return"string"==typeof e}}(s,i.type)?n.push(`${t}.${i.key} must be a ${i.type} when present`):i.validate&&i.validate(s,`${t}.${i.key}`,n):i.required&&n.push(`${t}.${i.key} is required`)}):n.push(`${t} must be an object`)}const Ui=[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"}];function validateProjectSnapshot(e){const t=[];return!e||"object"!=typeof e||Array.isArray(e)?{valid:!1,errors:["root must be an object"]}:(void 0!==e.schemaVersion&&"number"!=typeof e.schemaVersion&&t.push("schemaVersion must be a number when present"),void 0!==e.createTime&&"string"!=typeof e.createTime&&t.push("createTime must be a string when present"),Array.isArray(e.entities)?e.entities.forEach((e,i)=>{validateNode(e,`entities[${i}]`,Entity.typeId,t)}):t.push("entities must be an array"),void 0===e.relations||Array.isArray(e.relations)?Array.isArray(e.relations)&&e.relations.forEach((e,i)=>{validateNode(e,`relations[${i}]`,Relation.typeId,t)}):t.push("relations must be an array when present"),{valid:0===t.length,errors:t})}function validateNode(e,t,i,n){if(!e||"object"!=typeof e||Array.isArray(e))return void n.push(`${t} must be an object`);const s=void 0===e.typeId?i:e.typeId;!function isEntityTypeId(e){return e===Entity.typeId}(s)?!function isRelationTypeId(e){return e===Relation.typeId}(s)?validateDocumentNode(e,t,Ui,n):validateDocumentNode(e,t,Gi,n):validateDocumentNode(e,t,Hi,n)}function validateSchema(e){const t=[],i=e.filter(isEntity),n=e.filter(isRelation),s=new Map;return i.forEach(e=>{const i=(e.state.entityName||"").trim();if(!i)return void t.push({level:"error",message:"存在未命名的 Entity",componentId:e.state.id});s.has(i)||s.set(i,[]),s.get(i).push(e);const n=e.state.fields||[];0===n.length&&t.push({level:"warning",message:`Entity "${i}" 没有任何字段`,componentId:e.state.id});const r=new Set;n.forEach(n=>{const s=(n.name||"").trim();s?r.has(s)?t.push({level:"error",message:`Entity "${i}" 存在重复字段 "${s}"`,componentId:e.state.id}):r.add(s):t.push({level:"error",message:`Entity "${i}" 存在未命名字段`,componentId:e.state.id}),n.type||t.push({level:"warning",message:`Entity "${i}" 的字段 "${s||"(未命名)"}" 未设置类型`,componentId:e.state.id})})}),s.forEach((e,i)=>{e.length>1&&t.push({level:"error",message:`存在重复的 Entity 名称 "${i}"`})}),n.forEach(e=>{const n=e.state.links||{},s=n.start&&n.start.id,r=n.end&&n.end.id,a=e.state.relationType;if(!s||!r)return void t.push({level:"error",message:"存在没有完整起点/终点的 Relation",componentId:e.state.id});const o=i.some(e=>e.state.id===s),l=i.some(e=>e.state.id===r);o&&l||t.push({level:"error",message:"Relation 连接到了不存在的 Entity",componentId:e.state.id}),a?"many-to-many"!==a||e.state.joinTableName||t.push({level:"warning",message:"many-to-many 关系建议设置 joinTableName",componentId:e.state.id}):t.push({level:"error",message:"Relation 未设置关系类型",componentId:e.state.id})}),t}function toWords(e){return function convertToString(e){const t=e||"";return"string"==typeof t?t:String(t)}(e).match(/[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g)||[]}function camelCase(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return function toCamelCase(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i="";for(let n=0,s=e.length;n<s;n++){let s=e[n].toLowerCase();(t||0!==n)&&(s=s.substr(0,1).toUpperCase()+s.substr(1)),i+=s}return i}(toWords(e),t)}var Vi=[],Ki=[],Yi={},Xi={},Ji={};function sanitizeRule(e){return"string"==typeof e?new RegExp("^"+e+"$","i"):e}function restoreCase(e,t){return e===t?t:e===e.toLowerCase()?t.toLowerCase():e===e.toUpperCase()?t.toUpperCase():e[0]===e[0].toUpperCase()?t.charAt(0).toUpperCase()+t.substr(1).toLowerCase():t.toLowerCase()}function replace(e,t){return e.replace(t[0],function(i,n){var s=function interpolate(e,t){return e.replace(/\$(\d{1,2})/g,function(e,i){return t[i]||""})}(t[1],arguments);return restoreCase(""===i?e[n-1]:i,s)})}function sanitizeWord(e,t,i){if(!e.length||Yi.hasOwnProperty(e))return t;for(var n=i.length;n--;){var s=i[n];if(s[0].test(t))return replace(t,s)}return t}function replaceWord(e,t,i){return function(n){var s=n.toLowerCase();return t.hasOwnProperty(s)?restoreCase(n,s):e.hasOwnProperty(s)?restoreCase(n,e[s]):sanitizeWord(s,n,i)}}function checkWord(e,t,i){return function(n){var s=n.toLowerCase();return!!t.hasOwnProperty(s)||!e.hasOwnProperty(s)&&sanitizeWord(s,s,i)===s}}function pluralize(e,t,i){return(i?t+" ":"")+(1===t?pluralize.singular(e):pluralize.plural(e))}pluralize.plural=replaceWord(Ji,Xi,Vi),pluralize.isPlural=checkWord(Ji,Xi,Vi),pluralize.singular=replaceWord(Xi,Ji,Ki),pluralize.isSingular=checkWord(Xi,Ji,Ki),pluralize.addPluralRule=function(e,t){Vi.push([sanitizeRule(e),t])},pluralize.addSingularRule=function(e,t){Ki.push([sanitizeRule(e),t])},pluralize.addUncountableRule=function(e){"string"!=typeof e?(pluralize.addPluralRule(e,"$0"),pluralize.addSingularRule(e,"$0")):Yi[e.toLowerCase()]=!0},pluralize.addIrregularRule=function(e,t){t=t.toLowerCase(),e=e.toLowerCase(),Ji[e]=t,Xi[t]=e},[["I","we"],["me","us"],["he","they"],["she","they"],["them","them"],["myself","ourselves"],["yourself","yourselves"],["itself","themselves"],["herself","themselves"],["himself","themselves"],["themself","themselves"],["is","are"],["was","were"],["has","have"],["this","these"],["that","those"],["echo","echoes"],["dingo","dingoes"],["volcano","volcanoes"],["tornado","tornadoes"],["torpedo","torpedoes"],["genus","genera"],["viscus","viscera"],["stigma","stigmata"],["stoma","stomata"],["dogma","dogmata"],["lemma","lemmata"],["schema","schemata"],["anathema","anathemata"],["ox","oxen"],["axe","axes"],["die","dice"],["yes","yeses"],["foot","feet"],["eave","eaves"],["goose","geese"],["tooth","teeth"],["quiz","quizzes"],["human","humans"],["proof","proofs"],["carve","carves"],["valve","valves"],["looey","looies"],["thief","thieves"],["groove","grooves"],["pickaxe","pickaxes"],["passerby","passersby"]].forEach(function(e){return pluralize.addIrregularRule(e[0],e[1])}),[[/s?$/i,"s"],[/[^\u0000-\u007F]$/i,"$0"],[/([^aeiou]ese)$/i,"$1"],[/(ax|test)is$/i,"$1es"],[/(alias|[^aou]us|t[lm]as|gas|ris)$/i,"$1es"],[/(e[mn]u)s?$/i,"$1s"],[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i,"$1"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1i"],[/(alumn|alg|vertebr)(?:a|ae)$/i,"$1ae"],[/(seraph|cherub)(?:im)?$/i,"$1im"],[/(her|at|gr)o$/i,"$1oes"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,"$1a"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,"$1a"],[/sis$/i,"ses"],[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([^ch][ieo][ln])ey$/i,"$1ies"],[/(x|ch|ss|sh|zz)$/i,"$1es"],[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i,"$1ices"],[/\b((?:tit)?m|l)(?:ice|ouse)$/i,"$1ice"],[/(pe)(?:rson|ople)$/i,"$1ople"],[/(child)(?:ren)?$/i,"$1ren"],[/eaux$/i,"$0"],[/m[ae]n$/i,"men"],["thou","you"]].forEach(function(e){return pluralize.addPluralRule(e[0],e[1])}),[[/s$/i,""],[/(ss)$/i,"$1"],[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i,"$1fe"],[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i,"$1f"],[/ies$/i,"y"],[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i,"$1ie"],[/\b(mon|smil)ies$/i,"$1ey"],[/\b((?:tit)?m|l)ice$/i,"$1ouse"],[/(seraph|cherub)im$/i,"$1"],[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,"$1"],[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,"$1sis"],[/(movie|twelve|abuse|e[mn]u)s$/i,"$1"],[/(test)(?:is|es)$/i,"$1is"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1us"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,"$1um"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,"$1on"],[/(alumn|alg|vertebr)ae$/i,"$1a"],[/(cod|mur|sil|vert|ind)ices$/i,"$1ex"],[/(matr|append)ices$/i,"$1ix"],[/(pe)(rson|ople)$/i,"$1rson"],[/(child)ren$/i,"$1"],[/(eau)x?$/i,"$1"],[/men$/i,"man"]].forEach(function(e){return pluralize.addSingularRule(e[0],e[1])}),["adulthood","advice","agenda","aid","aircraft","alcohol","ammo","analytics","anime","athletics","audio","bison","blood","bream","buffalo","butter","carp","cash","chassis","chess","clothing","cod","commerce","cooperation","corps","debris","diabetes","digestion","elk","energy","equipment","excretion","expertise","firmware","flounder","fun","gallows","garbage","graffiti","hardware","headquarters","health","herpes","highjinks","homework","housework","information","jeans","justice","kudos","labour","literature","machinery","mackerel","mail","media","mews","moose","music","mud","manga","news","only","personnel","pike","plankton","pliers","police","pollution","premises","rain","research","rice","salmon","scissors","series","sewage","shambles","shrimp","software","species","staff","swine","tennis","traffic","transportation","trout","tuna","wealth","welfare","whiting","wildebeest","wildlife","you",/pok[eé]mon$/i,/[^aeiou]ese$/i,/deer$/i,/fish$/i,/measles$/i,/o[iu]s$/i,/pox$/i,/sheep$/i].forEach(pluralize.addUncountableRule);const Qi={number:"int",int:"int",integer:"int",smallint:"smallint",bigint:"bigint",float:"float",double:"double",real:"real",decimal:"decimal",numeric:"numeric",string:"varchar",varchar:"varchar",char:"char",text:"text",boolean:"boolean",bool:"boolean",date:"date",datetime:"datetime",timestamp:"timestamp",time:"time",json:"json",jsonb:"jsonb",uuid:"uuid",enum:"enum",blob:"blob",binary:"blob","simple-array":"simple-array","simple-json":"simple-json"},Zi=["varchar","char","nvarchar","nchar","text","uuid"];function normalizeColumn(e){const t={},i=function mapColumnType(e){if(null==e||""===e)return;const t=String(e).toLowerCase();return Qi[t]||String(e)}(e.type);if(void 0!==i&&(t.type=i),void 0!==e.length&&null!==e.length&&""!==e.length){const n=String(e.length).trim();if("decimal"===i||"numeric"===i){const[e,i]=n.split(",").map(e=>e.trim());e&&(t.precision=Number(e)),i&&(t.scale=Number(i))}else i&&Zi.indexOf(i)>=0&&(t.length=e.length)}return e.primary&&(t.primary=!0),e.generated&&(t.generated=!0),e.autoIncrement&&(t.generated=!0,t.strategy="increment"),void 0!==e.strategy&&(t.strategy=e.strategy),!1===e.nullable&&(t.nullable=!1),e.unique&&(t.unique=!0),void 0!==e.default&&(t.default=e.default),void 0!==e.comment&&(t.comment=e.comment),e.index&&(t.index=!0),t}function normalizeColumns(e){const t={};return Object.keys(e||{}).forEach(i=>{t[i]=normalizeColumn(e[i])}),t}function buildJoinColumn(e,t){return{name:e||t||"id",referencedColumnName:t||"id"}}function toSchemaObject(e){const t=[...e],i=[],n={};for(let e=0;e<t.length;e++){const s=t[e];if(isRelation(s))i.push(s);else if(isEntity(s)){const e=s.toEntityObject();e.columns=normalizeColumns(e.columns),n[s.state.id]=e}}for(let e=0;e<i.length;e++){const t=i[e],{fromId:s,fromName:r,toId:a,toName:o,relationType:l,referencedColumnName:h,sourceField:d,targetField:c,nullable:u,onDelete:p,onUpdate:f,joinTableName:g,fromKey:m,toKey:y}=t.toEntityObject(),_=n[s],b=n[a];if(!_||!b)continue;_.relations||(_.relations={}),b.relations||(b.relations={});const v=m||camelCase(o),k=y||camelCase(r),w={};!1===u&&(w.nullable=!1),p&&(w.onDelete=p),f&&(w.onUpdate=f),"one-to-one"===l?(b.relations[k]={type:l,target:r,joinColumn:buildJoinColumn(c||h,d||h),...w},_.relations[v]={type:l,target:o,inverseSide:k}):"one-to-many"===l?(_.relations[v]={type:l,target:o,inverseSide:k},b.relations[k]={type:"many-to-one",target:r,joinColumn:buildJoinColumn(c||h,d||h),...w}):"many-to-one"===l?(_.relations[v]={type:l,target:o,joinColumn:buildJoinColumn(d||h,c||h),...w},b.relations[k]={type:"one-to-many",target:r,inverseSide:v}):"many-to-many"===l&&(_.relations[`${pluralize(v)}`]={type:l,target:o,joinTable:!g||{name:g}},b.relations[`${pluralize(k)}`]={type:l,target:r,inverseSide:`${pluralize(v)}`})}const s=[];for(const e in n)s.push(n[e]);return s}function toSchemaString(e){return JSON.stringify(toSchemaObject(e))}function registerIEDType(e,t){e.registerType(t.typeId,t)}function createEmptyPath$1(e){const t=e.path2D&&e.path2D.constructor;return t?new t:null}class FlowDiamond extends i.ICEPath{static typeId="ice-entity-designer:FlowDiamond";createPathObject(){const e=this.state.width,t=this.state.height,i=0-this.state.localOrigin[0],n=0-this.state.localOrigin[1],s=createEmptyPath$1(this);return s?(s.moveTo(i+e/2,n),s.lineTo(i+e,n+t/2),s.lineTo(i+e/2,n+t),s.lineTo(i,n+t/2),s.closePath(),this.path2D=s,this.path2D):this.path2D}}class FlowParallelogram extends i.ICEPath{static typeId="ice-entity-designer:FlowParallelogram";createPathObject(){const e=this.state.width,t=this.state.height,i=Math.min(28,.18*e),n=0-this.state.localOrigin[0],s=0-this.state.localOrigin[1],r=createEmptyPath$1(this);return r?(r.moveTo(n+i,s),r.lineTo(n+e,s),r.lineTo(n+e-i,s+t),r.lineTo(n,s+t),r.closePath(),this.path2D=r,this.path2D):this.path2D}}function createEmptyPath(e){const t=e.path2D&&e.path2D.constructor;return t?new t:null}function localBox(e){return{w:e.state.width,h:e.state.height,x:0-e.state.localOrigin[0],y:0-e.state.localOrigin[1]}}class BpmnEventShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnEventShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=i+e/2,a=n+t/2,o=Math.min(e,t)/2,l=this.state.eventKind||"start";s.arc(r,a,o,0,2*Math.PI),"intermediate"!==l&&"end"!==l||(s.moveTo(r+.84*o,a),s.arc(r,a,.84*o,0,2*Math.PI));const h=this.state.trigger||"none";if("message"===h){const e=1.1*o,t=.78*o;s.moveTo(r-e/2,a-t/2),s.lineTo(r+e/2,a-t/2),s.lineTo(r+e/2,a+t/2),s.lineTo(r-e/2,a+t/2),s.closePath(),s.moveTo(r-e/2,a-t/2),s.lineTo(r,a+.08*t),s.lineTo(r+e/2,a-t/2)}else if("timer"===h){const e=.52*o;s.moveTo(r+e,a),s.arc(r,a,e,0,2*Math.PI),s.moveTo(r,a),s.lineTo(r,a-.62*e),s.moveTo(r,a),s.lineTo(r+.5*e,a)}else"error"===h?(s.moveTo(r+.34*o,a-.62*o),s.lineTo(r-.42*o,a+.06*o),s.lineTo(r-.02*o,a+.06*o),s.lineTo(r-.3*o,a+.66*o),s.lineTo(r+.44*o,a-.02*o),s.lineTo(r+.04*o,a-.02*o),s.closePath()):"terminate"===h&&(s.moveTo(r+.5*o,a),s.arc(r,a,.5*o,0,2*Math.PI));return this.path2D=s,this.path2D}}class BpmnGatewayShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnGatewayShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=i+e/2,a=n+t/2,o=e/2,l=t/2;s.moveTo(r,a-l),s.lineTo(r+o,a),s.lineTo(r,a+l),s.lineTo(r-o,a),s.closePath();const h=this.state.gatewayType||"exclusive",d=.42*Math.min(o,l);if("exclusive"===h)s.moveTo(r-d,a-d),s.lineTo(r+d,a+d),s.moveTo(r+d,a-d),s.lineTo(r-d,a+d);else if("parallel"===h)s.moveTo(r-d,a),s.lineTo(r+d,a),s.moveTo(r,a-d),s.lineTo(r,a+d);else if("inclusive"===h)s.moveTo(r+d,a),s.arc(r,a,d,0,2*Math.PI);else if("event"===h){const e=1.15*d;for(let t=0;t<5;t++){const i=-Math.PI/2+t*Math.PI*2/5,n=r+Math.cos(i)*e,o=a+Math.sin(i)*e;0===t?s.moveTo(n,o):s.lineTo(n,o)}s.closePath()}return this.path2D=s,this.path2D}}class BpmnTaskIcon extends i.ICEPath{static typeId="ice-entity-designer:BpmnTaskIcon";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=i+e/2,a=n+t/2,o=Math.min(e,t)/2,l=this.state.taskType||"none";if("user"===l)s.moveTo(r,a-o),s.arc(r,a-.35*o,.34*o,0,2*Math.PI),s.moveTo(r-.62*o,a+.72*o),s.arc(r,a+.72*o,.62*o,Math.PI,0);else if("service"===l){const e=8;for(let t=0;t<e;t++){const i=t*Math.PI*2/e,n=r+Math.cos(i)*o*.55,l=a+Math.sin(i)*o*.55,h=r+Math.cos(i)*o,d=a+Math.sin(i)*o;s.moveTo(n,l),s.lineTo(h,d)}s.moveTo(r+.34*o,a),s.arc(r,a,.34*o,0,2*Math.PI)}else"script"===l?(s.moveTo(r-.7*o,a-.85*o),s.lineTo(r+.7*o,a-.85*o),s.lineTo(r+.7*o,a+.5*o),s.moveTo(r-.7*o,a-.85*o),s.lineTo(r-.7*o,a+.5*o),s.moveTo(r-.7*o,a+.6*o),s.lineTo(r-.25*o,a+.85*o),s.lineTo(r+.25*o,a+.6*o),s.lineTo(r+.7*o,a+.85*o)):"send"===l?(s.moveTo(r-.85*o,a-.55*o),s.lineTo(r+.85*o,a-.55*o),s.lineTo(r+.85*o,a+.55*o),s.lineTo(r-.85*o,a+.55*o),s.closePath(),s.moveTo(r-.85*o,a-.55*o),s.lineTo(r,a+.12*o),s.lineTo(r+.85*o,a-.55*o)):"receive"===l?(s.moveTo(r-.85*o,a-.55*o),s.lineTo(r+.85*o,a-.55*o),s.lineTo(r+.85*o,a+.55*o),s.lineTo(r-.85*o,a+.55*o),s.closePath()):"manual"===l&&(s.moveTo(r-.7*o,a+.6*o),s.lineTo(r-.45*o,a-.5*o),s.lineTo(r+.45*o,a-.5*o),s.lineTo(r+.7*o,a+.6*o),s.closePath());return this.path2D=s,this.path2D}}class BpmnSubprocessMarker extends i.ICEPath{static typeId="ice-entity-designer:BpmnSubprocessMarker";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);return s?(s.moveTo(i,n),s.lineTo(i+e,n),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),s.moveTo(i+e/2,n+.22*t),s.lineTo(i+e/2,n+.78*t),s.moveTo(i+.22*e,n+t/2),s.lineTo(i+.78*e,n+t/2),this.path2D=s,this.path2D):this.path2D}}class BpmnDataObjectShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnDataObjectShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=Math.min(14,.22*e,.32*t);return s.moveTo(i,n),s.lineTo(i+e-r,n),s.lineTo(i+e,n+r),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),s.moveTo(i+e-r,n),s.lineTo(i+e-r,n+r),s.lineTo(i+e,n+r),this.path2D=s,this.path2D}}class BpmnAnnotationShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnAnnotationShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=Math.min(16,.3*e);return s.moveTo(i,n),s.lineTo(i+e,n),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),s.moveTo(i+r,n),s.lineTo(i,n),s.lineTo(i,n+t),s.lineTo(i+r,n+t),this.path2D=s,this.path2D}}class BpmnLaneShape extends i.ICEPath{static typeId="ice-entity-designer:BpmnLaneShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);if(!s)return this.path2D;const r=Math.min(this.state.bandSize||30,.4*e,.4*t);return s.moveTo(i,n),s.lineTo(i+e,n),s.lineTo(i+e,n+t),s.lineTo(i,n+t),s.closePath(),"top"===(this.state.band||"left")?(s.moveTo(i,n+r),s.lineTo(i+e,n+r)):(s.moveTo(i+r,n),s.lineTo(i+r,n+t)),this.path2D=s,this.path2D}}class BpmnFlowMarker extends i.ICEPath{static typeId="ice-entity-designer:BpmnFlowMarker";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),s=createEmptyPath(this);return s?("default"===(this.state.markerType||"conditional")?(s.moveTo(i+.2*e,n+.8*t),s.lineTo(i+.8*e,n+.2*t)):(s.moveTo(i+e/2,n),s.lineTo(i+e,n+t/2),s.lineTo(i+e/2,n+t),s.lineTo(i,n+t/2),s.closePath()),this.path2D=s,this.path2D):this.path2D}}const en={terminator:{label:"开始 / 结束",width:180,height:60,fill:"#dcfce7",stroke:"#16a34a",radius:30,shape:"rect"},process:{label:"处理",width:220,height:80,fill:"#e0e7ff",stroke:"#4f46e5",radius:10,shape:"rect"},decision:{label:"判定",width:200,height:120,fill:"#fef3c7",stroke:"#d97706",shape:"diamond"},io:{label:"输入 / 输出",width:220,height:80,fill:"#e0f2fe",stroke:"#0284c7",shape:"parallelogram"},bpmnEvent:{label:"事件",width:56,height:56,fill:"#ffffff",stroke:"#475569",shape:"event",lineWidth:1.4,eventKind:"start",trigger:"none",labelPlacement:"top-left"},bpmnTask:{label:"任务",width:180,height:90,fill:"#ffffff",stroke:"#64748b",radius:10,shape:"rect",taskType:"none",labelPlacement:"center"},bpmnGateway:{label:"网关",width:70,height:70,fill:"#ffffff",stroke:"#64748b",shape:"gateway",gatewayType:"exclusive",labelPlacement:"top-left"},bpmnSubprocess:{label:"子流程",width:200,height:110,fill:"#ffffff",stroke:"#64748b",radius:10,shape:"rect",labelPlacement:"center"},bpmnDataObject:{label:"数据对象",width:130,height:80,fill:"#ffffff",stroke:"#64748b",shape:"dataObject",labelPlacement:"center"},bpmnAnnotation:{label:"注释",width:200,height:80,fill:"#ffffff",stroke:"#64748b",shape:"annotation",lineDash:[],labelPlacement:"center"},bpmnPool:{label:"池",width:900,height:260,fill:"#f8fafc",stroke:"#94a3b8",shape:"lane",band:"top",bandSize:32,labelPlacement:"top-left"},bpmnLane:{label:"泳道",width:900,height:130,fill:"#ffffff",stroke:"#cbd5e1",shape:"lane",band:"left",bandSize:32,labelPlacement:"top-left",transparent:!0}},tn=-3e4,nn=-2e4,sn=["bpmnPool","bpmnLane","bpmnAnnotation","bpmnDataObject"],rn={rect:i.ICERect,diamond:FlowDiamond,parallelogram:FlowParallelogram,event:BpmnEventShape,gateway:BpmnGatewayShape,dataObject:BpmnDataObjectShape,annotation:BpmnAnnotationShape,lane:BpmnLaneShape},an="#0f172a";class FlowNode extends i.ICEGroup{static typeId="ice-entity-designer:FlowNode";shapeComponent=null;labelComponent=null;decorationComponents=[];hasDerivedChildren(){return!0}getSerializableChildren(){const e=[this.shapeComponent,this.labelComponent,...this.decorationComponents||[]];return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=en[e.kind]?e.kind:"process",i=en[t];super({kind:t,title:i.label,fillColor:i.fill,strokeColor:i.stroke,textColor:an,fontSize:14,width:i.width,height:i.height,fill:!1,stroke:!1,draggable:!0,interactive:!0,transformable:!1,linkable:-1===sn.indexOf(t),...e}),this.__buildShape()}__buildShape(){this.shapeComponent&&this.removeChild(this.shapeComponent),this.labelComponent&&this.removeChild(this.labelComponent),this.decorationComponents&&this.decorationComponents.length&&(this.removeChildren(this.decorationComponents),this.decorationComponents.length=0);const e=en[this.state.kind]||en.process,t=rn[e.shape]||i.ICERect;this.shapeComponent=new t({left:0,top:0,width:this.state.width,height:this.state.height,radius:e.radius||0,lineWidth:e.lineWidth||1.5,lineDash:this.state.lineDash||e.lineDash||[],eventKind:this.state.eventKind||e.eventKind,trigger:this.state.trigger||e.trigger,gatewayType:this.state.gatewayType||e.gatewayType,taskType:this.state.taskType||e.taskType,band:e.band,bandSize:e.bandSize,fill:!e.transparent,interactive:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fillStyle:this.state.fillColor||e.fill,strokeStyle:this.state.strokeColor||e.stroke,lineWidth:e.lineWidth||1.5}}),this.__buildDecorations(e);const n="top-left"===e.labelPlacement,s="lane"===e.shape&&"left"===e.band,r=s?Math.min(Number(e.bandSize)||30,.4*this.state.width,.4*this.state.height):0,a=s?Math.max(this.state.height-8,r):0;this.labelComponent=new i.ICEText(s?{left:r/2-a/2,top:this.state.height/2-r/2,width:a,height:r,text:String(this.state.title||""),wrap:!0,maxLines:1,ellipsis:"…",transform:{rotate:-90},interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fontSize:this.state.fontSize||13,fillStyle:this.state.textColor||an,textAlign:"center",textBaseline:"middle",fontWeight:"bold"}}:{left:n?10:0,top:n?"top"===e.band?18:16:0,width:n?Math.max(this.state.width-20,20):this.state.width,height:n?18:this.state.height,text:String(this.state.title||""),wrap:!n,maxLines:2,interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fontSize:this.state.fontSize||(n?13:14),fillStyle:this.state.textColor||an,textAlign:n?"left":"center",textBaseline:"middle",fontWeight:n?"bold":"normal",paddingLeft:n?0:12,paddingRight:n?0:12}}),this.addChild(this.shapeComponent),this.addChild(this.labelComponent)}__buildDecorations(e){const t=this.state.kind,i=[],n=this.state.strokeColor||e.stroke;if("bpmnTask"===t||"bpmnSubprocess"===t){const t=this.state.taskType||e.taskType||"none";"none"!==t&&i.push(new BpmnTaskIcon({left:8,top:8,width:14,height:14,stroke:!0,fill:!1,interactive:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,taskType:t,style:{strokeStyle:n,lineWidth:1.4}}))}"bpmnSubprocess"===t&&i.push(new BpmnSubprocessMarker({left:(this.state.width-14)/2,top:this.state.height-20,width:14,height:14,stroke:!0,fill:!1,interactive:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{strokeStyle:n,lineWidth:1.4}})),i.length&&(i.forEach(e=>this.addChild(e)),this.decorationComponents=i)}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=void 0!==e.kind||void 0!==e.fillColor||void 0!==e.strokeColor||void 0!==e.textColor||void 0!==e.fontSize||void 0!==e.eventKind||void 0!==e.trigger||void 0!==e.gatewayType||void 0!==e.taskType||void 0!==e.width||void 0!==e.height;return this.setState(e),t?this.__buildShape():this.labelComponent&&this.labelComponent.setState({text:String(this.state.title||"")}),this.dirty=!0,this}}class FlowEdge extends i.ICEVisioLink{static typeId="ice-entity-designer:FlowEdge";hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super({title:"Edge",arrow:"end",linkShape:"visio",lineType:"solid",linkable:!1,draggable:!1,interactive:!0,transformable:!1,startPoint:[0,0],endPoint:[10,10],label:"",...e,style:{strokeStyle:"#64748b",fillStyle:"#64748b",lineWidth:1.4,...e.style||{},label:{fontSize:12,fillStyle:"#334155",backgroundColor:"#ffffff",paddingLeft:4,paddingRight:4,...e.labelStyle||{},...(e.style||{}).label||{}}}}),this.applyPatch({flowType:this.state.flowType,condition:this.state.condition,isDefault:this.state.isDefault})}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e&&e.labelStyle&&(e={...e,style:{...this.state.style||{},...e.style||{},label:{...e.labelStyle||{},...(e.style||{}).label||{}}}},delete e.labelStyle);const t={...this.state,...e},i=t.flowType||"sequence",n="message"===i?{lineDash:[7,4],arrowStyle:"hollow",lineWidth:t.lineWidth||1.4}:"association"===i?{lineDash:[2,3],arrow:"none",arrowStyle:"hollow",lineWidth:t.lineWidth||1.2}:{arrow:t.arrow||"end",arrowStyle:"filled",lineDash:[],lineWidth:t.lineWidth||1.4};return this.setState({...e,...n}),this.dirty=!0,this}}class DesignerHighlightLayer{boxes=(()=>new Map)();options={color:"",lineWidth:3,padding:4,radius:6,fill:!1};constructor(e){this.ice=e}get ids(){return Array.from(this.boxes.keys())}set(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.options={...this.options,...t};const i=new Set(e.map(e=>e.id));Array.from(this.boxes.keys()).forEach(e=>{i.has(e)||this.__remove(e)}),e.forEach(e=>this.__place(e)),this.boxes.size||this.__destroy(),this.ice&&"function"==typeof this.ice.requestRepaint&&this.ice.requestRepaint()}clear(){this.boxes.forEach(e=>{this.ice&&"function"==typeof this.ice.removeTool&&this.ice.removeTool(e)}),this.boxes.clear(),this.ice&&"function"==typeof this.ice.requestRepaint&&this.ice.requestRepaint()}__place(e){const t=Number(this.options.padding)||0,n=e.minX-t,s=e.minY-t,r=Math.max(1,e.maxX-e.minX+2*t),a=Math.max(1,e.maxY-e.minY+2*t);let o=this.boxes.get(e.id);if(!o)return o=new i.ICERect({left:n,top:s,width:r,height:a,radius:this.options.radius,fill:!!this.options.fill,stroke:!0,interactive:!1,draggable:!1,transformable:!1,linkable:!1,style:{fillStyle:this.options.fill||"transparent",strokeStyle:this.__color(),lineWidth:this.options.lineWidth}}),o.__iceDesignerHighlight=!0,this.boxes.set(e.id,o),void this.ice.addTool(o);o.setState({left:n,top:s,width:r,height:a,radius:this.options.radius,fill:!!this.options.fill,style:{fillStyle:this.options.fill||"transparent",strokeStyle:this.__color(),lineWidth:this.options.lineWidth}})}__remove(e){const t=this.boxes.get(e);t&&(this.boxes.delete(e),this.ice&&"function"==typeof this.ice.removeTool&&this.ice.removeTool(t))}__destroy(){this.boxes.forEach(e=>{this.ice&&"function"==typeof this.ice.removeTool&&this.ice.removeTool(e)}),this.boxes.clear()}__color(){if(this.options.color)return this.options.color;try{const e=this.ice&&"function"==typeof this.ice.getTheme?this.ice.getTheme():null;return e&&e.semantic&&e.semantic.primary||i.DEFAULT_THEME.semantic.primary}catch{return i.DEFAULT_THEME.semantic.primary}}}function validateFlowSnapshot(e){const t=[];return!e||"object"!=typeof e||Array.isArray(e)?{valid:!1,errors:["root must be an object"]}:void 0!==e.scene?(!e.scene||"object"!=typeof e.scene||Array.isArray(e.scene)?t.push("scene must be an object when present"):Array.isArray(e.scene.childNodes)||t.push("scene.childNodes must be an array"),{valid:0===t.length,errors:t}):(Array.isArray(e.nodes)?e.nodes.forEach((e,i)=>{const n=`nodes[${i}]`;e&&"object"==typeof e&&!Array.isArray(e)?("string"!=typeof e.id&&t.push(`${n}.id must be a string`),void 0!==e.kind&&"string"!=typeof e.kind&&t.push(`${n}.kind must be a string when present`),void 0!==e.left&&"number"!=typeof e.left&&t.push(`${n}.left must be a number when present`),void 0!==e.top&&"number"!=typeof e.top&&t.push(`${n}.top 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)?Array.isArray(e.edges)&&e.edges.forEach((e,i)=>{const n=`edges[${i}]`;e&&"object"==typeof e&&!Array.isArray(e)?(["sourceId","targetId"].forEach(i=>{void 0!==e[i]&&null!==e[i]&&"string"!=typeof e[i]&&t.push(`${n}.${i} must be a string or null when present`)}),void 0!==e.label&&"string"!=typeof e.label&&t.push(`${n}.label must be a string when present`),void 0!==e.linkShape&&"visio"!==e.linkShape&&"bezier"!==e.linkShape&&t.push(`${n}.linkShape must be "visio" or "bezier" when present`)):t.push(`${n} must be an object`)}):t.push("edges must be an array when present"),{valid:0===t.length,errors:t})}class FlowDesigner{selectedId=null;__undoStack=[];__redoStack=[];__historyEnabled=!0;__maxHistory=100;__listeners=[];__mousedownHandler=e=>this.__handleMouseDown(e);__moveSession=!1;__moveEmitQueued=!1;__highlightOptions={};__beforeMoveHandler=()=>this.__onBeforeMove();__afterMoveHandler=()=>this.__onAfterMove();__mouseupHandler=()=>this.__endMoveSession();constructor(e){applyDesignerChrome(e),enableDesignerAlignmentGuides(e),this.ice=e,this.__highlight=new DesignerHighlightLayer(this.ice),registerIEDType(this.ice,FlowNode),registerIEDType(this.ice,FlowEdge),this.ice.evtBus.on("mousedown",this.__mousedownHandler,this),this.ice.evtBus.on("mouseup",this.__mouseupHandler,this)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===FlowNode.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===FlowEdge.typeId)}__flatten(){const e=[],walk=t=>{t.forEach(t=>{e.push(t),t.childNodes&&t.childNodes.length&&walk(t.childNodes)})};return walk(this.ice.childNodes||[]),e}get selected(){return this.selectedId?this.ice.findComponent(this.selectedId):null}setHighlights(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Object.keys(t).length&&(this.__highlightOptions={...this.__highlightOptions,...t});const i=(null==e?[]:Array.isArray(e)?e:[e]).map(e=>this.__highlightEntry(e)).filter(e=>!!e);return this.__highlight.set(i,this.__highlightOptions),i.length}highlight(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=null==e?null:this.__highlightEntry(e);return!(null!=e&&!i)&&(this.setHighlights(i?[i.id]:null,t),!!i)}clearHighlights(){this.setHighlights(null)}getHighlightedIds(){return this.__highlight.ids}__highlightEntry(e){const t=String(e),i=this.nodes.find(e=>String(e.state?.id)===t)||this.nodes.find(e=>String(e.state?.tag)===t);if(!i)return null;const n=i.getMinBoundingBox(!0).getMinAndMaxPoint();return{id:String(i.state.id),minX:n.minX,minY:n.minY,maxX:n.maxX,maxY:n.maxY}}__syncHighlights(){const e=this.__highlight.ids;e.length&&this.setHighlights(e)}subscribe(e){return"function"!=typeof e?()=>{}:(this.__listeners.push(e),()=>{const t=this.__listeners.indexOf(e);-1!==t&&this.__listeners.splice(t,1)})}__emitChange(){if(this.__syncHighlights(),!this.__listeners.length)return;const e=this.serialize();this.__listeners.slice().forEach(t=>t(e,this))}__attachNodeListeners(e){e&&"function"==typeof e.on&&(e.on(i.ICE_EVENT_NAME_CONSTS.BEFORE_MOVE,this.__beforeMoveHandler,this),e.on(i.ICE_EVENT_NAME_CONSTS.AFTER_MOVE,this.__afterMoveHandler,this))}__detachNodeListeners(e){e&&"function"==typeof e.off&&(e.off(i.ICE_EVENT_NAME_CONSTS.BEFORE_MOVE,this.__beforeMoveHandler,this),e.off(i.ICE_EVENT_NAME_CONSTS.AFTER_MOVE,this.__afterMoveHandler,this))}__onBeforeMove(){this.__moveSession||(this.__moveSession=!0,this.__captureHistory())}__onAfterMove(){if(this.__moveEmitQueued)return;this.__moveEmitQueued=!0;const flush=()=>{this.__moveEmitQueued=!1,this.__emitChange()};"function"==typeof requestAnimationFrame?requestAnimationFrame(flush):setTimeout(flush,16)}__endMoveSession(){this.__moveSession=!1}select(e){return this.selectedId=e,this.__emitChange(),this}__defaultPlacement(e,t){const i=this.nodes;if(!i.length)return{left:120,top:120};let n=1/0,s=-1/0;i.forEach(e=>{const t=e.getMinBoundingBox(!0);n=Math.min(n,t.tl[0]),s=Math.max(s,t.br[1])});const r=i.length;return{left:n+r%4*280,top:s+80+Math.floor(r/4)*(t+90)}}createNode(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new FlowNode({kind:e,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}__slotPoint(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}createEdge(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("连接两端必须是已存在的节点");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"B",targetPort:"T"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=new FlowEdge({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},startPoint:this.__slotPoint(t,s),endPoint:this.__slotPoint(i,r),label:e.label||"",linkShape:e.linkShape||"visio",flowType:e.flowType||"sequence",condition:e.condition||"",isDefault:!!e.isDefault,style:{...e.style||{},...e.labelStyle?{label:e.labelStyle}:{}}});return this.ice.addChild(a),this.selectedId=a.state.id,this.__emitChange(),a}updateNode(e,t){const i=this.ice.findComponent(e);return i&&i.constructor.typeId===FlowNode.typeId&&(this.__captureHistory(),i.applyPatch(t),this.__emitChange()),i}updateEdge(e,t){const i=this.ice.findComponent(e);return i&&i.constructor.typeId===FlowEdge.typeId&&(this.__captureHistory(),"function"==typeof i.applyPatch?i.applyPatch(t):(i.setState(t),i.dirty=!0),this.__emitChange()),i}remove(e){const t=this.ice.findComponent(e);t&&(this.__captureHistory(),-1!==this.nodes.indexOf(t)&&(this.__detachNodeListeners(t),this.edges.filter(t=>{const i=t.state.links||{};return i.start&&i.start.id===e||i.end&&i.end.id===e}).forEach(e=>this.ice.removeChild(e))),t.parentNode&&"function"==typeof t.parentNode.removeChild?t.parentNode.removeChild(t):this.ice.removeChild(t),this.selectedId===e&&(this.selectedId=null),this.__emitChange())}clear(){this.__captureHistory(),this.ice.clearAll(),this.selectedId=null,this.__emitChange()}serialize(){return JSON.stringify(this.toSnapshot())}toSnapshot(){const e=this.__serializer().toJSONObject();return{version:2,kind:"flowchart",createTime:e.createTime,scene:{version:e.version,childNodes:e.childNodes}}}__serializer(){const e=this.ice;return e.serializer||new i.Serializer(e)}__deserializer(){const e=this.ice;return e.deserializer||new i.Deserializer(e)}load(e){if(!e)return{loaded:!1,nodes:0,edges:0,skipped:[]};let t;try{t=JSON.parse(e)}catch(e){throw new Error(`Invalid flow snapshot: 不是合法 JSON(${e instanceof Error?e.message:String(e)})`)}if(!t||"object"!=typeof t)return{loaded:!1,nodes:0,edges:0,skipped:[]};const i=!!t.scene;if(!i&&!Array.isArray(t.nodes))return{loaded:!1,nodes:0,edges:0,skipped:[]};const n=validateFlowSnapshot(t);if(!n.valid)throw new Error(`Invalid flow snapshot:\n${n.errors.join("\n")}`);this.__captureHistory();const s=i?this.__applyEngineScene(t.scene,t.createTime):this.__clearAndBuild(t);return this.__emitChange(),s}__applyEngineScene(e,t){this.ice.clearAll(),this.selectedId=null;const i=this.__deserializer();i.fromJSONObject({version:e.version,createTime:t,childNodes:e.childNodes});const n={loaded:!0,nodes:this.nodes.length,edges:this.edges.length,skipped:[...i.unknownTypes||[]]};return this.nodes.forEach(e=>this.__attachNodeListeners(e)),n}__clearAndBuild(e){this.ice.clearAll(),this.selectedId=null;const t={loaded:!0,nodes:0,edges:0,skipped:[]};return(e.nodes||[]).forEach(e=>{if(void 0!==e.typeId&&this.ice.getType(e.typeId)!==FlowNode)return void t.skipped.push(String(e.typeId));const i=new FlowNode(e);delete i.state.typeId,this.ice.addChild(i),this.__attachNodeListeners(i),t.nodes+=1}),(e.edges||[]).forEach(e=>{if(void 0!==e.typeId&&this.ice.getType(e.typeId)!==FlowEdge)return void t.skipped.push(String(e.typeId));const i=e.sourceId||e.links&&e.links.start&&e.links.start.id||null,n=e.targetId||e.links&&e.links.end&&e.links.end.id||null,s=e.sourcePort||e.links&&e.links.start&&e.links.start.position||"B",r=e.targetPort||e.links&&e.links.end&&e.links.end.position||"T",a=i&&n?{start:{id:i,position:s},end:{id:n,position:r}}:e.links,o=new FlowEdge({...e,links:a,startPoint:e.startPoint||[0,0],endPoint:e.endPoint||[10,10]});delete o.state.typeId,this.ice.addChild(o),t.edges+=1}),t}contentComponents(){return this.nodes}fitViewportAlign="center";fitViewport(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:80;const t=this.contentComponents(),{width:i,height:n}=this.__viewportSize();if(!t.length||!i||!n)return;let s=1/0,r=1/0,a=-1/0,o=-1/0;t.forEach(e=>{const t=e.getMinBoundingBox(!0);s=Math.min(s,t.tl[0]),r=Math.min(r,t.tl[1]),a=Math.max(a,t.br[0]),o=Math.max(o,t.br[1])});const l=Math.max(a-s,1),h=Math.max(o-r,1),d=Math.min((i-2*e)/l,(n-2*e)/h,1.25),c=(i-l*d)/2-s*d,u="start"===this.fitViewportAlign?e-r*d:(n-h*d)/2-r*d;this.ice.setViewport(d,c,u)}__viewportSize(){const e=this.ice,t=e&&e.dpr?e.dpr:1,i=e&&"function"==typeof e.getInputRect?e.getInputRect():null;return{width:i&&i.width>0?i.width:(e?.canvasWidth||0)/t,height:i&&i.height>0?i.height:(e?.canvasHeight||0)/t}}canUndo(){return this.__undoStack.length>0}toSvg(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return i.exportSvg(this.ice,e)}canRedo(){return this.__redoStack.length>0}captureHistory(){this.__captureHistory()}resetHistory(){this.__undoStack.length=0,this.__redoStack.length=0}__captureHistory(){this.__historyEnabled&&(this.__undoStack.push(this.serialize()),this.__undoStack.length>this.__maxHistory&&this.__undoStack.shift(),this.__redoStack.length=0)}__applySnapshot(e){const t=JSON.parse(e);t&&t.scene?this.__applyEngineScene(t.scene):this.__clearAndBuild(t)}undo(){if(!this.canUndo())return;const e=this.serialize(),t=this.__undoStack.pop();this.__redoStack.push(e),this.__historyEnabled=!1;try{this.__applySnapshot(t)}catch(e){throw this.__redoStack.pop(),this.__undoStack.push(t),e}finally{this.__historyEnabled=!0}this.__emitChange()}redo(){if(!this.canRedo())return;const e=this.serialize(),t=this.__redoStack.pop();this.__undoStack.push(e),this.__historyEnabled=!1;try{this.__applySnapshot(t)}catch(e){throw this.__undoStack.pop(),this.__redoStack.push(t),e}finally{this.__historyEnabled=!0}this.__emitChange()}__handleMouseDown(e){const t=e&&e.param&&e.param.component;if(!t)return;let i=t;for(;i;){const e=i.constructor&&i.constructor.typeId;if(e===FlowNode.typeId||e===FlowEdge.typeId)return void this.select(i.state.id);i=i.parentNode}}dispose(){this.ice.evtBus.off("mousedown",this.__mousedownHandler,this),this.ice.evtBus.off("mouseup",this.__mouseupHandler,this),this.nodes.forEach(e=>this.__detachNodeListeners(e))}}function endpointId(e,t){return((e.state.links||{})[t]||{}).id}function boxOf(e){const t=e.getMinBoundingBox(!0);return{x0:t.tl[0],y0:t.tl[1],x1:t.br[0],y1:t.br[1]}}function contains(e,t){const i=(t.x0+t.x1)/2,n=(t.y0+t.y1)/2;return i>=e.x0&&i<=e.x1&&n>=e.y0&&n<=e.y1}function owningPool(e,t){const i=boxOf(e),n=t.filter(e=>"bpmnPool"===e.state.kind);for(const e of n)if(contains(boxOf(e),i))return e;return null}function validateBpmn(e){const t=[],i=e.nodes||[],n=e.edges||[],s=new Map;i.forEach(e=>s.set(e.state.id,e));const r=i.filter(e=>!!e&&-1!==["bpmnEvent","bpmnTask","bpmnGateway","bpmnSubprocess"].indexOf(e.state.kind)),a=n.filter(e=>"sequence"===(e.state.flowType||"sequence")),o=n.filter(e=>"message"===e.state.flowType),l=new Map,h=new Map;r.forEach(e=>{l.set(e.state.id,[]),h.set(e.state.id,[])}),a.forEach(e=>{const t=endpointId(e,"start"),i=endpointId(e,"end"),n=l.get(t),s=h.get(i);n&&n.push(e),s&&s.push(e)}),r.forEach(e=>{const i=e.state.kind,n=e.state.eventKind,s=l.get(e.state.id)||[],r=h.get(e.state.id)||[];if("bpmnEvent"===i&&"start"===n&&(r.length&&t.push({level:"error",code:"start-incoming",componentId:e.state.id,message:`开始事件「${e.state.title}」不能有流入的顺序流`}),s.length||t.push({level:"error",code:"start-no-outgoing",componentId:e.state.id,message:`开始事件「${e.state.title}」缺少流出的顺序流`})),"bpmnEvent"===i&&"end"===n&&(s.length&&t.push({level:"error",code:"end-outgoing",componentId:e.state.id,message:`结束事件「${e.state.title}」不能有流出的顺序流`}),r.length||t.push({level:"warning",code:"end-no-incoming",componentId:e.state.id,message:`结束事件「${e.state.title}」没有流入的顺序流(不可达)`})),"bpmnGateway"===i){const i=e.state.gatewayType||"exclusive";s.length<1&&t.push({level:"error",code:"gateway-no-outgoing",componentId:e.state.id,message:`网关「${e.state.title}」至少要有一条流出顺序流`}),"exclusive"!==i&&s.length<2&&t.push({level:"warning",code:"gateway-too-few-branches",componentId:e.state.id,message:`${{parallel:"并行",inclusive:"包容",event:"事件"}[i]||i}网关「${e.state.title}」通常应有 ≥2 条出边`});const n=s.filter(e=>e.state.isDefault);n.length>1&&t.push({level:"error",code:"gateway-multi-default",componentId:e.state.id,message:`网关「${e.state.title}」只能有一条默认流(当前 ${n.length} 条)`}),n.length&&"exclusive"!==i&&"inclusive"!==i&&t.push({level:"warning",code:"gateway-default-on-and",componentId:e.state.id,message:`并行网关「${e.state.title}」不应设置默认流`})}r.length||s.length||"bpmnPool"===i||"bpmnLane"===i||"bpmnAnnotation"===i||"bpmnEvent"===i&&"start"===n||t.push({level:"warning",code:"isolated-node",componentId:e.state.id,message:`「${e.state.title}」没有连任何顺序流`})});i.filter(e=>"bpmnPool"===e.state.kind).forEach(e=>{const i=boxOf(e),n=r.filter(e=>contains(i,boxOf(e))),s=n.filter(e=>"bpmnEvent"===e.state.kind&&"start"===e.state.eventKind);n.length&&!s.length&&t.push({level:"error",code:"pool-no-start",componentId:e.state.id,message:`池「${e.state.title}」里没有开始事件`})}),a.forEach(e=>{const n=s.get(endpointId(e,"start")),r=s.get(endpointId(e,"end"));if(!n||!r)return;owningPool(n,i)!==owningPool(r,i)&&t.push({level:"error",code:"sequence-flow-cross-pool",componentId:e.state.id,message:`顺序流不能跨池(「${n.state.title}」→「${r.state.title}」);跨参与者请用消息流`})}),o.forEach(e=>{const n=s.get(endpointId(e,"start")),r=s.get(endpointId(e,"end"));if(!n||!r)return;const a=owningPool(n,i),o=owningPool(r,i);a&&o&&a===o&&t.push({level:"warning",code:"message-flow-same-pool",componentId:e.state.id,message:"消息流通常用于跨池(不同参与者)之间的通信"})});const d=new Set,c=r.filter(e=>"bpmnEvent"===e.state.kind&&"start"===e.state.eventKind).map(e=>e.state.id);for(c.forEach(e=>d.add(e));c.length;){const e=c.shift();(l.get(e)||[]).forEach(e=>{const t=endpointId(e,"end");t&&!d.has(t)&&(d.add(t),c.push(t))})}return r.forEach(e=>{d.has(e.state.id)||t.push({level:"warning",code:"unreachable-node",componentId:e.state.id,message:`「${e.state.title}」从开始事件出发不可达`})}),t}class SimTokenDot extends i.ICECircle{static typeId="ice-entity-designer:SimToken";constructor(){super({radius:7,stroke:!1,interactive:!1,zIndex:10000020,...arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}})}}function escapeXml(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function localName(e){return(e&&(e.localName||e.nodeName||"")).split(":").pop()}function rectOf(e){const t=e.getMinBoundingBox(!0);return{x0:t.tl[0],y0:t.tl[1],x1:t.br[0],y1:t.br[1]}}function centerInside(e,t){const i=(t.x0+t.x1)/2,n=(t.y0+t.y1)/2;return i>=e.x0&&i<=e.x1&&n>=e.y0&&n<=e.y1}const on={class:"",interface:"«interface»",enum:"«enumeration»"};class UmlClass extends i.ICEGroup{static typeId="ice-entity-designer:UmlClass";stereotypeComponent=null;nameComponent=null;headerBackgroundComponent=null;memberComponents=[];dividerComponents=[];hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(UmlClass.arrangeParam(e)),this.syncCompartments()}static arrangeParam(e){const t=Li({kind:"class",className:"Class",attributes:[],methods:[],width:220,height:120,style:{strokeStyle:"#94a3b8",fillStyle:"#ffffff",radius:8,lineWidth:1.25,shadow:"sm"},headerStyle:{textColor:"#1e293b",stereotypeColor:"#6366f1",backgroundColor:"#eef2ff",fontSize:15,fontWeight:"bold",paddingTop:9,paddingBottom:9,paddingLeft:12,paddingRight:12},memberStyle:{textColor:"#475569",fontSize:12.5,paddingTop:5,paddingBottom:3,paddingLeft:12,paddingRight:12},dividerStyle:{strokeStyle:"#e2e8f0",fillStyle:"#e2e8f0",lineWidth:1}},e,{transformable:!1});return Ke(t.className)&&(t.className="Class"),Array.isArray(t.attributes)||(t.attributes=[]),Array.isArray(t.methods)||(t.methods=[]),t}static __layoutKeys=["kind","className","attributes","methods","abstract","width","headerStyle","memberStyle","dividerStyle"];setState(e){const t=!!e&&UmlClass.__layoutKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncCompartments()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}syncCompartments(){this.__clearDerivedChildren();const e=this.state.width,t=this.state.kind||"class",n=on[t]||(this.state.abstract?"«abstract»":""),s=this.state.headerStyle,r=this.state.memberStyle;let a=0;const o=Number(this.state.zIndex)||0,lineHeight=(e,t,i)=>Math.round(1.35*e+t+i),l=(this.state.style.lineWidth||1.5)/2,h=[];if(n){const t=Math.max((s.fontSize||16)-2,10),r=lineHeight(t,s.paddingTop,0),l=new i.ICEText({zIndex:o+2,left:0,top:a,width:e,height:r,text:n,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:t,fillStyle:s.stereotypeColor||s.textColor,textAlign:"center",textBaseline:"middle"}});this.stereotypeComponent=l,h.push(l),a+=r}const d=lineHeight(s.fontSize||16,n?0:s.paddingTop,s.paddingBottom),c=new i.ICEText({zIndex:o+2,left:0,top:a,width:e,height:d,text:String(this.state.className||""),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:s.fontSize,fillStyle:s.textColor,fontWeight:s.fontWeight,textAlign:"center",textBaseline:"middle",fontStyle:"interface"===t?"italic":"normal"}});this.nameComponent=c,h.push(c),a+=d;const u=a;s.backgroundColor&&"none"!==s.backgroundColor&&(this.headerBackgroundComponent=new i.ICERect({zIndex:o+1,left:l,top:l,width:Math.max(e-2*l,0),height:Math.max(u-l,0),origin:"top-left",radius:Math.max((this.state.style.radius||0)-l,0),stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:s.backgroundColor,lineWidth:0}}),this.addChild(this.headerBackgroundComponent)),h.forEach(e=>this.addChild(e));[this.state.attributes||[],this.state.methods||[]].forEach((t,n)=>{const s=new i.ICEPolyLine({zIndex:o+2,left:0,top:0,points:[[0,a],[e,a]],stroke:!0,interactive:!1,linkable:!1,style:{strokeStyle:this.state.dividerStyle.strokeStyle,fillStyle:this.state.dividerStyle.fillStyle,lineWidth:this.state.dividerStyle.lineWidth}});this.dividerComponents.push(s),this.addChild(s);const l=lineHeight(r.fontSize||13,r.paddingTop,r.paddingBottom);t.length?(t.forEach(t=>{const n=new i.ICEText({zIndex:o+2,left:0,top:a,width:e,height:l,text:String(t),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:r.fontSize,fillStyle:r.textColor,textBaseline:"middle",textAlign:"left",paddingLeft:r.paddingLeft}});this.memberComponents.push(n),this.addChild(n),a+=l}),a+=6):a+=l}),this.state.height=Math.max(Math.round(a),this.state.height||0)}__clearDerivedChildren(){this.headerBackgroundComponent&&(this.removeChild(this.headerBackgroundComponent),this.headerBackgroundComponent=null),this.stereotypeComponent&&(this.removeChild(this.stereotypeComponent),this.stereotypeComponent=null),this.nameComponent&&(this.removeChild(this.nameComponent),this.nameComponent=null),this.memberComponents.length&&(this.removeChildren(this.memberComponents),this.memberComponents.length=0),this.dividerComponents.length&&(this.removeChildren(this.dividerComponents),this.dividerComponents.length=0)}}const ln=["inheritance","realization","association","aggregation","composition","dependency"],hn={inheritance:{marker:"triangle",markerEnd:"end",filled:!1,dashed:!1},realization:{marker:"triangle",markerEnd:"end",filled:!1,dashed:!0},association:{marker:"none",markerEnd:"end",filled:!1,dashed:!1},aggregation:{marker:"diamond",markerEnd:"start",filled:!1,dashed:!1},composition:{marker:"diamond",markerEnd:"start",filled:!0,dashed:!1},dependency:{marker:"open",markerEnd:"end",filled:!1,dashed:!0}},dn={inheritance:"#6366f1",realization:"#8b5cf6",association:"#64748b",aggregation:"#0d9488",composition:"#0f766e",dependency:"#94a3b8"};class UmlRelation extends i.ICEPolyLine{static typeId="ice-entity-designer:UmlRelation";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(UmlRelation.arrangeParam(e)),this.__applyNotation(),this.setState({keepHistory:!1}),this.paramsDirty=!0}static arrangeParam(e){return Li({transformable:!1,relationKind:"association",label:"",arrowLength:12,fill:!1},e)}setState(e){const t=!!e&&(Object.prototype.hasOwnProperty.call(e,"relationKind")||Object.prototype.hasOwnProperty.call(e,"arrowLength"));super.setState(e),t&&this.state.relationKind&&this.__applyNotation()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}__applyNotation(){const e=this.state.relationKind||"association",t=hn[e]||hn.association,i=dn[e]||dn.association;this.state.umlMarker=t.marker,this.state.arrowStyle="none"===t.marker?"none":t.filled?"filled":"hollow",this.state.lineDash=t.dashed?this.state.lineDash&&this.state.lineDash.length?this.state.lineDash:[8,5]:[],this.state.arrow="none"===t.marker?"none":t.markerEnd,this.state.style={...this.state.style||{},strokeStyle:i,fillStyle:i,lineWidth:1.4}}calcArrowPoints(){const e=this.__arrowFaceIndexes;e.length=0;const t=this.state.relationKind||"association",i=hn[t]||hn.association,n=this.state.dots;if(!n||n.length<2||"none"===i.marker)return;const s="start"===i.markerEnd,r=[...s?n[0]:n[n.length-1]],a=[...s?n[1]:n[n.length-2]],o=r[0]-a[0],l=r[1]-a[1],h=Math.hypot(o,l)||1,d=o/h,c=l/h,u=this.state.arrowLength||14,p=.4*u,f=-c,g=d;if("triangle"===i.marker||"open"===i.marker){const t=this.doCalcArrowPoints([r,a]);return void(s?(n.unshift(...t),n.unshift([...r]),e.push(0)):(n.push(...t),n.push([...r]),e.push(n.length-4)))}const m=r[0]-d*(u/2),y=r[1]-c*(u/2),_=[[r[0],r[1]],[m+f*p,y+g*p],[r[0]-d*u,r[1]-c*u],[m-f*p,y-g*p]];s?(n.unshift(_[3],_[2],_[1]),e.push(0)):(n.push(_[1],_[2],_[3],[...r]),e.push(n.length-4))}}function normalizeLabelStyle(e){if(!e||"object"!=typeof e)return e;const t=e.labelStyle,i=e.style||{};if(!t&&i.label)return e;const n={...e,style:{...i,label:{...t||{},...i.label||{}}}};return delete n.labelStyle,n}class StateNode extends i.ICEGroup{static typeId="ice-entity-designer:StateNode";shapeComponent=null;innerRingComponent=null;labelComponent=null;hasDerivedChildren(){return!0}getSerializableChildren(){const e=[this.shapeComponent,this.innerRingComponent,this.labelComponent];return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(StateNode.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=normalizeLabelStyle(e);const t=e.kind||"state",i="initial"===t||"final"===t;return Li({kind:t,title:"状态",width:i?24:"composite"===t?320:160,height:i?24:"composite"===t?200:64,fill:!1,stroke:!1,style:{strokeStyle:"#94a3b8",fillStyle:"#ffffff",lineWidth:1.25,shadow:"sm",label:{textColor:"#1e293b",fontSize:13.5,fontWeight:"normal",paddingLeft:12,paddingTop:10}}},e,{transformable:!1})}static __shapeKeys=["kind","title","width","height","style"];setState(e){const t=!!e&&StateNode.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}isPseudoState(){return"initial"===this.state.kind||"final"===this.state.kind}syncShape(){this.__clearDerivedChildren();const e=Number(this.state.zIndex)||0,t=this.state.kind||"state",n=this.state.width,s=this.state.height;if("initial"===t)return this.shapeComponent=new i.ICECircle({zIndex:e+1,left:0,top:0,radius:Math.min(n,s)/2,stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.pseudoColor||"#334155"}}),void this.addChild(this.shapeComponent);if("final"===t){const t=Math.min(n,s)/2,r=this.state.style.lineWidth||1.5;return this.shapeComponent=new i.ICECircle({zIndex:e+1,left:0,top:0,radius:t,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.fillStyle||"#ffffff",strokeStyle:this.state.style.pseudoColor||"#334155",lineWidth:r}}),this.innerRingComponent=new i.ICECircle({zIndex:e+2,left:0,top:0,radius:.6*t,stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.pseudoColor||"#334155"}}),this.addChild(this.shapeComponent),void this.addChild(this.innerRingComponent)}this.shapeComponent=new i.ICERect({zIndex:e+1,left:0,top:0,width:n,height:s,radius:"composite"===t?14:12,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:this.state.style.fillStyle||"#ffffff",strokeStyle:this.state.style.strokeStyle||"#334155",lineWidth:this.state.style.lineWidth||1.5,shadow:this.state.style.shadow,lineDash:"composite"===t?[6,5]:[]}}),this.addChild(this.shapeComponent);const r="composite"===t;this.labelComponent=new i.ICEText({zIndex:e+2,left:0,top:0,width:n,height:r?Math.max(this.state.style.label.fontSize+2*this.state.style.label.paddingTop,28):s,text:String(this.state.title||""),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:this.state.style.label.fontSize,fontWeight:this.state.style.label.fontWeight,fillStyle:this.state.style.label.textColor,textAlign:r?"left":"center",textBaseline:r?"top":"middle",paddingLeft:r?this.state.style.label.paddingLeft:0,paddingTop:r?this.state.style.label.paddingTop:0}}),this.addChild(this.labelComponent)}__clearDerivedChildren(){this.shapeComponent&&(this.removeChild(this.shapeComponent),this.shapeComponent=null),this.innerRingComponent&&(this.removeChild(this.innerRingComponent),this.innerRingComponent=null),this.labelComponent&&(this.removeChild(this.labelComponent),this.labelComponent=null)}}class StateTransition extends i.ICEPolyLine{static typeId="ice-entity-designer:StateTransition";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(StateTransition.arrangeParam(e))}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=normalizeLabelStyle(e);const t=Li({transformable:!1,event:"",guard:"",action:"",arrow:"end",arrowStyle:"filled",fill:!1,arrowLength:12,style:{strokeStyle:"#64748b",fillStyle:"#64748b",lineWidth:1.4,label:{fontSize:12.5,fillStyle:"#334155",backgroundColor:"#ffffff"}}},e);return void 0===e.label&&(t.label=StateTransition.composeLabel(t)),t}static composeLabel(e){const t=(e.event||"").trim(),i=(e.guard||"").trim(),n=(e.action||"").trim();let s=t;return i&&(s+=`${s?" ":""}[${i}]`),n&&(s+=`${s?" / ":""}${n}`),s}setState(e){const t=!!e&&["event","guard","action"].some(t=>Object.prototype.hasOwnProperty.call(e,t))&&!Object.prototype.hasOwnProperty.call(e,"label")?{...e,label:StateTransition.composeLabel({...this.state,...e})}:e;super.setState(t)}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}}const cn=/^[A-Za-z_\u4e00-\u9fa5][A-Za-z0-9_\u4e00-\u9fa5-]*$/;function kindOf(e){return e.state.kind||"state"}function isPseudo(e){return"initial"===e||"final"===e}function splitTransitionLabel(e){const t=String(e||"").trim();if(!t)return{event:"",guard:"",action:""};const i=t.indexOf(" / "),n=-1===i?t:t.slice(0,i),s=-1===i?"":t.slice(i+3).trim(),r=/\[([^\]]*)\]\s*$/.exec(n);return r?{event:n.slice(0,r.index).trim(),guard:r[1].trim(),action:s}:{event:n.trim(),guard:"",action:s}}const un=864e5;function parseDate(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(String(e||"").trim());if(!t)return Number.NaN;const i=Number(t[1]),n=Number(t[2]),s=Number(t[3]);return Date.UTC(i,n-1,s)}function formatDate(e){const t=new Date(e),pad=e=>e<10?`0${e}`:String(e);return`${t.getUTCFullYear()}-${pad(t.getUTCMonth()+1)}-${pad(t.getUTCDate())}`}function addDays(e,t){const i=parseDate(e);return isNaN(i)?e:formatDate(i+t*un)}function diffDays(e,t){const i=parseDate(e),n=parseDate(t);return isNaN(i)||isNaN(n)?0:Math.round((n-i)/un)}function tickLabel(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return e;const i=Number(t[2]),n=Number(t[3]);return 1===n?`${i}月`:String(n)}class GanttTask extends i.ICEGroup{static typeId="ice-entity-designer:GanttTask";barComponent=null;progressComponent=null;labelComponent=null;hasDerivedChildren(){return!0}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(GanttTask.arrangeParam(e)),this.syncBar()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e=normalizeLabelStyle(e),Li({title:"任务",start:"2026-01-01",days:3,progress:0,row:0,resource:"",dayWidth:28,originDate:"2026-01-01",labelColumnWidth:140,rowHeight:36,headerHeight:34,style:{barFill:"#60a5fa",progressFill:"#2563eb",strokeStyle:"#3b82f6",lineWidth:1,label:{textColor:"#ffffff",fontSize:12}},transformable:!1},e)}static __shapeKeys=["title","start","days","progress","row","resource","dayWidth","originDate","labelColumnWidth","rowHeight","headerHeight","style"];setState(e){const t=!!e&&GanttTask.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&(this.syncGeometry(),this.syncBar(),this.trigger(i.ICE_EVENT_NAME_CONSTS.AFTER_MOVE,{left:this.state.left,top:this.state.top,target:this}))}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}setPosition(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const n=this.state.dayWidth||28,s=this.state.labelColumnWidth||0,r=this.state.rowHeight||36,a=this.state.headerHeight||34,o=Math.max(0,Math.round((e-s)/n)),l=Math.max(0,Math.round((t-a)/r));this.state.start=addDays(this.state.originDate,o),this.state.row=l,super.setState({start:this.state.start,row:l}),super.setPosition(s+o*n,a+l*r,i||void 0),this.syncBar()}barLeft(){return this.state.left}progressWidth(){return Math.max(0,Math.min(1,Number(this.state.progress)||0))*this.state.width}syncGeometry(){const e=this.state.dayWidth||28,t=Math.max(1,Number(this.state.days)||1);this.state.width=t*e,this.state.height=Math.max(18,(this.state.rowHeight||36)-14),this.state.left=(this.state.labelColumnWidth||0)+diffDays(this.state.originDate,this.state.start)*e,this.state.top=(this.state.headerHeight||34)+(Number(this.state.row)||0)*(this.state.rowHeight||36)+7}syncBar(){this.__clearDerivedChildren();const e=Number(this.state.zIndex)||0,t=this.state.width,n=this.state.height,s=this.state.style;this.barComponent=new i.ICERect({zIndex:e+1,left:0,top:0,width:t,height:n,radius:Math.min(4,n/2),stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:s.barFill,strokeStyle:s.strokeStyle,lineWidth:s.lineWidth}}),this.addChild(this.barComponent);const r=Math.max(0,Math.min(1,Number(this.state.progress)||0));r>0&&(this.progressComponent=new i.ICERect({zIndex:e+2,left:0,top:0,width:this.progressWidth(),height:n,radius:Math.min(4,n/2),stroke:!1,interactive:!1,linkable:!1,style:{fillStyle:s.progressFill}}),this.addChild(this.progressComponent));const a=Math.round(100*r);this.labelComponent=new i.ICEText({zIndex:e+3,left:0,top:0,width:t,height:n,text:`${this.state.title}(${Math.max(1,Number(this.state.days)||1)} 天)${a>0?` · ${a}%`:""}`,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:this.state.style.label.fontSize,fillStyle:this.state.style.label.textColor,textAlign:"left",textBaseline:"middle",paddingLeft:8}}),this.addChild(this.labelComponent)}__clearDerivedChildren(){[this.barComponent,this.progressComponent,this.labelComponent].forEach(e=>{e&&this.removeChild(e)}),this.barComponent=null,this.progressComponent=null,this.labelComponent=null}}class GanttDependency extends i.ICEPolyLine{static typeId="ice-entity-designer:GanttDependency";constructor(){super(Li({transformable:!1,arrow:"end",arrowStyle:"filled",fill:!1,routeType:"orthogonal",routeOffset:14,arrowLength:12,style:{strokeStyle:"#94a3b8",fillStyle:"#94a3b8",lineWidth:1.3}},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}))}}class GanttRuler extends i.ICEGroup{static typeId="ice-entity-designer:GanttRuler";constructor(){super({left:0,top:0,width:0,height:0,fill:!1,stroke:!1,interactive:!1,draggable:!1,linkable:!1})}hasDerivedChildren(){return!0}sync(e){this.removeChildren([...this.childNodes]);const{dayWidth:t,labelColumnWidth:n,headerHeight:s,rowHeight:r,originDate:a,dayCount:o,tasks:l}=e,h=n+o*t;this.state.width=h,this.state.height=s+l.length*r;const d=Number(this.state.zIndex)||0;if(this.addChild(new i.ICERect({zIndex:d+1,left:0,top:0,width:h,height:this.state.height,stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#ffffff"}})),this.addChild(new i.ICERect({zIndex:d+2,left:0,top:0,width:n,height:this.state.height,stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#f8fafc"}})),this.addChild(new i.ICERect({zIndex:d+2,left:0,top:0,width:h,height:s,stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#f1f5f9"}})),this.addChild(this.__text("任务",0,0,n,s,"#0f172a",13,"center",d+3)),!a)return;for(let e=0;e<o;e++){const r=new Date(Date.parse(`${this.__addDays(a,e)}T00:00:00Z`)).getUTCDay();0!==r&&6!==r||this.addChild(new i.ICERect({zIndex:d+1,left:n+e*t,top:s,width:t,height:Math.max(this.state.height-s,0),stroke:!1,linkable:!1,interactive:!1,style:{fillStyle:"#f1f5f9"}}))}const c=[];for(let e=0;e<o;e++)c.push(tickLabel(this.__addDays(a,e)));const u=o<=40;c.forEach((e,r)=>{const o=this.__addDays(a,r),l=1===new Date(Date.parse(`${o}T00:00:00Z`)).getUTCDay(),h=o.endsWith("-01"),c=u||l||h,p=n+r*t;this.addChild(new i.ICEPolyLine({zIndex:d+2,points:[[p,s],[p,this.state.height]],linkable:!1,interactive:!1,style:{strokeStyle:h?"#cbd5e1":l?"#e2e8f0":"#f1f5f9",fillStyle:"#e2e8f0",lineWidth:1}})),c&&this.addChild(this.__text(e,p,0,t,s,"#64748b",11,"center",d+3))}),l.forEach((e,t)=>{const a=s+t*r;this.addChild(this.__text(e.title,0,a,n,r,"#334155",13,"left",d+3,12)),this.addChild(new i.ICEPolyLine({zIndex:d+2,points:[[0,a+r],[h,a+r]],linkable:!1,interactive:!1,style:{strokeStyle:"#e2e8f0",fillStyle:"#e2e8f0",lineWidth:1}}))}),this.addChild(new i.ICEPolyLine({zIndex:d+3,points:[[0,s],[h,s]],linkable:!1,interactive:!1,style:{strokeStyle:"#cbd5e1",fillStyle:"#cbd5e1",lineWidth:1}})),this.addChild(new i.ICEPolyLine({zIndex:d+3,points:[[n,0],[n,this.state.height]],linkable:!1,interactive:!1,style:{strokeStyle:"#cbd5e1",fillStyle:"#cbd5e1",lineWidth:1}}))}__addDays(e,t){const i=Date.parse(`${e}T00:00:00Z`),n=new Date(i+24*t*60*60*1e3),pad=e=>e<10?`0${e}`:String(e);return`${n.getUTCFullYear()}-${pad(n.getUTCMonth()+1)}-${pad(n.getUTCDate())}`}__text(e,t,n,s,r,a,o,l,h){let d=arguments.length>9&&void 0!==arguments[9]?arguments[9]:0;return new i.ICEText({zIndex:h,left:t,top:n,width:s,height:r,text:e,stroke:!1,linkable:!1,interactive:!1,style:{fontSize:o,fillStyle:a,textAlign:l,textBaseline:"middle",paddingLeft:d}})}}const pn=/^(gantt|title|dateFormat|axisFormat|excludes|includes|todayMarker|tickInterval|accTitle|accDescr|displayMode|weekday)\b/i,fn=/^\d{4}-\d{2}-\d{2}$/,gn=/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/i,mn=/^(done|active|crit|milestone|vert)$/i;const yn=[{level:"500kV",colorName:"淡黄",color:"#f2e394",kv:500},{level:"220kV",colorName:"紫",color:"#8b5cf6",kv:220},{level:"110kV",colorName:"朱红",color:"#e05252",kv:110},{level:"35kV",colorName:"鲜黄",color:"#f5c518",kv:35},{level:"10kV",colorName:"绛红",color:"#9b1c31",kv:10},{level:"6kV",colorName:"深蓝",color:"#1d4ed8",kv:6}],_n="#1f2937";function defaultVoltageColors(){const e={};return yn.forEach(t=>{e[t.level]=t.color}),e}function voltageColorOf(e,t){if(!e)return _n;return(t||defaultVoltageColors())[e]||_n}const bn={busbar:{label:"母线",tag:"W",width:260,height:20,inline:!1},breaker:{label:"断路器",tag:"QF",width:44,height:52,inline:!0},disconnector:{label:"隔离开关",tag:"QS",width:44,height:52,inline:!0},loadSwitch:{label:"负荷开关",tag:"QL",width:44,height:52,inline:!0},earthingSwitch:{label:"接地开关",tag:"QE",width:44,height:60,inline:!0},earth:{label:"接地",tag:"E",width:40,height:34,inline:!1},currentTransformer:{label:"电流互感器",tag:"TA",width:44,height:52,inline:!0},voltageTransformer:{label:"电压互感器",tag:"TV",width:48,height:70,inline:!0},transformer:{label:"变压器",tag:"TM",width:52,height:76,inline:!0},fuse:{label:"熔断器",tag:"FU",width:40,height:56,inline:!0},arrester:{label:"避雷器",tag:"F",width:40,height:62,inline:!1},reactor:{label:"电抗器",tag:"L",width:44,height:56,inline:!0},generator:{label:"发电机",tag:"G",width:52,height:52,inline:!1},motor:{label:"电动机",tag:"M",width:52,height:52,inline:!1},load:{label:"负荷 / 出线",tag:"-",width:40,height:40,inline:!1},capacitor:{label:"并联电容器",tag:"C",width:52,height:56,inline:!0},arcSuppressionCoil:{label:"消弧线圈",tag:"L",width:48,height:76,inline:!0},threeWindingTransformer:{label:"三绕组变压器",tag:"TM",width:56,height:92,inline:!0},groundingTransformer:{label:"接地变压器",tag:"TM",width:56,height:96,inline:!0},groundingResistor:{label:"接地电阻",tag:"R",width:44,height:72,inline:!0},cable:{label:"电缆",tag:"W",width:44,height:72,inline:!0},cableTermination:{label:"电缆终端",tag:"W",width:48,height:64,inline:!0},cubicle:{label:"间隔 / 开关柜(方框)",tag:"GIS",width:200,height:140,inline:!1}},vn={strokeStyle:"#1f2937",lineWidth:1.6,heavyLineWidth:3,tagFontSize:10,tagColor:"#475569",letterFontSize:15,deEnergizedColor:"#94a3b8",nameFontSize:11,nameColor:"#334155",stateFontSize:10},kn=["breaker","disconnector","loadSwitch","earthingSwitch"];function arcPoints(e,t,i,n,s){let r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:16;const a=[];for(let o=0;o<=r;o++){const l=(n+(s-n)*o/r)*Math.PI/180;a.push([e+i*Math.cos(l),t+i*Math.sin(l)])}return a}class PowerSymbol extends i.ICEGroup{static typeId="ice-entity-designer:PowerSymbol";parts=[];hasDerivedChildren(){return!0}getSerializableChildren(){const e=this.parts.map(e=>e.component);return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(PowerSymbol.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.kind||"breaker",i=bn[t]||bn.breaker;return Li({kind:t,tag:i.tag,fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:vn.strokeStyle,lineWidth:vn.lineWidth},tagStyle:{fontSize:vn.tagFontSize,textColor:vn.tagColor},name:"",voltageLevel:"",voltageColors:null,switchState:"open",energized:void 0,transformable:!1,energizedSource:!1,attachedBusId:""},e)}static __shapeKeys=["kind","tag","width","height","style","tagStyle","name","voltageLevel","voltageColors","switchState","energized"];setState(e){const t=!!e&&PowerSymbol.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}part(e){const t=this.parts.find(t=>t.role===e);return t?t.component:null}syncShape(){var e=this;this.__clearParts();const t=this.state.kind||"breaker",n=bn[t]||bn.breaker,s=this.state.width||n.width,r=this.state.height||n.height,a=this.state.style&&this.state.style.lineWidth||vn.lineWidth,o=this.state.style&&this.state.style.strokeStyle||vn.strokeStyle,l=!1===this.state.energized?vn.deEnergizedColor:this.state.voltageLevel?voltageColorOf(this.state.voltageLevel,this.state.voltageColors||void 0):o||_n,h=s/2,d=Number(this.state.zIndex)||0,c=-1!==kn.indexOf(t),u="closed"===this.state.switchState,line=function(t,n){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a;return e.__add(t,new i.ICEPolyLine({zIndex:d+2,points:n,interactive:!1,linkable:!1,style:{strokeStyle:l,fillStyle:l,lineWidth:s}}))},rect=function(t,n,s,r,o){let h=arguments.length>5&&void 0!==arguments[5]&&arguments[5],c=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0;return e.__add(t,new i.ICERect({zIndex:d+2,left:n,top:s,width:r,height:o,radius:c,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:h?l:"#ffffff",strokeStyle:l,lineWidth:a}}))},circle=(e,t,n,s)=>this.__add(e,new i.ICECircle({zIndex:d+2,left:t,top:n,radius:s,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:l,lineWidth:a}})),text=(e,t,n,s,r,a,o)=>this.__add(e,new i.ICEText({zIndex:d+3,left:n,top:s,width:r,height:a,text:t,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:o,fillStyle:l,textAlign:"center",textBaseline:"middle"}}));switch(t){case"busbar":rect("busbar",0,r/2-vn.heavyLineWidth/2,s,vn.heavyLineWidth,!0);break;case"breaker":line("leadTop",[[h,0],[h,.22*r]]),line("arcMark",[[h-7,.22*r-7],[h+7,.22*r+7]]),line("arcMark",[[h+7,.22*r-7],[h-7,.22*r+7]]),line("blade",[[h,.22*r],[h-9,.78*r]]),line("leadBottom",[[h,.78*r],[h,r]]);break;case"disconnector":line("leadTop",[[h,0],[h,.22*r]]),line("contactBar",[[h-9,.22*r],[h+9,.22*r]]),line("blade",[[h,.22*r],[h-9,.78*r]]),line("leadBottom",[[h,.78*r],[h,r]]);break;case"loadSwitch":line("leadTop",[[h,0],[h,.16*r]]),this.__add("contactCircle",new i.ICECircle({zIndex:d+2,left:h,top:.22*r,radius:5,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:l,lineWidth:a}})),line("blade",[[h,.27*r],[h-9,.78*r]]),line("leadBottom",[[h,.78*r],[h,r]]);break;case"earthingSwitch":line("leadTop",[[h,0],[h,.18*r]]),line("blade",[[h,.18*r],[h-9,.5*r]]),line("leadBottom",[[h,.5*r],[h,.62*r]]),this.__earth(h,.62*r,14,l,a);break;case"earth":line("leadTop",[[h,0],[h,.45*r]]),this.__earth(h,.45*r,16,l,a);break;case"currentTransformer":line("leadTop",[[h,0],[h,r]]),circle("winding",h-11,r/2-11,11),line("polarityMark",[[h+9,r/2-4],[h+16,r/2-11],[h+16,r/2+4]]);break;case"voltageTransformer":line("leadTop",[[h,0],[h,.16*r]]),circle("windingPrimary",h-11,.16*r,11),circle("windingSecondary",h-11,.16*r+16,11),line("leadBottom",[[h,.16*r+32],[h,r]]);break;case"transformer":line("leadTop",[[h,0],[h,.16*r]]),circle("windingPrimary",h-12,.16*r,12),circle("windingSecondary",h-12,.16*r+18,12),line("leadBottom",[[h,.16*r+36],[h,r]]),text("windingMarkHigh","△",h-12,.16*r,24,24,11),text("windingMarkLow","Y",h-12,.16*r+18,24,24,11);break;case"fuse":line("leadTop",[[h,0],[h,r]]),rect("fuseBody",h-6,.2*r,12,.6*r);break;case"arrester":line("leadTop",[[h,0],[h,.2*r]]),rect("arresterBody",h-9,.2*r,18,.6*r),line("dischargeArrow",[[h,.3*r],[h,.66*r]]),line("dischargeArrowHead",[[h-5,.56*r],[h,.66*r],[h+5,.56*r]]),line("leadBottom",[[h,.8*r],[h,r]]);break;case"reactor":line("leadTop",[[h,0],[h,.2*r]]),line("coil",arcPoints(h,.2*r+10,10,0,180)),line("coil",arcPoints(h,.2*r+30,10,0,180)),line("leadBottom",[[h,.2*r+40],[h,r]]);break;case"generator":circle("body",h-s/2+2,r/2-Math.min(s,r)/2+2,Math.min(s,r)/2-2),text("letter","G",0,r/2-26,s,52,vn.letterFontSize);break;case"motor":circle("body",h-s/2+2,r/2-Math.min(s,r)/2+2,Math.min(s,r)/2-2),text("letter","M",0,r/2-26,s,52,vn.letterFontSize);break;case"capacitor":line("leadTop",[[h,0],[h,.34*r]]),line("plateTop",[[h-15,.34*r],[h+15,.34*r]]),line("plateBottom",[[h-15,.5*r],[h+15,.5*r]]),line("leadBottom",[[h,.5*r],[h,r]]);break;case"arcSuppressionCoil":line("leadTop",[[h,0],[h,.22*r]]),line("coil",arcPoints(h,.22*r+8,8,180,360)),line("coil",arcPoints(h,.22*r+24,8,180,360)),line("coil",arcPoints(h,.22*r+40,8,180,360)),line("leadBottom",[[h,.22*r+48],[h,.68*r]]),this.__earth(h,.68*r,14,l,a);break;case"threeWindingTransformer":{line("leadTop",[[h,0],[h,.14*r]]);const e=13;circle("windingHigh",h-e,.14*r,e),circle("windingMid",h-e,.14*r+18,e),circle("windingLow",h-e,.14*r+36,e),line("leadBottom",[[h,.14*r+49],[h,r]]);break}case"groundingTransformer":line("leadTop",[[h,0],[h,.16*r]]),circle("windingPrimary",h-12,.16*r,12),circle("windingSecondary",h-12,.16*r+18,12),line("leadBottom",[[h,.16*r+36],[h,.62*r]]),this.__earth(h,.62*r,14,l,a);break;case"groundingResistor":line("leadTop",[[h,0],[h,.24*r]]),rect("resistorBody",h-8,.24*r,16,.34*r),line("leadBottom",[[h,.58*r],[h,.72*r]]),this.__earth(h,.72*r,14,l,a);break;case"cable":line("leadTop",[[h,0],[h,r]]),rect("cableEnvelope",h-10,.3*r,20,.4*r,!1,10);break;case"cableTermination":line("leadTop",[[h,0],[h,r]]),line("terminationFlare",[[h-6,.34*r],[h+6,.34*r],[h+13,.62*r],[h-13,.62*r]]);break;case"cubicle":rect("cabinet",0,0,s,r),line("cabinetDivider",[[0,.24*r],[s,.24*r]]);break;case"load":line("leadTop",[[h,0],[h,.6*r]]),line("arrowHead",[[h-7,.5*r],[h,.66*r],[h+7,.5*r]])}const p=this.state.tag;p&&this.__add("tag",new i.ICEText({zIndex:d+4,left:s+4,top:r/2-8,width:44,height:16,text:String(p),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:this.state.tagStyle&&this.state.tagStyle.fontSize||vn.tagFontSize,fillStyle:this.state.tagStyle&&this.state.tagStyle.textColor||vn.tagColor,textAlign:"left",textBaseline:"middle"}})),this.state.name&&this.__add("nameLabel",new i.ICEText({zIndex:d+4,left:"busbar"===t?4:0,top:"busbar"===t?-18:-20,width:Math.max(s,64),height:16,text:String(this.state.name),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:vn.nameFontSize,fillStyle:vn.nameColor,textAlign:"busbar"===t?"left":"center",textBaseline:"middle"}})),c&&this.__add("stateBadge",new i.ICEText({zIndex:d+4,left:-24,top:r/2-8,width:20,height:16,text:u?"合":"分",stroke:!1,interactive:!1,linkable:!1,style:{fontSize:vn.stateFontSize,fillStyle:l,textAlign:"center",textBaseline:"middle"}}))}__earth(e,t,n,s,r){[n,.62*n,.28*n].forEach((n,a)=>{this.__add("earth",new i.ICEPolyLine({zIndex:(Number(this.state.zIndex)||0)+2,points:[[e-n,t+6*a],[e+n,t+6*a]],interactive:!1,linkable:!1,style:{strokeStyle:s,fillStyle:s,lineWidth:r}}))})}__add(e,t){return this.parts.push({role:e,component:t}),this.addChild(t),t}__clearParts(){const e=this.parts.map(e=>e.component).filter(e=>-1!==this.childNodes.indexOf(e));e.length&&this.removeChildren(e),this.parts=[]}}class PowerLine extends FlowEdge{static typeId="ice-entity-designer:PowerLine";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super({...e,label:e.label||"",style:{...e.style||{}}}),this.setState({keepHistory:!1})}applyVoltageColor(e){const t=voltageColorOf(String(this.state.voltageLevel||""),e);this.setState({keepHistory:!1,style:{...this.state.style||{},strokeStyle:t,fillStyle:t}})}}const wn={contactNO:{label:"常开接点",tag:"52a",width:48,height:24},contactNC:{label:"常闭接点",tag:"52b",width:48,height:24},pushButton:{label:"按钮",tag:"11",width:48,height:40},switchRemoteLocal:{label:"切换开关(远方/就地)",tag:"43",width:64,height:32},linkPlate:{label:"压板(连接片)",tag:"XB",width:56,height:24},indicatorLamp:{label:"信号灯",tag:"HL",width:36,height:36},relayDevice:{label:"保护 / 自动装置",tag:"",width:220,height:90},ctWinding:{label:"互感器二次绕组",tag:"LH",width:48,height:44},terminal:{label:"端子",tag:"",width:28,height:28},earth:{label:"接地",tag:"E",width:40,height:34}},Sn={strokeStyle:"#1f2937",lineWidth:1.4,heavyLineWidth:2.6,labelFontSize:10,labelColor:"#475569",tagFontSize:10,tagColor:"#64748b"};class SecondarySymbol extends i.ICEGroup{static typeId="ice-entity-designer:SecondarySymbol";parts=[];hasDerivedChildren(){return!0}getSerializableChildren(){const e=this.parts.map(e=>e.component);return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(SecondarySymbol.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.kind||"contactNO",i=wn[t]||wn.contactNO;return Li({kind:t,tag:i.tag,fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:Sn.strokeStyle,lineWidth:Sn.lineWidth},transformable:!1,name:"",tagStyle:{fontSize:Sn.tagFontSize,textColor:Sn.tagColor},switchState:"open"},e)}static __shapeKeys=["kind","tag","width","height","style","tagStyle","name","switchState"];setState(e){const t=!!e&&SecondarySymbol.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}part(e){const t=this.parts.find(t=>t.role===e);return t?t.component:null}syncShape(){var e=this;this.__clearParts();const t=this.state.kind||"contactNO",n=wn[t]||wn.contactNO,s=this.state.width||n.width,r=this.state.height||n.height,a=this.state.style&&this.state.style.strokeStyle||Sn.strokeStyle,o=this.state.style&&this.state.style.lineWidth||Sn.lineWidth,l=Number(this.state.zIndex)||0,h="closed"===this.state.switchState,d=r/2,line=function(t,n){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o;return e.__add(t,new i.ICEPolyLine({zIndex:l+2,points:n,interactive:!1,linkable:!1,style:{strokeStyle:a,fillStyle:a,lineWidth:s}}))},rect=function(t,n,s,r,h){let d=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;return e.__add(t,new i.ICERect({zIndex:l+2,left:n,top:s,width:r,height:h,radius:d,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:a,lineWidth:o}}))},circle=(e,t,n,s)=>this.__add(e,new i.ICECircle({zIndex:l+2,left:t,top:n,radius:s,stroke:!0,interactive:!1,linkable:!1,style:{fillStyle:"#ffffff",strokeStyle:a,lineWidth:o}})),text=function(t,n,s,r,o,h,d){let c=arguments.length>7&&void 0!==arguments[7]?arguments[7]:a;return e.__add(t,new i.ICEText({zIndex:l+3,left:s,top:r,width:o,height:h,text:n,stroke:!1,interactive:!1,linkable:!1,style:{fontSize:d,fillStyle:c,textAlign:"center",textBaseline:"middle"}}))};switch(t){case"contactNO":line("leadLeft",[[0,d],[.36*s,d]]),line("fixedContact",[[.36*s,d-8],[.36*s,d+8]]),line("movingContact",[[.4*s,d-9],[.68*s,d+5]]),line("leadRight",[[.72*s,d],[s,d]]);break;case"contactNC":line("leadLeft",[[0,d],[.36*s,d]]),line("leadRight",[[.36*s,d],[s,d]]),line("fixedContact",[[.36*s,d-8],[.36*s,d+8]]),line("movingContact",[[.4*s,d-9],[.62*s,d+5]]);break;case"pushButton":line("leadLeft",[[0,d+4],[.36*s,d+4]]),line("fixedContact",[[.36*s,d-4],[.36*s,d+12]]),line("movingContact",[[.4*s,d-5],[.68*s,d+9]]),line("leadRight",[[.72*s,d+4],[s,d+4]]),line("actuator",[[.5*s,2],[.5*s,d-6]]),line("actuatorCap",[[.36*s,2],[.64*s,2]]);break;case"switchRemoteLocal":rect("switchBody",0,0,s,r,4),line("lever",[[.5*s,d+6],[.5*s+(h?10:-10),d-6]]),text("positionText",h?"就地":"远方",0,d+6,s,14,9,Sn.labelColor);break;case"linkPlate":line("leadLeft",[[0,d],[.3*s,d]]),line("leadRight",[[.7*s,d],[s,d]]),line("plate",h?[[.3*s,d],[.7*s,d]]:[[.3*s,d-8],[.7*s,d+6]],1.6*o);break;case"indicatorLamp":line("leadTop",[[s/2,0],[s/2,.16*r]]),circle("lamp",4,.16*r,Math.min(s,r)/2-4),line("lampCrossA",[[.34*s,.32*r],[.66*s,.64*r]]),line("lampCrossB",[[.66*s,.32*r],[.34*s,.64*r]]),line("leadBottom",[[s/2,.84*r],[s/2,r]]);break;case"relayDevice":rect("deviceBody",0,0,s,r,4),text("deviceTitle",this.state.name||"装置",0,d-10,s,20,12,a),text("deviceModel",this.state.tag||"",0,d+10,s,16,10,Sn.labelColor);break;case"ctWinding":line("leadTop",[[s/2,0],[s/2,.24*r]]),[0,1,2].forEach(e=>{const t=.24*r+10+14*e,i=[];for(let e=0;e<=12;e+=1){const n=(180+180*e/12)*Math.PI/180;i.push([s/2+10*Math.cos(n),t+10*Math.sin(n)])}line("winding",i)}),line("leadBottom",[[s/2,.24*r+52],[s/2,r]]);break;case"terminal":line("leadTop",[[s/2,0],[s/2,.3*r]]),circle("terminalCircle",4,.3*r,Math.min(s,r)/2-4),line("leadBottom",[[s/2,.7*r],[s/2,r]]);break;case"earth":line("leadTop",[[s/2,0],[s/2,.45*r]]);[16,10,4].forEach((e,t)=>{line("earth",[[s/2-e,.45*r+6*t],[s/2+e,.45*r+6*t]])});break}this.state.name&&"relayDevice"!==t&&("terminal"===t?this.__add("nameLabel",new i.ICEText({zIndex:l+4,left:-46,top:d-9,width:40,height:18,text:String(this.state.name),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:Sn.labelFontSize,fillStyle:Sn.labelColor,textAlign:"right",textBaseline:"middle"}})):text("nameLabel",String(this.state.name),0,-18,Math.max(s,56),16,Sn.labelFontSize,Sn.labelColor)),this.state.tag&&"relayDevice"!==t&&this.__add("tag",new i.ICEText({zIndex:l+4,left:s+2,top:r/2-8,width:40,height:16,text:String(this.state.tag),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:Sn.tagFontSize,fillStyle:this.state.tagStyle&&this.state.tagStyle.textColor||Sn.tagColor,textAlign:"left",textBaseline:"middle"}}))}__add(e,t){return this.parts.push({role:e,component:t}),this.addChild(t),t}__clearParts(){const e=this.parts.map(e=>e.component).filter(e=>-1!==this.childNodes.indexOf(e));e.length&&this.removeChildren(e),this.parts=[]}}class TerminalStrip extends i.ICEGroup{static typeId="ice-entity-designer:TerminalStrip";constructor(){super(Li({title:"端子排",width:96,height:240,fill:"#f8fafc",stroke:"#cbd5e1",lineWidth:1,style:{fillStyle:"#f8fafc",strokeStyle:"#cbd5e1",lineWidth:1},transformable:!1,interactive:!1,linkable:!1},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})),this.addChild(new i.ICEText({left:0,top:-20,width:Math.max(this.state.width,60),height:16,text:String(this.state.title||"端子排"),stroke:!1,interactive:!1,linkable:!1,style:{fontSize:Sn.labelFontSize,fillStyle:Sn.labelColor,textAlign:"center",textBaseline:"middle"}}))}}class SecondaryWire extends FlowEdge{static typeId="ice-entity-designer:SecondaryWire";constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super({...e,arrow:e.arrow||"none"}),this.setState({keepHistory:!1})}}const Cn={sewage:{label:"污水",color:"#475569",lineType:"solid"},effluent:{label:"出水",color:"#0d9488",lineType:"solid"},recycle:{label:"混合液回流",color:"#0369a1",lineType:"solid"},returnSludge:{label:"回流污泥",color:"#a16207",lineType:"solid"},sludge:{label:"剩余污泥",color:"#92400e",lineType:"solid"},air:{label:"空气",color:"#0891b2",lineType:"dashed"},chemical:{label:"药剂",color:"#7c3aed",lineType:"dashed"},signal:{label:"仪表信号",color:"#9333ea",lineType:"dashdot"},power:{label:"动力回路",color:"#b45309",lineType:"dashdot"}},xn={barScreen:{label:"格栅",tag:"GR",width:90,height:50,shape:"tank",inline:!1},gritChamber:{label:"曝气沉砂池",tag:"GC",width:120,height:60,shape:"tank",inline:!1},primaryClarifier:{label:"初沉池",tag:"PC",width:110,height:110,shape:"round",inline:!1},anaerobicTank:{label:"厌氧池",tag:"AT",width:120,height:70,shape:"tank",inline:!1},anoxicTank:{label:"缺氧池",tag:"AX",width:120,height:70,shape:"tank",inline:!1},aerobicTank:{label:"好氧池",tag:"AE",width:140,height:70,shape:"tank",inline:!1},secondaryClarifier:{label:"二沉池",tag:"SC",width:120,height:120,shape:"round",inline:!1},coagulationTank:{label:"混凝沉淀池",tag:"CO",width:110,height:70,shape:"tank",inline:!1},filterBed:{label:"滤池",tag:"FL",width:120,height:60,shape:"tank",inline:!1},disinfectionTank:{label:"消毒接触池",tag:"DT",width:130,height:60,shape:"tank",inline:!1},storageTank:{label:"调节 / 事故池",tag:"EQ",width:130,height:70,shape:"tank",inline:!1},deodorizer:{label:"除臭装置",tag:"OD",width:120,height:60,shape:"tank",inline:!1},sludgeThickener:{label:"污泥浓缩池",tag:"ST",width:100,height:100,shape:"round",inline:!1},dewateringMachine:{label:"污泥脱水机",tag:"DW",width:110,height:60,shape:"tank",inline:!1},sludgeSilo:{label:"污泥料仓",tag:"SIL",width:90,height:80,shape:"tank",inline:!1},pump:{label:"水泵",tag:"P",width:44,height:44,shape:"device",inline:!1},submersiblePump:{label:"潜污泵",tag:"P-SB",width:44,height:44,shape:"device",inline:!1},screwPump:{label:"螺杆泵",tag:"P-SC",width:64,height:44,shape:"device",inline:!1},blower:{label:"鼓风机",tag:"B",width:48,height:48,shape:"device",inline:!1},vfd:{label:"变频器",tag:"VFD",width:56,height:40,shape:"device",inline:!1},dosingUnit:{label:"加药装置",tag:"DU",width:60,height:70,shape:"device",inline:!1},valve:{label:"阀门",tag:"V",width:32,height:32,shape:"device",inline:!0},motorValve:{label:"电动阀",tag:"MOV",width:34,height:46,shape:"device",inline:!0},checkValve:{label:"止回阀",tag:"CV",width:32,height:32,shape:"device",inline:!0},flowMeter:{label:"流量计",tag:"FIT",width:36,height:36,shape:"device",inline:!0},levelGauge:{label:"液位计",tag:"LT",width:32,height:32,shape:"device",inline:!1},pressureGauge:{label:"压力表",tag:"PT",width:32,height:32,shape:"device",inline:!1},analyzer:{label:"在线水质分析仪",tag:"AIT",width:36,height:36,shape:"device",inline:!1},inlet:{label:"进水",tag:"IN",width:80,height:36,shape:"boundary",inline:!1},outlet:{label:"出水 / 排放",tag:"OUT",width:80,height:36,shape:"boundary",inline:!1},sludgeOut:{label:"污泥外运",tag:"SO",width:80,height:44,shape:"boundary",inline:!1}},Tn={strokeStyle:"#1f2937",lineWidth:1.4,detailLineWidth:1,waterFill:"#eff6ff",sludgeFill:"#fef3c7",tagFontSize:9.5,tagColor:"#64748b",nameFontSize:12,nameColor:"#1e293b",letterFontSize:14,hollowFill:"#ffffff",idleColor:"#94a3b8"},In=["sludgeThickener","dewateringMachine","sludgeSilo","screwPump","sludgeOut"],En=["valve","motorValve"];function isWaterValveKind(e){return-1!==En.indexOf(e)}class WaterSymbol extends i.ICEGroup{static typeId="ice-entity-designer:WaterSymbol";parts=[];__originX=0;__originY=0;hasDerivedChildren(){return!0}getSerializableChildren(){const e=this.parts.map(e=>e.component);return this.childNodes.filter(t=>-1===e.indexOf(t))}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(WaterSymbol.arrangeParam(e)),this.syncShape()}static arrangeParam(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.kind||"pump",i=xn[t]||xn.pump;return Li({kind:t,tag:i.tag,name:"",fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:Tn.strokeStyle,lineWidth:Tn.lineWidth},tagStyle:{fontSize:Tn.tagFontSize,textColor:Tn.tagColor},valveState:"open",idle:!1,transformable:!1},e)}static __shapeKeys=["kind","tag","name","width","height","style","idle","valveState"];setState(e){const t=!!e&&WaterSymbol.__shapeKeys.some(t=>Object.prototype.hasOwnProperty.call(e,t));super.setState(e),t&&this.syncShape()}applyPatch(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.setState(e)}part(e){const t=this.parts.find(t=>t.role===e);return t?t.component:null}syncShape(){this.__clearParts();const e=this.state.kind||"pump",t=xn[e]||xn.pump,i=this.state.width||t.width,n=this.state.height||t.height,s=this.state.style&&this.state.style.strokeStyle||Tn.strokeStyle,r=this.state.idle?Tn.idleColor:s,a=this.state.style&&this.state.style.lineWidth||Tn.lineWidth,o=-1!==In.indexOf(e)?Tn.sludgeFill:Tn.waterFill,l=i/2,h=n/2,d=Number(this.state.zIndex)||0;switch(this.__originX=l,this.__originY=h,e){case"barScreen":this.__box(0,0,i,n,o,r,a,d);for(let e=1;e<=4;e++){const t=i/5*e-i/2;this.__poly([t,n/2,t+8,-n/2],r,Tn.detailLineWidth,d)}break;case"gritChamber":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/2+10,n/2,0,n/2+14,i/2-10,n/2],r,a,d),this.__circle(-i/4,-n/6,4,"none",r,Tn.detailLineWidth,d),this.__circle(0,n/8,3,"none",r,Tn.detailLineWidth,d),this.__circle(i/5,-n/8,3.5,"none",r,Tn.detailLineWidth,d);break;case"primaryClarifier":case"secondaryClarifier":{const t=Math.min(i,n)/2;this.__circle(0,0,t,o,r,a,d),this.__circle(0,0,t/6,"none",r,Tn.detailLineWidth,d),this.__poly([-t,0,t,0],r,Tn.detailLineWidth,d),"secondaryClarifier"===e&&this.__poly([.6*-t,.6*-t,.6*t,.6*t],r,Tn.detailLineWidth,d);break}case"anaerobicTank":case"anoxicTank":this.__box(0,0,i,n,o,r,a,d),this.__poly([0,-n/2,0,n/2-10],r,Tn.detailLineWidth,d),this.__poly([-10,n/2-10,10,n/2-10],r,Tn.detailLineWidth,d);break;case"aerobicTank":this.__box(0,0,i,n,o,r,a,d);for(let e=0;e<4;e++)this.__circle(-i/4+e*i/6,n/4,3.5,"none",r,Tn.detailLineWidth,d);break;case"coagulationTank":this.__box(0,0,i,n,o,r,a,d),this.__poly([0,-n/2,0,n/2-10],r,Tn.detailLineWidth,d),this.__poly([-10,n/2-10,10,n/2-10],r,Tn.detailLineWidth,d),this.__circle(-i/4,-n/4,3,"none",r,Tn.detailLineWidth,d),this.__circle(-i/4,-n/4+9,2,"none",r,Tn.detailLineWidth,d);break;case"filterBed":this.__box(0,0,i,n,o,r,a,d);for(let e=0;e<6;e++){const t=-i/2+12+e*(i-24)/5;this.__circle(t,n/6,2.5,"none",r,Tn.detailLineWidth,d),this.__circle(t,-n/6,2.5,"none",r,Tn.detailLineWidth,d)}break;case"disinfectionTank":this.__box(0,0,i,n,o,r,a,d);for(let e=1;e<=3;e++){const t=-i/2+e*i/4;this.__poly([t,n/2,t,-n/2+6],r,Tn.detailLineWidth,d)}break;case"sludgeThickener":{const e=Math.min(i,n)/2;this.__circle(0,0,e,o,r,a,d),this.__circle(0,0,e/5,"none",r,Tn.detailLineWidth,d),this.__poly([-e,0,-e/5,0],r,Tn.detailLineWidth,d),this.__poly([e/5,0,e,0],r,Tn.detailLineWidth,d);break}case"dewateringMachine":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/4,-n/6,i/4,-n/6],r,Tn.detailLineWidth,d),this.__poly([-i/4,0,i/4,0],r,Tn.detailLineWidth,d),this.__poly([-i/4,n/6,i/4,n/6],r,Tn.detailLineWidth,d);break;case"pump":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d),this.__closedPoly([0,.6*-e,.6*e,.5*e,.6*-e,.5*e],r,a,d);break}case"blower":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d);for(let t=0;t<3;t++){const i=2*Math.PI*t/3-Math.PI/2;this.__poly([0,0,.85*e*Math.cos(i),.85*e*Math.sin(i)],r,Tn.detailLineWidth,d)}break}case"dosingUnit":this.__box(0,-8,i,n-20,o,r,a,d),this.__closedPoly([0,n/2-16,8,n/2,-8,n/2],r,Tn.detailLineWidth,d),this.__circle(0,n/2-4,2,"none",r,Tn.detailLineWidth,d);break;case"valve":this.__closedPoly([-9,-8,-9,8,0,0],r,a,d),this.__closedPoly([9,-8,9,8,0,0],r,a,d),"closed"===this.state.valveState&&this.__poly([0,-10,0,10],"#dc2626",2,d);break;case"flowMeter":this.__circle(0,0,Math.min(i,n)/2,"none",r,a,d),this.__text(l-7,h-.7*Tn.letterFontSize,14,"F",Tn.letterFontSize,r,"center");break;case"analyzer":this.__circle(0,0,Math.min(i,n)/2,"none",r,a,d),this.__text(l-7,h-.7*Tn.letterFontSize,14,"A",Tn.letterFontSize,r,"center");break;case"storageTank":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/2+6,n/4,i/2-6,n/4],"#93c5fd",Tn.detailLineWidth,d),this.__poly([-i/4,-n/6,-i/8,-n/3,0,-n/6,i/8,-n/3,i/4,-n/6],r,Tn.detailLineWidth,d);break;case"deodorizer":this.__box(0,0,i,n,o,r,a,d);for(let e=0;e<2;e++)for(let t=0;t<4;t++)this.__circle(-i/4+t*(i/6),-n/8+e*(n/4),3,"none",r,Tn.detailLineWidth,d);this.__poly([-i/2,-n/2,-i/2,-n/4],r,a,d);break;case"sludgeSilo":this.__box(0,-n/8,i-20,.6*n,o,r,a,d),this.__poly([-i/2+10,.175*n,0,.42*n,i/2-10,.175*n],r,a,d),this.__poly([0,.42*n,0,n/2-2],r,a,d),this.__poly([-8,-n/8-.3*n,8,-n/8-.3*n],r,Tn.detailLineWidth,d);break;case"submersiblePump":{const e=Math.min(i,n)/2-3;this.__circle(0,-2,e,"none",r,a,d);for(let t=0;t<3;t++){const i=2*Math.PI*t/3-Math.PI/2;this.__poly([0,-2,.8*e*Math.cos(i),.8*e*Math.sin(i)-2],r,Tn.detailLineWidth,d)}this.__poly([-e,e+1,e,e+1],r,a,d);break}case"screwPump":this.__box(0,-3,i,n-14,o,r,a,d);for(let e=1;e<=4;e++){const t=-i/2+i/5*e;this.__poly([t-5,-n/2+5,t+5,n/2-11],r,Tn.detailLineWidth,d)}this.__poly([-i/3,n/2-4,i/3,n/2-4],r,a,d);break;case"vfd":this.__box(0,0,i,n,o,r,a,d),this.__poly([-i/4,4,-i/8,-5,0,4,i/8,-5,i/4,4],r,Tn.detailLineWidth,d);break;case"motorValve":this.__closedPoly([-9,8,-9,24,0,16],r,a,d),this.__closedPoly([9,8,9,24,0,16],r,a,d),this.__poly([0,8,0,2],r,Tn.detailLineWidth,d),this.__box(0,-6,22,16,"none",r,Tn.detailLineWidth,d),"closed"===this.state.valveState&&this.__poly([0,6,0,26],"#dc2626",2,d);break;case"checkValve":this.__box(0,0,i-6,n-14,"none",r,a,d),this.__closedPoly([-5,-6,6,0,-5,6],r,Tn.detailLineWidth,d),this.__poly([-i/2+3,0,i/2-3,0],r,Tn.detailLineWidth,d);break;case"levelGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d),this.__poly([.62*-e,6,.2*-e,0,.2*e,10,.62*e,4],r,Tn.detailLineWidth,d),this.__text(l-5,h-1,12,"L",Tn.tagFontSize,r,"center");break}case"pressureGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",r,a,d),this.__poly([0,6,.5*e,.45*-e],r,Tn.detailLineWidth,d),this.__circle(0,6,2,r,r,Tn.detailLineWidth,d),this.__text(l-5,h-1,12,"P",Tn.tagFontSize,r,"center");break}case"inlet":this.__box(10,0,i-20,n-12,o,r,a,d),this.__closedPoly([-i/2+2,0,-i/2+18,-8,-i/2+18,8],r,a,d);break;case"outlet":this.__box(-10,0,i-20,n-12,o,r,a,d),this.__closedPoly([i/2-2,0,i/2-18,-8,i/2-18,8],r,a,d);break;case"sludgeOut":this.__box(0,0,i,n,o,r,a,d);for(let e=-1;e<=1;e++)this.__poly([10*e-5,n/4,10*e+5,-n/4],r,Tn.detailLineWidth,d);break;default:this.__box(0,0,i,n,o,r,a,d)}const c=Math.max(i+24,90),u=l-c/2;this.state.tag&&this.__text(u,-18,c,String(this.state.tag),Tn.tagFontSize,Tn.tagColor,"center");const p=String(this.state.name||"");p&&this.__text(u,n+14,c,p,Tn.nameFontSize,Tn.nameColor,"center")}__box(e,t,n,s,r,a,o,l){return this.__add("box",new i.ICERect({left:this.__originX+e-n/2,top:this.__originY+t-s/2,width:n,height:s,radius:3,zIndex:l,interactive:!1,linkable:!1,style:{fillStyle:r,strokeStyle:a,lineWidth:o}}))}__circle(e,t,n,s,r,a,o){return this.__add("circle:"+e+","+t,new i.ICECircle({left:this.__originX+e-n,top:this.__originY+t-n,radius:n,zIndex:o,interactive:!1,linkable:!1,style:{fillStyle:"none"===s?Tn.hollowFill:s,strokeStyle:r,lineWidth:a}}))}__closedPoly(e,t,i,n){const s=this.__poly(e,t,i,n),r=e[e.length-2],a=e[e.length-1];return this.__poly([r,a,e[0],e[1]],t,i,n),s}__poly(e,t,n,s){const r=[];for(let t=0;t<e.length;t+=2)r.push([e[t]+this.__originX,e[t+1]+this.__originY]);if(2===r.length&&(Math.abs(r[1][0]-r[0][0])<.01||Math.abs(r[1][1]-r[0][1])<.01)){const[e,a]=r[0],[o,l]=r[1],h=Math.abs(a-l)<.01,d=h?Math.min(e,o):Math.min(e,o)-n/2,c=h?Math.min(a,l)-n/2:Math.min(a,l),u=h?Math.abs(o-e):n,p=h?n:Math.abs(l-a);return this.__add("line:"+s+":"+d+","+c,new i.ICERect({left:d,top:c,width:u,height:p,zIndex:s,interactive:!1,linkable:!1,style:{fillStyle:t,strokeStyle:t,lineWidth:0}}))}return this.__add("poly:"+s+":"+r.length,new i.ICEPolyLine({points:r,zIndex:s,interactive:!1,linkable:!1,arrow:"none",lineType:"solid",style:{strokeStyle:t,lineWidth:n}}))}__text(e,t,n,s,r,a){let o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"center";const l=Math.round(1.4*r);return this.__add("text:"+s,new i.ICEText({left:e,top:t,width:n,height:l,text:s,stroke:!1,interactive:!1,linkable:!1,zIndex:(Number(this.state.zIndex)||0)+4,style:{fontSize:r,fillStyle:a,textAlign:o,textBaseline:"middle"}}))}__add(e,t){return this.addChild(t),this.parts.push({role:e,component:t}),t}__clearParts(){this.parts.forEach(e=>{e.component&&e.component.parentNode===this&&this.removeChild(e.component)}),this.parts=[]}}function dashPatternOf(e,t){const i=Math.max(1,t);return"dashed"===e?[4*i,4*i]:"dashdot"===e?[7*i,3*i,1.5*i,3*i]:[]}function composePipeLabel(e,t){const i=Cn[e]||Cn.sewage,n=String(t||"").trim();return n?`${n} ${i.label}`:i.label}class WaterPipe extends FlowEdge{static typeId="ice-entity-designer:WaterPipe";applyMediumStyle(){const e=this.state.medium||"sewage",t=Cn[e]||Cn.sewage,i=void 0===this.state.label||""===this.state.label?composePipeLabel(e,this.state.dn):this.state.label;this.setState({lineType:"solid"===t.lineType?"solid":"dashed",lineDash:dashPatternOf(t.lineType,Number((this.state.style||{}).lineWidth)||1.4),label:i,style:{...this.state.style||{},strokeStyle:t.color,fillStyle:t.color}})}setMedium(e,t){this.setState({medium:e,label:"",dn:void 0===t?this.state.dn:t}),this.applyMediumStyle()}}const Pn={inheritance:"<|--",realization:"<|..",association:"--\x3e",aggregation:"o--",composition:"*--",dependency:"..>"},Mn=[[/<\|\.\./,"realization"],[/<\|--/,"inheritance"],[/\*--/,"composition"],[/o--/,"aggregation"],[/\.\.>/,"dependency"],[/-->/,"association"]];function quoteIfNeeded(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)?e:`"${e}"`}function unquote(e){const t=e.trim();return/^".*"$/.test(t)?t.slice(1,-1).trim():t}exports.BpmnDesigner=class BpmnDesigner extends FlowDesigner{__markers=(()=>new Map)();__markerSyncing=!1;__nesting=!1;constructor(e){super(e),this.subscribe(()=>this.syncFlowMarkers()),this.syncFlowMarkers()}validateBpmn(){return validateBpmn(this)}createNode(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=super.createNode(e,t);return this.__nestByGeometry(i),i}__nestByGeometry(e){if(this.__nesting)return;if("bpmnPool"===e.state.kind)return void e.setState({zIndex:tn});"bpmnLane"===e.state.kind&&e.setState({zIndex:nn});const t=e.getMinBoundingBox(!0),i=(t.tl[0]+t.br[0])/2,n=(t.tl[1]+t.br[1])/2,s=this.nodes.filter(t=>t!==e&&("bpmnPool"===t.state.kind||"bpmnLane"===t.state.kind)).filter(e=>{const t=this.__contentBox(e);return i>=t.tl[0]&&i<=t.br[0]&&n>=t.tl[1]&&n<=t.br[1]}).sort((e,t)=>e.state.width*e.state.height-t.state.width*t.state.height)[0];if(s){this.__nesting=!0;try{const t=s.getMinBoundingBox(!0).tl[0],i=s.getMinBoundingBox(!0).tl[1];e.setState({left:e.state.left-t,top:e.state.top-i}),s.adoptChild(e)}finally{this.__nesting=!1}}}__contentBox(e){const t=e.getMinBoundingBox(!0),i=en[e.state.kind]||{},n=i.band,s=i.bandSize||0;return n&&s?{tl:"top"===n?[t.tl[0],t.tl[1]+s]:[t.tl[0]+s,t.tl[1]],br:t.br}:t}syncFlowMarkers(){if(!this.__markerSyncing){this.__markerSyncing=!0;try{const e=new Set;this.edges.forEach(t=>{if(!!("sequence"!==(t.state.flowType||"sequence")||!t.state.condition&&!t.state.isDefault))return;e.add(t.state.id);const i=t.state.points&&t.state.points.length?t.state.points:[t.state.startPoint,t.state.endPoint],n=i[0]||[0,0],s=i[1]||n,r=s[0]-n[0],a=s[1]-n[1],o=Math.max(Math.hypot(r,a),1),l=n[0]+r/o*16-7,h=n[1]+a/o*16-7,d=t.state.isDefault?"default":"conditional",c=t.state.style&&t.state.style.strokeStyle||"#475569";let u=this.__markers.get(t.state.id);u?(u.setState({left:l,top:h,markerType:d,style:{...u.state.style||{},strokeStyle:c}}),u.dirty=!0):(u=new BpmnFlowMarker({left:l,top:h,width:14,height:14,interactive:!1,draggable:!1,linkable:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,markerType:d,style:{strokeStyle:c,fillStyle:"#ffffff",lineWidth:1.4}}),this.ice.addTool(u),this.__markers.set(t.state.id,u))}),[...this.__markers.keys()].forEach(t=>{if(!e.has(t)){const e=this.__markers.get(t);this.ice.removeTool(e),this.__markers.delete(t)}})}finally{this.__markerSyncing=!1}}}dispose(){this.__markers.forEach(e=>this.ice.removeTool(e)),this.__markers.clear(),super.dispose()}},exports.BpmnSimulator=class BpmnSimulator{tokens=[];visited=(()=>new Set)();running=!1;finished=!1;started=!1;nodeDurations=(()=>new Map)();nodeDuration=400;edgeDuration=600;seq=0;lastFrameAt=0;frameHandler=null;hostContinuousFrames=null;constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.designer=e,void 0!==t.nodeDuration&&(this.nodeDuration=t.nodeDuration),void 0!==t.edgeDuration&&(this.edgeDuration=t.edgeDuration)}setNodeDuration(e,t){this.nodeDurations.set(e,Math.max(0,Number(t)||0))}setEdgeDuration(e){this.edgeDuration=Math.max(1,Number(e)||600)}isRunning(){return this.running}isFinished(){return this.started&&0===this.tokens.length}getTokens(){return this.tokens}getVisitedNodeIds(){return[...this.visited]}start(){this.stop(),this.started=!0,this.finished=!1;const e=this.designer.nodes.filter(e=>"bpmnEvent"===e.state.kind&&"start"===(e.state.eventKind||"start"));e.forEach(e=>this.__spawn(e.state.id)),e.length||(this.finished=!0),this.running=!0,this.__acquireContinuousFrames(),this.frameHandler=()=>{const e=Date.now(),t=this.lastFrameAt?Math.min(100,e-this.lastFrameAt):16;this.lastFrameAt=e,this.step(t)},this.designer.ice&&this.designer.ice.evtBus&&this.designer.ice.evtBus.on(i.ICE_EVENT_NAME_CONSTS.ICE_FRAME_EVENT,this.frameHandler,this)}stop(){this.frameHandler&&this.designer.ice&&this.designer.ice.evtBus&&this.designer.ice.evtBus.off(i.ICE_EVENT_NAME_CONSTS.ICE_FRAME_EVENT,this.frameHandler,this),this.frameHandler=null,this.__releaseContinuousFrames(),this.tokens.forEach(e=>this.__removeComponent(e)),this.tokens=[],this.running=!1,this.lastFrameAt=0}__acquireContinuousFrames(){const e=this.designer&&this.designer.ice;e&&"function"==typeof e.setContinuousFrames&&(null===this.hostContinuousFrames&&(this.hostContinuousFrames="function"==typeof e.isContinuousFrames&&!!e.isContinuousFrames()),e.setContinuousFrames(!0))}__releaseContinuousFrames(){const e=this.designer&&this.designer.ice;e&&"function"==typeof e.setContinuousFrames&&null!==this.hostContinuousFrames&&(e.setContinuousFrames(this.hostContinuousFrames),this.hostContinuousFrames=null)}reset(){this.stop(),this.visited.clear(),this.started=!1,this.finished=!1}step(e){if(!this.tokens.length)return void(this.started&&(this.finished=!0,this.running=!1));const t=Math.max(0,Number(e)||0),i=[];this.tokens.forEach(e=>{if(e.edgeId)return e.progress+=t/this.edgeDuration,e.progress>=1&&this.__arriveAtNode(e,e.edgeId),this.__syncPosition(e),void(e.nodeId&&i.push(e));e.dwellRemaining-=t,e.dwellRemaining>0?i.push(e):this.__leaveNode(e,i)}),this.tokens=i,this.tokens.length||(this.finished=!0,this.running=!1)}__pickExclusive(e){const t=e.filter(e=>""!==String(e.state.condition||"").trim());if(t.length)return t[0];const i=e.filter(e=>!e.state.isDefault);return i.length?i[0]:e[0]}__spawn(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;const n=this.designer.ice.findComponent(e),s={id:"sim-token-"+ ++this.seq,nodeId:e,edgeId:t,progress:i,position:this.__nodePosition(n),dwellRemaining:this.nodeDurations.get(e)||this.nodeDuration,component:null},r=new SimTokenDot({left:s.position[0]-7,top:s.position[1]-7,style:{fillStyle:"#f97316"}});return s.component=r,this.designer.ice.addTool(r),this.visited.add(e),this.tokens.push(s),t&&this.__syncPosition(s),s}__arriveAtNode(e,t){const i=this.designer.ice.findComponent(t),n=i&&i.state.links||{},s=n.end&&n.end.id,r=s?this.designer.ice.findComponent(s):null;e.edgeId=null,e.progress=0,e.nodeId=s,e.position=this.__nodePosition(r),e.dwellRemaining=this.nodeDurations.get(s)||this.nodeDuration,this.visited.add(s);r&&"bpmnEvent"===r.state.kind&&("end"===(r.state.eventKind||"start")||"terminate"===r.state.trigger)&&(e.nodeId="",this.__removeComponent(e)),this.__syncPosition(e)}__leaveNode(e,t){const i=this.designer.ice.findComponent(e.nodeId),n=this.designer.edges.filter(t=>{const i=t.state.links||{};return i.start&&i.start.id===e.nodeId&&"sequence"===(t.state.flowType||"sequence")});if(!i||!n.length)return e.nodeId="",void this.__removeComponent(e);("bpmnGateway"===i.state.kind&&"exclusive"!==i.state.gatewayType?n:[this.__pickExclusive(n)]).forEach((i,n)=>{if(0===n)return e.edgeId=i.state.id,e.progress=0,e.dwellRemaining=0,void t.push(e);const s=this.__spawn(e.nodeId,i.state.id,0);s.dwellRemaining=0,t.push(s)})}__syncPosition(e){if(e.edgeId){const t=this.designer.ice.findComponent(e.edgeId),i=t&&t.state.points||[];e.position=function pointAt(e,t){if(!e||0===e.length)return[0,0];if(1===e.length)return[...e[0]];const i=[];let n=0;for(let t=1;t<e.length;t++){const s=Math.hypot(e[t][0]-e[t-1][0],e[t][1]-e[t-1][1]);i.push(s),n+=s}if(n<=0)return[...e[0]];let s=Math.max(0,Math.min(1,t))*n;for(let t=0;t<i.length;t++){if(s<=i[t]||t===i.length-1){const n=i[t]>0?s/i[t]:0,r=e[t],a=e[t+1];return[r[0]+(a[0]-r[0])*n,r[1]+(a[1]-r[1])*n]}s-=i[t]}return[...e[e.length-1]]}(i,e.progress)}if(e.component){const t=e.component.state.radius||7;e.component.setPosition(e.position[0]-t,e.position[1]-t)}}__nodePosition(e){if(!e)return[0,0];const t=e.getMinBoundingBox(!0);return[t.center[0],t.center[1]]}__removeComponent(e){e.component&&this.designer.ice&&(this.designer.ice.removeTool(e.component),e.component=null)}},exports.DESIGNER_CHROME=Ai,exports.DESIGNER_CHROME_ANTD=zi,exports.Entity=Entity,exports.EntityDesigner=class EntityDesigner{selectedId=null;__changeListeners=[];__mousedownHandler=e=>this.__handleMouseDown(e);__undoStack=[];__redoStack=[];__historyEnabled=!0;__maxHistory=100;constructor(e){this.ice=e,applyDesignerChrome(this.ice),enableDesignerAlignmentGuides(this.ice),registerIEDType(this.ice,Entity),registerIEDType(this.ice,Relation),this.ice.evtBus.on("mousedown",this.__mousedownHandler,this)}get entities(){return this.ice.childNodes.filter(e=>isEntity(e))}get relations(){return this.ice.childNodes.filter(e=>isRelation(e))}get selected(){return this.selectedId?this.ice.findComponent(this.selectedId):null}select(e){return this.selectedId=e,this}createEntity(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.captureHistory();const t=this.entities.length,i=new Entity({left:120+t%4*220,top:120+260*Math.floor(t/4),entityName:"NewEntity",fields:[],...e});return this.ice.addChild(i),this.select(i.state.id),this.__emitChange(),i}createRelation(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.captureHistory();const t=e.sourceId||e.fromId||e.links&&e.links.start&&e.links.start.id,i=e.targetId||e.toId||e.links&&e.links.end&&e.links.end.id,n=t?this.ice.findComponent(t):null,s=i?this.ice.findComponent(i):null,r=autoPorts(n,s,{sourcePort:"R",targetPort:"L"}),a=e.links&&e.links.start&&e.links.start.position||e.startPosition||r.sourcePort,o=e.links&&e.links.end&&e.links.end.position||e.endPosition||r.targetPort,l=e.links||{start:{id:t,position:a},end:{id:i,position:o}},h=n?this.__slotPoint(n,a):null,d=s?this.__slotPoint(s,o):null,c=new Relation({relationType:e.relationType||"one-to-many",sourceField:e.sourceField||"id",targetField:e.targetField||"id",links:l,startPoint:h||[0,0],endPoint:d||[10,10],...e});return this.ice.addChild(c),this.select(c.state.id),this.__emitChange(),c}updateEntity(e,t){const i=this.ice.findComponent(e);return isEntity(i)&&(this.captureHistory(),i.setState(t),this.__emitChange()),i}updateRelation(e,t){const i=this.ice.findComponent(e);if(isRelation(i)){this.captureHistory();const e={...i.state,...t},n=Relation.buildLabel(e,e.relationType||"one-to-one");i.setState({...t,label:n}),this.__emitChange()}return i}removeComponent(e){const t=this.ice.findComponent(e);if(t){if(this.captureHistory(),isEntity(t)){this.relations.filter(t=>{const i=t.state.links||{};return i.start&&i.start.id===e||i.end&&i.end.id===e}).forEach(e=>this.ice.removeChild(e))}this.ice.removeChild(t),this.selectedId===e&&(this.selectedId=null),this.__emitChange()}}bringToFront(e){return this.__reorder(e,"front")}sendToBack(e){return this.__reorder(e,"back")}moveUp(e){return this.__reorder(e,"up")}moveDown(e){return this.__reorder(e,"down")}__reorder(e,t){const i=e?this.ice.findComponent(e):this.selected;if(!i||"function"!=typeof i.bringToFront)return!1;const n=i.parentNode&&Array.isArray(i.parentNode.childNodes)?i.parentNode.childNodes:this.ice.childNodes;if(!Array.isArray(n)||n.length<2)return!1;const s=this.serializeProject(),r=n.map(e=>e.state.zIndex);"front"===t?i.bringToFront():"back"===t?i.sendToBack():"up"===t?i.moveUp():i.moveDown();const a=n.map(e=>e.state.zIndex);return!(r.length===a.length&&!r.some((e,t)=>e!==a[t]))&&(this.__pushHistory(s),this.__emitChange(),!0)}toSchemaObject(){return toSchemaObject(this.ice.childNodes)}toSchemaString(){return toSchemaString(this.ice.childNodes)}validate(){return validateSchema(this.ice.childNodes)}serializeProject(){const e={version:1,schemaVersion:1,createTime:i.toIsoTime(this.ice&&this.ice.documentMeta&&this.ice.documentMeta.createTime)||this.__rememberCreateTime(void 0),entities:this.entities.map(e=>this.__entitySnapshot(e)),relations:this.relations.map(e=>this.__relationSnapshot(e))};return JSON.stringify(e)}__rememberCreateTime(e){const t=this.ice;t&&"object"==typeof t&&(t.documentMeta&&"object"==typeof t.documentMeta||(t.documentMeta={}));const n=i.toIsoTime(e);if(n)return t&&t.documentMeta&&(t.documentMeta.createTime=n),n;const s=(new Date).toISOString();return t&&t.documentMeta&&(t.documentMeta.createTime=s),s}loadProject(e){if(!e)return{loaded:!1,entities:0,relations:0,unknownTypes:[],skipped:[]};const t=this.__parseProject(e);if(!t)return{loaded:!1,entities:0,relations:0,unknownTypes:[],skipped:[]};this.captureHistory();const i=this.__applySnapshot(t);return this.__emitChange(),i}__entitySnapshot(e){return pickDocumentNode({...e.state||{},typeId:Entity.typeId},Hi)}__slotPoint(e,t){const i=e.getMinBoundingBox(!0),n=i.center[0],s=i.center[1];switch(t){case"T":return[n,i.tl[1]];case"B":return[n,i.br[1]];case"L":return[i.tl[0],s];case"R":return[i.tr[0],s];default:return[n,s]}}__relationSnapshot(e){return pickDocumentNode({...e.state||{},typeId:Relation.typeId},Gi)}__parseProject(e){const t=JSON.parse(e);if(!t||!Array.isArray(t.entities))return null;if(void 0!==t.schemaVersion&&1!==t.schemaVersion)throw new Error(`Unsupported project schemaVersion: ${t.schemaVersion}`);const i=validateProjectSnapshot(t);if(!i.valid)throw new Error(`Invalid project snapshot:\n${i.errors.join("\n")}`);return t}__applyProject(e){const t=this.__parseProject(e);t&&this.__applySnapshot(t)}__resolveTypeId(e,t){return e&&"string"==typeof e.typeId&&e.typeId?e.typeId:"entities"===t?Entity.typeId:Relation.typeId}__resolveComponentClass(e){const t=this.ice;if("function"==typeof t.getType){const i=t.getType(e);if("function"==typeof i)return i}else if(t.typeMapping&&"function"==typeof t.typeMapping[e])return t.typeMapping[e];return e===Entity.typeId?Entity:e===Relation.typeId?Relation:null}__recordUnknownType(e,t,i,n,s){-1===e.unknownTypes.indexOf(n)&&e.unknownTypes.push(n);const r=s&&"string"==typeof s.id?s.id:void 0;e.skipped.push(void 0===r?{bucket:t,index:i,typeId:n}:{bucket:t,index:i,typeId:n,id:r})}__applySnapshot(e){const t=this.ice.renderer;t&&t.stop();const i={loaded:!0,entities:0,relations:0,unknownTypes:[],skipped:[]};try{this.ice.clearAll(),this.__rememberCreateTime(e&&e.createTime),this.ice.ctx&&"function"==typeof this.ice.ctx.clearRect&&(this.ice.ctx.setTransform(1,0,0,1,0,0),this.ice.ctx.clearRect(0,0,this.ice.canvasWidth||0,this.ice.canvasHeight||0));const createNode=(e,t,n)=>{const s=this.__resolveTypeId(e,t),r=this.__resolveComponentClass(s);if("function"!=typeof r)return this.__recordUnknownType(i,t,n,s,e),null;const a=new r(e);return delete a.state.typeId,delete a.props.typeId,this.ice.addChild(a),a},collect=(e,t,n)=>{const s=createNode(e,t,n);isEntity(s)?i.entities+=1:isRelation(s)&&(i.relations+=1)};e.entities.forEach((e,t)=>collect(e,"entities",t)),(e.relations||[]).forEach((e,t)=>collect(e,"relations",t)),this.selectedId=null}finally{if(t){const e=t.getRenderMode();t.setRenderMode("full"),t.start(),this.ice.dirty=!0,setTimeout(()=>{t.setRenderMode(e)},50)}}return i}__applyHistorySnapshot(e){this.__historyEnabled=!1;try{this.__applyProject(e),this.selectedId=null}finally{this.__historyEnabled=!0}}canUndo(){return this.__undoStack.length>0}canRedo(){return this.__redoStack.length>0}captureHistory(){this.__historyEnabled&&this.__pushHistory(this.serializeProject())}__pushHistory(e){this.__historyEnabled&&(this.__undoStack.push(e),this.__undoStack.length>this.__maxHistory&&this.__undoStack.shift(),this.__redoStack.length=0)}undo(){if(!this.canUndo())return;const e=this.serializeProject(),t=this.__undoStack.pop();try{this.__applyHistorySnapshot(t)}catch(e){throw this.__undoStack.push(t),e}this.__redoStack.push(e),this.__emitChange()}redo(){if(!this.canRedo())return;const e=this.serializeProject(),t=this.__redoStack.pop();try{this.__applyHistorySnapshot(t)}catch(e){throw this.__redoStack.push(t),e}this.__undoStack.push(e),this.__emitChange()}subscribe(e){return"function"!=typeof e?()=>{}:(this.__changeListeners.push(e),()=>{const t=this.__changeListeners.indexOf(e);-1!==t&&this.__changeListeners.splice(t,1)})}__emitChange(){if(!this.__changeListeners.length)return;const e=this.serializeProject();this.__changeListeners.slice().forEach(t=>t(e))}dispose(){this.ice.evtBus.off("mousedown",this.__mousedownHandler,this)}__handleMouseDown(e){const t=e&&e.param&&e.param.component;if(!t)return;let i=t;for(;i.parentNode;)i=i.parentNode;(isEntity(i)||isRelation(i))&&this.select(i.state.id)}},exports.FLOW_NODE_KINDS=en,exports.FlowDesigner=FlowDesigner,exports.FlowDiamond=FlowDiamond,exports.FlowEdge=FlowEdge,exports.FlowNode=FlowNode,exports.FlowParallelogram=FlowParallelogram,exports.GanttDependency=GanttDependency,exports.GanttDesigner=class GanttDesigner extends FlowDesigner{labelColumnWidth=140;headerHeight=34;rowHeight=36;dayWidth=28;originDate="";ruler=null;__syncing=!1;constructor(e){super(e),registerIEDType(this.ice,GanttTask),registerIEDType(this.ice,GanttDependency),registerIEDType(this.ice,GanttRuler)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===GanttTask.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===GanttDependency.typeId)}createTask(e){this.__captureHistory();const t=new GanttTask({id:e.id,title:e.title||"任务",start:e.start,days:e.days||3,progress:e.progress||0,resource:e.resource||"",row:void 0===e.row?this.nodes.length:e.row,dayWidth:this.dayWidth,originDate:this.originDate||e.start,labelColumnWidth:this.labelColumnWidth,rowHeight:this.rowHeight,headerHeight:this.headerHeight});return this.ice.addChild(t),this.__attachNodeListeners(t),this.selectedId=t.state.id,this.syncChrome(),this.__emitChange(),t}createDependency(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("依赖两端必须是已存在的任务");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"R",targetPort:"L"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=this.__anchor(t,s),o=this.__anchor(i,r),l=new GanttDependency({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},points:[a,o],startPoint:a,endPoint:o});return this.ice.addChild(l),this.selectedId=l.state.id,this.__emitChange(),l}setDayWidth(e){this.dayWidth=Math.max(4,Math.round(Number(e)||0)||28),this.nodes.forEach(e=>{e.setState({dayWidth:this.dayWidth})}),this.syncChrome(),this.__emitChange()}updateTask(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.ice.findComponent(e);return i&&i.constructor.typeId===GanttTask.typeId?(this.__captureHistory(),i.applyPatch(t),this.syncChrome(),this.__emitChange(),i):null}autoSchedule(){if(this.validateGantt().some(e=>"error"===e.level&&e.message.includes("成环")))return;const e=this.nodes;if(!e.length)return;this.__captureHistory();const t=new Map;e.forEach(e=>t.set(e.state.id,e));const i=new Map;e.forEach(e=>i.set(e.state.id,[])),this.edges.forEach(e=>{const t=e.state.links||{},n=t.start&&t.start.id,s=t.end&&t.end.id;n&&s&&i.has(s)&&i.get(s).push(n)});const n=new Map,s=new Map;e.forEach(e=>{n.set(e.state.id,(i.get(e.state.id)||[]).length),s.set(e.state.id,[])}),i.forEach((e,t)=>{e.forEach(e=>s.get(e).push(t))});const r=e.filter(e=>0===(n.get(e.state.id)||0)).map(e=>e.state.id),a=[];for(;r.length;){const e=r.shift();a.push(e),(s.get(e)||[]).forEach(e=>{n.set(e,(n.get(e)||0)-1),0===(n.get(e)||0)&&r.push(e)})}a.forEach(e=>{const n=t.get(e),s=(i.get(e)||[]).reduce((e,i)=>{const n=t.get(i),s=addDays(n.state.start,Math.max(1,Number(n.state.days)||1));return diffDays(e,s)>0?s:e},n.state.start);diffDays(n.state.start,s)>0&&n.applyPatch({start:s})}),this.syncChrome(),this.__emitChange()}criticalPath(){const e=this.nodes;if(!e.length)return[];const t=new Map;e.forEach(e=>t.set(e.state.id,e));const i=new Map,n=new Map;e.forEach(e=>{i.set(e.state.id,[]),n.set(e.state.id,[])}),this.edges.forEach(e=>{const t=e.state.links||{},s=t.start&&t.start.id,r=t.end&&t.end.id;s&&r&&i.has(r)&&i.has(s)&&(i.get(r).push(s),n.get(s).push(r))});const durationOf=e=>Math.max(1,Number(e.state.days)||1),s=[],r=new Map;e.forEach(e=>r.set(e.state.id,(i.get(e.state.id)||[]).length));const a=e.filter(e=>0===(r.get(e.state.id)||0)).map(e=>e.state.id);for(;a.length;){const e=a.shift();s.push(e),(n.get(e)||[]).forEach(e=>{r.set(e,(r.get(e)||0)-1),0===(r.get(e)||0)&&a.push(e)})}if(s.length!==e.length)return[];const o=new Map;s.forEach(e=>{const n=t.get(e),s=i.get(e)||[];let r=s.length?"":n.state.start;s.forEach(e=>{const i=t.get(e),n=addDays(o.get(e),durationOf(i));(!r||diffDays(r,n)>0)&&(r=n)}),o.set(e,r)});let l="";e.forEach(e=>{const t=addDays(o.get(e.state.id),durationOf(e));(!l||diffDays(l,t)>0)&&(l=t)});const h=new Map;return[...s].reverse().forEach(e=>{const i=t.get(e),s=n.get(e)||[];if(!s.length)return void h.set(e,addDays(l,-durationOf(i)));const r=s.reduce((e,t)=>{const i=h.get(t);return!e||diffDays(i,e)>0?i:e},null);h.set(e,addDays(r,-durationOf(i)))}),e.filter(e=>{const t=h.get(e.state.id);return 0===diffDays(o.get(e.state.id),t)})}computeOrigin(){const e=this.nodes.map(e=>e.state.start).filter(e=>!!e);return e.length?e.reduce((e,t)=>diffDays(e,t)<0?t:e):this.originDate||""}dayCount(){const e=this.nodes;if(!e.length)return 14;let t=this.originDate||e[0].state.start;return e.forEach(e=>{const i=addDays(e.state.start,Math.max(1,Number(e.state.days)||1));diffDays(t,i)>0&&(t=i)}),Math.max(1,diffDays(this.originDate,t)+1)}syncChrome(){if(!this.__syncing){this.__syncing=!0;try{this.originDate=this.computeOrigin();const e=this.nodes;this.ruler||(this.ruler=new GanttRuler,this.ice.addChild(this.ruler)),this.ruler.setState({zIndex:-1e4}),e.forEach((e,t)=>{const i={dayWidth:this.dayWidth,originDate:this.originDate,labelColumnWidth:this.labelColumnWidth,rowHeight:this.rowHeight,headerHeight:this.headerHeight};void 0!==e.state.row&&null!==e.state.row||(i.row=t),e.setState(i)}),this.ruler.sync({dayWidth:this.dayWidth,labelColumnWidth:this.labelColumnWidth,headerHeight:this.headerHeight,rowHeight:this.rowHeight,originDate:this.originDate,dayCount:this.dayCount(),tasks:e.map(e=>({title:e.state.title,row:Number(e.state.row)||0})),totalWidth:0,totalHeight:0}),this.ice.renderer&&this.ice.renderer.markQueueDirty()}finally{this.__syncing=!1}}}validateGantt(){const e=[],t=this.nodes,i=new Map;t.forEach(e=>{const t=String(e.state.resource||"").trim();t&&(i.has(t)||i.set(t,[]),i.get(t).push(e))}),i.forEach((t,i)=>{for(let n=0;n<t.length;n++)for(let s=n+1;s<t.length;s++){const r=t[n],a=t[s],o=addDays(r.state.start,Math.max(1,Number(r.state.days)||1)),l=addDays(a.state.start,Math.max(1,Number(a.state.days)||1));diffDays(r.state.start,l)>0&&diffDays(a.state.start,o)>0&&e.push({level:"warning",message:`资源冲突:「${i}」同时被「${r.state.title}」与「${a.state.title}」占用`,id:a.state.id})}}),t.forEach(t=>{const i=Number(t.state.progress);i>=0&&i<=1||e.push({level:"error",message:`任务「${t.state.title}」的进度必须在 0~1 之间`,id:t.state.id}),Number(t.state.days)>=1||e.push({level:"error",message:`任务「${t.state.title}」的持续天数必须 ≥ 1`,id:t.state.id})});const n=new Set(t.map(e=>e.state.id)),s=new Map;t.forEach(e=>s.set(e.state.id,[])),this.edges.forEach(t=>{const i=t.state.links||{},r=i.start&&i.start.id,a=i.end&&i.end.id;r&&a&&n.has(r)&&n.has(a)?s.get(r).push(a):e.push({level:"error",message:"依赖两端必须都是已存在的任务",id:t.state.id})});const r=new Map,a=[],visit=i=>{r.set(i,1),a.push(i);for(const n of s.get(i)||[]){const s=r.get(n)||0;if(1===s){const s=a.indexOf(n),o=a.slice(s>=0?s:0).concat(n).map(e=>{const i=t.find(t=>t.state.id===e);return i&&i.state.title||e});return e.push({level:"error",message:`依赖成环:${o.join(" → ")}`,id:i}),r.set(i,2),a.pop(),!0}if(0===s&&visit(n))return r.set(i,2),a.pop(),!0}return r.set(i,2),a.pop(),!1};return t.forEach(e=>{0===(r.get(e.state.id)||0)&&visit(e.state.id)}),e}__anchor(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}contentComponents(){return this.ruler?this.nodes.concat([this.ruler]):this.nodes}fitViewportAlign="start"},exports.GanttRuler=GanttRuler,exports.GanttTask=GanttTask,exports.POWER_STYLE=vn,exports.POWER_SYMBOL_KINDS=["busbar","breaker","disconnector","loadSwitch","earthingSwitch","earth","currentTransformer","voltageTransformer","transformer","fuse","arrester","reactor","generator","motor","load","capacitor","arcSuppressionCoil","threeWindingTransformer","groundingTransformer","groundingResistor","cable","cableTermination","cubicle"],exports.POWER_SYMBOL_PRESETS=bn,exports.POWER_VOLTAGE_LEVELS=yn,exports.PROJECT_SCHEMA_VERSION=1,exports.PowerDesigner=class PowerDesigner extends FlowDesigner{voltageColors=(()=>defaultVoltageColors())();constructor(e){super(e),registerIEDType(this.ice,PowerSymbol),registerIEDType(this.ice,PowerLine)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===PowerSymbol.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===PowerLine.typeId)}setVoltageColors(e){this.voltageColors={...this.voltageColors,...e||{}},this.nodes.forEach(e=>e.applyPatch({voltageColors:this.voltageColors})),this.edges.forEach(e=>e.applyVoltageColor(this.voltageColors)),this.ice.dirty=!0}createSymbol(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new PowerSymbol({kind:e,voltageColors:this.voltageColors,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}createLine(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("导体两端必须是已存在的设备");this.__captureHistory();const n=e.sourcePort||"B",s=e.targetPort||"T",r=new PowerLine({id:e.id,links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,n),endPoint:this.__slotPoint(i,s),voltageLevel:e.voltageLevel||t.state.voltageLevel||i.state.voltageLevel||"",arrow:"none",linkShape:"visio"});return r.applyVoltageColor(this.voltageColors),this.ice.addChild(r),this.selectedId=r.state.id,this.__emitChange(),r}setSwitchState(e,t){const i=this.__symbolById(e);if(!i)return null;if(-1===kn.indexOf(i.state.kind))throw new Error("只有断路器 / 隔离开关 / 负荷开关 / 接地开关才有分合状态");return this.__captureHistory(),i.applyPatch({switchState:t}),this.applyTopology(),this.__emitChange(),i}setEnergizedSource(e,t){const i=this.__symbolById(e);return i?(this.__captureHistory(),i.setState({energizedSource:!!t}),this.applyTopology(),this.__emitChange(),i):null}applyTopology(){const e=this.topology(),t=new Set(e.energized);return this.nodes.forEach(e=>{const i=t.has(e.state.id);e.state.energized!==i&&e.setState({energized:i})}),this.ice.dirty=!0,e}topology(){const e=this.nodes,t=new Map;e.forEach(e=>t.set(e.state.id,e));const i=this.__buildAdjacency(),isClosed=e=>{const i=t.get(e);return!i||-1===kn.indexOf(i.state.kind)||"closed"===i.state.switchState},n=new Set,s=[];for(e.filter(e=>e.state.energizedSource).forEach(e=>{n.add(e.state.id),s.push(e.state.id)});s.length;){const e=s.shift();(i.get(e)||[]).forEach(i=>{n.has(i)||(-1===kn.indexOf((t.get(i)||{state:{}}).state.kind)||isClosed(i)?(isClosed(e)||e===i)&&(n.add(i),s.push(i)):n.add(i))})}const r=new Set,a=[];return e.forEach(e=>{if(r.has(e.state.id))return;const t=[],n=[e.state.id];for(r.add(e.state.id);n.length;){const e=n.pop();t.push(e),(i.get(e)||[]).forEach(e=>{r.has(e)||(r.add(e),n.push(e))})}a.push(t)}),{energized:Array.from(n),islands:a}}validatePower(){const e=[],t=this.nodes,i=new Map;t.forEach(e=>i.set(e.state.id,e));const n=new Map;t.forEach(t=>{const i=String(t.state.name||"").trim();i&&(n.has(i)?e.push({level:"error",message:`设备编号重复:「${i}」(同一张图上编号必须唯一)`,id:t.state.id}):n.set(i,t))});const s=this.__buildAdjacency();this.edges.forEach(t=>{const n=t.state.links||{},s=i.get(n.start&&n.start.id),r=i.get(n.end&&n.end.id);if(!s||!r)return;const a=String(s.state.voltageLevel||""),o=String(r.state.voltageLevel||"");"transformer"!==s.state.kind&&"transformer"!==r.state.kind&&a&&o&&a!==o&&e.push({level:"error",message:`电压等级不一致:${s.state.name||s.state.kind}(${a}) 与 ${r.state.name||r.state.kind}(${o}) 直接相连,中间没有变压器`,id:t.state.id})});const r=this.topology(),a=t.filter(e=>e.state.energizedSource).map(e=>e.state.id);t.filter(e=>"busbar"===e.state.kind).forEach(t=>{(r.islands.find(e=>-1!==e.indexOf(t.state.id))||[]).some(e=>-1!==a.indexOf(e))||e.push({level:"warning",message:`母线「${t.state.name||"未命名"}」没有进线电源(该连通域里没有电源点)`,id:t.state.id})});t.filter(e=>"breaker"===e.state.kind).filter(e=>function kilovoltsOf(e){const t=/(\d+(?:\.\d+)?)/.exec(String(e||""));return t?Number(t[1]):0}(e.state.voltageLevel)>=110).forEach(t=>{(s.get(t.state.id)||[]).filter(e=>((e,t)=>{const n=new Set([e]);let r=[t];for(let e=0;e<3&&r.length;e+=1){const e=[];for(const t of r){if(n.has(t))continue;n.add(t);const r=i.get(t);if(!r)continue;const a=r.state.kind;if("disconnector"===a)return!0;-1===kn.indexOf(a)&&"busbar"!==a&&(s.get(t)||[]).forEach(t=>e.push(t))}r=e}return!1})(t.state.id,e)).length<2&&e.push({level:"warning",message:`断路器「${t.state.name||"未命名"}」两侧隔离开关不足(检修时需要可见断口)`,id:t.state.id})}),t.forEach(t=>{const i=this.attachedBusOf(t);if(!i)return;const n=String(t.state.voltageLevel||""),s=String(i.state.voltageLevel||"");n&&s&&n!==s&&e.push({level:"error",message:`电压等级不一致:设备「${t.state.name||t.state.kind}」(${n}) 挂到了母线「${i.state.name||"未命名"}」(${s}) 上`,id:t.state.id})});const o=new Set(r.energized);return t.filter(e=>"earthingSwitch"===e.state.kind).forEach(t=>{if(!("closed"===t.state.switchState))return;(s.get(t.state.id)||[]).filter(e=>o.has(e)).length&&e.push({level:"error",message:`带电合接地刀闸:接地开关「${t.state.name||"未命名"}」在合位,且该点带电(五防:禁止带电挂接地线)`,id:t.state.id})}),t.forEach(t=>{const i=this.attachedBusOf(t);i&&!this.isAttachedToBus(t)&&e.push({level:"warning",message:`设备「${t.state.name||t.state.kind}」挂在母线「${i.state.name||"未命名"}」上但已经拖离,需要重新贴合或补一段导体`,id:t.state.id})}),t.forEach(t=>{0===(s.get(t.state.id)||[]).length&&e.push({level:"warning",message:`设备「${t.state.name||t.state.kind}」没有任何连接(孤立设备)`,id:t.state.id})}),e}attachToBus(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n="string"==typeof e?this.__symbolById(e):e,s="string"==typeof t?this.__symbolById(t):t;if(!n||!s)throw new Error("attachToBus:设备与母线都必须已存在");if("busbar"!==s.state.kind)throw new Error("attachToBus:第二个参数必须是母线(busbar)");if(n===s)throw new Error("attachToBus:母线不能挂到自己身上");const r=this.attachedBusOf(n);if(r&&r!==s)throw new Error("attachToBus:设备已经挂在另一条母线上,请先断开");this.__captureHistory();const a=s.getMinBoundingBox(!0),o=n.getMinBoundingBox(!0).tc[0],l=Math.min(Math.max(void 0===i.centerX?o:i.centerX,a.tl[0]+24),a.br[0]-24);return n.setState({attachedBusId:s.state.id,left:l-n.state.width/2,top:(a.tl[1]+a.br[1])/2+3}),this.__watchBusMove(s),this.applyTopology(),this.__emitChange(),n}attachedBusOf(e){const t=e&&e.state&&e.state.attachedBusId;return t?this.__symbolById(t):null}isAttachedToBus(e){const t=this.attachedBusOf(e);if(!t)return!1;const i=t.getMinBoundingBox(!0),n=e.getMinBoundingBox(!0),s=(i.tl[1]+i.br[1])/2+3,r=Math.abs(n.tl[1]-s)<=8,a=n.tc[0]>=i.tl[0]&&n.tc[0]<=i.br[0];return r&&a}detachFromBus(e){const t="string"==typeof e?this.__symbolById(e):e;return t?(this.__captureHistory(),t.setState({attachedBusId:""}),this.applyTopology(),this.__emitChange(),t):null}__watchBusMove(e){e&&!e.__powerBusWatched&&(e.__powerBusWatched=!0,e.on(i.ICE_EVENT_NAME_CONSTS.AFTER_MOVE,()=>{const t=this.nodes.filter(t=>t.state.attachedBusId===e.state.id);if(!t.length)return;const i=e.getMinBoundingBox(!0),n=e.__powerBusLastBox||i,s=i.tl[0]-n.tl[0],r=i.tl[1]-n.tl[1];e.__powerBusLastBox=i,(s||r)&&t.forEach(e=>{e.getMinBoundingBox&&e.setState({left:e.state.left+s,top:e.state.top+r})})},this),e.__powerBusLastBox=e.getMinBoundingBox(!0))}__buildAdjacency(){const e=new Map;this.nodes.forEach(t=>e.set(t.state.id,[]));const link=(t,i)=>{e.has(t)&&e.has(i)&&(e.get(t).push(i),e.get(i).push(t))};return this.edges.forEach(e=>{const t=e.state.links||{},i=t.start&&t.start.id,n=t.end&&t.end.id;i&&n&&link(i,n)}),this.nodes.forEach(e=>{const t=this.attachedBusOf(e);t&&this.isAttachedToBus(e)&&link(t.state.id,e.state.id)}),e}__symbolById(e){return this.nodes.find(t=>t.state.id===e)||null}},exports.PowerLine=PowerLine,exports.PowerSymbol=PowerSymbol,exports.Relation=Relation,exports.SECONDARY_STYLE=Sn,exports.SECONDARY_SYMBOL_KINDS=["contactNO","contactNC","pushButton","switchRemoteLocal","linkPlate","indicatorLamp","relayDevice","ctWinding","terminal","earth"],exports.SECONDARY_SYMBOL_PRESETS=wn,exports.STATECHART_NODE_KINDS=["initial","final","state","composite"],exports.SecondaryDesigner=class SecondaryDesigner extends FlowDesigner{constructor(e){super(e),registerIEDType(this.ice,SecondarySymbol),registerIEDType(this.ice,SecondaryWire),registerIEDType(this.ice,TerminalStrip)}get nodes(){return this.__flatten().filter(e=>e.constructor&&(e.constructor.typeId===SecondarySymbol.typeId||e.constructor.typeId===TerminalStrip.typeId))}get symbols(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===SecondarySymbol.typeId)}get terminals(){return this.symbols.filter(e=>"terminal"===e.state.kind)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===SecondaryWire.typeId)}createSymbol(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new SecondarySymbol({kind:e,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}createWire(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=normalizeLabelStyle(e);const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("二次导线两端必须是已存在的元件");this.__captureHistory();const n=e.sourcePort||"B",s=e.targetPort||"T",r=new SecondaryWire({id:e.id,links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,n),endPoint:this.__slotPoint(i,s),label:e.circuitNo||"",circuitNo:e.circuitNo||"",cableNo:e.cableNo||"",style:{strokeStyle:"#475569",fillStyle:"#475569",lineWidth:1.4,...e.style||{},label:{fontSize:11,fillStyle:"#1f2937",backgroundColor:"#ffffff",...(e.style||{}).label||{}}}});return this.ice.addChild(r),this.selectedId=r.state.id,this.__emitChange(),r}createTerminalStrip(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.terminals||[],i=new TerminalStrip({title:e.title||"端子排",left:void 0===e.left?40:e.left,top:void 0===e.top?40:e.top,width:e.width||96,height:Math.max(34*(t.length+1),120)});this.ice.addChild(i);const n=[];return t.forEach((e,t)=>{const s=new SecondarySymbol({kind:"terminal",name:e.no,tag:e.tag||"",left:(i.state.width-28)/2,top:24+34*t});i.addChild(s),this.__attachNodeListeners(s),n.push(s)}),this.selectedId=i.state.id,this.__emitChange(),{strip:i,terminals:n}}validateSecondary(){const e=[];this.edges.forEach(t=>{String(t.state.circuitNo||t.state.label||"").trim()||e.push({level:"error",message:"二次导线缺少回路编号(等电位编号是二次图的读图依据)",id:t.state.id})});const t=new Map;this.edges.forEach(e=>{const i=String(e.state.circuitNo||e.state.label||"").trim(),n=/^([ABC])(\d+)$/.exec(i);if(!n)return;const s=t.get(n[2])||new Set;s.add(n[1]),t.set(n[2],s)}),t.forEach((t,i)=>{["A","B","C"].forEach(n=>{t.has(n)||e.push({level:"error",message:`电流回路编号缺相:${n}${i} 没有对应的回路(三相电流回路必须成组)`})})});const i=new Map;return this.terminals.forEach(t=>{const n=String(t.state.name||"").trim();n&&(i.has(n)?e.push({level:"error",message:`端子号重复:「${n}」在端子排上不唯一`,id:t.state.id}):i.set(n,t))}),this.symbols.some(e=>"earth"===e.state.kind)||e.push({level:"warning",message:"二次回路没有接地:电流回路的 N 侧应接地"}),e}presetOf(e){return wn[e]}},exports.SecondarySymbol=SecondarySymbol,exports.SecondaryWire=SecondaryWire,exports.StateNode=StateNode,exports.StateTransition=StateTransition,exports.StatechartDesigner=class StatechartDesigner extends FlowDesigner{__nesting=!1;constructor(e){super(e),registerIEDType(this.ice,StateNode),registerIEDType(this.ice,StateTransition)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===StateNode.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===StateTransition.typeId)}createState(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.__captureHistory();const t=new StateNode(e);if(void 0===e.left||void 0===e.top){const i=this.__defaultPlacement(t.state.width,t.state.height);t.setState({left:void 0===e.left?i.left:e.left,top:void 0===e.top?i.top:e.top})}return this.ice.addChild(t),this.__attachNodeListeners(t),this.__nestByGeometry(t),this.selectedId=t.state.id,this.__emitChange(),t}createTransition(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("转移两端必须是已存在的状态");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"R",targetPort:"L"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=new StateTransition({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},startPoint:this.__portPoint(t,s),endPoint:this.__portPoint(i,r),event:e.event||"",guard:e.guard||"",action:e.action||"",label:e.label,linkShape:e.linkShape||"visio",style:{...e.style||{},...e.labelStyle?{label:e.labelStyle}:{}}});return this.ice.addChild(a),this.selectedId=a.state.id,this.__emitChange(),a}__nestByGeometry(e){if(this.__nesting||e.constructor.typeId!==StateNode.typeId||"composite"===e.state.kind)return;const t=e.getMinBoundingBox(!0),i=(t.tl[0]+t.br[0])/2,n=(t.tl[1]+t.br[1])/2,s=this.nodes.filter(t=>t!==e&&"composite"===t.state.kind).filter(e=>{const t=e.getMinBoundingBox(!0);return i>=t.tl[0]&&i<=t.br[0]&&n>=t.tl[1]&&n<=t.br[1]}).sort((e,t)=>e.state.width*e.state.height-t.state.width*t.state.height)[0];if(s){this.__nesting=!0;try{const t=s.getMinBoundingBox(!0).tl[0],i=s.getMinBoundingBox(!0).tl[1];e.setState({left:e.state.left-t,top:e.state.top-i}),s.adoptChild(e)}finally{this.__nesting=!1}}}validateStatechart(){const e=[],t=this.nodes,i=t.filter(e=>"initial"===e.state.kind);t.length&&0===i.length&&e.push({level:"error",message:"缺少初始状态(initial):状态机没有入口"});const n=new Map,s=new Map;t.forEach(e=>{n.set(e.state.id,[]),s.set(e.state.id,0)}),this.edges.forEach(t=>{const i=t.state.links||{},r=i.start&&i.start.id,a=i.end&&i.end.id;r&&a&&n.has(r)&&n.has(a)?(n.get(r).push(a),s.set(a,(s.get(a)||0)+1)):e.push({level:"error",message:"转移两端必须都是已存在的状态",id:t.state.id})}),t.forEach(t=>{"final"===t.state.kind&&(n.get(t.state.id)||[]).length>0&&e.push({level:"error",message:"终止状态不应有出边",id:t.state.id})});const r=new Set,a=i.map(e=>e.state.id);for(a.forEach(e=>r.add(e));a.length;){const e=a.shift();(n.get(e)||[]).forEach(e=>{r.has(e)||(r.add(e),a.push(e))})}return t.forEach(t=>{if(r.has(t.state.id))return;const i=(e=>{const t=[],walk=e=>{(e||[]).forEach(e=>{e.constructor&&e.constructor.typeId===StateNode.typeId&&t.push(e),walk(e.childNodes)})};return walk(e.childNodes),t})(t);if(i.some(e=>r.has(e.state.id)))return;const a=0===(s.get(t.state.id)||0)&&0===(n.get(t.state.id)||[]).length;if(a&&i.length)return;const o=t.state.title||t.state.kind;e.push({level:"warning",message:a?`状态「${o}」没有任何转移(孤立节点)`:`状态「${o}」从初始状态不可达`,id:t.state.id})}),e}__portPoint(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}},exports.TerminalStrip=TerminalStrip,exports.UML_RELATION_KINDS=ln,exports.UML_RELATION_STYLE=hn,exports.UmlClass=UmlClass,exports.UmlDesigner=class UmlDesigner extends FlowDesigner{constructor(e){super(e),registerIEDType(this.ice,UmlClass),registerIEDType(this.ice,UmlRelation)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===UmlClass.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===UmlRelation.typeId)}createClass(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.__captureHistory();const t=new UmlClass(e);if(void 0===e.left||void 0===e.top){const i=this.__defaultPlacement(t.state.width,t.state.height);t.setState({left:void 0===e.left?i.left:e.left,top:void 0===e.top?i.top:e.top})}return this.ice.addChild(t),this.__attachNodeListeners(t),this.selectedId=t.state.id,this.__emitChange(),t}createRelation(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("关系两端必须是已存在的类");this.__captureHistory();const n=autoPorts(t,i,{sourcePort:"R",targetPort:"L"}),s=e.sourcePort||n.sourcePort,r=e.targetPort||n.targetPort,a=new UmlRelation({id:e.id,links:{start:{id:e.sourceId,position:s},end:{id:e.targetId,position:r}},startPoint:this.__portPoint(t,s),endPoint:this.__portPoint(i,r),relationKind:e.relationKind||"association",label:e.label||"",linkShape:e.linkShape||"visio",style:{...e.style||{},...e.labelStyle?{label:e.labelStyle}:{}}});return this.ice.addChild(a),this.selectedId=a.state.id,this.__emitChange(),a}setRelationKind(e,t){const i=this.ice.findComponent(e);return i&&i.constructor.typeId===UmlRelation.typeId&&(this.__captureHistory(),i.applyPatch({relationKind:t}),this.__emitChange()),i}get relationKinds(){return[...ln]}validateUml(){const e=[],t=this.nodes,i=new Map;t.forEach(t=>{const n=String(t.state.className||"").trim();n?(i.has(n)||i.set(n,[]),i.get(n).push(t)):e.push({level:"error",message:"存在未命名的类",id:t.state.id})}),i.forEach((t,i)=>{t.length>1&&e.push({level:"error",message:`类名重复:${i}(${t.length} 个)`,id:t[0].state.id})});const n=new Set(t.map(e=>e.state.id)),s=new Map;this.edges.forEach(t=>{const i=t.state.links||{},r=i.start&&i.start.id,a=i.end&&i.end.id;r&&a&&n.has(r)&&n.has(a)?"inheritance"!==t.state.relationKind&&"realization"!==t.state.relationKind||(s.has(r)||s.set(r,[]),s.get(r).push(a)):e.push({level:"error",message:"关系两端必须都是已存在的类",id:t.state.id})});const r=new Map,a=[],visit=i=>{r.set(i,1),a.push(i);for(const n of s.get(i)||[]){const s=r.get(n)||0;if(1===s){const s=a.indexOf(n),o=a.slice(s>=0?s:0).concat(n).map(e=>{const i=t.find(t=>t.state.id===e);return i?i.state.className:e});return e.push({level:"error",message:`继承关系成环:${o.join(" → ")}`,id:i}),r.set(i,2),a.pop(),!0}if(0===s&&visit(n))return r.set(i,2),a.pop(),!0}return r.set(i,2),a.pop(),!1};return t.forEach(e=>{0===(r.get(e.state.id)||0)&&visit(e.state.id)}),e}static describeRelationKind(e){const t=hn[e];if(!t)return"";return`${t.dashed?"虚线":"实线"} + ${"triangle"===t.marker?"空心三角":"diamond"===t.marker?t.filled?"实心菱形":"空心菱形":"open"===t.marker?"开放箭头":"无端点标记"}`}__portPoint(e,t){const i=e.getMinBoundingBox(!0);switch(t){case"T":return[...i.tc];case"R":return[...i.rc];case"B":return[...i.bc];case"L":return[...i.lc];default:return[...i.center]}}},exports.UmlRelation=UmlRelation,exports.WATER_BOUNDARY_KINDS=["inlet","outlet","sludgeOut"],exports.WATER_EQUIPMENT_KINDS=["pump","submersiblePump","screwPump","blower","vfd","dosingUnit","valve","motorValve","checkValve","flowMeter","levelGauge","pressureGauge","analyzer"],exports.WATER_MEDIUM_STYLES=Cn,exports.WATER_SLUDGE_KINDS=In,exports.WATER_STYLE=Tn,exports.WATER_SYMBOL_KINDS=["barScreen","gritChamber","primaryClarifier","anaerobicTank","anoxicTank","aerobicTank","secondaryClarifier","coagulationTank","filterBed","disinfectionTank","storageTank","deodorizer","sludgeThickener","dewateringMachine","sludgeSilo","pump","submersiblePump","screwPump","blower","vfd","dosingUnit","valve","motorValve","checkValve","flowMeter","levelGauge","pressureGauge","analyzer","inlet","outlet","sludgeOut"],exports.WATER_SYMBOL_PRESETS=xn,exports.WATER_UNIT_KINDS=["barScreen","gritChamber","primaryClarifier","anaerobicTank","anoxicTank","aerobicTank","secondaryClarifier","coagulationTank","filterBed","disinfectionTank","sludgeThickener","dewateringMachine","sludgeSilo","storageTank","deodorizer"],exports.WATER_VALVE_KINDS=En,exports.WaterPipe=WaterPipe,exports.WaterProcessDesigner=class WaterProcessDesigner extends FlowDesigner{constructor(e){super(e),registerIEDType(this.ice,WaterSymbol),registerIEDType(this.ice,WaterPipe)}get nodes(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===WaterSymbol.typeId)}get edges(){return this.__flatten().filter(e=>e.constructor&&e.constructor.typeId===WaterPipe.typeId)}createSymbol(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__captureHistory();const i=new WaterSymbol({kind:e,...t});if(void 0===t.left||void 0===t.top){const e=this.__defaultPlacement(i.state.width,i.state.height);i.setState({left:void 0===t.left?e.left:t.left,top:void 0===t.top?e.top:t.top})}return this.ice.addChild(i),this.__attachNodeListeners(i),this.selectedId=i.state.id,this.__emitChange(),i}createPipe(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=e.sourceId?this.ice.findComponent(e.sourceId):null,i=e.targetId?this.ice.findComponent(e.targetId):null;if(!t||!i)throw new Error("管线两端必须是已存在的符号");this.__captureHistory();const n=e.sourcePort||"B",s=e.targetPort||"T",r=new WaterPipe({id:e.id,links:{start:{id:e.sourceId,position:n},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,n),endPoint:this.__slotPoint(i,s),medium:e.medium||"sewage",dn:e.dn||"",label:e.label,arrow:e.arrow||"end",linkShape:e.linkShape||"visio"});return void 0===e.label&&r.applyMediumStyle(),this.ice.addChild(r),this.selectedId=r.state.id,this.__emitChange(),r}setValveState(e,t){const i=this.__symbolById(e);if(!i)throw new Error("找不到该符号:"+e);if(!isWaterValveKind(i.state.kind))throw new Error("只有阀门(手动阀 / 电动阀)能改开 / 闭状态");return i.applyPatch({valveState:t}),this.ice.dirty=!0,i}traceFlow(e){const t=e?[e]:this.nodes.filter(e=>"inlet"===e.state.kind).map(e=>e.state.id),i=this.__adjacency(),n=new Set(t),s=new Map,r=[...t];let a,o;for(;r.length;){const e=r.shift(),t=this.__symbolById(e);if(t&&(!isWaterValveKind(t.state.kind)||"closed"!==t.state.valveState)){if("outlet"===t.state.kind){a=e;break}(i.get(e)||[]).forEach(t=>{const i=this.__symbolById(t.to);i&&isWaterValveKind(i.state.kind)&&"closed"===i.state.valveState?o||(o=t.to):n.has(t.to)||(n.add(t.to),s.set(t.to,e),r.push(t.to))})}}const l=[];if(a){let e=a;for(;e;)l.unshift(e),e=s.get(e)}const h={connected:!!a,path:l};return a&&(h.outletId=a),!a&&o&&(h.blockedAt=o),h}validateWater(){const e=[],t=this.nodes,i=this.edges,n=new Map;t.forEach(t=>{const i=String(t.state.tag||"").trim();i&&(n.has(i)?e.push({level:"error",code:"duplicate-tag",message:`位号重复:${i}`,id:t.state.id}):n.set(i,t.state.id))});const s=new Map;i.forEach(e=>{[this.__linkId(e,"start"),this.__linkId(e,"end")].forEach(e=>{e&&s.set(e,(s.get(e)||0)+1)})}),t.forEach(t=>{s.get(t.state.id)||e.push({level:"warning",code:"isolated-symbol",message:`「${t.state.name||xn[t.state.kind]?.label||t.state.kind}」没有任何管线`,id:t.state.id})}),i.forEach(t=>{t.state.medium||e.push({level:"warning",code:"pipe-missing-medium",message:"管线缺少介质标注",id:t.state.id});"signal"===t.state.medium||"power"===t.state.medium||String(t.state.dn||"").trim()||e.push({level:"warning",code:"pipe-missing-dn",message:"管线缺少管径标注(DN)",id:t.state.id})});const r=this.traceFlow();if(r.connected){r.path.some(e=>{const t=this.__symbolById(e);return!!t&&"analyzer"===t.state.kind})||e.push({level:"error",code:"outlet-without-analyzer",message:"出水管线上没有在线水质分析仪(排污许可要求在线监测并联网)"})}else e.push({level:"error",code:"flow-disconnected",message:r.blockedAt?"从进水走不到出水:管线在关断的阀门处断开":"从进水走不到出水:主流程未接通",id:r.blockedAt});const a=i.some(e=>"sludge"===e.state.medium),o=t.some(e=>-1!==["sludgeThickener","dewateringMachine","sludgeOut"].indexOf(e.state.kind));a&&!o&&e.push({level:"warning",code:"sludge-without-disposal",message:"有剩余污泥排出,但图上没有污泥浓缩 / 脱水 / 外运单元"});const l=t.some(e=>"aerobicTank"===e.state.kind),h=t.some(e=>"anoxicTank"===e.state.kind),d=i.some(e=>"recycle"===e.state.medium);return l&&h&&!d&&e.push({level:"warning",code:"aao-missing-recycle",message:"有好氧池与缺氧池,但缺少混合液内回流(好氧 → 缺氧)"}),e}__linkId(e,t){const i=e.state&&e.state.links,n=i&&i[t];return n&&n.id?n.id:null}__adjacency(){const e=new Map;return this.edges.forEach(t=>{const i=this.__linkId(t,"start"),n=this.__linkId(t,"end");i&&n&&(e.has(i)||e.set(i,[]),e.has(n)||e.set(n,[]),e.get(i).push({to:n,pipe:t}),e.get(n).push({to:i,pipe:t}))}),e}__symbolById(e){return this.nodes.filter(t=>t.state.id===e)[0]||null}},exports.WaterSymbol=WaterSymbol,exports.addDays=addDays,exports.applyDesignerChrome=applyDesignerChrome,exports.arrowOf=function arrowOf(e){return Pn[e]||"--\x3e"},exports.composePipeLabel=composePipeLabel,exports.defaultVoltageColors=defaultVoltageColors,exports.designerChromeFromTheme=designerChromeFromTheme,exports.detectUmlDialect=function detectUmlDialect(e){return/@startuml/i.test(e)?"plantuml":/classDiagram/i.test(e)?"mermaid":"unknown"},exports.diffDays=diffDays,exports.eachDay=function eachDay(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:400;const n=parseDate(e),s=parseDate(t);if(isNaN(n)||isNaN(s)||s<n)return[];const r=[];for(let e=n;e<=s&&r.length<i;e+=un)r.push(formatDate(e));return r},exports.formatDate=formatDate,exports.fromBpmnXml=function fromBpmnXml(e,t){const i=globalThis.DOMParser;if("function"!=typeof i)throw new Error("当前环境没有 DOMParser:请在浏览器(或 jsdom)中导入 BPMN XML");const n=(new i).parseFromString(e,"application/xml"),s=n.getElementsByTagName("parsererror");if(s&&s.length)throw new Error(`BPMN XML 解析失败:${s[0].textContent}`);const r=[],a=Array.prototype.slice.call(n.getElementsByTagName("*")),o=new Map,l=new Map;a.forEach(e=>{const t=localName(e);if("BPMNShape"===t){const t=e.getAttribute("bpmnElement"),i=Array.prototype.slice.call(e.getElementsByTagName("*")).find(e=>"Bounds"===localName(e));t&&i&&o.set(t,{x:Number(i.getAttribute("x"))||0,y:Number(i.getAttribute("y"))||0,width:Number(i.getAttribute("width"))||120,height:Number(i.getAttribute("height"))||80})}else if("BPMNEdge"===t){const t=e.getAttribute("bpmnElement"),i=Array.prototype.slice.call(e.getElementsByTagName("*")).filter(e=>"waypoint"===localName(e)).map(e=>[Number(e.getAttribute("x"))||0,Number(e.getAttribute("y"))||0]);t&&l.set(t,i)}}),t.clear();const h=new Map;let d=0;a.forEach(e=>{const i=localName(e);if("lane"===i){const i=e.getAttribute("id"),n=i?o.get(i):null;if(n){const s=t.createNode("bpmnLane",{title:e.getAttribute("name")||"Lane",left:n.x,top:n.y,width:n.width,height:n.height});i&&h.set(i,s.state.id),d+=1}return}if("participant"!==i)return;const n=e.getAttribute("id"),s=n?o.get(n):null;if(!s)return;const r=t.createNode("bpmnPool",{title:e.getAttribute("name")||"Pool",left:s.x,top:s.y,width:s.width,height:s.height});h.set(n,r.state.id),d+=1,r.setState({zIndex:tn})}),a.forEach(e=>{const i=localName(e);if("participant"===i||"laneSet"===i||"process"===i||"collaboration"===i)return;if("lane"===i||"participant"===i)return;const n=function nodeFromElement(e){switch(e){case"startEvent":return{kind:"bpmnEvent",attrs:{eventKind:"start"}};case"endEvent":return{kind:"bpmnEvent",attrs:{eventKind:"end"}};case"intermediateThrowEvent":case"intermediateCatchEvent":return{kind:"bpmnEvent",attrs:{eventKind:"intermediate"}};case"exclusiveGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"exclusive"}};case"parallelGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"parallel"}};case"inclusiveGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"inclusive"}};case"eventBasedGateway":return{kind:"bpmnGateway",attrs:{gatewayType:"event"}};case"subProcess":return{kind:"bpmnSubprocess",attrs:{}};case"dataObjectReference":return{kind:"bpmnDataObject",attrs:{}};case"textAnnotation":return{kind:"bpmnAnnotation",attrs:{}};case"task":return{kind:"bpmnTask",attrs:{taskType:"none"}};case"userTask":return{kind:"bpmnTask",attrs:{taskType:"user"}};case"serviceTask":return{kind:"bpmnTask",attrs:{taskType:"service"}};case"scriptTask":return{kind:"bpmnTask",attrs:{taskType:"script"}};case"sendTask":return{kind:"bpmnTask",attrs:{taskType:"send"}};case"receiveTask":return{kind:"bpmnTask",attrs:{taskType:"receive"}};case"manualTask":return{kind:"bpmnTask",attrs:{taskType:"manual"}};default:return null}}(i);if(!n)return;const s=e.getAttribute("id");if(!s)return;const a=o.get(s);a||r.push(`元素 ${s}(${i})没有 DI 布局信息,已按默认尺寸放在原点附近`);const l={...n.attrs};if("bpmnEvent"===n.kind&&(l.trigger=function triggerOf(e){const t=(e&&e.childNodes?Array.prototype.slice.call(e.childNodes):[]).map(e=>localName(e));return-1!==t.indexOf("messageEventDefinition")?"message":-1!==t.indexOf("timerEventDefinition")?"timer":-1!==t.indexOf("errorEventDefinition")?"error":-1!==t.indexOf("terminateEventDefinition")?"terminate":"none"}(e)),"textAnnotation"===i){const t=Array.prototype.slice.call(e.getElementsByTagName("*")).find(e=>"text"===localName(e));l.title=t&&t.textContent||""}const c=t.createNode(n.kind,{...l,title:e.getAttribute("name")||l.title||"",left:a?a.x:0,top:a?a.y:0,width:a?a.width:void 0,height:a?a.height:void 0});h.set(s,c.state.id),d+=1});let c=0;return a.forEach(e=>{const i=localName(e);if("sequenceFlow"!==i&&"messageFlow"!==i)return;const n=e.getAttribute("sourceRef"),s=e.getAttribute("targetRef"),a=n?h.get(n):null,o=s?h.get(s):null;if(!a||!o)return void r.push(`连线 ${e.getAttribute("id")} 的端点未找到(sourceRef=${n} targetRef=${s})`);const l=Array.prototype.slice.call(e.getElementsByTagName("*")).find(e=>"conditionExpression"===localName(e));t.createEdge({sourceId:a,targetId:o,label:e.getAttribute("name")||"",flowType:"messageFlow"===i?"message":"sequence",isDefault:"true"===e.getAttribute("default"),condition:l?l.textContent:""}),c+=1}),t.resetHistory(),{nodes:d,edges:c,warnings:r}},exports.fromMermaidGantt=function fromMermaidGantt(e,t){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n=[],s=[],r=new Map,a=new Map;let o="",l=i.defaultStart||"";String(e||"").split(/\r?\n/).forEach(e=>{const t=e.trim();if(!t)return;if(t.startsWith("%%")){const e=/^%%\s*task\s+(\S+)\s*:\s*(.*)$/i.exec(t);if(e){const t=r.get(e[1])||{};e[2].split(/\s+/).forEach(e=>{const[i,n]=e.split("=");"progress"===i?t.progress=Number(n):"deps"===i&&n&&(t.deps=n.split(",").filter(e=>!!e))}),r.set(e[1],t)}return}if(pn.test(t))return;const i=/^section\s+(.+)$/i.exec(t);if(i)return void(o=i[1].trim());const h=/^(.+?)\s*:\s*(.*)$/.exec(t);if(!h)return void n.push(`不认识的语法,已跳过:${t}`);const d={id:null,title:h[1].trim(),start:null,endDate:null,after:[],days:null,progress:0,resource:o,line:t};h[2].split(",").forEach(e=>{const i=e.trim();if(!i)return;if(mn.test(i))return void(/^done$/i.test(i)?d.progress=1:/^active$/i.test(i)&&(d.progress=.5));const s=/^after\s+(.+)$/i.exec(i);s?d.after=s[1].trim().split(/\s+/).filter(e=>!!e):/^until\s+/i.test(i)?n.push(`暂不支持 until 依赖,已跳过该子句:${t}`):fn.test(i)?d.start?d.endDate||(d.endDate=i):d.start=i:gn.test(i)?d.days=function durationToDays(e){const t=gn.exec(e);if(!t)return 1;const i=Number(t[1]);switch(t[2].toLowerCase()){case"w":return Math.max(1,Math.round(7*i));case"d":return Math.max(1,Math.round(i));case"h":return Math.max(1,Math.round(i/24));default:return 1}}(i):d.id?n.push(`无法识别的子句「${i}」,已跳过:${t}`):d.id=i}),s.push(d),d.id&&a.set(d.id,d),!l&&d.start&&(l=d.start)}),t.clear();const h=l||"2026-01-01",d=new Map,c=[];s.forEach(e=>{const i=e.days||(e.start&&e.endDate?Math.max(1,diffDays(e.start,e.endDate)):3),n=t.createTask({title:e.title,start:e.start||h,days:i,progress:e.progress,resource:e.resource});c.push(n),e.id&&d.set(e.id,{node:n,parsed:e})});for(let e=0;e<8;e+=1){let e=!1;if(s.forEach((t,i)=>{if(!t.after.length)return;let n="";t.after.forEach(e=>{const t=d.get(e);if(!t)return;const i=addDays(t.node.state.start,Math.max(1,Number(t.node.state.days)||1));(!n||diffDays(n,i)>0)&&(n=i)}),n&&c[i].state.start!==n&&(c[i].applyPatch({start:n}),e=!0)}),!e)break}d.forEach((e,t)=>{const i=r.get(t);i&&("number"!=typeof i.progress||Number.isNaN(i.progress)||e.node.applyPatch({progress:i.progress}),i.deps&&i.deps.length&&(e.parsed.after=Array.from(new Set([...e.parsed.after,...i.deps]))))});let u=0;return s.forEach(e=>{if(!e.after.length)return;const i=d.get(e.id);i&&Array.from(new Set(e.after)).forEach(s=>{const r=d.get(s);r?(t.createDependency({sourceId:r.node.state.id,targetId:i.node.state.id}),u+=1):n.push(`找不到前置任务「${s}」,已跳过该依赖:${e.line}`)})}),t.select(null),{tasks:c.length,dependencies:u,warnings:n}},exports.fromPlantUml=function fromPlantUml(e,t){const i=[],n=new Map,s=[],r=String(e||"").split(/\r?\n/);let a=null,o=!1;r.forEach(e=>{const t=e.replace(/\s+$/,"").trim();if(!t||t.startsWith("'")||t.startsWith("//")||t.startsWith("%%"))return;if(/^@startuml/i.test(t)||/^@enduml/i.test(t)||/^classDiagram/i.test(t)||/^skinparam/i.test(t)||/^title/i.test(t))return;if(a){if("}"===t)return a=null,void(o=!1);if("--"===t||".."===t||"__"===t)return void(o=!1);const e=n.get(a);return void(o?e.attributes:e.methods).push(t)}const r=/^(abstract\s+class|abstract|class|interface|enum(?:eration)?)\s+(.+?)\s*(\{)?$/i.exec(t);if(r){const e=r[1].toLowerCase(),t=unquote(r[2].replace(/\{.*$/,"")),i=e.startsWith("interface")?"interface":e.startsWith("enum")?"enum":"class";return n.set(t,{kind:i,attributes:[],methods:[],abstract:e.startsWith("abstract")}),void(r[3]&&(a=t,o=!0))}/^(.+?)\s+(<\|--|<\|\.\.|<--|<\.\.|--\*|\*--|--o|o--|-->|\.\.>|--|\.\.)\s+(.+?)(?:\s*:\s*(.*))?$/.exec(t)?s.push(t):i.push(`不认识的语法,已跳过:${t}`)}),t.clear();const l=new Map;let h=0;n.forEach((e,i)=>{const n=t.createClass({kind:e.kind,className:i,abstract:e.abstract,attributes:e.attributes,methods:e.methods,left:80+h%3*260*1.4,top:80+280*Math.floor(h/3)});l.set(i,n),h++});let d=0;return s.forEach(e=>{const n=/^(.+?)\s+(<\|--|<\|\.\.|<--|<\.\.|--\*|\*--|--o|o--|-->|\.\.>|--|\.\.)\s+(.+?)(?:\s*:\s*(.*))?$/.exec(e);if(!n)return void i.push(`关系解析失败,已跳过:${e}`);const s=unquote(n[1]),r=n[2],a=unquote(n[3]),o=n[4]||"",h=0===r.indexOf("<"),c=(Mn.find(e=>{let[t]=e;return t.test(r)})||[/x/,"association"])[1],u=h?a:s,p=h?s:a,f=l.get(u),g=l.get(p);f&&g?(t.createRelation({sourceId:f.state.id,targetId:g.state.id,relationKind:c,label:o}),d++):i.push(`关系两端未定义,已跳过:${e}`)}),{classes:l.size,relations:d,warnings:i}},exports.fromPlantUmlState=function fromPlantUmlState(e,t){const i=[],n=[],s=[],r=[];String(e||"").split(/\r?\n/).forEach(e=>{const t=e.trim();if(!t||t.startsWith("'")||t.startsWith("//")||t.startsWith("%%"))return;if(/^@startuml/i.test(t)||/^@enduml/i.test(t)||/^title\b/i.test(t)||/^skinparam\b/i.test(t)||/^hide\b/i.test(t)||/^scale\b/i.test(t)||/^autoactivate\b/i.test(t)||/^note\b/i.test(t)||/^state\s+<<.*>>$/i.test(t))return;if("}"===t)return void r.pop();const a=/^state\s+(?:"([^"]+)"|([^\s{]+))(?:\s+as\s+([^\s{]+))?\s*(\{)?$/i.exec(t);if(a){const e=void 0!==a[1]?a[1]:a[2],t=a[3]||e,i=r.length?r[r.length-1]:null;return n.push({token:t,title:e,kind:a[4]?"composite":"state",parent:i}),void(a[4]&&r.push(t))}const o=/^(\[\*\]|[^\s]+)\s+(?:-+[a-z]*->|->)\s+(\[\*\]|[^\s]+)\s*(?::\s*(.*))?$/i.exec(t);o?s.push({from:o[1],to:o[2],label:(o[3]||"").trim(),line:t}):i.push(`不认识的语法,已跳过:${t}`)}),t.clear();const a=new Map,o=n.filter(e=>"composite"===e.kind),l=n.filter(e=>"composite"!==e.kind&&!e.parent);o.forEach((e,i)=>{const n=120+i%2*620,s=340+320*Math.floor(i/2),r=t.createState({kind:"composite",title:e.title,left:n,top:s,width:560,height:280});a.set(e.token,r)}),l.forEach((e,i)=>{const n=t.createState({title:e.title,left:120+i%4*280,top:100+140*Math.floor(i/4),width:180,height:64});a.set(e.token,n)}),n.filter(e=>"composite"!==e.kind&&e.parent).forEach(e=>{const s=a.get(e.parent);s||i.push(`找不到父状态「${e.parent}」,已按根级状态导入:${e.title}`);const r=n.filter(t=>t.parent===e.parent&&"composite"!==t.kind).findIndex(t=>t.token===e.token),o=s?s.state.left+24:120,l=s?s.state.top+70:100,h=t.createState({title:e.title,left:o+r%2*260,top:l+90*Math.floor(r/2),width:220,height:60});a.set(e.token,h)});let h=null,d=null;const ensureState=e=>{if(a.has(e))return a.get(e);const i=a.size,n=t.createState({title:e,left:120+i%4*280,top:100+140*Math.floor(i/4),width:180,height:64});return a.set(e,n),n};let c=0;return s.forEach(e=>{const i="[*]"===e.from?(h||(h=t.createState({kind:"initial",left:60,top:120})),h):ensureState(e.from),n="[*]"===e.to?(d||(d=t.createState({kind:"final",left:1160,top:120})),d):ensureState(e.to),s=splitTransitionLabel(e.label);t.createTransition({sourceId:i.state.id,targetId:n.state.id,event:s.event,guard:s.guard,action:s.action}),c+=1}),t.select(null),{states:a.size+(h?1:0)+(d?1:0),transitions:c,warnings:i}},exports.isWaterValveKind=isWaterValveKind,exports.parseDate=parseDate,exports.splitTransitionLabel=splitTransitionLabel,exports.tickLabel=tickLabel,exports.toBpmnXml=function toBpmnXml(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.nodes||[],n=e.edges||[],s=i.filter(e=>"bpmnPool"===e.state.kind),r=i.filter(e=>"bpmnLane"===e.state.kind),a=new Map;i.forEach(e=>a.set(e.state.id,e));const poolOf=e=>{if(!e)return null;const t=rectOf(e);return s.find(e=>centerInside(rectOf(e),t))||null},processIdOf=e=>`Process_${e?e.state.id:"default"}`,idOf=e=>{return t=e.state.id,String(t).replace(/[^A-Za-z0-9_-]/g,"_");var t},o=[],l=[],h=[],d=[],c=[];i.forEach(e=>{const t=function elementNameForNode(e){const t=e.state.kind;if("bpmnEvent"===t){const t=e.state.eventKind||"start";return"end"===t?"endEvent":"intermediate"===t?"intermediateThrowEvent":"startEvent"}if("bpmnGateway"===t)return{exclusive:"exclusiveGateway",parallel:"parallelGateway",inclusive:"inclusiveGateway",event:"eventBasedGateway"}[e.state.gatewayType||"exclusive"];if("bpmnSubprocess"===t)return"subProcess";if("bpmnDataObject"===t)return"dataObjectReference";if("bpmnAnnotation"===t)return"textAnnotation";if("bpmnTask"===t||"process"===t)return{none:"task",user:"userTask",service:"serviceTask",script:"scriptTask",send:"sendTask",receive:"receiveTask",manual:"manualTask"}[e.state.taskType||"none"]||"task";return null}(e);if(t){const i="bpmnEvent"===e.state.kind&&e.state.trigger&&"none"!==e.state.trigger?`<bpmn:${e.state.trigger}EventDefinition id="${idOf(e)}_def" />`:"",n="textAnnotation"===t?` id="${idOf(e)}"><bpmn:text>${escapeXml(e.state.title)}</bpmn:text></bpmn:textAnnotation>`:` id="${idOf(e)}" name="${escapeXml(e.state.title)}">${i}</bpmn:${t}>`,s="textAnnotation"===t?null:`<bpmn:${t}`;o.push(s?`${s}${n}`:`<bpmn:textAnnotation${n}`)}const i=rectOf(e);l.push(` <bpmndi:BPMNShape id="${idOf(e)}_di" bpmnElement="${idOf(e)}">\n <dc:Bounds x="${Math.round(i.x0)}" y="${Math.round(i.y0)}" width="${Math.round(i.x1-i.x0)}" height="${Math.round(i.y1-i.y0)}" />\n </bpmndi:BPMNShape>`)}),n.forEach(e=>{const t=e.state.links||{},i=a.get((t.start||{}).id),n=a.get((t.end||{}).id);if(!i||!n)return;if(poolOf(i)!==poolOf(n)||"message"===e.state.flowType)d.push(` <bpmn:messageFlow id="${idOf(e)}" name="${escapeXml(e.state.label)}" sourceRef="${idOf(i)}" targetRef="${idOf(n)}" />`);else{const t=e.state.condition?`\n <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${escapeXml(e.state.condition)}</bpmn:conditionExpression>\n `:"";h.push(` <bpmn:sequenceFlow id="${idOf(e)}" name="${escapeXml(e.state.label)}" sourceRef="${idOf(i)}" targetRef="${idOf(n)}"${e.state.isDefault?' default="true"':""}>${t}</bpmn:sequenceFlow>`)}const s=(e.state.points&&e.state.points.length?e.state.points:[e.state.startPoint,e.state.endPoint]).filter(Boolean);c.push(` <bpmndi:BPMNEdge id="${idOf(e)}_di" bpmnElement="${idOf(e)}">\n`+s.map(e=>` <di:waypoint x="${Math.round(e[0])}" y="${Math.round(e[1])}" />`).join("\n")+"\n </bpmndi:BPMNEdge>")});const u=[];return s.forEach(e=>{const t=r.filter(t=>centerInside(rectOf(e),rectOf(t))),i=t.length?`\n <bpmn:laneSet id="${idOf(e)}_lanes">\n`+t.map(e=>` <bpmn:lane id="${idOf(e)}" name="${escapeXml(e.state.title)}" />`).join("\n")+"\n </bpmn:laneSet>":"";u.push(` <bpmn:process id="${processIdOf(e)}" name="${escapeXml(e.state.title)}" isExecutable="false">${i}\n \x3c!-- 该池内的流元素与顺序流由下面的 collaboration/di 段按 id 关联 --\x3e\n </bpmn:process>`)}),u.push(' <bpmn:process id="Process_default" isExecutable="false" />'),`<?xml version="1.0" encoding="UTF-8"?>\n<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://ice-render/bpmn">\n <bpmn:collaboration id="Collaboration_1">\n${s.map(e=>` <bpmn:participant id="${idOf(e)}" name="${escapeXml(e.state.title)}" processRef="${processIdOf(e)}" />`).join("\n")}\n </bpmn:collaboration>\n`+u.join("\n")+"\n \x3c!-- 流元素 --\x3e\n"+o.map(e=>` ${e}`).join("\n")+"\n \x3c!-- 连线 --\x3e\n"+h.join("\n")+"\n"+d.join("\n")+`\n <bpmndi:BPMNDiagram id="BPMNDiagram_1" name="${escapeXml(t.name||"BPMN Diagram")}">\n <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">\n`+l.join("\n")+(c.length?"\n"+c.join("\n"):"")+"\n </bpmndi:BPMNPlane>\n </bpmndi:BPMNDiagram>\n</bpmn:definitions>\n"},exports.toMermaidGantt=function toMermaidGantt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.nodes||[],n=new Map;i.forEach((e,t)=>n.set(e.state.id,`t${t+1}`));const s=new Map;(e.edges||[]).forEach(e=>{const t=e.state.links||{},i=t.start&&t.start.id,r=t.end&&t.end.id;i&&r&&n.has(r)&&s.set(r,[...s.get(r)||[],i])});const r=["gantt"];t.title&&r.push(` title ${t.title}`),r.push(" dateFormat YYYY-MM-DD"),r.push(" axisFormat %m-%d");const emit=t=>{const i=n.get(t.state.id),a=Number(t.state.progress)||0,o=s.get(t.state.id)||[],l=[];a>=1?l.push("done"):a>0&&l.push("active");const h=1===o.length?n.get(o[0]):null,d=1===o.length?(e.nodes||[]).find(e=>e.state.id===o[0]):null,c=d&&h?addDays(d.state.start,Math.max(1,Math.round(Number(d.state.days)||1))):null,u=!!h&&c===String(t.state.start||""),p=u?`after ${h}`:String(t.state.start||""),f=Math.max(1,Math.round(Number(t.state.days)||1));r.push(` ${t.state.title} :${l.length?`${l.join(", ")}, `:""}${i}, ${p}, ${f}d`);const g=[];a>0&&a<1&&g.push(`progress=${a}`),o.length&&!u&&g.push(`deps=${o.map(e=>n.get(e)).join(",")}`),g.length&&r.push(` %% task ${i}: ${g.join(" ")}`)},a=[];return i.forEach(e=>{const t=String(e.state.resource||"");t&&-1===a.indexOf(t)&&a.push(t)}),i.filter(e=>!String(e.state.resource||"")).forEach(emit),a.forEach(e=>{r.push(""),r.push(` section ${e}`),i.filter(t=>String(t.state.resource||"")===e).forEach(emit)}),r.join("\n")},exports.toPlantUml=function toPlantUml(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=["@startuml"];t.title&&i.push(`title ${t.title}`),i.push("skinparam classAttributeIconSize 0");const n=e.nodes;n.forEach(e=>{const t=e.state.kind||"class",n="interface"===t?"interface":"enum"===t?"enum":e.state.abstract?"abstract class":"class",s=quoteIfNeeded(String(e.state.className||"Class"));[...e.state.attributes||[],...e.state.methods||[]].length?(i.push(`${n} ${s} {`),(e.state.attributes||[]).forEach(e=>i.push(` ${e}`)),(e.state.methods||[]).length&&(i.push(" --"),(e.state.methods||[]).forEach(e=>i.push(` ${e}`))),i.push("}")):i.push(`${n} ${s}`)});const s=new Map;return n.forEach(e=>s.set(e.state.id,e)),e.edges.forEach(e=>{const t=e.state.links||{},n=t.start&&t.start.id,r=t.end&&t.end.id,a=s.get(n),o=s.get(r);if(!a||!o)return;const l=e.state.relationKind||"association",h=Pn[l]||"--\x3e",d=e.state.label?` : ${e.state.label}`:"",c=0===h.indexOf("<"),u=quoteIfNeeded(String((c?o:a).state.className)),p=quoteIfNeeded(String((c?a:o).state.className));i.push(`${u} ${h} ${p}${d}`)}),i.push("@enduml"),i.join("\n")},exports.toPlantUmlState=function toPlantUmlState(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.nodes||[],n=["@startuml"];t.title&&n.push(`title ${t.title}`);const s=new Map;i.forEach(e=>s.set(e.state.id,e));const r=new Map;i.forEach(e=>{const t=String(e.state.title||"");t&&r.set(t,(r.get(t)||0)+1)});const a=new Map;let o=0;const declaration=e=>{const t=String(e.state.title||"");if(!(!cn.test(t)||(r.get(t)||0)>1))return`state ${t}`;o+=1;const i=`S${o}`;return a.set(e.state.id,i),`state "${t}" as ${i}`},reference=e=>a.get(e.state.id)||String(e.state.title||""),l=new Set;return i.filter(e=>"composite"===kindOf(e)).forEach(e=>{const t=i.filter(t=>!isPseudo(kindOf(t))&&function nearestStateAncestor(e){let t=e.parentNode;for(;t;){if(t.constructor&&"ice-entity-designer:StateNode"===t.constructor.typeId)return t;t=t.parentNode}return null}(t)===e);t.forEach(e=>l.add(e.state.id)),n.push(`${declaration(e)} {`),t.forEach(e=>n.push(` ${declaration(e)}`)),n.push("}")}),i.forEach(e=>{const t=kindOf(e);isPseudo(t)||"composite"===t||l.has(e.state.id)||n.push(declaration(e))}),(e.edges||[]).forEach(e=>{const t=e.state.links||{},i=s.get(t.start&&t.start.id),r=s.get(t.end&&t.end.id);if(!i||!r)return;const a="initial"===kindOf(i)?"[*]":reference(i),o="final"===kindOf(r)?"[*]":reference(r),l=e.state.label?` : ${e.state.label}`:"";n.push(`${a} --\x3e ${o}${l}`)}),n.push("@enduml"),n.join("\n")},exports.toSchemaObject=toSchemaObject,exports.toSchemaString=toSchemaString,exports.validateBpmn=validateBpmn,exports.validateFlowSnapshot=validateFlowSnapshot,exports.validateProjectSnapshot=validateProjectSnapshot,exports.validateSchema=validateSchema,exports.voltageColorOf=voltageColorOf,Object.keys(i).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})});
|