@kern0x1b/penstock-cli 26.10.5 → 26.10.6
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/{chunk-account-C8EHysMH.js → chunk-account-CMvFjqGw.js} +1 -1
- package/dist/{chunk-agentFailure-piRAFLGH.js → chunk-agentFailure-BiU8hJ-k.js} +1 -1
- package/dist/{chunk-agentLaunch-C5Uo40vv.js → chunk-agentLaunch-CRWlfuXv.js} +1 -1
- package/dist/{chunk-agentServe-4O0syoYQ.js → chunk-agentServe-M3jzEiHj.js} +1 -1
- package/dist/{chunk-analyze-Brxlb4U1.js → chunk-analyze-CCZJQpbU.js} +1 -1
- package/dist/chunk-analyze-D_2dPr5n.js +1 -0
- package/dist/chunk-apply-Dmo_XdOA.js +1 -0
- package/dist/{chunk-bot-I4kuhjyv.js → chunk-bot-51CfGKVL.js} +3 -3
- package/dist/chunk-codeFactSet-BqEOkvBS.js +1 -0
- package/dist/{chunk-codeIndex-CzENd6hG.js → chunk-codeIndex-olvCG85q.js} +1 -1
- package/dist/{chunk-codeLinks-D-gzUjYv.js → chunk-codeLinks-DW721PAt.js} +1 -1
- package/dist/chunk-codeLinks-S_BEJVPa.js +1 -0
- package/dist/{chunk-command-BctoT00W.js → chunk-command-B-7DfFou.js} +1 -1
- package/dist/chunk-command-CyUljAAc.js +1 -0
- package/dist/{chunk-command-Jl1msVwF.js → chunk-command-D7WS1aRl.js} +1 -1
- package/dist/chunk-commands-CMEkVxle.js +1 -0
- package/dist/{chunk-compose-BV9Jg348.js → chunk-compose-DCAQQndd.js} +1 -1
- package/dist/{chunk-connectors-CVfz5pSg.js → chunk-connectors-DG6IqkGl.js} +1 -1
- package/dist/{chunk-connectors-eXPldvkc.js → chunk-connectors-UpMjbdpU.js} +1 -1
- package/dist/{chunk-context-DPJmldqg.js → chunk-context-B-5CZFAT.js} +1 -1
- package/dist/{chunk-convert-B1sgT9kl.js → chunk-convert-B7srqZpZ.js} +1 -1
- package/dist/chunk-deploy-CGLF2dB1.js +1 -0
- package/dist/{chunk-deploy-DOXu2-8q.js → chunk-deploy-Clj9f2y-.js} +1 -1
- package/dist/chunk-diagram-CIy-F5iz.js +1 -0
- package/dist/{chunk-diagram-BaVwLa4h.js → chunk-diagram-DYoeuAJx.js} +1 -1
- package/dist/{chunk-diagramDefects-7UG_Iwsr.js → chunk-diagramDefects-DlVCfZci.js} +1 -1
- package/dist/{chunk-diagrams-6suPQBVQ.js → chunk-diagrams-wnFsPOKv.js} +1 -1
- package/dist/{chunk-diff-D1m_eKvv.js → chunk-diff-BJ2sJwcs.js} +1 -1
- package/dist/chunk-diff-BelMuQhT.js +1 -0
- package/dist/chunk-dispatch-CescmVW-.js +6 -0
- package/dist/{chunk-docs-CwY3Ce9M.js → chunk-docs-DzOiA9zg.js} +4 -4
- package/dist/{chunk-doctor-m0mnVdDE.js → chunk-doctor-GDNwRCg3.js} +1 -1
- package/dist/{chunk-drawing-shRfnrs9.js → chunk-drawing-C2qewK8L.js} +1 -1
- package/dist/{chunk-editPreview-BgH1JVOD.js → chunk-editPreview-DGu4slO6.js} +1 -1
- package/dist/chunk-export-CDFdw7Eh.js +1 -0
- package/dist/{chunk-export-D5kPD4Or.js → chunk-export-DP1Hab-_.js} +1 -1
- package/dist/{chunk-facts-DA3Y-k9a.js → chunk-facts-CfA8qH5b.js} +1 -1
- package/dist/{chunk-failure-BsimkHy_.js → chunk-failure-BK7fu4Yo.js} +1 -1
- package/dist/{chunk-features-BfRg2kR5.js → chunk-features-CiC2Yoej.js} +1 -1
- package/dist/chunk-features-Dq1Gvqp3.js +1 -0
- package/dist/chunk-folders-BO8qUHUV.js +1 -0
- package/dist/{chunk-folders-13vx0i0n.js → chunk-folders-yTMgOqLo.js} +1 -1
- package/dist/chunk-formChecks-BOiD8Idv.js +1 -0
- package/dist/chunk-help-DKtpVSxI.js +85 -0
- package/dist/chunk-importCommand-_CnKIoNk.js +1 -0
- package/dist/{chunk-init-AIh_7yE0.js → chunk-init-3zEab7KI.js} +3 -3
- package/dist/chunk-license-Cvnp1Aee.js +1 -0
- package/dist/{chunk-license-x3oHbKe2.js → chunk-license-DU4P8P8A.js} +1 -1
- package/dist/{chunk-lint-C_fAcLIg.js → chunk-lint-Df2davEY.js} +1 -1
- package/dist/{chunk-load-BVJUBU5S.js → chunk-load-CRmIvn7e.js} +1 -1
- package/dist/chunk-main-BY7JEoe1.js +1 -0
- package/dist/chunk-mcp-DKX2xT8d.js +77 -0
- package/dist/{chunk-mcpLaunch-C13ViiIP.js → chunk-mcpLaunch-DpDE0hW-.js} +1 -1
- package/dist/chunk-migrate-BaNzQNyD.js +2 -0
- package/dist/chunk-migrate-DcxIkacG.js +1 -0
- package/dist/{chunk-penstockCli-CqiOKC75.js → chunk-penstockCli-B0_wWDGy.js} +1 -1
- package/dist/chunk-plural-Di3FH8HP.js +1 -0
- package/dist/{chunk-pr-tC3-PSNM.js → chunk-pr-DXs1coaS.js} +1 -1
- package/dist/{chunk-project-qT-Fk_Rz.js → chunk-project-BS-4dy5o.js} +1 -1
- package/dist/{chunk-report-CDz78nCI.js → chunk-report-CtkTRSGT.js} +1 -1
- package/dist/{chunk-review-BqZSohXR.js → chunk-review-WIpFGKkc.js} +1 -1
- package/dist/{chunk-rules-DJlL7K_Q.js → chunk-rules-CoJAmvwu.js} +1 -1
- package/dist/{chunk-security-5SU-bq3A.js → chunk-security-BKVRwb6V.js} +10 -10
- package/dist/{chunk-share-YSewfw3F.js → chunk-share-B3W30sbt.js} +3 -3
- package/dist/chunk-src-CxTpK8wk.js +890 -0
- package/dist/{chunk-stages-C-nhLoBW.js → chunk-stages-Gm5BZUp5.js} +1 -1
- package/dist/chunk-status-X9Ny-Nu8.js +1 -0
- package/dist/{chunk-systemError-B-1nL94i.js → chunk-systemError-F6bMRwXU.js} +1 -1
- package/dist/chunk-systemError-cGwrYkmo.js +1 -0
- package/dist/{chunk-table-CJtiXv0e.js → chunk-table-B2WTbpMl.js} +1 -1
- package/dist/chunk-taskTest-B3gfOti1.js +1 -0
- package/dist/{chunk-taskTest-4rIxp0rL.js → chunk-taskTest-D-WDCLD5.js} +2 -2
- package/dist/{chunk-templates-Bxe3J0qy.js → chunk-templates-BdsiNRJ3.js} +1 -1
- package/dist/chunk-testCases-ba8k3BJD.js +4 -0
- package/dist/chunk-testCases-gXzkCxF5.js +1 -0
- package/dist/chunk-tests-BLBZ1eh2.js +1 -0
- package/dist/chunk-tests-DxL0JMtB.js +23 -0
- package/dist/chunk-translator-BAjzyPKE.js +22 -0
- package/dist/{chunk-trust-u1vZ6Yk0.js → chunk-trust-Ci9pDa27.js} +1 -1
- package/dist/{chunk-trust-yKw_pXRj.js → chunk-trust-DlJIoKs8.js} +1 -1
- package/dist/{chunk-workerVariables-CCLcoR0U.js → chunk-workerVariables-BnLSud8o.js} +1 -1
- package/dist/{chunk-wrapper-AJWl6ru-.js → chunk-wrapper-DqqRt0FZ.js} +1 -1
- package/dist/chunk-wrapper-E_u1_-Db.js +1 -0
- package/dist/locales/de.json +103 -2
- package/dist/locales/es.json +103 -2
- package/dist/locales/fr.json +103 -2
- package/dist/locales/ja.json +103 -2
- package/dist/locales/ko.json +103 -2
- package/dist/locales/pt-BR.json +103 -2
- package/dist/locales/ru.json +103 -2
- package/dist/locales/zh.json +103 -2
- package/dist/penstock.js +1 -1
- package/dist/web/assets/{AgentSettings-C3Er_rlW.js → AgentSettings-4B4hSxBk.js} +1 -1
- package/dist/web/assets/{AgentsDialog-Bo7kikb6.js → AgentsDialog-C32ALLtE.js} +1 -1
- package/dist/web/assets/{BpmnCanvas-Dw5zgCN3.js → BpmnCanvas-CZOJiq6t.js} +1 -1
- package/dist/web/assets/{BpmnDocument-CuU0biX9.js → BpmnDocument-BNLfXWLG.js} +4 -4
- package/dist/web/assets/{ConflictDialog-GxZ-d8SK.js → ConflictDialog-mUJYs1zz.js} +1 -1
- package/dist/web/assets/{DiffDocument-Bh3hFmmi.js → DiffDocument-C7csJl3x.js} +1 -1
- package/dist/web/assets/{DmnDocument-C8HpJAcE.js → DmnDocument-B2dyX49k.js} +1 -1
- package/dist/web/assets/{FormDocument-CH-4KB3x.js → FormDocument-ChSqEPE5.js} +1 -1
- package/dist/web/assets/{FormStepView-DraPVoAN.js → FormStepView-j4C0Qovo.js} +1 -1
- package/dist/web/assets/{GraphAwareLayoutService-C8J8YHJI.js → GraphAwareLayoutService-DD2iXfXi.js} +1 -1
- package/dist/web/assets/{NewFileDialog-j09JqpPj.js → NewFileDialog-eeIqqmXc.js} +1 -1
- package/dist/web/assets/{QuickOpen-CeBhsCzA.js → QuickOpen-C0I0FRt2.js} +1 -1
- package/dist/web/assets/{ScriptPane-DDikZDv6.js → ScriptPane-BAvcgLWX.js} +2 -2
- package/dist/web/assets/{ScriptRunDialog-DdzJ0pvT.js → ScriptRunDialog-DLlMiJiK.js} +1 -1
- package/dist/web/assets/{SettingsDialog-JUc5zUR9.js → SettingsDialog-C3ts5aiN.js} +1 -1
- package/dist/web/assets/{ShortcutsDialog-DECqWPNE.js → ShortcutsDialog-DVV504pS.js} +1 -1
- package/dist/web/assets/{SourceDocument-X8ajUcxM.js → SourceDocument-DRgUPazk.js} +1 -1
- package/dist/web/assets/{TextDocument-0z7qojAh.js → TextDocument-Bm0sPjft.js} +1 -1
- package/dist/web/assets/{UnreadableFileLayer-D3G59F4u.js → UnreadableFileLayer-DbW33CnE.js} +1 -1
- package/dist/web/assets/{UploadDialog-CiahYkTc.js → UploadDialog-BSl3zFNn.js} +1 -1
- package/dist/web/assets/{apply-HqvoGwLE.js → apply-B3FkgxjU.js} +1 -1
- package/dist/web/assets/{bpmnTheme-cOvp4qFc.js → bpmnTheme-C3HdVV1D.js} +1 -1
- package/dist/web/assets/bridgeInstance-BZBhe5hF.js +851 -0
- package/dist/web/assets/{commands-nPznxvPp.js → commands-DHPxsavW.js} +1 -1
- package/dist/web/assets/de-BH_bnU4H.js +1 -0
- package/dist/web/assets/{dialog-CtGB1LHI.js → dialog-LcHsiQKJ.js} +1 -1
- package/dist/web/assets/{diff-NgYeO98t.js → diff-bpdDl0KE.js} +1 -1
- package/dist/web/assets/{documentBridge-QW0IZ9Bq.js → documentBridge-4fZNBdp4.js} +2 -2
- package/dist/web/assets/{documents-KeXEdK1U.js → documents-FOVGbYYF.js} +1 -1
- package/dist/web/assets/{duplicate-DNPpPVse.js → duplicate-CdCuOnUl.js} +1 -1
- package/dist/web/assets/{engines-DU0BfbYM.js → engines-C884tl-T.js} +1 -1
- package/dist/web/assets/es-D7v7zkxC.js +1 -0
- package/dist/web/assets/{formChecks-sU20kKkU.js → formChecks-Bvuzw2sb.js} +1 -1
- package/dist/web/assets/fr-CuzAJTai.js +1 -0
- package/dist/web/assets/frontend-Y1MvD_Uo.js +1 -0
- package/dist/web/assets/httpHost-CnF86WJB.js +1 -0
- package/dist/web/assets/{index.es-BqVUpGyA.js → index.es-0rLw__5_.js} +1 -1
- package/dist/web/assets/{index.es-DqkfrvWI.js → index.es-BP1Cc_0e.js} +1 -1
- package/dist/web/assets/{intelligence-Ck_Q9upa.js → intelligence-E2EBYhHr.js} +1 -1
- package/dist/web/assets/ja-BgElyPpa.js +1 -0
- package/dist/web/assets/{jspdf.es.min-CM3S4IDt.js → jspdf.es.min-BSRrqhq_.js} +3 -3
- package/dist/web/assets/ko-j1Oi9MKH.js +1 -0
- package/dist/web/assets/{lib-DAKOOgix.js → lib-De3fPoUi.js} +1 -1
- package/dist/web/assets/{platform-CkWAyNst.js → platform-CjEV0T5t.js} +1 -1
- package/dist/web/assets/{preferences-nBrFGN89.js → preferences-CmXdxfFo.js} +1 -1
- package/dist/web/assets/pt-BR-CRWG2th4.js +1 -0
- package/dist/web/assets/ru-KJyuYSUL.js +1 -0
- package/dist/web/assets/{run-B3YvrVeP.js → run-B9EUa035.js} +1 -1
- package/dist/web/assets/{samples-BVuIm-bu.js → samples-03zukOEM.js} +1 -1
- package/dist/web/assets/{testCaseRuns-DYKnccnc.js → testCaseRuns-BYhJPipg.js} +1 -1
- package/dist/web/assets/translator-OIpY8kTG.js +1 -0
- package/dist/web/assets/{ui-3pEQJ50t.js → ui-BLMlfdD3.js} +1 -1
- package/dist/web/assets/{useTrace-BAXnn0Bt.js → useTrace-Cr28sh4A.js} +1 -1
- package/dist/web/assets/{web-B2zkonPE.js → web-Q9VZNxQi.js} +5 -5
- package/dist/web/assets/zh-CukDLcVz.js +1 -0
- package/dist/web/index.html +19 -19
- package/package.json +1 -1
- package/dist/chunk-analyze-CUxuBgNS.js +0 -1
- package/dist/chunk-apply-BAMwoXG9.js +0 -1
- package/dist/chunk-baseline-DvS2S0am.js +0 -1
- package/dist/chunk-codeFactSet-DOOlbIIj.js +0 -1
- package/dist/chunk-codeLinks-DLxEBWPi.js +0 -1
- package/dist/chunk-command-BR4memGJ.js +0 -1
- package/dist/chunk-commands-CeRlfHY-.js +0 -1
- package/dist/chunk-deploy-C4KJK-tw.js +0 -1
- package/dist/chunk-diagram-CCA1-fT5.js +0 -1
- package/dist/chunk-diff-BC8gZX5w.js +0 -1
- package/dist/chunk-dispatch-CW2CJI0C.js +0 -6
- package/dist/chunk-export-9AWsr5ai.js +0 -1
- package/dist/chunk-features-BwnwB6jL.js +0 -1
- package/dist/chunk-folders-C1Nes4Ap.js +0 -1
- package/dist/chunk-formChecks-acRgARZ3.js +0 -1
- package/dist/chunk-help-CFhmAhz8.js +0 -85
- package/dist/chunk-importCommand-5SJxu2k4.js +0 -1
- package/dist/chunk-license-B_To2110.js +0 -1
- package/dist/chunk-main-D3S4Xr__.js +0 -1
- package/dist/chunk-mcp-ByMCWlXC.js +0 -76
- package/dist/chunk-migrate-CLQ-hrae.js +0 -1
- package/dist/chunk-migrate-CVUR1K7f.js +0 -1
- package/dist/chunk-plural-Bq_4vgOr.js +0 -1
- package/dist/chunk-src-BLyg_6UX.js +0 -879
- package/dist/chunk-status-DgeSOz3A.js +0 -1
- package/dist/chunk-systemError-2me5k57V.js +0 -1
- package/dist/chunk-taskTest-rng12v_b.js +0 -1
- package/dist/chunk-testCases-CwQ-Mi7L.js +0 -1
- package/dist/chunk-testCases-xculyxH_.js +0 -4
- package/dist/chunk-tests-C-kNQNpq.js +0 -1
- package/dist/chunk-tests-C3XJ9LMT.js +0 -23
- package/dist/chunk-translator-BFUJmSkR.js +0 -21
- package/dist/chunk-wrapper-Bxz1Lgp5.js +0 -1
- package/dist/web/assets/bridgeInstance-DQk-c8L1.js +0 -850
- package/dist/web/assets/de-Dj813wjn.js +0 -1
- package/dist/web/assets/es-CyJDEw4H.js +0 -1
- package/dist/web/assets/fr-B1lqrd3d.js +0 -1
- package/dist/web/assets/frontend-caI7mOAL.js +0 -1
- package/dist/web/assets/httpHost-Dqit__mm.js +0 -1
- package/dist/web/assets/ja-BUAM_DzQ.js +0 -1
- package/dist/web/assets/ko-7l4EjTF9.js +0 -1
- package/dist/web/assets/pt-BR-CxxRL7kF.js +0 -1
- package/dist/web/assets/ru-C4gbkVXL.js +0 -1
- package/dist/web/assets/translator-B2N3PQBL.js +0 -1
- package/dist/web/assets/zh-DIYPlVjz.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./chunk-atomicWrite-C6J1gDtO.js";import{r as t}from"./chunk-translator-BFUJmSkR.js";import{t as n}from"./chunk-plural-Bq_4vgOr.js";import{A as r,C as i,D as a,E as o,M as s,N as c,O as l,P as u,S as d,T as f,_ as p,a as m,b as h,c as g,d as _,f as v,g as y,h as b,i as x,j as S,k as C,l as w,m as T,n as E,o as D,p as O,r as k,s as A,u as j,v as M,w as N,x as P,y as F}from"./chunk-diagramDefects-7UG_Iwsr.js";import{readFileSync as I}from"node:fs";import{BpmnModdle as L}from"bpmn-moddle";import{routeEdges as R}from"@mr_mint/elkjs-libavoid";import{Constraint as z,Rectangle as ee,Solver as B,Variable as te,generateXConstraints as ne,generateYConstraints as re}from"webcola";var V=class e extends Error{limitMs;constructor(n){super(t(`app.editor.layoutTooSlow`,{seconds:String(Math.round(n/1e3))})),this.name=e.name,this.limitMs=n}};function ie(e={}){let t=e.limitMs??15e3,n=e.now??(()=>performance.now()),r=n(),i=()=>n()-r;return{limitMs:t,elapsed:i,remaining:()=>t-i(),spare:()=>i()<t*.4,check(){if(i()>=t)throw new V(t)}}}let H=null;function U(){return H}let W=Promise.resolve();function ae(e,t){let n=W.then(async()=>{let n=ie(e);H=n;try{return await t(n)}finally{H=null}});return W=n.catch(()=>void 0),n}function G(){H?.check()}function oe(){return!H||H.spare()}function se(){return new Promise(e=>setTimeout(e,0))}function ce(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(n.source,(t.get(n.source)??0)+1),t.set(n.target,(t.get(n.target)??0)+1);return Math.max(0,...t.values())}function le(e){let t=0;for(let n=0;n<e.length;n++)for(let r=n+1;r<e.length;r++)F(e[n].from,e[n].to,e[r].from,e[r].to)&&t++;return t}function ue(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let{from:a,to:o}of e)t=Math.min(t,a.x,o.x),r=Math.max(r,a.x,o.x),n=Math.min(n,a.y,o.y),i=Math.max(i,a.y,o.y);let a=Math.max(100,Math.max(r-t,i-n)/Math.ceil(Math.sqrt(e.length))),o=(e,t,n)=>[Math.floor((e-n)/a),Math.floor((t-n)/a)],s=e.map(({from:e,to:r})=>({x:o(Math.min(e.x,r.x),Math.max(e.x,r.x),t),y:o(Math.min(e.y,r.y),Math.max(e.y,r.y),n)})),c=0;for(let e of s)if(c+=(e.x[1]-e.x[0]+1)*(e.y[1]-e.y[0]+1),c>2e6)return 1/0;let l=/* @__PURE__ */ new Map;s.forEach((e,t)=>{for(let n=e.x[0];n<=e.x[1];n++)for(let r=e.y[0];r<=e.y[1];r++){let e=`${n}:${r}`,i=l.get(e);i?i.push(t):l.set(e,[t])}});let u=0;for(let e of l.values())if(u+=e.length*(e.length-1)/2,u>8e6)return 1/0;let d=0;for(let[t,n]of l){let[r,i]=t.split(`:`).map(Number);for(let t=0;t<n.length;t++)for(let a=t+1;a<n.length;a++){let o=s[n[t]],c=s[n[a]];if(Math.max(o.x[0],c.x[0])!==r||Math.max(o.y[0],c.y[0])!==i)continue;let l=e[n[t]],u=e[n[a]];F(l.from,l.to,u.from,u.to)&&d++}}return d}function de(e){let t=ce(e);return e.length>2e4?{edges:e.length,crossings:1/0,hub:t}:{edges:e.length,crossings:e.length>1500?ue(e):le(e),hub:t}}function fe(e,t,n){let r=2e-4*(e.edges+t)**2+.02*e.edges*e.hub**2+.17*e.edges*e.crossings;return n?r*(1+e.crossings/15):r}var pe=class extends Error{};const me=e=>e.width||100,he=e=>e.height||80;function ge(e,t){let n=t?.positions.get(e.id)??{x:e.x,y:e.y},r=t?.sizes.get(e.id)??{width:me(e),height:he(e)},i=t?.padding?.get(e.id)??{top:0,right:0,bottom:0,left:0};return{left:n.x-i.left,top:n.y-i.top,right:n.x+r.width+i.right,bottom:n.y+r.height+i.bottom}}function _e(e,t){let n=e.map((e,t)=>({index:t,centre:e})).sort((e,t)=>e.centre-t.centre),r=[],i=[],a=()=>{i.length>1&&r.push(i.map(e=>e.index)),i=[]};for(let e of n){let n=i.length?e.centre-i[i.length-1].centre:0,r=i.length?e.centre-i[0].centre:0;i.length&&(n>t||r>t)&&a(),i.push(e)}return a(),r}function ve(e){let t=(e,t)=>e.x>=t.x&&e.X<=t.X&&e.y>=t.y&&e.Y<=t.Y;for(let n=0;n<e.length;n++)for(let r=0;r<e.length;r++){if(n===r)continue;let i=e[n],a=e[r];if(!t(i,a))continue;let o=a.X-i.x+1,s=i.X-a.x+1,c=a.Y-i.y+1,l=i.Y-a.y+1,u=Math.min(o,s,c,l);u===o?(i.x+=o,i.X+=o):u===s?(i.x-=s,i.X-=s):u===c?(i.y+=c,i.Y+=c):(i.y-=l,i.Y-=l)}}function ye(e){for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){let r=e[t],i=e[n];if(r.x<i.X&&i.x<r.X&&r.y<i.Y&&i.y<r.Y)return!0}return!1}function be(e,t,n,r,i,a){let o=e.map(e=>new te(t(e))),s=new Map(o.map((e,t)=>[e,t])),c=i(e,o),l=/* @__PURE__ */ new Set;for(let e of c){let t=s.get(e.left),n=s.get(e.right);t!==void 0&&n!==void 0&&l.add(t<n?`${t}:${n}`:`${n}:${t}`)}for(let n of a){let r=t(e[n.follower])-t(e[n.owner]);c.push(new z(o[n.owner],o[n.follower],r,!0)),l.add(n.owner<n.follower?`${n.owner}:${n.follower}`:`${n.follower}:${n.owner}`)}for(let n of _e(e.map(t),20))for(let e=1;e<n.length;e++){let t=n[e-1],r=n[e],i=t<r?`${t}:${r}`:`${r}:${t}`;l.has(i)||c.push(new z(o[t],o[r],0,!0))}new B(o,c).solve(),e.forEach((e,t)=>{let i=o[t].position();if(!Number.isFinite(i))return;let a=n(e)/2;r(e,i-a,i+a)})}function xe(e){let t=[...new Set(e.values())].sort((e,t)=>e-t),n=new Map(t.map((e,t)=>[e,t]));return new Map([...e].map(([e,t])=>[e,n.get(t)]))}function Se(e,t,n,r){let i=e.filter(e=>e.width>0&&e.height>0).filter(e=>!n.has(e.type??``)),a=i;if(a.length<1||!r&&(i.length<2||i.every(e=>e.x===0&&e.y===0)))return null;let o=Math.min(8,Math.max(2,t.nodesep/8)),s=i.map(e=>r?.positions.get(e.id)??{x:e.x,y:e.y}),c=i.map(e=>ge(e,r)),l=[],u=c.map(e=>new ee(e.left-o/2,e.right+o/2,e.top-o/2,e.bottom+o/2));for(let e=0;e<10&&ye(u);e++)ve(u),be(u,e=>e.cx(),e=>e.width(),(e,t,n)=>{e.x=t,e.X=n},ne,l),be(u,e=>e.cy(),e=>e.height(),(e,t,n)=>{e.y=t,e.Y=n},re,l);let d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new Map;i.forEach((e,t)=>{let n=u[t].x+o/2,r=u[t].y+o/2,i=Math.round(n-c[t].left),a=Math.round(r-c[t].top),l=Number.isFinite(i)?s[t].x+i:s[t].x,m=Number.isFinite(a)?s[t].y+a:s[t].y;d.set(e.id,{x:l,y:m}),f.set(e.id,l+me(e)/2),p.set(e.id,m+he(e)/2)}),e.forEach(e=>{if(d.has(e.id))return;let t=r?.positions.get(e.id)??{x:e.x,y:e.y};d.set(e.id,t),f.set(e.id,t.x+me(e)/2),p.set(e.id,t.y+he(e)/2)});let m=e=>r?.positions.get(e.id)??{x:e.x,y:e.y},h=Math.max(...a.map(e=>m(e).x+me(e)))-Math.min(...a.map(e=>m(e).x)),g=Math.max(...a.map(e=>m(e).y+he(e)))-Math.min(...a.map(e=>m(e).y))>h;return{positions:d,ranks:xe(g?p:f),rows:xe(g?f:p),authored:!0}}function Ce(e){return(e.children||[]).filter(e=>!!e.width&&!!e.height&&e.type!==`bpmn:Lane`&&!e.waypoints)}function we(e,t,n,r,i={x:0,y:0}){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Set,s=0,c=0,l=1/0,u=1/0;return e.forEach(e=>{let d=t.get(e.id)??{x:e.x,y:e.y},f=(Number.isFinite(d.x)?d.x:e.x)+i.x,p=(Number.isFinite(d.y)?d.y:e.y)+i.y,m=f-e.x,h=p-e.y;(m!==0||h!==0)&&(n.moves.push({elements:r(e),dx:m,dy:h}),o.add(e.id)),a.set(e.id,{x:f,y:p,width:e.width,height:e.height}),l=Math.min(l,f),u=Math.min(u,p),s=Math.max(s,f+e.width),c=Math.max(c,p+e.height)}),{positions:t,rects:a,size:{width:Number.isFinite(l)?s-l:0,height:Number.isFinite(u)?c-u:0},movedIds:o}}function Te(e,t,n,r,i,a={x:e.x,y:e.y,width:e.width,height:e.height},o=!1){if(!(a.width>0&&a.height>0))return;let s=[...t.entries()].filter(([e])=>n.has(e)).map(([,e])=>e);if(s.length===0)return;let c=r.marginY,l=Math.min(...s.map(e=>e.x))-c,u=Math.min(...s.map(e=>e.y))-c,d=Math.max(...s.map(e=>e.x+e.width))+c,f=Math.max(...s.map(e=>e.y+e.height))+c,p=o?l:Math.min(a.x,l),m=o?u:Math.min(a.y,u),h=(o?d:Math.max(a.x+a.width,d))-p,g=(o?f:Math.max(a.y+a.height,f))-m;(p!==a.x||m!==a.y||h!==a.width||g!==a.height)&&i.resizes.push({element:e,x:p,y:m,width:h,height:g})}function Ee(e,t){let n=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let r=n.get(t.id)??{x:0,y:0};n.set(t.id,{x:r.x+e.dx,y:r.y+e.dy})}));let r=new Map(t.resizes.map(e=>[e.element.id,e])),i=[],a=1/0,o=1/0,s=-1/0,c=-1/0,l=(e,t)=>{let u=r.get(e.id),d=n.get(e.id)??{x:0,y:0},f=u?{x:u.x,y:u.y,width:u.width,height:u.height}:{x:e.x+d.x,y:e.y+d.y,width:e.width,height:e.height};!w(e)&&!j(e)&&(a=Math.min(a,f.x),o=Math.min(o,f.y),s=Math.max(s,f.x+f.width),c=Math.max(c,f.y+f.height),t&&i.push(f));let p=(e.children||[]).filter(e=>!w(e)&&!j(e));p.forEach(e=>l(e,t&&p.length>0))};return(e.children||[]).forEach(e=>l(e,!g(e)&&!x.has(e.type??``)&&e.type!==`bpmn:Lane`)),{boxes:i,frame:a===1/0?{x:0,y:0,width:0,height:0}:{x:a,y:o,width:s-a,height:c-o}}}function De(e,t){let{boxes:n,frame:r}=Ee(e,t),i=n.filter(e=>!n.some(t=>t!==e&&l(t,e))),a=0;for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++)S(i[e],i[t])&&(a+=1);let o=t.routes.map(e=>e.waypoints).filter(e=>e.length>1),s=0,c=0;for(let e=0;e<o.length;e++)for(let t=e+1;t<o.length;t++)N(o[e],o[t])>0&&(s+=1),b(o[e],o[t])&&(c+=1);let u=o.reduce((e,t)=>e+T(t),0),d=0,p=0;o.forEach(e=>{d+=e.length-2,p+=f(e)});let m=r.width*r.height,h=1e9*a+12e3*s+1500*c+1500*u+150*d+p+.005*m;return{overlaps:a,crossings:s,merges:c,jogs:u,bends:d,length:p,area:m,energy:h}}function Oe(e,t){let n=[],r=/* @__PURE__ */ new Set,i=e=>{r.has(e.id)||(r.add(e.id),n.push(e))},a=e=>{i(e),(e.attachers||[]).forEach(i),(e.children||[]).forEach(a)};(e.children||[]).forEach(a);let o=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=o.get(t.id)??{x:0,y:0};o.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let s=new Map(t.resizes.map(e=>[e.element.id,e]));return{every:n,rectOf:e=>{let t=s.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=o.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}}}}function K(e){let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t}function ke(e,t,n,r){if(w(t)){let r=n.get(t.id)??t.waypoints??[];for(let t=0;t+1<r.length;t++){let n=o(e,r[t],r[t+1]);if(Math.abs(n.x-e.x)<=2&&Math.abs(n.y-e.y)<=2)return!0}return!1}return u(e,r(t),2)}const Ae=/* @__PURE__ */ new Set([`bpmn:TextAnnotation`,`bpmn:Group`]);function je(e,t,n){let{every:r,rectOf:i}=Oe(e,t),a=r.filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),o=0;return t.routes.forEach(e=>{let t=e.waypoints||[],r=e.connection,s=/* @__PURE__ */ new Set([r.source?.id,r.target?.id,...K(r.source),...K(r.target)]);for(let r=0;r+1<t.length;r++){let c=p(t[r],t[r+1]);if(!c)continue;let l=a.find(e=>s.has(e.id)||Ae.has(e.type??``)?!1:d(c,i(e)));l&&(o+=1,n?.(e,l))}}),o}function Me(e,t,n){let{rectOf:r}=Oe(e,t),i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;t.routes.forEach(e=>{let t=e.connection;if(!t.source||!t.target)return;let n=`${t.type}:${t.source.id}:${t.target.id}`;i.has(n)?a.add(t.id):i.add(n)});let o=0;return t.routes.forEach(e=>{let t=e.waypoints??[],i=e.connection;if(a.has(i.id)||t.length<2||!i.source||!i.target||i.type!==`bpmn:MessageFlow`&&i.type!==`bpmn:SequenceFlow`)return;let s=f(t),c=r(i.source),l=r(i.target),u=Math.abs(c.x+c.width/2-(l.x+l.width/2))+Math.abs(c.y+c.height/2-(l.y+l.height/2));u<40||s<=u*2||(o+=1,n?.(e))}),o}function Ne(e){let t=0;return e.routes.forEach(e=>{let n=e.connection;if(n.type!==`bpmn:Association`&&n.type!==`bpmn:DataInputAssociation`&&n.type!==`bpmn:DataOutputAssociation`)return;let r=e.waypoints??[];r.length<2||f(r)<=300||(t+=1)}),t}function Pe(e,t){let{every:n,rectOf:r}=Oe(e,t),i=n.filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),o=i.filter(e=>e.type===`bpmn:Participant`||e.type===`bpmn:SubProcess`),c=new Map(t.routes.map(e=>[e.connection.id,e.waypoints])),u=/* @__PURE__ */ new Set([`bpmn:Participant`,`bpmn:Lane`,`bpmn:SubProcess`]),d=/* @__PURE__ */ new Set([`bpmn:TextAnnotation`,`bpmn:DataObjectReference`,`bpmn:DataStoreReference`]),f=[...n.filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),...n.filter(g)],p=0;for(let e=0;e<f.length;e++)for(let t=e+1;t<f.length;t++){let n=f[e],i=f[t];if(n.host?.id===i.id||i.host?.id===n.id||K(n).has(i.id)||K(i).has(n.id)||n.type===`bpmn:Group`||i.type===`bpmn:Group`||Ae.has(n.type??``)&&u.has(i.type??``)||Ae.has(i.type??``)&&u.has(n.type??``))continue;let a=n.type===`bpmn:Participant`&&i.type===`bpmn:Participant`,o=d.has(n.type??``)||d.has(i.type??``);if(!a&&!o&&n.parent!==i.parent&&n.type!==`bpmn:Participant`&&i.type!==`bpmn:Participant`)continue;let s=r(n),c=r(i);s.x<c.x+c.width&&c.x<s.x+s.width&&s.y<c.y+c.height&&c.y<s.y+s.height&&(p+=1)}let m=0,h=0;t.routes.forEach(e=>{let t=e.waypoints,n=e.connection;if(!t||t.length<2)return;let i=!n.source||ke(t[0],n.source,c,r),a=!n.target||ke(t[t.length-1],n.target,c,r);i&&a||(m+=1);for(let e=0;e+1<t.length;e++)if(Math.abs(t[e].x-t[e+1].x)>.5&&Math.abs(t[e].y-t[e+1].y)>.5){h+=1;break}});let _=0;t.routes.forEach(e=>{let t=e.waypoints,n=e.connection;if(!t||t.length<2)return;let a=K(n.source),o=K(n.target);i.forEach(e=>{if(e.id===n.source?.id||e.id===n.target?.id||a.has(e.id)||o.has(e.id)||Ae.has(e.type??``))return;let i=r(e);for(let e=0;e+1<t.length;e++)s(t[e],t[e+1],i,2)&&(_+=1)})});let v=0;n.forEach(e=>{if(e.type===`bpmn:Participant`||e.type===`bpmn:Lane`||e.type===`bpmn:Group`||w(e)||j(e))return;let t=r(e),n=K(e);o.forEach(i=>{if(i.id===e.id||e.host?.id===i.id||K(i).has(e.id))return;let o=r(i),s=l(o,t),c=a(t,o);(e.type===`bpmn:TextAnnotation`?!s&&!c:n.has(i.id)?!s:!c)&&(v+=1)})});let y=0;return n.filter(g).forEach(e=>{let t=e.host;if(!t)return;let n=r(e),i=r(t),a=n.x+n.width/2,o=n.y+n.height/2,s=Math.abs(a-i.x)<=2||Math.abs(a-(i.x+i.width))<=2,c=Math.abs(o-i.y)<=2||Math.abs(o-(i.y+i.height))<=2,l=a>=i.x-2&&a<=i.x+i.width+2,u=o>=i.y-2&&o<=i.y+i.height+2;s&&u||c&&l||(y+=1)}),{ok:p===0&&m===0&&_===0&&v===0&&y===0&&h===0,overlaps:p,detachedEdges:m,edgeThroughNode:_,containment:v,boundaryOffHost:y,diagonalEdges:h}}function Fe(e,t,n=.5){let r=e.x+e.width*n,i=e.y+e.height*n,a=t.x+t.width/2,o=t.y+t.height/2;if(t.y>=e.y+e.height){let n={x:r,y:e.y+e.height},i={x:a,y:t.y};return n.x===i.x?[n,i]:[n,{x:n.x,y:i.y},i]}if(t.y+t.height<=e.y){let n={x:r,y:e.y},i={x:a,y:t.y+t.height};return n.x===i.x?[n,i]:[n,{x:n.x,y:i.y},i]}if(t.x>=e.x+e.width){let n={x:e.x+e.width,y:i},r={x:t.x,y:o};return n.y===r.y?[n,r]:[n,{x:r.x,y:n.y},r]}let s={x:e.x,y:i},c={x:t.x+t.width,y:o};return s.y===c.y?[s,c]:[s,{x:c.x,y:s.y},c]}function Ie(e,t,n){let r=e.length,i=new Map(e.map((e,n)=>[t(e),n])),a=Array.from({length:r},()=>Array(r).fill(0));n.forEach((e,t)=>{let[n,r]=t.split(`|`),o=i.get(n),s=i.get(r);o!==void 0&&s!==void 0&&o!==s&&(a[o][s]+=e,a[s][o]+=e)});let o=a.map(e=>e.reduce((e,t)=>e+t,0)),s=1<<r,c=new Float64Array(s);for(let e=1;e<s;e++){let t=e&-e,n=31-Math.clz32(t),i=e^t,s=0;for(let e=0;e<r;e++)i&1<<e&&(s+=a[n][e]);c[e]=c[i]+o[n]-2*s}let l=new Float64Array(s).fill(1/0),u=new Int32Array(s).fill(-1);l[0]=0;for(let e=1;e<s;e++){for(let t=0;t<r;t++){if(!(e&1<<t))continue;let n=l[e^1<<t];n<l[e]&&(l[e]=n,u[e]=t)}l[e]+=c[e]}let d=[];for(let t=s-1;t>0;){let n=u[t];d.push(e[n]),t^=1<<n}return d.reverse()}function Le(e,t){return e<t?`${e}|${t}`:`${t}|${e}`}function Re(e,t,n,r=!1){let i=[...e].sort((e,t)=>e.y-t.y||(e.id<t.id?-1:1));if(e.length<3||n.size===0)return i;if(r&&e.length<=14)return Ie(i,t,n);let a=e=>{let r=new Map(e.map((e,n)=>[t(e),n])),i=0;return n.forEach((e,t)=>{let[n,a]=t.split(`|`),o=r.get(n),s=r.get(a);o!==void 0&&s!==void 0&&(i+=e*Math.abs(o-s))}),i},o=i,s=a(o);for(let e=0;e<20;e++){let e=new Map(o.map((e,n)=>[t(e),n])),r=[...o.map(r=>{let i=t(r),a=0,o=0;return n.forEach((t,n)=>{let[r,s]=n.split(`|`),c=r===i?s:s===i?r:null;if(c===null)return;let l=e.get(c);l!==void 0&&(a+=t,o+=t*l)}),{item:r,place:a?o/a:e.get(i)}})].sort((e,t)=>e.place-t.place||(e.item.id<t.item.id?-1:1)).map(e=>e.item),i=a(r);if(i>=s)break;o=r,s=i}return o}function ze(e){let t=e=>[e,...(e.children||[]).flatMap(t)],n=/* @__PURE__ */ new Map;e.forEach(e=>t(e).forEach(t=>n.set(t.id,e.id)));let r=/* @__PURE__ */ new Map;return e.flatMap(t).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;if(!_(t))return;let i=n.get(t.source?.id??``),a=n.get(t.target?.id??``);if(!i||!a||i===a)return;let o=Le(i,a);r.set(o,(r.get(o)??0)+1)})),r}function Be(e,t=!1){let n=ze(e);return new Map(Re(e,e=>e.id,n,t).map((e,t)=>[e.id,t]))}function Ve(e,t,n,r,i){if(!n||e.length<2)return e;let a=r?0:e.length-1,o=r?1:e.length-2,s=e[a],c=e[o],l=t.x+t.width/2,u=t.y+t.height/2,d=Math.abs(s.x-t.x)<.5,f=Math.abs(s.x-(t.x+t.width))<.5,p=Math.abs(s.y-t.y)<.5,m=Math.abs(s.y-(t.y+t.height))<.5,h=o===0||o===e.length-1,g=[...e],_=(e,t)=>{g[a]=e,h?Math.abs(t.x-c.x)<.5&&Math.abs(t.y-c.y)<.5||g.splice(r?1:g.length-1,0,t):g[o]=t};(d||f)&&Math.abs(s.y-u)>.5?Math.abs(c.y-s.y)<.5&&_({x:s.x,y:u},{x:c.x,y:u}):(p||m)&&Math.abs(s.x-l)>.5&&Math.abs(c.x-s.x)<.5&&_({x:l,y:s.y},{x:l,y:c.y});for(let t=0;t+1<g.length;t++)if(q(g[t],g[t+1],i))return e;return g}function q(e,t,n){return n.some(n=>{if(e.x===t.x){let r=e.x;return r>n.x+.01&&r<n.x+n.width-.01&&Math.min(e.y,t.y)<n.y+n.height&&Math.max(e.y,t.y)>n.y}if(e.y===t.y){let r=e.y;return r>n.y+.01&&r<n.y+n.height-.01&&Math.min(e.x,t.x)<n.x+n.width&&Math.max(e.x,t.x)>n.x}return!1})}function J(e,t){return u(e,t,.5)}function He(e,t,n,r){let i=e;return t&&!J(i[0],t)&&(i=Ve(i,t,!0,!0,r)),n&&!J(i[i.length-1],n)&&(i=Ve(i,n,!0,!1,r)),i}var Ue=class{items=[];push(e){this.items.push(e);let t=this.items.length-1;for(;t>0;){let e=t-1>>1;if(this.items[e].guess<=this.items[t].guess)break;[this.items[e],this.items[t]]=[this.items[t],this.items[e]],t=e}}pop(){let e=this.items[0],t=this.items.pop();if(t===void 0||this.items.length===0)return e;this.items[0]=t;let n=0;for(;;){let t=n*2+1,r=t+1,i=n;if(t<this.items.length&&this.items[t].guess<this.items[i].guess&&(i=t),r<this.items.length&&this.items[r].guess<this.items[i].guess&&(i=r),i===n)return e;[this.items[n],this.items[i]]=[this.items[i],this.items[n]],n=i}}};function We(e,t,n){let r=Math.min(e.x,t.x),i=Math.max(e.x,t.x),a=Math.min(e.y,t.y),o=Math.max(e.y,t.y);return n.some(e=>i>e.x+4&&r<e.x+e.width-4&&o>e.y+4&&a<e.y+e.height-4)}function Ge(e,t,n,r){let i=Math.min(t,n)-r*2,a=Math.max(t,n)+r*2,o=/* @__PURE__ */ new Set([t,n]);return e.forEach(e=>{e>=i&&e<=a&&o.add(e)}),[...o].sort((e,t)=>e-t)}function Ke(e,t,n,r,i,a,o=2,s=90){let c=n.flatMap(e=>[e.x-i,e.x+e.width+i]),l=n.flatMap(e=>[e.y-i,e.y+e.height+i]),u=Ge(c,e.x,t.x,i).filter(e=>!a||e>=a.x-i&&e<=a.x+a.width+i),d=Ge(l,e.y,t.y,i);if(u.length*d.length>s*s)return null;let f=new Map(u.map((e,t)=>[e,t])),p=new Map(d.map((e,t)=>[e,t])),m=f.get(e.x),h=p.get(e.y),g=f.get(t.x),_=p.get(t.y);if(m===void 0||h===void 0||g===void 0||_===void 0)return null;let v=u.length,y=(e,t,n)=>(t*v+e)*3+n,b=/* @__PURE__ */ new Map,x=/* @__PURE__ */ new Map,S=new Ue,C=(e,n,r,i)=>{let a=y(e,n,r),o=b.get(a);return o!==void 0&&o<=i?!1:(b.set(a,i),S.push({ix:e,iy:n,dir:r,cost:i,guess:i+Math.abs(u[e]-t.x)+Math.abs(d[n]-t.y)}),!0)};C(m,h,o,0);let w=[];r.forEach(e=>{for(let t=0;t+1<e.length;t++){let n=e[t],r=e[t+1];w.push({a:n,b:r,left:Math.min(n.x,r.x),right:Math.max(n.x,r.x),top:Math.min(n.y,r.y),bottom:Math.max(n.y,r.y)})}});let T=/* @__PURE__ */ new Map,E=(e,t,n,r)=>{let i=n*v*d.length+r,a=T.get(i);if(a!==void 0)return a;let o=Math.min(e.x,t.x),s=Math.max(e.x,t.x),c=Math.min(e.y,t.y),l=Math.max(e.y,t.y),u=0;for(let n of w)n.right<o||n.left>s||n.bottom<c||n.top>l||F(e,t,n.a,n.b)&&u++;let f=u*400;return T.set(i,f),f},D=-1,O=0;for(;;){O++%512==0&&G();let e=S.pop();if(!e)break;if(b.get(y(e.ix,e.iy,e.dir))!==e.cost)continue;if(e.ix===g&&e.iy===_&&(o===2||e.dir===o)){D=y(e.ix,e.iy,e.dir);break}let t=[[e.ix+1,e.iy,0],[e.ix-1,e.iy,0],[e.ix,e.iy+1,1],[e.ix,e.iy-1,1]],r=e.ix===m&&e.iy===h;t.forEach(([t,i,a])=>{if(t<0||i<0||t>=u.length||i>=d.length||o!==2&&r&&a!==o)return;let s={x:u[e.ix],y:d[e.iy]},c={x:u[t],y:d[i]};if(We(s,c,n))return;let l=e.dir===2||e.dir===a?0:60,f=e.cost+Math.abs(c.x-s.x)+Math.abs(c.y-s.y)+l+E(s,c,e.iy*v+e.ix,i*v+t);C(t,i,a,f)&&x.set(y(t,i,a),y(e.ix,e.iy,e.dir))})}if(D<0)return null;let k=[],A=D;for(;A!==void 0;){let e=Math.floor(A/3);k.push({x:u[e%v],y:d[Math.floor(e/v)]}),A=x.get(A)}k.reverse();let j=[];return k.forEach((e,t)=>{let n=j[j.length-1];if(n&&n.x===e.x&&n.y===e.y)return;let r=k[t+1];n&&r&&(n.x===e.x&&r.x===e.x||n.y===e.y&&r.y===e.y)||j.push(e)}),j}function qe(e,t,n){let r=/* @__PURE__ */ new Map,i=[];return[...e].sort((e,r)=>n(e)-n(r)||t(e).from-t(r).from).forEach(e=>{let n=t(e),a=i.findIndex(e=>e<=n.from);a<0&&(a=i.length),i[a]=n.to,r.set(e,a)}),r}function Je(e,t){let n=new Map(e.map((e,t)=>[e,t]));return t.map((t,r)=>{let i=n.get(t.from)??0,a=n.get(t.to)??0,o=Math.min(i,a),s=Math.max(i,a),c=t=>`${e[t]}|${e[t+1]}`;return s-o<=1?{id:t.id,fromPool:t.from,toPool:t.to,gaps:[c(o)],strip:null}:{id:t.id,fromPool:t.from,toPool:t.to,gaps:[c(i<a?i:i-1),c(a<i?a:a-1)],strip:r%2==0?`right`:`left`}})}function Ye(e,t,n,r,i){let a=e=>c({x:e,y:t},{x:e,y:n},r)===0&&i.every(t=>Math.abs(t-e)>=16);if(a(e))return e;for(let t=1;t<=24;t++)for(let n of[1,-1]){let r=e+n*t*16;if(a(r))return r}return e}function Xe(e,t,n){let r=/* @__PURE__ */ new Map;e.forEach(e=>[...new Set(e.plan.gaps)].forEach(t=>{r.has(t)||r.set(t,[]),r.get(t).push(e)}));let i=e=>({from:Math.min(e.source.x+e.source.width/2,e.target.x+e.target.width/2),to:Math.max(e.source.x+e.source.width/2,e.target.x+e.target.width/2)}),a=/* @__PURE__ */ new Map;r.forEach((e,t)=>{let n=qe(e,i,e=>i(e).from);a.set(t,new Map([...n].map(([e,t])=>[e.connection.id,t])))});let o=e.filter(e=>e.plan.strip!==null),s=/* @__PURE__ */ new Map,c=e=>({from:Math.min(e.sourcePool.y,e.targetPool.y),to:Math.max(e.sourcePool.y+e.sourcePool.height,e.targetPool.y+e.targetPool.height)});[`left`,`right`].forEach(e=>{qe(o.filter(t=>t.plan.strip===e),c,e=>c(e).from).forEach((e,t)=>s.set(t.connection.id,e))});let l=[],u=/* @__PURE__ */ new Map;return e.forEach(e=>{let r=e.source.x+e.source.width/2,i=e.target.x+e.target.width/2,o=e.sourcePool.y<e.targetPool.y,c=o?e.source.y+e.source.height:e.source.y,d=o?e.target.y:e.target.y+e.target.height,f=n=>{let r=t.gapOf(n),i=a.get(n)?.get(e.connection.id)??0;if(!r)return c;let o=Math.max(1,r.high-r.low),s=Math.max(1,a.get(n)?.size??1),l=Math.min(20,o/(s+1));return r.low+o/2+(i-(s-1)/2)*l},p=f(e.plan.gaps[0]),m=f(e.plan.gaps[e.plan.gaps.length-1]),h=Ye(r,Math.min(c,p),Math.max(c,p),n,l);l.push(h);let g=Ye(i,Math.min(d,m),Math.max(d,m),n,l);if(l.push(g),e.plan.strip===null){u.set(e.connection.id,[{x:h,y:c},{x:h,y:p},{x:g,y:p},{x:g,y:d}]);return}let _=s.get(e.connection.id)??0,v=e.plan.strip===`right`?t.rightAt+(_+1)*20:t.leftAt-(_+1)*20;u.set(e.connection.id,[{x:h,y:c},{x:h,y:p},{x:v,y:p},{x:v,y:m},{x:g,y:m},{x:g,y:d}])}),u}const Ze=[`channel`,`target`,`source`,`third`,`far`];function Qe(e,t){let n=new Map(e.map(e=>[e.id,e.id])),r=e=>{let t=e;for(;n.get(t)!==t;)t=n.get(t);return t};return t.forEach(e=>{let t=v(e.source),i=v(e.target);if(!t||!i||!n.has(t.id)||!n.has(i.id))return;let a=r(t.id),o=r(i.id);a!==o&&n.set(a,o)}),new Map(e.map(e=>[e.id,r(e.id)]))}function $e(e){let t=v(e.source),n=v(e.target);return!t||!n?e.source.id:t.y<=n.y?`${t.id}|${n.id}`:`${n.id}|${t.id}`}function et(e){let t=e=>{let t=e.source,n=e.target,r=t.x+t.width/2,i=n.x+n.width/2;return{from:Math.min(r,i),to:Math.max(r,i)}},n=/* @__PURE__ */ new Map;e.forEach(e=>{let t=$e(e);n.has(t)||n.set(t,[]),n.get(t).push(e)});let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;return n.forEach((e,n)=>{let a=[];[...e].sort((e,n)=>t(e).from-t(n).from||(e.id<n.id?-1:1)).forEach(e=>{let n=t(e),i=a.findIndex(e=>e<=n.from);i<0&&(i=a.length),a[i]=n.to+20,r.set(e.id,i)}),i.set(n,a.length)}),{lane:r,width:i}}function tt(e){let t=e=>[e,...(e.children||[]).flatMap(t)],n=/* @__PURE__ */ new Map;return t(e).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;_(t)&&t.source&&t.target&&n.set(t.id,t)})),et([...n.values()]).width}function nt(e,t,n,r){let i=Math.min(e.y,t.y),a=Math.max(e.y+e.height,t.y+t.height),o=n.filter(e=>e.y>=i-1&&e.y+e.height<=a+1).sort((e,t)=>e.y-t.y),s=[];for(let e=1;e<o.length;e++){let t=o[e-1],n=o[e];s.push((t.y+t.height+n.y)/2)}return r?s:s.reverse()}function rt(e,t,n,r,i,a,o,s){if(i.length===0)return null;let c=e=>M(e,a)*m+o.reduce((t,n)=>t+N(e,n),0),l=e.x+e.width/2,u=[{x:l,y:t}],d=n.x+n.width/2;if(i.forEach((e,t)=>{let n=t+1<i.length?i[t+1]:r,o=/* @__PURE__ */ new Set([l,d]);a.forEach(t=>{t.y>Math.max(e,n)||t.y+t.height<Math.min(e,n)||(o.add(t.x-10),o.add(t.x+t.width+10))});let f={x:l,price:1/0};[...o].filter(e=>!s||e>=s.x&&e<=s.x+s.width).sort((e,t)=>Math.abs(e-d)-Math.abs(t-d)).forEach(t=>{let r=c([{x:l,y:e},{x:t,y:e},{x:t,y:n}])+Math.abs(t-l)*.01;r<f.price&&(f={x:t,price:r})}),u.push({x:l,y:e}),f.x!==l&&u.push({x:f.x,y:e}),l=f.x}),l===d)return u.push({x:l,y:r}),P(u);let f=u[u.length-1],p=r+Math.sign(f.y-r)*20;return u.push({x:l,y:p}),u.push({x:d,y:p}),u.push({x:d,y:r}),P(u)}function it(e,t,n,r,i=[],a){let o=e.x+e.width/2,s=e=>M(e,r)*m+i.reduce((t,n)=>t+N(e,n),0),c=e=>[{x:e,y:t},{x:e,y:n}],l=Math.max(0,e.width/2-10),u=[o];for(let e=1;e*10<=l;e++)u.push(o+e*10,o-e*10);let d=e=>s(c(e))*m+i.filter(t=>b(c(e),t)).length,f=u.reduce((e,t)=>d(t)<d(e)?t:e,o),p=Math.abs(t-e.y)<=Math.abs(t-(e.y+e.height))?-1:1,h=e=>{let r=t+p*Math.min(20,Math.abs(n-t));return r===t?[{x:e,y:t}]:[{x:e,y:t},{x:e,y:r}]};if(d(f)===0)return h(f);let g=s(c(o));if(g===0)return h(o);let _=t+p*20,v=e=>!a||e>=a.x&&e<=a.x+a.width,y={price:g,x:o};for(let e=1;e<=80&&y.price>0;e++)for(let r of[1,-1]){let i=o+r*e*10;if(!v(i))continue;let a=s([{x:o,y:t},{x:o,y:_},{x:i,y:_},{x:i,y:n}]);a<y.price&&(y={price:a,x:i})}return y.x===o?h(o):[{x:o,y:t},{x:o,y:_},{x:y.x,y:_},{x:y.x,y:n}]}function at(e,t,n=[],r=0,i=[],a=[],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=!0,l=0,u=1,d=!1){let f={x:e.x,y:e.y,width:e.width,height:e.height},p={x:t.x,y:t.y,width:t.width,height:t.height},g=v(e),_=v(t),y=[g,_].filter(e=>!!e),x=n.filter(e=>(e.x!==f.x||e.y!==f.y)&&(e.x!==p.x||e.y!==p.y)&&!y.some(t=>e.x===t.x&&e.y===t.y)),S=e=>M(e,x)*m+a.reduce((t,n)=>t+N(e,n),0),C=e=>e.reduce((t,n,r)=>r===0?0:t+Math.abs(n.x-e[r-1].x)+Math.abs(n.y-e[r-1].y),0),w=e=>c?S(e)*16e3+C(e):S(e),T=g?s.get(o.get(g.id)??``):void 0,E=(n,s)=>{let d=n?e.y:e.y+e.height,m=n?t.y+t.height:t.y,h=g&&_&&g!==_?n?{low:_.y+_.height,high:g.y}:{low:g.y+g.height,high:_.y}:{low:Math.min(d,m),high:Math.max(d,m)},v=Math.max(0,h.high-h.low),y=Math.min(20,v/(u+1)),C=(h.low+h.high)/2+(l-(u-1)/2)*y,E=Math.max(0,(l-(u-1)/2)*16+(u-1)*16/2),D=n?m+20+E:m-20-E,O=n?d-20:d+20,k=h.high-h.low,A={channel:C,target:D,source:O,third:h.low+k/3,far:h.low+k*2/3}[s],j={from:Math.max(f.x,p.x)+10,to:Math.min(f.x+f.width,p.x+p.width)-10};if(j.to>=j.from){let e=(j.from+j.to)/2,t=[e];for(let n=1;n*10<=(j.to-j.from)/2;n++)t.push(e+n*10,e-n*10);let n=t.map(e=>[{x:e,y:d},{x:e,y:m}]).find(e=>S(e)===0&&!a.some(t=>b(e,t)));if(n)return n}let M=ot(it(f,d,A,x,a,T),it(p,m,A,x,a,T).reverse(),A);if(!g||!_||g===_)return M;let N=Math.min(g.y,_.y),F=Math.max(g.y+g.height,_.y+_.height);if(!i.some(e=>e!==g&&e!==_&&e.y>N&&e.y+e.height<F)&&S(M)===0)return M;let I=(l-(u-1)/2)*y,L=(n?g.y-30:g.y+g.height+30)+I,R=(n?_.y+_.height+30:_.y-30)+I,z={left:Math.min(g.x,_.x),right:Math.max(g.x+g.width,_.x+_.width)},ee=i.filter(e=>e.y+e.height>Math.min(g.y,_.y)&&e.y<Math.max(g.y+g.height,_.y+_.height)&&e.x+e.width>z.left&&e.x<z.right&&(o.size===0||o.get(e.id)===o.get(g.id))),B=60+r%4*20,te=Math.max(...ee.map(e=>e.x+e.width),g.x+g.width,_.x+_.width)+B,ne=Math.min(...ee.map(e=>e.x),g.x,_.x)-B,re=T?Math.min(te,T.x+T.width-20):te,V=T?Math.max(ne,T.x+20):ne,ie=it(f,d,L,x,a,T),H=it(p,m,R,x,a,T).reverse(),U=e=>P([...ie,{x:ie[ie.length-1].x,y:L},{x:e,y:L},{x:e,y:R},{x:H[0].x,y:R},...H]),W=rt(f,d,p,m,nt(g,_,ee,!n),x,a,T),ae=Ke({x:f.x+f.width/2,y:d},{x:p.x+p.width/2,y:m},x,a,20,void 0,1),G=r%2==0?[U(re),U(V)]:[U(V),U(re)];return(c?[M,...ae?[ae]:[],...W?[W]:[],...G]:[...G,M,...W?[W]:[],...ae?[ae]:[]]).reduce((e,t)=>w(t)<w(e)?t:e)},D=e=>a.filter(t=>b(e,t)).length,O=e=>w(e)+D(e)*.5,k=d?`target`:`channel`,A=E(e.y>t.y,k);if(!g||!_||g===_)return h(A);let j=E(e.y<=t.y,k),F=O(j)<O(A)?j:A;if(D(F)===0)return h(F);let I=Ze.filter(e=>e!==k).flatMap(n=>[E(e.y>t.y,n),E(e.y<=t.y,n)]);return h(I.reduce((e,t)=>O(t)<O(e)?t:e,F))}function ot(e,t,n){let r=[...e];return r[r.length-1].y!==n&&r.push({x:r[r.length-1].x,y:n}),t[0].x!==r[r.length-1].x&&r.push({x:t[0].x,y:n}),t.forEach(e=>r.push(e)),P(r)}function st(e,t,n){if(t.length<2||e.length===0)return null;let r=Qe(t,e),i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return t.forEach(e=>{let t=r.get(e.id)??e.id;a.has(t)||a.set(t,[]),a.get(t).push(e)}),a.forEach((t,a)=>{let o=[...t].sort((e,t)=>e.y-t.y);if(o.length<2)return;let s=o.map(e=>e.id),c=e.filter(e=>{let t=v(e.source),n=v(e.target);return!!t&&!!n&&t.id!==n.id&&r.get(t.id)===a&&r.get(n.id)===a});if(c.length===0)return;let l=new Map(Je(s,c.map(e=>({id:e.id,from:v(e.source).id,to:v(e.target).id}))).map(e=>[e.id,e])),u=/* @__PURE__ */ new Map;for(let e=0;e+1<o.length;e++)u.set(`${o[e].id}|${o[e+1].id}`,{low:o[e].y+o[e].height,high:o[e+1].y});let d={gapOf:e=>u.get(e),leftAt:Math.min(...o.map(e=>e.x)),rightAt:Math.max(...o.map(e=>e.x+e.width))},f=e=>({x:e.x,y:e.y,width:e.width,height:e.height}),p=c.map(e=>({connection:e,plan:l.get(e.id),source:f(e.source),target:f(e.target),sourcePool:f(v(e.source)),targetPool:f(v(e.target))}));Xe(p,d,n.filter(e=>!p.some(t=>t.source.x===e.x&&t.source.y===e.y||t.target.x===e.x&&t.target.y===e.y))).forEach((e,t)=>i.set(t,e))}),e.every(e=>i.has(e.id))?i:null}function ct(e,t=[],n=[],i=!0,a=!1,o=!1){let s=t.filter(e=>e.type!==`bpmn:Lane`&&e.type!==`bpmn:Participant`&&!D.has(e.type??``)&&e.width>0&&e.height>0).map(e=>({x:e.x,y:e.y,width:e.width,height:e.height})),c=t.filter(e=>e.type===`bpmn:Participant`),l=e.filter(e=>_(e)&&e.source&&e.target),u=e=>{let t=v(e.source),n=v(e.target);if(!t||!n)return{low:0,high:0};let r=t.y+t.height/2,i=n.y+n.height/2;return{low:Math.min(r,i),high:Math.max(r,i)}},d=new Map([...l].sort((e,t)=>{let n=u(e),r=u(t);return r.high-r.low-(n.high-n.low)||n.low-r.low||(e.id<t.id?-1:1)}).map((e,t)=>[e.id,l.length-t])),{lane:f,width:p}=et(l),m=Qe(c,l),h=/* @__PURE__ */ new Map;c.forEach(e=>{let t=m.get(e.id);if(!t)return;let n=h.get(t),i={x:e.x-100,y:e.y,width:e.width+200,height:e.height};h.set(t,n?r(n,i):i)});let g=a?st(l,c,s):null;if(g)return l.map(e=>({connection:e,waypoints:g.get(e.id)}));let y=[...n];return l.map(e=>{let t=at(e.source,e.target,s,d.get(e.id)??0,c,y,m,h,i,f.get(e.id)??0,p.get($e(e))??1,o);return y.push(t),{connection:e,waypoints:t}})}function lt(e){let t=e.waypoints,n=[];for(let r=0;r+1<t.length;r++){let i=t[r],a=t[r+1],o=r===0||r+2===t.length;i.y===a.y&&i.x!==a.x?n.push({route:e,index:r,axis:`y`,at:i.y,from:Math.min(i.x,a.x),to:Math.max(i.x,a.x),anchored:o}):i.x===a.x&&i.y!==a.y&&n.push({route:e,index:r,axis:`x`,at:i.x,from:Math.min(i.y,a.y),to:Math.max(i.y,a.y),anchored:o})}return n}function ut(e,t){let n=/* @__PURE__ */ new Map;e.forEach(e=>n.set(e,new te(e.at,e.anchored?1e6:1)));let r=[],i=[...e].sort((e,t)=>e.at-t.at||e.from-t.from);for(let e=0;e<i.length;e++)for(let a=e+1;a<i.length;a++){let o=i[e],s=i[a];if(s.at-o.at>t)break;o.route!==s.route&&(Math.min(o.to,s.to)-Math.max(o.from,s.from)<=0||r.push(new z(n.get(o),n.get(s),t)))}if(r.length===0)return/* @__PURE__ */ new Map;new B(e.map(e=>n.get(e)),r).solve();let a=/* @__PURE__ */ new Map;return e.forEach(e=>{let t=n.get(e).position();Math.abs(t-e.at)>=.5&&a.set(e,t)}),a}function dt(e,t=16){let n=e.flatMap(lt),r=[];return[`x`,`y`].forEach(e=>{let i=n.filter(t=>t.axis===e);i.length<2||ut(i,t).forEach((t,n)=>r.push({route:n.route,index:n.index,axis:e,at:t,step:Math.abs(t-n.at)}))}),r.sort((e,t)=>e.step-t.step)}function ft(e){let t=e.route.waypoints,n=e.axis===`y`?`y`:`x`,r=t[e.index-1],i=t[e.index+2],a=r?r[n]:t[e.index][n],o=i?i[n]:t[e.index+1][n];return t[e.index].x<=t[e.index+1].x&&t[e.index].y<=t[e.index+1].y?{head:a,foot:o}:{head:o,foot:a}}const pt={comparisons:0};function mt(e){let t=e.map((e,t)=>t),n=e=>{let n=e;for(;t[n]!==n;)n=t[n];return n},r=e=>e===`x`?0:1,i=e.map((e,t)=>t).sort((t,n)=>r(e[t].axis)-r(e[n].axis)||e[t].at-e[n].at||e[t].from-e[n].from);for(let r=0;r<i.length;r++){let a=i[r],o=e[a];for(let s=r+1;s<i.length;s++){let r=i[s],c=e[r];if(pt.comparisons+=1,o.axis!==c.axis||c.at-o.at>12)break;if(o.route===c.route||Math.min(o.to,c.to)-Math.max(o.from,c.from)<40)continue;let l=n(a),u=n(r);l!==u&&(t[l]=u)}}let a=/* @__PURE__ */ new Map;return e.forEach((e,t)=>{let r=n(t);a.has(r)||a.set(r,[]),a.get(r).push(e)}),[...a.values()].filter(e=>e.length>1)}function ht(e,t=16){let n=e.flatMap(lt),r=[];return mt(n).forEach(e=>{let n=e.reduce((e,t)=>e+t.at,0)/e.length;[...e].sort((e,t)=>{let n=ft(e),r=ft(t);return n.head-r.head||n.foot-r.foot||e.at-t.at||e.index-t.index}).forEach((i,a)=>{let o=n+(a-(e.length-1)/2)*t;Math.abs(o-i.at)<.5||r.push({route:i.route,index:i.index,axis:i.axis,at:o,step:Math.abs(o-i.at)})})}),r.sort((e,t)=>e.step-t.step)}function gt(e,t){let n=[];return e.forEach(e=>{let r=t(e);lt(e).forEach(t=>{let i=t.axis===`y`,a;r.forEach(e=>{let n=i?e.x:e.y,r=i?e.x+e.width:e.y+e.height;Math.min(t.to,r)-Math.max(t.from,n)<40||(i?[e.y,e.y+e.height]:[e.x,e.x+e.width]).forEach((e,n)=>{if(Math.abs(e-t.at)>6)return;let r=n===0?e-12:e+12;(a===void 0||Math.abs(r-t.at)<Math.abs(a-t.at))&&(a=r)})}),a!==void 0&&n.push({route:e,index:t.index,axis:t.axis,at:a,step:Math.abs(a-t.at)})})}),n.sort((e,t)=>e.step-t.step)}function _t(e,t){let n=[];return e.forEach(e=>{let r=t(e);lt(e).forEach(t=>{if(t.anchored)return;let i=t.axis===`y`,a=r.filter(e=>{let n=i?e.x:e.y,r=i?e.x+e.width:e.y+e.height;return Math.min(t.to,r)-Math.max(t.from,n)>=40});if(!a.some(e=>(i?[e.y,e.y+e.height]:[e.x,e.x+e.width]).some(e=>Math.abs(e-t.at)<=6)))return;let o=a.map(e=>i?[e.y,e.y+e.height]:[e.x,e.x+e.width]).sort((e,t)=>e[0]-t[0]),s=[];o.forEach(e=>{let t=s[s.length-1];t&&e[0]<=t[1]?t[1]=Math.max(t[1],e[1]):s.push([e[0],e[1]])});let c=[];for(let e=0;e+1<s.length;e++)c.push([s[e][1],s[e+1][0]]);let l=c.filter(e=>e[1]-e[0]>=24).map(e=>(e[0]+e[1])/2).reduce((e,n)=>e===void 0||Math.abs(n-t.at)<Math.abs(e-t.at)?n:e,void 0);l===void 0||Math.abs(l-t.at)<.5||n.push({route:e,index:t.index,axis:t.axis,at:l,step:Math.abs(l-t.at)})})}),n.sort((e,t)=>e.step-t.step)}const vt=[.5,.34,.66,.42,.58],yt=3e3;function bt(e){let t=/* @__PURE__ */ new Map,n=e=>{let n=t.get(e.id);if(n)return n;let r={x:e.x,y:e.y,width:e.width,height:e.height};return t.set(e.id,r),r};e.moves.forEach(({elements:e,dx:t,dy:r})=>e.forEach(e=>{let i=n(e);i.x+=t,i.y+=r})),e.resizes.forEach(({element:e,x:n,y:r,width:i,height:a})=>{t.set(e.id,{x:n,y:r,width:i,height:a})});let r=e=>{let t=Math.round(e/40)*40;return Math.abs(t-e)<=4?t:e};e.routes.forEach(e=>{let t=e.connection.source?n(e.connection.source):void 0,a=e.connection.target?n(e.connection.target):void 0,o=He(e.waypoints,t,a,[]),s=o.map(e=>({x:r(e.x),y:r(e.y)}));e.waypoints=i(s)&&O(s)<=O(o)&&(!t||J(s[0],t))&&(!a||J(s[s.length-1],a))?s:o})}function Y(e,t){let n=[],r=/* @__PURE__ */ new Set,i=e=>{r.has(e.id)||(r.add(e.id),n.push(e))},a=e=>{i(e),(e.attachers||[]).forEach(i),(e.children||[]).forEach(a)};(e.children||[]).forEach(a);let o=/* @__PURE__ */ new Map,s=new Map(t.resizes.map(e=>[e.element.id,e])),c=()=>{o.clear(),t.moves.forEach(e=>e.elements.forEach(t=>{let n=o.get(t.id)??{x:0,y:0};o.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})})),s=new Map(t.resizes.map(e=>[e.element.id,e]))};return c(),{every:n,rectOf:e=>{let t=s.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=o.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}},driftOf:e=>{let t=o.get(e.id);if(t)return t;let n=s.get(e.id);return n?{x:n.x-e.x,y:n.y-e.y}:{x:0,y:0}},movedBy:e=>o.get(e.id),refresh:c}}function xt(e,t,n,r=!1){let i=(e.children||[]).filter(e=>e.type===`bpmn:Participant`);if(i.length<2)return;let a=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=a.get(t.id)??{x:0,y:0};a.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let o=new Map(t.resizes.map(e=>[e.element.id,e])),s=e=>{let t=o.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=a.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}},c=e=>[e,...(e.children||[]).flatMap(c)],l=(e.children||[]).filter(e=>x.has(e.type??``)),u=/* @__PURE__ */ new Map;l.forEach(e=>{let t=[...e.outgoing||[],...e.incoming||[]].map(t=>{let n=t;return n.source?.id===e.id?n.target:n.source}).filter(e=>!!e).map(e=>i.find(t=>c(t).some(t=>t.id===e.id))).find(Boolean);t&&u.set(e.id,t.id)});let d=tt(e),f=Be(i,r),p=[...i].sort((e,t)=>(f.get(e.id)??0)-(f.get(t.id)??0)),m=ze(i),h=wt(p,m).map(e=>{let t=Ct(e,m,s,n,d);return e.length>1&&t.forEach((e,n)=>t.set(n,{x:e.x+100,y:e.y})),{group:e,inside:t,width:Math.max(...e.map(e=>t.get(e.id).x+s(e).width))+(e.length>1?100:0),height:Math.max(...e.map(e=>t.get(e.id).y+s(e).height))}}),g=/* @__PURE__ */ new Map,_=Math.max(...h.map(e=>e.height)),v=[];h.slice().sort((e,t)=>t.height-e.height||t.width-e.width).forEach(e=>{let t=v.find(t=>t.used+e.height<=_+1);if(!t){let e=v[v.length-1];t={left:e?e.left+e.width+60:n.marginX,used:0,width:0},v.push(t)}let r=n.marginY+t.used;e.group.forEach(n=>{let i=e.inside.get(n.id);g.set(n.id,{x:t.left+i.x,y:r+i.y})}),t.used+=e.height+60,t.width=Math.max(t.width,e.width)}),p.forEach(e=>{let n=s(e),r=g.get(e.id),i=r.x-n.x,a=r.y-n.y;if(Math.abs(i)<.5&&Math.abs(a)<.5)return;let d=[...c(e),...l.filter(t=>u.get(t.id)===e.id)],f=new Set(d.map(e=>e.id));d.forEach(e=>{let n=o.get(e.id);n?(n.x+=i,n.y+=a):w(e)||t.moves.push({elements:[e],dx:i,dy:a})}),t.routes.forEach(e=>{f.has(e.connection.source?.id??``)&&f.has(e.connection.target?.id??``)&&(e.waypoints=e.waypoints.map(e=>({x:e.x+i,y:e.y+a})))})})}function St(e,t){let n=(e.children||[]).filter(e=>e.type===`bpmn:Participant`);if(n.length<2)return;let r=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=r.get(t.id)??{x:0,y:0};r.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let i=new Map(t.resizes.map(e=>[e.element.id,e])),a=e=>{let t=i.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=r.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}},o=e=>[e,...(e.children||[]).flatMap(o)],s=/* @__PURE__ */ new Map;n.forEach(e=>o(e).forEach(t=>s.set(t.id,e.id)));let c=[];if(n.flatMap(o).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;if(!_(t)||!t.source||!t.target)return;let n=s.get(t.source.id),r=s.get(t.target.id);if(!n||!r||n===r)return;let i=a(t.source),o=a(t.target);c.push({from:n,to:r,gap:o.x+o.width/2-(i.x+i.width/2)})})),c.length===0)return;let l=new Map(n.map(e=>[e.id,0])),u=[...n].sort((e,t)=>e.id<t.id?-1:1);for(let e=0;e<12;e++){let e=!1;if(u.forEach(t=>{let n=[];if(c.forEach(({from:e,to:r,gap:i})=>{e===t.id?n.push(l.get(r)+i):r===t.id&&n.push(l.get(e)-i)}),n.length===0)return;n.sort((e,t)=>e-t);let r=Math.round(n[Math.floor((n.length-1)/2)]);r!==l.get(t.id)&&(l.set(t.id,r),e=!0)}),!e)break}let d=new Map(n.map(e=>[e.id,e.id])),f=e=>{let t=e;for(;d.get(t)!==t;)t=d.get(t);return t};c.forEach(({from:e,to:t})=>{let n=f(e),r=f(t);n!==r&&d.set(n,r)});let p=/* @__PURE__ */ new Map;n.forEach(e=>{let t=f(e.id),n=p.get(t),r=l.get(e.id);(n===void 0||r<n)&&p.set(t,r)}),n.forEach(e=>{let n=l.get(e.id)-(p.get(f(e.id))??0);if(n<1)return;let r=o(e).filter(t=>t.id!==e.id),a=new Set(r.map(e=>e.id)),s=(e.children||[]).filter(e=>e.type===`bpmn:Lane`),c=s.length===1?s[0].id:void 0;r.forEach(e=>{let r=i.get(e.id);r?e.id===c?r.width+=n:r.x+=n:w(e)||t.moves.push({elements:[e],dx:n,dy:0})}),t.routes.forEach(e=>{a.has(e.connection.source?.id??``)&&a.has(e.connection.target?.id??``)&&(e.waypoints=e.waypoints.map(e=>({x:e.x+n,y:e.y})))});let u=i.get(e.id);u&&(u.width+=n)})}function Ct(e,t,n,r,i){let a=/* @__PURE__ */ new Map;if(e.length===1)return a.set(e[0].id,{x:0,y:0}),a;let o=/* @__PURE__ */ new Map;e.forEach(e=>o.set(e.id,[])),t.forEach((e,t)=>{let[n,r]=t.split(`|`);o.has(n)&&o.has(r)&&(o.get(n).push(r),o.get(r).push(n))});let s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set,l=0;e.forEach(e=>{if(c.has(e.id))return;let t=[e.id];for(c.add(e.id);t.length>0;){let e=t.shift();s.set(e,l),l+=1,(o.get(e)??[]).forEach(e=>{c.has(e)||(c.add(e),t.push(e))})}});let u=0,d=e.slice().sort((e,t)=>(s.get(e.id)??0)-(s.get(t.id)??0));return d.forEach((e,t)=>{a.set(e.id,{x:0,y:u});let r=d[t+1],o=r?i.get(`${e.id}|${r.id}`)??i.get(`${r.id}|${e.id}`)??0:0;u+=n(e).height+Math.max(60,(o+1)*20)}),a}function wt(e,t){let n=new Map(e.map(e=>[e.id,e.id])),r=e=>{let t=e;for(;n.get(t)!==t;)t=n.get(t);return t};t.forEach((e,t)=>{let[i,a]=t.split(`|`);if(!n.has(i)||!n.has(a))return;let o=r(i),s=r(a);o!==s&&n.set(o,s)});let i=/* @__PURE__ */ new Map;return e.forEach(e=>{let t=r(e.id);i.has(t)||i.set(t,[]),i.get(t).push(e)}),[...i.values()]}function Tt(e,t,n,r=[]){let i={x:e.x+e.width/2,y:e.y+e.height/2},a={x:t.x+t.width/2,y:t.y+t.height/2},o=(e,t)=>t>e.x+e.width/2?e.x+e.width:e.x,s=(e,t)=>t>e.y+e.height/2?e.y+e.height:e.y,c=[];vt.forEach(n=>{let r=i.y+(a.y-i.y)*n,l=i.x+(a.x-i.x)*n;c.push({path:[{x:i.x,y:s(e,a.y)},{x:i.x,y:r},{x:a.x,y:r},{x:a.x,y:s(t,i.y)}],sideways:0}),c.push({path:[{x:o(e,a.x),y:i.y},{x:l,y:i.y},{x:l,y:a.y},{x:o(t,i.x),y:a.y}],sideways:1})}),c.push({path:[{x:i.x,y:s(e,a.y)},{x:i.x,y:a.y},{x:o(t,i.x),y:a.y}],sideways:0}),c.push({path:[{x:o(e,a.x),y:i.y},{x:a.x,y:i.y},{x:a.x,y:s(t,i.y)}],sideways:1}),Math.abs(i.y-a.y)<1&&c.push({path:[{x:o(e,a.x),y:i.y},{x:o(t,i.x),y:a.y}],sideways:0}),Math.abs(i.x-a.x)<1&&c.push({path:[{x:i.x,y:s(e,a.y)},{x:a.x,y:s(t,i.y)}],sideways:0});let l=(e,t)=>t.x>e.x+.5&&t.x<e.x+e.width-.5&&t.y>e.y+.5&&t.y<e.y+e.height-.5,u=P(c[c.length-2].path),d=1/0;return c.forEach(({path:i,sideways:a})=>{let o=P(i),s=r.reduce((e,t)=>e+N(o,t),0),c=r.filter(e=>b(o,e)).length,f=(o.length>1&&l(e,o[1])?1:0)+(o.length>1&&l(t,o[o.length-2])?1:0),p=(M(o,n)+f)*10+s*5+c*20+a+o.length/100;p<d&&(d=p,u=o)}),u}function Et(e,t,n){let{every:r,rectOf:i}=Y(e,t),a=r.filter(e=>x.has(e.type??``)&&e.type!==`bpmn:Group`);new Set(a.map(e=>e.id)),Dt(a.filter(e=>e.type===`bpmn:TextAnnotation`&&[...e.outgoing||[],...e.incoming||[]].length===0),r,i,t,n)}function Dt(e,t,n,r,i){if(e.length===0)return;let a=t.filter(t=>!e.includes(t)&&t.type!==`bpmn:Lane`&&t.width>0&&t.height>0);if(a.length===0)return;let o=a.map(n),s=Math.min(...o.map(e=>e.x)),c=Math.max(...o.map(e=>e.x+e.width)),l=Math.min(...o.map(e=>e.y)),u=Math.max(...o.map(e=>e.y+e.height)),d=e.map(n),f={width:Math.max(...d.map(e=>e.width)),height:d.reduce((e,t)=>e+t.height,0)+i.nodesep*(e.length-1)},p={width:d.reduce((e,t)=>e+t.width,0)+i.marginX*(e.length-1),height:Math.max(...d.map(e=>e.height))},m=(e,t)=>e*t,h=m(c-s+i.marginX*2+f.width,u-l)<=m(Math.max(c-s,p.width),u-l+i.marginY*2+p.height),g=h?l:s;[...e].sort((e,t)=>n(e).y-n(t).y||n(e).x-n(t).x).forEach(e=>{let t=n(e),a=h?{x:c+i.marginX*2,y:g}:{x:g,y:u+i.marginY*2};g+=h?t.height+i.nodesep:t.width+i.marginX;let o=a.x-t.x,s=a.y-t.y;Math.abs(o)<.5&&Math.abs(s)<.5||r.moves.push({elements:[e],dx:o,dy:s})})}function Ot(e,t,n,i=!1,o=!0){let{every:s,rectOf:c}=Y(e,t),u=s.filter(e=>x.has(e.type??``)&&e.type!==`bpmn:Group`);if(u.length===0)return;new Set(u.map(e=>e.id));let d=u.filter(e=>e.type===`bpmn:TextAnnotation`&&[...e.outgoing||[],...e.incoming||[]].length===0),f=u.filter(e=>!d.includes(e));if(f.length===0)return;let p=new Set(f.map(e=>e.id)),m=s.filter(e=>!p.has(e.id)&&e.type!==`bpmn:Lane`&&e.width>0&&e.height>0),h=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},g=new Map(t.routes.map(e=>[e.connection.id,e.waypoints])),_=(e,t)=>{if(!e.source||!e.target)return c(e);let n=g.get(e.id)??e.waypoints??[];return n.length<2?c(e):zt(n,t,!1,[],[]).at},v=e=>[...e.outgoing||[],...e.incoming||[]].some(t=>{let n=t,r=n.source?.id===e.id?n.target:n.source;return!!r?.source&&!!r?.target}),y=m.map(c),b=[],w=[],T=/* @__PURE__ */ new Map,E=/* @__PURE__ */ new Map,D=e=>e.label?r(c(e),c(e.label)):c(e);f.filter(e=>!i||v(e)).forEach(e=>{let r=c(e),o=D(e),u=r.x-o.x,d=r.y-o.y,f=e=>({x:e.x-u,y:e.y-d,width:o.width,height:o.height}),v=h(e),x=m.filter(e=>!v.has(e.id)&&e.type!==`bpmn:Participant`&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:SubProcess`).map(c),O=[...(e.outgoing||[]).map(e=>e.target),...(e.incoming||[]).map(e=>e.source)].filter(e=>!!e&&!p.has(e.id)),k=e=>e.type===`bpmn:Participant`||e.type===`bpmn:Lane`||e.type===`bpmn:SubProcess`,A=O.filter(e=>!k(e)),j=A.length?_(A[0],r):O.length?_(O[0],r):r,P=n.nodesep,F=e.parent;for(;F&&F.type!==`bpmn:Participant`&&F.type!==`bpmn:SubProcess`;)F=F.parent;let I=F?T.get(F.id)??c(F):void 0,L=s.filter(e=>(e.type===`bpmn:Participant`||e.type===`bpmn:SubProcess`)&&!v.has(e.id)&&e.id!==F?.id).map(c),R=s.filter(e=>e.type===`bpmn:Lane`&&e.id!==F?.id).map(c),z=e=>{if(!I||l(I,e))return I??e;let t=Math.max(I.x+I.width,e.x+e.width+n.marginX),r=Math.max(I.y+I.height,e.y+e.height+n.marginY),i=Math.min(I.x,e.x-n.marginX),a=Math.min(I.y,e.y-n.marginY);return{x:i,y:a,width:t-i,height:r-a}},ee=e=>{if(!I)return!1;let t=z(e);if(t===I)return!1;let n=[];return t.x<I.x&&n.push({x:t.x,y:t.y,width:I.x-t.x,height:t.height}),t.x+t.width>I.x+I.width&&n.push({x:I.x+I.width,y:t.y,width:t.x+t.width-(I.x+I.width),height:t.height}),t.y<I.y&&n.push({x:t.x,y:t.y,width:t.width,height:I.y-t.y}),t.y+t.height>I.y+I.height&&n.push({x:t.x,y:I.y+I.height,width:t.width,height:t.y+t.height-(I.y+I.height)}),n.some(e=>L.some(t=>S(e,t)))},B=n.nodesep*6,te=e=>{if(!I)return!1;let t=Math.max(0,I.x-e.x),n=Math.max(0,e.x+e.width-(I.x+I.width)),r=Math.max(0,I.y-e.y),i=Math.max(0,e.y+e.height-(I.y+I.height));return t>B||n>B||r>B||i>B},ne=e=>R.some(t=>C(e,t))||L.some(t=>!a(e,t))?!1:A.length>1||L.length>5?!I||l(I,e):!te(e)&&!ee(e),re=e=>(!I||l(I,e))&&ne(e),V=A.length>1?x:[...x,...L],ie=e=>t.routes.reduce((t,n)=>t+M(n.waypoints,[e]),0),H=(n,r=1/0)=>{if(!ne(n)||x.some(e=>S(n,e))||b.some(e=>S(n,e)))return 1/0;let i=f(n),a=+!ne(i)+x.filter(e=>S(i,e)).length+w.filter(e=>S(i,e)).length,o=Math.abs(n.x+n.width/2-(j.x+j.width/2))+Math.abs(n.y+n.height/2-(j.y+j.height/2)),s=a*800+o*80;if(s>=r)return s;if(!A.length)return ie(n)*yt+s;let l=t.routes.filter(t=>t.connection.source?.id!==e.id&&t.connection.target?.id!==e.id).map(e=>e.waypoints);return A.reduce((e,t)=>{let r=g.get(t.id)??t.waypoints,i=t.source&&t.target&&r&&r.length>=2?zt(r,n,!1,V,l).waypoints:Tt(c(t),n,V,l);return e+M(i,V)+l.reduce((e,t)=>e+N(i,t),0)},0)*yt+ie(n)*yt+s},U=r,W=H(r);for(let e=1;e<=100&&W>0;e++){let t=j.y+j.height+P*e,n=j.y-P*e-r.height,i=j.x+j.width+P*e,a=j.x-P*e-r.width,o=j.x+j.width/2-r.width/2,s=j.y+j.height/2-r.height/2;for(let e of[{x:o,y:t,aside:0},{x:o,y:n,aside:0},{x:i,y:s,aside:1},{x:a,y:s,aside:1},{x:i,y:t,aside:1},{x:a,y:t,aside:1},{x:i,y:n,aside:1},{x:a,y:n,aside:1}]){let t={x:e.x,y:e.y,width:r.width,height:r.height},n=H(t,W)+e.aside*200;n<W&&(W=n,U=t)}}if(W===1/0){let e=j.y+j.height+P;for(let t=0;t<200;t++){let t={x:j.x+j.width/2-r.width/2,y:e,width:r.width,height:r.height};if(H(t)<1/0){U=t;break}e+=P}}if(U!==r&&t.moves.push({elements:[e],dx:U.x-r.x,dy:U.y-r.y}),[...e.outgoing||[],...e.incoming||[]].forEach(n=>{let r=n,i=r.source?.id===e.id?r.target:r.source;if(!i)return;let a=_(i,U),o=r.source?.id===e.id,s=t.routes.filter(e=>e.connection.id!==r.id).map(e=>e.waypoints),c=Tt(o?U:a,o?a:U,V,s),l=t.routes.find(e=>e.connection.id===r.id);l?l.waypoints=c:t.routes.push({connection:r,waypoints:c})}),y.push(U),b.push(U),w.push(f(U)),F&&!i&&!re(U)){E.has(F.id)||E.set(F.id,{...c(F)});let e=T.get(F.id)??{...c(F)},t=Math.max(e.x+e.width,U.x+U.width+n.marginX),r=Math.max(e.y+e.height,U.y+U.height+n.marginY);e.x=Math.min(e.x,U.x-n.marginX),e.y=Math.min(e.y,U.y-n.marginY),e.width=t-e.x,e.height=r-e.y,T.set(F.id,e)}});let O=new Map(t.resizes.map(e=>[e.element.id,e])),k=(e,n)=>{let r=O.get(e.id);r?(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height):t.resizes.push({element:e,x:n.x,y:n.y,width:n.width,height:n.height})};T.forEach((e,t)=>{let n=s.find(e=>e.id===t);if(!n)return;k(n,e);let r=E.get(t);if(!r)return;let i=r.x-e.x,a=r.y-e.y,l=e.x+e.width-(r.x+r.width),u=e.y+e.height-(r.y+r.height);if(i<=0&&a<=0&&l<=0&&u<=0)return;let d=s.filter(e=>e.type===`bpmn:Lane`&&e.parent?.id===t);o&&d.length===1&&d.forEach(e=>{let t=O.get(e.id)??c(e);k(e,{x:t.x-i,y:t.y-a,width:t.width+i+l,height:t.height+a+u})})})}function kt(e,t,n){let{every:r,rectOf:i}=Y(e,t),a=r.filter(e=>e.type===`bpmn:Group`&&e.width>0&&e.height>0);if(a.length===0)return;let o=r.filter(e=>e.type!==`bpmn:Group`&&!w(e)&&!j(e)&&e.width>0&&e.height>0),s=new Map(t.resizes.map(e=>[e.element.id,e])),c=n.nodesep/2;a.forEach(e=>{let n=o.filter(t=>t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height);if(n.length===0)return;let r=n.map(i),a=Math.min(...r.map(e=>e.x))-c,l=Math.min(...r.map(e=>e.y))-c,u=Math.max(...r.map(e=>e.x+e.width))+c,d=Math.max(...r.map(e=>e.y+e.height))+c,f=i(e);e.label&&t.moves.push({elements:[e.label],dx:a-f.x,dy:l-f.y});let p=s.get(e.id);p?(p.x=a,p.y=l,p.width=u-a,p.height=d-l):t.resizes.push({element:e,x:a,y:l,width:u-a,height:d-l})})}function At(e,t,n){let{every:r,rectOf:i,driftOf:a,movedBy:s}=Y(e,t),c=[...r.filter(e=>e.label&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:Participant`),...t.routes.map(e=>e.connection).filter(e=>e.label)];if(c.sort((e,n)=>{let r=!!t.routes.find(t=>t.connection.id===e.id);return r===!!t.routes.find(e=>e.connection.id===n.id)?0:r?-1:1}),c.length===0)return;let l=r.filter(e=>e.type!==`bpmn:Lane`&&e.width>0&&e.height>0),u=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},d=[],f=e=>{let n=t.routes.find(t=>t.connection.id===e.id)?.waypoints??e.waypoints;if(n&&n.length>1){let e={from:n[0],to:n[1],span:-1};for(let t=0;t+1<n.length;t++){let r=Math.abs(n[t+1].x-n[t].x)+Math.abs(n[t+1].y-n[t].y);r>e.span&&(e={from:n[t],to:n[t+1],span:r})}return{x:(e.from.x+e.to.x)/2,y:(e.from.y+e.to.y)/2,width:0,height:0}}if(e.source&&e.target){let t=i(e.source),n=i(e.target);return{x:(t.x+t.width/2+n.x+n.width/2)/2,y:(t.y+t.height/2+n.y+n.height/2)/2,width:0,height:0}}return i(e)},p=n.nodesep/2;c.forEach(e=>{let n=e.label,r=s(n)??a(e),c={x:n.x+r.x,y:n.y+r.y,width:n.width,height:n.height},m=t.routes.some(t=>t.connection.id===e.id);if(!m){let t=i(e);if(c.x>=t.x-1&&c.y>=t.y-1&&c.x+c.width<=t.x+t.width+1&&c.y+c.height<=t.y+t.height+1)return}let h=/* @__PURE__ */ new Set([e.id,...u(e),...u(e.source),...u(e.target)]);g(e)&&e.host&&h.delete(e.host.id);let _=l.filter(e=>!h.has(e.id)).map(i),v=e=>_.some(t=>S(e,t))||d.some(t=>S(e,t)),y=n=>t.routes.some(t=>t.connection.id!==e.id&&M(t.waypoints,[n])>0);if(!v(c)&&!y(c)&&!(m&&(n=>{let r=t.routes.find(t=>t.connection.id===e.id)?.waypoints??e.waypoints??[];if(r.length<2)return!1;let i=n.x+n.width/2,a=n.y+n.height/2,s=1/0;for(let e=0;e+1<r.length;e++){let t=o({x:i,y:a},r[e],r[e+1]);s=Math.min(s,Math.abs(i-t.x)+Math.abs(a-t.y))}return s>40})(c))){d.push(c);return}if(m){let r=t.routes.find(t=>t.connection.id===e.id)?.waypoints??e.waypoints??[],i=[];for(let e=0;e+1<r.length;e++){let t=r[e],n=r[e+1];if(Math.abs(n.x-t.x)+Math.abs(n.y-t.y)<c.width/2)continue;let a=t.y===n.y;for(let e=1;e<=9;e++){let r=e/10,o={x:t.x+(n.x-t.x)*r,y:t.y+(n.y-t.y)*r};[1,2,3].flatMap(e=>a?[{x:o.x-c.width/2,y:o.y-c.height-4*e},{x:o.x-c.width/2,y:o.y+4*e}]:[{x:o.x+4*e,y:o.y-c.height/2},{x:o.x-c.width-4*e,y:o.y-c.height/2}]).forEach(e=>i.push({x:Math.round(e.x),y:Math.round(e.y),width:c.width,height:c.height}))}}let a=i.find(e=>!v(e)&&!y(e))??i.find(e=>!v(e));if(a){t.moves.push({elements:[n],dx:a.x-c.x,dy:a.y-c.y}),d.push(a);return}}let b=f(e),x=b.x+b.width/2-c.width/2,C=b.y+b.height/2-c.height/2,w=c,T;outer:for(let e=1;e<=8;e++){let t=b.y+b.height+p*e,n=b.y-p*e-c.height,r=b.x+b.width+p*e,i=b.x-p*e-c.width;for(let e of[{x,y:t},{x,y:n},{x:r,y:C},{x:i,y:C},{x:r,y:t},{x:i,y:t},{x:r,y:n},{x:i,y:n}]){let t={x:e.x,y:e.y,width:c.width,height:c.height};if(!v(t)){if(!y(t)){w=t;break outer}T||=t}}}w===c&&T&&(w=T),w!==c&&t.moves.push({elements:[n],dx:w.x-c.x,dy:w.y-c.y}),d.push(w)})}function jt(e,t,n,r=!1){let{every:a,rectOf:o}=Y(e,t),s=a.filter(e=>e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),l=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},u=/* @__PURE__ */ new Set;t.routes.forEach(e=>{let t=e.connection,d=/* @__PURE__ */ new Set([t.source?.id??``,t.target?.id??``,...l(t.source),...l(t.target)]),f=((t.type??``).includes(`Association`)?a.filter(e=>e.type!==`bpmn:Lane`&&e.width>0&&e.height>0):s).filter(e=>!d.has(e.id)).map(o),p=M(e.waypoints,f);if(p===0)return;let m=e.waypoints[0],h=e.waypoints[e.waypoints.length-1],g=f.filter(t=>e.waypoints.some((n,r)=>r+1<e.waypoints.length&&c(n,e.waypoints[r+1],[t])>0));if(g.length===0)return;let _=n.nodesep/2,v=_;if(r)for(let e=0;e<3;e++){let t=Math.round(Math.min(...g.map(e=>e.y),m.y,h.y)-v),n=Math.round(Math.max(...g.map(e=>e.y+e.height),m.y,h.y)+v);if(!u.has(t)&&!u.has(n))break;v=_+(e+1)*2}let y=Math.round(Math.min(...g.map(e=>e.y),m.y,h.y)-v),b=Math.round(Math.max(...g.map(e=>e.y+e.height),m.y,h.y)+v);r&&(u.add(y),u.add(b));let x=a.filter(e=>e.type===`bpmn:Participant`).flatMap(e=>{let t=o(e);return[t.y-v,t.y+t.height+v]}),S=[Math.min(...f.map(e=>e.x))-v,Math.max(...f.map(e=>e.x+e.width))+v],C=[...[y,b,...x].map(e=>[m,{x:m.x,y:e},{x:h.x,y:e},h]),...S.flatMap(e=>[y,b,...x].map(t=>[m,{x:m.x,y:t},{x:e,y:t},{x:e,y:h.y},h])),...Nt(e.waypoints)],w=e.waypoints,T=p,E=O(e.waypoints);C.forEach(e=>{let t=P(e);if(!i(t)||O(t)>E)return;let n=M(t,f);n<T&&(T=n,w=t)}),e.waypoints=w})}function Mt(e){let t=[];for(let n=1;n+2<e;n++)t.push(n);if(t.length<=16)return t;let n=(t.length-1)/15;return Array.from({length:16},(e,r)=>t[Math.round(r*n)])}function Nt(e,t=!1){if(e.length<2)return[e];let n=e[0],r=e[e.length-1],i=Math.abs(e[1].x-n.x)<.5,a=Math.abs(r.x-e[e.length-2].x)<.5,o=[],s=!t;if(s&&i&&a)for(let e=1;e<=7;e++){let t=n.y+(r.y-n.y)*e/8;o.push([n,{x:n.x,y:t},{x:r.x,y:t},r])}else if(s&&!i&&!a)for(let e=1;e<=7;e++){let t=n.x+(r.x-n.x)*e/8;o.push([n,{x:t,y:n.y},{x:t,y:r.y},r])}else s&&i?o.push([n,{x:n.x,y:r.y},r]):s&&o.push([n,{x:r.x,y:n.y},r]);if(s)for(let t of Mt(e.length)){let n=Math.abs(e[t].x-e[t+1].x)<.5;for(let r=1;r<=40;r++)for(let i of[1,-1]){let a=i*r*20,s=(e,r)=>r!==t&&r!==t+1?e:n?{x:e.x+a,y:e.y}:{x:e.x,y:e.y+a};if(o.push(e.map(s)),t+3<e.length){let n=Math.abs(e[t+2].x-e[t+3].x)<.5;o.push(e.map((e,r)=>{let i=s(e,r);return r!==t+2&&r!==t+3?i:n?{x:i.x+a,y:i.y}:{x:i.x,y:i.y+a}}))}}}for(let n=0;t&&n+3<e.length;n++){let[t,r,i,a]=[e[n],e[n+1],e[n+2],e[n+3]],s=Math.abs(t.x-r.x)<.5&&Math.abs(i.x-a.x)<.5,c=Math.abs(t.y-r.y)<.5&&Math.abs(i.y-a.y)<.5;if(!(s?(r.y-t.y)*(a.y-i.y)<0:c&&(r.x-t.x)*(a.x-i.x)<0))continue;let l=s?{x:a.x,y:t.y}:{x:t.x,y:a.y};o.push([...e.slice(0,n+1),l,...e.slice(n+3)])}return o.map(P).filter(e=>e.length>=2)}function Pt(e,t){return new Set(t.filter(t=>M(e,[t.rect])>0).map(e=>e.id))}function Ft(e,t,n){let r=Pt(t,n);return[...Pt(e,n)].some(e=>!r.has(e))}function It(e,t){let{every:n,rectOf:r}=Y(e,t),i=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},a=n.filter(e=>e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=(e,t)=>new Set([e.connection.source?.id,e.connection.target?.id,t.connection.source?.id,t.connection.target?.id].filter(Boolean)).size<4;for(let e=0;e<30;e++){let e=!1;if(t.routes.forEach(n=>{let s=t.routes.filter(e=>e!==n&&!o(n,e)),c=e=>s.reduce((t,n)=>t+N(e,n.waypoints),0)*1e6+e.length*200+f(e),l=c(n.waypoints);if(l<1e6)return;let u=/* @__PURE__ */ new Set([n.connection.source?.id??``,n.connection.target?.id??``,...i(n.connection.source),...i(n.connection.target)]),d=a.filter(e=>!u.has(e.id)).map(e=>({id:e.id,rect:r(e)})),p=d.map(e=>e.rect),m=M(n.waypoints,p),h=n.waypoints,g=l,_=n.waypoints[0],v=n.waypoints[n.waypoints.length-1];Nt(n.waypoints).forEach(e=>{let t=e[0],r=e[e.length-1];if(t.x!==_.x||t.y!==_.y||r.x!==v.x||r.y!==v.y||!e.every((t,n)=>n===0||Math.abs(t.x-e[n-1].x)<.5||Math.abs(t.y-e[n-1].y)<.5)||M(e,p)>m||Ft(e,n.waypoints,d)||O(e)>O(n.waypoints))return;let i=c(e);i<g&&(g=i,h=e)}),h!==n.waypoints&&(n.waypoints=h,e=!0)}),!e)break}}function Lt(e,t,n=!0,r=!1,i=!1){let a=[],o=e=>{a.push(e),(e.attachers||[]).forEach(e=>a.push(e)),(e.children||[]).forEach(o)};(e.children||[]).forEach(o);let s=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=s.get(t.id)??{x:0,y:0};s.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let c=new Map(t.resizes.map(e=>[e.element.id,e])),l=a.map(e=>{let t=c.get(e.id);if(t)return{...e,x:t.x,y:t.y,width:t.width,height:t.height};let n=s.get(e.id)??{x:0,y:0};return{...e,x:e.x+n.x,y:e.y+n.y}}),u=new Map(l.map(e=>[e.id,e]));l.forEach(e=>{e.parent=e.parent?u.get(e.parent.id)??e.parent:e.parent});let d=/* @__PURE__ */ new Map;a.forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;_(t)&&d.set(t.id,t)})),d.size!==0&&ct([...d.values()].map(e=>({...e,source:e.source?u.get(e.source.id)??e.source:e.source,target:e.target?u.get(e.target.id)??e.target:e.target})),l,t.routes.filter(e=>!_(e.connection)).map(e=>e.waypoints),n,r,i).forEach(({connection:e,waypoints:n})=>{let r=d.get(e.id);if(!r)return;let i=t.routes.find(t=>t.connection.id===e.id);i?i.waypoints=n:t.routes.push({connection:r,waypoints:n})})}function Rt(e){if(e.length===0)return[];let t=[],n=f(e);if(n===0)return[e[0]];let r=n/16,i=0,a=0;for(let n=0;n+1<e.length;n++){let o=e[n],s=e[n+1],c=Math.abs(s.x-o.x)+Math.abs(s.y-o.y);for(;c>0&&a<=i+c;){let e=(a-i)/c;t.push({x:o.x+(s.x-o.x)*e,y:o.y+(s.y-o.y)*e}),a+=r}i+=c}return t.push(e[e.length-1]),t}function zt(e,t,n,r,i){let a={x:t.x+t.width/2,y:t.y+t.height/2},o;return Rt(e).forEach(e=>{let s={x:e.x,y:e.y,width:0,height:0},c={x:Math.max(t.x,Math.min(e.x,t.x+t.width)),y:Math.max(t.y,Math.min(e.y,t.y+t.height))},l=n?[c,e]:[e,c],u=Tt(n?t:s,n?s:t,r,i),d=(Math.abs(c.x-e.x)<.5||Math.abs(c.y-e.y)<.5)&&M(l,r)===0&&i.reduce((e,t)=>e+N(l,t),0)<=i.reduce((e,t)=>e+N(u,t),0)?l:u,f=M(d,r),p=f>0?Ke({x:t.x+t.width/2,y:t.y+t.height/2},e,r,i,20):null,m=p&&M(p,r)<f?n?p:[...p].reverse():d,h=Math.abs(e.x-a.x)+Math.abs(e.y-a.y),g=M(m,r)*4e3+i.reduce((e,t)=>e+N(m,t),0)*600+i.filter(e=>b(m,e)).length*1200+h;(!o||g<o.price)&&(o={at:s,waypoints:m,price:g})}),o?{at:o.at,waypoints:o.waypoints}:{at:t,waypoints:[]}}function Bt(e,t){return e.flatMap(e=>{if(!e.elements.some(e=>e.id===t))return[e];let n=e.elements.filter(e=>e.id!==t);return n.length===0?[]:[{...e,elements:n}]})}function Vt(e,t){let{every:n,rectOf:r,refresh:i}=Y(e,t),a=new Map(t.routes.map(e=>[e.connection.id,e.waypoints])),o=n.filter(e=>!x.has(e.type??``)&&!e.source&&!e.target&&e.width>0&&e.height>0),s=n.filter(e=>e.type===`bpmn:TextAnnotation`&&!e.source&&!e.target&&e.width>0&&e.height>0),c=[],u=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},d=e=>e.type===`bpmn:Lane`||e.type===`bpmn:Participant`||e.type===`bpmn:SubProcess`,f=/* @__PURE__ */ new Map;t.routes.forEach(e=>{let t=e.connection;if(t.type!==`bpmn:Association`)return;let n=[t.source,t.target].filter(e=>!!e),r=n.find(e=>!!e.source&&!!e.target),i=n.find(e=>e!==r);r&&i&&a.get(r.id)&&(f.has(i.id)||f.set(i.id,{note:i,links:[]}),f.get(i.id).links.push({op:e,owner:r}))}),f.forEach(({note:e,links:f})=>{let p=r(e),m=u(e),h=n.find(e=>d(e)&&m.has(e.id)),g=/* @__PURE__ */ new Set([e.id,...m,...f.flatMap(({owner:e})=>[e.id,...u(e)])]),_=o.filter(e=>!g.has(e.id)).map(r),v=o.filter(e=>!g.has(e.id)&&!d(e)).flatMap(e=>e.label?[r(e),r(e.label)]:[r(e)]).concat(s.filter(t=>t.id!==e.id).map(r)).concat(c),y=n.filter(e=>d(e)&&!m.has(e.id)).map(r),b=t.routes.filter(e=>!f.some(({op:t})=>t.connection.id===e.connection.id)).map(e=>e.waypoints),x=t=>f.map(({op:n,owner:r})=>({op:n,line:zt(a.get(r.id),t,n.connection.source?.id===e.id,_,b)})),C=e=>e.reduce((e,{line:t})=>e+M(t.waypoints,_),0),w=e=>e.reduce((e,{line:t})=>e+t.waypoints.reduce((e,n,r)=>r===0?0:e+Math.abs(n.x-t.waypoints[r-1].x)+Math.abs(n.y-t.waypoints[r-1].y),0),0),T=e=>C(e)>0||w(e)>260*f.length,E=t.moves.filter(t=>t.elements.some(t=>t.id===e.id)),D={x:p.x-E.reduce((e,t)=>e+t.dx,0),y:p.y-E.reduce((e,t)=>e+t.dy,0),width:p.width,height:p.height},O=p,k=x(p);if(T(k)){let e=k[0].line.at;for(let t=1;t<=8&&T(k);t++){let n=20*t;[{x:e.x-p.width/2,y:e.y+n},{x:e.x-p.width/2,y:e.y-n-p.height},{x:e.x+n,y:e.y-p.height/2},{x:e.x-n-p.width,y:e.y-p.height/2}].map(e=>({x:e.x,y:e.y,width:p.width,height:p.height})).forEach(e=>{if(!T(k)||v.some(t=>S(e,t))||y.some(t=>S(e,t))||h&&!l(r(h),e))return;let t=x(e);C(t)>0||w(t)>=w(k)||(O=e,k=t)})}}if(C(k)>0){let n=x(D);C(n)<C(k)&&(t.moves=Bt(t.moves,e.id),i(),k=n,O=p)}O!==p&&(t.moves.push({elements:[e],dx:O.x-p.x,dy:O.y-p.y}),c.push(O)),k.forEach(({op:e,line:t})=>{e.waypoints=t.waypoints})})}function Ht(e,t){let{every:n,rectOf:r}=Y(e,t),i=n.filter(e=>e.type!==`bpmn:Participant`&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:SubProcess`&&e.width>0&&e.height>0).map(r);t.routes.forEach(e=>{if(!(e.connection.type??``).includes(`Association`))return;let a=e.connection.source,o=e.connection.target;if(!a||!o)return;let s=/* @__PURE__ */ new Set([a.id,o.id]),c=n.filter(e=>!s.has(e.id)&&i.length>0).filter(e=>e.type!==`bpmn:Participant`&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:SubProcess`&&e.width>0&&e.height>0).map(r),l=t.routes.filter(t=>t!==e).map(e=>e.waypoints);e.waypoints=Tt(r(a),r(o),c,l)})}function Ut(e){return e.routes.map(e=>`${e.connection.id}:${e.waypoints.map(e=>`${Math.round(e.x)},${Math.round(e.y)}`).join(` `)}`).join(`|`)}function Wt(e,t,n,r=12){for(let i=1;i<=r;i++){let r=Ut(t);if(jt(e,t,n),It(e,t),Ut(t)===r)return i}return r}function Gt(e,t){if(e.length===0)return;let n=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let r=n.get(t.id)??{x:0,y:0};n.set(t.id,{x:r.x+e.dx,y:r.y+e.dy})}));let r=new Map(t.resizes.map(e=>[e.element.id,e]));e.forEach(e=>{if(r.has(e.id))return;let i=n.get(e.id)??{x:0,y:0};t.resizes.push({element:e,x:e.x+i.x,y:e.y+i.y,width:e.width,height:e.height})})}function Kt(e,t){let n=0;for(let r=0;r+1<e.length;r++){let i=p(e[r],e[r+1]);i&&t.some(e=>d(i,e))&&(n+=1)}return n}function qt(e,t){let n=/* @__PURE__ */ new Set;for(let r=0;r+1<e.length;r++){let i=p(e[r],e[r+1]);i&&t.forEach((e,t)=>{d(i,e)&&n.add(t)})}return n}function Jt(e,t){for(let n of t)if(!e.has(n))return!0;return!1}const Yt=[8,-8,16,-16,24,-24,32,-32,40,-40,60,-60,80,-80,100,-100,120,-120,160,-160,200,-200,300,-300,400,-400];function Xt(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>({id:e.id,rect:r(e)}))},s=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},c=s(),l=t.routes.map(e=>e.waypoints);t.routes.forEach(e=>{let n=t.routes.filter(t=>t!==e).map(e=>e.waypoints),a=o(e),s=a.map(e=>e.rect),c=(e,t)=>!q(e,t,s),l=e.connection.source?r(e.connection.source):void 0,u=e.connection.target?r(e.connection.target):void 0;for(let t=0;t+1<e.waypoints.length;t++){let r=e.waypoints,o=r[t],d=r[t+1],f=Math.abs(o.y-d.y)<.5,p=Math.abs(o.x-d.x)<.5;if(!f&&!p)continue;let m=t===0,h=t+1===r.length-1,g=t+1;if(m)for(;g+1<r.length&&(f?Math.abs(r[g+1].y-o.y)<.5:Math.abs(r[g+1].x-o.x)<.5);)g+=1;let _=t;if(h)for(;_-1>=0&&(f?Math.abs(r[_-1].y-d.y)<.5:Math.abs(r[_-1].x-d.x)<.5);)--_;let v=n.filter(e=>b(r,e)).length,y=Kt(r,s);if(v===0&&y===0)continue;let x=n.filter(e=>N(r,e)>0).length,S=M(r,s),C=O(r),w=T(r,c);for(let t of Yt){let o=r.map(e=>({...e}));for(let e=_;e<=g;e++)f?o[e].y+=t:o[e].x+=t;let d=P(o);if(!i(d)||l&&!J(d[0],l)||u&&!J(d[d.length-1],u)||M(d,s)>S||Ft(d,r,a)||n.filter(e=>N(d,e)>0).length>x||O(d)>C||T(d,c)>w)continue;let p=n.filter(e=>b(d,e)).length,m=Kt(d,s);if(!(p>v||m>y)&&!(p>=v&&m>=y)){e.waypoints=d;break}}}let d=n.filter(t=>b(e.waypoints,t)).length,f=Kt(e.waypoints,s);if(d===0&&f===0)return;let p=e.waypoints[0],m=e.waypoints[e.waypoints.length-1],h=n.filter(t=>N(e.waypoints,t)>0).length,g=O(e.waypoints),_=M(e.waypoints,s),v=e.waypoints,y=d,x=f;Nt(e.waypoints).forEach(t=>{let r=t[0],o=t[t.length-1];if(r.x!==p.x||r.y!==p.y||o.x!==m.x||o.y!==m.y||!i(t)||M(t,s)>_||Ft(t,e.waypoints,a)||n.filter(e=>N(t,e)>0).length>h||O(t)>g)return;let c=n.filter(e=>b(t,e)).length,l=Kt(t,s);c>y||l>x||c>=y&&l>=x||(v=t,y=c,x=l)}),e.waypoints=v}),s()>c&&t.routes.forEach((e,t)=>{e.waypoints=l[t]})}function Zt(e){return!!e&&((e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`))}const Qt=Yt[0];function $t(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&e.type!==`bpmn:Lane`&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>r(e))},s=(e,t,n)=>{let i=r(e),a=Math.abs(t.y-n.y)<.5&&Math.abs(t.x-n.x)>=.5;if(Math.abs(t.x-n.x)<.5&&Math.abs(t.y-n.y)>=.5)return t.y<=i.y+i.height/2?`n`:`s`;if(a)return t.x<=i.x+i.width/2?`w`:`e`},c=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Map;{let e=/* @__PURE__ */ new Set;t.routes.forEach(t=>{let n=t.waypoints;if(n.length<2)return;[t.connection.source,t.connection.target].forEach(t=>{t&&Zt(t)&&(e.has(t.id)?c.add(t.id):e.add(t.id))});let r=t.connection.source;if(r&&Zt(r)){let e=s(r,n[0],n[1]),i=`${r.id}:${e}`;e&&l.set(i,[...l.get(i)??[],`${t.connection.id}:s`])}let i=t.connection.target;if(i&&Zt(i)){let e=s(i,n[n.length-1],n[n.length-2]),r=`${i.id}:${e}`;e&&l.set(r,[...l.get(r)??[],`${t.connection.id}:t`])}}),l.forEach(e=>e.sort())}t.routes.forEach(e=>{if(e.waypoints.length<2||!(e.connection.source&&c.has(e.connection.source.id)||e.connection.target&&c.has(e.connection.target.id)))return;let n=t.routes.filter(t=>t!==e).map(e=>e.waypoints),a=o(e),u=t=>{let o=e.waypoints;if(o.length<2)return;let c=t?e.connection.source:e.connection.target;if(!Zt(c)||!c)return;let u=t?0:o.length-1,d=t?1:o.length-2,f=o[u],p=o[d],m=Math.abs(f.y-p.y)<.5&&Math.abs(f.x-p.x)>=.5,h=Math.abs(f.x-p.x)<.5&&Math.abs(f.y-p.y)>=.5;if(!m&&!h)return;let g=s(c,f,p),_=`${e.connection.id}:${t?`s`:`t`}`,v=g?l.get(`${c.id}:${g}`)??[_]:[_],y=Math.max(0,v.indexOf(_)),x=r(c),S=m?x.width:x.height,C=Math.min(S/2-4,Math.max(10,S*.4)),w=Math.ceil(y/2),T=y===0?0:w*C*(y%2==1?1:-1),E=m?{x:f.x,y:x.y+x.height/2+T}:{x:x.x+x.width/2+T,y:f.y};if(Math.abs(E.x-f.x)<4&&Math.abs(E.y-f.y)<4)return;let D=m?Math.sign(p.x-f.x)||1:Math.sign(p.y-f.y)||1,k=m?{x:E.x+D*Qt,y:E.y}:{x:E.x,y:E.y+D*Qt},A=m?{x:k.x,y:f.y}:{x:f.x,y:k.y},j=t?[E,k,A,...o.slice(1).map(e=>({...e}))]:[...o.slice(0,-1).map(e=>({...e})),A,k,E],F=t?o[2]:o[o.length-3],I=m?{x:p.x,y:E.y}:{x:E.x,y:p.y},L=F&&(t?[E,I,...o.slice(2).map(e=>({...e}))]:[...o.slice(0,-2).map(e=>({...e})),I,E]),R=n.filter(e=>b(o,e)).length,z=qt(o,a),ee=n.filter(e=>N(o,e)>0).length,B=M(o,a),te=O(o);for(let t of[L,j]){if(!t)continue;let r=P(t);if(i(r)&&!(M(r,a)>B)&&!(O(r)>te)&&!(n.filter(e=>N(r,e)>0).length>ee)&&!(n.filter(e=>b(r,e)).length>R)&&!Jt(z,qt(r,a))){e.waypoints=r;return}}};u(!0),u(!1)})}function en(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&e.type!==`bpmn:Lane`&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>r(e))},s=e=>[e.connection.source?.id,e.connection.target?.id].filter(e=>!!e);t.routes.forEach(e=>{let n=t.routes.filter(t=>t!==e&&s(t).some(t=>s(e).includes(t)));if(n.length===0)return;let a=t.routes.filter(t=>t!==e).map(e=>e.waypoints),c=o(e);for(let t=0;t+1<e.waypoints.length;t++){let o=e.waypoints,s=o[t],l=o[t+1],u=Math.abs(s.y-l.y)<.5&&Math.abs(s.x-l.x)>=.5,d=Math.abs(s.x-l.x)<.5&&Math.abs(s.y-l.y)>=.5;if(!u&&!d)continue;let f=u?`y`:`x`,p=u?s.y:s.x,m=Math.min(u?s.x:s.y,u?l.x:l.y),h=Math.max(u?s.x:s.y,u?l.x:l.y);if(!n.some(e=>y(e.waypoints).some(e=>e.axis!==f||Math.abs(e.at-p)>=30?!1:Math.min(h,e.to)-Math.max(m,e.from)>=60)))continue;let g=n.flatMap(e=>y(e.waypoints).map(e=>e)).filter(e=>e.axis!==f||Math.abs(e.at-p)>=30?!1:Math.min(h,e.to)-Math.max(m,e.from)>=60),_=a.filter(e=>b(o,e)).length,v=qt(o,c),x=a.filter(e=>N(o,e)>0).length,S=M(o,c),C=O(o),w=e=>!!e&&((e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`)),T=t===0&&w(e.connection.source),E=t+1===o.length-1&&w(e.connection.target),D=(T||E)&&!(T&&E),k=Yt[0],A=(e,t)=>u?{x:t.x,y:e.y+e.height/2}:{x:e.x+e.width/2,y:t.y},j=T&&e.connection.source?A(r(e.connection.source),o[0]):o[0],F=E&&e.connection.target?A(r(e.connection.target),o[o.length-1]):o[o.length-1],I=e=>{if(!D){let n=o.map(e=>({...e}));return u?(n[t].y+=e,n[t+1].y+=e):(n[t].x+=e,n[t+1].x+=e),n}if(T){let t={...j},n=o[1],r=u?{x:t.x+(Math.sign(n.x-t.x)||1)*k,y:t.y}:{x:t.x,y:t.y+(Math.sign(n.y-t.y)||1)*k};return[t,r,u?{x:r.x,y:n.y+e}:{x:n.x+e,y:r.y},u?{x:n.x,y:n.y+e}:{x:n.x+e,y:n.y},...o.slice(2).map(e=>({...e}))]}let n=o.length,r={...F},i=o[n-2],a=u?{x:r.x+(Math.sign(i.x-r.x)||1)*k,y:r.y}:{x:r.x,y:r.y+(Math.sign(i.y-r.y)||1)*k},s=u?{x:a.x,y:i.y+e}:{x:i.x+e,y:a.y},c=u?{x:i.x,y:i.y+e}:{x:i.x+e,y:i.y};return[...o.slice(0,n-2).map(e=>({...e})),c,s,a,r]},L=!1;for(let n of[!0,!1]){if(L)break;for(let s of Yt){let l=I(s),d=P(l);if(!i(d))continue;if(T){if(d[0].x!==j.x||d[0].y!==j.y)continue}else if(d[0].x!==o[0].x||d[0].y!==o[0].y){if(t!==0)continue;let n=e.connection.source?r(e.connection.source):void 0;if(!n||!J(d[0],n))continue}if(E){if(d[d.length-1].x!==F.x||d[d.length-1].y!==F.y)continue}else if(d[d.length-1].x!==o[o.length-1].x||d[d.length-1].y!==o[o.length-1].y){if(t+1!==o.length-1)continue;let n=e.connection.target?r(e.connection.target):void 0;if(!n||!J(d[d.length-1],n))continue}if(M(d,c)>S||O(d)>C||a.filter(e=>N(d,e)>0).length>x||a.filter(e=>b(d,e)).length>_||Jt(v,qt(d,c)))continue;let f=u?T?l[2].y:E?l[l.length-3].y:l[t].y:T?l[2].x:E?l[l.length-3].x:l[t].x;if(n){if(g.some(e=>Math.abs(e.at-f)<30))continue}else if(g.some(e=>Math.abs(e.at-f)<Math.abs(e.at-p)))continue;e.waypoints=d,L=!0;break}}}})}function tn(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&e.type!==`bpmn:Lane`&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>r(e))};t.routes.forEach(e=>{let n=t.routes.filter(t=>t!==e).map(e=>e.waypoints),a=o(e);for(let t=0;t+1<e.waypoints.length;t++){let o=e.waypoints,s=o[t],c=o[t+1],l=Math.abs(s.y-c.y)<.5&&Math.abs(s.x-c.x)>=.5,u=Math.abs(s.x-c.x)<.5&&Math.abs(s.y-c.y)>=.5;if(!l&&!u)continue;let d=l?`y`:`x`,f=l?s.y:s.x,p=Math.min(l?s.x:s.y,l?c.x:c.y),m=Math.max(l?s.x:s.y,l?c.x:c.y);if(m-p<150)continue;let h=a.filter(e=>{if(!(d===`x`?[e.x,e.x+e.width]:[e.y,e.y+e.height]).some(e=>Math.abs(e-f)<=2))return!1;let t=d===`x`?e.y:e.x,n=d===`x`?e.y+e.height:e.x+e.width;return Math.min(m,n)-Math.max(p,t)>=20});if(h.length===0)continue;let g=n.filter(e=>b(o,e)).length,_=qt(o,a),v=n.filter(e=>N(o,e)>0).length,y=M(o,a),x=O(o);for(let s of Yt){let c=o.map(e=>({...e}));l?(c[t].y+=s,c[t+1].y+=s):(c[t].x+=s,c[t+1].x+=s);let u=P(c);if(!i(u))continue;if(t===0){let t=e.connection.source?r(e.connection.source):void 0;if(!t||!J(u[0],t))continue}else if(u[0].x!==o[0].x||u[0].y!==o[0].y)continue;if(t+1===o.length-1){let t=e.connection.target?r(e.connection.target):void 0;if(!t||!J(u[u.length-1],t))continue}else if(u[u.length-1].x!==o[o.length-1].x||u[u.length-1].y!==o[o.length-1].y)continue;if(M(u,a)>y||O(u)>x||n.filter(e=>N(u,e)>0).length>v||n.filter(e=>b(u,e)).length>g||Jt(_,qt(u,a)))continue;let f=l?c[t].y:c[t].x;if(!h.some(e=>(d===`x`?[e.x,e.x+e.width]:[e.y,e.y+e.height]).some(e=>Math.abs(e-f)<20))){e.waypoints=u;break}}}})}function nn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},s=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},c=s(),l=t.routes.map(e=>e.waypoints);t.routes.forEach(e=>{let n=e.connection;if(!_(n)||!n.source||!n.target)return;let s=e.waypoints;if(s.length<2)return;let c=f(s),l=r(n.source),u=r(n.target),d=Math.abs(l.x+l.width/2-(u.x+u.width/2))+Math.abs(l.y+l.height/2-(u.y+u.height/2));if(d<40||c<=d*2)return;let p=/* @__PURE__ */ new Set([n.source.id,n.target.id,...o(n.source),...o(n.target)]),m=a.filter(e=>!p.has(e.id)).map(r),h=t.routes.filter(t=>t!==e).map(e=>e.waypoints),g=h.reduce((e,t)=>e+ +(N(s,t)>0),0),v=h.filter(e=>b(s,e)).length,y=O(s),x=Tt(l,u,m,h),S=M(x,m)===0,C=S?[x]:Nt(s),w=s[0],T=s[s.length-1],E,D=c;C.forEach(e=>{if(!S){let t=e[0],n=e[e.length-1];if(Math.abs(t.x-w.x)>2||Math.abs(t.y-w.y)>2||Math.abs(n.x-T.x)>2||Math.abs(n.y-T.y)>2)return}if(M(e,m)>0||!i(e)||O(e)>y)return;let t=f(e);t>=D||h.reduce((t,n)=>t+ +(N(e,n)>0),0)>g||h.filter(t=>b(e,t)).length>v||(D=t,E=e)}),E&&(e.waypoints=E)}),s()>c&&t.routes.forEach((e,t)=>{e.waypoints=l[t]})}function rn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},s=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},c=s(),l=t.routes.map(e=>e.waypoints);t.routes.forEach(e=>{let n=e.connection;if(!n.source||!n.target||!Zt(n.source)&&!Zt(n.target))return;let s=e.waypoints;if(s.length<2)return;let c=f(s),l=r(n.source),u=r(n.target),d=/* @__PURE__ */ new Set([n.source.id,n.target.id,...o(n.source),...o(n.target)]),p=a.filter(e=>!d.has(e.id)).map(r),m=t.routes.filter(t=>t!==e).map(e=>e.waypoints),h=m.reduce((e,t)=>e+ +(N(s,t)>0),0),g=m.filter(e=>b(s,e)).length,_=O(s),v=Tt(l,u,p,m);M(v,p)>0||i(v)&&(O(v)>_||f(v)>=c||m.reduce((e,t)=>e+ +(N(v,t)>0),0)>h||m.filter(e=>b(v,e)).length>g||(e.waypoints=v))}),s()>c&&t.routes.forEach((e,t)=>{e.waypoints=l[t]})}function an(e){e.routes.forEach(e=>{e.waypoints=h(e.waypoints)})}function on(e,t,n,r=`vpsc`){let{every:a,rectOf:o}=Y(e,t),s=a.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)).map(o),l=(e,n)=>t.routes.reduce((t,r)=>r===n?t:t+N(e,r.waypoints),0),u=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},d=u(),f=t.routes.map(e=>e.waypoints),p=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},m=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...p(e.connection.source),...p(e.connection.target)]);return a.filter(e=>!w(e)&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>({id:e.id,rect:o(e)}))},h=e=>m(e).map(e=>e.rect);(r===`lattice`?_t(t.routes,h):r===`border`?gt(t.routes,h):r===`ordered`?ht(t.routes,n):dt(t.routes,n)).forEach(({route:e,index:t,axis:n,at:r})=>{let a=e.waypoints;if(t+1>=a.length)return;let u=a.map(e=>({...e})),d=n===`y`?{y:r}:{x:r};u[t]={...u[t],...d},u[t+1]={...u[t+1],...d};let f=i(u),p=e.connection.source?o(e.connection.source):void 0,h=e.connection.target?o(e.connection.target):void 0,g=(!p||J(u[0],p))&&(!h||J(u[u.length-1],h));if(!f||!g)return;let _=m(e),v=_.map(e=>e.rect);c(u[t],u[t+1],v)>c(a[t],a[t+1],v)||Ft(u,a,_)||M(u,s)>M(a,s)||l(u,e)>l(a,e)||O(u)>O(a)||(e.waypoints=u)}),u()>d?t.routes.forEach((e,t)=>{e.waypoints=f[t]}):t.routes.forEach(e=>{e.waypoints=P(e.waypoints)})}function sn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)).map(e=>({id:e.id,rect:r(e)})),o=a.map(e=>e.rect),s=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&(e.children||[]).filter(e=>!w(e)&&!j(e)).length===0).map(r),c=(e,n)=>t.routes.reduce((t,r)=>r===n?t:t+N(e,r.waypoints),0),l=(e,n)=>t.routes.filter(t=>t!==n&&b(e,t.waypoints)).length;t.routes.forEach(e=>{for(let t=0;t<2;t++){let t=e.waypoints,n=!0;for(let u=0;u+3<t.length;u++){let[d,f,p,m]=[t[u],t[u+1],t[u+2],t[u+3]],h=d.x===f.x&&p.x===m.x&&f.y===p.y,g=d.y===f.y&&p.y===m.y&&f.x===p.x,_=h?Math.abs(f.x-p.x):g?Math.abs(f.y-p.y):0;if(!h&&!g||_<.5||_>=40)continue;let v=e.connection.source?r(e.connection.source):void 0,y=e.connection.target?r(e.connection.target):void 0,b=h?[d.x,m.x]:[d.y,m.y];for(let r of b){let d=t.map(e=>({...e}));for(let e=0;e<=3;e++)h?d[u+e].x=r:d[u+e].y=r;let f=P(d),p=i(f),m=(!v||J(f[0],v))&&(!y||J(f[f.length-1],y));if(p&&m&&!(M(f,o)>M(t,o))&&!(M(f,s)>M(t,s))&&!Ft(f,t,a)&&!(c(f,e)>c(t,e))&&!(l(f,e)>l(t,e))&&!(O(f)>O(t))){e.waypoints=f,n=!1;break}}if(!n)break}if(n)break}})}function cn(e,t){let{every:n,rectOf:r}=Y(e,t),i=n.filter(e=>e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=(e,t,n)=>{let i=r(e);if(Math.abs(t.y-n.y)<.5){let e=t.y;if(Math.abs(e-i.y)<.5||Math.abs(e-(i.y+i.height))<.5){let e=Math.min(t.x,n.x);return Math.max(t.x,n.x)>i.x&&e<i.x+i.width}}if(Math.abs(t.x-n.x)<.5){let e=t.x;if(Math.abs(e-i.x)<.5||Math.abs(e-(i.x+i.width))<.5){let e=Math.min(t.y,n.y);return Math.max(t.y,n.y)>i.y&&e<i.y+i.height}}return!1};for(let e=0;e<2;e++){let e=!1;if(t.routes.forEach(n=>{if(n.waypoints.length<=4)return;let s=n.connection,c=/* @__PURE__ */ new Set([s.source?.id??``,s.target?.id??``,...a(s.source),...a(s.target)]),l=i.filter(e=>!c.has(e.id)).map(r),u=t.routes.filter(e=>e!==n).map(e=>e.waypoints),d=e=>M(e,l)*1e6+u.reduce((t,n)=>t+N(e,n),0)*1e4+e.length*200+f(e),p=d(n.waypoints),m=!!s.source&&o(s.source,n.waypoints[0],n.waypoints[1]),h=!!s.target&&o(s.target,n.waypoints[n.waypoints.length-1],n.waypoints[n.waypoints.length-2]),g=n.waypoints,_=p;Nt(n.waypoints,!0).forEach(e=>{if(!m&&s.source&&o(s.source,e[0],e[1])||!h&&s.target&&o(s.target,e[e.length-1],e[e.length-2]))return;let t=d(e);t<_&&(_=t,g=e)}),g!==n.waypoints&&(n.waypoints=g,e=!0)}),!e)break}}const ln=[20,60,120,300],un=[6,3,1];function dn(e,t){let n=[];for(let r=0;r+1<e.length;r++){let i=e[r],a=e[r+1];n.push({x:Math.min(i.x,a.x)-t,y:Math.min(i.y,a.y)-t,width:Math.abs(a.x-i.x)+t*2,height:Math.abs(a.y-i.y)+t*2})}return n}function fn(e,t,n,r){let i,a=1/0;for(let o=0;o+1<e.length;o++){let s=e[o],c=e[o+1],l;if(t===`x`&&s.y===c.y){let e=Math.min(s.x,c.x),t=Math.max(s.x,c.x);n>=e&&n<=t&&(l={x:n,y:s.y})}else if(t===`y`&&s.x===c.x){let e=Math.min(s.y,c.y),t=Math.max(s.y,c.y);n>=e&&n<=t&&(l={x:s.x,y:n})}if(!l)continue;let u=Math.abs(l.x-r.x)+Math.abs(l.y-r.y);u<a&&(a=u,i=l)}return i}function pn(e,t){let n=e[0],r=1/0;for(let i=0;i+1<e.length;i++){let a=e[i],o=e[i+1],s=o.x-a.x,c=o.y-a.y,l=s*s+c*c,u=l===0?0:Math.max(0,Math.min(1,((t.x-a.x)*s+(t.y-a.y)*c)/l)),d={x:a.x+u*s,y:a.y+u*c},f=Math.abs(d.x-t.x)+Math.abs(d.y-t.y);f<r&&(r=f,n=d)}return n}function mn(e,t){return[[e,{x:t.x,y:e.y},t],[e,{x:e.x,y:t.y},t]]}function hn(e,t,n,r,a){let o=[];for(let{route:s,end:c}of e){if(s.waypoints.length<2)return;let e=c===`first`?s.waypoints[0]:s.waypoints[s.waypoints.length-1],l=c===`first`?s.waypoints[1]:s.waypoints[s.waypoints.length-2],u=s.connection.source?r(s.connection.source):void 0,d=s.connection.target?r(s.connection.target):void 0,f=/* @__PURE__ */ new Set([s.connection.source?.id,s.connection.target?.id,...a(s.connection.source),...a(s.connection.target)]),p=n.filter(e=>!f.has(e.id)).map(r),m=M(s.waypoints,p),h=c===`first`?d:u,g;if(l.x===e.x||l.y===e.y){let n=l.x===e.x?`x`:`y`,r=fn(t,n,n===`x`?l.x:l.y,e);if(r){let e=s.waypoints.map(e=>({...e}));c===`first`?e[0]=r:e[e.length-1]=r,i(e)&&M(e,p)<=m&&(g=e)}}if(!g){let n=pn(t,e),r=c===`first`?s.waypoints.slice(2):s.waypoints.slice(0,-2);for(let e of mn(l,n)){let t=P(c===`first`?[...e.slice().reverse(),...r]:[...r,...e]);if(i(t)&&!(M(t,p)>m)&&!(O(t)>0)){g=t;break}}}if(!g)return;let _=c===`first`?g[g.length-1]:g[0];if(h&&!J(_,h))return;o.push({dep:s,movedPath:g})}return o}function gn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},s=e=>t.routes.filter(t=>t!==e).flatMap(t=>{let{source:n,target:r}=t.connection,i=n?.id===e.connection.id;return i===(r?.id===e.connection.id)?[]:[{route:t,end:i?`first`:`last`}]}),c=[...new Map(t.routes.map(e=>[e,t.routes.filter(t=>t!==e&&b(e.waypoints,t.waypoints)).length])).entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e),l=(e,t,n,r)=>{let a=e.waypoints,o=O(a),s=r.reduce((e,t)=>e+ +(N(a,t)>0),0);for(let e=1;e+2<a.length;e++){let c=a[e],l=a[e+1],u=Math.abs(c.y-l.y)<.5,d=Math.abs(c.x-l.x)<.5;if(u||d)for(let c of Yt){let l=a.map(e=>({...e}));u?(l[e].y+=c,l[e+1].y+=c):(l[e].x+=c,l[e+1].x+=c);let d=P(l);if(i(d)&&!(M(d,n)>0)&&!b(d,t)&&!r.some(e=>b(d,e))&&!(O(d)>o)&&!(r.reduce((e,t)=>e+ +(N(d,t)>0),0)>s))return d}}};c.forEach(e=>{let n=e.connection;if(!n.source||!n.target)return;let c=t.routes.filter(t=>t!==e),u=c.filter(t=>b(e.waypoints,t.waypoints));if(u.length===0)return;let d=/* @__PURE__ */ new Set([n.source.id,n.target.id,...o(n.source),...o(n.target)]),f=a.filter(e=>!d.has(e.id)).map(r),p=c.map(e=>e.waypoints),m=(e,t)=>!q(e,t,f),h=T(e.waypoints,m),g=e.waypoints[0],_=e.waypoints[e.waypoints.length-1],v=null,y=1/0,x;for(let n of ln){for(let d of un){let S=u.flatMap(e=>dn(e.waypoints,d)),C=Ke(g,_,[...f,...S],p,n,void 0,2,150);if(!C||C.length<2||!i(C)||M(C,f)>0)continue;let w=p.reduce((e,t)=>e+ +(N(C,t)>0),0);if(v&&w>=y)continue;let E=c.filter(e=>b(C,e.waypoints));if(E.length>1)continue;let D;if(E.length===1){let n=E[0],i=t.routes.filter(e=>e!==n&&b(n.waypoints,e.waypoints)).length,c=i===1&&b(n.waypoints,e.waypoints);if(i>0&&!c||s(n).length>0)continue;let u=n.connection,d=/* @__PURE__ */ new Set([u.source?.id,u.target?.id,...o(u.source),...o(u.target)]),f=a.filter(e=>!d.has(e.id)).map(r),p=t.routes.filter(t=>t!==e&&t!==n).map(e=>e.waypoints),m=l(n,C,f,p);if(!m)continue;D={bystander:n,waypoints:m}}if(!(T(C,m)>h)&&(v=C,y=w,x=D,y===0))break}if(v&&y===0)break}if(!v)return;let S=hn(s(e),v,a,r,o);S&&(e.waypoints=v,S.forEach(({dep:e,movedPath:t})=>{e.waypoints=t}),x&&(x.bystander.waypoints=x.waypoints))}),_n(t,a,r,o,s)}function _n(e,t,n,r,a){let o=e.routes.filter(t=>e.routes.some(e=>e!==t&&b(t.waypoints,e.waypoints)));if(o.length===0)return;let s=/* @__PURE__ */ new Set,c=[];o.forEach(e=>{if(s.has(e))return;let t=[],n=[e];for(s.add(e);n.length>0;){let e=n.shift();t.push(e),o.forEach(t=>{s.has(t)||t===e||b(e.waypoints,t.waypoints)&&(s.add(t),n.push(t))})}c.push(t)});let l=o=>{let s=e.routes.filter(e=>!o.includes(e)),c=/* @__PURE__ */ new Map,l=o.map(e=>{let a=e.connection,o=/* @__PURE__ */ new Set([a.source?.id,a.target?.id,...r(a.source),...r(a.target)]),c=t.filter(e=>!o.has(e.id)).map(n),l=s.map(e=>e.waypoints),u=(e,t)=>!q(e,t,c),d=T(e.waypoints,u),f=e.waypoints[0],p=e.waypoints[e.waypoints.length-1],m=/* @__PURE__ */ new Set,h=[],g=e=>{let t=JSON.stringify(e);m.has(t)||(m.add(t),h.push(e))};g(e.waypoints);for(let t of ln){for(let n of un){let r=s.flatMap(t=>b(e.waypoints,t.waypoints)?dn(t.waypoints,n):[]),a=Ke(f,p,[...c,...r],l,t,void 0,2,150);if(!(!a||a.length<2)&&i(a)&&!(M(a,c)>0)&&!(T(a,u)>d)&&(g(a),h.length>=6))break}if(h.length>=6)break}return h});if(l.some(e=>e.length===0)||l.reduce((e,t)=>e*t.length,1)>4e3)return{solved:void 0,blockers:c};let u=s.map(e=>e.waypoints),d=e=>u.reduce((t,n)=>t+ +(N(e,n)>0),0),f=o.map(e=>a(e)),p=l.map(()=>0),m,h,g=1/0;outer:for(;;){let e=p.map((e,t)=>l[t][e]),i=!0;for(let t=0;t<e.length&&i;t++){for(let n=t+1;n<e.length&&i;n++)b(e[t],e[n])&&(i=!1);if(i){let n=s.find(n=>b(e[t],n.waypoints));n&&(i=!1,c.set(n,(c.get(n)??0)+1))}}let a;if(i){let i=e.reduce((e,t)=>e+d(t),0);if(i<g){a=[];for(let i=0;i<e.length&&a;i++){let o=hn(f[i],e[i],t,n,r);o?a.push(o):a=void 0}if(a&&(m=e,h=a,g=i,i===0))break outer}}let o=p.length-1;for(;;){if(o<0)break outer;if(p[o]++,p[o]<l[o].length)break;p[o]=0,o--}}return m&&h?{solved:m,solvedDeps:h,blockers:c}:{solved:void 0,blockers:c}};c.forEach(e=>{if(e.length<2||e.length>4)return;let t=e,n=l(t);if(!n.solved&&t.length<4){let e=[...n.blockers.entries()].sort((e,t)=>t[1]-e[1])[0];e&&(t=[...t,e[0]],n=l(t))}n.solved&&t.forEach((e,t)=>{e.waypoints=n.solved[t],n.solvedDeps[t].forEach(({dep:e,movedPath:t})=>{e.waypoints=t})})})}var vn=class extends Error{element;constructor(e,t){super(t),this.element=e}};const yn=e=>typeof e==`number`&&Number.isFinite(e)&&Math.abs(e)<=1e7;function bn(e,n){let r=e.waypoints!==void 0||e.source!==void 0||e.target!==void 0;for(let[t,n]of[[`x`,e.x],[`y`,e.y]])if(!yn(n))return`${t} is ${String(n)}`;for(let[t,i]of[[`width`,e.width],[`height`,e.height]])if(!yn(i)||i<=0&&!r&&!n&&e.type!==`root`&&e.type!==`bpmn:Process`&&e.type!==`label`)return`${t} is ${String(i)}`;for(let n of e.waypoints??[])if(!yn(n?.x)||!yn(n?.y))return t(`app.editor.layoutBadWaypoint`,{x:String(n?.x),y:String(n?.y)});return null}function xn(e){let n=/* @__PURE__ */ new Set,r=[e];for(let i=r.pop();i;i=r.pop()){if(n.has(i))continue;n.add(i);let a=bn(i,i===e);if(a)throw new vn(i.id,t(`app.editor.layoutBadShape`,{element:i.id||t(`app.editor.layoutAnElement`),problem:a}));r.push(...i.children??[],...i.attachers??[],...i.outgoing??[],...i.incoming??[]),i.label&&r.push(i.label)}}const Sn={nodesep:40,ranksep:80,marginX:40,marginY:40},Cn=globalThis.process?.env?.BPMN_LAYOUT_ENGINE!==`legacy`;function wn(e){return Math.max(e.width||36,e.label?.width??0)}function Tn(e){return e.reduce((e,t,n)=>e+wn(t)+(n>0?6:0),0)}function En(e){let t=0;for(let n=0;n<6;n++){let{south:n,north:r}=X({...e,width:t}),i=Math.max(Tn(n),Tn(r));if(i<=t)break;t=i}return t}function Dn(e){let t=[],n=e=>{if((e.attachers||[]).length>0&&Ce(e).length===0){let n=Math.max(e.width,En(e));n>e.width&&(e.width=n,t.push(e))}(e.children||[]).forEach(n)};return(e.children||[]).forEach(n),t}function On(e,t){let n=/* @__PURE__ */ new Map,{south:r,north:i}=X(e);return[r,i].forEach(e=>{if(e.length===0)return;let r=(t-Tn(e))/2;e.forEach(e=>{n.set(e.id,r+wn(e)/2),r+=wn(e)+6})}),n}function kn(e){return(e.businessObject?.eventDefinitions||[]).some(e=>e.$type===`bpmn:EscalationEventDefinition`)}function X(e){let t=e.attachers||[],n=[],r=t.filter(kn),i=0;return t.filter(e=>!kn(e)).forEach(t=>{let a=wn(t),o=i+(n.length>0?6:0)+a;n.length===0||o<=e.width?(n.push(t),i=o):r.push(t)}),{south:n,north:r}}function Z(e,t=`SOUTH`){let{south:n,north:r}=X(e),i=t===`SOUTH`?n:r;return i.length===0?0:Math.max(...i.map(e=>e.height||36))/2}function An(e){let t=(e.children||[]).filter(e=>e.type===`bpmn:Participant`);return t.length>0?t:[e]}function jn(e,t=[]){return t.push(e),(e.attachers||[]).forEach(e=>{t.push(e)}),(e.children||[]).forEach(e=>{!w(e)&&!j(e)&&jn(e,t)}),t}function Q(e,t){let n=[];return x.has(e.type??``)?n:((e.outgoing||[]).forEach(e=>{e.target&&t.has(e.target.id)&&(x.has(e.target.type??``)||n.push({target:e.target,conn:e,fromBoundary:!1}))}),(e.attachers||[]).forEach(e=>{(e.outgoing||[]).forEach(r=>{r.target&&t.has(r.target.id)&&n.push({target:r.target,conn:r,fromBoundary:!0,sourceAttacherId:e.id})})}),n.map((e,t)=>({edge:e,index:t})).sort((e,t)=>e.edge.target.y+e.edge.target.height/2-(t.edge.target.y+t.edge.target.height/2)||e.index-t.index).map(e=>e.edge))}function Mn(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;e.forEach(e=>{Q(e,t).forEach(e=>{n.set(e.target.id,(n.get(e.target.id)??0)+1),e.fromBoundary&&r.set(e.target.id,(r.get(e.target.id)??0)+1)})});let i=/* @__PURE__ */ new Set;return e.forEach(e=>{let a=n.get(e.id)??0,o=r.get(e.id)??0,s=Q(e,t).length===0;a>0&&a===o&&s&&i.add(e.id)}),i}function Nn(e,t){let n=/* @__PURE__ */ new Map;return e.forEach(e=>{(e.outgoing||[]).forEach(r=>{if(!r.target||!t.has(r.target.id))return;let i=x.has(e.type??``),a=x.has(r.target.type??``);a&&!i&&!n.has(r.target.id)&&n.set(r.target.id,e),i&&!a&&!n.has(e.id)&&n.set(e.id,r.target)})}),n}function Pn(e,t){let n=/* @__PURE__ */ new Map;return e.forEach(e=>{(e.attachers||[]).forEach(r=>{(r.outgoing||[]).forEach(r=>{r.target&&t.has(r.target.id)&&n.set(r.target.id,e)})})}),n}function Fn(e){let t=/* @__PURE__ */ new Map,n=[...e].sort((e,t)=>e.center-t.center||(e.id<t.id?-1:1)),r=[],i=()=>{if(r.length===0)return;let e=[...r.map(e=>e.center)].sort((e,t)=>e-t),n=e[Math.floor(e.length/2)];r.forEach(e=>t.set(e.id,n)),r=[]};return n.forEach(e=>{r.length>0&&e.center-r[0].center>20&&i(),r.push(e)}),i(),t}function In(e){let t=[...new Set(e.values())].sort((e,t)=>e-t),n=new Map(t.map((e,t)=>[e,t]));return new Map([...e.entries()].map(([e,t])=>[e,n.get(t)]))}function Ln(e){let t=e.filter(e=>(e.x??0)!==0||(e.y??0)!==0);if(t.length<2)return!1;let n=new Set(t.map(e=>Math.round(e.x))),r=new Set(t.map(e=>Math.round(e.y)));return n.size>1||r.size>1}function Rn(e,t,n){let r=e.filter(e=>!x.has(e.type??``));if(!Ln(r))return null;let i=Fn(r.map(e=>({id:e.id,center:e.x+(e.width||100)/2}))),a=Fn(r.map(e=>({id:e.id,center:e.y+(e.height||80)/2}))),o=/* @__PURE__ */ new Map;e.forEach(e=>{let t=i.get(e.id),n=a.get(e.id);o.set(e.id,{x:t===void 0?e.x:t-(e.width||100)/2,y:n===void 0?e.y:n-(e.height||80)/2})});let s=new Map(e.map(e=>[e.id,{x:e.x,y:e.y}])),c=new Map([...o].map(([e,t])=>[e,{...t}]));Gn(e,o,t,n??{x:t.marginX,y:t.marginY});let l=new Map([...s].map(([e,t])=>[e,{...t}]));Un(e,l,t);let u=new Map([...c].map(([e,t])=>[e,{...t}]));Un(e,u,t);let d=new Map([...s].map(([e,t])=>[e,{...t}]));Wn(e,d,t,Bn(e)),Un(e,d,t);let f=[s,c,l,u,d,o].reduce((t,n)=>$(e,n)<$(e,t)?n:t);f!==o&&f.forEach((e,t)=>o.set(t,e));let p=Bn(r);return{positions:o,ranks:In(p?a:i),rows:In(p?i:a),authored:!0}}function zn(e,t,n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;[...e].sort((e,t)=>e.center-t.center||(e.id<t.id?-1:1)).forEach(e=>{let t=[...r.keys()].find(t=>{let n=r.get(t);return Math.abs(n[0].center-e.center)>20?!1:!n.some(t=>t.otherStart<e.otherEnd&&t.otherEnd>e.otherStart)})??e.id;r.has(t)||r.set(t,[]),r.get(t).push(e),i.set(e.id,t)});let a=[...r.keys()].sort((e,t)=>Math.min(...r.get(e).map(e=>e.center))-Math.min(...r.get(t).map(e=>e.center))||(e<t?-1:1)),o=(e,t)=>e.otherStart<t.otherEnd&&e.otherEnd>t.otherStart,s=/* @__PURE__ */ new Map;a.forEach((e,i)=>{let c=r.get(e),l=n+Math.max(...c.map(e=>e.half));for(let e=0;e<i;e++){let n=a[e],i=s.get(n),u=r.get(n),d=i;u.forEach(e=>{c.forEach(n=>{o(e,n)&&(d=Math.max(d,i+e.half+n.half+t))})}),l=Math.max(l,d)}s.set(e,l)});let c=/* @__PURE__ */ new Map;return e.forEach(e=>c.set(e.id,s.get(i.get(e.id)))),c}function Bn(e){let t=new Map(e.map(e=>[e.id,e])),n=0,r=0;return e.forEach(e=>{(e.outgoing||[]).forEach(i=>{let a=i.target,o=a?t.get(a.id):void 0;o&&(n+=Math.abs(o.x+(o.width||100)/2-(e.x+(e.width||100)/2)),r+=Math.abs(o.y+(o.height||80)/2-(e.y+(e.height||80)/2)))})}),r>n}function Vn(e,t,n,r){let i=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);return i(n,r,e)>0!=i(n,r,t)>0&&i(e,t,n)>0!=i(e,t,r)>0}function Hn(e,t){let n=new Map(e.map(e=>[e.id,e])),r=e=>{let n=t.get(e.id)??{x:e.x,y:e.y};return{x:n.x+(e.width||100)/2,y:n.y+(e.height||80)/2}},i=[];e.forEach(e=>{x.has(e.type??``)||[e,...e.attachers||[]].forEach(t=>{(t.outgoing||[]).forEach(r=>{let a=r.target,o=a?n.get(a.id):void 0;o&&!x.has(o.type??``)&&i.push({a:n.get(t.id)??e,b:o})})})});let a=0;for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++){let n=i[e],o=i[t];n.a!==o.a&&n.a!==o.b&&n.b!==o.a&&n.b!==o.b&&Vn(r(n.a),r(n.b),r(o.a),r(o.b))&&a++}return a}function $(e,t,n=0){let r=new Map(e.map(e=>[e.id,e])),i=e=>{let n=t.get(e.id)??{x:e.x,y:e.y};return{x:n.x+(e.width||100)/2,y:n.y+(e.height||80)/2}},a=e=>{let n=t.get(e.id)??{x:e.x,y:e.y};return{x:n.x,y:n.y,width:e.width||100,height:e.height||80}},o=[];e.forEach(e=>{x.has(e.type??``)||(e.outgoing||[]).forEach(t=>{let n=t.target,i=n?r.get(n.id):void 0;i&&!x.has(i.type??``)&&o.push({a:e,b:i})})});let s=0;for(let e=0;e<o.length;e++)for(let t=e+1;t<o.length;t++){let n=o[e],r=o[t];n.a!==r.a&&n.a!==r.b&&n.b!==r.a&&n.b!==r.b&&Vn(i(n.a),i(n.b),i(r.a),i(r.b))&&s++}let c=0;o.forEach(({a:t,b:n})=>{let r=i(t),o=i(n);e.forEach(e=>{if(e===t||e===n||x.has(e.type??``))return;let i=a(e),s=Math.min(r.x,o.x),l=Math.max(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.y,o.y);s<i.x+i.width&&l>i.x&&u<i.y+i.height&&d>i.y&&c++})});let l=e.filter(e=>!x.has(e.type??``)&&!g(e)),u=0;for(let e=0;e<l.length;e++)for(let t=e+1;t<l.length;t++){let n=a(l[e]),r=a(l[t]);n.x<r.x+r.width&&n.x+n.width>r.x&&n.y<r.y+r.height&&n.y+n.height>r.y&&u++}let d=e.map(e=>a(e)),f=Math.max(...d.map(e=>e.x+e.width))-Math.min(...d.map(e=>e.x)),p=Math.max(...d.map(e=>e.y+e.height))-Math.min(...d.map(e=>e.y)),m=[];e.forEach(e=>{let n=t.get(e.id);n&&m.push({x:n.x-e.x,y:n.y-e.y})});let h=e=>{if(e.length===0)return 0;let t=[...e].sort((e,t)=>e-t);return t[Math.floor(t.length/2)]},_=h(m.map(e=>e.x)),v=h(m.map(e=>e.y)),y=m.length>0?m.reduce((e,t)=>e+Math.abs(t.x-_)+Math.abs(t.y-v),0)/m.length:0,b=0,S=[];o.forEach(({a:e,b:t})=>{let n=a(e),r=a(t),i=r.x+r.width/2-(n.x+n.width/2),o=r.y+r.height/2-(n.y+n.height/2);Math.abs(i)>=Math.abs(o)?(Math.abs(o)>2&&b++,S.push(i>0?r.x-(n.x+n.width):n.x-(r.x+r.width))):(Math.abs(i)>2&&b++,S.push(o>0?r.y-(n.y+n.height):n.y-(r.y+r.height)))});let C=S.filter(e=>e>0),w=C.reduce((e,t)=>e+t,0)/(C.length||1),T=C.reduce((e,t)=>e+Math.abs(t-w),0)/(C.length||1);return u*1e5+s*1e3+c*n+f*p/2e3+y*1+b*1e3+T*10}function Un(e,t,n){let r=e.filter(e=>!x.has(e.type??``)&&!g(e)&&t.has(e.id)),i=e=>{let n=t.get(e.id);return{x:n.x,y:n.y,width:e.width||100,height:e.height||80}};for(let e=0;e<12;e++){let e=!1;for(let a=0;a<r.length;a++)for(let o=a+1;o<r.length;o++){let s=i(r[a]),c=i(r[o]);if(!(s.x<c.x+c.width&&s.x+s.width>c.x&&s.y<c.y+c.height&&s.y+s.height>c.y))continue;let l=Math.min(s.y+s.height,c.y+c.height)-Math.max(s.y,c.y)+n.nodesep,u=Math.min(s.x+s.width,c.x+c.width)-Math.max(s.x,c.x)+n.nodesep,d=t.get(r[o].id);l<=u?t.set(r[o].id,{x:d.x,y:d.y+(c.y>=s.y?l:-l)}):t.set(r[o].id,{x:d.x+(c.x>=s.x?u:-u),y:d.y}),e=!0}if(!e)return}}function Wn(e,t,n,r){let i=new Map(e.map(e=>[e.id,e])),a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;e.forEach(e=>{x.has(e.type??``)||(e.outgoing||[]).forEach(t=>{let n=t.target,r=n?i.get(n.id):void 0;r&&!x.has(r.type??``)&&(a.has(r.id)||a.set(r.id,[]),a.get(r.id).push(e),o.has(e.id)||o.set(e.id,[]),o.get(e.id).push(r))})});let s=e=>r?e.width||100:e.height||80,c=e=>r?e.height||80:e.width||100,l=e=>r?e.x:e.y,u=e=>r?e.y:e.x,d=(e,t)=>r?{x:e,y:t}:{x:t,y:e};[...e].filter(e=>!x.has(e.type??``)&&t.has(e.id)).sort((e,n)=>u(t.get(e.id))-u(t.get(n.id))).forEach(e=>{let r=(a.get(e.id)??[]).filter(e=>t.has(e.id));if(r.length!==1)return;let i=r[0];if((o.get(i.id)??[]).length!==1)return;let f=t.get(i.id),p=t.get(e.id),m=l(f)+s(i)/2,h=u(f)+c(i)+n.ranksep;u(p)<u(f)||t.set(e.id,d(m-s(e)/2,h))})}function Gn(e,t,n,r){let i=e.filter(e=>!x.has(e.type??``)&&t.has(e.id));if(i.length===0)return;let a=Bn(i);for(let e=0;e<3;e++)Kn(i,t,n,a,r)}function Kn(e,t,n,r,i){let a=e=>{let n=t.get(e.id);return{x:n.x,y:n.y,w:e.width||100,h:e.height||80}},o=e.map(e=>{let t=a(e);return{id:e.id,center:t.x+t.w/2,half:t.w/2,otherStart:t.y,otherEnd:t.y+t.h}});if(!r){let r=zn(o,n.ranksep,i.x);e.forEach(e=>{let n=t.get(e.id);t.set(e.id,{x:r.get(e.id)-(e.width||100)/2,y:n.y})})}let s=e.map(e=>{let t=a(e);return{id:e.id,center:t.y+t.h/2,half:t.h/2,otherStart:t.x,otherEnd:t.x+t.w}});if(r){let r=zn(s,n.ranksep,i.y);e.forEach(e=>{let n=t.get(e.id);t.set(e.id,{x:n.x,y:r.get(e.id)-(e.height||80)/2})})}}function qn(e,t){let n=/* @__PURE__ */ new Map,r=[...e].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)),i=/* @__PURE__ */ new Set,a=[],o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set;function c(e){s.has(e.id)||o.has(e.id)||(o.add(e.id),a.push(e.id),Q(e,t).forEach(t=>{o.has(t.target.id)?a.length-a.indexOf(t.target.id)<=5&&i.add(`${e.id}->${t.target.id}`):c(t.target)}),a.pop(),o.delete(e.id),s.add(e.id))}r.forEach(c);let l=/* @__PURE__ */ new Set;function u(e){let a=n.get(e.id);if(a!==void 0)return a;if(l.has(e.id))return 0;l.add(e.id);let o=r.filter(n=>Q(n,t).some(t=>t.target.id===e.id)&&!i.has(`${n.id}->${e.id}`)),s=o.length===0?0:Math.max(...o.map(u))+1;return n.set(e.id,s),l.delete(e.id),s}return r.forEach(u),n}function Jn(e,t,n){let r=n?.get(t);if(!r)return e;let i=new Map(e.map(e=>[e.target.id,e])),a=r.map(e=>i.get(e)).filter(e=>!!e);return a.length===e.length?a:e}function Yn(e,t,n,r){let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;return[...e].sort((e,t)=>(n.get(e.id)??0)-(n.get(t.id)??0)||(e.id<t.id?-1:+(e.id>t.id))).forEach(e=>{let n=a.get(e.id),s=new Set(n??[]),c=!n||n.length===0?null:s.size===1?[...s][0]:null;i.set(e.id,c);let l=Q(e,t),u=Jn(l.filter(e=>!e.fromBoundary),e.id,r),d=l.filter(e=>e.fromBoundary),f=(e,t)=>{a.has(e.id)||a.set(e.id,[]),a.get(e.id).push(t)};if(u.length>1&&c===null){let e=Qn(u.length);u.forEach((t,n)=>{f(t.target,t.target.id),o.has(t.target.id)||o.set(t.target.id,e[n])})}else u.forEach(e=>f(e.target,c));d.forEach(e=>f(e.target,c))}),{groups:i,groupOrder:o}}function Xn(e,t,n,r,i){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;e.forEach(e=>{let n=t.get(e.id),r=(e.height||80)/2;a.set(n,Math.max(a.get(n)??0,r+Z(e,`NORTH`))),o.set(n,Math.max(o.get(n)??0,r+Z(e,`SOUTH`)))});let s=[...a.keys()].sort((e,t)=>e-t),c=s.includes(r)?r:s[0]??r,l=s.indexOf(c),u=/* @__PURE__ */ new Map;u.set(c,0);let d=/* @__PURE__ */ new Map;e.forEach(e=>{let n=t.get(e.id);d.has(n)||d.set(n,[]),d.get(n).push(e)});let f=(e,t)=>{if(!i)return o.get(e)+n+a.get(t);let r=n;return(d.get(e)??[]).forEach(e=>{(d.get(t)??[]).forEach(t=>{if(i.get(e.id)!==i.get(t.id))return;let a=(e.height||80)/2+Z(e,`SOUTH`)+n+(t.height||80)/2+Z(t,`NORTH`);r=Math.max(r,a)})}),r};for(let e=l+1;e<s.length;e++){let t=s[e-1],n=s[e];u.set(n,u.get(t)+f(t,n))}for(let e=l-1;e>=0;e--){let t=s[e+1],n=s[e];u.set(n,u.get(t)-f(n,t))}let p=1/0,m=-1/0;return s.forEach(e=>{p=Math.min(p,u.get(e)-a.get(e)),m=Math.max(m,u.get(e)+o.get(e))}),{centers:u,minY:p,maxY:m,topExtent:a,bottomExtent:o}}function Zn(e,t,n,r,i,a){let o=/* @__PURE__ */ new Map,s=e.filter(e=>!r.get(e.id)),c=s.map(e=>n.get(e.id)),l=Xn(s,n,a,c.length>0?c.reduce((e,t)=>Math.abs(t)<Math.abs(e)?t:e):0,t);s.forEach(e=>o.set(e.id,l.centers.get(n.get(e.id))));let u=/* @__PURE__ */ new Map;e.forEach(e=>{let t=r.get(e.id);t&&(u.has(t)||u.set(t,[]),u.get(t).push(e))});let d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Map;u.forEach((e,r)=>{let i=e.map(e=>n.get(e.id)).reduce((e,t)=>Math.abs(t)<Math.abs(e)?t:e);f.set(r,i),d.set(r,Xn(e,n,a,i,t))});let p=[...u.keys()].filter(e=>(i.get(e)??0)<0),m=[...u.keys()].filter(e=>(i.get(e)??0)>=0),h=(e,r)=>{let c=e=>Math.min(...u.get(e).map(e=>t.get(e.id)??0)),p=[...e].sort((e,t)=>{let n=c(e)-c(t);if(n!==0)return n;let a=i.get(e)??0,o=i.get(t)??0,s=r===-1?o-a:a-o;return s===0?e<t?-1:+(e>t):s}),m=e=>{let i=u.get(e),a=new Set(i.map(e=>t.get(e.id)??0)),o=s.filter(e=>[...a].some(n=>Math.abs(n-(t.get(e.id)??0))<=1));return o.length===0?r===-1?l.minY:l.maxY:r===-1?Math.min(...o.map(e=>l.centers.get(n.get(e.id))-(e.height||80)/2-Z(e,`NORTH`))):Math.max(...o.map(e=>l.centers.get(n.get(e.id))+(e.height||80)/2+Z(e,`SOUTH`)))},h=[];p.forEach(e=>{let c=u.get(e),p=Math.min(...c.map(e=>t.get(e.id)??0)),g=Math.max(...c.map(e=>t.get(e.id)??0)),_=d.get(e),v=m(e),y=h.find(e=>e.occupiedUntilRank<p);y||(y={edge:v,occupiedUntilRank:-1/0},h.push(y));let b=h.filter(e=>e!==y&&e.occupiedUntilRank>=p).reduce((e,t)=>r===-1?Math.min(e,t.edge):Math.max(e,t.edge),v);y.edge=b;let x=(i.get(e)??0)===0,S=f.get(e)??0,C=_.centers.get(S),w=[...l.centers.keys()].sort((e,t)=>e-t).reduce((e,t)=>e===void 0||Math.abs(t-S)<Math.abs(e-S)?t:e,void 0),T=(()=>{if(C===void 0||w===void 0)return;let e=l.centers.get(w),r=S-w;if(r===0)return e;let i=r>0,o=new Set(c.filter(e=>n.get(e.id)===S).map(e=>t.get(e.id)??0)),u=e=>[...o].some(t=>Math.abs(t-e)<=1),d=s.filter(e=>n.get(e.id)===w&&u(t.get(e.id)??0)),f=d.length?Math.max(...d.map(e=>(e.height||80)/2+Z(e,i?`SOUTH`:`NORTH`))):0,p=c.filter(e=>n.get(e.id)===S),m=p.length?Math.max(...p.map(e=>(e.height||80)/2+Z(e,i?`NORTH`:`SOUTH`))):0,h=f+a+m;return i?e+h:e-h})(),E=T!==void 0&&C!==void 0?T-C:0,D=x&&y.edge===v?E:r===-1?y.edge-a-_.maxY:y.edge+a-_.minY;c.forEach(e=>o.set(e.id,_.centers.get(n.get(e.id))+D)),y.occupiedUntilRank=g,y.edge=r===-1?_.minY+D:_.maxY+D})};return h(p,-1),h(m,1),o.forEach((e,t)=>{Number.isFinite(e)||o.set(t,l.centers.get(n.get(t)??0)??0)}),o}function Qn(e,t=!1){let n=[];if(e===2&&!t)return[0,1];if(e%2==1){let t=(e-1)/2;for(let r=0;r<e;r++)n.push(r-t)}else{let t=e/2;for(let r=0;r<e;r++)n.push(r<t?r-t:r-t+1)}return n}function $n(e,t,n,r,i){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Map,u=new Map(e.map(e=>[e.id,e])),d=e=>{let n=l.get(e);if(n)return n;let r=/* @__PURE__ */ new Set,i=[e];for(;i.length>0;){let e=i.pop(),n=u.get(e);n&&Q(n,t).forEach(e=>{r.has(e.target.id)||(r.add(e.target.id),i.push(e.target.id))})}return l.set(e,r),r},f=(e,t)=>d(t).has(e),p=/* @__PURE__ */ new Map;return e.forEach(e=>{let t=n.get(e.id)??0;p.has(t)||p.set(t,[]),p.get(t).push(e)}),[...p.keys()].sort((e,t)=>e-t).forEach(e=>{let n=p.get(e),l=new Map(n.map(e=>{let t=o.get(e.id);if(!t||t.length===0)return[e.id,0];let n=t.filter(e=>!e.cyclic),r=n.length>0?n:t,i=r.reduce((e,t)=>e+t.row,0)/r.length;return[e.id,i]})),u=e=>{let t=o.get(e)?.length??0,n=s.get(e)??0;return t>0&&n===t?3:t>1?2:+!c.has(e)};n.sort((e,t)=>u(e.id)-u(t.id)||l.get(e.id)-l.get(t.id)||(e.y??0)-(t.y??0)||(e.id<t.id?-1:+(e.id>t.id)));let d=/* @__PURE__ */ new Map;n.forEach(e=>{let n=r.get(e.id)??``;d.has(n)||d.set(n,/* @__PURE__ */ new Set);let u=d.get(n),p=Math.round(l.get(e.id)),m=p,h=0;for(;u.has(m);)h=h>0?-h:-h+1,m=p+h;u.add(m),a.set(e.id,m);let g=Q(e,t),_=Jn(g.filter(e=>!e.fromBoundary),e.id,i),v=g.filter(e=>e.fromBoundary),y=(t,n,r)=>{o.has(t.id)||o.set(t.id,[]);let i=f(e.id,t.id);o.get(t.id).push({row:m+n,cyclic:i}),n===0&&!r&&c.add(t.id),r&&s.set(t.id,(s.get(t.id)??0)+1)},b=_.map(t=>f(e.id,t.target.id)),x=b.some(Boolean)&&b.filter(e=>!e).length>1,S=0,C=x?b.map(e=>{if(!e)return 0;let t=S++;return t%2==0?Math.floor(t/2)+1:-(Math.floor(t/2)+1)}):Qn(_.length,(e.type??``).includes(`Gateway`));_.forEach((e,t)=>y(e.target,C[t],!1));let w=new Set(X(e).south.map(e=>e.id)),T=v.filter(e=>w.has(e.sourceAttacherId??``)),E=v.filter(e=>!w.has(e.sourceAttacherId??``));T.forEach((e,t)=>y(e.target,T.length-t,!0)),E.forEach((e,t)=>y(e.target,-(E.length-t),!0))})}),a}function er(e,t,n,r){let i=new Map(e.map(e=>[e.id,e])),a=/* @__PURE__ */ new Map;e.forEach(e=>{x.has(e.type??``)||[e,...e.attachers||[]].forEach(r=>{(r.outgoing||[]).forEach(r=>{let i=r.target;i&&t.has(i.id)&&(x.has(i.type??``)||(n.get(i.id)??0)<=(n.get(e.id)??0)||(a.has(i.id)||a.set(i.id,[]),a.get(i.id).push(e.id)))})})});let o=/* @__PURE__ */ new Map;return[...e].filter(e=>!x.has(e.type??``)).sort((e,t)=>(n.get(e.id)??0)-(n.get(t.id)??0)).forEach(e=>{let t=(a.get(e.id)??[]).reduce((e,t)=>{let n=i.get(t),a=o.get(t);return!n||a===void 0?e:Math.max(e,a+(n.width||100)+r.ranksep)},r.marginX);o.set(e.id,t)}),o}function tr(e,t,n){let r=e.reduce((e,n)=>Math.max(e,t.get(n.id)??0),0),i=/* @__PURE__ */ new Map;e.forEach(e=>{if(x.has(e.type??``))return;let n=t.get(e.id)??0;i.set(n,Math.max(i.get(n)??0,e.width||100))});let a=/* @__PURE__ */ new Map,o=n.marginX;for(let e=0;e<=r;e++)a.set(e,o),o+=(i.get(e)??100)+n.ranksep;return{rankX:a,rankWidth:i}}function nr(e,t,n,r,i,a){let o=e.filter(e=>!a.has(e.id)),s=/* @__PURE__ */ new Map;o.forEach(e=>s.set(e.id,[])),e.forEach(e=>{Q(e,t).forEach(t=>{s.has(e.id)&&s.get(e.id).push(t.target.id),s.has(t.target.id)&&s.get(t.target.id).push(e.id)})});let c=/* @__PURE__ */ new Map;o.forEach(e=>{let t=`${n.get(e.id)??0}:${r.get(e.id)??``}`;c.has(t)||c.set(t,[]),c.get(t).push(e.id)});for(let e=0;e<4;e++){let e=!1;if(c.forEach(t=>{if(t.length<2)return;let n=t.map(e=>i.get(e)).sort((e,t)=>e-t),r=e=>{let t=(s.get(e)??[]).map(e=>i.get(e)).filter(e=>e!==void 0);return t.length===0?i.get(e):t.reduce((e,t)=>e+t,0)/t.length};[...t].sort((e,t)=>r(e)-r(t)||i.get(e)-i.get(t)).forEach((t,r)=>{i.get(t)!==n[r]&&(e=!0),i.set(t,n[r])})}),!e)break}}function rr(e,t,n,r){let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;e.forEach(e=>{let t=n.get(e.id);t&&(a.has(t)||a.set(t,[]),a.get(t).push(e))});let o=e=>{let t=a.get(e);return!t||t.length===0?r.get(e)??0:t.reduce((e,t)=>e+(r.get(t.id)??0),0)/t.length},s=new Map(e.map(e=>[e.id,e])),c=/* @__PURE__ */ new Map,l=e=>{let n=c.get(e);if(n!==void 0)return n;let r=[],i=/* @__PURE__ */ new Set,a=e=>{i.add(e);let n=s.get(e),a=n?Q(n,t).filter(e=>!e.fromBoundary).map(e=>e.target.id):[];r.push({id:e,next:a,at:0,deepest:0})};a(e);let o=0;for(;r.length>0;){let e=r[r.length-1];if(e.at<e.next.length){let t=e.next[e.at++],n=c.get(t);n===void 0?i.has(t)||a(t):e.deepest=Math.max(e.deepest,n);continue}r.pop(),i.delete(e.id),o=s.get(e.id)?1+e.deepest:0,c.set(e.id,o);let t=r[r.length-1];t&&(t.deepest=Math.max(t.deepest,o))}return o};return e.forEach(e=>{let n=Q(e,t).filter(e=>!e.fromBoundary);if(n.length<=1)return;let r=n.map(e=>e.target.id);if(new Set(r).size!==r.length)return;let a=r.length===2?[...r].sort((e,t)=>l(t)-l(e)||o(e)-o(t)||(e<t?-1:1)):[...r].sort((e,t)=>o(e)-o(t)||(e<t?-1:+(e>t)));i.set(e.id,a)}),i}function ir(e,t,n){let r=/* @__PURE__ */ new Set;e.forEach(e=>{[e,...e.attachers||[]].forEach(n=>{(n.outgoing||[]).forEach(n=>{let i=n.target;i&&t.has(i.id)&&(r.add(e.id),r.add(i.id))})}),(e.incoming||[]).forEach(n=>{let i=n.source;i&&t.has(i.id)&&(r.add(e.id),r.add(i.id))})});let i=e.filter(e=>!r.has(e.id)&&!x.has(e.type??``)&&(e.x!==0||e.y!==0)),a=new Set(i.map(e=>e.id)),o=i.length>0?e.filter(e=>!a.has(e.id)):e,s=i.length>0?new Set(o.map(e=>e.id)):t,c=lr(o,s,n),l=[c.positions],u=e=>{let t=new Map([...e].map(([e,t])=>[e,{...t}]));return cr(o,s,t),t},d=new Map([...c.positions].map(([e,t])=>[e,{...t}]));sr(o,d,c.rows,n),l.push(u(c.positions),d,u(d));let f=l.map(e=>Hn(o,e)),p=Math.min(...f);if(l.filter((e,t)=>f[t]===p).reduce((e,t)=>$(o,t)<$(o,e)?t:e).forEach((e,t)=>c.positions.set(t,e)),i.length>0){let e=o.filter(e=>c.positions.has(e.id)),t=e.reduce((e,t)=>{let n=c.positions.get(t.id);return Math.max(e,n.y+(t.height||80))},n.marginY),r=e.reduce((e,t)=>Math.min(e,c.positions.get(t.id).x),n.marginX),a=t+n.ranksep;[...i].sort((e,t)=>e.x-t.x||e.y-t.y).forEach(e=>{c.positions.set(e.id,{x:r,y:a}),r+=(e.width||100)+n.nodesep})}return c}function ar(e,t,n){if(Cn){let t=Se(e,n,x);if(t)return t}let r=ir(e,t,n),i=Rn(e,n);if(i){let n=or(e,t);if($(e,i.positions)+n.crossings*1e3+n.through*1e3<=$(e,r.positions))return i}return r}function or(e,t){let n=[],r=/* @__PURE__ */ new Set;e.forEach(e=>{[e,...e.attachers||[]].forEach(i=>{(i.outgoing||[]).forEach(i=>{let a=i,o=a.target;if(!o||!t.has(o.id)||r.has(a.id)||x.has(e.type??``)||x.has(o.type??``))return;r.add(a.id);let s=a.waypoints??[];s.slice(1).forEach((e,t)=>n.push({id:a.id,a:s[t],b:e}))})})});let i=0;for(let e=0;e<n.length;e++)for(let t=e+1;t<n.length;t++)n[e].id!==n[t].id&&Vn(n[e].a,n[e].b,n[t].a,n[t].b)&&i++;let a=0;return n.forEach(({a:t,b:n})=>{e.forEach(e=>{if(x.has(e.type??``)||g(e))return;let r=Math.min(t.x,n.x),i=Math.max(t.x,n.x),o=Math.min(t.y,n.y),s=Math.max(t.y,n.y);r<e.x+e.width-2&&i>e.x+2&&o<e.y+e.height-2&&s>e.y+2&&a++})}),{crossings:i,through:a}}function sr(e,t,n,r){let i=e.filter(e=>!x.has(e.type??``)&&t.has(e.id));if(i.length===0)return;let a=/* @__PURE__ */ new Map;i.forEach(e=>{let r=n.get(e.id);if(r===void 0)return;let i=t.get(e.id),o=i.y-Z(e,`NORTH`),s=i.y+(e.height||80)+Z(e,`SOUTH`),c=a.get(r);c?(c.top=Math.min(c.top,o),c.bottom=Math.max(c.bottom,s),c.members.push(e)):a.set(r,{top:o,bottom:s,members:[e]})});let o=r.marginY;[...a.keys()].sort((e,t)=>e-t).forEach(e=>{let n=a.get(e),i=o-n.top;n.members.forEach(e=>{let n=t.get(e.id);t.set(e.id,{x:n.x,y:n.y+i})}),o+=n.bottom-n.top+r.nodesep})}function cr(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=e.filter(e=>(e.type??``).includes(`Gateway`)&&n.has(e.id));if(i.length===0)return;let a=e=>{let t=n.get(e.id);return{x:t.x,y:t.y,width:e.width||100,height:e.height||80}};i.forEach(i=>{let o=[];if((i.outgoing||[]).forEach(e=>{let n=e.target,i=n?r.get(n.id):void 0;i&&t.has(i.id)&&o.push(i)}),e.forEach(e=>{(e.outgoing||[]).forEach(t=>{t.target?.id===i.id&&o.push(e)})}),o.length<2)return;let s=o.map(e=>a(e).y+(e.height||80)/2),c=(Math.min(...s)+Math.max(...s))/2-(i.height||50)/2,l=n.get(i.id);if(Math.abs(c-l.y)<1)return;let u={x:l.x,y:c},d={x:u.x,y:u.y,width:i.width||50,height:i.height||50};e.some(e=>e.id!==i.id&&!x.has(e.type??``)&&n.has(e.id)&&S(d,a(e)))||n.set(i.id,u)})}function lr(e,t,n){let r=qn(e,t),i=Yn(e,t,r),a=$n(e,t,r,i.groups),o=rr(e,t,i.groups,a),{groups:s,groupOrder:c}=Yn(e,t,r,o),l=$n(e,t,r,s,o),u=Mn(e,t),d=Pn(e,u),f=Nn(e,t);nr(e,t,r,s,l,/* @__PURE__ */ new Set([...u,...f.keys()]));let p=e.filter(e=>!u.has(e.id)&&!f.has(e.id)),m=Zn(p,r,l,s,c,n.nodesep),{rankX:h,rankWidth:g}=tr(e,r,n),_=er(e,t,r,n),v=(e,t)=>(h.get(e)??0)+((g.get(e)??t)-t)/2,y=(e,t,n)=>_.get(e)??v(t,n),b=/* @__PURE__ */ new Map;p.forEach(e=>{let t=m.get(e.id);b.set(e.id,t-e.height/2)});let x=/* @__PURE__ */ new Map;e.forEach(e=>{if(!u.has(e.id))return;let t=d.get(e.id);t&&(x.has(t.id)||x.set(t.id,[]),x.get(t.id).push(e))}),x.forEach((t,r)=>{let i=e.find(e=>e.id===r),a=b.get(r)+i.height/2,o=l.get(r)??0,s=t.filter(e=>l.get(e.id)>=o),c=t.filter(e=>l.get(e.id)<o);[{list:s,edge:a+i.height/2,dir:1},{list:c,edge:a-i.height/2,dir:-1}].forEach(({list:e,edge:t,dir:r})=>{if(e.length===0)return;let i=e.map(e=>l.get(e.id)).reduce((e,t)=>Math.abs(t-o)<Math.abs(e-o)?t:e),a=Xn(e,l,n.nodesep,i),s=e.filter(e=>l.get(e.id)===i),c=Math.max(...s.map(e=>(e.height||80)/2+Z(e,r===1?`NORTH`:`SOUTH`))),u=r===1?t+n.nodesep+c:t-n.nodesep-c;e.forEach(e=>b.set(e.id,u+a.centers.get(l.get(e.id))-e.height/2))})});let S=[...b.keys()].map(t=>{let i=e.find(e=>e.id===t),a=r.get(t)??0,o=i.width<=n.ranksep-10;return{x:u.has(t)&&a>0&&o?h.get(a)-n.ranksep/2-i.width/2:y(t,a,i.width),y:b.get(t),w:i.width,h:i.height}}),C=(e,t,n,r)=>S.some(i=>e<i.x+i.w&&e+n>i.x&&t<i.y+i.h&&t+r>i.y),w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Map;f.forEach((t,n)=>{T.has(t.id)||T.set(t.id,[]),T.get(t.id).push(e.find(e=>e.id===n))}),T.forEach((t,i)=>{let a=e.find(e=>e.id===i),o={x:h.get(r.get(i)??0)??0,y:b.get(i),w:a.width,h:a.height},s=n.nodesep,c=(e,t,n,r)=>C(e-s/2,t-s/2,n+s,r+s),l=(e,t,n,r)=>{for(let i=0;i<=6;i++)for(let a of i===0?[1]:[1,-1]){let o=r===`x`?e.x+a*i*20:e.x,s=r===`y`?e.y+a*i*20:e.y;if(!c(o,s,t,n))return{x:o,y:s}}return null},u=(e,t)=>S.filter(n=>n.x<o.x+o.w+200&&n.x+n.w>o.x-200&&n.y<t&&n.y+n.h>e).length,d=u(o.y-400,o.y)<=u(o.y+o.h,o.y+o.h+400);t.forEach(e=>{let t={base:{x:o.x+o.w/2-e.width/2,y:o.y-s-e.height},axis:`x`},n={base:{x:o.x+o.w/2-e.width/2,y:o.y+o.h+s},axis:`x`},r=[...d?[t,n]:[n,t],{base:{x:o.x+o.w+s,y:o.y+o.h/2-e.height/2},axis:`y`},{base:{x:o.x-s-e.width,y:o.y+o.h/2-e.height/2},axis:`y`}],i=null;for(let{base:t,axis:n}of r)if(i=l(t,e.width,e.height,n),i)break;let{x:a,y:c}=i??r[0].base;b.set(e.id,c),w.set(e.id,a),S.push({x:a,y:c,w:e.width,h:e.height})})});let E=Math.min(0,...e.map(e=>b.get(e.id))),D=n.marginY-E,O=/* @__PURE__ */ new Map;return e.forEach(e=>{if(f.has(e.id))return;let t=r.get(e.id)??0,i=e.width<=n.ranksep-10,a=u.has(e.id)&&t>0&&i?h.get(t)-n.ranksep/2-e.width/2:y(e.id,t,e.width);O.set(e.id,{x:a,y:b.get(e.id)+D})}),f.forEach((e,t)=>{O.set(t,{x:w.get(t),y:b.get(t)+D})}),{positions:O,rows:l,ranks:r}}const ur=1e6;function dr(e,t,n,r){if(Cn){let t=Se(e,r,x);if(t)return{...t,laneBands:null}}let i=/* @__PURE__ */ new Map;n.forEach((e,t)=>i.set(e.businessObject?.id??e.id,t));let a=/* @__PURE__ */ new Map;e.forEach(e=>{(e.outgoing||[]).forEach(t=>{if(!t.target)return;let n=x.has(e.type??``),r=x.has(t.target.type??``);r&&!n&&!a.has(t.target.id)&&a.set(t.target.id,e.id),n&&!r&&!a.has(e.id)&&a.set(e.id,t.target.id)})});let o=new Map(e.map(e=>[e.id,e])),s=e=>{let t=e.businessObject?.lanes?.[0]?.id;if(t)return i.get(t)??0;let n=a.get(e.id),r=n?o.get(n):void 0;return r?s(r):0},c=/* @__PURE__ */ new Map;if(e.forEach(e=>{let t=s(e);c.has(t)||c.set(t,[]),c.get(t).push(e)}),Ln(e.filter(e=>!x.has(e.type??``)))){let t=/* @__PURE__ */ new Map;n.forEach((e,n)=>{let i=c.get(n)??[];if(i.length===0)return;let a=Rn(i,r,{x:e.x+r.marginX,y:e.y+r.marginY});a?i.forEach(n=>{let r=a.positions.get(n.id)??{x:n.x,y:n.y};t.set(n.id,{x:Math.min(Math.max(r.x,e.x),Math.max(e.x,e.x+e.width-n.width)),y:Math.min(Math.max(r.y,e.y),Math.max(e.y,e.y+e.height-n.height))})}):i.forEach(e=>t.set(e.id,{x:e.x,y:e.y}))}),e.forEach(e=>{t.has(e.id)||t.set(e.id,{x:e.x,y:e.y})});let i=new Map(e.map(e=>[e.id,{x:e.x,y:e.y}]));$(e,i)<$(e,t)&&i.forEach((e,n)=>t.set(n,e));let a=new Map([...t].map(([e,t])=>[e,t.x])),o=new Map([...t].map(([e,t])=>[e,t.y])),s=Bn(e);return{positions:t,ranks:In(s?o:a),rows:In(s?a:o),laneBands:null,authored:!0}}let l=qn(e,t),{rankX:u,rankWidth:d}=tr(e,l,r),f=(e,t)=>(u.get(e)??0)+((d.get(e)??t)-t)/2,p=/* @__PURE__ */ new Map,m=/* @__PURE__ */ new Map,h=[],g=0;n.forEach((e,t)=>{let n=c.get(t)??[];if(n.length===0){let e=r.marginY*2;h.push({y:g,height:e}),g+=e;return}let i=ar(n,new Set(n.map(e=>e.id)),r),o=0;n.forEach(e=>{let t=i.positions.get(e.id);o=Math.max(o,t.y+e.height)});let s=o+r.marginY,u=e=>x.has(e.type??``);n.forEach(e=>{if(u(e))return;let n=i.positions.get(e.id),r=l.get(e.id)??0;p.set(e.id,{x:f(r,e.width),y:g+n.y}),m.set(e.id,t*ur+(i.rows.get(e.id)??0))}),n.forEach(e=>{if(!u(e))return;let n=i.positions.get(e.id),r=a.get(e.id),o=r?i.positions.get(r):void 0,s=r?p.get(r):void 0,c=o&&s?s.x+(n.x-o.x):n.x;p.set(e.id,{x:c,y:g+n.y}),m.set(e.id,t*ur+(i.rows.get(e.id)??0))}),h.push({y:g,height:s}),g+=s});let _=e.filter(e=>!x.has(e.type??``)).map(e=>{let t=p.get(e.id);return{x:t.x,y:t.y,w:e.width,h:e.height}}),v=(e,t,n,r)=>_.some(i=>e<i.x+i.w&&e+n>i.x&&t<i.y+i.h&&t+r>i.y);return e.filter(e=>x.has(e.type??``)).forEach(e=>{let t=p.get(e.id),n=t;if(v(t.x,t.y,e.width,e.height))outer:for(let r=1;r<=15;r++)for(let i of[1,-1]){let a=t.x+i*r*20;if(!v(a,t.y,e.width,e.height)){n={x:a,y:t.y};break outer}}p.set(e.id,n),_.push({x:n.x,y:n.y,w:e.width,h:e.height})}),{positions:p,rows:m,ranks:l,laneBands:h}}function fr(e,t,n){let r=n.get(e),i=n.get(t);return r===void 0||i===void 0?!1:i<=r}function pr(e,t,n,r=!1,i){let a=[],o=(e,t)=>!i||i.has(e)||i.has(t),s=0;return e.forEach(e=>{x.has(e.type??``)||((e.outgoing||[]).forEach(i=>{let c=i.target;c&&t.has(c.id)&&!x.has(c.type??``)&&(r||!fr(e.id,c.id,n))&&o(e.id,c.id)&&a.push({id:`le${s++}`,sourceId:e.id,targetId:c.id,conn:i})}),(e.attachers||[]).forEach(e=>{(e.outgoing||[]).forEach(i=>{let c=i.target;c&&t.has(c.id)&&(r||!fr(e.id,c.id,n))&&o(e.id,c.id)&&a.push({id:`le${s++}`,sourceId:e.id,targetId:c.id,conn:i})})}))}),a}function mr(e,t,n){let r=[],i=/* @__PURE__ */ new Set,a=e=>{if(i.has(e.id))return;i.add(e.id);let a=t.get(e.id);if(!a||a.width<=0||a.height<=0)return;let o=n?.get(e.id);r.push({id:e.id,x:a.x,y:a.y,width:a.width,height:a.height,...o?{ports:o}:{}})};return e.forEach(e=>{a(e),(e.attachers||[]).forEach(e=>a(e))}),r}function hr(e,t,n=.5){switch(t){case`EAST`:return{x:e.width,y:e.height*n};case`WEST`:return{x:0,y:e.height*n};case`NORTH`:return{x:e.width*n,y:0};case`SOUTH`:return{x:e.width*n,y:e.height}}}function gr(e,t){let n=t.x-(e.x+e.width),r=e.x-(t.x+t.width),i=t.y-(e.y+e.height),a=e.y-(t.y+t.height),o=Math.max(n,r);return o>=0||o>=Math.max(i,a)?n>=r?{from:`EAST`,to:`WEST`}:{from:`WEST`,to:`EAST`}:i>=a?{from:`SOUTH`,to:`NORTH`}:{from:`NORTH`,to:`SOUTH`}}function _r(e,t,n,r,i){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;e.forEach(e=>{a.set(e.sourceId,(a.get(e.sourceId)??0)+1),o.set(e.targetId,(o.get(e.targetId)??0)+1)});let s=new Set(n.flatMap(e=>(e.attachers||[]).map(e=>e.id))),c=/* @__PURE__ */ new Map;n.forEach(e=>{let{south:t,north:n}=X(e);t.forEach(e=>c.set(e.id,`SOUTH`)),n.forEach(e=>c.set(e.id,`NORTH`))});let l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;e.forEach(e=>{let n=t.get(e.sourceId),r=t.get(e.targetId),d=(a.get(e.sourceId)??0)>1,f=(o.get(e.targetId)??0)>1;if(s.has(e.sourceId)?l.set(e.id,c.get(e.sourceId)??`SOUTH`):d?n!==void 0&&r!==void 0&&l.set(e.id,r<n?`NORTH`:r>n?`SOUTH`:`EAST`):l.set(e.id,`EAST`),f)n!==void 0&&r!==void 0&&u.set(e.id,n<r?`NORTH`:n>r?`SOUTH`:`WEST`);else{let t=i.get(e.sourceId),n=i.get(e.targetId),r=t&&n?t.x+t.width/2-(n.x+n.width/2):0,a=t&&n?t.y+t.height/2-(n.y+n.height/2):0;t&&n&&Math.abs(a)>Math.abs(r)*3?u.set(e.id,a>0?`SOUTH`:`NORTH`):u.set(e.id,`WEST`)}});let d=e=>Math.abs((t.get(e.targetId)??0)-(t.get(e.sourceId)??0)),f=/* @__PURE__ */ new Map;return e.forEach(e=>{if(!r.has(e.sourceId))return;let t=l.get(e.id);if(t!==`NORTH`&&t!==`SOUTH`)return;let n=`${e.sourceId}:${t}`;f.has(n)||f.set(n,[]),f.get(n).push(e)}),f.forEach(e=>{e.length<=1||[...e].sort((e,t)=>d(t)-d(e)).slice(1).forEach(e=>l.set(e.id,`EAST`))}),{sourceSideByEdge:l,targetSideByEdge:u}}function vr(e,t,n){let r=new Set(t.flatMap(e=>(e.attachers||[]).map(e=>e.id))),i=/* @__PURE__ */ new Map;t.forEach(e=>{let{south:t,north:n}=X(e);t.forEach(e=>i.set(e.id,`SOUTH`)),n.forEach(e=>i.set(e.id,`NORTH`))});let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map;return e.forEach(e=>{s.set(e.sourceId,(s.get(e.sourceId)??0)+1),c.set(e.targetId,(c.get(e.targetId)??0)+1)}),e.forEach(e=>{let t=n.get(e.sourceId),l=n.get(e.targetId);if(!t||!l)return;let{from:u,to:d}=gr(t,l),f=u;if((s.get(e.sourceId)??0)>1){let e=l.y+l.height/2-(t.y+t.height/2);Math.abs(e)>t.height/2&&(f=e>0?`SOUTH`:`NORTH`)}let p=d;if((c.get(e.targetId)??0)>1){let e=t.y+t.height/2-(l.y+l.height/2);Math.abs(e)>l.height/2&&(p=e>0?`SOUTH`:`NORTH`)}a.set(e.id,r.has(e.sourceId)?i.get(e.sourceId)??f:f),o.set(e.id,p)}),{sourceSideByEdge:a,targetSideByEdge:o}}function yr(e,t){let n=0;for(let r=0;r+1<e.length;r++){let i=p(e[r],e[r+1]);i&&t.some(e=>d(i,e))&&(n+=1)}return n}const br=[{nudgeOrthogonalSegmentsConnectedToShapes:!1,performUnifyingNudgingPreprocessingStep:!1},{nudgeOrthogonalSegmentsConnectedToShapes:!0,performUnifyingNudgingPreprocessingStep:!1},{nudgeOrthogonalSegmentsConnectedToShapes:!1,performUnifyingNudgingPreprocessingStep:!0},{nudgeOrthogonalSegmentsConnectedToShapes:!0,performUnifyingNudgingPreprocessingStep:!0}];async function xr(e,t,n,r,i,a){let o=null,s=1/0;for(let[c,l]of br.entries()){if(G(),c>0&&!oe())break;await se();let u;try{u=await Sr(e,t,n,r,{crossingPenalty:700,idealNudgingDistance:16,nudgeSharedPathsWithCommonEndPoint:!0,nudgeOrthogonalTouchingColinearSegments:!0,...l},i,a,c===0)}catch(e){if(!(e instanceof pe))throw e;if(c===0)throw new V(U()?.limitMs??0);break}let d=[...u.routes.values()].map(e=>[e.sourcePoint,...e.bendPoints,e.targetPoint]),f=0,p=0;for(let e=0;e<d.length;e++)for(let t=e+1;t<d.length;t++)N(d[e],d[t])>0&&(f+=1),b(d[e],d[t])&&(p+=1);let m=[...t.values()],h=d.reduce((e,t)=>e+yr(t,m),0),g=f*3e3+p*1500+h*6e3;g<s&&(s=g,o=u)}return o}async function Sr(e,t,n,r,i,a=!1,o,s=!0){let c=pr(e,new Set(e.map(e=>e.id)),r,a,o),l=new Map(c.map(e=>[e.id,{connection:e.conn}])),u=new Set(e.filter(e=>(e.type??``).includes(`Gateway`)).map(e=>e.id)),d=new Set(e.filter(e=>(e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`)).map(e=>e.id)),{sourceSideByEdge:f,targetSideByEdge:p}=a?vr(c,e,t):_r(c,n,e,d,t),m=/* @__PURE__ */ new Map;c.forEach(e=>{let t=f.get(e.id),n=p.get(e.id);if(t){let n=`${e.sourceId}:${t}:source`;m.has(n)||m.set(n,[]),m.get(n).push(`${e.id}:source`)}if(n){let t=`${e.targetId}:${n}:target`;m.has(t)||m.set(t,[]),m.get(t).push(`${e.id}:target`)}});let h=/* @__PURE__ */ new Set;m.forEach((e,t)=>{let[n,r,i]=t.split(`:`),a=i===`source`?`target`:`source`;m.has(`${n}:${r}:${a}`)&&h.add(`${n}:${r}`)});let g=/* @__PURE__ */ new Map,_=/* @__PURE__ */ new Map,v=(e,t,n,r)=>{g.has(e)||g.set(e,[]);let i=g.get(e),a=i.find(e=>e.id===t);if(a)return a.id;let o={...n};for(;i.some(e=>Math.abs(e.x-o.x)<.5&&Math.abs(e.y-o.y)<.5);)r===`NORTH`||r===`SOUTH`?o.x+=.5:o.y+=.5;return i.push({id:t,...o,properties:{"port.side":r}}),t};m.forEach((e,n)=>{let[r,i,a]=n.split(`:`),o=t.get(r);if(!o)return;let s=!u.has(r)&&h.has(`${r}:${i}`),c=e.length>1,l=s?a===`target`?[0,.5]:[.5,1]:[0,1],d=t=>c?l[0]+(l[1]-l[0])*(t+1)/(e.length+1):s?a===`target`?.4:.6:.5;e.forEach((e,t)=>{let n=c?`${r}__${i}__${a}__${t}`:`${r}__${i}__${a}`,s=v(r,n,hr(o,i,d(t)),i);_.set(e,s)})});let y={id:`root`,children:mr(e,t,g),edges:c.map(e=>({id:e.id,sources:[_.get(`${e.id}:source`)??e.sourceId],targets:[_.get(`${e.id}:target`)??e.targetId]}))},b=e=>{let n=t.get(e);return n?{x:n.x+n.width/2,y:n.y+n.height/2}:{x:0,y:0}},x=de(c.map(e=>({from:b(e.sourceId),to:b(e.targetId),source:e.sourceId,target:e.targetId}))),S=i.performUnifyingNudgingPreprocessingStep===!0;if(fe(x,e.length,S)>(U()?.remaining()??1/0)*(s?1:.5))throw new pe;let C=await R(y,i),w=e=>{if(!e)return!1;let t=[e.sourcePoint,...e.bendPoints,e.targetPoint];return t.some((e,n)=>n>0&&Math.abs(e.x-t[n-1].x)>1&&Math.abs(e.y-t[n-1].y)>1)},T=new Set(c.filter(e=>w(C.get(e.id))).map(e=>e.id));if(T.size>0){let n={id:`root`,children:mr(e,t,g),edges:c.map(e=>({id:e.id,sources:[T.has(e.id)?e.sourceId:_.get(`${e.id}:source`)??e.sourceId],targets:[T.has(e.id)?e.targetId:_.get(`${e.id}:target`)??e.targetId]}))},r=await R(n,i);T.forEach(e=>{let t=r.get(e);t&&C.set(e,t)})}return{routes:C,edgeMeta:l}}function Cr(e,t,n){if(e.length<3)return e;let r=e.length,i=e[r-1],a=e[r-2],o=e[r-3],s=Math.abs(i.x-t.x)<.5||Math.abs(i.x-(t.x+t.width))<.5,c=Math.abs(i.y-t.y)<.5||Math.abs(i.y-(t.y+t.height))<.5,l=Math.abs(i.x-a.x)<.5&&Math.abs(i.y-a.y)>.5,u=Math.abs(i.y-a.y)<.5&&Math.abs(i.x-a.x)>.5,d=Math.abs(a.y-o.y)<.5&&Math.abs(a.x-o.x)>.5,f=Math.abs(a.x-o.x)<.5&&Math.abs(a.y-o.y)>.5;if(s&&l&&d){let t={x:o.x,y:i.y};if(!q(o,t,n)&&!q(t,i,n)){let n=[...e];return n[r-2]=t,n}}if(c&&u&&f){let t={x:i.x,y:o.y};if(!q(o,t,n)&&!q(t,i,n)){let n=[...e];return n[r-2]=t,n}}return e}function wr(e){return(e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`)}function Tr(e,t){let n=Math.abs(e.x-t.x)<.5||Math.abs(e.x-(t.x+t.width))<.5,r=Math.abs(e.y-t.y)<.5||Math.abs(e.y-(t.y+t.height))<.5;return n&&!r?`horizontal`:r&&!n?`vertical`:null}function Er(e,t,n,r){let i=e.y===t.y;if(i===(n.y===r.y))return!1;let a=i?{y:e.y,x1:Math.min(e.x,t.x),x2:Math.max(e.x,t.x)}:{y:n.y,x1:Math.min(n.x,r.x),x2:Math.max(n.x,r.x)},o=i?{x:n.x,y1:Math.min(n.y,r.y),y2:Math.max(n.y,r.y)}:{x:e.x,y1:Math.min(e.y,t.y),y2:Math.max(e.y,t.y)};return o.x>a.x1&&o.x<a.x2&&a.y>o.y1&&a.y<o.y2}function Dr(e,t){for(let n=0;n+1<e.length;n++)for(let r of t)for(let t=0;t+1<r.length;t++)if(Er(e[n],e[n+1],r[t],r[t+1]))return!0;return!1}function Or(e,t,n){for(let n=0;n+1<e.length;n++)if(q(e[n],e[n+1],t))return!1;return!Dr(e,n)}function kr(e,t,n,r,i){if(e.length!==3)return null;let a=e[0],o=e[2],s=Tr(a,t),c=Tr(o,n);if(s===`horizontal`&&c===`horizontal`&&Math.abs(a.y-o.y)>.5){let e=(a.x+o.x)/2,t=[a,{x:e,y:a.y},{x:e,y:o.y},o];return Or(t,r,i)?t:null}if(s===`vertical`&&c===`vertical`&&Math.abs(a.x-o.x)>.5){let e=(a.y+o.y)/2,t=[a,{x:a.x,y:e},{x:o.x,y:e},o];return Or(t,r,i)?t:null}return null}function Ar(e,t,n,r,i,a,o){let s=e;if(n&&(s=Ve(s,n,o,!1,r)),t&&(s=Ve(s,t,a,!0,r)),t&&n){let e=kr(s,t,n,r,i);if(e)return e}return n&&(s=Cr(s,n,r)),t&&(s=[...Cr([...s].reverse(),t,r)].reverse()),s}function jr(e,t,n,r){if(!t||!n||e.length<2)return e;let i=e[0],a=e[e.length-1],o=Math.abs(i.x-(t.x+t.width))<.5,s=Math.abs(a.x-n.x)<.5;if(!o||!s||n.x<=t.x+t.width)return e;if(Math.abs(i.y-a.y)<.5)return[i,a];let c=Math.round((t.x+t.width+n.x)/2),l=[i,{x:c,y:i.y},{x:c,y:a.y},a];for(let t=0;t+1<l.length;t++)if(q(l[t],l[t+1],r))return e;return l}function Mr(e,t,n){let r=e.label,i=e.waypoints??[];if(!r||i.length<2||t.length<2)return;let a=e=>{let t=Math.floor(e.length/2);if(e.length%2==1)return e[t];let n=e[t-1],r=e[t];return{x:(n.x+r.x)/2,y:(n.y+r.y)/2}},o=a(i),s=a(t),c=s.x-o.x,l=s.y-o.y;Math.abs(c)<1&&Math.abs(l)<1||n.moves.push({elements:[r],dx:c,dy:l})}function Nr(e){let t=0;for(let n=1;n<e.length-1;n++){let r=e[n-1],i=e[n],a=e[n+1];Math.abs((i.x-r.x)*(a.y-i.y)-(i.y-r.y)*(a.x-i.x))>1&&t++}return t}function Pr(e,t,n,r){if(!t||!n||Nr(e)<2)return e;let i={x:t.x+t.width/2,y:t.y+t.height/2},a={x:n.x+n.width/2,y:n.y+n.height/2},o=a.x>=i.x?t.x+t.width:t.x,s=a.y>=i.y?t.y+t.height:t.y,c=i.x>=a.x?n.x+n.width:n.x,l=i.y>=a.y?n.y+n.height:n.y,u=Math.abs(i.y-a.y)<=1,d=Math.abs(i.x-a.x)<=1,f=[];u&&f.push([{x:o,y:i.y},{x:c,y:i.y}]),d&&f.push([{x:i.x,y:s},{x:i.x,y:l}]),f.push([{x:o,y:i.y},{x:a.x,y:i.y},{x:a.x,y:l}]),f.push([{x:i.x,y:s},{x:i.x,y:a.y},{x:c,y:a.y}]);let p=e=>e.slice(1).every((i,a)=>{let o=e[a],s=Math.min(o.x,i.x),c=Math.max(o.x,i.x),l=Math.min(o.y,i.y),u=Math.max(o.y,i.y);return r.every(e=>e===t||e===n||!(s<e.x+e.width-2&&c>e.x+2&&l<e.y+e.height-2&&u>e.y+2))}),m=(e,t)=>Math.abs(e.x-t.x)<.5?`W`:Math.abs(e.x-(t.x+t.width))<.5?`E`:Math.abs(e.y-t.y)<.5?`N`:Math.abs(e.y-(t.y+t.height))<.5?`S`:`?`,h=m(e[0],t),g=m(e[e.length-1],n),_=e=>m(e[0],t)===h&&m(e[e.length-1],n)===g;return f.find(t=>Nr(t)<Nr(e)&&_(t)&&p(t))??e}function Fr(e,t){let n=[...e],r=0;for(;r+3<n.length;){let[e,i,a,o]=[n[r],n[r+1],n[r+2],n[r+3]],s=Math.abs(i.x-a.x),c=Math.abs(i.y-a.y),l=e.x===i.x&&a.x===o.x&&i.y===a.y&&s>.5&&s<40,u=e.y===i.y&&a.y===o.y&&i.x===a.x&&c>.5&&c<40;if(l){let i={x:o.x,y:e.y};if(!q(e,i,t)&&!q(i,o,t)){n.splice(r,4,i,o);continue}}if(u){let i={x:e.x,y:o.y};if(!q(e,i,t)&&!q(i,o,t)){n.splice(r,4,i,o);continue}}r++}return n.filter((e,t)=>t===0||e.x!==n[t-1].x||e.y!==n[t-1].y)}function Ir(e){return(e.children||[]).filter(e=>e.type===`bpmn:Lane`).sort((e,t)=>e.y-t.y||(e.id<t.id?-1:1))}function Lr(e,t,n,r){let i=/* @__PURE__ */ new Map;return t.forEach(e=>Q(e,n).forEach(t=>{let n=r(e),a=r(t.target);if(!n||!a||n===a)return;let o=Le(n,a);i.set(o,(i.get(o)??0)+1)})),Re(e,e=>e.businessObject?.id??e.id,i)}function Rr(e,t,n,r,i,a){if(t.length===0)return;let o=/* @__PURE__ */ new Map;n.forEach(e=>{let t=e.businessObject?.lanes?.[0]?.id;t&&o.set(e.id,t)});let s=e=>e.businessObject?.id??e.id,c=e=>{let t=Ir(e);if(t.length)return t.flatMap(c);let i=s(e);return n.filter(e=>o.get(e.id)===i&&r.has(e.id))},l=(e,t)=>{let n=r.get(e.id);!n||Math.abs(t)<.5||(a.moves.push({elements:[e],dx:0,dy:t}),r.set(e.id,{...n,y:n.y+t}),(e.attachers||[]).forEach(e=>{let n=r.get(e.id);n&&(a.moves.push({elements:[e],dx:0,dy:t}),r.set(e.id,{...n,y:n.y+t}))}))},u=(e,t,o,s)=>{let d=s;return e.forEach(e=>{let s=Lr(Ir(e),n,new Set(n.map(e=>e.id)),t=>{let n=t.businessObject?.lanes?.[0]?.id;return Ir(e).some(e=>(e.businessObject?.id??e.id)===n)?n:void 0}),f=o-30,p;if(s.length)p=u(s,t+30,f,d)-d;else{let t=c(e);if(t.length){t.map(e=>r.get(e.id));let e=t.map(e=>{let t=r.get(e.id),n=(e.attachers||[]).map(e=>r.get(e.id)).filter(e=>!!e);return{top:Math.min(t.y,...n.map(e=>e.y)),bottom:Math.max(t.y+t.height,...n.map(e=>e.y+e.height))}}),n=Math.min(...e.map(e=>e.top));p=Math.max(...e.map(e=>e.bottom))-n+i.nodesep*2;let a=d+i.nodesep-n;t.forEach(e=>l(e,a))}else p=i.nodesep*2+40}a.resizes.push({element:e,x:t,y:d,width:o,height:p}),r.set(e.id,{x:t,y:d,width:o,height:p}),d+=p}),d},d=Lr(t,n,new Set(n.map(e=>e.id)),e=>{let n=e.businessObject?.lanes?.[0]?.id;if(!n)return;let r=t.find(e=>(e.businessObject?.id??e.id)===n);for(;r&&r.parent&&r.parent.type===`bpmn:Lane`&&!t.includes(r);)r=r.parent;return r?r.businessObject?.id??r.id:n}),f=n.filter(e=>!x.has(e.type??``)&&r.get(e.id)),p=f.length>0?f:n.filter(e=>r.get(e.id)),m=Math.min(...p.map(e=>r.get(e.id).x))-i.marginX,h=Math.max(...p.map(e=>r.get(e.id).x+r.get(e.id).width))+i.marginX-m,g=Math.min(...p.map(e=>r.get(e.id).y))-i.marginY,_=u(d,m,h,g);a.resizes.push({element:e,x:m-30,y:g,width:h+30,height:_-g})}function zr(e,t,n,r,i,a,o,s){let c=[];e.forEach(e=>{(e.outgoing||[]).forEach(t=>{let n=t.target;if(!n)return;let r=x.has(e.type??``);r!==x.has(n.type??``)&&c.push({real:r?n:e,annotation:r?e:n,conn:t,elIsAnn:r})})});let l=(e,t)=>t.y>=e.y+e.height?`SOUTH`:t.y+t.height<=e.y?`NORTH`:t.x>=e.x+e.width?`EAST`:`WEST`,u=/* @__PURE__ */ new Map;c.forEach(e=>{let t=n.get(e.real.id),r=n.get(e.annotation.id);if(!t||!r)return;let i=`${e.real.id}:${l(t,r)}`;u.has(i)||u.set(i,[]),u.get(i).push(e)}),c.forEach(e=>{let t=n.get(e.real.id),r=n.get(e.annotation.id);if(!t||!r)return;let i=l(t,r),a=u.get(`${e.real.id}:${i}`)??[e],s=.5;if(a.length>1&&!wr(e.real)){let t=[...a].sort((e,t)=>{let r=n.get(e.annotation.id),a=n.get(t.annotation.id);return(i===`NORTH`||i===`SOUTH`?r.x+r.width/2:r.y+r.height/2)-(i===`NORTH`||i===`SOUTH`?a.x+a.width/2:a.y+a.height/2)||(e.annotation.id<t.annotation.id?-1:1)});s=(t.findIndex(t=>t.annotation.id===e.annotation.id)+1)/(t.length+1)}let c=Fe(t,r,s),d=e.elIsAnn?[...c].reverse():c;o.routes.push({connection:e.conn,waypoints:d})});let d=0,f=0,p=(e,c)=>{let l=c.target;if(!l||!t.has(l.id)||x.has(l.type??``)||i||!fr(e,l.id,r))return;let u=n.get(e),p=n.get(l.id);if(!u||!p)return;let m=u.x+u.width/2,h=p.x+p.width/2,g=a+s.nodesep+d*s.nodesep;f=Math.max(f,g),o.routes.push({connection:c,waypoints:[{x:m,y:u.y+u.height},{x:m,y:g},{x:h,y:g},{x:h,y:p.y+p.height}]}),d+=1};return e.forEach(e=>{x.has(e.type??``)||((e.outgoing||[]).forEach(t=>p(e.id,t)),(e.attachers||[]).forEach(e=>(e.outgoing||[]).forEach(t=>p(e.id,t))))}),f}async function Br(e,t,n,r,i,a,o,s,c){let l=c,u=l?{positions:new Map(t.filter(e=>l.positions.has(e.id)).map(e=>[e.id,l.positions.get(e.id)])),sizes:l.sizes,padding:l.padding}:void 0,d=u&&u.positions.size===t.length?u:void 0,f=Se(t,a,x,d);if(f){let l=we(t,f.positions,o,e=>[e],s);for(let e of t){if((e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`).length===0)continue;let t=f.positions.get(e.id)??{x:e.x,y:e.y},n=d?.positions.get(e.id)??{x:e.x,y:e.y},r=l.rects.get(e.id);await Vr(e,a,r?{x:r.x,y:r.y}:null,o,[],{x:s.x+t.x-n.x,y:s.y+t.y-n.y},c)}let u=new Map(o.resizes.map(e=>[e.element.id,e]));t.forEach(e=>{let t=u.get(e.id);t&&l.rects.set(e.id,{x:t.x,y:t.y,width:t.width,height:t.height})}),t.forEach(e=>{let t=l.rects.get(e.id);if(!t)return;let{south:n,north:r}=X(e),i=(n,r)=>{if(n.length===0)return;let i=On(e,t.width);n.forEach(e=>{let n=e.width||36,a=e.height||36,s=Math.round(t.x+i.get(e.id)-n/2),c=Math.round(r-a/2);(s!==e.x||c!==e.y)&&o.moves.push({elements:[e],dx:s-e.x,dy:c-e.y}),l.rects.set(e.id,{x:s,y:c,width:n,height:a})})};i(n,t.y+t.height),i(r,t.y)}),i&&Rr(e,n,t,l.rects,a,o);let{routes:p,edgeMeta:m}=await xr(t,l.rects,f.rows,f.ranks,!0,d?void 0:l.movedIds),h=[...l.rects.values()],_=(e,t,n)=>t?Math.abs(e.x-t.x)<.5?`${n}:W`:Math.abs(e.x-(t.x+t.width))<.5?`${n}:E`:Math.abs(e.y-t.y)<.5?`${n}:N`:`${n}:S`:``,v=/* @__PURE__ */ new Map;p.forEach((e,t)=>{let n=m.get(t);if(!n)return;let r=n.connection.source,i=n.connection.target;[_(e.sourcePoint,r?l.rects.get(r.id):void 0,r?.id??``),_(e.targetPoint,i?l.rects.get(i.id):void 0,i?.id??``)].forEach(e=>{e&&v.set(e,(v.get(e)??0)+1)})});let y=(e,t,n)=>(v.get(_(e,t,n))??0)<=1,b=new Map([...p.entries()].map(([e,t])=>[e,[t.sourcePoint,...t.bendPoints,t.targetPoint]])),x=new Set([...m.values()].map(e=>e.connection.id));return Hr(t,l.rects,o,x),p.forEach((e,t)=>{let n=m.get(t);if(!n)return;let r=n.connection.source?l.rects.get(n.connection.source.id):void 0,i=n.connection.target?l.rects.get(n.connection.target.id):void 0,a=[...b.entries()].filter(([e])=>e!==t).map(([,e])=>e),s=Fr(b.get(t),h),c=He(jr(Pr(Ar(s,r,i,h,a,n.connection.source?wr(n.connection.source)&&y(s[0],r,n.connection.source.id):!1,n.connection.target?wr(n.connection.target)&&y(s[s.length-1],i,n.connection.target.id):!1),r,i,h),r,i,h),r,i,h),u=e=>{let t=0;for(let n=0;n+1<e.length;n++)q(e[n],e[n+1],h)&&t++;return t},d=u(c)>u(s)?s:c;Mr(n.connection,d,o),o.routes.push({connection:n.connection,waypoints:d})}),i||Te(e,l.rects,r,a,o,(e=>({x:e.x+s.x,y:e.y+s.y,width:e.width,height:e.height}))(e),!!d),{size:l.size,flowNodes:t,laned:i,authored:!0}}return null}async function Vr(e,t,n,r,i=[],a={x:0,y:0},o=null){let s=(e,t)=>e.id<t.id?-1:+(e.id>t.id),c=(e.children||[]).filter(e=>e.type===`bpmn:Lane`),l=(e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),u=[...l,...i].sort(s);if(u.length===0)return null;let d=new Set(u.map(e=>e.id)),f=new Set(l.filter(e=>!x.has(e.type??``)).map(e=>e.id)),p=c.length>0;if(Cn){let n=await Br(e,u,c,f,p,t,r,a,o);if(n)return n}let{positions:m,rows:h,ranks:_,laneBands:v,authored:y}=p?dr(u,d,c,t):{...ar(u,d,t),laneBands:null};if(y&&e.width>0&&e.height>0){let n=e.x+a.x,i=e.y+a.y,o=t.marginY/2,s=0,c=0;u.forEach(t=>{let r=m.get(t.id);if(!r)return;let l=n+o-a.x,u=i+o-a.y,d={x:Math.max(r.x,l),y:Math.max(r.y,u)};m.set(t.id,d),s=Math.max(s,d.x+a.x+t.width+o-(n+e.width)),c=Math.max(c,d.y+a.y+t.height+o-(i+e.height))}),(s>0||c>0)&&r.resizes.push({element:e,x:n,y:i,width:e.width+Math.max(0,s),height:e.height+Math.max(0,c)})}u.forEach(e=>{let t=m.get(e.id);t&&(Number.isFinite(t.x)&&Number.isFinite(t.y)||m.set(e.id,{x:Number.isFinite(t.x)?t.x:e.x,y:Number.isFinite(t.y)?t.y:e.y}))});let b=/* @__PURE__ */ new Map,S=0,C=0,T=0;u.forEach(e=>{let t=m.get(e.id);if(e.label){let n=t.x+(e.label.x-e.x);T=Math.max(T,-n)}}),u.forEach(e=>{let t=m.get(e.id),i=y?t.x:t.x+(n?.x??0)+T,o=y?t.y:t.y+(n?.y??0),s=i-e.x,c=o-e.y;if((s!==0||c!==0)&&r.moves.push({elements:jn(e),dx:s,dy:c}),b.set(e.id,{x:i+a.x,y:o+a.y,width:e.width,height:e.height}),y){(e.attachers||[]).forEach(e=>{b.set(e.id,{x:e.x+s+a.x,y:e.y+c+a.y,width:e.width,height:e.height})}),S=Math.max(S,i+e.width),C=Math.max(C,o+e.height+Z(e,`SOUTH`)),e.label&&(S=Math.max(S,i+(e.label.x+e.label.width-e.x)),C=Math.max(C,o+(e.label.y+e.label.height-e.y)));return}let{south:l,north:u}=X(e);[{list:l,y:o+e.height},{list:u,y:o}].forEach(({list:t,y:n})=>{let a=t.reduce((e,t)=>e+t.width,0)+6*Math.max(0,t.length-1),o=i+e.width/2-a/2;t.forEach(e=>{let t=o,i=n-e.height/2;b.set(e.id,{x:t,y:i,width:e.width,height:e.height});let a=t-(e.x+s),l=i-(e.y+c);(a!==0||l!==0)&&r.moves.push({elements:[e],dx:a,dy:l}),o+=e.width+6})}),S=Math.max(S,i+e.width),C=Math.max(C,o+e.height+Z(e,`SOUTH`)),e.label&&(S=Math.max(S,i+(e.label.x+e.label.width-e.x)),C=Math.max(C,o+(e.label.y+e.label.height-e.y)))});let E=zr(u,d,b,_,!!y,C,r,t);C=Math.max(C,E);for(let e of u){if((e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`).length===0)continue;let n=b.get(e.id);if(!n)continue;let i=r.resizes.length;await Vr(e,t,{x:n.x,y:n.y},r,[],{x:n.x-e.x,y:n.y-e.y},o);let a=r.resizes.slice(i).find(t=>t.element===e);a&&(b.set(e.id,{x:a.x,y:a.y,width:a.width,height:a.height}),S=Math.max(S,a.x+a.width),C=Math.max(C,a.y+a.height))}let D=new Set(u.filter(e=>{let t=b.get(e.id);return!!t&&(Math.abs(t.x-e.x)>1||Math.abs(t.y-e.y)>1)}).map(e=>e.id));if(y){let e=u.filter(e=>!x.has(e.type??``)).map(e=>({id:e.id,rect:b.get(e.id)})).filter(e=>!!e.rect);u.forEach(t=>{[t,...t.attachers||[]].forEach(n=>{(n.outgoing||[]).forEach(r=>{let i=r,a=i.target;if(!a||x.has(a.type??``)||x.has(t.type??``))return;let o=i.waypoints??[];o.slice(1).some((t,r)=>{let i=o[r],s=Math.min(i.x,t.x),c=Math.max(i.x,t.x),l=Math.min(i.y,t.y),u=Math.max(i.y,t.y);return e.some(({id:e,rect:t})=>e===n.id||e===a.id?!1:s<t.x+t.width-2&&c>t.x+2&&l<t.y+t.height-2&&u>t.y+2)})&&(D.add(n.id),D.add(a.id))})})})}let{routes:O,edgeMeta:k}=await xr(u,b,h,_,y===!0,y===!0?D:void 0),A=[...b.values()],M=new Map([...O.entries()].map(([e,t])=>[e,[t.sourcePoint,...t.bendPoints,t.targetPoint]])),N=new Set([...k.values()].map(e=>e.connection.id));y&&Hr(u,b,r,N),O.forEach((e,t)=>{let n=k.get(t);if(!n)return;let i=n.connection.source?b.get(n.connection.source.id):void 0,a=n.connection.target?b.get(n.connection.target.id):void 0,o=[...M.entries()].filter(([e])=>e!==t).map(([,e])=>e),s=Fr(M.get(t),A),c=n.connection.source?wr(n.connection.source):!1,l=n.connection.target?wr(n.connection.target):!1,u=Pr(Ar(s,i,a,A,o,c,l),i,a,A);Mr(n.connection,u,r),r.routes.push({connection:n.connection,waypoints:u})});let P=n?.x??0,F=n?.y??0;if(v){let i=n?F-40:0,a=S+40,o=v.reduce((e,t)=>e+t.height,0),s=Math.max(o,E+t.nodesep-i),l=s-o;l>0&&(v[v.length-1].height+=l);let u=s;C=Math.max(C,i+u),r.resizes.push({element:e,x:0,y:i,width:a,height:u}),c.forEach((e,t)=>{let n=v[t];r.resizes.push({element:e,x:0,y:i+n.y,width:a,height:n.height})})}return{size:{width:S-P,height:C-F},flowNodes:u,laned:p,authored:y===!0}}function Hr(e,t,n,r){let i=e=>{let n=e?t.get(e.id):void 0;return!e||!n?{x:0,y:0}:{x:n.x-e.x,y:n.y-e.y}},a=/* @__PURE__ */ new Set;e.forEach(e=>{[e,...e.attachers||[]].forEach(e=>{(e.outgoing||[]).forEach(t=>{let o=t;if(a.has(o.id)||(a.add(o.id),r?.has(o.id)))return;let s=o.waypoints??[];if(s.length<2)return;let c=i(o.source??e),l=i(o.target),u=s.length-1,d=s.map((e,t)=>{let n=u===0?0:t/u;return{x:e.x+c.x+(l.x-c.x)*n,y:e.y+c.y+(l.y-c.y)*n}});for(let e=1;e<d.length;e++){let t=e===d.length-1?2:20;Math.abs(d[e].x-d[e-1].x)<=t?d[e].x=d[e-1].x:Math.abs(d[e].y-d[e-1].y)<=t&&(d[e].y=d[e-1].y)}Mr(o,d,n),n.routes.push({connection:o,waypoints:d})})})})}function Ur(e){let t=[];return(e.outgoing||[]).forEach(e=>{e.target&&!x.has(e.target.type??``)&&t.push(e.target.id)}),(e.incoming||[]).forEach(e=>{e.source&&!x.has(e.source.type??``)&&t.push(e.source.id)}),t}function Wr(e,t){let n=new Map(e.map(e=>[e.id,e])),r=/* @__PURE__ */ new Map,i=[];e.forEach(e=>Q(e,t).forEach(t=>{t.fromBoundary?i.push(t.target.id):(r.has(t.target.id)||r.set(t.target.id,/* @__PURE__ */ new Set),r.get(t.target.id).add(e.id))}));let a=/* @__PURE__ */ new Set,o=[];return[...new Set(i)].forEach(e=>{let i=/* @__PURE__ */ new Set,s=[e];for(;s.length;){let e=s.shift();if(i.has(e)||a.has(e))continue;i.add(e);let r=n.get(e);r&&Q(r,t).filter(e=>!e.fromBoundary).forEach(e=>s.push(e.target.id))}for(let t=!1;!t;)t=!0,[...i].forEach(n=>{if(n===e)return;let a=r.get(n);a&&![...a].every(e=>i.has(e))&&(i.delete(n),t=!1)});i.size!==0&&(i.forEach(e=>a.add(e)),o.push([...i]))}),o.sort((e,t)=>t.length-e.length)}function Gr(e,t,n,r,i,a,o,s,c){let l=Math.max(...e.map(i))+c.nodesep,u=({source:e,target:t,escape:r})=>r||Math.sign(n(t)-n(e)),d=new Map(e.map(e=>[e.id,e.id])),f=e=>{let t=e;for(;d.get(t)!==t;)t=d.get(t);let n=e;for(;d.get(n)!==t;){let e=d.get(n);d.set(n,t),n=e}return t};t.forEach(e=>{u(e)===0&&d.set(f(e.source.id),f(e.target.id))});let p=/* @__PURE__ */ new Map,m=(e,t,n)=>{p.has(e)||p.set(e,[]),p.get(e).push({other:t,delta:n})};t.forEach(e=>{let t=u(e);if(t===0)return;let{source:n,target:r,escape:a,port:d}=e,p=t*((a?c.nodesep+d:l)+(a||(s.get(n.id)??0)>1?i(n)/2:0)+((o.get(r.id)??0)>1?i(r)/2:0));m(f(n.id),f(r.id),p),m(f(r.id),f(n.id),-p)});let h=/* @__PURE__ */ new Map,g=[...e].sort((e,t)=>n(e)-n(t)||r(e)-r(t));g.forEach(e=>{if(h.has(f(e.id)))return;h.set(f(e.id),n(e)*l);let t=[f(e.id)];for(;t.length;){let e=t.shift();(p.get(e)??[]).forEach(({other:n,delta:r})=>{h.has(n)||(h.set(n,h.get(e)+r),t.push(n))})}});let _=e=>h.get(f(e.id)),v=[...new Set(e.map(r))].sort((e,t)=>e-t),y=[...new Set(g.map(e=>f(e.id)))];for(let t=0;t<200;t++){let t=0;if(y.forEach(e=>{let n=p.get(e)??[];if(!n.length)return;let r=n.reduce((e,{other:t,delta:n})=>e+h.get(t)-n,0)/n.length;t=Math.max(t,Math.abs(r-h.get(e))),h.set(e,r)}),v.forEach(o=>{let s=e.filter(e=>r(e)===o).sort((e,t)=>_(e)-_(t)||n(e)-n(t));for(let e=1;e<s.length;e++){let n=s[e-1],r=s[e],o=i(n)/2+a(n)+c.nodesep+i(r)/2-(_(r)-_(n));o>0&&(h.set(f(r.id),_(r)+o),t=Math.max(t,o))}}),t<.5)break}let b=c.marginY-Math.min(...e.map(e=>_(e)-i(e)/2));return[...h.keys()].forEach(e=>h.set(e,h.get(e)+b)),_}function Kr(e,t,n){let r=e=>x.has(e.type??``),i=e.filter(e=>!r(e));if(i.length===0)return new Map(e.map(e=>[e.id,{x:e.x,y:e.y}]));let a=i.filter(e=>e.type===`bpmn:Participant`);if(a.length===i.length){let t=/* @__PURE__ */ new Map,i=n.marginY;return[...a].sort((e,t)=>e.y-t.y||(e.id<t.id?-1:1)).forEach(e=>{t.set(e.id,{x:n.marginX,y:i}),i+=(e.height||200)+n.nodesep}),qr(e.filter(r),a,t,n,e=>e.width||100,e=>e.height||80)}let o=qn(i,t),s=Wr(i,t),c=new Set(s.flat()),l=Yn(i,t,o),u=$n(i,t,o,l.groups),d=rr(i,t,l.groups,u),{groups:f}=Yn(i,t,o,d),p=$n(i,t,o,f,d);nr(i,t,o,f,p,/* @__PURE__ */ new Set);let m=/* @__PURE__ */ new Map;i.forEach(e=>{let n=On(e,e.width||100),r=new Set(X(e).north.map(e=>e.id));Q(e,t).forEach(t=>{t.fromBoundary&&c.has(t.target.id)&&m.set(t.target.id,{row:p.get(e.id)??0,port:n.get(t.sourceAttacherId??``)??0,away:r.has(t.sourceAttacherId??``)?-1:1})})});let h=s.map(e=>({path:e,entry:m.get(e.find(e=>m.has(e))??``)})).filter(e=>!!e.entry).sort((e,t)=>e.entry.row-t.entry.row||t.entry.port-e.entry.port);h.forEach(({path:e,entry:t},n)=>{let r=(n+1)/(h.length+1);e.forEach(e=>p.set(e,t.row+t.away*r))});let g=[.../* @__PURE__ */ new Set([...p.values()])].sort((e,t)=>e-t),_=new Map(g.map((e,t)=>[e,t]));p.forEach((e,t)=>p.set(t,_.get(e)));let v=e=>e.width||100,y=e=>e.height||80,b=e=>e.label&&e.label.y>=e.y+y(e)?e.label.y+e.label.height-(e.y+y(e)):0,S=e=>p.get(e.id)??0,C=e=>o.get(e.id)??0,w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Map,E=[];i.forEach(e=>{let n=new Set(X(e).north.map(e=>e.id));Q(e,t).forEach(t=>{if(t.fromBoundary){let r=(e.attachers||[]).find(e=>e.id===t.sourceAttacherId);E.push({source:e,target:t.target,escape:n.has(t.sourceAttacherId??``)?-1:1,port:(r?.height||36)/2})}else w.set(e.id,(w.get(e.id)??0)+1),T.set(t.target.id,(T.get(t.target.id)??0)+1),E.push({source:e,target:t.target,escape:0,port:0})})});let D=Gr(i,E,S,C,y,b,T,w,n),O=e=>D(e),k=e=>O(e)-y(e)/2,A=[...new Set(i.map(C))].sort((e,t)=>e-t),j=/* @__PURE__ */ new Map;A.forEach(e=>{let t=i.filter(t=>C(t)===e&&!c.has(t.id));j.set(e,t.length?Math.max(...t.map(v)):0)});let M=/* @__PURE__ */ new Map;E.forEach(({source:e,target:t,escape:r})=>{if(c.has(t.id))return;let i=C(e),a=C(t);if(a<=i)return;let o=Math.abs(O(t)-O(e)),s=r!==0||(w.get(e.id)??0)>1&&o>y(e)/2,l=(T.get(t.id)??0)>1&&o>y(t)/2,u=s||l||o<1?1:2,d=j.get(i)/2+(s?0:v(e)/2)+u*(r?n.nodesep:n.ranksep)+(l?0:v(t)/2)-j.get(a)/2;M.has(a)||M.set(a,[]),M.get(a).push({from:i,reach:d})});let N=/* @__PURE__ */ new Map;A.forEach((e,t)=>{if(t===0){N.set(e,n.marginX);return}let r=A[t-1],i=N.get(r)+j.get(r)+n.ranksep;(M.get(e)??[]).forEach(({from:e,reach:t})=>{N.has(e)&&(i=Math.max(i,N.get(e)+t))}),N.set(e,Math.round(i))});let P=/* @__PURE__ */ new Map;i.forEach(e=>Q(e,t).forEach(t=>{t.fromBoundary&&c.has(t.target.id)&&P.set(t.target.id,e)}));let F=e=>N.get(C(e))+(j.get(C(e))-v(e))/2,I=/* @__PURE__ */ new Map;s.forEach(e=>{let r=e.find(e=>P.has(e));if(r===void 0)return;let a=P.get(r),o=F(a)+v(a)+n.nodesep,s=[r],l=/* @__PURE__ */ new Set;for(;s.length;){let e=s.shift();if(l.has(e))continue;l.add(e);let r=i.find(t=>t.id===e);r&&(I.set(e,o),o+=v(r)+n.nodesep,Q(r,t).filter(e=>!e.fromBoundary&&c.has(e.target.id)).forEach(e=>s.push(e.target.id)))}});let L=/* @__PURE__ */ new Map;i.forEach(e=>{let t=I.get(e.id)??F(e);L.set(e.id,{x:Math.round(t),y:Math.round(k(e))})});let R=Jr(i,E,L,n,v,y,b);return qr(e.filter(r),i,R,n,v,y)}function qr(e,t,n,r,i,a){if(e.length===0)return n;let o=new Map(t.map(e=>[e.id,e])),s=t.filter(e=>n.has(e.id)).map(e=>({...n.get(e.id),width:i(e),height:a(e)})),c=e=>!s.some(t=>S(e,t)),l=e=>{let t=e;for(;t;){let e=o.get(t.id);if(e&&n.has(e.id))return e;t=t.parent}},u=e=>{let t=[...(e.outgoing||[]).map(e=>e.target),...(e.incoming||[]).map(e=>e.source)].map(l).filter(t=>!!t&&!e.id.startsWith(t.id));return[...new Map(t.map(e=>[e.id,e])).values()]},d=r.nodesep;return[...e].map((e,t)=>({decoration:e,index:t,owners:u(e)})).sort((e,t)=>t.owners.length-e.owners.length||i(t.decoration)*a(t.decoration)-i(e.decoration)*a(e.decoration)||e.index-t.index).forEach(({decoration:e,owners:t})=>{let o=i(e),l=a(e),u=()=>{let e=s.length?Math.max(...s.map(e=>e.x+e.width)):r.marginX,t=s.length?Math.min(...s.map(e=>e.y)):r.marginY;for(;!c({x:e+d,y:t,width:o,height:l});)t+=l+d;return{x:e+d,y:t,width:o,height:l}};if(t.length===0){let t=u();n.set(e.id,{x:Math.round(t.x),y:Math.round(t.y)}),s.push(t);return}let f={x:t.reduce((e,t)=>e+n.get(t.id).x+i(t)/2,0)/t.length,y:t.reduce((e,t)=>e+n.get(t.id).y+a(t)/2,0)/t.length},p={top:Math.min(...t.map(e=>n.get(e.id).y)),bottom:Math.max(...t.map(e=>n.get(e.id).y+a(e))),left:Math.min(...t.map(e=>n.get(e.id).x)),right:Math.max(...t.map(e=>n.get(e.id).x+i(e)))},m=[{x:f.x-o/2,y:p.bottom+d,slide:`x`},{x:f.x-o/2,y:p.top-d-l,slide:`x`},{x:p.right+d,y:f.y-l/2,slide:`y`},{x:p.left-d-o,y:f.y-l/2,slide:`y`}],h=null;for(let e of m){for(let t=0;t<=8&&!h;t++)for(let n of t===0?[1]:[1,-1]){let r=n*t*(d+Math.min(o,l)),i={x:e.x+(e.slide===`x`?r:0),y:e.y+(e.slide===`y`?r:0),width:o,height:l};if(c(i)){h=i;break}}if(h)break}let g=h??(()=>{let e=d+Math.min(o,l)/2,t=[];for(let n=1;n<=12;n++)for(let r=-n;r<=n;r++)for(let i of[-n,n])t.push({x:f.x-o/2+r*e,y:f.y-l/2+i*e,width:o,height:l}),t.push({x:f.x-o/2+i*e,y:f.y-l/2+r*e,width:o,height:l});return t.filter(c).sort((e,t)=>Math.abs(e.x-f.x)+Math.abs(e.y-f.y)-(Math.abs(t.x-f.x)+Math.abs(t.y-f.y)))[0]??null})()??u();n.set(e.id,{x:Math.round(g.x),y:Math.round(g.y)}),s.push(g)}),n}function Jr(e,t,n,r,i,a,o){let s=new Map(e.map(e=>[e.id,e.id])),c=e=>{let t=e;for(;s.get(t)!==t;)t=s.get(t);let n=e;for(;s.get(n)!==t;){let e=s.get(n);s.set(n,t),n=e}return t};t.forEach(({source:e,target:t})=>s.set(c(e.id),c(t.id)));let l=/* @__PURE__ */ new Map;if(e.forEach(e=>{let t=c(e.id);l.has(t)||l.set(t,[]),l.get(t).push(e)}),l.size<2)return n;let u=r.nodesep,d=[...l.values()].map(e=>{let t=Math.min(...e.map(e=>n.get(e.id).x))-u,r=Math.min(...e.map(e=>n.get(e.id).y))-u;return{group:e,left:t,top:r,width:Math.max(...e.map(e=>n.get(e.id).x+i(e)))+u-t,height:Math.max(...e.map(e=>n.get(e.id).y+a(e)+o(e)))+u-r}}).map(e=>({box:e,shapes:e.group.map(e=>{let t=n.get(e.id);return{x:t.x,y:t.y,width:i(e),height:a(e)+o(e)}})})),f=d.reduce((e,{box:t})=>e+t.width+t.height,0),p=d.reduce((e,{box:t})=>e+t.width*t.height,0),m=Math.max(1,36*d.length-1),h=Math.max(r.nodesep,(f+Math.sqrt(f*f+4*m*p))/(2*m)),g=({box:e,shapes:t})=>{let n=/* @__PURE__ */ new Set;return t.forEach(t=>{let r=Math.floor((t.x-e.left)/h),i=Math.floor((t.y-e.top)/h),a=Math.floor((t.x+t.width-e.left)/h),o=Math.floor((t.y+t.height-e.top)/h);for(let e=r;e<=a;e++)for(let t=i;t<=o;t++)n.add(`${e}:${t}`)}),[...n].map(e=>{let[t,n]=e.split(`:`).map(Number);return{column:t,row:n}})},_=d.map(e=>({...e,tiles:g(e)})).sort((e,t)=>t.box.width+t.box.height-(e.box.width+e.box.height)),v=/* @__PURE__ */ new Set,y=Math.ceil(Math.sqrt(_.reduce((e,t)=>e+t.tiles.length,0)))+4,b=[];for(let e=0;e<=y;e++)for(let t=-e;t<=e;t++)for(let n=-e;n<=e;n++)Math.max(Math.abs(t),Math.abs(n*1.6))===e&&b.push({x:t,y:n});let x=/* @__PURE__ */ new Map;_.forEach(e=>{let t=b.find(t=>e.tiles.every(e=>!v.has(`${t.x+e.column}:${t.y+e.row}`)))??b[b.length-1];e.tiles.forEach(e=>v.add(`${t.x+e.column}:${t.y+e.row}`)),e.box.group.forEach(r=>{let i=n.get(r.id);x.set(r.id,{x:i.x-e.box.left+t.x*h,y:i.y-e.box.top+t.y*h})})});let S=Math.min(...[...x.values()].map(e=>e.x)),C=Math.min(...[...x.values()].map(e=>e.y));return x.forEach((e,t)=>x.set(t,{x:e.x-S+r.marginX,y:e.y-C+r.marginY})),x}function Yr(e,t,n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=e=>{let a=(e.children||[]).filter(n);a.forEach(e=>o.set(e.id,e));let c=a.map(e=>{if(Ce(e).length===0)return e;let t=s(e),n={width:Math.max(t.width,En(e)),height:t.height};return i.set(e.id,n),{...e,width:n.width,height:n.height}}),l=Kr(c,new Set(c.map(e=>e.id)),t),u=0,d=0,f=/* @__PURE__ */ new Set;return c.forEach(e=>{let n={...l.get(e.id)??{x:e.x,y:e.y}};for(;f.has(`${Math.round(n.x)}:${Math.round(n.y)}`);)n.y+=e.height+t.nodesep;f.add(`${Math.round(n.x)}:${Math.round(n.y)}`),r.set(e.id,n),u=Math.max(u,n.x+e.width),d=Math.max(d,n.y+e.height)}),{width:u+t.marginX,height:d+t.marginY}};s(e);let c=/* @__PURE__ */ new Map,l=(e,t)=>{(e.children||[]).filter(n).forEach(e=>{let n=r.get(e.id);if(!n)return;let a={x:t.x+n.x,y:t.y+n.y};c.set(e.id,a),i.has(e.id)&&l(e,a)})};return l(e,{x:0,y:0}),c.forEach((e,t)=>{let n=o.get(t);if(!n||(n.attachers??[]).length===0)return;let r=i.get(t)?.width??n.width,{south:s,north:c}=X(n),l=e=>e.reduce((e,t,n)=>e+(t.width||36)+(n>0?6:0),0),u=Math.max(0,(Math.max(l(s),l(c))-r)/2),d=e=>e.reduce((e,t)=>Math.max(e,(t.height||36)/2),0);a.set(t,{top:d(c),bottom:d(s),left:u,right:u})}),{positions:c,sizes:i,padding:a}}async function Xr(e,t,n,r=0){let i=e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`,a={moves:[],resizes:[],routes:[]},o=Cn?Yr(e,t,i):null,s=An(e),c=s.length>1,l=(e.children||[]).some(e=>e.type===`bpmn:Participant`)?(e.children||[]).filter(e=>x.has(e.type??``)):[],u=0;for(let e of s){G(),await se();let i=c?{x:40,y:u+40}:null,s=new Set((e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`).map(e=>e.id)),d=l.filter(e=>Ur(e).some(e=>s.has(e))),f=await Vr(e,n?.has(e.id)?{...t,nodesep:t.nodesep+r}:t,i,a,d,{x:0,y:0},o);if(f&&c){let t=[...a.resizes].reverse().find(t=>t.element.id===e.id);if(t){u=t.y+t.height+60;continue}let n=f.size.height+80;a.resizes.push({element:e,x:0,y:u,width:f.size.width+80,height:n}),u+=n+60}}return a}function Zr(e){return{moves:e.moves.map(e=>({...e,elements:[...e.elements]})),resizes:e.resizes.map(e=>({...e})),routes:e.routes.map(e=>({...e,waypoints:e.waypoints.map(e=>({...e}))}))}}function Qr(e,t,n,r,i,a,o,s,c,l=!1,u=!0){let d=Zr(t);xt(e,d,n,r),Ot(e,d,n,!1,u),xt(e,d,n,r),Ot(e,d,n,!1,u),a&&St(e,d),G(),Et(e,d,n),jt(e,d,n,l),G(),Lt(e,d,i,o,s),bt(d),Wt(e,d,n),bt(d),Wt(e,d,n),G(),kt(e,d,n),Ht(e,d),Wt(e,d,n),cn(e,d),nn(e,d),rn(e,d),G(),an(d);for(let t=0;t<ti;t++)ni.forEach(t=>on(e,d,t,`ordered`)),on(e,d),on(e,d,void 0,`border`),G();G(),sn(e,d);for(let t=0;t<2;t++)Xt(e,d);sn(e,d),$t(e,d);for(let t=0;t<2;t++)en(e,d);return sn(e,d),G(),tn(e,d),Gt(c,d),Vt(e,d),At(e,d,n),on(e,d,void 0,`lattice`),d}function $r(e){if((e.children||[]).filter(e=>e.type===`bpmn:Participant`&&(e.children||[]).some(e=>!w(e))).length<2)return 0;let t=e=>[e,...(e.children||[]).flatMap(t)],n=/* @__PURE__ */ new Set;return t(e).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;if(!_(t)||!t.source||!t.target)return;let r=v(t.source),i=v(t.target);r&&i&&r.id!==i.id&&(n.add(r.id),n.add(i.id))})),n.size}const ei=[{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!1},{exactOrder:!1,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!0,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!1},{exactOrder:!1,shortRoutes:!0,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!0,hugTarget:!1},{exactOrder:!0,shortRoutes:!0,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!0,slidePools:!0,byChannel:!1,hugTarget:!0}],ti=4,ni=[36,20],ri=[12,24,36,48],ii=[{upTo:60,plans:11},{upTo:120,plans:6},{upTo:1/0,plans:4}];function ai(e){let t=e=>(w(e)||j(e)?0:1)+(e.children||[]).reduce((e,n)=>e+t(n),0);return(e.children||[]).reduce((e,n)=>e+t(n),0)}async function oi(e,t,n={}){return xn(e),ae(n,()=>si(e,t))}async function si(e,t){let n=Dn(e),r=await Xr(e,t),i=$r(e),a=ii.find(t=>ai(e)<=t.upTo).plans,o=ei.filter(e=>(i>=2||!e.shortRoutes&&!e.slidePools&&!e.byChannel&&!e.hugTarget)&&(i>=3||!e.exactOrder)).slice(0,a),s=o[0],c=1/0,l=0;for(let[i,a]of o.entries()){if(i>0&&!oe())break;G(),await se();let{exactOrder:o,shortRoutes:u,slidePools:d,byChannel:f,hugTarget:p}=a,m=De(e,Qr(e,r,t,o,u,d,f,p,n)).energy;l++,m<c&&(c=m,s=a)}let u=Qr(e,r,t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n);if(Pe(e,u).containment>0){let i=Qr(e,r,t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n,!1,!1);Pe(e,i).containment===0&&(u=i)}let d=De(e,u),f=je(e,u),p=Me(e,u),m=Ne(u);if((d.merges>0||f>0||p>0)&&oe()){let i=t=>{let n=t;for(;n?.parent;)n=n.parent;return n??e},a=/* @__PURE__ */ new Map,o=e=>a.set(e,(a.get(e)??0)+1),c=u.routes.map(e=>e.waypoints);u.routes.forEach((e,t)=>{c.some((n,r)=>r!==t&&b(e.waypoints,n))&&(o(i(e.connection.source).id),o(i(e.connection.target).id))}),je(e,u,(e,t)=>{o(i(e.connection.source).id),o(i(e.connection.target).id),o(i(t).id)}),Me(e,u,e=>{o(i(e.connection.source).id),o(i(e.connection.target).id)});let h=[...a.entries()].sort((e,t)=>t[1]-e[1]).slice(0,4).map(([e])=>e),g,_=d.merges,v=f,y=p;for(let r of h)for(let i of ri){if(!oe())break;G(),await se();let a=Qr(e,await Xr(e,t,/* @__PURE__ */ new Set([r]),i),t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n);if(!Pe(e,a).ok)continue;let o=De(e,a),c=je(e,a),l=Me(e,a),u=Ne(a);if(!(o.merges<=d.merges&&c<=f&&l<=p&&u<=m&&o.crossings<=d.crossings))continue;let h=o.merges<_||c<v||l<y,b=o.merges<=_&&c<=v&&l<=y;if(h&&b&&(g=a,_=o.merges,v=c,y=l),o.merges<d.merges||c<f||l<p)break}let x=Qr(e,r,t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n,!0);if(Pe(e,x).ok){let t=De(e,x),n=je(e,x),r=Me(e,x),i=Ne(x),a=t.merges<=d.merges&&n<=f&&r<=p&&i<=m&&t.crossings<=d.crossings+1,o=t.merges<_||n<v||r<y,s=t.merges<=_&&n<=v&&r<=y;a&&o&&s&&(g=x,_=t.merges,v=n,y=r)}if(g)return gn(e,g),Xt(e,g),ci(e,g,l)}return gn(e,u),Xt(e,u),ci(e,u,l)}function ci(e,t,n){return{...t,search:{candidates:n,energy:De(e,t).energy}}}const li=/* @__PURE__ */ new Set([`bpmn:Task`,`bpmn:UserTask`,`bpmn:ServiceTask`,`bpmn:ScriptTask`,`bpmn:BusinessRuleTask`,`bpmn:ManualTask`,`bpmn:SendTask`,`bpmn:ReceiveTask`,`bpmn:CallActivity`,`bpmn:SubProcess`,`bpmn:Transaction`,`bpmn:AdHocSubProcess`,`bpmn:ExclusiveGateway`,`bpmn:InclusiveGateway`,`bpmn:ParallelGateway`,`bpmn:EventBasedGateway`,`bpmn:ComplexGateway`,`bpmn:StartEvent`,`bpmn:EndEvent`,`bpmn:IntermediateCatchEvent`,`bpmn:IntermediateThrowEvent`,`bpmn:DataObjectReference`,`bpmn:DataStoreReference`,`bpmn:TextAnnotation`,`bpmn:Group`]),ui={"bpmn:SubProcess":{width:350,height:200},"bpmn:Transaction":{width:350,height:200},"bpmn:AdHocSubProcess":{width:350,height:200},"bpmn:ExclusiveGateway":{width:50,height:50},"bpmn:InclusiveGateway":{width:50,height:50},"bpmn:ParallelGateway":{width:50,height:50},"bpmn:EventBasedGateway":{width:50,height:50},"bpmn:ComplexGateway":{width:50,height:50},"bpmn:StartEvent":{width:36,height:36},"bpmn:EndEvent":{width:36,height:36},"bpmn:IntermediateCatchEvent":{width:36,height:36},"bpmn:IntermediateThrowEvent":{width:36,height:36},"bpmn:BoundaryEvent":{width:36,height:36},"bpmn:DataObjectReference":{width:36,height:50},"bpmn:DataStoreReference":{width:50,height:50},"bpmn:TextAnnotation":{width:100,height:30}};function di(e,t,n){e.moves.forEach(({elements:e,dx:t,dy:n})=>{e.forEach(e=>{e.x+=t,e.y+=n,e.label&&(e.label.x+=t,e.label.y+=n)})}),e.resizes.forEach(({element:e,x:t,y:n,width:r,height:i})=>{e.x=t,e.y=n,e.width=r,e.height=i}),e.routes.forEach(({connection:e,waypoints:t})=>{e.waypoints=t})}async function fi(e){let t=I(e,`utf8`),n=new L,{rootElement:r}=await n.fromXML(t);return pi(r,n,t)}function pi(e,t,n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;((e.diagrams?.[0])?.plane?.planeElement??[]).forEach(e=>{e.$type===`bpmndi:BPMNShape`&&e.bpmnElement&&r.set(e.bpmnElement.id,e),e.$type===`bpmndi:BPMNEdge`&&e.bpmnElement&&i.set(e.bpmnElement.id,e)});let a=/* @__PURE__ */ new Map,o=[],s=[],c=[],l=[],u=[];function d(e,t){let n=r.get(e.id),i=n?.bounds,s=ui[e.$type]??{width:100,height:80},c={id:e.id,type:e.$type,x:i?.x??0,y:i?.y??0,width:i?.width??s.width,height:i?.height??s.height,outgoing:[],attachers:[],children:[],parent:t,businessObject:e},l=n?.label?.bounds;return l&&(c.label={id:e.id+`_label`,type:`label`,x:l.x,y:l.y,width:l.width,height:l.height}),a.set(e.id,c),o.push(c),c}function f(e,t){e.forEach(e=>{let n=r.get(e.id)?.bounds,i={id:e.id,type:`bpmn:Lane`,x:n?.x??0,y:n?.y??0,width:n?.width??600,height:n?.height??200,parent:t,children:[],businessObject:e};t.children=[...t.children??[],i],o.push(i),a.set(e.id,i),(e.flowNodeRef??[]).forEach(t=>{let n=a.get(t.id);n&&(n.businessObject={...n.businessObject,lanes:[{id:e.id}]})}),e.childLaneSet?.lanes?.length&&f(e.childLaneSet.lanes,i)})}function p(e,t){(e.laneSets??[]).forEach(e=>f(e.lanes??[],t))}function m(e,t){[...e.ioSpecification?.dataInputs??[],...e.ioSpecification?.dataOutputs??[]].forEach(e=>{r.has(e.id)&&d(e,t)});let n=e.flowElements??[];n.forEach(e=>{if(e.$type===`bpmn:SequenceFlow`){c.push({flow:e,type:`bpmn:SequenceFlow`});return}if(e.$type===`bpmn:BoundaryEvent`||!li.has(e.$type))return;let n=d(e,t);[...e.ioSpecification?.dataInputs??[],...e.ioSpecification?.dataOutputs??[]].forEach(e=>{r.has(e.id)&&d(e,t)}),r.get(e.id)?.isExpanded!==!1&&(e.flowElements??[]).length>0&&m(e,n)}),n.forEach(e=>{e.$type===`bpmn:BoundaryEvent`&&u.push({be:e}),(e.dataInputAssociations??[]).forEach(t=>{let n=(t.sourceRef??[])[0];n&&l.push({flow:t,sourceRef:n,targetRef:e})}),(e.dataOutputAssociations??[]).forEach(t=>{t.targetRef&&l.push({flow:t,sourceRef:e,targetRef:t.targetRef})})}),(e.artifacts??[]).forEach(e=>{e.$type===`bpmn:Association`?c.push({flow:e,type:`bpmn:Association`}):li.has(e.$type)&&d(e,t)})}let h=(e.rootElements??[]).find(e=>e.$type===`bpmn:Collaboration`),g=(e.rootElements??[]).filter(e=>e.$type===`bpmn:Process`),_={id:`root`,type:`root`,x:0,y:0,width:0,height:0,children:[]};if(h&&h.participants?.length){_.children=h.participants.map(e=>{let t=r.get(e.id)?.bounds,n={id:e.id,type:`bpmn:Participant`,x:t?.x??0,y:t?.y??0,width:t?.width??600,height:t?.height??200,children:[]};return o.push(n),a.set(e.id,n),e.processRef&&(m(e.processRef,n),p(e.processRef,n)),n}),(h.artifacts??[]).forEach(e=>{e.$type===`bpmn:Association`?c.push({flow:e,type:`bpmn:Association`}):li.has(e.$type)&&d(e,_)}),(h.messageFlows??[]).forEach(e=>c.push({flow:e,type:`bpmn:MessageFlow`}));let e=new Set((h.participants??[]).map(e=>e.processRef?.id).filter(e=>!!e));g.filter(t=>!e.has(t.id)).forEach(e=>{m(e,_),p(e,_)})}else if(g.length){let e={id:g[0].id,type:`bpmn:Process`,x:0,y:0,width:0,height:0,children:[]};m(g[0],e),_.children=[e]}u.forEach(({be:e})=>{let t=a.get(e.attachedToRef?.id);if(!t)return;let n=r.get(e.id),i=n?.bounds,s=ui[`bpmn:BoundaryEvent`],c={id:e.id,type:`bpmn:BoundaryEvent`,x:i?.x??t.x,y:i?.y??t.y,width:i?.width??s.width,height:i?.height??s.height,outgoing:[],host:t,parent:t.parent,businessObject:{id:e.id,eventDefinitions:e.eventDefinitions}},l=n?.label?.bounds;l&&(c.label={id:e.id+`_label`,type:`label`,x:l.x,y:l.y,width:l.width,height:l.height}),a.set(e.id,c),o.push(c),t.attachers=[...t.attachers||[],c]}),l.forEach(({flow:e,sourceRef:t,targetRef:n})=>{c.push({flow:{...e,sourceRef:t,targetRef:n},type:`bpmn:DataAssociation`})});let v=/* @__PURE__ */ new Map;[...c.filter(({type:e})=>e!==`bpmn:Association`),...c.filter(({type:e})=>e===`bpmn:Association`)].forEach(({flow:e,type:t})=>{let n=e=>a.get(e??``)??v.get(e??``),r=n(e.sourceRef?.id),o=n(e.targetRef?.id);if(!r||!o)return;let c=i.get(e.id),l=(c?.waypoint??[]).map(e=>({x:e.x,y:e.y})),u={id:e.id,type:t,x:0,y:0,width:0,height:0,source:r,target:o,waypoints:l},d=c?.label?.bounds;d&&(u.label={id:e.id+`_label`,type:`label`,x:d.x,y:d.y,width:d.width,height:d.height}),r.outgoing=[...r.outgoing||[],u],o.incoming=[...o.incoming||[],u],v.set(u.id,u),s.push(u)});let y=e=>{e.children=o.filter(t=>t.parent===e),e.children.forEach(y)};_.children.forEach(y);let b=o.filter(e=>e.parent===_&&!_.children.includes(e));return b.length&&(_.children=[..._.children,...b]),{root:_.children.length===1&&_.children[0].type===`bpmn:Process`?_.children[0]:_,allNodes:o,allConnections:s,moddle:t,definitions:e,shapesById:r,edgesById:i,xml:n}}const mi=(e,t)=>e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y;function hi(e,t,n,r){let{allNodes:i,allConnections:a}=pi(e,t,``),o=/* @__PURE__ */ new Set,s=a.filter(e=>{let t=e.waypoints??[];if(t.length===0)return!1;let r=t.map(e=>e.x),i=t.map(e=>e.y),a={x:Math.min(...r),y:Math.min(...i),width:Math.max(...r)-Math.min(...r),height:Math.max(...i)-Math.min(...i)};return mi(a,n)});i.filter(e=>mi(e,n)).forEach(e=>o.add(e)),s.forEach(e=>{e.source&&o.add(e.source),e.target&&o.add(e.target)});let c=i.filter(e=>o.has(e)),l=new Set(s.map(e=>e.id)),u=a.filter(e=>l.has(e.id)&&o.has(e.source)&&o.has(e.target));return E(c,u,{settled:r}).defects.map(e=>`${e.kind}: ${e.detail}`)}async function gi(r,i={}){let{outPath:a,verbose:o=!1,asAuthored:s=!1,spacing:c}=i,l=e=>{o&&console.log(e)},{root:u,allNodes:d,allConnections:f,moddle:p,definitions:m,shapesById:h,edgesById:g,xml:_}=await fi(r),v={...Sn,...c},y=A(f),b=f.filter(e=>!y.includes(e));l(`file=${r}`),l(`nodes=${d.length} connections=${b.length}`);let x=k(d,f),S=Date.now();s||di(await oi(u,v,{limitMs:1/0}),f,d);let C=Date.now();l(`layoutTime=${C-S}ms`);let w=[],T=(e,t,n)=>{w.push({kind:e,detail:t,elements:n}),l(`${e}: ${t}`)},D=/* @__PURE__ */ new Set,O=e=>!e||h.has(e),j=/* @__PURE__ */ new Set;for(let e of _.matchAll(/<(?:\w+:)?(sequenceFlow|messageFlow|association)\s([^>]*)/g)){let t=/id="([^"]+)"/.exec(e[2])?.[1];if(!t)continue;let n=/sourceRef="([^"]+)"/.exec(e[2])?.[1],r=/targetRef="([^"]+)"/.exec(e[2])?.[1];!n||!r?j.add(t):D.add(t)}for(let e of _.matchAll(/<(?:\w+:)?(dataInputAssociation|dataOutputAssociation)\s([^>]*?)>([\s\S]*?)<\/(?:\w+:)?\1>/g)){let t=/id="([^"]+)"/.exec(e[2])?.[1];t&&([...e[3].matchAll(/<(?:\w+:)?(?:sourceRef|targetRef)>([^<]+)</g)].map(e=>e[1].trim()).some(e=>!O(e))||D.add(t))}let M=/* @__PURE__ */ new Set;[...h.entries()].filter(([,e])=>e?.isExpanded===!1).map(([e])=>e).forEach(e=>{let t=e=>{(e?.flowElements??[]).forEach(e=>{M.add(e.id),t(e)}),(e?.artifacts??[]).forEach(e=>M.add(e.id))},n=r=>{r&&typeof r==`object`&&(r.id===e&&t(r),[`rootElements`,`flowElements`].forEach(e=>(r[e]??[]).forEach(n)))};n(m)}),j.forEach(e=>T(`DANGLING-CONNECTION`,`${e}`,[e]));let N=new Set(f.map(e=>e.id)),P=0;D.forEach(e=>{N.has(e)||M.has(e)||(T(`LOST-CONNECTION`,`${e}`,[e]),P++)}),l(P===0?t(`app.output.noLostConnections`):n(P,`app.output.count.lostConnection`));let F=E(d,f,{before:x,modelDefects:w,log:o?e=>console.log(e):void 0});if(a){[...d,...u.children??[]].forEach(e=>{let t=h.get(e.id);t?.bounds&&(t.bounds.x=e.x,t.bounds.y=e.y,t.bounds.width=e.width,t.bounds.height=e.height,t.label?.bounds&&e.label&&(t.label.bounds.x=e.label.x,t.label.bounds.y=e.label.y))}),b.forEach(e=>{let t=g.get(e.id);t&&e.waypoints&&(t.waypoint=e.waypoints.map(e=>p.create(`dc:Point`,{x:e.x,y:e.y})),t.label?.bounds&&e.label&&(t.label.bounds.x=e.label.x,t.label.bounds.y=e.label.y))});let{xml:t}=await p.toXML(m,{format:!0});e(a,t)}return{file:r,...F,millis:C-S}}export{hi as a,gi as i,pi as n,fi as r,di as t};
|
|
1
|
+
import{t as e}from"./chunk-atomicWrite-C6J1gDtO.js";import{r as t}from"./chunk-translator-BAjzyPKE.js";import{t as n}from"./chunk-plural-Di3FH8HP.js";import{A as r,C as i,D as a,E as o,M as s,N as c,O as l,P as u,S as d,T as f,_ as p,a as m,b as h,c as g,d as _,f as v,g as y,h as b,i as x,j as S,k as C,l as w,m as T,n as E,o as D,p as O,r as k,s as A,u as j,v as M,w as N,x as P,y as F}from"./chunk-diagramDefects-DlVCfZci.js";import{readFileSync as I}from"node:fs";import{BpmnModdle as L}from"bpmn-moddle";import{routeEdges as R}from"@mr_mint/elkjs-libavoid";import{Constraint as z,Rectangle as ee,Solver as B,Variable as te,generateXConstraints as ne,generateYConstraints as re}from"webcola";var V=class e extends Error{limitMs;constructor(n){super(t(`app.editor.layoutTooSlow`,{seconds:String(Math.round(n/1e3))})),this.name=e.name,this.limitMs=n}};function ie(e={}){let t=e.limitMs??15e3,n=e.now??(()=>performance.now()),r=n(),i=()=>n()-r;return{limitMs:t,elapsed:i,remaining:()=>t-i(),spare:()=>i()<t*.4,check(){if(i()>=t)throw new V(t)}}}let H=null;function U(){return H}let W=Promise.resolve();function ae(e,t){let n=W.then(async()=>{let n=ie(e);H=n;try{return await t(n)}finally{H=null}});return W=n.catch(()=>void 0),n}function G(){H?.check()}function oe(){return!H||H.spare()}function se(){return new Promise(e=>setTimeout(e,0))}function ce(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(n.source,(t.get(n.source)??0)+1),t.set(n.target,(t.get(n.target)??0)+1);return Math.max(0,...t.values())}function le(e){let t=0;for(let n=0;n<e.length;n++)for(let r=n+1;r<e.length;r++)F(e[n].from,e[n].to,e[r].from,e[r].to)&&t++;return t}function ue(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let{from:a,to:o}of e)t=Math.min(t,a.x,o.x),r=Math.max(r,a.x,o.x),n=Math.min(n,a.y,o.y),i=Math.max(i,a.y,o.y);let a=Math.max(100,Math.max(r-t,i-n)/Math.ceil(Math.sqrt(e.length))),o=(e,t,n)=>[Math.floor((e-n)/a),Math.floor((t-n)/a)],s=e.map(({from:e,to:r})=>({x:o(Math.min(e.x,r.x),Math.max(e.x,r.x),t),y:o(Math.min(e.y,r.y),Math.max(e.y,r.y),n)})),c=0;for(let e of s)if(c+=(e.x[1]-e.x[0]+1)*(e.y[1]-e.y[0]+1),c>2e6)return 1/0;let l=/* @__PURE__ */ new Map;s.forEach((e,t)=>{for(let n=e.x[0];n<=e.x[1];n++)for(let r=e.y[0];r<=e.y[1];r++){let e=`${n}:${r}`,i=l.get(e);i?i.push(t):l.set(e,[t])}});let u=0;for(let e of l.values())if(u+=e.length*(e.length-1)/2,u>8e6)return 1/0;let d=0;for(let[t,n]of l){let[r,i]=t.split(`:`).map(Number);for(let t=0;t<n.length;t++)for(let a=t+1;a<n.length;a++){let o=s[n[t]],c=s[n[a]];if(Math.max(o.x[0],c.x[0])!==r||Math.max(o.y[0],c.y[0])!==i)continue;let l=e[n[t]],u=e[n[a]];F(l.from,l.to,u.from,u.to)&&d++}}return d}function de(e){let t=ce(e);return e.length>2e4?{edges:e.length,crossings:1/0,hub:t}:{edges:e.length,crossings:e.length>1500?ue(e):le(e),hub:t}}function fe(e,t,n){let r=2e-4*(e.edges+t)**2+.02*e.edges*e.hub**2+.17*e.edges*e.crossings;return n?r*(1+e.crossings/15):r}var pe=class extends Error{};const me=e=>e.width||100,he=e=>e.height||80;function ge(e,t){let n=t?.positions.get(e.id)??{x:e.x,y:e.y},r=t?.sizes.get(e.id)??{width:me(e),height:he(e)},i=t?.padding?.get(e.id)??{top:0,right:0,bottom:0,left:0};return{left:n.x-i.left,top:n.y-i.top,right:n.x+r.width+i.right,bottom:n.y+r.height+i.bottom}}function _e(e,t){let n=e.map((e,t)=>({index:t,centre:e})).sort((e,t)=>e.centre-t.centre),r=[],i=[],a=()=>{i.length>1&&r.push(i.map(e=>e.index)),i=[]};for(let e of n){let n=i.length?e.centre-i[i.length-1].centre:0,r=i.length?e.centre-i[0].centre:0;i.length&&(n>t||r>t)&&a(),i.push(e)}return a(),r}function ve(e){let t=(e,t)=>e.x>=t.x&&e.X<=t.X&&e.y>=t.y&&e.Y<=t.Y;for(let n=0;n<e.length;n++)for(let r=0;r<e.length;r++){if(n===r)continue;let i=e[n],a=e[r];if(!t(i,a))continue;let o=a.X-i.x+1,s=i.X-a.x+1,c=a.Y-i.y+1,l=i.Y-a.y+1,u=Math.min(o,s,c,l);u===o?(i.x+=o,i.X+=o):u===s?(i.x-=s,i.X-=s):u===c?(i.y+=c,i.Y+=c):(i.y-=l,i.Y-=l)}}function ye(e){for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){let r=e[t],i=e[n];if(r.x<i.X&&i.x<r.X&&r.y<i.Y&&i.y<r.Y)return!0}return!1}function be(e,t,n,r,i,a){let o=e.map(e=>new te(t(e))),s=new Map(o.map((e,t)=>[e,t])),c=i(e,o),l=/* @__PURE__ */ new Set;for(let e of c){let t=s.get(e.left),n=s.get(e.right);t!==void 0&&n!==void 0&&l.add(t<n?`${t}:${n}`:`${n}:${t}`)}for(let n of a){let r=t(e[n.follower])-t(e[n.owner]);c.push(new z(o[n.owner],o[n.follower],r,!0)),l.add(n.owner<n.follower?`${n.owner}:${n.follower}`:`${n.follower}:${n.owner}`)}for(let n of _e(e.map(t),20))for(let e=1;e<n.length;e++){let t=n[e-1],r=n[e],i=t<r?`${t}:${r}`:`${r}:${t}`;l.has(i)||c.push(new z(o[t],o[r],0,!0))}new B(o,c).solve(),e.forEach((e,t)=>{let i=o[t].position();if(!Number.isFinite(i))return;let a=n(e)/2;r(e,i-a,i+a)})}function xe(e){let t=[...new Set(e.values())].sort((e,t)=>e-t),n=new Map(t.map((e,t)=>[e,t]));return new Map([...e].map(([e,t])=>[e,n.get(t)]))}function Se(e,t,n,r){let i=e.filter(e=>e.width>0&&e.height>0).filter(e=>!n.has(e.type??``)),a=i;if(a.length<1||!r&&(i.length<2||i.every(e=>e.x===0&&e.y===0)))return null;let o=Math.min(8,Math.max(2,t.nodesep/8)),s=i.map(e=>r?.positions.get(e.id)??{x:e.x,y:e.y}),c=i.map(e=>ge(e,r)),l=[],u=c.map(e=>new ee(e.left-o/2,e.right+o/2,e.top-o/2,e.bottom+o/2));for(let e=0;e<10&&ye(u);e++)ve(u),be(u,e=>e.cx(),e=>e.width(),(e,t,n)=>{e.x=t,e.X=n},ne,l),be(u,e=>e.cy(),e=>e.height(),(e,t,n)=>{e.y=t,e.Y=n},re,l);let d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new Map;i.forEach((e,t)=>{let n=u[t].x+o/2,r=u[t].y+o/2,i=Math.round(n-c[t].left),a=Math.round(r-c[t].top),l=Number.isFinite(i)?s[t].x+i:s[t].x,m=Number.isFinite(a)?s[t].y+a:s[t].y;d.set(e.id,{x:l,y:m}),f.set(e.id,l+me(e)/2),p.set(e.id,m+he(e)/2)}),e.forEach(e=>{if(d.has(e.id))return;let t=r?.positions.get(e.id)??{x:e.x,y:e.y};d.set(e.id,t),f.set(e.id,t.x+me(e)/2),p.set(e.id,t.y+he(e)/2)});let m=e=>r?.positions.get(e.id)??{x:e.x,y:e.y},h=Math.max(...a.map(e=>m(e).x+me(e)))-Math.min(...a.map(e=>m(e).x)),g=Math.max(...a.map(e=>m(e).y+he(e)))-Math.min(...a.map(e=>m(e).y))>h;return{positions:d,ranks:xe(g?p:f),rows:xe(g?f:p),authored:!0}}function Ce(e){return(e.children||[]).filter(e=>!!e.width&&!!e.height&&e.type!==`bpmn:Lane`&&!e.waypoints)}function we(e,t,n,r,i={x:0,y:0}){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Set,s=0,c=0,l=1/0,u=1/0;return e.forEach(e=>{let d=t.get(e.id)??{x:e.x,y:e.y},f=(Number.isFinite(d.x)?d.x:e.x)+i.x,p=(Number.isFinite(d.y)?d.y:e.y)+i.y,m=f-e.x,h=p-e.y;(m!==0||h!==0)&&(n.moves.push({elements:r(e),dx:m,dy:h}),o.add(e.id)),a.set(e.id,{x:f,y:p,width:e.width,height:e.height}),l=Math.min(l,f),u=Math.min(u,p),s=Math.max(s,f+e.width),c=Math.max(c,p+e.height)}),{positions:t,rects:a,size:{width:Number.isFinite(l)?s-l:0,height:Number.isFinite(u)?c-u:0},movedIds:o}}function Te(e,t,n,r,i,a={x:e.x,y:e.y,width:e.width,height:e.height},o=!1){if(!(a.width>0&&a.height>0))return;let s=[...t.entries()].filter(([e])=>n.has(e)).map(([,e])=>e);if(s.length===0)return;let c=r.marginY,l=Math.min(...s.map(e=>e.x))-c,u=Math.min(...s.map(e=>e.y))-c,d=Math.max(...s.map(e=>e.x+e.width))+c,f=Math.max(...s.map(e=>e.y+e.height))+c,p=o?l:Math.min(a.x,l),m=o?u:Math.min(a.y,u),h=(o?d:Math.max(a.x+a.width,d))-p,g=(o?f:Math.max(a.y+a.height,f))-m;(p!==a.x||m!==a.y||h!==a.width||g!==a.height)&&i.resizes.push({element:e,x:p,y:m,width:h,height:g})}function Ee(e,t){let n=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let r=n.get(t.id)??{x:0,y:0};n.set(t.id,{x:r.x+e.dx,y:r.y+e.dy})}));let r=new Map(t.resizes.map(e=>[e.element.id,e])),i=[],a=1/0,o=1/0,s=-1/0,c=-1/0,l=(e,t)=>{let u=r.get(e.id),d=n.get(e.id)??{x:0,y:0},f=u?{x:u.x,y:u.y,width:u.width,height:u.height}:{x:e.x+d.x,y:e.y+d.y,width:e.width,height:e.height};!w(e)&&!j(e)&&(a=Math.min(a,f.x),o=Math.min(o,f.y),s=Math.max(s,f.x+f.width),c=Math.max(c,f.y+f.height),t&&i.push(f));let p=(e.children||[]).filter(e=>!w(e)&&!j(e));p.forEach(e=>l(e,t&&p.length>0))};return(e.children||[]).forEach(e=>l(e,!g(e)&&!x.has(e.type??``)&&e.type!==`bpmn:Lane`)),{boxes:i,frame:a===1/0?{x:0,y:0,width:0,height:0}:{x:a,y:o,width:s-a,height:c-o}}}function De(e,t){let{boxes:n,frame:r}=Ee(e,t),i=n.filter(e=>!n.some(t=>t!==e&&l(t,e))),a=0;for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++)S(i[e],i[t])&&(a+=1);let o=t.routes.map(e=>e.waypoints).filter(e=>e.length>1),s=0,c=0;for(let e=0;e<o.length;e++)for(let t=e+1;t<o.length;t++)N(o[e],o[t])>0&&(s+=1),b(o[e],o[t])&&(c+=1);let u=o.reduce((e,t)=>e+T(t),0),d=0,p=0;o.forEach(e=>{d+=e.length-2,p+=f(e)});let m=r.width*r.height,h=1e9*a+12e3*s+1500*c+1500*u+150*d+p+.005*m;return{overlaps:a,crossings:s,merges:c,jogs:u,bends:d,length:p,area:m,energy:h}}function Oe(e,t){let n=[],r=/* @__PURE__ */ new Set,i=e=>{r.has(e.id)||(r.add(e.id),n.push(e))},a=e=>{i(e),(e.attachers||[]).forEach(i),(e.children||[]).forEach(a)};(e.children||[]).forEach(a);let o=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=o.get(t.id)??{x:0,y:0};o.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let s=new Map(t.resizes.map(e=>[e.element.id,e]));return{every:n,rectOf:e=>{let t=s.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=o.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}}}}function K(e){let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t}function ke(e,t,n,r){if(w(t)){let r=n.get(t.id)??t.waypoints??[];for(let t=0;t+1<r.length;t++){let n=o(e,r[t],r[t+1]);if(Math.abs(n.x-e.x)<=2&&Math.abs(n.y-e.y)<=2)return!0}return!1}return u(e,r(t),2)}const Ae=/* @__PURE__ */ new Set([`bpmn:TextAnnotation`,`bpmn:Group`]);function je(e,t,n){let{every:r,rectOf:i}=Oe(e,t),a=r.filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),o=0;return t.routes.forEach(e=>{let t=e.waypoints||[],r=e.connection,s=/* @__PURE__ */ new Set([r.source?.id,r.target?.id,...K(r.source),...K(r.target)]);for(let r=0;r+1<t.length;r++){let c=p(t[r],t[r+1]);if(!c)continue;let l=a.find(e=>s.has(e.id)||Ae.has(e.type??``)?!1:d(c,i(e)));l&&(o+=1,n?.(e,l))}}),o}function Me(e,t,n){let{rectOf:r}=Oe(e,t),i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;t.routes.forEach(e=>{let t=e.connection;if(!t.source||!t.target)return;let n=`${t.type}:${t.source.id}:${t.target.id}`;i.has(n)?a.add(t.id):i.add(n)});let o=0;return t.routes.forEach(e=>{let t=e.waypoints??[],i=e.connection;if(a.has(i.id)||t.length<2||!i.source||!i.target||i.type!==`bpmn:MessageFlow`&&i.type!==`bpmn:SequenceFlow`)return;let s=f(t),c=r(i.source),l=r(i.target),u=Math.abs(c.x+c.width/2-(l.x+l.width/2))+Math.abs(c.y+c.height/2-(l.y+l.height/2));u<40||s<=u*2||(o+=1,n?.(e))}),o}function Ne(e){let t=0;return e.routes.forEach(e=>{let n=e.connection;if(n.type!==`bpmn:Association`&&n.type!==`bpmn:DataInputAssociation`&&n.type!==`bpmn:DataOutputAssociation`)return;let r=e.waypoints??[];r.length<2||f(r)<=300||(t+=1)}),t}function Pe(e,t){let{every:n,rectOf:r}=Oe(e,t),i=n.filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),o=i.filter(e=>e.type===`bpmn:Participant`||e.type===`bpmn:SubProcess`),c=new Map(t.routes.map(e=>[e.connection.id,e.waypoints])),u=/* @__PURE__ */ new Set([`bpmn:Participant`,`bpmn:Lane`,`bpmn:SubProcess`]),d=/* @__PURE__ */ new Set([`bpmn:TextAnnotation`,`bpmn:DataObjectReference`,`bpmn:DataStoreReference`]),f=[...n.filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),...n.filter(g)],p=0;for(let e=0;e<f.length;e++)for(let t=e+1;t<f.length;t++){let n=f[e],i=f[t];if(n.host?.id===i.id||i.host?.id===n.id||K(n).has(i.id)||K(i).has(n.id)||n.type===`bpmn:Group`||i.type===`bpmn:Group`||Ae.has(n.type??``)&&u.has(i.type??``)||Ae.has(i.type??``)&&u.has(n.type??``))continue;let a=n.type===`bpmn:Participant`&&i.type===`bpmn:Participant`,o=d.has(n.type??``)||d.has(i.type??``);if(!a&&!o&&n.parent!==i.parent&&n.type!==`bpmn:Participant`&&i.type!==`bpmn:Participant`)continue;let s=r(n),c=r(i);s.x<c.x+c.width&&c.x<s.x+s.width&&s.y<c.y+c.height&&c.y<s.y+s.height&&(p+=1)}let m=0,h=0;t.routes.forEach(e=>{let t=e.waypoints,n=e.connection;if(!t||t.length<2)return;let i=!n.source||ke(t[0],n.source,c,r),a=!n.target||ke(t[t.length-1],n.target,c,r);i&&a||(m+=1);for(let e=0;e+1<t.length;e++)if(Math.abs(t[e].x-t[e+1].x)>.5&&Math.abs(t[e].y-t[e+1].y)>.5){h+=1;break}});let _=0;t.routes.forEach(e=>{let t=e.waypoints,n=e.connection;if(!t||t.length<2)return;let a=K(n.source),o=K(n.target);i.forEach(e=>{if(e.id===n.source?.id||e.id===n.target?.id||a.has(e.id)||o.has(e.id)||Ae.has(e.type??``))return;let i=r(e);for(let e=0;e+1<t.length;e++)s(t[e],t[e+1],i,2)&&(_+=1)})});let v=0;n.forEach(e=>{if(e.type===`bpmn:Participant`||e.type===`bpmn:Lane`||e.type===`bpmn:Group`||w(e)||j(e))return;let t=r(e),n=K(e);o.forEach(i=>{if(i.id===e.id||e.host?.id===i.id||K(i).has(e.id))return;let o=r(i),s=l(o,t),c=a(t,o);(e.type===`bpmn:TextAnnotation`?!s&&!c:n.has(i.id)?!s:!c)&&(v+=1)})});let y=0;return n.filter(g).forEach(e=>{let t=e.host;if(!t)return;let n=r(e),i=r(t),a=n.x+n.width/2,o=n.y+n.height/2,s=Math.abs(a-i.x)<=2||Math.abs(a-(i.x+i.width))<=2,c=Math.abs(o-i.y)<=2||Math.abs(o-(i.y+i.height))<=2,l=a>=i.x-2&&a<=i.x+i.width+2,u=o>=i.y-2&&o<=i.y+i.height+2;s&&u||c&&l||(y+=1)}),{ok:p===0&&m===0&&_===0&&v===0&&y===0&&h===0,overlaps:p,detachedEdges:m,edgeThroughNode:_,containment:v,boundaryOffHost:y,diagonalEdges:h}}function Fe(e,t,n=.5){let r=e.x+e.width*n,i=e.y+e.height*n,a=t.x+t.width/2,o=t.y+t.height/2;if(t.y>=e.y+e.height){let n={x:r,y:e.y+e.height},i={x:a,y:t.y};return n.x===i.x?[n,i]:[n,{x:n.x,y:i.y},i]}if(t.y+t.height<=e.y){let n={x:r,y:e.y},i={x:a,y:t.y+t.height};return n.x===i.x?[n,i]:[n,{x:n.x,y:i.y},i]}if(t.x>=e.x+e.width){let n={x:e.x+e.width,y:i},r={x:t.x,y:o};return n.y===r.y?[n,r]:[n,{x:r.x,y:n.y},r]}let s={x:e.x,y:i},c={x:t.x+t.width,y:o};return s.y===c.y?[s,c]:[s,{x:c.x,y:s.y},c]}function Ie(e,t,n){let r=e.length,i=new Map(e.map((e,n)=>[t(e),n])),a=Array.from({length:r},()=>Array(r).fill(0));n.forEach((e,t)=>{let[n,r]=t.split(`|`),o=i.get(n),s=i.get(r);o!==void 0&&s!==void 0&&o!==s&&(a[o][s]+=e,a[s][o]+=e)});let o=a.map(e=>e.reduce((e,t)=>e+t,0)),s=1<<r,c=new Float64Array(s);for(let e=1;e<s;e++){let t=e&-e,n=31-Math.clz32(t),i=e^t,s=0;for(let e=0;e<r;e++)i&1<<e&&(s+=a[n][e]);c[e]=c[i]+o[n]-2*s}let l=new Float64Array(s).fill(1/0),u=new Int32Array(s).fill(-1);l[0]=0;for(let e=1;e<s;e++){for(let t=0;t<r;t++){if(!(e&1<<t))continue;let n=l[e^1<<t];n<l[e]&&(l[e]=n,u[e]=t)}l[e]+=c[e]}let d=[];for(let t=s-1;t>0;){let n=u[t];d.push(e[n]),t^=1<<n}return d.reverse()}function Le(e,t){return e<t?`${e}|${t}`:`${t}|${e}`}function Re(e,t,n,r=!1){let i=[...e].sort((e,t)=>e.y-t.y||(e.id<t.id?-1:1));if(e.length<3||n.size===0)return i;if(r&&e.length<=14)return Ie(i,t,n);let a=e=>{let r=new Map(e.map((e,n)=>[t(e),n])),i=0;return n.forEach((e,t)=>{let[n,a]=t.split(`|`),o=r.get(n),s=r.get(a);o!==void 0&&s!==void 0&&(i+=e*Math.abs(o-s))}),i},o=i,s=a(o);for(let e=0;e<20;e++){let e=new Map(o.map((e,n)=>[t(e),n])),r=[...o.map(r=>{let i=t(r),a=0,o=0;return n.forEach((t,n)=>{let[r,s]=n.split(`|`),c=r===i?s:s===i?r:null;if(c===null)return;let l=e.get(c);l!==void 0&&(a+=t,o+=t*l)}),{item:r,place:a?o/a:e.get(i)}})].sort((e,t)=>e.place-t.place||(e.item.id<t.item.id?-1:1)).map(e=>e.item),i=a(r);if(i>=s)break;o=r,s=i}return o}function ze(e){let t=e=>[e,...(e.children||[]).flatMap(t)],n=/* @__PURE__ */ new Map;e.forEach(e=>t(e).forEach(t=>n.set(t.id,e.id)));let r=/* @__PURE__ */ new Map;return e.flatMap(t).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;if(!_(t))return;let i=n.get(t.source?.id??``),a=n.get(t.target?.id??``);if(!i||!a||i===a)return;let o=Le(i,a);r.set(o,(r.get(o)??0)+1)})),r}function Be(e,t=!1){let n=ze(e);return new Map(Re(e,e=>e.id,n,t).map((e,t)=>[e.id,t]))}function Ve(e,t,n,r,i){if(!n||e.length<2)return e;let a=r?0:e.length-1,o=r?1:e.length-2,s=e[a],c=e[o],l=t.x+t.width/2,u=t.y+t.height/2,d=Math.abs(s.x-t.x)<.5,f=Math.abs(s.x-(t.x+t.width))<.5,p=Math.abs(s.y-t.y)<.5,m=Math.abs(s.y-(t.y+t.height))<.5,h=o===0||o===e.length-1,g=[...e],_=(e,t)=>{g[a]=e,h?Math.abs(t.x-c.x)<.5&&Math.abs(t.y-c.y)<.5||g.splice(r?1:g.length-1,0,t):g[o]=t};(d||f)&&Math.abs(s.y-u)>.5?Math.abs(c.y-s.y)<.5&&_({x:s.x,y:u},{x:c.x,y:u}):(p||m)&&Math.abs(s.x-l)>.5&&Math.abs(c.x-s.x)<.5&&_({x:l,y:s.y},{x:l,y:c.y});for(let t=0;t+1<g.length;t++)if(q(g[t],g[t+1],i))return e;return g}function q(e,t,n){return n.some(n=>{if(e.x===t.x){let r=e.x;return r>n.x+.01&&r<n.x+n.width-.01&&Math.min(e.y,t.y)<n.y+n.height&&Math.max(e.y,t.y)>n.y}if(e.y===t.y){let r=e.y;return r>n.y+.01&&r<n.y+n.height-.01&&Math.min(e.x,t.x)<n.x+n.width&&Math.max(e.x,t.x)>n.x}return!1})}function J(e,t){return u(e,t,.5)}function He(e,t,n,r){let i=e;return t&&!J(i[0],t)&&(i=Ve(i,t,!0,!0,r)),n&&!J(i[i.length-1],n)&&(i=Ve(i,n,!0,!1,r)),i}var Ue=class{items=[];push(e){this.items.push(e);let t=this.items.length-1;for(;t>0;){let e=t-1>>1;if(this.items[e].guess<=this.items[t].guess)break;[this.items[e],this.items[t]]=[this.items[t],this.items[e]],t=e}}pop(){let e=this.items[0],t=this.items.pop();if(t===void 0||this.items.length===0)return e;this.items[0]=t;let n=0;for(;;){let t=n*2+1,r=t+1,i=n;if(t<this.items.length&&this.items[t].guess<this.items[i].guess&&(i=t),r<this.items.length&&this.items[r].guess<this.items[i].guess&&(i=r),i===n)return e;[this.items[n],this.items[i]]=[this.items[i],this.items[n]],n=i}}};function We(e,t,n){let r=Math.min(e.x,t.x),i=Math.max(e.x,t.x),a=Math.min(e.y,t.y),o=Math.max(e.y,t.y);return n.some(e=>i>e.x+4&&r<e.x+e.width-4&&o>e.y+4&&a<e.y+e.height-4)}function Ge(e,t,n,r){let i=Math.min(t,n)-r*2,a=Math.max(t,n)+r*2,o=/* @__PURE__ */ new Set([t,n]);return e.forEach(e=>{e>=i&&e<=a&&o.add(e)}),[...o].sort((e,t)=>e-t)}function Ke(e,t,n,r,i,a,o=2,s=90){let c=n.flatMap(e=>[e.x-i,e.x+e.width+i]),l=n.flatMap(e=>[e.y-i,e.y+e.height+i]),u=Ge(c,e.x,t.x,i).filter(e=>!a||e>=a.x-i&&e<=a.x+a.width+i),d=Ge(l,e.y,t.y,i);if(u.length*d.length>s*s)return null;let f=new Map(u.map((e,t)=>[e,t])),p=new Map(d.map((e,t)=>[e,t])),m=f.get(e.x),h=p.get(e.y),g=f.get(t.x),_=p.get(t.y);if(m===void 0||h===void 0||g===void 0||_===void 0)return null;let v=u.length,y=(e,t,n)=>(t*v+e)*3+n,b=/* @__PURE__ */ new Map,x=/* @__PURE__ */ new Map,S=new Ue,C=(e,n,r,i)=>{let a=y(e,n,r),o=b.get(a);return o!==void 0&&o<=i?!1:(b.set(a,i),S.push({ix:e,iy:n,dir:r,cost:i,guess:i+Math.abs(u[e]-t.x)+Math.abs(d[n]-t.y)}),!0)};C(m,h,o,0);let w=[];r.forEach(e=>{for(let t=0;t+1<e.length;t++){let n=e[t],r=e[t+1];w.push({a:n,b:r,left:Math.min(n.x,r.x),right:Math.max(n.x,r.x),top:Math.min(n.y,r.y),bottom:Math.max(n.y,r.y)})}});let T=/* @__PURE__ */ new Map,E=(e,t,n,r)=>{let i=n*v*d.length+r,a=T.get(i);if(a!==void 0)return a;let o=Math.min(e.x,t.x),s=Math.max(e.x,t.x),c=Math.min(e.y,t.y),l=Math.max(e.y,t.y),u=0;for(let n of w)n.right<o||n.left>s||n.bottom<c||n.top>l||F(e,t,n.a,n.b)&&u++;let f=u*400;return T.set(i,f),f},D=-1,O=0;for(;;){O++%512==0&&G();let e=S.pop();if(!e)break;if(b.get(y(e.ix,e.iy,e.dir))!==e.cost)continue;if(e.ix===g&&e.iy===_&&(o===2||e.dir===o)){D=y(e.ix,e.iy,e.dir);break}let t=[[e.ix+1,e.iy,0],[e.ix-1,e.iy,0],[e.ix,e.iy+1,1],[e.ix,e.iy-1,1]],r=e.ix===m&&e.iy===h;t.forEach(([t,i,a])=>{if(t<0||i<0||t>=u.length||i>=d.length||o!==2&&r&&a!==o)return;let s={x:u[e.ix],y:d[e.iy]},c={x:u[t],y:d[i]};if(We(s,c,n))return;let l=e.dir===2||e.dir===a?0:60,f=e.cost+Math.abs(c.x-s.x)+Math.abs(c.y-s.y)+l+E(s,c,e.iy*v+e.ix,i*v+t);C(t,i,a,f)&&x.set(y(t,i,a),y(e.ix,e.iy,e.dir))})}if(D<0)return null;let k=[],A=D;for(;A!==void 0;){let e=Math.floor(A/3);k.push({x:u[e%v],y:d[Math.floor(e/v)]}),A=x.get(A)}k.reverse();let j=[];return k.forEach((e,t)=>{let n=j[j.length-1];if(n&&n.x===e.x&&n.y===e.y)return;let r=k[t+1];n&&r&&(n.x===e.x&&r.x===e.x||n.y===e.y&&r.y===e.y)||j.push(e)}),j}function qe(e,t,n){let r=/* @__PURE__ */ new Map,i=[];return[...e].sort((e,r)=>n(e)-n(r)||t(e).from-t(r).from).forEach(e=>{let n=t(e),a=i.findIndex(e=>e<=n.from);a<0&&(a=i.length),i[a]=n.to,r.set(e,a)}),r}function Je(e,t){let n=new Map(e.map((e,t)=>[e,t]));return t.map((t,r)=>{let i=n.get(t.from)??0,a=n.get(t.to)??0,o=Math.min(i,a),s=Math.max(i,a),c=t=>`${e[t]}|${e[t+1]}`;return s-o<=1?{id:t.id,fromPool:t.from,toPool:t.to,gaps:[c(o)],strip:null}:{id:t.id,fromPool:t.from,toPool:t.to,gaps:[c(i<a?i:i-1),c(a<i?a:a-1)],strip:r%2==0?`right`:`left`}})}function Ye(e,t,n,r,i){let a=e=>c({x:e,y:t},{x:e,y:n},r)===0&&i.every(t=>Math.abs(t-e)>=16);if(a(e))return e;for(let t=1;t<=24;t++)for(let n of[1,-1]){let r=e+n*t*16;if(a(r))return r}return e}function Xe(e,t,n){let r=/* @__PURE__ */ new Map;e.forEach(e=>[...new Set(e.plan.gaps)].forEach(t=>{r.has(t)||r.set(t,[]),r.get(t).push(e)}));let i=e=>({from:Math.min(e.source.x+e.source.width/2,e.target.x+e.target.width/2),to:Math.max(e.source.x+e.source.width/2,e.target.x+e.target.width/2)}),a=/* @__PURE__ */ new Map;r.forEach((e,t)=>{let n=qe(e,i,e=>i(e).from);a.set(t,new Map([...n].map(([e,t])=>[e.connection.id,t])))});let o=e.filter(e=>e.plan.strip!==null),s=/* @__PURE__ */ new Map,c=e=>({from:Math.min(e.sourcePool.y,e.targetPool.y),to:Math.max(e.sourcePool.y+e.sourcePool.height,e.targetPool.y+e.targetPool.height)});[`left`,`right`].forEach(e=>{qe(o.filter(t=>t.plan.strip===e),c,e=>c(e).from).forEach((e,t)=>s.set(t.connection.id,e))});let l=[],u=/* @__PURE__ */ new Map;return e.forEach(e=>{let r=e.source.x+e.source.width/2,i=e.target.x+e.target.width/2,o=e.sourcePool.y<e.targetPool.y,c=o?e.source.y+e.source.height:e.source.y,d=o?e.target.y:e.target.y+e.target.height,f=n=>{let r=t.gapOf(n),i=a.get(n)?.get(e.connection.id)??0;if(!r)return c;let o=Math.max(1,r.high-r.low),s=Math.max(1,a.get(n)?.size??1),l=Math.min(20,o/(s+1));return r.low+o/2+(i-(s-1)/2)*l},p=f(e.plan.gaps[0]),m=f(e.plan.gaps[e.plan.gaps.length-1]),h=Ye(r,Math.min(c,p),Math.max(c,p),n,l);l.push(h);let g=Ye(i,Math.min(d,m),Math.max(d,m),n,l);if(l.push(g),e.plan.strip===null){u.set(e.connection.id,[{x:h,y:c},{x:h,y:p},{x:g,y:p},{x:g,y:d}]);return}let _=s.get(e.connection.id)??0,v=e.plan.strip===`right`?t.rightAt+(_+1)*20:t.leftAt-(_+1)*20;u.set(e.connection.id,[{x:h,y:c},{x:h,y:p},{x:v,y:p},{x:v,y:m},{x:g,y:m},{x:g,y:d}])}),u}const Ze=[`channel`,`target`,`source`,`third`,`far`];function Qe(e,t){let n=new Map(e.map(e=>[e.id,e.id])),r=e=>{let t=e;for(;n.get(t)!==t;)t=n.get(t);return t};return t.forEach(e=>{let t=v(e.source),i=v(e.target);if(!t||!i||!n.has(t.id)||!n.has(i.id))return;let a=r(t.id),o=r(i.id);a!==o&&n.set(a,o)}),new Map(e.map(e=>[e.id,r(e.id)]))}function $e(e){let t=v(e.source),n=v(e.target);return!t||!n?e.source.id:t.y<=n.y?`${t.id}|${n.id}`:`${n.id}|${t.id}`}function et(e){let t=e=>{let t=e.source,n=e.target,r=t.x+t.width/2,i=n.x+n.width/2;return{from:Math.min(r,i),to:Math.max(r,i)}},n=/* @__PURE__ */ new Map;e.forEach(e=>{let t=$e(e);n.has(t)||n.set(t,[]),n.get(t).push(e)});let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;return n.forEach((e,n)=>{let a=[];[...e].sort((e,n)=>t(e).from-t(n).from||(e.id<n.id?-1:1)).forEach(e=>{let n=t(e),i=a.findIndex(e=>e<=n.from);i<0&&(i=a.length),a[i]=n.to+20,r.set(e.id,i)}),i.set(n,a.length)}),{lane:r,width:i}}function tt(e){let t=e=>[e,...(e.children||[]).flatMap(t)],n=/* @__PURE__ */ new Map;return t(e).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;_(t)&&t.source&&t.target&&n.set(t.id,t)})),et([...n.values()]).width}function nt(e,t,n,r){let i=Math.min(e.y,t.y),a=Math.max(e.y+e.height,t.y+t.height),o=n.filter(e=>e.y>=i-1&&e.y+e.height<=a+1).sort((e,t)=>e.y-t.y),s=[];for(let e=1;e<o.length;e++){let t=o[e-1],n=o[e];s.push((t.y+t.height+n.y)/2)}return r?s:s.reverse()}function rt(e,t,n,r,i,a,o,s){if(i.length===0)return null;let c=e=>M(e,a)*m+o.reduce((t,n)=>t+N(e,n),0),l=e.x+e.width/2,u=[{x:l,y:t}],d=n.x+n.width/2;if(i.forEach((e,t)=>{let n=t+1<i.length?i[t+1]:r,o=/* @__PURE__ */ new Set([l,d]);a.forEach(t=>{t.y>Math.max(e,n)||t.y+t.height<Math.min(e,n)||(o.add(t.x-10),o.add(t.x+t.width+10))});let f={x:l,price:1/0};[...o].filter(e=>!s||e>=s.x&&e<=s.x+s.width).sort((e,t)=>Math.abs(e-d)-Math.abs(t-d)).forEach(t=>{let r=c([{x:l,y:e},{x:t,y:e},{x:t,y:n}])+Math.abs(t-l)*.01;r<f.price&&(f={x:t,price:r})}),u.push({x:l,y:e}),f.x!==l&&u.push({x:f.x,y:e}),l=f.x}),l===d)return u.push({x:l,y:r}),P(u);let f=u[u.length-1],p=r+Math.sign(f.y-r)*20;return u.push({x:l,y:p}),u.push({x:d,y:p}),u.push({x:d,y:r}),P(u)}function it(e,t,n,r,i=[],a){let o=e.x+e.width/2,s=e=>M(e,r)*m+i.reduce((t,n)=>t+N(e,n),0),c=e=>[{x:e,y:t},{x:e,y:n}],l=Math.max(0,e.width/2-10),u=[o];for(let e=1;e*10<=l;e++)u.push(o+e*10,o-e*10);let d=e=>s(c(e))*m+i.filter(t=>b(c(e),t)).length,f=u.reduce((e,t)=>d(t)<d(e)?t:e,o),p=Math.abs(t-e.y)<=Math.abs(t-(e.y+e.height))?-1:1,h=e=>{let r=t+p*Math.min(20,Math.abs(n-t));return r===t?[{x:e,y:t}]:[{x:e,y:t},{x:e,y:r}]};if(d(f)===0)return h(f);let g=s(c(o));if(g===0)return h(o);let _=t+p*20,v=e=>!a||e>=a.x&&e<=a.x+a.width,y={price:g,x:o};for(let e=1;e<=80&&y.price>0;e++)for(let r of[1,-1]){let i=o+r*e*10;if(!v(i))continue;let a=s([{x:o,y:t},{x:o,y:_},{x:i,y:_},{x:i,y:n}]);a<y.price&&(y={price:a,x:i})}return y.x===o?h(o):[{x:o,y:t},{x:o,y:_},{x:y.x,y:_},{x:y.x,y:n}]}function at(e,t,n=[],r=0,i=[],a=[],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=!0,l=0,u=1,d=!1){let f={x:e.x,y:e.y,width:e.width,height:e.height},p={x:t.x,y:t.y,width:t.width,height:t.height},g=v(e),_=v(t),y=[g,_].filter(e=>!!e),x=n.filter(e=>(e.x!==f.x||e.y!==f.y)&&(e.x!==p.x||e.y!==p.y)&&!y.some(t=>e.x===t.x&&e.y===t.y)),S=e=>M(e,x)*m+a.reduce((t,n)=>t+N(e,n),0),C=e=>e.reduce((t,n,r)=>r===0?0:t+Math.abs(n.x-e[r-1].x)+Math.abs(n.y-e[r-1].y),0),w=e=>c?S(e)*16e3+C(e):S(e),T=g?s.get(o.get(g.id)??``):void 0,E=(n,s)=>{let d=n?e.y:e.y+e.height,m=n?t.y+t.height:t.y,h=g&&_&&g!==_?n?{low:_.y+_.height,high:g.y}:{low:g.y+g.height,high:_.y}:{low:Math.min(d,m),high:Math.max(d,m)},v=Math.max(0,h.high-h.low),y=Math.min(20,v/(u+1)),C=(h.low+h.high)/2+(l-(u-1)/2)*y,E=Math.max(0,(l-(u-1)/2)*16+(u-1)*16/2),D=n?m+20+E:m-20-E,O=n?d-20:d+20,k=h.high-h.low,A={channel:C,target:D,source:O,third:h.low+k/3,far:h.low+k*2/3}[s],j={from:Math.max(f.x,p.x)+10,to:Math.min(f.x+f.width,p.x+p.width)-10};if(j.to>=j.from){let e=(j.from+j.to)/2,t=[e];for(let n=1;n*10<=(j.to-j.from)/2;n++)t.push(e+n*10,e-n*10);let n=t.map(e=>[{x:e,y:d},{x:e,y:m}]).find(e=>S(e)===0&&!a.some(t=>b(e,t)));if(n)return n}let M=ot(it(f,d,A,x,a,T),it(p,m,A,x,a,T).reverse(),A);if(!g||!_||g===_)return M;let N=Math.min(g.y,_.y),F=Math.max(g.y+g.height,_.y+_.height);if(!i.some(e=>e!==g&&e!==_&&e.y>N&&e.y+e.height<F)&&S(M)===0)return M;let I=(l-(u-1)/2)*y,L=(n?g.y-30:g.y+g.height+30)+I,R=(n?_.y+_.height+30:_.y-30)+I,z={left:Math.min(g.x,_.x),right:Math.max(g.x+g.width,_.x+_.width)},ee=i.filter(e=>e.y+e.height>Math.min(g.y,_.y)&&e.y<Math.max(g.y+g.height,_.y+_.height)&&e.x+e.width>z.left&&e.x<z.right&&(o.size===0||o.get(e.id)===o.get(g.id))),B=60+r%4*20,te=Math.max(...ee.map(e=>e.x+e.width),g.x+g.width,_.x+_.width)+B,ne=Math.min(...ee.map(e=>e.x),g.x,_.x)-B,re=T?Math.min(te,T.x+T.width-20):te,V=T?Math.max(ne,T.x+20):ne,ie=it(f,d,L,x,a,T),H=it(p,m,R,x,a,T).reverse(),U=e=>P([...ie,{x:ie[ie.length-1].x,y:L},{x:e,y:L},{x:e,y:R},{x:H[0].x,y:R},...H]),W=rt(f,d,p,m,nt(g,_,ee,!n),x,a,T),ae=Ke({x:f.x+f.width/2,y:d},{x:p.x+p.width/2,y:m},x,a,20,void 0,1),G=r%2==0?[U(re),U(V)]:[U(V),U(re)];return(c?[M,...ae?[ae]:[],...W?[W]:[],...G]:[...G,M,...W?[W]:[],...ae?[ae]:[]]).reduce((e,t)=>w(t)<w(e)?t:e)},D=e=>a.filter(t=>b(e,t)).length,O=e=>w(e)+D(e)*.5,k=d?`target`:`channel`,A=E(e.y>t.y,k);if(!g||!_||g===_)return h(A);let j=E(e.y<=t.y,k),F=O(j)<O(A)?j:A;if(D(F)===0)return h(F);let I=Ze.filter(e=>e!==k).flatMap(n=>[E(e.y>t.y,n),E(e.y<=t.y,n)]);return h(I.reduce((e,t)=>O(t)<O(e)?t:e,F))}function ot(e,t,n){let r=[...e];return r[r.length-1].y!==n&&r.push({x:r[r.length-1].x,y:n}),t[0].x!==r[r.length-1].x&&r.push({x:t[0].x,y:n}),t.forEach(e=>r.push(e)),P(r)}function st(e,t,n){if(t.length<2||e.length===0)return null;let r=Qe(t,e),i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return t.forEach(e=>{let t=r.get(e.id)??e.id;a.has(t)||a.set(t,[]),a.get(t).push(e)}),a.forEach((t,a)=>{let o=[...t].sort((e,t)=>e.y-t.y);if(o.length<2)return;let s=o.map(e=>e.id),c=e.filter(e=>{let t=v(e.source),n=v(e.target);return!!t&&!!n&&t.id!==n.id&&r.get(t.id)===a&&r.get(n.id)===a});if(c.length===0)return;let l=new Map(Je(s,c.map(e=>({id:e.id,from:v(e.source).id,to:v(e.target).id}))).map(e=>[e.id,e])),u=/* @__PURE__ */ new Map;for(let e=0;e+1<o.length;e++)u.set(`${o[e].id}|${o[e+1].id}`,{low:o[e].y+o[e].height,high:o[e+1].y});let d={gapOf:e=>u.get(e),leftAt:Math.min(...o.map(e=>e.x)),rightAt:Math.max(...o.map(e=>e.x+e.width))},f=e=>({x:e.x,y:e.y,width:e.width,height:e.height}),p=c.map(e=>({connection:e,plan:l.get(e.id),source:f(e.source),target:f(e.target),sourcePool:f(v(e.source)),targetPool:f(v(e.target))}));Xe(p,d,n.filter(e=>!p.some(t=>t.source.x===e.x&&t.source.y===e.y||t.target.x===e.x&&t.target.y===e.y))).forEach((e,t)=>i.set(t,e))}),e.every(e=>i.has(e.id))?i:null}function ct(e,t=[],n=[],i=!0,a=!1,o=!1){let s=t.filter(e=>e.type!==`bpmn:Lane`&&e.type!==`bpmn:Participant`&&!D.has(e.type??``)&&e.width>0&&e.height>0).map(e=>({x:e.x,y:e.y,width:e.width,height:e.height})),c=t.filter(e=>e.type===`bpmn:Participant`),l=e.filter(e=>_(e)&&e.source&&e.target),u=e=>{let t=v(e.source),n=v(e.target);if(!t||!n)return{low:0,high:0};let r=t.y+t.height/2,i=n.y+n.height/2;return{low:Math.min(r,i),high:Math.max(r,i)}},d=new Map([...l].sort((e,t)=>{let n=u(e),r=u(t);return r.high-r.low-(n.high-n.low)||n.low-r.low||(e.id<t.id?-1:1)}).map((e,t)=>[e.id,l.length-t])),{lane:f,width:p}=et(l),m=Qe(c,l),h=/* @__PURE__ */ new Map;c.forEach(e=>{let t=m.get(e.id);if(!t)return;let n=h.get(t),i={x:e.x-100,y:e.y,width:e.width+200,height:e.height};h.set(t,n?r(n,i):i)});let g=a?st(l,c,s):null;if(g)return l.map(e=>({connection:e,waypoints:g.get(e.id)}));let y=[...n];return l.map(e=>{let t=at(e.source,e.target,s,d.get(e.id)??0,c,y,m,h,i,f.get(e.id)??0,p.get($e(e))??1,o);return y.push(t),{connection:e,waypoints:t}})}function lt(e){let t=e.waypoints,n=[];for(let r=0;r+1<t.length;r++){let i=t[r],a=t[r+1],o=r===0||r+2===t.length;i.y===a.y&&i.x!==a.x?n.push({route:e,index:r,axis:`y`,at:i.y,from:Math.min(i.x,a.x),to:Math.max(i.x,a.x),anchored:o}):i.x===a.x&&i.y!==a.y&&n.push({route:e,index:r,axis:`x`,at:i.x,from:Math.min(i.y,a.y),to:Math.max(i.y,a.y),anchored:o})}return n}function ut(e,t){let n=/* @__PURE__ */ new Map;e.forEach(e=>n.set(e,new te(e.at,e.anchored?1e6:1)));let r=[],i=[...e].sort((e,t)=>e.at-t.at||e.from-t.from);for(let e=0;e<i.length;e++)for(let a=e+1;a<i.length;a++){let o=i[e],s=i[a];if(s.at-o.at>t)break;o.route!==s.route&&(Math.min(o.to,s.to)-Math.max(o.from,s.from)<=0||r.push(new z(n.get(o),n.get(s),t)))}if(r.length===0)return/* @__PURE__ */ new Map;new B(e.map(e=>n.get(e)),r).solve();let a=/* @__PURE__ */ new Map;return e.forEach(e=>{let t=n.get(e).position();Math.abs(t-e.at)>=.5&&a.set(e,t)}),a}function dt(e,t=16){let n=e.flatMap(lt),r=[];return[`x`,`y`].forEach(e=>{let i=n.filter(t=>t.axis===e);i.length<2||ut(i,t).forEach((t,n)=>r.push({route:n.route,index:n.index,axis:e,at:t,step:Math.abs(t-n.at)}))}),r.sort((e,t)=>e.step-t.step)}function ft(e){let t=e.route.waypoints,n=e.axis===`y`?`y`:`x`,r=t[e.index-1],i=t[e.index+2],a=r?r[n]:t[e.index][n],o=i?i[n]:t[e.index+1][n];return t[e.index].x<=t[e.index+1].x&&t[e.index].y<=t[e.index+1].y?{head:a,foot:o}:{head:o,foot:a}}const pt={comparisons:0};function mt(e){let t=e.map((e,t)=>t),n=e=>{let n=e;for(;t[n]!==n;)n=t[n];return n},r=e=>e===`x`?0:1,i=e.map((e,t)=>t).sort((t,n)=>r(e[t].axis)-r(e[n].axis)||e[t].at-e[n].at||e[t].from-e[n].from);for(let r=0;r<i.length;r++){let a=i[r],o=e[a];for(let s=r+1;s<i.length;s++){let r=i[s],c=e[r];if(pt.comparisons+=1,o.axis!==c.axis||c.at-o.at>12)break;if(o.route===c.route||Math.min(o.to,c.to)-Math.max(o.from,c.from)<40)continue;let l=n(a),u=n(r);l!==u&&(t[l]=u)}}let a=/* @__PURE__ */ new Map;return e.forEach((e,t)=>{let r=n(t);a.has(r)||a.set(r,[]),a.get(r).push(e)}),[...a.values()].filter(e=>e.length>1)}function ht(e,t=16){let n=e.flatMap(lt),r=[];return mt(n).forEach(e=>{let n=e.reduce((e,t)=>e+t.at,0)/e.length;[...e].sort((e,t)=>{let n=ft(e),r=ft(t);return n.head-r.head||n.foot-r.foot||e.at-t.at||e.index-t.index}).forEach((i,a)=>{let o=n+(a-(e.length-1)/2)*t;Math.abs(o-i.at)<.5||r.push({route:i.route,index:i.index,axis:i.axis,at:o,step:Math.abs(o-i.at)})})}),r.sort((e,t)=>e.step-t.step)}function gt(e,t){let n=[];return e.forEach(e=>{let r=t(e);lt(e).forEach(t=>{let i=t.axis===`y`,a;r.forEach(e=>{let n=i?e.x:e.y,r=i?e.x+e.width:e.y+e.height;Math.min(t.to,r)-Math.max(t.from,n)<40||(i?[e.y,e.y+e.height]:[e.x,e.x+e.width]).forEach((e,n)=>{if(Math.abs(e-t.at)>6)return;let r=n===0?e-12:e+12;(a===void 0||Math.abs(r-t.at)<Math.abs(a-t.at))&&(a=r)})}),a!==void 0&&n.push({route:e,index:t.index,axis:t.axis,at:a,step:Math.abs(a-t.at)})})}),n.sort((e,t)=>e.step-t.step)}function _t(e,t){let n=[];return e.forEach(e=>{let r=t(e);lt(e).forEach(t=>{if(t.anchored)return;let i=t.axis===`y`,a=r.filter(e=>{let n=i?e.x:e.y,r=i?e.x+e.width:e.y+e.height;return Math.min(t.to,r)-Math.max(t.from,n)>=40});if(!a.some(e=>(i?[e.y,e.y+e.height]:[e.x,e.x+e.width]).some(e=>Math.abs(e-t.at)<=6)))return;let o=a.map(e=>i?[e.y,e.y+e.height]:[e.x,e.x+e.width]).sort((e,t)=>e[0]-t[0]),s=[];o.forEach(e=>{let t=s[s.length-1];t&&e[0]<=t[1]?t[1]=Math.max(t[1],e[1]):s.push([e[0],e[1]])});let c=[];for(let e=0;e+1<s.length;e++)c.push([s[e][1],s[e+1][0]]);let l=c.filter(e=>e[1]-e[0]>=24).map(e=>(e[0]+e[1])/2).reduce((e,n)=>e===void 0||Math.abs(n-t.at)<Math.abs(e-t.at)?n:e,void 0);l===void 0||Math.abs(l-t.at)<.5||n.push({route:e,index:t.index,axis:t.axis,at:l,step:Math.abs(l-t.at)})})}),n.sort((e,t)=>e.step-t.step)}const vt=[.5,.34,.66,.42,.58],yt=3e3;function bt(e){let t=/* @__PURE__ */ new Map,n=e=>{let n=t.get(e.id);if(n)return n;let r={x:e.x,y:e.y,width:e.width,height:e.height};return t.set(e.id,r),r};e.moves.forEach(({elements:e,dx:t,dy:r})=>e.forEach(e=>{let i=n(e);i.x+=t,i.y+=r})),e.resizes.forEach(({element:e,x:n,y:r,width:i,height:a})=>{t.set(e.id,{x:n,y:r,width:i,height:a})});let r=e=>{let t=Math.round(e/40)*40;return Math.abs(t-e)<=4?t:e};e.routes.forEach(e=>{let t=e.connection.source?n(e.connection.source):void 0,a=e.connection.target?n(e.connection.target):void 0,o=He(e.waypoints,t,a,[]),s=o.map(e=>({x:r(e.x),y:r(e.y)}));e.waypoints=i(s)&&O(s)<=O(o)&&(!t||J(s[0],t))&&(!a||J(s[s.length-1],a))?s:o})}function Y(e,t){let n=[],r=/* @__PURE__ */ new Set,i=e=>{r.has(e.id)||(r.add(e.id),n.push(e))},a=e=>{i(e),(e.attachers||[]).forEach(i),(e.children||[]).forEach(a)};(e.children||[]).forEach(a);let o=/* @__PURE__ */ new Map,s=new Map(t.resizes.map(e=>[e.element.id,e])),c=()=>{o.clear(),t.moves.forEach(e=>e.elements.forEach(t=>{let n=o.get(t.id)??{x:0,y:0};o.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})})),s=new Map(t.resizes.map(e=>[e.element.id,e]))};return c(),{every:n,rectOf:e=>{let t=s.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=o.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}},driftOf:e=>{let t=o.get(e.id);if(t)return t;let n=s.get(e.id);return n?{x:n.x-e.x,y:n.y-e.y}:{x:0,y:0}},movedBy:e=>o.get(e.id),refresh:c}}function xt(e,t,n,r=!1){let i=(e.children||[]).filter(e=>e.type===`bpmn:Participant`);if(i.length<2)return;let a=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=a.get(t.id)??{x:0,y:0};a.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let o=new Map(t.resizes.map(e=>[e.element.id,e])),s=e=>{let t=o.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=a.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}},c=e=>[e,...(e.children||[]).flatMap(c)],l=(e.children||[]).filter(e=>x.has(e.type??``)),u=/* @__PURE__ */ new Map;l.forEach(e=>{let t=[...e.outgoing||[],...e.incoming||[]].map(t=>{let n=t;return n.source?.id===e.id?n.target:n.source}).filter(e=>!!e).map(e=>i.find(t=>c(t).some(t=>t.id===e.id))).find(Boolean);t&&u.set(e.id,t.id)});let d=tt(e),f=Be(i,r),p=[...i].sort((e,t)=>(f.get(e.id)??0)-(f.get(t.id)??0)),m=ze(i),h=wt(p,m).map(e=>{let t=Ct(e,m,s,n,d);return e.length>1&&t.forEach((e,n)=>t.set(n,{x:e.x+100,y:e.y})),{group:e,inside:t,width:Math.max(...e.map(e=>t.get(e.id).x+s(e).width))+(e.length>1?100:0),height:Math.max(...e.map(e=>t.get(e.id).y+s(e).height))}}),g=/* @__PURE__ */ new Map,_=Math.max(...h.map(e=>e.height)),v=[];h.slice().sort((e,t)=>t.height-e.height||t.width-e.width).forEach(e=>{let t=v.find(t=>t.used+e.height<=_+1);if(!t){let e=v[v.length-1];t={left:e?e.left+e.width+60:n.marginX,used:0,width:0},v.push(t)}let r=n.marginY+t.used;e.group.forEach(n=>{let i=e.inside.get(n.id);g.set(n.id,{x:t.left+i.x,y:r+i.y})}),t.used+=e.height+60,t.width=Math.max(t.width,e.width)}),p.forEach(e=>{let n=s(e),r=g.get(e.id),i=r.x-n.x,a=r.y-n.y;if(Math.abs(i)<.5&&Math.abs(a)<.5)return;let d=[...c(e),...l.filter(t=>u.get(t.id)===e.id)],f=new Set(d.map(e=>e.id));d.forEach(e=>{let n=o.get(e.id);n?(n.x+=i,n.y+=a):w(e)||t.moves.push({elements:[e],dx:i,dy:a})}),t.routes.forEach(e=>{f.has(e.connection.source?.id??``)&&f.has(e.connection.target?.id??``)&&(e.waypoints=e.waypoints.map(e=>({x:e.x+i,y:e.y+a})))})})}function St(e,t){let n=(e.children||[]).filter(e=>e.type===`bpmn:Participant`);if(n.length<2)return;let r=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=r.get(t.id)??{x:0,y:0};r.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let i=new Map(t.resizes.map(e=>[e.element.id,e])),a=e=>{let t=i.get(e.id);if(t)return{x:t.x,y:t.y,width:t.width,height:t.height};let n=r.get(e.id)??{x:0,y:0};return{x:e.x+n.x,y:e.y+n.y,width:e.width,height:e.height}},o=e=>[e,...(e.children||[]).flatMap(o)],s=/* @__PURE__ */ new Map;n.forEach(e=>o(e).forEach(t=>s.set(t.id,e.id)));let c=[];if(n.flatMap(o).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;if(!_(t)||!t.source||!t.target)return;let n=s.get(t.source.id),r=s.get(t.target.id);if(!n||!r||n===r)return;let i=a(t.source),o=a(t.target);c.push({from:n,to:r,gap:o.x+o.width/2-(i.x+i.width/2)})})),c.length===0)return;let l=new Map(n.map(e=>[e.id,0])),u=[...n].sort((e,t)=>e.id<t.id?-1:1);for(let e=0;e<12;e++){let e=!1;if(u.forEach(t=>{let n=[];if(c.forEach(({from:e,to:r,gap:i})=>{e===t.id?n.push(l.get(r)+i):r===t.id&&n.push(l.get(e)-i)}),n.length===0)return;n.sort((e,t)=>e-t);let r=Math.round(n[Math.floor((n.length-1)/2)]);r!==l.get(t.id)&&(l.set(t.id,r),e=!0)}),!e)break}let d=new Map(n.map(e=>[e.id,e.id])),f=e=>{let t=e;for(;d.get(t)!==t;)t=d.get(t);return t};c.forEach(({from:e,to:t})=>{let n=f(e),r=f(t);n!==r&&d.set(n,r)});let p=/* @__PURE__ */ new Map;n.forEach(e=>{let t=f(e.id),n=p.get(t),r=l.get(e.id);(n===void 0||r<n)&&p.set(t,r)}),n.forEach(e=>{let n=l.get(e.id)-(p.get(f(e.id))??0);if(n<1)return;let r=o(e).filter(t=>t.id!==e.id),a=new Set(r.map(e=>e.id)),s=(e.children||[]).filter(e=>e.type===`bpmn:Lane`),c=s.length===1?s[0].id:void 0;r.forEach(e=>{let r=i.get(e.id);r?e.id===c?r.width+=n:r.x+=n:w(e)||t.moves.push({elements:[e],dx:n,dy:0})}),t.routes.forEach(e=>{a.has(e.connection.source?.id??``)&&a.has(e.connection.target?.id??``)&&(e.waypoints=e.waypoints.map(e=>({x:e.x+n,y:e.y})))});let u=i.get(e.id);u&&(u.width+=n)})}function Ct(e,t,n,r,i){let a=/* @__PURE__ */ new Map;if(e.length===1)return a.set(e[0].id,{x:0,y:0}),a;let o=/* @__PURE__ */ new Map;e.forEach(e=>o.set(e.id,[])),t.forEach((e,t)=>{let[n,r]=t.split(`|`);o.has(n)&&o.has(r)&&(o.get(n).push(r),o.get(r).push(n))});let s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set,l=0;e.forEach(e=>{if(c.has(e.id))return;let t=[e.id];for(c.add(e.id);t.length>0;){let e=t.shift();s.set(e,l),l+=1,(o.get(e)??[]).forEach(e=>{c.has(e)||(c.add(e),t.push(e))})}});let u=0,d=e.slice().sort((e,t)=>(s.get(e.id)??0)-(s.get(t.id)??0));return d.forEach((e,t)=>{a.set(e.id,{x:0,y:u});let r=d[t+1],o=r?i.get(`${e.id}|${r.id}`)??i.get(`${r.id}|${e.id}`)??0:0;u+=n(e).height+Math.max(60,(o+1)*20)}),a}function wt(e,t){let n=new Map(e.map(e=>[e.id,e.id])),r=e=>{let t=e;for(;n.get(t)!==t;)t=n.get(t);return t};t.forEach((e,t)=>{let[i,a]=t.split(`|`);if(!n.has(i)||!n.has(a))return;let o=r(i),s=r(a);o!==s&&n.set(o,s)});let i=/* @__PURE__ */ new Map;return e.forEach(e=>{let t=r(e.id);i.has(t)||i.set(t,[]),i.get(t).push(e)}),[...i.values()]}function Tt(e,t,n,r=[]){let i={x:e.x+e.width/2,y:e.y+e.height/2},a={x:t.x+t.width/2,y:t.y+t.height/2},o=(e,t)=>t>e.x+e.width/2?e.x+e.width:e.x,s=(e,t)=>t>e.y+e.height/2?e.y+e.height:e.y,c=[];vt.forEach(n=>{let r=i.y+(a.y-i.y)*n,l=i.x+(a.x-i.x)*n;c.push({path:[{x:i.x,y:s(e,a.y)},{x:i.x,y:r},{x:a.x,y:r},{x:a.x,y:s(t,i.y)}],sideways:0}),c.push({path:[{x:o(e,a.x),y:i.y},{x:l,y:i.y},{x:l,y:a.y},{x:o(t,i.x),y:a.y}],sideways:1})}),c.push({path:[{x:i.x,y:s(e,a.y)},{x:i.x,y:a.y},{x:o(t,i.x),y:a.y}],sideways:0}),c.push({path:[{x:o(e,a.x),y:i.y},{x:a.x,y:i.y},{x:a.x,y:s(t,i.y)}],sideways:1}),Math.abs(i.y-a.y)<1&&c.push({path:[{x:o(e,a.x),y:i.y},{x:o(t,i.x),y:a.y}],sideways:0}),Math.abs(i.x-a.x)<1&&c.push({path:[{x:i.x,y:s(e,a.y)},{x:a.x,y:s(t,i.y)}],sideways:0});let l=(e,t)=>t.x>e.x+.5&&t.x<e.x+e.width-.5&&t.y>e.y+.5&&t.y<e.y+e.height-.5,u=P(c[c.length-2].path),d=1/0;return c.forEach(({path:i,sideways:a})=>{let o=P(i),s=r.reduce((e,t)=>e+N(o,t),0),c=r.filter(e=>b(o,e)).length,f=(o.length>1&&l(e,o[1])?1:0)+(o.length>1&&l(t,o[o.length-2])?1:0),p=(M(o,n)+f)*10+s*5+c*20+a+o.length/100;p<d&&(d=p,u=o)}),u}function Et(e,t,n){let{every:r,rectOf:i}=Y(e,t),a=r.filter(e=>x.has(e.type??``)&&e.type!==`bpmn:Group`);new Set(a.map(e=>e.id)),Dt(a.filter(e=>e.type===`bpmn:TextAnnotation`&&[...e.outgoing||[],...e.incoming||[]].length===0),r,i,t,n)}function Dt(e,t,n,r,i){if(e.length===0)return;let a=t.filter(t=>!e.includes(t)&&t.type!==`bpmn:Lane`&&t.width>0&&t.height>0);if(a.length===0)return;let o=a.map(n),s=Math.min(...o.map(e=>e.x)),c=Math.max(...o.map(e=>e.x+e.width)),l=Math.min(...o.map(e=>e.y)),u=Math.max(...o.map(e=>e.y+e.height)),d=e.map(n),f={width:Math.max(...d.map(e=>e.width)),height:d.reduce((e,t)=>e+t.height,0)+i.nodesep*(e.length-1)},p={width:d.reduce((e,t)=>e+t.width,0)+i.marginX*(e.length-1),height:Math.max(...d.map(e=>e.height))},m=(e,t)=>e*t,h=m(c-s+i.marginX*2+f.width,u-l)<=m(Math.max(c-s,p.width),u-l+i.marginY*2+p.height),g=h?l:s;[...e].sort((e,t)=>n(e).y-n(t).y||n(e).x-n(t).x).forEach(e=>{let t=n(e),a=h?{x:c+i.marginX*2,y:g}:{x:g,y:u+i.marginY*2};g+=h?t.height+i.nodesep:t.width+i.marginX;let o=a.x-t.x,s=a.y-t.y;Math.abs(o)<.5&&Math.abs(s)<.5||r.moves.push({elements:[e],dx:o,dy:s})})}function Ot(e,t,n,i=!1,o=!0){let{every:s,rectOf:c}=Y(e,t),u=s.filter(e=>x.has(e.type??``)&&e.type!==`bpmn:Group`);if(u.length===0)return;new Set(u.map(e=>e.id));let d=u.filter(e=>e.type===`bpmn:TextAnnotation`&&[...e.outgoing||[],...e.incoming||[]].length===0),f=u.filter(e=>!d.includes(e));if(f.length===0)return;let p=new Set(f.map(e=>e.id)),m=s.filter(e=>!p.has(e.id)&&e.type!==`bpmn:Lane`&&e.width>0&&e.height>0),h=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},g=new Map(t.routes.map(e=>[e.connection.id,e.waypoints])),_=(e,t)=>{if(!e.source||!e.target)return c(e);let n=g.get(e.id)??e.waypoints??[];return n.length<2?c(e):zt(n,t,!1,[],[]).at},v=e=>[...e.outgoing||[],...e.incoming||[]].some(t=>{let n=t,r=n.source?.id===e.id?n.target:n.source;return!!r?.source&&!!r?.target}),y=m.map(c),b=[],w=[],T=/* @__PURE__ */ new Map,E=/* @__PURE__ */ new Map,D=e=>e.label?r(c(e),c(e.label)):c(e);f.filter(e=>!i||v(e)).forEach(e=>{let r=c(e),o=D(e),u=r.x-o.x,d=r.y-o.y,f=e=>({x:e.x-u,y:e.y-d,width:o.width,height:o.height}),v=h(e),x=m.filter(e=>!v.has(e.id)&&e.type!==`bpmn:Participant`&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:SubProcess`).map(c),O=[...(e.outgoing||[]).map(e=>e.target),...(e.incoming||[]).map(e=>e.source)].filter(e=>!!e&&!p.has(e.id)),k=e=>e.type===`bpmn:Participant`||e.type===`bpmn:Lane`||e.type===`bpmn:SubProcess`,A=O.filter(e=>!k(e)),j=A.length?_(A[0],r):O.length?_(O[0],r):r,P=n.nodesep,F=e.parent;for(;F&&F.type!==`bpmn:Participant`&&F.type!==`bpmn:SubProcess`;)F=F.parent;let I=F?T.get(F.id)??c(F):void 0,L=s.filter(e=>(e.type===`bpmn:Participant`||e.type===`bpmn:SubProcess`)&&!v.has(e.id)&&e.id!==F?.id).map(c),R=s.filter(e=>e.type===`bpmn:Lane`&&e.id!==F?.id).map(c),z=e=>{if(!I||l(I,e))return I??e;let t=Math.max(I.x+I.width,e.x+e.width+n.marginX),r=Math.max(I.y+I.height,e.y+e.height+n.marginY),i=Math.min(I.x,e.x-n.marginX),a=Math.min(I.y,e.y-n.marginY);return{x:i,y:a,width:t-i,height:r-a}},ee=e=>{if(!I)return!1;let t=z(e);if(t===I)return!1;let n=[];return t.x<I.x&&n.push({x:t.x,y:t.y,width:I.x-t.x,height:t.height}),t.x+t.width>I.x+I.width&&n.push({x:I.x+I.width,y:t.y,width:t.x+t.width-(I.x+I.width),height:t.height}),t.y<I.y&&n.push({x:t.x,y:t.y,width:t.width,height:I.y-t.y}),t.y+t.height>I.y+I.height&&n.push({x:t.x,y:I.y+I.height,width:t.width,height:t.y+t.height-(I.y+I.height)}),n.some(e=>L.some(t=>S(e,t)))},B=n.nodesep*6,te=e=>{if(!I)return!1;let t=Math.max(0,I.x-e.x),n=Math.max(0,e.x+e.width-(I.x+I.width)),r=Math.max(0,I.y-e.y),i=Math.max(0,e.y+e.height-(I.y+I.height));return t>B||n>B||r>B||i>B},ne=e=>R.some(t=>C(e,t))||L.some(t=>!a(e,t))?!1:A.length>1||L.length>5?!I||l(I,e):!te(e)&&!ee(e),re=e=>(!I||l(I,e))&&ne(e),V=A.length>1?x:[...x,...L],ie=e=>t.routes.reduce((t,n)=>t+M(n.waypoints,[e]),0),H=(n,r=1/0)=>{if(!ne(n)||x.some(e=>S(n,e))||b.some(e=>S(n,e)))return 1/0;let i=f(n),a=+!ne(i)+x.filter(e=>S(i,e)).length+w.filter(e=>S(i,e)).length,o=Math.abs(n.x+n.width/2-(j.x+j.width/2))+Math.abs(n.y+n.height/2-(j.y+j.height/2)),s=a*800+o*80;if(s>=r)return s;if(!A.length)return ie(n)*yt+s;let l=t.routes.filter(t=>t.connection.source?.id!==e.id&&t.connection.target?.id!==e.id).map(e=>e.waypoints);return A.reduce((e,t)=>{let r=g.get(t.id)??t.waypoints,i=t.source&&t.target&&r&&r.length>=2?zt(r,n,!1,V,l).waypoints:Tt(c(t),n,V,l);return e+M(i,V)+l.reduce((e,t)=>e+N(i,t),0)},0)*yt+ie(n)*yt+s},U=r,W=H(r);for(let e=1;e<=100&&W>0;e++){let t=j.y+j.height+P*e,n=j.y-P*e-r.height,i=j.x+j.width+P*e,a=j.x-P*e-r.width,o=j.x+j.width/2-r.width/2,s=j.y+j.height/2-r.height/2;for(let e of[{x:o,y:t,aside:0},{x:o,y:n,aside:0},{x:i,y:s,aside:1},{x:a,y:s,aside:1},{x:i,y:t,aside:1},{x:a,y:t,aside:1},{x:i,y:n,aside:1},{x:a,y:n,aside:1}]){let t={x:e.x,y:e.y,width:r.width,height:r.height},n=H(t,W)+e.aside*200;n<W&&(W=n,U=t)}}if(W===1/0){let e=j.y+j.height+P;for(let t=0;t<200;t++){let t={x:j.x+j.width/2-r.width/2,y:e,width:r.width,height:r.height};if(H(t)<1/0){U=t;break}e+=P}}if(U!==r&&t.moves.push({elements:[e],dx:U.x-r.x,dy:U.y-r.y}),[...e.outgoing||[],...e.incoming||[]].forEach(n=>{let r=n,i=r.source?.id===e.id?r.target:r.source;if(!i)return;let a=_(i,U),o=r.source?.id===e.id,s=t.routes.filter(e=>e.connection.id!==r.id).map(e=>e.waypoints),c=Tt(o?U:a,o?a:U,V,s),l=t.routes.find(e=>e.connection.id===r.id);l?l.waypoints=c:t.routes.push({connection:r,waypoints:c})}),y.push(U),b.push(U),w.push(f(U)),F&&!i&&!re(U)){E.has(F.id)||E.set(F.id,{...c(F)});let e=T.get(F.id)??{...c(F)},t=Math.max(e.x+e.width,U.x+U.width+n.marginX),r=Math.max(e.y+e.height,U.y+U.height+n.marginY);e.x=Math.min(e.x,U.x-n.marginX),e.y=Math.min(e.y,U.y-n.marginY),e.width=t-e.x,e.height=r-e.y,T.set(F.id,e)}});let O=new Map(t.resizes.map(e=>[e.element.id,e])),k=(e,n)=>{let r=O.get(e.id);r?(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height):t.resizes.push({element:e,x:n.x,y:n.y,width:n.width,height:n.height})};T.forEach((e,t)=>{let n=s.find(e=>e.id===t);if(!n)return;k(n,e);let r=E.get(t);if(!r)return;let i=r.x-e.x,a=r.y-e.y,l=e.x+e.width-(r.x+r.width),u=e.y+e.height-(r.y+r.height);if(i<=0&&a<=0&&l<=0&&u<=0)return;let d=s.filter(e=>e.type===`bpmn:Lane`&&e.parent?.id===t);o&&d.length===1&&d.forEach(e=>{let t=O.get(e.id)??c(e);k(e,{x:t.x-i,y:t.y-a,width:t.width+i+l,height:t.height+a+u})})})}function kt(e,t,n){let{every:r,rectOf:i}=Y(e,t),a=r.filter(e=>e.type===`bpmn:Group`&&e.width>0&&e.height>0);if(a.length===0)return;let o=r.filter(e=>e.type!==`bpmn:Group`&&!w(e)&&!j(e)&&e.width>0&&e.height>0),s=new Map(t.resizes.map(e=>[e.element.id,e])),c=n.nodesep/2;a.forEach(e=>{let n=o.filter(t=>t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height);if(n.length===0)return;let r=n.map(i),a=Math.min(...r.map(e=>e.x))-c,l=Math.min(...r.map(e=>e.y))-c,u=Math.max(...r.map(e=>e.x+e.width))+c,d=Math.max(...r.map(e=>e.y+e.height))+c,f=i(e);e.label&&t.moves.push({elements:[e.label],dx:a-f.x,dy:l-f.y});let p=s.get(e.id);p?(p.x=a,p.y=l,p.width=u-a,p.height=d-l):t.resizes.push({element:e,x:a,y:l,width:u-a,height:d-l})})}function At(e,t,n){let{every:r,rectOf:i,driftOf:a,movedBy:s}=Y(e,t),c=[...r.filter(e=>e.label&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:Participant`),...t.routes.map(e=>e.connection).filter(e=>e.label)];if(c.sort((e,n)=>{let r=!!t.routes.find(t=>t.connection.id===e.id);return r===!!t.routes.find(e=>e.connection.id===n.id)?0:r?-1:1}),c.length===0)return;let l=r.filter(e=>e.type!==`bpmn:Lane`&&e.width>0&&e.height>0),u=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},d=[],f=e=>{let n=t.routes.find(t=>t.connection.id===e.id)?.waypoints??e.waypoints;if(n&&n.length>1){let e={from:n[0],to:n[1],span:-1};for(let t=0;t+1<n.length;t++){let r=Math.abs(n[t+1].x-n[t].x)+Math.abs(n[t+1].y-n[t].y);r>e.span&&(e={from:n[t],to:n[t+1],span:r})}return{x:(e.from.x+e.to.x)/2,y:(e.from.y+e.to.y)/2,width:0,height:0}}if(e.source&&e.target){let t=i(e.source),n=i(e.target);return{x:(t.x+t.width/2+n.x+n.width/2)/2,y:(t.y+t.height/2+n.y+n.height/2)/2,width:0,height:0}}return i(e)},p=n.nodesep/2;c.forEach(e=>{let n=e.label,r=s(n)??a(e),c={x:n.x+r.x,y:n.y+r.y,width:n.width,height:n.height},m=t.routes.some(t=>t.connection.id===e.id);if(!m){let t=i(e);if(c.x>=t.x-1&&c.y>=t.y-1&&c.x+c.width<=t.x+t.width+1&&c.y+c.height<=t.y+t.height+1)return}let h=/* @__PURE__ */ new Set([e.id,...u(e),...u(e.source),...u(e.target)]);g(e)&&e.host&&h.delete(e.host.id);let _=l.filter(e=>!h.has(e.id)).map(i),v=e=>_.some(t=>S(e,t))||d.some(t=>S(e,t)),y=n=>t.routes.some(t=>t.connection.id!==e.id&&M(t.waypoints,[n])>0);if(!v(c)&&!y(c)&&!(m&&(n=>{let r=t.routes.find(t=>t.connection.id===e.id)?.waypoints??e.waypoints??[];if(r.length<2)return!1;let i=n.x+n.width/2,a=n.y+n.height/2,s=1/0;for(let e=0;e+1<r.length;e++){let t=o({x:i,y:a},r[e],r[e+1]);s=Math.min(s,Math.abs(i-t.x)+Math.abs(a-t.y))}return s>40})(c))){d.push(c);return}if(m){let r=t.routes.find(t=>t.connection.id===e.id)?.waypoints??e.waypoints??[],i=[];for(let e=0;e+1<r.length;e++){let t=r[e],n=r[e+1];if(Math.abs(n.x-t.x)+Math.abs(n.y-t.y)<c.width/2)continue;let a=t.y===n.y;for(let e=1;e<=9;e++){let r=e/10,o={x:t.x+(n.x-t.x)*r,y:t.y+(n.y-t.y)*r};[1,2,3].flatMap(e=>a?[{x:o.x-c.width/2,y:o.y-c.height-4*e},{x:o.x-c.width/2,y:o.y+4*e}]:[{x:o.x+4*e,y:o.y-c.height/2},{x:o.x-c.width-4*e,y:o.y-c.height/2}]).forEach(e=>i.push({x:Math.round(e.x),y:Math.round(e.y),width:c.width,height:c.height}))}}let a=i.find(e=>!v(e)&&!y(e))??i.find(e=>!v(e));if(a){t.moves.push({elements:[n],dx:a.x-c.x,dy:a.y-c.y}),d.push(a);return}}let b=f(e),x=b.x+b.width/2-c.width/2,C=b.y+b.height/2-c.height/2,w=c,T;outer:for(let e=1;e<=8;e++){let t=b.y+b.height+p*e,n=b.y-p*e-c.height,r=b.x+b.width+p*e,i=b.x-p*e-c.width;for(let e of[{x,y:t},{x,y:n},{x:r,y:C},{x:i,y:C},{x:r,y:t},{x:i,y:t},{x:r,y:n},{x:i,y:n}]){let t={x:e.x,y:e.y,width:c.width,height:c.height};if(!v(t)){if(!y(t)){w=t;break outer}T||=t}}}w===c&&T&&(w=T),w!==c&&t.moves.push({elements:[n],dx:w.x-c.x,dy:w.y-c.y}),d.push(w)})}function jt(e,t,n,r=!1){let{every:a,rectOf:o}=Y(e,t),s=a.filter(e=>e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),l=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},u=/* @__PURE__ */ new Set;t.routes.forEach(e=>{let t=e.connection,d=/* @__PURE__ */ new Set([t.source?.id??``,t.target?.id??``,...l(t.source),...l(t.target)]),f=((t.type??``).includes(`Association`)?a.filter(e=>e.type!==`bpmn:Lane`&&e.width>0&&e.height>0):s).filter(e=>!d.has(e.id)).map(o),p=M(e.waypoints,f);if(p===0)return;let m=e.waypoints[0],h=e.waypoints[e.waypoints.length-1],g=f.filter(t=>e.waypoints.some((n,r)=>r+1<e.waypoints.length&&c(n,e.waypoints[r+1],[t])>0));if(g.length===0)return;let _=n.nodesep/2,v=_;if(r)for(let e=0;e<3;e++){let t=Math.round(Math.min(...g.map(e=>e.y),m.y,h.y)-v),n=Math.round(Math.max(...g.map(e=>e.y+e.height),m.y,h.y)+v);if(!u.has(t)&&!u.has(n))break;v=_+(e+1)*2}let y=Math.round(Math.min(...g.map(e=>e.y),m.y,h.y)-v),b=Math.round(Math.max(...g.map(e=>e.y+e.height),m.y,h.y)+v);r&&(u.add(y),u.add(b));let x=a.filter(e=>e.type===`bpmn:Participant`).flatMap(e=>{let t=o(e);return[t.y-v,t.y+t.height+v]}),S=[Math.min(...f.map(e=>e.x))-v,Math.max(...f.map(e=>e.x+e.width))+v],C=[...[y,b,...x].map(e=>[m,{x:m.x,y:e},{x:h.x,y:e},h]),...S.flatMap(e=>[y,b,...x].map(t=>[m,{x:m.x,y:t},{x:e,y:t},{x:e,y:h.y},h])),...Nt(e.waypoints)],w=e.waypoints,T=p,E=O(e.waypoints);C.forEach(e=>{let t=P(e);if(!i(t)||O(t)>E)return;let n=M(t,f);n<T&&(T=n,w=t)}),e.waypoints=w})}function Mt(e){let t=[];for(let n=1;n+2<e;n++)t.push(n);if(t.length<=16)return t;let n=(t.length-1)/15;return Array.from({length:16},(e,r)=>t[Math.round(r*n)])}function Nt(e,t=!1){if(e.length<2)return[e];let n=e[0],r=e[e.length-1],i=Math.abs(e[1].x-n.x)<.5,a=Math.abs(r.x-e[e.length-2].x)<.5,o=[],s=!t;if(s&&i&&a)for(let e=1;e<=7;e++){let t=n.y+(r.y-n.y)*e/8;o.push([n,{x:n.x,y:t},{x:r.x,y:t},r])}else if(s&&!i&&!a)for(let e=1;e<=7;e++){let t=n.x+(r.x-n.x)*e/8;o.push([n,{x:t,y:n.y},{x:t,y:r.y},r])}else s&&i?o.push([n,{x:n.x,y:r.y},r]):s&&o.push([n,{x:r.x,y:n.y},r]);if(s)for(let t of Mt(e.length)){let n=Math.abs(e[t].x-e[t+1].x)<.5;for(let r=1;r<=40;r++)for(let i of[1,-1]){let a=i*r*20,s=(e,r)=>r!==t&&r!==t+1?e:n?{x:e.x+a,y:e.y}:{x:e.x,y:e.y+a};if(o.push(e.map(s)),t+3<e.length){let n=Math.abs(e[t+2].x-e[t+3].x)<.5;o.push(e.map((e,r)=>{let i=s(e,r);return r!==t+2&&r!==t+3?i:n?{x:i.x+a,y:i.y}:{x:i.x,y:i.y+a}}))}}}for(let n=0;t&&n+3<e.length;n++){let[t,r,i,a]=[e[n],e[n+1],e[n+2],e[n+3]],s=Math.abs(t.x-r.x)<.5&&Math.abs(i.x-a.x)<.5,c=Math.abs(t.y-r.y)<.5&&Math.abs(i.y-a.y)<.5;if(!(s?(r.y-t.y)*(a.y-i.y)<0:c&&(r.x-t.x)*(a.x-i.x)<0))continue;let l=s?{x:a.x,y:t.y}:{x:t.x,y:a.y};o.push([...e.slice(0,n+1),l,...e.slice(n+3)])}return o.map(P).filter(e=>e.length>=2)}function Pt(e,t){return new Set(t.filter(t=>M(e,[t.rect])>0).map(e=>e.id))}function Ft(e,t,n){let r=Pt(t,n);return[...Pt(e,n)].some(e=>!r.has(e))}function It(e,t){let{every:n,rectOf:r}=Y(e,t),i=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},a=n.filter(e=>e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=(e,t)=>new Set([e.connection.source?.id,e.connection.target?.id,t.connection.source?.id,t.connection.target?.id].filter(Boolean)).size<4;for(let e=0;e<30;e++){let e=!1;if(t.routes.forEach(n=>{let s=t.routes.filter(e=>e!==n&&!o(n,e)),c=e=>s.reduce((t,n)=>t+N(e,n.waypoints),0)*1e6+e.length*200+f(e),l=c(n.waypoints);if(l<1e6)return;let u=/* @__PURE__ */ new Set([n.connection.source?.id??``,n.connection.target?.id??``,...i(n.connection.source),...i(n.connection.target)]),d=a.filter(e=>!u.has(e.id)).map(e=>({id:e.id,rect:r(e)})),p=d.map(e=>e.rect),m=M(n.waypoints,p),h=n.waypoints,g=l,_=n.waypoints[0],v=n.waypoints[n.waypoints.length-1];Nt(n.waypoints).forEach(e=>{let t=e[0],r=e[e.length-1];if(t.x!==_.x||t.y!==_.y||r.x!==v.x||r.y!==v.y||!e.every((t,n)=>n===0||Math.abs(t.x-e[n-1].x)<.5||Math.abs(t.y-e[n-1].y)<.5)||M(e,p)>m||Ft(e,n.waypoints,d)||O(e)>O(n.waypoints))return;let i=c(e);i<g&&(g=i,h=e)}),h!==n.waypoints&&(n.waypoints=h,e=!0)}),!e)break}}function Lt(e,t,n=!0,r=!1,i=!1){let a=[],o=e=>{a.push(e),(e.attachers||[]).forEach(e=>a.push(e)),(e.children||[]).forEach(o)};(e.children||[]).forEach(o);let s=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let n=s.get(t.id)??{x:0,y:0};s.set(t.id,{x:n.x+e.dx,y:n.y+e.dy})}));let c=new Map(t.resizes.map(e=>[e.element.id,e])),l=a.map(e=>{let t=c.get(e.id);if(t)return{...e,x:t.x,y:t.y,width:t.width,height:t.height};let n=s.get(e.id)??{x:0,y:0};return{...e,x:e.x+n.x,y:e.y+n.y}}),u=new Map(l.map(e=>[e.id,e]));l.forEach(e=>{e.parent=e.parent?u.get(e.parent.id)??e.parent:e.parent});let d=/* @__PURE__ */ new Map;a.forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;_(t)&&d.set(t.id,t)})),d.size!==0&&ct([...d.values()].map(e=>({...e,source:e.source?u.get(e.source.id)??e.source:e.source,target:e.target?u.get(e.target.id)??e.target:e.target})),l,t.routes.filter(e=>!_(e.connection)).map(e=>e.waypoints),n,r,i).forEach(({connection:e,waypoints:n})=>{let r=d.get(e.id);if(!r)return;let i=t.routes.find(t=>t.connection.id===e.id);i?i.waypoints=n:t.routes.push({connection:r,waypoints:n})})}function Rt(e){if(e.length===0)return[];let t=[],n=f(e);if(n===0)return[e[0]];let r=n/16,i=0,a=0;for(let n=0;n+1<e.length;n++){let o=e[n],s=e[n+1],c=Math.abs(s.x-o.x)+Math.abs(s.y-o.y);for(;c>0&&a<=i+c;){let e=(a-i)/c;t.push({x:o.x+(s.x-o.x)*e,y:o.y+(s.y-o.y)*e}),a+=r}i+=c}return t.push(e[e.length-1]),t}function zt(e,t,n,r,i){let a={x:t.x+t.width/2,y:t.y+t.height/2},o;return Rt(e).forEach(e=>{let s={x:e.x,y:e.y,width:0,height:0},c={x:Math.max(t.x,Math.min(e.x,t.x+t.width)),y:Math.max(t.y,Math.min(e.y,t.y+t.height))},l=n?[c,e]:[e,c],u=Tt(n?t:s,n?s:t,r,i),d=(Math.abs(c.x-e.x)<.5||Math.abs(c.y-e.y)<.5)&&M(l,r)===0&&i.reduce((e,t)=>e+N(l,t),0)<=i.reduce((e,t)=>e+N(u,t),0)?l:u,f=M(d,r),p=f>0?Ke({x:t.x+t.width/2,y:t.y+t.height/2},e,r,i,20):null,m=p&&M(p,r)<f?n?p:[...p].reverse():d,h=Math.abs(e.x-a.x)+Math.abs(e.y-a.y),g=M(m,r)*4e3+i.reduce((e,t)=>e+N(m,t),0)*600+i.filter(e=>b(m,e)).length*1200+h;(!o||g<o.price)&&(o={at:s,waypoints:m,price:g})}),o?{at:o.at,waypoints:o.waypoints}:{at:t,waypoints:[]}}function Bt(e,t){return e.flatMap(e=>{if(!e.elements.some(e=>e.id===t))return[e];let n=e.elements.filter(e=>e.id!==t);return n.length===0?[]:[{...e,elements:n}]})}function Vt(e,t){let{every:n,rectOf:r,refresh:i}=Y(e,t),a=new Map(t.routes.map(e=>[e.connection.id,e.waypoints])),o=n.filter(e=>!x.has(e.type??``)&&!e.source&&!e.target&&e.width>0&&e.height>0),s=n.filter(e=>e.type===`bpmn:TextAnnotation`&&!e.source&&!e.target&&e.width>0&&e.height>0),c=[],u=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},d=e=>e.type===`bpmn:Lane`||e.type===`bpmn:Participant`||e.type===`bpmn:SubProcess`,f=/* @__PURE__ */ new Map;t.routes.forEach(e=>{let t=e.connection;if(t.type!==`bpmn:Association`)return;let n=[t.source,t.target].filter(e=>!!e),r=n.find(e=>!!e.source&&!!e.target),i=n.find(e=>e!==r);r&&i&&a.get(r.id)&&(f.has(i.id)||f.set(i.id,{note:i,links:[]}),f.get(i.id).links.push({op:e,owner:r}))}),f.forEach(({note:e,links:f})=>{let p=r(e),m=u(e),h=n.find(e=>d(e)&&m.has(e.id)),g=/* @__PURE__ */ new Set([e.id,...m,...f.flatMap(({owner:e})=>[e.id,...u(e)])]),_=o.filter(e=>!g.has(e.id)).map(r),v=o.filter(e=>!g.has(e.id)&&!d(e)).flatMap(e=>e.label?[r(e),r(e.label)]:[r(e)]).concat(s.filter(t=>t.id!==e.id).map(r)).concat(c),y=n.filter(e=>d(e)&&!m.has(e.id)).map(r),b=t.routes.filter(e=>!f.some(({op:t})=>t.connection.id===e.connection.id)).map(e=>e.waypoints),x=t=>f.map(({op:n,owner:r})=>({op:n,line:zt(a.get(r.id),t,n.connection.source?.id===e.id,_,b)})),C=e=>e.reduce((e,{line:t})=>e+M(t.waypoints,_),0),w=e=>e.reduce((e,{line:t})=>e+t.waypoints.reduce((e,n,r)=>r===0?0:e+Math.abs(n.x-t.waypoints[r-1].x)+Math.abs(n.y-t.waypoints[r-1].y),0),0),T=e=>C(e)>0||w(e)>260*f.length,E=t.moves.filter(t=>t.elements.some(t=>t.id===e.id)),D={x:p.x-E.reduce((e,t)=>e+t.dx,0),y:p.y-E.reduce((e,t)=>e+t.dy,0),width:p.width,height:p.height},O=p,k=x(p);if(T(k)){let e=k[0].line.at;for(let t=1;t<=8&&T(k);t++){let n=20*t;[{x:e.x-p.width/2,y:e.y+n},{x:e.x-p.width/2,y:e.y-n-p.height},{x:e.x+n,y:e.y-p.height/2},{x:e.x-n-p.width,y:e.y-p.height/2}].map(e=>({x:e.x,y:e.y,width:p.width,height:p.height})).forEach(e=>{if(!T(k)||v.some(t=>S(e,t))||y.some(t=>S(e,t))||h&&!l(r(h),e))return;let t=x(e);C(t)>0||w(t)>=w(k)||(O=e,k=t)})}}if(C(k)>0){let n=x(D);C(n)<C(k)&&(t.moves=Bt(t.moves,e.id),i(),k=n,O=p)}O!==p&&(t.moves.push({elements:[e],dx:O.x-p.x,dy:O.y-p.y}),c.push(O)),k.forEach(({op:e,line:t})=>{e.waypoints=t.waypoints})})}function Ht(e,t){let{every:n,rectOf:r}=Y(e,t),i=n.filter(e=>e.type!==`bpmn:Participant`&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:SubProcess`&&e.width>0&&e.height>0).map(r);t.routes.forEach(e=>{if(!(e.connection.type??``).includes(`Association`))return;let a=e.connection.source,o=e.connection.target;if(!a||!o)return;let s=/* @__PURE__ */ new Set([a.id,o.id]),c=n.filter(e=>!s.has(e.id)&&i.length>0).filter(e=>e.type!==`bpmn:Participant`&&e.type!==`bpmn:Lane`&&e.type!==`bpmn:SubProcess`&&e.width>0&&e.height>0).map(r),l=t.routes.filter(t=>t!==e).map(e=>e.waypoints);e.waypoints=Tt(r(a),r(o),c,l)})}function Ut(e){return e.routes.map(e=>`${e.connection.id}:${e.waypoints.map(e=>`${Math.round(e.x)},${Math.round(e.y)}`).join(` `)}`).join(`|`)}function Wt(e,t,n,r=12){for(let i=1;i<=r;i++){let r=Ut(t);if(jt(e,t,n),It(e,t),Ut(t)===r)return i}return r}function Gt(e,t){if(e.length===0)return;let n=/* @__PURE__ */ new Map;t.moves.forEach(e=>e.elements.forEach(t=>{let r=n.get(t.id)??{x:0,y:0};n.set(t.id,{x:r.x+e.dx,y:r.y+e.dy})}));let r=new Map(t.resizes.map(e=>[e.element.id,e]));e.forEach(e=>{if(r.has(e.id))return;let i=n.get(e.id)??{x:0,y:0};t.resizes.push({element:e,x:e.x+i.x,y:e.y+i.y,width:e.width,height:e.height})})}function Kt(e,t){let n=0;for(let r=0;r+1<e.length;r++){let i=p(e[r],e[r+1]);i&&t.some(e=>d(i,e))&&(n+=1)}return n}function qt(e,t){let n=/* @__PURE__ */ new Set;for(let r=0;r+1<e.length;r++){let i=p(e[r],e[r+1]);i&&t.forEach((e,t)=>{d(i,e)&&n.add(t)})}return n}function Jt(e,t){for(let n of t)if(!e.has(n))return!0;return!1}const Yt=[8,-8,16,-16,24,-24,32,-32,40,-40,60,-60,80,-80,100,-100,120,-120,160,-160,200,-200,300,-300,400,-400];function Xt(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>({id:e.id,rect:r(e)}))},s=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},c=s(),l=t.routes.map(e=>e.waypoints);t.routes.forEach(e=>{let n=t.routes.filter(t=>t!==e).map(e=>e.waypoints),a=o(e),s=a.map(e=>e.rect),c=(e,t)=>!q(e,t,s),l=e.connection.source?r(e.connection.source):void 0,u=e.connection.target?r(e.connection.target):void 0;for(let t=0;t+1<e.waypoints.length;t++){let r=e.waypoints,o=r[t],d=r[t+1],f=Math.abs(o.y-d.y)<.5,p=Math.abs(o.x-d.x)<.5;if(!f&&!p)continue;let m=t===0,h=t+1===r.length-1,g=t+1;if(m)for(;g+1<r.length&&(f?Math.abs(r[g+1].y-o.y)<.5:Math.abs(r[g+1].x-o.x)<.5);)g+=1;let _=t;if(h)for(;_-1>=0&&(f?Math.abs(r[_-1].y-d.y)<.5:Math.abs(r[_-1].x-d.x)<.5);)--_;let v=n.filter(e=>b(r,e)).length,y=Kt(r,s);if(v===0&&y===0)continue;let x=n.filter(e=>N(r,e)>0).length,S=M(r,s),C=O(r),w=T(r,c);for(let t of Yt){let o=r.map(e=>({...e}));for(let e=_;e<=g;e++)f?o[e].y+=t:o[e].x+=t;let d=P(o);if(!i(d)||l&&!J(d[0],l)||u&&!J(d[d.length-1],u)||M(d,s)>S||Ft(d,r,a)||n.filter(e=>N(d,e)>0).length>x||O(d)>C||T(d,c)>w)continue;let p=n.filter(e=>b(d,e)).length,m=Kt(d,s);if(!(p>v||m>y)&&!(p>=v&&m>=y)){e.waypoints=d;break}}}let d=n.filter(t=>b(e.waypoints,t)).length,f=Kt(e.waypoints,s);if(d===0&&f===0)return;let p=e.waypoints[0],m=e.waypoints[e.waypoints.length-1],h=n.filter(t=>N(e.waypoints,t)>0).length,g=O(e.waypoints),_=M(e.waypoints,s),v=e.waypoints,y=d,x=f;Nt(e.waypoints).forEach(t=>{let r=t[0],o=t[t.length-1];if(r.x!==p.x||r.y!==p.y||o.x!==m.x||o.y!==m.y||!i(t)||M(t,s)>_||Ft(t,e.waypoints,a)||n.filter(e=>N(t,e)>0).length>h||O(t)>g)return;let c=n.filter(e=>b(t,e)).length,l=Kt(t,s);c>y||l>x||c>=y&&l>=x||(v=t,y=c,x=l)}),e.waypoints=v}),s()>c&&t.routes.forEach((e,t)=>{e.waypoints=l[t]})}function Zt(e){return!!e&&((e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`))}const Qt=Yt[0];function $t(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&e.type!==`bpmn:Lane`&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>r(e))},s=(e,t,n)=>{let i=r(e),a=Math.abs(t.y-n.y)<.5&&Math.abs(t.x-n.x)>=.5;if(Math.abs(t.x-n.x)<.5&&Math.abs(t.y-n.y)>=.5)return t.y<=i.y+i.height/2?`n`:`s`;if(a)return t.x<=i.x+i.width/2?`w`:`e`},c=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Map;{let e=/* @__PURE__ */ new Set;t.routes.forEach(t=>{let n=t.waypoints;if(n.length<2)return;[t.connection.source,t.connection.target].forEach(t=>{t&&Zt(t)&&(e.has(t.id)?c.add(t.id):e.add(t.id))});let r=t.connection.source;if(r&&Zt(r)){let e=s(r,n[0],n[1]),i=`${r.id}:${e}`;e&&l.set(i,[...l.get(i)??[],`${t.connection.id}:s`])}let i=t.connection.target;if(i&&Zt(i)){let e=s(i,n[n.length-1],n[n.length-2]),r=`${i.id}:${e}`;e&&l.set(r,[...l.get(r)??[],`${t.connection.id}:t`])}}),l.forEach(e=>e.sort())}t.routes.forEach(e=>{if(e.waypoints.length<2||!(e.connection.source&&c.has(e.connection.source.id)||e.connection.target&&c.has(e.connection.target.id)))return;let n=t.routes.filter(t=>t!==e).map(e=>e.waypoints),a=o(e),u=t=>{let o=e.waypoints;if(o.length<2)return;let c=t?e.connection.source:e.connection.target;if(!Zt(c)||!c)return;let u=t?0:o.length-1,d=t?1:o.length-2,f=o[u],p=o[d],m=Math.abs(f.y-p.y)<.5&&Math.abs(f.x-p.x)>=.5,h=Math.abs(f.x-p.x)<.5&&Math.abs(f.y-p.y)>=.5;if(!m&&!h)return;let g=s(c,f,p),_=`${e.connection.id}:${t?`s`:`t`}`,v=g?l.get(`${c.id}:${g}`)??[_]:[_],y=Math.max(0,v.indexOf(_)),x=r(c),S=m?x.width:x.height,C=Math.min(S/2-4,Math.max(10,S*.4)),w=Math.ceil(y/2),T=y===0?0:w*C*(y%2==1?1:-1),E=m?{x:f.x,y:x.y+x.height/2+T}:{x:x.x+x.width/2+T,y:f.y};if(Math.abs(E.x-f.x)<4&&Math.abs(E.y-f.y)<4)return;let D=m?Math.sign(p.x-f.x)||1:Math.sign(p.y-f.y)||1,k=m?{x:E.x+D*Qt,y:E.y}:{x:E.x,y:E.y+D*Qt},A=m?{x:k.x,y:f.y}:{x:f.x,y:k.y},j=t?[E,k,A,...o.slice(1).map(e=>({...e}))]:[...o.slice(0,-1).map(e=>({...e})),A,k,E],F=t?o[2]:o[o.length-3],I=m?{x:p.x,y:E.y}:{x:E.x,y:p.y},L=F&&(t?[E,I,...o.slice(2).map(e=>({...e}))]:[...o.slice(0,-2).map(e=>({...e})),I,E]),R=n.filter(e=>b(o,e)).length,z=qt(o,a),ee=n.filter(e=>N(o,e)>0).length,B=M(o,a),te=O(o);for(let t of[L,j]){if(!t)continue;let r=P(t);if(i(r)&&!(M(r,a)>B)&&!(O(r)>te)&&!(n.filter(e=>N(r,e)>0).length>ee)&&!(n.filter(e=>b(r,e)).length>R)&&!Jt(z,qt(r,a))){e.waypoints=r;return}}};u(!0),u(!1)})}function en(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&e.type!==`bpmn:Lane`&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>r(e))},s=e=>[e.connection.source?.id,e.connection.target?.id].filter(e=>!!e);t.routes.forEach(e=>{let n=t.routes.filter(t=>t!==e&&s(t).some(t=>s(e).includes(t)));if(n.length===0)return;let a=t.routes.filter(t=>t!==e).map(e=>e.waypoints),c=o(e);for(let t=0;t+1<e.waypoints.length;t++){let o=e.waypoints,s=o[t],l=o[t+1],u=Math.abs(s.y-l.y)<.5&&Math.abs(s.x-l.x)>=.5,d=Math.abs(s.x-l.x)<.5&&Math.abs(s.y-l.y)>=.5;if(!u&&!d)continue;let f=u?`y`:`x`,p=u?s.y:s.x,m=Math.min(u?s.x:s.y,u?l.x:l.y),h=Math.max(u?s.x:s.y,u?l.x:l.y);if(!n.some(e=>y(e.waypoints).some(e=>e.axis!==f||Math.abs(e.at-p)>=30?!1:Math.min(h,e.to)-Math.max(m,e.from)>=60)))continue;let g=n.flatMap(e=>y(e.waypoints).map(e=>e)).filter(e=>e.axis!==f||Math.abs(e.at-p)>=30?!1:Math.min(h,e.to)-Math.max(m,e.from)>=60),_=a.filter(e=>b(o,e)).length,v=qt(o,c),x=a.filter(e=>N(o,e)>0).length,S=M(o,c),C=O(o),w=e=>!!e&&((e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`)),T=t===0&&w(e.connection.source),E=t+1===o.length-1&&w(e.connection.target),D=(T||E)&&!(T&&E),k=Yt[0],A=(e,t)=>u?{x:t.x,y:e.y+e.height/2}:{x:e.x+e.width/2,y:t.y},j=T&&e.connection.source?A(r(e.connection.source),o[0]):o[0],F=E&&e.connection.target?A(r(e.connection.target),o[o.length-1]):o[o.length-1],I=e=>{if(!D){let n=o.map(e=>({...e}));return u?(n[t].y+=e,n[t+1].y+=e):(n[t].x+=e,n[t+1].x+=e),n}if(T){let t={...j},n=o[1],r=u?{x:t.x+(Math.sign(n.x-t.x)||1)*k,y:t.y}:{x:t.x,y:t.y+(Math.sign(n.y-t.y)||1)*k};return[t,r,u?{x:r.x,y:n.y+e}:{x:n.x+e,y:r.y},u?{x:n.x,y:n.y+e}:{x:n.x+e,y:n.y},...o.slice(2).map(e=>({...e}))]}let n=o.length,r={...F},i=o[n-2],a=u?{x:r.x+(Math.sign(i.x-r.x)||1)*k,y:r.y}:{x:r.x,y:r.y+(Math.sign(i.y-r.y)||1)*k},s=u?{x:a.x,y:i.y+e}:{x:i.x+e,y:a.y},c=u?{x:i.x,y:i.y+e}:{x:i.x+e,y:i.y};return[...o.slice(0,n-2).map(e=>({...e})),c,s,a,r]},L=!1;for(let n of[!0,!1]){if(L)break;for(let s of Yt){let l=I(s),d=P(l);if(!i(d))continue;if(T){if(d[0].x!==j.x||d[0].y!==j.y)continue}else if(d[0].x!==o[0].x||d[0].y!==o[0].y){if(t!==0)continue;let n=e.connection.source?r(e.connection.source):void 0;if(!n||!J(d[0],n))continue}if(E){if(d[d.length-1].x!==F.x||d[d.length-1].y!==F.y)continue}else if(d[d.length-1].x!==o[o.length-1].x||d[d.length-1].y!==o[o.length-1].y){if(t+1!==o.length-1)continue;let n=e.connection.target?r(e.connection.target):void 0;if(!n||!J(d[d.length-1],n))continue}if(M(d,c)>S||O(d)>C||a.filter(e=>N(d,e)>0).length>x||a.filter(e=>b(d,e)).length>_||Jt(v,qt(d,c)))continue;let f=u?T?l[2].y:E?l[l.length-3].y:l[t].y:T?l[2].x:E?l[l.length-3].x:l[t].x;if(n){if(g.some(e=>Math.abs(e.at-f)<30))continue}else if(g.some(e=>Math.abs(e.at-f)<Math.abs(e.at-p)))continue;e.waypoints=d,L=!0;break}}}})}function tn(e,t){let{every:n,rectOf:r}=Y(e,t),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...a(e.connection.source),...a(e.connection.target)]);return n.filter(e=>!w(e)&&e.type!==`bpmn:Lane`&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>r(e))};t.routes.forEach(e=>{let n=t.routes.filter(t=>t!==e).map(e=>e.waypoints),a=o(e);for(let t=0;t+1<e.waypoints.length;t++){let o=e.waypoints,s=o[t],c=o[t+1],l=Math.abs(s.y-c.y)<.5&&Math.abs(s.x-c.x)>=.5,u=Math.abs(s.x-c.x)<.5&&Math.abs(s.y-c.y)>=.5;if(!l&&!u)continue;let d=l?`y`:`x`,f=l?s.y:s.x,p=Math.min(l?s.x:s.y,l?c.x:c.y),m=Math.max(l?s.x:s.y,l?c.x:c.y);if(m-p<150)continue;let h=a.filter(e=>{if(!(d===`x`?[e.x,e.x+e.width]:[e.y,e.y+e.height]).some(e=>Math.abs(e-f)<=2))return!1;let t=d===`x`?e.y:e.x,n=d===`x`?e.y+e.height:e.x+e.width;return Math.min(m,n)-Math.max(p,t)>=20});if(h.length===0)continue;let g=n.filter(e=>b(o,e)).length,_=qt(o,a),v=n.filter(e=>N(o,e)>0).length,y=M(o,a),x=O(o);for(let s of Yt){let c=o.map(e=>({...e}));l?(c[t].y+=s,c[t+1].y+=s):(c[t].x+=s,c[t+1].x+=s);let u=P(c);if(!i(u))continue;if(t===0){let t=e.connection.source?r(e.connection.source):void 0;if(!t||!J(u[0],t))continue}else if(u[0].x!==o[0].x||u[0].y!==o[0].y)continue;if(t+1===o.length-1){let t=e.connection.target?r(e.connection.target):void 0;if(!t||!J(u[u.length-1],t))continue}else if(u[u.length-1].x!==o[o.length-1].x||u[u.length-1].y!==o[o.length-1].y)continue;if(M(u,a)>y||O(u)>x||n.filter(e=>N(u,e)>0).length>v||n.filter(e=>b(u,e)).length>g||Jt(_,qt(u,a)))continue;let f=l?c[t].y:c[t].x;if(!h.some(e=>(d===`x`?[e.x,e.x+e.width]:[e.y,e.y+e.height]).some(e=>Math.abs(e-f)<20))){e.waypoints=u;break}}}})}function nn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},s=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},c=s(),l=t.routes.map(e=>e.waypoints);t.routes.forEach(e=>{let n=e.connection;if(!_(n)||!n.source||!n.target)return;let s=e.waypoints;if(s.length<2)return;let c=f(s),l=r(n.source),u=r(n.target),d=Math.abs(l.x+l.width/2-(u.x+u.width/2))+Math.abs(l.y+l.height/2-(u.y+u.height/2));if(d<40||c<=d*2)return;let p=/* @__PURE__ */ new Set([n.source.id,n.target.id,...o(n.source),...o(n.target)]),m=a.filter(e=>!p.has(e.id)).map(r),h=t.routes.filter(t=>t!==e).map(e=>e.waypoints),g=h.reduce((e,t)=>e+ +(N(s,t)>0),0),v=h.filter(e=>b(s,e)).length,y=O(s),x=Tt(l,u,m,h),S=M(x,m)===0,C=S?[x]:Nt(s),w=s[0],T=s[s.length-1],E,D=c;C.forEach(e=>{if(!S){let t=e[0],n=e[e.length-1];if(Math.abs(t.x-w.x)>2||Math.abs(t.y-w.y)>2||Math.abs(n.x-T.x)>2||Math.abs(n.y-T.y)>2)return}if(M(e,m)>0||!i(e)||O(e)>y)return;let t=f(e);t>=D||h.reduce((t,n)=>t+ +(N(e,n)>0),0)>g||h.filter(t=>b(e,t)).length>v||(D=t,E=e)}),E&&(e.waypoints=E)}),s()>c&&t.routes.forEach((e,t)=>{e.waypoints=l[t]})}function rn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},s=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},c=s(),l=t.routes.map(e=>e.waypoints);t.routes.forEach(e=>{let n=e.connection;if(!n.source||!n.target||!Zt(n.source)&&!Zt(n.target))return;let s=e.waypoints;if(s.length<2)return;let c=f(s),l=r(n.source),u=r(n.target),d=/* @__PURE__ */ new Set([n.source.id,n.target.id,...o(n.source),...o(n.target)]),p=a.filter(e=>!d.has(e.id)).map(r),m=t.routes.filter(t=>t!==e).map(e=>e.waypoints),h=m.reduce((e,t)=>e+ +(N(s,t)>0),0),g=m.filter(e=>b(s,e)).length,_=O(s),v=Tt(l,u,p,m);M(v,p)>0||i(v)&&(O(v)>_||f(v)>=c||m.reduce((e,t)=>e+ +(N(v,t)>0),0)>h||m.filter(e=>b(v,e)).length>g||(e.waypoints=v))}),s()>c&&t.routes.forEach((e,t)=>{e.waypoints=l[t]})}function an(e){e.routes.forEach(e=>{e.waypoints=h(e.waypoints)})}function on(e,t,n,r=`vpsc`){let{every:a,rectOf:o}=Y(e,t),s=a.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)).map(o),l=(e,n)=>t.routes.reduce((t,r)=>r===n?t:t+N(e,r.waypoints),0),u=()=>{let e=0;for(let n=0;n<t.routes.length;n++)for(let r=n+1;r<t.routes.length;r++)N(t.routes[n].waypoints,t.routes[r].waypoints)>0&&(e+=1);return e},d=u(),f=t.routes.map(e=>e.waypoints),p=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},m=e=>{let t=/* @__PURE__ */ new Set([e.connection.source?.id,e.connection.target?.id,...p(e.connection.source),...p(e.connection.target)]);return a.filter(e=>!w(e)&&!j(e)&&!D.has(e.type??``)&&e.width>0&&e.height>0&&!t.has(e.id)).map(e=>({id:e.id,rect:o(e)}))},h=e=>m(e).map(e=>e.rect);(r===`lattice`?_t(t.routes,h):r===`border`?gt(t.routes,h):r===`ordered`?ht(t.routes,n):dt(t.routes,n)).forEach(({route:e,index:t,axis:n,at:r})=>{let a=e.waypoints;if(t+1>=a.length)return;let u=a.map(e=>({...e})),d=n===`y`?{y:r}:{x:r};u[t]={...u[t],...d},u[t+1]={...u[t+1],...d};let f=i(u),p=e.connection.source?o(e.connection.source):void 0,h=e.connection.target?o(e.connection.target):void 0,g=(!p||J(u[0],p))&&(!h||J(u[u.length-1],h));if(!f||!g)return;let _=m(e),v=_.map(e=>e.rect);c(u[t],u[t+1],v)>c(a[t],a[t+1],v)||Ft(u,a,_)||M(u,s)>M(a,s)||l(u,e)>l(a,e)||O(u)>O(a)||(e.waypoints=u)}),u()>d?t.routes.forEach((e,t)=>{e.waypoints=f[t]}):t.routes.forEach(e=>{e.waypoints=P(e.waypoints)})}function sn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)).map(e=>({id:e.id,rect:r(e)})),o=a.map(e=>e.rect),s=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&(e.children||[]).filter(e=>!w(e)&&!j(e)).length===0).map(r),c=(e,n)=>t.routes.reduce((t,r)=>r===n?t:t+N(e,r.waypoints),0),l=(e,n)=>t.routes.filter(t=>t!==n&&b(e,t.waypoints)).length;t.routes.forEach(e=>{for(let t=0;t<2;t++){let t=e.waypoints,n=!0;for(let u=0;u+3<t.length;u++){let[d,f,p,m]=[t[u],t[u+1],t[u+2],t[u+3]],h=d.x===f.x&&p.x===m.x&&f.y===p.y,g=d.y===f.y&&p.y===m.y&&f.x===p.x,_=h?Math.abs(f.x-p.x):g?Math.abs(f.y-p.y):0;if(!h&&!g||_<.5||_>=40)continue;let v=e.connection.source?r(e.connection.source):void 0,y=e.connection.target?r(e.connection.target):void 0,b=h?[d.x,m.x]:[d.y,m.y];for(let r of b){let d=t.map(e=>({...e}));for(let e=0;e<=3;e++)h?d[u+e].x=r:d[u+e].y=r;let f=P(d),p=i(f),m=(!v||J(f[0],v))&&(!y||J(f[f.length-1],y));if(p&&m&&!(M(f,o)>M(t,o))&&!(M(f,s)>M(t,s))&&!Ft(f,t,a)&&!(c(f,e)>c(t,e))&&!(l(f,e)>l(t,e))&&!(O(f)>O(t))){e.waypoints=f,n=!1;break}}if(!n)break}if(n)break}})}function cn(e,t){let{every:n,rectOf:r}=Y(e,t),i=n.filter(e=>e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),a=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},o=(e,t,n)=>{let i=r(e);if(Math.abs(t.y-n.y)<.5){let e=t.y;if(Math.abs(e-i.y)<.5||Math.abs(e-(i.y+i.height))<.5){let e=Math.min(t.x,n.x);return Math.max(t.x,n.x)>i.x&&e<i.x+i.width}}if(Math.abs(t.x-n.x)<.5){let e=t.x;if(Math.abs(e-i.x)<.5||Math.abs(e-(i.x+i.width))<.5){let e=Math.min(t.y,n.y);return Math.max(t.y,n.y)>i.y&&e<i.y+i.height}}return!1};for(let e=0;e<2;e++){let e=!1;if(t.routes.forEach(n=>{if(n.waypoints.length<=4)return;let s=n.connection,c=/* @__PURE__ */ new Set([s.source?.id??``,s.target?.id??``,...a(s.source),...a(s.target)]),l=i.filter(e=>!c.has(e.id)).map(r),u=t.routes.filter(e=>e!==n).map(e=>e.waypoints),d=e=>M(e,l)*1e6+u.reduce((t,n)=>t+N(e,n),0)*1e4+e.length*200+f(e),p=d(n.waypoints),m=!!s.source&&o(s.source,n.waypoints[0],n.waypoints[1]),h=!!s.target&&o(s.target,n.waypoints[n.waypoints.length-1],n.waypoints[n.waypoints.length-2]),g=n.waypoints,_=p;Nt(n.waypoints,!0).forEach(e=>{if(!m&&s.source&&o(s.source,e[0],e[1])||!h&&s.target&&o(s.target,e[e.length-1],e[e.length-2]))return;let t=d(e);t<_&&(_=t,g=e)}),g!==n.waypoints&&(n.waypoints=g,e=!0)}),!e)break}}const ln=[20,60,120,300],un=[6,3,1];function dn(e,t){let n=[];for(let r=0;r+1<e.length;r++){let i=e[r],a=e[r+1];n.push({x:Math.min(i.x,a.x)-t,y:Math.min(i.y,a.y)-t,width:Math.abs(a.x-i.x)+t*2,height:Math.abs(a.y-i.y)+t*2})}return n}function fn(e,t,n,r){let i,a=1/0;for(let o=0;o+1<e.length;o++){let s=e[o],c=e[o+1],l;if(t===`x`&&s.y===c.y){let e=Math.min(s.x,c.x),t=Math.max(s.x,c.x);n>=e&&n<=t&&(l={x:n,y:s.y})}else if(t===`y`&&s.x===c.x){let e=Math.min(s.y,c.y),t=Math.max(s.y,c.y);n>=e&&n<=t&&(l={x:s.x,y:n})}if(!l)continue;let u=Math.abs(l.x-r.x)+Math.abs(l.y-r.y);u<a&&(a=u,i=l)}return i}function pn(e,t){let n=e[0],r=1/0;for(let i=0;i+1<e.length;i++){let a=e[i],o=e[i+1],s=o.x-a.x,c=o.y-a.y,l=s*s+c*c,u=l===0?0:Math.max(0,Math.min(1,((t.x-a.x)*s+(t.y-a.y)*c)/l)),d={x:a.x+u*s,y:a.y+u*c},f=Math.abs(d.x-t.x)+Math.abs(d.y-t.y);f<r&&(r=f,n=d)}return n}function mn(e,t){return[[e,{x:t.x,y:e.y},t],[e,{x:e.x,y:t.y},t]]}function hn(e,t,n,r,a){let o=[];for(let{route:s,end:c}of e){if(s.waypoints.length<2)return;let e=c===`first`?s.waypoints[0]:s.waypoints[s.waypoints.length-1],l=c===`first`?s.waypoints[1]:s.waypoints[s.waypoints.length-2],u=s.connection.source?r(s.connection.source):void 0,d=s.connection.target?r(s.connection.target):void 0,f=/* @__PURE__ */ new Set([s.connection.source?.id,s.connection.target?.id,...a(s.connection.source),...a(s.connection.target)]),p=n.filter(e=>!f.has(e.id)).map(r),m=M(s.waypoints,p),h=c===`first`?d:u,g;if(l.x===e.x||l.y===e.y){let n=l.x===e.x?`x`:`y`,r=fn(t,n,n===`x`?l.x:l.y,e);if(r){let e=s.waypoints.map(e=>({...e}));c===`first`?e[0]=r:e[e.length-1]=r,i(e)&&M(e,p)<=m&&(g=e)}}if(!g){let n=pn(t,e),r=c===`first`?s.waypoints.slice(2):s.waypoints.slice(0,-2);for(let e of mn(l,n)){let t=P(c===`first`?[...e.slice().reverse(),...r]:[...r,...e]);if(i(t)&&!(M(t,p)>m)&&!(O(t)>0)){g=t;break}}}if(!g)return;let _=c===`first`?g[g.length-1]:g[0];if(h&&!J(_,h))return;o.push({dep:s,movedPath:g})}return o}function gn(e,t){let{every:n,rectOf:r}=Y(e,t),a=n.filter(e=>!w(e)&&!j(e)&&e.type!==`bpmn:Lane`&&!D.has(e.type??``)&&e.width>0&&e.height>0),o=e=>{let t=/* @__PURE__ */ new Set,n=e?.parent;for(;n;)t.add(n.id),n=n.parent;return t},s=e=>t.routes.filter(t=>t!==e).flatMap(t=>{let{source:n,target:r}=t.connection,i=n?.id===e.connection.id;return i===(r?.id===e.connection.id)?[]:[{route:t,end:i?`first`:`last`}]}),c=[...new Map(t.routes.map(e=>[e,t.routes.filter(t=>t!==e&&b(e.waypoints,t.waypoints)).length])).entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e),l=(e,t,n,r)=>{let a=e.waypoints,o=O(a),s=r.reduce((e,t)=>e+ +(N(a,t)>0),0);for(let e=1;e+2<a.length;e++){let c=a[e],l=a[e+1],u=Math.abs(c.y-l.y)<.5,d=Math.abs(c.x-l.x)<.5;if(u||d)for(let c of Yt){let l=a.map(e=>({...e}));u?(l[e].y+=c,l[e+1].y+=c):(l[e].x+=c,l[e+1].x+=c);let d=P(l);if(i(d)&&!(M(d,n)>0)&&!b(d,t)&&!r.some(e=>b(d,e))&&!(O(d)>o)&&!(r.reduce((e,t)=>e+ +(N(d,t)>0),0)>s))return d}}};c.forEach(e=>{let n=e.connection;if(!n.source||!n.target)return;let c=t.routes.filter(t=>t!==e),u=c.filter(t=>b(e.waypoints,t.waypoints));if(u.length===0)return;let d=/* @__PURE__ */ new Set([n.source.id,n.target.id,...o(n.source),...o(n.target)]),f=a.filter(e=>!d.has(e.id)).map(r),p=c.map(e=>e.waypoints),m=(e,t)=>!q(e,t,f),h=T(e.waypoints,m),g=e.waypoints[0],_=e.waypoints[e.waypoints.length-1],v=null,y=1/0,x;for(let n of ln){for(let d of un){let S=u.flatMap(e=>dn(e.waypoints,d)),C=Ke(g,_,[...f,...S],p,n,void 0,2,150);if(!C||C.length<2||!i(C)||M(C,f)>0)continue;let w=p.reduce((e,t)=>e+ +(N(C,t)>0),0);if(v&&w>=y)continue;let E=c.filter(e=>b(C,e.waypoints));if(E.length>1)continue;let D;if(E.length===1){let n=E[0],i=t.routes.filter(e=>e!==n&&b(n.waypoints,e.waypoints)).length,c=i===1&&b(n.waypoints,e.waypoints);if(i>0&&!c||s(n).length>0)continue;let u=n.connection,d=/* @__PURE__ */ new Set([u.source?.id,u.target?.id,...o(u.source),...o(u.target)]),f=a.filter(e=>!d.has(e.id)).map(r),p=t.routes.filter(t=>t!==e&&t!==n).map(e=>e.waypoints),m=l(n,C,f,p);if(!m)continue;D={bystander:n,waypoints:m}}if(!(T(C,m)>h)&&(v=C,y=w,x=D,y===0))break}if(v&&y===0)break}if(!v)return;let S=hn(s(e),v,a,r,o);S&&(e.waypoints=v,S.forEach(({dep:e,movedPath:t})=>{e.waypoints=t}),x&&(x.bystander.waypoints=x.waypoints))}),_n(t,a,r,o,s)}function _n(e,t,n,r,a){let o=e.routes.filter(t=>e.routes.some(e=>e!==t&&b(t.waypoints,e.waypoints)));if(o.length===0)return;let s=/* @__PURE__ */ new Set,c=[];o.forEach(e=>{if(s.has(e))return;let t=[],n=[e];for(s.add(e);n.length>0;){let e=n.shift();t.push(e),o.forEach(t=>{s.has(t)||t===e||b(e.waypoints,t.waypoints)&&(s.add(t),n.push(t))})}c.push(t)});let l=o=>{let s=e.routes.filter(e=>!o.includes(e)),c=/* @__PURE__ */ new Map,l=o.map(e=>{let a=e.connection,o=/* @__PURE__ */ new Set([a.source?.id,a.target?.id,...r(a.source),...r(a.target)]),c=t.filter(e=>!o.has(e.id)).map(n),l=s.map(e=>e.waypoints),u=(e,t)=>!q(e,t,c),d=T(e.waypoints,u),f=e.waypoints[0],p=e.waypoints[e.waypoints.length-1],m=/* @__PURE__ */ new Set,h=[],g=e=>{let t=JSON.stringify(e);m.has(t)||(m.add(t),h.push(e))};g(e.waypoints);for(let t of ln){for(let n of un){let r=s.flatMap(t=>b(e.waypoints,t.waypoints)?dn(t.waypoints,n):[]),a=Ke(f,p,[...c,...r],l,t,void 0,2,150);if(!(!a||a.length<2)&&i(a)&&!(M(a,c)>0)&&!(T(a,u)>d)&&(g(a),h.length>=6))break}if(h.length>=6)break}return h});if(l.some(e=>e.length===0)||l.reduce((e,t)=>e*t.length,1)>4e3)return{solved:void 0,blockers:c};let u=s.map(e=>e.waypoints),d=e=>u.reduce((t,n)=>t+ +(N(e,n)>0),0),f=o.map(e=>a(e)),p=l.map(()=>0),m,h,g=1/0;outer:for(;;){let e=p.map((e,t)=>l[t][e]),i=!0;for(let t=0;t<e.length&&i;t++){for(let n=t+1;n<e.length&&i;n++)b(e[t],e[n])&&(i=!1);if(i){let n=s.find(n=>b(e[t],n.waypoints));n&&(i=!1,c.set(n,(c.get(n)??0)+1))}}let a;if(i){let i=e.reduce((e,t)=>e+d(t),0);if(i<g){a=[];for(let i=0;i<e.length&&a;i++){let o=hn(f[i],e[i],t,n,r);o?a.push(o):a=void 0}if(a&&(m=e,h=a,g=i,i===0))break outer}}let o=p.length-1;for(;;){if(o<0)break outer;if(p[o]++,p[o]<l[o].length)break;p[o]=0,o--}}return m&&h?{solved:m,solvedDeps:h,blockers:c}:{solved:void 0,blockers:c}};c.forEach(e=>{if(e.length<2||e.length>4)return;let t=e,n=l(t);if(!n.solved&&t.length<4){let e=[...n.blockers.entries()].sort((e,t)=>t[1]-e[1])[0];e&&(t=[...t,e[0]],n=l(t))}n.solved&&t.forEach((e,t)=>{e.waypoints=n.solved[t],n.solvedDeps[t].forEach(({dep:e,movedPath:t})=>{e.waypoints=t})})})}var vn=class extends Error{element;constructor(e,t){super(t),this.element=e}};const yn=e=>typeof e==`number`&&Number.isFinite(e)&&Math.abs(e)<=1e7;function bn(e,n){let r=e.waypoints!==void 0||e.source!==void 0||e.target!==void 0;for(let[t,n]of[[`x`,e.x],[`y`,e.y]])if(!yn(n))return`${t} is ${String(n)}`;for(let[t,i]of[[`width`,e.width],[`height`,e.height]])if(!yn(i)||i<=0&&!r&&!n&&e.type!==`root`&&e.type!==`bpmn:Process`&&e.type!==`label`)return`${t} is ${String(i)}`;for(let n of e.waypoints??[])if(!yn(n?.x)||!yn(n?.y))return t(`app.editor.layoutBadWaypoint`,{x:String(n?.x),y:String(n?.y)});return null}function xn(e){let n=/* @__PURE__ */ new Set,r=[e];for(let i=r.pop();i;i=r.pop()){if(n.has(i))continue;n.add(i);let a=bn(i,i===e);if(a)throw new vn(i.id,t(`app.editor.layoutBadShape`,{element:i.id||t(`app.editor.layoutAnElement`),problem:a}));r.push(...i.children??[],...i.attachers??[],...i.outgoing??[],...i.incoming??[]),i.label&&r.push(i.label)}}const Sn={nodesep:40,ranksep:80,marginX:40,marginY:40},Cn=globalThis.process?.env?.BPMN_LAYOUT_ENGINE!==`legacy`;function wn(e){return Math.max(e.width||36,e.label?.width??0)}function Tn(e){return e.reduce((e,t,n)=>e+wn(t)+(n>0?6:0),0)}function En(e){let t=0;for(let n=0;n<6;n++){let{south:n,north:r}=X({...e,width:t}),i=Math.max(Tn(n),Tn(r));if(i<=t)break;t=i}return t}function Dn(e){let t=[],n=e=>{if((e.attachers||[]).length>0&&Ce(e).length===0){let n=Math.max(e.width,En(e));n>e.width&&(e.width=n,t.push(e))}(e.children||[]).forEach(n)};return(e.children||[]).forEach(n),t}function On(e,t){let n=/* @__PURE__ */ new Map,{south:r,north:i}=X(e);return[r,i].forEach(e=>{if(e.length===0)return;let r=(t-Tn(e))/2;e.forEach(e=>{n.set(e.id,r+wn(e)/2),r+=wn(e)+6})}),n}function kn(e){return(e.businessObject?.eventDefinitions||[]).some(e=>e.$type===`bpmn:EscalationEventDefinition`)}function X(e){let t=e.attachers||[],n=[],r=t.filter(kn),i=0;return t.filter(e=>!kn(e)).forEach(t=>{let a=wn(t),o=i+(n.length>0?6:0)+a;n.length===0||o<=e.width?(n.push(t),i=o):r.push(t)}),{south:n,north:r}}function Z(e,t=`SOUTH`){let{south:n,north:r}=X(e),i=t===`SOUTH`?n:r;return i.length===0?0:Math.max(...i.map(e=>e.height||36))/2}function An(e){let t=(e.children||[]).filter(e=>e.type===`bpmn:Participant`);return t.length>0?t:[e]}function jn(e,t=[]){return t.push(e),(e.attachers||[]).forEach(e=>{t.push(e)}),(e.children||[]).forEach(e=>{!w(e)&&!j(e)&&jn(e,t)}),t}function Q(e,t){let n=[];return x.has(e.type??``)?n:((e.outgoing||[]).forEach(e=>{e.target&&t.has(e.target.id)&&(x.has(e.target.type??``)||n.push({target:e.target,conn:e,fromBoundary:!1}))}),(e.attachers||[]).forEach(e=>{(e.outgoing||[]).forEach(r=>{r.target&&t.has(r.target.id)&&n.push({target:r.target,conn:r,fromBoundary:!0,sourceAttacherId:e.id})})}),n.map((e,t)=>({edge:e,index:t})).sort((e,t)=>e.edge.target.y+e.edge.target.height/2-(t.edge.target.y+t.edge.target.height/2)||e.index-t.index).map(e=>e.edge))}function Mn(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;e.forEach(e=>{Q(e,t).forEach(e=>{n.set(e.target.id,(n.get(e.target.id)??0)+1),e.fromBoundary&&r.set(e.target.id,(r.get(e.target.id)??0)+1)})});let i=/* @__PURE__ */ new Set;return e.forEach(e=>{let a=n.get(e.id)??0,o=r.get(e.id)??0,s=Q(e,t).length===0;a>0&&a===o&&s&&i.add(e.id)}),i}function Nn(e,t){let n=/* @__PURE__ */ new Map;return e.forEach(e=>{(e.outgoing||[]).forEach(r=>{if(!r.target||!t.has(r.target.id))return;let i=x.has(e.type??``),a=x.has(r.target.type??``);a&&!i&&!n.has(r.target.id)&&n.set(r.target.id,e),i&&!a&&!n.has(e.id)&&n.set(e.id,r.target)})}),n}function Pn(e,t){let n=/* @__PURE__ */ new Map;return e.forEach(e=>{(e.attachers||[]).forEach(r=>{(r.outgoing||[]).forEach(r=>{r.target&&t.has(r.target.id)&&n.set(r.target.id,e)})})}),n}function Fn(e){let t=/* @__PURE__ */ new Map,n=[...e].sort((e,t)=>e.center-t.center||(e.id<t.id?-1:1)),r=[],i=()=>{if(r.length===0)return;let e=[...r.map(e=>e.center)].sort((e,t)=>e-t),n=e[Math.floor(e.length/2)];r.forEach(e=>t.set(e.id,n)),r=[]};return n.forEach(e=>{r.length>0&&e.center-r[0].center>20&&i(),r.push(e)}),i(),t}function In(e){let t=[...new Set(e.values())].sort((e,t)=>e-t),n=new Map(t.map((e,t)=>[e,t]));return new Map([...e.entries()].map(([e,t])=>[e,n.get(t)]))}function Ln(e){let t=e.filter(e=>(e.x??0)!==0||(e.y??0)!==0);if(t.length<2)return!1;let n=new Set(t.map(e=>Math.round(e.x))),r=new Set(t.map(e=>Math.round(e.y)));return n.size>1||r.size>1}function Rn(e,t,n){let r=e.filter(e=>!x.has(e.type??``));if(!Ln(r))return null;let i=Fn(r.map(e=>({id:e.id,center:e.x+(e.width||100)/2}))),a=Fn(r.map(e=>({id:e.id,center:e.y+(e.height||80)/2}))),o=/* @__PURE__ */ new Map;e.forEach(e=>{let t=i.get(e.id),n=a.get(e.id);o.set(e.id,{x:t===void 0?e.x:t-(e.width||100)/2,y:n===void 0?e.y:n-(e.height||80)/2})});let s=new Map(e.map(e=>[e.id,{x:e.x,y:e.y}])),c=new Map([...o].map(([e,t])=>[e,{...t}]));Gn(e,o,t,n??{x:t.marginX,y:t.marginY});let l=new Map([...s].map(([e,t])=>[e,{...t}]));Un(e,l,t);let u=new Map([...c].map(([e,t])=>[e,{...t}]));Un(e,u,t);let d=new Map([...s].map(([e,t])=>[e,{...t}]));Wn(e,d,t,Bn(e)),Un(e,d,t);let f=[s,c,l,u,d,o].reduce((t,n)=>$(e,n)<$(e,t)?n:t);f!==o&&f.forEach((e,t)=>o.set(t,e));let p=Bn(r);return{positions:o,ranks:In(p?a:i),rows:In(p?i:a),authored:!0}}function zn(e,t,n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;[...e].sort((e,t)=>e.center-t.center||(e.id<t.id?-1:1)).forEach(e=>{let t=[...r.keys()].find(t=>{let n=r.get(t);return Math.abs(n[0].center-e.center)>20?!1:!n.some(t=>t.otherStart<e.otherEnd&&t.otherEnd>e.otherStart)})??e.id;r.has(t)||r.set(t,[]),r.get(t).push(e),i.set(e.id,t)});let a=[...r.keys()].sort((e,t)=>Math.min(...r.get(e).map(e=>e.center))-Math.min(...r.get(t).map(e=>e.center))||(e<t?-1:1)),o=(e,t)=>e.otherStart<t.otherEnd&&e.otherEnd>t.otherStart,s=/* @__PURE__ */ new Map;a.forEach((e,i)=>{let c=r.get(e),l=n+Math.max(...c.map(e=>e.half));for(let e=0;e<i;e++){let n=a[e],i=s.get(n),u=r.get(n),d=i;u.forEach(e=>{c.forEach(n=>{o(e,n)&&(d=Math.max(d,i+e.half+n.half+t))})}),l=Math.max(l,d)}s.set(e,l)});let c=/* @__PURE__ */ new Map;return e.forEach(e=>c.set(e.id,s.get(i.get(e.id)))),c}function Bn(e){let t=new Map(e.map(e=>[e.id,e])),n=0,r=0;return e.forEach(e=>{(e.outgoing||[]).forEach(i=>{let a=i.target,o=a?t.get(a.id):void 0;o&&(n+=Math.abs(o.x+(o.width||100)/2-(e.x+(e.width||100)/2)),r+=Math.abs(o.y+(o.height||80)/2-(e.y+(e.height||80)/2)))})}),r>n}function Vn(e,t,n,r){let i=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);return i(n,r,e)>0!=i(n,r,t)>0&&i(e,t,n)>0!=i(e,t,r)>0}function Hn(e,t){let n=new Map(e.map(e=>[e.id,e])),r=e=>{let n=t.get(e.id)??{x:e.x,y:e.y};return{x:n.x+(e.width||100)/2,y:n.y+(e.height||80)/2}},i=[];e.forEach(e=>{x.has(e.type??``)||[e,...e.attachers||[]].forEach(t=>{(t.outgoing||[]).forEach(r=>{let a=r.target,o=a?n.get(a.id):void 0;o&&!x.has(o.type??``)&&i.push({a:n.get(t.id)??e,b:o})})})});let a=0;for(let e=0;e<i.length;e++)for(let t=e+1;t<i.length;t++){let n=i[e],o=i[t];n.a!==o.a&&n.a!==o.b&&n.b!==o.a&&n.b!==o.b&&Vn(r(n.a),r(n.b),r(o.a),r(o.b))&&a++}return a}function $(e,t,n=0){let r=new Map(e.map(e=>[e.id,e])),i=e=>{let n=t.get(e.id)??{x:e.x,y:e.y};return{x:n.x+(e.width||100)/2,y:n.y+(e.height||80)/2}},a=e=>{let n=t.get(e.id)??{x:e.x,y:e.y};return{x:n.x,y:n.y,width:e.width||100,height:e.height||80}},o=[];e.forEach(e=>{x.has(e.type??``)||(e.outgoing||[]).forEach(t=>{let n=t.target,i=n?r.get(n.id):void 0;i&&!x.has(i.type??``)&&o.push({a:e,b:i})})});let s=0;for(let e=0;e<o.length;e++)for(let t=e+1;t<o.length;t++){let n=o[e],r=o[t];n.a!==r.a&&n.a!==r.b&&n.b!==r.a&&n.b!==r.b&&Vn(i(n.a),i(n.b),i(r.a),i(r.b))&&s++}let c=0;o.forEach(({a:t,b:n})=>{let r=i(t),o=i(n);e.forEach(e=>{if(e===t||e===n||x.has(e.type??``))return;let i=a(e),s=Math.min(r.x,o.x),l=Math.max(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.y,o.y);s<i.x+i.width&&l>i.x&&u<i.y+i.height&&d>i.y&&c++})});let l=e.filter(e=>!x.has(e.type??``)&&!g(e)),u=0;for(let e=0;e<l.length;e++)for(let t=e+1;t<l.length;t++){let n=a(l[e]),r=a(l[t]);n.x<r.x+r.width&&n.x+n.width>r.x&&n.y<r.y+r.height&&n.y+n.height>r.y&&u++}let d=e.map(e=>a(e)),f=Math.max(...d.map(e=>e.x+e.width))-Math.min(...d.map(e=>e.x)),p=Math.max(...d.map(e=>e.y+e.height))-Math.min(...d.map(e=>e.y)),m=[];e.forEach(e=>{let n=t.get(e.id);n&&m.push({x:n.x-e.x,y:n.y-e.y})});let h=e=>{if(e.length===0)return 0;let t=[...e].sort((e,t)=>e-t);return t[Math.floor(t.length/2)]},_=h(m.map(e=>e.x)),v=h(m.map(e=>e.y)),y=m.length>0?m.reduce((e,t)=>e+Math.abs(t.x-_)+Math.abs(t.y-v),0)/m.length:0,b=0,S=[];o.forEach(({a:e,b:t})=>{let n=a(e),r=a(t),i=r.x+r.width/2-(n.x+n.width/2),o=r.y+r.height/2-(n.y+n.height/2);Math.abs(i)>=Math.abs(o)?(Math.abs(o)>2&&b++,S.push(i>0?r.x-(n.x+n.width):n.x-(r.x+r.width))):(Math.abs(i)>2&&b++,S.push(o>0?r.y-(n.y+n.height):n.y-(r.y+r.height)))});let C=S.filter(e=>e>0),w=C.reduce((e,t)=>e+t,0)/(C.length||1),T=C.reduce((e,t)=>e+Math.abs(t-w),0)/(C.length||1);return u*1e5+s*1e3+c*n+f*p/2e3+y*1+b*1e3+T*10}function Un(e,t,n){let r=e.filter(e=>!x.has(e.type??``)&&!g(e)&&t.has(e.id)),i=e=>{let n=t.get(e.id);return{x:n.x,y:n.y,width:e.width||100,height:e.height||80}};for(let e=0;e<12;e++){let e=!1;for(let a=0;a<r.length;a++)for(let o=a+1;o<r.length;o++){let s=i(r[a]),c=i(r[o]);if(!(s.x<c.x+c.width&&s.x+s.width>c.x&&s.y<c.y+c.height&&s.y+s.height>c.y))continue;let l=Math.min(s.y+s.height,c.y+c.height)-Math.max(s.y,c.y)+n.nodesep,u=Math.min(s.x+s.width,c.x+c.width)-Math.max(s.x,c.x)+n.nodesep,d=t.get(r[o].id);l<=u?t.set(r[o].id,{x:d.x,y:d.y+(c.y>=s.y?l:-l)}):t.set(r[o].id,{x:d.x+(c.x>=s.x?u:-u),y:d.y}),e=!0}if(!e)return}}function Wn(e,t,n,r){let i=new Map(e.map(e=>[e.id,e])),a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;e.forEach(e=>{x.has(e.type??``)||(e.outgoing||[]).forEach(t=>{let n=t.target,r=n?i.get(n.id):void 0;r&&!x.has(r.type??``)&&(a.has(r.id)||a.set(r.id,[]),a.get(r.id).push(e),o.has(e.id)||o.set(e.id,[]),o.get(e.id).push(r))})});let s=e=>r?e.width||100:e.height||80,c=e=>r?e.height||80:e.width||100,l=e=>r?e.x:e.y,u=e=>r?e.y:e.x,d=(e,t)=>r?{x:e,y:t}:{x:t,y:e};[...e].filter(e=>!x.has(e.type??``)&&t.has(e.id)).sort((e,n)=>u(t.get(e.id))-u(t.get(n.id))).forEach(e=>{let r=(a.get(e.id)??[]).filter(e=>t.has(e.id));if(r.length!==1)return;let i=r[0];if((o.get(i.id)??[]).length!==1)return;let f=t.get(i.id),p=t.get(e.id),m=l(f)+s(i)/2,h=u(f)+c(i)+n.ranksep;u(p)<u(f)||t.set(e.id,d(m-s(e)/2,h))})}function Gn(e,t,n,r){let i=e.filter(e=>!x.has(e.type??``)&&t.has(e.id));if(i.length===0)return;let a=Bn(i);for(let e=0;e<3;e++)Kn(i,t,n,a,r)}function Kn(e,t,n,r,i){let a=e=>{let n=t.get(e.id);return{x:n.x,y:n.y,w:e.width||100,h:e.height||80}},o=e.map(e=>{let t=a(e);return{id:e.id,center:t.x+t.w/2,half:t.w/2,otherStart:t.y,otherEnd:t.y+t.h}});if(!r){let r=zn(o,n.ranksep,i.x);e.forEach(e=>{let n=t.get(e.id);t.set(e.id,{x:r.get(e.id)-(e.width||100)/2,y:n.y})})}let s=e.map(e=>{let t=a(e);return{id:e.id,center:t.y+t.h/2,half:t.h/2,otherStart:t.x,otherEnd:t.x+t.w}});if(r){let r=zn(s,n.ranksep,i.y);e.forEach(e=>{let n=t.get(e.id);t.set(e.id,{x:n.x,y:r.get(e.id)-(e.height||80)/2})})}}function qn(e,t){let n=/* @__PURE__ */ new Map,r=[...e].sort((e,t)=>e.id<t.id?-1:+(e.id>t.id)),i=/* @__PURE__ */ new Set,a=[],o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set;function c(e){s.has(e.id)||o.has(e.id)||(o.add(e.id),a.push(e.id),Q(e,t).forEach(t=>{o.has(t.target.id)?a.length-a.indexOf(t.target.id)<=5&&i.add(`${e.id}->${t.target.id}`):c(t.target)}),a.pop(),o.delete(e.id),s.add(e.id))}r.forEach(c);let l=/* @__PURE__ */ new Set;function u(e){let a=n.get(e.id);if(a!==void 0)return a;if(l.has(e.id))return 0;l.add(e.id);let o=r.filter(n=>Q(n,t).some(t=>t.target.id===e.id)&&!i.has(`${n.id}->${e.id}`)),s=o.length===0?0:Math.max(...o.map(u))+1;return n.set(e.id,s),l.delete(e.id),s}return r.forEach(u),n}function Jn(e,t,n){let r=n?.get(t);if(!r)return e;let i=new Map(e.map(e=>[e.target.id,e])),a=r.map(e=>i.get(e)).filter(e=>!!e);return a.length===e.length?a:e}function Yn(e,t,n,r){let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;return[...e].sort((e,t)=>(n.get(e.id)??0)-(n.get(t.id)??0)||(e.id<t.id?-1:+(e.id>t.id))).forEach(e=>{let n=a.get(e.id),s=new Set(n??[]),c=!n||n.length===0?null:s.size===1?[...s][0]:null;i.set(e.id,c);let l=Q(e,t),u=Jn(l.filter(e=>!e.fromBoundary),e.id,r),d=l.filter(e=>e.fromBoundary),f=(e,t)=>{a.has(e.id)||a.set(e.id,[]),a.get(e.id).push(t)};if(u.length>1&&c===null){let e=Qn(u.length);u.forEach((t,n)=>{f(t.target,t.target.id),o.has(t.target.id)||o.set(t.target.id,e[n])})}else u.forEach(e=>f(e.target,c));d.forEach(e=>f(e.target,c))}),{groups:i,groupOrder:o}}function Xn(e,t,n,r,i){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;e.forEach(e=>{let n=t.get(e.id),r=(e.height||80)/2;a.set(n,Math.max(a.get(n)??0,r+Z(e,`NORTH`))),o.set(n,Math.max(o.get(n)??0,r+Z(e,`SOUTH`)))});let s=[...a.keys()].sort((e,t)=>e-t),c=s.includes(r)?r:s[0]??r,l=s.indexOf(c),u=/* @__PURE__ */ new Map;u.set(c,0);let d=/* @__PURE__ */ new Map;e.forEach(e=>{let n=t.get(e.id);d.has(n)||d.set(n,[]),d.get(n).push(e)});let f=(e,t)=>{if(!i)return o.get(e)+n+a.get(t);let r=n;return(d.get(e)??[]).forEach(e=>{(d.get(t)??[]).forEach(t=>{if(i.get(e.id)!==i.get(t.id))return;let a=(e.height||80)/2+Z(e,`SOUTH`)+n+(t.height||80)/2+Z(t,`NORTH`);r=Math.max(r,a)})}),r};for(let e=l+1;e<s.length;e++){let t=s[e-1],n=s[e];u.set(n,u.get(t)+f(t,n))}for(let e=l-1;e>=0;e--){let t=s[e+1],n=s[e];u.set(n,u.get(t)-f(n,t))}let p=1/0,m=-1/0;return s.forEach(e=>{p=Math.min(p,u.get(e)-a.get(e)),m=Math.max(m,u.get(e)+o.get(e))}),{centers:u,minY:p,maxY:m,topExtent:a,bottomExtent:o}}function Zn(e,t,n,r,i,a){let o=/* @__PURE__ */ new Map,s=e.filter(e=>!r.get(e.id)),c=s.map(e=>n.get(e.id)),l=Xn(s,n,a,c.length>0?c.reduce((e,t)=>Math.abs(t)<Math.abs(e)?t:e):0,t);s.forEach(e=>o.set(e.id,l.centers.get(n.get(e.id))));let u=/* @__PURE__ */ new Map;e.forEach(e=>{let t=r.get(e.id);t&&(u.has(t)||u.set(t,[]),u.get(t).push(e))});let d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Map;u.forEach((e,r)=>{let i=e.map(e=>n.get(e.id)).reduce((e,t)=>Math.abs(t)<Math.abs(e)?t:e);f.set(r,i),d.set(r,Xn(e,n,a,i,t))});let p=[...u.keys()].filter(e=>(i.get(e)??0)<0),m=[...u.keys()].filter(e=>(i.get(e)??0)>=0),h=(e,r)=>{let c=e=>Math.min(...u.get(e).map(e=>t.get(e.id)??0)),p=[...e].sort((e,t)=>{let n=c(e)-c(t);if(n!==0)return n;let a=i.get(e)??0,o=i.get(t)??0,s=r===-1?o-a:a-o;return s===0?e<t?-1:+(e>t):s}),m=e=>{let i=u.get(e),a=new Set(i.map(e=>t.get(e.id)??0)),o=s.filter(e=>[...a].some(n=>Math.abs(n-(t.get(e.id)??0))<=1));return o.length===0?r===-1?l.minY:l.maxY:r===-1?Math.min(...o.map(e=>l.centers.get(n.get(e.id))-(e.height||80)/2-Z(e,`NORTH`))):Math.max(...o.map(e=>l.centers.get(n.get(e.id))+(e.height||80)/2+Z(e,`SOUTH`)))},h=[];p.forEach(e=>{let c=u.get(e),p=Math.min(...c.map(e=>t.get(e.id)??0)),g=Math.max(...c.map(e=>t.get(e.id)??0)),_=d.get(e),v=m(e),y=h.find(e=>e.occupiedUntilRank<p);y||(y={edge:v,occupiedUntilRank:-1/0},h.push(y));let b=h.filter(e=>e!==y&&e.occupiedUntilRank>=p).reduce((e,t)=>r===-1?Math.min(e,t.edge):Math.max(e,t.edge),v);y.edge=b;let x=(i.get(e)??0)===0,S=f.get(e)??0,C=_.centers.get(S),w=[...l.centers.keys()].sort((e,t)=>e-t).reduce((e,t)=>e===void 0||Math.abs(t-S)<Math.abs(e-S)?t:e,void 0),T=(()=>{if(C===void 0||w===void 0)return;let e=l.centers.get(w),r=S-w;if(r===0)return e;let i=r>0,o=new Set(c.filter(e=>n.get(e.id)===S).map(e=>t.get(e.id)??0)),u=e=>[...o].some(t=>Math.abs(t-e)<=1),d=s.filter(e=>n.get(e.id)===w&&u(t.get(e.id)??0)),f=d.length?Math.max(...d.map(e=>(e.height||80)/2+Z(e,i?`SOUTH`:`NORTH`))):0,p=c.filter(e=>n.get(e.id)===S),m=p.length?Math.max(...p.map(e=>(e.height||80)/2+Z(e,i?`NORTH`:`SOUTH`))):0,h=f+a+m;return i?e+h:e-h})(),E=T!==void 0&&C!==void 0?T-C:0,D=x&&y.edge===v?E:r===-1?y.edge-a-_.maxY:y.edge+a-_.minY;c.forEach(e=>o.set(e.id,_.centers.get(n.get(e.id))+D)),y.occupiedUntilRank=g,y.edge=r===-1?_.minY+D:_.maxY+D})};return h(p,-1),h(m,1),o.forEach((e,t)=>{Number.isFinite(e)||o.set(t,l.centers.get(n.get(t)??0)??0)}),o}function Qn(e,t=!1){let n=[];if(e===2&&!t)return[0,1];if(e%2==1){let t=(e-1)/2;for(let r=0;r<e;r++)n.push(r-t)}else{let t=e/2;for(let r=0;r<e;r++)n.push(r<t?r-t:r-t+1)}return n}function $n(e,t,n,r,i){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Map,u=new Map(e.map(e=>[e.id,e])),d=e=>{let n=l.get(e);if(n)return n;let r=/* @__PURE__ */ new Set,i=[e];for(;i.length>0;){let e=i.pop(),n=u.get(e);n&&Q(n,t).forEach(e=>{r.has(e.target.id)||(r.add(e.target.id),i.push(e.target.id))})}return l.set(e,r),r},f=(e,t)=>d(t).has(e),p=/* @__PURE__ */ new Map;return e.forEach(e=>{let t=n.get(e.id)??0;p.has(t)||p.set(t,[]),p.get(t).push(e)}),[...p.keys()].sort((e,t)=>e-t).forEach(e=>{let n=p.get(e),l=new Map(n.map(e=>{let t=o.get(e.id);if(!t||t.length===0)return[e.id,0];let n=t.filter(e=>!e.cyclic),r=n.length>0?n:t,i=r.reduce((e,t)=>e+t.row,0)/r.length;return[e.id,i]})),u=e=>{let t=o.get(e)?.length??0,n=s.get(e)??0;return t>0&&n===t?3:t>1?2:+!c.has(e)};n.sort((e,t)=>u(e.id)-u(t.id)||l.get(e.id)-l.get(t.id)||(e.y??0)-(t.y??0)||(e.id<t.id?-1:+(e.id>t.id)));let d=/* @__PURE__ */ new Map;n.forEach(e=>{let n=r.get(e.id)??``;d.has(n)||d.set(n,/* @__PURE__ */ new Set);let u=d.get(n),p=Math.round(l.get(e.id)),m=p,h=0;for(;u.has(m);)h=h>0?-h:-h+1,m=p+h;u.add(m),a.set(e.id,m);let g=Q(e,t),_=Jn(g.filter(e=>!e.fromBoundary),e.id,i),v=g.filter(e=>e.fromBoundary),y=(t,n,r)=>{o.has(t.id)||o.set(t.id,[]);let i=f(e.id,t.id);o.get(t.id).push({row:m+n,cyclic:i}),n===0&&!r&&c.add(t.id),r&&s.set(t.id,(s.get(t.id)??0)+1)},b=_.map(t=>f(e.id,t.target.id)),x=b.some(Boolean)&&b.filter(e=>!e).length>1,S=0,C=x?b.map(e=>{if(!e)return 0;let t=S++;return t%2==0?Math.floor(t/2)+1:-(Math.floor(t/2)+1)}):Qn(_.length,(e.type??``).includes(`Gateway`));_.forEach((e,t)=>y(e.target,C[t],!1));let w=new Set(X(e).south.map(e=>e.id)),T=v.filter(e=>w.has(e.sourceAttacherId??``)),E=v.filter(e=>!w.has(e.sourceAttacherId??``));T.forEach((e,t)=>y(e.target,T.length-t,!0)),E.forEach((e,t)=>y(e.target,-(E.length-t),!0))})}),a}function er(e,t,n,r){let i=new Map(e.map(e=>[e.id,e])),a=/* @__PURE__ */ new Map;e.forEach(e=>{x.has(e.type??``)||[e,...e.attachers||[]].forEach(r=>{(r.outgoing||[]).forEach(r=>{let i=r.target;i&&t.has(i.id)&&(x.has(i.type??``)||(n.get(i.id)??0)<=(n.get(e.id)??0)||(a.has(i.id)||a.set(i.id,[]),a.get(i.id).push(e.id)))})})});let o=/* @__PURE__ */ new Map;return[...e].filter(e=>!x.has(e.type??``)).sort((e,t)=>(n.get(e.id)??0)-(n.get(t.id)??0)).forEach(e=>{let t=(a.get(e.id)??[]).reduce((e,t)=>{let n=i.get(t),a=o.get(t);return!n||a===void 0?e:Math.max(e,a+(n.width||100)+r.ranksep)},r.marginX);o.set(e.id,t)}),o}function tr(e,t,n){let r=e.reduce((e,n)=>Math.max(e,t.get(n.id)??0),0),i=/* @__PURE__ */ new Map;e.forEach(e=>{if(x.has(e.type??``))return;let n=t.get(e.id)??0;i.set(n,Math.max(i.get(n)??0,e.width||100))});let a=/* @__PURE__ */ new Map,o=n.marginX;for(let e=0;e<=r;e++)a.set(e,o),o+=(i.get(e)??100)+n.ranksep;return{rankX:a,rankWidth:i}}function nr(e,t,n,r,i,a){let o=e.filter(e=>!a.has(e.id)),s=/* @__PURE__ */ new Map;o.forEach(e=>s.set(e.id,[])),e.forEach(e=>{Q(e,t).forEach(t=>{s.has(e.id)&&s.get(e.id).push(t.target.id),s.has(t.target.id)&&s.get(t.target.id).push(e.id)})});let c=/* @__PURE__ */ new Map;o.forEach(e=>{let t=`${n.get(e.id)??0}:${r.get(e.id)??``}`;c.has(t)||c.set(t,[]),c.get(t).push(e.id)});for(let e=0;e<4;e++){let e=!1;if(c.forEach(t=>{if(t.length<2)return;let n=t.map(e=>i.get(e)).sort((e,t)=>e-t),r=e=>{let t=(s.get(e)??[]).map(e=>i.get(e)).filter(e=>e!==void 0);return t.length===0?i.get(e):t.reduce((e,t)=>e+t,0)/t.length};[...t].sort((e,t)=>r(e)-r(t)||i.get(e)-i.get(t)).forEach((t,r)=>{i.get(t)!==n[r]&&(e=!0),i.set(t,n[r])})}),!e)break}}function rr(e,t,n,r){let i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;e.forEach(e=>{let t=n.get(e.id);t&&(a.has(t)||a.set(t,[]),a.get(t).push(e))});let o=e=>{let t=a.get(e);return!t||t.length===0?r.get(e)??0:t.reduce((e,t)=>e+(r.get(t.id)??0),0)/t.length},s=new Map(e.map(e=>[e.id,e])),c=/* @__PURE__ */ new Map,l=e=>{let n=c.get(e);if(n!==void 0)return n;let r=[],i=/* @__PURE__ */ new Set,a=e=>{i.add(e);let n=s.get(e),a=n?Q(n,t).filter(e=>!e.fromBoundary).map(e=>e.target.id):[];r.push({id:e,next:a,at:0,deepest:0})};a(e);let o=0;for(;r.length>0;){let e=r[r.length-1];if(e.at<e.next.length){let t=e.next[e.at++],n=c.get(t);n===void 0?i.has(t)||a(t):e.deepest=Math.max(e.deepest,n);continue}r.pop(),i.delete(e.id),o=s.get(e.id)?1+e.deepest:0,c.set(e.id,o);let t=r[r.length-1];t&&(t.deepest=Math.max(t.deepest,o))}return o};return e.forEach(e=>{let n=Q(e,t).filter(e=>!e.fromBoundary);if(n.length<=1)return;let r=n.map(e=>e.target.id);if(new Set(r).size!==r.length)return;let a=r.length===2?[...r].sort((e,t)=>l(t)-l(e)||o(e)-o(t)||(e<t?-1:1)):[...r].sort((e,t)=>o(e)-o(t)||(e<t?-1:+(e>t)));i.set(e.id,a)}),i}function ir(e,t,n){let r=/* @__PURE__ */ new Set;e.forEach(e=>{[e,...e.attachers||[]].forEach(n=>{(n.outgoing||[]).forEach(n=>{let i=n.target;i&&t.has(i.id)&&(r.add(e.id),r.add(i.id))})}),(e.incoming||[]).forEach(n=>{let i=n.source;i&&t.has(i.id)&&(r.add(e.id),r.add(i.id))})});let i=e.filter(e=>!r.has(e.id)&&!x.has(e.type??``)&&(e.x!==0||e.y!==0)),a=new Set(i.map(e=>e.id)),o=i.length>0?e.filter(e=>!a.has(e.id)):e,s=i.length>0?new Set(o.map(e=>e.id)):t,c=lr(o,s,n),l=[c.positions],u=e=>{let t=new Map([...e].map(([e,t])=>[e,{...t}]));return cr(o,s,t),t},d=new Map([...c.positions].map(([e,t])=>[e,{...t}]));sr(o,d,c.rows,n),l.push(u(c.positions),d,u(d));let f=l.map(e=>Hn(o,e)),p=Math.min(...f);if(l.filter((e,t)=>f[t]===p).reduce((e,t)=>$(o,t)<$(o,e)?t:e).forEach((e,t)=>c.positions.set(t,e)),i.length>0){let e=o.filter(e=>c.positions.has(e.id)),t=e.reduce((e,t)=>{let n=c.positions.get(t.id);return Math.max(e,n.y+(t.height||80))},n.marginY),r=e.reduce((e,t)=>Math.min(e,c.positions.get(t.id).x),n.marginX),a=t+n.ranksep;[...i].sort((e,t)=>e.x-t.x||e.y-t.y).forEach(e=>{c.positions.set(e.id,{x:r,y:a}),r+=(e.width||100)+n.nodesep})}return c}function ar(e,t,n){if(Cn){let t=Se(e,n,x);if(t)return t}let r=ir(e,t,n),i=Rn(e,n);if(i){let n=or(e,t);if($(e,i.positions)+n.crossings*1e3+n.through*1e3<=$(e,r.positions))return i}return r}function or(e,t){let n=[],r=/* @__PURE__ */ new Set;e.forEach(e=>{[e,...e.attachers||[]].forEach(i=>{(i.outgoing||[]).forEach(i=>{let a=i,o=a.target;if(!o||!t.has(o.id)||r.has(a.id)||x.has(e.type??``)||x.has(o.type??``))return;r.add(a.id);let s=a.waypoints??[];s.slice(1).forEach((e,t)=>n.push({id:a.id,a:s[t],b:e}))})})});let i=0;for(let e=0;e<n.length;e++)for(let t=e+1;t<n.length;t++)n[e].id!==n[t].id&&Vn(n[e].a,n[e].b,n[t].a,n[t].b)&&i++;let a=0;return n.forEach(({a:t,b:n})=>{e.forEach(e=>{if(x.has(e.type??``)||g(e))return;let r=Math.min(t.x,n.x),i=Math.max(t.x,n.x),o=Math.min(t.y,n.y),s=Math.max(t.y,n.y);r<e.x+e.width-2&&i>e.x+2&&o<e.y+e.height-2&&s>e.y+2&&a++})}),{crossings:i,through:a}}function sr(e,t,n,r){let i=e.filter(e=>!x.has(e.type??``)&&t.has(e.id));if(i.length===0)return;let a=/* @__PURE__ */ new Map;i.forEach(e=>{let r=n.get(e.id);if(r===void 0)return;let i=t.get(e.id),o=i.y-Z(e,`NORTH`),s=i.y+(e.height||80)+Z(e,`SOUTH`),c=a.get(r);c?(c.top=Math.min(c.top,o),c.bottom=Math.max(c.bottom,s),c.members.push(e)):a.set(r,{top:o,bottom:s,members:[e]})});let o=r.marginY;[...a.keys()].sort((e,t)=>e-t).forEach(e=>{let n=a.get(e),i=o-n.top;n.members.forEach(e=>{let n=t.get(e.id);t.set(e.id,{x:n.x,y:n.y+i})}),o+=n.bottom-n.top+r.nodesep})}function cr(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=e.filter(e=>(e.type??``).includes(`Gateway`)&&n.has(e.id));if(i.length===0)return;let a=e=>{let t=n.get(e.id);return{x:t.x,y:t.y,width:e.width||100,height:e.height||80}};i.forEach(i=>{let o=[];if((i.outgoing||[]).forEach(e=>{let n=e.target,i=n?r.get(n.id):void 0;i&&t.has(i.id)&&o.push(i)}),e.forEach(e=>{(e.outgoing||[]).forEach(t=>{t.target?.id===i.id&&o.push(e)})}),o.length<2)return;let s=o.map(e=>a(e).y+(e.height||80)/2),c=(Math.min(...s)+Math.max(...s))/2-(i.height||50)/2,l=n.get(i.id);if(Math.abs(c-l.y)<1)return;let u={x:l.x,y:c},d={x:u.x,y:u.y,width:i.width||50,height:i.height||50};e.some(e=>e.id!==i.id&&!x.has(e.type??``)&&n.has(e.id)&&S(d,a(e)))||n.set(i.id,u)})}function lr(e,t,n){let r=qn(e,t),i=Yn(e,t,r),a=$n(e,t,r,i.groups),o=rr(e,t,i.groups,a),{groups:s,groupOrder:c}=Yn(e,t,r,o),l=$n(e,t,r,s,o),u=Mn(e,t),d=Pn(e,u),f=Nn(e,t);nr(e,t,r,s,l,/* @__PURE__ */ new Set([...u,...f.keys()]));let p=e.filter(e=>!u.has(e.id)&&!f.has(e.id)),m=Zn(p,r,l,s,c,n.nodesep),{rankX:h,rankWidth:g}=tr(e,r,n),_=er(e,t,r,n),v=(e,t)=>(h.get(e)??0)+((g.get(e)??t)-t)/2,y=(e,t,n)=>_.get(e)??v(t,n),b=/* @__PURE__ */ new Map;p.forEach(e=>{let t=m.get(e.id);b.set(e.id,t-e.height/2)});let x=/* @__PURE__ */ new Map;e.forEach(e=>{if(!u.has(e.id))return;let t=d.get(e.id);t&&(x.has(t.id)||x.set(t.id,[]),x.get(t.id).push(e))}),x.forEach((t,r)=>{let i=e.find(e=>e.id===r),a=b.get(r)+i.height/2,o=l.get(r)??0,s=t.filter(e=>l.get(e.id)>=o),c=t.filter(e=>l.get(e.id)<o);[{list:s,edge:a+i.height/2,dir:1},{list:c,edge:a-i.height/2,dir:-1}].forEach(({list:e,edge:t,dir:r})=>{if(e.length===0)return;let i=e.map(e=>l.get(e.id)).reduce((e,t)=>Math.abs(t-o)<Math.abs(e-o)?t:e),a=Xn(e,l,n.nodesep,i),s=e.filter(e=>l.get(e.id)===i),c=Math.max(...s.map(e=>(e.height||80)/2+Z(e,r===1?`NORTH`:`SOUTH`))),u=r===1?t+n.nodesep+c:t-n.nodesep-c;e.forEach(e=>b.set(e.id,u+a.centers.get(l.get(e.id))-e.height/2))})});let S=[...b.keys()].map(t=>{let i=e.find(e=>e.id===t),a=r.get(t)??0,o=i.width<=n.ranksep-10;return{x:u.has(t)&&a>0&&o?h.get(a)-n.ranksep/2-i.width/2:y(t,a,i.width),y:b.get(t),w:i.width,h:i.height}}),C=(e,t,n,r)=>S.some(i=>e<i.x+i.w&&e+n>i.x&&t<i.y+i.h&&t+r>i.y),w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Map;f.forEach((t,n)=>{T.has(t.id)||T.set(t.id,[]),T.get(t.id).push(e.find(e=>e.id===n))}),T.forEach((t,i)=>{let a=e.find(e=>e.id===i),o={x:h.get(r.get(i)??0)??0,y:b.get(i),w:a.width,h:a.height},s=n.nodesep,c=(e,t,n,r)=>C(e-s/2,t-s/2,n+s,r+s),l=(e,t,n,r)=>{for(let i=0;i<=6;i++)for(let a of i===0?[1]:[1,-1]){let o=r===`x`?e.x+a*i*20:e.x,s=r===`y`?e.y+a*i*20:e.y;if(!c(o,s,t,n))return{x:o,y:s}}return null},u=(e,t)=>S.filter(n=>n.x<o.x+o.w+200&&n.x+n.w>o.x-200&&n.y<t&&n.y+n.h>e).length,d=u(o.y-400,o.y)<=u(o.y+o.h,o.y+o.h+400);t.forEach(e=>{let t={base:{x:o.x+o.w/2-e.width/2,y:o.y-s-e.height},axis:`x`},n={base:{x:o.x+o.w/2-e.width/2,y:o.y+o.h+s},axis:`x`},r=[...d?[t,n]:[n,t],{base:{x:o.x+o.w+s,y:o.y+o.h/2-e.height/2},axis:`y`},{base:{x:o.x-s-e.width,y:o.y+o.h/2-e.height/2},axis:`y`}],i=null;for(let{base:t,axis:n}of r)if(i=l(t,e.width,e.height,n),i)break;let{x:a,y:c}=i??r[0].base;b.set(e.id,c),w.set(e.id,a),S.push({x:a,y:c,w:e.width,h:e.height})})});let E=Math.min(0,...e.map(e=>b.get(e.id))),D=n.marginY-E,O=/* @__PURE__ */ new Map;return e.forEach(e=>{if(f.has(e.id))return;let t=r.get(e.id)??0,i=e.width<=n.ranksep-10,a=u.has(e.id)&&t>0&&i?h.get(t)-n.ranksep/2-e.width/2:y(e.id,t,e.width);O.set(e.id,{x:a,y:b.get(e.id)+D})}),f.forEach((e,t)=>{O.set(t,{x:w.get(t),y:b.get(t)+D})}),{positions:O,rows:l,ranks:r}}const ur=1e6;function dr(e,t,n,r){if(Cn){let t=Se(e,r,x);if(t)return{...t,laneBands:null}}let i=/* @__PURE__ */ new Map;n.forEach((e,t)=>i.set(e.businessObject?.id??e.id,t));let a=/* @__PURE__ */ new Map;e.forEach(e=>{(e.outgoing||[]).forEach(t=>{if(!t.target)return;let n=x.has(e.type??``),r=x.has(t.target.type??``);r&&!n&&!a.has(t.target.id)&&a.set(t.target.id,e.id),n&&!r&&!a.has(e.id)&&a.set(e.id,t.target.id)})});let o=new Map(e.map(e=>[e.id,e])),s=e=>{let t=e.businessObject?.lanes?.[0]?.id;if(t)return i.get(t)??0;let n=a.get(e.id),r=n?o.get(n):void 0;return r?s(r):0},c=/* @__PURE__ */ new Map;if(e.forEach(e=>{let t=s(e);c.has(t)||c.set(t,[]),c.get(t).push(e)}),Ln(e.filter(e=>!x.has(e.type??``)))){let t=/* @__PURE__ */ new Map;n.forEach((e,n)=>{let i=c.get(n)??[];if(i.length===0)return;let a=Rn(i,r,{x:e.x+r.marginX,y:e.y+r.marginY});a?i.forEach(n=>{let r=a.positions.get(n.id)??{x:n.x,y:n.y};t.set(n.id,{x:Math.min(Math.max(r.x,e.x),Math.max(e.x,e.x+e.width-n.width)),y:Math.min(Math.max(r.y,e.y),Math.max(e.y,e.y+e.height-n.height))})}):i.forEach(e=>t.set(e.id,{x:e.x,y:e.y}))}),e.forEach(e=>{t.has(e.id)||t.set(e.id,{x:e.x,y:e.y})});let i=new Map(e.map(e=>[e.id,{x:e.x,y:e.y}]));$(e,i)<$(e,t)&&i.forEach((e,n)=>t.set(n,e));let a=new Map([...t].map(([e,t])=>[e,t.x])),o=new Map([...t].map(([e,t])=>[e,t.y])),s=Bn(e);return{positions:t,ranks:In(s?o:a),rows:In(s?a:o),laneBands:null,authored:!0}}let l=qn(e,t),{rankX:u,rankWidth:d}=tr(e,l,r),f=(e,t)=>(u.get(e)??0)+((d.get(e)??t)-t)/2,p=/* @__PURE__ */ new Map,m=/* @__PURE__ */ new Map,h=[],g=0;n.forEach((e,t)=>{let n=c.get(t)??[];if(n.length===0){let e=r.marginY*2;h.push({y:g,height:e}),g+=e;return}let i=ar(n,new Set(n.map(e=>e.id)),r),o=0;n.forEach(e=>{let t=i.positions.get(e.id);o=Math.max(o,t.y+e.height)});let s=o+r.marginY,u=e=>x.has(e.type??``);n.forEach(e=>{if(u(e))return;let n=i.positions.get(e.id),r=l.get(e.id)??0;p.set(e.id,{x:f(r,e.width),y:g+n.y}),m.set(e.id,t*ur+(i.rows.get(e.id)??0))}),n.forEach(e=>{if(!u(e))return;let n=i.positions.get(e.id),r=a.get(e.id),o=r?i.positions.get(r):void 0,s=r?p.get(r):void 0,c=o&&s?s.x+(n.x-o.x):n.x;p.set(e.id,{x:c,y:g+n.y}),m.set(e.id,t*ur+(i.rows.get(e.id)??0))}),h.push({y:g,height:s}),g+=s});let _=e.filter(e=>!x.has(e.type??``)).map(e=>{let t=p.get(e.id);return{x:t.x,y:t.y,w:e.width,h:e.height}}),v=(e,t,n,r)=>_.some(i=>e<i.x+i.w&&e+n>i.x&&t<i.y+i.h&&t+r>i.y);return e.filter(e=>x.has(e.type??``)).forEach(e=>{let t=p.get(e.id),n=t;if(v(t.x,t.y,e.width,e.height))outer:for(let r=1;r<=15;r++)for(let i of[1,-1]){let a=t.x+i*r*20;if(!v(a,t.y,e.width,e.height)){n={x:a,y:t.y};break outer}}p.set(e.id,n),_.push({x:n.x,y:n.y,w:e.width,h:e.height})}),{positions:p,rows:m,ranks:l,laneBands:h}}function fr(e,t,n){let r=n.get(e),i=n.get(t);return r===void 0||i===void 0?!1:i<=r}function pr(e,t,n,r=!1,i){let a=[],o=(e,t)=>!i||i.has(e)||i.has(t),s=0;return e.forEach(e=>{x.has(e.type??``)||((e.outgoing||[]).forEach(i=>{let c=i.target;c&&t.has(c.id)&&!x.has(c.type??``)&&(r||!fr(e.id,c.id,n))&&o(e.id,c.id)&&a.push({id:`le${s++}`,sourceId:e.id,targetId:c.id,conn:i})}),(e.attachers||[]).forEach(e=>{(e.outgoing||[]).forEach(i=>{let c=i.target;c&&t.has(c.id)&&(r||!fr(e.id,c.id,n))&&o(e.id,c.id)&&a.push({id:`le${s++}`,sourceId:e.id,targetId:c.id,conn:i})})}))}),a}function mr(e,t,n){let r=[],i=/* @__PURE__ */ new Set,a=e=>{if(i.has(e.id))return;i.add(e.id);let a=t.get(e.id);if(!a||a.width<=0||a.height<=0)return;let o=n?.get(e.id);r.push({id:e.id,x:a.x,y:a.y,width:a.width,height:a.height,...o?{ports:o}:{}})};return e.forEach(e=>{a(e),(e.attachers||[]).forEach(e=>a(e))}),r}function hr(e,t,n=.5){switch(t){case`EAST`:return{x:e.width,y:e.height*n};case`WEST`:return{x:0,y:e.height*n};case`NORTH`:return{x:e.width*n,y:0};case`SOUTH`:return{x:e.width*n,y:e.height}}}function gr(e,t){let n=t.x-(e.x+e.width),r=e.x-(t.x+t.width),i=t.y-(e.y+e.height),a=e.y-(t.y+t.height),o=Math.max(n,r);return o>=0||o>=Math.max(i,a)?n>=r?{from:`EAST`,to:`WEST`}:{from:`WEST`,to:`EAST`}:i>=a?{from:`SOUTH`,to:`NORTH`}:{from:`NORTH`,to:`SOUTH`}}function _r(e,t,n,r,i){let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map;e.forEach(e=>{a.set(e.sourceId,(a.get(e.sourceId)??0)+1),o.set(e.targetId,(o.get(e.targetId)??0)+1)});let s=new Set(n.flatMap(e=>(e.attachers||[]).map(e=>e.id))),c=/* @__PURE__ */ new Map;n.forEach(e=>{let{south:t,north:n}=X(e);t.forEach(e=>c.set(e.id,`SOUTH`)),n.forEach(e=>c.set(e.id,`NORTH`))});let l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map;e.forEach(e=>{let n=t.get(e.sourceId),r=t.get(e.targetId),d=(a.get(e.sourceId)??0)>1,f=(o.get(e.targetId)??0)>1;if(s.has(e.sourceId)?l.set(e.id,c.get(e.sourceId)??`SOUTH`):d?n!==void 0&&r!==void 0&&l.set(e.id,r<n?`NORTH`:r>n?`SOUTH`:`EAST`):l.set(e.id,`EAST`),f)n!==void 0&&r!==void 0&&u.set(e.id,n<r?`NORTH`:n>r?`SOUTH`:`WEST`);else{let t=i.get(e.sourceId),n=i.get(e.targetId),r=t&&n?t.x+t.width/2-(n.x+n.width/2):0,a=t&&n?t.y+t.height/2-(n.y+n.height/2):0;t&&n&&Math.abs(a)>Math.abs(r)*3?u.set(e.id,a>0?`SOUTH`:`NORTH`):u.set(e.id,`WEST`)}});let d=e=>Math.abs((t.get(e.targetId)??0)-(t.get(e.sourceId)??0)),f=/* @__PURE__ */ new Map;return e.forEach(e=>{if(!r.has(e.sourceId))return;let t=l.get(e.id);if(t!==`NORTH`&&t!==`SOUTH`)return;let n=`${e.sourceId}:${t}`;f.has(n)||f.set(n,[]),f.get(n).push(e)}),f.forEach(e=>{e.length<=1||[...e].sort((e,t)=>d(t)-d(e)).slice(1).forEach(e=>l.set(e.id,`EAST`))}),{sourceSideByEdge:l,targetSideByEdge:u}}function vr(e,t,n){let r=new Set(t.flatMap(e=>(e.attachers||[]).map(e=>e.id))),i=/* @__PURE__ */ new Map;t.forEach(e=>{let{south:t,north:n}=X(e);t.forEach(e=>i.set(e.id,`SOUTH`)),n.forEach(e=>i.set(e.id,`NORTH`))});let a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map,c=/* @__PURE__ */ new Map;return e.forEach(e=>{s.set(e.sourceId,(s.get(e.sourceId)??0)+1),c.set(e.targetId,(c.get(e.targetId)??0)+1)}),e.forEach(e=>{let t=n.get(e.sourceId),l=n.get(e.targetId);if(!t||!l)return;let{from:u,to:d}=gr(t,l),f=u;if((s.get(e.sourceId)??0)>1){let e=l.y+l.height/2-(t.y+t.height/2);Math.abs(e)>t.height/2&&(f=e>0?`SOUTH`:`NORTH`)}let p=d;if((c.get(e.targetId)??0)>1){let e=t.y+t.height/2-(l.y+l.height/2);Math.abs(e)>l.height/2&&(p=e>0?`SOUTH`:`NORTH`)}a.set(e.id,r.has(e.sourceId)?i.get(e.sourceId)??f:f),o.set(e.id,p)}),{sourceSideByEdge:a,targetSideByEdge:o}}function yr(e,t){let n=0;for(let r=0;r+1<e.length;r++){let i=p(e[r],e[r+1]);i&&t.some(e=>d(i,e))&&(n+=1)}return n}const br=[{nudgeOrthogonalSegmentsConnectedToShapes:!1,performUnifyingNudgingPreprocessingStep:!1},{nudgeOrthogonalSegmentsConnectedToShapes:!0,performUnifyingNudgingPreprocessingStep:!1},{nudgeOrthogonalSegmentsConnectedToShapes:!1,performUnifyingNudgingPreprocessingStep:!0},{nudgeOrthogonalSegmentsConnectedToShapes:!0,performUnifyingNudgingPreprocessingStep:!0}];async function xr(e,t,n,r,i,a){let o=null,s=1/0;for(let[c,l]of br.entries()){if(G(),c>0&&!oe())break;await se();let u;try{u=await Sr(e,t,n,r,{crossingPenalty:700,idealNudgingDistance:16,nudgeSharedPathsWithCommonEndPoint:!0,nudgeOrthogonalTouchingColinearSegments:!0,...l},i,a,c===0)}catch(e){if(!(e instanceof pe))throw e;if(c===0)throw new V(U()?.limitMs??0);break}let d=[...u.routes.values()].map(e=>[e.sourcePoint,...e.bendPoints,e.targetPoint]),f=0,p=0;for(let e=0;e<d.length;e++)for(let t=e+1;t<d.length;t++)N(d[e],d[t])>0&&(f+=1),b(d[e],d[t])&&(p+=1);let m=[...t.values()],h=d.reduce((e,t)=>e+yr(t,m),0),g=f*3e3+p*1500+h*6e3;g<s&&(s=g,o=u)}return o}async function Sr(e,t,n,r,i,a=!1,o,s=!0){let c=pr(e,new Set(e.map(e=>e.id)),r,a,o),l=new Map(c.map(e=>[e.id,{connection:e.conn}])),u=new Set(e.filter(e=>(e.type??``).includes(`Gateway`)).map(e=>e.id)),d=new Set(e.filter(e=>(e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`)).map(e=>e.id)),{sourceSideByEdge:f,targetSideByEdge:p}=a?vr(c,e,t):_r(c,n,e,d,t),m=/* @__PURE__ */ new Map;c.forEach(e=>{let t=f.get(e.id),n=p.get(e.id);if(t){let n=`${e.sourceId}:${t}:source`;m.has(n)||m.set(n,[]),m.get(n).push(`${e.id}:source`)}if(n){let t=`${e.targetId}:${n}:target`;m.has(t)||m.set(t,[]),m.get(t).push(`${e.id}:target`)}});let h=/* @__PURE__ */ new Set;m.forEach((e,t)=>{let[n,r,i]=t.split(`:`),a=i===`source`?`target`:`source`;m.has(`${n}:${r}:${a}`)&&h.add(`${n}:${r}`)});let g=/* @__PURE__ */ new Map,_=/* @__PURE__ */ new Map,v=(e,t,n,r)=>{g.has(e)||g.set(e,[]);let i=g.get(e),a=i.find(e=>e.id===t);if(a)return a.id;let o={...n};for(;i.some(e=>Math.abs(e.x-o.x)<.5&&Math.abs(e.y-o.y)<.5);)r===`NORTH`||r===`SOUTH`?o.x+=.5:o.y+=.5;return i.push({id:t,...o,properties:{"port.side":r}}),t};m.forEach((e,n)=>{let[r,i,a]=n.split(`:`),o=t.get(r);if(!o)return;let s=!u.has(r)&&h.has(`${r}:${i}`),c=e.length>1,l=s?a===`target`?[0,.5]:[.5,1]:[0,1],d=t=>c?l[0]+(l[1]-l[0])*(t+1)/(e.length+1):s?a===`target`?.4:.6:.5;e.forEach((e,t)=>{let n=c?`${r}__${i}__${a}__${t}`:`${r}__${i}__${a}`,s=v(r,n,hr(o,i,d(t)),i);_.set(e,s)})});let y={id:`root`,children:mr(e,t,g),edges:c.map(e=>({id:e.id,sources:[_.get(`${e.id}:source`)??e.sourceId],targets:[_.get(`${e.id}:target`)??e.targetId]}))},b=e=>{let n=t.get(e);return n?{x:n.x+n.width/2,y:n.y+n.height/2}:{x:0,y:0}},x=de(c.map(e=>({from:b(e.sourceId),to:b(e.targetId),source:e.sourceId,target:e.targetId}))),S=i.performUnifyingNudgingPreprocessingStep===!0;if(fe(x,e.length,S)>(U()?.remaining()??1/0)*(s?1:.5))throw new pe;let C=await R(y,i),w=e=>{if(!e)return!1;let t=[e.sourcePoint,...e.bendPoints,e.targetPoint];return t.some((e,n)=>n>0&&Math.abs(e.x-t[n-1].x)>1&&Math.abs(e.y-t[n-1].y)>1)},T=new Set(c.filter(e=>w(C.get(e.id))).map(e=>e.id));if(T.size>0){let n={id:`root`,children:mr(e,t,g),edges:c.map(e=>({id:e.id,sources:[T.has(e.id)?e.sourceId:_.get(`${e.id}:source`)??e.sourceId],targets:[T.has(e.id)?e.targetId:_.get(`${e.id}:target`)??e.targetId]}))},r=await R(n,i);T.forEach(e=>{let t=r.get(e);t&&C.set(e,t)})}return{routes:C,edgeMeta:l}}function Cr(e,t,n){if(e.length<3)return e;let r=e.length,i=e[r-1],a=e[r-2],o=e[r-3],s=Math.abs(i.x-t.x)<.5||Math.abs(i.x-(t.x+t.width))<.5,c=Math.abs(i.y-t.y)<.5||Math.abs(i.y-(t.y+t.height))<.5,l=Math.abs(i.x-a.x)<.5&&Math.abs(i.y-a.y)>.5,u=Math.abs(i.y-a.y)<.5&&Math.abs(i.x-a.x)>.5,d=Math.abs(a.y-o.y)<.5&&Math.abs(a.x-o.x)>.5,f=Math.abs(a.x-o.x)<.5&&Math.abs(a.y-o.y)>.5;if(s&&l&&d){let t={x:o.x,y:i.y};if(!q(o,t,n)&&!q(t,i,n)){let n=[...e];return n[r-2]=t,n}}if(c&&u&&f){let t={x:i.x,y:o.y};if(!q(o,t,n)&&!q(t,i,n)){let n=[...e];return n[r-2]=t,n}}return e}function wr(e){return(e.type??``).includes(`Gateway`)||(e.type??``).includes(`Event`)}function Tr(e,t){let n=Math.abs(e.x-t.x)<.5||Math.abs(e.x-(t.x+t.width))<.5,r=Math.abs(e.y-t.y)<.5||Math.abs(e.y-(t.y+t.height))<.5;return n&&!r?`horizontal`:r&&!n?`vertical`:null}function Er(e,t,n,r){let i=e.y===t.y;if(i===(n.y===r.y))return!1;let a=i?{y:e.y,x1:Math.min(e.x,t.x),x2:Math.max(e.x,t.x)}:{y:n.y,x1:Math.min(n.x,r.x),x2:Math.max(n.x,r.x)},o=i?{x:n.x,y1:Math.min(n.y,r.y),y2:Math.max(n.y,r.y)}:{x:e.x,y1:Math.min(e.y,t.y),y2:Math.max(e.y,t.y)};return o.x>a.x1&&o.x<a.x2&&a.y>o.y1&&a.y<o.y2}function Dr(e,t){for(let n=0;n+1<e.length;n++)for(let r of t)for(let t=0;t+1<r.length;t++)if(Er(e[n],e[n+1],r[t],r[t+1]))return!0;return!1}function Or(e,t,n){for(let n=0;n+1<e.length;n++)if(q(e[n],e[n+1],t))return!1;return!Dr(e,n)}function kr(e,t,n,r,i){if(e.length!==3)return null;let a=e[0],o=e[2],s=Tr(a,t),c=Tr(o,n);if(s===`horizontal`&&c===`horizontal`&&Math.abs(a.y-o.y)>.5){let e=(a.x+o.x)/2,t=[a,{x:e,y:a.y},{x:e,y:o.y},o];return Or(t,r,i)?t:null}if(s===`vertical`&&c===`vertical`&&Math.abs(a.x-o.x)>.5){let e=(a.y+o.y)/2,t=[a,{x:a.x,y:e},{x:o.x,y:e},o];return Or(t,r,i)?t:null}return null}function Ar(e,t,n,r,i,a,o){let s=e;if(n&&(s=Ve(s,n,o,!1,r)),t&&(s=Ve(s,t,a,!0,r)),t&&n){let e=kr(s,t,n,r,i);if(e)return e}return n&&(s=Cr(s,n,r)),t&&(s=[...Cr([...s].reverse(),t,r)].reverse()),s}function jr(e,t,n,r){if(!t||!n||e.length<2)return e;let i=e[0],a=e[e.length-1],o=Math.abs(i.x-(t.x+t.width))<.5,s=Math.abs(a.x-n.x)<.5;if(!o||!s||n.x<=t.x+t.width)return e;if(Math.abs(i.y-a.y)<.5)return[i,a];let c=Math.round((t.x+t.width+n.x)/2),l=[i,{x:c,y:i.y},{x:c,y:a.y},a];for(let t=0;t+1<l.length;t++)if(q(l[t],l[t+1],r))return e;return l}function Mr(e,t,n){let r=e.label,i=e.waypoints??[];if(!r||i.length<2||t.length<2)return;let a=e=>{let t=Math.floor(e.length/2);if(e.length%2==1)return e[t];let n=e[t-1],r=e[t];return{x:(n.x+r.x)/2,y:(n.y+r.y)/2}},o=a(i),s=a(t),c=s.x-o.x,l=s.y-o.y;Math.abs(c)<1&&Math.abs(l)<1||n.moves.push({elements:[r],dx:c,dy:l})}function Nr(e){let t=0;for(let n=1;n<e.length-1;n++){let r=e[n-1],i=e[n],a=e[n+1];Math.abs((i.x-r.x)*(a.y-i.y)-(i.y-r.y)*(a.x-i.x))>1&&t++}return t}function Pr(e,t,n,r){if(!t||!n||Nr(e)<2)return e;let i={x:t.x+t.width/2,y:t.y+t.height/2},a={x:n.x+n.width/2,y:n.y+n.height/2},o=a.x>=i.x?t.x+t.width:t.x,s=a.y>=i.y?t.y+t.height:t.y,c=i.x>=a.x?n.x+n.width:n.x,l=i.y>=a.y?n.y+n.height:n.y,u=Math.abs(i.y-a.y)<=1,d=Math.abs(i.x-a.x)<=1,f=[];u&&f.push([{x:o,y:i.y},{x:c,y:i.y}]),d&&f.push([{x:i.x,y:s},{x:i.x,y:l}]),f.push([{x:o,y:i.y},{x:a.x,y:i.y},{x:a.x,y:l}]),f.push([{x:i.x,y:s},{x:i.x,y:a.y},{x:c,y:a.y}]);let p=e=>e.slice(1).every((i,a)=>{let o=e[a],s=Math.min(o.x,i.x),c=Math.max(o.x,i.x),l=Math.min(o.y,i.y),u=Math.max(o.y,i.y);return r.every(e=>e===t||e===n||!(s<e.x+e.width-2&&c>e.x+2&&l<e.y+e.height-2&&u>e.y+2))}),m=(e,t)=>Math.abs(e.x-t.x)<.5?`W`:Math.abs(e.x-(t.x+t.width))<.5?`E`:Math.abs(e.y-t.y)<.5?`N`:Math.abs(e.y-(t.y+t.height))<.5?`S`:`?`,h=m(e[0],t),g=m(e[e.length-1],n),_=e=>m(e[0],t)===h&&m(e[e.length-1],n)===g;return f.find(t=>Nr(t)<Nr(e)&&_(t)&&p(t))??e}function Fr(e,t){let n=[...e],r=0;for(;r+3<n.length;){let[e,i,a,o]=[n[r],n[r+1],n[r+2],n[r+3]],s=Math.abs(i.x-a.x),c=Math.abs(i.y-a.y),l=e.x===i.x&&a.x===o.x&&i.y===a.y&&s>.5&&s<40,u=e.y===i.y&&a.y===o.y&&i.x===a.x&&c>.5&&c<40;if(l){let i={x:o.x,y:e.y};if(!q(e,i,t)&&!q(i,o,t)){n.splice(r,4,i,o);continue}}if(u){let i={x:e.x,y:o.y};if(!q(e,i,t)&&!q(i,o,t)){n.splice(r,4,i,o);continue}}r++}return n.filter((e,t)=>t===0||e.x!==n[t-1].x||e.y!==n[t-1].y)}function Ir(e){return(e.children||[]).filter(e=>e.type===`bpmn:Lane`).sort((e,t)=>e.y-t.y||(e.id<t.id?-1:1))}function Lr(e,t,n,r){let i=/* @__PURE__ */ new Map;return t.forEach(e=>Q(e,n).forEach(t=>{let n=r(e),a=r(t.target);if(!n||!a||n===a)return;let o=Le(n,a);i.set(o,(i.get(o)??0)+1)})),Re(e,e=>e.businessObject?.id??e.id,i)}function Rr(e,t,n,r,i,a){if(t.length===0)return;let o=/* @__PURE__ */ new Map;n.forEach(e=>{let t=e.businessObject?.lanes?.[0]?.id;t&&o.set(e.id,t)});let s=e=>e.businessObject?.id??e.id,c=e=>{let t=Ir(e);if(t.length)return t.flatMap(c);let i=s(e);return n.filter(e=>o.get(e.id)===i&&r.has(e.id))},l=(e,t)=>{let n=r.get(e.id);!n||Math.abs(t)<.5||(a.moves.push({elements:[e],dx:0,dy:t}),r.set(e.id,{...n,y:n.y+t}),(e.attachers||[]).forEach(e=>{let n=r.get(e.id);n&&(a.moves.push({elements:[e],dx:0,dy:t}),r.set(e.id,{...n,y:n.y+t}))}))},u=(e,t,o,s)=>{let d=s;return e.forEach(e=>{let s=Lr(Ir(e),n,new Set(n.map(e=>e.id)),t=>{let n=t.businessObject?.lanes?.[0]?.id;return Ir(e).some(e=>(e.businessObject?.id??e.id)===n)?n:void 0}),f=o-30,p;if(s.length)p=u(s,t+30,f,d)-d;else{let t=c(e);if(t.length){t.map(e=>r.get(e.id));let e=t.map(e=>{let t=r.get(e.id),n=(e.attachers||[]).map(e=>r.get(e.id)).filter(e=>!!e);return{top:Math.min(t.y,...n.map(e=>e.y)),bottom:Math.max(t.y+t.height,...n.map(e=>e.y+e.height))}}),n=Math.min(...e.map(e=>e.top));p=Math.max(...e.map(e=>e.bottom))-n+i.nodesep*2;let a=d+i.nodesep-n;t.forEach(e=>l(e,a))}else p=i.nodesep*2+40}a.resizes.push({element:e,x:t,y:d,width:o,height:p}),r.set(e.id,{x:t,y:d,width:o,height:p}),d+=p}),d},d=Lr(t,n,new Set(n.map(e=>e.id)),e=>{let n=e.businessObject?.lanes?.[0]?.id;if(!n)return;let r=t.find(e=>(e.businessObject?.id??e.id)===n);for(;r&&r.parent&&r.parent.type===`bpmn:Lane`&&!t.includes(r);)r=r.parent;return r?r.businessObject?.id??r.id:n}),f=n.filter(e=>!x.has(e.type??``)&&r.get(e.id)),p=f.length>0?f:n.filter(e=>r.get(e.id)),m=Math.min(...p.map(e=>r.get(e.id).x))-i.marginX,h=Math.max(...p.map(e=>r.get(e.id).x+r.get(e.id).width))+i.marginX-m,g=Math.min(...p.map(e=>r.get(e.id).y))-i.marginY,_=u(d,m,h,g);a.resizes.push({element:e,x:m-30,y:g,width:h+30,height:_-g})}function zr(e,t,n,r,i,a,o,s){let c=[];e.forEach(e=>{(e.outgoing||[]).forEach(t=>{let n=t.target;if(!n)return;let r=x.has(e.type??``);r!==x.has(n.type??``)&&c.push({real:r?n:e,annotation:r?e:n,conn:t,elIsAnn:r})})});let l=(e,t)=>t.y>=e.y+e.height?`SOUTH`:t.y+t.height<=e.y?`NORTH`:t.x>=e.x+e.width?`EAST`:`WEST`,u=/* @__PURE__ */ new Map;c.forEach(e=>{let t=n.get(e.real.id),r=n.get(e.annotation.id);if(!t||!r)return;let i=`${e.real.id}:${l(t,r)}`;u.has(i)||u.set(i,[]),u.get(i).push(e)}),c.forEach(e=>{let t=n.get(e.real.id),r=n.get(e.annotation.id);if(!t||!r)return;let i=l(t,r),a=u.get(`${e.real.id}:${i}`)??[e],s=.5;if(a.length>1&&!wr(e.real)){let t=[...a].sort((e,t)=>{let r=n.get(e.annotation.id),a=n.get(t.annotation.id);return(i===`NORTH`||i===`SOUTH`?r.x+r.width/2:r.y+r.height/2)-(i===`NORTH`||i===`SOUTH`?a.x+a.width/2:a.y+a.height/2)||(e.annotation.id<t.annotation.id?-1:1)});s=(t.findIndex(t=>t.annotation.id===e.annotation.id)+1)/(t.length+1)}let c=Fe(t,r,s),d=e.elIsAnn?[...c].reverse():c;o.routes.push({connection:e.conn,waypoints:d})});let d=0,f=0,p=(e,c)=>{let l=c.target;if(!l||!t.has(l.id)||x.has(l.type??``)||i||!fr(e,l.id,r))return;let u=n.get(e),p=n.get(l.id);if(!u||!p)return;let m=u.x+u.width/2,h=p.x+p.width/2,g=a+s.nodesep+d*s.nodesep;f=Math.max(f,g),o.routes.push({connection:c,waypoints:[{x:m,y:u.y+u.height},{x:m,y:g},{x:h,y:g},{x:h,y:p.y+p.height}]}),d+=1};return e.forEach(e=>{x.has(e.type??``)||((e.outgoing||[]).forEach(t=>p(e.id,t)),(e.attachers||[]).forEach(e=>(e.outgoing||[]).forEach(t=>p(e.id,t))))}),f}async function Br(e,t,n,r,i,a,o,s,c){let l=c,u=l?{positions:new Map(t.filter(e=>l.positions.has(e.id)).map(e=>[e.id,l.positions.get(e.id)])),sizes:l.sizes,padding:l.padding}:void 0,d=u&&u.positions.size===t.length?u:void 0,f=Se(t,a,x,d);if(f){let l=we(t,f.positions,o,e=>[e],s);for(let e of t){if((e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`).length===0)continue;let t=f.positions.get(e.id)??{x:e.x,y:e.y},n=d?.positions.get(e.id)??{x:e.x,y:e.y},r=l.rects.get(e.id);await Vr(e,a,r?{x:r.x,y:r.y}:null,o,[],{x:s.x+t.x-n.x,y:s.y+t.y-n.y},c)}let u=new Map(o.resizes.map(e=>[e.element.id,e]));t.forEach(e=>{let t=u.get(e.id);t&&l.rects.set(e.id,{x:t.x,y:t.y,width:t.width,height:t.height})}),t.forEach(e=>{let t=l.rects.get(e.id);if(!t)return;let{south:n,north:r}=X(e),i=(n,r)=>{if(n.length===0)return;let i=On(e,t.width);n.forEach(e=>{let n=e.width||36,a=e.height||36,s=Math.round(t.x+i.get(e.id)-n/2),c=Math.round(r-a/2);(s!==e.x||c!==e.y)&&o.moves.push({elements:[e],dx:s-e.x,dy:c-e.y}),l.rects.set(e.id,{x:s,y:c,width:n,height:a})})};i(n,t.y+t.height),i(r,t.y)}),i&&Rr(e,n,t,l.rects,a,o);let{routes:p,edgeMeta:m}=await xr(t,l.rects,f.rows,f.ranks,!0,d?void 0:l.movedIds),h=[...l.rects.values()],_=(e,t,n)=>t?Math.abs(e.x-t.x)<.5?`${n}:W`:Math.abs(e.x-(t.x+t.width))<.5?`${n}:E`:Math.abs(e.y-t.y)<.5?`${n}:N`:`${n}:S`:``,v=/* @__PURE__ */ new Map;p.forEach((e,t)=>{let n=m.get(t);if(!n)return;let r=n.connection.source,i=n.connection.target;[_(e.sourcePoint,r?l.rects.get(r.id):void 0,r?.id??``),_(e.targetPoint,i?l.rects.get(i.id):void 0,i?.id??``)].forEach(e=>{e&&v.set(e,(v.get(e)??0)+1)})});let y=(e,t,n)=>(v.get(_(e,t,n))??0)<=1,b=new Map([...p.entries()].map(([e,t])=>[e,[t.sourcePoint,...t.bendPoints,t.targetPoint]])),x=new Set([...m.values()].map(e=>e.connection.id));return Hr(t,l.rects,o,x),p.forEach((e,t)=>{let n=m.get(t);if(!n)return;let r=n.connection.source?l.rects.get(n.connection.source.id):void 0,i=n.connection.target?l.rects.get(n.connection.target.id):void 0,a=[...b.entries()].filter(([e])=>e!==t).map(([,e])=>e),s=Fr(b.get(t),h),c=He(jr(Pr(Ar(s,r,i,h,a,n.connection.source?wr(n.connection.source)&&y(s[0],r,n.connection.source.id):!1,n.connection.target?wr(n.connection.target)&&y(s[s.length-1],i,n.connection.target.id):!1),r,i,h),r,i,h),r,i,h),u=e=>{let t=0;for(let n=0;n+1<e.length;n++)q(e[n],e[n+1],h)&&t++;return t},d=u(c)>u(s)?s:c;Mr(n.connection,d,o),o.routes.push({connection:n.connection,waypoints:d})}),i||Te(e,l.rects,r,a,o,(e=>({x:e.x+s.x,y:e.y+s.y,width:e.width,height:e.height}))(e),!!d),{size:l.size,flowNodes:t,laned:i,authored:!0}}return null}async function Vr(e,t,n,r,i=[],a={x:0,y:0},o=null){let s=(e,t)=>e.id<t.id?-1:+(e.id>t.id),c=(e.children||[]).filter(e=>e.type===`bpmn:Lane`),l=(e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`),u=[...l,...i].sort(s);if(u.length===0)return null;let d=new Set(u.map(e=>e.id)),f=new Set(l.filter(e=>!x.has(e.type??``)).map(e=>e.id)),p=c.length>0;if(Cn){let n=await Br(e,u,c,f,p,t,r,a,o);if(n)return n}let{positions:m,rows:h,ranks:_,laneBands:v,authored:y}=p?dr(u,d,c,t):{...ar(u,d,t),laneBands:null};if(y&&e.width>0&&e.height>0){let n=e.x+a.x,i=e.y+a.y,o=t.marginY/2,s=0,c=0;u.forEach(t=>{let r=m.get(t.id);if(!r)return;let l=n+o-a.x,u=i+o-a.y,d={x:Math.max(r.x,l),y:Math.max(r.y,u)};m.set(t.id,d),s=Math.max(s,d.x+a.x+t.width+o-(n+e.width)),c=Math.max(c,d.y+a.y+t.height+o-(i+e.height))}),(s>0||c>0)&&r.resizes.push({element:e,x:n,y:i,width:e.width+Math.max(0,s),height:e.height+Math.max(0,c)})}u.forEach(e=>{let t=m.get(e.id);t&&(Number.isFinite(t.x)&&Number.isFinite(t.y)||m.set(e.id,{x:Number.isFinite(t.x)?t.x:e.x,y:Number.isFinite(t.y)?t.y:e.y}))});let b=/* @__PURE__ */ new Map,S=0,C=0,T=0;u.forEach(e=>{let t=m.get(e.id);if(e.label){let n=t.x+(e.label.x-e.x);T=Math.max(T,-n)}}),u.forEach(e=>{let t=m.get(e.id),i=y?t.x:t.x+(n?.x??0)+T,o=y?t.y:t.y+(n?.y??0),s=i-e.x,c=o-e.y;if((s!==0||c!==0)&&r.moves.push({elements:jn(e),dx:s,dy:c}),b.set(e.id,{x:i+a.x,y:o+a.y,width:e.width,height:e.height}),y){(e.attachers||[]).forEach(e=>{b.set(e.id,{x:e.x+s+a.x,y:e.y+c+a.y,width:e.width,height:e.height})}),S=Math.max(S,i+e.width),C=Math.max(C,o+e.height+Z(e,`SOUTH`)),e.label&&(S=Math.max(S,i+(e.label.x+e.label.width-e.x)),C=Math.max(C,o+(e.label.y+e.label.height-e.y)));return}let{south:l,north:u}=X(e);[{list:l,y:o+e.height},{list:u,y:o}].forEach(({list:t,y:n})=>{let a=t.reduce((e,t)=>e+t.width,0)+6*Math.max(0,t.length-1),o=i+e.width/2-a/2;t.forEach(e=>{let t=o,i=n-e.height/2;b.set(e.id,{x:t,y:i,width:e.width,height:e.height});let a=t-(e.x+s),l=i-(e.y+c);(a!==0||l!==0)&&r.moves.push({elements:[e],dx:a,dy:l}),o+=e.width+6})}),S=Math.max(S,i+e.width),C=Math.max(C,o+e.height+Z(e,`SOUTH`)),e.label&&(S=Math.max(S,i+(e.label.x+e.label.width-e.x)),C=Math.max(C,o+(e.label.y+e.label.height-e.y)))});let E=zr(u,d,b,_,!!y,C,r,t);C=Math.max(C,E);for(let e of u){if((e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`).length===0)continue;let n=b.get(e.id);if(!n)continue;let i=r.resizes.length;await Vr(e,t,{x:n.x,y:n.y},r,[],{x:n.x-e.x,y:n.y-e.y},o);let a=r.resizes.slice(i).find(t=>t.element===e);a&&(b.set(e.id,{x:a.x,y:a.y,width:a.width,height:a.height}),S=Math.max(S,a.x+a.width),C=Math.max(C,a.y+a.height))}let D=new Set(u.filter(e=>{let t=b.get(e.id);return!!t&&(Math.abs(t.x-e.x)>1||Math.abs(t.y-e.y)>1)}).map(e=>e.id));if(y){let e=u.filter(e=>!x.has(e.type??``)).map(e=>({id:e.id,rect:b.get(e.id)})).filter(e=>!!e.rect);u.forEach(t=>{[t,...t.attachers||[]].forEach(n=>{(n.outgoing||[]).forEach(r=>{let i=r,a=i.target;if(!a||x.has(a.type??``)||x.has(t.type??``))return;let o=i.waypoints??[];o.slice(1).some((t,r)=>{let i=o[r],s=Math.min(i.x,t.x),c=Math.max(i.x,t.x),l=Math.min(i.y,t.y),u=Math.max(i.y,t.y);return e.some(({id:e,rect:t})=>e===n.id||e===a.id?!1:s<t.x+t.width-2&&c>t.x+2&&l<t.y+t.height-2&&u>t.y+2)})&&(D.add(n.id),D.add(a.id))})})})}let{routes:O,edgeMeta:k}=await xr(u,b,h,_,y===!0,y===!0?D:void 0),A=[...b.values()],M=new Map([...O.entries()].map(([e,t])=>[e,[t.sourcePoint,...t.bendPoints,t.targetPoint]])),N=new Set([...k.values()].map(e=>e.connection.id));y&&Hr(u,b,r,N),O.forEach((e,t)=>{let n=k.get(t);if(!n)return;let i=n.connection.source?b.get(n.connection.source.id):void 0,a=n.connection.target?b.get(n.connection.target.id):void 0,o=[...M.entries()].filter(([e])=>e!==t).map(([,e])=>e),s=Fr(M.get(t),A),c=n.connection.source?wr(n.connection.source):!1,l=n.connection.target?wr(n.connection.target):!1,u=Pr(Ar(s,i,a,A,o,c,l),i,a,A);Mr(n.connection,u,r),r.routes.push({connection:n.connection,waypoints:u})});let P=n?.x??0,F=n?.y??0;if(v){let i=n?F-40:0,a=S+40,o=v.reduce((e,t)=>e+t.height,0),s=Math.max(o,E+t.nodesep-i),l=s-o;l>0&&(v[v.length-1].height+=l);let u=s;C=Math.max(C,i+u),r.resizes.push({element:e,x:0,y:i,width:a,height:u}),c.forEach((e,t)=>{let n=v[t];r.resizes.push({element:e,x:0,y:i+n.y,width:a,height:n.height})})}return{size:{width:S-P,height:C-F},flowNodes:u,laned:p,authored:y===!0}}function Hr(e,t,n,r){let i=e=>{let n=e?t.get(e.id):void 0;return!e||!n?{x:0,y:0}:{x:n.x-e.x,y:n.y-e.y}},a=/* @__PURE__ */ new Set;e.forEach(e=>{[e,...e.attachers||[]].forEach(e=>{(e.outgoing||[]).forEach(t=>{let o=t;if(a.has(o.id)||(a.add(o.id),r?.has(o.id)))return;let s=o.waypoints??[];if(s.length<2)return;let c=i(o.source??e),l=i(o.target),u=s.length-1,d=s.map((e,t)=>{let n=u===0?0:t/u;return{x:e.x+c.x+(l.x-c.x)*n,y:e.y+c.y+(l.y-c.y)*n}});for(let e=1;e<d.length;e++){let t=e===d.length-1?2:20;Math.abs(d[e].x-d[e-1].x)<=t?d[e].x=d[e-1].x:Math.abs(d[e].y-d[e-1].y)<=t&&(d[e].y=d[e-1].y)}Mr(o,d,n),n.routes.push({connection:o,waypoints:d})})})})}function Ur(e){let t=[];return(e.outgoing||[]).forEach(e=>{e.target&&!x.has(e.target.type??``)&&t.push(e.target.id)}),(e.incoming||[]).forEach(e=>{e.source&&!x.has(e.source.type??``)&&t.push(e.source.id)}),t}function Wr(e,t){let n=new Map(e.map(e=>[e.id,e])),r=/* @__PURE__ */ new Map,i=[];e.forEach(e=>Q(e,t).forEach(t=>{t.fromBoundary?i.push(t.target.id):(r.has(t.target.id)||r.set(t.target.id,/* @__PURE__ */ new Set),r.get(t.target.id).add(e.id))}));let a=/* @__PURE__ */ new Set,o=[];return[...new Set(i)].forEach(e=>{let i=/* @__PURE__ */ new Set,s=[e];for(;s.length;){let e=s.shift();if(i.has(e)||a.has(e))continue;i.add(e);let r=n.get(e);r&&Q(r,t).filter(e=>!e.fromBoundary).forEach(e=>s.push(e.target.id))}for(let t=!1;!t;)t=!0,[...i].forEach(n=>{if(n===e)return;let a=r.get(n);a&&![...a].every(e=>i.has(e))&&(i.delete(n),t=!1)});i.size!==0&&(i.forEach(e=>a.add(e)),o.push([...i]))}),o.sort((e,t)=>t.length-e.length)}function Gr(e,t,n,r,i,a,o,s,c){let l=Math.max(...e.map(i))+c.nodesep,u=({source:e,target:t,escape:r})=>r||Math.sign(n(t)-n(e)),d=new Map(e.map(e=>[e.id,e.id])),f=e=>{let t=e;for(;d.get(t)!==t;)t=d.get(t);let n=e;for(;d.get(n)!==t;){let e=d.get(n);d.set(n,t),n=e}return t};t.forEach(e=>{u(e)===0&&d.set(f(e.source.id),f(e.target.id))});let p=/* @__PURE__ */ new Map,m=(e,t,n)=>{p.has(e)||p.set(e,[]),p.get(e).push({other:t,delta:n})};t.forEach(e=>{let t=u(e);if(t===0)return;let{source:n,target:r,escape:a,port:d}=e,p=t*((a?c.nodesep+d:l)+(a||(s.get(n.id)??0)>1?i(n)/2:0)+((o.get(r.id)??0)>1?i(r)/2:0));m(f(n.id),f(r.id),p),m(f(r.id),f(n.id),-p)});let h=/* @__PURE__ */ new Map,g=[...e].sort((e,t)=>n(e)-n(t)||r(e)-r(t));g.forEach(e=>{if(h.has(f(e.id)))return;h.set(f(e.id),n(e)*l);let t=[f(e.id)];for(;t.length;){let e=t.shift();(p.get(e)??[]).forEach(({other:n,delta:r})=>{h.has(n)||(h.set(n,h.get(e)+r),t.push(n))})}});let _=e=>h.get(f(e.id)),v=[...new Set(e.map(r))].sort((e,t)=>e-t),y=[...new Set(g.map(e=>f(e.id)))];for(let t=0;t<200;t++){let t=0;if(y.forEach(e=>{let n=p.get(e)??[];if(!n.length)return;let r=n.reduce((e,{other:t,delta:n})=>e+h.get(t)-n,0)/n.length;t=Math.max(t,Math.abs(r-h.get(e))),h.set(e,r)}),v.forEach(o=>{let s=e.filter(e=>r(e)===o).sort((e,t)=>_(e)-_(t)||n(e)-n(t));for(let e=1;e<s.length;e++){let n=s[e-1],r=s[e],o=i(n)/2+a(n)+c.nodesep+i(r)/2-(_(r)-_(n));o>0&&(h.set(f(r.id),_(r)+o),t=Math.max(t,o))}}),t<.5)break}let b=c.marginY-Math.min(...e.map(e=>_(e)-i(e)/2));return[...h.keys()].forEach(e=>h.set(e,h.get(e)+b)),_}function Kr(e,t,n){let r=e=>x.has(e.type??``),i=e.filter(e=>!r(e));if(i.length===0)return new Map(e.map(e=>[e.id,{x:e.x,y:e.y}]));let a=i.filter(e=>e.type===`bpmn:Participant`);if(a.length===i.length){let t=/* @__PURE__ */ new Map,i=n.marginY;return[...a].sort((e,t)=>e.y-t.y||(e.id<t.id?-1:1)).forEach(e=>{t.set(e.id,{x:n.marginX,y:i}),i+=(e.height||200)+n.nodesep}),qr(e.filter(r),a,t,n,e=>e.width||100,e=>e.height||80)}let o=qn(i,t),s=Wr(i,t),c=new Set(s.flat()),l=Yn(i,t,o),u=$n(i,t,o,l.groups),d=rr(i,t,l.groups,u),{groups:f}=Yn(i,t,o,d),p=$n(i,t,o,f,d);nr(i,t,o,f,p,/* @__PURE__ */ new Set);let m=/* @__PURE__ */ new Map;i.forEach(e=>{let n=On(e,e.width||100),r=new Set(X(e).north.map(e=>e.id));Q(e,t).forEach(t=>{t.fromBoundary&&c.has(t.target.id)&&m.set(t.target.id,{row:p.get(e.id)??0,port:n.get(t.sourceAttacherId??``)??0,away:r.has(t.sourceAttacherId??``)?-1:1})})});let h=s.map(e=>({path:e,entry:m.get(e.find(e=>m.has(e))??``)})).filter(e=>!!e.entry).sort((e,t)=>e.entry.row-t.entry.row||t.entry.port-e.entry.port);h.forEach(({path:e,entry:t},n)=>{let r=(n+1)/(h.length+1);e.forEach(e=>p.set(e,t.row+t.away*r))});let g=[.../* @__PURE__ */ new Set([...p.values()])].sort((e,t)=>e-t),_=new Map(g.map((e,t)=>[e,t]));p.forEach((e,t)=>p.set(t,_.get(e)));let v=e=>e.width||100,y=e=>e.height||80,b=e=>e.label&&e.label.y>=e.y+y(e)?e.label.y+e.label.height-(e.y+y(e)):0,S=e=>p.get(e.id)??0,C=e=>o.get(e.id)??0,w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Map,E=[];i.forEach(e=>{let n=new Set(X(e).north.map(e=>e.id));Q(e,t).forEach(t=>{if(t.fromBoundary){let r=(e.attachers||[]).find(e=>e.id===t.sourceAttacherId);E.push({source:e,target:t.target,escape:n.has(t.sourceAttacherId??``)?-1:1,port:(r?.height||36)/2})}else w.set(e.id,(w.get(e.id)??0)+1),T.set(t.target.id,(T.get(t.target.id)??0)+1),E.push({source:e,target:t.target,escape:0,port:0})})});let D=Gr(i,E,S,C,y,b,T,w,n),O=e=>D(e),k=e=>O(e)-y(e)/2,A=[...new Set(i.map(C))].sort((e,t)=>e-t),j=/* @__PURE__ */ new Map;A.forEach(e=>{let t=i.filter(t=>C(t)===e&&!c.has(t.id));j.set(e,t.length?Math.max(...t.map(v)):0)});let M=/* @__PURE__ */ new Map;E.forEach(({source:e,target:t,escape:r})=>{if(c.has(t.id))return;let i=C(e),a=C(t);if(a<=i)return;let o=Math.abs(O(t)-O(e)),s=r!==0||(w.get(e.id)??0)>1&&o>y(e)/2,l=(T.get(t.id)??0)>1&&o>y(t)/2,u=s||l||o<1?1:2,d=j.get(i)/2+(s?0:v(e)/2)+u*(r?n.nodesep:n.ranksep)+(l?0:v(t)/2)-j.get(a)/2;M.has(a)||M.set(a,[]),M.get(a).push({from:i,reach:d})});let N=/* @__PURE__ */ new Map;A.forEach((e,t)=>{if(t===0){N.set(e,n.marginX);return}let r=A[t-1],i=N.get(r)+j.get(r)+n.ranksep;(M.get(e)??[]).forEach(({from:e,reach:t})=>{N.has(e)&&(i=Math.max(i,N.get(e)+t))}),N.set(e,Math.round(i))});let P=/* @__PURE__ */ new Map;i.forEach(e=>Q(e,t).forEach(t=>{t.fromBoundary&&c.has(t.target.id)&&P.set(t.target.id,e)}));let F=e=>N.get(C(e))+(j.get(C(e))-v(e))/2,I=/* @__PURE__ */ new Map;s.forEach(e=>{let r=e.find(e=>P.has(e));if(r===void 0)return;let a=P.get(r),o=F(a)+v(a)+n.nodesep,s=[r],l=/* @__PURE__ */ new Set;for(;s.length;){let e=s.shift();if(l.has(e))continue;l.add(e);let r=i.find(t=>t.id===e);r&&(I.set(e,o),o+=v(r)+n.nodesep,Q(r,t).filter(e=>!e.fromBoundary&&c.has(e.target.id)).forEach(e=>s.push(e.target.id)))}});let L=/* @__PURE__ */ new Map;i.forEach(e=>{let t=I.get(e.id)??F(e);L.set(e.id,{x:Math.round(t),y:Math.round(k(e))})});let R=Jr(i,E,L,n,v,y,b);return qr(e.filter(r),i,R,n,v,y)}function qr(e,t,n,r,i,a){if(e.length===0)return n;let o=new Map(t.map(e=>[e.id,e])),s=t.filter(e=>n.has(e.id)).map(e=>({...n.get(e.id),width:i(e),height:a(e)})),c=e=>!s.some(t=>S(e,t)),l=e=>{let t=e;for(;t;){let e=o.get(t.id);if(e&&n.has(e.id))return e;t=t.parent}},u=e=>{let t=[...(e.outgoing||[]).map(e=>e.target),...(e.incoming||[]).map(e=>e.source)].map(l).filter(t=>!!t&&!e.id.startsWith(t.id));return[...new Map(t.map(e=>[e.id,e])).values()]},d=r.nodesep;return[...e].map((e,t)=>({decoration:e,index:t,owners:u(e)})).sort((e,t)=>t.owners.length-e.owners.length||i(t.decoration)*a(t.decoration)-i(e.decoration)*a(e.decoration)||e.index-t.index).forEach(({decoration:e,owners:t})=>{let o=i(e),l=a(e),u=()=>{let e=s.length?Math.max(...s.map(e=>e.x+e.width)):r.marginX,t=s.length?Math.min(...s.map(e=>e.y)):r.marginY;for(;!c({x:e+d,y:t,width:o,height:l});)t+=l+d;return{x:e+d,y:t,width:o,height:l}};if(t.length===0){let t=u();n.set(e.id,{x:Math.round(t.x),y:Math.round(t.y)}),s.push(t);return}let f={x:t.reduce((e,t)=>e+n.get(t.id).x+i(t)/2,0)/t.length,y:t.reduce((e,t)=>e+n.get(t.id).y+a(t)/2,0)/t.length},p={top:Math.min(...t.map(e=>n.get(e.id).y)),bottom:Math.max(...t.map(e=>n.get(e.id).y+a(e))),left:Math.min(...t.map(e=>n.get(e.id).x)),right:Math.max(...t.map(e=>n.get(e.id).x+i(e)))},m=[{x:f.x-o/2,y:p.bottom+d,slide:`x`},{x:f.x-o/2,y:p.top-d-l,slide:`x`},{x:p.right+d,y:f.y-l/2,slide:`y`},{x:p.left-d-o,y:f.y-l/2,slide:`y`}],h=null;for(let e of m){for(let t=0;t<=8&&!h;t++)for(let n of t===0?[1]:[1,-1]){let r=n*t*(d+Math.min(o,l)),i={x:e.x+(e.slide===`x`?r:0),y:e.y+(e.slide===`y`?r:0),width:o,height:l};if(c(i)){h=i;break}}if(h)break}let g=h??(()=>{let e=d+Math.min(o,l)/2,t=[];for(let n=1;n<=12;n++)for(let r=-n;r<=n;r++)for(let i of[-n,n])t.push({x:f.x-o/2+r*e,y:f.y-l/2+i*e,width:o,height:l}),t.push({x:f.x-o/2+i*e,y:f.y-l/2+r*e,width:o,height:l});return t.filter(c).sort((e,t)=>Math.abs(e.x-f.x)+Math.abs(e.y-f.y)-(Math.abs(t.x-f.x)+Math.abs(t.y-f.y)))[0]??null})()??u();n.set(e.id,{x:Math.round(g.x),y:Math.round(g.y)}),s.push(g)}),n}function Jr(e,t,n,r,i,a,o){let s=new Map(e.map(e=>[e.id,e.id])),c=e=>{let t=e;for(;s.get(t)!==t;)t=s.get(t);let n=e;for(;s.get(n)!==t;){let e=s.get(n);s.set(n,t),n=e}return t};t.forEach(({source:e,target:t})=>s.set(c(e.id),c(t.id)));let l=/* @__PURE__ */ new Map;if(e.forEach(e=>{let t=c(e.id);l.has(t)||l.set(t,[]),l.get(t).push(e)}),l.size<2)return n;let u=r.nodesep,d=[...l.values()].map(e=>{let t=Math.min(...e.map(e=>n.get(e.id).x))-u,r=Math.min(...e.map(e=>n.get(e.id).y))-u;return{group:e,left:t,top:r,width:Math.max(...e.map(e=>n.get(e.id).x+i(e)))+u-t,height:Math.max(...e.map(e=>n.get(e.id).y+a(e)+o(e)))+u-r}}).map(e=>({box:e,shapes:e.group.map(e=>{let t=n.get(e.id);return{x:t.x,y:t.y,width:i(e),height:a(e)+o(e)}})})),f=d.reduce((e,{box:t})=>e+t.width+t.height,0),p=d.reduce((e,{box:t})=>e+t.width*t.height,0),m=Math.max(1,36*d.length-1),h=Math.max(r.nodesep,(f+Math.sqrt(f*f+4*m*p))/(2*m)),g=({box:e,shapes:t})=>{let n=/* @__PURE__ */ new Set;return t.forEach(t=>{let r=Math.floor((t.x-e.left)/h),i=Math.floor((t.y-e.top)/h),a=Math.floor((t.x+t.width-e.left)/h),o=Math.floor((t.y+t.height-e.top)/h);for(let e=r;e<=a;e++)for(let t=i;t<=o;t++)n.add(`${e}:${t}`)}),[...n].map(e=>{let[t,n]=e.split(`:`).map(Number);return{column:t,row:n}})},_=d.map(e=>({...e,tiles:g(e)})).sort((e,t)=>t.box.width+t.box.height-(e.box.width+e.box.height)),v=/* @__PURE__ */ new Set,y=Math.ceil(Math.sqrt(_.reduce((e,t)=>e+t.tiles.length,0)))+4,b=[];for(let e=0;e<=y;e++)for(let t=-e;t<=e;t++)for(let n=-e;n<=e;n++)Math.max(Math.abs(t),Math.abs(n*1.6))===e&&b.push({x:t,y:n});let x=/* @__PURE__ */ new Map;_.forEach(e=>{let t=b.find(t=>e.tiles.every(e=>!v.has(`${t.x+e.column}:${t.y+e.row}`)))??b[b.length-1];e.tiles.forEach(e=>v.add(`${t.x+e.column}:${t.y+e.row}`)),e.box.group.forEach(r=>{let i=n.get(r.id);x.set(r.id,{x:i.x-e.box.left+t.x*h,y:i.y-e.box.top+t.y*h})})});let S=Math.min(...[...x.values()].map(e=>e.x)),C=Math.min(...[...x.values()].map(e=>e.y));return x.forEach((e,t)=>x.set(t,{x:e.x-S+r.marginX,y:e.y-C+r.marginY})),x}function Yr(e,t,n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=e=>{let a=(e.children||[]).filter(n);a.forEach(e=>o.set(e.id,e));let c=a.map(e=>{if(Ce(e).length===0)return e;let t=s(e),n={width:Math.max(t.width,En(e)),height:t.height};return i.set(e.id,n),{...e,width:n.width,height:n.height}}),l=Kr(c,new Set(c.map(e=>e.id)),t),u=0,d=0,f=/* @__PURE__ */ new Set;return c.forEach(e=>{let n={...l.get(e.id)??{x:e.x,y:e.y}};for(;f.has(`${Math.round(n.x)}:${Math.round(n.y)}`);)n.y+=e.height+t.nodesep;f.add(`${Math.round(n.x)}:${Math.round(n.y)}`),r.set(e.id,n),u=Math.max(u,n.x+e.width),d=Math.max(d,n.y+e.height)}),{width:u+t.marginX,height:d+t.marginY}};s(e);let c=/* @__PURE__ */ new Map,l=(e,t)=>{(e.children||[]).filter(n).forEach(e=>{let n=r.get(e.id);if(!n)return;let a={x:t.x+n.x,y:t.y+n.y};c.set(e.id,a),i.has(e.id)&&l(e,a)})};return l(e,{x:0,y:0}),c.forEach((e,t)=>{let n=o.get(t);if(!n||(n.attachers??[]).length===0)return;let r=i.get(t)?.width??n.width,{south:s,north:c}=X(n),l=e=>e.reduce((e,t,n)=>e+(t.width||36)+(n>0?6:0),0),u=Math.max(0,(Math.max(l(s),l(c))-r)/2),d=e=>e.reduce((e,t)=>Math.max(e,(t.height||36)/2),0);a.set(t,{top:d(c),bottom:d(s),left:u,right:u})}),{positions:c,sizes:i,padding:a}}async function Xr(e,t,n,r=0){let i=e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`,a={moves:[],resizes:[],routes:[]},o=Cn?Yr(e,t,i):null,s=An(e),c=s.length>1,l=(e.children||[]).some(e=>e.type===`bpmn:Participant`)?(e.children||[]).filter(e=>x.has(e.type??``)):[],u=0;for(let e of s){G(),await se();let i=c?{x:40,y:u+40}:null,s=new Set((e.children||[]).filter(e=>!w(e)&&!j(e)&&!g(e)&&e.type!==`bpmn:Lane`).map(e=>e.id)),d=l.filter(e=>Ur(e).some(e=>s.has(e))),f=await Vr(e,n?.has(e.id)?{...t,nodesep:t.nodesep+r}:t,i,a,d,{x:0,y:0},o);if(f&&c){let t=[...a.resizes].reverse().find(t=>t.element.id===e.id);if(t){u=t.y+t.height+60;continue}let n=f.size.height+80;a.resizes.push({element:e,x:0,y:u,width:f.size.width+80,height:n}),u+=n+60}}return a}function Zr(e){return{moves:e.moves.map(e=>({...e,elements:[...e.elements]})),resizes:e.resizes.map(e=>({...e})),routes:e.routes.map(e=>({...e,waypoints:e.waypoints.map(e=>({...e}))}))}}function Qr(e,t,n,r,i,a,o,s,c,l=!1,u=!0){let d=Zr(t);xt(e,d,n,r),Ot(e,d,n,!1,u),xt(e,d,n,r),Ot(e,d,n,!1,u),a&&St(e,d),G(),Et(e,d,n),jt(e,d,n,l),G(),Lt(e,d,i,o,s),bt(d),Wt(e,d,n),bt(d),Wt(e,d,n),G(),kt(e,d,n),Ht(e,d),Wt(e,d,n),cn(e,d),nn(e,d),rn(e,d),G(),an(d);for(let t=0;t<ti;t++)ni.forEach(t=>on(e,d,t,`ordered`)),on(e,d),on(e,d,void 0,`border`),G();G(),sn(e,d);for(let t=0;t<2;t++)Xt(e,d);sn(e,d),$t(e,d);for(let t=0;t<2;t++)en(e,d);return sn(e,d),G(),tn(e,d),Gt(c,d),Vt(e,d),At(e,d,n),on(e,d,void 0,`lattice`),d}function $r(e){if((e.children||[]).filter(e=>e.type===`bpmn:Participant`&&(e.children||[]).some(e=>!w(e))).length<2)return 0;let t=e=>[e,...(e.children||[]).flatMap(t)],n=/* @__PURE__ */ new Set;return t(e).forEach(e=>(e.outgoing||[]).forEach(e=>{let t=e;if(!_(t)||!t.source||!t.target)return;let r=v(t.source),i=v(t.target);r&&i&&r.id!==i.id&&(n.add(r.id),n.add(i.id))})),n.size}const ei=[{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!1},{exactOrder:!1,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!0,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!1},{exactOrder:!1,shortRoutes:!0,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!1,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!1,slidePools:!0,byChannel:!1,hugTarget:!0},{exactOrder:!1,shortRoutes:!1,slidePools:!1,byChannel:!0,hugTarget:!1},{exactOrder:!0,shortRoutes:!0,slidePools:!1,byChannel:!1,hugTarget:!0},{exactOrder:!0,shortRoutes:!0,slidePools:!0,byChannel:!1,hugTarget:!0}],ti=4,ni=[36,20],ri=[12,24,36,48],ii=[{upTo:60,plans:11},{upTo:120,plans:6},{upTo:1/0,plans:4}];function ai(e){let t=e=>(w(e)||j(e)?0:1)+(e.children||[]).reduce((e,n)=>e+t(n),0);return(e.children||[]).reduce((e,n)=>e+t(n),0)}async function oi(e,t,n={}){return xn(e),ae(n,()=>si(e,t))}async function si(e,t){let n=Dn(e),r=await Xr(e,t),i=$r(e),a=ii.find(t=>ai(e)<=t.upTo).plans,o=ei.filter(e=>(i>=2||!e.shortRoutes&&!e.slidePools&&!e.byChannel&&!e.hugTarget)&&(i>=3||!e.exactOrder)).slice(0,a),s=o[0],c=1/0,l=0;for(let[i,a]of o.entries()){if(i>0&&!oe())break;G(),await se();let{exactOrder:o,shortRoutes:u,slidePools:d,byChannel:f,hugTarget:p}=a,m=De(e,Qr(e,r,t,o,u,d,f,p,n)).energy;l++,m<c&&(c=m,s=a)}let u=Qr(e,r,t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n);if(Pe(e,u).containment>0){let i=Qr(e,r,t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n,!1,!1);Pe(e,i).containment===0&&(u=i)}let d=De(e,u),f=je(e,u),p=Me(e,u),m=Ne(u);if((d.merges>0||f>0||p>0)&&oe()){let i=t=>{let n=t;for(;n?.parent;)n=n.parent;return n??e},a=/* @__PURE__ */ new Map,o=e=>a.set(e,(a.get(e)??0)+1),c=u.routes.map(e=>e.waypoints);u.routes.forEach((e,t)=>{c.some((n,r)=>r!==t&&b(e.waypoints,n))&&(o(i(e.connection.source).id),o(i(e.connection.target).id))}),je(e,u,(e,t)=>{o(i(e.connection.source).id),o(i(e.connection.target).id),o(i(t).id)}),Me(e,u,e=>{o(i(e.connection.source).id),o(i(e.connection.target).id)});let h=[...a.entries()].sort((e,t)=>t[1]-e[1]).slice(0,4).map(([e])=>e),g,_=d.merges,v=f,y=p;for(let r of h)for(let i of ri){if(!oe())break;G(),await se();let a=Qr(e,await Xr(e,t,/* @__PURE__ */ new Set([r]),i),t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n);if(!Pe(e,a).ok)continue;let o=De(e,a),c=je(e,a),l=Me(e,a),u=Ne(a);if(!(o.merges<=d.merges&&c<=f&&l<=p&&u<=m&&o.crossings<=d.crossings))continue;let h=o.merges<_||c<v||l<y,b=o.merges<=_&&c<=v&&l<=y;if(h&&b&&(g=a,_=o.merges,v=c,y=l),o.merges<d.merges||c<f||l<p)break}let x=Qr(e,r,t,s.exactOrder,s.shortRoutes,s.slidePools,s.byChannel,s.hugTarget,n,!0);if(Pe(e,x).ok){let t=De(e,x),n=je(e,x),r=Me(e,x),i=Ne(x),a=t.merges<=d.merges&&n<=f&&r<=p&&i<=m&&t.crossings<=d.crossings+1,o=t.merges<_||n<v||r<y,s=t.merges<=_&&n<=v&&r<=y;a&&o&&s&&(g=x,_=t.merges,v=n,y=r)}if(g)return gn(e,g),Xt(e,g),ci(e,g,l)}return gn(e,u),Xt(e,u),ci(e,u,l)}function ci(e,t,n){return{...t,search:{candidates:n,energy:De(e,t).energy}}}const li=/* @__PURE__ */ new Set([`bpmn:Task`,`bpmn:UserTask`,`bpmn:ServiceTask`,`bpmn:ScriptTask`,`bpmn:BusinessRuleTask`,`bpmn:ManualTask`,`bpmn:SendTask`,`bpmn:ReceiveTask`,`bpmn:CallActivity`,`bpmn:SubProcess`,`bpmn:Transaction`,`bpmn:AdHocSubProcess`,`bpmn:ExclusiveGateway`,`bpmn:InclusiveGateway`,`bpmn:ParallelGateway`,`bpmn:EventBasedGateway`,`bpmn:ComplexGateway`,`bpmn:StartEvent`,`bpmn:EndEvent`,`bpmn:IntermediateCatchEvent`,`bpmn:IntermediateThrowEvent`,`bpmn:DataObjectReference`,`bpmn:DataStoreReference`,`bpmn:TextAnnotation`,`bpmn:Group`]),ui={"bpmn:SubProcess":{width:350,height:200},"bpmn:Transaction":{width:350,height:200},"bpmn:AdHocSubProcess":{width:350,height:200},"bpmn:ExclusiveGateway":{width:50,height:50},"bpmn:InclusiveGateway":{width:50,height:50},"bpmn:ParallelGateway":{width:50,height:50},"bpmn:EventBasedGateway":{width:50,height:50},"bpmn:ComplexGateway":{width:50,height:50},"bpmn:StartEvent":{width:36,height:36},"bpmn:EndEvent":{width:36,height:36},"bpmn:IntermediateCatchEvent":{width:36,height:36},"bpmn:IntermediateThrowEvent":{width:36,height:36},"bpmn:BoundaryEvent":{width:36,height:36},"bpmn:DataObjectReference":{width:36,height:50},"bpmn:DataStoreReference":{width:50,height:50},"bpmn:TextAnnotation":{width:100,height:30}};function di(e,t,n){e.moves.forEach(({elements:e,dx:t,dy:n})=>{e.forEach(e=>{e.x+=t,e.y+=n,e.label&&(e.label.x+=t,e.label.y+=n)})}),e.resizes.forEach(({element:e,x:t,y:n,width:r,height:i})=>{e.x=t,e.y=n,e.width=r,e.height=i}),e.routes.forEach(({connection:e,waypoints:t})=>{e.waypoints=t})}async function fi(e){let t=I(e,`utf8`),n=new L,{rootElement:r}=await n.fromXML(t);return pi(r,n,t)}function pi(e,t,n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;((e.diagrams?.[0])?.plane?.planeElement??[]).forEach(e=>{e.$type===`bpmndi:BPMNShape`&&e.bpmnElement&&r.set(e.bpmnElement.id,e),e.$type===`bpmndi:BPMNEdge`&&e.bpmnElement&&i.set(e.bpmnElement.id,e)});let a=/* @__PURE__ */ new Map,o=[],s=[],c=[],l=[],u=[];function d(e,t){let n=r.get(e.id),i=n?.bounds,s=ui[e.$type]??{width:100,height:80},c={id:e.id,type:e.$type,x:i?.x??0,y:i?.y??0,width:i?.width??s.width,height:i?.height??s.height,outgoing:[],attachers:[],children:[],parent:t,businessObject:e},l=n?.label?.bounds;return l&&(c.label={id:e.id+`_label`,type:`label`,x:l.x,y:l.y,width:l.width,height:l.height}),a.set(e.id,c),o.push(c),c}function f(e,t){e.forEach(e=>{let n=r.get(e.id)?.bounds,i={id:e.id,type:`bpmn:Lane`,x:n?.x??0,y:n?.y??0,width:n?.width??600,height:n?.height??200,parent:t,children:[],businessObject:e};t.children=[...t.children??[],i],o.push(i),a.set(e.id,i),(e.flowNodeRef??[]).forEach(t=>{let n=a.get(t.id);n&&(n.businessObject={...n.businessObject,lanes:[{id:e.id}]})}),e.childLaneSet?.lanes?.length&&f(e.childLaneSet.lanes,i)})}function p(e,t){(e.laneSets??[]).forEach(e=>f(e.lanes??[],t))}function m(e,t){[...e.ioSpecification?.dataInputs??[],...e.ioSpecification?.dataOutputs??[]].forEach(e=>{r.has(e.id)&&d(e,t)});let n=e.flowElements??[];n.forEach(e=>{if(e.$type===`bpmn:SequenceFlow`){c.push({flow:e,type:`bpmn:SequenceFlow`});return}if(e.$type===`bpmn:BoundaryEvent`||!li.has(e.$type))return;let n=d(e,t);[...e.ioSpecification?.dataInputs??[],...e.ioSpecification?.dataOutputs??[]].forEach(e=>{r.has(e.id)&&d(e,t)}),r.get(e.id)?.isExpanded!==!1&&(e.flowElements??[]).length>0&&m(e,n)}),n.forEach(e=>{e.$type===`bpmn:BoundaryEvent`&&u.push({be:e}),(e.dataInputAssociations??[]).forEach(t=>{let n=(t.sourceRef??[])[0];n&&l.push({flow:t,sourceRef:n,targetRef:e})}),(e.dataOutputAssociations??[]).forEach(t=>{t.targetRef&&l.push({flow:t,sourceRef:e,targetRef:t.targetRef})})}),(e.artifacts??[]).forEach(e=>{e.$type===`bpmn:Association`?c.push({flow:e,type:`bpmn:Association`}):li.has(e.$type)&&d(e,t)})}let h=(e.rootElements??[]).find(e=>e.$type===`bpmn:Collaboration`),g=(e.rootElements??[]).filter(e=>e.$type===`bpmn:Process`),_={id:`root`,type:`root`,x:0,y:0,width:0,height:0,children:[]};if(h&&h.participants?.length){_.children=h.participants.map(e=>{let t=r.get(e.id)?.bounds,n={id:e.id,type:`bpmn:Participant`,x:t?.x??0,y:t?.y??0,width:t?.width??600,height:t?.height??200,children:[]};return o.push(n),a.set(e.id,n),e.processRef&&(m(e.processRef,n),p(e.processRef,n)),n}),(h.artifacts??[]).forEach(e=>{e.$type===`bpmn:Association`?c.push({flow:e,type:`bpmn:Association`}):li.has(e.$type)&&d(e,_)}),(h.messageFlows??[]).forEach(e=>c.push({flow:e,type:`bpmn:MessageFlow`}));let e=new Set((h.participants??[]).map(e=>e.processRef?.id).filter(e=>!!e));g.filter(t=>!e.has(t.id)).forEach(e=>{m(e,_),p(e,_)})}else if(g.length){let e={id:g[0].id,type:`bpmn:Process`,x:0,y:0,width:0,height:0,children:[]};m(g[0],e),_.children=[e]}u.forEach(({be:e})=>{let t=a.get(e.attachedToRef?.id);if(!t)return;let n=r.get(e.id),i=n?.bounds,s=ui[`bpmn:BoundaryEvent`],c={id:e.id,type:`bpmn:BoundaryEvent`,x:i?.x??t.x,y:i?.y??t.y,width:i?.width??s.width,height:i?.height??s.height,outgoing:[],host:t,parent:t.parent,businessObject:{id:e.id,eventDefinitions:e.eventDefinitions}},l=n?.label?.bounds;l&&(c.label={id:e.id+`_label`,type:`label`,x:l.x,y:l.y,width:l.width,height:l.height}),a.set(e.id,c),o.push(c),t.attachers=[...t.attachers||[],c]}),l.forEach(({flow:e,sourceRef:t,targetRef:n})=>{c.push({flow:{...e,sourceRef:t,targetRef:n},type:`bpmn:DataAssociation`})});let v=/* @__PURE__ */ new Map;[...c.filter(({type:e})=>e!==`bpmn:Association`),...c.filter(({type:e})=>e===`bpmn:Association`)].forEach(({flow:e,type:t})=>{let n=e=>a.get(e??``)??v.get(e??``),r=n(e.sourceRef?.id),o=n(e.targetRef?.id);if(!r||!o)return;let c=i.get(e.id),l=(c?.waypoint??[]).map(e=>({x:e.x,y:e.y})),u={id:e.id,type:t,x:0,y:0,width:0,height:0,source:r,target:o,waypoints:l},d=c?.label?.bounds;d&&(u.label={id:e.id+`_label`,type:`label`,x:d.x,y:d.y,width:d.width,height:d.height}),r.outgoing=[...r.outgoing||[],u],o.incoming=[...o.incoming||[],u],v.set(u.id,u),s.push(u)});let y=e=>{e.children=o.filter(t=>t.parent===e),e.children.forEach(y)};_.children.forEach(y);let b=o.filter(e=>e.parent===_&&!_.children.includes(e));return b.length&&(_.children=[..._.children,...b]),{root:_.children.length===1&&_.children[0].type===`bpmn:Process`?_.children[0]:_,allNodes:o,allConnections:s,moddle:t,definitions:e,shapesById:r,edgesById:i,xml:n}}const mi=(e,t)=>e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y;function hi(e,t,n,r){let{allNodes:i,allConnections:a}=pi(e,t,``),o=/* @__PURE__ */ new Set,s=a.filter(e=>{let t=e.waypoints??[];if(t.length===0)return!1;let r=t.map(e=>e.x),i=t.map(e=>e.y),a={x:Math.min(...r),y:Math.min(...i),width:Math.max(...r)-Math.min(...r),height:Math.max(...i)-Math.min(...i)};return mi(a,n)});i.filter(e=>mi(e,n)).forEach(e=>o.add(e)),s.forEach(e=>{e.source&&o.add(e.source),e.target&&o.add(e.target)});let c=i.filter(e=>o.has(e)),l=new Set(s.map(e=>e.id)),u=a.filter(e=>l.has(e.id)&&o.has(e.source)&&o.has(e.target));return E(c,u,{settled:r}).defects.map(e=>`${e.kind}: ${e.detail}`)}async function gi(r,i={}){let{outPath:a,verbose:o=!1,asAuthored:s=!1,spacing:c}=i,l=e=>{o&&console.log(e)},{root:u,allNodes:d,allConnections:f,moddle:p,definitions:m,shapesById:h,edgesById:g,xml:_}=await fi(r),v={...Sn,...c},y=A(f),b=f.filter(e=>!y.includes(e));l(`file=${r}`),l(`nodes=${d.length} connections=${b.length}`);let x=k(d,f),S=Date.now();s||di(await oi(u,v,{limitMs:1/0}),f,d);let C=Date.now();l(`layoutTime=${C-S}ms`);let w=[],T=(e,t,n)=>{w.push({kind:e,detail:t,elements:n}),l(`${e}: ${t}`)},D=/* @__PURE__ */ new Set,O=e=>!e||h.has(e),j=/* @__PURE__ */ new Set;for(let e of _.matchAll(/<(?:\w+:)?(sequenceFlow|messageFlow|association)\s([^>]*)/g)){let t=/id="([^"]+)"/.exec(e[2])?.[1];if(!t)continue;let n=/sourceRef="([^"]+)"/.exec(e[2])?.[1],r=/targetRef="([^"]+)"/.exec(e[2])?.[1];!n||!r?j.add(t):D.add(t)}for(let e of _.matchAll(/<(?:\w+:)?(dataInputAssociation|dataOutputAssociation)\s([^>]*?)>([\s\S]*?)<\/(?:\w+:)?\1>/g)){let t=/id="([^"]+)"/.exec(e[2])?.[1];t&&([...e[3].matchAll(/<(?:\w+:)?(?:sourceRef|targetRef)>([^<]+)</g)].map(e=>e[1].trim()).some(e=>!O(e))||D.add(t))}let M=/* @__PURE__ */ new Set;[...h.entries()].filter(([,e])=>e?.isExpanded===!1).map(([e])=>e).forEach(e=>{let t=e=>{(e?.flowElements??[]).forEach(e=>{M.add(e.id),t(e)}),(e?.artifacts??[]).forEach(e=>M.add(e.id))},n=r=>{r&&typeof r==`object`&&(r.id===e&&t(r),[`rootElements`,`flowElements`].forEach(e=>(r[e]??[]).forEach(n)))};n(m)}),j.forEach(e=>T(`DANGLING-CONNECTION`,`${e}`,[e]));let N=new Set(f.map(e=>e.id)),P=0;D.forEach(e=>{N.has(e)||M.has(e)||(T(`LOST-CONNECTION`,`${e}`,[e]),P++)}),l(P===0?t(`app.output.noLostConnections`):n(P,`app.output.count.lostConnection`));let F=E(d,f,{before:x,modelDefects:w,log:o?e=>console.log(e):void 0});if(a){[...d,...u.children??[]].forEach(e=>{let t=h.get(e.id);t?.bounds&&(t.bounds.x=e.x,t.bounds.y=e.y,t.bounds.width=e.width,t.bounds.height=e.height,t.label?.bounds&&e.label&&(t.label.bounds.x=e.label.x,t.label.bounds.y=e.label.y))}),b.forEach(e=>{let t=g.get(e.id);t&&e.waypoints&&(t.waypoint=e.waypoints.map(e=>p.create(`dc:Point`,{x:e.x,y:e.y})),t.label?.bounds&&e.label&&(t.label.bounds.x=e.label.x,t.label.bounds.y=e.label.y))});let{xml:t}=await p.toXML(m,{format:!0});e(a,t)}return{file:r,...F,millis:C-S}}export{hi as a,gi as i,pi as n,fi as r,di as t};
|