kritzel-stencil 0.3.27 → 0.3.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/kritzel-active-users_45.cjs.entry.js +8 -2
- package/dist/cjs/{schema.constants-9v4Edzoe.js → schema.constants-TiseVL4a.js} +14 -1
- package/dist/collection/classes/objects/selection-group.class.js +14 -1
- package/dist/collection/classes/structures/object-map.structure.js +6 -0
- package/dist/collection/constants/version.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-settings.js +1 -1
- package/dist/components/kritzel-tool-config.js +1 -1
- package/dist/components/{p-G3xSPZ0x.js → p-B0g_ls7F.js} +1 -1
- package/dist/components/{p-DXYkgNAO.js → p-BC7jWR_G.js} +1 -1
- package/dist/components/{p-ioK7ttPL.js → p-BqR6dXX-.js} +2 -2
- package/dist/components/{p-BmKYyPpl.js → p-CPnjRgkl.js} +1 -1
- package/dist/components/{p-CRKezkZU.js → p-pCB0JKlD.js} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/kritzel-active-users_45.entry.js +8 -2
- package/dist/esm/{schema.constants-BT66X_r5.js → schema.constants-7ayQfjzt.js} +14 -1
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/{p-BT66X_r5.js → p-7ayQfjzt.js} +1 -1
- package/dist/stencil/p-d6a79b4c.entry.js +9 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/objects/selection-group.class.d.ts +1 -0
- package/dist/types/constants/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/stencil/p-9ca04088.entry.js +0 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{p as t,H as e,c as n,h as i,d as r,t as s}from"./p-B43upypT.js";import{K as o}from"./p-D8W6LE-c.js";import{d as a,D as c,l,i as h,a as u,S as f,c as d,m as p,j as g,n as v,f as w,e as m,b as y,K as b,g as k,k as A}from"./p-BmKYyPpl.js";import{D as x,K as S,a as M}from"./p-CpzicliK.js";import{A as z,a as $,d as C}from"./p-CC0J_kEP.js";import{K as T,W as I}from"./p-DhMlShij.js";import{K as j,c as E,a as _,b as L,d as O}from"./p-BNu3Akp5.js";import{K as P}from"./p-WUdQqYnu.js";import{K as B,d as D}from"./p-BxpKq94F.js";import{O as R}from"./p-Dd-pMvlr.js";import*as W from"yjs";import{a as U,C as F}from"./p-CW-VyJgK.js";import{K,d as V}from"./p-CdR76C4L.js";import{K as N}from"./p-jGOpkGDl.js";import{d as G}from"./p-B4WfPDj0.js";import{d as H}from"./p-B4b6TDxp.js";var X="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};const Y="__kritzelCustomElementRendererRegistry__";class Q{static get _renderers(){return(()=>{const t=globalThis,e=t[Y];if(e)return e;const n={renderers:new Map};return t[Y]=n,n})().renderers}static register(t,e){this._renderers.set(t,e)}static get(t){return this._renderers.get(t)}static unregister(t){return this._renderers.delete(t)}}class Z extends j{__class__="KritzelCustomElement";element;rendererKey=null;rendererData;constructor(t){super(),t&&(this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.rotation=E.degreesToRadians(t.rotation??0),this.scale=t.scale||1,this.element=t.element??this.createPlaceholder(),this.height=t.height||0,this.width=t.width||0,this.rendererKey=t.rendererKey??null,this.rendererData=t.rendererData)}static create(t,e){const n=new Z(e);return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.userId=t.user?.id,n.zIndex=t.store.currentZIndex,n}mount(t){if(null!==t){if(this.applyInteractiveState(),this.isMounted&&this.elementRef===t){if(this.rendererKey)return;if(this.element.parentElement===t)return}if(this.elementRef=t,this.isMounted=!0,this.rendererKey){const e=Q.get(this.rendererKey);if(e)return t.innerHTML="",e.onMount({object:this,container:t,data:this.rendererData}),void this.applyInteractiveState()}this.elementRef.innerHTML="",this.elementRef.appendChild(this.element),this.applyInteractiveState()}}setIsInteractive(t){const e=this.isInteractive!==t;this.isInteractive=t,this.applyInteractiveState(),e&&!t&&this.blurFocusedDescendant()}applyInteractiveState(){const t=this.isInteractive?"auto":"none",e=this.isInteractive?"auto":"";this.element&&(this.element.style.pointerEvents=t,this.element.style.cursor=e),this.elementRef instanceof HTMLElement&&(this.elementRef.style.pointerEvents="auto",this.elementRef.style.cursor="",Array.from(this.elementRef.children).forEach((n=>{n instanceof HTMLElement&&(n.style.pointerEvents=t,n.style.cursor=e)})))}blurFocusedDescendant(){if(!(this.element||this.elementRef instanceof HTMLElement))return;const t=this.getDeepActiveElement(),e=!!this.element&&this.isNodeInsideHost(t,this.element),n=this.elementRef instanceof HTMLElement&&this.isNodeInsideHost(t,this.elementRef);t&&(e||n)&&t.blur()}hasFocusedInputElement(){if(!this.isInteractive)return!1;const t=this.getFocusHosts();if(t.some((t=>this.hasFocusedInputDescendant(t))))return!0;const e=this.getDeepActiveElement();return!!(e&&this.isInputLikeElement(e)&&t.some((t=>this.isNodeInsideHost(e,t))))}getFocusHosts(){const t=[];if(this.element&&t.push(this.element),this.elementRef instanceof HTMLElement){t.push(this.elementRef);const e=this.elementRef.firstElementChild;e instanceof HTMLElement&&t.push(e)}return t}hasFocusedInputDescendant(t){if(this.isInputLikeElement(t)&&this.matchesFocus(t))return!0;if("function"==typeof t.matches)try{if(!t.matches(":focus-within"))return!1}catch{}return null!==this.findFocusedInputLikeElement(t)}findFocusedInputLikeElement(t){let e=null;try{e=t.querySelector(":focus")}catch{e=null}return e instanceof HTMLElement?this.isInputLikeElement(e)?e:e.shadowRoot?this.findFocusedInputLikeElement(e.shadowRoot):null:null}matchesFocus(t){if("function"!=typeof t.matches)return!1;try{return t.matches(":focus")}catch{return!1}}isInputLikeElement(t){const e=t.tagName;return"INPUT"===e||"TEXTAREA"===e||"SELECT"===e||t.isContentEditable}isNodeInsideHost(t,e){if(!t)return!1;let n=t;for(;n;){if(n===e)return!0;if(n.parentNode){n=n.parentNode;continue}const t=n.getRootNode();if(!(t instanceof ShadowRoot))break;n=t.host}return!1}getDeepActiveElement(t=document){const e=t.activeElement;return e instanceof HTMLElement?e.shadowRoot?this.getDeepActiveElement(e.shadowRoot)??e:e:null}unmount(){if(this.isMounted&&this.elementRef){if(this.rendererKey){const t=Q.get(this.rendererKey);if(t){const e=t.onUnmount({object:this,container:this.elementRef,data:this.rendererData});void 0!==e&&(this.rendererData=e)}}this.isMounted=!1,this.elementRef=null}}isElementScrollable(){return!!P.findScrollableElement(this.element)}createPlaceholder(){const t=document.createElement("div");return t.textContent="[Custom Element]",t.style.border="1px dashed #ccc",t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.style.backgroundColor="#f9f9f9",t.style.color="#999",t.style.fontSize="12px",t}resize(t,e,n,i){n<=1||i<=1||(this.width=n,this.height=i,this.translateX=t,this.translateY=e,this.element&&(this.element.style.width=`${n}px`,this.element.style.height=`${i}px`),this._core.store.objects.update(this))}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t.isSelected=!1,t.isHovered=!1,t.isInteractive=!1,t.resizing=!1,t.markedForRemoval=!1,t.isVisible=!0,t.element=this.element.cloneNode(!0),t}serialize(){const{_core:t,_elementRef:e,element:n,totalWidth:i,totalHeight:r,isSelected:s,isHovered:o,isMounted:a,isInteractive:c,resizing:l,markedForRemoval:h,isVisible:u,...f}=this,d=structuredClone(f);return d.rendererKey=this.rendererKey,d.rendererData=this.rendererData,d.htmlString=n?n.outerHTML:"",d.serializedWidth=this.width,d.serializedHeight=this.height,d}deserialize(t){if(super.deserialize(t),delete this.allowEmbeddedInteraction,this.rendererKey=t.rendererKey??null,this.rendererData=t.rendererData,t.htmlString)try{const e=document.createElement("div");e.innerHTML=t.htmlString,this.element=e.firstElementChild||this.createPlaceholder()}catch{this.element=this.createPlaceholder()}else this.element=this.createPlaceholder();return this}}class q extends a{toolType="brush";color=x[0];size=6;opacity=1;palette=[...x];sizes=[...c];static MIN_POINT_DISTANCE_PX=3;_currentPathId=null;shouldAppendPoint(t,e,n,i){const r=t.points;if(!r||0===r.length)return!0;const s=r[r.length-1],o=e-s[0],a=n-s[1],c=q.MIN_POINT_DISTANCE_PX/i;return o*o+a*a>=c*c}constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&l.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=_.create(this._core,{points:[[(t.clientX-this._core.store.offsetX)/i,(t.clientY-this._core.store.offsetY)/i]],translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});r.isCompleted=!1,this._currentPathId=r.id,this._core.store.objects.insert(r),this._core.store.objects?.setActiveDrawingObject(r.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/i),s=Math.round((t[0].clientY-this._core.store.offsetY)/i);this._core.store.state.isDrawing=!0;const o=_.create(this._core,{points:[[r,s]],translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});o.isCompleted=!1,this._currentPathId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentPathId){const e=this._core.store.objects.findById(this._currentPathId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=(t.clientX-this._core.store.offsetX)/r,o=(t.clientY-this._core.store.offsetY)/r;if(!this.shouldAppendPoint(e,s,o,r))return;const a=_.create(this._core,{points:[...e.points,[s,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,fill:this.color,strokeWidth:this.size,opacity:this.opacity});a.id=e.id,a.workspaceId=e.workspaceId,a.zIndex=e.zIndex,a.isCompleted=!1,this._core.store.objects.update(a)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentPathId){const e=this._core.store.objects.findById(this._currentPathId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r);if(!this.shouldAppendPoint(e,s,o,r))return;const a=_.create(this._core,{points:[...e.points,[s,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,fill:this.color,strokeWidth:this.size,opacity:this.opacity});a.id=e.id,a.workspaceId=e.workspaceId,a.zIndex=e.zIndex,a.isCompleted=!1,this._core.store.objects.update(a)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}}}class J extends a{toolType="line";color=x[0];size=4;opacity=1;palette=[...x];sizes=[...c];arrows;_startX=0;_startY=0;_currentLineId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&l.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=(t.clientX-this._core.store.offsetX)/i,s=(t.clientY-this._core.store.offsetY)/i;this._startX=r,this._startY=s;const o=L.create(this._core,{startX:r,startY:s,endX:r,endY:s,translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/i),s=Math.round((t[0].clientY-this._core.store.offsetY)/i);this._core.store.state.isDrawing=!0,this._startX=r,this._startY=s;const o=L.create(this._core,{startX:r,startY:s,endX:r,endY:s,translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentLineId){const e=this._core.store.objects.findById(this._currentLineId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=L.create(this._core,{startX:this._startX,startY:this._startY,endX:(t.clientX-this._core.store.offsetX)/r,endY:(t.clientY-this._core.store.offsetY)/r,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});s.id=e.id,s.workspaceId=e.workspaceId,s.zIndex=e.zIndex,s.isCompleted=!1,this._core.store.objects.update(s)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentLineId){const e=this._core.store.objects.findById(this._currentLineId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r),a=L.create(this._core,{startX:this._startX,startY:this._startY,endX:s,endY:o,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});a.id=e.id,a.workspaceId=e.workspaceId,a.zIndex=e.zIndex,a.isCompleted=!1,this._core.store.objects.update(a)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}}selectLineAndSwitchTool(t){const e=h.create(this._core);e.addOrRemove(t),e.isSelected=!0,e.rotation=t.rotation,this._core.addSelectionGroup(e),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection")),this._core.rerender()}}class tt extends a{toolType="eraser";touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&l.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"!==t.pointerType&&"pen"!==t.pointerType||(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||(this._core.store.state.isErasing=!0)}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const e=this._core.getObjectsFromPointerEvent(t,".object");if(0===e.length)return;const n=this._core.store.state.pointerX,i=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(n,i)})),this._core.rerender()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&1===this._core.store.state.pointers.size&&this._core.store.state.isErasing){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const n=this._core.getObjectsFromPointerEvent(t,".object");if(0===n.length)return;const i=this._core.store.state.pointerX,r=this._core.store.state.pointerY;n.forEach((t=>{t.markedForRemoval=t.hitTest(i,r)})),this._core.rerender()}}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}if(("touch"===t.pointerType||"pen"===t.pointerType)&&(clearTimeout(this.touchStartTimeout),this._core.store.state.isErasing)){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}}}function et(t,e){return new Promise((function(n,i){let r;return nt(t).then((function(t){try{return r=t,n(new Blob([e.slice(0,2),r,e.slice(2)],{type:"image/jpeg"}))}catch(t){return i(t)}}),i)}))}const nt=t=>new Promise(((e,n)=>{const i=new FileReader;i.addEventListener("load",(({target:{result:t}})=>{const i=new DataView(t);let r=0;if(65496!==i.getUint16(r))return n("not a valid JPEG");for(r+=2;;){const s=i.getUint16(r);if(65498===s)break;const o=i.getUint16(r+2);if(65505===s&&1165519206===i.getUint32(r+4)){const s=r+10;let a;switch(i.getUint16(s)){case 18761:a=!0;break;case 19789:a=!1;break;default:return n("TIFF header contains invalid endian")}if(42!==i.getUint16(s+2,a))return n("TIFF header contains invalid version");const c=i.getUint32(s+4,a),l=s+c+2+12*i.getUint16(s+c,a);for(let t=s+c+2;t<l;t+=12)if(274==i.getUint16(t,a)){if(3!==i.getUint16(t+2,a))return n("Orientation data type is invalid");if(1!==i.getUint32(t+4,a))return n("Orientation data count is invalid");i.setUint16(t+8,1,a);break}return e(t.slice(r,r+2+o))}r+=2+o}return e(new Blob)})),i.readAsArrayBuffer(t)}));var it={},rt={get exports(){return it},set exports(t){it=t}};!function(){var t,e,n={};rt.exports=n,n.parse=function(t,e){for(var i=n.bin.readUshort,r=n.bin.readUint,s=0,o={},a=new Uint8Array(t),c=a.length-4;101010256!=r(a,c);)c--;s=c,s+=4;var l=i(a,s+=4);i(a,s+=2);var h=r(a,s+=2),u=r(a,s+=4);s+=4,s=u;for(var f=0;f<l;f++){r(a,s),s+=4,s+=4,s+=4,r(a,s+=4),h=r(a,s+=4);var d=r(a,s+=4),p=i(a,s+=4),g=i(a,s+2),v=i(a,s+4);s+=6;var w=r(a,s+=8);s+=4,s+=p+g+v,n._readLocal(a,w,o,h,d,e)}return o},n._readLocal=function(t,e,i,r,s,o){var a=n.bin.readUshort,c=n.bin.readUint;c(t,e),a(t,e+=4),a(t,e+=2);var l=a(t,e+=2);c(t,e+=2),c(t,e+=4),e+=4;var h=a(t,e+=8),u=a(t,e+=2),f=n.bin.readUTF8(t,e+=2,h);if(e+=h,e+=u,o)i[f]={size:s,csize:r};else{var d=new Uint8Array(t.buffer,e);if(0==l)i[f]=new Uint8Array(d.buffer.slice(e,e+r));else{if(8!=l)throw"unknown compression method: "+l;var p=new Uint8Array(s);n.inflateRaw(d,p),i[f]=p}}},n.inflateRaw=function(t,e){return n.F.inflate(t,e)},n.inflate=function(t,e){return n.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),e)},n.deflate=function(t,e){null==e&&(e={level:6});var i=0,r=new Uint8Array(50+Math.floor(1.1*t.length));r[i]=120,r[i+1]=156,i=n.F.deflateRaw(t,r,i+=2,e.level);var s=n.adler(t,0,t.length);return r[i+0]=s>>>24&255,r[i+1]=s>>>16&255,r[i+2]=s>>>8&255,r[i+3]=s>>>0&255,new Uint8Array(r.buffer,0,i+4)},n.deflateRaw=function(t,e){null==e&&(e={level:6});var i=new Uint8Array(50+Math.floor(1.1*t.length)),r=n.F.deflateRaw(t,i,r,e.level);return new Uint8Array(i.buffer,0,r)},n.encode=function(t,e){null==e&&(e=!1);var i=0,r=n.bin.writeUint,s=n.bin.writeUshort,o={};for(var a in t){var c=!n._noNeed(a)&&!e,l=t[a],h=n.crc.crc(l,0,l.length);o[a]={cpr:c,usize:l.length,crc:h,file:c?n.deflateRaw(l):l}}for(var a in o)i+=o[a].file.length+30+46+2*n.bin.sizeUTF8(a);i+=22;var u=new Uint8Array(i),f=0,d=[];for(var a in o){var p=o[a];d.push(f),f=n._writeHeader(u,f,a,p,0)}var g=0,v=f;for(var a in o)p=o[a],d.push(f),f=n._writeHeader(u,f,a,p,1,d[g++]);var w=f-v;return r(u,f,101010256),f+=4,s(u,f+=4,g),s(u,f+=2,g),r(u,f+=2,w),r(u,f+=4,v),f+=4,f+=2,u.buffer},n._noNeed=function(t){var e=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(e)},n._writeHeader=function(t,e,i,r,s,o){var a=n.bin.writeUint,c=n.bin.writeUshort,l=r.file;return a(t,e,0==s?67324752:33639248),e+=4,1==s&&(e+=2),c(t,e,20),c(t,e+=2,0),c(t,e+=2,r.cpr?8:0),a(t,e+=2,0),a(t,e+=4,r.crc),a(t,e+=4,l.length),a(t,e+=4,r.usize),c(t,e+=4,n.bin.sizeUTF8(i)),c(t,e+=2,0),e+=2,1==s&&(e+=2,e+=2,a(t,e+=6,o),e+=4),e+=n.bin.writeUTF8(t,e,i),0==s&&(t.set(l,e),e+=l.length),e},n.crc={table:function(){for(var t=new Uint32Array(256),e=0;e<256;e++){for(var n=e,i=0;i<8;i++)1&n?n=3988292384^n>>>1:n>>>=1;t[e]=n}return t}(),update:function(t,e,i,r){for(var s=0;s<r;s++)t=n.crc.table[255&(t^e[i+s])]^t>>>8;return t},crc:function(t,e,i){return 4294967295^n.crc.update(4294967295,t,e,i)}},n.adler=function(t,e,n){for(var i=1,r=0,s=e,o=e+n;s<o;){for(var a=Math.min(s+5552,o);s<a;)r+=i+=t[s++];i%=65521,r%=65521}return r<<16|i},n.bin={readUshort:function(t,e){return t[e]|t[e+1]<<8},writeUshort:function(t,e,n){t[e]=255&n,t[e+1]=n>>8&255},readUint:function(t,e){return 16777216*t[e+3]+(t[e+2]<<16|t[e+1]<<8|t[e])},writeUint:function(t,e,n){t[e]=255&n,t[e+1]=n>>8&255,t[e+2]=n>>16&255,t[e+3]=n>>24&255},readASCII:function(t,e,n){for(var i="",r=0;r<n;r++)i+=String.fromCharCode(t[e+r]);return i},writeASCII:function(t,e,n){for(var i=0;i<n.length;i++)t[e+i]=n.charCodeAt(i)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,i){for(var r,s="",o=0;o<i;o++)s+="%"+n.bin.pad(t[e+o].toString(16));try{r=decodeURIComponent(s)}catch(r){return n.bin.readASCII(t,e,i)}return r},writeUTF8:function(t,e,n){for(var i=n.length,r=0,s=0;s<i;s++){var o=n.charCodeAt(s);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[e+r]=240|o>>18,t[e+r+1]=128|o>>12&63,t[e+r+2]=128|o>>6&63,t[e+r+3]=128|63&o,r+=4}else t[e+r]=224|o>>12,t[e+r+1]=128|o>>6&63,t[e+r+2]=128|63&o,r+=3;else t[e+r]=192|o>>6,t[e+r+1]=128|63&o,r+=2;else t[e+r]=o,r++}return r},sizeUTF8:function(t){for(var e=t.length,n=0,i=0;i<e;i++){var r=t.charCodeAt(i);if(4294967168&r)if(4294965248&r)if(4294901760&r){if(4292870144&r)throw"e";n+=4}else n+=3;else n+=2;else n++}return n}},n.F={},n.F.deflateRaw=function(t,e,i,r){var s=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][r],o=n.F.U,a=n.F._goodIndex,c=n.F._putsE,l=0,h=i<<3,u=0,f=t.length;if(0==r){for(;l<f;)c(e,h,l+(S=Math.min(65535,f-l))==f?1:0),h=n.F._copyExact(t,l,S,e,h+8),l+=S;return h>>>3}var d=o.lits,p=o.strt,g=o.prev,v=0,w=0,m=0,y=0,b=0,k=0;for(f>2&&(p[k=n.F._hash(t,0)]=0),l=0;l<f;l++){if(b=k,l+1<f-2){k=n.F._hash(t,l+1);var A=l+1&32767;g[A]=p[k],p[k]=A}if(u<=l){(v>14e3||w>26697)&&f-l>100&&(u<l&&(d[v]=l-u,v+=2,u=l),h=n.F._writeBlock(l==f-1||u==f?1:0,d,v,y,t,m,l-m,e,h),v=w=y=0,m=l);var x=0;l<f-2&&(x=n.F._bestMatch(t,l,g,b,Math.min(s[2],f-l),s[3]));var S=x>>>16,M=65535&x;if(0!=x){M=65535&x;var z=a(S=x>>>16,o.of0);o.lhst[257+z]++;var $=a(M,o.df0);o.dhst[$]++,y+=o.exb[z]+o.dxb[$],d[v]=S<<23|l-u,d[v+1]=M<<16|z<<8|$,v+=2,u=l+S}else o.lhst[t[l]]++;w++}}for(m==l&&0!=t.length||(u<l&&(d[v]=l-u,v+=2,u=l),h=n.F._writeBlock(1,d,v,y,t,m,l-m,e,h),v=0,w=0,v=w=y=0,m=l);7&h;)h++;return h>>>3},n.F._bestMatch=function(t,e,i,r,s,o){var a=32767&e,c=i[a],l=a-c+32768&32767;if(c==a||r!=n.F._hash(t,e-l))return 0;for(var h=0,u=0,f=Math.min(32767,e);l<=f&&0!=--o&&c!=a;){if(0==h||t[e+h]==t[e+h-l]){var d=n.F._howLong(t,e,l);if(d>h){if(u=l,(h=d)>=s)break;l+2<d&&(d=l+2);for(var p=0,g=0;g<d-2;g++){var v=e-l+g+32768&32767,w=v-i[v]+32768&32767;w>p&&(p=w,c=v)}}}l+=(a=c)-(c=i[a])+32768&32767}return h<<16|u},n.F._howLong=function(t,e,n){if(t[e]!=t[e-n]||t[e+1]!=t[e+1-n]||t[e+2]!=t[e+2-n])return 0;var i=e,r=Math.min(t.length,e+258);for(e+=3;e<r&&t[e]==t[e-n];)e++;return e-i},n.F._hash=function(t,e){return(t[e]<<8|t[e+1])+(t[e+2]<<4)&65535},n.saved=0,n.F._writeBlock=function(t,e,i,r,s,o,a,c,l){var h,u,f,d,p,g,v,w,m,y=n.F.U,b=n.F._putsF,k=n.F._putsE;y.lhst[256]++,u=(h=n.F.getTrees())[0],f=h[1],d=h[2],p=h[3],g=h[4],v=h[5],w=h[6],m=h[7];var A=32+(l+3&7?8-(l+3&7):0)+(a<<3),x=r+n.F.contSize(y.fltree,y.lhst)+n.F.contSize(y.fdtree,y.dhst),S=r+n.F.contSize(y.ltree,y.lhst)+n.F.contSize(y.dtree,y.dhst);S+=14+3*v+n.F.contSize(y.itree,y.ihst)+(2*y.ihst[16]+3*y.ihst[17]+7*y.ihst[18]);for(var M=0;M<286;M++)y.lhst[M]=0;for(M=0;M<30;M++)y.dhst[M]=0;for(M=0;M<19;M++)y.ihst[M]=0;var z=A<x&&A<S?0:x<S?1:2;if(b(c,l,t),b(c,l+1,z),l+=3,0==z){for(;7&l;)l++;l=n.F._copyExact(s,o,a,c,l)}else{var $,C;if(1==z&&($=y.fltree,C=y.fdtree),2==z){n.F.makeCodes(y.ltree,u),n.F.revCodes(y.ltree,u),n.F.makeCodes(y.dtree,f),n.F.revCodes(y.dtree,f),n.F.makeCodes(y.itree,d),n.F.revCodes(y.itree,d),$=y.ltree,C=y.dtree,k(c,l,p-257),k(c,l+=5,g-1),k(c,l+=5,v-4),l+=4;for(var T=0;T<v;T++)k(c,l+3*T,y.itree[1+(y.ordr[T]<<1)]);l=n.F._codeTiny(w,y.itree,c,l+=3*v),l=n.F._codeTiny(m,y.itree,c,l)}for(var I=o,j=0;j<i;j+=2){for(var E=e[j],_=E>>>23,L=I+(8388607&E);I<L;)l=n.F._writeLit(s[I++],$,c,l);if(0!=_){var O=e[j+1],P=O>>16,B=O>>8&255,D=255&O;k(c,l=n.F._writeLit(257+B,$,c,l),_-y.of0[B]),b(c,l=n.F._writeLit(D,C,c,l+=y.exb[B]),P-y.df0[D]),l+=y.dxb[D],I+=_}}l=n.F._writeLit(256,$,c,l)}return l},n.F._copyExact=function(t,e,n,i,r){var s=r>>>3;return i[s]=n,i[s+1]=n>>>8,i[s+2]=255-i[s],i[s+3]=255-i[s+1],s+=4,i.set(new Uint8Array(t.buffer,e,n),s),r+(n+4<<3)},n.F.getTrees=function(){for(var t=n.F.U,e=n.F._hufTree(t.lhst,t.ltree,15),i=n.F._hufTree(t.dhst,t.dtree,15),r=[],s=n.F._lenCodes(t.ltree,r),o=[],a=n.F._lenCodes(t.dtree,o),c=0;c<r.length;c+=2)t.ihst[r[c]]++;for(c=0;c<o.length;c+=2)t.ihst[o[c]]++;for(var l=n.F._hufTree(t.ihst,t.itree,7),h=19;h>4&&0==t.itree[1+(t.ordr[h-1]<<1)];)h--;return[e,i,l,s,a,h,r,o]},n.F.getSecond=function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(t[n+1]);return e},n.F.nonZero=function(t){for(var e="",n=0;n<t.length;n+=2)0!=t[n+1]&&(e+=(n>>1)+",");return e},n.F.contSize=function(t,e){for(var n=0,i=0;i<e.length;i++)n+=e[i]*t[1+(i<<1)];return n},n.F._codeTiny=function(t,e,i,r){for(var s=0;s<t.length;s+=2){var o=t[s],a=t[s+1];r=n.F._writeLit(o,e,i,r);var c=16==o?2:17==o?3:7;o>15&&(n.F._putsE(i,r,a,c),r+=c)}return r},n.F._lenCodes=function(t,e){for(var n=t.length;2!=n&&0==t[n-1];)n-=2;for(var i=0;i<n;i+=2){var r=t[i+1],s=i+3<n?t[i+3]:-1,o=i+5<n?t[i+5]:-1,a=0==i?-1:t[i-1];if(0==r&&s==r&&o==r){for(var c=i+5;c+2<n&&t[c+2]==r;)c+=2;(l=Math.min(c+1-i>>>1,138))<11?e.push(17,l-3):e.push(18,l-11),i+=2*l-2}else if(r==a&&s==r&&o==r){for(c=i+5;c+2<n&&t[c+2]==r;)c+=2;var l=Math.min(c+1-i>>>1,6);e.push(16,l-3),i+=2*l-2}else e.push(r,0)}return n>>>1},n.F._hufTree=function(t,e,i){var r=[],s=t.length,o=e.length,a=0;for(a=0;a<o;a+=2)e[a]=0,e[a+1]=0;for(a=0;a<s;a++)0!=t[a]&&r.push({lit:a,f:t[a]});var c=r.length,l=r.slice(0);if(0==c)return 0;if(1==c){var h=r[0].lit;return l=0==h?1:0,e[1+(h<<1)]=1,e[1+(l<<1)]=1,1}r.sort((function(t,e){return t.f-e.f}));var u=r[0],f=r[1],d=0,p=1,g=2;for(r[0]={lit:-1,f:u.f+f.f,l:u,r:f,d:0};p!=c-1;)u=d!=p&&(g==c||r[d].f<r[g].f)?r[d++]:r[g++],f=d!=p&&(g==c||r[d].f<r[g].f)?r[d++]:r[g++],r[p++]={lit:-1,f:u.f+f.f,l:u,r:f};var v=n.F.setDepth(r[p-1],0);for(v>i&&(n.F.restrictDepth(l,i,v),v=i),a=0;a<c;a++)e[1+(l[a].lit<<1)]=l[a].d;return v},n.F.setDepth=function(t,e){return-1!=t.lit?(t.d=e,e):Math.max(n.F.setDepth(t.l,e+1),n.F.setDepth(t.r,e+1))},n.F.restrictDepth=function(t,e,n){var i=0,r=1<<n-e,s=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),i=0;i<t.length&&t[i].d>e;i++){var o=t[i].d;t[i].d=e,s+=r-(1<<n-o)}for(s>>>=n-e;s>0;)(o=t[i].d)<e?(t[i].d++,s-=1<<e-o-1):i++;for(;i>=0;i--)t[i].d==e&&s<0&&(t[i].d--,s++);0!=s&&console.log("debt left")},n.F._goodIndex=function(t,e){var n=0;return e[16|n]<=t&&(n|=16),e[8|n]<=t&&(n|=8),e[4|n]<=t&&(n|=4),e[2|n]<=t&&(n|=2),e[1|n]<=t&&(n|=1),n},n.F._writeLit=function(t,e,i,r){return n.F._putsF(i,r,e[t<<1]),r+e[1+(t<<1)]},n.F.inflate=function(t,e){var i=Uint8Array;if(3==t[0]&&0==t[1])return e||new i(0);var r=n.F,s=r._bitsF,o=r._bitsE,a=r._decodeTiny,c=r.makeCodes,l=r.codes2map,h=r._get17,u=r.U,f=null==e;f&&(e=new i(t.length>>>2<<3));for(var d,p,g=0,v=0,w=0,m=0,y=0,b=0,k=0,A=0,x=0;0==g;)if(g=s(t,x,1),v=s(t,x+1,2),x+=3,0!=v){if(f&&(e=n.F._check(e,A+(1<<17))),1==v&&(d=u.flmap,p=u.fdmap,b=511,k=31),2==v){w=o(t,x,5)+257,m=o(t,x+5,5)+1,y=o(t,x+10,4)+4,x+=14;for(var S=0;S<38;S+=2)u.itree[S]=0,u.itree[S+1]=0;var M=1;for(S=0;S<y;S++){var z=o(t,x+3*S,3);u.itree[1+(u.ordr[S]<<1)]=z,z>M&&(M=z)}x+=3*y,c(u.itree,M),l(u.itree,M,u.imap),d=u.lmap,p=u.dmap,x=a(u.imap,(1<<M)-1,w+m,t,x,u.ttree);var $=r._copyOut(u.ttree,0,w,u.ltree);b=(1<<$)-1;var C=r._copyOut(u.ttree,w,m,u.dtree);k=(1<<C)-1,c(u.ltree,$),l(u.ltree,$,d),c(u.dtree,C),l(u.dtree,C,p)}for(;;){var T=d[h(t,x)&b];x+=15&T;var I=T>>>4;if(I>>>8==0)e[A++]=I;else{if(256==I)break;var j=A+I-254;if(I>264){var E=u.ldef[I-257];j=A+(E>>>3)+o(t,x,7&E),x+=7&E}var _=p[h(t,x)&k],L=u.ddef[_>>>4],O=(L>>>4)+s(t,x+=15&_,15&L);for(x+=15&L,f&&(e=n.F._check(e,A+(1<<17)));A<j;)e[A]=e[A++-O],e[A]=e[A++-O],e[A]=e[A++-O],e[A]=e[A++-O];A=j}}}else{7&x&&(x+=8-(7&x));var P=4+(x>>>3),B=t[P-4]|t[P-3]<<8;f&&(e=n.F._check(e,A+B)),e.set(new i(t.buffer,t.byteOffset+P,B),A),x=P+B<<3,A+=B}return e.length==A?e:e.slice(0,A)},n.F._check=function(t,e){var n=t.length;if(e<=n)return t;var i=new Uint8Array(Math.max(n<<1,e));return i.set(t,0),i},n.F._decodeTiny=function(t,e,i,r,s,o){for(var a=n.F._bitsE,c=n.F._get17,l=0;l<i;){var h=t[c(r,s)&e];s+=15&h;var u=h>>>4;if(u<=15)o[l]=u,l++;else{var f=0,d=0;16==u?(d=3+a(r,s,2),s+=2,f=o[l-1]):17==u?(d=3+a(r,s,3),s+=3):18==u&&(d=11+a(r,s,7),s+=7);for(var p=l+d;l<p;)o[l]=f,l++}}return s},n.F._copyOut=function(t,e,n,i){for(var r=0,s=0,o=i.length>>>1;s<n;){var a=t[s+e];i[s<<1]=0,i[1+(s<<1)]=a,a>r&&(r=a),s++}for(;s<o;)i[s<<1]=0,i[1+(s<<1)]=0,s++;return r},n.F.makeCodes=function(t,e){for(var i,r,s,o,a=n.F.U,c=t.length,l=a.bl_count,h=0;h<=e;h++)l[h]=0;for(h=1;h<c;h+=2)l[t[h]]++;var u=a.next_code;for(i=0,l[0]=0,r=1;r<=e;r++)u[r]=i=i+l[r-1]<<1;for(s=0;s<c;s+=2)0!=(o=t[s+1])&&(t[s]=u[o],u[o]++)},n.F.codes2map=function(t,e,i){for(var r=t.length,s=n.F.U.rev15,o=0;o<r;o+=2)if(0!=t[o+1])for(var a=t[o+1],c=o>>1<<4|a,l=e-a,h=t[o]<<l,u=h+(1<<l);h!=u;)i[s[h]>>>15-e]=c,h++},n.F.revCodes=function(t,e){for(var i=n.F.U.rev15,r=15-e,s=0;s<t.length;s+=2)t[s]=i[t[s]<<e-t[s+1]]>>>r},n.F._putsE=function(t,e,n){var i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8},n.F._putsF=function(t,e,n){var i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8,t[i+2]|=n>>>16},n.F._bitsE=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<n)-1},n.F._bitsF=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<n)-1},n.F._get17=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},n.F._get25=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},n.F.U=(t=Uint16Array,e=Uint32Array,{next_code:new t(16),bl_count:new t(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new t(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new e(32),flmap:new t(512),fltree:[],fdmap:new t(32),fdtree:[],lmap:new t(32768),ltree:[],ttree:[],dmap:new t(32768),dtree:[],imap:new t(512),itree:[],rev15:new t(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=n.F.U,e=0;e<32768;e++){var i=e;i=(4278255360&(i=(4042322160&(i=(3435973836&(i=(2863311530&i)>>>1|(1431655765&i)<<1))>>>2|(858993459&i)<<2))>>>4|(252645135&i)<<4))>>>8|(16711935&i)<<8,t.rev15[e]=(i>>>16|i<<16)>>>17}function r(t,e,n){for(;0!=e--;)t.push(0,n)}for(e=0;e<32;e++)t.ldef[e]=t.of0[e]<<3|t.exb[e],t.ddef[e]=t.df0[e]<<4|t.dxb[e];r(t.fltree,144,8),r(t.fltree,112,9),r(t.fltree,24,7),r(t.fltree,8,8),n.F.makeCodes(t.fltree,9),n.F.codes2map(t.fltree,9,t.flmap),n.F.revCodes(t.fltree,9),r(t.fdtree,32,5),n.F.makeCodes(t.fdtree,5),n.F.codes2map(t.fdtree,5,t.fdmap),n.F.revCodes(t.fdtree,5),r(t.itree,19,0),r(t.ltree,286,0),r(t.dtree,30,0),r(t.ttree,320,0)}()}();var st=function(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(n){if("default"!==n&&!(n in t)){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}}))})),Object.freeze(t)}({__proto__:null,default:it},[it]);const ot=function(){var t={nextZero(t,e){for(;0!=t[e];)e++;return e},readUshort:(t,e)=>t[e]<<8|t[e+1],writeUshort(t,e,n){t[e]=n>>8&255,t[e+1]=255&n},readUint:(t,e)=>16777216*t[e]+(t[e+1]<<16|t[e+2]<<8|t[e+3]),writeUint(t,e,n){t[e]=n>>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n},readASCII(t,e,n){let i="";for(let r=0;r<n;r++)i+=String.fromCharCode(t[e+r]);return i},writeASCII(t,e,n){for(let i=0;i<n.length;i++)t[e+i]=n.charCodeAt(i)},readBytes(t,e,n){const i=[];for(let r=0;r<n;r++)i.push(t[e+r]);return i},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,n,i){let r,s="";for(let r=0;r<i;r++)s+=`%${t.pad(e[n+r].toString(16))}`;try{r=decodeURIComponent(s)}catch(r){return t.readASCII(e,n,i)}return r}};function e(e,n,i,r){const o=n*i,a=s(r),c=Math.ceil(n*a/8),l=new Uint8Array(4*o),h=new Uint32Array(l.buffer),{ctype:u}=r,{depth:f}=r,d=t.readUshort;if(6==u){const t=o<<2;if(8==f)for(var p=0;p<t;p+=4)l[p]=e[p],l[p+1]=e[p+1],l[p+2]=e[p+2],l[p+3]=e[p+3];if(16==f)for(p=0;p<t;p++)l[p]=e[p<<1]}else if(2==u){const t=r.tabs.tRNS;if(null==t){if(8==f)for(p=0;p<o;p++){var g=3*p;h[p]=255<<24|e[g+2]<<16|e[g+1]<<8|e[g]}if(16==f)for(p=0;p<o;p++)h[p]=255<<24|e[4+(g=6*p)]<<16|e[g+2]<<8|e[g]}else{var v=t[0];const n=t[1],i=t[2];if(8==f)for(p=0;p<o;p++){var w=p<<2;h[p]=255<<24|e[2+(g=3*p)]<<16|e[g+1]<<8|e[g],e[g]==v&&e[g+1]==n&&e[g+2]==i&&(l[w+3]=0)}if(16==f)for(p=0;p<o;p++)w=p<<2,h[p]=255<<24|e[4+(g=6*p)]<<16|e[g+2]<<8|e[g],d(e,g)==v&&d(e,g+2)==n&&d(e,g+4)==i&&(l[w+3]=0)}}else if(3==u){const t=r.tabs.PLTE,s=r.tabs.tRNS,a=s?s.length:0;if(1==f)for(var m=0;m<i;m++){var y=m*c,b=m*n;for(p=0;p<n;p++){var k=3*(A=e[y+(p>>3)]>>7-(7&p)&1);l[w=b+p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255}}if(2==f)for(m=0;m<i;m++)for(y=m*c,b=m*n,p=0;p<n;p++)k=3*(A=e[y+(p>>2)]>>6-((3&p)<<1)&3),l[w=b+p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255;if(4==f)for(m=0;m<i;m++)for(y=m*c,b=m*n,p=0;p<n;p++)k=3*(A=e[y+(p>>1)]>>4-((1&p)<<2)&15),l[w=b+p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255;if(8==f)for(p=0;p<o;p++){var A;k=3*(A=e[p]),l[w=p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255}}else if(4==u){if(8==f)for(p=0;p<o;p++){var x=e[S=p<<1];l[w=p<<2]=x,l[w+1]=x,l[w+2]=x,l[w+3]=e[S+1]}if(16==f)for(p=0;p<o;p++){var S;x=e[S=p<<2],l[w=p<<2]=x,l[w+1]=x,l[w+2]=x,l[w+3]=e[S+2]}}else if(0==u)for(v=r.tabs.tRNS?r.tabs.tRNS:-1,m=0;m<i;m++){const t=m*c,i=m*n;if(1==f)for(var M=0;M<n;M++){var z=(x=255*(e[t+(M>>>3)]>>>7-(7&M)&1))==255*v?0:255;h[i+M]=z<<24|x<<16|x<<8|x}else if(2==f)for(M=0;M<n;M++)z=(x=85*(e[t+(M>>>2)]>>>6-((3&M)<<1)&3))==85*v?0:255,h[i+M]=z<<24|x<<16|x<<8|x;else if(4==f)for(M=0;M<n;M++)z=(x=17*(e[t+(M>>>1)]>>>4-((1&M)<<2)&15))==17*v?0:255,h[i+M]=z<<24|x<<16|x<<8|x;else if(8==f)for(M=0;M<n;M++)z=(x=e[t+M])==v?0:255,h[i+M]=z<<24|x<<16|x<<8|x;else if(16==f)for(M=0;M<n;M++)x=e[t+(M<<1)],z=d(e,t+(M<<1))==v?0:255,h[i+M]=z<<24|x<<16|x<<8|x}return l}function n(t,e,n,a){const c=s(t),l=Math.ceil(n*c/8),h=new Uint8Array((l+1+t.interlace)*a);return e=t.tabs.CgBI?r(e,h):i(e,h),0==t.interlace?e=o(e,t,0,n,a):1==t.interlace&&(e=function(t,e){const n=e.width,i=e.height,r=s(e),a=r>>3,c=Math.ceil(n*r/8),l=new Uint8Array(i*c);let h=0;const u=[0,0,4,0,2,0,1],f=[0,4,0,2,0,1,0],d=[8,8,8,4,4,2,2],p=[8,8,4,4,2,2,1];let g=0;for(;g<7;){const s=d[g],w=p[g];let m=0,y=0,b=u[g];for(;b<i;)b+=s,y++;let k=f[g];for(;k<n;)k+=w,m++;const A=Math.ceil(m*r/8);o(t,e,h,m,y);let x=0,S=u[g];for(;S<i;){let e=f[g],i=h+x*A<<3;for(;e<n;){var v;if(1==r&&(v=(v=t[i>>3])>>7-(7&i)&1,l[S*c+(e>>3)]|=v<<7-(7&e)),2==r&&(v=(v=t[i>>3])>>6-(7&i)&3,l[S*c+(e>>2)]|=v<<6-((3&e)<<1)),4==r&&(v=(v=t[i>>3])>>4-(7&i)&15,l[S*c+(e>>1)]|=v<<4-((1&e)<<2)),r>=8){const n=S*c+e*a;for(let e=0;e<a;e++)l[n+e]=t[(i>>3)+e]}i+=r,e+=w}x++,S+=s}m*y!=0&&(h+=y*(1+A)),g+=1}return l}(e,t)),e}function i(t,e){return r(new Uint8Array(t.buffer,2,t.length-6),e)}var r=function(){const t={H:{}};return t.H.N=function(e,n){const i=Uint8Array;let r,s,o=0,a=0,c=0,l=0,h=0,u=0,f=0,d=0,p=0;if(3==e[0]&&0==e[1])return n||new i(0);const g=t.H,v=g.b,w=g.e,m=g.R,y=g.n,b=g.A,k=g.Z,A=g.m,x=null==n;for(x&&(n=new i(e.length>>>2<<5));0==o;)if(o=v(e,p,1),a=v(e,p+1,2),p+=3,0!=a){if(x&&(n=t.H.W(n,d+(1<<17))),1==a&&(r=A.J,s=A.h,u=511,f=31),2==a){c=w(e,p,5)+257,l=w(e,p+5,5)+1,h=w(e,p+10,4)+4,p+=14;let t=1;for(var S=0;S<38;S+=2)A.Q[S]=0,A.Q[S+1]=0;for(S=0;S<h;S++){const n=w(e,p+3*S,3);A.Q[1+(A.X[S]<<1)]=n,n>t&&(t=n)}p+=3*h,y(A.Q,t),b(A.Q,t,A.u),r=A.w,s=A.d,p=m(A.u,(1<<t)-1,c+l,e,p,A.v);const n=g.V(A.v,0,c,A.C);u=(1<<n)-1;const i=g.V(A.v,c,l,A.D);f=(1<<i)-1,y(A.C,n),b(A.C,n,r),y(A.D,i),b(A.D,i,s)}for(;;){const t=r[k(e,p)&u];p+=15&t;const i=t>>>4;if(i>>>8==0)n[d++]=i;else{if(256==i)break;{let t=d+i-254;if(i>264){const n=A.q[i-257];t=d+(n>>>3)+w(e,p,7&n),p+=7&n}const r=s[k(e,p)&f];p+=15&r;const o=A.c[r>>>4],a=(o>>>4)+v(e,p,15&o);for(p+=15&o;d<t;)n[d]=n[d++-a],n[d]=n[d++-a],n[d]=n[d++-a],n[d]=n[d++-a];d=t}}}}else{7&p&&(p+=8-(7&p));const r=4+(p>>>3),s=e[r-4]|e[r-3]<<8;x&&(n=t.H.W(n,d+s)),n.set(new i(e.buffer,e.byteOffset+r,s),d),p=r+s<<3,d+=s}return n.length==d?n:n.slice(0,d)},t.H.W=function(t,e){const n=t.length;if(e<=n)return t;const i=new Uint8Array(n<<1);return i.set(t,0),i},t.H.R=function(e,n,i,r,s,o){const a=t.H.e,c=t.H.Z;let l=0;for(;l<i;){const t=e[c(r,s)&n];s+=15&t;const i=t>>>4;if(i<=15)o[l]=i,l++;else{let t=0,e=0;16==i?(e=3+a(r,s,2),s+=2,t=o[l-1]):17==i?(e=3+a(r,s,3),s+=3):18==i&&(e=11+a(r,s,7),s+=7);const n=l+e;for(;l<n;)o[l]=t,l++}}return s},t.H.V=function(t,e,n,i){let r=0,s=0;const o=i.length>>>1;for(;s<n;){const n=t[s+e];i[s<<1]=0,i[1+(s<<1)]=n,n>r&&(r=n),s++}for(;s<o;)i[s<<1]=0,i[1+(s<<1)]=0,s++;return r},t.H.n=function(e,n){const i=t.H.m,r=e.length;let s,o,a,c;const l=i.j;for(var h=0;h<=n;h++)l[h]=0;for(h=1;h<r;h+=2)l[e[h]]++;const u=i.K;for(s=0,l[0]=0,o=1;o<=n;o++)s=s+l[o-1]<<1,u[o]=s;for(a=0;a<r;a+=2)c=e[a+1],0!=c&&(e[a]=u[c],u[c]++)},t.H.A=function(e,n,i){const r=e.length,s=t.H.m.r;for(let t=0;t<r;t+=2)if(0!=e[t+1]){const r=e[t+1],o=t>>1<<4|r,a=n-r;let c=e[t]<<a;const l=c+(1<<a);for(;c!=l;)i[s[c]>>>15-n]=o,c++}},t.H.l=function(e,n){const i=t.H.m.r,r=15-n;for(let t=0;t<e.length;t+=2)e[t]=i[e[t]<<n-e[t+1]]>>>r},t.H.M=function(t,e,n){const i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8},t.H.I=function(t,e,n){const i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8,t[i+2]|=n>>>16},t.H.e=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<n)-1},t.H.b=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<n)-1},t.H.Z=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},t.H.i=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},t.H.m=function(){const t=Uint16Array,e=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new e(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new e(286),Y:new e(30),a:new e(19),t:new e(15e3),k:new t(65536),g:new t(32768)}}(),function(){const e=t.H.m;for(var n=0;n<32768;n++){let t=n;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,e.r[n]=(t>>>16|t<<16)>>>17}function i(t,e,n){for(;0!=e--;)t.push(0,n)}for(n=0;n<32;n++)e.q[n]=e.S[n]<<3|e.T[n],e.c[n]=e.p[n]<<4|e.z[n];i(e._,144,8),i(e._,112,9),i(e._,24,7),i(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),i(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),i(e.Q,19,0),i(e.C,286,0),i(e.D,30,0),i(e.v,320,0)}(),t.H.N}();function s(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,e,n,i,r){let o=s(e);const c=Math.ceil(i*o/8);let l,h;o=Math.ceil(o/8);let u=t[n],f=0;if(u>1&&(t[n]=[0,0,1][u-2]),3==u)for(f=o;f<c;f++)t[f+1]=t[f+1]+(t[f+1-o]>>>1)&255;for(let e=0;e<r;e++)if(l=n+e*c,h=l+e+1,u=t[h-1],f=0,0==u)for(;f<c;f++)t[l+f]=t[h+f];else if(1==u){for(;f<o;f++)t[l+f]=t[h+f];for(;f<c;f++)t[l+f]=t[h+f]+t[l+f-o]}else if(2==u)for(;f<c;f++)t[l+f]=t[h+f]+t[l+f-c];else if(3==u){for(;f<o;f++)t[l+f]=t[h+f]+(t[l+f-c]>>>1);for(;f<c;f++)t[l+f]=t[h+f]+(t[l+f-c]+t[l+f-o]>>>1)}else{for(;f<o;f++)t[l+f]=t[h+f]+a(0,t[l+f-c],0);for(;f<c;f++)t[l+f]=t[h+f]+a(t[l+f-o],t[l+f-c],t[l+f-o-c])}return t}function a(t,e,n){const i=t+e-n,r=i-t,s=i-e,o=i-n;return r*r<=s*s&&r*r<=o*o?t:s*s<=o*o?e:n}function c(e,n,i){i.width=t.readUint(e,n),i.height=t.readUint(e,n+=4),i.depth=e[n+=4],n++,i.ctype=e[n],n++,i.compress=e[n],n++,i.filter=e[n],n++,i.interlace=e[n],n++}function l(t,e,n,i,r,s,o,a,c){const l=Math.min(e,r),h=Math.min(n,s);let u=0,f=0;for(let n=0;n<h;n++)for(let s=0;s<l;s++)if(o>=0&&a>=0?(u=n*e+s<<2,f=(a+n)*r+o+s<<2):(u=(-a+n)*e-o+s<<2,f=n*r+s<<2),0==c)i[f]=t[u],i[f+1]=t[u+1],i[f+2]=t[u+2],i[f+3]=t[u+3];else if(1==c){var d=t[u+3]*(1/255),p=t[u]*d,g=t[u+1]*d,v=t[u+2]*d,w=i[f+3]*(1/255),m=i[f]*w,y=i[f+1]*w,b=i[f+2]*w;const e=1-d,n=d+w*e,r=0==n?0:1/n;i[f+3]=255*n,i[f+0]=(p+m*e)*r,i[f+1]=(g+y*e)*r,i[f+2]=(v+b*e)*r}else if(2==c)p=t[u],g=t[u+1],v=t[u+2],m=i[f],y=i[f+1],b=i[f+2],(d=t[u+3])==(w=i[f+3])&&p==m&&g==y&&v==b?(i[f]=0,i[f+1]=0,i[f+2]=0,i[f+3]=0):(i[f]=p,i[f+1]=g,i[f+2]=v,i[f+3]=d);else if(3==c){if(p=t[u],g=t[u+1],v=t[u+2],m=i[f],y=i[f+1],b=i[f+2],(d=t[u+3])==(w=i[f+3])&&p==m&&g==y&&v==b)continue;if(d<220&&w>20)return!1}return!0}return{decode:function(e){const s=new Uint8Array(e);let o=8;const a=t,l=a.readUshort,h=a.readUint,u={tabs:{},frames:[]},f=new Uint8Array(s.length);let d,p=0,g=0;const v=[137,80,78,71,13,10,26,10];for(var w=0;w<8;w++)if(s[w]!=v[w])throw"The input is not a PNG file!";for(;o<s.length;){const t=a.readUint(s,o);o+=4;const e=a.readASCII(s,o,4);if(o+=4,"IHDR"==e)c(s,o,u);else if("iCCP"==e){for(var m=o;0!=s[m];)m++;a.readASCII(s,o,m-o);const n=s.slice(m+2,o+t);let c=null;try{c=i(n)}catch(t){c=r(n)}u.tabs[e]=c}else if("CgBI"==e)u.tabs[e]=s.slice(o,o+4);else if("IDAT"==e){for(w=0;w<t;w++)f[p+w]=s[o+w];p+=t}else if("acTL"==e)u.tabs[e]={num_frames:h(s,o),num_plays:h(s,o+4)},d=new Uint8Array(s.length);else if("fcTL"==e){0!=g&&((S=u.frames[u.frames.length-1]).data=n(u,d.slice(0,g),S.rect.width,S.rect.height),g=0);const t={x:h(s,o+12),y:h(s,o+16),width:h(s,o+4),height:h(s,o+8)};let e=l(s,o+22);e=l(s,o+20)/(0==e?100:e);const i={rect:t,delay:Math.round(1e3*e),dispose:s[o+24],blend:s[o+25]};u.frames.push(i)}else if("fdAT"==e){for(w=0;w<t-4;w++)d[g+w]=s[o+w+4];g+=t-4}else if("pHYs"==e)u.tabs[e]=[a.readUint(s,o),a.readUint(s,o+4),s[o+8]];else if("cHRM"==e)for(u.tabs[e]=[],w=0;w<8;w++)u.tabs[e].push(a.readUint(s,o+4*w));else if("tEXt"==e||"zTXt"==e){null==u.tabs[e]&&(u.tabs[e]={});var y=a.nextZero(s,o),b=a.readASCII(s,o,y-o),k=o+t-y-1;if("tEXt"==e)x=a.readASCII(s,y+1,k);else{var A=i(s.slice(y+2,y+2+k));x=a.readUTF8(A,0,A.length)}u.tabs[e][b]=x}else if("iTXt"==e){null==u.tabs[e]&&(u.tabs[e]={}),y=0,y=a.nextZero(s,m=o),b=a.readASCII(s,m,y-m);const n=s[m=y+1];var x;y=a.nextZero(s,m+=2),a.readASCII(s,m,y-m),y=a.nextZero(s,m=y+1),a.readUTF8(s,m,y-m),k=t-((m=y+1)-o),0==n?x=a.readUTF8(s,m,k):(A=i(s.slice(m,m+k)),x=a.readUTF8(A,0,A.length)),u.tabs[e][b]=x}else if("PLTE"==e)u.tabs[e]=a.readBytes(s,o,t);else if("hIST"==e){const t=u.tabs.PLTE.length/3;for(u.tabs[e]=[],w=0;w<t;w++)u.tabs[e].push(l(s,o+2*w))}else if("tRNS"==e)3==u.ctype?u.tabs[e]=a.readBytes(s,o,t):0==u.ctype?u.tabs[e]=l(s,o):2==u.ctype&&(u.tabs[e]=[l(s,o),l(s,o+2),l(s,o+4)]);else if("gAMA"==e)u.tabs[e]=a.readUint(s,o)/1e5;else if("sRGB"==e)u.tabs[e]=s[o];else if("bKGD"==e)0==u.ctype||4==u.ctype?u.tabs[e]=[l(s,o)]:2==u.ctype||6==u.ctype?u.tabs[e]=[l(s,o),l(s,o+2),l(s,o+4)]:3==u.ctype&&(u.tabs[e]=s[o]);else if("IEND"==e)break;o+=t,a.readUint(s,o),o+=4}var S;return 0!=g&&((S=u.frames[u.frames.length-1]).data=n(u,d.slice(0,g),S.rect.width,S.rect.height)),u.data=n(u,f,u.width,u.height),delete u.compress,delete u.interlace,delete u.filter,u},toRGBA8:function(t){const n=t.width,i=t.height;if(null==t.tabs.acTL)return[e(t.data,n,i,t).buffer];const r=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const s=n*i*4,o=new Uint8Array(s),a=new Uint8Array(s),c=new Uint8Array(s);for(let u=0;u<t.frames.length;u++){const f=t.frames[u],d=f.rect.x,p=f.rect.y,g=f.rect.width,v=f.rect.height,w=e(f.data,g,v,t);if(0!=u)for(var h=0;h<s;h++)c[h]=o[h];if(0==f.blend?l(w,g,v,o,n,i,d,p,0):1==f.blend&&l(w,g,v,o,n,i,d,p,1),r.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)l(a,g,v,o,n,i,d,p,0);else if(2==f.dispose)for(h=0;h<s;h++)o[h]=c[h]}return r},_paeth:a,_copyTile:l,_bin:t}}();!function(){const{_copyTile:t}=ot,{_bin:e}=ot,n=ot._paeth;var i={table:function(){const t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=3988292384^n>>>1:n>>>=1;t[e]=n}return t}(),update(t,e,n,r){for(let s=0;s<r;s++)t=i.table[255&(t^e[n+s])]^t>>>8;return t},crc:(t,e,n)=>4294967295^i.update(4294967295,t,e,n)};function r(t,e,n,i){e[n]+=t[0]*i>>4,e[n+1]+=t[1]*i>>4,e[n+2]+=t[2]*i>>4,e[n+3]+=t[3]*i>>4}function s(t){return Math.max(0,Math.min(255,t))}function o(t,e){const n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2],s=t[3]-e[3];return n*n+i*i+r*r+s*s}function a(t,e,n,i,a,c,l){null==l&&(l=1);const h=i.length,u=[];for(var f=0;f<h;f++){const t=i[f];u.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<h;f++){let t=4294967295;for(var d=0,p=0;p<h;p++){var g=o(u[f],u[p]);p!=f&&g<t&&(t=g,d=p)}}const v=new Uint32Array(a.buffer),w=new Int16Array(e*n*4),m=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<m.length;f++)m[f]=255*((m[f]+.5)/16-.5);for(let a=0;a<n;a++)for(let b=0;b<e;b++){var y;f=4*(a*e+b),y=2!=l?[s(t[f]+w[f]),s(t[f+1]+w[f+1]),s(t[f+2]+w[f+2]),s(t[f+3]+w[f+3])]:[s(t[f]+(g=m[4*(3&a)+(3&b)])),s(t[f+1]+g),s(t[f+2]+g),s(t[f+3]+g)],d=0;let k=16777215;for(p=0;p<h;p++){const t=o(y,u[p]);t<k&&(k=t,d=p)}const A=u[d],x=[y[0]-A[0],y[1]-A[1],y[2]-A[2],y[3]-A[3]];1==l&&(b!=e-1&&r(x,w,f+4,7),a!=n-1&&(0!=b&&r(x,w,f+4*e-4,3),r(x,w,f+4*e,5),b!=e-1&&r(x,w,f+4*e+4,1))),c[f>>2]=d,v[f>>2]=i[d]}}function c(t,n,r,s,o){null==o&&(o={});const{crc:a}=i,c=e.writeUint,l=e.writeUshort,h=e.writeASCII;let u=8;const f=t.frames.length>1;let d,p=!1,g=33+(f?20:0);if(null!=o.sRGB&&(g+=13),null!=o.pHYs&&(g+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),g+=21+d.length+4),3==t.ctype){for(var v=t.plte.length,w=0;w<v;w++)t.plte[w]>>>24!=255&&(p=!0);g+=8+3*v+4+(p?8+1*v+4:0)}for(var m=0;m<t.frames.length;m++)f&&(g+=38),g+=(A=t.frames[m]).cimg.length+12,0!=m&&(g+=4);g+=12;const y=new Uint8Array(g),b=[137,80,78,71,13,10,26,10];for(w=0;w<8;w++)y[w]=b[w];if(c(y,u,13),u+=4,h(y,u,"IHDR"),u+=4,c(y,u,n),u+=4,c(y,u,r),u+=4,y[u]=t.depth,u++,y[u]=t.ctype,u++,y[u]=0,u++,y[u]=0,u++,y[u]=0,u++,c(y,u,a(y,u-17,17)),u+=4,null!=o.sRGB&&(c(y,u,1),u+=4,h(y,u,"sRGB"),u+=4,y[u]=o.sRGB,u++,c(y,u,a(y,u-5,5)),u+=4),null!=o.iCCP){const t=13+d.length;c(y,u,t),u+=4,h(y,u,"iCCP"),u+=4,h(y,u,"ICC profile"),u+=11,u+=2,y.set(d,u),u+=d.length,c(y,u,a(y,u-(t+4),t+4)),u+=4}if(null!=o.pHYs&&(c(y,u,9),u+=4,h(y,u,"pHYs"),u+=4,c(y,u,o.pHYs[0]),u+=4,c(y,u,o.pHYs[1]),u+=4,y[u]=o.pHYs[2],u++,c(y,u,a(y,u-13,13)),u+=4),f&&(c(y,u,8),u+=4,h(y,u,"acTL"),u+=4,c(y,u,t.frames.length),u+=4,c(y,u,null!=o.loop?o.loop:0),u+=4,c(y,u,a(y,u-12,12)),u+=4),3==t.ctype){for(c(y,u,3*(v=t.plte.length)),u+=4,h(y,u,"PLTE"),u+=4,w=0;w<v;w++){const e=3*w,n=t.plte[w],i=n>>>8&255,r=n>>>16&255;y[u+e+0]=255&n,y[u+e+1]=i,y[u+e+2]=r}if(u+=3*v,c(y,u,a(y,u-3*v-4,3*v+4)),u+=4,p){for(c(y,u,v),u+=4,h(y,u,"tRNS"),u+=4,w=0;w<v;w++)y[u+w]=t.plte[w]>>>24&255;u+=v,c(y,u,a(y,u-v-4,v+4)),u+=4}}let k=0;for(m=0;m<t.frames.length;m++){var A=t.frames[m];f&&(c(y,u,26),u+=4,h(y,u,"fcTL"),u+=4,c(y,u,k++),u+=4,c(y,u,A.rect.width),u+=4,c(y,u,A.rect.height),u+=4,c(y,u,A.rect.x),u+=4,c(y,u,A.rect.y),u+=4,l(y,u,s[m]),u+=2,l(y,u,1e3),u+=2,y[u]=A.dispose,u++,y[u]=A.blend,u++,c(y,u,a(y,u-30,30)),u+=4);const e=A.cimg;c(y,u,(v=e.length)+(0==m?0:4)),u+=4;const n=u;h(y,u,0==m?"IDAT":"fdAT"),u+=4,0!=m&&(c(y,u,k++),u+=4),y.set(e,u),u+=v,c(y,u,a(y,n,u-n)),u+=4}return c(y,u,0),u+=4,h(y,u,"IEND"),u+=4,c(y,u,a(y,u-4,4)),u+=4,y.buffer}function l(t,e,n){for(let i=0;i<t.frames.length;i++){const r=t.frames[i],s=r.rect.height,o=new Uint8Array(s*r.bpl+s);r.cimg=d(r.img,s,r.bpp,r.bpl,o,e,n)}}function h(e,n,i,r,s){const o=s[0],c=s[1],l=s[2],h=s[3],d=s[4],p=s[5];let v=6,w=8,m=255;for(var y=0;y<e.length;y++){const t=new Uint8Array(e[y]);for(var b=t.length,k=0;k<b;k+=4)m&=t[k+3]}const A=255!=m,x=function(e,n,i,r,s,o){const a=[];for(var c=0;c<e.length;c++){const u=new Uint8Array(e[c]),d=new Uint32Array(u.buffer);var l;let g=0,v=0,w=n,m=i,y=r?1:0;if(0!=c){const b=o||r||1==c||0!=a[c-2].dispose?1:2;let k=0,A=1e9;for(let t=0;t<b;t++){var h=new Uint8Array(e[c-1-t]);const r=new Uint32Array(e[c-1-t]);let o=n,a=i,l=-1,u=-1;for(let t=0;t<i;t++)for(let e=0;e<n;e++)d[p=t*n+e]!=r[p]&&(e<o&&(o=e),e>l&&(l=e),t<a&&(a=t),t>u&&(u=t));-1==l&&(o=a=l=u=0),s&&(!(1&~o)&&o--,!(1&~a)&&a--);const f=(l-o+1)*(u-a+1);f<A&&(A=f,k=t,g=o,v=a,w=l-o+1,m=u-a+1)}h=new Uint8Array(e[c-1-k]),1==k&&(a[c-1].dispose=2),l=new Uint8Array(w*m*4),t(h,n,i,l,w,m,-g,-v,0),y=t(u,n,i,l,w,m,-g,-v,3)?1:0,1==y?f(u,n,i,l,{x:g,y:v,width:w,height:m}):t(u,n,i,l,w,m,-g,-v,0)}else l=u.slice(0);a.push({rect:{x:g,y:v,width:w,height:m},img:l,blend:y,dispose:0})}if(r)for(c=0;c<a.length;c++){if(1==(g=a[c]).blend)continue;const t=g.rect,r=a[c-1].rect,o=Math.min(t.x,r.x),l=Math.min(t.y,r.y),h={x:o,y:l,width:Math.max(t.x+t.width,r.x+r.width)-o,height:Math.max(t.y+t.height,r.y+r.height)-l};a[c-1].dispose=1,c-1!=0&&u(e,n,i,a,c-1,h,s),u(e,n,i,a,c,h,s)}let d=0;if(1!=e.length)for(var p=0;p<a.length;p++){var g;d+=(g=a[p]).rect.width*g.rect.height}return a}(e,n,i,o,c,l),S={},M=[],z=[];if(0!=r){const t=[];for(k=0;k<x.length;k++)t.push(x[k].img.buffer);const e=function(t){let e=0;for(var n=0;n<t.length;n++)e+=t[n].byteLength;const i=new Uint8Array(e);let r=0;for(n=0;n<t.length;n++){const e=new Uint8Array(t[n]),s=e.length;for(let t=0;t<s;t+=4){let n=e[t],s=e[t+1],o=e[t+2];const a=e[t+3];0==a&&(n=s=o=0),i[r+t]=n,i[r+t+1]=s,i[r+t+2]=o,i[r+t+3]=a}r+=s}return i.buffer}(t),n=g(e,r);for(k=0;k<n.plte.length;k++)M.push(n.plte[k].est.rgba);let i=0;for(k=0;k<x.length;k++){const t=(C=x[k]).img.length;var $=new Uint8Array(n.inds.buffer,i>>2,t>>2);z.push($);const e=new Uint8Array(n.abuf,i,t);p&&a(C.img,C.rect.width,C.rect.height,M,e,$),C.img.set(e),i+=t}}else for(y=0;y<x.length;y++){var C=x[y];const t=new Uint32Array(C.img.buffer);var T=C.rect.width;for(b=t.length,$=new Uint8Array(b),z.push($),k=0;k<b;k++){const e=t[k];if(0!=k&&e==t[k-1])$[k]=$[k-1];else if(k>T&&e==t[k-T])$[k]=$[k-T];else{let t=S[e];if(null==t&&(S[e]=t=M.length,M.push(e),M.length>=300))break;$[k]=t}}}const I=M.length;for(I<=256&&0==d&&(w=I<=2?1:I<=4?2:I<=16?4:8,w=Math.max(w,h)),y=0;y<x.length;y++){const t=(C=x[y]).rect.height;let e=C.img,n=4*(T=C.rect.width),i=4;if(I<=256&&0==d){n=Math.ceil(w*T/8);var j=new Uint8Array(n*t);const r=z[y];for(let e=0;e<t;e++){k=e*n;const t=e*T;if(8==w)for(var E=0;E<T;E++)j[k+E]=r[t+E];else if(4==w)for(E=0;E<T;E++)j[k+(E>>1)]|=r[t+E]<<4-4*(1&E);else if(2==w)for(E=0;E<T;E++)j[k+(E>>2)]|=r[t+E]<<6-2*(3&E);else if(1==w)for(E=0;E<T;E++)j[k+(E>>3)]|=r[t+E]<<7-1*(7&E)}e=j,v=3,i=1}else if(0==A&&1==x.length){j=new Uint8Array(T*t*3);const r=T*t;for(k=0;k<r;k++){const t=3*k,n=4*k;j[t]=e[n],j[t+1]=e[n+1],j[t+2]=e[n+2]}e=j,v=2,i=3,n=3*T}C.img=e,C.bpl=n,C.bpp=i}return{ctype:v,depth:w,plte:M,frames:x}}function u(e,n,i,r,s,o,a){const c=Uint8Array,l=Uint32Array,h=new c(e[s-1]),u=new l(e[s-1]),d=s+1<e.length?new c(e[s+1]):null,p=new c(e[s]),g=new l(p.buffer);let v=n,w=i,m=-1,y=-1;for(let t=0;t<o.height;t++)for(let e=0;e<o.width;e++){const i=o.x+e,a=o.y+t,c=a*n+i,l=g[c];0==l||0==r[s-1].dispose&&u[c]==l&&(null==d||0!=d[4*c+3])||(i<v&&(v=i),i>m&&(m=i),a<w&&(w=a),a>y&&(y=a))}-1==m&&(v=w=m=y=0),a&&(!(1&~v)&&v--,!(1&~w)&&w--);const b=r[s];b.rect=o={x:v,y:w,width:m-v+1,height:y-w+1},b.blend=1,b.img=new Uint8Array(o.width*o.height*4),0==r[s-1].dispose?(t(h,n,i,b.img,o.width,o.height,-o.x,-o.y,0),f(p,n,i,b.img,o)):t(p,n,i,b.img,o.width,o.height,-o.x,-o.y,0)}function f(e,n,i,r,s){t(e,n,i,r,s.width,s.height,-s.x,-s.y,2)}function d(t,e,n,i,r,s,o){const a=[];let c,l=[0,1,2,3,4];-1!=s?l=[s]:(e*i>5e5||1==n)&&(l=[0]),o&&(c={level:0});const h=st;for(var u=0;u<l.length;u++){for(let s=0;s<e;s++)p(r,t,s,i,n,l[u]);a.push(h.deflate(r,c))}let f,d=1e9;for(u=0;u<a.length;u++)a[u].length<d&&(f=u,d=a[u].length);return a[f]}function p(t,e,i,r,s,o){const a=i*r;let c=a+i;if(t[c]=o,c++,0==o)if(r<500)for(var l=0;l<r;l++)t[c+l]=e[a+l];else t.set(new Uint8Array(e.buffer,a,r),c);else if(1==o){for(l=0;l<s;l++)t[c+l]=e[a+l];for(l=s;l<r;l++)t[c+l]=e[a+l]-e[a+l-s]+256&255}else if(0==i){for(l=0;l<s;l++)t[c+l]=e[a+l];if(2==o)for(l=s;l<r;l++)t[c+l]=e[a+l];if(3==o)for(l=s;l<r;l++)t[c+l]=e[a+l]-(e[a+l-s]>>1)+256&255;if(4==o)for(l=s;l<r;l++)t[c+l]=e[a+l]-n(e[a+l-s],0,0)+256&255}else{if(2==o)for(l=0;l<r;l++)t[c+l]=e[a+l]+256-e[a+l-r]&255;if(3==o){for(l=0;l<s;l++)t[c+l]=e[a+l]+256-(e[a+l-r]>>1)&255;for(l=s;l<r;l++)t[c+l]=e[a+l]+256-(e[a+l-r]+e[a+l-s]>>1)&255}if(4==o){for(l=0;l<s;l++)t[c+l]=e[a+l]+256-n(0,e[a+l-r],0)&255;for(l=s;l<r;l++)t[c+l]=e[a+l]+256-n(e[a+l-s],e[a+l-r],e[a+l-s-r])&255}}}function g(t,e){const n=new Uint8Array(t),i=n.slice(0),r=new Uint32Array(i.buffer),s=v(i,e),o=s[0],a=s[1],c=n.length,l=new Uint8Array(c>>2);let h;if(n.length<2e7)for(var u=0;u<c;u+=4)h=w(o,f=n[u]*(1/255),d=n[u+1]*(1/255),p=n[u+2]*(1/255),g=n[u+3]*(1/255)),l[u>>2]=h.ind,r[u>>2]=h.est.rgba;else for(u=0;u<c;u+=4){var f=n[u]*(1/255),d=n[u+1]*(1/255),p=n[u+2]*(1/255),g=n[u+3]*(1/255);for(h=o;h.left;)h=m(h.est,f,d,p,g)<=0?h.left:h.right;l[u>>2]=h.ind,r[u>>2]=h.est.rgba}return{abuf:i.buffer,inds:l,plte:a}}function v(t,e,n){null==n&&(n=1e-4);const i=new Uint32Array(t.buffer),r={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};r.bst=k(t,r.i0,r.i1),r.est=A(r.bst);const s=[r];for(;s.length<e;){let e=0,r=0;for(var o=0;o<s.length;o++)s[o].est.L>e&&(e=s[o].est.L,r=o);if(e<n)break;const a=s[r],c=y(t,i,a.i0,a.i1,a.est.e,a.est.eMq255);if(a.i0>=c||a.i1<=c){a.est.L=0;continue}const l={i0:a.i0,i1:c,bst:null,est:null,tdst:0,left:null,right:null};l.bst=k(t,l.i0,l.i1),l.est=A(l.bst);const h={i0:c,i1:a.i1,bst:null,est:null,tdst:0,left:null,right:null};for(h.bst={R:[],m:[],N:a.bst.N-l.bst.N},o=0;o<16;o++)h.bst.R[o]=a.bst.R[o]-l.bst.R[o];for(o=0;o<4;o++)h.bst.m[o]=a.bst.m[o]-l.bst.m[o];h.est=A(h.bst),a.left=l,a.right=h,s[r]=l,s.push(h)}for(s.sort(((t,e)=>e.bst.N-t.bst.N)),o=0;o<s.length;o++)s[o].ind=o;return[r,s]}function w(t,e,n,i,r){if(null==t.left)return t.tdst=function(t,e,n,i,r){const s=e-t[0],o=n-t[1],a=i-t[2],c=r-t[3];return s*s+o*o+a*a+c*c}(t.est.q,e,n,i,r),t;const s=m(t.est,e,n,i,r);let o=t.left,a=t.right;s>0&&(o=t.right,a=t.left);const c=w(o,e,n,i,r);if(c.tdst<=s*s)return c;const l=w(a,e,n,i,r);return l.tdst<c.tdst?l:c}function m(t,e,n,i,r){const{e:s}=t;return s[0]*e+s[1]*n+s[2]*i+s[3]*r-t.eMq}function y(t,e,n,i,r,s){for(i-=4;n<i;){for(;b(t,n,r)<=s;)n+=4;for(;b(t,i,r)>s;)i-=4;if(n>=i)break;const o=e[n>>2];e[n>>2]=e[i>>2],e[i>>2]=o,n+=4,i-=4}for(;b(t,n,r)>s;)n-=4;return n+4}function b(t,e,n){return t[e]*n[0]+t[e+1]*n[1]+t[e+2]*n[2]+t[e+3]*n[3]}function k(t,e,n){const i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=[0,0,0,0],s=n-e>>2;for(let s=e;s<n;s+=4){const e=t[s]*(1/255),n=t[s+1]*(1/255),o=t[s+2]*(1/255),a=t[s+3]*(1/255);r[0]+=e,r[1]+=n,r[2]+=o,r[3]+=a,i[0]+=e*e,i[1]+=e*n,i[2]+=e*o,i[3]+=e*a,i[5]+=n*n,i[6]+=n*o,i[7]+=n*a,i[10]+=o*o,i[11]+=o*a,i[15]+=a*a}return i[4]=i[1],i[8]=i[2],i[9]=i[6],i[12]=i[3],i[13]=i[7],i[14]=i[11],{R:i,m:r,N:s}}function A(t){const{R:e}=t,{m:n}=t,{N:i}=t,r=n[0],s=n[1],o=n[2],a=n[3],c=0==i?0:1/i,l=[e[0]-r*r*c,e[1]-r*s*c,e[2]-r*o*c,e[3]-r*a*c,e[4]-s*r*c,e[5]-s*s*c,e[6]-s*o*c,e[7]-s*a*c,e[8]-o*r*c,e[9]-o*s*c,e[10]-o*o*c,e[11]-o*a*c,e[12]-a*r*c,e[13]-a*s*c,e[14]-a*o*c,e[15]-a*a*c],h=l,u=x;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,p=0;if(0!=i)for(let t=0;t<16&&(f=u.multVec(h,f),p=Math.sqrt(u.dot(f,f)),f=u.sml(1/p,f),!(0!=t&&Math.abs(p-d)<1e-9));t++)d=p;const g=[r*c,s*c,o*c,a*c];return{Cov:l,q:g,e:f,L:d,eMq255:u.dot(u.sml(255,g),f),eMq:u.dot(f,g),rgba:(Math.round(255*g[3])<<24|Math.round(255*g[2])<<16|Math.round(255*g[1])<<8|Math.round(255*g[0]))>>>0}}var x={multVec:(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],t[4]*e[0]+t[5]*e[1]+t[6]*e[2]+t[7]*e[3],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]+t[11]*e[3],t[12]*e[0]+t[13]*e[1]+t[14]*e[2]+t[15]*e[3]],dot:(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],sml:(t,e)=>[t*e[0],t*e[1],t*e[2],t*e[3]]};ot.encode=function(t,e,n,i,r,s,o){null==i&&(i=0),null==o&&(o=!1);const a=h(t,e,n,i,[!1,!1,!1,0,o,!1]);return l(a,-1),c(a,e,n,r,s)},ot.encodeLL=function(t,e,n,i,r,s,o,a){const h={ctype:0+(1==i?0:2)+(0==r?0:4),depth:s,frames:[]},u=(i+r)*s,f=u*e;for(let i=0;i<t.length;i++)h.frames.push({rect:{x:0,y:0,width:e,height:n},img:new Uint8Array(t[i]),blend:0,dispose:1,bpp:Math.ceil(u/8),bpl:Math.ceil(f/8)});return l(h,0,!0),c(h,e,n,o,a)},ot.encode.compress=h,ot.encode.dither=a,ot.quantize=g,ot.quantize.getKDtree=v,ot.quantize.getNearest=w}();const at={toArrayBuffer(t,e){const n=t.width,i=t.height,r=n<<2,s=t.getContext("2d").getImageData(0,0,n,i),o=new Uint32Array(s.data.buffer),a=(32*n+31)/32<<2,c=a*i,l=122+c,h=new ArrayBuffer(l),u=new DataView(h),f=1<<20;let d,p,g,v,w=f,m=0,y=0,b=0;function k(t){u.setUint16(y,t,!0),y+=2}function A(t){u.setUint32(y,t,!0),y+=4}function x(t){y+=t}k(19778),A(l),x(4),A(122),A(108),A(n),A(-i>>>0),k(1),k(32),A(3),A(c),A(2835),A(2835),x(8),A(16711680),A(65280),A(255),A(4278190080),A(1466527264),function t(){for(;m<i&&w>0;){for(v=122+m*a,d=0;d<r;)w--,p=o[b++],g=p>>>24,u.setUint32(v+d,p<<8|g),d+=4;m++}b<o.length?(w=f,setTimeout(t,at._dly)):e(h)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var ct={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},lt={[ct.CHROME]:16384,[ct.FIREFOX]:11180,[ct.DESKTOP_SAFARI]:16384,[ct.IE]:8192,[ct.IOS]:4096,[ct.ETC]:8192};const ht="undefined"!=typeof window,ut="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,ft=ht&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),dt=(ht||ut)&&(ft&&ft.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),pt=(ht||ut)&&(ft&&ft.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function gt(t,e,n=Date.now()){return new Promise((i=>{const r=t.split(","),s=r[0].match(/:(.*?);/)[1],o=globalThis.atob(r[1]);let a=o.length;const c=new Uint8Array(a);for(;a--;)c[a]=o.charCodeAt(a);const l=new Blob([c],{type:s});l.name=e,l.lastModified=n,i(l)}))}function vt(t){return new Promise(((e,n)=>{const i=new pt;i.onload=()=>e(i.result),i.onerror=t=>n(t),i.readAsDataURL(t)}))}function wt(t){return new Promise(((e,n)=>{const i=new Image;i.onload=()=>e(i),i.onerror=t=>n(t),i.src=t}))}function mt(){if(void 0!==mt.cachedResult)return mt.cachedResult;let t=ct.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=ct.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=ct.IOS:/Safari/i.test(e)?t=ct.DESKTOP_SAFARI:/Firefox/i.test(e)?t=ct.FIREFOX:(/MSIE/i.test(e)||1==!!document.documentMode)&&(t=ct.IE),mt.cachedResult=t}function yt(t,e){const n=mt(),i=lt[n];let r=t,s=e,o=r*s;const a=r>s?s/r:r/s;for(;o>i*i;){const t=(i+r)/2,e=(i+s)/2;t<e?(s=e,r=e*a):(s=t*a,r=t),o=r*s}return{width:r,height:s}}function bt(t,e){let n,i;try{if(n=new OffscreenCanvas(t,e),i=n.getContext("2d"),null===i)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){n=document.createElement("canvas"),i=n.getContext("2d")}return n.width=t,n.height=e,[n,i]}function kt(t,e){const{width:n,height:i}=yt(t.width,t.height),[r,s]=bt(n,i);return e&&/jpe?g/.test(e)&&(s.fillStyle="white",s.fillRect(0,0,r.width,r.height)),s.drawImage(t,0,0,r.width,r.height),r}function At(){return void 0!==At.cachedResult||(At.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),At.cachedResult}function xt(t,e={}){return new Promise((function(n,i){let r,s;var o=function(){try{return s=kt(r,e.fileType||t.type),n([r,s])}catch(t){return i(t)}},a=function(){try{var e=function(t){try{throw t}catch(t){return i(t)}};try{let n;return vt(t).then((function(t){try{return n=t,wt(n).then((function(t){try{return r=t,function(){try{return o()}catch(t){return i(t)}}()}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){e(t)}}catch(t){return i(t)}};try{if(At()||[ct.DESKTOP_SAFARI,ct.MOBILE_SAFARI].includes(mt()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return r=t,o()}catch(t){return a()}}),a)}catch(t){a()}}))}function St(t,e,n,i,r=1){return new Promise((function(s,o){let a;if("image/png"===e){let l,h,u;return l=t.getContext("2d"),({data:h}=l.getImageData(0,0,t.width,t.height)),u=ot.encode([h.buffer],t.width,t.height,4096*r),a=new Blob([u],{type:e}),a.name=n,a.lastModified=i,c.call(this)}{if("image/bmp"===e)return new Promise((e=>at.toBlob(t,e))).then(function(t){try{return a=t,a.name=n,a.lastModified=i,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:r}).then(function(t){try{return a=t,a.name=n,a.lastModified=i,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let p;return p=t.toDataURL(e,r),gt(p,n,i).then(function(t){try{return a=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return f.call(this)}}function f(){return c.call(this)}}function c(){return s(a)}}))}function Mt(t){t.width=0,t.height=0}function zt(){return new Promise((function(t,e){let n,i,r,s;return void 0!==zt.cachedResult?t(zt.cachedResult):gt("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return n=o,xt(n).then((function(o){try{return i=o[1],St(i,n.type,n.name,n.lastModified).then((function(n){try{return r=n,Mt(i),xt(r).then((function(n){try{return s=n[0],t(zt.cachedResult=1===s.width&&2===s.height)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}))}function $t(t){return new Promise(((e,n)=>{const i=new pt;i.onload=t=>{const n=new DataView(t.target.result);if(65496!=n.getUint16(0,!1))return e(-2);const i=n.byteLength;let r=2;for(;r<i;){if(n.getUint16(r+2,!1)<=8)return e(-1);const t=n.getUint16(r,!1);if(r+=2,65505==t){if(1165519206!=n.getUint32(r+=2,!1))return e(-1);const t=18761==n.getUint16(r+=6,!1);r+=n.getUint32(r+4,t);const i=n.getUint16(r,t);r+=2;for(let s=0;s<i;s++)if(274==n.getUint16(r+12*s,t))return e(n.getUint16(r+12*s+8,t))}else{if(65280&~t)break;r+=n.getUint16(r,!1)}}return e(-1)},i.onerror=t=>n(t),i.readAsArrayBuffer(t)}))}function Ct(t,e){const{width:n}=t,{height:i}=t,{maxWidthOrHeight:r}=e;let s,o=t;return isFinite(r)&&(n>r||i>r)&&([o,s]=bt(n,i),n>i?(o.width=r,o.height=i/n*r):(o.width=n/i*r,o.height=r),s.drawImage(t,0,0,o.width,o.height),Mt(t)),o}function Tt(t,e){const{width:n}=t,{height:i}=t,[r,s]=bt(n,i);switch(e>4&&e<9?(r.width=i,r.height=n):(r.width=n,r.height=i),e){case 2:s.transform(-1,0,0,1,n,0);break;case 3:s.transform(-1,0,0,-1,n,i);break;case 4:s.transform(1,0,0,-1,0,i);break;case 5:s.transform(0,1,1,0,0,0);break;case 6:s.transform(0,1,-1,0,i,0);break;case 7:s.transform(0,-1,-1,0,i,n);break;case 8:s.transform(0,-1,1,0,0,n)}return s.drawImage(t,0,0,n,i),Mt(t),r}function It(t,e,n=0){return new Promise((function(i,r){let s,o,a,c,l,h,u,f,d,p,g,v,w,m,y,b,k,A,x,S;function M(t=5){if(e.signal&&e.signal.aborted)throw e.signal.reason;s+=t,e.onProgress(Math.min(s,100))}function z(t){if(e.signal&&e.signal.aborted)throw e.signal.reason;s=Math.min(Math.max(t,s),100),e.onProgress(s)}return s=n,o=e.maxIteration||10,a=1024*e.maxSizeMB*1024,M(),xt(t,e).then(function(n){try{return[,c]=n,M(),l=Ct(c,e),M(),new Promise((function(n,i){var r;if(!(r=e.exifOrientation))return $t(t).then(function(t){try{return r=t,s.call(this)}catch(t){return i(t)}}.bind(this),i);function s(){return n(r)}return s.call(this)})).then(function(n){try{return h=n,M(),zt().then(function(n){try{return u=n?l:Tt(l,h),M(),f=e.initialQuality||1,d=e.fileType||t.type,St(u,d,t.name,t.lastModified,f).then(function(n){try{{if(p=n,M(),g=p.size>a,v=p.size>t.size,!g&&!v)return z(100),i(p);var s;function h(){if(o--&&(y>a||y>w)){let e,n;return e=S?.95*x.width:x.width,n=S?.95*x.height:x.height,[k,A]=bt(e,n),A.drawImage(x,0,0,e,n),f*="image/png"===d?.85:.95,St(k,d,t.name,t.lastModified,f).then((function(t){try{return b=t,Mt(x),x=k,y=b.size,z(Math.min(99,Math.floor((m-y)/(m-a)*100))),h}catch(t){return r(t)}}),r)}return[1]}return w=t.size,m=p.size,y=m,x=u,S=!e.alwaysKeepResolution&&g,(s=function(t){for(;t;){if(t.then)return void t.then(s,r);try{if(t.pop){if(t.length)return t.pop()?$.call(this):t;t=h}else t=t.call(this)}catch(t){return r(t)}}}.bind(this))(h);function $(){return Mt(x),Mt(k),Mt(l),Mt(u),Mt(c),z(100),i(b)}}}catch(C){return r(C)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}))}let jt;function Et(t,e){return new Promise(((n,i)=>{jt||(jt=function(){const t=[];return t.push("\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n"),URL.createObjectURL(new Blob(t))}());const r=new Worker(jt);r.addEventListener("message",(function(t){if(e.signal&&e.signal.aborted)r.terminate();else if(void 0===t.data.progress){if(t.data.error)return i(new Error(t.data.error)),void r.terminate();n(t.data.file),r.terminate()}else e.onProgress(t.data.progress)})),r.addEventListener("error",i),e.signal&&e.signal.addEventListener("abort",(()=>{i(e.signal.reason),r.terminate()})),r.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function _t(t,e){return new Promise((function(n,i){let r,s,o,a,c,l;if(r={...e},o=0,({onProgress:a}=r),r.maxSizeMB=r.maxSizeMB||Number.POSITIVE_INFINITY,c="boolean"!=typeof r.useWebWorker||r.useWebWorker,delete r.useWebWorker,r.onProgress=t=>{o=t,"function"==typeof a&&a(o)},!(t instanceof Blob||t instanceof dt))return i(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return i(new Error("The file given is not an image"));if(l="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!c||"function"!=typeof Worker||l)return It(t,r).then(function(t){try{return s=t,f.call(this)}catch(t){return i(t)}}.bind(this),i);var h=function(){try{return f.call(this)}catch(t){return i(t)}}.bind(this),u=function(){try{return It(t,r).then((function(t){try{return s=t,h()}catch(t){return i(t)}}),i)}catch(t){return i(t)}};try{return r.libURL=r.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Et(t,r).then((function(t){try{return s=t,h()}catch(t){return u()}}),u)}catch(t){u()}function f(){try{s.name=t.name,s.lastModified=t.lastModified}catch(t){}try{r.preserveExif&&"image/jpeg"===t.type&&(!r.fileType||r.fileType&&r.fileType===t.type)&&(s=et(t,s))}catch(t){}return n(s)}}))}_t.getDataUrlFromFile=vt,_t.getFilefromDataUrl=gt,_t.loadImage=wt,_t.drawImageInCanvas=kt,_t.drawFileInCanvas=xt,_t.canvasToFile=St,_t.getExifOrientation=$t,_t.handleMaxWidthOrHeight=Ct,_t.followExifOrientation=Tt,_t.cleanupCanvasMemory=Mt,_t.isAutoOrientationInBrowser=zt,_t.approximateBelowMaximumCanvasSizeOfBrowser=yt,_t.copyExifWithoutOrientation=et,_t.getBrowserName=mt,_t.version="2.0.2";class Lt extends a{toolType="image";fileInput=null;maxCompressionSize=1200;multiImportOffset=20;constructor(t){super(t),this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){this._core.store.isDisabled||this.fileInput?.click()}setupFileInput(){this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="image/*",this.fileInput.multiple=!0,this.fileInput.style.display="none",this.fileInput.addEventListener("change",this.handleFileSelect.bind(this)),this.fileInput.addEventListener("cancel",this.handleCancel.bind(this)),document.body.appendChild(this.fileInput)}handleFileSelect(t){const e=t.target,n=e.files?Array.from(e.files):[];if(0===n.length)return console.info("File selection cancelled by user."),this.handleCancel(),void(e&&(e.value=""));const i=n.map((t=>_t(t,{maxWidthOrHeight:this.maxCompressionSize}).then((t=>u.fromBlob(this._core,t)))));Promise.allSettled(i).then((t=>{const e=[];for(const n of t)"fulfilled"===n.status?e.push(n.value):console.error("Error during image compression or processing:",n.reason);0!==e.length?this.addImagesToStore(e):this.handleCancel()})),e&&(e.value="")}addImagesToStore(t){const e=this._core.store.currentZIndex;t.forEach(((t,n)=>{if(t.zIndex=e+n,t.centerInViewport(),n>0){const e=n*this.multiImportOffset;t.updatePosition(t.translateX+e,t.translateY+e)}this._core.addObject(t)})),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection")),this._core.selectObjects(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded(t)}handleCancel(){this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"))}}class Ot extends a{toolType="shape";shapeType=f.Rectangle;fillColor={light:"transparent",dark:"transparent"};strokeColor=x[0];strokeWidth=4;opacity=1;fontFamily="Arial";fontSize=16;fontColor=x[0];palette=[...x];sizes=[...c];startX=0;startY=0;isDrawing=!1;currentShape=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),n=this._core.findObjectById(e?.id),i=this._core.store.activeShape;if(null===i&&n instanceof d)return void n.edit(t);if(null!==i&&n instanceof d)return i.save(),void n.edit(t);if(null!==i&&n instanceof d==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"));if(!1===l.isLeftClick(t))return;this.startDrawing(t.clientX,t.clientY)}if("touch"===t.pointerType||"pen"===t.pointerType){const e=Array.from(this._core.store.state.pointers.values()),n=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=this._core.findObjectById(n?.id),r=this._core.store.activeShape;if(null===r&&i instanceof d)return void i.edit(t);if(null!==r&&i instanceof d)return r.save(),void i.edit(t);if(null!==r&&i instanceof d==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"));if(e.length>1)return;const s=Math.round(e[0].clientX),o=Math.round(e[0].clientY);this.startDrawing(s,o)}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&("mouse"===t.pointerType&&this.updateShapeSize(t.clientX,t.clientY),"touch"===t.pointerType||"pen"===t.pointerType)){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=Math.round(t[0].clientX),n=Math.round(t[0].clientY);this.updateShapeSize(e,n)}}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&this.finishDrawing()}startDrawing(t,e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1;this.startX=(t-this._core.store.offsetX)/r,this.startY=(e-this._core.store.offsetY)/r,this.isDrawing=!0,this.currentShape=d.create(this._core,{x:this.startX,y:this.startY,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,width:1,height:1,shapeType:this.shapeType,fillColor:this.fillColor,strokeColor:this.strokeColor,strokeWidth:this.strokeWidth,opacity:this.opacity,fontSize:this.fontSize,fontFamily:this.fontFamily,scale:i?1:n}),this._core.store.objects.insert(this.currentShape),this._core.store.objects?.setActiveDrawingObject(this.currentShape.id),this._core.rerender()}updateShapeSize(t,e){if(!this.currentShape)return;const n=this._core.store.state.lockDrawingScale?this._core.store.state.scale:1,i=(t-this._core.store.offsetX)/n,r=(e-this._core.store.offsetY)/n,s=Math.min(this.startX,i),o=Math.min(this.startY,r),a=Math.abs(i-this.startX),c=Math.abs(r-this.startY);this.currentShape.x=s,this.currentShape.y=o,this.currentShape.width=Math.max(1,a),this.currentShape.height=Math.max(1,c),this.currentShape.translateX=-this._core.store.state.translateX/n,this.currentShape.translateY=-this._core.store.state.translateY/n,this.currentShape.updateDimensions(),this._core.store.objects.update(this.currentShape)}finishDrawing(){if(this.currentShape){if(this.currentShape.width<10&&this.currentShape.height<10){const t=this.currentShape.id;this._core.store.objects.remove((e=>e.id===t))}else this.currentShape.zIndex=this._core.store.currentZIndex,this._core.store.objects.update(this.currentShape),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([this.currentShape]),this._core.selectObjects([this.currentShape]),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"));this.isDrawing=!1,this._core.store.objects?.setActiveDrawingObject(null),this.currentShape=null,this._core.store.objects?.stopUndoCapturing(),this._core.rerender()}}}class Pt{static _pointerCursor=null;static getPointerCursor(){return this._pointerCursor||(this._pointerCursor=this.getCursor({iconName:"pointer"})),this._pointerCursor}static getCursor(t){const e="default"===t.iconName?"mouse-pointer":t.iconName,n=K.get(e);if(!n)return console.warn(`Icon "${e}" not found in registry.`),"auto";const i=t.size||24,r=t.rotation||0,s=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:i/2,y:i/2});let a=n.replace(/width="\d+"/,`width="${i}"`).replace(/height="\d+"/,`height="${i}"`).replace(/currentColor/g,s);const c=i/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${i}" viewBox="0 0 ${i} ${i}">\n <g transform="rotate(${r} ${c} ${c})">\n ${a}\n </g>\n </svg>\n `.replace(/\s+/g," ").trim()).replace(/'/g,"%27").replace(/"/g,"%22")}') ${o.x} ${o.y}, auto`}}class Bt{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,e,n){const i=this.getLineById(t);if(!i)return;if("start"===e&&i.endAnchor?.objectId===n)return;if("end"===e&&i.startAnchor?.objectId===n)return;this.removeAnchor(t,e);const r={objectId:n};"start"===e?i.startAnchor=r:i.endAnchor=r,this.addToIndex(n,t,e),this.snapEndpointToObject(i,e,n),this._core.store.objects.update(i)}removeAnchor(t,e){const n=this.getLineById(t);if(!n)return;const i="start"===e?n.startAnchor:n.endAnchor;i&&(this.removeFromIndex(i.objectId,t,e),"start"===e?n.startAnchor=void 0:n.endAnchor=void 0)}getAnchor(t,e){const n=this.getLineById(t);return n?("start"===e?n.startAnchor:n.endAnchor)??null:null}getLinesAnchoredTo(t){const e=this._anchorIndex.get(t);return e?Array.from(e):[]}updateAnchorsForObject(t){const e=this.getLinesAnchoredTo(t);if(0===e.length)return;if(!this.getObjectById(t))return;for(const n of e){const e=this.getLineById(n.lineId);e&&this.snapEndpointToObject(e,n.endpoint,t)}const n=this._core.store.selectionGroup;n&&this._core.store.state.isDragging&&n.hasExternalAnchoredLineConnections()&&n.refreshObjectDimensions(void 0,!0)}snapEndpointToObject(t,e,n){const i=this.getObjectById(n);if(!i)return;const r=this.worldToLineLocal(t,i.centerX,i.centerY);t.updateEndpoint(e,r.x,r.y)}worldToLineLocal(t,e,n){const i=e-t.centerX,r=n-t.centerY,s=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(i*s-r*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(i*o+r*s+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,e,n,i,r="mouse"){return this.findBestSnapTarget(t,e,n,i,(n=>{const i=this.getSnapRadius(n,r),s=t-n.centerX,o=e-n.centerY;return Math.sqrt(s*s+o*o)<=i}))}findSnapPreviewTarget(t,e,n,i){return this.findBestSnapTarget(t,e,n,i,(()=>!0))}findBestSnapTarget(t,e,n,i,r){let s=null,o=-1/0;const a=this._core.store.allNonSelectionObjects;for(const c of a){if(c.id===n)continue;if(i&&c.id===i)continue;if(!this.isAnchorable(c))continue;const a=c.rotatedPolygon;O.isPointInPolygon({x:t,y:e},[a.topLeft,a.topRight,a.bottomRight,a.bottomLeft])&&r(c)&&c.zIndex>o&&(o=c.zIndex,s={objectId:c.id,centerX:c.centerX,centerY:c.centerY})}return s}getSnapRadius(t,e){const n=Math.min(t.width,t.height)/5;return"touch"===e||"pen"===e?Math.max(1.75*n,24/this.getSafeScale(this._core.store.state.scale)):n}setSnapCandidate(t){this._core.store.state.snapCandidate=t,this._core.rerender()}setSnapPreviewCandidate(t){this._core.store.state.snapPreviewCandidate=t,this._core.rerender()}getSnapCandidate(){return this._core.store.state.snapCandidate??null}getSnapPreviewCandidate(){return this._core.store.state.snapPreviewCandidate??null}clearSnapCandidate(){this._core.store.state.snapCandidate=null,this._core.rerender()}clearSnapPreviewCandidate(){this._core.store.state.snapPreviewCandidate=null,this._core.rerender()}getAnchorLinesRenderData(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const e=t.objects[0];if(!p.isInstanceOf(e,"KritzelLine"))return null;const n=e,i=this.computeAnchorVisualization(n,"start"),r=this.computeAnchorVisualization(n,"end"),s=this.isFiniteAnchorVisualization(i)?i:null,o=this.isFiniteAnchorVisualization(r)?r:null;if(!s&&!o)return null;const a=this.getSafeScale(this._core.store.state.scale),c=this.getSafeScale(n.scale),l=n.strokeWidth/c,h=""+2/a,u=Math.max(2*l,4/a),f=`${u} ${u}`,d=8/a;return this.areFiniteNumbers(l,u,d)?{lineStrokeWidth:l,indicatorStrokeWidth:h,dashArray:f,indicatorRadius:d,startAnchorViz:s,endAnchorViz:o}:null}getSnapIndicatorRenderData(){return this.getIndicatorRenderDataForCandidate(this.getSnapCandidate())}getSnapPreviewRenderData(){return this.getIndicatorRenderDataForCandidate(this.getSnapPreviewCandidate())}getIndicatorRenderDataForCandidate(t){if(!t)return null;if(!this.areFiniteNumbers(t.centerX,t.centerY,t.lineEndpointX,t.lineEndpointY))return null;const e=this.getSafeScale(this._core.store.state.scale),n=8/e,i=""+2/e,r=this.areFiniteNumbers(t.lineStrokeWidth)&&t.lineStrokeWidth>0?t.lineStrokeWidth:4/e,s=`${r}`,o=Math.max(2*r,4/e),a=`${o} ${o}`,c=t.lineStroke||"#000000";let l,h=this.areFiniteNumbers(t.edgeX)?t.edgeX:void 0,u=this.areFiniteNumbers(t.edgeY)?t.edgeY:void 0,f=h,d=u;const p=this.areFiniteNumbers(t.arrowOffset)&&t.arrowOffset>0?t.arrowOffset:void 0;if(void 0!==p&&void 0!==h&&void 0!==u){const e=t.lineEndpointX-h,n=t.lineEndpointY-u,i=Math.sqrt(e*e+n*n);i>p&&(f=h+e/i*p,d=u+n/i*p);const r=h-t.lineEndpointX,s=u-t.lineEndpointY,o=Math.sqrt(r*r+s*s);if(o>0){const t=r/o,e=s/o,n=-e,i=h,a=u,c=i-t*p,f=a-e*p,d=c+n*p/2,g=f+t*p/2,v=c-n*p/2,w=f-t*p/2;this.areFiniteNumbers(i,a,d,g,v,w)&&(l=`${i},${a} ${d},${g} ${v},${w}`)}}if(!this.areFiniteNumbers(n,r,o))return null;const g=(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t&&this.areFiniteNumbers(t.controlX,t.controlY,t.t)){const e="start"===t.endpoint?1-t.t:t.t;if(e>=1)return;const n=this.extractQuadraticSegment({x:t.lineEndpointX,y:t.lineEndpointY},{x:t.controlX,y:t.controlY},{x:t.centerX,y:t.centerY},e,1);if(!this.areFiniteNumbers(n.start.x,n.start.y,n.control.x,n.control.y,n.end.x,n.end.y))return;return`M ${n.start.x} ${n.start.y} Q ${n.control.x} ${n.control.y} ${n.end.x} ${n.end.y}`}})();return{indicatorRadius:n,indicatorStrokeWidth:i,lineStrokeWidth:s,dashArray:a,lineStroke:c,centerX:t.centerX,centerY:t.centerY,lineEndpointX:t.lineEndpointX,lineEndpointY:t.lineEndpointY,edgeX:h,edgeY:u,arrowOffset:p,arrowStyle:t.arrowStyle,arrowFill:t.arrowFill,solidLineEndX:f,solidLineEndY:d,arrowPoints:l,snapLinePath:g}}handleObjectDeleted(t){const e=this.getLinesAnchoredTo(t);for(const t of e){this.removeAnchor(t.lineId,t.endpoint);const e=this.getLineById(t.lineId);e&&this._core.store.objects.update(e)}this._anchorIndex.delete(t)}handleLineDeleted(t){const e=this.getLineById(t);e&&(e.startAnchor&&this.removeFromIndex(e.startAnchor.objectId,t,"start"),e.endAnchor&&this.removeFromIndex(e.endAnchor.objectId,t,"end"))}rebuildIndex(){this._anchorIndex.clear();const t=this._core.store.allObjects;for(const e of t)e instanceof L&&(e.startAnchor&&this.addToIndex(e.startAnchor.objectId,e.id,"start"),e.endAnchor&&this.addToIndex(e.endAnchor.objectId,e.id,"end"))}addToIndex(t,e,n){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const i=this._anchorIndex.get(t);for(const t of i)if(t.lineId===e&&t.endpoint===n)return;i.add({lineId:e,endpoint:n})}removeFromIndex(t,e,n){const i=this._anchorIndex.get(t);if(i){for(const t of i)if(t.lineId===e&&t.endpoint===n){i.delete(t);break}0===i.size&&this._anchorIndex.delete(t)}}getLineById(t){const e=this._core.store.objects.filter((e=>e.id===t));if(0===e.length)return null;const n=e[0];return n instanceof L?n:null}getObjectById(t){const e=this._core.store.objects.filter((e=>e.id===t));return e.length>0?e[0]:null}findAnchorTarget(t,e){const n="start"===e?t.startAnchor:t.endAnchor;return n?this._core.store.allNonSelectionObjects.find((t=>t.id===n.objectId))??null:null}computeAnchorVisualization(t,e){if(!("start"===e?t.startAnchor:t.endAnchor))return null;const n=this.findAnchorTarget(t,e);if(!n)return null;const i=this.computeAnchorClipInfo(t,e,n);if(!i)return null;const r=n.centerX,s=n.centerY;if(!this.areFiniteNumbers(i.worldX,i.worldY,r,s))return null;const o=this.buildAnchorPath(t,e,i,n)??void 0;return o&&!this.isFinitePathData(o)?null:{edgeX:i.worldX,edgeY:i.worldY,centerX:r,centerY:s,pathD:o}}computeClippedLinePath(t,e=!1){const n=this.getSnapCandidate(),i=this._core.store.selectionGroup,r=n&&i&&1===i.objects.length&&i.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!r)return e?void 0!==t.controlX&&void 0!==t.controlY?`M ${t.startX-t.x} ${t.startY-t.y} Q ${t.controlX-t.x} ${t.controlY-t.y} ${t.endX-t.x} ${t.endY-t.y}`:`M ${t.startX-t.x} ${t.startY-t.y} L ${t.endX-t.x} ${t.endY-t.y}`:t.d;const s=t.startAnchor?this.findAnchorTarget(t,"start"):null,o=t.endAnchor?this.findAnchorTarget(t,"end"):null;let a=s?this.computeAnchorClipInfo(t,"start",s):null,c=o?this.computeAnchorClipInfo(t,"end",o):null;if(r&&void 0!==n.edgeX&&void 0!==n.edgeY){const e=this.lineWorldToLocal(t,n.edgeX,n.edgeY),i={worldX:n.edgeX,worldY:n.edgeY,localX:e.x,localY:e.y,t:n.t};"start"===n.endpoint?a=i:c=i}const l=e?t.x:0,h=e?t.y:0;if(void 0!==t.controlX&&void 0!==t.controlY){let e=a?.t??0,n=c?.t??1;if(a&&t.hasStartArrow){const n=t.getArrowSize("start"),i=this.evaluateDerivativeSpeedAtT(t,e);i>0&&(e+=n/i)}if(c&&t.hasEndArrow){const e=t.getArrowSize("end"),i=this.evaluateDerivativeSpeedAtT(t,n);i>0&&(n-=e/i)}if(e<0&&(e=0),n>1&&(n=1),n<=e){const t=(e+n)/2;e=t,n=t}const i=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},e,n);return`M ${i.start.x-l} ${i.start.y-h} Q ${i.control.x-l} ${i.control.y-h} ${i.end.x-l} ${i.end.y-h}`}let u=a?.localX??t.startX,f=a?.localY??t.startY,d=c?.localX??t.endX,p=c?.localY??t.endY;if(a&&t.hasStartArrow){const e=t.getArrowSize("start"),n=d-u,i=p-f,r=Math.sqrt(n*n+i*i);r>e&&(u+=n/r*e,f+=i/r*e)}if(c&&t.hasEndArrow){const e=t.getArrowSize("end"),n=u-d,i=f-p,r=Math.sqrt(n*n+i*i);r>e&&(d+=n/r*e,p+=i/r*e)}return`M ${u-l} ${f-h} L ${d-l} ${p-h}`}computeAnchorClipInfo(t,e,n){return void 0!==t.controlX&&void 0!==t.controlY?this.computeCurvedClipInfo(t,e,n):this.computeStraightClipInfo(t,e,n)}computeStraightClipInfo(t,e,n){const i="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),r=this.getPathClipPoint(n,i);if(r){const n=this.lineWorldToLocal(t,r.x,r.y),i=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),s=Math.sqrt(Math.pow(n.x-t.startX,2)+Math.pow(n.y-t.startY,2));return{localX:n.x,localY:n.y,worldX:r.x,worldY:r.y,t:i>0?s/i:"start"===e?0:1}}const s=this.getClipPolygonForObject(n);let o;if(o=s?O.getLinePointsArrayIntersection(i,{x:n.centerX,y:n.centerY},s):O.getLinePolygonIntersection(i,{x:n.centerX,y:n.centerY},n.rotatedPolygon),!o)return null;const a=this.lineWorldToLocal(t,o.x,o.y),c=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),l=Math.sqrt(Math.pow(a.x-t.startX,2)+Math.pow(a.y-t.startY,2));return{localX:a.x,localY:a.y,worldX:o.x,worldY:o.y,t:c>0?l/c:"start"===e?0:1}}computeCurvedClipInfo(t,e,n){if(p.isInstanceOf(n,"KritzelPath"))return this.findCurveExitPointForPath(t,e,n);const i=this.getClipPolygonForObject(n),r=i??this.getPolygonPoints(n.rotatedPolygon),s=this.findCurveExitPoint(t,e,r);if(s)return s;const o="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let a;if(a=i?O.getLinePointsArrayIntersection(o,{x:n.centerX,y:n.centerY},i):O.getLinePolygonIntersection(o,{x:n.centerX,y:n.centerY},n.rotatedPolygon),!a)return null;const c=this.lineWorldToLocal(t,a.x,a.y),l=this.approximateParameterForWorldPoint(t,a);return{localX:c.x,localY:c.y,worldX:a.x,worldY:a.y,t:l}}findCurveExitPoint(t,e,n){const i="start"===e?0:1,r=this.evaluateLineAtT(t,i);let s=O.isPointInPolygon({x:r.worldX,y:r.worldY},n),o=i;for(let i=1;i<=64;i++){const r="start"===e?i/64:1-i/64,a=this.evaluateLineAtT(t,r),c=O.isPointInPolygon({x:a.worldX,y:a.worldY},n);if(s&&!c){const e=this.refineCurveExitParameter(t,n,o,r),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}s=c,o=r}return null}findCurveExitPointForPath(t,e,n){const i="start"===e?0:1,r=n.strokeWidth/n.scale/2,s=this.getPathAdjustedPoints(n);if(s.length<1)return null;const o=this.evaluateLineAtT(t,i);let a=this.isPointInPathStroke(o.worldX,o.worldY,s,r),c=i;for(let n=1;n<=64;n++){const i="start"===e?n/64:1-n/64,o=this.evaluateLineAtT(t,i),l=this.isPointInPathStroke(o.worldX,o.worldY,s,r);if(a&&!l){const e=this.refineCurveExitParameterForPath(t,s,r,c,i),n=this.evaluateLineAtT(t,e);return{localX:n.localX,localY:n.localY,worldX:n.worldX,worldY:n.worldY,t:e}}a=l,c=i}return null}refineCurveExitParameterForPath(t,e,n,i,r){let s=i,o=r;for(let i=0;i<8;i++){const i=(s+o)/2,r=this.evaluateLineAtT(t,i);this.isPointInPathStroke(r.worldX,r.worldY,e,n)?s=i:o=i}return(s+o)/2}getPathAdjustedPoints(t){return this.computePathAdjustedPoints(t)}computePathAdjustedPoints(t){if(!t.points?.length)return[];const e=t.rotation,n=Math.cos(e),i=Math.sin(e),r=t.points.map((t=>t[0])),s=t.points.map((t=>t[1])),o={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...s)+Math.max(...s))/2},{x:a,y:c}=o;return t.points.map((([t,e])=>{const r=t-a,s=e-c;return[a+r*n-s*i,c+r*i+s*n]})).map((([e,n])=>[Math.abs(e-t.x)/t.scale+t.translateX,Math.abs(n-t.y)/t.scale+t.translateY]))}isPointInPathStroke(t,e,n,i){if(1===n.length){const r=n[0],s=t-r[0],o=e-r[1];return Math.sqrt(s*s+o*o)<=i}for(let r=0;r<n.length-1;r++){const s=n[r],o=n[r+1];if(this.pointToSegmentDistance(t,e,s[0],s[1],o[0],o[1])<=i)return!0}return!1}pointToSegmentDistance(t,e,n,i,r,s){const o=r-n,a=s-i,c=o*o+a*a;if(0===c)return Math.sqrt((t-n)*(t-n)+(e-i)*(e-i));let l=((t-n)*o+(e-i)*a)/c;l=Math.max(0,Math.min(1,l));const h=n+l*o,u=i+l*a;return Math.sqrt((t-h)*(t-h)+(e-u)*(e-u))}refineCurveExitParameter(t,e,n,i){let r=n,s=i;for(let n=0;n<8;n++){const n=(r+s)/2,i=this.evaluateLineAtT(t,n);O.isPointInPolygon({x:i.worldX,y:i.worldY},e)?r=n:s=n}return(r+s)/2}approximateParameterForWorldPoint(t,e){let n=0,i=1/0;for(let r=0;r<=80;r++){const s=r/80,o=this.evaluateLineAtT(t,s),a=Math.hypot(o.worldX-e.x,o.worldY-e.y);a<i&&(i=a,n=s)}return n}evaluateLineAtT(t,e){const n=Math.max(0,Math.min(1,e));let i,r;if(void 0!==t.controlX&&void 0!==t.controlY){const e=1-n;i=e*e*t.startX+2*e*n*t.controlX+n*n*t.endX,r=e*e*t.startY+2*e*n*t.controlY+n*n*t.endY}else i=t.startX+(t.endX-t.startX)*n,r=t.startY+(t.endY-t.startY)*n;const s=this.lineLocalToWorld(t,i,r);return{t:n,localX:i,localY:r,worldX:s.x,worldY:s.y}}evaluateDerivativeSpeedAtT(t,e){const n=Math.max(0,Math.min(1,e));if(void 0!==t.controlX&&void 0!==t.controlY){const e=t.controlX,i=t.controlY,r=2*(1-n)*(e-t.startX)+2*n*(t.endX-e),s=2*(1-n)*(i-t.startY)+2*n*(t.endY-i);return Math.sqrt(r*r+s*s)}{const e=t.endX-t.startX,n=t.endY-t.startY;return Math.sqrt(e*e+n*n)}}extractQuadraticSegment(t,e,n,i,r){let s=Math.max(0,Math.min(1,i)),o=Math.max(0,Math.min(1,r));if(o<s){const t=s;s=o,o=t}let a={start:t,control:e,end:n};if(s>0){a=this.splitQuadraticSegment(a,s).right;const t=1-s;o=t>0?(o-s)/t:1}return o<1&&(a=this.splitQuadraticSegment(a,o).left),a}splitQuadraticSegment(t,e){const n=Math.max(0,Math.min(1,e)),i=t.start,r=t.control,s=t.end,o=this.lerpPoint(i,r,n),a=this.lerpPoint(r,s,n),c=this.lerpPoint(o,a,n);return{left:{start:i,control:o,end:c},right:{start:c,control:a,end:s}}}lerpPoint(t,e,n){return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}}buildAnchorPath(t,e,n,i){if(void 0===t.controlX||void 0===t.controlY||void 0===n.t)return`M ${n.worldX} ${n.worldY} L ${i.centerX} ${i.centerY}`;const r="start"===e?0:n.t,s="start"===e?n.t:1;if(s<=r)return`M ${n.worldX} ${n.worldY} L ${i.centerX} ${i.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},r,s);return this.buildWorldQuadraticPath(t,o,"start"===e)}buildWorldQuadraticPath(t,e,n=!1){const i=n?e.end:e.start,r=n?e.start:e.end,s=e.control,o=this.lineLocalToWorld(t,i.x,i.y),a=this.lineLocalToWorld(t,s.x,s.y),c=this.lineLocalToWorld(t,r.x,r.y);return`M ${o.x} ${o.y} Q ${a.x} ${a.y} ${c.x} ${c.y}`}getPolygonPoints(t){return[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft]}getClipPolygonForObject(t){return p.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,e){return p.isInstanceOf(t,"KritzelPath")?t.getClipPoint(e):null}lineLocalToWorld(t,e,n){const i=e-t.x,r=n-t.y,s=t.totalWidth/2,o=t.totalHeight/2,a=Math.cos(t.rotation),c=Math.sin(t.rotation),l=(i-s)*a-(r-o)*c+s,h=(i-s)*c+(r-o)*a+o,u=this.getSafeScale(t.scale);return{x:l/u+t.translateX,y:h/u+t.translateY}}lineWorldToLocal(t,e,n){const i=this.getSafeScale(t.scale),r=(e-t.translateX)*i,s=(n-t.translateY)*i,o=t.totalWidth/2,a=t.totalHeight/2,c=Math.cos(-t.rotation),l=Math.sin(-t.rotation);return{x:(r-o)*c-(s-a)*l+o+t.x,y:(r-o)*l+(s-a)*c+a+t.y}}getSafeScale(t){return Number.isFinite(t)&&Math.abs(t)>1e-6?t:1}areFiniteNumbers(...t){return t.every((t=>void 0!==t&&Number.isFinite(t)))}isFiniteAnchorVisualization(t){return!(!t||!this.areFiniteNumbers(t.edgeX,t.edgeY,t.centerX,t.centerY)||t.pathD&&!this.isFinitePathData(t.pathD))}isFinitePathData(t){return!t.includes("Infinity")&&!t.includes("NaN")}isAnchorable(t){return!(t instanceof g||t instanceof h)&&!(t instanceof L)&&t.isVisible}}class Dt{static interpolate(t,e){return e?t.replace(/\{(\w+)\}/g,((t,n)=>{const i=e[n];return null==i?t:String(i)})):t}}const Rt={code:"en",label:"English",terms:{"menu.copy":"Copy","menu.cut":"Cut","menu.paste":"Paste","menu.selectAll":"Select All","menu.order":"Order","menu.bringToFront":"Bring to Front","menu.sendToBack":"Send to Back","menu.moveUp":"Move Up","menu.moveDown":"Move Down","menu.align":"Align","menu.alignLeft":"Align Left","menu.alignCenterHorizontal":"Align Center Horizontally","menu.alignRight":"Align Right","menu.alignTop":"Align Top","menu.alignCenterVertical":"Align Center Vertically","menu.alignBottom":"Align Bottom","menu.group":"Group","menu.ungroup":"Ungroup","menu.export":"Export","menu.exportAsSvg":"Export as SVG","menu.exportAsPng":"Export as PNG","menu.delete":"Delete","menu.share":"Share","menu.import":"Import","menu.settings":"Settings","menu.logout":"Logout","settings.dialogTitle":"Settings","settings.categories.general":"General","settings.categories.viewport":"Viewport","settings.categories.shortcuts":"Keyboard Shortcuts","settings.categories.developer":"Developer Options","settings.categories.about":"About","settings.general.title":"General Settings","settings.general.theme.label":"Theme","settings.general.theme.description":"Select a registered color theme for the editor interface.","settings.general.language.label":"Language","settings.general.language.description":"Select the display language for the editor interface.","settings.general.lockDrawingScale.label":"Lock Drawing Scale","settings.general.lockDrawingScale.description":"When enabled, drawn objects maintain a fixed visual size regardless of the current zoom level.","settings.viewport.title":"Viewport Settings","settings.viewport.minZoom.label":"Minimum Zoom Level","settings.viewport.minZoom.description":"Sets the minimum zoom level. Lower values allow zooming out further to see more of the canvas.","settings.viewport.maxZoom.label":"Maximum Zoom Level","settings.viewport.maxZoom.description":"Sets the maximum zoom level. Higher values allow zooming in closer for detailed work.","settings.viewport.boundaryLeft.label":"Viewport Boundary Left","settings.viewport.boundaryLeft.description":"Left boundary in world coordinates. Set to limit how far left the viewport can pan.","settings.viewport.boundaryRight.label":"Viewport Boundary Right","settings.viewport.boundaryRight.description":"Right boundary in world coordinates. Set to limit how far right the viewport can pan.","settings.viewport.boundaryTop.label":"Viewport Boundary Top","settings.viewport.boundaryTop.description":"Top boundary in world coordinates. Set to limit how far up the viewport can pan.","settings.viewport.boundaryBottom.label":"Viewport Boundary Bottom","settings.viewport.boundaryBottom.description":"Bottom boundary in world coordinates. Set to limit how far down the viewport can pan.","settings.viewport.boundaryPlaceholder":"Infinite","settings.shortcuts.title":"Keyboard Shortcuts","settings.developer.title":"Developer Options","settings.developer.showViewportInfo.label":"Show Viewport Info","settings.developer.showViewportInfo.description":"Display viewport debug information such as position, zoom level, and boundaries.","settings.developer.showObjectInfo.label":"Show Object Info","settings.developer.showObjectInfo.description":"Display debug information about objects on the canvas.","settings.developer.showSyncProviderInfo.label":"Show Sync Provider Info","settings.developer.showSyncProviderInfo.description":"Display debug information about the sync provider connection status.","settings.developer.showMigrationInfo.label":"Show Migration Info","settings.developer.showMigrationInfo.description":"Display debug information about data migrations.","settings.about.title":"About","settings.about.description":"Kritzel - A drawing application","export.dialogTitle":"Export","export.tabs.viewport":"Export Viewport","export.tabs.workspace":"Export Workspace","export.format.label":"Format","export.filename.label":"Filename","export.filename.placeholder":"Enter filename","export.exportButton":"Export","workspace.sharedTooltip":"Shared workspace","workspace.rename":"Rename","workspace.delete":"Delete","zoom.zoomIn":"Zoom in","zoom.zoomOut":"Zoom out","utility.undo":"Undo","utility.redo":"Redo","utility.delete":"Delete selected items","share.dialogTitle":"Share Workspace","share.linkSharing.label":"Link sharing","share.linkSharing.enabledDescription":"Anyone with the link can access this workspace.","share.linkSharing.disabledDescription":"Link sharing is disabled. Only you can access this workspace.","share.linkSharing.toggleLabel":"Enable link sharing","share.copyLink.title":"Copy link","share.copyLink.copied":"Copied!","login.dialogTitle":"Sign in","currentUser.dialogTitle":"Account","backToContent.label":"Back to content","toolConfig.collapse":"Collapse","toolConfig.expand":"Expand","moreMenu.ariaLabel":"More options","engine.loading":"Loading...","watermark.poweredBy":"Powered by Kritzel"}},Wt={code:"de",label:"Deutsch",terms:{"menu.copy":"Kopieren","menu.cut":"Ausschneiden","menu.paste":"Einfügen","menu.selectAll":"Alles auswählen","menu.order":"Anordnen","menu.bringToFront":"In den Vordergrund","menu.sendToBack":"In den Hintergrund","menu.moveUp":"Nach vorne","menu.moveDown":"Nach hinten","menu.align":"Ausrichten","menu.alignLeft":"Linksbündig ausrichten","menu.alignCenterHorizontal":"Horizontal zentrieren","menu.alignRight":"Rechtsbündig ausrichten","menu.alignTop":"Oben ausrichten","menu.alignCenterVertical":"Vertikal zentrieren","menu.alignBottom":"Unten ausrichten","menu.group":"Gruppieren","menu.ungroup":"Gruppierung aufheben","menu.export":"Exportieren","menu.exportAsSvg":"Als SVG exportieren","menu.exportAsPng":"Als PNG exportieren","menu.delete":"Löschen","menu.share":"Teilen","menu.import":"Importieren","menu.settings":"Einstellungen","menu.logout":"Abmelden","settings.dialogTitle":"Einstellungen","settings.categories.general":"Allgemein","settings.categories.viewport":"Ansichtsfenster","settings.categories.shortcuts":"Tastenkürzel","settings.categories.developer":"Entwickleroptionen","settings.categories.about":"Über","settings.general.title":"Allgemeine Einstellungen","settings.general.theme.label":"Design","settings.general.theme.description":"Wählen Sie ein registriertes Farbdesign für die Editor-Oberfläche.","settings.general.language.label":"Sprache","settings.general.language.description":"Wählen Sie die Anzeigesprache für die Editor-Oberfläche.","settings.general.lockDrawingScale.label":"Zeichenskalierung sperren","settings.general.lockDrawingScale.description":"Wenn aktiviert, behalten gezeichnete Objekte unabhängig von der aktuellen Zoomstufe eine feste visuelle Größe.","settings.viewport.title":"Ansichtsfenster-Einstellungen","settings.viewport.minZoom.label":"Minimale Zoomstufe","settings.viewport.minZoom.description":"Legt die minimale Zoomstufe fest. Niedrigere Werte ermöglichen weiteres Herauszoomen, um mehr von der Zeichenfläche zu sehen.","settings.viewport.maxZoom.label":"Maximale Zoomstufe","settings.viewport.maxZoom.description":"Legt die maximale Zoomstufe fest. Höhere Werte ermöglichen näheres Heranzoomen für Detailarbeit.","settings.viewport.boundaryLeft.label":"Ansichtsfenster-Grenze links","settings.viewport.boundaryLeft.description":"Linke Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach links verschoben werden kann.","settings.viewport.boundaryRight.label":"Ansichtsfenster-Grenze rechts","settings.viewport.boundaryRight.description":"Rechte Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach rechts verschoben werden kann.","settings.viewport.boundaryTop.label":"Ansichtsfenster-Grenze oben","settings.viewport.boundaryTop.description":"Obere Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach oben verschoben werden kann.","settings.viewport.boundaryBottom.label":"Ansichtsfenster-Grenze unten","settings.viewport.boundaryBottom.description":"Untere Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach unten verschoben werden kann.","settings.viewport.boundaryPlaceholder":"Unendlich","settings.shortcuts.title":"Tastenkürzel","settings.developer.title":"Entwickleroptionen","settings.developer.showViewportInfo.label":"Ansichtsfenster-Infos anzeigen","settings.developer.showViewportInfo.description":"Zeigt Debug-Informationen zum Ansichtsfenster an, z. B. Position, Zoomstufe und Grenzen.","settings.developer.showObjectInfo.label":"Objekt-Infos anzeigen","settings.developer.showObjectInfo.description":"Zeigt Debug-Informationen zu Objekten auf der Zeichenfläche an.","settings.developer.showSyncProviderInfo.label":"Sync-Provider-Infos anzeigen","settings.developer.showSyncProviderInfo.description":"Zeigt Debug-Informationen zum Verbindungsstatus des Sync-Providers an.","settings.developer.showMigrationInfo.label":"Migrations-Infos anzeigen","settings.developer.showMigrationInfo.description":"Zeigt Debug-Informationen zu Datenmigrationen an.","settings.about.title":"Über","settings.about.description":"Kritzel – Eine Zeichenanwendung","export.dialogTitle":"Exportieren","export.tabs.viewport":"Ansichtsfenster exportieren","export.tabs.workspace":"Arbeitsbereich exportieren","export.format.label":"Format","export.filename.label":"Dateiname","export.filename.placeholder":"Dateiname eingeben","export.exportButton":"Exportieren","workspace.sharedTooltip":"Geteilter Arbeitsbereich","workspace.rename":"Umbenennen","workspace.delete":"Löschen","zoom.zoomIn":"Vergrößern","zoom.zoomOut":"Verkleinern","utility.undo":"Rückgängig","utility.redo":"Wiederholen","utility.delete":"Ausgewählte Elemente löschen","share.dialogTitle":"Arbeitsbereich teilen","share.linkSharing.label":"Link-Freigabe","share.linkSharing.enabledDescription":"Jeder mit dem Link kann auf diesen Arbeitsbereich zugreifen.","share.linkSharing.disabledDescription":"Die Link-Freigabe ist deaktiviert. Nur Sie können auf diesen Arbeitsbereich zugreifen.","share.linkSharing.toggleLabel":"Link-Freigabe aktivieren","share.copyLink.title":"Link kopieren","share.copyLink.copied":"Kopiert!","login.dialogTitle":"Anmelden","currentUser.dialogTitle":"Konto","backToContent.label":"Zurück zum Inhalt","toolConfig.collapse":"Einklappen","toolConfig.expand":"Ausklappen","moreMenu.ariaLabel":"Weitere Optionen","engine.loading":"Wird geladen...","watermark.poweredBy":"Bereitgestellt von Kritzel"}},Ut={code:"fr",label:"Français",terms:{"menu.copy":"Copier","menu.cut":"Couper","menu.paste":"Coller","menu.selectAll":"Tout sélectionner","menu.order":"Ordre","menu.bringToFront":"Mettre au premier plan","menu.sendToBack":"Mettre à l'arrière-plan","menu.moveUp":"Avancer","menu.moveDown":"Reculer","menu.align":"Aligner","menu.alignLeft":"Aligner à gauche","menu.alignCenterHorizontal":"Centrer horizontalement","menu.alignRight":"Aligner à droite","menu.alignTop":"Aligner en haut","menu.alignCenterVertical":"Centrer verticalement","menu.alignBottom":"Aligner en bas","menu.group":"Grouper","menu.ungroup":"Dégrouper","menu.export":"Exporter","menu.exportAsSvg":"Exporter en SVG","menu.exportAsPng":"Exporter en PNG","menu.delete":"Supprimer","menu.share":"Partager","menu.import":"Importer","menu.settings":"Paramètres","menu.logout":"Déconnexion","settings.dialogTitle":"Paramètres","settings.categories.general":"Général","settings.categories.viewport":"Fenêtre d'affichage","settings.categories.shortcuts":"Raccourcis clavier","settings.categories.developer":"Options développeur","settings.categories.about":"À propos","settings.general.title":"Paramètres généraux","settings.general.theme.label":"Thème","settings.general.theme.description":"Sélectionnez un thème de couleurs enregistré pour l'interface de l'éditeur.","settings.general.language.label":"Langue","settings.general.language.description":"Sélectionnez la langue d'affichage de l'interface de l'éditeur.","settings.general.lockDrawingScale.label":"Verrouiller l'échelle de dessin","settings.general.lockDrawingScale.description":"Lorsque cette option est activée, les objets dessinés conservent une taille visuelle fixe quel que soit le niveau de zoom actuel.","settings.viewport.title":"Paramètres de la fenêtre d'affichage","settings.viewport.minZoom.label":"Niveau de zoom minimal","settings.viewport.minZoom.description":"Définit le niveau de zoom minimal. Des valeurs plus faibles permettent de dézoomer davantage pour voir une plus grande partie du canevas.","settings.viewport.maxZoom.label":"Niveau de zoom maximal","settings.viewport.maxZoom.description":"Définit le niveau de zoom maximal. Des valeurs plus élevées permettent de zoomer davantage pour un travail détaillé.","settings.viewport.boundaryLeft.label":"Limite gauche de la fenêtre d'affichage","settings.viewport.boundaryLeft.description":"Limite gauche en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers la gauche.","settings.viewport.boundaryRight.label":"Limite droite de la fenêtre d'affichage","settings.viewport.boundaryRight.description":"Limite droite en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers la droite.","settings.viewport.boundaryTop.label":"Limite supérieure de la fenêtre d'affichage","settings.viewport.boundaryTop.description":"Limite supérieure en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers le haut.","settings.viewport.boundaryBottom.label":"Limite inférieure de la fenêtre d'affichage","settings.viewport.boundaryBottom.description":"Limite inférieure en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers le bas.","settings.viewport.boundaryPlaceholder":"Infini","settings.shortcuts.title":"Raccourcis clavier","settings.developer.title":"Options développeur","settings.developer.showViewportInfo.label":"Afficher les infos de la fenêtre d'affichage","settings.developer.showViewportInfo.description":"Affiche les informations de débogage de la fenêtre d'affichage telles que la position, le niveau de zoom et les limites.","settings.developer.showObjectInfo.label":"Afficher les infos des objets","settings.developer.showObjectInfo.description":"Affiche les informations de débogage des objets sur le canevas.","settings.developer.showSyncProviderInfo.label":"Afficher les infos du fournisseur de synchronisation","settings.developer.showSyncProviderInfo.description":"Affiche les informations de débogage sur l'état de connexion du fournisseur de synchronisation.","settings.developer.showMigrationInfo.label":"Afficher les infos de migration","settings.developer.showMigrationInfo.description":"Affiche les informations de débogage sur les migrations de données.","settings.about.title":"À propos","settings.about.description":"Kritzel - Une application de dessin","export.dialogTitle":"Exporter","export.tabs.viewport":"Exporter la fenêtre d'affichage","export.tabs.workspace":"Exporter l'espace de travail","export.format.label":"Format","export.filename.label":"Nom du fichier","export.filename.placeholder":"Saisir le nom du fichier","export.exportButton":"Exporter","workspace.sharedTooltip":"Espace de travail partagé","workspace.rename":"Renommer","workspace.delete":"Supprimer","zoom.zoomIn":"Zoom avant","zoom.zoomOut":"Zoom arrière","utility.undo":"Annuler","utility.redo":"Rétablir","utility.delete":"Supprimer les éléments sélectionnés","share.dialogTitle":"Partager l'espace de travail","share.linkSharing.label":"Partage par lien","share.linkSharing.enabledDescription":"Toute personne disposant du lien peut accéder à cet espace de travail.","share.linkSharing.disabledDescription":"Le partage par lien est désactivé. Vous seul pouvez accéder à cet espace de travail.","share.linkSharing.toggleLabel":"Activer le partage par lien","share.copyLink.title":"Copier le lien","share.copyLink.copied":"Copié !","login.dialogTitle":"Se connecter","currentUser.dialogTitle":"Compte","backToContent.label":"Retour au contenu","toolConfig.collapse":"Réduire","toolConfig.expand":"Développer","moreMenu.ariaLabel":"Plus d'options","engine.loading":"Chargement...","watermark.poweredBy":"Propulsé par Kritzel"}},Ft="kritzel-settings",Kt="en";class Vt{_core;_storageKey;_builtinLocales=new Map;_customLocales=new Map;_currentLocale=Kt;_fallbackLocale=Kt;constructor(t){this._core=t,this._storageKey=t.editorId?`${Ft}-${t.editorId}`:Ft,this._builtinLocales.set(Rt.code,Rt),this._builtinLocales.set(Wt.code,Wt),this._builtinLocales.set(Ut.code,Ut),this._currentLocale=this.getStoredLocale()}get currentLocale(){return this._currentLocale}get fallbackLocale(){return this._fallbackLocale}setFallbackLocale(t){this._fallbackLocale=t}registerLocales(t){for(const e of t)this._customLocales.set(e.code,e)}setLocale(t){this._currentLocale=t,this._core.rerender()}getAvailableLocales(){return Array.from(new Set([...this._builtinLocales.keys(),...this._customLocales.keys()]))}getAvailableLocaleOptions(){return this.getAvailableLocales().map((t=>({code:t,label:this.getLocaleLabel(t)})))}getLocaleLabel(t){return this._customLocales.get(t)?.label??this._builtinLocales.get(t)?.label??t}translate(t,e){const n=this._customLocales.get(this._currentLocale)?.terms[t]??this._builtinLocales.get(this._currentLocale)?.terms[t]??this._customLocales.get(this._fallbackLocale)?.terms[t]??this._builtinLocales.get(this._fallbackLocale)?.terms[t]??t;return Dt.interpolate(n,e)}getAllTerms(){const t=new Set;for(const e of[...this._builtinLocales.values(),...this._customLocales.values()])for(const n of Object.keys(e.terms))t.add(n);const e={};for(const n of t)e[n]=this.translate(n);return e}getStoredLocale(){if("undefined"==typeof localStorage)return Kt;const t=localStorage.getItem(this._storageKey);if(!t)return Kt;try{const e=JSON.parse(t);if("string"==typeof e?.locale)return e.locale}catch{}return Kt}cleanup(){this._customLocales.clear()}}class Nt{_core;_licenseKey;_isLicensed=!1;_verifiedToken;_validationId=0;_publicKeyPromise;_timer=null;constructor(t){this._core=t}get isLicensed(){return this._isLicensed}validate(t){this._licenseKey=t;const e=++this._validationId;let n;try{n=this.preCheck(t)}catch{return this.commit(!0,e),this._isLicensed}return"rejected"===n.status?(this._verifiedToken=void 0,this.commit(!1,e),this._isLicensed):this._verifiedToken===t?(this.commit(!0,e),this._isLicensed):(this.verifySignature(n.payloadSegment,n.signatureSegment).then((n=>{e===this._validationId&&(n?(this._verifiedToken=t,this.commit(!0,e)):(this._verifiedToken=void 0,this.commit(!1,e)))})).catch((()=>{e===this._validationId&&this.commit(!0,e)})),this._isLicensed)}startPeriodicValidation(){this.stopPeriodicValidation(),this.scheduleNextValidation()}stopPeriodicValidation(){null!==this._timer&&(clearTimeout(this._timer),this._timer=null)}destroy(){this.stopPeriodicValidation()}commit(t,e){e===this._validationId&&t!==this._isLicensed&&(this._isLicensed=t,this._core.rerender())}scheduleNextValidation(){const t=this.getRandomRevalidationDelay();this._timer=setTimeout((()=>{this.validate(this._licenseKey),this.scheduleNextValidation()}),t)}getRandomRevalidationDelay(){return 3e4+Math.floor(30001*Math.random())}preCheck(t){if(null==t)return{status:"rejected"};const e=t.trim();if(0===e.length||!e.startsWith("KRTZL1."))return{status:"rejected"};const n=e.slice(7).split(".");if(2!==n.length||0===n[0].length||0===n[1].length)return{status:"rejected"};const[i,r]=n;let s;try{s=JSON.parse(this.base64UrlToString(i))}catch{return{status:"rejected"}}return null===s||"object"!=typeof s||"number"==typeof s.exp&&1e3*s.exp<=Date.now()?{status:"rejected"}:{status:"pass",payloadSegment:i,signatureSegment:r,claims:s}}async verifySignature(t,e){const n=await this.getPublicKey(),i=this.utf8Bytes(t),r=this.base64UrlToBytes(e);return crypto.subtle.verify("Ed25519",n,r,i)}getPublicKey(){if(!this._publicKeyPromise){const t=this.base64UrlToBytes("I-pYJlxDEjT94rwSaqhXW5Sv__fMKS-JKKnV3pg0PaM");this._publicKeyPromise=Promise.resolve().then((()=>crypto.subtle.importKey("raw",t,{name:"Ed25519"},!1,["verify"]))),this._publicKeyPromise.catch((()=>{this._publicKeyPromise=void 0}))}return this._publicKeyPromise}base64UrlToString(t){return(new TextDecoder).decode(this.base64UrlToBytes(t))}base64UrlToBytes(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.padEnd(e.length+(4-e.length%4)%4,"="),i=atob(n),r=new Uint8Array(new ArrayBuffer(i.length));for(let t=0;t<i.length;t++)r[t]=i.charCodeAt(t);return r}utf8Bytes(t){const e=(new TextEncoder).encode(t),n=new Uint8Array(new ArrayBuffer(e.length));return n.set(e),n}}var Gt;function Ht(t,e,n,i,r,s){const o=s?.quiet??!0,a=e.get("schemaVersion")??0;if(a>=r)return{migrated:!1,fromVersion:a,toVersion:a};const c=i.filter((t=>t.fromVersion>=a&&t.toVersion<=r)).sort(((t,e)=>t.fromVersion-e.fromVersion));return o||console.log(`[Kritzel] Running ${c.length} migration(s) from v${a} to v${r}`),t.transact((()=>{for(const e of c)o||console.log(`[Kritzel] Migrating v${e.fromVersion} → v${e.toVersion}`),e.migrate(t,n);e.set("schemaVersion",r)}),"migration"),o||console.log(`[Kritzel] Migrations complete. Schema now at v${r}`),{migrated:!0,fromVersion:a,toVersion:r}}!function(t){t.StartHorizontal="start-horizontal",t.CenterHorizontal="center-horizontal",t.EndHorizontal="end-horizontal",t.StartVertical="start-vertical",t.CenterVertical="center-vertical",t.EndVertical="end-vertical"}(Gt||(Gt={}));const Xt=[{fromVersion:1,toVersion:2,migrate(t,e){const n=e.workspaces;n&&n.forEach(((t,e)=>{const i=t?.viewport;if(!i)return;if("centerWorldX"in i)return;const r=i.scale??1,s=i.translateX??0,o=i.translateY??0,a={...t,viewport:{centerWorldX:-s/r||0,centerWorldY:-o/r||0,scale:r}};n.set(e,a)}))}}],Yt=[{fromVersion:1,toVersion:2,migrate(t,e){}}],Qt={providers:[]};var Zt,qt,Jt,te={exports:{}},ee=(Zt||(Zt=1,qt=te,Jt=te.exports,function(){var t,e="Expected a function",n="__lodash_hash_undefined__",i="__lodash_placeholder__",r=32,s=128,o=1/0,a=9007199254740991,c=NaN,l=4294967295,h=[["ary",s],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",r],["partialRight",64],["rearg",256]],u="[object Arguments]",f="[object Array]",d="[object Boolean]",p="[object Date]",g="[object Error]",v="[object Function]",w="[object GeneratorFunction]",m="[object Map]",y="[object Number]",b="[object Object]",k="[object Promise]",A="[object RegExp]",x="[object Set]",S="[object String]",M="[object Symbol]",z="[object WeakMap]",$="[object ArrayBuffer]",C="[object DataView]",T="[object Float32Array]",I="[object Float64Array]",j="[object Int8Array]",E="[object Int16Array]",_="[object Int32Array]",L="[object Uint8Array]",O="[object Uint8ClampedArray]",P="[object Uint16Array]",B="[object Uint32Array]",D=/\b__p \+= '';/g,R=/\b(__p \+=) '' \+/g,W=/(__e\(.*?\)|\b__t\)) \+\n'';/g,U=/&(?:amp|lt|gt|quot|#39);/g,F=/[&<>"']/g,K=RegExp(U.source),V=RegExp(F.source),N=/<%-([\s\S]+?)%>/g,G=/<%([\s\S]+?)%>/g,H=/<%=([\s\S]+?)%>/g,Y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Q=/^\w*$/,Z=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,q=/[\\^$.*+?()[\]{}|]/g,J=RegExp(q.source),tt=/^\s+/,et=/\s/,nt=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,it=/\{\n\/\* \[wrapped with (.+)\] \*/,rt=/,? & /,st=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ot=/[()=,{}\[\]\/\s]/,at=/\\(\\)?/g,ct=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,lt=/\w*$/,ht=/^[-+]0x[0-9a-f]+$/i,ut=/^0b[01]+$/i,ft=/^\[object .+?Constructor\]$/,dt=/^0o[0-7]+$/i,pt=/^(?:0|[1-9]\d*)$/,gt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,vt=/($^)/,wt=/['\n\r\u2028\u2029\\]/g,mt="\\ud800-\\udfff",yt="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",bt="\\u2700-\\u27bf",kt="a-z\\xdf-\\xf6\\xf8-\\xff",At="A-Z\\xc0-\\xd6\\xd8-\\xde",xt="\\ufe0e\\ufe0f",St="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Mt="["+mt+"]",zt="["+St+"]",$t="["+yt+"]",Ct="\\d+",Tt="["+bt+"]",It="["+kt+"]",jt="[^"+mt+St+Ct+bt+kt+At+"]",Et="\\ud83c[\\udffb-\\udfff]",_t="[^"+mt+"]",Lt="(?:\\ud83c[\\udde6-\\uddff]){2}",Ot="[\\ud800-\\udbff][\\udc00-\\udfff]",Pt="["+At+"]",Bt="\\u200d",Dt="(?:"+It+"|"+jt+")",Rt="(?:"+Pt+"|"+jt+")",Wt="(?:['’](?:d|ll|m|re|s|t|ve))?",Ut="(?:['’](?:D|LL|M|RE|S|T|VE))?",Ft="(?:"+$t+"|"+Et+")?",Kt="["+xt+"]?",Vt=Kt+Ft+"(?:"+Bt+"(?:"+[_t,Lt,Ot].join("|")+")"+Kt+Ft+")*",Nt="(?:"+[Tt,Lt,Ot].join("|")+")"+Vt,Gt="(?:"+[_t+$t+"?",$t,Lt,Ot,Mt].join("|")+")",Ht=RegExp("['’]","g"),Xt=RegExp($t,"g"),Yt=RegExp(Et+"(?="+Et+")|"+Gt+Vt,"g"),Qt=RegExp([Pt+"?"+It+"+"+Wt+"(?="+[zt,Pt,"$"].join("|")+")",Rt+"+"+Ut+"(?="+[zt,Pt+Dt,"$"].join("|")+")",Pt+"?"+Dt+"+"+Wt,Pt+"+"+Ut,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ct,Nt].join("|"),"g"),Zt=RegExp("["+Bt+mt+yt+xt+"]"),te=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,ee=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],ne=-1,ie={};ie[T]=ie[I]=ie[j]=ie[E]=ie[_]=ie[L]=ie[O]=ie[P]=ie[B]=!0,ie[u]=ie[f]=ie[$]=ie[d]=ie[C]=ie[p]=ie[g]=ie[v]=ie[m]=ie[y]=ie[b]=ie[A]=ie[x]=ie[S]=ie[z]=!1;var re={};re[u]=re[f]=re[$]=re[C]=re[d]=re[p]=re[T]=re[I]=re[j]=re[E]=re[_]=re[m]=re[y]=re[b]=re[A]=re[x]=re[S]=re[M]=re[L]=re[O]=re[P]=re[B]=!0,re[g]=re[v]=re[z]=!1;var se={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},oe=parseFloat,ae=parseInt,ce="object"==typeof X&&X&&X.Object===Object&&X,le="object"==typeof self&&self&&self.Object===Object&&self,he=ce||le||Function("return this")(),ue=Jt&&!Jt.nodeType&&Jt,fe=ue&&qt&&!qt.nodeType&&qt,de=fe&&fe.exports===ue,pe=de&&ce.process,ge=function(){try{return fe&&fe.require&&fe.require("util").types||pe&&pe.binding&&pe.binding("util")}catch(t){}}(),ve=ge&&ge.isArrayBuffer,we=ge&&ge.isDate,me=ge&&ge.isMap,ye=ge&&ge.isRegExp,be=ge&&ge.isSet,ke=ge&&ge.isTypedArray;function Ae(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}function xe(t,e,n,i){for(var r=-1,s=null==t?0:t.length;++r<s;){var o=t[r];e(i,o,n(o),t)}return i}function Se(t,e){for(var n=-1,i=null==t?0:t.length;++n<i&&!1!==e(t[n],n,t););return t}function Me(t,e){for(var n=null==t?0:t.length;n--&&!1!==e(t[n],n,t););return t}function ze(t,e){for(var n=-1,i=null==t?0:t.length;++n<i;)if(!e(t[n],n,t))return!1;return!0}function $e(t,e){for(var n=-1,i=null==t?0:t.length,r=0,s=[];++n<i;){var o=t[n];e(o,n,t)&&(s[r++]=o)}return s}function Ce(t,e){return!(null==t||!t.length)&&De(t,e,0)>-1}function Te(t,e,n){for(var i=-1,r=null==t?0:t.length;++i<r;)if(n(e,t[i]))return!0;return!1}function Ie(t,e){for(var n=-1,i=null==t?0:t.length,r=Array(i);++n<i;)r[n]=e(t[n],n,t);return r}function je(t,e){for(var n=-1,i=e.length,r=t.length;++n<i;)t[r+n]=e[n];return t}function Ee(t,e,n,i){var r=-1,s=null==t?0:t.length;for(i&&s&&(n=t[++r]);++r<s;)n=e(n,t[r],r,t);return n}function _e(t,e,n,i){var r=null==t?0:t.length;for(i&&r&&(n=t[--r]);r--;)n=e(n,t[r],r,t);return n}function Le(t,e){for(var n=-1,i=null==t?0:t.length;++n<i;)if(e(t[n],n,t))return!0;return!1}var Oe=Fe("length");function Pe(t,e,n){var i;return n(t,(function(t,n,r){if(e(t,n,r))return i=n,!1})),i}function Be(t,e,n,i){for(var r=t.length,s=n+(i?1:-1);i?s--:++s<r;)if(e(t[s],s,t))return s;return-1}function De(t,e,n){return e==e?function(t,e,n){for(var i=n-1,r=t.length;++i<r;)if(t[i]===e)return i;return-1}(t,e,n):Be(t,We,n)}function Re(t,e,n,i){for(var r=n-1,s=t.length;++r<s;)if(i(t[r],e))return r;return-1}function We(t){return t!=t}function Ue(t,e){var n=null==t?0:t.length;return n?Ne(t,e)/n:c}function Fe(e){return function(n){return null==n?t:n[e]}}function Ke(e){return function(n){return null==e?t:e[n]}}function Ve(t,e,n,i,r){return r(t,(function(t,r,s){n=i?(i=!1,t):e(n,t,r,s)})),n}function Ne(e,n){for(var i,r=-1,s=e.length;++r<s;){var o=n(e[r]);o!==t&&(i=i===t?o:i+o)}return i}function Ge(t,e){for(var n=-1,i=Array(t);++n<t;)i[n]=e(n);return i}function He(t){return t?t.slice(0,un(t)+1).replace(tt,""):t}function Xe(t){return function(e){return t(e)}}function Ye(t,e){return Ie(e,(function(e){return t[e]}))}function Qe(t,e){return t.has(e)}function Ze(t,e){for(var n=-1,i=t.length;++n<i&&De(e,t[n],0)>-1;);return n}function qe(t,e){for(var n=t.length;n--&&De(e,t[n],0)>-1;);return n}var Je=Ke({À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"}),tn=Ke({"&":"&","<":"<",">":">",'"':""","'":"'"});function en(t){return"\\"+se[t]}function nn(t){return Zt.test(t)}function rn(t){var e=-1,n=Array(t.size);return t.forEach((function(t,i){n[++e]=[i,t]})),n}function sn(t,e){return function(n){return t(e(n))}}function on(t,e){for(var n=-1,r=t.length,s=0,o=[];++n<r;){var a=t[n];a!==e&&a!==i||(t[n]=i,o[s++]=n)}return o}function an(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=t})),n}function cn(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=[t,t]})),n}function ln(t){return nn(t)?function(t){for(var e=Yt.lastIndex=0;Yt.test(t);)++e;return e}(t):Oe(t)}function hn(t){return nn(t)?function(t){return t.match(Yt)||[]}(t):function(t){return t.split("")}(t)}function un(t){for(var e=t.length;e--&&et.test(t.charAt(e)););return e}var fn=Ke({"&":"&","<":"<",">":">",""":'"',"'":"'"}),dn=function X(et){var mt,yt=(et=null==et?he:dn.defaults(he.Object(),et,dn.pick(he,ee))).Array,bt=et.Date,kt=et.Error,At=et.Function,xt=et.Math,St=et.Object,Mt=et.RegExp,zt=et.String,$t=et.TypeError,Ct=yt.prototype,Tt=St.prototype,It=et["__core-js_shared__"],jt=At.prototype.toString,Et=Tt.hasOwnProperty,_t=0,Lt=(mt=/[^.]+$/.exec(It&&It.keys&&It.keys.IE_PROTO||""))?"Symbol(src)_1."+mt:"",Ot=Tt.toString,Pt=jt.call(St),Bt=he._,Dt=Mt("^"+jt.call(Et).replace(q,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Rt=de?et.Buffer:t,Wt=et.Symbol,Ut=et.Uint8Array,Ft=Rt?Rt.allocUnsafe:t,Kt=sn(St.getPrototypeOf,St),Vt=St.create,Nt=Tt.propertyIsEnumerable,Gt=Ct.splice,Yt=Wt?Wt.isConcatSpreadable:t,Zt=Wt?Wt.iterator:t,qt=Wt?Wt.toStringTag:t,Jt=function(){try{var t=as(St,"defineProperty");return t({},"",{}),t}catch(t){}}(),se=et.clearTimeout!==he.clearTimeout&&et.clearTimeout,ce=bt&&bt.now!==he.Date.now&&bt.now,le=et.setTimeout!==he.setTimeout&&et.setTimeout,ue=xt.ceil,fe=xt.floor,pe=St.getOwnPropertySymbols,ge=Rt?Rt.isBuffer:t,Oe=et.isFinite,Ke=Ct.join,pn=sn(St.keys,St),gn=xt.max,vn=xt.min,wn=bt.now,mn=et.parseInt,yn=xt.random,bn=Ct.reverse,kn=as(et,"DataView"),An=as(et,"Map"),xn=as(et,"Promise"),Sn=as(et,"Set"),Mn=as(et,"WeakMap"),zn=as(St,"create"),$n=Mn&&new Mn,Cn={},Tn=_s(kn),In=_s(An),jn=_s(xn),En=_s(Sn),_n=_s(Mn),Ln=Wt?Wt.prototype:t,On=Ln?Ln.valueOf:t,Pn=Ln?Ln.toString:t;function Bn(t){if(Zo(t)&&!Wo(t)&&!(t instanceof Un)){if(t instanceof Wn)return t;if(Et.call(t,"__wrapped__"))return Ls(t)}return new Wn(t)}var Dn=function(){function e(){}return function(n){if(!Qo(n))return{};if(Vt)return Vt(n);e.prototype=n;var i=new e;return e.prototype=t,i}}();function Rn(){}function Wn(e,n){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!n,this.__index__=0,this.__values__=t}function Un(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=l,this.__views__=[]}function Fn(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function Kn(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function Vn(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function Nn(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new Vn;++e<n;)this.add(t[e])}function Gn(t){var e=this.__data__=new Kn(t);this.size=e.size}function Hn(t,e){var n=Wo(t),i=!n&&Ro(t),r=!n&&!i&&Vo(t),s=!n&&!i&&!r&&sa(t),o=n||i||r||s,a=o?Ge(t.length,zt):[],c=a.length;for(var l in t)!e&&!Et.call(t,l)||o&&("length"==l||r&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||ps(l,c))||a.push(l);return a}function Xn(e){var n=e.length;return n?e[Vi(0,n-1)]:t}function Yn(t,e){return Is(Mr(t),ri(e,0,t.length))}function Qn(t){return Is(Mr(t))}function Zn(e,n,i){(i!==t&&!Po(e[n],i)||i===t&&!(n in e))&&ni(e,n,i)}function qn(e,n,i){var r=e[n];Et.call(e,n)&&Po(r,i)&&(i!==t||n in e)||ni(e,n,i)}function Jn(t,e){for(var n=t.length;n--;)if(Po(t[n][0],e))return n;return-1}function ti(t,e,n,i){return li(t,(function(t,r,s){e(i,t,n(t),s)})),i}function ei(t,e){return t&&zr(e,$a(e),t)}function ni(t,e,n){"__proto__"==e&&Jt?Jt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}function ii(e,n){for(var i=-1,r=n.length,s=yt(r),o=null==e;++i<r;)s[i]=o?t:Aa(e,n[i]);return s}function ri(e,n,i){return e==e&&(i!==t&&(e=e<=i?e:i),n!==t&&(e=e>=n?e:n)),e}function si(e,n,i,r,s,o){var a,c=1&n,l=2&n,h=4&n;if(i&&(a=s?i(e,r,s,o):i(e)),a!==t)return a;if(!Qo(e))return e;var f=Wo(e);if(f){if(a=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&Et.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(e),!c)return Mr(e,a)}else{var g=hs(e),k=g==v||g==w;if(Vo(e))return yr(e,c);if(g==b||g==u||k&&!s){if(a=l||k?{}:fs(e),!c)return l?function(t,e){return zr(t,ls(t),e)}(e,function(t,e){return t&&zr(e,Ca(e),t)}(a,e)):function(t,e){return zr(t,cs(t),e)}(e,ei(a,e))}else{if(!re[g])return s?e:{};a=function(t,e,n){var i=t.constructor;switch(e){case $:return br(t);case d:case p:return new i(+t);case C:return function(t,e){var n=e?br(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,n);case T:case I:case j:case E:case _:case L:case O:case P:case B:return kr(t,n);case m:return new i;case y:case S:return new i(t);case A:return function(t){var e=new t.constructor(t.source,lt.exec(t));return e.lastIndex=t.lastIndex,e}(t);case x:return new i;case M:return On?St(On.call(t)):{}}}(e,g,c)}}o||(o=new Gn);var z=o.get(e);if(z)return z;o.set(e,a),na(e)?e.forEach((function(t){a.add(si(t,n,i,t,e,o))})):qo(e)&&e.forEach((function(t,r){a.set(r,si(t,n,i,r,e,o))}));var D=f?t:(h?l?ts:Jr:l?Ca:$a)(e);return Se(D||e,(function(t,r){D&&(t=e[r=t]),qn(a,r,si(t,n,i,r,e,o))})),a}function oi(e,n,i){var r=i.length;if(null==e)return!r;for(e=St(e);r--;){var s=i[r],o=e[s];if(o===t&&!(s in e)||!(0,n[s])(o))return!1}return!0}function ai(n,i,r){if("function"!=typeof n)throw new $t(e);return zs((function(){n.apply(t,r)}),i)}function ci(t,e,n,i){var r=-1,s=Ce,o=!0,a=t.length,c=[],l=e.length;if(!a)return c;n&&(e=Ie(e,Xe(n))),i?(s=Te,o=!1):e.length>=200&&(s=Qe,o=!1,e=new Nn(e));t:for(;++r<a;){var h=t[r],u=null==n?h:n(h);if(h=i||0!==h?h:0,o&&u==u){for(var f=l;f--;)if(e[f]===u)continue t;c.push(h)}else s(e,u,i)||c.push(h)}return c}Bn.templateSettings={escape:N,evaluate:G,interpolate:H,variable:"",imports:{_:Bn}},(Bn.prototype=Rn.prototype).constructor=Bn,(Wn.prototype=Dn(Rn.prototype)).constructor=Wn,(Un.prototype=Dn(Rn.prototype)).constructor=Un,Fn.prototype.clear=function(){this.__data__=zn?zn(null):{},this.size=0},Fn.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Fn.prototype.get=function(e){var i=this.__data__;if(zn){var r=i[e];return r===n?t:r}return Et.call(i,e)?i[e]:t},Fn.prototype.has=function(e){var n=this.__data__;return zn?n[e]!==t:Et.call(n,e)},Fn.prototype.set=function(e,i){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=zn&&i===t?n:i,this},Kn.prototype.clear=function(){this.__data__=[],this.size=0},Kn.prototype.delete=function(t){var e=this.__data__,n=Jn(e,t);return!(n<0||(n==e.length-1?e.pop():Gt.call(e,n,1),--this.size,0))},Kn.prototype.get=function(e){var n=this.__data__,i=Jn(n,e);return i<0?t:n[i][1]},Kn.prototype.has=function(t){return Jn(this.__data__,t)>-1},Kn.prototype.set=function(t,e){var n=this.__data__,i=Jn(n,t);return i<0?(++this.size,n.push([t,e])):n[i][1]=e,this},Vn.prototype.clear=function(){this.size=0,this.__data__={hash:new Fn,map:new(An||Kn),string:new Fn}},Vn.prototype.delete=function(t){var e=ss(this,t).delete(t);return this.size-=e?1:0,e},Vn.prototype.get=function(t){return ss(this,t).get(t)},Vn.prototype.has=function(t){return ss(this,t).has(t)},Vn.prototype.set=function(t,e){var n=ss(this,t),i=n.size;return n.set(t,e),this.size+=n.size==i?0:1,this},Nn.prototype.add=Nn.prototype.push=function(t){return this.__data__.set(t,n),this},Nn.prototype.has=function(t){return this.__data__.has(t)},Gn.prototype.clear=function(){this.__data__=new Kn,this.size=0},Gn.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},Gn.prototype.get=function(t){return this.__data__.get(t)},Gn.prototype.has=function(t){return this.__data__.has(t)},Gn.prototype.set=function(t,e){var n=this.__data__;if(n instanceof Kn){var i=n.__data__;if(!An||i.length<199)return i.push([t,e]),this.size=++n.size,this;n=this.__data__=new Vn(i)}return n.set(t,e),this.size=n.size,this};var li=Tr(wi),hi=Tr(mi,!0);function ui(t,e){var n=!0;return li(t,(function(t,i,r){return n=!!e(t,i,r)})),n}function fi(e,n,i){for(var r=-1,s=e.length;++r<s;){var o=e[r],a=n(o);if(null!=a&&(c===t?a==a&&!ra(a):i(a,c)))var c=a,l=o}return l}function di(t,e){var n=[];return li(t,(function(t,i,r){e(t,i,r)&&n.push(t)})),n}function pi(t,e,n,i,r){var s=-1,o=t.length;for(n||(n=ds),r||(r=[]);++s<o;){var a=t[s];e>0&&n(a)?e>1?pi(a,e-1,n,i,r):je(r,a):i||(r[r.length]=a)}return r}var gi=Ir(),vi=Ir(!0);function wi(t,e){return t&&gi(t,e,$a)}function mi(t,e){return t&&vi(t,e,$a)}function yi(t,e){return $e(e,(function(e){return Ho(t[e])}))}function bi(e,n){for(var i=0,r=(n=gr(n,e)).length;null!=e&&i<r;)e=e[Es(n[i++])];return i&&i==r?e:t}function ki(t,e,n){var i=e(t);return Wo(t)?i:je(i,n(t))}function Ai(e){return null==e?e===t?"[object Undefined]":"[object Null]":qt&&qt in St(e)?function(e){var n=Et.call(e,qt),i=e[qt];try{e[qt]=t;var r=!0}catch(t){}var s=Ot.call(e);return r&&(n?e[qt]=i:delete e[qt]),s}(e):function(t){return Ot.call(t)}(e)}function xi(t,e){return t>e}function Si(t,e){return null!=t&&Et.call(t,e)}function Mi(t,e){return null!=t&&e in St(t)}function zi(e,n,i){for(var r=i?Te:Ce,s=e[0].length,o=e.length,a=o,c=yt(o),l=1/0,h=[];a--;){var u=e[a];a&&n&&(u=Ie(u,Xe(n))),l=vn(u.length,l),c[a]=!i&&(n||s>=120&&u.length>=120)?new Nn(a&&u):t}u=e[0];var f=-1,d=c[0];t:for(;++f<s&&h.length<l;){var p=u[f],g=n?n(p):p;if(p=i||0!==p?p:0,!(d?Qe(d,g):r(h,g,i))){for(a=o;--a;){var v=c[a];if(!(v?Qe(v,g):r(e[a],g,i)))continue t}d&&d.push(g),h.push(p)}}return h}function $i(e,n,i){var r=null==(e=xs(e,n=gr(n,e)))?e:e[Es(Ns(n))];return null==r?t:Ae(r,e,i)}function Ci(t){return Zo(t)&&Ai(t)==u}function Ti(e,n,i,r,s){return e===n||(null==e||null==n||!Zo(e)&&!Zo(n)?e!=e&&n!=n:function(e,n,i,r,s,o){var a=Wo(e),c=Wo(n),l=a?f:hs(e),h=c?f:hs(n),v=(l=l==u?b:l)==b,w=(h=h==u?b:h)==b,k=l==h;if(k&&Vo(e)){if(!Vo(n))return!1;a=!0,v=!1}if(k&&!v)return o||(o=new Gn),a||sa(e)?Zr(e,n,i,r,s,o):function(t,e,n,i,r,s,o){switch(n){case C:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case $:return!(t.byteLength!=e.byteLength||!s(new Ut(t),new Ut(e)));case d:case p:case y:return Po(+t,+e);case g:return t.name==e.name&&t.message==e.message;case A:case S:return t==e+"";case m:var a=rn;case x:if(a||(a=an),t.size!=e.size&&!(1&i))return!1;var c=o.get(t);if(c)return c==e;i|=2,o.set(t,e);var l=Zr(a(t),a(e),i,r,s,o);return o.delete(t),l;case M:if(On)return On.call(t)==On.call(e)}return!1}(e,n,l,i,r,s,o);if(!(1&i)){var z=v&&Et.call(e,"__wrapped__"),T=w&&Et.call(n,"__wrapped__");if(z||T){var I=z?e.value():e,j=T?n.value():n;return o||(o=new Gn),s(I,j,i,r,o)}}return!!k&&(o||(o=new Gn),function(e,n,i,r,s,o){var a=1&i,c=Jr(e),l=c.length;if(l!=Jr(n).length&&!a)return!1;for(var h=l;h--;){var u=c[h];if(!(a?u in n:Et.call(n,u)))return!1}var f=o.get(e),d=o.get(n);if(f&&d)return f==n&&d==e;var p=!0;o.set(e,n),o.set(n,e);for(var g=a;++h<l;){var v=e[u=c[h]],w=n[u];if(r)var m=a?r(w,v,u,n,e,o):r(v,w,u,e,n,o);if(!(m===t?v===w||s(v,w,i,r,o):m)){p=!1;break}g||(g="constructor"==u)}if(p&&!g){var y=e.constructor,b=n.constructor;y==b||!("constructor"in e)||!("constructor"in n)||"function"==typeof y&&y instanceof y&&"function"==typeof b&&b instanceof b||(p=!1)}return o.delete(e),o.delete(n),p}(e,n,i,r,s,o))}(e,n,i,r,Ti,s))}function Ii(e,n,i,r){var s=i.length,o=s,a=!r;if(null==e)return!o;for(e=St(e);s--;){var c=i[s];if(a&&c[2]?c[1]!==e[c[0]]:!(c[0]in e))return!1}for(;++s<o;){var l=(c=i[s])[0],h=e[l],u=c[1];if(a&&c[2]){if(h===t&&!(l in e))return!1}else{var f=new Gn;if(r)var d=r(h,u,l,e,n,f);if(!(d===t?Ti(u,h,3,r,f):d))return!1}}return!0}function ji(t){return!(!Qo(t)||(e=t,Lt&&Lt in e))&&(Ho(t)?Dt:ft).test(_s(t));var e}function Ei(t){return"function"==typeof t?t:null==t?Ja:"object"==typeof t?Wo(t)?Bi(t[0],t[1]):Pi(t):cc(t)}function _i(t){if(!ys(t))return pn(t);var e=[];for(var n in St(t))Et.call(t,n)&&"constructor"!=n&&e.push(n);return e}function Li(t,e){return t<e}function Oi(t,e){var n=-1,i=Fo(t)?yt(t.length):[];return li(t,(function(t,r,s){i[++n]=e(t,r,s)})),i}function Pi(t){var e=os(t);return 1==e.length&&e[0][2]?ks(e[0][0],e[0][1]):function(n){return n===t||Ii(n,t,e)}}function Bi(e,n){return vs(e)&&bs(n)?ks(Es(e),n):function(i){var r=Aa(i,e);return r===t&&r===n?xa(i,e):Ti(n,r,3)}}function Di(e,n,i,r,s){e!==n&&gi(n,(function(o,a){if(s||(s=new Gn),Qo(o))!function(e,n,i,r,s,o,a){var c=Ss(e,i),l=Ss(n,i),h=a.get(l);if(h)Zn(e,i,h);else{var u=o?o(c,l,i+"",e,n,a):t,f=u===t;if(f){var d=Wo(l),p=!d&&Vo(l),g=!d&&!p&&sa(l);u=l,d||p||g?Wo(c)?u=c:Ko(c)?u=Mr(c):p?(f=!1,u=yr(l,!0)):g?(f=!1,u=kr(l,!0)):u=[]:ta(l)||Ro(l)?(u=c,Ro(c)?u=da(c):Qo(c)&&!Ho(c)||(u=fs(l))):f=!1}f&&(a.set(l,u),s(u,l,r,o,a),a.delete(l)),Zn(e,i,u)}}(e,n,a,i,Di,r,s);else{var c=r?r(Ss(e,a),o,a+"",e,n,s):t;c===t&&(c=o),Zn(e,a,c)}}),Ca)}function Ri(e,n){var i=e.length;if(i)return ps(n+=n<0?i:0,i)?e[n]:t}function Wi(t,e,n){e=e.length?Ie(e,(function(t){return Wo(t)?function(e){return bi(e,1===t.length?t[0]:t)}:t})):[Ja];var i=-1;e=Ie(e,Xe(rs()));var r=Oi(t,(function(t){var n=Ie(e,(function(e){return e(t)}));return{criteria:n,index:++i,value:t}}));return function(t){var e=t.length;for(t.sort((function(t,e){return function(t,e,n){for(var i=-1,r=t.criteria,s=e.criteria,o=r.length,a=n.length;++i<o;){var c=Ar(r[i],s[i]);if(c)return i>=a?c:c*("desc"==n[i]?-1:1)}return t.index-e.index}(t,e,n)}));e--;)t[e]=t[e].value;return t}(r)}function Ui(t,e,n){for(var i=-1,r=e.length,s={};++i<r;){var o=e[i],a=bi(t,o);n(a,o)&&Yi(s,gr(o,t),a)}return s}function Fi(t,e,n,i){var r=i?Re:De,s=-1,o=e.length,a=t;for(t===e&&(e=Mr(e)),n&&(a=Ie(t,Xe(n)));++s<o;)for(var c=0,l=e[s],h=n?n(l):l;(c=r(a,h,c,i))>-1;)a!==t&&Gt.call(a,c,1),Gt.call(t,c,1);return t}function Ki(t,e){for(var n=t?e.length:0,i=n-1;n--;){var r=e[n];if(n==i||r!==s){var s=r;ps(r)?Gt.call(t,r,1):ar(t,r)}}return t}function Vi(t,e){return t+fe(yn()*(e-t+1))}function Ni(t,e){var n="";if(!t||e<1||e>a)return n;do{e%2&&(n+=t),(e=fe(e/2))&&(t+=t)}while(e);return n}function Gi(t,e){return $s(As(t,e,Ja),t+"")}function Hi(t){return Xn(Pa(t))}function Xi(t,e){var n=Pa(t);return Is(n,ri(e,0,n.length))}function Yi(e,n,i,r){if(!Qo(e))return e;for(var s=-1,o=(n=gr(n,e)).length,a=o-1,c=e;null!=c&&++s<o;){var l=Es(n[s]),h=i;if("__proto__"===l||"constructor"===l||"prototype"===l)return e;if(s!=a){var u=c[l];(h=r?r(u,l,c):t)===t&&(h=Qo(u)?u:ps(n[s+1])?[]:{})}qn(c,l,h),c=c[l]}return e}var Qi=$n?function(t,e){return $n.set(t,e),t}:Ja,Zi=Jt?function(t,e){return Jt(t,"toString",{configurable:!0,enumerable:!1,value:Qa(e),writable:!0})}:Ja;function qi(t){return Is(Pa(t))}function Ji(t,e,n){var i=-1,r=t.length;e<0&&(e=-e>r?0:r+e),(n=n>r?r:n)<0&&(n+=r),r=e>n?0:n-e>>>0,e>>>=0;for(var s=yt(r);++i<r;)s[i]=t[i+e];return s}function tr(t,e){var n;return li(t,(function(t,i,r){return!(n=e(t,i,r))})),!!n}function er(t,e,n){var i=0,r=null==t?i:t.length;if("number"==typeof e&&e==e&&r<=2147483647){for(;i<r;){var s=i+r>>>1,o=t[s];null!==o&&!ra(o)&&(n?o<=e:o<e)?i=s+1:r=s}return r}return nr(t,e,Ja,n)}function nr(e,n,i,r){var s=0,o=null==e?0:e.length;if(0===o)return 0;for(var a=(n=i(n))!=n,c=null===n,l=ra(n),h=n===t;s<o;){var u=fe((s+o)/2),f=i(e[u]),d=f!==t,p=null===f,g=f==f,v=ra(f);if(a)var w=r||g;else w=h?g&&(r||d):c?g&&d&&(r||!p):l?g&&d&&!p&&(r||!v):!p&&!v&&(r?f<=n:f<n);w?s=u+1:o=u}return vn(o,4294967294)}function ir(t,e){for(var n=-1,i=t.length,r=0,s=[];++n<i;){var o=t[n],a=e?e(o):o;if(!n||!Po(a,c)){var c=a;s[r++]=0===o?0:o}}return s}function rr(t){return"number"==typeof t?t:ra(t)?c:+t}function sr(t){if("string"==typeof t)return t;if(Wo(t))return Ie(t,sr)+"";if(ra(t))return Pn?Pn.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function or(t,e,n){var i=-1,r=Ce,s=t.length,o=!0,a=[],c=a;if(n)o=!1,r=Te;else if(s>=200){var l=e?null:Nr(t);if(l)return an(l);o=!1,r=Qe,c=new Nn}else c=e?[]:a;t:for(;++i<s;){var h=t[i],u=e?e(h):h;if(h=n||0!==h?h:0,o&&u==u){for(var f=c.length;f--;)if(c[f]===u)continue t;e&&c.push(u),a.push(h)}else r(c,u,n)||(c!==a&&c.push(u),a.push(h))}return a}function ar(t,e){var n=-1,i=(e=gr(e,t)).length;if(!i)return!0;for(;++n<i;){var r=Es(e[n]);if("__proto__"===r&&!Et.call(t,"__proto__"))return!1;if(("constructor"===r||"prototype"===r)&&n<i-1)return!1}var s=xs(t,e);return null==s||delete s[Es(Ns(e))]}function cr(t,e,n,i){return Yi(t,e,n(bi(t,e)),i)}function lr(t,e,n,i){for(var r=t.length,s=i?r:-1;(i?s--:++s<r)&&e(t[s],s,t););return n?Ji(t,i?0:s,i?s+1:r):Ji(t,i?s+1:0,i?r:s)}function hr(t,e){var n=t;return n instanceof Un&&(n=n.value()),Ee(e,(function(t,e){return e.func.apply(e.thisArg,je([t],e.args))}),n)}function ur(t,e,n){var i=t.length;if(i<2)return i?or(t[0]):[];for(var r=-1,s=yt(i);++r<i;)for(var o=t[r],a=-1;++a<i;)a!=r&&(s[r]=ci(s[r]||o,t[a],e,n));return or(pi(s,1),e,n)}function fr(e,n,i){for(var r=-1,s=e.length,o=n.length,a={};++r<s;)i(a,e[r],r<o?n[r]:t);return a}function dr(t){return Ko(t)?t:[]}function pr(t){return"function"==typeof t?t:Ja}function gr(t,e){return Wo(t)?t:vs(t,e)?[t]:js(pa(t))}var vr=Gi;function wr(e,n,i){var r=e.length;return i=i===t?r:i,!n&&i>=r?e:Ji(e,n,i)}var mr=se||function(t){return he.clearTimeout(t)};function yr(t,e){if(e)return t.slice();var n=t.length,i=Ft?Ft(n):new t.constructor(n);return t.copy(i),i}function br(t){var e=new t.constructor(t.byteLength);return new Ut(e).set(new Ut(t)),e}function kr(t,e){var n=e?br(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}function Ar(e,n){if(e!==n){var i=e!==t,r=null===e,s=e==e,o=ra(e),a=n!==t,c=null===n,l=n==n,h=ra(n);if(!c&&!h&&!o&&e>n||o&&a&&l&&!c&&!h||r&&a&&l||!i&&l||!s)return 1;if(!r&&!o&&!h&&e<n||h&&i&&s&&!r&&!o||c&&i&&s||!a&&s||!l)return-1}return 0}function xr(t,e,n,i){for(var r=-1,s=t.length,o=n.length,a=-1,c=e.length,l=gn(s-o,0),h=yt(c+l),u=!i;++a<c;)h[a]=e[a];for(;++r<o;)(u||r<s)&&(h[n[r]]=t[r]);for(;l--;)h[a++]=t[r++];return h}function Sr(t,e,n,i){for(var r=-1,s=t.length,o=-1,a=n.length,c=-1,l=e.length,h=gn(s-a,0),u=yt(h+l),f=!i;++r<h;)u[r]=t[r];for(var d=r;++c<l;)u[d+c]=e[c];for(;++o<a;)(f||r<s)&&(u[d+n[o]]=t[r++]);return u}function Mr(t,e){var n=-1,i=t.length;for(e||(e=yt(i));++n<i;)e[n]=t[n];return e}function zr(e,n,i,r){var s=!i;i||(i={});for(var o=-1,a=n.length;++o<a;){var c=n[o],l=r?r(i[c],e[c],c,i,e):t;l===t&&(l=e[c]),s?ni(i,c,l):qn(i,c,l)}return i}function $r(t,e){return function(n,i){var r=Wo(n)?xe:ti,s=e?e():{};return r(n,t,rs(i,2),s)}}function Cr(e){return Gi((function(n,i){var r=-1,s=i.length,o=s>1?i[s-1]:t,a=s>2?i[2]:t;for(o=e.length>3&&"function"==typeof o?(s--,o):t,a&&gs(i[0],i[1],a)&&(o=s<3?t:o,s=1),n=St(n);++r<s;){var c=i[r];c&&e(n,c,r,o)}return n}))}function Tr(t,e){return function(n,i){if(null==n)return n;if(!Fo(n))return t(n,i);for(var r=n.length,s=e?r:-1,o=St(n);(e?s--:++s<r)&&!1!==i(o[s],s,o););return n}}function Ir(t){return function(e,n,i){for(var r=-1,s=St(e),o=i(e),a=o.length;a--;){var c=o[t?a:++r];if(!1===n(s[c],c,s))break}return e}}function jr(e){return function(n){var i=nn(n=pa(n))?hn(n):t,r=i?i[0]:n.charAt(0),s=i?wr(i,1).join(""):n.slice(1);return r[e]()+s}}function Er(t){return function(e){return Ee(Ha(Ra(e).replace(Ht,"")),t,"")}}function _r(t){return function(){var e=arguments;switch(e.length){case 0:return new t;case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3]);case 5:return new t(e[0],e[1],e[2],e[3],e[4]);case 6:return new t(e[0],e[1],e[2],e[3],e[4],e[5]);case 7:return new t(e[0],e[1],e[2],e[3],e[4],e[5],e[6])}var n=Dn(t.prototype),i=t.apply(n,e);return Qo(i)?i:n}}function Lr(e){return function(n,i,r){var s=St(n);if(!Fo(n)){var o=rs(i,3);n=$a(n),i=function(t){return o(s[t],t,s)}}var a=e(n,i,r);return a>-1?s[o?n[a]:a]:t}}function Or(n){return qr((function(i){var r=i.length,s=r,o=Wn.prototype.thru;for(n&&i.reverse();s--;){var a=i[s];if("function"!=typeof a)throw new $t(e);if(o&&!c&&"wrapper"==ns(a))var c=new Wn([],!0)}for(s=c?s:r;++s<r;){var l=ns(a=i[s]),h="wrapper"==l?es(a):t;c=h&&ws(h[0])&&424==h[1]&&!h[4].length&&1==h[9]?c[ns(h[0])].apply(c,h[3]):1==a.length&&ws(a)?c[l]():c.thru(a)}return function(){var t=arguments,e=t[0];if(c&&1==t.length&&Wo(e))return c.plant(e).value();for(var n=0,s=r?i[n].apply(this,t):e;++n<r;)s=i[n].call(this,s);return s}}))}function Pr(e,n,i,r,o,a,c,l,h,u){var f=n&s,d=1&n,p=2&n,g=24&n,v=512&n,w=p?t:_r(e);return function s(){for(var m=arguments.length,y=yt(m),b=m;b--;)y[b]=arguments[b];if(g)var k=is(s),A=function(t,e){for(var n=t.length,i=0;n--;)t[n]===e&&++i;return i}(y,k);if(r&&(y=xr(y,r,o,g)),a&&(y=Sr(y,a,c,g)),m-=A,g&&m<u){var x=on(y,k);return Kr(e,n,Pr,s.placeholder,i,y,x,l,h,u-m)}var S=d?i:this,M=p?S[e]:e;return m=y.length,l?y=function(e,n){for(var i=e.length,r=vn(n.length,i),s=Mr(e);r--;){var o=n[r];e[r]=ps(o,i)?s[o]:t}return e}(y,l):v&&m>1&&y.reverse(),f&&h<m&&(y.length=h),this&&this!==he&&this instanceof s&&(M=w||_r(M)),M.apply(S,y)}}function Br(t,e){return function(n,i){return function(t,e,n,i){return wi(t,(function(t,r,s){e(i,n(t),r,s)})),i}(n,t,e(i),{})}}function Dr(e,n){return function(i,r){var s;if(i===t&&r===t)return n;if(i!==t&&(s=i),r!==t){if(s===t)return r;"string"==typeof i||"string"==typeof r?(i=sr(i),r=sr(r)):(i=rr(i),r=rr(r)),s=e(i,r)}return s}}function Rr(t){return qr((function(e){return e=Ie(e,Xe(rs())),Gi((function(n){var i=this;return t(e,(function(t){return Ae(t,i,n)}))}))}))}function Wr(e,n){var i=(n=n===t?" ":sr(n)).length;if(i<2)return i?Ni(n,e):n;var r=Ni(n,ue(e/ln(n)));return nn(n)?wr(hn(r),0,e).join(""):r.slice(0,e)}function Ur(e){return function(n,i,r){return r&&"number"!=typeof r&&gs(n,i,r)&&(i=r=t),n=la(n),i===t?(i=n,n=0):i=la(i),function(t,e,n,i){for(var r=-1,s=gn(ue((e-t)/(n||1)),0),o=yt(s);s--;)o[i?s:++r]=t,t+=n;return o}(n,i,r=r===t?n<i?1:-1:la(r),e)}}function Fr(t){return function(e,n){return"string"==typeof e&&"string"==typeof n||(e=fa(e),n=fa(n)),t(e,n)}}function Kr(e,n,i,s,o,a,c,l,h,u){var f=8&n;n|=f?r:64,4&(n&=~(f?64:r))||(n&=-4);var d=[e,n,o,f?a:t,f?c:t,f?t:a,f?t:c,l,h,u],p=i.apply(t,d);return ws(e)&&Ms(p,d),p.placeholder=s,Cs(p,e,n)}function Vr(t){var e=xt[t];return function(t,n){if(t=fa(t),(n=null==n?0:vn(ha(n),292))&&Oe(t)){var i=(pa(t)+"e").split("e");return+((i=(pa(e(i[0]+"e"+(+i[1]+n)))+"e").split("e"))[0]+"e"+(+i[1]-n))}return e(t)}}var Nr=Sn&&1/an(new Sn([,-0]))[1]==o?function(t){return new Sn(t)}:rc;function Gr(t){return function(e){var n=hs(e);return n==m?rn(e):n==x?cn(e):function(t,e){return Ie(e,(function(e){return[e,t[e]]}))}(e,t(e))}}function Hr(n,o,a,c,l,h,u,f){var d=2&o;if(!d&&"function"!=typeof n)throw new $t(e);var p=c?c.length:0;if(p||(o&=-97,c=l=t),u=u===t?u:gn(ha(u),0),f=f===t?f:ha(f),p-=l?l.length:0,64&o){var g=c,v=l;c=l=t}var w=d?t:es(n),m=[n,o,a,c,l,g,v,h,u,f];if(w&&function(t,e){var n=t[1],r=e[1],o=n|r;if(!(o<131||(r==s&&8==n||r==s&&256==n&&t[7].length<=e[8]||384==r&&e[7].length<=e[8]&&8==n)))return t;1&r&&(t[2]=e[2],o|=1&n?0:4);var a=e[3];if(a){var c=t[3];t[3]=c?xr(c,a,e[4]):a,t[4]=c?on(t[3],i):e[4]}(a=e[5])&&(t[5]=(c=t[5])?Sr(c,a,e[6]):a,t[6]=c?on(t[5],i):e[6]),(a=e[7])&&(t[7]=a),r&s&&(t[8]=null==t[8]?e[8]:vn(t[8],e[8])),null==t[9]&&(t[9]=e[9]),t[0]=e[0],t[1]=o}(m,w),n=m[0],o=m[1],a=m[2],c=m[3],l=m[4],!(f=m[9]=m[9]===t?d?0:n.length:gn(m[9]-p,0))&&24&o&&(o&=-25),o&&1!=o)y=8==o||16==o?function(e,n,i){var r=_r(e);return function s(){for(var o=arguments.length,a=yt(o),c=o,l=is(s);c--;)a[c]=arguments[c];var h=o<3&&a[0]!==l&&a[o-1]!==l?[]:on(a,l);return(o-=h.length)<i?Kr(e,n,Pr,s.placeholder,t,a,h,t,t,i-o):Ae(this&&this!==he&&this instanceof s?r:e,this,a)}}(n,o,f):o!=r&&33!=o||l.length?Pr.apply(t,m):function(t,e,n,i){var r=1&e,s=_r(t);return function e(){for(var o=-1,a=arguments.length,c=-1,l=i.length,h=yt(l+a),u=this&&this!==he&&this instanceof e?s:t;++c<l;)h[c]=i[c];for(;a--;)h[c++]=arguments[++o];return Ae(u,r?n:this,h)}}(n,o,a,c);else var y=function(t,e,n){var i=1&e,r=_r(t);return function e(){return(this&&this!==he&&this instanceof e?r:t).apply(i?n:this,arguments)}}(n,o,a);return Cs((w?Qi:Ms)(y,m),n,o)}function Xr(e,n,i,r){return e===t||Po(e,Tt[i])&&!Et.call(r,i)?n:e}function Yr(e,n,i,r,s,o){return Qo(e)&&Qo(n)&&(o.set(n,e),Di(e,n,t,Yr,o),o.delete(n)),e}function Qr(e){return ta(e)?t:e}function Zr(e,n,i,r,s,o){var a=1&i,c=e.length,l=n.length;if(c!=l&&!(a&&l>c))return!1;var h=o.get(e),u=o.get(n);if(h&&u)return h==n&&u==e;var f=-1,d=!0,p=2&i?new Nn:t;for(o.set(e,n),o.set(n,e);++f<c;){var g=e[f],v=n[f];if(r)var w=a?r(v,g,f,n,e,o):r(g,v,f,e,n,o);if(w!==t){if(w)continue;d=!1;break}if(p){if(!Le(n,(function(t,e){if(!Qe(p,e)&&(g===t||s(g,t,i,r,o)))return p.push(e)}))){d=!1;break}}else if(g!==v&&!s(g,v,i,r,o)){d=!1;break}}return o.delete(e),o.delete(n),d}function qr(e){return $s(As(e,t,Ws),e+"")}function Jr(t){return ki(t,$a,cs)}function ts(t){return ki(t,Ca,ls)}var es=$n?function(t){return $n.get(t)}:rc;function ns(t){for(var e=t.name+"",n=Cn[e],i=Et.call(Cn,e)?n.length:0;i--;){var r=n[i],s=r.func;if(null==s||s==t)return r.name}return e}function is(t){return(Et.call(Bn,"placeholder")?Bn:t).placeholder}function rs(){var t=Bn.iteratee||tc;return t=t===tc?Ei:t,arguments.length?t(arguments[0],arguments[1]):t}function ss(t,e){var n,i,r=t.__data__;return("string"==(i=typeof(n=e))||"number"==i||"symbol"==i||"boolean"==i?"__proto__"!==n:null===n)?r["string"==typeof e?"string":"hash"]:r.map}function os(t){for(var e=$a(t),n=e.length;n--;){var i=e[n],r=t[i];e[n]=[i,r,bs(r)]}return e}function as(e,n){var i=function(e,n){return null==e?t:e[n]}(e,n);return ji(i)?i:t}var cs=pe?function(t){return null==t?[]:(t=St(t),$e(pe(t),(function(e){return Nt.call(t,e)})))}:uc,ls=pe?function(t){for(var e=[];t;)je(e,cs(t)),t=Kt(t);return e}:uc,hs=Ai;function us(t,e,n){for(var i=-1,r=(e=gr(e,t)).length,s=!1;++i<r;){var o=Es(e[i]);if(!(s=null!=t&&n(t,o)))break;t=t[o]}return s||++i!=r?s:!!(r=null==t?0:t.length)&&Yo(r)&&ps(o,r)&&(Wo(t)||Ro(t))}function fs(t){return"function"!=typeof t.constructor||ys(t)?{}:Dn(Kt(t))}function ds(t){return Wo(t)||Ro(t)||!!(Yt&&t&&t[Yt])}function ps(t,e){var n=typeof t;return!!(e=null==e?a:e)&&("number"==n||"symbol"!=n&&pt.test(t))&&t>-1&&t%1==0&&t<e}function gs(t,e,n){if(!Qo(n))return!1;var i=typeof e;return!!("number"==i?Fo(n)&&ps(e,n.length):"string"==i&&e in n)&&Po(n[e],t)}function vs(t,e){if(Wo(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!ra(t))||Q.test(t)||!Y.test(t)||null!=e&&t in St(e)}function ws(t){var e=ns(t),n=Bn[e];if("function"!=typeof n||!(e in Un.prototype))return!1;if(t===n)return!0;var i=es(n);return!!i&&t===i[0]}(kn&&hs(new kn(new ArrayBuffer(1)))!=C||An&&hs(new An)!=m||xn&&hs(xn.resolve())!=k||Sn&&hs(new Sn)!=x||Mn&&hs(new Mn)!=z)&&(hs=function(e){var n=Ai(e),i=n==b?e.constructor:t,r=i?_s(i):"";if(r)switch(r){case Tn:return C;case In:return m;case jn:return k;case En:return x;case _n:return z}return n});var ms=It?Ho:fc;function ys(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Tt)}function bs(t){return t==t&&!Qo(t)}function ks(e,n){return function(i){return null!=i&&i[e]===n&&(n!==t||e in St(i))}}function As(e,n,i){return n=gn(n===t?e.length-1:n,0),function(){for(var t=arguments,r=-1,s=gn(t.length-n,0),o=yt(s);++r<s;)o[r]=t[n+r];r=-1;for(var a=yt(n+1);++r<n;)a[r]=t[r];return a[n]=i(o),Ae(e,this,a)}}function xs(t,e){return e.length<2?t:bi(t,Ji(e,0,-1))}function Ss(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var Ms=Ts(Qi),zs=le||function(t,e){return he.setTimeout(t,e)},$s=Ts(Zi);function Cs(t,e,n){var i=e+"";return $s(t,function(t,e){var n=e.length;if(!n)return t;var i=n-1;return e[i]=(n>1?"& ":"")+e[i],e=e.join(n>2?", ":" "),t.replace(nt,"{\n/* [wrapped with "+e+"] */\n")}(i,function(t,e){return Se(h,(function(n){var i="_."+n[0];e&n[1]&&!Ce(t,i)&&t.push(i)})),t.sort()}(function(t){var e=t.match(it);return e?e[1].split(rt):[]}(i),n)))}function Ts(e){var n=0,i=0;return function(){var r=wn(),s=16-(r-i);if(i=r,s>0){if(++n>=800)return arguments[0]}else n=0;return e.apply(t,arguments)}}function Is(e,n){var i=-1,r=e.length,s=r-1;for(n=n===t?r:n;++i<n;){var o=Vi(i,s),a=e[o];e[o]=e[i],e[i]=a}return e.length=n,e}var js=function(){var t=Io((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Z,(function(t,n,i,r){e.push(i?r.replace(at,"$1"):n||t)})),e}),(function(t){return 500===e.size&&e.clear(),t})),e=t.cache;return t}();function Es(t){if("string"==typeof t||ra(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function _s(t){if(null!=t){try{return jt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Ls(t){if(t instanceof Un)return t.clone();var e=new Wn(t.__wrapped__,t.__chain__);return e.__actions__=Mr(t.__actions__),e.__index__=t.__index__,e.__values__=t.__values__,e}var Os=Gi((function(t,e){return Ko(t)?ci(t,pi(e,1,Ko,!0)):[]})),Ps=Gi((function(e,n){var i=Ns(n);return Ko(i)&&(i=t),Ko(e)?ci(e,pi(n,1,Ko,!0),rs(i,2)):[]})),Bs=Gi((function(e,n){var i=Ns(n);return Ko(i)&&(i=t),Ko(e)?ci(e,pi(n,1,Ko,!0),t,i):[]}));function Ds(t,e,n){var i=null==t?0:t.length;if(!i)return-1;var r=null==n?0:ha(n);return r<0&&(r=gn(i+r,0)),Be(t,rs(e,3),r)}function Rs(e,n,i){var r=null==e?0:e.length;if(!r)return-1;var s=r-1;return i!==t&&(s=ha(i),s=i<0?gn(r+s,0):vn(s,r-1)),Be(e,rs(n,3),s,!0)}function Ws(t){return null!=t&&t.length?pi(t,1):[]}function Us(e){return e&&e.length?e[0]:t}var Fs=Gi((function(t){var e=Ie(t,dr);return e.length&&e[0]===t[0]?zi(e):[]})),Ks=Gi((function(e){var n=Ns(e),i=Ie(e,dr);return n===Ns(i)?n=t:i.pop(),i.length&&i[0]===e[0]?zi(i,rs(n,2)):[]})),Vs=Gi((function(e){var n=Ns(e),i=Ie(e,dr);return(n="function"==typeof n?n:t)&&i.pop(),i.length&&i[0]===e[0]?zi(i,t,n):[]}));function Ns(e){var n=null==e?0:e.length;return n?e[n-1]:t}var Gs=Gi(Hs);function Hs(t,e){return t&&t.length&&e&&e.length?Fi(t,e):t}var Xs=qr((function(t,e){var n=null==t?0:t.length,i=ii(t,e);return Ki(t,Ie(e,(function(t){return ps(t,n)?+t:t})).sort(Ar)),i}));function Ys(t){return null==t?t:bn.call(t)}var Qs=Gi((function(t){return or(pi(t,1,Ko,!0))})),Zs=Gi((function(e){var n=Ns(e);return Ko(n)&&(n=t),or(pi(e,1,Ko,!0),rs(n,2))})),qs=Gi((function(e){var n=Ns(e);return n="function"==typeof n?n:t,or(pi(e,1,Ko,!0),t,n)}));function Js(t){if(!t||!t.length)return[];var e=0;return t=$e(t,(function(t){if(Ko(t))return e=gn(t.length,e),!0})),Ge(e,(function(e){return Ie(t,Fe(e))}))}function to(e,n){if(!e||!e.length)return[];var i=Js(e);return null==n?i:Ie(i,(function(e){return Ae(n,t,e)}))}var eo=Gi((function(t,e){return Ko(t)?ci(t,e):[]})),no=Gi((function(t){return ur($e(t,Ko))})),io=Gi((function(e){var n=Ns(e);return Ko(n)&&(n=t),ur($e(e,Ko),rs(n,2))})),ro=Gi((function(e){var n=Ns(e);return n="function"==typeof n?n:t,ur($e(e,Ko),t,n)})),so=Gi(Js),oo=Gi((function(e){var n=e.length,i=n>1?e[n-1]:t;return i="function"==typeof i?(e.pop(),i):t,to(e,i)}));function ao(t){var e=Bn(t);return e.__chain__=!0,e}function co(t,e){return e(t)}var lo=qr((function(e){var n=e.length,i=n?e[0]:0,r=this.__wrapped__,s=function(t){return ii(t,e)};return!(n>1||this.__actions__.length)&&r instanceof Un&&ps(i)?((r=r.slice(i,+i+(n?1:0))).__actions__.push({func:co,args:[s],thisArg:t}),new Wn(r,this.__chain__).thru((function(e){return n&&!e.length&&e.push(t),e}))):this.thru(s)})),ho=$r((function(t,e,n){Et.call(t,n)?++t[n]:ni(t,n,1)})),uo=Lr(Ds),fo=Lr(Rs);function po(t,e){return(Wo(t)?Se:li)(t,rs(e,3))}function go(t,e){return(Wo(t)?Me:hi)(t,rs(e,3))}var vo=$r((function(t,e,n){Et.call(t,n)?t[n].push(e):ni(t,n,[e])})),wo=Gi((function(t,e,n){var i=-1,r="function"==typeof e,s=Fo(t)?yt(t.length):[];return li(t,(function(t){s[++i]=r?Ae(e,t,n):$i(t,e,n)})),s})),mo=$r((function(t,e,n){ni(t,n,e)}));function yo(t,e){return(Wo(t)?Ie:Oi)(t,rs(e,3))}var bo=$r((function(t,e,n){t[n?0:1].push(e)}),(function(){return[[],[]]})),ko=Gi((function(t,e){if(null==t)return[];var n=e.length;return n>1&&gs(t,e[0],e[1])?e=[]:n>2&&gs(e[0],e[1],e[2])&&(e=[e[0]]),Wi(t,pi(e,1),[])})),Ao=ce||function(){return he.Date.now()};function xo(e,n,i){return n=i?t:n,Hr(e,s,t,t,t,t,n=e&&null==n?e.length:n)}function So(n,i){var r;if("function"!=typeof i)throw new $t(e);return n=ha(n),function(){return--n>0&&(r=i.apply(this,arguments)),n<=1&&(i=t),r}}var Mo=Gi((function(t,e,n){var i=1;if(n.length){var s=on(n,is(Mo));i|=r}return Hr(t,i,e,n,s)})),zo=Gi((function(t,e,n){var i=3;if(n.length){var s=on(n,is(zo));i|=r}return Hr(e,i,t,n,s)}));function $o(n,i,r){var s,o,a,c,l,h,u=0,f=!1,d=!1,p=!0;if("function"!=typeof n)throw new $t(e);function g(e){var i=s,r=o;return s=o=t,u=e,c=n.apply(r,i)}function v(e){var n=e-h;return h===t||n>=i||n<0||d&&e-u>=a}function w(){var t=Ao();if(v(t))return m(t);l=zs(w,function(t){var e=i-(t-h);return d?vn(e,a-(t-u)):e}(t))}function m(e){return l=t,p&&s?g(e):(s=o=t,c)}function y(){var e=Ao(),n=v(e);if(s=arguments,o=this,h=e,n){if(l===t)return function(t){return u=t,l=zs(w,i),f?g(t):c}(h);if(d)return mr(l),l=zs(w,i),g(h)}return l===t&&(l=zs(w,i)),c}return i=fa(i)||0,Qo(r)&&(f=!!r.leading,a=(d="maxWait"in r)?gn(fa(r.maxWait)||0,i):a,p="trailing"in r?!!r.trailing:p),y.cancel=function(){l!==t&&mr(l),u=0,s=h=o=l=t},y.flush=function(){return l===t?c:m(Ao())},y}var Co=Gi((function(t,e){return ai(t,1,e)})),To=Gi((function(t,e,n){return ai(t,fa(e)||0,n)}));function Io(t,n){if("function"!=typeof t||null!=n&&"function"!=typeof n)throw new $t(e);var i=function(){var e=arguments,r=n?n.apply(this,e):e[0],s=i.cache;if(s.has(r))return s.get(r);var o=t.apply(this,e);return i.cache=s.set(r,o)||s,o};return i.cache=new(Io.Cache||Vn),i}function jo(t){if("function"!=typeof t)throw new $t(e);return function(){var e=arguments;switch(e.length){case 0:return!t.call(this);case 1:return!t.call(this,e[0]);case 2:return!t.call(this,e[0],e[1]);case 3:return!t.call(this,e[0],e[1],e[2])}return!t.apply(this,e)}}Io.Cache=Vn;var Eo=vr((function(t,e){var n=(e=1==e.length&&Wo(e[0])?Ie(e[0],Xe(rs())):Ie(pi(e,1),Xe(rs()))).length;return Gi((function(i){for(var r=-1,s=vn(i.length,n);++r<s;)i[r]=e[r].call(this,i[r]);return Ae(t,this,i)}))})),_o=Gi((function(e,n){var i=on(n,is(_o));return Hr(e,r,t,n,i)})),Lo=Gi((function(e,n){var i=on(n,is(Lo));return Hr(e,64,t,n,i)})),Oo=qr((function(e,n){return Hr(e,256,t,t,t,n)}));function Po(t,e){return t===e||t!=t&&e!=e}var Bo=Fr(xi),Do=Fr((function(t,e){return t>=e})),Ro=Ci(function(){return arguments}())?Ci:function(t){return Zo(t)&&Et.call(t,"callee")&&!Nt.call(t,"callee")},Wo=yt.isArray,Uo=ve?Xe(ve):function(t){return Zo(t)&&Ai(t)==$};function Fo(t){return null!=t&&Yo(t.length)&&!Ho(t)}function Ko(t){return Zo(t)&&Fo(t)}var Vo=ge||fc,No=we?Xe(we):function(t){return Zo(t)&&Ai(t)==p};function Go(t){if(!Zo(t))return!1;var e=Ai(t);return e==g||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!ta(t)}function Ho(t){if(!Qo(t))return!1;var e=Ai(t);return e==v||e==w||"[object AsyncFunction]"==e||"[object Proxy]"==e}function Xo(t){return"number"==typeof t&&t==ha(t)}function Yo(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=a}function Qo(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function Zo(t){return null!=t&&"object"==typeof t}var qo=me?Xe(me):function(t){return Zo(t)&&hs(t)==m};function Jo(t){return"number"==typeof t||Zo(t)&&Ai(t)==y}function ta(t){if(!Zo(t)||Ai(t)!=b)return!1;var e=Kt(t);if(null===e)return!0;var n=Et.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&jt.call(n)==Pt}var ea=ye?Xe(ye):function(t){return Zo(t)&&Ai(t)==A},na=be?Xe(be):function(t){return Zo(t)&&hs(t)==x};function ia(t){return"string"==typeof t||!Wo(t)&&Zo(t)&&Ai(t)==S}function ra(t){return"symbol"==typeof t||Zo(t)&&Ai(t)==M}var sa=ke?Xe(ke):function(t){return Zo(t)&&Yo(t.length)&&!!ie[Ai(t)]},oa=Fr(Li),aa=Fr((function(t,e){return t<=e}));function ca(t){if(!t)return[];if(Fo(t))return ia(t)?hn(t):Mr(t);if(Zt&&t[Zt])return function(t){for(var e,n=[];!(e=t.next()).done;)n.push(e.value);return n}(t[Zt]());var e=hs(t);return(e==m?rn:e==x?an:Pa)(t)}function la(t){return t?(t=fa(t))===o||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function ha(t){var e=la(t),n=e%1;return e==e?n?e-n:e:0}function ua(t){return t?ri(ha(t),0,l):0}function fa(t){if("number"==typeof t)return t;if(ra(t))return c;if(Qo(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Qo(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=He(t);var n=ut.test(t);return n||dt.test(t)?ae(t.slice(2),n?2:8):ht.test(t)?c:+t}function da(t){return zr(t,Ca(t))}function pa(t){return null==t?"":sr(t)}var ga=Cr((function(t,e){if(ys(e)||Fo(e))zr(e,$a(e),t);else for(var n in e)Et.call(e,n)&&qn(t,n,e[n])})),va=Cr((function(t,e){zr(e,Ca(e),t)})),wa=Cr((function(t,e,n,i){zr(e,Ca(e),t,i)})),ma=Cr((function(t,e,n,i){zr(e,$a(e),t,i)})),ya=qr(ii),ba=Gi((function(e,n){e=St(e);var i=-1,r=n.length,s=r>2?n[2]:t;for(s&&gs(n[0],n[1],s)&&(r=1);++i<r;)for(var o=n[i],a=Ca(o),c=-1,l=a.length;++c<l;){var h=a[c],u=e[h];(u===t||Po(u,Tt[h])&&!Et.call(e,h))&&(e[h]=o[h])}return e})),ka=Gi((function(e){return e.push(t,Yr),Ae(Ia,t,e)}));function Aa(e,n,i){var r=null==e?t:bi(e,n);return r===t?i:r}function xa(t,e){return null!=t&&us(t,e,Mi)}var Sa=Br((function(t,e,n){null!=e&&"function"!=typeof e.toString&&(e=Ot.call(e)),t[e]=n}),Qa(Ja)),Ma=Br((function(t,e,n){null!=e&&"function"!=typeof e.toString&&(e=Ot.call(e)),Et.call(t,e)?t[e].push(n):t[e]=[n]}),rs),za=Gi($i);function $a(t){return Fo(t)?Hn(t):_i(t)}function Ca(t){return Fo(t)?Hn(t,!0):function(t){if(!Qo(t))return function(t){var e=[];if(null!=t)for(var n in St(t))e.push(n);return e}(t);var e=ys(t),n=[];for(var i in t)("constructor"!=i||!e&&Et.call(t,i))&&n.push(i);return n}(t)}var Ta=Cr((function(t,e,n){Di(t,e,n)})),Ia=Cr((function(t,e,n,i){Di(t,e,n,i)})),ja=qr((function(t,e){var n={};if(null==t)return n;var i=!1;e=Ie(e,(function(e){return e=gr(e,t),i||(i=e.length>1),e})),zr(t,ts(t),n),i&&(n=si(n,7,Qr));for(var r=e.length;r--;)ar(n,e[r]);return n})),Ea=qr((function(t,e){return null==t?{}:function(t,e){return Ui(t,e,(function(e,n){return xa(t,n)}))}(t,e)}));function _a(t,e){if(null==t)return{};var n=Ie(ts(t),(function(t){return[t]}));return e=rs(e),Ui(t,n,(function(t,n){return e(t,n[0])}))}var La=Gr($a),Oa=Gr(Ca);function Pa(t){return null==t?[]:Ye(t,$a(t))}var Ba=Er((function(t,e,n){return e=e.toLowerCase(),t+(n?Da(e):e)}));function Da(t){return Ga(pa(t).toLowerCase())}function Ra(t){return(t=pa(t))&&t.replace(gt,Je).replace(Xt,"")}var Wa=Er((function(t,e,n){return t+(n?"-":"")+e.toLowerCase()})),Ua=Er((function(t,e,n){return t+(n?" ":"")+e.toLowerCase()})),Fa=jr("toLowerCase"),Ka=Er((function(t,e,n){return t+(n?"_":"")+e.toLowerCase()})),Va=Er((function(t,e,n){return t+(n?" ":"")+Ga(e)})),Na=Er((function(t,e,n){return t+(n?" ":"")+e.toUpperCase()})),Ga=jr("toUpperCase");function Ha(e,n,i){return e=pa(e),(n=i?t:n)===t?function(t){return te.test(t)}(e)?function(t){return t.match(Qt)||[]}(e):function(t){return t.match(st)||[]}(e):e.match(n)||[]}var Xa=Gi((function(e,n){try{return Ae(e,t,n)}catch(t){return Go(t)?t:new kt(t)}})),Ya=qr((function(t,e){return Se(e,(function(e){e=Es(e),ni(t,e,Mo(t[e],t))})),t}));function Qa(t){return function(){return t}}var Za=Or(),qa=Or(!0);function Ja(t){return t}function tc(t){return Ei("function"==typeof t?t:si(t,1))}var ec=Gi((function(t,e){return function(n){return $i(n,t,e)}})),nc=Gi((function(t,e){return function(n){return $i(t,n,e)}}));function ic(t,e,n){var i=$a(e),r=yi(e,i);null!=n||Qo(e)&&(r.length||!i.length)||(n=e,e=t,t=this,r=yi(e,$a(e)));var s=!(Qo(n)&&"chain"in n&&!n.chain),o=Ho(t);return Se(r,(function(n){var i=e[n];t[n]=i,o&&(t.prototype[n]=function(){var e=this.__chain__;if(s||e){var n=t(this.__wrapped__);return(n.__actions__=Mr(this.__actions__)).push({func:i,args:arguments,thisArg:t}),n.__chain__=e,n}return i.apply(t,je([this.value()],arguments))})})),t}function rc(){}var sc=Rr(Ie),oc=Rr(ze),ac=Rr(Le);function cc(t){return vs(t)?Fe(Es(t)):function(t){return function(e){return bi(e,t)}}(t)}var lc=Ur(),hc=Ur(!0);function uc(){return[]}function fc(){return!1}var dc,pc=Dr((function(t,e){return t+e}),0),gc=Vr("ceil"),vc=Dr((function(t,e){return t/e}),1),wc=Vr("floor"),mc=Dr((function(t,e){return t*e}),1),yc=Vr("round"),bc=Dr((function(t,e){return t-e}),0);return Bn.after=function(t,n){if("function"!=typeof n)throw new $t(e);return t=ha(t),function(){if(--t<1)return n.apply(this,arguments)}},Bn.ary=xo,Bn.assign=ga,Bn.assignIn=va,Bn.assignInWith=wa,Bn.assignWith=ma,Bn.at=ya,Bn.before=So,Bn.bind=Mo,Bn.bindAll=Ya,Bn.bindKey=zo,Bn.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Wo(t)?t:[t]},Bn.chain=ao,Bn.chunk=function(e,n,i){n=(i?gs(e,n,i):n===t)?1:gn(ha(n),0);var r=null==e?0:e.length;if(!r||n<1)return[];for(var s=0,o=0,a=yt(ue(r/n));s<r;)a[o++]=Ji(e,s,s+=n);return a},Bn.compact=function(t){for(var e=-1,n=null==t?0:t.length,i=0,r=[];++e<n;){var s=t[e];s&&(r[i++]=s)}return r},Bn.concat=function(){var t=arguments.length;if(!t)return[];for(var e=yt(t-1),n=arguments[0],i=t;i--;)e[i-1]=arguments[i];return je(Wo(n)?Mr(n):[n],pi(e,1))},Bn.cond=function(t){var n=null==t?0:t.length,i=rs();return t=n?Ie(t,(function(t){if("function"!=typeof t[1])throw new $t(e);return[i(t[0]),t[1]]})):[],Gi((function(e){for(var i=-1;++i<n;){var r=t[i];if(Ae(r[0],this,e))return Ae(r[1],this,e)}}))},Bn.conforms=function(t){return function(t){var e=$a(t);return function(n){return oi(n,t,e)}}(si(t,1))},Bn.constant=Qa,Bn.countBy=ho,Bn.create=function(t,e){var n=Dn(t);return null==e?n:ei(n,e)},Bn.curry=function e(n,i,r){var s=Hr(n,8,t,t,t,t,t,i=r?t:i);return s.placeholder=e.placeholder,s},Bn.curryRight=function e(n,i,r){var s=Hr(n,16,t,t,t,t,t,i=r?t:i);return s.placeholder=e.placeholder,s},Bn.debounce=$o,Bn.defaults=ba,Bn.defaultsDeep=ka,Bn.defer=Co,Bn.delay=To,Bn.difference=Os,Bn.differenceBy=Ps,Bn.differenceWith=Bs,Bn.drop=function(e,n,i){var r=null==e?0:e.length;return r?Ji(e,(n=i||n===t?1:ha(n))<0?0:n,r):[]},Bn.dropRight=function(e,n,i){var r=null==e?0:e.length;return r?Ji(e,0,(n=r-(n=i||n===t?1:ha(n)))<0?0:n):[]},Bn.dropRightWhile=function(t,e){return t&&t.length?lr(t,rs(e,3),!0,!0):[]},Bn.dropWhile=function(t,e){return t&&t.length?lr(t,rs(e,3),!0):[]},Bn.fill=function(e,n,i,r){var s=null==e?0:e.length;return s?(i&&"number"!=typeof i&&gs(e,n,i)&&(i=0,r=s),function(e,n,i,r){var s=e.length;for((i=ha(i))<0&&(i=-i>s?0:s+i),(r=r===t||r>s?s:ha(r))<0&&(r+=s),r=i>r?0:ua(r);i<r;)e[i++]=n;return e}(e,n,i,r)):[]},Bn.filter=function(t,e){return(Wo(t)?$e:di)(t,rs(e,3))},Bn.flatMap=function(t,e){return pi(yo(t,e),1)},Bn.flatMapDeep=function(t,e){return pi(yo(t,e),o)},Bn.flatMapDepth=function(e,n,i){return i=i===t?1:ha(i),pi(yo(e,n),i)},Bn.flatten=Ws,Bn.flattenDeep=function(t){return null!=t&&t.length?pi(t,o):[]},Bn.flattenDepth=function(e,n){return null!=e&&e.length?pi(e,n=n===t?1:ha(n)):[]},Bn.flip=function(t){return Hr(t,512)},Bn.flow=Za,Bn.flowRight=qa,Bn.fromPairs=function(t){for(var e=-1,n=null==t?0:t.length,i={};++e<n;){var r=t[e];ni(i,r[0],r[1])}return i},Bn.functions=function(t){return null==t?[]:yi(t,$a(t))},Bn.functionsIn=function(t){return null==t?[]:yi(t,Ca(t))},Bn.groupBy=vo,Bn.initial=function(t){return null!=t&&t.length?Ji(t,0,-1):[]},Bn.intersection=Fs,Bn.intersectionBy=Ks,Bn.intersectionWith=Vs,Bn.invert=Sa,Bn.invertBy=Ma,Bn.invokeMap=wo,Bn.iteratee=tc,Bn.keyBy=mo,Bn.keys=$a,Bn.keysIn=Ca,Bn.map=yo,Bn.mapKeys=function(t,e){var n={};return e=rs(e,3),wi(t,(function(t,i,r){ni(n,e(t,i,r),t)})),n},Bn.mapValues=function(t,e){var n={};return e=rs(e,3),wi(t,(function(t,i,r){ni(n,i,e(t,i,r))})),n},Bn.matches=function(t){return Pi(si(t,1))},Bn.matchesProperty=function(t,e){return Bi(t,si(e,1))},Bn.memoize=Io,Bn.merge=Ta,Bn.mergeWith=Ia,Bn.method=ec,Bn.methodOf=nc,Bn.mixin=ic,Bn.negate=jo,Bn.nthArg=function(t){return t=ha(t),Gi((function(e){return Ri(e,t)}))},Bn.omit=ja,Bn.omitBy=function(t,e){return _a(t,jo(rs(e)))},Bn.once=function(t){return So(2,t)},Bn.orderBy=function(e,n,i,r){return null==e?[]:(Wo(n)||(n=null==n?[]:[n]),Wo(i=r?t:i)||(i=null==i?[]:[i]),Wi(e,n,i))},Bn.over=sc,Bn.overArgs=Eo,Bn.overEvery=oc,Bn.overSome=ac,Bn.partial=_o,Bn.partialRight=Lo,Bn.partition=bo,Bn.pick=Ea,Bn.pickBy=_a,Bn.property=cc,Bn.propertyOf=function(e){return function(n){return null==e?t:bi(e,n)}},Bn.pull=Gs,Bn.pullAll=Hs,Bn.pullAllBy=function(t,e,n){return t&&t.length&&e&&e.length?Fi(t,e,rs(n,2)):t},Bn.pullAllWith=function(e,n,i){return e&&e.length&&n&&n.length?Fi(e,n,t,i):e},Bn.pullAt=Xs,Bn.range=lc,Bn.rangeRight=hc,Bn.rearg=Oo,Bn.reject=function(t,e){return(Wo(t)?$e:di)(t,jo(rs(e,3)))},Bn.remove=function(t,e){var n=[];if(!t||!t.length)return n;var i=-1,r=[],s=t.length;for(e=rs(e,3);++i<s;){var o=t[i];e(o,i,t)&&(n.push(o),r.push(i))}return Ki(t,r),n},Bn.rest=function(n,i){if("function"!=typeof n)throw new $t(e);return Gi(n,i=i===t?i:ha(i))},Bn.reverse=Ys,Bn.sampleSize=function(e,n,i){return n=(i?gs(e,n,i):n===t)?1:ha(n),(Wo(e)?Yn:Xi)(e,n)},Bn.set=function(t,e,n){return null==t?t:Yi(t,e,n)},Bn.setWith=function(e,n,i,r){return r="function"==typeof r?r:t,null==e?e:Yi(e,n,i,r)},Bn.shuffle=function(t){return(Wo(t)?Qn:qi)(t)},Bn.slice=function(e,n,i){var r=null==e?0:e.length;return r?(i&&"number"!=typeof i&&gs(e,n,i)?(n=0,i=r):(n=null==n?0:ha(n),i=i===t?r:ha(i)),Ji(e,n,i)):[]},Bn.sortBy=ko,Bn.sortedUniq=function(t){return t&&t.length?ir(t):[]},Bn.sortedUniqBy=function(t,e){return t&&t.length?ir(t,rs(e,2)):[]},Bn.split=function(e,n,i){return i&&"number"!=typeof i&&gs(e,n,i)&&(n=i=t),(i=i===t?l:i>>>0)?(e=pa(e))&&("string"==typeof n||null!=n&&!ea(n))&&!(n=sr(n))&&nn(e)?wr(hn(e),0,i):e.split(n,i):[]},Bn.spread=function(t,n){if("function"!=typeof t)throw new $t(e);return n=null==n?0:gn(ha(n),0),Gi((function(e){var i=e[n],r=wr(e,0,n);return i&&je(r,i),Ae(t,this,r)}))},Bn.tail=function(t){var e=null==t?0:t.length;return e?Ji(t,1,e):[]},Bn.take=function(e,n,i){return e&&e.length?Ji(e,0,(n=i||n===t?1:ha(n))<0?0:n):[]},Bn.takeRight=function(e,n,i){var r=null==e?0:e.length;return r?Ji(e,(n=r-(n=i||n===t?1:ha(n)))<0?0:n,r):[]},Bn.takeRightWhile=function(t,e){return t&&t.length?lr(t,rs(e,3),!1,!0):[]},Bn.takeWhile=function(t,e){return t&&t.length?lr(t,rs(e,3)):[]},Bn.tap=function(t,e){return e(t),t},Bn.throttle=function(t,n,i){var r=!0,s=!0;if("function"!=typeof t)throw new $t(e);return Qo(i)&&(r="leading"in i?!!i.leading:r,s="trailing"in i?!!i.trailing:s),$o(t,n,{leading:r,maxWait:n,trailing:s})},Bn.thru=co,Bn.toArray=ca,Bn.toPairs=La,Bn.toPairsIn=Oa,Bn.toPath=function(t){return Wo(t)?Ie(t,Es):ra(t)?[t]:Mr(js(pa(t)))},Bn.toPlainObject=da,Bn.transform=function(t,e,n){var i=Wo(t),r=i||Vo(t)||sa(t);if(e=rs(e,4),null==n){var s=t&&t.constructor;n=r?i?new s:[]:Qo(t)&&Ho(s)?Dn(Kt(t)):{}}return(r?Se:wi)(t,(function(t,i,r){return e(n,t,i,r)})),n},Bn.unary=function(t){return xo(t,1)},Bn.union=Qs,Bn.unionBy=Zs,Bn.unionWith=qs,Bn.uniq=function(t){return t&&t.length?or(t):[]},Bn.uniqBy=function(t,e){return t&&t.length?or(t,rs(e,2)):[]},Bn.uniqWith=function(e,n){return n="function"==typeof n?n:t,e&&e.length?or(e,t,n):[]},Bn.unset=function(t,e){return null==t||ar(t,e)},Bn.unzip=Js,Bn.unzipWith=to,Bn.update=function(t,e,n){return null==t?t:cr(t,e,pr(n))},Bn.updateWith=function(e,n,i,r){return r="function"==typeof r?r:t,null==e?e:cr(e,n,pr(i),r)},Bn.values=Pa,Bn.valuesIn=function(t){return null==t?[]:Ye(t,Ca(t))},Bn.without=eo,Bn.words=Ha,Bn.wrap=function(t,e){return _o(pr(e),t)},Bn.xor=no,Bn.xorBy=io,Bn.xorWith=ro,Bn.zip=so,Bn.zipObject=function(t,e){return fr(t||[],e||[],qn)},Bn.zipObjectDeep=function(t,e){return fr(t||[],e||[],Yi)},Bn.zipWith=oo,Bn.entries=La,Bn.entriesIn=Oa,Bn.extend=va,Bn.extendWith=wa,ic(Bn,Bn),Bn.add=pc,Bn.attempt=Xa,Bn.camelCase=Ba,Bn.capitalize=Da,Bn.ceil=gc,Bn.clamp=function(e,n,i){return i===t&&(i=n,n=t),i!==t&&(i=(i=fa(i))==i?i:0),n!==t&&(n=(n=fa(n))==n?n:0),ri(fa(e),n,i)},Bn.clone=function(t){return si(t,4)},Bn.cloneDeep=function(t){return si(t,5)},Bn.cloneDeepWith=function(e,n){return si(e,5,n="function"==typeof n?n:t)},Bn.cloneWith=function(e,n){return si(e,4,n="function"==typeof n?n:t)},Bn.conformsTo=function(t,e){return null==e||oi(t,e,$a(e))},Bn.deburr=Ra,Bn.defaultTo=function(t,e){return null==t||t!=t?e:t},Bn.divide=vc,Bn.endsWith=function(e,n,i){e=pa(e),n=sr(n);var r=e.length,s=i=i===t?r:ri(ha(i),0,r);return(i-=n.length)>=0&&e.slice(i,s)==n},Bn.eq=Po,Bn.escape=function(t){return(t=pa(t))&&V.test(t)?t.replace(F,tn):t},Bn.escapeRegExp=function(t){return(t=pa(t))&&J.test(t)?t.replace(q,"\\$&"):t},Bn.every=function(e,n,i){var r=Wo(e)?ze:ui;return i&&gs(e,n,i)&&(n=t),r(e,rs(n,3))},Bn.find=uo,Bn.findIndex=Ds,Bn.findKey=function(t,e){return Pe(t,rs(e,3),wi)},Bn.findLast=fo,Bn.findLastIndex=Rs,Bn.findLastKey=function(t,e){return Pe(t,rs(e,3),mi)},Bn.floor=wc,Bn.forEach=po,Bn.forEachRight=go,Bn.forIn=function(t,e){return null==t?t:gi(t,rs(e,3),Ca)},Bn.forInRight=function(t,e){return null==t?t:vi(t,rs(e,3),Ca)},Bn.forOwn=function(t,e){return t&&wi(t,rs(e,3))},Bn.forOwnRight=function(t,e){return t&&mi(t,rs(e,3))},Bn.get=Aa,Bn.gt=Bo,Bn.gte=Do,Bn.has=function(t,e){return null!=t&&us(t,e,Si)},Bn.hasIn=xa,Bn.head=Us,Bn.identity=Ja,Bn.includes=function(t,e,n,i){t=Fo(t)?t:Pa(t),n=n&&!i?ha(n):0;var r=t.length;return n<0&&(n=gn(r+n,0)),ia(t)?n<=r&&t.indexOf(e,n)>-1:!!r&&De(t,e,n)>-1},Bn.indexOf=function(t,e,n){var i=null==t?0:t.length;if(!i)return-1;var r=null==n?0:ha(n);return r<0&&(r=gn(i+r,0)),De(t,e,r)},Bn.inRange=function(e,n,i){return n=la(n),i===t?(i=n,n=0):i=la(i),function(t,e,n){return t>=vn(e,n)&&t<gn(e,n)}(e=fa(e),n,i)},Bn.invoke=za,Bn.isArguments=Ro,Bn.isArray=Wo,Bn.isArrayBuffer=Uo,Bn.isArrayLike=Fo,Bn.isArrayLikeObject=Ko,Bn.isBoolean=function(t){return!0===t||!1===t||Zo(t)&&Ai(t)==d},Bn.isBuffer=Vo,Bn.isDate=No,Bn.isElement=function(t){return Zo(t)&&1===t.nodeType&&!ta(t)},Bn.isEmpty=function(t){if(null==t)return!0;if(Fo(t)&&(Wo(t)||"string"==typeof t||"function"==typeof t.splice||Vo(t)||sa(t)||Ro(t)))return!t.length;var e=hs(t);if(e==m||e==x)return!t.size;if(ys(t))return!_i(t).length;for(var n in t)if(Et.call(t,n))return!1;return!0},Bn.isEqual=function(t,e){return Ti(t,e)},Bn.isEqualWith=function(e,n,i){var r=(i="function"==typeof i?i:t)?i(e,n):t;return r===t?Ti(e,n,t,i):!!r},Bn.isError=Go,Bn.isFinite=function(t){return"number"==typeof t&&Oe(t)},Bn.isFunction=Ho,Bn.isInteger=Xo,Bn.isLength=Yo,Bn.isMap=qo,Bn.isMatch=function(t,e){return t===e||Ii(t,e,os(e))},Bn.isMatchWith=function(e,n,i){return i="function"==typeof i?i:t,Ii(e,n,os(n),i)},Bn.isNaN=function(t){return Jo(t)&&t!=+t},Bn.isNative=function(t){if(ms(t))throw new kt("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return ji(t)},Bn.isNil=function(t){return null==t},Bn.isNull=function(t){return null===t},Bn.isNumber=Jo,Bn.isObject=Qo,Bn.isObjectLike=Zo,Bn.isPlainObject=ta,Bn.isRegExp=ea,Bn.isSafeInteger=function(t){return Xo(t)&&t>=-9007199254740991&&t<=a},Bn.isSet=na,Bn.isString=ia,Bn.isSymbol=ra,Bn.isTypedArray=sa,Bn.isUndefined=function(e){return e===t},Bn.isWeakMap=function(t){return Zo(t)&&hs(t)==z},Bn.isWeakSet=function(t){return Zo(t)&&"[object WeakSet]"==Ai(t)},Bn.join=function(t,e){return null==t?"":Ke.call(t,e)},Bn.kebabCase=Wa,Bn.last=Ns,Bn.lastIndexOf=function(e,n,i){var r=null==e?0:e.length;if(!r)return-1;var s=r;return i!==t&&(s=(s=ha(i))<0?gn(r+s,0):vn(s,r-1)),n==n?function(t,e,n){for(var i=n+1;i--;)if(t[i]===e)return i;return i}(e,n,s):Be(e,We,s,!0)},Bn.lowerCase=Ua,Bn.lowerFirst=Fa,Bn.lt=oa,Bn.lte=aa,Bn.max=function(e){return e&&e.length?fi(e,Ja,xi):t},Bn.maxBy=function(e,n){return e&&e.length?fi(e,rs(n,2),xi):t},Bn.mean=function(t){return Ue(t,Ja)},Bn.meanBy=function(t,e){return Ue(t,rs(e,2))},Bn.min=function(e){return e&&e.length?fi(e,Ja,Li):t},Bn.minBy=function(e,n){return e&&e.length?fi(e,rs(n,2),Li):t},Bn.stubArray=uc,Bn.stubFalse=fc,Bn.stubObject=function(){return{}},Bn.stubString=function(){return""},Bn.stubTrue=function(){return!0},Bn.multiply=mc,Bn.nth=function(e,n){return e&&e.length?Ri(e,ha(n)):t},Bn.noConflict=function(){return he._===this&&(he._=Bt),this},Bn.noop=rc,Bn.now=Ao,Bn.pad=function(t,e,n){t=pa(t);var i=(e=ha(e))?ln(t):0;if(!e||i>=e)return t;var r=(e-i)/2;return Wr(fe(r),n)+t+Wr(ue(r),n)},Bn.padEnd=function(t,e,n){t=pa(t);var i=(e=ha(e))?ln(t):0;return e&&i<e?t+Wr(e-i,n):t},Bn.padStart=function(t,e,n){t=pa(t);var i=(e=ha(e))?ln(t):0;return e&&i<e?Wr(e-i,n)+t:t},Bn.parseInt=function(t,e,n){return n||null==e?e=0:e&&(e=+e),mn(pa(t).replace(tt,""),e||0)},Bn.random=function(e,n,i){if(i&&"boolean"!=typeof i&&gs(e,n,i)&&(n=i=t),i===t&&("boolean"==typeof n?(i=n,n=t):"boolean"==typeof e&&(i=e,e=t)),e===t&&n===t?(e=0,n=1):(e=la(e),n===t?(n=e,e=0):n=la(n)),e>n){var r=e;e=n,n=r}if(i||e%1||n%1){var s=yn();return vn(e+s*(n-e+oe("1e-"+((s+"").length-1))),n)}return Vi(e,n)},Bn.reduce=function(t,e,n){var i=Wo(t)?Ee:Ve,r=arguments.length<3;return i(t,rs(e,4),n,r,li)},Bn.reduceRight=function(t,e,n){var i=Wo(t)?_e:Ve,r=arguments.length<3;return i(t,rs(e,4),n,r,hi)},Bn.repeat=function(e,n,i){return n=(i?gs(e,n,i):n===t)?1:ha(n),Ni(pa(e),n)},Bn.replace=function(){var t=arguments,e=pa(t[0]);return t.length<3?e:e.replace(t[1],t[2])},Bn.result=function(e,n,i){var r=-1,s=(n=gr(n,e)).length;for(s||(s=1,e=t);++r<s;){var o=null==e?t:e[Es(n[r])];o===t&&(r=s,o=i),e=Ho(o)?o.call(e):o}return e},Bn.round=yc,Bn.runInContext=X,Bn.sample=function(t){return(Wo(t)?Xn:Hi)(t)},Bn.size=function(t){if(null==t)return 0;if(Fo(t))return ia(t)?ln(t):t.length;var e=hs(t);return e==m||e==x?t.size:_i(t).length},Bn.snakeCase=Ka,Bn.some=function(e,n,i){var r=Wo(e)?Le:tr;return i&&gs(e,n,i)&&(n=t),r(e,rs(n,3))},Bn.sortedIndex=function(t,e){return er(t,e)},Bn.sortedIndexBy=function(t,e,n){return nr(t,e,rs(n,2))},Bn.sortedIndexOf=function(t,e){var n=null==t?0:t.length;if(n){var i=er(t,e);if(i<n&&Po(t[i],e))return i}return-1},Bn.sortedLastIndex=function(t,e){return er(t,e,!0)},Bn.sortedLastIndexBy=function(t,e,n){return nr(t,e,rs(n,2),!0)},Bn.sortedLastIndexOf=function(t,e){if(null!=t&&t.length){var n=er(t,e,!0)-1;if(Po(t[n],e))return n}return-1},Bn.startCase=Va,Bn.startsWith=function(t,e,n){return t=pa(t),n=null==n?0:ri(ha(n),0,t.length),e=sr(e),t.slice(n,n+e.length)==e},Bn.subtract=bc,Bn.sum=function(t){return t&&t.length?Ne(t,Ja):0},Bn.sumBy=function(t,e){return t&&t.length?Ne(t,rs(e,2)):0},Bn.template=function(e,n,i){var r=Bn.templateSettings;i&&gs(e,n,i)&&(n=t),e=pa(e),n=ma({},n,r,Xr);var s=ma({},n.imports,r.imports,Xr),o=$a(s),a=Ye(s,o);Se(o,(function(t){if(ot.test(t))throw new kt("Invalid `imports` option passed into `_.template`")}));var c,l,h=0,u=n.interpolate||vt,f="__p += '",d=Mt((n.escape||vt).source+"|"+u.source+"|"+(u===H?ct:vt).source+"|"+(n.evaluate||vt).source+"|$","g"),p="//# sourceURL="+(Et.call(n,"sourceURL")?(n.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++ne+"]")+"\n";e.replace(d,(function(t,n,i,r,s,o){return i||(i=r),f+=e.slice(h,o).replace(wt,en),n&&(c=!0,f+="' +\n__e("+n+") +\n'"),s&&(l=!0,f+="';\n"+s+";\n__p += '"),i&&(f+="' +\n((__t = ("+i+")) == null ? '' : __t) +\n'"),h=o+t.length,t})),f+="';\n";var g=Et.call(n,"variable")&&n.variable;if(g){if(ot.test(g))throw new kt("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(l?f.replace(D,""):f).replace(R,"$1").replace(W,"$1;"),f="function("+(g||"obj")+") {\n"+(g?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(c?", __e = _.escape":"")+(l?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var v=Xa((function(){return At(o,p+"return "+f).apply(t,a)}));if(v.source=f,Go(v))throw v;return v},Bn.times=function(t,e){if((t=ha(t))<1||t>a)return[];var n=l,i=vn(t,l);e=rs(e),t-=l;for(var r=Ge(i,e);++n<t;)e(n);return r},Bn.toFinite=la,Bn.toInteger=ha,Bn.toLength=ua,Bn.toLower=function(t){return pa(t).toLowerCase()},Bn.toNumber=fa,Bn.toSafeInteger=function(t){return t?ri(ha(t),-9007199254740991,a):0===t?t:0},Bn.toString=pa,Bn.toUpper=function(t){return pa(t).toUpperCase()},Bn.trim=function(e,n,i){if((e=pa(e))&&(i||n===t))return He(e);if(!e||!(n=sr(n)))return e;var r=hn(e),s=hn(n);return wr(r,Ze(r,s),qe(r,s)+1).join("")},Bn.trimEnd=function(e,n,i){if((e=pa(e))&&(i||n===t))return e.slice(0,un(e)+1);if(!e||!(n=sr(n)))return e;var r=hn(e);return wr(r,0,qe(r,hn(n))+1).join("")},Bn.trimStart=function(e,n,i){if((e=pa(e))&&(i||n===t))return e.replace(tt,"");if(!e||!(n=sr(n)))return e;var r=hn(e);return wr(r,Ze(r,hn(n))).join("")},Bn.truncate=function(e,n){var i=30,r="...";if(Qo(n)){var s="separator"in n?n.separator:s;i="length"in n?ha(n.length):i,r="omission"in n?sr(n.omission):r}var o=(e=pa(e)).length;if(nn(e)){var a=hn(e);o=a.length}if(i>=o)return e;var c=i-ln(r);if(c<1)return r;var l=a?wr(a,0,c).join(""):e.slice(0,c);if(s===t)return l+r;if(a&&(c+=l.length-c),ea(s)){if(e.slice(c).search(s)){var h,u=l;for(s.global||(s=Mt(s.source,pa(lt.exec(s))+"g")),s.lastIndex=0;h=s.exec(u);)var f=h.index;l=l.slice(0,f===t?c:f)}}else if(e.indexOf(sr(s),c)!=c){var d=l.lastIndexOf(s);d>-1&&(l=l.slice(0,d))}return l+r},Bn.unescape=function(t){return(t=pa(t))&&K.test(t)?t.replace(U,fn):t},Bn.uniqueId=function(t){var e=++_t;return pa(t)+e},Bn.upperCase=Na,Bn.upperFirst=Ga,Bn.each=po,Bn.eachRight=go,Bn.first=Us,ic(Bn,(dc={},wi(Bn,(function(t,e){Et.call(Bn.prototype,e)||(dc[e]=t)})),dc),{chain:!1}),Bn.VERSION="4.18.1",Se(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Bn[t].placeholder=Bn})),Se(["drop","take"],(function(e,n){Un.prototype[e]=function(i){i=i===t?1:gn(ha(i),0);var r=this.__filtered__&&!n?new Un(this):this.clone();return r.__filtered__?r.__takeCount__=vn(i,r.__takeCount__):r.__views__.push({size:vn(i,l),type:e+(r.__dir__<0?"Right":"")}),r},Un.prototype[e+"Right"]=function(t){return this.reverse()[e](t).reverse()}})),Se(["filter","map","takeWhile"],(function(t,e){var n=e+1,i=1==n||3==n;Un.prototype[t]=function(t){var e=this.clone();return e.__iteratees__.push({iteratee:rs(t,3),type:n}),e.__filtered__=e.__filtered__||i,e}})),Se(["head","last"],(function(t,e){var n="take"+(e?"Right":"");Un.prototype[t]=function(){return this[n](1).value()[0]}})),Se(["initial","tail"],(function(t,e){var n="drop"+(e?"":"Right");Un.prototype[t]=function(){return this.__filtered__?new Un(this):this[n](1)}})),Un.prototype.compact=function(){return this.filter(Ja)},Un.prototype.find=function(t){return this.filter(t).head()},Un.prototype.findLast=function(t){return this.reverse().find(t)},Un.prototype.invokeMap=Gi((function(t,e){return"function"==typeof t?new Un(this):this.map((function(n){return $i(n,t,e)}))})),Un.prototype.reject=function(t){return this.filter(jo(rs(t)))},Un.prototype.slice=function(e,n){e=ha(e);var i=this;return i.__filtered__&&(e>0||n<0)?new Un(i):(e<0?i=i.takeRight(-e):e&&(i=i.drop(e)),n!==t&&(i=(n=ha(n))<0?i.dropRight(-n):i.take(n-e)),i)},Un.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},Un.prototype.toArray=function(){return this.take(l)},wi(Un.prototype,(function(e,n){var i=/^(?:filter|find|map|reject)|While$/.test(n),r=/^(?:head|last)$/.test(n),s=Bn[r?"take"+("last"==n?"Right":""):n],o=r||/^find/.test(n);s&&(Bn.prototype[n]=function(){var n=this.__wrapped__,a=r?[1]:arguments,c=n instanceof Un,l=a[0],h=c||Wo(n),u=function(t){var e=s.apply(Bn,je([t],a));return r&&f?e[0]:e};h&&i&&"function"==typeof l&&1!=l.length&&(c=h=!1);var f=this.__chain__,d=o&&!f,p=c&&!this.__actions__.length;if(!o&&h){n=p?n:new Un(this);var g=e.apply(n,a);return g.__actions__.push({func:co,args:[u],thisArg:t}),new Wn(g,f)}return d&&p?e.apply(this,a):(g=this.thru(u),d?r?g.value()[0]:g.value():g)})})),Se(["pop","push","shift","sort","splice","unshift"],(function(t){var e=Ct[t],n=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",i=/^(?:pop|shift)$/.test(t);Bn.prototype[t]=function(){var t=arguments;if(i&&!this.__chain__){var r=this.value();return e.apply(Wo(r)?r:[],t)}return this[n]((function(n){return e.apply(Wo(n)?n:[],t)}))}})),wi(Un.prototype,(function(t,e){var n=Bn[e];if(n){var i=n.name+"";Et.call(Cn,i)||(Cn[i]=[]),Cn[i].push({name:e,func:n})}})),Cn[Pr(t,2).name]=[{name:"wrapper",func:t}],Un.prototype.clone=function(){var t=new Un(this.__wrapped__);return t.__actions__=Mr(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Mr(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Mr(this.__views__),t},Un.prototype.reverse=function(){if(this.__filtered__){var t=new Un(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},Un.prototype.value=function(){var t=this.__wrapped__.value(),e=this.__dir__,n=Wo(t),i=e<0,r=n?t.length:0,s=function(t,e,n){for(var i=-1,r=n.length;++i<r;){var s=n[i],o=s.size;switch(s.type){case"drop":t+=o;break;case"dropRight":e-=o;break;case"take":e=vn(e,t+o);break;case"takeRight":t=gn(t,e-o)}}return{start:t,end:e}}(0,r,this.__views__),o=s.start,a=s.end,c=a-o,l=i?a:o-1,h=this.__iteratees__,u=h.length,f=0,d=vn(c,this.__takeCount__);if(!n||!i&&r==c&&d==c)return hr(t,this.__actions__);var p=[];t:for(;c--&&f<d;){for(var g=-1,v=t[l+=e];++g<u;){var w=h[g],m=w.type,y=(0,w.iteratee)(v);if(2==m)v=y;else if(!y){if(1==m)continue t;break t}}p[f++]=v}return p},Bn.prototype.at=lo,Bn.prototype.chain=function(){return ao(this)},Bn.prototype.commit=function(){return new Wn(this.value(),this.__chain__)},Bn.prototype.next=function(){this.__values__===t&&(this.__values__=ca(this.value()));var e=this.__index__>=this.__values__.length;return{done:e,value:e?t:this.__values__[this.__index__++]}},Bn.prototype.plant=function(e){for(var n,i=this;i instanceof Rn;){var r=Ls(i);r.__index__=0,r.__values__=t,n?s.__wrapped__=r:n=r;var s=r;i=i.__wrapped__}return s.__wrapped__=e,n},Bn.prototype.reverse=function(){var e=this.__wrapped__;if(e instanceof Un){var n=e;return this.__actions__.length&&(n=new Un(this)),(n=n.reverse()).__actions__.push({func:co,args:[Ys],thisArg:t}),new Wn(n,this.__chain__)}return this.thru(Ys)},Bn.prototype.toJSON=Bn.prototype.valueOf=Bn.prototype.value=function(){return hr(this.__wrapped__,this.__actions__)},Bn.prototype.first=Bn.prototype.head,Zt&&(Bn.prototype[Zt]=function(){return this}),Bn}();fe?((fe.exports=dn)._=dn,ue._=dn):he._=dn}.call(te.exports)),te.exports);
|
|
1
|
+
import{p as t,H as e,c as n,h as i,d as r,t as s}from"./p-B43upypT.js";import{K as o}from"./p-D8W6LE-c.js";import{d as a,D as c,l,i as h,a as u,S as f,c as d,m as p,j as g,n as v,f as w,e as m,b as y,K as b,g as k,k as A}from"./p-CPnjRgkl.js";import{D as x,K as S,a as M}from"./p-CpzicliK.js";import{A as z,a as $,d as C}from"./p-CC0J_kEP.js";import{K as T,W as I}from"./p-DhMlShij.js";import{K as j,c as E,a as _,b as L,d as O}from"./p-BNu3Akp5.js";import{K as P}from"./p-WUdQqYnu.js";import{K as B,d as D}from"./p-BxpKq94F.js";import{O as R}from"./p-Dd-pMvlr.js";import*as W from"yjs";import{a as U,C as F}from"./p-CW-VyJgK.js";import{K,d as V}from"./p-CdR76C4L.js";import{K as N}from"./p-jGOpkGDl.js";import{d as G}from"./p-B4WfPDj0.js";import{d as H}from"./p-B4b6TDxp.js";var X="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};const Y="__kritzelCustomElementRendererRegistry__";class Q{static get _renderers(){return(()=>{const t=globalThis,e=t[Y];if(e)return e;const n={renderers:new Map};return t[Y]=n,n})().renderers}static register(t,e){this._renderers.set(t,e)}static get(t){return this._renderers.get(t)}static unregister(t){return this._renderers.delete(t)}}class Z extends j{__class__="KritzelCustomElement";element;rendererKey=null;rendererData;constructor(t){super(),t&&(this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.rotation=E.degreesToRadians(t.rotation??0),this.scale=t.scale||1,this.element=t.element??this.createPlaceholder(),this.height=t.height||0,this.width=t.width||0,this.rendererKey=t.rendererKey??null,this.rendererData=t.rendererData)}static create(t,e){const n=new Z(e);return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.userId=t.user?.id,n.zIndex=t.store.currentZIndex,n}mount(t){if(null!==t){if(this.applyInteractiveState(),this.isMounted&&this.elementRef===t){if(this.rendererKey)return;if(this.element.parentElement===t)return}if(this.elementRef=t,this.isMounted=!0,this.rendererKey){const e=Q.get(this.rendererKey);if(e)return t.innerHTML="",e.onMount({object:this,container:t,data:this.rendererData}),void this.applyInteractiveState()}this.elementRef.innerHTML="",this.elementRef.appendChild(this.element),this.applyInteractiveState()}}setIsInteractive(t){const e=this.isInteractive!==t;this.isInteractive=t,this.applyInteractiveState(),e&&!t&&this.blurFocusedDescendant()}applyInteractiveState(){const t=this.isInteractive?"auto":"none",e=this.isInteractive?"auto":"";this.element&&(this.element.style.pointerEvents=t,this.element.style.cursor=e),this.elementRef instanceof HTMLElement&&(this.elementRef.style.pointerEvents="auto",this.elementRef.style.cursor="",Array.from(this.elementRef.children).forEach((n=>{n instanceof HTMLElement&&(n.style.pointerEvents=t,n.style.cursor=e)})))}blurFocusedDescendant(){if(!(this.element||this.elementRef instanceof HTMLElement))return;const t=this.getDeepActiveElement(),e=!!this.element&&this.isNodeInsideHost(t,this.element),n=this.elementRef instanceof HTMLElement&&this.isNodeInsideHost(t,this.elementRef);t&&(e||n)&&t.blur()}hasFocusedInputElement(){if(!this.isInteractive)return!1;const t=this.getFocusHosts();if(t.some((t=>this.hasFocusedInputDescendant(t))))return!0;const e=this.getDeepActiveElement();return!!(e&&this.isInputLikeElement(e)&&t.some((t=>this.isNodeInsideHost(e,t))))}getFocusHosts(){const t=[];if(this.element&&t.push(this.element),this.elementRef instanceof HTMLElement){t.push(this.elementRef);const e=this.elementRef.firstElementChild;e instanceof HTMLElement&&t.push(e)}return t}hasFocusedInputDescendant(t){if(this.isInputLikeElement(t)&&this.matchesFocus(t))return!0;if("function"==typeof t.matches)try{if(!t.matches(":focus-within"))return!1}catch{}return null!==this.findFocusedInputLikeElement(t)}findFocusedInputLikeElement(t){let e=null;try{e=t.querySelector(":focus")}catch{e=null}return e instanceof HTMLElement?this.isInputLikeElement(e)?e:e.shadowRoot?this.findFocusedInputLikeElement(e.shadowRoot):null:null}matchesFocus(t){if("function"!=typeof t.matches)return!1;try{return t.matches(":focus")}catch{return!1}}isInputLikeElement(t){const e=t.tagName;return"INPUT"===e||"TEXTAREA"===e||"SELECT"===e||t.isContentEditable}isNodeInsideHost(t,e){if(!t)return!1;let n=t;for(;n;){if(n===e)return!0;if(n.parentNode){n=n.parentNode;continue}const t=n.getRootNode();if(!(t instanceof ShadowRoot))break;n=t.host}return!1}getDeepActiveElement(t=document){const e=t.activeElement;return e instanceof HTMLElement?e.shadowRoot?this.getDeepActiveElement(e.shadowRoot)??e:e:null}unmount(){if(this.isMounted&&this.elementRef){if(this.rendererKey){const t=Q.get(this.rendererKey);if(t){const e=t.onUnmount({object:this,container:this.elementRef,data:this.rendererData});void 0!==e&&(this.rendererData=e)}}this.isMounted=!1,this.elementRef=null}}isElementScrollable(){return!!P.findScrollableElement(this.element)}createPlaceholder(){const t=document.createElement("div");return t.textContent="[Custom Element]",t.style.border="1px dashed #ccc",t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.style.backgroundColor="#f9f9f9",t.style.color="#999",t.style.fontSize="12px",t}resize(t,e,n,i){n<=1||i<=1||(this.width=n,this.height=i,this.translateX=t,this.translateY=e,this.element&&(this.element.style.width=`${n}px`,this.element.style.height=`${i}px`),this._core.store.objects.update(this))}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t.isSelected=!1,t.isHovered=!1,t.isInteractive=!1,t.resizing=!1,t.markedForRemoval=!1,t.isVisible=!0,t.element=this.element.cloneNode(!0),t}serialize(){const{_core:t,_elementRef:e,element:n,totalWidth:i,totalHeight:r,isSelected:s,isHovered:o,isMounted:a,isInteractive:c,resizing:l,markedForRemoval:h,isVisible:u,...f}=this,d=structuredClone(f);return d.rendererKey=this.rendererKey,d.rendererData=this.rendererData,d.htmlString=n?n.outerHTML:"",d.serializedWidth=this.width,d.serializedHeight=this.height,d}deserialize(t){if(super.deserialize(t),delete this.allowEmbeddedInteraction,this.rendererKey=t.rendererKey??null,this.rendererData=t.rendererData,t.htmlString)try{const e=document.createElement("div");e.innerHTML=t.htmlString,this.element=e.firstElementChild||this.createPlaceholder()}catch{this.element=this.createPlaceholder()}else this.element=this.createPlaceholder();return this}}class q extends a{toolType="brush";color=x[0];size=6;opacity=1;palette=[...x];sizes=[...c];static MIN_POINT_DISTANCE_PX=3;_currentPathId=null;shouldAppendPoint(t,e,n,i){const r=t.points;if(!r||0===r.length)return!0;const s=r[r.length-1],o=e-s[0],a=n-s[1],c=q.MIN_POINT_DISTANCE_PX/i;return o*o+a*a>=c*c}constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&l.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=_.create(this._core,{points:[[(t.clientX-this._core.store.offsetX)/i,(t.clientY-this._core.store.offsetY)/i]],translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});r.isCompleted=!1,this._currentPathId=r.id,this._core.store.objects.insert(r),this._core.store.objects?.setActiveDrawingObject(r.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/i),s=Math.round((t[0].clientY-this._core.store.offsetY)/i);this._core.store.state.isDrawing=!0;const o=_.create(this._core,{points:[[r,s]],translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});o.isCompleted=!1,this._currentPathId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentPathId){const e=this._core.store.objects.findById(this._currentPathId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=(t.clientX-this._core.store.offsetX)/r,o=(t.clientY-this._core.store.offsetY)/r;if(!this.shouldAppendPoint(e,s,o,r))return;const a=_.create(this._core,{points:[...e.points,[s,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,fill:this.color,strokeWidth:this.size,opacity:this.opacity});a.id=e.id,a.workspaceId=e.workspaceId,a.zIndex=e.zIndex,a.isCompleted=!1,this._core.store.objects.update(a)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentPathId){const e=this._core.store.objects.findById(this._currentPathId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r);if(!this.shouldAppendPoint(e,s,o,r))return;const a=_.create(this._core,{points:[...e.points,[s,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,fill:this.color,strokeWidth:this.size,opacity:this.opacity});a.id=e.id,a.workspaceId=e.workspaceId,a.zIndex=e.zIndex,a.isCompleted=!1,this._core.store.objects.update(a)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}}}class J extends a{toolType="line";color=x[0];size=4;opacity=1;palette=[...x];sizes=[...c];arrows;_startX=0;_startY=0;_currentLineId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&l.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=(t.clientX-this._core.store.offsetX)/i,s=(t.clientY-this._core.store.offsetY)/i;this._startX=r,this._startY=s;const o=L.create(this._core,{startX:r,startY:s,endX:r,endY:s,translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.state.scale,n=this._core.store.state.lockDrawingScale,i=n?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/i),s=Math.round((t[0].clientY-this._core.store.offsetY)/i);this._core.store.state.isDrawing=!0,this._startX=r,this._startY=s;const o=L.create(this._core,{startX:r,startY:s,endX:r,endY:s,translateX:-this._core.store.state.translateX/i,translateY:-this._core.store.state.translateY/i,scale:n?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.objects.insert(o),this._core.store.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentLineId){const e=this._core.store.objects.findById(this._currentLineId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=L.create(this._core,{startX:this._startX,startY:this._startY,endX:(t.clientX-this._core.store.offsetX)/r,endY:(t.clientY-this._core.store.offsetY)/r,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});s.id=e.id,s.workspaceId=e.workspaceId,s.zIndex=e.zIndex,s.isCompleted=!1,this._core.store.objects.update(s)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentLineId){const e=this._core.store.objects.findById(this._currentLineId);if(e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1,s=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r),a=L.create(this._core,{startX:this._startX,startY:this._startY,endX:s,endY:o,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:n,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});a.id=e.id,a.workspaceId=e.workspaceId,a.zIndex=e.zIndex,a.isCompleted=!1,this._core.store.objects.update(a)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}}selectLineAndSwitchTool(t){const e=h.create(this._core);e.addOrRemove(t),e.isSelected=!0,e.rotation=t.rotation,this._core.addSelectionGroup(e),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection")),this._core.rerender()}}class tt extends a{toolType="eraser";touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&l.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"!==t.pointerType&&"pen"!==t.pointerType||(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||(this._core.store.state.isErasing=!0)}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const e=this._core.getObjectsFromPointerEvent(t,".object");if(0===e.length)return;const n=this._core.store.state.pointerX,i=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(n,i)})),this._core.rerender()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&1===this._core.store.state.pointers.size&&this._core.store.state.isErasing){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const n=this._core.getObjectsFromPointerEvent(t,".object");if(0===n.length)return;const i=this._core.store.state.pointerX,r=this._core.store.state.pointerY;n.forEach((t=>{t.markedForRemoval=t.hitTest(i,r)})),this._core.rerender()}}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}if(("touch"===t.pointerType||"pen"===t.pointerType)&&(clearTimeout(this.touchStartTimeout),this._core.store.state.isErasing)){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}}}function et(t,e){return new Promise((function(n,i){let r;return nt(t).then((function(t){try{return r=t,n(new Blob([e.slice(0,2),r,e.slice(2)],{type:"image/jpeg"}))}catch(t){return i(t)}}),i)}))}const nt=t=>new Promise(((e,n)=>{const i=new FileReader;i.addEventListener("load",(({target:{result:t}})=>{const i=new DataView(t);let r=0;if(65496!==i.getUint16(r))return n("not a valid JPEG");for(r+=2;;){const s=i.getUint16(r);if(65498===s)break;const o=i.getUint16(r+2);if(65505===s&&1165519206===i.getUint32(r+4)){const s=r+10;let a;switch(i.getUint16(s)){case 18761:a=!0;break;case 19789:a=!1;break;default:return n("TIFF header contains invalid endian")}if(42!==i.getUint16(s+2,a))return n("TIFF header contains invalid version");const c=i.getUint32(s+4,a),l=s+c+2+12*i.getUint16(s+c,a);for(let t=s+c+2;t<l;t+=12)if(274==i.getUint16(t,a)){if(3!==i.getUint16(t+2,a))return n("Orientation data type is invalid");if(1!==i.getUint32(t+4,a))return n("Orientation data count is invalid");i.setUint16(t+8,1,a);break}return e(t.slice(r,r+2+o))}r+=2+o}return e(new Blob)})),i.readAsArrayBuffer(t)}));var it={},rt={get exports(){return it},set exports(t){it=t}};!function(){var t,e,n={};rt.exports=n,n.parse=function(t,e){for(var i=n.bin.readUshort,r=n.bin.readUint,s=0,o={},a=new Uint8Array(t),c=a.length-4;101010256!=r(a,c);)c--;s=c,s+=4;var l=i(a,s+=4);i(a,s+=2);var h=r(a,s+=2),u=r(a,s+=4);s+=4,s=u;for(var f=0;f<l;f++){r(a,s),s+=4,s+=4,s+=4,r(a,s+=4),h=r(a,s+=4);var d=r(a,s+=4),p=i(a,s+=4),g=i(a,s+2),v=i(a,s+4);s+=6;var w=r(a,s+=8);s+=4,s+=p+g+v,n._readLocal(a,w,o,h,d,e)}return o},n._readLocal=function(t,e,i,r,s,o){var a=n.bin.readUshort,c=n.bin.readUint;c(t,e),a(t,e+=4),a(t,e+=2);var l=a(t,e+=2);c(t,e+=2),c(t,e+=4),e+=4;var h=a(t,e+=8),u=a(t,e+=2),f=n.bin.readUTF8(t,e+=2,h);if(e+=h,e+=u,o)i[f]={size:s,csize:r};else{var d=new Uint8Array(t.buffer,e);if(0==l)i[f]=new Uint8Array(d.buffer.slice(e,e+r));else{if(8!=l)throw"unknown compression method: "+l;var p=new Uint8Array(s);n.inflateRaw(d,p),i[f]=p}}},n.inflateRaw=function(t,e){return n.F.inflate(t,e)},n.inflate=function(t,e){return n.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),e)},n.deflate=function(t,e){null==e&&(e={level:6});var i=0,r=new Uint8Array(50+Math.floor(1.1*t.length));r[i]=120,r[i+1]=156,i=n.F.deflateRaw(t,r,i+=2,e.level);var s=n.adler(t,0,t.length);return r[i+0]=s>>>24&255,r[i+1]=s>>>16&255,r[i+2]=s>>>8&255,r[i+3]=s>>>0&255,new Uint8Array(r.buffer,0,i+4)},n.deflateRaw=function(t,e){null==e&&(e={level:6});var i=new Uint8Array(50+Math.floor(1.1*t.length)),r=n.F.deflateRaw(t,i,r,e.level);return new Uint8Array(i.buffer,0,r)},n.encode=function(t,e){null==e&&(e=!1);var i=0,r=n.bin.writeUint,s=n.bin.writeUshort,o={};for(var a in t){var c=!n._noNeed(a)&&!e,l=t[a],h=n.crc.crc(l,0,l.length);o[a]={cpr:c,usize:l.length,crc:h,file:c?n.deflateRaw(l):l}}for(var a in o)i+=o[a].file.length+30+46+2*n.bin.sizeUTF8(a);i+=22;var u=new Uint8Array(i),f=0,d=[];for(var a in o){var p=o[a];d.push(f),f=n._writeHeader(u,f,a,p,0)}var g=0,v=f;for(var a in o)p=o[a],d.push(f),f=n._writeHeader(u,f,a,p,1,d[g++]);var w=f-v;return r(u,f,101010256),f+=4,s(u,f+=4,g),s(u,f+=2,g),r(u,f+=2,w),r(u,f+=4,v),f+=4,f+=2,u.buffer},n._noNeed=function(t){var e=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(e)},n._writeHeader=function(t,e,i,r,s,o){var a=n.bin.writeUint,c=n.bin.writeUshort,l=r.file;return a(t,e,0==s?67324752:33639248),e+=4,1==s&&(e+=2),c(t,e,20),c(t,e+=2,0),c(t,e+=2,r.cpr?8:0),a(t,e+=2,0),a(t,e+=4,r.crc),a(t,e+=4,l.length),a(t,e+=4,r.usize),c(t,e+=4,n.bin.sizeUTF8(i)),c(t,e+=2,0),e+=2,1==s&&(e+=2,e+=2,a(t,e+=6,o),e+=4),e+=n.bin.writeUTF8(t,e,i),0==s&&(t.set(l,e),e+=l.length),e},n.crc={table:function(){for(var t=new Uint32Array(256),e=0;e<256;e++){for(var n=e,i=0;i<8;i++)1&n?n=3988292384^n>>>1:n>>>=1;t[e]=n}return t}(),update:function(t,e,i,r){for(var s=0;s<r;s++)t=n.crc.table[255&(t^e[i+s])]^t>>>8;return t},crc:function(t,e,i){return 4294967295^n.crc.update(4294967295,t,e,i)}},n.adler=function(t,e,n){for(var i=1,r=0,s=e,o=e+n;s<o;){for(var a=Math.min(s+5552,o);s<a;)r+=i+=t[s++];i%=65521,r%=65521}return r<<16|i},n.bin={readUshort:function(t,e){return t[e]|t[e+1]<<8},writeUshort:function(t,e,n){t[e]=255&n,t[e+1]=n>>8&255},readUint:function(t,e){return 16777216*t[e+3]+(t[e+2]<<16|t[e+1]<<8|t[e])},writeUint:function(t,e,n){t[e]=255&n,t[e+1]=n>>8&255,t[e+2]=n>>16&255,t[e+3]=n>>24&255},readASCII:function(t,e,n){for(var i="",r=0;r<n;r++)i+=String.fromCharCode(t[e+r]);return i},writeASCII:function(t,e,n){for(var i=0;i<n.length;i++)t[e+i]=n.charCodeAt(i)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,i){for(var r,s="",o=0;o<i;o++)s+="%"+n.bin.pad(t[e+o].toString(16));try{r=decodeURIComponent(s)}catch(r){return n.bin.readASCII(t,e,i)}return r},writeUTF8:function(t,e,n){for(var i=n.length,r=0,s=0;s<i;s++){var o=n.charCodeAt(s);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[e+r]=240|o>>18,t[e+r+1]=128|o>>12&63,t[e+r+2]=128|o>>6&63,t[e+r+3]=128|63&o,r+=4}else t[e+r]=224|o>>12,t[e+r+1]=128|o>>6&63,t[e+r+2]=128|63&o,r+=3;else t[e+r]=192|o>>6,t[e+r+1]=128|63&o,r+=2;else t[e+r]=o,r++}return r},sizeUTF8:function(t){for(var e=t.length,n=0,i=0;i<e;i++){var r=t.charCodeAt(i);if(4294967168&r)if(4294965248&r)if(4294901760&r){if(4292870144&r)throw"e";n+=4}else n+=3;else n+=2;else n++}return n}},n.F={},n.F.deflateRaw=function(t,e,i,r){var s=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][r],o=n.F.U,a=n.F._goodIndex,c=n.F._putsE,l=0,h=i<<3,u=0,f=t.length;if(0==r){for(;l<f;)c(e,h,l+(S=Math.min(65535,f-l))==f?1:0),h=n.F._copyExact(t,l,S,e,h+8),l+=S;return h>>>3}var d=o.lits,p=o.strt,g=o.prev,v=0,w=0,m=0,y=0,b=0,k=0;for(f>2&&(p[k=n.F._hash(t,0)]=0),l=0;l<f;l++){if(b=k,l+1<f-2){k=n.F._hash(t,l+1);var A=l+1&32767;g[A]=p[k],p[k]=A}if(u<=l){(v>14e3||w>26697)&&f-l>100&&(u<l&&(d[v]=l-u,v+=2,u=l),h=n.F._writeBlock(l==f-1||u==f?1:0,d,v,y,t,m,l-m,e,h),v=w=y=0,m=l);var x=0;l<f-2&&(x=n.F._bestMatch(t,l,g,b,Math.min(s[2],f-l),s[3]));var S=x>>>16,M=65535&x;if(0!=x){M=65535&x;var z=a(S=x>>>16,o.of0);o.lhst[257+z]++;var $=a(M,o.df0);o.dhst[$]++,y+=o.exb[z]+o.dxb[$],d[v]=S<<23|l-u,d[v+1]=M<<16|z<<8|$,v+=2,u=l+S}else o.lhst[t[l]]++;w++}}for(m==l&&0!=t.length||(u<l&&(d[v]=l-u,v+=2,u=l),h=n.F._writeBlock(1,d,v,y,t,m,l-m,e,h),v=0,w=0,v=w=y=0,m=l);7&h;)h++;return h>>>3},n.F._bestMatch=function(t,e,i,r,s,o){var a=32767&e,c=i[a],l=a-c+32768&32767;if(c==a||r!=n.F._hash(t,e-l))return 0;for(var h=0,u=0,f=Math.min(32767,e);l<=f&&0!=--o&&c!=a;){if(0==h||t[e+h]==t[e+h-l]){var d=n.F._howLong(t,e,l);if(d>h){if(u=l,(h=d)>=s)break;l+2<d&&(d=l+2);for(var p=0,g=0;g<d-2;g++){var v=e-l+g+32768&32767,w=v-i[v]+32768&32767;w>p&&(p=w,c=v)}}}l+=(a=c)-(c=i[a])+32768&32767}return h<<16|u},n.F._howLong=function(t,e,n){if(t[e]!=t[e-n]||t[e+1]!=t[e+1-n]||t[e+2]!=t[e+2-n])return 0;var i=e,r=Math.min(t.length,e+258);for(e+=3;e<r&&t[e]==t[e-n];)e++;return e-i},n.F._hash=function(t,e){return(t[e]<<8|t[e+1])+(t[e+2]<<4)&65535},n.saved=0,n.F._writeBlock=function(t,e,i,r,s,o,a,c,l){var h,u,f,d,p,g,v,w,m,y=n.F.U,b=n.F._putsF,k=n.F._putsE;y.lhst[256]++,u=(h=n.F.getTrees())[0],f=h[1],d=h[2],p=h[3],g=h[4],v=h[5],w=h[6],m=h[7];var A=32+(l+3&7?8-(l+3&7):0)+(a<<3),x=r+n.F.contSize(y.fltree,y.lhst)+n.F.contSize(y.fdtree,y.dhst),S=r+n.F.contSize(y.ltree,y.lhst)+n.F.contSize(y.dtree,y.dhst);S+=14+3*v+n.F.contSize(y.itree,y.ihst)+(2*y.ihst[16]+3*y.ihst[17]+7*y.ihst[18]);for(var M=0;M<286;M++)y.lhst[M]=0;for(M=0;M<30;M++)y.dhst[M]=0;for(M=0;M<19;M++)y.ihst[M]=0;var z=A<x&&A<S?0:x<S?1:2;if(b(c,l,t),b(c,l+1,z),l+=3,0==z){for(;7&l;)l++;l=n.F._copyExact(s,o,a,c,l)}else{var $,C;if(1==z&&($=y.fltree,C=y.fdtree),2==z){n.F.makeCodes(y.ltree,u),n.F.revCodes(y.ltree,u),n.F.makeCodes(y.dtree,f),n.F.revCodes(y.dtree,f),n.F.makeCodes(y.itree,d),n.F.revCodes(y.itree,d),$=y.ltree,C=y.dtree,k(c,l,p-257),k(c,l+=5,g-1),k(c,l+=5,v-4),l+=4;for(var T=0;T<v;T++)k(c,l+3*T,y.itree[1+(y.ordr[T]<<1)]);l=n.F._codeTiny(w,y.itree,c,l+=3*v),l=n.F._codeTiny(m,y.itree,c,l)}for(var I=o,j=0;j<i;j+=2){for(var E=e[j],_=E>>>23,L=I+(8388607&E);I<L;)l=n.F._writeLit(s[I++],$,c,l);if(0!=_){var O=e[j+1],P=O>>16,B=O>>8&255,D=255&O;k(c,l=n.F._writeLit(257+B,$,c,l),_-y.of0[B]),b(c,l=n.F._writeLit(D,C,c,l+=y.exb[B]),P-y.df0[D]),l+=y.dxb[D],I+=_}}l=n.F._writeLit(256,$,c,l)}return l},n.F._copyExact=function(t,e,n,i,r){var s=r>>>3;return i[s]=n,i[s+1]=n>>>8,i[s+2]=255-i[s],i[s+3]=255-i[s+1],s+=4,i.set(new Uint8Array(t.buffer,e,n),s),r+(n+4<<3)},n.F.getTrees=function(){for(var t=n.F.U,e=n.F._hufTree(t.lhst,t.ltree,15),i=n.F._hufTree(t.dhst,t.dtree,15),r=[],s=n.F._lenCodes(t.ltree,r),o=[],a=n.F._lenCodes(t.dtree,o),c=0;c<r.length;c+=2)t.ihst[r[c]]++;for(c=0;c<o.length;c+=2)t.ihst[o[c]]++;for(var l=n.F._hufTree(t.ihst,t.itree,7),h=19;h>4&&0==t.itree[1+(t.ordr[h-1]<<1)];)h--;return[e,i,l,s,a,h,r,o]},n.F.getSecond=function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(t[n+1]);return e},n.F.nonZero=function(t){for(var e="",n=0;n<t.length;n+=2)0!=t[n+1]&&(e+=(n>>1)+",");return e},n.F.contSize=function(t,e){for(var n=0,i=0;i<e.length;i++)n+=e[i]*t[1+(i<<1)];return n},n.F._codeTiny=function(t,e,i,r){for(var s=0;s<t.length;s+=2){var o=t[s],a=t[s+1];r=n.F._writeLit(o,e,i,r);var c=16==o?2:17==o?3:7;o>15&&(n.F._putsE(i,r,a,c),r+=c)}return r},n.F._lenCodes=function(t,e){for(var n=t.length;2!=n&&0==t[n-1];)n-=2;for(var i=0;i<n;i+=2){var r=t[i+1],s=i+3<n?t[i+3]:-1,o=i+5<n?t[i+5]:-1,a=0==i?-1:t[i-1];if(0==r&&s==r&&o==r){for(var c=i+5;c+2<n&&t[c+2]==r;)c+=2;(l=Math.min(c+1-i>>>1,138))<11?e.push(17,l-3):e.push(18,l-11),i+=2*l-2}else if(r==a&&s==r&&o==r){for(c=i+5;c+2<n&&t[c+2]==r;)c+=2;var l=Math.min(c+1-i>>>1,6);e.push(16,l-3),i+=2*l-2}else e.push(r,0)}return n>>>1},n.F._hufTree=function(t,e,i){var r=[],s=t.length,o=e.length,a=0;for(a=0;a<o;a+=2)e[a]=0,e[a+1]=0;for(a=0;a<s;a++)0!=t[a]&&r.push({lit:a,f:t[a]});var c=r.length,l=r.slice(0);if(0==c)return 0;if(1==c){var h=r[0].lit;return l=0==h?1:0,e[1+(h<<1)]=1,e[1+(l<<1)]=1,1}r.sort((function(t,e){return t.f-e.f}));var u=r[0],f=r[1],d=0,p=1,g=2;for(r[0]={lit:-1,f:u.f+f.f,l:u,r:f,d:0};p!=c-1;)u=d!=p&&(g==c||r[d].f<r[g].f)?r[d++]:r[g++],f=d!=p&&(g==c||r[d].f<r[g].f)?r[d++]:r[g++],r[p++]={lit:-1,f:u.f+f.f,l:u,r:f};var v=n.F.setDepth(r[p-1],0);for(v>i&&(n.F.restrictDepth(l,i,v),v=i),a=0;a<c;a++)e[1+(l[a].lit<<1)]=l[a].d;return v},n.F.setDepth=function(t,e){return-1!=t.lit?(t.d=e,e):Math.max(n.F.setDepth(t.l,e+1),n.F.setDepth(t.r,e+1))},n.F.restrictDepth=function(t,e,n){var i=0,r=1<<n-e,s=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),i=0;i<t.length&&t[i].d>e;i++){var o=t[i].d;t[i].d=e,s+=r-(1<<n-o)}for(s>>>=n-e;s>0;)(o=t[i].d)<e?(t[i].d++,s-=1<<e-o-1):i++;for(;i>=0;i--)t[i].d==e&&s<0&&(t[i].d--,s++);0!=s&&console.log("debt left")},n.F._goodIndex=function(t,e){var n=0;return e[16|n]<=t&&(n|=16),e[8|n]<=t&&(n|=8),e[4|n]<=t&&(n|=4),e[2|n]<=t&&(n|=2),e[1|n]<=t&&(n|=1),n},n.F._writeLit=function(t,e,i,r){return n.F._putsF(i,r,e[t<<1]),r+e[1+(t<<1)]},n.F.inflate=function(t,e){var i=Uint8Array;if(3==t[0]&&0==t[1])return e||new i(0);var r=n.F,s=r._bitsF,o=r._bitsE,a=r._decodeTiny,c=r.makeCodes,l=r.codes2map,h=r._get17,u=r.U,f=null==e;f&&(e=new i(t.length>>>2<<3));for(var d,p,g=0,v=0,w=0,m=0,y=0,b=0,k=0,A=0,x=0;0==g;)if(g=s(t,x,1),v=s(t,x+1,2),x+=3,0!=v){if(f&&(e=n.F._check(e,A+(1<<17))),1==v&&(d=u.flmap,p=u.fdmap,b=511,k=31),2==v){w=o(t,x,5)+257,m=o(t,x+5,5)+1,y=o(t,x+10,4)+4,x+=14;for(var S=0;S<38;S+=2)u.itree[S]=0,u.itree[S+1]=0;var M=1;for(S=0;S<y;S++){var z=o(t,x+3*S,3);u.itree[1+(u.ordr[S]<<1)]=z,z>M&&(M=z)}x+=3*y,c(u.itree,M),l(u.itree,M,u.imap),d=u.lmap,p=u.dmap,x=a(u.imap,(1<<M)-1,w+m,t,x,u.ttree);var $=r._copyOut(u.ttree,0,w,u.ltree);b=(1<<$)-1;var C=r._copyOut(u.ttree,w,m,u.dtree);k=(1<<C)-1,c(u.ltree,$),l(u.ltree,$,d),c(u.dtree,C),l(u.dtree,C,p)}for(;;){var T=d[h(t,x)&b];x+=15&T;var I=T>>>4;if(I>>>8==0)e[A++]=I;else{if(256==I)break;var j=A+I-254;if(I>264){var E=u.ldef[I-257];j=A+(E>>>3)+o(t,x,7&E),x+=7&E}var _=p[h(t,x)&k],L=u.ddef[_>>>4],O=(L>>>4)+s(t,x+=15&_,15&L);for(x+=15&L,f&&(e=n.F._check(e,A+(1<<17)));A<j;)e[A]=e[A++-O],e[A]=e[A++-O],e[A]=e[A++-O],e[A]=e[A++-O];A=j}}}else{7&x&&(x+=8-(7&x));var P=4+(x>>>3),B=t[P-4]|t[P-3]<<8;f&&(e=n.F._check(e,A+B)),e.set(new i(t.buffer,t.byteOffset+P,B),A),x=P+B<<3,A+=B}return e.length==A?e:e.slice(0,A)},n.F._check=function(t,e){var n=t.length;if(e<=n)return t;var i=new Uint8Array(Math.max(n<<1,e));return i.set(t,0),i},n.F._decodeTiny=function(t,e,i,r,s,o){for(var a=n.F._bitsE,c=n.F._get17,l=0;l<i;){var h=t[c(r,s)&e];s+=15&h;var u=h>>>4;if(u<=15)o[l]=u,l++;else{var f=0,d=0;16==u?(d=3+a(r,s,2),s+=2,f=o[l-1]):17==u?(d=3+a(r,s,3),s+=3):18==u&&(d=11+a(r,s,7),s+=7);for(var p=l+d;l<p;)o[l]=f,l++}}return s},n.F._copyOut=function(t,e,n,i){for(var r=0,s=0,o=i.length>>>1;s<n;){var a=t[s+e];i[s<<1]=0,i[1+(s<<1)]=a,a>r&&(r=a),s++}for(;s<o;)i[s<<1]=0,i[1+(s<<1)]=0,s++;return r},n.F.makeCodes=function(t,e){for(var i,r,s,o,a=n.F.U,c=t.length,l=a.bl_count,h=0;h<=e;h++)l[h]=0;for(h=1;h<c;h+=2)l[t[h]]++;var u=a.next_code;for(i=0,l[0]=0,r=1;r<=e;r++)u[r]=i=i+l[r-1]<<1;for(s=0;s<c;s+=2)0!=(o=t[s+1])&&(t[s]=u[o],u[o]++)},n.F.codes2map=function(t,e,i){for(var r=t.length,s=n.F.U.rev15,o=0;o<r;o+=2)if(0!=t[o+1])for(var a=t[o+1],c=o>>1<<4|a,l=e-a,h=t[o]<<l,u=h+(1<<l);h!=u;)i[s[h]>>>15-e]=c,h++},n.F.revCodes=function(t,e){for(var i=n.F.U.rev15,r=15-e,s=0;s<t.length;s+=2)t[s]=i[t[s]<<e-t[s+1]]>>>r},n.F._putsE=function(t,e,n){var i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8},n.F._putsF=function(t,e,n){var i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8,t[i+2]|=n>>>16},n.F._bitsE=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<n)-1},n.F._bitsF=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<n)-1},n.F._get17=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},n.F._get25=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},n.F.U=(t=Uint16Array,e=Uint32Array,{next_code:new t(16),bl_count:new t(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new t(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new e(32),flmap:new t(512),fltree:[],fdmap:new t(32),fdtree:[],lmap:new t(32768),ltree:[],ttree:[],dmap:new t(32768),dtree:[],imap:new t(512),itree:[],rev15:new t(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=n.F.U,e=0;e<32768;e++){var i=e;i=(4278255360&(i=(4042322160&(i=(3435973836&(i=(2863311530&i)>>>1|(1431655765&i)<<1))>>>2|(858993459&i)<<2))>>>4|(252645135&i)<<4))>>>8|(16711935&i)<<8,t.rev15[e]=(i>>>16|i<<16)>>>17}function r(t,e,n){for(;0!=e--;)t.push(0,n)}for(e=0;e<32;e++)t.ldef[e]=t.of0[e]<<3|t.exb[e],t.ddef[e]=t.df0[e]<<4|t.dxb[e];r(t.fltree,144,8),r(t.fltree,112,9),r(t.fltree,24,7),r(t.fltree,8,8),n.F.makeCodes(t.fltree,9),n.F.codes2map(t.fltree,9,t.flmap),n.F.revCodes(t.fltree,9),r(t.fdtree,32,5),n.F.makeCodes(t.fdtree,5),n.F.codes2map(t.fdtree,5,t.fdmap),n.F.revCodes(t.fdtree,5),r(t.itree,19,0),r(t.ltree,286,0),r(t.dtree,30,0),r(t.ttree,320,0)}()}();var st=function(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(n){if("default"!==n&&!(n in t)){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}}))})),Object.freeze(t)}({__proto__:null,default:it},[it]);const ot=function(){var t={nextZero(t,e){for(;0!=t[e];)e++;return e},readUshort:(t,e)=>t[e]<<8|t[e+1],writeUshort(t,e,n){t[e]=n>>8&255,t[e+1]=255&n},readUint:(t,e)=>16777216*t[e]+(t[e+1]<<16|t[e+2]<<8|t[e+3]),writeUint(t,e,n){t[e]=n>>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n},readASCII(t,e,n){let i="";for(let r=0;r<n;r++)i+=String.fromCharCode(t[e+r]);return i},writeASCII(t,e,n){for(let i=0;i<n.length;i++)t[e+i]=n.charCodeAt(i)},readBytes(t,e,n){const i=[];for(let r=0;r<n;r++)i.push(t[e+r]);return i},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,n,i){let r,s="";for(let r=0;r<i;r++)s+=`%${t.pad(e[n+r].toString(16))}`;try{r=decodeURIComponent(s)}catch(r){return t.readASCII(e,n,i)}return r}};function e(e,n,i,r){const o=n*i,a=s(r),c=Math.ceil(n*a/8),l=new Uint8Array(4*o),h=new Uint32Array(l.buffer),{ctype:u}=r,{depth:f}=r,d=t.readUshort;if(6==u){const t=o<<2;if(8==f)for(var p=0;p<t;p+=4)l[p]=e[p],l[p+1]=e[p+1],l[p+2]=e[p+2],l[p+3]=e[p+3];if(16==f)for(p=0;p<t;p++)l[p]=e[p<<1]}else if(2==u){const t=r.tabs.tRNS;if(null==t){if(8==f)for(p=0;p<o;p++){var g=3*p;h[p]=255<<24|e[g+2]<<16|e[g+1]<<8|e[g]}if(16==f)for(p=0;p<o;p++)h[p]=255<<24|e[4+(g=6*p)]<<16|e[g+2]<<8|e[g]}else{var v=t[0];const n=t[1],i=t[2];if(8==f)for(p=0;p<o;p++){var w=p<<2;h[p]=255<<24|e[2+(g=3*p)]<<16|e[g+1]<<8|e[g],e[g]==v&&e[g+1]==n&&e[g+2]==i&&(l[w+3]=0)}if(16==f)for(p=0;p<o;p++)w=p<<2,h[p]=255<<24|e[4+(g=6*p)]<<16|e[g+2]<<8|e[g],d(e,g)==v&&d(e,g+2)==n&&d(e,g+4)==i&&(l[w+3]=0)}}else if(3==u){const t=r.tabs.PLTE,s=r.tabs.tRNS,a=s?s.length:0;if(1==f)for(var m=0;m<i;m++){var y=m*c,b=m*n;for(p=0;p<n;p++){var k=3*(A=e[y+(p>>3)]>>7-(7&p)&1);l[w=b+p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255}}if(2==f)for(m=0;m<i;m++)for(y=m*c,b=m*n,p=0;p<n;p++)k=3*(A=e[y+(p>>2)]>>6-((3&p)<<1)&3),l[w=b+p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255;if(4==f)for(m=0;m<i;m++)for(y=m*c,b=m*n,p=0;p<n;p++)k=3*(A=e[y+(p>>1)]>>4-((1&p)<<2)&15),l[w=b+p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255;if(8==f)for(p=0;p<o;p++){var A;k=3*(A=e[p]),l[w=p<<2]=t[k],l[w+1]=t[k+1],l[w+2]=t[k+2],l[w+3]=A<a?s[A]:255}}else if(4==u){if(8==f)for(p=0;p<o;p++){var x=e[S=p<<1];l[w=p<<2]=x,l[w+1]=x,l[w+2]=x,l[w+3]=e[S+1]}if(16==f)for(p=0;p<o;p++){var S;x=e[S=p<<2],l[w=p<<2]=x,l[w+1]=x,l[w+2]=x,l[w+3]=e[S+2]}}else if(0==u)for(v=r.tabs.tRNS?r.tabs.tRNS:-1,m=0;m<i;m++){const t=m*c,i=m*n;if(1==f)for(var M=0;M<n;M++){var z=(x=255*(e[t+(M>>>3)]>>>7-(7&M)&1))==255*v?0:255;h[i+M]=z<<24|x<<16|x<<8|x}else if(2==f)for(M=0;M<n;M++)z=(x=85*(e[t+(M>>>2)]>>>6-((3&M)<<1)&3))==85*v?0:255,h[i+M]=z<<24|x<<16|x<<8|x;else if(4==f)for(M=0;M<n;M++)z=(x=17*(e[t+(M>>>1)]>>>4-((1&M)<<2)&15))==17*v?0:255,h[i+M]=z<<24|x<<16|x<<8|x;else if(8==f)for(M=0;M<n;M++)z=(x=e[t+M])==v?0:255,h[i+M]=z<<24|x<<16|x<<8|x;else if(16==f)for(M=0;M<n;M++)x=e[t+(M<<1)],z=d(e,t+(M<<1))==v?0:255,h[i+M]=z<<24|x<<16|x<<8|x}return l}function n(t,e,n,a){const c=s(t),l=Math.ceil(n*c/8),h=new Uint8Array((l+1+t.interlace)*a);return e=t.tabs.CgBI?r(e,h):i(e,h),0==t.interlace?e=o(e,t,0,n,a):1==t.interlace&&(e=function(t,e){const n=e.width,i=e.height,r=s(e),a=r>>3,c=Math.ceil(n*r/8),l=new Uint8Array(i*c);let h=0;const u=[0,0,4,0,2,0,1],f=[0,4,0,2,0,1,0],d=[8,8,8,4,4,2,2],p=[8,8,4,4,2,2,1];let g=0;for(;g<7;){const s=d[g],w=p[g];let m=0,y=0,b=u[g];for(;b<i;)b+=s,y++;let k=f[g];for(;k<n;)k+=w,m++;const A=Math.ceil(m*r/8);o(t,e,h,m,y);let x=0,S=u[g];for(;S<i;){let e=f[g],i=h+x*A<<3;for(;e<n;){var v;if(1==r&&(v=(v=t[i>>3])>>7-(7&i)&1,l[S*c+(e>>3)]|=v<<7-(7&e)),2==r&&(v=(v=t[i>>3])>>6-(7&i)&3,l[S*c+(e>>2)]|=v<<6-((3&e)<<1)),4==r&&(v=(v=t[i>>3])>>4-(7&i)&15,l[S*c+(e>>1)]|=v<<4-((1&e)<<2)),r>=8){const n=S*c+e*a;for(let e=0;e<a;e++)l[n+e]=t[(i>>3)+e]}i+=r,e+=w}x++,S+=s}m*y!=0&&(h+=y*(1+A)),g+=1}return l}(e,t)),e}function i(t,e){return r(new Uint8Array(t.buffer,2,t.length-6),e)}var r=function(){const t={H:{}};return t.H.N=function(e,n){const i=Uint8Array;let r,s,o=0,a=0,c=0,l=0,h=0,u=0,f=0,d=0,p=0;if(3==e[0]&&0==e[1])return n||new i(0);const g=t.H,v=g.b,w=g.e,m=g.R,y=g.n,b=g.A,k=g.Z,A=g.m,x=null==n;for(x&&(n=new i(e.length>>>2<<5));0==o;)if(o=v(e,p,1),a=v(e,p+1,2),p+=3,0!=a){if(x&&(n=t.H.W(n,d+(1<<17))),1==a&&(r=A.J,s=A.h,u=511,f=31),2==a){c=w(e,p,5)+257,l=w(e,p+5,5)+1,h=w(e,p+10,4)+4,p+=14;let t=1;for(var S=0;S<38;S+=2)A.Q[S]=0,A.Q[S+1]=0;for(S=0;S<h;S++){const n=w(e,p+3*S,3);A.Q[1+(A.X[S]<<1)]=n,n>t&&(t=n)}p+=3*h,y(A.Q,t),b(A.Q,t,A.u),r=A.w,s=A.d,p=m(A.u,(1<<t)-1,c+l,e,p,A.v);const n=g.V(A.v,0,c,A.C);u=(1<<n)-1;const i=g.V(A.v,c,l,A.D);f=(1<<i)-1,y(A.C,n),b(A.C,n,r),y(A.D,i),b(A.D,i,s)}for(;;){const t=r[k(e,p)&u];p+=15&t;const i=t>>>4;if(i>>>8==0)n[d++]=i;else{if(256==i)break;{let t=d+i-254;if(i>264){const n=A.q[i-257];t=d+(n>>>3)+w(e,p,7&n),p+=7&n}const r=s[k(e,p)&f];p+=15&r;const o=A.c[r>>>4],a=(o>>>4)+v(e,p,15&o);for(p+=15&o;d<t;)n[d]=n[d++-a],n[d]=n[d++-a],n[d]=n[d++-a],n[d]=n[d++-a];d=t}}}}else{7&p&&(p+=8-(7&p));const r=4+(p>>>3),s=e[r-4]|e[r-3]<<8;x&&(n=t.H.W(n,d+s)),n.set(new i(e.buffer,e.byteOffset+r,s),d),p=r+s<<3,d+=s}return n.length==d?n:n.slice(0,d)},t.H.W=function(t,e){const n=t.length;if(e<=n)return t;const i=new Uint8Array(n<<1);return i.set(t,0),i},t.H.R=function(e,n,i,r,s,o){const a=t.H.e,c=t.H.Z;let l=0;for(;l<i;){const t=e[c(r,s)&n];s+=15&t;const i=t>>>4;if(i<=15)o[l]=i,l++;else{let t=0,e=0;16==i?(e=3+a(r,s,2),s+=2,t=o[l-1]):17==i?(e=3+a(r,s,3),s+=3):18==i&&(e=11+a(r,s,7),s+=7);const n=l+e;for(;l<n;)o[l]=t,l++}}return s},t.H.V=function(t,e,n,i){let r=0,s=0;const o=i.length>>>1;for(;s<n;){const n=t[s+e];i[s<<1]=0,i[1+(s<<1)]=n,n>r&&(r=n),s++}for(;s<o;)i[s<<1]=0,i[1+(s<<1)]=0,s++;return r},t.H.n=function(e,n){const i=t.H.m,r=e.length;let s,o,a,c;const l=i.j;for(var h=0;h<=n;h++)l[h]=0;for(h=1;h<r;h+=2)l[e[h]]++;const u=i.K;for(s=0,l[0]=0,o=1;o<=n;o++)s=s+l[o-1]<<1,u[o]=s;for(a=0;a<r;a+=2)c=e[a+1],0!=c&&(e[a]=u[c],u[c]++)},t.H.A=function(e,n,i){const r=e.length,s=t.H.m.r;for(let t=0;t<r;t+=2)if(0!=e[t+1]){const r=e[t+1],o=t>>1<<4|r,a=n-r;let c=e[t]<<a;const l=c+(1<<a);for(;c!=l;)i[s[c]>>>15-n]=o,c++}},t.H.l=function(e,n){const i=t.H.m.r,r=15-n;for(let t=0;t<e.length;t+=2)e[t]=i[e[t]<<n-e[t+1]]>>>r},t.H.M=function(t,e,n){const i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8},t.H.I=function(t,e,n){const i=e>>>3;t[i]|=n<<=7&e,t[i+1]|=n>>>8,t[i+2]|=n>>>16},t.H.e=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<n)-1},t.H.b=function(t,e,n){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<n)-1},t.H.Z=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},t.H.i=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},t.H.m=function(){const t=Uint16Array,e=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new e(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new e(286),Y:new e(30),a:new e(19),t:new e(15e3),k:new t(65536),g:new t(32768)}}(),function(){const e=t.H.m;for(var n=0;n<32768;n++){let t=n;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,e.r[n]=(t>>>16|t<<16)>>>17}function i(t,e,n){for(;0!=e--;)t.push(0,n)}for(n=0;n<32;n++)e.q[n]=e.S[n]<<3|e.T[n],e.c[n]=e.p[n]<<4|e.z[n];i(e._,144,8),i(e._,112,9),i(e._,24,7),i(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),i(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),i(e.Q,19,0),i(e.C,286,0),i(e.D,30,0),i(e.v,320,0)}(),t.H.N}();function s(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,e,n,i,r){let o=s(e);const c=Math.ceil(i*o/8);let l,h;o=Math.ceil(o/8);let u=t[n],f=0;if(u>1&&(t[n]=[0,0,1][u-2]),3==u)for(f=o;f<c;f++)t[f+1]=t[f+1]+(t[f+1-o]>>>1)&255;for(let e=0;e<r;e++)if(l=n+e*c,h=l+e+1,u=t[h-1],f=0,0==u)for(;f<c;f++)t[l+f]=t[h+f];else if(1==u){for(;f<o;f++)t[l+f]=t[h+f];for(;f<c;f++)t[l+f]=t[h+f]+t[l+f-o]}else if(2==u)for(;f<c;f++)t[l+f]=t[h+f]+t[l+f-c];else if(3==u){for(;f<o;f++)t[l+f]=t[h+f]+(t[l+f-c]>>>1);for(;f<c;f++)t[l+f]=t[h+f]+(t[l+f-c]+t[l+f-o]>>>1)}else{for(;f<o;f++)t[l+f]=t[h+f]+a(0,t[l+f-c],0);for(;f<c;f++)t[l+f]=t[h+f]+a(t[l+f-o],t[l+f-c],t[l+f-o-c])}return t}function a(t,e,n){const i=t+e-n,r=i-t,s=i-e,o=i-n;return r*r<=s*s&&r*r<=o*o?t:s*s<=o*o?e:n}function c(e,n,i){i.width=t.readUint(e,n),i.height=t.readUint(e,n+=4),i.depth=e[n+=4],n++,i.ctype=e[n],n++,i.compress=e[n],n++,i.filter=e[n],n++,i.interlace=e[n],n++}function l(t,e,n,i,r,s,o,a,c){const l=Math.min(e,r),h=Math.min(n,s);let u=0,f=0;for(let n=0;n<h;n++)for(let s=0;s<l;s++)if(o>=0&&a>=0?(u=n*e+s<<2,f=(a+n)*r+o+s<<2):(u=(-a+n)*e-o+s<<2,f=n*r+s<<2),0==c)i[f]=t[u],i[f+1]=t[u+1],i[f+2]=t[u+2],i[f+3]=t[u+3];else if(1==c){var d=t[u+3]*(1/255),p=t[u]*d,g=t[u+1]*d,v=t[u+2]*d,w=i[f+3]*(1/255),m=i[f]*w,y=i[f+1]*w,b=i[f+2]*w;const e=1-d,n=d+w*e,r=0==n?0:1/n;i[f+3]=255*n,i[f+0]=(p+m*e)*r,i[f+1]=(g+y*e)*r,i[f+2]=(v+b*e)*r}else if(2==c)p=t[u],g=t[u+1],v=t[u+2],m=i[f],y=i[f+1],b=i[f+2],(d=t[u+3])==(w=i[f+3])&&p==m&&g==y&&v==b?(i[f]=0,i[f+1]=0,i[f+2]=0,i[f+3]=0):(i[f]=p,i[f+1]=g,i[f+2]=v,i[f+3]=d);else if(3==c){if(p=t[u],g=t[u+1],v=t[u+2],m=i[f],y=i[f+1],b=i[f+2],(d=t[u+3])==(w=i[f+3])&&p==m&&g==y&&v==b)continue;if(d<220&&w>20)return!1}return!0}return{decode:function(e){const s=new Uint8Array(e);let o=8;const a=t,l=a.readUshort,h=a.readUint,u={tabs:{},frames:[]},f=new Uint8Array(s.length);let d,p=0,g=0;const v=[137,80,78,71,13,10,26,10];for(var w=0;w<8;w++)if(s[w]!=v[w])throw"The input is not a PNG file!";for(;o<s.length;){const t=a.readUint(s,o);o+=4;const e=a.readASCII(s,o,4);if(o+=4,"IHDR"==e)c(s,o,u);else if("iCCP"==e){for(var m=o;0!=s[m];)m++;a.readASCII(s,o,m-o);const n=s.slice(m+2,o+t);let c=null;try{c=i(n)}catch(t){c=r(n)}u.tabs[e]=c}else if("CgBI"==e)u.tabs[e]=s.slice(o,o+4);else if("IDAT"==e){for(w=0;w<t;w++)f[p+w]=s[o+w];p+=t}else if("acTL"==e)u.tabs[e]={num_frames:h(s,o),num_plays:h(s,o+4)},d=new Uint8Array(s.length);else if("fcTL"==e){0!=g&&((S=u.frames[u.frames.length-1]).data=n(u,d.slice(0,g),S.rect.width,S.rect.height),g=0);const t={x:h(s,o+12),y:h(s,o+16),width:h(s,o+4),height:h(s,o+8)};let e=l(s,o+22);e=l(s,o+20)/(0==e?100:e);const i={rect:t,delay:Math.round(1e3*e),dispose:s[o+24],blend:s[o+25]};u.frames.push(i)}else if("fdAT"==e){for(w=0;w<t-4;w++)d[g+w]=s[o+w+4];g+=t-4}else if("pHYs"==e)u.tabs[e]=[a.readUint(s,o),a.readUint(s,o+4),s[o+8]];else if("cHRM"==e)for(u.tabs[e]=[],w=0;w<8;w++)u.tabs[e].push(a.readUint(s,o+4*w));else if("tEXt"==e||"zTXt"==e){null==u.tabs[e]&&(u.tabs[e]={});var y=a.nextZero(s,o),b=a.readASCII(s,o,y-o),k=o+t-y-1;if("tEXt"==e)x=a.readASCII(s,y+1,k);else{var A=i(s.slice(y+2,y+2+k));x=a.readUTF8(A,0,A.length)}u.tabs[e][b]=x}else if("iTXt"==e){null==u.tabs[e]&&(u.tabs[e]={}),y=0,y=a.nextZero(s,m=o),b=a.readASCII(s,m,y-m);const n=s[m=y+1];var x;y=a.nextZero(s,m+=2),a.readASCII(s,m,y-m),y=a.nextZero(s,m=y+1),a.readUTF8(s,m,y-m),k=t-((m=y+1)-o),0==n?x=a.readUTF8(s,m,k):(A=i(s.slice(m,m+k)),x=a.readUTF8(A,0,A.length)),u.tabs[e][b]=x}else if("PLTE"==e)u.tabs[e]=a.readBytes(s,o,t);else if("hIST"==e){const t=u.tabs.PLTE.length/3;for(u.tabs[e]=[],w=0;w<t;w++)u.tabs[e].push(l(s,o+2*w))}else if("tRNS"==e)3==u.ctype?u.tabs[e]=a.readBytes(s,o,t):0==u.ctype?u.tabs[e]=l(s,o):2==u.ctype&&(u.tabs[e]=[l(s,o),l(s,o+2),l(s,o+4)]);else if("gAMA"==e)u.tabs[e]=a.readUint(s,o)/1e5;else if("sRGB"==e)u.tabs[e]=s[o];else if("bKGD"==e)0==u.ctype||4==u.ctype?u.tabs[e]=[l(s,o)]:2==u.ctype||6==u.ctype?u.tabs[e]=[l(s,o),l(s,o+2),l(s,o+4)]:3==u.ctype&&(u.tabs[e]=s[o]);else if("IEND"==e)break;o+=t,a.readUint(s,o),o+=4}var S;return 0!=g&&((S=u.frames[u.frames.length-1]).data=n(u,d.slice(0,g),S.rect.width,S.rect.height)),u.data=n(u,f,u.width,u.height),delete u.compress,delete u.interlace,delete u.filter,u},toRGBA8:function(t){const n=t.width,i=t.height;if(null==t.tabs.acTL)return[e(t.data,n,i,t).buffer];const r=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const s=n*i*4,o=new Uint8Array(s),a=new Uint8Array(s),c=new Uint8Array(s);for(let u=0;u<t.frames.length;u++){const f=t.frames[u],d=f.rect.x,p=f.rect.y,g=f.rect.width,v=f.rect.height,w=e(f.data,g,v,t);if(0!=u)for(var h=0;h<s;h++)c[h]=o[h];if(0==f.blend?l(w,g,v,o,n,i,d,p,0):1==f.blend&&l(w,g,v,o,n,i,d,p,1),r.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)l(a,g,v,o,n,i,d,p,0);else if(2==f.dispose)for(h=0;h<s;h++)o[h]=c[h]}return r},_paeth:a,_copyTile:l,_bin:t}}();!function(){const{_copyTile:t}=ot,{_bin:e}=ot,n=ot._paeth;var i={table:function(){const t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=3988292384^n>>>1:n>>>=1;t[e]=n}return t}(),update(t,e,n,r){for(let s=0;s<r;s++)t=i.table[255&(t^e[n+s])]^t>>>8;return t},crc:(t,e,n)=>4294967295^i.update(4294967295,t,e,n)};function r(t,e,n,i){e[n]+=t[0]*i>>4,e[n+1]+=t[1]*i>>4,e[n+2]+=t[2]*i>>4,e[n+3]+=t[3]*i>>4}function s(t){return Math.max(0,Math.min(255,t))}function o(t,e){const n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2],s=t[3]-e[3];return n*n+i*i+r*r+s*s}function a(t,e,n,i,a,c,l){null==l&&(l=1);const h=i.length,u=[];for(var f=0;f<h;f++){const t=i[f];u.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<h;f++){let t=4294967295;for(var d=0,p=0;p<h;p++){var g=o(u[f],u[p]);p!=f&&g<t&&(t=g,d=p)}}const v=new Uint32Array(a.buffer),w=new Int16Array(e*n*4),m=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<m.length;f++)m[f]=255*((m[f]+.5)/16-.5);for(let a=0;a<n;a++)for(let b=0;b<e;b++){var y;f=4*(a*e+b),y=2!=l?[s(t[f]+w[f]),s(t[f+1]+w[f+1]),s(t[f+2]+w[f+2]),s(t[f+3]+w[f+3])]:[s(t[f]+(g=m[4*(3&a)+(3&b)])),s(t[f+1]+g),s(t[f+2]+g),s(t[f+3]+g)],d=0;let k=16777215;for(p=0;p<h;p++){const t=o(y,u[p]);t<k&&(k=t,d=p)}const A=u[d],x=[y[0]-A[0],y[1]-A[1],y[2]-A[2],y[3]-A[3]];1==l&&(b!=e-1&&r(x,w,f+4,7),a!=n-1&&(0!=b&&r(x,w,f+4*e-4,3),r(x,w,f+4*e,5),b!=e-1&&r(x,w,f+4*e+4,1))),c[f>>2]=d,v[f>>2]=i[d]}}function c(t,n,r,s,o){null==o&&(o={});const{crc:a}=i,c=e.writeUint,l=e.writeUshort,h=e.writeASCII;let u=8;const f=t.frames.length>1;let d,p=!1,g=33+(f?20:0);if(null!=o.sRGB&&(g+=13),null!=o.pHYs&&(g+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),g+=21+d.length+4),3==t.ctype){for(var v=t.plte.length,w=0;w<v;w++)t.plte[w]>>>24!=255&&(p=!0);g+=8+3*v+4+(p?8+1*v+4:0)}for(var m=0;m<t.frames.length;m++)f&&(g+=38),g+=(A=t.frames[m]).cimg.length+12,0!=m&&(g+=4);g+=12;const y=new Uint8Array(g),b=[137,80,78,71,13,10,26,10];for(w=0;w<8;w++)y[w]=b[w];if(c(y,u,13),u+=4,h(y,u,"IHDR"),u+=4,c(y,u,n),u+=4,c(y,u,r),u+=4,y[u]=t.depth,u++,y[u]=t.ctype,u++,y[u]=0,u++,y[u]=0,u++,y[u]=0,u++,c(y,u,a(y,u-17,17)),u+=4,null!=o.sRGB&&(c(y,u,1),u+=4,h(y,u,"sRGB"),u+=4,y[u]=o.sRGB,u++,c(y,u,a(y,u-5,5)),u+=4),null!=o.iCCP){const t=13+d.length;c(y,u,t),u+=4,h(y,u,"iCCP"),u+=4,h(y,u,"ICC profile"),u+=11,u+=2,y.set(d,u),u+=d.length,c(y,u,a(y,u-(t+4),t+4)),u+=4}if(null!=o.pHYs&&(c(y,u,9),u+=4,h(y,u,"pHYs"),u+=4,c(y,u,o.pHYs[0]),u+=4,c(y,u,o.pHYs[1]),u+=4,y[u]=o.pHYs[2],u++,c(y,u,a(y,u-13,13)),u+=4),f&&(c(y,u,8),u+=4,h(y,u,"acTL"),u+=4,c(y,u,t.frames.length),u+=4,c(y,u,null!=o.loop?o.loop:0),u+=4,c(y,u,a(y,u-12,12)),u+=4),3==t.ctype){for(c(y,u,3*(v=t.plte.length)),u+=4,h(y,u,"PLTE"),u+=4,w=0;w<v;w++){const e=3*w,n=t.plte[w],i=n>>>8&255,r=n>>>16&255;y[u+e+0]=255&n,y[u+e+1]=i,y[u+e+2]=r}if(u+=3*v,c(y,u,a(y,u-3*v-4,3*v+4)),u+=4,p){for(c(y,u,v),u+=4,h(y,u,"tRNS"),u+=4,w=0;w<v;w++)y[u+w]=t.plte[w]>>>24&255;u+=v,c(y,u,a(y,u-v-4,v+4)),u+=4}}let k=0;for(m=0;m<t.frames.length;m++){var A=t.frames[m];f&&(c(y,u,26),u+=4,h(y,u,"fcTL"),u+=4,c(y,u,k++),u+=4,c(y,u,A.rect.width),u+=4,c(y,u,A.rect.height),u+=4,c(y,u,A.rect.x),u+=4,c(y,u,A.rect.y),u+=4,l(y,u,s[m]),u+=2,l(y,u,1e3),u+=2,y[u]=A.dispose,u++,y[u]=A.blend,u++,c(y,u,a(y,u-30,30)),u+=4);const e=A.cimg;c(y,u,(v=e.length)+(0==m?0:4)),u+=4;const n=u;h(y,u,0==m?"IDAT":"fdAT"),u+=4,0!=m&&(c(y,u,k++),u+=4),y.set(e,u),u+=v,c(y,u,a(y,n,u-n)),u+=4}return c(y,u,0),u+=4,h(y,u,"IEND"),u+=4,c(y,u,a(y,u-4,4)),u+=4,y.buffer}function l(t,e,n){for(let i=0;i<t.frames.length;i++){const r=t.frames[i],s=r.rect.height,o=new Uint8Array(s*r.bpl+s);r.cimg=d(r.img,s,r.bpp,r.bpl,o,e,n)}}function h(e,n,i,r,s){const o=s[0],c=s[1],l=s[2],h=s[3],d=s[4],p=s[5];let v=6,w=8,m=255;for(var y=0;y<e.length;y++){const t=new Uint8Array(e[y]);for(var b=t.length,k=0;k<b;k+=4)m&=t[k+3]}const A=255!=m,x=function(e,n,i,r,s,o){const a=[];for(var c=0;c<e.length;c++){const u=new Uint8Array(e[c]),d=new Uint32Array(u.buffer);var l;let g=0,v=0,w=n,m=i,y=r?1:0;if(0!=c){const b=o||r||1==c||0!=a[c-2].dispose?1:2;let k=0,A=1e9;for(let t=0;t<b;t++){var h=new Uint8Array(e[c-1-t]);const r=new Uint32Array(e[c-1-t]);let o=n,a=i,l=-1,u=-1;for(let t=0;t<i;t++)for(let e=0;e<n;e++)d[p=t*n+e]!=r[p]&&(e<o&&(o=e),e>l&&(l=e),t<a&&(a=t),t>u&&(u=t));-1==l&&(o=a=l=u=0),s&&(!(1&~o)&&o--,!(1&~a)&&a--);const f=(l-o+1)*(u-a+1);f<A&&(A=f,k=t,g=o,v=a,w=l-o+1,m=u-a+1)}h=new Uint8Array(e[c-1-k]),1==k&&(a[c-1].dispose=2),l=new Uint8Array(w*m*4),t(h,n,i,l,w,m,-g,-v,0),y=t(u,n,i,l,w,m,-g,-v,3)?1:0,1==y?f(u,n,i,l,{x:g,y:v,width:w,height:m}):t(u,n,i,l,w,m,-g,-v,0)}else l=u.slice(0);a.push({rect:{x:g,y:v,width:w,height:m},img:l,blend:y,dispose:0})}if(r)for(c=0;c<a.length;c++){if(1==(g=a[c]).blend)continue;const t=g.rect,r=a[c-1].rect,o=Math.min(t.x,r.x),l=Math.min(t.y,r.y),h={x:o,y:l,width:Math.max(t.x+t.width,r.x+r.width)-o,height:Math.max(t.y+t.height,r.y+r.height)-l};a[c-1].dispose=1,c-1!=0&&u(e,n,i,a,c-1,h,s),u(e,n,i,a,c,h,s)}let d=0;if(1!=e.length)for(var p=0;p<a.length;p++){var g;d+=(g=a[p]).rect.width*g.rect.height}return a}(e,n,i,o,c,l),S={},M=[],z=[];if(0!=r){const t=[];for(k=0;k<x.length;k++)t.push(x[k].img.buffer);const e=function(t){let e=0;for(var n=0;n<t.length;n++)e+=t[n].byteLength;const i=new Uint8Array(e);let r=0;for(n=0;n<t.length;n++){const e=new Uint8Array(t[n]),s=e.length;for(let t=0;t<s;t+=4){let n=e[t],s=e[t+1],o=e[t+2];const a=e[t+3];0==a&&(n=s=o=0),i[r+t]=n,i[r+t+1]=s,i[r+t+2]=o,i[r+t+3]=a}r+=s}return i.buffer}(t),n=g(e,r);for(k=0;k<n.plte.length;k++)M.push(n.plte[k].est.rgba);let i=0;for(k=0;k<x.length;k++){const t=(C=x[k]).img.length;var $=new Uint8Array(n.inds.buffer,i>>2,t>>2);z.push($);const e=new Uint8Array(n.abuf,i,t);p&&a(C.img,C.rect.width,C.rect.height,M,e,$),C.img.set(e),i+=t}}else for(y=0;y<x.length;y++){var C=x[y];const t=new Uint32Array(C.img.buffer);var T=C.rect.width;for(b=t.length,$=new Uint8Array(b),z.push($),k=0;k<b;k++){const e=t[k];if(0!=k&&e==t[k-1])$[k]=$[k-1];else if(k>T&&e==t[k-T])$[k]=$[k-T];else{let t=S[e];if(null==t&&(S[e]=t=M.length,M.push(e),M.length>=300))break;$[k]=t}}}const I=M.length;for(I<=256&&0==d&&(w=I<=2?1:I<=4?2:I<=16?4:8,w=Math.max(w,h)),y=0;y<x.length;y++){const t=(C=x[y]).rect.height;let e=C.img,n=4*(T=C.rect.width),i=4;if(I<=256&&0==d){n=Math.ceil(w*T/8);var j=new Uint8Array(n*t);const r=z[y];for(let e=0;e<t;e++){k=e*n;const t=e*T;if(8==w)for(var E=0;E<T;E++)j[k+E]=r[t+E];else if(4==w)for(E=0;E<T;E++)j[k+(E>>1)]|=r[t+E]<<4-4*(1&E);else if(2==w)for(E=0;E<T;E++)j[k+(E>>2)]|=r[t+E]<<6-2*(3&E);else if(1==w)for(E=0;E<T;E++)j[k+(E>>3)]|=r[t+E]<<7-1*(7&E)}e=j,v=3,i=1}else if(0==A&&1==x.length){j=new Uint8Array(T*t*3);const r=T*t;for(k=0;k<r;k++){const t=3*k,n=4*k;j[t]=e[n],j[t+1]=e[n+1],j[t+2]=e[n+2]}e=j,v=2,i=3,n=3*T}C.img=e,C.bpl=n,C.bpp=i}return{ctype:v,depth:w,plte:M,frames:x}}function u(e,n,i,r,s,o,a){const c=Uint8Array,l=Uint32Array,h=new c(e[s-1]),u=new l(e[s-1]),d=s+1<e.length?new c(e[s+1]):null,p=new c(e[s]),g=new l(p.buffer);let v=n,w=i,m=-1,y=-1;for(let t=0;t<o.height;t++)for(let e=0;e<o.width;e++){const i=o.x+e,a=o.y+t,c=a*n+i,l=g[c];0==l||0==r[s-1].dispose&&u[c]==l&&(null==d||0!=d[4*c+3])||(i<v&&(v=i),i>m&&(m=i),a<w&&(w=a),a>y&&(y=a))}-1==m&&(v=w=m=y=0),a&&(!(1&~v)&&v--,!(1&~w)&&w--);const b=r[s];b.rect=o={x:v,y:w,width:m-v+1,height:y-w+1},b.blend=1,b.img=new Uint8Array(o.width*o.height*4),0==r[s-1].dispose?(t(h,n,i,b.img,o.width,o.height,-o.x,-o.y,0),f(p,n,i,b.img,o)):t(p,n,i,b.img,o.width,o.height,-o.x,-o.y,0)}function f(e,n,i,r,s){t(e,n,i,r,s.width,s.height,-s.x,-s.y,2)}function d(t,e,n,i,r,s,o){const a=[];let c,l=[0,1,2,3,4];-1!=s?l=[s]:(e*i>5e5||1==n)&&(l=[0]),o&&(c={level:0});const h=st;for(var u=0;u<l.length;u++){for(let s=0;s<e;s++)p(r,t,s,i,n,l[u]);a.push(h.deflate(r,c))}let f,d=1e9;for(u=0;u<a.length;u++)a[u].length<d&&(f=u,d=a[u].length);return a[f]}function p(t,e,i,r,s,o){const a=i*r;let c=a+i;if(t[c]=o,c++,0==o)if(r<500)for(var l=0;l<r;l++)t[c+l]=e[a+l];else t.set(new Uint8Array(e.buffer,a,r),c);else if(1==o){for(l=0;l<s;l++)t[c+l]=e[a+l];for(l=s;l<r;l++)t[c+l]=e[a+l]-e[a+l-s]+256&255}else if(0==i){for(l=0;l<s;l++)t[c+l]=e[a+l];if(2==o)for(l=s;l<r;l++)t[c+l]=e[a+l];if(3==o)for(l=s;l<r;l++)t[c+l]=e[a+l]-(e[a+l-s]>>1)+256&255;if(4==o)for(l=s;l<r;l++)t[c+l]=e[a+l]-n(e[a+l-s],0,0)+256&255}else{if(2==o)for(l=0;l<r;l++)t[c+l]=e[a+l]+256-e[a+l-r]&255;if(3==o){for(l=0;l<s;l++)t[c+l]=e[a+l]+256-(e[a+l-r]>>1)&255;for(l=s;l<r;l++)t[c+l]=e[a+l]+256-(e[a+l-r]+e[a+l-s]>>1)&255}if(4==o){for(l=0;l<s;l++)t[c+l]=e[a+l]+256-n(0,e[a+l-r],0)&255;for(l=s;l<r;l++)t[c+l]=e[a+l]+256-n(e[a+l-s],e[a+l-r],e[a+l-s-r])&255}}}function g(t,e){const n=new Uint8Array(t),i=n.slice(0),r=new Uint32Array(i.buffer),s=v(i,e),o=s[0],a=s[1],c=n.length,l=new Uint8Array(c>>2);let h;if(n.length<2e7)for(var u=0;u<c;u+=4)h=w(o,f=n[u]*(1/255),d=n[u+1]*(1/255),p=n[u+2]*(1/255),g=n[u+3]*(1/255)),l[u>>2]=h.ind,r[u>>2]=h.est.rgba;else for(u=0;u<c;u+=4){var f=n[u]*(1/255),d=n[u+1]*(1/255),p=n[u+2]*(1/255),g=n[u+3]*(1/255);for(h=o;h.left;)h=m(h.est,f,d,p,g)<=0?h.left:h.right;l[u>>2]=h.ind,r[u>>2]=h.est.rgba}return{abuf:i.buffer,inds:l,plte:a}}function v(t,e,n){null==n&&(n=1e-4);const i=new Uint32Array(t.buffer),r={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};r.bst=k(t,r.i0,r.i1),r.est=A(r.bst);const s=[r];for(;s.length<e;){let e=0,r=0;for(var o=0;o<s.length;o++)s[o].est.L>e&&(e=s[o].est.L,r=o);if(e<n)break;const a=s[r],c=y(t,i,a.i0,a.i1,a.est.e,a.est.eMq255);if(a.i0>=c||a.i1<=c){a.est.L=0;continue}const l={i0:a.i0,i1:c,bst:null,est:null,tdst:0,left:null,right:null};l.bst=k(t,l.i0,l.i1),l.est=A(l.bst);const h={i0:c,i1:a.i1,bst:null,est:null,tdst:0,left:null,right:null};for(h.bst={R:[],m:[],N:a.bst.N-l.bst.N},o=0;o<16;o++)h.bst.R[o]=a.bst.R[o]-l.bst.R[o];for(o=0;o<4;o++)h.bst.m[o]=a.bst.m[o]-l.bst.m[o];h.est=A(h.bst),a.left=l,a.right=h,s[r]=l,s.push(h)}for(s.sort(((t,e)=>e.bst.N-t.bst.N)),o=0;o<s.length;o++)s[o].ind=o;return[r,s]}function w(t,e,n,i,r){if(null==t.left)return t.tdst=function(t,e,n,i,r){const s=e-t[0],o=n-t[1],a=i-t[2],c=r-t[3];return s*s+o*o+a*a+c*c}(t.est.q,e,n,i,r),t;const s=m(t.est,e,n,i,r);let o=t.left,a=t.right;s>0&&(o=t.right,a=t.left);const c=w(o,e,n,i,r);if(c.tdst<=s*s)return c;const l=w(a,e,n,i,r);return l.tdst<c.tdst?l:c}function m(t,e,n,i,r){const{e:s}=t;return s[0]*e+s[1]*n+s[2]*i+s[3]*r-t.eMq}function y(t,e,n,i,r,s){for(i-=4;n<i;){for(;b(t,n,r)<=s;)n+=4;for(;b(t,i,r)>s;)i-=4;if(n>=i)break;const o=e[n>>2];e[n>>2]=e[i>>2],e[i>>2]=o,n+=4,i-=4}for(;b(t,n,r)>s;)n-=4;return n+4}function b(t,e,n){return t[e]*n[0]+t[e+1]*n[1]+t[e+2]*n[2]+t[e+3]*n[3]}function k(t,e,n){const i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=[0,0,0,0],s=n-e>>2;for(let s=e;s<n;s+=4){const e=t[s]*(1/255),n=t[s+1]*(1/255),o=t[s+2]*(1/255),a=t[s+3]*(1/255);r[0]+=e,r[1]+=n,r[2]+=o,r[3]+=a,i[0]+=e*e,i[1]+=e*n,i[2]+=e*o,i[3]+=e*a,i[5]+=n*n,i[6]+=n*o,i[7]+=n*a,i[10]+=o*o,i[11]+=o*a,i[15]+=a*a}return i[4]=i[1],i[8]=i[2],i[9]=i[6],i[12]=i[3],i[13]=i[7],i[14]=i[11],{R:i,m:r,N:s}}function A(t){const{R:e}=t,{m:n}=t,{N:i}=t,r=n[0],s=n[1],o=n[2],a=n[3],c=0==i?0:1/i,l=[e[0]-r*r*c,e[1]-r*s*c,e[2]-r*o*c,e[3]-r*a*c,e[4]-s*r*c,e[5]-s*s*c,e[6]-s*o*c,e[7]-s*a*c,e[8]-o*r*c,e[9]-o*s*c,e[10]-o*o*c,e[11]-o*a*c,e[12]-a*r*c,e[13]-a*s*c,e[14]-a*o*c,e[15]-a*a*c],h=l,u=x;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,p=0;if(0!=i)for(let t=0;t<16&&(f=u.multVec(h,f),p=Math.sqrt(u.dot(f,f)),f=u.sml(1/p,f),!(0!=t&&Math.abs(p-d)<1e-9));t++)d=p;const g=[r*c,s*c,o*c,a*c];return{Cov:l,q:g,e:f,L:d,eMq255:u.dot(u.sml(255,g),f),eMq:u.dot(f,g),rgba:(Math.round(255*g[3])<<24|Math.round(255*g[2])<<16|Math.round(255*g[1])<<8|Math.round(255*g[0]))>>>0}}var x={multVec:(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],t[4]*e[0]+t[5]*e[1]+t[6]*e[2]+t[7]*e[3],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]+t[11]*e[3],t[12]*e[0]+t[13]*e[1]+t[14]*e[2]+t[15]*e[3]],dot:(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],sml:(t,e)=>[t*e[0],t*e[1],t*e[2],t*e[3]]};ot.encode=function(t,e,n,i,r,s,o){null==i&&(i=0),null==o&&(o=!1);const a=h(t,e,n,i,[!1,!1,!1,0,o,!1]);return l(a,-1),c(a,e,n,r,s)},ot.encodeLL=function(t,e,n,i,r,s,o,a){const h={ctype:0+(1==i?0:2)+(0==r?0:4),depth:s,frames:[]},u=(i+r)*s,f=u*e;for(let i=0;i<t.length;i++)h.frames.push({rect:{x:0,y:0,width:e,height:n},img:new Uint8Array(t[i]),blend:0,dispose:1,bpp:Math.ceil(u/8),bpl:Math.ceil(f/8)});return l(h,0,!0),c(h,e,n,o,a)},ot.encode.compress=h,ot.encode.dither=a,ot.quantize=g,ot.quantize.getKDtree=v,ot.quantize.getNearest=w}();const at={toArrayBuffer(t,e){const n=t.width,i=t.height,r=n<<2,s=t.getContext("2d").getImageData(0,0,n,i),o=new Uint32Array(s.data.buffer),a=(32*n+31)/32<<2,c=a*i,l=122+c,h=new ArrayBuffer(l),u=new DataView(h),f=1<<20;let d,p,g,v,w=f,m=0,y=0,b=0;function k(t){u.setUint16(y,t,!0),y+=2}function A(t){u.setUint32(y,t,!0),y+=4}function x(t){y+=t}k(19778),A(l),x(4),A(122),A(108),A(n),A(-i>>>0),k(1),k(32),A(3),A(c),A(2835),A(2835),x(8),A(16711680),A(65280),A(255),A(4278190080),A(1466527264),function t(){for(;m<i&&w>0;){for(v=122+m*a,d=0;d<r;)w--,p=o[b++],g=p>>>24,u.setUint32(v+d,p<<8|g),d+=4;m++}b<o.length?(w=f,setTimeout(t,at._dly)):e(h)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var ct={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},lt={[ct.CHROME]:16384,[ct.FIREFOX]:11180,[ct.DESKTOP_SAFARI]:16384,[ct.IE]:8192,[ct.IOS]:4096,[ct.ETC]:8192};const ht="undefined"!=typeof window,ut="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,ft=ht&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),dt=(ht||ut)&&(ft&&ft.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),pt=(ht||ut)&&(ft&&ft.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function gt(t,e,n=Date.now()){return new Promise((i=>{const r=t.split(","),s=r[0].match(/:(.*?);/)[1],o=globalThis.atob(r[1]);let a=o.length;const c=new Uint8Array(a);for(;a--;)c[a]=o.charCodeAt(a);const l=new Blob([c],{type:s});l.name=e,l.lastModified=n,i(l)}))}function vt(t){return new Promise(((e,n)=>{const i=new pt;i.onload=()=>e(i.result),i.onerror=t=>n(t),i.readAsDataURL(t)}))}function wt(t){return new Promise(((e,n)=>{const i=new Image;i.onload=()=>e(i),i.onerror=t=>n(t),i.src=t}))}function mt(){if(void 0!==mt.cachedResult)return mt.cachedResult;let t=ct.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=ct.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=ct.IOS:/Safari/i.test(e)?t=ct.DESKTOP_SAFARI:/Firefox/i.test(e)?t=ct.FIREFOX:(/MSIE/i.test(e)||1==!!document.documentMode)&&(t=ct.IE),mt.cachedResult=t}function yt(t,e){const n=mt(),i=lt[n];let r=t,s=e,o=r*s;const a=r>s?s/r:r/s;for(;o>i*i;){const t=(i+r)/2,e=(i+s)/2;t<e?(s=e,r=e*a):(s=t*a,r=t),o=r*s}return{width:r,height:s}}function bt(t,e){let n,i;try{if(n=new OffscreenCanvas(t,e),i=n.getContext("2d"),null===i)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){n=document.createElement("canvas"),i=n.getContext("2d")}return n.width=t,n.height=e,[n,i]}function kt(t,e){const{width:n,height:i}=yt(t.width,t.height),[r,s]=bt(n,i);return e&&/jpe?g/.test(e)&&(s.fillStyle="white",s.fillRect(0,0,r.width,r.height)),s.drawImage(t,0,0,r.width,r.height),r}function At(){return void 0!==At.cachedResult||(At.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),At.cachedResult}function xt(t,e={}){return new Promise((function(n,i){let r,s;var o=function(){try{return s=kt(r,e.fileType||t.type),n([r,s])}catch(t){return i(t)}},a=function(){try{var e=function(t){try{throw t}catch(t){return i(t)}};try{let n;return vt(t).then((function(t){try{return n=t,wt(n).then((function(t){try{return r=t,function(){try{return o()}catch(t){return i(t)}}()}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){e(t)}}catch(t){return i(t)}};try{if(At()||[ct.DESKTOP_SAFARI,ct.MOBILE_SAFARI].includes(mt()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return r=t,o()}catch(t){return a()}}),a)}catch(t){a()}}))}function St(t,e,n,i,r=1){return new Promise((function(s,o){let a;if("image/png"===e){let l,h,u;return l=t.getContext("2d"),({data:h}=l.getImageData(0,0,t.width,t.height)),u=ot.encode([h.buffer],t.width,t.height,4096*r),a=new Blob([u],{type:e}),a.name=n,a.lastModified=i,c.call(this)}{if("image/bmp"===e)return new Promise((e=>at.toBlob(t,e))).then(function(t){try{return a=t,a.name=n,a.lastModified=i,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:r}).then(function(t){try{return a=t,a.name=n,a.lastModified=i,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let p;return p=t.toDataURL(e,r),gt(p,n,i).then(function(t){try{return a=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return f.call(this)}}function f(){return c.call(this)}}function c(){return s(a)}}))}function Mt(t){t.width=0,t.height=0}function zt(){return new Promise((function(t,e){let n,i,r,s;return void 0!==zt.cachedResult?t(zt.cachedResult):gt("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return n=o,xt(n).then((function(o){try{return i=o[1],St(i,n.type,n.name,n.lastModified).then((function(n){try{return r=n,Mt(i),xt(r).then((function(n){try{return s=n[0],t(zt.cachedResult=1===s.width&&2===s.height)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}))}function $t(t){return new Promise(((e,n)=>{const i=new pt;i.onload=t=>{const n=new DataView(t.target.result);if(65496!=n.getUint16(0,!1))return e(-2);const i=n.byteLength;let r=2;for(;r<i;){if(n.getUint16(r+2,!1)<=8)return e(-1);const t=n.getUint16(r,!1);if(r+=2,65505==t){if(1165519206!=n.getUint32(r+=2,!1))return e(-1);const t=18761==n.getUint16(r+=6,!1);r+=n.getUint32(r+4,t);const i=n.getUint16(r,t);r+=2;for(let s=0;s<i;s++)if(274==n.getUint16(r+12*s,t))return e(n.getUint16(r+12*s+8,t))}else{if(65280&~t)break;r+=n.getUint16(r,!1)}}return e(-1)},i.onerror=t=>n(t),i.readAsArrayBuffer(t)}))}function Ct(t,e){const{width:n}=t,{height:i}=t,{maxWidthOrHeight:r}=e;let s,o=t;return isFinite(r)&&(n>r||i>r)&&([o,s]=bt(n,i),n>i?(o.width=r,o.height=i/n*r):(o.width=n/i*r,o.height=r),s.drawImage(t,0,0,o.width,o.height),Mt(t)),o}function Tt(t,e){const{width:n}=t,{height:i}=t,[r,s]=bt(n,i);switch(e>4&&e<9?(r.width=i,r.height=n):(r.width=n,r.height=i),e){case 2:s.transform(-1,0,0,1,n,0);break;case 3:s.transform(-1,0,0,-1,n,i);break;case 4:s.transform(1,0,0,-1,0,i);break;case 5:s.transform(0,1,1,0,0,0);break;case 6:s.transform(0,1,-1,0,i,0);break;case 7:s.transform(0,-1,-1,0,i,n);break;case 8:s.transform(0,-1,1,0,0,n)}return s.drawImage(t,0,0,n,i),Mt(t),r}function It(t,e,n=0){return new Promise((function(i,r){let s,o,a,c,l,h,u,f,d,p,g,v,w,m,y,b,k,A,x,S;function M(t=5){if(e.signal&&e.signal.aborted)throw e.signal.reason;s+=t,e.onProgress(Math.min(s,100))}function z(t){if(e.signal&&e.signal.aborted)throw e.signal.reason;s=Math.min(Math.max(t,s),100),e.onProgress(s)}return s=n,o=e.maxIteration||10,a=1024*e.maxSizeMB*1024,M(),xt(t,e).then(function(n){try{return[,c]=n,M(),l=Ct(c,e),M(),new Promise((function(n,i){var r;if(!(r=e.exifOrientation))return $t(t).then(function(t){try{return r=t,s.call(this)}catch(t){return i(t)}}.bind(this),i);function s(){return n(r)}return s.call(this)})).then(function(n){try{return h=n,M(),zt().then(function(n){try{return u=n?l:Tt(l,h),M(),f=e.initialQuality||1,d=e.fileType||t.type,St(u,d,t.name,t.lastModified,f).then(function(n){try{{if(p=n,M(),g=p.size>a,v=p.size>t.size,!g&&!v)return z(100),i(p);var s;function h(){if(o--&&(y>a||y>w)){let e,n;return e=S?.95*x.width:x.width,n=S?.95*x.height:x.height,[k,A]=bt(e,n),A.drawImage(x,0,0,e,n),f*="image/png"===d?.85:.95,St(k,d,t.name,t.lastModified,f).then((function(t){try{return b=t,Mt(x),x=k,y=b.size,z(Math.min(99,Math.floor((m-y)/(m-a)*100))),h}catch(t){return r(t)}}),r)}return[1]}return w=t.size,m=p.size,y=m,x=u,S=!e.alwaysKeepResolution&&g,(s=function(t){for(;t;){if(t.then)return void t.then(s,r);try{if(t.pop){if(t.length)return t.pop()?$.call(this):t;t=h}else t=t.call(this)}catch(t){return r(t)}}}.bind(this))(h);function $(){return Mt(x),Mt(k),Mt(l),Mt(u),Mt(c),z(100),i(b)}}}catch(C){return r(C)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}))}let jt;function Et(t,e){return new Promise(((n,i)=>{jt||(jt=function(){const t=[];return t.push("\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n"),URL.createObjectURL(new Blob(t))}());const r=new Worker(jt);r.addEventListener("message",(function(t){if(e.signal&&e.signal.aborted)r.terminate();else if(void 0===t.data.progress){if(t.data.error)return i(new Error(t.data.error)),void r.terminate();n(t.data.file),r.terminate()}else e.onProgress(t.data.progress)})),r.addEventListener("error",i),e.signal&&e.signal.addEventListener("abort",(()=>{i(e.signal.reason),r.terminate()})),r.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function _t(t,e){return new Promise((function(n,i){let r,s,o,a,c,l;if(r={...e},o=0,({onProgress:a}=r),r.maxSizeMB=r.maxSizeMB||Number.POSITIVE_INFINITY,c="boolean"!=typeof r.useWebWorker||r.useWebWorker,delete r.useWebWorker,r.onProgress=t=>{o=t,"function"==typeof a&&a(o)},!(t instanceof Blob||t instanceof dt))return i(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return i(new Error("The file given is not an image"));if(l="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!c||"function"!=typeof Worker||l)return It(t,r).then(function(t){try{return s=t,f.call(this)}catch(t){return i(t)}}.bind(this),i);var h=function(){try{return f.call(this)}catch(t){return i(t)}}.bind(this),u=function(){try{return It(t,r).then((function(t){try{return s=t,h()}catch(t){return i(t)}}),i)}catch(t){return i(t)}};try{return r.libURL=r.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Et(t,r).then((function(t){try{return s=t,h()}catch(t){return u()}}),u)}catch(t){u()}function f(){try{s.name=t.name,s.lastModified=t.lastModified}catch(t){}try{r.preserveExif&&"image/jpeg"===t.type&&(!r.fileType||r.fileType&&r.fileType===t.type)&&(s=et(t,s))}catch(t){}return n(s)}}))}_t.getDataUrlFromFile=vt,_t.getFilefromDataUrl=gt,_t.loadImage=wt,_t.drawImageInCanvas=kt,_t.drawFileInCanvas=xt,_t.canvasToFile=St,_t.getExifOrientation=$t,_t.handleMaxWidthOrHeight=Ct,_t.followExifOrientation=Tt,_t.cleanupCanvasMemory=Mt,_t.isAutoOrientationInBrowser=zt,_t.approximateBelowMaximumCanvasSizeOfBrowser=yt,_t.copyExifWithoutOrientation=et,_t.getBrowserName=mt,_t.version="2.0.2";class Lt extends a{toolType="image";fileInput=null;maxCompressionSize=1200;multiImportOffset=20;constructor(t){super(t),this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){this._core.store.isDisabled||this.fileInput?.click()}setupFileInput(){this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="image/*",this.fileInput.multiple=!0,this.fileInput.style.display="none",this.fileInput.addEventListener("change",this.handleFileSelect.bind(this)),this.fileInput.addEventListener("cancel",this.handleCancel.bind(this)),document.body.appendChild(this.fileInput)}handleFileSelect(t){const e=t.target,n=e.files?Array.from(e.files):[];if(0===n.length)return console.info("File selection cancelled by user."),this.handleCancel(),void(e&&(e.value=""));const i=n.map((t=>_t(t,{maxWidthOrHeight:this.maxCompressionSize}).then((t=>u.fromBlob(this._core,t)))));Promise.allSettled(i).then((t=>{const e=[];for(const n of t)"fulfilled"===n.status?e.push(n.value):console.error("Error during image compression or processing:",n.reason);0!==e.length?this.addImagesToStore(e):this.handleCancel()})),e&&(e.value="")}addImagesToStore(t){const e=this._core.store.currentZIndex;t.forEach(((t,n)=>{if(t.zIndex=e+n,t.centerInViewport(),n>0){const e=n*this.multiImportOffset;t.updatePosition(t.translateX+e,t.translateY+e)}this._core.addObject(t)})),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection")),this._core.selectObjects(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded(t)}handleCancel(){this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"))}}class Ot extends a{toolType="shape";shapeType=f.Rectangle;fillColor={light:"transparent",dark:"transparent"};strokeColor=x[0];strokeWidth=4;opacity=1;fontFamily="Arial";fontSize=16;fontColor=x[0];palette=[...x];sizes=[...c];startX=0;startY=0;isDrawing=!1;currentShape=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),n=this._core.findObjectById(e?.id),i=this._core.store.activeShape;if(null===i&&n instanceof d)return void n.edit(t);if(null!==i&&n instanceof d)return i.save(),void n.edit(t);if(null!==i&&n instanceof d==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"));if(!1===l.isLeftClick(t))return;this.startDrawing(t.clientX,t.clientY)}if("touch"===t.pointerType||"pen"===t.pointerType){const e=Array.from(this._core.store.state.pointers.values()),n=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=this._core.findObjectById(n?.id),r=this._core.store.activeShape;if(null===r&&i instanceof d)return void i.edit(t);if(null!==r&&i instanceof d)return r.save(),void i.edit(t);if(null!==r&&i instanceof d==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"));if(e.length>1)return;const s=Math.round(e[0].clientX),o=Math.round(e[0].clientY);this.startDrawing(s,o)}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&("mouse"===t.pointerType&&this.updateShapeSize(t.clientX,t.clientY),"touch"===t.pointerType||"pen"===t.pointerType)){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=Math.round(t[0].clientX),n=Math.round(t[0].clientY);this.updateShapeSize(e,n)}}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&this.finishDrawing()}startDrawing(t,e){const n=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?n:1;this.startX=(t-this._core.store.offsetX)/r,this.startY=(e-this._core.store.offsetY)/r,this.isDrawing=!0,this.currentShape=d.create(this._core,{x:this.startX,y:this.startY,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,width:1,height:1,shapeType:this.shapeType,fillColor:this.fillColor,strokeColor:this.strokeColor,strokeWidth:this.strokeWidth,opacity:this.opacity,fontSize:this.fontSize,fontFamily:this.fontFamily,scale:i?1:n}),this._core.store.objects.insert(this.currentShape),this._core.store.objects?.setActiveDrawingObject(this.currentShape.id),this._core.rerender()}updateShapeSize(t,e){if(!this.currentShape)return;const n=this._core.store.state.lockDrawingScale?this._core.store.state.scale:1,i=(t-this._core.store.offsetX)/n,r=(e-this._core.store.offsetY)/n,s=Math.min(this.startX,i),o=Math.min(this.startY,r),a=Math.abs(i-this.startX),c=Math.abs(r-this.startY);this.currentShape.x=s,this.currentShape.y=o,this.currentShape.width=Math.max(1,a),this.currentShape.height=Math.max(1,c),this.currentShape.translateX=-this._core.store.state.translateX/n,this.currentShape.translateY=-this._core.store.state.translateY/n,this.currentShape.updateDimensions(),this._core.store.objects.update(this.currentShape)}finishDrawing(){if(this.currentShape){if(this.currentShape.width<10&&this.currentShape.height<10){const t=this.currentShape.id;this._core.store.objects.remove((e=>e.id===t))}else this.currentShape.zIndex=this._core.store.currentZIndex,this._core.store.objects.update(this.currentShape),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([this.currentShape]),this._core.selectObjects([this.currentShape]),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection"));this.isDrawing=!1,this._core.store.objects?.setActiveDrawingObject(null),this.currentShape=null,this._core.store.objects?.stopUndoCapturing(),this._core.rerender()}}}class Pt{static _pointerCursor=null;static getPointerCursor(){return this._pointerCursor||(this._pointerCursor=this.getCursor({iconName:"pointer"})),this._pointerCursor}static getCursor(t){const e="default"===t.iconName?"mouse-pointer":t.iconName,n=K.get(e);if(!n)return console.warn(`Icon "${e}" not found in registry.`),"auto";const i=t.size||24,r=t.rotation||0,s=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:i/2,y:i/2});let a=n.replace(/width="\d+"/,`width="${i}"`).replace(/height="\d+"/,`height="${i}"`).replace(/currentColor/g,s);const c=i/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${i}" viewBox="0 0 ${i} ${i}">\n <g transform="rotate(${r} ${c} ${c})">\n ${a}\n </g>\n </svg>\n `.replace(/\s+/g," ").trim()).replace(/'/g,"%27").replace(/"/g,"%22")}') ${o.x} ${o.y}, auto`}}class Bt{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,e,n){const i=this.getLineById(t);if(!i)return;if("start"===e&&i.endAnchor?.objectId===n)return;if("end"===e&&i.startAnchor?.objectId===n)return;this.removeAnchor(t,e);const r={objectId:n};"start"===e?i.startAnchor=r:i.endAnchor=r,this.addToIndex(n,t,e),this.snapEndpointToObject(i,e,n),this._core.store.objects.update(i)}removeAnchor(t,e){const n=this.getLineById(t);if(!n)return;const i="start"===e?n.startAnchor:n.endAnchor;i&&(this.removeFromIndex(i.objectId,t,e),"start"===e?n.startAnchor=void 0:n.endAnchor=void 0)}getAnchor(t,e){const n=this.getLineById(t);return n?("start"===e?n.startAnchor:n.endAnchor)??null:null}getLinesAnchoredTo(t){const e=this._anchorIndex.get(t);return e?Array.from(e):[]}updateAnchorsForObject(t){const e=this.getLinesAnchoredTo(t);if(0===e.length)return;if(!this.getObjectById(t))return;for(const n of e){const e=this.getLineById(n.lineId);e&&this.snapEndpointToObject(e,n.endpoint,t)}const n=this._core.store.selectionGroup;n&&this._core.store.state.isDragging&&n.hasExternalAnchoredLineConnections()&&n.refreshObjectDimensions(void 0,!0)}snapEndpointToObject(t,e,n){const i=this.getObjectById(n);if(!i)return;const r=this.worldToLineLocal(t,i.centerX,i.centerY);t.updateEndpoint(e,r.x,r.y)}worldToLineLocal(t,e,n){const i=e-t.centerX,r=n-t.centerY,s=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(i*s-r*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(i*o+r*s+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,e,n,i,r="mouse"){return this.findBestSnapTarget(t,e,n,i,(n=>{const i=this.getSnapRadius(n,r),s=t-n.centerX,o=e-n.centerY;return Math.sqrt(s*s+o*o)<=i}))}findSnapPreviewTarget(t,e,n,i){return this.findBestSnapTarget(t,e,n,i,(()=>!0))}findBestSnapTarget(t,e,n,i,r){let s=null,o=-1/0;const a=this._core.store.allNonSelectionObjects;for(const c of a){if(c.id===n)continue;if(i&&c.id===i)continue;if(!this.isAnchorable(c))continue;const a=c.rotatedPolygon;O.isPointInPolygon({x:t,y:e},[a.topLeft,a.topRight,a.bottomRight,a.bottomLeft])&&r(c)&&c.zIndex>o&&(o=c.zIndex,s={objectId:c.id,centerX:c.centerX,centerY:c.centerY})}return s}getSnapRadius(t,e){const n=Math.min(t.width,t.height)/5;return"touch"===e||"pen"===e?Math.max(1.75*n,24/this.getSafeScale(this._core.store.state.scale)):n}setSnapCandidate(t){this._core.store.state.snapCandidate=t,this._core.rerender()}setSnapPreviewCandidate(t){this._core.store.state.snapPreviewCandidate=t,this._core.rerender()}getSnapCandidate(){return this._core.store.state.snapCandidate??null}getSnapPreviewCandidate(){return this._core.store.state.snapPreviewCandidate??null}clearSnapCandidate(){this._core.store.state.snapCandidate=null,this._core.rerender()}clearSnapPreviewCandidate(){this._core.store.state.snapPreviewCandidate=null,this._core.rerender()}getAnchorLinesRenderData(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const e=t.objects[0];if(!p.isInstanceOf(e,"KritzelLine"))return null;const n=e,i=this.computeAnchorVisualization(n,"start"),r=this.computeAnchorVisualization(n,"end"),s=this.isFiniteAnchorVisualization(i)?i:null,o=this.isFiniteAnchorVisualization(r)?r:null;if(!s&&!o)return null;const a=this.getSafeScale(this._core.store.state.scale),c=this.getSafeScale(n.scale),l=n.strokeWidth/c,h=""+2/a,u=Math.max(2*l,4/a),f=`${u} ${u}`,d=8/a;return this.areFiniteNumbers(l,u,d)?{lineStrokeWidth:l,indicatorStrokeWidth:h,dashArray:f,indicatorRadius:d,startAnchorViz:s,endAnchorViz:o}:null}getSnapIndicatorRenderData(){return this.getIndicatorRenderDataForCandidate(this.getSnapCandidate())}getSnapPreviewRenderData(){return this.getIndicatorRenderDataForCandidate(this.getSnapPreviewCandidate())}getIndicatorRenderDataForCandidate(t){if(!t)return null;if(!this.areFiniteNumbers(t.centerX,t.centerY,t.lineEndpointX,t.lineEndpointY))return null;const e=this.getSafeScale(this._core.store.state.scale),n=8/e,i=""+2/e,r=this.areFiniteNumbers(t.lineStrokeWidth)&&t.lineStrokeWidth>0?t.lineStrokeWidth:4/e,s=`${r}`,o=Math.max(2*r,4/e),a=`${o} ${o}`,c=t.lineStroke||"#000000";let l,h=this.areFiniteNumbers(t.edgeX)?t.edgeX:void 0,u=this.areFiniteNumbers(t.edgeY)?t.edgeY:void 0,f=h,d=u;const p=this.areFiniteNumbers(t.arrowOffset)&&t.arrowOffset>0?t.arrowOffset:void 0;if(void 0!==p&&void 0!==h&&void 0!==u){const e=t.lineEndpointX-h,n=t.lineEndpointY-u,i=Math.sqrt(e*e+n*n);i>p&&(f=h+e/i*p,d=u+n/i*p);const r=h-t.lineEndpointX,s=u-t.lineEndpointY,o=Math.sqrt(r*r+s*s);if(o>0){const t=r/o,e=s/o,n=-e,i=h,a=u,c=i-t*p,f=a-e*p,d=c+n*p/2,g=f+t*p/2,v=c-n*p/2,w=f-t*p/2;this.areFiniteNumbers(i,a,d,g,v,w)&&(l=`${i},${a} ${d},${g} ${v},${w}`)}}if(!this.areFiniteNumbers(n,r,o))return null;const g=(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t&&this.areFiniteNumbers(t.controlX,t.controlY,t.t)){const e="start"===t.endpoint?1-t.t:t.t;if(e>=1)return;const n=this.extractQuadraticSegment({x:t.lineEndpointX,y:t.lineEndpointY},{x:t.controlX,y:t.controlY},{x:t.centerX,y:t.centerY},e,1);if(!this.areFiniteNumbers(n.start.x,n.start.y,n.control.x,n.control.y,n.end.x,n.end.y))return;return`M ${n.start.x} ${n.start.y} Q ${n.control.x} ${n.control.y} ${n.end.x} ${n.end.y}`}})();return{indicatorRadius:n,indicatorStrokeWidth:i,lineStrokeWidth:s,dashArray:a,lineStroke:c,centerX:t.centerX,centerY:t.centerY,lineEndpointX:t.lineEndpointX,lineEndpointY:t.lineEndpointY,edgeX:h,edgeY:u,arrowOffset:p,arrowStyle:t.arrowStyle,arrowFill:t.arrowFill,solidLineEndX:f,solidLineEndY:d,arrowPoints:l,snapLinePath:g}}handleObjectDeleted(t){const e=this.getLinesAnchoredTo(t);for(const t of e){this.removeAnchor(t.lineId,t.endpoint);const e=this.getLineById(t.lineId);e&&this._core.store.objects.update(e)}this._anchorIndex.delete(t)}handleLineDeleted(t){const e=this.getLineById(t);e&&(e.startAnchor&&this.removeFromIndex(e.startAnchor.objectId,t,"start"),e.endAnchor&&this.removeFromIndex(e.endAnchor.objectId,t,"end"))}rebuildIndex(){this._anchorIndex.clear();const t=this._core.store.allObjects;for(const e of t)e instanceof L&&(e.startAnchor&&this.addToIndex(e.startAnchor.objectId,e.id,"start"),e.endAnchor&&this.addToIndex(e.endAnchor.objectId,e.id,"end"))}addToIndex(t,e,n){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const i=this._anchorIndex.get(t);for(const t of i)if(t.lineId===e&&t.endpoint===n)return;i.add({lineId:e,endpoint:n})}removeFromIndex(t,e,n){const i=this._anchorIndex.get(t);if(i){for(const t of i)if(t.lineId===e&&t.endpoint===n){i.delete(t);break}0===i.size&&this._anchorIndex.delete(t)}}getLineById(t){const e=this._core.store.objects.filter((e=>e.id===t));if(0===e.length)return null;const n=e[0];return n instanceof L?n:null}getObjectById(t){const e=this._core.store.objects.filter((e=>e.id===t));return e.length>0?e[0]:null}findAnchorTarget(t,e){const n="start"===e?t.startAnchor:t.endAnchor;return n?this._core.store.allNonSelectionObjects.find((t=>t.id===n.objectId))??null:null}computeAnchorVisualization(t,e){if(!("start"===e?t.startAnchor:t.endAnchor))return null;const n=this.findAnchorTarget(t,e);if(!n)return null;const i=this.computeAnchorClipInfo(t,e,n);if(!i)return null;const r=n.centerX,s=n.centerY;if(!this.areFiniteNumbers(i.worldX,i.worldY,r,s))return null;const o=this.buildAnchorPath(t,e,i,n)??void 0;return o&&!this.isFinitePathData(o)?null:{edgeX:i.worldX,edgeY:i.worldY,centerX:r,centerY:s,pathD:o}}computeClippedLinePath(t,e=!1){const n=this.getSnapCandidate(),i=this._core.store.selectionGroup,r=n&&i&&1===i.objects.length&&i.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!r)return e?void 0!==t.controlX&&void 0!==t.controlY?`M ${t.startX-t.x} ${t.startY-t.y} Q ${t.controlX-t.x} ${t.controlY-t.y} ${t.endX-t.x} ${t.endY-t.y}`:`M ${t.startX-t.x} ${t.startY-t.y} L ${t.endX-t.x} ${t.endY-t.y}`:t.d;const s=t.startAnchor?this.findAnchorTarget(t,"start"):null,o=t.endAnchor?this.findAnchorTarget(t,"end"):null;let a=s?this.computeAnchorClipInfo(t,"start",s):null,c=o?this.computeAnchorClipInfo(t,"end",o):null;if(r&&void 0!==n.edgeX&&void 0!==n.edgeY){const e=this.lineWorldToLocal(t,n.edgeX,n.edgeY),i={worldX:n.edgeX,worldY:n.edgeY,localX:e.x,localY:e.y,t:n.t};"start"===n.endpoint?a=i:c=i}const l=e?t.x:0,h=e?t.y:0;if(void 0!==t.controlX&&void 0!==t.controlY){let e=a?.t??0,n=c?.t??1;if(a&&t.hasStartArrow){const n=t.getArrowSize("start"),i=this.evaluateDerivativeSpeedAtT(t,e);i>0&&(e+=n/i)}if(c&&t.hasEndArrow){const e=t.getArrowSize("end"),i=this.evaluateDerivativeSpeedAtT(t,n);i>0&&(n-=e/i)}if(e<0&&(e=0),n>1&&(n=1),n<=e){const t=(e+n)/2;e=t,n=t}const i=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},e,n);return`M ${i.start.x-l} ${i.start.y-h} Q ${i.control.x-l} ${i.control.y-h} ${i.end.x-l} ${i.end.y-h}`}let u=a?.localX??t.startX,f=a?.localY??t.startY,d=c?.localX??t.endX,p=c?.localY??t.endY;if(a&&t.hasStartArrow){const e=t.getArrowSize("start"),n=d-u,i=p-f,r=Math.sqrt(n*n+i*i);r>e&&(u+=n/r*e,f+=i/r*e)}if(c&&t.hasEndArrow){const e=t.getArrowSize("end"),n=u-d,i=f-p,r=Math.sqrt(n*n+i*i);r>e&&(d+=n/r*e,p+=i/r*e)}return`M ${u-l} ${f-h} L ${d-l} ${p-h}`}computeAnchorClipInfo(t,e,n){return void 0!==t.controlX&&void 0!==t.controlY?this.computeCurvedClipInfo(t,e,n):this.computeStraightClipInfo(t,e,n)}computeStraightClipInfo(t,e,n){const i="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),r=this.getPathClipPoint(n,i);if(r){const n=this.lineWorldToLocal(t,r.x,r.y),i=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),s=Math.sqrt(Math.pow(n.x-t.startX,2)+Math.pow(n.y-t.startY,2));return{localX:n.x,localY:n.y,worldX:r.x,worldY:r.y,t:i>0?s/i:"start"===e?0:1}}const s=this.getClipPolygonForObject(n);let o;if(o=s?O.getLinePointsArrayIntersection(i,{x:n.centerX,y:n.centerY},s):O.getLinePolygonIntersection(i,{x:n.centerX,y:n.centerY},n.rotatedPolygon),!o)return null;const a=this.lineWorldToLocal(t,o.x,o.y),c=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),l=Math.sqrt(Math.pow(a.x-t.startX,2)+Math.pow(a.y-t.startY,2));return{localX:a.x,localY:a.y,worldX:o.x,worldY:o.y,t:c>0?l/c:"start"===e?0:1}}computeCurvedClipInfo(t,e,n){if(p.isInstanceOf(n,"KritzelPath"))return this.findCurveExitPointForPath(t,e,n);const i=this.getClipPolygonForObject(n),r=i??this.getPolygonPoints(n.rotatedPolygon),s=this.findCurveExitPoint(t,e,r);if(s)return s;const o="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let a;if(a=i?O.getLinePointsArrayIntersection(o,{x:n.centerX,y:n.centerY},i):O.getLinePolygonIntersection(o,{x:n.centerX,y:n.centerY},n.rotatedPolygon),!a)return null;const c=this.lineWorldToLocal(t,a.x,a.y),l=this.approximateParameterForWorldPoint(t,a);return{localX:c.x,localY:c.y,worldX:a.x,worldY:a.y,t:l}}findCurveExitPoint(t,e,n){const i="start"===e?0:1,r=this.evaluateLineAtT(t,i);let s=O.isPointInPolygon({x:r.worldX,y:r.worldY},n),o=i;for(let i=1;i<=64;i++){const r="start"===e?i/64:1-i/64,a=this.evaluateLineAtT(t,r),c=O.isPointInPolygon({x:a.worldX,y:a.worldY},n);if(s&&!c){const e=this.refineCurveExitParameter(t,n,o,r),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}s=c,o=r}return null}findCurveExitPointForPath(t,e,n){const i="start"===e?0:1,r=n.strokeWidth/n.scale/2,s=this.getPathAdjustedPoints(n);if(s.length<1)return null;const o=this.evaluateLineAtT(t,i);let a=this.isPointInPathStroke(o.worldX,o.worldY,s,r),c=i;for(let n=1;n<=64;n++){const i="start"===e?n/64:1-n/64,o=this.evaluateLineAtT(t,i),l=this.isPointInPathStroke(o.worldX,o.worldY,s,r);if(a&&!l){const e=this.refineCurveExitParameterForPath(t,s,r,c,i),n=this.evaluateLineAtT(t,e);return{localX:n.localX,localY:n.localY,worldX:n.worldX,worldY:n.worldY,t:e}}a=l,c=i}return null}refineCurveExitParameterForPath(t,e,n,i,r){let s=i,o=r;for(let i=0;i<8;i++){const i=(s+o)/2,r=this.evaluateLineAtT(t,i);this.isPointInPathStroke(r.worldX,r.worldY,e,n)?s=i:o=i}return(s+o)/2}getPathAdjustedPoints(t){return this.computePathAdjustedPoints(t)}computePathAdjustedPoints(t){if(!t.points?.length)return[];const e=t.rotation,n=Math.cos(e),i=Math.sin(e),r=t.points.map((t=>t[0])),s=t.points.map((t=>t[1])),o={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...s)+Math.max(...s))/2},{x:a,y:c}=o;return t.points.map((([t,e])=>{const r=t-a,s=e-c;return[a+r*n-s*i,c+r*i+s*n]})).map((([e,n])=>[Math.abs(e-t.x)/t.scale+t.translateX,Math.abs(n-t.y)/t.scale+t.translateY]))}isPointInPathStroke(t,e,n,i){if(1===n.length){const r=n[0],s=t-r[0],o=e-r[1];return Math.sqrt(s*s+o*o)<=i}for(let r=0;r<n.length-1;r++){const s=n[r],o=n[r+1];if(this.pointToSegmentDistance(t,e,s[0],s[1],o[0],o[1])<=i)return!0}return!1}pointToSegmentDistance(t,e,n,i,r,s){const o=r-n,a=s-i,c=o*o+a*a;if(0===c)return Math.sqrt((t-n)*(t-n)+(e-i)*(e-i));let l=((t-n)*o+(e-i)*a)/c;l=Math.max(0,Math.min(1,l));const h=n+l*o,u=i+l*a;return Math.sqrt((t-h)*(t-h)+(e-u)*(e-u))}refineCurveExitParameter(t,e,n,i){let r=n,s=i;for(let n=0;n<8;n++){const n=(r+s)/2,i=this.evaluateLineAtT(t,n);O.isPointInPolygon({x:i.worldX,y:i.worldY},e)?r=n:s=n}return(r+s)/2}approximateParameterForWorldPoint(t,e){let n=0,i=1/0;for(let r=0;r<=80;r++){const s=r/80,o=this.evaluateLineAtT(t,s),a=Math.hypot(o.worldX-e.x,o.worldY-e.y);a<i&&(i=a,n=s)}return n}evaluateLineAtT(t,e){const n=Math.max(0,Math.min(1,e));let i,r;if(void 0!==t.controlX&&void 0!==t.controlY){const e=1-n;i=e*e*t.startX+2*e*n*t.controlX+n*n*t.endX,r=e*e*t.startY+2*e*n*t.controlY+n*n*t.endY}else i=t.startX+(t.endX-t.startX)*n,r=t.startY+(t.endY-t.startY)*n;const s=this.lineLocalToWorld(t,i,r);return{t:n,localX:i,localY:r,worldX:s.x,worldY:s.y}}evaluateDerivativeSpeedAtT(t,e){const n=Math.max(0,Math.min(1,e));if(void 0!==t.controlX&&void 0!==t.controlY){const e=t.controlX,i=t.controlY,r=2*(1-n)*(e-t.startX)+2*n*(t.endX-e),s=2*(1-n)*(i-t.startY)+2*n*(t.endY-i);return Math.sqrt(r*r+s*s)}{const e=t.endX-t.startX,n=t.endY-t.startY;return Math.sqrt(e*e+n*n)}}extractQuadraticSegment(t,e,n,i,r){let s=Math.max(0,Math.min(1,i)),o=Math.max(0,Math.min(1,r));if(o<s){const t=s;s=o,o=t}let a={start:t,control:e,end:n};if(s>0){a=this.splitQuadraticSegment(a,s).right;const t=1-s;o=t>0?(o-s)/t:1}return o<1&&(a=this.splitQuadraticSegment(a,o).left),a}splitQuadraticSegment(t,e){const n=Math.max(0,Math.min(1,e)),i=t.start,r=t.control,s=t.end,o=this.lerpPoint(i,r,n),a=this.lerpPoint(r,s,n),c=this.lerpPoint(o,a,n);return{left:{start:i,control:o,end:c},right:{start:c,control:a,end:s}}}lerpPoint(t,e,n){return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}}buildAnchorPath(t,e,n,i){if(void 0===t.controlX||void 0===t.controlY||void 0===n.t)return`M ${n.worldX} ${n.worldY} L ${i.centerX} ${i.centerY}`;const r="start"===e?0:n.t,s="start"===e?n.t:1;if(s<=r)return`M ${n.worldX} ${n.worldY} L ${i.centerX} ${i.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},r,s);return this.buildWorldQuadraticPath(t,o,"start"===e)}buildWorldQuadraticPath(t,e,n=!1){const i=n?e.end:e.start,r=n?e.start:e.end,s=e.control,o=this.lineLocalToWorld(t,i.x,i.y),a=this.lineLocalToWorld(t,s.x,s.y),c=this.lineLocalToWorld(t,r.x,r.y);return`M ${o.x} ${o.y} Q ${a.x} ${a.y} ${c.x} ${c.y}`}getPolygonPoints(t){return[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft]}getClipPolygonForObject(t){return p.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,e){return p.isInstanceOf(t,"KritzelPath")?t.getClipPoint(e):null}lineLocalToWorld(t,e,n){const i=e-t.x,r=n-t.y,s=t.totalWidth/2,o=t.totalHeight/2,a=Math.cos(t.rotation),c=Math.sin(t.rotation),l=(i-s)*a-(r-o)*c+s,h=(i-s)*c+(r-o)*a+o,u=this.getSafeScale(t.scale);return{x:l/u+t.translateX,y:h/u+t.translateY}}lineWorldToLocal(t,e,n){const i=this.getSafeScale(t.scale),r=(e-t.translateX)*i,s=(n-t.translateY)*i,o=t.totalWidth/2,a=t.totalHeight/2,c=Math.cos(-t.rotation),l=Math.sin(-t.rotation);return{x:(r-o)*c-(s-a)*l+o+t.x,y:(r-o)*l+(s-a)*c+a+t.y}}getSafeScale(t){return Number.isFinite(t)&&Math.abs(t)>1e-6?t:1}areFiniteNumbers(...t){return t.every((t=>void 0!==t&&Number.isFinite(t)))}isFiniteAnchorVisualization(t){return!(!t||!this.areFiniteNumbers(t.edgeX,t.edgeY,t.centerX,t.centerY)||t.pathD&&!this.isFinitePathData(t.pathD))}isFinitePathData(t){return!t.includes("Infinity")&&!t.includes("NaN")}isAnchorable(t){return!(t instanceof g||t instanceof h)&&!(t instanceof L)&&t.isVisible}}class Dt{static interpolate(t,e){return e?t.replace(/\{(\w+)\}/g,((t,n)=>{const i=e[n];return null==i?t:String(i)})):t}}const Rt={code:"en",label:"English",terms:{"menu.copy":"Copy","menu.cut":"Cut","menu.paste":"Paste","menu.selectAll":"Select All","menu.order":"Order","menu.bringToFront":"Bring to Front","menu.sendToBack":"Send to Back","menu.moveUp":"Move Up","menu.moveDown":"Move Down","menu.align":"Align","menu.alignLeft":"Align Left","menu.alignCenterHorizontal":"Align Center Horizontally","menu.alignRight":"Align Right","menu.alignTop":"Align Top","menu.alignCenterVertical":"Align Center Vertically","menu.alignBottom":"Align Bottom","menu.group":"Group","menu.ungroup":"Ungroup","menu.export":"Export","menu.exportAsSvg":"Export as SVG","menu.exportAsPng":"Export as PNG","menu.delete":"Delete","menu.share":"Share","menu.import":"Import","menu.settings":"Settings","menu.logout":"Logout","settings.dialogTitle":"Settings","settings.categories.general":"General","settings.categories.viewport":"Viewport","settings.categories.shortcuts":"Keyboard Shortcuts","settings.categories.developer":"Developer Options","settings.categories.about":"About","settings.general.title":"General Settings","settings.general.theme.label":"Theme","settings.general.theme.description":"Select a registered color theme for the editor interface.","settings.general.language.label":"Language","settings.general.language.description":"Select the display language for the editor interface.","settings.general.lockDrawingScale.label":"Lock Drawing Scale","settings.general.lockDrawingScale.description":"When enabled, drawn objects maintain a fixed visual size regardless of the current zoom level.","settings.viewport.title":"Viewport Settings","settings.viewport.minZoom.label":"Minimum Zoom Level","settings.viewport.minZoom.description":"Sets the minimum zoom level. Lower values allow zooming out further to see more of the canvas.","settings.viewport.maxZoom.label":"Maximum Zoom Level","settings.viewport.maxZoom.description":"Sets the maximum zoom level. Higher values allow zooming in closer for detailed work.","settings.viewport.boundaryLeft.label":"Viewport Boundary Left","settings.viewport.boundaryLeft.description":"Left boundary in world coordinates. Set to limit how far left the viewport can pan.","settings.viewport.boundaryRight.label":"Viewport Boundary Right","settings.viewport.boundaryRight.description":"Right boundary in world coordinates. Set to limit how far right the viewport can pan.","settings.viewport.boundaryTop.label":"Viewport Boundary Top","settings.viewport.boundaryTop.description":"Top boundary in world coordinates. Set to limit how far up the viewport can pan.","settings.viewport.boundaryBottom.label":"Viewport Boundary Bottom","settings.viewport.boundaryBottom.description":"Bottom boundary in world coordinates. Set to limit how far down the viewport can pan.","settings.viewport.boundaryPlaceholder":"Infinite","settings.shortcuts.title":"Keyboard Shortcuts","settings.developer.title":"Developer Options","settings.developer.showViewportInfo.label":"Show Viewport Info","settings.developer.showViewportInfo.description":"Display viewport debug information such as position, zoom level, and boundaries.","settings.developer.showObjectInfo.label":"Show Object Info","settings.developer.showObjectInfo.description":"Display debug information about objects on the canvas.","settings.developer.showSyncProviderInfo.label":"Show Sync Provider Info","settings.developer.showSyncProviderInfo.description":"Display debug information about the sync provider connection status.","settings.developer.showMigrationInfo.label":"Show Migration Info","settings.developer.showMigrationInfo.description":"Display debug information about data migrations.","settings.about.title":"About","settings.about.description":"Kritzel - A drawing application","export.dialogTitle":"Export","export.tabs.viewport":"Export Viewport","export.tabs.workspace":"Export Workspace","export.format.label":"Format","export.filename.label":"Filename","export.filename.placeholder":"Enter filename","export.exportButton":"Export","workspace.sharedTooltip":"Shared workspace","workspace.rename":"Rename","workspace.delete":"Delete","zoom.zoomIn":"Zoom in","zoom.zoomOut":"Zoom out","utility.undo":"Undo","utility.redo":"Redo","utility.delete":"Delete selected items","share.dialogTitle":"Share Workspace","share.linkSharing.label":"Link sharing","share.linkSharing.enabledDescription":"Anyone with the link can access this workspace.","share.linkSharing.disabledDescription":"Link sharing is disabled. Only you can access this workspace.","share.linkSharing.toggleLabel":"Enable link sharing","share.copyLink.title":"Copy link","share.copyLink.copied":"Copied!","login.dialogTitle":"Sign in","currentUser.dialogTitle":"Account","backToContent.label":"Back to content","toolConfig.collapse":"Collapse","toolConfig.expand":"Expand","moreMenu.ariaLabel":"More options","engine.loading":"Loading...","watermark.poweredBy":"Powered by Kritzel"}},Wt={code:"de",label:"Deutsch",terms:{"menu.copy":"Kopieren","menu.cut":"Ausschneiden","menu.paste":"Einfügen","menu.selectAll":"Alles auswählen","menu.order":"Anordnen","menu.bringToFront":"In den Vordergrund","menu.sendToBack":"In den Hintergrund","menu.moveUp":"Nach vorne","menu.moveDown":"Nach hinten","menu.align":"Ausrichten","menu.alignLeft":"Linksbündig ausrichten","menu.alignCenterHorizontal":"Horizontal zentrieren","menu.alignRight":"Rechtsbündig ausrichten","menu.alignTop":"Oben ausrichten","menu.alignCenterVertical":"Vertikal zentrieren","menu.alignBottom":"Unten ausrichten","menu.group":"Gruppieren","menu.ungroup":"Gruppierung aufheben","menu.export":"Exportieren","menu.exportAsSvg":"Als SVG exportieren","menu.exportAsPng":"Als PNG exportieren","menu.delete":"Löschen","menu.share":"Teilen","menu.import":"Importieren","menu.settings":"Einstellungen","menu.logout":"Abmelden","settings.dialogTitle":"Einstellungen","settings.categories.general":"Allgemein","settings.categories.viewport":"Ansichtsfenster","settings.categories.shortcuts":"Tastenkürzel","settings.categories.developer":"Entwickleroptionen","settings.categories.about":"Über","settings.general.title":"Allgemeine Einstellungen","settings.general.theme.label":"Design","settings.general.theme.description":"Wählen Sie ein registriertes Farbdesign für die Editor-Oberfläche.","settings.general.language.label":"Sprache","settings.general.language.description":"Wählen Sie die Anzeigesprache für die Editor-Oberfläche.","settings.general.lockDrawingScale.label":"Zeichenskalierung sperren","settings.general.lockDrawingScale.description":"Wenn aktiviert, behalten gezeichnete Objekte unabhängig von der aktuellen Zoomstufe eine feste visuelle Größe.","settings.viewport.title":"Ansichtsfenster-Einstellungen","settings.viewport.minZoom.label":"Minimale Zoomstufe","settings.viewport.minZoom.description":"Legt die minimale Zoomstufe fest. Niedrigere Werte ermöglichen weiteres Herauszoomen, um mehr von der Zeichenfläche zu sehen.","settings.viewport.maxZoom.label":"Maximale Zoomstufe","settings.viewport.maxZoom.description":"Legt die maximale Zoomstufe fest. Höhere Werte ermöglichen näheres Heranzoomen für Detailarbeit.","settings.viewport.boundaryLeft.label":"Ansichtsfenster-Grenze links","settings.viewport.boundaryLeft.description":"Linke Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach links verschoben werden kann.","settings.viewport.boundaryRight.label":"Ansichtsfenster-Grenze rechts","settings.viewport.boundaryRight.description":"Rechte Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach rechts verschoben werden kann.","settings.viewport.boundaryTop.label":"Ansichtsfenster-Grenze oben","settings.viewport.boundaryTop.description":"Obere Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach oben verschoben werden kann.","settings.viewport.boundaryBottom.label":"Ansichtsfenster-Grenze unten","settings.viewport.boundaryBottom.description":"Untere Grenze in Weltkoordinaten. Legen Sie fest, wie weit das Ansichtsfenster nach unten verschoben werden kann.","settings.viewport.boundaryPlaceholder":"Unendlich","settings.shortcuts.title":"Tastenkürzel","settings.developer.title":"Entwickleroptionen","settings.developer.showViewportInfo.label":"Ansichtsfenster-Infos anzeigen","settings.developer.showViewportInfo.description":"Zeigt Debug-Informationen zum Ansichtsfenster an, z. B. Position, Zoomstufe und Grenzen.","settings.developer.showObjectInfo.label":"Objekt-Infos anzeigen","settings.developer.showObjectInfo.description":"Zeigt Debug-Informationen zu Objekten auf der Zeichenfläche an.","settings.developer.showSyncProviderInfo.label":"Sync-Provider-Infos anzeigen","settings.developer.showSyncProviderInfo.description":"Zeigt Debug-Informationen zum Verbindungsstatus des Sync-Providers an.","settings.developer.showMigrationInfo.label":"Migrations-Infos anzeigen","settings.developer.showMigrationInfo.description":"Zeigt Debug-Informationen zu Datenmigrationen an.","settings.about.title":"Über","settings.about.description":"Kritzel – Eine Zeichenanwendung","export.dialogTitle":"Exportieren","export.tabs.viewport":"Ansichtsfenster exportieren","export.tabs.workspace":"Arbeitsbereich exportieren","export.format.label":"Format","export.filename.label":"Dateiname","export.filename.placeholder":"Dateiname eingeben","export.exportButton":"Exportieren","workspace.sharedTooltip":"Geteilter Arbeitsbereich","workspace.rename":"Umbenennen","workspace.delete":"Löschen","zoom.zoomIn":"Vergrößern","zoom.zoomOut":"Verkleinern","utility.undo":"Rückgängig","utility.redo":"Wiederholen","utility.delete":"Ausgewählte Elemente löschen","share.dialogTitle":"Arbeitsbereich teilen","share.linkSharing.label":"Link-Freigabe","share.linkSharing.enabledDescription":"Jeder mit dem Link kann auf diesen Arbeitsbereich zugreifen.","share.linkSharing.disabledDescription":"Die Link-Freigabe ist deaktiviert. Nur Sie können auf diesen Arbeitsbereich zugreifen.","share.linkSharing.toggleLabel":"Link-Freigabe aktivieren","share.copyLink.title":"Link kopieren","share.copyLink.copied":"Kopiert!","login.dialogTitle":"Anmelden","currentUser.dialogTitle":"Konto","backToContent.label":"Zurück zum Inhalt","toolConfig.collapse":"Einklappen","toolConfig.expand":"Ausklappen","moreMenu.ariaLabel":"Weitere Optionen","engine.loading":"Wird geladen...","watermark.poweredBy":"Bereitgestellt von Kritzel"}},Ut={code:"fr",label:"Français",terms:{"menu.copy":"Copier","menu.cut":"Couper","menu.paste":"Coller","menu.selectAll":"Tout sélectionner","menu.order":"Ordre","menu.bringToFront":"Mettre au premier plan","menu.sendToBack":"Mettre à l'arrière-plan","menu.moveUp":"Avancer","menu.moveDown":"Reculer","menu.align":"Aligner","menu.alignLeft":"Aligner à gauche","menu.alignCenterHorizontal":"Centrer horizontalement","menu.alignRight":"Aligner à droite","menu.alignTop":"Aligner en haut","menu.alignCenterVertical":"Centrer verticalement","menu.alignBottom":"Aligner en bas","menu.group":"Grouper","menu.ungroup":"Dégrouper","menu.export":"Exporter","menu.exportAsSvg":"Exporter en SVG","menu.exportAsPng":"Exporter en PNG","menu.delete":"Supprimer","menu.share":"Partager","menu.import":"Importer","menu.settings":"Paramètres","menu.logout":"Déconnexion","settings.dialogTitle":"Paramètres","settings.categories.general":"Général","settings.categories.viewport":"Fenêtre d'affichage","settings.categories.shortcuts":"Raccourcis clavier","settings.categories.developer":"Options développeur","settings.categories.about":"À propos","settings.general.title":"Paramètres généraux","settings.general.theme.label":"Thème","settings.general.theme.description":"Sélectionnez un thème de couleurs enregistré pour l'interface de l'éditeur.","settings.general.language.label":"Langue","settings.general.language.description":"Sélectionnez la langue d'affichage de l'interface de l'éditeur.","settings.general.lockDrawingScale.label":"Verrouiller l'échelle de dessin","settings.general.lockDrawingScale.description":"Lorsque cette option est activée, les objets dessinés conservent une taille visuelle fixe quel que soit le niveau de zoom actuel.","settings.viewport.title":"Paramètres de la fenêtre d'affichage","settings.viewport.minZoom.label":"Niveau de zoom minimal","settings.viewport.minZoom.description":"Définit le niveau de zoom minimal. Des valeurs plus faibles permettent de dézoomer davantage pour voir une plus grande partie du canevas.","settings.viewport.maxZoom.label":"Niveau de zoom maximal","settings.viewport.maxZoom.description":"Définit le niveau de zoom maximal. Des valeurs plus élevées permettent de zoomer davantage pour un travail détaillé.","settings.viewport.boundaryLeft.label":"Limite gauche de la fenêtre d'affichage","settings.viewport.boundaryLeft.description":"Limite gauche en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers la gauche.","settings.viewport.boundaryRight.label":"Limite droite de la fenêtre d'affichage","settings.viewport.boundaryRight.description":"Limite droite en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers la droite.","settings.viewport.boundaryTop.label":"Limite supérieure de la fenêtre d'affichage","settings.viewport.boundaryTop.description":"Limite supérieure en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers le haut.","settings.viewport.boundaryBottom.label":"Limite inférieure de la fenêtre d'affichage","settings.viewport.boundaryBottom.description":"Limite inférieure en coordonnées du monde. Définissez jusqu'où la fenêtre d'affichage peut se déplacer vers le bas.","settings.viewport.boundaryPlaceholder":"Infini","settings.shortcuts.title":"Raccourcis clavier","settings.developer.title":"Options développeur","settings.developer.showViewportInfo.label":"Afficher les infos de la fenêtre d'affichage","settings.developer.showViewportInfo.description":"Affiche les informations de débogage de la fenêtre d'affichage telles que la position, le niveau de zoom et les limites.","settings.developer.showObjectInfo.label":"Afficher les infos des objets","settings.developer.showObjectInfo.description":"Affiche les informations de débogage des objets sur le canevas.","settings.developer.showSyncProviderInfo.label":"Afficher les infos du fournisseur de synchronisation","settings.developer.showSyncProviderInfo.description":"Affiche les informations de débogage sur l'état de connexion du fournisseur de synchronisation.","settings.developer.showMigrationInfo.label":"Afficher les infos de migration","settings.developer.showMigrationInfo.description":"Affiche les informations de débogage sur les migrations de données.","settings.about.title":"À propos","settings.about.description":"Kritzel - Une application de dessin","export.dialogTitle":"Exporter","export.tabs.viewport":"Exporter la fenêtre d'affichage","export.tabs.workspace":"Exporter l'espace de travail","export.format.label":"Format","export.filename.label":"Nom du fichier","export.filename.placeholder":"Saisir le nom du fichier","export.exportButton":"Exporter","workspace.sharedTooltip":"Espace de travail partagé","workspace.rename":"Renommer","workspace.delete":"Supprimer","zoom.zoomIn":"Zoom avant","zoom.zoomOut":"Zoom arrière","utility.undo":"Annuler","utility.redo":"Rétablir","utility.delete":"Supprimer les éléments sélectionnés","share.dialogTitle":"Partager l'espace de travail","share.linkSharing.label":"Partage par lien","share.linkSharing.enabledDescription":"Toute personne disposant du lien peut accéder à cet espace de travail.","share.linkSharing.disabledDescription":"Le partage par lien est désactivé. Vous seul pouvez accéder à cet espace de travail.","share.linkSharing.toggleLabel":"Activer le partage par lien","share.copyLink.title":"Copier le lien","share.copyLink.copied":"Copié !","login.dialogTitle":"Se connecter","currentUser.dialogTitle":"Compte","backToContent.label":"Retour au contenu","toolConfig.collapse":"Réduire","toolConfig.expand":"Développer","moreMenu.ariaLabel":"Plus d'options","engine.loading":"Chargement...","watermark.poweredBy":"Propulsé par Kritzel"}},Ft="kritzel-settings",Kt="en";class Vt{_core;_storageKey;_builtinLocales=new Map;_customLocales=new Map;_currentLocale=Kt;_fallbackLocale=Kt;constructor(t){this._core=t,this._storageKey=t.editorId?`${Ft}-${t.editorId}`:Ft,this._builtinLocales.set(Rt.code,Rt),this._builtinLocales.set(Wt.code,Wt),this._builtinLocales.set(Ut.code,Ut),this._currentLocale=this.getStoredLocale()}get currentLocale(){return this._currentLocale}get fallbackLocale(){return this._fallbackLocale}setFallbackLocale(t){this._fallbackLocale=t}registerLocales(t){for(const e of t)this._customLocales.set(e.code,e)}setLocale(t){this._currentLocale=t,this._core.rerender()}getAvailableLocales(){return Array.from(new Set([...this._builtinLocales.keys(),...this._customLocales.keys()]))}getAvailableLocaleOptions(){return this.getAvailableLocales().map((t=>({code:t,label:this.getLocaleLabel(t)})))}getLocaleLabel(t){return this._customLocales.get(t)?.label??this._builtinLocales.get(t)?.label??t}translate(t,e){const n=this._customLocales.get(this._currentLocale)?.terms[t]??this._builtinLocales.get(this._currentLocale)?.terms[t]??this._customLocales.get(this._fallbackLocale)?.terms[t]??this._builtinLocales.get(this._fallbackLocale)?.terms[t]??t;return Dt.interpolate(n,e)}getAllTerms(){const t=new Set;for(const e of[...this._builtinLocales.values(),...this._customLocales.values()])for(const n of Object.keys(e.terms))t.add(n);const e={};for(const n of t)e[n]=this.translate(n);return e}getStoredLocale(){if("undefined"==typeof localStorage)return Kt;const t=localStorage.getItem(this._storageKey);if(!t)return Kt;try{const e=JSON.parse(t);if("string"==typeof e?.locale)return e.locale}catch{}return Kt}cleanup(){this._customLocales.clear()}}class Nt{_core;_licenseKey;_isLicensed=!1;_verifiedToken;_validationId=0;_publicKeyPromise;_timer=null;constructor(t){this._core=t}get isLicensed(){return this._isLicensed}validate(t){this._licenseKey=t;const e=++this._validationId;let n;try{n=this.preCheck(t)}catch{return this.commit(!0,e),this._isLicensed}return"rejected"===n.status?(this._verifiedToken=void 0,this.commit(!1,e),this._isLicensed):this._verifiedToken===t?(this.commit(!0,e),this._isLicensed):(this.verifySignature(n.payloadSegment,n.signatureSegment).then((n=>{e===this._validationId&&(n?(this._verifiedToken=t,this.commit(!0,e)):(this._verifiedToken=void 0,this.commit(!1,e)))})).catch((()=>{e===this._validationId&&this.commit(!0,e)})),this._isLicensed)}startPeriodicValidation(){this.stopPeriodicValidation(),this.scheduleNextValidation()}stopPeriodicValidation(){null!==this._timer&&(clearTimeout(this._timer),this._timer=null)}destroy(){this.stopPeriodicValidation()}commit(t,e){e===this._validationId&&t!==this._isLicensed&&(this._isLicensed=t,this._core.rerender())}scheduleNextValidation(){const t=this.getRandomRevalidationDelay();this._timer=setTimeout((()=>{this.validate(this._licenseKey),this.scheduleNextValidation()}),t)}getRandomRevalidationDelay(){return 3e4+Math.floor(30001*Math.random())}preCheck(t){if(null==t)return{status:"rejected"};const e=t.trim();if(0===e.length||!e.startsWith("KRTZL1."))return{status:"rejected"};const n=e.slice(7).split(".");if(2!==n.length||0===n[0].length||0===n[1].length)return{status:"rejected"};const[i,r]=n;let s;try{s=JSON.parse(this.base64UrlToString(i))}catch{return{status:"rejected"}}return null===s||"object"!=typeof s||"number"==typeof s.exp&&1e3*s.exp<=Date.now()?{status:"rejected"}:{status:"pass",payloadSegment:i,signatureSegment:r,claims:s}}async verifySignature(t,e){const n=await this.getPublicKey(),i=this.utf8Bytes(t),r=this.base64UrlToBytes(e);return crypto.subtle.verify("Ed25519",n,r,i)}getPublicKey(){if(!this._publicKeyPromise){const t=this.base64UrlToBytes("I-pYJlxDEjT94rwSaqhXW5Sv__fMKS-JKKnV3pg0PaM");this._publicKeyPromise=Promise.resolve().then((()=>crypto.subtle.importKey("raw",t,{name:"Ed25519"},!1,["verify"]))),this._publicKeyPromise.catch((()=>{this._publicKeyPromise=void 0}))}return this._publicKeyPromise}base64UrlToString(t){return(new TextDecoder).decode(this.base64UrlToBytes(t))}base64UrlToBytes(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.padEnd(e.length+(4-e.length%4)%4,"="),i=atob(n),r=new Uint8Array(new ArrayBuffer(i.length));for(let t=0;t<i.length;t++)r[t]=i.charCodeAt(t);return r}utf8Bytes(t){const e=(new TextEncoder).encode(t),n=new Uint8Array(new ArrayBuffer(e.length));return n.set(e),n}}var Gt;function Ht(t,e,n,i,r,s){const o=s?.quiet??!0,a=e.get("schemaVersion")??0;if(a>=r)return{migrated:!1,fromVersion:a,toVersion:a};const c=i.filter((t=>t.fromVersion>=a&&t.toVersion<=r)).sort(((t,e)=>t.fromVersion-e.fromVersion));return o||console.log(`[Kritzel] Running ${c.length} migration(s) from v${a} to v${r}`),t.transact((()=>{for(const e of c)o||console.log(`[Kritzel] Migrating v${e.fromVersion} → v${e.toVersion}`),e.migrate(t,n);e.set("schemaVersion",r)}),"migration"),o||console.log(`[Kritzel] Migrations complete. Schema now at v${r}`),{migrated:!0,fromVersion:a,toVersion:r}}!function(t){t.StartHorizontal="start-horizontal",t.CenterHorizontal="center-horizontal",t.EndHorizontal="end-horizontal",t.StartVertical="start-vertical",t.CenterVertical="center-vertical",t.EndVertical="end-vertical"}(Gt||(Gt={}));const Xt=[{fromVersion:1,toVersion:2,migrate(t,e){const n=e.workspaces;n&&n.forEach(((t,e)=>{const i=t?.viewport;if(!i)return;if("centerWorldX"in i)return;const r=i.scale??1,s=i.translateX??0,o=i.translateY??0,a={...t,viewport:{centerWorldX:-s/r||0,centerWorldY:-o/r||0,scale:r}};n.set(e,a)}))}}],Yt=[{fromVersion:1,toVersion:2,migrate(t,e){}}],Qt={providers:[]};var Zt,qt,Jt,te={exports:{}},ee=(Zt||(Zt=1,qt=te,Jt=te.exports,function(){var t,e="Expected a function",n="__lodash_hash_undefined__",i="__lodash_placeholder__",r=32,s=128,o=1/0,a=9007199254740991,c=NaN,l=4294967295,h=[["ary",s],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",r],["partialRight",64],["rearg",256]],u="[object Arguments]",f="[object Array]",d="[object Boolean]",p="[object Date]",g="[object Error]",v="[object Function]",w="[object GeneratorFunction]",m="[object Map]",y="[object Number]",b="[object Object]",k="[object Promise]",A="[object RegExp]",x="[object Set]",S="[object String]",M="[object Symbol]",z="[object WeakMap]",$="[object ArrayBuffer]",C="[object DataView]",T="[object Float32Array]",I="[object Float64Array]",j="[object Int8Array]",E="[object Int16Array]",_="[object Int32Array]",L="[object Uint8Array]",O="[object Uint8ClampedArray]",P="[object Uint16Array]",B="[object Uint32Array]",D=/\b__p \+= '';/g,R=/\b(__p \+=) '' \+/g,W=/(__e\(.*?\)|\b__t\)) \+\n'';/g,U=/&(?:amp|lt|gt|quot|#39);/g,F=/[&<>"']/g,K=RegExp(U.source),V=RegExp(F.source),N=/<%-([\s\S]+?)%>/g,G=/<%([\s\S]+?)%>/g,H=/<%=([\s\S]+?)%>/g,Y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Q=/^\w*$/,Z=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,q=/[\\^$.*+?()[\]{}|]/g,J=RegExp(q.source),tt=/^\s+/,et=/\s/,nt=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,it=/\{\n\/\* \[wrapped with (.+)\] \*/,rt=/,? & /,st=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ot=/[()=,{}\[\]\/\s]/,at=/\\(\\)?/g,ct=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,lt=/\w*$/,ht=/^[-+]0x[0-9a-f]+$/i,ut=/^0b[01]+$/i,ft=/^\[object .+?Constructor\]$/,dt=/^0o[0-7]+$/i,pt=/^(?:0|[1-9]\d*)$/,gt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,vt=/($^)/,wt=/['\n\r\u2028\u2029\\]/g,mt="\\ud800-\\udfff",yt="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",bt="\\u2700-\\u27bf",kt="a-z\\xdf-\\xf6\\xf8-\\xff",At="A-Z\\xc0-\\xd6\\xd8-\\xde",xt="\\ufe0e\\ufe0f",St="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Mt="["+mt+"]",zt="["+St+"]",$t="["+yt+"]",Ct="\\d+",Tt="["+bt+"]",It="["+kt+"]",jt="[^"+mt+St+Ct+bt+kt+At+"]",Et="\\ud83c[\\udffb-\\udfff]",_t="[^"+mt+"]",Lt="(?:\\ud83c[\\udde6-\\uddff]){2}",Ot="[\\ud800-\\udbff][\\udc00-\\udfff]",Pt="["+At+"]",Bt="\\u200d",Dt="(?:"+It+"|"+jt+")",Rt="(?:"+Pt+"|"+jt+")",Wt="(?:['’](?:d|ll|m|re|s|t|ve))?",Ut="(?:['’](?:D|LL|M|RE|S|T|VE))?",Ft="(?:"+$t+"|"+Et+")?",Kt="["+xt+"]?",Vt=Kt+Ft+"(?:"+Bt+"(?:"+[_t,Lt,Ot].join("|")+")"+Kt+Ft+")*",Nt="(?:"+[Tt,Lt,Ot].join("|")+")"+Vt,Gt="(?:"+[_t+$t+"?",$t,Lt,Ot,Mt].join("|")+")",Ht=RegExp("['’]","g"),Xt=RegExp($t,"g"),Yt=RegExp(Et+"(?="+Et+")|"+Gt+Vt,"g"),Qt=RegExp([Pt+"?"+It+"+"+Wt+"(?="+[zt,Pt,"$"].join("|")+")",Rt+"+"+Ut+"(?="+[zt,Pt+Dt,"$"].join("|")+")",Pt+"?"+Dt+"+"+Wt,Pt+"+"+Ut,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ct,Nt].join("|"),"g"),Zt=RegExp("["+Bt+mt+yt+xt+"]"),te=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,ee=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],ne=-1,ie={};ie[T]=ie[I]=ie[j]=ie[E]=ie[_]=ie[L]=ie[O]=ie[P]=ie[B]=!0,ie[u]=ie[f]=ie[$]=ie[d]=ie[C]=ie[p]=ie[g]=ie[v]=ie[m]=ie[y]=ie[b]=ie[A]=ie[x]=ie[S]=ie[z]=!1;var re={};re[u]=re[f]=re[$]=re[C]=re[d]=re[p]=re[T]=re[I]=re[j]=re[E]=re[_]=re[m]=re[y]=re[b]=re[A]=re[x]=re[S]=re[M]=re[L]=re[O]=re[P]=re[B]=!0,re[g]=re[v]=re[z]=!1;var se={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},oe=parseFloat,ae=parseInt,ce="object"==typeof X&&X&&X.Object===Object&&X,le="object"==typeof self&&self&&self.Object===Object&&self,he=ce||le||Function("return this")(),ue=Jt&&!Jt.nodeType&&Jt,fe=ue&&qt&&!qt.nodeType&&qt,de=fe&&fe.exports===ue,pe=de&&ce.process,ge=function(){try{return fe&&fe.require&&fe.require("util").types||pe&&pe.binding&&pe.binding("util")}catch(t){}}(),ve=ge&&ge.isArrayBuffer,we=ge&&ge.isDate,me=ge&&ge.isMap,ye=ge&&ge.isRegExp,be=ge&&ge.isSet,ke=ge&&ge.isTypedArray;function Ae(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}function xe(t,e,n,i){for(var r=-1,s=null==t?0:t.length;++r<s;){var o=t[r];e(i,o,n(o),t)}return i}function Se(t,e){for(var n=-1,i=null==t?0:t.length;++n<i&&!1!==e(t[n],n,t););return t}function Me(t,e){for(var n=null==t?0:t.length;n--&&!1!==e(t[n],n,t););return t}function ze(t,e){for(var n=-1,i=null==t?0:t.length;++n<i;)if(!e(t[n],n,t))return!1;return!0}function $e(t,e){for(var n=-1,i=null==t?0:t.length,r=0,s=[];++n<i;){var o=t[n];e(o,n,t)&&(s[r++]=o)}return s}function Ce(t,e){return!(null==t||!t.length)&&De(t,e,0)>-1}function Te(t,e,n){for(var i=-1,r=null==t?0:t.length;++i<r;)if(n(e,t[i]))return!0;return!1}function Ie(t,e){for(var n=-1,i=null==t?0:t.length,r=Array(i);++n<i;)r[n]=e(t[n],n,t);return r}function je(t,e){for(var n=-1,i=e.length,r=t.length;++n<i;)t[r+n]=e[n];return t}function Ee(t,e,n,i){var r=-1,s=null==t?0:t.length;for(i&&s&&(n=t[++r]);++r<s;)n=e(n,t[r],r,t);return n}function _e(t,e,n,i){var r=null==t?0:t.length;for(i&&r&&(n=t[--r]);r--;)n=e(n,t[r],r,t);return n}function Le(t,e){for(var n=-1,i=null==t?0:t.length;++n<i;)if(e(t[n],n,t))return!0;return!1}var Oe=Fe("length");function Pe(t,e,n){var i;return n(t,(function(t,n,r){if(e(t,n,r))return i=n,!1})),i}function Be(t,e,n,i){for(var r=t.length,s=n+(i?1:-1);i?s--:++s<r;)if(e(t[s],s,t))return s;return-1}function De(t,e,n){return e==e?function(t,e,n){for(var i=n-1,r=t.length;++i<r;)if(t[i]===e)return i;return-1}(t,e,n):Be(t,We,n)}function Re(t,e,n,i){for(var r=n-1,s=t.length;++r<s;)if(i(t[r],e))return r;return-1}function We(t){return t!=t}function Ue(t,e){var n=null==t?0:t.length;return n?Ne(t,e)/n:c}function Fe(e){return function(n){return null==n?t:n[e]}}function Ke(e){return function(n){return null==e?t:e[n]}}function Ve(t,e,n,i,r){return r(t,(function(t,r,s){n=i?(i=!1,t):e(n,t,r,s)})),n}function Ne(e,n){for(var i,r=-1,s=e.length;++r<s;){var o=n(e[r]);o!==t&&(i=i===t?o:i+o)}return i}function Ge(t,e){for(var n=-1,i=Array(t);++n<t;)i[n]=e(n);return i}function He(t){return t?t.slice(0,un(t)+1).replace(tt,""):t}function Xe(t){return function(e){return t(e)}}function Ye(t,e){return Ie(e,(function(e){return t[e]}))}function Qe(t,e){return t.has(e)}function Ze(t,e){for(var n=-1,i=t.length;++n<i&&De(e,t[n],0)>-1;);return n}function qe(t,e){for(var n=t.length;n--&&De(e,t[n],0)>-1;);return n}var Je=Ke({À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"}),tn=Ke({"&":"&","<":"<",">":">",'"':""","'":"'"});function en(t){return"\\"+se[t]}function nn(t){return Zt.test(t)}function rn(t){var e=-1,n=Array(t.size);return t.forEach((function(t,i){n[++e]=[i,t]})),n}function sn(t,e){return function(n){return t(e(n))}}function on(t,e){for(var n=-1,r=t.length,s=0,o=[];++n<r;){var a=t[n];a!==e&&a!==i||(t[n]=i,o[s++]=n)}return o}function an(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=t})),n}function cn(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=[t,t]})),n}function ln(t){return nn(t)?function(t){for(var e=Yt.lastIndex=0;Yt.test(t);)++e;return e}(t):Oe(t)}function hn(t){return nn(t)?function(t){return t.match(Yt)||[]}(t):function(t){return t.split("")}(t)}function un(t){for(var e=t.length;e--&&et.test(t.charAt(e)););return e}var fn=Ke({"&":"&","<":"<",">":">",""":'"',"'":"'"}),dn=function X(et){var mt,yt=(et=null==et?he:dn.defaults(he.Object(),et,dn.pick(he,ee))).Array,bt=et.Date,kt=et.Error,At=et.Function,xt=et.Math,St=et.Object,Mt=et.RegExp,zt=et.String,$t=et.TypeError,Ct=yt.prototype,Tt=St.prototype,It=et["__core-js_shared__"],jt=At.prototype.toString,Et=Tt.hasOwnProperty,_t=0,Lt=(mt=/[^.]+$/.exec(It&&It.keys&&It.keys.IE_PROTO||""))?"Symbol(src)_1."+mt:"",Ot=Tt.toString,Pt=jt.call(St),Bt=he._,Dt=Mt("^"+jt.call(Et).replace(q,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Rt=de?et.Buffer:t,Wt=et.Symbol,Ut=et.Uint8Array,Ft=Rt?Rt.allocUnsafe:t,Kt=sn(St.getPrototypeOf,St),Vt=St.create,Nt=Tt.propertyIsEnumerable,Gt=Ct.splice,Yt=Wt?Wt.isConcatSpreadable:t,Zt=Wt?Wt.iterator:t,qt=Wt?Wt.toStringTag:t,Jt=function(){try{var t=as(St,"defineProperty");return t({},"",{}),t}catch(t){}}(),se=et.clearTimeout!==he.clearTimeout&&et.clearTimeout,ce=bt&&bt.now!==he.Date.now&&bt.now,le=et.setTimeout!==he.setTimeout&&et.setTimeout,ue=xt.ceil,fe=xt.floor,pe=St.getOwnPropertySymbols,ge=Rt?Rt.isBuffer:t,Oe=et.isFinite,Ke=Ct.join,pn=sn(St.keys,St),gn=xt.max,vn=xt.min,wn=bt.now,mn=et.parseInt,yn=xt.random,bn=Ct.reverse,kn=as(et,"DataView"),An=as(et,"Map"),xn=as(et,"Promise"),Sn=as(et,"Set"),Mn=as(et,"WeakMap"),zn=as(St,"create"),$n=Mn&&new Mn,Cn={},Tn=_s(kn),In=_s(An),jn=_s(xn),En=_s(Sn),_n=_s(Mn),Ln=Wt?Wt.prototype:t,On=Ln?Ln.valueOf:t,Pn=Ln?Ln.toString:t;function Bn(t){if(Zo(t)&&!Wo(t)&&!(t instanceof Un)){if(t instanceof Wn)return t;if(Et.call(t,"__wrapped__"))return Ls(t)}return new Wn(t)}var Dn=function(){function e(){}return function(n){if(!Qo(n))return{};if(Vt)return Vt(n);e.prototype=n;var i=new e;return e.prototype=t,i}}();function Rn(){}function Wn(e,n){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!n,this.__index__=0,this.__values__=t}function Un(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=l,this.__views__=[]}function Fn(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function Kn(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function Vn(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}function Nn(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new Vn;++e<n;)this.add(t[e])}function Gn(t){var e=this.__data__=new Kn(t);this.size=e.size}function Hn(t,e){var n=Wo(t),i=!n&&Ro(t),r=!n&&!i&&Vo(t),s=!n&&!i&&!r&&sa(t),o=n||i||r||s,a=o?Ge(t.length,zt):[],c=a.length;for(var l in t)!e&&!Et.call(t,l)||o&&("length"==l||r&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||ps(l,c))||a.push(l);return a}function Xn(e){var n=e.length;return n?e[Vi(0,n-1)]:t}function Yn(t,e){return Is(Mr(t),ri(e,0,t.length))}function Qn(t){return Is(Mr(t))}function Zn(e,n,i){(i!==t&&!Po(e[n],i)||i===t&&!(n in e))&&ni(e,n,i)}function qn(e,n,i){var r=e[n];Et.call(e,n)&&Po(r,i)&&(i!==t||n in e)||ni(e,n,i)}function Jn(t,e){for(var n=t.length;n--;)if(Po(t[n][0],e))return n;return-1}function ti(t,e,n,i){return li(t,(function(t,r,s){e(i,t,n(t),s)})),i}function ei(t,e){return t&&zr(e,$a(e),t)}function ni(t,e,n){"__proto__"==e&&Jt?Jt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}function ii(e,n){for(var i=-1,r=n.length,s=yt(r),o=null==e;++i<r;)s[i]=o?t:Aa(e,n[i]);return s}function ri(e,n,i){return e==e&&(i!==t&&(e=e<=i?e:i),n!==t&&(e=e>=n?e:n)),e}function si(e,n,i,r,s,o){var a,c=1&n,l=2&n,h=4&n;if(i&&(a=s?i(e,r,s,o):i(e)),a!==t)return a;if(!Qo(e))return e;var f=Wo(e);if(f){if(a=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&Et.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(e),!c)return Mr(e,a)}else{var g=hs(e),k=g==v||g==w;if(Vo(e))return yr(e,c);if(g==b||g==u||k&&!s){if(a=l||k?{}:fs(e),!c)return l?function(t,e){return zr(t,ls(t),e)}(e,function(t,e){return t&&zr(e,Ca(e),t)}(a,e)):function(t,e){return zr(t,cs(t),e)}(e,ei(a,e))}else{if(!re[g])return s?e:{};a=function(t,e,n){var i=t.constructor;switch(e){case $:return br(t);case d:case p:return new i(+t);case C:return function(t,e){var n=e?br(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,n);case T:case I:case j:case E:case _:case L:case O:case P:case B:return kr(t,n);case m:return new i;case y:case S:return new i(t);case A:return function(t){var e=new t.constructor(t.source,lt.exec(t));return e.lastIndex=t.lastIndex,e}(t);case x:return new i;case M:return On?St(On.call(t)):{}}}(e,g,c)}}o||(o=new Gn);var z=o.get(e);if(z)return z;o.set(e,a),na(e)?e.forEach((function(t){a.add(si(t,n,i,t,e,o))})):qo(e)&&e.forEach((function(t,r){a.set(r,si(t,n,i,r,e,o))}));var D=f?t:(h?l?ts:Jr:l?Ca:$a)(e);return Se(D||e,(function(t,r){D&&(t=e[r=t]),qn(a,r,si(t,n,i,r,e,o))})),a}function oi(e,n,i){var r=i.length;if(null==e)return!r;for(e=St(e);r--;){var s=i[r],o=e[s];if(o===t&&!(s in e)||!(0,n[s])(o))return!1}return!0}function ai(n,i,r){if("function"!=typeof n)throw new $t(e);return zs((function(){n.apply(t,r)}),i)}function ci(t,e,n,i){var r=-1,s=Ce,o=!0,a=t.length,c=[],l=e.length;if(!a)return c;n&&(e=Ie(e,Xe(n))),i?(s=Te,o=!1):e.length>=200&&(s=Qe,o=!1,e=new Nn(e));t:for(;++r<a;){var h=t[r],u=null==n?h:n(h);if(h=i||0!==h?h:0,o&&u==u){for(var f=l;f--;)if(e[f]===u)continue t;c.push(h)}else s(e,u,i)||c.push(h)}return c}Bn.templateSettings={escape:N,evaluate:G,interpolate:H,variable:"",imports:{_:Bn}},(Bn.prototype=Rn.prototype).constructor=Bn,(Wn.prototype=Dn(Rn.prototype)).constructor=Wn,(Un.prototype=Dn(Rn.prototype)).constructor=Un,Fn.prototype.clear=function(){this.__data__=zn?zn(null):{},this.size=0},Fn.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Fn.prototype.get=function(e){var i=this.__data__;if(zn){var r=i[e];return r===n?t:r}return Et.call(i,e)?i[e]:t},Fn.prototype.has=function(e){var n=this.__data__;return zn?n[e]!==t:Et.call(n,e)},Fn.prototype.set=function(e,i){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=zn&&i===t?n:i,this},Kn.prototype.clear=function(){this.__data__=[],this.size=0},Kn.prototype.delete=function(t){var e=this.__data__,n=Jn(e,t);return!(n<0||(n==e.length-1?e.pop():Gt.call(e,n,1),--this.size,0))},Kn.prototype.get=function(e){var n=this.__data__,i=Jn(n,e);return i<0?t:n[i][1]},Kn.prototype.has=function(t){return Jn(this.__data__,t)>-1},Kn.prototype.set=function(t,e){var n=this.__data__,i=Jn(n,t);return i<0?(++this.size,n.push([t,e])):n[i][1]=e,this},Vn.prototype.clear=function(){this.size=0,this.__data__={hash:new Fn,map:new(An||Kn),string:new Fn}},Vn.prototype.delete=function(t){var e=ss(this,t).delete(t);return this.size-=e?1:0,e},Vn.prototype.get=function(t){return ss(this,t).get(t)},Vn.prototype.has=function(t){return ss(this,t).has(t)},Vn.prototype.set=function(t,e){var n=ss(this,t),i=n.size;return n.set(t,e),this.size+=n.size==i?0:1,this},Nn.prototype.add=Nn.prototype.push=function(t){return this.__data__.set(t,n),this},Nn.prototype.has=function(t){return this.__data__.has(t)},Gn.prototype.clear=function(){this.__data__=new Kn,this.size=0},Gn.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},Gn.prototype.get=function(t){return this.__data__.get(t)},Gn.prototype.has=function(t){return this.__data__.has(t)},Gn.prototype.set=function(t,e){var n=this.__data__;if(n instanceof Kn){var i=n.__data__;if(!An||i.length<199)return i.push([t,e]),this.size=++n.size,this;n=this.__data__=new Vn(i)}return n.set(t,e),this.size=n.size,this};var li=Tr(wi),hi=Tr(mi,!0);function ui(t,e){var n=!0;return li(t,(function(t,i,r){return n=!!e(t,i,r)})),n}function fi(e,n,i){for(var r=-1,s=e.length;++r<s;){var o=e[r],a=n(o);if(null!=a&&(c===t?a==a&&!ra(a):i(a,c)))var c=a,l=o}return l}function di(t,e){var n=[];return li(t,(function(t,i,r){e(t,i,r)&&n.push(t)})),n}function pi(t,e,n,i,r){var s=-1,o=t.length;for(n||(n=ds),r||(r=[]);++s<o;){var a=t[s];e>0&&n(a)?e>1?pi(a,e-1,n,i,r):je(r,a):i||(r[r.length]=a)}return r}var gi=Ir(),vi=Ir(!0);function wi(t,e){return t&&gi(t,e,$a)}function mi(t,e){return t&&vi(t,e,$a)}function yi(t,e){return $e(e,(function(e){return Ho(t[e])}))}function bi(e,n){for(var i=0,r=(n=gr(n,e)).length;null!=e&&i<r;)e=e[Es(n[i++])];return i&&i==r?e:t}function ki(t,e,n){var i=e(t);return Wo(t)?i:je(i,n(t))}function Ai(e){return null==e?e===t?"[object Undefined]":"[object Null]":qt&&qt in St(e)?function(e){var n=Et.call(e,qt),i=e[qt];try{e[qt]=t;var r=!0}catch(t){}var s=Ot.call(e);return r&&(n?e[qt]=i:delete e[qt]),s}(e):function(t){return Ot.call(t)}(e)}function xi(t,e){return t>e}function Si(t,e){return null!=t&&Et.call(t,e)}function Mi(t,e){return null!=t&&e in St(t)}function zi(e,n,i){for(var r=i?Te:Ce,s=e[0].length,o=e.length,a=o,c=yt(o),l=1/0,h=[];a--;){var u=e[a];a&&n&&(u=Ie(u,Xe(n))),l=vn(u.length,l),c[a]=!i&&(n||s>=120&&u.length>=120)?new Nn(a&&u):t}u=e[0];var f=-1,d=c[0];t:for(;++f<s&&h.length<l;){var p=u[f],g=n?n(p):p;if(p=i||0!==p?p:0,!(d?Qe(d,g):r(h,g,i))){for(a=o;--a;){var v=c[a];if(!(v?Qe(v,g):r(e[a],g,i)))continue t}d&&d.push(g),h.push(p)}}return h}function $i(e,n,i){var r=null==(e=xs(e,n=gr(n,e)))?e:e[Es(Ns(n))];return null==r?t:Ae(r,e,i)}function Ci(t){return Zo(t)&&Ai(t)==u}function Ti(e,n,i,r,s){return e===n||(null==e||null==n||!Zo(e)&&!Zo(n)?e!=e&&n!=n:function(e,n,i,r,s,o){var a=Wo(e),c=Wo(n),l=a?f:hs(e),h=c?f:hs(n),v=(l=l==u?b:l)==b,w=(h=h==u?b:h)==b,k=l==h;if(k&&Vo(e)){if(!Vo(n))return!1;a=!0,v=!1}if(k&&!v)return o||(o=new Gn),a||sa(e)?Zr(e,n,i,r,s,o):function(t,e,n,i,r,s,o){switch(n){case C:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case $:return!(t.byteLength!=e.byteLength||!s(new Ut(t),new Ut(e)));case d:case p:case y:return Po(+t,+e);case g:return t.name==e.name&&t.message==e.message;case A:case S:return t==e+"";case m:var a=rn;case x:if(a||(a=an),t.size!=e.size&&!(1&i))return!1;var c=o.get(t);if(c)return c==e;i|=2,o.set(t,e);var l=Zr(a(t),a(e),i,r,s,o);return o.delete(t),l;case M:if(On)return On.call(t)==On.call(e)}return!1}(e,n,l,i,r,s,o);if(!(1&i)){var z=v&&Et.call(e,"__wrapped__"),T=w&&Et.call(n,"__wrapped__");if(z||T){var I=z?e.value():e,j=T?n.value():n;return o||(o=new Gn),s(I,j,i,r,o)}}return!!k&&(o||(o=new Gn),function(e,n,i,r,s,o){var a=1&i,c=Jr(e),l=c.length;if(l!=Jr(n).length&&!a)return!1;for(var h=l;h--;){var u=c[h];if(!(a?u in n:Et.call(n,u)))return!1}var f=o.get(e),d=o.get(n);if(f&&d)return f==n&&d==e;var p=!0;o.set(e,n),o.set(n,e);for(var g=a;++h<l;){var v=e[u=c[h]],w=n[u];if(r)var m=a?r(w,v,u,n,e,o):r(v,w,u,e,n,o);if(!(m===t?v===w||s(v,w,i,r,o):m)){p=!1;break}g||(g="constructor"==u)}if(p&&!g){var y=e.constructor,b=n.constructor;y==b||!("constructor"in e)||!("constructor"in n)||"function"==typeof y&&y instanceof y&&"function"==typeof b&&b instanceof b||(p=!1)}return o.delete(e),o.delete(n),p}(e,n,i,r,s,o))}(e,n,i,r,Ti,s))}function Ii(e,n,i,r){var s=i.length,o=s,a=!r;if(null==e)return!o;for(e=St(e);s--;){var c=i[s];if(a&&c[2]?c[1]!==e[c[0]]:!(c[0]in e))return!1}for(;++s<o;){var l=(c=i[s])[0],h=e[l],u=c[1];if(a&&c[2]){if(h===t&&!(l in e))return!1}else{var f=new Gn;if(r)var d=r(h,u,l,e,n,f);if(!(d===t?Ti(u,h,3,r,f):d))return!1}}return!0}function ji(t){return!(!Qo(t)||(e=t,Lt&&Lt in e))&&(Ho(t)?Dt:ft).test(_s(t));var e}function Ei(t){return"function"==typeof t?t:null==t?Ja:"object"==typeof t?Wo(t)?Bi(t[0],t[1]):Pi(t):cc(t)}function _i(t){if(!ys(t))return pn(t);var e=[];for(var n in St(t))Et.call(t,n)&&"constructor"!=n&&e.push(n);return e}function Li(t,e){return t<e}function Oi(t,e){var n=-1,i=Fo(t)?yt(t.length):[];return li(t,(function(t,r,s){i[++n]=e(t,r,s)})),i}function Pi(t){var e=os(t);return 1==e.length&&e[0][2]?ks(e[0][0],e[0][1]):function(n){return n===t||Ii(n,t,e)}}function Bi(e,n){return vs(e)&&bs(n)?ks(Es(e),n):function(i){var r=Aa(i,e);return r===t&&r===n?xa(i,e):Ti(n,r,3)}}function Di(e,n,i,r,s){e!==n&&gi(n,(function(o,a){if(s||(s=new Gn),Qo(o))!function(e,n,i,r,s,o,a){var c=Ss(e,i),l=Ss(n,i),h=a.get(l);if(h)Zn(e,i,h);else{var u=o?o(c,l,i+"",e,n,a):t,f=u===t;if(f){var d=Wo(l),p=!d&&Vo(l),g=!d&&!p&&sa(l);u=l,d||p||g?Wo(c)?u=c:Ko(c)?u=Mr(c):p?(f=!1,u=yr(l,!0)):g?(f=!1,u=kr(l,!0)):u=[]:ta(l)||Ro(l)?(u=c,Ro(c)?u=da(c):Qo(c)&&!Ho(c)||(u=fs(l))):f=!1}f&&(a.set(l,u),s(u,l,r,o,a),a.delete(l)),Zn(e,i,u)}}(e,n,a,i,Di,r,s);else{var c=r?r(Ss(e,a),o,a+"",e,n,s):t;c===t&&(c=o),Zn(e,a,c)}}),Ca)}function Ri(e,n){var i=e.length;if(i)return ps(n+=n<0?i:0,i)?e[n]:t}function Wi(t,e,n){e=e.length?Ie(e,(function(t){return Wo(t)?function(e){return bi(e,1===t.length?t[0]:t)}:t})):[Ja];var i=-1;e=Ie(e,Xe(rs()));var r=Oi(t,(function(t){var n=Ie(e,(function(e){return e(t)}));return{criteria:n,index:++i,value:t}}));return function(t){var e=t.length;for(t.sort((function(t,e){return function(t,e,n){for(var i=-1,r=t.criteria,s=e.criteria,o=r.length,a=n.length;++i<o;){var c=Ar(r[i],s[i]);if(c)return i>=a?c:c*("desc"==n[i]?-1:1)}return t.index-e.index}(t,e,n)}));e--;)t[e]=t[e].value;return t}(r)}function Ui(t,e,n){for(var i=-1,r=e.length,s={};++i<r;){var o=e[i],a=bi(t,o);n(a,o)&&Yi(s,gr(o,t),a)}return s}function Fi(t,e,n,i){var r=i?Re:De,s=-1,o=e.length,a=t;for(t===e&&(e=Mr(e)),n&&(a=Ie(t,Xe(n)));++s<o;)for(var c=0,l=e[s],h=n?n(l):l;(c=r(a,h,c,i))>-1;)a!==t&&Gt.call(a,c,1),Gt.call(t,c,1);return t}function Ki(t,e){for(var n=t?e.length:0,i=n-1;n--;){var r=e[n];if(n==i||r!==s){var s=r;ps(r)?Gt.call(t,r,1):ar(t,r)}}return t}function Vi(t,e){return t+fe(yn()*(e-t+1))}function Ni(t,e){var n="";if(!t||e<1||e>a)return n;do{e%2&&(n+=t),(e=fe(e/2))&&(t+=t)}while(e);return n}function Gi(t,e){return $s(As(t,e,Ja),t+"")}function Hi(t){return Xn(Pa(t))}function Xi(t,e){var n=Pa(t);return Is(n,ri(e,0,n.length))}function Yi(e,n,i,r){if(!Qo(e))return e;for(var s=-1,o=(n=gr(n,e)).length,a=o-1,c=e;null!=c&&++s<o;){var l=Es(n[s]),h=i;if("__proto__"===l||"constructor"===l||"prototype"===l)return e;if(s!=a){var u=c[l];(h=r?r(u,l,c):t)===t&&(h=Qo(u)?u:ps(n[s+1])?[]:{})}qn(c,l,h),c=c[l]}return e}var Qi=$n?function(t,e){return $n.set(t,e),t}:Ja,Zi=Jt?function(t,e){return Jt(t,"toString",{configurable:!0,enumerable:!1,value:Qa(e),writable:!0})}:Ja;function qi(t){return Is(Pa(t))}function Ji(t,e,n){var i=-1,r=t.length;e<0&&(e=-e>r?0:r+e),(n=n>r?r:n)<0&&(n+=r),r=e>n?0:n-e>>>0,e>>>=0;for(var s=yt(r);++i<r;)s[i]=t[i+e];return s}function tr(t,e){var n;return li(t,(function(t,i,r){return!(n=e(t,i,r))})),!!n}function er(t,e,n){var i=0,r=null==t?i:t.length;if("number"==typeof e&&e==e&&r<=2147483647){for(;i<r;){var s=i+r>>>1,o=t[s];null!==o&&!ra(o)&&(n?o<=e:o<e)?i=s+1:r=s}return r}return nr(t,e,Ja,n)}function nr(e,n,i,r){var s=0,o=null==e?0:e.length;if(0===o)return 0;for(var a=(n=i(n))!=n,c=null===n,l=ra(n),h=n===t;s<o;){var u=fe((s+o)/2),f=i(e[u]),d=f!==t,p=null===f,g=f==f,v=ra(f);if(a)var w=r||g;else w=h?g&&(r||d):c?g&&d&&(r||!p):l?g&&d&&!p&&(r||!v):!p&&!v&&(r?f<=n:f<n);w?s=u+1:o=u}return vn(o,4294967294)}function ir(t,e){for(var n=-1,i=t.length,r=0,s=[];++n<i;){var o=t[n],a=e?e(o):o;if(!n||!Po(a,c)){var c=a;s[r++]=0===o?0:o}}return s}function rr(t){return"number"==typeof t?t:ra(t)?c:+t}function sr(t){if("string"==typeof t)return t;if(Wo(t))return Ie(t,sr)+"";if(ra(t))return Pn?Pn.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function or(t,e,n){var i=-1,r=Ce,s=t.length,o=!0,a=[],c=a;if(n)o=!1,r=Te;else if(s>=200){var l=e?null:Nr(t);if(l)return an(l);o=!1,r=Qe,c=new Nn}else c=e?[]:a;t:for(;++i<s;){var h=t[i],u=e?e(h):h;if(h=n||0!==h?h:0,o&&u==u){for(var f=c.length;f--;)if(c[f]===u)continue t;e&&c.push(u),a.push(h)}else r(c,u,n)||(c!==a&&c.push(u),a.push(h))}return a}function ar(t,e){var n=-1,i=(e=gr(e,t)).length;if(!i)return!0;for(;++n<i;){var r=Es(e[n]);if("__proto__"===r&&!Et.call(t,"__proto__"))return!1;if(("constructor"===r||"prototype"===r)&&n<i-1)return!1}var s=xs(t,e);return null==s||delete s[Es(Ns(e))]}function cr(t,e,n,i){return Yi(t,e,n(bi(t,e)),i)}function lr(t,e,n,i){for(var r=t.length,s=i?r:-1;(i?s--:++s<r)&&e(t[s],s,t););return n?Ji(t,i?0:s,i?s+1:r):Ji(t,i?s+1:0,i?r:s)}function hr(t,e){var n=t;return n instanceof Un&&(n=n.value()),Ee(e,(function(t,e){return e.func.apply(e.thisArg,je([t],e.args))}),n)}function ur(t,e,n){var i=t.length;if(i<2)return i?or(t[0]):[];for(var r=-1,s=yt(i);++r<i;)for(var o=t[r],a=-1;++a<i;)a!=r&&(s[r]=ci(s[r]||o,t[a],e,n));return or(pi(s,1),e,n)}function fr(e,n,i){for(var r=-1,s=e.length,o=n.length,a={};++r<s;)i(a,e[r],r<o?n[r]:t);return a}function dr(t){return Ko(t)?t:[]}function pr(t){return"function"==typeof t?t:Ja}function gr(t,e){return Wo(t)?t:vs(t,e)?[t]:js(pa(t))}var vr=Gi;function wr(e,n,i){var r=e.length;return i=i===t?r:i,!n&&i>=r?e:Ji(e,n,i)}var mr=se||function(t){return he.clearTimeout(t)};function yr(t,e){if(e)return t.slice();var n=t.length,i=Ft?Ft(n):new t.constructor(n);return t.copy(i),i}function br(t){var e=new t.constructor(t.byteLength);return new Ut(e).set(new Ut(t)),e}function kr(t,e){var n=e?br(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}function Ar(e,n){if(e!==n){var i=e!==t,r=null===e,s=e==e,o=ra(e),a=n!==t,c=null===n,l=n==n,h=ra(n);if(!c&&!h&&!o&&e>n||o&&a&&l&&!c&&!h||r&&a&&l||!i&&l||!s)return 1;if(!r&&!o&&!h&&e<n||h&&i&&s&&!r&&!o||c&&i&&s||!a&&s||!l)return-1}return 0}function xr(t,e,n,i){for(var r=-1,s=t.length,o=n.length,a=-1,c=e.length,l=gn(s-o,0),h=yt(c+l),u=!i;++a<c;)h[a]=e[a];for(;++r<o;)(u||r<s)&&(h[n[r]]=t[r]);for(;l--;)h[a++]=t[r++];return h}function Sr(t,e,n,i){for(var r=-1,s=t.length,o=-1,a=n.length,c=-1,l=e.length,h=gn(s-a,0),u=yt(h+l),f=!i;++r<h;)u[r]=t[r];for(var d=r;++c<l;)u[d+c]=e[c];for(;++o<a;)(f||r<s)&&(u[d+n[o]]=t[r++]);return u}function Mr(t,e){var n=-1,i=t.length;for(e||(e=yt(i));++n<i;)e[n]=t[n];return e}function zr(e,n,i,r){var s=!i;i||(i={});for(var o=-1,a=n.length;++o<a;){var c=n[o],l=r?r(i[c],e[c],c,i,e):t;l===t&&(l=e[c]),s?ni(i,c,l):qn(i,c,l)}return i}function $r(t,e){return function(n,i){var r=Wo(n)?xe:ti,s=e?e():{};return r(n,t,rs(i,2),s)}}function Cr(e){return Gi((function(n,i){var r=-1,s=i.length,o=s>1?i[s-1]:t,a=s>2?i[2]:t;for(o=e.length>3&&"function"==typeof o?(s--,o):t,a&&gs(i[0],i[1],a)&&(o=s<3?t:o,s=1),n=St(n);++r<s;){var c=i[r];c&&e(n,c,r,o)}return n}))}function Tr(t,e){return function(n,i){if(null==n)return n;if(!Fo(n))return t(n,i);for(var r=n.length,s=e?r:-1,o=St(n);(e?s--:++s<r)&&!1!==i(o[s],s,o););return n}}function Ir(t){return function(e,n,i){for(var r=-1,s=St(e),o=i(e),a=o.length;a--;){var c=o[t?a:++r];if(!1===n(s[c],c,s))break}return e}}function jr(e){return function(n){var i=nn(n=pa(n))?hn(n):t,r=i?i[0]:n.charAt(0),s=i?wr(i,1).join(""):n.slice(1);return r[e]()+s}}function Er(t){return function(e){return Ee(Ha(Ra(e).replace(Ht,"")),t,"")}}function _r(t){return function(){var e=arguments;switch(e.length){case 0:return new t;case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3]);case 5:return new t(e[0],e[1],e[2],e[3],e[4]);case 6:return new t(e[0],e[1],e[2],e[3],e[4],e[5]);case 7:return new t(e[0],e[1],e[2],e[3],e[4],e[5],e[6])}var n=Dn(t.prototype),i=t.apply(n,e);return Qo(i)?i:n}}function Lr(e){return function(n,i,r){var s=St(n);if(!Fo(n)){var o=rs(i,3);n=$a(n),i=function(t){return o(s[t],t,s)}}var a=e(n,i,r);return a>-1?s[o?n[a]:a]:t}}function Or(n){return qr((function(i){var r=i.length,s=r,o=Wn.prototype.thru;for(n&&i.reverse();s--;){var a=i[s];if("function"!=typeof a)throw new $t(e);if(o&&!c&&"wrapper"==ns(a))var c=new Wn([],!0)}for(s=c?s:r;++s<r;){var l=ns(a=i[s]),h="wrapper"==l?es(a):t;c=h&&ws(h[0])&&424==h[1]&&!h[4].length&&1==h[9]?c[ns(h[0])].apply(c,h[3]):1==a.length&&ws(a)?c[l]():c.thru(a)}return function(){var t=arguments,e=t[0];if(c&&1==t.length&&Wo(e))return c.plant(e).value();for(var n=0,s=r?i[n].apply(this,t):e;++n<r;)s=i[n].call(this,s);return s}}))}function Pr(e,n,i,r,o,a,c,l,h,u){var f=n&s,d=1&n,p=2&n,g=24&n,v=512&n,w=p?t:_r(e);return function s(){for(var m=arguments.length,y=yt(m),b=m;b--;)y[b]=arguments[b];if(g)var k=is(s),A=function(t,e){for(var n=t.length,i=0;n--;)t[n]===e&&++i;return i}(y,k);if(r&&(y=xr(y,r,o,g)),a&&(y=Sr(y,a,c,g)),m-=A,g&&m<u){var x=on(y,k);return Kr(e,n,Pr,s.placeholder,i,y,x,l,h,u-m)}var S=d?i:this,M=p?S[e]:e;return m=y.length,l?y=function(e,n){for(var i=e.length,r=vn(n.length,i),s=Mr(e);r--;){var o=n[r];e[r]=ps(o,i)?s[o]:t}return e}(y,l):v&&m>1&&y.reverse(),f&&h<m&&(y.length=h),this&&this!==he&&this instanceof s&&(M=w||_r(M)),M.apply(S,y)}}function Br(t,e){return function(n,i){return function(t,e,n,i){return wi(t,(function(t,r,s){e(i,n(t),r,s)})),i}(n,t,e(i),{})}}function Dr(e,n){return function(i,r){var s;if(i===t&&r===t)return n;if(i!==t&&(s=i),r!==t){if(s===t)return r;"string"==typeof i||"string"==typeof r?(i=sr(i),r=sr(r)):(i=rr(i),r=rr(r)),s=e(i,r)}return s}}function Rr(t){return qr((function(e){return e=Ie(e,Xe(rs())),Gi((function(n){var i=this;return t(e,(function(t){return Ae(t,i,n)}))}))}))}function Wr(e,n){var i=(n=n===t?" ":sr(n)).length;if(i<2)return i?Ni(n,e):n;var r=Ni(n,ue(e/ln(n)));return nn(n)?wr(hn(r),0,e).join(""):r.slice(0,e)}function Ur(e){return function(n,i,r){return r&&"number"!=typeof r&&gs(n,i,r)&&(i=r=t),n=la(n),i===t?(i=n,n=0):i=la(i),function(t,e,n,i){for(var r=-1,s=gn(ue((e-t)/(n||1)),0),o=yt(s);s--;)o[i?s:++r]=t,t+=n;return o}(n,i,r=r===t?n<i?1:-1:la(r),e)}}function Fr(t){return function(e,n){return"string"==typeof e&&"string"==typeof n||(e=fa(e),n=fa(n)),t(e,n)}}function Kr(e,n,i,s,o,a,c,l,h,u){var f=8&n;n|=f?r:64,4&(n&=~(f?64:r))||(n&=-4);var d=[e,n,o,f?a:t,f?c:t,f?t:a,f?t:c,l,h,u],p=i.apply(t,d);return ws(e)&&Ms(p,d),p.placeholder=s,Cs(p,e,n)}function Vr(t){var e=xt[t];return function(t,n){if(t=fa(t),(n=null==n?0:vn(ha(n),292))&&Oe(t)){var i=(pa(t)+"e").split("e");return+((i=(pa(e(i[0]+"e"+(+i[1]+n)))+"e").split("e"))[0]+"e"+(+i[1]-n))}return e(t)}}var Nr=Sn&&1/an(new Sn([,-0]))[1]==o?function(t){return new Sn(t)}:rc;function Gr(t){return function(e){var n=hs(e);return n==m?rn(e):n==x?cn(e):function(t,e){return Ie(e,(function(e){return[e,t[e]]}))}(e,t(e))}}function Hr(n,o,a,c,l,h,u,f){var d=2&o;if(!d&&"function"!=typeof n)throw new $t(e);var p=c?c.length:0;if(p||(o&=-97,c=l=t),u=u===t?u:gn(ha(u),0),f=f===t?f:ha(f),p-=l?l.length:0,64&o){var g=c,v=l;c=l=t}var w=d?t:es(n),m=[n,o,a,c,l,g,v,h,u,f];if(w&&function(t,e){var n=t[1],r=e[1],o=n|r;if(!(o<131||(r==s&&8==n||r==s&&256==n&&t[7].length<=e[8]||384==r&&e[7].length<=e[8]&&8==n)))return t;1&r&&(t[2]=e[2],o|=1&n?0:4);var a=e[3];if(a){var c=t[3];t[3]=c?xr(c,a,e[4]):a,t[4]=c?on(t[3],i):e[4]}(a=e[5])&&(t[5]=(c=t[5])?Sr(c,a,e[6]):a,t[6]=c?on(t[5],i):e[6]),(a=e[7])&&(t[7]=a),r&s&&(t[8]=null==t[8]?e[8]:vn(t[8],e[8])),null==t[9]&&(t[9]=e[9]),t[0]=e[0],t[1]=o}(m,w),n=m[0],o=m[1],a=m[2],c=m[3],l=m[4],!(f=m[9]=m[9]===t?d?0:n.length:gn(m[9]-p,0))&&24&o&&(o&=-25),o&&1!=o)y=8==o||16==o?function(e,n,i){var r=_r(e);return function s(){for(var o=arguments.length,a=yt(o),c=o,l=is(s);c--;)a[c]=arguments[c];var h=o<3&&a[0]!==l&&a[o-1]!==l?[]:on(a,l);return(o-=h.length)<i?Kr(e,n,Pr,s.placeholder,t,a,h,t,t,i-o):Ae(this&&this!==he&&this instanceof s?r:e,this,a)}}(n,o,f):o!=r&&33!=o||l.length?Pr.apply(t,m):function(t,e,n,i){var r=1&e,s=_r(t);return function e(){for(var o=-1,a=arguments.length,c=-1,l=i.length,h=yt(l+a),u=this&&this!==he&&this instanceof e?s:t;++c<l;)h[c]=i[c];for(;a--;)h[c++]=arguments[++o];return Ae(u,r?n:this,h)}}(n,o,a,c);else var y=function(t,e,n){var i=1&e,r=_r(t);return function e(){return(this&&this!==he&&this instanceof e?r:t).apply(i?n:this,arguments)}}(n,o,a);return Cs((w?Qi:Ms)(y,m),n,o)}function Xr(e,n,i,r){return e===t||Po(e,Tt[i])&&!Et.call(r,i)?n:e}function Yr(e,n,i,r,s,o){return Qo(e)&&Qo(n)&&(o.set(n,e),Di(e,n,t,Yr,o),o.delete(n)),e}function Qr(e){return ta(e)?t:e}function Zr(e,n,i,r,s,o){var a=1&i,c=e.length,l=n.length;if(c!=l&&!(a&&l>c))return!1;var h=o.get(e),u=o.get(n);if(h&&u)return h==n&&u==e;var f=-1,d=!0,p=2&i?new Nn:t;for(o.set(e,n),o.set(n,e);++f<c;){var g=e[f],v=n[f];if(r)var w=a?r(v,g,f,n,e,o):r(g,v,f,e,n,o);if(w!==t){if(w)continue;d=!1;break}if(p){if(!Le(n,(function(t,e){if(!Qe(p,e)&&(g===t||s(g,t,i,r,o)))return p.push(e)}))){d=!1;break}}else if(g!==v&&!s(g,v,i,r,o)){d=!1;break}}return o.delete(e),o.delete(n),d}function qr(e){return $s(As(e,t,Ws),e+"")}function Jr(t){return ki(t,$a,cs)}function ts(t){return ki(t,Ca,ls)}var es=$n?function(t){return $n.get(t)}:rc;function ns(t){for(var e=t.name+"",n=Cn[e],i=Et.call(Cn,e)?n.length:0;i--;){var r=n[i],s=r.func;if(null==s||s==t)return r.name}return e}function is(t){return(Et.call(Bn,"placeholder")?Bn:t).placeholder}function rs(){var t=Bn.iteratee||tc;return t=t===tc?Ei:t,arguments.length?t(arguments[0],arguments[1]):t}function ss(t,e){var n,i,r=t.__data__;return("string"==(i=typeof(n=e))||"number"==i||"symbol"==i||"boolean"==i?"__proto__"!==n:null===n)?r["string"==typeof e?"string":"hash"]:r.map}function os(t){for(var e=$a(t),n=e.length;n--;){var i=e[n],r=t[i];e[n]=[i,r,bs(r)]}return e}function as(e,n){var i=function(e,n){return null==e?t:e[n]}(e,n);return ji(i)?i:t}var cs=pe?function(t){return null==t?[]:(t=St(t),$e(pe(t),(function(e){return Nt.call(t,e)})))}:uc,ls=pe?function(t){for(var e=[];t;)je(e,cs(t)),t=Kt(t);return e}:uc,hs=Ai;function us(t,e,n){for(var i=-1,r=(e=gr(e,t)).length,s=!1;++i<r;){var o=Es(e[i]);if(!(s=null!=t&&n(t,o)))break;t=t[o]}return s||++i!=r?s:!!(r=null==t?0:t.length)&&Yo(r)&&ps(o,r)&&(Wo(t)||Ro(t))}function fs(t){return"function"!=typeof t.constructor||ys(t)?{}:Dn(Kt(t))}function ds(t){return Wo(t)||Ro(t)||!!(Yt&&t&&t[Yt])}function ps(t,e){var n=typeof t;return!!(e=null==e?a:e)&&("number"==n||"symbol"!=n&&pt.test(t))&&t>-1&&t%1==0&&t<e}function gs(t,e,n){if(!Qo(n))return!1;var i=typeof e;return!!("number"==i?Fo(n)&&ps(e,n.length):"string"==i&&e in n)&&Po(n[e],t)}function vs(t,e){if(Wo(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!ra(t))||Q.test(t)||!Y.test(t)||null!=e&&t in St(e)}function ws(t){var e=ns(t),n=Bn[e];if("function"!=typeof n||!(e in Un.prototype))return!1;if(t===n)return!0;var i=es(n);return!!i&&t===i[0]}(kn&&hs(new kn(new ArrayBuffer(1)))!=C||An&&hs(new An)!=m||xn&&hs(xn.resolve())!=k||Sn&&hs(new Sn)!=x||Mn&&hs(new Mn)!=z)&&(hs=function(e){var n=Ai(e),i=n==b?e.constructor:t,r=i?_s(i):"";if(r)switch(r){case Tn:return C;case In:return m;case jn:return k;case En:return x;case _n:return z}return n});var ms=It?Ho:fc;function ys(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Tt)}function bs(t){return t==t&&!Qo(t)}function ks(e,n){return function(i){return null!=i&&i[e]===n&&(n!==t||e in St(i))}}function As(e,n,i){return n=gn(n===t?e.length-1:n,0),function(){for(var t=arguments,r=-1,s=gn(t.length-n,0),o=yt(s);++r<s;)o[r]=t[n+r];r=-1;for(var a=yt(n+1);++r<n;)a[r]=t[r];return a[n]=i(o),Ae(e,this,a)}}function xs(t,e){return e.length<2?t:bi(t,Ji(e,0,-1))}function Ss(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var Ms=Ts(Qi),zs=le||function(t,e){return he.setTimeout(t,e)},$s=Ts(Zi);function Cs(t,e,n){var i=e+"";return $s(t,function(t,e){var n=e.length;if(!n)return t;var i=n-1;return e[i]=(n>1?"& ":"")+e[i],e=e.join(n>2?", ":" "),t.replace(nt,"{\n/* [wrapped with "+e+"] */\n")}(i,function(t,e){return Se(h,(function(n){var i="_."+n[0];e&n[1]&&!Ce(t,i)&&t.push(i)})),t.sort()}(function(t){var e=t.match(it);return e?e[1].split(rt):[]}(i),n)))}function Ts(e){var n=0,i=0;return function(){var r=wn(),s=16-(r-i);if(i=r,s>0){if(++n>=800)return arguments[0]}else n=0;return e.apply(t,arguments)}}function Is(e,n){var i=-1,r=e.length,s=r-1;for(n=n===t?r:n;++i<n;){var o=Vi(i,s),a=e[o];e[o]=e[i],e[i]=a}return e.length=n,e}var js=function(){var t=Io((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Z,(function(t,n,i,r){e.push(i?r.replace(at,"$1"):n||t)})),e}),(function(t){return 500===e.size&&e.clear(),t})),e=t.cache;return t}();function Es(t){if("string"==typeof t||ra(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function _s(t){if(null!=t){try{return jt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Ls(t){if(t instanceof Un)return t.clone();var e=new Wn(t.__wrapped__,t.__chain__);return e.__actions__=Mr(t.__actions__),e.__index__=t.__index__,e.__values__=t.__values__,e}var Os=Gi((function(t,e){return Ko(t)?ci(t,pi(e,1,Ko,!0)):[]})),Ps=Gi((function(e,n){var i=Ns(n);return Ko(i)&&(i=t),Ko(e)?ci(e,pi(n,1,Ko,!0),rs(i,2)):[]})),Bs=Gi((function(e,n){var i=Ns(n);return Ko(i)&&(i=t),Ko(e)?ci(e,pi(n,1,Ko,!0),t,i):[]}));function Ds(t,e,n){var i=null==t?0:t.length;if(!i)return-1;var r=null==n?0:ha(n);return r<0&&(r=gn(i+r,0)),Be(t,rs(e,3),r)}function Rs(e,n,i){var r=null==e?0:e.length;if(!r)return-1;var s=r-1;return i!==t&&(s=ha(i),s=i<0?gn(r+s,0):vn(s,r-1)),Be(e,rs(n,3),s,!0)}function Ws(t){return null!=t&&t.length?pi(t,1):[]}function Us(e){return e&&e.length?e[0]:t}var Fs=Gi((function(t){var e=Ie(t,dr);return e.length&&e[0]===t[0]?zi(e):[]})),Ks=Gi((function(e){var n=Ns(e),i=Ie(e,dr);return n===Ns(i)?n=t:i.pop(),i.length&&i[0]===e[0]?zi(i,rs(n,2)):[]})),Vs=Gi((function(e){var n=Ns(e),i=Ie(e,dr);return(n="function"==typeof n?n:t)&&i.pop(),i.length&&i[0]===e[0]?zi(i,t,n):[]}));function Ns(e){var n=null==e?0:e.length;return n?e[n-1]:t}var Gs=Gi(Hs);function Hs(t,e){return t&&t.length&&e&&e.length?Fi(t,e):t}var Xs=qr((function(t,e){var n=null==t?0:t.length,i=ii(t,e);return Ki(t,Ie(e,(function(t){return ps(t,n)?+t:t})).sort(Ar)),i}));function Ys(t){return null==t?t:bn.call(t)}var Qs=Gi((function(t){return or(pi(t,1,Ko,!0))})),Zs=Gi((function(e){var n=Ns(e);return Ko(n)&&(n=t),or(pi(e,1,Ko,!0),rs(n,2))})),qs=Gi((function(e){var n=Ns(e);return n="function"==typeof n?n:t,or(pi(e,1,Ko,!0),t,n)}));function Js(t){if(!t||!t.length)return[];var e=0;return t=$e(t,(function(t){if(Ko(t))return e=gn(t.length,e),!0})),Ge(e,(function(e){return Ie(t,Fe(e))}))}function to(e,n){if(!e||!e.length)return[];var i=Js(e);return null==n?i:Ie(i,(function(e){return Ae(n,t,e)}))}var eo=Gi((function(t,e){return Ko(t)?ci(t,e):[]})),no=Gi((function(t){return ur($e(t,Ko))})),io=Gi((function(e){var n=Ns(e);return Ko(n)&&(n=t),ur($e(e,Ko),rs(n,2))})),ro=Gi((function(e){var n=Ns(e);return n="function"==typeof n?n:t,ur($e(e,Ko),t,n)})),so=Gi(Js),oo=Gi((function(e){var n=e.length,i=n>1?e[n-1]:t;return i="function"==typeof i?(e.pop(),i):t,to(e,i)}));function ao(t){var e=Bn(t);return e.__chain__=!0,e}function co(t,e){return e(t)}var lo=qr((function(e){var n=e.length,i=n?e[0]:0,r=this.__wrapped__,s=function(t){return ii(t,e)};return!(n>1||this.__actions__.length)&&r instanceof Un&&ps(i)?((r=r.slice(i,+i+(n?1:0))).__actions__.push({func:co,args:[s],thisArg:t}),new Wn(r,this.__chain__).thru((function(e){return n&&!e.length&&e.push(t),e}))):this.thru(s)})),ho=$r((function(t,e,n){Et.call(t,n)?++t[n]:ni(t,n,1)})),uo=Lr(Ds),fo=Lr(Rs);function po(t,e){return(Wo(t)?Se:li)(t,rs(e,3))}function go(t,e){return(Wo(t)?Me:hi)(t,rs(e,3))}var vo=$r((function(t,e,n){Et.call(t,n)?t[n].push(e):ni(t,n,[e])})),wo=Gi((function(t,e,n){var i=-1,r="function"==typeof e,s=Fo(t)?yt(t.length):[];return li(t,(function(t){s[++i]=r?Ae(e,t,n):$i(t,e,n)})),s})),mo=$r((function(t,e,n){ni(t,n,e)}));function yo(t,e){return(Wo(t)?Ie:Oi)(t,rs(e,3))}var bo=$r((function(t,e,n){t[n?0:1].push(e)}),(function(){return[[],[]]})),ko=Gi((function(t,e){if(null==t)return[];var n=e.length;return n>1&&gs(t,e[0],e[1])?e=[]:n>2&&gs(e[0],e[1],e[2])&&(e=[e[0]]),Wi(t,pi(e,1),[])})),Ao=ce||function(){return he.Date.now()};function xo(e,n,i){return n=i?t:n,Hr(e,s,t,t,t,t,n=e&&null==n?e.length:n)}function So(n,i){var r;if("function"!=typeof i)throw new $t(e);return n=ha(n),function(){return--n>0&&(r=i.apply(this,arguments)),n<=1&&(i=t),r}}var Mo=Gi((function(t,e,n){var i=1;if(n.length){var s=on(n,is(Mo));i|=r}return Hr(t,i,e,n,s)})),zo=Gi((function(t,e,n){var i=3;if(n.length){var s=on(n,is(zo));i|=r}return Hr(e,i,t,n,s)}));function $o(n,i,r){var s,o,a,c,l,h,u=0,f=!1,d=!1,p=!0;if("function"!=typeof n)throw new $t(e);function g(e){var i=s,r=o;return s=o=t,u=e,c=n.apply(r,i)}function v(e){var n=e-h;return h===t||n>=i||n<0||d&&e-u>=a}function w(){var t=Ao();if(v(t))return m(t);l=zs(w,function(t){var e=i-(t-h);return d?vn(e,a-(t-u)):e}(t))}function m(e){return l=t,p&&s?g(e):(s=o=t,c)}function y(){var e=Ao(),n=v(e);if(s=arguments,o=this,h=e,n){if(l===t)return function(t){return u=t,l=zs(w,i),f?g(t):c}(h);if(d)return mr(l),l=zs(w,i),g(h)}return l===t&&(l=zs(w,i)),c}return i=fa(i)||0,Qo(r)&&(f=!!r.leading,a=(d="maxWait"in r)?gn(fa(r.maxWait)||0,i):a,p="trailing"in r?!!r.trailing:p),y.cancel=function(){l!==t&&mr(l),u=0,s=h=o=l=t},y.flush=function(){return l===t?c:m(Ao())},y}var Co=Gi((function(t,e){return ai(t,1,e)})),To=Gi((function(t,e,n){return ai(t,fa(e)||0,n)}));function Io(t,n){if("function"!=typeof t||null!=n&&"function"!=typeof n)throw new $t(e);var i=function(){var e=arguments,r=n?n.apply(this,e):e[0],s=i.cache;if(s.has(r))return s.get(r);var o=t.apply(this,e);return i.cache=s.set(r,o)||s,o};return i.cache=new(Io.Cache||Vn),i}function jo(t){if("function"!=typeof t)throw new $t(e);return function(){var e=arguments;switch(e.length){case 0:return!t.call(this);case 1:return!t.call(this,e[0]);case 2:return!t.call(this,e[0],e[1]);case 3:return!t.call(this,e[0],e[1],e[2])}return!t.apply(this,e)}}Io.Cache=Vn;var Eo=vr((function(t,e){var n=(e=1==e.length&&Wo(e[0])?Ie(e[0],Xe(rs())):Ie(pi(e,1),Xe(rs()))).length;return Gi((function(i){for(var r=-1,s=vn(i.length,n);++r<s;)i[r]=e[r].call(this,i[r]);return Ae(t,this,i)}))})),_o=Gi((function(e,n){var i=on(n,is(_o));return Hr(e,r,t,n,i)})),Lo=Gi((function(e,n){var i=on(n,is(Lo));return Hr(e,64,t,n,i)})),Oo=qr((function(e,n){return Hr(e,256,t,t,t,n)}));function Po(t,e){return t===e||t!=t&&e!=e}var Bo=Fr(xi),Do=Fr((function(t,e){return t>=e})),Ro=Ci(function(){return arguments}())?Ci:function(t){return Zo(t)&&Et.call(t,"callee")&&!Nt.call(t,"callee")},Wo=yt.isArray,Uo=ve?Xe(ve):function(t){return Zo(t)&&Ai(t)==$};function Fo(t){return null!=t&&Yo(t.length)&&!Ho(t)}function Ko(t){return Zo(t)&&Fo(t)}var Vo=ge||fc,No=we?Xe(we):function(t){return Zo(t)&&Ai(t)==p};function Go(t){if(!Zo(t))return!1;var e=Ai(t);return e==g||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!ta(t)}function Ho(t){if(!Qo(t))return!1;var e=Ai(t);return e==v||e==w||"[object AsyncFunction]"==e||"[object Proxy]"==e}function Xo(t){return"number"==typeof t&&t==ha(t)}function Yo(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=a}function Qo(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function Zo(t){return null!=t&&"object"==typeof t}var qo=me?Xe(me):function(t){return Zo(t)&&hs(t)==m};function Jo(t){return"number"==typeof t||Zo(t)&&Ai(t)==y}function ta(t){if(!Zo(t)||Ai(t)!=b)return!1;var e=Kt(t);if(null===e)return!0;var n=Et.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&jt.call(n)==Pt}var ea=ye?Xe(ye):function(t){return Zo(t)&&Ai(t)==A},na=be?Xe(be):function(t){return Zo(t)&&hs(t)==x};function ia(t){return"string"==typeof t||!Wo(t)&&Zo(t)&&Ai(t)==S}function ra(t){return"symbol"==typeof t||Zo(t)&&Ai(t)==M}var sa=ke?Xe(ke):function(t){return Zo(t)&&Yo(t.length)&&!!ie[Ai(t)]},oa=Fr(Li),aa=Fr((function(t,e){return t<=e}));function ca(t){if(!t)return[];if(Fo(t))return ia(t)?hn(t):Mr(t);if(Zt&&t[Zt])return function(t){for(var e,n=[];!(e=t.next()).done;)n.push(e.value);return n}(t[Zt]());var e=hs(t);return(e==m?rn:e==x?an:Pa)(t)}function la(t){return t?(t=fa(t))===o||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function ha(t){var e=la(t),n=e%1;return e==e?n?e-n:e:0}function ua(t){return t?ri(ha(t),0,l):0}function fa(t){if("number"==typeof t)return t;if(ra(t))return c;if(Qo(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Qo(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=He(t);var n=ut.test(t);return n||dt.test(t)?ae(t.slice(2),n?2:8):ht.test(t)?c:+t}function da(t){return zr(t,Ca(t))}function pa(t){return null==t?"":sr(t)}var ga=Cr((function(t,e){if(ys(e)||Fo(e))zr(e,$a(e),t);else for(var n in e)Et.call(e,n)&&qn(t,n,e[n])})),va=Cr((function(t,e){zr(e,Ca(e),t)})),wa=Cr((function(t,e,n,i){zr(e,Ca(e),t,i)})),ma=Cr((function(t,e,n,i){zr(e,$a(e),t,i)})),ya=qr(ii),ba=Gi((function(e,n){e=St(e);var i=-1,r=n.length,s=r>2?n[2]:t;for(s&&gs(n[0],n[1],s)&&(r=1);++i<r;)for(var o=n[i],a=Ca(o),c=-1,l=a.length;++c<l;){var h=a[c],u=e[h];(u===t||Po(u,Tt[h])&&!Et.call(e,h))&&(e[h]=o[h])}return e})),ka=Gi((function(e){return e.push(t,Yr),Ae(Ia,t,e)}));function Aa(e,n,i){var r=null==e?t:bi(e,n);return r===t?i:r}function xa(t,e){return null!=t&&us(t,e,Mi)}var Sa=Br((function(t,e,n){null!=e&&"function"!=typeof e.toString&&(e=Ot.call(e)),t[e]=n}),Qa(Ja)),Ma=Br((function(t,e,n){null!=e&&"function"!=typeof e.toString&&(e=Ot.call(e)),Et.call(t,e)?t[e].push(n):t[e]=[n]}),rs),za=Gi($i);function $a(t){return Fo(t)?Hn(t):_i(t)}function Ca(t){return Fo(t)?Hn(t,!0):function(t){if(!Qo(t))return function(t){var e=[];if(null!=t)for(var n in St(t))e.push(n);return e}(t);var e=ys(t),n=[];for(var i in t)("constructor"!=i||!e&&Et.call(t,i))&&n.push(i);return n}(t)}var Ta=Cr((function(t,e,n){Di(t,e,n)})),Ia=Cr((function(t,e,n,i){Di(t,e,n,i)})),ja=qr((function(t,e){var n={};if(null==t)return n;var i=!1;e=Ie(e,(function(e){return e=gr(e,t),i||(i=e.length>1),e})),zr(t,ts(t),n),i&&(n=si(n,7,Qr));for(var r=e.length;r--;)ar(n,e[r]);return n})),Ea=qr((function(t,e){return null==t?{}:function(t,e){return Ui(t,e,(function(e,n){return xa(t,n)}))}(t,e)}));function _a(t,e){if(null==t)return{};var n=Ie(ts(t),(function(t){return[t]}));return e=rs(e),Ui(t,n,(function(t,n){return e(t,n[0])}))}var La=Gr($a),Oa=Gr(Ca);function Pa(t){return null==t?[]:Ye(t,$a(t))}var Ba=Er((function(t,e,n){return e=e.toLowerCase(),t+(n?Da(e):e)}));function Da(t){return Ga(pa(t).toLowerCase())}function Ra(t){return(t=pa(t))&&t.replace(gt,Je).replace(Xt,"")}var Wa=Er((function(t,e,n){return t+(n?"-":"")+e.toLowerCase()})),Ua=Er((function(t,e,n){return t+(n?" ":"")+e.toLowerCase()})),Fa=jr("toLowerCase"),Ka=Er((function(t,e,n){return t+(n?"_":"")+e.toLowerCase()})),Va=Er((function(t,e,n){return t+(n?" ":"")+Ga(e)})),Na=Er((function(t,e,n){return t+(n?" ":"")+e.toUpperCase()})),Ga=jr("toUpperCase");function Ha(e,n,i){return e=pa(e),(n=i?t:n)===t?function(t){return te.test(t)}(e)?function(t){return t.match(Qt)||[]}(e):function(t){return t.match(st)||[]}(e):e.match(n)||[]}var Xa=Gi((function(e,n){try{return Ae(e,t,n)}catch(t){return Go(t)?t:new kt(t)}})),Ya=qr((function(t,e){return Se(e,(function(e){e=Es(e),ni(t,e,Mo(t[e],t))})),t}));function Qa(t){return function(){return t}}var Za=Or(),qa=Or(!0);function Ja(t){return t}function tc(t){return Ei("function"==typeof t?t:si(t,1))}var ec=Gi((function(t,e){return function(n){return $i(n,t,e)}})),nc=Gi((function(t,e){return function(n){return $i(t,n,e)}}));function ic(t,e,n){var i=$a(e),r=yi(e,i);null!=n||Qo(e)&&(r.length||!i.length)||(n=e,e=t,t=this,r=yi(e,$a(e)));var s=!(Qo(n)&&"chain"in n&&!n.chain),o=Ho(t);return Se(r,(function(n){var i=e[n];t[n]=i,o&&(t.prototype[n]=function(){var e=this.__chain__;if(s||e){var n=t(this.__wrapped__);return(n.__actions__=Mr(this.__actions__)).push({func:i,args:arguments,thisArg:t}),n.__chain__=e,n}return i.apply(t,je([this.value()],arguments))})})),t}function rc(){}var sc=Rr(Ie),oc=Rr(ze),ac=Rr(Le);function cc(t){return vs(t)?Fe(Es(t)):function(t){return function(e){return bi(e,t)}}(t)}var lc=Ur(),hc=Ur(!0);function uc(){return[]}function fc(){return!1}var dc,pc=Dr((function(t,e){return t+e}),0),gc=Vr("ceil"),vc=Dr((function(t,e){return t/e}),1),wc=Vr("floor"),mc=Dr((function(t,e){return t*e}),1),yc=Vr("round"),bc=Dr((function(t,e){return t-e}),0);return Bn.after=function(t,n){if("function"!=typeof n)throw new $t(e);return t=ha(t),function(){if(--t<1)return n.apply(this,arguments)}},Bn.ary=xo,Bn.assign=ga,Bn.assignIn=va,Bn.assignInWith=wa,Bn.assignWith=ma,Bn.at=ya,Bn.before=So,Bn.bind=Mo,Bn.bindAll=Ya,Bn.bindKey=zo,Bn.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Wo(t)?t:[t]},Bn.chain=ao,Bn.chunk=function(e,n,i){n=(i?gs(e,n,i):n===t)?1:gn(ha(n),0);var r=null==e?0:e.length;if(!r||n<1)return[];for(var s=0,o=0,a=yt(ue(r/n));s<r;)a[o++]=Ji(e,s,s+=n);return a},Bn.compact=function(t){for(var e=-1,n=null==t?0:t.length,i=0,r=[];++e<n;){var s=t[e];s&&(r[i++]=s)}return r},Bn.concat=function(){var t=arguments.length;if(!t)return[];for(var e=yt(t-1),n=arguments[0],i=t;i--;)e[i-1]=arguments[i];return je(Wo(n)?Mr(n):[n],pi(e,1))},Bn.cond=function(t){var n=null==t?0:t.length,i=rs();return t=n?Ie(t,(function(t){if("function"!=typeof t[1])throw new $t(e);return[i(t[0]),t[1]]})):[],Gi((function(e){for(var i=-1;++i<n;){var r=t[i];if(Ae(r[0],this,e))return Ae(r[1],this,e)}}))},Bn.conforms=function(t){return function(t){var e=$a(t);return function(n){return oi(n,t,e)}}(si(t,1))},Bn.constant=Qa,Bn.countBy=ho,Bn.create=function(t,e){var n=Dn(t);return null==e?n:ei(n,e)},Bn.curry=function e(n,i,r){var s=Hr(n,8,t,t,t,t,t,i=r?t:i);return s.placeholder=e.placeholder,s},Bn.curryRight=function e(n,i,r){var s=Hr(n,16,t,t,t,t,t,i=r?t:i);return s.placeholder=e.placeholder,s},Bn.debounce=$o,Bn.defaults=ba,Bn.defaultsDeep=ka,Bn.defer=Co,Bn.delay=To,Bn.difference=Os,Bn.differenceBy=Ps,Bn.differenceWith=Bs,Bn.drop=function(e,n,i){var r=null==e?0:e.length;return r?Ji(e,(n=i||n===t?1:ha(n))<0?0:n,r):[]},Bn.dropRight=function(e,n,i){var r=null==e?0:e.length;return r?Ji(e,0,(n=r-(n=i||n===t?1:ha(n)))<0?0:n):[]},Bn.dropRightWhile=function(t,e){return t&&t.length?lr(t,rs(e,3),!0,!0):[]},Bn.dropWhile=function(t,e){return t&&t.length?lr(t,rs(e,3),!0):[]},Bn.fill=function(e,n,i,r){var s=null==e?0:e.length;return s?(i&&"number"!=typeof i&&gs(e,n,i)&&(i=0,r=s),function(e,n,i,r){var s=e.length;for((i=ha(i))<0&&(i=-i>s?0:s+i),(r=r===t||r>s?s:ha(r))<0&&(r+=s),r=i>r?0:ua(r);i<r;)e[i++]=n;return e}(e,n,i,r)):[]},Bn.filter=function(t,e){return(Wo(t)?$e:di)(t,rs(e,3))},Bn.flatMap=function(t,e){return pi(yo(t,e),1)},Bn.flatMapDeep=function(t,e){return pi(yo(t,e),o)},Bn.flatMapDepth=function(e,n,i){return i=i===t?1:ha(i),pi(yo(e,n),i)},Bn.flatten=Ws,Bn.flattenDeep=function(t){return null!=t&&t.length?pi(t,o):[]},Bn.flattenDepth=function(e,n){return null!=e&&e.length?pi(e,n=n===t?1:ha(n)):[]},Bn.flip=function(t){return Hr(t,512)},Bn.flow=Za,Bn.flowRight=qa,Bn.fromPairs=function(t){for(var e=-1,n=null==t?0:t.length,i={};++e<n;){var r=t[e];ni(i,r[0],r[1])}return i},Bn.functions=function(t){return null==t?[]:yi(t,$a(t))},Bn.functionsIn=function(t){return null==t?[]:yi(t,Ca(t))},Bn.groupBy=vo,Bn.initial=function(t){return null!=t&&t.length?Ji(t,0,-1):[]},Bn.intersection=Fs,Bn.intersectionBy=Ks,Bn.intersectionWith=Vs,Bn.invert=Sa,Bn.invertBy=Ma,Bn.invokeMap=wo,Bn.iteratee=tc,Bn.keyBy=mo,Bn.keys=$a,Bn.keysIn=Ca,Bn.map=yo,Bn.mapKeys=function(t,e){var n={};return e=rs(e,3),wi(t,(function(t,i,r){ni(n,e(t,i,r),t)})),n},Bn.mapValues=function(t,e){var n={};return e=rs(e,3),wi(t,(function(t,i,r){ni(n,i,e(t,i,r))})),n},Bn.matches=function(t){return Pi(si(t,1))},Bn.matchesProperty=function(t,e){return Bi(t,si(e,1))},Bn.memoize=Io,Bn.merge=Ta,Bn.mergeWith=Ia,Bn.method=ec,Bn.methodOf=nc,Bn.mixin=ic,Bn.negate=jo,Bn.nthArg=function(t){return t=ha(t),Gi((function(e){return Ri(e,t)}))},Bn.omit=ja,Bn.omitBy=function(t,e){return _a(t,jo(rs(e)))},Bn.once=function(t){return So(2,t)},Bn.orderBy=function(e,n,i,r){return null==e?[]:(Wo(n)||(n=null==n?[]:[n]),Wo(i=r?t:i)||(i=null==i?[]:[i]),Wi(e,n,i))},Bn.over=sc,Bn.overArgs=Eo,Bn.overEvery=oc,Bn.overSome=ac,Bn.partial=_o,Bn.partialRight=Lo,Bn.partition=bo,Bn.pick=Ea,Bn.pickBy=_a,Bn.property=cc,Bn.propertyOf=function(e){return function(n){return null==e?t:bi(e,n)}},Bn.pull=Gs,Bn.pullAll=Hs,Bn.pullAllBy=function(t,e,n){return t&&t.length&&e&&e.length?Fi(t,e,rs(n,2)):t},Bn.pullAllWith=function(e,n,i){return e&&e.length&&n&&n.length?Fi(e,n,t,i):e},Bn.pullAt=Xs,Bn.range=lc,Bn.rangeRight=hc,Bn.rearg=Oo,Bn.reject=function(t,e){return(Wo(t)?$e:di)(t,jo(rs(e,3)))},Bn.remove=function(t,e){var n=[];if(!t||!t.length)return n;var i=-1,r=[],s=t.length;for(e=rs(e,3);++i<s;){var o=t[i];e(o,i,t)&&(n.push(o),r.push(i))}return Ki(t,r),n},Bn.rest=function(n,i){if("function"!=typeof n)throw new $t(e);return Gi(n,i=i===t?i:ha(i))},Bn.reverse=Ys,Bn.sampleSize=function(e,n,i){return n=(i?gs(e,n,i):n===t)?1:ha(n),(Wo(e)?Yn:Xi)(e,n)},Bn.set=function(t,e,n){return null==t?t:Yi(t,e,n)},Bn.setWith=function(e,n,i,r){return r="function"==typeof r?r:t,null==e?e:Yi(e,n,i,r)},Bn.shuffle=function(t){return(Wo(t)?Qn:qi)(t)},Bn.slice=function(e,n,i){var r=null==e?0:e.length;return r?(i&&"number"!=typeof i&&gs(e,n,i)?(n=0,i=r):(n=null==n?0:ha(n),i=i===t?r:ha(i)),Ji(e,n,i)):[]},Bn.sortBy=ko,Bn.sortedUniq=function(t){return t&&t.length?ir(t):[]},Bn.sortedUniqBy=function(t,e){return t&&t.length?ir(t,rs(e,2)):[]},Bn.split=function(e,n,i){return i&&"number"!=typeof i&&gs(e,n,i)&&(n=i=t),(i=i===t?l:i>>>0)?(e=pa(e))&&("string"==typeof n||null!=n&&!ea(n))&&!(n=sr(n))&&nn(e)?wr(hn(e),0,i):e.split(n,i):[]},Bn.spread=function(t,n){if("function"!=typeof t)throw new $t(e);return n=null==n?0:gn(ha(n),0),Gi((function(e){var i=e[n],r=wr(e,0,n);return i&&je(r,i),Ae(t,this,r)}))},Bn.tail=function(t){var e=null==t?0:t.length;return e?Ji(t,1,e):[]},Bn.take=function(e,n,i){return e&&e.length?Ji(e,0,(n=i||n===t?1:ha(n))<0?0:n):[]},Bn.takeRight=function(e,n,i){var r=null==e?0:e.length;return r?Ji(e,(n=r-(n=i||n===t?1:ha(n)))<0?0:n,r):[]},Bn.takeRightWhile=function(t,e){return t&&t.length?lr(t,rs(e,3),!1,!0):[]},Bn.takeWhile=function(t,e){return t&&t.length?lr(t,rs(e,3)):[]},Bn.tap=function(t,e){return e(t),t},Bn.throttle=function(t,n,i){var r=!0,s=!0;if("function"!=typeof t)throw new $t(e);return Qo(i)&&(r="leading"in i?!!i.leading:r,s="trailing"in i?!!i.trailing:s),$o(t,n,{leading:r,maxWait:n,trailing:s})},Bn.thru=co,Bn.toArray=ca,Bn.toPairs=La,Bn.toPairsIn=Oa,Bn.toPath=function(t){return Wo(t)?Ie(t,Es):ra(t)?[t]:Mr(js(pa(t)))},Bn.toPlainObject=da,Bn.transform=function(t,e,n){var i=Wo(t),r=i||Vo(t)||sa(t);if(e=rs(e,4),null==n){var s=t&&t.constructor;n=r?i?new s:[]:Qo(t)&&Ho(s)?Dn(Kt(t)):{}}return(r?Se:wi)(t,(function(t,i,r){return e(n,t,i,r)})),n},Bn.unary=function(t){return xo(t,1)},Bn.union=Qs,Bn.unionBy=Zs,Bn.unionWith=qs,Bn.uniq=function(t){return t&&t.length?or(t):[]},Bn.uniqBy=function(t,e){return t&&t.length?or(t,rs(e,2)):[]},Bn.uniqWith=function(e,n){return n="function"==typeof n?n:t,e&&e.length?or(e,t,n):[]},Bn.unset=function(t,e){return null==t||ar(t,e)},Bn.unzip=Js,Bn.unzipWith=to,Bn.update=function(t,e,n){return null==t?t:cr(t,e,pr(n))},Bn.updateWith=function(e,n,i,r){return r="function"==typeof r?r:t,null==e?e:cr(e,n,pr(i),r)},Bn.values=Pa,Bn.valuesIn=function(t){return null==t?[]:Ye(t,Ca(t))},Bn.without=eo,Bn.words=Ha,Bn.wrap=function(t,e){return _o(pr(e),t)},Bn.xor=no,Bn.xorBy=io,Bn.xorWith=ro,Bn.zip=so,Bn.zipObject=function(t,e){return fr(t||[],e||[],qn)},Bn.zipObjectDeep=function(t,e){return fr(t||[],e||[],Yi)},Bn.zipWith=oo,Bn.entries=La,Bn.entriesIn=Oa,Bn.extend=va,Bn.extendWith=wa,ic(Bn,Bn),Bn.add=pc,Bn.attempt=Xa,Bn.camelCase=Ba,Bn.capitalize=Da,Bn.ceil=gc,Bn.clamp=function(e,n,i){return i===t&&(i=n,n=t),i!==t&&(i=(i=fa(i))==i?i:0),n!==t&&(n=(n=fa(n))==n?n:0),ri(fa(e),n,i)},Bn.clone=function(t){return si(t,4)},Bn.cloneDeep=function(t){return si(t,5)},Bn.cloneDeepWith=function(e,n){return si(e,5,n="function"==typeof n?n:t)},Bn.cloneWith=function(e,n){return si(e,4,n="function"==typeof n?n:t)},Bn.conformsTo=function(t,e){return null==e||oi(t,e,$a(e))},Bn.deburr=Ra,Bn.defaultTo=function(t,e){return null==t||t!=t?e:t},Bn.divide=vc,Bn.endsWith=function(e,n,i){e=pa(e),n=sr(n);var r=e.length,s=i=i===t?r:ri(ha(i),0,r);return(i-=n.length)>=0&&e.slice(i,s)==n},Bn.eq=Po,Bn.escape=function(t){return(t=pa(t))&&V.test(t)?t.replace(F,tn):t},Bn.escapeRegExp=function(t){return(t=pa(t))&&J.test(t)?t.replace(q,"\\$&"):t},Bn.every=function(e,n,i){var r=Wo(e)?ze:ui;return i&&gs(e,n,i)&&(n=t),r(e,rs(n,3))},Bn.find=uo,Bn.findIndex=Ds,Bn.findKey=function(t,e){return Pe(t,rs(e,3),wi)},Bn.findLast=fo,Bn.findLastIndex=Rs,Bn.findLastKey=function(t,e){return Pe(t,rs(e,3),mi)},Bn.floor=wc,Bn.forEach=po,Bn.forEachRight=go,Bn.forIn=function(t,e){return null==t?t:gi(t,rs(e,3),Ca)},Bn.forInRight=function(t,e){return null==t?t:vi(t,rs(e,3),Ca)},Bn.forOwn=function(t,e){return t&&wi(t,rs(e,3))},Bn.forOwnRight=function(t,e){return t&&mi(t,rs(e,3))},Bn.get=Aa,Bn.gt=Bo,Bn.gte=Do,Bn.has=function(t,e){return null!=t&&us(t,e,Si)},Bn.hasIn=xa,Bn.head=Us,Bn.identity=Ja,Bn.includes=function(t,e,n,i){t=Fo(t)?t:Pa(t),n=n&&!i?ha(n):0;var r=t.length;return n<0&&(n=gn(r+n,0)),ia(t)?n<=r&&t.indexOf(e,n)>-1:!!r&&De(t,e,n)>-1},Bn.indexOf=function(t,e,n){var i=null==t?0:t.length;if(!i)return-1;var r=null==n?0:ha(n);return r<0&&(r=gn(i+r,0)),De(t,e,r)},Bn.inRange=function(e,n,i){return n=la(n),i===t?(i=n,n=0):i=la(i),function(t,e,n){return t>=vn(e,n)&&t<gn(e,n)}(e=fa(e),n,i)},Bn.invoke=za,Bn.isArguments=Ro,Bn.isArray=Wo,Bn.isArrayBuffer=Uo,Bn.isArrayLike=Fo,Bn.isArrayLikeObject=Ko,Bn.isBoolean=function(t){return!0===t||!1===t||Zo(t)&&Ai(t)==d},Bn.isBuffer=Vo,Bn.isDate=No,Bn.isElement=function(t){return Zo(t)&&1===t.nodeType&&!ta(t)},Bn.isEmpty=function(t){if(null==t)return!0;if(Fo(t)&&(Wo(t)||"string"==typeof t||"function"==typeof t.splice||Vo(t)||sa(t)||Ro(t)))return!t.length;var e=hs(t);if(e==m||e==x)return!t.size;if(ys(t))return!_i(t).length;for(var n in t)if(Et.call(t,n))return!1;return!0},Bn.isEqual=function(t,e){return Ti(t,e)},Bn.isEqualWith=function(e,n,i){var r=(i="function"==typeof i?i:t)?i(e,n):t;return r===t?Ti(e,n,t,i):!!r},Bn.isError=Go,Bn.isFinite=function(t){return"number"==typeof t&&Oe(t)},Bn.isFunction=Ho,Bn.isInteger=Xo,Bn.isLength=Yo,Bn.isMap=qo,Bn.isMatch=function(t,e){return t===e||Ii(t,e,os(e))},Bn.isMatchWith=function(e,n,i){return i="function"==typeof i?i:t,Ii(e,n,os(n),i)},Bn.isNaN=function(t){return Jo(t)&&t!=+t},Bn.isNative=function(t){if(ms(t))throw new kt("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return ji(t)},Bn.isNil=function(t){return null==t},Bn.isNull=function(t){return null===t},Bn.isNumber=Jo,Bn.isObject=Qo,Bn.isObjectLike=Zo,Bn.isPlainObject=ta,Bn.isRegExp=ea,Bn.isSafeInteger=function(t){return Xo(t)&&t>=-9007199254740991&&t<=a},Bn.isSet=na,Bn.isString=ia,Bn.isSymbol=ra,Bn.isTypedArray=sa,Bn.isUndefined=function(e){return e===t},Bn.isWeakMap=function(t){return Zo(t)&&hs(t)==z},Bn.isWeakSet=function(t){return Zo(t)&&"[object WeakSet]"==Ai(t)},Bn.join=function(t,e){return null==t?"":Ke.call(t,e)},Bn.kebabCase=Wa,Bn.last=Ns,Bn.lastIndexOf=function(e,n,i){var r=null==e?0:e.length;if(!r)return-1;var s=r;return i!==t&&(s=(s=ha(i))<0?gn(r+s,0):vn(s,r-1)),n==n?function(t,e,n){for(var i=n+1;i--;)if(t[i]===e)return i;return i}(e,n,s):Be(e,We,s,!0)},Bn.lowerCase=Ua,Bn.lowerFirst=Fa,Bn.lt=oa,Bn.lte=aa,Bn.max=function(e){return e&&e.length?fi(e,Ja,xi):t},Bn.maxBy=function(e,n){return e&&e.length?fi(e,rs(n,2),xi):t},Bn.mean=function(t){return Ue(t,Ja)},Bn.meanBy=function(t,e){return Ue(t,rs(e,2))},Bn.min=function(e){return e&&e.length?fi(e,Ja,Li):t},Bn.minBy=function(e,n){return e&&e.length?fi(e,rs(n,2),Li):t},Bn.stubArray=uc,Bn.stubFalse=fc,Bn.stubObject=function(){return{}},Bn.stubString=function(){return""},Bn.stubTrue=function(){return!0},Bn.multiply=mc,Bn.nth=function(e,n){return e&&e.length?Ri(e,ha(n)):t},Bn.noConflict=function(){return he._===this&&(he._=Bt),this},Bn.noop=rc,Bn.now=Ao,Bn.pad=function(t,e,n){t=pa(t);var i=(e=ha(e))?ln(t):0;if(!e||i>=e)return t;var r=(e-i)/2;return Wr(fe(r),n)+t+Wr(ue(r),n)},Bn.padEnd=function(t,e,n){t=pa(t);var i=(e=ha(e))?ln(t):0;return e&&i<e?t+Wr(e-i,n):t},Bn.padStart=function(t,e,n){t=pa(t);var i=(e=ha(e))?ln(t):0;return e&&i<e?Wr(e-i,n)+t:t},Bn.parseInt=function(t,e,n){return n||null==e?e=0:e&&(e=+e),mn(pa(t).replace(tt,""),e||0)},Bn.random=function(e,n,i){if(i&&"boolean"!=typeof i&&gs(e,n,i)&&(n=i=t),i===t&&("boolean"==typeof n?(i=n,n=t):"boolean"==typeof e&&(i=e,e=t)),e===t&&n===t?(e=0,n=1):(e=la(e),n===t?(n=e,e=0):n=la(n)),e>n){var r=e;e=n,n=r}if(i||e%1||n%1){var s=yn();return vn(e+s*(n-e+oe("1e-"+((s+"").length-1))),n)}return Vi(e,n)},Bn.reduce=function(t,e,n){var i=Wo(t)?Ee:Ve,r=arguments.length<3;return i(t,rs(e,4),n,r,li)},Bn.reduceRight=function(t,e,n){var i=Wo(t)?_e:Ve,r=arguments.length<3;return i(t,rs(e,4),n,r,hi)},Bn.repeat=function(e,n,i){return n=(i?gs(e,n,i):n===t)?1:ha(n),Ni(pa(e),n)},Bn.replace=function(){var t=arguments,e=pa(t[0]);return t.length<3?e:e.replace(t[1],t[2])},Bn.result=function(e,n,i){var r=-1,s=(n=gr(n,e)).length;for(s||(s=1,e=t);++r<s;){var o=null==e?t:e[Es(n[r])];o===t&&(r=s,o=i),e=Ho(o)?o.call(e):o}return e},Bn.round=yc,Bn.runInContext=X,Bn.sample=function(t){return(Wo(t)?Xn:Hi)(t)},Bn.size=function(t){if(null==t)return 0;if(Fo(t))return ia(t)?ln(t):t.length;var e=hs(t);return e==m||e==x?t.size:_i(t).length},Bn.snakeCase=Ka,Bn.some=function(e,n,i){var r=Wo(e)?Le:tr;return i&&gs(e,n,i)&&(n=t),r(e,rs(n,3))},Bn.sortedIndex=function(t,e){return er(t,e)},Bn.sortedIndexBy=function(t,e,n){return nr(t,e,rs(n,2))},Bn.sortedIndexOf=function(t,e){var n=null==t?0:t.length;if(n){var i=er(t,e);if(i<n&&Po(t[i],e))return i}return-1},Bn.sortedLastIndex=function(t,e){return er(t,e,!0)},Bn.sortedLastIndexBy=function(t,e,n){return nr(t,e,rs(n,2),!0)},Bn.sortedLastIndexOf=function(t,e){if(null!=t&&t.length){var n=er(t,e,!0)-1;if(Po(t[n],e))return n}return-1},Bn.startCase=Va,Bn.startsWith=function(t,e,n){return t=pa(t),n=null==n?0:ri(ha(n),0,t.length),e=sr(e),t.slice(n,n+e.length)==e},Bn.subtract=bc,Bn.sum=function(t){return t&&t.length?Ne(t,Ja):0},Bn.sumBy=function(t,e){return t&&t.length?Ne(t,rs(e,2)):0},Bn.template=function(e,n,i){var r=Bn.templateSettings;i&&gs(e,n,i)&&(n=t),e=pa(e),n=ma({},n,r,Xr);var s=ma({},n.imports,r.imports,Xr),o=$a(s),a=Ye(s,o);Se(o,(function(t){if(ot.test(t))throw new kt("Invalid `imports` option passed into `_.template`")}));var c,l,h=0,u=n.interpolate||vt,f="__p += '",d=Mt((n.escape||vt).source+"|"+u.source+"|"+(u===H?ct:vt).source+"|"+(n.evaluate||vt).source+"|$","g"),p="//# sourceURL="+(Et.call(n,"sourceURL")?(n.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++ne+"]")+"\n";e.replace(d,(function(t,n,i,r,s,o){return i||(i=r),f+=e.slice(h,o).replace(wt,en),n&&(c=!0,f+="' +\n__e("+n+") +\n'"),s&&(l=!0,f+="';\n"+s+";\n__p += '"),i&&(f+="' +\n((__t = ("+i+")) == null ? '' : __t) +\n'"),h=o+t.length,t})),f+="';\n";var g=Et.call(n,"variable")&&n.variable;if(g){if(ot.test(g))throw new kt("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(l?f.replace(D,""):f).replace(R,"$1").replace(W,"$1;"),f="function("+(g||"obj")+") {\n"+(g?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(c?", __e = _.escape":"")+(l?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var v=Xa((function(){return At(o,p+"return "+f).apply(t,a)}));if(v.source=f,Go(v))throw v;return v},Bn.times=function(t,e){if((t=ha(t))<1||t>a)return[];var n=l,i=vn(t,l);e=rs(e),t-=l;for(var r=Ge(i,e);++n<t;)e(n);return r},Bn.toFinite=la,Bn.toInteger=ha,Bn.toLength=ua,Bn.toLower=function(t){return pa(t).toLowerCase()},Bn.toNumber=fa,Bn.toSafeInteger=function(t){return t?ri(ha(t),-9007199254740991,a):0===t?t:0},Bn.toString=pa,Bn.toUpper=function(t){return pa(t).toUpperCase()},Bn.trim=function(e,n,i){if((e=pa(e))&&(i||n===t))return He(e);if(!e||!(n=sr(n)))return e;var r=hn(e),s=hn(n);return wr(r,Ze(r,s),qe(r,s)+1).join("")},Bn.trimEnd=function(e,n,i){if((e=pa(e))&&(i||n===t))return e.slice(0,un(e)+1);if(!e||!(n=sr(n)))return e;var r=hn(e);return wr(r,0,qe(r,hn(n))+1).join("")},Bn.trimStart=function(e,n,i){if((e=pa(e))&&(i||n===t))return e.replace(tt,"");if(!e||!(n=sr(n)))return e;var r=hn(e);return wr(r,Ze(r,hn(n))).join("")},Bn.truncate=function(e,n){var i=30,r="...";if(Qo(n)){var s="separator"in n?n.separator:s;i="length"in n?ha(n.length):i,r="omission"in n?sr(n.omission):r}var o=(e=pa(e)).length;if(nn(e)){var a=hn(e);o=a.length}if(i>=o)return e;var c=i-ln(r);if(c<1)return r;var l=a?wr(a,0,c).join(""):e.slice(0,c);if(s===t)return l+r;if(a&&(c+=l.length-c),ea(s)){if(e.slice(c).search(s)){var h,u=l;for(s.global||(s=Mt(s.source,pa(lt.exec(s))+"g")),s.lastIndex=0;h=s.exec(u);)var f=h.index;l=l.slice(0,f===t?c:f)}}else if(e.indexOf(sr(s),c)!=c){var d=l.lastIndexOf(s);d>-1&&(l=l.slice(0,d))}return l+r},Bn.unescape=function(t){return(t=pa(t))&&K.test(t)?t.replace(U,fn):t},Bn.uniqueId=function(t){var e=++_t;return pa(t)+e},Bn.upperCase=Na,Bn.upperFirst=Ga,Bn.each=po,Bn.eachRight=go,Bn.first=Us,ic(Bn,(dc={},wi(Bn,(function(t,e){Et.call(Bn.prototype,e)||(dc[e]=t)})),dc),{chain:!1}),Bn.VERSION="4.18.1",Se(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Bn[t].placeholder=Bn})),Se(["drop","take"],(function(e,n){Un.prototype[e]=function(i){i=i===t?1:gn(ha(i),0);var r=this.__filtered__&&!n?new Un(this):this.clone();return r.__filtered__?r.__takeCount__=vn(i,r.__takeCount__):r.__views__.push({size:vn(i,l),type:e+(r.__dir__<0?"Right":"")}),r},Un.prototype[e+"Right"]=function(t){return this.reverse()[e](t).reverse()}})),Se(["filter","map","takeWhile"],(function(t,e){var n=e+1,i=1==n||3==n;Un.prototype[t]=function(t){var e=this.clone();return e.__iteratees__.push({iteratee:rs(t,3),type:n}),e.__filtered__=e.__filtered__||i,e}})),Se(["head","last"],(function(t,e){var n="take"+(e?"Right":"");Un.prototype[t]=function(){return this[n](1).value()[0]}})),Se(["initial","tail"],(function(t,e){var n="drop"+(e?"":"Right");Un.prototype[t]=function(){return this.__filtered__?new Un(this):this[n](1)}})),Un.prototype.compact=function(){return this.filter(Ja)},Un.prototype.find=function(t){return this.filter(t).head()},Un.prototype.findLast=function(t){return this.reverse().find(t)},Un.prototype.invokeMap=Gi((function(t,e){return"function"==typeof t?new Un(this):this.map((function(n){return $i(n,t,e)}))})),Un.prototype.reject=function(t){return this.filter(jo(rs(t)))},Un.prototype.slice=function(e,n){e=ha(e);var i=this;return i.__filtered__&&(e>0||n<0)?new Un(i):(e<0?i=i.takeRight(-e):e&&(i=i.drop(e)),n!==t&&(i=(n=ha(n))<0?i.dropRight(-n):i.take(n-e)),i)},Un.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},Un.prototype.toArray=function(){return this.take(l)},wi(Un.prototype,(function(e,n){var i=/^(?:filter|find|map|reject)|While$/.test(n),r=/^(?:head|last)$/.test(n),s=Bn[r?"take"+("last"==n?"Right":""):n],o=r||/^find/.test(n);s&&(Bn.prototype[n]=function(){var n=this.__wrapped__,a=r?[1]:arguments,c=n instanceof Un,l=a[0],h=c||Wo(n),u=function(t){var e=s.apply(Bn,je([t],a));return r&&f?e[0]:e};h&&i&&"function"==typeof l&&1!=l.length&&(c=h=!1);var f=this.__chain__,d=o&&!f,p=c&&!this.__actions__.length;if(!o&&h){n=p?n:new Un(this);var g=e.apply(n,a);return g.__actions__.push({func:co,args:[u],thisArg:t}),new Wn(g,f)}return d&&p?e.apply(this,a):(g=this.thru(u),d?r?g.value()[0]:g.value():g)})})),Se(["pop","push","shift","sort","splice","unshift"],(function(t){var e=Ct[t],n=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",i=/^(?:pop|shift)$/.test(t);Bn.prototype[t]=function(){var t=arguments;if(i&&!this.__chain__){var r=this.value();return e.apply(Wo(r)?r:[],t)}return this[n]((function(n){return e.apply(Wo(n)?n:[],t)}))}})),wi(Un.prototype,(function(t,e){var n=Bn[e];if(n){var i=n.name+"";Et.call(Cn,i)||(Cn[i]=[]),Cn[i].push({name:e,func:n})}})),Cn[Pr(t,2).name]=[{name:"wrapper",func:t}],Un.prototype.clone=function(){var t=new Un(this.__wrapped__);return t.__actions__=Mr(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Mr(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Mr(this.__views__),t},Un.prototype.reverse=function(){if(this.__filtered__){var t=new Un(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},Un.prototype.value=function(){var t=this.__wrapped__.value(),e=this.__dir__,n=Wo(t),i=e<0,r=n?t.length:0,s=function(t,e,n){for(var i=-1,r=n.length;++i<r;){var s=n[i],o=s.size;switch(s.type){case"drop":t+=o;break;case"dropRight":e-=o;break;case"take":e=vn(e,t+o);break;case"takeRight":t=gn(t,e-o)}}return{start:t,end:e}}(0,r,this.__views__),o=s.start,a=s.end,c=a-o,l=i?a:o-1,h=this.__iteratees__,u=h.length,f=0,d=vn(c,this.__takeCount__);if(!n||!i&&r==c&&d==c)return hr(t,this.__actions__);var p=[];t:for(;c--&&f<d;){for(var g=-1,v=t[l+=e];++g<u;){var w=h[g],m=w.type,y=(0,w.iteratee)(v);if(2==m)v=y;else if(!y){if(1==m)continue t;break t}}p[f++]=v}return p},Bn.prototype.at=lo,Bn.prototype.chain=function(){return ao(this)},Bn.prototype.commit=function(){return new Wn(this.value(),this.__chain__)},Bn.prototype.next=function(){this.__values__===t&&(this.__values__=ca(this.value()));var e=this.__index__>=this.__values__.length;return{done:e,value:e?t:this.__values__[this.__index__++]}},Bn.prototype.plant=function(e){for(var n,i=this;i instanceof Rn;){var r=Ls(i);r.__index__=0,r.__values__=t,n?s.__wrapped__=r:n=r;var s=r;i=i.__wrapped__}return s.__wrapped__=e,n},Bn.prototype.reverse=function(){var e=this.__wrapped__;if(e instanceof Un){var n=e;return this.__actions__.length&&(n=new Un(this)),(n=n.reverse()).__actions__.push({func:co,args:[Ys],thisArg:t}),new Wn(n,this.__chain__)}return this.thru(Ys)},Bn.prototype.toJSON=Bn.prototype.valueOf=Bn.prototype.value=function(){return hr(this.__wrapped__,this.__actions__)},Bn.prototype.first=Bn.prototype.head,Zt&&(Bn.prototype[Zt]=function(){return this}),Bn}();fe?((fe.exports=dn)._=dn,ue._=dn):he._=dn}.call(te.exports)),te.exports);
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Lodash <https://lodash.com/>
|
|
@@ -6,4 +6,4 @@ import{p as t,H as e,c as n,h as i,d as r,t as s}from"./p-B43upypT.js";import{K
|
|
|
6
6
|
* Released under MIT license <https://lodash.com/license>
|
|
7
7
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
8
8
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
9
|
-
*/class ne{_core;_debounceUpdate;_debounceEndScaling;_animationFrameId=null;initialTouchDistance=0;startX=0;startY=0;static TOUCH_CURSOR_BROADCAST_THRESHOLD=5;_touchStartScreenX=0;_touchStartScreenY=0;_touchCursorBroadcastActive=!1;constructor(t,e){this._core=t,this._core.store.state.host=e,this._core.store.state.viewportWidth=e.clientWidth,this._core.store.state.viewportHeight=e.clientHeight,this._core.store.state.startX=0,this._core.store.state.startY=0,this._core.store.state.translateX=0,this._core.store.state.translateY=0,this._debounceUpdate=ee.debounce((()=>{this._core.updateWorkspaceViewport(this._core.store.state.translateX,this._core.store.state.translateY,this._core.store.state.scale)}),300),this._debounceEndScaling=ee.debounce((()=>{this._core.store.state.isScaling=!1,this._core.rerender()}),100)}cancelPendingUpdates(){this._debounceUpdate.cancel()}clampTranslate(t,e){const n=this._core.store.state,{scale:i,viewportWidth:r,viewportHeight:s}=n,{viewportBoundaryLeft:o,viewportBoundaryRight:a,viewportBoundaryTop:c,viewportBoundaryBottom:l}=n,h=-o*i,u=r-a*i,f=-c*i,d=s-l*i;let p=t,g=e;return Number.isFinite(u)&&Number.isFinite(h)?p=Math.max(u,Math.min(h,t)):Number.isFinite(u)?p=Math.max(u,t):Number.isFinite(h)&&(p=Math.min(h,t)),Number.isFinite(d)&&Number.isFinite(f)?g=Math.max(d,Math.min(f,e)):Number.isFinite(d)?g=Math.max(d,e):Number.isFinite(f)&&(g=Math.min(f,e)),{translateX:p,translateY:g}}getEffectiveMinScale(){const t=this._core.store.state,{viewportWidth:e,viewportHeight:n,scaleMin:i}=t,{viewportBoundaryLeft:r,viewportBoundaryRight:s,viewportBoundaryTop:o,viewportBoundaryBottom:a}=t,c=s-r,l=a-o;if(!Number.isFinite(c)||!Number.isFinite(l))return i;const h=Math.max(c>0?e/c:i,l>0?n/l:i);return Math.max(i,h)}handleResize(){this._core.store.state.viewportWidth=this._core.store.host.clientWidth,this._core.store.state.viewportHeight=this._core.store.host.clientHeight,this._core.store.state.hasViewportChanged=!0,this._core.rerender()}handlePointerDown(t){if(this.cancelViewportAnimation(),"mouse"===t.pointerType){const e=t.clientX-this._core.store.offsetX,n=t.clientY-this._core.store.offsetY;t.button===o.Right&&(this._core.store.state.isPanning=!0,this._core.store.state.startX=e,this._core.store.state.startY=n)}if("touch"===t.pointerType||"pen"===t.pointerType){const e=Array.from(this._core.store.state.pointers.values());if(1===e.length&&(this._touchStartScreenX=t.clientX,this._touchStartScreenY=t.clientY,this._touchCursorBroadcastActive=!1),2===e.length){this._core.store.objects?.clearCursorPosition();const t=this._core.store.currentPath;t&&this._core.store.objects.remove((e=>e.id===t.id)),this._core.store.state.isSelecting&&(this._core.store.state.isSelecting=!1,this._core.store.objects.remove((t=>t instanceof g)),this._core.store.setSelectionBox(null),this._core.store.selectedObjects.forEach((t=>{t.isSelected=!1}))),this._core.store.state.isScaling=!0;const n=e[0].clientX-this._core.store.offsetX,i=e[0].clientY-this._core.store.offsetY,r=e[1].clientX-this._core.store.offsetX,s=e[1].clientY-this._core.store.offsetY;this.initialTouchDistance=Math.sqrt(Math.pow(n-r,2)+Math.pow(i-s,2)),this.startX=(n+r)/2,this.startY=(i+s)/2,this._core.rerender()}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.host.getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top;if(this._core.store.state.pointerX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale,this._core.store.objects?.updateCursorPosition(this._core.store.state.pointerX,this._core.store.state.pointerY),this._core.store.state.isPanning){const t=this.clampTranslate(this._core.store.state.translateX+(n-this._core.store.state.startX),this._core.store.state.translateY+(i-this._core.store.state.startY));this._core.store.state.translateX=t.translateX,this._core.store.state.translateY=t.translateY,this._core.store.state.startX=n,this._core.store.state.startY=i,this._core.store.state.hasViewportChanged=!0,this._core.store.state.skipContextMenu=!0,this._core.rerender(),this._debounceUpdate()}}if("touch"===t.pointerType||"pen"===t.pointerType){const e=this._core.store.host.getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top,r=Array.from(this._core.store.state.pointers.values());if(this._core.store.state.isScaling||r.length>1)this._core.store.objects?.clearCursorPosition();else{if(this._core.store.state.pointerX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale,!this._touchCursorBroadcastActive){const e=t.clientX-this._touchStartScreenX,n=t.clientY-this._touchStartScreenY;Math.sqrt(e*e+n*n)>=ne.TOUCH_CURSOR_BROADCAST_THRESHOLD&&(this._touchCursorBroadcastActive=!0)}this._touchCursorBroadcastActive&&this._core.store.objects?.updateCursorPosition(this._core.store.state.pointerX,this._core.store.state.pointerY)}if(2===r.length){const t=r[0].clientX-this._core.store.offsetX,e=r[0].clientY-this._core.store.offsetY,n=r[1].clientX-this._core.store.offsetX,i=r[1].clientY-this._core.store.offsetY,s=Math.sqrt(Math.pow(t-n,2)+Math.pow(e-i,2)),o=(t+n)/2,a=(e+i)/2,c=s/this.initialTouchDistance,l=this._core.store.state.scale*c,h=this.getEffectiveMinScale();if(l>this._core.store.state.scaleMax||l<h){const t=this.clampTranslate(this._core.store.state.translateX+o-this.startX,this._core.store.state.translateY+a-this.startY);this._core.store.state.translateX=t.translateX,this._core.store.state.translateY=t.translateY}else{const t=this._core.store.state.translateX+o-this.startX-(o-this._core.store.state.translateX)*(c-1),e=this._core.store.state.translateY+a-this.startY-(a-this._core.store.state.translateY)*(c-1);this._core.store.state.scale=l;const n=this.clampTranslate(t,e);this._core.store.state.translateX=n.translateX,this._core.store.state.translateY=n.translateY,this.initialTouchDistance=s}this.startX=o,this.startY=a,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isPanning&&(this._core.store.state.isPanning=!1,this._core.rerender()),"touch"!==t.pointerType&&"pen"!==t.pointerType||(this._touchCursorBroadcastActive=!1,0===this._core.store.state.pointers.size&&this._debounceEndScaling())}handleWheel(t){this.cancelViewportAnimation(),t.ctrlKey?this.handleZoom(t):this.handlePan(t)}getViewport(){const t=this._core.store.state;return{translateX:t.translateX,translateY:t.translateY,scale:t.scale,width:t.viewportWidth,height:t.viewportHeight}}screenToWorld(t,e){const n=this._core.store.state;return{x:(t-n.translateX)/n.scale,y:(e-n.translateY)/n.scale}}worldToScreen(t,e){const n=this._core.store.state;return{x:t*n.scale+n.translateX,y:e*n.scale+n.translateY}}setViewport(t,e,n){const i=this._core.store.state,r=Math.min(i.scaleMax,Math.max(this.getEffectiveMinScale(),n));this.animateViewportTo(i.viewportWidth/2-t*r,i.viewportHeight/2-e*r,r)}panTo(t,e){this.setViewport(t,e,this._core.store.state.scale)}zoomTo(t,e,n){const i=this._core.store.state;void 0!==e&&void 0!==n?this.setViewport(e,n,t):this.setViewport((i.viewportWidth/2-i.translateX)/i.scale,(i.viewportHeight/2-i.translateY)/i.scale,t)}zoomIn(t,e){this.animateZoomAroundViewportCenter(t,e)}zoomOut(t,e){this.animateZoomAroundViewportCenter(1/t,e)}animateZoomAroundViewportCenter(t,e){this.cancelViewportAnimation();const n=this._core.store.state,i=n.scale,r=this.getEffectiveMinScale(),s=Math.min(n.scaleMax,Math.max(r,i*t)),o=n.viewportWidth/2,a=n.viewportHeight/2,c=(o-n.translateX)/i,l=(a-n.translateY)/i;if(s===i||e<=0)return this.applyZoomAroundCenter(s,o,a,c,l),n.isScaling=!0,this._core.rerender(),this._debounceUpdate(),void this._debounceEndScaling();const h=performance.now();n.isScaling=!0;const u=t=>{const r=Math.min((t-h)/e,1),f=r<.5?4*r*r*r:1-Math.pow(-2*r+2,3)/2;this.applyZoomAroundCenter(i+(s-i)*f,o,a,c,l),this._core.rerender(),r<1?this._animationFrameId=requestAnimationFrame(u):(this._animationFrameId=null,n.isScaling=!1,this._core.rerender(),this._debounceUpdate())};this._animationFrameId=requestAnimationFrame(u)}applyZoomAroundCenter(t,e,n,i,r){const s=this._core.store.state;s.scale=t;const o=this.clampTranslate(e-i*t,n-r*t);s.translateX=o.translateX,s.translateY=o.translateY,s.hasViewportChanged=!0}centerInViewport(t){const{scale:e,viewportWidth:n,viewportHeight:i}=this._core.store.state,{x:r,y:s,width:o,height:a}=t.rotatedBoundingBox,c=this.clampTranslate(n/2-(r+o/2)*e,i/2-(s+a/2)*e);this._core.store.state.translateX=c.translateX,this._core.store.state.translateY=c.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}centerFitInViewport(t){const e=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),n=Math.max(e,this.getEffectiveMinScale());this._core.store.state.scale=n,this.centerInViewport(t)}centerFitInViewportIfNeeded(t){const e=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),n=Math.max(e,this.getEffectiveMinScale());n<this._core.store.state.scale&&(this._core.store.state.scale=n),this.centerInViewport(t)}fitInViewportIfNeeded(t){const e=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),n=Math.max(e,this.getEffectiveMinScale());n<this._core.store.state.scale&&(this._core.store.state.scale=n,this.centerInViewport(t))}bringIntoViewIfNeeded(t){const{scale:e,translateX:n,translateY:i,viewportWidth:r,viewportHeight:s}=this._core.store.state,o=t.rotatedBoundingBox;if(o.x*e+n>=0&&o.y*e+i>=0&&(o.x+o.width)*e+n<=r&&(o.y+o.height)*e+i<=s)return;const a=Math.min(r/(1.1*o.width),s/(1.1*o.height),this._core.store.state.scaleMax),c=Math.max(a,this.getEffectiveMinScale()),l=Math.min(c,e),h=this.clampTranslate(r/2-(o.x+o.width/2)*l,s/2-(o.y+o.height/2)*l);this.animateViewportTo(h.translateX,h.translateY,l)}handleZoom(t){this._core.store.state.isScaling=!0;const e=this._core.store.host.getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top;this._core.store.state.pointerX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale,this._core.store.objects?.updateCursorPosition(this._core.store.state.pointerX,this._core.store.state.pointerY);const r=Math.max(.8,Math.min(1.2,1+-.012*t.deltaY)),s=this.getEffectiveMinScale(),o=Math.min(this._core.store.state.scaleMax,Math.max(s,this._core.store.state.scale*r)),a=o/this._core.store.state.scale,c=(n-this._core.store.state.translateX)*(a-1),l=(i-this._core.store.state.translateY)*(a-1);this._core.store.state.scale=o;let h=this._core.store.state.translateX-c;0!==t.deltaX&&(h-=.8*t.deltaX);const u=this.clampTranslate(h,this._core.store.state.translateY-l);this._core.store.state.translateX=u.translateX,this._core.store.state.translateY=u.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate(),this._debounceEndScaling()}handlePan(t){const e=this.clampTranslate(this._core.store.state.translateX-.8*t.deltaX,this._core.store.state.translateY-.8*t.deltaY);this._core.store.state.translateX=e.translateX,this._core.store.state.translateY=e.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}cancelViewportAnimation(){null!==this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}animateViewportTo(t,e,n,i=150){this.cancelViewportAnimation();const r=this._core.store.state.translateX,s=this._core.store.state.translateY,o=this._core.store.state.scale,a=performance.now();this._core.store.state.isScaling=!0;const c=l=>{const h=Math.min((l-a)/i,1),u=1-Math.pow(1-h,3);this._core.store.state.scale=o+(n-o)*u;const f=this.clampTranslate(r+(t-r)*u,s+(e-s)*u);this._core.store.state.translateX=f.translateX,this._core.store.state.translateY=f.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),h<1?this._animationFrameId=requestAnimationFrame(c):(this._animationFrameId=null,this._core.store.state.isScaling=!1,this._core.rerender(),this._debounceUpdate())};this._animationFrameId=requestAnimationFrame(c)}centerFitNearestContent(t=20){const e=this._core.store.allNonSelectionObjects;if(0===e.length)return!1;const n=-this._core.store.state.translateX/this._core.store.state.scale+this._core.store.state.viewportWidth/2/this._core.store.state.scale,i=-this._core.store.state.translateY/this._core.store.state.scale+this._core.store.state.viewportHeight/2/this._core.store.state.scale,r=e.map((t=>{const e=t.rotatedBoundingBox,r=e.y+e.height/2;return{obj:t,distance:Math.sqrt(Math.pow(e.x+e.width/2-n,2)+Math.pow(r-i,2))}}));r.sort(((t,e)=>t.distance-e.distance));const s=r.slice(0,t).map((t=>t.obj));let o=1/0,a=1/0,c=-1/0,l=-1/0;for(const t of s){const e=t.rotatedBoundingBox;o=Math.min(o,e.x),a=Math.min(a,e.y),c=Math.max(c,e.x+e.width),l=Math.max(l,e.y+e.height)}const h=c-o,u=l-a,f=o+h/2,d=a+u/2,p=Math.min(this._core.store.state.viewportWidth/(1.1*h),this._core.store.state.viewportHeight/(1.1*u),this._core.store.state.scaleMax),g=Math.max(p,this.getEffectiveMinScale());return this.animateViewportTo(this._core.store.state.viewportWidth/2-f*g,this._core.store.state.viewportHeight/2-d*g,g),!0}centerFitObjects(t,e=!0){if(0===t.length)return!1;let n=1/0,i=1/0,r=-1/0,s=-1/0;for(const e of t){const t=e.rotatedBoundingBox;n=Math.min(n,t.x),i=Math.min(i,t.y),r=Math.max(r,t.x+t.width),s=Math.max(s,t.y+t.height)}const o=r-n,a=s-i,c=n+o/2,l=i+a/2,h=Math.min(this._core.store.state.viewportWidth/(1.1*o),this._core.store.state.viewportHeight/(1.1*a),this._core.store.state.scaleMax),u=Math.max(h,this.getEffectiveMinScale());return this.animateViewportTo(this._core.store.state.viewportWidth/2-c*u,this._core.store.state.viewportHeight/2-l*u,u,e?150:0),!0}centerFitAllObjects(t=!0){return this.centerFitObjects(this._core.store.allNonSelectionObjects,t)}}class ie extends v{shortcuts=[{key:"Escape",label:"Clear Selection",category:"General",condition:t=>!!t.store.activeText||!!t.store.activeShape||!!t.store.selectionGroup,action:t=>{t.store.activeText?t.store.activeText.handleEscape():t.store.activeShape?t.store.activeShape.handleEscape():t.clearSelection()}},{key:"Delete",label:"Delete Selected",category:"General",condition:t=>!!t.store.selectionGroup,action:t=>t.delete()},{key:"a",ctrl:!0,label:"Select All in Viewport",category:"General",action:t=>t.selectAllObjectsInViewport()},{key:"A",ctrl:!0,shift:!0,label:"Select All Objects",category:"General",action:t=>t.selectAllObjects()},{key:"z",ctrl:!0,label:"Undo",category:"Undo/Redo",action:t=>t.undo()},{key:"y",ctrl:!0,label:"Redo",category:"Undo/Redo",action:t=>t.redo()},{key:"1",ctrl:!0,label:"Tool 1",category:"Tool Selection",action:()=>this.switchToolByIndex(0)},{key:"2",ctrl:!0,label:"Tool 2",category:"Tool Selection",action:()=>this.switchToolByIndex(1)},{key:"3",ctrl:!0,label:"Tool 3",category:"Tool Selection",action:()=>this.switchToolByIndex(2)},{key:"4",ctrl:!0,label:"Tool 4",category:"Tool Selection",action:()=>this.switchToolByIndex(3)},{key:"5",ctrl:!0,label:"Tool 5",category:"Tool Selection",action:()=>this.switchToolByIndex(4)},{key:"6",ctrl:!0,label:"Tool 6",category:"Tool Selection",action:()=>this.switchToolByIndex(5)},{key:"7",ctrl:!0,label:"Tool 7",category:"Tool Selection",action:()=>this.switchToolByIndex(6)},{key:"8",ctrl:!0,label:"Tool 8",category:"Tool Selection",action:()=>this.switchToolByIndex(7)},{key:"9",ctrl:!0,label:"Tool 9",category:"Tool Selection",action:()=>this.switchToolByIndex(8)},{key:"+",ctrl:!0,label:"Bring Forward",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.bringForward()},{key:"-",ctrl:!0,label:"Send Backward",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.sendBackward()},{key:"*",shift:!0,label:"Bring to Front",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.bringToFront()},{key:"_",shift:!0,label:"Send to Back",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.sendToBack()},{key:"g",ctrl:!0,label:"Group",category:"Grouping",condition:t=>!!t.store.selectionGroup&&t.store.selectionGroup.objects.length>=2,action:t=>t.group()},{key:"G",ctrl:!0,shift:!0,label:"Ungroup",category:"Grouping",condition:t=>!!t.store.selectionGroup,action:t=>t.ungroup()},{key:"ArrowUp",label:"Move Object Up",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(0,0,0,10),t.rerender()}},{key:"ArrowDown",label:"Move Object Down",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(0,10,0,0),t.rerender()}},{key:"ArrowLeft",label:"Move Object Left",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(0,0,10,0),t.rerender()}},{key:"ArrowRight",label:"Move Object Right",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(10,0,0,0),t.rerender()}}];constructor(t){super(t)}switchToolByIndex(t){const e=this._core.toolRegistry.getToolByIndex(t);e&&(this._core.store.setState("activeTool",e),this._core.deselectAllObjects(),e.onActivate())}handleKeyDown(t){if(this._core.store.state.isCtrlKeyPressed=t.ctrlKey,(this._core.store.activeText||this._core.store.activeShape||this._core.store.activeInteractiveCustomElement)&&"Escape"!==t.key)return;const e=this.shortcuts.find((e=>e.key===t.key&&!!e.ctrl===t.ctrlKey&&!!e.shift===t.shiftKey&&(!e.condition||e.condition(this._core))));e&&(t.preventDefault(),e.action(this._core))}handleKeyUp(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey}getDisplayableShortcuts(){return this.shortcuts.map((({key:t,ctrl:e,shift:n,label:i,category:r})=>({key:t,ctrl:e,shift:n,label:i,category:r})))}}class re extends v{globalContextMenuItems=[];objectContextMenuItems=[];constructor(t,e,n){super(t),this.globalContextMenuItems=e,this.objectContextMenuItems=n}resolveLabels(t){return t.map((t=>({...t,label:this._core.localizationManager.translate(t.label),children:t.children?this.resolveLabels(t.children):void 0})))}getResolvedContextMenuItems(){return this.resolveLabels(this._core.store.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems)}handleContextMenu(t){if(!(this._core.store.state.activeTool instanceof w))return;if(this._core.store.state.skipContextMenu)return void(this._core.store.state.skipContextMenu=!1);const e=this._core.store.state.activeTool;e?.moveHandler?.cancelPendingDrag(),this._core.store.selectionBox&&(this._core.store.objects.remove((t=>t instanceof g)),this._core.store.setSelectionBox(null),this._core.store.state.isSelecting=!1);const n=this._core.getObjectFromPointerEvent(t,".object");if(n&&!(n instanceof h)&&!(n instanceof g)){const t=h.create(this._core);t.addOrRemove(n),t.isSelected=!0,t.rotation=n.rotation,this._core.store.state.isSelecting=!1,this._core.store.selectionGroup&&this._core.removeSelectionGroup(),this._core.addSelectionGroup(t),this._core.rerender()}this._core.store.state.contextMenuItems=this.getResolvedContextMenuItems();const i=t.clientX-this._core.store.offsetX,r=t.clientY-this._core.store.offsetY,{translateX:s,translateY:o,scale:a}=this._core.store.state;this._core.store.state.contextMenuWorldX=(i-s)/a,this._core.store.state.contextMenuWorldY=(r-o)/a;let c=i,l=r;c+150>this._core.store.state.viewportWidth-10&&(c=this._core.store.state.viewportWidth-150-10),c=Math.max(10,c),l=Math.max(10,l),this._core.store.state.contextMenuX=c,this._core.store.state.contextMenuY=l,this._core.store.state.isContextMenuVisible=!0,this._core.store.state.isEnabled=!1,this._core.rerender()}open(t){const{x:e,y:n,objectId:i}=t;if(this._core.store.state.activeTool instanceof w){const t=this._core.store.state.activeTool;t?.moveHandler?.cancelPendingDrag()}if(this._core.store.selectionBox&&(this._core.store.objects.remove((t=>t instanceof g)),this._core.store.setSelectionBox(null),this._core.store.state.isSelecting=!1),i){const t=this._core.store.allObjects.find((t=>t.id===i));if(t&&!(t instanceof h)&&!(t instanceof g)){const e=h.create(this._core);e.addOrRemove(t),e.isSelected=!0,e.rotation=t.rotation,this._core.store.state.isSelecting=!1,this._core.store.selectionGroup&&this._core.removeSelectionGroup(),this._core.addSelectionGroup(e)}}this._core.store.state.contextMenuItems=this.getResolvedContextMenuItems(),this._core.store.state.contextMenuWorldX=e,this._core.store.state.contextMenuWorldY=n;const{translateX:r,translateY:s,scale:o}=this._core.store.state;let a=e*o+r,c=n*o+s;a+150>this._core.store.state.viewportWidth-10&&(a=this._core.store.state.viewportWidth-150-10),a=Math.max(10,a),c=Math.max(10,c),this._core.store.state.contextMenuX=a,this._core.store.state.contextMenuY=c,this._core.store.state.isContextMenuVisible=!0,this._core.store.state.isEnabled=!1,this._core.rerender()}}class se{_core;constructor(t){this._core=t}revive(t){if(t&&"object"==typeof t){if(t.__class__){let e;switch(t.__class__){case"KritzelPath":e=_.create(this._core).deserialize(t);break;case"KritzelLine":e=L.create(this._core).deserialize(t);break;case"KritzelText":e=b.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelShape":e=d.create(this._core,{shapeType:t.shapeType,fillColor:t.fillColor,strokeColor:t.strokeColor,strokeWidth:t.strokeWidth,fontSize:t.fontSize,fontFamily:t.fontFamily,fontColor:t.fontColor}).deserialize(t);break;case"KritzelImage":e=u.create(this._core).deserialize(t);break;case"KritzelCustomElement":e=Z.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":e=h.create(this._core).deserialize(t);break;case"KritzelGroup":e=y.create(this._core).deserialize(t);break;case"KritzelWorkspace":e=T.create(this._core,t).deserialize(t);break;case"KritzelBrushTool":e=new q(this._core);break;case"KritzelEraserTool":e=new tt(this._core);break;case"KritzelImageTool":e=new Lt(this._core);break;case"KritzelSelectionTool":e=new w(this._core);break;case"KritzelTextTool":e=new m(this._core);break;case"KritzelLineTool":e=new J(this._core);break;case"KritzelShapeTool":e=new Ot(this._core);break;default:e=t}return e}const e=Array.isArray(t)?[]:{};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=this.revive(t[n]));return e}return t}}const oe={activeWorkspace:void 0,activeTool:null,objects:null,snapCandidate:null,snapPreviewCandidate:null,resizeHandleType:null,lineHandleType:null,hasViewportChanged:!1,hasObjectsChanged:!1,isReady:!1,isEnabled:!0,isScaling:!1,isPanning:!1,isSelecting:!1,isResizing:!1,isResizeHandleHovered:!1,isResizeHandleSelected:!1,isRotating:!1,isRotationHandleHovered:!1,isRotationHandleSelected:!1,isLineHandleSelected:!1,isLineHandleDragging:!1,isDragging:!1,isDrawing:!1,isErasing:!1,isWriting:!1,isLoading:!1,isCtrlKeyPressed:!1,isContextMenuVisible:!1,contextMenuItems:[],contextMenuX:0,contextMenuY:0,contextMenuWorldX:0,contextMenuWorldY:0,skipContextMenu:!1,debugInfo:{showObjectInfo:!1,showViewportInfo:!1,showSyncProviderInfo:!1,showAssetResolverInfo:!1,showMigrationInfo:!1},host:null,pointerX:0,pointerY:0,scale:1,scaleMax:1,scaleMin:1,startX:0,startY:0,translateX:0,translateXMax:400,translateXMin:0,translateY:0,translateYMax:400,translateYMin:0,viewportWidth:0,viewportHeight:0,longTouchTimeout:null,longTouchDelay:300,pointers:new Map,workspaces:[],cursor:{icon:"default",iconActive:"default"},lockDrawingScale:!0,viewportBoundaryLeft:-1/0,viewportBoundaryRight:1/0,viewportBoundaryTop:-1/0,viewportBoundaryBottom:1/0};class ae{static calculateSelectionBounds(t){const e=t.map((t=>t.rotatedBoundingBox));return{minX:Math.min(...e.map((t=>t.x))),minY:Math.min(...e.map((t=>t.y))),maxX:Math.max(...e.map((t=>t.x+t.width))),maxY:Math.max(...e.map((t=>t.y+t.height)))}}static calculateAlignedPositions(t,e){const n=new Map;if(t.length<2)return n;const i=this.calculateSelectionBounds(t);for(const r of t){const t=r.rotatedBoundingBox;let s=r.translateX,o=r.translateY;const a=t.x-r.translateX,c=t.y-r.translateY;switch(e){case Gt.StartHorizontal:s=i.minX-a;break;case Gt.CenterHorizontal:s=r.translateX+((i.minX+i.maxX)/2-(t.x+t.width/2));break;case Gt.EndHorizontal:s=r.translateX+(i.maxX-(t.x+t.width));break;case Gt.StartVertical:o=i.minY-c;break;case Gt.CenterVertical:o=r.translateY+((i.minY+i.maxY)/2-(t.y+t.height/2));break;case Gt.EndVertical:o=r.translateY+(i.maxY-(t.y+t.height))}n.set(r.id,{translateX:s,translateY:o})}return n}}class ce{core;registry={};constructor(t){this.core=t}registerTool(t,e){const n=new e(this.core);return n.name=t,this.registry[t]=n,n}hasTool(t){return t in this.registry}getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}getToolByIndex(t){return Object.values(this.registry)[t]??null}}class le{bounds;capacity;objects=[];children=null;_size=0;get size(){return this._size}constructor(t,e=16){this.bounds=t,this.capacity=e}reset(){this.objects=[],this.children=null,this._size=0}insert(t){if(!this.intersects(t.rotatedBoundingBox,this.bounds))return!1;if(this.objects.length<this.capacity&&null===this.children)return this.objects.push(t),this._size++,!0;null===this.children&&this.subdivide();for(const e of this.children)if(e.insert(t))return this._size++,!0;return!1}update(t){const e=this.objects.findIndex((e=>e.id===t.id));if(-1!==e)return this.objects[e]=t,!0;if(null!==this.children)for(const e of this.children)if(e.update(t))return!0;return!1}remove(t){let e=0;const n=this.objects.findIndex((e=>t(e)));if(-1!==n&&(this.objects.splice(n,1),e++),null!==this.children)for(const n of this.children)e+=n.remove(t);return this._size-=e,e}query(t){const e=[];return this._queryInto(t,e),e}_queryInto(t,e){if(this.intersects(t,this.bounds)){for(const n of this.objects)this.intersects(n.rotatedBoundingBox,t)&&e.push(n);if(null!==this.children)for(const n of this.children)n._queryInto(t,e)}}filter(t){const e=[];return this._filterInto(t,e),e}_filterInto(t,e){for(const n of this.objects)t(n)&&e.push(n);if(null!==this.children)for(const n of this.children)n._filterInto(t,e)}allObjects(){const t=[];return this._collectAllInto(t),t}_collectAllInto(t){for(const e of this.objects)t.push(e);if(null!==this.children)for(const e of this.children)e._collectAllInto(t)}subdivide(){const{x:t,y:e,z:n,width:i,height:r}=this.bounds,s=i/2,o=r/2;this.children=[new le({x:t,y:e,z:n,width:s,height:o},this.capacity),new le({x:t+s,y:e,z:n,width:s,height:o},this.capacity),new le({x:t,y:e+o,z:n,width:s,height:o},this.capacity),new le({x:t+s,y:e+o,z:n,width:s,height:o},this.capacity)]}intersects(t,e){return!(t.x>=e.x+e.width||t.x+t.width<=e.x||t.y>=e.y+e.height||t.y+t.height<=e.y)}}class he{quadtree;_ydoc=null;_objectsMap=null;_metadataMap=null;_providers=[];_undoManager=null;_reviver=null;_core=null;_workspaceId=null;_isReady=!1;_temporaryItemsCount=0;_idMap=new Map;_awareness=null;_objectsObserver=null;_stackItemAddedHandler=null;_stackItemPoppedHandler=null;_awarenessChangeHandler=null;_awarenessChangeCallbacks=[];_objectsChangeCallbacks=[];_lastAwarenessEmitTime=0;_awarenessEmitTimeout=null;AWARENESS_THROTTLE_INTERVAL=100;_localOnlyMode=!1;_inTransaction=!1;get isReady(){return this._isReady}get awareness(){return this._awareness}get hasAwareness(){return!!this._awareness}get localClientId(){return this._awareness?.clientID??null}setLocalUser(t){if(!this._awareness||!t)return;const e=t.displayName||t.firstName||"Anonymous";this._awareness.setLocalStateField("user",{id:t.id,displayName:e,color:t.color||this.generateColorFromName(e)})}generateColorFromName(t){let e=0;for(let n=0;n<t.length;n++)e=t.charCodeAt(n)+((e<<5)-e);return`hsl(${Math.abs(e%360)}, 45%, 55%)`}updateCursorPosition(t,e){this._awareness&&this._awareness.setLocalStateField("cursor",{x:t,y:e})}clearCursorPosition(){this._awareness&&this._awareness.setLocalStateField("cursor",null)}setActiveDrawingObject(t){this._awareness&&this._awareness.setLocalStateField("activeObjectId",t)}setLocalSelectionBox(t){this._awareness&&this._awareness.setLocalStateField("selectionBox",t)}clearLocalSelectionBox(){this._awareness&&this._awareness.setLocalStateField("selectionBox",null)}removeOrphanedSelectionGroups(){if(!this._awareness)return;const t=this._awareness.getStates(),e=new Set;t.forEach((t=>{const n=t.user?.id;n&&e.add(n)}));const n=this._core?.user?.id,i=this.quadtree.filter((t=>t instanceof h&&null!=t.userId&&t.userId!==n&&!e.has(t.userId)));for(const t of i)this.quadtree.remove((e=>e.id===t.id)),this._idMap.delete(t.id),this._objectsMap&&this._ydoc.transact((()=>{this._objectsMap.delete(t.id)}),"local");i.length>0&&(this._core?.store.invalidateSelectionCache(),this._core?.rerender())}onAwarenessChange(t){this._awarenessChangeCallbacks.push(t)}onObjectsChange(t){this._objectsChangeCallbacks.push(t)}get undoManager(){return this._undoManager}get workspaceId(){return this._workspaceId}get undoState(){return{canUndo:!!this._undoManager&&this._undoManager.canUndo(),canRedo:!!this._undoManager&&this._undoManager.canRedo(),undoStackSize:this._undoManager?this._undoManager.undoStack.length:0,redoStackSize:this._undoManager?this._undoManager.redoStack.length:0}}get totalCount(){return this.quadtree.size}findById(t){return this._idMap.get(t)}constructor(){this.quadtree=new le({x:-1/0,y:-1/0,z:0,width:1/0,height:1/0},8)}async initialize(t,e,n){this._core=t,this._workspaceId=e,this._reviver=new se(t),this._ydoc=new W.Doc,this._objectsMap=this._ydoc.getMap("objects"),this._metadataMap=this._ydoc.getMap("metadata");const i=t.editorId?`kritzel-workspace-${t.editorId}-${e}`:`kritzel-workspace-${e}`,r=n??Qt,s=!!t.store?.state?.debugInfo?.showSyncProviderInfo,o=!s;for(const t of r.providers){let e;e="function"==typeof t?new t(i,this._ydoc,{quiet:o}):t.create(i,this._ydoc,{quiet:o}),this._providers.push(e)}if(s){const t=this._providers.map((t=>`${t.constructor.name} (${t.type})`)).join(", ");console.info(`[Kritzel] Workspace sync providers initialized for ${i}: ${t||"none"}`)}this._undoManager=new W.UndoManager([this._objectsMap],{captureTimeout:Number.MAX_SAFE_INTEGER,trackedOrigins:new Set(["local","temporary"]),ignoreRemoteMapChanges:!0}),this._stackItemAddedHandler=t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount++},this._stackItemPoppedHandler=t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount>0&&this._temporaryItemsCount--},this._undoManager.on("stack-item-added",this._stackItemAddedHandler),this._undoManager.on("stack-item-popped",this._stackItemPoppedHandler),this._objectsObserver=t=>{this.handleObjectsChange(t)},this._objectsMap.observe(this._objectsObserver);const a=this._providers.filter((t=>"local"===t.type)),c=this._providers.filter((t=>"network"===t.type)),l=await Promise.allSettled(a.map((t=>t.connect())));if(s){const t=l.filter((t=>"fulfilled"===t.status)).length;console.info(`[Kritzel] Workspace local providers connected: ${t}/${a.length}`)}l.forEach(((t,e)=>{s&&"rejected"===t.status&&console.error(`[Kritzel] Sync provider "${a[e]?.constructor.name}" failed to connect:`,t.reason)})),s&&c.length>0&&console.info(`[Kritzel] Workspace network providers connecting in background: ${c.length}`);for(const t of c)t.connect().catch((e=>{s&&console.error(`[Kritzel] Network sync provider "${t.constructor.name}" failed to connect:`,e)}));this._isReady=!0;for(const t of c)if(t.awareness){this._awareness=t.awareness;break}this._awareness&&(this._awarenessChangeHandler=t=>{t.removed.length>0&&this.removeOrphanedSelectionGroups();const e=Date.now(),n=e-this._lastAwarenessEmitTime;if(null!==this._awarenessEmitTimeout&&(clearTimeout(this._awarenessEmitTimeout),this._awarenessEmitTimeout=null),n>=this.AWARENESS_THROTTLE_INTERVAL){this._lastAwarenessEmitTime=e;const t=this._awareness.getStates();for(const e of this._awarenessChangeCallbacks)e(t)}else this._awarenessEmitTimeout=setTimeout((()=>{this._lastAwarenessEmitTime=Date.now(),this._awarenessEmitTimeout=null;const t=this._awareness.getStates();for(const e of this._awarenessChangeCallbacks)e(t)}),this.AWARENESS_THROTTLE_INTERVAL-n)},this._awareness.on("change",this._awarenessChangeHandler)),this.initializeMetadata("workspace",e,t.store?.state?.activeWorkspace?.name??""),Ht(this._ydoc,this._metadataMap,{objects:this._objectsMap},Yt,U,{quiet:!t.store?.state?.debugInfo?.showMigrationInfo}),this.loadFromYjs()}handleObjectsChange(t){if("local"===t.transaction.origin||"temporary"===t.transaction.origin)return void this._core?.rerender();if("migration"===t.transaction.origin)return;const e=Array.from(t.keysChanged),n=[],i=[],r=[];e.forEach((e=>{const s=t.changes.keys.get(e);if(s&&"delete"===s.action)r.push(e);else{const t=this._objectsMap?.get(e);if(t){const e=this._reviver?.revive(t);e instanceof h?i.push(e):n.push(e)}}})),r.forEach((t=>{this.quadtree.remove((e=>e.id===t)),this._idMap.delete(t)}));const s=[],o=[];n.forEach((t=>{if(this._idMap.has(t.id)){const e=this._idMap.get(t.id);e&&"function"==typeof t.adoptTransientStateFrom&&t.adoptTransientStateFrom(e),this.quadtree.update(t),this._idMap.set(t.id,t),o.push(t)}else this.quadtree.insert(t),this._idMap.set(t.id,t),s.push(t)}));const a=new Set;if(i.forEach((t=>{if(this._idMap.has(t.id)){const e=this._idMap.get(t.id);e&&"function"==typeof t.adoptTransientStateFrom&&t.adoptTransientStateFrom(e),this.quadtree.update(t),this._idMap.set(t.id,t)}else this.quadtree.insert(t),this._idMap.set(t.id,t);a.add(t.id),t.invalidateObjectsCache(),t.refreshObjectDimensions(void 0,!0),t.captureUnchangedSnapshots(),this.quadtree.update(t)})),n.length>0||r.length>0){const t=new Set([...n.map((t=>t.id)),...r]),e=this.quadtree.filter((t=>t instanceof h&&!a.has(t.id)));for(const n of e)n.objectIds.some((e=>t.has(e)))&&(n.invalidateObjectsCache(),n.refreshObjectDimensions(void 0,!0),n.captureUnchangedSnapshots(),this.quadtree.update(n))}if(this._core?.store.invalidateSelectionCache(),this._core?.rerender(),s.length>0&&this._core?.engine.emitObjectsAdded(s),r.length>0){const t=r.map((t=>({id:t})));this._core?.engine.emitObjectsRemoved(t)}o.length>0&&this._core?.engine.emitObjectsUpdated(o.map((t=>({object:t,changedProperties:[]}))));for(const t of this._objectsChangeCallbacks)t()}initializeMetadata(t,e,n){this._metadataMap&&this._ydoc&&this._ydoc.transact((()=>{this._metadataMap?.get("type")||this._metadataMap?.set("type",t),void 0===this._metadataMap?.get("isPublic")&&this._metadataMap?.set("isPublic",!1),void 0===this._metadataMap?.get("schemaVersion")&&this._metadataMap?.set("schemaVersion",U),this._metadataMap?.set("workspaceId",e),this._metadataMap?.set("workspaceName",n)}),"metadata")}getIsPublic(){return this._metadataMap?.get("isPublic")??!1}setIsPublic(t){this._metadataMap&&this._ydoc&&this._ydoc?.transact((()=>{this._metadataMap?.set("isPublic",t)}),"metadata")}getDocumentType(){return this._metadataMap?.get("type")??"workspace"}getWorkspaceName(){return this._metadataMap?.get("workspaceName")??""}setWorkspaceName(t){this._metadataMap&&this._ydoc&&this._ydoc?.transact((()=>{this._metadataMap?.set("workspaceName",t)}),"metadata")}getMetadataWorkspaceId(){return this._metadataMap?.get("workspaceId")??""}transaction(t){if(this._ydoc){this._inTransaction=!0;try{this._ydoc.transact(t,"local")}finally{this._inTransaction=!1}}}stopUndoCapturing(){this.markUndoBoundary()}markUndoBoundary(){this._inTransaction||this._undoManager?.stopCapturing()}withLocalUpdatesOnly(t){this._localOnlyMode=!0;try{t()}finally{this._localOnlyMode=!1}}loadFromYjs(){if(!this._objectsMap||!this._reviver)return;this.quadtree.reset(),this._idMap.clear();const t=this._core?.user?.id,e=[];this._objectsMap.forEach(((n,i)=>{const r=this._reviver?.revive(n);r instanceof h&&null!=r.userId&&r.userId!==t?e.push(i):r&&(this.quadtree.insert(r),this._idMap.set(r.id,r))})),e.length>0&&this._ydoc.transact((()=>{for(const t of e)this._objectsMap.delete(t)}),"local")}reset(){this.quadtree.reset(),this._idMap.clear(),this.markUndoBoundary(),this._ydoc?.transact((()=>{this._objectsMap?.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.quadtree.insert(t),this._idMap.set(t.id,t),this._objectsMap&&this.isPersistable(t)){const e=t.serialize();this.markUndoBoundary(),this._ydoc?.transact((()=>{this._objectsMap?.set(t.id,e)}),"local")}return!0}update(t,e={}){if(!t.id)return!1;if(!this._idMap.has(t.id))return!1;if(this.quadtree.update(t),this._idMap.set(t.id,t),!this._localOnlyMode&&this._objectsMap&&this.isPersistable(t)){const n=t.serialize(),i=e.temporary?"temporary":"local";this._ydoc?.transact((()=>{this._objectsMap?.set(t.id,n)}),i)}return!0}remove(t){const e=this.quadtree.filter(t);if(0!==e.length){this.markUndoBoundary();for(const t of e)this.quadtree.remove((e=>e.id===t.id)),this._idMap.delete(t.id),this._objectsMap&&this.isPersistable(t)&&this._ydoc?.transact((()=>{this._objectsMap?.delete(t.id)}),"local")}}filter(t){return this.quadtree.filter(t)}allObjects(){return this.quadtree.allObjects()}query(t){return this.quadtree.query(t)}isPersistable(t){return!(t instanceof g)}undo(){this._undoManager&&this._undoManager.canUndo()&&(this._undoManager.undo(),this._core?.engine.emitObjectsChange())}redo(){this._undoManager&&this._undoManager.canRedo()&&(this._undoManager.redo(),this._core?.engine.emitObjectsChange())}canUndo(){return!!this._undoManager&&this._undoManager.canUndo()}canRedo(){return!!this._undoManager&&this._undoManager.canRedo()}clearHistory(){this._undoManager&&(this._undoManager.clear(),this._temporaryItemsCount=0)}consolidateTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=this._undoManager.undoStack.length;if(0===t)return void(this._temporaryItemsCount=0);this._undoManager.stopCapturing();const e=Math.min(this._temporaryItemsCount,t);if(e>1){for(let t=0;t<e;t++)this._undoManager.canUndo()&&this._undoManager.undo();this._ydoc?.transact((()=>{for(let t=e-1;t>=0;t--)this._undoManager?.canRedo()&&this._undoManager.redo()}),"local")}this._temporaryItemsCount=0}clearTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=Math.min(this._temporaryItemsCount,this._undoManager.undoStack.length);for(let e=0;e<t;e++)this._undoManager.undoStack.length>0&&this._undoManager.undoStack.pop();this._temporaryItemsCount=0}destroy(){this._objectsMap&&this._objectsObserver&&(this._objectsMap.unobserve(this._objectsObserver),this._objectsObserver=null),this._undoManager&&(this._stackItemAddedHandler&&(this._undoManager.off("stack-item-added",this._stackItemAddedHandler),this._stackItemAddedHandler=null),this._stackItemPoppedHandler&&(this._undoManager.off("stack-item-popped",this._stackItemPoppedHandler),this._stackItemPoppedHandler=null),this._undoManager.destroy(),this._undoManager=null),this.quadtree.reset(),this._idMap.clear(),this._awareness&&this._awarenessChangeHandler&&(this._awareness.off("change",this._awarenessChangeHandler),this._awarenessChangeHandler=null),null!==this._awarenessEmitTimeout&&(clearTimeout(this._awarenessEmitTimeout),this._awarenessEmitTimeout=null),this._awareness=null,this._awarenessChangeCallbacks=[],this._providers.forEach((t=>{t.destroy()})),this._providers=[],this._objectsMap=null,this._metadataMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._core=null,this._reviver=null,this._workspaceId=null,this._isReady=!1,this._temporaryItemsCount=0}}class ue{_state;_listeners=new Map;_cachedSelectionBox=null;_cachedSelectionGroup=null;_selectionBoxCacheValid=!1;_selectionGroupCacheValid=!1;_localUserId=null;get state(){return this._state}get objects(){if(!this._state.objects)throw new Error("Objects map is not initialized.");return this._state.objects}get host(){if(!this._state.host)throw new Error("Host element is not set.");return this._state.host}get currentZIndex(){return Math.max(0,...this.objects.filter((t=>!(t instanceof h||t instanceof g))).map((t=>t.zIndex)))+1}get hasViewportBoundaries(){return Number.isFinite(this._state.viewportBoundaryLeft)||Number.isFinite(this._state.viewportBoundaryRight)||Number.isFinite(this._state.viewportBoundaryTop)||Number.isFinite(this._state.viewportBoundaryBottom)}get viewportBoundaryBounds(){const t=this._state.viewportBoundaryLeft,e=this._state.viewportBoundaryRight,n=this._state.viewportBoundaryTop,i=this._state.viewportBoundaryBottom;return{x:Number.isFinite(t)?t:-1/0,y:Number.isFinite(n)?n:-1/0,z:0,width:Number.isFinite(t)&&Number.isFinite(e)?e-t:1/0,height:Number.isFinite(n)&&Number.isFinite(i)?i-n:1/0}}get totalObjectCount(){return this.hasViewportBoundaries?this.allObjects.length:this.objects.totalCount}get allObjects(){return this.hasViewportBoundaries?this.objects.query(this.viewportBoundaryBounds):this.objects.allObjects()}get objectsInViewport(){return this.objects.query({x:-this._state.translateX/this._state.scale,y:-this._state.translateY/this._state.scale,z:this._state.scale,width:this._state.viewportWidth/this._state.scale,height:this._state.viewportHeight/this._state.scale,depth:100}).sort(((t,e)=>t.zIndex-e.zIndex))}get allNonSelectionObjects(){return this.allObjects.filter((t=>!(t instanceof h||t instanceof g)))}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof h))).filter((t=>t.isSelected))}get selectionBox(){if(this._selectionBoxCacheValid)return this._cachedSelectionBox;const t=this.objects.filter((t=>t instanceof g));return this._cachedSelectionBox=t.length>0?t[0]:null,this._selectionBoxCacheValid=!0,this._cachedSelectionBox}get selectionGroup(){if(this._selectionGroupCacheValid)return this._cachedSelectionGroup;const t=this.objects.filter((t=>t instanceof h));return this._cachedSelectionGroup=this._localUserId?t.find((t=>t.userId===this._localUserId))??null:t.length>0?t[0]:null,this._selectionGroupCacheValid=!0,this._cachedSelectionGroup}invalidateSelectionCache(){this._selectionBoxCacheValid=!1,this._selectionGroupCacheValid=!1}setSelectionBox(t){this._cachedSelectionBox=t,this._selectionBoxCacheValid=!0}setSelectionGroup(t){this._cachedSelectionGroup=t,this._selectionGroupCacheValid=!0}setLocalUserId(t){this._localUserId=t,this.invalidateSelectionCache()}get activeText(){const t=this.objects.filter((t=>t instanceof b&&t.isEditing));return t.length>0?t[0]:null}get activeShape(){const t=this.objects.filter((t=>t instanceof d&&t.isEditing));return t.length>0?t[0]:null}get activeInteractiveCustomElement(){return this.selectedObjects.find((t=>p.isInstanceOf(t,"KritzelCustomElement")&&t.hasFocusedInputElement()))??null}get currentPath(){const t=this.objects.filter((t=>t instanceof _&&!1===t.isCompleted));return t.length>0?t[0]:null}get currentLine(){const t=this.objects.filter((t=>t instanceof L&&!1===t.isCompleted));return t.length>0?t[0]:null}get offsetX(){return this.host.getBoundingClientRect().left}get offsetY(){return this.host.getBoundingClientRect().top}get isDisabled(){return!1===this._state.isEnabled||!1===this._state.isReady||null===this._state.activeWorkspace}get isPointerDown(){return this._state.pointers.size>0}constructor(t){this._state={...t,contextMenuItems:[...t.contextMenuItems],debugInfo:{...t.debugInfo},pointers:new Map(t.pointers),workspaces:[...t.workspaces],cursor:{...t.cursor}},this._state.objects=new he}onStateChange(t,e){this._listeners.has(t)||this._listeners.set(t,new Set);const n=this._listeners.get(t);if(!n)throw new Error(`Listeners set for property ${String(t)} was not initialized.`);n.add(e)}getState(t){return this._state[t]}setState(t,e){const n=this._state[t];if(n!==e){this._state[t]=e;const i=this._listeners.get(t);i&&i.forEach((i=>i(e,n,String(t))))}}}class fe{map;_ydoc=null;_workspacesMap=null;_metadataMap=null;_providers=[];_core=null;_isReady=!1;_onRemoteChangeCallback=null;_workspacesObserver=null;get isReady(){return this._isReady}get hasNetworkSyncProvider(){return this._providers.some((t=>"network"===t.type))}constructor(){this.map=new Map}onRemoteChange(t){this._onRemoteChangeCallback=t}async initialize(t,e){this._core=t,this._ydoc=new W.Doc,this._workspacesMap=this._ydoc.getMap("workspaces"),this._metadataMap=this._ydoc.getMap("metadata");const n=e?.appStateId??this.getOrCreateAppStateInstanceId(t),i=t.editorId?`kritzel-app-state-${t.editorId}-${n}`:`kritzel-app-state-${n}`,r=e??Qt,s=!!t.store.state.debugInfo.showSyncProviderInfo,o=!s;for(const t of r.providers){let e;e="function"==typeof t?new t(i,this._ydoc,{quiet:o}):t.create(i,this._ydoc,{quiet:o}),this._providers.push(e)}if(s){const t=this._providers.map((t=>`${t.constructor.name} (${t.type})`)).join(", ");console.info(`[Kritzel] App-state sync providers initialized for ${i}: ${t||"none"}`)}this._workspacesObserver=t=>{this.handleWorkspacesChange(t)},this._workspacesMap.observe(this._workspacesObserver);const a=this._providers.filter((t=>"local"===t.type)),c=this._providers.filter((t=>"network"===t.type)),l=await Promise.allSettled(a.map((t=>t.connect())));if(s){const t=l.filter((t=>"fulfilled"===t.status)).length;console.info(`[Kritzel] App-state local providers connected: ${t}/${a.length}`)}l.forEach(((t,e)=>{s&&"rejected"===t.status&&console.error(`[Kritzel] Sync provider "${a[e]?.constructor.name}" failed to connect:`,t.reason)})),s&&c.length>0&&console.info(`[Kritzel] App-state network providers connecting in background: ${c.length}`);for(const t of c)t.connect().catch((e=>{s&&console.error(`[Kritzel] Network sync provider "${t.constructor.name}" failed to connect:`,e)}));this._isReady=!0,Ht(this._ydoc,this._metadataMap,{workspaces:this._workspacesMap},Xt,F,{quiet:!t.store.state.debugInfo.showMigrationInfo}),this.initializeMetadata("state"),this.loadFromYjs()}getOrCreateAppStateInstanceId(t){const e=globalThis.localStorage;if(!e)throw new Error("[KritzelAppStateMap] localStorage is unavailable. Cannot persist app-state document identity.");const n=t.getStorageKey("kritzel-app-state-instance-id");let i;try{i=e.getItem(n)}catch{throw new Error("[KritzelAppStateMap] Failed to read app-state instance id from localStorage.")}if(i)return i;const r=R.generateUUID();try{e.setItem(n,r)}catch{throw new Error("[KritzelAppStateMap] Failed to persist app-state instance id to localStorage.")}return r}handleWorkspacesChange(t){if("local"===t.transaction.origin)return void this._core?.rerender();if("migration"===t.transaction.origin)return;const e=Array.from(t.keysChanged),n=[],i=[];e.forEach((e=>{const r=t.changes.keys.get(e);if(r&&"delete"===r.action)i.push(e);else{const t=this._workspacesMap.get(e);if(t){const e=this.reviveWorkspace(t);n.push(e)}}})),i.forEach((t=>{this.map.delete(t)})),n.forEach((t=>{this.map.set(t.id,t)})),this._core?.store&&(this._core.store.state.workspaces=this.allWorkspaces()),this._onRemoteChangeCallback&&this._onRemoteChangeCallback(),this._core?.rerender()}reviveWorkspace(t){let e=t.viewport;if(e&&"translateX"in e&&!("centerWorldX"in e)){const t=e.scale??1;e={centerWorldX:-(e.translateX??0)/t,centerWorldY:-(e.translateY??0)/t,scale:t}}const n=new T(t.id,t.name,e);return this._core&&(n._core=this._core),n.createdAt=new Date(t.createdAt),n.updatedAt=new Date(t.updatedAt),n.isPublic=t.isPublic??!1,n}initializeMetadata(t){this._metadataMap&&this._ydoc&&this._ydoc.transact((()=>{this._metadataMap?.get("type")||this._metadataMap?.set("type",t),void 0===this._metadataMap?.get("isPublic")&&this._metadataMap?.set("isPublic",!1),void 0===this._metadataMap?.get("schemaVersion")&&this._metadataMap?.set("schemaVersion",F)}),"metadata")}getIsPublic(){return this._metadataMap?.get("isPublic")??!1}setIsPublic(t){this._metadataMap&&this._ydoc&&this._ydoc.transact((()=>{this._metadataMap?.set("isPublic",t)}),"metadata")}getDocumentType(){return this._metadataMap?.get("type")??"state"}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._workspacesMap&&(this.map.clear(),this._workspacesMap.forEach(((t,e)=>{const n=this.reviveWorkspace(t);this.map.set(e,n)})))}reset(){this.map.clear(),this._ydoc?.transact((()=>{this._workspacesMap?.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.map.set(t.id,t),this._workspacesMap){const e=t.serialize();this._ydoc?.transact((()=>{this._workspacesMap?.set(t.id,e)}),"local")}return!0}update(t){if(!t.id||!this.map.has(t.id))return!1;if(this.map.set(t.id,t),this._workspacesMap){const e=t.serialize();this._ydoc?.transact((()=>{this._workspacesMap?.set(t.id,e)}),"local")}return!0}remove(t){const e=Array.from(this.map.values()).find(t);return!!e&&(this.map.delete(e.id),this._workspacesMap&&this._ydoc?.transact((()=>{this._workspacesMap?.delete(e.id)}),"local"),!0)}get(t){return this.map.get(t)}allWorkspaces(){return Array.from(this.map.values())}filter(t){return Array.from(this.map.values()).filter(t)}find(t){return Array.from(this.map.values()).find(t)}has(t){return this.map.has(t)}destroy(){this._workspacesMap&&this._workspacesObserver&&(this._workspacesMap.unobserve(this._workspacesObserver),this._workspacesObserver=null),this._providers.forEach((t=>{t.disconnect(),t.destroy()})),this._providers=[],this.map.clear(),this._workspacesMap=null,this._metadataMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._core=null,this._onRemoteChangeCallback=null,this._isReady=!1}}class de{_core;_targetElement=null;_shadowRoot=null;constructor(t){this._core=t}setTargetElement(t){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-global-pointer-cursor")),this._targetElement=t,this._targetElement&&this._targetElement.style.setProperty("--kritzel-global-pointer-cursor",Pt.getPointerCursor())}getTargetElement(){return this._targetElement}setShadowRoot(t){this._shadowRoot=t}resetToDefault(){this._core.store.state.cursor={icon:"default",iconActive:"default"}}updateHoverState(t){if(this._core.store.isPointerDown)return;if(!this._shadowRoot)return;const e=this._shadowRoot.elementsFromPoint(t.clientX,t.clientY);if(!e||0===e.length)return;const n=e.find((t=>t.classList.contains("resize-handle-overlay")));if(n){const t=this._core.store.selectionGroup,e=t?.rotationDegrees??0,i=n.classList.contains("top-left"),r=n.classList.contains("bottom-right");this._core.store.state.cursor={icon:"move-vertical",rotation:e+(i||r?-45:45)}}else this._core.store.state.cursor=e.find((t=>t.classList.contains("rotation-handle-overlay")))||e.find((t=>t.classList.contains("selection-line-handle-overlay")))?{icon:"hand",iconActive:"hand-grab"}:{icon:"default",iconActive:"default"}}applyCursor(){const t=this._core.store.state,e=this._core.store.isPointerDown,n=t.cursor?.icon,i=t.cursor?.iconActive??n,r=t.cursor?.rotation,s=Pt.getCursor({iconName:e?i:n,rotation:r});this._targetElement&&(this._targetElement.style.cursor=s)}cleanup(){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=null,this._shadowRoot=null}}class pe{_isFirefox=/firefox|fxios/i.test(navigator.userAgent);_isSafari=/safari/i.test(navigator.userAgent)&&!/chrome|chromium|crios|android|edg/i.test(navigator.userAgent);_requestHandlers=new Map;constructor(t){this.registerRequestPermissionHandler("clipboard-read",(async()=>{if(this._isFirefox||this._isSafari)return"granted";try{return await navigator.clipboard.readText(),"granted"}catch{return"denied"}}))}registerRequestPermissionHandler(t,e){this._requestHandlers.set(t,e)}async checkPermission(t){return(await navigator.permissions.query({name:t})).state}async requestPermission(t){const e=this._requestHandlers.get(t);return e?e():this.checkPermission(t)}}const ge="kritzel-clipboard/v1:";class ve{_core;_pasteOffset=0;constructor(t){this._core=t}serializeForClipboard(t){const e="function"==typeof t.serialize?t.serialize():t;return p.isInstanceOf(t,"KritzelGroup")&&(e.__children__=t.children.map((t=>this.serializeForClipboard(t)))),e}serializeClipboardPayload(t){return`${ge}${JSON.stringify(t)}`}parseClipboardPayload(t){if(!t||!t.startsWith(ge))return null;try{const e=JSON.parse(t.slice(21));return 1===e?.version&&Array.isArray(e.objects)?e:null}catch{return null}}determineTextPasteIntent(t){const e=this.parseClipboardPayload(t);return e?{type:"kritzel_objects",payload:e}:t&&t.trim().length>0?{type:"plain_text",text:t}:null}async writeBrowserClipboardPayload(t,e){const n=this.serializeClipboardPayload(t);if(e?.clipboardData)e.clipboardData.setData("text/plain",n);else if("undefined"!=typeof navigator&&navigator.clipboard?.writeText)try{await navigator.clipboard.writeText(n)}catch{}}reviveClipboardObject(t){const e=new se(this._core),{__children__:n,...i}=t,r=e.revive(i);if(!r)return null;if(n&&p.isInstanceOf(r,"KritzelGroup")){const t=n.map((t=>this.reviveClipboardObject(t))).filter((t=>null!=t));r._pendingChildren=t,r.childIds=t.map((t=>t.id))}return r}regenerateIdsAndRemapAnchors(t){const e=[],n=t.length>0&&t.every((t=>p.isInstanceOf(t,"KritzelLine"))),i=t=>{for(const n of t)e.push(n),p.isInstanceOf(n,"KritzelGroup")&&i(n._pendingChildren)};i(t);const r=new Map;for(const t of e){const e=t.generateId();r.set(t.id,e),t.id=e,t.isMounted=!1}for(const t of e)p.isInstanceOf(t,"KritzelGroup")&&(t.childIds=t.childIds.map((t=>r.get(t)??t))),p.isInstanceOf(t,"KritzelLine")&&(t.startAnchor&&r.has(t.startAnchor.objectId)?t.startAnchor={objectId:r.get(t.startAnchor.objectId)}:n&&(t.startAnchor=void 0),t.endAnchor&&r.has(t.endAnchor.objectId)?t.endAnchor={objectId:r.get(t.endAnchor.objectId)}:n&&(t.endAnchor=void 0))}async determinePasteIntent(t){if(t?.clipboardData){const e=t.clipboardData,n=Array.from(e.files??[]).filter((t=>t.type.startsWith("image/")));if(n.length>0)return{type:"image_files",files:n};if(e.types.includes("text/plain")){const t=this.determineTextPasteIntent(e.getData("text/plain"));if(t)return t}return{type:"unknown"}}if("undefined"==typeof navigator||!navigator.clipboard)return{type:"unknown"};const{clipboard:e}=navigator;if("granted"!==await this._core.permissionManager.checkPermission("clipboard-read")&&"granted"!==await this._core.permissionManager.requestPermission("clipboard-read"))return{type:"unknown"};if(e.read)try{const t=await e.read(),{imageFiles:n,text:i}=await this.processClipboardItems(t);if(n.length>0)return{type:"image_files",files:n};if(null!==i){const t=this.determineTextPasteIntent(i);if(t)return t}}catch{}if(e.readText){const t=this.determineTextPasteIntent(await e.readText());if(t)return t}return{type:"unknown"}}async processClipboardItems(t){const e=[];let n=null;return await Promise.all(t.map((async t=>{const i=t.types.find((t=>t.startsWith("image/")));if(i){const n=await t.getType(i);e.push(new File([n],"pasted-image",{type:i}))}else if(null===n&&t.types.includes("text/plain")){const e=await t.getType("text/plain");n=await e.text()}}))),{imageFiles:e,text:n}}copy(t){const e=this._core.store.selectionGroup;if(!e)return;const n={version:1,sourceWorkspaceId:this._core.store.state.activeWorkspace?.id,objects:e.objects.sort(((t,e)=>t.zIndex-e.zIndex)).map((t=>this.serializeForClipboard(t)))};this._pasteOffset=0,this.writeBrowserClipboardPayload(n,t)}cut(t){this._core.store.selectionGroup&&(this.copy(t),this._core.delete())}materializeKritzelObjects(t){const e=t.payload.objects.map((t=>this.reviveClipboardObject(t))).filter((t=>null!=t));return this.regenerateIdsAndRemapAnchors(e),e}async materializeImageFiles(t){try{const e=25/this._core.store.state.scale,n=t.files.map((async(t,n)=>{const i=await _t(t,{maxWidthOrHeight:1200});return u.fromBlob(this._core,i,{translateX:n*e,translateY:n*e})}));return await Promise.all(n)}catch(t){return console.error("Failed to import pasted image files:",t),null}}async materializePlainText(t){const e=b.create(this._core),n=t.text.split("\n").map((t=>0===t.length?{type:"paragraph"}:{type:"paragraph",content:[{type:"text",text:t}]}));return e.setContent({type:"doc",content:n}),[e]}async paste(t,e,n){const i=await this.determinePasteIntent(n);let r=null;"kritzel_objects"===i.type?r=this.materializeKritzelObjects(i):"image_files"===i.type?r=await this.materializeImageFiles(i):"plain_text"===i.type&&(r=await this.materializePlainText(i)),r&&0!==r.length&&await this.insertMaterializedObjects(r,i,t,e)}async insertMaterializedObjects(t,e,n,i){const r=this._core.store.state.activeWorkspace;if(!r)return;const s=t.some((t=>t.workspaceId!==r.id))||"kritzel_objects"!==e.type,o=void 0!==n&&void 0!==i,a=Math.min(...t.map((t=>t.translateX))),c=Math.min(...t.map((t=>t.translateY)));let l,u;const f=25/this._core.store.state.scale;void 0!==n&&void 0!==i?(l=n,u=i):s?(l=a,u=c):(l=a+f+this._pasteOffset,u=c+f+this._pasteOffset,this._pasteOffset+=f);const d=l-a,g=u-c;this._core.removeSelectionGroup(),this._core.removeSelectionBox();const v=h.create(this._core),w=this._core.store.currentZIndex;this._core.store.objects.transaction((()=>{const e=(t,n)=>{if(0===t._pendingChildren.length)return;const i=t._pendingChildren;t._pendingChildren=[],i.forEach(((t,i)=>{t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+d,t.translateY+g),t.zIndex=n+i+1,p.isInstanceOf(t,"KritzelGroup")&&e(t,t.zIndex),this._core.addObject(t)})),t.finalize()},n=[];t.forEach(((t,i)=>{t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+d,t.translateY+g),t.zIndex=w+i,p.isInstanceOf(t,"KritzelGroup")&&e(t,t.zIndex),this._core.addObject(t),n.push(t),v.addOrRemove(t)})),this._core.engine.emitObjectsAdded(n)})),this._core.anchorManager.rebuildIndex(),v.isSelected=!0,1===t.length&&(v.rotation=t[0].rotation),s&&!o&&v.centerInViewport(),this._core.addSelectionGroup(v),this._core.engine.viewport?.bringIntoViewIfNeeded(v),this._core.store.state.isSelecting=!1,await new Promise((t=>{requestAnimationFrame((()=>requestAnimationFrame((()=>t()))))})),v.refreshObjectDimensions(),s&&!o&&v.centerInViewport(),this._core.engine.emitObjectsChange(),this._core.rerender(),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection")),this._core.engine.emitObjectsChange(),this._core.rerender()}}class we{_kritzelEngine;_store;_syncConfig;_assetStorageConfig;_assetResolver;_appStateMap;_anchorManager;_cursorManager;_themeManager;_localizationManager;_licenseManager;_permissionManager;_clipboardManager;_toolRegistry;_editorId;_user;get engine(){return this._kritzelEngine}get store(){return this._store}get appStateMap(){return this._appStateMap}get anchorManager(){return this._anchorManager}get cursorManager(){return this._cursorManager}get themeManager(){return this._themeManager}get localizationManager(){return this._localizationManager}get licenseManager(){return this._licenseManager}get permissionManager(){return this._permissionManager}get toolRegistry(){return this._toolRegistry}get clipboardManager(){return this._clipboardManager}get editorId(){return this._editorId}getStorageKey(t){return this._editorId?`${t}-${this._editorId}`:t}get user(){return this._user}setUser(t){this._user=t,this._store.setLocalUserId(t?.id??null),this._store.objects?.setLocalUser(t)}constructor(t,e){this._kritzelEngine=t,this._editorId=e,this._store=new ue(oe),this._appStateMap=new fe,this._anchorManager=new Bt(this),this._cursorManager=new de(this),this._themeManager=new S(this),this._localizationManager=new Vt(this),this._licenseManager=new Nt(this),this._permissionManager=new pe(this),this._clipboardManager=new ve(this),this._toolRegistry=new ce(this),this._assetResolver=new k,this._assetResolver.setShowInfo(this._store.state.debugInfo?.showAssetResolverInfo??!1)}get assetResolver(){return this._assetResolver}setSyncConfig(t){this._syncConfig=t}setAssetStorageConfig(t){this._assetStorageConfig=t}setEditorId(t){this._editorId=t,this._themeManager=new S(this),this._localizationManager=new Vt(this)}async initializeYjs(){await this._appStateMap.initialize(this,this._syncConfig)}async initializeAssetStorage(){await this._assetResolver.init(this._assetStorageConfig),this.warnIfAssetStorageMismatched()}warnIfAssetStorageMismatched(){this._appStateMap.hasNetworkSyncProvider&&(this._assetResolver.hasRemoteProvider||console.warn("[Kritzel] A network sync provider is configured, but no remote asset storage provider was found. Images added on this device will only be available locally and will appear broken on other devices. Configure a remote asset provider (e.g. HttpAssetProvider) via the `assetStorage` prop to enable cross-device image sync."))}loadWorkspacesFromAppState(){return this._appStateMap.allWorkspaces()}saveWorkspaceToAppState(t){this._appStateMap.has(t.id)?this._appStateMap.update(t):this._appStateMap.insert(t)}deleteWorkspaceFromAppState(t){this._appStateMap.remove((e=>e.id===t))}async initializeWorkspace(t,e){const n=this.loadWorkspacesFromAppState(),i=!t&&!!this._editorId,r=n.length>0?[...n].sort(((t,e)=>{const n=e.createdAt.getTime()-t.createdAt.getTime();return 0!==n?n:e.updatedAt.getTime()-t.updatedAt.getTime()}))[0]:null,s=localStorage.getItem(this.getStorageKey("kritzel-active-workspace-id")),o=s?n.find((t=>t.id===s)):null;let a;if(t)a=t,n.find((e=>e.id===t.id))||(a._core=this,this.saveWorkspaceToAppState(a));else if(o)a=o;else if(r&&!i)a=r;else{if(e?.skipFallbackCreation)return this._store.state.workspaces=n,this._store.state.activeWorkspace=null,void this.rerender();a=new T(R.generateUUID(),"New Workspace"),a._core=this,this.saveWorkspaceToAppState(a)}localStorage.setItem(this.getStorageKey("kritzel-active-workspace-id"),a.id),this._store.objects&&this._store.objects.isReady&&this._store.objects.destroy();const c=new he;this._store.state.objects=c,this._store.state.activeWorkspace=a,this._store.state.workspaces=this.loadWorkspacesFromAppState();const l=a.viewport??{centerWorldX:0,centerWorldY:0,scale:1},h=l.scale??1,u=this._store.state.viewportHeight;this._store.state.translateX=this._store.state.viewportWidth/2-(l.centerWorldX??0)*h,this._store.state.translateY=u/2-(l.centerWorldY??0)*h,this._store.state.scale=h,await c.initialize(this,a.id,this._syncConfig),this._user&&c.setLocalUser(this._user),c.onAwarenessChange((t=>{this.engine.emitAwarenessChange(t)})),this._anchorManager.rebuildIndex(),this.engine.emitObjectsChange(),this.rerender()}async loadSharedWorkspace(t){const e=t;let n=this.getWorkspaces().find((t=>t.id===e));n?n.isPublic=!0:(n=new T(e,"Shared Workspace"),n.isPublic=!0,this.createWorkspace(n)),await this.initializeWorkspace(n)}getObjectsInViewport(){return this._store.objects?this._store.objects.query({x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,z:this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale,depth:100}).filter((t=>!(t instanceof h||t instanceof g))).sort(((t,e)=>t.zIndex-e.zIndex)):[]}rerender(){this._kritzelEngine&&this._kritzelEngine.forceUpdate++}findObjectById(t){for(const e of this._store.allObjects)if(e.id===t)return e;return null}getWorkspaces(){return this.loadWorkspacesFromAppState()}createWorkspace(t){t._core=this,t.createdAt=new Date,t.updatedAt=new Date,this.saveWorkspaceToAppState(t),this._store.state.workspaces=this.loadWorkspacesFromAppState()}updateWorkspace(t){t.updatedAt=new Date,this.saveWorkspaceToAppState(t),this._store.state.activeWorkspace?.id===t.id&&this._store.objects?.setWorkspaceName(t.name);const e=this._store.state.workspaces,n=e.findIndex((e=>e.id===t.id));-1!==n&&(e[n]=t,this._store.state.workspaces=e)}deleteWorkspace(t){this._store.state.activeWorkspace?.id===t.id&&(this.engine.viewport?.cancelPendingUpdates(),this._store.objects?.destroy()),this.deleteWorkspaceFromAppState(t.id),this._store.state.workspaces=this.loadWorkspacesFromAppState(),window.indexedDB.deleteDatabase(this._editorId?`kritzel-workspace-${this._editorId}-${t.id}`:`kritzel-workspace-${t.id}`)}updateWorkspaceViewport(t,e,n){const i=this._store.state.activeWorkspace;i&&this._store.state.workspaces.some((t=>t.id===i.id))&&(i.viewport={centerWorldX:(this._store.state.viewportWidth/2-t)/n,centerWorldY:(this._store.state.viewportHeight/2-e)/n,scale:n},i.updatedAt=new Date,this.saveWorkspaceToAppState(i))}getIsPublic(){return this._store.state.activeWorkspace?.isPublic??!1}addObject(t){this._store.objects.insert(t)}removeObject(t,e=!1){p.isInstanceOf(t,"KritzelGroup")&&!e&&[...t.children].forEach((t=>{this.removeObject(t)})),p.isInstanceOf(t,"KritzelCustomElement")&&t.unmount(),p.isInstanceOf(t,"KritzelLine")?this._anchorManager.handleLineDeleted(t.id):this._anchorManager.handleObjectDeleted(t.id),t.isMounted=!1,this._store.objects.remove((e=>e.id===t.id))}updateObject(t,e){const n=[];for(const i in e)if(e.hasOwnProperty(i)){const r=e[i];void 0!==r&&(t[i]=r,n.push(i))}t.onAfterUpdate(n),this._store.objects.update(t)}addSelectionGroup(t){this.removeLocalSelectionGroups(),this.removeSelectionBox();for(const e of t.objects??[])if(p.isInstanceOf(e,"KritzelCustomElement")){const t=e;"function"==typeof t.setIsInteractive?t.setIsInteractive(!0):t.isInteractive=!0}this._store.objects.insert(t),this._store.setSelectionGroup(t),this._kritzelEngine.triggerSelectionChange()}isLocalSelectionGroup(t){const e=this._user?.id;return null==e||t.userId===e||null==t.userId}teardownSelectionGroup(t){t.deselectAllChildren?.();for(const e of t.objects??[])if(p.isInstanceOf(e,"KritzelCustomElement")){const t=e;"function"==typeof t.setIsInteractive?t.setIsInteractive(!1):t.isInteractive=!1}}removeLocalSelectionGroups(){const t=this._store.objects.allObjects().filter((t=>t instanceof h||p.isInstanceOf(t,"KritzelSelectionGroup"))).filter((t=>this.isLocalSelectionGroup(t))),e=this._store.selectionGroup;if(e&&this.isLocalSelectionGroup(e)&&!t.some((t=>t.id===e.id))&&t.push(e),0===t.length)return!1;for(const e of t)this.teardownSelectionGroup(e);const n=new Set(t.map((t=>t.id)));return this._store.objects.remove((t=>n.has(t.id))),this._store.setSelectionGroup(null),!0}removeSelectionGroup(){this.removeLocalSelectionGroups()&&this._kritzelEngine.triggerSelectionChange()}removeSelectionBox(){const t=this._store.selectionBox;t&&(this._store.objects.remove((e=>e.id===t.id)),this._store.setSelectionBox(null),this._store.objects.clearLocalSelectionBox())}deselectAllObjects(){this.removeSelectionGroup(),this.rerender()}delete(){const t=this._store.selectionGroup;t&&(this._store.objects.stopUndoCapturing(),this._store.objects.transaction((()=>{t.objects.forEach((t=>this.removeObject(t))),this.removeSelectionGroup()})),this._store.objects.stopUndoCapturing(),this.engine.emitObjectsInViewportChange(),this.rerender())}undo(){this._store.objects?.undo()}redo(){this._store.objects?.redo()}deleteObject(t){const e=this.findObjectById(t);e&&(this.removeObject(e),this.engine.emitObjectsInViewportChange(),this.rerender())}bringForward(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=i.length>0?Math.max(...i.map((t=>t.zIndex)))+1:0;n.forEach((t=>{t.zIndex!==r&&this.updateObject(t,{zIndex:t.zIndex+1})})),this.rerender()}sendBackward(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=i.length>0?Math.min(...i.map((t=>t.zIndex)))-1:0;n.forEach((t=>{t.zIndex!==r&&this.updateObject(t,{zIndex:t.zIndex-1})})),this.rerender()}bringToFront(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=Math.max(...i.map((t=>t.zIndex)))+1;n.forEach((t=>{this.updateObject(t,{zIndex:r})})),this.rerender()}sendToBack(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=Math.min(...i.map((t=>t.zIndex)))-1;n.forEach((t=>{this.updateObject(t,{zIndex:r})})),this.rerender()}alignObjects(t){const e=this._store.selectionGroup;if(!e||e.objects.length<2)return;const n=e.objects,i=ae.calculateAlignedPositions(n,t);this._store.objects.transaction((()=>{for(const t of n){const e=i.get(t.id);e&&this.updateObject(t,{translateX:e.translateX,translateY:e.translateY})}})),e.refreshObjectDimensions(),this.rerender()}group(){const t=this._store.selectionGroup;if(!t||t.objects.length<2)return;const e=y.createFromObjects(this,t.objects);this.addObject(e),this.removeSelectionGroup();const n=h.create(this);n.addOrRemove(e),n.isSelected=!0,n.rotation=e.rotation,this.addSelectionGroup(n),this.engine.emitObjectsChange(),this.rerender()}ungroup(){const t=this._store.selectionGroup;if(!t)return;const e=t.objects.filter((t=>p.isInstanceOf(t,"KritzelGroup")));if(0===e.length)return;const n=[],i=t.objects.filter((t=>!p.isInstanceOf(t,"KritzelGroup")));e.forEach((t=>{const e=t.ungroup();n.push(...e),this.removeObject(t,!0)})),this.removeSelectionGroup();const r=h.create(this);[...n,...i].forEach((t=>{r.addOrRemove(t)})),r.isSelected=!0,this.addSelectionGroup(r),this.engine.emitObjectsChange(),this.rerender()}selectObjects(t){if(0===t.length)return;const e=h.create(this);t.forEach((t=>{t.isSelected=!1,e.addOrRemove(t)})),e.isSelected=!0,1===t.length&&(e.rotation=e.objects[0].rotation),this.addSelectionGroup(e),this.rerender()}selectAllObjects(){const t=this._store.objects.allObjects().filter((t=>!(t instanceof h||t instanceof g||t instanceof B)));if(t.length>0){const e=h.create(this);t.forEach((t=>{t.isSelected=!1,e.addOrRemove(t)})),e.isSelected=!0,this._store.state.isSelecting=!1,1===t.length&&(e.rotation=e.objects[0].rotation),this.addSelectionGroup(e),this._store.setState("activeTool",this._toolRegistry.getTool("selection")),this.rerender()}}selectAllObjectsInViewport(){const t=this._store.objects.query({x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,z:this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale,depth:100}).filter((t=>t.isInViewport())).filter((t=>!(t instanceof h||t instanceof g||t instanceof B)));if(t.length>0){const e=h.create(this);t.forEach((t=>{t.isSelected=!1,e.addOrRemove(t)})),e.isSelected=!0,this._store.state.isSelecting=!1,1===t.length&&(e.rotation=e.objects[0].rotation),this.addSelectionGroup(e),this._store.setState("activeTool",this._toolRegistry.getTool("selection")),this.rerender()}}clearSelection(){this.removeSelectionGroup();const t=this._user?.id;this._store.objects.remove((e=>e instanceof g||e instanceof h&&(null==t||e.userId===t||null==e.userId))),this._store.setSelectionBox(null),this._store.setSelectionGroup(null);for(const t of this._store.allNonSelectionObjects)t.isSelected&&(t.isSelected=!1);this._store.state.isSelecting=!1,this._store.state.isResizeHandleSelected=!1,this._store.state.isRotationHandleSelected=!1,this._store.state.isLineHandleSelected=!1,this._store.state.isLineHandleDragging=!1,this._store.state.lineHandleType=void 0,this.rerender()}resetActiveText(){const t=this._store.activeText;t&&(t.isEmpty?this.deleteObject(t.id):t.save())}resetActiveShape(){const t=this._store.activeShape;t&&t.save()}getObjectFromPointerEvent(t,e=".object"){const n=this._store.state.host?.shadowRoot;if(!n)return null;const i=t.clientX,r=t.clientY,s=n.elementFromPoint(i,r);if(!s)return null;const o=s.closest(e);if(o){const t=this._store.allObjects.find((t=>o.id===t.id));return t&&t.hitTest(i,r)?t:null}return null}getObjectsFromPointerEvent(t,e=".object"){const n=this._store.state.host?.shadowRoot;if(!n)return[];const i=n.elementsFromPoint(t.clientX,t.clientY);if(!i||0===i.length)return[];const r=new Set;return i.forEach((t=>{const n=t.closest(e);n&&n.id&&r.add(n.id)})),r.size>0?this._store.allObjects.filter((t=>r.has(t.id))).sort(((t,e)=>e.zIndex-t.zIndex)):[]}getElementsAtPoint(t,e){const n=this._store.state.host?.shadowRoot;if(!n)return[];const i=n.elementsFromPoint(t.clientX,t.clientY);return i&&0!==i.length?i.filter((t=>t.matches(e))):[]}isPointerOverElement(t,e){return this.getElementsAtPoint(t,e).length>0}getCanvasPoint(t){if(!this._store.state.host)return{x:0,y:0};const e=this._store.state.host.getBoundingClientRect();return{x:(t.clientX-e.left-this._store.state.translateX)/this._store.state.scale,y:(t.clientY-e.top-this._store.state.translateY)/this._store.state.scale}}beforeWorkspaceChange(){this._kritzelEngine.viewport?.cancelPendingUpdates(),this._store.state.activeWorkspace&&this.updateWorkspaceViewport(this._store.state.translateX,this._store.state.translateY,this._store.state.scale),this.resetActiveText(),this.clearSelection(),this._store.setState("activeTool",this._toolRegistry.getTool("selection"))}displaySelectionGroupUI(t){if(!t.isSelected)return!1;if(t instanceof h&&null!=this._user?.id&&null!=t.userId&&t.userId!==this._user.id)return!0;const e=this._store.selectionGroup;return e?t instanceof h&&t.id===e.id&&(e.objects.length>1||(1!==e.objects.length||!(e.objects[0]instanceof L))):!(t instanceof L)}displaySelectionLineUI(t){if(!(t instanceof L))return!1;const e=this._store.selectionGroup;if(!e)return t.isSelected;if(!e.isSelected)return!1;if(1===e.objects.length){const n=e.objects[0];return n instanceof L&&n.id===t.id}return!1}}class me{static calculateCombinedBounds(t){if(!t||0===t.length)return null;let e=1/0,n=1/0,i=-1/0,r=-1/0;for(const s of t){const t=s.rotatedBoundingBox;e=Math.min(e,t.x),n=Math.min(n,t.y),i=Math.max(i,t.x+t.width),r=Math.max(r,t.y+t.height)}return{x:e,y:n,z:1,width:i-e,height:r-n}}static generateSvg(t,e={}){const{theme:n,padding:i=0,includeXmlDeclaration:r=!0,rasterSafeForCanvas:s=!1,imageDataUrls:o}=e;if(!t||0===t.length)return"";const a=this.flattenObjects(t),c=this.calculateCombinedBounds(a);if(!c)return"";const l=c.x-i,h=c.y-i,u=c.width+2*i,f=c.height+2*i,d=this.collectDefs(a,n),p=t.sort(((t,e)=>t.zIndex-e.zIndex)).map((t=>this.objectToSvgElement(t,n,o,s))).filter(Boolean).join("\n ");return`${r?'<?xml version="1.0" encoding="UTF-8"?>\n':""}<svg xmlns="http://www.w3.org/2000/svg" viewBox="${l} ${h} ${u} ${f}" width="${u}" height="${f}">${d.length>0?`\n <defs>\n ${d.join("\n ")}\n </defs>`:""}\n ${p}\n</svg>`}static flattenObjects(t){const e=[];for(const n of t)p.isInstanceOf(n,"KritzelGroup")?e.push(...this.flattenObjects(n.children)):e.push(n);return e}static async resolveImageDataUrls(t,e){const n=new Map;if(!t||0===t.length)return n;const i=this.flattenObjects(t).filter((t=>p.isInstanceOf(t,"KritzelImage")));return await Promise.all(i.map((async t=>{if(t.src?.startsWith("data:"))n.set(t.id,t.src);else if(t.resolvedSrc?.startsWith("data:"))n.set(t.id,t.resolvedSrc);else if(t.assetId&&e)try{const i=await e.fetchBlob(t.assetId);n.set(t.id,await this.blobToDataUrl(i))}catch(e){console.warn(`[KritzelSvgExportHelper] Failed to inline image asset ${t.assetId} for export:`,e)}}))),n}static async blobToDataUrl(t){if("undefined"!=typeof FileReader)try{return await new Promise(((e,n)=>{const i=new FileReader;i.onload=()=>{"string"!=typeof i.result?n(new Error("FileReader result is not a string")):e(i.result)},i.onerror=()=>n(i.error??new Error("Failed to read blob as data URL")),i.readAsDataURL(t)}))}catch{}const e=new Uint8Array(await t.arrayBuffer());return`data:${t.type||"application/octet-stream"};base64,${this.uint8ToBase64(e)}`}static uint8ToBase64(t){if("undefined"!=typeof Buffer)return Buffer.from(t).toString("base64");let e="";for(let n=0;n<t.length;n+=32768){const i=t.subarray(n,Math.min(n+32768,t.length));e+=String.fromCharCode(...i)}if("function"==typeof btoa)return btoa(e);throw new Error("No base64 encoder available in this runtime")}static collectDefs(t,e){const n=[];for(const i of t)p.isInstanceOf(i,"KritzelLine")&&(i.hasStartArrow&&n.push(this.generateArrowMarker(i,"start",e)),i.hasEndArrow&&n.push(this.generateArrowMarker(i,"end",e)));return n}static generateArrowMarker(t,e,n){const i="start"===e?t.startMarkerId:t.endMarkerId,r=t.getArrowSize(e),s=t.getArrowFill(e);return`<marker id="${i}" markerWidth="${r}" markerHeight="${r}" refX="0" refY="${r/2}" orient="${"start"===e?"auto-start-reverse":"auto"}" markerUnits="userSpaceOnUse">\n <path d="${t.getArrowPath("start"===e?t.arrows?.start?.style:t.arrows?.end?.style)}" fill="${s}" transform="scale(${r/10})"/>\n </marker>`}static objectToSvgElement(t,e,n,i=!1){return p.isInstanceOf(t,"KritzelPath")?this.pathToSvg(t,e):p.isInstanceOf(t,"KritzelLine")?this.lineToSvg(t,e):p.isInstanceOf(t,"KritzelShape")?this.shapeToSvg(t,e):p.isInstanceOf(t,"KritzelText")?this.textToSvg(t,e,i):p.isInstanceOf(t,"KritzelImage")?this.imageToSvg(t,n):p.isInstanceOf(t,"KritzelCustomElement")?this.customElementToSvg(t,i):p.isInstanceOf(t,"KritzelGroup")?this.groupToSvg(t,e,n,i):""}static pathToSvg(t,e){const n=this.buildTransform(t),i=M.resolveThemeColor(t.fill,e),r=M.resolveThemeColor(t.stroke,e),s=1!==t.opacity?` opacity="${t.opacity}"`:"",o=this.getObjectScale(t);return`<g transform="${n}"${s}>\n <svg viewBox="${t.viewBox}" width="${t.totalWidth/o}" height="${t.totalHeight/o}" overflow="visible">\n <path d="${t.d}" fill="${i||"none"}" stroke="${r||"none"}"${t.strokeWidth?` stroke-width="${t.strokeWidth}"`:""}/>\n </svg>\n </g>`}static lineToSvg(t,e){const n=this.buildTransform(t),i=M.resolveThemeColor(t.stroke,e),r=1!==t.opacity?` opacity="${t.opacity}"`:"",s=this.getObjectScale(t);return`<g transform="${n}"${r}>\n <svg viewBox="${t.viewBox}" width="${t.totalWidth/s}" height="${t.totalHeight/s}" overflow="visible">\n <path d="${t.d}" fill="none" stroke="${i}" stroke-width="${t.strokeWidth}" stroke-linecap="round"${t.hasStartArrow?` marker-start="url(#${t.startMarkerId})"`:""}${t.hasEndArrow?` marker-end="url(#${t.endMarkerId})"`:""}/>\n </svg>\n </g>`}static shapeToSvg(t,e){const n=this.buildTransform(t),i=M.resolveThemeColor(t.fillColor,e),r=M.resolveThemeColor(t.strokeColor,e),s=1!==t.opacity?` opacity="${t.opacity}"`:"",o=this.getObjectScale(t),a=t.getSvgPath();let c="";if(t.editor&&!t.editor.state.doc.textContent.trim());else if(t.content){const n=this.prosemirrorToHtml(t.content,t,e);if(n){const i=M.resolveThemeColor(t.fontColor,e);c=`\n <foreignObject x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}">\n <div xmlns="http://www.w3.org/1999/xhtml" style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; font-family: ${t.fontFamily}; font-size: ${t.fontSize}px; color: ${i}; overflow: hidden;">\n ${n}\n </div>\n </foreignObject>`}}return`<g transform="${n}"${s}>\n <svg viewBox="${t.viewBox}" width="${t.totalWidth/o}" height="${t.totalHeight/o}" overflow="visible" preserveAspectRatio="none">\n <path d="${a}" fill="${i||"transparent"}" stroke="${r}" stroke-width="${t.strokeWidth}"/>${c}\n </svg>\n </g>`}static textToSvg(t,e,n=!1){if(n)return this.textToSvgRasterSafe(t,e);const i=this.buildTransform(t),r=1!==t.opacity?` opacity="${t.opacity}"`:"",s=M.resolveThemeColor(t.fontColor,e),o=M.resolveThemeColor(t.backgroundColor,e),a=this.getObjectScale(t),c=this.prosemirrorToHtml(t.content,t,e);return`<g transform="${i}"${r}>\n <foreignObject x="0" y="0" width="${t.totalWidth/a}" height="${t.totalHeight/a}">\n <div xmlns="http://www.w3.org/1999/xhtml" style="font-family: ${t.fontFamily}; font-size: ${t.fontSize}pt; color: ${s}; background-color: ${o||"transparent"}; transform: scale(${t.scaleFactor}); transform-origin: top left; white-space: pre-wrap; word-wrap: break-word;">\n ${c}\n </div>\n </foreignObject>\n </g>`}static textToSvgRasterSafe(t,e){const n=this.buildTransform(t),i=1!==t.opacity?` opacity="${t.opacity}"`:"",r=M.resolveThemeColor(t.fontColor,e),s=M.resolveThemeColor(t.backgroundColor,e),o=this.getObjectScale(t),a=t.totalWidth/o,c=t.totalHeight/o,l=this.prosemirrorToPlainTextLines(t.content),h=l.length>0?l:[""],u=Math.max(1,t.fontSize*(t.scaleFactor||1)),f=1.2*u,d=u,p=s&&"transparent"!==s?`<rect x="0" y="0" width="${a}" height="${c}" fill="${s}"/>`:"",g=h.map(((t,e)=>`<tspan x="0" y="${d+e*f}" xml:space="preserve">${this.escapeHtml(t)}</tspan>`)).join("");return`<g transform="${n}"${i}>\n ${p}\n <text font-family="${this.escapeHtml(t.fontFamily)}" font-size="${u}" fill="${r}">${g}</text>\n </g>`}static imageToSvg(t,e){const n=this.buildTransform(t),i=1!==t.opacity?` opacity="${t.opacity}"`:"",r=this.getObjectScale(t),s=t.totalWidth/r,o=t.totalHeight/r;return`<g transform="${n}"${i}>\n <image href="${e?.get(t.id)||t.resolvedSrc||t.src||""}" x="0" y="0" width="${s}" height="${o}" preserveAspectRatio="xMidYMid meet"/>\n </g>`}static customElementToSvg(t,e=!1){const n=this.buildTransform(t),i=1!==t.opacity?` opacity="${t.opacity}"`:"",r=this.getObjectScale(t),s=t.totalWidth/r,o=t.totalHeight/r;return e?(console.warn("[KritzelCustomElement SVG Export] Custom elements do not serialize well to PNG. Use SVG export or screenshot instead."),`<g transform="${n}"${i}>\n <rect x="0" y="0" width="${s}" height="${o}" fill="#f0f0f0" stroke="#999" stroke-width="1" />\n <text x="${s/2}" y="${o/2}" text-anchor="middle" dominant-baseline="middle" font-size="12" fill="#999">[Custom Element]</text>\n </g>`):`<g transform="${n}"${i}>\n <foreignObject x="0" y="0" width="${s}" height="${o}">\n <div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;">\n ${t.element?.outerHTML||'<div style="border:1px dashed #ccc">Empty</div>'}\n </div>\n </foreignObject>\n </g>`}static groupToSvg(t,e,n,i=!1){const r=t.children.sort(((t,e)=>t.zIndex-e.zIndex)).map((t=>this.objectToSvgElement(t,e,n,i))).filter(Boolean).join("\n ");return r?`<g${1!==t.opacity?` opacity="${t.opacity}"`:""}>\n ${r}\n </g>`:""}static buildTransform(t){const e=[],n=this.getObjectScale(t);if(e.push(`translate(${t.translateX}, ${t.translateY})`),0!==t.rotation){const i=t.rotation*(180/Math.PI);e.push(`rotate(${i}, ${t.totalWidth/2/n}, ${t.totalHeight/2/n})`)}return e.join(" ")}static getObjectScale(t){const e=t.scale??1;return 0===e?1:e}static prosemirrorToHtml(t,e,n){return t&&t.content?t.content.map((t=>this.nodeToHtml(t,n))).join(""):""}static nodeToHtml(t,e){if(!t)return"";switch(t.type){case"paragraph":return`<p style="margin: 0;">${(t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):"")||"<br/>"}</p>`;case"text":let n=this.escapeHtml(t.text||"");if(t.marks)for(const i of t.marks)n=this.applyMark(n,i,e);return n;case"hard_break":return"<br/>";case"bullet_list":return`<ul style="margin: 0; padding-left: 1.5em;">${t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}</ul>`;case"ordered_list":return`<ol style="margin: 0; padding-left: 1.5em;">${t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}</ol>`;case"list_item":return`<li>${t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}</li>`;default:return t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}}static prosemirrorToPlainTextLines(t){if(!t||!Array.isArray(t.content))return[];const e=t.content.map((t=>this.nodeToPlainText(t))).join("").replace(/\r\n/g,"\n").replace(/\n+$/,"");return e?e.split("\n"):[]}static nodeToPlainText(t){if(!t)return"";switch(t.type){case"text":return t.text||"";case"hard_break":return"\n";case"paragraph":return`${Array.isArray(t.content)?t.content.map((t=>this.nodeToPlainText(t))).join(""):""}\n`;case"list_item":return`- ${(Array.isArray(t.content)?t.content.map((t=>this.nodeToPlainText(t))).join(""):"").trim()}\n`;default:return Array.isArray(t.content)?t.content.map((t=>this.nodeToPlainText(t))).join(""):""}}static applyMark(t,e,n){switch(e.type){case"bold":case"strong":return`<strong>${t}</strong>`;case"italic":case"em":return`<em>${t}</em>`;case"underline":return`<u>${t}</u>`;case"strike":return`<s>${t}</s>`;case"code":return`<code>${t}</code>`;case"link":return`<a href="${this.escapeHtml(e.attrs?.href||"#")}">${t}</a>`;default:return t}}static escapeHtml(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}}const ye=(()=>{let t=0;return()=>(t+=1,`u${`0000${(Math.random()*36**4|0).toString(36)}`.slice(-4)}${t}`)})();function be(t){const e=[];for(let n=0,i=t.length;n<i;n++)e.push(t[n]);return e}let ke=null;function Ae(t={}){return ke||(t.includeStyleProperties?(ke=t.includeStyleProperties,ke):(ke=be(window.getComputedStyle(document.documentElement)),ke))}function xe(t,e){const n=(t.ownerDocument.defaultView||window).getComputedStyle(t).getPropertyValue(e);return n?parseFloat(n.replace("px","")):0}function Se(t,e={}){return{width:e.width||function(t){const e=xe(t,"border-left-width"),n=xe(t,"border-right-width");return t.clientWidth+e+n}(t),height:e.height||function(t){const e=xe(t,"border-top-width"),n=xe(t,"border-bottom-width");return t.clientHeight+e+n}(t)}}const Me=16384;function ze(t){return new Promise(((e,n)=>{const i=new Image;i.onload=()=>{i.decode().then((()=>{requestAnimationFrame((()=>e(i)))}))},i.onerror=n,i.crossOrigin="anonymous",i.decoding="async",i.src=t}))}const $e=(t,e)=>{if(t instanceof e)return!0;const n=Object.getPrototypeOf(t);return null!==n&&(n.constructor.name===e.name||$e(n,e))};function Ce(t,e,n,i){const r=window.getComputedStyle(t,n),s=r.getPropertyValue("content");if(""===s||"none"===s)return;const o=ye();try{e.className=`${e.className} ${o}`}catch(t){return}const a=document.createElement("style");a.appendChild(function(t,e,n,i){const r=`.${t}:${e}`,s=n.cssText?function(t){const e=t.getPropertyValue("content");return`${t.cssText} content: '${e.replace(/'|"/g,"")}';`}(n):function(t,e){return Ae(e).map((e=>`${e}: ${t.getPropertyValue(e)}${t.getPropertyPriority(e)?" !important":""};`)).join(" ")}(n,i);return document.createTextNode(`${r}{${s}}`)}(o,n,r,i)),e.appendChild(a)}const Te="application/font-woff",Ie="image/jpeg",je={woff:Te,woff2:Te,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:Ie,jpeg:Ie,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function Ee(t){const e=function(t){const e=/\.([^./]*?)$/g.exec(t);return e?e[1]:""}(t).toLowerCase();return je[e]||""}function _e(t){return-1!==t.search(/^(data:)/)}async function Le(t,e,n){const i=await fetch(t,e);if(404===i.status)throw new Error(`Resource "${i.url}" not found`);const r=await i.blob();return new Promise(((t,e)=>{const s=new FileReader;s.onerror=e,s.onloadend=()=>{try{t(n({res:i,result:s.result}))}catch(t){e(t)}},s.readAsDataURL(r)}))}const Oe={};async function Pe(t,e,n){const i=function(t,e,n){let i=t.replace(/\?.*/,"");return n&&(i=t),/ttf|otf|eot|woff2?/i.test(i)&&(i=i.replace(/.*\//,"")),e?`[${e}]${i}`:i}(t,e,n.includeQueryParams);if(null!=Oe[i])return Oe[i];let r;n.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());try{const i=await Le(t,n.fetchRequestInit,(({res:t,result:n})=>(e||(e=t.headers.get("Content-Type")||""),function(t){return t.split(/,/)[1]}(n))));r=function(t,e){return`data:${e};base64,${t}`}(i,e)}catch(e){r=n.imagePlaceholder||"";let i=`Failed to fetch resource: ${t}`;e&&(i="string"==typeof e?e:e.message),i&&console.warn(i)}return Oe[i]=r,r}const Be=t=>null!=t.tagName&&"SLOT"===t.tagName.toUpperCase(),De=t=>null!=t.tagName&&"SVG"===t.tagName.toUpperCase();async function Re(t,e,n){return n||!e.filter||e.filter(t)?Promise.resolve(t).then((t=>async function(t,e){return $e(t,HTMLCanvasElement)?async function(t){const e=t.toDataURL();return"data:,"===e?t.cloneNode(!1):ze(e)}(t):$e(t,HTMLVideoElement)?async function(t,e){if(t.currentSrc){const e=document.createElement("canvas"),n=e.getContext("2d");return e.width=t.clientWidth,e.height=t.clientHeight,null==n||n.drawImage(t,0,0,e.width,e.height),ze(e.toDataURL())}const n=t.poster,i=Ee(n);return ze(await Pe(n,i,e))}(t,e):$e(t,HTMLIFrameElement)?async function(t,e){var n;try{if(null===(n=null==t?void 0:t.contentDocument)||void 0===n?void 0:n.body)return await Re(t.contentDocument.body,e,!0)}catch(t){}return t.cloneNode(!1)}(t,e):t.cloneNode(De(t))}(t,e))).then((n=>async function(t,e,n){var i,r;if(De(e))return e;let s=[];return s=Be(t)&&t.assignedNodes?be(t.assignedNodes()):$e(t,HTMLIFrameElement)&&(null===(i=t.contentDocument)||void 0===i?void 0:i.body)?be(t.contentDocument.body.childNodes):be((null!==(r=t.shadowRoot)&&void 0!==r?r:t).childNodes),0===s.length||$e(t,HTMLVideoElement)||await s.reduce(((t,i)=>t.then((()=>Re(i,n))).then((t=>{t&&e.appendChild(t)}))),Promise.resolve()),e}(t,n,e))).then((n=>function(t,e,n){return $e(e,Element)&&(function(t,e,n){const i=e.style;if(!i)return;const r=window.getComputedStyle(t);r.cssText?(i.cssText=r.cssText,i.transformOrigin=r.transformOrigin):Ae(n).forEach((n=>{let s=r.getPropertyValue(n);if("font-size"===n&&s.endsWith("px")){const t=Math.floor(parseFloat(s.substring(0,s.length-2)))-.1;s=`${t}px`}$e(t,HTMLIFrameElement)&&"display"===n&&"inline"===s&&(s="block"),"d"===n&&e.getAttribute("d")&&(s=`path(${e.getAttribute("d")})`),i.setProperty(n,s,r.getPropertyPriority(n))}))}(t,e,n),function(t,e,n){Ce(t,e,":before",n),Ce(t,e,":after",n)}(t,e,n),function(t,e){$e(t,HTMLTextAreaElement)&&(e.innerHTML=t.value),$e(t,HTMLInputElement)&&e.setAttribute("value",t.value)}(t,e),function(t,e){if($e(t,HTMLSelectElement)){const n=Array.from(e.children).find((e=>t.value===e.getAttribute("value")));n&&n.setAttribute("selected","")}}(t,e)),e}(t,n,e))).then((t=>async function(t,e){const n=t.querySelectorAll?t.querySelectorAll("use"):[];if(0===n.length)return t;const i={};for(let r=0;r<n.length;r++){const s=n[r].getAttribute("xlink:href");if(s){const n=t.querySelector(s),r=document.querySelector(s);n||!r||i[s]||(i[s]=await Re(r,e,!0))}}const r=Object.values(i);if(r.length){const e="http://www.w3.org/1999/xhtml",n=document.createElementNS(e,"svg");n.setAttribute("xmlns",e),n.style.position="absolute",n.style.width="0",n.style.height="0",n.style.overflow="hidden",n.style.display="none";const i=document.createElementNS(e,"defs");n.appendChild(i);for(let t=0;t<r.length;t++)i.appendChild(r[t]);t.appendChild(n)}return t}(t,e))):null}const We=/url\((['"]?)([^'"]+?)\1\)/g,Ue=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Fe=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function Ke(t){return-1!==t.search(We)}async function Ve(t,e,n){if(!Ke(t))return t;const i=function(t,{preferredFontFormat:e}){return e?t.replace(Fe,(t=>{for(;;){const[n,,i]=Ue.exec(t)||[];if(!i)return"";if(i===e)return`src: ${n};`}})):t}(t,n),r=function(t){const e=[];return t.replace(We,((t,n,i)=>(e.push(i),t))),e.filter((t=>!_e(t)))}(i);return r.reduce(((t,i)=>t.then((t=>async function(t,e,n,i){try{const r=n?function(t,e){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;const n=document.implementation.createHTMLDocument(),i=n.createElement("base"),r=n.createElement("a");return n.head.appendChild(i),n.body.appendChild(r),e&&(i.href=e),r.href=t,r.href}(e,n):e,s=Ee(e);let o;return o=await Pe(r,s,i),t.replace(function(t){const e=t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${e})(['"]?\\))`,"g")}(e),`$1${o}$3`)}catch(t){}return t}(t,i,e,n)))),Promise.resolve(i))}async function Ne(t,e,n){var i;const r=null===(i=e.style)||void 0===i?void 0:i.getPropertyValue(t);if(r){const i=await Ve(r,null,n);return e.style.setProperty(t,i,e.style.getPropertyPriority(t)),!0}return!1}async function Ge(t,e){$e(t,Element)&&(await async function(t,e){await Ne("background",t,e)||await Ne("background-image",t,e),await Ne("mask",t,e)||await Ne("-webkit-mask",t,e)||await Ne("mask-image",t,e)||await Ne("-webkit-mask-image",t,e)}(t,e),await async function(t,e){const n=$e(t,HTMLImageElement);if((!n||_e(t.src))&&(!$e(t,SVGImageElement)||_e(t.href.baseVal)))return;const i=n?t.src:t.href.baseVal,r=await Pe(i,Ee(i),e);await new Promise(((i,s)=>{t.onload=i,t.onerror=e.onImageErrorHandler?(...t)=>{try{i(e.onImageErrorHandler(...t))}catch(t){s(t)}}:s;const o=t;o.decode&&(o.decode=i),"lazy"===o.loading&&(o.loading="eager"),n?(t.srcset="",t.src=r):t.href.baseVal=r}))}(t,e),await async function(t,e){const n=be(t.childNodes).map((t=>Ge(t,e)));await Promise.all(n).then((()=>t))}(t,e))}const He={};async function Xe(t){let e=He[t];if(null!=e)return e;const n=await fetch(t);return e={url:t,cssText:await n.text()},He[t]=e,e}async function Ye(t,e){let n=t.cssText;const i=/url\(["']?([^"')]+)["']?\)/g,r=(n.match(/url\([^)]+\)/g)||[]).map((async r=>{let s=r.replace(i,"$1");return s.startsWith("https://")||(s=new URL(s,t.url).href),Le(s,e.fetchRequestInit,(({result:t})=>(n=n.replace(r,`url(${t})`),[r,t])))}));return Promise.all(r).then((()=>n))}function Qe(t){if(null==t)return[];const e=[];let n=t.replace(/(\/\*[\s\S]*?\*\/)/gi,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const t=i.exec(n);if(null===t)break;e.push(t[0])}n=n.replace(i,"");const r=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,s=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let t=r.exec(n);if(null===t){if(t=s.exec(n),null===t)break;r.lastIndex=s.lastIndex}else s.lastIndex=r.lastIndex;e.push(t[0])}return e}function Ze(t){return t.trim().replace(/["']/g,"")}async function qe(t,e){const n=await async function(t,e){if(null==t.ownerDocument)throw new Error("Provided element is not within a Document");const n=be(t.ownerDocument.styleSheets),i=await async function(t,e){const n=[],i=[];return t.forEach((n=>{if("cssRules"in n)try{be(n.cssRules||[]).forEach(((t,r)=>{if(t.type===CSSRule.IMPORT_RULE){let s=r+1;const o=Xe(t.href).then((t=>Ye(t,e))).then((t=>Qe(t).forEach((t=>{try{n.insertRule(t,t.startsWith("@import")?s+=1:n.cssRules.length)}catch(e){console.error("Error inserting rule from remote css",{rule:t,error:e})}})))).catch((t=>{console.error("Error loading remote css",t.toString())}));i.push(o)}}))}catch(r){const s=t.find((t=>null==t.href))||document.styleSheets[0];null!=n.href&&i.push(Xe(n.href).then((t=>Ye(t,e))).then((t=>Qe(t).forEach((t=>{s.insertRule(t,s.cssRules.length)})))).catch((t=>{console.error("Error loading remote stylesheet",t)}))),console.error("Error inlining remote css file",r)}})),Promise.all(i).then((()=>(t.forEach((t=>{if("cssRules"in t)try{be(t.cssRules||[]).forEach((t=>{n.push(t)}))}catch(e){console.error(`Error while reading CSS rules from ${t.href}`,e)}})),n)))}(n,e);return function(t){return t.filter((t=>t.type===CSSRule.FONT_FACE_RULE)).filter((t=>Ke(t.style.getPropertyValue("src"))))}(i)}(t,e),i=function(t){const e=new Set;return function t(n){(n.style.fontFamily||getComputedStyle(n).fontFamily).split(",").forEach((t=>{e.add(Ze(t))})),Array.from(n.children).forEach((e=>{e instanceof HTMLElement&&t(e)}))}(t),e}(t);return(await Promise.all(n.filter((t=>i.has(Ze(t.style.fontFamily)))).map((t=>Ve(t.cssText,t.parentStyleSheet?t.parentStyleSheet.href:null,e))))).join("\n")}async function Je(t,e={}){const{width:n,height:i}=Se(t,e),r=await Re(t,e,!0);return await async function(t,e){const n=null!=e.fontEmbedCSS?e.fontEmbedCSS:e.skipFonts?null:await qe(t,e);if(n){const e=document.createElement("style"),i=document.createTextNode(n);e.appendChild(i),t.firstChild?t.insertBefore(e,t.firstChild):t.appendChild(e)}}(r,e),await Ge(r,e),function(t,e){const{style:n}=t;e.backgroundColor&&(n.backgroundColor=e.backgroundColor),e.width&&(n.width=`${e.width}px`),e.height&&(n.height=`${e.height}px`);const i=e.style;null!=i&&Object.keys(i).forEach((t=>{n[t]=i[t]}))}(r,e),await async function(t,e,n){const i="http://www.w3.org/2000/svg",r=document.createElementNS(i,"svg"),s=document.createElementNS(i,"foreignObject");return r.setAttribute("width",`${e}`),r.setAttribute("height",`${n}`),r.setAttribute("viewBox",`0 0 ${e} ${n}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),r.appendChild(s),s.appendChild(t),async function(t){return Promise.resolve().then((()=>(new XMLSerializer).serializeToString(t))).then(encodeURIComponent).then((t=>`data:image/svg+xml;charset=utf-8,${t}`))}(r)}(r,n,i)}class tn{static shouldKeepWheelInCustomElement(t,e){if(t.ctrlKey||!0!==e.isSelected)return!1;const n="function"==typeof t.composedPath?t.composedPath():[],i=this.getScrollableContainerFromEventPath(n,e);return!!i&&this.canElementConsumeWheel(i,t.deltaX,t.deltaY)}static getScrollableContainerFromEventPath(t,e){const n=[];e.element instanceof HTMLElement&&n.push(e.element),e.elementRef instanceof HTMLElement&&n.push(e.elementRef);const i=e.elmeentRef;i instanceof HTMLElement&&n.push(i);for(const e of n){const n=t.findIndex((t=>t===e));if(-1!==n)for(const e of t.slice(0,n+1))if(e instanceof HTMLElement&&this.isScrollableElement(e))return e}for(const t of n){if(this.isScrollableElement(t))return t;const e=t.firstElementChild;if(e instanceof HTMLElement&&this.isScrollableElement(e))return e}return null}static isScrollableElement(t){const e=t.scrollHeight-t.clientHeight>0,n=t.scrollWidth-t.clientWidth>0;if(!e&&!n)return!1;const i=window.getComputedStyle(t),r=i.overflowX,s=i.overflowY;return e&&"visible"!==s&&"clip"!==s||n&&"visible"!==r&&"clip"!==r}static canElementConsumeWheel(t,e,n){const i=this.canElementConsumeVerticalWheel(t,n),r=this.canElementConsumeHorizontalWheel(t,e);return i||r}static canElementConsumeVerticalWheel(t,e){if(0===e)return!1;const n=Math.max(0,t.scrollHeight-t.clientHeight);return 0!==n&&(e>0?t.scrollTop<n-1:!!(e<0)&&t.scrollTop>1)}static canElementConsumeHorizontalWheel(t,e){if(0===e)return!1;const n=Math.max(0,t.scrollWidth-t.clientWidth);return 0!==n&&(e>0?t.scrollLeft<n-1:!!(e<0)&&t.scrollLeft>1)}}const en=t(class extends e{get host(){return this}workspace;async onWorkspaceChange(t){const e=t?.id;if(!e)return;await Promise.resolve();const n=this.core.store.state.activeWorkspace?.id;n!==e&&(this.core.beforeWorkspaceChange(),await this.initializeWorkspaceIfNeeded(t),this.activeWorkspaceChange.emit(this.core.store.state.activeWorkspace))}editorId;activeWorkspaceId;async onActiveWorkspaceIdChange(t){t&&this._isYjsInitialized&&await this.switchToWorkspaceById(t)}syncConfig;async onSyncConfigChange(t){this._syncConfigRevision++,this.core.setSyncConfig(t),t&&!this._isYjsInitialized&&this._isViewportReady&&await this.initializeSyncAndWorkspace()}assetStorageConfig;async onAssetStorageConfigChange(t){this._assetStorageConfigRevision++,this.core.setAssetStorageConfig(t),t&&!this._isAssetStorageInitialized&&this._isViewportReady&&await this.initializeAssetStorage()}user;onUserChange(t){this.core.setUser(t)}globalContextMenuItems;onGlobalContextMenuItemsChange(t){this.contextMenuHandler&&(this.contextMenuHandler.globalContextMenuItems=t??[])}objectContextMenuItems;onObjectContextMenuItemsChange(t){this.contextMenuHandler&&(this.contextMenuHandler.objectContextMenuItems=t??[])}scaleMax=z;validateScaleMax(t){t>z?(console.warn(`scaleMax cannot be greater than ${z}.`),this.scaleMax=z,this.core.store.state.scaleMax=this.scaleMax):this.core.store.state.scaleMax=t}scaleMin=$;validateScaleMin(t){t<$?(console.warn(`scaleMin cannot be less than ${$}.`),this.scaleMin=$,this.core.store.state.scaleMin=this.scaleMin):this.core.store.state.scaleMin=t}cursorTarget;onCursorTargetChange(t){this.core.cursorManager.setTargetElement(t||document.body)}lockDrawingScale=!0;onLockDrawingScaleChange(t){this.core.store.state.lockDrawingScale=t}isObjectDistanceFadingActive=!1;onIsObjectDistanceFadingActiveChange(){this.core.rerender()}theme="light";onThemeChange(t){this.core.themeManager.setTheme(t)}licenseKey;onLicenseKeyChange(t){this.core.licenseManager.validate(t)}themes;onThemesChange(t){t&&t.length>0&&(this.core.themeManager.registerThemes(t),this.core.themeManager.applyTheme(this.core.themeManager.currentTheme))}locale="en";onLocaleChange(t){this.core.localizationManager.setLocale(t)}locales;onLocalesChange(t){t&&t.length>0&&(this.core.localizationManager.registerLocales(t),this.core.localizationManager.setLocale(this.locale))}fallbackLocale="en";onFallbackLocaleChange(t){this.core.localizationManager.setFallbackLocale(t),this.core.rerender()}viewportBoundaryLeft=-1/0;onViewportBoundaryLeftChange(t){this.core.store.state.viewportBoundaryLeft=t??-1/0}viewportBoundaryRight=1/0;onViewportBoundaryRightChange(t){this.core.store.state.viewportBoundaryRight=t??1/0}viewportBoundaryTop=-1/0;onViewportBoundaryTopChange(t){this.core.store.state.viewportBoundaryTop=t??-1/0}viewportBoundaryBottom=1/0;onViewportBoundaryBottomChange(t){this.core.store.state.viewportBoundaryBottom=t??1/0}debugInfo;onDebugInfoChange(t){t&&(this.core.store.state.debugInfo=t,this.core.assetResolver.setShowInfo(t.showAssetResolverInfo))}isPanningEnabled=!0;isZoomingEnabled=!0;isLoading=!1;onIsLoadingChange(){this.syncLoadingState()}isEngineReady;activeToolChange;objectsSelectionChange;workspacesChange;activeWorkspaceChange;longpress;objectsChange;objectsAdded;objectsRemoved;objectsUpdated;undoStateChange;objectsInViewportChange;viewportChange;awarenessChange;notificationsChange;forceUpdate=0;async triggerSelectionChange(){this.objectsSelectionChange.emit()}handleWheel(t){if(this.core.store.isDisabled)return;this.core.store.state.isContextMenuVisible&&this.hideContextMenu();const e=this.core.getObjectFromPointerEvent(t);e&&R.isClass(e,"KritzelCustomElement")&&tn.shouldKeepWheelInCustomElement(t,e)||(t.ctrlKey?this.isZoomingEnabled&&this.viewport.handleWheel(t):this.isPanningEnabled&&this.viewport.handleWheel(t),this.core.store.state?.activeTool?.handleWheel(t))}handlePointerDown(t){this.core.store.isDisabled||this.isEmbeddedCustomElementInteraction(t)||(N.isTouchDevice()&&l.onLongPress(t,(t=>this.longpress.emit(t))),this.host.setPointerCapture(t.pointerId),this.core.store.state.pointers.set(t.pointerId,t),this.viewport.handlePointerDown(t),this.core.store.state?.activeTool?.handlePointerDown(t))}throttledPointerMoveMulti=ee.throttle((t=>{this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t)}),16);handlePointerMove(t){this.core.store.isDisabled||t.buttons>0&&!this.core.store.state.pointers.has(t.pointerId)||(this.core.store.state.pointers.has(t.pointerId)&&this.core.store.state.pointers.set(t.pointerId,t),this.core.store.state.pointers.size>1&&this.throttledPointerMoveMulti(t),this.core.cursorManager.updateHoverState(t),this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t))}handlePointerUp(t){if(this.core.store.isDisabled)return;const e=this.core.store.state.pointers.has(t.pointerId);this.core.store.state.pointers.delete(t.pointerId),this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),e&&(this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handlePointerCancel(t){this.core.store.isDisabled||(this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),this.core.store.state.pointers.delete(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}isEmbeddedCustomElementInteraction(t){const n=t.composedPath(),i=n.find((t=>t instanceof e&&t.classList.contains("object")));if(!i?.id)return!1;const r=this.core.store.objects.findById(i.id);if(!r||!p.isInstanceOf(r,"KritzelCustomElement"))return!1;if(!this.core.store.selectionGroup?.objects?.some((t=>t.id===r.id)))return!1;if(!0!==r.isInteractive)return!1;const s=[];return r.element instanceof e&&s.push(r.element),r.elementRef instanceof e&&s.push(r.elementRef),0!==s.length&&s.some((t=>this.isNativeInteractiveEmbeddedTarget(n,t)))}isNativeInteractiveEmbeddedTarget(t,n){const i=t.findIndex((t=>t===n));if(-1===i)return!1;for(const n of t.slice(0,i))if(n instanceof e&&n.matches('input, button, textarea, select, a[href], [contenteditable="true"], [contenteditable=""]'))return!0;return!1}handlePointerLeave(){this.core.store.objects?.clearCursorPosition()}handleLongPress(t){this.contextMenuHandler.handleContextMenu(t.detail)}handleContextMenu(t){t.cancelable&&t.preventDefault(),this.core.store.isDisabled||"touch"!==t.pointerType&&"pen"!==t.pointerType&&this.contextMenuHandler.handleContextMenu(t)}handleResize(){this.viewport.handleResize()}handleKeyDown(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&this.keyHandler.handleKeyDown(t)}handleKeyUp(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&this.keyHandler.handleKeyUp(t)}handleCopy(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&(!this.core.store.selectionGroup||this.core.store.activeText||this.core.store.activeShape||(t.cancelable&&t.preventDefault(),this.core.clipboardManager.copy(t),this.core.rerender()))}handleCut(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&(!this.core.store.selectionGroup||this.core.store.activeText||this.core.store.activeShape||(t.cancelable&&t.preventDefault(),this.core.clipboardManager.cut(t)))}handlePaste(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&(this.core.store.activeText||this.core.store.activeShape||(t.cancelable&&t.preventDefault(),this.core.clipboardManager.paste(void 0,void 0,t)))}shouldHandleGlobalShortcutEvent(t){const n=t.composedPath();if(n.includes(this.host))return!0;if(n.some((t=>t instanceof e&&("DIALOG"===t.tagName||"KRITZEL-DIALOG"===t.tagName||"dialog"===t.getAttribute?.("role")||"alertdialog"===t.getAttribute?.("role")))))return!1;const i=n[0];return!(i instanceof e&&i.matches?.('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}preventDoubleTapZoomOnTouchDevices(t){t.cancelable&&t.preventDefault()}async registerTool(t,e,n){if("function"!=typeof e)return console.error(`Failed to register tool "${t}": Tool class must be a constructor function`),null;if(this.core.toolRegistry.hasTool(t)){const e=this.core.toolRegistry.getTool(t);return n&&this.applyToolConfig(e,n),e}const i=this.core.toolRegistry.registerTool(t,e);return n&&this.applyToolConfig(i,n),Promise.resolve(i)}async changeActiveTool(t){this.core.store.state.activeTool!==t&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",t),this.core.deselectAllObjects(),t?.onActivate())}async changeActiveToolByName(t){const e=this.core.toolRegistry.getTool(t);e?await this.changeActiveTool(e):console.warn(`[KritzelEngine] No tool registered with name: ${t}`)}async disable(){this.core.store.state.isEnabled=!1,this.core.rerender()}async enable(){this.core.store.state.isEnabled=!0,this.core.rerender()}async delete(){this.core.delete()}async copy(){this.core.clipboardManager.copy()}async cut(){this.core.clipboardManager.cut()}async paste(t,e){"granted"===await this.core.permissionManager.requestPermission("clipboard-read")?this.core.clipboardManager.paste(t,e):this.notificationsChange.emit({type:"error",message:"Clipboard read permission is required to paste content. Please grant permission and try again.",id:R.generateUUID()})}async bringForward(t){this.core.bringForward(t)}async sendBackward(t){this.core.sendBackward(t)}async bringToFront(t){this.core.bringToFront(t)}async sendToBack(t){this.core.sendToBack(t)}async alignObjects(t){this.core.alignObjects(t)}async group(){this.core.group()}async ungroup(){this.core.ungroup()}async undo(){this.core.undo()}async redo(){this.core.redo()}async hideContextMenu(){this.core.store.state.pointers.clear(),this.core.store.state.isContextMenuVisible=!1,this.core.store.objects?.remove((t=>t instanceof g)),this.core.store.setSelectionBox(null),this.core.store.objects?.clearLocalSelectionBox(),this.core.store.state.isSelecting=!1,this.core.store.state.isEnabled=!0,this.core.rerender()}async openContextMenu(t){this.contextMenuHandler.open(t)}async getObjectById(t){return this.core.store.allObjects.find((e=>e.id===t))||null}async getAllObjects(){return this.core.store.allObjects}async findObjects(t){return this.core.store.allNonSelectionObjects.filter(t)}async getObjectsTotalCount(){return this.core.store.totalObjectCount}async addObject(t){if(this.core.deselectAllObjects(),t.id=t.generateId(),t._core=this.core,t.scale=t.scale??this.core.store.state.scale,t.zIndex=this.core.store.currentZIndex,t.workspaceId=this.core.store.state.activeWorkspace.id,p.isInstanceOf(t,"KritzelImage")&&await t.prepareForInsert(),p.isInstanceOf(t,"KritzelText")){const e=t.content;t.editor=t.createEditor(),e&&t.setContent(e)}if(p.isInstanceOf(t,"KritzelGroup")&&t._pendingChildren.length>0){const e=new Map,n=[],i=t=>{if(0===t._pendingChildren.length)return;const r=t._pendingChildren;t._pendingChildren=[],t.childIds=[],r.forEach((r=>{const s=r.id;r.id=r.generateId(),r._core=this.core,r.scale=r.scale??this.core.store.state.scale,r.zIndex=this.core.store.currentZIndex,r.workspaceId=this.core.store.state.activeWorkspace.id,e.set(s,r.id),t.childIds.push(r.id),n.push(r),p.isInstanceOf(r,"KritzelGroup")&&i(r)}))};i(t),n.forEach((t=>{p.isInstanceOf(t,"KritzelLine")&&(t.startAnchor&&e.has(t.startAnchor.objectId)&&(t.startAnchor={objectId:e.get(t.startAnchor.objectId)}),t.endAnchor&&e.has(t.endAnchor.objectId)&&(t.endAnchor={objectId:e.get(t.endAnchor.objectId)}))})),n.forEach((t=>{this.core.addObject(t)})),t.finalize(),this.core.anchorManager.rebuildIndex()}return this.core.addObject(t),this.core.rerender(),await new Promise((t=>{requestAnimationFrame((()=>requestAnimationFrame((()=>t()))))})),this.emitObjectsChange(),this.emitObjectsAdded([t]),t}async addObjects(t){if(0===t.length)return[];for(const e of t)e._core=this.core,p.isInstanceOf(e,"KritzelImage")&&await e.prepareForInsert();return this.core.store.objects.transaction((()=>{for(const e of t){if(e.id=e.generateId(),e._core=this.core,e.zIndex=this.core.store.currentZIndex,e.workspaceId=this.core.store.state.activeWorkspace.id,p.isInstanceOf(e,"KritzelText")){const t=e.content;e.editor=e.createEditor(),t&&e.setContent(t)}if(p.isInstanceOf(e,"KritzelGroup")&&e._pendingChildren.length>0){const t=new Map,n=[],i=e=>{if(0===e._pendingChildren.length)return;const r=e._pendingChildren;e._pendingChildren=[],e.childIds=[],r.forEach((r=>{const s=r.id;r.id=r.generateId(),r._core=this.core,r.zIndex=this.core.store.currentZIndex,r.workspaceId=this.core.store.state.activeWorkspace.id,t.set(s,r.id),e.childIds.push(r.id),n.push(r),p.isInstanceOf(r,"KritzelGroup")&&i(r)}))};i(e),n.forEach((e=>{p.isInstanceOf(e,"KritzelLine")&&(e.startAnchor&&t.has(e.startAnchor.objectId)&&(e.startAnchor={objectId:t.get(e.startAnchor.objectId)}),e.endAnchor&&t.has(e.endAnchor.objectId)&&(e.endAnchor={objectId:t.get(e.endAnchor.objectId)}))})),n.forEach((t=>{this.core.addObject(t)})),e.finalize(),this.core.anchorManager.rebuildIndex()}this.core.addObject(e)}})),this.core.rerender(),await new Promise((t=>{requestAnimationFrame((()=>requestAnimationFrame((()=>t()))))})),this.emitObjectsChange(),this.emitObjectsAdded(t),t}async updateObject(t,e){return this.core.deselectAllObjects(),this.core.updateObject(t,e),this.core.rerender(),this.emitObjectsChange(),this.emitObjectsUpdated([{object:t,changedProperties:Object.keys(e)}]),t}async removeObject(t){const e=this.core.store.objects;return e?(this.core.deselectAllObjects(),e.remove((e=>e.id===t.id)),this.core.rerender(),this.emitObjectsChange(),this.emitObjectsRemoved([t]),t):null}async removeObjects(t){const e=this.core.store.objects;return e&&0!==t.length?(e.transaction((()=>{for(const e of t)this.core.removeObject(e)})),this.core.rerender(),this.emitObjectsChange(),this.emitObjectsRemoved(t),t):[]}async getSelectedObjects(){const t=this.core.store.selectionGroup;return t?t.objects:[]}async getDisplayableShortcuts(){return this.keyHandler.getDisplayableShortcuts()}async selectObjects(t){const e=this.core.toolRegistry.getTool("selection");e&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",e),this.core.deselectAllObjects(),this.core.selectObjects(t))}async selectAllObjectsInViewport(){const t=this.core.toolRegistry.getTool("selection");t&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",t),this.core.deselectAllObjects(),this.core.selectAllObjectsInViewport())}async clearSelection(){this.core.clearSelection()}async centerObjectInViewport(t){return t.centerInViewport(),this.core.updateObject(t,t),this.core.rerender(),t}async panToObject(t){this.viewport.panTo(t.centerX,t.centerY)}async backToContent(){return this.viewport.centerFitNearestContent(20)}async centerAllObjects(t=!0){return this.viewport.centerFitAllObjects(t)}async centerObjects(t,e=!0){return this.viewport.centerFitObjects(t,e)}async setViewport(t,e,n){this.viewport.setViewport(t,e,n)}async panTo(t,e){this.viewport.panTo(t,e)}async zoomTo(t,e,n){this.viewport.zoomTo(t,e,n)}async zoomIn(t,e){this.viewport.zoomIn(t,e)}async zoomOut(t,e){this.viewport.zoomOut(t,e)}async getViewport(){return this.viewport.getViewport()}async screenToWorld(t,e){return this.viewport.screenToWorld(t,e)}async worldToScreen(t,e){return this.viewport.worldToScreen(t,e)}async getObjectsInViewport(){return this.core.getObjectsInViewport()}async getScreenshot(t="png",e){if(!this.host)return null;const n={objects:this.core.store.objects,activeWorkspace:this.core.store.state.activeWorkspace,workspaces:this.core.store.state.workspaces,activeTool:this.core.store.state.activeTool,isReady:this.core.store.state.isReady,translateX:this.core.store.state.translateX,translateY:this.core.store.state.translateY,scale:this.core.store.state.scale},i={filter:t=>!("KRITZEL-CONTEXT-MENU"===t.tagName||"KRITZEL-AWARENESS-CURSORS"===t.tagName||t.classList&&t.classList.contains("debug-panel"))};let r;(e?.includeBackground??1)||(i.backgroundColor="transparent");try{r="svg"===t?await Je(this.host,i):await async function(t,e={}){return(await async function(t,e={}){const{width:n,height:i}=Se(t,e),r=await Je(t,e),s=await ze(r),o=document.createElement("canvas"),a=o.getContext("2d"),c=e.pixelRatio||function(){let t,e;try{e=process}catch(t){}const n=e&&e.env?e.env.devicePixelRatio:null;return n&&(t=parseInt(n,10),Number.isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}(),l=e.canvasWidth||n,h=e.canvasHeight||i;return o.width=l*c,o.height=h*c,e.skipAutoScale||function(t){(t.width>Me||t.height>Me)&&(t.width>Me&&t.height>Me?t.width>t.height?(t.height*=Me/t.width,t.width=Me):(t.width*=Me/t.height,t.height=Me):t.width>Me?(t.height*=Me/t.width,t.width=Me):(t.width*=Me/t.height,t.height=Me))}(o),o.style.width=`${l}`,o.style.height=`${h}`,e.backgroundColor&&(a.fillStyle=e.backgroundColor,a.fillRect(0,0,o.width,o.height)),a.drawImage(s,0,0,o.width,o.height),o}(t,e)).toDataURL()}(this.host,i)}finally{this.core.store.state.objects=n.objects,this.core.store.state.activeWorkspace=n.activeWorkspace,this.core.store.state.workspaces=n.workspaces,this.core.store.state.activeTool=n.activeTool,this.core.store.state.isReady=n.isReady,this.core.store.state.translateX=n.translateX,this.core.store.state.translateY=n.translateY,this.core.store.state.scale=n.scale,this.core.rerender()}return r}async exportViewportAsPng(t){try{const e=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.png`,n=await this.getScreenshot("png",t);if(!n)return void console.error("Failed to export viewport as PNG: screenshot could not be generated");const i=document.createElement("a");i.download=e,i.href=n,i.click()}catch(t){console.error("Failed to export viewport as PNG:",t)}}async exportViewportAsSvg(t){try{const e=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.svg`,n=await this.getScreenshot("svg",t);if(!n)return void console.error("Failed to export viewport as SVG: screenshot could not be generated");const i=document.createElement("a");i.download=e,i.href=n,i.click()}catch(t){console.error("Failed to export viewport as SVG:",t)}}async getSelectedObjectsAsSvgString(t){const e=await this.getSelectedObjects();if(!e||0===e.length)return null;const n=t?.theme??this.core.themeManager.getStoredTheme(),i=await me.resolveImageDataUrls(e,this.core.assetResolver);return me.generateSvg(e,{theme:n,padding:t?.padding??0,includeXmlDeclaration:!0,rasterSafeForCanvas:t?.rasterSafeForCanvas??!1,imageDataUrls:i})}async exportSelectedObjectsAsSvg(t){try{const e=await this.getSelectedObjectsAsSvgString(t);if(!e)return void console.warn("No objects selected for SVG export");const n=`selection-${(new Date).toISOString().replace(/[:.]/g,"-")}.svg`,i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(i),s=document.createElement("a");s.download=n,s.href=r,s.click(),URL.revokeObjectURL(r)}catch(t){console.error("Failed to export selected objects as SVG:",t)}}async getSelectedObjectsAsPngDataUrl(t){const e=await this.getSelectedObjectsAsSvgString({theme:t?.theme,padding:t?.padding,rasterSafeForCanvas:!0});if(!e)return null;const n=t?.scale??2;return new Promise(((t,i)=>{const r=new Image,s=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),o=URL.createObjectURL(s);r.onload=()=>{const e=document.createElement("canvas");e.width=r.width*n,e.height=r.height*n;const s=e.getContext("2d");if(!s)return URL.revokeObjectURL(o),void i(new Error("Failed to get canvas context"));s.scale(n,n),s.drawImage(r,0,0),URL.revokeObjectURL(o),t(e.toDataURL("image/png"))},r.onerror=()=>{URL.revokeObjectURL(o),i(new Error("Failed to load SVG for PNG conversion"))},r.src=o}))}async exportSelectedObjectsAsPng(t){try{const e=await this.getSelectedObjectsAsPngDataUrl(t);if(!e)return void console.warn("No objects selected for PNG export");const n=`selection-${(new Date).toISOString().replace(/[:.]/g,"-")}.png`,i=document.createElement("a");i.download=n,i.href=e,i.click()}catch(t){console.error("Failed to export selected objects as PNG:",t)}}async exportAsJson(){const t=this.core.store.state.activeWorkspace;if(!t)throw new Error("Cannot export workspace: no active workspace is loaded");const e=t.serialize({includeObjects:!0});return JSON.stringify(e,null,2)}async importFromJson(t){const e=JSON.parse(t);if(!e.__class__||"KritzelWorkspace"!==e.__class__)throw new Error("Invalid workspace data: missing or incorrect __class__ identifier");e.version&&e.version!==I&&console.warn(`Workspace version mismatch: expected ${I}, got ${e.version}`);const n=R.generateUUID();let i=e.viewport||{centerWorldX:0,centerWorldY:0,scale:1};if("translateX"in i&&!("centerWorldX"in i)){const t=i.scale??1;i={centerWorldX:-(i.translateX??0)/t,centerWorldY:-(i.translateY??0)/t,scale:t}}const r=new T(n,e.name||"Imported Workspace",i);if(this.core.createWorkspace(r),this.workspacesChange.emit(this.core.store.state.workspaces),this.core.beforeWorkspaceChange(),await this.core.initializeWorkspace(r),e.objects&&Array.isArray(e.objects)){const t=new se(this.core);for(const i of e.objects){const e=t.revive(i);e&&(e.workspaceId=n,this.core.addObject(e))}}this.core.rerender(),this.activeWorkspaceChange.emit(r)}async loadObjectsFromJson(t){const e=JSON.parse(t);if(!e.__class__||"KritzelWorkspace"!==e.__class__)throw new Error("Invalid workspace data: missing or incorrect __class__ identifier");e.version&&e.version!==I&&console.warn(`Workspace version mismatch: expected ${I}, got ${e.version}`);const n=this.core.store.state.activeWorkspace;if(!n)throw new Error("Cannot load objects: no active workspace is loaded");const i=n.id;let r=0;if(e.objects&&Array.isArray(e.objects)){const t=new se(this.core);for(const n of e.objects){const e=t.revive(n);e&&(e.workspaceId=i,this.core.addObject(e),r++)}}return this.core.rerender(),r}async downloadAsJson(t){try{const e=await this.exportAsJson(),n=this.core.store.state?.activeWorkspace?.name||"workspace",i=(new Date).toISOString().replace(/[:.]/g,"-"),r=t||`${n}-${i}`,s=new Blob([e],{type:"application/json;charset=utf-8"}),o=URL.createObjectURL(s),a=document.createElement("a");a.download=`${r}.json`,a.href=o,a.click(),URL.revokeObjectURL(o)}catch(t){console.error("Failed to download workspace as JSON:",t)}}async importFromFile(){return new Promise(((t,e)=>{const n=document.createElement("input");n.type="file",n.accept=".json,application/json",n.style.display="none";const i=()=>{n.removeEventListener("change",r),n.removeEventListener("cancel",s),document.body.removeChild(n)},r=async n=>{const r=n.target,s=r.files?.[0];if(!s)return i(),void t();try{const n=new FileReader;n.onload=async n=>{try{const e=n.target?.result;await this.importFromJson(e),i(),t()}catch(t){i(),console.error("Failed to import workspace from file:",t),e(t)}},n.onerror=()=>{i(),console.error("Failed to read file:",n.error),e(n.error)},n.readAsText(s)}catch(t){i(),console.error("Failed to process file:",t),e(t)}},s=()=>{i(),t()};n.addEventListener("change",r),n.addEventListener("cancel",s),document.body.appendChild(n),n.click()}))}async createWorkspace(t){return await this.core.createWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces),t}async updateWorkspace(t){await this.core.updateWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async deleteWorkspace(t){await this.core.deleteWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async getWorkspaces(){return await this.core.getWorkspaces()}async getActiveWorkspace(){const t=this.core.store.state.activeWorkspace;if(!t)throw new Error("No active workspace is loaded");return t}async getIsPublic(){return this.core.getIsPublic()}async loadSharedWorkspace(t){const e=t;let n=this.core.getWorkspaces().find((t=>t.id===e));n?n.isPublic=!0:(n=new T(e,"Shared Workspace"),n.isPublic=!0,this.core.createWorkspace(n)),this.workspacesChange.emit(this.core.store.state.workspaces),this.core.beforeWorkspaceChange(),await this.initializeWorkspaceIfNeeded(n),this.activeWorkspaceChange.emit(this.core.store.state.activeWorkspace)}async reinitSync(){this.core.setSyncConfig(this.syncConfig),this.core.setAssetStorageConfig(this.assetStorageConfig),this.core.store.objects?.clearCursorPosition(),this.core.store.objects?.destroy(),this.core.appStateMap.destroy(),this.core.assetResolver.destroy(),this._isYjsInitialized=!1,this._isAssetStorageInitialized=!1,await this.initializeSyncAndWorkspace()}async saveSettings(t){const e=this.core.getStorageKey("kritzel-settings");localStorage.setItem(e,JSON.stringify(t))}async loadSettings(){const t=this.core.getStorageKey("kritzel-settings"),e=localStorage.getItem(t);if(!e)return null;try{return JSON.parse(e)}catch{return null}}async registerLocales(t){this.core.localizationManager.registerLocales(t),this.core.localizationManager.setLocale(this.core.localizationManager.currentLocale)}async setLocale(t){this.locale=t,this.core.localizationManager.setLocale(t)}async getLocale(){return this.core.localizationManager.currentLocale}async getAvailableLocales(){return this.core.localizationManager.getAvailableLocales()}async getAvailableLocaleOptions(){return this.core.localizationManager.getAvailableLocaleOptions()}async t(t,e){return this.core.localizationManager.translate(t,e)}async getResolvedTerms(){return this.core.localizationManager.getAllTerms()}core;viewport;contextMenuHandler;keyHandler;contextMenuElement=null;_lastHadSelectionGroup=!1;_isViewportReady=!1;_isYjsInitialized=!1;_isAssetStorageInitialized=!1;_isResolvingActiveWorkspaceId=!1;_stateChangeListenersRegistered=!1;_workspaceInitializationPromise=null;_workspaceInitializationTargetKey=null;_syncInitPromise=null;_syncConfigRevision=0;_assetStorageConfigRevision=0;_isWorkspaceLoading=!1;_hasLoggedUnlicensedWelcomeBanner=!1;_previousVisibleCustomElements=new Set;_defaultUndoState={canUndo:!1,canRedo:!1,undoStackSize:0,redoStackSize:0};_objectDistanceFadeNearScale=1;_objectDistanceFadeFarScale=.15;_objectDistanceFadeMinOpacity=0;_objectDistanceFadeCloseStartScale=2;_objectDistanceFadeCloseMaxScale=4;_objectDistanceFadeCloseMinOpacity=0;syncLoadingState(){this.core.store.state.isLoading=this._isWorkspaceLoading||this.isLoading}applyToolConfig(t,e){if(Object.entries(e).forEach((([e,n])=>{t[e]=n})),"palettes"in e&&"type"in e){const n=e.palettes[e.type];n&&(t.palette=n)}if("sizes"in e&&null!=e.sizes&&"type"in e){const n=e,i=n.sizes?.[n.type];i&&(t.sizes=i)}}get isSelecting(){return this.core.store.state.activeTool instanceof w&&this.core.store.state.isSelecting}get isSelectionActive(){return this.core.store.state.activeTool instanceof w&&null!==this.core.store.selectionGroup}constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isEngineReady=n(this,"isEngineReady"),this.activeToolChange=n(this,"activeToolChange"),this.objectsSelectionChange=n(this,"objectsSelectionChange"),this.workspacesChange=n(this,"workspacesChange"),this.activeWorkspaceChange=n(this,"activeWorkspaceChange"),this.longpress=n(this,"longpress"),this.objectsChange=n(this,"objectsChange"),this.objectsAdded=n(this,"objectsAdded"),this.objectsRemoved=n(this,"objectsRemoved"),this.objectsUpdated=n(this,"objectsUpdated"),this.undoStateChange=n(this,"undoStateChange"),this.objectsInViewportChange=n(this,"objectsInViewportChange"),this.viewportChange=n(this,"viewportChange"),this.awarenessChange=n(this,"awarenessChange"),this.notificationsChange=n(this,"notificationsChange"),this.core=new we(this)}disconnectedCallback(){this.throttledPointerMoveMulti.cancel(),this.core.store.allObjects&&this.core.store.allObjects.forEach((t=>{p.isInstanceOf(t,"KritzelCustomElement")&&t.unmount()})),this.core.store.objects?.clearCursorPosition(),this.core.store.objects&&this.core.store.objects.destroy(),this.core.appStateMap.destroy(),this.core.cursorManager.cleanup(),this.core.themeManager.cleanup(),this.core.licenseManager.destroy()}componentWillLoad(){this.core.setEditorId(this.editorId),this.themes&&this.themes.length>0&&this.core.themeManager.registerThemes(this.themes);const t=this.host.closest("kritzel-editor");this.core.themeManager.injectThemeEarly(t||this.host),this.locales&&this.locales.length>0&&this.core.localizationManager.registerLocales(this.locales),this.core.localizationManager.setFallbackLocale(this.fallbackLocale),this.core.localizationManager.setLocale(this.locale),this.core.licenseManager.validate(this.licenseKey),this.core.licenseManager.startPeriodicValidation(),this.core.setUser(this.user),this.validateScaleMax(this.scaleMax),this.validateScaleMin(this.scaleMin),this.core.store.state.lockDrawingScale=this.lockDrawingScale,this.core.store.state.viewportBoundaryLeft=this.viewportBoundaryLeft,this.core.store.state.viewportBoundaryRight=this.viewportBoundaryRight,this.core.store.state.viewportBoundaryTop=this.viewportBoundaryTop,this.core.store.state.viewportBoundaryBottom=this.viewportBoundaryBottom,this._isWorkspaceLoading=!0,this.syncLoadingState()}async componentDidLoad(){setTimeout((async()=>{this.contextMenuHandler=new re(this.core,this.globalContextMenuItems??[],this.objectContextMenuItems??[]),this.keyHandler=new ie(this.core),this.viewport=new ne(this.core,this.host),this._isViewportReady=!0,this.core.cursorManager.setTargetElement(this.cursorTarget||document.body),this.host.shadowRoot&&this.core.cursorManager.setShadowRoot(this.host.shadowRoot);const t=this.host.closest("kritzel-editor");this.core.themeManager.setTargetElement(t||this.host),await this.initializeSyncAndWorkspace(),!1===this.core.store.state.isReady&&(this.core.store.state.isReady=!0,this.logUnlicensedWelcomeBanner(),this.isEngineReady.emit(this.core.store.state))}),50)}async initializeSyncAndWorkspace(){if(this._syncInitPromise)return this._syncInitPromise;this._syncInitPromise=this.doInitializeSyncAndWorkspace();try{await this._syncInitPromise}finally{this._syncInitPromise=null}}async initializeAssetStorage(){if(this._isAssetStorageInitialized)return;const t=this._assetStorageConfigRevision;this.core.setAssetStorageConfig(this.assetStorageConfig),await this.core.initializeAssetStorage(),t!==this._assetStorageConfigRevision&&(this.core.assetResolver.destroy(),this.core.setAssetStorageConfig(this.assetStorageConfig),await this.core.initializeAssetStorage()),this._isAssetStorageInitialized=!0}logUnlicensedWelcomeBanner(){this.core.licenseManager.isLicensed||this._hasLoggedUnlicensedWelcomeBanner||(this._hasLoggedUnlicensedWelcomeBanner=!0,console.info("%c👋 Welcome to Kritzel","color: #007AFF; font-weight: 700;"),console.info("This version of Kritzel is not licensed. Get a license at: https://kritzel.io"))}async doInitializeSyncAndWorkspace(){const t=this._syncConfigRevision;if(this.core.setSyncConfig(this.syncConfig),this.core.setAssetStorageConfig(this.assetStorageConfig),this._isYjsInitialized||(await this.core.initializeYjs(),t!==this._syncConfigRevision&&(this.core.appStateMap.destroy(),this.core.setSyncConfig(this.syncConfig),this.core.setAssetStorageConfig(this.assetStorageConfig),await this.core.initializeYjs()),this._isYjsInitialized=!0),!this._isAssetStorageInitialized&&this.assetStorageConfig&&await this.initializeAssetStorage(),this.activeWorkspaceId){const t=this.core.getWorkspaces().find((t=>t.id===this.activeWorkspaceId));t?await this.initializeWorkspaceIfNeeded(t):await this.initializeWorkspaceIfNeeded()}else{const t=this.resolveStartupWorkspace();await this.initializeWorkspaceIfNeeded(t)}const e=this.core.store.state.activeWorkspace;e&&this.activeWorkspaceChange.emit(e),this._stateChangeListenersRegistered||(this.core.appStateMap.onRemoteChange((()=>{this.workspacesChange.emit(this.core.store.state.workspaces),this.tryResolveActiveWorkspaceFromId()})),this._registerStateChangeListeners(),this._stateChangeListenersRegistered=!0),this.tryResolveActiveWorkspaceFromId()}resolveStartupWorkspace(){if(this.activeWorkspaceId){const t=this.core.getWorkspaces().find((t=>t.id===this.activeWorkspaceId));if(t)return t;console.warn(`[KritzelEngine] No workspace found with ID: ${this.activeWorkspaceId}`)}return this.workspace}tryResolveActiveWorkspaceFromId(){this.activeWorkspaceId&&!this._isResolvingActiveWorkspaceId&&this.core.store.state.activeWorkspace?.id!==this.activeWorkspaceId&&(this._isResolvingActiveWorkspaceId=!0,this.switchToWorkspaceById(this.activeWorkspaceId,!1).finally((()=>{this._isResolvingActiveWorkspaceId=!1})))}async switchToWorkspaceById(t,e=!0){const n=this.core.getWorkspaces().find((e=>e.id===t));n?this.core.store.state.activeWorkspace?.id!==n.id&&(this.core.beforeWorkspaceChange(),await this.initializeWorkspaceIfNeeded(n),this.activeWorkspaceChange.emit(this.core.store.state.activeWorkspace)):e&&console.warn(`[KritzelEngine] No workspace found with ID: ${t}`)}async initializeWorkspaceIfNeeded(t,e){const n=t?.id??null,i=n??(e?.skipFallbackCreation?"__NO_FALLBACK__":"__AUTO__");if(n&&this.core.store.state.activeWorkspace?.id===n)return;if(this._workspaceInitializationPromise&&this._workspaceInitializationTargetKey===i)return void await this._workspaceInitializationPromise;this._isWorkspaceLoading=!0,this.syncLoadingState();const r=this.core.initializeWorkspace(t,e);this._workspaceInitializationPromise=r,this._workspaceInitializationTargetKey=i;try{await r}finally{this._workspaceInitializationPromise===r&&(this._workspaceInitializationPromise=null,this._workspaceInitializationTargetKey=null),this._isWorkspaceLoading=!1,this.syncLoadingState()}}emitObjectsChange(){const t=this.core.store.objects;if(!t)return this.objectsChange.emit([]),this.undoStateChange.emit(this._defaultUndoState),void(this._lastHadSelectionGroup&&(this._lastHadSelectionGroup=!1,this.objectsSelectionChange.emit()));const e=t.undoState,n=null!==this.core.store.selectionGroup;this.objectsChange.emit(this.core.store.allObjects),this.undoStateChange.emit(e),this._lastHadSelectionGroup!==n&&(this._lastHadSelectionGroup=n,this.objectsSelectionChange.emit())}emitObjectsAdded(t){this.objectsAdded.emit({objects:t})}emitObjectsRemoved(t){this.objectsRemoved.emit({objects:t})}emitObjectsUpdated(t){this.objectsUpdated.emit({objects:t})}emitAwarenessChange(t){this.awarenessChange.emit(t)}emitObjectsInViewportChange(){this.objectsInViewportChange.emit(this.core.store.objectsInViewport)}_registerStateChangeListeners(){this.core.store.onStateChange("activeTool",this._handleActiveToolChange.bind(this))}_handleActiveToolChange(t){t instanceof w||(this.core.clearSelection(),this.core.store.objects?.remove((t=>t instanceof g)),this.core.store.setSelectionBox(null),this.core.store.objects?.clearLocalSelectionBox(),this.core.store.state.isSelecting=!1,this.core.store.state.isResizeHandleSelected=!1,this.core.store.state.isRotationHandleSelected=!1),t instanceof m||this.core.resetActiveText(),t instanceof Ot||this.core.resetActiveShape(),this.core.store.state.skipContextMenu=!1,t&&this.activeToolChange.emit(t),A.forceHideKeyboard(),this.core.rerender()}getObjectDistanceFadeMultiplier(t,e){if(!this.isObjectDistanceFadingActive)return 1;const n=Math.max(Number.isFinite(e)?e:1,Number.EPSILON)/Math.max(Number.isFinite(t)?t:1,Number.EPSILON),i=this.getFarDistanceFadeMultiplier(n),r=this.getCloseDistanceFadeMultiplier(n);return Math.min(i,r)}getFarDistanceFadeMultiplier(t){if(t>=this._objectDistanceFadeNearScale)return 1;if(t<=this._objectDistanceFadeFarScale)return this._objectDistanceFadeMinOpacity;const e=(this._objectDistanceFadeNearScale-t)/(this._objectDistanceFadeNearScale-this._objectDistanceFadeFarScale);return 1-e*e*(3-2*e)*(1-this._objectDistanceFadeMinOpacity)}getCloseDistanceFadeMultiplier(t){if(t<=this._objectDistanceFadeCloseStartScale)return 1;if(t>=this._objectDistanceFadeCloseMaxScale)return this._objectDistanceFadeCloseMinOpacity;const e=(t-this._objectDistanceFadeCloseStartScale)/(this._objectDistanceFadeCloseMaxScale-this._objectDistanceFadeCloseStartScale);return 1-e*e*(3-2*e)*(1-this._objectDistanceFadeCloseMinOpacity)}shouldApplyDistanceFade(t){return!p.isInstanceOf(t,"KritzelSelectionGroup")&&!p.isInstanceOf(t,"KritzelSelectionBox")}getObjectEffectiveOpacity(t,e){const n=Number.isFinite(t.opacity)?t.opacity:1,i=this.shouldApplyDistanceFade(t)?this.getObjectDistanceFadeMultiplier(t.scale,e):1;return{multiplied:(t.markedForRemoval?.5:1)*n*i,overridden:((t.markedForRemoval?.5:n)*i).toString()}}getSelectionHandleCapabilities(t){const e=p.isInstanceOf(t,"KritzelSelectionGroup")?t.objects:[t];return{canRenderResizeHandles:e.every((t=>!1!==t.isResizable)),canRenderRotationHandle:e.every((t=>!1!==t.isRotatable))}}render(){if(!this.viewport)return i(r,null,this.core.store.state.isLoading&&i("div",{class:"workspace-loading-overlay"},i("span",{class:"workspace-loading-spinner"}),this.core.localizationManager.translate("engine.loading")));const t=this.core.themeManager.getStoredTheme(),e=window.getComputedStyle(this.host).getPropertyValue("--kritzel-selection-handle-size").trim()||"6px",n=parseFloat(e),s=2*n<14?14:n,o=this.core.store.state.scale,a=this.core.store.state.viewportWidth/2+this.core.store.state.translateX,c=this.core.store.state.viewportHeight/2+this.core.store.state.translateY,l=this.core.store.objectsInViewport,h=t=>this.core.store.state.isScaling||p.isInstanceOf(t,"KritzelSelectionGroup")?"none":"auto",u=t=>t.markedForRemoval||p.isInstanceOf(t,"KritzelSelectionGroup")&&1===t.objects.length&&p.isInstanceOf(t.objects[0],"KritzelCustomElement")?"none":"auto",f=new Set;return l.forEach((t=>{p.isInstanceOf(t,"KritzelCustomElement")&&f.add(t.id)})),this._previousVisibleCustomElements.forEach((t=>{if(!f.has(t)){const e=this.core.store.objects.findById(t);e&&p.isInstanceOf(e,"KritzelCustomElement")&&e.unmount()}})),this._previousVisibleCustomElements=f,this.core.cursorManager.applyCursor(),this.core.store.state.hasViewportChanged&&(this.viewportChange.emit(this.viewport.getViewport()),this.core.store.totalObjectCount>0&&this.emitObjectsInViewportChange()),i(r,null,this.core.store.state.isLoading&&i("div",{class:"workspace-loading-overlay"},i("span",{class:"workspace-loading-spinner"}),"Loading..."),this.core.store.state.debugInfo.showViewportInfo&&i("div",{class:"debug-panel"},i("div",null,"ActiveWorkspaceId: ",this.core.store.state?.activeWorkspace?.id),i("div",null,"ActiveWorkspaceName: ",this.core.store.state?.activeWorkspace?.name),i("div",null,"TranslateX: ",this.core.store.state?.translateX),i("div",null,"TranslateY: ",this.core.store.state?.translateY),i("div",null,"ViewportWidth: ",this.core.store.state?.viewportWidth),i("div",null,"ViewportHeight: ",this.core.store.state?.viewportHeight),i("div",null,"PointerCount: ",this.core.store.state.pointers.size),i("div",null,"Scale: ",this.core.store.state?.scale),i("div",null,"ActiveTool: ",this.core.store.state?.activeTool?.name),i("div",null,"HasViewportChanged: ",this.core.store.state?.hasViewportChanged?"true":"false"),i("div",null,"IsEnabled: ",this.core.store.state?.isEnabled?"true":"false"),i("div",null,"IsScaling: ",this.core.store.state?.isScaling?"true":"false"),i("div",null,"IsPanning: ",this.core.store.state?.isPanning?"true":"false"),i("div",null,"IsSelecting: ",this.isSelecting?"true":"false"),i("div",null,"IsSelectionActive: ",this.isSelectionActive?"true":"false"),i("div",null,"IsResizeHandleSelected: ",this.core.store.state.isResizeHandleSelected?"true":"false"),i("div",null,"IsRotationHandleSelected: ",this.core.store.state.isRotationHandleSelected?"true":"false"),i("div",null,"IsRotationHandleHovered: ",this.core.store.state.isRotationHandleHovered?"true":"false"),i("div",null,"IsDrawing: ",this.core.store.state.isDrawing?"true":"false"),i("div",null,"IsWriting: ",this.core.store.state.isWriting?"true":"false"),i("div",null,"IsPointerDown: ",this.core.store.isPointerDown?"true":"false"),i("div",null,"PointerX: ",this.core.store.state?.pointerX),i("div",null,"PointerY: ",this.core.store.state?.pointerY),i("div",null,"TotalObjects: ",this.core.store.totalObjectCount),i("div",null,"ObjectsInViewport: ",this.core.store.objectsInViewport.length),i("div",null,"SelectedObjects: ",this.core.store.selectionGroup?.objects.length||0),i("div",null,"ViewportCenter: (",a.toFixed(2),", ",c.toFixed(2),")")),i("div",{id:"origin",class:"origin",style:{transform:`matrix(${this.core.store.state?.scale}, 0, 0, ${this.core.store.state?.scale}, ${this.core.store.state?.translateX}, ${this.core.store.state?.translateY})`}},l?.map((e=>{const{multiplied:r,overridden:a}=this.getObjectEffectiveOpacity(e,o);return i("div",{key:e.id,id:e.id,class:"object",style:{transform:e?.transformationMatrix,transformOrigin:"top left",position:"absolute",zIndex:this.core.displaySelectionLineUI(e)?"10001":e.zIndex.toString(),pointerEvents:h(e)}},p.isInstanceOf(e,"KritzelPath")&&i("svg",{ref:t=>t&&e.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{height:e?.totalHeight+"px",width:e?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,pointerEvents:e.markedForRemoval?"none":"auto",overflow:"visible"},viewBox:e?.viewBox},i("path",{d:e?.d,fill:M.applyOpacity(e.fill,r,t),stroke:M.applyOpacity(e?.stroke,r,t),"shape-rendering":e.isLowRes()?"optimizeSpeed":"auto"})),p.isInstanceOf(e,"KritzelLine")&&i("svg",{ref:t=>t&&e.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{height:e?.totalHeight+"px",width:e?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,pointerEvents:e.markedForRemoval?"none":"auto",overflow:"visible"},viewBox:e?.viewBox},(e.hasStartArrow||e.hasEndArrow)&&i("defs",null,e.hasStartArrow&&i("marker",{id:e.startMarkerId,markerWidth:e.getArrowSize("start"),markerHeight:e.getArrowSize("start"),refX:0,refY:e.getArrowSize("start")/2,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse"},i("path",{d:e.getArrowPath(e.arrows?.start?.style),fill:M.applyOpacity(e.getArrowFill("start"),r),transform:`scale(${e.getArrowSize("start")/10})`})),e.hasEndArrow&&i("marker",{id:e.endMarkerId,markerWidth:e.getArrowSize("end"),markerHeight:e.getArrowSize("end"),refX:0,refY:e.getArrowSize("end")/2,orient:"auto",markerUnits:"userSpaceOnUse"},i("path",{d:e.getArrowPath(e.arrows?.end?.style),fill:M.applyOpacity(e.getArrowFill("end"),r),transform:`scale(${e.getArrowSize("end")/10})`}))),i("path",{d:this.core.anchorManager.computeClippedLinePath(e),fill:"none",stroke:"transparent","stroke-width":Math.max(e?.strokeWidth||0,10),"stroke-linecap":"round"}),i("path",{d:this.core.anchorManager.computeClippedLinePath(e),fill:"none",stroke:M.applyOpacity(e?.stroke,r,t),"stroke-width":e?.strokeWidth,"stroke-linecap":"round","marker-start":e.hasStartArrow?`url(#${e.startMarkerId})`:void 0,"marker-end":e.hasEndArrow?`url(#${e.endMarkerId})`:void 0})),p.isInstanceOf(e,"KritzelImage")&&"ready"===e.loadState&&i("img",{ref:t=>t&&e.mount(t),src:e.resolvedSrc||e.src,style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor(e.backgroundColor,t),borderColor:M.resolveThemeColor(e.borderColor,t),borderWidth:e.borderWidth+"px",borderStyle:"solid",padding:e.padding+"px",overflow:"visible",userSelect:"none",imageRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"pixelated":"auto"},draggable:!1,decoding:"async",loading:"eager",onDragStart:t=>t.preventDefault()}),p.isInstanceOf(e,"KritzelImage")&&"ready"!==e.loadState&&i("div",{ref:()=>e.ensureLoaded(),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor({light:"#e5e7eb",dark:"#2a2a2a"},t),borderColor:M.resolveThemeColor("error"===e.loadState?{light:"#9ca3af",dark:"#6b7280"}:e.borderColor,t),borderWidth:"error"===e.loadState?"1px":e.borderWidth+"px",borderStyle:"solid",padding:e.padding+"px",overflow:"hidden",userSelect:"none",display:"flex",alignItems:"center",justifyContent:"center"}},i("kritzel-icon",{name:"error"===e.loadState?"image-off":"image",size:Math.max(16,.3*Math.min(e.totalWidth,e.totalHeight)),style:{color:M.resolveThemeColor({light:"#9ca3af",dark:"#6b7280"},t)}})),p.isInstanceOf(e,"KritzelCustomElement")&&i("div",{ref:t=>t&&e.mount(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor(e.backgroundColor,t),borderColor:M.resolveThemeColor(e.borderColor,t),borderWidth:e.borderWidth+"px",borderStyle:"solid",padding:e.padding+"px",overflow:"hidden",display:"block"}}),p.isInstanceOf(e,"KritzelSelectionGroup")&&!this.core.displaySelectionLineUI(e)&&i("div",{ref:t=>t&&e.mount(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:e.markedForRemoval?"0.5":e.opacity.toString(),pointerEvents:u(e)}}),p.isInstanceOf(e,"KritzelSelectionBox")&&i("div",{ref:t=>t&&e.mount(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:e.markedForRemoval?"0.5":e.opacity.toString(),pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor(e.backgroundColor,t),borderColor:M.resolveThemeColor(e.borderColor,t),borderWidth:e.borderWidth+"px",borderStyle:"solid"}}),p.isInstanceOf(e,"KritzelText")&&i("div",{style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto"}},i("div",{id:"text-object",ref:t=>t&&e.mount(t),onPointerDown:t=>e.handlePointerDown(t),onPointerMove:t=>e.handlePointerMove(t),onPointerUp:t=>e.handlePointerUp(t),style:{minWidth:e.initialWidth+"px",minHeight:e.initialHeight+"px",maxWidth:"500px",height:"auto",width:"max-content",transformOrigin:"top left",transform:`scale(${e.scaleFactor})`,backgroundColor:M.resolveThemeColor(e.backgroundColor,t),overflow:"visible"}})),p.isInstanceOf(e,"KritzelShape")&&(()=>{const n=M.resolveThemeColor(e.fillColor,t),s=M.resolveThemeColor(e.strokeColor,t),o=!!n&&"transparent"!==n&&s===n;return i("div",{ref:t=>t&&e.mount(t),onPointerDown:t=>e.handlePointerDown(t),onPointerMove:t=>e.handlePointerMove(t),onPointerUp:t=>e.handlePointerUp(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,pointerEvents:e.markedForRemoval?"none":"auto",overflow:"visible"}},i("svg",{xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:e.viewBox,preserveAspectRatio:"none"},i("path",{d:e.getSvgPath(),fill:M.applyOpacity(e.fillColor,r,t),stroke:o?"none":M.applyOpacity(e.strokeColor,r,t),"stroke-width":o?0:e.strokeWidth})),i("div",{ref:t=>t&&e.mountTextEditor(t),style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",overflow:"hidden",pointerEvents:e.isEditing?"auto":"none"}}))})(),this.core.store.state.debugInfo.showObjectInfo&&i("div",{style:{pointerEvents:"none",position:"absolute",left:`${e.totalWidth}px`,top:"0",zIndex:(e.zIndex+2).toString()}},i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"Id: ",e.id),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"userId: ",e.userId),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"width: ",e.width),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"height: ",e.height),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateX: ",e.translateX),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateY: ",e.translateY),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"scale: ",e.scale),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"rotationDegrees: ",e.rotationDegrees),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"zIndex: ",e.zIndex),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"isSelected: ",e.isSelected?"true":"false"),p.isInstanceOf(e,"KritzelCustomElement")&&i("div",null,i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"isInteractive: ",e.isInteractive?"true":"false")),p.isInstanceOf(e,"KritzelImage")&&i("div",null,i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"assetId: ",e.assetId),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"mimeType: ",e.mimeType))),(this.core.displaySelectionGroupUI(e)||this.core.displaySelectionLineUI(e))&&(()=>{const r=p.isInstanceOf(e,"KritzelSelectionGroup"),o=this.core.store.objects?.localClientId,a=this.core.store.objects?.awareness?.getStates(),c=r&&(null!=e.userId&&null!=this.core.user?.id&&e.userId!==this.core.user.id||null!=e.userId&&null!=this.core.user?.id&&e.userId===this.core.user.id&&null!=e.clientId&&null!=o&&e.clientId!==o&&!0===a?.has(e.clientId));let l;if(c&&a&&(r&&null!=e.clientId&&(l=a.get(e.clientId)?.user?.color),!l))for(const t of a.values())if(t.user?.id===e.userId){l=t.user.color;break}const h=l??(M.resolveThemeColor(e.borderColor,t)||"var(--kritzel-selection-border-color, #007AFF)"),u=l??"var(--kritzel-selection-handle-stroke-color, #007AFF)",f=null!=e.endAnchor,d=this.core.store.state.snapCandidate??this.core.store.state.snapPreviewCandidate,g=null!=e.startAnchor||"start"===d?.endpoint,v=f||"end"===d?.endpoint,w=this.core.displaySelectionLineUI(e)?"10000":(e.zIndex+1).toString(),m=e.scale??1,{canRenderResizeHandles:y,canRenderRotationHandle:b}=this.getSelectionHandleCapabilities(e);return i("svg",{xmlns:"http://www.w3.org/2000/svg",style:{zIndex:w,height:e?.totalHeight.toString(),width:e?.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${e.rotationDegrees}deg)`,transformOrigin:`${e.totalWidth/2}px ${e.totalHeight/2}px`,overflow:"visible",pointerEvents:"none"}},this.core.displaySelectionGroupUI(e)&&i("g",{class:"selection-group-ui",style:{pointerEvents:"none"}},(()=>{const t=c&&p.isInstanceOf(e,"KritzelSelectionGroup")&&1===e.objects.length&&p.isInstanceOf(e.objects[0],"KritzelLine")?e.objects[0]:null;return t?i("g",{class:"selection-line-borders"},i("path",{class:"selection-line-border",d:this.core.anchorManager.computeClippedLinePath(t,!0),style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"round",fill:"none"}})):i("g",{class:"selection-group-borders"},i("line",{x1:"0",y1:"0",x2:e.totalWidth,y2:"0",style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:"0",y1:"0",x2:"0",y2:e.totalHeight,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:"0",y1:e.totalHeight,x2:e.totalWidth,y2:e.totalHeight,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:e.totalWidth,y1:"0",x2:e.totalWidth,y2:e.totalHeight,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}))})(),!this.isSelecting&&!c&&i("g",{class:"selection-group-handles",style:{pointerEvents:"auto"}},y&&i("g",null,i("rect",{class:"resize-handle top-left",x:""+-(n-1)*m/this.core.store.state?.scale,y:""+-(n-1)*m/this.core.store.state?.scale,width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay top-left",x:""+-s*m/this.core.store.state?.scale,y:""+-s*m/this.core.store.state?.scale,width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("rect",{class:"resize-handle top-right",x:""+(e.totalWidth-(n-1)*m/this.core.store.state?.scale),y:""+-(n-1)*m/this.core.store.state?.scale,width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay top-right",x:""+(e.totalWidth-s*m/this.core.store.state?.scale),y:""+-s*m/this.core.store.state?.scale,width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("rect",{class:"resize-handle bottom-left",x:""+-(n-1)*m/this.core.store.state?.scale,y:""+(e.totalHeight-(n-1)*m/this.core.store.state?.scale),width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay bottom-left",x:""+-s*m/this.core.store.state?.scale,y:""+(e.totalHeight-s*m/this.core.store.state?.scale),width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("rect",{class:"resize-handle bottom-right",x:""+(e.totalWidth-(n-1)*m/this.core.store.state?.scale),y:""+(e.totalHeight-(n-1)*m/this.core.store.state?.scale),width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay bottom-right",x:""+(e.totalWidth-s*m/this.core.store.state?.scale),y:""+(e.totalHeight-s*m/this.core.store.state?.scale),width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}})),b&&i("g",null,i("line",{x1:e.totalWidth/2,y1:"0",x2:e.totalWidth/2,y2:-15*m/this.core.store.state?.scale,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${m} / ${this.core.store.state?.scale})`}}),i("circle",{class:"rotation-handle",cx:e.totalWidth/2,cy:-15*m/this.core.store.state?.scale,r:""+(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"rotation-handle-overlay",cx:e.totalWidth/2,cy:-15*m/this.core.store.state?.scale,r:""+s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}})))),this.core.displaySelectionLineUI(e)&&p.isInstanceOf(e,"KritzelLine")&&i("g",{class:"selection-line-ui",style:{pointerEvents:"none"}},i("g",{class:"selection-line-borders"},i("path",{class:"selection-line-border",d:this.core.anchorManager.computeClippedLinePath(e,!0),style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"round",fill:"none"}})),!this.isSelecting&&!c&&i("g",{class:"selection-line-handles",style:{pointerEvents:"auto"}},i("circle",{class:"selection-line-handle start",cx:e.startX-e.x,cy:e.startY-e.y,r:""+(n-1)*e.scale/this.core.store.state?.scale,style:{fill:g?u:"var(--kritzel-selection-handle-color, #000000)",stroke:u,strokeWidth:`calc(2px * ${e.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay start","data-testid":"line-handle-start",cx:e.startX-e.x,cy:e.startY-e.y,r:""+s*e.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle center",cx:void 0!==e.controlX?(e.startX+2*e.controlX+e.endX)/4-e.x:(e.startX-e.x+e.endX-e.x)/2,cy:void 0!==e.controlY?(e.startY+2*e.controlY+e.endY)/4-e.y:(e.startY-e.y+e.endY-e.y)/2,r:""+(n-1)*e.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:u,strokeWidth:`calc(2px * ${e.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay center","data-testid":"line-handle-center",cx:void 0!==e.controlX?(e.startX+2*e.controlX+e.endX)/4-e.x:(e.startX-e.x+e.endX-e.x)/2,cy:void 0!==e.controlY?(e.startY+2*e.controlY+e.endY)/4-e.y:(e.startY-e.y+e.endY-e.y)/2,r:""+s*e.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle end",cx:e.endX-e.x,cy:e.endY-e.y,r:""+(n-1)*e.scale/this.core.store.state?.scale,style:{fill:v?u:"var(--kritzel-selection-handle-color, #000000)",stroke:u,strokeWidth:`calc(2px * ${e.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay end","data-testid":"line-handle-end",cx:e.endX-e.x,cy:e.endY-e.y,r:""+s*e.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))))})())})),(()=>{const t=this.core.anchorManager.getSnapIndicatorRenderData()??this.core.anchorManager.getSnapPreviewRenderData();if(!t)return null;const e=null!=this.core.anchorManager.getSnapIndicatorRenderData();return i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"snap-indicator",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9999",overflow:"visible"}},i("g",null,t.snapLinePath?i("path",{d:t.snapLinePath,fill:"none",style:{stroke:e?"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))":"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.12))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}):void 0!==t.edgeX&&void 0!==t.edgeY&&i("line",{x1:t.edgeX,y1:t.edgeY,x2:t.centerX,y2:t.centerY,style:{stroke:e?"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))":"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.12))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.centerX,cy:t.centerY,r:t.indicatorRadius,style:{fill:e?"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))":"rgba(59, 130, 246, 0.18)",stroke:e?"var(--kritzel-snap-indicator-stroke, #007bff)":"rgba(59, 130, 246, 0.5)",strokeWidth:t.indicatorStrokeWidth}})))})(),(()=>{const t=this.core.anchorManager.getAnchorLinesRenderData();return t?i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"anchor-lines",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9998",overflow:"visible"}},t.startAnchorViz&&i("g",{class:"anchor-line-start"},t.startAnchorViz.pathD?i("path",{d:t.startAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):i("line",{x1:t.startAnchorViz.edgeX,y1:t.startAnchorViz.edgeY,x2:t.startAnchorViz.centerX,y2:t.startAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.startAnchorViz.centerX,cy:t.startAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}})),t.endAnchorViz&&i("g",{class:"anchor-line-end"},t.endAnchorViz.pathD?i("path",{d:t.endAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):i("line",{x1:t.endAnchorViz.edgeX,y1:t.endAnchorViz.edgeY,x2:t.endAnchorViz.centerX,y2:t.endAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.endAnchorViz.centerX,cy:t.endAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})()),this.core.store.state.isContextMenuVisible&&i("kritzel-context-menu",{class:"context-menu",ref:t=>this.contextMenuElement=t??null,items:this.core.store.state.contextMenuItems,objects:this.core.store.selectionGroup?.objects||[],style:{position:"absolute",left:`${this.core.store.state.contextMenuX}px`,top:`${this.core.store.state.contextMenuY}px`,zIndex:"10002"},onActionSelected:t=>{t.detail.action&&t.detail.action({x:this.core.store.state.contextMenuWorldX,y:this.core.store.state.contextMenuWorldY},this.core.store.selectionGroup?.objects||[]),this.hideContextMenu()},onClose:()=>this.hideContextMenu()}),this.core.store.objects?.hasAwareness&&i("kritzel-awareness-cursors",{core:this.core}),this.core.store.state?.activeTool instanceof tt&&!this.core.store.state.isScaling&&i("kritzel-cursor-trail",{core:this.core}),!this.core.licenseManager.isLicensed&&i("kritzel-watermark",{core:this.core,label:this.core.localizationManager.translate("watermark.poweredBy")}))}static get watchers(){return{workspace:[{onWorkspaceChange:0}],activeWorkspaceId:[{onActiveWorkspaceIdChange:0}],syncConfig:[{onSyncConfigChange:0}],assetStorageConfig:[{onAssetStorageConfigChange:0}],user:[{onUserChange:0}],globalContextMenuItems:[{onGlobalContextMenuItemsChange:0}],objectContextMenuItems:[{onObjectContextMenuItemsChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}],lockDrawingScale:[{onLockDrawingScaleChange:0}],isObjectDistanceFadingActive:[{onIsObjectDistanceFadingActiveChange:0}],theme:[{onThemeChange:0}],licenseKey:[{onLicenseKeyChange:0}],themes:[{onThemesChange:0}],locale:[{onLocaleChange:0}],locales:[{onLocalesChange:0}],fallbackLocale:[{onFallbackLocaleChange:0}],viewportBoundaryLeft:[{onViewportBoundaryLeftChange:0}],viewportBoundaryRight:[{onViewportBoundaryRightChange:0}],viewportBoundaryTop:[{onViewportBoundaryTopChange:0}],viewportBoundaryBottom:[{onViewportBoundaryBottomChange:0}],debugInfo:[{onDebugInfoChange:0}],isLoading:[{onIsLoadingChange:0}]}}static get style(){return":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.ProseMirror{outline:none}p,h1,h2,h3,h4,h5,h6,blockquote,pre{margin:0;padding:0}.workspace-loading-overlay{position:absolute;inset:0;z-index:9999;display:flex;align-items:center;justify-content:center;gap:10px;background-color:var(--kritzel-engine-loading-overlay-background, rgba(255, 255, 255, 0.6));color:var(--kritzel-engine-loading-overlay-color, #333);font-family:var(--kritzel-font-family, sans-serif);font-size:1.25rem;pointer-events:all;animation:workspace-loading-fade-in 200ms ease-out var(--kritzel-engine-loading-overlay-delay, 300ms) forwards;opacity:0}.workspace-loading-spinner{width:20px;height:20px;box-sizing:border-box;display:block;flex-shrink:0;border:2px solid var(--kritzel-engine-loading-overlay-spinner-color, #cccccc);border-top-color:var(--kritzel-engine-loading-overlay-spinner-active-color, #333333);border-radius:50%;animation:workspace-loading-spin 0.6s linear infinite}@keyframes workspace-loading-spin{to{transform:rotate(360deg)}}@keyframes workspace-loading-fade-in{to{opacity:1}}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}.PlaygroundEditorTheme__quote{margin:0;margin-left:20px;margin-bottom:10px;font-size:15px;color:rgb(101, 103, 107);border-left-color:rgb(206, 208, 212);border-left-width:4px;border-left-style:solid;padding-left:16px}"}},[513,"kritzel-engine",{workspace:[16],editorId:[1,"editor-id"],activeWorkspaceId:[1,"active-workspace-id"],syncConfig:[16],assetStorageConfig:[16],user:[16],globalContextMenuItems:[16],objectContextMenuItems:[16],scaleMax:[1026,"scale-max"],scaleMin:[1026,"scale-min"],cursorTarget:[16],lockDrawingScale:[4,"lock-drawing-scale"],isObjectDistanceFadingActive:[4,"is-object-distance-fading-active"],theme:[1],licenseKey:[1,"license-key"],themes:[16],locale:[1],locales:[16],fallbackLocale:[1,"fallback-locale"],viewportBoundaryLeft:[2,"viewport-boundary-left"],viewportBoundaryRight:[2,"viewport-boundary-right"],viewportBoundaryTop:[2,"viewport-boundary-top"],viewportBoundaryBottom:[2,"viewport-boundary-bottom"],debugInfo:[16],isPanningEnabled:[4,"is-panning-enabled"],isZoomingEnabled:[4,"is-zooming-enabled"],isLoading:[4,"is-loading"],forceUpdate:[32],triggerSelectionChange:[64],registerTool:[64],changeActiveTool:[64],changeActiveToolByName:[64],disable:[64],enable:[64],delete:[64],copy:[64],cut:[64],paste:[64],bringForward:[64],sendBackward:[64],bringToFront:[64],sendToBack:[64],alignObjects:[64],group:[64],ungroup:[64],undo:[64],redo:[64],hideContextMenu:[64],openContextMenu:[64],getObjectById:[64],getAllObjects:[64],findObjects:[64],getObjectsTotalCount:[64],addObject:[64],addObjects:[64],updateObject:[64],removeObject:[64],removeObjects:[64],getSelectedObjects:[64],getDisplayableShortcuts:[64],selectObjects:[64],selectAllObjectsInViewport:[64],clearSelection:[64],centerObjectInViewport:[64],panToObject:[64],backToContent:[64],centerAllObjects:[64],centerObjects:[64],setViewport:[64],panTo:[64],zoomTo:[64],zoomIn:[64],zoomOut:[64],getViewport:[64],screenToWorld:[64],worldToScreen:[64],getObjectsInViewport:[64],getScreenshot:[64],exportViewportAsPng:[64],exportViewportAsSvg:[64],getSelectedObjectsAsSvgString:[64],exportSelectedObjectsAsSvg:[64],getSelectedObjectsAsPngDataUrl:[64],exportSelectedObjectsAsPng:[64],exportAsJson:[64],importFromJson:[64],loadObjectsFromJson:[64],downloadAsJson:[64],importFromFile:[64],createWorkspace:[64],updateWorkspace:[64],deleteWorkspace:[64],getWorkspaces:[64],getActiveWorkspace:[64],getIsPublic:[64],loadSharedWorkspace:[64],reinitSync:[64],saveSettings:[64],loadSettings:[64],registerLocales:[64],setLocale:[64],getLocale:[64],getAvailableLocales:[64],getAvailableLocaleOptions:[64],t:[64],getResolvedTerms:[64]},[[1,"wheel","handleWheel"],[0,"pointerdown","handlePointerDown"],[0,"pointermove","handlePointerMove"],[0,"pointerup","handlePointerUp"],[0,"pointercancel","handlePointerCancel"],[1,"pointerleave","handlePointerLeave"],[1,"longpress","handleLongPress"],[0,"contextmenu","handleContextMenu"],[9,"resize","handleResize"],[8,"keydown","handleKeyDown"],[8,"keyup","handleKeyUp"],[8,"copy","handleCopy"],[8,"cut","handleCut"],[8,"paste","handlePaste"],[4,"dblclick","preventDoubleTapZoomOnTouchDevices"]],{workspace:[{onWorkspaceChange:0}],activeWorkspaceId:[{onActiveWorkspaceIdChange:0}],syncConfig:[{onSyncConfigChange:0}],assetStorageConfig:[{onAssetStorageConfigChange:0}],user:[{onUserChange:0}],globalContextMenuItems:[{onGlobalContextMenuItemsChange:0}],objectContextMenuItems:[{onObjectContextMenuItemsChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}],lockDrawingScale:[{onLockDrawingScaleChange:0}],isObjectDistanceFadingActive:[{onIsObjectDistanceFadingActiveChange:0}],theme:[{onThemeChange:0}],licenseKey:[{onLicenseKeyChange:0}],themes:[{onThemesChange:0}],locale:[{onLocaleChange:0}],locales:[{onLocalesChange:0}],fallbackLocale:[{onFallbackLocaleChange:0}],viewportBoundaryLeft:[{onViewportBoundaryLeftChange:0}],viewportBoundaryRight:[{onViewportBoundaryRightChange:0}],viewportBoundaryTop:[{onViewportBoundaryTopChange:0}],viewportBoundaryBottom:[{onViewportBoundaryBottomChange:0}],debugInfo:[{onDebugInfoChange:0}],isLoading:[{onIsLoadingChange:0}]}]);function nn(){"undefined"!=typeof customElements&&["kritzel-engine","kritzel-awareness-cursors","kritzel-context-menu","kritzel-cursor-trail","kritzel-icon","kritzel-watermark"].forEach((t=>{switch(t){case"kritzel-engine":customElements.get(s(t))||customElements.define(s(t),en);break;case"kritzel-awareness-cursors":customElements.get(s(t))||G();break;case"kritzel-context-menu":customElements.get(s(t))||D();break;case"kritzel-cursor-trail":customElements.get(s(t))||H();break;case"kritzel-icon":customElements.get(s(t))||V();break;case"kritzel-watermark":customElements.get(s(t))||C()}}))}export{Xt as A,Wt as D,Rt as E,Ut as F,Z as K,Yt as W,q as a,J as b,tt as c,Lt as d,Ot as e,Pt as f,Bt as g,Vt as h,Nt as i,Q as j,Gt as k,Qt as l,nn as m,en as n,Ht as r}
|
|
9
|
+
*/class ne{_core;_debounceUpdate;_debounceEndScaling;_animationFrameId=null;initialTouchDistance=0;startX=0;startY=0;static TOUCH_CURSOR_BROADCAST_THRESHOLD=5;_touchStartScreenX=0;_touchStartScreenY=0;_touchCursorBroadcastActive=!1;constructor(t,e){this._core=t,this._core.store.state.host=e,this._core.store.state.viewportWidth=e.clientWidth,this._core.store.state.viewportHeight=e.clientHeight,this._core.store.state.startX=0,this._core.store.state.startY=0,this._core.store.state.translateX=0,this._core.store.state.translateY=0,this._debounceUpdate=ee.debounce((()=>{this._core.updateWorkspaceViewport(this._core.store.state.translateX,this._core.store.state.translateY,this._core.store.state.scale)}),300),this._debounceEndScaling=ee.debounce((()=>{this._core.store.state.isScaling=!1,this._core.rerender()}),100)}cancelPendingUpdates(){this._debounceUpdate.cancel()}clampTranslate(t,e){const n=this._core.store.state,{scale:i,viewportWidth:r,viewportHeight:s}=n,{viewportBoundaryLeft:o,viewportBoundaryRight:a,viewportBoundaryTop:c,viewportBoundaryBottom:l}=n,h=-o*i,u=r-a*i,f=-c*i,d=s-l*i;let p=t,g=e;return Number.isFinite(u)&&Number.isFinite(h)?p=Math.max(u,Math.min(h,t)):Number.isFinite(u)?p=Math.max(u,t):Number.isFinite(h)&&(p=Math.min(h,t)),Number.isFinite(d)&&Number.isFinite(f)?g=Math.max(d,Math.min(f,e)):Number.isFinite(d)?g=Math.max(d,e):Number.isFinite(f)&&(g=Math.min(f,e)),{translateX:p,translateY:g}}getEffectiveMinScale(){const t=this._core.store.state,{viewportWidth:e,viewportHeight:n,scaleMin:i}=t,{viewportBoundaryLeft:r,viewportBoundaryRight:s,viewportBoundaryTop:o,viewportBoundaryBottom:a}=t,c=s-r,l=a-o;if(!Number.isFinite(c)||!Number.isFinite(l))return i;const h=Math.max(c>0?e/c:i,l>0?n/l:i);return Math.max(i,h)}handleResize(){this._core.store.state.viewportWidth=this._core.store.host.clientWidth,this._core.store.state.viewportHeight=this._core.store.host.clientHeight,this._core.store.state.hasViewportChanged=!0,this._core.rerender()}handlePointerDown(t){if(this.cancelViewportAnimation(),"mouse"===t.pointerType){const e=t.clientX-this._core.store.offsetX,n=t.clientY-this._core.store.offsetY;t.button===o.Right&&(this._core.store.state.isPanning=!0,this._core.store.state.startX=e,this._core.store.state.startY=n)}if("touch"===t.pointerType||"pen"===t.pointerType){const e=Array.from(this._core.store.state.pointers.values());if(1===e.length&&(this._touchStartScreenX=t.clientX,this._touchStartScreenY=t.clientY,this._touchCursorBroadcastActive=!1),2===e.length){this._core.store.objects?.clearCursorPosition();const t=this._core.store.currentPath;t&&this._core.store.objects.remove((e=>e.id===t.id)),this._core.store.state.isSelecting&&(this._core.store.state.isSelecting=!1,this._core.store.objects.remove((t=>t instanceof g)),this._core.store.setSelectionBox(null),this._core.store.selectedObjects.forEach((t=>{t.isSelected=!1}))),this._core.store.state.isScaling=!0;const n=e[0].clientX-this._core.store.offsetX,i=e[0].clientY-this._core.store.offsetY,r=e[1].clientX-this._core.store.offsetX,s=e[1].clientY-this._core.store.offsetY;this.initialTouchDistance=Math.sqrt(Math.pow(n-r,2)+Math.pow(i-s,2)),this.startX=(n+r)/2,this.startY=(i+s)/2,this._core.rerender()}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.host.getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top;if(this._core.store.state.pointerX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale,this._core.store.objects?.updateCursorPosition(this._core.store.state.pointerX,this._core.store.state.pointerY),this._core.store.state.isPanning){const t=this.clampTranslate(this._core.store.state.translateX+(n-this._core.store.state.startX),this._core.store.state.translateY+(i-this._core.store.state.startY));this._core.store.state.translateX=t.translateX,this._core.store.state.translateY=t.translateY,this._core.store.state.startX=n,this._core.store.state.startY=i,this._core.store.state.hasViewportChanged=!0,this._core.store.state.skipContextMenu=!0,this._core.rerender(),this._debounceUpdate()}}if("touch"===t.pointerType||"pen"===t.pointerType){const e=this._core.store.host.getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top,r=Array.from(this._core.store.state.pointers.values());if(this._core.store.state.isScaling||r.length>1)this._core.store.objects?.clearCursorPosition();else{if(this._core.store.state.pointerX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale,!this._touchCursorBroadcastActive){const e=t.clientX-this._touchStartScreenX,n=t.clientY-this._touchStartScreenY;Math.sqrt(e*e+n*n)>=ne.TOUCH_CURSOR_BROADCAST_THRESHOLD&&(this._touchCursorBroadcastActive=!0)}this._touchCursorBroadcastActive&&this._core.store.objects?.updateCursorPosition(this._core.store.state.pointerX,this._core.store.state.pointerY)}if(2===r.length){const t=r[0].clientX-this._core.store.offsetX,e=r[0].clientY-this._core.store.offsetY,n=r[1].clientX-this._core.store.offsetX,i=r[1].clientY-this._core.store.offsetY,s=Math.sqrt(Math.pow(t-n,2)+Math.pow(e-i,2)),o=(t+n)/2,a=(e+i)/2,c=s/this.initialTouchDistance,l=this._core.store.state.scale*c,h=this.getEffectiveMinScale();if(l>this._core.store.state.scaleMax||l<h){const t=this.clampTranslate(this._core.store.state.translateX+o-this.startX,this._core.store.state.translateY+a-this.startY);this._core.store.state.translateX=t.translateX,this._core.store.state.translateY=t.translateY}else{const t=this._core.store.state.translateX+o-this.startX-(o-this._core.store.state.translateX)*(c-1),e=this._core.store.state.translateY+a-this.startY-(a-this._core.store.state.translateY)*(c-1);this._core.store.state.scale=l;const n=this.clampTranslate(t,e);this._core.store.state.translateX=n.translateX,this._core.store.state.translateY=n.translateY,this.initialTouchDistance=s}this.startX=o,this.startY=a,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isPanning&&(this._core.store.state.isPanning=!1,this._core.rerender()),"touch"!==t.pointerType&&"pen"!==t.pointerType||(this._touchCursorBroadcastActive=!1,0===this._core.store.state.pointers.size&&this._debounceEndScaling())}handleWheel(t){this.cancelViewportAnimation(),t.ctrlKey?this.handleZoom(t):this.handlePan(t)}getViewport(){const t=this._core.store.state;return{translateX:t.translateX,translateY:t.translateY,scale:t.scale,width:t.viewportWidth,height:t.viewportHeight}}screenToWorld(t,e){const n=this._core.store.state;return{x:(t-n.translateX)/n.scale,y:(e-n.translateY)/n.scale}}worldToScreen(t,e){const n=this._core.store.state;return{x:t*n.scale+n.translateX,y:e*n.scale+n.translateY}}setViewport(t,e,n){const i=this._core.store.state,r=Math.min(i.scaleMax,Math.max(this.getEffectiveMinScale(),n));this.animateViewportTo(i.viewportWidth/2-t*r,i.viewportHeight/2-e*r,r)}panTo(t,e){this.setViewport(t,e,this._core.store.state.scale)}zoomTo(t,e,n){const i=this._core.store.state;void 0!==e&&void 0!==n?this.setViewport(e,n,t):this.setViewport((i.viewportWidth/2-i.translateX)/i.scale,(i.viewportHeight/2-i.translateY)/i.scale,t)}zoomIn(t,e){this.animateZoomAroundViewportCenter(t,e)}zoomOut(t,e){this.animateZoomAroundViewportCenter(1/t,e)}animateZoomAroundViewportCenter(t,e){this.cancelViewportAnimation();const n=this._core.store.state,i=n.scale,r=this.getEffectiveMinScale(),s=Math.min(n.scaleMax,Math.max(r,i*t)),o=n.viewportWidth/2,a=n.viewportHeight/2,c=(o-n.translateX)/i,l=(a-n.translateY)/i;if(s===i||e<=0)return this.applyZoomAroundCenter(s,o,a,c,l),n.isScaling=!0,this._core.rerender(),this._debounceUpdate(),void this._debounceEndScaling();const h=performance.now();n.isScaling=!0;const u=t=>{const r=Math.min((t-h)/e,1),f=r<.5?4*r*r*r:1-Math.pow(-2*r+2,3)/2;this.applyZoomAroundCenter(i+(s-i)*f,o,a,c,l),this._core.rerender(),r<1?this._animationFrameId=requestAnimationFrame(u):(this._animationFrameId=null,n.isScaling=!1,this._core.rerender(),this._debounceUpdate())};this._animationFrameId=requestAnimationFrame(u)}applyZoomAroundCenter(t,e,n,i,r){const s=this._core.store.state;s.scale=t;const o=this.clampTranslate(e-i*t,n-r*t);s.translateX=o.translateX,s.translateY=o.translateY,s.hasViewportChanged=!0}centerInViewport(t){const{scale:e,viewportWidth:n,viewportHeight:i}=this._core.store.state,{x:r,y:s,width:o,height:a}=t.rotatedBoundingBox,c=this.clampTranslate(n/2-(r+o/2)*e,i/2-(s+a/2)*e);this._core.store.state.translateX=c.translateX,this._core.store.state.translateY=c.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}centerFitInViewport(t){const e=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),n=Math.max(e,this.getEffectiveMinScale());this._core.store.state.scale=n,this.centerInViewport(t)}centerFitInViewportIfNeeded(t){const e=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),n=Math.max(e,this.getEffectiveMinScale());n<this._core.store.state.scale&&(this._core.store.state.scale=n),this.centerInViewport(t)}fitInViewportIfNeeded(t){const e=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),n=Math.max(e,this.getEffectiveMinScale());n<this._core.store.state.scale&&(this._core.store.state.scale=n,this.centerInViewport(t))}bringIntoViewIfNeeded(t){const{scale:e,translateX:n,translateY:i,viewportWidth:r,viewportHeight:s}=this._core.store.state,o=t.rotatedBoundingBox;if(o.x*e+n>=0&&o.y*e+i>=0&&(o.x+o.width)*e+n<=r&&(o.y+o.height)*e+i<=s)return;const a=Math.min(r/(1.1*o.width),s/(1.1*o.height),this._core.store.state.scaleMax),c=Math.max(a,this.getEffectiveMinScale()),l=Math.min(c,e),h=this.clampTranslate(r/2-(o.x+o.width/2)*l,s/2-(o.y+o.height/2)*l);this.animateViewportTo(h.translateX,h.translateY,l)}handleZoom(t){this._core.store.state.isScaling=!0;const e=this._core.store.host.getBoundingClientRect(),n=t.clientX-e.left,i=t.clientY-e.top;this._core.store.state.pointerX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale,this._core.store.objects?.updateCursorPosition(this._core.store.state.pointerX,this._core.store.state.pointerY);const r=Math.max(.8,Math.min(1.2,1+-.012*t.deltaY)),s=this.getEffectiveMinScale(),o=Math.min(this._core.store.state.scaleMax,Math.max(s,this._core.store.state.scale*r)),a=o/this._core.store.state.scale,c=(n-this._core.store.state.translateX)*(a-1),l=(i-this._core.store.state.translateY)*(a-1);this._core.store.state.scale=o;let h=this._core.store.state.translateX-c;0!==t.deltaX&&(h-=.8*t.deltaX);const u=this.clampTranslate(h,this._core.store.state.translateY-l);this._core.store.state.translateX=u.translateX,this._core.store.state.translateY=u.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate(),this._debounceEndScaling()}handlePan(t){const e=this.clampTranslate(this._core.store.state.translateX-.8*t.deltaX,this._core.store.state.translateY-.8*t.deltaY);this._core.store.state.translateX=e.translateX,this._core.store.state.translateY=e.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}cancelViewportAnimation(){null!==this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}animateViewportTo(t,e,n,i=150){this.cancelViewportAnimation();const r=this._core.store.state.translateX,s=this._core.store.state.translateY,o=this._core.store.state.scale,a=performance.now();this._core.store.state.isScaling=!0;const c=l=>{const h=Math.min((l-a)/i,1),u=1-Math.pow(1-h,3);this._core.store.state.scale=o+(n-o)*u;const f=this.clampTranslate(r+(t-r)*u,s+(e-s)*u);this._core.store.state.translateX=f.translateX,this._core.store.state.translateY=f.translateY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),h<1?this._animationFrameId=requestAnimationFrame(c):(this._animationFrameId=null,this._core.store.state.isScaling=!1,this._core.rerender(),this._debounceUpdate())};this._animationFrameId=requestAnimationFrame(c)}centerFitNearestContent(t=20){const e=this._core.store.allNonSelectionObjects;if(0===e.length)return!1;const n=-this._core.store.state.translateX/this._core.store.state.scale+this._core.store.state.viewportWidth/2/this._core.store.state.scale,i=-this._core.store.state.translateY/this._core.store.state.scale+this._core.store.state.viewportHeight/2/this._core.store.state.scale,r=e.map((t=>{const e=t.rotatedBoundingBox,r=e.y+e.height/2;return{obj:t,distance:Math.sqrt(Math.pow(e.x+e.width/2-n,2)+Math.pow(r-i,2))}}));r.sort(((t,e)=>t.distance-e.distance));const s=r.slice(0,t).map((t=>t.obj));let o=1/0,a=1/0,c=-1/0,l=-1/0;for(const t of s){const e=t.rotatedBoundingBox;o=Math.min(o,e.x),a=Math.min(a,e.y),c=Math.max(c,e.x+e.width),l=Math.max(l,e.y+e.height)}const h=c-o,u=l-a,f=o+h/2,d=a+u/2,p=Math.min(this._core.store.state.viewportWidth/(1.1*h),this._core.store.state.viewportHeight/(1.1*u),this._core.store.state.scaleMax),g=Math.max(p,this.getEffectiveMinScale());return this.animateViewportTo(this._core.store.state.viewportWidth/2-f*g,this._core.store.state.viewportHeight/2-d*g,g),!0}centerFitObjects(t,e=!0){if(0===t.length)return!1;let n=1/0,i=1/0,r=-1/0,s=-1/0;for(const e of t){const t=e.rotatedBoundingBox;n=Math.min(n,t.x),i=Math.min(i,t.y),r=Math.max(r,t.x+t.width),s=Math.max(s,t.y+t.height)}const o=r-n,a=s-i,c=n+o/2,l=i+a/2,h=Math.min(this._core.store.state.viewportWidth/(1.1*o),this._core.store.state.viewportHeight/(1.1*a),this._core.store.state.scaleMax),u=Math.max(h,this.getEffectiveMinScale());return this.animateViewportTo(this._core.store.state.viewportWidth/2-c*u,this._core.store.state.viewportHeight/2-l*u,u,e?150:0),!0}centerFitAllObjects(t=!0){return this.centerFitObjects(this._core.store.allNonSelectionObjects,t)}}class ie extends v{shortcuts=[{key:"Escape",label:"Clear Selection",category:"General",condition:t=>!!t.store.activeText||!!t.store.activeShape||!!t.store.selectionGroup,action:t=>{t.store.activeText?t.store.activeText.handleEscape():t.store.activeShape?t.store.activeShape.handleEscape():t.clearSelection()}},{key:"Delete",label:"Delete Selected",category:"General",condition:t=>!!t.store.selectionGroup,action:t=>t.delete()},{key:"a",ctrl:!0,label:"Select All in Viewport",category:"General",action:t=>t.selectAllObjectsInViewport()},{key:"A",ctrl:!0,shift:!0,label:"Select All Objects",category:"General",action:t=>t.selectAllObjects()},{key:"z",ctrl:!0,label:"Undo",category:"Undo/Redo",action:t=>t.undo()},{key:"y",ctrl:!0,label:"Redo",category:"Undo/Redo",action:t=>t.redo()},{key:"1",ctrl:!0,label:"Tool 1",category:"Tool Selection",action:()=>this.switchToolByIndex(0)},{key:"2",ctrl:!0,label:"Tool 2",category:"Tool Selection",action:()=>this.switchToolByIndex(1)},{key:"3",ctrl:!0,label:"Tool 3",category:"Tool Selection",action:()=>this.switchToolByIndex(2)},{key:"4",ctrl:!0,label:"Tool 4",category:"Tool Selection",action:()=>this.switchToolByIndex(3)},{key:"5",ctrl:!0,label:"Tool 5",category:"Tool Selection",action:()=>this.switchToolByIndex(4)},{key:"6",ctrl:!0,label:"Tool 6",category:"Tool Selection",action:()=>this.switchToolByIndex(5)},{key:"7",ctrl:!0,label:"Tool 7",category:"Tool Selection",action:()=>this.switchToolByIndex(6)},{key:"8",ctrl:!0,label:"Tool 8",category:"Tool Selection",action:()=>this.switchToolByIndex(7)},{key:"9",ctrl:!0,label:"Tool 9",category:"Tool Selection",action:()=>this.switchToolByIndex(8)},{key:"+",ctrl:!0,label:"Bring Forward",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.bringForward()},{key:"-",ctrl:!0,label:"Send Backward",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.sendBackward()},{key:"*",shift:!0,label:"Bring to Front",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.bringToFront()},{key:"_",shift:!0,label:"Send to Back",category:"Object Layering",condition:t=>!!t.store.selectionGroup,action:t=>t.sendToBack()},{key:"g",ctrl:!0,label:"Group",category:"Grouping",condition:t=>!!t.store.selectionGroup&&t.store.selectionGroup.objects.length>=2,action:t=>t.group()},{key:"G",ctrl:!0,shift:!0,label:"Ungroup",category:"Grouping",condition:t=>!!t.store.selectionGroup,action:t=>t.ungroup()},{key:"ArrowUp",label:"Move Object Up",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(0,0,0,10),t.rerender()}},{key:"ArrowDown",label:"Move Object Down",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(0,10,0,0),t.rerender()}},{key:"ArrowLeft",label:"Move Object Left",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(0,0,10,0),t.rerender()}},{key:"ArrowRight",label:"Move Object Right",category:"Movement",condition:t=>!!t.store.selectionGroup,action:t=>{t.store.selectionGroup.move(10,0,0,0),t.rerender()}}];constructor(t){super(t)}switchToolByIndex(t){const e=this._core.toolRegistry.getToolByIndex(t);e&&(this._core.store.setState("activeTool",e),this._core.deselectAllObjects(),e.onActivate())}handleKeyDown(t){if(this._core.store.state.isCtrlKeyPressed=t.ctrlKey,(this._core.store.activeText||this._core.store.activeShape||this._core.store.activeInteractiveCustomElement)&&"Escape"!==t.key)return;const e=this.shortcuts.find((e=>e.key===t.key&&!!e.ctrl===t.ctrlKey&&!!e.shift===t.shiftKey&&(!e.condition||e.condition(this._core))));e&&(t.preventDefault(),e.action(this._core))}handleKeyUp(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey}getDisplayableShortcuts(){return this.shortcuts.map((({key:t,ctrl:e,shift:n,label:i,category:r})=>({key:t,ctrl:e,shift:n,label:i,category:r})))}}class re extends v{globalContextMenuItems=[];objectContextMenuItems=[];constructor(t,e,n){super(t),this.globalContextMenuItems=e,this.objectContextMenuItems=n}resolveLabels(t){return t.map((t=>({...t,label:this._core.localizationManager.translate(t.label),children:t.children?this.resolveLabels(t.children):void 0})))}getResolvedContextMenuItems(){return this.resolveLabels(this._core.store.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems)}handleContextMenu(t){if(!(this._core.store.state.activeTool instanceof w))return;if(this._core.store.state.skipContextMenu)return void(this._core.store.state.skipContextMenu=!1);const e=this._core.store.state.activeTool;e?.moveHandler?.cancelPendingDrag(),this._core.store.selectionBox&&(this._core.store.objects.remove((t=>t instanceof g)),this._core.store.setSelectionBox(null),this._core.store.state.isSelecting=!1);const n=this._core.getObjectFromPointerEvent(t,".object");if(n&&!(n instanceof h)&&!(n instanceof g)){const t=h.create(this._core);t.addOrRemove(n),t.isSelected=!0,t.rotation=n.rotation,this._core.store.state.isSelecting=!1,this._core.store.selectionGroup&&this._core.removeSelectionGroup(),this._core.addSelectionGroup(t),this._core.rerender()}this._core.store.state.contextMenuItems=this.getResolvedContextMenuItems();const i=t.clientX-this._core.store.offsetX,r=t.clientY-this._core.store.offsetY,{translateX:s,translateY:o,scale:a}=this._core.store.state;this._core.store.state.contextMenuWorldX=(i-s)/a,this._core.store.state.contextMenuWorldY=(r-o)/a;let c=i,l=r;c+150>this._core.store.state.viewportWidth-10&&(c=this._core.store.state.viewportWidth-150-10),c=Math.max(10,c),l=Math.max(10,l),this._core.store.state.contextMenuX=c,this._core.store.state.contextMenuY=l,this._core.store.state.isContextMenuVisible=!0,this._core.store.state.isEnabled=!1,this._core.rerender()}open(t){const{x:e,y:n,objectId:i}=t;if(this._core.store.state.activeTool instanceof w){const t=this._core.store.state.activeTool;t?.moveHandler?.cancelPendingDrag()}if(this._core.store.selectionBox&&(this._core.store.objects.remove((t=>t instanceof g)),this._core.store.setSelectionBox(null),this._core.store.state.isSelecting=!1),i){const t=this._core.store.allObjects.find((t=>t.id===i));if(t&&!(t instanceof h)&&!(t instanceof g)){const e=h.create(this._core);e.addOrRemove(t),e.isSelected=!0,e.rotation=t.rotation,this._core.store.state.isSelecting=!1,this._core.store.selectionGroup&&this._core.removeSelectionGroup(),this._core.addSelectionGroup(e)}}this._core.store.state.contextMenuItems=this.getResolvedContextMenuItems(),this._core.store.state.contextMenuWorldX=e,this._core.store.state.contextMenuWorldY=n;const{translateX:r,translateY:s,scale:o}=this._core.store.state;let a=e*o+r,c=n*o+s;a+150>this._core.store.state.viewportWidth-10&&(a=this._core.store.state.viewportWidth-150-10),a=Math.max(10,a),c=Math.max(10,c),this._core.store.state.contextMenuX=a,this._core.store.state.contextMenuY=c,this._core.store.state.isContextMenuVisible=!0,this._core.store.state.isEnabled=!1,this._core.rerender()}}class se{_core;constructor(t){this._core=t}revive(t){if(t&&"object"==typeof t){if(t.__class__){let e;switch(t.__class__){case"KritzelPath":e=_.create(this._core).deserialize(t);break;case"KritzelLine":e=L.create(this._core).deserialize(t);break;case"KritzelText":e=b.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelShape":e=d.create(this._core,{shapeType:t.shapeType,fillColor:t.fillColor,strokeColor:t.strokeColor,strokeWidth:t.strokeWidth,fontSize:t.fontSize,fontFamily:t.fontFamily,fontColor:t.fontColor}).deserialize(t);break;case"KritzelImage":e=u.create(this._core).deserialize(t);break;case"KritzelCustomElement":e=Z.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":e=h.create(this._core).deserialize(t);break;case"KritzelGroup":e=y.create(this._core).deserialize(t);break;case"KritzelWorkspace":e=T.create(this._core,t).deserialize(t);break;case"KritzelBrushTool":e=new q(this._core);break;case"KritzelEraserTool":e=new tt(this._core);break;case"KritzelImageTool":e=new Lt(this._core);break;case"KritzelSelectionTool":e=new w(this._core);break;case"KritzelTextTool":e=new m(this._core);break;case"KritzelLineTool":e=new J(this._core);break;case"KritzelShapeTool":e=new Ot(this._core);break;default:e=t}return e}const e=Array.isArray(t)?[]:{};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=this.revive(t[n]));return e}return t}}const oe={activeWorkspace:void 0,activeTool:null,objects:null,snapCandidate:null,snapPreviewCandidate:null,resizeHandleType:null,lineHandleType:null,hasViewportChanged:!1,hasObjectsChanged:!1,isReady:!1,isEnabled:!0,isScaling:!1,isPanning:!1,isSelecting:!1,isResizing:!1,isResizeHandleHovered:!1,isResizeHandleSelected:!1,isRotating:!1,isRotationHandleHovered:!1,isRotationHandleSelected:!1,isLineHandleSelected:!1,isLineHandleDragging:!1,isDragging:!1,isDrawing:!1,isErasing:!1,isWriting:!1,isLoading:!1,isCtrlKeyPressed:!1,isContextMenuVisible:!1,contextMenuItems:[],contextMenuX:0,contextMenuY:0,contextMenuWorldX:0,contextMenuWorldY:0,skipContextMenu:!1,debugInfo:{showObjectInfo:!1,showViewportInfo:!1,showSyncProviderInfo:!1,showAssetResolverInfo:!1,showMigrationInfo:!1},host:null,pointerX:0,pointerY:0,scale:1,scaleMax:1,scaleMin:1,startX:0,startY:0,translateX:0,translateXMax:400,translateXMin:0,translateY:0,translateYMax:400,translateYMin:0,viewportWidth:0,viewportHeight:0,longTouchTimeout:null,longTouchDelay:300,pointers:new Map,workspaces:[],cursor:{icon:"default",iconActive:"default"},lockDrawingScale:!0,viewportBoundaryLeft:-1/0,viewportBoundaryRight:1/0,viewportBoundaryTop:-1/0,viewportBoundaryBottom:1/0};class ae{static calculateSelectionBounds(t){const e=t.map((t=>t.rotatedBoundingBox));return{minX:Math.min(...e.map((t=>t.x))),minY:Math.min(...e.map((t=>t.y))),maxX:Math.max(...e.map((t=>t.x+t.width))),maxY:Math.max(...e.map((t=>t.y+t.height)))}}static calculateAlignedPositions(t,e){const n=new Map;if(t.length<2)return n;const i=this.calculateSelectionBounds(t);for(const r of t){const t=r.rotatedBoundingBox;let s=r.translateX,o=r.translateY;const a=t.x-r.translateX,c=t.y-r.translateY;switch(e){case Gt.StartHorizontal:s=i.minX-a;break;case Gt.CenterHorizontal:s=r.translateX+((i.minX+i.maxX)/2-(t.x+t.width/2));break;case Gt.EndHorizontal:s=r.translateX+(i.maxX-(t.x+t.width));break;case Gt.StartVertical:o=i.minY-c;break;case Gt.CenterVertical:o=r.translateY+((i.minY+i.maxY)/2-(t.y+t.height/2));break;case Gt.EndVertical:o=r.translateY+(i.maxY-(t.y+t.height))}n.set(r.id,{translateX:s,translateY:o})}return n}}class ce{core;registry={};constructor(t){this.core=t}registerTool(t,e){const n=new e(this.core);return n.name=t,this.registry[t]=n,n}hasTool(t){return t in this.registry}getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}getToolByIndex(t){return Object.values(this.registry)[t]??null}}class le{bounds;capacity;objects=[];children=null;_size=0;get size(){return this._size}constructor(t,e=16){this.bounds=t,this.capacity=e}reset(){this.objects=[],this.children=null,this._size=0}insert(t){if(!this.intersects(t.rotatedBoundingBox,this.bounds))return!1;if(this.objects.length<this.capacity&&null===this.children)return this.objects.push(t),this._size++,!0;null===this.children&&this.subdivide();for(const e of this.children)if(e.insert(t))return this._size++,!0;return!1}update(t){const e=this.objects.findIndex((e=>e.id===t.id));if(-1!==e)return this.objects[e]=t,!0;if(null!==this.children)for(const e of this.children)if(e.update(t))return!0;return!1}remove(t){let e=0;const n=this.objects.findIndex((e=>t(e)));if(-1!==n&&(this.objects.splice(n,1),e++),null!==this.children)for(const n of this.children)e+=n.remove(t);return this._size-=e,e}query(t){const e=[];return this._queryInto(t,e),e}_queryInto(t,e){if(this.intersects(t,this.bounds)){for(const n of this.objects)this.intersects(n.rotatedBoundingBox,t)&&e.push(n);if(null!==this.children)for(const n of this.children)n._queryInto(t,e)}}filter(t){const e=[];return this._filterInto(t,e),e}_filterInto(t,e){for(const n of this.objects)t(n)&&e.push(n);if(null!==this.children)for(const n of this.children)n._filterInto(t,e)}allObjects(){const t=[];return this._collectAllInto(t),t}_collectAllInto(t){for(const e of this.objects)t.push(e);if(null!==this.children)for(const e of this.children)e._collectAllInto(t)}subdivide(){const{x:t,y:e,z:n,width:i,height:r}=this.bounds,s=i/2,o=r/2;this.children=[new le({x:t,y:e,z:n,width:s,height:o},this.capacity),new le({x:t+s,y:e,z:n,width:s,height:o},this.capacity),new le({x:t,y:e+o,z:n,width:s,height:o},this.capacity),new le({x:t+s,y:e+o,z:n,width:s,height:o},this.capacity)]}intersects(t,e){return!(t.x>=e.x+e.width||t.x+t.width<=e.x||t.y>=e.y+e.height||t.y+t.height<=e.y)}}class he{quadtree;_ydoc=null;_objectsMap=null;_metadataMap=null;_providers=[];_undoManager=null;_reviver=null;_core=null;_workspaceId=null;_isReady=!1;_temporaryItemsCount=0;_idMap=new Map;_awareness=null;_objectsObserver=null;_stackItemAddedHandler=null;_stackItemPoppedHandler=null;_awarenessChangeHandler=null;_awarenessChangeCallbacks=[];_objectsChangeCallbacks=[];_lastAwarenessEmitTime=0;_awarenessEmitTimeout=null;AWARENESS_THROTTLE_INTERVAL=100;_localOnlyMode=!1;_inTransaction=!1;get isReady(){return this._isReady}get awareness(){return this._awareness}get hasAwareness(){return!!this._awareness}get localClientId(){return this._awareness?.clientID??null}setLocalUser(t){if(!this._awareness||!t)return;const e=t.displayName||t.firstName||"Anonymous";this._awareness.setLocalStateField("user",{id:t.id,displayName:e,color:t.color||this.generateColorFromName(e)})}generateColorFromName(t){let e=0;for(let n=0;n<t.length;n++)e=t.charCodeAt(n)+((e<<5)-e);return`hsl(${Math.abs(e%360)}, 45%, 55%)`}updateCursorPosition(t,e){this._awareness&&this._awareness.setLocalStateField("cursor",{x:t,y:e})}clearCursorPosition(){this._awareness&&this._awareness.setLocalStateField("cursor",null)}setActiveDrawingObject(t){this._awareness&&this._awareness.setLocalStateField("activeObjectId",t)}setLocalSelectionBox(t){this._awareness&&this._awareness.setLocalStateField("selectionBox",t)}clearLocalSelectionBox(){this._awareness&&this._awareness.setLocalStateField("selectionBox",null)}removeOrphanedSelectionGroups(){if(!this._awareness)return;const t=this._awareness.getStates(),e=new Set;t.forEach((t=>{const n=t.user?.id;n&&e.add(n)}));const n=this._core?.user?.id,i=this.quadtree.filter((t=>t instanceof h&&null!=t.userId&&t.userId!==n&&!e.has(t.userId)));for(const t of i)this.quadtree.remove((e=>e.id===t.id)),this._idMap.delete(t.id),this._objectsMap&&this._ydoc.transact((()=>{this._objectsMap.delete(t.id)}),"local");i.length>0&&(this._core?.store.invalidateSelectionCache(),this._core?.rerender())}onAwarenessChange(t){this._awarenessChangeCallbacks.push(t)}onObjectsChange(t){this._objectsChangeCallbacks.push(t)}get undoManager(){return this._undoManager}get workspaceId(){return this._workspaceId}get undoState(){return{canUndo:!!this._undoManager&&this._undoManager.canUndo(),canRedo:!!this._undoManager&&this._undoManager.canRedo(),undoStackSize:this._undoManager?this._undoManager.undoStack.length:0,redoStackSize:this._undoManager?this._undoManager.redoStack.length:0}}get totalCount(){return this.quadtree.size}findById(t){return this._idMap.get(t)}constructor(){this.quadtree=new le({x:-1/0,y:-1/0,z:0,width:1/0,height:1/0},8)}async initialize(t,e,n){this._core=t,this._workspaceId=e,this._reviver=new se(t),this._ydoc=new W.Doc,this._objectsMap=this._ydoc.getMap("objects"),this._metadataMap=this._ydoc.getMap("metadata");const i=t.editorId?`kritzel-workspace-${t.editorId}-${e}`:`kritzel-workspace-${e}`,r=n??Qt,s=!!t.store?.state?.debugInfo?.showSyncProviderInfo,o=!s;for(const t of r.providers){let e;e="function"==typeof t?new t(i,this._ydoc,{quiet:o}):t.create(i,this._ydoc,{quiet:o}),this._providers.push(e)}if(s){const t=this._providers.map((t=>`${t.constructor.name} (${t.type})`)).join(", ");console.info(`[Kritzel] Workspace sync providers initialized for ${i}: ${t||"none"}`)}this._undoManager=new W.UndoManager([this._objectsMap],{captureTimeout:Number.MAX_SAFE_INTEGER,trackedOrigins:new Set(["local","temporary"]),ignoreRemoteMapChanges:!0}),this._stackItemAddedHandler=t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount++},this._stackItemPoppedHandler=t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount>0&&this._temporaryItemsCount--},this._undoManager.on("stack-item-added",this._stackItemAddedHandler),this._undoManager.on("stack-item-popped",this._stackItemPoppedHandler),this._objectsObserver=t=>{this.handleObjectsChange(t)},this._objectsMap.observe(this._objectsObserver);const a=this._providers.filter((t=>"local"===t.type)),c=this._providers.filter((t=>"network"===t.type)),l=await Promise.allSettled(a.map((t=>t.connect())));if(s){const t=l.filter((t=>"fulfilled"===t.status)).length;console.info(`[Kritzel] Workspace local providers connected: ${t}/${a.length}`)}l.forEach(((t,e)=>{s&&"rejected"===t.status&&console.error(`[Kritzel] Sync provider "${a[e]?.constructor.name}" failed to connect:`,t.reason)})),s&&c.length>0&&console.info(`[Kritzel] Workspace network providers connecting in background: ${c.length}`);for(const t of c)t.connect().catch((e=>{s&&console.error(`[Kritzel] Network sync provider "${t.constructor.name}" failed to connect:`,e)}));this._isReady=!0;for(const t of c)if(t.awareness){this._awareness=t.awareness;break}this._awareness&&(this._awarenessChangeHandler=t=>{t.removed.length>0&&this.removeOrphanedSelectionGroups();const e=Date.now(),n=e-this._lastAwarenessEmitTime;if(null!==this._awarenessEmitTimeout&&(clearTimeout(this._awarenessEmitTimeout),this._awarenessEmitTimeout=null),n>=this.AWARENESS_THROTTLE_INTERVAL){this._lastAwarenessEmitTime=e;const t=this._awareness.getStates();for(const e of this._awarenessChangeCallbacks)e(t)}else this._awarenessEmitTimeout=setTimeout((()=>{this._lastAwarenessEmitTime=Date.now(),this._awarenessEmitTimeout=null;const t=this._awareness.getStates();for(const e of this._awarenessChangeCallbacks)e(t)}),this.AWARENESS_THROTTLE_INTERVAL-n)},this._awareness.on("change",this._awarenessChangeHandler)),this.initializeMetadata("workspace",e,t.store?.state?.activeWorkspace?.name??""),Ht(this._ydoc,this._metadataMap,{objects:this._objectsMap},Yt,U,{quiet:!t.store?.state?.debugInfo?.showMigrationInfo}),this.loadFromYjs()}handleObjectsChange(t){if("local"===t.transaction.origin||"temporary"===t.transaction.origin)return void this._core?.rerender();if("migration"===t.transaction.origin)return;const e=Array.from(t.keysChanged),n=[],i=[],r=[];e.forEach((e=>{const s=t.changes.keys.get(e);if(s&&"delete"===s.action)r.push(e);else{const t=this._objectsMap?.get(e);if(t){const e=this._reviver?.revive(t);e instanceof h?i.push(e):n.push(e)}}})),r.forEach((t=>{const e=this._idMap.get(t);e instanceof h&&e.deselectAllChildren?.(),this.quadtree.remove((e=>e.id===t)),this._idMap.delete(t)}));const s=[],o=[];n.forEach((t=>{if(this._idMap.has(t.id)){const e=this._idMap.get(t.id);e&&"function"==typeof t.adoptTransientStateFrom&&t.adoptTransientStateFrom(e),this.quadtree.update(t),this._idMap.set(t.id,t),o.push(t)}else this.quadtree.insert(t),this._idMap.set(t.id,t),s.push(t)}));const a=new Set;if(i.forEach((t=>{if(this._idMap.has(t.id)){const e=this._idMap.get(t.id);e&&"function"==typeof t.adoptTransientStateFrom&&t.adoptTransientStateFrom(e),this.quadtree.update(t),this._idMap.set(t.id,t)}else this.quadtree.insert(t),this._idMap.set(t.id,t);a.add(t.id),t.invalidateObjectsCache(),t.refreshObjectDimensions(void 0,!0),t.captureUnchangedSnapshots(),this.quadtree.update(t)})),n.length>0||r.length>0){const t=new Set([...n.map((t=>t.id)),...r]),e=this.quadtree.filter((t=>t instanceof h&&!a.has(t.id)));for(const n of e)n.objectIds.some((e=>t.has(e)))&&(n.invalidateObjectsCache(),n.refreshObjectDimensions(void 0,!0),n.captureUnchangedSnapshots(),this.quadtree.update(n))}if(this._core?.store.invalidateSelectionCache(),this._core?.rerender(),s.length>0&&this._core?.engine.emitObjectsAdded(s),r.length>0){const t=r.map((t=>({id:t})));this._core?.engine.emitObjectsRemoved(t)}o.length>0&&this._core?.engine.emitObjectsUpdated(o.map((t=>({object:t,changedProperties:[]}))));for(const t of this._objectsChangeCallbacks)t()}initializeMetadata(t,e,n){this._metadataMap&&this._ydoc&&this._ydoc.transact((()=>{this._metadataMap?.get("type")||this._metadataMap?.set("type",t),void 0===this._metadataMap?.get("isPublic")&&this._metadataMap?.set("isPublic",!1),void 0===this._metadataMap?.get("schemaVersion")&&this._metadataMap?.set("schemaVersion",U),this._metadataMap?.set("workspaceId",e),this._metadataMap?.set("workspaceName",n)}),"metadata")}getIsPublic(){return this._metadataMap?.get("isPublic")??!1}setIsPublic(t){this._metadataMap&&this._ydoc&&this._ydoc?.transact((()=>{this._metadataMap?.set("isPublic",t)}),"metadata")}getDocumentType(){return this._metadataMap?.get("type")??"workspace"}getWorkspaceName(){return this._metadataMap?.get("workspaceName")??""}setWorkspaceName(t){this._metadataMap&&this._ydoc&&this._ydoc?.transact((()=>{this._metadataMap?.set("workspaceName",t)}),"metadata")}getMetadataWorkspaceId(){return this._metadataMap?.get("workspaceId")??""}transaction(t){if(this._ydoc){this._inTransaction=!0;try{this._ydoc.transact(t,"local")}finally{this._inTransaction=!1}}}stopUndoCapturing(){this.markUndoBoundary()}markUndoBoundary(){this._inTransaction||this._undoManager?.stopCapturing()}withLocalUpdatesOnly(t){this._localOnlyMode=!0;try{t()}finally{this._localOnlyMode=!1}}loadFromYjs(){if(!this._objectsMap||!this._reviver)return;this.quadtree.reset(),this._idMap.clear();const t=this._core?.user?.id,e=[];this._objectsMap.forEach(((n,i)=>{const r=this._reviver?.revive(n);r instanceof h&&null!=r.userId&&r.userId!==t?e.push(i):r&&(this.quadtree.insert(r),this._idMap.set(r.id,r))})),e.length>0&&this._ydoc.transact((()=>{for(const t of e)this._objectsMap.delete(t)}),"local")}reset(){this.quadtree.reset(),this._idMap.clear(),this.markUndoBoundary(),this._ydoc?.transact((()=>{this._objectsMap?.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.quadtree.insert(t),this._idMap.set(t.id,t),this._objectsMap&&this.isPersistable(t)){const e=t.serialize();this.markUndoBoundary(),this._ydoc?.transact((()=>{this._objectsMap?.set(t.id,e)}),"local")}return!0}update(t,e={}){if(!t.id)return!1;if(!this._idMap.has(t.id))return!1;if(this.quadtree.update(t),this._idMap.set(t.id,t),!this._localOnlyMode&&this._objectsMap&&this.isPersistable(t)){const n=t.serialize(),i=e.temporary?"temporary":"local";this._ydoc?.transact((()=>{this._objectsMap?.set(t.id,n)}),i)}return!0}remove(t){const e=this.quadtree.filter(t);if(0!==e.length){this.markUndoBoundary();for(const t of e)this.quadtree.remove((e=>e.id===t.id)),this._idMap.delete(t.id),this._objectsMap&&this.isPersistable(t)&&this._ydoc?.transact((()=>{this._objectsMap?.delete(t.id)}),"local")}}filter(t){return this.quadtree.filter(t)}allObjects(){return this.quadtree.allObjects()}query(t){return this.quadtree.query(t)}isPersistable(t){return!(t instanceof g)}undo(){this._undoManager&&this._undoManager.canUndo()&&(this._undoManager.undo(),this._core?.engine.emitObjectsChange())}redo(){this._undoManager&&this._undoManager.canRedo()&&(this._undoManager.redo(),this._core?.engine.emitObjectsChange())}canUndo(){return!!this._undoManager&&this._undoManager.canUndo()}canRedo(){return!!this._undoManager&&this._undoManager.canRedo()}clearHistory(){this._undoManager&&(this._undoManager.clear(),this._temporaryItemsCount=0)}consolidateTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=this._undoManager.undoStack.length;if(0===t)return void(this._temporaryItemsCount=0);this._undoManager.stopCapturing();const e=Math.min(this._temporaryItemsCount,t);if(e>1){for(let t=0;t<e;t++)this._undoManager.canUndo()&&this._undoManager.undo();this._ydoc?.transact((()=>{for(let t=e-1;t>=0;t--)this._undoManager?.canRedo()&&this._undoManager.redo()}),"local")}this._temporaryItemsCount=0}clearTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=Math.min(this._temporaryItemsCount,this._undoManager.undoStack.length);for(let e=0;e<t;e++)this._undoManager.undoStack.length>0&&this._undoManager.undoStack.pop();this._temporaryItemsCount=0}destroy(){this._objectsMap&&this._objectsObserver&&(this._objectsMap.unobserve(this._objectsObserver),this._objectsObserver=null),this._undoManager&&(this._stackItemAddedHandler&&(this._undoManager.off("stack-item-added",this._stackItemAddedHandler),this._stackItemAddedHandler=null),this._stackItemPoppedHandler&&(this._undoManager.off("stack-item-popped",this._stackItemPoppedHandler),this._stackItemPoppedHandler=null),this._undoManager.destroy(),this._undoManager=null),this.quadtree.reset(),this._idMap.clear(),this._awareness&&this._awarenessChangeHandler&&(this._awareness.off("change",this._awarenessChangeHandler),this._awarenessChangeHandler=null),null!==this._awarenessEmitTimeout&&(clearTimeout(this._awarenessEmitTimeout),this._awarenessEmitTimeout=null),this._awareness=null,this._awarenessChangeCallbacks=[],this._providers.forEach((t=>{t.destroy()})),this._providers=[],this._objectsMap=null,this._metadataMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._core=null,this._reviver=null,this._workspaceId=null,this._isReady=!1,this._temporaryItemsCount=0}}class ue{_state;_listeners=new Map;_cachedSelectionBox=null;_cachedSelectionGroup=null;_selectionBoxCacheValid=!1;_selectionGroupCacheValid=!1;_localUserId=null;get state(){return this._state}get objects(){if(!this._state.objects)throw new Error("Objects map is not initialized.");return this._state.objects}get host(){if(!this._state.host)throw new Error("Host element is not set.");return this._state.host}get currentZIndex(){return Math.max(0,...this.objects.filter((t=>!(t instanceof h||t instanceof g))).map((t=>t.zIndex)))+1}get hasViewportBoundaries(){return Number.isFinite(this._state.viewportBoundaryLeft)||Number.isFinite(this._state.viewportBoundaryRight)||Number.isFinite(this._state.viewportBoundaryTop)||Number.isFinite(this._state.viewportBoundaryBottom)}get viewportBoundaryBounds(){const t=this._state.viewportBoundaryLeft,e=this._state.viewportBoundaryRight,n=this._state.viewportBoundaryTop,i=this._state.viewportBoundaryBottom;return{x:Number.isFinite(t)?t:-1/0,y:Number.isFinite(n)?n:-1/0,z:0,width:Number.isFinite(t)&&Number.isFinite(e)?e-t:1/0,height:Number.isFinite(n)&&Number.isFinite(i)?i-n:1/0}}get totalObjectCount(){return this.hasViewportBoundaries?this.allObjects.length:this.objects.totalCount}get allObjects(){return this.hasViewportBoundaries?this.objects.query(this.viewportBoundaryBounds):this.objects.allObjects()}get objectsInViewport(){return this.objects.query({x:-this._state.translateX/this._state.scale,y:-this._state.translateY/this._state.scale,z:this._state.scale,width:this._state.viewportWidth/this._state.scale,height:this._state.viewportHeight/this._state.scale,depth:100}).sort(((t,e)=>t.zIndex-e.zIndex))}get allNonSelectionObjects(){return this.allObjects.filter((t=>!(t instanceof h||t instanceof g)))}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof h))).filter((t=>t.isSelected))}get selectionBox(){if(this._selectionBoxCacheValid)return this._cachedSelectionBox;const t=this.objects.filter((t=>t instanceof g));return this._cachedSelectionBox=t.length>0?t[0]:null,this._selectionBoxCacheValid=!0,this._cachedSelectionBox}get selectionGroup(){if(this._selectionGroupCacheValid)return this._cachedSelectionGroup;const t=this.objects.filter((t=>t instanceof h));return this._cachedSelectionGroup=this._localUserId?t.find((t=>t.userId===this._localUserId))??null:t.length>0?t[0]:null,this._selectionGroupCacheValid=!0,this._cachedSelectionGroup}invalidateSelectionCache(){this._selectionBoxCacheValid=!1,this._selectionGroupCacheValid=!1}setSelectionBox(t){this._cachedSelectionBox=t,this._selectionBoxCacheValid=!0}setSelectionGroup(t){this._cachedSelectionGroup=t,this._selectionGroupCacheValid=!0}setLocalUserId(t){this._localUserId=t,this.invalidateSelectionCache()}get activeText(){const t=this.objects.filter((t=>t instanceof b&&t.isEditing));return t.length>0?t[0]:null}get activeShape(){const t=this.objects.filter((t=>t instanceof d&&t.isEditing));return t.length>0?t[0]:null}get activeInteractiveCustomElement(){return this.selectedObjects.find((t=>p.isInstanceOf(t,"KritzelCustomElement")&&t.hasFocusedInputElement()))??null}get currentPath(){const t=this.objects.filter((t=>t instanceof _&&!1===t.isCompleted));return t.length>0?t[0]:null}get currentLine(){const t=this.objects.filter((t=>t instanceof L&&!1===t.isCompleted));return t.length>0?t[0]:null}get offsetX(){return this.host.getBoundingClientRect().left}get offsetY(){return this.host.getBoundingClientRect().top}get isDisabled(){return!1===this._state.isEnabled||!1===this._state.isReady||null===this._state.activeWorkspace}get isPointerDown(){return this._state.pointers.size>0}constructor(t){this._state={...t,contextMenuItems:[...t.contextMenuItems],debugInfo:{...t.debugInfo},pointers:new Map(t.pointers),workspaces:[...t.workspaces],cursor:{...t.cursor}},this._state.objects=new he}onStateChange(t,e){this._listeners.has(t)||this._listeners.set(t,new Set);const n=this._listeners.get(t);if(!n)throw new Error(`Listeners set for property ${String(t)} was not initialized.`);n.add(e)}getState(t){return this._state[t]}setState(t,e){const n=this._state[t];if(n!==e){this._state[t]=e;const i=this._listeners.get(t);i&&i.forEach((i=>i(e,n,String(t))))}}}class fe{map;_ydoc=null;_workspacesMap=null;_metadataMap=null;_providers=[];_core=null;_isReady=!1;_onRemoteChangeCallback=null;_workspacesObserver=null;get isReady(){return this._isReady}get hasNetworkSyncProvider(){return this._providers.some((t=>"network"===t.type))}constructor(){this.map=new Map}onRemoteChange(t){this._onRemoteChangeCallback=t}async initialize(t,e){this._core=t,this._ydoc=new W.Doc,this._workspacesMap=this._ydoc.getMap("workspaces"),this._metadataMap=this._ydoc.getMap("metadata");const n=e?.appStateId??this.getOrCreateAppStateInstanceId(t),i=t.editorId?`kritzel-app-state-${t.editorId}-${n}`:`kritzel-app-state-${n}`,r=e??Qt,s=!!t.store.state.debugInfo.showSyncProviderInfo,o=!s;for(const t of r.providers){let e;e="function"==typeof t?new t(i,this._ydoc,{quiet:o}):t.create(i,this._ydoc,{quiet:o}),this._providers.push(e)}if(s){const t=this._providers.map((t=>`${t.constructor.name} (${t.type})`)).join(", ");console.info(`[Kritzel] App-state sync providers initialized for ${i}: ${t||"none"}`)}this._workspacesObserver=t=>{this.handleWorkspacesChange(t)},this._workspacesMap.observe(this._workspacesObserver);const a=this._providers.filter((t=>"local"===t.type)),c=this._providers.filter((t=>"network"===t.type)),l=await Promise.allSettled(a.map((t=>t.connect())));if(s){const t=l.filter((t=>"fulfilled"===t.status)).length;console.info(`[Kritzel] App-state local providers connected: ${t}/${a.length}`)}l.forEach(((t,e)=>{s&&"rejected"===t.status&&console.error(`[Kritzel] Sync provider "${a[e]?.constructor.name}" failed to connect:`,t.reason)})),s&&c.length>0&&console.info(`[Kritzel] App-state network providers connecting in background: ${c.length}`);for(const t of c)t.connect().catch((e=>{s&&console.error(`[Kritzel] Network sync provider "${t.constructor.name}" failed to connect:`,e)}));this._isReady=!0,Ht(this._ydoc,this._metadataMap,{workspaces:this._workspacesMap},Xt,F,{quiet:!t.store.state.debugInfo.showMigrationInfo}),this.initializeMetadata("state"),this.loadFromYjs()}getOrCreateAppStateInstanceId(t){const e=globalThis.localStorage;if(!e)throw new Error("[KritzelAppStateMap] localStorage is unavailable. Cannot persist app-state document identity.");const n=t.getStorageKey("kritzel-app-state-instance-id");let i;try{i=e.getItem(n)}catch{throw new Error("[KritzelAppStateMap] Failed to read app-state instance id from localStorage.")}if(i)return i;const r=R.generateUUID();try{e.setItem(n,r)}catch{throw new Error("[KritzelAppStateMap] Failed to persist app-state instance id to localStorage.")}return r}handleWorkspacesChange(t){if("local"===t.transaction.origin)return void this._core?.rerender();if("migration"===t.transaction.origin)return;const e=Array.from(t.keysChanged),n=[],i=[];e.forEach((e=>{const r=t.changes.keys.get(e);if(r&&"delete"===r.action)i.push(e);else{const t=this._workspacesMap.get(e);if(t){const e=this.reviveWorkspace(t);n.push(e)}}})),i.forEach((t=>{this.map.delete(t)})),n.forEach((t=>{this.map.set(t.id,t)})),this._core?.store&&(this._core.store.state.workspaces=this.allWorkspaces()),this._onRemoteChangeCallback&&this._onRemoteChangeCallback(),this._core?.rerender()}reviveWorkspace(t){let e=t.viewport;if(e&&"translateX"in e&&!("centerWorldX"in e)){const t=e.scale??1;e={centerWorldX:-(e.translateX??0)/t,centerWorldY:-(e.translateY??0)/t,scale:t}}const n=new T(t.id,t.name,e);return this._core&&(n._core=this._core),n.createdAt=new Date(t.createdAt),n.updatedAt=new Date(t.updatedAt),n.isPublic=t.isPublic??!1,n}initializeMetadata(t){this._metadataMap&&this._ydoc&&this._ydoc.transact((()=>{this._metadataMap?.get("type")||this._metadataMap?.set("type",t),void 0===this._metadataMap?.get("isPublic")&&this._metadataMap?.set("isPublic",!1),void 0===this._metadataMap?.get("schemaVersion")&&this._metadataMap?.set("schemaVersion",F)}),"metadata")}getIsPublic(){return this._metadataMap?.get("isPublic")??!1}setIsPublic(t){this._metadataMap&&this._ydoc&&this._ydoc.transact((()=>{this._metadataMap?.set("isPublic",t)}),"metadata")}getDocumentType(){return this._metadataMap?.get("type")??"state"}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._workspacesMap&&(this.map.clear(),this._workspacesMap.forEach(((t,e)=>{const n=this.reviveWorkspace(t);this.map.set(e,n)})))}reset(){this.map.clear(),this._ydoc?.transact((()=>{this._workspacesMap?.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.map.set(t.id,t),this._workspacesMap){const e=t.serialize();this._ydoc?.transact((()=>{this._workspacesMap?.set(t.id,e)}),"local")}return!0}update(t){if(!t.id||!this.map.has(t.id))return!1;if(this.map.set(t.id,t),this._workspacesMap){const e=t.serialize();this._ydoc?.transact((()=>{this._workspacesMap?.set(t.id,e)}),"local")}return!0}remove(t){const e=Array.from(this.map.values()).find(t);return!!e&&(this.map.delete(e.id),this._workspacesMap&&this._ydoc?.transact((()=>{this._workspacesMap?.delete(e.id)}),"local"),!0)}get(t){return this.map.get(t)}allWorkspaces(){return Array.from(this.map.values())}filter(t){return Array.from(this.map.values()).filter(t)}find(t){return Array.from(this.map.values()).find(t)}has(t){return this.map.has(t)}destroy(){this._workspacesMap&&this._workspacesObserver&&(this._workspacesMap.unobserve(this._workspacesObserver),this._workspacesObserver=null),this._providers.forEach((t=>{t.disconnect(),t.destroy()})),this._providers=[],this.map.clear(),this._workspacesMap=null,this._metadataMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._core=null,this._onRemoteChangeCallback=null,this._isReady=!1}}class de{_core;_targetElement=null;_shadowRoot=null;constructor(t){this._core=t}setTargetElement(t){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-global-pointer-cursor")),this._targetElement=t,this._targetElement&&this._targetElement.style.setProperty("--kritzel-global-pointer-cursor",Pt.getPointerCursor())}getTargetElement(){return this._targetElement}setShadowRoot(t){this._shadowRoot=t}resetToDefault(){this._core.store.state.cursor={icon:"default",iconActive:"default"}}updateHoverState(t){if(this._core.store.isPointerDown)return;if(!this._shadowRoot)return;const e=this._shadowRoot.elementsFromPoint(t.clientX,t.clientY);if(!e||0===e.length)return;const n=e.find((t=>t.classList.contains("resize-handle-overlay")));if(n){const t=this._core.store.selectionGroup,e=t?.rotationDegrees??0,i=n.classList.contains("top-left"),r=n.classList.contains("bottom-right");this._core.store.state.cursor={icon:"move-vertical",rotation:e+(i||r?-45:45)}}else this._core.store.state.cursor=e.find((t=>t.classList.contains("rotation-handle-overlay")))||e.find((t=>t.classList.contains("selection-line-handle-overlay")))?{icon:"hand",iconActive:"hand-grab"}:{icon:"default",iconActive:"default"}}applyCursor(){const t=this._core.store.state,e=this._core.store.isPointerDown,n=t.cursor?.icon,i=t.cursor?.iconActive??n,r=t.cursor?.rotation,s=Pt.getCursor({iconName:e?i:n,rotation:r});this._targetElement&&(this._targetElement.style.cursor=s)}cleanup(){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=null,this._shadowRoot=null}}class pe{_isFirefox=/firefox|fxios/i.test(navigator.userAgent);_isSafari=/safari/i.test(navigator.userAgent)&&!/chrome|chromium|crios|android|edg/i.test(navigator.userAgent);_requestHandlers=new Map;constructor(t){this.registerRequestPermissionHandler("clipboard-read",(async()=>{if(this._isFirefox||this._isSafari)return"granted";try{return await navigator.clipboard.readText(),"granted"}catch{return"denied"}}))}registerRequestPermissionHandler(t,e){this._requestHandlers.set(t,e)}async checkPermission(t){return(await navigator.permissions.query({name:t})).state}async requestPermission(t){const e=this._requestHandlers.get(t);return e?e():this.checkPermission(t)}}const ge="kritzel-clipboard/v1:";class ve{_core;_pasteOffset=0;constructor(t){this._core=t}serializeForClipboard(t){const e="function"==typeof t.serialize?t.serialize():t;return p.isInstanceOf(t,"KritzelGroup")&&(e.__children__=t.children.map((t=>this.serializeForClipboard(t)))),e}serializeClipboardPayload(t){return`${ge}${JSON.stringify(t)}`}parseClipboardPayload(t){if(!t||!t.startsWith(ge))return null;try{const e=JSON.parse(t.slice(21));return 1===e?.version&&Array.isArray(e.objects)?e:null}catch{return null}}determineTextPasteIntent(t){const e=this.parseClipboardPayload(t);return e?{type:"kritzel_objects",payload:e}:t&&t.trim().length>0?{type:"plain_text",text:t}:null}async writeBrowserClipboardPayload(t,e){const n=this.serializeClipboardPayload(t);if(e?.clipboardData)e.clipboardData.setData("text/plain",n);else if("undefined"!=typeof navigator&&navigator.clipboard?.writeText)try{await navigator.clipboard.writeText(n)}catch{}}reviveClipboardObject(t){const e=new se(this._core),{__children__:n,...i}=t,r=e.revive(i);if(!r)return null;if(n&&p.isInstanceOf(r,"KritzelGroup")){const t=n.map((t=>this.reviveClipboardObject(t))).filter((t=>null!=t));r._pendingChildren=t,r.childIds=t.map((t=>t.id))}return r}regenerateIdsAndRemapAnchors(t){const e=[],n=t.length>0&&t.every((t=>p.isInstanceOf(t,"KritzelLine"))),i=t=>{for(const n of t)e.push(n),p.isInstanceOf(n,"KritzelGroup")&&i(n._pendingChildren)};i(t);const r=new Map;for(const t of e){const e=t.generateId();r.set(t.id,e),t.id=e,t.isMounted=!1}for(const t of e)p.isInstanceOf(t,"KritzelGroup")&&(t.childIds=t.childIds.map((t=>r.get(t)??t))),p.isInstanceOf(t,"KritzelLine")&&(t.startAnchor&&r.has(t.startAnchor.objectId)?t.startAnchor={objectId:r.get(t.startAnchor.objectId)}:n&&(t.startAnchor=void 0),t.endAnchor&&r.has(t.endAnchor.objectId)?t.endAnchor={objectId:r.get(t.endAnchor.objectId)}:n&&(t.endAnchor=void 0))}async determinePasteIntent(t){if(t?.clipboardData){const e=t.clipboardData,n=Array.from(e.files??[]).filter((t=>t.type.startsWith("image/")));if(n.length>0)return{type:"image_files",files:n};if(e.types.includes("text/plain")){const t=this.determineTextPasteIntent(e.getData("text/plain"));if(t)return t}return{type:"unknown"}}if("undefined"==typeof navigator||!navigator.clipboard)return{type:"unknown"};const{clipboard:e}=navigator;if("granted"!==await this._core.permissionManager.checkPermission("clipboard-read")&&"granted"!==await this._core.permissionManager.requestPermission("clipboard-read"))return{type:"unknown"};if(e.read)try{const t=await e.read(),{imageFiles:n,text:i}=await this.processClipboardItems(t);if(n.length>0)return{type:"image_files",files:n};if(null!==i){const t=this.determineTextPasteIntent(i);if(t)return t}}catch{}if(e.readText){const t=this.determineTextPasteIntent(await e.readText());if(t)return t}return{type:"unknown"}}async processClipboardItems(t){const e=[];let n=null;return await Promise.all(t.map((async t=>{const i=t.types.find((t=>t.startsWith("image/")));if(i){const n=await t.getType(i);e.push(new File([n],"pasted-image",{type:i}))}else if(null===n&&t.types.includes("text/plain")){const e=await t.getType("text/plain");n=await e.text()}}))),{imageFiles:e,text:n}}copy(t){const e=this._core.store.selectionGroup;if(!e)return;const n={version:1,sourceWorkspaceId:this._core.store.state.activeWorkspace?.id,objects:e.objects.sort(((t,e)=>t.zIndex-e.zIndex)).map((t=>this.serializeForClipboard(t)))};this._pasteOffset=0,this.writeBrowserClipboardPayload(n,t)}cut(t){this._core.store.selectionGroup&&(this.copy(t),this._core.delete())}materializeKritzelObjects(t){const e=t.payload.objects.map((t=>this.reviveClipboardObject(t))).filter((t=>null!=t));return this.regenerateIdsAndRemapAnchors(e),e}async materializeImageFiles(t){try{const e=25/this._core.store.state.scale,n=t.files.map((async(t,n)=>{const i=await _t(t,{maxWidthOrHeight:1200});return u.fromBlob(this._core,i,{translateX:n*e,translateY:n*e})}));return await Promise.all(n)}catch(t){return console.error("Failed to import pasted image files:",t),null}}async materializePlainText(t){const e=b.create(this._core),n=t.text.split("\n").map((t=>0===t.length?{type:"paragraph"}:{type:"paragraph",content:[{type:"text",text:t}]}));return e.setContent({type:"doc",content:n}),[e]}async paste(t,e,n){const i=await this.determinePasteIntent(n);let r=null;"kritzel_objects"===i.type?r=this.materializeKritzelObjects(i):"image_files"===i.type?r=await this.materializeImageFiles(i):"plain_text"===i.type&&(r=await this.materializePlainText(i)),r&&0!==r.length&&await this.insertMaterializedObjects(r,i,t,e)}async insertMaterializedObjects(t,e,n,i){const r=this._core.store.state.activeWorkspace;if(!r)return;const s=t.some((t=>t.workspaceId!==r.id))||"kritzel_objects"!==e.type,o=void 0!==n&&void 0!==i,a=Math.min(...t.map((t=>t.translateX))),c=Math.min(...t.map((t=>t.translateY)));let l,u;const f=25/this._core.store.state.scale;void 0!==n&&void 0!==i?(l=n,u=i):s?(l=a,u=c):(l=a+f+this._pasteOffset,u=c+f+this._pasteOffset,this._pasteOffset+=f);const d=l-a,g=u-c;this._core.removeSelectionGroup(),this._core.removeSelectionBox();const v=h.create(this._core),w=this._core.store.currentZIndex;this._core.store.objects.transaction((()=>{const e=(t,n)=>{if(0===t._pendingChildren.length)return;const i=t._pendingChildren;t._pendingChildren=[],i.forEach(((t,i)=>{t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+d,t.translateY+g),t.zIndex=n+i+1,p.isInstanceOf(t,"KritzelGroup")&&e(t,t.zIndex),this._core.addObject(t)})),t.finalize()},n=[];t.forEach(((t,i)=>{t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+d,t.translateY+g),t.zIndex=w+i,p.isInstanceOf(t,"KritzelGroup")&&e(t,t.zIndex),this._core.addObject(t),n.push(t),v.addOrRemove(t)})),this._core.engine.emitObjectsAdded(n)})),this._core.anchorManager.rebuildIndex(),v.isSelected=!0,1===t.length&&(v.rotation=t[0].rotation),s&&!o&&v.centerInViewport(),this._core.addSelectionGroup(v),this._core.engine.viewport?.bringIntoViewIfNeeded(v),this._core.store.state.isSelecting=!1,await new Promise((t=>{requestAnimationFrame((()=>requestAnimationFrame((()=>t()))))})),v.refreshObjectDimensions(),s&&!o&&v.centerInViewport(),this._core.engine.emitObjectsChange(),this._core.rerender(),this._core.store.setState("activeTool",this._core.toolRegistry.getTool("selection")),this._core.engine.emitObjectsChange(),this._core.rerender()}}class we{_kritzelEngine;_store;_syncConfig;_assetStorageConfig;_assetResolver;_appStateMap;_anchorManager;_cursorManager;_themeManager;_localizationManager;_licenseManager;_permissionManager;_clipboardManager;_toolRegistry;_editorId;_user;get engine(){return this._kritzelEngine}get store(){return this._store}get appStateMap(){return this._appStateMap}get anchorManager(){return this._anchorManager}get cursorManager(){return this._cursorManager}get themeManager(){return this._themeManager}get localizationManager(){return this._localizationManager}get licenseManager(){return this._licenseManager}get permissionManager(){return this._permissionManager}get toolRegistry(){return this._toolRegistry}get clipboardManager(){return this._clipboardManager}get editorId(){return this._editorId}getStorageKey(t){return this._editorId?`${t}-${this._editorId}`:t}get user(){return this._user}setUser(t){this._user=t,this._store.setLocalUserId(t?.id??null),this._store.objects?.setLocalUser(t)}constructor(t,e){this._kritzelEngine=t,this._editorId=e,this._store=new ue(oe),this._appStateMap=new fe,this._anchorManager=new Bt(this),this._cursorManager=new de(this),this._themeManager=new S(this),this._localizationManager=new Vt(this),this._licenseManager=new Nt(this),this._permissionManager=new pe(this),this._clipboardManager=new ve(this),this._toolRegistry=new ce(this),this._assetResolver=new k,this._assetResolver.setShowInfo(this._store.state.debugInfo?.showAssetResolverInfo??!1)}get assetResolver(){return this._assetResolver}setSyncConfig(t){this._syncConfig=t}setAssetStorageConfig(t){this._assetStorageConfig=t}setEditorId(t){this._editorId=t,this._themeManager=new S(this),this._localizationManager=new Vt(this)}async initializeYjs(){await this._appStateMap.initialize(this,this._syncConfig)}async initializeAssetStorage(){await this._assetResolver.init(this._assetStorageConfig),this.warnIfAssetStorageMismatched()}warnIfAssetStorageMismatched(){this._appStateMap.hasNetworkSyncProvider&&(this._assetResolver.hasRemoteProvider||console.warn("[Kritzel] A network sync provider is configured, but no remote asset storage provider was found. Images added on this device will only be available locally and will appear broken on other devices. Configure a remote asset provider (e.g. HttpAssetProvider) via the `assetStorage` prop to enable cross-device image sync."))}loadWorkspacesFromAppState(){return this._appStateMap.allWorkspaces()}saveWorkspaceToAppState(t){this._appStateMap.has(t.id)?this._appStateMap.update(t):this._appStateMap.insert(t)}deleteWorkspaceFromAppState(t){this._appStateMap.remove((e=>e.id===t))}async initializeWorkspace(t,e){const n=this.loadWorkspacesFromAppState(),i=!t&&!!this._editorId,r=n.length>0?[...n].sort(((t,e)=>{const n=e.createdAt.getTime()-t.createdAt.getTime();return 0!==n?n:e.updatedAt.getTime()-t.updatedAt.getTime()}))[0]:null,s=localStorage.getItem(this.getStorageKey("kritzel-active-workspace-id")),o=s?n.find((t=>t.id===s)):null;let a;if(t)a=t,n.find((e=>e.id===t.id))||(a._core=this,this.saveWorkspaceToAppState(a));else if(o)a=o;else if(r&&!i)a=r;else{if(e?.skipFallbackCreation)return this._store.state.workspaces=n,this._store.state.activeWorkspace=null,void this.rerender();a=new T(R.generateUUID(),"New Workspace"),a._core=this,this.saveWorkspaceToAppState(a)}localStorage.setItem(this.getStorageKey("kritzel-active-workspace-id"),a.id),this._store.objects&&this._store.objects.isReady&&this._store.objects.destroy();const c=new he;this._store.state.objects=c,this._store.state.activeWorkspace=a,this._store.state.workspaces=this.loadWorkspacesFromAppState();const l=a.viewport??{centerWorldX:0,centerWorldY:0,scale:1},h=l.scale??1,u=this._store.state.viewportHeight;this._store.state.translateX=this._store.state.viewportWidth/2-(l.centerWorldX??0)*h,this._store.state.translateY=u/2-(l.centerWorldY??0)*h,this._store.state.scale=h,await c.initialize(this,a.id,this._syncConfig),this._user&&c.setLocalUser(this._user),c.onAwarenessChange((t=>{this.engine.emitAwarenessChange(t)})),this._anchorManager.rebuildIndex(),this.engine.emitObjectsChange(),this.rerender()}async loadSharedWorkspace(t){const e=t;let n=this.getWorkspaces().find((t=>t.id===e));n?n.isPublic=!0:(n=new T(e,"Shared Workspace"),n.isPublic=!0,this.createWorkspace(n)),await this.initializeWorkspace(n)}getObjectsInViewport(){return this._store.objects?this._store.objects.query({x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,z:this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale,depth:100}).filter((t=>!(t instanceof h||t instanceof g))).sort(((t,e)=>t.zIndex-e.zIndex)):[]}rerender(){this._kritzelEngine&&this._kritzelEngine.forceUpdate++}findObjectById(t){for(const e of this._store.allObjects)if(e.id===t)return e;return null}getWorkspaces(){return this.loadWorkspacesFromAppState()}createWorkspace(t){t._core=this,t.createdAt=new Date,t.updatedAt=new Date,this.saveWorkspaceToAppState(t),this._store.state.workspaces=this.loadWorkspacesFromAppState()}updateWorkspace(t){t.updatedAt=new Date,this.saveWorkspaceToAppState(t),this._store.state.activeWorkspace?.id===t.id&&this._store.objects?.setWorkspaceName(t.name);const e=this._store.state.workspaces,n=e.findIndex((e=>e.id===t.id));-1!==n&&(e[n]=t,this._store.state.workspaces=e)}deleteWorkspace(t){this._store.state.activeWorkspace?.id===t.id&&(this.engine.viewport?.cancelPendingUpdates(),this._store.objects?.destroy()),this.deleteWorkspaceFromAppState(t.id),this._store.state.workspaces=this.loadWorkspacesFromAppState(),window.indexedDB.deleteDatabase(this._editorId?`kritzel-workspace-${this._editorId}-${t.id}`:`kritzel-workspace-${t.id}`)}updateWorkspaceViewport(t,e,n){const i=this._store.state.activeWorkspace;i&&this._store.state.workspaces.some((t=>t.id===i.id))&&(i.viewport={centerWorldX:(this._store.state.viewportWidth/2-t)/n,centerWorldY:(this._store.state.viewportHeight/2-e)/n,scale:n},i.updatedAt=new Date,this.saveWorkspaceToAppState(i))}getIsPublic(){return this._store.state.activeWorkspace?.isPublic??!1}addObject(t){this._store.objects.insert(t)}removeObject(t,e=!1){p.isInstanceOf(t,"KritzelGroup")&&!e&&[...t.children].forEach((t=>{this.removeObject(t)})),p.isInstanceOf(t,"KritzelCustomElement")&&t.unmount(),p.isInstanceOf(t,"KritzelLine")?this._anchorManager.handleLineDeleted(t.id):this._anchorManager.handleObjectDeleted(t.id),t.isMounted=!1,this._store.objects.remove((e=>e.id===t.id))}updateObject(t,e){const n=[];for(const i in e)if(e.hasOwnProperty(i)){const r=e[i];void 0!==r&&(t[i]=r,n.push(i))}t.onAfterUpdate(n),this._store.objects.update(t)}addSelectionGroup(t){this.removeLocalSelectionGroups(),this.removeSelectionBox();for(const e of t.objects??[])if(p.isInstanceOf(e,"KritzelCustomElement")){const t=e;"function"==typeof t.setIsInteractive?t.setIsInteractive(!0):t.isInteractive=!0}this._store.objects.insert(t),this._store.setSelectionGroup(t),this._kritzelEngine.triggerSelectionChange()}isLocalSelectionGroup(t){const e=this._user?.id;return null==e||t.userId===e||null==t.userId}teardownSelectionGroup(t){t.deselectAllChildren?.();for(const e of t.objects??[])if(p.isInstanceOf(e,"KritzelCustomElement")){const t=e;"function"==typeof t.setIsInteractive?t.setIsInteractive(!1):t.isInteractive=!1}}removeLocalSelectionGroups(){const t=this._store.objects.allObjects().filter((t=>t instanceof h||p.isInstanceOf(t,"KritzelSelectionGroup"))).filter((t=>this.isLocalSelectionGroup(t))),e=this._store.selectionGroup;if(e&&this.isLocalSelectionGroup(e)&&!t.some((t=>t.id===e.id))&&t.push(e),0===t.length)return!1;for(const e of t)this.teardownSelectionGroup(e);const n=new Set(t.map((t=>t.id)));return this._store.objects.remove((t=>n.has(t.id))),this._store.setSelectionGroup(null),!0}removeSelectionGroup(){this.removeLocalSelectionGroups()&&this._kritzelEngine.triggerSelectionChange()}removeSelectionBox(){const t=this._store.selectionBox;t&&(this._store.objects.remove((e=>e.id===t.id)),this._store.setSelectionBox(null),this._store.objects.clearLocalSelectionBox())}deselectAllObjects(){this.removeSelectionGroup(),this.rerender()}delete(){const t=this._store.selectionGroup;t&&(this._store.objects.stopUndoCapturing(),this._store.objects.transaction((()=>{t.objects.forEach((t=>this.removeObject(t))),this.removeSelectionGroup()})),this._store.objects.stopUndoCapturing(),this.engine.emitObjectsInViewportChange(),this.rerender())}undo(){this._store.objects?.undo()}redo(){this._store.objects?.redo()}deleteObject(t){const e=this.findObjectById(t);e&&(this.removeObject(e),this.engine.emitObjectsInViewportChange(),this.rerender())}bringForward(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=i.length>0?Math.max(...i.map((t=>t.zIndex)))+1:0;n.forEach((t=>{t.zIndex!==r&&this.updateObject(t,{zIndex:t.zIndex+1})})),this.rerender()}sendBackward(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=i.length>0?Math.min(...i.map((t=>t.zIndex)))-1:0;n.forEach((t=>{t.zIndex!==r&&this.updateObject(t,{zIndex:t.zIndex-1})})),this.rerender()}bringToFront(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=Math.max(...i.map((t=>t.zIndex)))+1;n.forEach((t=>{this.updateObject(t,{zIndex:r})})),this.rerender()}sendToBack(t){const e=this._store.selectionGroup,n=t?[t]:e?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===n.findIndex((e=>e.id===t.id)))),r=Math.min(...i.map((t=>t.zIndex)))-1;n.forEach((t=>{this.updateObject(t,{zIndex:r})})),this.rerender()}alignObjects(t){const e=this._store.selectionGroup;if(!e||e.objects.length<2)return;const n=e.objects,i=ae.calculateAlignedPositions(n,t);this._store.objects.transaction((()=>{for(const t of n){const e=i.get(t.id);e&&this.updateObject(t,{translateX:e.translateX,translateY:e.translateY})}})),e.refreshObjectDimensions(),this.rerender()}group(){const t=this._store.selectionGroup;if(!t||t.objects.length<2)return;const e=y.createFromObjects(this,t.objects);this.addObject(e),this.removeSelectionGroup();const n=h.create(this);n.addOrRemove(e),n.isSelected=!0,n.rotation=e.rotation,this.addSelectionGroup(n),this.engine.emitObjectsChange(),this.rerender()}ungroup(){const t=this._store.selectionGroup;if(!t)return;const e=t.objects.filter((t=>p.isInstanceOf(t,"KritzelGroup")));if(0===e.length)return;const n=[],i=t.objects.filter((t=>!p.isInstanceOf(t,"KritzelGroup")));e.forEach((t=>{const e=t.ungroup();n.push(...e),this.removeObject(t,!0)})),this.removeSelectionGroup();const r=h.create(this);[...n,...i].forEach((t=>{r.addOrRemove(t)})),r.isSelected=!0,this.addSelectionGroup(r),this.engine.emitObjectsChange(),this.rerender()}selectObjects(t){if(0===t.length)return;const e=h.create(this);t.forEach((t=>{t.isSelected=!1,e.addOrRemove(t)})),e.isSelected=!0,1===t.length&&(e.rotation=e.objects[0].rotation),this.addSelectionGroup(e),this.rerender()}selectAllObjects(){const t=this._store.objects.allObjects().filter((t=>!(t instanceof h||t instanceof g||t instanceof B)));if(t.length>0){const e=h.create(this);t.forEach((t=>{t.isSelected=!1,e.addOrRemove(t)})),e.isSelected=!0,this._store.state.isSelecting=!1,1===t.length&&(e.rotation=e.objects[0].rotation),this.addSelectionGroup(e),this._store.setState("activeTool",this._toolRegistry.getTool("selection")),this.rerender()}}selectAllObjectsInViewport(){const t=this._store.objects.query({x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,z:this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale,depth:100}).filter((t=>t.isInViewport())).filter((t=>!(t instanceof h||t instanceof g||t instanceof B)));if(t.length>0){const e=h.create(this);t.forEach((t=>{t.isSelected=!1,e.addOrRemove(t)})),e.isSelected=!0,this._store.state.isSelecting=!1,1===t.length&&(e.rotation=e.objects[0].rotation),this.addSelectionGroup(e),this._store.setState("activeTool",this._toolRegistry.getTool("selection")),this.rerender()}}clearSelection(){this.removeSelectionGroup();const t=this._user?.id;this._store.objects.remove((e=>e instanceof g||e instanceof h&&(null==t||e.userId===t||null==e.userId))),this._store.setSelectionBox(null),this._store.setSelectionGroup(null);for(const t of this._store.allNonSelectionObjects)t.isSelected&&(t.isSelected=!1);this._store.state.isSelecting=!1,this._store.state.isResizeHandleSelected=!1,this._store.state.isRotationHandleSelected=!1,this._store.state.isLineHandleSelected=!1,this._store.state.isLineHandleDragging=!1,this._store.state.lineHandleType=void 0,this.rerender()}resetActiveText(){const t=this._store.activeText;t&&(t.isEmpty?this.deleteObject(t.id):t.save())}resetActiveShape(){const t=this._store.activeShape;t&&t.save()}getObjectFromPointerEvent(t,e=".object"){const n=this._store.state.host?.shadowRoot;if(!n)return null;const i=t.clientX,r=t.clientY,s=n.elementFromPoint(i,r);if(!s)return null;const o=s.closest(e);if(o){const t=this._store.allObjects.find((t=>o.id===t.id));return t&&t.hitTest(i,r)?t:null}return null}getObjectsFromPointerEvent(t,e=".object"){const n=this._store.state.host?.shadowRoot;if(!n)return[];const i=n.elementsFromPoint(t.clientX,t.clientY);if(!i||0===i.length)return[];const r=new Set;return i.forEach((t=>{const n=t.closest(e);n&&n.id&&r.add(n.id)})),r.size>0?this._store.allObjects.filter((t=>r.has(t.id))).sort(((t,e)=>e.zIndex-t.zIndex)):[]}getElementsAtPoint(t,e){const n=this._store.state.host?.shadowRoot;if(!n)return[];const i=n.elementsFromPoint(t.clientX,t.clientY);return i&&0!==i.length?i.filter((t=>t.matches(e))):[]}isPointerOverElement(t,e){return this.getElementsAtPoint(t,e).length>0}getCanvasPoint(t){if(!this._store.state.host)return{x:0,y:0};const e=this._store.state.host.getBoundingClientRect();return{x:(t.clientX-e.left-this._store.state.translateX)/this._store.state.scale,y:(t.clientY-e.top-this._store.state.translateY)/this._store.state.scale}}beforeWorkspaceChange(){this._kritzelEngine.viewport?.cancelPendingUpdates(),this._store.state.activeWorkspace&&this.updateWorkspaceViewport(this._store.state.translateX,this._store.state.translateY,this._store.state.scale),this.resetActiveText(),this.clearSelection(),this._store.setState("activeTool",this._toolRegistry.getTool("selection"))}displaySelectionGroupUI(t){if(!t.isSelected)return!1;if(t instanceof h&&null!=this._user?.id&&null!=t.userId&&t.userId!==this._user.id)return!0;const e=this._store.selectionGroup;return e?t instanceof h&&t.id===e.id&&(e.objects.length>1||(1!==e.objects.length||!(e.objects[0]instanceof L))):!(t instanceof L)}displaySelectionLineUI(t){if(!(t instanceof L))return!1;const e=this._store.selectionGroup;if(!e)return t.isSelected;if(!e.isSelected)return!1;if(1===e.objects.length){const n=e.objects[0];return n instanceof L&&n.id===t.id}return!1}}class me{static calculateCombinedBounds(t){if(!t||0===t.length)return null;let e=1/0,n=1/0,i=-1/0,r=-1/0;for(const s of t){const t=s.rotatedBoundingBox;e=Math.min(e,t.x),n=Math.min(n,t.y),i=Math.max(i,t.x+t.width),r=Math.max(r,t.y+t.height)}return{x:e,y:n,z:1,width:i-e,height:r-n}}static generateSvg(t,e={}){const{theme:n,padding:i=0,includeXmlDeclaration:r=!0,rasterSafeForCanvas:s=!1,imageDataUrls:o}=e;if(!t||0===t.length)return"";const a=this.flattenObjects(t),c=this.calculateCombinedBounds(a);if(!c)return"";const l=c.x-i,h=c.y-i,u=c.width+2*i,f=c.height+2*i,d=this.collectDefs(a,n),p=t.sort(((t,e)=>t.zIndex-e.zIndex)).map((t=>this.objectToSvgElement(t,n,o,s))).filter(Boolean).join("\n ");return`${r?'<?xml version="1.0" encoding="UTF-8"?>\n':""}<svg xmlns="http://www.w3.org/2000/svg" viewBox="${l} ${h} ${u} ${f}" width="${u}" height="${f}">${d.length>0?`\n <defs>\n ${d.join("\n ")}\n </defs>`:""}\n ${p}\n</svg>`}static flattenObjects(t){const e=[];for(const n of t)p.isInstanceOf(n,"KritzelGroup")?e.push(...this.flattenObjects(n.children)):e.push(n);return e}static async resolveImageDataUrls(t,e){const n=new Map;if(!t||0===t.length)return n;const i=this.flattenObjects(t).filter((t=>p.isInstanceOf(t,"KritzelImage")));return await Promise.all(i.map((async t=>{if(t.src?.startsWith("data:"))n.set(t.id,t.src);else if(t.resolvedSrc?.startsWith("data:"))n.set(t.id,t.resolvedSrc);else if(t.assetId&&e)try{const i=await e.fetchBlob(t.assetId);n.set(t.id,await this.blobToDataUrl(i))}catch(e){console.warn(`[KritzelSvgExportHelper] Failed to inline image asset ${t.assetId} for export:`,e)}}))),n}static async blobToDataUrl(t){if("undefined"!=typeof FileReader)try{return await new Promise(((e,n)=>{const i=new FileReader;i.onload=()=>{"string"!=typeof i.result?n(new Error("FileReader result is not a string")):e(i.result)},i.onerror=()=>n(i.error??new Error("Failed to read blob as data URL")),i.readAsDataURL(t)}))}catch{}const e=new Uint8Array(await t.arrayBuffer());return`data:${t.type||"application/octet-stream"};base64,${this.uint8ToBase64(e)}`}static uint8ToBase64(t){if("undefined"!=typeof Buffer)return Buffer.from(t).toString("base64");let e="";for(let n=0;n<t.length;n+=32768){const i=t.subarray(n,Math.min(n+32768,t.length));e+=String.fromCharCode(...i)}if("function"==typeof btoa)return btoa(e);throw new Error("No base64 encoder available in this runtime")}static collectDefs(t,e){const n=[];for(const i of t)p.isInstanceOf(i,"KritzelLine")&&(i.hasStartArrow&&n.push(this.generateArrowMarker(i,"start",e)),i.hasEndArrow&&n.push(this.generateArrowMarker(i,"end",e)));return n}static generateArrowMarker(t,e,n){const i="start"===e?t.startMarkerId:t.endMarkerId,r=t.getArrowSize(e),s=t.getArrowFill(e);return`<marker id="${i}" markerWidth="${r}" markerHeight="${r}" refX="0" refY="${r/2}" orient="${"start"===e?"auto-start-reverse":"auto"}" markerUnits="userSpaceOnUse">\n <path d="${t.getArrowPath("start"===e?t.arrows?.start?.style:t.arrows?.end?.style)}" fill="${s}" transform="scale(${r/10})"/>\n </marker>`}static objectToSvgElement(t,e,n,i=!1){return p.isInstanceOf(t,"KritzelPath")?this.pathToSvg(t,e):p.isInstanceOf(t,"KritzelLine")?this.lineToSvg(t,e):p.isInstanceOf(t,"KritzelShape")?this.shapeToSvg(t,e):p.isInstanceOf(t,"KritzelText")?this.textToSvg(t,e,i):p.isInstanceOf(t,"KritzelImage")?this.imageToSvg(t,n):p.isInstanceOf(t,"KritzelCustomElement")?this.customElementToSvg(t,i):p.isInstanceOf(t,"KritzelGroup")?this.groupToSvg(t,e,n,i):""}static pathToSvg(t,e){const n=this.buildTransform(t),i=M.resolveThemeColor(t.fill,e),r=M.resolveThemeColor(t.stroke,e),s=1!==t.opacity?` opacity="${t.opacity}"`:"",o=this.getObjectScale(t);return`<g transform="${n}"${s}>\n <svg viewBox="${t.viewBox}" width="${t.totalWidth/o}" height="${t.totalHeight/o}" overflow="visible">\n <path d="${t.d}" fill="${i||"none"}" stroke="${r||"none"}"${t.strokeWidth?` stroke-width="${t.strokeWidth}"`:""}/>\n </svg>\n </g>`}static lineToSvg(t,e){const n=this.buildTransform(t),i=M.resolveThemeColor(t.stroke,e),r=1!==t.opacity?` opacity="${t.opacity}"`:"",s=this.getObjectScale(t);return`<g transform="${n}"${r}>\n <svg viewBox="${t.viewBox}" width="${t.totalWidth/s}" height="${t.totalHeight/s}" overflow="visible">\n <path d="${t.d}" fill="none" stroke="${i}" stroke-width="${t.strokeWidth}" stroke-linecap="round"${t.hasStartArrow?` marker-start="url(#${t.startMarkerId})"`:""}${t.hasEndArrow?` marker-end="url(#${t.endMarkerId})"`:""}/>\n </svg>\n </g>`}static shapeToSvg(t,e){const n=this.buildTransform(t),i=M.resolveThemeColor(t.fillColor,e),r=M.resolveThemeColor(t.strokeColor,e),s=1!==t.opacity?` opacity="${t.opacity}"`:"",o=this.getObjectScale(t),a=t.getSvgPath();let c="";if(t.editor&&!t.editor.state.doc.textContent.trim());else if(t.content){const n=this.prosemirrorToHtml(t.content,t,e);if(n){const i=M.resolveThemeColor(t.fontColor,e);c=`\n <foreignObject x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}">\n <div xmlns="http://www.w3.org/1999/xhtml" style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; font-family: ${t.fontFamily}; font-size: ${t.fontSize}px; color: ${i}; overflow: hidden;">\n ${n}\n </div>\n </foreignObject>`}}return`<g transform="${n}"${s}>\n <svg viewBox="${t.viewBox}" width="${t.totalWidth/o}" height="${t.totalHeight/o}" overflow="visible" preserveAspectRatio="none">\n <path d="${a}" fill="${i||"transparent"}" stroke="${r}" stroke-width="${t.strokeWidth}"/>${c}\n </svg>\n </g>`}static textToSvg(t,e,n=!1){if(n)return this.textToSvgRasterSafe(t,e);const i=this.buildTransform(t),r=1!==t.opacity?` opacity="${t.opacity}"`:"",s=M.resolveThemeColor(t.fontColor,e),o=M.resolveThemeColor(t.backgroundColor,e),a=this.getObjectScale(t),c=this.prosemirrorToHtml(t.content,t,e);return`<g transform="${i}"${r}>\n <foreignObject x="0" y="0" width="${t.totalWidth/a}" height="${t.totalHeight/a}">\n <div xmlns="http://www.w3.org/1999/xhtml" style="font-family: ${t.fontFamily}; font-size: ${t.fontSize}pt; color: ${s}; background-color: ${o||"transparent"}; transform: scale(${t.scaleFactor}); transform-origin: top left; white-space: pre-wrap; word-wrap: break-word;">\n ${c}\n </div>\n </foreignObject>\n </g>`}static textToSvgRasterSafe(t,e){const n=this.buildTransform(t),i=1!==t.opacity?` opacity="${t.opacity}"`:"",r=M.resolveThemeColor(t.fontColor,e),s=M.resolveThemeColor(t.backgroundColor,e),o=this.getObjectScale(t),a=t.totalWidth/o,c=t.totalHeight/o,l=this.prosemirrorToPlainTextLines(t.content),h=l.length>0?l:[""],u=Math.max(1,t.fontSize*(t.scaleFactor||1)),f=1.2*u,d=u,p=s&&"transparent"!==s?`<rect x="0" y="0" width="${a}" height="${c}" fill="${s}"/>`:"",g=h.map(((t,e)=>`<tspan x="0" y="${d+e*f}" xml:space="preserve">${this.escapeHtml(t)}</tspan>`)).join("");return`<g transform="${n}"${i}>\n ${p}\n <text font-family="${this.escapeHtml(t.fontFamily)}" font-size="${u}" fill="${r}">${g}</text>\n </g>`}static imageToSvg(t,e){const n=this.buildTransform(t),i=1!==t.opacity?` opacity="${t.opacity}"`:"",r=this.getObjectScale(t),s=t.totalWidth/r,o=t.totalHeight/r;return`<g transform="${n}"${i}>\n <image href="${e?.get(t.id)||t.resolvedSrc||t.src||""}" x="0" y="0" width="${s}" height="${o}" preserveAspectRatio="xMidYMid meet"/>\n </g>`}static customElementToSvg(t,e=!1){const n=this.buildTransform(t),i=1!==t.opacity?` opacity="${t.opacity}"`:"",r=this.getObjectScale(t),s=t.totalWidth/r,o=t.totalHeight/r;return e?(console.warn("[KritzelCustomElement SVG Export] Custom elements do not serialize well to PNG. Use SVG export or screenshot instead."),`<g transform="${n}"${i}>\n <rect x="0" y="0" width="${s}" height="${o}" fill="#f0f0f0" stroke="#999" stroke-width="1" />\n <text x="${s/2}" y="${o/2}" text-anchor="middle" dominant-baseline="middle" font-size="12" fill="#999">[Custom Element]</text>\n </g>`):`<g transform="${n}"${i}>\n <foreignObject x="0" y="0" width="${s}" height="${o}">\n <div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;">\n ${t.element?.outerHTML||'<div style="border:1px dashed #ccc">Empty</div>'}\n </div>\n </foreignObject>\n </g>`}static groupToSvg(t,e,n,i=!1){const r=t.children.sort(((t,e)=>t.zIndex-e.zIndex)).map((t=>this.objectToSvgElement(t,e,n,i))).filter(Boolean).join("\n ");return r?`<g${1!==t.opacity?` opacity="${t.opacity}"`:""}>\n ${r}\n </g>`:""}static buildTransform(t){const e=[],n=this.getObjectScale(t);if(e.push(`translate(${t.translateX}, ${t.translateY})`),0!==t.rotation){const i=t.rotation*(180/Math.PI);e.push(`rotate(${i}, ${t.totalWidth/2/n}, ${t.totalHeight/2/n})`)}return e.join(" ")}static getObjectScale(t){const e=t.scale??1;return 0===e?1:e}static prosemirrorToHtml(t,e,n){return t&&t.content?t.content.map((t=>this.nodeToHtml(t,n))).join(""):""}static nodeToHtml(t,e){if(!t)return"";switch(t.type){case"paragraph":return`<p style="margin: 0;">${(t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):"")||"<br/>"}</p>`;case"text":let n=this.escapeHtml(t.text||"");if(t.marks)for(const i of t.marks)n=this.applyMark(n,i,e);return n;case"hard_break":return"<br/>";case"bullet_list":return`<ul style="margin: 0; padding-left: 1.5em;">${t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}</ul>`;case"ordered_list":return`<ol style="margin: 0; padding-left: 1.5em;">${t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}</ol>`;case"list_item":return`<li>${t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}</li>`;default:return t.content?t.content.map((t=>this.nodeToHtml(t,e))).join(""):""}}static prosemirrorToPlainTextLines(t){if(!t||!Array.isArray(t.content))return[];const e=t.content.map((t=>this.nodeToPlainText(t))).join("").replace(/\r\n/g,"\n").replace(/\n+$/,"");return e?e.split("\n"):[]}static nodeToPlainText(t){if(!t)return"";switch(t.type){case"text":return t.text||"";case"hard_break":return"\n";case"paragraph":return`${Array.isArray(t.content)?t.content.map((t=>this.nodeToPlainText(t))).join(""):""}\n`;case"list_item":return`- ${(Array.isArray(t.content)?t.content.map((t=>this.nodeToPlainText(t))).join(""):"").trim()}\n`;default:return Array.isArray(t.content)?t.content.map((t=>this.nodeToPlainText(t))).join(""):""}}static applyMark(t,e,n){switch(e.type){case"bold":case"strong":return`<strong>${t}</strong>`;case"italic":case"em":return`<em>${t}</em>`;case"underline":return`<u>${t}</u>`;case"strike":return`<s>${t}</s>`;case"code":return`<code>${t}</code>`;case"link":return`<a href="${this.escapeHtml(e.attrs?.href||"#")}">${t}</a>`;default:return t}}static escapeHtml(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}}const ye=(()=>{let t=0;return()=>(t+=1,`u${`0000${(Math.random()*36**4|0).toString(36)}`.slice(-4)}${t}`)})();function be(t){const e=[];for(let n=0,i=t.length;n<i;n++)e.push(t[n]);return e}let ke=null;function Ae(t={}){return ke||(t.includeStyleProperties?(ke=t.includeStyleProperties,ke):(ke=be(window.getComputedStyle(document.documentElement)),ke))}function xe(t,e){const n=(t.ownerDocument.defaultView||window).getComputedStyle(t).getPropertyValue(e);return n?parseFloat(n.replace("px","")):0}function Se(t,e={}){return{width:e.width||function(t){const e=xe(t,"border-left-width"),n=xe(t,"border-right-width");return t.clientWidth+e+n}(t),height:e.height||function(t){const e=xe(t,"border-top-width"),n=xe(t,"border-bottom-width");return t.clientHeight+e+n}(t)}}const Me=16384;function ze(t){return new Promise(((e,n)=>{const i=new Image;i.onload=()=>{i.decode().then((()=>{requestAnimationFrame((()=>e(i)))}))},i.onerror=n,i.crossOrigin="anonymous",i.decoding="async",i.src=t}))}const $e=(t,e)=>{if(t instanceof e)return!0;const n=Object.getPrototypeOf(t);return null!==n&&(n.constructor.name===e.name||$e(n,e))};function Ce(t,e,n,i){const r=window.getComputedStyle(t,n),s=r.getPropertyValue("content");if(""===s||"none"===s)return;const o=ye();try{e.className=`${e.className} ${o}`}catch(t){return}const a=document.createElement("style");a.appendChild(function(t,e,n,i){const r=`.${t}:${e}`,s=n.cssText?function(t){const e=t.getPropertyValue("content");return`${t.cssText} content: '${e.replace(/'|"/g,"")}';`}(n):function(t,e){return Ae(e).map((e=>`${e}: ${t.getPropertyValue(e)}${t.getPropertyPriority(e)?" !important":""};`)).join(" ")}(n,i);return document.createTextNode(`${r}{${s}}`)}(o,n,r,i)),e.appendChild(a)}const Te="application/font-woff",Ie="image/jpeg",je={woff:Te,woff2:Te,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:Ie,jpeg:Ie,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function Ee(t){const e=function(t){const e=/\.([^./]*?)$/g.exec(t);return e?e[1]:""}(t).toLowerCase();return je[e]||""}function _e(t){return-1!==t.search(/^(data:)/)}async function Le(t,e,n){const i=await fetch(t,e);if(404===i.status)throw new Error(`Resource "${i.url}" not found`);const r=await i.blob();return new Promise(((t,e)=>{const s=new FileReader;s.onerror=e,s.onloadend=()=>{try{t(n({res:i,result:s.result}))}catch(t){e(t)}},s.readAsDataURL(r)}))}const Oe={};async function Pe(t,e,n){const i=function(t,e,n){let i=t.replace(/\?.*/,"");return n&&(i=t),/ttf|otf|eot|woff2?/i.test(i)&&(i=i.replace(/.*\//,"")),e?`[${e}]${i}`:i}(t,e,n.includeQueryParams);if(null!=Oe[i])return Oe[i];let r;n.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());try{const i=await Le(t,n.fetchRequestInit,(({res:t,result:n})=>(e||(e=t.headers.get("Content-Type")||""),function(t){return t.split(/,/)[1]}(n))));r=function(t,e){return`data:${e};base64,${t}`}(i,e)}catch(e){r=n.imagePlaceholder||"";let i=`Failed to fetch resource: ${t}`;e&&(i="string"==typeof e?e:e.message),i&&console.warn(i)}return Oe[i]=r,r}const Be=t=>null!=t.tagName&&"SLOT"===t.tagName.toUpperCase(),De=t=>null!=t.tagName&&"SVG"===t.tagName.toUpperCase();async function Re(t,e,n){return n||!e.filter||e.filter(t)?Promise.resolve(t).then((t=>async function(t,e){return $e(t,HTMLCanvasElement)?async function(t){const e=t.toDataURL();return"data:,"===e?t.cloneNode(!1):ze(e)}(t):$e(t,HTMLVideoElement)?async function(t,e){if(t.currentSrc){const e=document.createElement("canvas"),n=e.getContext("2d");return e.width=t.clientWidth,e.height=t.clientHeight,null==n||n.drawImage(t,0,0,e.width,e.height),ze(e.toDataURL())}const n=t.poster,i=Ee(n);return ze(await Pe(n,i,e))}(t,e):$e(t,HTMLIFrameElement)?async function(t,e){var n;try{if(null===(n=null==t?void 0:t.contentDocument)||void 0===n?void 0:n.body)return await Re(t.contentDocument.body,e,!0)}catch(t){}return t.cloneNode(!1)}(t,e):t.cloneNode(De(t))}(t,e))).then((n=>async function(t,e,n){var i,r;if(De(e))return e;let s=[];return s=Be(t)&&t.assignedNodes?be(t.assignedNodes()):$e(t,HTMLIFrameElement)&&(null===(i=t.contentDocument)||void 0===i?void 0:i.body)?be(t.contentDocument.body.childNodes):be((null!==(r=t.shadowRoot)&&void 0!==r?r:t).childNodes),0===s.length||$e(t,HTMLVideoElement)||await s.reduce(((t,i)=>t.then((()=>Re(i,n))).then((t=>{t&&e.appendChild(t)}))),Promise.resolve()),e}(t,n,e))).then((n=>function(t,e,n){return $e(e,Element)&&(function(t,e,n){const i=e.style;if(!i)return;const r=window.getComputedStyle(t);r.cssText?(i.cssText=r.cssText,i.transformOrigin=r.transformOrigin):Ae(n).forEach((n=>{let s=r.getPropertyValue(n);if("font-size"===n&&s.endsWith("px")){const t=Math.floor(parseFloat(s.substring(0,s.length-2)))-.1;s=`${t}px`}$e(t,HTMLIFrameElement)&&"display"===n&&"inline"===s&&(s="block"),"d"===n&&e.getAttribute("d")&&(s=`path(${e.getAttribute("d")})`),i.setProperty(n,s,r.getPropertyPriority(n))}))}(t,e,n),function(t,e,n){Ce(t,e,":before",n),Ce(t,e,":after",n)}(t,e,n),function(t,e){$e(t,HTMLTextAreaElement)&&(e.innerHTML=t.value),$e(t,HTMLInputElement)&&e.setAttribute("value",t.value)}(t,e),function(t,e){if($e(t,HTMLSelectElement)){const n=Array.from(e.children).find((e=>t.value===e.getAttribute("value")));n&&n.setAttribute("selected","")}}(t,e)),e}(t,n,e))).then((t=>async function(t,e){const n=t.querySelectorAll?t.querySelectorAll("use"):[];if(0===n.length)return t;const i={};for(let r=0;r<n.length;r++){const s=n[r].getAttribute("xlink:href");if(s){const n=t.querySelector(s),r=document.querySelector(s);n||!r||i[s]||(i[s]=await Re(r,e,!0))}}const r=Object.values(i);if(r.length){const e="http://www.w3.org/1999/xhtml",n=document.createElementNS(e,"svg");n.setAttribute("xmlns",e),n.style.position="absolute",n.style.width="0",n.style.height="0",n.style.overflow="hidden",n.style.display="none";const i=document.createElementNS(e,"defs");n.appendChild(i);for(let t=0;t<r.length;t++)i.appendChild(r[t]);t.appendChild(n)}return t}(t,e))):null}const We=/url\((['"]?)([^'"]+?)\1\)/g,Ue=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Fe=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function Ke(t){return-1!==t.search(We)}async function Ve(t,e,n){if(!Ke(t))return t;const i=function(t,{preferredFontFormat:e}){return e?t.replace(Fe,(t=>{for(;;){const[n,,i]=Ue.exec(t)||[];if(!i)return"";if(i===e)return`src: ${n};`}})):t}(t,n),r=function(t){const e=[];return t.replace(We,((t,n,i)=>(e.push(i),t))),e.filter((t=>!_e(t)))}(i);return r.reduce(((t,i)=>t.then((t=>async function(t,e,n,i){try{const r=n?function(t,e){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;const n=document.implementation.createHTMLDocument(),i=n.createElement("base"),r=n.createElement("a");return n.head.appendChild(i),n.body.appendChild(r),e&&(i.href=e),r.href=t,r.href}(e,n):e,s=Ee(e);let o;return o=await Pe(r,s,i),t.replace(function(t){const e=t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${e})(['"]?\\))`,"g")}(e),`$1${o}$3`)}catch(t){}return t}(t,i,e,n)))),Promise.resolve(i))}async function Ne(t,e,n){var i;const r=null===(i=e.style)||void 0===i?void 0:i.getPropertyValue(t);if(r){const i=await Ve(r,null,n);return e.style.setProperty(t,i,e.style.getPropertyPriority(t)),!0}return!1}async function Ge(t,e){$e(t,Element)&&(await async function(t,e){await Ne("background",t,e)||await Ne("background-image",t,e),await Ne("mask",t,e)||await Ne("-webkit-mask",t,e)||await Ne("mask-image",t,e)||await Ne("-webkit-mask-image",t,e)}(t,e),await async function(t,e){const n=$e(t,HTMLImageElement);if((!n||_e(t.src))&&(!$e(t,SVGImageElement)||_e(t.href.baseVal)))return;const i=n?t.src:t.href.baseVal,r=await Pe(i,Ee(i),e);await new Promise(((i,s)=>{t.onload=i,t.onerror=e.onImageErrorHandler?(...t)=>{try{i(e.onImageErrorHandler(...t))}catch(t){s(t)}}:s;const o=t;o.decode&&(o.decode=i),"lazy"===o.loading&&(o.loading="eager"),n?(t.srcset="",t.src=r):t.href.baseVal=r}))}(t,e),await async function(t,e){const n=be(t.childNodes).map((t=>Ge(t,e)));await Promise.all(n).then((()=>t))}(t,e))}const He={};async function Xe(t){let e=He[t];if(null!=e)return e;const n=await fetch(t);return e={url:t,cssText:await n.text()},He[t]=e,e}async function Ye(t,e){let n=t.cssText;const i=/url\(["']?([^"')]+)["']?\)/g,r=(n.match(/url\([^)]+\)/g)||[]).map((async r=>{let s=r.replace(i,"$1");return s.startsWith("https://")||(s=new URL(s,t.url).href),Le(s,e.fetchRequestInit,(({result:t})=>(n=n.replace(r,`url(${t})`),[r,t])))}));return Promise.all(r).then((()=>n))}function Qe(t){if(null==t)return[];const e=[];let n=t.replace(/(\/\*[\s\S]*?\*\/)/gi,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const t=i.exec(n);if(null===t)break;e.push(t[0])}n=n.replace(i,"");const r=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,s=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let t=r.exec(n);if(null===t){if(t=s.exec(n),null===t)break;r.lastIndex=s.lastIndex}else s.lastIndex=r.lastIndex;e.push(t[0])}return e}function Ze(t){return t.trim().replace(/["']/g,"")}async function qe(t,e){const n=await async function(t,e){if(null==t.ownerDocument)throw new Error("Provided element is not within a Document");const n=be(t.ownerDocument.styleSheets),i=await async function(t,e){const n=[],i=[];return t.forEach((n=>{if("cssRules"in n)try{be(n.cssRules||[]).forEach(((t,r)=>{if(t.type===CSSRule.IMPORT_RULE){let s=r+1;const o=Xe(t.href).then((t=>Ye(t,e))).then((t=>Qe(t).forEach((t=>{try{n.insertRule(t,t.startsWith("@import")?s+=1:n.cssRules.length)}catch(e){console.error("Error inserting rule from remote css",{rule:t,error:e})}})))).catch((t=>{console.error("Error loading remote css",t.toString())}));i.push(o)}}))}catch(r){const s=t.find((t=>null==t.href))||document.styleSheets[0];null!=n.href&&i.push(Xe(n.href).then((t=>Ye(t,e))).then((t=>Qe(t).forEach((t=>{s.insertRule(t,s.cssRules.length)})))).catch((t=>{console.error("Error loading remote stylesheet",t)}))),console.error("Error inlining remote css file",r)}})),Promise.all(i).then((()=>(t.forEach((t=>{if("cssRules"in t)try{be(t.cssRules||[]).forEach((t=>{n.push(t)}))}catch(e){console.error(`Error while reading CSS rules from ${t.href}`,e)}})),n)))}(n,e);return function(t){return t.filter((t=>t.type===CSSRule.FONT_FACE_RULE)).filter((t=>Ke(t.style.getPropertyValue("src"))))}(i)}(t,e),i=function(t){const e=new Set;return function t(n){(n.style.fontFamily||getComputedStyle(n).fontFamily).split(",").forEach((t=>{e.add(Ze(t))})),Array.from(n.children).forEach((e=>{e instanceof HTMLElement&&t(e)}))}(t),e}(t);return(await Promise.all(n.filter((t=>i.has(Ze(t.style.fontFamily)))).map((t=>Ve(t.cssText,t.parentStyleSheet?t.parentStyleSheet.href:null,e))))).join("\n")}async function Je(t,e={}){const{width:n,height:i}=Se(t,e),r=await Re(t,e,!0);return await async function(t,e){const n=null!=e.fontEmbedCSS?e.fontEmbedCSS:e.skipFonts?null:await qe(t,e);if(n){const e=document.createElement("style"),i=document.createTextNode(n);e.appendChild(i),t.firstChild?t.insertBefore(e,t.firstChild):t.appendChild(e)}}(r,e),await Ge(r,e),function(t,e){const{style:n}=t;e.backgroundColor&&(n.backgroundColor=e.backgroundColor),e.width&&(n.width=`${e.width}px`),e.height&&(n.height=`${e.height}px`);const i=e.style;null!=i&&Object.keys(i).forEach((t=>{n[t]=i[t]}))}(r,e),await async function(t,e,n){const i="http://www.w3.org/2000/svg",r=document.createElementNS(i,"svg"),s=document.createElementNS(i,"foreignObject");return r.setAttribute("width",`${e}`),r.setAttribute("height",`${n}`),r.setAttribute("viewBox",`0 0 ${e} ${n}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),r.appendChild(s),s.appendChild(t),async function(t){return Promise.resolve().then((()=>(new XMLSerializer).serializeToString(t))).then(encodeURIComponent).then((t=>`data:image/svg+xml;charset=utf-8,${t}`))}(r)}(r,n,i)}class tn{static shouldKeepWheelInCustomElement(t,e){if(t.ctrlKey||!0!==e.isSelected)return!1;const n="function"==typeof t.composedPath?t.composedPath():[],i=this.getScrollableContainerFromEventPath(n,e);return!!i&&this.canElementConsumeWheel(i,t.deltaX,t.deltaY)}static getScrollableContainerFromEventPath(t,e){const n=[];e.element instanceof HTMLElement&&n.push(e.element),e.elementRef instanceof HTMLElement&&n.push(e.elementRef);const i=e.elmeentRef;i instanceof HTMLElement&&n.push(i);for(const e of n){const n=t.findIndex((t=>t===e));if(-1!==n)for(const e of t.slice(0,n+1))if(e instanceof HTMLElement&&this.isScrollableElement(e))return e}for(const t of n){if(this.isScrollableElement(t))return t;const e=t.firstElementChild;if(e instanceof HTMLElement&&this.isScrollableElement(e))return e}return null}static isScrollableElement(t){const e=t.scrollHeight-t.clientHeight>0,n=t.scrollWidth-t.clientWidth>0;if(!e&&!n)return!1;const i=window.getComputedStyle(t),r=i.overflowX,s=i.overflowY;return e&&"visible"!==s&&"clip"!==s||n&&"visible"!==r&&"clip"!==r}static canElementConsumeWheel(t,e,n){const i=this.canElementConsumeVerticalWheel(t,n),r=this.canElementConsumeHorizontalWheel(t,e);return i||r}static canElementConsumeVerticalWheel(t,e){if(0===e)return!1;const n=Math.max(0,t.scrollHeight-t.clientHeight);return 0!==n&&(e>0?t.scrollTop<n-1:!!(e<0)&&t.scrollTop>1)}static canElementConsumeHorizontalWheel(t,e){if(0===e)return!1;const n=Math.max(0,t.scrollWidth-t.clientWidth);return 0!==n&&(e>0?t.scrollLeft<n-1:!!(e<0)&&t.scrollLeft>1)}}const en=t(class extends e{get host(){return this}workspace;async onWorkspaceChange(t){const e=t?.id;if(!e)return;await Promise.resolve();const n=this.core.store.state.activeWorkspace?.id;n!==e&&(this.core.beforeWorkspaceChange(),await this.initializeWorkspaceIfNeeded(t),this.activeWorkspaceChange.emit(this.core.store.state.activeWorkspace))}editorId;activeWorkspaceId;async onActiveWorkspaceIdChange(t){t&&this._isYjsInitialized&&await this.switchToWorkspaceById(t)}syncConfig;async onSyncConfigChange(t){this._syncConfigRevision++,this.core.setSyncConfig(t),t&&!this._isYjsInitialized&&this._isViewportReady&&await this.initializeSyncAndWorkspace()}assetStorageConfig;async onAssetStorageConfigChange(t){this._assetStorageConfigRevision++,this.core.setAssetStorageConfig(t),t&&!this._isAssetStorageInitialized&&this._isViewportReady&&await this.initializeAssetStorage()}user;onUserChange(t){this.core.setUser(t)}globalContextMenuItems;onGlobalContextMenuItemsChange(t){this.contextMenuHandler&&(this.contextMenuHandler.globalContextMenuItems=t??[])}objectContextMenuItems;onObjectContextMenuItemsChange(t){this.contextMenuHandler&&(this.contextMenuHandler.objectContextMenuItems=t??[])}scaleMax=z;validateScaleMax(t){t>z?(console.warn(`scaleMax cannot be greater than ${z}.`),this.scaleMax=z,this.core.store.state.scaleMax=this.scaleMax):this.core.store.state.scaleMax=t}scaleMin=$;validateScaleMin(t){t<$?(console.warn(`scaleMin cannot be less than ${$}.`),this.scaleMin=$,this.core.store.state.scaleMin=this.scaleMin):this.core.store.state.scaleMin=t}cursorTarget;onCursorTargetChange(t){this.core.cursorManager.setTargetElement(t||document.body)}lockDrawingScale=!0;onLockDrawingScaleChange(t){this.core.store.state.lockDrawingScale=t}isObjectDistanceFadingActive=!1;onIsObjectDistanceFadingActiveChange(){this.core.rerender()}theme="light";onThemeChange(t){this.core.themeManager.setTheme(t)}licenseKey;onLicenseKeyChange(t){this.core.licenseManager.validate(t)}themes;onThemesChange(t){t&&t.length>0&&(this.core.themeManager.registerThemes(t),this.core.themeManager.applyTheme(this.core.themeManager.currentTheme))}locale="en";onLocaleChange(t){this.core.localizationManager.setLocale(t)}locales;onLocalesChange(t){t&&t.length>0&&(this.core.localizationManager.registerLocales(t),this.core.localizationManager.setLocale(this.locale))}fallbackLocale="en";onFallbackLocaleChange(t){this.core.localizationManager.setFallbackLocale(t),this.core.rerender()}viewportBoundaryLeft=-1/0;onViewportBoundaryLeftChange(t){this.core.store.state.viewportBoundaryLeft=t??-1/0}viewportBoundaryRight=1/0;onViewportBoundaryRightChange(t){this.core.store.state.viewportBoundaryRight=t??1/0}viewportBoundaryTop=-1/0;onViewportBoundaryTopChange(t){this.core.store.state.viewportBoundaryTop=t??-1/0}viewportBoundaryBottom=1/0;onViewportBoundaryBottomChange(t){this.core.store.state.viewportBoundaryBottom=t??1/0}debugInfo;onDebugInfoChange(t){t&&(this.core.store.state.debugInfo=t,this.core.assetResolver.setShowInfo(t.showAssetResolverInfo))}isPanningEnabled=!0;isZoomingEnabled=!0;isLoading=!1;onIsLoadingChange(){this.syncLoadingState()}isEngineReady;activeToolChange;objectsSelectionChange;workspacesChange;activeWorkspaceChange;longpress;objectsChange;objectsAdded;objectsRemoved;objectsUpdated;undoStateChange;objectsInViewportChange;viewportChange;awarenessChange;notificationsChange;forceUpdate=0;async triggerSelectionChange(){this.objectsSelectionChange.emit()}handleWheel(t){if(this.core.store.isDisabled)return;this.core.store.state.isContextMenuVisible&&this.hideContextMenu();const e=this.core.getObjectFromPointerEvent(t);e&&R.isClass(e,"KritzelCustomElement")&&tn.shouldKeepWheelInCustomElement(t,e)||(t.ctrlKey?this.isZoomingEnabled&&this.viewport.handleWheel(t):this.isPanningEnabled&&this.viewport.handleWheel(t),this.core.store.state?.activeTool?.handleWheel(t))}handlePointerDown(t){this.core.store.isDisabled||this.isEmbeddedCustomElementInteraction(t)||(N.isTouchDevice()&&l.onLongPress(t,(t=>this.longpress.emit(t))),this.host.setPointerCapture(t.pointerId),this.core.store.state.pointers.set(t.pointerId,t),this.viewport.handlePointerDown(t),this.core.store.state?.activeTool?.handlePointerDown(t))}throttledPointerMoveMulti=ee.throttle((t=>{this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t)}),16);handlePointerMove(t){this.core.store.isDisabled||t.buttons>0&&!this.core.store.state.pointers.has(t.pointerId)||(this.core.store.state.pointers.has(t.pointerId)&&this.core.store.state.pointers.set(t.pointerId,t),this.core.store.state.pointers.size>1&&this.throttledPointerMoveMulti(t),this.core.cursorManager.updateHoverState(t),this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t))}handlePointerUp(t){if(this.core.store.isDisabled)return;const e=this.core.store.state.pointers.has(t.pointerId);this.core.store.state.pointers.delete(t.pointerId),this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),e&&(this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handlePointerCancel(t){this.core.store.isDisabled||(this.host.hasPointerCapture(t.pointerId)&&this.host.releasePointerCapture(t.pointerId),this.core.store.state.pointers.delete(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}isEmbeddedCustomElementInteraction(t){const n=t.composedPath(),i=n.find((t=>t instanceof e&&t.classList.contains("object")));if(!i?.id)return!1;const r=this.core.store.objects.findById(i.id);if(!r||!p.isInstanceOf(r,"KritzelCustomElement"))return!1;if(!this.core.store.selectionGroup?.objects?.some((t=>t.id===r.id)))return!1;if(!0!==r.isInteractive)return!1;const s=[];return r.element instanceof e&&s.push(r.element),r.elementRef instanceof e&&s.push(r.elementRef),0!==s.length&&s.some((t=>this.isNativeInteractiveEmbeddedTarget(n,t)))}isNativeInteractiveEmbeddedTarget(t,n){const i=t.findIndex((t=>t===n));if(-1===i)return!1;for(const n of t.slice(0,i))if(n instanceof e&&n.matches('input, button, textarea, select, a[href], [contenteditable="true"], [contenteditable=""]'))return!0;return!1}handlePointerLeave(){this.core.store.objects?.clearCursorPosition()}handleLongPress(t){this.contextMenuHandler.handleContextMenu(t.detail)}handleContextMenu(t){t.cancelable&&t.preventDefault(),this.core.store.isDisabled||"touch"!==t.pointerType&&"pen"!==t.pointerType&&this.contextMenuHandler.handleContextMenu(t)}handleResize(){this.viewport.handleResize()}handleKeyDown(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&this.keyHandler.handleKeyDown(t)}handleKeyUp(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&this.keyHandler.handleKeyUp(t)}handleCopy(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&(!this.core.store.selectionGroup||this.core.store.activeText||this.core.store.activeShape||(t.cancelable&&t.preventDefault(),this.core.clipboardManager.copy(t),this.core.rerender()))}handleCut(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&(!this.core.store.selectionGroup||this.core.store.activeText||this.core.store.activeShape||(t.cancelable&&t.preventDefault(),this.core.clipboardManager.cut(t)))}handlePaste(t){!this.core.store.isDisabled&&this.shouldHandleGlobalShortcutEvent(t)&&(this.core.store.activeText||this.core.store.activeShape||(t.cancelable&&t.preventDefault(),this.core.clipboardManager.paste(void 0,void 0,t)))}shouldHandleGlobalShortcutEvent(t){const n=t.composedPath();if(n.includes(this.host))return!0;if(n.some((t=>t instanceof e&&("DIALOG"===t.tagName||"KRITZEL-DIALOG"===t.tagName||"dialog"===t.getAttribute?.("role")||"alertdialog"===t.getAttribute?.("role")))))return!1;const i=n[0];return!(i instanceof e&&i.matches?.('input, textarea, select, [contenteditable="true"], [contenteditable=""]'))}preventDoubleTapZoomOnTouchDevices(t){t.cancelable&&t.preventDefault()}async registerTool(t,e,n){if("function"!=typeof e)return console.error(`Failed to register tool "${t}": Tool class must be a constructor function`),null;if(this.core.toolRegistry.hasTool(t)){const e=this.core.toolRegistry.getTool(t);return n&&this.applyToolConfig(e,n),e}const i=this.core.toolRegistry.registerTool(t,e);return n&&this.applyToolConfig(i,n),Promise.resolve(i)}async changeActiveTool(t){this.core.store.state.activeTool!==t&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",t),this.core.deselectAllObjects(),t?.onActivate())}async changeActiveToolByName(t){const e=this.core.toolRegistry.getTool(t);e?await this.changeActiveTool(e):console.warn(`[KritzelEngine] No tool registered with name: ${t}`)}async disable(){this.core.store.state.isEnabled=!1,this.core.rerender()}async enable(){this.core.store.state.isEnabled=!0,this.core.rerender()}async delete(){this.core.delete()}async copy(){this.core.clipboardManager.copy()}async cut(){this.core.clipboardManager.cut()}async paste(t,e){"granted"===await this.core.permissionManager.requestPermission("clipboard-read")?this.core.clipboardManager.paste(t,e):this.notificationsChange.emit({type:"error",message:"Clipboard read permission is required to paste content. Please grant permission and try again.",id:R.generateUUID()})}async bringForward(t){this.core.bringForward(t)}async sendBackward(t){this.core.sendBackward(t)}async bringToFront(t){this.core.bringToFront(t)}async sendToBack(t){this.core.sendToBack(t)}async alignObjects(t){this.core.alignObjects(t)}async group(){this.core.group()}async ungroup(){this.core.ungroup()}async undo(){this.core.undo()}async redo(){this.core.redo()}async hideContextMenu(){this.core.store.state.pointers.clear(),this.core.store.state.isContextMenuVisible=!1,this.core.store.objects?.remove((t=>t instanceof g)),this.core.store.setSelectionBox(null),this.core.store.objects?.clearLocalSelectionBox(),this.core.store.state.isSelecting=!1,this.core.store.state.isEnabled=!0,this.core.rerender()}async openContextMenu(t){this.contextMenuHandler.open(t)}async getObjectById(t){return this.core.store.allObjects.find((e=>e.id===t))||null}async getAllObjects(){return this.core.store.allObjects}async findObjects(t){return this.core.store.allNonSelectionObjects.filter(t)}async getObjectsTotalCount(){return this.core.store.totalObjectCount}async addObject(t){if(this.core.deselectAllObjects(),t.id=t.generateId(),t._core=this.core,t.scale=t.scale??this.core.store.state.scale,t.zIndex=this.core.store.currentZIndex,t.workspaceId=this.core.store.state.activeWorkspace.id,p.isInstanceOf(t,"KritzelImage")&&await t.prepareForInsert(),p.isInstanceOf(t,"KritzelText")){const e=t.content;t.editor=t.createEditor(),e&&t.setContent(e)}if(p.isInstanceOf(t,"KritzelGroup")&&t._pendingChildren.length>0){const e=new Map,n=[],i=t=>{if(0===t._pendingChildren.length)return;const r=t._pendingChildren;t._pendingChildren=[],t.childIds=[],r.forEach((r=>{const s=r.id;r.id=r.generateId(),r._core=this.core,r.scale=r.scale??this.core.store.state.scale,r.zIndex=this.core.store.currentZIndex,r.workspaceId=this.core.store.state.activeWorkspace.id,e.set(s,r.id),t.childIds.push(r.id),n.push(r),p.isInstanceOf(r,"KritzelGroup")&&i(r)}))};i(t),n.forEach((t=>{p.isInstanceOf(t,"KritzelLine")&&(t.startAnchor&&e.has(t.startAnchor.objectId)&&(t.startAnchor={objectId:e.get(t.startAnchor.objectId)}),t.endAnchor&&e.has(t.endAnchor.objectId)&&(t.endAnchor={objectId:e.get(t.endAnchor.objectId)}))})),n.forEach((t=>{this.core.addObject(t)})),t.finalize(),this.core.anchorManager.rebuildIndex()}return this.core.addObject(t),this.core.rerender(),await new Promise((t=>{requestAnimationFrame((()=>requestAnimationFrame((()=>t()))))})),this.emitObjectsChange(),this.emitObjectsAdded([t]),t}async addObjects(t){if(0===t.length)return[];for(const e of t)e._core=this.core,p.isInstanceOf(e,"KritzelImage")&&await e.prepareForInsert();return this.core.store.objects.transaction((()=>{for(const e of t){if(e.id=e.generateId(),e._core=this.core,e.zIndex=this.core.store.currentZIndex,e.workspaceId=this.core.store.state.activeWorkspace.id,p.isInstanceOf(e,"KritzelText")){const t=e.content;e.editor=e.createEditor(),t&&e.setContent(t)}if(p.isInstanceOf(e,"KritzelGroup")&&e._pendingChildren.length>0){const t=new Map,n=[],i=e=>{if(0===e._pendingChildren.length)return;const r=e._pendingChildren;e._pendingChildren=[],e.childIds=[],r.forEach((r=>{const s=r.id;r.id=r.generateId(),r._core=this.core,r.zIndex=this.core.store.currentZIndex,r.workspaceId=this.core.store.state.activeWorkspace.id,t.set(s,r.id),e.childIds.push(r.id),n.push(r),p.isInstanceOf(r,"KritzelGroup")&&i(r)}))};i(e),n.forEach((e=>{p.isInstanceOf(e,"KritzelLine")&&(e.startAnchor&&t.has(e.startAnchor.objectId)&&(e.startAnchor={objectId:t.get(e.startAnchor.objectId)}),e.endAnchor&&t.has(e.endAnchor.objectId)&&(e.endAnchor={objectId:t.get(e.endAnchor.objectId)}))})),n.forEach((t=>{this.core.addObject(t)})),e.finalize(),this.core.anchorManager.rebuildIndex()}this.core.addObject(e)}})),this.core.rerender(),await new Promise((t=>{requestAnimationFrame((()=>requestAnimationFrame((()=>t()))))})),this.emitObjectsChange(),this.emitObjectsAdded(t),t}async updateObject(t,e){return this.core.deselectAllObjects(),this.core.updateObject(t,e),this.core.rerender(),this.emitObjectsChange(),this.emitObjectsUpdated([{object:t,changedProperties:Object.keys(e)}]),t}async removeObject(t){const e=this.core.store.objects;return e?(this.core.deselectAllObjects(),e.remove((e=>e.id===t.id)),this.core.rerender(),this.emitObjectsChange(),this.emitObjectsRemoved([t]),t):null}async removeObjects(t){const e=this.core.store.objects;return e&&0!==t.length?(e.transaction((()=>{for(const e of t)this.core.removeObject(e)})),this.core.rerender(),this.emitObjectsChange(),this.emitObjectsRemoved(t),t):[]}async getSelectedObjects(){const t=this.core.store.selectionGroup;return t?t.objects:[]}async getDisplayableShortcuts(){return this.keyHandler.getDisplayableShortcuts()}async selectObjects(t){const e=this.core.toolRegistry.getTool("selection");e&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",e),this.core.deselectAllObjects(),this.core.selectObjects(t))}async selectAllObjectsInViewport(){const t=this.core.toolRegistry.getTool("selection");t&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",t),this.core.deselectAllObjects(),this.core.selectAllObjectsInViewport())}async clearSelection(){this.core.clearSelection()}async centerObjectInViewport(t){return t.centerInViewport(),this.core.updateObject(t,t),this.core.rerender(),t}async panToObject(t){this.viewport.panTo(t.centerX,t.centerY)}async backToContent(){return this.viewport.centerFitNearestContent(20)}async centerAllObjects(t=!0){return this.viewport.centerFitAllObjects(t)}async centerObjects(t,e=!0){return this.viewport.centerFitObjects(t,e)}async setViewport(t,e,n){this.viewport.setViewport(t,e,n)}async panTo(t,e){this.viewport.panTo(t,e)}async zoomTo(t,e,n){this.viewport.zoomTo(t,e,n)}async zoomIn(t,e){this.viewport.zoomIn(t,e)}async zoomOut(t,e){this.viewport.zoomOut(t,e)}async getViewport(){return this.viewport.getViewport()}async screenToWorld(t,e){return this.viewport.screenToWorld(t,e)}async worldToScreen(t,e){return this.viewport.worldToScreen(t,e)}async getObjectsInViewport(){return this.core.getObjectsInViewport()}async getScreenshot(t="png",e){if(!this.host)return null;const n={objects:this.core.store.objects,activeWorkspace:this.core.store.state.activeWorkspace,workspaces:this.core.store.state.workspaces,activeTool:this.core.store.state.activeTool,isReady:this.core.store.state.isReady,translateX:this.core.store.state.translateX,translateY:this.core.store.state.translateY,scale:this.core.store.state.scale},i={filter:t=>!("KRITZEL-CONTEXT-MENU"===t.tagName||"KRITZEL-AWARENESS-CURSORS"===t.tagName||t.classList&&t.classList.contains("debug-panel"))};let r;(e?.includeBackground??1)||(i.backgroundColor="transparent");try{r="svg"===t?await Je(this.host,i):await async function(t,e={}){return(await async function(t,e={}){const{width:n,height:i}=Se(t,e),r=await Je(t,e),s=await ze(r),o=document.createElement("canvas"),a=o.getContext("2d"),c=e.pixelRatio||function(){let t,e;try{e=process}catch(t){}const n=e&&e.env?e.env.devicePixelRatio:null;return n&&(t=parseInt(n,10),Number.isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}(),l=e.canvasWidth||n,h=e.canvasHeight||i;return o.width=l*c,o.height=h*c,e.skipAutoScale||function(t){(t.width>Me||t.height>Me)&&(t.width>Me&&t.height>Me?t.width>t.height?(t.height*=Me/t.width,t.width=Me):(t.width*=Me/t.height,t.height=Me):t.width>Me?(t.height*=Me/t.width,t.width=Me):(t.width*=Me/t.height,t.height=Me))}(o),o.style.width=`${l}`,o.style.height=`${h}`,e.backgroundColor&&(a.fillStyle=e.backgroundColor,a.fillRect(0,0,o.width,o.height)),a.drawImage(s,0,0,o.width,o.height),o}(t,e)).toDataURL()}(this.host,i)}finally{this.core.store.state.objects=n.objects,this.core.store.state.activeWorkspace=n.activeWorkspace,this.core.store.state.workspaces=n.workspaces,this.core.store.state.activeTool=n.activeTool,this.core.store.state.isReady=n.isReady,this.core.store.state.translateX=n.translateX,this.core.store.state.translateY=n.translateY,this.core.store.state.scale=n.scale,this.core.rerender()}return r}async exportViewportAsPng(t){try{const e=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.png`,n=await this.getScreenshot("png",t);if(!n)return void console.error("Failed to export viewport as PNG: screenshot could not be generated");const i=document.createElement("a");i.download=e,i.href=n,i.click()}catch(t){console.error("Failed to export viewport as PNG:",t)}}async exportViewportAsSvg(t){try{const e=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.svg`,n=await this.getScreenshot("svg",t);if(!n)return void console.error("Failed to export viewport as SVG: screenshot could not be generated");const i=document.createElement("a");i.download=e,i.href=n,i.click()}catch(t){console.error("Failed to export viewport as SVG:",t)}}async getSelectedObjectsAsSvgString(t){const e=await this.getSelectedObjects();if(!e||0===e.length)return null;const n=t?.theme??this.core.themeManager.getStoredTheme(),i=await me.resolveImageDataUrls(e,this.core.assetResolver);return me.generateSvg(e,{theme:n,padding:t?.padding??0,includeXmlDeclaration:!0,rasterSafeForCanvas:t?.rasterSafeForCanvas??!1,imageDataUrls:i})}async exportSelectedObjectsAsSvg(t){try{const e=await this.getSelectedObjectsAsSvgString(t);if(!e)return void console.warn("No objects selected for SVG export");const n=`selection-${(new Date).toISOString().replace(/[:.]/g,"-")}.svg`,i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(i),s=document.createElement("a");s.download=n,s.href=r,s.click(),URL.revokeObjectURL(r)}catch(t){console.error("Failed to export selected objects as SVG:",t)}}async getSelectedObjectsAsPngDataUrl(t){const e=await this.getSelectedObjectsAsSvgString({theme:t?.theme,padding:t?.padding,rasterSafeForCanvas:!0});if(!e)return null;const n=t?.scale??2;return new Promise(((t,i)=>{const r=new Image,s=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),o=URL.createObjectURL(s);r.onload=()=>{const e=document.createElement("canvas");e.width=r.width*n,e.height=r.height*n;const s=e.getContext("2d");if(!s)return URL.revokeObjectURL(o),void i(new Error("Failed to get canvas context"));s.scale(n,n),s.drawImage(r,0,0),URL.revokeObjectURL(o),t(e.toDataURL("image/png"))},r.onerror=()=>{URL.revokeObjectURL(o),i(new Error("Failed to load SVG for PNG conversion"))},r.src=o}))}async exportSelectedObjectsAsPng(t){try{const e=await this.getSelectedObjectsAsPngDataUrl(t);if(!e)return void console.warn("No objects selected for PNG export");const n=`selection-${(new Date).toISOString().replace(/[:.]/g,"-")}.png`,i=document.createElement("a");i.download=n,i.href=e,i.click()}catch(t){console.error("Failed to export selected objects as PNG:",t)}}async exportAsJson(){const t=this.core.store.state.activeWorkspace;if(!t)throw new Error("Cannot export workspace: no active workspace is loaded");const e=t.serialize({includeObjects:!0});return JSON.stringify(e,null,2)}async importFromJson(t){const e=JSON.parse(t);if(!e.__class__||"KritzelWorkspace"!==e.__class__)throw new Error("Invalid workspace data: missing or incorrect __class__ identifier");e.version&&e.version!==I&&console.warn(`Workspace version mismatch: expected ${I}, got ${e.version}`);const n=R.generateUUID();let i=e.viewport||{centerWorldX:0,centerWorldY:0,scale:1};if("translateX"in i&&!("centerWorldX"in i)){const t=i.scale??1;i={centerWorldX:-(i.translateX??0)/t,centerWorldY:-(i.translateY??0)/t,scale:t}}const r=new T(n,e.name||"Imported Workspace",i);if(this.core.createWorkspace(r),this.workspacesChange.emit(this.core.store.state.workspaces),this.core.beforeWorkspaceChange(),await this.core.initializeWorkspace(r),e.objects&&Array.isArray(e.objects)){const t=new se(this.core);for(const i of e.objects){const e=t.revive(i);e&&(e.workspaceId=n,this.core.addObject(e))}}this.core.rerender(),this.activeWorkspaceChange.emit(r)}async loadObjectsFromJson(t){const e=JSON.parse(t);if(!e.__class__||"KritzelWorkspace"!==e.__class__)throw new Error("Invalid workspace data: missing or incorrect __class__ identifier");e.version&&e.version!==I&&console.warn(`Workspace version mismatch: expected ${I}, got ${e.version}`);const n=this.core.store.state.activeWorkspace;if(!n)throw new Error("Cannot load objects: no active workspace is loaded");const i=n.id;let r=0;if(e.objects&&Array.isArray(e.objects)){const t=new se(this.core);for(const n of e.objects){const e=t.revive(n);e&&(e.workspaceId=i,this.core.addObject(e),r++)}}return this.core.rerender(),r}async downloadAsJson(t){try{const e=await this.exportAsJson(),n=this.core.store.state?.activeWorkspace?.name||"workspace",i=(new Date).toISOString().replace(/[:.]/g,"-"),r=t||`${n}-${i}`,s=new Blob([e],{type:"application/json;charset=utf-8"}),o=URL.createObjectURL(s),a=document.createElement("a");a.download=`${r}.json`,a.href=o,a.click(),URL.revokeObjectURL(o)}catch(t){console.error("Failed to download workspace as JSON:",t)}}async importFromFile(){return new Promise(((t,e)=>{const n=document.createElement("input");n.type="file",n.accept=".json,application/json",n.style.display="none";const i=()=>{n.removeEventListener("change",r),n.removeEventListener("cancel",s),document.body.removeChild(n)},r=async n=>{const r=n.target,s=r.files?.[0];if(!s)return i(),void t();try{const n=new FileReader;n.onload=async n=>{try{const e=n.target?.result;await this.importFromJson(e),i(),t()}catch(t){i(),console.error("Failed to import workspace from file:",t),e(t)}},n.onerror=()=>{i(),console.error("Failed to read file:",n.error),e(n.error)},n.readAsText(s)}catch(t){i(),console.error("Failed to process file:",t),e(t)}},s=()=>{i(),t()};n.addEventListener("change",r),n.addEventListener("cancel",s),document.body.appendChild(n),n.click()}))}async createWorkspace(t){return await this.core.createWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces),t}async updateWorkspace(t){await this.core.updateWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async deleteWorkspace(t){await this.core.deleteWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async getWorkspaces(){return await this.core.getWorkspaces()}async getActiveWorkspace(){const t=this.core.store.state.activeWorkspace;if(!t)throw new Error("No active workspace is loaded");return t}async getIsPublic(){return this.core.getIsPublic()}async loadSharedWorkspace(t){const e=t;let n=this.core.getWorkspaces().find((t=>t.id===e));n?n.isPublic=!0:(n=new T(e,"Shared Workspace"),n.isPublic=!0,this.core.createWorkspace(n)),this.workspacesChange.emit(this.core.store.state.workspaces),this.core.beforeWorkspaceChange(),await this.initializeWorkspaceIfNeeded(n),this.activeWorkspaceChange.emit(this.core.store.state.activeWorkspace)}async reinitSync(){this.core.setSyncConfig(this.syncConfig),this.core.setAssetStorageConfig(this.assetStorageConfig),this.core.store.objects?.clearCursorPosition(),this.core.store.objects?.destroy(),this.core.appStateMap.destroy(),this.core.assetResolver.destroy(),this._isYjsInitialized=!1,this._isAssetStorageInitialized=!1,await this.initializeSyncAndWorkspace()}async saveSettings(t){const e=this.core.getStorageKey("kritzel-settings");localStorage.setItem(e,JSON.stringify(t))}async loadSettings(){const t=this.core.getStorageKey("kritzel-settings"),e=localStorage.getItem(t);if(!e)return null;try{return JSON.parse(e)}catch{return null}}async registerLocales(t){this.core.localizationManager.registerLocales(t),this.core.localizationManager.setLocale(this.core.localizationManager.currentLocale)}async setLocale(t){this.locale=t,this.core.localizationManager.setLocale(t)}async getLocale(){return this.core.localizationManager.currentLocale}async getAvailableLocales(){return this.core.localizationManager.getAvailableLocales()}async getAvailableLocaleOptions(){return this.core.localizationManager.getAvailableLocaleOptions()}async t(t,e){return this.core.localizationManager.translate(t,e)}async getResolvedTerms(){return this.core.localizationManager.getAllTerms()}core;viewport;contextMenuHandler;keyHandler;contextMenuElement=null;_lastHadSelectionGroup=!1;_isViewportReady=!1;_isYjsInitialized=!1;_isAssetStorageInitialized=!1;_isResolvingActiveWorkspaceId=!1;_stateChangeListenersRegistered=!1;_workspaceInitializationPromise=null;_workspaceInitializationTargetKey=null;_syncInitPromise=null;_syncConfigRevision=0;_assetStorageConfigRevision=0;_isWorkspaceLoading=!1;_hasLoggedUnlicensedWelcomeBanner=!1;_previousVisibleCustomElements=new Set;_defaultUndoState={canUndo:!1,canRedo:!1,undoStackSize:0,redoStackSize:0};_objectDistanceFadeNearScale=1;_objectDistanceFadeFarScale=.15;_objectDistanceFadeMinOpacity=0;_objectDistanceFadeCloseStartScale=2;_objectDistanceFadeCloseMaxScale=4;_objectDistanceFadeCloseMinOpacity=0;syncLoadingState(){this.core.store.state.isLoading=this._isWorkspaceLoading||this.isLoading}applyToolConfig(t,e){if(Object.entries(e).forEach((([e,n])=>{t[e]=n})),"palettes"in e&&"type"in e){const n=e.palettes[e.type];n&&(t.palette=n)}if("sizes"in e&&null!=e.sizes&&"type"in e){const n=e,i=n.sizes?.[n.type];i&&(t.sizes=i)}}get isSelecting(){return this.core.store.state.activeTool instanceof w&&this.core.store.state.isSelecting}get isSelectionActive(){return this.core.store.state.activeTool instanceof w&&null!==this.core.store.selectionGroup}constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isEngineReady=n(this,"isEngineReady"),this.activeToolChange=n(this,"activeToolChange"),this.objectsSelectionChange=n(this,"objectsSelectionChange"),this.workspacesChange=n(this,"workspacesChange"),this.activeWorkspaceChange=n(this,"activeWorkspaceChange"),this.longpress=n(this,"longpress"),this.objectsChange=n(this,"objectsChange"),this.objectsAdded=n(this,"objectsAdded"),this.objectsRemoved=n(this,"objectsRemoved"),this.objectsUpdated=n(this,"objectsUpdated"),this.undoStateChange=n(this,"undoStateChange"),this.objectsInViewportChange=n(this,"objectsInViewportChange"),this.viewportChange=n(this,"viewportChange"),this.awarenessChange=n(this,"awarenessChange"),this.notificationsChange=n(this,"notificationsChange"),this.core=new we(this)}disconnectedCallback(){this.throttledPointerMoveMulti.cancel(),this.core.store.allObjects&&this.core.store.allObjects.forEach((t=>{p.isInstanceOf(t,"KritzelCustomElement")&&t.unmount()})),this.core.store.objects?.clearCursorPosition(),this.core.store.objects&&this.core.store.objects.destroy(),this.core.appStateMap.destroy(),this.core.cursorManager.cleanup(),this.core.themeManager.cleanup(),this.core.licenseManager.destroy()}componentWillLoad(){this.core.setEditorId(this.editorId),this.themes&&this.themes.length>0&&this.core.themeManager.registerThemes(this.themes);const t=this.host.closest("kritzel-editor");this.core.themeManager.injectThemeEarly(t||this.host),this.locales&&this.locales.length>0&&this.core.localizationManager.registerLocales(this.locales),this.core.localizationManager.setFallbackLocale(this.fallbackLocale),this.core.localizationManager.setLocale(this.locale),this.core.licenseManager.validate(this.licenseKey),this.core.licenseManager.startPeriodicValidation(),this.core.setUser(this.user),this.validateScaleMax(this.scaleMax),this.validateScaleMin(this.scaleMin),this.core.store.state.lockDrawingScale=this.lockDrawingScale,this.core.store.state.viewportBoundaryLeft=this.viewportBoundaryLeft,this.core.store.state.viewportBoundaryRight=this.viewportBoundaryRight,this.core.store.state.viewportBoundaryTop=this.viewportBoundaryTop,this.core.store.state.viewportBoundaryBottom=this.viewportBoundaryBottom,this._isWorkspaceLoading=!0,this.syncLoadingState()}async componentDidLoad(){setTimeout((async()=>{this.contextMenuHandler=new re(this.core,this.globalContextMenuItems??[],this.objectContextMenuItems??[]),this.keyHandler=new ie(this.core),this.viewport=new ne(this.core,this.host),this._isViewportReady=!0,this.core.cursorManager.setTargetElement(this.cursorTarget||document.body),this.host.shadowRoot&&this.core.cursorManager.setShadowRoot(this.host.shadowRoot);const t=this.host.closest("kritzel-editor");this.core.themeManager.setTargetElement(t||this.host),await this.initializeSyncAndWorkspace(),!1===this.core.store.state.isReady&&(this.core.store.state.isReady=!0,this.logUnlicensedWelcomeBanner(),this.isEngineReady.emit(this.core.store.state))}),50)}async initializeSyncAndWorkspace(){if(this._syncInitPromise)return this._syncInitPromise;this._syncInitPromise=this.doInitializeSyncAndWorkspace();try{await this._syncInitPromise}finally{this._syncInitPromise=null}}async initializeAssetStorage(){if(this._isAssetStorageInitialized)return;const t=this._assetStorageConfigRevision;this.core.setAssetStorageConfig(this.assetStorageConfig),await this.core.initializeAssetStorage(),t!==this._assetStorageConfigRevision&&(this.core.assetResolver.destroy(),this.core.setAssetStorageConfig(this.assetStorageConfig),await this.core.initializeAssetStorage()),this._isAssetStorageInitialized=!0}logUnlicensedWelcomeBanner(){this.core.licenseManager.isLicensed||this._hasLoggedUnlicensedWelcomeBanner||(this._hasLoggedUnlicensedWelcomeBanner=!0,console.info("%c👋 Welcome to Kritzel","color: #007AFF; font-weight: 700;"),console.info("This version of Kritzel is not licensed. Get a license at: https://kritzel.io"))}async doInitializeSyncAndWorkspace(){const t=this._syncConfigRevision;if(this.core.setSyncConfig(this.syncConfig),this.core.setAssetStorageConfig(this.assetStorageConfig),this._isYjsInitialized||(await this.core.initializeYjs(),t!==this._syncConfigRevision&&(this.core.appStateMap.destroy(),this.core.setSyncConfig(this.syncConfig),this.core.setAssetStorageConfig(this.assetStorageConfig),await this.core.initializeYjs()),this._isYjsInitialized=!0),!this._isAssetStorageInitialized&&this.assetStorageConfig&&await this.initializeAssetStorage(),this.activeWorkspaceId){const t=this.core.getWorkspaces().find((t=>t.id===this.activeWorkspaceId));t?await this.initializeWorkspaceIfNeeded(t):await this.initializeWorkspaceIfNeeded()}else{const t=this.resolveStartupWorkspace();await this.initializeWorkspaceIfNeeded(t)}const e=this.core.store.state.activeWorkspace;e&&this.activeWorkspaceChange.emit(e),this._stateChangeListenersRegistered||(this.core.appStateMap.onRemoteChange((()=>{this.workspacesChange.emit(this.core.store.state.workspaces),this.tryResolveActiveWorkspaceFromId()})),this._registerStateChangeListeners(),this._stateChangeListenersRegistered=!0),this.tryResolveActiveWorkspaceFromId()}resolveStartupWorkspace(){if(this.activeWorkspaceId){const t=this.core.getWorkspaces().find((t=>t.id===this.activeWorkspaceId));if(t)return t;console.warn(`[KritzelEngine] No workspace found with ID: ${this.activeWorkspaceId}`)}return this.workspace}tryResolveActiveWorkspaceFromId(){this.activeWorkspaceId&&!this._isResolvingActiveWorkspaceId&&this.core.store.state.activeWorkspace?.id!==this.activeWorkspaceId&&(this._isResolvingActiveWorkspaceId=!0,this.switchToWorkspaceById(this.activeWorkspaceId,!1).finally((()=>{this._isResolvingActiveWorkspaceId=!1})))}async switchToWorkspaceById(t,e=!0){const n=this.core.getWorkspaces().find((e=>e.id===t));n?this.core.store.state.activeWorkspace?.id!==n.id&&(this.core.beforeWorkspaceChange(),await this.initializeWorkspaceIfNeeded(n),this.activeWorkspaceChange.emit(this.core.store.state.activeWorkspace)):e&&console.warn(`[KritzelEngine] No workspace found with ID: ${t}`)}async initializeWorkspaceIfNeeded(t,e){const n=t?.id??null,i=n??(e?.skipFallbackCreation?"__NO_FALLBACK__":"__AUTO__");if(n&&this.core.store.state.activeWorkspace?.id===n)return;if(this._workspaceInitializationPromise&&this._workspaceInitializationTargetKey===i)return void await this._workspaceInitializationPromise;this._isWorkspaceLoading=!0,this.syncLoadingState();const r=this.core.initializeWorkspace(t,e);this._workspaceInitializationPromise=r,this._workspaceInitializationTargetKey=i;try{await r}finally{this._workspaceInitializationPromise===r&&(this._workspaceInitializationPromise=null,this._workspaceInitializationTargetKey=null),this._isWorkspaceLoading=!1,this.syncLoadingState()}}emitObjectsChange(){const t=this.core.store.objects;if(!t)return this.objectsChange.emit([]),this.undoStateChange.emit(this._defaultUndoState),void(this._lastHadSelectionGroup&&(this._lastHadSelectionGroup=!1,this.objectsSelectionChange.emit()));const e=t.undoState,n=null!==this.core.store.selectionGroup;this.objectsChange.emit(this.core.store.allObjects),this.undoStateChange.emit(e),this._lastHadSelectionGroup!==n&&(this._lastHadSelectionGroup=n,this.objectsSelectionChange.emit())}emitObjectsAdded(t){this.objectsAdded.emit({objects:t})}emitObjectsRemoved(t){this.objectsRemoved.emit({objects:t})}emitObjectsUpdated(t){this.objectsUpdated.emit({objects:t})}emitAwarenessChange(t){this.awarenessChange.emit(t)}emitObjectsInViewportChange(){this.objectsInViewportChange.emit(this.core.store.objectsInViewport)}_registerStateChangeListeners(){this.core.store.onStateChange("activeTool",this._handleActiveToolChange.bind(this))}_handleActiveToolChange(t){t instanceof w||(this.core.clearSelection(),this.core.store.objects?.remove((t=>t instanceof g)),this.core.store.setSelectionBox(null),this.core.store.objects?.clearLocalSelectionBox(),this.core.store.state.isSelecting=!1,this.core.store.state.isResizeHandleSelected=!1,this.core.store.state.isRotationHandleSelected=!1),t instanceof m||this.core.resetActiveText(),t instanceof Ot||this.core.resetActiveShape(),this.core.store.state.skipContextMenu=!1,t&&this.activeToolChange.emit(t),A.forceHideKeyboard(),this.core.rerender()}getObjectDistanceFadeMultiplier(t,e){if(!this.isObjectDistanceFadingActive)return 1;const n=Math.max(Number.isFinite(e)?e:1,Number.EPSILON)/Math.max(Number.isFinite(t)?t:1,Number.EPSILON),i=this.getFarDistanceFadeMultiplier(n),r=this.getCloseDistanceFadeMultiplier(n);return Math.min(i,r)}getFarDistanceFadeMultiplier(t){if(t>=this._objectDistanceFadeNearScale)return 1;if(t<=this._objectDistanceFadeFarScale)return this._objectDistanceFadeMinOpacity;const e=(this._objectDistanceFadeNearScale-t)/(this._objectDistanceFadeNearScale-this._objectDistanceFadeFarScale);return 1-e*e*(3-2*e)*(1-this._objectDistanceFadeMinOpacity)}getCloseDistanceFadeMultiplier(t){if(t<=this._objectDistanceFadeCloseStartScale)return 1;if(t>=this._objectDistanceFadeCloseMaxScale)return this._objectDistanceFadeCloseMinOpacity;const e=(t-this._objectDistanceFadeCloseStartScale)/(this._objectDistanceFadeCloseMaxScale-this._objectDistanceFadeCloseStartScale);return 1-e*e*(3-2*e)*(1-this._objectDistanceFadeCloseMinOpacity)}shouldApplyDistanceFade(t){return!p.isInstanceOf(t,"KritzelSelectionGroup")&&!p.isInstanceOf(t,"KritzelSelectionBox")}getObjectEffectiveOpacity(t,e){const n=Number.isFinite(t.opacity)?t.opacity:1,i=this.shouldApplyDistanceFade(t)?this.getObjectDistanceFadeMultiplier(t.scale,e):1;return{multiplied:(t.markedForRemoval?.5:1)*n*i,overridden:((t.markedForRemoval?.5:n)*i).toString()}}getSelectionHandleCapabilities(t){const e=p.isInstanceOf(t,"KritzelSelectionGroup")?t.objects:[t];return{canRenderResizeHandles:e.every((t=>!1!==t.isResizable)),canRenderRotationHandle:e.every((t=>!1!==t.isRotatable))}}render(){if(!this.viewport)return i(r,null,this.core.store.state.isLoading&&i("div",{class:"workspace-loading-overlay"},i("span",{class:"workspace-loading-spinner"}),this.core.localizationManager.translate("engine.loading")));const t=this.core.themeManager.getStoredTheme(),e=window.getComputedStyle(this.host).getPropertyValue("--kritzel-selection-handle-size").trim()||"6px",n=parseFloat(e),s=2*n<14?14:n,o=this.core.store.state.scale,a=this.core.store.state.viewportWidth/2+this.core.store.state.translateX,c=this.core.store.state.viewportHeight/2+this.core.store.state.translateY,l=this.core.store.objectsInViewport,h=t=>this.core.store.state.isScaling||p.isInstanceOf(t,"KritzelSelectionGroup")?"none":"auto",u=t=>t.markedForRemoval||p.isInstanceOf(t,"KritzelSelectionGroup")&&1===t.objects.length&&p.isInstanceOf(t.objects[0],"KritzelCustomElement")?"none":"auto",f=new Set;return l.forEach((t=>{p.isInstanceOf(t,"KritzelCustomElement")&&f.add(t.id)})),this._previousVisibleCustomElements.forEach((t=>{if(!f.has(t)){const e=this.core.store.objects.findById(t);e&&p.isInstanceOf(e,"KritzelCustomElement")&&e.unmount()}})),this._previousVisibleCustomElements=f,this.core.cursorManager.applyCursor(),this.core.store.state.hasViewportChanged&&(this.viewportChange.emit(this.viewport.getViewport()),this.core.store.totalObjectCount>0&&this.emitObjectsInViewportChange()),i(r,null,this.core.store.state.isLoading&&i("div",{class:"workspace-loading-overlay"},i("span",{class:"workspace-loading-spinner"}),"Loading..."),this.core.store.state.debugInfo.showViewportInfo&&i("div",{class:"debug-panel"},i("div",null,"ActiveWorkspaceId: ",this.core.store.state?.activeWorkspace?.id),i("div",null,"ActiveWorkspaceName: ",this.core.store.state?.activeWorkspace?.name),i("div",null,"TranslateX: ",this.core.store.state?.translateX),i("div",null,"TranslateY: ",this.core.store.state?.translateY),i("div",null,"ViewportWidth: ",this.core.store.state?.viewportWidth),i("div",null,"ViewportHeight: ",this.core.store.state?.viewportHeight),i("div",null,"PointerCount: ",this.core.store.state.pointers.size),i("div",null,"Scale: ",this.core.store.state?.scale),i("div",null,"ActiveTool: ",this.core.store.state?.activeTool?.name),i("div",null,"HasViewportChanged: ",this.core.store.state?.hasViewportChanged?"true":"false"),i("div",null,"IsEnabled: ",this.core.store.state?.isEnabled?"true":"false"),i("div",null,"IsScaling: ",this.core.store.state?.isScaling?"true":"false"),i("div",null,"IsPanning: ",this.core.store.state?.isPanning?"true":"false"),i("div",null,"IsSelecting: ",this.isSelecting?"true":"false"),i("div",null,"IsSelectionActive: ",this.isSelectionActive?"true":"false"),i("div",null,"IsResizeHandleSelected: ",this.core.store.state.isResizeHandleSelected?"true":"false"),i("div",null,"IsRotationHandleSelected: ",this.core.store.state.isRotationHandleSelected?"true":"false"),i("div",null,"IsRotationHandleHovered: ",this.core.store.state.isRotationHandleHovered?"true":"false"),i("div",null,"IsDrawing: ",this.core.store.state.isDrawing?"true":"false"),i("div",null,"IsWriting: ",this.core.store.state.isWriting?"true":"false"),i("div",null,"IsPointerDown: ",this.core.store.isPointerDown?"true":"false"),i("div",null,"PointerX: ",this.core.store.state?.pointerX),i("div",null,"PointerY: ",this.core.store.state?.pointerY),i("div",null,"TotalObjects: ",this.core.store.totalObjectCount),i("div",null,"ObjectsInViewport: ",this.core.store.objectsInViewport.length),i("div",null,"SelectedObjects: ",this.core.store.selectionGroup?.objects.length||0),i("div",null,"ViewportCenter: (",a.toFixed(2),", ",c.toFixed(2),")")),i("div",{id:"origin",class:"origin",style:{transform:`matrix(${this.core.store.state?.scale}, 0, 0, ${this.core.store.state?.scale}, ${this.core.store.state?.translateX}, ${this.core.store.state?.translateY})`}},l?.map((e=>{const{multiplied:r,overridden:a}=this.getObjectEffectiveOpacity(e,o);return i("div",{key:e.id,id:e.id,class:"object",style:{transform:e?.transformationMatrix,transformOrigin:"top left",position:"absolute",zIndex:this.core.displaySelectionLineUI(e)?"10001":e.zIndex.toString(),pointerEvents:h(e)}},p.isInstanceOf(e,"KritzelPath")&&i("svg",{ref:t=>t&&e.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{height:e?.totalHeight+"px",width:e?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,pointerEvents:e.markedForRemoval?"none":"auto",overflow:"visible"},viewBox:e?.viewBox},i("path",{d:e?.d,fill:M.applyOpacity(e.fill,r,t),stroke:M.applyOpacity(e?.stroke,r,t),"shape-rendering":e.isLowRes()?"optimizeSpeed":"auto"})),p.isInstanceOf(e,"KritzelLine")&&i("svg",{ref:t=>t&&e.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{height:e?.totalHeight+"px",width:e?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,pointerEvents:e.markedForRemoval?"none":"auto",overflow:"visible"},viewBox:e?.viewBox},(e.hasStartArrow||e.hasEndArrow)&&i("defs",null,e.hasStartArrow&&i("marker",{id:e.startMarkerId,markerWidth:e.getArrowSize("start"),markerHeight:e.getArrowSize("start"),refX:0,refY:e.getArrowSize("start")/2,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse"},i("path",{d:e.getArrowPath(e.arrows?.start?.style),fill:M.applyOpacity(e.getArrowFill("start"),r),transform:`scale(${e.getArrowSize("start")/10})`})),e.hasEndArrow&&i("marker",{id:e.endMarkerId,markerWidth:e.getArrowSize("end"),markerHeight:e.getArrowSize("end"),refX:0,refY:e.getArrowSize("end")/2,orient:"auto",markerUnits:"userSpaceOnUse"},i("path",{d:e.getArrowPath(e.arrows?.end?.style),fill:M.applyOpacity(e.getArrowFill("end"),r),transform:`scale(${e.getArrowSize("end")/10})`}))),i("path",{d:this.core.anchorManager.computeClippedLinePath(e),fill:"none",stroke:"transparent","stroke-width":Math.max(e?.strokeWidth||0,10),"stroke-linecap":"round"}),i("path",{d:this.core.anchorManager.computeClippedLinePath(e),fill:"none",stroke:M.applyOpacity(e?.stroke,r,t),"stroke-width":e?.strokeWidth,"stroke-linecap":"round","marker-start":e.hasStartArrow?`url(#${e.startMarkerId})`:void 0,"marker-end":e.hasEndArrow?`url(#${e.endMarkerId})`:void 0})),p.isInstanceOf(e,"KritzelImage")&&"ready"===e.loadState&&i("img",{ref:t=>t&&e.mount(t),src:e.resolvedSrc||e.src,style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor(e.backgroundColor,t),borderColor:M.resolveThemeColor(e.borderColor,t),borderWidth:e.borderWidth+"px",borderStyle:"solid",padding:e.padding+"px",overflow:"visible",userSelect:"none",imageRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"pixelated":"auto"},draggable:!1,decoding:"async",loading:"eager",onDragStart:t=>t.preventDefault()}),p.isInstanceOf(e,"KritzelImage")&&"ready"!==e.loadState&&i("div",{ref:()=>e.ensureLoaded(),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor({light:"#e5e7eb",dark:"#2a2a2a"},t),borderColor:M.resolveThemeColor("error"===e.loadState?{light:"#9ca3af",dark:"#6b7280"}:e.borderColor,t),borderWidth:"error"===e.loadState?"1px":e.borderWidth+"px",borderStyle:"solid",padding:e.padding+"px",overflow:"hidden",userSelect:"none",display:"flex",alignItems:"center",justifyContent:"center"}},i("kritzel-icon",{name:"error"===e.loadState?"image-off":"image",size:Math.max(16,.3*Math.min(e.totalWidth,e.totalHeight)),style:{color:M.resolveThemeColor({light:"#9ca3af",dark:"#6b7280"},t)}})),p.isInstanceOf(e,"KritzelCustomElement")&&i("div",{ref:t=>t&&e.mount(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor(e.backgroundColor,t),borderColor:M.resolveThemeColor(e.borderColor,t),borderWidth:e.borderWidth+"px",borderStyle:"solid",padding:e.padding+"px",overflow:"hidden",display:"block"}}),p.isInstanceOf(e,"KritzelSelectionGroup")&&!this.core.displaySelectionLineUI(e)&&i("div",{ref:t=>t&&e.mount(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:e.markedForRemoval?"0.5":e.opacity.toString(),pointerEvents:u(e)}}),p.isInstanceOf(e,"KritzelSelectionBox")&&i("div",{ref:t=>t&&e.mount(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:e.markedForRemoval?"0.5":e.opacity.toString(),pointerEvents:e.markedForRemoval?"none":"auto",backgroundColor:M.resolveThemeColor(e.backgroundColor,t),borderColor:M.resolveThemeColor(e.borderColor,t),borderWidth:e.borderWidth+"px",borderStyle:"solid"}}),p.isInstanceOf(e,"KritzelText")&&i("div",{style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,opacity:a,pointerEvents:e.markedForRemoval?"none":"auto"}},i("div",{id:"text-object",ref:t=>t&&e.mount(t),onPointerDown:t=>e.handlePointerDown(t),onPointerMove:t=>e.handlePointerMove(t),onPointerUp:t=>e.handlePointerUp(t),style:{minWidth:e.initialWidth+"px",minHeight:e.initialHeight+"px",maxWidth:"500px",height:"auto",width:"max-content",transformOrigin:"top left",transform:`scale(${e.scaleFactor})`,backgroundColor:M.resolveThemeColor(e.backgroundColor,t),overflow:"visible"}})),p.isInstanceOf(e,"KritzelShape")&&(()=>{const n=M.resolveThemeColor(e.fillColor,t),s=M.resolveThemeColor(e.strokeColor,t),o=!!n&&"transparent"!==n&&s===n;return i("div",{ref:t=>t&&e.mount(t),onPointerDown:t=>e.handlePointerDown(t),onPointerMove:t=>e.handlePointerMove(t),onPointerUp:t=>e.handlePointerUp(t),style:{position:"absolute",left:"0",top:"0",width:e.totalWidth+"px",height:e.totalHeight+"px",transform:0!==e.rotationDegrees?`rotate(${e.rotationDegrees}deg)`:void 0,transformOrigin:0!==e.rotationDegrees?`${e.totalWidth/2}px ${e.totalHeight/2}px`:void 0,pointerEvents:e.markedForRemoval?"none":"auto",overflow:"visible"}},i("svg",{xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:e.viewBox,preserveAspectRatio:"none"},i("path",{d:e.getSvgPath(),fill:M.applyOpacity(e.fillColor,r,t),stroke:o?"none":M.applyOpacity(e.strokeColor,r,t),"stroke-width":o?0:e.strokeWidth})),i("div",{ref:t=>t&&e.mountTextEditor(t),style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",overflow:"hidden",pointerEvents:e.isEditing?"auto":"none"}}))})(),this.core.store.state.debugInfo.showObjectInfo&&i("div",{style:{pointerEvents:"none",position:"absolute",left:`${e.totalWidth}px`,top:"0",zIndex:(e.zIndex+2).toString()}},i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"Id: ",e.id),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"userId: ",e.userId),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"width: ",e.width),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"height: ",e.height),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateX: ",e.translateX),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateY: ",e.translateY),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"scale: ",e.scale),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"rotationDegrees: ",e.rotationDegrees),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"zIndex: ",e.zIndex),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"isSelected: ",e.isSelected?"true":"false"),p.isInstanceOf(e,"KritzelCustomElement")&&i("div",null,i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"isInteractive: ",e.isInteractive?"true":"false")),p.isInstanceOf(e,"KritzelImage")&&i("div",null,i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"assetId: ",e.assetId),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"mimeType: ",e.mimeType))),(this.core.displaySelectionGroupUI(e)||this.core.displaySelectionLineUI(e))&&(()=>{const r=p.isInstanceOf(e,"KritzelSelectionGroup"),o=this.core.store.objects?.localClientId,a=this.core.store.objects?.awareness?.getStates(),c=r&&(null!=e.userId&&null!=this.core.user?.id&&e.userId!==this.core.user.id||null!=e.userId&&null!=this.core.user?.id&&e.userId===this.core.user.id&&null!=e.clientId&&null!=o&&e.clientId!==o&&!0===a?.has(e.clientId));let l;if(c&&a&&(r&&null!=e.clientId&&(l=a.get(e.clientId)?.user?.color),!l))for(const t of a.values())if(t.user?.id===e.userId){l=t.user.color;break}const h=l??(M.resolveThemeColor(e.borderColor,t)||"var(--kritzel-selection-border-color, #007AFF)"),u=l??"var(--kritzel-selection-handle-stroke-color, #007AFF)",f=null!=e.endAnchor,d=this.core.store.state.snapCandidate??this.core.store.state.snapPreviewCandidate,g=null!=e.startAnchor||"start"===d?.endpoint,v=f||"end"===d?.endpoint,w=this.core.displaySelectionLineUI(e)?"10000":(e.zIndex+1).toString(),m=e.scale??1,{canRenderResizeHandles:y,canRenderRotationHandle:b}=this.getSelectionHandleCapabilities(e);return i("svg",{xmlns:"http://www.w3.org/2000/svg",style:{zIndex:w,height:e?.totalHeight.toString(),width:e?.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${e.rotationDegrees}deg)`,transformOrigin:`${e.totalWidth/2}px ${e.totalHeight/2}px`,overflow:"visible",pointerEvents:"none"}},this.core.displaySelectionGroupUI(e)&&i("g",{class:"selection-group-ui",style:{pointerEvents:"none"}},(()=>{const t=c&&p.isInstanceOf(e,"KritzelSelectionGroup")&&1===e.objects.length&&p.isInstanceOf(e.objects[0],"KritzelLine")?e.objects[0]:null;return t?i("g",{class:"selection-line-borders"},i("path",{class:"selection-line-border",d:this.core.anchorManager.computeClippedLinePath(t,!0),style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"round",fill:"none"}})):i("g",{class:"selection-group-borders"},i("line",{x1:"0",y1:"0",x2:e.totalWidth,y2:"0",style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:"0",y1:"0",x2:"0",y2:e.totalHeight,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:"0",y1:e.totalHeight,x2:e.totalWidth,y2:e.totalHeight,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:e.totalWidth,y1:"0",x2:e.totalWidth,y2:e.totalHeight,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}))})(),!this.isSelecting&&!c&&i("g",{class:"selection-group-handles",style:{pointerEvents:"auto"}},y&&i("g",null,i("rect",{class:"resize-handle top-left",x:""+-(n-1)*m/this.core.store.state?.scale,y:""+-(n-1)*m/this.core.store.state?.scale,width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay top-left",x:""+-s*m/this.core.store.state?.scale,y:""+-s*m/this.core.store.state?.scale,width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("rect",{class:"resize-handle top-right",x:""+(e.totalWidth-(n-1)*m/this.core.store.state?.scale),y:""+-(n-1)*m/this.core.store.state?.scale,width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay top-right",x:""+(e.totalWidth-s*m/this.core.store.state?.scale),y:""+-s*m/this.core.store.state?.scale,width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("rect",{class:"resize-handle bottom-left",x:""+-(n-1)*m/this.core.store.state?.scale,y:""+(e.totalHeight-(n-1)*m/this.core.store.state?.scale),width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay bottom-left",x:""+-s*m/this.core.store.state?.scale,y:""+(e.totalHeight-s*m/this.core.store.state?.scale),width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("rect",{class:"resize-handle bottom-right",x:""+(e.totalWidth-(n-1)*m/this.core.store.state?.scale),y:""+(e.totalHeight-(n-1)*m/this.core.store.state?.scale),width:""+2*(n-1)*m/this.core.store.state?.scale,height:""+2*(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("rect",{class:"resize-handle-overlay bottom-right",x:""+(e.totalWidth-s*m/this.core.store.state?.scale),y:""+(e.totalHeight-s*m/this.core.store.state?.scale),width:""+2*s*m/this.core.store.state?.scale,height:""+2*s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}})),b&&i("g",null,i("line",{x1:e.totalWidth/2,y1:"0",x2:e.totalWidth/2,y2:-15*m/this.core.store.state?.scale,style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${m} / ${this.core.store.state?.scale})`}}),i("circle",{class:"rotation-handle",cx:e.totalWidth/2,cy:-15*m/this.core.store.state?.scale,r:""+(n-1)*m/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:u,strokeWidth:`calc(2px * ${m} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"rotation-handle-overlay",cx:e.totalWidth/2,cy:-15*m/this.core.store.state?.scale,r:""+s*m/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}})))),this.core.displaySelectionLineUI(e)&&p.isInstanceOf(e,"KritzelLine")&&i("g",{class:"selection-line-ui",style:{pointerEvents:"none"}},i("g",{class:"selection-line-borders"},i("path",{class:"selection-line-border",d:this.core.anchorManager.computeClippedLinePath(e,!0),style:{stroke:h,strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${e.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"round",fill:"none"}})),!this.isSelecting&&!c&&i("g",{class:"selection-line-handles",style:{pointerEvents:"auto"}},i("circle",{class:"selection-line-handle start",cx:e.startX-e.x,cy:e.startY-e.y,r:""+(n-1)*e.scale/this.core.store.state?.scale,style:{fill:g?u:"var(--kritzel-selection-handle-color, #000000)",stroke:u,strokeWidth:`calc(2px * ${e.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay start","data-testid":"line-handle-start",cx:e.startX-e.x,cy:e.startY-e.y,r:""+s*e.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle center",cx:void 0!==e.controlX?(e.startX+2*e.controlX+e.endX)/4-e.x:(e.startX-e.x+e.endX-e.x)/2,cy:void 0!==e.controlY?(e.startY+2*e.controlY+e.endY)/4-e.y:(e.startY-e.y+e.endY-e.y)/2,r:""+(n-1)*e.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:u,strokeWidth:`calc(2px * ${e.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay center","data-testid":"line-handle-center",cx:void 0!==e.controlX?(e.startX+2*e.controlX+e.endX)/4-e.x:(e.startX-e.x+e.endX-e.x)/2,cy:void 0!==e.controlY?(e.startY+2*e.controlY+e.endY)/4-e.y:(e.startY-e.y+e.endY-e.y)/2,r:""+s*e.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle end",cx:e.endX-e.x,cy:e.endY-e.y,r:""+(n-1)*e.scale/this.core.store.state?.scale,style:{fill:v?u:"var(--kritzel-selection-handle-color, #000000)",stroke:u,strokeWidth:`calc(2px * ${e.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay end","data-testid":"line-handle-end",cx:e.endX-e.x,cy:e.endY-e.y,r:""+s*e.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))))})())})),(()=>{const t=this.core.anchorManager.getSnapIndicatorRenderData()??this.core.anchorManager.getSnapPreviewRenderData();if(!t)return null;const e=null!=this.core.anchorManager.getSnapIndicatorRenderData();return i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"snap-indicator",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9999",overflow:"visible"}},i("g",null,t.snapLinePath?i("path",{d:t.snapLinePath,fill:"none",style:{stroke:e?"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))":"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.12))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}):void 0!==t.edgeX&&void 0!==t.edgeY&&i("line",{x1:t.edgeX,y1:t.edgeY,x2:t.centerX,y2:t.centerY,style:{stroke:e?"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))":"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.12))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.centerX,cy:t.centerY,r:t.indicatorRadius,style:{fill:e?"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))":"rgba(59, 130, 246, 0.18)",stroke:e?"var(--kritzel-snap-indicator-stroke, #007bff)":"rgba(59, 130, 246, 0.5)",strokeWidth:t.indicatorStrokeWidth}})))})(),(()=>{const t=this.core.anchorManager.getAnchorLinesRenderData();return t?i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"anchor-lines",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9998",overflow:"visible"}},t.startAnchorViz&&i("g",{class:"anchor-line-start"},t.startAnchorViz.pathD?i("path",{d:t.startAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):i("line",{x1:t.startAnchorViz.edgeX,y1:t.startAnchorViz.edgeY,x2:t.startAnchorViz.centerX,y2:t.startAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.startAnchorViz.centerX,cy:t.startAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}})),t.endAnchorViz&&i("g",{class:"anchor-line-end"},t.endAnchorViz.pathD?i("path",{d:t.endAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):i("line",{x1:t.endAnchorViz.edgeX,y1:t.endAnchorViz.edgeY,x2:t.endAnchorViz.centerX,y2:t.endAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.endAnchorViz.centerX,cy:t.endAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})()),this.core.store.state.isContextMenuVisible&&i("kritzel-context-menu",{class:"context-menu",ref:t=>this.contextMenuElement=t??null,items:this.core.store.state.contextMenuItems,objects:this.core.store.selectionGroup?.objects||[],style:{position:"absolute",left:`${this.core.store.state.contextMenuX}px`,top:`${this.core.store.state.contextMenuY}px`,zIndex:"10002"},onActionSelected:t=>{t.detail.action&&t.detail.action({x:this.core.store.state.contextMenuWorldX,y:this.core.store.state.contextMenuWorldY},this.core.store.selectionGroup?.objects||[]),this.hideContextMenu()},onClose:()=>this.hideContextMenu()}),this.core.store.objects?.hasAwareness&&i("kritzel-awareness-cursors",{core:this.core}),this.core.store.state?.activeTool instanceof tt&&!this.core.store.state.isScaling&&i("kritzel-cursor-trail",{core:this.core}),!this.core.licenseManager.isLicensed&&i("kritzel-watermark",{core:this.core,label:this.core.localizationManager.translate("watermark.poweredBy")}))}static get watchers(){return{workspace:[{onWorkspaceChange:0}],activeWorkspaceId:[{onActiveWorkspaceIdChange:0}],syncConfig:[{onSyncConfigChange:0}],assetStorageConfig:[{onAssetStorageConfigChange:0}],user:[{onUserChange:0}],globalContextMenuItems:[{onGlobalContextMenuItemsChange:0}],objectContextMenuItems:[{onObjectContextMenuItemsChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}],lockDrawingScale:[{onLockDrawingScaleChange:0}],isObjectDistanceFadingActive:[{onIsObjectDistanceFadingActiveChange:0}],theme:[{onThemeChange:0}],licenseKey:[{onLicenseKeyChange:0}],themes:[{onThemesChange:0}],locale:[{onLocaleChange:0}],locales:[{onLocalesChange:0}],fallbackLocale:[{onFallbackLocaleChange:0}],viewportBoundaryLeft:[{onViewportBoundaryLeftChange:0}],viewportBoundaryRight:[{onViewportBoundaryRightChange:0}],viewportBoundaryTop:[{onViewportBoundaryTopChange:0}],viewportBoundaryBottom:[{onViewportBoundaryBottomChange:0}],debugInfo:[{onDebugInfoChange:0}],isLoading:[{onIsLoadingChange:0}]}}static get style(){return":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.ProseMirror{outline:none}p,h1,h2,h3,h4,h5,h6,blockquote,pre{margin:0;padding:0}.workspace-loading-overlay{position:absolute;inset:0;z-index:9999;display:flex;align-items:center;justify-content:center;gap:10px;background-color:var(--kritzel-engine-loading-overlay-background, rgba(255, 255, 255, 0.6));color:var(--kritzel-engine-loading-overlay-color, #333);font-family:var(--kritzel-font-family, sans-serif);font-size:1.25rem;pointer-events:all;animation:workspace-loading-fade-in 200ms ease-out var(--kritzel-engine-loading-overlay-delay, 300ms) forwards;opacity:0}.workspace-loading-spinner{width:20px;height:20px;box-sizing:border-box;display:block;flex-shrink:0;border:2px solid var(--kritzel-engine-loading-overlay-spinner-color, #cccccc);border-top-color:var(--kritzel-engine-loading-overlay-spinner-active-color, #333333);border-radius:50%;animation:workspace-loading-spin 0.6s linear infinite}@keyframes workspace-loading-spin{to{transform:rotate(360deg)}}@keyframes workspace-loading-fade-in{to{opacity:1}}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}.PlaygroundEditorTheme__quote{margin:0;margin-left:20px;margin-bottom:10px;font-size:15px;color:rgb(101, 103, 107);border-left-color:rgb(206, 208, 212);border-left-width:4px;border-left-style:solid;padding-left:16px}"}},[513,"kritzel-engine",{workspace:[16],editorId:[1,"editor-id"],activeWorkspaceId:[1,"active-workspace-id"],syncConfig:[16],assetStorageConfig:[16],user:[16],globalContextMenuItems:[16],objectContextMenuItems:[16],scaleMax:[1026,"scale-max"],scaleMin:[1026,"scale-min"],cursorTarget:[16],lockDrawingScale:[4,"lock-drawing-scale"],isObjectDistanceFadingActive:[4,"is-object-distance-fading-active"],theme:[1],licenseKey:[1,"license-key"],themes:[16],locale:[1],locales:[16],fallbackLocale:[1,"fallback-locale"],viewportBoundaryLeft:[2,"viewport-boundary-left"],viewportBoundaryRight:[2,"viewport-boundary-right"],viewportBoundaryTop:[2,"viewport-boundary-top"],viewportBoundaryBottom:[2,"viewport-boundary-bottom"],debugInfo:[16],isPanningEnabled:[4,"is-panning-enabled"],isZoomingEnabled:[4,"is-zooming-enabled"],isLoading:[4,"is-loading"],forceUpdate:[32],triggerSelectionChange:[64],registerTool:[64],changeActiveTool:[64],changeActiveToolByName:[64],disable:[64],enable:[64],delete:[64],copy:[64],cut:[64],paste:[64],bringForward:[64],sendBackward:[64],bringToFront:[64],sendToBack:[64],alignObjects:[64],group:[64],ungroup:[64],undo:[64],redo:[64],hideContextMenu:[64],openContextMenu:[64],getObjectById:[64],getAllObjects:[64],findObjects:[64],getObjectsTotalCount:[64],addObject:[64],addObjects:[64],updateObject:[64],removeObject:[64],removeObjects:[64],getSelectedObjects:[64],getDisplayableShortcuts:[64],selectObjects:[64],selectAllObjectsInViewport:[64],clearSelection:[64],centerObjectInViewport:[64],panToObject:[64],backToContent:[64],centerAllObjects:[64],centerObjects:[64],setViewport:[64],panTo:[64],zoomTo:[64],zoomIn:[64],zoomOut:[64],getViewport:[64],screenToWorld:[64],worldToScreen:[64],getObjectsInViewport:[64],getScreenshot:[64],exportViewportAsPng:[64],exportViewportAsSvg:[64],getSelectedObjectsAsSvgString:[64],exportSelectedObjectsAsSvg:[64],getSelectedObjectsAsPngDataUrl:[64],exportSelectedObjectsAsPng:[64],exportAsJson:[64],importFromJson:[64],loadObjectsFromJson:[64],downloadAsJson:[64],importFromFile:[64],createWorkspace:[64],updateWorkspace:[64],deleteWorkspace:[64],getWorkspaces:[64],getActiveWorkspace:[64],getIsPublic:[64],loadSharedWorkspace:[64],reinitSync:[64],saveSettings:[64],loadSettings:[64],registerLocales:[64],setLocale:[64],getLocale:[64],getAvailableLocales:[64],getAvailableLocaleOptions:[64],t:[64],getResolvedTerms:[64]},[[1,"wheel","handleWheel"],[0,"pointerdown","handlePointerDown"],[0,"pointermove","handlePointerMove"],[0,"pointerup","handlePointerUp"],[0,"pointercancel","handlePointerCancel"],[1,"pointerleave","handlePointerLeave"],[1,"longpress","handleLongPress"],[0,"contextmenu","handleContextMenu"],[9,"resize","handleResize"],[8,"keydown","handleKeyDown"],[8,"keyup","handleKeyUp"],[8,"copy","handleCopy"],[8,"cut","handleCut"],[8,"paste","handlePaste"],[4,"dblclick","preventDoubleTapZoomOnTouchDevices"]],{workspace:[{onWorkspaceChange:0}],activeWorkspaceId:[{onActiveWorkspaceIdChange:0}],syncConfig:[{onSyncConfigChange:0}],assetStorageConfig:[{onAssetStorageConfigChange:0}],user:[{onUserChange:0}],globalContextMenuItems:[{onGlobalContextMenuItemsChange:0}],objectContextMenuItems:[{onObjectContextMenuItemsChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}],lockDrawingScale:[{onLockDrawingScaleChange:0}],isObjectDistanceFadingActive:[{onIsObjectDistanceFadingActiveChange:0}],theme:[{onThemeChange:0}],licenseKey:[{onLicenseKeyChange:0}],themes:[{onThemesChange:0}],locale:[{onLocaleChange:0}],locales:[{onLocalesChange:0}],fallbackLocale:[{onFallbackLocaleChange:0}],viewportBoundaryLeft:[{onViewportBoundaryLeftChange:0}],viewportBoundaryRight:[{onViewportBoundaryRightChange:0}],viewportBoundaryTop:[{onViewportBoundaryTopChange:0}],viewportBoundaryBottom:[{onViewportBoundaryBottomChange:0}],debugInfo:[{onDebugInfoChange:0}],isLoading:[{onIsLoadingChange:0}]}]);function nn(){"undefined"!=typeof customElements&&["kritzel-engine","kritzel-awareness-cursors","kritzel-context-menu","kritzel-cursor-trail","kritzel-icon","kritzel-watermark"].forEach((t=>{switch(t){case"kritzel-engine":customElements.get(s(t))||customElements.define(s(t),en);break;case"kritzel-awareness-cursors":customElements.get(s(t))||G();break;case"kritzel-context-menu":customElements.get(s(t))||D();break;case"kritzel-cursor-trail":customElements.get(s(t))||H();break;case"kritzel-icon":customElements.get(s(t))||V();break;case"kritzel-watermark":customElements.get(s(t))||C()}}))}export{Xt as A,Wt as D,Rt as E,Ut as F,Z as K,Yt as W,q as a,J as b,tt as c,Lt as d,Ot as e,Pt as f,Bt as g,Vt as h,Nt as i,Q as j,Gt as k,Qt as l,nn as m,en as n,Ht as r}
|