@vscada/core 0.0.1

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 (145) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/a11y/contrast.d.ts +11 -0
  3. package/dist/a11y/contrast.d.ts.map +1 -0
  4. package/dist/a11y/live-region.d.ts +42 -0
  5. package/dist/a11y/live-region.d.ts.map +1 -0
  6. package/dist/a11y/reduced-motion.d.ts +55 -0
  7. package/dist/a11y/reduced-motion.d.ts.map +1 -0
  8. package/dist/a11y/static-representation-registry.d.ts +20 -0
  9. package/dist/a11y/static-representation-registry.d.ts.map +1 -0
  10. package/dist/bindings/binding-fixture.d.ts +3 -0
  11. package/dist/bindings/binding-fixture.d.ts.map +1 -0
  12. package/dist/bindings/binding-types.d.ts +52 -0
  13. package/dist/bindings/binding-types.d.ts.map +1 -0
  14. package/dist/bindings/color-ramp.d.ts +9 -0
  15. package/dist/bindings/color-ramp.d.ts.map +1 -0
  16. package/dist/bindings/transforms.d.ts +103 -0
  17. package/dist/bindings/transforms.d.ts.map +1 -0
  18. package/dist/constants-DMdpoOyH.js +4 -0
  19. package/dist/contracts/connection-renderer.d.ts +16 -0
  20. package/dist/contracts/connection-renderer.d.ts.map +1 -0
  21. package/dist/contracts/connection-state.d.ts +8 -0
  22. package/dist/contracts/connection-state.d.ts.map +1 -0
  23. package/dist/contracts/handles.d.ts +83 -0
  24. package/dist/contracts/handles.d.ts.map +1 -0
  25. package/dist/contracts/primitive.d.ts +37 -0
  26. package/dist/contracts/primitive.d.ts.map +1 -0
  27. package/dist/contracts/renderer.d.ts +34 -0
  28. package/dist/contracts/renderer.d.ts.map +1 -0
  29. package/dist/contracts/tag-value.d.ts +33 -0
  30. package/dist/contracts/tag-value.d.ts.map +1 -0
  31. package/dist/contracts/time-source.d.ts +14 -0
  32. package/dist/contracts/time-source.d.ts.map +1 -0
  33. package/dist/custom-elements.json +1068 -0
  34. package/dist/export/svg-export.d.ts +24 -0
  35. package/dist/export/svg-export.d.ts.map +1 -0
  36. package/dist/fsm/fsm.d.ts +45 -0
  37. package/dist/fsm/fsm.d.ts.map +1 -0
  38. package/dist/fsm/tween.d.ts +39 -0
  39. package/dist/fsm/tween.d.ts.map +1 -0
  40. package/dist/import/load-svg-import.d.ts +22 -0
  41. package/dist/import/load-svg-import.d.ts.map +1 -0
  42. package/dist/import/svg-source-registry.d.ts +4 -0
  43. package/dist/import/svg-source-registry.d.ts.map +1 -0
  44. package/dist/index.d.ts +61 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +4549 -0
  47. package/dist/interaction/gesture-arbiter.d.ts +20 -0
  48. package/dist/interaction/gesture-arbiter.d.ts.map +1 -0
  49. package/dist/interaction/hit-area.d.ts +44 -0
  50. package/dist/interaction/hit-area.d.ts.map +1 -0
  51. package/dist/interaction/pan-zoom-gestures.d.ts +43 -0
  52. package/dist/interaction/pan-zoom-gestures.d.ts.map +1 -0
  53. package/dist/interaction/pointer-pipeline.d.ts +38 -0
  54. package/dist/interaction/pointer-pipeline.d.ts.map +1 -0
  55. package/dist/license/console-notice.d.ts +15 -0
  56. package/dist/license/console-notice.d.ts.map +1 -0
  57. package/dist/license/format.d.ts +29 -0
  58. package/dist/license/format.d.ts.map +1 -0
  59. package/dist/license/state.d.ts +43 -0
  60. package/dist/license/state.d.ts.map +1 -0
  61. package/dist/license/vendor-keys.d.ts +12 -0
  62. package/dist/license/vendor-keys.d.ts.map +1 -0
  63. package/dist/license/verify-fallback.d.ts +31 -0
  64. package/dist/license/verify-fallback.d.ts.map +1 -0
  65. package/dist/license/verify-webcrypto.d.ts +4 -0
  66. package/dist/license/verify-webcrypto.d.ts.map +1 -0
  67. package/dist/license/watermark.d.ts +20 -0
  68. package/dist/license/watermark.d.ts.map +1 -0
  69. package/dist/media/registry.d.ts +97 -0
  70. package/dist/media/registry.d.ts.map +1 -0
  71. package/dist/registry/connection-registry.d.ts +5 -0
  72. package/dist/registry/connection-registry.d.ts.map +1 -0
  73. package/dist/registry/element-catalog.d.ts +805 -0
  74. package/dist/registry/element-catalog.d.ts.map +1 -0
  75. package/dist/registry/primitive-registry.d.ts +7 -0
  76. package/dist/registry/primitive-registry.d.ts.map +1 -0
  77. package/dist/registry/theme-registry.d.ts +6 -0
  78. package/dist/registry/theme-registry.d.ts.map +1 -0
  79. package/dist/registry.d.ts +8 -0
  80. package/dist/registry.d.ts.map +1 -0
  81. package/dist/scada-view.d.ts +322 -0
  82. package/dist/scada-view.d.ts.map +1 -0
  83. package/dist/scene/connection-geometry.d.ts +95 -0
  84. package/dist/scene/connection-geometry.d.ts.map +1 -0
  85. package/dist/scene/constants.d.ts +10 -0
  86. package/dist/scene/constants.d.ts.map +1 -0
  87. package/dist/scene/crossing-jumps.d.ts +85 -0
  88. package/dist/scene/crossing-jumps.d.ts.map +1 -0
  89. package/dist/scene/dev-validate.d.ts +24 -0
  90. package/dist/scene/dev-validate.d.ts.map +1 -0
  91. package/dist/scene/errors.d.ts +15 -0
  92. package/dist/scene/errors.d.ts.map +1 -0
  93. package/dist/scene/groups.d.ts +90 -0
  94. package/dist/scene/groups.d.ts.map +1 -0
  95. package/dist/scene/lane-offset.d.ts +69 -0
  96. package/dist/scene/lane-offset.d.ts.map +1 -0
  97. package/dist/scene/orthogonal-router.d.ts +63 -0
  98. package/dist/scene/orthogonal-router.d.ts.map +1 -0
  99. package/dist/scene/scene-schema.d.ts +881 -0
  100. package/dist/scene/scene-schema.d.ts.map +1 -0
  101. package/dist/scene/structural-validator.d.ts +25 -0
  102. package/dist/scene/structural-validator.d.ts.map +1 -0
  103. package/dist/scene/validate-scene.d.ts +26 -0
  104. package/dist/scene/validate-scene.d.ts.map +1 -0
  105. package/dist/scene-authoring.d.ts +12 -0
  106. package/dist/scene-authoring.d.ts.map +1 -0
  107. package/dist/scene-authoring.js +952 -0
  108. package/dist/scheduler/alarm-band.d.ts +33 -0
  109. package/dist/scheduler/alarm-band.d.ts.map +1 -0
  110. package/dist/scheduler/animation-registry.d.ts +38 -0
  111. package/dist/scheduler/animation-registry.d.ts.map +1 -0
  112. package/dist/scheduler/lod.d.ts +25 -0
  113. package/dist/scheduler/lod.d.ts.map +1 -0
  114. package/dist/scheduler/quality-overlay.d.ts +19 -0
  115. package/dist/scheduler/quality-overlay.d.ts.map +1 -0
  116. package/dist/scheduler/quality.d.ts +15 -0
  117. package/dist/scheduler/quality.d.ts.map +1 -0
  118. package/dist/scheduler/scheduler.d.ts +243 -0
  119. package/dist/scheduler/scheduler.d.ts.map +1 -0
  120. package/dist/scheduler/visual-state-resolver.d.ts +31 -0
  121. package/dist/scheduler/visual-state-resolver.d.ts.map +1 -0
  122. package/dist/store/value-store.d.ts +65 -0
  123. package/dist/store/value-store.d.ts.map +1 -0
  124. package/dist/tokens.d.ts +703 -0
  125. package/dist/tokens.d.ts.map +1 -0
  126. package/dist/topology/graph.d.ts +33 -0
  127. package/dist/topology/graph.d.ts.map +1 -0
  128. package/dist/topology/group-collapse.d.ts +15 -0
  129. package/dist/topology/group-collapse.d.ts.map +1 -0
  130. package/dist/topology/inference.d.ts +71 -0
  131. package/dist/topology/inference.d.ts.map +1 -0
  132. package/dist/topology/traversal.d.ts +29 -0
  133. package/dist/topology/traversal.d.ts.map +1 -0
  134. package/dist/topology/upstream-highlight.d.ts +75 -0
  135. package/dist/topology/upstream-highlight.d.ts.map +1 -0
  136. package/dist/units/formatter.d.ts +22 -0
  137. package/dist/units/formatter.d.ts.map +1 -0
  138. package/dist/units/registry.d.ts +21 -0
  139. package/dist/units/registry.d.ts.map +1 -0
  140. package/dist/view/group-view-state.d.ts +77 -0
  141. package/dist/view/group-view-state.d.ts.map +1 -0
  142. package/dist/view/viewport-state.d.ts +112 -0
  143. package/dist/view/viewport-state.d.ts.map +1 -0
  144. package/dist/vscada.umd.cjs +45 -0
  145. package/package.json +37 -0
@@ -0,0 +1,45 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.VScada={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=globalThis,n=t.ShadowRoot&&(t.ShadyCSS===void 0||t.ShadyCSS.nativeShadow)&&`adoptedStyleSheets`in Document.prototype&&`replace`in CSSStyleSheet.prototype,r=Symbol(),i=new WeakMap,a=class{constructor(e,t,n){if(this._$cssResult$=!0,n!==r)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o,t=this.t;if(n&&e===void 0){let n=t!==void 0&&t.length===1;n&&(e=i.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),n&&i.set(t,e))}return e}toString(){return this.cssText}},o=e=>new a(typeof e==`string`?e:e+``,void 0,r),s=(e,...t)=>new a(e.length===1?e[0]:t.reduce((t,n,r)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if(typeof e==`number`)return e;throw Error(`Value passed to 'css' function must be a 'css' function result: `+e+`. Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.`)})(n)+e[r+1],e[0]),e,r),c=(e,r)=>{if(n)e.adoptedStyleSheets=r.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(let n of r){let r=document.createElement(`style`),i=t.litNonce;i!==void 0&&r.setAttribute(`nonce`,i),r.textContent=n.cssText,e.appendChild(r)}},l=n?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t=``;for(let n of e.cssRules)t+=n.cssText;return o(t)})(e):e,u,{is:d,defineProperty:f,getOwnPropertyDescriptor:p,getOwnPropertyNames:m,getOwnPropertySymbols:h,getPrototypeOf:g}=Object,_=globalThis,v=_.trustedTypes,y=v?v.emptyScript:``,ee=_.reactiveElementPolyfillSupport,b=(e,t)=>e,x={toAttribute(e,t){switch(t){case Boolean:e=e?y:null;break;case Object:case Array:e=e==null?e:JSON.stringify(e)}return e},fromAttribute(e,t){let n=e;switch(t){case Boolean:n=e!==null;break;case Number:n=e===null?null:Number(e);break;case Object:case Array:try{n=JSON.parse(e)}catch{n=null}}return n}},S=(e,t)=>!d(e,t),te={attribute:!0,type:String,converter:x,reflect:!1,useDefault:!1,hasChanged:S};(u=Symbol).metadata??(u.metadata=Symbol(`metadata`)),_.litPropertyMetadata??(_.litPropertyMetadata=new WeakMap);var C=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??(this.l=[])).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=te){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){let n=Symbol(),r=this.getPropertyDescriptor(e,n,t);r!==void 0&&f(this.prototype,e,r)}}static getPropertyDescriptor(e,t,n){let{get:r,set:i}=p(this.prototype,e)??{get(){return this[t]},set(e){this[t]=e}};return{get:r,set(t){let a=r?.call(this);i?.call(this,t),this.requestUpdate(e,a,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??te}static _$Ei(){if(this.hasOwnProperty(b(`elementProperties`)))return;let e=g(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(b(`finalized`)))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(b(`properties`))){let e=this.properties,t=[...m(e),...h(e)];for(let n of t)this.createProperty(n,e[n])}let e=this[Symbol.metadata];if(e!==null){let t=litPropertyMetadata.get(e);if(t!==void 0)for(let[e,n]of t)this.elementProperties.set(e,n)}this._$Eh=new Map;for(let[e,t]of this.elementProperties){let n=this._$Eu(e,t);n!==void 0&&this._$Eh.set(n,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let t=[];if(Array.isArray(e)){let n=new Set(e.flat(1/0).reverse());for(let e of n)t.unshift(l(e))}else e!==void 0&&t.push(l(e));return t}static _$Eu(e,t){let n=t.attribute;return!1===n?void 0:typeof n==`string`?n:typeof e==`string`?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??(this._$EO=new Set)).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,t=this.constructor.elementProperties;for(let n of t.keys())this.hasOwnProperty(n)&&(e.set(n,this[n]),delete this[n]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return c(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,t,n){this._$AK(e,n)}_$ET(e,t){let n=this.constructor.elementProperties.get(e),r=this.constructor._$Eu(e,n);if(r!==void 0&&!0===n.reflect){let i=(n.converter?.toAttribute===void 0?x:n.converter).toAttribute(t,n.type);this._$Em=e,i==null?this.removeAttribute(r):this.setAttribute(r,i),this._$Em=null}}_$AK(e,t){let n=this.constructor,r=n._$Eh.get(e);if(r!==void 0&&this._$Em!==r){let e=n.getPropertyOptions(r),i=typeof e.converter==`function`?{fromAttribute:e.converter}:e.converter?.fromAttribute===void 0?x:e.converter;this._$Em=r;let a=i.fromAttribute(t,e.type);this[r]=a??this._$Ej?.get(r)??a,this._$Em=null}}requestUpdate(e,t,n,r=!1,i){if(e!==void 0){let a=this.constructor;if(!1===r&&(i=this[e]),n??(n=a.getPropertyOptions(e)),!((n.hasChanged??S)(i,t)||n.useDefault&&n.reflect&&i===this._$Ej?.get(e)&&!this.hasAttribute(a._$Eu(e,n))))return;this.C(e,t,n)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(e,t,{useDefault:n,reflect:r,wrapped:i},a){n&&!(this._$Ej??(this._$Ej=new Map)).has(e)&&(this._$Ej.set(e,a??t??this[e]),!0!==i||a!==void 0)||(this._$AL.has(e)||(this.hasUpdated||n||(t=void 0),this._$AL.set(e,t)),!0===r&&this._$Em!==e&&(this._$Eq??(this._$Eq=new Set)).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(let[e,t]of this._$Ep)this[e]=t;this._$Ep=void 0}let e=this.constructor.elementProperties;if(e.size>0)for(let[t,n]of e){let{wrapped:e}=n,r=this[t];!0!==e||this._$AL.has(t)||r===void 0||this.C(t,void 0,n,r)}}let e=!1,t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),this._$EO?.forEach(e=>e.hostUpdate?.()),this.update(t)):this._$EM()}catch(t){throw e=!1,this._$EM(),t}e&&this._$AE(t)}willUpdate(e){}_$AE(e){this._$EO?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&(this._$Eq=this._$Eq.forEach(e=>this._$ET(e,this[e]))),this._$EM()}updated(e){}firstUpdated(e){}};C.elementStyles=[],C.shadowRootOptions={mode:`open`},C[b(`elementProperties`)]=new Map,C[b(`finalized`)]=new Map,ee?.({ReactiveElement:C}),(_.reactiveElementVersions??(_.reactiveElementVersions=[])).push(`2.1.2`);var w=globalThis,T=e=>e,ne=w.trustedTypes,re=ne?ne.createPolicy(`lit-html`,{createHTML:e=>e}):void 0,ie=`$lit$`,E=`lit$${Math.random().toFixed(9).slice(2)}$`,ae=`?`+E,oe=`<${ae}>`,D=document,se=()=>D.createComment(``),ce=e=>e===null||typeof e!=`object`&&typeof e!=`function`,le=Array.isArray,ue=e=>le(e)||typeof e?.[Symbol.iterator]==`function`,de=`[
2
+ \f\r]`,fe=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,pe=/-->/g,me=/>/g,O=RegExp(`>|${de}(?:([^\\s"'>=/]+)(${de}*=${de}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,`g`),he=/'/g,ge=/"/g,_e=/^(?:script|style|textarea|title)$/i,ve=(e=>(t,...n)=>({_$litType$:e,strings:t,values:n}))(1),ye=Symbol.for(`lit-noChange`),k=Symbol.for(`lit-nothing`),be=new WeakMap,A=D.createTreeWalker(D,129);function xe(e,t){if(!le(e)||!e.hasOwnProperty(`raw`))throw Error(`invalid template strings array`);return re===void 0?t:re.createHTML(t)}var Se=(e,t)=>{let n=e.length-1,r=[],i,a=t===2?`<svg>`:t===3?`<math>`:``,o=fe;for(let t=0;t<n;t++){let n=e[t],s,c,l=-1,u=0;for(;u<n.length&&(o.lastIndex=u,c=o.exec(n),c!==null);)u=o.lastIndex,o===fe?c[1]===`!--`?o=pe:c[1]===void 0?c[2]===void 0?c[3]!==void 0&&(o=O):(_e.test(c[2])&&(i=RegExp(`</`+c[2],`g`)),o=O):o=me:o===O?c[0]===`>`?(o=i??fe,l=-1):c[1]===void 0?l=-2:(l=o.lastIndex-c[2].length,s=c[1],o=c[3]===void 0?O:c[3]===`"`?ge:he):o===ge||o===he?o=O:o===pe||o===me?o=fe:(o=O,i=void 0);let d=o===O&&e[t+1].startsWith(`/>`)?` `:``;a+=o===fe?n+oe:l>=0?(r.push(s),n.slice(0,l)+ie+n.slice(l)+E+d):n+E+(l===-2?t:d)}return[xe(e,a+(e[n]||`<?>`)+(t===2?`</svg>`:t===3?`</math>`:``)),r]},Ce=class e{constructor({strings:t,_$litType$:n},r){let i;this.parts=[];let a=0,o=0,s=t.length-1,c=this.parts,[l,u]=Se(t,n);if(this.el=e.createElement(l,r),A.currentNode=this.el.content,n===2||n===3){let e=this.el.content.firstChild;e.replaceWith(...e.childNodes)}for(;(i=A.nextNode())!==null&&c.length<s;){if(i.nodeType===1){if(i.hasAttributes())for(let e of i.getAttributeNames())if(e.endsWith(ie)){let t=u[o++],n=i.getAttribute(e).split(E),r=/([.?@])?(.*)/.exec(t);c.push({type:1,index:a,name:r[2],strings:n,ctor:r[1]===`.`?Oe:r[1]===`?`?ke:r[1]===`@`?Ae:De}),i.removeAttribute(e)}else e.startsWith(E)&&(c.push({type:6,index:a}),i.removeAttribute(e));if(_e.test(i.tagName)){let e=i.textContent.split(E),t=e.length-1;if(t>0){i.textContent=ne?ne.emptyScript:``;for(let n=0;n<t;n++)i.append(e[n],se()),A.nextNode(),c.push({type:2,index:++a});i.append(e[t],se())}}}else if(i.nodeType===8)if(i.data===ae)c.push({type:2,index:a});else{let e=-1;for(;(e=i.data.indexOf(E,e+1))!==-1;)c.push({type:7,index:a}),e+=E.length-1}a++}}static createElement(e,t){let n=D.createElement(`template`);return n.innerHTML=e,n}};function we(e,t,n=e,r){if(t===ye)return t;let i=r===void 0?n._$Cl:n._$Co?.[r],a=ce(t)?void 0:t._$litDirective$;return i?.constructor!==a&&(i?._$AO?.(!1),a===void 0?i=void 0:(i=new a(e),i._$AT(e,n,r)),r===void 0?n._$Cl=i:(n._$Co??(n._$Co=[]))[r]=i),i!==void 0&&(t=we(e,i._$AS(e,t.values),i,r)),t}var Te=class{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){let{el:{content:t},parts:n}=this._$AD,r=(e?.creationScope??D).importNode(t,!0);A.currentNode=r;let i=A.nextNode(),a=0,o=0,s=n[0];for(;s!==void 0;){if(a===s.index){let t;s.type===2?t=new Ee(i,i.nextSibling,this,e):s.type===1?t=new s.ctor(i,s.name,s.strings,this,e):s.type===6&&(t=new je(i,this,e)),this._$AV.push(t),s=n[++o]}a!==s?.index&&(i=A.nextNode(),a++)}return A.currentNode=D,r}p(e){let t=0;for(let n of this._$AV)n!==void 0&&(n.strings===void 0?n._$AI(e[t]):(n._$AI(e,n,t),t+=n.strings.length-2)),t++}},Ee=class e{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,t,n,r){this.type=2,this._$AH=k,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=n,this.options=r,this._$Cv=r?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode,t=this._$AM;return t!==void 0&&e?.nodeType===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=we(this,e,t),ce(e)?e===k||e==null||e===``?(this._$AH!==k&&this._$AR(),this._$AH=k):e!==this._$AH&&e!==ye&&this._(e):e._$litType$===void 0?e.nodeType===void 0?ue(e)?this.k(e):this._(e):this.T(e):this.$(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==k&&ce(this._$AH)?this._$AA.nextSibling.data=e:this.T(D.createTextNode(e)),this._$AH=e}$(e){let{values:t,_$litType$:n}=e,r=typeof n==`number`?this._$AC(e):(n.el===void 0&&(n.el=Ce.createElement(xe(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===r)this._$AH.p(t);else{let e=new Te(r,this),n=e.u(this.options);e.p(t),this.T(n),this._$AH=e}}_$AC(e){let t=be.get(e.strings);return t===void 0&&be.set(e.strings,t=new Ce(e)),t}k(t){le(this._$AH)||(this._$AH=[],this._$AR());let n=this._$AH,r,i=0;for(let a of t)i===n.length?n.push(r=new e(this.O(se()),this.O(se()),this,this.options)):r=n[i],r._$AI(a),i++;i<n.length&&(this._$AR(r&&r._$AB.nextSibling,i),n.length=i)}_$AR(e=this._$AA.nextSibling,t){for(this._$AP?.(!1,!0,t);e!==this._$AB;){let t=T(e).nextSibling;T(e).remove(),e=t}}setConnected(e){this._$AM===void 0&&(this._$Cv=e,this._$AP?.(e))}},De=class{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,n,r,i){this.type=1,this._$AH=k,this._$AN=void 0,this.element=e,this.name=t,this._$AM=r,this.options=i,n.length>2||n[0]!==``||n[1]!==``?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=k}_$AI(e,t=this,n,r){let i=this.strings,a=!1;if(i===void 0)e=we(this,e,t,0),a=!ce(e)||e!==this._$AH&&e!==ye,a&&(this._$AH=e);else{let r=e,o,s;for(e=i[0],o=0;o<i.length-1;o++)s=we(this,r[n+o],t,o),s===ye&&(s=this._$AH[o]),a||(a=!ce(s)||s!==this._$AH[o]),s===k?e=k:e!==k&&(e+=(s??``)+i[o+1]),this._$AH[o]=s}a&&!r&&this.j(e)}j(e){e===k?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??``)}},Oe=class extends De{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===k?void 0:e}},ke=class extends De{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==k)}},Ae=class extends De{constructor(e,t,n,r,i){super(e,t,n,r,i),this.type=5}_$AI(e,t=this){if((e=we(this,e,t,0)??k)===ye)return;let n=this._$AH,r=e===k&&n!==k||e.capture!==n.capture||e.once!==n.once||e.passive!==n.passive,i=e!==k&&(n===k||r);r&&this.element.removeEventListener(this.name,this,n),i&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){typeof this._$AH==`function`?this._$AH.call(this.options?.host??this.element,e):this._$AH.handleEvent(e)}},je=class{constructor(e,t,n){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(e){we(this,e)}},Me=w.litHtmlPolyfillSupport;Me?.(Ce,Ee),(w.litHtmlVersions??(w.litHtmlVersions=[])).push(`3.3.3`);var Ne=(e,t,n)=>{let r=n?.renderBefore??t,i=r._$litPart$;if(i===void 0){let e=n?.renderBefore??null;r._$litPart$=i=new Ee(t.insertBefore(se(),e),e,void 0,n??{})}return i._$AI(e),i},Pe=globalThis,Fe=class extends C{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var e;let t=super.createRenderRoot();return(e=this.renderOptions).renderBefore??(e.renderBefore=t.firstChild),t}update(e){let t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=Ne(t,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return ye}};Fe._$litElement$=!0,Fe.finalized=!0,Pe.litElementHydrateSupport?.({LitElement:Fe});var Ie=Pe.litElementPolyfillSupport;Ie?.({LitElement:Fe}),(Pe.litElementVersions??(Pe.litElementVersions=[])).push(`4.2.2`);var Le=[`MISSING_VERSION`,`UNSUPPORTED_VERSION`,`BAD_SHAPE`,`DUPLICATE_ID`,`UNKNOWN_TYPE`,`UNRESOLVED_PORT`,`UNRESOLVED_TOPOLOGY_REF`,`AMBIGUOUS_GROUP_PORT_MAP`,`UNRESOLVED_GROUP_PORT_MAP`,`AMBIGUOUS_GROUP_CHILD`];function j(e,t,n){return{code:e,message:t,path:n}}var Re=[`1.0`],ze=new Set(Re),Be=new Set([`off-page`,`svg-import`]);function M(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ve(e){return M(e)&&typeof e.x==`number`&&Number.isFinite(e.x)&&typeof e.y==`number`&&Number.isFinite(e.y)&&typeof e.dir==`string`&&[`up`,`down`,`left`,`right`].includes(e.dir)}function He(e,t){if(e===void 0)return null;if(!M(e))return j(`BAD_SHAPE`,`${t}.ports must be an object of named ports`,`${t}.ports`);for(let[n,r]of Object.entries(e))if(!Ve(r))return j(`BAD_SHAPE`,`${t}.ports.${n} must be { x: number, y: number, dir: 'up'|'down'|'left'|'right' }`,`${t}.ports.${n}`);return null}function Ue(e,t){if(!M(e))return{ok:!1,error:j(`BAD_SHAPE`,`Scene must be an object`,``)};if(e.version===void 0||e.version===null||e.version===``)return{ok:!1,error:j(`MISSING_VERSION`,`Scene is missing required "version" field`,`version`)};if(typeof e.version!=`string`||!ze.has(e.version))return{ok:!1,error:j(`UNSUPPORTED_VERSION`,`Scene version "${String(e.version)}" is not supported`,`version`)};if(e.id===void 0||typeof e.id!=`string`||e.id.length===0)return{ok:!1,error:j(`BAD_SHAPE`,`Scene is missing required string "id"`,`id`)};if(!M(e.canvas)||typeof e.canvas.width!=`number`||!Number.isFinite(e.canvas.width)||typeof e.canvas.height!=`number`||!Number.isFinite(e.canvas.height))return{ok:!1,error:j(`BAD_SHAPE`,`Scene "canvas" must be { width: number, height: number }`,`canvas`)};let n=e.elements??[];if(!Array.isArray(n))return{ok:!1,error:j(`BAD_SHAPE`,`Scene "elements" must be an array`,`elements`)};let r=e.groups??[];if(!Array.isArray(r))return{ok:!1,error:j(`BAD_SHAPE`,`Scene "groups" must be an array`,`groups`)};let i=e.connections??[];if(!Array.isArray(i))return{ok:!1,error:j(`BAD_SHAPE`,`Scene "connections" must be an array`,`connections`)};let a=[];for(let e=0;e<n.length;e++){let t=n[e],r=`elements[${e}]`;if(!M(t)||typeof t.id!=`string`||t.id.length===0)return{ok:!1,error:j(`BAD_SHAPE`,`${r} must be an object with a non-empty string "id"`,`${r}.id`)};if(typeof t.type!=`string`||t.type.length===0)return{ok:!1,error:j(`BAD_SHAPE`,`${r} must declare a non-empty string "type"`,`${r}.type`)};let i=He(t.ports,r);if(i)return{ok:!1,error:i};a.push({id:t.id,type:t.type,ports:M(t.ports)?t.ports:{}})}for(let e=0;e<r.length;e++){let t=r[e],n=`groups[${e}]`;if(!M(t)||typeof t.id!=`string`||t.id.length===0)return{ok:!1,error:j(`BAD_SHAPE`,`${n} must be an object with a non-empty string "id"`,`${n}.id`)};if(t.children!==void 0&&!Array.isArray(t.children))return{ok:!1,error:j(`BAD_SHAPE`,`${n}.children must be an array of element ids`,`${n}.children`)};let i=He(t.ports,n);if(i)return{ok:!1,error:i};a.push({id:t.id,type:`group`,ports:M(t.ports)?t.ports:{}})}let o=new Map;for(let e of a){if(o.get(e.id)!==void 0)return{ok:!1,error:j(`DUPLICATE_ID`,`Duplicate element/group id "${e.id}"`,`id:${e.id}`)};o.set(e.id,e.id)}let s=new Map(a.map(e=>[e.id,e])),c=new Map;for(let e=0;e<r.length;e++){let t=r[e],n=`groups[${e}]`,i=t.id,a=Array.isArray(t.children)?t.children.filter(e=>typeof e==`string`):[],o=M(t.ports)?t.ports:{},l=M(t.portMap)?t.portMap:{};for(let e of a){let t=c.get(e);if(t!==void 0)return{ok:!1,error:j(`AMBIGUOUS_GROUP_CHILD`,`Child id "${e}" is declared under more than one group ("${t}" and "${i}")`,`${n}.children`)};c.set(e,i)}let u=new Map;for(let[e,t]of Object.entries(l)){let r=`${n}.portMap.${e}`;if(typeof t!=`string`)continue;if(!(e in o))return{ok:!1,error:j(`UNRESOLVED_GROUP_PORT_MAP`,`Group "${i}" portMap key "${e}" does not match any port declared on the group itself`,r)};let c=t.indexOf(`.`),l=c<0?t:t.slice(0,c),d=c<0?``:t.slice(c+1),f=l.length>0?s.get(l):void 0;if(c<0||l.length===0||d.length===0||!a.includes(l)||!f||!(d in f.ports))return{ok:!1,error:j(`UNRESOLVED_GROUP_PORT_MAP`,`Group "${i}" portMap["${e}"]="${t}" does not resolve to a real port on a child declared in this group's "children"`,r)};let p=`${l}.${d}`,m=u.get(p);if(m!==void 0)return{ok:!1,error:j(`AMBIGUOUS_GROUP_PORT_MAP`,`Group "${i}" maps both "${m}" and "${e}" to the same interior port "${p}"`,r)};u.set(p,e)}}for(let e=0;e<n.length;e++){let r=n[e],i=r.type;if(!Be.has(i)&&!t.has(i))return{ok:!1,error:j(`UNKNOWN_TYPE`,`Element "${r.id}" has unknown type "${i}" — is its primitive group registered via registerPrimitives()?`,`elements[${e}].type`)};if(i===`off-page`){let t=`elements[${e}]`,n=r.target;if(!M(n)||typeof n.scene!=`string`||typeof n.port!=`string`)return{ok:!1,error:j(`BAD_SHAPE`,`${t} (off-page) must declare "target": { scene: string, port: string }`,`${t}.target`)}}}for(let e=0;e<i.length;e++){let t=i[e],n=`connections[${e}]`;if(!M(t)||typeof t.id!=`string`||t.id.length===0)return{ok:!1,error:j(`BAD_SHAPE`,`${n} must be an object with a non-empty string "id"`,`${n}.id`)};for(let e of[`from`,`to`]){let r=t[e],i=`${n}.${e}`;if(typeof r!=`string`||!r.includes(`.`))return{ok:!1,error:j(`BAD_SHAPE`,`${i} must be an "ELEM.port" reference`,i)};let a=r.indexOf(`.`),o=r.slice(0,a),c=r.slice(a+1);if(o.length===0||c.length===0)return{ok:!1,error:j(`BAD_SHAPE`,`${i} must be an "ELEM.port" reference`,i)};let l=s.get(o);if(!l)return{ok:!1,error:j(`UNRESOLVED_PORT`,`Connection "${t.id}" ${e}="${r}" references element "${o}" but no such element or group exists`,i)};if(!(c in l.ports))return{ok:!1,error:j(`UNRESOLVED_PORT`,`Connection "${t.id}" ${e}="${r}" references port "${c}" but "${o}" declares no such port`,i)}}}let l=M(e.topology)?e.topology:{nodes:[],edges:[]},u=Array.isArray(l.nodes)?l.nodes:[],d=Array.isArray(l.edges)?l.edges:[],f=new Set;for(let e of i)M(e)&&typeof e.id==`string`&&f.add(e.id);for(let e=0;e<u.length;e++){let t=u[e],n=`topology.nodes[${e}]`;if(typeof t!=`string`||!s.has(t))return{ok:!1,error:j(`UNRESOLVED_TOPOLOGY_REF`,`topology.nodes[${e}] references "${String(t)}" but no such element or group exists`,n)}}for(let e=0;e<d.length;e++){let t=d[e],n=`topology.edges[${e}]`;if(!M(t)||typeof t.id!=`string`||t.id.length===0)return{ok:!1,error:j(`BAD_SHAPE`,`${n} must be an object with a non-empty string "id"`,`${n}.id`)};if(!f.has(t.id))return{ok:!1,error:j(`UNRESOLVED_TOPOLOGY_REF`,`topology edge "${t.id}" does not reference any connection with that id`,`${n}.id`)};for(let e of[`from`,`to`]){let r=t[e],i=`${n}.${e}`;if(typeof r!=`string`||!s.has(r))return{ok:!1,error:j(`UNRESOLVED_TOPOLOGY_REF`,`topology edge "${t.id}" ${e}="${String(r)}" references an element/group that does not exist`,i)}}}if(l.sources!==void 0){if(!Array.isArray(l.sources))return{ok:!1,error:j(`BAD_SHAPE`,`topology.sources must be an array of node ids`,`topology.sources`)};let e=new Set(u.filter(e=>typeof e==`string`));for(let t=0;t<l.sources.length;t++){let n=l.sources[t],r=`topology.sources[${t}]`;if(typeof n!=`string`||!e.has(n))return{ok:!1,error:j(`UNRESOLVED_TOPOLOGY_REF`,`topology.sources[${t}] references "${String(n)}" but it is not declared in topology.nodes`,r)}}}let p=n.map(e=>{let t=e;return{...t,bindings:Array.isArray(t.bindings)?t.bindings:[],thresholds:Array.isArray(t.thresholds)?t.thresholds:[]}}),m=i.map(e=>{let t=e;return{...t,bindings:Array.isArray(t.bindings)?t.bindings:[]}});return{ok:!0,scene:{...e,elements:p,groups:r,connections:m,topology:e.topology??{nodes:[],edges:[]},media:e.media??{},inferFlow:e.inferFlow===!0}}}async function We(e){return null}var Ge=new Map;function Ke(...e){for(let t of e)for(let[e,n]of Object.entries(t.primitives))Ge.has(e)&&Ge.get(e)!==n&&console.warn(`registerPrimitives: element type "${e}" is already registered — the new registration will overwrite it.`),Ge.set(e,n)}function qe(e){return Ge.get(e)}function Je(){return new Set(Ge.keys())}function Ye(){return Je()}var Xe;function Ze(e){Xe=e}function Qe(){return Xe}var $e=new Map;function et(...e){for(let t of e)$e.set(t.name,t)}function tt(e){return $e.get(e)??{name:e,palette:{}}}var nt={now:()=>performance.now(),onTick(e){let t=requestAnimationFrame(function n(r){e(r),t=requestAnimationFrame(n)});return()=>cancelAnimationFrame(t)}},rt={setTransform(e,t){e.style.transform=t},setAttr(e,t,n){e.setAttribute(t,n)},setCssVar(e,t,n){e.style.setProperty(t,n)},setText(e,t){e.textContent=t},animateTransform(e,t,n){let r=e.animate(t.map(e=>({transform:e})),{duration:n,iterations:1/0,easing:`linear`});return{setPlaybackRate(e){r.playbackRate=e},pause(){r.pause()},resume(){r.play()},seek(e){r.currentTime=e}}}},it={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function at(e){return it[e]}function ot(e){return e===`left`||e===`right`?`h`:`v`}function st(e,t,n,r){let i={x:e.x+at(t).x*24,y:e.y+at(t).y*24},a={x:n.x+at(r).x*24,y:n.y+at(r).y*24},o=ct(t,r,i,a);for(let t of o){let r=ut([e,i,...t,a,n]);if(!lt(r))return r}return ut([e,i,...o[o.length-1]??[],a,n])}function ct(e,t,n,r){if(ot(e)!==ot(t))return ot(e)===`v`?[[{x:n.x,y:r.y}],[{x:r.x,y:n.y}]]:[[{x:r.x,y:n.y}],[{x:n.x,y:r.y}]];let i=ot(e)===`v`,a=e=>i?e.y:e.x,o=e=>i?e.x:e.y,s=(e,t)=>i?{x:t,y:e}:{x:e,y:t},c=a(n)===a(r)?[]:[s(a(n),o(n)+24),s(a(r),o(n)+24)];return[[{x:r.x,y:n.y}],c]}function lt(e){for(let t=0;t<e.length-1;t++)for(let n=t+1;n<e.length-1;n++){let r=e[t],i=e[t+1],a=e[n],o=e[n+1],s=r.x===i.x;if(s===(a.x===o.x))if(s){if(r.x!==a.x)continue;let e=Math.min(r.y,i.y),t=Math.max(r.y,i.y),n=Math.min(a.y,o.y);if(e<Math.max(a.y,o.y)&&n<t)return!0}else{if(r.y!==a.y)continue;let e=Math.min(r.x,i.x),t=Math.max(r.x,i.x),n=Math.min(a.x,o.x);if(e<Math.max(a.x,o.x)&&n<t)return!0}}return!1}function ut(e){let t=e.slice(),n=!0;for(;n;){n=!1;for(let e=1;e<t.length-1;e++){let r=t[e-1],i=t[e+1],a=t[e];if(a.x===r.x&&a.y===r.y||a.x===i.x&&a.y===i.y){t.splice(e,1),n=!0;break}}if(!n)for(let e=1;e<t.length-1;e++){let r=t[e-1],i=t[e],a=t[e+1],o=i.x-r.x,s=i.y-r.y,c=a.x-i.x,l=a.y-i.y,u=o*l-s*c,d=o*c+s*l,f=o*o+s*s+c*c+l*l||1;if(Math.abs(u)<1e-9*f&&d>0){t.splice(e,1),n=!0;break}}}return t}var dt=24,ft=24*1.5;function pt(e,t,n=36){if(!t||e.length<2)return e;let r=e[0],i=e[e.length-1],a=ht(t*n,e);if(a===0)return e;let o=e.length===2?mt(r,i,a):e;if(o.length===2)return e;let s=vt(gt(o,a));return s[0]=r,s[s.length-1]=i,s}function mt(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.hypot(r,i);if(a<1e-9)return[e,t];let o=r/a,s=i/a,c=Math.min(Math.max(24,Math.abs(n)),a/3);return[e,{x:e.x+o*c,y:e.y+s*c},{x:t.x-o*c,y:t.y-s*c},t]}function ht(e,t){if(t.length<3)return e;let n=1/0;for(let e=0;e<t.length-1;e++){let r=Math.hypot(t[e+1].x-t[e].x,t[e+1].y-t[e].y);r>1e-9&&(n=Math.min(n,r))}if(!Number.isFinite(n))return e;let r=n/2;return Math.sign(e)*Math.min(Math.abs(e),r)}function gt(e,t){let n=[];for(let t=0;t<e.length-1;t++){let r=e[t],i=e[t+1],a=Math.hypot(i.x-r.x,i.y-r.y);n.push(a>1e-9?{x:(i.x-r.x)/a,y:(i.y-r.y)/a}:null)}let r=_t(n),i=[];for(let n=0;n<e.length-1;n++){let a=e[n],o=e[n+1],s=r[n],c={x:-s.y*t,y:s.x*t};i.push({from:{x:a.x+c.x,y:a.y+c.y},to:{x:o.x+c.x,y:o.y+c.y},dir:s})}return i}function _t(e){let t=e.slice();for(let e=0;e<t.length;e++){if(t[e])continue;let n=null;for(let r=e+1;r<t.length&&!n;r++)n=t[r];if(!n)for(let r=e-1;r>=0&&!n;r--)n=t[r];t[e]=n??{x:0,y:0}}return t}function vt(e){let t=[e[0].from];for(let n=0;n<e.length-1;n++){let r=e[n],i=e[n+1];t.push(yt(r.from,r.dir,i.from,i.dir)??r.to)}return t.push(e[e.length-1].to),t}function yt(e,t,n,r){let i=t.x*r.y-t.y*r.x;if(Math.abs(i)<1e-9)return null;let a=n.x-e.x,o=n.y-e.y,s=(a*r.y-o*r.x)/i;return{x:e.x+t.x*s,y:e.y+t.y*s}}function bt(e,t){if(e){if(t&&e.styles[t])return e.styles[t];if(e.defaultMedium)return e.styles[e.defaultMedium]}}var xt=[`animationSpeedFactor`,`opacity`,`waveAmplitude`,`wavePeriod`,`waveSpeed`],St=[`meniscus`],Ct=[`sharp`,`diffuse`,`none`];function wt(e){let t={};for(let n of xt){let r=e[n];typeof r==`number`&&(t[n]=r)}for(let n of St){let r=e[n];typeof r==`boolean`&&(t[n]=r)}return typeof e.color==`string`&&(t.color=e.color),typeof e.specular==`string`&&Ct.includes(e.specular)&&(t.specular=e.specular),t}function Tt(e,t,n){let r=bt(e,t);if(!r)return r;let i=t?n?.[t]:void 0;return i?{...r,...wt(i)}:r}function Et(e,t){return e.medium===void 0?t.edgeById.get(e.id)?.medium:e.medium}function Dt(e,t,n){let r=At(e.from,t),i=At(e.to,t);if(!r||!i)return null;let a={x:r.x,y:r.y},o={x:i.x,y:i.y},s=kt(e.bindings??[]),c=e.laneOffset,l=n?Et(e,n):e.medium,u=e.routing??`orthogonal`,d=!!e.waypoints&&e.waypoints.length>0;if((u===`manual`||u===`orthogonal`)&&d){let t=e.cornerRadius??0;return Ot(pt([a,...e.waypoints??[],o],c),t,l,s)}if(u===`orthogonal`){let t=e.cornerRadius??12;return Ot(pt(st(a,r.dir,o,i.dir),c),t,l,s)}return{segments:jt(pt([a,o],c)),corners:[],medium:l,flowBinding:s}}function Ot(e,t,n,r){return e.length<=2||t<=0?{segments:jt(e),corners:[],medium:n,flowBinding:r}:Nt(e,t,n,r)}function kt(e){let t=e.find(e=>e.type===`flow`);return t?{tag:t.tag,min:t.min,max:t.max}:void 0}function At(e,t){let n=e.indexOf(`.`);if(n<0)return null;let r=e.slice(0,n),i=e.slice(n+1),a=t.elements.find(e=>e.id===r);if(!a)return null;let o=a.ports[i];return o?{x:a.x+o.x,y:a.y+o.y,dir:o.dir}:null}function jt(e){let t=[];for(let n=0;n<e.length-1;n++)t.push({from:e[n],to:e[n+1]});return t}function Mt(e,t){let n=[],r=[],i=e[0];for(let a=1;a<e.length-1;a++){let o=e[a-1],s=e[a],c=e[a+1],l=Pt(s,o),u=Pt(c,s),d=Lt(l),f=Lt(u),p=Math.min(t,d/2,f/2),m=It(l,1/d),h=It(u,1/f),g=Pt(s,It(m,p)),_=Ft(s,It(h,p));n.push({from:i,to:g});let v=m.x*h.y-m.y*h.x;r.push({from:g,to:_,radius:p,sweepFlag:v>0?0:1}),i=_}return n.push({from:i,to:e[e.length-1]}),{segments:n,corners:r}}function Nt(e,t,n,r){let{segments:i,corners:a}=Mt(e,t);return{segments:i,corners:a,medium:n,flowBinding:r}}function Pt(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Ft(e,t){return{x:e.x+t.x,y:e.y+t.y}}function It(e,t){return{x:e.x*t,y:e.y*t}}function Lt(e){return Math.sqrt(e.x*e.x+e.y*e.y)}function Rt(e){if(e.segments.length===0)return``;let t=e.segments[0].from,n=[`M ${t.x} ${t.y}`];for(let t=0;t<e.segments.length;t++){let r=e.segments[t];n.push(`L ${r.to.x} ${r.to.y}`);let i=e.corners[t];i&&n.push(`A ${i.radius} ${i.radius} 0 0 ${i.sweepFlag} ${i.to.x} ${i.to.y}`)}return n.join(` `)}function zt(e){return Math.atan2(e.to.y-e.from.y,e.to.x-e.from.x)}function Bt(e,t){let n=new Map;for(let r of e.groups)if(t.has(r.id))for(let e of r.children)n.set(e,r.id);return n}function Vt(e,t,n){return Bt(e,t).get(n)??n}function Ht(e,t,n){if(n.size===0)return e;let r=Bt(t,n),i=e=>r.get(e)??e,a=new Set;for(let t of e.nodes)a.add(i(t));let o=[];for(let t of e.edges){let e=i(t.from),n=i(t.to);e!==n&&o.push({id:t.id,from:e,to:n,medium:t.medium})}let s=new Map,c=new Map,l=new Map;for(let e of o){l.set(e.id,e);let t=s.get(e.from);t?t.push(e):s.set(e.from,[e]);let n=c.get(e.to);n?n.push(e):c.set(e.to,[e])}return{nodes:a,edges:o,outgoing:s,incoming:c,edgeById:l}}var Ut={good:0,uncertain:1,stale:2,bad:3};function Wt(e,t){return Ut[e]>=Ut[t]?e:t}function Gt(e,t,n){return e.quality===`bad`?`bad`:t-(e.timestamp??e.arrivalTime)>n?`stale`:e.quality===`uncertain`?`uncertain`:`good`}function Kt(e){return e.reduce((e,t)=>Wt(e,t),`good`)}function qt(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m`}var N=`http://www.w3.org/2000/svg`;function Jt(e){return e.length===0?`uncertain`:Kt([...e])}function Yt(e,t){let n=document.createElementNS(N,`g`);n.setAttribute(`class`,`vscada-group-summary`),n.setAttribute(`data-group-id`,e.id);let r=t.tokens.panel;if(!r)return{svg:n,setAlarmCondition:()=>{},setSummaryValue:()=>{}};let i=document.createElementNS(N,`rect`);i.setAttribute(`class`,`vscada-group-face`),i.setAttribute(`width`,String(e.w)),i.setAttribute(`height`,String(e.h)),i.setAttribute(`fill`,r.raised.faceColor),n.appendChild(i);let a=document.createElementNS(N,`path`);a.setAttribute(`class`,`vscada-group-bevel-highlight`),a.setAttribute(`d`,`M 0 ${e.h} L 0 0 L ${e.w} 0`),a.setAttribute(`fill`,`none`),a.setAttribute(`stroke`,r.raised.highlightColor),a.setAttribute(`stroke-width`,`2`),n.appendChild(a);let o=document.createElementNS(N,`path`);o.setAttribute(`class`,`vscada-group-bevel-shadow`),o.setAttribute(`d`,`M ${e.w} 0 L ${e.w} ${e.h} L 0 ${e.h}`),o.setAttribute(`fill`,`none`),o.setAttribute(`stroke`,r.raised.shadowColor),o.setAttribute(`stroke-width`,`2`),n.appendChild(o);let s=document.createElementNS(N,`text`);s.setAttribute(`class`,`vscada-group-label`),s.setAttribute(`x`,`6`),s.setAttribute(`y`,`14`),s.setAttribute(`fill`,r.labelColor),s.textContent=e.label??e.id,n.appendChild(s);let c=new Map;e.summaryTags.forEach((e,t)=>{let i=document.createElementNS(N,`text`);i.setAttribute(`class`,`vscada-group-readout`),i.setAttribute(`data-tag`,e),i.setAttribute(`x`,`6`),i.setAttribute(`y`,String(28+t*14)),i.setAttribute(`fill`,r.readoutColor),n.appendChild(i),c.set(e,i)});let l=document.createElementNS(N,`circle`);l.setAttribute(`class`,`vscada-group-alarm`),l.setAttribute(`cx`,String(e.w-8)),l.setAttribute(`cy`,`8`),l.setAttribute(`r`,`5`),l.setAttribute(`fill`,r.alarmIndicator.goodColor),n.appendChild(l);let u=document.createElementNS(N,`text`);u.setAttribute(`class`,`vscada-group-alarm-label`),u.setAttribute(`x`,String(e.w-8)),u.setAttribute(`y`,`20`),u.setAttribute(`text-anchor`,`middle`),u.setAttribute(`font-size`,`7`),u.setAttribute(`fill`,r.labelColor),u.textContent=`GOOD`,n.appendChild(u);let d={good:r.alarmIndicator.goodColor,uncertain:r.alarmIndicator.uncertainColor,stale:r.alarmIndicator.staleColor,bad:r.alarmIndicator.badColor};function f(e,t){e.setAttr(l,`fill`,d[t]),e.setText(u,t.toUpperCase())}function p(e,t,n){let r=c.get(t);r&&e.setText(r,n)}return{svg:n,setAlarmCondition:f,setSummaryValue:p}}function Xt(e,t){let n=document.createElementNS(N,`g`);n.setAttribute(`class`,`vscada-group-frame`),n.setAttribute(`data-group-id`,e.id);let r=t.tokens.panel;if(!r)return n;let i=document.createElementNS(N,`rect`);i.setAttribute(`class`,`vscada-group-frame-outline`),i.setAttribute(`width`,String(e.w)),i.setAttribute(`height`,String(e.h)),i.setAttribute(`fill`,`none`),i.setAttribute(`stroke`,r.raised.highlightColor),i.setAttribute(`stroke-dasharray`,`4 3`),n.appendChild(i);let a=document.createElementNS(N,`text`);return a.setAttribute(`class`,`vscada-group-frame-label`),a.setAttribute(`x`,`4`),a.setAttribute(`y`,`-4`),a.setAttribute(`fill`,r.labelColor),a.textContent=e.label??e.id,n.appendChild(a),n}function Zt(e){return Object.entries(e.portMap).flatMap(([e,t])=>{let n=t.indexOf(`.`);return n<0?[]:[{groupPortName:e,childElementId:t.slice(0,n),childPortName:t.slice(n+1)}]})}function Qt(e,t){let n=new Map;for(let r of e.groups)if(t.has(r.id))for(let e of Zt(r))n.set(`${e.childElementId}.${e.childPortName}`,`${r.id}.${e.groupPortName}`);return n}function $t(e){let t=e.indexOf(`.`);return t<0?e:e.slice(0,t)}function en(e,t,n){let r=Vt(t,n,$t(e.from));return r===Vt(t,n,$t(e.to))&&n.has(r)}function tn(e,t){if(t.size===0)return e;let n=Qt(e,t),r=e.groups.filter(e=>t.has(e.id)).map(e=>({id:e.id,type:`group`,x:e.x,y:e.y,w:e.w,h:e.h,label:e.label,ports:e.ports,bindings:[],thresholds:[],transitions:{}})),i=e=>n.get(e)??e,a=e.connections.filter(n=>!en(n,e,t)).map(e=>({...e,from:i(e.from),to:i(e.to)}));return{...e,elements:[...e.elements,...r],connections:a}}function nn(e,t,n,r){if(en(e,t,n))return null;let i=tn(t,n),a=Qt(t,n);return Dt({...e,from:a.get(e.from)??e.from,to:a.get(e.to)??e.to},i,r)}var rn=class{constructor(e,t,n=``){this.timeSource=e,this.onWarning=t,this.buffer=new Map,this._tagPrefixVersion=0,this._tagPrefix=n}get tagPrefix(){return this._tagPrefix}set tagPrefix(e){e!==this._tagPrefix&&(this._tagPrefix=e,this._tagPrefixVersion++)}get tagPrefixVersion(){return this._tagPrefixVersion}setValues(e){for(let t of e)this.ingestOne(t)}clearValues(){this.buffer.clear()}get(e){return this.buffer.get(e)}resolve(e){return this.buffer.get(this._tagPrefix+e)}get size(){return this.buffer.size}tags(){return this.buffer.keys()}ingestOne(e){let t=e.quality??`good`,n=this.buffer.get(e.tag);if(n&&n.currentValue===e.value&&n.quality===t&&n.timestamp===e.timestamp)return;this.checkTimestamp(e);let r=this.timeSource.now();this.buffer.set(e.tag,{previousValue:n?n.currentValue:e.value,currentValue:e.value,arrivalTime:r,quality:t,timestamp:e.timestamp})}checkTimestamp(e){}},an={"state-lamp":0,flow:1,rotation:2,wave:3},on=class{constructor(){this.entries=[]}register(e,t,n=`rotation`){this.entries.push({elementId:e,handle:t,paused:!1,priority:n})}registeredEntries(){return this.entries.map(e=>({elementId:e.elementId,priority:e.priority}))}unregisterElement(e){this.entries=this.entries.filter(t=>t.elementId!==e)}pauseAll(e){for(let t of this.entries)t.elementId===e&&!t.paused&&(t.handle.pause(),t.paused=!0)}resumeAll(e){for(let t of this.entries)t.elementId===e&&t.paused&&(t.handle.resume(),t.paused=!1)}pauseScene(){for(let e of this.entries)e.paused||(e.handle.pause(),e.paused=!0)}resumeScene(){for(let e of this.entries)e.paused&&(e.handle.resume(),e.paused=!1)}isPaused(e){return this.entries.filter(t=>t.elementId===e).map(e=>e.paused)}seekAll(e){for(let t of this.entries)t.handle.seek(e)}};function sn(e){return e.quality===`good`?e.explicit===void 0?e.inferred===void 0?{tier:`default`,value:e.defaultValue}:{tier:`inferred`,value:e.inferred}:{tier:`explicit`,value:e.explicit}:{tier:`quality`,value:e.quality}}var cn=.5,ln=.1;function un(e,t,n=cn,r=ln){let i=n*r;return t?e<n+i:e<n-i}var dn=1e4,fn=1e3,pn=100,mn=2e3,hn=1e3,gn=1e3,_n=1e3/60,vn=1.5;function yn(e){return e===`stale`||e===`bad`}var bn=class{constructor(e,t,n,r,i={}){this.timeSource=e,this.store=t,this.renderer=n,this.animationRegistry=r,this.registrations=[],this.tickables=[],this.overlays=new Map,this.elementQuality=new Map,this.stopTick=null,this.wasSceneFrozen=!1,this.flowFrozen=new Map,this.flowIsolatedOverlay=new Map,this.lodFrozen=new Map,this.lodActiveValue=!1,this.lodMaxActiveAnimations=50,this.visibilityPaused=!1,this.offscreenTimerId=null,this.debugEnabled=!1,this.statsFrameCount=0,this.statsDroppedFrames=0,this.statsWindowStart=0,this.lastTickTime=null,this.statsCallback=null,this.conditionCallback=null,this.stalenessTimeout=dn,this.connectionState=`connected`,this._mode=`live`,this._animateEnabled=!0,this.snapThreshold=i.snapThreshold??50,this.lastSeenTagPrefixVersion=t.tagPrefixVersion}registerHandle(e,t,n){if(n.kind!==`animation`){if(n.kind===`tween`){this.tickables.push({elementId:e,handle:n});return}this.registrations.push({elementId:e,tag:t,handle:n,lastWritten:void 0,lastArrivalTimeSeen:void 0,tweenDurationMs:pn})}}registerQualityOverlay(e,t){this.overlays.set(e,t)}registerFlowInference(e,t){this.flowInference={cache:e,ids:[...t]}}unregisterElement(e){this.registrations=this.registrations.filter(t=>t.elementId!==e),this.tickables=this.tickables.filter(t=>t.elementId!==e),this.overlays.delete(e),this.elementQuality.delete(e),this.flowFrozen.delete(e),this.flowIsolatedOverlay.delete(e),this.lodFrozen.delete(e)}get registrationCount(){return this.registrations.length}get mode(){return this._mode}set mode(e){if(e===this._mode)return;let t=this._mode===`live`;this._mode=e,e===`static`?(t&&this.snapToTargets(),this.stop()):this.start()}get animate(){return this._animateEnabled}set animate(e){if(e===this._animateEnabled)return;if(this._animateEnabled=e,!e){this.animationRegistry.pauseScene();return}let t=new Set(this.animationRegistry.registeredEntries().map(e=>e.elementId));for(let e of t)this.visibilityPaused||this.isElementFrozen(e)||this.flowFrozen.get(e)||this.lodFrozen.get(e)||this.animationRegistry.resumeAll(e)}start(){this.stopTick||this._mode!==`static`&&(this.stopTick=this.timeSource.onTick(e=>this.tick(e)))}stop(){this.stopTick?.(),this.stopTick=null,this.offscreenTimerId!==null&&(clearInterval(this.offscreenTimerId),this.offscreenTimerId=null)}get isRunning(){return this.stopTick!==null}get lodActive(){return this.lodActiveValue}set lodActive(e){this.lodActiveValue=e}get debug(){return this.debugEnabled}set debug(e){let t=e&&!this.debugEnabled;this.debugEnabled=e,t&&(this.statsFrameCount=0,this.statsDroppedFrames=0,this.lastTickTime=null,this.statsWindowStart=this.timeSource.now())}onRenderStats(e){return this.statsCallback=e,()=>{this.statsCallback===e&&(this.statsCallback=null)}}onConditionTransition(e){return this.conditionCallback=e,()=>{this.conditionCallback===e&&(this.conditionCallback=null)}}get isPausedForOffscreen(){return this.visibilityPaused}pauseForOffscreen(){this.visibilityPaused||(this.visibilityPaused=!0,this.stop(),this.animationRegistry.pauseScene(),this.offscreenTimerId=setInterval(()=>this.offscreenTick(),hn))}resumeFromOffscreen(){if(!this.visibilityPaused)return;this.visibilityPaused=!1,this.offscreenTimerId!==null&&(clearInterval(this.offscreenTimerId),this.offscreenTimerId=null);let e=new Set(this.animationRegistry.registeredEntries().map(e=>e.elementId));for(let t of e)this.isElementFrozen(t)||this.flowFrozen.get(t)||this.lodFrozen.get(t)||this.animationRegistry.resumeAll(t);this.start()}offscreenTick(){let e=this.timeSource.now(),t=this.connectionState===`disconnected`;this.evaluateQuality(e,t),this.applyFlowInference()}snapToTargets(){this.syncTagPrefixIfChanged();let e=this.timeSource.now();for(let t of this.tickables)t.handle.snap(this.renderer,e);for(let t of this.registrations){let n=this.store.resolve(t.tag);n&&(t.tweenDurationMs=Math.max(e-n.arrivalTime,1),t.lastArrivalTimeSeen=n.arrivalTime,!Object.is(n.currentValue,t.lastWritten)&&(t.lastWritten=n.currentValue,Sn(t.handle,this.renderer,n.currentValue,e)))}}tick(e){this.debugEnabled&&this.accountFrame(e),this.syncTagPrefixIfChanged();let t=this.connectionState===`disconnected`;t&&!this.wasSceneFrozen&&this.animationRegistry.pauseScene(),this.wasSceneFrozen=t,this.evaluateQuality(e,t),this.applyFlowInference();for(let n of this.tickables)t||this.isElementFrozen(n.elementId)||n.handle.tick(this.renderer,e);for(let n of this.registrations){if(t||this.isElementFrozen(n.elementId))continue;let r=this.store.resolve(n.tag);if(!r)continue;if(r.arrivalTime!==n.lastArrivalTimeSeen){let e=n.lastArrivalTimeSeen===void 0?pn:r.arrivalTime-n.lastArrivalTimeSeen;n.tweenDurationMs=Math.min(Math.max(e,pn),mn),n.lastArrivalTimeSeen=r.arrivalTime}let i=n.handle.kind===`state`?r.currentValue:xn(r,e,n.tweenDurationMs,this.snapThreshold);Object.is(i,n.lastWritten)||(n.lastWritten=i,Sn(n.handle,this.renderer,i,e))}this.applyLod()}applyLod(){if(!this.lodActiveValue&&this.lodFrozen.size===0)return;if(!this.lodActiveValue){for(let[e,t]of[...this.lodFrozen]){if(!t){this.lodFrozen.delete(e);continue}this.isElementFrozen(e)||this.flowFrozen.get(e)||(this.animationRegistry.resumeAll(e),this.lodFrozen.delete(e))}return}let e=this.animationRegistry.registeredEntries(),t=[...e].sort((e,t)=>an[e.priority]-an[t.priority]),n=new Set(t.slice(0,this.lodMaxActiveAnimations).map(e=>e.elementId));for(let{elementId:t}of e){let e=!n.has(t),r=this.lodFrozen.get(t)??!1;if(e&&!r)this.animationRegistry.pauseAll(t),this.lodFrozen.set(t,!0);else if(!e&&r){if(this.isElementFrozen(t)||this.flowFrozen.get(t))continue;this.animationRegistry.resumeAll(t),this.lodFrozen.set(t,!1)}}}accountFrame(e){this.lastTickTime!==null&&e-this.lastTickTime>_n*vn&&this.statsDroppedFrames++,this.lastTickTime=e,this.statsFrameCount++;let t=e-this.statsWindowStart;if(t<gn)return;let n=t/1e3,r=n>0?this.statsFrameCount/n:0;this.statsCallback?.({fps:Math.round(r),elementCount:this.countDistinctElements(),droppedFrames:this.statsDroppedFrames}),this.statsFrameCount=0,this.statsDroppedFrames=0,this.statsWindowStart=e}countDistinctElements(){let e=new Set;for(let t of this.registrations)e.add(t.elementId);for(let t of this.tickables)e.add(t.elementId);for(let t of this.overlays.keys())e.add(t);for(let t of this.animationRegistry.registeredEntries())e.add(t.elementId);return e.size}syncTagPrefixIfChanged(){let e=this.store.tagPrefixVersion;if(e!==this.lastSeenTagPrefixVersion){this.lastSeenTagPrefixVersion=e;for(let e of this.registrations)e.lastWritten=void 0,e.lastArrivalTimeSeen=void 0,e.tweenDurationMs=pn}}isElementFrozen(e){let t=this.elementQuality.get(e);return t!==void 0&&yn(t.condition)}evaluateQuality(e,t){let n=new Map;for(let e of this.registrations){let t=n.get(e.elementId)??[];t.push(e.tag),n.set(e.elementId,t)}let r=new Set([...n.keys(),...this.overlays.keys()]);for(let i of r){let r=n.get(i)??[],a=`good`,o=0;for(let t of r){let n=this.store.resolve(t);n&&(a=Kt([a,Gt(n,e,this.stalenessTimeout)]),o=Math.max(o,e-(n.timestamp??n.arrivalTime)))}t&&(a=Kt([a,`stale`]));let s=this.elementQuality.get(i),c=s?.condition??`good`,l=this.overlays.get(i);a!==c&&(l?.setCondition(this.renderer,a),this.handleConditionTransition(i,c,a,e),this.conditionCallback?.(i,c,a));let u=s?.lastBadgeUpdate??-1/0;l&&(a===`stale`&&e-u>=fn?(l.setAgeBadge(this.renderer,qt(o)),u=e):a!==`stale`&&l.setAgeBadge(this.renderer,null)),this.elementQuality.set(i,{condition:a,lastBadgeUpdate:u})}}applyFlowInference(){if(!this.flowInference)return;let{cache:e,ids:t}=this.flowInference;for(let n of t){let t=e.getState(n),r=this.elementQuality.get(n)?.condition??`good`,i=sn({quality:r,inferred:t,defaultValue:`flowing`}),a=i.tier===`quality`,o=!a&&(i.value===`no-flow`||i.value===`isolated`);o?this.animationRegistry.pauseAll(n):a||this.flowFrozen.get(n)&&this.animationRegistry.resumeAll(n),this.flowFrozen.set(n,o);let s=this.overlays.get(n),c=i.tier===`inferred`&&i.value===`isolated`,l=this.flowIsolatedOverlay.get(n)??!1;s&&r===`good`&&c!==l&&s.setCondition(this.renderer,c?`stale`:`good`),this.flowIsolatedOverlay.set(n,c)}}handleConditionTransition(e,t,n,r){let i=yn(n)&&!yn(t),a=yn(t)&&!yn(n);if(i){if(this.animationRegistry.pauseAll(e),n===`bad`)for(let t of this.registrations)t.elementId===e&&t.handle.kind===`text`&&(t.handle.write(this.renderer,`----`,r),t.lastWritten=`----`)}else a&&this.animationRegistry.resumeAll(e)}};function xn(e,t,n,r){let{previousValue:i,currentValue:a,arrivalTime:o}=e;if(typeof i!=`number`||typeof a!=`number`||i===a||Math.abs(a-i)>r)return a;let s=Math.min(Math.max((t-o)/n,0),1);return i+(a-i)*s}function Sn(e,t,n,r){if(e.kind===`numeric`){typeof n==`number`&&e.write(t,n,r);return}(e.kind===`text`||e.kind===`state`)&&e.write(t,n,r)}var P=`http://www.w3.org/2000/svg`,Cn=`vscada-quality-hatch`;function wn(e,t,n){let r=n.tokens.quality,i=document.createElementNS(P,`g`);if(i.setAttribute(`class`,`vscada-quality-overlay`),i.setAttribute(`display`,`none`),!r)return{group:i,setCondition:()=>{},setAgeBadge:()=>{}};let a=document.createElementNS(P,`rect`);if(a.setAttribute(`class`,`vscada-quality-dash`),a.setAttribute(`width`,String(e)),a.setAttribute(`height`,String(t)),a.setAttribute(`fill`,`none`),a.setAttribute(`stroke`,r.uncertainDashColor),a.setAttribute(`stroke-dasharray`,`4 3`),a.setAttribute(`display`,`none`),i.appendChild(a),!n.defs.querySelector(`#${Cn}`)){let e=document.createElementNS(P,`pattern`);e.setAttribute(`id`,Cn),e.setAttribute(`width`,`8`),e.setAttribute(`height`,`8`),e.setAttribute(`patternUnits`,`userSpaceOnUse`),e.setAttribute(`patternTransform`,`rotate(45)`);let t=document.createElementNS(P,`line`);t.setAttribute(`x1`,`0`),t.setAttribute(`y1`,`0`),t.setAttribute(`x2`,`0`),t.setAttribute(`y2`,`8`),t.setAttribute(`stroke`,r.badHatchColor),t.setAttribute(`stroke-width`,`4`),e.appendChild(t),n.defs.appendChild(e)}let o=document.createElementNS(P,`rect`);o.setAttribute(`class`,`vscada-quality-hatch`),o.setAttribute(`width`,String(e)),o.setAttribute(`height`,String(t)),o.setAttribute(`fill`,`url(#${Cn})`),o.setAttribute(`opacity`,String(r.badHatchOpacity)),o.setAttribute(`display`,`none`),i.appendChild(o);let s=document.createElementNS(P,`rect`);s.setAttribute(`class`,`vscada-quality-stale`),s.setAttribute(`width`,String(e)),s.setAttribute(`height`,String(t)),s.setAttribute(`fill`,r.staleOverlayColor),s.setAttribute(`opacity`,String(r.staleOverlayOpacity)),s.setAttribute(`display`,`none`),i.appendChild(s);let c=document.createElementNS(P,`g`);c.setAttribute(`class`,`vscada-quality-badge`),c.setAttribute(`display`,`none`);let l=document.createElementNS(P,`rect`);l.setAttribute(`x`,String(e-24)),l.setAttribute(`y`,`-14`),l.setAttribute(`width`,`24`),l.setAttribute(`height`,`12`),l.setAttribute(`fill`,r.badgeBackgroundColor),c.appendChild(l);let u=document.createElementNS(P,`text`);u.setAttribute(`class`,`vscada-quality-badge-text`),u.setAttribute(`x`,String(e-12)),u.setAttribute(`y`,`-5`),u.setAttribute(`font-size`,`8`),u.setAttribute(`text-anchor`,`middle`),u.setAttribute(`fill`,r.badgeTextColor),c.appendChild(u),i.appendChild(c);function d(e,t){e.setAttr(i,`display`,t===`good`?`none`:`inline`),e.setAttr(a,`display`,t===`uncertain`?`inline`:`none`),e.setAttr(o,`display`,t===`bad`?`inline`:`none`),e.setAttr(s,`display`,t===`stale`?`inline`:`none`),e.setAttr(c,`display`,t===`stale`?`inline`:`none`)}function f(e,t){e.setText(u,t??``)}return{group:i,setCondition:d,setAgeBadge:f}}function Tn(e){return Number.isNaN(e)?0:Math.min(Math.max(e,0),1)}function En(e,t,n){return Math.min(Math.max(e,t),n)}function Dn(e,t,n){let r=t-e;return r===0?0:Tn((n-e)/r)}function On(e,t){return Dn(e.min,e.max,t)}function kn(e,t){return Dn(e.min,e.max,t)}var An=4;function jn(e,t){return En(t,0,e.max??4)}var Mn={minAngleDeg:-135,maxAngleDeg:135};function Nn(e,t,n=Mn){let r=Dn(e.min,e.max,t);return n.minAngleDeg+r*(n.maxAngleDeg-n.minAngleDeg)}function Pn(e,t){if(typeof t!=`number`)return String(t);let n=t.toFixed(e.decimals);return e.unit.length>0?`${n} ${e.unit}`:n}function Fn(e,t){if(e.map){let n=e.map[String(t)];if(n!==void 0)return n}return!!t}function In(e,t){let n=String(t),r=e.map[n];return r===void 0?{ok:!1,fault:{code:`UNMAPPED_STATE_VALUE`,message:`Tag "${e.tag}": value "${n}" has no entry in this binding's state map`,tag:e.tag}}:{ok:!0,state:r}}function Ln(e){return Math.min(Math.max(e,0),1)}function Rn(e){let t=/^#([0-9a-fA-F]{3})$/.exec(e);if(t){let[e,n,r]=t[1].split(``).map(e=>parseInt(e+e,16));return[e,n,r]}let n=/^#([0-9a-fA-F]{6})$/.exec(e);if(n){let e=n[1];return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}}function zn(e){return Math.round(Ln(e/255)*255).toString(16).padStart(2,`0`).toUpperCase()}function Bn(e,t,n){let r=Rn(e),i=Rn(t);if(!r||!i)return e;let a=Ln(n),o=r[0]+(i[0]-r[0])*a,s=r[1]+(i[1]-r[1])*a,c=r[2]+(i[2]-r[2])*a;return`#${zn(o)}${zn(s)}${zn(c)}`}function Vn(e,t){let n=[...e].sort((e,t)=>e.offset-t.offset);if(n.length===0)return`#000000`;if(n.length===1)return n[0].color;let r=Ln(t);if(r<=n[0].offset)return n[0].color;if(r>=n[n.length-1].offset)return n[n.length-1].color;for(let e=0;e<n.length-1;e++){let t=n[e],i=n[e+1];if(r>=t.offset&&r<=i.offset){let e=i.offset-t.offset,n=e===0?0:(r-t.offset)/e;return Bn(t.color,i.color,n)}}return n[n.length-1].color}function Hn(e,t){let n=e.colors;if(!n||n.length===0)return t.default;let r=[];for(let e=0;e<n.length;e++){let i=t.stops[n[e]];if(!i)continue;let a=n.length===1?0:e/(n.length-1);r.push({offset:a,color:i})}return r.length>=2?r:t.default}function Un(e,t,n){if(n)return Vn(Hn(e,n),Dn(e.min,e.max,t))}var Wn=new Map;function Gn(e){for(let[t,n]of Object.entries(e))Wn.set(t,n)}function Kn(e){return Wn.get(e)}var qn=`http://www.w3.org/2000/svg`,Jn=new Set([`readout`,`state`,`visibility`,`blink`,`color-ramp`]),Yn=[`scale(1)`,`scale(0.3)`,`scale(1)`],Xn=800;function Zn(e,t,n,r){let i=document.createElementNS(qn,`g`);i.setAttribute(`class`,`vscada-svg-import`),i.setAttribute(`data-element-id`,e.id);let a=wn(e.w,e.h,t);i.appendChild(a.group);let o={},s=new Set;function c(e,t){s.add(e),a.setCondition(n,`bad`)}function l(e){s.has(e)&&(s.delete(e),s.size===0&&a.setCondition(n,`good`))}let u=Kn(e.svgRef);if(u===void 0)return c(`svgRef:${e.svgRef}`,{code:`MISSING_SVG_SOURCE`,message:`svg-import "${e.id}" references svgRef "${e.svgRef}" but no source is registered — call registerSvgSources() before assigning the scene`,tag:e.svgRef}),{svg:i,handles:o};let d=new DOMParser().parseFromString(u,`image/svg+xml`),f=d.documentElement;if(d.querySelector(`parsererror`)||f.nodeName.toLowerCase()!==`svg`)return c(`svgRef:${e.svgRef}`,{code:`INVALID_SVG_SOURCE`,message:`svg-import "${e.id}"'s svgRef "${e.svgRef}" did not parse as SVG`,tag:e.svgRef}),{svg:i,handles:o};let p=document.createElementNS(qn,`svg`),m=f.getAttribute(`viewBox`);for(m&&p.setAttribute(`viewBox`,m),p.setAttribute(`width`,String(e.w)),p.setAttribute(`height`,String(e.h)),p.setAttribute(`preserveAspectRatio`,`xMidYMid meet`);f.firstChild;)p.appendChild(document.adoptNode(f.firstChild));i.appendChild(p);for(let r of e.bindings){if(!Jn.has(r.type)){c(`type:${r.tag}`,{code:`UNSUPPORTED_IMPORT_BINDING_TYPE`,message:`svg-import "${e.id}" binding for tag "${r.tag}" has unsupported type "${r.type}" — imported art supports readout/state/visibility/blink/color-ramp only`,tag:r.tag});continue}let i=p.querySelector(`#${CSS.escape(r.svgId)}`);if(!i){c(`id:${r.svgId}`,{code:`MISSING_SVG_ID`,message:`svg-import "${e.id}" binding for tag "${r.tag}" references svgId "${r.svgId}" but no matching element exists in the imported SVG`,tag:r.tag});continue}switch(r.type){case`readout`:o[r.tag]={kind:`text`,write(e,t){e.setText(i,Pn(r,t))}};break;case`state`:{let e=`state:${r.tag}`;o[r.tag]={kind:`state`,write(t,n){let a=In(r,n);if(a.ok){l(e),t.setAttr(i,`class`,a.state);return}c(e,a.fault)}};break}case`visibility`:o[r.tag]={kind:`state`,write(e,t){e.setAttr(i,`display`,Fn(r,t)?`inline`:`none`)}};break;case`color-ramp`:o[r.tag]={kind:`numeric`,write(e,n){if(typeof n!=`number`)return;let a=Un(r,n,t.tokens.colorRamp);a!==void 0&&e.setAttr(i,`fill`,a)}};break;case`blink`:{let t=n.animateTransform(i,Yn,Xn),a={kind:`animation`,pause:()=>t.pause(),resume:()=>t.resume(),seek:e=>t.seek(e)};o[`__svg-import-blink-animation-${e.id}-${r.tag}`]=a,o[r.tag]={kind:`numeric`,write(e,n){typeof n==`number`&&t.setPlaybackRate(jn(r,n))}};break}}}return{svg:i,handles:o}}function Qn(e){let t=new Set(e.topology.nodes),n=e.topology.edges.map(e=>({id:e.id,from:e.from,to:e.to,medium:e.medium})),r=new Map,i=new Map,a=new Map;for(let e of n){a.set(e.id,e);let t=r.get(e.from);t?t.push(e):r.set(e.from,[e]);let n=i.get(e.to);n?n.push(e):i.set(e.to,[e])}return{nodes:t,edges:n,outgoing:r,incoming:i,edgeById:a}}function $n(e,t,n){let r=n===`downstream`?e.outgoing:e.incoming,i=e=>n===`downstream`?e.to:e.from,a=new Set([t]),o=[t],s=e.nodes.size+1,c=0;for(;o.length>0;){if(c+=1,c>s)throw Error(`reachableSet exceeded its node-count iteration bound — cycle guard invariant violated`);let e=o.shift(),t=r.get(e)??[];for(let e of t){let t=i(e);a.has(t)||(a.add(t),o.push(t))}}return a}function er(e,t){return $n(e,t,`upstream`)}function tr(e,t){return $n(e,t,`downstream`)}function nr(e,t){let n=new Map;for(let r of e.nodes)n.set(r,t.has(r)?[]:e.outgoing.get(r)??[]);return{...e,outgoing:n}}function rr(e,t){let n=new Set;for(let r of t)for(let t of tr(e,r))n.add(t);return n}function ir(e){let{graph:t,sourceNodeIds:n,stoppedSourceNodeIds:r,closedNodeIds:i}=e,a=nr(t,i),o=[...n].filter(e=>!r.has(e)),s=rr(t,n),c=rr(a,n),l=rr(a,o),u=new Map;for(let e of t.nodes)if(s.has(e)){if(!c.has(e)){u.set(e,`isolated`);continue}u.set(e,l.has(e)?`flowing`:`no-flow`)}let d=new Map;for(let e of t.edges)if(s.has(e.from)){if(!c.has(e.from)){d.set(e.id,`isolated`);continue}if(i.has(e.from)){d.set(e.id,c.has(e.to)?`no-flow`:`isolated`);continue}d.set(e.id,l.has(e.from)?`flowing`:`no-flow`)}return{edgeStates:d,nodeStates:u}}function ar(e,t){return JSON.stringify([[...e].sort(),[...t].sort()])}var or=class{constructor(e,t){this.graph=e,this.sourceNodeIds=t,this.result={edgeStates:new Map,nodeStates:new Map}}update(e,t){let n=ar(e,t);return n!==this.lastSignature&&(this.result=ir({graph:this.graph,sourceNodeIds:this.sourceNodeIds,stoppedSourceNodeIds:e,closedNodeIds:t}),this.lastSignature=n),this.result}getEdgeState(e){return this.result.edgeStates.get(e)}getNodeState(e){return this.result.nodeStates.get(e)}getState(e){return this.result.edgeStates.get(e)??this.result.nodeStates.get(e)}reset(){this.result={edgeStates:new Map,nodeStates:new Map},this.lastSignature=void 0}};function sr(e,t){let n=e.edgeById.get(t);if(!n)return;let r=new Set([n.to]),i=new Set([n.id]),a=[n];for(;a.length>0;){let t=a.shift();r.add(t.from);let o=e.incoming.get(t.from)??[];for(let e of o)e.medium===n.medium&&(i.has(e.id)||(i.add(e.id),a.push(e)))}return{nodes:r,edges:i}}function cr(e){return e===`mouse`}var lr=`data-vscada-highlight`;function ur(e,t,n){let r=n.highlightAttr??lr,i;function a(e,n){e&&t.setAttr(e,r,n?`true`:`false`)}function o(){if(i){for(let e of i.nodes)a(n.getNodeElement(e),!1);for(let e of i.edges)a(n.getEdgeElement(e),!1);i=void 0}}return{onPointerEnter(t,r){if(!cr(r.pointerType))return;let s=sr(e,t);if(s){o(),i=s;for(let e of s.nodes)a(n.getNodeElement(e),!0);for(let e of s.edges)a(n.getEdgeElement(e),!0)}},onPointerLeave(){o()}}}var dr=class{constructor(e,t){this.animationRegistry=t,this.collapsed=new Map,this.scene=e,this.seedFromScene(e)}seedFromScene(e){this.collapsed=new Map(e.groups.map(e=>[e.id,e.collapsed]))}reset(e){this.scene=e,this.seedFromScene(e)}isCollapsed(e){return this.collapsed.get(e)??!1}collapsedGroupIds(){let e=new Set;for(let[t,n]of this.collapsed)n&&e.add(t);return e}toggleGroup(e){return this.setCollapsed(e,!this.isCollapsed(e))}setCollapsed(e,t){let n=this.scene.groups.find(t=>t.id===e);if(!n)return this.isCollapsed(e);let r=this.isCollapsed(e);return this.collapsed.set(e,t),t&&!r&&this.deregisterChildren(n),t}deregisterChildren(e){if(this.animationRegistry)for(let t of e.children)this.animationRegistry.pauseAll(t),this.animationRegistry.unregisterElement(t)}};function fr(e,t){return new dr(e,t)}var pr=`unknown`,mr=class{constructor(e,t,n,r){this.map=e,this.transitions=t,this.defaultTransition=n,this.onWarning=r}resolve(e,t){let n=String(e),r=this.map[n],i=this.currentState;if(r===void 0){this.onWarning?.({code:`UNMAPPED_STATE_VALUE`,message:`Tag "${t}": value "${n}" has no entry in this binding's state map`,tag:t});let e=i??`unknown`;return{state:e,previousState:i,transition:this.resolveDefault(i,e),changed:!1}}if(this.currentState=r,i===void 0||i===r)return{state:r,previousState:i,transition:this.resolveDefault(i,r),changed:!1};let a=`${i}→${r}`;return{state:r,previousState:i,transition:this.transitions[a]??this.resolveDefault(i,r),changed:!0}}resolveDefault(e,t){return typeof this.defaultTransition==`function`?this.defaultTransition(e,t):this.defaultTransition}};function hr(e,t,n,r=44){let i=r/n,a=Math.max(e,i),o=Math.max(t,i);return{x:(e-a)/2,y:(t-o)/2,w:a,h:o}}var gr=`http://www.w3.org/2000/svg`;function _r(e,t,n,r={x:0,y:0}){let i=hr(e,t,n),a=document.createElementNS(gr,`rect`);return a.setAttribute(`x`,String(i.x+r.x)),a.setAttribute(`y`,String(i.y+r.y)),a.setAttribute(`width`,String(i.w)),a.setAttribute(`height`,String(i.h)),a.setAttribute(`fill`,`transparent`),a.setAttribute(`class`,`vscada-hit-area`),a.style.pointerEvents=`all`,a.style.cursor=`pointer`,a.setAttribute(`tabindex`,`0`),a.setAttribute(`role`,`button`),a}function vr(e,t,n,r,i={x:0,y:0}){let a=hr(t,n,r);e.setAttribute(`x`,String(a.x+i.x)),e.setAttribute(`y`,String(a.y+i.y)),e.setAttribute(`width`,String(a.w)),e.setAttribute(`height`,String(a.h))}function yr(e=10){let t=new Map;return{onPointerDown(e,n,r){t.set(e,{x:n,y:r})},onPointerUp(n,r,i){let a=t.get(n);return t.delete(n),a&&Math.hypot(r-a.x,i-a.y)<=e?`tap`:`drag`},onPointerCancel(e){t.delete(e)}}}function br(e,t){let{elementId:n,elementType:r,tags:i,arbiter:a,isInteractive:o,onClick:s,onHoverChange:c}=t;e.addEventListener(`pointerdown`,e=>{let t=e;a.onPointerDown(t.pointerId,t.clientX,t.clientY)}),e.addEventListener(`pointerup`,e=>{let t=e;a.onPointerUp(t.pointerId,t.clientX,t.clientY)!==`tap`||!o()||s({elementId:n,tags:i,elementType:r})}),e.addEventListener(`pointercancel`,e=>{a.onPointerCancel(e.pointerId)}),e.addEventListener(`keydown`,e=>{let t=e;t.key!==`Enter`&&t.key!==` `||o()&&(t.preventDefault(),s({elementId:n,tags:i,elementType:r}))}),c&&(e.addEventListener(`pointerenter`,e=>{e.pointerType===`mouse`&&c(!0)}),e.addEventListener(`pointerleave`,e=>{e.pointerType===`mouse`&&c(!1)}))}var xr=.0015;function Sr(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function Cr(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function wr(e,t=10){let n=new Map,r=null,i=null;function a(){if(n.size<2)return null;let e=[...n.values()];return[e[0],e[1]]}return{onPointerDown(e,t,o){if(n.set(e,{originX:t,originY:o,x:t,y:o}),n.size>=2){r=null;let e=a();i=e?Sr(e[0],e[1]):null}},onPointerMove(o,s,c){let l=n.get(o);if(!l)return;if(l.x=s,l.y=c,n.size>=2){let t=a();if(!t||i===null||i<1)return;let n=Sr(t[0],t[1]),r=n/i;i=n;let o=Cr(t[0],t[1]);e.onZoomAboutPoint(e.getZoom()*r,o.x,o.y);return}if(r===null){if(Math.hypot(s-l.originX,c-l.originY)<=t)return;r=o,l.originX=s,l.originY=c;return}if(o!==r)return;let u=s-l.originX,d=c-l.originY;l.originX=s,l.originY=c,e.onPan(u,d)},onPointerUp(e){n.delete(e),r===e&&(r=null),n.size<2&&(i=null)},onPointerCancel(e){n.delete(e),r===e&&(r=null),n.size<2&&(i=null)},onWheel(t,n,r){let i=Math.exp(-t*xr);e.onZoomAboutPoint(e.getZoom()*i,n,r)}}}var Tr=.6,Er=10;function Dr(e){if(e>=1)return 1;let t=10*Math.sqrt(1-Tr*Tr),n=Math.exp(-.6*10*e),r=Tr*10/t;return 1-n*(Math.cos(t*e)+r*Math.sin(t*e))}var Or={linear:e=>e,"ease-in":e=>e*e,"ease-out":e=>1-(1-e)*(1-e),"critically-damped-overshoot":Dr};function kr(e){return Or[e]??Or.linear}var Ar=class{constructor(e){this.startTime=0,this.durationMs=1,this.easing=Or.linear,this.startValue=e,this.targetValue=e}retarget(e,t,n,r){this.startValue=this.valueAt(e),this.targetValue=t,this.startTime=e,this.durationMs=Math.max(n,1),this.easing=kr(r)}valueAt(e){let t=Math.min(Math.max((e-this.startTime)/this.durationMs,0),1);return this.startValue+(this.targetValue-this.startValue)*this.easing(t)}isSettled(e){return e-this.startTime>=this.durationMs}snap(e){this.startValue=this.targetValue,this.startTime=e,this.durationMs=1}};function jr(e,t,n){return Math.min(Math.max(e,t),n)}function Mr(e,t,n,r){let i=t-r-t*n,a=r;return i>a?(i+a)/2:jr(e,i,a)}var Nr=class{constructor(e,t,n={}){this.timeSource=e,this.onFrame=t,this.canvasWidth=0,this.canvasHeight=0,this.zoomValue=1,this.panXValue=0,this.panYValue=0,this.tween=null,this.stopTick=null,this.minZoom=n.minZoom??.25,this.maxZoom=n.maxZoom??4,this.panMarginPx=n.panMarginPx??100,this.zoomTweenDurationMs=n.zoomTweenDurationMs??300}get zoom(){return this.zoomValue}get pan(){return{x:this.panXValue,y:this.panYValue}}reset(e,t){this.canvasWidth=e,this.canvasHeight=t,this.tween=null,this.stopTick?.(),this.stopTick=null,this.zoomValue=1,this.panXValue=0,this.panYValue=0,this.onFrame(this.currentTransform())}currentTransform(){return{zoom:this.zoomValue,panX:this.panXValue,panY:this.panYValue}}clampZoom(e){return jr(e,this.minZoom,this.maxZoom)}applyPanClamp(){this.panXValue=Mr(this.panXValue,this.canvasWidth,this.zoomValue,this.panMarginPx),this.panYValue=Mr(this.panYValue,this.canvasHeight,this.zoomValue,this.panMarginPx)}setZoomImmediate(e){this.tween=null,this.stopTick?.(),this.stopTick=null,this.zoomValue=this.clampZoom(e),this.applyPanClamp(),this.onFrame(this.currentTransform())}setZoomAnimated(e,t=this.zoomTweenDurationMs){let n=this.clampZoom(e),r=this.timeSource.now(),i=new Ar(this.zoomValue);i.retarget(r,n,t,`ease-out`),this.tween=i,this.ensureAnimating()}panBy(e,t){this.panXValue+=e,this.panYValue+=t,this.applyPanClamp(),this.onFrame(this.currentTransform())}zoomAboutPoint(e,t,n){this.tween=null,this.stopTick?.(),this.stopTick=null;let r=this.zoomValue,i=this.clampZoom(e),a=i/r;this.panXValue=t-(t-this.panXValue)*a,this.panYValue=n-(n-this.panYValue)*a,this.zoomValue=i,this.applyPanClamp(),this.onFrame(this.currentTransform())}ensureAnimating(){this.stopTick||(this.stopTick=this.timeSource.onTick(e=>this.tickTween(e)))}tickTween(e){let t=this.tween;if(!t){this.stopTick?.(),this.stopTick=null;return}this.zoomValue=t.valueAt(e),this.applyPanClamp(),this.onFrame(this.currentTransform()),t.isSettled(e)&&(this.tween=null,this.stopTick?.(),this.stopTick=null)}snap(){if(!this.tween)return;let e=this.timeSource.now();this.tween.snap(e),this.zoomValue=this.tween.valueAt(e),this.tween=null,this.stopTick?.(),this.stopTick=null,this.applyPanClamp(),this.onFrame(this.currentTransform())}destroy(){this.stopTick?.(),this.stopTick=null,this.tween=null}};function Pr(e,t,n){return new Nr(e,t,n)}var Fr=`VSCADA`;function Ir(e){try{let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i}catch{return null}}function Lr(e){return typeof e==`object`&&!!e&&typeof e.company==`string`&&typeof e.expiry==`string`&&typeof e.tier==`string`&&typeof e.keyId==`string`}function Rr(e){let t=e.split(`.`);if(t.length!==4||t[0]!==Fr)return null;let[,n,r,i]=t,a=Ir(r);if(!a)return null;let o;try{o=JSON.parse(new TextDecoder().decode(a))}catch{return null}if(!Lr(o))return null;let s=Ir(i);return s?{version:n,encodedPayload:r,payload:o,signature:s}:null}function zr(e,t){return new TextEncoder().encode(`${e}.${t}`)}var Br={};function Vr(){return globalThis.crypto?.subtle!==void 0}async function Hr(e,t,n){let r=globalThis.crypto?.subtle;if(!r)return!1;try{let i=await r.importKey(`jwk`,n,{name:`ECDSA`,namedCurve:`P-256`},!1,[`verify`]);return await r.verify({name:`ECDSA`,hash:`SHA-256`},i,t,e)}catch{return!1}}function Ur(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function F(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(`${n}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let n=t&&`"${t}" `;throw RangeError(`${n}expected integer >= 0, got ${e}`)}}function I(e,t,n=``){let r=Ur(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`,l=o+`expected Uint8Array`+s+`, got `+c;throw r?RangeError(l):TypeError(l)}return e}function Wr(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`Hash must wrapped by utils.createHasher`);if(F(e.outputLen),F(e.blockLen),e.outputLen<1)throw Error(`"outputLen" must be >= 1`);if(e.blockLen<1)throw Error(`"blockLen" must be >= 1`)}function Gr(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function Kr(e,t){I(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw RangeError(`"digestInto() output" expected to be of length >=`+n)}function qr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Jr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function L(e,t){return e<<32-t|e>>>t}var Yr=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,Xr=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function Zr(e){if(I(e),Yr)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=Xr[e[n]];return t}var R={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qr(e){if(e>=R._0&&e<=R._9)return e-R._0;if(e>=R.A&&e<=R.F)return e-(R.A-10);if(e>=R.a&&e<=R.f)return e-(R.a-10)}function $r(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(Yr)try{return Uint8Array.fromHex(e)}catch(e){throw e instanceof SyntaxError?RangeError(e.message):e}let t=e.length,n=t/2;if(t%2)throw RangeError(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=Qr(e.charCodeAt(i)),a=Qr(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw RangeError(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function ei(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];I(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function ti(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function ni(e=32){F(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var ri=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ii(e){"@babel/helpers - typeof";return ii=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},ii(e)}function ai(e,t){if(ii(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(ii(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function oi(e){var t=ai(e,`string`);return ii(t)==`symbol`?t:t+``}function z(e,t,n){return(t=oi(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function si(e,t,n){return e&t^~e&n}function ci(e,t,n){return e&t^e&n^t&n}var li=class{constructor(e,t,n,r){z(this,`blockLen`,void 0),z(this,`outputLen`,void 0),z(this,`canXOF`,!1),z(this,`padOffset`,void 0),z(this,`isLE`,void 0),z(this,`buffer`,void 0),z(this,`view`,void 0),z(this,`finished`,!1),z(this,`length`,0),z(this,`pos`,0),z(this,`destroyed`,!1),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Jr(this.buffer)}update(e){Gr(this),I(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=Jr(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Gr(this),Kr(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,qr(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(this.length*8),i),this.process(n,0);let o=Jr(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},B=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ui=Uint32Array.from([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]),V=new Uint32Array(64),di=class extends li{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)V[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=V[e-15],n=V[e-2],r=L(t,7)^L(t,18)^t>>>3;V[e]=(L(n,17)^L(n,19)^n>>>10)+V[e-7]+r+V[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=L(o,6)^L(o,11)^L(o,25),u=l+t+si(o,s,c)+ui[e]+V[e]|0,d=(L(n,2)^L(n,13)^L(n,22))+ci(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){qr(V)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),qr(this.buffer)}},fi=class extends di{constructor(){super(32),z(this,`A`,B[0]|0),z(this,`B`,B[1]|0),z(this,`C`,B[2]|0),z(this,`D`,B[3]|0),z(this,`E`,B[4]|0),z(this,`F`,B[5]|0),z(this,`G`,B[6]|0),z(this,`H`,B[7]|0)}},pi=ti(()=>new fi,ri(1)),H=(e,t,n)=>I(e,t,n),mi=F,hi=Zr,U=(...e)=>ei(...e),gi=e=>$r(e),_i=Ur,vi=e=>ni(e),yi=BigInt(0),bi=BigInt(1);function xi(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}" `;throw TypeError(n+`expected boolean, got type=`+typeof e)}return e}function Si(e){if(typeof e==`bigint`){if(!ji(e))throw RangeError(`positive bigint expected, got `+e)}else mi(e);return e}function Ci(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function wi(e){let t=Si(e).toString(16);return t.length&1?`0`+t:t}function Ti(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?yi:BigInt(`0x`+e)}function Ei(e){return Ti(Zr(e))}function Di(e){return Ti(Zr(Ai(I(e)).reverse()))}function Oi(e,t){if(F(t),t===0)throw RangeError(`zero length`);e=Si(e);let n=e.toString(16);if(n.length>t*2)throw RangeError(`number too large`);return $r(n.padStart(t*2,`0`))}function ki(e,t){return Oi(e,t).reverse()}function Ai(e){return Uint8Array.from(H(e))}var ji=e=>typeof e==`bigint`&&yi<=e;function Mi(e,t,n){return ji(e)&&ji(t)&&ji(n)&&t<=e&&e<n}function Ni(e,t,n,r){if(!Mi(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function Pi(e){if(e<yi)throw Error(`expected non-negative bigint, got `+e);let t;for(t=0;e>yi;e>>=bi,t+=1);return t}var Fi=e=>(bi<<BigInt(e))-bi;function Ii(e,t,n){if(F(e,`hashLen`),F(t,`qByteLen`),typeof n!=`function`)throw TypeError(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=Uint8Array.of(),a=Uint8Array.of(0),o=Uint8Array.of(1),s=r(e),c=r(e),l=0,u=()=>{s.fill(1),c.fill(0),l=0},d=(...e)=>n(c,U(s,...e)),f=(e=i)=>{c=d(a,e),s=d(),e.length!==0&&(c=d(o,e),s=d())},p=()=>{if(l++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){s=d();let t=s.slice();n.push(t),e+=s.length}return U(...n)};return(e,t)=>{u(),f(e);let n;for(;(n=t(p()))===void 0;)f();return u(),n}}function Li(e,t={},n={}){if(Object.prototype.toString.call(e)!==`[object Object]`)throw TypeError(`expected valid options object`);function r(t,n,r){if(!r&&n!==`function`&&!Object.hasOwn(e,t))throw TypeError(`param "${t}" is invalid: expected own property`);let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw TypeError(`param "${t}" is invalid: expected ${n}, got ${a}`)}let i=(e,t)=>Object.entries(e).forEach(([e,n])=>r(e,n,t));i(t,!1),i(n,!0)}var W=BigInt(0),G=BigInt(1),K=BigInt(2),Ri=BigInt(3),zi=BigInt(4),Bi=BigInt(5),Vi=BigInt(7),Hi=BigInt(8),Ui=BigInt(9),Wi=BigInt(16);function q(e,t){if(t<=W)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=W?n:t+n}function Gi(e,t){if(e===W)throw Error(`invert: expected non-zero number`);if(t<=W)throw Error(`invert: expected positive modulus, got `+t);let n=q(e,t),r=t,i=W,a=G,o=G,s=W;for(;n!==W;){let e=r/n,t=r-n*e,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==G)throw Error(`invert: does not exist`);return q(i,t)}function Ki(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function qi(e,t){let n=e,r=(n.ORDER+G)/zi,i=n.pow(t,r);return Ki(n,i,t),i}function Ji(e,t){let n=e,r=(n.ORDER-Bi)/Hi,i=n.mul(t,K),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,K),a),c=n.mul(o,n.sub(s,n.ONE));return Ki(n,c,t),c}function Yi(e){let t=oa(e),n=Xi(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+Vi)/Wi;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return Ki(n,m,t),m})}function Xi(e){if(e<Ri)throw Error(`sqrt is not defined for small field`);let t=e-G,n=0;for(;t%K===W;)t/=K,n++;let r=K,i=oa(e);for(;na(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return qi;let a=i.pow(r,t),o=(t+G)/K;return function(e,r){let i=e;if(i.is0(r))return r;if(na(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))return i.ZERO;let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=G<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function Zi(e){return e%zi===Ri?qi:e%Hi===Bi?Ji:e%Wi===Ui?Yi(e):Xi(e)}var Qi=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function $i(e){if(Li(e,Qi.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,BYTES:`number`,BITS:`number`})),Ci(e.BYTES,`BYTES`),Ci(e.BITS,`BITS`),e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=G)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function ea(e,t,n){let r=e;if(n<W)throw Error(`invalid exponent, negatives unsupported`);if(n===W)return r.ONE;if(n===G)return t;let i=r.ONE,a=t;for(;n>W;)n&G&&(i=r.mul(i,a)),a=r.sqr(a),n>>=G;return i}function ta(e,t,n=!1){let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function na(e,t){let n=e,r=(n.ORDER-G)/K,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function ra(e,t){if(t!==void 0&&mi(t),e<=W)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=Pi(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected bit length (${n}) >= n.length (${t})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}var ia=new WeakMap,aa=class{constructor(e,t={}){if(z(this,`ORDER`,void 0),z(this,`BITS`,void 0),z(this,`BYTES`,void 0),z(this,`isLE`,void 0),z(this,`ZERO`,W),z(this,`ONE`,G),z(this,`_lengths`,void 0),z(this,`_mod`,void 0),e<=G)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=ra(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return q(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return W<=e&&e<this.ORDER}is0(e){return e===W}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&G)===G}neg(e){return q(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return q(e*e,this.ORDER)}add(e,t){return q(e+t,this.ORDER)}sub(e,t){return q(e-t,this.ORDER)}mul(e,t){return q(e*t,this.ORDER)}pow(e,t){return ea(this,e,t)}div(e,t){return q(e*Gi(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Gi(e,this.ORDER)}sqrt(e){let t=ia.get(this);return t||ia.set(this,t=Zi(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?ki(e,this.BYTES):Oi(e,this.BYTES)}fromBytes(e,t=!1){H(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?Di(e):Ei(e);if(o&&(s=q(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return ta(this,e)}cmov(e,t,n){return xi(n,`condition`),n?t:e}};Object.freeze(aa.prototype);function oa(e,t={}){return new aa(e,t)}function sa(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=G)throw Error(`field order must be greater than 1`);let t=Pi(e-G);return Math.ceil(t/8)}function ca(e){let t=sa(e);return t+Math.ceil(t/2)}function la(e,t,n=!1){H(e);let r=e.length,i=sa(t),a=Math.max(ca(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=q(n?Di(e):Ei(e),t-G)+G;return n?ki(o,i):Oi(o,i)}var ua=BigInt(0),J=BigInt(1);function da(e,t){let n=t.negate();return e?n:t}function fa(e,t){let n=ta(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function pa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function ma(e,t){pa(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:Fi(e),maxNumber:i,shiftBy:BigInt(e)}}function ha(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=J);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}var ga=new WeakMap,_a=new WeakMap;function va(e){return _a.get(e)||1}function ya(e){if(e!==ua)throw Error(`invalid wNAF`)}var ba=class{constructor(e,t){z(this,`BASE`,void 0),z(this,`ZERO`,void 0),z(this,`Fn`,void 0),z(this,`bits`,void 0),this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>ua;)t&J&&(n=n.add(r)),r=r.double(),t>>=J;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=ma(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=ma(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=ha(n,e,a);n=o,c?i=i.add(da(u,t[d])):r=r.add(da(l,t[s]))}return ya(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=ma(e,this.bits);for(let e=0;e<i.windows&&n!==ua;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=ha(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return ya(n),r}getPrecomputes(e,t,n){let r=ga.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),ga.set(t,r))),r}cached(e,t,n){let r=va(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=va(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){pa(t,this.bits),_a.set(e,t),ga.delete(e)}hasCache(e){return va(e)!==1}};function xa(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>ua||r>ua;)n&J&&(a=a.add(i)),r&J&&(o=o.add(i)),i=i.double(),n>>=J,r>>=J;return{p1:a,p2:o}}function Sa(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return $i(t),t}else return oa(e,{isLE:n})}function Ca(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>ua))throw Error(`CURVE.${e} must be positive bigint`)}let i=Sa(t.p,n.Fp,r),a=Sa(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function wa(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var Ta=class{constructor(e,t){if(z(this,`oHash`,void 0),z(this,`iHash`,void 0),z(this,`blockLen`,void 0),z(this,`outputLen`,void 0),z(this,`canXOF`,!1),z(this,`finished`,!1),z(this,`destroyed`,!1),Wr(e),I(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),qr(r)}update(e){return Gr(this),this.iHash.update(e),this}digestInto(e){Gr(this),Kr(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ea=(()=>{let e=((e,t,n)=>new Ta(e,t).update(n).digest());return e.create=(e,t)=>new Ta(e,t),e})(),Da=(e,t)=>(e+(e>=0?t:-t)/ja)/t;function Oa(e,t,n){Ni(`scalar`,e,X,n);let[[r,i],[a,o]]=t,s=Da(o*e,n),c=Da(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<X,f=u<X;d&&(l=-l),f&&(u=-u);let p=Fi(Math.ceil(Pi(n)/2))+Z;if(l<X||l>=p||u<X||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function ka(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function Aa(e,t){Li(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return xi(n.lowS,`lowS`),xi(n.prehash,`prehash`),n.format!==void 0&&ka(n.format),n}var Y={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=Y;if(Ci(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(typeof t!=`string`)throw TypeError(`"data" expected string, got type=`+typeof t);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=wi(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?wi(i.length/2|128):``;return wi(e)+a+i+t},decode(e,t){let{Err:n}=Y;t=H(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=Y;if(Si(e),e<X)throw new t(`integer: negative integers are not allowed`);let n=wi(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=Y;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return Ei(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=Y,i=H(e,void 0,`signature`),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=Y,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};Object.freeze(Y._tlv),Object.freeze(Y._int),Object.freeze(Y);var X=BigInt(0),Z=BigInt(1),ja=BigInt(2),Ma=BigInt(3),Na=BigInt(4);function Pa(e,t={}){var n;let r=Ca(`weierstrass`,e,t),i=r.Fp,a=r.Fn,o=r.CURVE,{h:s,n:c}=o;Li(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`});let{endo:l,allowInfinityPoint:u}=t;if(l&&(!i.is0(o.a)||typeof l.beta!=`bigint`||!Array.isArray(l.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let d=Ia(i,a);function f(){if(!i.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function p(e,t,n){if(u&&t.is0())return Uint8Array.of(0);let{x:r,y:a}=t.toAffine(),o=i.toBytes(r);return xi(n,`isCompressed`),n?(f(),U(Fa(!i.isOdd(a)),o)):U(Uint8Array.of(4),o,i.toBytes(a))}function m(e){H(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=d,r=e.length,a=e[0],o=e.subarray(1);if(u&&r===1&&a===0)return{x:i.ZERO,y:i.ZERO};if(r===t&&(a===2||a===3)){let e=i.fromBytes(o);if(!i.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=_(e),n;try{n=i.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}f();let r=i.isOdd(n);return(a&1)==1!==r&&(n=i.neg(n)),{x:e,y:n}}else if(r===n&&a===4){let e=i.BYTES,t=i.fromBytes(o.subarray(0,e)),n=i.fromBytes(o.subarray(e,e*2));if(!v(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${r}, expected compressed=${t} or uncompressed=${n}`)}let h=t.toBytes===void 0?p:t.toBytes,g=t.fromBytes===void 0?m:t.fromBytes;function _(e){let t=i.sqr(e),n=i.mul(t,e);return i.add(i.add(n,i.mul(e,o.a)),o.b)}function v(e,t){let n=i.sqr(t),r=_(e);return i.eql(n,r)}if(!v(o.Gx,o.Gy))throw Error(`bad curve params: generator point`);let y=i.mul(i.pow(o.a,Ma),Na),ee=i.mul(i.sqr(o.b),BigInt(27));if(i.is0(i.add(y,ee)))throw Error(`bad curve params: a or b`);function b(e,t,n=!1){if(!i.isValid(t)||n&&i.is0(t))throw Error(`bad point coordinate ${e}`);return t}function x(e){if(!(e instanceof C))throw Error(`Weierstrass Point expected`)}function S(e){if(!l||!l.basises)throw Error(`no endo`);return Oa(e,l.basises,a.ORDER)}function te(e,t,n,r,a){return n=new C(i.mul(n.X,e),n.Y,n.Z),t=da(r,t),n=da(a,n),t.add(n)}class C{constructor(e,t,n){z(this,`X`,void 0),z(this,`Y`,void 0),z(this,`Z`,void 0),this.X=b(`x`,e),this.Y=b(`y`,t,!0),this.Z=b(`z`,n),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!i.isValid(t)||!i.isValid(n))throw Error(`invalid affine point`);if(e instanceof C)throw Error(`projective point not allowed`);return i.is0(t)&&i.is0(n)?C.ZERO:new C(t,n,i.ONE)}static fromBytes(e){let t=C.fromAffine(g(H(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return C.fromBytes(gi(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return T.createCache(this,e),t||this.multiply(Ma),this}assertValidity(){let e=this;if(e.is0()){if(t.allowInfinityPoint&&i.is0(e.X)&&i.eql(e.Y,i.ONE)&&i.is0(e.Z))return;throw Error(`bad point: ZERO`)}let{x:n,y:r}=e.toAffine();if(!i.isValid(n)||!i.isValid(r))throw Error(`bad point: x or y not field elements`);if(!v(n,r))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`)}hasEvenY(){let{y:e}=this.toAffine();if(!i.isOdd)throw Error(`Field doesn't support isOdd`);return!i.isOdd(e)}equals(e){x(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:o,Z:s}=e,c=i.eql(i.mul(t,s),i.mul(a,r)),l=i.eql(i.mul(n,s),i.mul(o,r));return c&&l}negate(){return new C(this.X,i.neg(this.Y),this.Z)}double(){let{a:e,b:t}=o,n=i.mul(t,Ma),{X:r,Y:a,Z:s}=this,c=i.ZERO,l=i.ZERO,u=i.ZERO,d=i.mul(r,r),f=i.mul(a,a),p=i.mul(s,s),m=i.mul(r,a);return m=i.add(m,m),u=i.mul(r,s),u=i.add(u,u),c=i.mul(e,u),l=i.mul(n,p),l=i.add(c,l),c=i.sub(f,l),l=i.add(f,l),l=i.mul(c,l),c=i.mul(m,c),u=i.mul(n,u),p=i.mul(e,p),m=i.sub(d,p),m=i.mul(e,m),m=i.add(m,u),u=i.add(d,d),d=i.add(u,d),d=i.add(d,p),d=i.mul(d,m),l=i.add(l,d),p=i.mul(a,s),p=i.add(p,p),d=i.mul(p,m),c=i.sub(c,d),u=i.mul(p,f),u=i.add(u,u),u=i.add(u,u),new C(c,l,u)}add(e){x(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:s,Z:c}=e,l=i.ZERO,u=i.ZERO,d=i.ZERO,f=o.a,p=i.mul(o.b,Ma),m=i.mul(t,a),h=i.mul(n,s),g=i.mul(r,c),_=i.add(t,n),v=i.add(a,s);_=i.mul(_,v),v=i.add(m,h),_=i.sub(_,v),v=i.add(t,r);let y=i.add(a,c);return v=i.mul(v,y),y=i.add(m,g),v=i.sub(v,y),y=i.add(n,r),l=i.add(s,c),y=i.mul(y,l),l=i.add(h,g),y=i.sub(y,l),d=i.mul(f,v),l=i.mul(p,g),d=i.add(l,d),l=i.sub(h,d),d=i.add(h,d),u=i.mul(l,d),h=i.add(m,m),h=i.add(h,m),g=i.mul(f,g),v=i.mul(p,v),h=i.add(h,g),g=i.sub(m,g),g=i.mul(f,g),v=i.add(v,g),m=i.mul(h,v),u=i.add(u,m),m=i.mul(y,v),l=i.mul(_,l),l=i.sub(l,m),m=i.mul(_,h),d=i.mul(y,d),d=i.add(d,m),new C(l,u,d)}subtract(e){return x(e),this.add(e.negate())}is0(){return this.equals(C.ZERO)}multiply(e){let{endo:n}=t;if(!a.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let r,i,o=e=>T.cached(this,e,e=>fa(C,e));if(n){let{k1neg:t,k1:a,k2neg:s,k2:c}=S(e),{p:l,f:u}=o(a),{p:d,f}=o(c);i=u.add(f),r=te(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,i=n}return fa(C,[r,i])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this,i=e;if(!a.isValid(i))throw RangeError(`invalid scalar: out of range`);if(i===X||r.is0())return C.ZERO;if(i===Z)return r;if(T.hasCache(this))return this.multiply(i);if(n){let{k1neg:e,k1:t,k2neg:a,k2:o}=S(i),{p1:s,p2:c}=xa(C,r,t,o);return te(n.beta,s,c,e,a)}else return T.unsafe(r,i)}toAffine(e){let t=this,n=e,{X:r,Y:a,Z:o}=t;if(i.eql(o,i.ONE))return{x:r,y:a};let s=t.is0();n??(n=s?i.ONE:i.inv(o));let c=i.mul(r,n),l=i.mul(a,n),u=i.mul(o,n);if(s)return{x:i.ZERO,y:i.ZERO};if(!i.eql(u,i.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){let{isTorsionFree:e}=t;return s===Z?!0:e?e(C,this):T.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:e}=t;return s===Z?this:e?e(C,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Z?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return xi(e,`isCompressed`),this.assertValidity(),h(C,this,e)}toHex(e=!0){return hi(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}n=C,z(C,`BASE`,new n(o.Gx,o.Gy,i.ONE)),z(C,`ZERO`,new n(i.ZERO,i.ONE,i.ZERO)),z(C,`Fp`,i),z(C,`Fn`,a);let w=a.BITS,T=new ba(C,t.endo?Math.ceil(w/2):w);return w>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function Fa(e){return Uint8Array.of(e?2:3)}function Ia(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function La(e,t={}){let{Fn:n}=e,r=t.randomBytes===void 0?vi:t.randomBytes,i=Object.assign(Ia(e.Fp,n),{seed:Math.max(ca(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,la(H(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!_i(e))return;let s=H(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t);return e.fromBytes(r).multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=wa(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function Ra(e,t,n={}){let r=t;Wr(r),Li(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`}),n=Object.assign({},n);let i=n.randomBytes===void 0?vi:n.randomBytes,a=n.hmac===void 0?(e,t)=>Ea(r,e,t):n.hmac,{Fp:o,Fn:s}=e,{ORDER:c,BITS:l}=s,{keygen:u,getPublicKey:d,getSharedSecret:f,utils:p,lengths:m}=La(e,n),h={prehash:!0,lowS:typeof n.lowS!=`boolean`||n.lowS,format:`compact`,extraEntropy:!1},g=c*ja+Z<o.ORDER;function _(e){return e>c>>Z}function v(e,t){if(!s.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function y(){if(g)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function ee(e,t){ka(t);let n=m.signature;return H(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class b{constructor(e,t,n){if(z(this,`r`,void 0),z(this,`s`,void 0),z(this,`recovery`,void 0),this.r=v(`r`,e),this.s=v(`s`,t),n!=null){if(y(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=h.format){ee(e,t);let n;if(t===`der`){let{r:t,s:n}=Y.toSig(H(e));return new b(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=m.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new b(s.fromBytes(i),s.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(gi(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new b(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+c:n;if(!o.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let l=o.toBytes(a),u=e.fromBytes(U(Fa((i&1)==0),l)),d=s.inv(a),f=S(H(t,void 0,`msgHash`)),p=s.create(-f*d),m=s.create(r*d),h=e.BASE.multiplyUnsafe(p).add(u.multiplyUnsafe(m));if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return _(this.s)}toBytes(e=h.format){if(ka(e),e===`der`)return gi(Y.hexFromSig(this));let{r:t,s:n}=this,r=s.toBytes(t),i=s.toBytes(n);return e===`recovered`?(y(),U(Uint8Array.of(this.assertRecovery()),r,i)):U(r,i)}toHex(e){return hi(this.toBytes(e))}}Object.freeze(b.prototype),Object.freeze(b);let x=n.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=Ei(e),n=e.length*8-l;return n>0?t>>BigInt(n):t}:n.bits2int,S=n.bits2int_modN===void 0?function(e){return s.create(x(e))}:n.bits2int_modN,te=Fi(l);function C(e){return Ni(`num < 2^`+l,e,X,te),s.toBytes(e)}function w(e,t){return H(e,void 0,`message`),t?H(r(e),void 0,`prehashed message`):e}function T(t,n,r){let{lowS:a,prehash:o,extraEntropy:c}=Aa(r,h);t=w(t,o);let l=S(t),u=s.fromBytes(n);if(!s.isValidNot0(u))throw Error(`invalid private key`);let d=[C(u),C(l)];if(c!=null&&c!==!1){let e=c===!0?i(m.secretKey):c;d.push(H(e,void 0,`extraEntropy`))}let f=U(...d),p=l;function v(t){let n=x(t);if(!s.isValidNot0(n))return;let r=s.inv(n),i=e.BASE.multiply(n).toAffine(),o=s.create(i.x);if(o===X)return;let c=s.create(r*s.create(p+o*u));if(c===X)return;let l=(i.x===o?0:2)|Number(i.y&Z),d=c;return a&&_(c)&&(d=s.neg(c),l^=1),new b(o,d,g?void 0:l)}return{seed:f,k2sig:v}}function ne(e,t,n={}){let{seed:i,k2sig:o}=T(e,t,n);return Ii(r.outputLen,s.BYTES,a)(i,o).toBytes(n.format)}function re(t,n,r,i={}){let{lowS:a,prehash:o,format:c}=Aa(i,h);if(r=H(r,void 0,`publicKey`),n=w(n,o),!_i(t)){let e=t instanceof b?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}ee(t,c);try{let i=b.fromBytes(t,c),o=e.fromBytes(r);if(a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=S(n),f=s.inv(u),p=s.create(d*f),m=s.create(l*f),h=e.BASE.multiplyUnsafe(p).add(o.multiplyUnsafe(m));return!h.is0()&&s.create(h.x)===l}catch{return!1}}function ie(e,t,n={}){let{prehash:r}=Aa(n,h);return t=w(t,r),b.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:f,utils:p,lengths:m,Point:e,sign:ne,verify:re,recoverPublicKey:ie,Signature:b,hash:r})}var za=Ra(Pa({p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)}),pi);function Ba(e,t,n){let r=Va(n);if(!r)return!1;try{return za.verify(t,e,r,{lowS:!1})}catch{return!1}}function Va(e){if(e.kty!==`EC`||e.crv!==`P-256`||!e.x||!e.y)return null;let t=Ir(e.x),n=Ir(e.y);if(!t||!n||t.length!==32||n.length!==32)return null;let r=new Uint8Array(65);return r[0]=4,r.set(t,1),r.set(n,33),r}var Ha={status:`unlicensed`},Ua={status:`pending`};function Wa(e,t,n){let r=Date.parse(e);return Number.isNaN(r)?!1:r>=t||!Number.isNaN(n)&&r>=n}async function Ga(e,t,n,r){let i=Rr(e);if(!i)return Ha;let a=t[i.payload.keyId];if(!a)return{status:`unlicensed`,payload:i.payload};let o=zr(i.version,i.encodedPayload);if(!(Vr()?await Hr(o,i.signature,a):Ba(o,i.signature,a)))return{status:`unlicensed`,payload:i.payload};let s=Date.parse(r);return Wa(i.payload.expiry,n,s)?{status:`licensed`,payload:i.payload}:{status:`unlicensed`,payload:i.payload}}var Ka=null,qa=Ha,Ja=new Map,Ya=new Set,Xa=0;function Za(){Xa++}function Qa(){Xa--}function $a(){return Xa}function eo(e){qa=e;for(let t of Ya)t(e)}function to(e){if(e===Ka)return;Ka=e;let t=Ja.get(e);if(t){eo(t);return}eo(Ua),Ga(e,Br,Date.now(),`2026-09-09`).then(t=>{Ja.set(e,t),Ka===e&&eo(t)})}function no(){return qa}function ro(e){return Ya.add(e),e(qa),()=>Ya.delete(e)}var io=`docs/LICENSING.md`,ao=!1;function oo(e){if(ao)return;ao=!0;let t=e>1?` (${e} instances on this page)`:``;console.info(`[VScada] Running in unlicensed/evaluation mode${t} — full functionality, watermarked. See ${io} to apply a license key.`)}var Q=`http://www.w3.org/2000/svg`,so=`vscada-watermark-pattern`,co=`#808080`;function lo(e,t,n){if(!n.querySelector(`#${so}`)){let e=document.createElementNS(Q,`pattern`);e.setAttribute(`id`,so),e.setAttribute(`width`,`320`),e.setAttribute(`height`,`200`),e.setAttribute(`patternUnits`,`userSpaceOnUse`),e.setAttribute(`patternTransform`,`rotate(-30)`);let t=document.createElementNS(Q,`text`);t.setAttribute(`x`,`10`),t.setAttribute(`y`,`100`),t.setAttribute(`font-size`,`20`),t.setAttribute(`fill`,co),t.textContent=`VScada — unlicensed`,e.appendChild(t),n.appendChild(e)}let r=document.createElementNS(Q,`g`);r.setAttribute(`class`,`vscada-watermark-repeat`),r.setAttribute(`pointer-events`,`none`),r.setAttribute(`display`,`none`);let i=document.createElementNS(Q,`rect`);i.setAttribute(`width`,String(e)),i.setAttribute(`height`,String(t)),i.setAttribute(`fill`,`url(#${so})`),i.setAttribute(`opacity`,`0.12`),r.appendChild(i);let a=document.createElementNS(Q,`g`);a.setAttribute(`class`,`vscada-watermark-badge`),a.setAttribute(`pointer-events`,`none`),a.setAttribute(`display`,`none`);let o=document.createElementNS(Q,`text`);o.setAttribute(`x`,String(e-8)),o.setAttribute(`y`,String(t-8)),o.setAttribute(`text-anchor`,`end`),o.setAttribute(`font-size`,`12`),o.setAttribute(`fill`,co),o.setAttribute(`opacity`,`0.7`),o.textContent=`VScada — unlicensed`,a.appendChild(o);function s(e){let t=e?`inline`:`none`;r.setAttribute(`display`,t),a.setAttribute(`display`,t)}return{repeat:r,badge:a,setVisible:s}}var uo=`http://www.w3.org/2000/svg`;function fo(e){let t=e.cloneNode(!0);return po(e,t),t.getAttribute(`xmlns`)||t.setAttribute(`xmlns`,uo),new XMLSerializer().serializeToString(t)}function po(e,t){mo(e,t);let n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),r=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),i=n.nextNode(),a=r.nextNode();for(;i&&a;)mo(i,a),i=n.nextNode(),a=r.nextNode()}function mo(e,t){let n=getComputedStyle(e),r=n.transform;r&&r!==`none`&&(t.style.transform=r),ho(n,t),go(n,t)}function ho(e,t){let n=t.getAttribute(`style`);if(!n||!n.includes(`var(`))return;let r=n.split(`;`).map(e=>e.trim()).filter(Boolean).map(t=>{let n=t.indexOf(`:`);if(n===-1)return t;let r=t.slice(0,n).trim(),i=t.slice(n+1).trim();return i.includes(`var(`)?`${r}: ${e.getPropertyValue(r).trim()||i}`:`${r}: ${i}`}).join(`; `);t.setAttribute(`style`,r)}function go(e,t){for(let n of[...t.attributes]){if(n.name===`style`||!n.value.includes(`var(`))continue;let r=e.getPropertyValue(n.name).trim();r&&t.setAttribute(n.name,r)}}var _o=`(prefers-reduced-motion: reduce)`,vo=class{constructor(e,t,n){this.target=e,this.staticRepresentations=t,this.matchMedia=n,this.mql=null,this.onChange=e=>this.apply(e.matches),this.priorAnimated=null}connect(){!this.matchMedia||this.mql||(this.mql=this.matchMedia(_o),this.mql.addEventListener(`change`,this.onChange),this.apply(this.mql.matches))}disconnect(){this.mql?.removeEventListener(`change`,this.onChange),this.mql=null}get active(){return this.mql?.matches??!1}apply(e){e?(this.priorAnimated===null&&(this.priorAnimated=this.target.animated),this.staticRepresentations.activateAll(),this.target.animated=!1):(this.priorAnimated!==null&&(this.target.animated=this.priorAnimated,this.priorAnimated=null),this.staticRepresentations.deactivateAll())}},yo=class{constructor(){this.entries=[],this.active=!1}register(e,t){this.entries.push({elementId:e,handle:t}),this.active&&t.activate()}unregisterElement(e){this.entries=this.entries.filter(t=>t.elementId!==e)}activateAll(){this.active=!0;for(let e of this.entries)e.handle.activate()}deactivateAll(){this.active=!1;for(let e of this.entries)e.handle.deactivate()}get isActive(){return this.active}},bo=class{constructor(){this.target=null,this.pending=[],this.flushScheduled=!1,this.sawDisconnect=!1}attach(e){this.target=e}announceConditionTransition(e,t,n){if(!(t!==`bad`&&t!==`stale`)){if(t===`stale`&&n){if(this.sawDisconnect)return;this.sawDisconnect=!0,this.enqueue(`Scene disconnected`);return}this.enqueue(t===`bad`?`${e} quality bad`:`${e} stale`)}}announceThresholdCrossing(e,t,n){n!==`normal`&&this.enqueue(`${e} ${t} ${n} alarm`)}enqueue(e){this.pending.push(e),!this.flushScheduled&&(this.flushScheduled=!0,queueMicrotask(()=>this.flush()))}flush(){this.flushScheduled=!1,this.sawDisconnect=!1;let e=this.pending.join(`; `);this.pending=[],this.target&&(this.target.textContent=e)}};function xo(e,t){let n=new Set;for(let r of t)(r.direction===`below`?e<=r.value:e>=r.value)&&n.add(r.level);return n.has(`low-low`)?`low-low`:n.has(`high-high`)?`high-high`:n.has(`low`)?`low`:n.has(`high`)?`high`:`normal`}function So(e,t,n){if(!e)return n;switch(t){case`low-low`:return e.lowLowColor;case`low`:return e.lowColor;case`high`:return e.highColor;case`high-high`:return e.highHighColor;default:return e.normalColor}}var Co,wo=`http://www.w3.org/2000/svg`;function To(e){return e.type===`off-page`}function Eo(e){return e.type===`svg-import`}function Do(e){return e.startsWith(`__vessel-wave-animation-`)||e.startsWith(`__vapor-drift-animation-`)?`wave`:e.startsWith(`pipe-flow-animation`)?`flow`:e.startsWith(`__rotating-animations-`)?`rotation`:e.startsWith(`__indicator-lamp-animation-`)?`state-lamp`:`rotation`}var Oo=class extends Fe{constructor(e=nt,t=rt,n=typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia.bind(window):void 0){super(),this._scene=null,this._lastError=null,this._pendingDevValidation=null,this._sceneGeneration=0,this._staticRepresentations=new yo,this._liveRegion=new bo,this._unsubscribeConditionTransition=null,this._builtElements=[],this._builtDefs=null,this._watermark=null,this._licenseVerdict={status:`unlicensed`},this._needsStructureInsert=!1,this._schedulerStarted=!1,this._unsubscribeLicense=null,this._interactive=!0,this._gestureArbiter=yr(),this._hitLayerGroup=null,this._hitAreaEntries=[],this._viewportGroup=null,this._lodActive=!1,this._listenersAttached=!1,this._isIntersecting=!0,this._intersectionObserver=null,this._boundVisibilityChange=null,this._unsubscribeRenderStats=null,this._groupViewState=null,this._flowInferenceCache=null,this._flowStoppedSourceIds=new Set,this._flowClosedNodeIds=new Set,this._flowTrackedElementIds=[],this._renderer=t,this._store=new rn(e,e=>this._dispatchValueWarning(e)),this._animations=new on,this._scheduler=new bn(e,this._store,t,this._animations),this._reducedMotion=new vo(this,this._staticRepresentations,n),this._unsubscribeConditionTransition=this._scheduler.onConditionTransition((e,t,n)=>this._handleConditionTransition(e,n)),this._viewportState=Pr(e,e=>this._onViewportFrame(e)),this._panZoomGestures=wr({onPan:(e,t)=>{let n=this._viewBoxScale();this._viewportState.panBy(e*n,t*n)},onZoomAboutPoint:(e,t,n)=>{let r=this._toCanvasPoint(t,n);this._viewportState.zoomAboutPoint(e,r.x,r.y)},getZoom:()=>this._viewportState.zoom})}get stalenessTimeout(){return this._scheduler.stalenessTimeout}set stalenessTimeout(e){this._scheduler.stalenessTimeout=e}get snapThreshold(){return this._scheduler.snapThreshold}set snapThreshold(e){this._scheduler.snapThreshold=e}get connectionState(){return this._scheduler.connectionState}set connectionState(e){this._scheduler.connectionState=e}get mode(){return this._scheduler.mode}set mode(e){this._scheduler.mode=e}get animated(){return this._scheduler.animate}set animated(e){this._scheduler.animate=e}get reducedMotionActive(){return this._reducedMotion.active}snapToTargets(){this._scheduler.snapToTargets(),this._viewportState.snap()}get interactive(){return this._interactive}set interactive(e){this._interactive=e}get zoom(){return this._viewportState.zoom}set zoom(e){this._viewportState.setZoomAnimated(e)}get debug(){return this._scheduler.debug}set debug(e){this._scheduler.debug=e,e&&!this._unsubscribeRenderStats?this._unsubscribeRenderStats=this._scheduler.onRenderStats(e=>this._dispatchRenderStats(e)):!e&&this._unsubscribeRenderStats&&(this._unsubscribeRenderStats(),this._unsubscribeRenderStats=null)}seekAll(e){this._animations.seekAll(e)}exportSVG(){let e=this.renderRoot?.querySelector(`svg`);return e?fo(e):``}static get observedAttributes(){return[...super.observedAttributes,`license-key`,`tag-prefix`,`interactive`,`mode`,`animated`]}attributeChangedCallback(e,t,n){super.attributeChangedCallback(e,t,n),e===`license-key`&&n!==null&&n!==t&&to(n),e===`tag-prefix`&&n!==t&&(this.tagPrefix=n??``),e===`interactive`&&n!==t&&(this.interactive=n!==`false`),e===`mode`&&n!==t&&(this.mode=n===`static`?`static`:`live`),e===`animated`&&n!==t&&(this.animated=n!==`false`)}get tagPrefix(){return this._store.tagPrefix}set tagPrefix(e){this._store.tagPrefix=e}get scene(){return this._scene}set scene(e){if(e===this._scene)return;let t=++this._sceneGeneration;this._teardownBuiltElements();let n=Ue(e,Ye());if(!n.ok){this._scene=null,this._lastError=n.error,this._pendingDevValidation=null,this.dispatchEvent(new CustomEvent(`scene-error`,{detail:n.error,bubbles:!0,composed:!0})),this.requestUpdate();return}this._scene=n.scene,this._lastError=null,this._groupViewState?this._groupViewState.reset(this._scene):this._groupViewState=new dr(this._scene,this._animations),this._viewportState.reset(this._scene.canvas.width,this._scene.canvas.height),this._buildElements(this._scene),this.requestUpdate(),this._pendingDevValidation=We(e).then(e=>{if(t===this._sceneGeneration&&!(!e||e.length===0)){for(let t of e)console.warn(`[vscada] scene diagnostic at "${t.path}": ${t.message}`);this.dispatchEvent(new CustomEvent(`scene-error`,{detail:{code:`BAD_SHAPE`,message:`${e.length} dev-only Zod diagnostic(s); see console`,path:e[0].path},bubbles:!0,composed:!0}))}}).catch(e=>{console.error(`[vscada] dev-only scene validation failed`,e)})}get pendingDevValidation(){return this._pendingDevValidation}get values(){return Array.from(this._store.tags()).map(e=>{let t=this._store.get(e),n={tag:e,value:t.currentValue,quality:t.quality};return t.timestamp!==void 0&&(n.timestamp=t.timestamp),n})}set values(e){this.setValues(e)}setValues(e){this._store.setValues(e),this._scheduler.mode===`static`?this._scheduler.snapToTargets():this._maybeStartScheduler()}clearValues(){this._store.clearValues()}connectedCallback(){super.connectedCallback(),Za();let e=!0;this._unsubscribeLicense=ro(t=>{if(e){e=!1,queueMicrotask(()=>this._onLicenseVerdict(no()));return}this._onLicenseVerdict(t)}),this._maybeStartScheduler(),this._reducedMotion.connect(),typeof IntersectionObserver<`u`&&(this._intersectionObserver=new IntersectionObserver(e=>{let t=e[e.length-1];t&&(this._isIntersecting=t.isIntersecting,this._syncVisibilityPause())}),this._intersectionObserver.observe(this)),typeof document<`u`&&(this._boundVisibilityChange=()=>this._syncVisibilityPause(),document.addEventListener(`visibilitychange`,this._boundVisibilityChange))}disconnectedCallback(){super.disconnectedCallback(),Qa(),this._reducedMotion.disconnect(),this._unsubscribeConditionTransition?.(),this._unsubscribeLicense?.(),this._unsubscribeLicense=null,this._intersectionObserver?.disconnect(),this._intersectionObserver=null,this._boundVisibilityChange&&(document.removeEventListener(`visibilitychange`,this._boundVisibilityChange),this._boundVisibilityChange=null),this._viewportState.destroy(),this._scheduler.stop(),this._schedulerStarted=!1}_onLicenseVerdict(e){this._licenseVerdict=e,this._watermark?.setVisible(e.status===`unlicensed`),e.status===`unlicensed`&&oo($a())}firstUpdated(){let e=this.renderRoot.querySelector(`.vscada-live-region`);e&&this._liveRegion.attach(e);let t=this.renderRoot.querySelector(`svg`);!t||this._listenersAttached||(this._listenersAttached=!0,this._attachPanZoomListeners(t))}updated(e){if(super.updated(e),!this._needsStructureInsert)return;this._needsStructureInsert=!1;let t=this.renderRoot.querySelector(`svg`);if(t){for(;t.firstChild;)t.removeChild(t.firstChild);this._builtDefs&&t.appendChild(this._builtDefs),this._watermark&&t.appendChild(this._watermark.repeat),this._viewportGroup=document.createElementNS(wo,`g`),this._viewportGroup.setAttribute(`class`,`vscada-viewport`);for(let e of this._builtElements)this._viewportGroup.appendChild(e.svg);this._hitLayerGroup&&this._viewportGroup.appendChild(this._hitLayerGroup),t.appendChild(this._viewportGroup),this._applyViewportTransform({zoom:this._viewportState.zoom,panX:this._viewportState.pan.x,panY:this._viewportState.pan.y}),this._watermark&&t.appendChild(this._watermark.badge)}}render(){let e=ve`<div class="vscada-live-region" aria-live="assertive" aria-atomic="true"></div>`;if(this._lastError)return ve`${e}`;let t=this._scene?.canvas.width??100,n=this._scene?.canvas.height??100;return ve`<svg part="canvas" role="graphics-document" aria-label=${this._scene?`SCADA diagram: ${this._scene.id}`:`SCADA diagram`} viewBox="0 0 ${t} ${n}"></svg>${e}`}_buildElements(e){this._builtDefs=document.createElementNS(`http://www.w3.org/2000/svg`,`defs`);let t={tokens:tt(e.theme??`classic-hmi`),defs:this._builtDefs};t.tokens.focusRing&&(this.style.setProperty(`--vscada-focus-ring-color`,t.tokens.focusRing.color),this.style.setProperty(`--vscada-focus-ring-width`,`${t.tokens.focusRing.widthPx}px`),this.style.setProperty(`--vscada-focus-ring-offset`,`${t.tokens.focusRing.offsetPx}px`)),this._watermark=lo(e.canvas.width,e.canvas.height,this._builtDefs),this._watermark.setVisible(this._licenseVerdict.status===`unlicensed`);let n=Qn(e),r=this._groupViewState?.collapsedGroupIds()??new Set,i=new Set;for(let t of e.groups)if(r.has(t.id))for(let e of t.children)i.add(e);let a=e.topology.sources,o=new or(n,e.inferFlow?new Set(a===void 0?[...n.nodes].filter(e=>(n.incoming.get(e)?.length??0)===0&&(n.outgoing.get(e)?.length??0)>0):a.filter(e=>n.nodes.has(e))):new Set);this._flowInferenceCache=o,this._flowStoppedSourceIds=new Set,this._flowClosedNodeIds=new Set;let s=e.inferFlow?[...n.nodes,...n.edges.map(e=>e.id)]:[];this._scheduler.registerFlowInference(o,s);let c=new Map,l=[],u=1;for(let r of e.elements){if(e.inferFlow&&!To(r)&&!Eo(r)&&n.nodes.has(r.id)&&this._registerFlowStateTracking(r),i.has(r.id))continue;let a,o;if(Eo(r)){let e=Zn(r,t,this._renderer,e=>this._dispatchValueWarning(e));a=e.svg,o=e.handles}else{let e=qe(r.type);if(!e)continue;let n=(To(r),r),i=e.build(n,t,this._renderer);a=i.svg,o=i.handles}let s=To(r)||Eo(r)?o:this._wrapHandlesForLiveRegion(r,o);this._registerHandles(r.id,s);let d=document.createElementNS(wo,`g`);if(d.setAttribute(`transform`,`translate(${r.x} ${r.y})`),d.appendChild(a),!To(r)){let e=wn(r.w,r.h,t);d.appendChild(e.group),this._scheduler.registerQualityOverlay(r.id,e);let n=[...new Set(r.bindings.map(e=>e.tag))],i={x:r.x,y:r.y},a=_r(r.w,r.h,this._viewportState.zoom,i);a.setAttribute(`tabindex`,String(u++)),a.setAttribute(`aria-label`,r.label??r.id),this._hitAreaEntries.push({rect:a,w:r.w,h:r.h,origin:i}),br(a,{elementId:r.id,elementType:r.type,tags:n,arbiter:this._gestureArbiter,isInteractive:()=>this._interactive,onClick:e=>this._dispatchElementClick(e),onHoverChange:e=>{e&&this._dispatchElementHover(r.id,n)}}),l.push({area:r.w*r.h,rect:a})}c.set(r.id,d),this._builtElements.push({elementId:r.id,svg:d})}if(l.length>0){this._hitLayerGroup=document.createElementNS(wo,`g`),this._hitLayerGroup.setAttribute(`class`,`vscada-hit-layer`);for(let e of[...l].sort((e,t)=>t.area-e.area))this._hitLayerGroup.appendChild(e.rect)}for(let n of e.groups){let e=document.createElementNS(wo,`g`);if(e.setAttribute(`transform`,`translate(${n.x} ${n.y})`),e.setAttribute(`class`,`vscada-group`),r.has(n.id)){let r=Yt(n,t);r.svg.style.cursor=`pointer`,r.svg.addEventListener(`click`,()=>this._toggleGroup(n.id)),e.appendChild(r.svg)}else e.appendChild(Xt(n,t));c.set(n.id,e),this._builtElements.push({elementId:n.id,svg:e})}let d=ur(n,this._renderer,{getNodeElement:e=>c.get(e),getEdgeElement:e=>c.get(e)}),f=Qe();if(f)for(let i of e.connections){let a=nn(i,e,r,n);if(!a)continue;let{svg:o,handles:s}=f.build(a,t,this._renderer);this._registerHandles(i.id,s),o.addEventListener(`pointerenter`,e=>{d.onPointerEnter(i.id,{pointerType:e.pointerType})}),o.addEventListener(`pointerleave`,()=>d.onPointerLeave()),c.set(i.id,o),this._builtElements.push({elementId:i.id,svg:o})}this._needsStructureInsert=!0}_registerFlowStateTracking(e){let t=e.bindings.find(e=>e.type===`state`);if(!t)return;let n=e.id,r=new mr(t.map,e.transitions??{},{duration:0,easing:`linear`},e=>{});this._scheduler.registerHandle(n,t.tag,{kind:`state`,write:(e,i)=>{let a=r.resolve(i,t.tag);a.state===`stopped`?this._flowStoppedSourceIds.add(n):this._flowStoppedSourceIds.delete(n),a.state===`closed`?this._flowClosedNodeIds.add(n):this._flowClosedNodeIds.delete(n),this._flowInferenceCache?.update(this._flowStoppedSourceIds,this._flowClosedNodeIds)}}),this._flowTrackedElementIds.push(n)}_toggleGroup(e){!this._scene||!this._groupViewState||this._interactive&&(this._groupViewState.toggleGroup(e),this.dispatchEvent(new CustomEvent(`element-click`,{detail:{elementId:e,elementType:`group`},bubbles:!0,composed:!0})),this._teardownBuiltElements(),this._buildElements(this._scene),this.requestUpdate())}_handleConditionTransition(e,t){let n=this._scene?.elements.find(t=>t.id===e)?.label??e;this._liveRegion.announceConditionTransition(n,t,this._scheduler.connectionState===`disconnected`)}_wrapHandlesForLiveRegion(e,t){let n=e.thresholds??[];if(n.length===0)return t;let r=e.label??e.id,i={};for(let[a,o]of Object.entries(t)){let t=o.kind===`numeric`?n.filter(e=>e.tag===a):[];if(o.kind!==`numeric`||t.length===0){i[a]=o;continue}let s=e.bindings.find(e=>e.tag===a)?.type??`value`,c=`normal`;i[a]={kind:`numeric`,write:(e,n,i)=>{let a=xo(n,t);a!==c&&(this._liveRegion.announceThresholdCrossing(r,s,a),c=a),o.write(e,n,i)}}}return i}_registerHandles(e,t){for(let[n,r]of Object.entries(t))r.kind===`animation`?this._animations.register(e,r,Do(n)):r.kind===`static-representation`?this._staticRepresentations.register(e,r):this._scheduler.registerHandle(e,n,r)}_teardownBuiltElements(){for(let e of this._builtElements)this._scheduler.unregisterElement(e.elementId),this._animations.unregisterElement(e.elementId),this._staticRepresentations.unregisterElement(e.elementId);for(let e of this._flowTrackedElementIds)this._scheduler.unregisterElement(e);this._builtElements=[],this._flowTrackedElementIds=[],this._builtDefs=null,this._watermark=null,this._hitLayerGroup=null,this._hitAreaEntries=[],this._viewportGroup=null}_maybeStartScheduler(){this._schedulerStarted||!this.isConnected||this._store.size===0||(this._scheduler.start(),this._schedulerStarted=!0)}_dispatchValueWarning(e){this.dispatchEvent(new CustomEvent(`value-warning`,{detail:e,bubbles:!0,composed:!0}))}_dispatchElementClick(e){this.dispatchEvent(new CustomEvent(`element-click`,{detail:e,bubbles:!0,composed:!0}))}_dispatchElementHover(e,t){let n={elementId:e,tags:t};this.dispatchEvent(new CustomEvent(`element-hover`,{detail:n,bubbles:!0,composed:!0}))}_dispatchRenderStats(e){this.dispatchEvent(new CustomEvent(`render-stats`,{detail:e,bubbles:!0,composed:!0}))}_onViewportFrame(e){this._applyViewportTransform(e);for(let t of this._hitAreaEntries)vr(t.rect,t.w,t.h,e.zoom,t.origin);let t=un(e.zoom,this._lodActive);this._lodActive=t,this._scheduler.lodActive=t,this._viewportGroup?.classList.toggle(`vscada-lod-active`,t)}_applyViewportTransform(e){this._viewportGroup&&this._renderer.setAttr(this._viewportGroup,`transform`,`translate(${e.panX} ${e.panY}) scale(${e.zoom})`)}_viewBoxScale(){if(!this._scene)return 1;let e=this.renderRoot.querySelector(`svg`);if(!e)return 1;let t=e.getBoundingClientRect();return t.width===0?1:this._scene.canvas.width/t.width}_toCanvasPoint(e,t){let n=this.renderRoot.querySelector(`svg`);if(!n||!this._scene)return{x:e,y:t};let r=n.getBoundingClientRect(),i=this._viewBoxScale();return{x:(e-r.left)*i,y:(t-r.top)*i}}_attachPanZoomListeners(e){e.addEventListener(`pointerdown`,e=>{let t=e;this._panZoomGestures.onPointerDown(t.pointerId,t.clientX,t.clientY)}),e.addEventListener(`pointermove`,e=>{let t=e;this._panZoomGestures.onPointerMove(t.pointerId,t.clientX,t.clientY)}),e.addEventListener(`pointerup`,e=>{this._panZoomGestures.onPointerUp(e.pointerId)}),e.addEventListener(`pointercancel`,e=>{this._panZoomGestures.onPointerCancel(e.pointerId)}),e.addEventListener(`wheel`,e=>{e.preventDefault();let t=e;this._panZoomGestures.onWheel(t.deltaY,t.clientX,t.clientY)},{passive:!1})}_syncVisibilityPause(){!this._isIntersecting||document.hidden?this._scheduler.pauseForOffscreen():this._scheduler.resumeFromOffscreen()}};Co=Oo,Co.styles=s`
3
+ :host {
4
+ display: block;
5
+ }
6
+ svg {
7
+ display: block;
8
+ width: 100%;
9
+ height: 100%;
10
+ touch-action: none;
11
+ }
12
+ /**
13
+ * Story 4.3 Task 2 — LOD's "text labels below legibility → hidden".
14
+ * One core-owned CSS toggle on the viewport group covers every
15
+ * primitive's text uniformly (labels, readouts, the quality overlay's
16
+ * age badge) — no per-primitive change needed.
17
+ */
18
+ .vscada-viewport.vscada-lod-active text {
19
+ display: none;
20
+ }
21
+ /* Story 4.4 Task 3 — §11 ARIA live region: present in the accessibility
22
+ tree (never display:none/visibility:hidden, which would strip it
23
+ from screen readers too) but invisible on screen. Standard
24
+ visually-hidden recipe. */
25
+ .vscada-live-region {
26
+ position: absolute;
27
+ width: 1px;
28
+ height: 1px;
29
+ overflow: hidden;
30
+ clip-path: inset(50%);
31
+ white-space: nowrap;
32
+ }
33
+ /* Story 4.4 Task 4 — §11 keyboard focus ring. Custom properties are
34
+ resolved from the theme's focusRing token at scene-build time
35
+ (_buildElements, on the host element) and inherit through the
36
+ shadow boundary by construction; the fallback values here are the
37
+ ONLY thing that ever renders if a theme declares no focusRing token
38
+ at all — a missing focus ring is an accessibility regression, unlike
39
+ a primitive's own graceful color degrade (AD-7), so this default is
40
+ deliberate, not a banned literal-color fallback. */
41
+ .vscada-hit-area:focus-visible {
42
+ outline: var(--vscada-focus-ring-width, 2px) solid var(--vscada-focus-ring-color, #2c7be5);
43
+ outline-offset: var(--vscada-focus-ring-offset, 2px);
44
+ }
45
+ `;function ko(e=`scada-view`){let t=customElements.get(e);t?t!==Oo&&console.warn(`defineScadaView: "${e}" is already registered to a different class — ScadaView will not be used for this tag.`):customElements.define(e,Oo)}var Ao=24*.8,jo=1e-6,Mo=1e-9;function No(e){let t=new Map;for(let n=0;n<e.length;n++){let r=e[n];if(r)for(let i=n+1;i<e.length;i++){let n=e[i];if(n)for(let e of r.segments)for(let r=0;r<n.segments.length;r++){let a=Po(e,n.segments[r]);if(!a)continue;let o=t.get(i)??[];o.push({point:a.point,segmentIndex:r,t:a.u}),t.set(i,o)}}}return t}function Po(e,t){let n=e.to.x-e.from.x,r=e.to.y-e.from.y,i=t.to.x-t.from.x,a=t.to.y-t.from.y,o=n*a-r*i,s=n*n+r*r+i*i+a*a||1;if(Math.abs(o)<Mo*s)return null;let c=t.from.x-e.from.x,l=t.from.y-e.from.y,u=(c*a-l*i)/o,d=(c*r-l*n)/o;return u<=jo||u>=1-jo||d<=jo||d>=1-jo?null:{point:{x:e.from.x+u*n,y:e.from.y+u*r},t:u,u:d}}function Fo(e,t,n=Ao){if(t.length===0)return e;let r=new Map;for(let e of t){let t=r.get(e.segmentIndex)??[];t.push(e),r.set(e.segmentIndex,t)}let i=[...r.keys()].sort((e,t)=>t-e),a=e.segments,o=e.corners;for(let e of i){let t=[...r.get(e)].sort((e,t)=>e.t-t.t),i=Io(a,o,e,t,n);i&&(a=i.segments,o=i.corners)}return{...e,segments:a,corners:o}}function Io(e,t,n,r,i){let a=e[n];if(!a)return null;let o=a.to.x-a.from.x,s=a.to.y-a.from.y,c=Math.hypot(o,s);if(c<1e-9)return null;let l=o/c,u=s/c,d=r.map(e=>Math.hypot(e.point.x-a.from.x,e.point.y-a.from.y)),f=d.map((e,t)=>{let n=t===0?e:e-d[t-1],r=t===d.length-1?c-e:d[t+1]-e;return Math.min(i,n/2,r/2)}),p=[],m=[],h=a.from,g=!1;for(let e=0;e<r.length;e++){let t=f[e];if(t<=1e-6)continue;let n=r[e].point,i={x:n.x-l*t,y:n.y-u*t},a={x:n.x+l*t,y:n.y+u*t};p.push({from:h,to:i}),m.push({from:i,to:a,radius:t,sweepFlag:0}),h=a,g=!0}return g?(p.push({from:h,to:a.to}),{segments:[...e.slice(0,n),...p,...e.slice(n+1)],corners:Lo(t,n,m)}):null}function Lo(e,t,n){if(n.length===0)return e.slice();if(e.length===0){let e=[];for(let r=0;r<n.length;r++)e[t+r]=n[r];return e}return[...e.slice(0,t),...n,...e.slice(t)]}function Ro(e){let t=e.connections.map(t=>({connection:t,route:Dt(t,e)})),n=No(t.map(e=>e.route));return n.size===0?t:t.map(({connection:e,route:t},r)=>{if(!t)return{connection:e,route:t};let i=n.get(r);return!i||i.length===0?{connection:e,route:t}:{connection:e,route:Fo(t,i)}})}function zo(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Bo(e){let t=e.replace(`#`,``),n=t.length===3?t.split(``).map(e=>e+e).join(``):t;return{r:parseInt(n.slice(0,2),16),g:parseInt(n.slice(2,4),16),b:parseInt(n.slice(4,6),16)}}function Vo(e){let{r:t,g:n,b:r}=Bo(e);return .2126*zo(t)+.7152*zo(n)+.0722*zo(r)}function Ho(e,t){let n=Vo(e),r=Vo(t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function $(e){return{toCanonical:t=>t*e,fromCanonical:t=>t/e}}var Uo={Pa:{family:`pressure`,...$(1)},kPa:{family:`pressure`,...$(1e3)},bar:{family:`pressure`,...$(1e5)},psi:{family:`pressure`,...$(6894.757293168361)},K:{family:`temperature`,toCanonical:e=>e,fromCanonical:e=>e},degC:{family:`temperature`,toCanonical:e=>e+273.15,fromCanonical:e=>e-273.15},degF:{family:`temperature`,toCanonical:e=>(e-32)*5/9+273.15,fromCanonical:e=>(e-273.15)*9/5+32},m3s:{family:`flow`,...$(1)},m3h:{family:`flow`,...$(1/3600)},lpm:{family:`flow`,...$(1/6e4)},gpm:{family:`flow`,...$(.003785411784/60)},m:{family:`level`,...$(1)},mm:{family:`level`,...$(.001)},W:{family:`power`,...$(1)},kW:{family:`power`,...$(1e3)},MW:{family:`power`,...$(1e6)},kg:{family:`mass`,...$(1)},t:{family:`mass`,...$(1e3)},lb:{family:`mass`,...$(.45359237)}};function Wo(e){return Uo[e]?.family}function Go(e,t,n){if(t===n)return e;let r=Uo[t],i=Uo[n];if(!(!r||!i||r.family!==i.family))return i.fromCanonical(r.toCanonical(e))}function Ko(e,t){if(typeof e!=`number`||!Number.isFinite(e))return String(e);let n=t.displayUnit??t.unit,r=Go(e,t.unit,n),i=r??e,a=r===void 0?t.unit:n,o=i.toFixed(t.decimals);return a.length>0?`${o} ${a}`:o}e.DAMPED_OVERSHOOT_OMEGA=Er,e.DAMPED_OVERSHOOT_ZETA=Tr,e.DEFAULT_NEEDLE_SCALE=Mn,e.FlowInferenceCache=or,e.Fsm=mr,e.GroupViewStateController=dr,e.JUMP_ARC_RADIUS=Ao,e.LANE_WIDTH=ft,e.MAX_BINDING_PLAYBACK_RATE=An,e.PIPE_WIDTH_REFERENCE=dt,e.SCENE_ERROR_CODES=Le,e.SUPPORTED_SCENE_VERSIONS=Re,e.ScadaView=Oo,e.Tween=Ar,e.UNKNOWN_STATE=pr,e.VERSION=`0.0.0`,e.applyLaneOffset=pt,e.buildBoundaryReferenceIndex=Qt,e.buildCollapsedGraphView=Ht,e.buildGroupExpandedFrame=Xt,e.buildGroupSummaryBlock=Yt,e.buildPresentationScene=tn,e.buildTopologyGraph=Qn,e.computeFlowInference=ir,e.computeUpstreamHighlight=sr,e.contrastRatio=Ho,e.convertUnit=Go,e.createGroupViewState=fr,e.createUpstreamHoverController=ur,e.defaultTimeSource=nt,e.defineScadaView=ko,e.detectCrossings=No,e.domRenderer=rt,e.downstreamOf=tr,e.formatDisplayValue=Ko,e.getLicenseVerdict=no,e.isFinePointerHover=cr,e.onLicenseVerdict=ro,e.presentationNodeId=Vt,e.rangeFraction=Dn,e.reachableSet=$n,e.registerConnectionRenderer=Ze,e.registerPrimitives=Ke,e.registerSvgSources=Gn,e.registerThemes=et,e.relativeLuminance=Vo,e.resolveAlarmBand=xo,e.resolveAlarmColor=So,e.resolveBlinkRate=jn,e.resolveColorRampColor=Un,e.resolveEffectiveMedium=Et,e.resolveEffectiveMediumStyle=Tt,e.resolveEmissionIntensity=kn,e.resolveGroupAwareConnectionGeometry=nn,e.resolveLevelFraction=On,e.resolveMediumStyle=bt,e.resolveNeedleAngle=Nn,e.resolveSceneRoutes=Ro,e.resolveVisualState=sn,e.rollUpGroupCondition=Jt,e.routeToPathData=Rt,e.segmentAngle=zt,e.setLicenseKey=to,e.spliceJumpOvers=Fo,e.unitFamily=Wo,e.upstreamOf=er,e.validateSceneStructure=Ue});
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@vscada/core",
3
+ "version": "0.0.1",
4
+ "description": "VScada core: <scada-view> element, pipeline, contracts, and token schema",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "license": "UNLICENSED",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./scene-authoring": {
17
+ "types": "./dist/scene-authoring.d.ts",
18
+ "import": "./dist/scene-authoring.js"
19
+ }
20
+ },
21
+ "customElements": "dist/custom-elements.json",
22
+ "dependencies": {
23
+ "@noble/curves": "^2.2.0",
24
+ "lit": "~3.3.3",
25
+ "zod": "^4.4.3"
26
+ },
27
+ "devDependencies": {
28
+ "@custom-elements-manifest/analyzer": "~0.11.0",
29
+ "typescript": "~5.9.3",
30
+ "vite": "~8.1.5"
31
+ },
32
+ "scripts": {
33
+ "build": "vite build && vite build -c vite.config.umd.ts && tsc -b && pnpm run gen:cem",
34
+ "typecheck": "tsc -b",
35
+ "gen:cem": "custom-elements-manifest analyze --config custom-elements-manifest.config.mjs --outdir dist"
36
+ }
37
+ }