UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

91 lines (79 loc) 2.33 MB
"use strict";/** * @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.6.4 * * (C) 2025-present SheetXL Inc. & Michael T. Ford * License: The license can be found at https://www.sheetxl.com/license. */const Fa=require("./CP1jrGRLh9liezjk.cjs");function $3(n,e){for(var t=0;t<e.length;t++){const o=e[t];if(typeof o!="string"&&!Array.isArray(o)){for(const r in o)if(r!=="default"&&!(r in n)){const i=Object.getOwnPropertyDescriptor(o,r);i&&Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:()=>o[r]})}}}return Object.freeze(Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}))}const H2=new Map,qv=(n,e={})=>{const{message:t,icon:o,customElement:r,hide:i=!1,className:s,cssVars:a={}}=e;if(i)return;const l=typeof n=="string"?document.querySelector(n):n;if(!l)return void console.warn(`Element with selector "${n}" not found for panel.`);let c;if(pu(n),r)c=r;else{c=document.createElement("div"),c.className=s?`sheetxl-panel ${s}`:"sheetxl-panel";const d=Object.entries(a).map(([m,p])=>`--sheetxl-panel-${m}: ${p};`).join(" "),u=` @keyframes sheetxl-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .sheetxl-panel { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; backdrop-filter: blur(4px); border-radius: 4px; z-index: 9999; gap: 16px; /* CSS variables with fallbacks */ color: var(--sheetxl-panel-color, #333); } .sheetxl-panel.dark { color: var(--sheetxl-panel-color, #e0e0e0); } .sheetxl-icon { width: 24px; height: 24px; color: var(--sheetxl-panel-icon-color, #1976d2); } .sheetxl-panel.loading { /* Loading panel defaults */ color: var(--sheetxl-panel-color, #333); } .sheetxl-panel.loading.dark { color: var(--sheetxl-panel-color, #e0e0e0); } .sheetxl-panel.error { /* Error panel defaults */ color: var(--sheetxl-panel-color, #d32f2f); } .sheetxl-panel.error.dark { color: var(--sheetxl-panel-color, #f44336); } .sheetxl-panel.error .sheetxl-icon { color: var(--sheetxl-panel-icon-color, #d32f2f); } .sheetxl-panel.error.dark .sheetxl-icon { color: var(--sheetxl-panel-icon-color, #f44336); } .sheetxl-message { font-size: 1.1em; font-weight: 500; letter-spacing: 0.1px; text-align: center; margin: 0; } `,h=document.createElement("style");if(h.textContent=u,c.appendChild(h),o){const m=document.createElement("div");m.className="sheetxl-icon",typeof o=="string"?m.innerHTML=o:o instanceof HTMLElement&&m.appendChild(o),c.appendChild(m)}if(t){const m=document.createElement("div");m.className="sheetxl-message",m.textContent=t,c.appendChild(m)}d&&(c.style.cssText+=d),window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches&&c.classList.add("dark")}window.getComputedStyle(l).position==="static"&&(l.style.position="relative"),l.appendChild(c),H2.set(n,c)},pu=n=>{const e=H2.get(n);e&&e.parentNode&&(e.parentNode.removeChild(e),H2.delete(n))},Xv=(n,e={})=>{qv(n,{icon:` <svg width="24" height="24" viewBox="0 0 24 24" style="animation: sheetxl-spin 1s linear infinite;"> <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2" stroke-dasharray="31.416" stroke-dashoffset="31.416"> <animate attributeName="stroke-dasharray" dur="2s" values="0 31.416;15.708 15.708;0 31.416" repeatCount="indefinite"/> <animate attributeName="stroke-dashoffset" dur="2s" values="0;-15.708;-31.416" repeatCount="indefinite"/> </circle> </svg> `,className:"loading",...e})},Kv=(n,e={})=>{qv(n,{message:"Failed to load SheetXL",icon:` <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"> <path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z"/> </svg> `,className:"error",...e})},x1=new Map;var x=Fa.requireReact();const Ue=Fa.getDefaultExportFromCjs(x),jp=$3({__proto__:null,default:Ue},[x]);var g=Fa.requireJsxRuntime();const RI=$3({__proto__:null,default:Fa.getDefaultExportFromCjs(g)},[g]);var V2=Fa.requireClient();const U6=$3({__proto__:null,default:Fa.getDefaultExportFromCjs(V2)},[V2]),it={Number:"n",String:"s",Boolean:"b",Error:"e",RichData:"r",Null:"z"};var b1;exports.w=void 0,exports.n=void 0,(b1=exports.w||(exports.w={})).Orientation={Column:"column",Row:"row"},b1.Orientations={...b1.Orientation,Both:"both"},b1.Direction={Up:"up",Down:"down",Left:"left",Right:"right"},(n=>{n.Code={Parse:0,Null:1,Div0:2,Value:3,Ref:4,Name:5,Num:6,NA:7,GettingData:8,Spill:9,Connect:10,Blocked:11,Unknown:12,Field:13,Calc:14,Busy:16,Python:19,Timeout:20},n.Label={Parse:"#PARSE!",Null:"#NULL!",Div0:"#DIV/0!",Value:"#VALUE!",Ref:"#REF!",Name:"#NAME?",Num:"#NUM!",NA:"#N/A",GettingData:"#GETTING_DATA",Spill:"#SPILL!",Connect:"#CONNECT!",Blocked:"#BLOCKED!",Unknown:"#UNKNOWN!",Field:"#FIELD!",Calc:"#CALC!",Busy:"#BUSY!",Python:"#PYTHON!",Timeout:"#TIMEOUT!"};class e extends Error{constructor(v,_,k,I){super(k,I),this._label=_,this._code=v,this.details=I}static{this.code=n.Code.Unknown}get isFormulaError(){return!0}getLabel(){return this._label}getCode(){return this._code}equals(v){return!!v&&(this._code===v._code||this._code===v.code)}get[Symbol.toStringTag](){return"[FormulaError]"}toString(){return this.message||this._label}}n.Known=e;class t extends e{constructor(v,_){super(n.Code.Parse,n.Label.Parse,v,_)}static{this.code=n.Code.Parse}getDetails(){const v=this.details;return{line:v?.line??1,column:v?.column??1,offset:v?.offset??0,length:v?.length??0}}}n.Parse=t;class o extends e{constructor(v,_){super(n.Code.Null,n.Label.Null,v,_)}static{this.code=n.Code.Null}}n.Null=o;class r extends e{constructor(v,_){super(n.Code.Div0,n.Label.Div0,v,_)}static{this.code=n.Code.Div0}}n.Div0=r;class i extends e{constructor(v,_){super(n.Code.Value,n.Label.Value,v,_)}static{this.code=n.Code.Value}}n.Value=i;class s extends e{constructor(v,_){super(n.Code.Ref,n.Label.Ref,v,_)}static{this.code=n.Code.Ref}}n.Ref=s;class a extends e{constructor(v,_){super(n.Code.Name,n.Label.Name,v,_)}static{this.code=n.Code.Name}}n.Name=a;class l extends e{constructor(v,_){super(n.Code.Num,n.Label.Num,v,_)}static{this.code=n.Code.Num}}n.Num=l;class c extends e{constructor(v,_){super(n.Code.NA,n.Label.NA,v,_)}static{this.code=n.Code.NA}}n.NA=c;class d extends e{constructor(v,_){super(n.Code.GettingData,n.Label.GettingData,v,_)}static{this.code=n.Code.GettingData}}n.GettingData=d;class u extends e{constructor(v,_){super(n.Code.Spill,n.Label.Spill,v,_)}static{this.code=n.Code.Spill}}n.Spill=u;class h extends e{constructor(v,_){super(n.Code.Connect,n.Label.Connect,v,_)}static{this.code=n.Code.Connect}}n.Connect=h;class m extends e{constructor(v,_){super(n.Code.Blocked,n.Label.Blocked,v,_)}static{this.code=n.Code.Blocked}}n.Blocked=m;class p extends e{constructor(v,_){super(n.Code.Unknown,n.Label.Unknown,v,_)}static{this.code=n.Code.Unknown}}n.Unknown=p;class f extends e{constructor(v,_){super(n.Code.Field,n.Label.Field,v,_)}static{this.code=n.Code.Field}}n.Field=f;class w extends e{constructor(v,_){super(n.Code.Calc,n.Label.Calc,v,_)}static{this.code=n.Code.Calc}}n.Calc=w;class y extends e{constructor(v,_){super(n.Code.Busy,n.Label.Busy,v,_)}static{this.code=n.Code.Busy}}n.Busy=y;class b extends e{constructor(v,_){super(n.Code.Python,n.Label.Python,v,_)}static{this.code=n.Code.Python}}n.Python=b;class S extends e{constructor(v,_){super(n.Code.Timeout,n.Label.Timeout,v,_)}static{this.code=n.Code.Timeout}}n.Timeout=S})(exports.n||(exports.n={}));const No={};No[exports.n.Code.Parse]=exports.n.Parse,No[exports.n.Code.Null]=exports.n.Null,No[exports.n.Code.Div0]=exports.n.Div0,No[exports.n.Code.Value]=exports.n.Value,No[exports.n.Code.Ref]=exports.n.Ref,No[exports.n.Code.Name]=exports.n.Name,No[exports.n.Code.Num]=exports.n.Num,No[exports.n.Code.NA]=exports.n.NA,No[exports.n.Code.GettingData]=exports.n.GettingData,No[exports.n.Code.Spill]=exports.n.Spill,No[exports.n.Code.Connect]=exports.n.Connect,No[exports.n.Code.Blocked]=exports.n.Blocked,No[exports.n.Code.Unknown]=exports.n.Unknown,No[exports.n.Code.Field]=exports.n.Field,No[exports.n.Code.Calc]=exports.n.Calc,No[exports.n.Code.Busy]=exports.n.Busy,No[exports.n.Code.Python]=exports.n.Python,No[exports.n.Code.Timeout]=exports.n.Timeout;const Yv=new Map,W3=new Map,Zv=new Map,Jv=new Map,G6=Object.keys(No);for(let n=0;n<G6.length;n++){const e=G6[n],t=No[e];Zv.set(exports.n.Label[e],t),Jv.set(exports.n.Code[e],t);const o=new t;Yv.set(o.getLabel(),o),W3.set(o.getCode(),o)}const MI=W3.get(exports.n.Code.Unknown);var ao;(ao=exports.n||(exports.n={})).BuiltIn={Parse:new ao.Parse,Null:new ao.Null,Div0:new ao.Div0,Value:new ao.Value,Ref:new ao.Ref,Name:new ao.Name,Num:new ao.Num,NA:new ao.NA,GettingData:new ao.GettingData,Spill:new ao.Spill,Connect:new ao.Connect,Blocked:new ao.Blocked,Unknown:new ao.Unknown,Field:new ao.Field,Calc:new ao.Calc,Busy:new ao.Busy,Python:new ao.Python,Timeout:new ao.Timeout},ao.getBuiltInByLabel=n=>Yv.get(n),ao.newTypedError=(n,e,t)=>{let o;return o=typeof n=="string"?Zv.get(n):Jv.get(n),o||(o=ao.Unknown),new o(e,t)},ao.getBuiltInById=n=>W3.get(n)||MI;const Ye={Up:"up",Down:"down",Left:"left",Right:"right"},qt={TopLeft:"tl",Top:"t",TopRight:"tr",Left:"l",Center:"c",Right:"r",BottomLeft:"bl",Bottom:"b",BottomRight:"br"},nr="text/html",Ts="text/plain",Wd="image/png",TI=Object.freeze({left:0,top:0}),II=Object.freeze({left:0,top:0,bottom:0,right:0}),AI=Object.freeze({x:0,y:0,width:0,height:0}),fs=Object.freeze(Object.defineProperty({__proto__:null,EmptyBounds:AI,EmptyRect:II,EmptyTopLeft:TI},Symbol.toStringTag,{value:"Module"})),Nt={Column:"column",Row:"row"},w0={...Nt,Both:"both"},NI=Object.freeze({colIndex:0,rowIndex:0}),jI=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),Qv=(n,e)=>n.colStart===e.colStart?n.rowStart-e.rowStart:n.colStart-e.colStart,eC=(n,e)=>n.rowStart===e.rowStart?n.colStart-e.colStart:n.rowStart-e.rowStart,OI=(n,e)=>n.rowEnd===e.rowEnd?e.colEnd-n.colEnd:e.rowEnd-n.rowEnd,FI=(n,e)=>n.colEnd===e.colEnd?e.rowEnd-n.rowEnd:e.colEnd-n.colEnd,q6=(n,e)=>n.colIndex===e.colIndex?n.rowIndex-e.rowIndex:n.colIndex-e.colIndex,X6=(n,e)=>n.rowIndex===e.rowIndex?n.colIndex-e.colIndex:n.rowIndex-e.rowIndex,tC=(n=Nt.Row,e=!1)=>e?n!==Nt.Column?OI:FI:n!==Nt.Column?eC:Qv,K6=(n,e)=>n===e||!(!n||!e)&&n.rowIndex===e.rowIndex&&n.colIndex===e.colIndex,$2=(n,e)=>n===e||!(!n||!e)&&n.rowStart===e.rowStart&&n.rowEnd===e.rowEnd&&n.colStart===e.colStart&&n.colEnd===e.colEnd,W2=(n,e)=>!(!n||!e||n.colStart>e.colEnd||e.colStart>n.colEnd||n.rowStart>e.rowEnd||e.rowStart>n.rowEnd),Y6=(n,e)=>{if(n===e)return!0;if(!n||!e||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!$2(n[t],e[t]))return!1;return!0},Rf=(n,e,t)=>{if(!n&&!e)return null;if(!n)return t?e:{...e};if(!e)return t?n:{...n};const o=Math.min(n.colStart,e.colStart),r=Math.min(n.rowStart,e.rowStart),i=Math.max(n.colEnd,e.colEnd),s=Math.max(n.rowEnd,e.rowEnd);let a=t;return a?(a.colStart=o,a.rowStart=r,a.colEnd=i,a.rowEnd=s):a={colStart:o,rowStart:r,colEnd:i,rowEnd:s},a},Z6=(n,e)=>{if(!e||e.length===0)return n;const t={...n};for(let o=0;o<e.length;o++){const r=e[o];W2(t,r)&&(t.rowStart=Math.min(t.rowStart,r.rowStart),t.colStart=Math.min(t.colStart,r.colStart),t.rowEnd=Math.max(t.rowEnd,r.rowEnd),t.colEnd=Math.max(t.colEnd,r.colEnd))}return t},DI=[null,null],LI=(n,e,t)=>{if(n[0].value===n[1].value)return e};function J6(n,e=2,t,o=Nt.Row,r){let i=[...n];if(e<=0||n.length<=1)return i;let s=o===Nt.Column,a=0,l=!1;do{const c=i.sort(tC(s?Nt.Row:Nt.Column));i=[],i.push(c[0]);const d=c.length;let u=0,h=c[0],m=h.colStart,p=h.rowStart,f=h.colEnd,w=h.rowEnd;for(let y=1;y<d;y++){const b=c[y];let S=!1;if(S=s?h&&p===b.rowStart&&w===b.rowEnd&&f+1===b.colStart:h&&m===b.colStart&&f===b.colEnd&&w+1===b.rowStart,S){let C={colStart:m,rowStart:p,colEnd:s?b.colEnd:f,rowEnd:s?w:b.rowEnd};if(h.value!==void 0&&(C.value=h.value),t){const v=r??[null,null];v[0]=h,v[1]=b,C=t(v,C,o)}if(C){i[u]=C,l=!0,h=C,m=h.colStart,p=h.rowStart,f=h.colEnd,w=h.rowEnd;continue}}i[++u]=b,h=b,m=h.colStart,p=h.rowStart,f=h.colEnd,w=h.rowEnd}a++,s=!s,a===1&&(l=!0)}while(a<e&&l&&i.length>1);return i}const le=Object.freeze(Object.defineProperty({__proto__:null,EmptyCell:NI,EmptyRange:jI,cellToRange:(n,e)=>{if(!n)return null;let t=e;return t||(t={...n},delete t.colIndex,delete t.rowIndex),t.colStart=n.colIndex??0,t.rowStart=n.rowIndex??0,t.colEnd=n.colIndex??0,t.rowEnd=n.rowIndex??0,t},columnFirstCellComparator:q6,columnFirstRangeComparator:Qv,createCellComparator:(n=Nt.Row,e=!1)=>e?n!==Nt.Column?(t,o)=>t.rowIndex===o.rowIndex?o.colIndex-t.colIndex:o.rowIndex-t.rowIndex:(t,o)=>t.colIndex===o.colIndex?o.rowIndex-t.rowIndex:o.colIndex-t.colIndex:n!==Nt.Column?X6:q6,createConflatingRanges:(n,e=!1)=>{const t=[];let o,r,i=Number.MIN_SAFE_INTEGER,s=Number.MIN_SAFE_INTEGER;return{append:(a,l,c)=>{let d=!0;const u=c!==void 0;if(u){const p=n?n(r,c,e):r===c?c:void 0;p===void 0?d=!1:c=p}if(d&&l===s+1&&a===i)return e?o.rowEnd=l:o.colEnd=l,s=l,void(r=c);o&&t.push(o);const h=e?a:l,m=e?l:a;o={colStart:h,rowStart:m,colEnd:h,rowEnd:m},u&&(o.value=c),i=a,s=l,r=c},done:a=>(o&&(t.push(o),o=null),a?J6(t,3,a===!0?LI:a,e?Nt.Column:Nt.Row,DI):t)}},createRangeComparator:tC,defaultRange:(n,e,t)=>n?t?(t.colStart=n.colStart??e.colStart,t.rowStart=n.rowStart??e.rowStart,t.colEnd=n.colEnd??e.colEnd,t.rowEnd=n.rowEnd??e.rowEnd,t):{colStart:n.colStart??e.colStart,rowStart:n.rowStart??e.rowStart,colEnd:n.colEnd??e.colEnd,rowEnd:n.rowEnd??e.rowEnd}:e,extendRangeToIntersectingRanges:Z6,extendRangeToUnionRanges:(n,e)=>{if(!e||e.length===0)return n;let t=n,o=null;for(;!$2(t,o);)o=t,t=Z6(o,e);return t},indexOfCoords:(n,e)=>{const t={colStart:n.colIndex,rowStart:n.rowIndex,colEnd:n.colIndex,rowEnd:n.rowIndex};for(let o=e.length-1;o>=0;o--)if(W2(t,e[o]))return o;return-1},intersectRanges:(n,e,t)=>{if(!n)return t?e:{...e};if(!e)return t?n:{...n};if(!n&&!e||n.rowStart>e.rowEnd||n.rowEnd<e.rowStart||n.colStart>e.colEnd||n.colEnd<e.colStart)return null;const o=Math.max(n.colStart,e.colStart),r=Math.max(n.rowStart,e.rowStart),i=Math.min(n.colEnd,e.colEnd),s=Math.min(n.rowEnd,e.rowEnd);let a=t;return a?(a.colStart=o,a.rowStart=r,a.colEnd=i,a.rowEnd=s):a={colStart:o,rowStart:r,colEnd:i,rowEnd:s},a},isCellWithinRange:(n,e)=>!(!n||!e||n.rowIndex<e.rowStart||n.rowIndex>e.rowEnd||n.colIndex<e.colStart||n.colIndex>e.colEnd),isEqualCells:K6,isEqualRanges:$2,isEqualRangesArrays:Y6,isEqualSelectionCoords:(n,e)=>n===e||!(!n||!e)&&n.rangeIndex===e.rangeIndex&&!!K6(n.cell,e.cell)&&Y6(n.ranges,e.ranges),isRangeWithinRange:(n,e)=>!(n.rowStart<e.rowStart||n.rowEnd>e.rowEnd||n.colStart<e.colStart||n.colEnd>e.colEnd),isRangesIntersect:W2,isSingleCell:n=>!!n&&n.rowEnd===n.rowStart&&n.colStart===n.colEnd,isValidRange:n=>!(!n||typeof n.colStart!="number"||n.colStart<0||typeof n.colEnd!="number"||n.colEnd<n.colStart||typeof n.rowStart!="number"||n.rowStart<0||typeof n.rowEnd!="number"||n.rowEnd<n.rowStart),mergeRangedValues:J6,rowFirstCellComparator:X6,rowFirstRangeComparator:eC,sanitizeRange:n=>n?{colStart:n.colIndex??n.colStart??0,rowStart:n.rowIndex??n.rowStart??0,colEnd:n.colIndex??n.colEnd??0,rowEnd:n.rowIndex??n.rowEnd??0}:null,translateRange:(n,e=-n.rowStart,t=-n.colStart,o)=>o?(o.colStart=n.colStart+t,o.rowStart=n.rowStart+e,o.colEnd=n.colEnd+t,o.rowEnd=n.rowEnd+e,o):{colStart:n.colStart+t,rowStart:n.rowStart+e,colEnd:n.colEnd+t,rowEnd:n.rowEnd+e},unionRanges:Rf,unionRangesArrays:(n,e,t)=>{if(!n||n.length===0)return null;if(n.length===1&&!e)return n[0];let o=n[0];for(let r=1;r<n.length;r++)o=Rf(o,n[r],t);return e&&(o=Rf(o,e,t)),o}},Symbol.toStringTag,{value:"Module"})),PI=typeof Symbol=="function"&&Symbol.for?Symbol.for("react.element"):60103;function zI(n){return function(e){return!!e&&typeof e=="object"}(n)&&!function(e){const t=Object.prototype.toString.call(e);return t==="[object RegExp]"||t==="[object Date]"||e.$$typeof===PI}(n)}function bd(n,e){return e.clone!==!1&&e.isMergeableObject(n)?_l((t=n,Array.isArray(t)?[]:{}),n,e):n;var t}function BI(n,e,t){return n.concat(e).map(function(o){return bd(o,t)})}function Q6(n){return Object.keys(n).concat((e=n,Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return Object.propertyIsEnumerable.call(e,t)}):[]));var e}function e7(n,e){try{return e in n}catch{return!1}}function _l(n,e,t){(t=t||{}).arrayMerge=t.arrayMerge||BI,t.isMergeableObject=t.isMergeableObject||zI,t.cloneUnlessOtherwiseSpecified=bd;const o=Array.isArray(e);return o===Array.isArray(n)?o?t.arrayMerge(n,e,t):function(r,i,s){const a={};return s.isMergeableObject(r)&&Q6(r).forEach(function(l){a[l]=bd(r[l],s)}),Q6(i).forEach(function(l){(function(c,d){return e7(c,d)&&!(Object.hasOwnProperty.call(c,d)&&Object.propertyIsEnumerable.call(c,d))})(r,l)||(e7(r,l)&&s.isMergeableObject(i[l])?a[l]=function(c,d){if(!d.customMerge)return _l;const u=d.customMerge(c);return typeof u=="function"?u:_l}(l,s)(r[l],i[l],s):a[l]=bd(i[l],s))}),a}(n,e,t):bd(e,t)}_l.all=function(n,e){if(!Array.isArray(n))throw new Error("first argument should be an array");return n.reduce(function(t,o){return _l(t,o,e)},{})};const HI=Object.freeze([]),VI=Object.freeze({}),t7=n=>n,Vh=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){let e=16*Math.random()|0;return(n==="x"?e:3&e|8).toString(16)}),nC=(n,e)=>n===e||!(!Array.isArray(n)||!Array.isArray(e)||n.length!==e.length)&&n.every((t,o)=>t===e[o]),Ec=n=>typeof n=="object"&&!Array.isArray(n)&&n!==null,oC=n=>typeof n!="object"||Array.isArray(n)||n===null?n:(Object.keys(n).forEach(function(e){n[e]&&typeof n[e]=="object"?oC(n[e]):n[e]!==null&&n[e]!==void 0||delete n[e],typeof n[e]=="object"&&Object.keys(n[e]).length===0&&delete n[e]}),Object.keys(n).length===0?null:n),$I=(n,e)=>!(n!==e&&!nC(n,e)&&!n.isEqual?.(e)),rC=(n,e,t=$I)=>{if(n==null||n===e)return null;if(!n||typeof n!="object"||Array.isArray(n)||n.isImmutable?.())return t(n,e)?null:n;const o=Object.keys(n);if(o.length===0)return null;let r=!1;for(let i=0;i<o.length;i++){const s=o[i];rC(n[s],e?.[s],t)===null&&(r=!0,delete n[s])}return r&&Object.keys(n).length===0?null:void 0},n7=typeof performance=="object"&&typeof performance.now=="function"?()=>performance.now():()=>Date.now(),o7=n=>n==null,r7=(n,e)=>!(e.left>n.right||e.right<n.left||e.top>n.bottom||e.bottom<n.top),i7=!(typeof window>"u"||!window.document||!window.document.createElement),wr={Windows:"windows",MacOS:"macos",IOS:"ios",Linux:"linux",Android:"android",Safari:"safari",Firefox:"firefox",Node:"node",Unknown:"unknown"},mu=()=>{if(iC())return wr.Node;const n=globalThis.navigator!==void 0&&globalThis.navigator.userAgent?globalThis.navigator.userAgent.toLowerCase():"";return n?/(win32|win64|windows|wince)/i.test(n)?wr.Windows:/(macintosh|macintel|macppc|mac68k|macos)/i.test(n)?wr.MacOS:/(iphone|ipad|ipod)/i.test(n)?wr.IOS:/android/.test(n)?wr.Android:/linux/.test(n)?wr.Linux:/^((?!chrome|android|).)*safari/i.test(n)?wr.Safari:/^((?!chrome|android|Seamonkey).)*firefox/i.test(n)?wr.Firefox:wr.Unknown:wr.Unknown};function iC(){return typeof process<"u"&&process.release?.name==="node"||(typeof process<"u"&&process.browser,!1)}const s7=(n,e=!1)=>(document.hasFocus()||e)&&(n===document.activeElement||n?.contains(document.activeElement)),oe=Object.freeze(Object.defineProperty({__proto__:null,EmptyArray:HI,EmptyObject:VI,OSType:wr,arrayMove:function(n,e,t){const o=n.slice();return o.splice(t<0?o.length+t:t,0,o.splice(e,1)[0]),o},asNumber:n=>{const e=(t=>1*t)(n);return Number.isFinite(e)?e:0},camelToPrettyCase:n=>n.length===1?n.toUpperCase():n.replace(/([A-Z])/g," $1").replace(/^./,function(e){return e.toUpperCase()}).trim(),canUseDOM:i7,cancelTimeout:n=>{cancelAnimationFrame(n.id)},castToString:n=>n==null||n===void 0?"":typeof n!="string"?""+n:n,cloneObject:n=>o7(n)?n:JSON.parse(JSON.stringify(n)),consoleWithNoSource:(...n)=>new Promise(e=>{setTimeout(()=>{Function("console.log.apply(console, arguments)").apply(null,n),e()})}),debounce:function(n,e=300,t=!1){let o,r,i,s,a=0;function l(){let d=Date.now()-a;d<e&&d>=0?o=setTimeout(l,e-d):(o=null,t||(s=n.apply(i,r),i=r=null))}e==null&&(e=100);const c=function(){i=globalThis,r=arguments,a=Date.now();var d=t&&!o;return o||(o=setTimeout(l,e)),d&&(s=n.apply(i,r),i=r=null),s};return c.clear=function(){o&&(clearTimeout(o),o=null)},c.flush=function(){o&&(s=n.apply(i,r),i=r=null,clearTimeout(o),o=null)},c},deepEqual:function n(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){if(e.constructor!==t.constructor)return!1;let o,r,i;if(Array.isArray(e)){if(o=e.length,o!=t.length)return!1;for(r=o;r--!==0;)if(!n(e[r],t[r]))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;for(r of e.entries())if(!n(r[1],t.get(r[0])))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(o=e.length,o!=t.length)return!1;for(r=o;r--!==0;)if(e[r]!==t[r])return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if(i=Object.keys(e),o=i.length,o!==Object.keys(t).length)return!1;for(r=o;r--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[r]))return!1;for(r=o;r--!==0;){let s=i[r];if(!(s==="_owner"&&e.$$typeof||n(e[s],t[s])))return!1}return!0}return e!=e&&t!=t},deepFreeze:function n(e){return Object.freeze(e),Object.keys(e).forEach(t=>{typeof e[t]!="object"||e[t]===null||Object.isFrozen(e[t])||n(e[t])}),e},deepMerge:_l,diffValues:(n,e)=>{const t={},o=Object.keys(e),r=o.length;for(let i=0;i<r;i++){const s=o[i];n[s]!==e[s]&&(n[s]===void 0?t[s]=e[s]:t[s]=n[s])}return Object.keys(t).length===0?null:t},findEqualOrGreater:function(n,e,t=t7){let o=0,r=n.length-1;for(;o<=r;){let i=Math.floor((o+r)/2),s=t(n[i]);if(s===e)return i;s<e?o=i+1:r=i-1}return o},findEqualOrLesser:function(n,e,t=t7){let o=n.length-1,r=0;for(;o>=r;){let i=Math.floor((o+r)/2),s=t(n[i]);if(s===e)return i;s>e?o=i-1:r=i+1}return o},findNextStep:(n,e=!0,t=15,o=10,r=400)=>{const i=Math.max(n-o,0)+(e?1:-1);return Math.min(r,Math[e?"ceil":"floor"](i/t)*t+o)},getDPI:()=>{let n=1;return typeof window=="object"&&(n=window.devicePixelRatio||1),n},getFromPath:(n,e)=>{const t=e.split(".");let o=n;for(let r=0;r<t.length;r++){const i=t[r];if(!o)return null;let s=o[i];if(typeof s=="function"&&(s=s.bind(o)()),!s||!Ec(s))return s;o=s}return o??null},getOS:mu,hasFocus:s7,isDefined:n=>n!=null,isEmpty:n=>n==null||n==="",isEqualArrays:nC,isEqualBounds:(n,e)=>n===e||!(n&&!e||e&&!n)&&n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height,isEqualObjectKeys:(n,e)=>{if(n===e)return!0;if(n&&!e||e&&!n)return!1;const t=Object.keys(n);if(t.length!==Object.keys(e).length)return!1;for(let o=0;o<t.length;o++)if(n[t[o]]!==e[t[o]])return!1;return!0},isNode:iC,isNullOrUndefined:o7,isNumeric:n=>{const e=1*n;return Number.isFinite(e)&&typeof e=="number"},isObject:Ec,isPromiseLike:n=>!!n&&typeof n.then=="function",isRectInsideRect:(n,e)=>n.top>=e.top&&n.bottom<=e.bottom&&n.left>=e.left&&n.right<=e.right,isRectIntersect:r7,mergeContentful:(...n)=>{const e=n.length;if(e>0&&n[e-1]!==void 0&&!Ec(n[e-1]))return n[e-1];let t=n[0]||{};for(let o=1;o<e;o++)t=_l(t,n[o]||{},{arrayMerge:(r,i)=>[...i]});return t},nextTick:n=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(()=>{n()}):(typeof setImmediate=="function"?setImmediate:setTimeout)(()=>{n()})},openFileDialog:(n="*.*")=>new Promise((e,t)=>{if(!i7)return void t("Unable to open dialog with no dom.");const o=document.createElement("input");o.type="file",o.accept=n;let r=null,i=!1;globalThis.addEventListener?.("focus",()=>{setTimeout(()=>{r||i||(i=!0,e(null))},1e3)},{once:!0,passive:!0}),o.onchange=()=>{if(r=o.files[0],r){if(i)return void console.warn("File open detected after faux cancel.",r);e(r)}},o.autofocus=!0,o.click()}),rafThrottle:n=>{let e,t=!1,o=function(){t=!1,n(e)};return function(r){e=r,e&&e.persist&&e.persist(),t||(t=!0,requestAnimationFrame(o))}},removeEmptyProperties:oC,removeEqualValues:rC,removeListenerAll:n=>{if(!n)return[];for(let e=0;e<n.length;e++)n[e]&&n[e]();return[]},requestTimeout:(n,e)=>{const t=n7(),o={id:requestAnimationFrame(function r(){n7()-t>=e?n.call(null):o.id=requestAnimationFrame(r)})};return o},roundAccurately:(n,e=0)=>{if(n==null||!isFinite(n))return null;const t=10**e;return Number(Math.round(n*t)/t)},setToPath:(n,e,t)=>{const o=e.split(".");let r=n;if(!r)throw new Error("Can not set path to a null path.");for(let i=0;r&&i<o.length-1;i++){const s=o[i];let a=r[s];if(a==null&&(a={},r[s]=a),!Ec(a))throw new Error("Can not set path to a non object path.");r=a}if(typeof t!="number"&&typeof t!="boolean"&&typeof t!="string"&&!Ec(t))throw new Error(`Can not set path to ${t} that is not a a supported primitive.`);return r[o[o.length-1]]=t,n},splitNumber:n=>{let e=Math.abs(n);if(isNaN(e)||!isFinite(n))return null;let t=0|e,o=e-t,r=0,i=0,s=1;if(o>5e-8)for(;i<8&&Math.abs(r/s-o)>5e-8;)i++,s*=10,r=Math.round(o*s);return{ip:Math.trunc(n),fp:r,ipLength:Math.ceil(Math.log10(t+1)),fpLength:i}},subtractRect:(n,e,t=!1)=>{if(!e)return[n];if(!r7(n,e))return[];const o=[];let r=n;const i=()=>{e.top>r.top&&e.top<r.bottom&&(o.push({...r,bottom:e.top}),r={...r,top:e.top})},s=()=>{e.bottom>r.top&&e.bottom<r.bottom&&(o.push({...r,top:e.bottom}),r={...r,bottom:e.bottom})},a=()=>{e.right>r.left&&e.right<r.right&&(o.push({...r,left:e.right}),r={...r,right:e.right})},l=()=>{e.left>r.left&&e.left<r.right&&(o.push({...r,right:e.left}),r={...r,left:e.left})};return t?(l(),a(),i(),s()):(i(),s(),a(),l()),o},textToKey:n=>n.replace(/[^a-zA-Z0-9]/g,"").toLowerCase(),throttle:function(n,e){let t=null;return(...o)=>{const r=Date.now();(!t||r-t>=e)&&(t=r,n(...o))}},toSafeJSON:function n(e){if(e===null||typeof e!="object")return e;if(typeof e.toJSON=="function")return e.toJSON();if(Array.isArray(e))return e.map(o=>n(o));if(typeof e.toString=="function"&&e.toString!==Object.prototype.toString)return e.toString();const t={};for(const o in e)e.hasOwnProperty(o)&&(t[o]=n(e[o]));return t},transpose:n=>{if(!n)return n;const e=n.length,t=n[0].length,o=[];for(let r=0;r<t;r++)o[r]=Array(e);for(let r=0;r<e;r++)for(let i=0;i<t;i++)o[i][r]=n[r][i];return o},uuidV4:Vh,validEnumValue:(n,e)=>{if(!Object.values(n).includes(e))throw new Error(`Invalid type: ${e??"null"}. Must be one of: ${Object.values(e).join(", ")}.`)},whenFocus:async(n,e=!1)=>new Promise(t=>{s7(n,e)?t(!0):n.addEventListener("focusin",()=>{t(!0)},{once:!0}),n.focus()})},Symbol.toStringTag,{value:"Module"})),WI=Object.freeze(Object.defineProperty({__proto__:null,MESSAGE_ERROR_INVALID_ARG:n=>`Invalid argument: '${n}'.`},Symbol.toStringTag,{value:"Module"})),sC=n=>{const e=new Uint8Array(n),t=e.byteLength;let o="";for(let r=0;r<t;r++)o+=String.fromCharCode(e[r]);if(typeof window<"u"&&typeof globalThis.btoa=="function")return globalThis.btoa(o);if(typeof Buffer<"u")return Buffer.from(o,"binary").toString("base64");throw new Error("Unsupported environment")},U2=n=>new Promise((e,t)=>{if(n)if(typeof FileReader<"u"){const o=new FileReader;o.onload=()=>{e(o.result)},o.onerror=()=>{t(o.error)},o.readAsText(n)}else if(typeof Buffer<"u"){const o=r=>Buffer.from(r).toString("utf-8");n.arrayBuffer().then(r=>{e(o(r))}).catch(r=>{t(r)})}else t(new Error("Unsupported environment"));else e("")}),x0=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_MIME_TYPE:"*/*",arrayBufferToBase64:sC,base64ToArrayBuffer:n=>{const e=typeof window<"u"&&typeof globalThis.atob=="function"?globalThis.atob(n):Buffer.from(n,"base64").toString("binary"),t=e.length,o=new Uint8Array(t);for(let r=0;r<t;r++)o[r]=e.charCodeAt(r);return o.buffer},blobToString:U2},Symbol.toStringTag,{value:"Module"})),aC="data:image/png;base64,",lC="Unable to resolve image.",a7=n=>new Promise(async(e,t)=>{let o=null;try{o=new Image,o.src=n,o.addEventListener("load",function(){e({width:o.naturalWidth,height:o.naturalHeight})},{once:!0}),o.addEventListener("error",function(){URL.revokeObjectURL(n),t("Invalid Image")},{once:!0}),await o.decode("sync")}catch{o?.src&&URL.revokeObjectURL(o.src)}o||t(lC)}),Mf="image/svg+xml",$h=Object.freeze(Object.defineProperty({__proto__:null,DATA_URL_PNG_PREFIX:aC,getImageDataUrl:(n,e=1)=>new Promise(async(t,o)=>{let r=null;try{r=new Image,r.src=n,r.addEventListener("load",function(){try{const i=document.createElement("canvas");i.width=r.naturalWidth,i.height=r.naturalHeight,i.getContext("2d").drawImage(r,0,0);const s=i.toDataURL("image/png",e);t({elemImg:r,dataUrl:s})}catch(i){URL.revokeObjectURL(n),o(i)}},{once:!0}),r.addEventListener("error",function(){URL.revokeObjectURL(n),o("Invalid Image")},{once:!0}),await r.decode("sync")}catch{r?.src&&URL.revokeObjectURL(r.src)}r||o(lC)}),loadImageDetails:async(n,e=null)=>{let t=null;const o=async()=>{try{const i=e??"image/*",s=URL.createObjectURL(new Blob([n],{type:i})),a=await a7(s);t={mimeType:i,naturalDimensions:a,asUrl:s}}catch{}},r=async()=>{try{const i=new TextDecoder().decode(n),s=URL.createObjectURL(new Blob([i],{type:Mf})),a=await a7(s);t={mimeType:e??Mf,naturalDimensions:a,asUrl:s,asSVGText:i}}catch{}};if(e===Mf?await r():e.startsWith("image/")?await o():(await o(),t||await r()),!t)throw new Error("Failed to load image");return t}},Symbol.toStringTag,{value:"Module"}));function Wh(n,e){e||(e={}),typeof e=="function"&&(e={cmp:e});let t=typeof e.cycles=="boolean"&&e.cycles;const o=e.cmp&&function(i){return function(s){return function(a,l){const c={key:a,value:s[a]},d={key:l,value:s[l]};return i(c,d)}}}(e.cmp);let r=[];return function i(s){if(s&&s.toJSON&&typeof s.toJSON=="function"&&(s=s.toJSON()),s===void 0)return;if(typeof s=="number")return isFinite(s)?""+s:"null";if(typeof s!="object")return JSON.stringify(s);let a;if(Array.isArray(s)){a="[";for(let d=0;d<s.length;d++)d&&(a+=","),a+=i(s[d])||"null";return a+"]"}if(s===null)return"null";if(r.indexOf(s)!==-1){if(t)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}const l=r.push(s)-1,c=Object.keys(s).sort(o&&o(s));a="";for(let d=0;d<c.length;d++){const u=c[d],h=i(s[u]);h&&(a&&(a+=","),a+=JSON.stringify(u)+":"+h)}return r.splice(l,1),"{"+a+"}"}(n)}var so,l7;(l7=so||(so={})).resolveTypedUpdates=(n,e,t,o)=>{if(n===null)return n;if(n===void 0)return o;let r=n;if(e?.shorthand){const l=e?.shorthand(n,t);l!==void 0&&(r=l)}if(r!==null&&e?.getSubType){const l=e.getSubType(r);l&&(e=l)}const i=e?.properties,s=e?.arrayType??!1;let a=r;if(e&&e.merge&&a&&o)a=e.merge(a,o,t);else if(!s&&i){const l=Object.keys({...r,...o});a=null;for(let c=0;c<l.length;c++){const d=l[c];let u,h=r[d];if(h!==void 0){const m=i[d];u=m?(0,l7.resolveTypedUpdates)(h,m,t,o?.[d]):h}else u=o?.[d];u!=null&&(a=a??{},a[d]=u)}}return a};let Aa=class extends Error{constructor(n,e=null){super(n,e),this.name="ChainedError",this._cause=e}get cause(){return this._cause}},UI=class extends Aa{constructor(n="Partial Error",e=null){super(n,e)}};class Zn extends UI{constructor(e="Out of bounds",t=null){super(e,t),this.name="OutOfBoundsError"}}let cC=class extends Aa{constructor(n="Partial Error",e=null){super(n,e)}},Bi=class extends Aa{constructor(n="Null not supported",e=null){super(n,e)}},c7=class extends Error{constructor(n="Null not supported",e){super(n),this._type=e}get type(){return this._type}};class dC extends Aa{constructor(e="Not implemented",t=null){super(e,t)}}const d7=`The Safari browser does not support advanced copy and paste. Copy and paste will be limited to within the browser tab. Please use Chrome or Edge if external copy and paste is required.`,Tf=`You do not have permissions to access the clipboard. All copy and paste operations will be limited to the browser tab.`,uC={Safari:`The Safari browser does not support advanced copy and paste. Copy and paste will be limited to within the browser tab. Please use Chrome or Edge if external copy and paste is required.`,Perms:Tf,PermsWrite:mu()===wr.Safari?d7:Tf,PermsRead:mu()===wr.Safari?d7:Tf},If=async()=>new Promise(n=>{document.hasFocus()?n():globalThis.addEventListener?.("focus",()=>{n()},{once:!0}),document.activeElement.focus?.()}),Af=async(n,e,t)=>{if(mu()===wr.Safari)return await t(new Error(uC.Safari));try{const o=async s=>{try{return await s()}catch(a){if(a.message?.includes("Document is not focused"))return!1;throw a}},r=await globalThis?.navigator?.permissions?.query({name:n,allowWithoutGesture:!0,allowWithoutSanitization:!0});let i=!1;if(r.state==="prompt"&&(i=await o(e)),i||r.state!=="granted"||(i=await e()),!i)return await t(new Error(r.state))}catch(o){return o.message==="No valid data on clipboard"||o.name==="DataError"?void 0:await t(o)}},hC=async n=>{try{return await n.read({unsanitized:[nr]})}catch{}return await n.read()},pC=async(n,e)=>{if(!n)return null;const t=await hC(n);let o=!1;for(let r=0;!o&&t&&r<t.length;r++)if(o=t[r].types.includes(e),o)return await t[r].getType(e);return o?void 0:null};if(!globalThis.ClipboardItem){const n=(t,o)=>new Blob([o],{type:t});class e{constructor(o,r){this._items={},this._types=Object.keys(o);const i={},s=Object.keys(o);for(let a=0;a<s.length;a++){const l=s[a];let c=o[l];i[l]=typeof c=="string"?n(l,c):c}this._items=i,this._presentationStyle=r?.presentationStyle??"unspecified"}get types(){return this._types}getType(o){return Promise.resolve(this._items[o])}supports(o){return!0}}globalThis.ClipboardItem=e}const Op=async(n,e=nr)=>new Promise(async(t,o)=>{try{const r=await pC(n,e);if(r){const i=new FileReader;i.onload=()=>{t(i.result)},i.onerror=()=>{t("")},i.readAsText(r)}else t("")}catch(r){o(r)}}),G2=async(n,e=nr)=>{const t=await Op(n,e);if(!t)return null;let o=null;try{o=new DOMParser().parseFromString(t,nr)}catch{console.warn("Can't parse html from clipboard.")}return o},GI=async n=>{n&&await n.writeText("")},qI=pC,XI=Op,KI=G2,fu="clipboard-uuid",zl="web text/uuid",u7=n=>`<div style="display:none" ${fu}="${n}"/>`,YI=(n,e)=>{let t=null;try{const o=new DOMParser().parseFromString(e,nr);o.body.firstElementChild.setAttribute(fu,n),t=o.getElementsByTagName("body")[0].innerHTML}catch(o){console.warn("Can't embed uuid.",o)}return t},h7=(n,e)=>{if(!e||!n)return!1;try{const t=e.querySelectorAll(`[${fu}="${n}"]`);if(t&&t.length===1)return!0;if(e.querySelector("parsererror"))throw new Error("We are unable to parse node");return!1}catch{return!1}};let V0=class{constructor(n){if(n?.nativeClipboard===void 0||n?.nativeClipboard===!0)try{this._nativeClipboard=globalThis?.navigator.clipboard}catch{n?.nativeClipboard===!0&&console.warn("NativeClipboard option set to true but no native clipboard available.")}else this._nativeClipboard=n?.nativeClipboard===!1?null:n?.nativeClipboard;this._disableCheckOnFocus=n?.disableCheckOnFocus??!1,this._init()}async _checkForChanges(){this._nativeClipboard&&this._state&&!this._disableCheckOnFocus&&await Af("clipboard-read",async()=>{await If();const n=await Op(this._nativeClipboard,zl);if(!this._state||n&&n===this._state.uuid)return!0;const e=await G2(this._nativeClipboard,nr);return!this._state||(h7(this._state.uuid,e)||this.clear(),!0)},async n=>{n?.message==="denied"||n.message?.includes("Document is not focused")||mu()===wr.Safari||console.warn("Unable to detect clipboard changes: ",n)})}_init(){const n=this;this._listeners=new Map,this._listenersCapture=new Map,this._state=null,this._nativeClipboard&&(this._onFocus=()=>{n._checkForChanges()},this._onBlur=()=>{globalThis.addEventListener?.("focus",n._onFocus,{once:!0})},globalThis.addEventListener?.("blur",this._onBlur),this._nativeClipboard.addEventListener("clipboardchange",e=>{n._checkForChanges()}))}async read(){if(!this._nativeClipboard)return this._state?.items??null;const n=this;return await Af("clipboard-read",async()=>{if(await If(),this._state?.uuid){const e=await Op(this._nativeClipboard,zl);if(e&&e===n._state.uuid)return!0;const t=await G2(this._nativeClipboard,nr);if(h7(n._state?.uuid,t))return!0}return n._state={items:await hC(this._nativeClipboard),uuid:null,ref:null},this.dispatchEvent(new Event("clipboardread")),!0},async e=>{this.dispatchEvent(new Event("clipboarderrorread"))}),this._state?.items??[]}async write(n){return this._write({uuid:Vh(),items:n,ref:null})}async _write(n){if(!this._nativeClipboard)return this._state=n,this.dispatchEvent(new Event("clipboardwrite")),this.dispatchEvent(new Event("clipboardchange")),null;const e=this,t=[],o=n.uuid;let r=n.items??[];const i=()=>{e._state={uuid:o,ref:n.ref,items:t},e.dispatchEvent(new Event("clipboardwrite")),e.dispatchEvent(new Event("clipboardchange"))};await Af("clipboard-write",async()=>{await If(),o&&r.length===0&&(r.push(new ClipboardItem({[zl]:new Blob([o],{type:zl})})),r.push(new ClipboardItem({[nr]:new Blob([u7(o)],{type:nr})})));for(let s=0;s<Math.min(1,r.length);s++){const a=r[s];let l=a.types.indexOf(nr),c=null;if(l!==-1){const h=await a.getType(nr);c=await U2(h),c&&(c=YI(o,c))}if(!c&&a.types.includes(Ts)){const h=await a.getType(Ts);if(h){let m=null;typeof h=="string"?(console.warn("text as string",h),m=h):m=await U2(h),m&&(c=`<div ${fu}="${o}">${m}</div>`)}}if(!c&&a.types.includes(Wd)){const h=await a.getType(Wd),m=sC(await h.arrayBuffer());c=`<div ${fu}="${o}"><img src="${aC+m}"/></div>`}!c&&o&&(c=u7(o));const d=new Blob([c??""],{type:nr}),u={};for(let h=0;h<a.types.length;h++){const m=a.types[h];u[m]=h===l?d:a.getType(m)}c&&l===-1&&(u[nr]=d),o&&(u[zl]=new Blob([o],{type:zl})),t.push(new ClipboardItem(u))}try{t&&t.length!==0?await this._nativeClipboard.write(t):await GI(this._nativeClipboard)}catch(s){s.message?.includes("Document is not focused")||console.warn("Unable to write to native clipboard: ",s)}return i(),!0},async s=>{this.dispatchEvent(new Event("clipboarderrorwrite")),i()})}async writeReference(n){if(!n)return void this.clear();let e=null;const t={};try{const r=await n.toText?.()??null;r&&(t[Ts]=new Blob([r??""],{type:Ts}))}catch(r){e=r}try{const r=await n.toHtml?.()??null;r&&(t[nr]=new Blob([r],{type:nr}))}catch(r){e=r,console.warn("export to html",r)}try{const r=await n.toImage?.()??null;r&&(t[Wd]=r)}catch(r){e=r,console.warn("export to png",r)}const o=this._write({uuid:Vh(),ref:n,items:Object.keys(t).length>0?[new ClipboardItem(t)]:null});if(e)throw e;return o}clear(n=!1){this._state&&(this._state=null,n&&this._write({uuid:null,ref:null,items:null}),this.dispatchEvent(new Event("clipboardwrite")),this.dispatchEvent(new Event("clipboardchange")))}async readReference(){return await this.read(),this._state?.ref??null}readText(){return new Promise(async(n,e)=>{const t=await this.read();let o=null;for(let i=0;!o&&t&&i<t.length;i++)t[i].types.includes(Ts)&&(o=await t[i].getType(Ts));if(!o)return void n("");const r=new FileReader;r.onload=()=>{n(r.result)},r.readAsText(o),r.onerror=i=>{e(i)}})}async writeText(n){const e=[new ClipboardItem({[Ts]:new Blob([n],{type:Ts})})];return this._write({uuid:Vh(),items:e,ref:null})}addEventListener(n,e,t={}){const o=t?.capture?this._listenersCapture:this._listeners;let r=o.get(n);r||(r=new Map,o.set(n,r)),r.set(e,typeof t=="boolean"?{}:t)}dispatchEvent(n){if(!n)return;const e=t=>{const o=t.get(n.type);o&&o.forEach((r,i)=>{try{typeof i=="function"?i(n):i.handleEvent&&i.handleEvent(n),r.once&&o.delete(i)}catch(s){console.warn(s)}})};return e(this._listenersCapture),e(this._listeners),!0}removeEventListener(n,e,t){const o=t?.capture?this._listenersCapture:this._listeners,r=o.get(n);r&&(r.delete(e),r.size===0&&o.delete(n))}close(){globalThis.removeEventListener?.("focus",this._onFocus),globalThis.removeEventListener?.("blur",this._onBlur)}};var Nf;(Nf=V0||(V0={})).ErrorMessages=uC,Nf.Global=new Nf;let ZI=class{constructor(n=100){this._maxStack=n,this._undoStack=[],this._redoStack=[],this._repeatOperation=null,this._listeners=new Set}get maxStack(){return this._maxStack}undo(n=1){if(this._undoStack.length===0)return;let e=!1;try{for(let t=0;t<n&&this._undoStack.length>0;t++){const o=this._undoStack[this._undoStack.length-1];o.redo=o.undo(),this._undoStack.pop(),typeof o.redo=="function"?this._redoStack.push(o):this._redoStack=[],e=!0}}catch(t){throw t}finally{e&&this._notifyOnStackChange()}}redo(n=1){if(this._redoStack.length===0)return void(this._repeatOperation!==null&&this._repeatOperation.repeat());let e=!1;try{for(let t=0;t<n&&this._redoStack.length>0;t++){const o=this._redoStack[this._redoStack.length-1];o.redo(),this._redoStack.pop(),this._undoStack.push(o),e=!0}}catch(t){throw t}finally{e&&this._notifyOnStackChange()}}hasUndo(){return this._undoStack.length>0}getTopUndoDescription(){return this._undoStack.length===0?null:this._undoStack[this._undoStack.length-1].description}hasRedo(){return this._redoStack.length>0||this._repeatOperation!==null}getTopRedoDescription(){return this._repeatOperation!==null?this._repeatOperation.description:this._redoStack.length===0?null:this._redoStack[this._redoStack.length-1].description}getUndoDescriptions(){if(this._undoDescriptions)return this._undoDescriptions;const n=[];for(let e=this._undoStack.length-1;e>=0;e--)n.push(this._undoStack[e].description);return this._undoDescriptions=n,this._undoDescriptions}getRedoDescriptions(){if(this._redoDescriptions)return this._redoDescriptions;const n=[];for(let e=this._redoStack.length-1;e>=0;e--)n.push(this._redoStack[e].description);return n.length===0&&this._repeatOperation!==null&&n.push(this._repeatOperation.description),this._redoDescriptions=Object.freeze(n),this._redoDescriptions}addUndoOperation(n){const e={description:n.description,undo:n.undo,redo:null};this._undoStack.push(e),this._redoStack=[],this._undoStack.length>this._maxStack&&this._undoStack.shift(),this._notifyOnStackChange()}setRepeatableOperation(n){this._repeatOperation=n??null,this._redoStack=[],this._notifyOnStackChange()}clear(n=!0){this._undoStack=[],this._redoStack=[],this._repeatOperation=null,this._undoDescriptions=null,this._redoDescriptions=null,n&&this._notifyOnStackChange()}addListener(n){const e=this._listeners;return e.add(n),()=>{e.delete(n)}}_notifyOnStackChange(){this._undoDescriptions=null,this._redoDescriptions=null,this._listeners.forEach(n=>{n.onStackChange?.()})}};const p7=(n,e)=>{const t=new Map;return n.forEach((o,r)=>{e.get(r)!==o&&t.set(r,o)}),t};let m7=!1;class f7{constructor(e){this._record=e}getId(){return this._record.id}getDescription(){return this._record.description}getMeta(){return Object.freeze(this._record.meta)}getAuthor(){return this._record.author}getTimestamp(){return this._record.timestamp}getOperation(){return this._record.operation}}let Hi=class{constructor(n){this._listeners=new Set,this._listenersState=new Map,this._commits=new Map,this._locked=!1,this._current=null,this._pending=null,this._isSync=n?.sync??m7,this._isTransient=n?.transient??!1,this._author=n?.author;const e={id:"0",description:"initial",meta:{},author:this._author,timestamp:Date.now(),states:new Map,version:0,previousId:null},t={record:e,commit:new f7(e)};this._current=t,this._cacheModel=null,this._cacheState=null,this._states=e.states,this._transactionStack=[],this._transactionOpen=!1;const o=new Map;o.set(e.id,t),this._commits=o}static{this.setDefaultSync=n=>{m7=n}}getLog(n,e=100){const t=[];let o=n;do{const r=this._commits.get(o);if(!r)throw new Error(`Invalid commit id: '${o}'`);if(t.push(r.commit),o=r.record.previousId,!o)return t}while(t.length<e)}getCommitCount(){return this._commits.size}isOpenTransaction(){return this._transactionStack.length>0||this._transactionOpen}getPendingView(){const n=this._transactionStack;return n.length>0?n[0].getView():null}getState(n){const e=this._transactionStack;if(e.length===0){if(this._cacheModel===n)return this._cacheState;const t=this._states.get(n);return this._cacheModel=n,this._cacheState=t,t}return e[e.length-1].getState(n)}getCurrentCommit(){return this._pending?.commit??this._current.commit}restore(n,e){const t=this._getCommitContainer(n,e);if(this._current.commit.getId()===t.commit.getId())return t.commit;let o;e?.viewId&&e?.viewId!=="custom"||(o=t.record.viewAfter);const r=p7(t.record.states,this._current.record.states);this._notifyStates("onBeforeCommitStart",this._current,r,o,!0,!1),this._current=t,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,this._notifyStates("onAfterStateChange",t,r,o,!1,!0,!0),this._notify("onCommitChange",t.commit,!0),this._transactionOpen=!0;try{this._notifyStates("onRestoreOrRevert",t,t.record.states,o,!1,!0)}finally{this._transactionOpen=!1}return t.commit}revert(n,e){const t=this._getCommitContainer(n,e),o=this._commits.get(t.record.previousId);if(!o)throw new Error(`Invalid commit id: '${t.record.previousId}'`);let r;e?.viewId&&e?.viewId!==" custom"||(r=t.record.viewBefore??t.record.viewAfter);const i=p7(o.record.states,this._current.record.states);this._notifyStates("onBeforeCommitStart",this._current,i,r,!0,!1),this._current=o,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,this._notifyStates("onAfterStateChange",o,i,r,!0,!1,!0),this._notify("onCommitChange",o.commit,!0),this._transactionOpen=!0;try{this._notifyStates("onRestoreOrRevert",o,o.record.states,r,!0,!0)}finally{this._transactionOpen=!1}return o.commit}_getCommitContainer(n,e){const t=this._commits.get(n);if(!t)throw new Error(`Invalid commit id: '${n}'`);if(this._isTransient)throw new Error("Cannot revert transient store");if(e?.force&&this._transactionStack.length>0&&this._transactionStack[0].rollback(),this._transactionStack.length!==0)throw new Error("Open transactions.");return t}_pruneForwards(n){}beginCommit(n,e){const t=this._transactionStack,o=t.length;if(this._locked)throw console.warn("TransactionStore locked",t),new Error(`TransactionStore is locked by '${t[o-1].getDescription()}`);const r=n?.preventFurtherTransactions,i=this,s=(l,c,d)=>{const u=i._transactionStack;o!==u.length-1&&console.warn("Transaction stack out of sync",o,u.length,u),r&&(this._locked=!1),u.pop(),e?.(l,c,d),u.length===0&&(i._pending=null)};let a;if(t.length===0){const l=this._current.record,c={states:new Map,id:oe.uuidV4(),description:typeof n=="string"?n:n?.description??null,meta:{},timestamp:Date.now(),author:null,version:l.version+1,previousId:l.id,viewBefore:null,viewAfter:{},operation:n?.operation},d={record:c,commit:new f7(c)};this._pending=d,this._notify("onCommitStart",d.commit),a=new JI(this,d,l?.states,n,s)}else a=t[t.length-1].beginTransaction(n,s);return r&&(this._locked=!0),this._transactionStack.push(a),a}doBatch(n,e,t){let o;const r=this.beginCommit(e,t),i=this.getCurrentCommit();try{o=n?.(i);const s=()=>{r.commit(e)};if(o&&typeof o.then=="function")return new Promise((a,l)=>{o.then(c=>{try{s(),a(c)}catch(d){l(d)}}).catch(c=>{r.rollback(),l(c)})});s()}catch(s){throw r.rollback(),s}return o}remove(n){return!!n}addListener(n){const e=this._listeners;return e.add(n),()=>{e.delete(n)}}addStateListener(n,e){if(!n)throw new Error("Model is required");if(!e)throw new Error("Listener is required");let t=this._listenersState.get(n);return t||(t=new Set,this._listenersState.set(n,t)),t.add(e),()=>{t.delete(e),t.size===0&&this._listenersState.delete(n)}}dispatchEvents(n,e=!1){!e||this._isSync?n():setTimeout(n,0)}_commitRecord(n,e,t){let o=n.record,r=n.commit;if(!this._isTransient){if(t){const i=this._commits.get(o.previousId);if(i){o.previousId=i.record.id;const s=i.record,a=s.states;a&&o.states.forEach((l,c)=>{a.set(c,l)}),s.viewAfter={...s.viewAfter,...o.viewAfter},s.meta={...s.meta,...o.meta},s.timestamp=o.timestamp,o=s,r=i.commit,n={record:o,commit:r}}}this._commits.set(o.id,n)}this._current=n,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,t||this._notify("onCommitChange",r),this._notifyStates("onAfterStateChange",n,e,n.record.viewAfter,!1,!1,!0),t||this._notify("onCommitEnd",r,!0)}_notifyStates(n,e,t,o,r=!1,i=!1,s=!1){const a=e.commit,l=this._listenersState;t.forEach((c,d)=>{const u=l.get(d);u&&this.dispatchEvents(()=>{u.forEach(h=>{h[n]?.(c,o,a,r,i)})},s)})}_notify(n,e,t=!1){this.dispatchEvents(()=>{this._listeners.forEach(o=>{o[n]?.(e)})},t)}},mC=class{constructor(n,e){this._children=new Set,this._depth=0,this._container=null,this._closed=!1,this._container=n,e=typeof e=="string"?{description:e}:e,this._description=e?.description??"",e?.viewBefore!==void 0&&(n.record.viewBefore=n.record.viewBefore&&e.viewBefore?{...n.record.viewBefore,...e.viewBefore}:e.viewBefore),e?.viewAfter!==void 0&&(n.record.viewAfter=n.record.viewAfter&&e.viewAfter?{...n.record.viewAfter,...e.viewAfter}:e.viewAfter)}getView(){return this._container.record.viewAfter??this._container.record.viewBefore}getDepth(){return this._depth}getDescription(){return this._description}getStates(){return this._states}beginTransaction(n,e){this._ensureOpen();const t=new QI(this,this._container,typeof n=="string"?{description:n}:n,e);return this._children||this._children,this._children.add(t),t}updateState(n,e){this._ensureOpen();const t=this.getState(n),o=typeof e=="function"?e(t):e===void 0?t:{...t,...e};if(o){let r=this._states;r||(r=new Map,this._states=r),r.set(n,o)}return o}commit(n){if(this._ensureOpen(),typeof n=="string"&&(n={description:n}),n){if(n.description&&(this._description=n.description),n.meta&&(this._meta=oe.mergeContentful(n.meta,this._meta)),n.viewAf