@sentropic/design-system-elements 0.1.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE.THIRD-PARTY.md +44 -1
  2. package/README.md +123 -12
  3. package/catalog.json +401 -7
  4. package/dist/browser/chunks/{Modeler-BfAmwsmK.js → Modeler-D87tL_OJ.js} +4 -4
  5. package/dist/browser/chunks/Viewer-D9zjRrp2.js +4 -0
  6. package/dist/browser/chunks/bpmn-canvas-BevbP_6a.js +1 -0
  7. package/dist/browser/chunks/bpmn-mount-BhO_zb0S.js +2202 -0
  8. package/dist/browser/chunks/dist-DRauAwm2.js +6 -0
  9. package/dist/browser/chunks/{entropic-CM5BHERN.js → entropic-MwNVEq6w.js} +639 -0
  10. package/dist/browser/chunks/focus-renderer-BWm7DlQD.js +55 -0
  11. package/dist/browser/chunks/{forge-B8hrW4lA.js → forge-CzwO8Hbe.js} +639 -0
  12. package/dist/browser/chunks/layout-T3X333Za.js +1 -0
  13. package/dist/browser/elements.js +671 -6
  14. package/dist/browser/sri.json +52 -45
  15. package/dist/contracts/bar-chart.js +2 -2
  16. package/dist/contracts/decision-dossier.d.ts +4 -8
  17. package/dist/contracts/decision-dossier.js +8 -12
  18. package/dist/contracts/index.d.ts +1 -0
  19. package/dist/contracts/index.js +2 -0
  20. package/dist/contracts/time-series-chart.d.ts +49 -0
  21. package/dist/contracts/time-series-chart.js +37 -0
  22. package/dist/dossier/dossier-mount.js +845 -0
  23. package/dist/dossier/renderer/dossier.css +2 -0
  24. package/dist/element/bpmn-mount.d.ts +11 -0
  25. package/dist/element/bpmn-mount.js +56 -0
  26. package/dist/element/bpmn-types.d.ts +27 -0
  27. package/dist/element/bpmn-types.js +12 -0
  28. package/dist/element/bpmn.d.ts +10 -0
  29. package/dist/element/bpmn.js +39 -0
  30. package/dist/element/dom/dossier-mount.d.ts +25 -0
  31. package/dist/element/dom/dossier-review-mount.d.ts +25 -0
  32. package/dist/element/dom/dossier-review-state.svelte.d.ts +13 -0
  33. package/dist/element/dom/engines/bpmn-canvas.d.ts +11 -0
  34. package/dist/element/dom/engines/bpmn-canvas.js +11 -0
  35. package/dist/element/dom/engines/dossier-diagrams.d.ts +5 -0
  36. package/dist/element/dom/engines/dossier-evidence.d.ts +9 -0
  37. package/dist/element/dom/engines/dossier-styles.d.ts +21 -0
  38. package/dist/element/dom/engines/focus-renderer.d.ts +60 -0
  39. package/dist/element/dom/engines/focus-snapshot.d.ts +3 -0
  40. package/dist/element/dom/intents.d.ts +20 -0
  41. package/dist/element/markdown/minimal-markdown.d.ts +1 -2
  42. package/dist/element/markdown/minimal-markdown.js +19 -1
  43. package/dist/element/validator.d.ts +26 -0
  44. package/dist/element/validator.js +54 -0
  45. package/dist/focus-diagrams/diagram-layout.d.ts +140 -0
  46. package/dist/focus-diagrams/diagram-layout.js +190 -0
  47. package/dist/focus-diagrams/diagram-source.d.ts +11 -0
  48. package/dist/focus-diagrams/diagram-source.js +147 -0
  49. package/dist/focus-diagrams/dossier-views.d.ts +21 -0
  50. package/dist/focus-diagrams/dossier-views.js +57 -0
  51. package/dist/focus-diagrams/ecosystem.json +853 -0
  52. package/dist/focus-kit/index.html +13 -0
  53. package/dist/focus-kit/renderer/dossier.css +2 -0
  54. package/dist/focus-kit/renderer/dossier.js +845 -0
  55. package/dist/focus-kit-manifest.json +1 -0
  56. package/dist/focus-kit.d.ts +9 -0
  57. package/dist/focus-kit.js +30 -0
  58. package/dist/format-time-series-markdown.d.ts +5 -0
  59. package/dist/format-time-series-markdown.js +24 -0
  60. package/dist/generator/parity.js +6 -1
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.js +1 -0
  63. package/dist/ports/dossier-views.d.ts +3 -0
  64. package/dist/ports/dossier-views.js +3 -0
  65. package/dist/ports/focus.d.ts +0 -1
  66. package/dist/ports/types.d.ts +0 -1
  67. package/dist/shells/BarChart.html +8494 -0
  68. package/dist/shells/BarChart.js +8482 -0
  69. package/dist/shells/DecisionDossier.html +8502 -0
  70. package/dist/shells/DecisionDossier.js +8490 -0
  71. package/dist/shells/TimeSeriesChart.html +8475 -0
  72. package/dist/shells/TimeSeriesChart.js +8463 -0
  73. package/dist/shells/manifest.json +108 -0
  74. package/dist/structure/interpreter.d.ts +1 -1
  75. package/dist/structure/interpreter.js +14 -4
  76. package/dist/time-series.d.ts +13 -0
  77. package/dist/time-series.js +15 -0
  78. package/dist/validate/envelope.js +5 -1
  79. package/dist/validate/time-series.d.ts +5 -0
  80. package/dist/validate/time-series.js +28 -0
  81. package/fixtures/time-series-multi.json +46 -0
  82. package/fixtures/time-series-single.json +28 -0
  83. package/fixtures/time-series-thresholds.json +52 -0
  84. package/package.json +40 -6
  85. package/schemas/BarChart.v1.json +2 -2
  86. package/schemas/DecisionDossier.v1.json +155 -5
  87. package/schemas/TimeSeriesChart.v1.json +287 -0
  88. package/skill/SKILL.md +27 -0
  89. package/dist/browser/chunks/Viewer-eYLzc3fD.js +0 -4
  90. package/dist/browser/chunks/bpmn-canvas-DeAWdJFy.js +0 -2207
  91. package/dist/browser/chunks/dist-O6_2ByYB.js +0 -1
  92. package/dist/browser/chunks/focus-renderer-BgsZGo7n.js +0 -8
  93. package/dist/browser/chunks/layout-q0TR9-aY.js +0 -1
@@ -1 +0,0 @@
1
- export{g as BpmnModdle}from"./bpmn-canvas-DeAWdJFy.js";
@@ -1,8 +0,0 @@
1
- function e(e,t){this.v=e,this.k=t}function t(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function n(e){if(Array.isArray(e))return e}function r(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function i(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
2
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function a(e,t){return n(e)||r(e,t)||o(e,t)||i()}function o(e,n){if(e){if(typeof e==`string`)return t(e,n);var r={}.toString.call(e).slice(8,-1);return r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`?Array.from(e):r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}function s(t){var n,r;function i(n,r){try{var o=t[n](r),s=o.value,c=s instanceof e;Promise.resolve(c?s.v:s).then(function(e){if(c){var r=n===`return`&&s.k?n:`next`;if(!s.k||e.done)return i(r,e);e=t[r](e).value}a(!!o.done,e)},function(e){i(`throw`,e)})}catch(e){a(2,e)}}function a(e,t){e===2?n.reject(t):n.resolve({value:t,done:e}),(n=n.next)?i(n.key,n.arg):r=null}this._invoke=function(e,t){return new Promise(function(a,o){var s={key:e,arg:t,resolve:a,reject:o,next:null};r?r=r.next=s:(n=r=s,i(e,t))})},typeof t.return!=`function`&&(this.return=void 0)}s.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},s.prototype.next=function(e){return this._invoke(`next`,e)},s.prototype.throw=function(e){return this._invoke(`throw`,e)},s.prototype.return=function(e){return this._invoke(`return`,e)};var c=Object.entries,l=Object.setPrototypeOf,u=Object.isFrozen,d=Object.getPrototypeOf,f=Object.getOwnPropertyDescriptor,p=Object.freeze,m=Object.seal,h=Object.create,ee=typeof Reflect<`u`&&Reflect,g=ee.apply,te=ee.construct;p||=function(e){return e},m||=function(e){return e},g||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},te||=function(e){return new e(...[...arguments].slice(1))};var _=w(Array.prototype.forEach);Array.prototype.indexOf;var ne=w(Array.prototype.lastIndexOf),re=w(Array.prototype.pop),ie=w(Array.prototype.push),ae=w(Array.prototype.slice),oe=w(Array.prototype.splice),se=Array.isArray,ce=T(Set),le=w(Set.prototype.add),ue=w(Set.prototype.has),v=w(String.prototype.toLowerCase),de=w(String.prototype.toString),fe=w(String.prototype.match),pe=w(String.prototype.replace),me=w(String.prototype.indexOf),he=w(String.prototype.trim),ge=w(Number.prototype.toString),_e=w(Boolean.prototype.toString),y=typeof BigInt>`u`?null:w(BigInt.prototype.toString),ve=typeof Symbol>`u`?null:w(Symbol.prototype.toString),b=w(Object.prototype.hasOwnProperty),x=w(Object.prototype.toString),S=w(RegExp.prototype.test),C=T(TypeError);function w(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return g(e,t,n)}}function T(e){return function(){return te(e,[...arguments])}}function E(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:v;if(l&&l(e,null),!se(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(u(t)||(t[r]=e),i=e)}e[i]=!0}return e}function ye(e){for(let t=0;t<e.length;t++)b(e,t)||(e[t]=null);return e}function D(e){let t=h(null);for(let r of c(e)){var n=a(r,2);let i=n[0],o=n[1];b(e,i)&&(t[i]=se(o)?ye(o):o&&typeof o==`object`&&o.constructor===Object?D(o):o)}return t}function be(e){switch(typeof e){case`string`:return e;case`number`:return ge(e);case`boolean`:return _e(e);case`bigint`:return y?y(e):`0`;case`symbol`:return ve?ve(e):`Symbol()`;case`undefined`:return x(e);case`function`:case`object`:{if(e===null)return x(e);let t=e,n=O(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:x(e)}return x(e)}default:return x(e)}}function O(e,t){for(;e!==null;){let n=f(e,t);if(n){if(n.get)return w(n.get);if(typeof n.value==`function`)return w(n.value)}e=d(e)}function n(){return null}return n}function xe(e,t){for(;e!==null;){let n=f(e,t);if(n)return n.get?w(n.get):null;e=d(e)}return null}function Se(e){try{return S(e,``),!0}catch{return!1}}var Ce=p(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),we=p(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),Te=p([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),Ee=p([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),De=p(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),Oe=p([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),ke=p([`#text`]),Ae=p(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),je=p(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),Me=p(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),Ne=p([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Pe=m(/{{[\w\W]*|^[\w\W]*}}/g),Fe=m(/<%[\w\W]*|^[\w\W]*%>/g),Ie=m(/\${[\w\W]*/g),Le=m(/^data-[\-\w.\u00B7-\uFFFF]+$/),Re=m(/^aria-[\-\w]+$/),ze=m(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Be=m(/^(?:\w+script|data):/i),Ve=m(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),He=m(/^html$/i),Ue=m(/^[a-z][.\w]*(-[.\w]+)+$/i),We=m(/<[/\w!]/g),Ge=m(/<[/\w]/g),Ke=m(/<\/no(script|embed|frames)/i),qe=m(/\/>/i),k={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Je=p(E({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),Ye=function(){return typeof window>`u`?null:window},Xe=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Ze=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},A=function(e,t,n,r){return b(e,t)&&se(e[t])?E(r.base?D(r.base):{},e[t],r.transform):n},Qe=function(e,t,n){let r=b(e,t)?e[t]:void 0;return r&&typeof r==`object`?D(r):n()};function $e(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ye(),t=e=>$e(e);if(t.version=`3.4.17`,t.removed=[],!e||!e.document||e.document.nodeType!==k.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,l=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let u=e.DOMParser,d=e.trustedTypes,f=s.prototype,ee=O(f,`cloneNode`),g=O(f,`remove`),te=O(f,`removeAttributeNode`),ge=O(f,`nextSibling`),_e=O(f,`childNodes`),y=O(f,`parentNode`),ve=O(f,`shadowRoot`),x=O(f,`attributes`),w=o&&o.prototype?O(o.prototype,`nodeType`):null,T=o&&o.prototype?O(o.prototype,`nodeName`):null,ye=o&&o.prototype?O(o.prototype,`ownerDocument`):null,j=function(e){return w?w(e):e.nodeType},M=function(e){return T?T(e):e.nodeName},N=xe(f,`namespaceURI`),P=function(e){return N?N(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let F,I=``,et,tt=!1,nt=0,L=function(){if(nt>0)throw C(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},R=function(e){L(),nt++;try{return F.createHTML(e)}finally{nt--}},rt=function(e){L(),nt++;try{return F.createScriptURL(e)}finally{nt--}},it=function(){return tt||=(et=Xe(d,i),!0),et},at=n,ot=at.implementation,st=at.createNodeIterator,ct=at.createDocumentFragment,lt=at.getElementsByTagName,z=r.importNode,B=Ze();t.isSupported=typeof c==`function`&&typeof y==`function`&&ot&&ot.createHTMLDocument!==void 0;let ut=Pe,dt=Fe,ft=Ie,pt=Le,mt=Re,ht=Be,gt=Ve,_t=Ue,vt=ze,V=null,yt=E({},[...Ce,...we,...Te,...De,...ke]),H=null,bt=E({},[...Ae,...je,...Me,...Ne]),U=Object.seal(h(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),xt=null,St=null,W=Object.seal(h(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Ct=!0,wt=!0,Tt=!1,Et=!0,G=!1,K=!0,q=!1,Dt=!1,Ot=null,kt=null,At=!1,J=!1,Y=!1,jt=!1,Mt=!0,Nt=!1,Pt=`user-content-`,Ft=!0,It=!1,Lt=null,Rt={},zt=null,Bt=E({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Vt=null,Ht=E({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ut=null,Wt=E({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Gt=`http://www.w3.org/1998/Math/MathML`,Kt=`http://www.w3.org/2000/svg`,X=`http://www.w3.org/1999/xhtml`,qt=X,Jt=!1,Yt=null,Xt=E({},[Gt,Kt,X],de),Zt=p([`mi`,`mo`,`mn`,`ms`,`mtext`]),Qt=E({},Zt),$t=p([`annotation-xml`]),en=E({},$t),tn=E({},[`title`,`style`,`font`,`a`,`script`]),nn=null,rn=[`application/xhtml+xml`,`text/html`],Z=null,an=null,on=n.createElement(`form`),sn=function(e){return e instanceof RegExp||e instanceof Function},cn=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(an&&an===e)return;(!e||typeof e!=`object`)&&(e={}),e=D(e),nn=rn.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Z=nn===`application/xhtml+xml`?de:v,V=A(e,`ALLOWED_TAGS`,yt,{transform:Z}),H=A(e,`ALLOWED_ATTR`,bt,{transform:Z}),Yt=A(e,`ALLOWED_NAMESPACES`,Xt,{transform:de}),Ut=A(e,`ADD_URI_SAFE_ATTR`,Wt,{transform:Z,base:Wt}),Vt=A(e,`ADD_DATA_URI_TAGS`,Ht,{transform:Z,base:Ht}),zt=A(e,`FORBID_CONTENTS`,Bt,{transform:Z}),xt=A(e,`FORBID_TAGS`,D({}),{transform:Z}),St=A(e,`FORBID_ATTR`,D({}),{transform:Z}),Rt=b(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?D(e.USE_PROFILES):e.USE_PROFILES:!1,Ct=e.ALLOW_ARIA_ATTR!==!1,wt=e.ALLOW_DATA_ATTR!==!1,Tt=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Et=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,G=e.SAFE_FOR_TEMPLATES||!1,K=e.SAFE_FOR_XML!==!1,q=e.WHOLE_DOCUMENT||!1,J=e.RETURN_DOM||!1,Y=e.RETURN_DOM_FRAGMENT||!1,jt=e.RETURN_TRUSTED_TYPE||!1,At=e.FORCE_BODY||!1,Mt=e.SANITIZE_DOM!==!1,Nt=e.SANITIZE_NAMED_PROPS||!1,Ft=e.KEEP_CONTENT!==!1,It=e.IN_PLACE||!1,vt=Se(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:ze,qt=typeof e.NAMESPACE==`string`?e.NAMESPACE:X,Qt=Qe(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>E({},Zt)),en=Qe(e,`HTML_INTEGRATION_POINTS`,()=>E({},$t));let t=Qe(e,`CUSTOM_ELEMENT_HANDLING`,()=>h(null));if(U=h(null),b(t,`tagNameCheck`)&&sn(t.tagNameCheck)&&(U.tagNameCheck=t.tagNameCheck),b(t,`attributeNameCheck`)&&sn(t.attributeNameCheck)&&(U.attributeNameCheck=t.attributeNameCheck),b(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(U.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),m(U),G&&(wt=!1),Y&&(J=!0),Rt&&(V=E({},ke),H=h(null),Rt.html===!0&&(E(V,Ce),E(H,Ae)),Rt.svg===!0&&(E(V,we),E(H,je),E(H,Ne)),Rt.svgFilters===!0&&(E(V,Te),E(H,je),E(H,Ne)),Rt.mathMl===!0&&(E(V,De),E(H,Me),E(H,Ne))),W.tagCheck=null,W.attributeCheck=null,b(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?W.tagCheck=e.ADD_TAGS:se(e.ADD_TAGS)&&(V===yt&&(V=D(V)),E(V,e.ADD_TAGS,Z))),b(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?W.attributeCheck=e.ADD_ATTR:se(e.ADD_ATTR)&&(H===bt&&(H=D(H)),E(H,e.ADD_ATTR,Z))),b(e,`ADD_FORBID_CONTENTS`)&&se(e.ADD_FORBID_CONTENTS)&&(zt===Bt&&(zt=D(zt)),E(zt,e.ADD_FORBID_CONTENTS,Z)),Ft&&(V[`#text`]=!0),q&&E(V,[`html`,`head`,`body`]),V.table&&(E(V,[`tbody`]),delete xt.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw C(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw C(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=F;F=e.TRUSTED_TYPES_POLICY;try{I=R(``)}catch(e){throw F=t,e}}else e.TRUSTED_TYPES_POLICY===null?(F=void 0,I=``):(F===void 0&&(F=it()),F&&typeof I==`string`&&(I=R(``)));p&&p(e),an=e},ln=E({},[...we,...Te,...Ee]),un=E({},[...De,...Oe]),dn=function(e,t,n){return t.namespaceURI===X?e===`svg`:t.namespaceURI===Gt?e===`svg`&&(n===`annotation-xml`||Qt[n]):!!ln[e]},fn=function(e,t,n){return t.namespaceURI===X?e===`math`:t.namespaceURI===Kt?e===`math`&&en[n]:!!un[e]},pn=function(e,t,n){return t.namespaceURI===Kt&&!en[n]||t.namespaceURI===Gt&&!Qt[n]?!1:!un[e]&&(tn[e]||!ln[e])},mn=function(e){let t=P(e),n=v(M(e)),r=y(e),i,a;return r&&j(r)===k.element?(i={namespaceURI:P(r)},a=v(M(r))):(i={namespaceURI:qt},a=`template`),Yt[t]?t===Kt?dn(n,i,a):t===Gt?fn(n,i,a):t===X?pn(n,i,a):!!(nn===`application/xhtml+xml`&&Yt[t]):!1},hn=function(e){ie(t.removed,{element:e});try{y(e).removeChild(e)}catch{if(g(e),!y(e))throw C(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},gn=function(e,t,n){try{te(e,t)}catch{try{e.removeAttribute(n)}catch{}}},_n=function(e){xn(e);let t=_e(e);t&&_(ae(t),e=>{try{g(e)}catch{}});let n=j(e)===k.element?x(e):null;if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&gn(e,r,i)}},vn=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}ie(t.removed,{attribute:r||null,from:n});try{r?te(n,r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(J||Y)try{hn(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},yn=function(e){let t=x(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||H[Z(i)]||gn(e,r,i)}},bn=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&j(e)===k.element){let t=ve(e);Q(t)&&r.push(t)}let i=_e(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},xn=function(e){bn(e,e=>{j(e)===k.element&&yn(e)})},Sn=function(e){let t=[];return bn(e,e=>{t.push(e)},!0),t},Cn=function(e,t){let n=ce();_(Sn(e),e=>{j(e)===k.element&&le(n,e)}),_(t,e=>{j(e)===k.element&&!ue(n,e)&&yn(e)})},wn=function(e,n){let r=!1;return _(t.removed,t=>{t.element&&(r||=t.element===e,xn(t.element))}),Cn(e,n),r},Tn=function(e,t){let n=Lt,r=null,i=()=>(r||(r=ce(),_(t,e=>{le(r,e)})),r);for(let t=0;;t++){let r=Sn(e),a=[e],o=!1;if(_(r,e=>{j(e)===k.documentFragment?ie(a,e):!o&&!ue(n,e)&&(o=ue(i(),e))}),!o)return;if(t>=8)throw C(`the tree kept changing during in-place sanitization; refusing to return it`);_(a,(t,n)=>{En(t,n>0,e,i())})}},En=function(e,t,n,r){let i=jn(e),a;for(;a=i.nextNode();)ue(r,a)&&!ue(Lt,a)&&(t&&$(B.uponSanitizeShadowNode,a,null),Hn(a,n),Yn(a,n),Q(a.content)&&Xn(a.content))},Dn=function(e){Lt&&le(Lt,e)},On=function(e,t){return K?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},kn=function(e){K&&bn(e,e=>{let t=j(e);if(t===k.processingInstruction||t===k.comment&&S(Ge,e.data)){try{g(e)}catch{}return!1}if(t===k.element){let t=e,n=Z(M(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&On(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},An=function(e){let t=null,r=null;if(At)e=`<remove></remove>`+e;else{let t=fe(e,/^[\r\n\t ]+/);r=t&&t[0]}nn===`application/xhtml+xml`&&qt===X&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=F?R(e):e;if(qt===X)try{t=new u().parseFromString(i,nn)}catch{}if(!t||!t.documentElement){t=ot.createDocument(qt,`template`,null);try{t.documentElement.innerHTML=Jt?I:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),qt===X?lt.call(t,q?`html`:`body`)[0]:q?t.documentElement:a},jn=function(e){let t=ye?ye(e):e.ownerDocument;return st.call(t||e,e,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},Mn=function(e){return e=pe(e,ut,` `),e=pe(e,dt,` `),e=pe(e,ft,` `),e},Nn=function(e){Pn(e);let t=e.querySelectorAll?.call(e,`template`);t&&_(t,e=>{Q(e.content)&&Nn(e.content)})},Pn=function(e){e.normalize();let t=ye?ye(e):e.ownerDocument,n=st.call(t||e,e,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=Mn(r.data),r=n.nextNode()},Fn=function(e){let t=T?T(e):null;return typeof t!=`string`||Z(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==x(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==w(e)||e.childNodes!==_e(e)},Q=function(e){if(!w||typeof e!=`object`||!e)return!1;try{return w(e)===k.documentFragment}catch{return!1}},In=function(e){if(!w||typeof e!=`object`||!e)return!1;try{return typeof w(e)==`number`}catch{return!1}};function $(e,n,r){e.length!==0&&_(e,e=>{e.call(t,n,r,an)})}let Ln=function(e,t){return!!(K&&e.hasChildNodes()&&!In(e.firstElementChild)&&S(We,e.textContent)&&S(We,e.innerHTML)||K&&Je[t]&&j(e)===k.element&&P(e)===X&&(In(e.firstElementChild)||typeof e.textContent==`string`&&S(We,e.textContent))||e.nodeType===k.processingInstruction||K&&e.nodeType===k.comment&&S(Ge,e.data))},Rn=function(e,t){return e instanceof RegExp?S(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},zn=function(e,t,n){if(!xt[t]&&Gn(t)&&Rn(U.tagNameCheck,t))return!1;if(Ft&&!zt[t]&&!zt[v(t)]){let t=y(e),r=_e(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?ee(r[a],!0):r[a];t.insertBefore(i,ge(e))}}}return hn(e),!0},Bn=function(e,t,n,r){return e.length===0?t:t===n||t===r?D(t):t},Vn=function(e,t){return e===t||y(e)!==null?!1:(It&&xn(e),!0)},Hn=function(e,n){if(Dn(e),$(B.beforeSanitizeElements,e,null),Vn(e,n))return!0;if(Fn(e))return hn(e),!0;let r=Z(M(e));if(V=Bn(B.uponSanitizeElement,V,yt,Ot),$(B.uponSanitizeElement,e,{tagName:r,allowedTags:V}),Vn(e,n))return!0;if(Ln(e,r))return hn(e),!0;if(xt[r]||!(W.tagCheck instanceof Function&&W.tagCheck(r))&&!V[r]){let t=zn(e,r,n);return t===!1&&($(B.afterSanitizeElements,e,null),Vn(e,n))?!0:t}if(j(e)===k.element&&!mn(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&S(Ke,e.innerHTML))return hn(e),!0;if(G&&e.nodeType===k.text){let n=Mn(e.textContent);e.textContent!==n&&(ie(t.removed,{element:e.cloneNode()}),e.textContent=n)}return $(B.afterSanitizeElements,e,null),Vn(e,n)},Un=function(e,t,r){if(St[t]||On(t,e)||Mt&&(t===`id`||t===`name`)&&(r in n||r in on))return!1;let i=H[t]||W.attributeCheck instanceof Function&&W.attributeCheck(t,e);return wt&&S(pt,t)||Ct&&S(mt,t)?!0:i?Ut[t]||S(vt,pe(r,gt,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&me(r,`data:`)===0&&Vt[e]||Tt&&!S(ht,pe(r,gt,``))?!0:!r:Gn(e)&&Rn(U.tagNameCheck,e)&&Rn(U.attributeNameCheck,t,e)||t===`is`&&U.allowCustomizedBuiltInElements&&Rn(U.tagNameCheck,r)},Wn=E({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Gn=function(e){return!Wn[v(e)]&&S(_t,e)},Kn=function(e,t,n,r){if(F&&typeof d==`object`&&typeof d.getAttributeType==`function`&&!n)switch(d.getAttributeType(e,t)){case`TrustedHTML`:return R(r);case`TrustedScriptURL`:return rt(r)}return r},qn=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Fn(e)||(hn(e),!1)}catch{return vn(t,e),!1}},Jn=function(e,t){return K&&S(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,t)?!0:v(e)===`attributename`&&fe(t,`href`)!==null},Yn=function(e,n){if($(B.beforeSanitizeAttributes,e,null),Vn(e,n))return;let r=e.attributes;if(!r||Fn(e))return;H=Bn(B.uponSanitizeAttribute,H,bt,kt);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:H,forceKeepAttr:void 0},a=r.length,o=Z(e.nodeName);for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=Z(s),d=l,f=s===`value`?d:he(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,$(B.uponSanitizeAttribute,e,i),f=i.attrValue,Nt&&(u===`id`||u===`name`)&&me(f,Pt)!==0&&(vn(s,e,n),f=Pt+f,p=!0),Jn(s,f)?vn(s,e,n):i.forceKeepAttr||(i.keepAttr?!Et&&S(qe,f)?vn(s,e,n):(G&&(f=Mn(f)),Un(o,u,f)?(f=Kn(o,u,c,f),f!==d&&qn(e,s,c,f)&&p&&re(t.removed)):vn(s,e,n)):vn(s,e,n))}$(B.afterSanitizeAttributes,e,null),Vn(e,n)},Xn=function(e){let t=null,n=jn(e);for($(B.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if($(B.uponSanitizeShadowNode,t,null),Hn(t,e),Yn(t,e),Q(t.content)&&Xn(t.content),j(t)===k.element){let e=ve(t);Q(e)&&(Zn(e),Xn(e))}G&&Pn(e),$(B.afterSanitizeShadowDOM,e,null)},Zn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Xn(e.shadow);continue}let n=e.node,r=j(n)===k.element,i=_e(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=T?T(n):null;if(typeof e==`string`&&Z(e)===`template`){let e=n.content;Q(e)&&t.push({node:e,shadow:null})}}if(r){let e=ve(n);Q(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Jt=!e,Jt&&(e=`<!-->`),typeof e!=`string`&&!In(e)&&(e=be(e),typeof e!=`string`))throw C(`dirty is not a string, aborting`);if(!t.isSupported)return e;Dt?(V=Ot,H=kt):cn(n),(B.uponSanitizeElement.length>0||B.uponSanitizeAttribute.length>0)&&(V=D(V)),B.uponSanitizeAttribute.length>0&&(H=D(H)),t.removed=[];let c=It&&typeof e!=`string`&&In(e),l=[],u=Lt;if(c){kn(e);let t=M(e);if(typeof t==`string`){let n=Z(t);if(!V[n]||xt[n])throw _n(e),C(`root node is forbidden and cannot be sanitized in-place`)}if(Fn(e))throw _n(e),C(`root node is clobbered and cannot be sanitized in-place`);l=Sn(e),Lt=ce()}else if(In(e))i=An(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===k.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Zn(i);else{if(!J&&!G&&!q&&e.indexOf(`<`)===-1)return F&&jt?R(e):e;if(i=An(e),!i)return J?null:jt?I:``}i&&At&&hn(i.firstChild);let d=c?e:i;try{c&&Zn(e);let t=jn(d);for(;o=t.nextNode();)Hn(o,d),Yn(o,d),Q(o.content)&&Xn(o.content);c&&Tn(e,l)}catch(t){throw c&&(_n(e),wn(e,l)),t}finally{Lt=u}if(c){if(wn(e,l))throw C(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return G&&Nn(e),e}if(J){if(G&&Nn(i),Y)for(s=ct.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(H.shadowroot||H.shadowrootmode)&&(s=z.call(r,s,!0)),s}let f=q?i.outerHTML:i.innerHTML;return q&&V[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&S(He,i.ownerDocument.doctype.name)&&(f=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
3
- `+f),G&&(f=Mn(f)),F&&jt?R(f):f},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};cn(e),Dt=!0,Ot=V,kt=H},t.clearConfig=function(){an=null,Dt=!1,Ot=null,kt=null,F=et,I=``},t.isValidAttribute=function(e,t,n){an||cn({});let r=Z(e),i=Z(t);return typeof n==`string`&&(Jn(t,n)||!Et&&S(qe,n))?!1:Un(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&b(B,e)&&ie(B[e],t)},t.removeHook=function(e,t){if(b(B,e)){if(t!==void 0){let n=ne(B[e],t);return n===-1?void 0:oe(B[e],n,1)[0]}return re(B[e])}},t.removeHooks=function(e){b(B,e)&&(B[e]=[])},t.removeAllHooks=function(){B=Ze()},t}var j=$e(),M=class extends Error{issue;constructor(e){super(e.message),this.issue=e}},N=(e,t,n)=>{throw new M({path:e,code:t,message:n})};function P(e,t,n,r=[]){(!e||typeof e!=`object`||Array.isArray(e))&&N(t,`invalid_evidence`,`Expected a closed object`);let i=e;for(let e of Object.keys(i))[...n,...r].includes(e)||N(`${t}.${e}`,`invalid_evidence`,`Unknown evidence field`);for(let e of n)Object.hasOwn(i,e)||N(`${t}.${e}`,`invalid_evidence`,`Missing evidence field`);return i}function F(e,t,n=!1){return(typeof e!=`string`||!n&&!e.trim())&&N(t,`invalid_evidence`,`Expected a non-empty string`),e}function I(e,t){return Array.isArray(e)||N(t,`invalid_evidence`,`Expected an array`),e}var et=(e,t)=>I(e,t).map((e,n)=>F(e,`${t}[${n}]`));function tt(e,t){let n=t=>new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(t);if(t===`image/png`){if(e.length>=33&&[137,80,78,71,13,10,26,10].every((t,n)=>e[n]===t)&&n(8)===13&&n(12)===1229472850)return[n(16),n(20)]}else if(e[0]===255&&e[1]===216){let t=2;for(;t+4<e.length&&e[t]===255;){let n=e[t+1],r=e[t+2]<<8|e[t+3];if(r<2||t+2+r>e.length)break;if([192,193,194,195,197,198,199,201,202,203,205,206,207].includes(n)&&r>=8)return[e[t+7]<<8|e[t+8],e[t+5]<<8|e[t+6]];t+=r+2}}}var nt=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],L=(e,t)=>e>>>t|e<<32-t;function R(e){let t=new Uint8Array(Math.ceil((e.length+9)/64)*64);t.set(e),t[e.length]=128;let n=new DataView(t.buffer),r=e.length*8;n.setUint32(t.length-8,Math.floor(r/4294967296)),n.setUint32(t.length-4,r>>>0);let i=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],a=new Int32Array(64);for(let e=0;e<t.length;e+=64){for(let t=0;t<16;t++)a[t]=n.getInt32(e+t*4);for(let e=16;e<64;e++){let t=a[e-15],n=a[e-2];a[e]=a[e-16]+(L(t,7)^L(t,18)^t>>>3)+a[e-7]+(L(n,17)^L(n,19)^n>>>10)}let[t,r,o,s,c,l,u,d]=i;for(let e=0;e<64;e++){let n=d+(L(c,6)^L(c,11)^L(c,25))+(c&l^~c&u)+nt[e]+a[e]|0,i=(L(t,2)^L(t,13)^L(t,22))+(t&r^t&o^r&o)|0;d=u,u=l,l=c,c=s+n|0,s=o,o=r,r=t,t=n+i|0}[t,r,o,s,c,l,u,d].forEach((e,t)=>{i[t]=i[t]+e|0})}return i.map(e=>(e>>>0).toString(16).padStart(8,`0`)).join(``)}function rt(e){if(e.length%4||/[^A-Za-z0-9+/]/.test(e.replace(/={1,2}$/,``)))throw Error(`Invalid base64`);let t=atob(e);if(btoa(t)!==e)throw Error(`Non-canonical base64`);let n=new Uint8Array(t.length);for(let e=0;e<n.length;e++)n[e]=t.charCodeAt(e);return n}var it=e=>new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(e),at=e=>e.split(/\r\n|\n|\r/),ot=e=>/^text\/[a-z0-9.+-]+$/.test(e)||[`application/json`,`application/yaml`,`application/x-yaml`,`application/x-ndjson`].includes(e);function st(e,t){let n=new Map;return{sources:I(e,`$.sources`).map((e,r)=>{let i=`$.sources[${r}]`,a=P(e,i,[`id`,`title`,`origin`,`mediaType`,`encoding`,`data`,`sha256`,`size`],[`width`,`height`,`alt`]);for(let e of[`id`,`title`,`mediaType`,`sha256`])F(a[e],`${i}.${e}`);t(a.id,`${i}.id`);let o=a.origin,s=o&&Object.hasOwn(o,`uri`)?[`uri`]:[`repo`,`revision`,`path`];P(o,`${i}.origin`,s);for(let e of s)F(o[e],`${i}.origin.${e}`);a.encoding!==`base64`&&N(`${i}.encoding`,`source_encoding`,`Only original base64 bytes are accepted`);let c=a.mediaType;!ot(c)&&![`image/png`,`image/jpeg`].includes(c)&&N(`${i}.mediaType`,`unsupported_media`,`Unsupported media for source ${a.id}`);let l;try{l=rt(F(a.data,`${i}.data`,!0))}catch{return N(`${i}.data`,`source_encoding`,`Invalid base64 for source ${a.id}`)}if((!Number.isSafeInteger(a.size)||a.size!==l.length)&&N(`${i}.size`,`source_size`,`Byte size mismatch for source ${a.id}`),(!/^[a-f0-9]{64}$/.test(a.sha256)||R(l)!==a.sha256)&&N(`${i}.sha256`,`source_digest`,`SHA-256 mismatch for source ${a.id}`),ot(c)){try{n.set(a.id,at(it(l)).length)}catch{N(`${i}.data`,`source_encoding`,`Invalid UTF-8 for source ${a.id}`)}for(let e of[`width`,`height`,`alt`])a[e]!==void 0&&N(`${i}.${e}`,`invalid_evidence`,`Image metadata on text`)}else{F(a.alt,`${i}.alt`);let e=tt(l,c);(!e||!Number.isSafeInteger(a.width)||!Number.isSafeInteger(a.height)||e[0]<=0||e[1]<=0||e[0]!==a.width||e[1]!==a.height)&&N(i,`image_metadata`,`Image dimensions/signature mismatch for source ${a.id}`)}return a}),lineCounts:n}}function ct(e,t){try{let{schemaVersion:n,sources:r,citations:i,evidenceGroups:a,annexes:o,...s}=e,c=new Map,l=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return e;let{citationRefs:n,...r}=e;return n!==void 0&&c.set(t,et(n,`${t}.citationRefs`)),r};Array.isArray(s.sections)&&(s.sections=s.sections.map((e,t)=>{let n=l(e,`$.sections[${t}]`);return n?.kind===`optionSet`&&Array.isArray(n.options)?{...n,options:n.options.map((e,n)=>l(e,`$.sections[${t}].options[${n}]`))}:n}));let u=t(s);if(!u.ok)return u;let d=u.value,f=new Set,p=new Set([d.ref]),m=(e,t)=>{f.has(e)&&N(t,`duplicate_id`,`Duplicate id ${e}`),f.add(e)};d.sections.forEach(e=>{m(e.id,`$.sections`),p.add(e.id),p.add(e.targetRef),e.kind===`optionSet`&&e.options.forEach(e=>{m(e.id,`$.sections.options`),p.add(e.id),p.add(e.targetRef)})});let{sources:h,lineCounts:ee}=st(r,m),g=new Map(h.map(e=>[e.id,e])),te=I(i,`$.citations`).map((e,t)=>{let n=`$.citations[${t}]`,r=P(e,n,[`id`,`sourceId`,`label`,`locator`]);for(let e of[`id`,`sourceId`,`label`])F(r[e],`${n}.${e}`);m(r.id,`${n}.id`);let i=g.get(r.sourceId)??N(`${n}.sourceId`,`unresolved_source`,`Unknown source ${r.sourceId}`),a=r.locator;return a?.kind===`lines`?(P(a,`${n}.locator`,[`kind`,`start`,`end`]),ee.has(i.id)||N(`${n}.locator`,`citation_media`,`Source ${i.id} is not text`),(!Number.isSafeInteger(a.start)||!Number.isSafeInteger(a.end)||a.start<1||a.end<a.start||a.end>ee.get(i.id))&&N(`${n}.locator`,`citation_range`,`Invalid inclusive line range for ${i.id}`)):a?.kind===`image`?(P(a,`${n}.locator`,[`kind`,`caption`]),F(a.caption,`${n}.locator.caption`),i.mediaType.startsWith(`image/`)||N(`${n}.locator`,`citation_media`,`Source ${i.id} is not an image`)):N(`${n}.locator`,`invalid_evidence`,`Unknown citation locator`),r}),_=new Set(te.map(e=>e.id)),ne=(e,t,n,r)=>{let i=et(e,t);for(let e of i)n.has(e)||N(t,r,`Unresolved reference ${e}`);return i};for(let[e,t]of c)ne(t,`${e}.citationRefs`,_,`unresolved_citation`);let re=I(a,`$.evidenceGroups`).map((e,t)=>{let n=`$.evidenceGroups[${t}]`,r=P(e,n,[`id`,`summary`,`citationRefs`,`sourceRefs`]);return m(F(r.id,`${n}.id`),`${n}.id`),F(r.summary,`${n}.summary`),ne(r.citationRefs,`${n}.citationRefs`,_,`unresolved_citation`),ne(r.sourceRefs,`${n}.sourceRefs`,new Set(g.keys()),`unresolved_source`),r}),ie=I(o,`$.annexes`).map((e,t)=>{let n=`$.annexes[${t}]`,r=P(e,n,[`id`,`title`,`summary`,`blocks`,`backRefs`]);return m(F(r.id,`${n}.id`),`${n}.id`),F(r.title,`${n}.title`),F(r.summary,`${n}.summary`),ne(r.backRefs,`${n}.backRefs`,p,`unresolved_target`),I(r.blocks,`${n}.blocks`).forEach((e,t)=>{let r=`${n}.blocks[${t}]`,i=e?.kind;if(i===`text`||i===`code`){let t=P(e,r,[`kind`,`text`],i===`code`?[`language`]:[]);F(t.text,`${r}.text`,!0),t.language!==void 0&&F(t.language,`${r}.language`)}else if(i===`table`){let t=P(e,r,[`kind`,`columns`,`rows`]),n=et(t.columns,`${r}.columns`);n.length||N(r,`invalid_evidence`,`A table needs columns`),I(t.rows,`${r}.rows`).forEach((e,t)=>{let i=I(e,`${r}.rows[${t}]`);i.forEach((e,n)=>F(e,`${r}.rows[${t}][${n}]`,!0)),i.length!==n.length&&N(r,`invalid_evidence`,`Table row width mismatch`)})}else if(i===`references`){let t=P(e,r,[`kind`,`citationRefs`]);ne(t.citationRefs,`${r}.citationRefs`,_,`unresolved_citation`)}else N(`${r}.kind`,`invalid_evidence`,`Unsupported annex block (no decisions or active content)`)}),r}),ae=(e,t)=>c.has(t)?{...e,citationRefs:c.get(t)}:e,oe=d.sections.map((e,t)=>ae(e.kind===`optionSet`?{...e,options:e.options.map((e,n)=>ae(e,`$.sections[${t}].options[${n}]`))}:e,`$.sections[${t}]`));return{ok:!0,value:{...d,schemaVersion:2,sections:oe,sources:h,citations:te,evidenceGroups:re,annexes:ie}}}catch(e){if(e instanceof M)return{ok:!1,issues:[e.issue]};throw e}}var lt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),z=(e,t,n)=>({path:e,code:t,message:n}),B=(e,t,n,r,i,a)=>{if(!lt(e)){a.push(z(t,`invalid_type`,`expected an object`));return}let o=new Set(n);for(let n of Object.keys(e))o.has(n)||a.push(z(`${t}.${n}`,`unknown_field`,`field not in the closed schema`));for(let n of r)e[n]===void 0&&a.push(z(`${t}.${n}`,`missing_field`,`required field is missing`));for(let n of i)e[n]!==void 0&&typeof e[n]!=`string`&&a.push(z(`${t}.${n}`,`invalid_type`,`expected a string`));return e},ut=(e,t,n,r)=>{(typeof e!=`string`||!n.includes(e))&&r.push(z(t,`invalid_enum`,`expected one of: ${n.join(` | `)}`))},dt=[`ref`,`subject`,`title`,`hash`,`cursor`,`sections`,`interactions`,`provenance`,`amendmentTrace`],ft=[`ref`,`subject`,`title`,`hash`,`cursor`],pt=[...dt,`readability`],mt=(e,t,n)=>{let r=n.length,i=B(e,t,[`kind`,`id`,`targetRef`,`label`,`body`,`annotation`,`annotationComment`,`consequence`],[`kind`,`id`,`targetRef`,`label`,`annotation`],[`id`,`targetRef`,`label`,`body`,`annotationComment`,`consequence`],n);if(i!==void 0&&(i.kind!==`option`&&n.push(z(`${t}.kind`,`invalid_discriminator`,`expected "option"`)),ut(i.annotation,`${t}.annotation`,[`none`,`accept`,`reject`,`comment`],n),n.length===r))return{kind:`option`,id:i.id,targetRef:i.targetRef,label:i.label,...typeof i.body==`string`?{body:i.body}:{},annotation:i.annotation,...typeof i.annotationComment==`string`?{annotationComment:i.annotationComment}:{},...typeof i.consequence==`string`?{consequence:i.consequence}:{}}},ht=(e,t,n)=>{let r=n.length,i=B(e,t,[`at`,`author`,`summary`],[`at`,`author`,`summary`],[`at`,`author`,`summary`],n);if(i!==void 0&&n.length===r)return{at:i.at,author:i.author,summary:i.summary}},gt=(e,t,n)=>{if(!lt(e)){n.push(z(t,`invalid_type`,`expected an object`));return}let r=e.kind;if(r!==`prose`&&r!==`question`&&r!==`optionSet`&&r!==`outcome`&&r!==`amendmentTrace`&&r!==`diagram`){n.push(z(`${t}.kind`,r===void 0?`missing_field`:`unknown_node_kind`,`unknown section kind ${typeof r==`string`?`"${r}"`:` discriminant`}`));return}let i=n.length;switch(r){case`prose`:{let r=B(e,t,[`kind`,`id`,`targetRef`,`markdown`,`questionId`],[`kind`,`id`,`targetRef`,`markdown`],[`id`,`targetRef`,`markdown`,`questionId`],n);return r===void 0||n.length!==i?void 0:{kind:`prose`,id:r.id,targetRef:r.targetRef,markdown:r.markdown,...typeof r.questionId==`string`?{questionId:r.questionId}:{}}}case`question`:{let r=B(e,t,[`kind`,`id`,`targetRef`,`question`,`recommendedAnswer`,`answer`,`state`,`context`,`readingTimeMinutes`,`recommendedOptionId`],[`kind`,`id`,`targetRef`,`question`,`state`],[`id`,`targetRef`,`question`,`recommendedAnswer`,`answer`,`context`,`recommendedOptionId`],n);return r===void 0||(ut(r.state,`${t}.state`,[`open`,`answered`,`validated`],n),r.readingTimeMinutes!==void 0&&(typeof r.readingTimeMinutes!=`number`||!Number.isFinite(r.readingTimeMinutes))&&n.push(z(`${t}.readingTimeMinutes`,`invalid_type`,`expected a finite number`)),n.length!==i)?void 0:{kind:`question`,id:r.id,targetRef:r.targetRef,question:r.question,...typeof r.recommendedAnswer==`string`?{recommendedAnswer:r.recommendedAnswer}:{},...typeof r.answer==`string`?{answer:r.answer}:{},state:r.state,...typeof r.context==`string`?{context:r.context}:{},...typeof r.recommendedOptionId==`string`?{recommendedOptionId:r.recommendedOptionId}:{},...typeof r.readingTimeMinutes==`number`?{readingTimeMinutes:r.readingTimeMinutes}:{}}}case`optionSet`:{let r=B(e,t,[`kind`,`id`,`targetRef`,`title`,`options`,`questionId`],[`kind`,`id`,`targetRef`,`options`],[`id`,`targetRef`,`title`,`questionId`],n);if(r===void 0)return;let a=[];return Array.isArray(r.options)?r.options.forEach((e,r)=>{let i=mt(e,`${t}.options[${r}]`,n);i!==void 0&&a.push(i)}):n.push(z(`${t}.options`,`invalid_type`,`expected an array`)),n.length===i?{kind:`optionSet`,id:r.id,targetRef:r.targetRef,...typeof r.title==`string`?{title:r.title}:{},options:a,...typeof r.questionId==`string`?{questionId:r.questionId}:{}}:void 0}case`outcome`:{let r=B(e,t,[`kind`,`id`,`targetRef`,`modality`,`statement`,`questionId`],[`kind`,`id`,`targetRef`,`modality`,`statement`],[`id`,`targetRef`,`statement`,`questionId`],n);return r===void 0||(ut(r.modality,`${t}.modality`,[`decision`,`orientation`,`amendment`,`comment`],n),n.length!==i)?void 0:{kind:`outcome`,id:r.id,targetRef:r.targetRef,modality:r.modality,statement:r.statement,...typeof r.questionId==`string`?{questionId:r.questionId}:{}}}case`amendmentTrace`:{let r=B(e,t,[`kind`,`id`,`targetRef`,`steps`],[`kind`,`id`,`targetRef`,`steps`],[`id`,`targetRef`],n);if(r===void 0)return;let a=[];return Array.isArray(r.steps)?r.steps.forEach((e,r)=>{let i=ht(e,`${t}.steps[${r}]`,n);i!==void 0&&a.push(i)}):n.push(z(`${t}.steps`,`invalid_type`,`expected an array`)),n.length===i?{kind:`amendmentTrace`,id:r.id,targetRef:r.targetRef,steps:a}:void 0}case`diagram`:{let r=B(e,t,[`kind`,`id`,`targetRef`,`syntax`,`source`,`alt`,`scene`],[`kind`,`id`,`targetRef`,`syntax`,`source`,`alt`],[`id`,`targetRef`,`source`,`alt`],n);return r===void 0||(ut(r.syntax,`${t}.syntax`,[`mermaid`,`plantuml`],n),r.scene!==void 0&&!lt(r.scene)&&n.push(z(`${t}.scene`,`invalid_type`,`expected a diagram-core SemanticDocument object`)),n.length!==i)?void 0:{kind:`diagram`,id:r.id,targetRef:r.targetRef,syntax:r.syntax,source:r.source,alt:r.alt,...r.scene===void 0?{}:{scene:r.scene}}}}},_t=(e,t,n)=>{let r=n.length,i=B(e,t,[`name`,`targetRef`,`label`,`enabled`],[`name`,`targetRef`,`label`,`enabled`],[`name`,`targetRef`,`label`],n);if(i!==void 0&&(i.enabled!==!1&&n.push(z(`${t}.enabled`,`enabled_action`,`snapshot interactions must stay disabled (enabled:false)`)),n.length===r))return{name:i.name,targetRef:i.targetRef,label:i.label,enabled:!1}},vt=(e,t,n)=>{let r=n.length,i=B(e,t,[`term`,`definition`],[`term`,`definition`],[`term`,`definition`],n);if(i!==void 0&&n.length===r)return{term:i.term,definition:i.definition}},V=(e,t,n)=>{let r=n.length,i=B(e,t,[`ownerRequestQuote`,`noOwnerRequest`,`stakes`,`stakesLevel`,`readingBudgetMinutes`,`glossary`],[],[`ownerRequestQuote`,`stakes`],n);if(i===void 0)return;i.stakesLevel!==void 0&&ut(i.stakesLevel,`${t}.stakesLevel`,[`low`,`medium`,`high`],n),i.noOwnerRequest!==void 0&&typeof i.noOwnerRequest!=`boolean`&&n.push(z(`${t}.noOwnerRequest`,`invalid_type`,`expected a boolean`)),i.readingBudgetMinutes!==void 0&&(typeof i.readingBudgetMinutes!=`number`||!Number.isFinite(i.readingBudgetMinutes))&&n.push(z(`${t}.readingBudgetMinutes`,`invalid_type`,`expected a finite number`));let a;if(i.glossary!==void 0&&(a=[],Array.isArray(i.glossary)?i.glossary.forEach((e,r)=>{let i=vt(e,`${t}.glossary[${r}]`,n);i!==void 0&&a.push(i)}):n.push(z(`${t}.glossary`,`invalid_type`,`expected an array`))),n.length===r)return{...typeof i.ownerRequestQuote==`string`?{ownerRequestQuote:i.ownerRequestQuote}:{},...typeof i.noOwnerRequest==`boolean`?{noOwnerRequest:i.noOwnerRequest}:{},...typeof i.stakes==`string`?{stakes:i.stakes}:{},...i.stakesLevel===void 0?{}:{stakesLevel:i.stakesLevel},...typeof i.readingBudgetMinutes==`number`?{readingBudgetMinutes:i.readingBudgetMinutes}:{},...a===void 0?{}:{glossary:a}}},yt=e=>{let t=[],n=B(e,`$`,[...pt],[...dt],[...ft],t);if(n===void 0)return{ok:!1,issues:t};let r=[];Array.isArray(n.sections)?n.sections.forEach((e,n)=>{let i=gt(e,`$.sections[${n}]`,t);i!==void 0&&r.push(i)}):t.push(z(`$.sections`,`invalid_type`,`expected an array`));let i=[];Array.isArray(n.interactions)?n.interactions.forEach((e,n)=>{let r=_t(e,`$.interactions[${n}]`,t);r!==void 0&&i.push(r)}):t.push(z(`$.interactions`,`invalid_type`,`expected an array`));let a,o=B(n.provenance,`$.provenance`,[`source`,`readAt`,`comprehensionEvidence`],[`source`,`readAt`],[`source`,`readAt`],t);if(o!==void 0){let e;if(o.comprehensionEvidence!==void 0){let n=t.length,r=B(o.comprehensionEvidence,`$.provenance.comprehensionEvidence`,[`subject`,`dossierHash`,`signature`],[`subject`,`dossierHash`],[`subject`,`dossierHash`,`signature`],t);r!==void 0&&t.length===n&&(e={subject:r.subject,dossierHash:r.dossierHash,...typeof r.signature==`string`?{signature:r.signature}:{}})}a={source:o.source,readAt:o.readAt,...e===void 0?{}:{comprehensionEvidence:e}}}let s=[];Array.isArray(n.amendmentTrace)?n.amendmentTrace.forEach((e,n)=>{let r=ht(e,`$.amendmentTrace[${n}]`,t);r!==void 0&&s.push(r)}):t.push(z(`$.amendmentTrace`,`invalid_type`,`expected an array`));let c;return n.readability!==void 0&&(c=V(n.readability,`$.readability`,t)),t.length>0||a===void 0||n.readability!==void 0&&c===void 0||typeof n.ref!=`string`||typeof n.subject!=`string`||typeof n.title!=`string`||typeof n.hash!=`string`||typeof n.cursor!=`string`?{ok:!1,issues:t}:{ok:!0,value:{ref:n.ref,subject:n.subject,title:n.title,hash:n.hash,cursor:n.cursor,sections:r,interactions:i,provenance:a,amendmentTrace:s,...c===void 0?{}:{readability:c}}}},H=e=>lt(e)&&Object.hasOwn(e,`schemaVersion`)?e.schemaVersion===2?ct(e,yt):{ok:!1,issues:[z(`$.schemaVersion`,`unsupported_version`,`Supported explicit version: 2; omit schemaVersion for legacy v1`)]}:yt(e),bt=e=>{let t=[],n=new Map,r=(e,r)=>{let i=n.get(e);i===void 0?n.set(e,r):t.push(z(r,`duplicate_id`,`node id "${e}" already used at ${i}`))};e.sections.forEach((e,t)=>{let n=`$.sections[${t}]`;r(e.id,`${n}.id`),e.kind===`optionSet`&&e.options.forEach((e,t)=>{r(e.id,`${n}.options[${t}].id`)})});let i=new Set([e.ref]);for(let t of e.sections)if(i.add(t.id),i.add(t.targetRef),t.kind===`optionSet`)for(let e of t.options)i.add(e.id),i.add(e.targetRef);e.interactions.forEach((e,n)=>{i.has(e.targetRef)||t.push(z(`$.interactions[${n}].targetRef`,`unresolved_target`,`interaction target "${e.targetRef}" resolves to no node`))});let a=e.provenance.comprehensionEvidence;return a!==void 0&&a.dossierHash!==e.hash&&t.push(z(`$.provenance.comprehensionEvidence.dossierHash`,`evidence_mismatch`,`comprehension evidence does not match the snapshot hash`)),t},U=e=>{let t=H(e);if(!t.ok)return t;let n=bt(t.value);return n.length>0?{ok:!1,issues:n}:t};function xt(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function St(e){let t=[],n=e=>(t.push(e),`\u0000${t.length-1}\u0000`),r=xt(e);return r=r.replace(/`([^`]+)`/g,(e,t)=>n(`<code>${t}</code>`)),r=r.replace(/\[([^\]]*)\]\((https:\/\/[^)\s]+)\)/g,(e,t,r)=>{let i=r.replace(/"/g,`%22`);return n(`<a href="${i}">${t}</a>`)}),r=r.replace(/\*\*([^*]+)\*\*/g,`<strong>$1</strong>`),r=r.replace(/\*([^*]+)\*/g,`<em>$1</em>`),r.replace(/\u0000(\d+)\u0000/g,(e,n)=>t[Number(n)]??``)}function W(e,t){return e[t]??``}function Ct(e){return/^- /.test(e)}function wt(e){let t=e.replace(/\r\n?/g,`
4
- `).split(`
5
- `),n=[],r=0;for(;r<t.length;){let e=W(t,r);if(e.trim()===``){r+=1;continue}if(Ct(e)){let e=[];for(;r<t.length&&Ct(W(t,r));)e.push(`<li>${St(W(t,r).slice(2))}</li>`),r+=1;n.push(`<ul>\n${e.join(`
6
- `)}\n</ul>`);continue}let i=[];for(;r<t.length;){let e=W(t,r);if(e.trim()===``||Ct(e))break;i.push(St(e)),r+=1}n.push(`<p>${i.join(`
7
- `)}</p>`)}return n.join(`
8
- `)}function Tt(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Et(e){let t=e.startsWith(`$`)?e.slice(1):e,n=[];for(let e of t.matchAll(/([^.[\]]+)|\[(\d+)\]/g)){let t=e[1]??e[2];t!==void 0&&n.push(Tt(t))}return n.length===0?``:`/${n.join(`/`)}`}function G(e){return{source:`focus`,validate(t){let n=e(t);return n.ok?[]:n.issues.map(e=>({code:e.code,message:e.message,pointer:Et(e.path),severity:`error`}))}}}var K=G(U);function q(e){return typeof e==`string`&&e.length>0?e:void 0}var Dt=[`p`,`ul`,`li`,`code`,`a`,`strong`,`em`],Ot=[`href`],kt=/^https:\/\/[^\s"'<>]+$/i;function At(e){return j.sanitize(e,{ALLOWED_TAGS:Dt,ALLOWED_ATTR:Ot,ALLOW_DATA_ATTR:!1,ALLOWED_URI_REGEXP:kt})}function J(e){let t=document.createElement(`div`);return t.className=`st-dossier__prose`,t.innerHTML=At(wt(e)),t}function Y(e,t,n){let r=document.createElement(e);return r.className=t,r.textContent=n,r}function jt(e,t){return e.some(e=>typeof e==`object`&&!!e&&e.name===`choose-option`&&e.targetRef===t&&e.enabled===!1)}function Mt(e,t){let n=q(e.id)??``,r=q(e.label)??``;if(t){let e=Y(`div`,`st-dossier__option st-dossier__option--disabled`,r);return e.setAttribute(`data-option-disabled`,n),e}let i=document.createElement(`button`);i.type=`button`,i.className=`st-dossier__option`,i.setAttribute(`data-option-id`,n),i.append(Y(`span`,`st-dossier__optionLabel`,r));let a=q(e.body);a!==void 0&&i.append(Y(`span`,`st-dossier__optionBody`,a));let o=q(e.annotation);return o!==void 0&&o!==`none`&&i.append(Y(`span`,`st-dossier__optionAnnotation`,o)),i}function Nt(e,t){let n=q(e.kind)??``;if(n===`prose`)return J(q(e.markdown)??``);if(n===`question`){let t=document.createElement(`div`);t.className=`st-dossier__question`,t.setAttribute(`data-st-question`,q(e.id)??``);let n=Y(`h3`,`st-dossier__questionText`,q(e.question)??``);n.setAttribute(`data-st-question-text`,``),t.append(n);let r=q(e.state);if(r!==void 0){let e=Y(`span`,`st-dossier__state`,r);e.setAttribute(`data-st-question-state`,r),t.append(e)}return t}if(n===`optionSet`){let n=document.createElement(`div`);n.className=`st-dossier__options`,n.setAttribute(`data-st-option-set`,q(e.id)??``);let r=q(e.title);r!==void 0&&n.append(Y(`h4`,`st-dossier__optionsTitle`,r));let i=Array.isArray(e.options)?e.options:[];for(let e of i)if(typeof e==`object`&&e){let r=e;n.append(Mt(r,jt(t,q(r.id)??``)))}return n}if(n===`outcome`){let t=document.createElement(`div`);t.className=`st-dossier__outcome`,t.setAttribute(`data-st-outcome`,q(e.id)??``);let n=Y(`p`,`st-dossier__outcomeText`,q(e.statement)??``);n.setAttribute(`data-st-outcome-statement`,``),t.append(n);let r=q(e.modality);return r!==void 0&&t.append(Y(`span`,`st-dossier__modality`,r)),t}if(n===`amendmentTrace`){let t=document.createElement(`ol`);t.className=`st-dossier__trace`,t.setAttribute(`data-st-trace`,q(e.id)??``);let n=Array.isArray(e.steps)?e.steps:[];for(let e of n)if(typeof e==`object`&&e){let n=e,r=q(n.at)??``,i=q(n.author)??``,a=Y(`li`,`st-dossier__traceStep`,q(n.summary)??``);a.setAttribute(`data-st-trace-step`,`${r} ${i}`.trim()),t.append(a)}return t}if(n===`diagram`){let t=document.createElement(`figure`);t.className=`st-dossier__diagram`,t.setAttribute(`data-st-diagram`,q(e.id)??``);let n=q(e.alt);n!==void 0&&t.append(Y(`figcaption`,`st-dossier__diagramAlt`,n));let r=Y(`pre`,`st-dossier__diagramSource`,q(e.source)??``);return r.setAttribute(`data-st-diagram-source`,``),t.append(r),t}return Y(`div`,`st-dossier__unknownSection`,n)}function Pt(e,t,n){let r=t??{},i=Array.isArray(r.sections)?r.sections:[],a=Array.isArray(r.interactions)?r.interactions:[],o=document.createElement(`article`);o.className=`st-dossier`,o.setAttribute(`data-st-dossier`,``);let s=document.createElement(`header`);s.className=`st-dossier__header`;let c=q(r.subject);c!==void 0&&s.append(Y(`p`,`st-dossier__subject`,c)),s.append(Y(`h2`,`st-dossier__title`,q(r.title)??``)),s.setAttribute(`data-st-dossier-title`,``),o.append(s);for(let e of i)typeof e==`object`&&e&&o.append(Nt(e,a));let l=Array.isArray(r.amendmentTrace)?r.amendmentTrace:[];if(l.length>0){let e=document.createElement(`footer`);e.className=`st-dossier__traceFooter`,e.setAttribute(`data-st-trace-footer`,``);for(let t of l)if(typeof t==`object`&&t){let n=t,r=Y(`p`,`st-dossier__traceEntry`,q(n.summary)??``);r.setAttribute(`data-st-trace-at`,q(n.at)??``),e.append(r)}o.append(e)}let u=q((r.provenance??{}).source);if(u!==void 0){let e=Y(`p`,`st-dossier__provenance`,u);e.setAttribute(`data-st-provenance`,u),o.append(e)}let d=t=>{let r=t.target;if(!(r instanceof Element))return;let i=r.closest(`[data-option-id]`);i!==null&&e.contains(i)&&n(i.getAttribute(`data-option-id`)??``)};return e.addEventListener(`click`,d),e.replaceChildren(o),()=>{e.removeEventListener(`click`,d),e.replaceChildren()}}export{K as port,Pt as renderDossier,At as renderMarkdownToSafeHtml};
@@ -1 +0,0 @@
1
- import{m as e,t,w as n,x as r}from"./dist-Co2MgHWm.js";import{n as i}from"./ModelUtil-CMh7LuN4.js";import{r as a}from"./LabelUtil-7QpE43Ed.js";import{a as o}from"./LayoutUtil-hAMJmJFU.js";import{i as s,n as c,t as l}from"./textMetrics-BrMS6-sA.js";import{g as u}from"./bpmn-canvas-DeAWdJFy.js";function d(e){return!!e.sourceRef}function f(e){return!!e.attachedToRef}function p(e,t,n=new Set){if(e===t)return!0;if(n.has(e)||(n.add(e),!e.outgoing||e.outgoing.length===0))return!1;for(let r of e.outgoing.map(e=>e.targetRef))if(p(r,t,n))return!0;return!1}var m=80,h=100;function g(e){return _(e,`bpmn:SubProcess`)||_(e,`bpmn:Task`)?{width:h,height:m}:_(e,`bpmn:Gateway`)?{width:50,height:50}:_(e,`bpmn:Event`)?{width:36,height:36}:_(e,`bpmn:Participant`)||_(e,`bpmn:Lane`)?{width:400,height:100}:_(e,`bpmn:DataObjectReference`)?{width:36,height:50}:_(e,`bpmn:DataStoreReference`)?{width:50,height:50}:_(e,`bpmn:TextAnnotation`)?{width:h,height:30}:{width:h,height:m}}function _(e,t){return e.$instanceOf(t)}var v=150,y=140;function b(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function x(e,t,n=`r`,r=`top-left`){if(n===`h`&&(n=/left/.test(r)?`l`:`r`),n===`v`&&(n=/top/.test(r)?`t`:`b`),n===`t`)return{original:e,x:e.x,y:t.y};if(n===`r`)return{original:e,x:t.x+t.width,y:e.y};if(n===`b`)return{original:e,x:e.x,y:t.y+t.height};if(n===`l`)return{original:e,x:t.x,y:e.y};throw Error(`unexpected dockingDirection: <`+n+`>`)}function ee(e,t,n){let r=e.di,i=t.di,a=r.get(`bounds`),o=i.get(`bounds`),s=b(a),c=b(o),l=t.gridPosition.col-e.gridPosition.col,u=t.gridPosition.row-e.gridPosition.row,d=`${u>0?`bottom`:`top`}-${l>0?`right`:`left`}`,f=`${u>0?`top`:`bottom`}-${l>0?`left`:`right`}`,p=e.grid||e.attachedToRef?.grid,h=t.grid;if(l===0&&u===0){let{x:t,y:n}=S(e.gridPosition.row,e.gridPosition.col);return[x(s,a,`r`,d),{x:p?t+(p.getGridDimensions()[1]+1)*v:t+v,y:s.y},{x:p?t+(p.getGridDimensions()[1]+1)*v:t+v,y:n},{x:c.x,y:n},x(c,o,`t`,f)]}if(l<0){let{y:r}=S(e.gridPosition.row,e.gridPosition.col),i=y/2;if(s.y>=c.y){let i=ne(e,t,n);return i?[x(s,a,`b`),{x:s.x,y:p?r+(p.getGridDimensions()[0]+1)*y:r+y+i*y},{x:c.x,y:p?r+(p.getGridDimensions()[0]+1)*y:r+y+i*y},x(c,o,`b`)]:[x(s,a,`b`),{x:s.x,y:p?r+(p.getGridDimensions()[0]+1)*y:r+y},{x:c.x,y:p?r+(p.getGridDimensions()[0]+1)*y:r+y},x(c,o,`b`)]}{let e=s.y-i;return[x(s,a,`t`),{x:s.x,y:e},{x:c.x,y:e},x(c,o,`t`)]}}if(u===0){if(w(e,t,n)){let{y:t}=S(e.gridPosition.row,e.gridPosition.col);return[x(s,a,`b`),{x:s.x,y:p?t+(p.getGridDimensions()[0]+1)*y:t+y},{x:c.x,y:p?t+(p.getGridDimensions()[0]+1)*y:t+y},x(c,o,`b`)]}{let e=x(s,a,`h`,d),t=x(c,o,`h`,f);return p&&(e.y=a.y+m/2),h&&(t.y=o.y+m/2),[e,t]}}if(l===0){if(w(e,t,n)){let e=-Math.sign(u)*y/2;return[x(s,a,`r`),{x:s.x+v/2,y:s.y},{x:c.x+v/2,y:c.y+e},{x:c.x,y:c.y+e},x(c,o,Math.sign(e)>0?`b`:`t`)]}return[x(s,a,`v`,d),x(c,o,`v`,f)]}let g=te(e,t,n);if(g){let e=x(s,a,g[0],d),t=x(c,o,g[1],f);return[e,g[0]===`h`?{x:t.x,y:e.y}:{x:e.x,y:t.y},t]}let _=-Math.sign(u)*y/2;return[x(s,a,`r`,d),{x:s.x+v/2,y:s.y},{x:s.x+v/2,y:c.y+_},{x:c.x-v/2,y:c.y+_},{x:c.x-v/2,y:c.y},x(c,o,`l`,f)]}function S(e,t){return{width:v,height:y,x:t*v,y:e*y}}function C(e,t,n,r,i){let{width:a,height:o}=g(e),{x:s,y:c}=r;if(!i)return{width:e.isExpanded?e.grid.getGridDimensions()[1]*v+a:a,height:e.isExpanded?e.grid.getGridDimensions()[0]*y+o:o,x:n*v+(v-a)/2+s,y:t*y+(y-o)/2+c};let l=i.di.bounds;return{width:a,height:o,x:Math.round(l.x+l.width/2-a/2),y:Math.round(l.y+l.height-o/2)}}function w(e,t,n){let{row:r,col:i}=e.gridPosition,{row:a,col:o}=t.gridPosition,s=o-i,c=a-r,l=0;return s&&(l+=n.getElementsInRange({row:r,col:i},{row:r,col:o}).length),c&&(l+=n.getElementsInRange({row:r,col:o},{row:a,col:o}).length),l>2}function te(e,t,n){let{row:r,col:i}=e.gridPosition,{row:a,col:o}=t.gridPosition,s=o-i,c=a-r;if(s>0&&c!==0){if(c>0){let e=0,t={row:a,col:i};return e+=n.getElementsInRange({row:r,col:i},t).length,e+=n.getElementsInRange(t,{row:a,col:o}).length,e>2?!1:[`v`,`h`]}{let e=0,t={row:r,col:o};return e+=n.getElementsInRange({row:r,col:i},t).length,e+=n.getElementsInRange(t,{row:a,col:o}).length,e>2?!1:[`h`,`v`]}}}function ne(e,t,n){let r=e.attachedToRef?e.attachedToRef:e,i=t.attachedToRef?t.attachedToRef:t,[a,o]=n.find(r),[,s]=n.find(i),c=o<s?o:s,l=o<s?s:o;return n.getAllElements().filter(e=>e.gridPosition.row===a&&e.gridPosition.col>c&&e.gridPosition.col<l).reduce((e,t)=>{if(t.grid?.getGridDimensions()[0]>e)return t.grid?.getGridDimensions()[0]},0)}var T=class{constructor(){this.grid=[]}add(e,t){if(!t){this._addStart(e);return}let[n,r]=t;if(!n&&!r&&this._addStart(e),this.grid[n]||(this.grid[n]=[]),this.grid[n][r])throw Error(`Grid is occupied please ensure the place you insert at is not occupied`);this.grid[n][r]=e}createRow(e){!e&&!Number.isInteger(e)?this.grid.push([]):this.grid.splice(e+1,0,[])}_addStart(e){this.grid.push([e])}addAfter(e,t){e||this._addStart(t);let[n,r]=this.find(e);this.grid[n].splice(r+1,0,t)}addBelow(e,t){e||this._addStart(t);let[n,r]=this.find(e);if(this.grid[n+1]||(this.grid[n+1]=[]),this.grid[n+1][r]&&this.grid.splice(n+1,0,[]),this.grid[n+1][r])throw Error(`Grid is occupied and we could not find a place - this should not happen`);this.grid[n+1][r]=t}find(e){let t,n;return t=this.grid.findIndex(t=>(n=t.findIndex(t=>t===e),n!==-1)),[t,n]}get(e,t){return(this.grid[e]||[])[t]}getElementsInRange({row:e,col:t},{row:n,col:r}){let i=[];e>n&&([e,n]=[n,e]),t>r&&([t,r]=[r,t]);for(let a=e;a<=n;a++)for(let e=t;e<=r;e++){let t=this.get(a,e);t&&i.push(t)}return i}adjustGridPosition(e){let[t,n]=this.find(e),[,r]=this.getGridDimensions();n<r-1&&(this.grid[t].length=r,this.grid[t][r]=e,this.grid[t][n]=null)}adjustRowForMultipleIncoming(e,t){let n=e.map(e=>this.find(e)),r=Math.min(...n.map(e=>e[0]).filter(e=>e>=0)),[i,a]=this.find(t);r<i&&!this.grid[r][a]&&(this.grid[r][a]=t,this.grid[i][a]=null)}adjustColumnForMultipleIncoming(e,t){let n=e.map(e=>this.find(e)),r=Math.max(...n.map(e=>e[1]).filter(e=>e>=0)),[i,a]=this.find(t);r+1>a&&(this.grid[i][r+1]=t,this.grid[i][a]=null)}getAllElements(){let e=[];for(let t=0;t<this.grid.length;t++)for(let n=0;n<this.grid[t].length;n++){let r=this.get(t,n);r&&e.push(r)}return e}getGridDimensions(){let e=this.grid.length,t=0;for(let n=0;n<e;n++){let e=this.grid[n].length;e>t&&(t=e)}return[e,t]}elementsByPosition(){let e=[];return this.grid.forEach((t,n)=>{t.forEach((t,r)=>{t&&e.push({element:t,row:n,col:r})})}),e}getElementsTotal(){let e=this.grid.flat();return new Set(e.filter(e=>e)).size}createCol(e,t){this.grid.forEach((n,r)=>{this.expandRow(r,e,t)})}expandRow(e,t,n){if(!Number.isInteger(e)||e<0||e>this.rowCount-1)return;let r=Number.isInteger(n)&&n>0?Array(n):[,],i=this.grid[e];!t&&!Number.isInteger(t)?i.splice(i.length,0,...r):i.splice(t+1,0,...r)}},re=class{constructor(e){this.moddle=e}create(e,t){return this.moddle.create(e,t||{})}createDiBounds(e){return this.create(`dc:Bounds`,e)}createDiLabel(){return this.create(`bpmndi:BPMNLabel`,{bounds:this.createDiBounds()})}createDiShape(e,n,r){return this.create(`bpmndi:BPMNShape`,t({bpmnElement:e,bounds:this.createDiBounds(n)},r))}createDiWaypoints(e){var t=this;return r(e,function(e){return t.createDiWaypoint(e)})}createDiWaypoint(e){return this.create(`dc:Point`,n(e,[`x`,`y`]))}createDiEdge(e,n,r){return this.create(`bpmndi:BPMNEdge`,t({bpmnElement:e,waypoint:this.createDiWaypoints(n)},r))}createDiPlane(e){return this.create(`bpmndi:BPMNPlane`,e)}createDiDiagram(e){return this.create(`bpmndi:BPMNDiagram`,e)}},E={addToGrid:({element:e,grid:t,visited:n})=>{let r=[];return(e.attachers||[]).map(e=>(e.outgoing||[]).reverse()).flat().map(e=>e.targetRef).forEach((i,a,o)=>{n.has(i)||(D(i,e,t),r.push(i),n.add(i))}),r},createElementDi:({element:e,row:t,col:n,diFactory:r,shift:i})=>{let a=C(e,t,n,i),o=[];return(e.attachers||[]).forEach((s,c,l)=>{s.gridPosition={row:t,col:n};let u=C(s,t,n,i,e);u.x=a.x+(c+1)*(a.width/(l.length+1))-u.width/2;let d=r.createDiShape(s,u,{id:s.id+`_di`});s.di=d,s.gridPosition={row:t,col:n},o.push(d)}),o},createConnectionDi:({element:e,row:t,col:n,layoutGrid:r,diFactory:i,shift:a})=>(e.attachers||[]).flatMap(e=>(e.outgoing||[]).map(a=>{let o=a.targetRef,s=ee(e,o,r);return O(e,s,[t,n]),i.createDiEdge(a,s,{id:a.id+`_di`})}))};function D(e,t,n){let[r,i]=n.find(t);(n.get(r+1,i)||n.get(r+1,i+1))&&n.createRow(r),n.add(e,[r+1,i+1])}function O(e,t,[n,r]){let i=e.di.get(`bounds`),a=x(b(i),i,`b`);if(t[0].x===a.x&&t[0].y===a.y)return;let o=e.grid||e.attachedToRef?.grid;if(t.length===2){let e=[a,{x:a.x,y:o?(n+o.getGridDimensions()[0]+1)*y:(n+1)*y},{x:o?(r+o.getGridDimensions()[1]+1)*v:(r+1)*v,y:o?(n+o.getGridDimensions()[0]+1)*y:(n+1)*y},{x:o?(r+o.getGridDimensions()[1]+1)*v:(r+1)*v,y:o?n*y+y/2:(n+.5)*y}];t.splice(0,1,...e);return}let s=[a,{x:a.x,y:o?(n+o.getGridDimensions()[0]+1)*y:(n+1)*y},{x:t[1].x,y:o?(n+o.getGridDimensions()[0]+1)*y:(n+1)*y}];t.splice(0,1,...s)}var k={createElementDi:({element:e,row:t,col:n,diFactory:r,shift:i})=>{let a=C(e,t,n,i),o={id:e.id+`_di`};_(e,`bpmn:ExclusiveGateway`)&&(o.isMarkerVisible=!0),e.isExpanded&&(o.isExpanded=!0);let s=r.createDiShape(e,a,o);return e.di=s,e.gridPosition={row:t,col:n},s}},A={addToGrid:({element:e,grid:t,visited:n,stack:r})=>{let i=[],a=(e.outgoing||[]).map(e=>e.targetRef).filter(e=>e),o=null;return a.length>1&&ae(a)&&t.adjustGridPosition(e),a.forEach((a,s,c)=>{n.has(a)||(o||r.length>0)&&M(a,n)&&!j(a,n)||(o?_(e,`bpmn:ExclusiveGateway`)&&_(a,`bpmn:ExclusiveGateway`)?t.addAfter(o,a):t.addBelow(c[s-1],a):t.addAfter(e,a),a!==e&&(o=a),i.unshift(a),n.add(a))}),i=ie(i,`bpmn:ExclusiveGateway`),i},createConnectionDi:({element:e,row:t,col:n,layoutGrid:r,diFactory:i})=>(e.outgoing||[]).map(t=>{let n=t.targetRef,a=ee(e,n,r);return i.createDiEdge(t,a,{id:t.id+`_di`})})};function ie(e,t){let n=e.filter(e=>!_(e,t));return[...e.filter(e=>_(e,t)),...n]}function j(e,t){for(let n of e.incoming)if(!t.has(n.sourceRef))return p(e,n.sourceRef)}function M(e,t){if(e.incoming.length>1){for(let n of e.incoming)if(!t.has(n.sourceRef))return!0}return!1}function ae(e){return e.every(e=>_(e,`bpmn:Task`))}var oe=[k,{addToGrid:({element:e,grid:t,visited:n})=>{let r=[],i=(e.incoming||[]).map(e=>e.sourceRef).filter(e=>e);return i.length>1&&(t.adjustColumnForMultipleIncoming(i,e),t.adjustRowForMultipleIncoming(i,e)),r}},A,E],se=class{constructor(){this.moddle=new u,this.diFactory=new re(this.moddle),this._handlers=oe}handle(t,n){return this._handlers.filter(n=>e(n[t])).map(e=>e[t](n))}async layoutProcess(e){let t=await this.moddle.fromXML(e),{rootElement:n}=t;this.diagram=n;let r=this.getProcess();return r&&(this.setExpandedPropertyToModdleElements(t),this.setExecutedProcesses(r),this.createGridsForProcesses(),this.cleanDi(),this.createRootDi(r),this.drawProcesses()),(await this.moddle.toXML(this.diagram,{format:!0})).xml}createGridsForProcesses(){let e=this.layoutedProcesses.sort((e,t)=>t.level-e.level);for(let t of e)if(t.grid=this.createGridLayout(t),le(t.grid),N(t.grid),t.isExpanded){let[e,n]=t.grid.getGridDimensions();e===0&&t.grid.createRow(),n===0&&t.grid.createCol()}}setExpandedPropertyToModdleElements(e){let t=e.elementsById;if(t)for(let e of Object.values(t))e.$type===`bpmndi:BPMNShape`&&e.isExpanded===!0&&(e.bpmnElement.isExpanded=!0)}setExecutedProcesses(e){this.layoutedProcesses=[];let t=[e];for(;t.length>0;){let e=t.pop();this.layoutedProcesses.push(e),e.level=e.$parent===this.diagram?0:e.$parent.level+1;let n=e.get(`flowElements`).filter(e=>_(e,`bpmn:SubProcess`));t.splice(t.length,0,...n)}}cleanDi(){this.diagram.diagrams=[]}createGridLayout(e){let t=new T,n=e.flowElements||[],r=n.filter(e=>!_(e,`bpmn:SequenceFlow`));if(!n)return t;ce(n);let i=new Set;for(;i.size<r.filter(e=>!e.attachedToRef).length;){let e=n.filter(e=>!d(e)&&!f(e)&&(!e.incoming||!ue(e))&&!i.has(e)),a=[...e];if(e.forEach(e=>{t.add(e),i.add(e)}),this.handleGrid(t,i,a),t.getElementsTotal()!==r.length){let e=t.getAllElements(),n=r.filter(t=>!e.includes(t)&&!f(t));n.length>0&&(a.push(n[0]),t.add(n[0]),i.add(n[0]),this.handleGrid(t,i,a))}}return t}generateDi(e,t,n){let r=this.diFactory,i=(n||this.diagram.diagrams[0]).plane.get(`planeElement`);e.elementsByPosition().forEach(({element:n,row:a,col:o})=>{let s=this.handle(`createElementDi`,{element:n,row:a,col:o,layoutGrid:e,diFactory:r,shift:t}).flat();i.push(...s)}),e.elementsByPosition().forEach(({element:n,row:a,col:o})=>{let s=this.handle(`createConnectionDi`,{element:n,row:a,col:o,layoutGrid:e,diFactory:r,shift:t}).flat();i.push(...s)})}handleGrid(e,t,n){for(;n.length>0;){let r=n.pop();this.handle(`addToGrid`,{element:r,grid:e,visited:t,stack:n}).flat().forEach(e=>{n.push(e),t.add(e)})}}getProcess(){return this.diagram.get(`rootElements`).find(e=>e.$type===`bpmn:Process`)}createRootDi(e){this.createProcessDi(e)}createProcessDi(e){let t=this.diFactory,n=t.createDiPlane({id:`BPMNPlane_`+e.id,bpmnElement:e}),r=t.createDiDiagram({id:`BPMNDiagram_`+e.id,plane:n});return this.diagram.diagrams.push(r),r}drawProcesses(){let e=this.layoutedProcesses.sort((e,t)=>e.level-t.level);for(let t of e){if(t.isExpanded){let e=this.getElementDi(t),n=this.getProcDi(e),{x:r,y:i}=e.bounds,{width:a,height:o}=g(t);r+=v/2-a/4,i+=y-o-o/4,this.generateDi(t.grid,{x:r,y:i},n);continue}let e=this.diagram.diagrams.find(e=>e.plane.bpmnElement===t);this.generateDi(t.grid,{x:0,y:0},e)}}getElementDi(e){return this.diagram.diagrams.map(e=>e.plane.planeElement).flat().find(t=>t.bpmnElement===e)}getProcDi(e){return this.diagram.diagrams.find(t=>t.plane.planeElement.includes(e))}};function ce(e){e.filter(e=>f(e)).forEach(e=>{let t=e.attachedToRef,n=t.attachers||[];n.push(e),t.attachers=n})}function le(e){let[t,n]=e.getGridDimensions();for(let r=n-1;r>=0;r--){let n=[];for(let i=0;i<t;i++){let t=e.get(i,r);t&&t.isExpanded&&n.push(t)}if(n.length===0)continue;let i=n.reduce((e,t)=>{let[,n]=t.grid.getGridDimensions();return e===void 0||n>e?n:e},void 0)||2;e.createCol(r,i)}}function N(e){let[t,n]=e.getGridDimensions();for(let r=t-1;r>=0;r--){let t=[];for(let i=0;i<n;i++){let n=e.get(r,i);n&&n.isExpanded&&t.push(n)}if(t.length===0)continue;let i=t.reduce((e,t)=>{let[n]=t.grid.getGridDimensions();return e===void 0||n>e?n:e},void 0)||1;for(let t=0;t<i;t++)e.createRow(r)}}function ue(e){let t=e.incoming?.filter(t=>t.sourceRef!==e&&t.sourceRef.attachedToRef===void 0)||[],n=e.incoming?.filter(t=>t.sourceRef!==e&&t.sourceRef.attachedToRef!==e);return t?.length>0||n?.length>0}function de(e){return new se().layoutProcess(e)}var fe=new Set([`START`,`END`,`TASK`,`SUB-PROCESS`,`GATEWAY`,`EVENT`,`EXTERNAL_PROCESS`]),P=new Set([`TASK_INPUT`,`TASK_OUTPUT`,`EXTERNAL_INPUT`,`PROCESS_OUTPUT`,`DOCUMENT`,`DATA_OBJECT`,`EXTERNAL_DATA_OBJECT`]),pe=30,me=30,he=40,ge=70,_e=26,ve=24,ye=200,be=70,F=10,I=10,L=12,xe=11,R=1.2,z=50,B=40,V=50,Se={EVENT:120,ITEM:100},Ce={TASK:[120,80],"SUB-PROCESS":[120,80],EXTERNAL_PROCESS:[108,62],GATEWAY:[z,z],START:[z,z],END:[z,z],EVENT:[z,z],TASK_INPUT:[B,V],TASK_OUTPUT:[B,V],EXTERNAL_INPUT:[B,V],PROCESS_OUTPUT:[B,V],DOCUMENT:[110,50]},we=new Set([`TASK`,`SUB-PROCESS`,`EXTERNAL_PROCESS`]),H=80,U=30,Te=31,Ee=10,De=120,Oe=20,W=.74,ke=6,G=4,K=150,q=e=>e.x+Math.floor(e.w/2),Ae=e=>e.text??e.label??``,J=e=>e.y+Math.floor(e.h/2),Y=(e,t,n,r)=>({x:e,y:t,w:n,h:r});function je(e,t,n){let r=n.padX??8,i=n.padY??6,a=l(e,t,n.bold)+2*r,o,s;a<=n.maxW?(o=Math.max(n.minW,a),s=1):(o=n.maxW,s=c(e,t,n.maxW-2*r,n.bold).length);let u=Math.max(n.minH,s*t*R+2*i+(n.extraH??0));return[Math.ceil(o),Math.ceil(u)]}function Me(e,t,n,r=!1){if(!(e??``).trim())return[0,0];let i=c(e,t,n,r),a=Math.max(...i.map(e=>l(e,t,r)));return[Math.ceil(Math.min(n,a)+4),Math.ceil(i.length*t*R+2)]}function Ne(e,t){let n=l(e,L,!0)+Te,r=Math.max(H,t-2*Ee),i=Math.trunc(Math.min(r,Math.max(H,Math.ceil(n))));if(n<=i)return[i,U];let a=c(e,L,i-Te,!0).length;return[i,Math.trunc(Math.max(U,Math.ceil(a*L*1.2+8)))]}function X(e){let t=(e??``).split(/\s+/).filter(Boolean),n=t.length?Math.max(...t.map(e=>l(e,L,!0))):0;return Math.trunc(Math.ceil(n+Te+2*Ee))}function Pe(e){let t=c(e,xe,De-2*ke).length*xe*1.2;return Math.trunc(Math.max(50,Math.ceil((Oe+t+G)/W)))}function Fe(e){let t=(e.type||`TASK`).trim().toUpperCase();return t in Ce?t:`TASK`}function Ie(e,t){let n=Ae(e),r=String(e.app_label||``),i=r?Math.min(200,Math.max(120,X(r))):120;return t===`TASK`||t===`SUB-PROCESS`?je(n,L,{minW:i,maxW:Math.max(200,i),minH:80,padX:8,padY:8,extraH:r?10:0}):t===`EXTERNAL_PROCESS`?je(n,L,{minW:Math.max(108,r?i:108),maxW:200,minH:62,padX:14,padY:8,extraH:10}):t===`DOCUMENT`?[De,Pe(n)]:Ce[t]??[120,80]}var Le={START:`startEvent`,END:`endEvent`,EVENT:`intermediateThrowEvent`,"SUB-PROCESS":`subProcess`,EXTERNAL_PROCESS:`callActivity`};function Z(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function Re(e,t){let n=new Map(e.map((e,t)=>[e.label,`n${t}`])),r=new Map([...n.values()].map(e=>[e,[]])),i=new Map([...n.values()].map(e=>[e,[]])),a=[];return t.forEach(([e,t],o)=>{let s=n.get(e),c=n.get(t);if(s&&c){let e=`f${o}`;i.get(s).push(e),r.get(c).push(e),a.push(`<bpmn:sequenceFlow id="${e}" sourceRef="${s}" targetRef="${c}"/>`)}}),{xml:`<?xml version="1.0" encoding="UTF-8"?><bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" id="d" targetNamespace="http://bpmn.io/schema/bpmn"><bpmn:process id="p" isExecutable="false">`+e.map(e=>{let t=n.get(e.label),a=(e.type||`TASK`).trim().toUpperCase(),o=a===`GATEWAY`?(e.subtype||``).trim().toUpperCase()===`AND`?`parallelGateway`:`exclusiveGateway`:Le[a]??`task`,s=r.get(t).map(e=>`<bpmn:incoming>${e}</bpmn:incoming>`).join(``)+i.get(t).map(e=>`<bpmn:outgoing>${e}</bpmn:outgoing>`).join(``);return`<bpmn:${o} id="${t}" name="${Z(Ae(e))}">${s}</bpmn:${o}>`}).join(``)+a.join(``)+`</bpmn:process></bpmn:definitions>`,ids:n}}var ze=/bpmnElement="(n\d+)"[^>]*>\s*<dc:Bounds x="(-?[\d.]+)" y="(-?[\d.]+)" width="([\d.]+)" height="([\d.]+)"/g;async function Be(e,t){if(!e.length)return new Map;let{xml:n,ids:r}=Re(e,t),i;try{i=await de(n)}catch{return null}let a=new Map;for(let e of i.matchAll(ze))a.set(e[1]??``,Math.floor((Number(e[2])+Number(e[4])/2)/K));if(a.size!==r.size)return null;let o=Math.min(...a.values()),s=new Map;for(let[e,t]of r)s.set(e,a.get(t)-o);return s}async function Ve(e,t={}){let n=t.originY??0,r=t.columns??`bpmn-io`,i=e.lanes??[],a=new Map,o=new Map,s=new Map,c=[];i.forEach((e,t)=>{for(let n of e.nodes??[]){let e=n.label||``;a.has(e)||(a.set(e,t),o.set(e,Fe(n)),s.set(e,n),fe.has(o.get(e))&&c.push(e))}});let l=new Set(c),u=(e.connections??[]).filter(e=>a.has(e.source)&&a.has(e.target)),d=u.filter(e=>(e.kind||`FLOW`)===`FLOW`&&l.has(e.source)&&l.has(e.target)),f=u.filter(e=>(e.kind||`FLOW`)!==`FLOW`),p=new Map,m=e=>p.get(e)??[];for(let e of d)p.set(e.source,[...m(e.source),e.target]);let h=[...c.filter(e=>o.get(e)===`START`),...c],g=new Set,_=(e,t)=>`${e}\u0000${t}`,v=new Map;for(let e of h){if(v.has(e))continue;let t=[[e,0]];for(v.set(e,1);t.length;){let e=t[t.length-1],n=m(e[0]);if(e[1]>=n.length){v.set(e[0],2),t.pop();continue}let r=n[e[1]++],i=v.get(r)??0;i===1?g.add(_(e[0],r)):i===0&&(v.set(r,1),t.push([r,0]))}}let y=new Map(c.map(e=>[e,0])),b=new Map;for(let e of d)g.has(_(e.source,e.target))||(y.set(e.target,y.get(e.target)+1),b.set(e.source,[...b.get(e.source)??[],e.target]));let x=new Map(c.map(e=>[e,0])),ee=c.filter(e=>y.get(e)===0);for(;ee.length;){let e=ee.shift();for(let t of b.get(e)??[])x.set(t,Math.max(x.get(t),x.get(e)+1)),y.set(t,y.get(t)-1),y.get(t)===0&&ee.push(t)}if(r===`bpmn-io`){let e=await Be(c.map(e=>s.get(e)),d.map(e=>[e.source,e.target]));if(e){let t=[...new Set(e.values())].sort((e,t)=>e-t);x=new Map(c.map(n=>[n,t.indexOf(e.get(n))]))}}let S=new Map,C=new Map,w=(e,t)=>`${e}:${t}`;for(let e of c){let t=w(a.get(e),x.get(e));C.set(e,S.get(t)??0),S.set(t,(S.get(t)??0)+1)}let te=i.map((e,t)=>{let n=[...S.entries()].filter(([e])=>Number(e.split(`:`)[0])===t).map(([,e])=>e);return n.length?Math.max(...n):1}),ne=x.size?Math.max(...x.values()):0,T=new Map;for(let[e,t]of s)T.set(e,Ie(t,o.get(e)));let re=new Map;for(let[e,t]of s){let n=o.get(e);n===`START`||n===`END`||n===`EVENT`||n===`GATEWAY`?re.set(e,Me(Ae(t),xe,Se.EVENT)):P.has(n)&&n!==`DOCUMENT`&&re.set(e,Me(Ae(t),xe,Se.ITEM))}let E=new Map;for(let e of c){let t=s.get(e);t.app_label&&we.has(o.get(e))&&E.set(e,Ne(String(t.app_label),T.get(e)[0]))}let D=new Map,O=new Map,k=new Map,A=new Map,ie=(e,t,n)=>void e.set(t,[...e.get(t)??[],n]);for(let[e,t]of s){if(!P.has(o.get(e)))continue;let n=t._task&&x.has(t._task)?t._task:null;if(n===null){A.set(a.get(e),[...A.get(a.get(e))??[],e]);continue}let r=t._dir||`in`;ie(r===`doc`?D:r===`in`?O:k,n,e)}let j=e=>re.get(e)??[0,0],M=e=>o.get(e)===`DOCUMENT`?T.get(e)[0]:Math.max(T.get(e)[0],j(e)[0]),ae=e=>T.get(e)[1]+(j(e)[1]?4+j(e)[1]:0),oe=e=>e.reduce((e,t)=>e+M(t),0)+F*Math.max(0,e.length-1),se=e=>{let t=D.get(e)??[],n=Math.floor((t.length+1)/2);return[t.slice(0,n),t.slice(n)]},ce=new Map;for(let[e,t]of D){let n=w(a.get(e),C.get(e));for(let e of t)ce.set(n,Math.max(ce.get(n)??0,T.get(e)[1]))}for(let[e,t]of D){let n=w(a.get(e),C.get(e));for(let e of t)T.set(e,[T.get(e)[0],ce.get(n)])}let le=new Map;for(let e of c){let t=w(a.get(e),C.get(e));le.set(t,Math.max(le.get(t)??0,T.get(e)[1]/2))}let N=new Map;for(let e of c){let[t,n]=T.get(e),[r,i]=se(e),o=w(a.get(e),C.get(e)),s=D.get(e)??[],c=n/2+(s.length?le.get(o)-n/2+Math.max(...s.map(e=>T.get(e)[1]))+14:0),l=E.has(e)?E.get(e)[0]/2:0,u=0;E.has(e)&&(u=E.get(e)[1]-10);let d=u+14,f=[...O.get(e)??[],...k.get(e)??[]];f.length&&(u=d+Math.max(...f.map(ae))),re.has(e)&&j(e)[1]&&(u=Math.max(u,4+j(e)[1]));let p=Math.max(l,I),m=Math.max(t/2,I+oe(r),p+8+oe(O.get(e)??[]),j(e)[0]/2),h=Math.max(t/2,I+oe(i),p+8+oe(k.get(e)??[]),j(e)[0]/2);N.set(e,{left:m,right:h,up:c,down:n/2+u,itemStart:d})}let ue=pe+me+he,de=(e,t)=>{let n=c.filter(t=>x.get(t)===e).map(e=>t(N.get(e)));return n.length?Math.max(...n):60},L=[],R=[];for(let e=0;e<=ne;e++)L.push(de(e,e=>e.left)),R.push(de(e,e=>e.right));let z=[],B=ue;for(let e=0;e<=ne;e++)B+=L[e]??0,z.push(B),B+=(R[e]??0)+ge;let V=i.map((e,t)=>(A.get(t)??[]).reduce((e,t)=>e+M(t)+F,0)),Ce=Math.trunc(Math.max(B-ge+be,ue+(V.length?Math.max(...V):0)+be)),H=new Map,U=new Map;for(let e of c){let t=w(a.get(e),C.get(e));H.set(t,Math.max(H.get(t)??0,N.get(e).up)),U.set(t,Math.max(U.get(t)??0,N.get(e).down))}let Te=new Map,Ee=new Map,De=[],Oe=new Map,W=n;i.forEach((e,t)=>{let n=W;for(let e=0;e<(te[t]??1);e++){let n=w(t,e),r=H.has(n)?H.get(n):40,i=U.has(n)?U.get(n):40;Te.set(n,W),Ee.set(n,Math.trunc(W+_e+r)),W=Math.trunc(W+_e+r+i+ve)}let r=A.get(t)??[];r.length&&(Oe.set(t,W),W+=Math.max(...r.map(e=>o.get(e)===`DOCUMENT`?T.get(e)[1]:ae(e)))+ve);let i=Math.max(ye,W-n);W=n+i,De.push([e.name||``,Y(pe,n,Ce-pe,i)])});let ke=Y(0,n,Ce,Math.max(W-n,ye)),G={},K=e=>G[e],je={},X={},Pe=(e,t,n,r)=>{let[i,a]=T.get(e),o=t+Math.floor(r/2);if(G[e]=Y(o-Math.floor(i/2),n,i,a),j(e)[1]){let[t,r]=j(e);je[e]=Y(o-Math.floor(t/2),n+a+4,t,r)}};for(let e of c){let[t,n]=T.get(e),r=w(a.get(e),C.get(e)),i=Math.trunc(z[x.get(e)]??0),o=Ee.get(r),s=Y(i-Math.floor(t/2),o-Math.floor(n/2),t,n);if(G[e]=s,j(e)[1]){let[t,n]=j(e);je[e]=Y(i-Math.floor(t/2),s.y+s.h+4,t,n)}if(E.has(e)){let[t,n]=E.get(e);X[e]=Y(i-Math.floor(t/2),s.y+s.h-10,t,n)}let[c,l]=se(e),u=o-Math.trunc(le.get(r))-14,d=i-I;for(let e of[...c].reverse()){let[t,n]=T.get(e);d-=t,G[e]=Y(d,u-n,t,n),d-=F}let f=i+I;for(let e of l){let[t,n]=T.get(e);G[e]=Y(f,u-n,t,n),f+=t+F}let p=Math.max(X[e]?Math.floor(X[e].w/2):0,I)+8,m=Math.trunc(o+n/2+N.get(e).itemStart);d=i-p;for(let t of[...O.get(e)??[]].reverse()){let e=M(t);d-=e,Pe(t,d,m,e),d-=F}f=i+p;for(let t of k.get(e)??[]){let e=M(t);Pe(t,f,m,e),f+=e+F}}for(let[e,t]of A){let n=ue;for(let r of t){let t=M(r);o.get(r)===`DOCUMENT`?G[r]=Y(n,Oe.get(e),T.get(r)[0],T.get(r)[1]):Pe(r,n,Oe.get(e),t),n+=t+F}}let Le=[],Z=[],Re=new Map,ze=e=>{let t=w(a.get(e),C.get(e)),n=Re.get(t)??0;return Re.set(t,n+1),Te.get(t)+8+n%3*5},Ve=(e,t)=>J(K(e))<=J(K(t))?e:t,He=(e,t,n,r)=>{let i=Math.min(t,n),a=Math.max(t,n);return c.some(t=>!r.includes(t)&&K(t).x<a&&K(t).x+K(t).w>i&&K(t).y<=e&&e<=K(t).y+K(t).h)},We=e=>Math.trunc((z[e]??0)-(L[e]??0)-ge/2);for(let e of d){let t=e.source,n=e.target,r=K(t),i=K(n),a;if(g.has(_(t,n))||q(i)<q(r)){let e=ze(Ve(t,n));a=[[q(r),r.y],[q(r),e],[q(i),e],[q(i),i.y]]}else if(q(i)===q(r)){let e=J(i)>J(r),o=e?t:n;if(X[o]||(O.get(o)??[]).length||(k.get(o)??[]).length){let e=Math.trunc((z[x.get(t)]??0)+(R[x.get(t)]??0)+14);a=[[r.x+r.w,J(r)],[e,J(r)],[e,J(i)],[i.x+i.w,J(i)]]}else a=e?[[q(r),r.y+r.h],[q(i),i.y]]:[[q(r),r.y],[q(i),i.y+i.h]]}else{let e=We(x.get(n)),o=Math.abs(J(r)-J(i))<2;if(o&&!He(J(r),r.x+r.w,i.x,[t,n]))a=[[r.x+r.w,J(r)],[i.x,J(i)]];else if(!o&&!He(J(r),r.x+r.w,e,[t,n]))a=[[r.x+r.w,J(r)],[e,J(r)],[e,J(i)],[i.x,J(i)]];else if(o){let e=ze(t);a=[[q(r),r.y],[q(r),e],[q(i),e],[q(i),i.y]]}else{let n=ze(t);a=[[q(r),r.y],[q(r),n],[e,n],[e,J(i)],[i.x,J(i)]]}}if(Le.push(a),e.label){let[t,n]=Me(e.label,xe,120),[r,i,o,s]=a,c=a.length===4&&i[0]===o[0]&&r[1]===i[1],[[l,u],[d,f]]=c?[o,s]:[r,i];c?Z.push(Y(d-t-4,f-n-2,t,n)):l===d?Z.push(Y(l+4,Math.floor((u+f)/2)-Math.floor(n/2),t,n)):Z.push(Y(Math.floor((l+d)/2)-Math.floor(t/2),Math.min(u,f)-n-2,t,n))}else Z.push(null)}for(let e of f){let t=K(e.source),n=K(e.target);if(!t||!n){Le.push([]),Z.push(null);continue}let r=P.has(o.get(e.source)),[i,a]=r?[e.source,e.target]:[e.target,e.source],c=s.get(i)._task===a,l=Ue(i,a,K(i),K(a),o,X,z,L,x,c);r||(l=[...l].reverse()),Le.push(l),Z.push(null)}return{pool:ke,lanes:De,nodes:G,edges:Le,edgeLabels:Z,connections:[...d,...f],apps:X,labels:je}}function He(e,t){return t?[t.x+6,t.x+t.w-6,t.y+t.h]:[e.x+8,e.x+e.w-8,e.y+e.h]}function Ue(e,t,n,r,i,a,o,s,c,l){let u=c.has(t)?Math.trunc((o[c.get(t)]??0)-(s[c.get(t)]??0)-12):r.x-12;if(i.get(e)===`DOCUMENT`){let e=r.x+14,t=r.x+r.w-14,i=r.y,a=r.y-7;if(l){if(e<=q(n)&&q(n)<=t)return[[q(n),n.y+n.h],[q(n),i]];let o=q(n)<q(r)?e:t;return[[q(n),n.y+n.h],[q(n),a],[o,a],[o,i]]}let o=n.y+n.h+6;return[[q(n),n.y+n.h],[q(n),o],[u,o],[u,a],[e,a],[e,i]]}let[d,f,p]=He(r,a[t]),m=p+7;if(l){if(d<=q(n)&&q(n)<=f)return[[q(n),n.y],[q(n),p]];let e=q(n)<q(r)?d:f;return[[q(n),n.y],[q(n),m],[e,m],[e,p]]}let h=n.y-8;return[[q(n),n.y],[q(n),h],[u,h],[u,m],[d,m],[d,p]]}var We={startEvent:[`START`,null],endEvent:[`END`,null],task:[`TASK`,null],subProcess:[`SUB-PROCESS`,null],callActivity:[`EXTERNAL_PROCESS`,null],exclusiveGateway:[`GATEWAY`,`OR`],parallelGateway:[`GATEWAY`,`AND`],inclusiveGateway:[`GATEWAY`,`OR`],intermediateThrowEvent:[`EVENT`,null],intermediateCatchEvent:[`EVENT`,null]},Ge=new Set([`task`,`subProcess`,`callActivity`,`exclusiveGateway`,`parallelGateway`,`inclusiveGateway`,`startEvent`,`endEvent`,`intermediateThrowEvent`,`intermediateCatchEvent`]),Ke=new Set([`TASK`,`SUB-PROCESS`,`EXTERNAL_PROCESS`]),Q=e=>e.localName,qe=(e,t)=>[...e.children].filter(e=>Q(e)===t),$=e=>(e.type||`TASK`).trim().toUpperCase();function Je(e){if(typeof DOMParser>`u`)throw Error(`parseProcesses needs a DOM (DOMParser)`);let t=[...new DOMParser().parseFromString(e,`application/xml`).documentElement.children],n=t.filter(e=>Q(e)===`collaboration`).flatMap(e=>[...e.children].filter(e=>Q(e)===`textAnnotation`||Q(e)===`association`));return t.filter(e=>Q(e)===`process`).map(e=>({id:e.getAttribute(`id`)??``,proc:Xe(e,n)}))}function Ye(e,t){let n=new Set([e,...e.getElementsByTagName(`*`)].map(e=>e.getAttribute(`id`)).filter(Boolean)),r=new Set(t.filter(e=>Q(e)===`textAnnotation`).map(e=>e.getAttribute(`id`))),i=new Set;for(let e of t){if(Q(e)!==`association`)continue;let t=e.getAttribute(`sourceRef`),a=e.getAttribute(`targetRef`),o=e=>n.has(e)||r.has(e);o(t)&&o(a)&&(n.has(t)||n.has(a))&&(i.add(e.getAttribute(`id`)),r.has(t)&&i.add(t),r.has(a)&&i.add(a))}return t.filter(e=>i.has(e.getAttribute(`id`)))}function Xe(e,t=[]){let n=[e,...e.getElementsByTagName(`*`)];for(let r of Ye(e,t))n.push(r,...r.getElementsByTagName(`*`));let r=new Map;for(let e of n){let t=e.getAttribute(`id`);t&&![`laneSet`,`lane`,`flowNodeRef`].includes(Q(e))&&r.set(t,e)}let i=new Map,a=new Map,o=new Set,s=e=>e.getAttribute(`name`)??``;for(let[e,t]of r){let n=Q(t);if(n===`textAnnotation`){let n=(t.textContent??``).trim();n.startsWith(`[App]`)?a.set(e,n.slice(5).trim()):n.startsWith(`[Doc]`)&&(i.set(e,{type:`DOCUMENT`,label:e,text:n.slice(5).trim()||e}),o.add(e))}else if(n in We){let[r,a]=We[n];i.set(e,{type:r,label:e,text:s(t)||e,...a?{subtype:a}:{}})}else n===`dataInput`?i.set(e,{type:`EXTERNAL_INPUT`,label:e,text:s(t)||e}):n===`dataOutput`?i.set(e,{type:`PROCESS_OUTPUT`,label:e,text:s(t)||e}):n===`dataObjectReference`&&i.set(e,{type:`TASK_OUTPUT`,label:e,text:s(t)||e,_pending:!0})}let c=[],l=new Map;for(let t of e.getElementsByTagName(`*`))if(Q(t)===`laneSet`)for(let e of qe(t,`lane`)){c.push(e.getAttribute(`name`)||e.getAttribute(`id`)||``);for(let t of qe(e,`flowNodeRef`)){let e=(t.textContent??``).trim();r.has(e)&&l.set(e,c.length-1)}}c.length||c.push(`Lane 1`);let u=[];for(let[e,t]of r){let e=Q(t);if(e===`sequenceFlow`){let e=t.getAttribute(`sourceRef`)??``,n=t.getAttribute(`targetRef`)??``;i.has(e)&&i.has(n)&&u.push({source:e,target:n,kind:`FLOW`,...t.getAttribute(`name`)?{label:t.getAttribute(`name`)}:{}})}else if(e===`association`){let e=t.getAttribute(`sourceRef`)??``,n=t.getAttribute(`targetRef`)??``;a.has(e)&&i.has(n)?i.get(n).app_label=a.get(e)??null:a.has(n)&&i.has(e)?i.get(e).app_label=a.get(n)??null:i.has(e)&&i.has(n)&&(o.has(e)||o.has(n))&&u.push({source:e,target:n,kind:`DOC`})}else if(e===`dataInputAssociation`||e===`dataOutputAssociation`){let n=t.parentElement&&Ge.has(Q(t.parentElement))?t.parentElement.getAttribute(`id`):null;if(!n||!i.has(n))continue;let r=qe(t,e===`dataInputAssociation`?`sourceRef`:`targetRef`);for(let t of r){let r=(t.textContent??``).trim();if(!i.has(r))continue;let a=i.get(r);e===`dataInputAssociation`?u.push({source:r,target:n,kind:`DATA`}):u.push({source:n,target:r,kind:`DATA`}),a._pending&&(a.type=e===`dataInputAssociation`?`TASK_INPUT`:`TASK_OUTPUT`,delete a._pending)}}}for(let e of i.values())delete e._pending;let d=new Map;for(let e of u){let t=i.get(e.source),n=i.get(e.target);if(t&&n){if(e.kind===`DATA`){let[n,r]=$(t)===`TASK_INPUT`||$(t)===`EXTERNAL_INPUT`?[e.source,e.target]:[e.target,e.source];d.set(n,l.get(r)??0)}else if(e.kind===`DOC`){let t=$(n)===`DOCUMENT`?e.target:e.source,r=t===e.target?e.source:e.target;d.set(t,l.get(r)??0)}}}let f=c.map(e=>({name:e,nodes:[]}));for(let[e,t]of i)f[l.get(e)??d.get(e)??0]?.nodes.push(t);let p={name:e.getAttribute(`name`)||e.getAttribute(`id`)||``,lanes:f,connections:u};return Ze(p),Qe(p),p}function Ze(e){let t=new Map;for(let n of e.lanes)for(let e of n.nodes)t.has(e.label)||t.set(e.label,e);for(let n of e.connections){let e=t.get(n.source),r=t.get(n.target);if(!e||!r)continue;let i=$(e),a=$(r),o=a===`DOCUMENT`||i===`DOCUMENT`?`DOC`:P.has(a)||P.has(i)?`DATA`:`FLOW`;if(n.kind=o,o===`FLOW`)continue;let[s,c,l]=P.has(a)?[r,e,`out`]:[e,r,`in`];if(!fe.has($(c)))continue;let u=$(s);u===`DATA_OBJECT`?s.type=l===`out`?`TASK_OUTPUT`:`TASK_INPUT`:u===`EXTERNAL_DATA_OBJECT`&&(s.type=l===`out`?`PROCESS_OUTPUT`:`EXTERNAL_INPUT`),s._task===void 0&&(s._task=c.label),s._dir===void 0&&(s._dir=o===`DOC`?`doc`:l)}for(let e of t.values()){let t=$(e);P.has(t)&&e._dir===void 0&&(e._dir={TASK_INPUT:`in`,EXTERNAL_INPUT:`in`,DOCUMENT:`doc`}[t]??`out`,t===`DATA_OBJECT`?e.type=`TASK_INPUT`:t===`EXTERNAL_DATA_OBJECT`&&(e.type=`EXTERNAL_INPUT`))}return e}function Qe(e){let t=new Map;for(let n of e.lanes)for(let e of n.nodes)t.has(e.label)||t.set(e.label,e);let n=new Map;for(let r of e.connections)(r.kind||`FLOW`).toUpperCase()===`FLOW`&&t.has(r.source)&&t.has(r.target)&&n.set(r.target,[...n.get(r.target)??[],r.source]);let r=e=>{let r=new Set([e]),i=[...n.get(e)??[]];for(;i.length;){let e=i.shift();if(r.has(e))continue;r.add(e);let a=t.get(e);if(a&&Ke.has($(a)))return e;i.push(...(n.get(e)??[]).filter(e=>!r.has(e)))}return null},i=[];for(let n of e.connections){let e=(n.kind||`FLOW`).toUpperCase();if(e!==`DATA`&&e!==`DOC`){i.push(n);continue}let a=t.get(n.source),o=t.get(n.target);if(!a||!o){i.push(n);continue}let s,c;if(e===`DOC`){if($(a)===`DOCUMENT`)[s,c]=[n.source,n.target];else if($(o)===`DOCUMENT`)[s,c]=[n.target,n.source];else{i.push(n);continue}}else{if(P.has($(a))&&P.has($(o))){i.push(n);continue}s=P.has($(a))?n.source:n.target,c=P.has($(a))?n.target:n.source}let l=c===n.source;if(Ke.has($(t.get(c)))){i.push(n);continue}let u=r(c);if(u===null)continue;n=l?{...n,source:u}:{...n,target:u};let d=t.get(s);d&&(d._task=u),i.push(n)}e.connections=i}function $e(e,t,n){let r=t.x+t.w/2,i=t.y+t.h/2,a=[[`top`,Math.abs(i-e.y)],[`bottom`,Math.abs(i-(e.y+e.h))],[`left`,Math.abs(r-e.x)],[`right`,Math.abs(r-(e.x+e.w))]].reduce((e,t)=>t[1]<e[1]?t:e)[0],o=e=>Math.min(1,Math.max(0,e)),s=a===`top`||a===`bottom`,c=o(s?(r-e.x)/(e.w||1):(i-e.y)/(e.h||1)),l=s?n.x+c*n.w:a===`left`?n.x:n.x+n.w,u=s?a===`top`?n.y:n.y+n.h:n.y+c*n.h;return{x:Math.round(l-t.w/2),y:Math.round(u-t.h/2),w:t.w,h:t.h}}function et(e,t){let n=new Map;for(let e of t)e.bounds&&n.set(e.element,e.bounds);let r=[],i=[];for(let t of e.getAll()){if(t.type!==`bpmn:BoundaryEvent`||!t.host)continue;let e=n.get(t.host);if(!e)continue;let a=$e({x:t.host.x,y:t.host.y,w:t.host.width,h:t.host.height},{x:t.x,y:t.y,w:t.width,h:t.height},e);r.push({element:t,bounds:a}),i.push(t);let o=t.label;o&&r.push({element:o,bounds:{x:o.x+(a.x-t.x),y:o.y+(a.y-t.y),w:o.width,h:o.height}})}let a=new Set(i.map(e=>e.id));return{changes:r,reroute:e.getAll().filter(e=>e.waypoints&&e.source&&e.target&&(a.has(e.source.id)||a.has(e.target.id)))}}var tt=`bpmnCanvas.autoLayout`,nt={FLOW:[`bpmn:SequenceFlow`],DATA:[`bpmn:DataInputAssociation`,`bpmn:DataOutputAssociation`],DOC:[`bpmn:Association`]};function rt(e,t,n,r=[]){let i=t.x-n.pool.x,a=t.y-n.pool.y,o=e=>({x:e.x+i,y:e.y+a,w:e.w,h:e.h}),c=[{element:t,bounds:o(n.pool)}];e.getAll().filter(e=>e.type===`bpmn:Lane`&&e.parent===t).sort((e,t)=>e.y-t.y).forEach((e,t)=>{let r=n.lanes[t];r&&c.push({element:e,bounds:o(r[1])})});for(let[t,i]of Object.entries(n.nodes)){let a=e.get(t);if(!a){r.push(t);continue}c.push({element:a,bounds:o(i)});let s=n.labels[t];s&&a.label&&c.push({element:a.label,bounds:o(s)})}for(let[t,r]of Object.entries(n.apps)){let i=e.get(t),a=n.nodes[t];if(!i||!a)continue;let l=[...i.incoming??[],...i.outgoing??[]].filter(e=>e.type===`bpmn:Association`),u=0;for(let e of l){let t=e.source===i?e.target:e.source;if(t?.type!==`bpmn:TextAnnotation`||!s(t.businessObject?.text))continue;let n=o({...r,x:r.x+u*(r.w+4)});u+=1,c.push({element:t,bounds:n});let l=n.x+Math.floor(n.w/2),d=o(a),f=[[l,n.y],[l,d.y+d.h-20]];c.push({element:e,waypoints:e.source===t?f:[...f].reverse()})}}let l=new Map;for(let t of e.getAll())t.waypoints&&t.source&&t.target&&l.set(`${t.source.id}\u0000${t.target.id}\u0000${t.type}`,t);return n.connections.forEach((e,t)=>{let s=n.edges[t];if(!s?.length)return;let u=(nt[e.kind||`FLOW`]??[]).map(t=>l.get(`${e.source}\u0000${e.target}\u0000${t}`)??l.get(`${e.target}\u0000${e.source}\u0000${t}`)).find(Boolean);if(!u){r.push(`${e.source}->${e.target}`);return}let d=u.source?.id===e.source,f=s.map(([e,t])=>[e+i,t+a]);c.push({element:u,waypoints:d?f:[...f].reverse()});let p=n.edgeLabels[t];p&&u.label&&c.push({element:u.label,bounds:o(p)})}),c}function it(e,t){let n=new Map(Je(e).map(e=>[e.id,e.proc]));return t.getAll().filter(e=>e.type===`bpmn:Participant`&&e.businessObject?.processRef).map(e=>({participant:e,proc:n.get(e.businessObject.processRef.id)})).filter(e=>e.proc)}var at=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.w&&e.height===t.h,ot=(e,t)=>{let n=e.waypoints??[];return n.length===t.length&&t.every(([e,t],r)=>n[r]?.x===e&&n[r]?.y===t)},st=e=>e.type===`label`?e.labelTarget?.id:e.id,ct=class{static $inject=[`moddle`,`layouter`,`connectionDocking`,`graphicsFactory`,`elementRegistry`];moddle;layouter;docking;graphics;registry;constructor(e,t,n,r,i){this.moddle=e,this.layouter=t,this.docking=n,this.graphics=r,this.registry=i}boundsDi(e,t,n){if(e.type!==`label`)return i(e).bounds;let r=i(e.labelTarget);return!r.label&&t?(r.set(`label`,this.moddle.create(`bpmndi:BPMNLabel`,{bounds:this.moddle.create(`dc:Bounds`)})),n?.push(r)):r.label&&!r.label.bounds&&t&&r.label.set(`bounds`,this.moddle.create(`dc:Bounds`)),r.label?.bounds}setBounds(e,t,n,r){let i=this.boundsDi(e,!0,r);n.push({element:e,bounds:{x:e.x,y:e.y,width:e.width,height:e.height},di:i?{x:i.x,y:i.y,width:i.width,height:i.height}:void 0}),Object.assign(e,{x:t.x,y:t.y,width:t.w,height:t.h}),i&&Object.assign(i,{x:t.x,y:t.y,width:t.w,height:t.h})}setWaypoints(e,t,n){let r=i(e);n.push({element:e,waypoints:e.waypoints,diWaypoints:r.waypoint}),e.waypoints=t.map(({x:e,y:t})=>({x:e,y:t})),r.set(`waypoint`,t.map(({x:e,y:t})=>this.moddle.create(`dc:Point`,{x:e,y:t})))}execute(e){let t=[],n=[];for(let r of e.changes)r.bounds&&this.setBounds(r.element,r.bounds,t,n),r.waypoints&&this.setWaypoints(r.element,r.waypoints.map(([e,t])=>({x:e,y:t})),t);for(let r of e.reroute??[]){let e=r.source?.type===`bpmn:BoundaryEvent`||r.target?.type===`bpmn:BoundaryEvent`?{connectionStart:o(r.source),connectionEnd:o(r.target),waypoints:[]}:{},i=this.layouter.layoutConnection(r,e),s={...r,waypoints:i};this.setWaypoints(r,this.docking.getCroppedWaypoints(s,r.source,r.target),t);let c=r.label;if(c){let e=a(r);this.setBounds(c,{x:Math.round(e.x-c.width/2),y:Math.round(e.y-c.height/2),w:c.width,h:c.height},t,n)}}e.saved=t,e.createdLabels=n;let r=[...e.changes.map(e=>e.element),...e.reroute??[],...(e.reroute??[]).map(e=>e.label)];return[...new Set(r.filter(Boolean))]}revert(e){for(let t of[...e.saved??[]].reverse()){let e=t.element;if(t.bounds){Object.assign(e,t.bounds);let n=this.boundsDi(e,!1);n&&t.di&&Object.assign(n,t.di)}t.waypoints&&(e.waypoints=t.waypoints,i(e).set(`waypoint`,t.diWaypoints))}for(let t of e.createdLabels??[])delete t.label;let t=[...e.changes.map(e=>e.element),...e.reroute??[],...(e.reroute??[]).map(e=>e.label)],n=[];for(let e of new Set(t.filter(Boolean)))if(e.type===`label`){let t=this.registry.getGraphics(e);t&&this.graphics.update(`shape`,e,t)}else n.push(e);return n}},lt=()=>new DOMException(`Layout superseded or canvas destroyed`,`AbortError`),ut=class{static $inject=[`commandStack`,`elementRegistry`,`bpmnjs`,`eventBus`];commandStack;registry;bpmnjs;generation=0;destroyed=!1;constructor(e,t,n,r){e.registerHandler(tt,ct),this.commandStack=e,this.registry=t,this.bpmnjs=n,r.on([`diagram.clear`,`import.parse.start`,`root.set`,`commandStack.changed`],()=>{this.generation+=1}),r.on(`diagram.destroy`,()=>{this.destroyed=!0,this.generation+=1})}async run(e=()=>!0){if(this.destroyed)throw lt();let t=++this.generation,n=()=>!this.destroyed&&t===this.generation&&e(),{xml:r}=await this.bpmnjs.saveXML();if(!n())throw lt();let i=[],a=[];for(let{participant:e,proc:t}of it(r,this.registry)){let r=await Ve(t);if(!n())throw lt();i.push(...rt(this.registry,e,r,a))}let o=et(this.registry,i);i.push(...o.changes);let s=i.length?[...new Set([...this.registry.getAll().filter(e=>e.type===`bpmn:MessageFlow`&&e.source&&e.target),...o.reroute])]:[],c=new Set([...i.map(e=>st(e.element)),...s.map(e=>e.id)]),l=i.filter(e=>e.bounds?!at(e.element,e.bounds):e.waypoints?!ot(e.element,e.waypoints):!1),u=new Set(l.map(e=>st(e.element))).size,d=new Set(a);for(let e of this.registry.getAll())e.parent&&e.type!==`label`&&(c.has(e.id)||d.add(e.id));return l.length&&this.commandStack.execute(tt,{changes:l,reroute:s}),{changed:u,skipped:[...d].sort()}}},dt={__init__:[`bpmnCanvasLayout`],bpmnCanvasLayout:[`type`,ut]};export{ct as AutoLayoutHandler,ut as BpmnCanvasLayout,dt as BpmnCanvasLayoutModule,rt as layoutChanges,it as processesByParticipant};