PageSourceSearch

https://service-ski-snowboard-n8d795p.gamma.site/_next/static/chunks/ab16df01.6591518370ed49e8.js

js service-ski-snowboard-n8d795p.gamma.site collected 2026-10-03 04:08:23 UTC 86,391 bytes, 2 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2533],{16610:function(e,t,i){i.d(t,{M:function(){return N}});var s=i(42869),r=i(189),n=i(85947),a=i(10161),h=i(41276),o=i(80492),p=i(38021),d=i(84527),l=i(46921),g=i(80489),u=i(80695),c=i(24196),S=i(96284),f=i(20930),m=i(85592),y=i(8662),I=i(66745),P=i(92226),C=i(65693),w=i(99590),x=i(73565),_=i(23338),b=i(13638),v=i(42731),T=i(97540),A=i(90663),B=i(10795),F=i(86906),k=i(37572),E=i(79461),M=i(85289),O=i(65650),R=i(7367),z=i(97279),K=i(35407),V=i(15937),U=i(37669),L=Object.defineProperty,G=Object.getOwnPropertyDescriptor,D=(e,t,i,s)=>{for(var r,n=s>1?void 0:s?G(t,i):t,a=e.length-1;a>=0;a--)(r=e[a])&&(n=(s?r(t,i,n):r(n))||n);return s&&n&&L(t,i,n),n};class N extends a.EventEmitter{constructor({store:e,user:t,shapeUtils:i,tools:s,getContainer:a,initialState:p,inferDarkMode:d}){super(),this.store=e,this.snaps=new E.f(this),this.user=new R.K(t??(0,h.L)(),d??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new M.R(this);class l extends U.m{static initial=p??""}this.root=new l(this),this.root.children={};let g=(0,o.m)(i),u=new Set(Object.keys(e.schema.types.shape.migrations.subTypeMigrations));for(let e of g){if(!u.has(e.type))throw Error(`Editor and store have different shapes: "${e.type}" was passed into the editor but not the schema`);u.delete(e.type)}if(u.size>0)throw Error(`Editor and store have different shapes: "${[...u][0]}" is present in the store schema but not provided to the editor`);let c={},S={},f=new Map;for(let e of g){let t=new e(this);c[e.type]=t;let i=(0,r.DR)(e.props??{});for(let t of(S[e.type]=i,i.keys()))if(f.has(t.id)){if(f.get(t.id)!==t)throw Error(`Multiple style props with id "${t.id}" in use. Style prop IDs must be unique.`)}
1else f.set(t.id,t)}for(let e of(this.shapeUtils=c,this.styleProps=S,[...s])){if((0,n.nr)(this.root.children,e.id))throw Error(`Can't override tool with id "${e.id}"`);this.root.children[e.id]=new e(this,this.root)}this.environment=new A.l(this),this.scribbles=new F.o(this);let m=new Set,y=e=>{let t,i,s;let r=this.getShape(e);if(!r)return;let{start:a,end:h}=r.props,o="binding"===a.type?this.getShape(a.boundShapeId):void 0,p="binding"===h.type?this.getShape(h.boundShapeId):void 0,d=this.getAncestorPageId(r);if(!d)return;if(o&&p)t=this.findCommonAncestor([o,p])??d;else{if(!o&&!p)return;let e=(o||p)?.parentId;t=e&&e===r.parentId?r.parentId:d}t&&t!==r.parentId&&this.reparentShapes([e],t);let l=this.getShape(e);if(!l)throw Error("no reparented arrow");let g=this.getShapeNearestSibling(l,o),u=this.getShapeNearestSibling(l,p);if(g&&u)i=g.index>u.index?g:u;else if(g&&!u)i=g;else{if(!u||g)return;i=u}let c=this.getSortedChildIdsForParent(i.parentId).map(e=>this.getShape(e)).filter(e=>e.index>i.index);if(c.length){let e=c.find(e=>"arrow"!==e.type);if(l.index>i.index&&(!e||l.index<e.index))return;s=(0,n.eI)(i.index,c[0].index)}else s=(0,n._L)(i.index);s!==l.index&&this.updateShapes([{id:e,type:"arrow",index:s}])},I=(e,t)=>{let{x:i,y:s}=(0,K.Qs)(this,e)[t];this.store.put([{...e,props:{...e.props,[t]:{type:"point",x:i,y:s}}}])},P=e=>{for(let t of["start","end"]){let i=e.props[t];if("binding"!==i.type)continue;let s=this.getShape(i.boundShapeId),r=this.getAncestorPageId(e)===this.getAncestorPageId(s);s&&r||I(e,t)}y(e.id)},C=(e,t)=>{let i=null,s=e.selectedShapeIds.filter(e=>!t.has(e));s.length!==e.selectedShapeIds.length&&(i||(i={...e}),i.selectedShapeIds=s);let r=e.erasingShapeIds.filter(e=>!t.has(e));r.length!==e.erasingShapeIds.length&&(i||(i={...e}),i.erasingShapeIds=r),e.hoveredShapeId&&t.has(e.hoveredShapeId)&&(i||(i={...e}),i.hoveredShapeId=null),e.editingShapeId&&t.has(e.editingShapeId)&&(i||(i={...e}),i.editingShapeId=null);let n=e.hintingShapeIds.filter(e=>!t.has(e));return n.length!==e.hintingShapeIds.length&&(i||(i={...e}),i.hintingShapeIds=n),e.focusedGroupId&&t.has(e.focusedGroupId)&&(i||(i={...e}),i.focusedGroupId=null),i};if(this.sideEffects=new k.Y(this),this.sideEffects.registerBatchCompleteHandler(()=>{for(let e of m){m.delete(e);let t=this.getShape(e);if(!t)continue;let i=this.getShapeUtil(t),s=i.onChildrenChange?.(t);s?.length&&this.updateShapes(s,{squashing:!0})}this.emit("update")}),this.sideEffects.registerBeforeDeleteHandler("shape",e=>{e.parentId&&(0,r.YT)(e.parentId)&&m.add(e.parentId);let t=this._getArrowBindingsIndex().get()[e.id];if(t?.length)for(let{arrowId:e,handleId:i}of t){let t=this.getShape(e);t&&I(t,i)}let i=new Set([e.id]),s=(0,n.oA)(this.getPageStates().map(e=>C(e,i)));s.length&&this.store.put(s)}),this.sideEffects.registerBeforeDeleteHandler("page",e=>{if(this.getInstanceState().currentPageId!==e.id)return;let t=this.getPages().find(t=>t.id!==e.id)?.id;if(!t)return;this.store.put([{...this.getInstanceState(),currentPageId:t}]);let i=r.AN.createId(e.id),s=r.iS.createId(e.id);this.store.remove([i,s])}),this.sideEffects.registerAfterChangeHandler("shape",(e,t)=>{if(this.isShapeOfType(t,"arrow")&&P(t),e.parentId!==t.parentId){let e=e=>{let t=this._getArrowBindingsIndex().get()[e];if(t?.length)for(let e of t)y(e.arrowId)};e(t.id),this.visitDescendants(t.id,e)}if(e.parentId!==t.parentId&&(0,r.r5)(t.parentId)){let i=new Set([e.id]);for(let s of(this.visitDescendants(e.id,e=>{i.add(e)}),this.getPageStates())){if(s.pageId===t.parentId)continue;let e=C(s,i);e&&this.store.put([e])}}e.parentId&&(0,r.YT)(e.parentId)&&m.add(e.parentId),t.parentId!==e.parentId&&(0,r.YT)(t.parentId)&&m.add(t.parentId)}),this.sideEffects.registerAfterChangeHandler("instance_page_state",(e,t)=>{if(e?.selectedShapeIds!==t?.selectedShapeIds){let e=t.selectedShapeIds.filter(e=>{let i=this.getShape(e)?.parentId;for(;(0,r.YT)(i);){if(t.selectedShapeIds.includes(i))return!1;i=this.getShape(i)?.parentId}return!0}),i=null;if(e.length>0){let t=this.findCommonAncestor((0,n.oA)(e.map(e=>this.getShape(e))),e=>this.isShapeOfType(e,"group"));t&&(i=t)}else t?.focusedGroupId&&(i=t.focusedGroupId);(e.length!==t.selectedShapeIds.length||i!==t.focusedGroupId)&&this.store.put([{...t,selectedShapeIds:e,focu
1sedGroupId:i??null}])}}),this.sideEffects.registerAfterCreateHandler("shape",e=>{this.isShapeOfType(e,"arrow")&&P(e)}),this.sideEffects.registerAfterCreateHandler("page",e=>{let t=r.AN.createId(e.id),i=r.iS.createId(e.id);this.store.has(t)||this.store.put([r.AN.create({id:t})]),this.store.has(i)||this.store.put([r.iS.create({id:i,pageId:e.id})])}),this._currentPageShapeIds=(0,v.Q)(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=(0,b.s)(this.store),this.disposables.add(this.store.listen(e=>{this.emit("change",e)})),this.store.ensureStoreIsUsable(),this._setInstancePageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]},{ephemeral:!0}),p&&void 0===this.root.children[p])throw Error(`No state found for initialState "${p}".`);this.root.enter(void 0,"initial"),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.updateRenderingBounds(),requestAnimationFrame(()=>{this._tickManager.start()})}store;root;disposables=new Set;_tickManager=new O.r(this);snaps;user;textMeasure;environment;scribbles;getContainer;sideEffects;
1dispose(){this.disposables.forEach(e=>e()),this.disposables.clear()}shapeUtils;styleProps;getShapeUtil(e){let t="string"==typeof e?e:e.type,i=(0,n.eg)(this.shapeUtils,t);return(0,n.hu)(i,`No shape util found for type "${t}"`),i}history=new B.E(this,e=>{this.annotateError(e,{origin:"history.batch",willCrashApp:!0}),this.crash(e)});undo(){return this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(e,t,i){return this.history.mark(e,t,i),this}bail(){return this.history.bail(),this}bailToMark(e){return this.history.bailToMark(e),this}batch(e){return this.history.batch(e),this}_getArrowBindingsIndex(){return(0,_.w)(this)}getArrowsBoundTo(e){return this._getArrowBindingsIndex().get()[e]||s.LZ}getArrowInfoCache(){return this.store.createComputedCache("arrow infoCache",e=>(0,K.el)(e)?(0,V.r)(this,e):(0,z.p)(this,e))}getArrowInfo(e){let t="string"==typeof e?e:e.id;return this.getArrowInfoCache().get(t)}annotateError(e,{origin:t,willCrashApp:i,tags:s,extras:r}){let a=this.createErrorAnnotations(t,i);return(0,n.lw)(e,{tags:{...a.tags,...s},extras:{...a.extras,...r}}),i&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(e,t){try{let i=this.getEditingShapeId();return{tags:{origin:e,willCrashApp:t},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes(),editingShape:i?this.getShape(i):void 0,inputs:this.inputs}}}catch{return{tags:{origin:e,willCrashApp:t},extras:{}}}}_crashingError=null;getCrashingError(){return this._crashingError}crash(e){return this._crashingError=e,this.store.markAsPossiblyCorrupted(),this.emit("crash",{error:e}),this}getPath(){return this.root.getPath().split("root.")[1]}isIn(e){let t=e.split(".").reverse(),i=this.root;for(;t.length>0;){let e=t.pop();if(!e)return!0;let s=i.getCurrent();if(s?.id===e){if(0===t.length)return!0;i=s;continue}break}return!1}isInAny(...e){return e.some(e=>this.isIn(e))}setCurrentTool(e,t={}){return this.root.transition(e,t),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){let e=this.getCurrentTool();return e?e.getCurrentToolIdMask()??e.id:""}getStateDescendant(e){let t=e.split(".").reverse(),i=this.root;for(;t.length>0;){let e=t.pop();if(!e)break;let s=i.children?.[e];if(!s)return;i=s}return i}getDocumentSettings(){return this.store.get(r.G4)}updateDocumentSettings(e){return this.store.put([{...this.getDocumentSettings(),...e}]),this}getInstanceState(){return this.store.get(r.PQ)}updateInstanceState(e,t){return this._updateInstanceState(e,{ephemeral:!0,squashing:!0,...t}),void 0!==e.isChangingStyle&&(clearTimeout(this._isChangingStyleTimeout),!0===e.isChangingStyle&&(this._isChangingStyleTimeout=setTimeout(()=>{this.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},2e3))),this}_updateInstanceState=this.history.createCommand("updateInstanceState",(e,t)=>{let i=this.store.get(this.getInstanceState().id),s={...i,...e};return{data:{prev:i,next:s},ephemeral:!1,squashing:!1,...t}},{do:({next:e})=>{this.store.put([e])},undo:({prev:e})=>{this.store.put([e])},squash:({prev:e},{next:t})=>({prev:e,next:t})});_isChangingStyleTimeout=-1;getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(e){let t=new Set(this.getOpenMenus());return t.has(e)||(t.add(e),this.updateInstanceState({openMenus:[...t]})),this}deleteOpenMenu(e){let t=new Set(this.getOpenMenus());return t.has(e)&&(t.delete(e),this.updateInstanceState({openMenus:[...t]})),this}clearOpenMenus(){return this.getOpenMenus().length&&this.updateInstanceState({openMenus:[]}),this}getIsMenuOpen(){return this.getOpenMenus().length>0}setCursor=e=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...e}},{ephemeral:!0}),this);getPageStates(){return this._getPageStatesQuery().get()}_getPageStatesQuery(){return this.store.query.records("instance_page_state")}getCurrentPageState(){return this.store.get(this._getCurrentPageStateId())}_getCurrentPageStateId(){return r.iS.createId(this.getCurrentPageId())}updateCurrentPageState(e,t){return this._setInstancePageState(e,t),this}_setInstancePageState=this.history.createCommand("setInstancePageState",(e,t)=>({data:{prev:this.store.get(e.id??this.getCurrentPageState().id),partial:e},...t}),{do:({prev:e,partial:t})=>{this.store.update(e.id,e=>({...e,...t}))},undo:({prev:e})=>{this.store.update(e.id,()=>e)}});getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){let{selectedShapeIds:e}=this.getCurrentPageState();return(0,n.oA)(e.map(e=>this.store.get(e)))}setSelectedShapes(e,t){let i=e.map(e=>"string"==typeof e?e:e.id);return this._setSelectedShapes(i,t),this}_setSelectedShapes=this.history.createCommand("setSelectedShapes",(e,t)=>{let{selectedShapeIds:i}=this.getCurrentPageState(),s=new Set(i);return e.length===s.size&&e.every(e=>s.has(e))?null:{data:{selectedShapeIds:e,prevSelectedShapeIds:i},preservesRedoStack:!0,...t}},{do:({selectedShapeIds:e})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:e}])},undo:({prevSelectedShapeIds:e})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:e}])},squash:({prevSelectedShapeIds:e},{selectedShapeIds:t})=>({selectedShapeIds:t,prevSelectedShapeIds:e})});isAncestorSelected(e){let t="string"==typeof e?e:e?.id??null,i=this.getShape(t);if(!i)return!1;let s=this.getSelectedShapeIds();return!!this.findShapeAncestor(i,e=>s.includes(e.id))}select(...e){let t="string"==typeof e[0]?e:e.map(e=>e.id);return this.setSelectedShapes(t),this}deselect(...e){let t="string"==typeof e[0]?e:e.map(e=>e.id),i=this.getSelectedShapeIds();return i.length>0&&t.length>0&&this.setSelectedShapes(i.filter(e=>!t.includes(e))),this}selectAll(){let e=this.getSortedChildIdsForParent(this.getCurrentPageId());return e.length<=0||this.setSelectedShapes(this._getUnlockedShapeIds(e)),this}
1selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShape(){let e=this.getSelectedShapes();return 1===e.length?e[0]:null}getSelectionPageBounds(){let e=this.getCurrentPageState().selectedShapeIds;return 0===e.length?null:d.xu.Common((0,n.oA)(e.map(e=>this.getShapePageBounds(e))))}getSelectionRotation(){let e=this.getSelectedShapeIds();if(0===e.length)return 0;if(1===e.length)return this.getShapePageTransform(this.getSelectedShapeIds()[0]).rotation();let t=e.map(e=>this.getShapePageTransform(e).rotation());return t.every(e=>Math.abs(e-t[0])<Math.PI/180)?this.getShapePageTransform(e[0]).rotation():0}getSelectionRotatedPageBounds(){let e=this.getSelectedShapeIds();if(0===e.length)return;let t=this.getSelectionRotation();if(0===t)return this.getSelectionPageBounds();if(1===e.length){let t=this.getShapeGeometry(e[0]).bounds.clone(),i=this.getShapePageTransform(e[0]);return t.point=i.applyToPoint(t.point),t}let i=d.xu.FromPoints(this.getSelectedShapeIds().flatMap(e=>{let t=this.getShapePageTransform(e);return t?t.applyToPoints(this.getShapeGeometry(e).vertices):[]}).map(e=>g.B.Rot(e,-t)));return i.point=i.point.rot(t),i}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){let e=this.getFocusedGroupId();return e?this.getShape(e):void 0}setFocusedGroup(e){let t="string"==typeof e?e:e?.id??null;if(null!==t){let e=this.getShape(t);if(!e)throw Error(`Editor.setFocusedGroup: Shape with id ${t} does not exist`);if(!this.isShapeOfType(e,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${e.type}`)}return t===this.getFocusedGroupId()||this._setFocusedGroupId(t),this}_setFocusedGroupId=this.history.createCommand("setFocusedGroupId",e=>{let t=this.getCurrentPageState().focusedGroupId;if(t!==e)return{data:{prev:t,next:e},preservesRedoStack:!0,squashing:!0}},{do:({next:e})=>{this.store.update(this.getCurrentPageState().id,t=>({...t,focusedGroupId:e}))},undo:({prev:e})=>{this.store.update(this.getCurrentPageState().id,t=>({...t,focusedGroupId:e}))},squash:({prev:e},{next:t})=>({prev:e,next:t})});popFocusedGroupId(){let e=this.getFocusedGroup();if(e){let t=this.findShapeAncestor(e,e=>this.isShapeOfType(e,"group"));this.setFocusedGroup(t?.id??null),this.select(e.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){let e=this.getEditingShapeId();return e?this.getShape(e):void 0}setEditingShape(e){let t="string"==typeof e?e:e?.id??null;if(t!==this.getEditingShapeId()){if(t){let e=this.getShape(t);if(e&&this.getShapeUtil(e).canEdit(e))return this._setInstancePageState({editingShapeId:t}),this}this._setInstancePageState({editingShapeId:null})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){let e=this.getHoveredShapeId();return e?this.getShape(e):void 0}setHoveredShape(e){let t="string"==typeof e?e:e?.id??null;return t===this.getHoveredShapeId()||this.updateCurrentPageState({hoveredShapeId:t},{ephemeral:!0}),this}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){let e=this.getHintingShapeIds();return(0,n.oA)(e.map(e=>this.getShape(e)))}setHintingShapes(e){let t="string"==typeof e[0]?e:e.map(e=>e.id);return this.updateCurrentPageState({hintingShapeIds:(0,n.D8)(t)},{ephemeral:!0}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){let e=this.getErasingShapeIds();return(0,n.oA)(e.map(e=>this.getShape(e)))}setErasingShapes(e){let t="string"==typeof e[0]?e:e.map(e=>e.id);t.sort();let i=this.getErasingShapeIds();if(t.length===i.length){for(let e=0;e<t.length;e++)if(t[e]!==i[e]){this._setInstancePageState({erasingShapeIds:t},{ephemeral:!0});break}}else this._setInstancePageState({erasingShapeIds:t},{ephemeral:!0});return this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(e){let t="string"==typeof e?e:e?.id??null;if(t!==this.getCroppingShapeId()){if(t){let e=this.getShape(t),i=this.getShapeUtil(e);e&&i.canCrop(e)&&this.updateCurrentPageState({croppingShapeId:t})}else this.updateCurrentPageState({croppingShapeId:null})}return this}getCameraId(){return r.AN.createId(this.getCurrentPageId())}getCamera(){return this.store.get(this.getCameraId())}getZoomLevel(){return this.getCamera().z}_setCamera(e){let t=this.getCamera();return t.x===e.x&&t.y===e.y&&t.z===e.z||this.batch(()=>{this.store.put([{...t,...e}]);let{currentScreenPoint:i}=this.inputs,{screenBounds:s}=this.store.unsafeGetWithoutCapture(r.PQ);this.dispatch({type:"pointer",target:"canvas",name:"pointer_move",point:g.B.AddXY(i,s.x,s.y),pointerId:p.CK.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shift
1Key,button:0,isPen:this.getInstanceState().isPenMode??!1}),this._tickCameraState()}),this}setCamera(e,t){let i=Number.isFinite(e.x)?e.x:0,s=Number.isFinite(e.y)?e.y:0,r=Number.isFinite(e.z)?e.z:this.getZoomLevel();if(this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),t){let{width:e,height:n}=this.getViewportScreenBounds();return this._animateToViewport(new d.xu(-i,-s,e/r,n/r),t)}return this._setCamera({x:i,y:s,z:r}),this}centerOnPoint(e,t){if(!this.getInstanceState().canMoveCamera)return this;let{width:i,height:s}=this.getViewportPageBounds();return this.setCamera({x:-(e.x-i/2),y:-(e.y-s/2),z:this.getCamera().z},t),this}zoomToContent(){let e=this.getSelectionPageBounds()??this.getCurrentPageBounds();return e&&this.zoomToBounds(e,{targetZoom:Math.min(1,this.getZoomLevel()),duration:220}),this}zoomToFit(e){if(!this.getInstanceState().canMoveCamera)return this;let t=[...this.getCurrentPageShapeIds()];if(t.length<=0)return this;let i=d.xu.Common((0,n.oA)(t.map(e=>this.getShapePageBounds(e))));return this.zoomToBounds(i,e),this}resetZoom(e=this.getViewportScreenCenter(),t){if(!this.getInstanceState().canMoveCamera)return this;let{x:i,y:s,z:r}=this.getCamera(),{x:n,y:a}=e;return this.setCamera({x:i+(n/1-n)-(n/r-n),y:s+(a/1-a)-(a/r-a),z:1},t),this}zoomIn(e=this.getViewportScreenCenter(),t){if(!this.getInstanceState().canMoveCamera)return this;let{x:i,y:s,z:r}=this.getCamera(),n=p.sZ;for(let e=1;e<p.E.length;e++){let t=p.E[e-1],i=p.E[e];if(!(i-r<=(i-t)/2)){n=i;break}}let{x:a,y:h}=e;return this.setCamera({x:i+(a/n-a)-(a/r-a),y:s+(h/n-h)-(h/r-h),z:n},t),this}zoomOut(e=this.getViewportScreenCenter(),t){if(!this.getInstanceState().canMoveCamera)return this;let{x:i,y:s,z:r}=this.getCamera(),n=p.Zj;for(let e=p.E.length-1;e>0;e--){let t=p.E[e-1],i=p.E[e];if(!(i-r>=(i-t)/2)){n=t;break}}let{x:a,y:h}=e;return this.setCamera({x:i+(a/n-a)-(a/r-a),y:s+(h/n-h)-(h/r-h),z:n},t),this}zoomToSelection(e){if(!this.getInstanceState().canMoveCamera)return this;let t=this.getSelectionPageBounds();return t&&this.zoomToBounds(t,{targetZoom:Math.max(1,this.getZoomLevel()),...e}),this}panZoomIntoView(e,t){if(!this.getInstanceState().canMoveCamera||e.length<=0)return this;let i=d.xu.Common((0,n.oA)(e.map(e=>this.getShapePageBounds(e)))),s=this.getViewportPageBounds();if(s.h<i.h||s.w<i.w)this.zoomToBounds(i,{targetZoom:this.getCamera().z,...t});else{let e=this.getViewportPageBounds().clone().expandBy(-32/this.getZoomLevel()),s=0,r=0;e.maxY<i.maxY?r=e.maxY-i.maxY:e.minY>i.minY&&(r=e.minY-i.minY),e.maxX<i.maxX?s=e.maxX-i.maxX:e.minX>i.minX&&(s=e.minX-i.minX);let n=this.getCamera();this.setCamera({x:n.x+s,y:n.y+r,z:n.z},t)}return this}zoomToBounds(e,t){if(!this.getInstanceState().canMoveCamera)return this;let i=this.getViewportScreenBounds(),s=t?.inset??Math.min(256,.28*i.width),r=(0,f.uZ)(Math.min((i.width-s)/e.width,(i.height-s)/e.height),p.Zj,p.sZ);return t?.targetZoom!==void 0&&(r=Math.min(t.targetZoom,r)),this.setCamera({x:-e.minX+(i.width-e.width*r)/2/r,y:-e.minY+(i.height-e.height*r)/2/r,z:r},t),this}pan(e,t){if(!this.getInstanceState().canMoveCamera)return this;let{x:i,y:s,z:r}=this.getCamera();return this.setCamera({x:i+e.x/r,y:s+e.y/r,z:r},t),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_viewportAnimation=null;_animateViewport(e){if(!this._viewportAnimation)return;let t=()=>{this.removeListener("tick",this._animateViewport),this.removeListener("stop-camera-animation",t),this._viewportAnimation=null};this.once("stop-camera-animation",t),this._viewportAnimation.elapsed+=e;let{elapsed:i,easing:s,duration:r,start:n,end:a}=this._viewportAnimation;if(i>r){this._setCamera({x:-a.x,y:-a.y,z:this.getViewportScreenBounds().width/a.width}),t();return}let h=s(1-(r-i)/r),o=n.minX+(a.minX-n.minX)*h,p=n.minY+(a.minY-n.minY)*h,d=n.maxX+(a.maxX-n.maxX)*h;this._setCamera({x:-o,y:-p,z:this.getViewportScreenBounds().width/(d-o)})}_animateToViewport(e,t={}){let{duration:i=0,easing:s=u.L.easeInOutCubic}=t,r=this.user.getAnimationSpeed(),n=this.getViewportPageBounds();return(this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),0===i||0===r)?this._setCamera({x:-e.x,y:-e.y,z:this.getViewportScreenBounds().width/e.width}):(this._viewportAnimation={elapsed:0,duration:i/r,easing:s,start:n.clone(),end:e.clone()},this.addListener("tick",this._animateViewport),this)}slideCamera(e={}){if(!this.getInstanceState().canMoveCamera||(this.stopCameraAnimation(),0===this.user.getAnimationSpeed()))return this;let{speed:t,friction:i,direction:s,speedThreshold:r=.01}=e,n=Math.min(t,1),a=()=>{this.removeListener("tick",h),this.removeListener("stop-camera-animation",a)};this.once("stop-camera-animation",a);let h=e=>{let{x:t,y:h,z:o}=this.getCamera(),p=g.B.Mul(s,n*e/o);
1(n*=1-i)<r?a():this._setCamera({x:t+p.x,y:h+p.y,z:o})};return this.addListener("tick",h),this}animateToUser(e){let t=[...this.store.query.records("instance_presence",()=>({userId:{eq:e}})).get()].sort((e,t)=>e.lastActivityTimestamp-t.lastActivityTimestamp).pop();return t&&this.batch(()=>{null!==this.getInstanceState().followingUserId&&this.stopFollowingUser();let i=t.currentPageId===this.getCurrentPageId();i||this.setCurrentPage(t.currentPageId),this.centerOnPoint(t.cursor,i?{duration:500}:void 0);let{highlightedUserIds:s}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...s,e]}),setTimeout(()=>{let t=[...this.getInstanceState().highlightedUserIds],i=t.indexOf(e);i<0||(t.splice(i,1),this.updateInstanceState({highlightedUserIds:t}))},p.O8)}),this}animateToShape(e,t=p.Xy){if(!this.getInstanceState().canMoveCamera)return this;let i=this.getViewportScreenBounds().clone().expandBy(-32),s=i.width/i.height,r=this.getShapePageBounds(e);if(!r)return this;let n=r.width/r.height,a=r.clone(),h=r.width/i.width;return a.width+=(i.minX+i.maxX)*h,a.height+=(i.minY+i.maxY)*h,a.x-=i.minX*h,a.y-=i.minY*h,n>s?(a.height=r.width/s,a.y-=(a.height-r.height)/2):(a.width=r.height*s,a.x-=(a.width-r.width)/2),this._animateToViewport(a,t)}_willSetInitialBounds=!0;_wasInset=!1;updateViewportScreenBounds(e,t=!1){e.width=Math.max(e.width,1),e.height=Math.max(e.height,1);let i=[0!==e.minY,document.body.scrollWidth!==e.maxX,document.body.scrollHeight!==e.maxY,0!==e.minX],s=e.equals(this.getViewportScreenBounds()),{_willSetInitialBounds:r}=this;if(s)this._willSetInitialBounds=!1;else if(r)this._willSetInitialBounds=!1,this.updateInstanceState({screenBounds:e.toJson(),insets:i},{squashing:!0,ephemeral:!0});else if(t&&!this.getInstanceState().followingUserId){let t=this.getViewportPageCenter();this.updateInstanceState({screenBounds:e.toJson(),insets:i},{squashing:!0,ephemeral:!0}),this.centerOnPoint(t)}else this.updateInstanceState({screenBounds:e.toJson(),insets:i},{squashing:!0,ephemeral:!0});return this._tickCameraState(),this.updateRenderingBounds(),this}getViewportScreenBounds(){let{x:e,y:t,w:i,h:s}=this.getInstanceState().screenBounds;return new d.xu(e,t,i,s)}getViewportScreenCenter(){let e=this.getViewportScreenBounds();return new g.B(e.midX-e.minX,e.midY-e.minY)}getViewportPageBounds(){let{w:e,h:t}=this.getViewportScreenBounds(),{x:i,y:s,z:r}=this.getCamera();return new d.xu(-i,-s,e/r,t/r)}getViewportPageCenter(){return this.getViewportPageBounds().center}screenToPage(e){let{screenBounds:t}=this.store.unsafeGetWithoutCapture(r.PQ),{x:i,y:s,z:n=1}=this.getCamera();return{x:(e.x-t.x)/n-i,y:(e.y-t.y)/n-s,z:e.z??.5}}pageToScreen(e){let{screenBounds:t}=this.store.unsafeGetWithoutCapture(r.PQ),{x:i,y:s,z:n=1}=this.getCamera();return{x:(e.x+i)*n+t.x,y:(e.y+s)*n+t.y,z:e.z??.5}}startFollowingUser(e){let t=this.store.query.records("instance_presence",()=>({userId:{eq:e}})),i=this.user.getId();if(i||console.warn("You should set the userId for the current instance before following a user"),t.get().some(e=>e.followingUserId===i))return this;(0,s.ay)(()=>{this.stopFollowingUser(),this.updateInstanceState({followingUserId:e},{ephemeral:!0})});let r=()=>{this.removeListener("frame",a),this.removeListener("stop-following",r)},n=!1,a=()=>{let s=[...t.get()].sort((e,t)=>e.lastActivityTimestamp-t.lastActivityTimestamp).pop();if(!s){this.stopFollowingUser();return}let r=s.currentPageId===this.getCurrentPageId(),a=r?p.CN:1;if(!r){this.stopFollowingUser(),this.setCurrentPage(s.currentPageId),this.startFollowingUser(e);return}let{center:h,width:o,height:l}=this.getViewportPageBounds(),u=d.xu.From(s.screenBounds),c=u.width/s.camera.z,S=u.height/s.camera.z,m=new g.B(c/2-s.camera.x,S/2-s.camera.y),y=s.followingUserId===i,I=o+(c-o)*a,P=l+(S-l)*a,C=(0,f.uZ)(this.getCamera().z*(y?l/P:Math.min(o/I,l/P)),p.Zj,p.sZ),w=this.getViewportScreenBounds().w/C,x=this.getViewportScreenBounds().h/C,_=m.sub(h),b=g.B.Add(h,g.B.Mul(_,a)),v=g.B.Sub(b,h).len(),T=Math.abs(C-this.getCamera().z);if(v<p.wi&&T<p.Ns){n=!0;return}n&&v<p.Qd&&T<p.RH||(n=!1,this.stopCameraAnimation(),this._setCamera({x:-(b.x-w/2),y:-(b.y-x/2),z:C}))};return this.once("stop-following",r),this.addListener("frame",a),this}stopFollowingUser(){return this.updateInstanceState({followingUserId:null},{ephemeral:!0}
1),this.emit("stop-following"),this}_cameraState=(0,s.cn)("camera state","idle");getCameraState(){return this._cameraState.get()}_cameraStateTimeoutRemaining=0;_lastUpdateRenderingBoundsTimestamp=Date.now();_decayCameraStateTimeout=e=>{this._cameraStateTimeoutRemaining-=e,this._cameraStateTimeoutRemaining<=0&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"),this.updateRenderingBounds())};_tickCameraState=()=>{this._cameraStateTimeoutRemaining=p.yV;let e=Date.now();"idle"===this._cameraState.__unsafe__getWithoutCapture()?(this._lastUpdateRenderingBoundsTimestamp=e,this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout)):e-this._lastUpdateRenderingBoundsTimestamp>p.aR&&this.updateRenderingBounds()};getUnorderedRenderingShapes(e){let t=[],i=2*p.kx,s=p.kx,r=this.getEditingShapeId(),n=this.getSelectedShapeIds(),a=this.getErasingShapeIds(),h=this.getRenderingBoundsExpanded(),o=Number.isFinite(this.renderingBoundsMargin),d=(l,g,u)=>{let c=this.getShape(l);if(!c)return;g*=c.opacity;let S=!1,f=!1,m=this.getShapeUtil(c),y=this.getShapeMaskedPageBounds(l);e&&((f=!u&&a.includes(l))&&(g*=.32),S=o&&m.canUnmount(c)&&r!==l&&(void 0===y||!h.includes(y)&&!n.includes(l))),t.push({id:l,shape:c,util:m,index:i,backgroundIndex:s,opacity:g,isCulled:S,maskedPageBounds:y}),i+=1,s+=1;let I=this.getSortedChildIdsForParent(l);if(!I.length)return;let P=null;for(let e of(m.providesBackgroundForChildren(c)&&(P=s,s=i,i+=p.kx),I))d(e,g,u||f);null!==P&&(s=P)};for(let t of e?[this.getCurrentPage()]:this.getPages())for(let e of this.getSortedChildIdsForParent(t.id))d(e,1,!1);return t}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(n.uv)}getRenderingBounds(){return this._renderingBounds.get()}_renderingBounds=(0,s.cn)("rendering viewport",new d.xu);getRenderingBoundsExpanded(){return this._renderingBoundsExpanded.get()}_renderingBoundsExpanded=(0,s.cn)("rendering viewport expanded",new d.xu);updateRenderingBounds(){let e=this.getViewportPageBounds();return e.equals(this._renderingBounds.__unsafe__getWithoutCapture())||(this._renderingBounds.set(e.clone()),Number.isFinite(this.renderingBoundsMargin)?this._renderingBoundsExpanded.set(e.clone().expandBy(this.renderingBoundsMargin/this.getZoomLevel())):this._renderingBoundsExpanded.set(e)),this}renderingBoundsMargin=100;_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(n.hl)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(e){return this.store.get("string"==typeof e?e:e.id)}_currentPageShapeIds;getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getPageShapeIds(e){let t="string"==typeof e?e:e.id,i=this.store.query.exec("shape",{parentId:{eq:t}});return this.getShapeAndDescendantIds(i.map(e=>e.id))}setCurrentPage(e,t){let i="string"==typeof e?e:e.id;return this._setCurrentPageId(i,t),this}_setCurrentPageId=this.history.createCommand("setCurrentPage",(e,t)=>{if(!this.store.has(e)){console.error("Tried to set the current page id to a page that doesn't exist.");return}return this.stopFollowingUser(),{data:{toId:e,fromId:this.getCurrentPageId()},squashing:!0,preservesRedoStack:!0,...t}},{do:({toId:e})=>{if(this.store.has(e)){if(!this.getPageStates().find(t=>t.pageId===e)){let t=r.AN.create({id:r.AN.createId(e)});this.store.put([t,r.iS.create({id:r.iS.createId(e),pageId:e})])}this.store.put([{...this.getInstanceState(),currentPageId:e}]),this.updateRenderingBounds()}},undo:({fromId:e})=>{this.store.has(e)&&(this.store.put([{...this.getInstanceState(),currentPageId:e}]),this.updateRenderingBounds())},squash:({fromId:e},{toId:t})=>({toId:t,fromId:e})});updatePage(e,t){return this._updatePage(e,t),this}_updatePage=this.history.createCommand("updatePage",(e,t)=>{if(this.getInstanceState().isReadonly)return null;let i=this.getPage(e.id);return i?{data:{prev:i,partial:e},...t}:null},{do:({partial:e})=>{this.store.update(e.id,t=>({...t,...e}))},undo:({prev:e,partial:t})=>{this.store.update(t.id,()=>e)},squash:(e,t)=>({prev:{...e.prev,...t.prev},partial:t.partial})});createPage(e){return this._createPage(e),this}_createPage=this.history.createCommand("createPage",e=>
1{if(this.getInstanceState().isReadonly||this.getPages().length>=p.Et)return null;let t=this.getPages(),i=(0,P.u)(e.name??"Page 1",t.map(e=>e.name)),s=e.index;(!s||t.some(e=>e.index===s))&&(s=(0,n._L)(t[t.length-1].index));let a=r.ez.create({meta:{},...e,name:i,index:s}),h=r.AN.create({id:r.AN.createId(a.id)}),o=r.iS.create({id:r.iS.createId(a.id),pageId:a.id});return{data:{newPage:a,newTabPageState:o,newCamera:h}}},{do:({newPage:e,newTabPageState:t,newCamera:i})=>{this.store.put([e,i,t])},undo:({newPage:e,newTabPageState:t,newCamera:i})=>{1!==this.getPages().length&&this.store.remove([t.id,e.id,i.id])}});deletePage(e){let t="string"==typeof e?e:e.id;return this._deletePage(t),this}_deletePage=this.history.createCommand("delete_page",e=>{if(this.getInstanceState().isReadonly)return null;let t=this.getPages();if(1===t.length)return null;let i=this.getPage(e),s=this.getPageStates().filter(t=>t.pageId===e);if(!i)return null;if(e===this.getCurrentPageId()){let i=t.findIndex(t=>t.id===e),s=t[i-1]??t[i+1];this.setCurrentPage(s.id)}return{data:{id:e,deletedPage:i,deletedPageStates:s}}},{do:({deletedPage:e,deletedPageStates:t})=>{let i=this.getPages();if(1!==i.length){if(e.id===this.getCurrentPageId()){let t=i.findIndex(t=>t.id===e.id),s=i[t-1]??i[t+1];this.setCurrentPage(s.id)}this.store.remove(t.map(e=>e.id)),this.store.remove([e.id]),this.updateRenderingBounds()}},undo:({deletedPage:e,deletedPageStates:t})=>{this.store.put([e]),this.store.put(t),this.updateRenderingBounds()}});duplicatePage(e,t=r.ez.createId()){if(this.getPages().length>=p.Et)return this;let i="string"==typeof e?e:e.id,s=this.getPage(i);if(!s)return this;let a={...this.getCamera()},h=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.batch(()=>{let e=this.getPages(),i=(0,n.eI)(s.index,e[e.indexOf(s)+1]?.index);if(this.createPage({name:s.name+" Copy",id:t,index:i}),this.setCurrentPage(t),this.setCamera(a),h)return this.putContentOntoCurrentPage(h)}),this}renamePage(e,t,i){let s="string"==typeof e?e:e.id;return this.getInstanceState().isReadonly||this.updatePage({id:s,name:t},i),this}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(e){return this._createAssets(e),this}_createAssets=this.history.createCommand("createAssets",e=>this.getInstanceState().isReadonly||e.length<=0?null:{data:{assets:e}},{do:({assets:e})=>{this.store.put(e)},undo:({assets:e})=>{this.store.remove(e.map(e=>e.id))}});updateAssets(e){return this._updateAssets(e),this}_updateAssets=this.history.createCommand("updateAssets",e=>{if(!this.getInstanceState().isReadonly&&!(e.length<=0))return{data:{snapshots:{},assets:e}}},{do:({assets:e,snapshots:t})=>{this.store.put(e.map(e=>{let i=this.store.get(e.id);return t[e.id]=i,{...i,...e}}))},undo:({snapshots:e})=>{this.store.put(Object.values(e))}});deleteAssets(e){let t="string"==typeof e[0]?e:e.map(e=>e.id);return this._deleteAssets(t),this}_deleteAssets=this.history.createCommand("deleteAssets",e=>{if(this.getInstanceState().isReadonly||e.length<=0)return;let t=(0,n.oA)(e.map(e=>this.store.get(e)));return{data:{ids:e,prev:t}}},{do:({ids:e})=>{this.store.remove(e)},undo:({prev:e})=>{this.store.put(e)}});getAsset(e){return this.store.get("string"==typeof e?e:e.id)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",e=>this.getShapeUtil(e).getGeometry(e),(e,t)=>e.props===t.props)}getShapeGeometry(e){return this._getShapeGeometryCache().get("string"==typeof e?e:e.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",e=>this.getShapeUtil(e).getHandles?.(e))}getShapeHandles(e){return this._getShapeHandlesCache().get("string"==typeof e?e:e.id)}getShapeLocalTransform(e){let t="string"==typeof e?e:e.id,i=this.getShape(t);if(!i)throw Error("Editor.getTransform: shape not found");return l._.Identity().translate(i.x,i.y).rotate(i.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",e=>{if((0,r.r5)(e.parentId))return this.getShapeLocalTransform(e);let t=this._getShapePageTransformCache().get(e.parentId)??l._.Identity();
1return l._.Compose(t,this.getShapeLocalTransform(e))})}getShapeParentTransform(e){let t="string"==typeof e?e:e.id,i=this.getShape(t);return!i||(0,r.r5)(i.parentId)?l._.Identity():this._getShapePageTransformCache().get(i.parentId)??l._.Identity()}getShapePageTransform(e){let t="string"==typeof e?e:this.getShape(e).id;return this._getShapePageTransformCache().get(t)??l._.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",e=>{let t=this._getShapePageTransformCache().get(e.id);return t?d.xu.FromPoints(l._.applyToPoints(t,this.getShapeGeometry(e).vertices)):new d.xu})}getShapePageBounds(e){return this._getShapePageBoundsCache().get("string"==typeof e?e:e.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",e=>{let t=this._getShapeMaskCache().get(e.id);if(!t)return;if(0===t.length)return"polygon(0px 0px, 0px 0px, 0px 0px)";let i=this._getShapePageTransformCache().get(e.id);if(!i)return;let s=l._.applyToPoints(l._.Inverse(i),t);return`polygon(${s.map(e=>`${e.x}px ${e.y}px`).join(",")})`})}getShapeClipPath(e){return this._getShapeClipPathCache().get("string"==typeof e?e:e.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",e=>{if((0,r.r5)(e.parentId))return;let t=this.getShapeAncestors(e.id).filter(e=>this.isShapeOfType(e,"frame"));if(0!==t.length)return t.map(e=>this._getShapePageTransformCache().get(e.id).applyToPoints(this.getShapeGeometry(e).vertices)).reduce((e,t)=>{if(!(t&&e))return;let i=(0,S.tY)(e,t);return i?i.map(g.B.Cast):[]})})}getShapeMask(e){return this._getShapeMaskCache().get("string"==typeof e?e:e.id)}getShapeMaskedPageBounds(e){"string"!=typeof e&&(e=e.id);let t=this._getShapePageBoundsCache().get(e);if(!t)return;let i=this._getShapeMaskCache().get(e);if(i){if(0===i.length)return;let{corners:e}=t;if(e.every((e,t)=>e&&g.B.Equals(e,i[t])))return t.clone();let s=(0,S.tY)(i,e);if(!s)return;return d.xu.FromPoints(s)}return t}getShapeAncestors(e,t=[]){let i="string"==typeof e?e:e.id,s=this.getShape(i);if(!s)return t;let n=s.parentId;if((0,r.r5)(n))return t.reverse(),t;let a=this.store.get(n);return a?(t.push(a),this.getShapeAncestors(a,t)):t}findShapeAncestor(e,t){let i="string"==typeof e?e:e.id,s=this.getShape(i);if(!s)return;let n=s.parentId;if((0,r.r5)(n))return;let a=this.getShape(n);if(a)return t(a)?a:this.findShapeAncestor(a,t)}hasAncestor(e,t){let i="string"==typeof e?e:e?.id,s=i&&this.getShape(i);return!!s&&(s.parentId===t||this.hasAncestor(this.getShapeParent(s),t))}findCommonAncestor(e,t){if(0===e.length)return;let i="string"==typeof e[0]?e:e.map(e=>e.id),s=(0,n.oA)(i.map(e=>this.getShape(e)));if(1===s.length){let e=s[0].parentId;if((0,r.r5)(e))return;return t?this.findShapeAncestor(s[0],t)?.id:e}let[a,...h]=s,o=this.getShapeParent(a);for(;o;){if(t&&!t(o)){o=this.getShapeParent(o);continue}if(h.every(e=>this.hasAncestor(e,o.id)))return o.id;o=this.getShapeParent(o)}}
1isShapeOrAncestorLocked(e){let t="string"==typeof e?this.getShape(e):e;return void 0!==t&&(!!t.isLocked||this.isShapeOrAncestorLocked(this.getShapeParent(t)))}getCurrentPageBounds(){let e;return this.getCurrentPageShapeIds().forEach(t=>{let i=this.getShapeMaskedPageBounds(t);i&&(e=e?e.expand(i):i.clone())}),e}getSelectedShapeAtPoint(e){let t=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(e=>"group"!==e.type&&t.includes(e.id)).reverse().find(t=>this.isPointInShape(t,e,{hitInside:!0,margin:0}))}getShapeAtPoint(e,t={}){let i=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:r,margin:n=0,hitLabels:a=!1,hitInside:h=!1,hitFrameInside:o=!1}=t,d=1/0,l=null,g=1/0,u=null,S=(t.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(t=>{if(this.isShapeOfType(t,"group"))return!1;let i=this.getShapeMask(t);return(!i||!!(0,f.Of)(e,i))&&(!r||r(t))});for(let t=S.length-1;t>=0;t--){let r;let f=S[t],m=this.getShapeGeometry(f),y=m instanceof c.m,I=this.getPointInShapeSpace(f,e);if((this.isShapeOfType(f,"arrow")||this.isShapeOfType(f,"geo")&&"none"===f.props.fill)&&f.props.text.trim()){for(let e of m.children)if(e.isLabel&&e.isPointInBounds(I))return f}if(this.isShapeOfType(f,"frame")){if(Math.abs(m.distanceToPoint(I,h))<=n)return u||f;if(m.hitTestPoint(I,0,!0))return u||l||(o?f:void 0);continue}if(y){let e=1/0;for(let t of m.children){if(t.isLabel&&!a)continue;let i=t.distanceToPoint(I,h);i<e&&(e=i)}r=e}else r=0===n&&(m.bounds.w<1||m.bounds.h<1)?m.distanceToPoint(I,h):m.bounds.containsPoint(I,n)?m.distanceToPoint(I,h):1/0;if(m.isClosed){if(r<=n){if(m.isFilled||y&&m.children[0].isFilled)return u||f;if(this.getShapePageBounds(f).contains(s))continue;if(Math.abs(r)<n)Math.abs(r)<g&&(g=Math.abs(r),u=f);else if(!u){let{area:e}=m;e<d&&(d=e,l=f)}}}else if(r<p.wM/i)return f}return u||l||void 0}getShapesAtPoint(e,t={}){return this.getCurrentPageShapes().filter(i=>this.isPointInShape(i,e,t))}isPointInShape(e,t,i={}){let{hitInside:s=!1,margin:r=0}=i,n="string"==typeof e?e:e.id,a=this.getShapeMask(n);return(!a||!!(0,f.Of)(t,a))&&this.getShapeGeometry(n).hitTestPoint(this.getPointInShapeSpace(e,t),r,s)}getPointInShapeSpace(e,t){let i="string"==typeof e?e:e.id;return this._getShapePageTransformCache().get(i).clone().invert().applyToPoint(t)}getPointInParentSpace(e,t){let i="string"==typeof e?e:e.id,s=this.getShape(i);if(!s)return new g.B(0,0);if((0,r.r5)(s.parentId))return g.B.From(t);let n=this.getShapePageTransform(s.parentId);return n?n.clone().invert().applyToPoint(t):g.B.From(t)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),e=>this.store.get(e))}getCurrentPageShapesSorted(){let e=new Set(this.getCurrentPageShapes().sort(n.hl)),t=[];return e.forEach(i=>{let s=this.getShape(i.parentId);(0,r.VV)(s)||function i(s){t.push(s),e.delete(s),e.forEach(e=>{e.parentId===s.id&&i(e)})}(i)}),t}getCurrentPageRenderingShapesSorted(){return this.getRenderingShapes().filter(({isCulled:e})=>!e).sort((e,t)=>e.index-t.index).map(({shape:e})=>e)}
1isShapeOfType(e,t){return("string"==typeof e?this.getShape(e):e).type===t}getShape(e){let t="string"==typeof e?e:e.id;if((0,r.YT)(t))return this.store.get(t)}getShapeParent(e){let t="string"==typeof e?e:e?.id;if(!t)return;let i=this.getShape(t);if(void 0!==i&&(0,r.YT)(i.parentId))return this.store.get(i.parentId)}getShapeNearestSibling(e,t){return t?t.parentId===e.parentId?t:this.findShapeAncestor(t,t=>t.parentId===e.parentId):void 0}isShapeInPage(e,t=this.getCurrentPageId()){let i="string"==typeof e?e:e.id,s=this.getShape(i);if(!s)return!1;let r=!1;if(s.parentId===t)r=!0;else{let e=this.getShape(s.parentId);for(;e;){if(e.parentId===t){r=!0;break}e=this.getShape(e.parentId)}}return r}getAncestorPageId(e){let t="string"==typeof e?e:e?.id,i=t&&this.getShape(t);if(i)return(0,r.r5)(i.parentId)?i.parentId:this.getAncestorPageId(this.getShape(i.parentId))}_parentIdsToChildIds;reparentShapes(e,t,i){let s="string"==typeof e[0]?e:e.map(e=>e.id);if(0===s.length)return this;let a=[],h=(0,r.r5)(t)?l._.Identity():this.getShapePageTransform(t),o=h.rotation(),p=[],d=(0,n.oA)(this.getSortedChildIdsForParent(t).map(e=>this.getShape(e)));if(i){let e=d.find(e=>e.index===i);if(e){let t=d[d.indexOf(e)+1];p=t?(0,n.Xv)(i,t.index,s.length):(0,n.vw)(i,s.length)}else{let e=d.sort(n.hl).find(e=>e.index>i);p=e?(0,n.Xv)(i,e.index,s.length):(0,n.vw)(i,s.length)}}else{let e=d.length&&d[d.length-1];p=e?(0,n.vw)(e.index,s.length):(0,n.H$)(s.length)}let g=h.clone().invert(),u=(0,n.oA)(s.map(e=>this.getShape(e))),c=u.filter(e=>e.isLocked);c.length&&this.updateShapes(c.map(({id:e,type:t})=>({id:e,type:t,isLocked:!1})));for(let e=0;e<u.length;e++){let i=u[e],s=this.getShapePageTransform(i);if(!s)continue;let r=s.point();if(!r)continue;let n=g.applyToPoint(r),h=s.rotation()-o;a.push({id:i.id,type:i.type,parentId:t,x:n.x,y:n.y,rotation:h,index:p[e],isLocked:i.isLocked})}return this.updateShapes(a),this}getHighestIndexForParent(e){let t="string"==typeof e?e:e.id,i=this._parentIdsToChildIds.get()[t];if(!i||0===i.length)return"a1";let s=this.getShape(i[i.length-1]);return(0,n._L)(s.index)}_childIdsCache=new y._;getSortedChildIdsForParent(e){let t="string"==typeof e?e:e.id,i=this._parentIdsToChildIds.get()[t];return i?this._childIdsCache.get(i,()=>i):s.LZ}visitDescendants(e,t){let i="string"==typeof e?e:e.id;for(let e of this.getSortedChildIdsForParent(i))!1!==t(e)&&this.visitDescendants(e,t);return this}getShapeAndDescendantIds(e){let t=new Set,i=[...e];for(;i.length>0;){let e=i.pop();if(!e)break;if(!t.has(e))for(let s of(t.add(e),this.getSortedChildIdsForParent(e)))i.push(s)}return t}getDroppingOverShape(e,t=[]){let i=this.getCurrentPageShapesSorted();for(let s=i.length-1;s>=0;s--){let r=i[s];if(!this.getShapeUtil(r).canDropShapes(r,t)||t.find(e=>e.id===r.id||this.hasAncestor(r,e.id)))continue;let n=this.getShapeMaskedPageBounds(r.id);if(n&&n.containsPoint(e)&&this.getShapeGeometry(r).hitTestPoint(this.getPointInShapeSpace(r,e),0,!0))return r}}getOutermostSelectableShape(e,t){let i="string"==typeof e?e:e.id,s=this.getShape(i),r=s,n=s,a=this.getFocusedGroup();for(;n;){if(this.isShapeOfType(n,"group")&&a?.id!==n.id&&!this.hasAncestor(a,n.id)&&(t?.(n)??!0))r=n;else if(a?.id===n.id)break;n=this.getShapeParent(n)}return r}rotateShapesBy(e,t){if(("string"==typeof e[0]?e:e.map(e=>e.id)).length<=0)return this;let i=(0,w.o)({editor:this});return i&&(0,w.Z)({delta:t,snapshot:i,editor:this,stage:"one-off"}),this}getChangesToTranslateShape(e,t){let i=e,s=this.getShapeUtil(e);return i=X(i,s.onTranslateStart?.(i)??void 0),i=X(i,{id:e.id,type:e.type,x:t.x,y:t.y}),i=X(i,s.onTranslate?.(e,i)??void 0),i=X(i,s.onTranslateEnd?.(e,i)??void 0)}nudgeShapes(e,t,i){let s="string"==typeof e[0]?e:e.map(e=>e.id);if(s.length<=0)return this;let r=[];for(let e of s){let i=this.getShape(e),s=g.B.From(t),n=this.getShapeParentTransform(i);n&&s.rot(-n.rotation()),r.push(this.getChangesToTranslateShape(i,s.add(i)))}return this.updateShapes(r,{squashing:!0,...i}),this}duplicateShapes(e,t){let i="string"==typeof e[0]?e:e.map(e=>e.id);if(i.length<=0)return this;let s=new Set(i),a=[],h=[...i];for(;h.length>0;){let e=h.pop();if(!e)break;
1a.push(e),this.getSortedChildIdsForParent(e).forEach(e=>h.push(e))}a.reverse();let o=new Map(a.map(e=>[e,(0,r.F1)()])),d=(0,n.oA)(a.map(e=>{let i=this.getShape(e);if(!i)return null;let r=o.get(e),a=0,h=0;if(t&&s.has(e)){let e=this.getShapeParentTransform(i),s=new g.B(t.x,t.y).rot(-e.rotation());a=s.x,h=s.y}let p=i.parentId??this.getCurrentPageId(),d=this.getSortedChildIdsForParent(p),l=d.indexOf(i.id),u=d[l+1],c=u?this.getShape(u):null,S=c?(0,n.eI)(i.index,c.index):(0,n._L)(i.index),f=(0,n.p$)(i);if(this.isShapeOfType(i,"arrow")&&this.isShapeOfType(f,"arrow")){let e,t;let s=this.getArrowInfo(i);if("binding"===i.props.start.type&&!(e=o.get(i.props.start.boundShapeId))){if(s?.isValid){let{x:e,y:t}=s.start.point;f.props.start={type:"point",x:e,y:t}}else{let{start:e}=(0,K.Qs)(this,i);f.props.start={type:"point",x:e.x,y:e.y}}}if("binding"===i.props.end.type&&!(t=o.get(i.props.end.boundShapeId))){if(s?.isValid){let{x:e,y:t}=s.end.point;f.props.end={type:"point",x:e,y:t}}else{let{end:e}=(0,K.Qs)(this,i);f.props.start={type:"point",x:e.x,y:e.y}}}let r=(0,K.el)(f)?(0,V.r)(this,f):(0,z.p)(this,f);
1if(s?.isValid&&r?.isValid&&!(0,K.el)(i)){let e=g.B.Med(s.start.handle,s.end.handle),t=g.B.Dist(s.middle,e),i=g.B.Dist(r.middle,e);f.props.bend<0?f.props.bend+=i-t:f.props.bend-=i-t}"binding"===f.props.start.type&&e&&(f.props.start.boundShapeId=e),"binding"===f.props.end.type&&t&&(f.props.end.boundShapeId=t)}return{...f,id:r,x:i.x+a,y:i.y+h,index:S}}));return d.forEach(e=>{(0,r.YT)(e.parentId)&&o.has(e.parentId)&&(e.parentId=o.get(e.parentId))}),this.history.batch(()=>{let e=d.length+this.getCurrentPageShapeIds().size>p.kx;e&&Y(this);let i=e?d.slice(0,p.kx-this.getCurrentPageShapeIds().size):d,s=i.map(e=>e.id);if(this.createShapes(i),this.setSelectedShapes(s),void 0!==t){let e=this.getSelectionPageBounds(),t=this.getViewportPageBounds();e&&!t.contains(e)&&this.centerOnPoint(e.center,{duration:p.KD})}}),this}moveShapesToPage(e,t){let i="string"==typeof e[0]?e:e.map(e=>e.id);if(0===i.length||this.getInstanceState().isReadonly||t===this.getCurrentPageId()||!this.store.has(t))return this;let s=this.getContentFromCurrentPage(i);if(!s)return this;if(this.getPageShapeIds(t).size+s.shapes.length>
1p.kx)return Y(this,t),this;let r=this.getCamera().z;return this.history.batch(()=>{this.deleteShapes(i),this.setCurrentPage(t),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(s,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:r}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(e){let t="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly||0===t.length)return this;let i=!0,s=!0,r=[];for(let e of t){let t=this.getShape(e);t&&(r.push(t),t.isLocked?s=!1:i=!1)}return this.batch(()=>{s?(this.updateShapes(r.map(e=>({id:e.id,type:e.type,isLocked:!0}))),this.setSelectedShapes([])):i?this.updateShapes(r.map(e=>({id:e.id,type:e.type,isLocked:!1}))):this.updateShapes(r.map(e=>({id:e.id,type:e.type,isLocked:!0})))}),this}sendToBack(e){let t="string"==typeof e[0]?e:e.map(e=>e.id),i=(0,C.B)(this,"toBack",t);return i&&this.updateShapes(i),this}sendBackward(e){let t="string"==typeof e[0]?e:e.map(e=>e.id),i=(0,C.B)(this,"backward",t);return i&&this.updateShapes(i),this}bringForward(e){let t="string"==typeof e[0]?e:e.map(e=>e.id),i=(0,C.B)(this,"forward",t);return i&&this.updateShapes(i),this}bringToFront(e){let t="string"==typeof e[0]?e:e.map(e=>e.id),i=(0,C.B)(this,"toFront",t);return i&&this.updateShapes(i),this}flipShapes(e,t){let i="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly)return this;let s=(0,n.oA)(i.map(e=>this.getShape(e)));if(!s.length)return this;s=(0,n.oA)(s.map(e=>this.isShapeOfType(e,"group")?this.getSortedChildIdsForParent(e.id).map(e=>this.getShape(e)):e).flat());let r=d.xu.Common((0,n.oA)(s.map(e=>this.getShapePageBounds(e)))).center;return this.batch(()=>{for(let e of s){let i=this.getShapeGeometry(e).bounds,s=this.getShapePageTransform(e.id);s&&this.resizeShape(e.id,{x:"horizontal"===t?-1:1,y:"vertical"===t?-1:1},{initialBounds:i,initialPageTransform:s,initialShape:e,mode:"scale_shape",scaleOrigin:r,scaleAxisRotation:0})}}),this}stackShapes(e,t,i){let s,r,a,h,o;let p="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly)return this;let d=(0,n.oA)(p.map(e=>this.getShape(e)).filter(e=>!(!e||this.isShapeOfType(e,"arrow")&&("binding"===e.props.start.type||"binding"===e.props.end.type)))),l=d.length;if(0===i&&l<3||l<2)return this;let u=Object.fromEntries(d.map(e=>[e.id,this.getShapePageBounds(e)]));if("horizontal"===t?(s="x",r="minX",a="maxX",h="width"):(s="y",r="minY",a="maxY",h="height"),0===i){let e=[];d.sort((e,t)=>u[e.id][r]-u[t.id][r]);for(let t=0;t<l-1;t++){let i=d[t],s=d[t+1],n=u[i.id],h=u[s.id][r]-n[a],o=e.find(e=>e.gap===h);o?o.count++:e.push({gap:h,count:1})}let t=0;e.forEach(e=>{e.count>t&&(t=e.count,o=e.gap)}),1===t&&(o=Math.max(0,e.reduce((e,t)=>e+t.gap*t.count,0)/(l-1)))}else o=i;let c=[],S=u[d[0].id][a];return d.forEach((e,t)=>{if(0===t)return;let i={x:0,y:0};i[s]=S+o-u[e.id][s];let r=this.getShapeParent(e),n=r?g.B.Rot(i,-this.getShapePageTransform(r).decompose().rotation):i,a=this.getShapeUtil(e).onTranslateStart?.(e);c.push(a?{...a,[s]:e[s]+n[s]}:{id:e.id,type:e.type,[s]:e[s]+n[s]}),S+=u[e.id][h]+o}),this.updateShapes(c),this}packShapes(e,t){let i,s,r;let a="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly||a.length<2)return this;let h=(0,n.oA)(a.map(e=>this.getShape(e)).filter(e=>!(!e||this.isShapeOfType(e,"arrow")&&("binding"===e.props.start.type||"binding"===e.props.end.type)))),o={},p={},l,u,c=0;for(let e=0;e<h.length;e++)l=h[e],u=this.getShapePageBounds(l),o[l.id]=u,p[l.id]=u.clone(),c+=u.width*u.height;let S=d.xu.Common((0,n.oA)(Object.values(o))),f=S.width;h.sort((e,t)=>o[t.id].height-o[e.id].height);let m=Math.max(Math.ceil(Math.sqrt(c/.95)),f),y=[new d.xu(S.x,S.y,m,1/0)],I=0,P=0;for(let e=0;e<h.length;e++){u=p[(l=h[e]).id];for(let e=y.length-1;e>=0;e--)if(i=y[e],!(u.width>i.width)&&!(u.height>i.height)){u.x=i.x,u.y=i.y,P=Math.max(P,u.maxY),I=Math.max(I,u.maxX),u.width===i.width&&u.height===i.height?(s=y.pop(),e<y.length&&(y[e]=s)):u.height===i.height?(i.x+=u.width+t,i.width-=u.width+t):(u.width===i.width||y.push(new d.xu(i.x+(u.width+t),i.y,i.width-(u.width+t),u.height)),i.y+=u.height+t,i.height-=u.height+t);break}}let C=d.xu.Common(Object.values(p)),w=g.B.Sub(S.center,C.center),x=[];for(let e=0;e<h.length;e++){u=o[(l=h[e]).id],r=p[l.id];let t=g.B.Sub(r.point,u.point).add(w),i=this.getShapeParentTransform(l);i&&t.rot(-i.rotation());let s={id:l.id,type:l.type,x:l.x+t.x,y:l.y+t.y},n=this.getShapeUtil(l).onTranslateStart?.({...l,...s});n?x.push({...s,...n}):x.push(s)}return x.length&&this.updateShapes(x),this}alignShapes(e,t){let i="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly||i.length<2)return this;let s=(0,n.oA)(i.map(e=>this.getShape(e))),r=Object.fromEntries(s.map(e=>
1[e.id,this.getShapePageBounds(e)])),a=d.xu.Common((0,n.oA)(Object.values(r))),h=[];return s.forEach(e=>{let i=r[e.id];if(!i)return;let s={x:0,y:0};switch(t){case"top":s.y=a.minY-i.minY;break;case"center-vertical":s.y=a.midY-i.minY-i.height/2;break;case"bottom":s.y=a.maxY-i.minY-i.height;break;case"left":s.x=a.minX-i.minX;break;case"center-horizontal":s.x=a.midX-i.minX-i.width/2;break;case"right":s.x=a.maxX-i.minX-i.width}let n=this.getShapeParent(e),o=n?g.B.Rot(s,-this.getShapePageTransform(n).decompose().rotation):s;h.push(this.getChangesToTranslateShape(e,g.B.Add(e,o)))}),this.updateShapes(h),this}distributeShapes(e,t){let i,s,r,a,h;let o="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly||o.length<3)return this;let p=o.length,d=(0,n.oA)(o.map(e=>this.getShape(e))),l=Object.fromEntries(d.map(e=>[e.id,this.getShapePageBounds(e)]));"horizontal"===t?(i="x",s="minX",r="maxX",a="midX",h="width"):(i="y",s="minY",r="maxY",a="midY",h="height");let u=[],c=d.sort((e,t)=>l[e.id][s]-l[t.id][s])[0],S=d.sort((e,t)=>l[t.id][r]-l[e.id][r])[0],f=l[c.id][a],m=(l[S.id][a]-f)/(p-1),y=f+m;return d.filter(e=>e!==c&&e!==S).sort((e,t)=>l[e.id][a]-l[t.id][a]).forEach((e,t)=>{let s={x:0,y:0};s[i]=y+m*t-l[e.id][h]/2-l[e.id][i];let r=this.getShapeParent(e),n=r?g.B.Rot(s,-this.getShapePageTransform(r).rotation()):s;u.push(this.getChangesToTranslateShape(e,g.B.Add(e,n)))}),this.updateShapes(u),this}stretchShapes(e,t){let i="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly||i.length<2)return this;let s=(0,n.oA)(i.map(e=>this.getShape(e))),r=Object.fromEntries(i.map(e=>[e,this.getShapeGeometry(e).bounds])),a=Object.fromEntries(i.map(e=>[e,this.getShapePageBounds(e)])),h=d.xu.Common((0,n.oA)(Object.values(a)));switch(t){case"vertical":this.batch(()=>{for(let e of s){if(this.getShapePageTransform(e).rotation()%f.yo)continue;let t=r[e.id],i=a[e.id],s=new g.B(0,h.minY-i.minY),n=this.getShapeParentTransform(e);n&&s.rot(-n.rotation());let{x:o,y:p}=g.B.Add(s,e);this.updateShapes([{id:e.id,type:e.type,x:o,y:p}],{squashing:!0});let d=new g.B(1,h.height/i.height);this.resizeShape(e.id,d,{initialBounds:t,scaleOrigin:new g.B(i.center.x,h.minY),scaleAxisRotation:0})}});break;case"horizontal":this.batch(()=>{for(let e of s){let t=r[e.id],i=a[e.id];if(this.getShapePageTransform(e).rotation()%f.yo)continue;let s=new g.B(h.minX-i.minX,0),n=this.getShapeParentTransform(e);n&&s.rot(-n.rotation());let{x:o,y:p}=g.B.Add(s,e);this.updateShapes([{id:e.id,type:e.type,x:o,y:p}],{squashing:!0});let d=new g.B(h.width/i.width,1);this.resizeShape(e.id,d,{initialBounds:t,scaleOrigin:new g.B(h.minX,i.center.y),scaleAxisRotation:0})}})}return this}resizeShape(e,t,i={}){let s="string"==typeof e?e:e.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(t.x)||(t=new g.B(1,t.y)),Number.isFinite(t.y)||(t=new g.B(t.x,1));let r=i.initialShape??this.getShape(s);if(!r)return this;let n=i.scaleOrigin??this.getShapePageBounds(s)?.center;if(!n)return this;let a=i.initialPageTransform?l._.Cast(i.initialPageTransform):this.getShapePageTransform(s);if(!a)return this;let h=a.rotation();if(null==h)return this;let o=i.scaleAxisRotation??h,p=i.initialBounds??this.getShapeGeometry(s).bounds;if(!p)return this;if(!(0,f._G)(h,o))return this._resizeUnalignedShape(s,t,{...i,initialBounds:p,scaleOrigin:n,scaleAxisRotation:o,initialPageTransform:a,initialShape:r});let d=this.getShapeUtil(r);if(d.isAspectRatioLocked(r)&&(t=Math.abs(t.x)>Math.abs(t.y)?new g.B(t.x,Math.sign(t.y)*Math.abs(t.x)):new g.B(Math.sign(t.x)*Math.abs(t.y),t.y)),d.onResize&&d.canResize(r)){let e=this._scalePagePoint(l._.applyToPoint(a,new g.B(0,0)),n,t,o),u=this.getPointInParentSpace(r.id,e),c=new g.B(t.x,t.y),S=(0,f.C2)((h-o)%Math.PI,0);c.x=S?t.x:t.y,c.y=S?t.y:t.x;let m=l._.applyToPoint(a,new g.B),{x:y,y:I}=this.getPointInParentSpace(r.id,m);this.updateShapes([{id:s,type:r.type,x:u.x,y:u.y,...d.onResize({...r,x:y,y:I},{newPoint:u,handle:i.dragHandle??"bottom_right",mode:i.mode??"scale_shape",scaleX:c.x,scaleY:c.y,initialBounds:p,initialShape:r})}],{squashing:!0})}else{let e=l._.applyToPoint(a,p.center),i=this._scalePagePoint(e,n,t,o),h=this.getPointInParentSpace(r.id,e),d=this.getPointInParentSpace(r.id,i),u=g.B.Sub(d,h);this.updateShapes([{id:s,type:r.type,x:r.x+u.x,y:r.y+u.y}],{squashing:!0})}return this}
1_scalePagePoint(e,t,i,s){let r=g.B.RotWith(e,t,-s).sub(t),n=g.B.MulV(r,i);return g.B.Add(n,t).rotWith(t,s)}_resizeUnalignedShape(e,t,i){let{type:s}=i.initialShape,r=new g.B(t.x,t.y);if(Math.abs(t.x)>Math.abs(t.y)?r.x=Math.sign(t.x)*Math.abs(t.y):r.y=Math.sign(t.y)*Math.abs(t.x),this.resizeShape(e,r,{initialShape:i.initialShape,initialBounds:i.initialBounds}),Math.sign(t.x)*Math.sign(t.y)<0){let{rotation:t}=l._.Decompose(i.initialPageTransform);t-=2*t,this.updateShapes([{id:e,type:s,rotation:t}],{squashing:!0})}let n=l._.applyToPoint(i.initialPageTransform,i.initialBounds.center),a=this._scalePagePoint(n,i.scaleOrigin,t,i.scaleAxisRotation),h=this.getShapePageBounds(e),o=this.getShapePageTransform(e),p=h.center,d=o.point();if(!p||!d)return this;let u=g.B.Sub(a,p),c=g.B.Add(d,u),{x:S,y:f}=this.getPointInParentSpace(e,c);return this.updateShapes([{id:e,type:s,x:S,y:f}],{squashing:!0}),this}getInitialMetaForShape(e){return{}}createShape(e){return this._createShapes([e]),this}createShapes(e){if(!Array.isArray(e))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");return this._createShapes(e),this}_createShapes=this.history.createCommand("createShapes",e=>{if(this.getInstanceState().isReadonly||e.length<=0)return null;let t=this.getCurrentPageShapeIds();if(e.length+t.size>p.kx){Y(this);return}return 0===e.length?null:{data:{currentPageId:this.getCurrentPageId(),partials:e.map(e=>e.id?e:{...e,id:(0,r.F1)()})}}},{do:({partials:e})=>{let t=this.getFocusedGroupId(),i=this.getCurrentPageShapesSorted();e=e.map(s=>{if(!s.parentId||!(this.store.has(s.parentId)||e.some(e=>e.id===s.parentId))){let e=this.getFocusedGroupId();for(let t=i.length-1;t>=0;t--){let r=i[t];if(this.getShapeUtil(r).canReceiveNewChildrenOfType(r,s.type)&&this.isPointInShape(r,{x:s.x??0,y:s.y??0},{margin:0,hitInside:!0})){e=r.id;break}}let n=s.parentId;if(e===s.id&&(e=t),e!==n&&((s={...s}).parentId=e,(0,r.YT)(e))){let t=this.getPointInShapeSpace(this.getShape(e),{x:s.x??0,y:s.y??0});s.x=t.x,s.y=t.y,s.rotation=-this.getShapePageTransform(e).rotation()+(s.rotation??0)}}return s});let s=new Map,a=[];for(let i of e){let e=this.getShapeUtil(i),r=i.index;if(!r){let e=i.parentId??t;s.has(e)||s.set(e,this.getHighestIndexForParent(e)),r=s.get(e),s.set(e,(0,n._L)(r))}let h=e.getDefaultProps();for(let[e,t]of this.styleProps[i.type])h[t]=this.getStyleForNextShape(e);let o=this.store.schema.types.shape.create({...i,index:r,opacity:i.opacity??this.getInstanceState().opacityForNextShape,parentId:i.parentId??t,props:"props"in i?{...h,...i.props}:h});if(void 0===o.index)throw Error("no index!");let p=this.getShapeUtil(o).onBeforeCreate?.(o);p&&(o=p),a.push(o)}a.forEach(e=>{e.meta={...this.getInitialMetaForShape(e),...e.meta}}),this.store.put(a)},undo:({partials:e})=>{this.store.remove(e.map(e=>e.id))}});animatingShapes=new Map;animateShape(e,t){return this.animateShapes([e],t)}animateShapes(e,t={}){let i,s,r,n;let{duration:a=500,easing:h=u.L.linear}=t,o=(0,x.E)(),p=a,d=[];for(let t=0,i=e.length;t<i;t++){if(!(s=e[t]))continue;r={partial:s,values:[]};let i=this.getShape(s.id);if(i){for(let e of["x","y","rotation"])void 0!==s[e]&&i[e]!==s[e]&&r.values.push({prop:e,from:i[e],to:s[e]});d.push(r),this.animatingShapes.set(i.id,o)}}let l=t=>{if((p-=t)<0){let{animatingShapes:t}=this,i=e.filter(e=>e&&t.get(e.id)===o);i.length&&this.updateShapes(i,{squashing:!1}),this.removeListener("tick",l);return}i=h(1-p/a);let{animatingShapes:s}=this,r=[];for(let e=0,t=d.length;e<t;e++)n=d[e],s.get(n.partial.id)===o&&r.push({id:n.partial.id,type:n.partial.type,...n.values.reduce((e,{prop:t,from:s,to:r})=>(e[t]=s+(r-s)*i,e),{})});this._updateShapes(r,{squashing:!0})};return this.addListener("tick",l),this}groupShapes(e,t=(0,r.F1)()){if(!Array.isArray(e))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;let i="string"==typeof e[0]?e:e.map(e=>e.id);if(i.length<=1)return this;let s=(0,n.oA)(this._getUnlockedShapeIds(i).map(e=>this.getShape(e))),a=s.sort(n.hl).map(e=>e.id),{x:h,y:o}=d.xu.Common((0,n.oA)(s.map(e=>this.getShapePageBounds(e)))).point,p=this.findCommonAncestor(s)??this.getCurrentPageId();if("select"!==this.getCurrentToolId())return this;this.isIn("select.idle")||this.cancel();let l=s.filter(e=>e.parentId===p).sort(n.hl),g=l[l.length-1]?.index;return this.batch(()=>{this.createShapes([{id:t,type:"group",parentId:p,index:g,x:h,y:o,opacity:1,props:{}}]),this.reparentShapes(a,t),this.select(t)}),this}ungroupShapes(e){let t="string"==typeof e[0]?e:e.map(e=>e.id);if(this.getInstanceState().isReadonly||0===t.length||"select"!==this.getCurrentToolId())return this;this.isIn("select.idle")||this.cancel();let i=new Set,s=(0,n.oA)(t.map(e=>this.getShape(e))),r=[];
1return s.forEach(e=>{this.isShapeOfType(e,"group")?r.push(e):i.add(e.id)}),0===r.length||this.batch(()=>{let e;for(let t=0,s=r.length;t<s;t++){e=r[t];let s=this.getSortedChildIdsForParent(e.id);for(let e=0,t=s.length;e<t;e++)i.add(s[e]);this.reparentShapes(s,e.parentId,e.index)}this.deleteShapes(r.map(e=>e.id)),this.select(...i)}),this}updateShape(e,t){return this.updateShapes([e],t),this}updateShapes(e,t){let i=Array(e.length);for(let t=0,s=e.length;t<s;t++){let s=e[t];if(!s)continue;let r=this.getShape(s.id);r&&(!this.isShapeOrAncestorLocked(r)||Object.hasOwn(s,"isLocked"))&&(this.animatingShapes.delete(s.id),i.push(s))}return this._updateShapes(i,t),this}_updateShapes=this.history.createCommand("updateShapes",(e,t)=>{let i,s;if(this.getInstanceState().isReadonly)return null;let r={},n={};for(let t=0,a=e.length;t<a;t++){let a=e[t];a&&(i=this.getShape(a.id))&&(s=X(i,a))!==i&&(r[i.id]=i,n[i.id]=s)}return{data:{snapshots:r,updates:n},...t}},{do:({updates:e})=>{this.store.put((0,n.UM)(e).map(e=>{let t=this.store.get(e.id);if(t){let i=this.getShapeUtil(e).onBeforeUpdate?.(t,e);if(i)return i}return e}))},undo:({snapshots:e})=>{this.store.put(Object.values(e))},squash:(e,t)=>({snapshots:{...t.snapshots,...e.snapshots},updates:{...e.updates,...t.updates}})});_getUnlockedShapeIds(e){return e.filter(e=>!this.getShape(e)?.isLocked)}deleteShapes(e){if(!Array.isArray(e))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");return this._deleteShapes(this._getUnlockedShapeIds("string"==typeof e[0]?e:e.map(e=>e.id))),this}deleteShape(e){return this.deleteShapes(["string"==typeof e?e:e.id]),this}_deleteShapes=this.history.createCommand("delete_shapes",e=>{if(this.getInstanceState().isReadonly||0===e.length)return null;let t=[...this.getCurrentPageState().selectedShapeIds],i=new Set(e);for(let t of e)this.visitDescendants(t,e=>{i.add(e)});let s=[...i],r=this._getArrowBindingsIndex().get(),a=(0,n.oA)(s.flatMap(e=>{let t=this.getShape(e),i=r[e];return i&&i.length>0?i.map(({arrowId:e})=>this.getShape(e)).concat(t):t})),h=t.filter(e=>!i.has(e));return{data:{deletedIds:s,snapshots:a,prevSelectedShapeIds:t,postSelectedShapeIds:h}}},{do:({deletedIds:e,postSelectedShapeIds:t})=>{this.store.remove(e),this.store.update(this.getCurrentPageState().id,e=>({...e,selectedShapeIds:t}))},undo:({snapshots:e,prevSelectedShapeIds:t})=>{this.store.put(e),this.store.update(this.getCurrentPageState().id,e=>({...e,selectedShapeIds:t}))}});_extractSharedStyles(e,t){if(this.isShapeOfType(e,"group")){let i=this._parentIdsToChildIds.get()[e.id];if(i)for(let e=0,s=i.length;e<s;e++)this._extractSharedStyles(this.getShape(i[e]),t)}else for(let[i,s]of this.styleProps[e.type])t.applyValue(i,(0,n.eg)(e.props,s))}_getSelectionSharedStyles(){let e=this.getSelectedShapes(),t=new m.o;for(let i of e)this._extractSharedStyles(i,t);return t}getStyleForNextShape(e){let t=this.getInstanceState().stylesForNextShape[e.id];return void 0===t?e.defaultValue:t}getShapeStyleIfExists(e,t){let i=this.styleProps[e.type].get(t);if(void 0!==i)return(0,n.eg)(e.props,i)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();let e=this.root.getCurrent(),t=new m.o;if(!e)return t;if(e.shapeType)for(let i of this.styleProps[e.shapeType].keys())t.applyValue(i,this.getStyleForNextShape(i));return t}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){let e=[],t=i=>{let s=this.getShape(i);if(s){if(this.isShapeOfType(s,"group"))for(let e of this.getSortedChildIdsForParent(s.id))t(e);else e.push(s)}};for(let e of this.getSelectedShapeIds())t(e);let i=null;for(let t of e)if(null===i)i=t.opacity;else if(i!==t.opacity)return{type:"mixed"};if(null!==i)return{type:"shared",value:i}}return{type:"shared",value:this.getInstanceState().opacityForNextShape}}setOpacityForNextShapes(e,t){return this.updateInstanceState({opacityForNextShape:e},t),this}setOpacityForSelectedShapes(e,t){let i=this.getSelectedShapes();if(i.length>0){let s=[],r=e=>{if(this.isShapeOfType(e,"group"))for(let t of this.getSortedChildIdsForParent(e))r(this.getShape(t));else s.push(e)};for(let e of i)r(e);this.updateShapes(s.map(t=>({id:t.id,type:t.type,opacity:e})),t)}return this}setStyleForNextShapes(e,t,i){let s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[e.id]:t}},i),this}setStyleForSelectedShapes(e,t,i){let s=this.getSelectedShapes();if(s.length>0){let r=[],n=i=>
1{if(this.isShapeOfType(i,"group"))for(let e of this.getSortedChildIdsForParent(i.id))n(this.getShape(e));else{let s=this.getShapeUtil(i),n=this.styleProps[i.type].get(e);if(n){let e={id:i.id,type:i.type,props:{[n]:t}};r.push({util:s,originalShape:i,updatePartial:e})}}};for(let e of s)n(e);this.updateShapes(r.map(({updatePartial:e})=>e),i)}return this}externalAssetContentHandlers={file:null,url:null};registerExternalAssetHandler(e,t){return this.externalAssetContentHandlers[e]=t,this}async getAssetForExternalContent(e){return await this.externalAssetContentHandlers[e.type]?.(e)}externalContentHandlers={text:null,files:null,embed:null,"svg-text":null,url:null};registerExternalContentHandler(e,t){return this.externalContentHandlers[e]=t,this}async putExternalContent(e){return this.externalContentHandlers[e.type]?.(e)}getContentFromCurrentPage(e){let t="string"==typeof e[0]?e:e.map(e=>e.id);if(!t||0===t.length)return;let i={},s=(0,n.D8)(t.map(e=>this.getShape(e)).sort(n.hl).flatMap(e=>{let t=[e];return this.visitDescendants(e.id,e=>{t.push(this.getShape(e))}),t}));s=s.map(e=>{if(i[e.id]=this.getShapePageTransform(e.id),e=(0,n.v4)(e),this.isShapeOfType(e,"arrow")){let t="binding"===e.props.start.type?e.props.start.boundShapeId:void 0,i="binding"===e.props.end.type?e.props.end.boundShapeId:void 0,r=this.getArrowInfo(e);if("binding"===e.props.start.type&&!s.some(e=>e.id===t)){if(r?.isValid){let{x:t,y:i}=r.start.point;e.props.start={type:"point",x:t,y:i}}else{let{start:t}=(0,K.Qs)(this,e);e.props.start={type:"point",x:t.x,y:t.y}}}if("binding"===e.props.end.type&&!s.some(e=>e.id===i)){if(r?.isValid){let{x:t,y:i}=r.end.point;e.props.end={type:"point",x:t,y:i}}else{let{end:t}=(0,K.Qs)(this,e);e.props.end={type:"point",x:t.x,y:t.y}}}let n=(0,K.el)(e)?(0,V.r)(this,e):(0,z.p)(this,e);if(r?.isValid&&n?.isValid&&!(0,K.el)(e)){let t=g.B.Med(r.start.handle,r.end.handle),i=g.B.Dist(r.middle,t),s=g.B.Dist(n.middle,t);e.props.bend<0?e.props.bend+=s-i:e.props.bend-=s-i}}return e});let r=[];s.forEach(e=>{if(void 0===s.find(t=>t.id===e.parentId)){let t=this.getShapePageTransform(e.id),i=t.point(),s=t.rotation();e.x=i.x,e.y=i.y,e.rotation=s,e.parentId=this.getCurrentPageId(),r.push(e.id)}});let a=new Set;return s.forEach(e=>{"assetId"in e.props&&null!==e.props.assetId&&a.add(e.props.assetId)}),{shapes:s,rootShapeIds:r,schema:this.store.schema.serialize(),assets:(0,n.oA)(Array.from(a).map(e=>this.getAsset(e)))}}putContentOntoCurrentPage(e,t={}){if(this.getInstanceState().isReadonly)return this;if(!e.schema)throw Error("Could not put content:\ncontent is missing a schema.");let{select:i=!1,preserveIds:s=!1,preservePosition:a=!1}=t,{point:h}=t,o=this.getCurrentPageId(),{rootShapeIds:u}=e,c=[],S=[],f={store:{...Object.fromEntries(e.assets.map(e=>[e.id,e])),...Object.fromEntries(e.shapes.map(e=>[e.id,e]))},schema:e.schema},m=this.store.schema.migrateStoreSnapshot(f);if("error"===m.type)throw Error("Could not put content: could not migrate content");for(let e of Object.values(m.value))switch(e.typeName){case"asset":c.push(e);break;case"shape":S.push(e)}let y=new Map(S.map(e=>[e.id,(0,r.F1)()])),P=this.getCurrentPageId(),C=1/0,w=[];for(let e of this.getSelectedShapes()){if(0===C)break;let t=this.isShapeOfType(e,"frame"),i=this.getShapeAncestors(e);t&&i.push(e);let s=t?i.length+1:i.length;if(s<C)C=s,w=i,P=t?e.id:e.parentId;else if(s===C){if(w.length!==i.length)throw Error(`Ancestors: ${w.length} !== ${i.length}`);if(0===w.length){P=o;break}P=o;for(let e=0;e<w.length&&i[e]===w[e];e++)P=i[e].id}}let x=!1;if(!(0,r.r5)(P)){let e=this.getShape(P);if(e){if(this.getViewportPageBounds().includes(this.getShapePageBounds(e))){if(1===u.length){let t=S.find(e=>e.id===u[0]);this.isShapeOfType(e,"frame")&&this.isShapeOfType(t,"frame")&&t.props.w===e?.props.w&&t.props.h===e?.props.h&&(x=!0)}}else P=o}else P=o}x||(x=y.has(P)),x&&(P=this.getShape(P).parentId);let _=this.getHighestIndexForParent(P),b=[],v=S.map(e=>{let t;if(s)t=(0,n.p$)(e),y.set(e.id,e.id);else{let i=y.get(e.id);t=(0,n.p$)({...e,id:i})}if(u.includes(e.id)&&(t.parentId=o,b.push(t)),y.has(t.parentId)?t.parentId=y.get(e.parentId):(u.push(t.id),t.index=_,_=(0,n._L)(_)),this.isShapeOfType(t,"arrow")){if("binding"===t.props.start.type){let e=y.get(t.props.start.boundShapeId);t.props.start=e?{...t.props.start,boundShapeId:e}:{type:"point",x:0,y:0}}if("binding"===t.props.end.type){let e=y.get(t.props.end.boundShapeId);t.props.end=e?{...t.props.end,boundShapeId:e}:{type:"point",x:0,y:0}}}return t});if(v.length+this.getCurrentPageShapeIds().size>p.kx)return Y(this),this;let T=[],A=[];return T=c.filter(e=>!this.store.has(e.id)).map(e=>(("image"===e.type||"video"===e.type)&&(e.props.src&&e.props.src?.startsWith("data:image")?(A.push((0,n.v4)(e)),e.props.src=null):A.push((0,n.v4)(e))),e)),Promise.allSettled(A.map(async e=>{let t=await (0,I.B)(e.props.src,e.props.name,e.props.mimeType??"image/png"),i=await this.getAssetForExternalContent({type:"file",file:t});return i?[e,i]:null})).then(e=>{this.updateAssets((0,n.oA)(e.map(e=>"fulfilled"===e.status&&e.value?{...e.value[1],id:e.value[0].id}:void 0)))}),this.batch(()=>{T.length>0&&this.createAssets(T),this.createShapes(v),i&&this.select(...b.map(e=>e.id)),P!==o&&this.reparentShapes(b.map(e=>e.id),P);let e=v.map(e=>this.getShape(e.id)),t=d.xu.Common(e.map(e=>this.getShapePageBounds(e)));if(void 0===h){if((0,r.r5)(P)){let e=this.getViewportPageBounds();h=a||e.includes(d.xu.From(t))?t.center:e.center}else{let e=this.getShape(P);
1h=l._.applyToPoint(this.getShapePageTransform(e),this.getShapeGeometry(e).bounds.center)}}if(1===b.length){let e=b[0];if(this.isShapeOfType(e,"frame"))for(;this.getShapesAtPoint(h).some(t=>this.isShapeOfType(t,"frame")&&t.props.w===e.props.w&&t.props.h===e.props.h);)h.x+=t.w+16}let s=d.xu.Common((0,n.oA)(b.map(({id:e})=>this.getShapePageBounds(e)))).center,p=g.B.Sub(h,s);this.updateShapes(b.map(({id:e})=>{let t=this.getShape(e),i=this.getShapeParentTransform(e).decompose().rotation,s=g.B.Rot(p,-i);return{id:t.id,type:t.type,x:t.x+s.x,y:t.y+s.y}}))}),this}async getSvg(e,t={}){let i="string"==typeof e[0]?e:e.map(e=>e.id);if(0===i.length)return;if(!window.document)throw Error("No document");let{scale:s=1,background:n=!1,padding:a=p.s_,preserveAspectRatio:h=!1}=t,o=t.darkMode??this.user.getIsDarkMode(),d=(0,r.y6)({isDarkMode:o}),l=this.getShapeAndDescendantIds(i),g=this.getUnorderedRenderingShapes(!1).filter(({id:e})=>l.has(e)),u=null;if(t.bounds)u=t.bounds;else for(let{maskedPageBounds:e}of g)e&&(u?u.union(e):u=e.clone());if(!u)return;let c=1===i.length&&this.isShapeOfType(this.getShape(i[0]),"frame")?i[0]:null;c||u.expandBy(a);let S=u.width*s,f=u.height*s,m=window.document.createElementNS("http://www.w3.org/2000/svg","svg");h&&m.setAttribute("preserveAspectRatio",h),m.setAttribute("direction","ltr"),m.setAttribute("width",S+""),m.setAttribute("height",f+""),m.setAttribute("viewBox",`${u.minX} ${u.minY} ${u.width} ${u.height}`),m.setAttribute("stroke-linecap","round"),m.setAttribute("stroke-linejoin","round"),n?c?m.style.setProperty("background",d.solid):m.style.setProperty("background-color",d.background):m.style.setProperty("background-color","transparent");try{document.body.focus?.()}catch(e){}let y=window.document.createElementNS("http://www.w3.org/2000/svg","defs");m.append(y);let I=new Map,P={isDarkMode:o,addExportDef:e=>{if(I.has(e.key))return;let t=(async()=>{let t=await e.getElement();if(!t)return;let i=document.createComment(`def: ${e.key}`);for(let e of(y.appendChild(i),Array.isArray(t)?t:[t]))y.appendChild(e)})();I.set(e.key,t)}},C=(await Promise.all(g.map(async({id:e,opacity:t,index:i,backgroundIndex:s})=>{if(e===c)return[];let r=this.getShape(e);if(this.isShapeOfType(r,"group"))return[];let n=this.getShapeUtil(r),a=await n.toSvg?.(r,P),h=await n.toBackgroundSvg?.(r,P);if(a){let e=document.createElementNS("http://www.w3.org/2000/svg","g");e.appendChild(a),a=e}if(h){let e=document.createElementNS("http://www.w3.org/2000/svg","g");e.appendChild(h),h=e}if(!a&&!h){let e=this.getShapePageBounds(r),t=window.document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("width",e.width+""),t.setAttribute("height",e.height+""),t.setAttribute("fill",d.solid),t.setAttribute("stroke",d.grey.pattern),t.setAttribute("stroke-width","1"),a=t}let o=this.getShapePageTransform(r).toCssString();"scale"in r.props&&1!==r.props.scale&&(o=`${o} scale(${r.props.scale}, ${r.props.scale})`),a?.setAttribute("transform",o),h?.setAttribute("transform",o),a?.setAttribute("opacity",t+""),h?.setAttribute("opacity",t+"");let p=this.getShapeMask(r.id);if(p){let e=document.createElementNS("http://www.w3.org/2000/svg","clipPath");y.appendChild(e);let t=(0,x.E)();e.id=t;let i=document.createElementNS("http://www.w3.org/2000/svg","path");if(i.setAttribute("d",`M${p.map(({x:e,y:t})=>`${e},${t}`).join("L")}Z`),e.appendChild(i),a){let e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("clip-path",`url(#${t})`),e.appendChild(a),a=e}if(h){let e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("clip-path",`url(#${t})`),e.appendChild(h),h=e}}let l=[];return a&&l.push({zIndex:i,element:a}),h&&l.push({zIndex:s,element:h}),l}))).flat();for(let{element:e}of(await Promise.all(I.values()),C.sort((e,t)=>e.zIndex-t.zIndex)))m.appendChild(e);return m}inputs={originPagePoint:new g.B,originScreenPoint:new g.B,previousPagePoint:new g.B,previousScreenPoint:new g.B,currentPagePoint:new g.B,currentScreenPoint:new g.B,keys:new Set,buttons:new Set,isPen:!1,shiftKey:!1,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,pointerVelocity:new g.B};_updateInputsFromEvent(e){let{previousScreenPoint:t,previousPagePoint:i,currentScreenPoint:s,
1currentPagePoint:n}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(r.PQ),{x:h,y:o,z:d}=this.getCamera(),l=e.point.x-a.x,g=e.point.y-a.y,u=e.point.z;t.setTo(s),i.setTo(n),s.set(l,g),n.set(l/d-h,g/d-o,u??.5),this.inputs.isPen="pointer"===e.type&&e.isPen,"pointer_down"===e.name&&this.inputs.pointerVelocity.set(0,0),this.store.put([{id:r.LV,typeName:"pointer",x:n.x,y:n.y,lastActivityTimestamp:"pointer"===e.type&&e.pointerId===p.CK.CAMERA_MOVE?this.store.get(r.LV)?.lastActivityTimestamp??Date.now():Date.now(),meta:{}}])}cancel(){return this.dispatch({type:"misc",name:"cancel"}),this}interrupt(){return this.dispatch({type:"misc",name:"interrupt"}),this}complete(){return this.dispatch({type:"misc",name:"complete"}),this}_clickManager=new T.o(this);cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_prevCursor="default";_shiftKeyTimeout=-1;_setShiftKeyTimeout=()=>{this.inputs.shiftKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Shift",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ShiftLeft"})};_altKeyTimeout=-1;_setAltKeyTimeout=()=>{this.inputs.altKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Alt",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"AltLeft"})};_ctrlKeyTimeout=-1;_setCtrlKeyTimeout=()=>{this.inputs.ctrlKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Ctrl",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ControlLeft"})};_restoreToolId="select";_pinchStart=1;_didPinch=!1;_selectedShapeIdsAtPointerDown=[];capturedPointerId=null;dispatch=e=>{if(this.getCrashingError())return this;let{inputs:t}=this,{type:i}=e;return this.batch(()=>{if("misc"===e.type){("cancel"===e.name||"complete"===e.name)&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}}))),this.root.handleEvent(e);return}e.shiftKey?(clearInterval(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,t.shiftKey=!0):!e.shiftKey&&t.shiftKey&&-1===this._shiftKeyTimeout&&(this._shiftKeyTimeout=setTimeout(this._setShiftKeyTimeout,150)),e.altKey?(clearInterval(this._altKeyTimeout),this._altKeyTimeout=-1,t.altKey=!0):!e.altKey&&t.altKey&&-1===this._altKeyTimeout&&(this._altKeyTimeout=setTimeout(this._setAltKeyTimeout,150)),e.ctrlKey?(clearInterval(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,t.ctrlKey=!0):!e.ctrlKey&&t.ctrlKey&&-1===this._ctrlKeyTimeout&&(this._ctrlKeyTimeout=setTimeout(this._setCtrlKeyTimeout,150));let{originPagePoint:s,originScreenPoint:n,currentPagePoint:a,currentScreenPoint:h}=t;switch(t.isPointing||(t.isDragging=!1),i){case"pinch":if(!this.getInstanceState().canMoveCamera)return;switch(this._updateInputsFromEvent(e),e.name){case"pinch_start":if(t.isPinching)return;t.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds()),this._didPinch=!0,t.isPinching=!0,this.interrupt());return;case"pinch":{if(!t.isPinching)return;let{point:{z:i=1},delta:{x:s,y:n}}=e,{screenBounds:a}=this.store.unsafeGetWithoutCapture(r.PQ),{x:h,y:o}=g.B.SubXY(e.point,a.x,a.y),{x:d,y:l,z:u}=this.getCamera(),c=Math.min(p.sZ,Math.max(p.Zj,i));this.setCamera({x:d+s/u-h/u+h/c,y:l+n/u-o/u+o/c,z:c});return}case"pinch_end":{if(!t.isPinching)return this;t.isPinching=!1;let{_selectedShapeIdsAtPointerDown:e}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown,{squashing:!0}),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,requestAnimationFrame(()=>{this._didPinch||this.setSelectedShapes(e,{squashing:!0})}));return}}case"wheel":if(!this.getInstanceState().canMoveCamera)return;if(this._updateInputsFromEvent(e),this.getIsMenuOpen());else{if(t.ctrlKey){let{x:t,y:i}=this.inputs.currentScreenPoint,{x:s,y:r,z:n}=this.getCamera(),a=Math.min(p.sZ,Math.max(p.Zj,n+(e.delta.z??0)*n));this.setCamera({x:s+(t/a-t)-(t/n-t),y:r+(i/a-i)-(i/n-i),z:a});return}this.pan(e.delta),!t.isDragging&&t.isPointing&&s.dist(a)>(this.getInstanceState().isCoarsePointer?p.UD:p.Sk)/this.getZoomLevel()&&(t.isDragging=!0)}break;case"pointer":{if(t.isPinching)return;this._updateInputsFromEvent(e);let{isPen:i}=e;switch(e.name){case"pointer_down":if(this.clearOpenMenus(),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),0===e.button&&(this.capturedPointerId=e.pointerId),t.buttons.add(e.button),t.isPointing=!0,t.isDragging=!1,this.getInstanceState().isPenMode){if(!i)return}else i&&this.updateInstanceState({isPenMode:!0});if(5===e.button?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):1===e.button&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0),this.inputs.isPanning)return this.stopCameraAnimation(),this.updateInstanceState({cursor:{type:"grabbing",rotation:0}}),this;n.setTo(h),s.setTo(a);break;case"pointer_move":if(!i&&this.getInstanceState().isPenMode)return;if(this.inputs.isPanning&&this.inputs.isPointing){let{currentScreenPoint:e,previousScreenPoint:t}=this.inputs;this.pan(g.B.Sub(e,t));return}!t.isDragging&&t.isPointing&&s.dist(a)>(this.getInstanceState().isCoarsePointer?p.UD:p.Sk)/this.getZoomLevel()&&(t.isDragging=!0);break;case"pointer_up":if(t.buttons.delete(e.button),t.isPointing=!1,t.isDragging=!1,this.getIsMenuOpen()||!i&&this.getInstanceState().isPenMode)return;this.capturedPointerId===e.pointerId&&(this.capturedPointerId=null,e.button=0),t.isPanning?1===e.button?this.inputs.keys.has(" ")?(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:p.$G}),this.updateInstanceState({cursor:{type:"grab",rotation:0}})):(t.isPanning=!1,this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:p.$G}),this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}})):0===e.button&&(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:p.$G}),this.updateInstanceState({cursor:{type:"grab",rotation:0}})):5===e.button&&(this.complete(),this.setCurrentTool(this._restoreToolId))}break}case"keyboard":switch("ShiftRight"===e.key&&(e.key="ShiftLeft"),"AltRight"===e.key&&(e.key="AltLeft"),"ControlRight"===e.code&&(e.code="Control
1Left"),e.name){case"key_down":t.keys.add(e.code),e.ctrlKey||"Space"!==e.code||(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,this.updateInstanceState({cursor:{type:this.inputs.isPointing?"grabbing":"grab",rotation:0}}));break;case"key_up":t.keys.delete(e.code),"Space"!==e.code||this.inputs.buttons.has(1)||(this.inputs.isPanning=!1,this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}}))}}if("pointer"===e.type&&(1===e.button?e.name="middle_click":2===e.button&&(e.name="right_click"),e.isPen===this.getInstanceState().isPenMode))switch(e.name){case"pointer_down":{let t=this._clickManager.transformPointerDownEvent(e);if(e.name!==t.name){this.root.handleEvent(e),this.emit("event",e),this.root.handleEvent(t),this.emit("event",t);return}break}case"pointer_up":{let t=this._clickManager.transformPointerUpEvent(e);if(e.name!==t.name){this.root.handleEvent(e),this.emit("event",e),this.root.handleEvent(t),this.emit("event",t);return}break}case"pointer_move":this._clickManager.handleMove()}this.root.handleEvent(e),this.emit("event",e)}),this}}function Y(e,t=e.getCurrentPageId()){let i=e.getPage(t).name;e.emit("max-shapes",{name:i,pageId:t,count:p.kx})}function X(e,t){if(!t)return e;let i=null,s=Object.entries(t);for(let t=0,r=s.length;t<r;t++){let[r,n]=s[t];if(void 0!==n&&"id"!==r&&"type"!==r&&"typeName"!==r&&n!==e[r]){if(i||(i={...e}),"props"===r||"meta"===r){for(let[t,s]of(i[r]={...e[r]},Object.entries(n)))void 0!==s&&(i[r][t]=s);continue}i[r]=n}}return i||e}D([s.Fl],N.prototype,"getCanUndo",1),D([s.Fl],N.prototype,"getCanRedo",1),D([s.Fl],N.prototype,"_getArrowBindingsIndex",1),D([s.Fl],N.prototype,"getArrowInfoCache",1),D([s.Fl],N.prototype,"getPath",1),D([s.Fl],N.prototype,"getCurrentTool",1),D([s.Fl],N.prototype,"getCurrentToolId",1),D([s.Fl],N.prototype,"getDocumentSettings",1),D([s.Fl],N.prototype,"getInstanceState",1),D([s.Fl],N.prototype,"getOpenMenus",1),D([s.Fl],N.prototype,"getIsMenuOpen",1),D([s.Fl],N.prototype,"getPageStates",1),D([s.Fl],N.prototype,"_getPageStatesQuery",1),D([s.Fl],N.prototype,"getCurrentPageState",1),D([s.Fl],N.prototype,"_getCurrentPageStateId",1),D([s.Fl],N.prototype,"getSelectedShapeIds",1),D([s.Fl],N.prototype,"getSelectedShapes",1),D([s.Fl],N.prototype,"getOnlySelectedShape",1),D([s.Fl],N.prototype,"getSelectionPageBounds",1),D([s.Fl],N.prototype,"getSelectionRotation",1),D([s.Fl],N.prototype,"getSelectionRotatedPageBounds",1),D([s.Fl],N.prototype,"getFocusedGroupId",1),D([s.Fl],N.prototype,"getFocusedGroup",1),D([s.Fl],N.prototype,"getEditingShapeId",1),D([s.Fl],N.prototype,"getEditingShape",1),D([s.Fl],N.prototype,"getHoveredShapeId",1),D([s.Fl],N.prototype,"getHoveredShape",1),D([s.Fl],N.prototype,"getHintingShapeIds",1),D([s.Fl],N.prototype,"getHintingShape",1),D([s.Fl],N.prototype,"getErasingShapeIds",1),D([s.Fl],N.prototype,"getErasingShapes",1),D([s.Fl],N.prototype,"getCameraId",1),D([s.Fl],N.prototype,"getCamera",1),D([s.Fl],N.prototype,"getZoomLevel",1),D([s.Fl],N.prototype,"getViewportScreenBounds",1),D([s.Fl],N.prototype,"getViewportScreenCenter",1),D([s.Fl],N.prototype,"getViewportPageBounds",1),D([s.Fl],N.prototype,"getViewportPageCenter",1),D([s.Fl],N.prototype,"getRenderingShapes",1),D([s.Fl],N.prototype,"_getAllPagesQuery",1),D([s.Fl],N.prototype,"getPages",1),D([s.Fl],N.prototype,"_getAllAssetsQuery",1),D([s.Fl],N.prototype,"_getShapeGeometryCache",1),D([s.Fl],N.prototype,"_getShapeHandlesCache",1),D([s.Fl],N.prototype,"_getShapePageTransformCache",1),D([s.Fl],N.prototype,"_getShapePageBoundsCache",1),D([s.Fl],N.prototype,"_getShapeClipPathCache",1),D([s.Fl],N.prototype,"_getShapeMaskCache",1),D([s.Fl],N.prototype,"getCurrentPageBounds",1),D([s.Fl],N.prototype,"getCurrentPageShapes",1),D([s.Fl],N.prototype,"getCurrentPageShapesSorted",1),D([s.Fl],N.prototype,"getCurrentPageRenderingShapesSorted",1),D([s.Fl],N.prototype,"_getSelectionSharedStyles",1),D([(0,s.Fl)({isEqual:(e,t)=>e.equals(t)})],N.prototype,"getSharedStyles",1),D([s.Fl],N.prototype,"getSharedOpacity",1)}}]);
2//# sourceMappingURL=ab16df01.6591518370ed49e8.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.