ice-entity-designer 0.12.0 → 0.12.2
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/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/package.json +6 -4
package/dist/react.mjs
CHANGED
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import{createContext as e,createElement as t,useContext as i,forwardRef as n,useRef as r,useState as s,useEffect as o,useImperativeHandle as a,Fragment as l}from"react";import{ICEGroup as h,ICEText as c,ICERect as u,ICEPolyLine as d,ICEVisioLink as p,toIsoTime as y,ICEPath as f,ICE_EVENT_NAME_CONSTS as g,DEFAULT_THEME as m,Serializer as _,Deserializer as b,exportSvg as v,ICECircle as w,registerVirtualSource as k,materializedIndices as x,materializedChild as S,syncVirtualWindow as C,ICE as T}from"ice-render";const M=e(null);function EntityDesignerProvider(e){return t(M.Provider,{value:e.designer},e.children)}function useEntityDesigner(){return i(M)}const I=e(null);function FlowDesignerProvider(e){return t(I.Provider,{value:e.designer},e.children)}function useFlowDesigner(){return i(I)}var P,q,E="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 j,$,O,D,A,N,B,F,z,L,H,R,W,V,U,G,K,X,Y,J,Q,Z,ee,te,ie,ne,re,se,oe,ae,le,he,ce,ue,de,pe,ye,fe,ge,me,_e,be,ve,we,ke,xe,Se,Ce,Te,Me,Ie,Pe,qe,Ee,je,$e,Oe,De,Ae,Ne,Be,Fe,ze,Le,He,Re,We,Ve,Ue,Ge,Ke,Xe,Ye,Je,Qe,Ze,et,tt,it,nt,rt,st,ot,at,lt,ht,ct,ut,dt,pt,yt,ft,gt,mt,_t,bt,vt,wt,kt=getDefaultExportFromCjs(function requireIsNil(){return q?P:(q=1,P=function isNil(e){return null==e})}());function requireEq(){if(D)return O;return D=1,O=function eq(e,t){return e===t||e!=e&&t!=t}}function require_assocIndexOf(){if(N)return A;N=1;var e=requireEq();return A=function assocIndexOf(t,i){for(var n=t.length;n--;)if(e(t[n][0],i))return n;return-1}}function require_ListCache(){if(G)return U;G=1;var e=function require_listCacheClear(){return $?j:($=1,j=function listCacheClear(){this.__data__=[],this.size=0})}(),t=function require_listCacheDelete(){if(F)return B;F=1;var e=require_assocIndexOf(),t=Array.prototype.splice;return B=function listCacheDelete(i){var n=this.__data__,r=e(n,i);return!(r<0||(r==n.length-1?n.pop():t.call(n,r,1),--this.size,0))}}(),i=function require_listCacheGet(){if(L)return z;L=1;var e=require_assocIndexOf();return z=function listCacheGet(t){var i=this.__data__,n=e(i,t);return n<0?void 0:i[n][1]}}(),n=function require_listCacheHas(){if(R)return H;R=1;var e=require_assocIndexOf();return H=function listCacheHas(t){return e(this.__data__,t)>-1}}(),r=function require_listCacheSet(){if(V)return W;V=1;var e=require_assocIndexOf();return W=function listCacheSet(t,i){var n=this.__data__,r=e(n,t);return r<0?(++this.size,n.push([t,i])):n[r][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=r,U=ListCache}function require_freeGlobal(){if(ne)return ie;ne=1;var e="object"==typeof E&&E&&E.Object===Object&&E;return ie=e}function require_root(){if(se)return re;se=1;var e=require_freeGlobal(),t="object"==typeof self&&self&&self.Object===Object&&self,i=e||t||Function("return this")();return re=i}function require_Symbol(){if(ae)return oe;ae=1;var e=require_root().Symbol;return oe=e}function require_baseGetTag(){if(pe)return de;pe=1;var e=require_Symbol(),t=function require_getRawTag(){if(he)return le;he=1;var e=require_Symbol(),t=Object.prototype,i=t.hasOwnProperty,n=t.toString,r=e?e.toStringTag:void 0;return le=function getRawTag(e){var t=i.call(e,r),s=e[r];try{e[r]=void 0;var o=!0}catch(e){}var a=n.call(e);return o&&(t?e[r]=s:delete e[r]),a}}(),i=function require_objectToString(){if(ue)return ce;ue=1;var e=Object.prototype.toString;return ce=function objectToString(t){return e.call(t)}}(),n=e?e.toStringTag:void 0;return de=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(fe)return ye;return fe=1,ye=function isObject(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}}function requireIsFunction(){if(me)return ge;me=1;var e=require_baseGetTag(),t=requireIsObject();return ge=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(we)return ve;we=1;var e,t=function require_coreJsData(){if(be)return _e;be=1;var e=require_root()["__core-js_shared__"];return _e=e}(),i=(e=/[^.]+$/.exec(t&&t.keys&&t.keys.IE_PROTO||""))?"Symbol(src)_1."+e:"";return ve=function isMasked(e){return!!i&&i in e}}function require_baseIsNative(){if(Ce)return Se;Ce=1;var e=requireIsFunction(),t=require_isMasked(),i=requireIsObject(),n=function require_toSource(){if(xe)return ke;xe=1;var e=Function.prototype.toString;return ke=function toSource(t){if(null!=t){try{return e.call(t)}catch(e){}try{return t+""}catch(e){}}return""}}(),r=/^\[object .+?Constructor\]$/,s=Function.prototype,o=Object.prototype,a=s.toString,l=o.hasOwnProperty,h=RegExp("^"+a.call(l).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");return Se=function baseIsNative(s){return!(!i(s)||t(s))&&(e(s)?h:r).test(n(s))}}function require_getNative(){if(Pe)return Ie;Pe=1;var e=require_baseIsNative(),t=function require_getValue(){return Me?Te:(Me=1,Te=function getValue(e,t){return null==e?void 0:e[t]})}();return Ie=function getNative(i,n){var r=t(i,n);return e(r)?r:void 0}}function require_Map(){if(Ee)return qe;Ee=1;var e=require_getNative()(require_root(),"Map");return qe=e}function require_nativeCreate(){if($e)return je;$e=1;var e=require_getNative()(Object,"create");return je=e}function require_Hash(){if(Ve)return We;Ve=1;var e=function require_hashClear(){if(De)return Oe;De=1;var e=require_nativeCreate();return Oe=function hashClear(){this.__data__=e?e(null):{},this.size=0}}(),t=function require_hashDelete(){return Ne?Ae:(Ne=1,Ae=function hashDelete(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t})}(),i=function require_hashGet(){if(Fe)return Be;Fe=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return Be=function hashGet(i){var n=this.__data__;if(e){var r=n[i];return"__lodash_hash_undefined__"===r?void 0:r}return t.call(n,i)?n[i]:void 0}}(),n=function require_hashHas(){if(Le)return ze;Le=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return ze=function hashHas(i){var n=this.__data__;return e?void 0!==n[i]:t.call(n,i)}}(),r=function require_hashSet(){if(Re)return He;Re=1;var e=require_nativeCreate();return He=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=r,We=Hash}function require_getMapData(){if(Je)return Ye;Je=1;var e=function require_isKeyable(){return Xe?Ke:(Xe=1,Ke=function isKeyable(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e})}();return Ye=function getMapData(t,i){var n=t.__data__;return e(i)?n["string"==typeof i?"string":"hash"]:n.map}}function require_MapCache(){if(at)return ot;at=1;var e=function require_mapCacheClear(){if(Ge)return Ue;Ge=1;var e=require_Hash(),t=require_ListCache(),i=require_Map();return Ue=function mapCacheClear(){this.size=0,this.__data__={hash:new e,map:new(i||t),string:new e}}}(),t=function require_mapCacheDelete(){if(Ze)return Qe;Ze=1;var e=require_getMapData();return Qe=function mapCacheDelete(t){var i=e(this,t).delete(t);return this.size-=i?1:0,i}}(),i=function require_mapCacheGet(){if(tt)return et;tt=1;var e=require_getMapData();return et=function mapCacheGet(t){return e(this,t).get(t)}}(),n=function require_mapCacheHas(){if(nt)return it;nt=1;var e=require_getMapData();return it=function mapCacheHas(t){return e(this,t).has(t)}}(),r=function require_mapCacheSet(){if(st)return rt;st=1;var e=require_getMapData();return rt=function mapCacheSet(t,i){var n=e(this,t),r=n.size;return n.set(t,i),this.size+=n.size==r?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=r,ot=MapCache}function require_Stack(){if(ut)return ct;ut=1;var e=require_ListCache(),t=function require_stackClear(){if(X)return K;X=1;var e=require_ListCache();return K=function stackClear(){this.__data__=new e,this.size=0}}(),i=function require_stackDelete(){return J?Y:(J=1,Y=function stackDelete(e){var t=this.__data__,i=t.delete(e);return this.size=t.size,i})}(),n=function require_stackGet(){return Z?Q:(Z=1,Q=function stackGet(e){return this.__data__.get(e)})}(),r=function require_stackHas(){return te?ee:(te=1,ee=function stackHas(e){return this.__data__.has(e)})}(),s=function require_stackSet(){if(ht)return lt;ht=1;var e=require_ListCache(),t=require_Map(),i=require_MapCache();return lt=function stackSet(n,r){var s=this.__data__;if(s instanceof e){var o=s.__data__;if(!t||o.length<199)return o.push([n,r]),this.size=++s.size,this;s=this.__data__=new i(o)}return s.set(n,r),this.size=s.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=r,Stack.prototype.set=s,ct=Stack}function require_defineProperty(){if(pt)return dt;pt=1;var e=require_getNative(),t=function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch(e){}}();return dt=t}function require_baseAssignValue(){if(ft)return yt;ft=1;var e=require_defineProperty();return yt=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(mt)return gt;mt=1;var e=require_baseAssignValue(),t=requireEq();return gt=function assignMergeValue(i,n,r){(void 0!==r&&!t(i[n],r)||void 0===r&&!(n in i))&&e(i,n,r)}}function require_baseFor(){if(wt)return vt;wt=1;var e=function require_createBaseFor(){return bt?_t:(bt=1,_t=function createBaseFor(e){return function(t,i,n){for(var r=-1,s=Object(t),o=n(t),a=o.length;a--;){var l=o[e?a:++r];if(!1===i(s[l],l,s))break}return t}})}()();return vt=e}var xt,St,Ct,Tt,Mt,It,Pt,qt,Et,jt,$t,Ot,Dt,At,Nt,Bt,Ft,zt,Lt,Ht,Rt,Wt,Vt,Ut,Gt,Kt,Xt,Yt,Jt,Qt,Zt,ei,ti,ii={exports:{}};function require_cloneArrayBuffer(){if(Mt)return Tt;Mt=1;var e=function require_Uint8Array(){if(Ct)return St;Ct=1;var e=require_root().Uint8Array;return St=e}();return Tt=function cloneArrayBuffer(t){var i=new t.constructor(t.byteLength);return new e(i).set(new e(t)),i}}function require_getPrototype(){if(Nt)return At;Nt=1;var e=function require_overArg(){return Dt?Ot:(Dt=1,Ot=function overArg(e,t){return function(i){return e(t(i))}})}()(Object.getPrototypeOf,Object);return At=e}function require_isPrototype(){if(Ft)return Bt;Ft=1;var e=Object.prototype;return Bt=function isPrototype(t){var i=t&&t.constructor;return t===("function"==typeof i&&i.prototype||e)}}function require_initCloneObject(){if(Lt)return zt;Lt=1;var e=function require_baseCreate(){if($t)return jt;$t=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 jt=i}(),t=require_getPrototype(),i=require_isPrototype();return zt=function initCloneObject(n){return"function"!=typeof n.constructor||i(n)?{}:e(t(n))}}function requireIsObjectLike(){if(Rt)return Ht;return Rt=1,Ht=function isObjectLike(e){return null!=e&&"object"==typeof e}}function requireIsArguments(){if(Gt)return Ut;Gt=1;var e=function require_baseIsArguments(){if(Vt)return Wt;Vt=1;var e=require_baseGetTag(),t=requireIsObjectLike();return Wt=function baseIsArguments(i){return t(i)&&"[object Arguments]"==e(i)}}(),t=requireIsObjectLike(),i=Object.prototype,n=i.hasOwnProperty,r=i.propertyIsEnumerable,s=e(function(){return arguments}())?e:function(e){return t(e)&&n.call(e,"callee")&&!r.call(e,"callee")};return Ut=s}function requireIsArray(){if(Xt)return Kt;Xt=1;var e=Array.isArray;return Kt=e}function requireIsLength(){if(Jt)return Yt;Jt=1;return Yt=function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}}function requireIsArrayLike(){if(Zt)return Qt;Zt=1;var e=requireIsFunction(),t=requireIsLength();return Qt=function isArrayLike(i){return null!=i&&t(i.length)&&!e(i)}}var ni,ri,si,oi,ai,li,hi,ci,ui,di={exports:{}};function requireIsBuffer(){return si||(si=1,function(e,t){var i=require_root(),n=function requireStubFalse(){return ri?ni:(ri=1,ni=function stubFalse(){return!1})}(),r=t&&!t.nodeType&&t,s=r&&e&&!e.nodeType&&e,o=s&&s.exports===r?i.Buffer:void 0,a=(o?o.isBuffer:void 0)||n;e.exports=a}(di,di.exports)),di.exports}var pi,yi,fi,gi,mi,_i,bi,vi,wi,ki,xi,Si,Ci,Ti,Mi,Ii,Pi,qi,Ei,ji,$i,Oi,Di,Ai,Ni,Bi,Fi,zi,Li,Hi,Ri,Wi,Vi,Ui,Gi,Ki,Xi,Yi,Ji,Qi,Zi,en,tn,nn,rn,sn,on,an,ln,hn={exports:{}};function requireIsTypedArray(){if(fi)return yi;fi=1;var e=function require_baseIsTypedArray(){if(hi)return li;hi=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,li=function baseIsTypedArray(r){return i(r)&&t(r.length)&&!!n[e(r)]}}(),t=function require_baseUnary(){return ui?ci:(ui=1,ci=function baseUnary(e){return function(t){return e(t)}})}(),i=function require_nodeUtil(){return pi||(pi=1,e=hn,t=hn.exports,i=require_freeGlobal(),n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,s=r&&r.exports===n&&i.process,o=function(){try{return r&&r.require&&r.require("util").types||s&&s.binding&&s.binding("util")}catch(e){}}(),e.exports=o),hn.exports;var e,t,i,n,r,s,o}(),n=i&&i.isTypedArray,r=n?t(n):e;return yi=r}function require_safeGet(){if(mi)return gi;return mi=1,gi=function safeGet(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}}function require_copyObject(){if(wi)return vi;wi=1;var e=function require_assignValue(){if(bi)return _i;bi=1;var e=require_baseAssignValue(),t=requireEq(),i=Object.prototype.hasOwnProperty;return _i=function assignValue(n,r,s){var o=n[r];i.call(n,r)&&t(o,s)&&(void 0!==s||r in n)||e(n,r,s)}}(),t=require_baseAssignValue();return vi=function copyObject(i,n,r,s){var o=!r;r||(r={});for(var a=-1,l=n.length;++a<l;){var h=n[a],c=s?s(r[h],i[h],h,r,i):void 0;void 0===c&&(c=i[h]),o?t(r,h,c):e(r,h,c)}return r}}function require_isIndex(){if(Ci)return Si;Ci=1;var e=/^(?:0|[1-9]\d*)$/;return Si=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(Mi)return Ti;Mi=1;var e=function require_baseTimes(){return xi?ki:(xi=1,ki=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(),r=require_isIndex(),s=requireIsTypedArray(),o=Object.prototype.hasOwnProperty;return Ti=function arrayLikeKeys(a,l){var h=i(a),c=!h&&t(a),u=!h&&!c&&n(a),d=!h&&!c&&!u&&s(a),p=h||c||u||d,y=p?e(a.length,String):[],f=y.length;for(var g in a)!l&&!o.call(a,g)||p&&("length"==g||u&&("offset"==g||"parent"==g)||d&&("buffer"==g||"byteLength"==g||"byteOffset"==g)||r(g,f))||y.push(g);return y}}function require_baseKeysIn(){if(Ei)return qi;Ei=1;var e=requireIsObject(),t=require_isPrototype(),i=function require_nativeKeysIn(){return Pi?Ii:(Pi=1,Ii=function nativeKeysIn(e){var t=[];if(null!=e)for(var i in Object(e))t.push(i);return t})}(),n=Object.prototype.hasOwnProperty;return qi=function baseKeysIn(r){if(!e(r))return i(r);var s=t(r),o=[];for(var a in r)("constructor"!=a||!s&&n.call(r,a))&&o.push(a);return o}}function requireKeysIn(){if($i)return ji;$i=1;var e=require_arrayLikeKeys(),t=require_baseKeysIn(),i=requireIsArrayLike();return ji=function keysIn(n){return i(n)?e(n,!0):t(n)}}function require_baseMergeDeep(){if(Ni)return Ai;Ni=1;var e=require_assignMergeValue(),t=function require_cloneBuffer(){return xt||(xt=1,e=ii,t=ii.exports,i=require_root(),n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,s=r&&r.exports===n?i.Buffer:void 0,o=s?s.allocUnsafe:void 0,e.exports=function cloneBuffer(e,t){if(t)return e.slice();var i=e.length,n=o?o(i):new e.constructor(i);return e.copy(n),n}),ii.exports;var e,t,i,n,r,s,o}(),i=function require_cloneTypedArray(){if(Pt)return It;Pt=1;var e=require_cloneArrayBuffer();return It=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 Et?qt:(Et=1,qt=function copyArray(e,t){var i=-1,n=e.length;for(t||(t=Array(n));++i<n;)t[i]=e[i];return t})}(),r=require_initCloneObject(),s=requireIsArguments(),o=requireIsArray(),a=function requireIsArrayLikeObject(){if(ti)return ei;ti=1;var e=requireIsArrayLike(),t=requireIsObjectLike();return ei=function isArrayLikeObject(i){return t(i)&&e(i)}}(),l=requireIsBuffer(),h=requireIsFunction(),c=requireIsObject(),u=function requireIsPlainObject(){if(ai)return oi;ai=1;var e=require_baseGetTag(),t=require_getPrototype(),i=requireIsObjectLike(),n=Function.prototype,r=Object.prototype,s=n.toString,o=r.hasOwnProperty,a=s.call(Object);return oi=function isPlainObject(n){if(!i(n)||"[object Object]"!=e(n))return!1;var r=t(n);if(null===r)return!0;var l=o.call(r,"constructor")&&r.constructor;return"function"==typeof l&&l instanceof l&&s.call(l)==a}}(),d=requireIsTypedArray(),p=require_safeGet(),y=function requireToPlainObject(){if(Di)return Oi;Di=1;var e=require_copyObject(),t=requireKeysIn();return Oi=function toPlainObject(i){return e(i,t(i))}}();return Ai=function baseMergeDeep(f,g,m,_,b,v,w){var k=p(f,m),x=p(g,m),S=w.get(x);if(S)e(f,m,S);else{var C=v?v(k,x,m+"",f,g,w):void 0,T=void 0===C;if(T){var M=o(x),I=!M&&l(x),P=!M&&!I&&d(x);C=x,M||I||P?o(k)?C=k:a(k)?C=n(k):I?(T=!1,C=t(x,!0)):P?(T=!1,C=i(x,!0)):C=[]:u(x)||s(x)?(C=k,s(k)?C=y(k):c(k)&&!h(k)||(C=r(x))):T=!1}T&&(w.set(x,C),b(C,x,_,v,w),w.delete(x)),e(f,m,C)}}}function requireIdentity(){if(Li)return zi;return Li=1,zi=function identity(e){return e}}function require_overRest(){if(Vi)return Wi;Vi=1;var e=function require_apply(){return Ri?Hi:(Ri=1,Hi=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 Wi=function overRest(i,n,r){return n=t(void 0===n?i.length-1:n,0),function(){for(var s=arguments,o=-1,a=t(s.length-n,0),l=Array(a);++o<a;)l[o]=s[n+o];o=-1;for(var h=Array(n+1);++o<n;)h[o]=s[o];return h[n]=r(l),e(i,this,h)}},Wi}function require_baseSetToString(){if(Xi)return Ki;Xi=1;var e=function requireConstant(){return Gi?Ui:(Gi=1,Ui=function constant(e){return function(){return e}})}(),t=require_defineProperty(),i=requireIdentity();return Ki=t?function(i,n){return t(i,"toString",{configurable:!0,enumerable:!1,value:e(n),writable:!0})}:i}function require_setToString(){if(Zi)return Qi;Zi=1;var e=require_baseSetToString(),t=function require_shortOut(){if(Ji)return Yi;Ji=1;var e=Date.now;return Yi=function shortOut(t){var i=0,n=0;return function(){var r=e(),s=16-(r-n);if(n=r,s>0){if(++i>=800)return arguments[0]}else i=0;return t.apply(void 0,arguments)}},Yi}(),i=t(e);return Qi=i}function require_createAssigner(){if(on)return sn;on=1;var e=function require_baseRest(){if(tn)return en;tn=1;var e=requireIdentity(),t=require_overRest(),i=require_setToString();return en=function baseRest(n,r){return i(t(n,r,e),n+"")}}(),t=function require_isIterateeCall(){if(rn)return nn;rn=1;var e=requireEq(),t=requireIsArrayLike(),i=require_isIndex(),n=requireIsObject();return nn=function isIterateeCall(r,s,o){if(!n(o))return!1;var a=typeof s;return!!("number"==a?t(o)&&i(s,o.length):"string"==a&&s in o)&&e(o[s],r)}}();return sn=function createAssigner(i){return e(function(e,n){var r=-1,s=n.length,o=s>1?n[s-1]:void 0,a=s>2?n[2]:void 0;for(o=i.length>3&&"function"==typeof o?(s--,o):void 0,a&&t(n[0],n[1],a)&&(o=s<3?void 0:o,s=1),e=Object(e);++r<s;){var l=n[r];l&&i(e,l,r,o)}return e})}}var cn=function requireMerge(){if(ln)return an;ln=1;var e=function require_baseMerge(){if(Fi)return Bi;Fi=1;var e=require_Stack(),t=require_assignMergeValue(),i=require_baseFor(),n=require_baseMergeDeep(),r=requireIsObject(),s=requireKeysIn(),o=require_safeGet();return Bi=function baseMerge(a,l,h,c,u){a!==l&&i(l,function(i,s){if(u||(u=new e),r(i))n(a,l,s,h,baseMerge,c,u);else{var d=c?c(o(a,s),i,s+"",a,l,u):void 0;void 0===d&&(d=i),t(a,s,d)}},s)},Bi}(),t=require_createAssigner()(function(t,i,n){e(t,i,n)});return an=t}(),un=getDefaultExportFromCjs(cn);class Entity extends h{static typeId="ice-entity-designer:Entity";hasDerivedChildren(){return!0}entityFieldsComponent=[];constructor(e){super(Entity.arrangeParam(e)),this.syncEntityNameAndFields()}static arrangeParam(e){const t=un({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 kt(t.entityName)&&(t.entityName="Entity Name"),kt(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 c({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 u({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 d({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(!kt(this.state.fields)){const e=this.state.fields.length;for(let t=0;t<e;t++){const i=this.state.fields[t],n=this.fieldDisplay(i),r=new c({left:0,top:0,text:n.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(" ")} `:"",r=e.type?`${e.type}${e.length?`(${e.length})`:""}`:"",s=i.length?` ${i.join(" ")}`:"",o=void 0!==e.default?` = ${e.default}`:"",a=e.comment?` // ${e.comment}`:"";return{text:`${n}${e.name}${r?` ${r}`:""}${s}${o}${a}`}}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 r=e,s=Math.max(t,this.state.height);return this.state.width=r,this.state.height=s,{width:r,height:s}}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=!kt(e.fields)||!kt(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 p{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,r]=i[e]||i["one-to-one"];return`${t.sourceCardinality||n} : ${t.targetCardinality||r}`}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:r,nullable:s,onDelete:o,onUpdate:a,joinTableName:l,fromKey:h,toKey:c}=this.state;let u,d,p,y,f,g;this.state.links&&this.state.links.start&&this.state.links.start.id&&(p=this.state.links.start.id,u=this.ice.findComponent(p),y=u.state.entityName),this.state.links&&this.state.links.end&&this.state.links.end.id&&(f=this.state.links.end.id,d=this.ice.findComponent(f),g=d.state.entityName);return{title:e,fromId:p,fromName:y,toId:f,toName:g,relationType:t,referencedColumnName:i,sourceField:n,targetField:r,nullable:!1!==s&&void 0,onDelete:o,onUpdate:a,joinTableName:l,fromKey:h,toKey:c}}}function designerChromeFromTheme(e){const t=e&&e.semantic||{},i=t.primary||"#0D6EFD",n=t.success||"#198754",r=t.warning||"#FFC107";return{selection:{stroke:i,fill:withAlpha(i,.12),lineWidth:1,lineDash:[]},handle:{fill:i,stroke:"#ffffff",activeFill:r,lineWidth:1},linkHook:{fill:n,stroke:"#ffffff",lineWidth:1},slot:{fill:n,stroke:"#ffffff",hoverFill:r,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 dn=["T","R","B","L"],pn={T:[0,-1],R:[1,0],B:[0,1],L:[-1,0]};function boxOf(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(e),r=boxOf(t);if(!n||!r)return{...i};const s=centerOf(n),o=centerOf(r);let a={...i},l=1/0;for(const e of dn){const t=portPoint(n,e),i=pn[e],h=(o[0]-t[0])*i[0]+(o[1]-t[1])*i[1]>=0;for(const n of dn){const o=portPoint(r,n),c=pn[n],u=(h?0:1e6)+((s[0]-o[0])*c[0]+(s[1]-o[1])*c[1]>=0?0:1e6)+((o[0]-t[0])*i[0]+(o[1]-t[1])*i[1]>=0&&(t[0]-o[0])*c[0]+(t[1]-o[1])*c[1]>=0?0:1e6)+Math.hypot(t[0]-o[0],t[1]-o[1]);u<l&&(l=u,a={sourcePort:e,targetPort:n})}}return a}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 yn="data",fn=[{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"}],gn=[{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 r=e[n];void 0!==r&&(r&&"object"==typeof r&&!Array.isArray(r)?(void 0!==r.id&&"string"!=typeof r.id&&i.push(`${t}.${n}.id must be a string when present`),void 0!==r.position&&"string"!=typeof r.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"}],mn=[...[{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"}],...fn],_n=[...gn,...fn];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[yn]:void 0;return void 0!==n&&(i[yn]=n),i}function validateDocumentNode(e,t,i,n){e&&"object"==typeof e&&!Array.isArray(e)?i.forEach(i=>{const r=e[i.key];void 0!==r?!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}}(r,i.type)?n.push(`${t}.${i.key} must be a ${i.type} when present`):i.validate&&i.validate(r,`${t}.${i.key}`,n):i.required&&n.push(`${t}.${i.key} is required`)}):n.push(`${t} must be an object`)}const bn=[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"}];function validateNode(e,t,i,n){if(!e||"object"!=typeof e||Array.isArray(e))return void n.push(`${t} must be an object`);const r=void 0===e.typeId?i:e.typeId;!function isEntityTypeId(e){return e===Entity.typeId}(r)?!function isRelationTypeId(e){return e===Relation.typeId}(r)?validateDocumentNode(e,t,bn,n):validateDocumentNode(e,t,_n,n):validateDocumentNode(e,t,mn,n)}function validateSchema(e){const t=[],i=e.filter(isEntity),n=e.filter(isRelation),r=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});r.has(i)||r.set(i,[]),r.get(i).push(e);const n=e.state.fields||[];0===n.length&&t.push({level:"warning",message:`Entity "${i}" 没有任何字段`,componentId:e.state.id});const s=new Set;n.forEach(n=>{const r=(n.name||"").trim();r?s.has(r)?t.push({level:"error",message:`Entity "${i}" 存在重复字段 "${r}"`,componentId:e.state.id}):s.add(r):t.push({level:"error",message:`Entity "${i}" 存在未命名字段`,componentId:e.state.id}),n.type||t.push({level:"warning",message:`Entity "${i}" 的字段 "${r||"(未命名)"}" 未设置类型`,componentId:e.state.id})})}),r.forEach((e,i)=>{e.length>1&&t.push({level:"error",message:`存在重复的 Entity 名称 "${i}"`})}),n.forEach(e=>{const n=e.state.links||{},r=n.start&&n.start.id,s=n.end&&n.end.id,o=e.state.relationType;if(!r||!s)return void t.push({level:"error",message:"存在没有完整起点/终点的 Relation",componentId:e.state.id});const a=i.some(e=>e.state.id===r),l=i.some(e=>e.state.id===s);a&&l||t.push({level:"error",message:"Relation 连接到了不存在的 Entity",componentId:e.state.id}),o?"many-to-many"!==o||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,r=e.length;n<r;n++){let r=e[n].toLowerCase();(t||0!==n)&&(r=r.substr(0,1).toUpperCase()+r.substr(1)),i+=r}return i}(toWords(e),t)}var vn=[],wn=[],kn={},xn={},Sn={};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 r=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,r)})}function sanitizeWord(e,t,i){if(!e.length||kn.hasOwnProperty(e))return t;for(var n=i.length;n--;){var r=i[n];if(r[0].test(t))return replace(t,r)}return t}function replaceWord(e,t,i){return function(n){var r=n.toLowerCase();return t.hasOwnProperty(r)?restoreCase(n,r):e.hasOwnProperty(r)?restoreCase(n,e[r]):sanitizeWord(r,n,i)}}function checkWord(e,t,i){return function(n){var r=n.toLowerCase();return!!t.hasOwnProperty(r)||!e.hasOwnProperty(r)&&sanitizeWord(r,r,i)===r}}function pluralize(e,t,i){return(i?t+" ":"")+(1===t?pluralize.singular(e):pluralize.plural(e))}pluralize.plural=replaceWord(Sn,xn,vn),pluralize.isPlural=checkWord(Sn,xn,vn),pluralize.singular=replaceWord(xn,Sn,wn),pluralize.isSingular=checkWord(xn,Sn,wn),pluralize.addPluralRule=function(e,t){vn.push([sanitizeRule(e),t])},pluralize.addSingularRule=function(e,t){wn.push([sanitizeRule(e),t])},pluralize.addUncountableRule=function(e){"string"!=typeof e?(pluralize.addPluralRule(e,"$0"),pluralize.addSingularRule(e,"$0")):kn[e.toLowerCase()]=!0},pluralize.addIrregularRule=function(e,t){t=t.toLowerCase(),e=e.toLowerCase(),Sn[e]=t,xn[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 Cn={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"},Tn=["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 Cn[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&&Tn.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 r=t[e];if(isRelation(r))i.push(r);else if(isEntity(r)){const e=r.toEntityObject();e.columns=normalizeColumns(e.columns),n[r.state.id]=e}}for(let e=0;e<i.length;e++){const t=i[e],{fromId:r,fromName:s,toId:o,toName:a,relationType:l,referencedColumnName:h,sourceField:c,targetField:u,nullable:d,onDelete:p,onUpdate:y,joinTableName:f,fromKey:g,toKey:m}=t.toEntityObject(),_=n[r],b=n[o];if(!_||!b)continue;_.relations||(_.relations={}),b.relations||(b.relations={});const v=g||camelCase(a),w=m||camelCase(s),k={};!1===d&&(k.nullable=!1),p&&(k.onDelete=p),y&&(k.onUpdate=y),"one-to-one"===l?(b.relations[w]={type:l,target:s,joinColumn:buildJoinColumn(u||h,c||h),...k},_.relations[v]={type:l,target:a,inverseSide:w}):"one-to-many"===l?(_.relations[v]={type:l,target:a,inverseSide:w},b.relations[w]={type:"many-to-one",target:s,joinColumn:buildJoinColumn(u||h,c||h),...k}):"many-to-one"===l?(_.relations[v]={type:l,target:a,joinColumn:buildJoinColumn(c||h,u||h),...k},b.relations[w]={type:"one-to-many",target:s,inverseSide:v}):"many-to-many"===l&&(_.relations[`${pluralize(v)}`]={type:l,target:a,joinTable:!f||{name:f}},b.relations[`${pluralize(w)}`]={type:l,target:s,inverseSide:`${pluralize(v)}`})}const r=[];for(const e in n)r.push(n[e]);return r}function toSchemaString(e){return JSON.stringify(toSchemaObject(e))}function registerIEDType(e,t){e.registerType(t.typeId,t)}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,r=i?this.ice.findComponent(i):null,s=autoPorts(n,r,{sourcePort:"R",targetPort:"L"}),o=e.links&&e.links.start&&e.links.start.position||e.startPosition||s.sourcePort,a=e.links&&e.links.end&&e.links.end.position||e.endPosition||s.targetPort,l=e.links||{start:{id:t,position:o},end:{id:i,position:a}},h=n?this.__slotPoint(n,o):null,c=r?this.__slotPoint(r,a):null,u=new Relation({relationType:e.relationType||"one-to-many",sourceField:e.sourceField||"id",targetField:e.targetField||"id",links:l,startPoint:h||[0,0],endPoint:c||[10,10],...e});return this.ice.addChild(u),this.select(u.state.id),this.__emitChange(),u}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 r=this.serializeProject(),s=n.map(e=>e.state.zIndex);"front"===t?i.bringToFront():"back"===t?i.sendToBack():"up"===t?i.moveUp():i.moveDown();const o=n.map(e=>e.state.zIndex);return!(s.length===o.length&&!s.some((e,t)=>e!==o[t]))&&(this.__pushHistory(r),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:y(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 i=y(e);if(i)return t&&t.documentMeta&&(t.documentMeta.createTime=i),i;const n=(new Date).toISOString();return t&&t.documentMeta&&(t.documentMeta.createTime=n),n}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},mn)}__slotPoint(e,t){const i=e.getMinBoundingBox(!0),n=i.center[0],r=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],r];case"R":return[i.tr[0],r];default:return[n,r]}}__relationSnapshot(e){return pickDocumentNode({...e.state||{},typeId:Relation.typeId},_n)}__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=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})}(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,r){-1===e.unknownTypes.indexOf(n)&&e.unknownTypes.push(n);const s=r&&"string"==typeof r.id?r.id:void 0;e.skipped.push(void 0===s?{bucket:t,index:i,typeId:n}:{bucket:t,index:i,typeId:n,id:s})}__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 r=this.__resolveTypeId(e,t),s=this.__resolveComponentClass(r);if("function"!=typeof s)return this.__recordUnknownType(i,t,n,r,e),null;const o=new s(e);return delete o.state.typeId,delete o.props.typeId,this.ice.addChild(o),o},collect=(e,t,n)=>{const r=createNode(e,t,n);isEntity(r)?i.entities+=1:isRelation(r)&&(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)}}function createEmptyPath$1(e){const t=e.path2D&&e.path2D.constructor;return t?new t:null}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 BpmnTaskIcon extends f{static typeId="ice-entity-designer:BpmnTaskIcon";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=i+e/2,o=n+t/2,a=Math.min(e,t)/2,l=this.state.taskType||"none";if("user"===l)r.moveTo(s,o-a),r.arc(s,o-.35*a,.34*a,0,2*Math.PI),r.moveTo(s-.62*a,o+.72*a),r.arc(s,o+.72*a,.62*a,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=s+Math.cos(i)*a*.55,l=o+Math.sin(i)*a*.55,h=s+Math.cos(i)*a,c=o+Math.sin(i)*a;r.moveTo(n,l),r.lineTo(h,c)}r.moveTo(s+.34*a,o),r.arc(s,o,.34*a,0,2*Math.PI)}else"script"===l?(r.moveTo(s-.7*a,o-.85*a),r.lineTo(s+.7*a,o-.85*a),r.lineTo(s+.7*a,o+.5*a),r.moveTo(s-.7*a,o-.85*a),r.lineTo(s-.7*a,o+.5*a),r.moveTo(s-.7*a,o+.6*a),r.lineTo(s-.25*a,o+.85*a),r.lineTo(s+.25*a,o+.6*a),r.lineTo(s+.7*a,o+.85*a)):"send"===l?(r.moveTo(s-.85*a,o-.55*a),r.lineTo(s+.85*a,o-.55*a),r.lineTo(s+.85*a,o+.55*a),r.lineTo(s-.85*a,o+.55*a),r.closePath(),r.moveTo(s-.85*a,o-.55*a),r.lineTo(s,o+.12*a),r.lineTo(s+.85*a,o-.55*a)):"receive"===l?(r.moveTo(s-.85*a,o-.55*a),r.lineTo(s+.85*a,o-.55*a),r.lineTo(s+.85*a,o+.55*a),r.lineTo(s-.85*a,o+.55*a),r.closePath()):"manual"===l&&(r.moveTo(s-.7*a,o+.6*a),r.lineTo(s-.45*a,o-.5*a),r.lineTo(s+.45*a,o-.5*a),r.lineTo(s+.7*a,o+.6*a),r.closePath());return this.path2D=r,this.path2D}}class BpmnSubprocessMarker extends f{static typeId="ice-entity-designer:BpmnSubprocessMarker";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);return r?(r.moveTo(i,n),r.lineTo(i+e,n),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),r.moveTo(i+e/2,n+.22*t),r.lineTo(i+e/2,n+.78*t),r.moveTo(i+.22*e,n+t/2),r.lineTo(i+.78*e,n+t/2),this.path2D=r,this.path2D):this.path2D}}const Mn={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}},In=["bpmnPool","bpmnLane","bpmnAnnotation","bpmnDataObject"],Pn={rect:u,diamond:class FlowDiamond extends f{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],r=createEmptyPath$1(this);return r?(r.moveTo(i+e/2,n),r.lineTo(i+e,n+t/2),r.lineTo(i+e/2,n+t),r.lineTo(i,n+t/2),r.closePath(),this.path2D=r,this.path2D):this.path2D}},parallelogram:class FlowParallelogram extends f{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],r=0-this.state.localOrigin[1],s=createEmptyPath$1(this);return s?(s.moveTo(n+i,r),s.lineTo(n+e,r),s.lineTo(n+e-i,r+t),s.lineTo(n,r+t),s.closePath(),this.path2D=s,this.path2D):this.path2D}},event:class BpmnEventShape extends f{static typeId="ice-entity-designer:BpmnEventShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=i+e/2,o=n+t/2,a=Math.min(e,t)/2,l=this.state.eventKind||"start";r.arc(s,o,a,0,2*Math.PI),"intermediate"!==l&&"end"!==l||(r.moveTo(s+.84*a,o),r.arc(s,o,.84*a,0,2*Math.PI));const h=this.state.trigger||"none";if("message"===h){const e=1.1*a,t=.78*a;r.moveTo(s-e/2,o-t/2),r.lineTo(s+e/2,o-t/2),r.lineTo(s+e/2,o+t/2),r.lineTo(s-e/2,o+t/2),r.closePath(),r.moveTo(s-e/2,o-t/2),r.lineTo(s,o+.08*t),r.lineTo(s+e/2,o-t/2)}else if("timer"===h){const e=.52*a;r.moveTo(s+e,o),r.arc(s,o,e,0,2*Math.PI),r.moveTo(s,o),r.lineTo(s,o-.62*e),r.moveTo(s,o),r.lineTo(s+.5*e,o)}else"error"===h?(r.moveTo(s+.34*a,o-.62*a),r.lineTo(s-.42*a,o+.06*a),r.lineTo(s-.02*a,o+.06*a),r.lineTo(s-.3*a,o+.66*a),r.lineTo(s+.44*a,o-.02*a),r.lineTo(s+.04*a,o-.02*a),r.closePath()):"terminate"===h&&(r.moveTo(s+.5*a,o),r.arc(s,o,.5*a,0,2*Math.PI));return this.path2D=r,this.path2D}},gateway:class BpmnGatewayShape extends f{static typeId="ice-entity-designer:BpmnGatewayShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=i+e/2,o=n+t/2,a=e/2,l=t/2;r.moveTo(s,o-l),r.lineTo(s+a,o),r.lineTo(s,o+l),r.lineTo(s-a,o),r.closePath();const h=this.state.gatewayType||"exclusive",c=.42*Math.min(a,l);if("exclusive"===h)r.moveTo(s-c,o-c),r.lineTo(s+c,o+c),r.moveTo(s+c,o-c),r.lineTo(s-c,o+c);else if("parallel"===h)r.moveTo(s-c,o),r.lineTo(s+c,o),r.moveTo(s,o-c),r.lineTo(s,o+c);else if("inclusive"===h)r.moveTo(s+c,o),r.arc(s,o,c,0,2*Math.PI);else if("event"===h){const e=1.15*c;for(let t=0;t<5;t++){const i=-Math.PI/2+t*Math.PI*2/5,n=s+Math.cos(i)*e,a=o+Math.sin(i)*e;0===t?r.moveTo(n,a):r.lineTo(n,a)}r.closePath()}return this.path2D=r,this.path2D}},dataObject:class BpmnDataObjectShape extends f{static typeId="ice-entity-designer:BpmnDataObjectShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=Math.min(14,.22*e,.32*t);return r.moveTo(i,n),r.lineTo(i+e-s,n),r.lineTo(i+e,n+s),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),r.moveTo(i+e-s,n),r.lineTo(i+e-s,n+s),r.lineTo(i+e,n+s),this.path2D=r,this.path2D}},annotation:class BpmnAnnotationShape extends f{static typeId="ice-entity-designer:BpmnAnnotationShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=Math.min(16,.3*e);return r.moveTo(i,n),r.lineTo(i+e,n),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),r.moveTo(i+s,n),r.lineTo(i,n),r.lineTo(i,n+t),r.lineTo(i+s,n+t),this.path2D=r,this.path2D}},lane:class BpmnLaneShape extends f{static typeId="ice-entity-designer:BpmnLaneShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=Math.min(this.state.bandSize||30,.4*e,.4*t);return r.moveTo(i,n),r.lineTo(i+e,n),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),"top"===(this.state.band||"left")?(r.moveTo(i,n+s),r.lineTo(i+e,n+s)):(r.moveTo(i+s,n),r.lineTo(i+s,n+t)),this.path2D=r,this.path2D}}},qn="#0f172a";class FlowNode extends h{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=Mn[e.kind]?e.kind:"process",i=Mn[t];super({kind:t,title:i.label,fillColor:i.fill,strokeColor:i.stroke,textColor:qn,fontSize:14,width:i.width,height:i.height,fill:!1,stroke:!1,draggable:!0,interactive:!0,transformable:!1,linkable:-1===In.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=Mn[this.state.kind]||Mn.process,t=Pn[e.shape]||u;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 i="top-left"===e.labelPlacement,n="lane"===e.shape&&"left"===e.band,r=n?Math.min(Number(e.bandSize)||30,.4*this.state.width,.4*this.state.height):0,s=n?Math.max(this.state.height-8,r):0;this.labelComponent=new c(n?{left:r/2-s/2,top:this.state.height/2-r/2,width:s,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||qn,textAlign:"center",textBaseline:"middle",fontWeight:"bold"}}:{left:i?10:0,top:i?"top"===e.band?18:16:0,width:i?Math.max(this.state.width-20,20):this.state.width,height:i?18:this.state.height,text:String(this.state.title||""),wrap:!i,maxLines:2,interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fontSize:this.state.fontSize||(i?13:14),fillStyle:this.state.textColor||qn,textAlign:i?"left":"center",textBaseline:"middle",fontWeight:i?"bold":"normal",paddingLeft:i?0:12,paddingRight:i?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,i=void 0!==e.left||void 0!==e.top,n=void 0!==e.width||void 0!==e.height;if(n&&this.trigger(g.BEFORE_RESIZE),i){const t=void 0!==e.left?e.left:this.state.left,i=void 0!==e.top?e.top:this.state.top,n={...e};delete n.left,delete n.top,Object.keys(n).length&&this.setState(n),this.setPosition(t,i)}else this.setState(e);return t?this.__buildShape():this.labelComponent&&this.labelComponent.setState({text:String(this.state.title||"")}),(n||t)&&this.trigger(g.AFTER_RESIZE),this.dirty=!0,this}}class FlowEdge extends p{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,i=e.minX-t,n=e.minY-t,r=Math.max(1,e.maxX-e.minX+2*t),s=Math.max(1,e.maxY-e.minY+2*t);let o=this.boxes.get(e.id);if(!o)return o=new u({left:i,top:n,width:r,height:s,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:i,top:n,width:r,height:s,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||m.semantic.primary}catch{return m.semantic.primary}}}class FlowDesigner{selectedId=null;__undoStack=[];__redoStack=[];__historyEnabled=!0;__maxHistory=100;__maxHistoryBytes=33554432;__historyBytes=0;__batchDepth=0;__batchStart=null;__listeners=[];__mousedownHandler=e=>this.__handleMouseDown(e);__moveSession=!1;__moveEmitQueued=!1;__patchDepth=0;__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=>this.isNodeComponent(e))}get edges(){return this.__flatten().filter(e=>this.isEdgeComponent(e))}isNodeComponent(e){return e instanceof FlowNode}isEdgeComponent(e){return e instanceof FlowEdge}__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(g.BEFORE_MOVE,this.__beforeMoveHandler,this),e.on(g.AFTER_MOVE,this.__afterMoveHandler,this))}__detachNodeListeners(e){e&&"function"==typeof e.off&&(e.off(g.BEFORE_MOVE,this.__beforeMoveHandler,this),e.off(g.AFTER_MOVE,this.__afterMoveHandler,this))}__onBeforeMove(){this.__patchDepth>0||this.__moveSession||(this.__moveSession=!0,this.__captureHistory())}__onAfterMove(){if(this.__patchDepth>0)return;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,r=-1/0;i.forEach(e=>{const t=e.getMinBoundingBox(!0);n=Math.min(n,t.tl[0]),r=Math.max(r,t.br[1])});const s=i.length;return{left:n+s%4*280,top:r+80+Math.floor(s/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"}),r=e.sourcePort||n.sourcePort,s=e.targetPort||n.targetPort,o=new FlowEdge({id:e.id,links:{start:{id:e.sourceId,position:r},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,r),endPoint:this.__slotPoint(i,s),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(o),this.selectedId=o.state.id,this.__emitChange(),o}updateNode(e,t){const i=this.ice.findComponent(e);return i&&this.isNodeComponent(i)&&(this.__captureHistory(),this.__applyPatch(i,t),this.__emitChange()),i}updateEdge(e,t){const i=this.ice.findComponent(e);return i&&this.isEdgeComponent(i)&&(this.__captureHistory(),this.__applyPatch(i,t),this.__emitChange()),i}__applyPatch(e,t){this.__patchDepth++;try{e&&"function"==typeof e.applyPatch?e.applyPatch(t):(e.setState(t),e.dirty=!0)}finally{this.__patchDepth--}}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 _(e)}__deserializer(){const e=this.ice;return e.deserializer||new b(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=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})}(t);if(!n.valid)throw new Error(`Invalid flow snapshot:\n${n.errors.join("\n")}`);this.__captureHistory();const r=i?this.__applyEngineScene(t.scene,t.createTime):this.__clearAndBuild(t);return this.__emitChange(),r}__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,r=e.sourcePort||e.links&&e.links.start&&e.links.start.position||"B",s=e.targetPort||e.links&&e.links.end&&e.links.end.position||"T",o=i&&n?{start:{id:i,position:r},end:{id:n,position:s}}:e.links,a=new FlowEdge({...e,links:o,startPoint:e.startPoint||[0,0],endPoint:e.endPoint||[10,10]});delete a.state.typeId,this.ice.addChild(a),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 r=1/0,s=1/0,o=-1/0,a=-1/0;t.forEach(e=>{const t=e.getMinBoundingBox(!0);r=Math.min(r,t.tl[0]),s=Math.min(s,t.tl[1]),o=Math.max(o,t.br[0]),a=Math.max(a,t.br[1])});const l=Math.max(o-r,1),h=Math.max(a-s,1),c=Math.min((i-2*e)/l,(n-2*e)/h,1.25),u=(i-l*c)/2-r*c,d="start"===this.fitViewportAlign?e-s*c:(n-h*c)/2-s*c;this.ice.setViewport(c,u,d)}__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 v(this.ice,e)}canRedo(){return this.__redoStack.length>0}captureHistory(){this.__captureHistory()}resetHistory(){this.__undoStack.length=0,this.__redoStack.length=0,this.__historyBytes=0,this.__batchStart=null}beginBatch(){0===this.__batchDepth&&this.__historyEnabled&&(this.__batchStart=this.serialize()),this.__batchDepth++}endBatch(){if(0!==this.__batchDepth&&(this.__batchDepth--,0===this.__batchDepth)){const e=this.__batchStart;this.__batchStart=null,null!==e&&this.__historyEnabled&&this.__pushHistory(e)}}setHistoryBudget(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Number(e.maxEntries)>0&&(this.__maxHistory=Math.floor(Number(e.maxEntries))),Number(e.maxBytes)>0&&(this.__maxHistoryBytes=Math.floor(Number(e.maxBytes))),this.__recountHistory()}getHistoryStats(){return{undo:this.__undoStack.length,redo:this.__redoStack.length,bytes:this.__historyBytes}}__captureHistory(){this.__historyEnabled&&(this.__batchDepth>0||this.__pushHistory(this.serialize()))}__pushHistory(e){for(this.__undoStack.push(e),this.__redoStack.length=0,this.__recountHistory();this.__undoStack.length>0&&(this.__undoStack.length>this.__maxHistory||this.__historyBytes>this.__maxHistoryBytes)&&1!==this.__undoStack.length;)this.__undoStack.shift(),this.__recountHistory()}__recountHistory(){let e=0;for(const t of this.__undoStack)e+=t.length;for(const t of this.__redoStack)e+=t.length;this.__historyBytes=e}__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.__recountHistory(),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.__recountHistory(),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;){if(this.isSelectableComponent(i))return void this.select(i.state.id);i=i.parentNode}}isSelectableComponent(e){return e instanceof FlowNode||e instanceof FlowEdge}dispose(){this.ice.evtBus.off("mousedown",this.__mousedownHandler,this),this.ice.evtBus.off("mouseup",this.__mouseupHandler,this),this.nodes.forEach(e=>this.__detachNodeListeners(e))}}const En={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"}},jn={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}},$n="#1f2937",On=1.4,Dn=1,An="#eff6ff",Nn="#fef3c7",Bn=9.5,Fn="#64748b",zn=12,Ln="#1e293b",Hn=14,Rn="#ffffff",Wn="#94a3b8",Vn=["sludgeThickener","dewateringMachine","sludgeSilo","screwPump","sludgeOut"];class WaterSymbol extends h{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=jn[t]||jn.pump;return un({kind:t,tag:i.tag,name:"",fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:$n,lineWidth:On},tagStyle:{fontSize:Bn,textColor:Fn},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=jn[e]||jn.pump,i=this.state.width||t.width,n=this.state.height||t.height,r=this.state.style&&this.state.style.strokeStyle||$n,s=this.state.idle?Wn:r,o=this.state.style&&this.state.style.lineWidth||On,a=-1!==Vn.indexOf(e)?Nn:An,l=i/2,h=n/2,c=Number(this.state.zIndex)||0;switch(this.__originX=l,this.__originY=h,e){case"barScreen":this.__box(0,0,i,n,a,s,o,c);for(let e=1;e<=4;e++){const t=i/5*e-i/2;this.__poly([t,n/2,t+8,-n/2],s,Dn,c)}break;case"gritChamber":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/2+10,n/2,0,n/2+14,i/2-10,n/2],s,o,c),this.__circle(-i/4,-n/6,4,"none",s,Dn,c),this.__circle(0,n/8,3,"none",s,Dn,c),this.__circle(i/5,-n/8,3.5,"none",s,Dn,c);break;case"primaryClarifier":case"secondaryClarifier":{const t=Math.min(i,n)/2;this.__circle(0,0,t,a,s,o,c),this.__circle(0,0,t/6,"none",s,Dn,c),this.__poly([-t,0,t,0],s,Dn,c),"secondaryClarifier"===e&&this.__poly([.6*-t,.6*-t,.6*t,.6*t],s,Dn,c);break}case"anaerobicTank":case"anoxicTank":this.__box(0,0,i,n,a,s,o,c),this.__poly([0,-n/2,0,n/2-10],s,Dn,c),this.__poly([-10,n/2-10,10,n/2-10],s,Dn,c);break;case"aerobicTank":this.__box(0,0,i,n,a,s,o,c);for(let e=0;e<4;e++)this.__circle(-i/4+e*i/6,n/4,3.5,"none",s,Dn,c);break;case"coagulationTank":this.__box(0,0,i,n,a,s,o,c),this.__poly([0,-n/2,0,n/2-10],s,Dn,c),this.__poly([-10,n/2-10,10,n/2-10],s,Dn,c),this.__circle(-i/4,-n/4,3,"none",s,Dn,c),this.__circle(-i/4,-n/4+9,2,"none",s,Dn,c);break;case"filterBed":this.__box(0,0,i,n,a,s,o,c);for(let e=0;e<6;e++){const t=-i/2+12+e*(i-24)/5;this.__circle(t,n/6,2.5,"none",s,Dn,c),this.__circle(t,-n/6,2.5,"none",s,Dn,c)}break;case"disinfectionTank":this.__box(0,0,i,n,a,s,o,c);for(let e=1;e<=3;e++){const t=-i/2+e*i/4;this.__poly([t,n/2,t,-n/2+6],s,Dn,c)}break;case"sludgeThickener":{const e=Math.min(i,n)/2;this.__circle(0,0,e,a,s,o,c),this.__circle(0,0,e/5,"none",s,Dn,c),this.__poly([-e,0,-e/5,0],s,Dn,c),this.__poly([e/5,0,e,0],s,Dn,c);break}case"dewateringMachine":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/4,-n/6,i/4,-n/6],s,Dn,c),this.__poly([-i/4,0,i/4,0],s,Dn,c),this.__poly([-i/4,n/6,i/4,n/6],s,Dn,c);break;case"pump":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c),this.__closedPoly([0,.6*-e,.6*e,.5*e,.6*-e,.5*e],s,o,c);break}case"blower":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c);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)],s,Dn,c)}break}case"dosingUnit":this.__box(0,-8,i,n-20,a,s,o,c),this.__closedPoly([0,n/2-16,8,n/2,-8,n/2],s,Dn,c),this.__circle(0,n/2-4,2,"none",s,Dn,c);break;case"valve":this.__closedPoly([-9,-8,-9,8,0,0],s,o,c),this.__closedPoly([9,-8,9,8,0,0],s,o,c),"closed"===this.state.valveState&&this.__poly([0,-10,0,10],"#dc2626",2,c);break;case"flowMeter":this.__circle(0,0,Math.min(i,n)/2,"none",s,o,c),this.__text(l-7,h-.7*Hn,14,"F",Hn,s,"center");break;case"analyzer":this.__circle(0,0,Math.min(i,n)/2,"none",s,o,c),this.__text(l-7,h-.7*Hn,14,"A",Hn,s,"center");break;case"storageTank":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/2+6,n/4,i/2-6,n/4],"#93c5fd",Dn,c),this.__poly([-i/4,-n/6,-i/8,-n/3,0,-n/6,i/8,-n/3,i/4,-n/6],s,Dn,c);break;case"deodorizer":this.__box(0,0,i,n,a,s,o,c);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",s,Dn,c);this.__poly([-i/2,-n/2,-i/2,-n/4],s,o,c);break;case"sludgeSilo":this.__box(0,-n/8,i-20,.6*n,a,s,o,c),this.__poly([-i/2+10,.175*n,0,.42*n,i/2-10,.175*n],s,o,c),this.__poly([0,.42*n,0,n/2-2],s,o,c),this.__poly([-8,-n/8-.3*n,8,-n/8-.3*n],s,Dn,c);break;case"submersiblePump":{const e=Math.min(i,n)/2-3;this.__circle(0,-2,e,"none",s,o,c);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],s,Dn,c)}this.__poly([-e,e+1,e,e+1],s,o,c);break}case"screwPump":this.__box(0,-3,i,n-14,a,s,o,c);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],s,Dn,c)}this.__poly([-i/3,n/2-4,i/3,n/2-4],s,o,c);break;case"vfd":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/4,4,-i/8,-5,0,4,i/8,-5,i/4,4],s,Dn,c);break;case"motorValve":this.__closedPoly([-9,8,-9,24,0,16],s,o,c),this.__closedPoly([9,8,9,24,0,16],s,o,c),this.__poly([0,8,0,2],s,Dn,c),this.__box(0,-6,22,16,"none",s,Dn,c),"closed"===this.state.valveState&&this.__poly([0,6,0,26],"#dc2626",2,c);break;case"checkValve":this.__box(0,0,i-6,n-14,"none",s,o,c),this.__closedPoly([-5,-6,6,0,-5,6],s,Dn,c),this.__poly([-i/2+3,0,i/2-3,0],s,Dn,c);break;case"levelGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c),this.__poly([.62*-e,6,.2*-e,0,.2*e,10,.62*e,4],s,Dn,c),this.__text(l-5,h-1,12,"L",Bn,s,"center");break}case"pressureGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c),this.__poly([0,6,.5*e,.45*-e],s,Dn,c),this.__circle(0,6,2,s,s,Dn,c),this.__text(l-5,h-1,12,"P",Bn,s,"center");break}case"inlet":this.__box(10,0,i-20,n-12,a,s,o,c),this.__closedPoly([-i/2+2,0,-i/2+18,-8,-i/2+18,8],s,o,c);break;case"outlet":this.__box(-10,0,i-20,n-12,a,s,o,c),this.__closedPoly([i/2-2,0,i/2-18,-8,i/2-18,8],s,o,c);break;case"sludgeOut":this.__box(0,0,i,n,a,s,o,c);for(let e=-1;e<=1;e++)this.__poly([10*e-5,n/4,10*e+5,-n/4],s,Dn,c);break;default:this.__box(0,0,i,n,a,s,o,c)}const u=Math.max(i+24,90),d=l-u/2;this.state.tag&&this.__text(d,-18,u,String(this.state.tag),Bn,Fn,"center");const p=String(this.state.name||"");p&&this.__text(d,n+14,u,p,zn,Ln,"center")}__box(e,t,i,n,r,s,o,a){return this.__add("box",new u({left:this.__originX+e-i/2,top:this.__originY+t-n/2,width:i,height:n,radius:3,zIndex:a,interactive:!1,linkable:!1,style:{fillStyle:r,strokeStyle:s,lineWidth:o}}))}__circle(e,t,i,n,r,s,o){return this.__add("circle:"+e+","+t,new w({left:this.__originX+e-i,top:this.__originY+t-i,radius:i,zIndex:o,interactive:!1,linkable:!1,style:{fillStyle:"none"===n?Rn:n,strokeStyle:r,lineWidth:s}}))}__closedPoly(e,t,i,n){const r=this.__poly(e,t,i,n),s=e[e.length-2],o=e[e.length-1];return this.__poly([s,o,e[0],e[1]],t,i,n),r}__poly(e,t,i,n){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,s]=r[0],[o,a]=r[1],l=Math.abs(s-a)<.01,h=l?Math.min(e,o):Math.min(e,o)-i/2,c=l?Math.min(s,a)-i/2:Math.min(s,a),d=l?Math.abs(o-e):i,p=l?i:Math.abs(a-s);return this.__add("line:"+n+":"+h+","+c,new u({left:h,top:c,width:d,height:p,zIndex:n,interactive:!1,linkable:!1,style:{fillStyle:t,strokeStyle:t,lineWidth:0}}))}return this.__add("poly:"+n+":"+r.length,new d({points:r,zIndex:n,interactive:!1,linkable:!1,arrow:"none",lineType:"solid",style:{strokeStyle:t,lineWidth:i}}))}__text(e,t,i,n,r,s){let o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"center";const a=Math.round(1.4*r);return this.__add("text:"+n,new c({left:e,top:t,width:i,height:a,text:n,stroke:!1,interactive:!1,linkable:!1,zIndex:(Number(this.state.zIndex)||0)+4,style:{fontSize:r,fillStyle:s,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]:[]}class WaterPipe extends FlowEdge{static typeId="ice-entity-designer:WaterPipe";applyMediumStyle(){const e=this.state.medium||"sewage",t=En[e]||En.sewage,i=void 0===this.state.label||""===this.state.label?function composePipeLabel(e,t){const i=En[e]||En.sewage,n=String(t||"").trim();return n?`${n} ${i.label}`:i.label}(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 Un="ied:water-virtual-doc",Gn=Object.keys(jn),Kn=Object.keys(En);class WaterVirtualDoc{documentType=(()=>Un)();version=1;tagOf(e){const t=jn[Gn[this.kind[e]]],i=String(e%1e5);return`${t.tag}-${"00000".slice(i.length)}${i}`}nameOf(e){return jn[Gn[this.kind[e]]].label}nodeCount=0;sprites=[];svgDefs=[];scratch=(()=>new Float64Array(4))();labelSyncPad=300;layer=null;lastView=null;syncLabelsOnPaint=!0;constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.ice=e;const i=Math.max(1,t.symbols||2e4);this.worldW=t.worldW||12e3,this.worldH=t.worldH||8e3,this.cols=t.cols||Math.max(1,Math.round(Math.sqrt(i*this.worldW/this.worldH))),this.rows=Math.ceil(i/this.cols);const n=!1!==t.pipes;this.symbolCount=i,this.count=i+i+(n?i:0),this.type=new Uint8Array(this.count),this.x=new Float32Array(this.count),this.y=new Float32Array(this.count),this.w=new Float32Array(this.count),this.h=new Float32Array(this.count),this.kind=new Uint8Array(this.count),this.labelOf=new Int32Array(this.count).fill(-1),this.pipeFrom=new Int32Array(this.count),this.pipeTo=new Int32Array(this.count),this.pipeMedium=new Uint8Array(this.count),this.pipeDn=new Uint16Array(this.count),this.done=new Uint8Array(this.count),this.windowSeen=new Int32Array(this.count).fill(-1);const r=this.worldW/this.cols,s=this.worldH/Math.max(1,this.rows);for(let e=0;e<i;e++){const t=e%this.cols,n=e/this.cols|0,o=(7*e+(e/13|0))%Gn.length,a=jn[Gn[o]],l=t*r+29*e%17,h=n*s+43*e%13;this.type[e]=0,this.kind[e]=o,this.x[e]=l,this.y[e]=h,this.w[e]=a.width,this.h[e]=a.height;const c=i+e;this.type[c]=1,this.kind[c]=o,this.labelOf[c]=e,this.x[c]=l,this.y[c]=h+a.height,this.w[c]=90,this.h[c]=14}if(n)for(let e=0;e<i;e++){const t=2*i+e,n=e+this.cols<i?e+this.cols:e;if(this.type[t]=2,this.pipeFrom[t]=e,this.pipeTo[t]=n,this.pipeMedium[t]=e%Kn.length,this.pipeDn[t]=100+e%9*50,n!==e){const e=this.pipeBox(t,this.scratch);this.x[t]=e[0],this.y[t]=e[1],this.w[t]=e[2]-e[0],this.h[t]=e[3]-e[1]}else this.x[t]=this.x[e],this.y[t]=this.y[e],this.w[t]=0,this.h[t]=0}this.cell=128,this.gw=Math.max(1,Math.ceil(this.worldW/this.cell)+1),this.gh=Math.max(1,Math.ceil(this.worldH/this.cell)+1),this.rebuildIndex(),this.__mintSprites()}rebuildIndex(){this.head=new Int32Array(this.gw*this.gh).fill(-1),this.nodePrim=new Int32Array(2*this.count).fill(-1),this.nodeNext=new Int32Array(2*this.count).fill(-1),this.nodeCount=0;for(let e=0;e<this.count;e++){if(1===this.type[e])continue;if(this.__degenerate(e))continue;const t=Math.max(0,Math.min(this.gw-1,this.x[e]/this.cell|0)),i=Math.max(0,Math.min(this.gw-1,(this.x[e]+this.w[e])/this.cell|0)),n=Math.max(0,Math.min(this.gh-1,this.y[e]/this.cell|0)),r=Math.max(0,Math.min(this.gh-1,(this.y[e]+this.h[e])/this.cell|0));for(let s=n;s<=r;s++)for(let n=t;n<=i;n++)this.__addNode(s*this.gw+n,e)}}__addNode(e,t){if(this.nodeCount>=this.nodePrim.length){const e=new Int32Array(2*this.nodeCount).fill(-1);e.set(this.nodePrim),this.nodePrim=e;const t=new Int32Array(2*this.nodeCount).fill(-1);t.set(this.nodeNext),this.nodeNext=t}this.nodePrim[this.nodeCount]=t,this.nodeNext[this.nodeCount]=this.head[e],this.head[e]=this.nodeCount++}boxAt(e,t){t[0]=this.x[e],t[1]=this.y[e],t[2]=this.x[e]+this.w[e],t[3]=this.y[e]+this.h[e]}forEachInBox(e,t,i,n,r){const s=Math.max(0,Math.min(this.gw-1,e/this.cell|0)),o=Math.max(0,Math.min(this.gw-1,i/this.cell|0)),a=Math.max(0,Math.min(this.gh-1,t/this.cell|0)),l=Math.max(0,Math.min(this.gh-1,n/this.cell|0)),h=++this.windowStamp;for(let c=a;c<=l;c++){const a=c*this.gw;for(let l=s;l<=o;l++){let s=this.head[a+l];for(;-1!==s;){const o=this.nodePrim[s];this.windowSeen[o]!==h&&(this.windowSeen[o]=h,this.x[o]+this.w[o]>=e&&this.x[o]<=i&&this.y[o]+this.h[o]>=t&&this.y[o]<=n&&r(o)),s=this.nodeNext[s]}}}}windowStamp=0;__degenerate(e){return 2===this.type[e]&&this.pipeFrom[e]===this.pipeTo[e]}hitTest(e,t){const i=Math.max(0,Math.min(this.gw-1,e/this.cell|0)),n=Math.max(0,Math.min(this.gh-1,t/this.cell|0));let r=this.head[n*this.gw+i];for(;-1!==r;){const i=this.nodePrim[r];if(this.__hitPrecise(i,e,t))return i;r=this.nodeNext[r]}return-1}__hitPrecise(e,t,i){const n=this.x[e],r=this.y[e];if(t<n||i<r||t>n+this.w[e]||i>r+this.h[e])return!1;if(0===this.type[e])return!0;const s=this.pipeFrom[e],o=this.pipeTo[e],a=this.x[s]+this.w[s]/2,l=this.y[s]+this.h[s]/2,h=this.x[o]+this.w[o]/2,c=this.y[o]+this.h[o]/2,u=a+.5*(h-a);return this.__segDist(t,i,a,l,u,l)<=4||this.__segDist(t,i,u,l,u,c)<=4||this.__segDist(t,i,u,c,h,c)<=4}__segDist(e,t,i,n,r,s){const o=r-i,a=s-n,l=o*o+a*a;let h=l?((e-i)*o+(t-n)*a)/l:0;h=Math.max(0,Math.min(1,h));const c=i+h*o,u=n+h*a;return Math.hypot(e-c,t-u)}paint(e,t){return this.drawCalls=0,this.lastView=t,this.forEachInBox(t.x0,t.y0,t.x1,t.y1,t=>{const i=this.type[t];if(1!==i&&!this.__degenerate(t)&&!this.done[t])if(0===i){const i=this.sprites[this.kind[t]];i&&(e.drawImage(i.canvas,this.x[t]-i.ox,this.y[t]-i.oy,i.w,i.h),this.drawCalls++)}else this.__strokePipe(e,t),this.drawCalls++}),this.syncLabelsOnPaint&&this.syncLabels(t),!0}attachLayer(e){this.layer=e;for(const t of x(e)){if(0!==this.type[t])continue;const i=S(e,t);i&&this.liveComponents.set(t,i)}}syncLabels(){(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.lastView)&&this.layer&&C(this.layer,{pad:this.labelSyncPad,budget:128,needs:e=>0===this.type[e],map:e=>this.labelIndexOfSymbol(e)})}applyPatch(e,t){if(!(e>=0)||e>=this.count)return!1;let i=!1;if("number"==typeof t.left&&(this.x[e]=t.left,i=!0),"number"==typeof t.top&&(this.y[e]=t.top,i=!0),0===this.type[e]){const t=this.labelIndexOfSymbol(e);t>=0&&(this.x[t]=this.x[e],this.y[t]=this.y[e]+this.h[e])}return i&&this.rebuildIndex(),this.version++,this.recordEdit(e,this.x[e],this.y[e]),!0}onChildPatched(e,t){this.applyPatch(e,t)}labelIndexOfSymbol(e){const t=this.symbolCount+e;return t<this.count&&1===this.type[t]?t:-1}__strokePipe(e,t){const i=this.pipeFrom[t],n=this.pipeTo[t],r=En[Kn[this.pipeMedium[t]]],s=this.x[i]+this.w[i]/2,o=this.y[i]+this.h[i]/2,a=this.x[n]+this.w[n]/2,l=this.y[n]+this.h[n]/2,h=s+.5*(a-s);e.save(),e.strokeStyle=r.color,e.lineWidth=1.4,e.setLineDash("dashed"===r.lineType?[5,5]:"dashdot"===r.lineType?[9,4,2,4]:[]),e.beginPath(),e.moveTo(s,o),e.lineTo(h,o),e.lineTo(h,l),e.lineTo(a,l),e.stroke(),e.restore()}drawCalls=0;materialize(e){this.done[e]=1;const t=this.type[e];if(0===t){const t=new WaterSymbol({kind:Gn[this.kind[e]],id:`vs-${e}`,left:this.x[e],top:this.y[e],name:this.nameOf(e),tag:this.tagOf(e)});return this.liveComponents.set(e,t),t}if(1===t){const t=this.labelOf[e];return new c({left:this.x[e],top:this.y[e],width:90,text:`${this.tagOf(t)} ${this.nameOf(t)}`,style:{fontSize:Bn,fillStyle:Fn}})}const i=new WaterPipe({id:`vp-${e}`,medium:Kn[this.pipeMedium[e]],dn:`DN${this.pipeDn[e]}`});return i.setState({left:0,top:0}),i}windowItems(e,t){const i=this.labelSyncPad;this.forEachInBox(e.x0-i,e.y0-i,e.x1+i,e.y1+i,t)}pipeBox(e,t){const i=this.pipeFrom[e],n=this.pipeTo[e],r=this.x[i]+this.w[i]/2,s=this.y[i]+this.h[i]/2,o=this.x[n]+this.w[n]/2,a=this.y[n]+this.h[n]/2,l=r+.5*(o-r);return t[0]=Math.min(r,l,o),t[1]=Math.min(s,a),t[2]=Math.max(r,l,o),t[3]=Math.max(s,a),t}get bytes(){return this.type.byteLength+this.x.byteLength+this.y.byteLength+this.w.byteLength+this.h.byteLength+this.kind.byteLength+this.labelOf.byteLength+this.pipeFrom.byteLength+this.pipeTo.byteLength+this.pipeMedium.byteLength+this.pipeDn.byteLength+this.done.byteLength+this.head.byteLength+this.nodePrim.byteLength+this.nodeNext.byteLength+this.windowSeen.byteLength}serializeDocument(){return this.syncEditsFromComponents(),{v:1,params:{symbols:this.symbolCount,cols:this.cols,worldW:this.worldW,worldH:this.worldH,pipes:this.count>2*this.symbolCount},edits:this.edits.map(e=>{let[t,i,n]=e;return[t,Math.round(100*i)/100,Math.round(100*n)/100]})}}edits=[];liveComponents=(()=>new Map)();syncEditsFromComponents(){for(const[e,t]of this.liveComponents){const i=t.state.left,n=t.state.top;(Math.abs(i-this.x[e])>.01||Math.abs(n-this.y[e])>.01)&&(this.x[e]=i,this.y[e]=n,this.recordEdit(e,i,n))}}recordEdit(e,t,i){for(let n=0;n<this.edits.length;n++)if(this.edits[n][0]===e)return void(this.edits[n]=[e,t,i]);this.edits.push([e,t,i])}static fromPayload(e,t){const i=e&&e.params||{},n=new WaterVirtualDoc(t,{symbols:i.symbols,cols:i.cols,worldW:i.worldW,worldH:i.worldH,pipes:!1!==i.pipes}),r=e&&e.edits||[];for(const e of r){const t=Number(e[0]);if(!(t>=0)||t>=n.symbolCount)continue;n.x[t]=Number(e[1]),n.y[t]=Number(e[2]);const i=n.symbolCount+t;n.x[i]=n.x[t],n.y[i]=n.y[t]+n.h[t],n.recordEdit(t,n.x[t],n.y[t])}return n.rebuildIndex(),n}documentBounds(e){return e[0]=0,e[1]=0,e[2]=this.worldW,e[3]=this.worldH,!0}paintToSvg(e){for(let t=0;t<Gn.length;t++){const i=`${Un}-${Gn[t]}`;this.svgDefs[t]||(this.svgDefs[t]=this.__svgFragmentOfKind(Gn[t])),this.svgDefs[t]&&e.define(i,this.svgDefs[t])}for(let t=0;t<this.symbolCount;t++){if(this.done[t])continue;const i=`${Un}-${Gn[this.kind[t]]}`;e.use(i,this.x[t],this.y[t])}for(let t=2*this.symbolCount;t<this.count;t++){if(2!==this.type[t]||this.pipeFrom[t]===this.pipeTo[t])continue;const i=this.pipeFrom[t],n=this.pipeTo[t],r=this.x[i]+this.w[i]/2,s=this.y[i]+this.h[i]/2,o=this.x[n]+this.w[n]/2,a=this.y[n]+this.h[n]/2,l=r+.5*(o-r),h=En[Kn[this.pipeMedium[t]]],c="dashed"===h.lineType?' stroke-dasharray="5 5"':"dashdot"===h.lineType?' stroke-dasharray="9 4 2 4"':"";e.raw(`<polyline points="${r},${s} ${l},${s} ${l},${a} ${o},${a}" fill="none" stroke="${h.color}" stroke-width="1.4"${c}/>`)}for(let t=0;t<this.symbolCount;t++){const i=this.symbolCount+t;if(this.done[i])continue;const n=`${this.tagOf(t)} ${this.nameOf(t)}`;e.raw(`<text x="${this.x[t]}" y="${this.y[i]+Bn}" font-size="${Bn}" fill="${Fn}">${escapeXml(n)}</text>`)}return!0}__svgFragmentOfKind(e){const t=new WaterSymbol({kind:e,left:0,top:0,name:"",tag:""});this.ice.addChild(t);try{const e=v([t],{area:"content"});return e.replace(/^<svg[^>]*>/,"").replace(/<\/svg>$/,"").replace(/<defs>[\s\S]*?<\/defs>/,"")||null}finally{this.ice.removeChild(t)}}__mintSprites(){for(let e=0;e<Gn.length;e++){const t=Gn[e],i=jn[t],n=new WaterSymbol({kind:t,left:0,top:0,name:"",tag:""});this.ice.addChild(n),n.refreshParams(),n.composeMatrix();const r=n.getMinBoundingBox().getMinAndMaxPoint(),s=2,o=Math.floor(2*r.minX)-s,a=Math.floor(2*r.minY)-s,l=Math.max(1,Math.ceil(2*r.maxX)-o+s),h=Math.max(1,Math.ceil(2*r.maxY)-a+s),c=document.createElement("canvas");c.width=l,c.height=h;const u=c.getContext("2d");n.renderTo(u,[2,0,0,2,-o,-a]),this.ice.removeChild(n),this.sprites[e]={canvas:c,w:i.width,h:i.height,ox:(0-o)/2,oy:(0-a)/2}}}}function escapeXml(e){return String(e).replace(/[&<>"]/g,e=>"&"===e?"&":"<"===e?"<":">"===e?">":""")}function createDesignerSession(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=new T;i.init(e,{renderMode:"full"===t.renderMode?"full":"dirty-rect"});const n=new EntityDesigner(i),r=t.onChange?n.subscribe(t.onChange):null;t.initialProject&&n.loadProject(t.initialProject);let s=!1;return{ice:i,designer:n,destroy(){s||(s=!0,r&&r(),n.dispose(),i.destroy())}}}function shouldApplyControlledValue(e,t){return void 0!==e&&e!==t}function createFlowSession(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=new T;i.init(e,{renderMode:"full"===t.renderMode?"full":"dirty-rect"});const n=new FlowDesigner(i),r=t.onChange,s=r?n.subscribe(e=>r(e)):null;t.initialFlow&&n.load(t.initialFlow);let o=!1;return{ice:i,designer:n,destroy(){o||(o=!0,s&&s(),n.dispose(),i.destroy())}}}function reportLoadError(e,t,i,n){const r=n instanceof Error?n:new Error(String(n));e&&e({phase:t,snapshot:i,error:r})}function createHandle$1(e){const t=e?e.designer:null;return{ice:e?e.ice:null,designer:t,addEntity:e=>t?t.createEntity(e):null,connect:e=>t?t.createRelation(e):null,updateEntity:(e,i)=>t?t.updateEntity(e,i):null,updateRelation:(e,i)=>t?t.updateRelation(e,i):null,remove:e=>{t&&t.removeComponent(e)},loadProject:e=>t?t.loadProject(e):{loaded:!1,entities:0,relations:0,unknownTypes:[],skipped:[]},undo:()=>{t&&t.undo()},redo:()=>{t&&t.redo()},toSchemaObject:()=>t?t.toSchemaObject():[],toSchemaString:()=>t?t.toSchemaString():"[]",validate:()=>t?t.validate():[],serializeProject:()=>t?t.serializeProject():""}}k(Un,(e,t)=>t&&t.ice?WaterVirtualDoc.fromPayload(e,t.ice):null);const Xn=n(function EntityDesignerCanvas(e,i){const n=r(null),h=r(null),[c,u]=s(null),d=r(e.onChange);d.current=e.onChange;const p=r(e.onReady);p.current=e.onReady;const y=r(e.onError);y.current=e.onError;const f=r(null),g=e.width||1200,m=e.height||800,_=void 0!==e.value?e.value:e.defaultValue;return o(()=>{const t=n.current;if(!t)return;const i=createDesignerSession(t,{renderMode:e.renderMode,onChange:e=>{f.current=e;const t=d.current,i=h.current;t&&i&&t({snapshot:e,schema:i.designer.toSchemaObject()})}});if(h.current=i,void 0!==_){f.current=_;try{i.designer.loadProject(_)}catch(e){reportLoadError(y.current,"load-initial",_,e)}}else f.current=null;return u(i.designer),p.current&&p.current(createHandle$1(i)),()=>{i.destroy(),h.current=null,u(null)}},[]),o(()=>{if(!c)return;if(!shouldApplyControlledValue(e.value,f.current))return;const t=e.value;f.current=t;try{c.loadProject(t)}catch(e){reportLoadError(y.current,"load-controlled",t,e)}},[e.value,c]),a(i,()=>createHandle$1(h.current),[c]),t(l,null,t("div",{className:e.className,style:{position:"relative",width:g,height:m,...e.style||{}}},t("canvas",{ref:n,width:g,height:m,style:{display:"block"}})),t(EntityDesignerProvider,{designer:c,children:e.children}))}),Yn='{"version":1,"kind":"flowchart","nodes":[],"edges":[]}';function createHandle(e){const t=e?e.designer:null;return{ice:e?e.ice:null,designer:t,addNode:(e,i)=>t?t.createNode(e,i):null,connect:e=>t?t.createEdge(e):null,updateNode:(e,i)=>t?t.updateNode(e,i):null,updateEdge:(e,i)=>t?t.updateEdge(e,i):null,remove:e=>{t&&t.remove(e)},load:e=>t?t.load(e):{loaded:!1,nodes:0,edges:0,skipped:[]},undo:()=>{t&&t.undo()},redo:()=>{t&&t.redo()},serialize:()=>t?t.serialize():Yn,toSnapshot:()=>t?t.toSnapshot():JSON.parse(Yn),fitViewport:e=>{t&&t.fitViewport(e)}}}const Jn=n(function FlowDesignerCanvas(e,i){const n=r(null),h=r(null),[c,u]=s(null),d=r(e.onChange);d.current=e.onChange;const p=r(e.onReady);p.current=e.onReady;const y=r(e.onError);y.current=e.onError;const f=r(null),g=e.width||1200,m=e.height||800,_=void 0!==e.value?e.value:e.defaultValue;return o(()=>{const t=n.current;if(!t)return;const i=createFlowSession(t,{renderMode:e.renderMode,onChange:e=>{f.current=e;const t=d.current,i=h.current;t&&i&&t({snapshot:e,counts:{nodes:i.designer.nodes.length,edges:i.designer.edges.length}})}});if(h.current=i,void 0!==_){f.current=_;try{i.designer.load(_)}catch(e){reportLoadError(y.current,"load-initial",_,e)}}else f.current=null;return u(i.designer),p.current&&p.current(createHandle(i)),()=>{i.destroy(),h.current=null,u(null)}},[]),o(()=>{if(!c)return;if(!shouldApplyControlledValue(e.value,f.current))return;const t=e.value;f.current=t;try{c.load(t)}catch(e){reportLoadError(y.current,"load-controlled",t,e)}},[e.value,c]),a(i,()=>createHandle(h.current),[c]),t(l,null,t("div",{className:e.className,style:{position:"relative",width:g,height:m,...e.style||{}}},t("canvas",{ref:n,width:g,height:m,style:{display:"block"}})),t(FlowDesignerProvider,{designer:c,children:e.children}))});export{Entity,Xn as EntityDesignerCanvas,M as EntityDesignerContext,EntityDesignerProvider,Mn as FLOW_NODE_KINDS,FlowDesigner,Jn as FlowDesignerCanvas,I as FlowDesignerContext,FlowDesignerProvider,FlowEdge,FlowNode,Relation,createDesignerSession,createFlowSession,shouldApplyControlledValue,toSchemaObject,toSchemaString,useEntityDesigner,useFlowDesigner,validateSchema};
|
|
25
|
+
import{createContext as e,createElement as t,useContext as i,forwardRef as n,useRef as r,useState as s,useEffect as o,useImperativeHandle as a,Fragment as l}from"react";import{ICEGroup as h,ICEText as c,ICERect as u,ICEPolyLine as d,ICEVisioLink as p,toIsoTime as y,ICEPath as f,ICE_EVENT_NAME_CONSTS as g,DEFAULT_THEME as m,Serializer as _,Deserializer as b,exportSvg as v,ICECircle as w,registerVirtualSource as k,materializedIndices as x,materializedChild as S,syncVirtualWindow as C,renderSubtreeTo as T,ICE as M}from"ice-render";const I=e(null);function EntityDesignerProvider(e){return t(I.Provider,{value:e.designer},e.children)}function useEntityDesigner(){return i(I)}const P=e(null);function FlowDesignerProvider(e){return t(P.Provider,{value:e.designer},e.children)}function useFlowDesigner(){return i(P)}var q,E,j="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 $,O,D,A,N,B,F,z,L,H,R,W,V,U,G,K,X,Y,J,Q,Z,ee,te,ie,ne,re,se,oe,ae,le,he,ce,ue,de,pe,ye,fe,ge,me,_e,be,ve,we,ke,xe,Se,Ce,Te,Me,Ie,Pe,qe,Ee,je,$e,Oe,De,Ae,Ne,Be,Fe,ze,Le,He,Re,We,Ve,Ue,Ge,Ke,Xe,Ye,Je,Qe,Ze,et,tt,it,nt,rt,st,ot,at,lt,ht,ct,ut,dt,pt,yt,ft,gt,mt,_t,bt,vt,wt,kt,xt=getDefaultExportFromCjs(function requireIsNil(){return E?q:(E=1,q=function isNil(e){return null==e})}());function requireEq(){if(A)return D;return A=1,D=function eq(e,t){return e===t||e!=e&&t!=t}}function require_assocIndexOf(){if(B)return N;B=1;var e=requireEq();return N=function assocIndexOf(t,i){for(var n=t.length;n--;)if(e(t[n][0],i))return n;return-1}}function require_ListCache(){if(K)return G;K=1;var e=function require_listCacheClear(){return O?$:(O=1,$=function listCacheClear(){this.__data__=[],this.size=0})}(),t=function require_listCacheDelete(){if(z)return F;z=1;var e=require_assocIndexOf(),t=Array.prototype.splice;return F=function listCacheDelete(i){var n=this.__data__,r=e(n,i);return!(r<0||(r==n.length-1?n.pop():t.call(n,r,1),--this.size,0))}}(),i=function require_listCacheGet(){if(H)return L;H=1;var e=require_assocIndexOf();return L=function listCacheGet(t){var i=this.__data__,n=e(i,t);return n<0?void 0:i[n][1]}}(),n=function require_listCacheHas(){if(W)return R;W=1;var e=require_assocIndexOf();return R=function listCacheHas(t){return e(this.__data__,t)>-1}}(),r=function require_listCacheSet(){if(U)return V;U=1;var e=require_assocIndexOf();return V=function listCacheSet(t,i){var n=this.__data__,r=e(n,t);return r<0?(++this.size,n.push([t,i])):n[r][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=r,G=ListCache}function require_freeGlobal(){if(re)return ne;re=1;var e="object"==typeof j&&j&&j.Object===Object&&j;return ne=e}function require_root(){if(oe)return se;oe=1;var e=require_freeGlobal(),t="object"==typeof self&&self&&self.Object===Object&&self,i=e||t||Function("return this")();return se=i}function require_Symbol(){if(le)return ae;le=1;var e=require_root().Symbol;return ae=e}function require_baseGetTag(){if(ye)return pe;ye=1;var e=require_Symbol(),t=function require_getRawTag(){if(ce)return he;ce=1;var e=require_Symbol(),t=Object.prototype,i=t.hasOwnProperty,n=t.toString,r=e?e.toStringTag:void 0;return he=function getRawTag(e){var t=i.call(e,r),s=e[r];try{e[r]=void 0;var o=!0}catch(e){}var a=n.call(e);return o&&(t?e[r]=s:delete e[r]),a}}(),i=function require_objectToString(){if(de)return ue;de=1;var e=Object.prototype.toString;return ue=function objectToString(t){return e.call(t)}}(),n=e?e.toStringTag:void 0;return pe=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(ge)return fe;return ge=1,fe=function isObject(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}}function requireIsFunction(){if(_e)return me;_e=1;var e=require_baseGetTag(),t=requireIsObject();return me=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(ke)return we;ke=1;var e,t=function require_coreJsData(){if(ve)return be;ve=1;var e=require_root()["__core-js_shared__"];return be=e}(),i=(e=/[^.]+$/.exec(t&&t.keys&&t.keys.IE_PROTO||""))?"Symbol(src)_1."+e:"";return we=function isMasked(e){return!!i&&i in e}}function require_baseIsNative(){if(Te)return Ce;Te=1;var e=requireIsFunction(),t=require_isMasked(),i=requireIsObject(),n=function require_toSource(){if(Se)return xe;Se=1;var e=Function.prototype.toString;return xe=function toSource(t){if(null!=t){try{return e.call(t)}catch(e){}try{return t+""}catch(e){}}return""}}(),r=/^\[object .+?Constructor\]$/,s=Function.prototype,o=Object.prototype,a=s.toString,l=o.hasOwnProperty,h=RegExp("^"+a.call(l).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");return Ce=function baseIsNative(s){return!(!i(s)||t(s))&&(e(s)?h:r).test(n(s))}}function require_getNative(){if(qe)return Pe;qe=1;var e=require_baseIsNative(),t=function require_getValue(){return Ie?Me:(Ie=1,Me=function getValue(e,t){return null==e?void 0:e[t]})}();return Pe=function getNative(i,n){var r=t(i,n);return e(r)?r:void 0}}function require_Map(){if(je)return Ee;je=1;var e=require_getNative()(require_root(),"Map");return Ee=e}function require_nativeCreate(){if(Oe)return $e;Oe=1;var e=require_getNative()(Object,"create");return $e=e}function require_Hash(){if(Ue)return Ve;Ue=1;var e=function require_hashClear(){if(Ae)return De;Ae=1;var e=require_nativeCreate();return De=function hashClear(){this.__data__=e?e(null):{},this.size=0}}(),t=function require_hashDelete(){return Be?Ne:(Be=1,Ne=function hashDelete(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t})}(),i=function require_hashGet(){if(ze)return Fe;ze=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return Fe=function hashGet(i){var n=this.__data__;if(e){var r=n[i];return"__lodash_hash_undefined__"===r?void 0:r}return t.call(n,i)?n[i]:void 0}}(),n=function require_hashHas(){if(He)return Le;He=1;var e=require_nativeCreate(),t=Object.prototype.hasOwnProperty;return Le=function hashHas(i){var n=this.__data__;return e?void 0!==n[i]:t.call(n,i)}}(),r=function require_hashSet(){if(We)return Re;We=1;var e=require_nativeCreate();return Re=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=r,Ve=Hash}function require_getMapData(){if(Qe)return Je;Qe=1;var e=function require_isKeyable(){return Ye?Xe:(Ye=1,Xe=function isKeyable(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e})}();return Je=function getMapData(t,i){var n=t.__data__;return e(i)?n["string"==typeof i?"string":"hash"]:n.map}}function require_MapCache(){if(lt)return at;lt=1;var e=function require_mapCacheClear(){if(Ke)return Ge;Ke=1;var e=require_Hash(),t=require_ListCache(),i=require_Map();return Ge=function mapCacheClear(){this.size=0,this.__data__={hash:new e,map:new(i||t),string:new e}}}(),t=function require_mapCacheDelete(){if(et)return Ze;et=1;var e=require_getMapData();return Ze=function mapCacheDelete(t){var i=e(this,t).delete(t);return this.size-=i?1:0,i}}(),i=function require_mapCacheGet(){if(it)return tt;it=1;var e=require_getMapData();return tt=function mapCacheGet(t){return e(this,t).get(t)}}(),n=function require_mapCacheHas(){if(rt)return nt;rt=1;var e=require_getMapData();return nt=function mapCacheHas(t){return e(this,t).has(t)}}(),r=function require_mapCacheSet(){if(ot)return st;ot=1;var e=require_getMapData();return st=function mapCacheSet(t,i){var n=e(this,t),r=n.size;return n.set(t,i),this.size+=n.size==r?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=r,at=MapCache}function require_Stack(){if(dt)return ut;dt=1;var e=require_ListCache(),t=function require_stackClear(){if(Y)return X;Y=1;var e=require_ListCache();return X=function stackClear(){this.__data__=new e,this.size=0}}(),i=function require_stackDelete(){return Q?J:(Q=1,J=function stackDelete(e){var t=this.__data__,i=t.delete(e);return this.size=t.size,i})}(),n=function require_stackGet(){return ee?Z:(ee=1,Z=function stackGet(e){return this.__data__.get(e)})}(),r=function require_stackHas(){return ie?te:(ie=1,te=function stackHas(e){return this.__data__.has(e)})}(),s=function require_stackSet(){if(ct)return ht;ct=1;var e=require_ListCache(),t=require_Map(),i=require_MapCache();return ht=function stackSet(n,r){var s=this.__data__;if(s instanceof e){var o=s.__data__;if(!t||o.length<199)return o.push([n,r]),this.size=++s.size,this;s=this.__data__=new i(o)}return s.set(n,r),this.size=s.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=r,Stack.prototype.set=s,ut=Stack}function require_defineProperty(){if(yt)return pt;yt=1;var e=require_getNative(),t=function(){try{var t=e(Object,"defineProperty");return t({},"",{}),t}catch(e){}}();return pt=t}function require_baseAssignValue(){if(gt)return ft;gt=1;var e=require_defineProperty();return ft=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(_t)return mt;_t=1;var e=require_baseAssignValue(),t=requireEq();return mt=function assignMergeValue(i,n,r){(void 0!==r&&!t(i[n],r)||void 0===r&&!(n in i))&&e(i,n,r)}}function require_baseFor(){if(kt)return wt;kt=1;var e=function require_createBaseFor(){return vt?bt:(vt=1,bt=function createBaseFor(e){return function(t,i,n){for(var r=-1,s=Object(t),o=n(t),a=o.length;a--;){var l=o[e?a:++r];if(!1===i(s[l],l,s))break}return t}})}()();return wt=e}var St,Ct,Tt,Mt,It,Pt,qt,Et,jt,$t,Ot,Dt,At,Nt,Bt,Ft,zt,Lt,Ht,Rt,Wt,Vt,Ut,Gt,Kt,Xt,Yt,Jt,Qt,Zt,ei,ti,ii,ni={exports:{}};function require_cloneArrayBuffer(){if(It)return Mt;It=1;var e=function require_Uint8Array(){if(Tt)return Ct;Tt=1;var e=require_root().Uint8Array;return Ct=e}();return Mt=function cloneArrayBuffer(t){var i=new t.constructor(t.byteLength);return new e(i).set(new e(t)),i}}function require_getPrototype(){if(Bt)return Nt;Bt=1;var e=function require_overArg(){return At?Dt:(At=1,Dt=function overArg(e,t){return function(i){return e(t(i))}})}()(Object.getPrototypeOf,Object);return Nt=e}function require_isPrototype(){if(zt)return Ft;zt=1;var e=Object.prototype;return Ft=function isPrototype(t){var i=t&&t.constructor;return t===("function"==typeof i&&i.prototype||e)}}function require_initCloneObject(){if(Ht)return Lt;Ht=1;var e=function require_baseCreate(){if(Ot)return $t;Ot=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 $t=i}(),t=require_getPrototype(),i=require_isPrototype();return Lt=function initCloneObject(n){return"function"!=typeof n.constructor||i(n)?{}:e(t(n))}}function requireIsObjectLike(){if(Wt)return Rt;return Wt=1,Rt=function isObjectLike(e){return null!=e&&"object"==typeof e}}function requireIsArguments(){if(Kt)return Gt;Kt=1;var e=function require_baseIsArguments(){if(Ut)return Vt;Ut=1;var e=require_baseGetTag(),t=requireIsObjectLike();return Vt=function baseIsArguments(i){return t(i)&&"[object Arguments]"==e(i)}}(),t=requireIsObjectLike(),i=Object.prototype,n=i.hasOwnProperty,r=i.propertyIsEnumerable,s=e(function(){return arguments}())?e:function(e){return t(e)&&n.call(e,"callee")&&!r.call(e,"callee")};return Gt=s}function requireIsArray(){if(Yt)return Xt;Yt=1;var e=Array.isArray;return Xt=e}function requireIsLength(){if(Qt)return Jt;Qt=1;return Jt=function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}}function requireIsArrayLike(){if(ei)return Zt;ei=1;var e=requireIsFunction(),t=requireIsLength();return Zt=function isArrayLike(i){return null!=i&&t(i.length)&&!e(i)}}var ri,si,oi,ai,li,hi,ci,ui,di,pi={exports:{}};function requireIsBuffer(){return oi||(oi=1,function(e,t){var i=require_root(),n=function requireStubFalse(){return si?ri:(si=1,ri=function stubFalse(){return!1})}(),r=t&&!t.nodeType&&t,s=r&&e&&!e.nodeType&&e,o=s&&s.exports===r?i.Buffer:void 0,a=(o?o.isBuffer:void 0)||n;e.exports=a}(pi,pi.exports)),pi.exports}var yi,fi,gi,mi,_i,bi,vi,wi,ki,xi,Si,Ci,Ti,Mi,Ii,Pi,qi,Ei,ji,$i,Oi,Di,Ai,Ni,Bi,Fi,zi,Li,Hi,Ri,Wi,Vi,Ui,Gi,Ki,Xi,Yi,Ji,Qi,Zi,en,tn,nn,rn,sn,on,an,ln,hn,cn={exports:{}};function requireIsTypedArray(){if(gi)return fi;gi=1;var e=function require_baseIsTypedArray(){if(ci)return hi;ci=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,hi=function baseIsTypedArray(r){return i(r)&&t(r.length)&&!!n[e(r)]}}(),t=function require_baseUnary(){return di?ui:(di=1,ui=function baseUnary(e){return function(t){return e(t)}})}(),i=function require_nodeUtil(){return yi||(yi=1,e=cn,t=cn.exports,i=require_freeGlobal(),n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,s=r&&r.exports===n&&i.process,o=function(){try{return r&&r.require&&r.require("util").types||s&&s.binding&&s.binding("util")}catch(e){}}(),e.exports=o),cn.exports;var e,t,i,n,r,s,o}(),n=i&&i.isTypedArray,r=n?t(n):e;return fi=r}function require_safeGet(){if(_i)return mi;return _i=1,mi=function safeGet(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}}function require_copyObject(){if(ki)return wi;ki=1;var e=function require_assignValue(){if(vi)return bi;vi=1;var e=require_baseAssignValue(),t=requireEq(),i=Object.prototype.hasOwnProperty;return bi=function assignValue(n,r,s){var o=n[r];i.call(n,r)&&t(o,s)&&(void 0!==s||r in n)||e(n,r,s)}}(),t=require_baseAssignValue();return wi=function copyObject(i,n,r,s){var o=!r;r||(r={});for(var a=-1,l=n.length;++a<l;){var h=n[a],c=s?s(r[h],i[h],h,r,i):void 0;void 0===c&&(c=i[h]),o?t(r,h,c):e(r,h,c)}return r}}function require_isIndex(){if(Ti)return Ci;Ti=1;var e=/^(?:0|[1-9]\d*)$/;return Ci=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(Ii)return Mi;Ii=1;var e=function require_baseTimes(){return Si?xi:(Si=1,xi=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(),r=require_isIndex(),s=requireIsTypedArray(),o=Object.prototype.hasOwnProperty;return Mi=function arrayLikeKeys(a,l){var h=i(a),c=!h&&t(a),u=!h&&!c&&n(a),d=!h&&!c&&!u&&s(a),p=h||c||u||d,y=p?e(a.length,String):[],f=y.length;for(var g in a)!l&&!o.call(a,g)||p&&("length"==g||u&&("offset"==g||"parent"==g)||d&&("buffer"==g||"byteLength"==g||"byteOffset"==g)||r(g,f))||y.push(g);return y}}function require_baseKeysIn(){if(ji)return Ei;ji=1;var e=requireIsObject(),t=require_isPrototype(),i=function require_nativeKeysIn(){return qi?Pi:(qi=1,Pi=function nativeKeysIn(e){var t=[];if(null!=e)for(var i in Object(e))t.push(i);return t})}(),n=Object.prototype.hasOwnProperty;return Ei=function baseKeysIn(r){if(!e(r))return i(r);var s=t(r),o=[];for(var a in r)("constructor"!=a||!s&&n.call(r,a))&&o.push(a);return o}}function requireKeysIn(){if(Oi)return $i;Oi=1;var e=require_arrayLikeKeys(),t=require_baseKeysIn(),i=requireIsArrayLike();return $i=function keysIn(n){return i(n)?e(n,!0):t(n)}}function require_baseMergeDeep(){if(Bi)return Ni;Bi=1;var e=require_assignMergeValue(),t=function require_cloneBuffer(){return St||(St=1,e=ni,t=ni.exports,i=require_root(),n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,s=r&&r.exports===n?i.Buffer:void 0,o=s?s.allocUnsafe:void 0,e.exports=function cloneBuffer(e,t){if(t)return e.slice();var i=e.length,n=o?o(i):new e.constructor(i);return e.copy(n),n}),ni.exports;var e,t,i,n,r,s,o}(),i=function require_cloneTypedArray(){if(qt)return Pt;qt=1;var e=require_cloneArrayBuffer();return Pt=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 jt?Et:(jt=1,Et=function copyArray(e,t){var i=-1,n=e.length;for(t||(t=Array(n));++i<n;)t[i]=e[i];return t})}(),r=require_initCloneObject(),s=requireIsArguments(),o=requireIsArray(),a=function requireIsArrayLikeObject(){if(ii)return ti;ii=1;var e=requireIsArrayLike(),t=requireIsObjectLike();return ti=function isArrayLikeObject(i){return t(i)&&e(i)}}(),l=requireIsBuffer(),h=requireIsFunction(),c=requireIsObject(),u=function requireIsPlainObject(){if(li)return ai;li=1;var e=require_baseGetTag(),t=require_getPrototype(),i=requireIsObjectLike(),n=Function.prototype,r=Object.prototype,s=n.toString,o=r.hasOwnProperty,a=s.call(Object);return ai=function isPlainObject(n){if(!i(n)||"[object Object]"!=e(n))return!1;var r=t(n);if(null===r)return!0;var l=o.call(r,"constructor")&&r.constructor;return"function"==typeof l&&l instanceof l&&s.call(l)==a}}(),d=requireIsTypedArray(),p=require_safeGet(),y=function requireToPlainObject(){if(Ai)return Di;Ai=1;var e=require_copyObject(),t=requireKeysIn();return Di=function toPlainObject(i){return e(i,t(i))}}();return Ni=function baseMergeDeep(f,g,m,_,b,v,w){var k=p(f,m),x=p(g,m),S=w.get(x);if(S)e(f,m,S);else{var C=v?v(k,x,m+"",f,g,w):void 0,T=void 0===C;if(T){var M=o(x),I=!M&&l(x),P=!M&&!I&&d(x);C=x,M||I||P?o(k)?C=k:a(k)?C=n(k):I?(T=!1,C=t(x,!0)):P?(T=!1,C=i(x,!0)):C=[]:u(x)||s(x)?(C=k,s(k)?C=y(k):c(k)&&!h(k)||(C=r(x))):T=!1}T&&(w.set(x,C),b(C,x,_,v,w),w.delete(x)),e(f,m,C)}}}function requireIdentity(){if(Hi)return Li;return Hi=1,Li=function identity(e){return e}}function require_overRest(){if(Ui)return Vi;Ui=1;var e=function require_apply(){return Wi?Ri:(Wi=1,Ri=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 Vi=function overRest(i,n,r){return n=t(void 0===n?i.length-1:n,0),function(){for(var s=arguments,o=-1,a=t(s.length-n,0),l=Array(a);++o<a;)l[o]=s[n+o];o=-1;for(var h=Array(n+1);++o<n;)h[o]=s[o];return h[n]=r(l),e(i,this,h)}},Vi}function require_baseSetToString(){if(Yi)return Xi;Yi=1;var e=function requireConstant(){return Ki?Gi:(Ki=1,Gi=function constant(e){return function(){return e}})}(),t=require_defineProperty(),i=requireIdentity();return Xi=t?function(i,n){return t(i,"toString",{configurable:!0,enumerable:!1,value:e(n),writable:!0})}:i}function require_setToString(){if(en)return Zi;en=1;var e=require_baseSetToString(),t=function require_shortOut(){if(Qi)return Ji;Qi=1;var e=Date.now;return Ji=function shortOut(t){var i=0,n=0;return function(){var r=e(),s=16-(r-n);if(n=r,s>0){if(++i>=800)return arguments[0]}else i=0;return t.apply(void 0,arguments)}},Ji}(),i=t(e);return Zi=i}function require_createAssigner(){if(an)return on;an=1;var e=function require_baseRest(){if(nn)return tn;nn=1;var e=requireIdentity(),t=require_overRest(),i=require_setToString();return tn=function baseRest(n,r){return i(t(n,r,e),n+"")}}(),t=function require_isIterateeCall(){if(sn)return rn;sn=1;var e=requireEq(),t=requireIsArrayLike(),i=require_isIndex(),n=requireIsObject();return rn=function isIterateeCall(r,s,o){if(!n(o))return!1;var a=typeof s;return!!("number"==a?t(o)&&i(s,o.length):"string"==a&&s in o)&&e(o[s],r)}}();return on=function createAssigner(i){return e(function(e,n){var r=-1,s=n.length,o=s>1?n[s-1]:void 0,a=s>2?n[2]:void 0;for(o=i.length>3&&"function"==typeof o?(s--,o):void 0,a&&t(n[0],n[1],a)&&(o=s<3?void 0:o,s=1),e=Object(e);++r<s;){var l=n[r];l&&i(e,l,r,o)}return e})}}var un=function requireMerge(){if(hn)return ln;hn=1;var e=function require_baseMerge(){if(zi)return Fi;zi=1;var e=require_Stack(),t=require_assignMergeValue(),i=require_baseFor(),n=require_baseMergeDeep(),r=requireIsObject(),s=requireKeysIn(),o=require_safeGet();return Fi=function baseMerge(a,l,h,c,u){a!==l&&i(l,function(i,s){if(u||(u=new e),r(i))n(a,l,s,h,baseMerge,c,u);else{var d=c?c(o(a,s),i,s+"",a,l,u):void 0;void 0===d&&(d=i),t(a,s,d)}},s)},Fi}(),t=require_createAssigner()(function(t,i,n){e(t,i,n)});return ln=t}(),dn=getDefaultExportFromCjs(un);class Entity extends h{static typeId="ice-entity-designer:Entity";hasDerivedChildren(){return!0}entityFieldsComponent=[];constructor(e){super(Entity.arrangeParam(e)),this.syncEntityNameAndFields()}static arrangeParam(e){const t=dn({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 xt(t.entityName)&&(t.entityName="Entity Name"),xt(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 c({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 u({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 d({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(!xt(this.state.fields)){const e=this.state.fields.length;for(let t=0;t<e;t++){const i=this.state.fields[t],n=this.fieldDisplay(i),r=new c({left:0,top:0,text:n.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(" ")} `:"",r=e.type?`${e.type}${e.length?`(${e.length})`:""}`:"",s=i.length?` ${i.join(" ")}`:"",o=void 0!==e.default?` = ${e.default}`:"",a=e.comment?` // ${e.comment}`:"";return{text:`${n}${e.name}${r?` ${r}`:""}${s}${o}${a}`}}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 r=e,s=Math.max(t,this.state.height);return this.state.width=r,this.state.height=s,{width:r,height:s}}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=!xt(e.fields)||!xt(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 p{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,r]=i[e]||i["one-to-one"];return`${t.sourceCardinality||n} : ${t.targetCardinality||r}`}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:r,nullable:s,onDelete:o,onUpdate:a,joinTableName:l,fromKey:h,toKey:c}=this.state;let u,d,p,y,f,g;this.state.links&&this.state.links.start&&this.state.links.start.id&&(p=this.state.links.start.id,u=this.ice.findComponent(p),y=u.state.entityName),this.state.links&&this.state.links.end&&this.state.links.end.id&&(f=this.state.links.end.id,d=this.ice.findComponent(f),g=d.state.entityName);return{title:e,fromId:p,fromName:y,toId:f,toName:g,relationType:t,referencedColumnName:i,sourceField:n,targetField:r,nullable:!1!==s&&void 0,onDelete:o,onUpdate:a,joinTableName:l,fromKey:h,toKey:c}}}function designerChromeFromTheme(e){const t=e&&e.semantic||{},i=t.primary||"#0D6EFD",n=t.success||"#198754",r=t.warning||"#FFC107";return{selection:{stroke:i,fill:withAlpha(i,.12),lineWidth:1,lineDash:[]},handle:{fill:i,stroke:"#ffffff",activeFill:r,lineWidth:1},linkHook:{fill:n,stroke:"#ffffff",lineWidth:1},slot:{fill:n,stroke:"#ffffff",hoverFill:r,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 pn=["T","R","B","L"],yn={T:[0,-1],R:[1,0],B:[0,1],L:[-1,0]};function boxOf(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(e),r=boxOf(t);if(!n||!r)return{...i};const s=centerOf(n),o=centerOf(r);let a={...i},l=1/0;for(const e of pn){const t=portPoint(n,e),i=yn[e],h=(o[0]-t[0])*i[0]+(o[1]-t[1])*i[1]>=0;for(const n of pn){const o=portPoint(r,n),c=yn[n],u=(h?0:1e6)+((s[0]-o[0])*c[0]+(s[1]-o[1])*c[1]>=0?0:1e6)+((o[0]-t[0])*i[0]+(o[1]-t[1])*i[1]>=0&&(t[0]-o[0])*c[0]+(t[1]-o[1])*c[1]>=0?0:1e6)+Math.hypot(t[0]-o[0],t[1]-o[1]);u<l&&(l=u,a={sourcePort:e,targetPort:n})}}return a}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 fn="data",gn=[{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"}],mn=[{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 r=e[n];void 0!==r&&(r&&"object"==typeof r&&!Array.isArray(r)?(void 0!==r.id&&"string"!=typeof r.id&&i.push(`${t}.${n}.id must be a string when present`),void 0!==r.position&&"string"!=typeof r.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"}],_n=[...[{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"}],...gn],bn=[...mn,...gn];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[fn]:void 0;return void 0!==n&&(i[fn]=n),i}function validateDocumentNode(e,t,i,n){e&&"object"==typeof e&&!Array.isArray(e)?i.forEach(i=>{const r=e[i.key];void 0!==r?!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}}(r,i.type)?n.push(`${t}.${i.key} must be a ${i.type} when present`):i.validate&&i.validate(r,`${t}.${i.key}`,n):i.required&&n.push(`${t}.${i.key} is required`)}):n.push(`${t} must be an object`)}const vn=[{key:"id",type:"string",required:!0},{key:"typeId",type:"string"}];function validateNode(e,t,i,n){if(!e||"object"!=typeof e||Array.isArray(e))return void n.push(`${t} must be an object`);const r=void 0===e.typeId?i:e.typeId;!function isEntityTypeId(e){return e===Entity.typeId}(r)?!function isRelationTypeId(e){return e===Relation.typeId}(r)?validateDocumentNode(e,t,vn,n):validateDocumentNode(e,t,bn,n):validateDocumentNode(e,t,_n,n)}function validateSchema(e){const t=[],i=e.filter(isEntity),n=e.filter(isRelation),r=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});r.has(i)||r.set(i,[]),r.get(i).push(e);const n=e.state.fields||[];0===n.length&&t.push({level:"warning",message:`Entity "${i}" 没有任何字段`,componentId:e.state.id});const s=new Set;n.forEach(n=>{const r=(n.name||"").trim();r?s.has(r)?t.push({level:"error",message:`Entity "${i}" 存在重复字段 "${r}"`,componentId:e.state.id}):s.add(r):t.push({level:"error",message:`Entity "${i}" 存在未命名字段`,componentId:e.state.id}),n.type||t.push({level:"warning",message:`Entity "${i}" 的字段 "${r||"(未命名)"}" 未设置类型`,componentId:e.state.id})})}),r.forEach((e,i)=>{e.length>1&&t.push({level:"error",message:`存在重复的 Entity 名称 "${i}"`})}),n.forEach(e=>{const n=e.state.links||{},r=n.start&&n.start.id,s=n.end&&n.end.id,o=e.state.relationType;if(!r||!s)return void t.push({level:"error",message:"存在没有完整起点/终点的 Relation",componentId:e.state.id});const a=i.some(e=>e.state.id===r),l=i.some(e=>e.state.id===s);a&&l||t.push({level:"error",message:"Relation 连接到了不存在的 Entity",componentId:e.state.id}),o?"many-to-many"!==o||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,r=e.length;n<r;n++){let r=e[n].toLowerCase();(t||0!==n)&&(r=r.substr(0,1).toUpperCase()+r.substr(1)),i+=r}return i}(toWords(e),t)}var wn=[],kn=[],xn={},Sn={},Cn={};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 r=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,r)})}function sanitizeWord(e,t,i){if(!e.length||xn.hasOwnProperty(e))return t;for(var n=i.length;n--;){var r=i[n];if(r[0].test(t))return replace(t,r)}return t}function replaceWord(e,t,i){return function(n){var r=n.toLowerCase();return t.hasOwnProperty(r)?restoreCase(n,r):e.hasOwnProperty(r)?restoreCase(n,e[r]):sanitizeWord(r,n,i)}}function checkWord(e,t,i){return function(n){var r=n.toLowerCase();return!!t.hasOwnProperty(r)||!e.hasOwnProperty(r)&&sanitizeWord(r,r,i)===r}}function pluralize(e,t,i){return(i?t+" ":"")+(1===t?pluralize.singular(e):pluralize.plural(e))}pluralize.plural=replaceWord(Cn,Sn,wn),pluralize.isPlural=checkWord(Cn,Sn,wn),pluralize.singular=replaceWord(Sn,Cn,kn),pluralize.isSingular=checkWord(Sn,Cn,kn),pluralize.addPluralRule=function(e,t){wn.push([sanitizeRule(e),t])},pluralize.addSingularRule=function(e,t){kn.push([sanitizeRule(e),t])},pluralize.addUncountableRule=function(e){"string"!=typeof e?(pluralize.addPluralRule(e,"$0"),pluralize.addSingularRule(e,"$0")):xn[e.toLowerCase()]=!0},pluralize.addIrregularRule=function(e,t){t=t.toLowerCase(),e=e.toLowerCase(),Cn[e]=t,Sn[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 Tn={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"},Mn=["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 Tn[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&&Mn.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 r=t[e];if(isRelation(r))i.push(r);else if(isEntity(r)){const e=r.toEntityObject();e.columns=normalizeColumns(e.columns),n[r.state.id]=e}}for(let e=0;e<i.length;e++){const t=i[e],{fromId:r,fromName:s,toId:o,toName:a,relationType:l,referencedColumnName:h,sourceField:c,targetField:u,nullable:d,onDelete:p,onUpdate:y,joinTableName:f,fromKey:g,toKey:m}=t.toEntityObject(),_=n[r],b=n[o];if(!_||!b)continue;_.relations||(_.relations={}),b.relations||(b.relations={});const v=g||camelCase(a),w=m||camelCase(s),k={};!1===d&&(k.nullable=!1),p&&(k.onDelete=p),y&&(k.onUpdate=y),"one-to-one"===l?(b.relations[w]={type:l,target:s,joinColumn:buildJoinColumn(u||h,c||h),...k},_.relations[v]={type:l,target:a,inverseSide:w}):"one-to-many"===l?(_.relations[v]={type:l,target:a,inverseSide:w},b.relations[w]={type:"many-to-one",target:s,joinColumn:buildJoinColumn(u||h,c||h),...k}):"many-to-one"===l?(_.relations[v]={type:l,target:a,joinColumn:buildJoinColumn(c||h,u||h),...k},b.relations[w]={type:"one-to-many",target:s,inverseSide:v}):"many-to-many"===l&&(_.relations[`${pluralize(v)}`]={type:l,target:a,joinTable:!f||{name:f}},b.relations[`${pluralize(w)}`]={type:l,target:s,inverseSide:`${pluralize(v)}`})}const r=[];for(const e in n)r.push(n[e]);return r}function toSchemaString(e){return JSON.stringify(toSchemaObject(e))}function registerIEDType(e,t){e.registerType(t.typeId,t)}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,r=i?this.ice.findComponent(i):null,s=autoPorts(n,r,{sourcePort:"R",targetPort:"L"}),o=e.links&&e.links.start&&e.links.start.position||e.startPosition||s.sourcePort,a=e.links&&e.links.end&&e.links.end.position||e.endPosition||s.targetPort,l=e.links||{start:{id:t,position:o},end:{id:i,position:a}},h=n?this.__slotPoint(n,o):null,c=r?this.__slotPoint(r,a):null,u=new Relation({relationType:e.relationType||"one-to-many",sourceField:e.sourceField||"id",targetField:e.targetField||"id",links:l,startPoint:h||[0,0],endPoint:c||[10,10],...e});return this.ice.addChild(u),this.select(u.state.id),this.__emitChange(),u}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 r=this.serializeProject(),s=n.map(e=>e.state.zIndex);"front"===t?i.bringToFront():"back"===t?i.sendToBack():"up"===t?i.moveUp():i.moveDown();const o=n.map(e=>e.state.zIndex);return!(s.length===o.length&&!s.some((e,t)=>e!==o[t]))&&(this.__pushHistory(r),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:y(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 i=y(e);if(i)return t&&t.documentMeta&&(t.documentMeta.createTime=i),i;const n=(new Date).toISOString();return t&&t.documentMeta&&(t.documentMeta.createTime=n),n}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},_n)}__slotPoint(e,t){const i=e.getMinBoundingBox(!0),n=i.center[0],r=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],r];case"R":return[i.tr[0],r];default:return[n,r]}}__relationSnapshot(e){return pickDocumentNode({...e.state||{},typeId:Relation.typeId},bn)}__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=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})}(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,r){-1===e.unknownTypes.indexOf(n)&&e.unknownTypes.push(n);const s=r&&"string"==typeof r.id?r.id:void 0;e.skipped.push(void 0===s?{bucket:t,index:i,typeId:n}:{bucket:t,index:i,typeId:n,id:s})}__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 r=this.__resolveTypeId(e,t),s=this.__resolveComponentClass(r);if("function"!=typeof s)return this.__recordUnknownType(i,t,n,r,e),null;const o=new s(e);return delete o.state.typeId,delete o.props.typeId,this.ice.addChild(o),o},collect=(e,t,n)=>{const r=createNode(e,t,n);isEntity(r)?i.entities+=1:isRelation(r)&&(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)}}function createEmptyPath$1(e){const t=e.path2D,i=t&&t.constructor;if(!i)return null;return new i(t.native?new t.native.constructor:null)}function createEmptyPath(e){const t=e.path2D,i=t&&t.constructor;if(!i)return null;return new i(t.native?new t.native.constructor: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 BpmnTaskIcon extends f{static typeId="ice-entity-designer:BpmnTaskIcon";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=i+e/2,o=n+t/2,a=Math.min(e,t)/2,l=this.state.taskType||"none";if("user"===l)r.moveTo(s,o-a),r.arc(s,o-.35*a,.34*a,0,2*Math.PI),r.moveTo(s-.62*a,o+.72*a),r.arc(s,o+.72*a,.62*a,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=s+Math.cos(i)*a*.55,l=o+Math.sin(i)*a*.55,h=s+Math.cos(i)*a,c=o+Math.sin(i)*a;r.moveTo(n,l),r.lineTo(h,c)}r.moveTo(s+.34*a,o),r.arc(s,o,.34*a,0,2*Math.PI)}else"script"===l?(r.moveTo(s-.7*a,o-.85*a),r.lineTo(s+.7*a,o-.85*a),r.lineTo(s+.7*a,o+.5*a),r.moveTo(s-.7*a,o-.85*a),r.lineTo(s-.7*a,o+.5*a),r.moveTo(s-.7*a,o+.6*a),r.lineTo(s-.25*a,o+.85*a),r.lineTo(s+.25*a,o+.6*a),r.lineTo(s+.7*a,o+.85*a)):"send"===l?(r.moveTo(s-.85*a,o-.55*a),r.lineTo(s+.85*a,o-.55*a),r.lineTo(s+.85*a,o+.55*a),r.lineTo(s-.85*a,o+.55*a),r.closePath(),r.moveTo(s-.85*a,o-.55*a),r.lineTo(s,o+.12*a),r.lineTo(s+.85*a,o-.55*a)):"receive"===l?(r.moveTo(s-.85*a,o-.55*a),r.lineTo(s+.85*a,o-.55*a),r.lineTo(s+.85*a,o+.55*a),r.lineTo(s-.85*a,o+.55*a),r.closePath()):"manual"===l&&(r.moveTo(s-.7*a,o+.6*a),r.lineTo(s-.45*a,o-.5*a),r.lineTo(s+.45*a,o-.5*a),r.lineTo(s+.7*a,o+.6*a),r.closePath());return this.path2D=r,this.path2D}}class BpmnSubprocessMarker extends f{static typeId="ice-entity-designer:BpmnSubprocessMarker";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);return r?(r.moveTo(i,n),r.lineTo(i+e,n),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),r.moveTo(i+e/2,n+.22*t),r.lineTo(i+e/2,n+.78*t),r.moveTo(i+.22*e,n+t/2),r.lineTo(i+.78*e,n+t/2),this.path2D=r,this.path2D):this.path2D}}const In={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}},Pn=["bpmnPool","bpmnLane","bpmnAnnotation","bpmnDataObject"],qn={rect:u,diamond:class FlowDiamond extends f{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],r=createEmptyPath$1(this);return r?(r.moveTo(i+e/2,n),r.lineTo(i+e,n+t/2),r.lineTo(i+e/2,n+t),r.lineTo(i,n+t/2),r.closePath(),this.path2D=r,this.path2D):this.path2D}},parallelogram:class FlowParallelogram extends f{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],r=0-this.state.localOrigin[1],s=createEmptyPath$1(this);return s?(s.moveTo(n+i,r),s.lineTo(n+e,r),s.lineTo(n+e-i,r+t),s.lineTo(n,r+t),s.closePath(),this.path2D=s,this.path2D):this.path2D}},event:class BpmnEventShape extends f{static typeId="ice-entity-designer:BpmnEventShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=i+e/2,o=n+t/2,a=Math.min(e,t)/2,l=this.state.eventKind||"start";r.arc(s,o,a,0,2*Math.PI),"intermediate"!==l&&"end"!==l||(r.moveTo(s+.84*a,o),r.arc(s,o,.84*a,0,2*Math.PI));const h=this.state.trigger||"none";if("message"===h){const e=1.1*a,t=.78*a;r.moveTo(s-e/2,o-t/2),r.lineTo(s+e/2,o-t/2),r.lineTo(s+e/2,o+t/2),r.lineTo(s-e/2,o+t/2),r.closePath(),r.moveTo(s-e/2,o-t/2),r.lineTo(s,o+.08*t),r.lineTo(s+e/2,o-t/2)}else if("timer"===h){const e=.52*a;r.moveTo(s+e,o),r.arc(s,o,e,0,2*Math.PI),r.moveTo(s,o),r.lineTo(s,o-.62*e),r.moveTo(s,o),r.lineTo(s+.5*e,o)}else"error"===h?(r.moveTo(s+.34*a,o-.62*a),r.lineTo(s-.42*a,o+.06*a),r.lineTo(s-.02*a,o+.06*a),r.lineTo(s-.3*a,o+.66*a),r.lineTo(s+.44*a,o-.02*a),r.lineTo(s+.04*a,o-.02*a),r.closePath()):"terminate"===h&&(r.moveTo(s+.5*a,o),r.arc(s,o,.5*a,0,2*Math.PI));return this.path2D=r,this.path2D}},gateway:class BpmnGatewayShape extends f{static typeId="ice-entity-designer:BpmnGatewayShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=i+e/2,o=n+t/2,a=e/2,l=t/2;r.moveTo(s,o-l),r.lineTo(s+a,o),r.lineTo(s,o+l),r.lineTo(s-a,o),r.closePath();const h=this.state.gatewayType||"exclusive",c=.42*Math.min(a,l);if("exclusive"===h)r.moveTo(s-c,o-c),r.lineTo(s+c,o+c),r.moveTo(s+c,o-c),r.lineTo(s-c,o+c);else if("parallel"===h)r.moveTo(s-c,o),r.lineTo(s+c,o),r.moveTo(s,o-c),r.lineTo(s,o+c);else if("inclusive"===h)r.moveTo(s+c,o),r.arc(s,o,c,0,2*Math.PI);else if("event"===h){const e=1.15*c;for(let t=0;t<5;t++){const i=-Math.PI/2+t*Math.PI*2/5,n=s+Math.cos(i)*e,a=o+Math.sin(i)*e;0===t?r.moveTo(n,a):r.lineTo(n,a)}r.closePath()}return this.path2D=r,this.path2D}},dataObject:class BpmnDataObjectShape extends f{static typeId="ice-entity-designer:BpmnDataObjectShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=Math.min(14,.22*e,.32*t);return r.moveTo(i,n),r.lineTo(i+e-s,n),r.lineTo(i+e,n+s),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),r.moveTo(i+e-s,n),r.lineTo(i+e-s,n+s),r.lineTo(i+e,n+s),this.path2D=r,this.path2D}},annotation:class BpmnAnnotationShape extends f{static typeId="ice-entity-designer:BpmnAnnotationShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=Math.min(16,.3*e);return r.moveTo(i,n),r.lineTo(i+e,n),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),r.moveTo(i+s,n),r.lineTo(i,n),r.lineTo(i,n+t),r.lineTo(i+s,n+t),this.path2D=r,this.path2D}},lane:class BpmnLaneShape extends f{static typeId="ice-entity-designer:BpmnLaneShape";createPathObject(){const{w:e,h:t,x:i,y:n}=localBox(this),r=createEmptyPath(this);if(!r)return this.path2D;const s=Math.min(this.state.bandSize||30,.4*e,.4*t);return r.moveTo(i,n),r.lineTo(i+e,n),r.lineTo(i+e,n+t),r.lineTo(i,n+t),r.closePath(),"top"===(this.state.band||"left")?(r.moveTo(i,n+s),r.lineTo(i+e,n+s)):(r.moveTo(i+s,n),r.lineTo(i+s,n+t)),this.path2D=r,this.path2D}}},En="#0f172a";class FlowNode extends h{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=In[e.kind]?e.kind:"process",i=In[t];super({kind:t,title:i.label,fillColor:i.fill,strokeColor:i.stroke,textColor:En,fontSize:14,width:i.width,height:i.height,fill:!1,stroke:!1,draggable:!0,interactive:!0,transformable:!1,linkable:-1===Pn.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=In[this.state.kind]||In.process,t=qn[e.shape]||u;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 i="top-left"===e.labelPlacement,n="lane"===e.shape&&"left"===e.band,r=n?Math.min(Number(e.bandSize)||30,.4*this.state.width,.4*this.state.height):0,s=n?Math.max(this.state.height-8,r):0;this.labelComponent=new c(n?{left:r/2-s/2,top:this.state.height/2-r/2,width:s,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||En,textAlign:"center",textBaseline:"middle",fontWeight:"bold"}}:{left:i?10:0,top:i?"top"===e.band?18:16:0,width:i?Math.max(this.state.width-20,20):this.state.width,height:i?18:this.state.height,text:String(this.state.title||""),wrap:!i,maxLines:2,interactive:!1,linkable:!1,stroke:!1,showMinBoundingBox:!1,showMaxBoundingBox:!1,style:{fontSize:this.state.fontSize||(i?13:14),fillStyle:this.state.textColor||En,textAlign:i?"left":"center",textBaseline:"middle",fontWeight:i?"bold":"normal",paddingLeft:i?0:12,paddingRight:i?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,i=void 0!==e.left||void 0!==e.top,n=void 0!==e.width||void 0!==e.height;if(n&&this.trigger(g.BEFORE_RESIZE),i){const t=void 0!==e.left?e.left:this.state.left,i=void 0!==e.top?e.top:this.state.top,n={...e};delete n.left,delete n.top,Object.keys(n).length&&this.setState(n),this.setPosition(t,i)}else this.setState(e);return t?this.__buildShape():this.labelComponent&&this.labelComponent.setState({text:String(this.state.title||"")}),(n||t)&&this.trigger(g.AFTER_RESIZE),this.dirty=!0,this}}class FlowEdge extends p{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,i=e.minX-t,n=e.minY-t,r=Math.max(1,e.maxX-e.minX+2*t),s=Math.max(1,e.maxY-e.minY+2*t);let o=this.boxes.get(e.id);if(!o)return o=new u({left:i,top:n,width:r,height:s,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:i,top:n,width:r,height:s,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||m.semantic.primary}catch{return m.semantic.primary}}}class FlowDesigner{selectedId=null;__undoStack=[];__redoStack=[];__historyEnabled=!0;__maxHistory=100;__maxHistoryBytes=33554432;__historyBytes=0;__batchDepth=0;__batchStart=null;__listeners=[];__mousedownHandler=e=>this.__handleMouseDown(e);__moveSession=!1;__moveEmitQueued=!1;__patchDepth=0;__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=>this.isNodeComponent(e))}get edges(){return this.__flatten().filter(e=>this.isEdgeComponent(e))}isNodeComponent(e){return e instanceof FlowNode}isEdgeComponent(e){return e instanceof FlowEdge}__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(g.BEFORE_MOVE,this.__beforeMoveHandler,this),e.on(g.AFTER_MOVE,this.__afterMoveHandler,this))}__detachNodeListeners(e){e&&"function"==typeof e.off&&(e.off(g.BEFORE_MOVE,this.__beforeMoveHandler,this),e.off(g.AFTER_MOVE,this.__afterMoveHandler,this))}__onBeforeMove(){this.__patchDepth>0||this.__moveSession||(this.__moveSession=!0,this.__captureHistory())}__onAfterMove(){if(this.__patchDepth>0)return;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,r=-1/0;i.forEach(e=>{const t=e.getMinBoundingBox(!0);n=Math.min(n,t.tl[0]),r=Math.max(r,t.br[1])});const s=i.length;return{left:n+s%4*280,top:r+80+Math.floor(s/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"}),r=e.sourcePort||n.sourcePort,s=e.targetPort||n.targetPort,o=new FlowEdge({id:e.id,links:{start:{id:e.sourceId,position:r},end:{id:e.targetId,position:s}},startPoint:this.__slotPoint(t,r),endPoint:this.__slotPoint(i,s),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(o),this.selectedId=o.state.id,this.__emitChange(),o}updateNode(e,t){const i=this.ice.findComponent(e);return i&&this.isNodeComponent(i)&&(this.__captureHistory(),this.__applyPatch(i,t),this.__emitChange()),i}updateEdge(e,t){const i=this.ice.findComponent(e);return i&&this.isEdgeComponent(i)&&(this.__captureHistory(),this.__applyPatch(i,t),this.__emitChange()),i}__applyPatch(e,t){this.__patchDepth++;try{e&&"function"==typeof e.applyPatch?e.applyPatch(t):(e.setState(t),e.dirty=!0)}finally{this.__patchDepth--}}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 _(e)}__deserializer(){const e=this.ice;return e.deserializer||new b(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=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})}(t);if(!n.valid)throw new Error(`Invalid flow snapshot:\n${n.errors.join("\n")}`);this.__captureHistory();const r=i?this.__applyEngineScene(t.scene,t.createTime):this.__clearAndBuild(t);return this.__emitChange(),r}__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,r=e.sourcePort||e.links&&e.links.start&&e.links.start.position||"B",s=e.targetPort||e.links&&e.links.end&&e.links.end.position||"T",o=i&&n?{start:{id:i,position:r},end:{id:n,position:s}}:e.links,a=new FlowEdge({...e,links:o,startPoint:e.startPoint||[0,0],endPoint:e.endPoint||[10,10]});delete a.state.typeId,this.ice.addChild(a),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 r=1/0,s=1/0,o=-1/0,a=-1/0;t.forEach(e=>{const t=e.getMinBoundingBox(!0);r=Math.min(r,t.tl[0]),s=Math.min(s,t.tl[1]),o=Math.max(o,t.br[0]),a=Math.max(a,t.br[1])});const l=Math.max(o-r,1),h=Math.max(a-s,1),c=Math.min((i-2*e)/l,(n-2*e)/h,1.25),u=(i-l*c)/2-r*c,d="start"===this.fitViewportAlign?e-s*c:(n-h*c)/2-s*c;this.ice.setViewport(c,u,d)}__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 v(this.ice,e)}canRedo(){return this.__redoStack.length>0}captureHistory(){this.__captureHistory()}resetHistory(){this.__undoStack.length=0,this.__redoStack.length=0,this.__historyBytes=0,this.__batchStart=null}beginBatch(){0===this.__batchDepth&&this.__historyEnabled&&(this.__batchStart=this.serialize()),this.__batchDepth++}endBatch(){if(0!==this.__batchDepth&&(this.__batchDepth--,0===this.__batchDepth)){const e=this.__batchStart;this.__batchStart=null,null!==e&&this.__historyEnabled&&this.__pushHistory(e)}}setHistoryBudget(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Number(e.maxEntries)>0&&(this.__maxHistory=Math.floor(Number(e.maxEntries))),Number(e.maxBytes)>0&&(this.__maxHistoryBytes=Math.floor(Number(e.maxBytes))),this.__recountHistory()}getHistoryStats(){return{undo:this.__undoStack.length,redo:this.__redoStack.length,bytes:this.__historyBytes}}__captureHistory(){this.__historyEnabled&&(this.__batchDepth>0||this.__pushHistory(this.serialize()))}__pushHistory(e){for(this.__undoStack.push(e),this.__redoStack.length=0,this.__recountHistory();this.__undoStack.length>0&&(this.__undoStack.length>this.__maxHistory||this.__historyBytes>this.__maxHistoryBytes)&&1!==this.__undoStack.length;)this.__undoStack.shift(),this.__recountHistory()}__recountHistory(){let e=0;for(const t of this.__undoStack)e+=t.length;for(const t of this.__redoStack)e+=t.length;this.__historyBytes=e}__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.__recountHistory(),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.__recountHistory(),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;){if(this.isSelectableComponent(i))return void this.select(i.state.id);i=i.parentNode}}isSelectableComponent(e){return e instanceof FlowNode||e instanceof FlowEdge}dispose(){this.ice.evtBus.off("mousedown",this.__mousedownHandler,this),this.ice.evtBus.off("mouseup",this.__mouseupHandler,this),this.nodes.forEach(e=>this.__detachNodeListeners(e))}}const jn={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"}},$n={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}},On="#1f2937",Dn=1.4,An=1,Nn="#eff6ff",Bn="#fef3c7",Fn=9.5,zn="#64748b",Ln=12,Hn="#1e293b",Rn=14,Wn="#ffffff",Vn="#94a3b8",Un=["sludgeThickener","dewateringMachine","sludgeSilo","screwPump","sludgeOut"];class WaterSymbol extends h{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=$n[t]||$n.pump;return dn({kind:t,tag:i.tag,name:"",fill:!1,stroke:!1,width:i.width,height:i.height,style:{strokeStyle:On,lineWidth:Dn},tagStyle:{fontSize:Fn,textColor:zn},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=$n[e]||$n.pump,i=this.state.width||t.width,n=this.state.height||t.height,r=this.state.style&&this.state.style.strokeStyle||On,s=this.state.idle?Vn:r,o=this.state.style&&this.state.style.lineWidth||Dn,a=-1!==Un.indexOf(e)?Bn:Nn,l=i/2,h=n/2,c=Number(this.state.zIndex)||0;switch(this.__originX=l,this.__originY=h,e){case"barScreen":this.__box(0,0,i,n,a,s,o,c);for(let e=1;e<=4;e++){const t=i/5*e-i/2;this.__poly([t,n/2,t+8,-n/2],s,An,c)}break;case"gritChamber":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/2+10,n/2,0,n/2+14,i/2-10,n/2],s,o,c),this.__circle(-i/4,-n/6,4,"none",s,An,c),this.__circle(0,n/8,3,"none",s,An,c),this.__circle(i/5,-n/8,3.5,"none",s,An,c);break;case"primaryClarifier":case"secondaryClarifier":{const t=Math.min(i,n)/2;this.__circle(0,0,t,a,s,o,c),this.__circle(0,0,t/6,"none",s,An,c),this.__poly([-t,0,t,0],s,An,c),"secondaryClarifier"===e&&this.__poly([.6*-t,.6*-t,.6*t,.6*t],s,An,c);break}case"anaerobicTank":case"anoxicTank":this.__box(0,0,i,n,a,s,o,c),this.__poly([0,-n/2,0,n/2-10],s,An,c),this.__poly([-10,n/2-10,10,n/2-10],s,An,c);break;case"aerobicTank":this.__box(0,0,i,n,a,s,o,c);for(let e=0;e<4;e++)this.__circle(-i/4+e*i/6,n/4,3.5,"none",s,An,c);break;case"coagulationTank":this.__box(0,0,i,n,a,s,o,c),this.__poly([0,-n/2,0,n/2-10],s,An,c),this.__poly([-10,n/2-10,10,n/2-10],s,An,c),this.__circle(-i/4,-n/4,3,"none",s,An,c),this.__circle(-i/4,-n/4+9,2,"none",s,An,c);break;case"filterBed":this.__box(0,0,i,n,a,s,o,c);for(let e=0;e<6;e++){const t=-i/2+12+e*(i-24)/5;this.__circle(t,n/6,2.5,"none",s,An,c),this.__circle(t,-n/6,2.5,"none",s,An,c)}break;case"disinfectionTank":this.__box(0,0,i,n,a,s,o,c);for(let e=1;e<=3;e++){const t=-i/2+e*i/4;this.__poly([t,n/2,t,-n/2+6],s,An,c)}break;case"sludgeThickener":{const e=Math.min(i,n)/2;this.__circle(0,0,e,a,s,o,c),this.__circle(0,0,e/5,"none",s,An,c),this.__poly([-e,0,-e/5,0],s,An,c),this.__poly([e/5,0,e,0],s,An,c);break}case"dewateringMachine":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/4,-n/6,i/4,-n/6],s,An,c),this.__poly([-i/4,0,i/4,0],s,An,c),this.__poly([-i/4,n/6,i/4,n/6],s,An,c);break;case"pump":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c),this.__closedPoly([0,.6*-e,.6*e,.5*e,.6*-e,.5*e],s,o,c);break}case"blower":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c);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)],s,An,c)}break}case"dosingUnit":this.__box(0,-8,i,n-20,a,s,o,c),this.__closedPoly([0,n/2-16,8,n/2,-8,n/2],s,An,c),this.__circle(0,n/2-4,2,"none",s,An,c);break;case"valve":this.__closedPoly([-9,-8,-9,8,0,0],s,o,c),this.__closedPoly([9,-8,9,8,0,0],s,o,c),"closed"===this.state.valveState&&this.__poly([0,-10,0,10],"#dc2626",2,c);break;case"flowMeter":this.__circle(0,0,Math.min(i,n)/2,"none",s,o,c),this.__text(l-7,h-.7*Rn,14,"F",Rn,s,"center");break;case"analyzer":this.__circle(0,0,Math.min(i,n)/2,"none",s,o,c),this.__text(l-7,h-.7*Rn,14,"A",Rn,s,"center");break;case"storageTank":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/2+6,n/4,i/2-6,n/4],"#93c5fd",An,c),this.__poly([-i/4,-n/6,-i/8,-n/3,0,-n/6,i/8,-n/3,i/4,-n/6],s,An,c);break;case"deodorizer":this.__box(0,0,i,n,a,s,o,c);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",s,An,c);this.__poly([-i/2,-n/2,-i/2,-n/4],s,o,c);break;case"sludgeSilo":this.__box(0,-n/8,i-20,.6*n,a,s,o,c),this.__poly([-i/2+10,.175*n,0,.42*n,i/2-10,.175*n],s,o,c),this.__poly([0,.42*n,0,n/2-2],s,o,c),this.__poly([-8,-n/8-.3*n,8,-n/8-.3*n],s,An,c);break;case"submersiblePump":{const e=Math.min(i,n)/2-3;this.__circle(0,-2,e,"none",s,o,c);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],s,An,c)}this.__poly([-e,e+1,e,e+1],s,o,c);break}case"screwPump":this.__box(0,-3,i,n-14,a,s,o,c);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],s,An,c)}this.__poly([-i/3,n/2-4,i/3,n/2-4],s,o,c);break;case"vfd":this.__box(0,0,i,n,a,s,o,c),this.__poly([-i/4,4,-i/8,-5,0,4,i/8,-5,i/4,4],s,An,c);break;case"motorValve":this.__closedPoly([-9,8,-9,24,0,16],s,o,c),this.__closedPoly([9,8,9,24,0,16],s,o,c),this.__poly([0,8,0,2],s,An,c),this.__box(0,-6,22,16,"none",s,An,c),"closed"===this.state.valveState&&this.__poly([0,6,0,26],"#dc2626",2,c);break;case"checkValve":this.__box(0,0,i-6,n-14,"none",s,o,c),this.__closedPoly([-5,-6,6,0,-5,6],s,An,c),this.__poly([-i/2+3,0,i/2-3,0],s,An,c);break;case"levelGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c),this.__poly([.62*-e,6,.2*-e,0,.2*e,10,.62*e,4],s,An,c),this.__text(l-5,h-1,12,"L",Fn,s,"center");break}case"pressureGauge":{const e=Math.min(i,n)/2;this.__circle(0,0,e,"none",s,o,c),this.__poly([0,6,.5*e,.45*-e],s,An,c),this.__circle(0,6,2,s,s,An,c),this.__text(l-5,h-1,12,"P",Fn,s,"center");break}case"inlet":this.__box(10,0,i-20,n-12,a,s,o,c),this.__closedPoly([-i/2+2,0,-i/2+18,-8,-i/2+18,8],s,o,c);break;case"outlet":this.__box(-10,0,i-20,n-12,a,s,o,c),this.__closedPoly([i/2-2,0,i/2-18,-8,i/2-18,8],s,o,c);break;case"sludgeOut":this.__box(0,0,i,n,a,s,o,c);for(let e=-1;e<=1;e++)this.__poly([10*e-5,n/4,10*e+5,-n/4],s,An,c);break;default:this.__box(0,0,i,n,a,s,o,c)}const u=Math.max(i+24,90),d=l-u/2;this.state.tag&&this.__text(d,-18,u,String(this.state.tag),Fn,zn,"center");const p=String(this.state.name||"");p&&this.__text(d,n+14,u,p,Ln,Hn,"center")}__box(e,t,i,n,r,s,o,a){return this.__add("box",new u({left:this.__originX+e-i/2,top:this.__originY+t-n/2,width:i,height:n,radius:3,zIndex:a,interactive:!1,linkable:!1,style:{fillStyle:r,strokeStyle:s,lineWidth:o}}))}__circle(e,t,i,n,r,s,o){return this.__add("circle:"+e+","+t,new w({left:this.__originX+e-i,top:this.__originY+t-i,radius:i,zIndex:o,interactive:!1,linkable:!1,style:{fillStyle:"none"===n?Wn:n,strokeStyle:r,lineWidth:s}}))}__closedPoly(e,t,i,n){const r=this.__poly(e,t,i,n),s=e[e.length-2],o=e[e.length-1];return this.__poly([s,o,e[0],e[1]],t,i,n),r}__poly(e,t,i,n){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,s]=r[0],[o,a]=r[1],l=Math.abs(s-a)<.01,h=l?Math.min(e,o):Math.min(e,o)-i/2,c=l?Math.min(s,a)-i/2:Math.min(s,a),d=l?Math.abs(o-e):i,p=l?i:Math.abs(a-s);return this.__add("line:"+n+":"+h+","+c,new u({left:h,top:c,width:d,height:p,zIndex:n,interactive:!1,linkable:!1,style:{fillStyle:t,strokeStyle:t,lineWidth:0}}))}return this.__add("poly:"+n+":"+r.length,new d({points:r,zIndex:n,interactive:!1,linkable:!1,arrow:"none",lineType:"solid",style:{strokeStyle:t,lineWidth:i}}))}__text(e,t,i,n,r,s){let o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"center";const a=Math.round(1.4*r);return this.__add("text:"+n,new c({left:e,top:t,width:i,height:a,text:n,stroke:!1,interactive:!1,linkable:!1,zIndex:(Number(this.state.zIndex)||0)+4,style:{fontSize:r,fillStyle:s,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]:[]}class WaterPipe extends FlowEdge{static typeId="ice-entity-designer:WaterPipe";applyMediumStyle(){const e=this.state.medium||"sewage",t=jn[e]||jn.sewage,i=void 0===this.state.label||""===this.state.label?function composePipeLabel(e,t){const i=jn[e]||jn.sewage,n=String(t||"").trim();return n?`${n} ${i.label}`:i.label}(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 Gn="ied:water-virtual-doc",Kn=Object.keys($n),Xn=Object.keys(jn);class WaterVirtualDoc{documentType=(()=>Gn)();version=1;tagOf(e){const t=$n[Kn[this.kind[e]]],i=String(e%1e5);return`${t.tag}-${"00000".slice(i.length)}${i}`}nameOf(e){return $n[Kn[this.kind[e]]].label}nodeCount=0;sprites=[];svgDefs=[];scratch=(()=>new Float64Array(4))();labelSyncPad=300;layer=null;lastView=null;syncLabelsOnPaint=!0;constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.ice=e;const i=Math.max(1,t.symbols||2e4);this.worldW=t.worldW||12e3,this.worldH=t.worldH||8e3,this.cols=t.cols||Math.max(1,Math.round(Math.sqrt(i*this.worldW/this.worldH))),this.rows=Math.ceil(i/this.cols);const n=!1!==t.pipes;this.symbolCount=i,this.count=i+i+(n?i:0),this.type=new Uint8Array(this.count),this.x=new Float32Array(this.count),this.y=new Float32Array(this.count),this.w=new Float32Array(this.count),this.h=new Float32Array(this.count),this.kind=new Uint8Array(this.count),this.labelOf=new Int32Array(this.count).fill(-1),this.pipeFrom=new Int32Array(this.count),this.pipeTo=new Int32Array(this.count),this.pipeMedium=new Uint8Array(this.count),this.pipeDn=new Uint16Array(this.count),this.done=new Uint8Array(this.count),this.windowSeen=new Int32Array(this.count).fill(-1);const r=this.worldW/this.cols,s=this.worldH/Math.max(1,this.rows);for(let e=0;e<i;e++){const t=e%this.cols,n=e/this.cols|0,o=(7*e+(e/13|0))%Kn.length,a=$n[Kn[o]],l=t*r+29*e%17,h=n*s+43*e%13;this.type[e]=0,this.kind[e]=o,this.x[e]=l,this.y[e]=h,this.w[e]=a.width,this.h[e]=a.height;const c=i+e;this.type[c]=1,this.kind[c]=o,this.labelOf[c]=e,this.x[c]=l,this.y[c]=h+a.height,this.w[c]=90,this.h[c]=14}if(n)for(let e=0;e<i;e++){const t=2*i+e,n=e+this.cols<i?e+this.cols:e;if(this.type[t]=2,this.pipeFrom[t]=e,this.pipeTo[t]=n,this.pipeMedium[t]=e%Xn.length,this.pipeDn[t]=100+e%9*50,n!==e){const e=this.pipeBox(t,this.scratch);this.x[t]=e[0],this.y[t]=e[1],this.w[t]=e[2]-e[0],this.h[t]=e[3]-e[1]}else this.x[t]=this.x[e],this.y[t]=this.y[e],this.w[t]=0,this.h[t]=0}this.cell=128,this.gw=Math.max(1,Math.ceil(this.worldW/this.cell)+1),this.gh=Math.max(1,Math.ceil(this.worldH/this.cell)+1),this.rebuildIndex(),this.__mintSprites()}rebuildIndex(){this.head=new Int32Array(this.gw*this.gh).fill(-1),this.nodePrim=new Int32Array(2*this.count).fill(-1),this.nodeNext=new Int32Array(2*this.count).fill(-1),this.nodeCount=0;for(let e=0;e<this.count;e++){if(1===this.type[e])continue;if(this.__degenerate(e))continue;const t=Math.max(0,Math.min(this.gw-1,this.x[e]/this.cell|0)),i=Math.max(0,Math.min(this.gw-1,(this.x[e]+this.w[e])/this.cell|0)),n=Math.max(0,Math.min(this.gh-1,this.y[e]/this.cell|0)),r=Math.max(0,Math.min(this.gh-1,(this.y[e]+this.h[e])/this.cell|0));for(let s=n;s<=r;s++)for(let n=t;n<=i;n++)this.__addNode(s*this.gw+n,e)}}__addNode(e,t){if(this.nodeCount>=this.nodePrim.length){const e=new Int32Array(2*this.nodeCount).fill(-1);e.set(this.nodePrim),this.nodePrim=e;const t=new Int32Array(2*this.nodeCount).fill(-1);t.set(this.nodeNext),this.nodeNext=t}this.nodePrim[this.nodeCount]=t,this.nodeNext[this.nodeCount]=this.head[e],this.head[e]=this.nodeCount++}boxAt(e,t){t[0]=this.x[e],t[1]=this.y[e],t[2]=this.x[e]+this.w[e],t[3]=this.y[e]+this.h[e]}forEachInBox(e,t,i,n,r){const s=Math.max(0,Math.min(this.gw-1,e/this.cell|0)),o=Math.max(0,Math.min(this.gw-1,i/this.cell|0)),a=Math.max(0,Math.min(this.gh-1,t/this.cell|0)),l=Math.max(0,Math.min(this.gh-1,n/this.cell|0)),h=++this.windowStamp;for(let c=a;c<=l;c++){const a=c*this.gw;for(let l=s;l<=o;l++){let s=this.head[a+l];for(;-1!==s;){const o=this.nodePrim[s];this.windowSeen[o]!==h&&(this.windowSeen[o]=h,this.x[o]+this.w[o]>=e&&this.x[o]<=i&&this.y[o]+this.h[o]>=t&&this.y[o]<=n&&r(o)),s=this.nodeNext[s]}}}}windowStamp=0;__degenerate(e){return 2===this.type[e]&&this.pipeFrom[e]===this.pipeTo[e]}hitTest(e,t){const i=Math.max(0,Math.min(this.gw-1,e/this.cell|0)),n=Math.max(0,Math.min(this.gh-1,t/this.cell|0));let r=this.head[n*this.gw+i];for(;-1!==r;){const i=this.nodePrim[r];if(this.__hitPrecise(i,e,t))return i;r=this.nodeNext[r]}return-1}__hitPrecise(e,t,i){const n=this.x[e],r=this.y[e];if(t<n||i<r||t>n+this.w[e]||i>r+this.h[e])return!1;if(0===this.type[e])return!0;const s=this.pipeFrom[e],o=this.pipeTo[e],a=this.x[s]+this.w[s]/2,l=this.y[s]+this.h[s]/2,h=this.x[o]+this.w[o]/2,c=this.y[o]+this.h[o]/2,u=a+.5*(h-a);return this.__segDist(t,i,a,l,u,l)<=4||this.__segDist(t,i,u,l,u,c)<=4||this.__segDist(t,i,u,c,h,c)<=4}__segDist(e,t,i,n,r,s){const o=r-i,a=s-n,l=o*o+a*a;let h=l?((e-i)*o+(t-n)*a)/l:0;h=Math.max(0,Math.min(1,h));const c=i+h*o,u=n+h*a;return Math.hypot(e-c,t-u)}paint(e,t){return this.drawCalls=0,this.lastView=t,this.forEachInBox(t.x0,t.y0,t.x1,t.y1,t=>{const i=this.type[t];if(1!==i&&!this.__degenerate(t)&&!this.done[t])if(0===i){const i=this.sprites[this.kind[t]];i&&(e.drawImage(i.canvas,this.x[t]-i.ox,this.y[t]-i.oy,i.w,i.h),this.drawCalls++)}else this.__strokePipe(e,t),this.drawCalls++}),this.syncLabelsOnPaint&&this.syncLabels(t),!0}attachLayer(e){this.layer=e;for(const t of x(e)){if(0!==this.type[t])continue;const i=S(e,t);i&&this.liveComponents.set(t,i)}}syncLabels(){(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.lastView)&&this.layer&&C(this.layer,{pad:this.labelSyncPad,budget:128,needs:e=>0===this.type[e],map:e=>this.labelIndexOfSymbol(e)})}applyPatch(e,t){if(!(e>=0)||e>=this.count)return!1;let i=!1;if("number"==typeof t.left&&(this.x[e]=t.left,i=!0),"number"==typeof t.top&&(this.y[e]=t.top,i=!0),0===this.type[e]){const t=this.labelIndexOfSymbol(e);t>=0&&(this.x[t]=this.x[e],this.y[t]=this.y[e]+this.h[e])}return i&&this.rebuildIndex(),this.version++,this.recordEdit(e,this.x[e],this.y[e]),!0}onChildPatched(e,t){this.applyPatch(e,t)}labelIndexOfSymbol(e){const t=this.symbolCount+e;return t<this.count&&1===this.type[t]?t:-1}__strokePipe(e,t){const i=this.pipeFrom[t],n=this.pipeTo[t],r=jn[Xn[this.pipeMedium[t]]],s=this.x[i]+this.w[i]/2,o=this.y[i]+this.h[i]/2,a=this.x[n]+this.w[n]/2,l=this.y[n]+this.h[n]/2,h=s+.5*(a-s);e.save(),e.strokeStyle=r.color,e.lineWidth=1.4,e.setLineDash("dashed"===r.lineType?[5,5]:"dashdot"===r.lineType?[9,4,2,4]:[]),e.beginPath(),e.moveTo(s,o),e.lineTo(h,o),e.lineTo(h,l),e.lineTo(a,l),e.stroke(),e.restore()}drawCalls=0;materialize(e){this.done[e]=1;const t=this.type[e];if(0===t){const t=new WaterSymbol({kind:Kn[this.kind[e]],id:`vs-${e}`,left:this.x[e],top:this.y[e],name:this.nameOf(e),tag:this.tagOf(e)});return this.liveComponents.set(e,t),t}if(1===t){const t=this.labelOf[e];return new c({left:this.x[e],top:this.y[e],width:90,text:`${this.tagOf(t)} ${this.nameOf(t)}`,style:{fontSize:Fn,fillStyle:zn}})}const i=new WaterPipe({id:`vp-${e}`,medium:Xn[this.pipeMedium[e]],dn:`DN${this.pipeDn[e]}`});return i.setState({left:0,top:0}),i}windowItems(e,t){const i=this.labelSyncPad;this.forEachInBox(e.x0-i,e.y0-i,e.x1+i,e.y1+i,t)}pipeBox(e,t){const i=this.pipeFrom[e],n=this.pipeTo[e],r=this.x[i]+this.w[i]/2,s=this.y[i]+this.h[i]/2,o=this.x[n]+this.w[n]/2,a=this.y[n]+this.h[n]/2,l=r+.5*(o-r);return t[0]=Math.min(r,l,o),t[1]=Math.min(s,a),t[2]=Math.max(r,l,o),t[3]=Math.max(s,a),t}get bytes(){return this.type.byteLength+this.x.byteLength+this.y.byteLength+this.w.byteLength+this.h.byteLength+this.kind.byteLength+this.labelOf.byteLength+this.pipeFrom.byteLength+this.pipeTo.byteLength+this.pipeMedium.byteLength+this.pipeDn.byteLength+this.done.byteLength+this.head.byteLength+this.nodePrim.byteLength+this.nodeNext.byteLength+this.windowSeen.byteLength}serializeDocument(){return this.syncEditsFromComponents(),{v:1,params:{symbols:this.symbolCount,cols:this.cols,worldW:this.worldW,worldH:this.worldH,pipes:this.count>2*this.symbolCount},edits:this.edits.map(e=>{let[t,i,n]=e;return[t,Math.round(100*i)/100,Math.round(100*n)/100]})}}edits=[];liveComponents=(()=>new Map)();syncEditsFromComponents(){for(const[e,t]of this.liveComponents){const i=t.state.left,n=t.state.top;(Math.abs(i-this.x[e])>.01||Math.abs(n-this.y[e])>.01)&&(this.x[e]=i,this.y[e]=n,this.recordEdit(e,i,n))}}recordEdit(e,t,i){for(let n=0;n<this.edits.length;n++)if(this.edits[n][0]===e)return void(this.edits[n]=[e,t,i]);this.edits.push([e,t,i])}static fromPayload(e,t){const i=e&&e.params||{},n=new WaterVirtualDoc(t,{symbols:i.symbols,cols:i.cols,worldW:i.worldW,worldH:i.worldH,pipes:!1!==i.pipes}),r=e&&e.edits||[];for(const e of r){const t=Number(e[0]);if(!(t>=0)||t>=n.symbolCount)continue;n.x[t]=Number(e[1]),n.y[t]=Number(e[2]);const i=n.symbolCount+t;n.x[i]=n.x[t],n.y[i]=n.y[t]+n.h[t],n.recordEdit(t,n.x[t],n.y[t])}return n.rebuildIndex(),n}documentBounds(e){return e[0]=0,e[1]=0,e[2]=this.worldW,e[3]=this.worldH,!0}paintToSvg(e){for(let t=0;t<Kn.length;t++){const i=`${Gn}-${Kn[t]}`;this.svgDefs[t]||(this.svgDefs[t]=this.__svgFragmentOfKind(Kn[t])),this.svgDefs[t]&&e.define(i,this.svgDefs[t])}for(let t=0;t<this.symbolCount;t++){if(this.done[t])continue;const i=`${Gn}-${Kn[this.kind[t]]}`;e.use(i,this.x[t],this.y[t])}for(let t=2*this.symbolCount;t<this.count;t++){if(2!==this.type[t]||this.pipeFrom[t]===this.pipeTo[t])continue;const i=this.pipeFrom[t],n=this.pipeTo[t],r=this.x[i]+this.w[i]/2,s=this.y[i]+this.h[i]/2,o=this.x[n]+this.w[n]/2,a=this.y[n]+this.h[n]/2,l=r+.5*(o-r),h=jn[Xn[this.pipeMedium[t]]],c="dashed"===h.lineType?' stroke-dasharray="5 5"':"dashdot"===h.lineType?' stroke-dasharray="9 4 2 4"':"";e.raw(`<polyline points="${r},${s} ${l},${s} ${l},${a} ${o},${a}" fill="none" stroke="${h.color}" stroke-width="1.4"${c}/>`)}for(let t=0;t<this.symbolCount;t++){const i=this.symbolCount+t;if(this.done[i])continue;const n=`${this.tagOf(t)} ${this.nameOf(t)}`;e.raw(`<text x="${this.x[t]}" y="${this.y[i]+Fn}" font-size="${Fn}" fill="${zn}">${escapeXml(n)}</text>`)}return!0}__svgFragmentOfKind(e){const t=new WaterSymbol({kind:e,left:0,top:0,name:"",tag:""});this.ice.addChild(t);try{const e=v([t],{area:"content"});return e.replace(/^<svg[^>]*>/,"").replace(/<\/svg>$/,"").replace(/<defs>[\s\S]*?<\/defs>/,"")||null}finally{this.ice.removeChild(t)}}__mintSprites(){for(let e=0;e<Kn.length;e++){const t=Kn[e],i=$n[t],n=new WaterSymbol({kind:t,left:0,top:0,name:"",tag:""});this.ice.addChild(n),n.refreshParams(),n.composeMatrix();const r=n.getMinBoundingBox().getMinAndMaxPoint(),s=2,o=Math.floor(2*r.minX)-s,a=Math.floor(2*r.minY)-s,l=Math.max(1,Math.ceil(2*r.maxX)-o+s),h=Math.max(1,Math.ceil(2*r.maxY)-a+s),c=document.createElement("canvas");c.width=l,c.height=h;const u=c.getContext("2d");T(n,u,[2,0,0,2,-o,-a]),this.ice.removeChild(n),this.sprites[e]={canvas:c,w:i.width,h:i.height,ox:(0-o)/2,oy:(0-a)/2}}}}function escapeXml(e){return String(e).replace(/[&<>"]/g,e=>"&"===e?"&":"<"===e?"<":">"===e?">":""")}function createDesignerSession(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=new M;i.init(e,{renderMode:"full"===t.renderMode?"full":"dirty-rect"});const n=new EntityDesigner(i),r=t.onChange?n.subscribe(t.onChange):null;t.initialProject&&n.loadProject(t.initialProject);let s=!1;return{ice:i,designer:n,destroy(){s||(s=!0,r&&r(),n.dispose(),i.destroy())}}}function shouldApplyControlledValue(e,t){return void 0!==e&&e!==t}function createFlowSession(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=new M;i.init(e,{renderMode:"full"===t.renderMode?"full":"dirty-rect"});const n=new FlowDesigner(i),r=t.onChange,s=r?n.subscribe(e=>r(e)):null;t.initialFlow&&n.load(t.initialFlow);let o=!1;return{ice:i,designer:n,destroy(){o||(o=!0,s&&s(),n.dispose(),i.destroy())}}}function reportLoadError(e,t,i,n){const r=n instanceof Error?n:new Error(String(n));e&&e({phase:t,snapshot:i,error:r})}function createHandle$1(e){const t=e?e.designer:null;return{ice:e?e.ice:null,designer:t,addEntity:e=>t?t.createEntity(e):null,connect:e=>t?t.createRelation(e):null,updateEntity:(e,i)=>t?t.updateEntity(e,i):null,updateRelation:(e,i)=>t?t.updateRelation(e,i):null,remove:e=>{t&&t.removeComponent(e)},loadProject:e=>t?t.loadProject(e):{loaded:!1,entities:0,relations:0,unknownTypes:[],skipped:[]},undo:()=>{t&&t.undo()},redo:()=>{t&&t.redo()},toSchemaObject:()=>t?t.toSchemaObject():[],toSchemaString:()=>t?t.toSchemaString():"[]",validate:()=>t?t.validate():[],serializeProject:()=>t?t.serializeProject():""}}k(Gn,(e,t)=>t&&t.ice?WaterVirtualDoc.fromPayload(e,t.ice):null);const Yn=n(function EntityDesignerCanvas(e,i){const n=r(null),h=r(null),[c,u]=s(null),d=r(e.onChange);d.current=e.onChange;const p=r(e.onReady);p.current=e.onReady;const y=r(e.onError);y.current=e.onError;const f=r(null),g=e.width||1200,m=e.height||800,_=void 0!==e.value?e.value:e.defaultValue;return o(()=>{const t=n.current;if(!t)return;const i=createDesignerSession(t,{renderMode:e.renderMode,onChange:e=>{f.current=e;const t=d.current,i=h.current;t&&i&&t({snapshot:e,schema:i.designer.toSchemaObject()})}});if(h.current=i,void 0!==_){f.current=_;try{i.designer.loadProject(_)}catch(e){reportLoadError(y.current,"load-initial",_,e)}}else f.current=null;return u(i.designer),p.current&&p.current(createHandle$1(i)),()=>{i.destroy(),h.current=null,u(null)}},[]),o(()=>{if(!c)return;if(!shouldApplyControlledValue(e.value,f.current))return;const t=e.value;f.current=t;try{c.loadProject(t)}catch(e){reportLoadError(y.current,"load-controlled",t,e)}},[e.value,c]),a(i,()=>createHandle$1(h.current),[c]),t(l,null,t("div",{className:e.className,style:{position:"relative",width:g,height:m,...e.style||{}}},t("canvas",{ref:n,width:g,height:m,style:{display:"block"}})),t(EntityDesignerProvider,{designer:c,children:e.children}))}),Jn='{"version":1,"kind":"flowchart","nodes":[],"edges":[]}';function createHandle(e){const t=e?e.designer:null;return{ice:e?e.ice:null,designer:t,addNode:(e,i)=>t?t.createNode(e,i):null,connect:e=>t?t.createEdge(e):null,updateNode:(e,i)=>t?t.updateNode(e,i):null,updateEdge:(e,i)=>t?t.updateEdge(e,i):null,remove:e=>{t&&t.remove(e)},load:e=>t?t.load(e):{loaded:!1,nodes:0,edges:0,skipped:[]},undo:()=>{t&&t.undo()},redo:()=>{t&&t.redo()},serialize:()=>t?t.serialize():Jn,toSnapshot:()=>t?t.toSnapshot():JSON.parse(Jn),fitViewport:e=>{t&&t.fitViewport(e)}}}const Qn=n(function FlowDesignerCanvas(e,i){const n=r(null),h=r(null),[c,u]=s(null),d=r(e.onChange);d.current=e.onChange;const p=r(e.onReady);p.current=e.onReady;const y=r(e.onError);y.current=e.onError;const f=r(null),g=e.width||1200,m=e.height||800,_=void 0!==e.value?e.value:e.defaultValue;return o(()=>{const t=n.current;if(!t)return;const i=createFlowSession(t,{renderMode:e.renderMode,onChange:e=>{f.current=e;const t=d.current,i=h.current;t&&i&&t({snapshot:e,counts:{nodes:i.designer.nodes.length,edges:i.designer.edges.length}})}});if(h.current=i,void 0!==_){f.current=_;try{i.designer.load(_)}catch(e){reportLoadError(y.current,"load-initial",_,e)}}else f.current=null;return u(i.designer),p.current&&p.current(createHandle(i)),()=>{i.destroy(),h.current=null,u(null)}},[]),o(()=>{if(!c)return;if(!shouldApplyControlledValue(e.value,f.current))return;const t=e.value;f.current=t;try{c.load(t)}catch(e){reportLoadError(y.current,"load-controlled",t,e)}},[e.value,c]),a(i,()=>createHandle(h.current),[c]),t(l,null,t("div",{className:e.className,style:{position:"relative",width:g,height:m,...e.style||{}}},t("canvas",{ref:n,width:g,height:m,style:{display:"block"}})),t(FlowDesignerProvider,{designer:c,children:e.children}))});export{Entity,Yn as EntityDesignerCanvas,I as EntityDesignerContext,EntityDesignerProvider,In as FLOW_NODE_KINDS,FlowDesigner,Qn as FlowDesignerCanvas,P as FlowDesignerContext,FlowDesignerProvider,FlowEdge,FlowNode,Relation,createDesignerSession,createFlowSession,shouldApplyControlledValue,toSchemaObject,toSchemaString,useEntityDesigner,useFlowDesigner,validateSchema};
|