From 8229813ebafa78e1b89ff7a5a8ed4f7cfface78d Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 30 Jun 2025 12:58:32 +0100 Subject: [PATCH] improve vivas --- atlas/models.py | 2 +- atlas/templates/atlas/collection_detail.html | 6 +- atlas/templates/atlas/collection_viva.html | 127 ++++++++++--------- atlas/templates/atlas/viewer_local.html | 79 +++++++----- atlas/views.py | 28 ++-- rad/static/dv3d/index.js | 16 +-- 6 files changed, 142 insertions(+), 116 deletions(-) diff --git a/atlas/models.py b/atlas/models.py index 92396020..5c17bd4e 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -1147,7 +1147,7 @@ class CaseDetail(models.Model): return None def default_viewerstate_string(self): - return json.dumps(self.default_viewerstate) if self.default_viewerstate else "" + return json.dumps(self.default_viewerstate) if self.default_viewerstate else "{}" class CasePrior(models.Model): case_detail = models.ForeignKey(CaseDetail, on_delete=models.CASCADE) diff --git a/atlas/templates/atlas/collection_detail.html b/atlas/templates/atlas/collection_detail.html index 8397be3d..dc9726d8 100644 --- a/atlas/templates/atlas/collection_detail.html +++ b/atlas/templates/atlas/collection_detail.html @@ -18,7 +18,11 @@
  • Case {{forloop.counter}} : {{casedetail.case.title}} - (setup default display) + (setup default display + {% if casedetail.default_viewerstate %} + + {% endif %} + ) {% if collection.collection_type == "QUE" %} (edit questions diff --git a/atlas/templates/atlas/collection_viva.html b/atlas/templates/atlas/collection_viva.html index 27fd59a8..26059e5e 100644 --- a/atlas/templates/atlas/collection_viva.html +++ b/atlas/templates/atlas/collection_viva.html @@ -10,9 +10,9 @@

    It is also possible to open a single series by clicking on the 'Load' button next to the individual series.

    Once opened the case details will be show on the right hand side of the page.

    -
    - -
    +
    + +
    @@ -22,48 +22,49 @@
      - {% for case in cases %} + {% for casedetail in casedetails %} + {% with case=casedetail.case %} -
    1. - {{case.casedetail.sort_order}} -
      Case {{forloop.counter}}: {{case.title}}   +
    2. +
      Case {{forloop.counter}}: {{case.title}}   {% comment %} {% endcomment %} {% comment %} {% endcomment %} {% comment %} {% endcomment %} - - -
      -
      -
      Series: - {% for series in case.series.all %} - - - Series {{ forloop.counter }}:
      - {{series.get_block}} -
      + + +
      +
      +
      Series: + {% for series in case.series.all %} + + + Series {{ forloop.counter }}:
      + {{series.get_block}} +
      {% comment %} {% endcomment %} {% comment %} - -
      + + +
      +
      - - {% endfor %} -
      + {% endfor %} +
      +
      -
    -
  • + + {% endwith %} {% endfor %} @@ -92,37 +93,37 @@ var win2 = false; $(document).ready(function() { - let loadLocalMode = true; + let loadLocalMode = true; // Update all "Load" buttons to reflect the current mode - function updateLoadButtons() { - if (loadLocalMode) { - $('.open-case').hide(); - $('.open-series').hide(); - $('.open-case-local').show(); - $('.open-series-local').show(); - $('#toggle-load-mode').text('Switch to Load OHIF'); - $("#open-viewer").hide() - $("#open-viewer-local").show() - } else { - $('.open-case').show(); - $('.open-series').show(); - $('.open-case-local').hide(); - $('.open-series-local').hide(); - $("#open-viewer").show() - $("#open-viewer-local").hide() - $('#toggle-load-mode').text('Switch to Load Local'); - } - } + function updateLoadButtons() { + if (loadLocalMode) { + $('.open-case').hide(); + $('.open-series').hide(); + $('.open-case-local').show(); + $('.open-series-local').show(); + $('#toggle-load-mode').text('Switch to Load OHIF'); + $("#open-viewer").hide() + $("#open-viewer-local").show() + } else { + $('.open-case').show(); + $('.open-series').show(); + $('.open-case-local').hide(); + $('.open-series-local').hide(); + $("#open-viewer").show() + $("#open-viewer-local").hide() + $('#toggle-load-mode').text('Switch to Load Local'); + } + } // Initial state: show only normal Load buttons - updateLoadButtons(); + updateLoadButtons(); // Toggle button click handler - $('#toggle-load-mode').click(function() { - loadLocalMode = !loadLocalMode; - updateLoadButtons(); - }); + $('#toggle-load-mode').click(function() { + loadLocalMode = !loadLocalMode; + updateLoadButtons(); + }); const bc = new BroadcastChannel("viva_load"); bc.onmessage = (event) => { @@ -152,6 +153,7 @@ console.log('clicked local', c) console.log('open local', c.dataset.case) case_details = JSON.parse(c.dataset.casejson); + let viewerstate = JSON.parse(c.dataset.viewerstate) || {}; $('#loading-case').show() $("#open-viewer-local").addClass("flash-button"); $('#current-case-title').html("Case: "+c.dataset.title); @@ -159,7 +161,10 @@ $("#current-case-discussion").html("Discussion: "+case_details['discussion']); $("#current-case-report").html("Report: "+case_details['report']); - bc.postMessage({"type": "open", "case" : c.dataset.case, "images": c.dataset.images}); + bc.postMessage({"type": "open", + "case" : c.dataset.case, "images": c.dataset.images, + "viewerstate": viewerstate + }); }); $('.open-series-local').click(function() { @@ -181,7 +186,7 @@ "type": "open", "case": c.dataset.case, "series": seriesPk, - "images": JSON.stringify(images) + "images": JSON.stringify(images), }); }); $('.open-case, .open-series').click(function() { diff --git a/atlas/templates/atlas/viewer_local.html b/atlas/templates/atlas/viewer_local.html index dd661c8d..a632cb87 100644 --- a/atlas/templates/atlas/viewer_local.html +++ b/atlas/templates/atlas/viewer_local.html @@ -1,9 +1,9 @@ - + {% load static %} - - Viewer + + Viewer - + - -
    -

    Awating load request

    - This page will display series when loaded from other pages. -
    -
    + +
    +

    Awating load request

    + This page will display series when loaded from other pages. +
    +
    - + console.log("viewerstate: ", event.data.viewerstate); + console.log(event.data.viewerstate == {}); + if ( + event.data.viewerstate && + Object.keys(event.data.viewerstate).length > 0 + ) { + document.getElementById("root").dataset.viewerstate = event.data.viewerstate; + } else { + delete document.getElementById("root").dataset.viewerstate; + } - + window.mountDicomViewers(); + bc.postMessage({"type": "open-complete-local"}); + } + }; + }); + + + diff --git a/atlas/views.py b/atlas/views.py index a7c36c69..326915c6 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -1611,22 +1611,28 @@ class CollectionView(LoginRequiredMixin, SingleTableMixin, FilterView): def collection_viva(request, pk): collection = get_object_or_404(CaseCollection, pk=pk) - cases = ( - collection.cases.all() - .order_by("casedetail__sort_order") - .prefetch_related( - "series", - "series__images", - "series__contrast", - "series__plane", - "series__examination", - ) + #cases = ( + # collection.cases.all() + # .order_by("casedetail__sort_order") + # .prefetch_related( + # "series", + # "series__images", + # "series__contrast", + # "series__plane", + # "series__examination", + # ) + #) + + casedetails = CaseDetail.objects.filter(collection=collection).order_by( + "sort_order" ) + logger.debug(casedetails) + return render( request, "atlas/collection_viva.html", - {"collection": collection, "cases": cases, "can_edit": True}, + {"collection": collection, "casedetails": casedetails, "can_edit": True}, ) diff --git a/rad/static/dv3d/index.js b/rad/static/dv3d/index.js index 89f7bf66..4e848e46 100644 --- a/rad/static/dv3d/index.js +++ b/rad/static/dv3d/index.js @@ -6,7 +6,7 @@ var hG=Object.defineProperty;var gG=(t,e,r)=>e in t?hG(t,e,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Qp=Symbol.for("react.element"),mG=Symbol.for("react.portal"),vG=Symbol.for("react.fragment"),yG=Symbol.for("react.strict_mode"),wG=Symbol.for("react.profiler"),xG=Symbol.for("react.provider"),CG=Symbol.for("react.context"),SG=Symbol.for("react.forward_ref"),_G=Symbol.for("react.suspense"),TG=Symbol.for("react.memo"),EG=Symbol.for("react.lazy"),FE=Symbol.iterator;function DG(t){return t===null||typeof t!="object"?null:(t=FE&&t[FE]||t["@@iterator"],typeof t=="function"?t:null)}var $b={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},jb=Object.assign,Hb={};function Q0(t,e,r){this.props=t,this.context=e,this.refs=Hb,this.updater=r||$b}Q0.prototype.isReactComponent={};Q0.prototype.setState=function(t,e){if(typeof t!="object"&&typeof t!="function"&&t!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")};Q0.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function Kb(){}Kb.prototype=Q0.prototype;function cS(t,e,r){this.props=t,this.context=e,this.refs=Hb,this.updater=r||$b}var lS=cS.prototype=new Kb;lS.constructor=cS;jb(lS,Q0.prototype);lS.isPureReactComponent=!0;var UE=Array.isArray,qb=Object.prototype.hasOwnProperty,uS={current:null},Xb={key:!0,ref:!0,__self:!0,__source:!0};function Yb(t,e,r){var n,i={},o=null,a=null;if(e!=null)for(n in e.ref!==void 0&&(a=e.ref),e.key!==void 0&&(o=""+e.key),e)qb.call(e,n)&&!Xb.hasOwnProperty(n)&&(i[n]=e[n]);var s=arguments.length-2;if(s===1)i.children=r;else if(1e in t?hG(t,e,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var PG=At,RG=Symbol.for("react.element"),LG=Symbol.for("react.fragment"),AG=Object.prototype.hasOwnProperty,NG=PG.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,kG={key:!0,ref:!0,__self:!0,__source:!0};function Zb(t,e,r){var n,i={},o=null,a=null;r!==void 0&&(o=""+r),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(a=e.ref);for(n in e)AG.call(e,n)&&!kG.hasOwnProperty(n)&&(i[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)i[n]===void 0&&(i[n]=e[n]);return{$$typeof:RG,type:t,key:o,ref:a,props:i,_owner:NG.current}}_y.Fragment=LG;_y.jsx=Zb;_y.jsxs=Zb;Wb.exports=_y;var lt=Wb.exports,Qb={exports:{}},Sa={},eI={exports:{}},tI={};/** + */var PG=Nt,RG=Symbol.for("react.element"),LG=Symbol.for("react.fragment"),AG=Object.prototype.hasOwnProperty,NG=PG.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,kG={key:!0,ref:!0,__self:!0,__source:!0};function Zb(t,e,r){var n,i={},o=null,a=null;r!==void 0&&(o=""+r),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(a=e.ref);for(n in e)AG.call(e,n)&&!kG.hasOwnProperty(n)&&(i[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)i[n]===void 0&&(i[n]=e[n]);return{$$typeof:RG,type:t,key:o,ref:a,props:i,_owner:NG.current}}_y.Fragment=LG;_y.jsx=Zb;_y.jsxs=Zb;Wb.exports=_y;var lt=Wb.exports,Qb={exports:{}},Sa={},eI={exports:{}},tI={};/** * @license React * scheduler.production.min.js * @@ -30,7 +30,7 @@ var hG=Object.defineProperty;var gG=(t,e,r)=>e in t?hG(t,e,{enumerable:!0,config * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var FG=At,ya=VG;function yt(t){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+t,r=1;r"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),R3=Object.prototype.hasOwnProperty,UG=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,GE={},WE={};function BG(t){return R3.call(WE,t)?!0:R3.call(GE,t)?!1:UG.test(t)?WE[t]=!0:(GE[t]=!0,!1)}function GG(t,e,r,n){if(r!==null&&r.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return n?!1:r!==null?!r.acceptsBooleans:(t=t.toLowerCase().slice(0,5),t!=="data-"&&t!=="aria-");default:return!1}}function WG(t,e,r,n){if(e===null||typeof e>"u"||GG(t,e,r,n))return!0;if(n)return!1;if(r!==null)switch(r.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function Vo(t,e,r,n,i,o,a){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=n,this.attributeNamespace=i,this.mustUseProperty=r,this.propertyName=t,this.type=e,this.sanitizeURL=o,this.removeEmptyString=a}var ro={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){ro[t]=new Vo(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];ro[e]=new Vo(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){ro[t]=new Vo(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){ro[t]=new Vo(t,2,!1,t,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(t){ro[t]=new Vo(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){ro[t]=new Vo(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){ro[t]=new Vo(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){ro[t]=new Vo(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){ro[t]=new Vo(t,5,!1,t.toLowerCase(),null,!1,!1)});var dS=/[\-:]([a-z])/g;function hS(t){return t[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(t){var e=t.replace(dS,hS);ro[e]=new Vo(e,1,!1,t,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(t){var e=t.replace(dS,hS);ro[e]=new Vo(e,1,!1,t,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(t){var e=t.replace(dS,hS);ro[e]=new Vo(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){ro[t]=new Vo(t,1,!1,t.toLowerCase(),null,!1,!1)});ro.xlinkHref=new Vo("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){ro[t]=new Vo(t,1,!1,t.toLowerCase(),null,!0,!0)});function gS(t,e,r,n){var i=ro.hasOwnProperty(e)?ro[e]:null;(i!==null?i.type!==0:n||!(2"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),R3=Object.prototype.hasOwnProperty,UG=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,GE={},WE={};function BG(t){return R3.call(WE,t)?!0:R3.call(GE,t)?!1:UG.test(t)?WE[t]=!0:(GE[t]=!0,!1)}function GG(t,e,r,n){if(r!==null&&r.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return n?!1:r!==null?!r.acceptsBooleans:(t=t.toLowerCase().slice(0,5),t!=="data-"&&t!=="aria-");default:return!1}}function WG(t,e,r,n){if(e===null||typeof e>"u"||GG(t,e,r,n))return!0;if(n)return!1;if(r!==null)switch(r.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function Vo(t,e,r,n,i,o,a){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=n,this.attributeNamespace=i,this.mustUseProperty=r,this.propertyName=t,this.type=e,this.sanitizeURL=o,this.removeEmptyString=a}var ro={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){ro[t]=new Vo(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];ro[e]=new Vo(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){ro[t]=new Vo(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){ro[t]=new Vo(t,2,!1,t,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(t){ro[t]=new Vo(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){ro[t]=new Vo(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){ro[t]=new Vo(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){ro[t]=new Vo(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){ro[t]=new Vo(t,5,!1,t.toLowerCase(),null,!1,!1)});var dS=/[\-:]([a-z])/g;function hS(t){return t[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(t){var e=t.replace(dS,hS);ro[e]=new Vo(e,1,!1,t,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(t){var e=t.replace(dS,hS);ro[e]=new Vo(e,1,!1,t,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(t){var e=t.replace(dS,hS);ro[e]=new Vo(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){ro[t]=new Vo(t,1,!1,t.toLowerCase(),null,!1,!1)});ro.xlinkHref=new Vo("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){ro[t]=new Vo(t,1,!1,t.toLowerCase(),null,!0,!0)});function gS(t,e,r,n){var i=ro.hasOwnProperty(e)?ro[e]:null;(i!==null?i.type!==0:n||!(2s||i[a]!==o[s]){var c=` @@ -3766,7 +3766,7 @@ fn main( "use strict"; return body.apply(this, arguments); }; `)(U)}function bn(R,U){var q=fn(U,function(le){this.name=U,this.message=le;var he=new Error(le).stack;he!==void 0&&(this.stack=this.toString()+` -`+he.replace(/^Error(:[^\n]*)?\n/,""))});return q.prototype=Object.create(R.prototype),q.prototype.constructor=q,q.prototype.toString=function(){return this.message===void 0?this.name:this.name+": "+this.message},q}var Xi=void 0;function Mr(R){throw new Xi(R)}function Be(R,U,q){R.forEach(function(be){Ft[be]=U});function le(be){var ke=q(be);ke.length!==R.length&&Mr("Mismatched type converter count");for(var Je=0;Je{xt.hasOwnProperty(be)?he[ke]=xt[be]:(ve.push(be),Lt.hasOwnProperty(be)||(Lt[be]=[]),Lt[be].push(()=>{he[ke]=xt[be],++Te,Te===ve.length&&le(he)}))}),ve.length===0&&le(he)}function ft(R){var U=tt[R];delete tt[R];var q=U.rawConstructor,le=U.rawDestructor,he=U.fields,ve=he.map(Te=>Te.getterReturnType).concat(he.map(Te=>Te.setterArgumentType));Be([R],ve,Te=>{var be={};return he.forEach((ke,Je)=>{var pt=ke.fieldName,Mt=Te[Je],Tt=ke.getter,dn=ke.getterContext,ln=Te[Je+he.length],Xn=ke.setter,li=ke.setterContext;be[pt]={read:yi=>Mt.fromWireType(Tt(dn,yi)),write:(yi,rf)=>{var Oa=[];Xn(li,yi,ln.toWireType(Oa,rf)),nt(Oa)}}}),[{name:U.name,fromWireType:function(ke){var Je={};for(var pt in be)Je[pt]=be[pt].read(ke);return le(ke),Je},toWireType:function(ke,Je){for(var pt in be)if(!(pt in Je))throw new TypeError('Missing field: "'+pt+'"');var Mt=q();for(pt in be)be[pt].write(Mt,Je[pt]);return ke!==null&&ke.push(le,Mt),Mt},argPackAdvance:8,readValueFromPointer:dt,destructorFunction:le}]})}function Ut(R,U,q,le,he){}function Sn(R){switch(R){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+R)}}function Qn(){for(var R=new Array(256),U=0;U<256;++U)R[U]=String.fromCharCode(U);Pt=R}var Pt=void 0;function _n(R){for(var U="",q=R;k[q];)U+=Pt[k[q++]];return U}var sn=void 0;function rn(R){throw new sn(R)}function pi(R,U,q={}){if(!("argPackAdvance"in U))throw new TypeError("registerType registeredInstance requires argPackAdvance");var le=U.name;if(R||rn('type "'+le+'" must have a positive integer typeid pointer'),xt.hasOwnProperty(R)){if(q.ignoreDuplicateRegistrations)return;rn("Cannot register type '"+le+"' twice")}if(xt[R]=U,delete Ft[R],Lt.hasOwnProperty(R)){var he=Lt[R];delete Lt[R],he.forEach(ve=>ve())}}function Vi(R,U,q,le,he){var ve=Sn(q);U=_n(U),pi(R,{name:U,fromWireType:function(Te){return!!Te},toWireType:function(Te,be){return be?le:he},argPackAdvance:8,readValueFromPointer:function(Te){var be;if(q===1)be=A;else if(q===2)be=F;else if(q===4)be=Y;else throw new TypeError("Unknown boolean type size: "+U);return this.fromWireType(be[Te>>ve])},destructorFunction:null})}function Ha(R){if(!(this instanceof ut)||!(R instanceof ut))return!1;for(var U=this.$$.ptrType.registeredClass,q=this.$$.ptr,le=R.$$.ptrType.registeredClass,he=R.$$.ptr;U.baseClass;)q=U.upcast(q),U=U.baseClass;for(;le.baseClass;)he=le.upcast(he),le=le.baseClass;return U===le&&q===he}function Ea(R){return{count:R.count,deleteScheduled:R.deleteScheduled,preservePointerOnDelete:R.preservePointerOnDelete,ptr:R.ptr,ptrType:R.ptrType,smartPtr:R.smartPtr,smartPtrType:R.smartPtrType}}function To(R){function U(q){return q.$$.ptrType.registeredClass.name}rn(U(R)+" instance already deleted")}var ra=!1;function Uo(R){}function fr(R){R.smartPtr?R.smartPtrType.rawDestructor(R.smartPtr):R.ptrType.registeredClass.rawDestructor(R.ptr)}function oo(R){R.count.value-=1;var U=R.count.value===0;U&&fr(R)}function yn(R,U,q){if(U===q)return R;if(q.baseClass===void 0)return null;var le=yn(R,U,q.baseClass);return le===null?null:q.downcast(le)}var Qr={};function Da(){return Object.keys(Bi).length}function Fi(){var R=[];for(var U in Bi)Bi.hasOwnProperty(U)&&R.push(Bi[U]);return R}var ao=[];function Ui(){for(;ao.length;){var R=ao.pop();R.$$.deleteScheduled=!1,R.delete()}}var mi=void 0;function Ka(R){mi=R,ao.length&&mi&&mi(Ui)}function Bo(){o.getInheritedInstanceCount=Da,o.getLiveInheritedInstances=Fi,o.flushPendingDeletes=Ui,o.setDelayFunction=Ka}var Bi={};function qa(R,U){for(U===void 0&&rn("ptr should not be undefined");R.baseClass;)U=R.upcast(U),R=R.baseClass;return U}function Gi(R,U){return U=qa(R,U),Bi[U]}function ia(R,U){(!U.ptrType||!U.ptr)&&Mr("makeClassHandle requires ptr and ptrType");var q=!!U.smartPtrType,le=!!U.smartPtr;return q!==le&&Mr("Both smartPtrType and smartPtr must be specified"),U.count={value:1},Ue(Object.create(R,{$$:{value:U}}))}function de(R){var U=this.getPointee(R);if(!U)return this.destructor(R),null;var q=Gi(this.registeredClass,U);if(q!==void 0){if(q.$$.count.value===0)return q.$$.ptr=U,q.$$.smartPtr=R,q.clone();var le=q.clone();return this.destructor(R),le}function he(){return this.isSmartPointer?ia(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:U,smartPtrType:this,smartPtr:R}):ia(this.registeredClass.instancePrototype,{ptrType:this,ptr:R})}var ve=this.registeredClass.getActualType(U),Te=Qr[ve];if(!Te)return he.call(this);var be;this.isConst?be=Te.constPointerType:be=Te.pointerType;var ke=yn(U,this.registeredClass,be.registeredClass);return ke===null?he.call(this):this.isSmartPointer?ia(be.registeredClass.instancePrototype,{ptrType:be,ptr:ke,smartPtrType:this,smartPtr:R}):ia(be.registeredClass.instancePrototype,{ptrType:be,ptr:ke})}function Ue(R){return typeof FinalizationRegistry>"u"?(Ue=U=>U,R):(ra=new FinalizationRegistry(U=>{oo(U.$$)}),Ue=U=>{var q=U.$$,le=!!q.smartPtr;if(le){var he={$$:q};ra.register(U,he,U)}return U},Uo=U=>ra.unregister(U),Ue(R))}function _e(){if(this.$$.ptr||To(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var R=Ue(Object.create(Object.getPrototypeOf(this),{$$:{value:Ea(this.$$)}}));return R.$$.count.value+=1,R.$$.deleteScheduled=!1,R}function ye(){this.$$.ptr||To(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&rn("Object already scheduled for deletion"),Uo(this),oo(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function je(){return!this.$$.ptr}function ot(){return this.$$.ptr||To(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&rn("Object already scheduled for deletion"),ao.push(this),ao.length===1&&mi&&mi(Ui),this.$$.deleteScheduled=!0,this}function st(){ut.prototype.isAliasOf=Ha,ut.prototype.clone=_e,ut.prototype.delete=ye,ut.prototype.isDeleted=je,ut.prototype.deleteLater=ot}function ut(){}function rt(R,U,q){if(R[U].overloadTable===void 0){var le=R[U];R[U]=function(){return R[U].overloadTable.hasOwnProperty(arguments.length)||rn("Function '"+q+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+R[U].overloadTable+")!"),R[U].overloadTable[arguments.length].apply(this,arguments)},R[U].overloadTable=[],R[U].overloadTable[le.argCount]=le}}function Ct(R,U,q){o.hasOwnProperty(R)?(rn("Cannot register public name '"+R+"' twice"),rt(o,R,R),o.hasOwnProperty(q)&&rn("Cannot register multiple overloads of a function with the same number of arguments ("+q+")!"),o[R].overloadTable[q]=U):o[R]=U}function Qt(R,U,q,le,he,ve,Te,be){this.name=R,this.constructor=U,this.instancePrototype=q,this.rawDestructor=le,this.baseClass=he,this.getActualType=ve,this.upcast=Te,this.downcast=be,this.pureVirtualFunctions=[]}function on(R,U,q){for(;U!==q;)U.upcast||rn("Expected null or instance of "+q.name+", got an instance of "+U.name),R=U.upcast(R),U=U.baseClass;return R}function cn(R,U){if(U===null)return this.isReference&&rn("null is not a valid "+this.name),0;U.$$||rn('Cannot pass "'+Ja(U)+'" as a '+this.name),U.$$.ptr||rn("Cannot pass deleted object as a pointer of type "+this.name);var q=U.$$.ptrType.registeredClass,le=on(U.$$.ptr,q,this.registeredClass);return le}function Gt(R,U){var q;if(U===null)return this.isReference&&rn("null is not a valid "+this.name),this.isSmartPointer?(q=this.rawConstructor(),R!==null&&R.push(this.rawDestructor,q),q):0;U.$$||rn('Cannot pass "'+Ja(U)+'" as a '+this.name),U.$$.ptr||rn("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&U.$$.ptrType.isConst&&rn("Cannot convert argument of type "+(U.$$.smartPtrType?U.$$.smartPtrType.name:U.$$.ptrType.name)+" to parameter type "+this.name);var le=U.$$.ptrType.registeredClass;if(q=on(U.$$.ptr,le,this.registeredClass),this.isSmartPointer)switch(U.$$.smartPtr===void 0&&rn("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:U.$$.smartPtrType===this?q=U.$$.smartPtr:rn("Cannot convert argument of type "+(U.$$.smartPtrType?U.$$.smartPtrType.name:U.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:q=U.$$.smartPtr;break;case 2:if(U.$$.smartPtrType===this)q=U.$$.smartPtr;else{var he=U.clone();q=this.rawShare(q,Go.toHandle(function(){he.delete()})),R!==null&&R.push(this.rawDestructor,q)}break;default:rn("Unsupporting sharing policy")}return q}function xn(R,U){if(U===null)return this.isReference&&rn("null is not a valid "+this.name),0;U.$$||rn('Cannot pass "'+Ja(U)+'" as a '+this.name),U.$$.ptr||rn("Cannot pass deleted object as a pointer of type "+this.name),U.$$.ptrType.isConst&&rn("Cannot convert argument of type "+U.$$.ptrType.name+" to parameter type "+this.name);var q=U.$$.ptrType.registeredClass,le=on(U.$$.ptr,q,this.registeredClass);return le}function er(R){return this.rawGetPointee&&(R=this.rawGetPointee(R)),R}function nr(R){this.rawDestructor&&this.rawDestructor(R)}function or(R){R!==null&&R.delete()}function qn(){Nt.prototype.getPointee=er,Nt.prototype.destructor=nr,Nt.prototype.argPackAdvance=8,Nt.prototype.readValueFromPointer=dt,Nt.prototype.deleteObject=or,Nt.prototype.fromWireType=de}function Nt(R,U,q,le,he,ve,Te,be,ke,Je,pt){this.name=R,this.registeredClass=U,this.isReference=q,this.isConst=le,this.isSmartPointer=he,this.pointeeType=ve,this.sharingPolicy=Te,this.rawGetPointee=be,this.rawConstructor=ke,this.rawShare=Je,this.rawDestructor=pt,!he&&U.baseClass===void 0?le?(this.toWireType=cn,this.destructorFunction=null):(this.toWireType=xn,this.destructorFunction=null):this.toWireType=Gt}function Bn(R,U,q){o.hasOwnProperty(R)||Mr("Replacing nonexistant public symbol"),o[R].overloadTable!==void 0&&q!==void 0||(o[R]=U,o[R].argCount=q)}function dr(R,U,q){var le=o["dynCall_"+R];return q&&q.length?le.apply(null,[U].concat(q)):le.call(null,U)}var si=[];function jn(R){var U=si[R];return U||(R>=si.length&&(si.length=R+1),si[R]=U=Ee.get(R)),U}function wr(R,U,q){if(R.includes("j"))return dr(R,U,q);var le=jn(U).apply(null,q);return le}function ei(R,U){var q=[];return function(){return q.length=0,Object.assign(q,arguments),wr(R,U,q)}}function xr(R,U){R=_n(R);function q(){return R.includes("j")?ei(R,U):jn(U)}var le=q();return typeof le!="function"&&rn("unknown function pointer with signature "+R+": "+U),le}var uc=void 0;function ba(R){var U=kt(R),q=_n(U);return vt(U),q}function Yi(R,U){var q=[],le={};function he(ve){if(!le[ve]&&!xt[ve]){if(Ft[ve]){Ft[ve].forEach(he);return}q.push(ve),le[ve]=!0}}throw U.forEach(he),new uc(R+": "+q.map(ba).join([", "]))}function Xa(R,U,q,le,he,ve,Te,be,ke,Je,pt,Mt,Tt){pt=_n(pt),ve=xr(he,ve),be&&(be=xr(Te,be)),Je&&(Je=xr(ke,Je)),Tt=xr(Mt,Tt);var dn=$n(pt);Ct(dn,function(){Yi("Cannot construct "+pt+" due to unbound types",[le])}),Be([R,U,q],le?[le]:[],function(ln){ln=ln[0];var Xn,li;le?(Xn=ln.registeredClass,li=Xn.instancePrototype):li=ut.prototype;var yi=fn(dn,function(){if(Object.getPrototypeOf(this)!==rf)throw new sn("Use 'new' to construct "+pt);if(Oa.constructor_body===void 0)throw new sn(pt+" has no accessible constructor");var kE=Oa.constructor_body[arguments.length];if(kE===void 0)throw new sn("Tried to invoke ctor of "+pt+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(Oa.constructor_body).toString()+") parameters instead!");return kE.apply(this,arguments)}),rf=Object.create(li,{constructor:{value:yi}});yi.prototype=rf;var Oa=new Qt(pt,yi,rf,Tt,Xn,ve,be,Je),U1=new Nt(pt,Oa,!0,!1,!1),Ih=new Nt(pt+"*",Oa,!1,!1,!1),NE=new Nt(pt+" const*",Oa,!1,!0,!1);return Qr[R]={pointerType:Ih,constPointerType:NE},Bn(dn,yi),[U1,Ih,NE]})}function cl(R,U){for(var q=[],le=0;le>2]);return q}function ll(R,U){if(!(R instanceof Function))throw new TypeError("new_ called with constructor type "+typeof R+" which is not a function");var q=fn(R.name||"unknownFunctionName",function(){});q.prototype=R.prototype;var le=new q,he=R.apply(le,U);return he instanceof Object?he:le}function bs(R,U,q,le,he){var ve=U.length;ve<2&&rn("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var Te=U[1]!==null&&q!==null,be=!1,ke=1;ke{xt.hasOwnProperty(be)?he[ke]=xt[be]:(ve.push(be),Lt.hasOwnProperty(be)||(Lt[be]=[]),Lt[be].push(()=>{he[ke]=xt[be],++Te,Te===ve.length&&le(he)}))}),ve.length===0&&le(he)}function ft(R){var U=tt[R];delete tt[R];var q=U.rawConstructor,le=U.rawDestructor,he=U.fields,ve=he.map(Te=>Te.getterReturnType).concat(he.map(Te=>Te.setterArgumentType));Be([R],ve,Te=>{var be={};return he.forEach((ke,Je)=>{var pt=ke.fieldName,Mt=Te[Je],Tt=ke.getter,dn=ke.getterContext,ln=Te[Je+he.length],Xn=ke.setter,li=ke.setterContext;be[pt]={read:yi=>Mt.fromWireType(Tt(dn,yi)),write:(yi,rf)=>{var Oa=[];Xn(li,yi,ln.toWireType(Oa,rf)),nt(Oa)}}}),[{name:U.name,fromWireType:function(ke){var Je={};for(var pt in be)Je[pt]=be[pt].read(ke);return le(ke),Je},toWireType:function(ke,Je){for(var pt in be)if(!(pt in Je))throw new TypeError('Missing field: "'+pt+'"');var Mt=q();for(pt in be)be[pt].write(Mt,Je[pt]);return ke!==null&&ke.push(le,Mt),Mt},argPackAdvance:8,readValueFromPointer:dt,destructorFunction:le}]})}function Ut(R,U,q,le,he){}function Sn(R){switch(R){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+R)}}function Qn(){for(var R=new Array(256),U=0;U<256;++U)R[U]=String.fromCharCode(U);Pt=R}var Pt=void 0;function _n(R){for(var U="",q=R;k[q];)U+=Pt[k[q++]];return U}var sn=void 0;function rn(R){throw new sn(R)}function pi(R,U,q={}){if(!("argPackAdvance"in U))throw new TypeError("registerType registeredInstance requires argPackAdvance");var le=U.name;if(R||rn('type "'+le+'" must have a positive integer typeid pointer'),xt.hasOwnProperty(R)){if(q.ignoreDuplicateRegistrations)return;rn("Cannot register type '"+le+"' twice")}if(xt[R]=U,delete Ft[R],Lt.hasOwnProperty(R)){var he=Lt[R];delete Lt[R],he.forEach(ve=>ve())}}function Vi(R,U,q,le,he){var ve=Sn(q);U=_n(U),pi(R,{name:U,fromWireType:function(Te){return!!Te},toWireType:function(Te,be){return be?le:he},argPackAdvance:8,readValueFromPointer:function(Te){var be;if(q===1)be=A;else if(q===2)be=F;else if(q===4)be=Y;else throw new TypeError("Unknown boolean type size: "+U);return this.fromWireType(be[Te>>ve])},destructorFunction:null})}function Ha(R){if(!(this instanceof ut)||!(R instanceof ut))return!1;for(var U=this.$$.ptrType.registeredClass,q=this.$$.ptr,le=R.$$.ptrType.registeredClass,he=R.$$.ptr;U.baseClass;)q=U.upcast(q),U=U.baseClass;for(;le.baseClass;)he=le.upcast(he),le=le.baseClass;return U===le&&q===he}function Ea(R){return{count:R.count,deleteScheduled:R.deleteScheduled,preservePointerOnDelete:R.preservePointerOnDelete,ptr:R.ptr,ptrType:R.ptrType,smartPtr:R.smartPtr,smartPtrType:R.smartPtrType}}function To(R){function U(q){return q.$$.ptrType.registeredClass.name}rn(U(R)+" instance already deleted")}var ra=!1;function Uo(R){}function fr(R){R.smartPtr?R.smartPtrType.rawDestructor(R.smartPtr):R.ptrType.registeredClass.rawDestructor(R.ptr)}function oo(R){R.count.value-=1;var U=R.count.value===0;U&&fr(R)}function yn(R,U,q){if(U===q)return R;if(q.baseClass===void 0)return null;var le=yn(R,U,q.baseClass);return le===null?null:q.downcast(le)}var Qr={};function Da(){return Object.keys(Bi).length}function Fi(){var R=[];for(var U in Bi)Bi.hasOwnProperty(U)&&R.push(Bi[U]);return R}var ao=[];function Ui(){for(;ao.length;){var R=ao.pop();R.$$.deleteScheduled=!1,R.delete()}}var mi=void 0;function Ka(R){mi=R,ao.length&&mi&&mi(Ui)}function Bo(){o.getInheritedInstanceCount=Da,o.getLiveInheritedInstances=Fi,o.flushPendingDeletes=Ui,o.setDelayFunction=Ka}var Bi={};function qa(R,U){for(U===void 0&&rn("ptr should not be undefined");R.baseClass;)U=R.upcast(U),R=R.baseClass;return U}function Gi(R,U){return U=qa(R,U),Bi[U]}function ia(R,U){(!U.ptrType||!U.ptr)&&Mr("makeClassHandle requires ptr and ptrType");var q=!!U.smartPtrType,le=!!U.smartPtr;return q!==le&&Mr("Both smartPtrType and smartPtr must be specified"),U.count={value:1},Ue(Object.create(R,{$$:{value:U}}))}function de(R){var U=this.getPointee(R);if(!U)return this.destructor(R),null;var q=Gi(this.registeredClass,U);if(q!==void 0){if(q.$$.count.value===0)return q.$$.ptr=U,q.$$.smartPtr=R,q.clone();var le=q.clone();return this.destructor(R),le}function he(){return this.isSmartPointer?ia(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:U,smartPtrType:this,smartPtr:R}):ia(this.registeredClass.instancePrototype,{ptrType:this,ptr:R})}var ve=this.registeredClass.getActualType(U),Te=Qr[ve];if(!Te)return he.call(this);var be;this.isConst?be=Te.constPointerType:be=Te.pointerType;var ke=yn(U,this.registeredClass,be.registeredClass);return ke===null?he.call(this):this.isSmartPointer?ia(be.registeredClass.instancePrototype,{ptrType:be,ptr:ke,smartPtrType:this,smartPtr:R}):ia(be.registeredClass.instancePrototype,{ptrType:be,ptr:ke})}function Ue(R){return typeof FinalizationRegistry>"u"?(Ue=U=>U,R):(ra=new FinalizationRegistry(U=>{oo(U.$$)}),Ue=U=>{var q=U.$$,le=!!q.smartPtr;if(le){var he={$$:q};ra.register(U,he,U)}return U},Uo=U=>ra.unregister(U),Ue(R))}function _e(){if(this.$$.ptr||To(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var R=Ue(Object.create(Object.getPrototypeOf(this),{$$:{value:Ea(this.$$)}}));return R.$$.count.value+=1,R.$$.deleteScheduled=!1,R}function ye(){this.$$.ptr||To(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&rn("Object already scheduled for deletion"),Uo(this),oo(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function je(){return!this.$$.ptr}function ot(){return this.$$.ptr||To(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&rn("Object already scheduled for deletion"),ao.push(this),ao.length===1&&mi&&mi(Ui),this.$$.deleteScheduled=!0,this}function st(){ut.prototype.isAliasOf=Ha,ut.prototype.clone=_e,ut.prototype.delete=ye,ut.prototype.isDeleted=je,ut.prototype.deleteLater=ot}function ut(){}function rt(R,U,q){if(R[U].overloadTable===void 0){var le=R[U];R[U]=function(){return R[U].overloadTable.hasOwnProperty(arguments.length)||rn("Function '"+q+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+R[U].overloadTable+")!"),R[U].overloadTable[arguments.length].apply(this,arguments)},R[U].overloadTable=[],R[U].overloadTable[le.argCount]=le}}function Ct(R,U,q){o.hasOwnProperty(R)?(rn("Cannot register public name '"+R+"' twice"),rt(o,R,R),o.hasOwnProperty(q)&&rn("Cannot register multiple overloads of a function with the same number of arguments ("+q+")!"),o[R].overloadTable[q]=U):o[R]=U}function Qt(R,U,q,le,he,ve,Te,be){this.name=R,this.constructor=U,this.instancePrototype=q,this.rawDestructor=le,this.baseClass=he,this.getActualType=ve,this.upcast=Te,this.downcast=be,this.pureVirtualFunctions=[]}function on(R,U,q){for(;U!==q;)U.upcast||rn("Expected null or instance of "+q.name+", got an instance of "+U.name),R=U.upcast(R),U=U.baseClass;return R}function cn(R,U){if(U===null)return this.isReference&&rn("null is not a valid "+this.name),0;U.$$||rn('Cannot pass "'+Ja(U)+'" as a '+this.name),U.$$.ptr||rn("Cannot pass deleted object as a pointer of type "+this.name);var q=U.$$.ptrType.registeredClass,le=on(U.$$.ptr,q,this.registeredClass);return le}function Gt(R,U){var q;if(U===null)return this.isReference&&rn("null is not a valid "+this.name),this.isSmartPointer?(q=this.rawConstructor(),R!==null&&R.push(this.rawDestructor,q),q):0;U.$$||rn('Cannot pass "'+Ja(U)+'" as a '+this.name),U.$$.ptr||rn("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&U.$$.ptrType.isConst&&rn("Cannot convert argument of type "+(U.$$.smartPtrType?U.$$.smartPtrType.name:U.$$.ptrType.name)+" to parameter type "+this.name);var le=U.$$.ptrType.registeredClass;if(q=on(U.$$.ptr,le,this.registeredClass),this.isSmartPointer)switch(U.$$.smartPtr===void 0&&rn("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:U.$$.smartPtrType===this?q=U.$$.smartPtr:rn("Cannot convert argument of type "+(U.$$.smartPtrType?U.$$.smartPtrType.name:U.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:q=U.$$.smartPtr;break;case 2:if(U.$$.smartPtrType===this)q=U.$$.smartPtr;else{var he=U.clone();q=this.rawShare(q,Go.toHandle(function(){he.delete()})),R!==null&&R.push(this.rawDestructor,q)}break;default:rn("Unsupporting sharing policy")}return q}function xn(R,U){if(U===null)return this.isReference&&rn("null is not a valid "+this.name),0;U.$$||rn('Cannot pass "'+Ja(U)+'" as a '+this.name),U.$$.ptr||rn("Cannot pass deleted object as a pointer of type "+this.name),U.$$.ptrType.isConst&&rn("Cannot convert argument of type "+U.$$.ptrType.name+" to parameter type "+this.name);var q=U.$$.ptrType.registeredClass,le=on(U.$$.ptr,q,this.registeredClass);return le}function er(R){return this.rawGetPointee&&(R=this.rawGetPointee(R)),R}function nr(R){this.rawDestructor&&this.rawDestructor(R)}function or(R){R!==null&&R.delete()}function qn(){At.prototype.getPointee=er,At.prototype.destructor=nr,At.prototype.argPackAdvance=8,At.prototype.readValueFromPointer=dt,At.prototype.deleteObject=or,At.prototype.fromWireType=de}function At(R,U,q,le,he,ve,Te,be,ke,Je,pt){this.name=R,this.registeredClass=U,this.isReference=q,this.isConst=le,this.isSmartPointer=he,this.pointeeType=ve,this.sharingPolicy=Te,this.rawGetPointee=be,this.rawConstructor=ke,this.rawShare=Je,this.rawDestructor=pt,!he&&U.baseClass===void 0?le?(this.toWireType=cn,this.destructorFunction=null):(this.toWireType=xn,this.destructorFunction=null):this.toWireType=Gt}function Bn(R,U,q){o.hasOwnProperty(R)||Mr("Replacing nonexistant public symbol"),o[R].overloadTable!==void 0&&q!==void 0||(o[R]=U,o[R].argCount=q)}function dr(R,U,q){var le=o["dynCall_"+R];return q&&q.length?le.apply(null,[U].concat(q)):le.call(null,U)}var si=[];function jn(R){var U=si[R];return U||(R>=si.length&&(si.length=R+1),si[R]=U=Ee.get(R)),U}function wr(R,U,q){if(R.includes("j"))return dr(R,U,q);var le=jn(U).apply(null,q);return le}function ei(R,U){var q=[];return function(){return q.length=0,Object.assign(q,arguments),wr(R,U,q)}}function xr(R,U){R=_n(R);function q(){return R.includes("j")?ei(R,U):jn(U)}var le=q();return typeof le!="function"&&rn("unknown function pointer with signature "+R+": "+U),le}var uc=void 0;function ba(R){var U=kt(R),q=_n(U);return vt(U),q}function Yi(R,U){var q=[],le={};function he(ve){if(!le[ve]&&!xt[ve]){if(Ft[ve]){Ft[ve].forEach(he);return}q.push(ve),le[ve]=!0}}throw U.forEach(he),new uc(R+": "+q.map(ba).join([", "]))}function Xa(R,U,q,le,he,ve,Te,be,ke,Je,pt,Mt,Tt){pt=_n(pt),ve=xr(he,ve),be&&(be=xr(Te,be)),Je&&(Je=xr(ke,Je)),Tt=xr(Mt,Tt);var dn=$n(pt);Ct(dn,function(){Yi("Cannot construct "+pt+" due to unbound types",[le])}),Be([R,U,q],le?[le]:[],function(ln){ln=ln[0];var Xn,li;le?(Xn=ln.registeredClass,li=Xn.instancePrototype):li=ut.prototype;var yi=fn(dn,function(){if(Object.getPrototypeOf(this)!==rf)throw new sn("Use 'new' to construct "+pt);if(Oa.constructor_body===void 0)throw new sn(pt+" has no accessible constructor");var kE=Oa.constructor_body[arguments.length];if(kE===void 0)throw new sn("Tried to invoke ctor of "+pt+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(Oa.constructor_body).toString()+") parameters instead!");return kE.apply(this,arguments)}),rf=Object.create(li,{constructor:{value:yi}});yi.prototype=rf;var Oa=new Qt(pt,yi,rf,Tt,Xn,ve,be,Je),U1=new At(pt,Oa,!0,!1,!1),Ih=new At(pt+"*",Oa,!1,!1,!1),NE=new At(pt+" const*",Oa,!1,!0,!1);return Qr[R]={pointerType:Ih,constPointerType:NE},Bn(dn,yi),[U1,Ih,NE]})}function cl(R,U){for(var q=[],le=0;le>2]);return q}function ll(R,U){if(!(R instanceof Function))throw new TypeError("new_ called with constructor type "+typeof R+" which is not a function");var q=fn(R.name||"unknownFunctionName",function(){});q.prototype=R.prototype;var le=new q,he=R.apply(le,U);return he instanceof Object?he:le}function bs(R,U,q,le,he){var ve=U.length;ve<2&&rn("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var Te=U[1]!==null&&q!==null,be=!1,ke=1;ke{nt.hasOwnProperty(qe)?He[it]=nt[qe]:(Ze.push(qe),tt.hasOwnProperty(qe)||(tt[qe]=[]),tt[qe].push(()=>{He[it]=nt[qe],++Qe,Qe===Ze.length&&Ae(He)}))}),Ze.length===0&&Ae(He)}function Xi(Q){var te=gt[Q];delete gt[Q];var me=te.rawConstructor,Ae=te.rawDestructor,He=te.fields,Ze=He.map(Qe=>Qe.getterReturnType).concat(He.map(Qe=>Qe.setterArgumentType));bn([Q],Ze,Qe=>{var qe={};return He.forEach((it,vt)=>{var kt=it.fieldName,Wt=Qe[vt],Kt=it.getter,J=it.getterContext,X=Qe[vt+He.length],fe=it.setter,Me=it.setterContext;qe[kt]={read:We=>Wt.fromWireType(Kt(J,We)),write:(We,ct)=>{var et=[];fe(Me,We,X.toWireType(et,ct)),Ie(et)}}}),[{name:te.name,fromWireType:function(it){var vt={};for(var kt in qe)vt[kt]=qe[kt].read(it);return Ae(it),vt},toWireType:function(it,vt){for(var kt in qe)if(!(kt in vt))throw new TypeError('Missing field: "'+kt+'"');var Wt=me();for(kt in qe)qe[kt].write(Wt,vt[kt]);return it!==null&&it.push(Ae,Wt),Wt},argPackAdvance:8,readValueFromPointer:$e,destructorFunction:Ae}]})}function Mr(Q,te,me,Ae,He){}function Be(Q){switch(Q){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+Q)}}function ft(){for(var Q=new Array(256),te=0;te<256;++te)Q[te]=String.fromCharCode(te);Ut=Q}var Ut=void 0;function Sn(Q){for(var te="",me=Q;V[me];)te+=Ut[V[me++]];return te}var Qn=void 0;function Pt(Q){throw new Qn(Q)}function _n(Q,te,me={}){if(!("argPackAdvance"in te))throw new TypeError("registerType registeredInstance requires argPackAdvance");var Ae=te.name;if(Q||Pt('type "'+Ae+'" must have a positive integer typeid pointer'),nt.hasOwnProperty(Q)){if(me.ignoreDuplicateRegistrations)return;Pt("Cannot register type '"+Ae+"' twice")}if(nt[Q]=te,delete dt[Q],tt.hasOwnProperty(Q)){var He=tt[Q];delete tt[Q],He.forEach(Ze=>Ze())}}function sn(Q,te,me,Ae,He){var Ze=Be(me);te=Sn(te),_n(Q,{name:te,fromWireType:function(Qe){return!!Qe},toWireType:function(Qe,qe){return qe?Ae:He},argPackAdvance:8,readValueFromPointer:function(Qe){var qe;if(me===1)qe=L;else if(me===2)qe=G;else if(me===4)qe=k;else throw new TypeError("Unknown boolean type size: "+te);return this.fromWireType(qe[Qe>>Ze])},destructorFunction:null})}function rn(Q){if(!(this instanceof je)||!(Q instanceof je))return!1;for(var te=this.$$.ptrType.registeredClass,me=this.$$.ptr,Ae=Q.$$.ptrType.registeredClass,He=Q.$$.ptr;te.baseClass;)me=te.upcast(me),te=te.baseClass;for(;Ae.baseClass;)He=Ae.upcast(He),Ae=Ae.baseClass;return te===Ae&&me===He}function pi(Q){return{count:Q.count,deleteScheduled:Q.deleteScheduled,preservePointerOnDelete:Q.preservePointerOnDelete,ptr:Q.ptr,ptrType:Q.ptrType,smartPtr:Q.smartPtr,smartPtrType:Q.smartPtrType}}function Vi(Q){function te(me){return me.$$.ptrType.registeredClass.name}Pt(te(Q)+" instance already deleted")}var Ha=!1;function Ea(Q){}function To(Q){Q.smartPtr?Q.smartPtrType.rawDestructor(Q.smartPtr):Q.ptrType.registeredClass.rawDestructor(Q.ptr)}function ra(Q){Q.count.value-=1;var te=Q.count.value===0;te&&To(Q)}function Uo(Q,te,me){if(te===me)return Q;if(me.baseClass===void 0)return null;var Ae=Uo(Q,te,me.baseClass);return Ae===null?null:me.downcast(Ae)}var fr={};function oo(){return Object.keys(mi).length}function yn(){var Q=[];for(var te in mi)mi.hasOwnProperty(te)&&Q.push(mi[te]);return Q}var Qr=[];function Da(){for(;Qr.length;){var Q=Qr.pop();Q.$$.deleteScheduled=!1,Q.delete()}}var Fi=void 0;function ao(Q){Fi=Q,Qr.length&&Fi&&Fi(Da)}function Ui(){o.getInheritedInstanceCount=oo,o.getLiveInheritedInstances=yn,o.flushPendingDeletes=Da,o.setDelayFunction=ao}var mi={};function Ka(Q,te){for(te===void 0&&Pt("ptr should not be undefined");Q.baseClass;)te=Q.upcast(te),Q=Q.baseClass;return te}function Bo(Q,te){return te=Ka(Q,te),mi[te]}function Bi(Q,te){(!te.ptrType||!te.ptr)&&fn("makeClassHandle requires ptr and ptrType");var me=!!te.smartPtrType,Ae=!!te.smartPtr;return me!==Ae&&fn("Both smartPtrType and smartPtr must be specified"),te.count={value:1},Gi(Object.create(Q,{$$:{value:te}}))}function qa(Q){var te=this.getPointee(Q);if(!te)return this.destructor(Q),null;var me=Bo(this.registeredClass,te);if(me!==void 0){if(me.$$.count.value===0)return me.$$.ptr=te,me.$$.smartPtr=Q,me.clone();var Ae=me.clone();return this.destructor(Q),Ae}function He(){return this.isSmartPointer?Bi(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:te,smartPtrType:this,smartPtr:Q}):Bi(this.registeredClass.instancePrototype,{ptrType:this,ptr:Q})}var Ze=this.registeredClass.getActualType(te),Qe=fr[Ze];if(!Qe)return He.call(this);var qe;this.isConst?qe=Qe.constPointerType:qe=Qe.pointerType;var it=Uo(te,this.registeredClass,qe.registeredClass);return it===null?He.call(this):this.isSmartPointer?Bi(qe.registeredClass.instancePrototype,{ptrType:qe,ptr:it,smartPtrType:this,smartPtr:Q}):Bi(qe.registeredClass.instancePrototype,{ptrType:qe,ptr:it})}function Gi(Q){return typeof FinalizationRegistry>"u"?(Gi=te=>te,Q):(Ha=new FinalizationRegistry(te=>{ra(te.$$)}),Gi=te=>{var me=te.$$,Ae=!!me.smartPtr;if(Ae){var He={$$:me};Ha.register(te,He,te)}return te},Ea=te=>Ha.unregister(te),Gi(Q))}function ia(){if(this.$$.ptr||Vi(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var Q=Gi(Object.create(Object.getPrototypeOf(this),{$$:{value:pi(this.$$)}}));return Q.$$.count.value+=1,Q.$$.deleteScheduled=!1,Q}function de(){this.$$.ptr||Vi(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&Pt("Object already scheduled for deletion"),Ea(this),ra(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function Ue(){return!this.$$.ptr}function _e(){return this.$$.ptr||Vi(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&Pt("Object already scheduled for deletion"),Qr.push(this),Qr.length===1&&Fi&&Fi(Da),this.$$.deleteScheduled=!0,this}function ye(){je.prototype.isAliasOf=rn,je.prototype.clone=ia,je.prototype.delete=de,je.prototype.isDeleted=Ue,je.prototype.deleteLater=_e}function je(){}function ot(Q,te,me){if(Q[te].overloadTable===void 0){var Ae=Q[te];Q[te]=function(){return Q[te].overloadTable.hasOwnProperty(arguments.length)||Pt("Function '"+me+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+Q[te].overloadTable+")!"),Q[te].overloadTable[arguments.length].apply(this,arguments)},Q[te].overloadTable=[],Q[te].overloadTable[Ae.argCount]=Ae}}function st(Q,te,me){o.hasOwnProperty(Q)?((me===void 0||o[Q].overloadTable!==void 0&&o[Q].overloadTable[me]!==void 0)&&Pt("Cannot register public name '"+Q+"' twice"),ot(o,Q,Q),o.hasOwnProperty(me)&&Pt("Cannot register multiple overloads of a function with the same number of arguments ("+me+")!"),o[Q].overloadTable[me]=te):(o[Q]=te,me!==void 0&&(o[Q].numArguments=me))}function ut(Q,te,me,Ae,He,Ze,Qe,qe){this.name=Q,this.constructor=te,this.instancePrototype=me,this.rawDestructor=Ae,this.baseClass=He,this.getActualType=Ze,this.upcast=Qe,this.downcast=qe,this.pureVirtualFunctions=[]}function rt(Q,te,me){for(;te!==me;)te.upcast||Pt("Expected null or instance of "+me.name+", got an instance of "+te.name),Q=te.upcast(Q),te=te.baseClass;return Q}function Ct(Q,te){if(te===null)return this.isReference&&Pt("null is not a valid "+this.name),0;te.$$||Pt('Cannot pass "'+Wi(te)+'" as a '+this.name),te.$$.ptr||Pt("Cannot pass deleted object as a pointer of type "+this.name);var me=te.$$.ptrType.registeredClass,Ae=rt(te.$$.ptr,me,this.registeredClass);return Ae}function Qt(Q,te){var me;if(te===null)return this.isReference&&Pt("null is not a valid "+this.name),this.isSmartPointer?(me=this.rawConstructor(),Q!==null&&Q.push(this.rawDestructor,me),me):0;te.$$||Pt('Cannot pass "'+Wi(te)+'" as a '+this.name),te.$$.ptr||Pt("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&te.$$.ptrType.isConst&&Pt("Cannot convert argument of type "+(te.$$.smartPtrType?te.$$.smartPtrType.name:te.$$.ptrType.name)+" to parameter type "+this.name);var Ae=te.$$.ptrType.registeredClass;if(me=rt(te.$$.ptr,Ae,this.registeredClass),this.isSmartPointer)switch(te.$$.smartPtr===void 0&&Pt("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:te.$$.smartPtrType===this?me=te.$$.smartPtr:Pt("Cannot convert argument of type "+(te.$$.smartPtrType?te.$$.smartPtrType.name:te.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:me=te.$$.smartPtr;break;case 2:if(te.$$.smartPtrType===this)me=te.$$.smartPtr;else{var He=te.clone();me=this.rawShare(me,so.toHandle(function(){He.delete()})),Q!==null&&Q.push(this.rawDestructor,me)}break;default:Pt("Unsupporting sharing policy")}return me}function on(Q,te){if(te===null)return this.isReference&&Pt("null is not a valid "+this.name),0;te.$$||Pt('Cannot pass "'+Wi(te)+'" as a '+this.name),te.$$.ptr||Pt("Cannot pass deleted object as a pointer of type "+this.name),te.$$.ptrType.isConst&&Pt("Cannot convert argument of type "+te.$$.ptrType.name+" to parameter type "+this.name);var me=te.$$.ptrType.registeredClass,Ae=rt(te.$$.ptr,me,this.registeredClass);return Ae}function cn(Q){return this.rawGetPointee&&(Q=this.rawGetPointee(Q)),Q}function Gt(Q){this.rawDestructor&&this.rawDestructor(Q)}function xn(Q){Q!==null&&Q.delete()}function er(){nr.prototype.getPointee=cn,nr.prototype.destructor=Gt,nr.prototype.argPackAdvance=8,nr.prototype.readValueFromPointer=$e,nr.prototype.deleteObject=xn,nr.prototype.fromWireType=qa}function nr(Q,te,me,Ae,He,Ze,Qe,qe,it,vt,kt){this.name=Q,this.registeredClass=te,this.isReference=me,this.isConst=Ae,this.isSmartPointer=He,this.pointeeType=Ze,this.sharingPolicy=Qe,this.rawGetPointee=qe,this.rawConstructor=it,this.rawShare=vt,this.rawDestructor=kt,!He&&te.baseClass===void 0?Ae?(this.toWireType=Ct,this.destructorFunction=null):(this.toWireType=on,this.destructorFunction=null):this.toWireType=Qt}function or(Q,te,me){o.hasOwnProperty(Q)||fn("Replacing nonexistant public symbol"),o[Q].overloadTable!==void 0&&me!==void 0?o[Q].overloadTable[me]=te:(o[Q]=te,o[Q].argCount=me)}function qn(Q,te,me){var Ae=o["dynCall_"+Q];return me&&me.length?Ae.apply(null,[te].concat(me)):Ae.call(null,te)}var Nt=[];function Bn(Q){var te=Nt[Q];return te||(Q>=Nt.length&&(Nt.length=Q+1),Nt[Q]=te=ue.get(Q)),te}function dr(Q,te,me){if(Q.includes("j"))return qn(Q,te,me);var Ae=Bn(te).apply(null,me);return Ae}function si(Q,te){var me=[];return function(){return me.length=0,Object.assign(me,arguments),dr(Q,te,me)}}function jn(Q,te){Q=Sn(Q);function me(){return Q.includes("j")?si(Q,te):Bn(te)}var Ae=me();return typeof Ae!="function"&&Pt("unknown function pointer with signature "+Q+": "+te),Ae}var wr=void 0;function ei(Q){var te=Ia(Q),me=Sn(te);return Eo(te),me}function xr(Q,te){var me=[],Ae={};function He(Ze){if(!Ae[Ze]&&!nt[Ze]){if(dt[Ze]){dt[Ze].forEach(He);return}me.push(Ze),Ae[Ze]=!0}}throw te.forEach(He),new wr(Q+": "+me.map(ei).join([", "]))}function uc(Q,te,me,Ae,He,Ze,Qe,qe,it,vt,kt,Wt,Kt){kt=Sn(kt),Ze=jn(He,Ze),qe&&(qe=jn(Qe,qe)),vt&&(vt=jn(it,vt)),Kt=jn(Wt,Kt);var J=Ft(kt);st(J,function(){xr("Cannot construct "+kt+" due to unbound types",[Ae])}),bn([Q,te,me],Ae?[Ae]:[],function(X){X=X[0];var fe,Me;Ae?(fe=X.registeredClass,Me=fe.instancePrototype):Me=je.prototype;var We=jt(J,function(){if(Object.getPrototypeOf(this)!==ct)throw new Qn("Use 'new' to construct "+kt);if(et.constructor_body===void 0)throw new Qn(kt+" has no accessible constructor");var R=et.constructor_body[arguments.length];if(R===void 0)throw new Qn("Tried to invoke ctor of "+kt+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(et.constructor_body).toString()+") parameters instead!");return R.apply(this,arguments)}),ct=Object.create(Me,{constructor:{value:We}});We.prototype=ct;var et=new ut(kt,We,ct,Kt,fe,Ze,qe,vt),Ye=new nr(kt,et,!0,!1,!1),$=new nr(kt+"*",et,!1,!1,!1),H=new nr(kt+" const*",et,!1,!0,!1);return fr[Q]={pointerType:$,constPointerType:H},or(J,We),[Ye,$,H]})}function ba(Q,te){for(var me=[],Ae=0;Ae>2]);return me}function Yi(Q,te){if(!(Q instanceof Function))throw new TypeError("new_ called with constructor type "+typeof Q+" which is not a function");var me=jt(Q.name||"unknownFunctionName",function(){});me.prototype=Q.prototype;var Ae=new me,He=Q.apply(Ae,te);return He instanceof Object?He:Ae}function Xa(Q,te,me,Ae,He){var Ze=te.length;Ze<2&&Pt("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var Qe=te[1]!==null&&me!==null,qe=!1,it=1;it{nt.hasOwnProperty(qe)?He[it]=nt[qe]:(Ze.push(qe),tt.hasOwnProperty(qe)||(tt[qe]=[]),tt[qe].push(()=>{He[it]=nt[qe],++Qe,Qe===Ze.length&&Ae(He)}))}),Ze.length===0&&Ae(He)}function Xi(Q){var te=gt[Q];delete gt[Q];var me=te.rawConstructor,Ae=te.rawDestructor,He=te.fields,Ze=He.map(Qe=>Qe.getterReturnType).concat(He.map(Qe=>Qe.setterArgumentType));bn([Q],Ze,Qe=>{var qe={};return He.forEach((it,vt)=>{var kt=it.fieldName,Wt=Qe[vt],Kt=it.getter,J=it.getterContext,X=Qe[vt+He.length],fe=it.setter,Me=it.setterContext;qe[kt]={read:We=>Wt.fromWireType(Kt(J,We)),write:(We,ct)=>{var et=[];fe(Me,We,X.toWireType(et,ct)),Ie(et)}}}),[{name:te.name,fromWireType:function(it){var vt={};for(var kt in qe)vt[kt]=qe[kt].read(it);return Ae(it),vt},toWireType:function(it,vt){for(var kt in qe)if(!(kt in vt))throw new TypeError('Missing field: "'+kt+'"');var Wt=me();for(kt in qe)qe[kt].write(Wt,vt[kt]);return it!==null&&it.push(Ae,Wt),Wt},argPackAdvance:8,readValueFromPointer:$e,destructorFunction:Ae}]})}function Mr(Q,te,me,Ae,He){}function Be(Q){switch(Q){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+Q)}}function ft(){for(var Q=new Array(256),te=0;te<256;++te)Q[te]=String.fromCharCode(te);Ut=Q}var Ut=void 0;function Sn(Q){for(var te="",me=Q;V[me];)te+=Ut[V[me++]];return te}var Qn=void 0;function Pt(Q){throw new Qn(Q)}function _n(Q,te,me={}){if(!("argPackAdvance"in te))throw new TypeError("registerType registeredInstance requires argPackAdvance");var Ae=te.name;if(Q||Pt('type "'+Ae+'" must have a positive integer typeid pointer'),nt.hasOwnProperty(Q)){if(me.ignoreDuplicateRegistrations)return;Pt("Cannot register type '"+Ae+"' twice")}if(nt[Q]=te,delete dt[Q],tt.hasOwnProperty(Q)){var He=tt[Q];delete tt[Q],He.forEach(Ze=>Ze())}}function sn(Q,te,me,Ae,He){var Ze=Be(me);te=Sn(te),_n(Q,{name:te,fromWireType:function(Qe){return!!Qe},toWireType:function(Qe,qe){return qe?Ae:He},argPackAdvance:8,readValueFromPointer:function(Qe){var qe;if(me===1)qe=L;else if(me===2)qe=G;else if(me===4)qe=k;else throw new TypeError("Unknown boolean type size: "+te);return this.fromWireType(qe[Qe>>Ze])},destructorFunction:null})}function rn(Q){if(!(this instanceof je)||!(Q instanceof je))return!1;for(var te=this.$$.ptrType.registeredClass,me=this.$$.ptr,Ae=Q.$$.ptrType.registeredClass,He=Q.$$.ptr;te.baseClass;)me=te.upcast(me),te=te.baseClass;for(;Ae.baseClass;)He=Ae.upcast(He),Ae=Ae.baseClass;return te===Ae&&me===He}function pi(Q){return{count:Q.count,deleteScheduled:Q.deleteScheduled,preservePointerOnDelete:Q.preservePointerOnDelete,ptr:Q.ptr,ptrType:Q.ptrType,smartPtr:Q.smartPtr,smartPtrType:Q.smartPtrType}}function Vi(Q){function te(me){return me.$$.ptrType.registeredClass.name}Pt(te(Q)+" instance already deleted")}var Ha=!1;function Ea(Q){}function To(Q){Q.smartPtr?Q.smartPtrType.rawDestructor(Q.smartPtr):Q.ptrType.registeredClass.rawDestructor(Q.ptr)}function ra(Q){Q.count.value-=1;var te=Q.count.value===0;te&&To(Q)}function Uo(Q,te,me){if(te===me)return Q;if(me.baseClass===void 0)return null;var Ae=Uo(Q,te,me.baseClass);return Ae===null?null:me.downcast(Ae)}var fr={};function oo(){return Object.keys(mi).length}function yn(){var Q=[];for(var te in mi)mi.hasOwnProperty(te)&&Q.push(mi[te]);return Q}var Qr=[];function Da(){for(;Qr.length;){var Q=Qr.pop();Q.$$.deleteScheduled=!1,Q.delete()}}var Fi=void 0;function ao(Q){Fi=Q,Qr.length&&Fi&&Fi(Da)}function Ui(){o.getInheritedInstanceCount=oo,o.getLiveInheritedInstances=yn,o.flushPendingDeletes=Da,o.setDelayFunction=ao}var mi={};function Ka(Q,te){for(te===void 0&&Pt("ptr should not be undefined");Q.baseClass;)te=Q.upcast(te),Q=Q.baseClass;return te}function Bo(Q,te){return te=Ka(Q,te),mi[te]}function Bi(Q,te){(!te.ptrType||!te.ptr)&&fn("makeClassHandle requires ptr and ptrType");var me=!!te.smartPtrType,Ae=!!te.smartPtr;return me!==Ae&&fn("Both smartPtrType and smartPtr must be specified"),te.count={value:1},Gi(Object.create(Q,{$$:{value:te}}))}function qa(Q){var te=this.getPointee(Q);if(!te)return this.destructor(Q),null;var me=Bo(this.registeredClass,te);if(me!==void 0){if(me.$$.count.value===0)return me.$$.ptr=te,me.$$.smartPtr=Q,me.clone();var Ae=me.clone();return this.destructor(Q),Ae}function He(){return this.isSmartPointer?Bi(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:te,smartPtrType:this,smartPtr:Q}):Bi(this.registeredClass.instancePrototype,{ptrType:this,ptr:Q})}var Ze=this.registeredClass.getActualType(te),Qe=fr[Ze];if(!Qe)return He.call(this);var qe;this.isConst?qe=Qe.constPointerType:qe=Qe.pointerType;var it=Uo(te,this.registeredClass,qe.registeredClass);return it===null?He.call(this):this.isSmartPointer?Bi(qe.registeredClass.instancePrototype,{ptrType:qe,ptr:it,smartPtrType:this,smartPtr:Q}):Bi(qe.registeredClass.instancePrototype,{ptrType:qe,ptr:it})}function Gi(Q){return typeof FinalizationRegistry>"u"?(Gi=te=>te,Q):(Ha=new FinalizationRegistry(te=>{ra(te.$$)}),Gi=te=>{var me=te.$$,Ae=!!me.smartPtr;if(Ae){var He={$$:me};Ha.register(te,He,te)}return te},Ea=te=>Ha.unregister(te),Gi(Q))}function ia(){if(this.$$.ptr||Vi(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var Q=Gi(Object.create(Object.getPrototypeOf(this),{$$:{value:pi(this.$$)}}));return Q.$$.count.value+=1,Q.$$.deleteScheduled=!1,Q}function de(){this.$$.ptr||Vi(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&Pt("Object already scheduled for deletion"),Ea(this),ra(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function Ue(){return!this.$$.ptr}function _e(){return this.$$.ptr||Vi(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&Pt("Object already scheduled for deletion"),Qr.push(this),Qr.length===1&&Fi&&Fi(Da),this.$$.deleteScheduled=!0,this}function ye(){je.prototype.isAliasOf=rn,je.prototype.clone=ia,je.prototype.delete=de,je.prototype.isDeleted=Ue,je.prototype.deleteLater=_e}function je(){}function ot(Q,te,me){if(Q[te].overloadTable===void 0){var Ae=Q[te];Q[te]=function(){return Q[te].overloadTable.hasOwnProperty(arguments.length)||Pt("Function '"+me+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+Q[te].overloadTable+")!"),Q[te].overloadTable[arguments.length].apply(this,arguments)},Q[te].overloadTable=[],Q[te].overloadTable[Ae.argCount]=Ae}}function st(Q,te,me){o.hasOwnProperty(Q)?((me===void 0||o[Q].overloadTable!==void 0&&o[Q].overloadTable[me]!==void 0)&&Pt("Cannot register public name '"+Q+"' twice"),ot(o,Q,Q),o.hasOwnProperty(me)&&Pt("Cannot register multiple overloads of a function with the same number of arguments ("+me+")!"),o[Q].overloadTable[me]=te):(o[Q]=te,me!==void 0&&(o[Q].numArguments=me))}function ut(Q,te,me,Ae,He,Ze,Qe,qe){this.name=Q,this.constructor=te,this.instancePrototype=me,this.rawDestructor=Ae,this.baseClass=He,this.getActualType=Ze,this.upcast=Qe,this.downcast=qe,this.pureVirtualFunctions=[]}function rt(Q,te,me){for(;te!==me;)te.upcast||Pt("Expected null or instance of "+me.name+", got an instance of "+te.name),Q=te.upcast(Q),te=te.baseClass;return Q}function Ct(Q,te){if(te===null)return this.isReference&&Pt("null is not a valid "+this.name),0;te.$$||Pt('Cannot pass "'+Wi(te)+'" as a '+this.name),te.$$.ptr||Pt("Cannot pass deleted object as a pointer of type "+this.name);var me=te.$$.ptrType.registeredClass,Ae=rt(te.$$.ptr,me,this.registeredClass);return Ae}function Qt(Q,te){var me;if(te===null)return this.isReference&&Pt("null is not a valid "+this.name),this.isSmartPointer?(me=this.rawConstructor(),Q!==null&&Q.push(this.rawDestructor,me),me):0;te.$$||Pt('Cannot pass "'+Wi(te)+'" as a '+this.name),te.$$.ptr||Pt("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&te.$$.ptrType.isConst&&Pt("Cannot convert argument of type "+(te.$$.smartPtrType?te.$$.smartPtrType.name:te.$$.ptrType.name)+" to parameter type "+this.name);var Ae=te.$$.ptrType.registeredClass;if(me=rt(te.$$.ptr,Ae,this.registeredClass),this.isSmartPointer)switch(te.$$.smartPtr===void 0&&Pt("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:te.$$.smartPtrType===this?me=te.$$.smartPtr:Pt("Cannot convert argument of type "+(te.$$.smartPtrType?te.$$.smartPtrType.name:te.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:me=te.$$.smartPtr;break;case 2:if(te.$$.smartPtrType===this)me=te.$$.smartPtr;else{var He=te.clone();me=this.rawShare(me,so.toHandle(function(){He.delete()})),Q!==null&&Q.push(this.rawDestructor,me)}break;default:Pt("Unsupporting sharing policy")}return me}function on(Q,te){if(te===null)return this.isReference&&Pt("null is not a valid "+this.name),0;te.$$||Pt('Cannot pass "'+Wi(te)+'" as a '+this.name),te.$$.ptr||Pt("Cannot pass deleted object as a pointer of type "+this.name),te.$$.ptrType.isConst&&Pt("Cannot convert argument of type "+te.$$.ptrType.name+" to parameter type "+this.name);var me=te.$$.ptrType.registeredClass,Ae=rt(te.$$.ptr,me,this.registeredClass);return Ae}function cn(Q){return this.rawGetPointee&&(Q=this.rawGetPointee(Q)),Q}function Gt(Q){this.rawDestructor&&this.rawDestructor(Q)}function xn(Q){Q!==null&&Q.delete()}function er(){nr.prototype.getPointee=cn,nr.prototype.destructor=Gt,nr.prototype.argPackAdvance=8,nr.prototype.readValueFromPointer=$e,nr.prototype.deleteObject=xn,nr.prototype.fromWireType=qa}function nr(Q,te,me,Ae,He,Ze,Qe,qe,it,vt,kt){this.name=Q,this.registeredClass=te,this.isReference=me,this.isConst=Ae,this.isSmartPointer=He,this.pointeeType=Ze,this.sharingPolicy=Qe,this.rawGetPointee=qe,this.rawConstructor=it,this.rawShare=vt,this.rawDestructor=kt,!He&&te.baseClass===void 0?Ae?(this.toWireType=Ct,this.destructorFunction=null):(this.toWireType=on,this.destructorFunction=null):this.toWireType=Qt}function or(Q,te,me){o.hasOwnProperty(Q)||fn("Replacing nonexistant public symbol"),o[Q].overloadTable!==void 0&&me!==void 0?o[Q].overloadTable[me]=te:(o[Q]=te,o[Q].argCount=me)}function qn(Q,te,me){var Ae=o["dynCall_"+Q];return me&&me.length?Ae.apply(null,[te].concat(me)):Ae.call(null,te)}var At=[];function Bn(Q){var te=At[Q];return te||(Q>=At.length&&(At.length=Q+1),At[Q]=te=ue.get(Q)),te}function dr(Q,te,me){if(Q.includes("j"))return qn(Q,te,me);var Ae=Bn(te).apply(null,me);return Ae}function si(Q,te){var me=[];return function(){return me.length=0,Object.assign(me,arguments),dr(Q,te,me)}}function jn(Q,te){Q=Sn(Q);function me(){return Q.includes("j")?si(Q,te):Bn(te)}var Ae=me();return typeof Ae!="function"&&Pt("unknown function pointer with signature "+Q+": "+te),Ae}var wr=void 0;function ei(Q){var te=Ia(Q),me=Sn(te);return Eo(te),me}function xr(Q,te){var me=[],Ae={};function He(Ze){if(!Ae[Ze]&&!nt[Ze]){if(dt[Ze]){dt[Ze].forEach(He);return}me.push(Ze),Ae[Ze]=!0}}throw te.forEach(He),new wr(Q+": "+me.map(ei).join([", "]))}function uc(Q,te,me,Ae,He,Ze,Qe,qe,it,vt,kt,Wt,Kt){kt=Sn(kt),Ze=jn(He,Ze),qe&&(qe=jn(Qe,qe)),vt&&(vt=jn(it,vt)),Kt=jn(Wt,Kt);var J=Ft(kt);st(J,function(){xr("Cannot construct "+kt+" due to unbound types",[Ae])}),bn([Q,te,me],Ae?[Ae]:[],function(X){X=X[0];var fe,Me;Ae?(fe=X.registeredClass,Me=fe.instancePrototype):Me=je.prototype;var We=jt(J,function(){if(Object.getPrototypeOf(this)!==ct)throw new Qn("Use 'new' to construct "+kt);if(et.constructor_body===void 0)throw new Qn(kt+" has no accessible constructor");var R=et.constructor_body[arguments.length];if(R===void 0)throw new Qn("Tried to invoke ctor of "+kt+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(et.constructor_body).toString()+") parameters instead!");return R.apply(this,arguments)}),ct=Object.create(Me,{constructor:{value:We}});We.prototype=ct;var et=new ut(kt,We,ct,Kt,fe,Ze,qe,vt),Ye=new nr(kt,et,!0,!1,!1),$=new nr(kt+"*",et,!1,!1,!1),H=new nr(kt+" const*",et,!1,!0,!1);return fr[Q]={pointerType:$,constPointerType:H},or(J,We),[Ye,$,H]})}function ba(Q,te){for(var me=[],Ae=0;Ae>2]);return me}function Yi(Q,te){if(!(Q instanceof Function))throw new TypeError("new_ called with constructor type "+typeof Q+" which is not a function");var me=jt(Q.name||"unknownFunctionName",function(){});me.prototype=Q.prototype;var Ae=new me,He=Q.apply(Ae,te);return He instanceof Object?He:Ae}function Xa(Q,te,me,Ae,He){var Ze=te.length;Ze<2&&Pt("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var Qe=te[1]!==null&&me!==null,qe=!1,it=1;it{Lt.hasOwnProperty(Ye)?We[$]=Lt[Ye]:(ct.push(Ye),dt.hasOwnProperty(Ye)||(dt[Ye]=[]),dt[Ye].push(()=>{We[$]=Lt[Ye],++et,et===ct.length&&Me(We)}))}),ct.length===0&&Me(We)}function Be(J){var X=$e[J];delete $e[J];var fe=X.rawConstructor,Me=X.rawDestructor,We=X.fields,ct=We.map(et=>et.getterReturnType).concat(We.map(et=>et.setterArgumentType));Mr([J],ct,et=>{var Ye={};return We.forEach(($,H)=>{var R=$.fieldName,U=et[H],q=$.getter,le=$.getterContext,he=et[H+We.length],ve=$.setter,Te=$.setterContext;Ye[R]={read:be=>U.fromWireType(q(le,be)),write:(be,ke)=>{var Je=[];ve(Te,be,he.toWireType(Je,ke)),tt(Je)}}}),[{name:X.name,fromWireType:function($){var H={};for(var R in Ye)H[R]=Ye[R].read($);return Me($),H},toWireType:function($,H){for(var R in Ye)if(!(R in H))throw new TypeError('Missing field: "'+R+'"');var U=fe();for(R in Ye)Ye[R].write(U,H[R]);return $!==null&&$.push(Me,U),U},argPackAdvance:8,readValueFromPointer:nt,destructorFunction:Me}]})}function ft(J,X,fe,Me,We){}function Ut(J){switch(J){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+J)}}function Sn(){for(var J=new Array(256),X=0;X<256;++X)J[X]=String.fromCharCode(X);Qn=J}var Qn=void 0;function Pt(J){for(var X="",fe=J;A[fe];)X+=Qn[A[fe++]];return X}var _n=void 0;function sn(J){throw new _n(J)}function rn(J,X,fe={}){if(!("argPackAdvance"in X))throw new TypeError("registerType registeredInstance requires argPackAdvance");var Me=X.name;if(J||sn('type "'+Me+'" must have a positive integer typeid pointer'),Lt.hasOwnProperty(J)){if(fe.ignoreDuplicateRegistrations)return;sn("Cannot register type '"+Me+"' twice")}if(Lt[J]=X,delete xt[J],dt.hasOwnProperty(J)){var We=dt[J];delete dt[J],We.forEach(ct=>ct())}}function pi(J,X,fe,Me,We){var ct=Ut(fe);X=Pt(X),rn(J,{name:X,fromWireType:function(et){return!!et},toWireType:function(et,Ye){return Ye?Me:We},argPackAdvance:8,readValueFromPointer:function(et){var Ye;if(fe===1)Ye=G;else if(fe===2)Ye=k;else if(fe===4)Ye=j;else throw new TypeError("Unknown boolean type size: "+X);return this.fromWireType(Ye[et>>ct])},destructorFunction:null})}function Vi(J){if(!(this instanceof st)||!(J instanceof st))return!1;for(var X=this.$$.ptrType.registeredClass,fe=this.$$.ptr,Me=J.$$.ptrType.registeredClass,We=J.$$.ptr;X.baseClass;)fe=X.upcast(fe),X=X.baseClass;for(;Me.baseClass;)We=Me.upcast(We),Me=Me.baseClass;return X===Me&&fe===We}function Ha(J){return{count:J.count,deleteScheduled:J.deleteScheduled,preservePointerOnDelete:J.preservePointerOnDelete,ptr:J.ptr,ptrType:J.ptrType,smartPtr:J.smartPtr,smartPtrType:J.smartPtrType}}function Ea(J){function X(fe){return fe.$$.ptrType.registeredClass.name}sn(X(J)+" instance already deleted")}var To=!1;function ra(J){}function Uo(J){J.smartPtr?J.smartPtrType.rawDestructor(J.smartPtr):J.ptrType.registeredClass.rawDestructor(J.ptr)}function fr(J){J.count.value-=1;var X=J.count.value===0;X&&Uo(J)}function oo(J,X,fe){if(X===fe)return J;if(fe.baseClass===void 0)return null;var Me=oo(J,X,fe.baseClass);return Me===null?null:fe.downcast(Me)}var yn={};function Qr(){return Object.keys(Bo).length}function Da(){var J=[];for(var X in Bo)Bo.hasOwnProperty(X)&&J.push(Bo[X]);return J}var Fi=[];function ao(){for(;Fi.length;){var J=Fi.pop();J.$$.deleteScheduled=!1,J.delete()}}var Ui=void 0;function mi(J){Ui=J,Fi.length&&Ui&&Ui(ao)}function Ka(){o.getInheritedInstanceCount=Qr,o.getLiveInheritedInstances=Da,o.flushPendingDeletes=ao,o.setDelayFunction=mi}var Bo={};function Bi(J,X){for(X===void 0&&sn("ptr should not be undefined");J.baseClass;)X=J.upcast(X),J=J.baseClass;return X}function qa(J,X){return X=Bi(J,X),Bo[X]}function Gi(J,X){(!X.ptrType||!X.ptr)&&Xi("makeClassHandle requires ptr and ptrType");var fe=!!X.smartPtrType,Me=!!X.smartPtr;return fe!==Me&&Xi("Both smartPtrType and smartPtr must be specified"),X.count={value:1},de(Object.create(J,{$$:{value:X}}))}function ia(J){var X=this.getPointee(J);if(!X)return this.destructor(J),null;var fe=qa(this.registeredClass,X);if(fe!==void 0){if(fe.$$.count.value===0)return fe.$$.ptr=X,fe.$$.smartPtr=J,fe.clone();var Me=fe.clone();return this.destructor(J),Me}function We(){return this.isSmartPointer?Gi(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:X,smartPtrType:this,smartPtr:J}):Gi(this.registeredClass.instancePrototype,{ptrType:this,ptr:J})}var ct=this.registeredClass.getActualType(X),et=yn[ct];if(!et)return We.call(this);var Ye;this.isConst?Ye=et.constPointerType:Ye=et.pointerType;var $=oo(X,this.registeredClass,Ye.registeredClass);return $===null?We.call(this):this.isSmartPointer?Gi(Ye.registeredClass.instancePrototype,{ptrType:Ye,ptr:$,smartPtrType:this,smartPtr:J}):Gi(Ye.registeredClass.instancePrototype,{ptrType:Ye,ptr:$})}function de(J){return typeof FinalizationRegistry>"u"?(de=X=>X,J):(To=new FinalizationRegistry(X=>{fr(X.$$)}),de=X=>{var fe=X.$$,Me=!!fe.smartPtr;if(Me){var We={$$:fe};To.register(X,We,X)}return X},ra=X=>To.unregister(X),de(J))}function Ue(){if(this.$$.ptr||Ea(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var J=de(Object.create(Object.getPrototypeOf(this),{$$:{value:Ha(this.$$)}}));return J.$$.count.value+=1,J.$$.deleteScheduled=!1,J}function _e(){this.$$.ptr||Ea(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&sn("Object already scheduled for deletion"),ra(this),fr(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function ye(){return!this.$$.ptr}function je(){return this.$$.ptr||Ea(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&sn("Object already scheduled for deletion"),Fi.push(this),Fi.length===1&&Ui&&Ui(ao),this.$$.deleteScheduled=!0,this}function ot(){st.prototype.isAliasOf=Vi,st.prototype.clone=Ue,st.prototype.delete=_e,st.prototype.isDeleted=ye,st.prototype.deleteLater=je}function st(){}function ut(J,X,fe){if(J[X].overloadTable===void 0){var Me=J[X];J[X]=function(){return J[X].overloadTable.hasOwnProperty(arguments.length)||sn("Function '"+fe+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+J[X].overloadTable+")!"),J[X].overloadTable[arguments.length].apply(this,arguments)},J[X].overloadTable=[],J[X].overloadTable[Me.argCount]=Me}}function rt(J,X,fe){o.hasOwnProperty(J)?(sn("Cannot register public name '"+J+"' twice"),ut(o,J,J),o.hasOwnProperty(fe)&&sn("Cannot register multiple overloads of a function with the same number of arguments ("+fe+")!"),o[J].overloadTable[fe]=X):o[J]=X}function Ct(J,X,fe,Me,We,ct,et,Ye){this.name=J,this.constructor=X,this.instancePrototype=fe,this.rawDestructor=Me,this.baseClass=We,this.getActualType=ct,this.upcast=et,this.downcast=Ye,this.pureVirtualFunctions=[]}function Qt(J,X,fe){for(;X!==fe;)X.upcast||sn("Expected null or instance of "+fe.name+", got an instance of "+X.name),J=X.upcast(J),X=X.baseClass;return J}function on(J,X){if(X===null)return this.isReference&&sn("null is not a valid "+this.name),0;X.$$||sn('Cannot pass "'+fc(X)+'" as a '+this.name),X.$$.ptr||sn("Cannot pass deleted object as a pointer of type "+this.name);var fe=X.$$.ptrType.registeredClass,Me=Qt(X.$$.ptr,fe,this.registeredClass);return Me}function cn(J,X){var fe;if(X===null)return this.isReference&&sn("null is not a valid "+this.name),this.isSmartPointer?(fe=this.rawConstructor(),J!==null&&J.push(this.rawDestructor,fe),fe):0;X.$$||sn('Cannot pass "'+fc(X)+'" as a '+this.name),X.$$.ptr||sn("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&X.$$.ptrType.isConst&&sn("Cannot convert argument of type "+(X.$$.smartPtrType?X.$$.smartPtrType.name:X.$$.ptrType.name)+" to parameter type "+this.name);var Me=X.$$.ptrType.registeredClass;if(fe=Qt(X.$$.ptr,Me,this.registeredClass),this.isSmartPointer)switch(X.$$.smartPtr===void 0&&sn("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:X.$$.smartPtrType===this?fe=X.$$.smartPtr:sn("Cannot convert argument of type "+(X.$$.smartPtrType?X.$$.smartPtrType.name:X.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:fe=X.$$.smartPtr;break;case 2:if(X.$$.smartPtrType===this)fe=X.$$.smartPtr;else{var We=X.clone();fe=this.rawShare(fe,Wi.toHandle(function(){We.delete()})),J!==null&&J.push(this.rawDestructor,fe)}break;default:sn("Unsupporting sharing policy")}return fe}function Gt(J,X){if(X===null)return this.isReference&&sn("null is not a valid "+this.name),0;X.$$||sn('Cannot pass "'+fc(X)+'" as a '+this.name),X.$$.ptr||sn("Cannot pass deleted object as a pointer of type "+this.name),X.$$.ptrType.isConst&&sn("Cannot convert argument of type "+X.$$.ptrType.name+" to parameter type "+this.name);var fe=X.$$.ptrType.registeredClass,Me=Qt(X.$$.ptr,fe,this.registeredClass);return Me}function xn(J){return this.rawGetPointee&&(J=this.rawGetPointee(J)),J}function er(J){this.rawDestructor&&this.rawDestructor(J)}function nr(J){J!==null&&J.delete()}function or(){qn.prototype.getPointee=xn,qn.prototype.destructor=er,qn.prototype.argPackAdvance=8,qn.prototype.readValueFromPointer=nt,qn.prototype.deleteObject=nr,qn.prototype.fromWireType=ia}function qn(J,X,fe,Me,We,ct,et,Ye,$,H,R){this.name=J,this.registeredClass=X,this.isReference=fe,this.isConst=Me,this.isSmartPointer=We,this.pointeeType=ct,this.sharingPolicy=et,this.rawGetPointee=Ye,this.rawConstructor=$,this.rawShare=H,this.rawDestructor=R,!We&&X.baseClass===void 0?Me?(this.toWireType=on,this.destructorFunction=null):(this.toWireType=Gt,this.destructorFunction=null):this.toWireType=cn}function Nt(J,X,fe){o.hasOwnProperty(J)||Xi("Replacing nonexistant public symbol"),o[J].overloadTable!==void 0&&fe!==void 0||(o[J]=X,o[J].argCount=fe)}function Bn(J,X,fe){var Me=o["dynCall_"+J];return fe&&fe.length?Me.apply(null,[X].concat(fe)):Me.call(null,X)}var dr=[];function si(J){var X=dr[J];return X||(J>=dr.length&&(dr.length=J+1),dr[J]=X=pe.get(J)),X}function jn(J,X,fe){if(J.includes("j"))return Bn(J,X,fe);var Me=si(X).apply(null,fe);return Me}function wr(J,X){var fe=[];return function(){return fe.length=0,Object.assign(fe,arguments),jn(J,X,fe)}}function ei(J,X){J=Pt(J);function fe(){return J.includes("j")?wr(J,X):si(X)}var Me=fe();return typeof Me!="function"&&sn("unknown function pointer with signature "+J+": "+X),Me}var xr=void 0;function uc(J){var X=Qe(J),fe=Pt(X);return Ze(X),fe}function ba(J,X){var fe=[],Me={};function We(ct){if(!Me[ct]&&!Lt[ct]){if(xt[ct]){xt[ct].forEach(We);return}fe.push(ct),Me[ct]=!0}}throw X.forEach(We),new xr(J+": "+fe.map(uc).join([", "]))}function Yi(J,X,fe,Me,We,ct,et,Ye,$,H,R,U,q){R=Pt(R),ct=ei(We,ct),Ye&&(Ye=ei(et,Ye)),H&&(H=ei($,H)),q=ei(U,q);var le=Pn(R);rt(le,function(){ba("Cannot construct "+R+" due to unbound types",[Me])}),Mr([J,X,fe],Me?[Me]:[],function(he){he=he[0];var ve,Te;Me?(ve=he.registeredClass,Te=ve.instancePrototype):Te=st.prototype;var be=$n(le,function(){if(Object.getPrototypeOf(this)!==ke)throw new _n("Use 'new' to construct "+R);if(Je.constructor_body===void 0)throw new _n(R+" has no accessible constructor");var dn=Je.constructor_body[arguments.length];if(dn===void 0)throw new _n("Tried to invoke ctor of "+R+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(Je.constructor_body).toString()+") parameters instead!");return dn.apply(this,arguments)}),ke=Object.create(Te,{constructor:{value:be}});be.prototype=ke;var Je=new Ct(R,be,ke,q,ve,ct,Ye,H),pt=new qn(R,Je,!0,!1,!1),Mt=new qn(R+"*",Je,!1,!1,!1),Tt=new qn(R+" const*",Je,!1,!0,!1);return yn[J]={pointerType:Mt,constPointerType:Tt},Nt(le,be),[pt,Mt,Tt]})}function Xa(J,X){for(var fe=[],Me=0;Me>2]);return fe}function cl(J,X){if(!(J instanceof Function))throw new TypeError("new_ called with constructor type "+typeof J+" which is not a function");var fe=$n(J.name||"unknownFunctionName",function(){});fe.prototype=J.prototype;var Me=new fe,We=J.apply(Me,X);return We instanceof Object?We:Me}function ll(J,X,fe,Me,We){var ct=X.length;ct<2&&sn("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var et=X[1]!==null&&fe!==null,Ye=!1,$=1;${Lt.hasOwnProperty(Ye)?We[$]=Lt[Ye]:(ct.push(Ye),dt.hasOwnProperty(Ye)||(dt[Ye]=[]),dt[Ye].push(()=>{We[$]=Lt[Ye],++et,et===ct.length&&Me(We)}))}),ct.length===0&&Me(We)}function Be(J){var X=$e[J];delete $e[J];var fe=X.rawConstructor,Me=X.rawDestructor,We=X.fields,ct=We.map(et=>et.getterReturnType).concat(We.map(et=>et.setterArgumentType));Mr([J],ct,et=>{var Ye={};return We.forEach(($,H)=>{var R=$.fieldName,U=et[H],q=$.getter,le=$.getterContext,he=et[H+We.length],ve=$.setter,Te=$.setterContext;Ye[R]={read:be=>U.fromWireType(q(le,be)),write:(be,ke)=>{var Je=[];ve(Te,be,he.toWireType(Je,ke)),tt(Je)}}}),[{name:X.name,fromWireType:function($){var H={};for(var R in Ye)H[R]=Ye[R].read($);return Me($),H},toWireType:function($,H){for(var R in Ye)if(!(R in H))throw new TypeError('Missing field: "'+R+'"');var U=fe();for(R in Ye)Ye[R].write(U,H[R]);return $!==null&&$.push(Me,U),U},argPackAdvance:8,readValueFromPointer:nt,destructorFunction:Me}]})}function ft(J,X,fe,Me,We){}function Ut(J){switch(J){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+J)}}function Sn(){for(var J=new Array(256),X=0;X<256;++X)J[X]=String.fromCharCode(X);Qn=J}var Qn=void 0;function Pt(J){for(var X="",fe=J;A[fe];)X+=Qn[A[fe++]];return X}var _n=void 0;function sn(J){throw new _n(J)}function rn(J,X,fe={}){if(!("argPackAdvance"in X))throw new TypeError("registerType registeredInstance requires argPackAdvance");var Me=X.name;if(J||sn('type "'+Me+'" must have a positive integer typeid pointer'),Lt.hasOwnProperty(J)){if(fe.ignoreDuplicateRegistrations)return;sn("Cannot register type '"+Me+"' twice")}if(Lt[J]=X,delete xt[J],dt.hasOwnProperty(J)){var We=dt[J];delete dt[J],We.forEach(ct=>ct())}}function pi(J,X,fe,Me,We){var ct=Ut(fe);X=Pt(X),rn(J,{name:X,fromWireType:function(et){return!!et},toWireType:function(et,Ye){return Ye?Me:We},argPackAdvance:8,readValueFromPointer:function(et){var Ye;if(fe===1)Ye=G;else if(fe===2)Ye=k;else if(fe===4)Ye=j;else throw new TypeError("Unknown boolean type size: "+X);return this.fromWireType(Ye[et>>ct])},destructorFunction:null})}function Vi(J){if(!(this instanceof st)||!(J instanceof st))return!1;for(var X=this.$$.ptrType.registeredClass,fe=this.$$.ptr,Me=J.$$.ptrType.registeredClass,We=J.$$.ptr;X.baseClass;)fe=X.upcast(fe),X=X.baseClass;for(;Me.baseClass;)We=Me.upcast(We),Me=Me.baseClass;return X===Me&&fe===We}function Ha(J){return{count:J.count,deleteScheduled:J.deleteScheduled,preservePointerOnDelete:J.preservePointerOnDelete,ptr:J.ptr,ptrType:J.ptrType,smartPtr:J.smartPtr,smartPtrType:J.smartPtrType}}function Ea(J){function X(fe){return fe.$$.ptrType.registeredClass.name}sn(X(J)+" instance already deleted")}var To=!1;function ra(J){}function Uo(J){J.smartPtr?J.smartPtrType.rawDestructor(J.smartPtr):J.ptrType.registeredClass.rawDestructor(J.ptr)}function fr(J){J.count.value-=1;var X=J.count.value===0;X&&Uo(J)}function oo(J,X,fe){if(X===fe)return J;if(fe.baseClass===void 0)return null;var Me=oo(J,X,fe.baseClass);return Me===null?null:fe.downcast(Me)}var yn={};function Qr(){return Object.keys(Bo).length}function Da(){var J=[];for(var X in Bo)Bo.hasOwnProperty(X)&&J.push(Bo[X]);return J}var Fi=[];function ao(){for(;Fi.length;){var J=Fi.pop();J.$$.deleteScheduled=!1,J.delete()}}var Ui=void 0;function mi(J){Ui=J,Fi.length&&Ui&&Ui(ao)}function Ka(){o.getInheritedInstanceCount=Qr,o.getLiveInheritedInstances=Da,o.flushPendingDeletes=ao,o.setDelayFunction=mi}var Bo={};function Bi(J,X){for(X===void 0&&sn("ptr should not be undefined");J.baseClass;)X=J.upcast(X),J=J.baseClass;return X}function qa(J,X){return X=Bi(J,X),Bo[X]}function Gi(J,X){(!X.ptrType||!X.ptr)&&Xi("makeClassHandle requires ptr and ptrType");var fe=!!X.smartPtrType,Me=!!X.smartPtr;return fe!==Me&&Xi("Both smartPtrType and smartPtr must be specified"),X.count={value:1},de(Object.create(J,{$$:{value:X}}))}function ia(J){var X=this.getPointee(J);if(!X)return this.destructor(J),null;var fe=qa(this.registeredClass,X);if(fe!==void 0){if(fe.$$.count.value===0)return fe.$$.ptr=X,fe.$$.smartPtr=J,fe.clone();var Me=fe.clone();return this.destructor(J),Me}function We(){return this.isSmartPointer?Gi(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:X,smartPtrType:this,smartPtr:J}):Gi(this.registeredClass.instancePrototype,{ptrType:this,ptr:J})}var ct=this.registeredClass.getActualType(X),et=yn[ct];if(!et)return We.call(this);var Ye;this.isConst?Ye=et.constPointerType:Ye=et.pointerType;var $=oo(X,this.registeredClass,Ye.registeredClass);return $===null?We.call(this):this.isSmartPointer?Gi(Ye.registeredClass.instancePrototype,{ptrType:Ye,ptr:$,smartPtrType:this,smartPtr:J}):Gi(Ye.registeredClass.instancePrototype,{ptrType:Ye,ptr:$})}function de(J){return typeof FinalizationRegistry>"u"?(de=X=>X,J):(To=new FinalizationRegistry(X=>{fr(X.$$)}),de=X=>{var fe=X.$$,Me=!!fe.smartPtr;if(Me){var We={$$:fe};To.register(X,We,X)}return X},ra=X=>To.unregister(X),de(J))}function Ue(){if(this.$$.ptr||Ea(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var J=de(Object.create(Object.getPrototypeOf(this),{$$:{value:Ha(this.$$)}}));return J.$$.count.value+=1,J.$$.deleteScheduled=!1,J}function _e(){this.$$.ptr||Ea(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&sn("Object already scheduled for deletion"),ra(this),fr(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function ye(){return!this.$$.ptr}function je(){return this.$$.ptr||Ea(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&sn("Object already scheduled for deletion"),Fi.push(this),Fi.length===1&&Ui&&Ui(ao),this.$$.deleteScheduled=!0,this}function ot(){st.prototype.isAliasOf=Vi,st.prototype.clone=Ue,st.prototype.delete=_e,st.prototype.isDeleted=ye,st.prototype.deleteLater=je}function st(){}function ut(J,X,fe){if(J[X].overloadTable===void 0){var Me=J[X];J[X]=function(){return J[X].overloadTable.hasOwnProperty(arguments.length)||sn("Function '"+fe+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+J[X].overloadTable+")!"),J[X].overloadTable[arguments.length].apply(this,arguments)},J[X].overloadTable=[],J[X].overloadTable[Me.argCount]=Me}}function rt(J,X,fe){o.hasOwnProperty(J)?(sn("Cannot register public name '"+J+"' twice"),ut(o,J,J),o.hasOwnProperty(fe)&&sn("Cannot register multiple overloads of a function with the same number of arguments ("+fe+")!"),o[J].overloadTable[fe]=X):o[J]=X}function Ct(J,X,fe,Me,We,ct,et,Ye){this.name=J,this.constructor=X,this.instancePrototype=fe,this.rawDestructor=Me,this.baseClass=We,this.getActualType=ct,this.upcast=et,this.downcast=Ye,this.pureVirtualFunctions=[]}function Qt(J,X,fe){for(;X!==fe;)X.upcast||sn("Expected null or instance of "+fe.name+", got an instance of "+X.name),J=X.upcast(J),X=X.baseClass;return J}function on(J,X){if(X===null)return this.isReference&&sn("null is not a valid "+this.name),0;X.$$||sn('Cannot pass "'+fc(X)+'" as a '+this.name),X.$$.ptr||sn("Cannot pass deleted object as a pointer of type "+this.name);var fe=X.$$.ptrType.registeredClass,Me=Qt(X.$$.ptr,fe,this.registeredClass);return Me}function cn(J,X){var fe;if(X===null)return this.isReference&&sn("null is not a valid "+this.name),this.isSmartPointer?(fe=this.rawConstructor(),J!==null&&J.push(this.rawDestructor,fe),fe):0;X.$$||sn('Cannot pass "'+fc(X)+'" as a '+this.name),X.$$.ptr||sn("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&X.$$.ptrType.isConst&&sn("Cannot convert argument of type "+(X.$$.smartPtrType?X.$$.smartPtrType.name:X.$$.ptrType.name)+" to parameter type "+this.name);var Me=X.$$.ptrType.registeredClass;if(fe=Qt(X.$$.ptr,Me,this.registeredClass),this.isSmartPointer)switch(X.$$.smartPtr===void 0&&sn("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:X.$$.smartPtrType===this?fe=X.$$.smartPtr:sn("Cannot convert argument of type "+(X.$$.smartPtrType?X.$$.smartPtrType.name:X.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:fe=X.$$.smartPtr;break;case 2:if(X.$$.smartPtrType===this)fe=X.$$.smartPtr;else{var We=X.clone();fe=this.rawShare(fe,Wi.toHandle(function(){We.delete()})),J!==null&&J.push(this.rawDestructor,fe)}break;default:sn("Unsupporting sharing policy")}return fe}function Gt(J,X){if(X===null)return this.isReference&&sn("null is not a valid "+this.name),0;X.$$||sn('Cannot pass "'+fc(X)+'" as a '+this.name),X.$$.ptr||sn("Cannot pass deleted object as a pointer of type "+this.name),X.$$.ptrType.isConst&&sn("Cannot convert argument of type "+X.$$.ptrType.name+" to parameter type "+this.name);var fe=X.$$.ptrType.registeredClass,Me=Qt(X.$$.ptr,fe,this.registeredClass);return Me}function xn(J){return this.rawGetPointee&&(J=this.rawGetPointee(J)),J}function er(J){this.rawDestructor&&this.rawDestructor(J)}function nr(J){J!==null&&J.delete()}function or(){qn.prototype.getPointee=xn,qn.prototype.destructor=er,qn.prototype.argPackAdvance=8,qn.prototype.readValueFromPointer=nt,qn.prototype.deleteObject=nr,qn.prototype.fromWireType=ia}function qn(J,X,fe,Me,We,ct,et,Ye,$,H,R){this.name=J,this.registeredClass=X,this.isReference=fe,this.isConst=Me,this.isSmartPointer=We,this.pointeeType=ct,this.sharingPolicy=et,this.rawGetPointee=Ye,this.rawConstructor=$,this.rawShare=H,this.rawDestructor=R,!We&&X.baseClass===void 0?Me?(this.toWireType=on,this.destructorFunction=null):(this.toWireType=Gt,this.destructorFunction=null):this.toWireType=cn}function At(J,X,fe){o.hasOwnProperty(J)||Xi("Replacing nonexistant public symbol"),o[J].overloadTable!==void 0&&fe!==void 0||(o[J]=X,o[J].argCount=fe)}function Bn(J,X,fe){var Me=o["dynCall_"+J];return fe&&fe.length?Me.apply(null,[X].concat(fe)):Me.call(null,X)}var dr=[];function si(J){var X=dr[J];return X||(J>=dr.length&&(dr.length=J+1),dr[J]=X=pe.get(J)),X}function jn(J,X,fe){if(J.includes("j"))return Bn(J,X,fe);var Me=si(X).apply(null,fe);return Me}function wr(J,X){var fe=[];return function(){return fe.length=0,Object.assign(fe,arguments),jn(J,X,fe)}}function ei(J,X){J=Pt(J);function fe(){return J.includes("j")?wr(J,X):si(X)}var Me=fe();return typeof Me!="function"&&sn("unknown function pointer with signature "+J+": "+X),Me}var xr=void 0;function uc(J){var X=Qe(J),fe=Pt(X);return Ze(X),fe}function ba(J,X){var fe=[],Me={};function We(ct){if(!Me[ct]&&!Lt[ct]){if(xt[ct]){xt[ct].forEach(We);return}fe.push(ct),Me[ct]=!0}}throw X.forEach(We),new xr(J+": "+fe.map(uc).join([", "]))}function Yi(J,X,fe,Me,We,ct,et,Ye,$,H,R,U,q){R=Pt(R),ct=ei(We,ct),Ye&&(Ye=ei(et,Ye)),H&&(H=ei($,H)),q=ei(U,q);var le=Pn(R);rt(le,function(){ba("Cannot construct "+R+" due to unbound types",[Me])}),Mr([J,X,fe],Me?[Me]:[],function(he){he=he[0];var ve,Te;Me?(ve=he.registeredClass,Te=ve.instancePrototype):Te=st.prototype;var be=$n(le,function(){if(Object.getPrototypeOf(this)!==ke)throw new _n("Use 'new' to construct "+R);if(Je.constructor_body===void 0)throw new _n(R+" has no accessible constructor");var dn=Je.constructor_body[arguments.length];if(dn===void 0)throw new _n("Tried to invoke ctor of "+R+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(Je.constructor_body).toString()+") parameters instead!");return dn.apply(this,arguments)}),ke=Object.create(Te,{constructor:{value:be}});be.prototype=ke;var Je=new Ct(R,be,ke,q,ve,ct,Ye,H),pt=new qn(R,Je,!0,!1,!1),Mt=new qn(R+"*",Je,!1,!1,!1),Tt=new qn(R+" const*",Je,!1,!0,!1);return yn[J]={pointerType:Mt,constPointerType:Tt},At(le,be),[pt,Mt,Tt]})}function Xa(J,X){for(var fe=[],Me=0;Me>2]);return fe}function cl(J,X){if(!(J instanceof Function))throw new TypeError("new_ called with constructor type "+typeof J+" which is not a function");var fe=$n(J.name||"unknownFunctionName",function(){});fe.prototype=J.prototype;var Me=new fe,We=J.apply(Me,X);return We instanceof Object?We:Me}function ll(J,X,fe,Me,We){var ct=X.length;ct<2&&sn("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var et=X[1]!==null&&fe!==null,Ye=!1,$=1;${ft.hasOwnProperty(ve)?q[Te]=ft[ve]:(le.push(ve),Be.hasOwnProperty(ve)||(Be[ve]=[]),Be[ve].push(()=>{q[Te]=ft[ve],++he,he===le.length&&U(q)}))}),le.length===0&&U(q)}function Ha($){var H=bn[$];delete bn[$];var R=H.rawConstructor,U=H.rawDestructor,q=H.fields,le=q.map(he=>he.getterReturnType).concat(q.map(he=>he.setterArgumentType));Vi([$],le,he=>{var ve={};return q.forEach((Te,be)=>{var ke=Te.fieldName,Je=he[be],pt=Te.getter,Mt=Te.getterContext,Tt=he[be+q.length],dn=Te.setter,ln=Te.setterContext;ve[ke]={read:Xn=>Je.fromWireType(pt(Mt,Xn)),write:(Xn,li)=>{var yi=[];dn(ln,Xn,Tt.toWireType(yi,li)),Xi(yi)}}}),[{name:H.name,fromWireType:function(Te){var be={};for(var ke in ve)be[ke]=ve[ke].read(Te);return U(Te),be},toWireType:function(Te,be){for(var ke in ve)if(!(ke in be))throw new TypeError('Missing field: "'+ke+'"');var Je=R();for(ke in ve)ve[ke].write(Je,be[ke]);return Te!==null&&Te.push(U,Je),Je},argPackAdvance:8,readValueFromPointer:Mr,destructorFunction:U}]})}function Ea($,H,R,U,q){}function To($){switch($){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+$)}}function ra(){for(var $=new Array(256),H=0;H<256;++H)$[H]=String.fromCharCode(H);Uo=$}var Uo=void 0;function fr($){for(var H="",R=$;G[R];)H+=Uo[G[R++]];return H}var oo=void 0;function yn($){throw new oo($)}function Qr($,H,R={}){if(!("argPackAdvance"in H))throw new TypeError("registerType registeredInstance requires argPackAdvance");var U=H.name;if($||yn('type "'+U+'" must have a positive integer typeid pointer'),ft.hasOwnProperty($)){if(R.ignoreDuplicateRegistrations)return;yn("Cannot register type '"+U+"' twice")}if(ft[$]=H,delete Ut[$],Be.hasOwnProperty($)){var q=Be[$];delete Be[$],q.forEach(le=>le())}}function Da($,H,R,U,q){var le=To(R);H=fr(H),Qr($,{name:H,fromWireType:function(he){return!!he},toWireType:function(he,ve){return ve?U:q},argPackAdvance:8,readValueFromPointer:function(he){var ve;if(R===1)ve=V;else if(R===2)ve=A;else if(R===4)ve=F;else throw new TypeError("Unknown boolean type size: "+H);return this.fromWireType(ve[he>>le])},destructorFunction:null})}function Fi($){if(!(this instanceof or)||!($ instanceof or))return!1;for(var H=this.$$.ptrType.registeredClass,R=this.$$.ptr,U=$.$$.ptrType.registeredClass,q=$.$$.ptr;H.baseClass;)R=H.upcast(R),H=H.baseClass;for(;U.baseClass;)q=U.upcast(q),U=U.baseClass;return H===U&&R===q}function ao($){return{count:$.count,deleteScheduled:$.deleteScheduled,preservePointerOnDelete:$.preservePointerOnDelete,ptr:$.ptr,ptrType:$.ptrType,smartPtr:$.smartPtr,smartPtrType:$.smartPtrType}}function Ui($){function H(R){return R.$$.ptrType.registeredClass.name}yn(H($)+" instance already deleted")}var mi=!1;function Ka($){}function Bo($){$.smartPtr?$.smartPtrType.rawDestructor($.smartPtr):$.ptrType.registeredClass.rawDestructor($.ptr)}function Bi($){$.count.value-=1;var H=$.count.value===0;H&&Bo($)}function qa($,H,R){if(H===R)return $;if(R.baseClass===void 0)return null;var U=qa($,H,R.baseClass);return U===null?null:R.downcast(U)}var Gi={};function ia(){return Object.keys(st).length}function de(){var $=[];for(var H in st)st.hasOwnProperty(H)&&$.push(st[H]);return $}var Ue=[];function _e(){for(;Ue.length;){var $=Ue.pop();$.$$.deleteScheduled=!1,$.delete()}}var ye=void 0;function je($){ye=$,Ue.length&&ye&&ye(_e)}function ot(){o.getInheritedInstanceCount=ia,o.getLiveInheritedInstances=de,o.flushPendingDeletes=_e,o.setDelayFunction=je}var st={};function ut($,H){for(H===void 0&&yn("ptr should not be undefined");$.baseClass;)H=$.upcast(H),$=$.baseClass;return H}function rt($,H){return H=ut($,H),st[H]}function Ct($,H){(!H.ptrType||!H.ptr)&&pi("makeClassHandle requires ptr and ptrType");var R=!!H.smartPtrType,U=!!H.smartPtr;return R!==U&&pi("Both smartPtrType and smartPtr must be specified"),H.count={value:1},on(Object.create($,{$$:{value:H}}))}function Qt($){var H=this.getPointee($);if(!H)return this.destructor($),null;var R=rt(this.registeredClass,H);if(R!==void 0){if(R.$$.count.value===0)return R.$$.ptr=H,R.$$.smartPtr=$,R.clone();var U=R.clone();return this.destructor($),U}function q(){return this.isSmartPointer?Ct(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:H,smartPtrType:this,smartPtr:$}):Ct(this.registeredClass.instancePrototype,{ptrType:this,ptr:$})}var le=this.registeredClass.getActualType(H),he=Gi[le];if(!he)return q.call(this);var ve;this.isConst?ve=he.constPointerType:ve=he.pointerType;var Te=qa(H,this.registeredClass,ve.registeredClass);return Te===null?q.call(this):this.isSmartPointer?Ct(ve.registeredClass.instancePrototype,{ptrType:ve,ptr:Te,smartPtrType:this,smartPtr:$}):Ct(ve.registeredClass.instancePrototype,{ptrType:ve,ptr:Te})}function on($){return typeof FinalizationRegistry>"u"?(on=H=>H,$):(mi=new FinalizationRegistry(H=>{Bi(H.$$)}),on=H=>{var R=H.$$,U=!!R.smartPtr;if(U){var q={$$:R};mi.register(H,q,H)}return H},Ka=H=>mi.unregister(H),on($))}function cn(){if(this.$$.ptr||Ui(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var $=on(Object.create(Object.getPrototypeOf(this),{$$:{value:ao(this.$$)}}));return $.$$.count.value+=1,$.$$.deleteScheduled=!1,$}function Gt(){this.$$.ptr||Ui(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&yn("Object already scheduled for deletion"),Ka(this),Bi(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function xn(){return!this.$$.ptr}function er(){return this.$$.ptr||Ui(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&yn("Object already scheduled for deletion"),Ue.push(this),Ue.length===1&&ye&&ye(_e),this.$$.deleteScheduled=!0,this}function nr(){or.prototype.isAliasOf=Fi,or.prototype.clone=cn,or.prototype.delete=Gt,or.prototype.isDeleted=xn,or.prototype.deleteLater=er}function or(){}function qn($,H,R){if($[H].overloadTable===void 0){var U=$[H];$[H]=function(){return $[H].overloadTable.hasOwnProperty(arguments.length)||yn("Function '"+R+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+$[H].overloadTable+")!"),$[H].overloadTable[arguments.length].apply(this,arguments)},$[H].overloadTable=[],$[H].overloadTable[U.argCount]=U}}function Nt($,H,R){o.hasOwnProperty($)?((R===void 0||o[$].overloadTable!==void 0&&o[$].overloadTable[R]!==void 0)&&yn("Cannot register public name '"+$+"' twice"),qn(o,$,$),o.hasOwnProperty(R)&&yn("Cannot register multiple overloads of a function with the same number of arguments ("+R+")!"),o[$].overloadTable[R]=H):(o[$]=H,R!==void 0&&(o[$].numArguments=R))}function Bn($,H,R,U,q,le,he,ve){this.name=$,this.constructor=H,this.instancePrototype=R,this.rawDestructor=U,this.baseClass=q,this.getActualType=le,this.upcast=he,this.downcast=ve,this.pureVirtualFunctions=[]}function dr($,H,R){for(;H!==R;)H.upcast||yn("Expected null or instance of "+R.name+", got an instance of "+H.name),$=H.upcast($),H=H.baseClass;return $}function si($,H){if(H===null)return this.isReference&&yn("null is not a valid "+this.name),0;H.$$||yn('Cannot pass "'+dc(H)+'" as a '+this.name),H.$$.ptr||yn("Cannot pass deleted object as a pointer of type "+this.name);var R=H.$$.ptrType.registeredClass,U=dr(H.$$.ptr,R,this.registeredClass);return U}function jn($,H){var R;if(H===null)return this.isReference&&yn("null is not a valid "+this.name),this.isSmartPointer?(R=this.rawConstructor(),$!==null&&$.push(this.rawDestructor,R),R):0;H.$$||yn('Cannot pass "'+dc(H)+'" as a '+this.name),H.$$.ptr||yn("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&H.$$.ptrType.isConst&&yn("Cannot convert argument of type "+(H.$$.smartPtrType?H.$$.smartPtrType.name:H.$$.ptrType.name)+" to parameter type "+this.name);var U=H.$$.ptrType.registeredClass;if(R=dr(H.$$.ptr,U,this.registeredClass),this.isSmartPointer)switch(H.$$.smartPtr===void 0&&yn("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:H.$$.smartPtrType===this?R=H.$$.smartPtr:yn("Cannot convert argument of type "+(H.$$.smartPtrType?H.$$.smartPtrType.name:H.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:R=H.$$.smartPtr;break;case 2:if(H.$$.smartPtrType===this)R=H.$$.smartPtr;else{var q=H.clone();R=this.rawShare(R,Za.toHandle(function(){q.delete()})),$!==null&&$.push(this.rawDestructor,R)}break;default:yn("Unsupporting sharing policy")}return R}function wr($,H){if(H===null)return this.isReference&&yn("null is not a valid "+this.name),0;H.$$||yn('Cannot pass "'+dc(H)+'" as a '+this.name),H.$$.ptr||yn("Cannot pass deleted object as a pointer of type "+this.name),H.$$.ptrType.isConst&&yn("Cannot convert argument of type "+H.$$.ptrType.name+" to parameter type "+this.name);var R=H.$$.ptrType.registeredClass,U=dr(H.$$.ptr,R,this.registeredClass);return U}function ei($){return this.rawGetPointee&&($=this.rawGetPointee($)),$}function xr($){this.rawDestructor&&this.rawDestructor($)}function uc($){$!==null&&$.delete()}function ba(){Yi.prototype.getPointee=ei,Yi.prototype.destructor=xr,Yi.prototype.argPackAdvance=8,Yi.prototype.readValueFromPointer=Mr,Yi.prototype.deleteObject=uc,Yi.prototype.fromWireType=Qt}function Yi($,H,R,U,q,le,he,ve,Te,be,ke){this.name=$,this.registeredClass=H,this.isReference=R,this.isConst=U,this.isSmartPointer=q,this.pointeeType=le,this.sharingPolicy=he,this.rawGetPointee=ve,this.rawConstructor=Te,this.rawShare=be,this.rawDestructor=ke,!q&&H.baseClass===void 0?U?(this.toWireType=si,this.destructorFunction=null):(this.toWireType=wr,this.destructorFunction=null):this.toWireType=jn}function Xa($,H,R){o.hasOwnProperty($)||pi("Replacing nonexistant public symbol"),o[$].overloadTable!==void 0&&R!==void 0?o[$].overloadTable[R]=H:(o[$]=H,o[$].argCount=R)}function cl($,H,R){var U=o["dynCall_"+$];return R&&R.length?U.apply(null,[H].concat(R)):U.call(null,H)}function ll($,H,R){if($.includes("j"))return cl($,H,R);var U=dt(H).apply(null,R);return U}function bs($,H){var R=[];return function(){return R.length=0,Object.assign(R,arguments),ll($,H,R)}}function gr($,H){$=fr($);function R(){return $.includes("j")?bs($,H):dt(H)}var U=R();return typeof U!="function"&&yn("unknown function pointer with signature "+$+": "+H),U}var Ya=void 0;function vi($){var H=He($),R=fr(H);return me(H),R}function ci($,H){var R=[],U={};function q(le){if(!U[le]&&!ft[le]){if(Ut[le]){Ut[le].forEach(q);return}R.push(le),U[le]=!0}}throw H.forEach(q),new Ya($+": "+R.map(vi).join([", "]))}function ul($,H,R,U,q,le,he,ve,Te,be,ke,Je,pt){ke=fr(ke),le=gr(q,le),ve&&(ve=gr(he,ve)),be&&(be=gr(Te,be)),pt=gr(Je,pt);var Mt=Pt(ke);Nt(Mt,function(){ci("Cannot construct "+ke+" due to unbound types",[U])}),Vi([$,H,R],U?[U]:[],function(Tt){Tt=Tt[0];var dn,ln;U?(dn=Tt.registeredClass,ln=dn.instancePrototype):ln=or.prototype;var Xn=_n(Mt,function(){if(Object.getPrototypeOf(this)!==li)throw new oo("Use 'new' to construct "+ke);if(yi.constructor_body===void 0)throw new oo(ke+" has no accessible constructor");var Ih=yi.constructor_body[arguments.length];if(Ih===void 0)throw new oo("Tried to invoke ctor of "+ke+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(yi.constructor_body).toString()+") parameters instead!");return Ih.apply(this,arguments)}),li=Object.create(ln,{constructor:{value:Xn}});Xn.prototype=li;var yi=new Bn(ke,Xn,li,pt,dn,le,ve,be),rf=new Yi(ke,yi,!0,!1,!1),Oa=new Yi(ke+"*",yi,!1,!1,!1),U1=new Yi(ke+" const*",yi,!1,!0,!1);return Gi[$]={pointerType:Oa,constPointerType:U1},Xa(Mt,Xn),[rf,Oa,U1]})}function so($,H){for(var R=[],U=0;U<$;U++)R.push(j[H+U*4>>2]);return R}function Uu($,H){if(!($ instanceof Function))throw new TypeError("new_ called with constructor type "+typeof $+" which is not a function");var R=_n($.name||"unknownFunctionName",function(){});R.prototype=$.prototype;var U=new R,q=$.apply(U,H);return q instanceof Object?q:U}function Wi($,H,R,U,q){var le=H.length;le<2&&yn("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var he=H[1]!==null&&R!==null,ve=!1,Te=1;Te{ft.hasOwnProperty(ve)?q[Te]=ft[ve]:(le.push(ve),Be.hasOwnProperty(ve)||(Be[ve]=[]),Be[ve].push(()=>{q[Te]=ft[ve],++he,he===le.length&&U(q)}))}),le.length===0&&U(q)}function Ha($){var H=bn[$];delete bn[$];var R=H.rawConstructor,U=H.rawDestructor,q=H.fields,le=q.map(he=>he.getterReturnType).concat(q.map(he=>he.setterArgumentType));Vi([$],le,he=>{var ve={};return q.forEach((Te,be)=>{var ke=Te.fieldName,Je=he[be],pt=Te.getter,Mt=Te.getterContext,Tt=he[be+q.length],dn=Te.setter,ln=Te.setterContext;ve[ke]={read:Xn=>Je.fromWireType(pt(Mt,Xn)),write:(Xn,li)=>{var yi=[];dn(ln,Xn,Tt.toWireType(yi,li)),Xi(yi)}}}),[{name:H.name,fromWireType:function(Te){var be={};for(var ke in ve)be[ke]=ve[ke].read(Te);return U(Te),be},toWireType:function(Te,be){for(var ke in ve)if(!(ke in be))throw new TypeError('Missing field: "'+ke+'"');var Je=R();for(ke in ve)ve[ke].write(Je,be[ke]);return Te!==null&&Te.push(U,Je),Je},argPackAdvance:8,readValueFromPointer:Mr,destructorFunction:U}]})}function Ea($,H,R,U,q){}function To($){switch($){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+$)}}function ra(){for(var $=new Array(256),H=0;H<256;++H)$[H]=String.fromCharCode(H);Uo=$}var Uo=void 0;function fr($){for(var H="",R=$;G[R];)H+=Uo[G[R++]];return H}var oo=void 0;function yn($){throw new oo($)}function Qr($,H,R={}){if(!("argPackAdvance"in H))throw new TypeError("registerType registeredInstance requires argPackAdvance");var U=H.name;if($||yn('type "'+U+'" must have a positive integer typeid pointer'),ft.hasOwnProperty($)){if(R.ignoreDuplicateRegistrations)return;yn("Cannot register type '"+U+"' twice")}if(ft[$]=H,delete Ut[$],Be.hasOwnProperty($)){var q=Be[$];delete Be[$],q.forEach(le=>le())}}function Da($,H,R,U,q){var le=To(R);H=fr(H),Qr($,{name:H,fromWireType:function(he){return!!he},toWireType:function(he,ve){return ve?U:q},argPackAdvance:8,readValueFromPointer:function(he){var ve;if(R===1)ve=V;else if(R===2)ve=A;else if(R===4)ve=F;else throw new TypeError("Unknown boolean type size: "+H);return this.fromWireType(ve[he>>le])},destructorFunction:null})}function Fi($){if(!(this instanceof or)||!($ instanceof or))return!1;for(var H=this.$$.ptrType.registeredClass,R=this.$$.ptr,U=$.$$.ptrType.registeredClass,q=$.$$.ptr;H.baseClass;)R=H.upcast(R),H=H.baseClass;for(;U.baseClass;)q=U.upcast(q),U=U.baseClass;return H===U&&R===q}function ao($){return{count:$.count,deleteScheduled:$.deleteScheduled,preservePointerOnDelete:$.preservePointerOnDelete,ptr:$.ptr,ptrType:$.ptrType,smartPtr:$.smartPtr,smartPtrType:$.smartPtrType}}function Ui($){function H(R){return R.$$.ptrType.registeredClass.name}yn(H($)+" instance already deleted")}var mi=!1;function Ka($){}function Bo($){$.smartPtr?$.smartPtrType.rawDestructor($.smartPtr):$.ptrType.registeredClass.rawDestructor($.ptr)}function Bi($){$.count.value-=1;var H=$.count.value===0;H&&Bo($)}function qa($,H,R){if(H===R)return $;if(R.baseClass===void 0)return null;var U=qa($,H,R.baseClass);return U===null?null:R.downcast(U)}var Gi={};function ia(){return Object.keys(st).length}function de(){var $=[];for(var H in st)st.hasOwnProperty(H)&&$.push(st[H]);return $}var Ue=[];function _e(){for(;Ue.length;){var $=Ue.pop();$.$$.deleteScheduled=!1,$.delete()}}var ye=void 0;function je($){ye=$,Ue.length&&ye&&ye(_e)}function ot(){o.getInheritedInstanceCount=ia,o.getLiveInheritedInstances=de,o.flushPendingDeletes=_e,o.setDelayFunction=je}var st={};function ut($,H){for(H===void 0&&yn("ptr should not be undefined");$.baseClass;)H=$.upcast(H),$=$.baseClass;return H}function rt($,H){return H=ut($,H),st[H]}function Ct($,H){(!H.ptrType||!H.ptr)&&pi("makeClassHandle requires ptr and ptrType");var R=!!H.smartPtrType,U=!!H.smartPtr;return R!==U&&pi("Both smartPtrType and smartPtr must be specified"),H.count={value:1},on(Object.create($,{$$:{value:H}}))}function Qt($){var H=this.getPointee($);if(!H)return this.destructor($),null;var R=rt(this.registeredClass,H);if(R!==void 0){if(R.$$.count.value===0)return R.$$.ptr=H,R.$$.smartPtr=$,R.clone();var U=R.clone();return this.destructor($),U}function q(){return this.isSmartPointer?Ct(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:H,smartPtrType:this,smartPtr:$}):Ct(this.registeredClass.instancePrototype,{ptrType:this,ptr:$})}var le=this.registeredClass.getActualType(H),he=Gi[le];if(!he)return q.call(this);var ve;this.isConst?ve=he.constPointerType:ve=he.pointerType;var Te=qa(H,this.registeredClass,ve.registeredClass);return Te===null?q.call(this):this.isSmartPointer?Ct(ve.registeredClass.instancePrototype,{ptrType:ve,ptr:Te,smartPtrType:this,smartPtr:$}):Ct(ve.registeredClass.instancePrototype,{ptrType:ve,ptr:Te})}function on($){return typeof FinalizationRegistry>"u"?(on=H=>H,$):(mi=new FinalizationRegistry(H=>{Bi(H.$$)}),on=H=>{var R=H.$$,U=!!R.smartPtr;if(U){var q={$$:R};mi.register(H,q,H)}return H},Ka=H=>mi.unregister(H),on($))}function cn(){if(this.$$.ptr||Ui(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var $=on(Object.create(Object.getPrototypeOf(this),{$$:{value:ao(this.$$)}}));return $.$$.count.value+=1,$.$$.deleteScheduled=!1,$}function Gt(){this.$$.ptr||Ui(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&yn("Object already scheduled for deletion"),Ka(this),Bi(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function xn(){return!this.$$.ptr}function er(){return this.$$.ptr||Ui(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&yn("Object already scheduled for deletion"),Ue.push(this),Ue.length===1&&ye&&ye(_e),this.$$.deleteScheduled=!0,this}function nr(){or.prototype.isAliasOf=Fi,or.prototype.clone=cn,or.prototype.delete=Gt,or.prototype.isDeleted=xn,or.prototype.deleteLater=er}function or(){}function qn($,H,R){if($[H].overloadTable===void 0){var U=$[H];$[H]=function(){return $[H].overloadTable.hasOwnProperty(arguments.length)||yn("Function '"+R+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+$[H].overloadTable+")!"),$[H].overloadTable[arguments.length].apply(this,arguments)},$[H].overloadTable=[],$[H].overloadTable[U.argCount]=U}}function At($,H,R){o.hasOwnProperty($)?((R===void 0||o[$].overloadTable!==void 0&&o[$].overloadTable[R]!==void 0)&&yn("Cannot register public name '"+$+"' twice"),qn(o,$,$),o.hasOwnProperty(R)&&yn("Cannot register multiple overloads of a function with the same number of arguments ("+R+")!"),o[$].overloadTable[R]=H):(o[$]=H,R!==void 0&&(o[$].numArguments=R))}function Bn($,H,R,U,q,le,he,ve){this.name=$,this.constructor=H,this.instancePrototype=R,this.rawDestructor=U,this.baseClass=q,this.getActualType=le,this.upcast=he,this.downcast=ve,this.pureVirtualFunctions=[]}function dr($,H,R){for(;H!==R;)H.upcast||yn("Expected null or instance of "+R.name+", got an instance of "+H.name),$=H.upcast($),H=H.baseClass;return $}function si($,H){if(H===null)return this.isReference&&yn("null is not a valid "+this.name),0;H.$$||yn('Cannot pass "'+dc(H)+'" as a '+this.name),H.$$.ptr||yn("Cannot pass deleted object as a pointer of type "+this.name);var R=H.$$.ptrType.registeredClass,U=dr(H.$$.ptr,R,this.registeredClass);return U}function jn($,H){var R;if(H===null)return this.isReference&&yn("null is not a valid "+this.name),this.isSmartPointer?(R=this.rawConstructor(),$!==null&&$.push(this.rawDestructor,R),R):0;H.$$||yn('Cannot pass "'+dc(H)+'" as a '+this.name),H.$$.ptr||yn("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&H.$$.ptrType.isConst&&yn("Cannot convert argument of type "+(H.$$.smartPtrType?H.$$.smartPtrType.name:H.$$.ptrType.name)+" to parameter type "+this.name);var U=H.$$.ptrType.registeredClass;if(R=dr(H.$$.ptr,U,this.registeredClass),this.isSmartPointer)switch(H.$$.smartPtr===void 0&&yn("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:H.$$.smartPtrType===this?R=H.$$.smartPtr:yn("Cannot convert argument of type "+(H.$$.smartPtrType?H.$$.smartPtrType.name:H.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:R=H.$$.smartPtr;break;case 2:if(H.$$.smartPtrType===this)R=H.$$.smartPtr;else{var q=H.clone();R=this.rawShare(R,Za.toHandle(function(){q.delete()})),$!==null&&$.push(this.rawDestructor,R)}break;default:yn("Unsupporting sharing policy")}return R}function wr($,H){if(H===null)return this.isReference&&yn("null is not a valid "+this.name),0;H.$$||yn('Cannot pass "'+dc(H)+'" as a '+this.name),H.$$.ptr||yn("Cannot pass deleted object as a pointer of type "+this.name),H.$$.ptrType.isConst&&yn("Cannot convert argument of type "+H.$$.ptrType.name+" to parameter type "+this.name);var R=H.$$.ptrType.registeredClass,U=dr(H.$$.ptr,R,this.registeredClass);return U}function ei($){return this.rawGetPointee&&($=this.rawGetPointee($)),$}function xr($){this.rawDestructor&&this.rawDestructor($)}function uc($){$!==null&&$.delete()}function ba(){Yi.prototype.getPointee=ei,Yi.prototype.destructor=xr,Yi.prototype.argPackAdvance=8,Yi.prototype.readValueFromPointer=Mr,Yi.prototype.deleteObject=uc,Yi.prototype.fromWireType=Qt}function Yi($,H,R,U,q,le,he,ve,Te,be,ke){this.name=$,this.registeredClass=H,this.isReference=R,this.isConst=U,this.isSmartPointer=q,this.pointeeType=le,this.sharingPolicy=he,this.rawGetPointee=ve,this.rawConstructor=Te,this.rawShare=be,this.rawDestructor=ke,!q&&H.baseClass===void 0?U?(this.toWireType=si,this.destructorFunction=null):(this.toWireType=wr,this.destructorFunction=null):this.toWireType=jn}function Xa($,H,R){o.hasOwnProperty($)||pi("Replacing nonexistant public symbol"),o[$].overloadTable!==void 0&&R!==void 0?o[$].overloadTable[R]=H:(o[$]=H,o[$].argCount=R)}function cl($,H,R){var U=o["dynCall_"+$];return R&&R.length?U.apply(null,[H].concat(R)):U.call(null,H)}function ll($,H,R){if($.includes("j"))return cl($,H,R);var U=dt(H).apply(null,R);return U}function bs($,H){var R=[];return function(){return R.length=0,Object.assign(R,arguments),ll($,H,R)}}function gr($,H){$=fr($);function R(){return $.includes("j")?bs($,H):dt(H)}var U=R();return typeof U!="function"&&yn("unknown function pointer with signature "+$+": "+H),U}var Ya=void 0;function vi($){var H=He($),R=fr(H);return me(H),R}function ci($,H){var R=[],U={};function q(le){if(!U[le]&&!ft[le]){if(Ut[le]){Ut[le].forEach(q);return}R.push(le),U[le]=!0}}throw H.forEach(q),new Ya($+": "+R.map(vi).join([", "]))}function ul($,H,R,U,q,le,he,ve,Te,be,ke,Je,pt){ke=fr(ke),le=gr(q,le),ve&&(ve=gr(he,ve)),be&&(be=gr(Te,be)),pt=gr(Je,pt);var Mt=Pt(ke);At(Mt,function(){ci("Cannot construct "+ke+" due to unbound types",[U])}),Vi([$,H,R],U?[U]:[],function(Tt){Tt=Tt[0];var dn,ln;U?(dn=Tt.registeredClass,ln=dn.instancePrototype):ln=or.prototype;var Xn=_n(Mt,function(){if(Object.getPrototypeOf(this)!==li)throw new oo("Use 'new' to construct "+ke);if(yi.constructor_body===void 0)throw new oo(ke+" has no accessible constructor");var Ih=yi.constructor_body[arguments.length];if(Ih===void 0)throw new oo("Tried to invoke ctor of "+ke+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(yi.constructor_body).toString()+") parameters instead!");return Ih.apply(this,arguments)}),li=Object.create(ln,{constructor:{value:Xn}});Xn.prototype=li;var yi=new Bn(ke,Xn,li,pt,dn,le,ve,be),rf=new Yi(ke,yi,!0,!1,!1),Oa=new Yi(ke+"*",yi,!1,!1,!1),U1=new Yi(ke+" const*",yi,!1,!0,!1);return Gi[$]={pointerType:Oa,constPointerType:U1},Xa(Mt,Xn),[rf,Oa,U1]})}function so($,H){for(var R=[],U=0;U<$;U++)R.push(j[H+U*4>>2]);return R}function Uu($,H){if(!($ instanceof Function))throw new TypeError("new_ called with constructor type "+typeof $+" which is not a function");var R=_n($.name||"unknownFunctionName",function(){});R.prototype=$.prototype;var U=new R,q=$.apply(U,H);return q instanceof Object?q:U}function Wi($,H,R,U,q){var le=H.length;le<2&&yn("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var he=H[1]!==null&&R!==null,ve=!1,Te=1;Te0);var he=so(H,R);q=gr(U,q),Vi([],[$],function(ve){ve=ve[0];var Te="constructor "+ve.name;if(ve.registeredClass.constructor_body===void 0&&(ve.registeredClass.constructor_body=[]),ve.registeredClass.constructor_body[H-1]!==void 0)throw new oo("Cannot register multiple constructors with identical number of parameters ("+(H-1)+") for class '"+ve.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");return ve.registeredClass.constructor_body[H-1]=()=>{ci("Cannot construct "+ve.name+" due to unbound types",he)},Vi([],he,function(be){return be.splice(1,0,null),ve.registeredClass.constructor_body[H-1]=Wi(Te,be,null,q,le),[]}),[]})}function fc($,H,R,U,q,le,he,ve){var Te=so(R,U);H=fr(H),le=gr(q,le),Vi([],[$],function(be){be=be[0];var ke=be.name+"."+H;H.startsWith("@@")&&(H=Symbol[H.substring(2)]),ve&&be.registeredClass.pureVirtualFunctions.push(H);function Je(){ci("Cannot call "+ke+" due to unbound types",Te)}var pt=be.registeredClass.instancePrototype,Mt=pt[H];return Mt===void 0||Mt.overloadTable===void 0&&Mt.className!==be.name&&Mt.argCount===R-2?(Je.argCount=R-2,Je.className=be.name,pt[H]=Je):(qn(pt,H,ke),pt[H].overloadTable[R-2]=Je),Vi([],Te,function(Tt){var dn=Wi(ke,Tt,be,le,he);return pt[H].overloadTable===void 0?(dn.argCount=R-2,pt[H]=dn):pt[H].overloadTable[R-2]=dn,[]}),[]})}var Ja=[],Ji=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function fl($){$>4&&--Ji[$].refcount===0&&(Ji[$]=void 0,Ja.push($))}function Bu(){for(var $=0,H=5;H($||yn("Cannot use deleted val. handle = "+$),Ji[$].value),toHandle:$=>{switch($){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:{var H=Ja.length?Ja.pop():Ji.length;return Ji[H]={refcount:1,value:$},H}}}};function hl($,H){H=fr(H),Qr($,{name:H,fromWireType:function(R){var U=Za.toValue(R);return fl(R),U},toWireType:function(R,U){return Za.toHandle(U)},argPackAdvance:8,readValueFromPointer:Mr,destructorFunction:null})}function dc($){if($===null)return"null";var H=typeof $;return H==="object"||H==="array"||H==="function"?$.toString():""+$}function Wu($,H){switch(H){case 2:return function(R){return this.fromWireType(Y[R>>2])};case 3:return function(R){return this.fromWireType(re[R>>3])};default:throw new TypeError("Unknown float type: "+$)}}function zu($,H,R){var U=To(R);H=fr(H),Qr($,{name:H,fromWireType:function(q){return q},toWireType:function(q,le){return le},argPackAdvance:8,readValueFromPointer:Wu(H,U),destructorFunction:null})}function $u($,H,R,U,q,le){var he=so(H,R);$=fr($),q=gr(U,q),Nt($,function(){ci("Cannot call "+$+" due to unbound types",he)},H-1),Vi([],he,function(ve){var Te=[ve[0],null].concat(ve.slice(1));return Xa($,Wi($,Te,null,q,le),H-1),[]})}function ju($,H,R){switch(H){case 0:return R?function(q){return V[q]}:function(q){return G[q]};case 1:return R?function(q){return A[q>>1]}:function(q){return k[q>>1]};case 2:return R?function(q){return F[q>>2]}:function(q){return j[q>>2]};default:throw new TypeError("Unknown integer type: "+$)}}function Hu($,H,R,U,q){H=fr(H);var le=To(R),he=Je=>Je;if(U===0){var ve=32-8*R;he=Je=>Je<>>ve}var Te=H.includes("unsigned"),be=(Je,pt)=>{},ke;Te?ke=function(Je,pt){return be(pt,this.name),pt>>>0}:ke=function(Je,pt){return be(pt,this.name),pt},Qr($,{name:H,fromWireType:he,toWireType:ke,argPackAdvance:8,readValueFromPointer:ju(H,le,U!==0),destructorFunction:null})}function Ku($,H,R){var U=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],q=U[H];function le(he){he=he>>2;var ve=j,Te=ve[he],be=ve[he+1];return new q(L,be,Te)}R=fr(R),Qr($,{name:R,fromWireType:le,argPackAdvance:8,readValueFromPointer:le},{ignoreDuplicateRegistrations:!0})}function qu($,H){H=fr(H);var R=H==="std::string";Qr($,{name:H,fromWireType:function(U){var q=j[U>>2],le=U+4,he;if(R)for(var ve=le,Te=0;Te<=q;++Te){var be=le+Te;if(Te==q||G[be]==0){var ke=be-ve,Je=b(ve,ke);he===void 0?he=Je:(he+="\0",he+=Je),ve=be+1}}else{for(var pt=new Array(q),Te=0;Te>2]=le,R&&he)P(q,Te,le+1);else if(he)for(var be=0;be255&&(me(Te),yn("String has UTF-16 code units that do not fit in 8 bits")),G[Te+be]=ke}else for(var be=0;be>1,q=U+H/2;!(U>=q)&&k[U];)++U;if(R=U<<1,R-$>32&&gl)return gl.decode(G.subarray($,R));for(var le="",he=0;!(he>=H/2);++he){var ve=A[$+he*2>>1];if(ve==0)break;le+=String.fromCharCode(ve)}return le}function pl($,H,R){if(R===void 0&&(R=2147483647),R<2)return 0;R-=2;for(var U=H,q=R<$.length*2?R/2:$.length,le=0;le>1]=he,H+=2}return A[H>>1]=0,H-U}function ml($){return $.length*2}function Yu($,H){for(var R=0,U="";!(R>=H/4);){var q=F[$+R*4>>2];if(q==0)break;if(++R,q>=65536){var le=q-65536;U+=String.fromCharCode(55296|le>>10,56320|le&1023)}else U+=String.fromCharCode(q)}return U}function hc($,H,R){if(R===void 0&&(R=2147483647),R<4)return 0;for(var U=H,q=U+R-4,le=0;le<$.length;++le){var he=$.charCodeAt(le);if(he>=55296&&he<=57343){var ve=$.charCodeAt(++le);he=65536+((he&1023)<<10)|ve&1023}if(F[H>>2]=he,H+=4,H+4>q)break}return F[H>>2]=0,H-U}function vl($){for(var H=0,R=0;R<$.length;++R){var U=$.charCodeAt(R);U>=55296&&U<=57343&&++R,H+=4}return H}function yl($,H,R){R=fr(R);var U,q,le,he,ve;H===2?(U=Xu,q=pl,he=ml,le=()=>k,ve=1):H===4&&(U=Yu,q=hc,he=vl,le=()=>j,ve=2),Qr($,{name:R,fromWireType:function(Te){for(var be=j[Te>>2],ke=le(),Je,pt=Te+4,Mt=0;Mt<=be;++Mt){var Tt=Te+4+Mt*H;if(Mt==be||ke[Tt>>ve]==0){var dn=Tt-pt,ln=U(pt,dn);Je===void 0?Je=ln:(Je+="\0",Je+=ln),pt=Tt+H}}return me(Te),Je},toWireType:function(Te,be){typeof be!="string"&&yn("Cannot pass non-string to C++ string type "+R);var ke=he(be),Je=te(4+ke+H);return j[Je>>2]=ke>>ve,q(be,Je+4,ke+H),Te!==null&&Te.push(me,Je),Je},argPackAdvance:8,readValueFromPointer:Mr,destructorFunction:function(Te){me(Te)}})}function gc($,H,R,U,q,le){bn[$]={name:fr(H),rawConstructor:gr(R,U),rawDestructor:gr(q,le),fields:[]}}function Ju($,H,R,U,q,le,he,ve,Te,be){bn[$].fields.push({fieldName:fr(H),getterReturnType:R,getter:gr(U,q),getterContext:le,setterArgumentType:he,setter:gr(ve,Te),setterContext:be})}function wl($,H){H=fr(H),Qr($,{isVoid:!0,name:H,argPackAdvance:0,fromWireType:function(){},toWireType:function(R,U){}})}function Zu($){$>4&&(Ji[$].refcount+=1)}function xl($,H){var R=ft[$];return R===void 0&&yn(H+" has unknown type "+vi($)),R}function Qu($,H){$=xl($,"_emval_take_value");var R=$.readValueFromPointer(H);return Za.toHandle(R)}function ef(){Ne("")}function tf($,H,R){G.copyWithin($,H,H+R)}function nf(){return 2147483648}function pc($){try{return S.grow($-L.byteLength+65535>>>16),ue(S.buffer),1}catch{}}function mc($){var H=G.length;$=$>>>0;var R=nf();if($>R)return!1;let U=(Te,be)=>Te+(be-Te%be)%be;for(var q=1;q<=4;q*=2){var le=H*(1+.2/q);le=Math.min(le,$+100663296);var he=Math.min(R,U(Math.max($,le),65536)),ve=pc(he);if(ve)return!0}return!1}function oa($){return 52}function Ia($,H,R,U,q){return 70}var Eo=[null,[],[]];function Cl($,H){var R=Eo[$];H===0||H===10?(($===1?w:x)(D(R,0)),R.length=0):R.push(H)}function Sl($,H,R,U){for(var q=0,le=0;le>2],ve=j[H+4>>2];H+=8;for(var Te=0;Te>2]=q,0}function vc($){return $}function _l($){var H=o["_"+$];return H}function Is($,H){V.set($,H)}function Tl($,H,R,U,q){var le={string:Tt=>{var dn=0;if(Tt!=null&&Tt!==0){var ln=(Tt.length<<2)+1;dn=it(ln),P(Tt,dn,ln)}return dn},array:Tt=>{var dn=it(Tt.length);return Is(Tt,dn),dn}};function he(Tt){return H==="string"?b(Tt):H==="boolean"?!!Tt:Tt}var ve=_l($),Te=[],be=0;if(U)for(var ke=0;ke0||(Se(),Z>0))return;function H(){et||(et=!0,o.calledRun=!0,!_&&(B(),a(o),o.onRuntimeInitialized&&o.onRuntimeInitialized(),O()))}o.setStatus?(o.setStatus("Running..."),setTimeout(function(){setTimeout(function(){o.setStatus("")},1),H()},1)):H()}if(o.preInit)for(typeof o.preInit=="function"&&(o.preInit=[o.preInit]);o.preInit.length>0;)o.preInit.pop()();return Ye(),o.ready}})();t.exports=r})(cG);var Mxe=cG.exports;const Pxe=ac(Mxe),Rxe=new URL("/static/dv3d/openjphjs.wasm",import.meta.url),Sg={codec:void 0,decoder:void 0,decodeConfig:{}};function Lxe(t,e,r){const n={width:e,height:r};for(;t>0;)n.width=Math.ceil(n.width/2),n.height=Math.ceil(n.height/2),t--;return n}function Axe(t){if(Sg.decodeConfig=t,Sg.codec)return Promise.resolve();const e=Pxe({locateFile:r=>r.endsWith(".wasm")?Rxe.toString():r});return new Promise((r,n)=>{e.then(i=>{Sg.codec=i,Sg.decoder=new i.HTJ2KDecoder,r()},n)})}async function Nxe(t,e){await Axe();const r=new Sg.codec.HTJ2KDecoder,n=r.getEncodedBuffer(t.length);n.set(t);const i=e.decodeLevel||0;r.decodeSubResolution(i);const o=r.getFrameInfo();if(e.decodeLevel>0){const{width:E,height:D}=Lxe(e.decodeLevel,o.width,o.height);o.width=E,o.height=D}const a=r.getDecodedBuffer();new Uint8Array(a.length).set(a);const c=`x: ${r.getImageOffset().x}, y: ${r.getImageOffset().y}`,l=r.getNumDecompositions(),f=r.getNumLayers(),u=["unknown","LRCP","RLCP","RPCL","PCRL","CPRL"][r.getProgressionOrder()+1],d=r.getIsReversible(),h=`${r.getBlockDimensions().width} x ${r.getBlockDimensions().height}`,g=`${r.getTileSize().width} x ${r.getTileSize().height}`,p=`${r.getTileOffset().x}, ${r.getTileOffset().y}`,v=`${a.length.toLocaleString()} bytes`,y=`${(a.length/n.length).toFixed(2)}:1`,m={columns:o.width,rows:o.height,bitsPerPixel:o.bitsPerSample,signed:o.isSigned,bytesPerPixel:e.bytesPerPixel,componentsPerPixel:o.componentCount};let w=kxe(o,a);const{buffer:x,byteOffset:C,byteLength:S}=w,_=x.slice(C,C+S);w=new w.constructor(_);const T={imageOffset:c,numDecompositions:l,numLayers:f,progessionOrder:u,reversible:d,blockDimensions:h,tileSize:g,tileOffset:p,decodedSize:v,compressionRatio:y};return{...e,pixelData:w,imageInfo:m,encodeOptions:T,...T,...m}}function kxe(t,e){return t.bitsPerSample>8?t.isSigned?new Int16Array(e.buffer,e.byteOffset,e.byteLength/2):new Uint16Array(e.buffer,e.byteOffset,e.byteLength/2):t.isSigned?new Int8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function Vxe(t,e){const r=t.length,{rescaleSlope:n,rescaleIntercept:i,suvbw:o,doseGridScaling:a}=e;if(e.modality==="PT"&&typeof o=="number"&&!isNaN(o))for(let s=0;s>o;let a=t.pixelData;t.pixelDataLength=t.pixelData.length;const{min:s,max:c}=X5(t.pixelData),l=typeof e.allowFloatRendering<"u"?e.allowFloatRendering:!0;let f=dE(t.photometricInterpretation)&&((m=e.targetBuffer)==null?void 0:m.offset)===void 0;const d=((w=e.preScale)==null?void 0:w.enabled)&&Object.values(e.preScale.scalingParameters).some(C=>typeof C=="number"&&!Number.isInteger(C)),h=!e.preScale.enabled||!l&&d,g=(x=e.targetBuffer)==null?void 0:x.type;if(g&&e.preScale.enabled&&!h){const C=e.preScale.scalingParameters,S=sS(s,c,C);f=!v3e(S.min,S.max,Ab[g])}g&&!f?a=Gxe(e,t,Ab,a):e.preScale.enabled&&!h?a=Wxe(e,s,c,t):a=lG(s,c,t);let p=s,v=c;if(e.preScale.enabled&&!h){const C=e.preScale.scalingParameters;if(uG(C),Bxe(C)){Vxe(a,C),t.preScale={...e.preScale,scaled:!0};const _=sS(s,c,C);p=_.min,v=_.max}}else h&&(t.preScale={enabled:!0,scaled:!1},p=s,v=c);t.pixelData=a,t.smallestPixelValue=p,t.largestPixelValue=v;const y=new Date().getTime();return t.decodeTimeInMS=y-r,t}function Bxe(t){const{rescaleSlope:e,rescaleIntercept:r,modality:n,doseGridScaling:i,suvbw:o}=t;return typeof e=="number"&&typeof r=="number"||n==="RTDOSE"&&typeof i=="number"||n==="PT"&&typeof o=="number"}function Gxe(t,e,r,n){const{arrayBuffer:i,type:o,offset:a=0,length:s,rows:c}=t.targetBuffer,l=r[o];if(!l)throw new Error(`target array ${o} is not supported, or doesn't exist.`);c&&c!=e.rows&&$xe(e,t.targetBuffer,l);const f=e.pixelDataLength,u=a,d=s??f-u,h=e.pixelData;if(d!==h.length)throw new Error(`target array for image does not have the same length (${d}) as the decoded image length (${h.length}).`);const g=i?new l(i,u,d):new l(d);return g.set(h,0),n=g,n}function Wxe(t,e,r,n){const i=t.preScale.scalingParameters;uG(i);const o=sS(e,r,i);return lG(o.min,o.max,n)}function lG(t,e,r){const n=hE(t,e),i=new n(r.pixelData.length);return i.set(r.pixelData,0),i}function sS(t,e,r){const{rescaleSlope:n,rescaleIntercept:i,modality:o,doseGridScaling:a,suvbw:s}=r;return o==="PT"&&typeof s=="number"&&!isNaN(s)?{min:s*(t*n+i),max:s*(e*n+i)}:o==="RTDOSE"&&typeof a=="number"&&!isNaN(a)?{min:t*a,max:e*a}:typeof n=="number"&&typeof i=="number"?{min:n*t+i,max:n*e+i}:{min:t,max:e}}function uG(t){if(!t)throw new Error("options.preScale.scalingParameters must be defined if preScale.enabled is true, and scalingParameters cannot be derived from the metadata providers.")}function zxe(t,e,r){const{samplesPerPixel:n}=t,{rows:i,columns:o}=e,a=i*o*n,s=new r(a),c=s.byteLength/a;return{pixelData:s,rows:i,columns:o,frameInfo:{...t.frameInfo,rows:i,columns:o},imageInfo:{...t.imageInfo,rows:i,columns:o,bytesPerPixel:c}}}function $xe(t,e,r){const n=zxe(t,e,r),{scalingType:i="replicate"}=e;return Fxe[i](t,n),Object.assign(t,n),t.pixelDataLength=t.pixelData.length,t}async function fG(t,e,r,n,i,o){const a=new Date().getTime();let s=null,c;switch(e){case"1.2.840.10008.1.2":case"1.2.840.10008.1.2.1":s=Ob(t,r);break;case"1.2.840.10008.1.2.2":s=rxe(t,r);break;case"1.2.840.10008.1.2.1.99":s=Ob(t,r);break;case"1.2.840.10008.1.2.5":s=ixe(t,r);break;case"1.2.840.10008.1.2.4.50":c={...t},s=dxe(r,c);break;case"1.2.840.10008.1.2.4.51":s=vxe(t,r);break;case"1.2.840.10008.1.2.4.57":s=Pb(t,r);break;case"1.2.840.10008.1.2.4.70":s=Pb(t,r);break;case"1.2.840.10008.1.2.4.80":c={signed:t.pixelRepresentation===1,bytesPerPixel:t.bitsAllocated<=8?1:2,...t},s=Rb(r,c);break;case"1.2.840.10008.1.2.4.81":c={signed:t.pixelRepresentation===1,bytesPerPixel:t.bitsAllocated<=8?1:2,...t},s=Rb(r,c);break;case"1.2.840.10008.1.2.4.90":c={...t},s=Lb(r,c);break;case"1.2.840.10008.1.2.4.91":c={...t},s=Lb(r,c);break;case"3.2.840.10008.1.2.4.96":case"1.2.840.10008.1.2.4.201":case"1.2.840.10008.1.2.4.202":case"1.2.840.10008.1.2.4.203":c={...t},s=Nxe(r,c);break;default:throw new Error(`no decoder for transfer syntax ${e}`)}if(!s)throw new Error("decodePromise not defined");const l=await s,f=Uxe(l,i,a);return o==null||o(f),f}const jxe={decodeTask({imageFrame:t,transferSyntax:e,decodeConfig:r,options:n,pixelData:i,callbackFn:o}){return fG(t,e,i,r,n,o)}};iT(jxe);const Nb={constants:Q3e,convertRGBColorByPixel:xB,convertRGBColorByPlane:CB,convertYBRFullByPixel:SB,convertYBRFullByPlane:_B,convertPALETTECOLOR:TB,wadouri:S3e,wadors:K3e,init:rG,convertColorSpace:zB,createImage:Y5,decodeJPEGBaseline8BitColor:$B,getImageFrame:jB,getPixelData:vE,getMinMax:X5,isColorImage:dE,isJPEGBaseline8BitColor:J3e,internal:Vwe,decodeImageFrame:fG};class Z0 extends Ou{}VE(Z0,"toolName","NoLabelArrowAnnotate");function kb(t,e){const r=mt("imagePlaneModule",t);if(!r)return;const{rowCosines:n,columnCosines:i,imagePositionPatient:o,rowPixelSpacing:a,columnPixelSpacing:s}=r;if(!n||!i||!o)return;const c=s||1,l=a||1,f=n,u=i,d=o;return[d[0]+e.x*u[0]*c+e.y*f[0]*l,d[1]+e.x*u[1]*c+e.y*f[1]*l,d[2]+e.x*u[2]*c+e.y*f[2]*l]}window.cornerstone3dTools=Twe;const{MouseBindings:tg,KeyboardBindings:Vb}=nN,{IMAGE_RENDERED:qm}=Xe,Hxe=[{name:"Soft Tissue",center:40,width:400},{name:"Lung",center:-600,width:1500},{name:"Bone",center:300,width:1500},{name:"Brain",center:40,width:80},{name:"Abdomen",center:60,width:400}],ng=[{label:"Window/Level",value:H0.toolName},{label:"Pan",value:j0.toolName},{label:"Zoom",value:q0.toolName},{label:"Stack Scroll",value:id.toolName},{label:"Rotate",value:K0.toolName},{label:"Length",value:Iu.toolName},{label:"Probe",value:nl.toolName},{label:"Arrow (No Label)",value:Z0.toolName},{label:"Arrow Annotate",value:Ou.toolName},{label:"Rectangle ROI",value:tl.toolName},{label:"Ellipse ROI",value:od.toolName},{label:"Freehand ROI",value:bu.toolName},{label:"Freehand Contour Segmentation",value:ic.toolName},{label:"Sculptor",value:X0.toolName},{label:"Reference Cursors",value:ua.toolName}],Fb=[{label:"Left",value:"Primary"},{label:"Middle",value:"Auxiliary"},{label:"Right",value:"Secondary"}],Xm=[{label:"Left",value:"Primary",mask:1},{label:"Middle",value:"Auxiliary",mask:4},{label:"Right",value:"Secondary",mask:2},{label:"Left + Right",value:"Primary_and_Secondary",mask:3},{label:"Left + Middle",value:"Primary_and_Auxiliary",mask:5},{label:"Right + Middle",value:"Secondary_and_Auxiliary",mask:6},{label:"Left + Right + Middle",value:"Primary_and_Secondary_and_Auxiliary",mask:7},{label:"Fourth Button",value:"Fourth_Button",mask:8},{label:"Fifth Button",value:"Fifth_Button",mask:16},{label:"Mouse Wheel",value:"Wheel",mask:524288},{label:"Mouse Wheel + Left",value:"Wheel_Primary",mask:524289}];function Ub({container_id:t,imageStacks:e,autoCacheStack:r,annotationJson:n,viewerState:i,...o}){var Fi,ao,Ui,mi,Ka,Bo,Bi,qa,Gi,ia;const a=At.useRef(null),s=At.useRef(null),c=At.useRef(!1),[l,f]=At.useState(!1),[u,d]=At.useState(!1),[h,g]=At.useState(null),[p,v]=At.useState(null),y=9,m="renderingEngine_"+t,w="TOOL_GROUP_"+t,x=At.useRef(null),C=At.useRef(!1),[S,_]=At.useState(!0),[T,E]=At.useState([]),[D,b]=At.useState(0),[I,P]=At.useState(()=>Array(y).fill([])),M=de=>{typeof de=="function"?P(Ue=>{const _e=de(Ue);return console.log("setViewportImageIds (fn):",_e),_e}):(console.log("setViewportImageIds:",de),P(de))},[L,V]=At.useState(()=>Array(y).fill(0)),[G,A]=At.useState(!1),[k,F]=At.useState(null);At.useEffect(()=>{let de=!1;if(n||i){F(n?"annotations":"viewerState");const Ue=setTimeout(()=>{if(de)return;const _e=t||"default";if(n)try{const ye=window[`importAnnotations_${_e}`]||window.importAnnotations;typeof ye=="function"&&ye(n)}catch(ye){console.error("Failed to import annotations from prop:",ye)}if(i)try{const ye=window[`importViewerState_${_e}`]||window.importViewerState;typeof ye=="function"&&ye(i)}catch(ye){console.error("Failed to import viewer state from prop:",ye)}F(null)},2e3);return()=>{de=!0,clearTimeout(Ue),F(null)}}},[n,i,t]),At.useEffect(()=>{e().then(async de=>{const Ue=await Promise.all(de.map(async _e=>{let ye;try{const je=_e[0];if(je&&je.startsWith("wadouri:")){const ot=je.slice(8),ut=await(await fetch(ot)).arrayBuffer();ye=Tr.parseDicom(new Uint8Array(ut)).string("x0020000d")}}catch{}return{imageIds:_e,studyInstanceUID:ye}}));E(Ue),await O(de[0]),M(Array(y).fill(de[0]||[]))})},[]);const j=async(de,Ue)=>{const _e=T[Ue];if(!_e)return;const ye=_e.imageIds;oe(je=>{const ot=[...je];return ot[de]="stack",ot}),M(je=>{const ot=[...je];return ot[de]=ye,ot}),V(je=>{const ot=[...je];return ot[de]=Ue,ot}),await O(ye)},[Y,re]=At.useState(!1),[ue,ce]=At.useState(!0),[pe,Ee]=At.useState(!1),[Oe,Se]=At.useState(!1),B=()=>{console.log("Sorting viewport imageIds by slice location"),M(de=>{const Ue=de.map((_e,ye)=>{if(!_e||_e.length===0)return _e;const st=[..._e.map(ut=>{const rt=mt("imagePlaneModule",ut);let Ct=null;return rt&&(rt.sliceLocation!==void 0?Ct=Number(rt.sliceLocation):rt.imagePositionPatient&&Array.isArray(rt.imagePositionPatient)&&rt.imagePositionPatient.length===3&&(Ct=Number(rt.imagePositionPatient[2]))),{imageId:ut,sortKey:Ct}})].sort((ut,rt)=>ut.sortKey!==null&&rt.sortKey!==null?ut.sortKey-rt.sortKey:ut.imageId.localeCompare(rt.imageId)).map(ut=>ut.imageId);return JSON.stringify(st)===JSON.stringify(_e)?_e:st});return A(!0),Ue})},O=async de=>{console.log("Setting loaded imageIds:",de),console.log("autoCacheStack:",r);const Ue=[];if(r){for(const _e of de)if(_e.startsWith("wadouri:"))try{const ye=_e.slice(8);if(Nb.wadouri.dataSetCacheManager){const je=Nb.wadouri.dataSetCacheManager.load(ye);je&&typeof je.then=="function"&&Ue.push(je)}else console.warn("MetaDataManager not found. Unable to cache metadata.")}catch(ye){console.warn(`Failed to cache metadata for ${_e}:`,ye)}await Promise.all(Ue),Ne&&(console.log("Sorting viewport imageIds by slice location"),B())}},[z,W]=At.useState({rows:1,cols:1}),[K,Z]=At.useState(!1),ee=At.useRef([]),xe=At.useRef({}),De=At.useRef({}),[Ne,ze]=At.useState(!1),[ie,ae]=At.useState(!0),we=[];for(let de=1;de<=3;de++)for(let Ue=1;Ue<=3;Ue++)we.push({rows:de,cols:Ue});const[se,ge]=At.useState(()=>Array(z.rows*z.cols).fill({index:0,total:0,windowCenter:"",windowWidth:"",slicePosition:0})),[Fe,oe]=At.useState(()=>Array(y).fill("stack")),[ht,wt]=At.useState(()=>Array(z.rows*z.cols).fill(!1)),[gt,Ie]=At.useState({Primary:id.toolName,Auxiliary:j0.toolName,Secondary:H0.toolName,Primary_and_Secondary:q0.toolName,Fourth_Button:K0.toolName,Wheel:id.toolName}),[$e,tt]=At.useState({Primary:Iu.toolName,Auxiliary:nl.toolName,Secondary:Z0.toolName}),[nt,dt]=At.useState(!1);At.useEffect(()=>{const de=_e=>{_e.ctrlKey&&dt(!0)},Ue=_e=>{_e.ctrlKey||dt(!1)};return window.addEventListener("keydown",de),window.addEventListener("keyup",Ue),()=>{window.removeEventListener("keydown",de),window.removeEventListener("keyup",Ue)}},[]);const[Lt,xt]=At.useState(!1),[Ft,jt]=At.useState(null),Pn=(de,Ue)=>{Ro&&Ro(Ue),yn(_e=>{const ye=[..._e];return ye[de]=Ue,ye})},$n=(de,Ue,_e)=>{const ye=Rr.getAllAnnotations()||[];ye.forEach(ot=>{ot.annotationUID===Ue&&(ot.isSelected=!1)}),Rr.removeAnnotation(Ue),x.current.render();const je=_e.filter(ot=>ot.annotationUID!==Ue);yn(ot=>{const st=[...ot],ut=je.length>0?je[0].annotationUID:null;return st[de]=ut,ye.forEach(rt=>{rt.isSelected=rt.annotationUID===ut}),Ro(ut),x.current.render(),st})},fn=()=>{const de=I.findIndex(je=>je&&je.length>0);if(de===-1){jt("No images loaded."),xt(!0);return}const Ue=I[de][0],_e=["imagePlaneModule","generalSeriesModule","generalStudyModule","patientModule","imagePixelModule","voiLutModule","modalityLutModule","sopCommonModule","petIsotopeModule","multiframeModule","cineModule","overlayPlaneModule","generalImageModule","stackModule","voiLutModule","modalityLutModule","petSeriesModule","petImageModule","petIsotopeModule","petSeriesModule","petImageModule","petIsotopeModule","petSeriesModule","petImageModule","petIsotopeModule","petSeriesModule","petImageModule","petIsotopeModule"],ye={};_e.forEach(je=>{const ot=mt(je,Ue);ot!==void 0&&(ye[je]=ot)}),jt(lt.jsx("pre",{style:{maxHeight:600,overflow:"auto",fontSize:13,color:"#fff"},children:JSON.stringify(ye,null,2)})),xt(!0)};At.useEffect(()=>(window.loadDicomStackFromFiles=de=>{const Ue=Array.from(de);Sn({target:{files:Ue}})},()=>{window.loadDicomStackFromFiles=void 0}),[]);const[bn,Xi]=At.useState(!1);At.useEffect(()=>{const de=Kr(w);de&&["ArrowAnnotate","NoLabelArrowAnnotate","Length","RectangleROI","EllipticalROI","PlanarFreehandROI","PlanarFreehandContourSegmentation"].forEach(Ue=>{de.setToolConfiguration(Ue,{color:"#00e676",selectedColor:"#ffeb3b"})})},[w]),At.useEffect(()=>{const de=_e=>{_e.altKey&&Xi(!0)},Ue=_e=>{_e.altKey||Xi(!1)};return window.addEventListener("keydown",de),window.addEventListener("keyup",Ue),()=>{window.removeEventListener("keydown",de),window.removeEventListener("keyup",Ue)}},[]),At.useEffect(()=>{if(!ie)return;const de=Kr(w);de&&(bn?(de.hasTool(ua.toolName)||de.addTool(ua.toolName),de.setToolEnabled(ua.toolName),de.setToolActive(ua.toolName)):de.hasTool(ua.toolName)&&de.setToolDisabled(ua.toolName))},[bn,ie]);const Mr=At.useCallback(()=>{[Kr(w)].forEach(Ue=>{if(Ue){ng.forEach(ye=>{Ue.setToolPassive(ye.value,{removeAllBindings:!0})}),Ue.setToolDisabled(ua.toolName);const _e={};Object.entries(gt).forEach(([ye,je])=>{_e[je]||(_e[je]=[]);const ot=Xm.find(st=>st.value===ye);ot?_e[je].push({mouseButton:ot.mask}):tg[ye]&&_e[je].push({mouseButton:tg[ye]})}),Object.entries($e).forEach(([ye,je])=>{if(!je)return;_e[je]||(_e[je]=[]);const ot=Xm.find(st=>st.value===ye);ot?_e[je].push({mouseButton:ot.mask,modifierKey:Vb.Ctrl}):tg[ye]&&_e[je].push({mouseButton:tg[ye],modifierKey:Vb.Ctrl})}),Object.entries(_e).forEach(([ye,je])=>{Ue.setToolActive(ye,{bindings:je})})}})},[gt,$e]),[Be,ft]=At.useState(!1),Ut=At.useRef(null),Sn=async de=>{const Ue=de.target.files;if(!Ue||Ue.length===0)return;ze(!1);const _e=Array.from(Ue).sort((ut,rt)=>ut.name.localeCompare(rt.name));let ye;const je=await _e[0].arrayBuffer();ye=Tr.parseDicom(new Uint8Array(je)).string("x0020000d"),console.log("StudyInstanceUID:",ye);const st=_e.map(ut=>`wadouri:${URL.createObjectURL(ut)}`);E(ut=>{const rt=[...ut,{imageIds:st,studyInstanceUID:ye}];return M(Ct=>{const Qt=[...Ct];return Qt[0]=st,Qt}),V(Ct=>{const Qt=[...Ct];return Qt[0]=rt.length-1,Qt}),O(st),rt})},Qn=At.useCallback((de,Ue)=>{if(!Ue)return;let _e=0,ye=0,je="",ot="",st="";if(Fe[de]==="stack"){if(_e=typeof Ue.getCurrentImageIdIndex=="function"?Ue.getCurrentImageIdIndex():0,ye=(typeof Ue.getImageIds=="function"?Ue.getImageIds():[]).length,typeof Ue.getProperties=="function"){const rt=Ue.getProperties();if(rt.voiRange){const{lower:Ct,upper:Qt}=rt.voiRange;je=((Qt+Ct)/2).toFixed(0),ot=(Qt-Ct).toFixed(0)}}}else if(Fe[de]==="volume"){if(typeof Ue.getSliceIndex=="function"&&(_e=Ue.getSliceIndex()),typeof Ue.getNumberOfSlices=="function"&&(ye=Ue.getNumberOfSlices()),typeof Ue.getProperties=="function"){let ut;if(Ue.volumeIds&&Ue.volumeIds.size>0){const rt=Array.from(Ue.volumeIds)[0];ut=Ue.getProperties(rt)}else ut=Ue.getProperties();if(ut&&ut.voiRange){const{lower:rt,upper:Ct}=ut.voiRange;je=((Ct+rt)/2).toFixed(0),ot=(Ct-rt).toFixed(0)}}if(typeof Ue.getSlicePlaneCoordinates=="function"){const ut=Ue.getSlicePlaneCoordinates();ut&&typeof ut.position=="number"&&(st=ut.position.toFixed(2)+" mm")}}ge(ut=>{const rt=[...ut];return rt[de]={index:_e+1,total:ye,windowCenter:je,windowWidth:ot,slicePosition:st},rt})},[Fe]),[Pt,_n]=At.useState(!1);function sn(){for(let de=0;de{const de=async()=>{var ot;console.log("setup"),c.current||(c.current=!0,await WZ(),await iF(),rG());let _e=x.current;_e||(_e=new CA(m),x.current=_e);let ye=Kr(w);ye||(ye=Kxe(w)),Fe.slice(0,z.rows*z.cols).filter(st=>st==="volume").length,Vi(ye);for(let st=0;st{if(Ct.offsetWidth>0&&Ct.offsetHeight>0){_e.resize();const xn=_e.getViewport(rt);xn&&typeof xn.resize=="function"&&xn.resize(),xn&&typeof xn.render=="function"&&xn.render()}});Gt.observe(Ct),Ct._resizeObserver=Gt}if(Fe[st]==="stack")ut&&ut.length>0&&on.setStack(ut),Y?ye.removeViewports(m,rt):ye.addViewport(rt,m);else if(Fe[st]==="volume"){ye.addViewport(rt,m);const Gt=`myVolumeId_${st}`;(await Vv(Gt,{imageIds:ut})).load(),on.setVolumes([{volumeId:Gt}]),on.render(),Ct._overlayListener&&on.element.removeEventListener(qm,Ct._overlayListener);const er=()=>Qn(st,on);on.element.addEventListener(qm,er),Ct._overlayListener=er,Qn(st,on);continue}if(on.render(),!C.current){De.current[st]!==void 0&&typeof on.setImageIdIndex=="function"&&Aa(on.element,{imageIndex:De.current[st]});const Gt=xe.current[st];if(Gt&&typeof on.setProperties=="function"){const{voiRange:xn,invert:er,interpolationType:nr,VOILUTFunction:or,colormap:qn}=Gt,Nt={};xn&&xn.lower!==void 0&&xn.upper!==void 0&&(Nt.voiRange=xn),er!==void 0&&(Nt.invert=er),nr!==void 0&&(Nt.interpolationType=nr),or&&(Nt.VOILUTFunction=or),qn!=null&&(typeof qn=="string"||typeof qn=="object"&&!("actor"in qn))&&(Nt.colormap=qn),setTimeout(()=>{console.log("Restoring properties (timeout) for viewport",st,Nt),on.setProperties(Nt),on.render()},100)}}Ct._overlayListener&&on.element.removeEventListener(qm,Ct._overlayListener);const cn=()=>Qn(st,on);on.element.addEventListener(qm,cn),Ct._overlayListener=cn,Qn(st,on)}for(let st=0;st=2?(ye.hasTool(Fs.toolName)||ye.addTool(Fs.toolName),ye.setToolEnabled(Fs.toolName),ye.setToolConfiguration(Fs.toolName,{}),ye.setToolActive(Fs.toolName,{bindings:[{mouseButton:tg.Primary}]})):ye.hasTool(Fs.toolName)&&ye.setToolDisabled(Fs.toolName)),Mr()},Ue=requestAnimationFrame(()=>{de()});return()=>{ee.current.forEach(_e=>{_e&&_e._resizeObserver&&(_e._resizeObserver.disconnect(),delete _e._resizeObserver)}),cancelAnimationFrame(Ue)}},[s,Qn,z,Fe,I]);const rn=At.useCallback(de=>{const Ue=`CT_${de}`,ye=x.current.getViewport(Ue);ye&&typeof ye.resetCamera=="function"&&(ye.resetCamera(),console.log("Restoring viewport properties for viewport",de),ye.resetProperties(),ye.render())},[]),pi=At.useCallback((de,Ue,_e)=>{const ye=`CT_${de}`;try{const je=x.current;if(je){const ot=je.getViewport(ye);ot&&typeof ot.setProperties=="function"&&(console.log(`Applying preset to viewport ${de}: center=${Ue}, width=${_e}`),ot.setProperties({voiRange:{lower:Ue-_e/2,upper:Ue+_e/2}}),ot.render(),Qn(de,ot))}}catch{}},[Qn]);At.useEffect(()=>{ge(Array(z.rows*z.cols).fill({index:0,total:0,windowCenter:"",windowWidth:""})),wt(Array(z.rows*z.cols).fill(!1))},[z]),At.useEffect(()=>{Mr()},[gt,$e,nt,Mr]),At.useEffect(()=>{if(!l)return;const de=Ue=>{const _e=document.querySelector(".preset-menu");_e&&!_e.contains(Ue.target)&&f(!1)};return document.addEventListener("mousedown",de),()=>document.removeEventListener("mousedown",de)},[l]),At.useEffect(()=>{const de=Ue=>{if(Ue.button===3||Ue.button===4)return Ue.preventDefault(),!1};return window.addEventListener("mousedown",de,!0),window.addEventListener("mouseup",de,!0),window.addEventListener("auxclick",de,!0),()=>{window.removeEventListener("mousedown",de,!0),window.removeEventListener("mouseup",de,!0),window.removeEventListener("auxclick",de,!0)}},[]),At.useEffect(()=>{const de=a.current;if(!de)return;const Ue=_e=>{_e.preventDefault()};return de.addEventListener("contextmenu",Ue),()=>{de.removeEventListener("contextmenu",Ue)}},[]),At.useEffect(()=>{if(!ue)return;const de=Kr(w);Vi(de)},[D,ue]),At.useEffect(()=>{Ut.current&&(Ut.current.setAttribute("webkitdirectory","true"),Ut.current.setAttribute("directory","true"))},[]),At.useEffect(()=>(window.loadDicomStackFromWadouriList=async de=>{if(!de||de.length===0)return;let Ue;try{const _e=de[0];if(_e&&_e.startsWith("wadouri:")){const ye=_e.slice(8),ot=await(await fetch(ye)).arrayBuffer();Ue=Tr.parseDicom(new Uint8Array(ot)).string("x0020000d")}}catch{}E(_e=>{const ye=[..._e,{imageIds:de,studyInstanceUID:Ue}];return M(je=>{const ot=[...je];return ot[0]=de,ot}),V(je=>{const ot=[...je];return ot[0]=ye.length-1,ot}),O(de),ye})},()=>{window.loadDicomStackFromWadouriList=void 0}),[E,M,V,O]),At.useEffect(()=>{!Ne||!I.every(Ue=>!Ue||Ue.length===0||Ue.every(_e=>!!mt("imagePlaneModule",_e)))||M(Ue=>{let _e=!1;const ye=Ue.map(je=>{if(!je||je.length===0)return je;const ut=[...je.map(rt=>({imageId:rt,sliceLoc:(()=>{const Ct=mt("imagePlaneModule",rt);return Ct&&Ct.sliceLocation!==void 0?Number(Ct.sliceLocation):null})()}))].sort((rt,Ct)=>rt.sliceLoc!==null&&Ct.sliceLoc!==null?rt.sliceLoc-Ct.sliceLoc:rt.imageId.localeCompare(Ct.imageId)).map(rt=>rt.imageId);return JSON.stringify(ut)!==JSON.stringify(je)?(_e=!0,ut):je});return _e&&A(!0),ye})},[Ne,T]);function Vi(de){if(!de)return;const Ue=`CT_${D}`;ue?(de.setToolEnabled(Gf.toolName),de.setToolConfiguration(Gf.toolName,{sourceViewportId:Ue})):de.setToolDisabled(Gf.toolName)}function Ha(){var Ue,_e,ye;const de=x.current;if(de)for(let je=0;je=ye.length||de>=Ue)return alert("Invalid truncation bounds."),!1;const je=ye.slice(de,Ue+1);E([{..._e,imageIds:je}]),M([je]),V([0]);const ot=x.current;if(ot){const rt=ot.getViewport("CT_0");rt&&typeof rt.setStack=="function"&&(rt.setStack(je),(st=rt.setImageIdIndex)==null||st.call(rt,0),(ut=rt.render)==null||ut.call(rt))}return!0}function To(de=0){const Ue=x.current;if(!Ue)return null;const _e=Ue.getViewport(`CT_${de}`);return!_e||typeof _e.getCurrentImageIdIndex!="function"?null:_e.getCurrentImageIdIndex()}At.useEffect(()=>{const de=t||"default";function Ue(_e,ye){const je=x.current;if(!je)return;const ot=je.getViewport(`CT_${_e}`);if(!ot||typeof ot.getImageIds!="function")return;const ut=ot.getImageIds().map(Qt=>Qt.replace(/^wadouri:/,"")),rt=ye.replace(/^wadouri:/,""),Ct=ut.indexOf(rt);Ct!==-1&&typeof ot.setImageIdIndex=="function"&&(Aa(ot.element,{imageIndex:Ct}),Qn(_e,ot))}return window[`getViewport_${de}`]=_e=>{const ye=x.current;if(ye)return ye.getViewport(`CT_${_e}`)},window[`getAllViewports_${de}`]=()=>{const _e=x.current;return _e?Array.from({length:y},(ye,je)=>_e.getViewport(`CT_${je}`)).filter(Boolean):[]},window[`jumpToSliceByImageId_${de}`]=Ue,window[`resetViewer_${de}`]=Ha,window[`truncateStack_${de}`]=Ea,window[`getCurrentStackPosition_${de}`]=To,window[`loadAdditionalStack_${de}`]=async(_e,ye)=>{var ot;if(!Array.isArray(_e)||_e.length===0)return;let je=ye;if(!je&&((ot=_e[0])!=null&&ot.startsWith("wadouri:")))try{const st=_e[0].slice(8),rt=await(await fetch(st)).arrayBuffer();je=Tr.parseDicom(new Uint8Array(rt)).string("x0020000d")}catch{}E(st=>[...st,{imageIds:_e,studyInstanceUID:je}]),M(st=>{const ut=[...st],rt=ut.findIndex(Ct=>!Ct||Ct.length===0);return rt!==-1&&(ut[rt]=_e),ut}),O(_e)},window[`exportViewerState_${de}`]=()=>{var Gt;const _e=z.rows*z.cols,ye=Fe.slice(0,_e),je=L.slice(0,_e),ot=T.map(xn=>({i:xn.imageIds,u:xn.studyInstanceUID}));console.log("Exporting viewer state with",_e,"active viewports"),console.log("modes",ye);const st=x.current,ut=[],rt=[],Ct=[],Qt=[],on=[];for(let xn=0;xn<_e;xn++){let er=null,nr=null,or=null,qn=null,Nt=null;if(console.log("Exporting state for viewport",xn),st){console.log("Rendering engine found, exporting state for viewport",xn);const Bn=`CT_${xn}`,dr=st.getViewport(Bn);if(dr){if(typeof dr.getProperties=="function"){const{voiRange:si,invert:jn,interpolationType:wr,VOILUTFunction:ei,colormap:xr}=dr.getProperties();er={voiRange:si,invert:jn,interpolationType:wr,VOILUTFunction:ei,colormap:xr}}typeof dr.getCurrentImageIdIndex=="function"&&(nr=dr.getCurrentImageIdIndex()),typeof dr.getCamera=="function"&&(or=dr.getCamera()),console.log("viewport",Bn,"properties",er),ye[xn]==="volume"&&(console.log("Getting orientation for viewport",xn),console.log("viewport.viewportProperties",dr.viewportProperties),qn=((Gt=dr.viewportProperties)==null?void 0:Gt.orientation)||null,typeof dr.getSliceIndex=="function"&&(Nt=dr.getSliceIndex()))}}ut.push(er),rt.push(nr),Ct.push(or),Qt.push(qn),on.push(Nt)}return JSON.stringify({grid:z,modes:ye,stacks:ot,stackIdx:je,stackPos:rt,props:ut,cam:Ct,orientations:Qt,volumeSliceIndices:on})},window[`importViewerState_${de}`]=_e=>{try{C.current=!0;const ye=typeof _e=="string"?JSON.parse(_e):_e;if(ye.grid&&W(ye.grid),ye.modes&&oe(ye.modes),ye.stacks&&E(ye.stacks.map(ut=>({imageIds:ut.i,studyInstanceUID:ut.u}))),ye.stackIdx&&ye.stacks){const ut=ye.stackIdx.map(rt=>{var Ct;return((Ct=ye.stacks[rt])==null?void 0:Ct.i)||[]});M(ut),V(ye.stackIdx)}const je=30;let ot=0;async function st(){var Qt,on,cn,Gt,xn,er,nr,or,qn;const ut=x.current;if(!ut){C.current=!1;return}const rt=((Qt=ye.grid)==null?void 0:Qt.rows)*((on=ye.grid)==null?void 0:on.cols)||1;let Ct=!0;for(let Nt=0;Ntei===jn[xr])){console.warn(`Viewport ${Nt}: importedImageIds do not match viewportImageIds`,{importedImageIds:jn,viewportImageIds:wr}),Ct=!1;break}}catch{Ct=!1}}if(!Ct&&ot{st()},500);return}for(let Nt=0;Nt{Aa(Bn.element,{imageIndex:ye.volumeSliceIndices[Nt]})},100)),Bn.render()}else Bn.setStack&&(Bn.setStack(jn),Bn.render()),ye.stackPos&&typeof ye.stackPos[Nt]=="number"&&typeof Bn.setImageIdIndex=="function"&&(Mn&&Aa?Aa(Bn.element,{imageIndex:ye.stackPos[Nt]}):Bn.setImageIdIndex(ye.stackPos[Nt]));if(ye.props&&ye.props[Nt]&&typeof Bn.setProperties=="function"){console.log("Restoring properties for viewport",Nt,ye.props[Nt]);const wr={...ye.props[Nt]};wr.colormap!==void 0&&wr.colormap!==null&&typeof wr.colormap!="string"&&(typeof wr.colormap!="object"||!("name"in wr.colormap))&&delete wr.colormap,setTimeout(()=>{Bn.setProperties(wr),Bn.render()},100)}else console.warn("No properties to restore for viewport",Nt);ye.cam&&ye.cam[Nt]&&typeof Bn.setCamera=="function"&&(Bn.setCamera(ye.cam[Nt]),Bn.render())}}C.current=!1}setTimeout(()=>{st()},0)}catch(ye){C.current=!1,alert("Failed to import viewer state: "+ye)}},window[`exportAnnotations_${de}`]=()=>{try{let _e=Rr.getAllAnnotations();if(console.log("Exporting annotations:",_e),Array.isArray(_e)){const ye=[Iu.toolName,Z0.toolName,Ou.toolName,tl.toolName,od.toolName,bu.toolName,ic.toolName,nl.toolName,X0.toolName];_e=_e.filter(je=>ye.includes(je.metadata.toolName))}else return"{}";return JSON.stringify(_e,null,2)}catch(_e){return alert("Failed to export annotations: "+_e),"{}"}},window[`importAnnotations_${de}`]=_e=>{try{const ye=typeof _e=="string"?JSON.parse(_e):_e;Rr.removeAllAnnotations&&Rr.removeAllAnnotations(),Array.isArray(ye)&&ye.forEach(je=>{Rr.addAnnotation(je,je.annotationUID)}),x.current&&x.current.render()}catch(ye){alert("Failed to import annotations: "+ye)}},window[`importLegacyAnnotations_${de}`]=_e=>{Rr.removeAllAnnotations&&Rr.removeAllAnnotations();let ye;try{ye=typeof _e=="string"?JSON.parse(_e):_e}catch{alert("Invalid legacy annotation JSON");return}const je={ArrowAnnotate:"ArrowAnnotate"};Object.entries(ye).forEach(([ot,st])=>{console.log("Importing legacy annotations for imageId:",ot),Object.entries(st).forEach(([ut,rt])=>{const Ct=je[ut]||ut;rt.data&&Array.isArray(rt.data)&&rt.data.forEach(Qt=>{const on=kb(ot,{x:Qt.handles.start.y,y:Qt.handles.start.x}),cn=kb(ot,{x:Qt.handles.end.y,y:Qt.handles.end.x});console.log("Importing legacy annotation:"),console.log(" Image ID:",ot),console.log(" Start World:",on),console.log(" End World:",cn);const Gt=mt("imagePlaneModule",ot);console.log(rL);let xn=mt("frameOfReferenceUID",ot);!xn&&Gt&&Gt.frameOfReferenceUID&&(xn=Gt.frameOfReferenceUID);const er=Gt!=null&&Gt.rowCosines&&(Gt!=null&&Gt.columnCosines)?[Gt.rowCosines[1]*Gt.columnCosines[2]-Gt.rowCosines[2]*Gt.columnCosines[1],Gt.rowCosines[2]*Gt.columnCosines[0]-Gt.rowCosines[0]*Gt.columnCosines[2],Gt.rowCosines[0]*Gt.columnCosines[1]-Gt.rowCosines[1]*Gt.columnCosines[0]]:void 0;Array.isArray(er)&&er.length,typeof Qt.rotation=="number"&&Qt.rotation;const nr={annotationUID:Qt.uuid,metadata:{toolName:Ct,referencedImageId:ot,FrameOfReferenceUID:xn,viewPlaneNormal:er},data:{handles:{points:[on,cn],textBox:Qt.handles.textBox},text:Qt.text||""},visibility:Qt.visible!==!1,active:Qt.active||!1};Rr.addAnnotation(nr,nr.annotationUID)})})}),x.current&&x.current.render()},window[`importLegacyViewport_${de}`]=_e=>{let ye;try{ye=typeof _e=="string"?JSON.parse(_e):_e}catch{alert("Invalid legacy viewport JSON");return}const je=x.current;if(!je)return;const ot=`CT_${D??0}`,st=je.getViewport(ot);if(!st)return;const ut={};if(ye.voi&&(ut.voiRange={lower:ye.voi.windowCenter-ye.voi.windowWidth/2,upper:ye.voi.windowCenter+ye.voi.windowWidth/2}),typeof ye.invert=="boolean"&&(ut.invert=ye.invert),typeof ye.pixelReplication=="boolean"&&(ut.interpolationType=ye.pixelReplication?0:1),typeof ye.hflip=="boolean"&&(ut.hflip=ye.hflip),typeof ye.vflip=="boolean"&&(ut.vflip=ye.vflip),typeof st.setProperties=="function"&&st.setProperties(ut),ye.translation||ye.scale){const rt=st.getCamera?st.getCamera():{};ye.translation&&(rt.translation={...rt.translation,...ye.translation}),ye.scale&&(rt.parallelScale=200/ye.scale),console.log("Applying legacy camera properties:",rt),typeof st.setCamera=="function"&&st.setCamera(rt)}typeof ye.rotation=="number"&&st.setRotation(ye.rotation),st.render(),Qn(D??0,st)},()=>{window[`exportViewerState_${de}`]=void 0,window[`importViewerState_${de}`]=void 0,window[`exportAnnotations_${de}`]=void 0,window[`importAnnotations_${de}`]=void 0,window[`importLegacyAnnotations_${de}`]=void 0,window[`importLegacyViewport_${de}`]=void 0,window[`jumpToSliceByImageId_${de}`]=void 0,window[`resetViewer_${de}`]=void 0,window[`truncateStack_${de}`]=void 0,window[`getCurrentStackPosition_${de}`]=void 0,window[`loadAdditionalStack_${de}`]=void 0,window[`getViewport_${de}`]=void 0,window[`getAllViewports_${de}`]=void 0}},[z,Fe,L,T,I,W,oe,V,E,M,E,M,O]),At.useEffect(()=>{function de(Ue){if(console.log("Handling arrow key navigation",Ue.key),console.log("activeViewport",D),D===null)return;const _e=x.current;if(!_e)return;const ye=_e.getViewport(`CT_${D}`);if(ye){if(console.log(ye),Fe[D]==="stack"){if(typeof ye.getCurrentImageIdIndex!="function"||typeof ye.setImageIdIndex!="function")return;const je=I[D];if(!je||je.length===0)return;Ue.key==="ArrowUp"||Ue.key==="ArrowRight"?(ps(ye,{delta:-1}),Ue.preventDefault()):(Ue.key==="ArrowDown"||Ue.key==="ArrowLeft")&&(ps(ye,{delta:1}),Ue.preventDefault())}Fe[D]==="volume"&&typeof ye.getSliceIndex=="function"&&typeof ye.getNumberOfSlices=="function"&&ye.getNumberOfSlices()>1&&(Ue.key==="ArrowUp"||Ue.key==="ArrowRight"?(ps(ye,{delta:-1}),Ue.preventDefault()):(Ue.key==="ArrowDown"||Ue.key==="ArrowLeft")&&(ps(ye,{delta:1}),Ue.preventDefault()))}}return window.addEventListener("keydown",de),()=>window.removeEventListener("keydown",de)},[D,Fe,I,Qn]);const ra=D!==null?L[D]:0,Uo=T[ra],fr=Uo==null?void 0:Uo.studyInstanceUID,[oo,yn]=At.useState(()=>Array(y).fill(null)),Qr=z.rows*z.cols,Da=[];for(let de=0;deee.current[de]=_e,style:{flex:1,border:Ue?"1px solid #222":"none",background:"#000",minWidth:0,minHeight:0,position:"relative",overflow:"hidden",flexDirection:"column",gridRow:Math.floor(de/z.cols)+1,gridColumn:de%z.cols+1,height:"100%",boxShadow:D===de?"0 0 0 4px #1976d2, 0 0 16px 4px #1976d2cc":void 0,zIndex:D===de?10:1},onClick:()=>{b(de),Z(!1)},onDoubleClick:()=>rn(de),children:[lt.jsx("button",{style:{position:"absolute",top:8,left:8,zIndex:20,background:"#333",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 8px",cursor:"pointer",fontSize:"12px",opacity:.85},onClick:()=>{oe(_e=>{const ye=[..._e];return ye[de]=_e[de]==="stack"?"volume":"stack",ye})},children:Fe[de]==="stack"?"Volume":"Stack"}),Fe[de]==="volume"&<.jsxs("div",{style:{position:"absolute",top:8,left:70,zIndex:21,display:"flex",gap:"6px",background:"rgba(34,34,34,0.85)",borderRadius:"4px",padding:"2px 6px",alignItems:"center"},children:[lt.jsx("button",{style:{background:"#444",color:"#fff",border:"none",borderRadius:"3px",padding:"2px 8px",cursor:"pointer",fontSize:"12px",marginRight:"2px"},onClick:()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);ye&&ye.setOrientation&&(ye.setOrientation("axial"),ye.render())},children:"Axial"}),lt.jsx("button",{style:{background:"#444",color:"#fff",border:"none",borderRadius:"3px",padding:"2px 8px",cursor:"pointer",fontSize:"12px",marginRight:"2px"},onClick:()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);ye&&ye.setOrientation&&(ye.setOrientation("sagittal"),ye.render())},children:"Sagittal"}),lt.jsx("button",{style:{background:"#444",color:"#fff",border:"none",borderRadius:"3px",padding:"2px 8px",cursor:"pointer",fontSize:"12px"},onClick:()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);ye&&ye.setOrientation&&(ye.setOrientation("coronal"),ye.render())},children:"Coronal"})]}),lt.jsxs("button",{style:{position:"absolute",top:40,left:8,zIndex:20,background:"#111",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 8px",cursor:"pointer",fontSize:"13px",opacity:.85,marginTop:"4px",display:"flex",alignItems:"center",gap:"6px"},title:"Toggle Fullscreen",onClick:_e=>{_e.stopPropagation();const ye=ee.current[de];document.fullscreenElement===ye?document.exitFullscreen():ye!=null&&ye.requestFullscreen?ye.requestFullscreen():ye!=null&&ye.webkitRequestFullscreen?ye.webkitRequestFullscreen():ye!=null&&ye.msRequestFullscreen&&ye.msRequestFullscreen()},onMouseEnter:()=>g(de),onMouseLeave:()=>g(null),children:[lt.jsx("span",{style:{fontSize:"18px",lineHeight:1},children:"⛶"}),h===de&<.jsx("span",{style:{marginLeft:6},children:document.fullscreenElement===ee.current[de]?"Exit Fullscreen":"Fullscreen"})]}),Fe[de]==="stack"&&S&&(()=>{var on;const _e=I[de],je=(Rr.getAllAnnotations()||[]).filter(cn=>cn.metadata&&cn.metadata.referencedImageId&&_e.includes(cn.metadata.referencedImageId)&&cn.metadata.toolName!==ua.toolName);if(!je.length)return null;const ot=x.current,st=ot==null?void 0:ot.getViewport(`CT_${de}`),ut=((on=st==null?void 0:st.getCurrentImageIdIndex)==null?void 0:on.call(st))??0,rt=_e[ut],Ct=je.filter(cn=>cn.metadata.referencedImageId===rt),Qt=oo[de];return lt.jsxs("div",{style:{position:"absolute",left:"50%",bottom:60,transform:"translateX(-50%)",zIndex:30,display:"flex",gap:4,pointerEvents:"auto",alignItems:"center"},children:[lt.jsx("button",{style:{background:"rgba(30,30,30,0.7)",color:"#fff",border:"none",borderRadius:"50%",width:28,height:28,fontSize:"16px",fontWeight:"bold",cursor:"pointer",opacity:.7,display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.18)",transition:"opacity 0.2s"},title:"Previous Annotation","aria-label":"Previous Annotation",onClick:()=>{const cn=x.current,Gt=cn==null?void 0:cn.getViewport(`CT_${de}`);if(!Gt||typeof Gt.getCurrentImageIdIndex!="function")return;const xn=Gt.getCurrentImageIdIndex(),er=Bb(xn,_e,je,-1);if(er!==null&&typeof Gt.setImageIdIndex=="function"){Aa(Gt.element,{imageIndex:er}),Qn(de,Gt);const nr=_e[er],or=je.filter(qn=>qn.metadata.referencedImageId===nr);Pn(de,or.length>0?or[0].annotationUID:null)}},children:lt.jsx("span",{"aria-hidden":"true",children:"◀"})}),lt.jsx("button",{style:{background:"rgba(30,30,30,0.7)",color:"#fff",border:"none",borderRadius:"50%",width:28,height:28,fontSize:"16px",fontWeight:"bold",cursor:"pointer",opacity:.7,display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.18)",transition:"opacity 0.2s"},title:"Next Annotation","aria-label":"Next Annotation",onClick:()=>{const cn=x.current,Gt=cn==null?void 0:cn.getViewport(`CT_${de}`);if(!Gt||typeof Gt.getCurrentImageIdIndex!="function")return;const xn=Gt.getCurrentImageIdIndex(),er=Bb(xn,_e,je,1);if(er!==null&&typeof Gt.setImageIdIndex=="function"){Aa(Gt.element,{imageIndex:er}),Qn(de,Gt);const nr=_e[er],or=je.filter(qn=>qn.metadata.referencedImageId===nr);Pn(de,or.length>0?or[0].annotationUID:null)}},children:lt.jsx("span",{"aria-hidden":"true",children:"▶"})}),Ct.length>0&<.jsx("div",{style:{display:"flex",gap:2,alignItems:"center"},children:Ct.map(cn=>lt.jsxs("div",{style:{display:"flex",alignItems:"center",background:Qt===cn.annotationUID?"rgb(4, 225, 0)":"#444",color:Qt===cn.annotationUID?"#222":"#fff",borderRadius:"4px",padding:"2px 6px",marginRight:2,cursor:"pointer",border:Qt===cn.annotationUID?"2px solid #1976d2":"none",fontWeight:Qt===cn.annotationUID?"bold":"normal"},onClick:()=>Pn(de,cn.annotationUID),children:[lt.jsxs("span",{style:{marginRight:4},children:[Qt===cn.annotationUID?"★ ":"",cn.metadata.toolName||"Annotation"]}),lt.jsx("button",{style:{background:"#b71c1c",color:"#fff",border:"none",borderRadius:"50%",width:20,height:20,fontSize:"13px",fontWeight:"bold",cursor:"pointer",marginLeft:2,display:"flex",alignItems:"center",justifyContent:"center",opacity:.85},title:"Delete this annotation","aria-label":"Delete annotation",onClick:Gt=>{Gt.stopPropagation(),$n(de,cn.annotationUID,Ct)},children:"🗑️"})]},cn.annotationUID))})]})})(),lt.jsx("div",{style:{position:"absolute",left:8,bottom:8,background:"rgba(0,0,0,0.7)",color:"#fff",padding:"6px 12px",borderRadius:"4px",fontSize:"14px",zIndex:10,pointerEvents:"none",minWidth:"120px",userSelect:"none"},children:Fe[de]==="stack"?lt.jsxs(lt.Fragment,{children:[lt.jsxs("div",{children:["Image: ",(Fi=se[de])==null?void 0:Fi.index," / ",(ao=se[de])==null?void 0:ao.total]}),lt.jsxs("div",{children:["WC: ",(Ui=se[de])==null?void 0:Ui.windowCenter,"   WW: ",(mi=se[de])==null?void 0:mi.windowWidth]})]}):lt.jsxs("div",{children:["Slice: ",(Ka=se[de])==null?void 0:Ka.index," / ",(Bo=se[de])==null?void 0:Bo.total,((Bi=se[de])==null?void 0:Bi.slicePosition)&<.jsxs("span",{children:["   (",(qa=se[de])==null?void 0:qa.slicePosition,")"]}),lt.jsx("br",{}),"WC: ",(Gi=se[de])==null?void 0:Gi.windowCenter,"   WW: ",(ia=se[de])==null?void 0:ia.windowWidth]})}),lt.jsx("div",{style:{position:"absolute",right:8,bottom:8,zIndex:10,pointerEvents:"auto"},children:lt.jsxs("div",{className:"preset-menu",style:{background:"rgba(0,0,0,0.7)",color:"#fff",borderRadius:"4px",fontSize:"14px",minWidth:"120px",overflow:"hidden",cursor:"pointer",position:"relative",boxShadow:ht[de]?"0 2px 8px rgba(0,0,0,0.3)":void 0,pointerEvents:"auto"},onClick:_e=>_e.stopPropagation(),children:[lt.jsxs("div",{style:{padding:"6px 12px",fontWeight:"bold",userSelect:"none"},onClick:_e=>{_e.stopPropagation(),wt(ye=>{const je=[...ye];return je[de]=!je[de],je})},children:["Presets",lt.jsx("span",{style:{float:"right",fontWeight:"normal"},children:ht[de]?"▲":"▼"})]}),ht[de]&<.jsx("div",{className:"preset-menu-content",style:{background:"rgba(0,0,0,0.95)",borderRadius:"0 0 4px 4px",padding:"6px 0 6px 0",display:"flex",flexDirection:"column",zIndex:11,pointerEvents:"auto"},onClick:_e=>_e.stopPropagation(),children:Hxe.map(_e=>lt.jsx("button",{style:{display:"block",width:"100%",margin:"2px 0",background:"#333",color:"#fff",border:"none",borderRadius:"3px",cursor:"pointer",padding:"4px 0",fontSize:"13px",opacity:.9},onClick:ye=>{ye.stopPropagation(),pi(de,_e.center,_e.width),wt(je=>{const ot=[...je];return ot[de]=!1,ot})},children:_e.name},_e.name))})]})}),Fe[de]==="stack"&&I[de]&<.jsx("div",{style:{position:"absolute",top:"10%",right:8,width:"12px",height:"80%",maxHeight:"100%",minHeight:0,zIndex:30,display:I[de].length>0?"flex":"none",alignItems:"flex-start",justifyContent:"center",pointerEvents:"none",flexDirection:"column",padding:0},children:lt.jsx("div",{style:{width:"8px",height:"100%",maxHeight:"100%",minHeight:0,borderRadius:"6px",background:"#222",position:"relative",display:"flex",flexDirection:"column",justifyContent:"flex-start",boxShadow:"0 0 8px #2196f3cc",overflow:"hidden"},children:I[de].map((_e,ye)=>{const je=!!mt("imagePlaneModule",_e),ot=x.current;let st=-1;if(ot&&typeof ot.getViewport=="function"){const rt=ot.getViewport(`CT_${de}`);rt&&typeof rt.getCurrentImageIdIndex=="function"&&(st=rt.getCurrentImageIdIndex())}const ut=ye===st;return lt.jsx("div",{style:{width:"100%",height:`${100/I[de].length}%`,background:ut?"linear-gradient(to right, #ffeb3b 60%, #ff9800 100%)":je?"linear-gradient(to right, #4caf50 60%, #2196f3 100%)":"#444",opacity:je?.95:.4,transition:"background 0.3s, opacity 0.3s",borderBottom:ye{const rt=x.current,Ct=rt==null?void 0:rt.getViewport(`CT_${de}`);Ct&&typeof Ct.setImageIdIndex=="function"&&Fe[de]==="stack"&&(Aa(Ct.element,{imageIndex:ye}),Qn(de,Ct))}},_e)})})}),Fe[de]==="volume"&&(()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);let je=0,ot=0;return ye&&typeof ye.getNumberOfSlices=="function"&&typeof ye.getSliceIndex=="function"&&(je=ye.getNumberOfSlices(),ot=ye.getSliceIndex()),je>1?lt.jsx("div",{style:{position:"absolute",top:"10%",right:8,width:"12px",height:"80%",maxHeight:"100%",minHeight:0,zIndex:30,display:"flex",alignItems:"flex-start",justifyContent:"center",pointerEvents:"auto",flexDirection:"column",padding:0},children:lt.jsx("div",{style:{width:"8px",height:"100%",maxHeight:"100%",minHeight:0,borderRadius:"6px",background:"#222",position:"relative",display:"flex",flexDirection:"column",justifyContent:"flex-start",boxShadow:"0 0 8px #2196f3cc",overflow:"hidden",cursor:"pointer"},onClick:st=>{const rt=st.currentTarget.getBoundingClientRect(),Ct=st.clientY-rt.top,Qt=Math.floor(Ct/rt.height*je),on=x.current,cn=on==null?void 0:on.getViewport(`CT_${de}`);cn&&(Aa(cn.element,{imageIndex:Qt}),cn.render(),Qn(de,cn))},children:Array.from({length:je}).map((st,ut)=>{const rt=ut===ot;return lt.jsx("div",{style:{width:"100%",height:`${100/je}%`,minHeight:rt?1:0,background:rt?"linear-gradient(to right, #ffeb3b 60%, #ff9800 100%)":"#444",opacity:rt?.95:.4,transition:"background 0.3s, opacity 0.3s",borderBottom:ut1||!I[de]||I[de].length===0)&<.jsx("div",{style:{position:"absolute",left:0,right:0,bottom:8,zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",width:"100%",background:"none",borderRadius:"0",padding:0},children:lt.jsxs("div",{style:{position:"relative"},children:[lt.jsxs("button",{style:{background:"#222",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"2px 8px",fontSize:"13px",marginRight:"6px",minWidth:120,textAlign:"left",cursor:"pointer"},onClick:()=>v(p===de?null:de),"aria-haspopup":"listbox","aria-expanded":p===de,children:[(()=>{const _e=T[L[de]||0],ye=_e==null?void 0:_e.studyInstanceUID,ot=fr&&ye&&fr===ye?"#4caf50":"#888";return lt.jsxs("span",{children:[lt.jsx("span",{style:{color:ot,fontWeight:"bold",marginRight:6,fontSize:"16px",verticalAlign:"middle"},children:"●"}),"Stack ",L[de]+1," (",(_e==null?void 0:_e.imageIds.length)||0," images)"]})})(),lt.jsx("span",{style:{float:"right",fontSize:"12px"},children:"▼"})]}),p===de&<.jsx("div",{ref:_e=>{_e&&_e.focus()},tabIndex:0,style:{position:"absolute",left:0,bottom:"110%",background:"#222",border:"1px solid #444",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.3)",zIndex:100,minWidth:180,maxHeight:220,overflowY:"auto",overscrollBehavior:"contain",scrollbarWidth:"thin"},role:"listbox",onMouseDown:_e=>_e.stopPropagation(),onWheel:_e=>{const ye=_e.currentTarget,{scrollTop:je,scrollHeight:ot,clientHeight:st}=ye,ut=je===0,rt=je+st>=ot-1;_e.deltaY<0&&ut||_e.deltaY>0&&rt||(_e.stopPropagation(),_e.preventDefault(),ye.scrollTop+=_e.deltaY)},onBlur:_e=>{const ye=_e.relatedTarget,je=_e.currentTarget.parentElement;je!=null&&je.contains(ye)||setTimeout(()=>v(null),100)},children:T.map((_e,ye)=>{const je=_e.studyInstanceUID,st=fr&&je&&fr===je?"#4caf50":"#888",ut=_e.imageIds.length===0;return lt.jsxs("div",{role:"option","aria-selected":L[de]===ye,style:{padding:"6px 12px",background:L[de]===ye?"#444":"#222",color:ut?"#aaa":"#fff",cursor:ut?"not-allowed":"pointer",display:"flex",alignItems:"center",fontWeight:L[de]===ye?"bold":"normal",borderBottom:"1px solid #333",userSelect:"none",opacity:ut?.6:1},tabIndex:-1,onMouseDown:rt=>{rt.preventDefault(),ut||(j(de,ye),v(null))},children:[lt.jsx("span",{style:{color:st,fontWeight:"bold",marginRight:8,fontSize:"16px",verticalAlign:"middle"},children:"●"}),"Stack ",ye+1," (",_e.imageIds.length," images",ut&<.jsx("span",{style:{color:"#f44336",marginLeft:6},children:"(empty)"}),")"]},ye)})})]})})]},de))}return lt.jsxs("div",{ref:a,style:{position:"relative",inset:0,width:"100%",height:"100%",boxSizing:"border-box",background:"#222",padding:"12px",overflow:"hidden"},children:[k&<.jsx("div",{style:{position:"absolute",zIndex:3e3,top:0,left:0,width:"100%",height:"100%",background:"rgba(0,0,0,0.7)",color:"#fff",display:"flex",alignItems:"center",justifyContent:"center",fontSize:28,fontWeight:"bold",letterSpacing:1},children:k==="annotations"?"Loading Annotations...":"Loading Viewer State..."}),lt.jsxs("div",{children:[lt.jsx("button",{style:{position:"absolute",top:"50%",transform:"translateY(-50%)",left:Be?250:-20,zIndex:200,width:40,height:40,background:"#222",color:"#fff",border:"none",borderRadius:"50%",fontWeight:"bold",cursor:"pointer",fontSize:"22px",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",transition:"left 0.25s cubic-bezier(.4,2,.6,1), background 0.2s"},onClick:()=>ft(de=>!de),"aria-label":"Open menu",children:"☰"}),Be&<.jsx("div",{style:{position:"absolute",top:0,left:0,width:220,height:"100%",background:"#222",color:"#fff",zIndex:199,boxShadow:"2px 0 12px rgba(0,0,0,0.3)",flexDirection:"column",padding:"24px 16px 16px 16px",display:"flex",overflow:"hidden"},children:lt.jsxs("div",{style:{flex:1,minHeight:0,overflowY:"auto",display:"flex",flexDirection:"column"},children:[lt.jsxs("div",{style:{fontWeight:"bold",fontSize:18,marginBottom:24},children:["Menu",lt.jsx("button",{style:{float:"right",background:"transparent",color:"#fff",border:"none",fontSize:"22px",cursor:"pointer"},onClick:()=>ft(!1),"aria-label":"Close menu",children:"×"})]}),lt.jsx("button",{style:{padding:"10px 18px",background:"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>{var de;return(de=Ut.current)==null?void 0:de.click()},children:"Load DICOM Folder"}),lt.jsx("input",{ref:Ut,type:"file",style:{display:"none"},multiple:!0,onChange:Sn,accept:".dcm,application/dicom"}),lt.jsxs("div",{style:{marginBottom:"18px",display:"flex",alignItems:"center",gap:"8px"},children:[lt.jsx("input",{type:"checkbox",id:"orderBySliceLocation",checked:Ne,onChange:de=>ze(de.target.checked),style:{accentColor:"#666"}}),lt.jsx("label",{htmlFor:"orderBySliceLocation",style:{fontSize:"15px",cursor:"pointer"},children:"Order by Slice Location"})]}),lt.jsx("button",{style:{padding:"10px 18px",background:"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:fn,children:"Show DICOM Metadata"}),lt.jsxs("button",{style:{padding:"10px 18px",background:Y?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>re(de=>!de),children:[Y?"Disable":"Enable"," Cross Reference Lines"]}),lt.jsxs("button",{style:{padding:"10px 18px",background:ue?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>ce(de=>!de),children:[ue?"Disable":"Enable"," Reference Lines"]}),lt.jsx("button",{onClick:B,style:{margin:8,padding:8},children:"Sort All Viewports by Slice Location"}),lt.jsx("button",{style:{padding:"10px 18px",background:ie?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>ae(de=>!de),children:ie?"Disable Alt Key for Reference Cursors":"Enable Alt Key for Reference Cursors"}),lt.jsxs("button",{style:{padding:"10px 18px",background:S?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>_(de=>!de),children:[S?"Hide":"Show"," Annotation Navigation"]})]})})]}),lt.jsxs("div",{className:"grid-menu-hover-container",style:{position:"absolute",top:0,left:"50%",transform:"translateX(-50%)",zIndex:100,display:"flex",flexDirection:"column",alignItems:"center",width:"auto",height:"48px",pointerEvents:"none"},children:[lt.jsx("div",{style:{position:"absolute",top:0,left:"50%",transform:"translateX(-50%)",width:80,height:14,zIndex:1,pointerEvents:"auto",background:"transparent"},onMouseEnter:()=>_n(!0),onFocus:()=>_n(!0),tabIndex:-1}),lt.jsx("button",{style:{position:"relative",top:Pt?"0":"-22px",opacity:Pt?1:.5,transition:"top 0.25s cubic-bezier(.4,2,.6,1), opacity 0.2s",padding:"6px 16px",background:"#222",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginLeft:"4px",marginRight:"8px",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",pointerEvents:Pt?"auto":"none",zIndex:2,display:Pt?"block":"none"},title:"Toggle Fullscreen",onClick:()=>{const de=document.querySelector(".dicom-viewer-root");de&&(document.fullscreenElement===de?document.exitFullscreen():de.requestFullscreen?de.requestFullscreen():de.webkitRequestFullscreen?de.webkitRequestFullscreen():de.msRequestFullscreen&&de.msRequestFullscreen())},children:"⛶ Fullscreen"}),lt.jsxs("button",{className:"grid-menu-btn",style:{position:"relative",top:Pt?"0":"-22px",opacity:Pt?1:.5,transition:"top 0.25s cubic-bezier(.4,2,.6,1), opacity 0.2s",padding:"6px 16px",background:"#222",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginRight:"8px",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",pointerEvents:Pt?"auto":"none",zIndex:2,display:Pt?"block":"none"},onMouseLeave:()=>_n(!1),onBlur:()=>_n(!1),onClick:()=>Z(de=>!de),tabIndex:0,children:["Grid: ",z.rows,"x",z.cols," ▼"]}),K&<.jsx("div",{style:{position:"absolute",top:"110%",left:"50%",transform:"translateX(-50%)",background:"#222",color:"#fff",borderRadius:"6px",boxShadow:"0 2px 12px rgba(0,0,0,0.4)",padding:"12px",display:"grid",gridTemplateColumns:"repeat(3, 40px)",gap:"8px",zIndex:200,pointerEvents:"auto"},children:we.map(de=>lt.jsxs("button",{style:{width:"40px",height:"40px",background:de.rows===z.rows&&de.cols===z.cols?"#444":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px"},onClick:()=>{sn(),W({rows:de.rows,cols:de.cols}),Z(!1)},children:[de.rows,"x",de.cols]},`${de.rows}x${de.cols}`))})]}),lt.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"grid",margin:3,gridTemplateRows:`repeat(${z.rows}, 1fr)`,gridTemplateColumns:`repeat(${z.cols}, 1fr)`,gap:"5px",zIndex:1},children:Da}),lt.jsx("button",{style:{position:"absolute",top:8,right:8,zIndex:20,padding:"6px 12px",background:"#222",color:"#fff",border:"none",borderRadius:"4px",cursor:"pointer",opacity:.85,userSelect:"none"},onClick:()=>d(!0),children:"Settings"}),u&<.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",background:"rgba(0,0,0,0.4)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>d(!1),children:lt.jsxs("div",{style:{background:"#222",color:"#fff",borderRadius:"8px",minWidth:"320px",minHeight:"180px",padding:"24px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)",position:"relative"},onClick:de=>de.stopPropagation(),children:[lt.jsx("div",{style:{fontSize:"20px",marginBottom:"16px"},children:"Settings"}),lt.jsxs("div",{style:{marginBottom:"24px"},children:[lt.jsx("div",{style:{marginBottom:12,fontWeight:"bold"},children:"Mouse Button Tool Bindings"}),Fb.map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label," Button:"]}),lt.jsx("select",{value:gt[de.value],onChange:Ue=>Ie(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))})]},de.value)),lt.jsxs("div",{style:{margin:"12px 0"},children:[lt.jsxs("button",{style:{background:"#333",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 12px",cursor:"pointer",fontSize:"14px",marginBottom:"8px"},onClick:()=>Ee(de=>!de),children:[pe?"Hide":"Show"," Advanced Mouse Bindings"]}),pe&<.jsx("div",{style:{marginTop:8},children:Xm.slice(3).map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label,":"]}),lt.jsxs("select",{value:gt[de.value]||"",onChange:Ue=>Ie(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:[lt.jsx("option",{value:"",children:"(None)"}),ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))]})]},de.value))})]}),lt.jsx("div",{style:{margin:"18px 0 8px 0",fontWeight:"bold"},children:"Ctrl + Mouse Button Tool Bindings"}),Fb.map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label," + Ctrl:"]}),lt.jsxs("select",{value:$e[de.value]||"",onChange:Ue=>tt(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:[lt.jsx("option",{value:"",children:"(None)"}),ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))]})]},de.value+"_ctrl")),lt.jsxs("div",{style:{margin:"12px 0"},children:[lt.jsxs("button",{style:{background:"#333",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 12px",cursor:"pointer",fontSize:"14px",marginBottom:"8px"},onClick:()=>Se(de=>!de),children:[Oe?"Hide":"Show"," Advanced Ctrl + Mouse Bindings"]}),Oe&<.jsx("div",{style:{marginTop:8},children:Xm.slice(3).map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label," + Ctrl:"]}),lt.jsxs("select",{value:$e[de.value]||"",onChange:Ue=>tt(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:[lt.jsx("option",{value:"",children:"(None)"}),ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))]})]},de.value+"_ctrl"))})]})]}),lt.jsx("button",{style:{position:"absolute",top:12,right:12,background:"transparent",color:"#fff",border:"none",fontSize:"20px",cursor:"pointer"},onClick:()=>d(!1),"aria-label":"Close",children:"×"})]})}),Lt&<.jsx("div",{style:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",background:"rgba(0,0,0,0.5)",zIndex:2e3,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>xt(!1),children:lt.jsxs("div",{style:{background:"#222",color:"#fff",borderRadius:"8px",minWidth:"320px",maxWidth:"80vw",maxHeight:"80vh",padding:"24px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)",position:"relative",overflow:"auto"},onClick:de=>de.stopPropagation(),children:[lt.jsx("div",{style:{fontSize:"20px",marginBottom:"16px"},children:"DICOM Metadata"}),Ft,lt.jsx("button",{style:{position:"absolute",top:12,right:12,background:"transparent",color:"#fff",border:"none",fontSize:"20px",cursor:"pointer"},onClick:()=>xt(!1),"aria-label":"Close",children:"×"})]})})]})}function Kxe(t){console.log("Setting up tools...",t),Ci(j0),Ci(H0),Ci(id),Ci(q0),Ci(K0),Ci(Iu),Ci(nl),Ci(Ou),Ci(tl),Ci(od),Ci(bu),Ci(ic),Ci(X0),Ci(ua),Ci(Fs),Ci(Gf),Ci(Z0);let e=Kr(t);return e||(e=hN(t),e.addTool(H0.toolName),e.addTool(j0.toolName),e.addTool(q0.toolName),e.addTool(id.toolName,{loop:!1}),e.addTool(K0.toolName),e.addTool(Iu.toolName),e.addTool(Z0.toolName,{getTextCallback:()=>""}),e.addTool(Ou.toolName),e.addTool(nl.toolName,{statsCalculator:()=>null}),e.addTool(tl.toolName,{calculateStats:!1,getTextCallback:()=>""}),e.addTool(od.toolName,{getTextCallback:()=>""}),e.addTool(bu.toolName,{calculateStats:!1}),e.addTool(ic.toolName,{}),e.addTool(X0.toolName,{}),e.addTool(Gf.toolName),e.addTool(ua.toolName)),e}function Bb(t,e,r,n){if(!r.length||!e.length)return null;const i=r.map(o=>e.findIndex(a=>a===o.metadata.referencedImageId)).filter(o=>o!==-1).sort((o,a)=>o-a);if(!i.length)return null;if(n===1){for(let o of i)if(o>t)return o;return i[0]}else{for(let o=i.length-1;o>=0;o--)if(i[o]`wadouri:/test_images/stack2/IMG${r+1}.dcm`),Array.from({length:25},(e,r)=>`wadouri:/test_images/stack5/IMG${r+1}.dcm`),Array.from({length:26},(e,r)=>`wadouri:/test_images/stack3/IMG${r+1}.dcm`)]}const Gb=t=>t.map(e=>e.startsWith("wadouri:")?e:`wadouri:${e}`);function dG(){document.querySelectorAll(".dicom-viewer-test-root").forEach(r=>{const n=r.id||"",i=()=>qxe();Tx(r).render(lt.jsx(Ub,{container_id:n,imageStacks:i}))}),document.querySelectorAll(".dicom-viewer-root").forEach(r=>{const n=r.id||"";let i;const o=r.getAttribute("data-images");if(o){let f;try{f=JSON.parse(o)}catch(u){console.error("Invalid data-images JSON:",u),f=[]}Array.isArray(f)&&f.length>0&&typeof f[0]=="string"?i=()=>Promise.resolve([Gb(f)]):Array.isArray(f)?i=()=>Promise.resolve(f.map(u=>Array.isArray(u)?Gb(u):[])):i=()=>Promise.resolve([[]])}else i=()=>Promise.resolve([[]]);const a=r.getAttribute("data-auto-cache-stack"),s=a==="true"||a==="1",c=r.getAttribute("data-annotationjson"),l=r.getAttribute("data-viewerstate");console.log("Mounting DICOM viewer:"),console.log(l,c,s),Tx(r).render(lt.jsx(Ub,{container_id:n,imageStacks:i,autoCacheStack:s,annotationJson:c||void 0,viewerState:l||void 0}))})}dG();window.mountDicomViewers=dG; +`,Tt.push(pt);var Xn=Uu(Function,Tt).apply(null,dn);return Xn}function Go($,H,R,U,q,le){T(H>0);var he=so(H,R);q=gr(U,q),Vi([],[$],function(ve){ve=ve[0];var Te="constructor "+ve.name;if(ve.registeredClass.constructor_body===void 0&&(ve.registeredClass.constructor_body=[]),ve.registeredClass.constructor_body[H-1]!==void 0)throw new oo("Cannot register multiple constructors with identical number of parameters ("+(H-1)+") for class '"+ve.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");return ve.registeredClass.constructor_body[H-1]=()=>{ci("Cannot construct "+ve.name+" due to unbound types",he)},Vi([],he,function(be){return be.splice(1,0,null),ve.registeredClass.constructor_body[H-1]=Wi(Te,be,null,q,le),[]}),[]})}function fc($,H,R,U,q,le,he,ve){var Te=so(R,U);H=fr(H),le=gr(q,le),Vi([],[$],function(be){be=be[0];var ke=be.name+"."+H;H.startsWith("@@")&&(H=Symbol[H.substring(2)]),ve&&be.registeredClass.pureVirtualFunctions.push(H);function Je(){ci("Cannot call "+ke+" due to unbound types",Te)}var pt=be.registeredClass.instancePrototype,Mt=pt[H];return Mt===void 0||Mt.overloadTable===void 0&&Mt.className!==be.name&&Mt.argCount===R-2?(Je.argCount=R-2,Je.className=be.name,pt[H]=Je):(qn(pt,H,ke),pt[H].overloadTable[R-2]=Je),Vi([],Te,function(Tt){var dn=Wi(ke,Tt,be,le,he);return pt[H].overloadTable===void 0?(dn.argCount=R-2,pt[H]=dn):pt[H].overloadTable[R-2]=dn,[]}),[]})}var Ja=[],Ji=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function fl($){$>4&&--Ji[$].refcount===0&&(Ji[$]=void 0,Ja.push($))}function Bu(){for(var $=0,H=5;H($||yn("Cannot use deleted val. handle = "+$),Ji[$].value),toHandle:$=>{switch($){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:{var H=Ja.length?Ja.pop():Ji.length;return Ji[H]={refcount:1,value:$},H}}}};function hl($,H){H=fr(H),Qr($,{name:H,fromWireType:function(R){var U=Za.toValue(R);return fl(R),U},toWireType:function(R,U){return Za.toHandle(U)},argPackAdvance:8,readValueFromPointer:Mr,destructorFunction:null})}function dc($){if($===null)return"null";var H=typeof $;return H==="object"||H==="array"||H==="function"?$.toString():""+$}function Wu($,H){switch(H){case 2:return function(R){return this.fromWireType(Y[R>>2])};case 3:return function(R){return this.fromWireType(re[R>>3])};default:throw new TypeError("Unknown float type: "+$)}}function zu($,H,R){var U=To(R);H=fr(H),Qr($,{name:H,fromWireType:function(q){return q},toWireType:function(q,le){return le},argPackAdvance:8,readValueFromPointer:Wu(H,U),destructorFunction:null})}function $u($,H,R,U,q,le){var he=so(H,R);$=fr($),q=gr(U,q),At($,function(){ci("Cannot call "+$+" due to unbound types",he)},H-1),Vi([],he,function(ve){var Te=[ve[0],null].concat(ve.slice(1));return Xa($,Wi($,Te,null,q,le),H-1),[]})}function ju($,H,R){switch(H){case 0:return R?function(q){return V[q]}:function(q){return G[q]};case 1:return R?function(q){return A[q>>1]}:function(q){return k[q>>1]};case 2:return R?function(q){return F[q>>2]}:function(q){return j[q>>2]};default:throw new TypeError("Unknown integer type: "+$)}}function Hu($,H,R,U,q){H=fr(H);var le=To(R),he=Je=>Je;if(U===0){var ve=32-8*R;he=Je=>Je<>>ve}var Te=H.includes("unsigned"),be=(Je,pt)=>{},ke;Te?ke=function(Je,pt){return be(pt,this.name),pt>>>0}:ke=function(Je,pt){return be(pt,this.name),pt},Qr($,{name:H,fromWireType:he,toWireType:ke,argPackAdvance:8,readValueFromPointer:ju(H,le,U!==0),destructorFunction:null})}function Ku($,H,R){var U=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],q=U[H];function le(he){he=he>>2;var ve=j,Te=ve[he],be=ve[he+1];return new q(L,be,Te)}R=fr(R),Qr($,{name:R,fromWireType:le,argPackAdvance:8,readValueFromPointer:le},{ignoreDuplicateRegistrations:!0})}function qu($,H){H=fr(H);var R=H==="std::string";Qr($,{name:H,fromWireType:function(U){var q=j[U>>2],le=U+4,he;if(R)for(var ve=le,Te=0;Te<=q;++Te){var be=le+Te;if(Te==q||G[be]==0){var ke=be-ve,Je=b(ve,ke);he===void 0?he=Je:(he+="\0",he+=Je),ve=be+1}}else{for(var pt=new Array(q),Te=0;Te>2]=le,R&&he)P(q,Te,le+1);else if(he)for(var be=0;be255&&(me(Te),yn("String has UTF-16 code units that do not fit in 8 bits")),G[Te+be]=ke}else for(var be=0;be>1,q=U+H/2;!(U>=q)&&k[U];)++U;if(R=U<<1,R-$>32&&gl)return gl.decode(G.subarray($,R));for(var le="",he=0;!(he>=H/2);++he){var ve=A[$+he*2>>1];if(ve==0)break;le+=String.fromCharCode(ve)}return le}function pl($,H,R){if(R===void 0&&(R=2147483647),R<2)return 0;R-=2;for(var U=H,q=R<$.length*2?R/2:$.length,le=0;le>1]=he,H+=2}return A[H>>1]=0,H-U}function ml($){return $.length*2}function Yu($,H){for(var R=0,U="";!(R>=H/4);){var q=F[$+R*4>>2];if(q==0)break;if(++R,q>=65536){var le=q-65536;U+=String.fromCharCode(55296|le>>10,56320|le&1023)}else U+=String.fromCharCode(q)}return U}function hc($,H,R){if(R===void 0&&(R=2147483647),R<4)return 0;for(var U=H,q=U+R-4,le=0;le<$.length;++le){var he=$.charCodeAt(le);if(he>=55296&&he<=57343){var ve=$.charCodeAt(++le);he=65536+((he&1023)<<10)|ve&1023}if(F[H>>2]=he,H+=4,H+4>q)break}return F[H>>2]=0,H-U}function vl($){for(var H=0,R=0;R<$.length;++R){var U=$.charCodeAt(R);U>=55296&&U<=57343&&++R,H+=4}return H}function yl($,H,R){R=fr(R);var U,q,le,he,ve;H===2?(U=Xu,q=pl,he=ml,le=()=>k,ve=1):H===4&&(U=Yu,q=hc,he=vl,le=()=>j,ve=2),Qr($,{name:R,fromWireType:function(Te){for(var be=j[Te>>2],ke=le(),Je,pt=Te+4,Mt=0;Mt<=be;++Mt){var Tt=Te+4+Mt*H;if(Mt==be||ke[Tt>>ve]==0){var dn=Tt-pt,ln=U(pt,dn);Je===void 0?Je=ln:(Je+="\0",Je+=ln),pt=Tt+H}}return me(Te),Je},toWireType:function(Te,be){typeof be!="string"&&yn("Cannot pass non-string to C++ string type "+R);var ke=he(be),Je=te(4+ke+H);return j[Je>>2]=ke>>ve,q(be,Je+4,ke+H),Te!==null&&Te.push(me,Je),Je},argPackAdvance:8,readValueFromPointer:Mr,destructorFunction:function(Te){me(Te)}})}function gc($,H,R,U,q,le){bn[$]={name:fr(H),rawConstructor:gr(R,U),rawDestructor:gr(q,le),fields:[]}}function Ju($,H,R,U,q,le,he,ve,Te,be){bn[$].fields.push({fieldName:fr(H),getterReturnType:R,getter:gr(U,q),getterContext:le,setterArgumentType:he,setter:gr(ve,Te),setterContext:be})}function wl($,H){H=fr(H),Qr($,{isVoid:!0,name:H,argPackAdvance:0,fromWireType:function(){},toWireType:function(R,U){}})}function Zu($){$>4&&(Ji[$].refcount+=1)}function xl($,H){var R=ft[$];return R===void 0&&yn(H+" has unknown type "+vi($)),R}function Qu($,H){$=xl($,"_emval_take_value");var R=$.readValueFromPointer(H);return Za.toHandle(R)}function ef(){Ne("")}function tf($,H,R){G.copyWithin($,H,H+R)}function nf(){return 2147483648}function pc($){try{return S.grow($-L.byteLength+65535>>>16),ue(S.buffer),1}catch{}}function mc($){var H=G.length;$=$>>>0;var R=nf();if($>R)return!1;let U=(Te,be)=>Te+(be-Te%be)%be;for(var q=1;q<=4;q*=2){var le=H*(1+.2/q);le=Math.min(le,$+100663296);var he=Math.min(R,U(Math.max($,le),65536)),ve=pc(he);if(ve)return!0}return!1}function oa($){return 52}function Ia($,H,R,U,q){return 70}var Eo=[null,[],[]];function Cl($,H){var R=Eo[$];H===0||H===10?(($===1?w:x)(D(R,0)),R.length=0):R.push(H)}function Sl($,H,R,U){for(var q=0,le=0;le>2],ve=j[H+4>>2];H+=8;for(var Te=0;Te>2]=q,0}function vc($){return $}function _l($){var H=o["_"+$];return H}function Is($,H){V.set($,H)}function Tl($,H,R,U,q){var le={string:Tt=>{var dn=0;if(Tt!=null&&Tt!==0){var ln=(Tt.length<<2)+1;dn=it(ln),P(Tt,dn,ln)}return dn},array:Tt=>{var dn=it(Tt.length);return Is(Tt,dn),dn}};function he(Tt){return H==="string"?b(Tt):H==="boolean"?!!Tt:Tt}var ve=_l($),Te=[],be=0;if(U)for(var ke=0;ke0||(Se(),Z>0))return;function H(){et||(et=!0,o.calledRun=!0,!_&&(B(),a(o),o.onRuntimeInitialized&&o.onRuntimeInitialized(),O()))}o.setStatus?(o.setStatus("Running..."),setTimeout(function(){setTimeout(function(){o.setStatus("")},1),H()},1)):H()}if(o.preInit)for(typeof o.preInit=="function"&&(o.preInit=[o.preInit]);o.preInit.length>0;)o.preInit.pop()();return Ye(),o.ready}})();t.exports=r})(cG);var Mxe=cG.exports;const Pxe=ac(Mxe),Rxe=new URL("/static/dv3d/openjphjs.wasm",import.meta.url),Sg={codec:void 0,decoder:void 0,decodeConfig:{}};function Lxe(t,e,r){const n={width:e,height:r};for(;t>0;)n.width=Math.ceil(n.width/2),n.height=Math.ceil(n.height/2),t--;return n}function Axe(t){if(Sg.decodeConfig=t,Sg.codec)return Promise.resolve();const e=Pxe({locateFile:r=>r.endsWith(".wasm")?Rxe.toString():r});return new Promise((r,n)=>{e.then(i=>{Sg.codec=i,Sg.decoder=new i.HTJ2KDecoder,r()},n)})}async function Nxe(t,e){await Axe();const r=new Sg.codec.HTJ2KDecoder,n=r.getEncodedBuffer(t.length);n.set(t);const i=e.decodeLevel||0;r.decodeSubResolution(i);const o=r.getFrameInfo();if(e.decodeLevel>0){const{width:E,height:D}=Lxe(e.decodeLevel,o.width,o.height);o.width=E,o.height=D}const a=r.getDecodedBuffer();new Uint8Array(a.length).set(a);const c=`x: ${r.getImageOffset().x}, y: ${r.getImageOffset().y}`,l=r.getNumDecompositions(),f=r.getNumLayers(),u=["unknown","LRCP","RLCP","RPCL","PCRL","CPRL"][r.getProgressionOrder()+1],d=r.getIsReversible(),h=`${r.getBlockDimensions().width} x ${r.getBlockDimensions().height}`,g=`${r.getTileSize().width} x ${r.getTileSize().height}`,p=`${r.getTileOffset().x}, ${r.getTileOffset().y}`,v=`${a.length.toLocaleString()} bytes`,y=`${(a.length/n.length).toFixed(2)}:1`,m={columns:o.width,rows:o.height,bitsPerPixel:o.bitsPerSample,signed:o.isSigned,bytesPerPixel:e.bytesPerPixel,componentsPerPixel:o.componentCount};let w=kxe(o,a);const{buffer:x,byteOffset:C,byteLength:S}=w,_=x.slice(C,C+S);w=new w.constructor(_);const T={imageOffset:c,numDecompositions:l,numLayers:f,progessionOrder:u,reversible:d,blockDimensions:h,tileSize:g,tileOffset:p,decodedSize:v,compressionRatio:y};return{...e,pixelData:w,imageInfo:m,encodeOptions:T,...T,...m}}function kxe(t,e){return t.bitsPerSample>8?t.isSigned?new Int16Array(e.buffer,e.byteOffset,e.byteLength/2):new Uint16Array(e.buffer,e.byteOffset,e.byteLength/2):t.isSigned?new Int8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function Vxe(t,e){const r=t.length,{rescaleSlope:n,rescaleIntercept:i,suvbw:o,doseGridScaling:a}=e;if(e.modality==="PT"&&typeof o=="number"&&!isNaN(o))for(let s=0;s>o;let a=t.pixelData;t.pixelDataLength=t.pixelData.length;const{min:s,max:c}=X5(t.pixelData),l=typeof e.allowFloatRendering<"u"?e.allowFloatRendering:!0;let f=dE(t.photometricInterpretation)&&((m=e.targetBuffer)==null?void 0:m.offset)===void 0;const d=((w=e.preScale)==null?void 0:w.enabled)&&Object.values(e.preScale.scalingParameters).some(C=>typeof C=="number"&&!Number.isInteger(C)),h=!e.preScale.enabled||!l&&d,g=(x=e.targetBuffer)==null?void 0:x.type;if(g&&e.preScale.enabled&&!h){const C=e.preScale.scalingParameters,S=sS(s,c,C);f=!v3e(S.min,S.max,Ab[g])}g&&!f?a=Gxe(e,t,Ab,a):e.preScale.enabled&&!h?a=Wxe(e,s,c,t):a=lG(s,c,t);let p=s,v=c;if(e.preScale.enabled&&!h){const C=e.preScale.scalingParameters;if(uG(C),Bxe(C)){Vxe(a,C),t.preScale={...e.preScale,scaled:!0};const _=sS(s,c,C);p=_.min,v=_.max}}else h&&(t.preScale={enabled:!0,scaled:!1},p=s,v=c);t.pixelData=a,t.smallestPixelValue=p,t.largestPixelValue=v;const y=new Date().getTime();return t.decodeTimeInMS=y-r,t}function Bxe(t){const{rescaleSlope:e,rescaleIntercept:r,modality:n,doseGridScaling:i,suvbw:o}=t;return typeof e=="number"&&typeof r=="number"||n==="RTDOSE"&&typeof i=="number"||n==="PT"&&typeof o=="number"}function Gxe(t,e,r,n){const{arrayBuffer:i,type:o,offset:a=0,length:s,rows:c}=t.targetBuffer,l=r[o];if(!l)throw new Error(`target array ${o} is not supported, or doesn't exist.`);c&&c!=e.rows&&$xe(e,t.targetBuffer,l);const f=e.pixelDataLength,u=a,d=s??f-u,h=e.pixelData;if(d!==h.length)throw new Error(`target array for image does not have the same length (${d}) as the decoded image length (${h.length}).`);const g=i?new l(i,u,d):new l(d);return g.set(h,0),n=g,n}function Wxe(t,e,r,n){const i=t.preScale.scalingParameters;uG(i);const o=sS(e,r,i);return lG(o.min,o.max,n)}function lG(t,e,r){const n=hE(t,e),i=new n(r.pixelData.length);return i.set(r.pixelData,0),i}function sS(t,e,r){const{rescaleSlope:n,rescaleIntercept:i,modality:o,doseGridScaling:a,suvbw:s}=r;return o==="PT"&&typeof s=="number"&&!isNaN(s)?{min:s*(t*n+i),max:s*(e*n+i)}:o==="RTDOSE"&&typeof a=="number"&&!isNaN(a)?{min:t*a,max:e*a}:typeof n=="number"&&typeof i=="number"?{min:n*t+i,max:n*e+i}:{min:t,max:e}}function uG(t){if(!t)throw new Error("options.preScale.scalingParameters must be defined if preScale.enabled is true, and scalingParameters cannot be derived from the metadata providers.")}function zxe(t,e,r){const{samplesPerPixel:n}=t,{rows:i,columns:o}=e,a=i*o*n,s=new r(a),c=s.byteLength/a;return{pixelData:s,rows:i,columns:o,frameInfo:{...t.frameInfo,rows:i,columns:o},imageInfo:{...t.imageInfo,rows:i,columns:o,bytesPerPixel:c}}}function $xe(t,e,r){const n=zxe(t,e,r),{scalingType:i="replicate"}=e;return Fxe[i](t,n),Object.assign(t,n),t.pixelDataLength=t.pixelData.length,t}async function fG(t,e,r,n,i,o){const a=new Date().getTime();let s=null,c;switch(e){case"1.2.840.10008.1.2":case"1.2.840.10008.1.2.1":s=Ob(t,r);break;case"1.2.840.10008.1.2.2":s=rxe(t,r);break;case"1.2.840.10008.1.2.1.99":s=Ob(t,r);break;case"1.2.840.10008.1.2.5":s=ixe(t,r);break;case"1.2.840.10008.1.2.4.50":c={...t},s=dxe(r,c);break;case"1.2.840.10008.1.2.4.51":s=vxe(t,r);break;case"1.2.840.10008.1.2.4.57":s=Pb(t,r);break;case"1.2.840.10008.1.2.4.70":s=Pb(t,r);break;case"1.2.840.10008.1.2.4.80":c={signed:t.pixelRepresentation===1,bytesPerPixel:t.bitsAllocated<=8?1:2,...t},s=Rb(r,c);break;case"1.2.840.10008.1.2.4.81":c={signed:t.pixelRepresentation===1,bytesPerPixel:t.bitsAllocated<=8?1:2,...t},s=Rb(r,c);break;case"1.2.840.10008.1.2.4.90":c={...t},s=Lb(r,c);break;case"1.2.840.10008.1.2.4.91":c={...t},s=Lb(r,c);break;case"3.2.840.10008.1.2.4.96":case"1.2.840.10008.1.2.4.201":case"1.2.840.10008.1.2.4.202":case"1.2.840.10008.1.2.4.203":c={...t},s=Nxe(r,c);break;default:throw new Error(`no decoder for transfer syntax ${e}`)}if(!s)throw new Error("decodePromise not defined");const l=await s,f=Uxe(l,i,a);return o==null||o(f),f}const jxe={decodeTask({imageFrame:t,transferSyntax:e,decodeConfig:r,options:n,pixelData:i,callbackFn:o}){return fG(t,e,i,r,n,o)}};iT(jxe);const Nb={constants:Q3e,convertRGBColorByPixel:xB,convertRGBColorByPlane:CB,convertYBRFullByPixel:SB,convertYBRFullByPlane:_B,convertPALETTECOLOR:TB,wadouri:S3e,wadors:K3e,init:rG,convertColorSpace:zB,createImage:Y5,decodeJPEGBaseline8BitColor:$B,getImageFrame:jB,getPixelData:vE,getMinMax:X5,isColorImage:dE,isJPEGBaseline8BitColor:J3e,internal:Vwe,decodeImageFrame:fG};class Z0 extends Ou{}VE(Z0,"toolName","NoLabelArrowAnnotate");function kb(t,e){const r=mt("imagePlaneModule",t);if(!r)return;const{rowCosines:n,columnCosines:i,imagePositionPatient:o,rowPixelSpacing:a,columnPixelSpacing:s}=r;if(!n||!i||!o)return;const c=s||1,l=a||1,f=n,u=i,d=o;return[d[0]+e.x*u[0]*c+e.y*f[0]*l,d[1]+e.x*u[1]*c+e.y*f[1]*l,d[2]+e.x*u[2]*c+e.y*f[2]*l]}window.cornerstone3dTools=Twe;const{MouseBindings:tg,KeyboardBindings:Vb}=nN,{IMAGE_RENDERED:qm}=Xe,Hxe=[{name:"Soft Tissue",center:40,width:400},{name:"Lung",center:-600,width:1500},{name:"Bone",center:300,width:1500},{name:"Brain",center:40,width:80},{name:"Abdomen",center:60,width:400}],ng=[{label:"Window/Level",value:H0.toolName},{label:"Pan",value:j0.toolName},{label:"Zoom",value:q0.toolName},{label:"Stack Scroll",value:id.toolName},{label:"Rotate",value:K0.toolName},{label:"Length",value:Iu.toolName},{label:"Probe",value:nl.toolName},{label:"Arrow (No Label)",value:Z0.toolName},{label:"Arrow Annotate",value:Ou.toolName},{label:"Rectangle ROI",value:tl.toolName},{label:"Ellipse ROI",value:od.toolName},{label:"Freehand ROI",value:bu.toolName},{label:"Freehand Contour Segmentation",value:ic.toolName},{label:"Sculptor",value:X0.toolName},{label:"Reference Cursors",value:ua.toolName}],Fb=[{label:"Left",value:"Primary"},{label:"Middle",value:"Auxiliary"},{label:"Right",value:"Secondary"}],Xm=[{label:"Left",value:"Primary",mask:1},{label:"Middle",value:"Auxiliary",mask:4},{label:"Right",value:"Secondary",mask:2},{label:"Left + Right",value:"Primary_and_Secondary",mask:3},{label:"Left + Middle",value:"Primary_and_Auxiliary",mask:5},{label:"Right + Middle",value:"Secondary_and_Auxiliary",mask:6},{label:"Left + Right + Middle",value:"Primary_and_Secondary_and_Auxiliary",mask:7},{label:"Fourth Button",value:"Fourth_Button",mask:8},{label:"Fifth Button",value:"Fifth_Button",mask:16},{label:"Mouse Wheel",value:"Wheel",mask:524288},{label:"Mouse Wheel + Left",value:"Wheel_Primary",mask:524289}];function Ub({container_id:t,imageStacks:e,autoCacheStack:r,annotationJson:n,viewerState:i,...o}){var Fi,ao,Ui,mi,Ka,Bo,Bi,qa,Gi,ia;const a=Nt.useRef(null),s=Nt.useRef(null),c=Nt.useRef(!1),[l,f]=Nt.useState(!1),[u,d]=Nt.useState(!1),[h,g]=Nt.useState(null),[p,v]=Nt.useState(null),y=9,m="renderingEngine_"+t,w="TOOL_GROUP_"+t,x=Nt.useRef(null),C=Nt.useRef(!1),[S,_]=Nt.useState(!0),[T,E]=Nt.useState([]),[D,b]=Nt.useState(0),[I,P]=Nt.useState(()=>Array(y).fill([])),M=de=>{typeof de=="function"?P(Ue=>{const _e=de(Ue);return console.log("setViewportImageIds (fn):",_e),_e}):(console.log("setViewportImageIds:",de),P(de))},[L,V]=Nt.useState(()=>Array(y).fill(0)),[G,A]=Nt.useState(!1),[k,F]=Nt.useState(null);Nt.useEffect(()=>{let de=!1;if(n||i){F(n?"annotations":"viewerState");const Ue=setTimeout(()=>{if(de)return;const _e=t||"default";if(n)try{const ye=window[`importAnnotations_${_e}`]||window.importAnnotations;typeof ye=="function"&&ye(n)}catch(ye){console.error("Failed to import annotations from prop:",ye)}if(i)try{const ye=window[`importViewerState_${_e}`]||window.importViewerState;typeof ye=="function"&&ye(i)}catch(ye){console.error("Failed to import viewer state from prop:",ye)}F(null)},2e3);return()=>{de=!0,clearTimeout(Ue),F(null)}}},[n,i,t]),Nt.useEffect(()=>{e().then(async de=>{const Ue=await Promise.all(de.map(async _e=>{let ye;try{const je=_e[0];if(je&&je.startsWith("wadouri:")){const ot=je.slice(8),ut=await(await fetch(ot)).arrayBuffer();ye=Tr.parseDicom(new Uint8Array(ut)).string("x0020000d")}}catch{}return{imageIds:_e,studyInstanceUID:ye}}));E(Ue),await O(de[0]),M(Array(y).fill(de[0]||[]))})},[]);const j=async(de,Ue)=>{const _e=T[Ue];if(!_e)return;const ye=_e.imageIds;oe(je=>{const ot=[...je];return ot[de]="stack",ot}),M(je=>{const ot=[...je];return ot[de]=ye,ot}),V(je=>{const ot=[...je];return ot[de]=Ue,ot}),await O(ye)},[Y,re]=Nt.useState(!1),[ue,ce]=Nt.useState(!0),[pe,Ee]=Nt.useState(!1),[Oe,Se]=Nt.useState(!1),B=()=>{console.log("Sorting viewport imageIds by slice location"),M(de=>{const Ue=de.map((_e,ye)=>{if(!_e||_e.length===0)return _e;const st=[..._e.map(ut=>{const rt=mt("imagePlaneModule",ut);let Ct=null;return rt&&(rt.sliceLocation!==void 0?Ct=Number(rt.sliceLocation):rt.imagePositionPatient&&Array.isArray(rt.imagePositionPatient)&&rt.imagePositionPatient.length===3&&(Ct=Number(rt.imagePositionPatient[2]))),{imageId:ut,sortKey:Ct}})].sort((ut,rt)=>ut.sortKey!==null&&rt.sortKey!==null?ut.sortKey-rt.sortKey:ut.imageId.localeCompare(rt.imageId)).map(ut=>ut.imageId);return JSON.stringify(st)===JSON.stringify(_e)?_e:st});return A(!0),Ue})},O=async de=>{console.log("Setting loaded imageIds:",de),console.log("autoCacheStack:",r);const Ue=[];if(r){for(const _e of de)if(_e.startsWith("wadouri:"))try{const ye=_e.slice(8);if(Nb.wadouri.dataSetCacheManager){const je=Nb.wadouri.dataSetCacheManager.load(ye);je&&typeof je.then=="function"&&Ue.push(je)}else console.warn("MetaDataManager not found. Unable to cache metadata.")}catch(ye){console.warn(`Failed to cache metadata for ${_e}:`,ye)}await Promise.all(Ue),Ne&&(console.log("Sorting viewport imageIds by slice location"),B())}},[z,W]=Nt.useState({rows:1,cols:1}),[K,Z]=Nt.useState(!1),ee=Nt.useRef([]),xe=Nt.useRef({}),De=Nt.useRef({}),[Ne,ze]=Nt.useState(!1),[ie,ae]=Nt.useState(!0),we=[];for(let de=1;de<=3;de++)for(let Ue=1;Ue<=3;Ue++)we.push({rows:de,cols:Ue});const[se,ge]=Nt.useState(()=>Array(z.rows*z.cols).fill({index:0,total:0,windowCenter:"",windowWidth:"",slicePosition:0})),[Fe,oe]=Nt.useState(()=>Array(y).fill("stack")),[ht,wt]=Nt.useState(()=>Array(z.rows*z.cols).fill(!1)),[gt,Ie]=Nt.useState({Primary:id.toolName,Auxiliary:j0.toolName,Secondary:H0.toolName,Primary_and_Secondary:q0.toolName,Fourth_Button:K0.toolName,Wheel:id.toolName}),[$e,tt]=Nt.useState({Primary:Iu.toolName,Auxiliary:nl.toolName,Secondary:Z0.toolName}),[nt,dt]=Nt.useState(!1);Nt.useEffect(()=>{const de=_e=>{_e.ctrlKey&&dt(!0)},Ue=_e=>{_e.ctrlKey||dt(!1)};return window.addEventListener("keydown",de),window.addEventListener("keyup",Ue),()=>{window.removeEventListener("keydown",de),window.removeEventListener("keyup",Ue)}},[]);const[Lt,xt]=Nt.useState(!1),[Ft,jt]=Nt.useState(null),Pn=(de,Ue)=>{Ro&&Ro(Ue),yn(_e=>{const ye=[..._e];return ye[de]=Ue,ye})},$n=(de,Ue,_e)=>{const ye=Rr.getAllAnnotations()||[];ye.forEach(ot=>{ot.annotationUID===Ue&&(ot.isSelected=!1)}),Rr.removeAnnotation(Ue),x.current.render();const je=_e.filter(ot=>ot.annotationUID!==Ue);yn(ot=>{const st=[...ot],ut=je.length>0?je[0].annotationUID:null;return st[de]=ut,ye.forEach(rt=>{rt.isSelected=rt.annotationUID===ut}),Ro(ut),x.current.render(),st})},fn=()=>{const de=I.findIndex(je=>je&&je.length>0);if(de===-1){jt("No images loaded."),xt(!0);return}const Ue=I[de][0],_e=["imagePlaneModule","generalSeriesModule","generalStudyModule","patientModule","imagePixelModule","voiLutModule","modalityLutModule","sopCommonModule","petIsotopeModule","multiframeModule","cineModule","overlayPlaneModule","generalImageModule","stackModule","voiLutModule","modalityLutModule","petSeriesModule","petImageModule","petIsotopeModule","petSeriesModule","petImageModule","petIsotopeModule","petSeriesModule","petImageModule","petIsotopeModule","petSeriesModule","petImageModule","petIsotopeModule"],ye={};_e.forEach(je=>{const ot=mt(je,Ue);ot!==void 0&&(ye[je]=ot)}),jt(lt.jsx("pre",{style:{maxHeight:600,overflow:"auto",fontSize:13,color:"#fff"},children:JSON.stringify(ye,null,2)})),xt(!0)};Nt.useEffect(()=>(window.loadDicomStackFromFiles=de=>{const Ue=Array.from(de);Sn({target:{files:Ue}})},()=>{window.loadDicomStackFromFiles=void 0}),[]);const[bn,Xi]=Nt.useState(!1);Nt.useEffect(()=>{const de=Kr(w);de&&["ArrowAnnotate","NoLabelArrowAnnotate","Length","RectangleROI","EllipticalROI","PlanarFreehandROI","PlanarFreehandContourSegmentation"].forEach(Ue=>{de.setToolConfiguration(Ue,{color:"#00e676",selectedColor:"#ffeb3b"})})},[w]),Nt.useEffect(()=>{const de=_e=>{_e.altKey&&Xi(!0)},Ue=_e=>{_e.altKey||Xi(!1)};return window.addEventListener("keydown",de),window.addEventListener("keyup",Ue),()=>{window.removeEventListener("keydown",de),window.removeEventListener("keyup",Ue)}},[]),Nt.useEffect(()=>{if(!ie)return;const de=Kr(w);de&&(bn?(de.hasTool(ua.toolName)||de.addTool(ua.toolName),de.setToolEnabled(ua.toolName),de.setToolActive(ua.toolName)):de.hasTool(ua.toolName)&&de.setToolDisabled(ua.toolName))},[bn,ie]);const Mr=Nt.useCallback(()=>{[Kr(w)].forEach(Ue=>{if(Ue){ng.forEach(ye=>{Ue.setToolPassive(ye.value,{removeAllBindings:!0})}),Ue.setToolDisabled(ua.toolName);const _e={};Object.entries(gt).forEach(([ye,je])=>{_e[je]||(_e[je]=[]);const ot=Xm.find(st=>st.value===ye);ot?_e[je].push({mouseButton:ot.mask}):tg[ye]&&_e[je].push({mouseButton:tg[ye]})}),Object.entries($e).forEach(([ye,je])=>{if(!je)return;_e[je]||(_e[je]=[]);const ot=Xm.find(st=>st.value===ye);ot?_e[je].push({mouseButton:ot.mask,modifierKey:Vb.Ctrl}):tg[ye]&&_e[je].push({mouseButton:tg[ye],modifierKey:Vb.Ctrl})}),Object.entries(_e).forEach(([ye,je])=>{Ue.setToolActive(ye,{bindings:je})})}})},[gt,$e]),[Be,ft]=Nt.useState(!1),Ut=Nt.useRef(null),Sn=async de=>{const Ue=de.target.files;if(!Ue||Ue.length===0)return;ze(!1);const _e=Array.from(Ue).sort((ut,rt)=>ut.name.localeCompare(rt.name));let ye;const je=await _e[0].arrayBuffer();ye=Tr.parseDicom(new Uint8Array(je)).string("x0020000d"),console.log("StudyInstanceUID:",ye);const st=_e.map(ut=>`wadouri:${URL.createObjectURL(ut)}`);E(ut=>{const rt=[...ut,{imageIds:st,studyInstanceUID:ye}];return M(Ct=>{const Qt=[...Ct];return Qt[0]=st,Qt}),V(Ct=>{const Qt=[...Ct];return Qt[0]=rt.length-1,Qt}),O(st),rt})},Qn=Nt.useCallback((de,Ue)=>{if(!Ue)return;let _e=0,ye=0,je="",ot="",st="";if(Fe[de]==="stack"){if(_e=typeof Ue.getCurrentImageIdIndex=="function"?Ue.getCurrentImageIdIndex():0,ye=(typeof Ue.getImageIds=="function"?Ue.getImageIds():[]).length,typeof Ue.getProperties=="function"){const rt=Ue.getProperties();if(rt.voiRange){const{lower:Ct,upper:Qt}=rt.voiRange;je=((Qt+Ct)/2).toFixed(0),ot=(Qt-Ct).toFixed(0)}}}else if(Fe[de]==="volume"){if(typeof Ue.getSliceIndex=="function"&&(_e=Ue.getSliceIndex()),typeof Ue.getNumberOfSlices=="function"&&(ye=Ue.getNumberOfSlices()),typeof Ue.getProperties=="function"){let ut;if(Ue.volumeIds&&Ue.volumeIds.size>0){const rt=Array.from(Ue.volumeIds)[0];ut=Ue.getProperties(rt)}else ut=Ue.getProperties();if(ut&&ut.voiRange){const{lower:rt,upper:Ct}=ut.voiRange;je=((Ct+rt)/2).toFixed(0),ot=(Ct-rt).toFixed(0)}}if(typeof Ue.getSlicePlaneCoordinates=="function"){const ut=Ue.getSlicePlaneCoordinates();ut&&typeof ut.position=="number"&&(st=ut.position.toFixed(2)+" mm")}}ge(ut=>{const rt=[...ut];return rt[de]={index:_e+1,total:ye,windowCenter:je,windowWidth:ot,slicePosition:st},rt})},[Fe]),[Pt,_n]=Nt.useState(!1);function sn(){for(let de=0;de{const de=async()=>{var ot;console.log("setup"),c.current||(c.current=!0,await WZ(),await iF(),rG());let _e=x.current;_e||(_e=new CA(m),x.current=_e);let ye=Kr(w);ye||(ye=Kxe(w)),Fe.slice(0,z.rows*z.cols).filter(st=>st==="volume").length,Vi(ye);for(let st=0;st{if(Ct.offsetWidth>0&&Ct.offsetHeight>0){_e.resize();const xn=_e.getViewport(rt);xn&&typeof xn.resize=="function"&&xn.resize(),xn&&typeof xn.render=="function"&&xn.render()}});Gt.observe(Ct),Ct._resizeObserver=Gt}if(Fe[st]==="stack")ut&&ut.length>0&&on.setStack(ut),Y?ye.removeViewports(m,rt):ye.addViewport(rt,m);else if(Fe[st]==="volume"){ye.addViewport(rt,m);const Gt=`myVolumeId_${st}`;(await Vv(Gt,{imageIds:ut})).load(),on.setVolumes([{volumeId:Gt}]),on.render(),Ct._overlayListener&&on.element.removeEventListener(qm,Ct._overlayListener);const er=()=>Qn(st,on);on.element.addEventListener(qm,er),Ct._overlayListener=er,Qn(st,on);continue}if(on.render(),!C.current){De.current[st]!==void 0&&typeof on.setImageIdIndex=="function"&&Aa(on.element,{imageIndex:De.current[st]});const Gt=xe.current[st];if(Gt&&typeof on.setProperties=="function"){const{voiRange:xn,invert:er,interpolationType:nr,VOILUTFunction:or,colormap:qn}=Gt,At={};xn&&xn.lower!==void 0&&xn.upper!==void 0&&(At.voiRange=xn),er!==void 0&&(At.invert=er),nr!==void 0&&(At.interpolationType=nr),or&&(At.VOILUTFunction=or),qn!=null&&(typeof qn=="string"||typeof qn=="object"&&!("actor"in qn))&&(At.colormap=qn),setTimeout(()=>{console.log("Restoring properties (timeout) for viewport",st,At),on.setProperties(At),on.render()},100)}}Ct._overlayListener&&on.element.removeEventListener(qm,Ct._overlayListener);const cn=()=>Qn(st,on);on.element.addEventListener(qm,cn),Ct._overlayListener=cn,Qn(st,on)}for(let st=0;st=2?(ye.hasTool(Fs.toolName)||ye.addTool(Fs.toolName),ye.setToolEnabled(Fs.toolName),ye.setToolConfiguration(Fs.toolName,{}),ye.setToolActive(Fs.toolName,{bindings:[{mouseButton:tg.Primary}]})):ye.hasTool(Fs.toolName)&&ye.setToolDisabled(Fs.toolName)),Mr()},Ue=requestAnimationFrame(()=>{de()});return()=>{ee.current.forEach(_e=>{_e&&_e._resizeObserver&&(_e._resizeObserver.disconnect(),delete _e._resizeObserver)}),cancelAnimationFrame(Ue)}},[s,Qn,z,Fe,I]);const rn=Nt.useCallback(de=>{const Ue=`CT_${de}`,ye=x.current.getViewport(Ue);ye&&typeof ye.resetCamera=="function"&&(ye.resetCamera(),console.log("Restoring viewport properties for viewport",de),ye.resetProperties(),ye.render())},[]),pi=Nt.useCallback((de,Ue,_e)=>{const ye=`CT_${de}`;try{const je=x.current;if(je){const ot=je.getViewport(ye);ot&&typeof ot.setProperties=="function"&&(console.log(`Applying preset to viewport ${de}: center=${Ue}, width=${_e}`),ot.setProperties({voiRange:{lower:Ue-_e/2,upper:Ue+_e/2}}),ot.render(),Qn(de,ot))}}catch{}},[Qn]);Nt.useEffect(()=>{ge(Array(z.rows*z.cols).fill({index:0,total:0,windowCenter:"",windowWidth:""})),wt(Array(z.rows*z.cols).fill(!1))},[z]),Nt.useEffect(()=>{Mr()},[gt,$e,nt,Mr]),Nt.useEffect(()=>{if(!l)return;const de=Ue=>{const _e=document.querySelector(".preset-menu");_e&&!_e.contains(Ue.target)&&f(!1)};return document.addEventListener("mousedown",de),()=>document.removeEventListener("mousedown",de)},[l]),Nt.useEffect(()=>{const de=Ue=>{if(Ue.button===3||Ue.button===4)return Ue.preventDefault(),!1};return window.addEventListener("mousedown",de,!0),window.addEventListener("mouseup",de,!0),window.addEventListener("auxclick",de,!0),()=>{window.removeEventListener("mousedown",de,!0),window.removeEventListener("mouseup",de,!0),window.removeEventListener("auxclick",de,!0)}},[]),Nt.useEffect(()=>{const de=a.current;if(!de)return;const Ue=_e=>{_e.preventDefault()};return de.addEventListener("contextmenu",Ue),()=>{de.removeEventListener("contextmenu",Ue)}},[]),Nt.useEffect(()=>{if(!ue)return;const de=Kr(w);Vi(de)},[D,ue]),Nt.useEffect(()=>{Ut.current&&(Ut.current.setAttribute("webkitdirectory","true"),Ut.current.setAttribute("directory","true"))},[]),Nt.useEffect(()=>(window.loadDicomStackFromWadouriList=async de=>{if(!de||de.length===0)return;let Ue;try{const _e=de[0];if(_e&&_e.startsWith("wadouri:")){const ye=_e.slice(8),ot=await(await fetch(ye)).arrayBuffer();Ue=Tr.parseDicom(new Uint8Array(ot)).string("x0020000d")}}catch{}E(_e=>{const ye=[..._e,{imageIds:de,studyInstanceUID:Ue}];return M(je=>{const ot=[...je];return ot[0]=de,ot}),V(je=>{const ot=[...je];return ot[0]=ye.length-1,ot}),O(de),ye})},()=>{window.loadDicomStackFromWadouriList=void 0}),[E,M,V,O]),Nt.useEffect(()=>{!Ne||!I.every(Ue=>!Ue||Ue.length===0||Ue.every(_e=>!!mt("imagePlaneModule",_e)))||M(Ue=>{let _e=!1;const ye=Ue.map(je=>{if(!je||je.length===0)return je;const ut=[...je.map(rt=>({imageId:rt,sliceLoc:(()=>{const Ct=mt("imagePlaneModule",rt);return Ct&&Ct.sliceLocation!==void 0?Number(Ct.sliceLocation):null})()}))].sort((rt,Ct)=>rt.sliceLoc!==null&&Ct.sliceLoc!==null?rt.sliceLoc-Ct.sliceLoc:rt.imageId.localeCompare(Ct.imageId)).map(rt=>rt.imageId);return JSON.stringify(ut)!==JSON.stringify(je)?(_e=!0,ut):je});return _e&&A(!0),ye})},[Ne,T]);function Vi(de){if(!de)return;const Ue=`CT_${D}`;ue?(de.setToolEnabled(Gf.toolName),de.setToolConfiguration(Gf.toolName,{sourceViewportId:Ue})):de.setToolDisabled(Gf.toolName)}function Ha(){var Ue,_e,ye;const de=x.current;if(de)for(let je=0;je=ye.length||de>=Ue)return alert("Invalid truncation bounds."),!1;const je=ye.slice(de,Ue+1);E([{..._e,imageIds:je}]),M([je]),V([0]);const ot=x.current;if(ot){const rt=ot.getViewport("CT_0");rt&&typeof rt.setStack=="function"&&(rt.setStack(je),(st=rt.setImageIdIndex)==null||st.call(rt,0),(ut=rt.render)==null||ut.call(rt))}return!0}function To(de=0){const Ue=x.current;if(!Ue)return null;const _e=Ue.getViewport(`CT_${de}`);return!_e||typeof _e.getCurrentImageIdIndex!="function"?null:_e.getCurrentImageIdIndex()}Nt.useEffect(()=>{const de=t||"default";function Ue(_e,ye){const je=x.current;if(!je)return;const ot=je.getViewport(`CT_${_e}`);if(!ot||typeof ot.getImageIds!="function")return;const ut=ot.getImageIds().map(Qt=>Qt.replace(/^wadouri:/,"")),rt=ye.replace(/^wadouri:/,""),Ct=ut.indexOf(rt);Ct!==-1&&typeof ot.setImageIdIndex=="function"&&(Aa(ot.element,{imageIndex:Ct}),Qn(_e,ot))}return window[`getViewport_${de}`]=_e=>{const ye=x.current;if(ye)return ye.getViewport(`CT_${_e}`)},window[`getAllViewports_${de}`]=()=>{const _e=x.current;return _e?Array.from({length:y},(ye,je)=>_e.getViewport(`CT_${je}`)).filter(Boolean):[]},window[`jumpToSliceByImageId_${de}`]=Ue,window[`resetViewer_${de}`]=Ha,window[`truncateStack_${de}`]=Ea,window[`getCurrentStackPosition_${de}`]=To,window[`loadAdditionalStack_${de}`]=async(_e,ye)=>{var ot;if(!Array.isArray(_e)||_e.length===0)return;let je=ye;if(!je&&((ot=_e[0])!=null&&ot.startsWith("wadouri:")))try{const st=_e[0].slice(8),rt=await(await fetch(st)).arrayBuffer();je=Tr.parseDicom(new Uint8Array(rt)).string("x0020000d")}catch{}E(st=>[...st,{imageIds:_e,studyInstanceUID:je}]),M(st=>{const ut=[...st],rt=ut.findIndex(Ct=>!Ct||Ct.length===0);return rt!==-1&&(ut[rt]=_e),ut}),O(_e)},window[`exportViewerState_${de}`]=()=>{var Gt;const _e=z.rows*z.cols,ye=Fe.slice(0,_e),je=L.slice(0,_e),ot=T.map(xn=>({i:xn.imageIds,u:xn.studyInstanceUID}));console.log("Exporting viewer state with",_e,"active viewports"),console.log("modes",ye);const st=x.current,ut=[],rt=[],Ct=[],Qt=[],on=[];for(let xn=0;xn<_e;xn++){let er=null,nr=null,or=null,qn=null,At=null;if(console.log("Exporting state for viewport",xn),st){console.log("Rendering engine found, exporting state for viewport",xn);const Bn=`CT_${xn}`,dr=st.getViewport(Bn);if(dr){if(typeof dr.getProperties=="function"){const{voiRange:si,invert:jn,interpolationType:wr,VOILUTFunction:ei,colormap:xr}=dr.getProperties();er={voiRange:si,invert:jn,interpolationType:wr,VOILUTFunction:ei,colormap:xr}}typeof dr.getCurrentImageIdIndex=="function"&&(nr=dr.getCurrentImageIdIndex()),typeof dr.getCamera=="function"&&(or=dr.getCamera()),console.log("viewport",Bn,"properties",er),ye[xn]==="volume"&&(console.log("Getting orientation for viewport",xn),console.log("viewport.viewportProperties",dr.viewportProperties),qn=((Gt=dr.viewportProperties)==null?void 0:Gt.orientation)||null,typeof dr.getSliceIndex=="function"&&(At=dr.getSliceIndex()))}}ut.push(er),rt.push(nr),Ct.push(or),Qt.push(qn),on.push(At)}return JSON.stringify({grid:z,modes:ye,stacks:ot,stackIdx:je,stackPos:rt,props:ut,cam:Ct,orientations:Qt,volumeSliceIndices:on})},window[`importViewerState_${de}`]=_e=>{try{C.current=!0;const ye=typeof _e=="string"?JSON.parse(_e):_e;if(ye.grid&&W(ye.grid),ye.modes&&oe(ye.modes),ye.stacks&&E(ye.stacks.map(ut=>({imageIds:ut.i,studyInstanceUID:ut.u}))),ye.stackIdx&&ye.stacks){const ut=ye.stackIdx.map(rt=>{var Ct;return((Ct=ye.stacks[rt])==null?void 0:Ct.i)||[]});M(ut),V(ye.stackIdx)}const je=30;let ot=0;async function st(){var Qt,on,cn,Gt,xn,er,nr,or,qn;const ut=x.current;if(!ut){C.current=!1;return}const rt=((Qt=ye.grid)==null?void 0:Qt.rows)*((on=ye.grid)==null?void 0:on.cols)||1;let Ct=!0;for(let At=0;Atei===jn[xr])){console.warn(`Viewport ${At}: importedImageIds do not match viewportImageIds`,{importedImageIds:jn,viewportImageIds:wr}),Ct=!1;break}}catch{Ct=!1}}if(!Ct&&ot{st()},500);return}for(let At=0;At{Aa(Bn.element,{imageIndex:ye.volumeSliceIndices[At]})},100)),Bn.render()}else Bn.setStack&&(Bn.setStack(jn),Bn.render()),ye.stackPos&&typeof ye.stackPos[At]=="number"&&typeof Bn.setImageIdIndex=="function"&&(Mn&&Aa?Aa(Bn.element,{imageIndex:ye.stackPos[At]}):Bn.setImageIdIndex(ye.stackPos[At]));if(ye.props&&ye.props[At]&&typeof Bn.setProperties=="function"){console.log("Restoring properties for viewport",At,ye.props[At]);const wr={...ye.props[At]};wr.colormap!==void 0&&wr.colormap!==null&&typeof wr.colormap!="string"&&(typeof wr.colormap!="object"||!("name"in wr.colormap))&&delete wr.colormap,setTimeout(()=>{Bn.setProperties(wr),Bn.render()},100)}else console.warn("No properties to restore for viewport",At);ye.cam&&ye.cam[At]&&typeof Bn.setCamera=="function"&&(console.log("Restoring camera for viewport",At,ye.cam[At]),Bn.setCamera(ye.cam[At]),Bn.render())}}C.current=!1}setTimeout(()=>{st()},100)}catch(ye){C.current=!1,alert("Failed to import viewer state: "+ye)}},window[`exportAnnotations_${de}`]=()=>{try{let _e=Rr.getAllAnnotations();if(console.log("Exporting annotations:",_e),Array.isArray(_e)){const ye=[Iu.toolName,Z0.toolName,Ou.toolName,tl.toolName,od.toolName,bu.toolName,ic.toolName,nl.toolName,X0.toolName];_e=_e.filter(je=>ye.includes(je.metadata.toolName))}else return"{}";return JSON.stringify(_e,null,2)}catch(_e){return alert("Failed to export annotations: "+_e),"{}"}},window[`importAnnotations_${de}`]=_e=>{try{const ye=typeof _e=="string"?JSON.parse(_e):_e;Rr.removeAllAnnotations&&Rr.removeAllAnnotations(),Array.isArray(ye)&&ye.forEach(je=>{Rr.addAnnotation(je,je.annotationUID)}),x.current&&x.current.render()}catch(ye){alert("Failed to import annotations: "+ye)}},window[`importLegacyAnnotations_${de}`]=_e=>{Rr.removeAllAnnotations&&Rr.removeAllAnnotations();let ye;try{ye=typeof _e=="string"?JSON.parse(_e):_e}catch{alert("Invalid legacy annotation JSON");return}const je={ArrowAnnotate:"ArrowAnnotate"};Object.entries(ye).forEach(([ot,st])=>{console.log("Importing legacy annotations for imageId:",ot),Object.entries(st).forEach(([ut,rt])=>{const Ct=je[ut]||ut;rt.data&&Array.isArray(rt.data)&&rt.data.forEach(Qt=>{const on=kb(ot,{x:Qt.handles.start.y,y:Qt.handles.start.x}),cn=kb(ot,{x:Qt.handles.end.y,y:Qt.handles.end.x});console.log("Importing legacy annotation:"),console.log(" Image ID:",ot),console.log(" Start World:",on),console.log(" End World:",cn);const Gt=mt("imagePlaneModule",ot);console.log(rL);let xn=mt("frameOfReferenceUID",ot);!xn&&Gt&&Gt.frameOfReferenceUID&&(xn=Gt.frameOfReferenceUID);const er=Gt!=null&&Gt.rowCosines&&(Gt!=null&&Gt.columnCosines)?[Gt.rowCosines[1]*Gt.columnCosines[2]-Gt.rowCosines[2]*Gt.columnCosines[1],Gt.rowCosines[2]*Gt.columnCosines[0]-Gt.rowCosines[0]*Gt.columnCosines[2],Gt.rowCosines[0]*Gt.columnCosines[1]-Gt.rowCosines[1]*Gt.columnCosines[0]]:void 0;Array.isArray(er)&&er.length,typeof Qt.rotation=="number"&&Qt.rotation;const nr={annotationUID:Qt.uuid,metadata:{toolName:Ct,referencedImageId:ot,FrameOfReferenceUID:xn,viewPlaneNormal:er},data:{handles:{points:[on,cn],textBox:Qt.handles.textBox},text:Qt.text||""},visibility:Qt.visible!==!1,active:Qt.active||!1};Rr.addAnnotation(nr,nr.annotationUID)})})}),x.current&&x.current.render()},window[`importLegacyViewport_${de}`]=_e=>{let ye;try{ye=typeof _e=="string"?JSON.parse(_e):_e}catch{alert("Invalid legacy viewport JSON");return}const je=x.current;if(!je)return;const ot=`CT_${D??0}`,st=je.getViewport(ot);if(!st)return;const ut={};if(ye.voi&&(ut.voiRange={lower:ye.voi.windowCenter-ye.voi.windowWidth/2,upper:ye.voi.windowCenter+ye.voi.windowWidth/2}),typeof ye.invert=="boolean"&&(ut.invert=ye.invert),typeof ye.pixelReplication=="boolean"&&(ut.interpolationType=ye.pixelReplication?0:1),typeof ye.hflip=="boolean"&&(ut.hflip=ye.hflip),typeof ye.vflip=="boolean"&&(ut.vflip=ye.vflip),typeof st.setProperties=="function"&&st.setProperties(ut),ye.translation||ye.scale){const rt=st.getCamera?st.getCamera():{};ye.translation&&(rt.translation={...rt.translation,...ye.translation}),ye.scale&&(rt.parallelScale=200/ye.scale),console.log("Applying legacy camera properties:",rt),typeof st.setCamera=="function"&&st.setCamera(rt)}typeof ye.rotation=="number"&&st.setRotation(ye.rotation),st.render(),Qn(D??0,st)},()=>{window[`exportViewerState_${de}`]=void 0,window[`importViewerState_${de}`]=void 0,window[`exportAnnotations_${de}`]=void 0,window[`importAnnotations_${de}`]=void 0,window[`importLegacyAnnotations_${de}`]=void 0,window[`importLegacyViewport_${de}`]=void 0,window[`jumpToSliceByImageId_${de}`]=void 0,window[`resetViewer_${de}`]=void 0,window[`truncateStack_${de}`]=void 0,window[`getCurrentStackPosition_${de}`]=void 0,window[`loadAdditionalStack_${de}`]=void 0,window[`getViewport_${de}`]=void 0,window[`getAllViewports_${de}`]=void 0}},[z,Fe,L,T,I,W,oe,V,E,M,E,M,O]),Nt.useEffect(()=>{function de(Ue){if(console.log("Handling arrow key navigation",Ue.key),console.log("activeViewport",D),D===null)return;const _e=x.current;if(!_e)return;const ye=_e.getViewport(`CT_${D}`);if(ye){if(console.log(ye),Fe[D]==="stack"){if(typeof ye.getCurrentImageIdIndex!="function"||typeof ye.setImageIdIndex!="function")return;const je=I[D];if(!je||je.length===0)return;Ue.key==="ArrowUp"||Ue.key==="ArrowRight"?(ps(ye,{delta:-1}),Ue.preventDefault()):(Ue.key==="ArrowDown"||Ue.key==="ArrowLeft")&&(ps(ye,{delta:1}),Ue.preventDefault())}Fe[D]==="volume"&&typeof ye.getSliceIndex=="function"&&typeof ye.getNumberOfSlices=="function"&&ye.getNumberOfSlices()>1&&(Ue.key==="ArrowUp"||Ue.key==="ArrowRight"?(ps(ye,{delta:-1}),Ue.preventDefault()):(Ue.key==="ArrowDown"||Ue.key==="ArrowLeft")&&(ps(ye,{delta:1}),Ue.preventDefault()))}}return window.addEventListener("keydown",de),()=>window.removeEventListener("keydown",de)},[D,Fe,I,Qn]);const ra=D!==null?L[D]:0,Uo=T[ra],fr=Uo==null?void 0:Uo.studyInstanceUID,[oo,yn]=Nt.useState(()=>Array(y).fill(null)),Qr=z.rows*z.cols,Da=[];for(let de=0;deee.current[de]=_e,style:{flex:1,border:Ue?"1px solid #222":"none",background:"#000",minWidth:0,minHeight:0,position:"relative",overflow:"hidden",flexDirection:"column",gridRow:Math.floor(de/z.cols)+1,gridColumn:de%z.cols+1,height:"100%",boxShadow:D===de?"0 0 0 4px #1976d2, 0 0 16px 4px #1976d2cc":void 0,zIndex:D===de?10:1},onClick:()=>{b(de),Z(!1)},onDoubleClick:()=>rn(de),children:[lt.jsx("button",{style:{position:"absolute",top:8,left:8,zIndex:20,background:"#333",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 8px",cursor:"pointer",fontSize:"12px",opacity:.85},onClick:()=>{oe(_e=>{const ye=[..._e];return ye[de]=_e[de]==="stack"?"volume":"stack",ye})},children:Fe[de]==="stack"?"Volume":"Stack"}),Fe[de]==="volume"&<.jsxs("div",{style:{position:"absolute",top:8,left:70,zIndex:21,display:"flex",gap:"6px",background:"rgba(34,34,34,0.85)",borderRadius:"4px",padding:"2px 6px",alignItems:"center"},children:[lt.jsx("button",{style:{background:"#444",color:"#fff",border:"none",borderRadius:"3px",padding:"2px 8px",cursor:"pointer",fontSize:"12px",marginRight:"2px"},onClick:()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);ye&&ye.setOrientation&&(ye.setOrientation("axial"),ye.render())},children:"Axial"}),lt.jsx("button",{style:{background:"#444",color:"#fff",border:"none",borderRadius:"3px",padding:"2px 8px",cursor:"pointer",fontSize:"12px",marginRight:"2px"},onClick:()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);ye&&ye.setOrientation&&(ye.setOrientation("sagittal"),ye.render())},children:"Sagittal"}),lt.jsx("button",{style:{background:"#444",color:"#fff",border:"none",borderRadius:"3px",padding:"2px 8px",cursor:"pointer",fontSize:"12px"},onClick:()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);ye&&ye.setOrientation&&(ye.setOrientation("coronal"),ye.render())},children:"Coronal"})]}),lt.jsxs("button",{style:{position:"absolute",top:40,left:8,zIndex:20,background:"#111",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 8px",cursor:"pointer",fontSize:"13px",opacity:.85,marginTop:"4px",display:"flex",alignItems:"center",gap:"6px"},title:"Toggle Fullscreen",onClick:_e=>{_e.stopPropagation();const ye=ee.current[de];document.fullscreenElement===ye?document.exitFullscreen():ye!=null&&ye.requestFullscreen?ye.requestFullscreen():ye!=null&&ye.webkitRequestFullscreen?ye.webkitRequestFullscreen():ye!=null&&ye.msRequestFullscreen&&ye.msRequestFullscreen()},onMouseEnter:()=>g(de),onMouseLeave:()=>g(null),children:[lt.jsx("span",{style:{fontSize:"18px",lineHeight:1},children:"⛶"}),h===de&<.jsx("span",{style:{marginLeft:6},children:document.fullscreenElement===ee.current[de]?"Exit Fullscreen":"Fullscreen"})]}),Fe[de]==="stack"&&S&&(()=>{var on;const _e=I[de],je=(Rr.getAllAnnotations()||[]).filter(cn=>cn.metadata&&cn.metadata.referencedImageId&&_e.includes(cn.metadata.referencedImageId)&&cn.metadata.toolName!==ua.toolName);if(!je.length)return null;const ot=x.current,st=ot==null?void 0:ot.getViewport(`CT_${de}`),ut=((on=st==null?void 0:st.getCurrentImageIdIndex)==null?void 0:on.call(st))??0,rt=_e[ut],Ct=je.filter(cn=>cn.metadata.referencedImageId===rt),Qt=oo[de];return lt.jsxs("div",{style:{position:"absolute",left:"50%",bottom:60,transform:"translateX(-50%)",zIndex:30,display:"flex",gap:4,pointerEvents:"auto",alignItems:"center"},children:[lt.jsx("button",{style:{background:"rgba(30,30,30,0.7)",color:"#fff",border:"none",borderRadius:"50%",width:28,height:28,fontSize:"16px",fontWeight:"bold",cursor:"pointer",opacity:.7,display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.18)",transition:"opacity 0.2s"},title:"Previous Annotation","aria-label":"Previous Annotation",onClick:()=>{const cn=x.current,Gt=cn==null?void 0:cn.getViewport(`CT_${de}`);if(!Gt||typeof Gt.getCurrentImageIdIndex!="function")return;const xn=Gt.getCurrentImageIdIndex(),er=Bb(xn,_e,je,-1);if(er!==null&&typeof Gt.setImageIdIndex=="function"){Aa(Gt.element,{imageIndex:er}),Qn(de,Gt);const nr=_e[er],or=je.filter(qn=>qn.metadata.referencedImageId===nr);Pn(de,or.length>0?or[0].annotationUID:null)}},children:lt.jsx("span",{"aria-hidden":"true",children:"◀"})}),lt.jsx("button",{style:{background:"rgba(30,30,30,0.7)",color:"#fff",border:"none",borderRadius:"50%",width:28,height:28,fontSize:"16px",fontWeight:"bold",cursor:"pointer",opacity:.7,display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 1px 4px rgba(0,0,0,0.18)",transition:"opacity 0.2s"},title:"Next Annotation","aria-label":"Next Annotation",onClick:()=>{const cn=x.current,Gt=cn==null?void 0:cn.getViewport(`CT_${de}`);if(!Gt||typeof Gt.getCurrentImageIdIndex!="function")return;const xn=Gt.getCurrentImageIdIndex(),er=Bb(xn,_e,je,1);if(er!==null&&typeof Gt.setImageIdIndex=="function"){Aa(Gt.element,{imageIndex:er}),Qn(de,Gt);const nr=_e[er],or=je.filter(qn=>qn.metadata.referencedImageId===nr);Pn(de,or.length>0?or[0].annotationUID:null)}},children:lt.jsx("span",{"aria-hidden":"true",children:"▶"})}),Ct.length>0&<.jsx("div",{style:{display:"flex",gap:2,alignItems:"center"},children:Ct.map(cn=>lt.jsxs("div",{style:{display:"flex",alignItems:"center",background:Qt===cn.annotationUID?"rgb(4, 225, 0)":"#444",color:Qt===cn.annotationUID?"#222":"#fff",borderRadius:"4px",padding:"2px 6px",marginRight:2,cursor:"pointer",border:Qt===cn.annotationUID?"2px solid #1976d2":"none",fontWeight:Qt===cn.annotationUID?"bold":"normal"},onClick:()=>Pn(de,cn.annotationUID),children:[lt.jsxs("span",{style:{marginRight:4},children:[Qt===cn.annotationUID?"★ ":"",cn.metadata.toolName||"Annotation"]}),lt.jsx("button",{style:{background:"#b71c1c",color:"#fff",border:"none",borderRadius:"50%",width:20,height:20,fontSize:"13px",fontWeight:"bold",cursor:"pointer",marginLeft:2,display:"flex",alignItems:"center",justifyContent:"center",opacity:.85},title:"Delete this annotation","aria-label":"Delete annotation",onClick:Gt=>{Gt.stopPropagation(),$n(de,cn.annotationUID,Ct)},children:"🗑️"})]},cn.annotationUID))})]})})(),lt.jsx("div",{style:{position:"absolute",left:8,bottom:8,background:"rgba(0,0,0,0.7)",color:"#fff",padding:"6px 12px",borderRadius:"4px",fontSize:"14px",zIndex:10,pointerEvents:"none",minWidth:"120px",userSelect:"none"},children:Fe[de]==="stack"?lt.jsxs(lt.Fragment,{children:[lt.jsxs("div",{children:["Image: ",(Fi=se[de])==null?void 0:Fi.index," / ",(ao=se[de])==null?void 0:ao.total]}),lt.jsxs("div",{children:["WC: ",(Ui=se[de])==null?void 0:Ui.windowCenter,"   WW: ",(mi=se[de])==null?void 0:mi.windowWidth]})]}):lt.jsxs("div",{children:["Slice: ",(Ka=se[de])==null?void 0:Ka.index," / ",(Bo=se[de])==null?void 0:Bo.total,((Bi=se[de])==null?void 0:Bi.slicePosition)&<.jsxs("span",{children:["   (",(qa=se[de])==null?void 0:qa.slicePosition,")"]}),lt.jsx("br",{}),"WC: ",(Gi=se[de])==null?void 0:Gi.windowCenter,"   WW: ",(ia=se[de])==null?void 0:ia.windowWidth]})}),lt.jsx("div",{style:{position:"absolute",right:8,bottom:8,zIndex:10,pointerEvents:"auto"},children:lt.jsxs("div",{className:"preset-menu",style:{background:"rgba(0,0,0,0.7)",color:"#fff",borderRadius:"4px",fontSize:"14px",minWidth:"120px",overflow:"hidden",cursor:"pointer",position:"relative",boxShadow:ht[de]?"0 2px 8px rgba(0,0,0,0.3)":void 0,pointerEvents:"auto"},onClick:_e=>_e.stopPropagation(),children:[lt.jsxs("div",{style:{padding:"6px 12px",fontWeight:"bold",userSelect:"none"},onClick:_e=>{_e.stopPropagation(),wt(ye=>{const je=[...ye];return je[de]=!je[de],je})},children:["Presets",lt.jsx("span",{style:{float:"right",fontWeight:"normal"},children:ht[de]?"▲":"▼"})]}),ht[de]&<.jsx("div",{className:"preset-menu-content",style:{background:"rgba(0,0,0,0.95)",borderRadius:"0 0 4px 4px",padding:"6px 0 6px 0",display:"flex",flexDirection:"column",zIndex:11,pointerEvents:"auto"},onClick:_e=>_e.stopPropagation(),children:Hxe.map(_e=>lt.jsx("button",{style:{display:"block",width:"100%",margin:"2px 0",background:"#333",color:"#fff",border:"none",borderRadius:"3px",cursor:"pointer",padding:"4px 0",fontSize:"13px",opacity:.9},onClick:ye=>{ye.stopPropagation(),pi(de,_e.center,_e.width),wt(je=>{const ot=[...je];return ot[de]=!1,ot})},children:_e.name},_e.name))})]})}),Fe[de]==="stack"&&I[de]&<.jsx("div",{style:{position:"absolute",top:"10%",right:8,width:"12px",height:"80%",maxHeight:"100%",minHeight:0,zIndex:30,display:I[de].length>0?"flex":"none",alignItems:"flex-start",justifyContent:"center",pointerEvents:"none",flexDirection:"column",padding:0},children:lt.jsx("div",{style:{width:"8px",height:"100%",maxHeight:"100%",minHeight:0,borderRadius:"6px",background:"#222",position:"relative",display:"flex",flexDirection:"column",justifyContent:"flex-start",boxShadow:"0 0 8px #2196f3cc",overflow:"hidden"},children:I[de].map((_e,ye)=>{const je=!!mt("imagePlaneModule",_e),ot=x.current;let st=-1;if(ot&&typeof ot.getViewport=="function"){const rt=ot.getViewport(`CT_${de}`);rt&&typeof rt.getCurrentImageIdIndex=="function"&&(st=rt.getCurrentImageIdIndex())}const ut=ye===st;return lt.jsx("div",{style:{width:"100%",height:`${100/I[de].length}%`,background:ut?"linear-gradient(to right, #ffeb3b 60%, #ff9800 100%)":je?"linear-gradient(to right, #4caf50 60%, #2196f3 100%)":"#444",opacity:je?.95:.4,transition:"background 0.3s, opacity 0.3s",borderBottom:ye{const rt=x.current,Ct=rt==null?void 0:rt.getViewport(`CT_${de}`);Ct&&typeof Ct.setImageIdIndex=="function"&&Fe[de]==="stack"&&(Aa(Ct.element,{imageIndex:ye}),Qn(de,Ct))}},_e)})})}),Fe[de]==="volume"&&(()=>{const _e=x.current,ye=_e==null?void 0:_e.getViewport(`CT_${de}`);let je=0,ot=0;return ye&&typeof ye.getNumberOfSlices=="function"&&typeof ye.getSliceIndex=="function"&&(je=ye.getNumberOfSlices(),ot=ye.getSliceIndex()),je>1?lt.jsx("div",{style:{position:"absolute",top:"10%",right:8,width:"12px",height:"80%",maxHeight:"100%",minHeight:0,zIndex:30,display:"flex",alignItems:"flex-start",justifyContent:"center",pointerEvents:"auto",flexDirection:"column",padding:0},children:lt.jsx("div",{style:{width:"8px",height:"100%",maxHeight:"100%",minHeight:0,borderRadius:"6px",background:"#222",position:"relative",display:"flex",flexDirection:"column",justifyContent:"flex-start",boxShadow:"0 0 8px #2196f3cc",overflow:"hidden",cursor:"pointer"},onClick:st=>{const rt=st.currentTarget.getBoundingClientRect(),Ct=st.clientY-rt.top,Qt=Math.floor(Ct/rt.height*je),on=x.current,cn=on==null?void 0:on.getViewport(`CT_${de}`);cn&&(Aa(cn.element,{imageIndex:Qt}),cn.render(),Qn(de,cn))},children:Array.from({length:je}).map((st,ut)=>{const rt=ut===ot;return lt.jsx("div",{style:{width:"100%",height:`${100/je}%`,minHeight:rt?1:0,background:rt?"linear-gradient(to right, #ffeb3b 60%, #ff9800 100%)":"#444",opacity:rt?.95:.4,transition:"background 0.3s, opacity 0.3s",borderBottom:ut1||!I[de]||I[de].length===0)&<.jsx("div",{style:{position:"absolute",left:0,right:0,bottom:8,zIndex:20,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",width:"100%",background:"none",borderRadius:"0",padding:0},children:lt.jsxs("div",{style:{position:"relative"},children:[lt.jsxs("button",{style:{background:"#222",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"2px 8px",fontSize:"13px",marginRight:"6px",minWidth:120,textAlign:"left",cursor:"pointer"},onClick:()=>v(p===de?null:de),"aria-haspopup":"listbox","aria-expanded":p===de,children:[(()=>{const _e=T[L[de]||0],ye=_e==null?void 0:_e.studyInstanceUID,ot=fr&&ye&&fr===ye?"#4caf50":"#888";return lt.jsxs("span",{children:[lt.jsx("span",{style:{color:ot,fontWeight:"bold",marginRight:6,fontSize:"16px",verticalAlign:"middle"},children:"●"}),"Stack ",L[de]+1," (",(_e==null?void 0:_e.imageIds.length)||0," images)"]})})(),lt.jsx("span",{style:{float:"right",fontSize:"12px"},children:"▼"})]}),p===de&<.jsx("div",{ref:_e=>{_e&&_e.focus()},tabIndex:0,style:{position:"absolute",left:0,bottom:"110%",background:"#222",border:"1px solid #444",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.3)",zIndex:100,minWidth:180,maxHeight:220,overflowY:"auto",overscrollBehavior:"contain",scrollbarWidth:"thin"},role:"listbox",onMouseDown:_e=>_e.stopPropagation(),onWheel:_e=>{const ye=_e.currentTarget,{scrollTop:je,scrollHeight:ot,clientHeight:st}=ye,ut=je===0,rt=je+st>=ot-1;_e.deltaY<0&&ut||_e.deltaY>0&&rt||(_e.stopPropagation(),_e.preventDefault(),ye.scrollTop+=_e.deltaY)},onBlur:_e=>{const ye=_e.relatedTarget,je=_e.currentTarget.parentElement;je!=null&&je.contains(ye)||setTimeout(()=>v(null),100)},children:T.map((_e,ye)=>{const je=_e.studyInstanceUID,st=fr&&je&&fr===je?"#4caf50":"#888",ut=_e.imageIds.length===0;return lt.jsxs("div",{role:"option","aria-selected":L[de]===ye,style:{padding:"6px 12px",background:L[de]===ye?"#444":"#222",color:ut?"#aaa":"#fff",cursor:ut?"not-allowed":"pointer",display:"flex",alignItems:"center",fontWeight:L[de]===ye?"bold":"normal",borderBottom:"1px solid #333",userSelect:"none",opacity:ut?.6:1},tabIndex:-1,onMouseDown:rt=>{rt.preventDefault(),ut||(j(de,ye),v(null))},children:[lt.jsx("span",{style:{color:st,fontWeight:"bold",marginRight:8,fontSize:"16px",verticalAlign:"middle"},children:"●"}),"Stack ",ye+1," (",_e.imageIds.length," images",ut&<.jsx("span",{style:{color:"#f44336",marginLeft:6},children:"(empty)"}),")"]},ye)})})]})})]},de))}return lt.jsxs("div",{ref:a,style:{position:"relative",inset:0,width:"100%",height:"100%",boxSizing:"border-box",background:"#222",padding:"12px",overflow:"hidden"},children:[k&<.jsx("div",{style:{position:"absolute",zIndex:3e3,top:0,left:0,width:"100%",height:"100%",background:"rgba(0,0,0,0.7)",color:"#fff",display:"flex",alignItems:"center",justifyContent:"center",fontSize:28,fontWeight:"bold",letterSpacing:1},children:k==="annotations"?"Loading Annotations...":"Loading Viewer State..."}),lt.jsxs("div",{children:[lt.jsx("button",{style:{position:"absolute",top:"50%",transform:"translateY(-50%)",left:Be?250:-20,zIndex:200,width:40,height:40,background:"#222",color:"#fff",border:"none",borderRadius:"50%",fontWeight:"bold",cursor:"pointer",fontSize:"22px",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",transition:"left 0.25s cubic-bezier(.4,2,.6,1), background 0.2s"},onClick:()=>ft(de=>!de),"aria-label":"Open menu",children:"☰"}),Be&<.jsx("div",{style:{position:"absolute",top:0,left:0,width:220,height:"100%",background:"#222",color:"#fff",zIndex:199,boxShadow:"2px 0 12px rgba(0,0,0,0.3)",flexDirection:"column",padding:"24px 16px 16px 16px",display:"flex",overflow:"hidden"},children:lt.jsxs("div",{style:{flex:1,minHeight:0,overflowY:"auto",display:"flex",flexDirection:"column"},children:[lt.jsxs("div",{style:{fontWeight:"bold",fontSize:18,marginBottom:24},children:["Menu",lt.jsx("button",{style:{float:"right",background:"transparent",color:"#fff",border:"none",fontSize:"22px",cursor:"pointer"},onClick:()=>ft(!1),"aria-label":"Close menu",children:"×"})]}),lt.jsx("button",{style:{padding:"10px 18px",background:"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>{var de;return(de=Ut.current)==null?void 0:de.click()},children:"Load DICOM Folder"}),lt.jsx("input",{ref:Ut,type:"file",style:{display:"none"},multiple:!0,onChange:Sn,accept:".dcm,application/dicom"}),lt.jsxs("div",{style:{marginBottom:"18px",display:"flex",alignItems:"center",gap:"8px"},children:[lt.jsx("input",{type:"checkbox",id:"orderBySliceLocation",checked:Ne,onChange:de=>ze(de.target.checked),style:{accentColor:"#666"}}),lt.jsx("label",{htmlFor:"orderBySliceLocation",style:{fontSize:"15px",cursor:"pointer"},children:"Order by Slice Location"})]}),lt.jsx("button",{style:{padding:"10px 18px",background:"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:fn,children:"Show DICOM Metadata"}),lt.jsxs("button",{style:{padding:"10px 18px",background:Y?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>re(de=>!de),children:[Y?"Disable":"Enable"," Cross Reference Lines"]}),lt.jsxs("button",{style:{padding:"10px 18px",background:ue?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>ce(de=>!de),children:[ue?"Disable":"Enable"," Reference Lines"]}),lt.jsx("button",{onClick:B,style:{margin:8,padding:8},children:"Sort All Viewports by Slice Location"}),lt.jsx("button",{style:{padding:"10px 18px",background:ie?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>ae(de=>!de),children:ie?"Disable Alt Key for Reference Cursors":"Enable Alt Key for Reference Cursors"}),lt.jsxs("button",{style:{padding:"10px 18px",background:S?"#1976d2":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginBottom:"18px",width:"100%"},onClick:()=>_(de=>!de),children:[S?"Hide":"Show"," Annotation Navigation"]})]})})]}),lt.jsxs("div",{className:"grid-menu-hover-container",style:{position:"absolute",top:0,left:"50%",transform:"translateX(-50%)",zIndex:100,display:"flex",flexDirection:"column",alignItems:"center",width:"auto",height:"48px",pointerEvents:"none"},children:[lt.jsx("div",{style:{position:"absolute",top:0,left:"50%",transform:"translateX(-50%)",width:80,height:14,zIndex:1,pointerEvents:"auto",background:"transparent"},onMouseEnter:()=>_n(!0),onFocus:()=>_n(!0),tabIndex:-1}),lt.jsx("button",{style:{position:"relative",top:Pt?"0":"-22px",opacity:Pt?1:.5,transition:"top 0.25s cubic-bezier(.4,2,.6,1), opacity 0.2s",padding:"6px 16px",background:"#222",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginLeft:"4px",marginRight:"8px",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",pointerEvents:Pt?"auto":"none",zIndex:2,display:Pt?"block":"none"},title:"Toggle Fullscreen",onClick:()=>{const de=document.querySelector(".dicom-viewer-root");de&&(document.fullscreenElement===de?document.exitFullscreen():de.requestFullscreen?de.requestFullscreen():de.webkitRequestFullscreen?de.webkitRequestFullscreen():de.msRequestFullscreen&&de.msRequestFullscreen())},children:"⛶ Fullscreen"}),lt.jsxs("button",{className:"grid-menu-btn",style:{position:"relative",top:Pt?"0":"-22px",opacity:Pt?1:.5,transition:"top 0.25s cubic-bezier(.4,2,.6,1), opacity 0.2s",padding:"6px 16px",background:"#222",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px",marginRight:"8px",boxShadow:"0 2px 8px rgba(0,0,0,0.2)",pointerEvents:Pt?"auto":"none",zIndex:2,display:Pt?"block":"none"},onMouseLeave:()=>_n(!1),onBlur:()=>_n(!1),onClick:()=>Z(de=>!de),tabIndex:0,children:["Grid: ",z.rows,"x",z.cols," ▼"]}),K&<.jsx("div",{style:{position:"absolute",top:"110%",left:"50%",transform:"translateX(-50%)",background:"#222",color:"#fff",borderRadius:"6px",boxShadow:"0 2px 12px rgba(0,0,0,0.4)",padding:"12px",display:"grid",gridTemplateColumns:"repeat(3, 40px)",gap:"8px",zIndex:200,pointerEvents:"auto"},children:we.map(de=>lt.jsxs("button",{style:{width:"40px",height:"40px",background:de.rows===z.rows&&de.cols===z.cols?"#444":"#333",color:"#fff",border:"none",borderRadius:"4px",fontWeight:"bold",cursor:"pointer",fontSize:"15px"},onClick:()=>{sn(),W({rows:de.rows,cols:de.cols}),Z(!1)},children:[de.rows,"x",de.cols]},`${de.rows}x${de.cols}`))})]}),lt.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"grid",margin:3,gridTemplateRows:`repeat(${z.rows}, 1fr)`,gridTemplateColumns:`repeat(${z.cols}, 1fr)`,gap:"5px",zIndex:1},children:Da}),lt.jsx("button",{style:{position:"absolute",top:8,right:8,zIndex:20,padding:"6px 12px",background:"#222",color:"#fff",border:"none",borderRadius:"4px",cursor:"pointer",opacity:.85,userSelect:"none"},onClick:()=>d(!0),children:"Settings"}),u&<.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",background:"rgba(0,0,0,0.4)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>d(!1),children:lt.jsxs("div",{style:{background:"#222",color:"#fff",borderRadius:"8px",minWidth:"320px",minHeight:"180px",padding:"24px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)",position:"relative"},onClick:de=>de.stopPropagation(),children:[lt.jsx("div",{style:{fontSize:"20px",marginBottom:"16px"},children:"Settings"}),lt.jsxs("div",{style:{marginBottom:"24px"},children:[lt.jsx("div",{style:{marginBottom:12,fontWeight:"bold"},children:"Mouse Button Tool Bindings"}),Fb.map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label," Button:"]}),lt.jsx("select",{value:gt[de.value],onChange:Ue=>Ie(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))})]},de.value)),lt.jsxs("div",{style:{margin:"12px 0"},children:[lt.jsxs("button",{style:{background:"#333",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 12px",cursor:"pointer",fontSize:"14px",marginBottom:"8px"},onClick:()=>Ee(de=>!de),children:[pe?"Hide":"Show"," Advanced Mouse Bindings"]}),pe&<.jsx("div",{style:{marginTop:8},children:Xm.slice(3).map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label,":"]}),lt.jsxs("select",{value:gt[de.value]||"",onChange:Ue=>Ie(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:[lt.jsx("option",{value:"",children:"(None)"}),ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))]})]},de.value))})]}),lt.jsx("div",{style:{margin:"18px 0 8px 0",fontWeight:"bold"},children:"Ctrl + Mouse Button Tool Bindings"}),Fb.map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label," + Ctrl:"]}),lt.jsxs("select",{value:$e[de.value]||"",onChange:Ue=>tt(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:[lt.jsx("option",{value:"",children:"(None)"}),ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))]})]},de.value+"_ctrl")),lt.jsxs("div",{style:{margin:"12px 0"},children:[lt.jsxs("button",{style:{background:"#333",color:"#fff",border:"none",borderRadius:"4px",padding:"4px 12px",cursor:"pointer",fontSize:"14px",marginBottom:"8px"},onClick:()=>Se(de=>!de),children:[Oe?"Hide":"Show"," Advanced Ctrl + Mouse Bindings"]}),Oe&<.jsx("div",{style:{marginTop:8},children:Xm.slice(3).map(de=>lt.jsxs("div",{style:{marginBottom:10},children:[lt.jsxs("label",{style:{marginRight:8},children:[de.label," + Ctrl:"]}),lt.jsxs("select",{value:$e[de.value]||"",onChange:Ue=>tt(_e=>({..._e,[de.value]:Ue.target.value})),style:{background:"#333",color:"#fff",border:"1px solid #444",borderRadius:"4px",padding:"4px 8px",fontSize:"14px"},children:[lt.jsx("option",{value:"",children:"(None)"}),ng.map(Ue=>lt.jsx("option",{value:Ue.value,children:Ue.label},Ue.value))]})]},de.value+"_ctrl"))})]})]}),lt.jsx("button",{style:{position:"absolute",top:12,right:12,background:"transparent",color:"#fff",border:"none",fontSize:"20px",cursor:"pointer"},onClick:()=>d(!1),"aria-label":"Close",children:"×"})]})}),Lt&<.jsx("div",{style:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",background:"rgba(0,0,0,0.5)",zIndex:2e3,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>xt(!1),children:lt.jsxs("div",{style:{background:"#222",color:"#fff",borderRadius:"8px",minWidth:"320px",maxWidth:"80vw",maxHeight:"80vh",padding:"24px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)",position:"relative",overflow:"auto"},onClick:de=>de.stopPropagation(),children:[lt.jsx("div",{style:{fontSize:"20px",marginBottom:"16px"},children:"DICOM Metadata"}),Ft,lt.jsx("button",{style:{position:"absolute",top:12,right:12,background:"transparent",color:"#fff",border:"none",fontSize:"20px",cursor:"pointer"},onClick:()=>xt(!1),"aria-label":"Close",children:"×"})]})})]})}function Kxe(t){console.log("Setting up tools...",t),Ci(j0),Ci(H0),Ci(id),Ci(q0),Ci(K0),Ci(Iu),Ci(nl),Ci(Ou),Ci(tl),Ci(od),Ci(bu),Ci(ic),Ci(X0),Ci(ua),Ci(Fs),Ci(Gf),Ci(Z0);let e=Kr(t);return e||(e=hN(t),e.addTool(H0.toolName),e.addTool(j0.toolName),e.addTool(q0.toolName),e.addTool(id.toolName,{loop:!1}),e.addTool(K0.toolName),e.addTool(Iu.toolName),e.addTool(Z0.toolName,{getTextCallback:()=>""}),e.addTool(Ou.toolName),e.addTool(nl.toolName,{statsCalculator:()=>null}),e.addTool(tl.toolName,{calculateStats:!1,getTextCallback:()=>""}),e.addTool(od.toolName,{getTextCallback:()=>""}),e.addTool(bu.toolName,{calculateStats:!1}),e.addTool(ic.toolName,{}),e.addTool(X0.toolName,{}),e.addTool(Gf.toolName),e.addTool(ua.toolName)),e}function Bb(t,e,r,n){if(!r.length||!e.length)return null;const i=r.map(o=>e.findIndex(a=>a===o.metadata.referencedImageId)).filter(o=>o!==-1).sort((o,a)=>o-a);if(!i.length)return null;if(n===1){for(let o of i)if(o>t)return o;return i[0]}else{for(let o=i.length-1;o>=0;o--)if(i[o]`wadouri:/test_images/stack2/IMG${r+1}.dcm`),Array.from({length:25},(e,r)=>`wadouri:/test_images/stack5/IMG${r+1}.dcm`),Array.from({length:26},(e,r)=>`wadouri:/test_images/stack3/IMG${r+1}.dcm`)]}const Gb=t=>t.map(e=>e.startsWith("wadouri:")?e:`wadouri:${e}`);function dG(){document.querySelectorAll(".dicom-viewer-test-root").forEach(r=>{const n=r.id||"",i=()=>qxe();Tx(r).render(lt.jsx(Ub,{container_id:n,imageStacks:i}))}),document.querySelectorAll(".dicom-viewer-root").forEach(r=>{const n=r.id||"";let i;const o=r.getAttribute("data-images");if(o){let f;try{f=JSON.parse(o)}catch(u){console.error("Invalid data-images JSON:",u),f=[]}Array.isArray(f)&&f.length>0&&typeof f[0]=="string"?i=()=>Promise.resolve([Gb(f)]):Array.isArray(f)?i=()=>Promise.resolve(f.map(u=>Array.isArray(u)?Gb(u):[])):i=()=>Promise.resolve([[]])}else i=()=>Promise.resolve([[]]);const a=r.getAttribute("data-auto-cache-stack"),s=a==="true"||a==="1",c=r.getAttribute("data-annotationjson"),l=r.getAttribute("data-viewerstate");console.log("Mounting DICOM viewer:"),console.log(l,c,s),Tx(r).render(lt.jsx(Ub,{container_id:n,imageStacks:i,autoCacheStack:s,annotationJson:c||void 0,viewerState:l||void 0}))})}dG();window.mountDicomViewers=dG;