@kitschpatrol/tldraw-cli 4.6.10 → 4.6.11
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.
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
var y3=Object.defineProperty;var S3=(e,t,n)=>t in e?y3(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var g=(e,t,n)=>S3(e,typeof t!="symbol"?t+"":t,n);function v3(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in e)){const o=Object.getOwnPropertyDescriptor(r,s);o&&Object.defineProperty(e,s,o.get?o:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();var cn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ni(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var SE={exports:{}},jf={},vE={exports:{}},Ie={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ru=Symbol.for("react.element"),x3=Symbol.for("react.portal"),w3=Symbol.for("react.fragment"),b3=Symbol.for("react.strict_mode"),P3=Symbol.for("react.profiler"),C3=Symbol.for("react.provider"),I3=Symbol.for("react.context"),E3=Symbol.for("react.forward_ref"),k3=Symbol.for("react.suspense"),_3=Symbol.for("react.memo"),T3=Symbol.for("react.lazy"),N1=Symbol.iterator;function M3(e){return e===null||typeof e!="object"?null:(e=N1&&e[N1]||e["@@iterator"],typeof e=="function"?e:null)}var xE={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},wE=Object.assign,bE={};function bl(e,t,n){this.props=e,this.context=t,this.refs=bE,this.updater=n||xE}bl.prototype.isReactComponent={};bl.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};bl.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function PE(){}PE.prototype=bl.prototype;function lx(e,t,n){this.props=e,this.context=t,this.refs=bE,this.updater=n||xE}var cx=lx.prototype=new PE;cx.constructor=lx;wE(cx,bl.prototype);cx.isPureReactComponent=!0;var F1=Array.isArray,CE=Object.prototype.hasOwnProperty,ux={current:null},IE={key:!0,ref:!0,__self:!0,__source:!0};function EE(e,t,n){var r,s={},o=null,i=null;if(t!=null)for(r in t.ref!==void 0&&(i=t.ref),t.key!==void 0&&(o=""+t.key),t)CE.call(t,r)&&!IE.hasOwnProperty(r)&&(s[r]=t[r]);var a=arguments.length-2;if(a===1)s.children=n;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];s.children=l}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)s[r]===void 0&&(s[r]=a[r]);return{$$typeof:Ru,type:e,key:o,ref:i,props:s,_owner:ux.current}}function A3(e,t){return{$$typeof:Ru,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function dx(e){return typeof e=="object"&&e!==null&&e.$$typeof===Ru}function j3(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(n){return t[n]})}var z1=/\/+/g;function Zg(e,t){return typeof e=="object"&&e!==null&&e.key!=null?j3(""+e.key):t.toString(36)}function Ph(e,t,n,r,s){var o=typeof e;(o==="undefined"||o==="boolean")&&(e=null);var i=!1;if(e===null)i=!0;else switch(o){case"string":case"number":i=!0;break;case"object":switch(e.$$typeof){case Ru:case x3:i=!0}}if(i)return i=e,s=s(i),e=r===""?"."+Zg(i,0):r,F1(s)?(n="",e!=null&&(n=e.replace(z1,"$&/")+"/"),Ph(s,t,n,"",function(c){return c})):s!=null&&(dx(s)&&(s=A3(s,n+(!s.key||i&&i.key===s.key?"":(""+s.key).replace(z1,"$&/")+"/")+e)),t.push(s)),1;if(i=0,r=r===""?".":r+":",F1(e))for(var a=0;a<e.length;a++){o=e[a];var l=r+Zg(o,a);i+=Ph(o,t,n,l,s)}else if(l=M3(e),typeof l=="function")for(e=l.call(e),a=0;!(o=e.next()).done;)o=o.value,l=r+Zg(o,a++),i+=Ph(o,t,n,l,s);else if(o==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return i}function vd(e,t,n){if(e==null)return e;var r=[],s=0;return Ph(e,r,"","",function(o){return t.call(n,o,s++)}),r}function O3(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(n){(e._status===0||e._status===-1)&&(e._status=1,e._result=n)},function(n){(e._status===0||e._status===-1)&&(e._status=2,e._result=n)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var xn={current:null},Ch={transition:null},D3={ReactCurrentDispatcher:xn,ReactCurrentBatchConfig:Ch,ReactCurrentOwner:ux};function kE(){throw Error("act(...) is not supported in production builds of React.")}Ie.Children={map:vd,forEach:function(e,t,n){vd(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return vd(e,function(){t++}),t},toArray:function(e){return vd(e,function(t){return t})||[]},only:function(e){if(!dx(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};Ie.Component=bl;Ie.Fragment=w3;Ie.Profiler=P3;Ie.PureComponent=lx;Ie.StrictMode=b3;Ie.Suspense=k3;Ie.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=D3;Ie.act=kE;Ie.cloneElement=function(e,t,n){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=wE({},e.props),s=e.key,o=e.ref,i=e._owner;if(t!=null){if(t.ref!==void 0&&(o=t.ref,i=ux.current),t.key!==void 0&&(s=""+t.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in t)CE.call(t,l)&&!IE.hasOwnProperty(l)&&(r[l]=t[l]===void 0&&a!==void 0?a[l]:t[l])}var l=arguments.length-2;if(l===1)r.children=n;else if(1<l){a=Array(l);for(var c=0;c<l;c++)a[c]=arguments[c+2];r.children=a}return{$$typeof:Ru,type:e.type,key:s,ref:o,props:r,_owner:i}};Ie.createContext=function(e){return e={$$typeof:I3,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:C3,_context:e},e.Consumer=e};Ie.createElement=EE;Ie.createFactory=function(e){var t=EE.bind(null,e);return t.type=e,t};Ie.createRef=function(){return{current:null}};Ie.forwardRef=function(e){return{$$typeof:E3,render:e}};Ie.isValidElement=dx;Ie.lazy=function(e){return{$$typeof:T3,_payload:{_status:-1,_result:e},_init:O3}};Ie.memo=function(e,t){return{$$typeof:_3,type:e,compare:t===void 0?null:t}};Ie.startTransition=function(e){var t=Ch.transition;Ch.transition={};try{e()}finally{Ch.transition=t}};Ie.unstable_act=kE;Ie.useCallback=function(e,t){return xn.current.useCallback(e,t)};Ie.useContext=function(e){return xn.current.useContext(e)};Ie.useDebugValue=function(){};Ie.useDeferredValue=function(e){return xn.current.useDeferredValue(e)};Ie.useEffect=function(e,t){return xn.current.useEffect(e,t)};Ie.useId=function(){return xn.current.useId()};Ie.useImperativeHandle=function(e,t,n){return xn.current.useImperativeHandle(e,t,n)};Ie.useInsertionEffect=function(e,t){return xn.current.useInsertionEffect(e,t)};Ie.useLayoutEffect=function(e,t){return xn.current.useLayoutEffect(e,t)};Ie.useMemo=function(e,t){return xn.current.useMemo(e,t)};Ie.useReducer=function(e,t,n){return xn.current.useReducer(e,t,n)};Ie.useRef=function(e){return xn.current.useRef(e)};Ie.useState=function(e){return xn.current.useState(e)};Ie.useSyncExternalStore=function(e,t,n){return xn.current.useSyncExternalStore(e,t,n)};Ie.useTransition=function(){return xn.current.useTransition()};Ie.version="18.3.1";vE.exports=Ie;var P=vE.exports;const Ce=ni(P),R3=v3({__proto__:null,default:Ce},[P]);/**
|
|
10
|
-
* @license React
|
|
11
|
-
* react-jsx-runtime.production.min.js
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var L3=P,$3=Symbol.for("react.element"),N3=Symbol.for("react.fragment"),F3=Object.prototype.hasOwnProperty,z3=L3.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,B3={key:!0,ref:!0,__self:!0,__source:!0};function _E(e,t,n){var r,s={},o=null,i=null;n!==void 0&&(o=""+n),t.key!==void 0&&(o=""+t.key),t.ref!==void 0&&(i=t.ref);for(r in t)F3.call(t,r)&&!B3.hasOwnProperty(r)&&(s[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)s[r]===void 0&&(s[r]=t[r]);return{$$typeof:$3,type:e,key:o,ref:i,props:s,_owner:z3.current}}jf.Fragment=N3;jf.jsx=_E;jf.jsxs=_E;SE.exports=jf;var d=SE.exports;function ie(e,t={}){const n=typeof e=="string"?e:e.src;if(typeof t=="function")return t(n);const{baseUrl:r=""}=t;return n.startsWith("data:")||n.match(/^https?:\/\//)?n:`${r.replace(/\/$/,"")}/${n.replace(/^\.?\//,"")}`}function U3(e){const t=ie("./icons/icon/0_merged.svg",e);return{fonts:{monospace:ie("./fonts/IBMPlexMono-Medium.woff2",e),sansSerif:ie("./fonts/IBMPlexSans-Medium.woff2",e),serif:ie("./fonts/IBMPlexSerif-Medium.woff2",e),draw:ie("./fonts/Shantell_Sans-Tldrawish.woff2",e)},icons:{"align-bottom":t+"#align-bottom","align-center-horizontal":t+"#align-center-horizontal","align-center-vertical":t+"#align-center-vertical","align-left":t+"#align-left","align-right":t+"#align-right","align-top":t+"#align-top","arrow-left":t+"#arrow-left","arrowhead-arrow":t+"#arrowhead-arrow","arrowhead-bar":t+"#arrowhead-bar","arrowhead-diamond":t+"#arrowhead-diamond","arrowhead-dot":t+"#arrowhead-dot","arrowhead-none":t+"#arrowhead-none","arrowhead-square":t+"#arrowhead-square","arrowhead-triangle-inverted":t+"#arrowhead-triangle-inverted","arrowhead-triangle":t+"#arrowhead-triangle",blob:t+"#blob","bring-forward":t+"#bring-forward","bring-to-front":t+"#bring-to-front",broken:t+"#broken","check-circle":t+"#check-circle",check:t+"#check","chevron-down":t+"#chevron-down","chevron-left":t+"#chevron-left","chevron-right":t+"#chevron-right","chevron-up":t+"#chevron-up","chevrons-ne":t+"#chevrons-ne","chevrons-sw":t+"#chevrons-sw","clipboard-copied":t+"#clipboard-copied","clipboard-copy":t+"#clipboard-copy",color:t+"#color","cross-2":t+"#cross-2","cross-circle":t+"#cross-circle","dash-dashed":t+"#dash-dashed","dash-dotted":t+"#dash-dotted","dash-draw":t+"#dash-draw","dash-solid":t+"#dash-solid",disconnected:t+"#disconnected",discord:t+"#discord","distribute-horizontal":t+"#distribute-horizontal","distribute-vertical":t+"#distribute-vertical",dot:t+"#dot","dots-horizontal":t+"#dots-horizontal","dots-vertical":t+"#dots-vertical","drag-handle-dots":t+"#drag-handle-dots",duplicate:t+"#duplicate",edit:t+"#edit","external-link":t+"#external-link","fill-fill":t+"#fill-fill","fill-none":t+"#fill-none","fill-pattern":t+"#fill-pattern","fill-semi":t+"#fill-semi","fill-solid":t+"#fill-solid",follow:t+"#follow",following:t+"#following","font-draw":t+"#font-draw","font-mono":t+"#font-mono","font-sans":t+"#font-sans","font-serif":t+"#font-serif","geo-arrow-down":t+"#geo-arrow-down","geo-arrow-left":t+"#geo-arrow-left","geo-arrow-right":t+"#geo-arrow-right","geo-arrow-up":t+"#geo-arrow-up","geo-check-box":t+"#geo-check-box","geo-cloud":t+"#geo-cloud","geo-diamond":t+"#geo-diamond","geo-ellipse":t+"#geo-ellipse","geo-heart":t+"#geo-heart","geo-hexagon":t+"#geo-hexagon","geo-octagon":t+"#geo-octagon","geo-oval":t+"#geo-oval","geo-pentagon":t+"#geo-pentagon","geo-rectangle":t+"#geo-rectangle","geo-rhombus-2":t+"#geo-rhombus-2","geo-rhombus":t+"#geo-rhombus","geo-star":t+"#geo-star","geo-trapezoid":t+"#geo-trapezoid","geo-triangle":t+"#geo-triangle","geo-x-box":t+"#geo-x-box",github:t+"#github",group:t+"#group","horizontal-align-end":t+"#horizontal-align-end","horizontal-align-middle":t+"#horizontal-align-middle","horizontal-align-start":t+"#horizontal-align-start","info-circle":t+"#info-circle",leading:t+"#leading",link:t+"#link",lock:t+"#lock",menu:t+"#menu",minus:t+"#minus",mixed:t+"#mixed",pack:t+"#pack",plus:t+"#plus","question-mark-circle":t+"#question-mark-circle","question-mark":t+"#question-mark",redo:t+"#redo","reset-zoom":t+"#reset-zoom","rotate-ccw":t+"#rotate-ccw","rotate-cw":t+"#rotate-cw","send-backward":t+"#send-backward","send-to-back":t+"#send-to-back","share-1":t+"#share-1","size-extra-large":t+"#size-extra-large","size-large":t+"#size-large","size-medium":t+"#size-medium","size-small":t+"#size-small","spline-cubic":t+"#spline-cubic","spline-line":t+"#spline-line","stack-horizontal":t+"#stack-horizontal","stack-vertical":t+"#stack-vertical","status-offline":t+"#status-offline","stretch-horizontal":t+"#stretch-horizontal","stretch-vertical":t+"#stretch-vertical","text-align-center":t+"#text-align-center","text-align-left":t+"#text-align-left","text-align-right":t+"#text-align-right","toggle-off":t+"#toggle-off","toggle-on":t+"#toggle-on","tool-arrow":t+"#tool-arrow","tool-eraser":t+"#tool-eraser","tool-frame":t+"#tool-frame","tool-hand":t+"#tool-hand","tool-highlight":t+"#tool-highlight","tool-laser":t+"#tool-laser","tool-line":t+"#tool-line","tool-media":t+"#tool-media","tool-note":t+"#tool-note","tool-pencil":t+"#tool-pencil","tool-pointer":t+"#tool-pointer","tool-screenshot":t+"#tool-screenshot","tool-text":t+"#tool-text",trash:t+"#trash",twitter:t+"#twitter",undo:t+"#undo",ungroup:t+"#ungroup",unlock:t+"#unlock","vertical-align-end":t+"#vertical-align-end","vertical-align-middle":t+"#vertical-align-middle","vertical-align-start":t+"#vertical-align-start","warning-triangle":t+"#warning-triangle","zoom-in":t+"#zoom-in","zoom-out":t+"#zoom-out"},translations:{ar:ie("./translations/ar.json",e),ca:ie("./translations/ca.json",e),cs:ie("./translations/cs.json",e),da:ie("./translations/da.json",e),de:ie("./translations/de.json",e),en:ie("./translations/en.json",e),es:ie("./translations/es.json",e),fa:ie("./translations/fa.json",e),fi:ie("./translations/fi.json",e),fr:ie("./translations/fr.json",e),gl:ie("./translations/gl.json",e),he:ie("./translations/he.json",e),"hi-in":ie("./translations/hi-in.json",e),hr:ie("./translations/hr.json",e),hu:ie("./translations/hu.json",e),id:ie("./translations/id.json",e),it:ie("./translations/it.json",e),ja:ie("./translations/ja.json",e),"ko-kr":ie("./translations/ko-kr.json",e),ku:ie("./translations/ku.json",e),languages:ie("./translations/languages.json",e),main:ie("./translations/main.json",e),my:ie("./translations/my.json",e),ne:ie("./translations/ne.json",e),no:ie("./translations/no.json",e),pl:ie("./translations/pl.json",e),"pt-br":ie("./translations/pt-br.json",e),"pt-pt":ie("./translations/pt-pt.json",e),ro:ie("./translations/ro.json",e),ru:ie("./translations/ru.json",e),sl:ie("./translations/sl.json",e),sv:ie("./translations/sv.json",e),te:ie("./translations/te.json",e),th:ie("./translations/th.json",e),tr:ie("./translations/tr.json",e),uk:ie("./translations/uk.json",e),vi:ie("./translations/vi.json",e),"zh-cn":ie("./translations/zh-cn.json",e),"zh-tw":ie("./translations/zh-tw.json",e)},embedIcons:{codepen:ie("./embed-icons/codepen.png",e),codesandbox:ie("./embed-icons/codesandbox.png",e),desmos:ie("./embed-icons/desmos.png",e),excalidraw:ie("./embed-icons/excalidraw.png",e),felt:ie("./embed-icons/felt.png",e),figma:ie("./embed-icons/figma.png",e),github_gist:ie("./embed-icons/github_gist.png",e),google_calendar:ie("./embed-icons/google_calendar.png",e),google_maps:ie("./embed-icons/google_maps.png",e),google_slides:ie("./embed-icons/google_slides.png",e),observable:ie("./embed-icons/observable.png",e),replit:ie("./embed-icons/replit.png",e),scratch:ie("./embed-icons/scratch.png",e),spotify:ie("./embed-icons/spotify.png",e),tldraw:ie("./embed-icons/tldraw.png",e),val_town:ie("./embed-icons/val_town.png",e),vimeo:ie("./embed-icons/vimeo.png",e),youtube:ie("./embed-icons/youtube.png",e)}}}var Hl=function(e){return e&&e.Math===Math&&e},Gn=Hl(typeof globalThis=="object"&&globalThis)||Hl(typeof window=="object"&&window)||Hl(typeof self=="object"&&self)||Hl(typeof cn=="object"&&cn)||Hl(typeof cn=="object"&&cn)||function(){return this}()||Function("return this")(),hx={},wn=function(e){try{return!!e()}catch{return!0}},H3=wn,ri=!H3(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),K3=wn,Of=!K3(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),W3=Of,xd=Function.prototype.call,io=W3?xd.bind(xd):function(){return xd.apply(xd,arguments)},TE={},ME={}.propertyIsEnumerable,AE=Object.getOwnPropertyDescriptor,G3=AE&&!ME.call({1:2},1);TE.f=G3?function(t){var n=AE(this,t);return!!n&&n.enumerable}:ME;var jE=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},OE=Of,DE=Function.prototype,sS=DE.call,V3=OE&&DE.bind.bind(sS,sS),Rt=OE?V3:function(e){return function(){return sS.apply(e,arguments)}},RE=Rt,Y3=RE({}.toString),X3=RE("".slice),Pl=function(e){return X3(Y3(e),8,-1)},q3=Rt,Z3=wn,Q3=Pl,Qg=Object,J3=q3("".split),e5=Z3(function(){return!Qg("z").propertyIsEnumerable(0)})?function(e){return Q3(e)==="String"?J3(e,""):Qg(e)}:Qg,Df=function(e){return e==null},t5=Df,n5=TypeError,Cl=function(e){if(t5(e))throw new n5("Can't call method on "+e);return e},r5=e5,s5=Cl,Rf=function(e){return r5(s5(e))},Jg=typeof document=="object"&&document.all,bn=typeof Jg>"u"&&Jg!==void 0?function(e){return typeof e=="function"||e===Jg}:function(e){return typeof e=="function"},o5=bn,ea=function(e){return typeof e=="object"?e!==null:o5(e)},em=Gn,i5=bn,a5=function(e){return i5(e)?e:void 0},Lf=function(e,t){return arguments.length<2?a5(em[e]):em[e]&&em[e][t]},l5=Rt,LE=l5({}.isPrototypeOf),c5=typeof navigator<"u"&&String(navigator.userAgent)||"",$E=Gn,tm=c5,B1=$E.process,U1=$E.Deno,H1=B1&&B1.versions||U1&&U1.version,K1=H1&&H1.v8,Nr,vp;K1&&(Nr=K1.split("."),vp=Nr[0]>0&&Nr[0]<4?1:+(Nr[0]+Nr[1]));!vp&&tm&&(Nr=tm.match(/Edge\/(\d+)/),(!Nr||Nr[1]>=74)&&(Nr=tm.match(/Chrome\/(\d+)/),Nr&&(vp=+Nr[1])));var u5=vp,W1=u5,d5=wn,h5=Gn,p5=h5.String,NE=!!Object.getOwnPropertySymbols&&!d5(function(){var e=Symbol("symbol detection");return!p5(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&W1&&W1<41}),f5=NE,FE=f5&&!Symbol.sham&&typeof Symbol.iterator=="symbol",g5=Lf,m5=bn,y5=LE,S5=FE,v5=Object,zE=S5?function(e){return typeof e=="symbol"}:function(e){var t=g5("Symbol");return m5(t)&&y5(t.prototype,v5(e))},x5=String,w5=function(e){try{return x5(e)}catch{return"Object"}},b5=bn,P5=w5,C5=TypeError,px=function(e){if(b5(e))return e;throw new C5(P5(e)+" is not a function")},I5=px,E5=Df,fx=function(e,t){var n=e[t];return E5(n)?void 0:I5(n)},nm=io,rm=bn,sm=ea,k5=TypeError,_5=function(e,t){var n,r;if(t==="string"&&rm(n=e.toString)&&!sm(r=nm(n,e))||rm(n=e.valueOf)&&!sm(r=nm(n,e))||t!=="string"&&rm(n=e.toString)&&!sm(r=nm(n,e)))return r;throw new k5("Can't convert object to primitive value")},BE={exports:{}},G1=Gn,T5=Object.defineProperty,gx=function(e,t){try{T5(G1,e,{value:t,configurable:!0,writable:!0})}catch{G1[e]=t}return t},M5=Gn,A5=gx,V1="__core-js_shared__",Y1=BE.exports=M5[V1]||A5(V1,{});(Y1.versions||(Y1.versions=[])).push({version:"3.37.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.37.1/LICENSE",source:"https://github.com/zloirock/core-js"});var mx=BE.exports,X1=mx,yx=function(e,t){return X1[e]||(X1[e]=t||{})},j5=Cl,O5=Object,Lu=function(e){return O5(j5(e))},D5=Rt,R5=Lu,L5=D5({}.hasOwnProperty),si=Object.hasOwn||function(t,n){return L5(R5(t),n)},$5=Rt,N5=0,F5=Math.random(),z5=$5(1 .toString),UE=function(e){return"Symbol("+(e===void 0?"":e)+")_"+z5(++N5+F5,36)},B5=Gn,U5=yx,q1=si,H5=UE,K5=NE,W5=FE,Ia=B5.Symbol,om=U5("wks"),G5=W5?Ia.for||Ia:Ia&&Ia.withoutSetter||H5,ao=function(e){return q1(om,e)||(om[e]=K5&&q1(Ia,e)?Ia[e]:G5("Symbol."+e)),om[e]},V5=io,Z1=ea,Q1=zE,Y5=fx,X5=_5,q5=ao,Z5=TypeError,Q5=q5("toPrimitive"),J5=function(e,t){if(!Z1(e)||Q1(e))return e;var n=Y5(e,Q5),r;if(n){if(t===void 0&&(t="default"),r=V5(n,e,t),!Z1(r)||Q1(r))return r;throw new Z5("Can't convert object to primitive value")}return t===void 0&&(t="number"),X5(e,t)},e$=J5,t$=zE,HE=function(e){var t=e$(e,"string");return t$(t)?t:t+""},n$=Gn,J1=ea,oS=n$.document,r$=J1(oS)&&J1(oS.createElement),KE=function(e){return r$?oS.createElement(e):{}},s$=ri,o$=wn,i$=KE,WE=!s$&&!o$(function(){return Object.defineProperty(i$("div"),"a",{get:function(){return 7}}).a!==7}),a$=ri,l$=io,c$=TE,u$=jE,d$=Rf,h$=HE,p$=si,f$=WE,eb=Object.getOwnPropertyDescriptor;hx.f=a$?eb:function(t,n){if(t=d$(t),n=h$(n),f$)try{return eb(t,n)}catch{}if(p$(t,n))return u$(!l$(c$.f,t,n),t[n])};var Il={},g$=ri,m$=wn,GE=g$&&m$(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),y$=ea,S$=String,v$=TypeError,ta=function(e){if(y$(e))return e;throw new v$(S$(e)+" is not an object")},x$=ri,w$=WE,b$=GE,wd=ta,tb=HE,P$=TypeError,im=Object.defineProperty,C$=Object.getOwnPropertyDescriptor,am="enumerable",lm="configurable",cm="writable";Il.f=x$?b$?function(t,n,r){if(wd(t),n=tb(n),wd(r),typeof t=="function"&&n==="prototype"&&"value"in r&&cm in r&&!r[cm]){var s=C$(t,n);s&&s[cm]&&(t[n]=r.value,r={configurable:lm in r?r[lm]:s[lm],enumerable:am in r?r[am]:s[am],writable:!1})}return im(t,n,r)}:im:function(t,n,r){if(wd(t),n=tb(n),wd(r),w$)try{return im(t,n,r)}catch{}if("get"in r||"set"in r)throw new P$("Accessors not supported");return"value"in r&&(t[n]=r.value),t};var I$=ri,E$=Il,k$=jE,Sx=I$?function(e,t,n){return E$.f(e,t,k$(1,n))}:function(e,t,n){return e[t]=n,e},VE={exports:{}},iS=ri,_$=si,YE=Function.prototype,T$=iS&&Object.getOwnPropertyDescriptor,vx=_$(YE,"name"),M$=vx&&(function(){}).name==="something",A$=vx&&(!iS||iS&&T$(YE,"name").configurable),j$={EXISTS:vx,PROPER:M$,CONFIGURABLE:A$},O$=Rt,D$=bn,aS=mx,R$=O$(Function.toString);D$(aS.inspectSource)||(aS.inspectSource=function(e){return R$(e)});var XE=aS.inspectSource,L$=Gn,$$=bn,nb=L$.WeakMap,N$=$$(nb)&&/native code/.test(String(nb)),F$=yx,z$=UE,rb=F$("keys"),qE=function(e){return rb[e]||(rb[e]=z$(e))},xx={},B$=N$,ZE=Gn,U$=ea,H$=Sx,um=si,dm=mx,K$=qE,W$=xx,sb="Object already initialized",lS=ZE.TypeError,G$=ZE.WeakMap,xp,eu,wp,V$=function(e){return wp(e)?eu(e):xp(e,{})},Y$=function(e){return function(t){var n;if(!U$(t)||(n=eu(t)).type!==e)throw new lS("Incompatible receiver, "+e+" required");return n}};if(B$||dm.state){var ns=dm.state||(dm.state=new G$);ns.get=ns.get,ns.has=ns.has,ns.set=ns.set,xp=function(e,t){if(ns.has(e))throw new lS(sb);return t.facade=e,ns.set(e,t),t},eu=function(e){return ns.get(e)||{}},wp=function(e){return ns.has(e)}}else{var ua=K$("state");W$[ua]=!0,xp=function(e,t){if(um(e,ua))throw new lS(sb);return t.facade=e,H$(e,ua,t),t},eu=function(e){return um(e,ua)?e[ua]:{}},wp=function(e){return um(e,ua)}}var QE={set:xp,get:eu,has:wp,enforce:V$,getterFor:Y$},wx=Rt,X$=wn,q$=bn,bd=si,cS=ri,Z$=j$.CONFIGURABLE,Q$=XE,JE=QE,J$=JE.enforce,eN=JE.get,ob=String,Ih=Object.defineProperty,tN=wx("".slice),nN=wx("".replace),rN=wx([].join),sN=cS&&!X$(function(){return Ih(function(){},"length",{value:8}).length!==8}),oN=String(String).split("String"),iN=VE.exports=function(e,t,n){tN(ob(t),0,7)==="Symbol("&&(t="["+nN(ob(t),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(t="get "+t),n&&n.setter&&(t="set "+t),(!bd(e,"name")||Z$&&e.name!==t)&&(cS?Ih(e,"name",{value:t,configurable:!0}):e.name=t),sN&&n&&bd(n,"arity")&&e.length!==n.arity&&Ih(e,"length",{value:n.arity});try{n&&bd(n,"constructor")&&n.constructor?cS&&Ih(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=J$(e);return bd(r,"source")||(r.source=rN(oN,typeof t=="string"?t:"")),e};Function.prototype.toString=iN(function(){return q$(this)&&eN(this).source||Q$(this)},"toString");var aN=VE.exports,lN=bn,cN=Il,uN=aN,dN=gx,ek=function(e,t,n,r){r||(r={});var s=r.enumerable,o=r.name!==void 0?r.name:t;if(lN(n)&&uN(n,o,r),r.global)s?e[t]=n:dN(t,n);else{try{r.unsafe?e[t]&&(s=!0):delete e[t]}catch{}s?e[t]=n:cN.f(e,t,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},tk={},hN=Math.ceil,pN=Math.floor,fN=Math.trunc||function(t){var n=+t;return(n>0?pN:hN)(n)},gN=fN,na=function(e){var t=+e;return t!==t||t===0?0:gN(t)},mN=na,yN=Math.max,SN=Math.min,vN=function(e,t){var n=mN(e);return n<0?yN(n+t,0):SN(n,t)},xN=na,wN=Math.min,nk=function(e){var t=xN(e);return t>0?wN(t,9007199254740991):0},bN=nk,$u=function(e){return bN(e.length)},PN=Rf,CN=vN,IN=$u,ib=function(e){return function(t,n,r){var s=PN(t),o=IN(s);if(o===0)return!e&&-1;var i=CN(r,o),a;if(e&&n!==n){for(;o>i;)if(a=s[i++],a!==a)return!0}else for(;o>i;i++)if((e||i in s)&&s[i]===n)return e||i||0;return!e&&-1}},EN={includes:ib(!0),indexOf:ib(!1)},kN=Rt,hm=si,_N=Rf,TN=EN.indexOf,MN=xx,ab=kN([].push),rk=function(e,t){var n=_N(e),r=0,s=[],o;for(o in n)!hm(MN,o)&&hm(n,o)&&ab(s,o);for(;t.length>r;)hm(n,o=t[r++])&&(~TN(s,o)||ab(s,o));return s},bx=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],AN=rk,jN=bx,ON=jN.concat("length","prototype");tk.f=Object.getOwnPropertyNames||function(t){return AN(t,ON)};var sk={};sk.f=Object.getOwnPropertySymbols;var DN=Lf,RN=Rt,LN=tk,$N=sk,NN=ta,FN=RN([].concat),zN=DN("Reflect","ownKeys")||function(t){var n=LN.f(NN(t)),r=$N.f;return r?FN(n,r(t)):n},lb=si,BN=zN,UN=hx,HN=Il,KN=function(e,t,n){for(var r=BN(t),s=HN.f,o=UN.f,i=0;i<r.length;i++){var a=r[i];!lb(e,a)&&!(n&&lb(n,a))&&s(e,a,o(t,a))}},WN=wn,GN=bn,VN=/#|\.prototype\./,Nu=function(e,t){var n=XN[YN(e)];return n===ZN?!0:n===qN?!1:GN(t)?WN(t):!!t},YN=Nu.normalize=function(e){return String(e).replace(VN,".").toLowerCase()},XN=Nu.data={},qN=Nu.NATIVE="N",ZN=Nu.POLYFILL="P",QN=Nu,Pd=Gn,JN=hx.f,eF=Sx,tF=ek,nF=gx,rF=KN,sF=QN,El=function(e,t){var n=e.target,r=e.global,s=e.stat,o,i,a,l,c,u;if(r?i=Pd:s?i=Pd[n]||nF(n,{}):i=Pd[n]&&Pd[n].prototype,i)for(a in t){if(c=t[a],e.dontCallGetSet?(u=JN(i,a),l=u&&u.value):l=i[a],o=sF(r?a:n+(s?".":"#")+a,e.forced),!o&&l!==void 0){if(typeof c==typeof l)continue;rF(c,l)}(e.sham||l&&l.sham)&&eF(c,"sham",!0),tF(i,a,c,e)}},ok={},oF=rk,iF=bx,aF=Object.keys||function(t){return oF(t,iF)},lF=ri,cF=GE,uF=Il,dF=ta,hF=Rf,pF=aF;ok.f=lF&&!cF?Object.defineProperties:function(t,n){dF(t);for(var r=hF(n),s=pF(n),o=s.length,i=0,a;o>i;)uF.f(t,a=s[i++],r[a]);return t};var fF=Lf,gF=fF("document","documentElement"),mF=ta,yF=ok,cb=bx,SF=xx,vF=gF,xF=KE,wF=qE,ub=">",db="<",uS="prototype",dS="script",ik=wF("IE_PROTO"),pm=function(){},ak=function(e){return db+dS+ub+e+db+"/"+dS+ub},hb=function(e){e.write(ak("")),e.close();var t=e.parentWindow.Object;return e=null,t},bF=function(){var e=xF("iframe"),t="java"+dS+":",n;return e.style.display="none",vF.appendChild(e),e.src=String(t),n=e.contentWindow.document,n.open(),n.write(ak("document.F=Object")),n.close(),n.F},Cd,Eh=function(){try{Cd=new ActiveXObject("htmlfile")}catch{}Eh=typeof document<"u"?document.domain&&Cd?hb(Cd):bF():hb(Cd);for(var e=cb.length;e--;)delete Eh[uS][cb[e]];return Eh()};SF[ik]=!0;var lk=Object.create||function(t,n){var r;return t!==null?(pm[uS]=mF(t),r=new pm,pm[uS]=null,r[ik]=t):r=Eh(),n===void 0?r:yF.f(r,n)},PF=ao,CF=lk,IF=Il.f,hS=PF("unscopables"),pS=Array.prototype;pS[hS]===void 0&&IF(pS,hS,{configurable:!0,value:CF(null)});var Px=function(e){pS[hS][e]=!0},EF=El,kF=Lu,_F=$u,TF=na,MF=Px;EF({target:"Array",proto:!0},{at:function(t){var n=kF(this),r=_F(n),s=TF(t),o=s>=0?s:r+s;return o<0||o>=r?void 0:n[o]}});MF("at");var AF=Gn,jF=Rt,Fu=function(e,t){return jF(AF[e].prototype[t])},OF=Fu;OF("Array","at");var DF=Pl,ck=Array.isArray||function(t){return DF(t)==="Array"},RF=TypeError,LF=9007199254740991,$F=function(e){if(e>LF)throw RF("Maximum allowed index exceeded");return e},NF=Pl,FF=Rt,zF=function(e){if(NF(e)==="Function")return FF(e)},pb=zF,BF=px,UF=Of,HF=pb(pb.bind),KF=function(e,t){return BF(e),t===void 0?e:UF?HF(e,t):function(){return e.apply(t,arguments)}},WF=ck,GF=$u,VF=$F,YF=KF,uk=function(e,t,n,r,s,o,i,a){for(var l=s,c=0,u=i?YF(i,a):!1,h,p;c<r;)c in n&&(h=u?u(n[c],c,t):n[c],o>0&&WF(h)?(p=GF(h),l=uk(e,t,h,p,l,o-1)-1):(VF(l+1),e[l]=h),l++),c++;return l},dk=uk,XF=ao,qF=XF("toStringTag"),hk={};hk[qF]="z";var ZF=String(hk)==="[object z]",QF=ZF,JF=bn,kh=Pl,e4=ao,t4=e4("toStringTag"),n4=Object,r4=kh(function(){return arguments}())==="Arguments",s4=function(e,t){try{return e[t]}catch{}},pk=QF?kh:function(e){var t,n,r;return e===void 0?"Undefined":e===null?"Null":typeof(n=s4(t=n4(e),t4))=="string"?n:r4?kh(t):(r=kh(t))==="Object"&&JF(t.callee)?"Arguments":r},o4=Rt,i4=wn,fk=bn,a4=pk,l4=Lf,c4=XE,gk=function(){},mk=l4("Reflect","construct"),Cx=/^\s*(?:class|function)\b/,u4=o4(Cx.exec),d4=!Cx.test(gk),Kl=function(t){if(!fk(t))return!1;try{return mk(gk,[],t),!0}catch{return!1}},yk=function(t){if(!fk(t))return!1;switch(a4(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return d4||!!u4(Cx,c4(t))}catch{return!0}};yk.sham=!0;var h4=!mk||i4(function(){var e;return Kl(Kl.call)||!Kl(Object)||!Kl(function(){e=!0})||e})?yk:Kl,fb=ck,p4=h4,f4=ea,g4=ao,m4=g4("species"),gb=Array,y4=function(e){var t;return fb(e)&&(t=e.constructor,p4(t)&&(t===gb||fb(t.prototype))?t=void 0:f4(t)&&(t=t[m4],t===null&&(t=void 0))),t===void 0?gb:t},S4=y4,Sk=function(e,t){return new(S4(e))(t===0?0:t)},v4=El,x4=dk,w4=px,b4=Lu,P4=$u,C4=Sk;v4({target:"Array",proto:!0},{flatMap:function(t){var n=b4(this),r=P4(n),s;return w4(t),s=C4(n,0),s.length=x4(s,n,n,r,0,1,t,arguments.length>1?arguments[1]:void 0),s}});var I4=Px;I4("flatMap");var E4=Fu;E4("Array","flatMap");var k4=El,_4=dk,T4=Lu,M4=$u,A4=na,j4=Sk;k4({target:"Array",proto:!0},{flat:function(){var t=arguments.length?arguments[0]:void 0,n=T4(this),r=M4(n),s=j4(n,0);return s.length=_4(s,n,n,r,0,t===void 0?1:A4(t)),s}});var O4=Px;O4("flat");var D4=Fu;D4("Array","flat");var R4=pk,L4=String,zu=function(e){if(R4(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return L4(e)},$4=El,N4=Rt,F4=Cl,z4=na,B4=zu,U4=wn,H4=N4("".charAt),K4=U4(function(){return"𠮷".at(-2)!=="\uD842"});$4({target:"String",proto:!0,forced:K4},{at:function(t){var n=B4(F4(this)),r=n.length,s=z4(t),o=s>=0?s:r+s;return o<0||o>=r?void 0:H4(n,o)}});var W4=Fu;W4("String","at");var G4=ta,vk=function(){var e=G4(this),t="";return e.hasIndices&&(t+="d"),e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.unicodeSets&&(t+="v"),e.sticky&&(t+="y"),t},Ix=wn,V4=Gn,Ex=V4.RegExp,kx=Ix(function(){var e=Ex("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),Y4=kx||Ix(function(){return!Ex("a","y").sticky}),X4=kx||Ix(function(){var e=Ex("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),q4={BROKEN_CARET:X4,MISSED_STICKY:Y4,UNSUPPORTED_Y:kx},Z4=wn,Q4=Gn,J4=Q4.RegExp,ez=Z4(function(){var e=J4(".","s");return!(e.dotAll&&e.test(`
|
|
18
|
-
`)&&e.flags==="s")}),tz=wn,nz=Gn,rz=nz.RegExp,sz=tz(function(){var e=rz("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),Ea=io,$f=Rt,oz=zu,iz=vk,az=q4,lz=yx,cz=lk,uz=QE.get,dz=ez,hz=sz,pz=lz("native-string-replace",String.prototype.replace),bp=RegExp.prototype.exec,fS=bp,fz=$f("".charAt),gz=$f("".indexOf),mz=$f("".replace),fm=$f("".slice),gS=function(){var e=/a/,t=/b*/g;return Ea(bp,e,"a"),Ea(bp,t,"a"),e.lastIndex!==0||t.lastIndex!==0}(),xk=az.BROKEN_CARET,mS=/()??/.exec("")[1]!==void 0,yz=gS||mS||xk||dz||hz;yz&&(fS=function(t){var n=this,r=uz(n),s=oz(t),o=r.raw,i,a,l,c,u,h,p;if(o)return o.lastIndex=n.lastIndex,i=Ea(fS,o,s),n.lastIndex=o.lastIndex,i;var f=r.groups,S=xk&&n.sticky,y=Ea(iz,n),x=n.source,m=0,v=s;if(S&&(y=mz(y,"y",""),gz(y,"g")===-1&&(y+="g"),v=fm(s,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&fz(s,n.lastIndex-1)!==`
|
|
19
|
-
`)&&(x="(?: "+x+")",v=" "+v,m++),a=new RegExp("^(?:"+x+")",y)),mS&&(a=new RegExp("^"+x+"$(?!\\s)",y)),gS&&(l=n.lastIndex),c=Ea(bp,S?a:n,v),S?c?(c.input=fm(c.input,m),c[0]=fm(c[0],m),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:gS&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),mS&&c&&c.length>1&&Ea(pz,c[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(c[u]=void 0)}),c&&f)for(c.groups=h=cz(null),u=0;u<f.length;u++)p=f[u],h[p[0]]=c[p[1]];return c});var _x=fS,Sz=El,mb=_x;Sz({target:"RegExp",proto:!0,forced:/./.exec!==mb},{exec:mb});var vz=Of,wk=Function.prototype,yb=wk.apply,Sb=wk.call,xz=typeof Reflect=="object"&&Reflect.apply||(vz?Sb.bind(yb):function(){return Sb.apply(yb,arguments)}),vb=io,xb=ek,wz=_x,wb=wn,bk=ao,bz=Sx,Pz=bk("species"),gm=RegExp.prototype,Cz=function(e,t,n,r){var s=bk(e),o=!wb(function(){var c={};return c[s]=function(){return 7},""[e](c)!==7}),i=o&&!wb(function(){var c=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[Pz]=function(){return u},u.flags="",u[s]=/./[s]),u.exec=function(){return c=!0,null},u[s](""),!c});if(!o||!i||n){var a=/./[s],l=t(s,""[e],function(c,u,h,p,f){var S=u.exec;return S===wz||S===gm.exec?o&&!f?{done:!0,value:vb(a,u,h,p)}:{done:!0,value:vb(c,h,u,p)}:{done:!1}});xb(String.prototype,e,l[0]),xb(gm,s,l[1])}r&&bz(gm[s],"sham",!0)},Tx=Rt,Iz=na,Ez=zu,kz=Cl,_z=Tx("".charAt),bb=Tx("".charCodeAt),Tz=Tx("".slice),Pb=function(e){return function(t,n){var r=Ez(kz(t)),s=Iz(n),o=r.length,i,a;return s<0||s>=o?e?"":void 0:(i=bb(r,s),i<55296||i>56319||s+1===o||(a=bb(r,s+1))<56320||a>57343?e?_z(r,s):i:e?Tz(r,s,s+2):(i-55296<<10)+(a-56320)+65536)}},Mz={codeAt:Pb(!1),charAt:Pb(!0)},Az=Mz.charAt,jz=function(e,t,n){return t+(n?Az(e,t).length:1)},Mx=Rt,Oz=Lu,Dz=Math.floor,mm=Mx("".charAt),Rz=Mx("".replace),ym=Mx("".slice),Lz=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,$z=/\$([$&'`]|\d{1,2})/g,Pk=function(e,t,n,r,s,o){var i=n+e.length,a=r.length,l=$z;return s!==void 0&&(s=Oz(s),l=Lz),Rz(o,l,function(c,u){var h;switch(mm(u,0)){case"$":return"$";case"&":return e;case"`":return ym(t,0,n);case"'":return ym(t,i);case"<":h=s[ym(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=Dz(p/10);return f===0?c:f<=a?r[f-1]===void 0?mm(u,1):r[f-1]+mm(u,1):c}h=r[p-1]}return h===void 0?"":h})},Cb=io,Nz=ta,Fz=bn,zz=Pl,Bz=_x,Uz=TypeError,Hz=function(e,t){var n=e.exec;if(Fz(n)){var r=Cb(n,e,t);return r!==null&&Nz(r),r}if(zz(e)==="RegExp")return Cb(Bz,e,t);throw new Uz("RegExp#exec called on incompatible receiver")},Kz=xz,Ib=io,Nf=Rt,Wz=Cz,Gz=wn,Vz=ta,Yz=bn,Xz=Df,qz=na,Zz=nk,da=zu,Qz=Cl,Jz=jz,e6=fx,t6=Pk,n6=Hz,r6=ao,yS=r6("replace"),s6=Math.max,o6=Math.min,i6=Nf([].concat),Sm=Nf([].push),Eb=Nf("".indexOf),kb=Nf("".slice),a6=function(e){return e===void 0?e:String(e)},l6=function(){return"a".replace(/./,"$0")==="$0"}(),_b=function(){return/./[yS]?/./[yS]("a","$0")==="":!1}(),c6=!Gz(function(){var e=/./;return e.exec=function(){var t=[];return t.groups={a:"7"},t},"".replace(e,"$<a>")!=="7"});Wz("replace",function(e,t,n){var r=_b?"$":"$0";return[function(o,i){var a=Qz(this),l=Xz(o)?void 0:e6(o,yS);return l?Ib(l,o,a,i):Ib(t,da(a),o,i)},function(s,o){var i=Vz(this),a=da(s);if(typeof o=="string"&&Eb(o,r)===-1&&Eb(o,"$<")===-1){var l=n(t,i,a,o);if(l.done)return l.value}var c=Yz(o);c||(o=da(o));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=n6(i,a),!(f===null||(Sm(p,f),!u));){var S=da(f[0]);S===""&&(i.lastIndex=Jz(a,Zz(i.lastIndex),h))}for(var y="",x=0,m=0;m<p.length;m++){f=p[m];for(var v=da(f[0]),w=s6(o6(qz(f.index),a.length),0),C=[],E,_=1;_<f.length;_++)Sm(C,a6(f[_]));var I=f.groups;if(c){var k=i6([v],C,w,a);I!==void 0&&Sm(k,I),E=da(Kz(o,void 0,k))}else E=t6(v,a,w,C,I,o);w>=x&&(y+=kb(a,x,w)+E,x=w+v.length)}return y+kb(a,x)}]},!c6||!l6||_b);var u6=ea,d6=Pl,h6=ao,p6=h6("match"),f6=function(e){var t;return u6(e)&&((t=e[p6])!==void 0?!!t:d6(e)==="RegExp")},g6=io,m6=si,y6=LE,S6=vk,Tb=RegExp.prototype,v6=function(e){var t=e.flags;return t===void 0&&!("flags"in Tb)&&!m6(e,"flags")&&y6(Tb,e)?g6(S6,e):t},x6=El,w6=io,Ax=Rt,Mb=Cl,b6=bn,P6=Df,C6=f6,Wl=zu,I6=fx,E6=v6,k6=Pk,_6=ao,T6=_6("replace"),M6=TypeError,vm=Ax("".indexOf);Ax("".replace);var Ab=Ax("".slice),A6=Math.max;x6({target:"String",proto:!0},{replaceAll:function(t,n){var r=Mb(this),s,o,i,a,l,c,u,h,p,f=0,S=0,y="";if(!P6(t)){if(s=C6(t),s&&(o=Wl(Mb(E6(t))),!~vm(o,"g")))throw new M6("`.replaceAll` does not allow non-global regexes");if(i=I6(t,T6),i)return w6(i,t,r,n)}for(a=Wl(r),l=Wl(t),c=b6(n),c||(n=Wl(n)),u=l.length,h=A6(1,u),f=vm(a,l);f!==-1;)p=c?Wl(n(l,f,a)):k6(l,a,f,[],void 0,n),y+=Ab(a,S,f)+p,S=f+u,f=f+h>a.length?-1:vm(a,l,f+h);return S<a.length&&(y+=Ab(a,S)),y}});var j6=Fu;j6("String","replaceAll");function Ck(e){return e&&typeof e=="object"&&"parents"in e}function Ik(e){for(let t=0,n=e.parents.length;t<n;t++)if(e.parents[t].__unsafe__getWithoutCapture(!0),e.parents[t].lastChangedEpoch!==e.parentEpochs[t])return!0;return!1}const Pp=(e,t)=>{if(e.children.remove(t)&&e.children.isEmpty&&Ck(e))for(let n=0,r=e.parents.length;n<r;n++)Pp(e.parents[n],e)},jx=(e,t)=>{if(e.children.add(t)&&Ck(e))for(let n=0,r=e.parents.length;n<r;n++)jx(e.parents[n],e)};function Ek(e,t){return e===t||Object.is(e,t)||!!(e&&t&&typeof e.equals=="function"&&e.equals(t))}function oi(e,t){const n=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[n]??(r[n]=t()),r[n]}const Gs=oi("empty_array",()=>Object.freeze([])),jb=8;class Cp{constructor(){g(this,"arraySize",0);g(this,"array",Array(jb));g(this,"set",null)}get isEmpty(){if(this.array)return this.arraySize===0;if(this.set)return this.set.size===0;throw new Error("no set or array")}add(t){if(this.array)return this.array.indexOf(t)!==-1?!1:this.arraySize<jb?(this.array[this.arraySize]=t,this.arraySize++,!0):(this.set=new Set(this.array),this.array=null,this.set.add(t),!0);if(this.set)return this.set.has(t)?!1:(this.set.add(t),!0);throw new Error("no set or array")}remove(t){if(this.array){const n=this.array.indexOf(t);return n===-1?!1:(this.array[n]=void 0,this.arraySize--,n!==this.arraySize&&(this.array[n]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return this.set.has(t)?(this.set.delete(t),!0):!1;throw new Error("no set or array")}visit(t){if(this.array){for(let n=0;n<this.arraySize;n++){const r=this.array[n];typeof r<"u"&&t(r)}return}if(this.set){this.set.forEach(t);return}throw new Error("no set or array")}has(t){return this.array?this.array.indexOf(t)!==-1:this.set.has(t)}clear(){this.set?this.set.clear():(this.arraySize=0,this.array=[])}size(){return this.set?this.set.size:this.arraySize}}const rr=Symbol.for("com.tldraw.state/RESET_VALUE");class kk{constructor(t){g(this,"index",0);g(this,"buffer");this.capacity=t,this.buffer=new Array(t)}pushEntry(t,n,r){if(r!==void 0){if(r===rr){this.clear();return}this.buffer[this.index]=[t,n,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(t){const{index:n,capacity:r,buffer:s}=this;for(let o=0;o<r;o++){const i=(n-1+r-o)%r,a=s[i];if(!a)return rr;const[l,c]=a;if(o===0&&t>=c)return[];if(l<=t&&t<c){const u=o+1,h=new Array(u);for(let p=0;p<u;p++)h[p]=s[(i+p)%r][2];return h}}return rr}}class O6{constructor(t,n){g(this,"offset",0);g(this,"maybeRemoved");this.below=t,this.child=n}}const rt=oi("capture",()=>({stack:null}));function Id(e){const t=rt.stack;rt.stack=null;try{return e()}finally{rt.stack=t}}function _k(e){rt.stack=new O6(rt.stack,e),e.parentSet.clear()}function Tk(){const e=rt.stack;if(rt.stack=e.below,e.offset<e.child.parents.length){for(let t=e.offset;t<e.child.parents.length;t++){const n=e.child.parents[t];e.child.parentSet.has(n)||Pp(n,e.child)}e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset}if(e.maybeRemoved)for(let t=0;t<e.maybeRemoved.length;t++){const n=e.maybeRemoved[t];e.child.parentSet.has(n)||Pp(n,e.child)}}function Ip(e){if(rt.stack){if(rt.stack.child.parentSet.has(e))return;if(rt.stack.child.parentSet.add(e),rt.stack.child.isActivelyListening&&jx(e,rt.stack.child),rt.stack.offset<rt.stack.child.parents.length){const n=rt.stack.child.parents[rt.stack.offset];n!==e&&(rt.stack.maybeRemoved?rt.stack.maybeRemoved.push(n):rt.stack.maybeRemoved=[n])}rt.stack.child.parents[rt.stack.offset]=e,rt.stack.child.parentEpochs[rt.stack.offset]=e.lastChangedEpoch,rt.stack.offset++}}const Mo=-1;class D6{constructor(t,n,r){g(this,"_isActivelyListening",!1);g(this,"lastTraversedEpoch",Mo);g(this,"lastReactedEpoch",Mo);g(this,"_scheduleCount",0);g(this,"parentSet",new Cp);g(this,"parentEpochs",[]);g(this,"parents",[]);g(this,"_scheduleEffect");g(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=t,this.runEffect=n,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==An()){if(this.parents.length&&!Ik(this)){this.lastReactedEpoch=An();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let t=0,n=this.parents.length;t<n;t++)jx(this.parents[t],this)}detach(){this._isActivelyListening=!1;for(let t=0,n=this.parents.length;t<n;t++)Pp(this.parents[t],this)}execute(){try{_k(this);const t=An(),n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=t,n}finally{Tk()}}}const kl=oi("EffectScheduler",()=>D6);function ra(e,t,n){const r=new kl(e,t,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function R6(e,t,n){const r=new kl(e,t,n);return{scheduler:r,start:s=>{const o=(s==null?void 0:s.force)??!1;r.attach(),o?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}class L6{constructor(t){g(this,"initialAtomValues",new Map);this.parent=t}get isRoot(){return this.parent===null}commit(){this.isRoot?Mk(this.initialAtomValues.keys()):this.initialAtomValues.forEach((t,n)=>{this.parent.initialAtomValues.has(n)||this.parent.initialAtomValues.set(n,t)})}abort(){ze.globalEpoch++,this.initialAtomValues.forEach((t,n)=>{var r;n.set(t),(r=n.historyBuffer)==null||r.clear()}),this.commit()}}const ze=oi("transactions",()=>({globalEpoch:Mo+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Mo+1}));function $6(){return ze.reactionEpoch}function An(){return ze.globalEpoch}function N6(){return ze.globalIsReacting}function Ox(e,t){t.lastTraversedEpoch!==ze.globalEpoch&&(t.lastTraversedEpoch=ze.globalEpoch,t instanceof kl?e.add(t):t.children.visit(n=>Ox(e,n)))}function Mk(e){var t;if(ze.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{ze.globalIsReacting=!0,ze.reactionEpoch=ze.globalEpoch;const n=new Set;for(const s of e)s.children.visit(o=>Ox(n,o));for(const s of n)s.maybeScheduleEffect();let r=0;for(;(t=ze.cleanupReactors)!=null&&t.size;){if(r++>1e3)throw new Error("Reaction update depth limit exceeded");const s=ze.cleanupReactors;ze.cleanupReactors=null;for(const o of s)o.maybeScheduleEffect()}}finally{ze.cleanupReactors=null,ze.globalIsReacting=!1}}function F6(e,t){if(ze.globalIsReacting){const n=ze.cleanupReactors??(ze.cleanupReactors=new Set);e.children.visit(r=>Ox(n,r))}else ze.currentTransaction?ze.currentTransaction.initialAtomValues.has(e)||ze.currentTransaction.initialAtomValues.set(e,t):Mk([e])}function z6(){ze.globalEpoch++}function B6(e){const t=new L6(ze.currentTransaction);ze.currentTransaction=t;try{let n,r=!1;try{n=e(()=>r=!0)}catch(s){throw t.abort(),s}return r?t.abort():t.commit(),n}finally{ze.currentTransaction=ze.currentTransaction.parent}}function gs(e){return ze.currentTransaction?e():B6(e)}class U6{constructor(t,n,r){g(this,"isEqual");g(this,"computeDiff");g(this,"lastChangedEpoch",An());g(this,"children",new Cp);g(this,"historyBuffer");this.name=t,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new kk(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(t){return this.current}get(){return Ip(this),this.current}set(t,n){var s,o;if(((s=this.isEqual)==null?void 0:s.call(this,this.current,t))??Ek(this.current,t))return this.current;z6(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,An(),n??((o=this.computeDiff)==null?void 0:o.call(this,this.current,t,this.lastChangedEpoch,An()))??rr),this.lastChangedEpoch=An();const r=this.current;return this.current=t,F6(this,r),t}update(t){return this.set(t(this.current))}getDiffSince(t){var n;return Ip(this),t>=this.lastChangedEpoch?Gs:((n=this.historyBuffer)==null?void 0:n.getChangesSince(t))??rr}}const H6=oi("Atom",()=>U6);function Mt(e,t,n){return new H6(e,t,n)}let Ob=!1;function K6(){Ob||(Ob=!0,console.warn(`Using \`@computed\` as a decorator for getters is deprecated and will be removed in the near future. Please refactor to use \`@computed\` as a decorator for methods.
|
|
20
|
-
|
|
21
|
-
// Before
|
|
22
|
-
@computed
|
|
23
|
-
get foo() {
|
|
24
|
-
return 'foo'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// After
|
|
28
|
-
@computed
|
|
29
|
-
getFoo() {
|
|
30
|
-
return 'foo'
|
|
31
|
-
}
|
|
32
|
-
`))}const gc=Symbol.for("com.tldraw.state/UNINITIALIZED"),Mi=e=>e===gc,SS=oi("WithDiff",()=>class{constructor(t,n){this.value=t,this.diff=n}});function mc(e,t){return new SS(e,t)}class W6{constructor(t,n,r){g(this,"lastChangedEpoch",Mo);g(this,"lastTraversedEpoch",Mo);g(this,"lastCheckedEpoch",Mo);g(this,"parentSet",new Cp);g(this,"parents",[]);g(this,"parentEpochs",[]);g(this,"children",new Cp);g(this,"historyBuffer");g(this,"state",gc);g(this,"error",null);g(this,"computeDiff");g(this,"isEqual");this.name=t,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new kk(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??Ek}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(t){var s;const n=this.lastChangedEpoch===Mo,r=An();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&N6()&&this.lastTraversedEpoch<$6()||!Ik(this)))if(this.lastCheckedEpoch=r,this.error){if(t)return this.state;throw this.error.thrownValue}else return this.state;try{_k(this);const o=this.derive(this.state,this.lastCheckedEpoch),i=o instanceof SS?o.value:o,a=this.state===gc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=o instanceof SS?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,An(),l??((s=this.computeDiff)==null?void 0:s.call(this,this.state,i,this.lastCheckedEpoch,An()))??rr)}this.lastChangedEpoch=An(),this.state=i}return this.error=null,this.lastCheckedEpoch=An(),this.state}catch(o){if(this.state!==gc&&(this.state=gc,this.lastChangedEpoch=An()),this.lastCheckedEpoch=An(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!t)throw o;return this.state}finally{Tk()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Ip(this)}}getDiffSince(t){var n;return this.__unsafe__getWithoutCapture(!0),Ip(this),t>=this.lastChangedEpoch?Gs:((n=this.historyBuffer)==null?void 0:n.getChangesSince(t))??rr}}const Dx=oi("Computed",()=>W6);function G6(e={},t,n,r){const s=r.value,o=Symbol.for("__@tldraw/state__computed__"+n);return r.value=function(){let i=this[o];return i||(i=new Dx(n,s.bind(this),e),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[Y6]=!0,r}function Db(e={},t,n,r){return r.get?(K6(),V6(e,t,n,r)):G6(e,t,n,r)}function V6(e={},t,n,r){const s=r.get,o=Symbol.for("__@tldraw/state__computed__"+n);return r.get=function(){let i=this[o];return i||(i=new Dx(n,s.bind(this),e),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const Y6="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const e=arguments[0];return(t,n,r)=>Db(e,t,n,r)}else return typeof arguments[0]=="string"?new Dx(arguments[0],arguments[1],arguments[2]):Db(void 0,arguments[0],arguments[1],arguments[2])}const Ak=1,X6=oi("apiVersion",()=>Ak);if(X6!==Ak)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");var jk="Expected a function",Rb=NaN,q6="[object Symbol]",Z6=/^\s+|\s+$/g,Q6=/^[-+]0x[0-9a-f]+$/i,J6=/^0b[01]+$/i,e8=/^0o[0-7]+$/i,t8=parseInt,n8=typeof cn=="object"&&cn&&cn.Object===Object&&cn,r8=typeof self=="object"&&self&&self.Object===Object&&self,s8=n8||r8||Function("return this")(),o8=Object.prototype,i8=o8.toString,a8=Math.max,l8=Math.min,xm=function(){return s8.Date.now()};function c8(e,t,n){var r,s,o,i,a,l,c=0,u=!1,h=!1,p=!0;if(typeof e!="function")throw new TypeError(jk);t=Lb(t)||0,Ep(n)&&(u=!!n.leading,h="maxWait"in n,o=h?a8(Lb(n.maxWait)||0,t):o,p="trailing"in n?!!n.trailing:p);function f(_){var I=r,k=s;return r=s=void 0,c=_,i=e.apply(k,I),i}function S(_){return c=_,a=setTimeout(m,t),u?f(_):i}function y(_){var I=_-l,k=_-c,T=t-I;return h?l8(T,o-k):T}function x(_){var I=_-l,k=_-c;return l===void 0||I>=t||I<0||h&&k>=o}function m(){var _=xm();if(x(_))return v(_);a=setTimeout(m,y(_))}function v(_){return a=void 0,p&&r?f(_):(r=s=void 0,i)}function w(){a!==void 0&&clearTimeout(a),c=0,r=l=s=a=void 0}function C(){return a===void 0?i:v(xm())}function E(){var _=xm(),I=x(_);if(r=arguments,s=this,l=_,I){if(a===void 0)return S(l);if(h)return a=setTimeout(m,t),f(l)}return a===void 0&&(a=setTimeout(m,t)),i}return E.cancel=w,E.flush=C,E}function u8(e,t,n){var r=!0,s=!0;if(typeof e!="function")throw new TypeError(jk);return Ep(n)&&(r="leading"in n?!!n.leading:r,s="trailing"in n?!!n.trailing:s),c8(e,t,{leading:r,maxWait:t,trailing:s})}function Ep(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function d8(e){return!!e&&typeof e=="object"}function h8(e){return typeof e=="symbol"||d8(e)&&i8.call(e)==q6}function Lb(e){if(typeof e=="number")return e;if(h8(e))return Rb;if(Ep(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Ep(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Z6,"");var n=J6.test(e);return n||e8.test(e)?t8(e.slice(2),n?2:8):Q6.test(e)?Rb:+e}var p8=u8;const Ok=ni(p8);var f8=200,Rx="__lodash_hash_undefined__",g8=1/0,m8="[object Function]",y8="[object GeneratorFunction]",S8=/[\\^$.*+?()[\]{}|]/g,v8=/^\[object .+?Constructor\]$/,x8=typeof cn=="object"&&cn&&cn.Object===Object&&cn,w8=typeof self=="object"&&self&&self.Object===Object&&self,Lx=x8||w8||Function("return this")();function b8(e,t){var n=e?e.length:0;return!!n&&C8(e,t,0)>-1}function P8(e,t,n,r){for(var s=e.length,o=n+-1;++o<s;)if(t(e[o],o,e))return o;return-1}function C8(e,t,n){if(t!==t)return P8(e,I8,n);for(var r=n-1,s=e.length;++r<s;)if(e[r]===t)return r;return-1}function I8(e){return e!==e}function E8(e,t){return e.has(t)}function k8(e,t){return e==null?void 0:e[t]}function _8(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch{}return t}function Dk(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}var T8=Array.prototype,M8=Function.prototype,Rk=Object.prototype,wm=Lx["__core-js_shared__"],$b=function(){var e=/[^.]+$/.exec(wm&&wm.keys&&wm.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Lk=M8.toString,$x=Rk.hasOwnProperty,A8=Rk.toString,j8=RegExp("^"+Lk.call($x).replace(S8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),O8=T8.splice,D8=Nx(Lx,"Map"),bm=Nx(Lx,"Set"),tu=Nx(Object,"create");function Ri(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function R8(){this.__data__=tu?tu(null):{}}function L8(e){return this.has(e)&&delete this.__data__[e]}function $8(e){var t=this.__data__;if(tu){var n=t[e];return n===Rx?void 0:n}return $x.call(t,e)?t[e]:void 0}function N8(e){var t=this.__data__;return tu?t[e]!==void 0:$x.call(t,e)}function F8(e,t){var n=this.__data__;return n[e]=tu&&t===void 0?Rx:t,this}Ri.prototype.clear=R8;Ri.prototype.delete=L8;Ri.prototype.get=$8;Ri.prototype.has=N8;Ri.prototype.set=F8;function _l(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function z8(){this.__data__=[]}function B8(e){var t=this.__data__,n=Ff(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():O8.call(t,n,1),!0}function U8(e){var t=this.__data__,n=Ff(t,e);return n<0?void 0:t[n][1]}function H8(e){return Ff(this.__data__,e)>-1}function K8(e,t){var n=this.__data__,r=Ff(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}_l.prototype.clear=z8;_l.prototype.delete=B8;_l.prototype.get=U8;_l.prototype.has=H8;_l.prototype.set=K8;function Tl(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function W8(){this.__data__={hash:new Ri,map:new(D8||_l),string:new Ri}}function G8(e){return zf(this,e).delete(e)}function V8(e){return zf(this,e).get(e)}function Y8(e){return zf(this,e).has(e)}function X8(e,t){return zf(this,e).set(e,t),this}Tl.prototype.clear=W8;Tl.prototype.delete=G8;Tl.prototype.get=V8;Tl.prototype.has=Y8;Tl.prototype.set=X8;function kp(e){var t=-1,n=e?e.length:0;for(this.__data__=new Tl;++t<n;)this.add(e[t])}function q8(e){return this.__data__.set(e,Rx),this}function Z8(e){return this.__data__.has(e)}kp.prototype.add=kp.prototype.push=q8;kp.prototype.has=Z8;function Ff(e,t){for(var n=e.length;n--;)if(oB(e[n][0],t))return n;return-1}function Q8(e){if(!$k(e)||nB(e))return!1;var t=iB(e)||_8(e)?j8:v8;return t.test(rB(e))}function J8(e,t,n){var r=-1,s=b8,o=e.length,i=!0,a=[],l=a;if(o>=f8){var c=eB(e);if(c)return Dk(c);i=!1,s=E8,l=new kp}else l=a;e:for(;++r<o;){var u=e[r],h=u;if(u=u!==0?u:0,i&&h===h){for(var p=l.length;p--;)if(l[p]===h)continue e;a.push(u)}else s(l,h,n)||(l!==a&&l.push(h),a.push(u))}return a}var eB=bm&&1/Dk(new bm([,-0]))[1]==g8?function(e){return new bm(e)}:aB;function zf(e,t){var n=e.__data__;return tB(t)?n[typeof t=="string"?"string":"hash"]:n.map}function Nx(e,t){var n=k8(e,t);return Q8(n)?n:void 0}function tB(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function nB(e){return!!$b&&$b in e}function rB(e){if(e!=null){try{return Lk.call(e)}catch{}try{return e+""}catch{}}return""}function sB(e){return e&&e.length?J8(e):[]}function oB(e,t){return e===t||e!==e&&t!==t}function iB(e){var t=$k(e)?A8.call(e):"";return t==m8||t==y8}function $k(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function aB(){}var lB=sB;const cB=ni(lB),yc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},uB=yc.Good;class Nk{constructor(){g(this,"startTime",0);g(this,"name","");g(this,"frames",0);g(this,"started",!1);g(this,"frame",null);g(this,"recordFrame",()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))})}start(t){this.name=t,this.frames=0,this.started=!0,this.frame!==null&&cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(this.recordFrame),this.startTime=performance.now()}stop(){this.started=!1,this.frame!==null&&cancelAnimationFrame(this.frame);const t=(performance.now()-this.startTime)/1e3,n=t===0?0:Math.floor(this.frames/t),r=n>55?yc.Good:n>30?yc.Mid:yc.Poor,s=r===yc.Mid?"black":"white",o=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${o} %c${n}%c fps`,`color: white; background: ${uB};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${r};color: ${s};`,"font-weight: normal")}isStarted(){return this.started}}function Fx(e,t){const n=[];e:for(const r of e){for(const s of n)if(t?t(r,s):r===s)continue e;n.push(r)}return n}function ye(e){return e.filter(t=>t!=null)}function Ut(e){return e[e.length-1]}function dB(e,t){let n,r=1/0;for(const s of e){const o=t(s);o<r&&(n=s,r=o)}return n}function hB(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}class Zs{constructor(){g(this,"items",new WeakMap)}get(t,n){return this.items.has(t)||this.items.set(t,n(t)),this.items.get(t)}}function Fk(e){const t=(...n)=>{try{return e(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,t),r}};return t}const nu=()=>{},yn={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function un(e,t){const n=t&&e&&typeof e=="object"&&t in e?e[t]:e;throw new Error(`Unknown switch case ${n}`)}const Xe=Fk((e,t)=>{if(!e)throw new Error(t||"Assertion Error")}),xr=Fk((e,t)=>{if(e==null)throw new Error(t??"value must be defined");return e});function zk(e,t){let n;const r=(...s)=>(n||(n={},n.promise=new Promise((o,i)=>{n.resolve=o,n.reject=i})),clearTimeout(n.timeout),n.latestArgs=s,n.timeout=setTimeout(()=>{const o=n;n=void 0;try{o.resolve(e(...o.latestArgs))}catch(i){o.reject(i)}},t),n.promise);return r.cancel=()=>{n&&clearTimeout(n.timeout)},r}const Nb=new WeakMap;function zx(e,t){if(typeof e!="object"||e===null)return;let n=Nb.get(e);n||(n={tags:{},extras:{}},Nb.set(e,n)),t.tags&&(n.tags={...n.tags,...t.tags}),t.extras&&(n.extras={...n.extras,...t.extras})}async function ws(e,t){return window.fetch(e,{referrerPolicy:"strict-origin-when-cross-origin",...t})}const ol=(e,t)=>{const n=new window.Image(e,t);return n.referrerPolicy="strict-origin-when-cross-origin",n};class Ai{static async dataUrlToArrayBuffer(t){return ws(t).then(function(n){return n.arrayBuffer()})}static async blobToDataUrl(t){return await new Promise((n,r)=>{if(t){const s=new FileReader;s.onload=()=>n(s.result),s.onerror=o=>r(o),s.onabort=o=>r(o),s.readAsDataURL(t)}})}static async blobToText(t){return await new Promise((n,r)=>{if(t){const s=new FileReader;s.onload=()=>n(s.result),s.onerror=o=>r(o),s.onabort=o=>r(o),s.readAsText(t)}})}}function vS(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t+""}function pB(e){const t=new DataView(e);let n=0;for(let r=0;r<t.byteLength;r++)n=(n<<5)-n+t.getUint8(r),n|=0;return n+""}/*!
|
|
33
|
-
* MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
|
|
34
|
-
* Copyright (c) Philip van Heemstra
|
|
35
|
-
*/function fB(e){const t=new Uint8Array(e);if(!t||!(typeof Buffer<"u"&&Buffer.isBuffer(t)||t instanceof Uint8Array)||t.length<16||!(t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71&&t[4]===13&&t[5]===10&&t[6]===26&&t[7]===10))return!1;function r(o,i,a,l,c=1024){if(!i)return-1;i=new RegExp(i,"g");const u=i.source.length,h=new TextDecoder,p=o.length;if(typeof l>"u"&&(l=p),a>=p||l<=0||a>=l)return-1;o=o.subarray(a,l);let f=-1,S=0,y=0,x="";e:for(;S<o.length;){const m=S+c,v=o.subarray(S,m),w=h.decode(v,{stream:!0}),C=x+w;let E,_=-1;for(;(E=i.exec(C))!==null;){_=E.index-x.length,f=y+_;break e}S=m,y+=w.length;const I=_>-1?_+u:w.length-u;x=w.slice(I)}return f>=0&&(f+=a>=0?a:p+a),f}const s=r(t,"IDAT",12);return s>=12?r(t,"acTL",8,s)>=8:!1}const gB=e=>new Uint8Array(e)[3]===44;/*!
|
|
36
|
-
* MIT License
|
|
37
|
-
* Modified code originally from <https://github.com/qzb/is-animated>
|
|
38
|
-
* Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
|
|
39
|
-
*/function Fb(e,t){let n=0;for(;e[t+n];)n+=e[t+n]+1;return n+1}function mB(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function yB(e){const t=new Uint8Array(e);let n,r,s=0,o=0;if(!mB(e))return!1;for(n=t[10]&128,r=t[10]&7,s+=6,s+=7,s+=n?3*Math.pow(2,r+1):0;o<2&&s<t.length;)switch(t[s]){case 44:o+=1,n=t[s+9]&128,r=t[s+9]&7,s+=10,s+=n?3*Math.pow(2,r+1):0,s+=Fb(t,s+1)+1;break;case 33:s+=2,s+=Fb(t,s);break;case 59:s=t.length;break;default:s=t.length;break}return o>1}let xS=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];typeof Int32Array<"u"&&(xS=new Int32Array(xS));/*!
|
|
40
|
-
* MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
|
|
41
|
-
* Copyright: 2014 Alex Gorbatchev
|
|
42
|
-
* Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
|
|
43
|
-
*/const SB=(e,t)=>{let n=~~t^-1;for(let r=0;r<e.length;r++)n=xS[(n^e[r])&255]^n>>>8;return n^-1},zb=4,Bb=4;class ls{static isPng(t,n){return t.getUint8(n+0)===137&&t.getUint8(n+1)===80&&t.getUint8(n+2)===78&&t.getUint8(n+3)===71&&t.getUint8(n+4)===13&&t.getUint8(n+5)===10&&t.getUint8(n+6)===26&&t.getUint8(n+7)===10}static getChunkType(t,n){return[String.fromCharCode(t.getUint8(n)),String.fromCharCode(t.getUint8(n+1)),String.fromCharCode(t.getUint8(n+2)),String.fromCharCode(t.getUint8(n+3))].join("")}static readChunks(t,n=0){const r={};if(!ls.isPng(t,n))throw new Error("Not a PNG");for(n+=8;n<=t.buffer.byteLength;){const s=n,o=t.getInt32(n);n+=4;const i=ls.getChunkType(t,n);if(i==="IDAT"&&r[i]){n+=o+zb+Bb;continue}if(i==="IEND")break;r[i]={start:s,dataOffset:n+4,size:o},n+=o+zb+Bb}return r}static parsePhys(t,n){return{ppux:t.getUint32(n),ppuy:t.getUint32(n+4),unit:t.getUint8(n+4)}}static findChunk(t,n){return ls.readChunks(t)[n]}static setPhysChunk(t,n=1,r){let s=46,o=0;const i=ls.findChunk(t,"pHYs");i&&(s=i.start,o=i.size);const a=ls.findChunk(t,"IDAT");a&&(s=a.start,o=0);const l=new ArrayBuffer(21),c=new DataView(l);c.setUint32(0,9),c.setUint8(4,112),c.setUint8(5,72),c.setUint8(6,89),c.setUint8(7,115);const u=2835.5;c.setInt32(8,u*n),c.setInt32(12,u*n),c.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));c.setInt32(17,SB(h));const p=t.buffer.slice(0,s),f=t.buffer.slice(s+o);return new Blob([p,l,f],r)}}/*!
|
|
44
|
-
* MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
|
|
45
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
46
|
-
*/function vB(e){return!e||e.length<12?!1:e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function xB(e){const t=new Uint8Array(e);return!vB(t)||!t||t.length<21?!1:(t[20]>>1&1)===1}const Bk=Object.freeze(["image/svg+xml"]),Uk=Object.freeze(["image/jpeg","image/png","image/webp"]),Hk=Object.freeze(["image/gif","image/apng","image/avif"]),Bx=Object.freeze([...Uk,...Bk,...Hk]),Kk=Object.freeze(["video/mp4","video/webm","video/quicktime"]),wB=[...Bx,...Kk].join(",");class ds{static loadVideo(t){return new Promise((n,r)=>{const s=document.createElement("video");s.onloadeddata=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load video"))},s.crossOrigin="anonymous",s.src=t})}static loadImage(t){return new Promise((n,r)=>{const s=ol();s.onload=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load image"))},s.crossOrigin="anonymous",s.referrerPolicy="strict-origin-when-cross-origin",s.src=t})}static async getVideoSize(t){return ds.usingObjectURL(t,async n=>{const r=await ds.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(t){const n=await ds.usingObjectURL(t,ds.loadImage);try{if(t.type==="image/png"){const r=new DataView(await t.arrayBuffer());if(ls.isPng(r,0)){const s=ls.findChunk(r,"pHYs");if(s){const o=ls.parsePhys(r,s.dataOffset);if(o.unit===0&&o.ppux===o.ppuy){const i=Math.max(o.ppux/2834.5,1);return{w:Math.round(n.naturalWidth/i),h:Math.round(n.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:n.naturalWidth,h:n.naturalHeight}}return{w:n.naturalWidth,h:n.naturalHeight}}static async isAnimated(t){return t.type==="image/gif"?yB(await t.arrayBuffer()):t.type==="image/avif"?gB(await t.arrayBuffer()):t.type==="image/webp"?xB(await t.arrayBuffer()):t.type==="image/apng"?fB(await t.arrayBuffer()):!1}static isAnimatedImageType(t){return Hk.includes(t||"")}static isStaticImageType(t){return Uk.includes(t||"")}static isVectorImageType(t){return Bk.includes(t||"")}static isImageType(t){return Bx.includes(t)}static async usingObjectURL(t,n){const r=URL.createObjectURL(t);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function On(e,t,n){return e+(t-e)*n}function qr(e=""){let t=0,n=0,r=0,s=0;function o(){const i=t^t<<11;return t=n,n=r,r=s,s^=(s>>>19^i^i>>>8)>>>0,s/4294967296*2}for(let i=0;i<e.length+64;i++)t^=e.charCodeAt(i)|0,o();return o}function il(e,t,n,r=!1){const[s,o]=t,[i,a]=n,l=i+(e-s)/(o-s)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function ms(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function $n(e,t){if(ms(e,t))return e[t]}function Ub(e){return Object.keys(e)}function gt(e){return Object.values(e)}function Bn(e){return Object.entries(e)}function Wk(e){return Object.fromEntries(e)}function $c(e,t){const n={};let r=!1;for(const[s,o]of Bn(e))t(s,o)?n[s]=o:r=!0;return r?n:e}function Bu(e,t){const n={};for(const[r,s]of Bn(e)){const o=t(r,s);n[r]=o}return n}function Gk(e,t){if(e===t)return!0;const n=new Set(Object.keys(e)),r=new Set(Object.keys(t));if(n.size!==r.size)return!1;for(const s of n)if(!r.has(s)||!Object.is(e[s],t[s]))return!1;return!0}const tr="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Vk="a0",Yk="A00000000000000000000000000";function Xk(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("Invalid index key head: "+e)}function qk(e){if(e.length!==Xk(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function Hb(e){if(e===void 0)throw Error("n is undefined")}function Kb(e){qk(e);const[t,...n]=e.split("");let r=!0;for(let s=n.length-1;r&&s>=0;s--){const o=tr.indexOf(n[s])+1;o===tr.length?n[s]="0":(n[s]=tr.charAt(o),r=!1)}if(r){if(t==="Z")return"a0";if(t==="z")return;const s=String.fromCharCode(t.charCodeAt(0)+1);return s>"a"?n.push("0"):n.pop(),s+n.join("")}else return t+n.join("")}function bB(e){qk(e);const[t,...n]=e.split("");let r=!0;for(let s=n.length-1;r&&s>=0;s--){const o=tr.indexOf(n[s])-1;o===-1?n[s]=tr.slice(-1):(n[s]=tr.charAt(o),r=!1)}if(r){if(t==="a")return"Z"+tr.slice(-1);if(t==="A")return;const s=String.fromCharCode(t.charCodeAt(0)-1);return s<"Z"?n.push(tr.slice(-1)):n.pop(),s+n.join("")}else return t+n.join("")}function ka(e,t){if(t!==void 0&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)==="0"||t&&t.slice(-1)==="0")throw new Error("trailing zero");if(t){let s=0;for(;(e.charAt(s)||"0")===t.charAt(s);)s++;if(s>0)return t.slice(0,s)+ka(e.slice(s),t.slice(s))}const n=e?tr.indexOf(e.charAt(0)):0,r=t!==void 0?tr.indexOf(t.charAt(0)):tr.length;if(r-n>1){const s=Math.round(.5*(n+r));return tr.charAt(s)}else return t&&t.length>1?t.slice(0,1):tr.charAt(n)+ka(e.slice(1),void 0)}function Sc(e){const t=Xk(e.charAt(0));if(t>e.length)throw new Error("invalid index: "+e);return e.slice(0,t)}function wS(e){if(e===Yk)throw new Error("invalid index: "+e);const t=Sc(e);if(e.slice(t.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function ha(e,t){if(e!==void 0&&wS(e),t!==void 0&&wS(t),e!==void 0&&t!==void 0&&e>=t)throw new Error(e+" >= "+t);if(e===void 0&&t===void 0)return Vk;if(e===void 0){if(t===void 0)throw Error("b is undefined");const a=Sc(t),l=t.slice(a.length);if(a===Yk)return a+ka("",l);if(a<t)return a;const c=bB(a);return Hb(c),c}if(t===void 0){const a=Sc(e),l=e.slice(a.length),c=Kb(a);return c===void 0?a+ka(l,void 0):c}const n=Sc(e),r=e.slice(n.length),s=Sc(t),o=t.slice(s.length);if(n===s)return n+ka(r,o);const i=Kb(n);return Hb(i),i<t?i:n+ka(r,void 0)}function Vo(e,t,n){if(n===0)return[];if(n===1)return[ha(e,t)];if(t===void 0){let o=ha(e,t);const i=[o];for(let a=0;a<n-1;a++)o=ha(o,t),i.push(o);return i}if(e===void 0){let o=ha(e,t);const i=[o];for(let a=0;a<n-1;a++)o=ha(e,o),i.push(o);return i.reverse(),i}const r=Math.floor(n/2),s=ha(e,t);return[...Vo(e,s,r),s,...Vo(s,t,n-r-1)]}const Zk=Vk;function PB(e){wS(e)}function al(e,t,n){return Vo(e,t,n)}function Pm(e,t){return Vo(e,void 0,t)}function ru(e,t){return Vo(e,t,1)[0]}function zr(e){return Vo(e,void 0,1)[0]}function CB(e){return Vo(void 0,e,1)[0]}function su(e,t="a1"){return[t,...Vo(t,void 0,e)]}function ln(e,t){return e.index<t.index?-1:e.index>t.index?1:0}function IB(e,t){return e.id>t.id?1:-1}function Ux(e){try{return localStorage.getItem(e)}catch{return null}}function Hx(e,t){try{localStorage.setItem(e,t)}catch{}}function EB(){try{localStorage.clear()}catch{}}function Qk(e){try{return sessionStorage.getItem(e)}catch{return null}}function Kx(e,t){try{sessionStorage.setItem(e,t)}catch{}}function Jk(e){try{sessionStorage.removeItem(e)}catch{}}function kB(){try{sessionStorage.clear()}catch{}}const _B=()=>typeof process<"u"&&!1,_a=[],TB=60,_h=Math.ceil(1e3/TB);let Gl,Cm=0,bS=0;const MB=()=>{const e=_a.splice(0,_a.length);for(const t of e)t()};function e_(){if(Gl)return;const e=Date.now(),t=e-bS;if(Cm+t<_h){Gl=requestAnimationFrame(()=>{Gl=void 0,e_()});return}Gl=requestAnimationFrame(()=>{Gl=void 0,bS=e,Cm=Math.min(Cm+t-_h,_h*10),MB()})}let Wb=!1;function t_(e){return _B()?(e(),()=>{}):(_a.includes(e)||(_a.push(e),Wb||(Wb=!0,bS=Date.now()-_h-1),e_()),()=>{const t=_a.indexOf(e);t>-1&&_a.splice(t,1)})}class AB{constructor(){g(this,"timeouts",[]);g(this,"intervals",[]);g(this,"rafs",[])}setTimeout(t,n,...r){const s=window.setTimeout(t,n,r);return this.timeouts.push(s),s}setInterval(t,n,...r){const s=window.setInterval(t,n,r);return this.intervals.push(s),s}requestAnimationFrame(t){const n=window.requestAnimationFrame(t);return this.rafs.push(n),n}dispose(){this.timeouts.forEach(t=>clearTimeout(t)),this.intervals.forEach(t=>clearInterval(t)),this.rafs.forEach(t=>cancelAnimationFrame(t)),this.timeouts.length=0,this.intervals.length=0,this.rafs.length=0}}function jB(e){return e!==null}function OB(){return typeof globalThis<"u"&&globalThis.structuredClone?[globalThis.structuredClone,!0]:typeof global<"u"&&global.structuredClone?[global.structuredClone,!0]:typeof window<"u"&&window.structuredClone?[window.structuredClone,!0]:[e=>e&&JSON.parse(JSON.stringify(e)),!1]}const n_=OB(),Ge=n_[0];n_[1];const DB=Object.getPrototypeOf(Ge({}));var Im={};const Wx={enableLicensing:RB("enableLicensing",{defaults:{all:!0,production:!1}})},r_=Tn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),xt={logPreventDefaults:Tn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Tn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Tn("logElementRemoves",{defaults:{all:!1}}),debugSvg:Tn("debugSvg",{defaults:{all:!1}}),showFps:Tn("showFps",{defaults:{all:!1}}),measurePerformance:Tn("measurePerformance",{defaults:{all:!1}}),throwToBlob:Tn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Tn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Tn("debugCursors",{defaults:{all:!1}}),forceSrgb:Tn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Tn("debugGeometry",{defaults:{all:!1}}),hideShapes:Tn("hideShapes",{defaults:{all:!1}}),editOnType:Tn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;ra("element removal logging",()=>{xt.logElementRemoves.get()?Element.prototype.removeChild=function(t){return console.warn("[tldraw] removing child:",t),e.call(this,t)}:Element.prototype.removeChild=e})}function Tn(e,{defaults:t,shouldStoreForSession:n=!0}){return s_({name:e,defaults:t,shouldStoreForSession:n})}function RB(e,{defaults:t,shouldStoreForSession:n=!0}){return s_({name:e,defaults:t,shouldStoreForSession:n})}function s_(e){const t=$B(e),n=e.shouldStoreForSession?LB(e.name):null,r=Mt(`debug:${e.name}`,n??t);return typeof window<"u"&&(e.shouldStoreForSession&&ra(`debug:${e.name}`,()=>{const s=r.get();s===t?Jk(`tldraw_debug:${e.name}`):Kx(`tldraw_debug:${e.name}`,JSON.stringify(s))}),Object.defineProperty(window,`tldraw${e.name.replace(/^[a-z]/,s=>s.toUpperCase())}`,{get(){return r.get()},set(s){r.set(s)},configurable:!0})),Object.assign(r,e)}function LB(e){try{return JSON.parse(Qk(`tldraw_debug:${e}`)??"null")}catch{return null}}function Em(e){try{return e()}catch{return null}}function $B(e){switch(Em(()=>Im.TLDRAW_ENV)??Em(()=>Im.VERCEL_PUBLIC_TLDRAW_ENV)??Em(()=>Im.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return e.defaults.production??e.defaults.all;case"preview":case"staging":return e.defaults.staging??e.defaults.all;default:return e.defaults.development??e.defaults.all}}class Th{constructor(t){g(this,"nextValue");g(this,"diff");this.previousValue=t}get(){var r,s,o,i;const t=((s=(r=this.diff)==null?void 0:r.removed)==null?void 0:s.size)??0,n=((i=(o=this.diff)==null?void 0:o.added)==null?void 0:i.size)??0;if(!(t===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(t,n){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(t),this.diff??(this.diff={}),n?(r=this.diff.removed)==null||r.delete(t):((s=this.diff).added??(s.added=new Set),this.diff.added.add(t))}add(t){var s,o,i;const n=this.previousValue.has(t);if(n)return((o=(s=this.diff)==null?void 0:s.removed)==null?void 0:o.has(t))?this._add(t,n):void 0;(i=this.nextValue)!=null&&i.has(t)||this._add(t,n)}_remove(t,n){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(t),this.diff??(this.diff={}),n?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(t)):(s=this.diff.added)==null||s.delete(t)}remove(t){var s,o,i,a;const n=this.previousValue.has(t);if(!n)return((o=(s=this.diff)==null?void 0:s.added)==null?void 0:o.has(t))?this._remove(t,n):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(t)||this._remove(t,n)}}let Uu=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");class Bf{constructor(t,n){g(this,"createDefaultProperties");g(this,"validator");g(this,"ephemeralKeys");g(this,"ephemeralKeySet");g(this,"scope");g(this,"isInstance",t=>(t==null?void 0:t.typeName)===this.typeName);this.typeName=t,this.createDefaultProperties=n.createDefaultProperties,this.validator=n.validator??{validate:s=>s},this.scope=n.scope??"document",this.ephemeralKeys=n.ephemeralKeys;const r=new Set;if(n.ephemeralKeys)for(const[s,o]of Bn(n.ephemeralKeys))o&&r.add(s);this.ephemeralKeySet=r}create(t){const n={...this.createDefaultProperties(),id:this.createId()};for(const[r,s]of Object.entries(t))s!==void 0&&(n[r]=s);return n.typeName=this.typeName,n}clone(t){return{...Ge(t),id:this.createId()}}createId(t){return this.typeName+":"+(t??Uu())}createCustomId(t){return this.typeName+":"+t}parseId(t){if(!this.isId(t))throw new Error(`ID "${t}" is not a valid ID for type "${this.typeName}"`);return t.slice(this.typeName.length+1)}isId(t){if(!t)return!1;for(let n=0;n<this.typeName.length;n++)if(t[n]!==this.typeName[n])return!1;return t[this.typeName.length]===":"}withDefaultProperties(t){return new Bf(this.typeName,{createDefaultProperties:t,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(t,n){return n&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(n,t):this.validator.validate(t)}}function _s(e,t){return new Bf(e,{createDefaultProperties:()=>({}),validator:t.validator,scope:t.scope,ephemeralKeys:t.ephemeralKeys})}function _p(){return{added:{},updated:{},removed:{}}}function PS(e){const t={added:e.removed,removed:e.added,updated:{}};for(const[n,r]of Object.values(e.updated))t.updated[n.id]=[r,n];return t}function o_(e){return Object.keys(e.added).length===0&&Object.keys(e.updated).length===0&&Object.keys(e.removed).length===0}function Gx(e){const t={added:{},removed:{},updated:{}};return Nc(t,e),t}function Nc(e,t){for(const n of t){for(const[r,s]of Bn(n.added))if(e.removed[r]){const o=e.removed[r];delete e.removed[r],o!==s&&(e.updated[r]=[o,s])}else e.added[r]=s;for(const[r,[s,o]]of Bn(n.updated)){if(e.added[r]){e.added[r]=o,delete e.updated[r],delete e.removed[r];continue}if(e.updated[r]){e.updated[r]=[e.updated[r][0],o],delete e.removed[r];continue}e.updated[r]=n.updated[r],delete e.removed[r]}for(const[r,s]of Bn(n.removed))e.added[r]?delete e.added[r]:e.updated[r]?(e.removed[r]=e.updated[r][0],delete e.updated[r]):e.removed[r]=s}}var Tp={exports:{}};Tp.exports;(function(e,t){var n=200,r="__lodash_hash_undefined__",s=1,o=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",p="[object Error]",f="[object Function]",S="[object GeneratorFunction]",y="[object Map]",x="[object Number]",m="[object Null]",v="[object Object]",w="[object Promise]",C="[object Proxy]",E="[object RegExp]",_="[object Set]",I="[object String]",k="[object Symbol]",T="[object Undefined]",M="[object WeakMap]",D="[object ArrayBuffer]",$="[object DataView]",j="[object Float32Array]",O="[object Float64Array]",R="[object Int8Array]",H="[object Int16Array]",B="[object Int32Array]",z="[object Uint8Array]",W="[object Uint8ClampedArray]",Y="[object Uint16Array]",q="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,be=/^(?:0|[1-9]\d*)$/,J={};J[j]=J[O]=J[R]=J[H]=J[B]=J[z]=J[W]=J[Y]=J[q]=!0,J[a]=J[l]=J[D]=J[u]=J[$]=J[h]=J[p]=J[f]=J[y]=J[x]=J[v]=J[E]=J[_]=J[I]=J[M]=!1;var Ue=typeof cn=="object"&&cn&&cn.Object===Object&&cn,Oe=typeof self=="object"&&self&&self.Object===Object&&self,nt=Ue||Oe||Function("return this")(),je=t&&!t.nodeType&&t,it=je&&!0&&e&&!e.nodeType&&e,Fe=it&&it.exports===je,Xn=Fe&&Ue.process,Nt=function(){try{return Xn&&Xn.binding&&Xn.binding("util")}catch{}}(),_n=Nt&&Nt.isTypedArray;function St(A,L){for(var V=-1,ee=A==null?0:A.length,Ze=0,me=[];++V<ee;){var ft=A[V];L(ft,V,A)&&(me[Ze++]=ft)}return me}function Qt(A,L){for(var V=-1,ee=L.length,Ze=A.length;++V<ee;)A[Ze+V]=L[V];return A}function As(A,L){for(var V=-1,ee=A==null?0:A.length;++V<ee;)if(L(A[V],V,A))return!0;return!1}function Nl(A,L){for(var V=-1,ee=Array(A);++V<A;)ee[V]=L(V);return ee}function mo(A){return function(L){return A(L)}}function hL(A,L){return A.has(L)}function pL(A,L){return A==null?void 0:A[L]}function fL(A){var L=-1,V=Array(A.size);return A.forEach(function(ee,Ze){V[++L]=[Ze,ee]}),V}function gL(A,L){return function(V){return A(L(V))}}function mL(A){var L=-1,V=Array(A.size);return A.forEach(function(ee){V[++L]=ee}),V}var yL=Array.prototype,SL=Function.prototype,dd=Object.prototype,Kg=nt["__core-js_shared__"],x1=SL.toString,ts=dd.hasOwnProperty,w1=function(){var A=/[^.]+$/.exec(Kg&&Kg.keys&&Kg.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),b1=dd.toString,vL=RegExp("^"+x1.call(ts).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),P1=Fe?nt.Buffer:void 0,hd=nt.Symbol,C1=nt.Uint8Array,I1=dd.propertyIsEnumerable,xL=yL.splice,gi=hd?hd.toStringTag:void 0,E1=Object.getOwnPropertySymbols,wL=P1?P1.isBuffer:void 0,bL=gL(Object.keys,Object),Wg=ca(nt,"DataView"),Fl=ca(nt,"Map"),Gg=ca(nt,"Promise"),Vg=ca(nt,"Set"),Yg=ca(nt,"WeakMap"),zl=ca(Object,"create"),PL=Si(Wg),CL=Si(Fl),IL=Si(Gg),EL=Si(Vg),kL=Si(Yg),k1=hd?hd.prototype:void 0,Xg=k1?k1.valueOf:void 0;function mi(A){var L=-1,V=A==null?0:A.length;for(this.clear();++L<V;){var ee=A[L];this.set(ee[0],ee[1])}}function _L(){this.__data__=zl?zl(null):{},this.size=0}function TL(A){var L=this.has(A)&&delete this.__data__[A];return this.size-=L?1:0,L}function ML(A){var L=this.__data__;if(zl){var V=L[A];return V===r?void 0:V}return ts.call(L,A)?L[A]:void 0}function AL(A){var L=this.__data__;return zl?L[A]!==void 0:ts.call(L,A)}function jL(A,L){var V=this.__data__;return this.size+=this.has(A)?0:1,V[A]=zl&&L===void 0?r:L,this}mi.prototype.clear=_L,mi.prototype.delete=TL,mi.prototype.get=ML,mi.prototype.has=AL,mi.prototype.set=jL;function js(A){var L=-1,V=A==null?0:A.length;for(this.clear();++L<V;){var ee=A[L];this.set(ee[0],ee[1])}}function OL(){this.__data__=[],this.size=0}function DL(A){var L=this.__data__,V=fd(L,A);if(V<0)return!1;var ee=L.length-1;return V==ee?L.pop():xL.call(L,V,1),--this.size,!0}function RL(A){var L=this.__data__,V=fd(L,A);return V<0?void 0:L[V][1]}function LL(A){return fd(this.__data__,A)>-1}function $L(A,L){var V=this.__data__,ee=fd(V,A);return ee<0?(++this.size,V.push([A,L])):V[ee][1]=L,this}js.prototype.clear=OL,js.prototype.delete=DL,js.prototype.get=RL,js.prototype.has=LL,js.prototype.set=$L;function yi(A){var L=-1,V=A==null?0:A.length;for(this.clear();++L<V;){var ee=A[L];this.set(ee[0],ee[1])}}function NL(){this.size=0,this.__data__={hash:new mi,map:new(Fl||js),string:new mi}}function FL(A){var L=gd(this,A).delete(A);return this.size-=L?1:0,L}function zL(A){return gd(this,A).get(A)}function BL(A){return gd(this,A).has(A)}function UL(A,L){var V=gd(this,A),ee=V.size;return V.set(A,L),this.size+=V.size==ee?0:1,this}yi.prototype.clear=NL,yi.prototype.delete=FL,yi.prototype.get=zL,yi.prototype.has=BL,yi.prototype.set=UL;function pd(A){var L=-1,V=A==null?0:A.length;for(this.__data__=new yi;++L<V;)this.add(A[L])}function HL(A){return this.__data__.set(A,r),this}function KL(A){return this.__data__.has(A)}pd.prototype.add=pd.prototype.push=HL,pd.prototype.has=KL;function yo(A){var L=this.__data__=new js(A);this.size=L.size}function WL(){this.__data__=new js,this.size=0}function GL(A){var L=this.__data__,V=L.delete(A);return this.size=L.size,V}function VL(A){return this.__data__.get(A)}function YL(A){return this.__data__.has(A)}function XL(A,L){var V=this.__data__;if(V instanceof js){var ee=V.__data__;if(!Fl||ee.length<n-1)return ee.push([A,L]),this.size=++V.size,this;V=this.__data__=new yi(ee)}return V.set(A,L),this.size=V.size,this}yo.prototype.clear=WL,yo.prototype.delete=GL,yo.prototype.get=VL,yo.prototype.has=YL,yo.prototype.set=XL;function qL(A,L){var V=md(A),ee=!V&&d3(A),Ze=!V&&!ee&&qg(A),me=!V&&!ee&&!Ze&&L1(A),ft=V||ee||Ze||me,kt=ft?Nl(A.length,String):[],Ft=kt.length;for(var at in A)ts.call(A,at)&&!(ft&&(at=="length"||Ze&&(at=="offset"||at=="parent")||me&&(at=="buffer"||at=="byteLength"||at=="byteOffset")||i3(at,Ft)))&&kt.push(at);return kt}function fd(A,L){for(var V=A.length;V--;)if(j1(A[V][0],L))return V;return-1}function ZL(A,L,V){var ee=L(A);return md(A)?ee:Qt(ee,V(A))}function Bl(A){return A==null?A===void 0?T:m:gi&&gi in Object(A)?s3(A):u3(A)}function _1(A){return Ul(A)&&Bl(A)==a}function T1(A,L,V,ee,Ze){return A===L?!0:A==null||L==null||!Ul(A)&&!Ul(L)?A!==A&&L!==L:QL(A,L,V,ee,T1,Ze)}function QL(A,L,V,ee,Ze,me){var ft=md(A),kt=md(L),Ft=ft?l:So(A),at=kt?l:So(L);Ft=Ft==a?v:Ft,at=at==a?v:at;var qn=Ft==v,Or=at==v,Jt=Ft==at;if(Jt&&qg(A)){if(!qg(L))return!1;ft=!0,qn=!1}if(Jt&&!qn)return me||(me=new yo),ft||L1(A)?M1(A,L,V,ee,Ze,me):n3(A,L,Ft,V,ee,Ze,me);if(!(V&s)){var gr=qn&&ts.call(A,"__wrapped__"),mr=Or&&ts.call(L,"__wrapped__");if(gr||mr){var vo=gr?A.value():A,Os=mr?L.value():L;return me||(me=new yo),Ze(vo,Os,V,ee,me)}}return Jt?(me||(me=new yo),r3(A,L,V,ee,Ze,me)):!1}function JL(A){if(!R1(A)||l3(A))return!1;var L=O1(A)?vL:ge;return L.test(Si(A))}function e3(A){return Ul(A)&&D1(A.length)&&!!J[Bl(A)]}function t3(A){if(!c3(A))return bL(A);var L=[];for(var V in Object(A))ts.call(A,V)&&V!="constructor"&&L.push(V);return L}function M1(A,L,V,ee,Ze,me){var ft=V&s,kt=A.length,Ft=L.length;if(kt!=Ft&&!(ft&&Ft>kt))return!1;var at=me.get(A);if(at&&me.get(L))return at==L;var qn=-1,Or=!0,Jt=V&o?new pd:void 0;for(me.set(A,L),me.set(L,A);++qn<kt;){var gr=A[qn],mr=L[qn];if(ee)var vo=ft?ee(mr,gr,qn,L,A,me):ee(gr,mr,qn,A,L,me);if(vo!==void 0){if(vo)continue;Or=!1;break}if(Jt){if(!As(L,function(Os,vi){if(!hL(Jt,vi)&&(gr===Os||Ze(gr,Os,V,ee,me)))return Jt.push(vi)})){Or=!1;break}}else if(!(gr===mr||Ze(gr,mr,V,ee,me))){Or=!1;break}}return me.delete(A),me.delete(L),Or}function n3(A,L,V,ee,Ze,me,ft){switch(V){case $:if(A.byteLength!=L.byteLength||A.byteOffset!=L.byteOffset)return!1;A=A.buffer,L=L.buffer;case D:return!(A.byteLength!=L.byteLength||!me(new C1(A),new C1(L)));case u:case h:case x:return j1(+A,+L);case p:return A.name==L.name&&A.message==L.message;case E:case I:return A==L+"";case y:var kt=fL;case _:var Ft=ee&s;if(kt||(kt=mL),A.size!=L.size&&!Ft)return!1;var at=ft.get(A);if(at)return at==L;ee|=o,ft.set(A,L);var qn=M1(kt(A),kt(L),ee,Ze,me,ft);return ft.delete(A),qn;case k:if(Xg)return Xg.call(A)==Xg.call(L)}return!1}function r3(A,L,V,ee,Ze,me){var ft=V&s,kt=A1(A),Ft=kt.length,at=A1(L),qn=at.length;if(Ft!=qn&&!ft)return!1;for(var Or=Ft;Or--;){var Jt=kt[Or];if(!(ft?Jt in L:ts.call(L,Jt)))return!1}var gr=me.get(A);if(gr&&me.get(L))return gr==L;var mr=!0;me.set(A,L),me.set(L,A);for(var vo=ft;++Or<Ft;){Jt=kt[Or];var Os=A[Jt],vi=L[Jt];if(ee)var $1=ft?ee(vi,Os,Jt,L,A,me):ee(Os,vi,Jt,A,L,me);if(!($1===void 0?Os===vi||Ze(Os,vi,V,ee,me):$1)){mr=!1;break}vo||(vo=Jt=="constructor")}if(mr&&!vo){var yd=A.constructor,Sd=L.constructor;yd!=Sd&&"constructor"in A&&"constructor"in L&&!(typeof yd=="function"&&yd instanceof yd&&typeof Sd=="function"&&Sd instanceof Sd)&&(mr=!1)}return me.delete(A),me.delete(L),mr}function A1(A){return ZL(A,f3,o3)}function gd(A,L){var V=A.__data__;return a3(L)?V[typeof L=="string"?"string":"hash"]:V.map}function ca(A,L){var V=pL(A,L);return JL(V)?V:void 0}function s3(A){var L=ts.call(A,gi),V=A[gi];try{A[gi]=void 0;var ee=!0}catch{}var Ze=b1.call(A);return ee&&(L?A[gi]=V:delete A[gi]),Ze}var o3=E1?function(A){return A==null?[]:(A=Object(A),St(E1(A),function(L){return I1.call(A,L)}))}:g3,So=Bl;(Wg&&So(new Wg(new ArrayBuffer(1)))!=$||Fl&&So(new Fl)!=y||Gg&&So(Gg.resolve())!=w||Vg&&So(new Vg)!=_||Yg&&So(new Yg)!=M)&&(So=function(A){var L=Bl(A),V=L==v?A.constructor:void 0,ee=V?Si(V):"";if(ee)switch(ee){case PL:return $;case CL:return y;case IL:return w;case EL:return _;case kL:return M}return L});function i3(A,L){return L=L??i,!!L&&(typeof A=="number"||be.test(A))&&A>-1&&A%1==0&&A<L}function a3(A){var L=typeof A;return L=="string"||L=="number"||L=="symbol"||L=="boolean"?A!=="__proto__":A===null}function l3(A){return!!w1&&w1 in A}function c3(A){var L=A&&A.constructor,V=typeof L=="function"&&L.prototype||dd;return A===V}function u3(A){return b1.call(A)}function Si(A){if(A!=null){try{return x1.call(A)}catch{}try{return A+""}catch{}}return""}function j1(A,L){return A===L||A!==A&&L!==L}var d3=_1(function(){return arguments}())?_1:function(A){return Ul(A)&&ts.call(A,"callee")&&!I1.call(A,"callee")},md=Array.isArray;function h3(A){return A!=null&&D1(A.length)&&!O1(A)}var qg=wL||m3;function p3(A,L){return T1(A,L)}function O1(A){if(!R1(A))return!1;var L=Bl(A);return L==f||L==S||L==c||L==C}function D1(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function R1(A){var L=typeof A;return A!=null&&(L=="object"||L=="function")}function Ul(A){return A!=null&&typeof A=="object"}var L1=_n?mo(_n):e3;function f3(A){return h3(A)?qL(A):t3(A)}function g3(){return[]}function m3(){return!1}e.exports=p3})(Tp,Tp.exports);var NB=Tp.exports;const FB=ni(NB);function zB(e){if(e.length===0)return new Set;const t=e[0],n=e.slice(1),r=new Set;for(const s of t)n.every(o=>o.has(s))&&r.add(s);return r}function BB(e,t){const n={};for(const r of t)e.has(r)||(n.added??(n.added=new Set),n.added.add(r));for(const r of e)t.has(r)||(n.removed??(n.removed=new Set),n.removed.add(r));return n.added||n.removed?n:void 0}function Gb(e,t){for(const[n,r]of Object.entries(e)){const s=r,o=t[n];if("eq"in s&&o!==s.eq||"neq"in s&&o===s.neq||"gt"in s&&(typeof o!="number"||o<=s.gt))return!1}return!0}function Vb(e,t,n){const r=Object.fromEntries(Object.keys(n).map(s=>[s,new Set]));for(const[s,o]of Object.entries(n))if("eq"in o){const a=e.index(t,s).get().get(o.eq);if(a)for(const l of a)r[s].add(l)}else if("neq"in o){const i=e.index(t,s);for(const[a,l]of i.get())if(a!==o.neq)for(const c of l)r[s].add(c)}else if("gt"in o){const i=e.index(t,s);for(const[a,l]of i.get())if(a>o.gt)for(const c of l)r[s].add(c)}return zB(Object.values(r))}class UB{constructor(t,n){g(this,"indexCache",new Map);g(this,"historyCache",new Map);this.atoms=t,this.history=n}filterHistory(t){if(this.historyCache.has(t))return this.historyCache.get(t);const n=G("filterHistory:"+t,(r,s)=>{if(Mi(r))return this.history.get();const o=this.history.getDiffSince(s);if(o===rr)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of o){for(const h of gt(u.added))if(h.typeName===t)if(i.removed[h.id]){const p=i.removed[h.id];delete i.removed[h.id],l--,p!==h&&(i.updated[h.id]=[p,h],c++)}else i.added[h.id]=h,a++;for(const[h,p]of gt(u.updated))p.typeName===t&&(i.added[p.id]?i.added[p.id]=p:i.updated[p.id]?i.updated[p.id]=[i.updated[p.id][0],p]:(i.updated[p.id]=[h,p],c++));for(const h of gt(u.removed))h.typeName===t&&(i.added[h.id]?(delete i.added[h.id],a--):i.updated[h.id]?(i.removed[h.id]=i.updated[h.id][0],delete i.updated[h.id],c--,l++):(i.removed[h.id]=h,l++))}return a||l||c?mc(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(t,n),n}index(t,n){const r=t+":"+n;if(this.indexCache.has(r))return this.indexCache.get(r);const s=this.__uncached_createIndex(t,n);return this.indexCache.set(r,s),s}__uncached_createIndex(t,n){const r=this.filterHistory(t),s=()=>{r.get();const o=new Map;for(const i of gt(this.atoms.get())){const a=i.get();if(a.typeName===t){const l=a[n];o.has(l)||o.set(l,new Set),o.get(l).add(a.id)}}return o};return G("index:"+t+":"+n,(o,i)=>{if(Mi(o))return s();const a=r.getDiffSince(i);if(a===rr)return s();const l=new Map,c=(f,S)=>{let y=l.get(f);y||(y=new Th(o.get(f)??new Set)),y.add(S),l.set(f,y)},u=(f,S)=>{let y=l.get(f);y||(y=new Th(o.get(f)??new Set)),y.remove(S),l.set(f,y)};for(const f of a){for(const S of gt(f.added))if(S.typeName===t){const y=S[n];c(y,S.id)}for(const[S,y]of gt(f.updated))if(y.typeName===t){const x=S[n],m=y[n];x!==m&&(u(x,y.id),c(m,y.id))}for(const S of gt(f.removed))if(S.typeName===t){const y=S[n];u(y,S.id)}}let h,p;for(const[f,S]of l){const y=S.get();y&&(h||(h=new Map(o)),p||(p=new Map),y.value.size===0?h.delete(f):h.set(f,y.value),p.set(f,y.diff))}return h&&p?mc(h,p):o},{historyLength:100})}record(t,n=()=>({}),r="record:"+t+(n?":"+n.toString():"")){const s=this.ids(t,n,r);return G(r,()=>{var o;for(const i of s.get())return(o=this.atoms.get()[i])==null?void 0:o.get()})}records(t,n=()=>({}),r="records:"+t+(n?":"+n.toString():"")){const s=this.ids(t,n,"ids:"+r);return G(r,()=>[...s.get()].map(o=>{const i=this.atoms.get()[o];if(!i)throw new Error("no atom found for record id: "+o);return i.get()}))}ids(t,n=()=>({}),r="ids:"+t+(n?":"+n.toString():"")){const s=this.filterHistory(t),o=()=>{s.get();const l=n();return Object.keys(l).length===0?new Set(gt(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===t?u.id:[]})):Vb(this,t,l)},i=l=>{const c=o(),u=BB(l,c);return u?mc(c,u):l},a=G("ids_query:"+r,n,{isEqual:FB});return G("query:"+r,(l,c)=>{const u=a.get();if(Mi(l))return o();if(c<a.lastChangedEpoch)return i(l);const h=s.getDiffSince(c);if(h===rr)return i(l);const p=new Th(l);for(const S of h){for(const y of gt(S.added))y.typeName===t&&Gb(u,y)&&p.add(y.id);for(const[y,x]of gt(S.updated))x.typeName===t&&(Gb(u,x)?p.add(x.id):p.remove(x.id));for(const y of gt(S.removed))y.typeName===t&&p.remove(y.id)}const f=p.get();return f?mc(f.value,f.diff):l},{historyLength:50})}exec(t,n){const r=Vb(this,t,n);if(r.size===0)return Gs;const s=this.atoms.get();return[...r].map(o=>s[o].get())}}class HB{constructor(t){g(this,"_beforeCreateHandlers",{});g(this,"_afterCreateHandlers",{});g(this,"_beforeChangeHandlers",{});g(this,"_afterChangeHandlers",{});g(this,"_beforeDeleteHandlers",{});g(this,"_afterDeleteHandlers",{});g(this,"_operationCompleteHandlers",[]);g(this,"_isEnabled",!0);this.store=t}isEnabled(){return this._isEnabled}setIsEnabled(t){this._isEnabled=t}handleBeforeCreate(t,n){if(!this._isEnabled)return t;const r=this._beforeCreateHandlers[t.typeName];if(r){let s=t;for(const o of r)s=o(s,n);return s}return t}handleAfterCreate(t,n){if(!this._isEnabled)return;const r=this._afterCreateHandlers[t.typeName];if(r)for(const s of r)s(t,n)}handleBeforeChange(t,n,r){if(!this._isEnabled)return n;const s=this._beforeChangeHandlers[n.typeName];if(s){let o=n;for(const i of s)o=i(t,o,r);return o}return n}handleAfterChange(t,n,r){if(!this._isEnabled)return;const s=this._afterChangeHandlers[n.typeName];if(s)for(const o of s)o(t,n,r)}handleBeforeDelete(t,n){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[t.typeName];if(r){for(const s of r)if(s(t,n)===!1)return!1}return!0}handleAfterDelete(t,n){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[t.typeName];if(r)for(const s of r)s(t,n)}handleOperationComplete(t){if(this._isEnabled)for(const n of this._operationCompleteHandlers)n(t)}register(t){const n=[];for(const[r,s]of Object.entries(t))s!=null&&s.beforeCreate&&n.push(this.registerBeforeCreateHandler(r,s.beforeCreate)),s!=null&&s.afterCreate&&n.push(this.registerAfterCreateHandler(r,s.afterCreate)),s!=null&&s.beforeChange&&n.push(this.registerBeforeChangeHandler(r,s.beforeChange)),s!=null&&s.afterChange&&n.push(this.registerAfterChangeHandler(r,s.afterChange)),s!=null&&s.beforeDelete&&n.push(this.registerBeforeDeleteHandler(r,s.beforeDelete)),s!=null&&s.afterDelete&&n.push(this.registerAfterDeleteHandler(r,s.afterDelete));return()=>{for(const r of n)r()}}registerBeforeCreateHandler(t,n){return this._beforeCreateHandlers[t]||(this._beforeCreateHandlers[t]=[]),this._beforeCreateHandlers[t].push(n),()=>xi(this._beforeCreateHandlers[t],n)}registerAfterCreateHandler(t,n){return this._afterCreateHandlers[t]||(this._afterCreateHandlers[t]=[]),this._afterCreateHandlers[t].push(n),()=>xi(this._afterCreateHandlers[t],n)}registerBeforeChangeHandler(t,n){return this._beforeChangeHandlers[t]||(this._beforeChangeHandlers[t]=[]),this._beforeChangeHandlers[t].push(n),()=>xi(this._beforeChangeHandlers[t],n)}registerAfterChangeHandler(t,n){return this._afterChangeHandlers[t]||(this._afterChangeHandlers[t]=[]),this._afterChangeHandlers[t].push(n),()=>xi(this._afterChangeHandlers[t],n)}registerBeforeDeleteHandler(t,n){return this._beforeDeleteHandlers[t]||(this._beforeDeleteHandlers[t]=[]),this._beforeDeleteHandlers[t].push(n),()=>xi(this._beforeDeleteHandlers[t],n)}registerAfterDeleteHandler(t,n){return this._afterDeleteHandlers[t]||(this._afterDeleteHandlers[t]=[]),this._afterDeleteHandlers[t].push(n),()=>xi(this._afterDeleteHandlers[t],n)}registerOperationCompleteHandler(t){return this._operationCompleteHandlers.push(t),()=>xi(this._operationCompleteHandlers,t)}}function xi(e,t){const n=e.indexOf(t);n>=0&&e.splice(n,1)}class Vx{constructor(t){g(this,"id");g(this,"atoms",Mt("store_atoms",{}));g(this,"history",Mt("history",0,{historyLength:1e3}));g(this,"query",new UB(this.atoms,this.history));g(this,"listeners",new Set);g(this,"historyAccumulator",new WB);g(this,"historyReactor");g(this,"cancelHistoryReactor",()=>{});g(this,"schema");g(this,"props");g(this,"scopedTypes");g(this,"sideEffects",new HB(this));g(this,"put",(t,n)=>{this.atomic(()=>{const r={},s={},o=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.isMergingRemoteChanges?"remote":"user";for(let u=0,h=t.length;u<h;u++){a=t[u];const p=(i??o)[a.id];if(p){const f=p.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(f,a,c),this.schema.validateRecord(this,a,n??"updateRecord",f)===f)continue;p.set(a),l=!0;const y=p.__unsafe__getWithoutCapture();r[a.id]=[f,y],this.addDiffForAfterEvent(f,y)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),s[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...o}),i[a.id]=Mt("atom:"+a.id,a)}i&&this.atoms.set(i),l&&this.updateHistory({added:s,updated:r,removed:{}})})});g(this,"remove",t=>{this.atomic(()=>{const n=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const o of t){const i=this.atoms.__unsafe__getWithoutCapture()[o];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&n.add(o)}let s;this.atoms.update(o=>{let i;for(const a of t){if(n.has(a)||!(a in o))continue;i||(i={...o}),s||(s={}),delete i[a];const l=o[a].get();s[a]=l,this.addDiffForAfterEvent(l,null)}return i??o}),s&&this.updateHistory({added:{},updated:{},removed:s})})});g(this,"get",t=>{var n;return(n=this.atoms.get()[t])==null?void 0:n.get()});g(this,"unsafeGetWithoutCapture",t=>{var n;return(n=this.atoms.get()[t])==null?void 0:n.__unsafe__getWithoutCapture()});g(this,"serialize",(t="document")=>{const n={};for(const[r,s]of Bn(this.atoms.get())){const o=s.get();(t==="all"||this.scopedTypes[t].has(o.typeName))&&(n[r]=o)}return n});g(this,"allRecords",()=>gt(this.atoms.get()).map(t=>t.get()));g(this,"clear",()=>{this.remove(Ub(this.atoms.get()))});g(this,"update",(t,n)=>{const r=this.atoms.get()[t];if(!r){console.error(`Record ${t} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])});g(this,"has",t=>!!this.atoms.get()[t]);g(this,"listen",(t,n)=>{this._flushHistory();const r={onHistory:t,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.listeners.add(r),this.historyReactor.scheduler.isActivelyListening||this.historyReactor.start(),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}});g(this,"isMergingRemoteChanges",!1);g(this,"mergeRemoteChanges",t=>{if(this.isMergingRemoteChanges)return t();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,gs(t)}finally{this.isMergingRemoteChanges=!1}});g(this,"createComputedCache",(t,n,r)=>{const s=new Zs;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=r?G(i.name+":equals",()=>i.get(),{isEqual:r}):i;return G(t+":"+o,()=>n(a.get()))}).get()}}});g(this,"createSelectedComputedCache",(t,n,r)=>{const s=new Zs;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=G(t+":"+o+":selector",()=>n(i.get()));return G(t+":"+o,()=>r(a.get()))}).get()}}});g(this,"_integrityChecker");g(this,"_isPossiblyCorrupted",!1);g(this,"pendingAfterEvents",null);g(this,"_isInAtomicOp",!1);const{initialData:n,schema:r,id:s}=t;this.id=s??Uu(),this.schema=r,this.props=t.props,n&&this.atoms.set(Wk(Bn(n).map(([o,i])=>[o,Mt("atom:"+o,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=R6("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>this.cancelHistoryReactor=t_(o)}),this.scopedTypes={document:new Set(gt(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(gt(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(gt(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const t=this.historyAccumulator.flush();for(const{changes:n,source:r}of t){let s=null,o=null,i=null;for(const{onHistory:a,filters:l}of this.listeners)if(!(l.source!=="all"&&l.source!==r))if(l.scope!=="all")if(l.scope==="document"){if(o??(o=this.filterChangesByScope(n,"document")),!o)continue;a({changes:o,source:r})}else if(l.scope==="session"){if(s??(s=this.filterChangesByScope(n,"session")),!s)continue;a({changes:s,source:r})}else{if(i??(i=this.filterChangesByScope(n,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:n,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(t,n){const r={added:$c(t.added,(s,o)=>this.scopedTypes[n].has(o.typeName)),updated:$c(t.updated,(s,o)=>this.scopedTypes[n].has(o[1].typeName)),removed:$c(t.removed,(s,o)=>this.scopedTypes[n].has(o.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(t){this.historyAccumulator.add({changes:t,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,t)}validate(t){this.allRecords().forEach(n=>this.schema.validateRecord(this,n,t,null))}getStoreSnapshot(t="document"){return{store:this.serialize(t),schema:this.schema.serialize()}}getSnapshot(t="document"){return console.warn("[tldraw] `Store.getSnapshot` is deprecated and will be removed in a future release. Use `getSnapshot` from the `tldraw` package instead."),this.getStoreSnapshot(t)}migrateSnapshot(t){const n=this.schema.migrateStoreSnapshot(t);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);return{store:n.value,schema:this.schema.serialize()}}loadStoreSnapshot(t){const n=this.schema.migrateStoreSnapshot(t);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(n.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}loadSnapshot(t){console.warn("[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead."),this.loadStoreSnapshot(t)}extractingChanges(t){const n=[],r=this.historyAccumulator.addInterceptor(s=>n.push(s.changes));try{return gs(t),Gx(n)}finally{r()}}applyDiff(t,{runCallbacks:n=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=gt(t.added);for(const[i,a]of gt(t.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){s.push(a);continue}let u=null;for(const[h,p]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(p,$n(c,h))||(u||(u={...c}),u[h]=p);u&&s.push(u)}else s.push(a)}const o=Ub(t.removed);s.length&&this.put(s),o.length&&this.remove(o)},n)}ensureStoreIsUsable(){this.atomic(()=>{var t;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(t=this._integrityChecker)==null||t.call(this)})}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}addDiffForAfterEvent(t,n){if(Xe(this.pendingAfterEvents,"must be in event operation"),t===n||(t&&n&&Xe(t.id===n.id),!t&&!n))return;const r=(t||n).id,s=this.pendingAfterEvents.get(r);s?s.after=n:this.pendingAfterEvents.set(r,{before:t,after:n})}flushAtomicCallbacks(){let t=0;const n=this.isMergingRemoteChanges?"remote":"user";for(;this.pendingAfterEvents;){const r=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(t++,t>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:s,after:o}of r.values())s&&o?this.sideEffects.handleAfterChange(s,o,n):s&&!o?this.sideEffects.handleAfterDelete(s,n):!s&&o&&this.sideEffects.handleAfterCreate(o,n);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(n)}}}atomic(t,n=!0){return gs(()=>{if(this._isInAtomicOp)return this.pendingAfterEvents||(this.pendingAfterEvents=new Map),t();this.pendingAfterEvents=new Map;const r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(n??r),this._isInAtomicOp=!0;try{const s=t();return this.flushAtomicCallbacks(),s}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(r),this._isInAtomicOp=!1}})}addHistoryInterceptor(t){return this.historyAccumulator.addInterceptor(n=>t(n,this.isMergingRemoteChanges?"remote":"user"))}}function KB(e){if(e.length===0)return[];const t=[];let n=[e[0]],r;for(let s=1,o=e.length;s<o;s++)r=e[s],n[0].source!==r.source&&(t.push(n),n=[]),n.push(r);return t.push(n),t.map(s=>({source:s[0].source,changes:Gx(s.map(o=>o.changes))}))}class WB{constructor(){g(this,"_history",[]);g(this,"_interceptors",new Set)}addInterceptor(t){return this._interceptors.add(t),()=>{this._interceptors.delete(t)}}add(t){this._history.push(t);for(const n of this._interceptors)n(t)}flush(){const t=KB(this._history);return this._history=[],t}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function GB(e,t,n){const r=new Zs;return{get(s,o){return r.get(s,()=>(s instanceof Vx?s:s.store).createComputedCache(e,l=>t(s,l),n)).get(o)}}}function VB(e){const t=[];for(let n=e.length-1;n>=0;n--){const r=e[n];if("id"in r)t.unshift(r);else{const s=r.dependsOn,o=t[0];o&&(t[0]={...o,dependsOn:s.concat(o.dependsOn??[])})}}return t}function Va({sequence:e,sequenceId:t,retroactive:n=!0}){const r={sequenceId:t,retroactive:n,sequence:VB(e)};return i_(r),r}function Vn(e,t){return Object.fromEntries(Bn(t).map(([n,r])=>[n,`${e}/${r}`]))}function dr(e){const t=e.sequenceId;return Va({sequenceId:t,retroactive:e.retroactive??!0,sequence:e.sequence.map(n=>"id"in n?{...n,scope:"record",filter:r=>{var s,o;return r.typeName===e.recordType&&(((s=n.filter)==null?void 0:s.call(n,r))??!0)&&(((o=e.filter)==null?void 0:o.call(e,r))??!0)}}:n)})}function YB(e){const t=new Map(e.map(o=>[o.id,o])),n=new Set,r=[];function s(o){Xe(!n.has(o.id),`Circular dependency in migrations: ${o.id}`),n.add(o.id);const{version:i,sequenceId:a}=Mp(o.id),l=t.get(`${a}/${i-1}`);if(l&&s(l),o.dependsOn)for(const c of o.dependsOn){const u=t.get(c);u&&s(u)}t.delete(o.id),r.push(o)}for(const o of t.values())s(o);return r}function Mp(e){const[t,n]=e.split("/");return{sequenceId:t,version:parseInt(n)}}function Yb(e,t){t&&Xe(e.startsWith(t+"/"),`Every migration in sequence '${t}' must have an id starting with '${t}/'. Got invalid id: '${e}'`),Xe(e.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${e}'`)}function i_(e){if(Xe(!e.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${e.sequenceId}`),Xe(e.sequenceId.length,"sequenceId must be a non-empty string"),e.sequence.length===0)return;Yb(e.sequence[0].id,e.sequenceId);let t=Mp(e.sequence[0].id).version;Xe(t===1,`Expected the first migrationId to be '${e.sequenceId}/1' but got '${e.sequence[0].id}'`);for(let n=1;n<e.sequence.length;n++){const r=e.sequence[n].id;Yb(r,e.sequenceId);const s=Mp(r).version;Xe(s===t+1,`Migration id numbers must increase in increments of 1, expected ${e.sequenceId}/${t+1} but got '${e.sequence[n].id}'`),t=s}}var Po=(e=>(e.IncompatibleSubtype="incompatible-subtype",e.UnknownType="unknown-type",e.TargetVersionTooNew="target-version-too-new",e.TargetVersionTooOld="target-version-too-old",e.MigrationError="migration-error",e.UnrecognizedSubtype="unrecognized-subtype",e))(Po||{});function XB(e){if(e.schemaVersion>2||e.schemaVersion<1)return yn.err("Bad schema version");if(e.schemaVersion===2)return yn.ok(e);const t={schemaVersion:2,sequences:{}};for(const[n,r]of Object.entries(e.recordVersions))if(t.sequences[`com.tldraw.${n}`]=r.version,"subTypeKey"in r)for(const[s,o]of Object.entries(r.subTypeVersions))t.sequences[`com.tldraw.${n}.${s}`]=o;return yn.ok(t)}class Yx{constructor(t,n){g(this,"migrations",{});g(this,"sortedMigrations");var s;this.types=t,this.options=n;for(const o of n.migrations??[])Xe(!this.migrations[o.sequenceId],`Duplicate migration sequenceId ${o.sequenceId}`),i_(o),this.migrations[o.sequenceId]=o;const r=Object.values(this.migrations).flatMap(o=>o.sequence);this.sortedMigrations=YB(r);for(const o of this.sortedMigrations)if((s=o.dependsOn)!=null&&s.length)for(const i of o.dependsOn){const a=r.find(l=>l.id===i);Xe(a,`Migration '${o.id}' depends on missing migration '${i}'`)}}static create(t,n){return new Yx(t,n??{})}validateRecord(t,n,r,s){try{const o=$n(this.types,n.typeName);if(!o)throw new Error(`Missing definition for record type ${n.typeName}`);return o.validate(n,s??void 0)}catch(o){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:t,record:n,phase:r,recordBefore:s,error:o});throw o}}getMigrationsSince(t){const n=XB(t);if(!n.ok)return n;const r=n.value,s=new Set(Object.keys(r.sequences).filter(i=>this.migrations[i]));for(const i in this.migrations)r.sequences[i]===void 0&&this.migrations[i].retroactive&&s.add(i);if(s.size===0)return yn.ok([]);const o=new Set;for(const i of s){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)o.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return yn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))o.add(u.id)}return yn.ok(this.sortedMigrations.filter(({id:i})=>o.has(i)))}migratePersistedRecord(t,n,r="up"){const s=this.getMigrationsSince(n);if(!s.ok)return console.error("Error migrating record",s.error),{type:"error",reason:Po.MigrationError};let o=s.value;if(o.length===0)return{type:"success",value:t};if(o.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?Po.TargetVersionTooOld:Po.TargetVersionTooNew};if(r==="down"){if(!o.every(i=>i.down))return{type:"error",reason:Po.TargetVersionTooOld};o=o.slice().reverse()}t=Ge(t);try{for(const i of o){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(t):!0))continue;const l=i[r](t);l&&(t=Ge(l))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:Po.MigrationError}}return{type:"success",value:t}}migrateStoreSnapshot(t){let{store:n}=t;const r=this.getMigrationsSince(t.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:Po.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:n};n=Ge(n);try{for(const o of s)if(o.scope==="record")for(const[i,a]of Object.entries(n)){if(!(o.filter?o.filter(a):!0))continue;const c=o.up(a);c&&(n[i]=Ge(c))}else if(o.scope==="store"){const i=o.up(n);i&&(n=Ge(i))}else un(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Po.MigrationError}}return{type:"success",value:n}}createIntegrityChecker(t){var n,r;return((r=(n=this.options).createIntegrityChecker)==null?void 0:r.call(n,t))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:t,sequence:n})=>[t,n.length?Mp(n.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:t})=>[t,0]))}}getType(t){const n=$n(this.types,t);return Xe(n,"record type does not exists"),n}}function qB(e){if(!e.length)return null;let t="";for(const n of e)typeof n=="number"?t+=`.${n}`:n.startsWith("(")?t.endsWith(")")?t=`${t.slice(0,-1)}, ${n.slice(1)}`:t+=n:t+=`.${n}`;return t=t.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),t.startsWith(".")?t.slice(1):t}class ke extends Error{constructor(n,r=[]){const s=qB(r),o=n.split(`
|
|
47
|
-
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
48
|
-
`);super(r?`At ${s}: ${o}`:o);g(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function Un(e,t){try{return t()}catch(n){throw n instanceof ke?new ke(n.rawMessage,[e,...n.path]):new ke(n.toString(),[e])}}function Yo(e){if(e===null)return"null";if(Array.isArray(e))return"an array";const t=typeof e;switch(t){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${t}`;case"object":return`an ${t}`;case"undefined":return"undefined";default:un(t)}}class Pn{constructor(t,n){this.validationFn=t,this.validateUsingKnownGoodVersionFn=n}validate(t){return this.validationFn(t)}validateUsingKnownGoodVersion(t,n){return Object.is(t,n)?t:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(t,n):this.validate(n)}isValid(t){try{return this.validate(t),!0}catch{return!1}}nullable(){return nU(this)}optional(){return l_(this)}refine(t){return new Pn(n=>t(this.validate(n)),(n,r)=>{const s=this.validateUsingKnownGoodVersion(n,r);return Object.is(n,s)?n:t(s)})}check(t,n){return typeof t=="string"?this.refine(r=>(Un(`(check ${t})`,()=>n(r)),r)):this.refine(r=>(t(r),r))}}class ZB extends Pn{constructor(t){super(n=>{const r=Xb.validate(n);for(let s=0;s<r.length;s++)Un(s,()=>t.validate(r[s]));return r},(n,r)=>{if(!t.validateUsingKnownGoodVersion)return this.validate(r);const s=Xb.validate(r);let o=n.length!==s.length;for(let i=0;i<s.length;i++){const a=s[i];if(i>=n.length){o=!0,Un(i,()=>t.validate(a));continue}if(Object.is(n[i],a))continue;const l=Un(i,()=>t.validateUsingKnownGoodVersion(n[i],a));Object.is(l,n[i])||(o=!0)}return o?r:n}),this.itemValidator=t}nonEmpty(){return this.check(t=>{if(t.length===0)throw new ke("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(t=>{if(t.length<=1)throw new ke("Expected an array with length greater than 1")})}}class Ap extends Pn{constructor(t,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new ke(`Expected object, got ${Yo(r)}`);for(const[s,o]of Object.entries(t))Un(s,()=>{o.validate($n(r,s))});if(!n){for(const s of Object.keys(r))if(!ms(t,s))throw new ke("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new ke(`Expected object, got ${Yo(s)}`);let o=!1;for(const[i,a]of Object.entries(t)){const l=$n(r,i),c=$n(s,i);if(Object.is(l,c))continue;const u=Un(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(o=!0)}if(!n){for(const i of Object.keys(s))if(!ms(t,i))throw new ke("Unexpected property",[i])}for(const i of Object.keys(r))if(!ms(s,i)){o=!0;break}return o?s:r}),this.config=t,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new Ap(this.config,!0)}extend(t){return new Ap({...this.config,...t})}}class Uf extends Pn{constructor(t,n,r,s){super(o=>{this.expectObject(o);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(o);return i===void 0?this.unknownValueValidation(o,a):Un(`(${t} = ${a})`,()=>i.validate(o))},(o,i)=>{this.expectObject(i),this.expectObject(o);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):$n(o,t)!==$n(i,t)?Un(`(${t} = ${l})`,()=>a.validate(i)):Un(`(${t} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(o,i):a.validate(i))}),this.key=t,this.config=n,this.unknownValueValidation=r,this.useNumberKeys=s}expectObject(t){if(typeof t!="object"||t===null)throw new ke(`Expected an object, got ${Yo(t)}`,[])}getMatchingSchemaAndVariant(t){const n=$n(t,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new ke(`Expected a string for key "${this.key}", got ${Yo(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new ke(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:ms(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(t){return new Uf(this.key,this.config,t,this.useNumberKeys)}}class QB extends Pn{constructor(t,n){super(r=>{if(typeof r!="object"||r===null)throw new ke(`Expected object, got ${Yo(r)}`);for(const[s,o]of Object.entries(r))Un(s,()=>{t.validate(s),n.validate(o)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new ke(`Expected object, got ${Yo(s)}`);let o=!1;for(const[i,a]of Object.entries(s)){if(!ms(r,i)){o=!0,Un(i,()=>{t.validate(i),n.validate(a)});continue}const l=$n(r,i),c=a;if(Object.is(l,c))continue;const u=Un(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(o=!0)}for(const i of Object.keys(r))if(!ms(s,i)){o=!0;break}return o?s:r}),this.keyValidator=t,this.valueValidator=n}}function Xx(e){return new Pn(t=>{if(typeof t!==e)throw new ke(`Expected ${e}, got ${Yo(t)}`);return t})}const JB=new Pn(e=>e),fe=Xx("string"),he=Xx("number").check(e=>{if(Number.isNaN(e))throw new ke("Expected a number, got NaN");if(!Number.isFinite(e))throw new ke(`Expected a finite number, got ${e}`)}),jp=he.check(e=>{if(e<0)throw new ke(`Expected a positive number, got ${e}`)}),Pt=he.check(e=>{if(e<=0)throw new ke(`Expected a non-zero positive number, got ${e}`)}),a_=he.check(e=>{if(!Number.isInteger(e))throw new ke(`Expected an integer, got ${e}`)}),Mh=a_.check(e=>{if(e<0)throw new ke(`Expected a positive integer, got ${e}`)}),eU=a_.check(e=>{if(e<=0)throw new ke(`Expected a non-zero positive integer, got ${e}`)}),Se=Xx("boolean");function dn(e){return new Pn(t=>{if(t!==e)throw new ke(`Expected ${e}, got ${JSON.stringify(t)}`);return e})}const Xb=new Pn(e=>{if(!Array.isArray(e))throw new ke(`Expected an array, got ${Yo(e)}`);return e});function Ht(e){return new ZB(e)}function xe(e){return new Ap(e)}function CS(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===DB)}function IS(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(IS):CS(e)?Object.values(e).every(IS):!1}const Kt=new Pn(e=>{if(IS(e))return e;throw new ke(`Expected json serializable value, got ${typeof e}`)},(e,t)=>{if(Array.isArray(e)&&Array.isArray(t)){let n=e.length!==t.length;for(let r=0;r<t.length;r++){if(r>=e.length){n=!0,Kt.validate(t[r]);continue}const s=e[r],o=t[r];if(Object.is(s,o))continue;const i=Kt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}return n?t:e}else if(CS(e)&&CS(t)){let n=!1;for(const r of Object.keys(t)){if(!ms(e,r)){n=!0,Kt.validate(t[r]);continue}const s=e[r],o=t[r];if(Object.is(s,o))continue;const i=Kt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}for(const r of Object.keys(e))if(!ms(t,r)){n=!0;break}return n?t:e}else return Kt.validate(t)});function Op(e,t){return new QB(e,t)}function qx(e,t){return new Uf(e,t,(n,r)=>{throw new ke(`Expected one of ${Object.keys(t).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function tU(e,t){return new Uf(e,t,(n,r)=>{throw new ke(`Expected one of ${Object.keys(t).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function Ts(e,t){return new Pn(n=>Un(e,()=>t.validate(n)),(n,r)=>Un(e,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(n,r):t.validate(r)))}function Hf(e){return new Pn(t=>{if(!e.has(t)){const n=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new ke(`Expected ${n}, got ${t}`)}return t})}function l_(e){return new Pn(t=>{if(t!==void 0)return e.validate(t)},(t,n)=>{if(!(t===void 0&&n===void 0)&&n!==void 0)return e.validateUsingKnownGoodVersion&&t!==void 0?e.validateUsingKnownGoodVersion(t,n):e.validate(n)})}function nU(e){return new Pn(t=>t===null?null:e.validate(t),(t,n)=>n===null?null:e.validateUsingKnownGoodVersion&&t!==null?e.validateUsingKnownGoodVersion(t,n):e.validate(n))}function Kf(...e){return Hf(new Set(e))}function Zx(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new ke(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new ke(`Expected a valid url, got ${JSON.stringify(e)}`)}}const rU=new Set(["http:","https:","mailto:"]),lr=fe.check(e=>{if(e==="")return;const t=Zx(e);if(!rU.has(t.protocol.toLowerCase()))throw new ke(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),sU=new Set(["http:","https:","data:","asset:"]),Li=fe.check(e=>{if(e==="")return;const t=Zx(e);if(!sU.has(t.protocol.toLowerCase()))throw new ke(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)});fe.check(e=>{if(e==="")return;if(!Zx(e).protocol.toLowerCase().match(/^https?:$/))throw new ke(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)});const Qx=fe.refine(e=>{try{return PB(e),e}catch{throw new ke(`Expected an index key, got ${JSON.stringify(e)}`)}});function sr(e){return fe.refine(t=>{if(!t.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return t})}const Wf=sr("asset");function Jx(e,t){return xe({id:Wf,typeName:dn("asset"),type:dn(e),props:t,meta:Kt})}const $i=xe({x:he,y:he,z:he.optional()}),Fc=xe({x:he,y:he,w:he,h:he}),c_=he.check(e=>{if(e<0||e>1)throw new ke("Opacity must be between 0 and 1")}),oU=fe.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),Sr=sr("shape");function iU(e,t,n){return xe({id:Sr,typeName:dn("shape"),x:he,y:he,rotation:he,index:Qx,parentId:oU,type:dn(e),isLocked:Se,opacity:c_,props:t?xe(t):Kt,meta:n?xe(n):Kt})}const aU=sr("binding");function lU(e,t,n){return xe({id:aU,typeName:dn("binding"),type:dn(e),fromId:Sr,toId:Sr,props:t?xe(t):Kt,meta:n?xe(n):Kt})}Vn("com.tldraw.binding",{});dr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function ji(e){return`binding:${Uu()}`}function cU(e){return _s("binding",{scope:"document",validator:Ts("binding",qx("type",Bu(e,(t,{props:n,meta:r})=>lU(t,n,r))))}).withDefaultProperties(()=>({meta:{}}))}class qt{constructor(t,n,r){this.id=t,this.defaultValue=n,this.type=r}static define(t,n){const{defaultValue:r,type:s=JB}=n;return new qt(t,r,s)}static defineEnum(t,n){const{defaultValue:r,values:s}=n;return new uU(t,r,s)}setDefaultValue(t){this.defaultValue=t}validate(t){return this.type.validate(t)}validateUsingKnownGoodVersion(t,n){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(t,n):this.validate(n)}}class uU extends qt{constructor(t,n,r){super(t,n,Kf(...r)),this.values=r}}const Ed=Vn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),dU=dr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:Ed.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:Ed.HoistOpacity,up:e=>{e.opacity=Number(e.props.opacity??"1"),delete e.props.opacity},down:e=>{const t=e.opacity;delete e.opacity,e.props.opacity=t<.175?"0.1":t<.375?"0.25":t<.625?"0.5":t<.875?"0.75":"1"}},{id:Ed.AddMeta,up:e=>{e.meta={}}},{id:Ed.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function Ta(e){return e?e.typeName==="shape":!1}function jn(e){return e?e.startsWith("shape:"):!1}function $e(e){return`shape:${e??Uu()}`}function u_(e){const t=new Map;for(const[n,r]of Object.entries(e))if(r instanceof qt){if(t.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);t.set(r,n)}return t}function Zr(e,t){return Bu(t,(n,r)=>`com.tldraw.shape.${e}/${r}`)}function hU(e){return _s("shape",{scope:"document",validator:Ts("shape",qx("type",Bu(e,(t,{props:n,meta:r})=>iU(t,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function qb(e,t){const n=[];for(const[r,{migrations:s}]of Object.entries(t)){const o=`com.tldraw.${e}.${r}`;s?"sequenceId"in s?(Xe(o===s.sequenceId,`sequenceId mismatch for ${r} ${Bf} migrations. Expected '${o}', got '${s.sequenceId}'`),n.push(s)):"sequence"in s?n.push(Va({sequenceId:o,retroactive:!1,sequence:s.sequence.map(i=>"id"in i?d_(e,r,i):i)})):n.push(Va({sequenceId:o,retroactive:!1,sequence:Object.keys(s.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${o}/${i}`,scope:"record",filter:a=>a.typeName===e&&a.type===r,up:a=>{const l=s.migrators[i].up(a);if(l)return l},down:a=>{const l=s.migrators[i].down(a);if(l)return l}}))})):n.push(Va({sequenceId:o,retroactive:!1,sequence:[]}))}return n}function d_(e,t,n){return{id:n.id,dependsOn:n.dependsOn,scope:"record",filter:r=>r.typeName===e&&r.type===t,up:r=>{const s=n.up(r.props);s&&(r.props=s)},down:typeof n.down=="function"?r=>{const s=n.down(r.props);s&&(r.props=s)}:void 0}}const h_=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],Dp={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",fill:"#4465e9",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#9fa8b2",fill:"#9fa8b2",note:{fill:"#C0CAD3",text:"#000000"},semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",note:{fill:"#9BC4FD",text:"#000000"},semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#4cb05e",fill:"#4cb05e",note:{fill:"#98D08A",text:"#000000"},semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#f87777",fill:"#f87777",note:{fill:"#F7A5A1",text:"#000000"},semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e085f4",fill:"#e085f4",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#e16919",fill:"#e16919",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",fill:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",fill:"#4f72fc",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",fill:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",fill:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",fill:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",fill:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",fill:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",fill:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function lo(e){return e.isDarkMode?Dp.darkMode:Dp.lightMode}const cr=qt.defineEnum("tldraw:color",{defaultValue:"black",values:h_}),p_=qt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:h_}),Ni=qt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Fi=qt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),bs=qt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),f_={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Ps=qt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),g_=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Rp=qt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:g_}),Lp=qt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:g_}),m_={labelColor:p_,color:cr,fill:Fi,dash:Ni,size:Ps,arrowheadStart:Rp,arrowheadEnd:Lp,font:bs,start:$i,end:$i,bend:he,text:fe,labelPosition:he,scale:Pt},ba=Zr("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function kd(e){return d_("shape","arrow",e)}const y_=Va({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[kd({id:ba.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"}),kd({id:ba.AddIsPrecise,up:({start:e,end:t})=>{e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5)),t.type==="binding"&&(t.isPrecise=!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5))},down:({start:e,end:t})=>{e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise),t.type==="binding"&&(t.isPrecise||(t.normalizedAnchor={x:.5,y:.5}),delete t.isPrecise)}}),kd({id:ba.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}),{id:ba.ExtractBindings,scope:"store",up:e=>{const t=Object.values(e).filter(n=>n.typeName==="shape"&&n.type==="arrow");for(const n of t){const{start:r,end:s}=n.props;if(r.type==="binding"){const o=ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};e[o]=i,n.props.start={x:0,y:0}}else delete n.props.start.type;if(s.type==="binding"){const o=ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:s.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:s.normalizedAnchor,isExact:s.isExact,isPrecise:s.isPrecise}};e[o]=i,n.props.end={x:0,y:0}}else delete n.props.end.type}}},kd({id:ba.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}})]}),S_={terminal:Kf("start","end"),normalizedAnchor:$i,isExact:Se,isPrecise:Se},v_={sequence:[{dependsOn:[ba.ExtractBindings]}]},pU=Ts("camera",xe({typeName:dn("camera"),id:sr("camera"),x:he,y:he,z:he,meta:Kt})),fU=Vn("com.tldraw.camera",{AddMeta:1}),gU=dr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:fU.AddMeta,up:e=>{e.meta={}}}]}),hs=_s("camera",{validator:pU,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),mU=new Set(["none","default","pointer","cross","grab","rotate","grabbing","resize-edge","resize-corner","text","move","ew-resize","ns-resize","nesw-resize","nwse-resize","nesw-rotate","nwse-rotate","swne-rotate","senw-rotate","zoom-in","zoom-out"]),x_=Hf(mU),yU=xe({type:x_,rotation:he}),SU=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),vU=Hf(SU),xU=new Set(["starting","paused","active","stopping"]),w_=xe({id:fe,points:Ht($i),size:jp,color:vU,opacity:he,state:Hf(xU),delay:he,shrink:he,taper:Se}),ou=sr("page"),wU=Ts("page",xe({typeName:dn("page"),id:ou,name:fe,index:Qx,meta:Kt})),bU=Vn("com.tldraw.page",{AddMeta:1}),PU=dr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:bU.AddMeta,up:e=>{e.meta={}}}]}),Qs=_s("page",{validator:wU,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Mn(e){return Qs.isId(e)}const CU={id:!1,typeName:!1,currentPageId:!1,opacityForNextShape:!1,stylesForNextShape:!1,followingUserId:!1,highlightedUserIds:!1,brush:!1,cursor:!1,scribbles:!1,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!1,chatMessage:!1,isChatting:!1,isPenMode:!1,isGridMode:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!1,openMenus:!1,isChangingStyle:!1,isReadonly:!0,meta:!1,duplicateProps:!1},b_=e=>e?$c(e,t=>CU[t]):null;sr("instance");function IU(e){const t={};for(const[r,s]of e)t[r]=l_(s);const n=Ts("instance",xe({typeName:dn("instance"),id:sr("instance"),currentPageId:ou,followingUserId:fe.nullable(),brush:Fc.nullable(),opacityForNextShape:c_,stylesForNextShape:xe(t),cursor:yU,scribbles:Ht(w_),isFocusMode:Se,isDebugMode:Se,isToolLocked:Se,exportBackground:Se,screenBounds:Fc,insets:Ht(Se),zoomBrush:Fc.nullable(),isPenMode:Se,isGridMode:Se,chatMessage:fe,isChatting:Se,highlightedUserIds:Ht(fe),isFocused:Se,devicePixelRatio:he,isCoarsePointer:Se,isHoveringCanvas:Se.nullable(),openMenus:Ht(fe),isChangingStyle:Se,isReadonly:Se,meta:Kt,duplicateProps:xe({shapeIds:Ht(sr("shape")),offset:xe({x:he,y:he})}).nullable()}));return _s("instance",{validator:n,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const Qe=Vn("com.tldraw.instance",{AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24,RemoveCanMoveCamera:25}),EU=dr({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:Qe.AddTransparentExportBgs,up:e=>({...e,exportBackground:!0})},{id:Qe.RemoveDialog,up:({dialog:e,...t})=>t},{id:Qe.AddToolLockMode,up:e=>({...e,isToolLocked:!1})},{id:Qe.RemoveExtraPropsForNextShape,up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:Object.fromEntries(Object.entries(e).filter(([n])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(n)))})},{id:Qe.AddLabelColor,up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:{...e,labelColor:"black"}})},{id:Qe.AddFollowingUserId,up:e=>({...e,followingUserId:null})},{id:Qe.RemoveAlignJustify,up:e=>{let t=e.propsForNextShape.align;return t==="justify"&&(t="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:t}}}},{id:Qe.AddZoom,up:e=>({...e,zoomBrush:null})},{id:Qe.AddVerticalAlign,up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}})},{id:Qe.AddScribbleDelay,up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e}},{id:Qe.RemoveUserId,up:({userId:e,...t})=>t},{id:Qe.AddIsPenModeAndIsGridMode,up:e=>({...e,isPenMode:!1,isGridMode:!1})},{id:Qe.HoistOpacity,up:({propsForNextShape:{opacity:e,...t},...n})=>({...n,opacityForNextShape:Number(e??"1"),propsForNextShape:t})},{id:Qe.AddChat,up:e=>({...e,chatMessage:"",isChatting:!1})},{id:Qe.AddHighlightedUserIds,up:e=>({...e,highlightedUserIds:[]})},{id:Qe.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:e,...t})=>({...t,stylesForNextShape:{}})},{id:Qe.AddMeta,up:e=>({...e,meta:{}})},{id:Qe.RemoveCursorColor,up:e=>{const{color:t,...n}=e.cursor;return{...e,cursor:n}}},{id:Qe.AddLonelyProperties,up:e=>({...e,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:Qe.ReadOnlyReadonly,up:({isReadOnly:e,...t})=>({...t,isReadonly:e})},{id:Qe.AddHoveringCanvas,up:e=>({...e,isHoveringCanvas:null})},{id:Qe.AddScribbles,up:({scribble:e,...t})=>({...t,scribbles:[]})},{id:Qe.AddInset,up:e=>({...e,insets:[!1,!1,!1,!1]}),down:({insets:e,...t})=>({...t})},{id:Qe.AddDuplicateProps,up:e=>({...e,duplicateProps:null}),down:({duplicateProps:e,...t})=>({...t})},{id:Qe.RemoveCanMoveCamera,up:({canMoveCamera:e,...t})=>({...t}),down:e=>({...e,canMoveCamera:!0})}]}),Sn="instance:instance",kU=Ts("instance_page_state",xe({typeName:dn("instance_page_state"),id:sr("instance_page_state"),pageId:ou,selectedShapeIds:Ht(Sr),hintingShapeIds:Ht(Sr),erasingShapeIds:Ht(Sr),hoveredShapeId:Sr.nullable(),editingShapeId:Sr.nullable(),croppingShapeId:Sr.nullable(),focusedGroupId:Sr.nullable(),meta:Kt})),Vl=Vn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),_U=dr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Vl.AddCroppingId,up(e){e.croppingShapeId=null}},{id:Vl.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:Vl.AddMeta,up:e=>{e.meta={}}},{id:Vl.RenameProperties,up:e=>{},down:e=>{}},{id:Vl.RenamePropertiesAgain,up:e=>{e.selectedShapeIds=e.selectedIds,delete e.selectedIds,e.hintingShapeIds=e.hintingIds,delete e.hintingIds,e.erasingShapeIds=e.erasingIds,delete e.erasingIds,e.hoveredShapeId=e.hoveredId,delete e.hoveredId,e.editingShapeId=e.editingId,delete e.editingId,e.croppingShapeId=e.croppingShapeId??e.croppingId??null,delete e.croppingId,e.focusedGroupId=e.focusLayerId,delete e.focusLayerId},down:e=>{e.selectedIds=e.selectedShapeIds,delete e.selectedShapeIds,e.hintingIds=e.hintingShapeIds,delete e.hintingShapeIds,e.erasingIds=e.erasingShapeIds,delete e.erasingShapeIds,e.hoveredId=e.hoveredShapeId,delete e.hoveredShapeId,e.editingId=e.editingShapeId,delete e.editingShapeId,e.croppingId=e.croppingShapeId,delete e.croppingShapeId,e.focusLayerId=e.focusedGroupId,delete e.focusedGroupId}}]}),Br=_s("instance_page_state",{validator:kU,scope:"session",ephemeralKeys:{pageId:!1,selectedShapeIds:!1,editingShapeId:!1,croppingShapeId:!1,meta:!1,hintingShapeIds:!0,erasingShapeIds:!0,hoveredShapeId:!0,focusedGroupId:!0}}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),TU=Ts("pointer",xe({typeName:dn("pointer"),id:sr("pointer"),x:he,y:he,lastActivityTimestamp:he,meta:Kt})),MU=Vn("com.tldraw.pointer",{AddMeta:1}),AU=dr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:MU.AddMeta,up:e=>{e.meta={}}}]}),e0=_s("pointer",{validator:TU,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),$p=e0.createId("pointer"),jU=Ts("instance_presence",xe({typeName:dn("instance_presence"),id:sr("instance_presence"),userId:fe,userName:fe,lastActivityTimestamp:he,followingUserId:fe.nullable(),cursor:xe({x:he,y:he,type:x_,rotation:he}),color:fe,camera:xe({x:he,y:he,z:he}),screenBounds:Fc,selectedShapeIds:Ht(sr("shape")),currentPageId:sr("page"),brush:Fc.nullable(),scribbles:Ht(w_),chatMessage:fe,meta:Kt})),Yl=Vn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),OU=dr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Yl.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:Yl.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:Yl.AddChatMessage,up:e=>{e.chatMessage=""}},{id:Yl.AddMeta,up:e=>{e.meta={}}},{id:Yl.RenameSelectedShapeIds,up:e=>{}}]}),DU=_s("instance_presence",{validator:jU,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:0,followingUserId:null,color:"#FF0000",camera:{x:0,y:0,z:1},cursor:{x:0,y:0,type:"default",rotation:0},screenBounds:{x:0,y:0,w:1,h:1},selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),RU=Ts("document",xe({typeName:dn("document"),id:dn("document:document"),gridSize:he,name:fe,meta:Kt})),Zb=Vn("com.tldraw.document",{AddName:1,AddMeta:2}),LU=dr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:Zb.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:Zb.AddMeta,up:e=>{e.meta={}}}]}),t0=_s("document",{validator:RU,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),ES=t0.createId("document");function $U(e,t){return e.index<t.index?-1:e.index>t.index?1:0}function Qb(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const NU=({error:e,phase:t,record:n,recordBefore:r})=>{throw zx(e,{tags:{origin:"store.validateRecord",storePhase:t,isExistingValidationIssue:t==="initialize"},extras:{recordBefore:r?Qb(Ge(r)):void 0,recordAfter:Qb(Ge(n))}}),e};function FU(){return[Qs.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function zU(e){const t=e.query.ids("page"),n=()=>{if(!e.has(ES))return e.put([t0.create({id:ES,name:e.props.defaultName})]),n();if(!e.has($p))return e.put([e0.create({id:$p})]),n();const r=t.get();if(r.size===0)return e.put(FU()),n();const s=()=>[...r].map(l=>e.get(l)).sort($U)[0].id,o=e.get(Sn);if(o){if(!r.has(o.currentPageId))return e.put([{...o,currentPageId:s()}]),n()}else return e.put([e.schema.types.instance.create({id:Sn,currentPageId:s(),exportBackground:!0})]),n();const i=new Set,a=new Set;for(const l of r){const c=Br.createId(l);e.has(c)||i.add(c);const u=hs.createId(l);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(l=>Br.create({id:l,pageId:Br.parseId(l)}))),a.size>0&&e.put([...a].map(l=>hs.create({id:l})))};return n}const BU=Jx("bookmark",xe({title:fe,description:fe,image:fe,favicon:fe,src:Li.nullable()})),Jb=Vn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),UU=dr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:Jb.MakeUrlsValid,up:e=>{Li.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:Jb.AddFavicon,up:e=>{Li.isValid(e.props.favicon)||(e.props.favicon="")},down:e=>{delete e.props.favicon}}]}),HU=Jx("image",xe({w:he,h:he,name:fe,isAnimated:Se,mimeType:fe.nullable(),src:Li.nullable(),fileSize:Pt.optional()})),Xl=Vn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),KU=dr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:Xl.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:Xl.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:Xl.MakeUrlsValid,up:e=>{Li.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:Xl.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}},{id:Xl.MakeFileSizeOptional,up:e=>{e.props.fileSize===-1&&(e.props.fileSize=void 0)},down:e=>{e.props.fileSize===void 0&&(e.props.fileSize=-1)}}]}),WU=Jx("video",xe({w:he,h:he,name:fe,isAnimated:Se,mimeType:fe.nullable(),src:Li.nullable(),fileSize:he.optional()})),ql=Vn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),GU=dr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:ql.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:ql.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:ql.MakeUrlsValid,up:e=>{Li.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:ql.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}},{id:ql.MakeFileSizeOptional,up:e=>{e.props.fileSize===-1&&(e.props.fileSize=void 0)},down:e=>{e.props.fileSize===void 0&&(e.props.fileSize=-1)}}]}),VU=Ts("asset",qx("type",{image:HU,video:WU,bookmark:BU})),YU=Vn("com.tldraw.asset",{AddMeta:1}),XU=dr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:YU.AddMeta,up:e=>{e.meta={}}}]}),Ii=_s("asset",{validator:VU,scope:"document"}).withDefaultProperties(()=>({meta:{}})),P_={w:Pt,h:Pt,assetId:Wf.nullable(),url:lr},eP=Zr("bookmark",{NullAssetId:1,MakeUrlsValid:2}),C_={sequence:[{id:eP.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:"retired"},{id:eP.MakeUrlsValid,up:e=>{lr.isValid(e.url)||(e.url="")},down:e=>{}}]},I_=xe({type:Kf("free","straight"),points:Ht($i)}),E_={color:cr,fill:Fi,dash:Ni,size:Ps,segments:Ht(I_),isComplete:Se,isClosed:Se,isPen:Se,scale:Pt},tP=Zr("draw",{AddInPen:1,AddScale:2}),k_={sequence:[{id:tP.AddInPen,up:e=>{const{points:t}=e.segments[0];if(t.length===0){e.isPen=!1;return}let n=!(t[0].z===0||t[0].z===.5);t[1]&&(n=n&&!(t[1].z===0||t[1].z===.5)),e.isPen=n},down:"retired"},{id:tP.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]};var qU={};const nP=/(^\/r\/[^/]+\/?$)/,De=e=>{try{return new URL(e)}catch{return}},Hu=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,overridePermissions:{"allow-top-navigation":!0},toEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(nP))return e},fromEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(nP))return e}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!e.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${e}`},fromEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/^\/embed\/?$/)){const n=t.searchParams.get("url");if(n)return n}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:e=>{if(e.includes("/maps/")){const t=e.match(/@(.*),(.*),(.*)z/);let n;if(t){const[,r,s,o]=t;n=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${qU.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${s}&zoom=${o}`}else n="";return n}},fromEmbedUrl:e=>{const t=De(e);if(!t)return;if(t.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&t.searchParams.has("center")&&t.searchParams.get("zoom")){const r=t.searchParams.get("zoom"),[s,o]=t.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${r}z`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=De(e),n=t&&t.pathname.match(/\/v\/(.+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:e=>{const t=De(e),n=t&&t.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=De(e),n=t&&t.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:e=>{const t=De(e),n=t&&t.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:e=>{const t=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,n=e.match(t);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/embed/${o}`}},fromEmbedUrl:e=>{const t=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=e.match(t);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/pen/${o}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:e=>{const t=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,n=e.match(t);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/embed/${s}`}},fromEmbedUrl:e=>{const t=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=e.match(t);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/${s}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=De(e);if(!t)return;const n=t.hostname.replace(/^www./,"");if(n==="youtu.be")return`https://www.youtube.com/embed/${t.pathname.split("/").filter(Boolean)[0]}`;if((n==="youtube.com"||n==="m.youtube.com")&&t.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${t.searchParams.get("v")}`},fromEmbedUrl:e=>{const t=De(e);if(!t)return;if(t.hostname.replace(/^www./,"")==="youtube.com"){const r=t.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:e=>{const t=De(e),n=t==null?void 0:t.searchParams.get("cid");if(t!=null&&t.pathname.match(/\/calendar\/u\/0/)&&n){t.pathname="/calendar/embed";const r=Array.from(t.searchParams.keys());for(const s of r)t.searchParams.delete(s);return t.searchParams.set("src",n),t.href}},fromEmbedUrl:e=>{const t=De(e),n=t==null?void 0:t.searchParams.get("src");if(t!=null&&t.pathname.match(/\/calendar\/embed/)&&n){t.pathname="/calendar/u/0";const r=Array.from(t.searchParams.keys());for(const s of r)t.searchParams.delete(s);return t.searchParams.set("cid",n),t.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:e=>{const t=De(e);if(t!=null&&t.pathname.match(/^\/presentation/)&&(t!=null&&t.pathname.match(/\/pub\/?$/))){t.pathname=t.pathname.replace(/\/pub$/,"/embed");const n=Array.from(t.searchParams.keys());for(const r of n)t.searchParams.delete(r);return t.href}},fromEmbedUrl:e=>{const t=De(e);if(t!=null&&t.pathname.match(/^\/presentation/)&&(t!=null&&t.pathname.match(/\/embed\/?$/))){t.pathname=t.pathname.replace(/\/embed$/,"/pub");const n=Array.from(t.searchParams.keys());for(const r of n)t.searchParams.delete(r);return t.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0},fromEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${e}?embed=true`},fromEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/)&&t.searchParams.has("embed"))return t.searchParams.delete("embed"),t.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/^\/map\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/^\/embed\/map\//))return t.pathname=t.pathname.replace(/^\/embed/,""),t.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/^\/(artist|album)\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/^\/embed\/(artist|album)\//))return t.origin+t.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=De(e);if(t&&t.hostname==="vimeo.com"&&t.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+t.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:e=>{const t=De(e);if(t&&t.hostname==="player.vimeo.com"){const n=t.pathname.match(/^\/video\/([^/]+)\/?$/);if(n)return"https://vimeo.com/"+n[1]}}},{type:"excalidraw",title:"Excalidraw",hostnames:["excalidraw.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=De(e);if(t&&t.hash.match(/#room=/))return e},fromEmbedUrl:e=>{const t=De(e);if(t&&t.hash.match(/#room=/))return e}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${t.origin}/embed${t.pathname}?cell=*`;if(t&&t.pathname.match(/^\/d\/([^/]+)\/?$/)){const n=t.pathname.replace(/^\/d/,"");return`${t.origin}/embed${n}?cell=*`}},fromEmbedUrl:e=>{const t=De(e);if(t&&t.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${t.origin}${t.pathname.replace("/embed","")}#cell-*`;if(t&&t.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${t.origin}${t.pathname.replace("/embed","/d")}#cell-*`}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,toEmbedUrl:e=>{const t=De(e);if(t&&t.hostname==="www.desmos.com"&&t.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&t.search===""&&t.hash==="")return`${e}?embed`},fromEmbedUrl:e=>{const t=De(e);if(t&&t.hostname==="www.desmos.com"&&t.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&t.search==="?embed"&&t.hash==="")return e.replace("?embed","")}}],ZU={"allow-downloads-without-user-activation":!1,"allow-downloads":!1,"allow-modals":!1,"allow-orientation-lock":!1,"allow-pointer-lock":!1,"allow-popups":!0,"allow-popups-to-escape-sandbox":!1,"allow-presentation":!1,"allow-storage-access-by-user-activation":!1,"allow-top-navigation":!1,"allow-top-navigation-by-user-activation":!1,"allow-scripts":!0,"allow-same-origin":!0,"allow-forms":!0},__={w:Pt,h:Pt,url:fe},_d=Zr("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),T_={sequence:[{id:_d.GenOriginalUrlInEmbed,up:e=>{try{const t=e.url,n=new URL(t).host.replace("www.","");let r;for(const s of Hu)if(s.hostnames.includes(n))try{r=s.fromEmbedUrl(t)}catch(o){console.warn(o)}e.tmpOldUrl=e.url,e.url=r??""}catch{e.url="",e.tmpOldUrl=e.url}},down:"retired"},{id:_d.RemoveDoesResize,up:e=>{delete e.doesResize},down:"retired"},{id:_d.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:"retired"},{id:_d.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:"retired"}]},M_={w:Pt,h:Pt,name:fe},A_={sequence:[]},Np=qt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Fp=qt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Ur=qt.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),j_={geo:Ur,labelColor:p_,color:cr,fill:Fi,dash:Ni,size:Ps,font:bs,align:Np,verticalAlign:Fp,url:lr,w:Pt,h:Pt,growY:jp,text:fe,scale:Pt},Ds=Zr("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),O_={sequence:[{id:Ds.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Ds.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"},{id:Ds.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:Ds.AddCheckBox,up:e=>{},down:"retired"},{id:Ds.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:Ds.MigrateLegacyAlign,up:e=>{let t;switch(e.align){case"start":t="start-legacy";break;case"end":t="end-legacy";break;default:t="middle-legacy";break}e.align=t},down:"retired"},{id:Ds.AddCloud,up:e=>{},down:"retired"},{id:Ds.MakeUrlsValid,up:e=>{lr.isValid(e.url)||(e.url="")},down:e=>{}},{id:Ds.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},D_={},R_={sequence:[]},L_={color:cr,size:Ps,segments:Ht(I_),isComplete:Se,isPen:Se,scale:Pt},QU=Zr("highlight",{AddScale:1}),$_={sequence:[{id:QU.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},JU=xe({topLeft:$i,bottomRight:$i}),N_={w:Pt,h:Pt,playing:Se,url:lr,assetId:Wf.nullable(),crop:JU.nullable(),flipX:Se,flipY:Se},Td=Zr("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),F_={sequence:[{id:Td.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Td.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:Td.MakeUrlsValid,up:e=>{lr.isValid(e.url)||(e.url="")},down:e=>{}},{id:Td.AddFlipProps,up:e=>{e.flipX=!1,e.flipY=!1},down:e=>{delete e.flipX,delete e.flipY}}]},zp=qt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),e9=xe({id:fe,index:Qx,x:he,y:he}),z_={color:cr,dash:Ni,size:Ps,spline:zp,points:Op(fe,e9),scale:Pt},Zl=Zr("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),B_={sequence:[{id:Zl.AddSnapHandles,up:e=>{for(const t of Object.values(e.handles))t.canSnap=!0},down:"retired"},{id:Zl.RemoveExtraHandleProps,up:e=>{e.handles=Wk(Object.values(e.handles).map(t=>[t.index,{x:t.x,y:t.y}]))},down:e=>{const t=Object.entries(e.handles).map(([n,r])=>({index:n,...r})).sort(ln);e.handles=Object.fromEntries(t.map((n,r)=>{const s=r===0?"start":r===t.length-1?"end":`handle:${n.index}`;return[s,{id:s,type:"vertex",canBind:!1,canSnap:!0,index:n.index,x:n.x,y:n.y}]}))}},{id:Zl.HandlesToPoints,up:e=>{const t=Object.entries(e.handles).map(([n,{x:r,y:s}])=>({x:r,y:s,index:n})).sort(ln);e.points=t.map(({x:n,y:r})=>({x:n,y:r})),delete e.handles},down:e=>{const t=su(e.points.length);e.handles=Object.fromEntries(e.points.map((n,r)=>[t[r],{x:n.x,y:n.y}])),delete e.points}},{id:Zl.PointIndexIds,up:e=>{const t=su(e.points.length);e.points=Object.fromEntries(e.points.map((n,r)=>{const s=t[r];return[s,{id:s,index:s,x:n.x,y:n.y}]}))},down:e=>{const t=Object.values(e.points).sort(ln);e.points=t.map(({x:n,y:r})=>({x:n,y:r}))}},{id:Zl.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},U_={color:cr,size:Ps,font:bs,fontSizeAdjustment:jp,align:Np,verticalAlign:Fp,growY:jp,url:lr,text:fe,scale:Pt},wi=Zr("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7}),H_={sequence:[{id:wi.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:wi.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:wi.MigrateLegacyAlign,up:e=>{switch(e.align){case"start":e.align="start-legacy";return;case"end":e.align="end-legacy";return;default:e.align="middle-legacy";return}},down:"retired"},{id:wi.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:wi.MakeUrlsValid,up:e=>{lr.isValid(e.url)||(e.url="")},down:e=>{}},{id:wi.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}},{id:wi.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},kS=qt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),K_={color:cr,size:Ps,font:bs,textAlign:kS,w:Pt,text:fe,scale:Pt,autoSize:Se},rP=Zr("text",{RemoveJustify:1,AddTextAlign:2}),W_={sequence:[{id:rP.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:rP.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}}]},G_={w:Pt,h:Pt,time:he,playing:Se,url:lr,assetId:Wf.nullable()},sP=Zr("video",{AddUrlProp:1,MakeUrlsValid:2}),V_={sequence:[{id:sP.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:sP.MakeUrlsValid,up:e=>{lr.isValid(e.url)||(e.url="")},down:e=>{}}]},Md=Vn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),t9=Va({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:Md.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[t,n]of Bn(e))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete e[t]}},{id:Md.AddInstancePresenceType,scope:"store",up(e){}},{id:Md.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[t,n]of Bn(e))n.typeName.match(/^(user|user_presence)$/)&&delete e[t]}},{id:Md.RemoveUserDocument,scope:"store",up:e=>{for(const[t,n]of Bn(e))n.typeName.match("user_document")&&delete e[t]}}]}),n9={arrow:{migrations:y_,props:m_},bookmark:{migrations:C_,props:P_},draw:{migrations:k_,props:E_},embed:{migrations:T_,props:__},frame:{migrations:A_,props:M_},geo:{migrations:O_,props:j_},group:{migrations:R_,props:D_},highlight:{migrations:$_,props:L_},image:{migrations:F_,props:N_},line:{migrations:B_,props:z_},note:{migrations:H_,props:U_},text:{migrations:W_,props:K_},video:{migrations:V_,props:G_}},r9={arrow:{migrations:v_,props:S_}};function s9({shapes:e=n9,bindings:t=r9,migrations:n}={}){const r=new Map;for(const a of gt(e))for(const l of u_(a.props??{}).keys()){if(r.has(l.id)&&r.get(l.id)!==l)throw new Error(`Multiple StyleProp instances with the same id: ${l.id}`);r.set(l.id,l)}const s=hU(e),o=cU(t),i=IU(r);return Yx.create({asset:Ii,binding:o,camera:hs,document:t0,instance:i,instance_page_state:Br,page:Qs,instance_presence:DU,pointer:e0,shape:s},{migrations:[t9,XU,gU,LU,EU,_U,PU,OU,AU,dU,UU,KU,GU,...qb("shape",e),...qb("binding",t),...n??[]],onValidationFailure:NU,createIntegrityChecker:zU})}const iu=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"uk",label:"Ukrainian"},{locale:"he",label:"עברית"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ku",label:"کوردی"},{locale:"ne",label:"नेपाली"},{locale:"hi-in",label:"हिन्दी"},{locale:"te",label:"తెలుగు"},{locale:"th",label:"ภาษาไทย"},{locale:"my",label:"မြန်မာစာ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function o9(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return i9(e)}function i9(e){for(const t of e){const n=a9(t);if(n)return n}return"en"}const oP={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function a9(e){const t=iu.find(s=>s.locale===e.toLowerCase());if(t)return t.locale;const[n,r]=e.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=iu.find(o=>o.locale===n);if(s)return s.locale}return n in oP?oP[n]:null}function Gf(e,t){const n=Ce.useRef(t);n.current=t;const[r,s,o]=Ce.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),l=new kl(`useStateTracking(${e})`,()=>{var u;return(u=n.current)==null?void 0:u.call(n)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[e]);return Ce.useSyncExternalStore(s,o,o),Ce.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const iP={apply(e,t,n){return Gf(e.displayName??e.name??"tracked(???)",()=>e.apply(t,n))}},l9=Symbol.for("react.memo"),c9=Symbol.for("react.forward_ref");function Lt(e){let t=null;const n=e.$$typeof;return n===l9&&(e=e.type,t=e.compare),n===c9?P.memo(P.forwardRef(new Proxy(e.render,iP))):P.memo(new Proxy(e,iP),t)}function u9(){const e=arguments[0],t=arguments[1],n=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return P.useMemo(()=>G(`useComputed(${e})`,t,n),r)}function Lo(e,t,n=Gs){P.useEffect(()=>{const r=new kl(e,t);return r.attach(),r.execute(),()=>{r.detach()}},n)}function K(){const e=arguments,t=e.length===3?e[2]:[e[0]],n=e.length===3?e[0]:`useValue(${e[0].name})`,r=P.useRef(!0);r.current=!0;const s=P.useMemo(()=>e.length===1?e[0]:G(n,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),t);try{const{subscribe:o,getSnapshot:i}=P.useMemo(()=>({subscribe:a=>ra(`useValue(${n})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return P.useSyncExternalStore(o,i,i)}finally{r.current=!1}}var Y_={exports:{}};/*!
|
|
49
|
-
Copyright (c) 2018 Jed Watson.
|
|
50
|
-
Licensed under the MIT License (MIT), see
|
|
51
|
-
http://jedwatson.github.io/classnames
|
|
52
|
-
*/(function(e){(function(){var t={}.hasOwnProperty;function n(){for(var o="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(o=s(o,r(a)))}return o}function r(o){if(typeof o=="string"||typeof o=="number")return o;if(typeof o!="object")return"";if(Array.isArray(o))return n.apply(null,o);if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]"))return o.toString();var i="";for(var a in o)t.call(o,a)&&o[a]&&(i=s(i,a));return i}function s(o,i){return i?o?o+" "+i:o+i:o}e.exports?(n.default=n,e.exports=n):window.classNames=n})()})(Y_);var d9=Y_.exports;const ce=ni(d9),X_="2.4.3",aP={major:"2024-06-28T10:56:07.893Z",minor:"2024-07-22T16:42:50.301Z",patch:"2024-07-31T13:08:03.152Z"},h9={error:null};class q_ extends P.Component{constructor(){super(...arguments);g(this,"state",h9)}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){var r,s;(s=(r=this.props).onError)==null||s.call(r,n)}render(){const{error:n}=this.state;if(n!==null){const{fallback:r}=this.props;return d.jsx(r,{error:n})}return this.props.children}}function au({children:e,fallback:t,...n}){return t===null?e:d.jsx(q_,{fallback:t,...n,children:e})}const Vf=P.createContext(null);function F(){const e=Ce.useContext(Vf);if(!e)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function p9(){return d.jsx("div",{className:"tl-background"})}function Ml(e,t,n,r,s,o){P.useLayoutEffect(()=>{const i=e.current;if(!i||t===void 0)return;let a=`translate(${t}px, ${n}px)`;r!==void 0&&(a+=` scale(${r})`),s!==void 0&&(a+=` rotate(${s}rad)`),o&&(a+=` translate(${o.x}px, ${o.y}px)`),i.style.transform=a})}const At={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>e*(2-e),easeInOutQuad:e=>e<.5?2*e*e:-1+(4-2*e)*e,easeInCubic:e=>e*e*e,easeOutCubic:e=>--e*e*e+1,easeInOutCubic:e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1- --e*e*e*e,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-8*--e*e*e*e,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1+--e*e*e*e*e,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e<=0?0:Math.pow(2,10*e-10),easeOutExpo:e=>e>=1?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>e<=0?0:e>=1?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2};class b{constructor(t=0,n=0,r=1){this.x=t,this.y=n,this.z=r}get pressure(){return this.z}set(t=this.x,n=this.y,r=this.z){return this.x=t,this.y=n,this.z=r,this}setTo({x:t=0,y:n=0,z:r=1}){return this.x=t,this.y=n,this.z=r,this}rot(t){if(t===0)return this;const{x:n,y:r}=this,s=Math.sin(t),o=Math.cos(t);return this.x=n*o-r*s,this.y=n*s+r*o,this}rotWith(t,n){if(n===0)return this;const r=this.x-t.x,s=this.y-t.y,o=Math.sin(n),i=Math.cos(n);return this.x=t.x+(r*i-s*o),this.y=t.y+(r*o+s*i),this}clone(){const{x:t,y:n,z:r}=this;return new b(t,n,r)}sub(t){return this.x-=t.x,this.y-=t.y,this}subXY(t,n){return this.x-=t,this.y-=n,this}subScalar(t){return this.x-=t,this.y-=t,this}add(t){return this.x+=t.x,this.y+=t.y,this}addXY(t,n){return this.x+=t,this.y+=n,this}addScalar(t){return this.x+=t,this.y+=t,this}clamp(t,n){return this.x=Math.max(this.x,t),this.y=Math.max(this.y,t),n!==void 0&&(this.x=Math.min(this.x,n),this.y=Math.min(this.y,n)),this}div(t){return this.x/=t,this.y/=t,this}divV(t){return this.x/=t.x,this.y/=t.y,this}mul(t){return this.x*=t,this.y*=t,this}mulV(t){return this.x*=t.x,this.y*=t.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(t,n){const r=b.Tan(t,this);return this.add(r.mul(n))}neg(){return this.x*=-1,this.y*=-1,this}cross(t){return this.x=this.y*t.z-this.z*t.y,this.y=this.z*t.x-this.x*t.z,this}dpr(t){return b.Dpr(this,t)}cpr(t){return b.Cpr(this,t)}len2(){return b.Len2(this)}len(){return b.Len(this)}pry(t){return b.Pry(this,t)}per(){const{x:t,y:n}=this;return this.x=n,this.y=-t,this}uni(){return b.Uni(this)}tan(t){return b.Tan(this,t)}dist(t){return b.Dist(this,t)}distanceToLineSegment(t,n){return b.DistanceToLineSegment(t,n,this)}slope(t){return b.Slope(this,t)}snapToGrid(t){return this.x=Math.round(this.x/t)*t,this.y=Math.round(this.y/t)*t,this}angle(t){return b.Angle(this,t)}toAngle(){return b.ToAngle(this)}lrp(t,n){return this.x=this.x+(t.x-this.x)*n,this.y=this.y+(t.y-this.y)*n,this}equals(t){return b.Equals(this,t)}equalsXY(t,n){return b.EqualsXY(this,t,n)}norm(){const t=this.len();return this.x=t===0?0:this.x/t,this.y=t===0?0:this.y/t,this}toFixed(){return b.ToFixed(this)}toString(){return b.ToString(b.ToFixed(this))}toJson(){return b.ToJson(this)}toArray(){return b.ToArray(this)}static Add(t,n){return new b(t.x+n.x,t.y+n.y)}static AddXY(t,n,r){return new b(t.x+n,t.y+r)}static Sub(t,n){return new b(t.x-n.x,t.y-n.y)}static SubXY(t,n,r){return new b(t.x-n,t.y-r)}static AddScalar(t,n){return new b(t.x+n,t.y+n)}static SubScalar(t,n){return new b(t.x-n,t.y-n)}static Div(t,n){return new b(t.x/n,t.y/n)}static Mul(t,n){return new b(t.x*n,t.y*n)}static DivV(t,n){return new b(t.x/n.x,t.y/n.y)}static MulV(t,n){return new b(t.x*n.x,t.y*n.y)}static Neg(t){return new b(-t.x,-t.y)}static Per(t){return new b(t.y,-t.x)}static Abs(t){return new b(Math.abs(t.x),Math.abs(t.y))}static Dist(t,n){return((t.y-n.y)**2+(t.x-n.x)**2)**.5}static DistMin(t,n,r){return(t.x-n.x)*(t.x-n.x)+(t.y-n.y)*(t.y-n.y)<r**2}static Dist2(t,n){return(t.x-n.x)*(t.x-n.x)+(t.y-n.y)*(t.y-n.y)}static Dpr(t,n){return t.x*n.x+t.y*n.y}static Cross(t,n){return new b(t.y*n.z-t.z*n.y,t.z*n.x-t.x*n.z)}static Cpr(t,n){return t.x*n.y-n.x*t.y}static Len2(t){return t.x*t.x+t.y*t.y}static Len(t){return(t.x*t.x+t.y*t.y)**.5}static Pry(t,n){return b.Dpr(t,n)/b.Len(n)}static Uni(t){return b.Div(t,b.Len(t))}static Tan(t,n){return b.Uni(b.Sub(t,n))}static Min(t,n){return new b(Math.min(t.x,n.x),Math.min(t.y,n.y))}static Max(t,n){return new b(Math.max(t.x,n.x),Math.max(t.y,n.y))}static From({x:t,y:n,z:r=1}){return new b(t,n,r)}static FromArray(t){return new b(t[0],t[1])}static Rot(t,n=0){const r=Math.sin(n),s=Math.cos(n);return new b(t.x*s-t.y*r,t.x*r+t.y*s)}static RotWith(t,n,r){const s=t.x-n.x,o=t.y-n.y,i=Math.sin(r),a=Math.cos(r);return new b(n.x+(s*a-o*i),n.y+(s*i+o*a))}static NearestPointOnLineThroughPoint(t,n,r){return b.Mul(n,b.Sub(r,t).pry(n)).add(t)}static NearestPointOnLineSegment(t,n,r,s=!0){if(b.Equals(t,r)||b.Equals(n,r))return b.From(r);const o=b.Tan(n,t),i=b.Add(t,b.Mul(o,b.Sub(r,t).pry(o)));if(s){if(i.x<Math.min(t.x,n.x))return b.Cast(t.x<n.x?t:n);if(i.x>Math.max(t.x,n.x))return b.Cast(t.x>n.x?t:n);if(i.y<Math.min(t.y,n.y))return b.Cast(t.y<n.y?t:n);if(i.y>Math.max(t.y,n.y))return b.Cast(t.y>n.y?t:n)}return i}static DistanceToLineThroughPoint(t,n,r){return b.Dist(r,b.NearestPointOnLineThroughPoint(t,n,r))}static DistanceToLineSegment(t,n,r,s=!0){return b.Dist(r,b.NearestPointOnLineSegment(t,n,r,s))}static Snap(t,n=1){return new b(Math.round(t.x/n)*n,Math.round(t.y/n)*n)}static Cast(t){return t instanceof b?t:b.From(t)}static Slope(t,n){return t.x===n.y?NaN:(t.y-n.y)/(t.x-n.x)}static IsNaN(t){return isNaN(t.x)||isNaN(t.y)}static Angle(t,n){return Math.atan2(n.y-t.y,n.x-t.x)}static Lrp(t,n,r){return b.Sub(n,t).mul(r).add(t)}static Med(t,n){return new b((t.x+n.x)/2,(t.y+n.y)/2)}static Equals(t,n){return Math.abs(t.x-n.x)<1e-4&&Math.abs(t.y-n.y)<1e-4}static EqualsXY(t,n,r){return t.x===n&&t.y===r}static Clockwise(t,n,r){return(r.x-t.x)*(n.y-t.y)-(n.x-t.x)*(r.y-t.y)<0}static Rescale(t,n){const r=b.Len(t);return new b(n*t.x/r,n*t.y/r)}static ScaleWithOrigin(t,n,r){return b.Sub(t,r).mul(n).add(r)}static ToFixed(t){return new b(Bs(t.x),Bs(t.y))}static ToInt(t){return new b(parseInt(t.x.toFixed(0)),parseInt(t.y.toFixed(0)),parseInt((t.z??0).toFixed(0)))}static ToCss(t){return`${t.x},${t.y}`}static Nudge(t,n,r){return b.Add(t,b.Tan(n,t).mul(r))}static ToString(t){return`${t.x}, ${t.y}`}static ToAngle(t){let n=Math.atan2(t.y,t.x);return n<0&&(n+=Math.PI*2),n}static FromAngle(t,n=1){return new b(Math.cos(t)*n,Math.sin(t)*n)}static ToArray(t){return[t.x,t.y,t.z]}static ToJson(t){const{x:n,y:r,z:s}=t;return{x:n,y:r,z:s}}static Average(t){const n=t.length,r=new b(0,0);if(n===0)return r;for(let s=0;s<n;s++)r.add(t[s]);return r.div(n)}static Clamp(t,n,r){return r===void 0?new b(Math.min(Math.max(t.x,n)),Math.min(Math.max(t.y,n))):new b(Math.min(Math.max(t.x,n),r),Math.min(Math.max(t.y,n),r))}static PointsBetween(t,n,r=6){const s=[];for(let o=0;o<r;o++){const i=At.easeInQuad(o/(r-1)),a=b.Lrp(t,n,i);a.z=Math.min(1,.5+Math.abs(.5-f9(i))*.65),s.push(a)}return s}static SnapToGrid(t,n=8){return new b(Math.round(t.x/n)*n,Math.round(t.y/n)*n)}}const f9=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Te(e){return`${N(e.x)},${N(e.y)} `}function Dn(e,t){return`${N((e.x+t.x)/2)},${N((e.y+t.y)/2)} `}const Me=Math.PI,Ve=Me/2,Le=Me*2,g9=Math.sin;function _t(e,t,n){return Math.max(t,typeof n<"u"?Math.min(e,n):e)}function Ad(e,t=1e10){return e?Math.round(e*t)/t:0}function $o(e,t,n=1e-6){return Math.abs(e-t)<=n}function Z_(e,t){const n=Math.pow(e-t,2)/Math.pow(e+t,2);return Me*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function No(e){return e=e%Le,e<0?e=e+Le:e===0&&(e=0),e}function Ku(e,t){return e=No(e),t=No(t),e>t&&(t+=Le),t-e}function Q_(e,t){return Le-Ku(e,t)}function Ah(e,t){const n=(t-e)%Le;return 2*n%Le-n}function _S(e){return(Le+e)%Le}function Bp(e,t){const n=Le/t;let r=Math.floor((_S(e)+n/2)/n)*n%Le;return r<Me&&(r+=Le),r>Me&&(r-=Le),r}function J_(e,t){return e===t||$o(e%(Math.PI/2)-t%(Math.PI/2),0)}function m9(e){return e*Me/180}function y9(e){return e*180/Me}function zi(e,t,n){return new b(e.x,e.y).add(b.FromAngle(n,t))}function km(e,t,n){const r=e/2,s=t/2,o=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let S=0;S<n;S++){const y=Le/n,x=-Ve+S*y,m=r+r*Math.cos(x),v=s+s*Math.sin(x);m<i&&(i=m),v<l&&(l=v),m>a&&(a=m),v>c&&(c=v),o.push(new b(m,v))}const u=a-i,h=c-l,p=e-u,f=t-h;if(p!==0||f!==0)for(let S=0;S<o.length;S++){const y=o[S];y.x=(y.x-i)/u*e,y.y=(y.y-l)/h*t}return o}function Ql(e,t,n,r){return e<r&&n<t}function Lr(e,t,n,r){const s=Math.max(e,n),o=Math.min(t,r);return s<=o?[s,o]:null}function lP(e,t,n){return(t.x-e.x)*(n.y-e.y)-(n.x-e.x)*(t.y-e.y)}function or(e,t){let n=0,r,s;for(let o=0;o<t.length;o++){if(r=t[o],r.x===e.x&&r.y===e.y||(s=t[(o+1)%t.length],b.Dist(e,r)+b.Dist(e,s)===b.Dist(r,s)))return!0;r.y<=e.y?s.y>e.y&&lP(r,s,e)>0&&(n+=1):s.y<=e.y&&lP(r,s,e)<0&&(n-=1)}return n!==0}function N(e){return Math.round(e*1e4)/1e4}function Bs(e){return Math.round(e*100)/100}const cP=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function ko(e,t,n){return n<0?Ku(e,t):Q_(e,t)}function TS(e,t,n,r){let s;if(Math.abs(e)>Me){s=Ah(t,r);const o=Ah(r,n);return Math.abs(s)<Math.abs(o)?s/e:(e-o)/e}else{s=Ah(t,r);const o=s/e;return Math.sign(s)!==Math.sign(e)?Math.abs(o)>.5?1:0:o}}function S9(e,t,n,r){const s=2*((t-e)%Le)%Le-(t-e)%Le;return r?(Le-Math.abs(s))*(n?1:-1):s}function n0(e,t,n){const r=-2*(e.x*(t.y-n.y)-e.y*(t.x-n.x)+t.x*n.y-n.x*t.y);return new b(((e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y)+(n.x*n.x+n.y*n.y)*(t.y-e.y))/r,((e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x)+(n.x*n.x+n.y*n.y)*(e.x-t.x))/r)}function v9(e,t,n,r,s){if(n===null)return[b.From(e),b.From(t)];const o=[],i=b.Angle(n,e),a=b.Angle(n,t),l=Ku(i,a);for(let c=0;c<s;c++){const u=c/(s-1),h=i+l*u,p=zi(n,r,h);o.push(p)}return o}const _m=({brush:e,color:t,opacity:n,className:r})=>{const s=P.useRef(null);Ml(s,e.x,e.y);const o=N(Math.max(1,e.w)),i=N(Math.max(1,e.h));return d.jsx("svg",{className:"tl-overlays__item",ref:s,children:t?d.jsxs("g",{className:"tl-brush",opacity:n,children:[d.jsx("rect",{width:o,height:i,fill:t,opacity:.75}),d.jsx("rect",{width:o,height:i,fill:"none",stroke:t,opacity:.1})]}):d.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:o,height:i})})},uP={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Tm={duration:0,easing:At.easeInOutCubic},dP={CAMERA_MOVE:-10},x9=["top","right","bottom","left"],hP=0,r0=2,jd=1,pP=5,w9=128;function Up(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return Up(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ee(e){e.preventDefault(),xt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Wu(e,t){if(e.setPointerCapture(t.pointerId),xt.logPointerCaptures.get()){const n=r_.get();n.set(e,(n.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,t)}}function Gu(e,t){if(e.hasPointerCapture(t.pointerId)&&(e.releasePointerCapture(t.pointerId),xt.logPointerCaptures.get())){const n=r_.get();n.get(e)===1?n.delete(e):n.has(e)?n.set(e,n.get(e)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",e,t)}}const Ot=e=>e.stopPropagation(),nn=(e,t,n)=>{e&&e.style.setProperty(t,n)};function Nn(e){return e.isKilled=!0,{point:{x:e.clientX,y:e.clientY,z:e.pressure},shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,pointerId:e.pointerId,button:e.button,isPen:e.pointerType==="pen"}}function e2(){const e=F();return P.useMemo(function(){let r,s;function o(y){if(!y.isKilled){if(y.button===r0){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...Nn(y)});return}y.button!==0&&y.button!==1&&y.button!==5||(Wu(y.currentTarget,y),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Nn(y)}))}}function i(y){y.isKilled||y.clientX===r&&y.clientY===s||(r=y.clientX,s=y.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Nn(y)}))}function a(y){y.isKilled||y.button!==0&&y.button!==1&&y.button!==2&&y.button!==5||(r=y.clientX,s=y.clientY,Gu(y.currentTarget,y),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Nn(y)}))}function l(y){if(y.isKilled||e.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const x=y.pointerType==="mouse"||y.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!0:null})}function c(y){if(y.isKilled||e.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const x=y.pointerType==="mouse"||y.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!1:null})}function u(y){y.isKilled=!0,Ee(y)}function h(y){y.isKilled=!0,y.target instanceof HTMLElement&&y.target.tagName!=="A"&&y.target.tagName!=="TEXTAREA"&&!(e.getEditingShape()&&y.target.className.includes("tl-text-content"))&&Ee(y)}function p(y){Ee(y)}async function f(y){var m,v;if(Ee(y),!((v=(m=y.dataTransfer)==null?void 0:m.files)!=null&&v.length))return;const x=Array.from(y.dataTransfer.files);await e.putExternalContent({type:"files",files:x,point:e.screenToPage({x:y.clientX,y:y.clientY}),ignoreParent:!1})}function S(y){Ot(y)}return{onPointerDown:o,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:h,onClick:S}},[e])}function b9(){const e=F();P.useEffect(()=>{let t=e.getInstanceState().isCoarsePointer;const n=i=>{const a=i.pointerType!=="mouse";t!==a&&(t=a,e.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",n,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),s=e.environment.isFirefox&&!e.environment.isAndroid&&!e.environment.isIos,o=()=>{const i=s?!1:r.matches;t===i&&(t=i,e.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",o),o()),()=>{window.removeEventListener("pointerdown",n,{capture:!0}),r&&r.removeEventListener("change",o)}},[e])}const t2=P.createContext(null);function P9({container:e,children:t}){return d.jsx(t2.Provider,{value:e,children:t})}function $t(){return xr(P.useContext(t2),"useContainer used outside of <Tldraw />")}function C9(){const e=F(),t=$t(),n=K("isFocused",()=>e.getIsFocused(),[e]);P.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let r=null;const s=()=>{r!=null&&r();const o=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(o),a=l=>{l.type==="change"&&s()};i.addEventListener?i.addEventListener("change",s):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",s):i.removeListener&&i.removeListener(a)},e.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{r==null||r()}},[e]),P.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!Od()&&Ee(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){Ee(a);return}break}case"Tab":{if(Od()||e.getIsMenuOpen())return;break}case",":return;case"Escape":{if((e.getEditingShape()||e.getSelectedShapeIds().length>0)&&a.preventDefault(),e.getOpenMenus().length>0)return;e.inputs.keys.has("Escape")||(e.inputs.keys.add("Escape"),e.cancel(),e.focus());return}default:if(Od()||e.getIsMenuOpen())return}const l={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)},s=a=>{if(a.isKilled||(a.isKilled=!0,Od()||e.getIsMenuOpen())||a.key===",")return;const l={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)};function o(a){var l,c;if(t.contains(a.target)){const u=a.touches[0].pageX,h=a.touches[0].radiusX||0;(u-h<10||u+h>e.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),Ee(a))}}const i=a=>{t.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Ee(a)};return t.addEventListener("touchstart",o,{passive:!1}),t.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Ee),document.addEventListener("gesturechange",Ee),document.addEventListener("gestureend",Ee),t.addEventListener("keydown",r),t.addEventListener("keyup",s),()=>{t.removeEventListener("touchstart",o),t.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Ee),document.removeEventListener("gesturechange",Ee),document.removeEventListener("gestureend",Ee),t.removeEventListener("keydown",r),t.removeEventListener("keyup",s)}},[e,t,n])}const I9=["input","select","button","textarea"];function Od(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||I9.indexOf(e.tagName.toLowerCase())>-1))}const E9=["textarea","input"];function k9(e){const t=F();P.useEffect(()=>{const n=e.current;if(!n)return;const r=s=>{var o;if(s instanceof PointerEvent&&s.pointerType==="pen"){s.isKilled=!0;const{target:i}=s;if(E9.includes((o=i.tagName)==null?void 0:o.toLocaleLowerCase())||t.isIn("select.editing_shape"))return;Ee(s)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[t,e])}function _9(e,t,n){return Math.max(t,Math.min(e,n))}const Wt={toVector(e,t){return e===void 0&&(e=t),Array.isArray(e)?e:[e,e]},add(e,t){return[e[0]+t[0],e[1]+t[1]]},sub(e,t){return[e[0]-t[0],e[1]-t[1]]},addTo(e,t){e[0]+=t[0],e[1]+=t[1]},subTo(e,t){e[0]-=t[0],e[1]-=t[1]}};function fP(e,t,n){return t===0||Math.abs(t)===1/0?Math.pow(e,n*5):e*t*n/(t+n*e)}function gP(e,t,n,r=.15){return r===0?_9(e,t,n):e<t?-fP(t-e,n-t,r)+t:e>n?+fP(e-n,n-t,r)+n:e}function T9(e,[t,n],[r,s]){const[[o,i],[a,l]]=e;return[gP(t,o,i,r),gP(n,a,l,s)]}function M9(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function A9(e){var t=M9(e,"string");return typeof t=="symbol"?t:String(t)}function sn(e,t,n){return t=A9(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function mP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function ut(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?mP(Object(n),!0).forEach(function(r){sn(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):mP(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}const n2={pointer:{start:"down",change:"move",end:"up"},mouse:{start:"down",change:"move",end:"up"},touch:{start:"start",change:"move",end:"end"},gesture:{start:"start",change:"change",end:"end"}};function yP(e){return e?e[0].toUpperCase()+e.slice(1):""}const j9=["enter","leave"];function O9(e=!1,t){return e&&!j9.includes(t)}function D9(e,t="",n=!1){const r=n2[e],s=r&&r[t]||t;return"on"+yP(e)+yP(s)+(O9(n,s)?"Capture":"")}const R9=["gotpointercapture","lostpointercapture"];function L9(e){let t=e.substring(2).toLowerCase();const n=!!~t.indexOf("passive");n&&(t=t.replace("passive",""));const r=R9.includes(t)?"capturecapture":"capture",s=!!~t.indexOf(r);return s&&(t=t.replace("capture","")),{device:t,capture:s,passive:n}}function $9(e,t=""){const n=n2[e],r=n&&n[t]||t;return e+r}function r2(e){return"touches"in e}function N9(e){return r2(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function F9(e){return Array.from(e.touches).filter(t=>{var n,r;return t.target===e.currentTarget||((n=e.currentTarget)===null||n===void 0||(r=n.contains)===null||r===void 0?void 0:r.call(n,t.target))})}function MS(e,t){try{const n=t.clientX-e.clientX,r=t.clientY-e.clientY,s=(t.clientX+e.clientX)/2,o=(t.clientY+e.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[s,o]}}catch{}return null}function z9(e){return F9(e).map(t=>t.identifier)}function SP(e,t){const[n,r]=Array.from(e.touches).filter(s=>t.includes(s.identifier));return MS(n,r)}const vP=40,xP=800;function s2(e){let{deltaX:t,deltaY:n,deltaMode:r}=e;return r===1?(t*=vP,n*=vP):r===2&&(t*=xP,n*=xP),[t,n]}function B9(e){const t={};if("buttons"in e&&(t.buttons=e.buttons),"shiftKey"in e){const{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o}=e;Object.assign(t,{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o})}return t}function Hp(e,...t){return typeof e=="function"?e(...t):e}function U9(){}function H9(...e){return e.length===0?U9:e.length===1?e[0]:function(){let t;for(const n of e)t=n.apply(this,arguments)||t;return t}}function wP(e,t){return Object.assign({},t,e||{})}const K9=32;class o2{constructor(t,n,r){this.ctrl=t,this.args=n,this.key=r,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(t){this.ctrl.state[this.key]=t}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:t,shared:n,ingKey:r,args:s}=this;n[r]=t._active=t.active=t._blocked=t._force=!1,t._step=[!1,!1],t.intentional=!1,t._movement=[0,0],t._distance=[0,0],t._direction=[0,0],t._delta=[0,0],t._bounds=[[-1/0,1/0],[-1/0,1/0]],t.args=s,t.axis=void 0,t.memo=void 0,t.elapsedTime=t.timeDelta=0,t.direction=[0,0],t.distance=[0,0],t.overflow=[0,0],t._movementBound=[!1,!1],t.velocity=[0,0],t.movement=[0,0],t.delta=[0,0],t.timeStamp=0}start(t){const n=this.state,r=this.config;n._active||(this.reset(),this.computeInitial(),n._active=!0,n.target=t.target,n.currentTarget=t.currentTarget,n.lastOffset=r.from?Hp(r.from,n):n.offset,n.offset=n.lastOffset,n.startTime=n.timeStamp=t.timeStamp)}computeValues(t){const n=this.state;n._values=t,n.values=this.config.transform(t)}computeInitial(){const t=this.state;t._initial=t._values,t.initial=t.values}compute(t){const{state:n,config:r,shared:s}=this;n.args=this.args;let o=0;if(t&&(n.event=t,r.preventDefault&&t.cancelable&&n.event.preventDefault(),n.type=t.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,B9(t)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=t.timeStamp-n.timeStamp,n.timeStamp=t.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const _=n._delta.map(Math.abs);Wt.addTo(n._distance,_)}this.axisIntent&&this.axisIntent(t);const[i,a]=n._movement,[l,c]=r.threshold,{_step:u,values:h}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[_,I]=h;p[0]=u[0]!==!1?_-u[0]:0,p[1]=u[1]!==!1?I-u[1]:0}else p[0]=u[0]!==!1?i-u[0]:0,p[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(p);const f=n.offset,S=n._active&&!n._blocked||n.active;S&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=s[this.ingKey]=n._active,t&&(n.first&&("bounds"in r&&(n._bounds=Hp(r.bounds,n)),this.setup&&this.setup()),n.movement=p,this.computeOffset()));const[y,x]=n.offset,[[m,v],[w,C]]=n._bounds;n.overflow=[y<m?-1:y>v?1:0,x<w?-1:x>C?1:0],n._movementBound[0]=n.overflow[0]?n._movementBound[0]===!1?n._movement[0]:n._movementBound[0]:!1,n._movementBound[1]=n.overflow[1]?n._movementBound[1]===!1?n._movement[1]:n._movementBound[1]:!1;const E=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=T9(n._bounds,n.offset,E),n.delta=Wt.sub(n.offset,f),this.computeMovement(),S&&(!n.last||o>K9)){n.delta=Wt.sub(n.offset,f);const _=n.delta.map(Math.abs);Wt.addTo(n.distance,_),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&o>0&&(n.velocity=[_[0]/o,_[1]/o],n.timeDelta=o)}}emit(){const t=this.state,n=this.shared,r=this.config;if(t._active||this.clean(),(t._blocked||!t.intentional)&&!t._force&&!r.triggerAllEvents)return;const s=this.handler(ut(ut(ut({},n),t),{},{[this.aliasKey]:t.values}));s!==void 0&&(t.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function W9([e,t],n){const r=Math.abs(e),s=Math.abs(t);if(r>s&&r>n)return"x";if(s>r&&s>n)return"y"}class G9 extends o2{constructor(...t){super(...t),sn(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=Wt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Wt.sub(this.state.offset,this.state.lastOffset)}axisIntent(t){const n=this.state,r=this.config;if(!n.axis&&t){const s=typeof r.axisThreshold=="object"?r.axisThreshold[N9(t)]:r.axisThreshold;n.axis=W9(n._movement,s)}n._blocked=(r.lockDirection||!!r.axis)&&!n.axis||!!r.axis&&r.axis!==n.axis}restrictToAxis(t){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":t[1]=0;break;case"y":t[0]=0;break}}}const V9=e=>e,bP=.15,i2={enabled(e=!0){return e},eventOptions(e,t,n){return ut(ut({},n.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[bP,bP];case!1:return[0,0];default:return Wt.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return Wt.toVector(e)},transform(e,t,n){const r=e||n.shared.transform;return this.hasCustomTransform=!!r,r||V9},threshold(e){return Wt.toVector(e,0)}},Y9=0,Vu=ut(ut({},i2),{},{axis(e,t,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(e=Y9){return e},bounds(e={}){if(typeof e=="function")return o=>Vu.bounds(e(o));if("current"in e)return()=>e.current;if(typeof HTMLElement=="function"&&e instanceof HTMLElement)return e;const{left:t=-1/0,right:n=1/0,top:r=-1/0,bottom:s=1/0}=e;return[[t,n],[r,s]]}}),Yu=typeof window<"u"&&window.document&&window.document.createElement;function a2(){return Yu&&"ontouchstart"in window}function X9(){return a2()||Yu&&window.navigator.maxTouchPoints>1}function q9(){return Yu&&"onpointerdown"in window}function Z9(){return Yu&&"exitPointerLock"in window.document}function Q9(){try{return"constructor"in GestureEvent}catch{return!1}}const wr={isBrowser:Yu,gesture:Q9(),touch:a2(),touchscreen:X9(),pointer:q9(),pointerLock:Z9()},J9=250,e7=180,t7=.5,n7=50,r7=250,s7=10,PP={mouse:0,touch:0,pen:8};ut(ut({},Vu),{},{device(e,t,{pointer:{touch:n=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&wr.pointerLock,wr.touch&&n?"touch":this.pointerLock?"mouse":wr.pointer&&!s?"pointer":wr.touch?"touch":"mouse"},preventScrollAxis(e,t,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&e?J9:void 0,!(!wr.touchscreen||n===!1))return e||(n!==void 0?"y":void 0)},pointerCapture(e,t,{pointer:{capture:n=!0,buttons:r=1,keys:s=!0}={}}){return this.pointerButtons=r,this.keys=s,!this.pointerLock&&this.device==="pointer"&&n},threshold(e,t,{filterTaps:n=!1,tapsThreshold:r=3,axis:s=void 0}){const o=Wt.toVector(e,n?r:s?1:0);return this.filterTaps=n,this.tapsThreshold=r,o},swipe({velocity:e=t7,distance:t=n7,duration:n=r7}={}){return{velocity:this.transform(Wt.toVector(e)),distance:this.transform(Wt.toVector(t)),duration:n}},delay(e=0){switch(e){case!0:return e7;case!1:return 0;default:return e}},axisThreshold(e){return e?ut(ut({},PP),e):PP},keyboardDisplacement(e=s7){return e}});function l2(e){const[t,n]=e.overflow,[r,s]=e._delta,[o,i]=e._direction;(t<0&&r>0&&o<0||t>0&&r<0&&o>0)&&(e._movement[0]=e._movementBound[0]),(n<0&&s>0&&i<0||n>0&&s<0&&i>0)&&(e._movement[1]=e._movementBound[1])}const o7=30,i7=100;class a7 extends o2{constructor(...t){super(...t),sn(this,"ingKey","pinching"),sn(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const t=this.state;t._touchIds=[],t.canceled=!1,t.cancel=this.cancel.bind(this),t.turns=0}computeOffset(){const{type:t,movement:n,lastOffset:r}=this.state;t==="wheel"?this.state.offset=Wt.add(n,r):this.state.offset=[(1+n[0])*r[0],n[1]+r[1]]}computeMovement(){const{offset:t,lastOffset:n}=this.state;this.state.movement=[t[0]/n[0],t[1]-n[1]]}axisIntent(){const t=this.state,[n,r]=t._movement;if(!t.axis){const s=Math.abs(n)*o7-Math.abs(r);s<0?t.axis="angle":s>0&&(t.axis="scale")}}restrictToAxis(t){this.config.lockDirection&&(this.state.axis==="scale"?t[1]=0:this.state.axis==="angle"&&(t[0]=0))}cancel(){const t=this.state;t.canceled||setTimeout(()=>{t.canceled=!0,t._active=!1,this.compute(),this.emit()},0)}touchStart(t){this.ctrl.setEventIds(t);const n=this.state,r=this.ctrl.touchIds;if(n._active&&n._touchIds.every(o=>r.has(o))||r.size<2)return;this.start(t),n._touchIds=Array.from(r).slice(0,2);const s=SP(t,n._touchIds);s&&this.pinchStart(t,s)}pointerStart(t){if(t.buttons!=null&&t.buttons%2!==1)return;this.ctrl.setEventIds(t),t.target.setPointerCapture(t.pointerId);const n=this.state,r=n._pointerEvents,s=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>s.has(i))||(r.size<2&&r.set(t.pointerId,t),n._pointerEvents.size<2))return;this.start(t);const o=MS(...Array.from(r.values()));o&&this.pinchStart(t,o)}pinchStart(t,n){const r=this.state;r.origin=n.origin,this.computeValues([n.distance,n.angle]),this.computeInitial(),this.compute(t),this.emit()}touchMove(t){if(!this.state._active)return;const n=SP(t,this.state._touchIds);n&&this.pinchMove(t,n)}pointerMove(t){const n=this.state._pointerEvents;if(n.has(t.pointerId)&&n.set(t.pointerId,t),!this.state._active)return;const r=MS(...Array.from(n.values()));r&&this.pinchMove(t,r)}pinchMove(t,n){const r=this.state,s=r._values[1],o=n.angle-s;let i=0;Math.abs(o)>270&&(i+=Math.sign(o)),this.computeValues([n.distance,n.angle-360*i]),r.origin=n.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(t),this.emit()}touchEnd(t){this.ctrl.setEventIds(t),this.state._active&&this.state._touchIds.some(n=>!this.ctrl.touchIds.has(n))&&(this.state._active=!1,this.compute(t),this.emit())}pointerEnd(t){const n=this.state;this.ctrl.setEventIds(t);try{t.target.releasePointerCapture(t.pointerId)}catch{}n._pointerEvents.has(t.pointerId)&&n._pointerEvents.delete(t.pointerId),n._active&&n._pointerEvents.size<2&&(n._active=!1,this.compute(t),this.emit())}gestureStart(t){t.cancelable&&t.preventDefault();const n=this.state;n._active||(this.start(t),this.computeValues([t.scale,t.rotation]),n.origin=[t.clientX,t.clientY],this.compute(t),this.emit())}gestureMove(t){if(t.cancelable&&t.preventDefault(),!this.state._active)return;const n=this.state;this.computeValues([t.scale,t.rotation]),n.origin=[t.clientX,t.clientY];const r=n._movement;n._movement=[t.scale-1,t.rotation],n._delta=Wt.sub(n._movement,r),this.compute(t),this.emit()}gestureEnd(t){this.state._active&&(this.state._active=!1,this.compute(t),this.emit())}wheel(t){const n=this.config.modifierKey;n&&(Array.isArray(n)?!n.find(r=>t[r]):!t[n])||(this.state._active?this.wheelChange(t):this.wheelStart(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(t){this.start(t),this.wheelChange(t)}wheelChange(t){"uv"in t||t.cancelable&&t.preventDefault();const r=this.state;r._delta=[-s2(t)[1]/i7*r.offset[0],0],Wt.addTo(r._movement,r._delta),l2(r),this.state.origin=[t.clientX,t.clientY],this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){const n=this.config.device;n&&(t(n,"start",this[n+"Start"].bind(this)),t(n,"change",this[n+"Move"].bind(this)),t(n,"end",this[n+"End"].bind(this)),t(n,"cancel",this[n+"End"].bind(this)),t("lostPointerCapture","",this[n+"End"].bind(this))),this.config.pinchOnWheel&&t("wheel","",this.wheel.bind(this),{passive:!1})}}const l7=ut(ut({},i2),{},{device(e,t,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!wr.touch&&wr.gesture)return"gesture";if(wr.touch&&r)return"touch";if(wr.touchscreen){if(wr.pointer)return"pointer";if(wr.touch)return"touch"}},bounds(e,t,{scaleBounds:n={},angleBounds:r={}}){const s=i=>{const a=wP(Hp(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},o=i=>{const a=wP(Hp(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[s(),o()]:i=>[s(i),o(i)]},threshold(e,t,n){return this.lockDirection=n.axis==="lock",Wt.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});ut(ut({},Vu),{},{mouseOnly:(e=!0)=>e});class c7 extends G9{constructor(...t){super(...t),sn(this,"ingKey","wheeling")}wheel(t){this.state._active||this.start(t),this.wheelChange(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(t){const n=this.state;n._delta=s2(t),Wt.addTo(n._movement,n._delta),l2(n),this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){t("wheel","",this.wheel.bind(this))}}const u7=Vu;ut(ut({},Vu),{},{mouseOnly:(e=!0)=>e});const s0=new Map,AS=new Map;function d7(e){s0.set(e.key,e.engine),AS.set(e.key,e.resolver)}const h7={key:"pinch",engine:a7,resolver:l7},p7={key:"wheel",engine:c7,resolver:u7};function f7(e,t){if(e==null)return{};var n={},r=Object.keys(e),s,o;for(o=0;o<r.length;o++)s=r[o],!(t.indexOf(s)>=0)&&(n[s]=e[s]);return n}function g7(e,t){if(e==null)return{};var n=f7(e,t),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)r=o[s],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}const m7={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=wr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:t=!1}={}){return{passive:e,capture:t}},transform(e){return e}},y7=["target","eventOptions","window","enabled","transform"];function jh(e={},t){const n={};for(const[r,s]of Object.entries(t))switch(typeof s){case"function":n[r]=s.call(n,e[r],r,e);break;case"object":n[r]=jh(e[r],s);break;case"boolean":s&&(n[r]=e[r]);break}return n}function S7(e,t,n={}){const r=e,{target:s,eventOptions:o,window:i,enabled:a,transform:l}=r,c=g7(r,y7);if(n.shared=jh({target:s,eventOptions:o,window:i,enabled:a,transform:l},m7),t){const u=AS.get(t);n[t]=jh(ut({shared:n.shared},c),u)}else for(const u in c){const h=AS.get(u);h&&(n[u]=jh(ut({shared:n.shared},c[u]),h))}return n}class c2{constructor(t,n){sn(this,"_listeners",new Set),this._ctrl=t,this._gestureKey=n}add(t,n,r,s,o){const i=this._listeners,a=$9(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ut(ut({},l),o);t.addEventListener(a,s,c);const u=()=>{t.removeEventListener(a,s,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(t=>t()),this._listeners.clear()}}class v7{constructor(){sn(this,"_timeouts",new Map)}add(t,n,r=140,...s){this.remove(t),this._timeouts.set(t,window.setTimeout(n,r,...s))}remove(t){const n=this._timeouts.get(t);n&&window.clearTimeout(n)}clean(){this._timeouts.forEach(t=>void window.clearTimeout(t)),this._timeouts.clear()}}class x7{constructor(t){sn(this,"gestures",new Set),sn(this,"_targetEventStore",new c2(this)),sn(this,"gestureEventStores",{}),sn(this,"gestureTimeoutStores",{}),sn(this,"handlers",{}),sn(this,"config",{}),sn(this,"pointerIds",new Set),sn(this,"touchIds",new Set),sn(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),w7(this,t)}setEventIds(t){if(r2(t))return this.touchIds=new Set(z9(t)),this.touchIds;if("pointerId"in t)return t.type==="pointerup"||t.type==="pointercancel"?this.pointerIds.delete(t.pointerId):t.type==="pointerdown"&&this.pointerIds.add(t.pointerId),this.pointerIds}applyHandlers(t,n){this.handlers=t,this.nativeHandlers=n}applyConfig(t,n){this.config=S7(t,n,this.config)}clean(){this._targetEventStore.clean();for(const t of this.gestures)this.gestureEventStores[t].clean(),this.gestureTimeoutStores[t].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...t){const n=this.config.shared,r={};let s;if(!(n.target&&(s=n.target(),!s))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],l=CP(r,a.eventOptions,!!s);if(a.enabled){const c=s0.get(i);new c(this,t,i).bind(l)}}const o=CP(r,n.eventOptions,!!s);for(const i in this.nativeHandlers)o(i,"",a=>this.nativeHandlers[i](ut(ut({},this.state.shared),{},{event:a,args:t})),void 0,!0)}for(const o in r)r[o]=H9(...r[o]);if(!s)return r;for(const o in r){const{device:i,capture:a,passive:l}=L9(o);this._targetEventStore.add(s,i,"",r[o],{capture:a,passive:l})}}}}function pa(e,t){e.gestures.add(t),e.gestureEventStores[t]=new c2(e,t),e.gestureTimeoutStores[t]=new v7}function w7(e,t){t.drag&&pa(e,"drag"),t.wheel&&pa(e,"wheel"),t.scroll&&pa(e,"scroll"),t.move&&pa(e,"move"),t.pinch&&pa(e,"pinch"),t.hover&&pa(e,"hover")}const CP=(e,t,n)=>(r,s,o,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:t.capture,h=(c=i.passive)!==null&&c!==void 0?c:t.passive;let p=a?r:D9(r,s,u);n&&h&&(p+="Passive"),e[p]=e[p]||[],e[p].push(o)},b7=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function P7(e){const t={},n={},r=new Set;for(let s in e)b7.test(s)?(r.add(RegExp.lastMatch),n[s]=e[s]):t[s]=e[s];return[n,t,r]}function fa(e,t,n,r,s,o){if(!e.has(n)||!s0.has(r))return;const i=n+"Start",a=n+"End",l=c=>{let u;return c.first&&i in t&&t[i](c),n in t&&(u=t[n](c)),c.last&&a in t&&t[a](c),u};s[r]=l,o[r]=o[r]||{}}function C7(e,t){const[n,r,s]=P7(e),o={};return fa(s,n,"onDrag","drag",o,t),fa(s,n,"onWheel","wheel",o,t),fa(s,n,"onScroll","scroll",o,t),fa(s,n,"onPinch","pinch",o,t),fa(s,n,"onMove","move",o,t),fa(s,n,"onHover","hover",o,t),{handlers:o,config:t,nativeHandlers:r}}function I7(e,t={},n,r){const s=Ce.useMemo(()=>new x7(e),[]);if(s.applyHandlers(e,r),s.applyConfig(t,n),Ce.useEffect(s.effect.bind(s)),Ce.useEffect(()=>s.clean.bind(s),[]),t.target===void 0)return s.bind.bind(s)}function E7(e){return e.forEach(d7),function(n,r){const{handlers:s,nativeHandlers:o,config:i}=C7(n,r||{});return I7(s,i,void 0,o)}}const IP=10,k7=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function u2(e){let{deltaY:t,deltaX:n}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(t)>IP?IP*Math.sign(t):t)/100:e.shiftKey&&!k7&&(n=t,t=0),{x:-n,y:-t,z:-r}}const _7=E7([p7,h7]);let ga;const T7=e=>ga===void 0?(ga=e,!1):e-ga>120&&e-ga<160?(ga=e,!0):(ga=e,!1);function M7(e){const t=F(),n=P.useMemo(()=>{let r="not sure";const s=({event:y})=>{if(!t.getInstanceState().isFocused||(r="not sure",T7(Date.now())))return;const x=t.getEditingShapeId();if(x){const w=t.getShape(x);if(w&&t.getShapeUtil(w).canScroll(w)){const E=t.getShapePageBounds(x);if(E!=null&&E.containsPoint(t.inputs.currentPagePoint))return}}Ee(y),Ot(y);const m=u2(y);if(m.x===0&&m.y===0)return;const v={type:"wheel",name:"wheel",delta:m,point:new b(y.clientX,y.clientY),shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey};t.dispatch(v)};let o=1,i=1,a=1,l=0;const c=new b,u=new b,h=y=>{const x=e.current;r="not sure";const{event:m,origin:v,da:w}=y;m instanceof WheelEvent||(m.target===x||x!=null&&x.contains(m.target))&&(u.x=v[0],u.y=v[1],c.x=v[0],c.y=v[1],o=w[0],i=t.getZoomLevel(),t.dispatch({type:"pinch",name:"pinch_start",point:{x:v[0],y:v[1],z:t.getZoomLevel()},delta:{x:0,y:0},shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey}))},p=y=>{if(y&&(r="zooming"),r==="zooming")return;const x=Math.abs(l-o),m=b.Dist(c,u);switch(r){case"not sure":{x>24?r="zooming":m>16&&(r="panning");break}case"panning":{x>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:h,onPinchEnd:y=>{const x=e.current,{event:m,origin:v,offset:w}=y;if(m instanceof WheelEvent||!(m.target===x||x!=null&&x.contains(m.target)))return;const C=w[0];r="not sure",t.timers.requestAnimationFrame(()=>{t.dispatch({type:"pinch",name:"pinch_end",point:{x:v[0],y:v[1],z:C},delta:{x:v[0],y:v[1]},shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey})})},onPinch:y=>{const x=e.current,{event:m,origin:v,offset:w,da:C}=y;if(m instanceof WheelEvent||!(m.target===x||x!=null&&x.contains(m.target)))return;const E=y.type==="gesturechange"||y.type==="gestureend";l=C[0];const _=v[0]-u.x,I=v[1]-u.y;switch(u.x=v[0],u.y=v[1],p(E),r){case"zooming":{a=w[0],t.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:a},delta:{x:_,y:I},shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey});break}case"panning":{t.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:i},delta:{x:_,y:I},shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey});break}}}}},[t,e]);_7(n,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[t.getZoomLevel(),0],scaleBounds:()=>({from:t.getZoomLevel(),max:8,min:.05})}})}function Mm(e,t,n){const r=e.getShape(t),s=e.getShapeHandles(r);return{shape:r,handle:s.find(o=>o.id===n)}}function A7(e,t){const n=F();return P.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Up(l.currentTarget);Wu(c,l);const{shape:u,handle:h}=Mm(n,e,t);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...Nn(l)})};let s,o;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===s&&l.clientY===o)return;s=l.clientX,o=l.clientY;const{shape:c,handle:u}=Mm(n,e,t);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...Nn(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Up(l.currentTarget);Gu(c,l);const{shape:u,handle:h}=Mm(n,e,t);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...Nn(l)})}}},[n,e,t])}const et=class et{constructor(t=0,n=0,r=0,s=0){g(this,"x",0);g(this,"y",0);g(this,"w",0);g(this,"h",0);this.x=t,this.y=n,this.w=r,this.h=s}get point(){return new b(this.x,this.y)}set point(t){this.x=t.x,this.y=t.y}get minX(){return this.x}set minX(t){this.x=t}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get minY(){return this.y}set minY(t){this.y=t}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get width(){return this.w}set width(t){this.w=t}get height(){return this.h}set height(t){this.h=t}get aspectRatio(){return this.width/this.height}get center(){return new b(this.midX,this.midY)}set center(t){this.minX=t.x-this.width/2,this.minY=t.y-this.height/2}get corners(){return[new b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(this.minX,this.maxY)]}get cornersAndCenter(){return[new b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(this.minX,this.maxY),this.center]}get sides(){const{corners:t}=this;return[[t[0],t[1]],[t[1],t[2]],[t[2],t[3]],[t[3],t[0]]]}get size(){return new b(this.w,this.h)}toFixed(){return this.x=Ad(this.x),this.y=Ad(this.y),this.w=Ad(this.w),this.h=Ad(this.h),this}setTo(t){return this.x=t.x,this.y=t.y,this.w=t.w,this.h=t.h,this}set(t=0,n=0,r=0,s=0){return this.x=t,this.y=n,this.w=r,this.h=s,this}expand(t){const n=Math.min(this.minX,t.minX),r=Math.min(this.minY,t.minY),s=Math.max(this.maxX,t.maxX),o=Math.max(this.maxY,t.maxY);return this.x=n,this.y=r,this.w=s-n,this.h=o-r,this}expandBy(t){return this.x-=t,this.y-=t,this.w+=t*2,this.h+=t*2,this}scale(t){return this.x/=t,this.y/=t,this.w/=t,this.h/=t,this}clone(){const{x:t,y:n,w:r,h:s}=this;return new et(t,n,r,s)}translate(t){return this.x+=t.x,this.y+=t.y,this}snapToGrid(t){const n=Math.round(this.minX/t)*t,r=Math.round(this.minY/t)*t,s=Math.round(this.maxX/t)*t,o=Math.round(this.maxY/t)*t;this.minX=n,this.minY=r,this.width=Math.max(1,s-n),this.height=Math.max(1,o-r)}collides(t){return et.Collides(this,t)}contains(t){return et.Contains(this,t)}includes(t){return et.Includes(this,t)}containsPoint(t,n=0){return et.ContainsPoint(this,t,n)}getHandlePoint(t){switch(t){case"top_left":return new b(this.minX,this.minY);case"top_right":return new b(this.maxX,this.minY);case"bottom_left":return new b(this.minX,this.maxY);case"bottom_right":return new b(this.maxX,this.maxY);case"top":return new b(this.midX,this.minY);case"right":return new b(this.maxX,this.midY);case"bottom":return new b(this.midX,this.maxY);case"left":return new b(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(t,n,r){const{minX:s,minY:o,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:u,maxY:h}=this;switch(t){case"left":case"top_left":case"bottom_left":{l+=n;break}case"right":case"top_right":case"bottom_right":{u+=n;break}}switch(t){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{h+=r;break}}const p=(u-l)/(i-s),f=(h-c)/(a-o),S=p<0,y=f<0;if(S){const x=u;u=l,l=x}if(y){const x=h;h=c,c=x}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(h-c)}union(t){const n=Math.min(this.minX,t.x),r=Math.min(this.minY,t.y),s=Math.max(this.maxX,t.w+t.x),o=Math.max(this.maxY,t.h+t.y);return this.x=n,this.y=r,this.width=s-n,this.height=o-r,this}static From(t){return new et(t.x,t.y,t.w,t.h)}static FromCenter(t,n){return new et(t.x-n.x/2,t.y-n.y/2,n.x,n.y)}static FromPoints(t){if(t.length===0)return new et;let n=1/0,r=1/0,s=-1/0,o=-1/0,i;for(let a=0,l=t.length;a<l;a++)i=t[a],n=Math.min(i.x,n),r=Math.min(i.y,r),s=Math.max(i.x,s),o=Math.max(i.y,o);return new et(n,r,s-n,o-r)}static Expand(t,n){const r=Math.min(n.minX,t.minX),s=Math.min(n.minY,t.minY),o=Math.max(n.maxX,t.maxX),i=Math.max(n.maxY,t.maxY);return new et(r,s,o-r,i-s)}static ExpandBy(t,n){return new et(t.minX-n,t.minY-n,t.width+n*2,t.height+n*2)}static Resize(t,n,r,s,o=!1){const{minX:i,minY:a,maxX:l,maxY:c}=t;let{minX:u,minY:h,maxX:p,maxY:f}=t;switch(n){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(n){case"top":case"top_left":case"top_right":{h+=s;break}case"bottom":case"bottom_left":case"bottom_right":{f+=s;break}}const S=(p-u)/(l-i),y=(f-h)/(c-a),x=S<0,m=y<0;if(o){const w=(l-i)/(c-a),C=Math.abs(p-u),E=Math.abs(f-h),_=C*(y<0?1:-1)*(1/w),I=E*(S<0?1:-1)*w,k=w<C/E;switch(n){case"top_left":{k?h=f+_:u=p+I;break}case"top_right":{k?h=f+_:p=u-I;break}case"bottom_right":{k?f=h-_:p=u-I;break}case"bottom_left":{k?f=h-_:u=p+I;break}case"bottom":case"top":{const T=(u+p)/2,M=E*w;u=T-M/2,p=T+M/2;break}case"left":case"right":{const T=(h+f)/2,M=C/w;h=T-M/2,f=T+M/2;break}}}if(x){const w=p;p=u,u=w}if(m){const w=f;f=h,h=w}const v=new et(u,h,Math.abs(p-u),Math.abs(f-h));return{box:v,scaleX:+(v.width/t.width*(S>0?1:-1)).toFixed(5),scaleY:+(v.height/t.height*(y>0?1:-1)).toFixed(5)}}equals(t){return et.Equals(this,t)}static Equals(t,n){return n.x===t.x&&n.y===t.y&&n.w===t.w&&n.h===t.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(t){return new et(t.x,t.y,Math.max(1,t.w),Math.max(1,t.h))}};g(et,"Collides",(t,n)=>!(t.maxX<n.minX||t.minX>n.maxX||t.maxY<n.minY||t.minY>n.maxY)),g(et,"Contains",(t,n)=>t.minX<n.minX&&t.minY<n.minY&&t.maxY>n.maxY&&t.maxX>n.maxX),g(et,"Includes",(t,n)=>et.Collides(t,n)||et.Contains(t,n)),g(et,"ContainsPoint",(t,n,r=0)=>!(n.x<t.minX-r||n.y<t.minY-r||n.x>t.maxX+r||n.y>t.maxY+r)),g(et,"Common",t=>{let n=1/0,r=1/0,s=-1/0,o=-1/0;for(let i=0;i<t.length;i++){const a=t[i];n=Math.min(n,a.minX),r=Math.min(r,a.minY),s=Math.max(s,a.maxX),o=Math.max(o,a.maxY)}return new et(n,r,s-n,o-r)}),g(et,"Sides",(t,n=0)=>{const{corners:r}=t;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]});let Q=et;function j7(e){switch(e){case"top":return"bottom";case"bottom":return"top";case"top_left":return"bottom_left";case"top_right":return"bottom_right";case"bottom_left":return"top_left";case"bottom_right":return"top_right";default:return e}}function O7(e){switch(e){case"left":return"right";case"right":return"left";case"top_left":return"top_right";case"top_right":return"top_left";case"bottom_left":return"bottom_right";case"bottom_right":return"bottom_left";default:return e}}function D7(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function R7(e){const t=F();P.useLayoutEffect(()=>{let n=new Q;function r(){const c=e.current;if(!c)return null;const u=c.getBoundingClientRect(),h=new Q(u.left||u.x,u.top||u.y,Math.max(u.width,1),Math.max(u.height,1));n.equals(h)||(t.updateViewportScreenBounds(h),n=h)}r();const s=Ok(r,200,{trailing:!0}),o=t.timers.setInterval(s,1e3);window.addEventListener("resize",s);const i=new ResizeObserver(c=>{c[0].contentRect&&s()}),a=e.current;let l=null;return a&&(i.observe(a),l=L7(a),l.addEventListener("scroll",s)),()=>{clearInterval(o),window.removeEventListener("resize",s),i.disconnect(),l==null||l.removeEventListener("scroll",s),s.cancel()}},[t,e])}/*!
|
|
53
|
-
* Author: excalidraw
|
|
54
|
-
* MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
|
|
55
|
-
* https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
|
|
56
|
-
*/const L7=e=>{let t=e.parentElement;for(;t;){if(t===document.body)return document;const{overflowY:n}=window.getComputedStyle(t);if(t.scrollHeight>t.clientHeight&&(n==="auto"||n==="scroll"||n==="overlay"))return t;t=t.parentElement}return document},Re=class Re{constructor(t,n,r,s,o,i){g(this,"a",1);g(this,"b",0);g(this,"c",0);g(this,"d",1);g(this,"e",0);g(this,"f",0);this.a=t,this.b=n,this.c=r,this.d=s,this.e=o,this.f=i}equals(t){return this===t||this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(t){const n=t,{a:r,b:s,c:o,d:i,e:a,f:l}=this;return this.a=r*n.a+o*n.b,this.c=r*n.c+o*n.d,this.e=r*n.e+o*n.f+a,this.b=s*n.a+i*n.b,this.d=s*n.c+i*n.d,this.f=s*n.e+i*n.f+l,this}rotate(t,n,r){return t===0?this:n===void 0?this.multiply(Re.Rotate(t)):this.translate(n,r).multiply(Re.Rotate(t)).translate(-n,-r)}translate(t,n){return this.multiply(Re.Translate(t,n))}scale(t,n){return this.multiply(Re.Scale(t,n))}invert(){const{a:t,b:n,c:r,d:s,e:o,f:i}=this,a=t*s-n*r;return this.a=s/a,this.b=n/-a,this.c=r/-a,this.d=t/a,this.e=(s*o-r*i)/-a,this.f=(n*o-t*i)/a,this}applyToPoint(t){return Re.applyToPoint(this,t)}applyToPoints(t){return Re.applyToPoints(this,t)}rotation(){return Re.Rotation(this)}point(){return Re.Point(this)}decomposed(){return Re.Decompose(this)}toCssString(){return Re.toCssString(this)}setTo(t){return Object.assign(this,t),this}decompose(){return Re.Decompose(this)}clone(){return new Re(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new Re(1,0,0,1,0,0)}static Translate(t,n){return new Re(1,0,0,1,t,n)}static Rotate(t,n,r){if(t===0)return Re.Identity();const s=Math.cos(t),o=Math.sin(t),i=new Re(s,o,-o,s,0,0);return n===void 0?i:Re.Compose(Re.Translate(n,r),i,Re.Translate(-n,-r))}static Multiply(t,n){return{a:t.a*n.a+t.c*n.b,c:t.a*n.c+t.c*n.d,e:t.a*n.e+t.c*n.f+t.e,b:t.b*n.a+t.d*n.b,d:t.b*n.c+t.d*n.d,f:t.b*n.e+t.d*n.f+t.f}}static Inverse(t){const n=t.a*t.d-t.b*t.c;return{a:t.d/n,b:t.b/-n,c:t.c/-n,d:t.a/n,e:(t.d*t.e-t.c*t.f)/-n,f:(t.b*t.e-t.a*t.f)/n}}static Absolute(t){const n=t.a*t.d-t.b*t.c;return{a:t.d/n,b:t.b/-n,c:t.c/-n,d:t.a/n,e:(t.d*t.e-t.c*t.f)/n,f:(t.b*t.e-t.a*t.f)/-n}}static Compose(...t){const n=Re.Identity();for(let r=0,s=t.length;r<s;r++)n.multiply(t[r]);return n}static Point(t){return new b(t.e,t.f)}static Rotation(t){let n;if(t.a!==0||t.c!==0){const r=(t.a*t.a+t.c*t.c)**.5;n=Math.acos(t.a/r)*(t.c>0?-1:1)}else if(t.b!==0||t.d!==0){const r=(t.b*t.b+t.d*t.d)**.5;n=Ve+Math.acos(t.b/r)*(t.d>0?-1:1)}else n=0;return _S(n)}static Decompose(t){let n,r,s;if(t.a!==0||t.c!==0){const o=(t.a*t.a+t.c*t.c)**.5;n=o,r=(t.a*t.d-t.b*t.c)/o,s=Math.acos(t.a/o)*(t.c>0?-1:1)}else if(t.b!==0||t.d!==0){const o=(t.b*t.b+t.d*t.d)**.5;n=(t.a*t.d-t.b*t.c)/o,r=o,s=Ve+Math.acos(t.b/o)*(t.d>0?-1:1)}else n=0,r=0,s=0;return{x:t.e,y:t.f,scaleX:n,scaleY:r,rotation:_S(s)}}static Smooth(t,n=1e10){return t.a=Math.round(t.a*n)/n,t.b=Math.round(t.b*n)/n,t.c=Math.round(t.c*n)/n,t.d=Math.round(t.d*n)/n,t.e=Math.round(t.e*n)/n,t.f=Math.round(t.f*n)/n,t}static toCssString(t){return`matrix(${N(t.a)}, ${N(t.b)}, ${N(t.c)}, ${N(t.d)}, ${N(t.e)}, ${N(t.f)})`}static applyToPoint(t,n){return new b(t.a*n.x+t.c*n.y+t.e,t.b*n.x+t.d*n.y+t.f,n.z)}static applyToXY(t,n,r){return[t.a*n+t.c*r+t.e,t.b*n+t.d*r+t.f]}static applyToPoints(t,n){return n.map(r=>new b(t.a*r.x+t.c*r.y+t.e,t.b*r.x+t.d*r.y+t.f,r.z))}static applyToBounds(t,n){return new Q(t.e+n.minX,t.f+n.minY,n.width,n.height)}static From(t){return new Re(t.a,t.b,t.c,t.d,t.e,t.f)}static Cast(t){return t instanceof Re?t:Re.From(t)}};g(Re,"Scale",(t,n,r,s)=>{const o=new Re(t,0,0,n,0,0);return r===void 0?o:Re.Compose(Re.Translate(r,s),o,Re.Translate(-r,-s))});let oe=Re;function d2(e,t){return t===0?e:d2(t,e%t)}function h2(e){const t=e.toString().split(".")[1];if(!t)return 1;const n=Math.pow(10,t.length),r=parseInt(t,10);return n/d2(r,n)}class ii{constructor(t){g(this,"isFilled",!1);g(this,"isClosed",!0);g(this,"isLabel",!1);g(this,"debugColor");g(this,"ignore");g(this,"_vertices");g(this,"_bounds");g(this,"_area");g(this,"_length");this.isFilled=t.isFilled,this.isClosed=t.isClosed,this.isLabel=t.isLabel??!1,this.debugColor=t.debugColor,this.ignore=t.ignore}hitTestPoint(t,n=0,r=!1){return this.isClosed&&(this.isFilled||r)&&or(t,this.vertices)?!0:b.Dist2(t,this.nearestPoint(t))<=n*n}distanceToPoint(t,n=!1){return t.dist(this.nearestPoint(t))*(this.isClosed&&(this.isFilled||n)&&or(t,this.vertices)?-1:1)}distanceToLineSegment(t,n){if(t.equals(n))return this.distanceToPoint(t);const{vertices:r}=this;let s,o=1/0,i,a,l;for(let c=0;c<r.length;c++)a=r[c],l=b.NearestPointOnLineSegment(t,n,a,!0),i=b.Dist2(a,l),i<o&&(o=i,s=l);if(!s)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&or(s,this.vertices)?-o:o}hitTestLineSegment(t,n,r=0){return this.distanceToLineSegment(t,n)<=r}nearestPointOnLineSegment(t,n){const{vertices:r}=this;let s,o=1/0,i,a,l;for(let c=0;c<r.length;c++)a=r[c],l=b.NearestPointOnLineSegment(t,n,a,!0),i=b.Dist2(a,l),i<o&&(o=i,s=l);if(!s)throw Error("nearest point not found");return s}isPointInBounds(t,n=0){const{bounds:r}=this;return!(t.x<r.minX-n||t.y<r.minY-n||t.x>r.maxX+n||t.y>r.maxY+n)}get vertices(){return this._vertices||(this._vertices=this.getVertices()),this._vertices}getBounds(){return Q.FromPoints(this.vertices)}get bounds(){return this._bounds||(this._bounds=this.getBounds()),this._bounds}get center(){return this.bounds.center}get area(){return this._area||(this._area=this.getArea()),this._area}getArea(){if(!this.isClosed)return 0;const{vertices:t}=this;let n=0;for(let r=0,s=t.length;r<s;r++){const o=t[r],i=t[(r+1)%s];n+=o.x*i.y-i.x*o.y}return n/2}toSimpleSvgPath(){let t="";const{vertices:n}=this,r=n.length;if(r===0)return t;t+=`M${n[0].x},${n[0].y}`;for(let s=1;s<r;s++)t+=`L${n[s].x},${n[s].y}`;return this.isClosed&&(t+="Z"),t}get length(){return this._length?this._length:(this._length=this.getLength(),this._length)}getLength(){const{vertices:t}=this;let n,r=t[0],s=0;for(let o=1;o<t.length;o++)n=t[o],s+=b.Dist2(r,n),r=n;return Math.sqrt(s)}}class Gr extends ii{constructor(n){super({...n,isClosed:!0,isFilled:!1});g(this,"children",[]);g(this,"ignoredChildren",[]);for(const r of n.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(n=>!n.isLabel).flatMap(n=>n.vertices)}nearestPoint(n){let r=1/0,s;const{children:o}=this;if(o.length===0)throw Error("no children");let i,a;for(const l of o)i=l.nearestPoint(n),a=b.Dist2(i,n),a<r&&(r=a,s=i);if(!s)throw Error("nearest point not found");return s}distanceToPoint(n,r=!1){return Math.min(...this.children.map((s,o)=>s.distanceToPoint(n,r||o>0)))}hitTestPoint(n,r,s){return!!this.children.filter(o=>!o.isLabel).find(o=>o.hitTestPoint(n,r,s))}hitTestLineSegment(n,r,s){return!!this.children.filter(o=>!o.isLabel).find(o=>o.hitTestLineSegment(n,r,s))}getArea(){return this.children[0].area}toSimpleSvgPath(){let n="";for(const s of this.children)n+=s.toSimpleSvgPath();const r=Q.FromPoints(this.vertices).corners;for(let s=0,o=r.length;s<o;s++){const i=r[s],a=r[(s-1+o)%o],l=i.dist(a),c=r[(s+1)%o],u=i.dist(c),h=i.clone().lrp(a,4/l),p=i,f=i.clone().lrp(c,4/u);n+=`M${h.x},${h.y} L${p.x},${p.y} L${f.x},${f.y} `}return n}getLength(){return this.children.reduce((n,r)=>r.isLabel?n:n+r.length,0)}getSvgPathData(){return this.children.map((n,r)=>n.isLabel?"":n.getSvgPathData(r===0)).join(" ")}}function $7(e=!0){const[t,n]=P.useState(0),r=F();P.useEffect(()=>{if(!e)return;const s=()=>n(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,e])}const N7=Lt(function({showStroke:t=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const s=F();$7(r);const o=s.getZoomLevel(),i=s.getRenderingShapes(),{inputs:{currentPagePoint:a}}=s;return d.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=s.getShape(l.id);if(c.type==="group")return null;const u=s.getShapeGeometry(c),h=s.getShapePageTransform(c),p=s.getPointInShapeSpace(c,a),f=u.nearestPoint(p),S=u.distanceToPoint(p,!0),y=Math.abs(S)*o,x=S<0,{vertices:m}=u;return d.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[t&&d.jsx("g",{stroke:u.debugColor??"red",opacity:"1",strokeWidth:2/o,fill:"none",children:d.jsx(p2,{geometry:u})}),n&&m.map((v,w)=>d.jsx("circle",{cx:v.x,cy:v.y,r:2/o,fill:`hsl(${il(w,[0,m.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/o},`v${w}`)),r&&y<150&&d.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-y/150,stroke:x?"goldenrod":"dodgerblue",strokeWidth:2/o})]},l.id+"_outline")})})});function p2({geometry:e}){return e instanceof Gr?d.jsx(d.Fragment,{children:[...e.children,...e.ignoredChildren].map((t,n)=>d.jsx(p2,{geometry:t},n))}):d.jsx("path",{d:e.toSimpleSvgPath()})}function f2(e){return cB(e)}function g2(){const e=F(),t=u9("userIds",()=>f2(e.getCollaborators().map(n=>n.userId)).sort(),{isEqual:(n,r)=>{var s;return n.join(",")===((s=r.join)==null?void 0:s.call(r,","))}},[e]);return K(t)}function Yf(e){const t=F();return K(`latestPresence:${e}`,()=>t.getCollaborators().find(r=>r.userId===e),[t,e])??null}const F7=Lt(function(){return g2().map(n=>d.jsx(z7,{collaboratorId:n},n))}),z7=Lt(function({collaboratorId:t}){const n=F(),r=Yf(t),s=U7(n,r);if(!(r&&r.currentPageId===n.getCurrentPageId()))return null;switch(s){case"inactive":{const{followingUserId:o,highlightedUserIds:i}=n.getInstanceState();if(!(o===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:o}=n.getInstanceState();if(r.followingUserId===n.user.getId()&&!(r.chatMessage||o.includes(r.userId)))return null;break}}return d.jsx(B7,{latestPresence:r})}),B7=Lt(function({latestPresence:t}){const n=F(),{CollaboratorBrush:r,CollaboratorScribble:s,CollaboratorCursor:o,CollaboratorHint:i,CollaboratorShapeIndicator:a}=ot(),l=n.getZoomLevel(),c=n.getViewportPageBounds(),{userId:u,chatMessage:h,brush:p,scribbles:f,selectedShapeIds:S,userName:y,cursor:x,color:m}=t,v=!(x.x<c.minX-12/l||x.y<c.minY-16/l||x.x>c.maxX-12/l||x.y>c.maxY-16/l);return d.jsxs(d.Fragment,{children:[p&&r?d.jsx(r,{className:"tl-collaborator__brush",brush:p,color:m,opacity:.1},u+"_brush"):null,v&&o?d.jsx(o,{className:"tl-collaborator__cursor",point:x,color:m,zoom:l,name:y!=="New User"?y:null,chatMessage:h},u+"_cursor"):i?d.jsx(i,{className:"tl-collaborator__cursor-hint",point:x,color:m,zoom:l,viewport:c},u+"_cursor_hint"):null,s&&f.length?d.jsx(d.Fragment,{children:f.map(w=>d.jsx(s,{className:"tl-collaborator__scribble",scribble:w,color:m,zoom:l,opacity:w.color==="laser"?.5:.1},u+"_scribble_"+w.id))}):null,a&&S.map(w=>d.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:w,color:m,opacity:.5},u+"_"+w))]})});function EP(e,t){return t>e.options.collaboratorInactiveTimeoutMs?"inactive":t>e.options.collaboratorIdleTimeoutMs?"idle":"active"}function U7(e,t){const n=P.useRef((t==null?void 0:t.lastActivityTimestamp)??-1),[r,s]=P.useState(()=>EP(e,Date.now()-n.current));return P.useEffect(()=>{const o=e.timers.setInterval(()=>{s(EP(e,Date.now()-n.current))},e.options.collaboratorCheckIntervalMs);return()=>clearInterval(o)},[e]),t&&(n.current=t.lastActivityTimestamp),r}const m2=P.memo(function({id:t,shape:n,util:r,index:s,backgroundIndex:o,opacity:i,dprMultiple:a}){const l=F(),{ShapeErrorFallback:c}=ot(),u=P.useRef(null),h=P.useRef(null),p=P.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});Lo("set shape stuff",()=>{const y=l.getShape(t);if(!y)return;const x=p.current,m=l.getShapeClipPath(t)??"none";m!==x.clipPath&&(nn(u.current,"clip-path",m),nn(h.current,"clip-path",m),x.clipPath=m);const v=l.getShapePageTransform(t),w=oe.toCssString(v),C=l.getShapeGeometry(y).bounds;w!==x.transform&&(nn(u.current,"transform",w),nn(h.current,"transform",w),x.transform=w);const E=C.w%a,_=C.h%a,I=E===0?C.w:C.w+(a-E),k=_===0?C.h:C.h+(a-_);(I!==x.width||k!==x.height)&&(nn(u.current,"width",Math.max(I,a)+"px"),nn(u.current,"height",Math.max(k,a)+"px"),nn(h.current,"width",Math.max(I,a)+"px"),nn(h.current,"height",Math.max(k,a)+"px"),x.width=I,x.height=k)},[l]),Lo("set opacity and z-index",()=>{const y=u.current,x=h.current;nn(y,"opacity",i),nn(x,"opacity",i),nn(y,"z-index",s),nn(x,"z-index",o)},[i,s,o]),Lo("set display",()=>{if(!l.getShape(t))return;const m=l.getCulledShapes().has(t);m!==p.current.isCulled&&(nn(u.current,"display",m?"none":"block"),nn(h.current,"display",m?"none":"block"),p.current.isCulled=m)},[l]);const f=P.useCallback(y=>l.annotateError(y,{origin:"shape",willCrashApp:!1}),[l]);if(!n)return null;const S="fill"in n.props&&n.props.fill!=="none";return d.jsxs(d.Fragment,{children:[r.backgroundComponent&&d.jsx("div",{ref:h,className:"tl-shape tl-shape-background","data-shape-type":n.type,draggable:!1,children:d.jsx(au,{fallback:c,onError:f,children:d.jsx(K7,{shape:n,util:r})})}),d.jsx("div",{ref:u,className:"tl-shape","data-shape-type":n.type,"data-shape-is-filled":S,draggable:!1,children:d.jsx(au,{fallback:c,onError:f,children:d.jsx(H7,{shape:n,util:r})})})]})}),H7=P.memo(function({shape:t,util:n}){return Gf("InnerShape:"+t.type,()=>n.component(n.editor.store.unsafeGetWithoutCapture(t.id)))},(e,t)=>e.shape.props===t.shape.props&&e.shape.meta===t.shape.meta),K7=P.memo(function({shape:t,util:n}){return Gf("InnerShape:"+t.type,()=>{var r;return(r=n.backgroundComponent)==null?void 0:r.call(n,n.editor.store.unsafeGetWithoutCapture(t.id))})},(e,t)=>e.shape.props===t.shape.props&&e.shape.meta===t.shape.meta);function W7({className:e}){const t=F(),{Background:n,SvgDefs:r,ShapeIndicators:s}=ot(),o=P.useRef(null),i=P.useRef(null),a=P.useRef(null),l=$t();R7(o),C9(),b9(),M7(o),k9(o);const c=P.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});Lo("position layers",function(){const{x:v,y:w,z:C}=t.getCamera();if(c.current.allowTextOutline&&t.environment.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&C<t.options.textShadowLod!==c.current.lodDisableTextOutline){const I=C<t.options.textShadowLod;l.style.setProperty("--tl-text-outline",I?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=I}const E=C>=1?il(C,[1,8],[.125,.5],!0):il(C,[.1,1],[-2,.125],!0),_=`scale(${N(C)}) translate(${N(v+E)}px,${N(w+E)}px)`;nn(i.current,"transform",_),nn(a.current,"transform",_)},[t,l]);const u=e2(),h=K("shapeSvgDefs",()=>{const m=new Map;for(const v of gt(t.shapeUtils)){if(!v)return;const w=v.getCanvasSvgDefs();for(const{key:C,component:E}of w)m.has(C)||m.set(C,d.jsx(E,{},C))}return[...m.values()]},[t]),p=K("debug_shapes",()=>xt.hideShapes.get(),[xt]),f=K("debug_svg",()=>xt.debugSvg.get(),[xt]),S=K("debug_geometry",()=>xt.debugGeometry.get(),[xt]),y=K("isEditingAnything",()=>t.getEditingShapeId()!==null,[t]),x=K("isSelectingAnything",()=>!!t.getSelectedShapeIds().length,[t]);return d.jsxs(d.Fragment,{children:[d.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":y,"data-isselectinganything":x,className:ce("tl-canvas",e),"data-testid":"canvas",...u,children:[d.jsx("svg",{className:"tl-svg-context",children:d.jsxs("defs",{children:[h,d.jsx(oH,{}),d.jsx(iH,{}),r&&d.jsx(r,{})]})}),n&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(n,{})}),d.jsx(V7,{}),d.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(uH,{}),d.jsx(cH,{}),p?null:f?d.jsx(tH,{}):d.jsx(rH,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:a,className:"tl-html-layer",children:[S?d.jsx(N7,{}):null,d.jsx(Q7,{}),d.jsx(X7,{}),d.jsx(Y7,{}),d.jsx(q7,{}),s&&d.jsx(s,{}),d.jsx(sH,{}),d.jsx(Z7,{}),d.jsx(lH,{}),d.jsx(F7,{})]})}),d.jsx(dH,{})]}),d.jsx(G7,{})]})}function G7(){const{InFrontOfTheCanvas:e}=ot();return e?d.jsx(e,{}):null}function V7(){const e=F(),t=K("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:n,y:r,z:s}=K("camera",()=>e.getCamera(),[e]),o=K("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=ot();return i&&o?d.jsx(i,{x:n,y:r,z:s,size:t}):null}function Y7(){const e=F(),t=K("scribbles",()=>e.getInstanceState().scribbles,[e]),n=K("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=ot();return r&&t.length?t.map(s=>d.jsx(r,{className:"tl-user-scribble",scribble:s,zoom:n},s.id)):null}function X7(){const e=F(),t=K("brush",()=>e.getInstanceState().brush,[e]),{Brush:n}=ot();return n&&t?d.jsx(n,{className:"tl-user-brush",brush:t}):null}function q7(){const e=F(),t=K("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:n}=ot();return n&&t?d.jsx(n,{className:"tl-user-brush tl-zoom-brush",brush:t}):null}function Z7(){const e=F(),t=K("snapLines",()=>e.snaps.getIndicators(),[e]),n=K("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=ot();return r&&t.length>0?t.map(s=>d.jsx(r,{className:"tl-user-snapline",line:s,zoom:n},s.id)):null}function Q7(){const e=F(),t=K("handles shapeIdWithHandles",()=>{const{isReadonly:n,isChangingStyle:r}=e.getInstanceState();if(n||r)return!1;const s=e.getOnlySelectedShape();return!s||!e.getShapeHandles(s)?!1:s.id},[e]);return t?d.jsx(J7,{shapeId:t}):null}function J7({shapeId:e}){const t=F(),{Handles:n}=ot(),r=K("zoomLevel",()=>t.getZoomLevel(),[t]),s=K("coarse pointer",()=>t.getInstanceState().isCoarsePointer,[t]),o=K("handles transform",()=>t.getShapePageTransform(e),[t,e]),i=K("handles",()=>{const a=t.getShapeHandles(e);if(!a)return null;const l=(s?t.options.coarseHandleRadius:t.options.handleRadius)/r*2;return a.filter(c=>c.type!=="virtual"||!a.some(u=>u!==c&&u.type==="vertex"&&b.Dist(c,u)<l)).sort(c=>c.type==="vertex"?1:-1)},[t,r,s,e]);return!n||!i||!o?null:d.jsx(n,{children:d.jsx("g",{transform:oe.toCssString(o),children:i.map(a=>d.jsx(eH,{shapeId:e,handle:a,zoom:r,isCoarse:s},a.id))})})}function eH({shapeId:e,handle:t,zoom:n,isCoarse:r}){const s=A7(e,t.id),{Handle:o}=ot();return o?d.jsx("g",{"aria-label":"handle",transform:`translate(${t.x}, ${t.y})`,...s,children:d.jsx(o,{shapeId:e,handle:t,zoom:n,isCoarse:r})}):null}function tH(){const e=F(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=K("dpr multiple",()=>h2(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return t.map(r=>d.jsxs(P.Fragment,{children:[d.jsx(m2,{...r,dprMultiple:n}),d.jsx(aH,{id:r.id})]},r.id+"_fragment"))}function nH(){const e=F(),t=P.useRef(new Set);return Lo("reflow for culled shapes",()=>{const n=e.getCulledShapes();if(t.current.size===n.size&&[...n].every(s=>t.current.has(s)))return;t.current=n;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[e]),null}function rH(){const e=F(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=K("dpr multiple",()=>h2(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return d.jsxs(d.Fragment,{children:[t.map(r=>d.jsx(m2,{...r,dprMultiple:n},r.id+"_shape")),e.environment.isSafari&&d.jsx(nH,{})]})}function sH(){const e=F(),{ShapeIndicator:t}=ot(),n=K("hinting shape ids",()=>Fx(e.getHintingShapeIds()),[e]);return!n.length||!t?null:n.map(r=>d.jsx(t,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function oH(){return d.jsxs("g",{id:"cursor",children:[d.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),d.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function iH(){return d.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function aH({id:e}){const t=F(),[n,r]=P.useState(null),s=K("is in root",()=>{const o=t.getShape(e);return(o==null?void 0:o.parentId)===t.getCurrentPageId()},[t,e]);return P.useEffect(()=>{if(!s)return;let o=null;const i=ra("shape to svg",async()=>{const a=Math.random();o=a;const c=t.isShapeOfType(e,"frame")?0:10;let u=t.getShapePageBounds(e);if(!u)return;u=u.clone().expandBy(c);const h=await t.getSvgString([e],{padding:c,background:t.getInstanceState().exportBackground});if(o!==a||!h)return;const p=`data:image/svg+xml;utf8,${encodeURIComponent(h.svg)}`;r({src:p,bounds:u})});return()=>{o=null,i()}},[t,e,s]),!s||!n?null:d.jsx("img",{src:n.src,width:n.bounds.width,height:n.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${n.bounds.x}px, ${n.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function lH(){const e=F(),t=K("selection rotation",()=>e.getSelectionRotation(),[e]),n=K("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=ot();return!n||!r?null:d.jsx(r,{bounds:n,rotation:t})}function cH(){const e=F(),t=K("selection rotation",()=>e.getSelectionRotation(),[e]),n=K("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=ot();return!n||!r?null:d.jsx(r,{bounds:n,rotation:t})}function uH(){const{OnTheCanvas:e}=ot();return e?d.jsx(e,{}):null}function dH(){const e=F(),t=K("camera state",()=>e.getCameraState(),[e]);return d.jsx("div",{className:ce("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":t==="idle"})})}function hH({className:e,zoom:t,point:n,color:r,viewport:s,opacity:o=1}){const i=P.useRef(null);return Ml(i,_t(n.x,s.minX+5/t,s.maxX-5/t),_t(n.y,s.minY+5/t,s.maxY-5/t),1/t,b.Angle(s.center,n)),d.jsxs("svg",{ref:i,className:ce("tl-overlays__item",e),children:[d.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),d.jsx("use",{href:"#cursor_hint",color:r,opacity:o})]})}const kP=P.memo(function({className:t,zoom:n,point:r,color:s,name:o,chatMessage:i}){const a=P.useRef(null);return Ml(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n),r?d.jsxs("div",{ref:a,className:ce("tl-overlays__item",t),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:"#cursor",color:s})}),i?d.jsxs(d.Fragment,{children:[o&&d.jsx("div",{className:"tl-nametag-title",style:{color:s},children:o}),d.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:s},children:i})]}):o&&d.jsx("div",{className:"tl-nametag",style:{backgroundColor:s},children:o})]}):null});function y2(){return P.useId().replace(/:/g,"_")}function pH({x:e,y:t,z:n,size:r}){const s=`grid_${y2()}`,o=F(),{gridSteps:i}=o.options;return d.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[d.jsx("defs",{children:i.map(({min:a,mid:l,step:c},u)=>{const h=c*r*n,p=.5+e*n,f=.5+t*n,S=p>0?p%h:h+p%h,y=f>0?f%h:h+f%h,x=n<l?il(n,[a,l],[0,1]):1;return d.jsx("pattern",{id:`${s}_${c}`,width:h,height:h,patternUnits:"userSpaceOnUse",children:d.jsx("circle",{className:"tl-grid-dot",cx:S,cy:y,r:1,opacity:x})},u)})}),i.map(({step:a},l)=>d.jsx("rect",{width:"100%",height:"100%",fill:`url(#${s}_${a})`},l))]})}function fH({handle:e,isCoarse:t,className:n,zoom:r}){const s=F(),o=(t?s.options.coarseHandleRadius:s.options.handleRadius)/r;if(e.type==="clone"){const a=3/r,l=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,c=x9.indexOf(e.id);return d.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,n),children:[d.jsx("circle",{className:"tl-handle__bg",r:o}),d.jsx("path",{className:"tl-handle__fg",d:l,transform:`rotate(${-90+90*c})`})]})}const i=(e.type==="create"&&t?3:4)/Math.max(r,.25);return d.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,n),children:[d.jsx("circle",{className:"tl-handle__bg",r:o}),d.jsx("circle",{className:"tl-handle__fg",r:i})]})}const gH=({children:e})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),mH=()=>{const{Spinner:e}=ot();return d.jsx(aw,{children:e?d.jsx(e,{}):null})};function o0(e,t=!0){const n=e.length;if(n<2)return"";let r=e[0],s=e[1];if(n===2)return`M${Te(r)}L${Te(s)}`;let o="";for(let i=2,a=n-1;i<a;i++)r=e[i],s=e[i+1],o+=Dn(r,s);return t?`M${Dn(e[0],e[1])}Q${Te(e[1])}${Dn(e[1],e[2])}T${o}${Dn(e[n-1],e[0])}${Dn(e[0],e[1])}Z`:`M${Te(e[0])}Q${Te(e[1])}${Dn(e[1],e[2])}${e.length>3?"T":""}${o}L${Te(e[n-1])}`}function _P({scribble:e,zoom:t,color:n,opacity:r,className:s}){return e.points.length?d.jsx("svg",{className:s&&ce("tl-overlays__item",s),children:d.jsx("path",{className:"tl-scribble",d:o0(e.points,!1),stroke:n??`var(--color-${e.color})`,fill:"none",strokeWidth:8/t,opacity:r??e.opacity})}):null}function S2({bounds:e,rotation:t}){const n=P.useRef(null);return Ml(n,e.x,e.y,1,t),P.useLayoutEffect(()=>{const r=n.current;r&&(r.style.width=N(Math.max(1,e.width))+"px",r.style.height=N(Math.max(1,e.height))+"px")},[e.width,e.height]),d.jsx("div",{ref:n,className:"tl-selection__bg",draggable:!1})}function yH({bounds:e,rotation:t}){const n=F(),r=P.useRef(null),s=K("only selected shape",()=>n.getOnlySelectedShape(),[n]),o=s?n.getShapeUtil(s).expandSelectionOutlinePx(s):0;return Ml(r,e==null?void 0:e.x,e==null?void 0:e.y,1,t,{x:-o,y:-o}),e=e.clone().expandBy(o).zeroFix(),d.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsx("rect",{className:ce("tl-selection__fg__outline"),width:N(e.width),height:N(e.height)})})}const SH=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),vH=({shape:e,util:t})=>Gf("Indicator: "+e.type,()=>t.indicator(t.editor.store.unsafeGetWithoutCapture(e.id))),xH=({editor:e,id:t})=>{const n=K("shape for indicator",()=>e.store.get(t),[e,t]),{ShapeIndicatorErrorFallback:r}=ot();return!n||n.isLocked?null:d.jsx(au,{fallback:r,onError:s=>e.annotateError(s,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(vH,{shape:n,util:e.getShapeUtil(n)},n.id)})},TP=P.memo(function({shapeId:t,className:n,color:r,hidden:s,opacity:o}){const i=F(),a=P.useRef(null);return Lo("indicator transform",()=>{const l=a.current;if(!l)return;const c=i.getShapePageTransform(t);c&&l.style.setProperty("transform",c.toCssString())},[i,t]),P.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",s?"none":"block")},[s]),d.jsx("svg",{ref:a,className:ce("tl-overlays__item",n),children:d.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:o,children:d.jsx(xH,{editor:i,id:t})})})}),wH=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),v2=P.memo(function(){const t=F(),n=P.useRef(new Set),r=K("should display selected ids",()=>{const i=n.current,a=new Set;if(t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!t.getInstanceState().isChangingStyle){const l=t.getSelectedShapeIds();for(const c of l)a.add(c);if(t.isInAny("select.idle","select.editing_shape")){const c=t.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const u=t.getHoveredShapeId();u&&a.add(u)}}}if(i.size!==a.size)return n.current=a,a;for(const l of a)if(!i.has(l))return n.current=a,a;return i},[t]),s=K("rendering shapes",()=>t.getRenderingShapes(),[t]),{ShapeIndicator:o}=ot();return o?s.map(({id:i})=>d.jsx(o,{shapeId:i,hidden:!r.has(i)},i+"_indicator")):null});function bH({points:e,zoom:t}){const n=2.5/t,r=e.reduce((p,f)=>Math.min(p,f.x),1/0),s=e.reduce((p,f)=>Math.max(p,f.x),-1/0),o=e.reduce((p,f)=>Math.min(p,f.y),1/0),i=e.reduce((p,f)=>Math.max(p,f.y),-1/0),a=e.some(p=>p.x===r&&p.y===o);let l,c,u,h;return a?(l=r,c=o,u=s,h=i):(l=r,c=i,u=s,h=o),d.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[d.jsx("line",{x1:l,y1:c,x2:u,y2:h}),e.map((p,f)=>d.jsx("g",{transform:`translate(${p.x},${p.y})`,children:d.jsx("path",{className:"tl-snap-point",d:`M ${-n},${-n} L ${n},${n} M ${-n},${n} L ${n},${-n}`})},f))]})}function PH({gaps:e,direction:t,zoom:n}){const r=3.5/n;let s=[-1/0,1/0],o=null;const i=t==="horizontal";for(const l of e){if(o=Lr(s[0],s[1],i?l.startEdge[0].y:l.startEdge[0].x,i?l.startEdge[1].y:l.startEdge[1].x),o)s=o;else continue;if(o=Lr(s[0],s[1],i?l.endEdge[0].y:l.endEdge[0].x,i?l.endEdge[1].y:l.endEdge[1].x),o)s=o;else continue}if(s===null)return null;const a=(s[0]+s[1])/2;return d.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:l,endEdge:c},u)=>d.jsx(P.Fragment,{children:i?d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),d.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),d.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),d.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),d.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),d.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),d.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},u))})}function CH({className:e,line:t,zoom:n}){return d.jsx("svg",{className:ce("tl-overlays__item",e),children:t.type==="points"?d.jsx(bH,{...t,zoom:n}):t.type==="gaps"?d.jsx(PH,{...t,zoom:n}):null})}function i0(){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const IH=()=>null;function x2(e,t){const n=P.useRef(e);return t(e,n.current)?n.current:(n.current=e,e)}function zc(e){return x2(e,hB)}const EH=(e,t)=>(e??(e=null),t??(t=null),e===t?!0:!e||!t?!1:Gk(e,t));function Xf(e){return x2(e,EH)}const w2=P.createContext(null);function kH({overrides:e={},children:t}){const n=Xf(e),r=P.useMemo(()=>({Background:p9,SvgDefs:IH,Brush:_m,ZoomBrush:_m,CollaboratorBrush:_m,Cursor:kP,CollaboratorCursor:kP,CollaboratorHint:hH,CollaboratorShapeIndicator:TP,Grid:pH,Scribble:_P,SnapIndicator:CH,Handles:gH,Handle:fH,CollaboratorScribble:_P,ErrorFallback:P2,ShapeErrorFallback:SH,ShapeIndicatorErrorFallback:wH,Spinner:i0,SelectionBackground:S2,SelectionForeground:yH,ShapeIndicators:v2,ShapeIndicator:TP,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:W7,LoadingScreen:mH,...n}),[n]);return d.jsx(w2.Provider,{value:r,children:t})}function ot(){const e=P.useContext(w2);if(!e)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}const a0={openWindow:(e,t)=>window.open(e,t,"noopener noreferrer"),refreshPage:()=>window.location.reload(),hardReset:async()=>{var e;return await((e=window.__tldraw__hardReset)==null?void 0:e.call(window))}};function b2(){a0.hardReset()}function _H(){a0.refreshPage()}const TH="https://github.com/tldraw/tldraw/issues/new",P2=({error:e,editor:t})=>{const n=P.useRef(null),[r,s]=P.useState(!1),[o,i]=P.useState(!1),[a,l]=P.useState(!1);let c=null;try{c=ot().Canvas??null}catch{}const u=e instanceof Error?e.message:String(e),h=e instanceof Error?e.stack:null,p=K("isDarkMode",()=>{try{if(t)return t.user.getIsDarkMode()}catch{}return null},[t]),[f,S]=P.useState(null);P.useLayoutEffect(()=>{var E;p!==null&&S(p);let w=(E=n.current)==null?void 0:E.parentElement,C=!1;for(;w;){if(w.classList.contains("tl-theme__dark")||w.classList.contains("tl-theme__light")){C=!0;break}w=w.parentElement}if(C){S(null);return}typeof window<"u"&&"matchMedia"in window&&S(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),P.useEffect(()=>{if(o){const w=t==null?void 0:t.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(w)}},[o,t]);const y=()=>{const w=document.createElement("textarea");w.value=h??u,document.body.appendChild(w),w.select(),document.execCommand("copy"),w.remove(),i(!0)},x=()=>{_H()},m=async()=>{b2()},v=new URL(TH);return v.searchParams.set("title",u),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
|
|
57
|
-
|
|
58
|
-
\`\`\`js
|
|
59
|
-
${h??u}
|
|
60
|
-
\`\`\`
|
|
61
|
-
|
|
62
|
-
My browser: ${navigator.userAgent}`),d.jsxs("div",{ref:n,className:ce("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[d.jsx("div",{className:"tl-error-boundary__overlay"}),t&&d.jsx(q_,{onError:nu,fallback:()=>null,children:d.jsx(Vf.Provider,{value:t,children:d.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?d.jsx(c,{}):null})})}),d.jsx("div",{className:ce("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Are you sure?"}),d.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),d.jsx("button",{className:"tl-error-boundary__reset",onClick:m,children:"Reset data"})]})]}):d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Something's gone wrong."}),d.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",d.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",d.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&d.jsxs(d.Fragment,{children:["Message:",d.jsx("h4",{children:d.jsx("code",{children:u})}),"Stack trace:",d.jsxs("div",{className:"tl-error-boundary__content__error",children:[d.jsx("pre",{children:d.jsx("code",{children:h??u})}),d.jsx("button",{onClick:y,children:o?"Copied!":"Copy"})]})]}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>s(!r),children:r?"Hide details":"Show details"}),d.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[d.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),d.jsx("button",{className:"tl-error-boundary__refresh",onClick:x,children:"Refresh Page"})]})]})]})})]})};function ct(){return Uu()}const C2="TLDRAW_USER_DATA_v3",I2=xe({id:fe,name:fe.nullable().optional(),locale:fe.nullable().optional(),color:fe.nullable().optional(),colorScheme:Kf("light","dark","system").optional(),animationSpeed:he.nullable().optional(),edgeScrollSpeed:he.nullable().optional(),isSnapMode:Se.nullable().optional(),isWrapMode:Se.nullable().optional(),isDynamicSizeMode:Se.nullable().optional(),isPasteAtCursorMode:Se.nullable().optional()}),Ls={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},l0=Math.max(...Object.values(Ls));function MH(e){e.version<Ls.AddAnimationSpeed&&(e.user.animationSpeed=1),e.version<Ls.AddIsSnapMode&&(e.user.isSnapMode=!1),e.version<Ls.MakeFieldsNullable,e.version<Ls.AddEdgeScrollSpeed&&(e.user.edgeScrollSpeed=1),e.version<Ls.AddExcalidrawSelectMode&&(e.user.isWrapMode=!1),e.version<Ls.AllowSystemColorScheme&&(e.user.isDarkMode===!0?e.user.colorScheme="dark":e.user.isDarkMode===!1&&(e.user.colorScheme="light"),delete e.user.isDarkMode),e.version<Ls.AddDynamicSizeMode&&(e.user.isDynamicSizeMode=!1),e.version<Ls.AddPasteAtCursor&&(e.user.isPasteAtCursorMode=!1),e.version=l0}const jS=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function E2(){return jS[Math.floor(Math.random()*jS.length)]}function AH(){var e,t;return typeof window<"u"&&"matchMedia"in window?((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:t.matches)??!1:!1}const Rs=Object.freeze({name:"New User",locale:o9(),color:E2(),edgeScrollSpeed:1,animationSpeed:AH()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"system"});function Am(){return{id:ct(),color:E2()}}function k2(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return Am();const t=Ge(e);MH(t);try{return I2.validate(t.user)}catch{return Am()}}function jH(){const e=JSON.parse(Ux(C2)||"null")??null;return k2(e)}const qf=Mt("globalUserData",null);function OH(){Hx(C2,JSON.stringify({version:l0,user:qf.get()}))}function _2(e){I2.validate(e),qf.set(e),OH(),RH()}const DH=typeof process<"u"&&!1,Ya=typeof BroadcastChannel<"u"&&!DH?new BroadcastChannel("tldraw-user-sync"):null;Ya==null||Ya.addEventListener("message",e=>{const t=e.data;(t==null?void 0:t.type)===M2&&(t==null?void 0:t.origin)!==T2()&&qf.set(k2(t.data))});let jm=null;function T2(){return jm===null&&(jm=ct()),jm}const M2="tldraw-user-preferences-change";function RH(){Ya==null||Ya.postMessage({type:M2,origin:T2(),data:{user:A2(),version:l0}})}function A2(){let e=qf.get();return e||(e=jH(),_2(e)),e}const LH=G("defaultLocalStorageUserPrefs",()=>A2());function j2(e={}){return{userPreferences:e.userPreferences??LH,setUserPreferences:e.setUserPreferences??_2}}var O2={exports:{}};(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function s(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function o(l,c,u,h,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new s(u,h||l,p),S=n?n+c:c;return l._events[S]?l._events[S].fn?l._events[S]=[l._events[S],f]:l._events[S].push(f):(l._events[S]=f,l._eventsCount++),l}function i(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],u,h;if(this._eventsCount===0)return c;for(h in u=this._events)t.call(u,h)&&c.push(n?h.slice(1):h);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=n?n+c:c,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var p=0,f=h.length,S=new Array(f);p<f;p++)S[p]=h[p].fn;return S},a.prototype.listenerCount=function(c){var u=n?n+c:c,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,u,h,p,f,S){var y=n?n+c:c;if(!this._events[y])return!1;var x=this._events[y],m=arguments.length,v,w;if(x.fn){switch(x.once&&this.removeListener(c,x.fn,void 0,!0),m){case 1:return x.fn.call(x.context),!0;case 2:return x.fn.call(x.context,u),!0;case 3:return x.fn.call(x.context,u,h),!0;case 4:return x.fn.call(x.context,u,h,p),!0;case 5:return x.fn.call(x.context,u,h,p,f),!0;case 6:return x.fn.call(x.context,u,h,p,f,S),!0}for(w=1,v=new Array(m-1);w<m;w++)v[w-1]=arguments[w];x.fn.apply(x.context,v)}else{var C=x.length,E;for(w=0;w<C;w++)switch(x[w].once&&this.removeListener(c,x[w].fn,void 0,!0),m){case 1:x[w].fn.call(x[w].context);break;case 2:x[w].fn.call(x[w].context,u);break;case 3:x[w].fn.call(x[w].context,u,h);break;case 4:x[w].fn.call(x[w].context,u,h,p);break;default:if(!v)for(E=1,v=new Array(m-1);E<m;E++)v[E-1]=arguments[E];x[w].fn.apply(x[w].context,v)}}return!0},a.prototype.on=function(c,u,h){return o(this,c,u,h,!1)},a.prototype.once=function(c,u,h){return o(this,c,u,h,!0)},a.prototype.removeListener=function(c,u,h,p){var f=n?n+c:c;if(!this._events[f])return this;if(!u)return i(this,f),this;var S=this._events[f];if(S.fn)S.fn===u&&(!p||S.once)&&(!h||S.context===h)&&i(this,f);else{for(var y=0,x=[],m=S.length;y<m;y++)(S[y].fn!==u||p&&!S[y].once||h&&S[y].context!==h)&&x.push(S[y]);x.length?this._events[f]=x.length===1?x[0]:x:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=n?n+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a})(O2);var $H=O2.exports;const NH=ni($H);var D2={exports:{}},hr={},R2={exports:{}},L2={};/**
|
|
63
|
-
* @license React
|
|
64
|
-
* scheduler.production.min.js
|
|
65
|
-
*
|
|
66
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
67
|
-
*
|
|
68
|
-
* This source code is licensed under the MIT license found in the
|
|
69
|
-
* LICENSE file in the root directory of this source tree.
|
|
70
|
-
*/(function(e){function t(z,W){var Y=z.length;z.push(W);e:for(;0<Y;){var q=Y-1>>>1,le=z[q];if(0<s(le,W))z[q]=W,z[Y]=le,Y=q;else break e}}function n(z){return z.length===0?null:z[0]}function r(z){if(z.length===0)return null;var W=z[0],Y=z.pop();if(Y!==W){z[0]=Y;e:for(var q=0,le=z.length,ge=le>>>1;q<ge;){var be=2*(q+1)-1,J=z[be],Ue=be+1,Oe=z[Ue];if(0>s(J,Y))Ue<le&&0>s(Oe,J)?(z[q]=Oe,z[Ue]=Y,q=Ue):(z[q]=J,z[be]=Y,q=be);else if(Ue<le&&0>s(Oe,Y))z[q]=Oe,z[Ue]=Y,q=Ue;else break e}}return W}function s(z,W){var Y=z.sortIndex-W.sortIndex;return Y!==0?Y:z.id-W.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;e.unstable_now=function(){return o.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,h=null,p=3,f=!1,S=!1,y=!1,x=typeof setTimeout=="function"?setTimeout:null,m=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function w(z){for(var W=n(c);W!==null;){if(W.callback===null)r(c);else if(W.startTime<=z)r(c),W.sortIndex=W.expirationTime,t(l,W);else break;W=n(c)}}function C(z){if(y=!1,w(z),!S)if(n(l)!==null)S=!0,H(E);else{var W=n(c);W!==null&&B(C,W.startTime-z)}}function E(z,W){S=!1,y&&(y=!1,m(k),k=-1),f=!0;var Y=p;try{for(w(W),h=n(l);h!==null&&(!(h.expirationTime>W)||z&&!D());){var q=h.callback;if(typeof q=="function"){h.callback=null,p=h.priorityLevel;var le=q(h.expirationTime<=W);W=e.unstable_now(),typeof le=="function"?h.callback=le:h===n(l)&&r(l),w(W)}else r(l);h=n(l)}if(h!==null)var ge=!0;else{var be=n(c);be!==null&&B(C,be.startTime-W),ge=!1}return ge}finally{h=null,p=Y,f=!1}}var _=!1,I=null,k=-1,T=5,M=-1;function D(){return!(e.unstable_now()-M<T)}function $(){if(I!==null){var z=e.unstable_now();M=z;var W=!0;try{W=I(!0,z)}finally{W?j():(_=!1,I=null)}}else _=!1}var j;if(typeof v=="function")j=function(){v($)};else if(typeof MessageChannel<"u"){var O=new MessageChannel,R=O.port2;O.port1.onmessage=$,j=function(){R.postMessage(null)}}else j=function(){x($,0)};function H(z){I=z,_||(_=!0,j())}function B(z,W){k=x(function(){z(e.unstable_now())},W)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(z){z.callback=null},e.unstable_continueExecution=function(){S||f||(S=!0,H(E))},e.unstable_forceFrameRate=function(z){0>z||125<z?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):T=0<z?Math.floor(1e3/z):5},e.unstable_getCurrentPriorityLevel=function(){return p},e.unstable_getFirstCallbackNode=function(){return n(l)},e.unstable_next=function(z){switch(p){case 1:case 2:case 3:var W=3;break;default:W=p}var Y=p;p=W;try{return z()}finally{p=Y}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(z,W){switch(z){case 1:case 2:case 3:case 4:case 5:break;default:z=3}var Y=p;p=z;try{return W()}finally{p=Y}},e.unstable_scheduleCallback=function(z,W,Y){var q=e.unstable_now();switch(typeof Y=="object"&&Y!==null?(Y=Y.delay,Y=typeof Y=="number"&&0<Y?q+Y:q):Y=q,z){case 1:var le=-1;break;case 2:le=250;break;case 5:le=1073741823;break;case 4:le=1e4;break;default:le=5e3}return le=Y+le,z={id:u++,callback:W,priorityLevel:z,startTime:Y,expirationTime:le,sortIndex:-1},Y>q?(z.sortIndex=Y,t(c,z),n(l)===null&&z===n(c)&&(y?(m(k),k=-1):y=!0,B(C,Y-q))):(z.sortIndex=le,t(l,z),S||f||(S=!0,H(E))),z},e.unstable_shouldYield=D,e.unstable_wrapCallback=function(z){var W=p;return function(){var Y=p;p=W;try{return z.apply(this,arguments)}finally{p=Y}}}})(L2);R2.exports=L2;var FH=R2.exports;/**
|
|
71
|
-
* @license React
|
|
72
|
-
* react-dom.production.min.js
|
|
73
|
-
*
|
|
74
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
75
|
-
*
|
|
76
|
-
* This source code is licensed under the MIT license found in the
|
|
77
|
-
* LICENSE file in the root directory of this source tree.
|
|
78
|
-
*/var zH=P,ur=FH;function X(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n<arguments.length;n++)t+="&args[]="+encodeURIComponent(arguments[n]);return"Minified React error #"+e+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var $2=new Set,lu={};function sa(e,t){ll(e,t),ll(e+"Capture",t)}function ll(e,t){for(lu[e]=t,e=0;e<t.length;e++)$2.add(t[e])}var Js=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),OS=Object.prototype.hasOwnProperty,BH=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,MP={},AP={};function UH(e){return OS.call(AP,e)?!0:OS.call(MP,e)?!1:BH.test(e)?AP[e]=!0:(MP[e]=!0,!1)}function HH(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function KH(e,t,n,r){if(t===null||typeof t>"u"||HH(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function Cn(e,t,n,r,s,o,i){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=s,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=o,this.removeEmptyString=i}var Yt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Yt[e]=new Cn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Yt[t]=new Cn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Yt[e]=new Cn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Yt[e]=new Cn(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){Yt[e]=new Cn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Yt[e]=new Cn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Yt[e]=new Cn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Yt[e]=new Cn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Yt[e]=new Cn(e,5,!1,e.toLowerCase(),null,!1,!1)});var c0=/[\-:]([a-z])/g;function u0(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(c0,u0);Yt[t]=new Cn(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(c0,u0);Yt[t]=new Cn(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(c0,u0);Yt[t]=new Cn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Yt[e]=new Cn(e,1,!1,e.toLowerCase(),null,!1,!1)});Yt.xlinkHref=new Cn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Yt[e]=new Cn(e,1,!1,e.toLowerCase(),null,!0,!0)});function d0(e,t,n,r){var s=Yt.hasOwnProperty(t)?Yt[t]:null;(s!==null?s.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(KH(t,n,s,r)&&(n=null),r||s===null?UH(t)&&(n===null?e.removeAttribute(t):e.setAttribute(t,""+n)):s.mustUseProperty?e[s.propertyName]=n===null?s.type===3?!1:"":n:(t=s.attributeName,r=s.attributeNamespace,n===null?e.removeAttribute(t):(s=s.type,n=s===3||s===4&&n===!0?"":""+n,r?e.setAttributeNS(r,t,n):e.setAttribute(t,n))))}var co=zH.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Dd=Symbol.for("react.element"),Ma=Symbol.for("react.portal"),Aa=Symbol.for("react.fragment"),h0=Symbol.for("react.strict_mode"),DS=Symbol.for("react.profiler"),N2=Symbol.for("react.provider"),F2=Symbol.for("react.context"),p0=Symbol.for("react.forward_ref"),RS=Symbol.for("react.suspense"),LS=Symbol.for("react.suspense_list"),f0=Symbol.for("react.memo"),Io=Symbol.for("react.lazy"),z2=Symbol.for("react.offscreen"),jP=Symbol.iterator;function Jl(e){return e===null||typeof e!="object"?null:(e=jP&&e[jP]||e["@@iterator"],typeof e=="function"?e:null)}var pt=Object.assign,Om;function vc(e){if(Om===void 0)try{throw Error()}catch(n){var t=n.stack.trim().match(/\n( *(at )?)/);Om=t&&t[1]||""}return`
|
|
79
|
-
`+Om+e}var Dm=!1;function Rm(e,t){if(!e||Dm)return"";Dm=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(t)if(t=function(){throw Error()},Object.defineProperty(t.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(t,[])}catch(c){var r=c}Reflect.construct(e,[],t)}else{try{t.call()}catch(c){r=c}e.call(t.prototype)}else{try{throw Error()}catch(c){r=c}e()}}catch(c){if(c&&r&&typeof c.stack=="string"){for(var s=c.stack.split(`
|
|
80
|
-
`),o=r.stack.split(`
|
|
81
|
-
`),i=s.length-1,a=o.length-1;1<=i&&0<=a&&s[i]!==o[a];)a--;for(;1<=i&&0<=a;i--,a--)if(s[i]!==o[a]){if(i!==1||a!==1)do if(i--,a--,0>a||s[i]!==o[a]){var l=`
|
|
82
|
-
`+s[i].replace(" at new "," at ");return e.displayName&&l.includes("<anonymous>")&&(l=l.replace("<anonymous>",e.displayName)),l}while(1<=i&&0<=a);break}}}finally{Dm=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?vc(e):""}function WH(e){switch(e.tag){case 5:return vc(e.type);case 16:return vc("Lazy");case 13:return vc("Suspense");case 19:return vc("SuspenseList");case 0:case 2:case 15:return e=Rm(e.type,!1),e;case 11:return e=Rm(e.type.render,!1),e;case 1:return e=Rm(e.type,!0),e;default:return""}}function $S(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Aa:return"Fragment";case Ma:return"Portal";case DS:return"Profiler";case h0:return"StrictMode";case RS:return"Suspense";case LS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case F2:return(e.displayName||"Context")+".Consumer";case N2:return(e._context.displayName||"Context")+".Provider";case p0:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case f0:return t=e.displayName||null,t!==null?t:$S(e.type)||"Memo";case Io:t=e._payload,e=e._init;try{return $S(e(t))}catch{}}return null}function GH(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return $S(t);case 8:return t===h0?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Xo(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function B2(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function VH(e){var t=B2(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var s=n.get,o=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return s.call(this)},set:function(i){r=""+i,o.call(this,i)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(i){r=""+i},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Rd(e){e._valueTracker||(e._valueTracker=VH(e))}function U2(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=B2(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Kp(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function NS(e,t){var n=t.checked;return pt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function OP(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Xo(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function H2(e,t){t=t.checked,t!=null&&d0(e,"checked",t,!1)}function FS(e,t){H2(e,t);var n=Xo(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?zS(e,t.type,n):t.hasOwnProperty("defaultValue")&&zS(e,t.type,Xo(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function DP(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function zS(e,t,n){(t!=="number"||Kp(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var xc=Array.isArray;function Xa(e,t,n,r){if(e=e.options,t){t={};for(var s=0;s<n.length;s++)t["$"+n[s]]=!0;for(n=0;n<e.length;n++)s=t.hasOwnProperty("$"+e[n].value),e[n].selected!==s&&(e[n].selected=s),s&&r&&(e[n].defaultSelected=!0)}else{for(n=""+Xo(n),t=null,s=0;s<e.length;s++){if(e[s].value===n){e[s].selected=!0,r&&(e[s].defaultSelected=!0);return}t!==null||e[s].disabled||(t=e[s])}t!==null&&(t.selected=!0)}}function BS(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(X(91));return pt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function RP(e,t){var n=t.value;if(n==null){if(n=t.children,t=t.defaultValue,n!=null){if(t!=null)throw Error(X(92));if(xc(n)){if(1<n.length)throw Error(X(93));n=n[0]}t=n}t==null&&(t=""),n=t}e._wrapperState={initialValue:Xo(n)}}function K2(e,t){var n=Xo(t.value),r=Xo(t.defaultValue);n!=null&&(n=""+n,n!==e.value&&(e.value=n),t.defaultValue==null&&e.defaultValue!==n&&(e.defaultValue=n)),r!=null&&(e.defaultValue=""+r)}function LP(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function W2(e){switch(e){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function US(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?W2(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var Ld,G2=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(t,n,r,s){MSApp.execUnsafeLocalFunction(function(){return e(t,n,r,s)})}:e}(function(e,t){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=t;else{for(Ld=Ld||document.createElement("div"),Ld.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=Ld.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function cu(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Bc={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},YH=["Webkit","ms","Moz","O"];Object.keys(Bc).forEach(function(e){YH.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Bc[t]=Bc[e]})});function V2(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Bc.hasOwnProperty(e)&&Bc[e]?(""+t).trim():t+"px"}function Y2(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,s=V2(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,s):e[n]=s}}var XH=pt({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function HS(e,t){if(t){if(XH[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(X(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(X(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(X(61))}if(t.style!=null&&typeof t.style!="object")throw Error(X(62))}}function KS(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var WS=null;function g0(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var GS=null,qa=null,Za=null;function $P(e){if(e=Zu(e)){if(typeof GS!="function")throw Error(X(280));var t=e.stateNode;t&&(t=tg(t),GS(e.stateNode,e.type,t))}}function X2(e){qa?Za?Za.push(e):Za=[e]:qa=e}function q2(){if(qa){var e=qa,t=Za;if(Za=qa=null,$P(e),t)for(e=0;e<t.length;e++)$P(t[e])}}function Z2(e,t){return e(t)}function Q2(){}var Lm=!1;function J2(e,t,n){if(Lm)return e(t,n);Lm=!0;try{return Z2(e,t,n)}finally{Lm=!1,(qa!==null||Za!==null)&&(Q2(),q2())}}function uu(e,t){var n=e.stateNode;if(n===null)return null;var r=tg(n);if(r===null)return null;n=r[t];e:switch(t){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(e=e.type,r=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!r;break e;default:e=!1}if(e)return null;if(n&&typeof n!="function")throw Error(X(231,t,typeof n));return n}var VS=!1;if(Js)try{var ec={};Object.defineProperty(ec,"passive",{get:function(){VS=!0}}),window.addEventListener("test",ec,ec),window.removeEventListener("test",ec,ec)}catch{VS=!1}function qH(e,t,n,r,s,o,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{t.apply(n,c)}catch(u){this.onError(u)}}var Uc=!1,Wp=null,Gp=!1,YS=null,ZH={onError:function(e){Uc=!0,Wp=e}};function QH(e,t,n,r,s,o,i,a,l){Uc=!1,Wp=null,qH.apply(ZH,arguments)}function JH(e,t,n,r,s,o,i,a,l){if(QH.apply(this,arguments),Uc){if(Uc){var c=Wp;Uc=!1,Wp=null}else throw Error(X(198));Gp||(Gp=!0,YS=c)}}function oa(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function eT(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function NP(e){if(oa(e)!==e)throw Error(X(188))}function eK(e){var t=e.alternate;if(!t){if(t=oa(e),t===null)throw Error(X(188));return t!==e?null:e}for(var n=e,r=t;;){var s=n.return;if(s===null)break;var o=s.alternate;if(o===null){if(r=s.return,r!==null){n=r;continue}break}if(s.child===o.child){for(o=s.child;o;){if(o===n)return NP(s),e;if(o===r)return NP(s),t;o=o.sibling}throw Error(X(188))}if(n.return!==r.return)n=s,r=o;else{for(var i=!1,a=s.child;a;){if(a===n){i=!0,n=s,r=o;break}if(a===r){i=!0,r=s,n=o;break}a=a.sibling}if(!i){for(a=o.child;a;){if(a===n){i=!0,n=o,r=s;break}if(a===r){i=!0,r=o,n=s;break}a=a.sibling}if(!i)throw Error(X(189))}}if(n.alternate!==r)throw Error(X(190))}if(n.tag!==3)throw Error(X(188));return n.stateNode.current===n?e:t}function tT(e){return e=eK(e),e!==null?nT(e):null}function nT(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=nT(e);if(t!==null)return t;e=e.sibling}return null}var rT=ur.unstable_scheduleCallback,FP=ur.unstable_cancelCallback,tK=ur.unstable_shouldYield,nK=ur.unstable_requestPaint,wt=ur.unstable_now,rK=ur.unstable_getCurrentPriorityLevel,m0=ur.unstable_ImmediatePriority,sT=ur.unstable_UserBlockingPriority,Vp=ur.unstable_NormalPriority,sK=ur.unstable_LowPriority,oT=ur.unstable_IdlePriority,Zf=null,ys=null;function oK(e){if(ys&&typeof ys.onCommitFiberRoot=="function")try{ys.onCommitFiberRoot(Zf,e,void 0,(e.current.flags&128)===128)}catch{}}var Hr=Math.clz32?Math.clz32:lK,iK=Math.log,aK=Math.LN2;function lK(e){return e>>>=0,e===0?32:31-(iK(e)/aK|0)|0}var $d=64,Nd=4194304;function wc(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Yp(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,s=e.suspendedLanes,o=e.pingedLanes,i=n&268435455;if(i!==0){var a=i&~s;a!==0?r=wc(a):(o&=i,o!==0&&(r=wc(o)))}else i=n&~s,i!==0?r=wc(i):o!==0&&(r=wc(o));if(r===0)return 0;if(t!==0&&t!==r&&!(t&s)&&(s=r&-r,o=t&-t,s>=o||s===16&&(o&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0<t;)n=31-Hr(t),s=1<<n,r|=e[n],t&=~s;return r}function cK(e,t){switch(e){case 1:case 2:case 4:return t+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function uK(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,s=e.expirationTimes,o=e.pendingLanes;0<o;){var i=31-Hr(o),a=1<<i,l=s[i];l===-1?(!(a&n)||a&r)&&(s[i]=cK(a,t)):l<=t&&(e.expiredLanes|=a),o&=~a}}function XS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function iT(){var e=$d;return $d<<=1,!($d&4194240)&&($d=64),e}function $m(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function Xu(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Hr(t),e[t]=n}function dK(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<n;){var s=31-Hr(n),o=1<<s;t[s]=0,r[s]=-1,e[s]=-1,n&=~o}}function y0(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-Hr(n),s=1<<r;s&t|e[r]&t&&(e[r]|=t),n&=~s}}var Ne=0;function aT(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var lT,S0,cT,uT,dT,qS=!1,Fd=[],Fo=null,zo=null,Bo=null,du=new Map,hu=new Map,_o=[],hK="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function zP(e,t){switch(e){case"focusin":case"focusout":Fo=null;break;case"dragenter":case"dragleave":zo=null;break;case"mouseover":case"mouseout":Bo=null;break;case"pointerover":case"pointerout":du.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":hu.delete(t.pointerId)}}function tc(e,t,n,r,s,o){return e===null||e.nativeEvent!==o?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:o,targetContainers:[s]},t!==null&&(t=Zu(t),t!==null&&S0(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,s!==null&&t.indexOf(s)===-1&&t.push(s),e)}function pK(e,t,n,r,s){switch(t){case"focusin":return Fo=tc(Fo,e,t,n,r,s),!0;case"dragenter":return zo=tc(zo,e,t,n,r,s),!0;case"mouseover":return Bo=tc(Bo,e,t,n,r,s),!0;case"pointerover":var o=s.pointerId;return du.set(o,tc(du.get(o)||null,e,t,n,r,s)),!0;case"gotpointercapture":return o=s.pointerId,hu.set(o,tc(hu.get(o)||null,e,t,n,r,s)),!0}return!1}function hT(e){var t=Ei(e.target);if(t!==null){var n=oa(t);if(n!==null){if(t=n.tag,t===13){if(t=eT(n),t!==null){e.blockedOn=t,dT(e.priority,function(){cT(n)});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Oh(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=ZS(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);WS=r,n.target.dispatchEvent(r),WS=null}else return t=Zu(n),t!==null&&S0(t),e.blockedOn=n,!1;t.shift()}return!0}function BP(e,t,n){Oh(e)&&n.delete(t)}function fK(){qS=!1,Fo!==null&&Oh(Fo)&&(Fo=null),zo!==null&&Oh(zo)&&(zo=null),Bo!==null&&Oh(Bo)&&(Bo=null),du.forEach(BP),hu.forEach(BP)}function nc(e,t){e.blockedOn===t&&(e.blockedOn=null,qS||(qS=!0,ur.unstable_scheduleCallback(ur.unstable_NormalPriority,fK)))}function pu(e){function t(s){return nc(s,e)}if(0<Fd.length){nc(Fd[0],e);for(var n=1;n<Fd.length;n++){var r=Fd[n];r.blockedOn===e&&(r.blockedOn=null)}}for(Fo!==null&&nc(Fo,e),zo!==null&&nc(zo,e),Bo!==null&&nc(Bo,e),du.forEach(t),hu.forEach(t),n=0;n<_o.length;n++)r=_o[n],r.blockedOn===e&&(r.blockedOn=null);for(;0<_o.length&&(n=_o[0],n.blockedOn===null);)hT(n),n.blockedOn===null&&_o.shift()}var Qa=co.ReactCurrentBatchConfig,Xp=!0;function gK(e,t,n,r){var s=Ne,o=Qa.transition;Qa.transition=null;try{Ne=1,v0(e,t,n,r)}finally{Ne=s,Qa.transition=o}}function mK(e,t,n,r){var s=Ne,o=Qa.transition;Qa.transition=null;try{Ne=4,v0(e,t,n,r)}finally{Ne=s,Qa.transition=o}}function v0(e,t,n,r){if(Xp){var s=ZS(e,t,n,r);if(s===null)Vm(e,t,r,qp,n),zP(e,r);else if(pK(s,e,t,n,r))r.stopPropagation();else if(zP(e,r),t&4&&-1<hK.indexOf(e)){for(;s!==null;){var o=Zu(s);if(o!==null&&lT(o),o=ZS(e,t,n,r),o===null&&Vm(e,t,r,qp,n),o===s)break;s=o}s!==null&&r.stopPropagation()}else Vm(e,t,r,null,n)}}var qp=null;function ZS(e,t,n,r){if(qp=null,e=g0(r),e=Ei(e),e!==null)if(t=oa(e),t===null)e=null;else if(n=t.tag,n===13){if(e=eT(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null);return qp=e,null}function pT(e){switch(e){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(rK()){case m0:return 1;case sT:return 4;case Vp:case sK:return 16;case oT:return 536870912;default:return 16}default:return 16}}var Ao=null,x0=null,Dh=null;function fT(){if(Dh)return Dh;var e,t=x0,n=t.length,r,s="value"in Ao?Ao.value:Ao.textContent,o=s.length;for(e=0;e<n&&t[e]===s[e];e++);var i=n-e;for(r=1;r<=i&&t[n-r]===s[o-r];r++);return Dh=s.slice(e,1<r?1-r:void 0)}function Rh(e){var t=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function zd(){return!0}function UP(){return!1}function pr(e){function t(n,r,s,o,i){this._reactName=n,this._targetInst=s,this.type=r,this.nativeEvent=o,this.target=i,this.currentTarget=null;for(var a in e)e.hasOwnProperty(a)&&(n=e[a],this[a]=n?n(o):o[a]);return this.isDefaultPrevented=(o.defaultPrevented!=null?o.defaultPrevented:o.returnValue===!1)?zd:UP,this.isPropagationStopped=UP,this}return pt(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var n=this.nativeEvent;n&&(n.preventDefault?n.preventDefault():typeof n.returnValue!="unknown"&&(n.returnValue=!1),this.isDefaultPrevented=zd)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=zd)},persist:function(){},isPersistent:zd}),t}var Al={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},w0=pr(Al),qu=pt({},Al,{view:0,detail:0}),yK=pr(qu),Nm,Fm,rc,Qf=pt({},qu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:b0,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return"movementX"in e?e.movementX:(e!==rc&&(rc&&e.type==="mousemove"?(Nm=e.screenX-rc.screenX,Fm=e.screenY-rc.screenY):Fm=Nm=0,rc=e),Nm)},movementY:function(e){return"movementY"in e?e.movementY:Fm}}),HP=pr(Qf),SK=pt({},Qf,{dataTransfer:0}),vK=pr(SK),xK=pt({},qu,{relatedTarget:0}),zm=pr(xK),wK=pt({},Al,{animationName:0,elapsedTime:0,pseudoElement:0}),bK=pr(wK),PK=pt({},Al,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),CK=pr(PK),IK=pt({},Al,{data:0}),KP=pr(IK),EK={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},kK={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},_K={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function TK(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=_K[e])?!!t[e]:!1}function b0(){return TK}var MK=pt({},qu,{key:function(e){if(e.key){var t=EK[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=Rh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?kK[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:b0,charCode:function(e){return e.type==="keypress"?Rh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Rh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),AK=pr(MK),jK=pt({},Qf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),WP=pr(jK),OK=pt({},qu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:b0}),DK=pr(OK),RK=pt({},Al,{propertyName:0,elapsedTime:0,pseudoElement:0}),LK=pr(RK),$K=pt({},Qf,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),NK=pr($K),FK=[9,13,27,32],P0=Js&&"CompositionEvent"in window,Hc=null;Js&&"documentMode"in document&&(Hc=document.documentMode);var zK=Js&&"TextEvent"in window&&!Hc,gT=Js&&(!P0||Hc&&8<Hc&&11>=Hc),GP=" ",VP=!1;function mT(e,t){switch(e){case"keyup":return FK.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function yT(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ja=!1;function BK(e,t){switch(e){case"compositionend":return yT(t);case"keypress":return t.which!==32?null:(VP=!0,GP);case"textInput":return e=t.data,e===GP&&VP?null:e;default:return null}}function UK(e,t){if(ja)return e==="compositionend"||!P0&&mT(e,t)?(e=fT(),Dh=x0=Ao=null,ja=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case"compositionend":return gT&&t.locale!=="ko"?null:t.data;default:return null}}var HK={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function YP(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!HK[e.type]:t==="textarea"}function ST(e,t,n,r){X2(r),t=Zp(t,"onChange"),0<t.length&&(n=new w0("onChange","change",null,n,r),e.push({event:n,listeners:t}))}var Kc=null,fu=null;function KK(e){TT(e,0)}function Jf(e){var t=Ra(e);if(U2(t))return e}function WK(e,t){if(e==="change")return t}var vT=!1;if(Js){var Bm;if(Js){var Um="oninput"in document;if(!Um){var XP=document.createElement("div");XP.setAttribute("oninput","return;"),Um=typeof XP.oninput=="function"}Bm=Um}else Bm=!1;vT=Bm&&(!document.documentMode||9<document.documentMode)}function qP(){Kc&&(Kc.detachEvent("onpropertychange",xT),fu=Kc=null)}function xT(e){if(e.propertyName==="value"&&Jf(fu)){var t=[];ST(t,fu,e,g0(e)),J2(KK,t)}}function GK(e,t,n){e==="focusin"?(qP(),Kc=t,fu=n,Kc.attachEvent("onpropertychange",xT)):e==="focusout"&&qP()}function VK(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Jf(fu)}function YK(e,t){if(e==="click")return Jf(t)}function XK(e,t){if(e==="input"||e==="change")return Jf(t)}function qK(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Vr=typeof Object.is=="function"?Object.is:qK;function gu(e,t){if(Vr(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var s=n[r];if(!OS.call(t,s)||!Vr(e[s],t[s]))return!1}return!0}function ZP(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function QP(e,t){var n=ZP(e);e=0;for(var r;n;){if(n.nodeType===3){if(r=e+n.textContent.length,e<=t&&r>=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=ZP(n)}}function wT(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?wT(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function bT(){for(var e=window,t=Kp();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Kp(e.document)}return t}function C0(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function ZK(e){var t=bT(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&wT(n.ownerDocument.documentElement,n)){if(r!==null&&C0(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var s=n.textContent.length,o=Math.min(r.start,s);r=r.end===void 0?o:Math.min(r.end,s),!e.extend&&o>r&&(s=r,r=o,o=s),s=QP(n,o);var i=QP(n,r);s&&i&&(e.rangeCount!==1||e.anchorNode!==s.node||e.anchorOffset!==s.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(t=t.createRange(),t.setStart(s.node,s.offset),e.removeAllRanges(),o>r?(e.addRange(t),e.extend(i.node,i.offset)):(t.setEnd(i.node,i.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n<t.length;n++)e=t[n],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var QK=Js&&"documentMode"in document&&11>=document.documentMode,Oa=null,QS=null,Wc=null,JS=!1;function JP(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;JS||Oa==null||Oa!==Kp(r)||(r=Oa,"selectionStart"in r&&C0(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Wc&&gu(Wc,r)||(Wc=r,r=Zp(QS,"onSelect"),0<r.length&&(t=new w0("onSelect","select",null,t,n),e.push({event:t,listeners:r}),t.target=Oa)))}function Bd(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n["Webkit"+e]="webkit"+t,n["Moz"+e]="moz"+t,n}var Da={animationend:Bd("Animation","AnimationEnd"),animationiteration:Bd("Animation","AnimationIteration"),animationstart:Bd("Animation","AnimationStart"),transitionend:Bd("Transition","TransitionEnd")},Hm={},PT={};Js&&(PT=document.createElement("div").style,"AnimationEvent"in window||(delete Da.animationend.animation,delete Da.animationiteration.animation,delete Da.animationstart.animation),"TransitionEvent"in window||delete Da.transitionend.transition);function eg(e){if(Hm[e])return Hm[e];if(!Da[e])return e;var t=Da[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in PT)return Hm[e]=t[n];return e}var CT=eg("animationend"),IT=eg("animationiteration"),ET=eg("animationstart"),kT=eg("transitionend"),_T=new Map,eC="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function ai(e,t){_T.set(e,t),sa(t,[e])}for(var Km=0;Km<eC.length;Km++){var Wm=eC[Km],JK=Wm.toLowerCase(),eW=Wm[0].toUpperCase()+Wm.slice(1);ai(JK,"on"+eW)}ai(CT,"onAnimationEnd");ai(IT,"onAnimationIteration");ai(ET,"onAnimationStart");ai("dblclick","onDoubleClick");ai("focusin","onFocus");ai("focusout","onBlur");ai(kT,"onTransitionEnd");ll("onMouseEnter",["mouseout","mouseover"]);ll("onMouseLeave",["mouseout","mouseover"]);ll("onPointerEnter",["pointerout","pointerover"]);ll("onPointerLeave",["pointerout","pointerover"]);sa("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));sa("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));sa("onBeforeInput",["compositionend","keypress","textInput","paste"]);sa("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var bc="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),tW=new Set("cancel close invalid load scroll toggle".split(" ").concat(bc));function tC(e,t,n){var r=e.type||"unknown-event";e.currentTarget=n,JH(r,t,void 0,e),e.currentTarget=null}function TT(e,t){t=(t&4)!==0;for(var n=0;n<e.length;n++){var r=e[n],s=r.event;r=r.listeners;e:{var o=void 0;if(t)for(var i=r.length-1;0<=i;i--){var a=r[i],l=a.instance,c=a.currentTarget;if(a=a.listener,l!==o&&s.isPropagationStopped())break e;tC(s,a,c),o=l}else for(i=0;i<r.length;i++){if(a=r[i],l=a.instance,c=a.currentTarget,a=a.listener,l!==o&&s.isPropagationStopped())break e;tC(s,a,c),o=l}}}if(Gp)throw e=YS,Gp=!1,YS=null,e}function Je(e,t){var n=t[sv];n===void 0&&(n=t[sv]=new Set);var r=e+"__bubble";n.has(r)||(MT(t,e,2,!1),n.add(r))}function Gm(e,t,n){var r=0;t&&(r|=4),MT(n,e,r,t)}var Ud="_reactListening"+Math.random().toString(36).slice(2);function mu(e){if(!e[Ud]){e[Ud]=!0,$2.forEach(function(n){n!=="selectionchange"&&(tW.has(n)||Gm(n,!1,e),Gm(n,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[Ud]||(t[Ud]=!0,Gm("selectionchange",!1,t))}}function MT(e,t,n,r){switch(pT(t)){case 1:var s=gK;break;case 4:s=mK;break;default:s=v0}n=s.bind(null,t,n,e),s=void 0,!VS||t!=="touchstart"&&t!=="touchmove"&&t!=="wheel"||(s=!0),r?s!==void 0?e.addEventListener(t,n,{capture:!0,passive:s}):e.addEventListener(t,n,!0):s!==void 0?e.addEventListener(t,n,{passive:s}):e.addEventListener(t,n,!1)}function Vm(e,t,n,r,s){var o=r;if(!(t&1)&&!(t&2)&&r!==null)e:for(;;){if(r===null)return;var i=r.tag;if(i===3||i===4){var a=r.stateNode.containerInfo;if(a===s||a.nodeType===8&&a.parentNode===s)break;if(i===4)for(i=r.return;i!==null;){var l=i.tag;if((l===3||l===4)&&(l=i.stateNode.containerInfo,l===s||l.nodeType===8&&l.parentNode===s))return;i=i.return}for(;a!==null;){if(i=Ei(a),i===null)return;if(l=i.tag,l===5||l===6){r=o=i;continue e}a=a.parentNode}}r=r.return}J2(function(){var c=o,u=g0(n),h=[];e:{var p=_T.get(e);if(p!==void 0){var f=w0,S=e;switch(e){case"keypress":if(Rh(n)===0)break e;case"keydown":case"keyup":f=AK;break;case"focusin":S="focus",f=zm;break;case"focusout":S="blur",f=zm;break;case"beforeblur":case"afterblur":f=zm;break;case"click":if(n.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":f=HP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=vK;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=DK;break;case CT:case IT:case ET:f=bK;break;case kT:f=LK;break;case"scroll":f=yK;break;case"wheel":f=NK;break;case"copy":case"cut":case"paste":f=CK;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=WP}var y=(t&4)!==0,x=!y&&e==="scroll",m=y?p!==null?p+"Capture":null:p;y=[];for(var v=c,w;v!==null;){w=v;var C=w.stateNode;if(w.tag===5&&C!==null&&(w=C,m!==null&&(C=uu(v,m),C!=null&&y.push(yu(v,C,w)))),x)break;v=v.return}0<y.length&&(p=new f(p,S,null,n,u),h.push({event:p,listeners:y}))}}if(!(t&7)){e:{if(p=e==="mouseover"||e==="pointerover",f=e==="mouseout"||e==="pointerout",p&&n!==WS&&(S=n.relatedTarget||n.fromElement)&&(Ei(S)||S[eo]))break e;if((f||p)&&(p=u.window===u?u:(p=u.ownerDocument)?p.defaultView||p.parentWindow:window,f?(S=n.relatedTarget||n.toElement,f=c,S=S?Ei(S):null,S!==null&&(x=oa(S),S!==x||S.tag!==5&&S.tag!==6)&&(S=null)):(f=null,S=c),f!==S)){if(y=HP,C="onMouseLeave",m="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(y=WP,C="onPointerLeave",m="onPointerEnter",v="pointer"),x=f==null?p:Ra(f),w=S==null?p:Ra(S),p=new y(C,v+"leave",f,n,u),p.target=x,p.relatedTarget=w,C=null,Ei(u)===c&&(y=new y(m,v+"enter",S,n,u),y.target=w,y.relatedTarget=x,C=y),x=C,f&&S)t:{for(y=f,m=S,v=0,w=y;w;w=ma(w))v++;for(w=0,C=m;C;C=ma(C))w++;for(;0<v-w;)y=ma(y),v--;for(;0<w-v;)m=ma(m),w--;for(;v--;){if(y===m||m!==null&&y===m.alternate)break t;y=ma(y),m=ma(m)}y=null}else y=null;f!==null&&nC(h,p,f,y,!1),S!==null&&x!==null&&nC(h,x,S,y,!0)}}e:{if(p=c?Ra(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var E=WK;else if(YP(p))if(vT)E=XK;else{E=VK;var _=GK}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(E=YK);if(E&&(E=E(e,c))){ST(h,E,n,u);break e}_&&_(e,p,c),e==="focusout"&&(_=p._wrapperState)&&_.controlled&&p.type==="number"&&zS(p,"number",p.value)}switch(_=c?Ra(c):window,e){case"focusin":(YP(_)||_.contentEditable==="true")&&(Oa=_,QS=c,Wc=null);break;case"focusout":Wc=QS=Oa=null;break;case"mousedown":JS=!0;break;case"contextmenu":case"mouseup":case"dragend":JS=!1,JP(h,n,u);break;case"selectionchange":if(QK)break;case"keydown":case"keyup":JP(h,n,u)}var I;if(P0)e:{switch(e){case"compositionstart":var k="onCompositionStart";break e;case"compositionend":k="onCompositionEnd";break e;case"compositionupdate":k="onCompositionUpdate";break e}k=void 0}else ja?mT(e,n)&&(k="onCompositionEnd"):e==="keydown"&&n.keyCode===229&&(k="onCompositionStart");k&&(gT&&n.locale!=="ko"&&(ja||k!=="onCompositionStart"?k==="onCompositionEnd"&&ja&&(I=fT()):(Ao=u,x0="value"in Ao?Ao.value:Ao.textContent,ja=!0)),_=Zp(c,k),0<_.length&&(k=new KP(k,e,null,n,u),h.push({event:k,listeners:_}),I?k.data=I:(I=yT(n),I!==null&&(k.data=I)))),(I=zK?BK(e,n):UK(e,n))&&(c=Zp(c,"onBeforeInput"),0<c.length&&(u=new KP("onBeforeInput","beforeinput",null,n,u),h.push({event:u,listeners:c}),u.data=I))}TT(h,t)})}function yu(e,t,n){return{instance:e,listener:t,currentTarget:n}}function Zp(e,t){for(var n=t+"Capture",r=[];e!==null;){var s=e,o=s.stateNode;s.tag===5&&o!==null&&(s=o,o=uu(e,n),o!=null&&r.unshift(yu(e,o,s)),o=uu(e,t),o!=null&&r.push(yu(e,o,s))),e=e.return}return r}function ma(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function nC(e,t,n,r,s){for(var o=t._reactName,i=[];n!==null&&n!==r;){var a=n,l=a.alternate,c=a.stateNode;if(l!==null&&l===r)break;a.tag===5&&c!==null&&(a=c,s?(l=uu(n,o),l!=null&&i.unshift(yu(n,l,a))):s||(l=uu(n,o),l!=null&&i.push(yu(n,l,a)))),n=n.return}i.length!==0&&e.push({event:t,listeners:i})}var nW=/\r\n?/g,rW=/\u0000|\uFFFD/g;function rC(e){return(typeof e=="string"?e:""+e).replace(nW,`
|
|
83
|
-
`).replace(rW,"")}function Hd(e,t,n){if(t=rC(t),rC(e)!==t&&n)throw Error(X(425))}function Qp(){}var ev=null,tv=null;function nv(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var rv=typeof setTimeout=="function"?setTimeout:void 0,sW=typeof clearTimeout=="function"?clearTimeout:void 0,sC=typeof Promise=="function"?Promise:void 0,oW=typeof queueMicrotask=="function"?queueMicrotask:typeof sC<"u"?function(e){return sC.resolve(null).then(e).catch(iW)}:rv;function iW(e){setTimeout(function(){throw e})}function Ym(e,t){var n=t,r=0;do{var s=n.nextSibling;if(e.removeChild(n),s&&s.nodeType===8)if(n=s.data,n==="/$"){if(r===0){e.removeChild(s),pu(t);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=s}while(n);pu(t)}function Uo(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?")break;if(t==="/$")return null}}return e}function oC(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n==="$"||n==="$!"||n==="$?"){if(t===0)return e;t--}else n==="/$"&&t++}e=e.previousSibling}return null}var jl=Math.random().toString(36).slice(2),cs="__reactFiber$"+jl,Su="__reactProps$"+jl,eo="__reactContainer$"+jl,sv="__reactEvents$"+jl,aW="__reactListeners$"+jl,lW="__reactHandles$"+jl;function Ei(e){var t=e[cs];if(t)return t;for(var n=e.parentNode;n;){if(t=n[eo]||n[cs]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=oC(e);e!==null;){if(n=e[cs])return n;e=oC(e)}return t}e=n,n=e.parentNode}return null}function Zu(e){return e=e[cs]||e[eo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Ra(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(X(33))}function tg(e){return e[Su]||null}var ov=[],La=-1;function li(e){return{current:e}}function tt(e){0>La||(e.current=ov[La],ov[La]=null,La--)}function Ye(e,t){La++,ov[La]=e.current,e.current=t}var qo={},hn=li(qo),Hn=li(!1),Bi=qo;function cl(e,t){var n=e.type.contextTypes;if(!n)return qo;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var s={},o;for(o in n)s[o]=t[o];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=s),s}function Kn(e){return e=e.childContextTypes,e!=null}function Jp(){tt(Hn),tt(hn)}function iC(e,t,n){if(hn.current!==qo)throw Error(X(168));Ye(hn,t),Ye(Hn,n)}function AT(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var s in r)if(!(s in t))throw Error(X(108,GH(e)||"Unknown",s));return pt({},n,r)}function ef(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||qo,Bi=hn.current,Ye(hn,e),Ye(Hn,Hn.current),!0}function aC(e,t,n){var r=e.stateNode;if(!r)throw Error(X(169));n?(e=AT(e,t,Bi),r.__reactInternalMemoizedMergedChildContext=e,tt(Hn),tt(hn),Ye(hn,e)):tt(Hn),Ye(Hn,n)}var zs=null,ng=!1,Xm=!1;function jT(e){zs===null?zs=[e]:zs.push(e)}function cW(e){ng=!0,jT(e)}function ci(){if(!Xm&&zs!==null){Xm=!0;var e=0,t=Ne;try{var n=zs;for(Ne=1;e<n.length;e++){var r=n[e];do r=r(!0);while(r!==null)}zs=null,ng=!1}catch(s){throw zs!==null&&(zs=zs.slice(e+1)),rT(m0,ci),s}finally{Ne=t,Xm=!1}}return null}var $a=[],Na=0,tf=null,nf=0,br=[],Pr=0,Ui=null,Us=1,Hs="";function bi(e,t){$a[Na++]=nf,$a[Na++]=tf,tf=e,nf=t}function OT(e,t,n){br[Pr++]=Us,br[Pr++]=Hs,br[Pr++]=Ui,Ui=e;var r=Us;e=Hs;var s=32-Hr(r)-1;r&=~(1<<s),n+=1;var o=32-Hr(t)+s;if(30<o){var i=s-s%5;o=(r&(1<<i)-1).toString(32),r>>=i,s-=i,Us=1<<32-Hr(t)+s|n<<s|r,Hs=o+e}else Us=1<<o|n<<s|r,Hs=e}function I0(e){e.return!==null&&(bi(e,1),OT(e,1,0))}function E0(e){for(;e===tf;)tf=$a[--Na],$a[Na]=null,nf=$a[--Na],$a[Na]=null;for(;e===Ui;)Ui=br[--Pr],br[Pr]=null,Hs=br[--Pr],br[Pr]=null,Us=br[--Pr],br[Pr]=null}var ir=null,nr=null,st=!1,Fr=null;function DT(e,t){var n=Cr(5,null,null,0);n.elementType="DELETED",n.stateNode=t,n.return=e,t=e.deletions,t===null?(e.deletions=[n],e.flags|=16):t.push(n)}function lC(e,t){switch(e.tag){case 5:var n=e.type;return t=t.nodeType!==1||n.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null?(e.stateNode=t,ir=e,nr=Uo(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,ir=e,nr=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(n=Ui!==null?{id:Us,overflow:Hs}:null,e.memoizedState={dehydrated:t,treeContext:n,retryLane:1073741824},n=Cr(18,null,null,0),n.stateNode=t,n.return=e,e.child=n,ir=e,nr=null,!0):!1;default:return!1}}function iv(e){return(e.mode&1)!==0&&(e.flags&128)===0}function av(e){if(st){var t=nr;if(t){var n=t;if(!lC(e,t)){if(iv(e))throw Error(X(418));t=Uo(n.nextSibling);var r=ir;t&&lC(e,t)?DT(r,n):(e.flags=e.flags&-4097|2,st=!1,ir=e)}}else{if(iv(e))throw Error(X(418));e.flags=e.flags&-4097|2,st=!1,ir=e}}}function cC(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;ir=e}function Kd(e){if(e!==ir)return!1;if(!st)return cC(e),st=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!nv(e.type,e.memoizedProps)),t&&(t=nr)){if(iv(e))throw RT(),Error(X(418));for(;t;)DT(e,t),t=Uo(t.nextSibling)}if(cC(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(X(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var n=e.data;if(n==="/$"){if(t===0){nr=Uo(e.nextSibling);break e}t--}else n!=="$"&&n!=="$!"&&n!=="$?"||t++}e=e.nextSibling}nr=null}}else nr=ir?Uo(e.stateNode.nextSibling):null;return!0}function RT(){for(var e=nr;e;)e=Uo(e.nextSibling)}function ul(){nr=ir=null,st=!1}function k0(e){Fr===null?Fr=[e]:Fr.push(e)}var uW=co.ReactCurrentBatchConfig;function sc(e,t,n){if(e=n.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(n._owner){if(n=n._owner,n){if(n.tag!==1)throw Error(X(309));var r=n.stateNode}if(!r)throw Error(X(147,e));var s=r,o=""+e;return t!==null&&t.ref!==null&&typeof t.ref=="function"&&t.ref._stringRef===o?t.ref:(t=function(i){var a=s.refs;i===null?delete a[o]:a[o]=i},t._stringRef=o,t)}if(typeof e!="string")throw Error(X(284));if(!n._owner)throw Error(X(290,e))}return e}function Wd(e,t){throw e=Object.prototype.toString.call(t),Error(X(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function uC(e){var t=e._init;return t(e._payload)}function LT(e){function t(m,v){if(e){var w=m.deletions;w===null?(m.deletions=[v],m.flags|=16):w.push(v)}}function n(m,v){if(!e)return null;for(;v!==null;)t(m,v),v=v.sibling;return null}function r(m,v){for(m=new Map;v!==null;)v.key!==null?m.set(v.key,v):m.set(v.index,v),v=v.sibling;return m}function s(m,v){return m=Go(m,v),m.index=0,m.sibling=null,m}function o(m,v,w){return m.index=w,e?(w=m.alternate,w!==null?(w=w.index,w<v?(m.flags|=2,v):w):(m.flags|=2,v)):(m.flags|=1048576,v)}function i(m){return e&&m.alternate===null&&(m.flags|=2),m}function a(m,v,w,C){return v===null||v.tag!==6?(v=ny(w,m.mode,C),v.return=m,v):(v=s(v,w),v.return=m,v)}function l(m,v,w,C){var E=w.type;return E===Aa?u(m,v,w.props.children,C,w.key):v!==null&&(v.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===Io&&uC(E)===v.type)?(C=s(v,w.props),C.ref=sc(m,v,w),C.return=m,C):(C=Uh(w.type,w.key,w.props,null,m.mode,C),C.ref=sc(m,v,w),C.return=m,C)}function c(m,v,w,C){return v===null||v.tag!==4||v.stateNode.containerInfo!==w.containerInfo||v.stateNode.implementation!==w.implementation?(v=ry(w,m.mode,C),v.return=m,v):(v=s(v,w.children||[]),v.return=m,v)}function u(m,v,w,C,E){return v===null||v.tag!==7?(v=Di(w,m.mode,C,E),v.return=m,v):(v=s(v,w),v.return=m,v)}function h(m,v,w){if(typeof v=="string"&&v!==""||typeof v=="number")return v=ny(""+v,m.mode,w),v.return=m,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case Dd:return w=Uh(v.type,v.key,v.props,null,m.mode,w),w.ref=sc(m,null,v),w.return=m,w;case Ma:return v=ry(v,m.mode,w),v.return=m,v;case Io:var C=v._init;return h(m,C(v._payload),w)}if(xc(v)||Jl(v))return v=Di(v,m.mode,w,null),v.return=m,v;Wd(m,v)}return null}function p(m,v,w,C){var E=v!==null?v.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return E!==null?null:a(m,v,""+w,C);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case Dd:return w.key===E?l(m,v,w,C):null;case Ma:return w.key===E?c(m,v,w,C):null;case Io:return E=w._init,p(m,v,E(w._payload),C)}if(xc(w)||Jl(w))return E!==null?null:u(m,v,w,C,null);Wd(m,w)}return null}function f(m,v,w,C,E){if(typeof C=="string"&&C!==""||typeof C=="number")return m=m.get(w)||null,a(v,m,""+C,E);if(typeof C=="object"&&C!==null){switch(C.$$typeof){case Dd:return m=m.get(C.key===null?w:C.key)||null,l(v,m,C,E);case Ma:return m=m.get(C.key===null?w:C.key)||null,c(v,m,C,E);case Io:var _=C._init;return f(m,v,w,_(C._payload),E)}if(xc(C)||Jl(C))return m=m.get(w)||null,u(v,m,C,E,null);Wd(v,C)}return null}function S(m,v,w,C){for(var E=null,_=null,I=v,k=v=0,T=null;I!==null&&k<w.length;k++){I.index>k?(T=I,I=null):T=I.sibling;var M=p(m,I,w[k],C);if(M===null){I===null&&(I=T);break}e&&I&&M.alternate===null&&t(m,I),v=o(M,v,k),_===null?E=M:_.sibling=M,_=M,I=T}if(k===w.length)return n(m,I),st&&bi(m,k),E;if(I===null){for(;k<w.length;k++)I=h(m,w[k],C),I!==null&&(v=o(I,v,k),_===null?E=I:_.sibling=I,_=I);return st&&bi(m,k),E}for(I=r(m,I);k<w.length;k++)T=f(I,m,k,w[k],C),T!==null&&(e&&T.alternate!==null&&I.delete(T.key===null?k:T.key),v=o(T,v,k),_===null?E=T:_.sibling=T,_=T);return e&&I.forEach(function(D){return t(m,D)}),st&&bi(m,k),E}function y(m,v,w,C){var E=Jl(w);if(typeof E!="function")throw Error(X(150));if(w=E.call(w),w==null)throw Error(X(151));for(var _=E=null,I=v,k=v=0,T=null,M=w.next();I!==null&&!M.done;k++,M=w.next()){I.index>k?(T=I,I=null):T=I.sibling;var D=p(m,I,M.value,C);if(D===null){I===null&&(I=T);break}e&&I&&D.alternate===null&&t(m,I),v=o(D,v,k),_===null?E=D:_.sibling=D,_=D,I=T}if(M.done)return n(m,I),st&&bi(m,k),E;if(I===null){for(;!M.done;k++,M=w.next())M=h(m,M.value,C),M!==null&&(v=o(M,v,k),_===null?E=M:_.sibling=M,_=M);return st&&bi(m,k),E}for(I=r(m,I);!M.done;k++,M=w.next())M=f(I,m,k,M.value,C),M!==null&&(e&&M.alternate!==null&&I.delete(M.key===null?k:M.key),v=o(M,v,k),_===null?E=M:_.sibling=M,_=M);return e&&I.forEach(function($){return t(m,$)}),st&&bi(m,k),E}function x(m,v,w,C){if(typeof w=="object"&&w!==null&&w.type===Aa&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case Dd:e:{for(var E=w.key,_=v;_!==null;){if(_.key===E){if(E=w.type,E===Aa){if(_.tag===7){n(m,_.sibling),v=s(_,w.props.children),v.return=m,m=v;break e}}else if(_.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===Io&&uC(E)===_.type){n(m,_.sibling),v=s(_,w.props),v.ref=sc(m,_,w),v.return=m,m=v;break e}n(m,_);break}else t(m,_);_=_.sibling}w.type===Aa?(v=Di(w.props.children,m.mode,C,w.key),v.return=m,m=v):(C=Uh(w.type,w.key,w.props,null,m.mode,C),C.ref=sc(m,v,w),C.return=m,m=C)}return i(m);case Ma:e:{for(_=w.key;v!==null;){if(v.key===_)if(v.tag===4&&v.stateNode.containerInfo===w.containerInfo&&v.stateNode.implementation===w.implementation){n(m,v.sibling),v=s(v,w.children||[]),v.return=m,m=v;break e}else{n(m,v);break}else t(m,v);v=v.sibling}v=ry(w,m.mode,C),v.return=m,m=v}return i(m);case Io:return _=w._init,x(m,v,_(w._payload),C)}if(xc(w))return S(m,v,w,C);if(Jl(w))return y(m,v,w,C);Wd(m,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,v!==null&&v.tag===6?(n(m,v.sibling),v=s(v,w),v.return=m,m=v):(n(m,v),v=ny(w,m.mode,C),v.return=m,m=v),i(m)):n(m,v)}return x}var dl=LT(!0),$T=LT(!1),rf=li(null),sf=null,Fa=null,_0=null;function T0(){_0=Fa=sf=null}function M0(e){var t=rf.current;tt(rf),e._currentValue=t}function lv(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function Ja(e,t){sf=e,_0=Fa=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Fn=!0),e.firstContext=null)}function _r(e){var t=e._currentValue;if(_0!==e)if(e={context:e,memoizedValue:t,next:null},Fa===null){if(sf===null)throw Error(X(308));Fa=e,sf.dependencies={lanes:0,firstContext:e}}else Fa=Fa.next=e;return t}var ki=null;function A0(e){ki===null?ki=[e]:ki.push(e)}function NT(e,t,n,r){var s=t.interleaved;return s===null?(n.next=n,A0(t)):(n.next=s.next,s.next=n),t.interleaved=n,to(e,r)}function to(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var Eo=!1;function j0(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function FT(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Vs(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Ho(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Ae&2){var s=r.pending;return s===null?t.next=t:(t.next=s.next,s.next=t),r.pending=t,to(e,n)}return s=r.interleaved,s===null?(t.next=t,A0(r)):(t.next=s.next,s.next=t),r.interleaved=t,to(e,n)}function Lh(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,y0(e,n)}}function dC(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var s=null,o=null;if(n=n.firstBaseUpdate,n!==null){do{var i={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};o===null?s=o=i:o=o.next=i,n=n.next}while(n!==null);o===null?s=o=t:o=o.next=t}else s=o=t;n={baseState:r.baseState,firstBaseUpdate:s,lastBaseUpdate:o,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function of(e,t,n,r){var s=e.updateQueue;Eo=!1;var o=s.firstBaseUpdate,i=s.lastBaseUpdate,a=s.shared.pending;if(a!==null){s.shared.pending=null;var l=a,c=l.next;l.next=null,i===null?o=c:i.next=c,i=l;var u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=c:a.next=c,u.lastBaseUpdate=l))}if(o!==null){var h=s.baseState;i=0,u=c=l=null,a=o;do{var p=a.lane,f=a.eventTime;if((r&p)===p){u!==null&&(u=u.next={eventTime:f,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var S=e,y=a;switch(p=t,f=n,y.tag){case 1:if(S=y.payload,typeof S=="function"){h=S.call(f,h,p);break e}h=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=y.payload,p=typeof S=="function"?S.call(f,h,p):S,p==null)break e;h=pt({},h,p);break e;case 2:Eo=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,p=s.effects,p===null?s.effects=[a]:p.push(a))}else f={eventTime:f,lane:p,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(c=u=f,l=h):u=u.next=f,i|=p;if(a=a.next,a===null){if(a=s.shared.pending,a===null)break;p=a,a=p.next,p.next=null,s.lastBaseUpdate=p,s.shared.pending=null}}while(!0);if(u===null&&(l=h),s.baseState=l,s.firstBaseUpdate=c,s.lastBaseUpdate=u,t=s.shared.interleaved,t!==null){s=t;do i|=s.lane,s=s.next;while(s!==t)}else o===null&&(s.shared.lanes=0);Ki|=i,e.lanes=i,e.memoizedState=h}}function hC(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var r=e[t],s=r.callback;if(s!==null){if(r.callback=null,r=n,typeof s!="function")throw Error(X(191,s));s.call(r)}}}var Qu={},Ss=li(Qu),vu=li(Qu),xu=li(Qu);function _i(e){if(e===Qu)throw Error(X(174));return e}function O0(e,t){switch(Ye(xu,t),Ye(vu,e),Ye(Ss,Qu),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:US(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=US(t,e)}tt(Ss),Ye(Ss,t)}function hl(){tt(Ss),tt(vu),tt(xu)}function zT(e){_i(xu.current);var t=_i(Ss.current),n=US(t,e.type);t!==n&&(Ye(vu,e),Ye(Ss,n))}function D0(e){vu.current===e&&(tt(Ss),tt(vu))}var lt=li(0);function af(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var qm=[];function R0(){for(var e=0;e<qm.length;e++)qm[e]._workInProgressVersionPrimary=null;qm.length=0}var $h=co.ReactCurrentDispatcher,Zm=co.ReactCurrentBatchConfig,Hi=0,ht=null,It=null,Tt=null,lf=!1,Gc=!1,wu=0,dW=0;function en(){throw Error(X(321))}function L0(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!Vr(e[n],t[n]))return!1;return!0}function $0(e,t,n,r,s,o){if(Hi=o,ht=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,$h.current=e===null||e.memoizedState===null?gW:mW,e=n(r,s),Gc){o=0;do{if(Gc=!1,wu=0,25<=o)throw Error(X(301));o+=1,Tt=It=null,t.updateQueue=null,$h.current=yW,e=n(r,s)}while(Gc)}if($h.current=cf,t=It!==null&&It.next!==null,Hi=0,Tt=It=ht=null,lf=!1,t)throw Error(X(300));return e}function N0(){var e=wu!==0;return wu=0,e}function os(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Tt===null?ht.memoizedState=Tt=e:Tt=Tt.next=e,Tt}function Tr(){if(It===null){var e=ht.alternate;e=e!==null?e.memoizedState:null}else e=It.next;var t=Tt===null?ht.memoizedState:Tt.next;if(t!==null)Tt=t,It=e;else{if(e===null)throw Error(X(310));It=e,e={memoizedState:It.memoizedState,baseState:It.baseState,baseQueue:It.baseQueue,queue:It.queue,next:null},Tt===null?ht.memoizedState=Tt=e:Tt=Tt.next=e}return Tt}function bu(e,t){return typeof t=="function"?t(e):t}function Qm(e){var t=Tr(),n=t.queue;if(n===null)throw Error(X(311));n.lastRenderedReducer=e;var r=It,s=r.baseQueue,o=n.pending;if(o!==null){if(s!==null){var i=s.next;s.next=o.next,o.next=i}r.baseQueue=s=o,n.pending=null}if(s!==null){o=s.next,r=r.baseState;var a=i=null,l=null,c=o;do{var u=c.lane;if((Hi&u)===u)l!==null&&(l=l.next={lane:0,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null}),r=c.hasEagerState?c.eagerState:e(r,c.action);else{var h={lane:u,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=h,i=r):l=l.next=h,ht.lanes|=u,Ki|=u}c=c.next}while(c!==null&&c!==o);l===null?i=r:l.next=a,Vr(r,t.memoizedState)||(Fn=!0),t.memoizedState=r,t.baseState=i,t.baseQueue=l,n.lastRenderedState=r}if(e=n.interleaved,e!==null){s=e;do o=s.lane,ht.lanes|=o,Ki|=o,s=s.next;while(s!==e)}else s===null&&(n.lanes=0);return[t.memoizedState,n.dispatch]}function Jm(e){var t=Tr(),n=t.queue;if(n===null)throw Error(X(311));n.lastRenderedReducer=e;var r=n.dispatch,s=n.pending,o=t.memoizedState;if(s!==null){n.pending=null;var i=s=s.next;do o=e(o,i.action),i=i.next;while(i!==s);Vr(o,t.memoizedState)||(Fn=!0),t.memoizedState=o,t.baseQueue===null&&(t.baseState=o),n.lastRenderedState=o}return[o,r]}function BT(){}function UT(e,t){var n=ht,r=Tr(),s=t(),o=!Vr(r.memoizedState,s);if(o&&(r.memoizedState=s,Fn=!0),r=r.queue,F0(WT.bind(null,n,r,e),[e]),r.getSnapshot!==t||o||Tt!==null&&Tt.memoizedState.tag&1){if(n.flags|=2048,Pu(9,KT.bind(null,n,r,s,t),void 0,null),Dt===null)throw Error(X(349));Hi&30||HT(n,t,s)}return s}function HT(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=ht.updateQueue,t===null?(t={lastEffect:null,stores:null},ht.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function KT(e,t,n,r){t.value=n,t.getSnapshot=r,GT(t)&&VT(e)}function WT(e,t,n){return n(function(){GT(t)&&VT(e)})}function GT(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!Vr(e,n)}catch{return!0}}function VT(e){var t=to(e,1);t!==null&&Kr(t,e,1,-1)}function pC(e){var t=os();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:bu,lastRenderedState:e},t.queue=e,e=e.dispatch=fW.bind(null,ht,e),[t.memoizedState,e]}function Pu(e,t,n,r){return e={tag:e,create:t,destroy:n,deps:r,next:null},t=ht.updateQueue,t===null?(t={lastEffect:null,stores:null},ht.updateQueue=t,t.lastEffect=e.next=e):(n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e)),e}function YT(){return Tr().memoizedState}function Nh(e,t,n,r){var s=os();ht.flags|=e,s.memoizedState=Pu(1|t,n,void 0,r===void 0?null:r)}function rg(e,t,n,r){var s=Tr();r=r===void 0?null:r;var o=void 0;if(It!==null){var i=It.memoizedState;if(o=i.destroy,r!==null&&L0(r,i.deps)){s.memoizedState=Pu(t,n,o,r);return}}ht.flags|=e,s.memoizedState=Pu(1|t,n,o,r)}function fC(e,t){return Nh(8390656,8,e,t)}function F0(e,t){return rg(2048,8,e,t)}function XT(e,t){return rg(4,2,e,t)}function qT(e,t){return rg(4,4,e,t)}function ZT(e,t){if(typeof t=="function")return e=e(),t(e),function(){t(null)};if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function QT(e,t,n){return n=n!=null?n.concat([e]):null,rg(4,4,ZT.bind(null,t,e),n)}function z0(){}function JT(e,t){var n=Tr();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&L0(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function eM(e,t){var n=Tr();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&L0(t,r[1])?r[0]:(e=e(),n.memoizedState=[e,t],e)}function tM(e,t,n){return Hi&21?(Vr(n,t)||(n=iT(),ht.lanes|=n,Ki|=n,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Fn=!0),e.memoizedState=n)}function hW(e,t){var n=Ne;Ne=n!==0&&4>n?n:4,e(!0);var r=Zm.transition;Zm.transition={};try{e(!1),t()}finally{Ne=n,Zm.transition=r}}function nM(){return Tr().memoizedState}function pW(e,t,n){var r=Wo(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},rM(e))sM(t,n);else if(n=NT(e,t,n,r),n!==null){var s=vn();Kr(n,e,r,s),oM(n,t,r)}}function fW(e,t,n){var r=Wo(e),s={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(rM(e))sM(t,s);else{var o=e.alternate;if(e.lanes===0&&(o===null||o.lanes===0)&&(o=t.lastRenderedReducer,o!==null))try{var i=t.lastRenderedState,a=o(i,n);if(s.hasEagerState=!0,s.eagerState=a,Vr(a,i)){var l=t.interleaved;l===null?(s.next=s,A0(t)):(s.next=l.next,l.next=s),t.interleaved=s;return}}catch{}finally{}n=NT(e,t,s,r),n!==null&&(s=vn(),Kr(n,e,r,s),oM(n,t,r))}}function rM(e){var t=e.alternate;return e===ht||t!==null&&t===ht}function sM(e,t){Gc=lf=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function oM(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,y0(e,n)}}var cf={readContext:_r,useCallback:en,useContext:en,useEffect:en,useImperativeHandle:en,useInsertionEffect:en,useLayoutEffect:en,useMemo:en,useReducer:en,useRef:en,useState:en,useDebugValue:en,useDeferredValue:en,useTransition:en,useMutableSource:en,useSyncExternalStore:en,useId:en,unstable_isNewReconciler:!1},gW={readContext:_r,useCallback:function(e,t){return os().memoizedState=[e,t===void 0?null:t],e},useContext:_r,useEffect:fC,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Nh(4194308,4,ZT.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Nh(4194308,4,e,t)},useInsertionEffect:function(e,t){return Nh(4,2,e,t)},useMemo:function(e,t){var n=os();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=os();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=pW.bind(null,ht,e),[r.memoizedState,e]},useRef:function(e){var t=os();return e={current:e},t.memoizedState=e},useState:pC,useDebugValue:z0,useDeferredValue:function(e){return os().memoizedState=e},useTransition:function(){var e=pC(!1),t=e[0];return e=hW.bind(null,e[1]),os().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=ht,s=os();if(st){if(n===void 0)throw Error(X(407));n=n()}else{if(n=t(),Dt===null)throw Error(X(349));Hi&30||HT(r,t,n)}s.memoizedState=n;var o={value:n,getSnapshot:t};return s.queue=o,fC(WT.bind(null,r,o,e),[e]),r.flags|=2048,Pu(9,KT.bind(null,r,o,n,t),void 0,null),n},useId:function(){var e=os(),t=Dt.identifierPrefix;if(st){var n=Hs,r=Us;n=(r&~(1<<32-Hr(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=wu++,0<n&&(t+="H"+n.toString(32)),t+=":"}else n=dW++,t=":"+t+"r"+n.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},mW={readContext:_r,useCallback:JT,useContext:_r,useEffect:F0,useImperativeHandle:QT,useInsertionEffect:XT,useLayoutEffect:qT,useMemo:eM,useReducer:Qm,useRef:YT,useState:function(){return Qm(bu)},useDebugValue:z0,useDeferredValue:function(e){var t=Tr();return tM(t,It.memoizedState,e)},useTransition:function(){var e=Qm(bu)[0],t=Tr().memoizedState;return[e,t]},useMutableSource:BT,useSyncExternalStore:UT,useId:nM,unstable_isNewReconciler:!1},yW={readContext:_r,useCallback:JT,useContext:_r,useEffect:F0,useImperativeHandle:QT,useInsertionEffect:XT,useLayoutEffect:qT,useMemo:eM,useReducer:Jm,useRef:YT,useState:function(){return Jm(bu)},useDebugValue:z0,useDeferredValue:function(e){var t=Tr();return It===null?t.memoizedState=e:tM(t,It.memoizedState,e)},useTransition:function(){var e=Jm(bu)[0],t=Tr().memoizedState;return[e,t]},useMutableSource:BT,useSyncExternalStore:UT,useId:nM,unstable_isNewReconciler:!1};function Rr(e,t){if(e&&e.defaultProps){t=pt({},t),e=e.defaultProps;for(var n in e)t[n]===void 0&&(t[n]=e[n]);return t}return t}function cv(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:pt({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var sg={isMounted:function(e){return(e=e._reactInternals)?oa(e)===e:!1},enqueueSetState:function(e,t,n){e=e._reactInternals;var r=vn(),s=Wo(e),o=Vs(r,s);o.payload=t,n!=null&&(o.callback=n),t=Ho(e,o,s),t!==null&&(Kr(t,e,s,r),Lh(t,e,s))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=vn(),s=Wo(e),o=Vs(r,s);o.tag=1,o.payload=t,n!=null&&(o.callback=n),t=Ho(e,o,s),t!==null&&(Kr(t,e,s,r),Lh(t,e,s))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=vn(),r=Wo(e),s=Vs(n,r);s.tag=2,t!=null&&(s.callback=t),t=Ho(e,s,r),t!==null&&(Kr(t,e,r,n),Lh(t,e,r))}};function gC(e,t,n,r,s,o,i){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,o,i):t.prototype&&t.prototype.isPureReactComponent?!gu(n,r)||!gu(s,o):!0}function iM(e,t,n){var r=!1,s=qo,o=t.contextType;return typeof o=="object"&&o!==null?o=_r(o):(s=Kn(t)?Bi:hn.current,r=t.contextTypes,o=(r=r!=null)?cl(e,s):qo),t=new t(n,o),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=sg,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=s,e.__reactInternalMemoizedMaskedChildContext=o),t}function mC(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps=="function"&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps=="function"&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&sg.enqueueReplaceState(t,t.state,null)}function uv(e,t,n,r){var s=e.stateNode;s.props=n,s.state=e.memoizedState,s.refs={},j0(e);var o=t.contextType;typeof o=="object"&&o!==null?s.context=_r(o):(o=Kn(t)?Bi:hn.current,s.context=cl(e,o)),s.state=e.memoizedState,o=t.getDerivedStateFromProps,typeof o=="function"&&(cv(e,t,o,n),s.state=e.memoizedState),typeof t.getDerivedStateFromProps=="function"||typeof s.getSnapshotBeforeUpdate=="function"||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(t=s.state,typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount(),t!==s.state&&sg.enqueueReplaceState(s,s.state,null),of(e,n,s,r),s.state=e.memoizedState),typeof s.componentDidMount=="function"&&(e.flags|=4194308)}function pl(e,t){try{var n="",r=t;do n+=WH(r),r=r.return;while(r);var s=n}catch(o){s=`
|
|
84
|
-
Error generating stack: `+o.message+`
|
|
85
|
-
`+o.stack}return{value:e,source:t,stack:s,digest:null}}function ey(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function dv(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var SW=typeof WeakMap=="function"?WeakMap:Map;function aM(e,t,n){n=Vs(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){df||(df=!0,wv=r),dv(e,t)},n}function lM(e,t,n){n=Vs(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var s=t.value;n.payload=function(){return r(s)},n.callback=function(){dv(e,t)}}var o=e.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(n.callback=function(){dv(e,t),typeof r!="function"&&(Ko===null?Ko=new Set([this]):Ko.add(this));var i=t.stack;this.componentDidCatch(t.value,{componentStack:i!==null?i:""})}),n}function yC(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new SW;var s=new Set;r.set(t,s)}else s=r.get(t),s===void 0&&(s=new Set,r.set(t,s));s.has(n)||(s.add(n),e=jW.bind(null,e,t,n),t.then(e,e))}function SC(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function vC(e,t,n,r,s){return e.mode&1?(e.flags|=65536,e.lanes=s,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=Vs(-1,1),t.tag=2,Ho(n,t,1))),n.lanes|=1),e)}var vW=co.ReactCurrentOwner,Fn=!1;function mn(e,t,n,r){t.child=e===null?$T(t,null,n,r):dl(t,e.child,n,r)}function xC(e,t,n,r,s){n=n.render;var o=t.ref;return Ja(t,s),r=$0(e,t,n,r,o,s),n=N0(),e!==null&&!Fn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~s,no(e,t,s)):(st&&n&&I0(t),t.flags|=1,mn(e,t,r,s),t.child)}function wC(e,t,n,r,s){if(e===null){var o=n.type;return typeof o=="function"&&!Y0(o)&&o.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=o,cM(e,t,o,r,s)):(e=Uh(n.type,null,r,t,t.mode,s),e.ref=t.ref,e.return=t,t.child=e)}if(o=e.child,!(e.lanes&s)){var i=o.memoizedProps;if(n=n.compare,n=n!==null?n:gu,n(i,r)&&e.ref===t.ref)return no(e,t,s)}return t.flags|=1,e=Go(o,r),e.ref=t.ref,e.return=t,t.child=e}function cM(e,t,n,r,s){if(e!==null){var o=e.memoizedProps;if(gu(o,r)&&e.ref===t.ref)if(Fn=!1,t.pendingProps=r=o,(e.lanes&s)!==0)e.flags&131072&&(Fn=!0);else return t.lanes=e.lanes,no(e,t,s)}return hv(e,t,n,r,s)}function uM(e,t,n){var r=t.pendingProps,s=r.children,o=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ye(Ba,Jn),Jn|=n;else{if(!(n&1073741824))return e=o!==null?o.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,Ye(Ba,Jn),Jn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:n,Ye(Ba,Jn),Jn|=r}else o!==null?(r=o.baseLanes|n,t.memoizedState=null):r=n,Ye(Ba,Jn),Jn|=r;return mn(e,t,s,n),t.child}function dM(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function hv(e,t,n,r,s){var o=Kn(n)?Bi:hn.current;return o=cl(t,o),Ja(t,s),n=$0(e,t,n,r,o,s),r=N0(),e!==null&&!Fn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~s,no(e,t,s)):(st&&r&&I0(t),t.flags|=1,mn(e,t,n,s),t.child)}function bC(e,t,n,r,s){if(Kn(n)){var o=!0;ef(t)}else o=!1;if(Ja(t,s),t.stateNode===null)Fh(e,t),iM(t,n,r),uv(t,n,r,s),r=!0;else if(e===null){var i=t.stateNode,a=t.memoizedProps;i.props=a;var l=i.context,c=n.contextType;typeof c=="object"&&c!==null?c=_r(c):(c=Kn(n)?Bi:hn.current,c=cl(t,c));var u=n.getDerivedStateFromProps,h=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";h||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||l!==c)&&mC(t,i,r,c),Eo=!1;var p=t.memoizedState;i.state=p,of(t,r,i,s),l=t.memoizedState,a!==r||p!==l||Hn.current||Eo?(typeof u=="function"&&(cv(t,n,u,r),l=t.memoizedState),(a=Eo||gC(t,n,a,r,p,l,c))?(h||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(t.flags|=4194308)):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=l),i.props=r,i.state=l,i.context=c,r=a):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{i=t.stateNode,FT(e,t),a=t.memoizedProps,c=t.type===t.elementType?a:Rr(t.type,a),i.props=c,h=t.pendingProps,p=i.context,l=n.contextType,typeof l=="object"&&l!==null?l=_r(l):(l=Kn(n)?Bi:hn.current,l=cl(t,l));var f=n.getDerivedStateFromProps;(u=typeof f=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==h||p!==l)&&mC(t,i,r,l),Eo=!1,p=t.memoizedState,i.state=p,of(t,r,i,s);var S=t.memoizedState;a!==h||p!==S||Hn.current||Eo?(typeof f=="function"&&(cv(t,n,f,r),S=t.memoizedState),(c=Eo||gC(t,n,c,r,p,S,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,S,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,S,l)),typeof i.componentDidUpdate=="function"&&(t.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=S),i.props=r,i.state=S,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),r=!1)}return pv(e,t,n,r,o,s)}function pv(e,t,n,r,s,o){dM(e,t);var i=(t.flags&128)!==0;if(!r&&!i)return s&&aC(t,n,!1),no(e,t,o);r=t.stateNode,vW.current=t;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&i?(t.child=dl(t,e.child,null,o),t.child=dl(t,null,a,o)):mn(e,t,a,o),t.memoizedState=r.state,s&&aC(t,n,!0),t.child}function hM(e){var t=e.stateNode;t.pendingContext?iC(e,t.pendingContext,t.pendingContext!==t.context):t.context&&iC(e,t.context,!1),O0(e,t.containerInfo)}function PC(e,t,n,r,s){return ul(),k0(s),t.flags|=256,mn(e,t,n,r),t.child}var fv={dehydrated:null,treeContext:null,retryLane:0};function gv(e){return{baseLanes:e,cachePool:null,transitions:null}}function pM(e,t,n){var r=t.pendingProps,s=lt.current,o=!1,i=(t.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(s&2)!==0),a?(o=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(s|=1),Ye(lt,s&1),e===null)return av(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(i=r.children,e=r.fallback,o?(r=t.mode,o=t.child,i={mode:"hidden",children:i},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=i):o=ag(i,r,0,null),e=Di(e,r,n,null),o.return=t,e.return=t,o.sibling=e,t.child=o,t.child.memoizedState=gv(n),t.memoizedState=fv,e):B0(t,i));if(s=e.memoizedState,s!==null&&(a=s.dehydrated,a!==null))return xW(e,t,i,r,a,s,n);if(o){o=r.fallback,i=t.mode,s=e.child,a=s.sibling;var l={mode:"hidden",children:r.children};return!(i&1)&&t.child!==s?(r=t.child,r.childLanes=0,r.pendingProps=l,t.deletions=null):(r=Go(s,l),r.subtreeFlags=s.subtreeFlags&14680064),a!==null?o=Go(a,o):(o=Di(o,i,n,null),o.flags|=2),o.return=t,r.return=t,r.sibling=o,t.child=r,r=o,o=t.child,i=e.child.memoizedState,i=i===null?gv(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},o.memoizedState=i,o.childLanes=e.childLanes&~n,t.memoizedState=fv,r}return o=e.child,e=o.sibling,r=Go(o,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function B0(e,t){return t=ag({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function Gd(e,t,n,r){return r!==null&&k0(r),dl(t,e.child,null,n),e=B0(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function xW(e,t,n,r,s,o,i){if(n)return t.flags&256?(t.flags&=-257,r=ey(Error(X(422))),Gd(e,t,i,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(o=r.fallback,s=t.mode,r=ag({mode:"visible",children:r.children},s,0,null),o=Di(o,s,i,null),o.flags|=2,r.return=t,o.return=t,r.sibling=o,t.child=r,t.mode&1&&dl(t,e.child,null,i),t.child.memoizedState=gv(i),t.memoizedState=fv,o);if(!(t.mode&1))return Gd(e,t,i,null);if(s.data==="$!"){if(r=s.nextSibling&&s.nextSibling.dataset,r)var a=r.dgst;return r=a,o=Error(X(419)),r=ey(o,r,void 0),Gd(e,t,i,r)}if(a=(i&e.childLanes)!==0,Fn||a){if(r=Dt,r!==null){switch(i&-i){case 4:s=2;break;case 16:s=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:s=32;break;case 536870912:s=268435456;break;default:s=0}s=s&(r.suspendedLanes|i)?0:s,s!==0&&s!==o.retryLane&&(o.retryLane=s,to(e,s),Kr(r,e,s,-1))}return V0(),r=ey(Error(X(421))),Gd(e,t,i,r)}return s.data==="$?"?(t.flags|=128,t.child=e.child,t=OW.bind(null,e),s._reactRetry=t,null):(e=o.treeContext,nr=Uo(s.nextSibling),ir=t,st=!0,Fr=null,e!==null&&(br[Pr++]=Us,br[Pr++]=Hs,br[Pr++]=Ui,Us=e.id,Hs=e.overflow,Ui=t),t=B0(t,r.children),t.flags|=4096,t)}function CC(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),lv(e.return,t,n)}function ty(e,t,n,r,s){var o=e.memoizedState;o===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:s}:(o.isBackwards=t,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=s)}function fM(e,t,n){var r=t.pendingProps,s=r.revealOrder,o=r.tail;if(mn(e,t,r.children,n),r=lt.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&CC(e,n,t);else if(e.tag===19)CC(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Ye(lt,r),!(t.mode&1))t.memoizedState=null;else switch(s){case"forwards":for(n=t.child,s=null;n!==null;)e=n.alternate,e!==null&&af(e)===null&&(s=n),n=n.sibling;n=s,n===null?(s=t.child,t.child=null):(s=n.sibling,n.sibling=null),ty(t,!1,s,n,o);break;case"backwards":for(n=null,s=t.child,t.child=null;s!==null;){if(e=s.alternate,e!==null&&af(e)===null){t.child=s;break}e=s.sibling,s.sibling=n,n=s,s=e}ty(t,!0,n,null,o);break;case"together":ty(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function Fh(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function no(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Ki|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(X(153));if(t.child!==null){for(e=t.child,n=Go(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=Go(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function wW(e,t,n){switch(t.tag){case 3:hM(t),ul();break;case 5:zT(t);break;case 1:Kn(t.type)&&ef(t);break;case 4:O0(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,s=t.memoizedProps.value;Ye(rf,r._currentValue),r._currentValue=s;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(Ye(lt,lt.current&1),t.flags|=128,null):n&t.child.childLanes?pM(e,t,n):(Ye(lt,lt.current&1),e=no(e,t,n),e!==null?e.sibling:null);Ye(lt,lt.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return fM(e,t,n);t.flags|=128}if(s=t.memoizedState,s!==null&&(s.rendering=null,s.tail=null,s.lastEffect=null),Ye(lt,lt.current),r)break;return null;case 22:case 23:return t.lanes=0,uM(e,t,n)}return no(e,t,n)}var gM,mv,mM,yM;gM=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};mv=function(){};mM=function(e,t,n,r){var s=e.memoizedProps;if(s!==r){e=t.stateNode,_i(Ss.current);var o=null;switch(n){case"input":s=NS(e,s),r=NS(e,r),o=[];break;case"select":s=pt({},s,{value:void 0}),r=pt({},r,{value:void 0}),o=[];break;case"textarea":s=BS(e,s),r=BS(e,r),o=[];break;default:typeof s.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Qp)}HS(n,r);var i;n=null;for(c in s)if(!r.hasOwnProperty(c)&&s.hasOwnProperty(c)&&s[c]!=null)if(c==="style"){var a=s[c];for(i in a)a.hasOwnProperty(i)&&(n||(n={}),n[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(lu.hasOwnProperty(c)?o||(o=[]):(o=o||[]).push(c,null));for(c in r){var l=r[c];if(a=s!=null?s[c]:void 0,r.hasOwnProperty(c)&&l!==a&&(l!=null||a!=null))if(c==="style")if(a){for(i in a)!a.hasOwnProperty(i)||l&&l.hasOwnProperty(i)||(n||(n={}),n[i]="");for(i in l)l.hasOwnProperty(i)&&a[i]!==l[i]&&(n||(n={}),n[i]=l[i])}else n||(o||(o=[]),o.push(c,n)),n=l;else c==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,a=a?a.__html:void 0,l!=null&&a!==l&&(o=o||[]).push(c,l)):c==="children"?typeof l!="string"&&typeof l!="number"||(o=o||[]).push(c,""+l):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(lu.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&Je("scroll",e),o||a===l||(o=[])):(o=o||[]).push(c,l))}n&&(o=o||[]).push("style",n);var c=o;(t.updateQueue=c)&&(t.flags|=4)}};yM=function(e,t,n,r){n!==r&&(t.flags|=4)};function oc(e,t){if(!st)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function tn(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var s=e.child;s!==null;)n|=s.lanes|s.childLanes,r|=s.subtreeFlags&14680064,r|=s.flags&14680064,s.return=e,s=s.sibling;else for(s=e.child;s!==null;)n|=s.lanes|s.childLanes,r|=s.subtreeFlags,r|=s.flags,s.return=e,s=s.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function bW(e,t,n){var r=t.pendingProps;switch(E0(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return tn(t),null;case 1:return Kn(t.type)&&Jp(),tn(t),null;case 3:return r=t.stateNode,hl(),tt(Hn),tt(hn),R0(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Kd(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Fr!==null&&(Cv(Fr),Fr=null))),mv(e,t),tn(t),null;case 5:D0(t);var s=_i(xu.current);if(n=t.type,e!==null&&t.stateNode!=null)mM(e,t,n,r,s),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(X(166));return tn(t),null}if(e=_i(Ss.current),Kd(t)){r=t.stateNode,n=t.type;var o=t.memoizedProps;switch(r[cs]=t,r[Su]=o,e=(t.mode&1)!==0,n){case"dialog":Je("cancel",r),Je("close",r);break;case"iframe":case"object":case"embed":Je("load",r);break;case"video":case"audio":for(s=0;s<bc.length;s++)Je(bc[s],r);break;case"source":Je("error",r);break;case"img":case"image":case"link":Je("error",r),Je("load",r);break;case"details":Je("toggle",r);break;case"input":OP(r,o),Je("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!o.multiple},Je("invalid",r);break;case"textarea":RP(r,o),Je("invalid",r)}HS(n,o),s=null;for(var i in o)if(o.hasOwnProperty(i)){var a=o[i];i==="children"?typeof a=="string"?r.textContent!==a&&(o.suppressHydrationWarning!==!0&&Hd(r.textContent,a,e),s=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(o.suppressHydrationWarning!==!0&&Hd(r.textContent,a,e),s=["children",""+a]):lu.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Je("scroll",r)}switch(n){case"input":Rd(r),DP(r,o,!0);break;case"textarea":Rd(r),LP(r);break;case"select":case"option":break;default:typeof o.onClick=="function"&&(r.onclick=Qp)}r=s,t.updateQueue=r,r!==null&&(t.flags|=4)}else{i=s.nodeType===9?s:s.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=W2(n)),e==="http://www.w3.org/1999/xhtml"?n==="script"?(e=i.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(n,{is:r.is}):(e=i.createElement(n),n==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,n),e[cs]=t,e[Su]=r,gM(e,t,!1,!1),t.stateNode=e;e:{switch(i=KS(n,r),n){case"dialog":Je("cancel",e),Je("close",e),s=r;break;case"iframe":case"object":case"embed":Je("load",e),s=r;break;case"video":case"audio":for(s=0;s<bc.length;s++)Je(bc[s],e);s=r;break;case"source":Je("error",e),s=r;break;case"img":case"image":case"link":Je("error",e),Je("load",e),s=r;break;case"details":Je("toggle",e),s=r;break;case"input":OP(e,r),s=NS(e,r),Je("invalid",e);break;case"option":s=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},s=pt({},r,{value:void 0}),Je("invalid",e);break;case"textarea":RP(e,r),s=BS(e,r),Je("invalid",e);break;default:s=r}HS(n,s),a=s;for(o in a)if(a.hasOwnProperty(o)){var l=a[o];o==="style"?Y2(e,l):o==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&G2(e,l)):o==="children"?typeof l=="string"?(n!=="textarea"||l!=="")&&cu(e,l):typeof l=="number"&&cu(e,""+l):o!=="suppressContentEditableWarning"&&o!=="suppressHydrationWarning"&&o!=="autoFocus"&&(lu.hasOwnProperty(o)?l!=null&&o==="onScroll"&&Je("scroll",e):l!=null&&d0(e,o,l,i))}switch(n){case"input":Rd(e),DP(e,r,!1);break;case"textarea":Rd(e),LP(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Xo(r.value));break;case"select":e.multiple=!!r.multiple,o=r.value,o!=null?Xa(e,!!r.multiple,o,!1):r.defaultValue!=null&&Xa(e,!!r.multiple,r.defaultValue,!0);break;default:typeof s.onClick=="function"&&(e.onclick=Qp)}switch(n){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return tn(t),null;case 6:if(e&&t.stateNode!=null)yM(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(X(166));if(n=_i(xu.current),_i(Ss.current),Kd(t)){if(r=t.stateNode,n=t.memoizedProps,r[cs]=t,(o=r.nodeValue!==n)&&(e=ir,e!==null))switch(e.tag){case 3:Hd(r.nodeValue,n,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Hd(r.nodeValue,n,(e.mode&1)!==0)}o&&(t.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[cs]=t,t.stateNode=r}return tn(t),null;case 13:if(tt(lt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(st&&nr!==null&&t.mode&1&&!(t.flags&128))RT(),ul(),t.flags|=98560,o=!1;else if(o=Kd(t),r!==null&&r.dehydrated!==null){if(e===null){if(!o)throw Error(X(318));if(o=t.memoizedState,o=o!==null?o.dehydrated:null,!o)throw Error(X(317));o[cs]=t}else ul(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;tn(t),o=!1}else Fr!==null&&(Cv(Fr),Fr=null),o=!0;if(!o)return t.flags&65536?t:null}return t.flags&128?(t.lanes=n,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||lt.current&1?Et===0&&(Et=3):V0())),t.updateQueue!==null&&(t.flags|=4),tn(t),null);case 4:return hl(),mv(e,t),e===null&&mu(t.stateNode.containerInfo),tn(t),null;case 10:return M0(t.type._context),tn(t),null;case 17:return Kn(t.type)&&Jp(),tn(t),null;case 19:if(tt(lt),o=t.memoizedState,o===null)return tn(t),null;if(r=(t.flags&128)!==0,i=o.rendering,i===null)if(r)oc(o,!1);else{if(Et!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(i=af(e),i!==null){for(t.flags|=128,oc(o,!1),r=i.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=n,n=t.child;n!==null;)o=n,e=r,o.flags&=14680066,i=o.alternate,i===null?(o.childLanes=0,o.lanes=e,o.child=null,o.subtreeFlags=0,o.memoizedProps=null,o.memoizedState=null,o.updateQueue=null,o.dependencies=null,o.stateNode=null):(o.childLanes=i.childLanes,o.lanes=i.lanes,o.child=i.child,o.subtreeFlags=0,o.deletions=null,o.memoizedProps=i.memoizedProps,o.memoizedState=i.memoizedState,o.updateQueue=i.updateQueue,o.type=i.type,e=i.dependencies,o.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),n=n.sibling;return Ye(lt,lt.current&1|2),t.child}e=e.sibling}o.tail!==null&&wt()>fl&&(t.flags|=128,r=!0,oc(o,!1),t.lanes=4194304)}else{if(!r)if(e=af(i),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),oc(o,!0),o.tail===null&&o.tailMode==="hidden"&&!i.alternate&&!st)return tn(t),null}else 2*wt()-o.renderingStartTime>fl&&n!==1073741824&&(t.flags|=128,r=!0,oc(o,!1),t.lanes=4194304);o.isBackwards?(i.sibling=t.child,t.child=i):(n=o.last,n!==null?n.sibling=i:t.child=i,o.last=i)}return o.tail!==null?(t=o.tail,o.rendering=t,o.tail=t.sibling,o.renderingStartTime=wt(),t.sibling=null,n=lt.current,Ye(lt,r?n&1|2:n&1),t):(tn(t),null);case 22:case 23:return G0(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Jn&1073741824&&(tn(t),t.subtreeFlags&6&&(t.flags|=8192)):tn(t),null;case 24:return null;case 25:return null}throw Error(X(156,t.tag))}function PW(e,t){switch(E0(t),t.tag){case 1:return Kn(t.type)&&Jp(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return hl(),tt(Hn),tt(hn),R0(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return D0(t),null;case 13:if(tt(lt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(X(340));ul()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return tt(lt),null;case 4:return hl(),null;case 10:return M0(t.type._context),null;case 22:case 23:return G0(),null;case 24:return null;default:return null}}var Vd=!1,an=!1,CW=typeof WeakSet=="function"?WeakSet:Set,te=null;function za(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){mt(e,t,r)}else n.current=null}function yv(e,t,n){try{n()}catch(r){mt(e,t,r)}}var IC=!1;function IW(e,t){if(ev=Xp,e=bT(),C0(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var s=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var i=0,a=-1,l=-1,c=0,u=0,h=e,p=null;t:for(;;){for(var f;h!==n||s!==0&&h.nodeType!==3||(a=i+s),h!==o||r!==0&&h.nodeType!==3||(l=i+r),h.nodeType===3&&(i+=h.nodeValue.length),(f=h.firstChild)!==null;)p=h,h=f;for(;;){if(h===e)break t;if(p===n&&++c===s&&(a=i),p===o&&++u===r&&(l=i),(f=h.nextSibling)!==null)break;h=p,p=h.parentNode}h=f}n=a===-1||l===-1?null:{start:a,end:l}}else n=null}n=n||{start:0,end:0}}else n=null;for(tv={focusedElem:e,selectionRange:n},Xp=!1,te=t;te!==null;)if(t=te,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,te=e;else for(;te!==null;){t=te;try{var S=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var y=S.memoizedProps,x=S.memoizedState,m=t.stateNode,v=m.getSnapshotBeforeUpdate(t.elementType===t.type?y:Rr(t.type,y),x);m.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var w=t.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(X(163))}}catch(C){mt(t,t.return,C)}if(e=t.sibling,e!==null){e.return=t.return,te=e;break}te=t.return}return S=IC,IC=!1,S}function Vc(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var s=r=r.next;do{if((s.tag&e)===e){var o=s.destroy;s.destroy=void 0,o!==void 0&&yv(t,n,o)}s=s.next}while(s!==r)}}function og(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Sv(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function SM(e){var t=e.alternate;t!==null&&(e.alternate=null,SM(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[cs],delete t[Su],delete t[sv],delete t[aW],delete t[lW])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function vM(e){return e.tag===5||e.tag===3||e.tag===4}function EC(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||vM(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function vv(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=Qp));else if(r!==4&&(e=e.child,e!==null))for(vv(e,t,n),e=e.sibling;e!==null;)vv(e,t,n),e=e.sibling}function xv(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(xv(e,t,n),e=e.sibling;e!==null;)xv(e,t,n),e=e.sibling}var zt=null,$r=!1;function xo(e,t,n){for(n=n.child;n!==null;)xM(e,t,n),n=n.sibling}function xM(e,t,n){if(ys&&typeof ys.onCommitFiberUnmount=="function")try{ys.onCommitFiberUnmount(Zf,n)}catch{}switch(n.tag){case 5:an||za(n,t);case 6:var r=zt,s=$r;zt=null,xo(e,t,n),zt=r,$r=s,zt!==null&&($r?(e=zt,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):zt.removeChild(n.stateNode));break;case 18:zt!==null&&($r?(e=zt,n=n.stateNode,e.nodeType===8?Ym(e.parentNode,n):e.nodeType===1&&Ym(e,n),pu(e)):Ym(zt,n.stateNode));break;case 4:r=zt,s=$r,zt=n.stateNode.containerInfo,$r=!0,xo(e,t,n),zt=r,$r=s;break;case 0:case 11:case 14:case 15:if(!an&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){s=r=r.next;do{var o=s,i=o.destroy;o=o.tag,i!==void 0&&(o&2||o&4)&&yv(n,t,i),s=s.next}while(s!==r)}xo(e,t,n);break;case 1:if(!an&&(za(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){mt(n,t,a)}xo(e,t,n);break;case 21:xo(e,t,n);break;case 22:n.mode&1?(an=(r=an)||n.memoizedState!==null,xo(e,t,n),an=r):xo(e,t,n);break;default:xo(e,t,n)}}function kC(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new CW),t.forEach(function(r){var s=DW.bind(null,e,r);n.has(r)||(n.add(r),r.then(s,s))})}}function Dr(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var s=n[r];try{var o=e,i=t,a=i;e:for(;a!==null;){switch(a.tag){case 5:zt=a.stateNode,$r=!1;break e;case 3:zt=a.stateNode.containerInfo,$r=!0;break e;case 4:zt=a.stateNode.containerInfo,$r=!0;break e}a=a.return}if(zt===null)throw Error(X(160));xM(o,i,s),zt=null,$r=!1;var l=s.alternate;l!==null&&(l.return=null),s.return=null}catch(c){mt(s,t,c)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)wM(t,e),t=t.sibling}function wM(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Dr(t,e),rs(e),r&4){try{Vc(3,e,e.return),og(3,e)}catch(y){mt(e,e.return,y)}try{Vc(5,e,e.return)}catch(y){mt(e,e.return,y)}}break;case 1:Dr(t,e),rs(e),r&512&&n!==null&&za(n,n.return);break;case 5:if(Dr(t,e),rs(e),r&512&&n!==null&&za(n,n.return),e.flags&32){var s=e.stateNode;try{cu(s,"")}catch(y){mt(e,e.return,y)}}if(r&4&&(s=e.stateNode,s!=null)){var o=e.memoizedProps,i=n!==null?n.memoizedProps:o,a=e.type,l=e.updateQueue;if(e.updateQueue=null,l!==null)try{a==="input"&&o.type==="radio"&&o.name!=null&&H2(s,o),KS(a,i);var c=KS(a,o);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?Y2(s,h):u==="dangerouslySetInnerHTML"?G2(s,h):u==="children"?cu(s,h):d0(s,u,h,c)}switch(a){case"input":FS(s,o);break;case"textarea":K2(s,o);break;case"select":var p=s._wrapperState.wasMultiple;s._wrapperState.wasMultiple=!!o.multiple;var f=o.value;f!=null?Xa(s,!!o.multiple,f,!1):p!==!!o.multiple&&(o.defaultValue!=null?Xa(s,!!o.multiple,o.defaultValue,!0):Xa(s,!!o.multiple,o.multiple?[]:"",!1))}s[Su]=o}catch(y){mt(e,e.return,y)}}break;case 6:if(Dr(t,e),rs(e),r&4){if(e.stateNode===null)throw Error(X(162));s=e.stateNode,o=e.memoizedProps;try{s.nodeValue=o}catch(y){mt(e,e.return,y)}}break;case 3:if(Dr(t,e),rs(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{pu(t.containerInfo)}catch(y){mt(e,e.return,y)}break;case 4:Dr(t,e),rs(e);break;case 13:Dr(t,e),rs(e),s=e.child,s.flags&8192&&(o=s.memoizedState!==null,s.stateNode.isHidden=o,!o||s.alternate!==null&&s.alternate.memoizedState!==null||(K0=wt())),r&4&&kC(e);break;case 22:if(u=n!==null&&n.memoizedState!==null,e.mode&1?(an=(c=an)||u,Dr(t,e),an=c):Dr(t,e),rs(e),r&8192){if(c=e.memoizedState!==null,(e.stateNode.isHidden=c)&&!u&&e.mode&1)for(te=e,u=e.child;u!==null;){for(h=te=u;te!==null;){switch(p=te,f=p.child,p.tag){case 0:case 11:case 14:case 15:Vc(4,p,p.return);break;case 1:za(p,p.return);var S=p.stateNode;if(typeof S.componentWillUnmount=="function"){r=p,n=p.return;try{t=r,S.props=t.memoizedProps,S.state=t.memoizedState,S.componentWillUnmount()}catch(y){mt(r,n,y)}}break;case 5:za(p,p.return);break;case 22:if(p.memoizedState!==null){TC(h);continue}}f!==null?(f.return=p,te=f):TC(h)}u=u.sibling}e:for(u=null,h=e;;){if(h.tag===5){if(u===null){u=h;try{s=h.stateNode,c?(o=s.style,typeof o.setProperty=="function"?o.setProperty("display","none","important"):o.display="none"):(a=h.stateNode,l=h.memoizedProps.style,i=l!=null&&l.hasOwnProperty("display")?l.display:null,a.style.display=V2("display",i))}catch(y){mt(e,e.return,y)}}}else if(h.tag===6){if(u===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(y){mt(e,e.return,y)}}else if((h.tag!==22&&h.tag!==23||h.memoizedState===null||h===e)&&h.child!==null){h.child.return=h,h=h.child;continue}if(h===e)break e;for(;h.sibling===null;){if(h.return===null||h.return===e)break e;u===h&&(u=null),h=h.return}u===h&&(u=null),h.sibling.return=h.return,h=h.sibling}}break;case 19:Dr(t,e),rs(e),r&4&&kC(e);break;case 21:break;default:Dr(t,e),rs(e)}}function rs(e){var t=e.flags;if(t&2){try{e:{for(var n=e.return;n!==null;){if(vM(n)){var r=n;break e}n=n.return}throw Error(X(160))}switch(r.tag){case 5:var s=r.stateNode;r.flags&32&&(cu(s,""),r.flags&=-33);var o=EC(e);xv(e,o,s);break;case 3:case 4:var i=r.stateNode.containerInfo,a=EC(e);vv(e,a,i);break;default:throw Error(X(161))}}catch(l){mt(e,e.return,l)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function EW(e,t,n){te=e,bM(e)}function bM(e,t,n){for(var r=(e.mode&1)!==0;te!==null;){var s=te,o=s.child;if(s.tag===22&&r){var i=s.memoizedState!==null||Vd;if(!i){var a=s.alternate,l=a!==null&&a.memoizedState!==null||an;a=Vd;var c=an;if(Vd=i,(an=l)&&!c)for(te=s;te!==null;)i=te,l=i.child,i.tag===22&&i.memoizedState!==null?MC(s):l!==null?(l.return=i,te=l):MC(s);for(;o!==null;)te=o,bM(o),o=o.sibling;te=s,Vd=a,an=c}_C(e)}else s.subtreeFlags&8772&&o!==null?(o.return=s,te=o):_C(e)}}function _C(e){for(;te!==null;){var t=te;if(t.flags&8772){var n=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:an||og(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!an)if(n===null)r.componentDidMount();else{var s=t.elementType===t.type?n.memoizedProps:Rr(t.type,n.memoizedProps);r.componentDidUpdate(s,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var o=t.updateQueue;o!==null&&hC(t,o,r);break;case 3:var i=t.updateQueue;if(i!==null){if(n=null,t.child!==null)switch(t.child.tag){case 5:n=t.child.stateNode;break;case 1:n=t.child.stateNode}hC(t,i,n)}break;case 5:var a=t.stateNode;if(n===null&&t.flags&4){n=a;var l=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":l.autoFocus&&n.focus();break;case"img":l.src&&(n.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var c=t.alternate;if(c!==null){var u=c.memoizedState;if(u!==null){var h=u.dehydrated;h!==null&&pu(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(X(163))}an||t.flags&512&&Sv(t)}catch(p){mt(t,t.return,p)}}if(t===e){te=null;break}if(n=t.sibling,n!==null){n.return=t.return,te=n;break}te=t.return}}function TC(e){for(;te!==null;){var t=te;if(t===e){te=null;break}var n=t.sibling;if(n!==null){n.return=t.return,te=n;break}te=t.return}}function MC(e){for(;te!==null;){var t=te;try{switch(t.tag){case 0:case 11:case 15:var n=t.return;try{og(4,t)}catch(l){mt(t,n,l)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var s=t.return;try{r.componentDidMount()}catch(l){mt(t,s,l)}}var o=t.return;try{Sv(t)}catch(l){mt(t,o,l)}break;case 5:var i=t.return;try{Sv(t)}catch(l){mt(t,i,l)}}}catch(l){mt(t,t.return,l)}if(t===e){te=null;break}var a=t.sibling;if(a!==null){a.return=t.return,te=a;break}te=t.return}}var kW=Math.ceil,uf=co.ReactCurrentDispatcher,U0=co.ReactCurrentOwner,Er=co.ReactCurrentBatchConfig,Ae=0,Dt=null,Ct=null,Gt=0,Jn=0,Ba=li(0),Et=0,Cu=null,Ki=0,ig=0,H0=0,Yc=null,Rn=null,K0=0,fl=1/0,Ns=null,df=!1,wv=null,Ko=null,Yd=!1,jo=null,hf=0,Xc=0,bv=null,zh=-1,Bh=0;function vn(){return Ae&6?wt():zh!==-1?zh:zh=wt()}function Wo(e){return e.mode&1?Ae&2&&Gt!==0?Gt&-Gt:uW.transition!==null?(Bh===0&&(Bh=iT()),Bh):(e=Ne,e!==0||(e=window.event,e=e===void 0?16:pT(e.type)),e):1}function Kr(e,t,n,r){if(50<Xc)throw Xc=0,bv=null,Error(X(185));Xu(e,n,r),(!(Ae&2)||e!==Dt)&&(e===Dt&&(!(Ae&2)&&(ig|=n),Et===4&&To(e,Gt)),Wn(e,r),n===1&&Ae===0&&!(t.mode&1)&&(fl=wt()+500,ng&&ci()))}function Wn(e,t){var n=e.callbackNode;uK(e,t);var r=Yp(e,e===Dt?Gt:0);if(r===0)n!==null&&FP(n),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(n!=null&&FP(n),t===1)e.tag===0?cW(AC.bind(null,e)):jT(AC.bind(null,e)),oW(function(){!(Ae&6)&&ci()}),n=null;else{switch(aT(r)){case 1:n=m0;break;case 4:n=sT;break;case 16:n=Vp;break;case 536870912:n=oT;break;default:n=Vp}n=MM(n,PM.bind(null,e))}e.callbackPriority=t,e.callbackNode=n}}function PM(e,t){if(zh=-1,Bh=0,Ae&6)throw Error(X(327));var n=e.callbackNode;if(el()&&e.callbackNode!==n)return null;var r=Yp(e,e===Dt?Gt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=pf(e,r);else{t=r;var s=Ae;Ae|=2;var o=IM();(Dt!==e||Gt!==t)&&(Ns=null,fl=wt()+500,Oi(e,t));do try{MW();break}catch(a){CM(e,a)}while(!0);T0(),uf.current=o,Ae=s,Ct!==null?t=0:(Dt=null,Gt=0,t=Et)}if(t!==0){if(t===2&&(s=XS(e),s!==0&&(r=s,t=Pv(e,s))),t===1)throw n=Cu,Oi(e,0),To(e,r),Wn(e,wt()),n;if(t===6)To(e,r);else{if(s=e.current.alternate,!(r&30)&&!_W(s)&&(t=pf(e,r),t===2&&(o=XS(e),o!==0&&(r=o,t=Pv(e,o))),t===1))throw n=Cu,Oi(e,0),To(e,r),Wn(e,wt()),n;switch(e.finishedWork=s,e.finishedLanes=r,t){case 0:case 1:throw Error(X(345));case 2:Pi(e,Rn,Ns);break;case 3:if(To(e,r),(r&130023424)===r&&(t=K0+500-wt(),10<t)){if(Yp(e,0)!==0)break;if(s=e.suspendedLanes,(s&r)!==r){vn(),e.pingedLanes|=e.suspendedLanes&s;break}e.timeoutHandle=rv(Pi.bind(null,e,Rn,Ns),t);break}Pi(e,Rn,Ns);break;case 4:if(To(e,r),(r&4194240)===r)break;for(t=e.eventTimes,s=-1;0<r;){var i=31-Hr(r);o=1<<i,i=t[i],i>s&&(s=i),r&=~o}if(r=s,r=wt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*kW(r/1960))-r,10<r){e.timeoutHandle=rv(Pi.bind(null,e,Rn,Ns),r);break}Pi(e,Rn,Ns);break;case 5:Pi(e,Rn,Ns);break;default:throw Error(X(329))}}}return Wn(e,wt()),e.callbackNode===n?PM.bind(null,e):null}function Pv(e,t){var n=Yc;return e.current.memoizedState.isDehydrated&&(Oi(e,t).flags|=256),e=pf(e,t),e!==2&&(t=Rn,Rn=n,t!==null&&Cv(t)),e}function Cv(e){Rn===null?Rn=e:Rn.push.apply(Rn,e)}function _W(e){for(var t=e;;){if(t.flags&16384){var n=t.updateQueue;if(n!==null&&(n=n.stores,n!==null))for(var r=0;r<n.length;r++){var s=n[r],o=s.getSnapshot;s=s.value;try{if(!Vr(o(),s))return!1}catch{return!1}}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function To(e,t){for(t&=~H0,t&=~ig,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var n=31-Hr(t),r=1<<n;e[n]=-1,t&=~r}}function AC(e){if(Ae&6)throw Error(X(327));el();var t=Yp(e,0);if(!(t&1))return Wn(e,wt()),null;var n=pf(e,t);if(e.tag!==0&&n===2){var r=XS(e);r!==0&&(t=r,n=Pv(e,r))}if(n===1)throw n=Cu,Oi(e,0),To(e,t),Wn(e,wt()),n;if(n===6)throw Error(X(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Pi(e,Rn,Ns),Wn(e,wt()),null}function W0(e,t){var n=Ae;Ae|=1;try{return e(t)}finally{Ae=n,Ae===0&&(fl=wt()+500,ng&&ci())}}function Wi(e){jo!==null&&jo.tag===0&&!(Ae&6)&&el();var t=Ae;Ae|=1;var n=Er.transition,r=Ne;try{if(Er.transition=null,Ne=1,e)return e()}finally{Ne=r,Er.transition=n,Ae=t,!(Ae&6)&&ci()}}function G0(){Jn=Ba.current,tt(Ba)}function Oi(e,t){e.finishedWork=null,e.finishedLanes=0;var n=e.timeoutHandle;if(n!==-1&&(e.timeoutHandle=-1,sW(n)),Ct!==null)for(n=Ct.return;n!==null;){var r=n;switch(E0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Jp();break;case 3:hl(),tt(Hn),tt(hn),R0();break;case 5:D0(r);break;case 4:hl();break;case 13:tt(lt);break;case 19:tt(lt);break;case 10:M0(r.type._context);break;case 22:case 23:G0()}n=n.return}if(Dt=e,Ct=e=Go(e.current,null),Gt=Jn=t,Et=0,Cu=null,H0=ig=Ki=0,Rn=Yc=null,ki!==null){for(t=0;t<ki.length;t++)if(n=ki[t],r=n.interleaved,r!==null){n.interleaved=null;var s=r.next,o=n.pending;if(o!==null){var i=o.next;o.next=s,r.next=i}n.pending=r}ki=null}return e}function CM(e,t){do{var n=Ct;try{if(T0(),$h.current=cf,lf){for(var r=ht.memoizedState;r!==null;){var s=r.queue;s!==null&&(s.pending=null),r=r.next}lf=!1}if(Hi=0,Tt=It=ht=null,Gc=!1,wu=0,U0.current=null,n===null||n.return===null){Et=1,Cu=t,Ct=null;break}e:{var o=e,i=n.return,a=n,l=t;if(t=Gt,a.flags|=32768,l!==null&&typeof l=="object"&&typeof l.then=="function"){var c=l,u=a,h=u.tag;if(!(u.mode&1)&&(h===0||h===11||h===15)){var p=u.alternate;p?(u.updateQueue=p.updateQueue,u.memoizedState=p.memoizedState,u.lanes=p.lanes):(u.updateQueue=null,u.memoizedState=null)}var f=SC(i);if(f!==null){f.flags&=-257,vC(f,i,a,o,t),f.mode&1&&yC(o,c,t),t=f,l=c;var S=t.updateQueue;if(S===null){var y=new Set;y.add(l),t.updateQueue=y}else S.add(l);break e}else{if(!(t&1)){yC(o,c,t),V0();break e}l=Error(X(426))}}else if(st&&a.mode&1){var x=SC(i);if(x!==null){!(x.flags&65536)&&(x.flags|=256),vC(x,i,a,o,t),k0(pl(l,a));break e}}o=l=pl(l,a),Et!==4&&(Et=2),Yc===null?Yc=[o]:Yc.push(o),o=i;do{switch(o.tag){case 3:o.flags|=65536,t&=-t,o.lanes|=t;var m=aM(o,l,t);dC(o,m);break e;case 1:a=l;var v=o.type,w=o.stateNode;if(!(o.flags&128)&&(typeof v.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(Ko===null||!Ko.has(w)))){o.flags|=65536,t&=-t,o.lanes|=t;var C=lM(o,a,t);dC(o,C);break e}}o=o.return}while(o!==null)}kM(n)}catch(E){t=E,Ct===n&&n!==null&&(Ct=n=n.return);continue}break}while(!0)}function IM(){var e=uf.current;return uf.current=cf,e===null?cf:e}function V0(){(Et===0||Et===3||Et===2)&&(Et=4),Dt===null||!(Ki&268435455)&&!(ig&268435455)||To(Dt,Gt)}function pf(e,t){var n=Ae;Ae|=2;var r=IM();(Dt!==e||Gt!==t)&&(Ns=null,Oi(e,t));do try{TW();break}catch(s){CM(e,s)}while(!0);if(T0(),Ae=n,uf.current=r,Ct!==null)throw Error(X(261));return Dt=null,Gt=0,Et}function TW(){for(;Ct!==null;)EM(Ct)}function MW(){for(;Ct!==null&&!tK();)EM(Ct)}function EM(e){var t=TM(e.alternate,e,Jn);e.memoizedProps=e.pendingProps,t===null?kM(e):Ct=t,U0.current=null}function kM(e){var t=e;do{var n=t.alternate;if(e=t.return,t.flags&32768){if(n=PW(n,t),n!==null){n.flags&=32767,Ct=n;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Et=6,Ct=null;return}}else if(n=bW(n,t,Jn),n!==null){Ct=n;return}if(t=t.sibling,t!==null){Ct=t;return}Ct=t=e}while(t!==null);Et===0&&(Et=5)}function Pi(e,t,n){var r=Ne,s=Er.transition;try{Er.transition=null,Ne=1,AW(e,t,n,r)}finally{Er.transition=s,Ne=r}return null}function AW(e,t,n,r){do el();while(jo!==null);if(Ae&6)throw Error(X(327));n=e.finishedWork;var s=e.finishedLanes;if(n===null)return null;if(e.finishedWork=null,e.finishedLanes=0,n===e.current)throw Error(X(177));e.callbackNode=null,e.callbackPriority=0;var o=n.lanes|n.childLanes;if(dK(e,o),e===Dt&&(Ct=Dt=null,Gt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||Yd||(Yd=!0,MM(Vp,function(){return el(),null})),o=(n.flags&15990)!==0,n.subtreeFlags&15990||o){o=Er.transition,Er.transition=null;var i=Ne;Ne=1;var a=Ae;Ae|=4,U0.current=null,IW(e,n),wM(n,e),ZK(tv),Xp=!!ev,tv=ev=null,e.current=n,EW(n),nK(),Ae=a,Ne=i,Er.transition=o}else e.current=n;if(Yd&&(Yd=!1,jo=e,hf=s),o=e.pendingLanes,o===0&&(Ko=null),oK(n.stateNode),Wn(e,wt()),t!==null)for(r=e.onRecoverableError,n=0;n<t.length;n++)s=t[n],r(s.value,{componentStack:s.stack,digest:s.digest});if(df)throw df=!1,e=wv,wv=null,e;return hf&1&&e.tag!==0&&el(),o=e.pendingLanes,o&1?e===bv?Xc++:(Xc=0,bv=e):Xc=0,ci(),null}function el(){if(jo!==null){var e=aT(hf),t=Er.transition,n=Ne;try{if(Er.transition=null,Ne=16>e?16:e,jo===null)var r=!1;else{if(e=jo,jo=null,hf=0,Ae&6)throw Error(X(331));var s=Ae;for(Ae|=4,te=e.current;te!==null;){var o=te,i=o.child;if(te.flags&16){var a=o.deletions;if(a!==null){for(var l=0;l<a.length;l++){var c=a[l];for(te=c;te!==null;){var u=te;switch(u.tag){case 0:case 11:case 15:Vc(8,u,o)}var h=u.child;if(h!==null)h.return=u,te=h;else for(;te!==null;){u=te;var p=u.sibling,f=u.return;if(SM(u),u===c){te=null;break}if(p!==null){p.return=f,te=p;break}te=f}}}var S=o.alternate;if(S!==null){var y=S.child;if(y!==null){S.child=null;do{var x=y.sibling;y.sibling=null,y=x}while(y!==null)}}te=o}}if(o.subtreeFlags&2064&&i!==null)i.return=o,te=i;else e:for(;te!==null;){if(o=te,o.flags&2048)switch(o.tag){case 0:case 11:case 15:Vc(9,o,o.return)}var m=o.sibling;if(m!==null){m.return=o.return,te=m;break e}te=o.return}}var v=e.current;for(te=v;te!==null;){i=te;var w=i.child;if(i.subtreeFlags&2064&&w!==null)w.return=i,te=w;else e:for(i=v;te!==null;){if(a=te,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:og(9,a)}}catch(E){mt(a,a.return,E)}if(a===i){te=null;break e}var C=a.sibling;if(C!==null){C.return=a.return,te=C;break e}te=a.return}}if(Ae=s,ci(),ys&&typeof ys.onPostCommitFiberRoot=="function")try{ys.onPostCommitFiberRoot(Zf,e)}catch{}r=!0}return r}finally{Ne=n,Er.transition=t}}return!1}function jC(e,t,n){t=pl(n,t),t=aM(e,t,1),e=Ho(e,t,1),t=vn(),e!==null&&(Xu(e,1,t),Wn(e,t))}function mt(e,t,n){if(e.tag===3)jC(e,e,n);else for(;t!==null;){if(t.tag===3){jC(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Ko===null||!Ko.has(r))){e=pl(n,e),e=lM(t,e,1),t=Ho(t,e,1),e=vn(),t!==null&&(Xu(t,1,e),Wn(t,e));break}}t=t.return}}function jW(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),t=vn(),e.pingedLanes|=e.suspendedLanes&n,Dt===e&&(Gt&n)===n&&(Et===4||Et===3&&(Gt&130023424)===Gt&&500>wt()-K0?Oi(e,0):H0|=n),Wn(e,t)}function _M(e,t){t===0&&(e.mode&1?(t=Nd,Nd<<=1,!(Nd&130023424)&&(Nd=4194304)):t=1);var n=vn();e=to(e,t),e!==null&&(Xu(e,t,n),Wn(e,n))}function OW(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),_M(e,n)}function DW(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,s=e.memoizedState;s!==null&&(n=s.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(X(314))}r!==null&&r.delete(t),_M(e,n)}var TM;TM=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Hn.current)Fn=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Fn=!1,wW(e,t,n);Fn=!!(e.flags&131072)}else Fn=!1,st&&t.flags&1048576&&OT(t,nf,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Fh(e,t),e=t.pendingProps;var s=cl(t,hn.current);Ja(t,n),s=$0(null,t,r,e,s,n);var o=N0();return t.flags|=1,typeof s=="object"&&s!==null&&typeof s.render=="function"&&s.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Kn(r)?(o=!0,ef(t)):o=!1,t.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,j0(t),s.updater=sg,t.stateNode=s,s._reactInternals=t,uv(t,r,e,n),t=pv(null,t,r,!0,o,n)):(t.tag=0,st&&o&&I0(t),mn(null,t,s,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Fh(e,t),e=t.pendingProps,s=r._init,r=s(r._payload),t.type=r,s=t.tag=LW(r),e=Rr(r,e),s){case 0:t=hv(null,t,r,e,n);break e;case 1:t=bC(null,t,r,e,n);break e;case 11:t=xC(null,t,r,e,n);break e;case 14:t=wC(null,t,r,Rr(r.type,e),n);break e}throw Error(X(306,r,""))}return t;case 0:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Rr(r,s),hv(e,t,r,s,n);case 1:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Rr(r,s),bC(e,t,r,s,n);case 3:e:{if(hM(t),e===null)throw Error(X(387));r=t.pendingProps,o=t.memoizedState,s=o.element,FT(e,t),of(t,r,null,n);var i=t.memoizedState;if(r=i.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){s=pl(Error(X(423)),t),t=PC(e,t,r,n,s);break e}else if(r!==s){s=pl(Error(X(424)),t),t=PC(e,t,r,n,s);break e}else for(nr=Uo(t.stateNode.containerInfo.firstChild),ir=t,st=!0,Fr=null,n=$T(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(ul(),r===s){t=no(e,t,n);break e}mn(e,t,r,n)}t=t.child}return t;case 5:return zT(t),e===null&&av(t),r=t.type,s=t.pendingProps,o=e!==null?e.memoizedProps:null,i=s.children,nv(r,s)?i=null:o!==null&&nv(r,o)&&(t.flags|=32),dM(e,t),mn(e,t,i,n),t.child;case 6:return e===null&&av(t),null;case 13:return pM(e,t,n);case 4:return O0(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=dl(t,null,r,n):mn(e,t,r,n),t.child;case 11:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Rr(r,s),xC(e,t,r,s,n);case 7:return mn(e,t,t.pendingProps,n),t.child;case 8:return mn(e,t,t.pendingProps.children,n),t.child;case 12:return mn(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,s=t.pendingProps,o=t.memoizedProps,i=s.value,Ye(rf,r._currentValue),r._currentValue=i,o!==null)if(Vr(o.value,i)){if(o.children===s.children&&!Hn.current){t=no(e,t,n);break e}}else for(o=t.child,o!==null&&(o.return=t);o!==null;){var a=o.dependencies;if(a!==null){i=o.child;for(var l=a.firstContext;l!==null;){if(l.context===r){if(o.tag===1){l=Vs(-1,n&-n),l.tag=2;var c=o.updateQueue;if(c!==null){c=c.shared;var u=c.pending;u===null?l.next=l:(l.next=u.next,u.next=l),c.pending=l}}o.lanes|=n,l=o.alternate,l!==null&&(l.lanes|=n),lv(o.return,n,t),a.lanes|=n;break}l=l.next}}else if(o.tag===10)i=o.type===t.type?null:o.child;else if(o.tag===18){if(i=o.return,i===null)throw Error(X(341));i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),lv(i,n,t),i=o.sibling}else i=o.child;if(i!==null)i.return=o;else for(i=o;i!==null;){if(i===t){i=null;break}if(o=i.sibling,o!==null){o.return=i.return,i=o;break}i=i.return}o=i}mn(e,t,s.children,n),t=t.child}return t;case 9:return s=t.type,r=t.pendingProps.children,Ja(t,n),s=_r(s),r=r(s),t.flags|=1,mn(e,t,r,n),t.child;case 14:return r=t.type,s=Rr(r,t.pendingProps),s=Rr(r.type,s),wC(e,t,r,s,n);case 15:return cM(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Rr(r,s),Fh(e,t),t.tag=1,Kn(r)?(e=!0,ef(t)):e=!1,Ja(t,n),iM(t,r,s),uv(t,r,s,n),pv(null,t,r,!0,e,n);case 19:return fM(e,t,n);case 22:return uM(e,t,n)}throw Error(X(156,t.tag))};function MM(e,t){return rT(e,t)}function RW(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Cr(e,t,n,r){return new RW(e,t,n,r)}function Y0(e){return e=e.prototype,!(!e||!e.isReactComponent)}function LW(e){if(typeof e=="function")return Y0(e)?1:0;if(e!=null){if(e=e.$$typeof,e===p0)return 11;if(e===f0)return 14}return 2}function Go(e,t){var n=e.alternate;return n===null?(n=Cr(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Uh(e,t,n,r,s,o){var i=2;if(r=e,typeof e=="function")Y0(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case Aa:return Di(n.children,s,o,t);case h0:i=8,s|=8;break;case DS:return e=Cr(12,n,t,s|2),e.elementType=DS,e.lanes=o,e;case RS:return e=Cr(13,n,t,s),e.elementType=RS,e.lanes=o,e;case LS:return e=Cr(19,n,t,s),e.elementType=LS,e.lanes=o,e;case z2:return ag(n,s,o,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case N2:i=10;break e;case F2:i=9;break e;case p0:i=11;break e;case f0:i=14;break e;case Io:i=16,r=null;break e}throw Error(X(130,e==null?e:typeof e,""))}return t=Cr(i,n,t,s),t.elementType=e,t.type=r,t.lanes=o,t}function Di(e,t,n,r){return e=Cr(7,e,r,t),e.lanes=n,e}function ag(e,t,n,r){return e=Cr(22,e,r,t),e.elementType=z2,e.lanes=n,e.stateNode={isHidden:!1},e}function ny(e,t,n){return e=Cr(6,e,null,t),e.lanes=n,e}function ry(e,t,n){return t=Cr(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function $W(e,t,n,r,s){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=$m(0),this.expirationTimes=$m(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=$m(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function X0(e,t,n,r,s,o,i,a,l){return e=new $W(e,t,n,a,l),t===1?(t=1,o===!0&&(t|=8)):t=0,o=Cr(3,null,null,t),e.current=o,o.stateNode=e,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},j0(o),e}function NW(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Ma,key:r==null?null:""+r,children:e,containerInfo:t,implementation:n}}function AM(e){if(!e)return qo;e=e._reactInternals;e:{if(oa(e)!==e||e.tag!==1)throw Error(X(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(Kn(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(X(171))}if(e.tag===1){var n=e.type;if(Kn(n))return AT(e,n,t)}return t}function jM(e,t,n,r,s,o,i,a,l){return e=X0(n,r,!0,e,s,o,i,a,l),e.context=AM(null),n=e.current,r=vn(),s=Wo(n),o=Vs(r,s),o.callback=t??null,Ho(n,o,s),e.current.lanes=s,Xu(e,s,r),Wn(e,r),e}function lg(e,t,n,r){var s=t.current,o=vn(),i=Wo(s);return n=AM(n),t.context===null?t.context=n:t.pendingContext=n,t=Vs(o,i),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=Ho(s,t,i),e!==null&&(Kr(e,s,i,o),Lh(e,s,i)),i}function ff(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function OC(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function q0(e,t){OC(e,t),(e=e.alternate)&&OC(e,t)}function FW(){return null}var OM=typeof reportError=="function"?reportError:function(e){console.error(e)};function Z0(e){this._internalRoot=e}cg.prototype.render=Z0.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(X(409));lg(e,t,null,null)};cg.prototype.unmount=Z0.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Wi(function(){lg(null,e,null,null)}),t[eo]=null}};function cg(e){this._internalRoot=e}cg.prototype.unstable_scheduleHydration=function(e){if(e){var t=uT();e={blockedOn:null,target:e,priority:t};for(var n=0;n<_o.length&&t!==0&&t<_o[n].priority;n++);_o.splice(n,0,e),n===0&&hT(e)}};function Q0(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function ug(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function DC(){}function zW(e,t,n,r,s){if(s){if(typeof r=="function"){var o=r;r=function(){var c=ff(i);o.call(c)}}var i=jM(t,r,e,0,null,!1,!1,"",DC);return e._reactRootContainer=i,e[eo]=i.current,mu(e.nodeType===8?e.parentNode:e),Wi(),i}for(;s=e.lastChild;)e.removeChild(s);if(typeof r=="function"){var a=r;r=function(){var c=ff(l);a.call(c)}}var l=X0(e,0,!1,null,null,!1,!1,"",DC);return e._reactRootContainer=l,e[eo]=l.current,mu(e.nodeType===8?e.parentNode:e),Wi(function(){lg(t,l,n,r)}),l}function dg(e,t,n,r,s){var o=n._reactRootContainer;if(o){var i=o;if(typeof s=="function"){var a=s;s=function(){var l=ff(i);a.call(l)}}lg(t,i,e,s)}else i=zW(n,t,e,s,r);return ff(i)}lT=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var n=wc(t.pendingLanes);n!==0&&(y0(t,n|1),Wn(t,wt()),!(Ae&6)&&(fl=wt()+500,ci()))}break;case 13:Wi(function(){var r=to(e,1);if(r!==null){var s=vn();Kr(r,e,1,s)}}),q0(e,1)}};S0=function(e){if(e.tag===13){var t=to(e,134217728);if(t!==null){var n=vn();Kr(t,e,134217728,n)}q0(e,134217728)}};cT=function(e){if(e.tag===13){var t=Wo(e),n=to(e,t);if(n!==null){var r=vn();Kr(n,e,t,r)}q0(e,t)}};uT=function(){return Ne};dT=function(e,t){var n=Ne;try{return Ne=e,t()}finally{Ne=n}};GS=function(e,t,n){switch(t){case"input":if(FS(e,n),t=n.name,n.type==="radio"&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll("input[name="+JSON.stringify(""+t)+'][type="radio"]'),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var s=tg(r);if(!s)throw Error(X(90));U2(r),FS(r,s)}}}break;case"textarea":K2(e,n);break;case"select":t=n.value,t!=null&&Xa(e,!!n.multiple,t,!1)}};Z2=W0;Q2=Wi;var BW={usingClientEntryPoint:!1,Events:[Zu,Ra,tg,X2,q2,W0]},ic={findFiberByHostInstance:Ei,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},UW={bundleType:ic.bundleType,version:ic.version,rendererPackageName:ic.rendererPackageName,rendererConfig:ic.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:co.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=tT(e),e===null?null:e.stateNode},findFiberByHostInstance:ic.findFiberByHostInstance||FW,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Xd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Xd.isDisabled&&Xd.supportsFiber)try{Zf=Xd.inject(UW),ys=Xd}catch{}}hr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=BW;hr.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Q0(t))throw Error(X(200));return NW(e,t,null,n)};hr.createRoot=function(e,t){if(!Q0(e))throw Error(X(299));var n=!1,r="",s=OM;return t!=null&&(t.unstable_strictMode===!0&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(s=t.onRecoverableError)),t=X0(e,1,!1,null,null,n,!1,r,s),e[eo]=t.current,mu(e.nodeType===8?e.parentNode:e),new Z0(t)};hr.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(X(188)):(e=Object.keys(e).join(","),Error(X(268,e)));return e=tT(t),e=e===null?null:e.stateNode,e};hr.flushSync=function(e){return Wi(e)};hr.hydrate=function(e,t,n){if(!ug(t))throw Error(X(200));return dg(null,e,t,!0,n)};hr.hydrateRoot=function(e,t,n){if(!Q0(e))throw Error(X(405));var r=n!=null&&n.hydratedSources||null,s=!1,o="",i=OM;if(n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(o=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),t=jM(t,null,e,1,n??null,s,!1,o,i),e[eo]=t.current,mu(e),r)for(e=0;e<r.length;e++)n=r[e],s=n._getVersion,s=s(n._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[n,s]:t.mutableSourceEagerHydrationData.push(n,s);return new cg(t)};hr.render=function(e,t,n){if(!ug(t))throw Error(X(200));return dg(null,e,t,!1,n)};hr.unmountComponentAtNode=function(e){if(!ug(e))throw Error(X(40));return e._reactRootContainer?(Wi(function(){dg(null,null,e,!1,function(){e._reactRootContainer=null,e[eo]=null})}),!0):!1};hr.unstable_batchedUpdates=W0;hr.unstable_renderSubtreeIntoContainer=function(e,t,n,r){if(!ug(n))throw Error(X(200));if(e==null||e._reactInternals===void 0)throw Error(X(38));return dg(e,t,n,!1,r)};hr.version="18.3.1-next-f1338f8080-20240426";function DM(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(DM)}catch(e){console.error(e)}}DM(),D2.exports=hr;var ia=D2.exports;const HW=ni(ia);var Iv={},RM,RC=ia;RM=Iv.createRoot=RC.createRoot,Iv.hydrateRoot=RC.hydrateRoot;const tl="TLDRAW_TAB_ID_v2",vs=globalThis.window;function KW(){return vs?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(vs.navigator.platform)||vs.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const gf=vs?vs[tl]??Qk(tl)??"TLDRAW_INSTANCE_STATE_V1_"+ct():"<error>";vs&&(vs[tl]=gf,KW()?Kx(tl,gf):Jk(tl));vs==null||vs.addEventListener("beforeunload",()=>{Kx(tl,gf)});const LM={Initial:0},hg=Math.max(...Object.values(LM));function WW(e){e.version<LM.Initial,e.version=hg}const $M=xe({version:he,currentPageId:ou,isFocusMode:Se,exportBackground:Se,isDebugMode:Se,isToolLocked:Se,isGridMode:Se,pageStates:Ht(xe({pageId:ou,camera:xe({x:he,y:he,z:he}),selectedShapeIds:Ht(Sr),focusedGroupId:Sr.nullable()}))});function GW(e){if(!e||typeof e!="object")return console.warn("Invalid instance state"),null;if(!("version"in e)||typeof e.version!="number")return console.warn("No version in instance state"),null;e.version!==hg&&(e=Ge(e),WW(e));try{return $M.validate(e)}catch(t){return console.warn(t),null}}function NM(e){const t=e.query.ids("page");return G("sessionStateSnapshot",()=>{const n=e.get(Sn);if(!n)return null;const r=[...t.get()];return{version:hg,currentPageId:n.currentPageId,exportBackground:n.exportBackground,isFocusMode:n.isFocusMode,isDebugMode:n.isDebugMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,pageStates:r.map(s=>{const o=e.get(Br.createId(s)),i=e.get(hs.createId(s));return{pageId:s,camera:{x:(i==null?void 0:i.x)??0,y:(i==null?void 0:i.y)??0,z:(i==null?void 0:i.z)??1},selectedShapeIds:(o==null?void 0:o.selectedShapeIds)??[],focusedGroupId:(o==null?void 0:o.focusedGroupId)??null}})}})}function FM(e,t){const n=GW(t);if(!n)return;const r=e.schema.types.instance.create({id:Sn,...b_(e.get(Sn)),currentPageId:n.currentPageId,isDebugMode:n.isDebugMode,isFocusMode:n.isFocusMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,exportBackground:n.exportBackground}),s=e.allRecords().filter(o=>o.typeName==="instance_page_state"||o.typeName==="camera");e.atomic(()=>{e.remove(s.map(o=>o.id));for(const o of n.pageStates)e.put([hs.create({id:hs.createId(o.pageId),x:o.camera.x,y:o.camera.y,z:o.camera.z}),Br.create({id:Br.createId(o.pageId),pageId:o.pageId,selectedShapeIds:o.selectedShapeIds,focusedGroupId:o.focusedGroupId})]);e.put([r]),e.ensureStoreIsUsable()})}function VW(e){var s;const t=[];for(const o of Object.values(e))(s=o.typeName)!=null&&s.match(/^(instance.*|pointer|camera)$/)&&t.push(o);const n=t.filter(o=>o.typeName==="instance"&&o.id!==Sn)[0];if(!n)return null;const r={version:hg,currentPageId:n.currentPageId,exportBackground:!!n.exportBackground,isFocusMode:!!n.isFocusMode,isDebugMode:!!n.isDebugMode,isToolLocked:!!n.isToolLocked,isGridMode:!1,pageStates:t.filter(o=>o.typeName==="instance_page_state"&&o.instanceId===n.id).map(o=>{const i=e[o.cameraId]??{x:0,y:0,z:1};return{pageId:o.pageId,camera:{x:i.x,y:i.y,z:i.z},selectedShapeIds:o.selectedShapeIds,focusedGroupId:o.focusedGroupId}})};try{return $M.validate(r),r}catch{return null}}function zM(e,t){let n={};if("store"in t){const s=e.schema.migrateStoreSnapshot(t);if(s.type!=="success")throw new Error("Failed to migrate store snapshot: "+s.reason);n.document={schema:e.schema.serialize(),store:$c(s.value,(o,{typeName:i})=>e.scopedTypes.document.has(i))}}else n=t;const r=b_(e.get(Sn));e.atomic(()=>{n.document&&e.loadStoreSnapshot(n.document),r&&e.update(Sn,s=>({...s,...r})),n.session&&FM(e,n.session)})}const YW=new Zs;function XW(e){const n=YW.get(e,NM).get();if(!n)throw new Error("Session state is not ready yet");return{document:e.getStoreSnapshot(),session:n}}function BM(e){const t=[],n=new Set;for(const r of e){if(n.has(r.type))throw new Error(`Binding type "${r.type}" is defined more than once`);t.push(r),n.add(r.type)}return t}function Zo({children:e,className:t="",...n}){return d.jsx("svg",{...n,className:ce("tl-svg-container",t),children:e})}function J0(e,t,n,r){const s=e.x-n.x,o=e.y-n.y,i=r.x-n.x,a=r.y-n.y,l=t.x-e.x,c=t.y-e.y,u=i*o-a*s,h=l*o-c*s,p=a*l-i*c;if(u===0||h===0||p===0)return null;if(p!==0){const f=u/p,S=h/p;if(0<=f&&f<=1&&0<=S&&S<=1)return b.AddXY(e,f*l,f*c)}return null}function Ju(e,t,n,r){const s=(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y),o=2*((t.x-e.x)*(e.x-n.x)+(t.y-e.y)*(e.y-n.y)),i=n.x*n.x+n.y*n.y+e.x*e.x+e.y*e.y-2*(n.x*e.x+n.y*e.y)-r*r,a=o*o-4*s*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-o+l)/(2*s),u=(-o-l)/(2*s);if((c<0||c>1)&&(u<0||u>1))return null;const h=[];return 0<=c&&c<=1&&h.push(b.Lrp(e,t,c)),0<=u&&u<=1&&h.push(b.Lrp(e,t,u)),h.length===0?null:h}function qW(e,t,n){const r=[];let s;for(let o=0,i=n.length-1;o<i;o++)s=J0(e,t,n[o],n[o+1]),s&&r.push(s);return r.length===0?null:r}function ew(e,t,n){const r=[];let s;for(let o=1,i=n.length;o<i+1;o++)s=J0(e,t,n[o-1],n[o%n.length]),s&&r.push(s);return r.length===0?null:r}function ZW(e,t,n,r){let s=n.x-e.x,o=n.y-e.y;const i=Math.sqrt(s*s+o*o),a=(i*i-r*r+t*t)/(2*i),l=Math.sqrt(t*t-a*a);return s/=i,o/=i,[new b(e.x+s*a-o*l,e.y+o*a+s*l),new b(e.x+s*a+o*l,e.y+o*a-s*l)]}function Ev(e,t,n){const r=[];let s,o,i;for(let a=0,l=n.length;a<l;a++)s=n[a],o=n[(a+1)%n.length],i=Ju(s,o,e,t),i&&r.push(...i);return r.length===0?null:r}function LC(e,t,n){const r=[];let s,o,i;for(let a=1,l=n.length;a<l;a++)s=n[a-1],o=n[a],i=Ju(s,o,e,t),i&&r.push(...i);return r.length===0?null:r}function qd(e,t,n){return(n.y-e.y)*(t.x-e.x)>(t.y-e.y)*(n.x-e.x)}function tw(e,t,n,r){return qd(e,n,r)!==qd(t,n,r)&&qd(e,t,n)!==qd(e,t,r)}function $C(e,t){const n=new Map;let r,s,o,i;for(let a=0,l=e.length;a<l;a++)if(r=e[a],or(r,t)){const c=sy(r);n.has(c)||n.set(c,r)}for(let a=0,l=t.length;a<l;a++)if(r=t[a],or(r,e)){const c=sy(r);n.has(c)||n.set(c,r)}for(let a=0,l=e.length;a<l;a++){r=e[a],s=e[(a+1)%e.length];for(let c=0,u=t.length;c<u;c++){o=t[c],i=t[(c+1)%t.length];const h=J0(r,s,o,i);if(h!==null){const p=sy(h);n.has(p)||n.set(p,h)}}}return n.size===0?null:QW([...n.values()])}function sy(e){return`${e.x},${e.y}`}function QW(e){const t=b.Average(e);return e.sort((n,r)=>b.Angle(t,n)-b.Angle(t,r))}function UM(e,t){let n,r,s,o;for(let i=0,a=e.length;i<a;i++){n=e[i],r=e[(i+1)%a];for(let l=0,c=t.length;l<c;l++)if(s=t[l],o=t[(l+1)%c],tw(n,r,s,o))return!0}return!1}function JW(e,t){let n,r,s,o;for(let i=0,a=e.length;i<a;i++){n=e[i],r=e[(i+1)%a];for(let l=1,c=t.length;l<c;l++)if(s=t[l-1],o=t[l],tw(n,r,s,o))return!0}return!1}class Ks extends ii{constructor(n){super({...n,isClosed:!1,isFilled:!1});g(this,"start");g(this,"end");g(this,"d");g(this,"u");g(this,"ul");const{start:r,end:s}=n;this.start=r,this.end=s,this.d=r.clone().sub(s),this.u=this.d.clone().uni(),this.ul=this.u.len()}getLength(){return this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(n){const{start:r,end:s,u:o,ul:i}=this;if(i===0)return r;const a=b.Sub(n,r).dpr(o)/i,l=r.x+o.x*a;if(l<Math.min(r.x,s.x))return r.x<s.x?r:s;if(l>Math.max(r.x,s.x))return r.x>s.x?r:s;const c=r.y+o.y*a;return c<Math.min(r.y,s.y)?r.y<s.y?r:s:c>Math.max(r.y,s.y)?r.y>s.y?r:s:new b(l,c)}hitTestLineSegment(n,r,s=0){return tw(n,r,this.start,this.end)||this.distanceToLineSegment(n,r)<=s}getSvgPathData(n=!0){const{start:r,end:s}=this;return`${n?`M${r.toFixed()}`:""} L${s.toFixed()}`}}class Ol extends ii{constructor(n){super({isClosed:!1,isFilled:!1,...n});g(this,"points");g(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:n}=this;for(let r=0,s=n.length-1;r<s;r++){const o=n[r],i=n[r+1];this._segments.push(new Ks({start:o,end:i}))}this.isClosed&&this._segments.push(new Ks({start:n[n.length-1],end:n[0]}))}return this._segments}getLength(){return this.segments.reduce((n,r)=>n+r.length,0)}getVertices(){return this.points}nearestPoint(n){const{segments:r}=this;let s=this.points[0],o=1/0,i,a;for(let l=0;l<r.length;l++)i=r[l].nearestPoint(n),a=b.Dist2(i,n),a<o&&(s=i,o=a);if(!s)throw Error("nearest point not found");return s}hitTestLineSegment(n,r,s=0){const{segments:o}=this;for(let i=0,a=o.length;i<a;i++)if(o[i].hitTestLineSegment(n,r,s))return!0;return!1}getSvgPathData(){const{vertices:n}=this;return n.length<2?"":n.reduce((r,s,o)=>o===0?`M ${s.x} ${s.y}`:`${r} L ${s.x} ${s.y}`,"")}}class vt extends Ol{constructor(t){super({...t}),this.isClosed=!0}}class ro extends vt{constructor(n){const{x:r=0,y:s=0,width:o,height:i}=n;super({...n,points:[new b(r,s),new b(r+o,s),new b(r+o,s+i),new b(r,s+i)]});g(this,"x");g(this,"y");g(this,"w");g(this,"h");this.x=r,this.y=s,this.w=o,this.h=i}getBounds(){return new Q(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:n,y:r,w:s,h:o}=this;return`M${n},${r} h${s} v${o} h-${s}z`}}class Wr{constructor(t){g(this,"canSnap",()=>!0);g(this,"canScroll",()=>!1);g(this,"canEdit",()=>!1);g(this,"canResize",()=>!0);g(this,"canEditInReadOnly",()=>!1);g(this,"canCrop",()=>!1);g(this,"canBeLaidOut",()=>!0);g(this,"hideResizeHandles",()=>!1);g(this,"hideRotateHandle",()=>!1);g(this,"hideSelectionBoundsBg",()=>!1);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"isAspectRatioLocked",()=>!1);g(this,"onBeforeCreate");g(this,"onBeforeUpdate");g(this,"onDragShapesOver");g(this,"onDragShapesOut");g(this,"onDropShapesOver");g(this,"onResizeStart");g(this,"onResize");g(this,"onResizeEnd");g(this,"onTranslateStart");g(this,"onTranslate");g(this,"onTranslateEnd");g(this,"onHandleDrag");g(this,"onRotateStart");g(this,"onRotate");g(this,"onRotateEnd");g(this,"onBindingChange");g(this,"onChildrenChange");g(this,"onDoubleClickHandle");g(this,"onDoubleClickEdge");g(this,"onDoubleClick");g(this,"onClick");g(this,"onEditEnd");this.editor=t}canBind(t){return!0}providesBackgroundForChildren(t){return!1}canReceiveNewChildrenOfType(t,n){return!1}canDropShapes(t,n){return!1}expandSelectionOutlinePx(t){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(t){return{}}getHandleSnapGeometry(t){return{}}}g(Wr,"props"),g(Wr,"migrations"),g(Wr,"type");function eG(e,t,n={}){const{closed:r=!1,snap:s=1,start:o="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=n;let c=0,u=0,h=1,p=0,f=0;switch(l){case"dashed":{h=1,c=Math.min(t*a,e/4);break}case"dotted":{h=100,c=t/h;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(o==="outset"?(e+=c/2,f+=c/2):o==="skip"&&(e-=c,f-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),u=Math.floor(e/c/(2*h)),u-=u%s,u<3&&l==="dashed"?e/t<5?(c=e,u=1,p=0):(c=e*.333,p=e*.333):(u=Math.max(u,3),c=e/u/(2*h),r?(f=c/2,p=(e-u*c)/u):p=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}function NC({bounds:e,className:t}){const n=F(),r=K("zoom level",()=>n.getZoomLevel(),[n]);return d.jsx("g",{className:t,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((s,o)=>{const{strokeDasharray:i,strokeDashoffset:a}=eG(s[0].dist(s[1]),1/r,{style:"dashed",lengthRatio:4});return d.jsx("line",{x1:s[0].x,y1:s[0].y,x2:s[1].x,y2:s[1].y,strokeDasharray:i,strokeDashoffset:a},o)})})}class Hh extends Wr{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"canBind",()=>!1);g(this,"onChildrenChange",n=>{const r=this.editor.getSortedChildIdsForParent(n.id);if(r.length===0){this.editor.getCurrentPageState().focusedGroupId===n.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([n.id]);return}else if(r.length===1){this.editor.getCurrentPageState().focusedGroupId===n.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(r,n.parentId),this.editor.deleteShapes([n.id]);return}})}getDefaultProps(){return{}}getGeometry(n){const r=this.editor.getSortedChildIdsForParent(n.id);return r.length===0?new ro({width:1,height:1,isFilled:!1}):new Gr({children:r.map(s=>{const o=this.editor.getShape(s),i=this.editor.getShapeGeometry(s),a=this.editor.getShapeLocalTransform(o).applyToPoints(i.vertices);return i.isClosed?new vt({points:a,isFilled:!0}):new Ol({points:a})})})}component(n){const r=this.editor.getErasingShapeIds().includes(n.id),{hintingShapeIds:s}=this.editor.getCurrentPageState(),o=s.length>0&&s.some(l=>l!==n.id&&this.editor.isShapeOfType(this.editor.getShape(l),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==n.id;if(!r&&(i||o))return null;const a=this.editor.getShapeGeometry(n).bounds;return d.jsx(Zo,{id:n.id,children:d.jsx(NC,{className:"tl-group",bounds:a})})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds;return d.jsx(NC,{className:"",bounds:r})}}g(Hh,"type","group"),g(Hh,"props",D_),g(Hh,"migrations",R_);const HM=[Hh],tG=new Set(HM.map(e=>e.type));function KM(e){const t=[...HM],n=new Set;for(const r of e){if(tG.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(n.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);t.push(r),n.add(r.type)}return t}const nG={maxShapesPerPage:4e3,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,defaultSvgPadding:32,cameraSlideFriction:.09,maxPointsPerDrawShape:500,gridSteps:[{min:-1,mid:.15,step:64},{min:.05,mid:.375,step:16},{min:.15,mid:1,step:4},{min:.7,mid:2.5,step:1}],collaboratorInactiveTimeoutMs:6e4,collaboratorIdleTimeoutMs:3e3,collaboratorCheckIntervalMs:1200,cameraMovingTimeoutMs:64,hitTestMargin:8,edgeScrollDelay:200,edgeScrollEaseDuration:200,edgeScrollSpeed:25,edgeScrollDistance:8,coarsePointerWidth:12,coarseHandleRadius:20,handleRadius:12,longPressDurationMs:500,textShadowLod:.35,adjacentShapeMargin:10,flattenImageBoundsExpand:64,flattenImageBoundsPadding:16};function FC(e,t){if(!t)return!1;switch(e.type){case"mixed":return t.type==="mixed";case"shared":return t.type==="shared"&&e.value===t.value;default:throw un(e)}}class rG{constructor(t){g(this,"map");this.map=new Map(t)}get(t){return this.map.get(t)}getAsKnownValue(t){const n=this.get(t);if(n&&n.type!=="mixed")return n.value}get size(){return this.map.size}equals(t){if(this.size!==t.size)return!1;const n=new Set;for(const[r,s]of this){if(!FC(s,t.get(r)))return!1;n.add(r)}for(const[r,s]of t)if(!n.has(r)&&!FC(s,this.get(r)))return!1;return!0}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}[Symbol.iterator](){return this.map[Symbol.iterator]()}}class kv extends rG{set(t,n){this.map.set(t,n)}applyValue(t,n){const r=this.get(t);if(!r){this.set(t,{type:"shared",value:n});return}switch(r.type){case"mixed":return;case"shared":r.value!==n&&this.set(t,{type:"mixed"});return;default:un(r,"type")}}}function sG(e,t,n){return ws(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],t,{type:n})})}const oG="https://cdn.tldraw.com";function Oo(){return`${oG}/${X_}`}function iG(e,t){var s;let n=e;const r=new Set(t);for(;r.has(n);)n=(s=/^.*(\d+)$/.exec(n))!=null&&s[1]?n.replace(/(\d+)(?=\D?)$/,o=>(+o+1).toString()):`${n} 1`;return n}function Zd(e,t,n){if(n.length===0)return[];const r=new Map;for(const o of ye(n.map(i=>e.getShape(i)))){const{parentId:i}=o;r.has(i)||r.set(i,{children:ye(e.getSortedChildIdsForParent(i).map(a=>e.getShape(a))),moving:new Set}),r.get(i).moving.add(o)}const s=[];switch(t){case"toBack":{r.forEach(({moving:o,children:i})=>aG(o,i,s));break}case"toFront":{r.forEach(({moving:o,children:i})=>lG(o,i,s));break}case"forward":{r.forEach(({moving:o,children:i})=>cG(o,i,s));break}case"backward":{r.forEach(({moving:o,children:i})=>uG(o,i,s));break}}return s}function aG(e,t,n){const r=t.length;if(e.size===r)return;let s,o;for(let i=0;i<r;i++){const a=t[i];if(e.has(a))s=a.index,e.delete(a);else{o=a.index;break}}if(e.size!==0){const i=al(s,o,e.size);n.push(...Array.from(e.values()).sort(ln).map((a,l)=>({...a,index:i[l]})))}}function lG(e,t,n){const r=t.length;if(e.size===r)return;let s,o;for(let i=r-1;i>-1;i--){const a=t[i];if(e.has(a))o=a.index,e.delete(a);else{s=a.index;break}}if(e.size!==0){const i=al(s,o,e.size);n.push(...Array.from(e.values()).sort(ln).map((a,l)=>({...a,index:i[l]})))}}function cG(e,t,n){var o;const r=t.length;if(e.size===r)return;let s={name:"skipping"};for(let i=0;i<r;i++){const a=e.has(t[i]);switch(s.name){case"skipping":{if(!a)continue;s={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:l}=s;al(t[i].index,(o=t[i+1])==null?void 0:o.index,i-l).forEach((c,u)=>n.push({...t[l+u],index:c})),s={name:"skipping"};break}}}}function uG(e,t,n){var o;const r=t.length;if(e.size===r)return;let s={name:"skipping"};for(let i=r-1;i>-1;i--){const a=e.has(t[i]);switch(s.name){case"skipping":{if(!a)continue;s={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;al((o=t[i-1])==null?void 0:o.index,t[i].index,s.selectIndex-i).forEach((l,c)=>{n.push({...t[i+c+1],index:l})}),s={name:"skipping"};break}}}}function WM({editor:e}){const t=e.getSelectedShapes(),n=e.getSelectionRotation(),r=e.getSelectionRotatedPageBounds(),{inputs:{originPagePoint:s}}=e;if(!r)return null;const o=r.center.clone().rotWith(r.point,n);return{selectionPageCenter:o,initialCursorAngle:o.angle(s),initialSelectionRotation:n,shapeSnapshots:t.map(i=>({shape:Ge(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function Kh({delta:e,editor:t,snapshot:n,stage:r}){const{selectionPageCenter:s,shapeSnapshots:o}=n;t.updateShapes(o.map(({shape:a,initialPagePoint:l})=>{const c=jn(a.parentId)?t.getShapePageTransform(a.parentId):oe.Identity(),u=b.RotWith(l,s,e),h=oe.applyToPoint(oe.Inverse(c),u),p=No(a.rotation+e);return{id:a.id,type:a.type,x:h.x,y:h.y,rotation:p}}));const i=[];o.forEach(({shape:a})=>{var h,p,f;const l=t.getShape(a.id);if(!l)return;const c=t.getShapeUtil(a);if(r==="start"||r==="one-off"){const S=(h=c.onRotateStart)==null?void 0:h.call(c,a);S&&i.push(S)}const u=(p=c.onRotate)==null?void 0:p.call(c,a,l);if(u&&i.push(u),r==="end"||r==="one-off"){const S=(f=c.onRotateEnd)==null?void 0:f.call(c,a,l);S&&i.push(S)}}),i.length>0&&t.updateShapes(i)}const dG=e=>{const{store:t}=e,n=t.query.filterHistory("binding"),r=t.query.records("binding");function s(){const o=r.get(),i=new Map;for(const a of o){const{fromId:l,toId:c}=a,u=i.get(l);u?u.push(a):i.set(l,[a]);const h=i.get(c);h?h.push(a):i.set(c,[a])}return i}return G("arrowBindingsIndex",(o,i)=>{if(Mi(o))return s();const a=o,l=n.getDiffSince(i);if(l===rr)return s();let c;function u(f){c??(c=new Map(a));const S=c.get(f.fromId),y=S==null?void 0:S.filter(v=>v.id!==f.id);y!=null&&y.length?c.set(f.fromId,y):c.delete(f.fromId);const x=c.get(f.toId),m=x==null?void 0:x.filter(v=>v.id!==f.id);m!=null&&m.length?c.set(f.toId,m):c.delete(f.toId)}function h(f){c??(c=new Map(a));let S=c.get(f);return S?S===a.get(f)&&(S=S.slice(0),c.set(f,S)):(S=[],c.set(f,S)),S}function p(f){h(f.fromId).push(f),h(f.toId).push(f)}for(const f of l){for(const S of gt(f.added))p(S);for(const[S,y]of gt(f.updated))u(S),p(y);for(const S of gt(f.removed))u(S)}return c??a})};function hG(e,t,n){const r=e.getShapeMaskedPageBounds(t);return r===void 0?!0:!n.includes(r)}const pG=e=>{function t(n){const r=n.getCurrentPageShapeIds(),s=n.getViewportPageBounds(),o=new Set;return r.forEach(i=>{hG(n,i,s)&&o.add(i)}),o}return G("getCulledShapes",n=>{if(Mi(n))return t(e);const r=t(e);if(n.size!==r.size)return r;for(const s of n)if(!r.has(s))return r;return n})},fG=e=>{const t=e.query.ids("shape"),n=e.query.filterHistory("shape");function r(){const s={},o=t.get(),i=Array(o.size);return o.forEach(a=>i.push(e.get(a))),i.sort(ln),i.forEach(a=>{s[a.parentId]||(s[a.parentId]=[]),s[a.parentId].push(a.id)}),s}return G("parentsToChildrenWithIndexes",(s,o)=>{if(Mi(s))return r();const i=n.getDiffSince(o);if(i===rr)return r();if(i.length===0)return s;let a=null;const l=h=>{a||(a={...s}),a[h]?a[h]===s[h]&&(a[h]=[...a[h]]):a[h]=[]},c=new Set;let u;for(let h=0,p=i.length;h<p;h++){u=i[h];for(const f of Object.values(u.added))Ta(f)&&(l(f.parentId),a[f.parentId].push(f.id),c.add(a[f.parentId]));for(const[f,S]of Object.values(u.updated))if(Ta(S)&&Ta(f)){if(f.parentId!==S.parentId)l(f.parentId),l(S.parentId),a[f.parentId].splice(a[f.parentId].indexOf(S.id),1),a[S.parentId].push(S.id),c.add(a[S.parentId]);else if(f.index!==S.index){l(S.parentId);const y=a[S.parentId].indexOf(S.id);a[S.parentId][y]=S.id,c.add(a[S.parentId])}}for(const f of Object.values(u.removed))Ta(f)&&(l(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const h of c){const p=ye(h.map(f=>e.get(f)));p.sort(ln),h.splice(0,h.length,...p.map(f=>f.id))}return a??s})},oy=(e,t,n)=>{for(;!Mn(n.parentId);){const r=e.get(n.parentId);if(!r)return!1;n=r}return n.parentId===t},gG=(e,t)=>{const n=e.query.ids("shape");let r=null;function s(){const o=t();return r=o,new Set([...n.get()].filter(i=>oy(e,o,e.get(i))))}return G("_shapeIdsInCurrentPage",(o,i)=>{if(Mi(o))return s();const a=t();if(a!==r)return s();const l=e.history.getDiffSince(i);if(l===rr)return s();const c=new Th(o);for(const h of l){for(const p of Object.values(h.added))Ta(p)&&oy(e,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))Ta(f)&&(oy(e,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(h.removed))jn(p)&&c.remove(p)}const u=c.get();return u?mc(u.value,u.diff):o})},GM=P.createContext(null);function mG({context:e,editor:t,children:n}){return d.jsx(Vf.Provider,{value:t,children:d.jsx(GM.Provider,{value:e,children:n})})}function VM(){const e=P.useContext(GM);return e?{isDarkMode:e.isDarkMode}:null}async function yG(e,t,n={}){var E,_;const r=typeof t[0]=="string"?t:t.map(I=>I.id);if(r.length===0)return;if(!window.document)throw Error("No document");const{scale:s=1,background:o=!1,padding:i=e.options.defaultSvgPadding,preserveAspectRatio:a=!1}=n,l=n.darkMode??e.user.getIsDarkMode(),c=lo({isDarkMode:l}),u=e.getShapeAndDescendantIds(r),h=e.getUnorderedRenderingShapes(!1).filter(({id:I})=>u.has(I));let p=null;if(n.bounds)p=n.bounds;else for(const{id:I}of h){const k=e.getShapeMaskedPageBounds(I);k&&(p?p.union(k):p=k.clone())}if(!p)return;const f=r.length===1&&e.isShapeOfType(e.getShape(r[0]),"frame")?r[0]:null;f||p.expandBy(i);const S=p.width*s,y=p.height*s;try{(_=(E=document.body).focus)==null||_.call(E)}catch{}const x=[],m=new Map,v={isDarkMode:l,addExportDef:I=>{if(m.has(I.key))return;const k=(async()=>{const T=await I.getElement();T&&x.push(d.jsx(P.Fragment,{children:T},x.length))})();m.set(I.key,k)}},w=(await Promise.all(h.map(async({id:I,opacity:k,index:T,backgroundIndex:M})=>{var z,W;if(I===f)return[];const D=e.getShape(I);if(e.isShapeOfType(D,"group"))return[];const $=e.getShapeUtil(D);let j=await((z=$.toSvg)==null?void 0:z.call($,D,v)),O=await((W=$.toBackgroundSvg)==null?void 0:W.call($,D,v));if(!j&&!O){const Y=e.getShapePageBounds(D);j=d.jsx("rect",{width:Y.w,height:Y.h,fill:c.solid,stroke:c.grey.pattern,strokeWidth:1})}let R=e.getShapePageTransform(D).toCssString();"scale"in D.props&&D.props.scale!==1&&(R=`${R} scale(${D.props.scale}, ${D.props.scale})`),j&&(j=d.jsx("g",{transform:R,opacity:k,children:j},D.id)),O&&(O=d.jsx("g",{transform:R,opacity:k,children:O},`bg_${D.id}`));const H=e.getShapeMask(D.id);if(H){const Y=`mask_${D.id.replace(":","_")}`;x.push(d.jsx("clipPath",{id:Y,children:d.jsx("path",{d:`M${H.map(({x:q,y:le})=>`${q},${le}`).join("L")}Z`})},x.length)),j&&(j=d.jsx("g",{clipPath:`url(#${Y})`,children:j},D.id)),O&&(O=d.jsx("g",{clipPath:`url(#${Y})`,children:O},`bg_${D.id}`))}const B=[];return j&&B.push({zIndex:T,element:j}),O&&B.push({zIndex:M,element:O}),B}))).flat();return await Promise.all(m.values()),{jsx:d.jsx(mG,{editor:e,context:v,children:d.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:S,height:y,viewBox:`${p.minX} ${p.minY} ${p.width} ${p.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:o?f?c.solid:c.background:"transparent"},children:[d.jsx("defs",{children:x}),w.sort((I,k)=>I.zIndex-k.zIndex).map(({element:I})=>I)]})}),width:S,height:y}}const SG=40;class vG{constructor(t){g(this,"_clickId","");g(this,"_clickTimeout");g(this,"_clickScreenPoint");g(this,"_previousScreenPoint");g(this,"_getClickTimeout",(t,n=ct())=>{this._clickId=n,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===t&&this._clickId===n){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},t==="idle"||t==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)});g(this,"_clickState","idle");g(this,"lastPointerInfo",{});g(this,"handlePointerEvent",t=>{switch(t.name){case"pointer_down":{if(!this._clickState)return t;switch(this._clickScreenPoint=b.From(t.point),this._previousScreenPoint&&b.Dist2(this._previousScreenPoint,this._clickScreenPoint)>SG**2&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=t,this._clickState){case"pendingDouble":return this._clickState="pendingTriple",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"double_click",phase:"down"};case"pendingTriple":return this._clickState="pendingQuadruple",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"triple_click",phase:"down"};case"pendingQuadruple":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"quadruple_click",phase:"down"};case"idle":{this._clickState="pendingDouble";break}case"pendingOverflow":{this._clickState="overflow";break}}return this._clickTimeout=this._getClickTimeout(this._clickState),t}case"pointer_up":{if(!this._clickState)return t;switch(this._clickScreenPoint=b.From(t.point),this._clickState){case"pendingTriple":return{...this.lastPointerInfo,type:"click",name:"double_click",phase:"up"};case"pendingQuadruple":return{...this.lastPointerInfo,type:"click",name:"triple_click",phase:"up"};case"pendingOverflow":return{...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"up"}}return t}case"pointer_move":return this._clickState!=="idle"&&this._clickScreenPoint&&b.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout(),t}return t});g(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});this.editor=t}get clickState(){return this._clickState}}class xG{constructor(t){g(this,"_isEdgeScrolling",!1);g(this,"_edgeScrollDuration",-1);this.editor=t}updateEdgeScrolling(t){const{editor:n}=this,r=this.getEdgeScroll();if(r.x===0&&r.y===0)this._isEdgeScrolling&&(this._isEdgeScrolling=!1,this._edgeScrollDuration=0);else if(this._isEdgeScrolling||(this._isEdgeScrolling=!0,this._edgeScrollDuration=0),this._edgeScrollDuration+=t,this._edgeScrollDuration>n.options.edgeScrollDelay){const s=n.options.edgeScrollEaseDuration>0?At.easeInCubic(Math.min(1,this._edgeScrollDuration/(n.options.edgeScrollDelay+n.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*s,y:r.y*s})}}getEdgeProximityFactors(t,n,r,s,o){const{editor:i}=this,a=i.options.edgeScrollDistance,l=r?i.options.coarsePointerWidth:0,c=t-l,u=t+l,h=s?0:a,p=o?n:n-a;return c<h?Math.min(1,(h-c)/a):u>p?-Math.min(1,(u-p)/a):0}getEdgeScroll(){const{editor:t}=this,{inputs:{currentScreenPoint:{x:n,y:r}}}=t,s=t.getViewportScreenBounds(),{isCoarsePointer:o,insets:[i,a,l,c]}=t.getInstanceState(),u=this.getEdgeProximityFactors(n,s.w,o,c,a),h=this.getEdgeProximityFactors(r,s.h,o,i,l);return{x:u,y:h}}moveCameraWhenCloseToEdge(t){const{editor:n}=this;if(!n.inputs.isDragging||n.inputs.isPanning||n.getCameraOptions().isLocked||t.x===0&&t.y===0)return;const r=n.getViewportScreenBounds(),s=r.w<1e3?.612:1,o=r.h<1e3?.612:1,i=n.getZoomLevel(),a=n.user.getEdgeScrollSpeed()*n.options.edgeScrollSpeed,l=a*t.x*s/i,c=a*t.y*o/i,{x:u,y:h,z:p}=n.getCamera();n.setCamera(new b(u+l,h+c,p))}}class wG{constructor(t){g(this,"isSafari");g(this,"isIos");g(this,"isChromeForIos");g(this,"isFirefox");g(this,"isAndroid");this.editor=t,typeof window<"u"&&"navigator"in window?(this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),this.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),this.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),this.isFirefox=/firefox/i.test(navigator.userAgent),this.isAndroid=/android/i.test(navigator.userAgent)):(this.isSafari=!1,this.isIos=!1,this.isChromeForIos=!1,this.isFirefox=!1,this.isAndroid=!1)}}class bG{constructor(t,n){g(this,"disposeSideEffectListener");this.editor=t,this.disposeSideEffectListener=t.sideEffects.registerAfterChangeHandler("instance",(s,o)=>{s.isFocused!==o.isFocused&&(o.isFocused?this.focus():this.blur(),this.updateContainerClass())});const r=t.getInstanceState().isFocused;n!==r&&t.updateInstanceState({isFocused:!!n}),this.updateContainerClass()}updateContainerClass(){const t=this.editor.getContainer();this.editor.getInstanceState().isFocused?t.classList.add("tl-container__focused"):t.classList.remove("tl-container__focused")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var t;(t=this.disposeSideEffectListener)==null||t.call(this)}}function ac(e){return CG}class PG{constructor(){g(this,"length",0);g(this,"head",null);g(this,"tail",this)}push(t){return new nw(t,this)}toArray(){return Gs}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const CG=new PG;class nw{constructor(t,n){g(this,"length");this.head=t,this.tail=n,this.length=n.length+1}push(t){return new nw(t,this)}toArray(){return Array.from(this)}[Symbol.iterator](){let t=this;return{next(){if(t.length){const n=t.head;return t=t.tail,{value:n,done:!1}}else return{value:void 0,done:!0}}}}}class IG{constructor(t){g(this,"store");g(this,"dispose");g(this,"state","recording");g(this,"pendingDiff",new kG);g(this,"stacks",Mt("HistoryManager.stacks",{undos:ac(),redos:ac()},{isEqual:(t,n)=>t.undos===n.undos&&t.redos===n.redos}));g(this,"annotateError");g(this,"_isInBatch",!1);g(this,"batch",(t,n)=>{const r=this.state;r!=="paused"&&(n!=null&&n.history)&&(this.state=EG[n.history]);try{if(this._isInBatch)return gs(t),this;this._isInBatch=!0;try{gs(t)}catch(s){throw this.annotateError(s),s}finally{this._isInBatch=!1}return this}finally{this.state=r}});g(this,"_undo",({pushToRedoStack:t,toMark:n=void 0})=>{var s;const r=this.state;this.state="paused";try{let{undos:o,redos:i}=this.stacks.get();const a=this.pendingDiff.clear(),l=o_(a),c=PS(a);t&&!l&&(i=i.push({type:"diff",diff:a}));let u=!1;if(l)for(;((s=o.head)==null?void 0:s.type)==="stop";){const h=o.head;if(o=o.tail,t&&(i=i.push(h)),h.id===n){u=!0;break}}if(!u)e:for(;o.head;){const h=o.head;switch(o=o.tail,t&&(i=i.push(h)),h.type){case"diff":Nc(c,[PS(h.diff)]);break;case"stop":if(!n||h.id===n)break e;break;default:un(h)}}this.store.applyDiff(c,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:o,redos:i})}finally{this.state=r}return this});g(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));g(this,"redo",()=>{var n;const t=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:r,redos:s}=this.stacks.get();if(s.length===0)return this;for(;((n=s.head)==null?void 0:n.type)==="stop";)r=r.push(s.head),s=s.tail;const o=_p();for(;s.head;){const i=s.head;if(r=r.push(i),s=s.tail,i.type==="diff")Nc(o,[i.diff]);else break}this.store.applyDiff(o,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:s})}finally{this.state=t}return this});g(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));g(this,"bailToMark",t=>(this._undo({pushToRedoStack:!1,toMark:t}),this));g(this,"squashToMark",t=>{var o;let n=this.stacks.get().undos;const r=[];for(;n.head&&!(n.head.type==="stop"&&n.head.id===t);)n.head.type==="diff"&&r.push(n.head.diff),n=n.tail;if(!n.head||((o=n.head)==null?void 0:o.id)!==t)return console.error("Could not find mark to squash to: ",t),this;if(r.length===0)return this;const s=_p();return Nc(s,r.reverse()),this.stacks.update(({redos:i})=>({undos:n.push({type:"diff",diff:s}),redos:i})),this});g(this,"mark",(t=ct())=>(gs(()=>{this.flushPendingDiff(),this.stacks.update(({undos:n,redos:r})=>({undos:n.push({type:"stop",id:t}),redos:r}))}),t));this.store=t.store,this.annotateError=t.annotateError??nu,this.dispose=this.store.addHistoryInterceptor((n,r)=>{if(r==="user")switch(this.state){case"recording":this.pendingDiff.apply(n.changes),this.stacks.update(({undos:s})=>({undos:s,redos:ac()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(n.changes);break;case"paused":break;default:un(this.state)}})}flushPendingDiff(){if(this.pendingDiff.isEmpty())return;const t=this.pendingDiff.clear();this.stacks.update(({undos:n,redos:r})=>({undos:n.push({type:"diff",diff:t}),redos:r}))}getNumUndos(){return this.stacks.get().undos.length+(this.pendingDiff.isEmpty()?0:1)}getNumRedos(){return this.stacks.get().redos.length}clear(){this.stacks.set({undos:ac(),redos:ac()}),this.pendingDiff.clear()}debug(){const{undos:t,redos:n}=this.stacks.get();return{undos:t.toArray(),redos:n.toArray(),pendingDiff:this.pendingDiff.debug(),state:this.state}}}const EG={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class kG{constructor(){g(this,"diff",_p());g(this,"isEmptyAtom",Mt("PendingDiff.isEmpty",!0))}clear(){const t=this.diff;return this.diff=_p(),this.isEmptyAtom.set(!0),t}isEmpty(){return this.isEmptyAtom.get()}apply(t){Nc(this.diff,[t]),this.isEmptyAtom.set(o_(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class _G{constructor(t){g(this,"scribbleItems",new Map);g(this,"state","paused");g(this,"addScribble",(t,n=ct())=>{const r={id:n,scribble:{id:n,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...t,state:"starting"},timeoutMs:0,delayRemaining:t.delay??0,prev:null,next:null};return this.scribbleItems.set(n,r),r});g(this,"stop",t=>{const n=this.scribbleItems.get(t);if(!n)throw Error(`Scribble with id ${t} not found`);return n.delayRemaining=Math.min(n.delayRemaining,200),n.scribble.state="stopping",n});g(this,"addPoint",(t,n,r)=>{const s=this.scribbleItems.get(t);if(!s)throw Error(`Scribble with id ${t} not found`);const{prev:o}=s,i={x:n,y:r,z:.5};return(!o||b.Dist(o,i)>=1)&&(s.next=i),s});g(this,"tick",t=>{this.scribbleItems.size!==0&&this.editor.run(()=>{this.scribbleItems.forEach(n=>{if(n.scribble.state==="starting"){const{next:l,prev:c}=n;l&&l!==c&&(n.prev=l,n.scribble.points.push(l)),n.scribble.points.length>8&&(n.scribble.state="active");return}n.delayRemaining>0&&(n.delayRemaining=Math.max(0,n.delayRemaining-t)),n.timeoutMs+=t,n.timeoutMs>=16&&(n.timeoutMs=0);const{delayRemaining:r,timeoutMs:s,prev:o,next:i,scribble:a}=n;switch(a.state){case"active":{i&&i!==o?(n.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):s===0&&(a.points.length>1?a.points.shift():n.delayRemaining=a.delay);break}case"stopping":{if(n.delayRemaining===0&&s===0){if(a.points.length===1){this.scribbleItems.delete(n.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:n})=>({...n,points:[...n.points]})).slice(-5)})})});this.editor=t}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}}var TG=Object.defineProperty,MG=Object.getOwnPropertyDescriptor,pg=(e,t,n,r)=>{for(var s=MG(t,n),o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(t,n,s)||s);return s&&TG(t,n,s),s};const de=e=>Math.round(e*10**8)/10**8;function $s(e,t,n,r,s){const o=e.filter(a=>(r==="forward"?a.startNode.id===t:a.endNode.id===t)&&de(a.length)===de(n)&&Lr(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));if(o.length===0)return[];const i=new Set;return o.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(l)){i.add(l);const c=$s(e,l,n,r,Lr(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));o.push(...c)}}),o}function AG(e){e.sort((t,n)=>n.gaps.length-t.gaps.length);for(let t=e.length-1;t>0;t--){const n=e[t];for(let r=t-1;r>=0;r--){const s=e[r];if(s.direction===n.direction&&n.gaps.every(o=>s.gaps.some(i=>de(o.startEdge[0].x)===de(i.startEdge[0].x)&&de(o.startEdge[0].y)===de(i.startEdge[0].y)&&de(o.startEdge[1].x)===de(i.startEdge[1].x)&&de(o.startEdge[1].y)===de(i.startEdge[1].y))&&s.gaps.some(i=>de(o.endEdge[0].x)===de(i.endEdge[0].x)&&de(o.endEdge[0].y)===de(i.endEdge[0].y)&&de(o.endEdge[1].x)===de(i.endEdge[1].x)&&de(o.endEdge[1].y)===de(i.endEdge[1].y)))){e.splice(t,1);break}}}}class ed{constructor(t){g(this,"editor");this.manager=t,this.editor=t.editor}getSnapPointsCache(){const{editor:t}=this;return t.store.createComputedCache("snapPoints",n=>{const r=t.getShapePageTransform(n.id);if(!r)return;const o=t.getShapeUtil(n).getBoundsSnapGeometry(n).points??t.getShapeGeometry(n).bounds.cornersAndCenter;if(!(!r||!o))return o.map((i,a)=>{const{x:l,y:c}=oe.applyToPoint(r,i);return{x:l,y:c,id:`${n.id}:${a}`}})})}getSnapPoints(t){return this.getSnapPointsCache().get(t)??[]}getSnappablePoints(){const t=this.getSnapPointsCache(),n=this.manager.getSnappableShapes(),r=[];for(const s of n){const o=t.get(s);o&&r.push(...o)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),t=>({id:t,pageBounds:xr(this.editor.getShapePageBounds(t))}))}getVisibleGaps(){const t=[],n=[];let r,s;const o=this.getSnappableGapNodes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<o.length;a++){r=o[a];for(let l=a+1;l<o.length;l++)s=o[l],r.pageBounds.maxX<s.pageBounds.minX&&Ql(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)&&t.push({startNode:r,endNode:s,startEdge:[new b(r.pageBounds.maxX,r.pageBounds.minY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(s.pageBounds.minX,s.pageBounds.minY),new b(s.pageBounds.minX,s.pageBounds.maxY)],length:s.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Lr(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)})}const i=o.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let l=a+1;l<i.length;l++)s=i[l],r.pageBounds.maxY<s.pageBounds.minY&&Ql(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)&&n.push({startNode:r,endNode:s,startEdge:[new b(r.pageBounds.minX,r.pageBounds.maxY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(s.pageBounds.minX,s.pageBounds.minY),new b(s.pageBounds.maxX,s.pageBounds.minY)],length:s.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Lr(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)})}return{horizontal:t,vertical:n}}snapTranslateShapes({lockedAxis:t,initialSelectionPageBounds:n,initialSelectionSnapPoints:r,dragDelta:s}){var x,m;const o=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=n.clone().translate(s),l=r.map(({x:v,y:w},C)=>({id:"selection:"+C,x:v+s.x,y:w+s.y})),c=i,u=[],h=[],p=new b(o,o);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const f=new b(t==="x"?0:((x=u[0])==null?void 0:x.nudge)??0,t==="y"?0:((m=h[0])==null?void 0:m.nudge)??0);p.x=0,p.y=0,u.length=0,h.length=0,l.forEach(v=>{v.x+=f.x,v.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const S=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),y=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...y,...S]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:t,dragDelta:n,handle:r,isAspectRatioLocked:s,isResizingFromCenter:o}){var I,k;const i=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=Q.Resize(t,r,o?n.x*2:n.x,o?n.y*2:n.y,s);let u=r;l<0&&(u=O7(u)),c<0&&(u=j7(u)),o&&(a.center=t.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",f=zC(u,a),S=this.getSnappablePoints(),y=[],x=[],m=new b(i,i);this.collectPointSnaps({minOffset:m,nearestSnapsX:y,nearestSnapsY:x,otherNodeSnapPoints:S,selectionSnapPoints:f});const v=new b(h?0:((I=y[0])==null?void 0:I.nudge)??0,p?0:((k=x[0])==null?void 0:k.nudge)??0);if(s&&D7(u)&&v.len()!==0){const T=y.length&&x.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":y.length?"x":"y",M=t.aspectRatio;T==="x"?(x.length=0,v.y=v.x/M,(u==="bottom_left"||u==="top_right")&&(v.y=-v.y)):(y.length=0,v.x=v.y*M,(u==="bottom_left"||u==="top_right")&&(v.x=-v.x))}const w=b.Add(n,v),{box:C}=Q.Resize(t,r,o?w.x*2:w.x,o?w.y*2:w.y,s);o&&(C.center=t.center);const E=zC("any",C);y.length=0,x.length=0,m.x=0,m.y=0,this.collectPointSnaps({minOffset:m,nearestSnapsX:y,nearestSnapsY:x,otherNodeSnapPoints:S,selectionSnapPoints:E});const _=this.getPointSnapLines({nearestSnapsX:y,nearestSnapsY:x});return this.manager.setIndicators([..._]),{nudge:v}}collectPointSnaps({selectionSnapPoints:t,otherNodeSnapPoints:n,minOffset:r,nearestSnapsX:s,nearestSnapsY:o}){for(const i of t)for(const a of n){const l=b.Sub(i,a),c=Math.abs(l.x),u=Math.abs(l.y);de(c)<=de(r.x)&&(de(c)<de(r.x)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),de(u)<=de(r.y)&&(de(u)<de(r.y)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:t,minOffset:n,nearestSnapsX:r,nearestSnapsY:s}){const{horizontal:o,vertical:i}=this.getVisibleGaps();for(const a of o){if(!Ql(a.breadthIntersection[0],a.breadthIntersection[1],t.minY,t.maxY))continue;const c=a.startEdge[0].x+a.length/2-t.center.x;if(a.length>t.width&&de(Math.abs(c))<=de(n.x)){de(Math.abs(c))<de(n.x)&&(r.length=0),n.x=Math.abs(c);const m={type:"gap_center",gap:a,nudge:c},v=r.find(({type:C})=>C==="gap_center"),w=v&&Lr(a.breadthIntersection[0],a.breadthIntersection[1],v.gap.breadthIntersection[0],v.gap.breadthIntersection[1]);v&&v.gap.length>a.length&&w?r[r.indexOf(v)]=m:(!v||!w)&&r.push(m)}const h=a.startNode.pageBounds.minX-a.length,p=t.maxX,f=h-p;de(Math.abs(f))<=de(n.x)&&(de(Math.abs(f))<de(n.x)&&(r.length=0),n.x=Math.abs(f),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:f}));const S=a.endNode.pageBounds.maxX+a.length,y=t.minX,x=S-y;de(Math.abs(x))<=de(n.x)&&(de(Math.abs(x))<de(n.x)&&(r.length=0),n.x=Math.abs(x),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:x}))}for(const a of i){if(!Ql(a.breadthIntersection[0],a.breadthIntersection[1],t.minX,t.maxX))continue;const c=a.startEdge[0].y+a.length/2-t.center.y;if(a.length>t.height&&de(Math.abs(c))<=de(n.y)){de(Math.abs(c))<de(n.y)&&(s.length=0),n.y=Math.abs(c);const m={type:"gap_center",gap:a,nudge:c},v=s.find(({type:C})=>C==="gap_center"),w=v&&Ql(v.gap.breadthIntersection[0],v.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);v&&v.gap.length>a.length&&w?s[s.indexOf(v)]=m:(!v||!w)&&s.push(m);continue}const h=a.startNode.pageBounds.minY-a.length,p=t.maxY,f=h-p;de(Math.abs(f))<=de(n.y)&&(de(Math.abs(f))<de(n.y)&&(s.length=0),n.y=Math.abs(f),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:f}));const S=a.endNode.pageBounds.maxY+a.length,y=t.minY,x=S-y;de(Math.abs(x))<=de(n.y)&&(de(Math.abs(x))<de(n.y)&&(s.length=0),n.y=Math.abs(x),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:x}))}}getPointSnapLines({nearestSnapsX:t,nearestSnapsY:n}){const r={},s={};if(t.length>0){for(const o of t)if(o.type==="points"){const i=de(o.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(o.points)}}if(n.length>0){for(const o of n)if(o.type==="points"){const i=de(o.points.otherPoint.y);s[i]||(s[i]=[]),s[i].push(o.points)}}return Object.values(r).concat(Object.values(s)).map(o=>({id:ct(),type:"points",points:Fx(o.map(i=>b.From(i.otherPoint)).concat(o.map(i=>b.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:t,nearestSnapsX:n,nearestSnapsY:r}){const{vertical:s,horizontal:o}=this.getVisibleGaps(),i={top:t.sides[0],right:t.sides[1],bottom:[t.corners[3],t.corners[2]],left:[t.corners[0],t.corners[3]]},a=[];if(n.length>0)for(const l of n){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:f,endEdge:S}}=l;switch(l.type){case"gap_center":{const y=(f-t.width)/2,x=Lr(c[0],c[1],t.minY,t.maxY);a.push({type:"gaps",direction:"horizontal",id:ct(),gaps:[...$s(o,h.id,y,"backward",x),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:S},...$s(o,p.id,y,"forward",x)]});break}case"gap_duplicate":{const y=Lr(c[0],c[1],t.minY,t.maxY);a.push({type:"gaps",direction:"horizontal",id:ct(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(x=>x.clone().addXY(-h.pageBounds.width,0))},{startEdge:u,endEdge:S},...$s(o,p.id,f,"forward",y)]:[...$s(o,h.id,f,"backward",y),{startEdge:u,endEdge:S},{startEdge:S.map(x=>x.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:f,endEdge:S}}=l;switch(l.type){case"gap_center":{const y=(f-t.height)/2,x=Lr(c[0],c[1],t.minX,t.maxX);a.push({type:"gaps",direction:"vertical",id:ct(),gaps:[...$s(s,h.id,y,"backward",x),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:S},...$s(s,l.gap.endNode.id,y,"forward",x)]});break}case"gap_duplicate":{const y=Lr(c[0],c[1],t.minX,t.maxX);a.push({type:"gaps",direction:"vertical",id:ct(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(x=>x.clone().addXY(0,-h.pageBounds.height))},{startEdge:u,endEdge:S},...$s(s,p.id,f,"forward",y)]:[...$s(s,h.id,f,"backward",y),{startEdge:u,endEdge:S},{startEdge:S.map(x=>x.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return AG(a),a}}pg([G],ed.prototype,"getSnapPointsCache");pg([G],ed.prototype,"getSnappablePoints");pg([G],ed.prototype,"getSnappableGapNodes");pg([G],ed.prototype,"getVisibleGaps");function zC(e,t){const{minX:n,maxX:r,minY:s,maxY:o}=t,i=[];switch(e){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:n,y:s})}switch(e){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:s})}switch(e){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:o})}switch(e){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:n,y:o})}return i}var jG=Object.defineProperty,OG=Object.getOwnPropertyDescriptor,DG=(e,t,n,r)=>{for(var s=OG(t,n),o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(t,n,s)||s);return s&&jG(t,n,s),s};const RG=()=>null,LG=()=>[];class YM{constructor(t){g(this,"editor");this.manager=t,this.editor=t.editor}getSnapGeometryCache(){const{editor:t}=this;return t.store.createComputedCache("handle snap geometry",n=>{const r=t.getShapeUtil(n).getHandleSnapGeometry(n);return{outline:r.outline===void 0?t.getShapeGeometry(n):r.outline,points:r.points??[],getSelfSnapOutline:r.getSelfSnapOutline??RG,getSelfSnapPoints:r.getSelfSnapPoints??LG}})}*iterateSnapPointsInPageSpace(t,n){var s,o;const r=(s=this.getSnapGeometryCache().get(t))==null?void 0:s.getSelfSnapPoints(n);if(r&&r.length){const i=xr(this.editor.getShapePageTransform(t));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===t)continue;const a=(o=this.getSnapGeometryCache().get(i))==null?void 0:o.points;if(!a||!a.length)continue;const l=xr(this.editor.getShapePageTransform(i));for(const c of a)yield l.applyToPoint(c)}}*iterateSnapOutlines(t,n){var s,o;const r=(s=this.getSnapGeometryCache().get(t))==null?void 0:s.getSelfSnapOutline(n);r&&(yield{shapeId:t,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===t)continue;const a=(o=this.getSnapGeometryCache().get(i))==null?void 0:o.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:t,handle:n,handleInPageSpace:r}){const s=this.manager.getSnapThreshold();let o=s,i=null;for(const c of this.iterateSnapPointsInPageSpace(t,n))b.DistMin(r,c,o)&&(o=b.Dist(r,c),i=c);if(i)return i;let a=s,l=null;for(const{shapeId:c,outline:u}of this.iterateSnapOutlines(t,n)){const h=xr(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),f=u.nearestPoint(p),S=h.applyToPoint(f);b.DistMin(r,S,a)&&(a=b.Dist(r,S),l=S)}return l||null}snapHandle({currentShapeId:t,handle:n}){const s=xr(this.editor.getShapePageTransform(t)).applyToPoint(n),o=this.getHandleSnapPosition({currentShapeId:t,handle:n,handleInPageSpace:s});return o?(this.manager.setIndicators([{id:ct(),type:"points",points:[o]}]),{nudge:b.Sub(o,s)}):null}}DG([G],YM.prototype,"getSnapGeometryCache");var $G=Object.defineProperty,NG=Object.getOwnPropertyDescriptor,rw=(e,t,n,r)=>{for(var s=NG(t,n),o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(t,n,s)||s);return s&&$G(t,n,s),s};class fg{constructor(t){g(this,"shapeBounds");g(this,"handles");g(this,"_snapIndicators",Mt("snapLines",void 0));this.editor=t,this.shapeBounds=new ed(this),this.handles=new YM(this)}getIndicators(){return this._snapIndicators.get()??Gs}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(t){this._snapIndicators.set(t)}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:t}=this,n=t.getViewportPageBounds(),r=t.getSelectedShapeIds(),s=new Set,o=i=>{if(jn(i)){const l=t.getShape(i);l&&t.isShapeOfType(l,"frame")&&s.add(i)}const a=t.getSortedChildIdsForParent(i);for(const l of a){if(r.includes(l))continue;const c=t.getShape(l);if(!c||!t.getShapeUtil(c).canSnap(c))continue;const h=t.getShapePageBounds(l);if(h&&n.includes(h)){if(t.isShapeOfType(c,"group")){o(l);continue}s.add(l)}}};return o(this.getCurrentCommonAncestor()??t.getCurrentPageId()),s}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}rw([G],fg.prototype,"getSnapThreshold");rw([G],fg.prototype,"getSnappableShapes");rw([G],fg.prototype,"getCurrentCommonAncestor");const FG=/\r?\n|\r/g;function BC(e){return e.replace(FG,`
|
|
86
|
-
`).split(`
|
|
87
|
-
`).map(t=>t||" ").join(`
|
|
88
|
-
`)}const zG={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},BG=/\s/;class UG{constructor(t){g(this,"baseElm");g(this,"measureText",(t,n)=>{var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-style",n.fontStyle),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("font-size",n.fontSize+"px"),r.style.setProperty("line-height",n.lineHeight*n.fontSize+"px"),r.style.setProperty("max-width",n.maxWidth===null?null:n.maxWidth+"px"),r.style.setProperty("min-width",n.minWidth===null?null:n.minWidth+"px"),r.style.setProperty("padding",n.padding),r.style.setProperty("overflow-wrap",n.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=BC(t);const s=r.scrollWidth,o=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:o.width,h:o.height,scrollWidth:s}});this.editor=t;const n=this.editor.getContainer(),r=document.createElement("div");r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,n.appendChild(r),this.baseElm=r,t.disposables.add(()=>{r.remove()})}measureElementTextNodeSpans(t,{shouldTruncateToFirstLine:n=!1}={}){const r=[],s=t.getBoundingClientRect(),o=-s.left,i=-s.top,a=new Range,l=t.childNodes[0];let c=0,u=null,h=null,p=0,f=0,S=!1;for(const y of t.childNodes)if(y.nodeType===Node.TEXT_NODE)for(const x of y.textContent??""){a.setStart(l,c),a.setEnd(l,c+x.length);const m=a.getClientRects(),v=m[m.length-1],w=v.top+i,C=v.left+o,E=v.right+o,_=C<f,I=BG.test(x);if(I!==h||w!==p||!u){if(u){if(n&&w!==p){S=!0;break}r.push(u)}u={box:{x:C,y:w,w:v.width,h:v.height},text:x},f=C}else _&&(u.box.x=C),u.box.w=_?u.box.w+v.width:E-u.box.x,u.text+=x;x===`
|
|
89
|
-
`&&(f=0),h=I,p=w,c+=x.length}return u&&r.push(u),{spans:r,didTruncate:S}}measureTextSpans(t,n){var c;if(t==="")return[];const r=(c=this.baseElm)==null?void 0:c.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const s=Math.ceil(n.width-n.padding*2);r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("width",`${s}px`),r.style.setProperty("height","min-content"),r.style.setProperty("font-size",`${n.fontSize}px`),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("line-height",`${n.lineHeight*n.fontSize}px`),r.style.setProperty("text-align",zG[n.textAlign]);const o=n.overflow==="truncate-ellipsis"||n.overflow==="truncate-clip";o&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=BC(t);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:o});if(n.overflow==="truncate-ellipsis"&&l){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${s-u}px`),r.textContent=i;const h=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,p=h[h.length-1];return h.push({text:"…",box:{x:Math.min(p.box.x+p.box.w,n.width-n.padding-u),y:p.box.y,w:u,h:p.box.h}}),h}return r.remove(),a}}const UC=(typeof process<"u",t_);class HG{constructor(t){g(this,"cancelRaf");g(this,"isPaused",!0);g(this,"now",0);g(this,"start",()=>{var t;this.isPaused=!1,(t=this.cancelRaf)==null||t.call(this),this.cancelRaf=UC(this.tick),this.now=Date.now()});g(this,"tick",()=>{if(this.isPaused)return;const t=Date.now(),n=t-this.now;this.now=t,this.updatePointerVelocity(n),this.editor.emit("frame",n),this.editor.emit("tick",n),this.cancelRaf=UC(this.tick)});g(this,"dispose",()=>{var t;this.isPaused=!0,(t=this.cancelRaf)==null||t.call(this)});g(this,"prevPoint",new b);g(this,"updatePointerVelocity",t=>{const{prevPoint:n,editor:{inputs:{currentScreenPoint:r,pointerVelocity:s}}}=this;if(t===0)return;const o=b.Sub(r,n);this.prevPoint=r.clone();const i=o.len(),a=i?o.div(i):new b(0,0),l=s.clone().lrp(a.mul(i/t),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),s.equals(l)||(this.editor.inputs.pointerVelocity=l)});this.editor=t,this.editor.disposables.add(this.dispose),this.start()}}var KG=Object.defineProperty,WG=Object.getOwnPropertyDescriptor,Ar=(e,t,n,r)=>{for(var s=WG(t,n),o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(t,n,s)||s);return s&&KG(t,n,s),s};class fr{constructor(t,n){g(this,"systemColorScheme",Mt("systemColorScheme","light"));g(this,"updateUserPreferences",t=>{this.user.setUserPreferences({...this.user.userPreferences.get(),...t})});if(this.user=t,this.inferDarkMode=n,typeof window>"u"||!("matchMedia"in window))return;const r=window.matchMedia("(prefers-color-scheme: dark)");r!=null&&r.matches&&this.systemColorScheme.set("dark"),r==null||r.addEventListener("change",s=>{s.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")})}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme){case"dark":return!0;case"light":return!1;case"system":return this.systemColorScheme.get()==="dark";default:return this.inferDarkMode?this.systemColorScheme.get()==="dark":!1}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??Rs.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??Rs.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??Rs.name}getLocale(){return this.user.userPreferences.get().locale??Rs.locale}getColor(){return this.user.userPreferences.get().color??Rs.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??Rs.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??Rs.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??Rs.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??Rs.isPasteAtCursorMode}}Ar([G],fr.prototype,"getUserPreferences");Ar([G],fr.prototype,"getIsDarkMode");Ar([G],fr.prototype,"getEdgeScrollSpeed");Ar([G],fr.prototype,"getAnimationSpeed");Ar([G],fr.prototype,"getId");Ar([G],fr.prototype,"getName");Ar([G],fr.prototype,"getLocale");Ar([G],fr.prototype,"getColor");Ar([G],fr.prototype,"getIsSnapMode");Ar([G],fr.prototype,"getIsWrapMode");Ar([G],fr.prototype,"getIsDynamicResizeMode");Ar([G],fr.prototype,"getIsPasteAtCursorMode");const GG={wheel:"onWheel",pointer_down:"onPointerDown",pointer_move:"onPointerMove",long_press:"onLongPress",pointer_up:"onPointerUp",right_click:"onRightClick",middle_click:"onMiddleClick",key_down:"onKeyDown",key_up:"onKeyUp",key_repeat:"onKeyRepeat",cancel:"onCancel",complete:"onComplete",interrupt:"onInterrupt",double_click:"onDoubleClick",triple_click:"onTripleClick",quadruple_click:"onQuadrupleClick",tick:"onTick"},VG=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class se{constructor(t,n){g(this,"performanceTracker");g(this,"id");g(this,"type");g(this,"shapeType");g(this,"initial");g(this,"children");g(this,"isLockable");g(this,"parent");g(this,"_path");g(this,"_current");g(this,"_isActive");g(this,"transition",(t,n={})=>{var o;const r=t.split(".");let s=this;for(let i=0;i<r.length;i++){const a=r[i],l=s.getCurrent(),c=(o=s.children)==null?void 0:o[a];if(!c)throw Error(`${s.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(n,a),s._current.set(c),c.enter(n,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;s=c}return this});g(this,"handleEvent",t=>{var s;const n=GG[t.name],r=this._current.__unsafe__getWithoutCapture();(s=this[n])==null||s.call(this,t),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(t)});g(this,"enter",(t,n)=>{var r;if(xt.measurePerformance.get()&&VG.includes(this.id)&&this.performanceTracker.start(this.id),this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,t,n),this.children&&this.initial&&this.getIsActive()){const s=this.children[this.initial];this._current.set(s),s.enter(t,n)}});g(this,"exit",(t,n)=>{var r,s;xt.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,t,n),this.getIsActive()||(s=this.getCurrent())==null||s.exit(t,n)});g(this,"_currentToolIdMask",Mt("curent tool id mask",void 0));g(this,"onWheel");g(this,"onPointerDown");g(this,"onPointerMove");g(this,"onLongPress");g(this,"onPointerUp");g(this,"onDoubleClick");g(this,"onTripleClick");g(this,"onQuadrupleClick");g(this,"onRightClick");g(this,"onMiddleClick");g(this,"onKeyDown");g(this,"onKeyUp");g(this,"onKeyRepeat");g(this,"onCancel");g(this,"onComplete");g(this,"onInterrupt");g(this,"onTick");g(this,"onEnter");g(this,"onExit");this.editor=t;const{id:r,children:s,initial:o,isLockable:i}=this.constructor;this.id=r,this._isActive=Mt("toolIsActive"+this.id,!1),this._current=Mt("toolState"+this.id,void 0),this._path=G("toolPath"+this.id,()=>{const a=this.getCurrent();return this.id+(a?`.${a.getPath()}`:"")}),this.parent=n??{},this.parent?s&&o?(this.type="branch",this.initial=o,this.children=Object.fromEntries(s().map(a=>[a.id,new a(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",s&&o&&(this.initial=o,this.children=Object.fromEntries(s().map(a=>[a.id,new a(this.editor,this)])),this._current.set(this.children[this.initial]))),this.isLockable=i,this.performanceTracker=new Nk}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(t){this._currentToolIdMask.set(t)}}g(se,"id"),g(se,"initial"),g(se,"children"),g(se,"isLockable",!0);class Wh extends se{constructor(){super(...arguments);g(this,"onKeyDown",n=>{var r;switch(n.code){case"KeyZ":{if(!(n.shiftKey||n.ctrlKey)){const s=this.getCurrent();s&&((r=s.getCurrent())==null?void 0:r.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...n,onInteractionEnd:s.id})}break}}})}}g(Wh,"id","root"),g(Wh,"initial",""),g(Wh,"children",()=>[]);var YG=Object.defineProperty,XG=Object.getOwnPropertyDescriptor,ne=(e,t,n,r)=>{for(var s=XG(t,n),o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(t,n,s)||s);return s&&YG(t,n,s),s};class Z extends NH{constructor({store:n,user:r,shapeUtils:s,bindingUtils:o,tools:i,getContainer:a,cameraOptions:l,initialState:c,autoFocus:u,inferDarkMode:h,options:p}){super();g(this,"options");g(this,"store");g(this,"root");g(this,"disposables",new Set);g(this,"isDisposed",!1);g(this,"_tickManager");g(this,"snaps");g(this,"timers");g(this,"user");g(this,"textMeasure");g(this,"environment");g(this,"scribbles");g(this,"sideEffects");g(this,"edgeScrollManager");g(this,"focusManager");g(this,"getContainer");g(this,"shapeUtils");g(this,"styleProps");g(this,"bindingUtils");g(this,"history");g(this,"_shouldIgnoreShapeLock",!1);g(this,"_crashingError",null);g(this,"_updateInstanceState",(n,r)=>{this.run(()=>{this.store.put([{...this.getInstanceState(),...n}])},r)});g(this,"_isChangingStyleTimeout",-1);g(this,"setCursor",n=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...n}}),this));g(this,"_updateCurrentPageState",n=>{this.store.update(n.id??this.getCurrentPageState().id,r=>({...r,...n}))});g(this,"_cameraOptions",Mt("camera options",uP));g(this,"_viewportAnimation",null);g(this,"_willSetInitialBounds",!0);g(this,"_isLockedOnFollowingUser",Mt("isLockedOnFollowingUser",!1));g(this,"_cameraState",Mt("camera state","idle"));g(this,"_cameraStateTimeoutRemaining",0);g(this,"_decayCameraStateTimeout",n=>{this._cameraStateTimeoutRemaining-=n,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))});g(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});g(this,"_currentPageShapeIds");g(this,"_parentIdsToChildIds");g(this,"animatingShapes",new Map);g(this,"_updateShapes",n=>{this.getInstanceState().isReadonly||this.run(()=>{var i,a;const r=[];let s,o;for(let l=0,c=n.length;l<c;l++){const u=n[l];u&&(s=this.getShape(u.id),s&&(o=ss(s,u),o!==s&&(o=((a=(i=this.getShapeUtil(s)).onBeforeUpdate)==null?void 0:a.call(i,s,o))??o,r.push(o))))}this.store.put(r)})});g(this,"externalAssetContentHandlers",{file:null,url:null});g(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});g(this,"inputs",{originPagePoint:new b,originScreenPoint:new b,previousPagePoint:new b,previousScreenPoint:new b,currentPagePoint:new b,currentScreenPoint:new 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 b});g(this,"_clickManager",new vG(this));g(this,"_prevCursor","default");g(this,"_shiftKeyTimeout",-1);g(this,"_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"})});g(this,"_altKeyTimeout",-1);g(this,"_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"})});g(this,"_ctrlKeyTimeout",-1);g(this,"_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"})});g(this,"_restoreToolId","select");g(this,"_pinchStart",1);g(this,"_didPinch",!1);g(this,"_selectedShapeIdsAtPointerDown",[]);g(this,"_longPressTimeout",-1);g(this,"capturedPointerId",null);g(this,"performanceTracker");g(this,"performanceTrackerTimeout",-1);g(this,"dispatch",n=>(this._pendingEventsForNextTick.push(n),n.type==="pointer"&&n.name==="pointer_move"||n.type==="wheel"||n.type==="pinch"||this._flushEventsForTick(0),this));g(this,"_pendingEventsForNextTick",[]);g(this,"_flushEventForTick",n=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:s}=n;if(n.type==="misc"){(n.name==="cancel"||n.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}))),this.root.handleEvent(n);return}n.shiftKey?(clearTimeout(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!n.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),n.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!n.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),n.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!n.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:o,currentPagePoint:i}=r;r.isPointing||(r.isDragging=!1);const a=this.store.unsafeGetWithoutCapture(Sn),l=this.store.get(this._getCurrentPageStateId()),c=this._cameraOptions.__unsafe__getWithoutCapture();switch(s){case"pinch":{if(c.isLocked)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(n),n.name){case"pinch_start":{if(r.isPinching)return;r.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=[...l.selectedShapeIds]),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{point:{z:u=1},delta:{x:h,y:p}}=n,{x:f,y:S}=b.SubXY(n.point,a.screenBounds.x,a.screenBounds.y);this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:y,y:x,z:m}=Id(()=>this.getCamera()),{panSpeed:v,zoomSpeed:w}=c;this._setCamera(new b(y+h*v/m-f/m+f/(u*w),x+p*v/m-S/m+S/(u*w),u*w),{immediate:!0});return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:u}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,u.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(u)}));return}}}case"wheel":{if(c.isLocked)return;if(this._updateInputsFromEvent(n),!this.getIsMenuOpen()){const{panSpeed:u,zoomSpeed:h,wheelBehavior:p}=c;if(p!=="none"){this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:f,y:S,z:y}=Id(()=>this.getCamera()),{x,y:m,z:v=0}=n.delta;let w=p;switch(r.ctrlKey&&(w=p==="pan"?"zoom":"pan"),w){case"zoom":{const{x:C,y:E}=this.inputs.currentScreenPoint;let _=v;p==="zoom"&&(Math.abs(m)>10?_=10*Math.sign(m)/100:_=m/100);const I=y+(_??0)*h*y;this._setCamera(new b(f+(C/I-C)-(C/y-C),S+(E/I-E)-(E/y-E),I),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new b(f+x*u/y,S+m*u/y,y),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(n);const{isPen:u}=n,{isPenMode:h}=a;switch(n.name){case"pointer_down":{if(h&&!u)return;if(this.clearOpenMenus(),this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{this.dispatch({...n,point:this.inputs.currentScreenPoint,name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),n.button===hP&&(this.capturedPointerId=n.pointerId),r.buttons.add(n.button),r.isPointing=!0,r.isDragging=!1,!h&&u&&this.updateInstanceState({isPenMode:!0}),n.button===pP?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):n.button===jd&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!u&&h)return;const{x:p,y:f,z:S}=Id(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:y,previousScreenPoint:x}=this.inputs,{panSpeed:m}=c,v=b.Sub(y,x);this.setCamera(new b(p+v.x*m/S,f+v.y*m/S,S),{immediate:!0}),this.maybeTrackPerformance("Panning");return}r.isPointing&&!r.isDragging&&b.Dist2(o,i)*this.getZoomLevel()>(a.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/S&&(r.isDragging=!0,clearTimeout(this._longPressTimeout));break}case"pointer_up":{if(r.isDragging=!1,r.isPointing=!1,clearTimeout(this._longPressTimeout),r.buttons.delete(n.button),this.getIsMenuOpen()||a.isPenMode&&!u)return;if(this.capturedPointerId===n.pointerId&&(this.capturedPointerId=null,n.button=0),r.isPanning){r.keys.has("Space")||(r.isPanning=!1);const p=this.inputs.pointerVelocity,f=Math.min(2,p.len());switch(n.button){case hP:{this.setCursor({type:"grab",rotation:0});break}case jd:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}f>0&&this.slideCamera({speed:f,direction:p})}else n.button===pP&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(n.key==="ShiftRight"&&(n.key="ShiftLeft"),n.key==="AltRight"&&(n.key="AltLeft"),n.code==="ControlRight"&&(n.code="ControlLeft"),n.name){case"key_down":{r.keys.add(n.code),n.code==="Space"&&!n.ctrlKey&&(this.inputs.isPanning||(this._prevCursor=a.cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout),this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0}));break}case"key_up":{r.keys.delete(n.code),n.code==="Space"&&(this.inputs.buttons.has(jd)||(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(n.type==="pointer"){n.button===jd?n.name="middle_click":n.button===r0&&(n.name="right_click");const{isPenMode:u}=this.store.unsafeGetWithoutCapture(Sn);if(n.isPen===u){const h=this._clickManager.handlePointerEvent(n);if(n.name!==h.name){this.root.handleEvent(n),this.emit("event",n),this.root.handleEvent(h),this.emit("event",h);return}}}return this.root.handleEvent(n),this.emit("event",n),this});this.options={...nG,...p},this.store=n,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new IG({store:n,annotateError:T=>{this.annotateError(T,{origin:"history.batch",willCrashApp:!0}),this.crash(T)}}),this.snaps=new fg(this),this.timers=new AB,this.disposables.add(this.timers.dispose.bind(this.timers)),this._cameraOptions.set({...uP,...l}),this.user=new fr(r??j2(),h??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new UG(this),this._tickManager=new HG(this);class f extends Wh{}g(f,"initial",c??""),this.root=new f(this),this.root.children={};const S=KM(s),y={},x={},m=new Map;for(const T of S){const M=new T(this);y[T.type]=M;const D=u_(T.props??{});x[T.type]=D;for(const $ of D.keys())if(!m.has($.id))m.set($.id,$);else if(m.get($.id)!==$)throw Error(`Multiple style props with id "${$.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=y,this.styleProps=x;const v=BM(o),w={};for(const T of v){const M=new T(this);w[T.type]=M}this.bindingUtils=w;for(const T of[...i]){if(ms(this.root.children,T.id))throw Error(`Can't override tool with id "${T.id}"`);this.root.children[T.id]=new T(this,this.root)}this.environment=new wG(this),this.scribbles=new _G(this);const C=(T,M)=>{let D=null;const $=T.selectedShapeIds.filter(R=>!M.has(R));$.length!==T.selectedShapeIds.length&&(D||(D={...T}),D.selectedShapeIds=$);const j=T.erasingShapeIds.filter(R=>!M.has(R));j.length!==T.erasingShapeIds.length&&(D||(D={...T}),D.erasingShapeIds=j),T.hoveredShapeId&&M.has(T.hoveredShapeId)&&(D||(D={...T}),D.hoveredShapeId=null),T.editingShapeId&&M.has(T.editingShapeId)&&(D||(D={...T}),D.editingShapeId=null);const O=T.hintingShapeIds.filter(R=>!M.has(R));return O.length!==T.hintingShapeIds.length&&(D||(D={...T}),D.hintingShapeIds=O),T.focusedGroupId&&M.has(T.focusedGroupId)&&(D||(D={...T}),D.focusedGroupId=null),D};this.sideEffects=this.store.sideEffects;let E=new Map;const _=new Set,I=new Set;let k=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var T,M,D,$;_.clear();for(const j of I){I.delete(j);const O=this.getShape(j);if(!O)continue;const R=this.getShapeUtil(O),H=(T=R.onChildrenChange)==null?void 0:T.call(R,O);H!=null&&H.length&&this.updateShapes(H)}if(k.size){const j=k;k=new Set;for(const O of j){const R=this.getBindingUtil(O);(M=R.onOperationComplete)==null||M.call(R)}}if(E.size){const j=E;E=new Map;for(const O of j.values())($=(D=this.getBindingUtil(O.binding)).onAfterDelete)==null||$.call(D,O)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(T,M)=>{var D,$,j,O;for(const R of this.getBindingsInvolvingShape(M))k.add(R.type),R.fromId===M.id&&(($=(D=this.getBindingUtil(R)).onAfterChangeFromShape)==null||$.call(D,{binding:R,shapeBefore:T,shapeAfter:M})),R.toId===M.id&&((O=(j=this.getBindingUtil(R)).onAfterChangeToShape)==null||O.call(j,{binding:R,shapeBefore:T,shapeAfter:M}));if(T.parentId!==M.parentId){const R=H=>{var z,W,Y,q;const B=this.getShape(H);if(B)for(const le of this.getBindingsInvolvingShape(B))k.add(le.type),le.fromId===B.id&&((W=(z=this.getBindingUtil(le)).onAfterChangeFromShape)==null||W.call(z,{binding:le,shapeBefore:B,shapeAfter:B})),le.toId===B.id&&((q=(Y=this.getBindingUtil(le)).onAfterChangeToShape)==null||q.call(Y,{binding:le,shapeBefore:B,shapeAfter:B}))};R(M.id),this.visitDescendants(M.id,R)}if(T.parentId!==M.parentId&&Mn(M.parentId)){const R=new Set([T.id]);this.visitDescendants(T.id,H=>{R.add(H)});for(const H of this.getPageStates()){if(H.pageId===M.parentId)continue;const B=C(H,R);B&&this.store.put([B])}}T.parentId&&jn(T.parentId)&&I.add(T.parentId),M.parentId!==T.parentId&&jn(M.parentId)&&I.add(M.parentId)},beforeDelete:T=>{var j,O,R,H;if(_.has(T.id))return;T.parentId&&jn(T.parentId)&&I.add(T.parentId),_.add(T.id);const M=[];for(const B of this.getBindingsInvolvingShape(T)){k.add(B.type),M.push(B.id);const z=this.getBindingUtil(B);B.fromId===T.id?((j=z.onBeforeIsolateToShape)==null||j.call(z,{binding:B,removedShape:T}),(O=z.onBeforeDeleteFromShape)==null||O.call(z,{binding:B,shape:T})):((R=z.onBeforeIsolateFromShape)==null||R.call(z,{binding:B,removedShape:T}),(H=z.onBeforeDeleteToShape)==null||H.call(z,{binding:B,shape:T}))}M.length&&this.deleteBindings(M);const D=new Set([T.id]),$=ye(this.getPageStates().map(B=>C(B,D)));$.length&&this.store.put($)}},binding:{beforeCreate:T=>{var D,$;const M=($=(D=this.getBindingUtil(T)).onBeforeCreate)==null?void 0:$.call(D,{binding:T});return M||T},afterCreate:T=>{var M,D;k.add(T.type),(D=(M=this.getBindingUtil(T)).onAfterCreate)==null||D.call(M,{binding:T})},beforeChange:(T,M)=>{var $,j;const D=(j=($=this.getBindingUtil(M)).onBeforeChange)==null?void 0:j.call($,{bindingBefore:T,bindingAfter:M});return D||M},afterChange:(T,M)=>{var D,$;k.add(M.type),($=(D=this.getBindingUtil(M)).onAfterChange)==null||$.call(D,{bindingBefore:T,bindingAfter:M})},beforeDelete:T=>{var M,D;(D=(M=this.getBindingUtil(T)).onBeforeDelete)==null||D.call(M,{binding:T})},afterDelete:T=>{var M,D;(D=(M=this.getBindingUtil(T)).onAfterDelete)==null||D.call(M,{binding:T}),k.add(T.type)}},page:{afterCreate:T=>{const M=hs.createId(T.id),D=Br.createId(T.id);this.store.has(M)||this.store.put([hs.create({id:M})]),this.store.has(D)||this.store.put([Br.create({id:D,pageId:T.id})])},afterDelete:(T,M)=>{var j,O;if(((j=this.getInstanceState())==null?void 0:j.currentPageId)===T.id){const R=(O=this.getPages().find(H=>H.id!==T.id))==null?void 0:O.id;R?this.store.put([{...this.getInstanceState(),currentPageId:R}]):M==="user"&&this.store.ensureStoreIsUsable()}const D=hs.createId(T.id),$=Br.createId(T.id);this.store.remove([D,$])}},instance:{afterChange:(T,M,D)=>{var $;if(!this.store.has(M.currentPageId)){const j=this.store.has(T.currentPageId)?T.currentPageId:($=this.getPages()[0])==null?void 0:$.id;j?this.store.update(M.id,O=>({...O,currentPageId:j})):D==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(T,M)=>{if((T==null?void 0:T.selectedShapeIds)!==(M==null?void 0:M.selectedShapeIds)){const D=M.selectedShapeIds.filter(j=>{var R,H;let O=(R=this.getShape(j))==null?void 0:R.parentId;for(;jn(O);){if(M.selectedShapeIds.includes(O))return!1;O=(H=this.getShape(O))==null?void 0:H.parentId}return!0});let $=null;if(D.length>0){const j=this.findCommonAncestor(ye(D.map(O=>this.getShape(O))),O=>this.isShapeOfType(O,"group"));j&&($=j)}else M!=null&&M.focusedGroupId&&($=M.focusedGroupId);(D.length!==M.selectedShapeIds.length||$!==M.focusedGroupId)&&this.store.put([{...M,selectedShapeIds:D,focusedGroupId:$??null}])}}}})),this._currentPageShapeIds=gG(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=fG(this.store),this.disposables.add(this.store.listen(T=>{this.emit("change",T)})),this.disposables.add(this.history.dispose),this.run(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})},{history:"ignore"}),c&&this.root.children[c]===void 0)throw Error(`No state found for initialState "${c}".`);this.root.enter(void 0,"initial"),this.edgeScrollManager=new xG(this),this.focusManager=new bG(this,u),this.disposables.add(this.focusManager.dispose.bind(this.focusManager)),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.on("tick",this._flushEventsForTick),this.timers.requestAnimationFrame(()=>{this._tickManager.start()}),this.performanceTracker=new Nk}dispose(){this.disposables.forEach(n=>n()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(n){const r=typeof n=="string"?n:n.type,s=$n(this.shapeUtils,r);return Xe(s,`No shape util found for type "${r}"`),s}getBindingUtil(n){const r=typeof n=="string"?n:n.type,s=$n(this.bindingUtils,r);return Xe(s,`No binding util found for type "${r}"`),s}undo(){return this._flushEventsForTick(0),this.complete(),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.complete(),this.history.redo(),this}clearHistory(){return this.history.clear(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(n){return this.history.mark(n),this}squashToMark(n){return this.history.squashToMark(n),this}bail(){return this.history.bail(),this}bailToMark(n){return this.history.bailToMark(n),this}run(n,r){const s=this._shouldIgnoreShapeLock;this._shouldIgnoreShapeLock=(r==null?void 0:r.ignoreShapeLock)??s;try{this.history.batch(n,r)}finally{this._shouldIgnoreShapeLock=s}return this}batch(n,r){return this.run(n,r)}annotateError(n,{origin:r,willCrashApp:s,tags:o,extras:i}){const a=this.createErrorAnnotations(r,s);return zx(n,{tags:{...a.tags,...o},extras:{...a.extras,...i}}),s&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(n,r){try{const s=this.getEditingShapeId();return{tags:{origin:n,willCrashApp:r},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes(),editingShape:s?this.getShape(s):void 0,inputs:this.inputs}}}catch{return{tags:{origin:n,willCrashApp:r},extras:{}}}}getCrashingError(){return this._crashingError}crash(n){return this._crashingError=n,this.store.markAsPossiblyCorrupted(),this.emit("crash",{error:n}),this}getPath(){return this.root.getPath().split("root.")[1]}isIn(n){const r=n.split(".").reverse();let s=this.root;for(;r.length>0;){const o=r.pop();if(!o)return!0;const i=s.getCurrent();if((i==null?void 0:i.id)===o){if(r.length===0)return!0;s=i;continue}else return!1}return!1}isInAny(...n){return n.some(r=>this.isIn(r))}setCurrentTool(n,r={}){return this.root.transition(n,r),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const n=this.getCurrentTool();return n?n.getCurrentToolIdMask()??n.id:""}getStateDescendant(n){var o;const r=n.split(".").reverse();let s=this.root;for(;r.length>0;){const i=r.pop();if(!i)return s;const a=(o=s.children)==null?void 0:o[i];if(!a)return;s=a}return s}getDocumentSettings(){return this.store.get(ES)}updateDocumentSettings(n){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...n}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(Sn)}updateInstanceState(n,r){return this._updateInstanceState(n,{history:"ignore",...r}),n.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),n.isChangingStyle===!0&&(this._isChangingStyleTimeout=this.timers.setTimeout(()=>{this._updateInstanceState({isChangingStyle:!1},{history:"ignore"})},2e3))),this}getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(n){const r=new Set(this.getOpenMenus());return r.has(n)||(r.add(n),this.updateInstanceState({openMenus:[...r]})),this}deleteOpenMenu(n){const r=new Set(this.getOpenMenus());return r.has(n)&&(r.delete(n),this.updateInstanceState({openMenus:[...r]})),this}clearOpenMenus(){return this.getOpenMenus().length&&this.updateInstanceState({openMenus:[]}),this}getIsMenuOpen(){return this.getOpenMenus().length>0}getPageStates(){return this._getPageStatesQuery().get()}_getPageStatesQuery(){return this.store.query.records("instance_page_state")}getCurrentPageState(){return this.store.get(this._getCurrentPageStateId())}_getCurrentPageStateId(){return Br.createId(this.getCurrentPageId())}updateCurrentPageState(n){return this._updateCurrentPageState(n),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:n}=this.getCurrentPageState();return ye(n.map(r=>this.store.get(r)))}setSelectedShapes(n){return this.run(()=>{const r=n.map(i=>typeof i=="string"?i:i.id),{selectedShapeIds:s}=this.getCurrentPageState(),o=new Set(s);if(r.length===o.size&&r.every(i=>o.has(i)))return null;this.store.put([{...this.getCurrentPageState(),selectedShapeIds:r}])},{history:"record-preserveRedoStack"})}isAncestorSelected(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null,s=this.getShape(r);if(!s)return!1;const o=this.getSelectedShapeIds();return!!this.findShapeAncestor(s,i=>o.includes(i.id))}select(...n){const r=typeof n[0]=="string"?n:n.map(s=>s.id);return this.setSelectedShapes(r),this}deselect(...n){const r=typeof n[0]=="string"?n:n.map(o=>o.id),s=this.getSelectedShapeIds();return s.length>0&&r.length>0&&this.setSelectedShapes(s.filter(o=>!r.includes(o))),this}selectAll(){const n=this.getSortedChildIdsForParent(this.getCurrentPageId());return n.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(n)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var n;return((n=this.getOnlySelectedShape())==null?void 0:n.id)??null}getOnlySelectedShape(){const n=this.getSelectedShapes();return n.length===1?n[0]:null}getSelectionPageBounds(){const n=this.getCurrentPageState().selectedShapeIds;return n.length===0?null:Q.Common(ye(n.map(r=>this.getShapePageBounds(r))))}getSelectionRotation(){const n=this.getSelectedShapeIds();let r=!1,s=0;for(let o=0,i=n.length;o<i;o++){const a=this.getShapePageTransform(n[o]);if(a)if(r){if(a.rotation()!==s)return 0}else r=!0,s=a.rotation()}return s}getSelectionRotatedPageBounds(){const n=this.getSelectedShapeIds();if(n.length===0)return;const r=this.getSelectionRotation();if(r===0)return this.getSelectionPageBounds();if(n.length===1){const o=this.getShapeGeometry(n[0]).bounds.clone(),i=this.getShapePageTransform(n[0]);return o.point=i.applyToPoint(o.point),o}const s=Q.FromPoints(this.getSelectedShapeIds().flatMap(o=>{const i=this.getShapePageTransform(o);return i?i.applyToPoints(this.getShapeGeometry(o).bounds.corners):[]}).map(o=>o.rot(-r)));return s.point=s.point.rot(r),s}getSelectionRotatedScreenBounds(){const n=this.getSelectionRotatedPageBounds();if(!n)return;const{x:r,y:s}=this.pageToScreen(n.point),o=this.getZoomLevel();return new Q(r,s,n.width*o,n.height*o)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const n=this.getFocusedGroupId();return n?this.getShape(n):void 0}setFocusedGroup(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;if(r!==null){const s=this.getShape(r);if(!s)throw Error(`Editor.setFocusedGroup: Shape with id ${r} does not exist`);if(!this.isShapeOfType(s,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${s.type}`)}return r===this.getFocusedGroupId()?this:this.run(()=>{this.store.update(this.getCurrentPageState().id,s=>({...s,focusedGroupId:r}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const n=this.getFocusedGroup();if(n){const r=this.findShapeAncestor(n,s=>this.isShapeOfType(s,"group"));this.setFocusedGroup((r==null?void 0:r.id)??null),this.select(n.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const n=this.getEditingShapeId();return n?this.getShape(n):void 0}setEditingShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;if(r!==this.getEditingShapeId()){if(r){const s=this.getShape(r);if(s&&this.getShapeUtil(s).canEdit(s))return this.run(()=>{this._updateCurrentPageState({editingShapeId:r})},{history:"ignore"}),this}this.run(()=>{this._updateCurrentPageState({editingShapeId:null})},{history:"ignore"})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const n=this.getHoveredShapeId();return n?this.getShape(n):void 0}setHoveredShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;return r===this.getHoveredShapeId()?this:(this.run(()=>{this.updateCurrentPageState({hoveredShapeId:r})},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const n=this.getHintingShapeIds();return ye(n.map(r=>this.getShape(r)))}setHintingShapes(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id);return this.run(()=>{this._updateCurrentPageState({hintingShapeIds:Fx(r)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const n=this.getErasingShapeIds();return ye(n.map(r=>this.getShape(r)))}setErasingShapes(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);r.sort();const s=this.getErasingShapeIds();return this.run(()=>{if(r.length===s.length){for(let o=0;o<r.length;o++)if(r[o]!==s[o]){this._updateCurrentPageState({erasingShapeIds:r});break}}else this._updateCurrentPageState({erasingShapeIds:r})},{history:"ignore"}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;return r!==this.getCroppingShapeId()&&this.run(()=>{if(!r)this.updateCurrentPageState({croppingShapeId:null});else{const s=this.getShape(r),o=this.getShapeUtil(s);s&&o.canCrop(s)&&this.updateCurrentPageState({croppingShapeId:r})}},{history:"ignore"}),this}_unsafe_getCameraId(){return hs.createId(this.getCurrentPageId())}getCamera(){const n=this.store.get(this._unsafe_getCameraId());if(this._isLockedOnFollowingUser.get()){const r=this.getCameraForFollowing();if(r)return{...n,...r}}return n}getViewportPageBoundsForFollowing(){const n=this.getInstanceState().followingUserId;if(!n)return null;const r=this.getCollaborators().find(p=>p.userId===n);if(!r)return null;const{w:s,h:o}=r.screenBounds,{x:i,y:a,z:l}=r.camera,c=new Q(-i,-a,s/l,o/l),u=this.getViewportScreenBounds().clone(),h=u.width/u.height;return u.width=c.width,u.height=u.width/h,u.height<c.height&&(u.height=c.height,u.width=u.height*h),u.center=c.center,u}getCameraForFollowing(){const n=this.getViewportPageBoundsForFollowing();return n?{x:-n.x,y:-n.y,z:this.getViewportScreenBounds().w/n.width}:null}getZoomLevel(){return this.getCamera().z}getInitialZoom(){const n=this.getCameraOptions();if(!n.constraints||n.constraints.initialZoom==="default")return 1;const{zx:r,zy:s}=KC(this,n);switch(n.constraints.initialZoom){case"fit-min":return Math.max(r,s);case"fit-max":return Math.min(r,s);case"fit-x":return r;case"fit-y":return s;case"fit-min-100":return Math.min(1,Math.max(r,s));case"fit-max-100":return Math.min(1,Math.min(r,s));case"fit-x-100":return Math.min(1,r);case"fit-y-100":return Math.min(1,s);default:throw un(n.constraints.initialZoom)}}getBaseZoom(){const n=this.getCameraOptions();if(!n.constraints||n.constraints.baseZoom==="default")return 1;const{zx:r,zy:s}=KC(this,n);switch(n.constraints.baseZoom){case"fit-min":return Math.max(r,s);case"fit-max":return Math.min(r,s);case"fit-x":return r;case"fit-y":return s;case"fit-min-100":return Math.min(1,Math.max(r,s));case"fit-max-100":return Math.min(1,Math.min(r,s));case"fit-x-100":return Math.min(1,r);case"fit-y-100":return Math.min(1,s);default:throw un(n.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(n){var s;const r=Ge({...this._cameraOptions.__unsafe__getWithoutCapture(),...n});return((s=r.zoomSteps)==null?void 0:s.length)<1&&(r.zoomSteps=[1]),this._cameraOptions.set(r),this}getConstrainedCamera(n,r){const s=this.getCamera();let{x:o,y:i,z:a=s.z}=n;if(!(r!=null&&r.force)){const l=this.getCameraOptions(),c=l.zoomSteps[0],u=Ut(l.zoomSteps),h=this.getViewportScreenBounds();if(l.constraints){const{constraints:p}=l,f=Math.min(p.padding.y,h.w/2),S=Math.min(p.padding.x,h.h/2),y=Q.From(l.constraints.bounds),x=(h.w-S*2)/y.w,m=(h.h-f*2)/y.h,v=this.getBaseZoom(),w=u*v,C=c*v;if(r!=null&&r.reset&&(a=this.getInitialZoom()),a<C||a>w){const{x:j,y:O,z:R}=s,H=-j+h.w/R/2,B=-O+h.h/R/2;a=_t(a,C,w);const z=-j+h.w/a/2,W=-O+h.h/a/2;o=j+z-H,i=O+W-B}const E=S/a-y.x,_=f/a-y.y,I=(h.w-S*2)/a-y.w,k=(h.h-f*2)/a-y.h,T=E+I*p.origin.x,M=_+k*p.origin.y,D=typeof p.behavior=="string"?p.behavior:p.behavior.x,$=typeof p.behavior=="string"?p.behavior:p.behavior.y;if(r!=null&&r.reset)o=T,i=M;else{switch(D){case"fixed":{o=T;break}case"contain":{a<x?o=T:o=_t(o,E+I,E);break}case"inside":{a<x?o=_t(o,E,(h.w-S)/a-y.w):o=_t(o,E+I,E);break}case"outside":{o=_t(o,S/a-y.w,(h.w-S)/a);break}case"free":break;default:throw un(D)}switch($){case"fixed":{i=M;break}case"contain":{a<m?i=M:i=_t(i,_+k,_);break}case"inside":{a<m?i=_t(i,_,(h.h-f)/a-y.h):i=_t(i,_+k,_);break}case"outside":{i=_t(i,f/a-y.h,(h.h-f)/a);break}case"free":break;default:throw un($)}}}else if(a>u||a<c){const{x:p,y:f,z:S}=s;a=_t(a,c,u),o=p+(-p+h.w/a/2)-(-p+h.w/S/2),i=f+(-f+h.h/a/2)-(-f+h.h/S/2)}}return{x:o,y:i,z:a}}_setCamera(n,r){const s=this.getCamera(),{x:o,y:i,z:a}=this.getConstrainedCamera(n,r);return s.x===o&&s.y===i&&s.z===a?this:(gs(()=>{const l={...s,x:o,y:i,z:a};this.run(()=>{this.store.put([l])},{history:"ignore"});const{currentScreenPoint:c,currentPagePoint:u}=this.inputs,{screenBounds:h}=this.store.unsafeGetWithoutCapture(Sn);if(c.x/a-o!==u.x||c.y/a-i!==u.y){const p={type:"pointer",target:"canvas",name:"pointer_move",point:b.AddXY(c,h.x,h.y),pointerId:dP.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,button:0,isPen:this.getInstanceState().isPenMode??!1};r!=null&&r.immediate?this._flushEventForTick(p):this.dispatch(p)}this._tickCameraState()}),this)}setCamera(n,r){const{isLocked:s}=this._cameraOptions.__unsafe__getWithoutCapture();if(s&&!(r!=null&&r.force))return this;this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser();const o=b.Cast(n);Number.isFinite(o.x)||(o.x=0),Number.isFinite(o.y)||(o.y=0),(o.z===void 0||!Number.isFinite(o.z))&&(n.z=this.getZoomLevel());const i=this.getConstrainedCamera(o,r);if(r!=null&&r.animation){const{width:a,height:l}=this.getViewportScreenBounds();this._animateToViewport(new Q(-i.x,-i.y,a/i.z,l/i.z),r)}else this._setCamera(i,{...r,force:!0});return this}centerOnPoint(n,r){const{isLocked:s}=this.getCameraOptions();if(s&&!(r!=null&&r.force))return this;const{width:o,height:i}=this.getViewportPageBounds();return this.setCamera(new b(-(n.x-o/2),-(n.y-i/2),this.getCamera().z),r),this}zoomToFit(n){const r=[...this.getCurrentPageShapeIds()];if(r.length<=0)return this;const s=Q.Common(ye(r.map(o=>this.getShapePageBounds(o))));return this.zoomToBounds(s,n),this}resetZoom(n=this.getViewportScreenCenter(),r){const{isLocked:s,constraints:o}=this.getCameraOptions();if(s&&!(r!=null&&r.force))return this;const i=this.getCamera(),{x:a,y:l,z:c}=i,{x:u,y:h}=n;let p=1;if(o){const f=this.getInitialZoom();c!==f&&(p=f)}return this.setCamera(new b(a+(u/p-u)-(u/c-u),l+(h/p-h)-(h/c-h),p),r),this}zoomIn(n=this.getViewportScreenCenter(),r){const{isLocked:s}=this.getCameraOptions();if(s&&!(r!=null&&r.force))return this;const{x:o,y:i,z:a}=this.getCamera(),{zoomSteps:l}=this.getCameraOptions();if(l!==null&&l.length>1){const c=this.getBaseZoom();let u=Ut(l)*c;for(let h=1;h<l.length;h++){const p=l[h-1]*c,f=l[h]*c;if(!(f-a<=(f-p)/2)){u=f;break}}this.setCamera(new b(o+(n.x/u-n.x)-(n.x/a-n.x),i+(n.y/u-n.y)-(n.y/a-n.y),u),r)}return this}zoomOut(n=this.getViewportScreenCenter(),r){const{isLocked:s}=this.getCameraOptions();if(s&&!(r!=null&&r.force))return this;const{zoomSteps:o}=this.getCameraOptions();if(o!==null&&o.length>1){const i=this.getBaseZoom(),{x:a,y:l,z:c}=this.getCamera();let u=o[0]*i;for(let h=o.length-1;h>0;h--){const p=o[h-1]*i,f=o[h]*i;if(!(f-c>=(f-p)/2)){u=p;break}}this.setCamera(new b(a+(n.x/u-n.x)-(n.x/c-n.x),l+(n.y/u-n.y)-(n.y/c-n.y),u),r)}return this}zoomToSelection(n){const{isLocked:r}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const s=this.getSelectionPageBounds();return s&&this.zoomToBounds(s,{targetZoom:Math.max(1,this.getZoomLevel()),...n}),this}zoomToBounds(n,r){const s=this._cameraOptions.__unsafe__getWithoutCapture();if(s.isLocked&&!(r!=null&&r.force))return this;const o=this.getViewportScreenBounds(),i=(r==null?void 0:r.inset)??Math.min(w9,o.width*.28),a=this.getBaseZoom(),l=s.zoomSteps[0],c=Ut(s.zoomSteps);let u=_t(Math.min((o.width-i)/n.w,(o.height-i)/n.h),l*a,c*a);return(r==null?void 0:r.targetZoom)!==void 0&&(u=Math.min(r.targetZoom,u)),this.setCamera(new b(-n.x+(o.width-n.w*u)/2/u,-n.y+(o.height-n.h*u)/2/u,u),r),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(n){if(!this._viewportAnimation)return;this._viewportAnimation.elapsed+=n;const{elapsed:r,easing:s,duration:o,start:i,end:a}=this._viewportAnimation;if(r>o){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new b(-a.x,-a.y,this.getViewportScreenBounds().width/a.width));return}const l=o-r,c=s(1-l/o),u=i.minX+(a.minX-i.minX)*c,h=i.minY+(a.minY-i.minY)*c,p=i.maxX+(a.maxX-i.maxX)*c;this._setCamera(new b(-u,-h,this.getViewportScreenBounds().width/(p-u)),{force:!0})}_animateToViewport(n,r={animation:Tm}){const{animation:s,...o}=r;if(!s)return;const{duration:i=0,easing:a=At.easeInOutCubic}=s,l=this.user.getAnimationSpeed(),c=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),i===0||l===0?this._setCamera(new b(-n.x,-n.y,this.getViewportScreenBounds().width/n.width),{...o}):(this._viewportAnimation={elapsed:0,duration:i/l,easing:a,start:c.clone(),end:n.clone()},this.once("stop-camera-animation",()=>{this.off("tick",this._animateViewport),this._viewportAnimation=null}),this.on("tick",this._animateViewport),this)}slideCamera(n={}){const{isLocked:r}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;if(this.user.getAnimationSpeed()===0)return this;this.stopCameraAnimation();const{speed:o,friction:i=this.options.cameraSlideFriction,direction:a,speedThreshold:l=.01}=n;let c=Math.min(o,1);const u=()=>{this.off("tick",h),this.off("stop-camera-animation",u)};this.once("stop-camera-animation",u);const h=p=>{const{x:f,y:S,z:y}=this.getCamera(),x=b.Mul(a,c*p/y);c*=1-i,c<l?u():this._setCamera(new b(f+x.x,S+x.y,y))};return this.on("tick",h),this}zoomToUser(n,r={animation:{duration:500}}){const s=this.getCollaborators().find(o=>o.userId===n);return s?(this.run(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const o=s.currentPageId===this.getCurrentPageId();o||this.setCurrentPage(s.currentPageId),r&&r.animation&&!o&&(r.animation=void 0),this.centerOnPoint(s.cursor,r);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,n]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],l=a.indexOf(n);l<0||(a.splice(l,1),this.updateInstanceState({highlightedUserIds:a}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(n,r=!1){n.width=Math.max(n.width,1),n.height=Math.max(n.height,1);const s=[n.minY!==0,!$o(document.body.scrollWidth,n.maxX,1),!$o(document.body.scrollHeight,n.maxY,1),n.minX!==0],{screenBounds:o,insets:i}=this.getInstanceState();if(n.equals(o)&&s.every((l,c)=>l===i[c]))return this;const{_willSetInitialBounds:a}=this;if(this._willSetInitialBounds=!1,a)this.updateInstanceState({screenBounds:n.toJson(),insets:s}),this.setCamera(this.getCamera());else if(r&&!this.getInstanceState().followingUserId){const l=this.getViewportPageBounds().center;this.updateInstanceState({screenBounds:n.toJson(),insets:s}),this.centerOnPoint(l)}else this.updateInstanceState({screenBounds:n.toJson(),insets:s}),this._setCamera(b.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:n,y:r,w:s,h:o}=this.getInstanceState().screenBounds;return new Q(n,r,s,o)}getViewportScreenCenter(){const n=this.getViewportScreenBounds();return new b(n.midX-n.minX,n.midY-n.minY)}getViewportPageBounds(){const{w:n,h:r}=this.getViewportScreenBounds(),{x:s,y:o,z:i}=this.getCamera();return new Q(-s,-o,n/i,r/i)}screenToPage(n){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(Sn),{x:s,y:o,z:i=1}=this.getCamera();return new b((n.x-r.x)/i-s,(n.y-r.y)/i-o,n.z??.5)}pageToScreen(n){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(Sn),{x:s,y:o,z:i=1}=this.getCamera();return new b((n.x+s)*i+r.x,(n.y+o)*i+r.y,n.z??.5)}pageToViewport(n){const{x:r,y:s,z:o=1}=this.getCamera();return new b((n.x+r)*o,(n.y+s)*o,n.z??.5)}_getCollaboratorsQuery(){return this.store.query.records("instance_presence",()=>({userId:{neq:this.user.getId()}}))}getCollaborators(){const n=this._getCollaboratorsQuery().get();return n.length?[...new Set(n.map(s=>s.userId))].sort().map(s=>n.filter(i=>i.userId===s).sort((i,a)=>a.lastActivityTimestamp-i.lastActivityTimestamp)[0]):Gs}getCollaboratorsOnCurrentPage(){const n=this.getCurrentPageId();return this.getCollaborators().filter(r=>r.currentPageId===n)}startFollowingUser(n){this.stopFollowingUser();const r=this._getCollaboratorsQuery().get().filter(i=>i.userId===n);if(!r.length)return console.warn("User not found"),this;const s=this.user.getId();if(s||console.warn("You should set the userId for the current instance before following a user"),r.some(i=>i.followingUserId===s))return this;const o=G("latestLeaderPresence",()=>this.getCollaborators().find(i=>i.userId===n));return gs(()=>{this.updateInstanceState({followingUserId:n},{history:"ignore"});const i=ra("update current page",()=>{const c=o.get();if(!c){this.stopFollowingUser();return}c.currentPageId!==this.getCurrentPageId()&&this.getPage(c.currentPageId)&&this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:c.currentPageId}]),this._isLockedOnFollowingUser.set(!0)},{history:"ignore"})}),a=()=>{i(),this._isLockedOnFollowingUser.set(!1),this.off("frame",l),this.off("stop-following",a)},l=()=>{if(!o.get()){this.stopFollowingUser();return}if(this._isLockedOnFollowingUser.get())return;const u=this.user.getAnimationSpeed();if(u===0){this._isLockedOnFollowingUser.set(!0);return}const h=this.getViewportPageBoundsForFollowing();if(!h){this.stopFollowingUser();return}const p=this.getViewportPageBounds(),f=Math.abs(h.minX-p.minX)+Math.abs(h.maxX-p.maxX),S=Math.abs(h.minY-p.minY)+Math.abs(h.maxY-p.maxY);if(f<this.options.followChaseViewportSnap&&S<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const y=_t(u*.5,.1,.8),x=new Q(On(p.minX,h.minX,y),On(p.minY,h.minY,y),On(p.width,h.width,y),On(p.height,h.height,y)),m=new b(-x.x,-x.y,this.getViewportScreenBounds().width/x.width);this.stopCameraAnimation(),this._setCamera(m)};this.once("stop-following",a),this.addListener("frame",l),l()}),this}stopFollowingUser(){return this.run(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")},{history:"ignore"}),this}getUnorderedRenderingShapes(n){const r=[];let s=this.options.maxShapesPerPage*2,o=this.options.maxShapesPerPage;const i=this.getErasingShapeIds(),a=(c,u,h)=>{const p=this.getShape(c);if(!p)return;u*=p.opacity;let f=!1;const S=this.getShapeUtil(p);n&&(f=!h&&i.includes(c),f&&(u*=.32)),r.push({id:c,shape:p,util:S,index:s,backgroundIndex:o,opacity:u}),s+=1,o+=1;const y=this.getSortedChildIdsForParent(c);if(!y.length)return;let x=null;S.providesBackgroundForChildren(p)&&(x=o,o=s,s+=this.options.maxShapesPerPage);for(const m of y)a(m,u,h||f);x!==null&&(o=x)},l=n?[this.getCurrentPage()]:this.getPages();for(const c of l)for(const u of this.getSortedChildIdsForParent(c.id))a(u,1,!1);return r}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(IB)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(ln)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(n){return this.store.get(typeof n=="string"?n:n.id)}getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getCurrentPageShapeIdsSorted(){return Array.from(this.getCurrentPageShapeIds()).sort()}getPageShapeIds(n){const r=typeof n=="string"?n:n.id,s=this.store.query.exec("shape",{parentId:{eq:r}});return this.getShapeAndDescendantIds(s.map(o=>o.id))}setCurrentPage(n){const r=typeof n=="string"?n:n.id;return this.store.has(r)?(this.stopFollowingUser(),this.complete(),this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:r}])},{history:"record-preserveRedoStack"})):(console.error("Tried to set the current page id to a page that doesn't exist."),this)}updatePage(n){return this.getInstanceState().isReadonly?this:this.getPage(n.id)?this.run(()=>this.store.update(n.id,s=>({...s,...n}))):this}createPage(n){return this.run(()=>{if(this.getInstanceState().isReadonly||this.getPages().length>=this.options.maxPages)return;const r=this.getPages(),s=iG(n.name??"Page 1",r.map(a=>a.name));let o=n.index;(!o||r.some(a=>a.index===o))&&(o=zr(r[r.length-1].index));const i=Qs.create({meta:{},...n,name:s,index:o});this.store.put([i])}),this}deletePage(n){const r=typeof n=="string"?n:n.id;return this.run(()=>{if(this.getInstanceState().isReadonly)return;const s=this.getPages();if(s.length===1)return;const o=this.getPage(r);if(o){if(r===this.getCurrentPageId()){const i=s.findIndex(l=>l.id===r),a=s[i-1]??s[i+1];this.setCurrentPage(a.id)}this.store.remove([o.id])}}),this}duplicatePage(n,r=Qs.createId()){if(this.getPages().length>=this.options.maxPages)return this;const s=typeof n=="string"?n:n.id,o=this.getPage(s);if(!o)return this;const i={...this.getCamera()},a=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(o.id));return this.run(()=>{var u;const l=this.getPages(),c=ru(o.index,(u=l[l.indexOf(o)+1])==null?void 0:u.index);if(this.createPage({name:o.name+" Copy",id:r,index:c}),this.setCurrentPage(r),this.setCamera(i),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(n,r){const s=typeof n=="string"?n:n.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:s,name:r}),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(n){return this.getInstanceState().isReadonly?this:n.length<=0?this:(this.run(()=>this.store.put(n),{history:"ignore"}),this)}updateAssets(n){return this.getInstanceState().isReadonly?this:n.length<=0?this:(this.run(()=>{this.store.put(n.map(r=>({...this.store.get(r.id),...r})))},{history:"ignore"}),this)}deleteAssets(n){if(this.getInstanceState().isReadonly)return this;const r=typeof n[0]=="string"?n:n.map(s=>s.id);return r.length<=0?this:(this.run(()=>this.store.remove(r),{history:"ignore"}),this)}getAsset(n){return this.store.get(typeof n=="string"?n:n.id)}async resolveAssetUrl(n,r){if(!n)return null;const s=this.getAsset(n);if(!s)return null;const{screenScale:o=1,shouldResolveToOriginal:i=!1}=r,l=Math.max(.125,(h=>Math.pow(2,Math.ceil(Math.log2(h))))(o)),c="connection"in navigator?navigator.connection.effectiveType:null,u=this.getInstanceState().devicePixelRatio;return await this.store.props.assets.resolve(s,{screenScale:o||1,steppedScreenScale:l,dpr:u,networkEffectiveType:c,shouldResolveToOriginal:i})}async uploadAsset(n,r){return await this.store.props.assets.upload(n,r)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",n=>this.getShapeUtil(n).getGeometry(n),(n,r)=>n.props===r.props)}getShapeGeometry(n){return this._getShapeGeometryCache().get(typeof n=="string"?n:n.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",n=>{var r,s;return(s=(r=this.getShapeUtil(n)).getHandles)==null?void 0:s.call(r,n)})}getShapeHandles(n){return this._getShapeHandlesCache().get(typeof n=="string"?n:n.id)}getShapeLocalTransform(n){const r=typeof n=="string"?n:n.id,s=this.getShape(r);if(!s)throw Error("Editor.getTransform: shape not found");return oe.Identity().translate(s.x,s.y).rotate(s.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",n=>{if(Mn(n.parentId))return this.getShapeLocalTransform(n);const r=this._getShapePageTransformCache().get(n.parentId)??oe.Identity();return oe.Compose(r,this.getShapeLocalTransform(n))})}getShapeParentTransform(n){const r=typeof n=="string"?n:n.id,s=this.getShape(r);return!s||Mn(s.parentId)?oe.Identity():this._getShapePageTransformCache().get(s.parentId)??oe.Identity()}getShapePageTransform(n){const r=typeof n=="string"?n:n.id;return this._getShapePageTransformCache().get(r)??oe.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",n=>{const r=this._getShapePageTransformCache().get(n.id);return r?Q.FromPoints(oe.applyToPoints(r,this.getShapeGeometry(n).vertices)):new Q})}getShapePageBounds(n){return this._getShapePageBoundsCache().get(typeof n=="string"?n:n.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",n=>{const r=this._getShapeMaskCache().get(n.id);if(!r)return;if(r.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const s=this._getShapePageTransformCache().get(n.id);return s?`polygon(${oe.applyToPoints(oe.Inverse(s),r).map(i=>`${i.x}px ${i.y}px`).join(",")})`:void 0})}getShapeClipPath(n){return this._getShapeClipPathCache().get(typeof n=="string"?n:n.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",n=>{if(Mn(n.parentId))return;const r=this.getShapeAncestors(n.id).filter(o=>this.isShapeOfType(o,"frame"));return r.length===0?void 0:r.map(o=>this._getShapePageTransformCache().get(o.id).applyToPoints(this.getShapeGeometry(o).vertices)).reduce((o,i)=>{if(!(i&&o))return;const a=$C(o,i);return a?a.map(b.Cast):[]})})}getShapeMask(n){return this._getShapeMaskCache().get(typeof n=="string"?n:n.id)}getShapeMaskedPageBounds(n){return typeof n!="string"&&(n=n.id),this._getShapeMaskedPageBoundsCache().get(n)}_getShapeMaskedPageBoundsCache(){return this.store.createComputedCache("shapeMaskedPageBoundsCache",n=>{const r=this._getShapePageBoundsCache().get(n.id);if(!r)return;const s=this._getShapeMaskCache().get(n.id);if(s){if(s.length===0)return;const{corners:o}=r;if(o.every((a,l)=>a&&b.Equals(a,s[l])))return r.clone();const i=$C(s,o);return i?Q.FromPoints(i):void 0}return r})}getShapeAncestors(n,r=[]){const s=typeof n=="string"?n:n.id,o=this.getShape(s);if(!o)return r;const i=o.parentId;if(Mn(i))return r.reverse(),r;const a=this.store.get(i);return a?(r.push(a),this.getShapeAncestors(a,r)):r}findShapeAncestor(n,r){const s=typeof n=="string"?n:n.id,o=this.getShape(s);if(!o)return;const i=o.parentId;if(Mn(i))return;const a=this.getShape(i);if(a)return r(a)?a:this.findShapeAncestor(a,r)}hasAncestor(n,r){const s=typeof n=="string"?n:n==null?void 0:n.id,o=s&&this.getShape(s);return o?o.parentId===r?!0:this.hasAncestor(this.getShapeParent(o),r):!1}findCommonAncestor(n,r){var c;if(n.length===0)return;const s=typeof n[0]=="string"?n:n.map(u=>u.id),o=ye(s.map(u=>this.getShape(u)));if(o.length===1){const u=o[0].parentId;return Mn(u)?void 0:r?(c=this.findShapeAncestor(o[0],r))==null?void 0:c.id:u}const[i,...a]=o;let l=this.getShapeParent(i);for(;l;){if(r&&!r(l)){l=this.getShapeParent(l);continue}if(a.every(u=>this.hasAncestor(u,l.id)))return l.id;l=this.getShapeParent(l)}}isShapeOrAncestorLocked(n){const r=typeof n=="string"?this.getShape(n):n;return r===void 0?!1:r.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(r))}_notVisibleShapes(){return pG(this)}getCulledShapes(){const n=this._notVisibleShapes().get(),r=this.getSelectedShapeIds(),s=this.getEditingShapeId(),o=new Set(n);return s&&o.delete(s),r.forEach(i=>{o.delete(i)}),o}getCurrentPageBounds(){let n;return this.getCurrentPageShapeIdsSorted().forEach(r=>{const s=this.getShapeMaskedPageBounds(r);s&&(n?n=n.expand(s):n=s.clone())}),n}getSelectedShapeAtPoint(n){const r=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(s=>s.type!=="group"&&r.includes(s.id)).reverse().find(s=>this.isPointInShape(s,n,{hitInside:!0,margin:0}))}getShapeAtPoint(n,r={}){const s=this.getZoomLevel(),o=this.getViewportPageBounds(),{filter:i,margin:a=0,hitLocked:l=!1,hitLabels:c=!1,hitInside:u=!1,hitFrameInside:h=!1}=r;let p=1/0,f=null,S=1/0,y=null;const x=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(m=>{if(m.isLocked&&!l||this.isShapeOfType(m,"group"))return!1;const v=this.getShapeMask(m);return v&&!or(n,v)?!1:i?i(m):!0});for(let m=x.length-1;m>=0;m--){const v=x[m],w=this.getShapeGeometry(v),C=w instanceof Gr,E=this.getPointInShapeSpace(v,n);if((this.isShapeOfType(v,"arrow")||this.isShapeOfType(v,"geo")&&v.props.fill==="none")&&v.props.text.trim()){for(const I of w.children)if(I.isLabel&&I.isPointInBounds(E))return v}if(this.isShapeOfType(v,"frame")){const I=w.distanceToPoint(E,u);if(Math.abs(I)<=a)return y||v;if(w.hitTestPoint(E,0,!0))return y||f||(h?v:void 0);continue}let _;if(C){let I=1/0;for(const k of w.children){if(k.isLabel&&!c)continue;const T=k.distanceToPoint(E,u);T<I&&(I=T)}_=I}else a===0&&(w.bounds.w<1||w.bounds.h<1)||w.bounds.containsPoint(E,a)?_=w.distanceToPoint(E,u):_=1/0;if(w.isClosed){if(_<=a){if(w.isFilled||C&&w.children[0].isFilled)return y||v;if(this.getShapePageBounds(v).contains(o))continue;if(Math.abs(_)<a)Math.abs(_)<S&&(S=Math.abs(_),y=v);else if(!y){const{area:I}=w;I<p&&(p=I,f=v)}}}else if(_<this.options.hitTestMargin/s)return v}return y||f||void 0}getShapesAtPoint(n,r={}){return this.getCurrentPageShapes().filter(s=>this.isPointInShape(s,n,r))}isPointInShape(n,r,s={}){const{hitInside:o=!1,margin:i=0}=s,a=typeof n=="string"?n:n.id,l=this.getShapeMask(a);return l&&!or(r,l)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(n,r),i,o)}getPointInShapeSpace(n,r){const s=typeof n=="string"?n:n.id;return this._getShapePageTransformCache().get(s).clone().invert().applyToPoint(r)}getPointInParentSpace(n,r){const s=typeof n=="string"?n:n.id,o=this.getShape(s);if(!o)return new b(0,0);if(Mn(o.parentId))return b.From(r);const i=this.getShapePageTransform(o.parentId);return i?i.clone().invert().applyToPoint(r):b.From(r)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),n=>this.store.get(n))}getCurrentPageShapesSorted(){const n=[],r=this.getSortedChildIdsForParent(this.getCurrentPageId());for(let s=0,o=r.length;s<o;s++)XM(this,r[s],n);return n}getCurrentPageRenderingShapesSorted(){const n=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:r})=>!n.has(r))}isShapeOfType(n,r){const s=typeof n=="string"?this.getShape(n):n;return s?s.type===r:!1}getShape(n){const r=typeof n=="string"?n:n.id;if(jn(r))return this.store.get(r)}getShapeParent(n){const r=typeof n=="string"?n:n==null?void 0:n.id;if(!r)return;const s=this.getShape(r);if(!(s===void 0||!jn(s.parentId)))return this.store.get(s.parentId)}getShapeNearestSibling(n,r){return r?r.parentId===n.parentId?r:this.findShapeAncestor(r,o=>o.parentId===n.parentId):void 0}isShapeInPage(n,r=this.getCurrentPageId()){const s=typeof n=="string"?n:n.id,o=this.getShape(s);if(!o)return!1;let i=!1;if(o.parentId===r)i=!0;else{let a=this.getShape(o.parentId);e:for(;a;){if(a.parentId===r){i=!0;break e}a=this.getShape(a.parentId)}}return i}getAncestorPageId(n){const r=typeof n=="string"?n:n==null?void 0:n.id,s=r&&this.getShape(r);if(s)return Mn(s.parentId)?s.parentId:this.getAncestorPageId(this.getShape(s.parentId))}reparentShapes(n,r,s){const o=typeof n[0]=="string"?n:n.map(f=>f.id);if(o.length===0)return this;const i=[],a=Mn(r)?oe.Identity():this.getShapePageTransform(r),l=a.rotation();let c=[];const u=ye(this.getSortedChildIdsForParent(r).map(f=>this.getShape(f)));if(s){const f=u.find(S=>S.index===s);if(f){const S=u[u.indexOf(f)+1];S?c=al(s,S.index,o.length):c=Pm(s,o.length)}else{const S=u.sort(ln).find(y=>y.index>s);S?c=al(s,S.index,o.length):c=Pm(s,o.length)}}else{const f=u.length&&u[u.length-1];c=f?Pm(f.index,o.length):su(o.length)}const h=a.clone().invert(),p=ye(o.map(f=>this.getShape(f)));return this.run(()=>{for(let f=0;f<p.length;f++){const S=p[f],y=this.getShapePageTransform(S);if(!y)continue;const x=y.point();if(!x)continue;const m=h.applyToPoint(x),v=y.rotation()-l;i.push({id:S.id,type:S.type,parentId:r,x:m.x,y:m.y,rotation:v,index:c[f]})}this.updateShapes(i)},{ignoreShapeLock:!0}),this}getHighestIndexForParent(n){const r=typeof n=="string"?n:n.id,s=this._parentIdsToChildIds.get()[r];if(!s||s.length===0)return"a1";const o=this.getShape(s[s.length-1]);return zr(o.index)}getSortedChildIdsForParent(n){const r=typeof n=="string"?n:n.id,s=this._parentIdsToChildIds.get()[r];return s||Gs}visitDescendants(n,r){const s=typeof n=="string"?n:n.id,o=this.getSortedChildIdsForParent(s);for(const i of o)r(i)!==!1&&this.visitDescendants(i,r);return this}getShapeAndDescendantIds(n){const r=new Set;for(const s of n.map(o=>this.getShape(o)).sort(ln))r.add(s.id),this.visitDescendants(s,o=>{r.add(o)});return r}getDroppingOverShape(n,r=[]){const s=this.getCurrentPageShapesSorted();for(let o=s.length-1;o>=0;o--){const i=s[o];if(this.getSelectedShapeIds().includes(i.id)||!this.getShapeUtil(i).canDropShapes(i,r)||r.find(l=>l.id===i.id||this.hasAncestor(i,l.id)))continue;const a=this.getShapeMaskedPageBounds(i.id);if(a&&a.containsPoint(n)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,n),0,!0))return i}}getOutermostSelectableShape(n,r){const s=typeof n=="string"?n:n.id,o=this.getShape(s);let i=o,a=o;const l=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(l==null?void 0:l.id)!==a.id&&!this.hasAncestor(l,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((l==null?void 0:l.id)===a.id)break;a=this.getShapeParent(a)}return i}_getBindingsIndexCache(){const n=dG(this);return this.store.createComputedCache("bindingsIndex",r=>n.get().get(r.id))}getBinding(n){return this.store.get(n)}getBindingsFromShape(n,r){const s=typeof n=="string"?n:n.id;return this.getBindingsInvolvingShape(s).filter(o=>o.fromId===s&&o.type===r)}getBindingsToShape(n,r){const s=typeof n=="string"?n:n.id;return this.getBindingsInvolvingShape(s).filter(o=>o.toId===s&&o.type===r)}getBindingsInvolvingShape(n,r){const s=typeof n=="string"?n:n.id,o=this._getBindingsIndexCache().get(s)??Gs;return r?o.filter(i=>i.type===r):o}createBindings(n){const r=[];for(const s of n){const o=this.getShape(s.fromId),i=this.getShape(s.toId);if(!o||!i||!this.canBindShapes({fromShape:o,toShape:i,binding:s}))continue;const l=this.getBindingUtil(s.type).getDefaultProps(),c=this.store.schema.types.binding.create({...s,id:s.id??ji(),props:{...l,...s.props}});r.push(c)}return this.store.put(r),this}createBinding(n){return this.createBindings([n])}updateBindings(n){const r=[];for(const s of n){if(!s)continue;const o=this.getBinding(s.id);if(!o)continue;const i=ss(o,s);if(i===o)continue;const a=this.getShape(i.fromId),l=this.getShape(i.toId);!a||!l||this.canBindShapes({fromShape:a,toShape:l,binding:i})&&r.push(i)}return this.store.put(r),this}updateBinding(n){return this.updateBindings([n])}deleteBindings(n,{isolateShapes:r=!1}={}){const s=n.map(o=>typeof o=="string"?o:o.id);return r?this.store.atomic(()=>{var o,i;for(const a of s){const l=this.getBinding(a);if(!l)continue;const c=this.getBindingUtil(l);(o=c.onBeforeIsolateFromShape)==null||o.call(c,{binding:l,removedShape:this.getShape(l.toId)}),(i=c.onBeforeIsolateToShape)==null||i.call(c,{binding:l,removedShape:this.getShape(l.fromId)}),this.store.remove([a])}}):this.store.remove(s),this}deleteBinding(n,r){return this.deleteBindings([n],r)}canBindShapes({fromShape:n,toShape:r,binding:s}){const o=typeof n=="string"?n:n.type,i=typeof r=="string"?r:r.type,a=typeof s=="string"?s:s.type,l={fromShapeType:o,toShapeType:i,bindingType:a};return o===i?this.getShapeUtil(o).canBind(l):this.getShapeUtil(o).canBind(l)&&this.getShapeUtil(i).canBind(l)}rotateShapesBy(n,r){if((typeof n[0]=="string"?n:n.map(i=>i.id)).length<=0)return this;const o=WM({editor:this});return o?(Kh({delta:r,snapshot:o,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(n,r){var i,a,l;let s=n;const o=this.getShapeUtil(n);return s=ss(s,((i=o.onTranslateStart)==null?void 0:i.call(o,s))??void 0),s=ss(s,{id:n.id,type:n.type,x:r.x,y:r.y}),s=ss(s,((a=o.onTranslate)==null?void 0:a.call(o,n,s))??void 0),s=ss(s,((l=o.onTranslateEnd)==null?void 0:l.call(o,n,s))??void 0),s}nudgeShapes(n,r){const s=typeof n[0]=="string"?n:n.map(i=>i.id);if(s.length<=0)return this;const o=[];for(const i of s){const a=this.getShape(i),l=b.From(r),c=this.getShapeParentTransform(a);c&&l.rot(-c.rotation()),o.push(this.getChangesToTranslateShape(a,l.add(a)))}return this.updateShapes(o),this}duplicateShapes(n,r){return this.run(()=>{const s=typeof n[0]=="string"?n:n.map(p=>p.id);if(s.length<=0)return this;const o=new Set(s),i=this.getShapeAndDescendantIds(s),a=[...i].reverse(),l=new Map;for(const p of i)l.set(p,$e());const{shapesToCreate:c,bindingsToCreate:u}=HC(this,i,p=>{const f=[];for(const y of p){const x=this.getBinding(y);if(!x)continue;const m=ji();f.push({...x,id:m,fromId:xr(l.get(x.fromId)),toId:xr(l.get(x.toId))})}const S=[];for(const y of a){const x=xr(l.get(y)),m=this.getShape(y);if(!m)continue;let v=0,w=0;if(r&&o.has(y)){const M=this.getShapeParentTransform(m),D=new b(r.x,r.y).rot(-M.rotation());v=D.x,w=D.y}const C=m.parentId,E=this.getSortedChildIdsForParent(C),_=E.indexOf(m.id),I=E[_+1],k=I?this.getShape(I):null,T=k?ru(m.index,k.index):zr(m.index);S.push({...m,id:x,x:m.x+v,y:m.y+w,index:T,parentId:l.get(m.parentId)??m.parentId})}return{shapesToCreate:S,bindingsToCreate:f}});if(c.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){Qd(this);return}if(this.createShapes(c),this.createBindings(u),this.setSelectedShapes(ye(s.map(p=>l.get(p)))),r!==void 0){const p=this.getSelectionPageBounds(),f=this.getViewportPageBounds();p&&!f.contains(p)&&this.centerOnPoint(p.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(n,r){const s=typeof n[0]=="string"?n:n.map(l=>l.id);if(s.length===0)return this;if(this.getInstanceState().isReadonly)return this;const o=this.getCurrentPageId();if(r===o)return this;if(!this.store.has(r))return this;const i=this.getContentFromCurrentPage(s);if(!i)return this;if(this.getPageShapeIds(r).size+i.shapes.length>this.options.maxShapesPerPage)return Qd(this,r),this;const a=this.getCamera().z;return this.run(()=>{this.deleteShapes(s),this.setCurrentPage(r),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(i,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:a}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(n){const r=typeof n[0]=="string"?n:n.map(a=>a.id);if(this.getInstanceState().isReadonly||r.length===0)return this;let s=!0,o=!0;const i=[];for(const a of r){const l=this.getShape(a);l&&(i.push(l),l.isLocked?o=!1:s=!1)}return this.run(()=>{o?(this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0}))),this.setSelectedShapes([])):s?this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!1}))):this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0})))}),this}sendToBack(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id),s=Zd(this,"toBack",r);return s&&this.updateShapes(s),this}sendBackward(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id),s=Zd(this,"backward",r);return s&&this.updateShapes(s),this}bringForward(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id),s=Zd(this,"forward",r);return s&&this.updateShapes(s),this}bringToFront(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id),s=Zd(this,"toFront",r);return s&&this.updateShapes(s),this}flipShapes(n,r){const s=typeof n[0]=="string"?n:n.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;let o=ye(s.map(a=>this.getShape(a)));if(!o.length)return this;o=ye(o.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(l=>this.getShape(l)):a).flat());const i=Q.Common(ye(o.map(a=>this.getShapePageBounds(a)))).center;return this.run(()=>{for(const a of o){const l=this.getShapeGeometry(a).bounds,c=this.getShapePageTransform(a.id);c&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:l,initialPageTransform:c,initialShape:a,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(a).isAspectRatioLocked(a),scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(n,r,s){const o=typeof n[0]=="string"?n:n.map(x=>x.id);if(this.getInstanceState().isReadonly)return this;const i=o.map(x=>this.getShape(x)).filter(x=>x?this.getShapeUtil(x).canBeLaidOut(x):!1),a=i.length;if(s===0&&a<3||a<2)return this;const l=Object.fromEntries(i.map(x=>[x.id,this.getShapePageBounds(x)]));let c,u,h,p;r==="horizontal"?(c="x",u="minX",h="maxX",p="width"):(c="y",u="minY",h="maxY",p="height");let f;if(s===0){const x=[];i.sort((v,w)=>l[v.id][u]-l[w.id][u]);for(let v=0;v<a-1;v++){const w=i[v],C=i[v+1],E=l[w.id],I=l[C.id][u]-E[h],k=x.find(T=>T.gap===I);k?k.count++:x.push({gap:I,count:1})}let m=0;x.forEach(v=>{v.count>m&&(m=v.count,f=v.gap)}),m===1&&(f=Math.max(0,x.reduce((v,w)=>v+w.gap*w.count,0)/(a-1)))}else f=s;const S=[];let y=l[i[0].id][h];return i.forEach((x,m)=>{var _,I;if(m===0)return;const v={x:0,y:0};v[c]=y+f-l[x.id][c];const w=this.getShapeParent(x),C=w?b.Rot(v,-this.getShapePageTransform(w).decompose().rotation):v,E=(I=(_=this.getShapeUtil(x)).onTranslateStart)==null?void 0:I.call(_,x);S.push(E?{...E,[c]:x[c]+C[c]}:{id:x.id,type:x.type,[c]:x[c]+C[c]}),y+=l[x.id][p]+f}),this.updateShapes(S),this}packShapes(n,r){var I,k;const s=typeof n[0]=="string"?n:n.map(T=>T.id);if(this.getInstanceState().isReadonly)return this;if(s.length<2)return this;const o=s.map(T=>this.getShape(T)).filter(T=>T?this.getShapeUtil(T).canBeLaidOut(T):!1),i={},a={};let l,c,u=0;for(let T=0;T<o.length;T++)l=o[T],c=this.getShapePageBounds(l),i[l.id]=c,a[l.id]=c.clone(),u+=c.width*c.height;const h=Q.Common(ye(Object.values(i))),p=h.width;o.sort((T,M)=>i[M.id].height-i[T.id].height);const f=Math.max(Math.ceil(Math.sqrt(u/.95)),p),S=[new Q(h.x,h.y,f,1/0)];let y=0,x=0,m,v;for(let T=0;T<o.length;T++){l=o[T],c=a[l.id];for(let M=S.length-1;M>=0;M--)if(m=S[M],!(c.width>m.width||c.height>m.height)){c.x=m.x,c.y=m.y,x=Math.max(x,c.maxY),y=Math.max(y,c.maxX),c.width===m.width&&c.height===m.height?(v=S.pop(),M<S.length&&(S[M]=v)):c.height===m.height?(m.x+=c.width+r,m.width-=c.width+r):c.width===m.width?(m.y+=c.height+r,m.height-=c.height+r):(S.push(new Q(m.x+(c.width+r),m.y,m.width-(c.width+r),c.height)),m.y+=c.height+r,m.height-=c.height+r);break}}const w=Q.Common(Object.values(a)),C=b.Sub(h.center,w.center);let E;const _=[];for(let T=0;T<o.length;T++){l=o[T],c=i[l.id],E=a[l.id];const M=b.Sub(E.point,c.point).add(C),D=this.getShapeParentTransform(l);D&&M.rot(-D.rotation());const $={id:l.id,type:l.type,x:l.x+M.x,y:l.y+M.y},j=(k=(I=this.getShapeUtil(l)).onTranslateStart)==null?void 0:k.call(I,{...l,...$});j?_.push({...$,...j}):_.push($)}return _.length&&this.updateShapes(_),this}alignShapes(n,r){const s=typeof n[0]=="string"?n:n.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(s.length<2)return this;const o=ye(s.map(c=>this.getShape(c))),i=Object.fromEntries(o.map(c=>[c.id,this.getShapePageBounds(c)])),a=Q.Common(ye(Object.values(i))),l=[];return o.forEach(c=>{const u=i[c.id];if(!u)return;const h={x:0,y:0};switch(r){case"top":{h.y=a.minY-u.minY;break}case"center-vertical":{h.y=a.midY-u.minY-u.height/2;break}case"bottom":{h.y=a.maxY-u.minY-u.height;break}case"left":{h.x=a.minX-u.minX;break}case"center-horizontal":{h.x=a.midX-u.minX-u.width/2;break}case"right":{h.x=a.maxX-u.minX-u.width;break}}const p=this.getShapeParent(c),f=p?b.Rot(h,-this.getShapePageTransform(p).decompose().rotation):h;l.push(this.getChangesToTranslateShape(c,b.Add(c,f)))}),this.updateShapes(l),this}distributeShapes(n,r){const s=typeof n[0]=="string"?n:n.map(w=>w.id);if(this.getInstanceState().isReadonly)return this;if(s.length<3)return this;const o=s.length,i=ye(s.map(w=>this.getShape(w))),a=Object.fromEntries(i.map(w=>[w.id,this.getShapePageBounds(w)]));let l,c,u,h,p;r==="horizontal"?(l="x",c="minX",u="maxX",h="midX",p="width"):(l="y",c="minY",u="maxY",h="midY",p="height");const f=[],S=i.sort((w,C)=>a[w.id][c]-a[C.id][c])[0],y=i.sort((w,C)=>a[C.id][u]-a[w.id][u])[0],x=a[S.id][h],m=(a[y.id][h]-x)/(o-1),v=x+m;return i.filter(w=>w!==S&&w!==y).sort((w,C)=>a[w.id][h]-a[C.id][h]).forEach((w,C)=>{const E={x:0,y:0};E[l]=v+m*C-a[w.id][p]/2-a[w.id][l];const _=this.getShapeParent(w),I=_?b.Rot(E,-this.getShapePageTransform(_).rotation()):E;f.push(this.getChangesToTranslateShape(w,b.Add(w,I)))}),this.updateShapes(f),this}stretchShapes(n,r){const s=typeof n[0]=="string"?n:n.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(s.length<2)return this;const o=ye(s.map(c=>this.getShape(c))),i=Object.fromEntries(s.map(c=>[c,this.getShapeGeometry(c).bounds])),a=Object.fromEntries(s.map(c=>[c,this.getShapePageBounds(c)])),l=Q.Common(ye(Object.values(a)));switch(r){case"vertical":{this.run(()=>{for(const c of o){if(this.getShapePageTransform(c).rotation()%Le)continue;const h=i[c.id],p=a[c.id],f=new b(0,l.minY-p.minY),S=this.getShapeParentTransform(c);S&&f.rot(-S.rotation());const{x:y,y:x}=b.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:y,y:x}]);const m=new b(1,l.height/p.height);this.resizeShape(c.id,m,{initialBounds:h,scaleOrigin:new b(p.center.x,l.minY),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}case"horizontal":{this.run(()=>{for(const c of o){const u=i[c.id],h=a[c.id];if(this.getShapePageTransform(c).rotation()%Le)continue;const f=new b(l.minX-h.minX,0),S=this.getShapeParentTransform(c);S&&f.rot(-S.rotation());const{x:y,y:x}=b.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:y,y:x}]);const m=new b(l.width/h.width,1);this.resizeShape(c.id,m,{initialBounds:u,scaleOrigin:new b(l.minX,h.center.y),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}}return this}resizeShape(n,r,s={}){var S,y,x;const o=typeof n=="string"?n:n.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new b(1,r.y)),Number.isFinite(r.y)||(r=new b(r.x,1));const i=s.initialShape??this.getShape(o);if(!i)return this;const a=s.scaleOrigin??((S=this.getShapePageBounds(o))==null?void 0:S.center);if(!a)return this;const l=s.initialPageTransform?oe.Cast(s.initialPageTransform):this.getShapePageTransform(o);if(!l)return this;const c=l.rotation();if(c==null)return this;const u=s.scaleAxisRotation??c,h=s.initialBounds??this.getShapeGeometry(o).bounds;if(!h)return this;const p=s.isAspectRatioLocked??this.getShapeUtil(i).isAspectRatioLocked(i);if(!J_(c,u))return this._resizeUnalignedShape(o,r,{...s,initialBounds:h,scaleOrigin:a,scaleAxisRotation:u,initialPageTransform:l,isAspectRatioLocked:p,initialShape:i});const f=this.getShapeUtil(i);if(p&&(Math.abs(r.x)>Math.abs(r.y)?r=new b(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new b(Math.sign(r.x)*Math.abs(r.y),r.y)),f.onResize&&f.canResize(i)){const m=this._scalePagePoint(oe.applyToPoint(l,new b(0,0)),a,r,u),v=this.getPointInParentSpace(i.id,m),w=new b(r.x,r.y),C=$o((c-u)%Math.PI,0);w.x=C?r.x:r.y,w.y=C?r.y:r.x;const E=oe.applyToPoint(l,new b),{x:_,y:I}=this.getPointInParentSpace(i.id,E);let k=i;s.skipStartAndEndCallbacks||(k=ss(i,((y=f.onResizeStart)==null?void 0:y.call(f,i))??void 0)),k=ss(k,{id:o,type:i.type,x:v.x,y:v.y,...f.onResize({...i,x:_,y:I},{newPoint:v,handle:s.dragHandle??"bottom_right",mode:s.mode??"scale_shape",scaleX:w.x,scaleY:w.y,initialBounds:h,initialShape:i})}),s.skipStartAndEndCallbacks||(k=ss(k,((x=f.onResizeEnd)==null?void 0:x.call(f,i,k))??void 0)),this.updateShapes([k])}else{const m=oe.applyToPoint(l,h.center),v=this._scalePagePoint(m,a,r,u),w=this.getPointInParentSpace(i.id,m),C=this.getPointInParentSpace(i.id,v),E=b.Sub(C,w);this.updateShapes([{id:o,type:i.type,x:i.x+E.x,y:i.y+E.y}])}return this}_scalePagePoint(n,r,s,o){const i=b.RotWith(n,r,-o).sub(r),a=b.MulV(i,s);return b.Add(a,r).rotWith(r,o)}_resizeUnalignedShape(n,r,s){const{type:o}=s.initialShape,i=new b(r.x,r.y);if(Math.abs(r.x)>Math.abs(r.y)?i.x=Math.sign(r.x)*Math.abs(r.y):i.y=Math.sign(r.y)*Math.abs(r.x),this.resizeShape(n,i,{initialShape:s.initialShape,initialBounds:s.initialBounds,isAspectRatioLocked:s.isAspectRatioLocked}),Math.sign(r.x)*Math.sign(r.y)<0){let{rotation:m}=oe.Decompose(s.initialPageTransform);m-=2*m,this.updateShapes([{id:n,type:o,rotation:m}])}const a=oe.applyToPoint(s.initialPageTransform,s.initialBounds.center),l=this._scalePagePoint(a,s.scaleOrigin,r,s.scaleAxisRotation),c=this.getShapePageBounds(n),u=this.getShapePageTransform(n),h=c.center,p=u.point();if(!h||!p)return this;const f=b.Sub(l,h),S=b.Add(p,f),{x:y,y:x}=this.getPointInParentSpace(n,S);return this.updateShapes([{id:n,type:o,x:y,y:x}]),this}getInitialMetaForShape(n){return{}}createShape(n){return this.createShapes([n]),this}createShapes(n){if(!Array.isArray(n))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");if(this.getInstanceState().isReadonly)return this;if(n.length<=0)return this;const r=this.getCurrentPageShapeIds();if(n.length+r.size>this.options.maxShapesPerPage)return Qd(this),this;const o=this.getFocusedGroupId();return this.run(()=>{var h,p;const i=this.getCurrentPageShapesSorted(),a=n.map(f=>{if(f.id||(f={id:$e(),...f}),!f.parentId||!(this.store.has(f.parentId)||n.some(S=>S.id===f.parentId))){let S=this.getFocusedGroupId();for(let x=i.length-1;x>=0;x--){const m=i[x];if(this.getShapeUtil(m).canReceiveNewChildrenOfType(m,f.type)&&this.isPointInShape(m,{x:f.x??0,y:f.y??0},{margin:0,hitInside:!0})){S=m.id;break}}const y=f.parentId;if(S===f.id&&(S=o),S!==y&&(f={...f},f.parentId=S,jn(S))){const x=this.getPointInShapeSpace(this.getShape(S),{x:f.x??0,y:f.y??0});f.x=x.x,f.y=x.y,f.rotation=-this.getShapePageTransform(S).rotation()+(f.rotation??0)}}return f}),l=new Map,c=[],{opacityForNextShape:u}=this.getInstanceState();for(const f of a){const S=this.getShapeUtil(f);let y=f.index;if(!y){const w=f.parentId??o;l.has(w)||l.set(w,this.getHighestIndexForParent(w)),y=l.get(w),l.set(w,zr(y))}const x=S.getDefaultProps();for(const[w,C]of this.styleProps[f.type])x[C]=this.getStyleForNextShape(w);let m=this.store.schema.types.shape.create({...f,index:y,opacity:f.opacity??u,parentId:f.parentId??o,props:"props"in f?{...x,...f.props}:x});if(m.index===void 0)throw Error("no index!");const v=(p=(h=this.getShapeUtil(m)).onBeforeCreate)==null?void 0:p.call(h,m);v&&(m=v),c.push(m)}c.forEach(f=>{f.meta={...this.getInitialMetaForShape(f),...f.meta}}),this.store.put(c)}),this}animateShape(n,r={animation:Tm}){return this.animateShapes([n],r)}animateShapes(n,r={animation:Tm}){if(!r.animation)return this;const{duration:s=500,easing:o=At.linear}=r.animation,i=ct();let a=s,l;const c=[];let u,h;for(let f=0,S=n.length;f<S;f++){if(u=n[f],!u)continue;const y=this.getShape(u.id);y&&(h={start:Ge(y),end:ss(Ge(y),u)},c.push(h),this.animatingShapes.set(y.id,i))}const p=f=>{var m,v;if(a-=f,a<0){const{animatingShapes:w}=this,C=n.filter(E=>E&&w.get(E.id)===i);C.length&&this.updateShapes(C),this.off("tick",p);return}l=o(1-a/s);const{animatingShapes:S}=this,y=[];let x;for(let w=0,C=c.length;w<C;w++){const{start:E,end:_}=c[w];x=S.get(E.id),x===i&&y.push({..._,x:E.x+(_.x-E.x)*l,y:E.y+(_.y-E.y)*l,opacity:E.opacity+(_.opacity-E.opacity)*l,rotation:E.rotation+(_.rotation-E.rotation)*l,props:((v=(m=this.getShapeUtil(_)).getInterpolatedProps)==null?void 0:v.call(m,E,_,l))??_.props})}this._updateShapes(y)};return this.on("tick",p),this}groupShapes(n,r={}){var y;const{groupId:s=$e(),select:o=!0}=r;if(!Array.isArray(n))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const i=typeof n[0]=="string"?n:n.map(x=>x.id);if(i.length<=1)return this;const a=ye((this._shouldIgnoreShapeLock?i:this._getUnlockedShapeIds(i)).map(x=>this.getShape(x))),l=a.sort(ln).map(x=>x.id),c=Q.Common(ye(a.map(x=>this.getShapePageBounds(x)))),{x:u,y:h}=c.point,p=this.findCommonAncestor(a)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const f=a.filter(x=>x.parentId===p).sort(ln),S=(y=f[f.length-1])==null?void 0:y.index;return this.run(()=>{this.createShapes([{id:s,type:"group",parentId:p,index:S,x:u,y:h,opacity:1,props:{}}]),this.reparentShapes(l,s),o&&this.select(s)}),this}ungroupShapes(n,r={}){if(this.getInstanceState().isReadonly)return this;const{select:s=!0}=r,o=typeof n[0]=="string"?n:n.map(c=>c.id),i=ye((this._shouldIgnoreShapeLock?o:this._getUnlockedShapeIds(o)).map(c=>this.getShape(c)));if(i.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const a=new Set,l=[];return i.forEach(c=>{this.isShapeOfType(c,"group")?l.push(c):a.add(c.id)}),l.length===0?this:(this.run(()=>{let c;for(let u=0,h=l.length;u<h;u++){c=l[u];const p=this.getSortedChildIdsForParent(c.id);for(let f=0,S=p.length;f<S;f++)a.add(p[f]);this.reparentShapes(p,c.parentId,c.index)}this.deleteShapes(l.map(u=>u.id)),s&&this.select(...a)}),this)}updateShape(n){return this.updateShapes([n]),this}updateShapes(n){const r=Array(n.length);for(let s=0,o=n.length;s<o;s++){const i=n[s];if(!i)continue;const a=this.getShape(i.id);if(a){if(!this._shouldIgnoreShapeLock){if(a.isLocked){if(!(Object.hasOwn(i,"isLocked")&&!i.isLocked))continue}else if(this.isShapeOrAncestorLocked(a))continue}this.animatingShapes.delete(i.id),r.push(i)}}return this._updateShapes(r),this}_getUnlockedShapeIds(n){return n.filter(r=>{var s;return!((s=this.getShape(r))!=null&&s.isLocked)})}deleteShapes(n){if(this.getInstanceState().isReadonly)return this;if(!Array.isArray(n))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");const r=typeof n[0]=="string"?n:n.map(i=>i.id),s=this._shouldIgnoreShapeLock?r:this._getUnlockedShapeIds(r);if(s.length===0)return this;const o=new Set(s);for(const i of s)this.visitDescendants(i,a=>{o.add(a)});return this.run(()=>this.store.remove([...o]))}deleteShape(n){return this.deleteShapes([typeof n=="string"?n:n.id]),this}_extractSharedStyles(n,r){if(this.isShapeOfType(n,"group")){const s=this._parentIdsToChildIds.get()[n.id];if(!s)return;for(let o=0,i=s.length;o<i;o++)this._extractSharedStyles(this.getShape(s[o]),r)}else for(const[s,o]of this.styleProps[n.type])r.applyValue(s,$n(n.props,o))}_getSelectionSharedStyles(){const n=this.getSelectedShapes(),r=new kv;for(const s of n)this._extractSharedStyles(s,r);return r}getStyleForNextShape(n){const r=this.getInstanceState().stylesForNextShape[n.id];return r===void 0?n.defaultValue:r}getShapeStyleIfExists(n,r){const s=this.styleProps[n.type].get(r);if(s!==void 0)return $n(n.props,s)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const n=this.root.getCurrent(),r=new kv;if(!n)return r;if(n.shapeType)for(const s of this.styleProps[n.shapeType].keys())r.applyValue(s,this.getStyleForNextShape(s));return r}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const n=[],r=o=>{const i=this.getShape(o);if(i)if(this.isShapeOfType(i,"group"))for(const a of this.getSortedChildIdsForParent(i.id))r(a);else n.push(i)};for(const o of this.getSelectedShapeIds())r(o);let s=null;for(const o of n)if(s===null)s=o.opacity;else if(s!==o.opacity)return{type:"mixed"};if(s!==null)return{type:"shared",value:s}}return{type:"shared",value:this.getInstanceState().opacityForNextShape}}setOpacityForNextShapes(n,r){return this.updateInstanceState({opacityForNextShape:n},r),this}setOpacityForSelectedShapes(n){const r=this.getSelectedShapes();if(r.length>0){const s=[],o=i=>{if(this.isShapeOfType(i,"group")){const a=this.getSortedChildIdsForParent(i);for(const l of a)o(this.getShape(l))}else s.push(i)};for(const i of r)o(i);this.updateShapes(s.map(i=>({id:i.id,type:i.type,opacity:n})))}return this}setStyleForNextShapes(n,r,s){const o=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...o,[n.id]:r}},s),this}setStyleForSelectedShapes(n,r){const s=this.getSelectedShapes();if(s.length>0){const o=[],i=a=>{if(this.isShapeOfType(a,"group")){const l=this.getSortedChildIdsForParent(a.id);for(const c of l)i(this.getShape(c))}else{const l=this.getShapeUtil(a),c=this.styleProps[a.type].get(n);if(c){const u={id:a.id,type:a.type,props:{[c]:r}};o.push({util:l,originalShape:a,updatePartial:u})}}};for(const a of s)i(a);this.updateShapes(o.map(({updatePartial:a})=>a))}return this}registerExternalAssetHandler(n,r){return this.externalAssetContentHandlers[n]=r,this}async getAssetForExternalContent(n){var r,s;return await((s=(r=this.externalAssetContentHandlers)[n.type])==null?void 0:s.call(r,n))}hasExternalAssetHandler(n){return!!this.externalAssetContentHandlers[n]}registerExternalContentHandler(n,r){return this.externalContentHandlers[n]=r,this}async putExternalContent(n){var r,s;return(s=(r=this.externalContentHandlers)[n.type])==null?void 0:s.call(r,n)}getContentFromCurrentPage(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);if(!r||r.length===0)return;const s=this.getShapeAndDescendantIds(r);return HC(this,s,o=>{const i=[];for(const h of o){const p=this.getBinding(h);p&&i.push(p)}const a=[],l=[];for(const h of s){const p=this.getShape(h);if(!p)continue;if(!s.has(p.parentId)){const S=this.getShapePageTransform(p.id),y=S.point();l.push({...p,x:y.x,y:y.y,rotation:S.rotation(),parentId:this.getCurrentPageId()}),a.push(p.id)}else l.push(p)}const c=[],u=new Set;for(const h of l){if(!("assetId"in h.props))continue;const p=h.props.assetId;if(!p||u.has(p))continue;u.add(p);const f=this.getAsset(p);f&&c.push(f)}return{schema:this.store.schema.serialize(),shapes:l,rootShapeIds:a,bindings:i,assets:c}})}async resolveAssetsInContent(n){if(!n)return;const r=[];return await Promise.allSettled(n.assets.map(async s=>{var o,i;if((s.type==="image"||s.type==="video")&&!((o=s.props.src)!=null&&o.startsWith("data:image"))&&!((i=s.props.src)!=null&&i.startsWith("http"))){const a=Ge(s),l=await this.store.props.assets.resolve(s,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});a.props.src=await Ai.blobToDataUrl(await ws(l).then(c=>c.blob())),r.push(a)}else r.push(s)})),n.assets=r,n}putContentOntoCurrentPage(n,r={}){var D,$;if(this.getInstanceState().isReadonly)return this;if(!n.schema)throw Error(`Could not put content:
|
|
90
|
-
content is missing a schema.`);const{select:s=!1,preserveIds:o=!1,preservePosition:i=!1}=r;let{point:a=void 0}=r;const l=this.getCurrentPageId(),{rootShapeIds:c}=n,u=[],h=[],p=[],f={store:{...Object.fromEntries(n.assets.map(j=>[j.id,j])),...Object.fromEntries(n.shapes.map(j=>[j.id,j])),...Object.fromEntries(((D=n.bindings)==null?void 0:D.map(j=>[j.id,j]))??[])},schema:n.schema},S=this.store.schema.migrateStoreSnapshot(f);if(S.type==="error")throw Error("Could not put content: could not migrate content");for(const j of Object.values(S.value))switch(j.typeName){case"asset":{u.push(j);break}case"shape":{h.push(j);break}case"binding":{p.push(j);break}}const y=new Map(o?h.map(j=>[j.id,j.id]):h.map(j=>[j.id,$e()])),x=new Map(o?p.map(j=>[j.id,j.id]):p.map(j=>[j.id,ji()]));let m=this.getCurrentPageId(),v=1/0,w=[];for(const j of this.getSelectedShapes()){if(v===0)break;const O=this.isShapeOfType(j,"frame"),R=this.getShapeAncestors(j);O&&R.push(j);const H=O?R.length+1:R.length;if(H<v)v=H,w=R,m=O?j.id:j.parentId;else if(H===v){if(w.length!==R.length)throw Error(`Ancestors: ${w.length} !== ${R.length}`);if(w.length===0){m=l;break}else{m=l;for(let B=0;B<w.length&&R[B]===w[B];B++)m=R[B].id}}}let C=!1;if(!Mn(m)){const j=this.getShape(m);if(j){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(j)))m=l;else if(c.length===1){const O=h.find(R=>R.id===c[0]);this.isShapeOfType(j,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(j==null?void 0:j.props.w)&&O.props.h===(j==null?void 0:j.props.h)&&(C=!0)}}else m=l}C||(C=y.has(m)),C&&(m=this.getShape(m).parentId);let E=this.getHighestIndexForParent(m);const _=[],I=h.map(j=>{const O=y.get(j.id),R={...j,id:O};return c.includes(j.id)&&(R.parentId=l,_.push(R)),y.has(R.parentId)?R.parentId=y.get(j.parentId):(c.push(R.id),R.index=E,E=zr(E)),R});if(I.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return Qd(this),this;const k=p.map(j=>({...j,id:xr(x.get(j.id)),fromId:xr(y.get(j.fromId)),toId:xr(y.get(j.toId))})),T=[],M=[];for(const j of u)this.store.has(j.id)||((j.type==="image"||j.type==="video")&&(($=j.props.src)!=null&&$.startsWith("data:image"))&&(M.push(Ge(j)),j.props.src=null),T.push(j));return Promise.allSettled(M.map(async j=>{const O=await sG(j.props.src,j.props.name,j.props.mimeType??"image/png"),R=await this.getAssetForExternalContent({type:"file",file:O});if(!R){this.deleteAssets([j.id]);return}this.updateAssets([{...R,id:j.id}])})),this.run(()=>{T.length>0&&this.createAssets(T),this.createShapes(I),this.createBindings(k),s&&this.select(..._.map(B=>B.id)),m!==l&&this.reparentShapes(_.map(B=>B.id),m);const j=I.map(B=>this.getShape(B.id)),O=Q.Common(j.map(B=>this.getShapePageBounds(B)));if(a===void 0)if(Mn(m)){const B=this.getViewportPageBounds();i||B.includes(Q.From(O))?a=O.center:a=B.center}else{const B=this.getShape(m);a=oe.applyToPoint(this.getShapePageTransform(B),this.getShapeGeometry(B).bounds.center)}if(_.length===1){const B=_[0];if(this.isShapeOfType(B,"frame"))for(;this.getShapesAtPoint(a).some(z=>this.isShapeOfType(z,"frame")&&z.props.w===B.props.w&&z.props.h===B.props.h);)a.x+=O.w+16}const R=Q.Common(ye(_.map(({id:B})=>this.getShapePageBounds(B)))).center,H=b.Sub(a,R);this.updateShapes(_.map(({id:B})=>{const z=this.getShape(B),W=this.getShapeParentTransform(B).decompose().rotation,Y=b.Rot(H,-W);return{id:z.id,type:z.type,x:z.x+Y.x,y:z.y+Y.y}}))}),this}async getSvgElement(n,r={}){const s=await yG(this,n,r);if(!s)return;const o=document.createDocumentFragment(),i=RM(o);ia.flushSync(()=>{i.render(s.jsx)});const a=o.firstElementChild;return Xe(a instanceof SVGSVGElement,"Expected an SVG element"),i.unmount(),{svg:a,width:s.width,height:s.height}}async getSvgString(n,r={}){const s=await this.getSvgElement(n,r);return s?{svg:new XMLSerializer().serializeToString(s.svg),width:s.width,height:s.height}:void 0}async getSvg(n,r={}){const s=await this.getSvgElement(n,r);if(s)return s.svg}_updateInputsFromEvent(n){const{pointerVelocity:r,previousScreenPoint:s,previousPagePoint:o,currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:l}=this.store.unsafeGetWithoutCapture(Sn),{x:c,y:u,z:h}=Id(()=>this.getCamera()),p=n.point.x-l.x,f=n.point.y-l.y,S=n.point.z??.5;s.setTo(i),o.setTo(a),i.set(p,f);const y=p/h-c,x=f/h-u;isFinite(y)&&isFinite(x)&&a.set(y,x,S),this.inputs.isPen=n.type==="pointer"&&n.isPen,(n.name==="pointer_down"||this.inputs.isPinching)&&(r.set(0,0),this.inputs.originScreenPoint.setTo(i),this.inputs.originPagePoint.setTo(a)),this.run(()=>{var m;this.store.put([{id:$p,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:n.type==="pointer"&&n.pointerId===dP.CAMERA_MOVE?((m=this.store.unsafeGetWithoutCapture($p))==null?void 0:m.lastActivityTimestamp)??this._tickManager.now:this._tickManager.now,meta:{}}])},{history:"ignore"})}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}focus({focusContainer:n=!0}={}){return n&&this.focusManager.focus(),this.updateInstanceState({isFocused:!0}),this}blur({blurContainer:n=!0}={}){return this.getIsFocused()?(n?this.focusManager.blur():this.complete(),this.updateInstanceState({isFocused:!1}),this):this}getIsFocused(){return this.getInstanceState().isFocused}getSnapshot(){return XW(this.store)}loadSnapshot(n){return zM(this.store,n),this}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_flushEventsForTick(n){this.run(()=>{if(this._pendingEventsForNextTick.length>0){const r=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const s of r)this._flushEventForTick(s)}n>0&&this.root.handleEvent({type:"misc",name:"tick",elapsed:n}),this.scribbles.tick(n)})}maybeTrackPerformance(n){xt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(n),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}ne([G],Z.prototype,"getCanUndo");ne([G],Z.prototype,"getCanRedo");ne([G],Z.prototype,"getPath");ne([G],Z.prototype,"getCurrentTool");ne([G],Z.prototype,"getCurrentToolId");ne([G],Z.prototype,"getDocumentSettings");ne([G],Z.prototype,"getInstanceState");ne([G],Z.prototype,"getOpenMenus");ne([G],Z.prototype,"getIsMenuOpen");ne([G],Z.prototype,"getPageStates");ne([G],Z.prototype,"_getPageStatesQuery");ne([G],Z.prototype,"getCurrentPageState");ne([G],Z.prototype,"_getCurrentPageStateId");ne([G],Z.prototype,"getSelectedShapeIds");ne([G],Z.prototype,"getSelectedShapes");ne([G],Z.prototype,"getOnlySelectedShapeId");ne([G],Z.prototype,"getOnlySelectedShape");ne([G],Z.prototype,"getSelectionPageBounds");ne([G],Z.prototype,"getSelectionRotation");ne([G],Z.prototype,"getSelectionRotatedPageBounds");ne([G],Z.prototype,"getSelectionRotatedScreenBounds");ne([G],Z.prototype,"getFocusedGroupId");ne([G],Z.prototype,"getFocusedGroup");ne([G],Z.prototype,"getEditingShapeId");ne([G],Z.prototype,"getEditingShape");ne([G],Z.prototype,"getHoveredShapeId");ne([G],Z.prototype,"getHoveredShape");ne([G],Z.prototype,"getHintingShapeIds");ne([G],Z.prototype,"getHintingShape");ne([G],Z.prototype,"getErasingShapeIds");ne([G],Z.prototype,"getErasingShapes");ne([G],Z.prototype,"_unsafe_getCameraId");ne([G],Z.prototype,"getCamera");ne([G],Z.prototype,"getViewportPageBoundsForFollowing");ne([G],Z.prototype,"getCameraForFollowing");ne([G],Z.prototype,"getZoomLevel");ne([G],Z.prototype,"getViewportScreenBounds");ne([G],Z.prototype,"getViewportScreenCenter");ne([G],Z.prototype,"getViewportPageBounds");ne([G],Z.prototype,"_getCollaboratorsQuery");ne([G],Z.prototype,"getCollaborators");ne([G],Z.prototype,"getCollaboratorsOnCurrentPage");ne([G],Z.prototype,"getRenderingShapes");ne([G],Z.prototype,"_getAllPagesQuery");ne([G],Z.prototype,"getPages");ne([G],Z.prototype,"getCurrentPageId");ne([G],Z.prototype,"getCurrentPageShapeIdsSorted");ne([G],Z.prototype,"_getAllAssetsQuery");ne([G],Z.prototype,"_getShapeGeometryCache");ne([G],Z.prototype,"_getShapeHandlesCache");ne([G],Z.prototype,"_getShapePageTransformCache");ne([G],Z.prototype,"_getShapePageBoundsCache");ne([G],Z.prototype,"_getShapeClipPathCache");ne([G],Z.prototype,"_getShapeMaskCache");ne([G],Z.prototype,"_getShapeMaskedPageBoundsCache");ne([G],Z.prototype,"_notVisibleShapes");ne([G],Z.prototype,"getCulledShapes");ne([G],Z.prototype,"getCurrentPageBounds");ne([G],Z.prototype,"getCurrentPageShapes");ne([G],Z.prototype,"getCurrentPageShapesSorted");ne([G],Z.prototype,"getCurrentPageRenderingShapesSorted");ne([G],Z.prototype,"_getBindingsIndexCache");ne([G],Z.prototype,"_getSelectionSharedStyles");ne([G({isEqual:(e,t)=>e.equals(t)})],Z.prototype,"getSharedStyles");ne([G],Z.prototype,"getSharedOpacity");ne([G],Z.prototype,"getIsFocused");function Qd(e,t=e.getCurrentPageId()){const n=e.getPage(t).name;e.emit("max-shapes",{name:n,pageId:t,count:e.options.maxShapesPerPage})}function ss(e,t){if(!t)return e;let n=null;const r=Object.entries(t);for(let s=0,o=r.length;s<o;s++){const[i,a]=r[s];if(a!==void 0&&!(i==="id"||i==="type"||i==="typeName")&&a!==e[i]){if(n||(n={...e}),i==="props"||i==="meta"){n[i]={...e[i]};for(const[l,c]of Object.entries(a))c!==void 0&&(n[i][l]=c);continue}n[i]=a}}return n||e}function XM(e,t,n){const r=e.getShape(t);if(!r)return;n.push(r);const s=e.getSortedChildIdsForParent(t);for(let o=0,i=s.length;o<i;o++)XM(e,s[o],n)}function HC(e,t,n){let r;if(e.run(()=>{const s=e.store.extractingChanges(()=>{const o=new Set,i=new Set;for(const a of t)if(e.getShape(a))for(const c of e.getBindingsInvolvingShape(a)){const u=t.has(c.fromId),h=t.has(c.toId);if(u&&h){o.add(c.id);continue}(!u||!h)&&i.add(c.id)}e.deleteBindings([...i],{isolateShapes:!0});try{r=yn.ok(n(o))}catch(a){r=yn.err(a)}});e.store.applyDiff(PS(s))},{history:"ignore"}),r.ok)return r.value;throw r.error}function KC(e,t){if(!t.constraints)throw Error("Should have constraints here");const{padding:{x:n,y:r}}=t.constraints,s=e.getViewportScreenBounds(),o=Q.From(t.constraints.bounds),i=(s.w-n*2)/o.w,a=(s.h-r*2)/o.h;return{zx:i,zy:a}}function td(){const e=F(),t=VM();return K("isDarkMode",()=>(t==null?void 0:t.isDarkMode)??e.user.getIsDarkMode(),[t,e])}const WC="<path d='m19.7432 17.0869-4.072 4.068 2.829 2.828-8.473-.013-.013-8.47 2.841 2.842 4.075-4.068 1.414-1.415-2.844-2.842h8.486v8.484l-2.83-2.827z' fill='%23fff'/><path d='m18.6826 16.7334-4.427 4.424 1.828 1.828-5.056-.016-.014-5.054 1.842 1.841 4.428-4.422 2.474-2.475-1.844-1.843h5.073v5.071l-1.83-1.828z' fill='%23000'/>",GC="<path d='m9 17.9907v.005l5.997 5.996.001-3.999h1.999 2.02v4l5.98-6.001-5.98-5.999.001 4.019-2.021.002h-2l.001-4.022zm1.411.003 3.587-3.588-.001 2.587h3.5 2.521v-2.585l3.565 3.586-3.564 3.585-.001-2.585h-2.521l-3.499-.001-.001 2.586z' fill='%23fff'/><path d='m17.4971 18.9932h2.521v2.586l3.565-3.586-3.565-3.585v2.605h-2.521-3.5v-2.607l-3.586 3.587 3.586 3.586v-2.587z' fill='%23000'/>",Jd='<path d="M22.4789 9.45728L25.9935 12.9942L22.4789 16.5283V14.1032C18.126 14.1502 14.6071 17.6737 14.5675 22.0283H17.05L13.513 25.543L9.97889 22.0283H12.5674C12.6071 16.5691 17.0214 12.1503 22.4789 12.1031L22.4789 9.45728Z" fill="black"/><path fill-rule="evenodd" clip-rule="evenodd" d="M21.4789 7.03223L27.4035 12.9945L21.4789 18.9521V15.1868C18.4798 15.6549 16.1113 18.0273 15.649 21.0284H19.475L13.5128 26.953L7.55519 21.0284H11.6189C12.1243 15.8155 16.2679 11.6677 21.4789 11.1559L21.4789 7.03223ZM22.4789 12.1031C17.0214 12.1503 12.6071 16.5691 12.5674 22.0284H9.97889L13.513 25.543L17.05 22.0284H14.5675C14.5705 21.6896 14.5947 21.3558 14.6386 21.0284C15.1157 17.4741 17.9266 14.6592 21.4789 14.1761C21.8063 14.1316 22.1401 14.1069 22.4789 14.1032V16.5284L25.9935 12.9942L22.4789 9.45729L22.4789 12.1031Z" fill="white"/>';function wo(e,t,n,r,s,o=16,i=16){const a=(-n-t)*(Me/180),l=Math.sin(a),c=Math.cos(a),u=1*c-1*l,h=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${s};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${h}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${t+n} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${o} ${i}, pointer`}const qG=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],ZG={none:()=>"none","ew-resize":(e,t,n)=>wo(GC,e,0,t,n),"ns-resize":(e,t,n)=>wo(GC,e,90,t,n),"nesw-resize":(e,t,n)=>wo(WC,e,0,t,n),"nwse-resize":(e,t,n)=>wo(WC,e,90,t,n),"nwse-rotate":(e,t,n)=>wo(Jd,e,0,t,n),"nesw-rotate":(e,t,n)=>wo(Jd,e,90,t,n),"senw-rotate":(e,t,n)=>wo(Jd,e,180,t,n),"swne-rotate":(e,t,n)=>wo(Jd,e,270,t,n)};function Zn(e,t=0,n="black"){return ZG[e](y9(t),!1,n)}function QG(){const e=F(),t=$t(),n=td();Lo("useCursor",()=>{const{type:r,rotation:s}=e.getInstanceState().cursor;if(qG.includes(r)){t.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}t.style.setProperty("--tl-cursor",Zn(r,s,n?"white":"black"))},[e,t,n])}function JG(){const e=F(),t=$t(),n=td(),r=K(xt.forceSrgb);Ce.useEffect(()=>{n?(t.setAttribute("data-color-mode","dark"),t.classList.remove("tl-theme__light"),t.classList.add("tl-theme__dark")):(t.setAttribute("data-color-mode","light"),t.classList.remove("tl-theme__dark"),t.classList.add("tl-theme__light")),r?t.classList.add("tl-theme__force-sRGB"):t.classList.remove("tl-theme__force-sRGB")},[e,t,r,n])}function qM(e){const t=P.useRef();return P.useLayoutEffect(()=>{t.current=e}),P.useDebugValue(e),P.useCallback((...n)=>{const r=t.current;return Xe(r,"fn does not exist"),r(...n)},[])}function eV(){const[e,t]=P.useState(0);P.useEffect(()=>t(n=>n+1),[])}const tV=e=>e.props.src,nV={upload:(e,t)=>Ai.blobToDataUrl(t)};function rV(e){return"schema"in e&&e.schema?e.schema:s9({shapes:"shapeUtils"in e&&e.shapeUtils?VC(KM(e.shapeUtils)):void 0,bindings:"bindingUtils"in e&&e.bindingUtils?VC(BM(e.bindingUtils)):void 0,migrations:"migrations"in e?e.migrations:void 0})}function Iu({initialData:e,defaultName:t="",id:n,assets:r=nV,onEditorMount:s,multiplayerStatus:o,...i}={}){const a=rV(i),l=new Vx({id:n,schema:a,initialData:e,props:{defaultName:t,assets:{upload:r.upload,resolve:r.resolve??tV},onEditorMount:c=>{Xe(c instanceof Z),s==null||s(c)},multiplayerStatus:o??null}});if(i.snapshot){if(e)throw new Error("Cannot provide both initialData and snapshot");zM(l,i.snapshot)}return l}function VC(e){return Object.fromEntries(e.map(t=>[t.type,{props:t.props,migrations:t.migrations}]))}const sV=(e,t)=>t.some(n=>e instanceof n);let YC,XC;function oV(){return YC||(YC=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function iV(){return XC||(XC=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const ZM=new WeakMap,_v=new WeakMap,QM=new WeakMap,iy=new WeakMap,sw=new WeakMap;function aV(e){const t=new Promise((n,r)=>{const s=()=>{e.removeEventListener("success",o),e.removeEventListener("error",i)},o=()=>{n(Ys(e.result)),s()},i=()=>{r(e.error),s()};e.addEventListener("success",o),e.addEventListener("error",i)});return t.then(n=>{n instanceof IDBCursor&&ZM.set(n,e)}).catch(()=>{}),sw.set(t,e),t}function lV(e){if(_v.has(e))return;const t=new Promise((n,r)=>{const s=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",i),e.removeEventListener("abort",i)},o=()=>{n(),s()},i=()=>{r(e.error||new DOMException("AbortError","AbortError")),s()};e.addEventListener("complete",o),e.addEventListener("error",i),e.addEventListener("abort",i)});_v.set(e,t)}let Tv={get(e,t,n){if(e instanceof IDBTransaction){if(t==="done")return _v.get(e);if(t==="objectStoreNames")return e.objectStoreNames||QM.get(e);if(t==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Ys(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function cV(e){Tv=e(Tv)}function uV(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...n){const r=e.call(ay(this),t,...n);return QM.set(r,t.sort?t.sort():[t]),Ys(r)}:iV().includes(e)?function(...t){return e.apply(ay(this),t),Ys(ZM.get(this))}:function(...t){return Ys(e.apply(ay(this),t))}}function dV(e){return typeof e=="function"?uV(e):(e instanceof IDBTransaction&&lV(e),sV(e,oV())?new Proxy(e,Tv):e)}function Ys(e){if(e instanceof IDBRequest)return aV(e);if(iy.has(e))return iy.get(e);const t=dV(e);return t!==e&&(iy.set(e,t),sw.set(t,e)),t}const ay=e=>sw.get(e);function JM(e,t,{blocked:n,upgrade:r,blocking:s,terminated:o}={}){const i=indexedDB.open(e,t),a=Ys(i);return r&&i.addEventListener("upgradeneeded",l=>{r(Ys(i.result),l.oldVersion,l.newVersion,Ys(i.transaction),l)}),n&&i.addEventListener("blocked",l=>n(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),s&&l.addEventListener("versionchange",c=>s(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function eA(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",r=>t(r.oldVersion,r)),Ys(n).then(()=>{})}const hV=["get","getKey","getAll","getAllKeys","count"],pV=["put","add","delete","clear"],ly=new Map;function qC(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(ly.get(t))return ly.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,s=pV.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(s||hV.includes(n)))return;const o=async function(i,...a){const l=this.transaction(i,s?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[n](...a),s&&l.done]))[0]};return ly.set(t,o),o}cV(e=>({...e,get:(t,n,r)=>qC(t,n)||e.get(t,n,r),has:(t,n)=>!!qC(t,n)||e.has(t,n)}));const fV="TLDRAW_DOCUMENT_v2",gV="TLDRAW_ASSET_STORE_v1",tA="TLDRAW_DB_NAME_INDEX_v2",Pe={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function nA(e){const t=fV+e;return yV(t),await JM(t,4,{upgrade(n){n.objectStoreNames.contains(Pe.Records)||n.createObjectStore(Pe.Records),n.objectStoreNames.contains(Pe.Schema)||n.createObjectStore(Pe.Schema),n.objectStoreNames.contains(Pe.SessionState)||n.createObjectStore(Pe.SessionState),n.objectStoreNames.contains(Pe.Assets)||n.createObjectStore(Pe.Assets)}})}async function mV(e){const t=window.indexedDB.databases?(await window.indexedDB.databases()).map(p=>p.name):ow(),n=gV+e;if(!t.find(p=>p===n))return;const s=await JM(n,1,{upgrade(p){p.objectStoreNames.contains("assets")||p.createObjectStore("assets")}}),o=s.transaction(["assets"],"readonly"),i=o.objectStore("assets"),a=await i.getAllKeys(),l=await Promise.all(a.map(async p=>[p,await i.get(p)]));await o.done;const c=await nA(e),u=c.transaction([Pe.Assets],"readwrite"),h=u.objectStore(Pe.Assets);for(const[p,f]of l)h.put(f,p);await u.done,s.close(),c.close(),await eA(n)}const Jc=class Jc{constructor(t){g(this,"getDbPromise");g(this,"isClosed",!1);g(this,"pendingTransactionSet",new Set);Jc.connectedInstances.add(this),this.getDbPromise=(async()=>(await mV(t),await nA(t)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(nu)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),Jc.connectedInstances.delete(this))}tx(t,n,r){const s=(async()=>{Xe(!this.isClosed,"db is closed");const i=(await this.getDb()).transaction(n,t);try{return await r(i)}finally{this.isClosed?i.abort():await i.done}})();return this.pendingTransactionSet.add(s),s.finally(()=>this.pendingTransactionSet.delete(s)),s}async load({sessionId:t}={}){return await this.tx("readonly",[Pe.Records,Pe.Schema,Pe.SessionState],async n=>{var l,c;const r=n.objectStore(Pe.Records),s=n.objectStore(Pe.Schema),o=n.objectStore(Pe.SessionState);let i=t?(l=await o.get(t))==null?void 0:l.snapshot:null;return i||(i=(c=(await o.getAll()).sort((h,p)=>h.updatedAt-p.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await s.get(Pe.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:t,changes:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Pe.Records,Pe.Schema,Pe.SessionState],async o=>{const i=o.objectStore(Pe.Records),a=o.objectStore(Pe.Schema),l=o.objectStore(Pe.SessionState);for(const[c,u]of Object.entries(n.added))await i.put(u,c);for(const[c,u]of Object.values(n.updated))await i.put(u,u.id);for(const c of Object.keys(n.removed))await i.delete(c);a.put(t.serialize(),Pe.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:t,snapshot:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Pe.Records,Pe.Schema,Pe.SessionState],async o=>{const i=o.objectStore(Pe.Records),a=o.objectStore(Pe.Schema),l=o.objectStore(Pe.SessionState);await i.clear();for(const[c,u]of Object.entries(n))await i.put(u,c);a.put(t.serialize(),Pe.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[Pe.SessionState],async t=>{const n=t.objectStore(Pe.SessionState),r=(await n.getAll()).sort((o,i)=>o.updatedAt-i.updatedAt);if(r.length<10){await t.done;return}const s=r.slice(0,r.length-10);for(const{id:o}of s)await n.delete(o)})}async getAsset(t){return await this.tx("readonly",[Pe.Assets],async n=>await n.objectStore(Pe.Assets).get(t))}async storeAsset(t,n){await this.tx("readwrite",[Pe.Assets],async r=>{await r.objectStore(Pe.Assets).put(n,t)})}};g(Jc,"connectedInstances",new Set);let mf=Jc;function ow(){const e=JSON.parse(Ux(tA)||"[]")??[];return Array.isArray(e)?e:[]}function yV(e){const t=new Set(ow());t.add(e),Hx(tA,JSON.stringify([...t]))}function SV(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
|
|
91
|
-
|
|
92
|
-
Keep seeing this message?
|
|
93
|
-
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
|
|
94
|
-
• If your hard disk is full, try clearing up some space and then reload the page.`)}function vV(){window.alert(`Oops! We could not access your browser's storage—and the app won't work correctly without that. We now need to reload the page and try again.
|
|
95
|
-
|
|
96
|
-
Keep seeing this message?
|
|
97
|
-
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const xV=350,wV=1e4,ZC=Symbol("UPDATE_INSTANCE_STATE"),bV=e=>e;class PV{constructor(t){g(this,"onmessage")}postMessage(t){}close(){}}const CV=typeof BroadcastChannel>"u"?PV:BroadcastChannel;class IV{constructor(t,{persistenceKey:n,sessionId:r=gf,onLoad:s,onLoadError:o},i=new CV(`tldraw-tab-sync-${n}`)){g(this,"disposables",new Set);g(this,"diffQueue",[]);g(this,"didDispose",!1);g(this,"shouldDoFullDBWrite",!0);g(this,"isReloading",!1);g(this,"persistenceKey");g(this,"sessionId");g(this,"serializedSchema");g(this,"isDebugging",!1);g(this,"documentTypes");g(this,"$sessionStateSnapshot");g(this,"db");g(this,"initTime",Date.now());g(this,"isPersisting",!1);g(this,"didLastWriteError",!1);g(this,"scheduledPersistTimeout",null);this.store=t,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=n,this.sessionId=r,this.db=new mf(n),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=NM(this.store),this.disposables.add(t.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(bV({type:"diff",storeId:this.store.id,changes:a,schema:this.serializedSchema})),this.schedulePersist()},{source:"user",scope:"document"})),this.disposables.add(t.listen(()=>{this.diffQueue.push(ZC),this.schedulePersist()},{scope:"session"})),this.connect(s,o),this.documentTypes=new Set(Object.values(this.store.schema.types).filter(a=>a.scope==="document").map(a=>a.typeName))}debug(...t){this.isDebugging&&console.debug(...t)}async connect(t,n){this.debug("connecting");let r;try{r=await this.db.load({sessionId:this.sessionId})}catch(s){n(s),vV();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const s=Object.fromEntries(r.records.map(a=>[a.id,a])),o=r.sessionStateSnapshot??VW(s),i=this.store.schema.migrateStoreSnapshot({store:s,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(i.type==="error"){console.error("failed to migrate store",i),n(new Error(`Failed to migrate store: ${i.reason}`));return}this.store.mergeRemoteChanges(()=>{this.store.put(Object.values(i.value).filter(a=>this.documentTypes.has(a.typeName)),"initialize")}),o&&FM(this.store,o)}this.channel.onmessage=({data:s})=>{var a,l;this.debug("got message",s);const o=s,i=this.store.schema.getMigrationsSince(o.schema);if(i.ok){if(i.value.length>0){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}}else{if(Date.now()-this.initTime<5e3){n(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(l=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||l.call(a);return}o.type==="diff"&&(this.debug("applying diff"),gs(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(o.changes),this.store.ensureStoreIsUsable()})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),t(this)}catch(s){if(this.debug("error loading data from store",s),this.didDispose)return;n(s);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(t=>t())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?wV:xV))}persistIfNeeded(){this.debug("persistIfNeeded",{isPersisting:this.isPersisting,isReloading:this.isReloading,shouldDoFullDBWrite:this.shouldDoFullDBWrite,diffQueueLength:this.diffQueue.length,storeIsPossiblyCorrupt:this.store.isPossiblyCorrupted()}),this.scheduledPersistTimeout&&(clearTimeout(this.scheduledPersistTimeout),this.scheduledPersistTimeout=null),!this.isPersisting&&(this.isReloading||this.store.isPossiblyCorrupted()||(this.shouldDoFullDBWrite||this.diffQueue.length>0)&&this.doPersist())}async doPersist(){if(Xe(!this.isPersisting,"persist already in progress"),this.didDispose)return;this.isPersisting=!0,this.debug("doPersist start");const t=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await this.db.storeSnapshot({schema:this.store.schema,snapshot:this.store.serialize(),sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const n=Gx(t.filter(r=>r!==ZC));await this.db.storeChanges({changes:n,schema:this.store.schema,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()})}this.didLastWriteError=!1}catch(n){this.shouldDoFullDBWrite=!0,this.didLastWriteError=!0,console.error("failed to store changes in indexed db",n),SV(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function rA(e){const t=P.useRef(e),[n,r]=P.useState(e);n!==t.current&&r(t.current);const s=P.useCallback(o=>{typeof o=="function"?t.current=o(t.current):t.current=o,r(t.current)},[]);return[n,s]}function EV(e){const[t,n]=rA({status:"loading"});return e=Xf(e),P.useEffect(()=>{const{persistenceKey:r,sessionId:s,...o}=e;if(!r){n({status:"not-synced",store:Iu(o)});return}n({status:"loading"});const i=new Zs,a={upload:async(h,p)=>(await u.db.storeAsset(h.id,p),h.id),resolve:async h=>h.props.src?h.props.src.startsWith("asset:")?await i.get(h,async()=>{const p=await u.db.getAsset(h.id);return p?URL.createObjectURL(p):null}):h.props.src:null,...o.assets},l=Iu({...o,assets:a});let c=!1;const u=new IV(l,{sessionId:s,persistenceKey:r,onLoad(){c||n({store:l,status:"synced-local"})},onLoadError(h){c||n({status:"error",error:h})}});return()=>{c=!0,u.close()}},[e,n]),t}function kV(){const e=F(),t=$t();P.useEffect(()=>{const n=o=>t.style.setProperty("--tl-zoom",o.toString()),r=zk(n,100),s=new kl("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?n(e.getZoomLevel()):r(e.getZoomLevel())});return s.attach(),s.execute(),()=>{s.detach(),r.cancel()}},[e,t])}function Mv(e){const t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let r=0,s=e.length;r<s;r++)n[r]=e.charCodeAt(r);return t}function _V(e){const t=atob(e),n=Mv(t);return crypto.subtle.importKey("spki",new Uint8Array(n),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const TV=5,Gh={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4},MV=Math.max(...Object.values(Gh)),Pc={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},AV=Object.keys(Pc).length,eh="sales@tldraw.com";class iw{constructor(t,n,r){g(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");g(this,"isDevelopment");g(this,"isTest");g(this,"isCryptoAvailable");g(this,"state",Mt("license state","pending"));this.isTest=!1,this.isDevelopment=this.getIsDevelopment(r),this.publicKey=n||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,Wx.enableLicensing.get()?this.getLicenseFromKey(t).then(s=>{const o=jV(s);this.state.set(o?"unlicensed":"licensed")}):this.state.set("licensed")}getIsDevelopment(t){return t==="development"?!0:t==="production"?!1:window.location.protocol!=="https:"}async extractLicenseKey(t){const[n,r]=t.split("."),[s,o]=n.split("/");if(!s.startsWith("tldraw-"))throw new Error(`Unsupported prefix '${s}'`);const i=await _V(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(Mv(atob(r))),new Uint8Array(Mv(atob(o))))}catch(c){throw console.error(c),new Error("Could not perform signature validation")}if(!a)throw new Error("Invalid signature");let l;try{l=JSON.parse(atob(o))}catch{throw new Error("Could not parse object")}return l.length>AV&&this.outputMessages(["License key contains some unknown properties.","You may want to update tldraw packages to a newer version to get access to new functionality."]),{id:l[Pc.ID],hosts:l[Pc.HOSTS],flags:l[Pc.FLAGS],expiryDate:l[Pc.EXPIRY_DATE]}}async getLicenseFromKey(t){if(!t)return this.isDevelopment||this.outputNoLicenseKeyProvided(),{isLicenseParseable:!1,reason:"no-key-provided"};if(this.isDevelopment&&!this.isCryptoAvailable)return console.log("tldraw: you seem to be in a development environment that does not support crypto. License not verified."),console.log("You should check that this works in production separately."),{isLicenseParseable:!1,reason:"has-key-development-mode"};let n=t.replace(/[\u200B-\u200D\uFEFF]/g,"");n=n.replace(/\r?\n|\r/g,"");try{const r=await this.extractLicenseKey(n),s=new Date(r.expiryDate),o=this.isFlagEnabled(r.flags,Gh.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,Gh.PERPETUAL_LICENSE),a={license:r,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(r),expiryDate:s,isAnnualLicense:o,isAnnualLicenseExpired:o&&this.isAnnualLicenseExpired(s),isPerpetualLicense:i,isPerpetualLicenseExpired:i&&this.isPerpetualLicenseExpired(s),isInternalLicense:this.isFlagEnabled(r.flags,Gh.INTERNAL_LICENSE)};return this.outputLicenseInfoIfNeeded(a),a}catch(r){return this.outputInvalidLicenseKey(r.message),{isLicenseParseable:!1,reason:"invalid-license-key"}}}isDomainValid(t){const n=window.location.hostname.toLowerCase();return t.hosts.some(r=>{const s=r.toLowerCase().trim();return s===n||`www.${s}`===n||s===`www.${n}`||r==="*"?!0:r.includes("*")?new RegExp(r.replace(/\*/g,".*?")).test(n):!1})}getExpirationDateWithoutGracePeriod(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())}getExpirationDateWithGracePeriod(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()+TV+1)}isAnnualLicenseExpired(t){const n=this.getExpirationDateWithGracePeriod(t),r=new Date>=n;return!r&&new Date>=this.getExpirationDateWithoutGracePeriod(t)&&this.outputMessages(["tldraw license is about to expire, you are in a grace period.",`Please reach out to ${eh} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(t){const n=this.getExpirationDateWithGracePeriod(t),r={major:new Date(aP.major),minor:new Date(aP.minor)};return r.major>=n||r.minor>=n}isFlagEnabled(t,n){return(t&n)===n}outputNoLicenseKeyProvided(){this.outputMessages(["No tldraw license key provided!",`Please reach out to ${eh} if you would like to license tldraw or if you'd like a trial.`])}outputInvalidLicenseKey(t){this.outputMessages(["Invalid tldraw license key",`Reason: ${t}`])}outputLicenseInfoIfNeeded(t){t.isAnnualLicenseExpired&&this.outputMessages(["Your tldraw license has expired!",`Please reach out to ${eh} to renew.`]),!t.isDomainValid&&!t.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${eh} if you would like to use tldraw on other domains.`]),t.license.flags>=MV*2&&this.outputMessages(["This tldraw license contains some unknown flags.","You may want to update tldraw packages to a newer version to get access to new functionality."])}outputMessages(t){if(!this.isTest){this.outputDelimiter();for(const n of t)console.log(`%c${n}`,"color: white; background: crimson; padding: 2px; border-radius: 3px;");this.outputDelimiter()}}outputDelimiter(){console.log("%c-------------------------------------------------------------------","color: white; background: crimson; padding: 2px; border-radius: 3px;")}}g(iw,"className","tl-watermark_SEE-LICENSE");function jV(e){if(!e.isLicenseParseable||!e.isDomainValid&&!e.isDevelopment)return!0;if(e.isPerpetualLicenseExpired||e.isAnnualLicenseExpired){if(e.isInternalLicense)throw new Error("License: Internal license expired.");return!0}return!1}const sA=P.createContext({}),OV=()=>P.useContext(sA);function DV({licenseKey:e,children:t}){const[n]=P.useState(()=>new iw(e));return d.jsx(sA.Provider,{value:n,children:t})}const RV='<svg xmlns="http://www.w3.org/2000/svg" width="3001" height="1000" fill="none"><path fill="#000" d="M590.656 300.449c0 49.706-40.294 90-90 90-49.705 0-90-40.294-90-90 0-49.705 40.295-90 90-90 49.706 0 90 40.295 90 90M569.431 719.011c-15.247 32.821-56.006 91.589-98.338 91.438-32.004-.115-38.642-30.904-17.414-50.856 17.381-16.337 28.246-48.075 31.995-72.719.415-2.728-1.556-5.197-4.272-5.679-39.666-7.04-70.746-40.877-70.746-83.417 0-48.23 38.983-87.329 87.07-87.329 39.936 0 70.172 22.237 83.369 52.397 18.839 43.055 7.117 115.733-11.664 156.165M2613.29 385.681V239.319c0-11.363 9.22-20.569 20.59-20.569h8.26c11.37 0 20.59 9.206 20.59 20.569v36.911c0 8.629 7 15.625 15.63 15.625h35.25c8.63 0 15.63-6.996 15.63-15.625v-36.911c0-11.363 9.22-20.569 20.59-20.569h8.17c11.37 0 20.59 9.206 20.59 20.569v146.362c0 11.363-9.22 20.569-20.59 20.569h-8.17c-11.37 0-20.59-9.206-20.59-20.569v-36.999c0-8.63-7-15.625-15.63-15.625h-35.25c-8.63 0-15.63 6.995-15.63 15.625v36.999c0 11.363-9.22 20.569-20.59 20.569h-8.26c-11.37 0-20.59-9.206-20.59-20.569M2391.97 239.319v146.362c0 11.348-9.16 20.569-20.49 20.569h-8.2c-11.33 0-20.49-9.221-20.49-20.569V239.319c0-11.348 9.16-20.569 20.49-20.569h8.2c11.33 0 20.49 9.221 20.49 20.569M2098.23 391.43l-42.69-146.361c-3.85-13.171 6.06-26.319 19.79-26.319h10.6c9.59 0 17.93 6.611 20.08 15.952l17.01 73.045c1.48 6.348 10.47 6.478 12.14.176l19.47-73.838c2.38-9.04 10.57-15.335 19.93-15.335h12.1c9.37 0 17.56 6.3 19.94 15.346l19.49 74.067c1.66 6.305 10.65 6.178 12.13-.171l17.09-73.294c2.15-9.339 10.49-15.948 20.08-15.948h10.53c13.72 0 23.63 13.141 19.79 26.31l-42.63 146.361c-2.56 8.789-10.63 14.829-19.79 14.829h-15.68c-9.12 0-17.16-5.98-19.76-14.709l-21.17-71.059c-1.77-5.948-10.19-5.957-11.97-.012l-21.33 71.071c-2.6 8.729-10.64 14.709-19.76 14.709h-15.59c-9.17 0-17.23-6.035-19.8-14.82M2443.23 218.75h118.59c11.38 0 20.62 9.195 20.62 20.557s-9.24 20.556-20.62 20.556h-24.79c-5.53 0-10 4.477-10 10v115.818c0 11.368-9.25 20.569-20.63 20.569h-7.65c-11.39 0-20.63-9.201-20.63-20.569V269.863c0-5.523-4.48-10-10-10h-24.89c-11.37 0-20.61-9.195-20.61-20.556s9.24-20.557 20.61-20.557M1174.15 218.75h24.64c8.35 0 15.88 5.042 19.04 12.764l34.61 83.942c2.13 5.161 9.44 5.155 11.56-.01l34.43-83.932a20.58 20.58 0 0 1 19.04-12.764h24.64c11.37 0 20.58 9.208 20.58 20.569v146.362c0 11.361-9.21 20.569-20.58 20.569h-7.09c-11.36 0-20.58-9.208-20.58-20.569l-.12-50.645c-.01-6.888-9.53-8.688-12.06-2.283l-23.46 59.332a20.57 20.57 0 0 1-19.14 13.009h-3.03a20.57 20.57 0 0 1-19.15-13.046l-23.47-59.68c-2.52-6.416-12.05-4.623-12.06 2.271l-.13 51.042c0 11.361-9.21 20.569-20.57 20.569h-7.1c-11.36 0-20.57-9.208-20.57-20.569V239.319c0-11.361 9.21-20.569 20.57-20.569"/><path fill="#000" fill-rule="evenodd" d="m1449.94 391.836 6.12-19.392a6.255 6.255 0 0 1 5.96-4.369l50.22-.061a6.24 6.24 0 0 1 5.96 4.348l6.23 19.486c2.71 8.581 10.71 14.402 19.74 14.402h9.34c14.13 0 24.15-13.791 19.61-27.151l-49.74-146.361c-2.85-8.37-10.74-13.988-19.61-13.988h-33.16c-8.87 0-16.77 5.618-19.61 13.988l-49.74 146.361c-4.54 13.36 5.48 27.151 19.61 27.151h9.32c9.04 0 17.04-5.827 19.75-14.414m31.1-98.858c1.85-5.807 10.08-5.796 11.91.016l8.83 27.916c1.28 4.028-1.73 8.134-5.96 8.134h-17.74c-4.23 0-7.24-4.119-5.95-8.151zM1681.81 406.25c18.91 0 35.39-3.686 49.36-11.168 13.97-7.544 24.73-18.394 32.24-32.489 7.56-14.105 11.29-30.866 11.29-50.182 0-19.256-3.73-35.957-11.29-50.004-7.57-14.094-18.35-24.912-32.32-32.397-13.91-7.545-30.4-11.26-49.37-11.26h-49.5c-11.38 0-20.63 9.201-20.63 20.569v146.362c0 11.368 9.25 20.569 20.63 20.569zm23.13-47.701c-6.62 3.215-14.85 4.886-24.79 4.886-10.49 0-19-8.507-19-19v-64.34c0-10.149 8.23-18.376 18.38-18.376 10.18 0 18.56 1.703 25.23 4.974 6.59 3.149 11.63 8.315 15.08 15.633 3.45 7.269 5.28 17.268 5.28 30.162 0 12.891-1.82 22.951-5.28 30.347-3.39 7.319-8.36 12.509-14.9 15.714" clip-rule="evenodd"/><path fill="#000" d="M1804.21 385.681V239.319c0-11.361 9.21-20.569 20.58-20.569h91.28c11.36 0 20.57 9.202 20.57 20.557s-9.21 20.556-20.57 20.556h-54.64a7.807 7.807 0 0 0-7.81 7.813v16.366a7.806 7.806 0 0 0 7.81 7.812h48.13c11.37 0 20.58 9.246 20.58 20.602s-9.21 20.601-20.58 20.601h-48.13a7.806 7.806 0 0 0-7.81 7.812v16.455a7.807 7.807 0 0 0 7.81 7.813h54.64c11.36 0 20.57 9.202 20.57 20.556s-9.21 20.557-20.57 20.557h-91.28c-11.37 0-20.58-9.208-20.58-20.569"/><path fill="#000" fill-rule="evenodd" d="M2875.5 68.75h-2750c-31.066 0-56.25 25.184-56.25 56.25v750c0 31.066 25.184 56.25 56.25 56.25h2750c31.07 0 56.25-25.184 56.25-56.25V125c0-31.066-25.18-56.25-56.25-56.25M125.5 0C56.464 0 .5 55.964.5 125v750c0 69.036 55.965 125 125 125h2750c69.04 0 125-55.964 125-125V125c0-69.036-55.96-125-125-125z" clip-rule="evenodd"/><path fill="#000" d="M2476.06 804.813c-10.54 0-19.82-6.947-22.81-17.068L2390.79 575.7c-4.49-15.248 6.92-30.534 22.8-30.534h27.75c11.1 0 20.72 7.686 23.18 18.52L2489 671.402c2.07 9.093 14.93 9.321 17.32.308l28.83-108.844c2.76-10.435 12.19-17.7 22.98-17.7h25.17c10.8 0 20.25 7.293 22.99 17.755l28.27 107.739c2.36 9.001 15.18 8.829 17.3-.232l25.01-106.888c2.51-10.763 12.1-18.374 23.14-18.374h27.87c15.88 0 27.29 15.286 22.8 30.534l-62.46 212.045a23.78 23.78 0 0 1-22.81 17.068h-32.12c-10.39 0-19.58-6.763-22.69-16.696l-32.08-102.694c-2.62-8.397-14.51-8.331-17.04.095l-30.74 102.346c-3.02 10.061-12.27 16.949-22.76 16.949zM1742.44 804.813h-75.81c-13.09 0-23.71-10.656-23.71-23.801V568.967c0-13.145 10.62-23.801 23.71-23.801h74.8c26.6 0 49.59 5.198 68.95 15.594 19.45 10.312 34.44 25.187 44.96 44.627 10.61 19.355 15.91 42.556 15.91 69.602q0 40.57-15.78 69.73c-10.53 19.355-25.43 34.231-44.71 44.627-19.28 10.311-42.05 15.467-68.32 15.467m-29.3-83.642c0 13.145 10.61 23.801 23.71 23.801h3.06c12.8 0 23.7-2.07 32.71-6.212 9.09-4.141 16-11.283 20.71-21.426q7.2-15.213 7.2-42.345 0-27.13-7.32-42.344c-4.8-10.143-11.87-17.285-21.22-21.426-9.26-4.142-20.63-6.212-34.1-6.212h-1.04c-13.1 0-23.71 10.656-23.71 23.801zM1460.86 804.813c-13.12 0-23.76-10.656-23.76-23.801V568.967c0-13.145 10.64-23.801 23.76-23.801h22.84c13.13 0 23.76 10.656 23.76 23.801v155.247c0 13.145 10.64 23.801 23.76 23.801h57.27c13.12 0 23.76 10.656 23.76 23.801v9.196c0 13.145-10.64 23.801-23.76 23.801zM1204.45 601.964c-13.13 0-23.77-10.656-23.77-23.801v-9.196c0-13.145 10.64-23.801 23.77-23.801h177.89c13.13 0 23.78 10.656 23.78 23.801v9.196c0 13.145-10.65 23.801-23.78 23.801h-39.38c-8.21 0-14.86 6.66-14.86 14.875v164.173c0 13.145-10.64 23.801-23.78 23.801h-21.85c-13.13 0-23.78-10.656-23.78-23.801V616.839c0-8.215-6.65-14.875-14.86-14.875z"/><path fill="#000" fill-rule="evenodd" d="M2223.05 787.891c-3.02 10.047-12.27 16.922-22.74 16.922h-25.43c-16.19 0-27.64-15.862-22.57-31.261l69.88-212.045c3.21-9.753 12.31-16.341 22.56-16.341h61.84c10.25 0 19.35 6.588 22.56 16.341l69.87 212.045c5.08 15.399-6.37 31.261-22.56 31.261h-25.43c-10.48 0-19.72-6.875-22.74-16.922l-6.7-22.2a14.84 14.84 0 0 0-14.21-10.576h-63.42c-6.55 0-12.32 4.296-14.22 10.576zm76.13-96.945-14.13-48.436c-2.46-8.451-14.36-8.602-17.04-.217l-15.46 48.436c-1.84 5.759 2.45 11.645 8.48 11.645h29.6c5.94 0 10.22-5.715 8.55-11.428" clip-rule="evenodd"/><path fill="#000" d="M1939.6 804.813c-13.13 0-23.77-10.656-23.77-23.801V568.967c0-13.145 10.64-23.801 23.77-23.801h88.13c19.24 0 36.08 3.508 50.51 10.523s25.65 17.115 33.67 30.3q12.03 19.779 12.03 47.416c0 18.595-4.14 34.273-12.41 47.036-7.64 11.913-18.18 21.101-31.63 27.564-16.98 8.159-36 11.104-54.7 11.104h-43.07c-76.56 0 4.08-135.84 4.08-84.706v7.996c0 12.117 9.81 21.941 21.91 21.941 8.12 0 16.3-.345 24.04-3.043 5.91-2.113 10.43-5.451 13.55-10.015 3.2-4.565 4.81-10.523 4.81-17.877 0-7.437-1.61-13.481-4.81-18.129-3.12-4.733-7.64-8.199-13.55-10.396-7.05-2.766-14.67-3.423-22.18-3.423-13.13 0-23.77 10.656-23.77 23.801v47.71c0 11.825 11.14 16.003 19.91 20.752 12.31 6.671 7.58 25.389-6.42 25.389-7.45 0-13.49 6.048-13.49 13.508v48.395c0 13.145-10.63 23.801-23.76 23.801zm134.89-106.758 5.41 9.95 33.51 61.622c8.62 15.86-2.84 35.186-20.87 35.186h-22.27c-8.74 0-16.77-4.798-20.92-12.496l-35.05-65.04a15.52 15.52 0 0 0-13.66-8.168c-42.24 0 40.62-82.154 73.85-21.054M931.652 0h68.748v1000h-68.748z"/></svg>',LV=`${Oo()}/watermarks/watermark-desktop.svg`,th=`data:image/svg+xml;utf8,${encodeURIComponent(RV)}`;let cy=null;async function $V(e){return e?th:(cy||(cy=Promise.race([(async()=>{try{const t=await ws(LV);if(!t.ok)return th;const n=await t.blob();return URL.createObjectURL(n)}catch{return th}})(),new Promise(t=>{setTimeout(()=>{t(th)},3e3)})])),cy)}const NV=Ce.memo(function({forceLocal:t=!1}){const n=e2(),r=F(),s=OV(),o=K("show watermark",()=>Wx.enableLicensing.get()&&r.getViewportScreenBounds().width>760&&s.state.get()==="unlicensed",[r,s]),i=K("debug mode",()=>r.getInstanceState().isDebugMode,[r]),a=K("is menu open",()=>r.getIsMenuOpen(),[r]),[l,c]=P.useState(null),u=t||s.isDevelopment;if(P.useEffect(()=>{if(!o)return;let f=!1;return(async()=>{const S=await $V(u);f||c(S)})(),()=>{f=!0}},[u,o]),!o||!l)return null;const h=iw.className,p=`url('${l}') center 100% / 100% no-repeat`;return d.jsxs(d.Fragment,{children:[d.jsx("style",{children:`
|
|
98
|
-
/* ------------------- SEE LICENSE -------------------
|
|
99
|
-
The tldraw watermark is part of tldraw's license. It is shown for unlicensed
|
|
100
|
-
users. By using this library, you agree to keep the watermark's behavior,
|
|
101
|
-
keeping it visible, unobscured, and available to user-interaction.
|
|
102
|
-
|
|
103
|
-
To remove the watermark, please purchase a license at tldraw.dev.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
.${h} {
|
|
107
|
-
position: absolute;
|
|
108
|
-
bottom: var(--space-2);
|
|
109
|
-
right: var(--space-2);
|
|
110
|
-
width: 96px;
|
|
111
|
-
height: 32px;
|
|
112
|
-
z-index: 2147483647 !important;
|
|
113
|
-
pointer-events: ${a?"none":"all"};
|
|
114
|
-
background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
|
|
115
|
-
border-radius: 5px;
|
|
116
|
-
padding: 2px;
|
|
117
|
-
box-sizing: content-box;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
.${h}[data-debug='true'] {
|
|
121
|
-
bottom: 46px;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.${h} > a {
|
|
125
|
-
position: absolute;
|
|
126
|
-
width: 96px;
|
|
127
|
-
height: 32px;
|
|
128
|
-
pointer-events: none;
|
|
129
|
-
cursor: inherit;
|
|
130
|
-
color: var(--color-text);
|
|
131
|
-
background-color: currentColor;
|
|
132
|
-
opacity: .28;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@media (hover: hover) {
|
|
136
|
-
.${h}:hover {
|
|
137
|
-
background-color: var(--color-background);
|
|
138
|
-
transition: background-color 0.2s ease-in-out;
|
|
139
|
-
transition-delay: 0.32s;
|
|
140
|
-
}
|
|
141
|
-
.${h}:hover > a {
|
|
142
|
-
animation: delayed_link 0.2s forwards ease-in-out;
|
|
143
|
-
animation-delay: 0.32s;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
@keyframes delayed_link {
|
|
148
|
-
0% {
|
|
149
|
-
cursor: inherit;
|
|
150
|
-
opacity: .38;
|
|
151
|
-
pointer-events: none;
|
|
152
|
-
}
|
|
153
|
-
100% {
|
|
154
|
-
cursor: pointer;
|
|
155
|
-
opacity: 1;
|
|
156
|
-
pointer-events: all;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
`}),d.jsx("div",{className:h,"data-debug":i,draggable:!1,...n,children:d.jsx("a",{href:"https://tldraw.dev",target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:Ot,style:{mask:p,WebkitMask:p}})})]})}),FV=[],zV=[],BV=[],UV="tl-container",HV=P.memo(function({store:t,components:n,className:r,user:s,...o}){const[i,a]=Ce.useState(null),l=P.useMemo(()=>s??j2(),[s]),c=(n==null?void 0:n.ErrorFallback)===void 0?P2:n==null?void 0:n.ErrorFallback,u={...o,shapeUtils:o.shapeUtils??FV,bindingUtils:o.bindingUtils??zV,tools:o.tools??BV,components:n};return d.jsx("div",{ref:a,"data-tldraw":X_,draggable:!1,className:ce(`${UV} tl-theme__light`,r),onPointerDown:Ot,tabIndex:-1,children:d.jsx(au,{fallback:c,onError:h=>zx(h,{tags:{origin:"react.tldraw-before-app"}}),children:i&&d.jsx(DV,{licenseKey:o.licenseKey,children:d.jsx(P9,{container:i,children:d.jsx(kH,{overrides:n,children:t?t instanceof Vx?d.jsx(iA,{...u,store:t,user:l}):d.jsx(oA,{...u,store:t,user:l}):d.jsx(KV,{...u,store:t,user:l})})})})})})});function KV(e){const{defaultName:t,snapshot:n,initialData:r,shapeUtils:s,bindingUtils:o,persistenceKey:i,sessionId:a,user:l,assets:c}=e,u=EV({shapeUtils:s,bindingUtils:o,initialData:r,persistenceKey:i,sessionId:a,defaultName:t,snapshot:n,assets:c});return d.jsx(oA,{...e,store:u,user:l})}const oA=P.memo(function({store:t,user:n,...r}){const s=$t();P.useLayoutEffect(()=>{n.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,n]);const{LoadingScreen:o}=ot();switch(t.status){case"error":throw t.error;case"loading":return o?d.jsx(o,{}):null}return d.jsx(iA,{...r,store:t.store,user:n})});function iA({onMount:e,children:t,store:n,tools:r,shapeUtils:s,bindingUtils:o,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:u,options:h,licenseKey:p}){const{ErrorFallback:f}=ot(),S=$t(),[y,x]=rA(null),m=P.useRef({autoFocus:l,inferDarkMode:c,initialState:a,cameraOptions:u});P.useLayoutEffect(()=>{m.current={autoFocus:l,inferDarkMode:c,initialState:a,cameraOptions:u}},[l,c,a,u]),P.useLayoutEffect(()=>{const{autoFocus:C,inferDarkMode:E,initialState:_,cameraOptions:I}=m.current,k=new Z({store:n,shapeUtils:s,bindingUtils:o,tools:r,getContainer:()=>S,user:i,initialState:_,autoFocus:C,inferDarkMode:E,cameraOptions:I,options:h,licenseKey:p});return x(k),()=>{k.dispose()}},[o,S,h,s,n,r,i,x,p]),P.useLayoutEffect(()=>{y&&u&&y.setCameraOptions(u)},[y,u]);const v=P.useSyncExternalStore(P.useCallback(C=>y?(y.on("crash",C),()=>y.off("crash",C)):()=>{},[y]),()=>(y==null?void 0:y.getCrashingError())??null),{Canvas:w}=ot();return y?d.jsx(au,{fallback:f,onError:C=>y.annotateError(C,{origin:"react.tldraw",willCrashApp:!0}),children:v?d.jsx(GV,{crashingError:v}):d.jsx(Vf.Provider,{value:y,children:d.jsxs(WV,{onMount:e,children:[t??(w?d.jsx(w,{}):null),d.jsx(NV,{})]})})}):null}function WV({children:e,onMount:t}){return kV(),QG(),JG(),eV(),lA(n=>{const r=n.store.props.onEditorMount(n),s=t==null?void 0:t(n);return()=>{r==null||r(),s==null||s()}}),e}function GV({crashingError:e}){throw e}function aw({children:e}){return d.jsx("div",{className:"tl-loading",children:e})}function aA({children:e}){return d.jsx("div",{className:"tl-loading",children:e})}function lA(e){const t=F(),n=qM(r=>{let s;return r.run(()=>{s=e==null?void 0:e(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});Ce.useLayoutEffect(()=>{if(t)return n==null?void 0:n(t)},[t,n])}function Gi({children:e,className:t="",...n}){return d.jsx("div",{...n,className:ce("tl-html-container",t),children:e})}class Vh{constructor(t){this.editor=t}}g(Vh,"props"),g(Vh,"migrations"),g(Vh,"type");function lw(e,t,n={}){const{newPoint:r,handle:s,scaleX:o,scaleY:i}=t,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let h=e.props.w*o,p=e.props.h*i;const f=new b(0,0);if(h>0){if(h<a){switch(s){case"top_left":case"left":case"bottom_left":{f.x=h-a;break}case"top":case"bottom":{f.x=(h-a)/2;break}default:f.x=0}h=a}}else if(f.x=h,h=-h,h<a){switch(s){case"top_left":case"left":case"bottom_left":{f.x=-h;break}default:f.x=-a}h=a}if(p>0){if(p<c){switch(s){case"top_left":case"top":case"top_right":{f.y=p-c;break}case"right":case"left":{f.y=(p-c)/2;break}default:f.y=0}p=c}}else if(f.y=p,p=-p,p<c){switch(s){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-c}p=c}const{x:S,y}=f.rot(e.rotation).add(r);return{...e,x:S,y,props:{w:Math.min(l,h),h:Math.min(u,p)}}}class Dl extends Wr{constructor(){super(...arguments);g(this,"onResize",(n,r)=>lw(n,r))}getGeometry(n){return new ro({width:n.props.w,height:n.props.h,isFilled:!0})}getHandleSnapGeometry(n){return{points:this.getGeometry(n).bounds.cornersAndCenter}}getInterpolatedProps(n,r,s){return{...r.props,w:On(n.props.w,r.props.w,s),h:On(n.props.h,r.props.h,s)}}}var Ny;let VV=(Ny=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Ny,"id","idle"),Ny);var Fy;let YV=(Fy=class extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"wasFocusedOnEnter",!1);g(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});g(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,s=this.parent.shapeType,o=$e();this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:s,x:r.x,y:r.y,props:{w:1,h:1}}]).select(o),this.editor.setCurrentTool("select.resizing",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:this.parent.onCreate})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:n}=this.editor.inputs;if(!this.wasFocusedOnEnter)return;this.editor.mark(this.markId);const r=this.parent.shapeType,s=$e();this.editor.mark(this.markId),this.editor.createShapes([{id:s,type:r,x:n.x,y:n.y}]);const o=this.editor.getShape(s);if(!o){this.cancel();return}let{w:i,h:a}=o.props;const l=new b(i/2,a/2),c=this.editor.getShapeParentTransform(o);c&&l.rot(-c.rotation());let u=1;this.editor.user.getIsDynamicResizeMode()&&(u=1/this.editor.getZoomLevel(),i*=u,a*=u,l.mul(u));const h=Ge(o);h.x=o.x-l.x,h.y=o.y-l.y,h.props.w=i,h.props.h=a,"scale"in o.props&&(h.props.scale=u),this.editor.updateShape(h),this.editor.setSelectedShapes([s]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},g(Fy,"id","pointing"),Fy);class Yh extends se{constructor(){super(...arguments);g(this,"onCreate")}}g(Yh,"id","box"),g(Yh,"initial","idle"),g(Yh,"children",()=>[VV,YV]);function gg(e){const t=F();return K("isEditing",()=>t.getEditingShapeId()===e,[t,e])}function is(e){const t=F();return P.useMemo(function(){const s=c=>{if(c.isKilled)return;if(c.button===r0){t.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...Nn(c)});return}if(c.button!==0)return;const u=Up(c.currentTarget);function h(){u.removeEventListener("pointerup",h),Gu(u,c)}Wu(u,c),u.addEventListener("pointerup",h),t.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...Nn(c)}),Ot(c)};let o,i;function a(c){c.isKilled||c.button===0&&(c.clientX===o&&c.clientY===i||(o=c.clientX,i=c.clientY,t.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...Nn(c)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&t.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...Nn(c)})}}},[t,e])}function XV(e){const[t,n]=P.useState(()=>({store:Iu(e),opts:e}));if(!Gk(t.opts,e)){const r={store:Iu(e),opts:e};return n(r),r.store}return t.store}const qV=20,ZV=8;function cw(e,t=qV){return Math.max(ZV,Math.ceil(e/t))}class Ua extends ii{constructor(n){super({...n,isFilled:!1,isClosed:!1});g(this,"_center");g(this,"radius");g(this,"start");g(this,"end");g(this,"largeArcFlag");g(this,"sweepFlag");g(this,"measure");g(this,"angleStart");g(this,"angleEnd");const{center:r,sweepFlag:s,largeArcFlag:o,start:i,end:a}=n;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=b.Angle(r,i),this.angleEnd=b.Angle(r,a),this.radius=b.Dist(r,i),this.measure=S9(this.angleStart,this.angleEnd,s,o),this.start=i,this.end=a,this.sweepFlag=s,this.largeArcFlag=o,this._center=r}nearestPoint(n){const{_center:r,measure:s,radius:o,angleEnd:i,angleStart:a,start:l,end:c}=this,u=TS(s,a,i,r.angle(n));if(u<=0)return l;if(u>=1)return c;const h=r.clone().add(n.clone().sub(r).uni().mul(o));let p,f=1/0,S;for(const y of[l,c,h])S=b.Dist2(n,y),S<f&&(p=y,f=S);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(n,r){const{_center:s,radius:o,measure:i,angleStart:a,angleEnd:l}=this,c=Ju(n,r,s,o);return c===null?!1:c.some(u=>{const h=TS(i,a,l,s.angle(u));return h>=0&&h<=1})}getVertices(){const{_center:n,measure:r,length:s,radius:o,angleStart:i}=this,a=[];for(let l=0,c=cw(Math.abs(s));l<c+1;l++){const u=l/c*r,h=i+u;a.push(zi(n,o,h))}return a}getSvgPathData(n=!0){const{start:r,end:s,radius:o,largeArcFlag:i,sweepFlag:a}=this;return`${n?`M${r.toFixed()}`:""} A${o} ${o} 0 ${i} ${a} ${s.toFixed()}`}getLength(){return this.measure*this.radius}}class uw extends ii{constructor(n){super({isClosed:!0,...n});g(this,"_center");g(this,"radius");g(this,"x");g(this,"y");this.config=n;const{x:r=0,y:s=0,radius:o}=n;this.x=r,this.y=s,this._center=new b(o+r,o+s),this.radius=o}getBounds(){return new Q(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,s=Le*r,o=[];for(let i=0,a=cw(s);i<a;i++){const l=i/a*Le;o.push(zi(n,r,l))}return o}nearestPoint(n){const{_center:r,radius:s}=this;return r.equals(n)?b.AddXY(r,s,0):r.clone().add(n.clone().sub(r).uni().mul(s))}hitTestLineSegment(n,r,s=0){const{_center:o,radius:i}=this;return Ju(n,r,o,i+s)!==null}getSvgPathData(){const{_center:n,radius:r}=this;return`M${n.x+r},${n.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class on extends Ol{constructor(n){const{start:r,cp1:s,cp2:o,end:i}=n;super({...n,points:[r,i]});g(this,"a");g(this,"b");g(this,"c");g(this,"d");this.a=r,this.b=s,this.c=o,this.d=i}getVertices(){const n=[],{a:r,b:s,c:o,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;n.push(new b((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*s.x+3*(1-c)*(c*c)*o.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*s.y+3*(1-c)*(c*c)*o.y+c*c*c*i.y))}return n}midPoint(){return on.GetAtT(this,.5)}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=b.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}getSvgPathData(n=!0){const{a:r,b:s,c:o,d:i}=this;return`${n?`M ${r.toFixed()} `:""} C${s.toFixed()} ${o.toFixed()} ${i.toFixed()}`}static GetAtT(n,r){const{a:s,b:o,c:i,d:a}=n;return new b((1-r)*(1-r)*(1-r)*s.x+3*((1-r)*(1-r))*r*o.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*s.y+3*((1-r)*(1-r))*r*o.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(n=32){let r,s=this.a,o=0;for(let i=1;i<=n;i++)r=on.GetAtT(this,i/n),o+=b.Dist(s,r),s=r;return o}}class QV extends ii{constructor(n){super({...n,isClosed:!1,isFilled:!1});g(this,"points");g(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,s=r-2,o=1.25;for(let i=0;i<r-1;i++){const a=i===0?n[0]:n[i-1],l=n[i],c=n[i+1],u=i===s?c:n[i+2],h=l,p=i===0?a:new b(l.x+(c.x-a.x)/6*o,l.y+(c.y-a.y)/6*o),f=i===s?c:new b(c.x-(u.x-l.x)/6*o,c.y-(u.y-l.y)/6*o),S=c;this._segments.push(new on({start:h,cp1:p,cp2:f,end:S}))}}return this._segments}getLength(){return this.segments.reduce((n,r)=>n+r.length,0)}getVertices(){const n=this.segments.reduce((r,s)=>r.concat(s.vertices),[]);return n.push(this.points[this.points.length-1]),n}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=b.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.segments.some(s=>s.hitTestLineSegment(n,r))}getSvgPathData(){let n=this.segments.reduce((r,s,o)=>r+s.getSvgPathData(o===0),"");return this.isClosed&&(n+="Z"),n}}class JV extends ii{constructor(n){super({...n,isClosed:!0});g(this,"w");g(this,"h");g(this,"_edges");this.config=n;const{width:r,height:s}=n;this.w=r,this.h=s}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,s=n.length;r<s;r++){const o=n[r],i=n[(r+1)%s];this._edges.push(new Ks({start:o,end:i}))}}return this._edges}getVertices(){const n=Math.max(1,this.w),r=Math.max(1,this.h),s=n/2,o=r/2,i=Math.pow(s-o,2)/Math.pow(s+o,2),a=Me*(s+o)*(1+3*i/(10+Math.sqrt(4-3*i))),l=cw(a),c=Le/l,u=Math.cos(c),h=Math.sin(c);let p=0,f=1,S=0,y=1;const x=Array(l);for(let m=0;m<l;m++)x[m]=new b(s+s*f,o+o*p),S=h*f+u*p,y=u*f-h*p,p=S,f=y;return x}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.edges)i=a.nearestPoint(n),o=b.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(s=>s.hitTestLineSegment(n,r))}getBounds(){return new Q(0,0,this.w,this.h)}getLength(){const{w:n,h:r}=this,s=n/2,o=r/2,i=Math.max(0,s),a=Math.max(0,o);return Z_(i,a)}getSvgPathData(n=!1){const{w:r,h:s}=this,o=r/2,i=s/2,a=Math.max(0,o),l=Math.max(0,i);return`${n?`M${o-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class eY extends ii{constructor(n){super({...n,isClosed:!0});g(this,"w");g(this,"h");g(this,"a");g(this,"b");g(this,"c");g(this,"d");this.config=n;const{width:r,height:s}=n;if(this.w=r,this.h=s,s>r){const o=r/2;this.a=new Ua({start:new b(0,o),end:new b(r,o),center:new b(r/2,o),sweepFlag:1,largeArcFlag:1}),this.b=new Ks({start:new b(r,o),end:new b(r,s-o)}),this.c=new Ua({start:new b(r,s-o),end:new b(0,s-o),center:new b(r/2,s-o),sweepFlag:1,largeArcFlag:1}),this.d=new Ks({start:new b(0,s-o),end:new b(0,o)})}else{const o=s/2;this.a=new Ua({start:new b(o,s),end:new b(o,0),center:new b(o,o),sweepFlag:1,largeArcFlag:1}),this.b=new Ks({start:new b(o,0),end:new b(r-o,0)}),this.c=new Ua({start:new b(r-o,0),end:new b(r-o,s),center:new b(r-o,o),sweepFlag:1,largeArcFlag:1}),this.d=new Ks({start:new b(r-o,s),end:new b(o,s)})}}nearestPoint(n){let r,s=1/0,o,i;const{a,b:l,c,d:u}=this;for(const h of[a,l,c,u])i=h.nearestPoint(n),o=b.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){const{a:s,b:o,c:i,d:a}=this;return[s,o,i,a].some(l=>l.hitTestLineSegment(n,r))}getVertices(){const{a:n,b:r,c:s,d:o}=this;return[n,r,s,o].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new Q(0,0,this.w,this.h)}getLength(){const{h:n,w:r}=this;return n>r?(Me*(r/2)+(n-r))*2:(Me*(n/2)+(r-n))*2}getSvgPathData(){const{a:n,b:r,c:s,d:o}=this;return[n,r,s,o].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function tY({shouldReload:e=!0}={}){kB();for(const t of mf.connectedInstances)await t.close();await Promise.all(ow().map(t=>eA(t))),EB(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=tY);function nY(e,t="_blank"){a0.openWindow(e,t)}function rY({children:e}){const t=F();return K("shouldDisplayHandles",()=>{if(t.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(t.isInAny("select.editing_shape")){const r=t.getOnlySelectedShape();return r&&t.isShapeOfType(r,"note")}return!1},[t])?d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:sY}=Math,nl=sY+1e-4;function cA(e,t={}){const{size:n=16,smoothing:r=.5}=t;if(e.length===0||n<=0)return{left:[],right:[]};const s=e[0],o=e[e.length-1],i=o.runningLength,a=Math.pow(n*r,2),l=[],c=[];let u=e[0].vector,h=e[0].point,p=h,f=h,S=p,y=!1,x;for(let m=0;m<e.length;m++){x=e[m];const{point:v,vector:w}=e[m],C=x.vector.dpr(u),E=(m<e.length-1?e[m+1]:e[m]).vector,_=m<e.length-1?E.dpr(x.vector):1,I=C<0&&!y,k=_!==null&&_<.2;if(I||k){if(_>-.62&&i-x.runningLength>x.radius){const M=u.clone().mul(x.radius);u.clone().cpr(E)<0?(f=b.Add(v,M),S=b.Sub(v,M)):(f=b.Sub(v,M),S=b.Add(v,M)),l.push(f),c.push(S)}else{const M=u.clone().mul(x.radius).per(),D=b.Sub(x.input,M);for(let $=1/13,j=0;j<1;j+=$)f=b.RotWith(D,x.input,nl*j),l.push(f),S=b.RotWith(D,x.input,nl+nl*-j),c.push(S)}h=f,p=S,k&&(y=!0);continue}if(y=!1,x===s||x===o){const M=b.Per(w).mul(x.radius);l.push(b.Sub(v,M)),c.push(b.Add(v,M));continue}const T=b.Lrp(E,w,_).per().mul(x.radius);f=b.Sub(v,T),(m<=1||b.Dist2(h,f)>a)&&(l.push(f),h=f),S=b.Add(v,T),(m<=1||b.Dist2(p,S)>a)&&(c.push(S),p=S),u=w}return{left:l,right:c}}function dw(e,t={}){const{size:n=16,start:r={},end:s={},last:o=!1}=t,{cap:i=!0}=r,{cap:a=!0}=s;if(e.length===0||n<=0)return[];const l=e[0],c=e[e.length-1],u=c.runningLength,h=r.taper===!1?0:r.taper===!0?Math.max(n,u):r.taper,p=s.taper===!1?0:s.taper===!0?Math.max(n,u):s.taper,{left:f,right:S}=cA(e,t),y=l.point,x=e.length>1?e[e.length-1].point:b.AddXY(l.point,1,1);if(e.length===1&&(!(h||p)||o)){const C=b.Add(y,b.Sub(y,x).uni().per().mul(-l.radius)),E=[];for(let _=1/13,I=_;I<=1;I+=_)E.push(b.RotWith(C,y,nl*2*I));return E}const m=[];if(!(h||p&&e.length===1))if(i)for(let C=1/8,E=C;E<=1;E+=C){const _=b.RotWith(S[0],y,nl*E);m.push(_)}else{const C=b.Sub(f[0],S[0]),E=b.Mul(C,.5),_=b.Mul(C,.51);m.push(b.Sub(y,E),b.Sub(y,_),b.Add(y,_),b.Add(y,E))}const v=[],w=c.vector.clone().per().neg();if(p||h&&e.length===1)v.push(x);else if(a){const C=b.Add(x,b.Mul(w,c.radius));for(let E=1/29,_=E;_<1;_+=E)v.push(b.RotWith(C,x,nl*3*_))}else v.push(b.Add(x,b.Mul(w,c.radius)),b.Add(x,b.Mul(w,c.radius*.99)),b.Sub(x,b.Mul(w,c.radius*.99)),b.Sub(x,b.Mul(w,c.radius)));return f.concat(v,S.reverse(),m)}const oY=.025,iY=.01;function Cs(e,t={}){var x;const{streamline:n=.5,size:r=16,simulatePressure:s=!1}=t;if(e.length===0)return[];const o=.15+(1-n)*.85;let i=e.map(b.From),a=0;if(!s){let m=i[0];for(;m&&!(m.z>=oY);)i.shift(),m=i[0]}if(!s){let m=i[i.length-1];for(;m&&!(m.z>=iY);)i.pop(),m=i[i.length-1]}if(i.length===0)return[{point:b.From(e[0]),input:b.From(e[0]),pressure:s?.5:.15,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(b.Dist2(l,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(b.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=t.last||!t.simulatePressure||i.length>1&&b.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&t.simulatePressure){const m=i[1];i=i.slice(0,-1);for(let v=1;v<5;v++){const w=b.Lrp(i[0],m,v/4);w.z=(i[0].z+(m.z-i[0].z))*v/4,i.push(w)}}const h=[{point:i[0],input:i[0],pressure:s?.5:i[0].z,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let p=0,f=h[0],S,y;u&&n>0&&i.push(i[i.length-1].clone());for(let m=1,v=i.length;m<v;m++)S=!o||t.last&&m===v-1?i[m].clone():i[m].clone().lrp(f.point,1-o),!f.point.equals(S)&&(y=b.Dist(S,f.point),p+=y,!(m<4&&p<r)&&(f={input:i[m],point:S,pressure:s?.5:i[m].z,vector:b.Sub(f.point,S).uni(),distance:y,runningLength:p,radius:1},h.push(f)));if((x=h[1])!=null&&x.vector&&(h[0].vector=h[1].vector.clone()),p<1){const m=Math.max(.5,...h.map(v=>v.pressure));h.forEach(v=>v.pressure=m)}return h}const{min:bo}=Math,uy=.275;function mg(e,t){const{size:n=16,thinning:r=.5,simulatePressure:s=!0,easing:o=x=>x,start:i={},end:a={}}=t,{easing:l=At.easeOutQuad}=i,{easing:c=At.easeOutCubic}=a,u=e[e.length-1].runningLength;let h,p=e[0].pressure,f;if(!s&&u<n){const x=e.reduce((m,v)=>Math.max(m,v.pressure),.5);return e.forEach(m=>{m.pressure=x,m.radius=n*o(.5-r*(.5-m.pressure))}),e}else{let x;for(let m=0,v=e.length;m<v&&(f=e[m],!(f.runningLength>n*5));m++){const w=bo(1,f.distance/n);if(s){const C=bo(1,1-w);x=bo(1,p+(C-p)*(w*uy))}else x=bo(1,p+(f.pressure-p)*.5);p=p+(x-p)*.5}for(let m=0;m<e.length;m++){if(f=e[m],r){let{pressure:v}=f;const w=bo(1,f.distance/n);if(s){const C=bo(1,1-w);v=bo(1,p+(C-p)*(w*uy))}else v=bo(1,p+(v-p)*(w*uy));f.radius=n*o(.5-r*(.5-v)),p=v}else f.radius=n/2;h===void 0&&(h=f.radius)}}const S=i.taper===!1?0:i.taper===!0?Math.max(n,u):i.taper,y=a.taper===!1?0:a.taper===!0?Math.max(n,u):a.taper;if(S||y)for(let x=0;x<e.length;x++){f=e[x];const{runningLength:m}=f,v=m<S?l(m/S):1,w=u-m<y?c((u-m)/y):1;f.radius=Math.max(.01,f.radius*Math.min(v,w))}return e}function aY(e,t={}){return dw(mg(Cs(e,t),t),t)}function QC({scribble:e,zoom:t,color:n,opacity:r,className:s}){if(!e.points.length)return null;const o=aY(e.points,{size:e.size/t,start:{taper:e.taper,easing:At.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(o.length<4){const a=e.size/t/2,{x:l,y:c}=e.points[e.points.length-1];i=`M ${l-a},${c} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=o0(o);return d.jsx("svg",{className:s&&ce("tl-overlays__item",s),children:d.jsx("path",{className:"tl-scribble",d:i,fill:n??`var(--color-${e.color})`,opacity:r??e.opacity})})}const lY=({bounds:e,rotation:t})=>{const n=F();return K("should display",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[n])?d.jsx(S2,{bounds:e,rotation:t}):null};function uo(){const e=F();return K("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function cY({size:e,width:t,height:n,hideAlternateHandles:r}){const s=N(e/3),o=s/2;return d.jsxs("svg",{className:"tl-overlays__item",children:[d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
160
|
-
${N(0-o)},${N(e)}
|
|
161
|
-
${N(0-o)},${N(0-o)}
|
|
162
|
-
${N(e)},${N(0-o)}`,strokeWidth:s,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(t/2-e),y1:N(0-o),x2:N(t/2+e),y2:N(0-o),strokeWidth:s,"data-testid":"selection.crop.top","aria-label":"top handle"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
163
|
-
${N(t-e)},${N(0-o)}
|
|
164
|
-
${N(t+o)},${N(0-o)}
|
|
165
|
-
${N(t+o)},${N(e)}`,strokeWidth:s,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(t+o),y1:N(n/2-e),x2:N(t+o),y2:N(n/2+e),strokeWidth:s,"data-testid":"selection.crop.right","aria-label":"right handle"}),d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
166
|
-
${N(t+o)},${N(n-e)}
|
|
167
|
-
${N(t+o)},${N(n+o)}
|
|
168
|
-
${N(t-e)},${N(n+o)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(t/2-e),y1:N(n+o),x2:N(t/2+e),y2:N(n+o),strokeWidth:s,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
169
|
-
${N(0+e)},${N(n+o)}
|
|
170
|
-
${N(0-o)},${N(n+o)}
|
|
171
|
-
${N(0-o)},${N(n-e)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(0-o),y1:N(n/2-e),x2:N(0-o),y2:N(n/2+e),strokeWidth:s,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const uY=Lt(function({bounds:t,rotation:n}){const r=F(),s=P.useRef(null),o=uo(),i=is("top"),a=is("right"),l=is("bottom"),c=is("left"),u=is("top_left"),h=is("top_right"),p=is("bottom_right"),f=is("bottom_left"),S=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",y=r.getInstanceState().isCoarsePointer,x=r.getOnlySelectedShape(),m=x&&r.isShapeOrAncestorLocked(x),v=x?r.getShapeUtil(x).expandSelectionOutlinePx(x):0;if(Ml(s,t==null?void 0:t.x,t==null?void 0:t.y,1,r.getSelectionRotation(),{x:-v,y:-v}),!t)return null;t=t.clone().expandBy(v).zeroFix();const w=r.getZoomLevel(),C=r.getInstanceState().isChangingStyle,E=t.width,_=t.height,I=8/w,k=E<I*2,T=_<I*2,M=E<I*4,D=_<I*4,$=E<I*5,j=_<I*5,O=y?1.75:1,R=6/w*O,H=(M?R/2:R)*(O*.75),B=(D?R/2:R)*(O*.75),z=(x?!r.getShapeUtil(x).hideSelectionBoundsFg(x):!0)&&!C;let W=z&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle","select.pointing_resize_handle")||z&&r.isIn("select.resizing")&&x&&r.isShapeOfType(x,"text");x&&W&&r.environment.isFirefox&&r.isShapeOfType(x,"embed")&&(W=!1);const Y=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!C&&!o,q=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!C&&!o,le=!y&&!(k||T)&&(q||Y)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!m,ge=y&&(!M||!D)&&(q||Y)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!m,be=q&&(x?r.getShapeUtil(x).canResize(x)&&!r.getShapeUtil(x).hideResizeHandles(x):!0)&&!Y&&!m,J=k||T,Ue=k&&T,Oe=$||j,nt=be||Y,je=!le,it=!q||!ge,Fe=!q||!nt,Xn=!q||!nt||J,Nt=!q||!nt||J,_n=!q||!nt||Ue&&!Y;let St=!0,Qt=!0;if(Y)St=Oe,Qt=Oe;else if(be){St=J||Ue||y;const mo=y&&x&&x.type==="text";Qt=St&&!mo}const As=Math.min(24/w,_-B*3),Nl=q&&y&&x&&r.isShapeOfType(x,"text")&&As*w>=4;return d.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsxs("g",{ref:s,children:[W&&d.jsx("rect",{className:"tl-selection__fg__outline",width:N(E),height:N(_)}),d.jsx(nh,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:R,corner:"top_left_rotate",cursor:S?Zn("nwse-rotate",n):void 0,isHidden:je}),d.jsx(nh,{"data-testid":"selection.rotate.top-right",cx:E+R*3,cy:0,targetSize:R,corner:"top_right_rotate",cursor:S?Zn("nesw-rotate",n):void 0,isHidden:je}),d.jsx(nh,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:_+R*3,targetSize:R,corner:"bottom_left_rotate",cursor:S?Zn("swne-rotate",n):void 0,isHidden:je}),d.jsx(nh,{"data-testid":"selection.rotate.bottom-right",cx:E+R*3,cy:_+R*3,targetSize:R,corner:"bottom_right_rotate",cursor:S?Zn("senw-rotate",n):void 0,isHidden:je}),d.jsx(hY,{"data-testid":"selection.rotate.mobile",cx:M?-R*1.5:E/2,cy:M?_/2:-R*1.5,size:I,isHidden:it}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":St}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:N(0-(D?B*2:B)),width:N(E),height:N(Math.max(1,B*2)),style:S?{cursor:Zn("ns-resize",n)}:void 0,...i}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Qt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:N(E-(M?0:H)),y:0,height:N(_),width:N(Math.max(1,H*2)),style:S?{cursor:Zn("ew-resize",n)}:void 0,...a}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":St}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:N(_-(D?0:B)),width:N(E),height:N(Math.max(1,B*2)),style:S?{cursor:Zn("ns-resize",n)}:void 0,...l}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Qt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:N(0-(M?H*2:H)),y:0,height:N(_),width:N(Math.max(1,H*2)),style:S?{cursor:Zn("ew-resize",n)}:void 0,...c}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Fe}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:N(0-(M?H*2:H*1.5)),y:N(0-(D?B*2:B*1.5)),width:N(H*3),height:N(B*3),style:S?{cursor:Zn("nwse-resize",n)}:void 0,...u}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Xn}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:N(E-(M?0:H*1.5)),y:N(0-(D?B*2:B*1.5)),width:N(H*3),height:N(B*3),style:S?{cursor:Zn("nesw-resize",n)}:void 0,...h}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":_n}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:N(E-(M?H:H*1.5)),y:N(_-(D?B:B*1.5)),width:N(H*3),height:N(B*3),style:S?{cursor:Zn("nwse-resize",n)}:void 0,...p}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Nt}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:N(0-(M?H*3:H*1.5)),y:N(_-(D?0:B*1.5)),width:N(H*3),height:N(B*3),style:S?{cursor:Zn("nesw-resize",n)}:void 0,...f}),be&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.resize.top-left",className:ce("tl-corner-handle",{"tl-hidden":Fe}),"aria-label":"top_left handle",x:N(0-I/2),y:N(0-I/2),width:N(I),height:N(I)}),d.jsx("rect",{"data-testid":"selection.resize.top-right",className:ce("tl-corner-handle",{"tl-hidden":Xn}),"aria-label":"top_right handle",x:N(E-I/2),y:N(0-I/2),width:N(I),height:N(I)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ce("tl-corner-handle",{"tl-hidden":_n}),"aria-label":"bottom_right handle",x:N(E-I/2),y:N(_-I/2),width:N(I),height:N(I)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ce("tl-corner-handle",{"tl-hidden":Nt}),"aria-label":"bottom_left handle",x:N(0-I/2),y:N(_-I/2),width:N(I),height:N(I)})]}),Nl&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:N(0-I/4),y:N(_/2-As/2),rx:I/4,width:N(I/2),height:N(As)}),d.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:I/4,x:N(E-I/4),y:N(_/2-As/2),width:N(I/2),height:N(As)})]}),Y&&d.jsx(cY,{size:I,width:E,height:_,hideAlternateHandles:Oe})]})})}),nh=function({cx:t,cy:n,targetSize:r,corner:s,cursor:o,isHidden:i,"data-testid":a}){const l=is(s);return d.jsx("rect",{className:ce("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${s} target`,pointerEvents:"all",x:N(t-r*3),y:N(n-r*3),width:N(Math.max(1,r*3)),height:N(Math.max(1,r*3)),cursor:o,...l})},dY=Math.sqrt(Math.PI),hY=function({cx:t,cy:n,size:r,isHidden:s,"data-testid":o}){const i=is("mobile_rotate"),a=F(),l=K("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return d.jsxs("g",{children:[d.jsx("circle",{"data-testid":o,pointerEvents:"all",className:ce("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":s}),cx:t,cy:n,r:c,...i}),d.jsx("circle",{className:ce("tl-mobile-rotate__fg",{"tl-hidden":s}),cx:t,cy:n,r:r/dY})]})};function pY(){const e=F();return K("is in a valid select state",()=>e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle"),[e])?d.jsx(v2,{}):null}function Av(e,t,n){const{arrowheadStart:r,arrowheadEnd:s}=t.props,o=Ha(e,t,n),i=o.start.clone(),a=o.end.clone(),l=b.Med(i,a);if(b.Equals(i,a))return{bindings:n,isStraight:!0,start:{handle:i,point:i,arrowhead:t.props.arrowheadStart},end:{handle:a,point:a,arrowhead:t.props.arrowheadEnd},middle:l,isValid:!1,length:0};const c=b.Sub(a,i).uni(),u=yf(e,t,"start"),h=yf(e,t,"end"),p=e.getShapePageTransform(t);JC(a,o.start,p,h),JC(i,o.end,p,u);let f=0,S=0,y=0,x=0,m=Ka*t.props.scale;const v=u&&h&&u.shape===h.shape,w=u&&h?hw(e,u.shape.id,h.shape.id):"safe";w==="safe"&&u&&h&&!v&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(Ka*t.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(Ka*t.props.scale))));const C=b.Sub(a,i),E=b.Len(C)?C.uni():b.From(C),_=!b.Equals(E,c);v||(w!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(y=Do[t.props.size]/2+("size"in u.shape.props?Do[u.shape.props.size]/2:0),f=(Sf+y)*t.props.scale,m+=y*t.props.scale),w!=="end-contains-start"&&h&&s!=="none"&&!h.isExact&&(x=Do[t.props.size]/2+("size"in h.shape.props?Do[h.shape.props.size]/2:0),S=(Sf+x)*t.props.scale,m+=x*t.props.scale));const I=i.clone().add(E.clone().mul(f*(_?-1:1))),k=a.clone().sub(E.clone().mul(S*(_?-1:1)));b.DistMin(I,k,m)&&(f!==0&&S!==0?(f*=-1.5,S*=-1.5):f!==0?f*=-1:S!==0&&(S*=-1)),i.add(E.clone().mul(f*(_?-1:1))),a.sub(E.clone().mul(S*(_?-1:1))),_?(u&&h&&a.setTo(b.Add(i,E.clone().mul(-Ka*t.props.scale))),l.setTo(b.Med(o.start,o.end))):l.setTo(b.Med(i,a));const T=b.Dist(i,a);return{bindings:n,isStraight:!0,start:{handle:o.start,point:i,arrowhead:t.props.arrowheadStart},end:{handle:o.end,point:a,arrowhead:t.props.arrowheadEnd},middle:l,isValid:T>0,length:T}}function JC(e,t,n,r){if(r===void 0||r.isExact)return;const s=oe.applyToPoint(n,t),o=oe.applyToPoint(n,e),i=oe.applyToPoint(oe.Inverse(r.transform),s),a=oe.applyToPoint(oe.Inverse(r.transform),o),l=r.isClosed,u=(l?ew:qW)(i,a,r.outline);let h;if(u!==null&&(h=u.sort((S,y)=>b.Dist2(S,i)-b.Dist2(y,i))[0]??(l?void 0:a)),h===void 0)return;const p=oe.applyToPoint(r.transform,h),f=oe.applyToPoint(oe.Inverse(n),p);e.setTo(f),r.didIntersect=!0}function fY(e,t,n){const{arrowheadEnd:r,arrowheadStart:s}=t.props,o=t.props.bend;if(Math.abs(o)>Math.abs(t.props.bend*(vY*t.props.scale)))return Av(e,t,n);const i=Ha(e,t,n),a=b.Med(i.start,i.end),l=b.Sub(i.end,i.start),c=b.Len(l)?l.uni():b.From(l),u=b.Add(a,c.per().mul(-o)),h=yf(e,t,"start"),p=yf(e,t,"end"),f=i.start.clone(),S=i.end.clone(),y=u.clone();if(b.Equals(f,S))return{bindings:n,isStraight:!0,start:{handle:f,point:f,arrowhead:t.props.arrowheadStart},end:{handle:S,point:S,arrowhead:t.props.arrowheadEnd},middle:y,isValid:!1,length:0};const x=t.props.bend<0,m=x?Ku:Q_,v=eI(f,S,y),w=b.Angle(v.center,f),C=b.Angle(v.center,S),E=m(w,C);if(v.length===0||v.size===0||!cP(v.length)||!cP(v.size))return Av(e,t,n);const _=f.clone(),I=S.clone(),k=y.clone(),T=e.getShapePageTransform(t);let M=0,D=0,$=Ka*t.props.scale;if(h&&!h.isExact){const Y=oe.applyToPoint(T,_),q=oe.applyToPoint(T,v.center),le=oe.applyToPoint(T,I),ge=oe.Inverse(h.transform),be=oe.applyToPoint(ge,Y),J=oe.applyToPoint(ge,q),Ue=oe.applyToPoint(ge,le),{isClosed:Oe}=h,nt=Oe?Ev:LC;let je,it=nt(J,v.radius,h.outline);if(it){const Fe=J.angle(be),Xn=J.angle(Ue),Nt=m(Fe,Xn);it=it.filter(St=>m(Fe,J.angle(St))<=Nt);const _n=Nt*.25;it.sort(Oe?(St,Qt)=>Math.abs(m(Fe,J.angle(St))-_n)<Math.abs(m(Fe,J.angle(Qt))-_n)?-1:1:(St,Qt)=>m(Fe,J.angle(St))<m(Fe,J.angle(Qt))?-1:1),je=it[0]??(Oe?void 0:be)}else je=Oe?void 0:be;if(je&&(_.setTo(e.getPointInShapeSpace(t,oe.applyToPoint(h.transform,je))),h.didIntersect=!0,s!=="none")){const Fe=Do[t.props.size]/2+("size"in h.shape.props?Do[h.shape.props.size]/2:0);M=(Sf+Fe)*t.props.scale,$+=Fe*t.props.scale}}if(p&&!p.isExact){const Y=oe.applyToPoint(T,_),q=oe.applyToPoint(T,I),le=oe.applyToPoint(T,v.center),ge=oe.Inverse(p.transform),be=oe.applyToPoint(ge,Y),J=oe.applyToPoint(ge,le),Ue=oe.applyToPoint(ge,q),Oe=p.isClosed,nt=Oe?Ev:LC;let je,it=nt(J,v.radius,p.outline);if(it){const Fe=J.angle(be),Xn=J.angle(Ue),Nt=m(Fe,Xn),_n=Nt*.75;it=it.filter(St=>m(Fe,J.angle(St))<=Nt),it.sort(Oe?(St,Qt)=>Math.abs(m(Fe,J.angle(St))-_n)<Math.abs(m(Fe,J.angle(Qt))-_n)?-1:1:(St,Qt)=>m(Fe,J.angle(St))<m(Fe,J.angle(Qt))?-1:1),it[0]?je=it[0]:je=Oe?void 0:Ue}else je=Oe?void 0:Ue;if(je&&(I.setTo(e.getPointInShapeSpace(t,oe.applyToPoint(p.transform,je))),p.didIntersect=!0,r!=="none")){const Fe=Do[t.props.size]/2+("size"in p.shape.props?Do[p.shape.props.size]/2:0);D=(Sf+Fe)*t.props.scale,$+=Fe*t.props.scale}}let j=b.Angle(v.center,_),O=b.Angle(v.center,I),R=m(j,O),H=R*v.radius;const B=_.clone(),z=I.clone();if(M!==0&&B.setTo(v.center).add(b.FromAngle(j+R*(M/H*(x?1:-1))).mul(v.radius)),D!==0&&z.setTo(v.center).add(b.FromAngle(O+R*(D/H*(x?-1:1))).mul(v.radius)),b.DistMin(B,z,$)&&(M!==0&&D!==0?(M*=-1.5,D*=-1.5):M!==0?M*=-2:D!==0&&(D*=-2)),M!==0&&_.setTo(v.center).add(b.FromAngle(j+R*(M/H*(x?1:-1))).mul(v.radius)),D!==0&&I.setTo(v.center).add(b.FromAngle(O+R*(D/H*(x?-1:1))).mul(v.radius)),h&&p&&!h.isExact&&!p.isExact){j=b.Angle(v.center,_),O=b.Angle(v.center,I),R=m(j,O),H=R*v.radius;const Y=hw(e,h.shape.id,p.shape.id);Y==="double-bound"&&H<30?(_.setTo(f),I.setTo(S),k.setTo(y)):Y==="safe"&&(h&&!h.didIntersect&&_.setTo(f),(p&&!p.didIntersect||m(w,j)>m(w,O))&&I.setTo(v.center).add(b.FromAngle(j+R*(Math.min(.9,Ka*t.props.scale/H)*(x?1:-1))).mul(v.radius)))}gY(v.center,v.radius,_,I,k,E,x),_.equals(I)&&(_.setTo(k.clone().addXY(1,1)),I.setTo(k.clone().subXY(1,1))),f.setTo(_),S.setTo(I),y.setTo(k);const W=eI(f,S,y);return{bindings:n,isStraight:!1,start:{point:f,handle:i.start,arrowhead:t.props.arrowheadStart},end:{point:S,handle:i.end,arrowhead:t.props.arrowheadEnd},middle:y,handleArc:v,bodyArc:W,isValid:W.length!==0&&isFinite(W.center.x)&&isFinite(W.center.y)}}function eI(e,t,n){const r=n0(e,t,n),s=b.Dist(r,e),o=+b.Clockwise(e,n,t),i=((e.y-t.y)**2+(e.x-t.x)**2)**.5,a=((t.y-n.y)**2+(t.x-n.x)**2)**.5,l=((n.y-e.y)**2+(n.x-e.x)**2)**.5,c=Math.acos((a*a+l*l-i*i)/(2*a*l))*2,u=+(Me>c),h=(Le-c)*(o?1:-1),p=h*s;return{center:r,radius:s,size:h,length:p,largeArcFlag:u,sweepFlag:o}}function gY(e,t,n,r,s,o,i){const a=b.Angle(e,n),l=b.Angle(e,r);let c=Ku(a,l);if(i||(c=Le-c),s.setTo(e).add(b.FromAngle(a+c*(.5*(i?1:-1))).mul(t)),c>o){s.rotWith(e,Me);const u=r.clone();r.setTo(n),n.setTo(u)}}const mY=8;function yY(e){return Math.abs(e.props.bend)<mY*e.props.scale}function yf(e,t,n){const r=e.getBindingsFromShape(t,"arrow").find(l=>l.props.terminal===n);if(!r)return;const s=e.getShape(r.toId);if(!s)return;const o=e.getShapePageTransform(s),i=e.getShapeGeometry(s),a=i instanceof Gr?i.children[0].vertices:i.vertices;return{shape:s,transform:o,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function tI(e,t,n,r){const s=e.getShape(n.toId);if(s){const{point:o,size:i}=e.getShapeGeometry(s).bounds,a=b.Add(o,b.MulV(n.props.isPrecise||r?n.props.normalizedAnchor:{x:.5,y:.5},i)),l=oe.applyToPoint(e.getShapePageTransform(s),a);return oe.applyToPoint(oe.Inverse(t),l)}else return new b(0,0)}function Ln(e,t){const n=e.getBindingsFromShape(t,"arrow");return{start:n.find(r=>r.props.terminal==="start"),end:n.find(r=>r.props.terminal==="end")}}const SY=GB("arrow info",(e,t)=>{const n=Ln(e,t);return yY(t)?Av(e,t,n):fY(e,t,n)});function ps(e,t){const n=typeof t=="string"?t:t.id;return SY.get(e,n)}function Ha(e,t,n){var a,l;const r=e.getShapePageTransform(t),s=hw(e,(a=n.start)==null?void 0:a.toId,(l=n.end)==null?void 0:l.toId),o=n.start?tI(e,r,n.start,s==="double-bound"||s==="start-contains-end"):b.From(t.props.start),i=n.end?tI(e,r,n.end,s==="double-bound"||s==="end-contains-start"):b.From(t.props.end);return{start:o,end:i}}function lc(e,t,n,r){const s=typeof t=="string"?t:t.id,o=typeof n=="string"?n:n.id,i=e.getBindingsFromShape(s,"arrow").filter(l=>l.props.terminal===r.terminal);i.length>1&&e.deleteBindings(i.slice(1));const a=i[0];a?e.updateBinding({...a,toId:o,props:r}):e.createBinding({type:"arrow",fromId:s,toId:o,props:r})}function Xh(e,t,n){const r=e.getBindingsFromShape(t,"arrow").filter(s=>s.props.terminal===n);e.deleteBindings(r)}const Ka=10,Sf=10,vY=10,Do={s:2,m:3.5,l:5,xl:10};function hw(e,t,n){if(!t||!n)return"safe";if(t===n)return"double-bound";const r=e.getShapePageBounds(t),s=e.getShapePageBounds(n);if(r&&s){if(r.contains(s))return"start-contains-end";if(s.contains(r))return"end-contains-start"}return"safe"}class qh extends Vh{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:t}){dy(this.editor,this.editor.getShape(t.fromId))}onAfterChange({bindingAfter:t}){dy(this.editor,this.editor.getShape(t.fromId))}onAfterChangeFromShape({shapeAfter:t}){dy(this.editor,t)}onAfterChangeToShape({binding:t}){uA(this.editor,t.fromId)}onBeforeIsolateFromShape({binding:t}){const n=this.editor.getShape(t.fromId);n&&vf({editor:this.editor,arrow:n,terminal:t.props.terminal})}}g(qh,"type","arrow"),g(qh,"props",S_),g(qh,"migrations",v_);function uA(e,t){var x;const n=e.getShape(t);if(!n)return;const r=Ln(e,n),{start:s,end:o}=r,i=s?e.getShape(s.toId):void 0,a=o?e.getShape(o.toId):void 0,l=e.getAncestorPageId(n);if(!l)return;let c;if(i&&a)c=e.findCommonAncestor([i,a])??l;else if(i||a){const m=(x=i||a)==null?void 0:x.parentId;m&&m===n.parentId?c=n.parentId:c=l}else return;c&&c!==n.parentId&&e.reparentShapes([t],c);const u=e.getShape(t);if(!u)throw Error("no reparented arrow");const h=e.getShapeNearestSibling(u,i),p=e.getShapeNearestSibling(u,a);let f;if(h&&p)f=h.index>p.index?h:p;else if(h&&!p)f=h;else if(p&&!h)f=p;else return;let S;const y=e.getSortedChildIdsForParent(f.parentId).map(m=>e.getShape(m)).filter(m=>m.index>f.index);if(y.length){const m=y.find(v=>v.type!=="arrow");if(u.index>f.index&&(!m||u.index<m.index))return;S=ru(f.index,y[0].index)}else S=zr(f.index);S!==u.index&&e.updateShapes([{id:t,type:"arrow",index:S}])}function dy(e,t){const n=Ln(e,t);for(const r of["start","end"]){const s=n[r];if(!s)continue;const o=e.getShape(s.toId),i=e.getAncestorPageId(t)===e.getAncestorPageId(o);(!o||!i)&&vf({editor:e,arrow:t,terminal:r,unbind:!0})}uA(e,t.id)}function vf({editor:e,arrow:t,terminal:n,unbind:r=!1,useHandle:s=!1}){const o=ps(e,t);if(!o)throw new Error("expected arrow info");const i=s?o.start.handle:o.start.point,a=s?o.end.handle:o.end.point,l=n==="start"?i:a,c={id:t.id,type:"arrow",props:{[n]:{x:l.x,y:l.y},bend:t.props.bend}};if(!o.isStraight){const u=n==="start"?i:o.start.handle,h=n==="end"?a:o.end.handle,p=b.Med(u,h),f=b.Sub(u,h).per().uni().mul(o.handleArc.radius*2*Math.sign(t.props.bend)),S=Ju(o.handleArc.center,b.Add(p,f),o.handleArc.center,o.handleArc.radius);Xe((S==null?void 0:S.length)===1);const y=b.Dist(p,S[0])*Math.sign(t.props.bend);$o(y,c.props.bend)||(c.props.bend=y)}e.updateShape(c),r&&Xh(e,t,n)}const dA=[qh],Vt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},jt={s:2,m:3.5,l:5,xl:10},gl={s:18,m:24,l:36,xl:44},Xs={s:18,m:22,l:26,xl:32},xY={s:18,m:20,l:24,xl:28},xs={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},wY=20,bY=4.25,vr=16;/*!
|
|
172
|
-
* canvas-size
|
|
173
|
-
* v1.2.6
|
|
174
|
-
* https://github.com/jhildenbiddle/canvas-size
|
|
175
|
-
* (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
|
|
176
|
-
* MIT license
|
|
177
|
-
*/function PY(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,s,o,i,a=[],l=!0,c=!1;try{if(o=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=o.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(u){c=!0,s=u}finally{try{if(!l&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw s}}return a}}function nI(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function Qn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?nI(Object(n),!0).forEach(function(r){CY(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):nI(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function CY(e,t,n){return t=OY(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function IY(e,t){if(e==null)return{};var n={},r=Object.keys(e),s,o;for(o=0;o<r.length;o++)s=r[o],!(t.indexOf(s)>=0)&&(n[s]=e[s]);return n}function EY(e,t){if(e==null)return{};var n=IY(e,t),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(s=0;s<o.length;s++)r=o[s],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function rI(e,t){return _Y(e)||PY(e,t)||hA(e,t)||AY()}function rh(e){return kY(e)||TY(e)||hA(e)||MY()}function kY(e){if(Array.isArray(e))return jv(e)}function _Y(e){if(Array.isArray(e))return e}function TY(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function hA(e,t){if(e){if(typeof e=="string")return jv(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return jv(e,t)}}function jv(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function MY(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
178
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function AY(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
179
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function jY(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function OY(e){var t=jY(e,"string");return typeof t=="symbol"?t:String(t)}function qc(e){var t=e.sizes.shift(),n=Math.max(Math.ceil(t[0]),1),r=Math.max(Math.ceil(t[1]),1),s=[n-1,r-1,1,1],o=Date.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,l;i?(a=new OffscreenCanvas(1,1),l=new OffscreenCanvas(n,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,l=document.createElement("canvas"),l.width=n,l.height=r);var c=a.getContext("2d"),u=l.getContext("2d");u&&(u.fillRect.apply(u,s),c.drawImage(l,n-1,r-1,1,1,0,0,1,1));var h=c&&c.getImageData(0,0,1,1).data[3]!==0,p=Date.now()-o;return[a,l].forEach(function(f){f.height=0,f.width=0}),i?(postMessage({width:n,height:r,benchmark:p,isTestPass:h}),!h&&e.sizes.length&&qc(e)):h?e.onSuccess(n,r,p):(e.onError(n,r,p),e.sizes.length&&qc(e)),h}var hy={area:[16384,14188,11402,11180,10836,8192,4096,1],height:[8388607,65535,32767,16384,8192,4096,1],width:[4194303,65535,32767,16384,8192,4096,1]},DY=["onError","onSuccess"],Wa={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},cc={};function py(e){var t=e.width===e.height,n=e.height===1,r=e.width===1,s=[];if(!e.width||!e.height)e.sizes.forEach(function(u){var h=t||n?u:1,p=t||r?u:1;s.push([h,p])});else for(var o=e.min||Wa.min,i=e.step||Wa.step,a=Math.max(e.width,e.height);a>=o;){var l=t||n?a:1,c=t||r?a:1;s.push([l,c]),a-=i}return s}function sh(e){var t=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),s=e.onError,o=e.onSuccess,i=EY(e,DY),a=null;if(!t)return!1;if(e.useWorker&&n){var l=`
|
|
180
|
-
var canvasTest = `.concat(qc.toString(),`;
|
|
181
|
-
onmessage = function(e) {
|
|
182
|
-
canvasTest(e.data);
|
|
183
|
-
};
|
|
184
|
-
`),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(h){var p=h.data,f=p.width,S=p.height,y=p.benchmark,x=p.isTestPass;x?(cc[r].onSuccess(f,S,y),delete cc[r]):cc[r].onError(f,S,y)}}if(e.usePromise)return new Promise(function(h,p){var f=Qn(Qn({},e),{},{onError:function(m,v,w){var C;if(e.sizes.length===0)C=!0;else{var E=e.sizes.slice(-1),_=rI(E,1),I=rI(_[0],2),k=I[0],T=I[1];C=m===k&&v===T}s(m,v,w),C&&p({width:m,height:v,benchmark:w})},onSuccess:function(m,v,w){o(m,v,w),h({width:m,height:v,benchmark:w})}});if(a){var S=f.onError,y=f.onSuccess;cc[r]={onError:S,onSuccess:y},a.postMessage(i)}else qc(f)});if(a)cc[r]={onError:s,onSuccess:o},a.postMessage(i);else return qc(e)}var fy={maxArea:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=py({width:t.max,height:t.max,min:t.min,step:t.step,sizes:rh(hy.area)}),r=Qn(Qn(Qn({},Wa),t),{},{sizes:n});return sh(r)},maxHeight:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=py({width:1,height:t.max,min:t.min,step:t.step,sizes:rh(hy.height)}),r=Qn(Qn(Qn({},Wa),t),{},{sizes:n});return sh(r)},maxWidth:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=py({width:t.max,height:1,min:t.min,step:t.step,sizes:rh(hy.width)}),r=Qn(Qn(Qn({},Wa),t),{},{sizes:n});return sh(r)},test:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=Qn(Qn({},Wa),t);return n.sizes=rh(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),sh(n)}};let gy=null;function RY(){return gy||(gy=LY()),gy}async function LY(){const e=await fy.maxWidth({usePromise:!0}),t=await fy.maxHeight({usePromise:!0}),n=await fy.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:t.height,maxArea:n.width*n.height}}const sI=8192,$Y=4096*4096;async function NY(e,t){if(e<=sI&&t<=sI&&e*t<=$Y)return[e,t];const{maxWidth:n,maxHeight:r,maxArea:s}=await RY(),o=e/t;if(e>n&&(e=n,t=e/o),t>r&&(t=r,e=t*o),e*t>s){const i=Math.sqrt(s/(e*t));e*=i,t*=i}return[e,t]}function FY(e,t){const n=e.w/t.w,r=e.h/t.h;return n<=1&&r<=1?e:n>r?{w:e.w/n,h:e.h/n}:{w:e.w/r,h:e.h/r}}function zY(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function BY(e){const t=new URL(e).host.replace("www.","");for(const n of Hu)if(pA(n.hostnames,t)){const r=n.fromEmbedUrl(e);if(r)return{definition:n,url:r,embedUrl:e}}}const UY=e=>e.split("*").map(t=>zY(t)).join(".+"),pA=(e,t)=>!!e.find(n=>{const r=new RegExp(UY(n));return t.match(r)});function HY(e){const t=new URL(e).host.replace("www.","");for(const n of Hu)if(pA(n.hostnames,t)){const r=n.toEmbedUrl(e);if(r)return{definition:n,embedUrl:r,url:e}}}function fA(e){return HY(e)??BY(e)}function Ro(e){try{return fA(e)}catch(t){console.error(t)}}/*!
|
|
185
|
-
* MIT License
|
|
186
|
-
* Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
|
|
187
|
-
* Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
|
|
188
|
-
*/const Ga=" ",gn=class gn{static insertTextFirefox(t,n){t.setRangeText(n,t.selectionStart||0,t.selectionEnd||0,"end"),t.dispatchEvent(new InputEvent("input",{data:n,inputType:"insertText",isComposing:!1}))}static insert(t,n){const r=t.ownerDocument,s=r.activeElement;s!==t&&t.focus(),r.execCommand("insertText",!1,n)||gn.insertTextFirefox(t,n),s===r.body?t.blur():s instanceof HTMLElement&&s!==t&&s.focus()}static set(t,n){t.select(),gn.insert(t,n)}static getSelection(t){const{selectionStart:n,selectionEnd:r}=t;return t.value.slice(n||void 0,r||void 0)}static wrapSelection(t,n,r){const{selectionStart:s,selectionEnd:o}=t,i=gn.getSelection(t);gn.insert(t,n+i+(r??n)),t.selectionStart=(s||0)+n.length,t.selectionEnd=(o||0)+n.length}static replace(t,n,r){let s=0;t.value.replace(n,(...o)=>{const i=s+o[o.length-2],a=o[0].length;t.selectionStart=i,t.selectionEnd=i+a;const l=typeof r=="string"?r:r(...o);return gn.insert(t,l),t.selectionStart=i,s+=l.length-a,l})}static findLineEnd(t,n){const r=t.lastIndexOf(`
|
|
189
|
-
`,n-1)+1;return t.charAt(r)!==" "?n:r+1}static indent(t){var a;const{selectionStart:n,selectionEnd:r,value:s}=t,o=s.slice(n,r),i=(a=/\n/g.exec(o))==null?void 0:a.length;if(i&&i>0){const l=s.lastIndexOf(`
|
|
190
|
-
`,n-1)+1,c=t.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${Ga}`),h=u.length-c.length;t.setSelectionRange(l,r-1),gn.insert(t,u),t.setSelectionRange(n+1,r+h)}else gn.insert(t,Ga)}static unindent(t){const{selectionStart:n,selectionEnd:r,value:s}=t,o=s.lastIndexOf(`
|
|
191
|
-
`,n-1)+1,i=gn.findLineEnd(s,r),a=t.value.slice(o,i),l=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),c=a.length-l.length;t.setSelectionRange(o,i),gn.insert(t,l);const u=/\t| {1,2}/.exec(s.slice(o,n)),h=u?u[0].length:0,p=n-h;t.setSelectionRange(n-h,Math.max(p,r-c))}static indentCE(t){var l;const n=window.getSelection(),r=t.innerText,s=oh(t)??0,o=oh(t)??0,i=r.slice(s,o),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
|
|
192
|
-
`,s-1)+1,u=r.slice(c,o-1),p=u.replace(/^|\n/g,`$&${Ga}`).length-u.length;n&&n.setBaseAndExtent(t,s+1,t,o+p)}else{const c=window.getSelection();t.innerText=r.slice(0,s)+Ga+r.slice(s),c==null||c.setBaseAndExtent(t,s+1,t,s+2)}}static unindentCE(t){const n=window.getSelection(),r=t.innerText,s=oh(t)??0,o=oh(t)??0,i=r.lastIndexOf(`
|
|
193
|
-
`,s-1)+1,a=gn.findLineEnd(r,o),l=r.slice(i,a),c=l.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=l.length-c.length;if(n){n.setBaseAndExtent(t,i,t,a);const h=/\t| {1,2}/.exec(r.slice(i,s)),p=h?h[0].length:0,f=s-p;n.setBaseAndExtent(t,s-p,t,Math.max(f,o-u))}}static normalizeText(t){return t.replace(gn.fixNewLines,`
|
|
194
|
-
`)}static normalizeTextForDom(t){return t.replace(gn.fixNewLines,`
|
|
195
|
-
`).split(`
|
|
196
|
-
`).map(n=>n||" ").join(`
|
|
197
|
-
`)}};g(gn,"fixNewLines",/\r?\n|\r/g);let ml=gn;function oh(e){if(typeof window.getSelection>"u")return;const t=window.getSelection();if(!t)return;let n=0;if(t.rangeCount!==0){const r=t.getRangeAt(0),s=r.cloneRange();s.selectNodeContents(e),s.setEnd(r.endContainer,r.endOffset),n=s.toString().length}return n}const KY=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function gA(e){return KY.test(e)}function WY(e){return e.replace(/\t/g,Ga)}function GY(e){const t=e.split(`
|
|
198
|
-
`);for(;t[0]&&t[0].trim().length===0;)t.shift();let n=1/0;for(const r of t)if(r.trim().length>0){const s=r.length-r.trimStart().length;n=Math.min(n,s)}return t.map(r=>r.slice(n)).join(`
|
|
199
|
-
`)}function VY(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function YY(e){return VY(GY(WY(e)))}function XY(e,{maxImageDimension:t,maxAssetSize:n,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:s},{toasts:o,msg:i}){e.registerExternalAssetHandler("file",async({file:a})=>{const l=a.name;let c=a;const u=r.includes(c.type),h=s.includes(c.type);!u&&!h&&o.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),Xe(u||h,`File type not allowed: ${c.type}`),c.size>n&&o.addToast({title:i("assets.files.size-too-big"),severity:"error"}),Xe(c.size<=n,`File size too big: ${(c.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`),c.type==="video/quicktime"&&(c=new File([c],c.name,{type:"video/mp4"}));let p=u?await ds.getImageSize(c):await ds.getVideoSize(c);const f=await ds.isAnimated(c)||h,S=pB(await c.arrayBuffer());if(isFinite(t)){const m=FY(p,{w:t,h:t});p!==m&&ds.isStaticImageType(c.type)&&(p=m)}const x={id:Ii.createId(S),type:u?"image":"video",typeName:"asset",props:{name:l,src:"",w:p.w,h:p.h,fileSize:c.size,mimeType:c.type,isAnimated:f}};return x.props.src=await e.uploadAsset(x,c),Ii.create(x)}),e.registerExternalAssetHandler("url",async({url:a})=>{var c,u,h,p,f;let l;try{const y=await(await ws(a,{method:"GET",mode:"no-cors"})).text(),x=new DOMParser().parseFromString(y,"text/html");l={image:((c=x.head.querySelector('meta[property="og:image"]'))==null?void 0:c.getAttribute("content"))??"",favicon:((u=x.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:u.getAttribute("href"))??((h=x.head.querySelector('link[rel="icon"]'))==null?void 0:h.getAttribute("href"))??"",title:((p=x.head.querySelector('meta[property="og:title"]'))==null?void 0:p.getAttribute("content"))??a,description:((f=x.head.querySelector('meta[property="og:description"]'))==null?void 0:f.getAttribute("content"))??""},l.image.startsWith("http")||(l.image=new URL(l.image,a).href),l.favicon.startsWith("http")||(l.favicon=new URL(l.favicon,a).href)}catch(S){console.error(S),o.addToast({title:i("assets.url.failed"),severity:"error"}),l={image:"",favicon:"",title:"",description:""}}return{id:Ii.createId(vS(a)),typeName:"asset",type:"bookmark",props:{src:a,description:l.description,image:l.image,favicon:l.favicon,title:l.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:a,text:l})=>{const c=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=new DOMParser().parseFromString(l,"image/svg+xml").querySelector("svg");if(!u)throw new Error("No <svg/> element present");let h=parseFloat(u.getAttribute("width")||"0"),p=parseFloat(u.getAttribute("height")||"0");if(!(h&&p)){document.body.appendChild(u);const S=u.getBoundingClientRect();document.body.removeChild(u),h=S.width,p=S.height}const f=await e.getAssetForExternalContent({type:"file",file:new File([l],"asset.svg",{type:"image/svg+xml"})});if(!f)throw Error("Could not create an asset");oI(e,[f],c)}),e.registerExternalContentHandler("embed",({point:a,url:l,embed:c})=>{const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),{width:h,height:p}=c,f=$e(),S={id:f,type:"embed",x:u.x-(h||450)/2,y:u.y-(p||450)/2,props:{w:h,h:p,url:l}};e.createShapes([S]).select(f)}),e.registerExternalContentHandler("files",async({point:a,files:l})=>{const c=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=new b(c.x,c.y),h=[];await Promise.all(l.map(async(p,f)=>{if(p.size>n)return o.addToast({title:i("assets.files.size-too-big"),severity:"error"}),console.warn(`File size too big: ${(p.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`),null;if(!p.type)throw new Error("No mime type");if(!r.concat(s).includes(p.type))return o.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),console.warn(`${p.name} not loaded - Extension not allowed.`),null;try{const S=await e.getAssetForExternalContent({type:"file",file:p});if(!S)throw Error("Could not create an asset");h[f]=S}catch(S){return o.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(S),null}})),oI(e,ye(h),u)}),e.registerExternalContentHandler("text",async({point:a,text:l})=>{const c=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=e.getShapeUtil("text").getDefaultProps(),h=YY(l),p=e.getOnlySelectedShape();if(p&&"text"in p.props){e.updateShapes([{id:p.id,type:p.type,props:{text:h}}]);return}let f,S,y,x="middle";const m=h.split(`
|
|
200
|
-
`).length>1,v=gA(h);m&&(x=m?v?"end":"start":"middle");const w=e.textMeasure.measureText(h,{...Vt,fontFamily:xs[u.font],fontSize:gl[u.size],maxWidth:null}),C=Math.min(m?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(w.w>C){const E=e.textMeasure.measureText(h,{...Vt,fontFamily:xs[u.font],fontSize:gl[u.size],maxWidth:C});f=E.w,S=E.h,y=!1,x=v?"end":"start"}else f=w.w,S=w.h,y=!0;c.y-S/2<e.getViewportPageBounds().minY+40&&(c.y=e.getViewportPageBounds().minY+40+S/2),e.createShapes([{id:$e(),type:"text",x:c.x-f/2,y:c.y-S/2,props:{text:h,textAlign:x,autoSize:y,w:f}}])}),e.registerExternalContentHandler("url",async({point:a,url:l})=>{const c=Ro(l);if(c)return e.putExternalContent({type:"embed",url:c.url,point:a,embed:c.definition});const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=Ii.createId(vS(l)),p=qY(e,l,u);let f=e.getAsset(h),S=!1;if(!f){S=!0;try{const y=await e.getAssetForExternalContent({type:"url",url:l});if(!y)throw Error("Could not create an asset");f=y}catch{o.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.run(()=>{S&&e.createAssets([f]),e.updateShapes([{id:p.id,type:p.type,props:{assetId:f.id}}])})})}async function oI(e,t,n){if(!t.length)return[];const r=b.From(n),s=[];for(let o=0;o<t.length;o++){const i=t[o];switch(i.type){case"bookmark":{s.push({id:$e(),type:"bookmark",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,url:i.props.src}}),r.x+=300;break}case"image":{s.push({id:$e(),type:"image",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w;break}case"video":s.push({id:$e(),type:"video",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w}}return e.run(()=>{const o=t.filter(i=>!e.getAsset(i.id));o.length&&e.createAssets(o),e.createShapes(s).select(...s.map(i=>i.id)),mA(e,n)}),s.map(o=>o.id)}function mA(e,t){const n=e.getViewportPageBounds();let r=e.getSelectionPageBounds();if(r){const s=r.center.sub(t);e.updateShapes(e.getSelectedShapes().map(o=>{const i=e.getShapeParentTransform(o).decompose().rotation,a=b.Rot(s,-i);return{id:o.id,type:o.type,x:o.x-a.x,y:o.y-a.y}}))}r=e.getSelectionPageBounds(),r&&!n.contains(r)&&e.zoomToSelection()}function qY(e,t,n){const r={id:$e(),type:"bookmark",x:n.x-150,y:n.y-160,opacity:1,props:{assetId:null,url:t}};return e.run(()=>{e.createShapes([r]).select(r.id),mA(e,n)}),e.getShape(r.id)}var zy;let ZY=(zy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")});g(this,"onKeyUp",n=>{var r;if(n.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const s=this.editor.getOnlySelectedShape();s&&this.editor.getShapeUtil(s).canEdit(s)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(s.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...n,target:"shape",shape:s}))}})}},g(zy,"id","idle"),zy);var By;let QY=(By=class extends se{constructor(){super(...arguments);g(this,"shape");g(this,"markId","");g(this,"onEnter",()=>{this.didTimeout=!1;const n=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.canBindShapes({fromShape:"arrow",toShape:r,binding:"arrow"}),margin:0,hitInside:!0,renderingOnly:!0});n?this.editor.setHintingShapes([n.id]):this.createArrowShape(),this.startPreciseTimeout()});g(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});g(this,"onPointerMove",()=>{if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:{id:"end",type:"vertex",index:"a3",x:0,y:0},isCreating:!0,onInteractionEnd:"arrow"})}});g(this,"onPointerUp",()=>{this.cancel()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()});g(this,"preciseTimeout",-1);g(this,"didTimeout",!1)}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u;const{originPagePoint:n}=this.editor.inputs,r=$e();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShape({id:r,type:"arrow",x:n.x,y:n.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const s=this.editor.getShape(r);if(!s)throw Error("expected shape");const o=this.editor.getShapeHandles(s);if(!o)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=o.find(h=>h.id==="start"),c=(u=i.onHandleDrag)==null?void 0:u.call(i,s,{handle:{...l,x:0,y:0},isPrecise:!0,initial:a});c&&this.editor.updateShapes([c]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,o;const n=this.shape;if(!n)throw Error("expected shape");const r=this.editor.getShapeHandles(n);if(!r)throw Error("expected handles for arrow");{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=r.find(u=>u.id==="start"),c=(s=i.onHandleDrag)==null?void 0:s.call(i,n,{handle:{...l,x:0,y:0},isPrecise:this.didTimeout,initial:a});c&&this.editor.updateShapes([c])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint),c=r.find(h=>h.id==="end"),u=(o=i.onHandleDrag)==null?void 0:o.call(i,this.editor.getShape(n),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(n.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},g(By,"id","pointing"),By);class Zh extends se{constructor(){super(...arguments);g(this,"shapeType","arrow")}}g(Zh,"id","arrow"),g(Zh,"initial","idle"),g(Zh,"children",()=>[ZY,QY]);class pw extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"initialShape");g(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");g(this,"util",this.editor.getShapeUtil(this.shapeType));g(this,"isPen",!1);g(this,"isPenOrStylus",!1);g(this,"segmentMode","free");g(this,"didJustShiftClickToExtendPreviousShapeLine",!1);g(this,"pagePointWhereCurrentSegmentChanged",{});g(this,"pagePointWhereNextSegmentChanged",null);g(this,"lastRecordedPoint",{});g(this,"mergeNextPoint",!1);g(this,"currentLineLength",0);g(this,"canDraw",!1);g(this,"markId",null);g(this,"onEnter",n=>{this.markId=null,this.info=n,this.canDraw=!this.editor.getIsMenuOpen(),this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.canDraw&&this.startShape()});g(this,"onPointerMove",()=>{const{inputs:n}=this.editor;if(this.isPen&&!n.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&n.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(this.isPenOrStylus?b.Dist(n.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=n.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape())});g(this,"onKeyDown",n=>{if(n.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()});g(this,"onKeyUp",n=>{if(n.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()});g(this,"onExit",()=>{this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())})}canClose(){return this.shapeType!=="highlight"}getIsClosed(n,r,s){if(!this.canClose())return!1;const o=jt[r],i=n[0].points[0],a=n[n.length-1],l=a.points[a.points.length-1];return i!==l&&this.currentLineLength>o*4*s&&b.DistMin(i,l,o*2*s)}startShape(){const{inputs:{originPagePoint:n,isPen:r}}=this.editor;this.markId="draw start "+ct(),this.editor.mark(this.markId);const{z:s=.5}=this.info.point;this.isPen=r,this.isPenOrStylus=r||s>0&&s<.5||s>.5&&s<1;const o=this.isPenOrStylus?s*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=n.clone(),this.initialShape){const a=this.editor.getShape(this.initialShape.id);if(a&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const l=Ut(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=Ut(l.points);if(!c)throw Error("Expected a previous point!");const{x:u,y:h}=this.editor.getPointInShapeSpace(a,n).toFixed(),p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+o.toFixed(2)},{x:u,y:h,z:+o.toFixed(2)}]},f=oe.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=f,this.pagePointWhereNextSegmentChanged=null;const S=[...a.props.segments,p];this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const y={id:a.id,type:this.shapeType,props:{segments:S}};this.canClose()&&(y.props.isClosed=this.getIsClosed(S,a.props.size,a.props.scale)),this.editor.updateShapes([y]);return}}this.pagePointWhereCurrentSegmentChanged=n.clone();const i=$e();this.editor.createShapes([{id:i,type:this.shapeType,x:n.x,y:n.y,props:{isPen:this.isPenOrStylus,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+o.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(i)}updateDrawingShape(){const{initialShape:n}=this,{inputs:r}=this.editor;if(!n)return;const{id:s,props:{size:o,scale:i}}=n,a=this.editor.getShape(s);if(!a)return;const{segments:l}=a.props,{x:c,y:u,z:h}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),p=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,f={x:c,y:u,z:p};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:S}=this;if(S===null)throw Error("We should have a point where the segment changed");if(b.Dist2(S,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const x=Ut(l);if(!x)throw Error("Expected a previous segment!");const m=Ut(x.points);if(!m)throw Error("Expected a previous last point!");let v;const w=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(x.type==="straight"){this.currentLineLength+=b.Dist(m,w),v={type:"straight",points:[{...m},w]};const E=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=oe.applyToPoint(E,m)}else v={type:"straight",points:[w,f]};const C={id:s,type:this.shapeType,props:{segments:[...l,v]}};this.canClose()&&(C.props.isClosed=this.getIsClosed(l,o,i)),this.editor.updateShapes([C])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:S}=this;if(S===null)throw Error("We should have a point where the segment changed");if(b.Dist2(S,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const x=l.slice(),m=x[x.length-1],v=Ut(m.points);if(!v)throw Error("No previous point!");const w={type:"free",points:[...b.PointsBetween(v,f,6).map(_=>({x:Bs(_.x),y:Bs(_.y),z:Bs(_.z)}))]},C=[...x,w];this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(C));const E={id:s,type:this.shapeType,props:{segments:C}};this.canClose()&&(E.props.isClosed=this.getIsClosed(C,o,i)),this.editor.updateShapes([E])}break}case"straight":{const S=l.slice(),y=S[S.length-1],{pagePointWhereCurrentSegmentChanged:x}=this,{ctrlKey:m,currentPagePoint:v}=this.editor.inputs;if(!x)throw Error("We should have a point where the segment changed");let w,C=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(C=!m,this.didJustShiftClickToExtendPreviousShapeLine=!1):C=!m;let E=this.editor.getPointInShapeSpace(a,v).toFixed().toJson(),_=!1,I;if((this.editor.user.getIsSnapMode()?!m:m)&&S.length>2){let M,D=8/this.editor.getZoomLevel();for(let $=0,j=l.length-2;$<j;$++){const O=l[$];if(!O)break;if(O.type==="free")continue;const R=O.points[0],H=Ut(O.points);if(!(R&&H))continue;const B=b.NearestPointOnLineSegment(R,H,E);if(b.DistMin(B,E,D)){M=B.toFixed().toJson(),D=b.Dist(B,E),I=O;break}}M&&(_=!0,E=M)}if(_&&I){const M=this.editor.getShapePageTransform(a),D=I.points[0],$=Ut(I.points);if(!$)throw Error("Expected a last point!");const j=oe.applyToPoint(M,D),O=oe.applyToPoint(M,$),R=oe.applyToPoint(M,E);this.editor.snaps.setIndicators([{id:ct(),type:"points",points:[j,R,O]}])}else{if(this.editor.snaps.clearIndicators(),C){const M=b.Angle(x,v),$=Bp(M,24)-M;w=b.RotWith(v,x,$)}else w=v;E=this.editor.getPointInShapeSpace(a,w).toFixed().toJson()}this.currentLineLength+=b.Dist(y.points[0],E),S[S.length-1]={...y,type:"straight",points:[y.points[0],E]};const T={id:s,type:this.shapeType,props:{segments:S}};this.canClose()&&(T.props.isClosed=this.getIsClosed(l,o,i)),this.editor.updateShapes([T]);break}case"free":{const S=l.slice(),y=S[S.length-1],x=[...y.points];if(x.length&&this.mergeNextPoint){const{z:v}=x[x.length-1];x[x.length-1]={x:f.x,y:f.y,z:v?Math.max(v,f.z):f.z}}else this.currentLineLength+=b.Dist(x[x.length-1],f),x.push(f);S[S.length-1]={...y,points:x},this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const m={id:s,type:this.shapeType,props:{segments:S}};if(this.canClose()&&(m.props.isClosed=this.getIsClosed(S,o,i)),this.editor.updateShapes([m]),x.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:s,type:this.shapeType,props:{isComplete:!0}}]);const v=$e(),w=this.editor.getShape(s).props;this.editor.createShapes([{id:v,type:this.shapeType,x:Bs(r.currentPagePoint.x),y:Bs(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:w.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(h*1.25).toFixed():.5}]}]}}]),this.initialShape=Ge(this.editor.getShape(v)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(n){let r=0;for(const s of n)for(let o=0;o<s.points.length-1;o++){const i=s.points[o],a=s.points[o+1];r+=b.Dist2(a,i)}return Math.sqrt(r)}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:n}=this;n&&(this.editor.updateShapes([{id:n.id,type:n.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}g(pw,"id","drawing");var Uy;let yA=(Uy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",n=>{this.parent.transition("drawing",n)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Uy,"id","idle"),Uy);class Cc extends se{constructor(){super(...arguments);g(this,"shapeType","draw");g(this,"onExit",()=>{const n=this.children.drawing;n.initialShape=void 0})}}g(Cc,"id","draw"),g(Cc,"initial","idle"),g(Cc,"isLockable",!1),g(Cc,"children",()=>[yA,pw]);class Ov extends Yh{constructor(){super(...arguments);g(this,"shapeType","frame");g(this,"onCreate",n=>{if(!n)return;const r=this.editor.getShapePageBounds(n),s=[],o=this.editor.getShapeAncestors(n).map(i=>i.id);this.editor.getSortedChildIdsForParent(n.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===n.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&JY(a,o,n)&&s.push(a.id)}),this.editor.reparentShapes(s,n.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")})}}g(Ov,"id","frame"),g(Ov,"initial","idle");function JY(e,t,n){return t.includes(e.id)?!1:e.parentId===n.parentId}var Hy;let eX=(Hy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onKeyUp",n=>{var r;if(n.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const s=this.editor.getOnlySelectedShape();s&&this.editor.getShapeUtil(s).canEdit(s)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(s.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...n,target:"shape",shape:s}))}});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Hy,"id","idle"),Hy);var Ky;let tX=(Ky=class extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"onPointerUp",()=>{this.complete()});g(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,s=$e();this.markId=`creating:${s}`,this.editor.mark(this.markId),this.editor.createShapes([{id:s,type:"geo",x:r.x,y:r.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(Ur),scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]).select(s).setCurrentTool("select.resizing",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:n}=this.editor.inputs,r=$e();this.markId=`creating:${r}`,this.editor.mark(this.markId);const s=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,o=this.editor.getStyleForNextShape(Ur),i=o==="star"?{w:200,h:190}:o==="cloud"?{w:300,h:180}:{w:200,h:200};this.editor.createShapes([{id:r,type:"geo",x:n.x,y:n.y,props:{geo:this.editor.getStyleForNextShape(Ur),scale:s,...i}}]);const a=this.editor.getShape(r);if(!a)return;const{w:l,h:c}=a.props,u=new b(l/2,c/2).mul(s),h=this.editor.getShapeParentTransform(a);h&&u.rot(-h.rotation()),this.editor.select(r),this.editor.updateShape({id:a.id,type:"geo",x:a.x-u.x,y:a.y-u.y,props:{geo:this.editor.getStyleForNextShape(Ur),w:l*s,h:c*s}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},g(Ky,"id","pointing"),Ky);class Qh extends se{constructor(){super(...arguments);g(this,"shapeType","geo")}}g(Qh,"id","geo"),g(Qh,"initial","idle"),g(Qh,"children",()=>[eX,tX]);class Ic extends se{constructor(){super(...arguments);g(this,"shapeType","highlight");g(this,"onExit",()=>{const n=this.children.drawing;n.initialShape=void 0})}}g(Ic,"id","highlight"),g(Ic,"initial","idle"),g(Ic,"children",()=>[yA,pw]),g(Ic,"isLockable",!1);var Wy;let nX=(Wy=class extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"onEnter",n=>{this.shapeId=n.shapeId,this.editor.setCursor({type:"cross",rotation:0})});g(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Wy,"id","idle"),Wy);const iI=2;var Gy;let rX=(Gy=class extends se{constructor(){super(...arguments);g(this,"shape",{});g(this,"markId");g(this,"onEnter",n=>{const{inputs:r}=this.editor,{currentPagePoint:s}=r;this.markId=void 0;const o=n.shapeId&&this.editor.getShape(n.shapeId);if(o&&r.shiftKey){this.markId=`creating:${o.id}`,this.editor.mark(this.markId),this.shape=o;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(f=>f.type==="vertex").sort(ln),l=a[a.length-1],c=a[a.length-2],u=oe.applyToPoint(this.editor.getShapeParentTransform(this.shape),new b(this.shape.x,this.shape.y)),h=b.Sub(s,u).addXY(.1,.1),p=Ge(this.shape.props.points);if(b.DistMin(l,c,iI)||b.DistMin(h,l,iI))p[l.id]={id:l.id,index:l.index,x:h.x,y:h.y};else{const f=zr(l.index);p[f]={id:f,index:f,x:h.x,y:h.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:p}}])}else{const i=$e();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:"line",x:s.x,y:s.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(i),this.shape=this.editor.getShape(i)}});g(this,"onPointerMove",()=>{if(this.shape&&this.editor.inputs.isDragging){const n=this.editor.getShapeHandles(this.shape);if(!n)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Ut(n);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators()})}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}},g(Gy,"id","pointing"),Gy);class Jh extends se{constructor(){super(...arguments);g(this,"shapeType","line")}}g(Jh,"id","line"),g(Jh,"initial","idle"),g(Jh,"children",()=>[nX,rX]);var Vy;let sX=(Vy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Vy,"id","idle"),Vy);function Ke(e,t){var s;const n=new Set;for(const o of t){const i=e.getShape(o);if(!i)continue;e.getShapeUtil(i).onDragShapesOut&&n.add(i);const a=e.getShape(i.parentId);a&&e.getShapeUtil(a).onDragShapesOut&&n.add(a)}const r=new Map;for(const o of n){const i=SA(e,o);i.length&&r.set(o,i)}for(const[o,i]of r){const a=e.getShapeUtil(o),l=ye(i.map(c=>e.getShape(c)));(s=a.onDragShapesOut)==null||s.call(a,o,l)}}function SA(e,t){const n=e.getSortedChildIdsForParent(t.id);if(n.length===0)return[];const r=e.getShapePageBounds(t);if(!r)return[];let s,o,i;const a=[];for(const l of n){const c=e.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}s??(s=e.getShapeGeometry(t)),o??(o=e.getShapePageTransform(t)),i??(i=o.applyToPoints(s.vertices));const u=e.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:h,isClosed:p}=e.getShapeGeometry(l);if(!h.some(f=>or(f,u))){if(p){if(UM(u,h))continue}else if(JW(u,h))continue;a.push(l)}}return a}function xf(e,t,n=!1){e.select(t),e.setEditingShape(t),e.setCurrentTool("select.editing_shape",{target:"shape",shape:t}),n&&e.emit("select-all-text",{shapeId:t.id}),vA(e)}const oX=16;function vA(e){const t=e.getSelectionPageBounds(),n=e.getViewportPageBounds();if(t&&!n.contains(t)){const r=t.clone().expandBy(oX/e.getZoomLevel()).expand(n),s=n.clone().translate({x:(r.center.x-n.center.x)*2,y:(r.center.y-n.center.y)*2});e.zoomToBounds(s,{animation:{duration:e.options.animationMediumMs},inset:0})}}const iX=0,Be=200,yg=new b(Be/2,Be/2),xA=10,aX=e=>[[["a1"],new b(Be*.5,Be*-.5-e.options.adjacentShapeMargin)],[["a2"],new b(Be*1.5+e.options.adjacentShapeMargin,Be*.5)],[["a3"],new b(Be*.5,Be*1.5+e.options.adjacentShapeMargin)],[["a4"],new b(Be*-.5-e.options.adjacentShapeMargin,Be*.5)]];function lX(e,t){if(t===1)return aX(e);const n=Be*t,r=e.options.adjacentShapeMargin*t;return[[["a1"],new b(n*.5,n*-.5-r)],[["a2"],new b(n*1.5+r,n*.5)],[["a3"],new b(n*.5,n*1.5+r)],[["a4"],new b(n*-.5-r,n*.5)]]}function wA(e,t,n,r,s,o){return Object.fromEntries(lX(e,o).map(([i,a],l)=>{const c=a.clone();return l===0&&s?c.y-=s:l===2&&r&&(c.y+=r),[i,c.rot(n).add(t)]}))}function bA(e,t,n,r){const s=new Set(e.getSelectedShapeIds()),o=(Be+e.options.adjacentShapeMargin+r)**2,i=new Map,a=[];for(const u of e.getCurrentPageShapes()){if(!e.isShapeOfType(u,"note")||n!==u.props.scale||s.has(u.id))continue;const h=e.getShapePageTransform(u.id);t===h.rotation()&&(i.set(u,e.getShapePageBounds(u).center),a.push(...Object.values(wA(e,h.point(),t,u.props.growY,r,n))))}const l=a.length;let c;for(const[u,h]of i)for(let p=0;p<l;p++)c=a[p],c&&(b.Dist2(h,c)>o||e.isPointInShape(u,c)&&(a[p]=void 0));return ye(a)}function PA(e,t,n,r,s=!1){let o;const i=e.getCurrentPageShapesSorted(),a=(Be+e.options.adjacentShapeMargin**2)**t.props.scale;for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="note"&&c.id!==t.id){const u=e.getShapePageBounds(c);if(u&&b.Dist2(u.center,n)<a&&e.isPointInShape(c,n)){o=c;break}}}if(e.complete(),!o||s){e.mark("creating note shape");const l=$e();e.createShape({id:l,type:"note",x:n.x,y:n.y,rotation:r,opacity:t.opacity,props:{...t.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const c=e.getShape(l);if(!c)return;const u=e.getPointInParentSpace(c,b.Sub(n,b.Rot(yg.clone().mul(c.props.scale),r)));e.updateShape({id:l,type:"note",x:u.x,y:u.y}),o=e.getShape(l)}return vA(e),o}var Yy;let cX=(Yy=class extends se{constructor(){super(...arguments);g(this,"dragged",!1);g(this,"info",{});g(this,"wasFocusedOnEnter",!1);g(this,"markId","");g(this,"shape",{});g(this,"onEnter",()=>{const{editor:n}=this;if(this.wasFocusedOnEnter=!n.getIsMenuOpen(),this.wasFocusedOnEnter){const r=$e();this.markId=`creating:${r}`,n.mark(this.markId);const s=this.editor.inputs.originPagePoint.clone(),o=aI(this.editor,s,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);o&&s.sub(o),this.shape=lI(this.editor,r,s)}});g(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=$e(),s=this.editor.inputs.originPagePoint.clone(),o=aI(this.editor,s,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);o&&s.sub(o),this.shape=lI(this.editor,r,s)}this.editor.setCurrentTool("select.translating",{...n,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()})}complete(){this.wasFocusedOnEnter&&(this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):(this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape",{...this.info,target:"shape",shape:this.shape})))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}},g(Yy,"id","pointing"),Yy);function aI(e,t,n){let r=xA/e.getZoomLevel(),s;for(const o of bA(e,0,n,0)){const i=b.Sub(t,o),a=i.len();a<r&&(r=a,s=i)}return s}function lI(e,t,n){e.createShape({id:t,type:"note",x:n.x,y:n.y,props:{scale:e.user.getIsDynamicResizeMode()?1/e.getZoomLevel():1}}).select(t);const r=e.getShape(t),s=e.getShapeGeometry(r).bounds;return e.updateShapes([{id:t,type:"note",x:r.x-s.width/2,y:r.y-s.height/2}]),e.getShape(t)}class ep extends se{constructor(){super(...arguments);g(this,"shapeType","note")}}g(ep,"id","note"),g(ep,"initial","idle"),g(ep,"children",()=>[sX,cX]);function uX(e){const t=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),renderingOnly:!0});if(!t)return e.setHoveredShape(null);let n;const r=e.getOutermostSelectableShape(t);return r===t||r.id===e.getFocusedGroupId()||e.getSelectedShapeIds().includes(r.id)?n=t:n=r,e.setHoveredShape(n.id)}const Ws=Ok(uX,32);var Xy;let dX=(Xy=class extends se{constructor(){super(...arguments);g(this,"onPointerMove",n=>{switch(n.target){case"shape":case"canvas":Ws(this.editor)}});g(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onExit",()=>{Ws.cancel()});g(this,"onKeyDown",n=>{var r;if(n.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const s=this.editor.getOnlySelectedShape();s&&this.editor.getShapeUtil(s).canEdit(s)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(s.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...n,target:"shape",shape:s}))}});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Xy,"id","idle"),Xy);var qy;let hX=(qy=class extends se{constructor(){super(...arguments);g(this,"shape");g(this,"markId","");g(this,"onExit",()=>{this.editor.setHintingShapes([])});g(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{inputs:{originPagePoint:r}}=this.editor,s=$e();this.markId=`creating:${s}`,this.editor.mark(this.markId);const o=this.createTextShape(s,r,!1);if(!o){this.cancel();return}this.shape=this.editor.getShape(o),this.editor.select(s),this.editor.setCurrentTool("select.resizing",{...n,target:"selection",handle:"right",isCreating:!0,creationCursorOffset:{x:18,y:1},onInteractionEnd:"text",onCreate:()=>{this.editor.setEditingShape(o.id),this.editor.setCurrentTool("select.editing_shape")}})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.cancel()});g(this,"onCancel",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}complete(){var o;this.editor.mark("creating text shape");const n=$e(),{currentPagePoint:r}=this.editor.inputs;this.createTextShape(n,r,!0)&&(this.editor.select(n),this.editor.setEditingShape(n),this.editor.setCurrentTool("select"),(o=this.editor.root.getCurrent())==null||o.transition("editing_shape"))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(n,r,s){this.editor.createShape({id:n,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:s,w:20,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const o=this.editor.getShape(n);if(!o){this.cancel();return}const i=this.editor.getShapePageBounds(o),a=new b;if(s)switch(o.props.textAlign){case"start":{a.x=0;break}case"middle":{a.x=-i.width/2;break}case"end":{a.x=-i.width;break}}else a.x=0;if(a.y=-i.height/2,jn(o.parentId)){const l=this.editor.getShapeParentTransform(o);a.rot(-l.rotation())}return this.editor.updateShape({...o,x:o.x+a.x,y:o.y+a.y}),o}},g(qy,"id","pointing"),qy);class Ec extends se{constructor(){super(...arguments);g(this,"shapeType","text")}}g(Ec,"id","text"),g(Ec,"initial","idle"),g(Ec,"children",()=>[dX,hX]),g(Ec,"isLockable",!1);const pX=[Ec,Cc,Qh,ep,Jh,Ov,Zh,Ic];function jr(){return lo({isDarkMode:td()})}function Sg(e){return{key:`${bs.id}:${e}`,getElement:async()=>{const t=fX(e);if(!t)return null;const n=t.$$_url,r=t.$$_fontface;if(!n||!r)return null;const s=await(await ws(n)).blob(),o=await Ai.blobToDataUrl(s),i=r.replace(n,o);return d.jsx("style",{children:i})}}}function fX(e){const t=f_[e];for(const n of document.fonts)if(t.includes(n.family))return n;return null}function fw(e){return{key:`${bs.id}:${e}`,getElement:async()=>e!=="pattern"?null:d.jsx(gX,{})}}function gX(){const e=jr(),t=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:"hash_pattern_mask",children:[d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),d.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[d.jsx("line",{x1:t*1,y1:t*3,x2:t*3,y2:t*1}),d.jsx("line",{x1:t*5,y1:t*7,x2:t*7,y2:t*5}),d.jsx("line",{x1:t*9,y1:t*11,x2:t*11,y2:t*9})]})]}),d.jsx("pattern",{id:wf(1,e.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function gw(){return{key:`${bs.id}:pattern`,component:vX}}const kc=8,cI=(e,t,n)=>new Promise((r,s)=>{const o=kc*t*e,i=document.createElement("canvas");i.width=o,i.height=o;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?Dp.darkMode.solid:Dp.lightMode.solid,a.fillRect(0,0,o,o),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*t*e;const l=8/12,c=u=>u*t*e;a.beginPath(),a.moveTo(c(l*1),c(l*3)),a.lineTo(c(l*3),c(l*1)),a.moveTo(c(l*5),c(l*7)),a.lineTo(c(l*7),c(l*5)),a.moveTo(c(l*9),c(l*11)),a.lineTo(c(l*11),c(l*9)),a.stroke(),i.toBlob(u=>{!u||xt.throwToBlob.get()?s():r(u)})}),uI=(e,t)=>{const n=document.createElement("canvas");n.width=e[0],n.height=e[1];const r=n.getContext("2d");return r?(t(r),n.toDataURL()):""};let my=null;function mX(){return my||(my={white:uI([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:uI([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),my}function CA(e){return Math.ceil(Math.log2(Math.max(1,e)))}function wf(e,t){const n=CA(e);return`tldraw_hash_pattern_${t}_${n}`}function IA(e){const t=[],r=CA(e);for(let s=0;s<=r;s++)t.push(Math.pow(2,s));return t}function yX(e){const t=mX();return IA(e).flatMap(n=>[{zoom:n,url:t.white,theme:"light"},{zoom:n,url:t.black,theme:"dark"}])}function SX(){const e=F(),t=K("devicePixelRatio",()=>e.getInstanceState().devicePixelRatio,[e]),n=K("maxZoom",()=>Math.ceil(Ut(e.getCameraOptions().zoomSteps)),[e]),[r,s]=P.useState(!1),[o,i]=P.useState(()=>yX(n));return P.useEffect(()=>{const l=Promise.all(IA(n).flatMap(u=>[cI(t,u,!1).then(h=>({zoom:u,theme:"light",url:URL.createObjectURL(h)})),cI(t,u,!0).then(h=>({zoom:u,theme:"dark",url:URL.createObjectURL(h)}))]));let c=!1;return l.then(u=>{c||(i(u),s(!0))}),()=>{c=!0,s(!1),l.then(u=>{for(const{url:h}of u)URL.revokeObjectURL(h)})}},[t,n]),{defs:d.jsx(d.Fragment,{children:o.map(l=>{const c=wf(l.zoom,l.theme);return d.jsx("pattern",{id:c,width:kc,height:kc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:l.url,width:kc,height:kc})},c)})}),isReady:r}}function vX(){const e=F(),t=P.useRef(null),{defs:n,isReady:r}=SX();return P.useEffect(()=>{if(r&&e.environment.isSafari){const s=EA(t.current);s&&e.timers.requestAnimationFrame(()=>{s.style.display="none",e.timers.requestAnimationFrame(()=>{s.style.display=""})})}},[e,r]),d.jsx("g",{ref:t,"data-testid":r?"ready-pattern-fill-defs":void 0,children:n})}function EA(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?EA(e.parentElement):null}const rn=Ce.memo(function({theme:t,d:n,color:r,fill:s,scale:o}){switch(s){case"none":return null;case"solid":return d.jsx("path",{fill:t[r].semi,d:n});case"semi":return d.jsx("path",{fill:t.solid,d:n});case"fill":return d.jsx("path",{fill:t[r].fill,d:n});case"pattern":return d.jsx(xX,{theme:t,color:r,fill:s,d:n,scale:o})}});function xX({d:e,color:t,theme:n}){const r=F(),s=VM(),o=K("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:n[t].pattern,d:e}),d.jsx("path",{fill:s?`url(#${wf(1,n.id)})`:i?n[t].semi:`url(#${wf(o,n.id)})`,d:e})]})}function wX(e){return e.replace(/\s/g," ")}function Dv(e,t,n){const{padding:r=0}=n;if(t.length===0)return null;const s=Q.From(t[0].box);for(const{box:c}of t)s.union(c);const o=r+(n.offsetX??0),i=(n.offsetY??0)+n.fontSize/2+(n.verticalTextAlign==="start"?r:n.verticalTextAlign==="end"?n.height-r-s.height:(Math.ceil(n.height)-s.height)/2);let a=null;const l=[];for(const{text:c,box:u}of t)a!==null&&u.y>a&&l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:o,y:u.y+i,children:`
|
|
201
|
-
`},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+o,y:u.y+i,unicodeBidi:"plaintext",children:wX(c)},l.length)),a=u.y;return d.jsx("text",{fontSize:n.fontSize,fontFamily:n.fontFamily,fontStyle:n.fontStyle,fontWeight:n.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:n.stroke,strokeWidth:n.strokeWidth,fill:n.fill,children:l})}function bX(e,t,n,r){if((e==="start-legacy"||e==="end-legacy")&&n.length!==0){const s=Q.From(n[0].box);for(const{box:o}of n)s.union(o);if(e==="start-legacy")return(r-2*t-s.width)/2;if(e==="end-legacy")return-(r-2*t-s.width)/2}}function PX(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function vg({fontSize:e,font:t,align:n,verticalAlign:r,text:s,labelColor:o,bounds:i,padding:a=16,stroke:l=!0}){const c=F(),u=jr(),h={fontSize:e,fontFamily:f_[t],textAlign:n,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:Vt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:o,stroke:void 0,strokeWidth:void 0},p=c.textMeasure.measureTextSpans(s,h),f=bX(n,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const S=Dv(c,p,h);let y=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,y=Dv(c,p,h)),d.jsxs(d.Fragment,{children:[y,S]})}const CX=P.forwardRef(function({isEditing:t,text:n,handleFocus:r,handleChange:s,handleKeyDown:o,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){return d.jsx("textarea",{ref:c,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!t,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:n,onFocus:r,onChange:s,onKeyDown:o,onBlur:i,onTouchEnd:Ot,onContextMenu:t?Ot:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:Ee})});function IX(e,t,n){const r=F(),s=P.useRef(null),o=K("isEditing",()=>r.getEditingShapeId()===e,[r]),i=K("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);P.useEffect(()=>{function u({shapeId:h}){var p;h===e&&((p=s.current)==null||p.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,e,o]),P.useEffect(()=>{var u,h,p,f;o&&(document.activeElement!==s.current&&((u=s.current)==null||u.focus()),r.getInstanceState().isCoarsePointer&&((h=s.current)==null||h.select()),r.environment.isSafari&&((p=s.current)==null||p.blur(),(f=s.current)==null||f.focus()))},[r,o]);const a=P.useCallback(u=>{if(r.getEditingShapeId()===e)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&r.complete();break}}},[r,e]),l=P.useCallback(u=>{if(r.getEditingShapeId()!==e)return;let h=ml.normalizeText(u.currentTarget.value);const p=h.replace(/\t/g,Ga);if(p!==h){const f=u.currentTarget.selectionStart;u.currentTarget.value=p,u.currentTarget.selectionStart=f+(p.length-h.length),u.currentTarget.selectionEnd=f+(p.length-h.length),h=p}r.updateShape({id:e,type:t,props:{text:h}})},[r,e,t]),c=P.useCallback(u=>{r.dispatch({...Nn(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Ot(u)},[r,e]);return{rInput:s,handleFocus:nu,handleBlur:nu,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:Ot,isEmpty:n.trim().length===0,isEditing:o,isEditingAnything:i}}const xg=Ce.memo(function({id:t,type:n,text:r,labelColor:s,font:o,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:f,classNamePrefix:S,style:y,textWidth:x,textHeight:m}){const{rInput:v,isEmpty:w,isEditing:C,isEditingAnything:E,..._}=IX(t,n,r),[I,k]=P.useState(r);P.useEffect(()=>{C||k(r)},[C,r]);const T=ml.normalizeTextForDom(r),M=T.length>0,D=PX(l);if(!C&&!M)return null;const $=S||"tl-text";return d.jsx("div",{className:`${$}-label tl-text-wrapper`,"data-font":o,"data-align":l,"data-hastext":!w,"data-isediting":C,"data-iseditinganything":E,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||D?"center":l,alignItems:c==="middle"?"center":c,padding:p,...y},children:d.jsxs("div",{className:`${$}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(x||0),color:s,width:x?Math.ceil(x):void 0,height:m?Math.ceil(m):void 0},children:[d.jsx("div",{className:`${$} tl-text tl-text-content`,dir:"auto",children:T.split(`
|
|
202
|
-
`).map((j,O)=>d.jsx("div",{dir:"auto",children:j},O))}),(E||h)&&d.jsx(CX,{ref:v,text:r,isEditing:C,..._,handleKeyDown:f??_.handleKeyDown},I)]})})});function as(e,t,n={}){const{closed:r=!1,snap:s=1,start:o="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=n;let c=0,u=0,h=1,p=0,f=0;switch(l){case"dashed":{h=1,c=Math.min(t*a,e/4);break}case"dotted":{h=100,c=t/h;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(o==="outset"?(e+=c/2,f+=c/2):o==="skip"&&(e-=c,f-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),u=Math.floor(e/c/(2*h)),u-=u%s,u<3&&l==="dashed"?e/t<4?(c=e,u=1,p=0):(c=e*(1/3),p=e*(1/3)):(c=e/u/(2*h),r?(f=c/2,p=(e-u*c)/u):p=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}const dI=new WeakMap;function mw(e,t){const n=dI.get(t);if(n)return n;const r=ps(e,t);let s=0,o=0;const i=r.isStraight?new Ks({start:b.From(r.start.point),end:b.From(r.end.point)}):new Ua({center:b.Cast(r.handleArc.center),start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(t.props.text.trim()){const l=i.bounds,c=Rv(t),{w:u,h}=e.textMeasure.measureText(t.props.text,{...Vt,fontFamily:xs[t.props.font],fontSize:c,maxWidth:null});if(s=u,o=h,l.width>l.height){s=Math.max(Math.min(u,64),Math.min(l.width-64,u));const{w:p,h:f}=e.textMeasure.measureText(t.props.text,{...Vt,fontFamily:xs[t.props.font],fontSize:c,maxWidth:s});s=p,o=f}if(s>16*c){s=16*c;const{w:p,h:f}=e.textMeasure.measureText(t.props.text,{...Vt,fontFamily:xs[t.props.font],fontSize:c,maxWidth:s});s=p,o=f}}const a=new b(s,o).addScalar(bY*2*t.props.scale);return dI.set(t,a),a}function kA(e){const t=jt[e.props.size];return(wY+(t-jt.s)*2+(t===jt.xl?20:0))*e.props.scale}function EX(e,t,n){const r=mw(e,t),s=kA(t),o=b.Nudge(n.start.point,n.end.point,s),i=b.Nudge(n.end.point,n.start.point,s),a=ew(o,i,Q.FromCenter(n.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;b.Dist2(l,o)>b.Dist2(c,o)&&([c,l]=a);const u=o.add(b.Sub(n.middle,l)),h=i.add(b.Sub(n.middle,c)),p=b.Dist(n.start.point,u)/n.length,f=b.Dist(n.start.point,h)/n.length;return{start:p,end:f}}function kX(e,t,n){const r=mw(e,t),s=kA(t),o=Math.sign(t.props.bend),i=s/n.handleArc.radius*o,a=b.Angle(n.bodyArc.center,n.start.point)-i,l=b.Angle(n.bodyArc.center,n.end.point)+i,c=zi(n.bodyArc.center,n.bodyArc.radius,a),u=zi(n.bodyArc.center,n.bodyArc.radius,l),h=[],p=hI(n.bodyArc.center,n.bodyArc.radius,a,l,o,Q.FromCenter(c,r).corners);h.push(new vt({points:Q.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const f=hI(n.bodyArc.center,n.bodyArc.radius,a,l,o,Q.FromCenter(u,r).corners);h.push(new vt({points:Q.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const I of[...p??[],...f??[],c,u])h.push(new uw({x:I.x-3,y:I.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const S=(p&&pI(n.start.point,p))??n.middle,y=(f&&pI(n.end.point,f))??n.middle,x=b.Angle(n.bodyArc.center,n.start.point),m=b.Angle(n.bodyArc.center,n.end.point),v=b.Angle(n.bodyArc.center,S),w=b.Angle(n.bodyArc.center,y);if(ko(x,v,o)>ko(x,w,o))return{start:.5,end:.5,dbg:h};const C=ko(x,m,o),E=ko(x,v,o)/C,_=ko(x,w,o)/C;return{start:E,end:_,dbg:h}}function tp(e,t){let n;const r=[],s=ps(e,t),o=!!s.bindings.start,i=!!s.bindings.end,a=s.start.arrowhead!=="none",l=s.end.arrowhead!=="none";if(s.isStraight){const u=EX(e,t,s);let h=_t(t.props.labelPosition,a||o?u.start:0,l||i?u.end:1);h=h>=.48&&h<=.52?.5:h,n=b.Lrp(s.start.point,s.end.point,h)}else{const u=kX(e,t,s);u.dbg&&r.push(...u.dbg);let h=_t(t.props.labelPosition,a||o?u.start:0,l||i?u.end:1);h=h>=.48&&h<=.52?.5:h;const p=_X(b.Angle(s.bodyArc.center,s.start.point),b.Angle(s.bodyArc.center,s.end.point),Math.sign(t.props.bend),h);n=zi(s.bodyArc.center,s.bodyArc.radius,p)}const c=mw(e,t);return{box:Q.FromCenter(n,c),debugGeom:r}}function hI(e,t,n,r,s,o){const i=Ev(e,t,o),a=ko(n,r,s);return i==null?void 0:i.filter(l=>{const c=ko(n,b.Angle(e,l),s);return c>=0&&c<=a})}function pI(e,t){let n=null,r=-1/0;for(const s of t){const o=b.Dist2(e,s);o>r&&(n=s,r=o)}return n}function _X(e,t,n,r){const s=ko(e,t,n);return e+s*r*n*-1}function Rv(e){return xY[e.props.size]*e.props.scale}function TX(e,t,n){const r=t==="end"?e.end.point:e.start.point,s=t==="end"?e.start.point:e.end.point,o=e.isStraight?b.Dist(s,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(o/5,n*3),n);let a;if(e.isStraight)a=b.Nudge(r,s,i);else{const l=ZW(r,i,e.handleArc.center,e.handleArc.radius);a=t==="end"?e.handleArc.sweepFlag?l[0]:l[1]:e.handleArc.sweepFlag?l[1]:l[0]}return b.IsNaN(a)&&(a=e.start.point),{point:r,int:a}}function MX({point:e,int:t}){const n=b.RotWith(t,e,Me/6),r=b.RotWith(t,e,-Me/6);return`M ${n.x} ${n.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function AX({point:e,int:t}){const n=b.RotWith(t,e,Me/6),r=b.RotWith(t,e,-Me/6);return`M ${n.x} ${n.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function jX({point:e,int:t}){const n=b.Sub(t,e).div(2),r=b.Add(e,b.Rot(n,Ve)),s=b.Sub(e,b.Rot(n,Ve));return`M ${r.x} ${r.y} L ${t.x} ${t.y} L ${s.x} ${s.y} Z`}function OX({point:e,int:t}){const n=b.Lrp(e,t,.45),r=b.Dist(n,e);return`M ${n.x-r},${n.y}
|
|
203
|
-
a ${r},${r} 0 1,0 ${r*2},0
|
|
204
|
-
a ${r},${r} 0 1,0 -${r*2},0 `}function DX({point:e,int:t}){const n=b.Lrp(e,t,.75),r=b.RotWith(n,e,Me/4),s=b.RotWith(n,e,-Me/4),o=b.Lrp(r,s,.5);return o.add(b.Sub(o,e)),`M ${o.x} ${o.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${s.x} ${s.y} Z`}function RX({int:e,point:t}){const n=b.Lrp(t,e,.85),r=b.Sub(n,t).div(2),s=b.Add(t,b.Rot(r,Ve)),o=b.Sub(t,b.Rot(r,Ve)),i=b.Add(n,b.Rot(r,Ve)),a=b.Sub(n,b.Rot(r,Ve));return`M ${s.x} ${s.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${o.x} ${o.y} Z`}function LX({int:e,point:t}){const n=b.Sub(e,t).div(2),r=b.Add(t,b.Rot(n,Ve)),s=b.Sub(t,b.Rot(n,Ve));return`M ${r.x} ${r.y} L ${s.x} ${s.y}`}function bf(e,t,n){const r=t==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const s=TX(e,t,n);if(s){switch(r){case"bar":return LX(s);case"square":return RX(s);case"diamond":return DX(s);case"dot":return OX(s);case"inverted":return jX(s);case"arrow":return MX(s);case"triangle":return AX(s)}return""}}function $X(e){const{start:t,end:n,handleArc:{radius:r,largeArcFlag:s,sweepFlag:o}}=e;return`M${t.handle.x},${t.handle.y} A${r} ${r} 0 ${s} ${o} ${n.handle.x},${n.handle.y}`}function _A(e){const{start:t,end:n,bodyArc:{radius:r,largeArcFlag:s,sweepFlag:o}}=e;return`M${t.point.x},${t.point.y} A${r} ${r} 0 ${s} ${o} ${n.point.x},${n.point.y}`}function TA(e,t){return`M${e.x},${e.y}L${t.x},${t.y}`}function NX(e){return TA(e.start.handle,e.end.handle)}function MA(e){return TA(e.start.point,e.end.point)}let FX=0;class np extends Wr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"canSnap",()=>!1);g(this,"hideResizeHandles",()=>!0);g(this,"hideRotateHandle",()=>!0);g(this,"hideSelectionBoundsBg",()=>!0);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"canBeLaidOut",n=>{const r=Ln(this.editor,n);return!r.start&&!r.end});g(this,"onHandleDrag",(n,{handle:r,isPrecise:s})=>{const o=r.id,i=Ln(this.editor,n);if(o==="middle"){const{start:_,end:I}=Ha(this.editor,n,i),k=b.Sub(I,_),T=b.Per(k),M=b.Med(I,_),D=b.Sub(M,T),$=b.Add(M,T),j=b.NearestPointOnLineSegment(D,$,r,!1);let O=b.Dist(j,M);return b.Clockwise(j,I,M)&&(O*=-1),{id:n.id,type:n.type,props:{bend:O}}}const a={id:n.id,type:"arrow",props:{}},l=i[o],u=i[o==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return Xh(this.editor,n,o),a.props[o]={x:r.x,y:r.y},a;const h=this.editor.getShapePageTransform(n.id).applyToPoint(r),p=this.editor.getShapeAtPoint(h,{hitInside:!0,hitFrameInside:!0,margin:0,filter:_=>!_.isLocked&&this.editor.canBindShapes({fromShape:n,toShape:_,binding:"arrow"})});if(!p)return Xh(this.editor,n,o),a.props[o]={x:r.x,y:r.y},a;const f=this.editor.getShapeGeometry(p),S=Q.ZeroFix(f.bounds),x=this.editor.getShapePageTransform(a.id).applyToPoint(r),m=this.editor.getPointInShapeSpace(p,x);let v=s;v||(!l||l&&p.id!==l.toId)&&(v=this.editor.inputs.pointerVelocity.len()<.5),s||(f.isClosed||(v=!0),u&&p.id===u.toId&&u.props.isPrecise&&(v=!0));const w={x:(m.x-S.minX)/S.width,y:(m.y-S.minY)/S.height};v&&b.Dist(m,S.center)<Math.max(4,Math.min(Math.min(S.width,S.height)*.15,16))/this.editor.getZoomLevel()&&(w.x=.5,w.y=.5);const C={terminal:o,normalizedAnchor:w,isPrecise:v,isExact:this.editor.inputs.altKey};lc(this.editor,n,p.id,C),this.editor.setHintingShapes([p.id]);const E=Ln(this.editor,n);return E.start&&E.end&&E.start.toId===E.end.toId&&b.Equals(E.start.props.normalizedAnchor,E.end.props.normalizedAnchor)&&lc(this.editor,n,E.end.toId,{...E.end.props,normalizedAnchor:{x:E.end.props.normalizedAnchor.x+.05,y:E.end.props.normalizedAnchor.y}}),a});g(this,"onTranslateStart",n=>{const r=Ln(this.editor,n),s=Ha(this.editor,n,r),o=this.editor.getShapePageTransform(n.id),i=this.editor.getSelectedShapeIds();if(!(r.start&&(i.includes(r.start.toId)||this.editor.isAncestorSelected(r.start.toId))||r.end&&(i.includes(r.end.toId)||this.editor.isAncestorSelected(r.end.toId)))){gI.set(n,{pagePosition:o.applyToPoint(n),terminalBindings:Bu(s,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:o.applyToPoint(l)}:null})}),r.start&&(vf({editor:this.editor,arrow:n,terminal:"start",useHandle:!0}),n=this.editor.getShape(n.id)),r.end&&vf({editor:this.editor,arrow:n,terminal:"end",useHandle:!0});for(const a of["start","end"]){const l=r[a];l&&this.editor.updateBinding({...l,props:{...l.props,isPrecise:!0}})}}});g(this,"onTranslate",(n,r)=>{const s=gI.get(n);if(!s)return;const o=this.editor.getShapePageTransform(r.id),i=b.Sub(o.applyToPoint(r),s.pagePosition);for(const a of Object.values(s.terminalBindings)){if(!a)continue;const l=b.Add(a.pagePosition,b.Mul(i,.5)),c=this.editor.getShapeAtPoint(l,{hitInside:!0,hitFrameInside:!0,margin:0,filter:u=>!u.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:u,binding:"arrow"})});if((c==null?void 0:c.id)===a.binding.toId){const u=Q.ZeroFix(this.editor.getShapeGeometry(c).bounds),h=this.editor.getPointInShapeSpace(c,l),p={x:(h.x-u.minX)/u.width,y:(h.y-u.minY)/u.height};lc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else Xh(this.editor,r,a.binding.props.terminal)}});g(this,"_resizeInitialBindings",new Zs);g(this,"onResize",(n,r)=>{const{scaleX:s,scaleY:o}=r,i=this._resizeInitialBindings.get(n,()=>Ln(this.editor,n)),a=Ha(this.editor,n,i),{start:l,end:c}=Ge(n.props);let{bend:u}=n.props;i.start||(l.x=a.start.x*s,l.y=a.start.y*o),i.end||(c.x=a.end.x*s,c.y=a.end.y*o);const h=Math.abs(s),p=Math.abs(o),f=i!=null&&i.start?b.From(i.start.props.normalizedAnchor):null,S=i!=null&&i.end?b.From(i.end.props.normalizedAnchor):null;return s<0&&o>=0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.x=1-f.x),S&&(S.x=1-S.x)):s>=0&&o<0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.y=1-f.y),S&&(S.y=1-S.y)):s>=0&&o>=0?u!==0&&(u*=Math.max(h,p)):s<0&&o<0&&(u!==0&&(u*=Math.max(h,p)),f&&(f.x=1-f.x,f.y=1-f.y),S&&(S.x=1-S.x,S.y=1-S.y)),i.start&&f&&lc(this.editor,n,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&S&&lc(this.editor,n,i.end.toId,{...i.end.props,normalizedAnchor:S.toJson()}),{props:{start:l,end:c,bend:u}}});g(this,"onDoubleClickHandle",(n,r)=>{switch(r.id){case"start":return{id:n.id,type:n.type,props:{...n.props,arrowheadStart:n.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:n.id,type:n.type,props:{...n.props,arrowheadEnd:n.props.arrowheadEnd==="none"?"arrow":"none"}}}});g(this,"onEditEnd",n=>{const{id:r,type:s,props:{text:o}}=n;o.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:o.trimEnd()}}])})}canBind({toShapeType:n}){return n!=="arrow"}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{x:0,y:0},end:{x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw",scale:1}}getGeometry(n){const r=ps(this.editor,n),s=[],o=r.isStraight?new Ks({start:b.From(r.start.point),end:b.From(r.end.point)}):new Ua({center:b.Cast(r.handleArc.center),start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(n.props.text.trim()){const a=tp(this.editor,n);s.push(...a.debugGeom),i=new ro({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Gr({children:[...i?[o,i]:[o],...s]})}getHandles(n){const r=ps(this.editor,n);return[{id:"start",type:"vertex",index:"a0",x:r.start.handle.x,y:r.start.handle.y},{id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y}].filter(Boolean)}component(n){const r=jr(),s=this.editor.getOnlySelectedShape(),o=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,i=ps(this.editor,n);if(!(i!=null&&i.isValid))return null;const a=tp(this.editor,n),l=n.id===this.editor.getOnlySelectedShapeId(),u=this.editor.getEditingShapeId()===n.id||n.props.text;return d.jsxs(d.Fragment,{children:[d.jsx(Zo,{id:n.id,style:{minWidth:50,minHeight:50},children:d.jsx(fI,{shape:n,shouldDisplayHandles:o&&(s==null?void 0:s.id)===n.id})}),u&&d.jsx(xg,{id:n.id,classNamePrefix:"tl-arrow",type:"arrow",font:n.props.font,fontSize:Rv(n),lineHeight:Vt.lineHeight,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:r[n.props.labelColor].solid,textWidth:a.box.w,isSelected:l,padding:0,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)`}})]})}indicator(n){const r=gg(n.id),s=ps(this.editor,n);if(!s)return null;const{start:o,end:i}=Ha(this.editor,n,s==null?void 0:s.bindings),a=this.editor.getShapeGeometry(n),l=a.bounds,c=n.props.text.trim()?a.children[1]:null;if(b.Equals(o,i))return null;const u=jt[n.props.size]*n.props.scale,h=s.start.arrowhead&&bf(s,"start",u),p=s.end.arrowhead&&bf(s,"end",u),f=s.isStraight?MA(s):_A(s),S=h&&s.start.arrowhead!=="arrow"||p&&s.end.arrowhead!=="arrow"||!!c,y=(n.id+"_clip").replace(":","_");return r&&c?d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5*n.props.scale,ry:3.5*n.props.scale}):d.jsxs("g",{children:[S&&d.jsx("defs",{children:d.jsxs("mask",{id:y,children:[d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.w+200,height:l.h+200,fill:"white"}),c&&d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,fill:"black",rx:3.5*n.props.scale,ry:3.5*n.props.scale}),h&&d.jsx("path",{d:h,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&d.jsx("path",{d:p,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{...S?{mask:`url(#${y})`}:void 0,children:[S&&d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.width+200,height:l.height+200,opacity:0}),d.jsx("path",{d:f})]}),h&&d.jsx("path",{d:h}),p&&d.jsx("path",{d:p}),c&&d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5,ry:3.5})]})}toSvg(n,r){r.addExportDef(fw(n.props.fill)),n.props.text&&r.addExportDef(Sg(n.props.font));const s=lo(r),o=1/n.props.scale;return d.jsxs("g",{transform:`scale(${o})`,children:[d.jsx(fI,{shape:n,shouldDisplayHandles:!1}),d.jsx(vg,{fontSize:Rv(n),font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:s[n.props.labelColor].solid,bounds:tp(this.editor,n).box,padding:4*n.props.scale})]})}getCanvasSvgDefs(){return[gw(),{key:"arrow:dot",component:BX},{key:"arrow:cross",component:UX}]}getInterpolatedProps(n,r,s){return{...r.props,start:{x:On(n.props.start.x,r.props.start.x,s),y:On(n.props.start.y,r.props.start.y,s)},end:{x:On(n.props.end.x,r.props.end.x,s),y:On(n.props.end.y,r.props.end.y,s)},bend:On(n.props.bend,r.props.bend,s),labelPosition:On(n.props.labelPosition,r.props.labelPosition,s)}}}g(np,"type","arrow"),g(np,"props",m_),g(np,"migrations",y_);function zX(e,t){const n=ps(e,t);return n.isStraight?b.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const fI=Lt(function({shape:t,shouldDisplayHandles:n}){const r=F(),s=jr(),o=ps(r,t),i=Q.ZeroFix(r.getShapeGeometry(t).bounds),a=Ln(r,t),l=Ce.useMemo(()=>r.environment.isSafari?FX+=1:0,[t]);if(!(o!=null&&o.isValid))return null;const c=jt[t.props.size]*t.props.scale,u=o.start.arrowhead&&bf(o,"start",c),h=o.end.arrowhead&&bf(o,"end",c),p=o.isStraight?MA(o):_A(o);let f=null;if(n){const C=2/r.getZoomLevel(),{strokeDasharray:E,strokeDashoffset:_}=as(zX(r,t),C,{end:"skip",start:"skip",lengthRatio:2.5});f=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:o.isStraight?NX(o):$X(o),strokeDasharray:E,strokeDashoffset:_,strokeWidth:C,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:S,strokeDashoffset:y}=as(o.isStraight?o.length:Math.abs(o.bodyArc.length),c,{style:t.props.dash}),x=tp(r,t),m=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),v=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow"),w=(t.id+"_clip_"+l).replace(":","_");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsxs("mask",{id:w,children:[d.jsx("rect",{x:N(-100+i.minX),y:N(-100+i.minY),width:N(i.width+200),height:N(i.height+200),fill:"white"}),t.props.text.trim()&&d.jsx("rect",{x:x.box.x,y:x.box.y,width:x.box.w,height:x.box.h,fill:"black",rx:4,ry:4}),u&&m&&d.jsx("path",{d:u,fill:o.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),h&&v&&d.jsx("path",{d:h,fill:o.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{fill:"none",stroke:s[t.props.color].solid,strokeWidth:c,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[f,d.jsxs("g",{mask:`url(#${w})`,children:[d.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),d.jsx("path",{d:p,strokeDasharray:S,strokeDashoffset:y})]}),u&&m&&t.props.fill!=="none"&&d.jsx(rn,{theme:s,d:u,color:t.props.color,fill:t.props.fill,scale:t.props.scale}),h&&v&&t.props.fill!=="none"&&d.jsx(rn,{theme:s,d:h,color:t.props.color,fill:t.props.fill,scale:t.props.scale}),u&&d.jsx("path",{d:u}),h&&d.jsx("path",{d:h})]})]})}),gI=new WeakMap;function BX(){return d.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:d.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function UX(){return d.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[d.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),d.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const mI="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E";function yl({url:e,zoomLevel:t}){return d.jsx("a",{className:ce("tl-hyperlink-button",{"tl-hyperlink-button__hidden":t<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:Ot,onPointerUp:Ot,title:e,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${mI}") center 100% / 100% no-repeat`,WebkitMask:`url("${mI}") center 100% / 100% no-repeat`}})})}const yI="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E",HX=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function yw(e){return HX.map(n=>{const{offsetX:r,offsetY:s,blur:o,spread:i,color:a}=n,l=new b(r,s),{x:c,y:u}=l.rot(-e);return`${c}px ${u}px ${o}px ${i}px ${a}`}).join(", ")}const KX=300,AA=320,WX=46,GX=101;class rp extends Dl{constructor(){super(...arguments);g(this,"canResize",()=>!1);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"onBeforeCreate",n=>SI(this.editor,n));g(this,"onBeforeUpdate",(n,r)=>{if(n.props.url!==r.props.url)if(lr.isValid(r.props.url))YX(this.editor,r);else return{...r,props:{...r.props,url:n.props.url}};if(n.props.assetId!==r.props.assetId)return SI(this.editor,r)})}getDefaultProps(){return{url:"",w:KX,h:AA,assetId:null}}component(n){const r=n.props.assetId?this.editor.getAsset(n.props.assetId):null,s=this.editor.getShapePageTransform(n).rotation(),o=VX(n);return d.jsx(Gi,{children:d.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:yw(s),maxHeight:n.props.h},children:[(!r||r.props.image)&&d.jsxs("div",{className:"tl-bookmark__image_container",children:[r?d.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):d.jsx("div",{className:"tl-bookmark__placeholder"}),(r==null?void 0:r.props.image)&&d.jsx(yl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]}),d.jsxs("div",{className:"tl-bookmark__copy_container",children:[r!=null&&r.props.title?d.jsx("h2",{className:"tl-bookmark__heading",children:r.props.title}):null,r!=null&&r.props.description&&(r!=null&&r.props.image)?d.jsx("p",{className:"tl-bookmark__description",children:r.props.description}):null,d.jsxs("a",{className:"tl-bookmark__link",href:n.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Ot,onPointerUp:Ot,onClick:Ot,children:[r!=null&&r.props.favicon?d.jsx("img",{className:"tl-bookmark__favicon",src:r==null?void 0:r.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",alt:`favicon of ${o}`}):d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${yI}") center 100% / 100% no-repeat`,WebkitMask:`url("${yI}") center 100% / 100% no-repeat`}}),d.jsx("span",{children:o})]})]})]})})}indicator(n){return d.jsx("rect",{width:N(n.props.w),height:N(n.props.h),rx:"6",ry:"6"})}}g(rp,"type","bookmark"),g(rp,"props",P_),g(rp,"migrations",C_);function SI(e,t){const n=t.props.assetId?e.getAsset(t.props.assetId):null;let r=AA;return n&&(n.props.image||(n.props.title?r=GX:r=WX)),{...t,props:{...t.props,h:r}}}const VX=e=>{try{return new URL(e.props.url).hostname.replace(/^www\./,"")}catch{return e.props.url}};function YX(e,t){const{url:n}=t.props,r=Ii.createId(vS(n));e.getAsset(r)?t.props.assetId!==r&&e.updateShapes([{id:t.id,type:t.type,props:{assetId:r}}]):(e.updateShapes([{id:t.id,type:t.type,props:{assetId:null}}]),XX(e,t))}const XX=zk(async(e,t)=>{if(e.isDisposed)return;const{url:n}=t.props,r=await e.getAssetForExternalContent({type:"url",url:n});r&&e.run(()=>{e.createAssets([r]),e.updateShapes([{id:t.id,type:t.type,props:{assetId:r.id}}])})},500);function Vi(e,t=!1){const n=e.length;if(n<2)return"";let r=e[0].point,s=e[1].point;if(n===2)return`M${Te(r)}L${Te(s)}`;let o="";for(let i=2,a=n-1;i<a;i++)r=e[i].point,s=e[i+1].point,o+=Dn(r,s);return t?`M${Dn(e[0].point,e[1].point)}Q${Te(e[1].point)}${Dn(e[1].point,e[2].point)}T${o}${Dn(e[n-1].point,e[0].point)}${Dn(e[0].point,e[1].point)}Z`:`M${Te(e[0].point)}Q${Te(e[1].point)}${Dn(e[1].point,e[2].point)}${e.length>3?"T":""}${o}L${Te(e[n-1].point)}`}function qX(e,t={}){const{start:n={},end:r={}}=t,{cap:s=!0}=n,{cap:o=!0}=r;Xe(!n.taper&&!r.taper,"cap taper not supported here"),Xe(!n.easing&&!r.easing,"cap easing not supported here"),Xe(s&&o,"cap must be true");const i=Cs(e,t);mg(i,t);const a=ZX(i);let l="";for(const c of a)l+=JX(c,t);return l}function ZX(e){if(e.length<=2)return[e];const t=[];let n=[e[0]],r=b.Sub(e[1].point,e[0].point).uni(),s,o,i,a,l;for(let c=1,u=e.length;c<u-1;c++){if(i=e[c-1],a=e[c],l=e[c+1],s=b.Sub(l.point,a.point).uni(),o=b.Dpr(r,s),r=s,o<-.8){const h={...a,point:a.input};n.push(h),t.push(yy(n)),n=[h];continue}if(n.push(a),!(o>.7)&&(b.Dist2(i.point,a.point)+b.Dist2(a.point,l.point))/((i.radius+a.radius+l.radius)/3)**2<1.5){n.push(a),t.push(yy(n)),n=[a];continue}}return n.push(e[e.length-1]),t.push(yy(n)),t}function yy(e){const t=e[0];let n;for(;e.length>2&&(n=e[1],b.Dist2(t.point,n.point)<((t.radius+n.radius)/2*.5)**2);)e.splice(1,1);const r=e[e.length-1];let s;for(;e.length>2&&(s=e[e.length-2],b.Dist2(r.point,s.point)<((r.radius+s.radius)/2*.5)**2);)e.splice(e.length-2,1);return e.length>1&&(e[0]={...e[0],vector:b.Sub(e[0].point,e[1].point).uni()},e[e.length-1]={...e[e.length-1],vector:b.Sub(e[e.length-2].point,e[e.length-1].point).uni()}),e}function QX(e,t,n){return"M "+e+" "+t+" m -"+n+", 0 a "+n+","+n+" 0 1,1 "+n*2+",0 a "+n+","+n+" 0 1,1 -"+n*2+",0"}function JX(e,t={}){if(e.length===0)return"";if(e.length===1)return QX(e[0].point.x,e[0].point.y,e[0].radius);const{left:n,right:r}=cA(e,t);r.reverse();let s=`M${Te(n[0])}T`;for(let o=1;o<n.length;o++)s+=Dn(n[o-1],n[o]);{const o=e[e.length-1],i=o.radius,a=o.vector.clone().per().neg(),l=b.Add(o.point,b.Mul(a,i)),c=b.Add(o.point,b.Mul(a,-i));s+=`${Te(l)}A${N(i)},${N(i)} 0 0 1 ${Te(c)}T`}for(let o=1;o<r.length;o++)s+=Dn(r[o-1],r[o]);{const o=e[0],i=o.radius,a=o.vector.clone().per(),l=b.Add(o.point,b.Mul(a,i)),c=b.Add(o.point,b.Mul(a,-i));s+=`${Te(l)}A${N(i)},${N(i)} 0 0 1 ${Te(c)}Z`}return s}const eq=e=>e*.65+g9(e*Me/2)*.35,tq=e=>({size:e,thinning:.5,streamline:il(e,[9,16],[.64,.74],!0),smoothing:.62,easing:At.easeOutSine,simulatePressure:!0}),nq=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:eq}),vI=e=>({size:e,thinning:0,streamline:il(e,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:At.linear}),rq=e=>({size:e,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:At.linear});function Sw({strokeWidth:e,showAsComplete:t}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:At.easeOutSine,last:t}}function Lv(e,t,n,r){const s=e.isComplete||n;return r?e.isPen?{...rq(t),last:s}:{...vI(t),last:s}:e.dash==="draw"?e.isPen?{...nq(t),last:s}:{...tq(t),last:s}:{...vI(t),last:s}}function Sl(e){const t=[];for(const n of e)if(n.type==="free"||n.points.length<2)t.push(...n.points.map(b.Cast));else{const r=Math.max(4,Math.floor(b.Dist(n.points[0],n.points[1])/16));t.push(...b.PointsBetween(n.points[0],n.points[1],r))}return t}function sq(e,t){return{draw:"none",solid:"none",dotted:`0.1 ${t*2}`,dashed:`${t*2} ${t*2}`}[e.props.dash]}class sp extends Wr{constructor(){super(...arguments);g(this,"hideResizeHandles",n=>Sy(n));g(this,"hideRotateHandle",n=>Sy(n));g(this,"hideSelectionBoundsFg",n=>Sy(n));g(this,"onResize",(n,r)=>{const{scaleX:s,scaleY:o}=r,i=[];for(const a of n.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:Bs(s*l),y:Bs(o*c),z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(n){const r=Sl(n.props.segments),s=(jt[n.props.size]+1)*n.props.scale;if(n.props.segments.length===1){const i=Q.FromPoints(r);if(i.width<s*2&&i.height<s*2)return new uw({x:-s,y:-s,radius:s,isFilled:!0})}const o=Cs(r,Lv(n.props,s,n.props.isPen,!0)).map(i=>i.point);return n.props.isClosed?new vt({points:o,isFilled:n.props.fill!=="none"}):new Ol({points:o})}component(n){return d.jsx(Zo,{id:n.id,children:d.jsx(xI,{shape:n,zoomLevel:this.editor.getZoomLevel()})})}indicator(n){var h;const r=Sl(n.props.segments);let s=(jt[n.props.size]+1)*n.props.scale;const o=this.editor.getZoomLevel();!(o<.5&&o<1.5/s)&&!n.props.isPen&&n.props.dash==="draw"&&r.length===1&&(s+=qr(n.id)()*(s/6));const a=n.props.isComplete||((h=Ut(n.props.segments))==null?void 0:h.type)==="straight",l=Lv(n.props,s,a,!0),c=Cs(r,l),u=c.length>1?Vi(c,n.props.isClosed):jA(r[0],s);return d.jsx("path",{d:u})}toSvg(n,r){r.addExportDef(fw(n.props.fill));const s=1/n.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(xI,{shape:n,zoomLevel:1})})}getCanvasSvgDefs(){return[gw()]}expandSelectionOutlinePx(n){const r=n.props.dash==="draw"?1.6:1;return jt[n.props.size]*r/2*n.props.scale}}g(sp,"type","draw"),g(sp,"props",E_),g(sp,"migrations",k_);function jA(e,t){const n=(t+1)*.5;return`M ${e.x} ${e.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function Sy(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function xI({shape:e,zoomLevel:t}){var h;const n=jr(),r=Sl(e.props.segments),s=e.props.isComplete||((h=Ut(e.props.segments))==null?void 0:h.type)==="straight";let o=(jt[e.props.size]+1)*e.props.scale;const i=t<.5&&t<1.5/o;!i&&!e.props.isPen&&e.props.dash==="draw"&&r.length===1&&(o+=qr(e.id)()*(o/6));const a=Lv(e.props,o,s,i);if(!i&&e.props.dash==="draw")return d.jsxs(d.Fragment,{children:[e.props.isClosed&&e.props.fill&&r.length>1?d.jsx(rn,{d:Vi(Cs(r,a),e.props.isClosed),theme:n,color:e.props.color,fill:e.props.isClosed?e.props.fill:"none",scale:e.props.scale}):null,d.jsx("path",{d:qX(r,a),strokeLinecap:"round",fill:n[e.props.color].solid})]});const l=Cs(r,a),c=l.length<2,u=c?jA(r[0],0):Vi(l,e.props.isClosed);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{d:u,theme:n,color:e.props.color,fill:c||e.props.isClosed?e.props.fill:"none",scale:e.props.scale}),d.jsx("path",{d:u,strokeLinecap:"round",fill:c?n[e.props.color].solid:"none",stroke:n[e.props.color].solid,strokeWidth:o,strokeDasharray:c?"none":sq(e,o),strokeDashoffset:"0"})]})}function oq(e,t,n={}){const{newPoint:r,handle:s,scaleX:o,scaleY:i}=t,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let h=e.props.w*o,p=e.props.h*i;const f=new b(0,0);if(h>0){if(h<a){switch(s){case"top_left":case"left":case"bottom_left":{f.x=h-a;break}case"top":case"bottom":{f.x=(h-a)/2;break}default:f.x=0}h=a}}else if(f.x=h,h=-h,h<a){switch(s){case"top_left":case"left":case"bottom_left":{f.x=-h;break}default:f.x=-a}h=a}if(p>0){if(p<c){switch(s){case"top_left":case"top":case"top_right":{f.y=p-c;break}case"right":case"left":{f.y=(p-c)/2;break}default:f.y=0}p=c}}else if(f.y=p,p=-p,p<c){switch(s){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-c}p=c}const{x:S,y}=f.rot(e.rotation).add(r);return{x:S,y,props:{w:Math.min(l,h),h:Math.min(u,p)}}}const iq=e=>Object.entries(e).filter(([t,n])=>n).map(([t])=>t).join(" ");class op extends Dl{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",n=>!this.canResize(n));g(this,"canEdit",()=>!0);g(this,"canResize",n=>{var r,s;return!!((s=(r=Ro(n.props.url))==null?void 0:r.definition)!=null&&s.doesResize)});g(this,"canEditInReadOnly",()=>!0);g(this,"isAspectRatioLocked",n=>{const r=Ro(n.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});g(this,"onResize",(n,r)=>{const s=this.isAspectRatioLocked(n),o=Ro(n.props.url);let i=(o==null?void 0:o.definition.minWidth)??200,a=(o==null?void 0:o.definition.minHeight)??200;if(s){const l=n.props.w/n.props.h;l>1?i*=l:a/=l}return oq(n,r,{minWidth:i,minHeight:a})})}getDefaultProps(){return{w:300,h:300,url:""}}component(n){const{w:r,h:s,url:o}=n.props,i=gg(n.id),a=P.useMemo(()=>fA(o),[o]),l=K("is hovering",()=>{const{editingShapeId:f,hoveredShapeId:S}=this.editor.getCurrentPageState();if(f&&S!==f){const y=this.editor.getShape(f);if(y&&this.editor.isShapeOfType(y,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(n).rotation(),u=i||l;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const f=a.url.split("/").pop();if(!f)throw Error("No gist id!");return d.jsx(Gi,{className:"tl-embed-container",id:n.id,children:d.jsx(aq,{id:f,width:N(r),height:N(s),isInteractive:u,pageRotation:c})})}const p=iq({...ZU,...(a==null?void 0:a.definition.overridePermissions)??{}});return d.jsx(Gi,{className:"tl-embed-container",id:n.id,children:a!=null&&a.definition?d.jsx("iframe",{className:"tl-embed",sandbox:p,src:a.embedUrl,width:N(r),height:N(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:yw(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(n){const r=P.useMemo(()=>Ro(n.props.url),[n.props.url]);return d.jsx("rect",{width:N(n.props.w),height:N(n.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}g(op,"type","embed"),g(op,"props",__),g(op,"migrations",T_);function aq({id:e,file:t,isInteractive:n,width:r,height:s,style:o,pageRotation:i}){return d.jsx("iframe",{className:"tl-embed",draggable:!1,width:N(r),height:N(s),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...o,pointerEvents:n?"all":"none",zIndex:n?"":"-1",boxShadow:yw(i)},srcDoc:`
|
|
205
|
-
<html>
|
|
206
|
-
<head>
|
|
207
|
-
<base target="_blank">
|
|
208
|
-
</head>
|
|
209
|
-
<body>
|
|
210
|
-
<script src=${`https://gist.github.com/${e}.js${t?`?file=${t}`:""}`}><\/script>
|
|
211
|
-
<style type="text/css">
|
|
212
|
-
* { margin: 0px; }
|
|
213
|
-
table { height: 100%; background-color: red; }
|
|
214
|
-
.gist { background-color: none; height: 100%; }
|
|
215
|
-
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
216
|
-
</style>
|
|
217
|
-
</body>
|
|
218
|
-
</html>`})}const lq=P.forwardRef(({id:e,name:t,isEditing:n},r)=>{const s=F(),o=P.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Ot(l),l.currentTarget.blur(),s.setEditingShape(null))},[s]),i=P.useCallback(l=>{const c=s.getShape(e);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==h&&s.updateShapes([{id:e,type:"frame",props:{name:h}}])},[e,s]),a=P.useCallback(l=>{const c=s.getShape(e);if(!c)return;const u=c.props.name,h=l.currentTarget.value;u!==h&&s.updateShapes([{id:e,type:"frame",props:{name:h}}])},[e,s]);return d.jsxs("div",{className:`tl-frame-label ${n?"tl-frame-label__editing":""}`,children:[d.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:n?void 0:"none"},value:t,autoFocus:!0,onKeyDown:o,onBlur:i,onChange:a}),OA(t,"Frame")+""]})}),cq=function({id:t,name:n,width:r,height:s}){const o=F(),i=K("shape rotation",()=>No(o.getShapePageTransform(t).rotation()),[o,t]),a=gg(t),l=P.useRef(null),c=P.useCallback(S=>{const y=Nn(S);S.preventDefault(),o.getEditingShapeId()!==t&&o.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:o.getShape(t),...y})},[o,t]);P.useEffect(()=>{const S=l.current;S&&a&&(S.focus(),S.select())},[l,a]);const h=((i+Math.PI/4)*(2/Math.PI)+4)%4,p=["top","left","bottom","right"][Math.floor(h)];let f;switch(p){case"top":f="";break;case"right":f=`translate(${N(r)}px, 0px) rotate(90deg)`;break;case"bottom":f=`translate(${N(r)}px, ${N(s)}px) rotate(180deg)`;break;case"left":f=`translate(0px, ${N(s)}px) rotate(270deg)`;break}return d.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(p==="top"||p==="bottom"?r:s)}px + var(--space-5))`,bottom:"100%",transform:`${f} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:c,children:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(lq,{ref:l,id:t,name:n,isEditing:a})})})};function OA(e,t){return e.match(/^\s*$/)?t:e}class ip extends Dl{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"canReceiveNewChildrenOfType",(n,r)=>!n.isLocked);g(this,"canDropShapes",(n,r)=>!n.isLocked);g(this,"onDragShapesOver",(n,r)=>{r.every(s=>s.parentId===n.id)||this.editor.reparentShapes(r,n.id)});g(this,"onDragShapesOut",(n,r)=>{const s=this.editor.getShape(n.parentId);s&&this.editor.isShapeOfType(s,"group")?this.editor.reparentShapes(r,s.id):this.editor.reparentShapes(r,this.editor.getCurrentPageId())});g(this,"onResize",(n,r)=>lw(n,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(n){return new ro({width:n.props.w,height:n.props.h,isFilled:!1})}component(n){const r=this.editor.getShapeGeometry(n).bounds,s=jr(),o=K("is creating this shape",()=>{const i=this.editor.getStateDescendant("select.resizing");if(!i||!i.getIsActive())return!1;const a=i==null?void 0:i.info;return a?a.isCreating&&this.editor.getOnlySelectedShapeId()===n.id:!1},[n.id]);return d.jsxs(d.Fragment,{children:[d.jsx(Zo,{children:d.jsx("rect",{className:ce("tl-frame__body",{"tl-frame__creating":o}),width:r.width,height:r.height,fill:s.solid,stroke:s.text})}),o?null:d.jsx(cq,{id:n.id,name:n.props.name,width:r.width,height:r.height})]})}toSvg(n,r){const s=lo({isDarkMode:r.isDarkMode}),a=((No(this.editor.getShapePageTransform(n.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,l=Math.floor(a);let c;switch(l){case 0:c="";break;case 3:c=`translate(${N(n.props.w)}, 0) rotate(90)`;break;case 2:c=`translate(${N(n.props.w)}, ${N(n.props.h)}) rotate(180)`;break;case 1:c=`translate(0, ${N(n.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}const u={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:n.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle"},h=this.editor.textMeasure.measureTextSpans(OA(n.props.name,"Frame")+"",u),p=h[0],f=Ut(h),S=f.box.w+f.box.x-p.box.x,y=Dv(this.editor,h,{offsetY:-u.height-2,...u});return d.jsxs(d.Fragment,{children:[d.jsx("rect",{width:n.props.w,height:n.props.h,fill:s.solid,stroke:s.black.solid,strokeWidth:1,rx:1,ry:1}),d.jsxs("g",{transform:c,children:[d.jsx("rect",{x:-8,y:-u.height-4,width:S+16,height:u.height,fill:s.background,rx:4,ry:4}),y]})]})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds;return d.jsx("rect",{width:N(r.width),height:N(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}g(ip,"type","frame"),g(ip,"props",M_),g(ip,"migrations",A_);function wI(e,t){return e>t?(Me*(t/2)+(e-t))*2:(Me*(e/2)+(t-e))*2}function DA(e,t){return vw(e,t).map((n,r)=>n.getSvgPathData(r===0)).join(" ")+" Z"}function uq(e,t,n,r){const s=e/4,o=t/4,i=qr(r),a=n*.75,l=v=>v.addXY(i()*a,i()*a),c=new b(e/2,t),u=new b(0,o*1.2),h=new b(e/2,o*.9),p=new b(e,o*1.2),f=l(new b(e/2,t)),S=l(new b(0,o*1.2)),y=l(new b(e/2,o*.9)),x=l(new b(e,o*1.2));return[new on({start:c,cp1:new b(s*1.5,o*3),cp2:new b(0,o*2.5),end:u}),new on({start:u,cp1:new b(0,-o*.32),cp2:new b(s*1.85,-o*.32),end:h}),new on({start:h,cp1:new b(s*2.15,-o*.32),cp2:new b(e,-o*.32),end:p}),new on({start:p,cp1:new b(e,o*2.5),cp2:new b(s*2.5,o*3),end:f}),new on({start:f,cp1:new b(s*1.5,o*3),cp2:new b(0,o*2.5),end:S}),new on({start:S,cp1:new b(0,-o*.32),cp2:new b(s*1.85,-o*.32),end:y}),new on({start:y,cp1:new b(s*2.15,-o*.32),cp2:new b(e,-o*.32),end:x}),new on({start:x,cp1:new b(e,o*2.5),cp2:new b(s*2.5,o*3),end:c})].map((v,w)=>v.getSvgPathData(w===0)).join(" ")+" Z"}function vw(e,t){const n=e/4,r=t/4;return[new on({start:new b(e/2,t),cp1:new b(n*1.5,r*3),cp2:new b(0,r*2.5),end:new b(0,r*1.2)}),new on({start:new b(0,r*1.2),cp1:new b(0,-r*.32),cp2:new b(n*1.85,-r*.32),end:new b(e/2,r*.9)}),new on({start:new b(e/2,r*.9),cp1:new b(n*2.15,-r*.32),cp2:new b(e,-r*.32),end:new b(e,r*1.2)}),new on({start:new b(e,r*1.2),cp1:new b(e,r*2.5),cp2:new b(n*2.5,r*3),end:new b(e/2,t)})]}function dq(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function hq(e,t,n,r){const s=qr(e),o=t/2,i=n/2,a=Z_(o,i),l=[],c=Le*s(),u=Le+Ve/2+Math.abs(s())*Ve,h=Math.max(16,a/10);for(let p=0;p<h;p++){const f=p/(h-1),S=c+f*u,y=Math.cos(S),x=Math.sin(S);l.push(new b(o*y+t*.5+.05*s(),i*x+n/2+.05*s(),Math.min(1,.5+Math.abs(.5-(s()>0?At.easeInOutSine(f):At.easeInExpo(f)))/2)))}return Cs(l,dq(r))}function pq(e,t,n,r){return Vi(hq(e,t,n,r))}function $v(e){let t="M";const n=e.length;let r,s,o;for(let i=0,a=n;i<a;i+=3)r=e[i],s=e[i+1],o=e[i+2],t+=`${Te(r)}L${Te(s)}Q${Te(o)}`;return t+=`${Te(e[0])}`,t}function Nv(e,t,n,r,s){const o=[],i=qr(e);let a=t[0],l;const c=t.length;for(let u=0,h=c*s;u<h;u++){l=b.AddXY(t[(u+1)%c],i()*n,i()*n);const p=b.Sub(l,a),f=b.Len(p),S=b.Div(p,f).mul(Math.min(f/4,r));o.push(b.Add(a,S),b.Add(l,S.neg()),l),a=l}return o}function fq(e,t,n){const r=Math.min(e,t)/2,s=Math.max(e,t)-r*2,i=(Math.PI*(r*2)+2*s)/n,a=e>t?[{type:"straight",start:new b(r,0),delta:new b(1,0)},{type:"arc",center:new b(e-r,r),startAngle:-Me/2},{type:"straight",start:new b(e-r,t),delta:new b(-1,0)},{type:"arc",center:new b(r,r),startAngle:Me/2}]:[{type:"straight",start:new b(e,r),delta:new b(0,1)},{type:"arc",center:new b(r,t-r),startAngle:0},{type:"straight",start:new b(0,t-r),delta:new b(0,-1)},{type:"arc",center:new b(r,r),startAngle:Me}];let l=0;const c=[];for(let u=0;u<n;u++){const h=a[0];h.type==="straight"?c.push(b.Add(h.start,b.Mul(h.delta,l))):c.push(zi(h.center,r,h.startAngle+l/r)),l+=i;let p=h.type==="straight"?s:Me*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?s:Me*r}return c}const gq={s:50,m:70,l:100,xl:130},mq=.2;function wg(e,t,n,r){const s=qr(n),o=wI(e,t),i=Math.max(Math.ceil(o/gq[r]),6,Math.ceil(o/Math.min(e,t))),a=o/i*mq,l=Math.max(e-a*2,1),c=Math.max(t-a*2,1),h=wI(l,c)/i,p=(e-l)/2,f=(t-c)/2,S=fq(l,c,i).map(w=>w.addXY(p,f)),y=e<20?0:a*.3,x=t<20?0:a*.3,m=S.slice(0);for(let w=0;w<Math.floor(i/2);w++)m[w]=b.AddXY(m[w],s()*y,s()*x),m[i-w-1]=b.AddXY(m[i-w-1],s()*y,s()*x);const v=[];for(let w=0;w<m.length;w++){const C=w===m.length-1?0:w+1,E=m[w],_=m[C],I=S[w],k=S[C],T=b.Dist(I,k),M=h-T,$=b.Dist(E,_)/T,j=(Math.max(p,f)+M)*$,O=b.Lrp(I,k,.5).add(b.Sub(k,I).uni().per().mul(j));O.x<0?O.x=0:O.x>e&&(O.x=e),O.y<0?O.y=0:O.y>t&&(O.y=t);const R=n0(E,_,O),H=b.Dist(R||b.Average([E,_]),E);v.push({leftPoint:E,rightPoint:_,arcPoint:O,center:R,radius:H})}return v}function yq(e,t,n,r){const s=[],o=wg(e,t,n,r);for(const{center:i,radius:a,leftPoint:l,rightPoint:c}of o)s.push(...v9(l,c,i,a,10));return s}function Fv(e,t,n,r){const s=wg(e,t,n,r);let o=`M${s[0].leftPoint.toFixed()}`;for(const{leftPoint:i,rightPoint:a,radius:l,center:c}of s){if(c===null){o+=` L${a.toFixed()}`;continue}const u=b.Clockwise(i,a,c)?"0":"1";o+=` A${N(l)},${N(l)} 0 ${u},1 ${a.toFixed()}`}return o+=" Z",o}const Sq={s:.5,m:.7,l:.9,xl:1.6};function vq(e,t,n,r){const s=qr(n),o=Sq[r],i=wg(e,t,n,r),c=i.reduce((f,S)=>f+b.Dist2(S.leftPoint,S.rightPoint),0)/i.length>(o*15)**2?f=>f.addXY(s()*o*2,s()*o*2):f=>f;let u=`M${i[0].leftPoint.toFixed()}`,h=c(i[0].leftPoint),p=`M${h.toFixed()}`;for(const{leftPoint:f,center:S,rightPoint:y,radius:x,arcPoint:m}of i){if(S===null){u+=` L${y.toFixed()}`;const I=c(y);p+=` L${I.toFixed()}`,h=I;continue}const v=b.Clockwise(f,y,S)?"0":"1";u+=` A${N(x)},${N(x)} 0 ${v},1 ${y.toFixed()}`;const w=c(y),C=c(m),E=n0(h,w,C);if(!Number.isFinite(E.x)||!Number.isFinite(E.y)){p+=` L${w.toFixed()}`,h=w;continue}const _=Math.abs(b.Dist(E,h));p+=` A${N(_)},${N(_)} 0 ${v},1 ${w.toFixed()}`,h=w}return u+p+" Z"}function zv(e,t){switch(e.geo){case"x-box":return xq(e.w,e.h,t,e.dash);case"check-box":return wq(e.w,e.h);default:return}}function xq(e,t,n,r){const s=r==="draw"?.62:0;if(r==="dashed")return[[new b(0,0),new b(e/2,t/2)],[new b(e,t),new b(e/2,t/2)],[new b(0,t),new b(e/2,t/2)],[new b(e,0),new b(e/2,t/2)]];const o=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(t,a));return[[new b(o(n*s),i(n*s)),new b(o(e-n*s),i(t-n*s))],[new b(o(n*s),i(t-n*s)),new b(o(e-n*s),i(n*s))]]}function wq(e,t){const n=Math.min(e,t)*.82,r=(e-n)/2,s=(t-n)/2,o=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(t,a));return[[new b(o(r+n*.25),i(s+n*.52)),new b(o(r+n*.45),i(s+n*.82))],[new b(o(r+n*.45),i(s+n*.82)),new b(o(r+n*.82),i(s+n*.22))]]}function bI({shape:e,shouldScale:t}){const n=t?e.props.scale:1,r=F(),s=jr(),{id:o,props:i}=e,{w:a,color:l,fill:c,dash:u,growY:h,size:p}=i,f=jt[p]*n,S=i.h+h;switch(i.geo){case"cloud":if(u==="solid"){const y=Fv(a,S,o,p);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:l,fill:c,scale:n}),d.jsx("path",{d:y,stroke:s[l].solid,strokeWidth:f,fill:"none"})]})}else if(u==="draw"){const y=vq(a,S,o,p);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:l,fill:c,scale:n}),d.jsx("path",{d:y,stroke:s[l].solid,strokeWidth:f,fill:"none"})]})}else{const y=Fv(a,S,o,p),x=wg(a,S,o,p);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:l,fill:c,scale:n}),d.jsx("g",{strokeWidth:f,stroke:s[l].solid,fill:"none",pointerEvents:"all",children:x.map(({leftPoint:m,rightPoint:v,center:w,radius:C},E)=>{const _=w?C*No(No(b.Angle(w,v))-No(b.Angle(w,m))):b.Dist(m,v),{strokeDasharray:I,strokeDashoffset:k}=as(_,f,{style:u,start:"outset",end:"outset"});return d.jsx("path",{d:w?`M${m.x},${m.y}A${C},${C},0,0,1,${v.x},${v.y}`:`M${m.x},${m.y}L${v.x},${v.y}`,strokeDasharray:I,strokeDashoffset:k},E)})})]})}case"ellipse":{const y=t?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=y.getSvgPathData(!0);if(u==="dashed"||u==="dotted"){const m=y.length,{strokeDasharray:v,strokeDashoffset:w}=as(m<64?m*2:m,f,{style:u,snap:4,closed:!0});return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:x,color:l,fill:c,scale:n}),d.jsx("path",{d:x,strokeWidth:f,fill:"none",stroke:s[l].solid,strokeDasharray:v,strokeDashoffset:w})]})}else{const v=(t?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e)).getSvgPathData(!0);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:v,color:l,fill:c,scale:n}),d.jsx("path",{d:v,stroke:s[l].solid,strokeWidth:f,fill:"none"})]})}}case"oval":{const y=t?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=y.getSvgPathData(!0);if(u==="dashed"||u==="dotted"){const m=y.getLength(),{strokeDasharray:v,strokeDashoffset:w}=as(m<64?m*2:m,f,{style:u,snap:4,start:"outset",end:"outset",closed:!0});return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:x,color:l,fill:c,scale:n}),d.jsx("path",{d:x,strokeWidth:f,fill:"none",stroke:s[l].solid,strokeDasharray:v,strokeDashoffset:w})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:x,color:l,fill:c,scale:n}),d.jsx("path",{d:x,stroke:s[l].solid,strokeWidth:f,fill:"none"})]})}case"heart":if(u==="dashed"||u==="dotted"||u==="solid"){const y=DA(a,S),x=vw(a,S);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:l,fill:c,scale:n}),x.map((m,v)=>{const{strokeDasharray:w,strokeDashoffset:C}=as(m.length,f,{style:u,snap:1,start:"outset",end:"outset",closed:!0});return d.jsx("path",{d:m.getSvgPathData(),strokeWidth:f,fill:"none",stroke:s[l].solid,strokeDasharray:w,strokeDashoffset:C,pointerEvents:"all"},`curve_${v}`)})]})}else{const y=uq(a,S,f,e.id);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:l,fill:c,scale:n}),d.jsx("path",{d:y,stroke:s[l].solid,strokeWidth:f,fill:"none"})]})}default:{const y=t?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=y instanceof Gr?y.children[0].vertices:y.vertices,m=zv(e.props,f);if(u==="solid"){let v="M"+x[0]+"L"+x.slice(1)+"Z";if(m)for(const[w,C]of m)v+=`M${w.x},${w.y}L${C.x},${C.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:v,color:l,fill:c,scale:n}),d.jsx("path",{d:v,stroke:s[l].solid,strokeWidth:f,fill:"none"})]})}else if(u==="dashed"||u==="dotted"){const v="M"+x[0]+"L"+x.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:v,color:l,fill:c,scale:n}),d.jsxs("g",{strokeWidth:f,stroke:s[l].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(x.length)).map((w,C)=>{const E=b.ToFixed(x[C]),_=b.ToFixed(x[(C+1)%x.length]),I=b.Dist(E,_),{strokeDasharray:k,strokeDashoffset:T}=as(I,f,{style:u,start:"outset",end:"outset"});return d.jsx("line",{x1:E.x,y1:E.y,x2:_.x,y2:_.y,strokeDasharray:k,strokeDashoffset:T},C)}),m&&m.map(([w,C],E)=>{const _=b.Dist(w,C),{strokeDasharray:I,strokeDashoffset:k}=as(_,f,{style:u,start:"skip",end:"skip",snap:u==="dotted"?4:void 0});return d.jsx("path",{d:`M${w.x},${w.y}L${C.x},${C.y}`,stroke:s[l].solid,strokeWidth:f,fill:"none",strokeDasharray:I,strokeDashoffset:k},`line_fg_${E}`)})]})]})}else if(u==="draw"){let v=$v(Nv(o,x,f/3,f*2,2));if(m)for(const[C,E]of m)v+=`M${C.toFixed()}L${E.toFixed()}`;const w=$v(Nv(o,x,0,f*2,1));return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:w,color:l,fill:c,scale:n}),d.jsx("path",{d:v,stroke:s[l].solid,strokeWidth:f,fill:"none"})]})}}}}const PI=17*3;class ap extends Dl{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"onEditEnd",n=>{const{id:r,type:s,props:{text:o}}=n;o.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:o.trimEnd()}}])});g(this,"onResize",(n,{handle:r,newPoint:s,scaleX:o,scaleY:i,initialShape:a})=>{const l=a.props.w/a.props.scale,c=a.props.h/a.props.scale,u=a.props.growY/a.props.scale;let h=l*o,p=(c+u)*i,f=0,S=0;const y=PI;if(n.props.text.trim()){let E=Math.max(Math.abs(h),y),_=Math.max(Math.abs(p),y);E<y&&_===y&&(E=y),E===y&&_<y&&(_=y);const I=ih(this.editor,{...n,props:{...n.props,w:E*n.props.scale,h:_*n.props.scale}}),k=Math.max(Math.abs(h),I.w)*Math.sign(h),T=Math.max(Math.abs(p),I.h)*Math.sign(p);f=Math.abs(k)-Math.abs(h),S=Math.abs(T)-Math.abs(p),h=k,p=T}const x=h*n.props.scale,m=p*n.props.scale,v=new b(0,0);o<0&&(v.x+=x),(r==="left"||r==="top_left"||r==="bottom_left")&&(v.x+=o<0?f:-f),i<0&&(v.y+=m),(r==="top"||r==="top_left"||r==="top_right")&&(v.y+=i<0?S:-S);const{x:w,y:C}=v.rot(n.rotation).add(s);return{x:w,y:C,props:{w:Math.max(Math.abs(x),1),h:Math.max(Math.abs(m),1),growY:0}}});g(this,"onBeforeCreate",n=>{if(!n.props.text)return n.props.growY?{...n,props:{...n.props,growY:0}}:void 0;const r=n.props.h/n.props.scale,s=ih(this.editor,n).h;let o=null;if(s>r?o=s-r:n.props.growY&&(o=0),o!==null)return{...n,props:{...n.props,growY:o*n.props.scale}}});g(this,"onBeforeUpdate",(n,r)=>{const s=n.props.text,o=r.props.text;if(s===o&&n.props.font===r.props.font&&n.props.size===r.props.size)return;if(s&&!o)return{...r,props:{...r.props,growY:0}};const i=n.props.w/n.props.scale,a=n.props.h/n.props.scale,l=n.props.growY/n.props.scale,c=ih(this.editor,r);if(!s&&o&&o.length===1){let h=Math.max(i,c.w),p=Math.max(a,c.h);const f=PI;return i<f&&a<f&&(h=Math.max(h,f),p=Math.max(p,f),h=Math.max(h,p),p=Math.max(h,p)),{...r,props:{...r.props,w:h*r.props.scale,h:p*r.props.scale,growY:0}}}let u=null;if(c.h>a?u=c.h-a:l&&(u=0),u!==null){const h=r.props.w/r.props.scale;return{...r,props:{...r.props,growY:u*r.props.scale,w:Math.max(h,c.w)*r.props.scale}}}if(c.w>i)return{...r,props:{...r.props,w:c.w*r.props.scale}}});g(this,"onDoubleClick",n=>{if(this.editor.inputs.altKey)switch(n.props.geo){case"rectangle":return{...n,props:{geo:"check-box"}};case"check-box":return{...n,props:{geo:"rectangle"}}}})}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:"",scale:1}}getGeometry(n){const r=Math.max(1,n.props.w),s=Math.max(1,n.props.h+n.props.growY),o=r/2,i=s/2,a=n.props.fill!=="none";let l;switch(n.props.geo){case"cloud":{l=new vt({points:yq(r,s,n.id,n.props.size),isFilled:a});break}case"triangle":{l=new vt({points:[new b(o,0),new b(r,s),new b(0,s)],isFilled:a});break}case"diamond":{l=new vt({points:[new b(o,0),new b(r,i),new b(o,s),new b(0,i)],isFilled:a});break}case"pentagon":{l=new vt({points:km(r,s,5),isFilled:a});break}case"hexagon":{l=new vt({points:km(r,s,6),isFilled:a});break}case"octagon":{l=new vt({points:km(r,s,8),isFilled:a});break}case"ellipse":{l=new JV({width:r,height:s,isFilled:a});break}case"oval":{l=new eY({width:r,height:s,isFilled:a});break}case"star":{const w=Le/5/2,C=Math.floor(5/4)*2,E=5*2-C,_=0,I=Math.floor(5/2)*2,k=Math.cos(-Ve+C*w)*r/2,T=Math.cos(-Ve+E*w)*r/2,M=Math.sin(-Ve+_*w)*s/2,D=Math.sin(-Ve+I*w)*s/2,$=r-Math.abs(k-T),j=s-Math.abs(D-M),O=r/2+T-(r/2-k),R=s/2+M-(s/2-D),H=1,B=(r-O)/2,z=(s-R)/2,W=(r+$)/2,Y=(s+j)/2,q=W*H/2,le=Y*H/2;l=new vt({points:Array.from(Array(5*2)).map((ge,be)=>{const J=-Ve+be*w;return new b(B+(be%2?q:W)*Math.cos(J),z+(be%2?le:Y)*Math.sin(J))}),isFilled:a});break}case"rhombus":{const v=Math.min(r*.38,s*.38);l=new vt({points:[new b(v,0),new b(r,0),new b(r-v,s),new b(0,s)],isFilled:a});break}case"rhombus-2":{const v=Math.min(r*.38,s*.38);l=new vt({points:[new b(0,0),new b(r-v,0),new b(r,s),new b(v,s)],isFilled:a});break}case"trapezoid":{const v=Math.min(r*.38,s*.38);l=new vt({points:[new b(v,0),new b(r-v,0),new b(r,s),new b(0,s)],isFilled:a});break}case"arrow-right":{const v=Math.min(r,s)*.38,w=s*.16;l=new vt({points:[new b(0,w),new b(r-v,w),new b(r-v,0),new b(r,s/2),new b(r-v,s),new b(r-v,s-w),new b(0,s-w)],isFilled:a});break}case"arrow-left":{const v=Math.min(r,s)*.38,w=s*.16;l=new vt({points:[new b(v,0),new b(v,w),new b(r,w),new b(r,s-w),new b(v,s-w),new b(v,s),new b(0,s/2)],isFilled:a});break}case"arrow-up":{const v=r*.16,w=Math.min(r,s)*.38;l=new vt({points:[new b(r/2,0),new b(r,w),new b(r-v,w),new b(r-v,s),new b(v,s),new b(v,w),new b(0,w)],isFilled:a});break}case"arrow-down":{const v=r*.16,w=Math.min(r,s)*.38;l=new vt({points:[new b(v,0),new b(r-v,0),new b(r-v,s-w),new b(r,s-w),new b(r/2,s),new b(0,s-w),new b(v,s-w)],isFilled:a});break}case"check-box":case"x-box":case"rectangle":{l=new ro({width:r,height:s,isFilled:a});break}case"heart":{const w=vw(r,s).reduce((C,E)=>(C.push(...E.vertices),C),[]);l=new vt({points:w,isFilled:a});break}default:un(n.props.geo)}const c=ih(this.editor,n),u=r/n.props.scale,h=s/n.props.scale,p=Math.min(100,u/2),f=Math.min(Xs[n.props.size]*Vt.lineHeight+vr*2,h/2),S=Math.min(u,Math.max(c.w,Math.min(p,Math.max(1,u-8)))),y=Math.min(h,Math.max(c.h,Math.min(f,Math.max(1,h-8)))),x=zv(n.props,jt[n.props.size]*n.props.scale),m=x?x.map(v=>new Ol({points:v})):[];return new Gr({children:[l,new ro({x:n.props.align==="start"?0:n.props.align==="end"?(u-S)*n.props.scale:(u-S)/2*n.props.scale,y:n.props.verticalAlign==="start"?0:n.props.verticalAlign==="end"?(h-y)*n.props.scale:(h-y)/2*n.props.scale,width:S*n.props.scale,height:y*n.props.scale,isFilled:!0,isLabel:!0}),...m]})}getHandleSnapGeometry(n){const r=this.getGeometry(n),s=r.children[0];switch(n.props.geo){case"arrow-down":case"arrow-left":case"arrow-right":case"arrow-up":case"check-box":case"diamond":case"hexagon":case"octagon":case"pentagon":case"rectangle":case"rhombus":case"rhombus-2":case"star":case"trapezoid":case"triangle":case"x-box":return{outline:s,points:[...s.getVertices(),r.bounds.center]};case"cloud":case"ellipse":case"heart":case"oval":return{outline:s,points:[r.bounds.center]};default:un(n.props.geo)}}component(n){const{id:r,type:s,props:o}=n,{fill:i,font:a,align:l,verticalAlign:c,size:u,text:h}=o,p=n.id===this.editor.getOnlySelectedShapeId(),f=jr(),y=this.editor.getEditingShapeId()!==null||n.props.text;return d.jsxs(d.Fragment,{children:[d.jsx(Zo,{id:r,children:d.jsx(bI,{shape:n,shouldScale:!0})}),y&&d.jsx(Gi,{style:{overflow:"hidden",width:n.props.w,height:n.props.h+o.growY},children:d.jsx(xg,{id:r,type:s,font:a,fontSize:Xs[u]*n.props.scale,lineHeight:Vt.lineHeight,padding:vr*n.props.scale,fill:i,align:l,verticalAlign:c,text:h,isSelected:p,labelColor:f[o.labelColor].solid,wrap:!0})}),n.props.url&&d.jsx(yl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){const{id:r,props:s}=n,{w:o,size:i}=s,a=s.h+s.growY,l=jt[i],c=this.editor.getShapeGeometry(n);switch(s.geo){case"ellipse":return s.dash==="draw"?d.jsx("path",{d:pq(r,o,a,l)}):d.jsx("path",{d:c.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:DA(o,a)});case"oval":return d.jsx("path",{d:c.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:Fv(o,a,r,i)});default:{const u=this.editor.getShapeGeometry(n),h=u instanceof Gr?u.children[0].vertices:u.vertices;let p;if(s.dash==="draw"){const S=Nv(r,h,0,l*2*n.props.scale,1);p=$v(S)}else p="M"+h[0]+"L"+h.slice(1)+"Z";const f=zv(n.props,l);if(f)for(const[S,y]of f)p+=`M${S.x},${S.y}L${y.x},${y.y}`;return d.jsx("path",{d:p})}}}toSvg(n,r){const s={...n,props:{...n.props,w:n.props.w/n.props.scale,h:n.props.h/n.props.scale}},o=s.props;r.addExportDef(fw(o.fill));let i;if(o.text){r.addExportDef(Sg(o.font));const a=lo(r),l=new Q(0,0,o.w,o.h+o.growY);i=d.jsx(vg,{fontSize:Xs[o.size],font:o.font,align:o.align,verticalAlign:o.verticalAlign,text:o.text,labelColor:a[o.labelColor].solid,bounds:l,padding:16})}return d.jsxs(d.Fragment,{children:[d.jsx(bI,{shouldScale:!1,shape:s}),i]})}getCanvasSvgDefs(){return[gw()]}}g(ap,"type","geo"),g(ap,"props",j_),g(ap,"migrations",O_);function ih(e,t){const{text:n,font:r,size:s,w:o}=t.props;if(!n)return{w:0,h:0};const i=e.textMeasure.measureText("w",{...Vt,fontFamily:xs[r],fontSize:Xs[s],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=e.textMeasure.measureText(n,{...Vt,fontFamily:xs[r],fontSize:Xs[s],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[s]),Math.ceil(o/t.props.scale-vr*2))});return{w:l.w+vr*2,h:l.h+vr*2}}function bq(){const[e,t]=P.useState(!1);return P.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),s=matchMedia("(color-gamut: p3)");t(r&&s.matches);const o=()=>t(r&&s.matches);return s.addEventListener("change",o),()=>s.removeEventListener("change",o)},[]),K(xt.forceSrgb)||!e?"srgb":"p3"}const CI=.35,II=.82;class lp extends Wr{constructor(){super(...arguments);g(this,"hideResizeHandles",n=>ah(n));g(this,"hideRotateHandle",n=>ah(n));g(this,"hideSelectionBoundsFg",n=>ah(n));g(this,"onResize",(n,r)=>{const{scaleX:s,scaleY:o}=r,i=[];for(const a of n.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:s*l,y:o*c,z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(n){const r=Ci(n);if(ah(n))return new uw({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:s,sw:o}=EI(n,r,!0),i=Sw({strokeWidth:o,showAsComplete:!0});return mg(s,i),new vt({points:dw(s,i),isFilled:!0})}component(n){const r=vy(this.editor,n),s=Ci(n);return d.jsx(Zo,{id:n.id,children:d.jsx(lh,{shape:n,forceSolid:r,strokeWidth:s,opacity:CI})})}backgroundComponent(n){const r=vy(this.editor,n),s=Ci(n);return d.jsx(Zo,{id:n.id,children:d.jsx(lh,{shape:n,forceSolid:r,strokeWidth:s,opacity:II})})}indicator(n){const r=vy(this.editor,n),s=Ci(n),{strokePoints:o,sw:i}=EI(n,s,r),a=Sl(n.props.segments);let l;return o.length<2?l=Cq(a[0],i):l=Vi(o,!1),d.jsx("path",{d:l})}toSvg(n){const r=Ci(n),s=r<1.5,o=1/n.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(lh,{forceSolid:s,strokeWidth:r,shape:n,opacity:CI})})}toBackgroundSvg(n){const r=Ci(n),s=r<1.5,o=1/n.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(lh,{forceSolid:s,strokeWidth:r,shape:n,opacity:II})})}}g(lp,"type","highlight"),g(lp,"props",L_),g(lp,"migrations",$_);function Pq(e){return`M ${e.x} ${e.y} m -${.1}, 0 a ${.1},${.1} 0 1,0 ${.1*2},0 a ${.1},${.1} 0 1,0 -${.1*2},0`}function Cq(e,t){const n=t/2;return`M ${e.x} ${e.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function EI(e,t,n){var l;const r=Sl(e.props.segments),s=e.props.isComplete||((l=Ut(e.props.segments))==null?void 0:l.type)==="straight";let o=t;!n&&!e.props.isPen&&r.length===1&&(o+=qr(e.id)()*(t/6));const i=Sw({strokeWidth:o,showAsComplete:s});return{strokePoints:Cs(r,i),sw:o}}function Ci(e){return gl[e.props.size]*1.12*e.props.scale}function ah(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function lh({strokeWidth:e,forceSolid:t,shape:n,opacity:r}){var p;const s=jr(),o=Sl(n.props.segments);let i=e;!t&&!n.props.isPen&&o.length===1&&(i+=qr(n.id)()*(i/6));const a=Sw({strokeWidth:i,showAsComplete:n.props.isComplete||((p=Ut(n.props.segments))==null?void 0:p.type)==="straight"}),l=Cs(o,a),c=l.length>1?Vi(l,!1):Pq(n.props.segments[0].points[0]),u=bq(),h=s[n.props.color].highlight[u];return d.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function vy(e,t){return K("forceSolid",()=>{const n=Ci(t),r=e.getZoomLevel();return n/r<1.5},[e])}function RA(){return d.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),d.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),d.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function LA(e,t,n){const r=F(),[s,o]=P.useState(null),i=t?r.getAsset(t):null,l=r.getCulledShapes().has(e),c=P.useRef(!1);P.useEffect(()=>{s&&(c.current=!0)},[s]);const u=i&&"w"in i.props?n/i.props.w:1,h=K("zoom level",()=>r.getZoomLevel()*u,[r,u]);return P.useEffect(()=>{if(l)return;let p=!1;const f=r.timers.setTimeout(async()=>{const S=await r.resolveAssetUrl(t,{screenScale:h});p||o(S)},c.current?500:0);return()=>{clearTimeout(f),p=!0}},[t,i==null?void 0:i.props.src,l,h,r]),{asset:i,url:s}}function $A(){const[e,t]=P.useState(!1);return P.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{t(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}async function Iq(e){const n=await(await ws(e)).blob();return Ai.blobToDataUrl(n)}class cp extends Dl{constructor(){super(...arguments);g(this,"isAspectRatioLocked",()=>!0);g(this,"canCrop",()=>!0);g(this,"onResize",(n,r)=>{let s=lw(n,r);const{flipX:o,flipY:i}=r.initialShape.props;return s={...s,props:{...s.props,flipX:r.scaleX<0!==o,flipY:r.scaleY<0!==i}},s});g(this,"onDoubleClick",n=>{const r=n.props.assetId?this.editor.getAsset(n.props.assetId):void 0;!r||!(r.props.src&&this.isAnimated(n))||this.editor.updateShapes([{type:"image",id:n.id,props:{playing:!n.props.playing}}])});g(this,"onDoubleClickEdge",n=>{const r=n.props;if(!r||this.editor.getCroppingShapeId()!==n.id)return;const s=Ge(r.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},o=1/(s.bottomRight.x-s.topLeft.x)*n.props.w,i=1/(s.bottomRight.y-s.topLeft.y)*n.props.h,a=new b(s.topLeft.x*o,s.topLeft.y*i).rot(n.rotation),l={id:n.id,type:n.type,x:n.x-a.x,y:n.y-a.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:o,h:i}};this.editor.updateShapes([l])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null,flipX:!1,flipY:!1}}isAnimated(n){const r=n.props.assetId?this.editor.getAsset(n.props.assetId):void 0;return r?"mimeType"in r.props&&ds.isAnimatedImageType(r==null?void 0:r.props.mimeType)||"isAnimated"in r.props&&r.props.isAnimated:!1}component(n){var y;const r=this.editor.getCroppingShapeId()===n.id,s=$A(),[o,i]=P.useState(""),[a,l]=P.useState(""),c=n.id===this.editor.getOnlySelectedShapeId(),{asset:u,url:h}=LA(n.id,n.props.assetId,n.props.w);if(P.useEffect(()=>{if(h){let x=!1;const m=ol();return m.onload=()=>{x||l(h)},m.src=h,()=>{x=!0}}},[h,n]),P.useEffect(()=>{if(h&&this.isAnimated(n)){let x=!1;const m=ol();return m.onload=()=>{if(x)return;const v=document.createElement("canvas");v.width=m.width,v.height=m.height;const w=v.getContext("2d");w&&(w.drawImage(m,0,0),i(v.toDataURL()),l(h))},m.crossOrigin="anonymous",m.src=h,()=>{x=!0}}},[s,h,n]),(u==null?void 0:u.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const p=c&&r&&this.editor.isIn("select.crop"),f=s&&(((y=u==null?void 0:u.props.mimeType)==null?void 0:y.includes("video"))||this.isAnimated(n)),S=kI(n);return u!=null&&u.props.src?a?d.jsxs(d.Fragment,{children:[p&&d.jsx("div",{style:S,children:d.jsx("img",{className:"tl-image",crossOrigin:this.isAnimated(n)?"anonymous":void 0,src:!n.props.playing||f?o:a,referrerPolicy:"strict-origin-when-cross-origin",style:{opacity:.1},draggable:!1})}),d.jsxs(Gi,{id:n.id,style:{overflow:"hidden",width:n.props.w,height:n.props.h},children:[d.jsxs("div",{className:"tl-image-container",style:S,children:[d.jsx("img",{className:ce("tl-image",{"tl-flip-x":n.props.flipX&&!n.props.flipY,"tl-flip-y":n.props.flipY&&!n.props.flipX,"tl-flip-xy":n.props.flipY&&n.props.flipX}),crossOrigin:this.isAnimated(n)?"anonymous":void 0,src:!n.props.playing||f?o:a,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1}),this.isAnimated(n)&&!n.props.playing&&d.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),n.props.url&&d.jsx(yl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):null:d.jsxs(Gi,{id:n.id,style:{overflow:"hidden",width:n.props.w,height:n.props.h,color:"var(--color-text-3)",backgroundColor:u?"transparent":"var(--color-low)",border:u?"none":"1px solid var(--color-low-border)"},children:[d.jsx("div",{className:"tl-image-container",style:S,children:u?null:d.jsx(RA,{})}),"url"in n.props&&n.props.url&&d.jsx(yl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){return this.editor.getCroppingShapeId()===n.id?null:d.jsx("rect",{width:N(n.props.w),height:N(n.props.h)})}async toSvg(n){if(!n.props.assetId||!this.editor.getAsset(n.props.assetId))return null;let s=await this.editor.resolveAssetUrl(n.props.assetId,{shouldResolveToOriginal:!0});if(!s)return null;(s.startsWith("blob:")||s.startsWith("http")||s.startsWith("/")||s.startsWith("./"))&&(s=await Iq(s)||"");const o=kI(n),i=n.props.crop;if(o.transform&&i){const{transform:a,width:l,height:c}=o,u=(i.bottomRight.x-i.topLeft.x)*l,h=(i.bottomRight.y-i.topLeft.y)*c,p=[new b(0,0),new b(u,0),new b(u,h),new b(0,h)],f=`cropClipPath_${n.id.replace(":","_")}`;return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:f,children:d.jsx("polygon",{points:p.map(S=>`${S.x},${S.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${f})`,children:d.jsx("image",{href:s,width:l,height:c,style:{transform:a}})})]})}else return d.jsx("image",{href:s,width:n.props.w,height:n.props.h})}}g(cp,"type","image"),g(cp,"props",N_),g(cp,"migrations",F_);function kI(e){const t=e.props.crop,n=t==null?void 0:t.topLeft;if(!n)return{width:e.props.w,height:e.props.h};const r=1/(t.bottomRight.x-t.topLeft.x)*e.props.w,s=1/(t.bottomRight.y-t.topLeft.y)*e.props.h,o=-n.x*r,i=-n.y*s;return{transform:`translate(${o}px, ${i}px)`,width:r,height:s}}function NA(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function FA(e,t,n){const r=t.vertices,s=NA(n);return Cs(r,s)}function Eq(e,t,n){const r=NA(n);return dw(mg(FA(e,t,n),r),r)}function kq(e,t,n){const r=Eq(e,t,n);return o0(r)}function _q(e,t,n){if(e.props.dash==="draw"){const r=FA(e,t,n);return Vi(r)}return t.getSvgPathData()}function zA(e,t,n){let r=`M ${Te(t[0])}L`,s=`M ${Te(t[0])}L`;const o=n/3,i=n*2,a=qr(e);let l=t[0],c,u=t[0],h;const p=t.length;for(let f=0,S=p-1;f<S;f++){c=t[f+1],h=b.AddXY(t[f+1],a()*o,a()*o);const y=b.Sub(c,l),x=b.Len(y),m=b.Div(y,x).mul(Math.min(x/4,i)),v=b.Add(l,m),w=b.Add(c,m.neg()),C=b.Sub(h,u),E=b.Len(C),_=b.Div(C,E).mul(Math.min(E/4,i)),I=b.Add(u,_),k=b.Add(h,_.neg());f===S-1?(r+=`${Te(v)}L ${Te(c)}`,s+=`${Te(I)}L ${Te(h)}`):(r+=`${Te(v)}L ${Te(w)}Q ${Te(c)}`,s+=`${Te(I)}L ${Te(k)}Q ${Te(h)}`,l=c,u=h)}return[r,r+s]}const Tq=new Zs;class up extends Wr{constructor(){super(...arguments);g(this,"hideResizeHandles",()=>!0);g(this,"hideRotateHandle",()=>!0);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"hideSelectionBoundsBg",()=>!0);g(this,"onResize",(n,r)=>{const{scaleX:s,scaleY:o}=r;return{props:{points:Bu(n.props.points,(i,{id:a,index:l,x:c,y:u})=>({id:a,index:l,x:c*s,y:u*o}))}}});g(this,"onHandleDrag",(n,{handle:r})=>{if(r.type==="vertex")return{...n,props:{...n.props,points:{...n.props.points,[r.id]:{id:r.id,index:r.index,x:r.x,y:r.y}}}}})}getDefaultProps(){const[n,r]=su(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[n]:{id:n,index:n,x:0,y:0},[r]:{id:r,index:r,x:.1,y:.1}},scale:1}}getGeometry(n){return Tc(n)}getHandles(n){return Tq.get(n.props,()=>{const r=Tc(n),s=_c(n),o=s.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<s.length-1;i++){const a=ru(s[i].index,s[i+1].index),c=r.segments[i].midPoint();o.push({id:a,type:"create",index:a,x:c.x,y:c.y,canSnap:!0})}return o.sort(ln)})}component(n){return d.jsx(Zo,{id:n.id,children:d.jsx(_I,{shape:n})})}indicator(n){const r=jt[n.props.size]*n.props.scale,s=Tc(n),{dash:o}=n.props;let i;if(n.props.spline==="line"){const a=s.points;if(o==="solid"||o==="dotted"||o==="dashed")i="M"+a[0]+"L"+a.slice(1);else{const[l]=zA(n.id,a,r);i=l}}else i=_q(n,s,r);return d.jsx("path",{d:i})}toSvg(n){return d.jsx(_I,{shouldScale:!0,shape:n})}getHandleSnapGeometry(n){const r=_c(n);return{points:r,getSelfSnapPoints:s=>{const o=this.getHandles(n).filter(i=>i.type==="vertex").findIndex(i=>i.id===s.id);return r.filter((i,a)=>Math.abs(a-o)>1).map(b.From)},getSelfSnapOutline:s=>{const o=this.getHandles(n).filter(a=>a.type==="vertex").findIndex(a=>a.id===s.id),i=Tc(n).segments.filter((a,l)=>l!==o-1&&l!==o);return i.length?new Gr({children:i}):null}}}getInterpolatedProps(n,r,s){const o=_c(n),i=_c(r),a=[],l=[];let c=Zk;if(o.length>i.length)for(let u=0;u<o.length;u++)a[u]={...o[u]},i[u]===void 0?l[u]={...i[i.length-1],id:c}:l[u]={...i[u],id:c},c=zr(c);else if(i.length>o.length)for(let u=0;u<i.length;u++)l[u]={...i[u]},o[u]===void 0?a[u]={...o[o.length-1],id:c}:a[u]={...o[u],id:c},c=zr(c);else for(let u=0;u<i.length;u++)a[u]=o[u],l[u]=i[u];return{...r.props,points:Object.fromEntries(a.map((u,h)=>{const p=l[h];return[u.id,{...u,x:On(u.x,p.x,s),y:On(u.y,p.y,s)}]}))}}}g(up,"type","line"),g(up,"props",z_),g(up,"migrations",B_);function _c(e){return Object.values(e.props.points).sort(ln)}function Tc(e){const t=_c(e).map(b.From);switch(e.props.spline){case"cubic":return new QV({points:t});case"line":return new Ol({points:t})}}function _I({shape:e,shouldScale:t=!1}){const n=jr(),r=Tc(e),{dash:s,color:o,size:i}=e.props,a=1/e.props.scale,l=t?a:1,c=jt[i]*e.props.scale;if(e.props.spline==="line"){if(s==="solid"){const u=r.points,h="M"+u[0]+"L"+u.slice(1);return d.jsx("path",{d:h,stroke:n[o].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}if(s==="dashed"||s==="dotted")return d.jsx("g",{stroke:n[o].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((u,h)=>{const{strokeDasharray:p,strokeDashoffset:f}=as(u.length,c,{style:s,start:h>0?"outset":"none",end:h<r.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:p,strokeDashoffset:f,d:u.getSvgPathData(!0),fill:"none"},h)})});if(s==="draw"){const u=r.points,[h,p]=zA(e.id,u,c);return d.jsx("path",{d:p,stroke:n[o].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}}if(e.props.spline==="cubic"){const u=r.getSvgPathData();if(s==="solid")return d.jsx("path",{strokeWidth:c,stroke:n[o].solid,fill:"none",d:u,transform:`scale(${l})`});if(s==="dashed"||s==="dotted")return d.jsx("g",{stroke:n[o].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((h,p)=>{const{strokeDasharray:f,strokeDashoffset:S}=as(h.length,c,{style:s,start:p>0?"outset":"none",end:p<r.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:f,strokeDashoffset:S,d:h.getSvgPathData(),fill:"none"},p)})});if(s==="draw")return d.jsx("path",{d:kq(e,r,c),strokeWidth:1,stroke:n[o].solid,fill:n[o].solid,transform:`scale(${l})`})}}const BA=P.createContext(null);function Mq({assetUrls:e,children:t}){return P.useEffect(()=>{for(const n of Object.values(e.icons)){const r=ol();r.src=n,r.decode()}for(const n of Object.values(e.embedIcons)){const r=ol();r.src=n,r.decode()}},[e]),d.jsx(BA.Provider,{value:e,children:t})}function xw(){const e=P.useContext(BA);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const Bv={"action.convert-to-bookmark":"Convert to Bookmark","action.convert-to-embed":"Convert to Embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","action.export-as-json.short":"JSON","action.export-as-json":"Export as JSON","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-json.short":"JSON","action.export-all-as-json":"Export as JSON","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.fork-project-on-tldraw":"Fork project on tldraw","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.paste-error-title":"Pasting failed","action.paste-error-description":"Could not paste due to missing clipboard permissions. Please enable the permissions and try again.","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-paste-at-cursor.menu":"Paste at cursor","action.toggle-paste-at-cursor":"Toggle paste at cursor","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.size-too-big":"File size is too big","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","theme.dark":"Dark","theme.light":"Light","theme.system":"System","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","fill-style.fill":"Fill","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","menu.title":"Menu","menu.theme":"Theme","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.help":"Help","menu.view":"View","context-menu.edit":"Edit","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy editor link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About","help-menu.docs":"Documentation & API","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},Aq=new Set(["ar","fa","he","ur","ku"]),ya={locale:"en",label:"English",messages:Bv,dir:"ltr"};async function jq(e,t){if(!(await ws(t.translations.en)).ok)return console.warn("No main translations found."),ya;if(e==="en")return ya;const r=iu.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),ya;const o=await(await ws(t.translations[r.locale])).json();if(!o)return console.warn(`No messages found for locale ${e}`),ya;const i=[];for(const a in ya.messages)o[a]||i.push(a);return i.length>0,{locale:e,label:r.label,dir:Aq.has(r.locale)?"rtl":"ltr",messages:{...ya.messages,...o}}}const UA=P.createContext(null);function HA(){const e=P.useContext(UA);if(!e)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return e}const Oq=Lt(function({overrides:t,children:n}){const s=F().user.getLocale(),o=xw(),[i,a]=P.useState(()=>t&&t.en?{locale:"en",label:"English",dir:"ltr",messages:{...Bv,...t.en}}:{locale:"en",label:"English",dir:"ltr",messages:Bv});return P.useEffect(()=>{let l=!1;async function c(){const u=await jq(s,o);u&&!l&&(t&&t[s]?a({...u,messages:{...u.messages,...t[s]}}):a(u))}return c(),()=>{l=!0}},[o,s,t]),d.jsx(UA.Provider,{value:i,children:n})});function we(){const e=HA();return P.useCallback(function(n){return e.messages[n]??n},[e])}class dp extends Wr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"hideResizeHandles",()=>!0);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"onBeforeCreate",n=>TI(this.editor,n));g(this,"onBeforeUpdate",(n,r)=>{if(!(n.props.text===r.props.text&&n.props.font===r.props.font&&n.props.size===r.props.size))return TI(this.editor,r)});g(this,"onEditEnd",n=>{const{id:r,type:s,props:{text:o}}=n;o.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:o.trimEnd()}}])})}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(n){const{labelHeight:r,labelWidth:s}=KA(this.editor,n),{scale:o}=n.props,i=r*o,a=s*o,l=Be*o,c=ch(n);return new Gr({children:[new ro({width:l,height:c,isFilled:!0}),new ro({x:n.props.align==="start"?0:n.props.align==="end"?l-a:(l-a)/2,y:n.props.verticalAlign==="start"?0:n.props.verticalAlign==="end"?c-i:(c-i)/2,width:a,height:i,isFilled:!0,isLabel:!0})]})}getHandles(n){const{scale:r}=n.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const o=this.editor.getZoomLevel();if(o*r<.25)return[];const i=ch(n),a=Be*r,l=iX/o*r;return o*r<.5?[{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l}]:[{id:"top",index:"a1",type:"clone",x:a/2,y:-l},{id:"right",index:"a2",type:"clone",x:a+l,y:i/2},{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l},{id:"left",index:"a4",type:"clone",x:-l,y:i/2}]}component(n){const{id:r,type:s,props:{scale:o,color:i,font:a,size:l,align:c,text:u,verticalAlign:h,fontSizeAdjustment:p}}=n,f=Lq(r),S=jr(),y=Be*o,x=ch(n),m=K("shape rotation",()=>{var C;return((C=this.editor.getShapePageTransform(r))==null?void 0:C.rotation())??0},[this.editor]),v=K("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),w=n.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:r,className:"tl-note__container",style:{width:y,height:x,backgroundColor:S[i].note.fill,borderBottom:v?`${3*o}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:v?"none":$q(n.id,m,o)},children:d.jsx(xg,{id:r,type:s,font:a,fontSize:(p||Xs[l])*o,lineHeight:Vt.lineHeight,align:c,verticalAlign:h,text:u,isNote:!0,isSelected:w,labelColor:S[i].note.text,wrap:!0,padding:16*o,onKeyDown:f})}),"url"in n.props&&n.props.url&&d.jsx(yl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){const{scale:r}=n.props;return d.jsx("rect",{rx:r,width:N(Be*r),height:N(ch(n))})}toSvg(n,r){n.props.text&&r.addExportDef(Sg(n.props.font));const s=lo({isDarkMode:r.isDarkMode}),o=Nq(n);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:Be-10,height:o.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:Be,height:o.h,fill:s[n.props.color].note.fill}),d.jsx(vg,{fontSize:n.props.fontSizeAdjustment||Xs[n.props.size],font:n.props.font,align:n.props.align,verticalAlign:n.props.verticalAlign,text:n.props.text,labelColor:s[n.props.color].note.text,bounds:o,stroke:!1})]})}}g(dp,"type","note"),g(dp,"props",U_),g(dp,"migrations",H_);function TI(e,t){const{labelHeight:n,fontSizeAdjustment:r}=KA(e,t),s=Math.max(0,n-Be);if(s!==t.props.growY||r!==t.props.fontSizeAdjustment)return{...t,props:{...t.props,growY:s,fontSizeAdjustment:r}}}function Dq(e,t){const{text:n}=t.props;if(!n)return{labelHeight:Xs[t.props.size]*Vt.lineHeight+vr*2,labelWidth:100,fontSizeAdjustment:0};const r=Xs[t.props.size];let s=0,o=0,i=Be,a=Be;const l=1;do{s=Math.min(r,r-o);const c=e.textMeasure.measureText(n,{...Vt,fontFamily:xs[t.props.font],fontSize:s,maxWidth:Be-vr*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+vr*2,a=c.w+vr*2,s<=14){const u=e.textMeasure.measureText(n,{...Vt,fontFamily:xs[t.props.font],fontSize:s,maxWidth:Be-vr*2-l});i=u.h+vr*2,a=u.w+vr*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(o++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:s}}const Rq=new Zs;function KA(e,t){return Rq.get(t,()=>Dq(e,t))}function Lq(e){const t=F(),n=HA();return P.useCallback(r=>{const s=t.getShape(e);if(!s)return;const o=r.key==="Tab",i=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(o||i){r.preventDefault();const a=t.getShapePageTransform(e),l=a.rotation(),c=!!(n.dir==="rtl"||gA(s.props.text)),u=(Be+t.options.adjacentShapeMargin+(i&&!r.shiftKey?s.props.growY:0))*s.props.scale,h=new b(o?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(yg.clone().mul(s.props.scale)).rot(l).add(a.point()),p=PA(t,s,h,l);p&&(t.mark("editing adjacent shape"),xf(t,p,!0))}},[e,t,n.dir])}function ch(e){return(Be+e.props.growY)*e.props.scale}function $q(e,t,n){const r=qr(e),s=Math.abs(r())+.5,o=Math.cos(t),i=5*n,a=4*n,l=6*n,c=7*n;return`0px ${i-s}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
219
|
-
0px ${(a+s*c)*Math.max(0,o)}px ${l+s*c}px -${a+s*l}px rgba(15, 23, 31, ${(.3+s*.1).toFixed(2)}),
|
|
220
|
-
0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+o)/2)).toFixed(2)})`}function Nq(e){return new Q(0,0,Be,Be+e.props.growY)}function Fq(e,{initialBounds:t,scaleX:n,scaleY:r,newPoint:s}){const o=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new b(0,0);n<0&&(i.x=-(t.width*o)),r<0&&(i.y=-(t.height*o));const{x:a,y:l}=b.Add(s,i.rot(e.rotation));return{x:a,y:l,props:{scale:o*e.props.scale}}}const zq=new Zs;class hp extends Wr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"isAspectRatioLocked",()=>!0);g(this,"onResize",(n,r)=>{const{newPoint:s,initialBounds:o,initialShape:i,scaleX:a,handle:l}=r;if(r.mode==="scale_shape"||l!=="right"&&l!=="left")return{id:n.id,type:n.type,...Fq(n,r)};{const c=Math.max(1,Math.abs(o.width*a)),{x:u,y:h}=a<0?b.Sub(s,b.FromAngle(n.rotation).mul(c)):s;return{id:n.id,type:n.type,x:u,y:h,props:{w:c/i.props.scale,autoSize:!1}}}});g(this,"onEditEnd",n=>{const{id:r,type:s,props:{text:o}}=n,i=n.props.text.trimEnd();i.length===0?this.editor.deleteShapes([n.id]):i!==n.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:o.trimEnd()}}])});g(this,"onBeforeUpdate",(n,r)=>{if(!r.props.autoSize)return;const s=n.props.size!==r.props.size||n.props.textAlign!==r.props.textAlign||n.props.font!==r.props.font||n.props.scale!==1&&r.props.scale===1,o=n.props.text!==r.props.text;if(!s&&!o)return;const i=this.getMinDimensions(n),a=MI(this.editor,r.props),l=i.width*n.props.scale,c=i.height*n.props.scale,u=a.width*r.props.scale,h=a.height*r.props.scale;let p;switch(r.props.textAlign){case"middle":{p=new b((u-l)/2,o?0:(h-c)/2);break}case"end":{p=new b(u-l,o?0:(h-c)/2);break}default:{if(o)break;p=new b(0,(h-c)/2);break}}if(p){p.rot(r.rotation);const{x:f,y:S}=r;return{...r,x:f-p.x,y:S-p.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(n){return zq.get(n.props,r=>MI(this.editor,r))}getGeometry(n){const{scale:r}=n.props,{width:s,height:o}=this.getMinDimensions(n);return new ro({width:s*r,height:o*r,isFilled:!0,isLabel:!0})}component(n){const{id:r,props:{font:s,size:o,text:i,color:a,scale:l,textAlign:c}}=n,{width:u,height:h}=this.getMinDimensions(n),p=n.id===this.editor.getOnlySelectedShapeId(),f=jr(),S=Bq(r);return d.jsx(xg,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:s,fontSize:gl[o],lineHeight:Vt.lineHeight,align:c,verticalAlign:"middle",text:i,labelColor:f[a].solid,isSelected:p,textWidth:u,textHeight:h,style:{transform:`scale(${l})`,transformOrigin:"top left"},wrap:!0,onKeyDown:S})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds,s=F();return n.props.autoSize&&s.getEditingShapeId()===n.id?null:d.jsx("rect",{width:N(r.width),height:N(r.height)})}toSvg(n,r){n.props.text&&r.addExportDef(Sg(n.props.font));const s=this.editor.getShapeGeometry(n).bounds,o=s.width/(n.props.scale??1),i=s.height/(n.props.scale??1),a=lo(r);return d.jsx(vg,{fontSize:gl[n.props.size],font:n.props.font,align:n.props.textAlign,verticalAlign:"middle",text:n.props.text,labelColor:a[n.props.color].solid,bounds:new Q(0,0,o,i),padding:0})}}g(hp,"type","text"),g(hp,"props",K_),g(hp,"migrations",W_);function MI(e,t){const{font:n,text:r,autoSize:s,size:o,w:i}=t,a=s?16:Math.max(16,i),l=gl[o],c=s?null:Math.floor(Math.max(a,i)),u=e.textMeasure.measureText(r,{...Vt,fontFamily:xs[n],fontSize:l,maxWidth:c});return s&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function Bq(e){const t=F();return P.useCallback(n=>{if(t.getEditingShapeId()===e)switch(n.key){case"Enter":{(n.ctrlKey||n.metaKey)&&t.complete();break}case"Tab":{Ee(n),n.shiftKey?ml.unindent(n.currentTarget):ml.indent(n.currentTarget);break}}},[t,e])}class pp extends Dl{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"isAspectRatioLocked",()=>!0)}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(n){const{editor:r}=this,s=r.getShapeGeometry(n).bounds.w*r.getZoomLevel()>=110,{asset:o,url:i}=LA(n.id,n.props.assetId,n.props.w),{time:a,playing:l}=n.props,c=gg(n.id),u=$A(),h=P.useRef(null),p=P.useCallback(v=>{const w=v.currentTarget;w&&r.updateShapes([{type:"video",id:n.id,props:{playing:!0,time:w.currentTime}}])},[n.id,r]),f=P.useCallback(v=>{const w=v.currentTarget;w&&r.updateShapes([{type:"video",id:n.id,props:{playing:!1,time:w.currentTime}}])},[n.id,r]),S=P.useCallback(v=>{const w=v.currentTarget;w&&c&&r.updateShapes([{type:"video",id:n.id,props:{time:w.currentTime}}])},[c,n.id,r]),[y,x]=P.useState(!1),m=P.useCallback(v=>{const w=v.currentTarget;w&&(a!==w.currentTime&&(w.currentTime=a),l||w.pause(),x(!0))},[l,a]);return P.useEffect(()=>{const v=h.current;v&&(y&&!c&&a!==v.currentTime&&(v.currentTime=a),c&&document.activeElement!==v&&v.focus())},[c,y,a]),P.useEffect(()=>{if(u){const v=h.current;if(!v)return;v.pause(),v.currentTime=0}},[h,u]),d.jsxs(d.Fragment,{children:[d.jsx(Gi,{id:n.id,style:{color:"var(--color-text-3)",backgroundColor:o?"transparent":"var(--color-low)",border:o?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:o!=null&&o.props.src?i?d.jsx("video",{ref:h,style:c?{pointerEvents:"all"}:void 0,className:`tl-video tl-video-shape-${n.id.split(":")[1]}`,width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:c&&s,onPlay:p,onPause:f,onTimeUpdate:S,onLoadedData:m,hidden:!y,children:d.jsx("source",{src:i})}):null:d.jsx(RA,{})})})}),"url"in n.props&&n.props.url&&d.jsx(yl,{url:n.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(n){return d.jsx("rect",{width:N(n.props.w),height:N(n.props.h)})}toSvg(n){return d.jsx("image",{href:Uq(n.id),width:n.props.w,height:n.props.h})}}g(pp,"type","video"),g(pp,"props",G_),g(pp,"migrations",V_);function Uq(e){const t=e.split(":")[1],n=document.querySelector(`.tl-video-shape-${t}`);if(n){const r=document.createElement("canvas");return r.width=n.videoWidth,r.height=n.videoHeight,r.getContext("2d").drawImage(n,0,0),r.toDataURL("image/png")}else throw new Error("Video with not found when attempting serialization.")}const WA=[hp,rp,sp,ap,dp,up,ip,np,lp,op,cp,pp];function Hq(e){return e.sideEffects.register({instance_page_state:{afterChange:(t,n)=>{if(t.croppingShapeId!==n.croppingShapeId){const r=e.isIn("select.crop");!t.croppingShapeId&&n.croppingShapeId?r||e.setCurrentTool("select.crop.idle"):t.croppingShapeId&&!n.croppingShapeId&&r&&e.setCurrentTool("select.idle")}t.editingShapeId!==n.editingShapeId&&(!t.editingShapeId&&n.editingShapeId?e.isIn("select.editing_shape")||e.setCurrentTool("select.editing_shape"):t.editingShapeId&&!n.editingShapeId&&e.isIn("select.editing_shape")&&e.setCurrentTool("select.idle"))}}})}class GA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"scribbleId","id");g(this,"markId","");g(this,"excludedShapeIds",new Set);g(this,"onEnter",n=>{this.markId="erase scribble begin",this.editor.mark(this.markId),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(o=>{if(this.editor.isShapeOrAncestorLocked(o))return!0;if(this.editor.isShapeOfType(o,"group")||this.editor.isShapeOfType(o,"frame")){const i=this.editor.getPointInShapeSpace(o,r);return this.editor.getShapeGeometry(o).bounds.containsPoint(i)}return!1}).map(o=>o.id));const s=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=s.id,this.update()});g(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()})}update(){const{editor:n,excludedShapeIds:r}=this,s=n.getErasingShapeIds(),o=n.getZoomLevel(),i=n.getCurrentPageShapes(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=n;this.pushPointToScribble();const c=new Set(s),u=this.editor.options.hitTestMargin/o;for(const h of i){if(n.isShapeOfType(h,"group"))continue;const p=n.getShapeMask(h.id);if(p&&!or(a,p))continue;const f=n.getShapeGeometry(h),S=n.getShapePageTransform(h);if(!f||!S)continue;const y=S.clone().invert(),x=y.applyToPoint(l),m=y.applyToPoint(a),{bounds:v}=f;v.minX-u>Math.max(x.x,m.x)||v.minY-u>Math.max(x.y,m.y)||v.maxX+u<Math.min(x.x,m.x)||v.maxY+u<Math.min(x.y,m.y)||f.hitTestLineSegment(x,m,u)&&c.add(n.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),n.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.setErasingShapes([]),n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}g(GA,"id","erasing");var Zy;let Kq=(Zy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Zy,"id","idle"),Zy);var Qy;let Wq=(Qy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{const n=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapesSorted(),{inputs:{currentPagePoint:s}}=this.editor,o=new Set,i=o.size;for(let a=r.length,l=a-1;l>=0;l--){const c=r[l];if(!(this.editor.isShapeOrAncestorLocked(c)||this.editor.isShapeOfType(c,"group"))&&this.editor.isPointInShape(c,s,{hitInside:!1,margin:this.editor.options.hitTestMargin/n})){const u=this.editor.getOutermostSelectableShape(c);if(this.editor.isShapeOfType(u,"frame")&&o.size>i)break;o.add(u.id)}}this.editor.setErasingShapes([...o])});g(this,"onLongPress",n=>{this.startErasing(n)});g(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startErasing(n)});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()})}startErasing(n){this.parent.transition("erasing",n)}complete(){const n=this.editor.getErasingShapeIds();n.length&&(this.editor.mark("erase end"),this.editor.deleteShapes(n)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},g(Qy,"id","pointing"),Qy);class Mc extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(Mc,"id","eraser"),g(Mc,"initial","idle"),g(Mc,"isLockable",!1),g(Mc,"children",()=>[Kq,Wq,GA]);class VA extends se{constructor(){super(...arguments);g(this,"initialCamera",new b);g(this,"onEnter",()=>{this.initialCamera=b.From(this.editor.getCamera()),this.update()});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.parent.transition("idle")});g(this,"onComplete",()=>{this.complete()})}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:s,originScreenPoint:o}=r.inputs,i=b.Sub(s,o).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,s=Math.min(r.len(),2);s>.1&&this.editor.slideCamera({speed:s,direction:r}),this.parent.transition("idle")}}g(VA,"id","dragging");var Jy;let Gq=(Jy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});g(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Jy,"id","idle"),Jy);var eS;let Vq=(eS=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})});g(this,"onLongPress",()=>{this.startDragging()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startDragging()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.complete()})}startDragging(){this.parent.transition("dragging")}complete(){this.parent.transition("idle")}},g(eS,"id","pointing"),eS);class Ac extends se{constructor(){super(...arguments);g(this,"onDoubleClick",n=>{if(n.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{animation:{duration:220,easing:At.easeOutQuint}})}});g(this,"onTripleClick",n=>{if(n.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{animation:{duration:320,easing:At.easeOutQuint}})}});g(this,"onQuadrupleClick",n=>{if(n.phase==="settle"){const r=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:s}}=this.editor;r===1?this.editor.zoomToFit({animation:{duration:400,easing:At.easeOutQuint}}):this.editor.resetZoom(s,{animation:{duration:320,easing:At.easeOutQuint}})}})}}g(Ac,"id","hand"),g(Ac,"initial","idle"),g(Ac,"isLockable",!1),g(Ac,"children",()=>[Gq,Vq,VA]);var tS;let Yq=(tS=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",n=>{this.parent.transition("lasering",n)})}},g(tS,"id","idle"),tS);class YA extends se{constructor(){super(...arguments);g(this,"scribbleId","id");g(this,"onEnter",()=>{const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:1200,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.pushPointToScribble()});g(this,"onPointerUp",()=>{this.complete()});g(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}g(YA,"id","lasering");class jc extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(jc,"id","laser"),g(jc,"initial","idle"),g(jc,"children",()=>[Yq,YA]),g(jc,"isLockable",!1);class XA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"initialSelectedShapeIds",[]);g(this,"excludedShapeIds",new Set);g(this,"isWrapMode",!1);g(this,"initialStartShape",null);g(this,"onEnter",n=>{const{altKey:r,currentPagePoint:s}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",n);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(o=>this.editor.isShapeOfType(o,"group")||this.editor.isShapeOrAncestorLocked(o)).map(o=>o.id)),this.info=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(s)[0],this.hitTestShapes()});g(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});g(this,"onTick",({elapsed:n})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)});g(this,"onPointerMove",()=>{this.hitTestShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",n=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",n)});g(this,"onKeyDown",n=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",n):this.hitTestShapes()});g(this,"onKeyUp",()=>{this.hitTestShapes()});g(this,"onInterrupt",()=>{this.editor.updateInstanceState({brush:null})})}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:n,excludedShapeIds:r,isWrapMode:s}=this,{inputs:{originPagePoint:o,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=n,c=new Set(a?this.initialSelectedShapeIds:[]),u=s?!l:l,h=Q.FromPoints([o,i]),{corners:p}=h;let f,S,y,x,m,v;const w=n.getCurrentPageShapes(),C=n.getCurrentPageId();e:for(let I=0,k=w.length;I<k;I++){if(y=w[I],r.has(y.id)||c.has(y.id)||(x=n.getShapePageBounds(y),!x))continue e;if(h.contains(x)){this.handleHit(y,i,C,c,p);continue e}if(u||n.isShapeOfType(y,"frame"))continue e;if(h.collides(x)){if(m=n.getShapePageTransform(y),!m)continue e;v=m.clone().invert().applyToPoints(p);const T=n.getShapeGeometry(y);t:for(let M=0;M<4;M++)if(f=v[M],S=v[(M+1)%4],T.hitTestLineSegment(f,S,0)){this.handleHit(y,i,C,c,p);break t}}}n.getInstanceState().isCoarsePointer;const E=n.getInstanceState().brush;(!E||!h.equals(E))&&n.updateInstanceState({brush:{...h.toJson()}});const _=n.getSelectedShapeIds();(_.length!==c.size||_.some(I=>!c.has(I)))&&n.setSelectedShapes(Array.from(c))}handleHit(n,r,s,o,i){if(n.parentId===s){o.add(n.id);return}const a=this.editor.getOutermostSelectableShape(n),l=this.editor.getShapeMask(a.id);l&&!UM(l,i)&&!or(r,l)||o.add(a.id)}}g(XA,"id","brushing");const vl={bottom:"ns-resize",top:"ns-resize",left:"ew-resize",right:"ew-resize",bottom_left:"nesw-resize",bottom_right:"nwse-resize",top_left:"nwse-resize",top_right:"nesw-resize",bottom_left_rotate:"swne-rotate",bottom_right_rotate:"senw-rotate",top_left_rotate:"nwse-rotate",top_right_rotate:"nesw-rotate",mobile_rotate:"grabbing"};class qA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.info=n,this.updateCursor()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startResizing()});g(this,"onLongPress",()=>{this.startResizing()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const n=this.editor.getSelectedShapes(),r=vl[this.info.handle];this.editor.setCursor({type:r,rotation:n.length===1?this.editor.getSelectionRotation():0})}startResizing(){this.editor.getInstanceState().isReadonly||this.parent.transition("resizing",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}g(qA,"id","pointing_resize_handle");const yr=8;class ww extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","");g(this,"snapshot",{});g(this,"onEnter",n=>{this.info=n,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"getDefaultCrop",()=>({topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}))}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=vl[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}updateShapes(){const{shape:n,cursorHandleOffset:r}=this.snapshot;if(!n||!this.editor.getShapeUtil("image"))return;const o=n.props,i=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),l=i.clone().sub(a).rot(-n.rotation),c=o.crop??this.getDefaultCrop(),u=Ge(c),h=new b(n.x,n.y),p=new b(0,0),f=1/(c.bottomRight.x-c.topLeft.x)*o.w,S=1/(c.bottomRight.y-c.topLeft.y)*o.h;let y=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(S<yr)break;y=!0,u.topLeft.y=u.topLeft.y+l.y/S,S*(u.bottomRight.y-u.topLeft.y)<yr?(u.topLeft.y=u.bottomRight.y-yr/S,p.y=(u.topLeft.y-c.topLeft.y)*S):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-c.topLeft.y)*S):p.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(S<yr)break;y=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/S),S*(u.bottomRight.y-u.topLeft.y)<yr&&(u.bottomRight.y=u.topLeft.y+yr/S);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<yr)break;y=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<yr?(u.topLeft.x=u.bottomRight.x-yr/f,p.x=(u.topLeft.x-c.topLeft.x)*f):u.topLeft.x<=0?(u.topLeft.x=0,p.x=(u.topLeft.x-c.topLeft.x)*f):p.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(f<yr)break;y=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<yr&&(u.bottomRight.x=u.topLeft.x+yr/f);break}}if(!y)return;h.add(p.rot(n.rotation));const x={id:n.id,type:n.type,x:h.x,y:h.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*f,h:(u.bottomRight.y-u.topLeft.y)*S}};this.editor.updateShapes([x]),this.updateCursor()}complete(){this.updateShapes(),Ke(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const n=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,s=this.editor.getOnlySelectedShape(),o=this.editor.getSelectionRotatedPageBounds(),i=b.RotWith(o.getHandlePoint(this.info.handle),o.point,n),a=b.Sub(r,i);return{shape:s,cursorHandleOffset:a}}}g(ww,"id","cropping");function ZA(e,t=!1){const n=e.getZoomLevel(),{inputs:{currentPagePoint:r}}=e;return e.getShapeAtPoint(r,{hitInside:!1,hitLabels:t,margin:e.options.hitTestMargin/n,renderingOnly:!0})??e.getSelectedShapeAtPoint(r)}function QA(e,t,n){if(!t)throw Error("Needs to translate a cropped shape!");const{crop:r}=t.props;if(!r)return;const s=e.inputs.shiftKey?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;s==="x"?n.x=0:s==="y"&&(n.y=0),n.rot(-t.rotation);const o=1/(r.bottomRight.x-r.topLeft.x)*t.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*t.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=Ge(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-n.x/o)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-n.y/i)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:t.id,type:t.type,props:{crop:c}}}var nS;let Xq=(nS=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"default",rotation:0});const n=this.editor.getOnlySelectedShape();n&&this.editor.setCroppingShape(n.id)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});g(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});g(this,"onPointerDown",n=>{var r;if(!this.editor.getIsMenuOpen()){if(n.ctrlKey){this.cancel(),this.editor.root.handleEvent(n);return}switch(n.target){case"canvas":{const s=ZA(this.editor);if(s&&!this.editor.isShapeOfType(s,"group")){this.onPointerDown({...n,shape:s,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(n);break}case"shape":{if(n.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",n);return}else(r=this.editor.getShapeUtil(n.shape))!=null&&r.canCrop(n.shape)?(this.editor.setCroppingShape(n.shape.id),this.editor.setSelectedShapes([n.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",n)):(this.cancel(),this.editor.root.handleEvent(n));break}case"selection":{switch(n.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...n,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...n,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}});g(this,"onDoubleClick",n=>{var i;if(this.editor.inputs.shiftKey||n.phase!=="up")return;const r=this.editor.getCroppingShapeId();if(!r)return;const s=this.editor.getShape(r);if(!s)return;const o=this.editor.getShapeUtil(s);if(o){if(n.target==="selection"){(i=o.onDoubleClickEdge)==null||i.call(o,s);return}this.cancel(),this.editor.root.handleEvent(n)}});g(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});g(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});g(this,"onKeyUp",n=>{switch(n.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}})}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(n=!1){const{editor:{inputs:{keys:r}}}=this,s=r.has("ShiftLeft"),o=new b(0,0);if(r.has("ArrowLeft")&&(o.x+=1),r.has("ArrowRight")&&(o.x-=1),r.has("ArrowUp")&&(o.y+=1),r.has("ArrowDown")&&(o.y-=1),o.equals(new b(0,0)))return;s&&o.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=QA(this.editor,i,o);a&&(n||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},g(nS,"id","idle"),nS);class JA extends se{constructor(){super(...arguments);g(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});g(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",n)});g(this,"onPointerUp",n=>{this.editor.setCurrentTool("select.crop.idle",n)})}}g(JA,"id","pointing_crop");class bw extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const s=vl[this.info.handle];this.editor.setCursor({type:s,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startCropping()});g(this,"onLongPress",()=>{this.startCropping()});g(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startCropping(){this.editor.getInstanceState().isReadonly||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}g(bw,"id","pointing_crop_handle");class ej extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","translating crop");g(this,"snapshot",{});g(this,"onEnter",n=>{this.info=n,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onKeyDown",n=>{switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}});g(this,"onKeyUp",n=>{switch(n.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}})}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const n=this.snapshot.shape;if(!n)return;const{originPagePoint:r,currentPagePoint:s}=this.editor.inputs,o=s.clone().sub(r),i=QA(this.editor,n,o);i&&this.editor.updateShapes([i])}}g(ej,"id","translating_crop");class fp extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"onEnter",()=>{this.didCancel=!1,this.markId="crop",this.editor.mark(this.markId)});g(this,"didCancel",!1);g(this,"onExit",()=>{this.didCancel?this.editor.bailToMark(this.markId):this.editor.squashToMark(this.markId)});g(this,"onCancel",()=>{this.didCancel=!0})}}g(fp,"id","crop"),g(fp,"initial","idle"),g(fp,"children",()=>[Xq,ej,JA,bw,ww]);class tj extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"initialHandle",{});g(this,"initialAdjacentHandle",null);g(this,"initialPagePoint",{});g(this,"markId","");g(this,"initialPageTransform");g(this,"initialPageRotation");g(this,"info",{});g(this,"isPrecise",!1);g(this,"isPreciseId",null);g(this,"pointingId",null);g(this,"onEnter",n=>{const{shape:r,isCreating:s,handle:o}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId=s?`creating:${r.id}`:"dragging handle",s||this.editor.mark(this.markId),this.initialHandle=Ge(o),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[o.index]:{id:o.index,index:o.index,x:o.x,y:o.y}}}});const c=this.editor.getShapeHandles(r).find(u=>u.index===o.index);this.initialHandle=Ge(c)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.setCursor({type:s?"cross":"grabbing",rotation:0});const i=this.editor.getShapeHandles(r).sort(ln),a=i.findIndex(l=>l.id===n.handle.id);this.initialAdjacentHandle=null;for(let l=a+1;l<i.length;l++){const c=i[l];if(c.type==="vertex"&&c.id!=="middle"&&c.id!==n.handle.id){this.initialAdjacentHandle=c;break}}if(!this.initialAdjacentHandle)for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="vertex"&&c.id!=="middle"&&c.id!==n.handle.id){this.initialAdjacentHandle=c;break}}if(this.editor.isShapeOfType(r,"arrow")){const l=Ln(this.editor,r)[n.handle.id];this.isPrecise=!1,l?(this.editor.setHintingShapes([l.toId]),this.isPrecise=l.props.isPrecise,this.isPrecise?this.isPreciseId=l.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)});g(this,"exactTimeout",-1);g(this,"onPointerMove",()=>{this.update()});g(this,"onKeyDown",()=>{this.update()});g(this,"onKeyUp",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.update(),this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})})}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clearIndicators(),Ke(this.editor,[this.shapeId]);const{onInteractionEnd:n}=this.info;if(this.editor.getInstanceState().isToolLocked&&n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:n}=this.info;if(n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var I;const{editor:n,shapeId:r,initialPagePoint:s}=this,{initialHandle:o,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:h,shiftKey:p,ctrlKey:f,altKey:S,pointerVelocity:y}}=n,x=this.info.shape,m=n.getShape(r);if(!m)return;const v=n.getShapeUtil(m);let w=h.clone().sub(s).rot(-i).add(o);if(p&&a&&o.id!=="middle"){const k=b.Angle(a,w),M=Bp(k,24)-k;w=b.RotWith(w,a,M)}n.snaps.clearIndicators();let C={...o,x:w.x,y:w.y};if(o.canSnap&&(c?!f:f)){if(!n.getShapePageTransform(m.id))throw Error("Expected a page transform");const T=u.handles.snapHandle({currentShapeId:r,handle:C});T&&(T.nudge.rot(-n.getShapeParentTransform(m).rotation()),w.add(T.nudge),C={...o,x:w.x,y:w.y})}const E=(I=v.onHandleDrag)==null?void 0:I.call(v,m,{handle:C,isPrecise:this.isPrecise||S,initial:x}),_={id:m.id,type:m.type,...E};if(o.type==="vertex"&&this.editor.isShapeOfType(m,"arrow")){const k=Ln(n,m)[o.id];k?l[0]!==k.toId&&(n.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=y.len()<.5||S,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}E&&n.updateShapes([_])}}g(tj,"id","dragging_handle");function nj(e){return e.isLabel?[e]:e instanceof Gr?e.children.filter(t=>t.isLabel):[]}class rj extends se{constructor(){super(...arguments);g(this,"hitShapeForPointerUp",null);g(this,"onEnter",()=>{const n=this.editor.getEditingShape();if(!n)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,Ws(this.editor),this.editor.select(n)});g(this,"onExit",()=>{var o;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),Ws.cancel();const r=this.editor.getShape(n),s=this.editor.getShapeUtil(r);(o=s.onEditEnd)==null||o.call(s,r)});g(this,"onPointerMove",n=>{if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly||this.hitShapeForPointerUp.isLocked)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",n),this.hitShapeForPointerUp=null;return}switch(n.target){case"shape":case"canvas":{Ws(this.editor);return}}});g(this,"onPointerDown",n=>{switch(this.hitShapeForPointerUp=null,n.target){case"shape":{const{shape:r}=n,s=this.editor.getEditingShape();if(!s)throw Error("Expected an editing shape!");const o=this.editor.getShapeUtil(r).getGeometry(r),i=nj(o),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(s,"text")&&s.props.text.trim()==="";if(a&&!l){const c=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(c,0)&&a.hitTestPoint(c)){if(r.id===s.id)return;this.hitShapeForPointerUp=r,this.editor.mark("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===s.id)this.editor.isShapeOfType(r,"frame")&&(this.editor.setEditingShape(null),this.parent.transition("idle",n));else{this.parent.transition("pointing_shape",n);return}return}break}}this.parent.transition("idle",n),this.editor.root.handleEvent(n)});g(this,"onPointerUp",n=>{const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const s=this.editor.getShapeUtil(r);if(!r.isLocked){if(this.editor.getInstanceState().isReadonly&&!s.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),Ws(this.editor)}});g(this,"onComplete",n=>{this.parent.transition("idle",n)});g(this,"onCancel",n=>{this.parent.transition("idle",n)})}}g(rj,"id","editing_shape");function AI(e){const t=e.getOnlySelectedShape();return!!(t&&!e.isShapeOrAncestorLocked(t)&&e.getShapeUtil(t).canCrop(t))}function Pf(e){const t=e.getSelectedShapeIds(),{shiftKey:n,altKey:r,currentPagePoint:s}=e.inputs,o=e.getShapeAtPoint(s,{hitInside:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:i=>!i.isLocked});if(o){const i=e.getOutermostSelectableShape(o);if(n&&!r)e.cancelDoubleClick(),t.includes(i.id)?(e.mark("deselecting shape"),e.deselect(i)):(e.mark("shift selecting shape"),e.setSelectedShapes([...t,i.id]));else{let a;i===o||i.id===e.getFocusedGroupId()||t.includes(i.id)?a=o:a=i,a&&!t.includes(a.id)&&(e.mark("selecting shape"),e.select(a.id))}}else{if(n)return;{t.length>0&&(e.mark("selecting none"),e.selectNone());const i=e.getFocusedGroupId();if(jn(i)){const a=e.getShape(i);e.isPointInShape(a,s,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const qq=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var rS;let Zq=(rS=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Ws(this.editor),this.editor.setCursor({type:"default",rotation:0})});g(this,"onExit",()=>{Ws.cancel()});g(this,"onPointerMove",()=>{Ws(this.editor)});g(this,"onPointerDown",n=>{if(this.editor.getIsMenuOpen())return;const r=n.ctrlKey&&AI(this.editor);if(n.ctrlKey&&!r){if(n.target==="shape"&&this.isDarwin&&this.editor.inputs.keys.has("ControlLeft")&&!this.editor.isShapeOrAncestorLocked(n.shape)){this.parent.transition("pointing_shape",n);return}this.parent.transition("brushing",n);return}switch(n.target){case"canvas":{const s=ZA(this.editor);if(s&&!s.isLocked){this.onPointerDown({...n,shape:s,target:"shape"});return}const o=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((o.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&jI(this.editor,a)){this.onPointerDown({...n,target:"selection"});return}this.parent.transition("pointing_canvas",n);break}case"shape":{const{shape:s}=n;if(this.isOverArrowLabelTest(s)){this.parent.transition("pointing_arrow_label",n);break}if(this.editor.isShapeOrAncestorLocked(s)){this.parent.transition("pointing_canvas",n);break}this.parent.transition("pointing_shape",n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",n):this.parent.transition("pointing_handle",n);break}case"selection":{switch(n.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",n);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("crop.pointing_crop_handle",n):this.parent.transition("pointing_resize_handle",n);break}default:{const s=this.editor.getHoveredShape();if(s&&!this.editor.getSelectedShapeIds().includes(s.id)&&!s.isLocked){this.onPointerDown({...n,shape:s,target:"shape"});return}this.parent.transition("pointing_selection",n)}}break}}});g(this,"onDoubleClick",n=>{var r,s,o,i;if(!(this.editor.inputs.shiftKey||n.phase!=="up"))switch(n.target){case"canvas":{const a=this.editor.getHoveredShape(),l=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),c=this.editor.getFocusedGroupId();if(l){if(this.editor.isShapeOfType(l,"group")){Pf(this.editor);return}else{const u=this.editor.getShape(l.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(c&&u.id===c)){Pf(this.editor);return}}this.onDoubleClick({...n,shape:l,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(n);break}case"selection":{if(this.editor.getInstanceState().isReadonly)break;const a=this.editor.getOnlySelectedShape();if(a){const l=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(n.handle==="right"||n.handle==="left"||n.handle==="top"||n.handle==="bottom"){const c=(r=l.onDoubleClickEdge)==null?void 0:r.call(l,a);if(c){this.editor.mark("double click edge"),this.editor.updateShapes([c]),Ke(this.editor,[a.id]);return}}if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",n);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,n,!0)}break}case"shape":{const{shape:a}=n,l=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(l.onDoubleClick){const c=(s=l.onDoubleClick)==null?void 0:s.call(l,a);if(c){this.editor.updateShapes([c]);return}else if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.mark("select and crop"),this.editor.select((o=n.shape)==null?void 0:o.id),this.parent.transition("crop",n);return}}this.shouldStartEditingShape(a)?this.startEditingShape(a,n,!0):this.handleDoubleClickOnCanvas(n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:l}=n,c=this.editor.getShapeUtil(a),u=(i=c.onDoubleClickHandle)==null?void 0:i.call(c,a,l);u?this.editor.updateShapes([u]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,n,!0)}}});g(this,"onRightClick",n=>{switch(n.target){case"canvas":{const r=this.editor.getHoveredShape(),s=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!1,renderingOnly:!0});if(s){this.onRightClick({...n,shape:s,target:"shape"});return}const o=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((o.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&jI(this.editor,a)){this.onRightClick({...n,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:s}=n,o=this.editor.getOutermostSelectableShape(s,i=>!r.includes(i.id));!r.includes(o.id)&&!this.editor.findShapeAncestor(o,i=>r.includes(i.id))&&(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([o.id]));break}}});g(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});g(this,"onKeyDown",n=>{switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(xt.editOnType.get()&&!qq.includes(n.key)&&!n.altKey&&!n.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...n,target:"shape",shape:r},!0);return}}});g(this,"onKeyRepeat",n=>{switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});g(this,"onKeyUp",n=>{switch(n.code){case"Enter":{const r=this.editor.getSelectedShapes();if(r.every(o=>this.editor.isShapeOfType(o,"group"))){this.editor.setSelectedShapes(r.flatMap(o=>this.editor.getSortedChildIdsForParent(o.id)));return}const s=this.editor.getOnlySelectedShape();if(s&&this.shouldStartEditingShape(s)){this.startEditingShape(s,{...n,target:"shape",shape:s},!0);return}AI(this.editor)&&this.parent.transition("crop",n);break}}});g(this,"isDarwin",window.navigator.userAgent.toLowerCase().indexOf("mac")>-1)}shouldStartEditingShape(n=this.editor.getOnlySelectedShape()){return!n||this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||!this.canInteractWithShapeInReadOnly(n)?!1:this.editor.getShapeUtil(n).canEdit(n)}startEditingShape(n,r,s){this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||(this.editor.mark("editing shape"),xf(this.editor,n,s),this.parent.transition("editing_shape",r))}isOverArrowLabelTest(n){if(!n)return!1;const r=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(n,"arrow")){const s=this.editor.getShapeGeometry(n).children[1];if(s&&or(r,s.vertices))return!0}return!1}handleDoubleClickOnCanvas(n){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=$e(),{x:s,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:s,y:o,props:{text:"",autoSize:!0}}]);const i=this.editor.getShape(r);if(!i)return;const a=this.editor.getShapeUtil(i);this.editor.getInstanceState().isReadonly&&!a.canEditInReadOnly(i)||(this.editor.setEditingShape(r),this.editor.select(r),this.parent.transition("editing_shape",n))}nudgeSelectedShapes(n=!1){const{editor:{inputs:{keys:r}}}=this,s=r.has("ShiftLeft"),o=new b(0,0);if(r.has("ArrowLeft")&&(o.x-=1),r.has("ArrowRight")&&(o.x+=1),r.has("ArrowUp")&&(o.y-=1),r.has("ArrowDown")&&(o.y+=1),o.equals(new b(0,0)))return;n||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?s?i*eZ:i:s?Qq:Jq,l=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(l,o.mul(a)),Ke(this.editor,l)}canInteractWithShapeInReadOnly(n){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(n).canEditInReadOnly(n))}},g(rS,"id","idle"),rS);const Qq=10,Jq=1,eZ=5;function jI(e,t){const n=e.getSelectionRotatedPageBounds();if(!n)return!1;const r=e.getSelectionRotation();return r?or(t,n.corners.map(s=>b.RotWith(s,n.point,r))):n.containsPoint(t)}class sj extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"markId","");g(this,"wasAlreadySelected",!1);g(this,"didDrag",!1);g(this,"info",{});g(this,"onEnter",n=>{const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const o=this.editor.getShapeGeometry(r).children[1];if(!o)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);this._labelDragOffset=b.Sub(o.center,a),this.markId="label-drag start",this.editor.mark(this.markId),this.editor.setSelectedShapes([this.shapeId])});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});g(this,"_labelDragOffset",new b(0,0));g(this,"onPointerMove",()=>{const{isDragging:n}=this.editor.inputs;if(!n)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const s=ps(this.editor,r),o=this.editor.getShapeGeometry(r),i=o.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(b.Add(a,this._labelDragOffset));let c;if(s.isStraight){const u=b.Dist(s.start.point,s.end.point);c=1-b.Dist(s.end.point,l)/u}else{const{_center:u,measure:h,angleEnd:p,angleStart:f}=o.children[0];c=TS(h,f,p,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})});g(this,"onPointerUp",()=>{const n=this.editor.getShape(this.shapeId);n&&(this.didDrag||!this.wasAlreadySelected?this.complete():(this.editor.setEditingShape(n.id),this.editor.setCurrentTool("select.editing_shape")))});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}g(sj,"id","pointing_arrow_label");class oj extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{const{inputs:n}=this.editor;n.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});g(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",n)});g(this,"onPointerUp",()=>{Pf(this.editor),this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}g(oj,"id","pointing_canvas");class ij extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.info=n;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const s=Ln(this.editor,r)[n.handle.id];s&&this.editor.setHintingShapes([s.toId])}this.editor.setCursor({type:"grabbing",rotation:0})});g(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerUp",()=>{const{shape:n,handle:r}=this.info;if(this.editor.isShapeOfType(n,"note")){const{editor:s}=this,o=OI(s,n,r,!1);if(o){xf(s,o,!0);return}}this.parent.transition("idle",this.info)});g(this,"onPointerMove",()=>{const{editor:n}=this;n.inputs.isDragging&&this.startDraggingHandle()});g(this,"onLongPress",()=>{this.startDraggingHandle()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startDraggingHandle(){const{editor:n}=this;if(n.getInstanceState().isReadonly)return;const{shape:r,handle:s}=this.info;if(n.isShapeOfType(r,"note")){const o=OI(n,r,s,!0);if(o){const i=n.getPointInParentSpace(o,n.inputs.originPagePoint).sub(b.Rot(yg.clone().mul(r.props.scale),o.rotation));n.updateShape({...o,x:i.x,y:i.y}),n.setHoveredShape(o.id).select(o.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:n.getShape(o),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{xf(n,o,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}g(ij,"id","pointing_handle");function OI(e,t,n,r){const s=e.getShapePageTransform(t.id),o=s.point(),i=s.rotation(),l=wA(e,o,i,t.props.growY,0,t.props.scale)[n.index];if(l)return PA(e,t,l,i,r)}class aj extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.updateCursor()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startRotating()});g(this,"onLongPress",()=>{this.startRotating()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:vl[this.info.handle],rotation:this.editor.getSelectionRotation()})}startRotating(){this.editor.getInstanceState().isReadonly||this.parent.transition("rotating",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}g(aj,"id","pointing_rotate_handle");class lj extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.info=n});g(this,"onPointerUp",n=>{Pf(this.editor),this.parent.transition("idle",n)});g(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startTranslating(n)});g(this,"onLongPress",n=>{this.startTranslating(n)});g(this,"onDoubleClick",n=>{var o,i;const r=this.editor.getHoveredShape(),s=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(s){this.parent.transition("idle"),(i=(o=this.parent).onDoubleClick)==null||i.call(o,{...n,target:"shape",shape:this.editor.getShape(s)});return}});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startTranslating(n){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",n)}cancel(){this.parent.transition("idle")}}g(lj,"id","pointing_selection");class cj extends se{constructor(){super(...arguments);g(this,"hitShape",{});g(this,"hitShapeForPointerUp",{});g(this,"isDoubleClick",!1);g(this,"didSelectOnEnter",!1);g(this,"onEnter",n=>{const r=this.editor.getSelectedShapeIds(),s=this.editor.getSelectionRotatedPageBounds(),o=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:l}}=this.editor;this.hitShape=n.shape,this.isDoubleClick=!1;const c=this.editor.getOutermostSelectableShape(n.shape),u=this.editor.findShapeAncestor(c,h=>r.includes(h.id));if(this.editor.getShapeUtil(n.shape).onClick||c.id===o||r.includes(c.id)||u||r.length>1&&(s!=null&&s.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=c;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(c.id)||(this.editor.mark("shift selecting shape"),this.editor.setSelectedShapes([...r,c.id]))):(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([c.id]))});g(this,"onPointerUp",n=>{var u;const r=this.editor.getSelectedShapeIds(),s=this.editor.getFocusedGroupId(),o=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i,shiftKey:a}}=this.editor,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/o,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const h=this.editor.getShapeUtil(c);if(h.onClick){const p=(u=h.onClick)==null?void 0:u.call(h,c);if(p){this.editor.mark("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",n);return}}if(c.id===s){r.length>0?(this.editor.mark("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",n);return}}if(!this.didSelectOnEnter){const h=this.editor.getOutermostSelectableShape(l,p=>!r.includes(p.id));if(r.includes(h.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const p=this.editor.getShapeUtil(c).getGeometry(c),f=nj(p),S=f.length===1?f[0]:void 0;if(S){const y=this.editor.getPointInShapeSpace(c,i);if(S.bounds.containsPoint(y,0)&&S.hitTestPoint(y)){this.editor.run(()=>{this.editor.mark("editing on pointer up"),this.editor.select(c.id);const x=this.editor.getShapeUtil(c);this.editor.getInstanceState().isReadonly&&!x.canEditInReadOnly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:c.id}))});return}}}this.editor.mark("selecting on pointer up"),this.editor.select(c.id)}else this.editor.mark("selecting on pointer up"),this.editor.select(c);else if(a){const p=this.editor.getShapeAncestors(h);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(f=>!p.find(S=>S.id===f)),h.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",n)});g(this,"onDoubleClick",()=>{this.isDoubleClick=!0});g(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startTranslating(n)});g(this,"onLongPress",n=>{this.startTranslating(n)});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startTranslating(n){this.editor.getInstanceState().isReadonly||(this.editor.focus(),this.parent.transition("translating",n))}cancel(){this.parent.transition("idle")}}g(cj,"id","pointing_shape");class uj extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","");g(this,"didHoldCommand",!1);g(this,"creationCursorOffset",{x:0,y:0});g(this,"snapshot",{});g(this,"onEnter",n=>{const{isCreating:r=!1,creationCursorOffset:s={x:0,y:0}}=n;this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=s,this.snapshot=this._createSnapshot(),r?(this.markId=`creating:${this.editor.getOnlySelectedShape().id}`,this.editor.setCursor({type:"cross",rotation:0})):(this.markId="starting resizing",this.editor.mark(this.markId)),this.handleResizeStart(),this.updateShapes()});g(this,"onTick",({elapsed:n})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onKeyDown",()=>{this.updateShapes()});g(this,"onKeyUp",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()});g(this,"_createSnapshot",()=>{const n=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:s}}=this.editor,o=this.editor.getSelectionRotatedPageBounds(),i=b.RotWith(o.getHandlePoint(this.info.handle),o.point,r),a=b.Sub(s,i),l=new Map,c=[];n.forEach(h=>{const p=this.editor.getShape(h);if(p){if(p.type==="frame"&&c.push({id:h,children:ye(this.editor.getSortedChildIdsForParent(p).map(f=>this.editor.getShape(f)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&n.length===1)return;this.editor.visitDescendants(p.id,f=>{const S=this.editor.getShape(f);if(S&&(l.set(S.id,this._createShapeSnapshot(S)),this.editor.isShapeOfType(S,"frame")))return!1})}});const u=![...l.values()].some(h=>!J_(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:o,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}});g(this,"_createShapeSnapshot",n=>{const r=this.editor.getShapePageTransform(n),s=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:oe.Decompose(r).rotation,isAspectRatioLocked:s.isAspectRatioLocked(n)}})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var n,r;if(Ke(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(n=this.info).onCreate)==null||r.call(n,this.editor.getOnlySelectedShape());return}if(this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd){this.editor.setCurrentTool(this.info.onInteractionEnd,{});return}this.parent.transition("idle")}handleResizeStart(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:s})=>{var a;const o=this.editor.getShapeUtil(s),i=(a=o.onResizeStart)==null?void 0:a.call(o,s);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:s})=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onResizeEnd)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:n,shiftKey:r}=this.editor.inputs,{frames:s,shapeSnapshots:o,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot;let h=r||!u;if(o.size===1){const k=[...o.values()][0];this.editor.isShapeOfType(k.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),S=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:k}=this.editor.getDocumentSettings();f.snapToGrid(k)}const y=this.info.handle,x=DI(y,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%Ve===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:b.Sub(f,S),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:DI(y,c),isAspectRatioLocked:h,isResizingFromCenter:n});f.add(k)}const v=b.RotWith(n?i.center:i.getHandlePoint(x),i.point,c),w=b.Sub(f,v).rot(-c),C=b.Sub(S,v).rot(-c),E=b.DivV(w,C);Number.isFinite(E.x)||(E.x=1),Number.isFinite(E.y)||(E.y=1);const _=y==="top"||y==="bottom",I=y==="left"||y==="right";h?I?E.y=Math.abs(E.x):_?E.x=Math.abs(E.y):Math.abs(E.x)>Math.abs(E.y)?E.y=Math.abs(E.x)*(E.y<0?-1:1):E.x=Math.abs(E.y)*(E.x<0?-1:1):(_&&(E.x=1),I&&(E.y=1)),this.info.isCreating||this.updateCursor({dragHandle:y,isFlippedX:E.x<0,isFlippedY:E.y<0,rotation:c});for(const k of o.keys()){const T=o.get(k);this.editor.resizeShape(k,E,{initialShape:T.shape,initialBounds:T.bounds,initialPageTransform:T.pageTransform,dragHandle:y,mode:l.length===1&&k===l[0]?"resize_bounds":"scale_shape",scaleOrigin:v,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:T}of s){if(!T.length)continue;const M=o.get(k).shape,D=this.editor.getShape(k);if(!(M&&D))continue;const $=D.x-M.x,j=D.y-M.y,O=new b($,j).rot(-M.rotation);if(O.x!==0||O.y!==0)for(const R of T)this.editor.updateShape({id:R.id,type:R.type,x:R.x-O.x,y:R.y-O.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of s)if(k.length)for(const T of k)this.editor.updateShape({id:T.id,type:T.type,x:T.x,y:T.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:s,rotation:o}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==s&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==s&&(i.type="nwse-resize");break}}i.rotation=o,this.editor.setCursor(i)}}g(uj,"id","resizing");const xy=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function DI(e,t){t=t%Le;const n=Math.round(t/(Me/4)),r=xy.indexOf(e);return xy[(r+n)%xy.length]}const RI=Math.PI/180;class dj extends se{constructor(){super(...arguments);g(this,"snapshot",{});g(this,"info",{});g(this,"markId","");g(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=WM({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const s=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Kh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:vl[this.info.handle],rotation:s+this.snapshot.initialSelectionRotation})});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});g(this,"onPointerMove",()=>{this.update()});g(this,"onKeyDown",()=>{this.update()});g(this,"onKeyUp",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"update",()=>{const n=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Kh({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:vl[this.info.handle],rotation:n+this.snapshot.initialSelectionRotation})});g(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});g(this,"complete",()=>{Kh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ke(this.editor,this.snapshot.shapeSnapshots.map(n=>n.shape.id)),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)})}_getRotationFromPointerPosition({snapToNearestDegree:n}){const r=this.editor.getSelectionRotation(),s=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:o,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialSelectionRotation:l}=this.snapshot;if(!s)return l;const u=s.center.clone().rotWith(s.point,r).angle(i)-a;let h=l+u;if(o)h=Bp(h,24);else if(n&&(h=Math.round(h/RI)*RI,this.editor.getInstanceState().isCoarsePointer)){const p=Bp(h,4),f=Ah(h,p);Math.abs(f)<m9(5)&&(h=p)}return h-l}}g(dj,"id","rotating");class hj extends se{constructor(){super(...arguments);g(this,"hits",new Set);g(this,"size",0);g(this,"scribbleId","id");g(this,"initialSelectedShapeIds",new Set);g(this,"newlySelectedShapeIds",new Set);g(this,"onEnter",()=>{this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const n=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=n.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});g(this,"onPointerUp",()=>{this.complete()});g(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});g(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)})}updateScribbleSelection(n){const{editor:r}=this,s=this.editor.getCurrentPageShapes(),{inputs:{shiftKey:o,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const h=s;let p,f,S,y;const x=0;for(let w=0,C=h.length;w<C;w++){if(p=h[w],r.isShapeOfType(p,"group")||c.has(p.id)||r.isShapeOrAncestorLocked(p)||(f=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&f.bounds.containsPoint(r.getPointInShapeSpace(p,i))))continue;const E=r.getShapePageTransform(p);if(!f||!E)continue;const _=E.clone().invert();S=_.applyToPoint(a),y=_.applyToPoint(l);const{bounds:I}=f;if(!(I.minX-x>Math.max(S.x,y.x)||I.minY-x>Math.max(S.y,y.y)||I.maxX+x<Math.min(S.x,y.x)||I.maxY+x<Math.min(S.y,y.y))&&f.hitTestLineSegment(S,y,x)){const k=this.editor.getOutermostSelectableShape(p),T=this.editor.getShapeMask(k.id);if(T&&ew(a,l,T)!==null&&!or(l,T))continue;c.add(k.id)}}const m=r.getSelectedShapeIds(),v=new Set(o?[...c,...u]:[...c]);(m.length!==v.size||m.some(w=>!v.has(w)))&&this.editor.setSelectedShapes(Array.from(v))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}g(hj,"id","scribble_brushing");const tZ=20,nZ=100;class rZ{constructor(t){g(this,"prevDroppingShapeId",null);g(this,"droppingNodeTimer",null);g(this,"first",!0);g(this,"dispose",()=>{this.clear()});this.editor=t,t.disposables.add(this.dispose)}updateDroppingNode(t,n){var r;this.first&&(this.editor.setHintingShapes(t.map(s=>this.editor.findShapeAncestor(s,o=>o.type!=="group")).filter(s=>s)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,t))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(t,tZ,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(t,nZ,n))}setDragTimer(t,n,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.run(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,t,r)}),this.droppingNodeTimer=null},n)}handleDrag(t,n,r){var l,c,u,h,p;n=ye(n.map(f=>this.editor.getShape(f.id)));const s=((l=this.editor.getDroppingOverShape(t,n))==null?void 0:l.id)??null;if(s===this.prevDroppingShapeId){this.hintParents(n);return}const{prevDroppingShapeId:o}=this,i=o&&this.editor.getShape(o),a=s&&this.editor.getShape(s);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,n)),a&&((p=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(h,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=s}hintParents(t){const n=new Map;for(const s of t){const o=this.editor.findShapeAncestor(s,i=>i.type!=="group");o&&(n.has(o.id)||n.set(o.id,[]),n.get(o.id).push(s.id))}const r=[];for(const[s,o]of n){const i=this.editor.getShape(s);i&&SA(this.editor,i).length<o.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(t){var r,s;const{prevDroppingShapeId:n}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,t),n){const o=this.editor.getShape(n);if(!o)return;(s=(r=this.editor.getShapeUtil(o)).onDropShapesOver)==null||s.call(r,o,t)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class pj extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"selectionSnapshot",{});g(this,"snapshot",{});g(this,"markId","");g(this,"isCloning",!1);g(this,"isCreating",!1);g(this,"onCreate",()=>{});g(this,"dragAndDropManager",new rZ(this.editor));g(this,"onEnter",n=>{var o;const{isCreating:r=!1,onCreate:s=()=>{}}=n;if(!((o=this.editor.getSelectedShapeIds())!=null&&o.length)){this.parent.transition("idle");return}if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.isCreating=r,this.onCreate=s,r?this.markId=`creating:${this.editor.getOnlySelectedShape().id}`:(this.markId="translating",this.editor.mark(this.markId)),this.isCloning=!1,this.info=n,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=LI(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()});g(this,"onTick",({elapsed:n})=>{const{editor:r}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),r.edgeScrollManager.updateEdgeScrolling(n)});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});g(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"updateParentTransforms",()=>{const{editor:n,snapshot:{shapeSnapshots:r}}=this;r.forEach(s=>{const o=n.getShape(s.shape.id);if(!o)return null;const i=Mn(o.parentId)?null:oe.Inverse(n.getShapePageTransform(o.parentId));s.parentTransform=i})})}startCloning(){this.isCreating||(this.isCloning=!0,this.reset(),this.markId="translating",this.editor.mark(this.markId),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=LI(this.editor),this.handleStart(),this.updateShapes())}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId="translating",this.editor.mark(this.markId),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){var n;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),Ke(this.editor,this.snapshot.movingShapes.map(r=>r.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(n=this.onCreate)==null||n.call(this,this.editor.getOnlySelectedShape()):this.parent.transition("idle")}cancel(){this.reset(),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.parent.transition("idle",this.info)}handleStart(){const{movingShapes:n}=this.snapshot,r=[];n.forEach(s=>{var a;const o=this.editor.getShapeUtil(s),i=(a=o.onTranslateStart)==null?void 0:a.call(o,s);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:n}=this.snapshot;if(this.isCloning&&n.length>0){const s=b.Average(n.map(i=>this.editor.getShapePageTransform(i.id).point())),o=b.Sub(s,this.selectionSnapshot.averagePagePoint);b.IsNaN(o)||this.editor.updateInstanceState({duplicateProps:{shapeIds:n.map(i=>i.id),offset:{x:o.x,y:o.y}}})}const r=[];n.forEach(s=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onTranslateEnd)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:n}=this;this.dragAndDropManager.updateDroppingNode(n.movingShapes,this.updateParentTransforms),sZ({editor:this.editor,snapshot:n});const{movingShapes:r}=n,s=[];r.forEach(o=>{var c;const i=this.editor.getShape(o.id),a=this.editor.getShapeUtil(o),l=(c=a.onTranslate)==null?void 0:c.call(a,o,i);l&&s.push(l)}),s.length>0&&this.editor.updateShapes(s)}}g(pj,"id","translating");function LI(e){var h;const t=[],n=[],r=e.getSelectedShapeIds(),s=ye(r.map(p=>{const f=e.getShape(p);if(!f)return null;t.push(f);const S=e.getShapePageTransform(p),y=S.point(),x=S.rotation();n.push(y);const m=Qs.isId(f.parentId)?null:oe.Inverse(e.getShapePageTransform(f.parentId));return{shape:f,pagePoint:y,pageRotation:x,parentTransform:m}})),o=e.getOnlySelectedShape();let i=[];if(o)i=e.snaps.shapeBounds.getSnapPoints(o.id);else{const p=e.getSelectionPageBounds();p&&(i=p.cornersAndCenter.map((f,S)=>({id:"selection:"+S,x:f.x,y:f.y})))}let a,l;const{originPagePoint:c}=e.inputs,u=s.filter(p=>e.isShapeOfType(p.shape,"note")&&e.isPointInShape(p.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const p=e.getCurrentPageShapesSorted();l=(h=u.map(f=>({snapshot:f,index:p.findIndex(S=>S.id===f.shape.id)})).sort((f,S)=>S.index-f.index)[0])==null?void 0:h.snapshot}return l&&(a=bA(e,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:b.Average(n),movingShapes:t,shapeSnapshots:s,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function sZ({editor:e,snapshot:t}){const{inputs:n}=e,{noteSnapshot:r,noteAdjacentPositions:s,initialPageBounds:o,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=t,c=e.getInstanceState().isGridMode,u=e.getDocumentSettings().gridSize,h=b.Sub(n.currentPagePoint,n.originPagePoint),p=e.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;if(p==="x"?h.x=0:p==="y"&&(h.y=0),e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:x}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:o,lockedAxis:p,initialSelectionSnapPoints:i});h.add(x)}else if(r&&s){const{scale:x}=r.shape.props,m=r.pagePoint.clone().add(h).add(yg.clone().mul(x).rot(r.pageRotation));let v=xA/e.getZoomLevel(),w=new b(0,0);for(const C of s){const E=b.Sub(m,C),_=E.len();_<v&&(v=_,w=E)}h.sub(w)}const S=b.Add(l,h);c&&!n.ctrlKey&&S.snapToGrid(u);const y=b.Sub(S,l);e.updateShapes(ye(a.map(({shape:x,pagePoint:m,parentTransform:v})=>{const w=b.Add(m,y),C=v?oe.applyToPoint(v,w):w;return{id:x.id,type:x.type,x:C.x,y:C.y}})))}class Oc extends se{constructor(){super(...arguments);g(this,"reactor");g(this,"cleanUpDuplicateProps",()=>{const n=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const s=new Set(r.duplicateProps.shapeIds);n.length===s.size&&n.every(o=>s.has(o))||this.editor.updateInstanceState({duplicateProps:null})});g(this,"onEnter",()=>{this.reactor=ra("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){typeof process<"u",console.error(n)}})});g(this,"onExit",()=>{var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}g(Oc,"id","select"),g(Oc,"initial","idle"),g(Oc,"isLockable",!1),g(Oc,"children",()=>[fp,ww,Zq,oj,cj,pj,XA,hj,bw,lj,qA,rj,uj,dj,aj,sj,ij,tj]);class fj extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.info=n});g(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}g(fj,"id","idle");class gj extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.info=n});g(this,"onPointerUp",()=>{this.complete()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});g(this,"onCancel",()=>{this.cancel()})}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{animation:{duration:220}}):this.editor.zoomIn(n,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}g(gj,"id","pointing");class mj extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"zoomBrush",new Q);g(this,"onEnter",n=>{this.info=n,this.update()});g(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()})}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Q.FromPoints([n,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:n}=this,r=8/this.editor.getZoomLevel();if(n.width<r&&n.height<r){const s=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(s,{animation:{duration:220}}):this.editor.zoomIn(s,{animation:{duration:220}})}else{const s=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:s,animation:{duration:220}})}this.parent.transition("idle",this.info)}}g(mj,"id","zoom_brushing");class Dc extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)});g(this,"onKeyDown",()=>{this.updateCursor()});g(this,"onKeyUp",n=>{this.updateCursor(),n.code==="KeyZ"&&this.complete()});g(this,"onInterrupt",()=>{this.complete()})}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}g(Dc,"id","zoom"),g(Dc,"initial","idle"),g(Dc,"children",()=>[fj,mj,gj]),g(Dc,"isLockable",!1);const oZ=[Mc,Ac,jc,Dc,Oc];function re(e,t,{checkForDefaultPrevented:n=!0}={}){return function(s){if(e==null||e(s),n===!1||!s.defaultPrevented)return t==null?void 0:t(s)}}function iZ(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function bg(...e){return t=>e.forEach(n=>iZ(n,t))}function qe(...e){return P.useCallback(bg(...e),e)}function aZ(e,t){const n=P.createContext(t);function r(o){const{children:i,...a}=o,l=P.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})}function s(o){const i=P.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${o}\` must be used within \`${e}\``)}return r.displayName=e+"Provider",[r,s]}function Ms(e,t=[]){let n=[];function r(o,i){const a=P.createContext(i),l=n.length;n=[...n,i];function c(h){const{scope:p,children:f,...S}=h,y=(p==null?void 0:p[e][l])||a,x=P.useMemo(()=>S,Object.values(S));return d.jsx(y.Provider,{value:x,children:f})}function u(h,p){const f=(p==null?void 0:p[e][l])||a,S=P.useContext(f);if(S)return S;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${o}\``)}return c.displayName=o+"Provider",[c,u]}const s=()=>{const o=n.map(i=>P.createContext(i));return function(a){const l=(a==null?void 0:a[e])||o;return P.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return s.scopeName=e,[r,lZ(s,...t)]}function lZ(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(o)[`__scope${c}`];return{...a,...h}},{});return P.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var Qo=globalThis!=null&&globalThis.document?P.useLayoutEffect:()=>{},cZ=R3.useId||(()=>{}),uZ=0;function qs(e){const[t,n]=P.useState(cZ());return Qo(()=>{e||n(r=>r??String(uZ++))},[e]),e||(t?`radix-${t}`:"")}function Xt(e){const t=P.useRef(e);return P.useEffect(()=>{t.current=e}),P.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function ui({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,s]=dZ({defaultProp:t,onChange:n}),o=e!==void 0,i=o?e:r,a=Xt(n),l=P.useCallback(c=>{if(o){const h=typeof c=="function"?c(e):c;h!==e&&a(h)}else s(c)},[o,e,s,a]);return[i,l]}function dZ({defaultProp:e,onChange:t}){const n=P.useState(e),[r]=n,s=P.useRef(r),o=Xt(t);return P.useEffect(()=>{s.current!==r&&(o(r),s.current=r)},[r,s,o]),n}var Yi=P.forwardRef((e,t)=>{const{children:n,...r}=e,s=P.Children.toArray(n),o=s.find(pZ);if(o){const i=o.props.children,a=s.map(l=>l===o?P.Children.count(i)>1?P.Children.only(null):P.isValidElement(i)?i.props.children:null:l);return d.jsx(Uv,{...r,ref:t,children:P.isValidElement(i)?P.cloneElement(i,void 0,a):null})}return d.jsx(Uv,{...r,ref:t,children:n})});Yi.displayName="Slot";var Uv=P.forwardRef((e,t)=>{const{children:n,...r}=e;if(P.isValidElement(n)){const s=gZ(n);return P.cloneElement(n,{...fZ(r,n.props),ref:t?bg(t,s):s})}return P.Children.count(n)>1?P.Children.only(null):null});Uv.displayName="SlotClone";var hZ=({children:e})=>d.jsx(d.Fragment,{children:e});function pZ(e){return P.isValidElement(e)&&e.type===hZ}function fZ(e,t){const n={...t};for(const r in t){const s=e[r],o=t[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...a)=>{o(...a),s(...a)}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"&&(n[r]=[s,o].filter(Boolean).join(" "))}return{...e,...n}}function gZ(e){var r,s;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(s=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:s.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var mZ=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],_e=mZ.reduce((e,t)=>{const n=P.forwardRef((r,s)=>{const{asChild:o,...i}=r,a=o?Yi:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(a,{...i,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Pw(e,t){e&&ia.flushSync(()=>e.dispatchEvent(t))}function yZ(e,t=globalThis==null?void 0:globalThis.document){const n=Xt(e);P.useEffect(()=>{const r=s=>{s.key==="Escape"&&n(s)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var SZ="DismissableLayer",Hv="dismissableLayer.update",vZ="dismissableLayer.pointerDownOutside",xZ="dismissableLayer.focusOutside",$I,yj=P.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),nd=P.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:i,onDismiss:a,...l}=e,c=P.useContext(yj),[u,h]=P.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=P.useState({}),S=qe(t,I=>h(I)),y=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),m=y.indexOf(x),v=u?y.indexOf(u):-1,w=c.layersWithOutsidePointerEventsDisabled.size>0,C=v>=m,E=bZ(I=>{const k=I.target,T=[...c.branches].some(M=>M.contains(k));!C||T||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},p),_=PZ(I=>{const k=I.target;[...c.branches].some(M=>M.contains(k))||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},p);return yZ(I=>{v===c.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},p),P.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&($I=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),NI(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=$I)}},[u,p,n,c]),P.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),NI())},[u,c]),P.useEffect(()=>{const I=()=>f({});return document.addEventListener(Hv,I),()=>document.removeEventListener(Hv,I)},[]),d.jsx(_e.div,{...l,ref:S,style:{pointerEvents:w?C?"auto":"none":void 0,...e.style},onFocusCapture:re(e.onFocusCapture,_.onFocusCapture),onBlurCapture:re(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:re(e.onPointerDownCapture,E.onPointerDownCapture)})});nd.displayName=SZ;var wZ="DismissableLayerBranch",Sj=P.forwardRef((e,t)=>{const n=P.useContext(yj),r=P.useRef(null),s=qe(t,r);return P.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),d.jsx(_e.div,{...e,ref:s})});Sj.displayName=wZ;function bZ(e,t=globalThis==null?void 0:globalThis.document){const n=Xt(e),r=P.useRef(!1),s=P.useRef(()=>{});return P.useEffect(()=>{const o=a=>{if(a.target&&!r.current){let l=function(){vj(vZ,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",s.current),s.current=l,t.addEventListener("click",s.current,{once:!0})):l()}else t.removeEventListener("click",s.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",o),t.removeEventListener("click",s.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function PZ(e,t=globalThis==null?void 0:globalThis.document){const n=Xt(e),r=P.useRef(!1);return P.useEffect(()=>{const s=o=>{o.target&&!r.current&&vj(xZ,n,{originalEvent:o},{discrete:!1})};return t.addEventListener("focusin",s),()=>t.removeEventListener("focusin",s)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function NI(){const e=new CustomEvent(Hv);document.dispatchEvent(e)}function vj(e,t,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&s.addEventListener(e,t,{once:!0}),r?Pw(s,o):s.dispatchEvent(o)}var CZ=nd,IZ=Sj,wy="focusScope.autoFocusOnMount",by="focusScope.autoFocusOnUnmount",FI={bubbles:!1,cancelable:!0},EZ="FocusScope",Pg=P.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:o,...i}=e,[a,l]=P.useState(null),c=Xt(s),u=Xt(o),h=P.useRef(null),p=qe(t,y=>l(y)),f=P.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;P.useEffect(()=>{if(r){let y=function(w){if(f.paused||!a)return;const C=w.target;a.contains(C)?h.current=C:Co(h.current,{select:!0})},x=function(w){if(f.paused||!a)return;const C=w.relatedTarget;C!==null&&(a.contains(C)||Co(h.current,{select:!0}))},m=function(w){if(document.activeElement===document.body)for(const E of w)E.removedNodes.length>0&&Co(a)};document.addEventListener("focusin",y),document.addEventListener("focusout",x);const v=new MutationObserver(m);return a&&v.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",y),document.removeEventListener("focusout",x),v.disconnect()}}},[r,a,f.paused]),P.useEffect(()=>{if(a){BI.add(f);const y=document.activeElement;if(!a.contains(y)){const m=new CustomEvent(wy,FI);a.addEventListener(wy,c),a.dispatchEvent(m),m.defaultPrevented||(kZ(jZ(xj(a)),{select:!0}),document.activeElement===y&&Co(a))}return()=>{a.removeEventListener(wy,c),setTimeout(()=>{const m=new CustomEvent(by,FI);a.addEventListener(by,u),a.dispatchEvent(m),m.defaultPrevented||Co(y??document.body,{select:!0}),a.removeEventListener(by,u),BI.remove(f)},0)}}},[a,c,u,f]);const S=P.useCallback(y=>{if(!n&&!r||f.paused)return;const x=y.key==="Tab"&&!y.altKey&&!y.ctrlKey&&!y.metaKey,m=document.activeElement;if(x&&m){const v=y.currentTarget,[w,C]=_Z(v);w&&C?!y.shiftKey&&m===C?(y.preventDefault(),n&&Co(w,{select:!0})):y.shiftKey&&m===w&&(y.preventDefault(),n&&Co(C,{select:!0})):m===v&&y.preventDefault()}},[n,r,f.paused]);return d.jsx(_e.div,{tabIndex:-1,...i,ref:p,onKeyDown:S})});Pg.displayName=EZ;function kZ(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Co(r,{select:t}),document.activeElement!==n)return}function _Z(e){const t=xj(e),n=zI(t,e),r=zI(t.reverse(),e);return[n,r]}function xj(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function zI(e,t){for(const n of e)if(!TZ(n,{upTo:t}))return n}function TZ(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function MZ(e){return e instanceof HTMLInputElement&&"select"in e}function Co(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&MZ(e)&&t&&e.select()}}var BI=AZ();function AZ(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=UI(e,t),e.unshift(t)},remove(t){var n;e=UI(e,t),(n=e[0])==null||n.resume()}}}function UI(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function jZ(e){return e.filter(t=>t.tagName!=="A")}var OZ="Portal",rd=P.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[s,o]=P.useState(!1);Qo(()=>o(!0),[]);const i=n||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?HW.createPortal(d.jsx(_e.div,{...r,ref:t}),i):null});rd.displayName=OZ;function DZ(e,t){return P.useReducer((n,r)=>t[n][r]??n,e)}var Qr=e=>{const{present:t,children:n}=e,r=RZ(t),s=typeof n=="function"?n({present:r.isPresent}):P.Children.only(n),o=qe(r.ref,LZ(s));return typeof n=="function"||r.isPresent?P.cloneElement(s,{ref:o}):null};Qr.displayName="Presence";function RZ(e){const[t,n]=P.useState(),r=P.useRef({}),s=P.useRef(e),o=P.useRef("none"),i=e?"mounted":"unmounted",[a,l]=DZ(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return P.useEffect(()=>{const c=uh(r.current);o.current=a==="mounted"?c:"none"},[a]),Qo(()=>{const c=r.current,u=s.current;if(u!==e){const p=o.current,f=uh(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&p!==f?"ANIMATION_OUT":"UNMOUNT"),s.current=e}},[e,l]),Qo(()=>{if(t){const c=h=>{const f=uh(r.current).includes(h.animationName);h.target===t&&f&&ia.flushSync(()=>l("ANIMATION_END"))},u=h=>{h.target===t&&(o.current=uh(r.current))};return t.addEventListener("animationstart",u),t.addEventListener("animationcancel",c),t.addEventListener("animationend",c),()=>{t.removeEventListener("animationstart",u),t.removeEventListener("animationcancel",c),t.removeEventListener("animationend",c)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:P.useCallback(c=>{c&&(r.current=getComputedStyle(c)),n(c)},[])}}function uh(e){return(e==null?void 0:e.animationName)||"none"}function LZ(e){var r,s;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(s=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:s.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var Py=0;function Cw(){P.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??HI()),document.body.insertAdjacentElement("beforeend",e[1]??HI()),Py++,()=>{Py===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Py--}},[])}function HI(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.cssText="outline: none; opacity: 0; position: fixed; pointer-events: none",e}var us=function(){return us=Object.assign||function(t){for(var n,r=1,s=arguments.length;r<s;r++){n=arguments[r];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},us.apply(this,arguments)};function wj(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(n[r[s]]=e[r[s]]);return n}function $Z(e,t,n){if(n||arguments.length===2)for(var r=0,s=t.length,o;r<s;r++)(o||!(r in t))&&(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}var gp="right-scroll-bar-position",mp="width-before-scroll-bar",NZ="with-scroll-bars-hidden",FZ="--removed-body-scroll-bar-size";function Cy(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function zZ(e,t){var n=P.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var s=n.value;s!==r&&(n.value=r,n.callback(r,s))}}}})[0];return n.callback=t,n.facade}var BZ=typeof window<"u"?P.useLayoutEffect:P.useEffect,KI=new WeakMap;function UZ(e,t){var n=zZ(null,function(r){return e.forEach(function(s){return Cy(s,r)})});return BZ(function(){var r=KI.get(n);if(r){var s=new Set(r),o=new Set(e),i=n.current;s.forEach(function(a){o.has(a)||Cy(a,null)}),o.forEach(function(a){s.has(a)||Cy(a,i)})}KI.set(n,e)},[e]),n}function HZ(e){return e}function KZ(e,t){t===void 0&&(t=HZ);var n=[],r=!1,s={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(o){var i=t(o,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(o){for(r=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(a){return o(a)},filter:function(){return n}}},assignMedium:function(o){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(o),i=n}var l=function(){var u=i;i=[],u.forEach(o)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),n}}}};return s}function WZ(e){e===void 0&&(e={});var t=KZ(null);return t.options=us({async:!0,ssr:!1},e),t}var bj=function(e){var t=e.sideCar,n=wj(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return P.createElement(r,us({},n))};bj.isSideCarExport=!0;function GZ(e,t){return e.useMedium(t),bj}var Pj=WZ(),Iy=function(){},Cg=P.forwardRef(function(e,t){var n=P.useRef(null),r=P.useState({onScrollCapture:Iy,onWheelCapture:Iy,onTouchMoveCapture:Iy}),s=r[0],o=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,h=e.shards,p=e.sideCar,f=e.noIsolation,S=e.inert,y=e.allowPinchZoom,x=e.as,m=x===void 0?"div":x,v=e.gapMode,w=wj(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=p,E=UZ([n,t]),_=us(us({},w),s);return P.createElement(P.Fragment,null,u&&P.createElement(C,{sideCar:Pj,removeScrollBar:c,shards:h,noIsolation:f,inert:S,setCallbacks:o,allowPinchZoom:!!y,lockRef:n,gapMode:v}),i?P.cloneElement(P.Children.only(a),us(us({},_),{ref:E})):P.createElement(m,us({},_,{className:l,ref:E}),a))});Cg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Cg.classNames={fullWidth:mp,zeroRight:gp};var VZ=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function YZ(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=VZ();return t&&e.setAttribute("nonce",t),e}function XZ(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function qZ(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var ZZ=function(){var e=0,t=null;return{add:function(n){e==0&&(t=YZ())&&(XZ(t,n),qZ(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},QZ=function(){var e=ZZ();return function(t,n){P.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Cj=function(){var e=QZ(),t=function(n){var r=n.styles,s=n.dynamic;return e(r,s),null};return t},JZ={left:0,top:0,right:0,gap:0},Ey=function(e){return parseInt(e||"",10)||0},eQ=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],s=t[e==="padding"?"paddingRight":"marginRight"];return[Ey(n),Ey(r),Ey(s)]},tQ=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return JZ;var t=eQ(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},nQ=Cj(),rl="data-scroll-locked",rQ=function(e,t,n,r){var s=e.left,o=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
221
|
-
.`.concat(NZ,` {
|
|
222
|
-
overflow: hidden `).concat(r,`;
|
|
223
|
-
padding-right: `).concat(a,"px ").concat(r,`;
|
|
224
|
-
}
|
|
225
|
-
body[`).concat(rl,`] {
|
|
226
|
-
overflow: hidden `).concat(r,`;
|
|
227
|
-
overscroll-behavior: contain;
|
|
228
|
-
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
229
|
-
padding-left: `.concat(s,`px;
|
|
230
|
-
padding-top: `).concat(o,`px;
|
|
231
|
-
padding-right: `).concat(i,`px;
|
|
232
|
-
margin-left:0;
|
|
233
|
-
margin-top:0;
|
|
234
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
235
|
-
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
.`).concat(gp,` {
|
|
239
|
-
right: `).concat(a,"px ").concat(r,`;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
.`).concat(mp,` {
|
|
243
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
.`).concat(gp," .").concat(gp,` {
|
|
247
|
-
right: 0 `).concat(r,`;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
.`).concat(mp," .").concat(mp,` {
|
|
251
|
-
margin-right: 0 `).concat(r,`;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
body[`).concat(rl,`] {
|
|
255
|
-
`).concat(FZ,": ").concat(a,`px;
|
|
256
|
-
}
|
|
257
|
-
`)},WI=function(){var e=parseInt(document.body.getAttribute(rl)||"0",10);return isFinite(e)?e:0},sQ=function(){P.useEffect(function(){return document.body.setAttribute(rl,(WI()+1).toString()),function(){var e=WI()-1;e<=0?document.body.removeAttribute(rl):document.body.setAttribute(rl,e.toString())}},[])},oQ=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,s=r===void 0?"margin":r;sQ();var o=P.useMemo(function(){return tQ(s)},[s]);return P.createElement(nQ,{styles:rQ(o,!t,s,n?"":"!important")})},Kv=!1;if(typeof window<"u")try{var dh=Object.defineProperty({},"passive",{get:function(){return Kv=!0,!0}});window.addEventListener("test",dh,dh),window.removeEventListener("test",dh,dh)}catch{Kv=!1}var Sa=Kv?{passive:!1}:!1,iQ=function(e){return e.tagName==="TEXTAREA"},Ij=function(e,t){var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!iQ(e)&&n[t]==="visible")},aQ=function(e){return Ij(e,"overflowY")},lQ=function(e){return Ij(e,"overflowX")},GI=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var s=Ej(e,r);if(s){var o=kj(e,r),i=o[1],a=o[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},cQ=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},uQ=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Ej=function(e,t){return e==="v"?aQ(t):lQ(t)},kj=function(e,t){return e==="v"?cQ(t):uQ(t)},dQ=function(e,t){return e==="h"&&t==="rtl"?-1:1},hQ=function(e,t,n,r,s){var o=dQ(e,window.getComputedStyle(t).direction),i=o*r,a=n.target,l=t.contains(a),c=!1,u=i>0,h=0,p=0;do{var f=kj(e,a),S=f[0],y=f[1],x=f[2],m=y-x-o*S;(S||m)&&Ej(e,a)&&(h+=m,p+=S),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(u&&(Math.abs(h)<1||!s)||!u&&(Math.abs(p)<1||!s))&&(c=!0),c},hh=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},VI=function(e){return[e.deltaX,e.deltaY]},YI=function(e){return e&&"current"in e?e.current:e},pQ=function(e,t){return e[0]===t[0]&&e[1]===t[1]},fQ=function(e){return`
|
|
258
|
-
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
259
|
-
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
260
|
-
`)},gQ=0,va=[];function mQ(e){var t=P.useRef([]),n=P.useRef([0,0]),r=P.useRef(),s=P.useState(gQ++)[0],o=P.useState(Cj)[0],i=P.useRef(e);P.useEffect(function(){i.current=e},[e]),P.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(s));var y=$Z([e.lockRef.current],(e.shards||[]).map(YI),!0).filter(Boolean);return y.forEach(function(x){return x.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),y.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(s))})}}},[e.inert,e.lockRef.current,e.shards]);var a=P.useCallback(function(y,x){if("touches"in y&&y.touches.length===2)return!i.current.allowPinchZoom;var m=hh(y),v=n.current,w="deltaX"in y?y.deltaX:v[0]-m[0],C="deltaY"in y?y.deltaY:v[1]-m[1],E,_=y.target,I=Math.abs(w)>Math.abs(C)?"h":"v";if("touches"in y&&I==="h"&&_.type==="range")return!1;var k=GI(I,_);if(!k)return!0;if(k?E=I:(E=I==="v"?"h":"v",k=GI(I,_)),!k)return!1;if(!r.current&&"changedTouches"in y&&(w||C)&&(r.current=E),!E)return!0;var T=r.current||E;return hQ(T,x,y,T==="h"?w:C,!0)},[]),l=P.useCallback(function(y){var x=y;if(!(!va.length||va[va.length-1]!==o)){var m="deltaY"in x?VI(x):hh(x),v=t.current.filter(function(E){return E.name===x.type&&(E.target===x.target||x.target===E.shadowParent)&&pQ(E.delta,m)})[0];if(v&&v.should){x.cancelable&&x.preventDefault();return}if(!v){var w=(i.current.shards||[]).map(YI).filter(Boolean).filter(function(E){return E.contains(x.target)}),C=w.length>0?a(x,w[0]):!i.current.noIsolation;C&&x.cancelable&&x.preventDefault()}}},[]),c=P.useCallback(function(y,x,m,v){var w={name:y,delta:x,target:m,should:v,shadowParent:yQ(m)};t.current.push(w),setTimeout(function(){t.current=t.current.filter(function(C){return C!==w})},1)},[]),u=P.useCallback(function(y){n.current=hh(y),r.current=void 0},[]),h=P.useCallback(function(y){c(y.type,VI(y),y.target,a(y,e.lockRef.current))},[]),p=P.useCallback(function(y){c(y.type,hh(y),y.target,a(y,e.lockRef.current))},[]);P.useEffect(function(){return va.push(o),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,Sa),document.addEventListener("touchmove",l,Sa),document.addEventListener("touchstart",u,Sa),function(){va=va.filter(function(y){return y!==o}),document.removeEventListener("wheel",l,Sa),document.removeEventListener("touchmove",l,Sa),document.removeEventListener("touchstart",u,Sa)}},[]);var f=e.removeScrollBar,S=e.inert;return P.createElement(P.Fragment,null,S?P.createElement(o,{styles:fQ(s)}):null,f?P.createElement(oQ,{gapMode:e.gapMode}):null)}function yQ(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const SQ=GZ(Pj,mQ);var Ig=P.forwardRef(function(e,t){return P.createElement(Cg,us({},e,{ref:t,sideCar:SQ}))});Ig.classNames=Cg.classNames;var vQ=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},xa=new WeakMap,ph=new WeakMap,fh={},ky=0,_j=function(e){return e&&(e.host||_j(e.parentNode))},xQ=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=_j(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},wQ=function(e,t,n,r){var s=xQ(t,Array.isArray(e)?e:[e]);fh[n]||(fh[n]=new WeakMap);var o=fh[n],i=[],a=new Set,l=new Set(s),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};s.forEach(c);var u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(p){if(a.has(p))u(p);else try{var f=p.getAttribute(r),S=f!==null&&f!=="false",y=(xa.get(p)||0)+1,x=(o.get(p)||0)+1;xa.set(p,y),o.set(p,x),i.push(p),y===1&&S&&ph.set(p,!0),x===1&&p.setAttribute(n,"true"),S||p.setAttribute(r,"true")}catch(m){console.error("aria-hidden: cannot operate on ",p,m)}})};return u(t),a.clear(),ky++,function(){i.forEach(function(h){var p=xa.get(h)-1,f=o.get(h)-1;xa.set(h,p),o.set(h,f),p||(ph.has(h)||h.removeAttribute(r),ph.delete(h)),f||h.removeAttribute(n)}),ky--,ky||(xa=new WeakMap,xa=new WeakMap,ph=new WeakMap,fh={})}},Iw=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),s=vQ(e);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),wQ(r,s,n,"aria-hidden")):function(){return null}},Ew="Dialog",[Tj,_ae]=Ms(Ew),[bQ,Jr]=Tj(Ew),Mj=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:i=!0}=e,a=P.useRef(null),l=P.useRef(null),[c=!1,u]=ui({prop:r,defaultProp:s,onChange:o});return d.jsx(bQ,{scope:t,triggerRef:a,contentRef:l,contentId:qs(),titleId:qs(),descriptionId:qs(),open:c,onOpenChange:u,onOpenToggle:P.useCallback(()=>u(h=>!h),[u]),modal:i,children:n})};Mj.displayName=Ew;var Aj="DialogTrigger",PQ=P.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Jr(Aj,n),o=qe(t,s.triggerRef);return d.jsx(_e.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":Tw(s.open),...r,ref:o,onClick:re(e.onClick,s.onOpenToggle)})});PQ.displayName=Aj;var kw="DialogPortal",[CQ,jj]=Tj(kw,{forceMount:void 0}),Oj=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:s}=e,o=Jr(kw,t);return d.jsx(CQ,{scope:t,forceMount:n,children:P.Children.map(r,i=>d.jsx(Qr,{present:n||o.open,children:d.jsx(rd,{asChild:!0,container:s,children:i})}))})};Oj.displayName=kw;var Cf="DialogOverlay",Dj=P.forwardRef((e,t)=>{const n=jj(Cf,e.__scopeDialog),{forceMount:r=n.forceMount,...s}=e,o=Jr(Cf,e.__scopeDialog);return o.modal?d.jsx(Qr,{present:r||o.open,children:d.jsx(IQ,{...s,ref:t})}):null});Dj.displayName=Cf;var IQ=P.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Jr(Cf,n);return d.jsx(Ig,{as:Yi,allowPinchZoom:!0,shards:[s.contentRef],children:d.jsx(_e.div,{"data-state":Tw(s.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),Xi="DialogContent",Rj=P.forwardRef((e,t)=>{const n=jj(Xi,e.__scopeDialog),{forceMount:r=n.forceMount,...s}=e,o=Jr(Xi,e.__scopeDialog);return d.jsx(Qr,{present:r||o.open,children:o.modal?d.jsx(EQ,{...s,ref:t}):d.jsx(kQ,{...s,ref:t})})});Rj.displayName=Xi;var EQ=P.forwardRef((e,t)=>{const n=Jr(Xi,e.__scopeDialog),r=P.useRef(null),s=qe(t,n.contentRef,r);return P.useEffect(()=>{const o=r.current;if(o)return Iw(o)},[]),d.jsx(Lj,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:re(e.onCloseAutoFocus,o=>{var i;o.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:re(e.onPointerDownOutside,o=>{const i=o.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&o.preventDefault()}),onFocusOutside:re(e.onFocusOutside,o=>o.preventDefault())})}),kQ=P.forwardRef((e,t)=>{const n=Jr(Xi,e.__scopeDialog),r=P.useRef(!1),s=P.useRef(!1);return d.jsx(Lj,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,o),o.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),Lj=P.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,...i}=e,a=Jr(Xi,n),l=P.useRef(null),c=qe(t,l);return Cw(),d.jsxs(d.Fragment,{children:[d.jsx(Pg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:d.jsx(nd,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Tw(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(TQ,{titleId:a.titleId}),d.jsx(AQ,{contentRef:l,descriptionId:a.descriptionId})]})]})}),_w="DialogTitle",$j=P.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Jr(_w,n);return d.jsx(_e.h2,{id:s.titleId,...r,ref:t})});$j.displayName=_w;var Nj="DialogDescription",_Q=P.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Jr(Nj,n);return d.jsx(_e.p,{id:s.descriptionId,...r,ref:t})});_Q.displayName=Nj;var Fj="DialogClose",zj=P.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,s=Jr(Fj,n);return d.jsx(_e.button,{type:"button",...r,ref:t,onClick:re(e.onClick,()=>s.onOpenChange(!1))})});zj.displayName=Fj;function Tw(e){return e?"open":"closed"}var Bj="DialogTitleWarning",[Tae,Uj]=aZ(Bj,{contentName:Xi,titleName:_w,docsSlug:"dialog"}),TQ=({titleId:e})=>{const t=Uj(Bj),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
261
|
-
|
|
262
|
-
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
263
|
-
|
|
264
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return P.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},MQ="DialogDescriptionWarning",AQ=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Uj(MQ).contentName}}.`;return P.useEffect(()=>{var o;const s=(o=e.current)==null?void 0:o.getAttribute("aria-describedby");t&&s&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},jQ=Mj,OQ=Oj,DQ=Dj,RQ=Rj;const Hj=()=>{},Kj=P.createContext(null);function LQ({onEvent:e,children:t}){return d.jsx(Kj.Provider,{value:e??Hj,children:t})}function Zt(){return P.useContext(Kj)??Hj}const Wj=P.createContext(null);function $Q({children:e}){const t=F(),n=Zt(),[r,s]=P.useState([]),o=P.useCallback(c=>{const u=c.id??ct();return s(h=>[...h.filter(p=>p.id!==c.id),{...c,id:u}]),n("open-menu",{source:"dialog",id:u}),t.addOpenMenu(u),u},[t,n]),i=P.useCallback((c,u)=>(s(h=>h.map(p=>p.id===c?{...p,...u}:p)),n("open-menu",{source:"dialog",id:c}),t.addOpenMenu(c),c),[t,n]),a=P.useCallback(c=>(s(u=>u.filter(h=>{var p;return h.id===c?((p=h.onClose)==null||p.call(h),!1):!0})),n("close-menu",{source:"dialog",id:c}),t.deleteOpenMenu(c),c),[t,n]),l=P.useCallback(()=>{s(c=>(c.forEach(u=>{var h;(h=u.onClose)==null||h.call(u),n("close-menu",{source:"dialog",id:u.id}),t.deleteOpenMenu(u.id)}),[]))},[t,n]);return d.jsx(Wj.Provider,{value:{dialogs:r,addDialog:o,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function aa(){const e=P.useContext(Wj);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const NQ=({id:e,component:t,onClose:n})=>{const{removeDialog:r}=aa(),s=$t(),o=P.useCallback(i=>{if(!i){if(n)try{n()}catch(a){console.warn(a)}r(e)}},[e,n,r]);return d.jsx(jQ,{onOpenChange:o,defaultOpen:!0,children:d.jsx(OQ,{container:s,children:d.jsx(DQ,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&o(!1)},children:d.jsx(RQ,{dir:"ltr",className:"tlui-dialog__content",children:d.jsx(t,{onClose:()=>o(!1)})})})})})};function FQ(){const{dialogs:e}=aa();return e.map(t=>d.jsx(NQ,{...t},t.id))}const zQ=Ce.memo(FQ);function BQ(){const e=F(),t=K("follow",()=>e.getInstanceState().followingUserId,[e]);return t?d.jsx(UQ,{userId:t}):null}function UQ({userId:e}){const t=Yf(e);return t?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:t.color}}):null}function Eg(e){const t=e+"CollectionProvider",[n,r]=Ms(t),[s,o]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:S,children:y}=f,x=Ce.useRef(null),m=Ce.useRef(new Map).current;return d.jsx(s,{scope:S,itemMap:m,collectionRef:x,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=Ce.forwardRef((f,S)=>{const{scope:y,children:x}=f,m=o(a,y),v=qe(S,m.collectionRef);return d.jsx(Yi,{ref:v,children:x})});l.displayName=a;const c=e+"CollectionItemSlot",u="data-radix-collection-item",h=Ce.forwardRef((f,S)=>{const{scope:y,children:x,...m}=f,v=Ce.useRef(null),w=qe(S,v),C=o(c,y);return Ce.useEffect(()=>(C.itemMap.set(v,{ref:v,...m}),()=>void C.itemMap.delete(v))),d.jsx(Yi,{[u]:"",ref:w,children:x})});h.displayName=c;function p(f){const S=o(e+"CollectionConsumer",f);return Ce.useCallback(()=>{const x=S.collectionRef.current;if(!x)return[];const m=Array.from(x.querySelectorAll(`[${u}]`));return Array.from(S.itemMap.values()).sort((C,E)=>m.indexOf(C.ref.current)-m.indexOf(E.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},p,r]}var HQ="VisuallyHidden",Mw=P.forwardRef((e,t)=>d.jsx(_e.span,{...e,ref:t,style:{position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal",...e.style}}));Mw.displayName=HQ;var Aw="ToastProvider",[jw,KQ,WQ]=Eg("Toast"),[Gj,Mae]=Ms("Toast",[WQ]),[GQ,kg]=Gj(Aw),Vj=e=>{const{__scopeToast:t,label:n="Notification",duration:r=5e3,swipeDirection:s="right",swipeThreshold:o=50,children:i}=e,[a,l]=P.useState(null),[c,u]=P.useState(0),h=P.useRef(!1),p=P.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${Aw}\`. Expected non-empty \`string\`.`),d.jsx(jw.Provider,{scope:t,children:d.jsx(GQ,{scope:t,label:n,duration:r,swipeDirection:s,swipeThreshold:o,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:P.useCallback(()=>u(f=>f+1),[]),onToastRemove:P.useCallback(()=>u(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:p,children:i})})};Vj.displayName=Aw;var Yj="ToastViewport",VQ=["F8"],Wv="toast.viewportPause",Gv="toast.viewportResume",Xj=P.forwardRef((e,t)=>{const{__scopeToast:n,hotkey:r=VQ,label:s="Notifications ({hotkey})",...o}=e,i=kg(Yj,n),a=KQ(n),l=P.useRef(null),c=P.useRef(null),u=P.useRef(null),h=P.useRef(null),p=qe(t,h,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=i.toastCount>0;P.useEffect(()=>{const x=m=>{var w;r.every(C=>m[C]||m.code===C)&&((w=h.current)==null||w.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),P.useEffect(()=>{const x=l.current,m=h.current;if(S&&x&&m){const v=()=>{if(!i.isClosePausedRef.current){const _=new CustomEvent(Wv);m.dispatchEvent(_),i.isClosePausedRef.current=!0}},w=()=>{if(i.isClosePausedRef.current){const _=new CustomEvent(Gv);m.dispatchEvent(_),i.isClosePausedRef.current=!1}},C=_=>{!x.contains(_.relatedTarget)&&w()},E=()=>{x.contains(document.activeElement)||w()};return x.addEventListener("focusin",v),x.addEventListener("focusout",C),x.addEventListener("pointermove",v),x.addEventListener("pointerleave",E),window.addEventListener("blur",v),window.addEventListener("focus",w),()=>{x.removeEventListener("focusin",v),x.removeEventListener("focusout",C),x.removeEventListener("pointermove",v),x.removeEventListener("pointerleave",E),window.removeEventListener("blur",v),window.removeEventListener("focus",w)}}},[S,i.isClosePausedRef]);const y=P.useCallback(({tabbingDirection:x})=>{const v=a().map(w=>{const C=w.ref.current,E=[C,...iJ(C)];return x==="forwards"?E:E.reverse()});return(x==="forwards"?v.reverse():v).flat()},[a]);return P.useEffect(()=>{const x=h.current;if(x){const m=v=>{var E,_,I;const w=v.altKey||v.ctrlKey||v.metaKey;if(v.key==="Tab"&&!w){const k=document.activeElement,T=v.shiftKey;if(v.target===x&&T){(E=c.current)==null||E.focus();return}const $=y({tabbingDirection:T?"backwards":"forwards"}),j=$.findIndex(O=>O===k);_y($.slice(j+1))?v.preventDefault():T?(_=c.current)==null||_.focus():(I=u.current)==null||I.focus()}};return x.addEventListener("keydown",m),()=>x.removeEventListener("keydown",m)}},[a,y]),d.jsxs(IZ,{ref:l,role:"region","aria-label":s.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:S?void 0:"none"},children:[S&&d.jsx(Vv,{ref:c,onFocusFromOutsideViewport:()=>{const x=y({tabbingDirection:"forwards"});_y(x)}}),d.jsx(jw.Slot,{scope:n,children:d.jsx(_e.ol,{tabIndex:-1,...o,ref:p})}),S&&d.jsx(Vv,{ref:u,onFocusFromOutsideViewport:()=>{const x=y({tabbingDirection:"backwards"});_y(x)}})]})});Xj.displayName=Yj;var qj="ToastFocusProxy",Vv=P.forwardRef((e,t)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...s}=e,o=kg(qj,n);return d.jsx(Mw,{"aria-hidden":!0,tabIndex:0,...s,ref:t,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=o.viewport)!=null&&c.contains(a))&&r()}})});Vv.displayName=qj;var _g="Toast",YQ="toast.swipeStart",XQ="toast.swipeMove",qQ="toast.swipeCancel",ZQ="toast.swipeEnd",Zj=P.forwardRef((e,t)=>{const{forceMount:n,open:r,defaultOpen:s,onOpenChange:o,...i}=e,[a=!0,l]=ui({prop:r,defaultProp:s,onChange:o});return d.jsx(Qr,{present:n||a,children:d.jsx(eJ,{open:a,...i,ref:t,onClose:()=>l(!1),onPause:Xt(e.onPause),onResume:Xt(e.onResume),onSwipeStart:re(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:re(e.onSwipeMove,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:re(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:re(e.onSwipeEnd,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});Zj.displayName=_g;var[QQ,JQ]=Gj(_g,{onClose(){}}),eJ=P.forwardRef((e,t)=>{const{__scopeToast:n,type:r="foreground",duration:s,open:o,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:p,onSwipeEnd:f,...S}=e,y=kg(_g,n),[x,m]=P.useState(null),v=qe(t,O=>m(O)),w=P.useRef(null),C=P.useRef(null),E=s||y.duration,_=P.useRef(0),I=P.useRef(E),k=P.useRef(0),{onToastAdd:T,onToastRemove:M}=y,D=Xt(()=>{var R;(x==null?void 0:x.contains(document.activeElement))&&((R=y.viewport)==null||R.focus()),i()}),$=P.useCallback(O=>{!O||O===1/0||(window.clearTimeout(k.current),_.current=new Date().getTime(),k.current=window.setTimeout(D,O))},[D]);P.useEffect(()=>{const O=y.viewport;if(O){const R=()=>{$(I.current),c==null||c()},H=()=>{const B=new Date().getTime()-_.current;I.current=I.current-B,window.clearTimeout(k.current),l==null||l()};return O.addEventListener(Wv,H),O.addEventListener(Gv,R),()=>{O.removeEventListener(Wv,H),O.removeEventListener(Gv,R)}}},[y.viewport,E,l,c,$]),P.useEffect(()=>{o&&!y.isClosePausedRef.current&&$(E)},[o,E,y.isClosePausedRef,$]),P.useEffect(()=>(T(),()=>M()),[T,M]);const j=P.useMemo(()=>x?sO(x):null,[x]);return y.viewport?d.jsxs(d.Fragment,{children:[j&&d.jsx(tJ,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:j}),d.jsx(QQ,{scope:n,onClose:D,children:ia.createPortal(d.jsx(jw.ItemSlot,{scope:n,children:d.jsx(CZ,{asChild:!0,onEscapeKeyDown:re(a,()=>{y.isFocusedToastEscapeKeyDownRef.current||D(),y.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(_e.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":o?"open":"closed","data-swipe-direction":y.swipeDirection,...S,ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:re(e.onKeyDown,O=>{O.key==="Escape"&&(a==null||a(O.nativeEvent),O.nativeEvent.defaultPrevented||(y.isFocusedToastEscapeKeyDownRef.current=!0,D()))}),onPointerDown:re(e.onPointerDown,O=>{O.button===0&&(w.current={x:O.clientX,y:O.clientY})}),onPointerMove:re(e.onPointerMove,O=>{if(!w.current)return;const R=O.clientX-w.current.x,H=O.clientY-w.current.y,B=!!C.current,z=["left","right"].includes(y.swipeDirection),W=["left","up"].includes(y.swipeDirection)?Math.min:Math.max,Y=z?W(0,R):0,q=z?0:W(0,H),le=O.pointerType==="touch"?10:2,ge={x:Y,y:q},be={originalEvent:O,delta:ge};B?(C.current=ge,gh(XQ,h,be,{discrete:!1})):XI(ge,y.swipeDirection,le)?(C.current=ge,gh(YQ,u,be,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(R)>le||Math.abs(H)>le)&&(w.current=null)}),onPointerUp:re(e.onPointerUp,O=>{const R=C.current,H=O.target;if(H.hasPointerCapture(O.pointerId)&&H.releasePointerCapture(O.pointerId),C.current=null,w.current=null,R){const B=O.currentTarget,z={originalEvent:O,delta:R};XI(R,y.swipeDirection,y.swipeThreshold)?gh(ZQ,f,z,{discrete:!0}):gh(qQ,p,z,{discrete:!0}),B.addEventListener("click",W=>W.preventDefault(),{once:!0})}})})})}),y.viewport)})]}):null}),tJ=e=>{const{__scopeToast:t,children:n,...r}=e,s=kg(_g,t),[o,i]=P.useState(!1),[a,l]=P.useState(!1);return sJ(()=>i(!0)),P.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(rd,{asChild:!0,children:d.jsx(Mw,{...r,children:o&&d.jsxs(d.Fragment,{children:[s.label," ",n]})})})},nJ="ToastTitle",Qj=P.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return d.jsx(_e.div,{...r,ref:t})});Qj.displayName=nJ;var rJ="ToastDescription",Jj=P.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return d.jsx(_e.div,{...r,ref:t})});Jj.displayName=rJ;var eO="ToastAction",tO=P.forwardRef((e,t)=>{const{altText:n,...r}=e;return n.trim()?d.jsx(rO,{altText:n,asChild:!0,children:d.jsx(Ow,{...r,ref:t})}):(console.error(`Invalid prop \`altText\` supplied to \`${eO}\`. Expected non-empty \`string\`.`),null)});tO.displayName=eO;var nO="ToastClose",Ow=P.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e,s=JQ(nO,n);return d.jsx(rO,{asChild:!0,children:d.jsx(_e.button,{type:"button",...r,ref:t,onClick:re(e.onClick,s.onClose)})})});Ow.displayName=nO;var rO=P.forwardRef((e,t)=>{const{__scopeToast:n,altText:r,...s}=e;return d.jsx(_e.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:t})});function sO(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),oJ(r)){const s=r.ariaHidden||r.hidden||r.style.display==="none",o=r.dataset.radixToastAnnounceExclude==="";if(!s)if(o){const i=r.dataset.radixToastAnnounceAlt;i&&t.push(i)}else t.push(...sO(r))}}),t}function gh(e,t,n,{discrete:r}){const s=n.originalEvent.currentTarget,o=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n});t&&s.addEventListener(e,t,{once:!0}),r?Pw(s,o):s.dispatchEvent(o)}var XI=(e,t,n=0)=>{const r=Math.abs(e.x),s=Math.abs(e.y),o=r>s;return t==="left"||t==="right"?o&&r>n:!o&&s>n};function sJ(e=()=>{}){const t=Xt(e);Qo(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[t])}function oJ(e){return e.nodeType===e.ELEMENT_NODE}function iJ(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function _y(e){const t=document.activeElement;return e.some(n=>n===t?!0:(n.focus(),document.activeElement!==t))}var aJ=Zj,lJ=Qj,cJ=Jj,uJ=tO,qI=Ow;const oO=P.createContext(null);function dJ({children:e}){const[t,n]=P.useState([]),r=P.useCallback(i=>{const a=i.id??ct();return n(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),s=P.useCallback(i=>(n(a=>a.filter(l=>l.id!==i)),i),[]),o=P.useCallback(()=>{n(()=>[])},[]);return d.jsx(Vj,{children:d.jsx(oO.Provider,{value:{toasts:t,addToast:r,removeToast:s,clearToasts:o},children:e})})}function es(){const e=P.useContext(oO);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}const ue=P.forwardRef(function({children:t,disabled:n,type:r,...s},o){return d.jsx("button",{ref:o,type:"button",draggable:!1,disabled:n,...s,className:ce("tlui-button",`tlui-button__${r}`,s.className),children:t})});function bt({children:e}){return d.jsx("span",{className:"tlui-button__label",children:e})}const Is=P.memo(function({small:t,invertIcon:n,icon:r,color:s,className:o,...i}){const a=xw(),l=a.icons[r]??a.icons["question-mark-circle"],c=P.useRef(null);return P.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),r==="none"?d.jsx("div",{className:ce("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":t},o)}):d.jsx("div",{...i,ref:c,className:ce("tlui-icon",{"tlui-icon__small":t},o),style:{color:s,mask:`url(${l}) center 100% / 100% no-repeat`,transform:n?"scale(-1, 1)":void 0}})}),hJ={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function pJ({toast:e}){const{removeToast:t}=es(),n=we(),r=i=>{i||t(e.id)},s=e.actions&&e.actions.length>0,o=e.icon||e.severity&&hJ[e.severity];return d.jsxs(aJ,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[o&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(Is,{icon:o})}),d.jsxs("div",{className:"tlui-toast__main",children:[d.jsxs("div",{className:"tlui-toast__content",children:[e.title&&d.jsx(lJ,{className:"tlui-toast__title",children:e.title}),e.description&&d.jsx(cJ,{className:"tlui-toast__description",children:e.description})]}),e.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>d.jsx(uJ,{altText:i.label,asChild:!0,onClick:i.onClick,children:d.jsx(ue,{type:i.type,children:d.jsx(bt,{children:i.label})})},a)),d.jsx(qI,{asChild:!0,children:d.jsx(ue,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:d.jsx(bt,{children:e.closeLabel??n("toast.close")})})})]})]}),!s&&d.jsx(qI,{asChild:!0,children:d.jsx(ue,{type:"normal",className:"tlui-toast__close",children:d.jsx(bt,{children:e.closeLabel??n("toast.close")})})})]})}function fJ(){const{toasts:e}=es();return e.map(t=>d.jsx(pJ,{toast:t},t.id))}const gJ=P.memo(fJ);function mJ(){const e=F(),{toasts:t}=es(),[n,r]=P.useState(!1);return P.useEffect(()=>{let s=-1;return t.length?r(!0):s=e.timers.setTimeout(()=>{r(!1)},1e3),()=>{clearTimeout(s)}},[t.length,r,e]),n?d.jsx(Xj,{className:"tlui-toast__viewport"}):null}function ve({icon:e,small:t,invertIcon:n}){return d.jsx(Is,{className:"tlui-button__icon",icon:e,small:t,invertIcon:n})}const Ty=[0,390,428,468,580,640,840,1023];var yt=(e=>(e[e.ZERO=0]="ZERO",e[e.MOBILE_XXS=1]="MOBILE_XXS",e[e.MOBILE_XS=2]="MOBILE_XS",e[e.MOBILE_SM=3]="MOBILE_SM",e[e.MOBILE=4]="MOBILE",e[e.TABLET_SM=5]="TABLET_SM",e[e.TABLET=6]="TABLET",e[e.DESKTOP=7]="DESKTOP",e))(yt||{});let Yv={fonts:{draw:`${Oo()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${Oo()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${Oo()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${Oo()}/fonts/IBMPlexMono-Medium.woff2`}};function iO(e){return P.useMemo(()=>e?{fonts:{...Yv.fonts,...e==null?void 0:e.fonts}}:Yv,[e])}const yJ=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bring-forward","bring-to-front","broken","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","color","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","leading","link","lock","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","stretch-horizontal","stretch-vertical","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];let uc={...Yv,icons:Object.fromEntries(yJ.map(e=>[e,`${Oo()}/icons/icon/${e}.svg`])),translations:Object.fromEntries(iu.map(e=>[e.locale,`${Oo()}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Hu.map(e=>[e.type,`${Oo()}/embed-icons/${e.type}.png`]))};function SJ(e){return e?{fonts:Object.assign({...uc.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...uc.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...uc.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...uc.translations},{...e==null?void 0:e.translations})}:uc}function Tg({className:e,children:t}){return d.jsx("div",{className:ce("tlui-dialog__header",e),children:t})}function Mg({className:e,children:t}){return d.jsx($j,{dir:"ltr",className:ce("tlui-dialog__header__title",e),children:t})}function Ag(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(zj,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:d.jsx(ve,{small:!0,icon:"cross-2"})})})})}function Eu({className:e,children:t,style:n}){return d.jsx("div",{className:ce("tlui-dialog__body",e),style:n,children:t})}function Dw({className:e,children:t}){return d.jsx("div",{className:ce("tlui-dialog__footer",e),children:t})}const jg=P.forwardRef(function({className:t,label:n,icon:r,iconLeft:s,autoSelect:o=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:p,onBlur:f,shouldManuallyMaintainScrollPositionWhenFocused:S=!1,children:y,value:x},m){const v=F(),w=P.useRef(null);P.useImperativeHandle(m,()=>w.current);const C=we(),E=P.useRef(a??""),_=P.useRef(a??""),[I,k]=P.useState(!1),T=P.useCallback(j=>{k(!0);const O=j.currentTarget;_.current=O.value,v.timers.requestAnimationFrame(()=>{o&&O.select()}),p==null||p()},[o,p,v.timers]),M=P.useCallback(j=>{const O=j.currentTarget.value;_.current=O,u==null||u(O)},[u]),D=P.useCallback(j=>{switch(j.key){case"Enter":{j.currentTarget.blur(),Ot(j),c==null||c(j.currentTarget.value);break}case"Escape":{j.currentTarget.value=E.current,j.currentTarget.blur(),Ot(j),h==null||h(j.currentTarget.value);break}}},[c,h]),$=P.useCallback(j=>{k(!1);const O=j.currentTarget.value;f==null||f(O)},[f]);return P.useEffect(()=>{if(!v.environment.isIos)return;const j=window.visualViewport;if(I&&S&&j){const O=()=>{var R;(R=w.current)==null||R.scrollIntoView({block:"center"})};return j.addEventListener("resize",O),j.addEventListener("scroll",O),v.timers.requestAnimationFrame(()=>{var R;(R=w.current)==null||R.scrollIntoView({block:"center"})}),()=>{j.removeEventListener("resize",O),j.removeEventListener("scroll",O)}}},[v,I,S]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[y,n&&d.jsx("label",{children:C(n)}),s&&d.jsx(Is,{icon:s,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:w,className:ce("tlui-input",t),type:"text",defaultValue:a,onKeyUp:D,onChange:M,onFocus:T,onBlur:$,autoFocus:i,placeholder:l,value:x}),r&&d.jsx(Is,{icon:r,small:!!n})]})}),aO=Lt(function({onClose:t}){const n=F(),r=we(),s=xw(),[o,i]=P.useState(null),[a,l]=P.useState(""),[c,u]=P.useState(null),[h,p]=P.useState(!1),f=P.useRef(-1);return d.jsxs(d.Fragment,{children:[d.jsxs(Tg,{children:[d.jsx(Mg,{children:o?`${r("embed-dialog.title")} — ${o.title}`:r("embed-dialog.title")}),d.jsx(Ag,{})]}),o?d.jsxs(d.Fragment,{children:[d.jsxs(Eu,{className:"tlui-embed-dialog__enter",children:[d.jsx(jg,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:S=>{l(S);const y=Ro(S);u(y&&y.definition.type===o.type?y:null),p(!1),clearTimeout(f.current),f.current=n.timers.setTimeout(()=>p(!y),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",o.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:o.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(Is,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(Dw,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(bt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(ue,{type:"normal",onClick:t,children:d.jsx(bt,{children:r("embed-dialog.cancel")})}),d.jsx(ue,{type:"primary",disabled:!c,onClick:()=>{c&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageBounds().center,embed:c.definition}),t())},children:d.jsx(bt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(Eu,{className:"tlui-embed-dialog__list",children:Hu.map(S=>d.jsxs(ue,{type:"menu",onClick:()=>i(S),children:[d.jsx(bt,{children:S.title}),d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${s.embedIcons[S.type]})`}})]},S.type))})})]})});function lO(){const e=F(),t=P.useRef();return P.useEffect(()=>{const n=window.document.createElement("input");n.type="file",n.accept=wB,n.multiple=!0,t.current=n;async function r(s){const o=s.target.files;!o||o.length===0||(e.mark("insert media"),await e.putExternalContent({type:"files",files:Array.from(o),point:e.getViewportPageBounds().center,ignoreParent:!1}),n.value="")}return n.addEventListener("change",r),()=>{t.current=void 0,n.removeEventListener("change",r)}},[e]),P.useCallback(()=>{var n;(n=t.current)==null||n.click()},[t])}const cO=P.createContext(null);function vJ({overrides:e,children:t}){const n=F(),r=Zt(),{addDialog:s}=aa(),o=lO(),i=P.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){n.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){n.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){n.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){n.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...Ur.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){n.run(()=>{n.setStyleForNextShapes(Ur,c),n.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){n.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){n.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){n.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){n.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){o(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){n.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){n.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(c){s({component:aO}),r("select-tool",{source:c,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){n.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}}];a.push();const l=Object.fromEntries(a.map(c=>[c.id,c]));return e?e(n,l,{insertMedia:o}):l},[e,n,r,o,s]);return d.jsx(cO.Provider,{value:i,children:t})}function Og(){const e=P.useContext(cO);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const uO=Ce.createContext(null);function xJ({forceMobile:e=!1,children:t}){const n=F(),r=K("breakpoint",()=>{const{width:s}=n.getViewportScreenBounds(),o=e?yt.MOBILE_SM:Ty.length-1;for(let i=0;i<o;i++)if(s>Ty[i]&&s<=Ty[i+1])return i;return o},[n]);return d.jsx(uO.Provider,{value:r,children:t})}function In(){const e=P.useContext(uO);if(e===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}function wJ(){const{addToast:e,removeToast:t,clearToasts:n}=es(),{addDialog:r,clearDialogs:s,removeDialog:o,updateDialog:i}=aa(),l=In()<yt.TABLET_SM,c=we();return P.useMemo(()=>({addToast:e,removeToast:t,clearToasts:n,addDialog:r,clearDialogs:s,removeDialog:o,updateDialog:i,msg:c,isMobile:l}),[r,e,s,n,c,o,t,i,l])}function bJ(e,t){const n={};for(const r of e)if(r.translations)for(const[s,o]of Bn(r.translations)){let i=n[s];i||(i=n[s]={}),Object.assign(i,o)}return{actions:(r,s)=>{for(const o of e)o.actions&&(s=o.actions(r,s,t));return s},tools:(r,s,o)=>{for(const i of e)i.tools&&(s=i.tools(r,s,{...t,...o}));return s},translations:n}}function dO(e){return P.useMemo(()=>e,e)}function PJ(e){const t=dO(e==null?[]:Array.isArray(e)?e:[e]);return P.useMemo(()=>{const n={};for(const r of t)if(r.translations)for(const[s,o]of Bn(r.translations)){let i=n[s];i||(i=n[s]={}),Object.assign(i,o)}return n},[t])}function CJ(e){const t=wJ(),n=dO(e==null?[]:Array.isArray(e)?e:[e]);return P.useMemo(()=>bJ(n,t),[n,t])}function IJ(e,t){const n=ye(t.map(s=>e.getShape(s)).filter(s=>s&&e.isShapeOfType(s,"frame")));if(!n.length)return;const r=[];e.run(()=>{n.map(s=>{const o=e.getSortedChildIdsForParent(s.id);o.length&&(e.reparentShapes(o,s.parentId,s.index),r.push(...o))}),e.setSelectedShapes(r),e.deleteShapes(t)})}const EJ=50;function kJ(e,t,n={}){const r=e.getShape(t);if(!r)return;const s=e.getSortedChildIdsForParent(r.id),o=ye(s.map(f=>e.getShape(f)));if(!o.length)return;const i=Q.FromPoints(o.flatMap(f=>{const S=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(S.vertices)})),{padding:a=EJ}=n,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,h=a-i.minY;if(u===0&&h===0&&r.props.w===l&&r.props.h===c)return;const p=new b(u,h).rot(r.rotation);e.run(()=>{const f=s.map(S=>{const y=e.getShape(S);return{id:y.id,type:y.type,x:y.x+u,y:y.y+h}});f.push({id:r.id,type:r.type,x:r.x-p.x,y:r.y-p.y,props:{w:l,h:c}}),e.updateShapes(f)})}function ZI(e){return lr.isValid(e)?{isValid:!0,hasProtocol:!0}:lr.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const _J=Lt(function({onClose:t}){const r=F().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(TJ,{onClose:t,selectedShape:r}):null}),TJ=Lt(function({onClose:t,selectedShape:n}){const r=F(),s=we(),o=P.useRef(null);P.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var S;return(S=o.current)==null?void 0:S.focus()})},[r]);const i=P.useRef(n.props.url),[a,l]=P.useState(()=>{const S=ZI(n.props.url),y=S.isValid===!0?S.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:y,safe:y,valid:!0}}),c=P.useCallback(S=>{const y=S.replace(/https?:\/\/(https?:\/\/)/,(v,w)=>w),x=ZI(y),m=x.isValid===!0?x.hasProtocol?y:"https://"+y:"https://";l({actual:y,safe:m,valid:x.isValid})},[]),u=P.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(r.updateShapes([{id:S.id,type:S.type,props:{url:""}}]),t())},[r,t]),h=P.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(S&&"url"in S.props&&S.props.url!==a.safe&&r.updateShapes([{id:S.id,type:S.type,props:{url:a.safe}}]),t())},[r,t,a]),p=P.useCallback(()=>{t()},[t]);if(!n)return t(),null;const f=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(Tg,{children:[d.jsx(Mg,{children:s("edit-link-dialog.title")}),d.jsx(Ag,{})]}),d.jsx(Eu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(jg,{ref:o,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:p}),d.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),d.jsxs(Dw,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:p,onTouchEnd:p,children:d.jsx(bt,{children:s("edit-link-dialog.cancel")})}),f?d.jsx(ue,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(bt,{children:s("edit-link-dialog.clear")})}):d.jsx(ue,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(bt,{children:s("edit-link-dialog.save")})})]})]})});var Rw={exports:{}};Rw.exports;(function(e){var t=function(){var n=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",o={};function i(l,c){if(!o[l]){o[l]={};for(var u=0;u<l.length;u++)o[l][l.charAt(u)]=u}return o[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return n(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),h=0,p=c.length;h<p;h++){var f=c.charCodeAt(h);u[h*2]=f>>>8,u[h*2+1]=f%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var p=[];return c.forEach(function(f){p.push(n(f))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return s.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(s,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return n(c)})},_compress:function(l,c,u){if(l==null)return"";var h,p,f={},S={},y="",x="",m="",v=2,w=3,C=2,E=[],_=0,I=0,k;for(k=0;k<l.length;k+=1)if(y=l.charAt(k),Object.prototype.hasOwnProperty.call(f,y)||(f[y]=w++,S[y]=!0),x=m+y,Object.prototype.hasOwnProperty.call(f,x))m=x;else{if(Object.prototype.hasOwnProperty.call(S,m)){if(m.charCodeAt(0)<256){for(h=0;h<C;h++)_=_<<1,I==c-1?(I=0,E.push(u(_)),_=0):I++;for(p=m.charCodeAt(0),h=0;h<8;h++)_=_<<1|p&1,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=p>>1}else{for(p=1,h=0;h<C;h++)_=_<<1|p,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=0;for(p=m.charCodeAt(0),h=0;h<16;h++)_=_<<1|p&1,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=p>>1}v--,v==0&&(v=Math.pow(2,C),C++),delete S[m]}else for(p=f[m],h=0;h<C;h++)_=_<<1|p&1,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=p>>1;v--,v==0&&(v=Math.pow(2,C),C++),f[x]=w++,m=String(y)}if(m!==""){if(Object.prototype.hasOwnProperty.call(S,m)){if(m.charCodeAt(0)<256){for(h=0;h<C;h++)_=_<<1,I==c-1?(I=0,E.push(u(_)),_=0):I++;for(p=m.charCodeAt(0),h=0;h<8;h++)_=_<<1|p&1,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=p>>1}else{for(p=1,h=0;h<C;h++)_=_<<1|p,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=0;for(p=m.charCodeAt(0),h=0;h<16;h++)_=_<<1|p&1,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=p>>1}v--,v==0&&(v=Math.pow(2,C),C++),delete S[m]}else for(p=f[m],h=0;h<C;h++)_=_<<1|p&1,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=p>>1;v--,v==0&&(v=Math.pow(2,C),C++)}for(p=2,h=0;h<C;h++)_=_<<1|p&1,I==c-1?(I=0,E.push(u(_)),_=0):I++,p=p>>1;for(;;)if(_=_<<1,I==c-1){E.push(u(_));break}else I++;return E.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],p=4,f=4,S=3,y="",x=[],m,v,w,C,E,_,I,k={val:u(0),position:c,index:1};for(m=0;m<3;m+=1)h[m]=m;for(w=0,E=Math.pow(2,2),_=1;_!=E;)C=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),w|=(C>0?1:0)*_,_<<=1;switch(w){case 0:for(w=0,E=Math.pow(2,8),_=1;_!=E;)C=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),w|=(C>0?1:0)*_,_<<=1;I=n(w);break;case 1:for(w=0,E=Math.pow(2,16),_=1;_!=E;)C=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),w|=(C>0?1:0)*_,_<<=1;I=n(w);break;case 2:return""}for(h[3]=I,v=I,x.push(I);;){if(k.index>l)return"";for(w=0,E=Math.pow(2,S),_=1;_!=E;)C=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),w|=(C>0?1:0)*_,_<<=1;switch(I=w){case 0:for(w=0,E=Math.pow(2,8),_=1;_!=E;)C=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),w|=(C>0?1:0)*_,_<<=1;h[f++]=n(w),I=f-1,p--;break;case 1:for(w=0,E=Math.pow(2,16),_=1;_!=E;)C=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),w|=(C>0?1:0)*_,_<<=1;h[f++]=n(w),I=f-1,p--;break;case 2:return x.join("")}if(p==0&&(p=Math.pow(2,S),S++),h[I])y=h[I];else if(I===f)y=v+v.charAt(0);else return null;x.push(y),h[f++]=v+y.charAt(0),p--,v=y,p==0&&(p=Math.pow(2,S),S++)}}};return a}();e!=null?e.exports=t:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return t})})(Rw);var MJ=Rw.exports;const hO=ni(MJ);async function AJ(e,t,n){var m,v,w;const{elements:r,files:s}=t,o={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,l=e.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(C=>{if(c.set(C.id,$e()),C.boundElements!==null)for(const E of C.boundElements)E.type==="text"&&h.add(E.id)});let p=Zk;for(const C of r){if(h.has(C.id))continue;const E=c.get(C.id),_={id:E,typeName:"shape",parentId:l,index:p,x:C.x,y:C.y,rotation:0,isLocked:C.locked,opacity:jJ(C.opacity),meta:{}};switch(C.angle!==0&&a.set(E,C.angle),C.groupIds&&C.groupIds.length>0?i.has(C.groupIds[0])?(m=i.get(C.groupIds[0]))==null||m.push(E):i.set(C.groupIds[0],[E]):u.push(E),C.type){case"rectangle":case"ellipse":case"diamond":{let I="",k="middle";if(C.boundElements!==null){for(const M of C.boundElements)if(M.type==="text"){const D=r.find($=>$.id===M.id);D&&(I=D.text,k=NJ[D.textAlign])}}const T=C.backgroundColor==="transparent"?C.strokeColor:C.backgroundColor;o.shapes.push({..._,type:"geo",props:{geo:C.type,url:C.link??"",w:C.width,h:C.height,size:mh[C.strokeWidth]??"draw",color:dc[T]??"black",text:I,align:k,dash:yh(C),fill:BJ(C)}});break}case"freedraw":{o.shapes.push({..._,type:"draw",props:{dash:yh(C),size:mh[C.strokeWidth],color:dc[C.strokeColor]??"black",segments:[{type:"free",points:C.points.map(([I,k,T=.5])=>({x:I,y:k,z:T}))}]}});break}case"line":{if(C.points.slice().length<2)break;const k=su(C.points.length);o.shapes.push({..._,type:"line",props:{dash:yh(C),size:mh[C.strokeWidth],color:dc[C.strokeColor]??"black",spline:C.roundness?"cubic":"line",points:{...Object.fromEntries(C.points.map(([T,M],D)=>{const $=k[D];return[$,{id:$,index:$,x:T,y:M}]}))}}});break}case"arrow":{let I="";if(C.boundElements!==null){for(const $ of C.boundElements)if($.type==="text"){const j=r.find(O=>O.id===$.id);j&&(I=j.text)}}const k=C.points[0],T=C.points[C.points.length-1],M=c.get((v=C.startBinding)==null?void 0:v.elementId),D=c.get((w=C.endBinding)==null?void 0:w.elementId);o.shapes.push({..._,type:"arrow",props:{text:I,bend:zJ(C,k,T),dash:yh(C),size:mh[C.strokeWidth]??"m",color:dc[C.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:T[0],y:T[1]},arrowheadEnd:QI[C.endArrowhead]??"none",arrowheadStart:QI[C.startArrowhead]??"none"}}),M&&o.bindings.push({id:ji(),typeName:"binding",type:"arrow",fromId:E,toId:M,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),D&&o.bindings.push({id:ji(),typeName:"binding",type:"arrow",fromId:E,toId:D,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:I,scale:k}=DJ(C.fontSize);o.shapes.push({..._,type:"text",props:{size:I,scale:k,font:RJ[C.fontFamily]??"draw",color:dc[C.strokeColor]??"black",text:C.text,textAlign:FJ[C.textAlign]}});break}case"image":{const I=s[C.fileId];if(!I)break;const k=Ii.createId();o.assets.push({id:k,typeName:"asset",type:"image",props:{w:C.width,h:C.height,fileSize:I.size,name:C.id??"Untitled",isAnimated:!1,mimeType:I.mimeType,src:I.dataURL},meta:{}}),o.shapes.push({..._,type:"image",props:{w:C.width,h:C.height,assetId:k}})}}p=zr(p)}const f=n??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(o,{point:f,select:!1,preserveIds:!0});for(const C of i.values())if(C.length>1){e.groupShapes(C);const E=e.getShape(C[0]);E!=null&&E.parentId&&jn(E.parentId)&&u.push(E.parentId)}for(const[C,E]of a)e.select(C),e.rotateShapesBy([C],E);const S=ye(u.map(C=>e.getShape(C))),y=Q.Common(S.map(C=>e.getShapePageBounds(C))),x=e.getViewportPageBounds().center;e.updateShapes(S.map(C=>{const E={x:(C.x??0)-(y.x+y.w/2),y:(C.y??0)-(y.y+y.h/2)};return{id:C.id,type:C.type,x:x.x+E.x,y:x.y+E.y}})),e.setSelectedShapes(u)}const jJ=e=>{const t=e/100;return t<.2?.1:t<.4?.25:t<.6?.5:t<.8?.75:1},mh={1:"s",2:"m",3:"l",4:"xl"},OJ={16:"s",20:"m",28:"l",36:"xl"};function DJ(e){const t=OJ[e];return t?{size:t,scale:1}:e<16?{size:"s",scale:e/16}:e>36?{size:"xl",scale:e/36}:{size:"m",scale:1}}const RJ={1:"draw",2:"sans",3:"mono"},dc={"#ffffff":"grey","#000000":"black","#343a40":"black","#495057":"grey","#c92a2a":"red","#a61e4d":"light-red","#862e9c":"violet","#5f3dc4":"light-violet","#364fc7":"blue","#1864ab":"light-blue","#0b7285":"light-green","#087f5b":"light-green","#2b8a3e":"green","#5c940d":"light-green","#e67700":"yellow","#d9480f":"orange","#ced4da":"grey","#868e96":"grey","#fa5252":"light-red","#e64980":"red","#be4bdb":"light-violet","#7950f2":"violet","#4c6ef5":"blue","#228be6":"light-blue","#15aabf":"light-green","#12b886":"green","#40c057":"green","#82c91e":"light-green","#fab005":"yellow","#fd7e14":"orange","#212529":"grey"},LJ={solid:"draw",dashed:"dashed",dotted:"dotted"},$J={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},NJ={left:"start",center:"middle",right:"end"},FJ={left:"start",center:"middle",right:"end"},QI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function zJ(e,t,n){let r=0;if(e.points.length>2){const s=new b(t[0],t[1]),o=new b(n[0],n[1]),i=new b(e.points[1][0],e.points[1][1]),a=b.Sub(o,s),l=b.Per(a),c=b.Med(o,s),u=b.Sub(c,l),h=b.Add(c,l),p=b.NearestPointOnLineSegment(u,h,i,!1);r=b.Dist(p,c),b.Clockwise(p,o,c)&&(r*=-1)}return r}const yh=e=>{let t=LJ[e.strokeStyle]??"draw";return t==="draw"&&e.roughness===0&&(t="solid"),t},BJ=e=>e.backgroundColor==="transparent"?"none":$J[e.fillStyle]??"solid";async function UJ(e,t,n,r){const o=(await Promise.all(t.map(async i=>await(await ws(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:o,point:n,ignoreParent:!1,sources:r}),t.forEach(i=>URL.revokeObjectURL(i))}function HJ(e,t,n){const r=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(t,{point:n,select:!0});const s=e.getSelectionPageBounds();r&&s&&(r!=null&&r.collides(s))&&(e.updateInstanceState({isChangingStyle:!0}),e.timers.setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1})},150))}async function Xv(e,t,n,r){return e.mark("paste"),await e.putExternalContent({type:"url",point:n,url:t,sources:r})}function KJ(e){const t=document.implementation.createHTMLDocument("");return t.documentElement.innerHTML=e.trim(),t.body.textContent||t.body.innerText||""}const WJ=e=>{try{const t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}},GJ=e=>{const t=e.split(/[\n\s]/);for(const n of t)try{const r=new URL(n);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return f2(t)},VJ=e=>/^<svg/.test(e),YJ=["input","select","textarea"];function My(e){const{activeElement:t}=document;return e.getIsMenuOpen()||t&&(t.getAttribute("contenteditable")||YJ.indexOf(t.tagName.toLowerCase())>-1)}const XJ=e=>e.types.find(t=>t.match(/^image\//)),Ay=(e,t,n,r)=>{const s=GJ(t);if(s)for(const o of s)Xv(e,o,n);else WJ(t)?Xv(e,t,n):VJ(t)?(e.mark("paste"),e.putExternalContent({type:"svg-text",text:t,point:n,sources:r})):(e.mark("paste"),e.putExternalContent({type:"text",text:t,point:n,sources:r}))},qJ=async(e,t,n)=>{if(e.getEditingShapeId()!==null)return;if(!t)throw Error("No clipboard data");const r=[];for(const s of Object.values(t.items))switch(s.kind){case"file":{r.push({type:"file",source:new Promise(o=>o(s.getAsFile()))});break}case"string":{s.type==="text/html"?r.push({type:"html",source:new Promise(o=>s.getAsString(o))}):s.type==="text/plain"?r.push({type:"text",source:new Promise(o=>s.getAsString(o))}):r.push({type:s.type,source:new Promise(o=>s.getAsString(o))});break}}fO(e,r,n)},pO=async(e,t,n)=>{const r=[];for(const s of t){if(XJ(s))for(const o of s.types)o.match(/^image\//)&&r.push({type:"blob",source:s.getType(o)});s.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const o=await s.getType("text/html");return await Ai.blobToText(o)})()}),s.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const o=await s.getType("text/uri-list");return await Ai.blobToText(o)})()}),s.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const o=await s.getType("text/plain");return await Ai.blobToText(o)})()})}return await fO(e,r,n)};async function fO(e,t,n){const r=t.filter(o=>(o.type==="file"||o.type==="blob")&&o.source!==null);if(r.length){const i=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await UJ(e,i,n)}const s=await Promise.all(t.filter(o=>o.type!=="file").map(o=>new Promise(i=>{const a=o;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=hO.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(h);if(p.type!=="application/tldraw"&&i({type:"error",data:p,reason:`found tldraw data comment but JSON was of a different type: ${p.type}`}),typeof p.data=="string"){i({type:"error",data:p,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:p.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const h=JSON.parse(l);if(h.type==="excalidraw/clipboard"){i({type:"excalidraw",data:h});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const o of s)if(o.type==="tldraw"){HJ(e,o.data,n);return}for(const o of s)if(o.type==="excalidraw"){AJ(e,o.data,n);return}for(const o of s)if(o.type==="text"&&o.subtype==="html"){const a=new DOMParser().parseFromString(o.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");Ay(e,c,n,s);return}if(!s.some(c=>c.type==="text"&&c.subtype!=="html")&&o.data.trim()){Ay(e,KJ(o.data),n,s);return}}for(const o of s)if(o.type==="text"&&o.subtype==="url"){Xv(e,o.data,n,s);return}for(const o of s)if(o.type==="text"&&o.subtype==="text"&&o.data.trim()){Ay(e,o.data,n,s);return}}const If=async e=>{var r;const t=await e.resolveAssetsInContent(e.getContentFromCurrentPage(e.getSelectedShapeIds()));if(!t){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=hO.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:t}));if(!(typeof navigator>"u")){const s=t.shapes.map(o=>e.isShapeOfType(o,"text")||e.isShapeOfType(o,"geo")||e.isShapeOfType(o,"arrow")?o.props.text:e.isShapeOfType(o,"bookmark")||e.isShapeOfType(o,"embed")?o.props.url:null).filter(jB);if((r=navigator.clipboard)!=null&&r.write){const o=new Blob([`<div data-tldraw>${n}</div>`],{type:"text/html"});let i=s.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<div data-tldraw>${n}</div>`)}};function ZJ(){const e=F(),t=Zt(),n=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await If(e),t("copy",{source:i}))},[e,t]),r=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await If(e),e.deleteShapes(e.getSelectedShapeIds()),t("cut",{source:i}))},[e,t]),s=P.useCallback(async function(i,a,l){e.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(pO(e,i,l),t("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{s(c,a,l)}))},[e,t]);return{copy:n,cut:r,paste:s}}function QJ(){const e=F(),t=Zt(),n=K("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!n)return;const r=async l=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||My(e)||(Ee(l),await If(e),t("copy",{source:"kbd"}))};async function s(l){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||My(e)||(Ee(l),await If(e),e.deleteShapes(e.getSelectedShapeIds()),t("cut",{source:"kbd"}))}let o=!1;const i=l=>{l.button===1&&(o=!0,e.timers.requestAnimationFrame(()=>{o=!1}))},a=l=>{if(o){Ot(l);return}if(e.getEditingShapeId()!==null||My(e))return;let c,u=!1;e.inputs.shiftKey&&(u=!0),e.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=e.inputs.currentPagePoint),l.clipboardData&&!e.inputs.shiftKey?qJ(e,l.clipboardData,c):navigator.clipboard.read().then(h=>{Array.isArray(h)&&h[0]instanceof ClipboardItem&&pO(e,h,c)}),Ee(l),t("paste",{source:"kbd"})};return document.addEventListener("copy",r),document.addEventListener("cut",s),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",s),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[e,t,n])}async function gO(e,t,n){const{type:r,quality:s,scale:o,width:i,height:a}=n;let[l,c]=await NY(i*o,a*o);l=Math.floor(l),c=Math.floor(c);const u=l/i,h=URL.createObjectURL(new Blob([t],{type:"image/svg+xml"})),p=await new Promise(S=>{const y=ol();y.crossOrigin="anonymous",y.onload=async()=>{e.environment.isSafari&&await new Promise(v=>e.timers.setTimeout(v,250));const x=document.createElement("canvas"),m=x.getContext("2d");x.width=l,x.height=c,m.imageSmoothingEnabled=!0,m.imageSmoothingQuality="high",m.drawImage(y,0,0,l,c),URL.revokeObjectURL(h),S(x)},y.onerror=()=>{S(null)},y.src=h});if(!p)return null;const f=await new Promise(S=>p.toBlob(y=>{(!y||xt.throwToBlob.get())&&S(null),S(y)},"image/"+r,s));if(!f)return null;if(r==="png"){const S=new DataView(await f.arrayBuffer());return ls.setPhysChunk(S,u,{type:"image/"+r})}else return f}async function mO(e,t,n){const r=await e.getSvgString(t!=null&&t.length?t:[...e.getCurrentPageShapeIds()],{scale:1,background:e.getInstanceState().exportBackground,...n});if(!r)throw new Error("Could not construct SVG.");return r}async function qv(e,t,n,r={}){var s;switch(n){case"svg":return(s=await mO(e,t,r))==null?void 0:s.svg;case"json":{const o=await e.resolveAssetsInContent(e.getContentFromCurrentPage(t));return JSON.stringify(o)}default:un(n)}}async function yO({editor:e,ids:t,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await qv(e,t,"svg",r)],{type:"text/plain"});case"json":return new Blob([await qv(e,t,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const s=await mO(e,t,r);if(!s)throw new Error("Could not construct image.");const o=await gO(e,s.svg,{type:n,quality:1,scale:2,width:s.width,height:s.height});if(!o)throw new Error("Could not construct image.");return o}default:un(n)}}const JJ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function eee(e,t,n,r={}){return{blobPromise:yO({editor:e,ids:t,format:n,opts:r}),mimeType:JJ[n]}}function tee(e,t,n="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:s,mimeType:o}=eee(e,t,n,r);return window.navigator.clipboard.write([new ClipboardItem({[o]:s})]).catch(i=>(console.error(i),s.then(a=>window.navigator.clipboard.write([new ClipboardItem({[o]:a})]))))}switch(n){case"json":case"svg":return nee(async()=>qv(e,t,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:un(n)}}async function nee(e){var t,n;await((n=(t=navigator.clipboard)==null?void 0:t.writeText)==null?void 0:n.call(t,await e()))}function ree(){const e=F(),{addToast:t}=es(),n=we();return P.useCallback((r,s="svg")=>{tee(e,r,s).catch(()=>{t({id:"copy-fail",severity:"warning",title:n("toast.error.copy-fail.title"),description:n("toast.error.copy-fail.desc")})})},[e,t,n])}async function see(e,t,n="png",r,s={}){if(!r&&(r=`shapes at ${JI()}`,t.length===1)){const a=e.getShape(t[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${JI()}`}r+=`.${n}`;const o=await yO({editor:e,ids:t,format:n,opts:s}),i=new File([o],r,{type:o.type});oee(i)}function JI(){const e=new Date,t=String(e.getFullYear()).slice(2),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),s=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return`${t}-${n}-${r} ${s}.${o}.${i}`}function oee(e){const t=document.createElement("a"),n=URL.createObjectURL(e);t.href=n,t.download=e.name,t.click(),URL.revokeObjectURL(n)}function iee(){const e=F(),{addToast:t}=es(),n=we();return P.useCallback((r,s="png",o)=>{see(e,r,s,o,{scale:1,background:e.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),t({id:"export-fail",title:n("toast.error.export-fail.title"),description:n("toast.error.export-fail.desc"),severity:"error"})})},[e,t,n])}async function aee(e,t,n){const r=ye(t.map(a=>{const l=e.getShape(a);if(!(!l||e.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||e.isShapeOfType(a,"image"))return}const s=[];if(n!==void 0){const a=r.map(l=>({shape:l,bounds:e.getShapeMaskedPageBounds(l).clone().expandBy(n)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){s[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of s)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||s.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Q.Common(r.map(l=>e.getShapeMaskedPageBounds(l)));s.push({shapes:r,bounds:a})}const o=e.options.flattenImageBoundsPadding;for(const a of s){n!==void 0&&a.bounds.expandBy(-n);const l=await e.getSvgString(a.shapes,{padding:o});if(!(l!=null&&l.svg))continue;const c=new Blob([l.svg],{type:"image/svg+xml"}),u=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});u&&(a.asset=u)}const i=[];return gs(()=>{for(const a of s){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=e.findCommonAncestor(u)??e.getCurrentPageId();if(!h)continue;let p="a1";for(const m of u)if(m.parentId===h){m.index>p&&(p=m.index);break}let f,S,y;if(jn(h)){const m=e.getShape(h);if(!m)continue;const v=e.getPointInShapeSpace(m,{x:c.x,y:c.y});y=e.getShapePageTransform(h).rotation(),v.sub(new b(o,o).rot(-y)),f=v.x,S=v.y}else f=c.x-o,S=c.y-o,y=0;e.deleteShapes(u),e.createAssets([{...l,id:l.id}]);const x=$e();e.createShape({id:x,type:"image",index:p,parentId:h,x:f,y:S,rotation:-y,props:{assetId:l.id,w:c.w+o*2,h:c.h+o*2}}),i.push(x)}}),i}function Dg(){return!!F().store.props.multiplayerStatus}function lee(){const e=F();return K("multiplayerStatus",()=>e.store.props.multiplayerStatus?e.store.props.multiplayerStatus.get():null,[e])}function cee(){const e=F(),t=P.useRef(null),n=P.useRef(null);return P.useCallback(async function(){const s=document.createElement("div"),o=document.createElement("style"),i=(m,v)=>{m&&(m.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),m&&document.body.contains(m)&&document.body.removeChild(m)};i(t.current,n.current),t.current=s,n.current=o;const a=`tl-print-surface-${ct()}`;s.className=a,o.innerHTML=`
|
|
265
|
-
.${a} {
|
|
266
|
-
display: none;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
.${a} svg {
|
|
270
|
-
max-width: 100%;
|
|
271
|
-
height: 100%;
|
|
272
|
-
display: block;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
@media print {
|
|
276
|
-
html, body {
|
|
277
|
-
min-height: 100%;
|
|
278
|
-
height: 100%;
|
|
279
|
-
margin: 0;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
body {
|
|
283
|
-
position: relative;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
body > * {
|
|
287
|
-
display: none;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
.tldraw__editor {
|
|
291
|
-
display: none;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
.${a} {
|
|
295
|
-
display: block !important;
|
|
296
|
-
background: white;
|
|
297
|
-
min-height: 100%;
|
|
298
|
-
height: 100%;
|
|
299
|
-
max-width: 100%;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
.${a}__item {
|
|
303
|
-
padding: 10mm;
|
|
304
|
-
display: flex;
|
|
305
|
-
min-height: 100%;
|
|
306
|
-
flex-direction: column;
|
|
307
|
-
page-break-after: always;
|
|
308
|
-
position: relative;
|
|
309
|
-
overflow: hidden;
|
|
310
|
-
height: 100%;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
.${a}__item__main {
|
|
314
|
-
flex: 1;
|
|
315
|
-
display: flex;
|
|
316
|
-
align-items: center;
|
|
317
|
-
justify-content: center;
|
|
318
|
-
max-height: 100%;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
.${a}__item__header {
|
|
322
|
-
display: none;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
.${a}__item__footer {
|
|
326
|
-
display: none;
|
|
327
|
-
text-align: right;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
.${a}__item__footer__hide {
|
|
331
|
-
display: none;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
`;const l=()=>{document.head.appendChild(o),document.body.appendChild(s)},c=()=>{e.once("tick",()=>{i(s,o)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(m,v,w){try{s.innerHTML+=`<div class="${a}__item">
|
|
338
|
-
<div class="${a}__item__header">
|
|
339
|
-
${m.replace(/</g,"<").replace(/>/g,">")}
|
|
340
|
-
</div>
|
|
341
|
-
<div class="${a}__item__main">
|
|
342
|
-
${w}
|
|
343
|
-
</div>
|
|
344
|
-
<div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
|
|
345
|
-
${v??""}
|
|
346
|
-
</div>
|
|
347
|
-
</div>`}catch(C){console.error(C)}}function h(){e.environment.isChromeForIos?(l(),window.print()):e.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=e.getSelectedShapeIds(),f=e.getCurrentPageId(),S=e.getPages(),x={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const m=await e.getSvgString(p,x);if(m){const v=S.find(w=>w.id===f);u(`tldraw — ${v==null?void 0:v.name}`,null,m.svg),h()}}else{const m=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(m.id),x);v&&(u(`tldraw — ${m.name}`,null,v.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const SO=P.createContext(null);function uee(e){return Object.fromEntries(e.map(t=>[t.id,t]))}function wa(e,t){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||t}function dee({overrides:e,children:t}){const n=F(),r=Dg(),{addDialog:s,clearDialogs:o}=aa(),{clearToasts:i,addToast:a}=es(),l=we(),c=lO(),u=cee(),{cut:h,copy:p,paste:f}=ZJ(),S=ree(),y=iee(),x=l("document.default-name"),m=Zt(),v=P.useMemo(()=>{function w(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function C(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}const E=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(I){C()&&(w()||(m("edit-link",{source:I}),n.mark("edit-link"),s({component:_J})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(I){m("insert-embed",{source:I}),s({component:aO})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(I){m("insert-media",{source:I}),c()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(I){m("undo",{source:I}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(I){m("redo",{source:I}),n.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(I){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(m("export-as",{format:"svg",source:I}),y(k,"svg",wa(n,x)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(I){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(m("export-as",{format:"png",source:I}),y(k,"png",wa(n,x)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(I){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(m("export-as",{format:"json",source:I}),y(k,"json",wa(n,x)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(I){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(m("export-all-as",{format:"svg",source:I}),y(Array.from(n.getCurrentPageShapeIds()),"svg",wa(n,x)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(I){const k=Array.from(n.getCurrentPageShapeIds().values());k.length!==0&&(m("export-all-as",{format:"png",source:I}),y(k,"png",wa(n,x)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(I){const k=Array.from(n.getCurrentPageShapeIds().values());k.length!==0&&(m("export-all-as",{format:"json",source:I}),y(k,"json",wa(n,x)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(I){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(m("copy-as",{format:"svg",source:I}),S(k,"svg"))}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,onSelect(I){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(m("copy-as",{format:"png",source:I}),S(k,"png"))}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(I){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(m("copy-as",{format:"json",source:I}),S(k,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(I){if(!C()||w())return;m("toggle-auto-size",{source:I}),n.mark("toggling auto size");const k=n.getSelectedShapes().filter(T=>n.isShapeOfType(T,"text")&&T.props.autoSize===!1);n.updateShapes(k.map(T=>({id:T.id,type:T.type,props:{...T.props,w:8,autoSize:!0}}))),Ke(n,k.map(T=>T.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(I){m("open-embed-link",{source:I});const k=n.getSelectedShapeIds(),T="No embed shapes selected";if(k.length!==1){console.error(T);return}const M=n.getShape(k[0]);if(!M||!n.isShapeOfType(M,"embed")){console.error(T);return}nY(M.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(I){var k,T;if(((k=n.root.getCurrent())==null?void 0:k.id)!=="zoom"&&(m("zoom-tool",{source:I}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const M=n.root.getCurrent();M&&((T=M.getCurrent())==null?void 0:T.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:M.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(I){C()&&(w()||n.run(()=>{m("convert-to-bookmark",{source:I});const k=n.getSelectedShapes(),T=[],M=[];for(const D of k){if(!D||!n.isShapeOfType(D,"embed")||!D.props.url)continue;const $=new b(D.x,D.y);$.rot(-D.rotation),$.add(new b(D.props.w/2-300/2,D.props.h/2-320/2)),$.rot(D.rotation);const j={id:$e(),type:"bookmark",rotation:D.rotation,x:$.x,y:$.y,opacity:1,props:{url:D.props.url}};T.push(j),M.push(D.id)}n.mark("convert shapes to bookmark"),n.deleteShapes(M),n.createShapes(T)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(I){C()&&(w()||(m("convert-to-embed",{source:I}),n.run(()=>{const k=n.getSelectedShapeIds(),T=ye(k.map($=>n.getShape($))),M=[],D=[];for(const $ of T){if(!n.isShapeOfType($,"bookmark"))continue;const{url:j}=$.props,O=Ro($.props.url);if(!O||!O.definition)continue;const{width:R,height:H}=O.definition,B=new b($.x,$.y);B.rot(-$.rotation),B.add(new b($.props.w/2-R/2,$.props.h/2-H/2)),B.rot($.rotation);const z={id:$e(),type:"embed",x:B.x,y:B.y,rotation:$.rotation,props:{url:j,w:R,h:H}};M.push(z),D.push($.id)}n.mark("convert shapes to embed"),n.deleteShapes(D),n.createShapes(M)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(I){if(!C()||w())return;m("duplicate-shapes",{source:I});const k=n.getInstanceState();let T,M;if(k.duplicateProps)T=k.duplicateProps.shapeIds,M=k.duplicateProps.offset;else{T=n.getSelectedShapeIds();const D=Q.Common(ye(T.map($=>n.getShapePageBounds($))));M=n.getCameraOptions().isLocked?{x:n.options.adjacentShapeMargin,y:n.options.adjacentShapeMargin}:{x:D.width+n.options.adjacentShapeMargin,y:0}}n.mark("duplicate shapes"),n.duplicateShapes(T,M),k.duplicateProps&&n.updateInstanceState({duplicateProps:{...k.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(I){C()&&(w()||(m("ungroup-shapes",{source:I}),n.mark("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(I){if(!C()||w())return;m("group-shapes",{source:I});const k=n.getOnlySelectedShape();k&&n.isShapeOfType(k,"group")?(n.mark("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())):(n.mark("group"),n.groupShapes(n.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(I){if(!C())return;m("remove-frame",{source:I});const k=n.getSelectedShapes();k.length>0&&k.every(T=>n.isShapeOfType(T,"frame"))&&(n.mark("remove-frame"),IJ(n,k.map(T=>T.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(I){if(!C())return;m("fit-frame-to-content",{source:I});const k=n.getOnlySelectedShape();k&&n.isShapeOfType(k,"frame")&&(n.mark("fit-frame-to-content"),kJ(n,k.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(I){if(!C()||w())return;m("align-shapes",{operation:"left",source:I}),n.mark("align left");const k=n.getSelectedShapeIds();n.alignShapes(k,"left"),Ke(n,k)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(I){if(!C()||w())return;m("align-shapes",{operation:"center-horizontal",source:I}),n.mark("align center horizontal");const k=n.getSelectedShapeIds();n.alignShapes(k,"center-horizontal"),Ke(n,k)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(I){if(!C()||w())return;m("align-shapes",{operation:"right",source:I}),n.mark("align right");const k=n.getSelectedShapeIds();n.alignShapes(k,"right"),Ke(n,k)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(I){if(!C()||w())return;m("align-shapes",{operation:"center-vertical",source:I}),n.mark("align center vertical");const k=n.getSelectedShapeIds();n.alignShapes(k,"center-vertical"),Ke(n,k)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(I){if(!C()||w())return;m("align-shapes",{operation:"top",source:I}),n.mark("align top");const k=n.getSelectedShapeIds();n.alignShapes(k,"top"),Ke(n,k)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(I){if(!C()||w())return;m("align-shapes",{operation:"bottom",source:I}),n.mark("align bottom");const k=n.getSelectedShapeIds();n.alignShapes(k,"bottom"),Ke(n,k)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(I){if(!C()||w())return;m("distribute-shapes",{operation:"horizontal",source:I}),n.mark("distribute horizontal");const k=n.getSelectedShapeIds();n.distributeShapes(k,"horizontal"),Ke(n,k)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(I){if(!C()||w())return;m("distribute-shapes",{operation:"vertical",source:I}),n.mark("distribute vertical");const k=n.getSelectedShapeIds();n.distributeShapes(k,"vertical"),Ke(n,k)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(I){if(!C()||w())return;m("stretch-shapes",{operation:"horizontal",source:I}),n.mark("stretch horizontal");const k=n.getSelectedShapeIds();n.stretchShapes(k,"horizontal"),Ke(n,k)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(I){if(!C()||w())return;m("stretch-shapes",{operation:"vertical",source:I}),n.mark("stretch vertical");const k=n.getSelectedShapeIds();n.stretchShapes(k,"vertical"),Ke(n,k)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(I){if(!C()||w())return;m("flip-shapes",{operation:"horizontal",source:I}),n.mark("flip horizontal");const k=n.getSelectedShapeIds();n.flipShapes(k,"horizontal"),Ke(n,k)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(I){if(!C()||w())return;m("flip-shapes",{operation:"vertical",source:I}),n.mark("flip vertical");const k=n.getSelectedShapeIds();n.flipShapes(k,"vertical"),Ke(n,k)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(I){if(!C()||w())return;m("pack-shapes",{source:I}),n.mark("pack");const k=n.getSelectedShapeIds();n.packShapes(k,n.options.adjacentShapeMargin),Ke(n,k)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(I){if(!C()||w())return;m("stack-shapes",{operation:"vertical",source:I}),n.mark("stack-vertical");const k=n.getSelectedShapeIds();n.stackShapes(k,"vertical",16),Ke(n,k)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(I){if(!C()||w())return;m("stack-shapes",{operation:"horizontal",source:I}),n.mark("stack-horizontal");const k=n.getSelectedShapeIds();n.stackShapes(k,"horizontal",16),Ke(n,k)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(I){C()&&(w()||(m("reorder-shapes",{operation:"toFront",source:I}),n.mark("bring to front"),n.bringToFront(n.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(I){C()&&(w()||(m("reorder-shapes",{operation:"forward",source:I}),n.mark("bring forward"),n.bringForward(n.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(I){C()&&(w()||(m("reorder-shapes",{operation:"backward",source:I}),n.mark("send backward"),n.sendBackward(n.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(I){C()&&(w()||(m("reorder-shapes",{operation:"toBack",source:I}),n.mark("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(I){C()&&(w()||(n.mark("cut"),h(I)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(I){C()&&(w()||p(I))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(I){var k;(k=navigator.clipboard)==null||k.read().then(T=>{f(T,I,I==="context-menu"?n.inputs.currentPagePoint:void 0)}).catch(()=>{a({title:l("action.paste-error-title"),description:l("action.paste-error-description"),severity:"error"})})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(I){n.run(()=>{w()||(m("select-all-shapes",{source:I}),n.mark("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(I){C()&&(w()||(m("select-none-shapes",{source:I}),n.mark("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(I){C()&&(w()||(m("delete-shapes",{source:I}),n.mark("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(I){if(!C()||w())return;m("rotate-cw",{source:I}),n.mark("rotate-cw");const k=n.getSelectionRotation()%(Ve/2),T=$o(k,0)||$o(k,Ve/2),M=n.getSelectedShapeIds();n.rotateShapesBy(M,Ve/2-(T?0:k)),Ke(n,M)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(I){if(!C()||w())return;m("rotate-ccw",{source:I}),n.mark("rotate-ccw");const k=n.getSelectionRotation()%(Ve/2),T=$o(k,0),M=n.getSelectedShapeIds();n.rotateShapesBy(M,T?-(Ve/2):-k),Ke(n,M)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(I){m("zoom-in",{source:I}),n.zoomIn(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(I){m("zoom-out",{source:I}),n.zoomOut(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(I){m("reset-zoom",{source:I}),n.resetZoom(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(I){m("zoom-to-fit",{source:I}),n.zoomToFit({animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(I){C()&&(w()||(m("zoom-to-selection",{source:I}),n.zoomToSelection({animation:{duration:n.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(I){m("toggle-snap-mode",{source:I}),n.user.updateUserPreferences({isSnapMode:!n.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(I){const k=n.user.getIsDarkMode()?"light":"dark";m("color-scheme",{source:I,value:k}),n.user.updateUserPreferences({colorScheme:k})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(I){m("toggle-wrap-mode",{source:I}),n.user.updateUserPreferences({isWrapMode:!n.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-dynamic-size-mode",label:{default:"action.toggle-dynamic-size-mode",menu:"action.toggle-dynamic-size-mode.menu"},readonlyOk:!1,onSelect(I){m("toggle-dynamic-size-mode",{source:I}),n.user.updateUserPreferences({isDynamicSizeMode:!n.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-paste-at-cursor",label:{default:"action.toggle-paste-at-cursor",menu:"action.toggle-paste-at-cursor.menu"},readonlyOk:!1,onSelect(I){m("toggle-paste-at-cursor",{source:I}),n.user.updateUserPreferences({isPasteAtCursorMode:!n.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(I){m("toggle-reduce-motion",{source:I}),n.user.updateUserPreferences({animationSpeed:n.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(I){m("toggle-edge-scrolling",{source:I}),n.user.updateUserPreferences({edgeScrollSpeed:n.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(I){m("toggle-transparent",{source:I}),n.updateInstanceState({exportBackground:!n.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(I){m("toggle-tool-lock",{source:I}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(I){m("unlock-all",{source:I});const k=[];for(const T of n.getCurrentPageShapes())T.isLocked&&k.push({id:T.id,type:T.type,isLocked:!1});k.length>0&&n.updateShapes(k)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(I){n.timers.requestAnimationFrame(()=>{n.run(()=>{m("toggle-focus-mode",{source:I}),o(),i(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(I){m("toggle-grid-mode",{source:I}),n.updateInstanceState({isGridMode:!n.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(I){m("toggle-debug-mode",{source:I}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(I){m("print",{source:I}),u()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(I){m("exit-pen-mode",{source:I}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(I){m("stop-following",{source:I}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(I){m("zoom-to-content",{source:I});const k=n.getSelectionPageBounds()??n.getCurrentPageBounds();k&&n.zoomToBounds(k,{targetZoom:Math.min(1,n.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(I){n.mark("locking"),m("toggle-lock",{source:I}),n.toggleLock(n.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(I){const k=Qs.createId(),T=n.getSelectedShapeIds();n.run(()=>{n.mark("move_shapes_to_page"),n.createPage({name:l("page-menu.new-page-initial-name"),id:k}),n.moveShapesToPage(T,k)}),m("move-to-new-page",{source:I})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(I){const k=cr;n.run(()=>{n.mark("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(k,"white"),n.setStyleForNextShapes(k,"white")}),m("set-style",{source:I,id:k.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(I){const k=Fi;n.run(()=>{n.mark("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(k,"fill"),n.setStyleForNextShapes(k,"fill")}),m("set-style",{source:I,id:k.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async I=>{const k=n.getSelectedShapeIds();if(k.length===0)return;n.mark("flattening to image"),m("flatten-to-image",{source:I});const T=await aee(n,k,n.options.flattenImageBoundsExpand);T!=null&&T.length&&n.setSelectedShapes(T)}}];r&&E.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(I){m("open-cursor-chat",{source:I}),!n.getInstanceState().isCoarsePointer&&n.timers.requestAnimationFrame(()=>{n.updateInstanceState({isChatting:!0})})}});const _=uee(E);return e?e(n,_,void 0):_},[n,m,e,s,a,c,y,S,h,p,f,o,i,u,l,x,r]);return d.jsx(SO.Provider,{value:v,children:t})}function ae(){const e=P.useContext(SO);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function ku(e,t){return e?typeof e=="string"?e:t?e[t]??e.default:void 0:void 0}const hee=["top","right","bottom","left"],fs=Math.min,er=Math.max,Ef=Math.round,Sh=Math.floor,Jo=e=>({x:e,y:e}),pee={left:"right",right:"left",bottom:"top",top:"bottom"},fee={start:"end",end:"start"};function Zv(e,t,n){return er(e,fs(t,n))}function so(e,t){return typeof e=="function"?e(t):e}function oo(e){return e.split("-")[0]}function Rl(e){return e.split("-")[1]}function Lw(e){return e==="x"?"y":"x"}function $w(e){return e==="y"?"height":"width"}function ei(e){return["top","bottom"].includes(oo(e))?"y":"x"}function Nw(e){return Lw(ei(e))}function gee(e,t,n){n===void 0&&(n=!1);const r=Rl(e),s=Nw(e),o=$w(s);let i=s==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[o]>t.floating[o]&&(i=kf(i)),[i,kf(i)]}function mee(e){const t=kf(e);return[Qv(e),t,Qv(t)]}function Qv(e){return e.replace(/start|end/g,t=>fee[t])}function yee(e,t,n){const r=["left","right"],s=["right","left"],o=["top","bottom"],i=["bottom","top"];switch(e){case"top":case"bottom":return n?t?s:r:t?r:s;case"left":case"right":return t?o:i;default:return[]}}function See(e,t,n,r){const s=Rl(e);let o=yee(oo(e),n==="start",r);return s&&(o=o.map(i=>i+"-"+s),t&&(o=o.concat(o.map(Qv)))),o}function kf(e){return e.replace(/left|right|bottom|top/g,t=>pee[t])}function vee(e){return{top:0,right:0,bottom:0,left:0,...e}}function vO(e){return typeof e!="number"?vee(e):{top:e,right:e,bottom:e,left:e}}function _f(e){const{x:t,y:n,width:r,height:s}=e;return{width:r,height:s,top:n,left:t,right:t+r,bottom:n+s,x:t,y:n}}function eE(e,t,n){let{reference:r,floating:s}=e;const o=ei(t),i=Nw(t),a=$w(i),l=oo(t),c=o==="y",u=r.x+r.width/2-s.width/2,h=r.y+r.height/2-s.height/2,p=r[a]/2-s[a]/2;let f;switch(l){case"top":f={x:u,y:r.y-s.height};break;case"bottom":f={x:u,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:h};break;case"left":f={x:r.x-s.width,y:h};break;default:f={x:r.x,y:r.y}}switch(Rl(t)){case"start":f[i]-=p*(n&&c?-1:1);break;case"end":f[i]+=p*(n&&c?-1:1);break}return f}const xee=async(e,t,n)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:i}=n,a=o.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:s}),{x:u,y:h}=eE(c,r,l),p=r,f={},S=0;for(let y=0;y<a.length;y++){const{name:x,fn:m}=a[y],{x:v,y:w,data:C,reset:E}=await m({x:u,y:h,initialPlacement:r,placement:p,strategy:s,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:t}});u=v??u,h=w??h,f={...f,[x]:{...f[x],...C}},E&&S<=50&&(S++,typeof E=="object"&&(E.placement&&(p=E.placement),E.rects&&(c=E.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:s}):E.rects),{x:u,y:h}=eE(c,p,l)),y=-1)}return{x:u,y:h,placement:p,strategy:s,middlewareData:f}};async function _u(e,t){var n;t===void 0&&(t={});const{x:r,y:s,platform:o,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:p=!1,padding:f=0}=so(t,e),S=vO(f),x=a[p?h==="floating"?"reference":"floating":h],m=_f(await o.getClippingRect({element:(n=await(o.isElement==null?void 0:o.isElement(x)))==null||n?x:x.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),v=h==="floating"?{x:r,y:s,width:i.floating.width,height:i.floating.height}:i.reference,w=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),C=await(o.isElement==null?void 0:o.isElement(w))?await(o.getScale==null?void 0:o.getScale(w))||{x:1,y:1}:{x:1,y:1},E=_f(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:w,strategy:l}):v);return{top:(m.top-E.top+S.top)/C.y,bottom:(E.bottom-m.bottom+S.bottom)/C.y,left:(m.left-E.left+S.left)/C.x,right:(E.right-m.right+S.right)/C.x}}const wee=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:s,rects:o,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:u=0}=so(e,t)||{};if(c==null)return{};const h=vO(u),p={x:n,y:r},f=Nw(s),S=$w(f),y=await i.getDimensions(c),x=f==="y",m=x?"top":"left",v=x?"bottom":"right",w=x?"clientHeight":"clientWidth",C=o.reference[S]+o.reference[f]-p[f]-o.floating[S],E=p[f]-o.reference[f],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=_?_[w]:0;(!I||!await(i.isElement==null?void 0:i.isElement(_)))&&(I=a.floating[w]||o.floating[S]);const k=C/2-E/2,T=I/2-y[S]/2-1,M=fs(h[m],T),D=fs(h[v],T),$=M,j=I-y[S]-D,O=I/2-y[S]/2+k,R=Zv($,O,j),H=!l.arrow&&Rl(s)!=null&&O!==R&&o.reference[S]/2-(O<$?M:D)-y[S]/2<0,B=H?O<$?O-$:O-j:0;return{[f]:p[f]+B,data:{[f]:R,centerOffset:O-R-B,...H&&{alignmentOffset:B}},reset:H}}}),bee=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:s,middlewareData:o,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:u=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:S="none",flipAlignment:y=!0,...x}=so(e,t);if((n=o.arrow)!=null&&n.alignmentOffset)return{};const m=oo(s),v=ei(a),w=oo(a)===a,C=await(l.isRTL==null?void 0:l.isRTL(c.floating)),E=p||(w||!y?[kf(a)]:mee(a)),_=S!=="none";!p&&_&&E.push(...See(a,y,S,C));const I=[a,...E],k=await _u(t,x),T=[];let M=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&T.push(k[m]),h){const O=gee(s,i,C);T.push(k[O[0]],k[O[1]])}if(M=[...M,{placement:s,overflows:T}],!T.every(O=>O<=0)){var D,$;const O=(((D=o.flip)==null?void 0:D.index)||0)+1,R=I[O];if(R)return{data:{index:O,overflows:M},reset:{placement:R}};let H=($=M.filter(B=>B.overflows[0]<=0).sort((B,z)=>B.overflows[1]-z.overflows[1])[0])==null?void 0:$.placement;if(!H)switch(f){case"bestFit":{var j;const B=(j=M.filter(z=>{if(_){const W=ei(z.placement);return W===v||W==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(W=>W>0).reduce((W,Y)=>W+Y,0)]).sort((z,W)=>z[1]-W[1])[0])==null?void 0:j[0];B&&(H=B);break}case"initialPlacement":H=a;break}if(s!==H)return{reset:{placement:H}}}return{}}}};function tE(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function nE(e){return hee.some(t=>e[t]>=0)}const Pee=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...s}=so(e,t);switch(r){case"referenceHidden":{const o=await _u(t,{...s,elementContext:"reference"}),i=tE(o,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nE(i)}}}case"escaped":{const o=await _u(t,{...s,altBoundary:!0}),i=tE(o,n.floating);return{data:{escapedOffsets:i,escaped:nE(i)}}}default:return{}}}}};async function Cee(e,t){const{placement:n,platform:r,elements:s}=e,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),i=oo(n),a=Rl(n),l=ei(n)==="y",c=["left","top"].includes(i)?-1:1,u=o&&l?-1:1,h=so(t,e);let{mainAxis:p,crossAxis:f,alignmentAxis:S}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...h};return a&&typeof S=="number"&&(f=a==="end"?S*-1:S),l?{x:f*u,y:p*c}:{x:p*c,y:f*u}}const Iee=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:s,y:o,placement:i,middlewareData:a}=t,l=await Cee(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:o+l.y,data:{...l,placement:i}}}}},Eee=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:s}=t,{mainAxis:o=!0,crossAxis:i=!1,limiter:a={fn:x=>{let{x:m,y:v}=x;return{x:m,y:v}}},...l}=so(e,t),c={x:n,y:r},u=await _u(t,l),h=ei(oo(s)),p=Lw(h);let f=c[p],S=c[h];if(o){const x=p==="y"?"top":"left",m=p==="y"?"bottom":"right",v=f+u[x],w=f-u[m];f=Zv(v,f,w)}if(i){const x=h==="y"?"top":"left",m=h==="y"?"bottom":"right",v=S+u[x],w=S-u[m];S=Zv(v,S,w)}const y=a.fn({...t,[p]:f,[h]:S});return{...y,data:{x:y.x-n,y:y.y-r}}}}},kee=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:s,rects:o,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=so(e,t),u={x:n,y:r},h=ei(s),p=Lw(h);let f=u[p],S=u[h];const y=so(a,t),x=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(l){const w=p==="y"?"height":"width",C=o.reference[p]-o.floating[w]+x.mainAxis,E=o.reference[p]+o.reference[w]-x.mainAxis;f<C?f=C:f>E&&(f=E)}if(c){var m,v;const w=p==="y"?"width":"height",C=["top","left"].includes(oo(s)),E=o.reference[h]-o.floating[w]+(C&&((m=i.offset)==null?void 0:m[h])||0)+(C?0:x.crossAxis),_=o.reference[h]+o.reference[w]+(C?0:((v=i.offset)==null?void 0:v[h])||0)-(C?x.crossAxis:0);S<E?S=E:S>_&&(S=_)}return{[p]:f,[h]:S}}}},_ee=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:s,elements:o}=t,{apply:i=()=>{},...a}=so(e,t),l=await _u(t,a),c=oo(n),u=Rl(n),h=ei(n)==="y",{width:p,height:f}=r.floating;let S,y;c==="top"||c==="bottom"?(S=c,y=u===(await(s.isRTL==null?void 0:s.isRTL(o.floating))?"start":"end")?"left":"right"):(y=c,S=u==="end"?"top":"bottom");const x=f-l.top-l.bottom,m=p-l.left-l.right,v=fs(f-l[S],x),w=fs(p-l[y],m),C=!t.middlewareData.shift;let E=v,_=w;if(h?_=u||C?fs(w,m):m:E=u||C?fs(v,x):x,C&&!u){const k=er(l.left,0),T=er(l.right,0),M=er(l.top,0),D=er(l.bottom,0);h?_=p-2*(k!==0||T!==0?k+T:er(l.left,l.right)):E=f-2*(M!==0||D!==0?M+D:er(l.top,l.bottom))}await i({...t,availableWidth:_,availableHeight:E});const I=await s.getDimensions(o.floating);return p!==I.width||f!==I.height?{reset:{rects:!0}}:{}}}};function Ll(e){return xO(e)?(e.nodeName||"").toLowerCase():"#document"}function ar(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ho(e){var t;return(t=(xO(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function xO(e){return e instanceof Node||e instanceof ar(e).Node}function Yr(e){return e instanceof Element||e instanceof ar(e).Element}function Es(e){return e instanceof HTMLElement||e instanceof ar(e).HTMLElement}function rE(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof ar(e).ShadowRoot}function sd(e){const{overflow:t,overflowX:n,overflowY:r,display:s}=Xr(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!["inline","contents"].includes(s)}function Tee(e){return["table","td","th"].includes(Ll(e))}function Rg(e){return[":popover-open",":modal"].some(t=>{try{return e.matches(t)}catch{return!1}})}function Fw(e){const t=zw(),n=Yr(e)?Xr(e):e;return n.transform!=="none"||n.perspective!=="none"||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function Mee(e){let t=ti(e);for(;Es(t)&&!xl(t);){if(Fw(t))return t;if(Rg(t))return null;t=ti(t)}return null}function zw(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function xl(e){return["html","body","#document"].includes(Ll(e))}function Xr(e){return ar(e).getComputedStyle(e)}function Lg(e){return Yr(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function ti(e){if(Ll(e)==="html")return e;const t=e.assignedSlot||e.parentNode||rE(e)&&e.host||ho(e);return rE(t)?t.host:t}function wO(e){const t=ti(e);return xl(t)?e.ownerDocument?e.ownerDocument.body:e.body:Es(t)&&sd(t)?t:wO(t)}function Tu(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const s=wO(e),o=s===((r=e.ownerDocument)==null?void 0:r.body),i=ar(s);return o?t.concat(i,i.visualViewport||[],sd(s)?s:[],i.frameElement&&n?Tu(i.frameElement):[]):t.concat(s,Tu(s,[],n))}function bO(e){const t=Xr(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const s=Es(e),o=s?e.offsetWidth:n,i=s?e.offsetHeight:r,a=Ef(n)!==o||Ef(r)!==i;return a&&(n=o,r=i),{width:n,height:r,$:a}}function Bw(e){return Yr(e)?e:e.contextElement}function sl(e){const t=Bw(e);if(!Es(t))return Jo(1);const n=t.getBoundingClientRect(),{width:r,height:s,$:o}=bO(t);let i=(o?Ef(n.width):n.width)/r,a=(o?Ef(n.height):n.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Aee=Jo(0);function PO(e){const t=ar(e);return!zw()||!t.visualViewport?Aee:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function jee(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==ar(e)?!1:t}function qi(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const s=e.getBoundingClientRect(),o=Bw(e);let i=Jo(1);t&&(r?Yr(r)&&(i=sl(r)):i=sl(e));const a=jee(o,n,r)?PO(o):Jo(0);let l=(s.left+a.x)/i.x,c=(s.top+a.y)/i.y,u=s.width/i.x,h=s.height/i.y;if(o){const p=ar(o),f=r&&Yr(r)?ar(r):r;let S=p,y=S.frameElement;for(;y&&r&&f!==S;){const x=sl(y),m=y.getBoundingClientRect(),v=Xr(y),w=m.left+(y.clientLeft+parseFloat(v.paddingLeft))*x.x,C=m.top+(y.clientTop+parseFloat(v.paddingTop))*x.y;l*=x.x,c*=x.y,u*=x.x,h*=x.y,l+=w,c+=C,S=ar(y),y=S.frameElement}}return _f({width:u,height:h,x:l,y:c})}function Oee(e){let{elements:t,rect:n,offsetParent:r,strategy:s}=e;const o=s==="fixed",i=ho(r),a=t?Rg(t.floating):!1;if(r===i||a&&o)return n;let l={scrollLeft:0,scrollTop:0},c=Jo(1);const u=Jo(0),h=Es(r);if((h||!h&&!o)&&((Ll(r)!=="body"||sd(i))&&(l=Lg(r)),Es(r))){const p=qi(r);c=sl(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x,y:n.y*c.y-l.scrollTop*c.y+u.y}}function Dee(e){return Array.from(e.getClientRects())}function CO(e){return qi(ho(e)).left+Lg(e).scrollLeft}function Ree(e){const t=ho(e),n=Lg(e),r=e.ownerDocument.body,s=er(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),o=er(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+CO(e);const a=-n.scrollTop;return Xr(r).direction==="rtl"&&(i+=er(t.clientWidth,r.clientWidth)-s),{width:s,height:o,x:i,y:a}}function Lee(e,t){const n=ar(e),r=ho(e),s=n.visualViewport;let o=r.clientWidth,i=r.clientHeight,a=0,l=0;if(s){o=s.width,i=s.height;const c=zw();(!c||c&&t==="fixed")&&(a=s.offsetLeft,l=s.offsetTop)}return{width:o,height:i,x:a,y:l}}function $ee(e,t){const n=qi(e,!0,t==="fixed"),r=n.top+e.clientTop,s=n.left+e.clientLeft,o=Es(e)?sl(e):Jo(1),i=e.clientWidth*o.x,a=e.clientHeight*o.y,l=s*o.x,c=r*o.y;return{width:i,height:a,x:l,y:c}}function sE(e,t,n){let r;if(t==="viewport")r=Lee(e,n);else if(t==="document")r=Ree(ho(e));else if(Yr(t))r=$ee(t,n);else{const s=PO(e);r={...t,x:t.x-s.x,y:t.y-s.y}}return _f(r)}function IO(e,t){const n=ti(e);return n===t||!Yr(n)||xl(n)?!1:Xr(n).position==="fixed"||IO(n,t)}function Nee(e,t){const n=t.get(e);if(n)return n;let r=Tu(e,[],!1).filter(a=>Yr(a)&&Ll(a)!=="body"),s=null;const o=Xr(e).position==="fixed";let i=o?ti(e):e;for(;Yr(i)&&!xl(i);){const a=Xr(i),l=Fw(i);!l&&a.position==="fixed"&&(s=null),(o?!l&&!s:!l&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||sd(i)&&!l&&IO(e,i))?r=r.filter(u=>u!==i):s=a,i=ti(i)}return t.set(e,r),r}function Fee(e){let{element:t,boundary:n,rootBoundary:r,strategy:s}=e;const i=[...n==="clippingAncestors"?Rg(t)?[]:Nee(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=sE(t,u,s);return c.top=er(h.top,c.top),c.right=fs(h.right,c.right),c.bottom=fs(h.bottom,c.bottom),c.left=er(h.left,c.left),c},sE(t,a,s));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function zee(e){const{width:t,height:n}=bO(e);return{width:t,height:n}}function Bee(e,t,n){const r=Es(t),s=ho(t),o=n==="fixed",i=qi(e,!0,o,t);let a={scrollLeft:0,scrollTop:0};const l=Jo(0);if(r||!r&&!o)if((Ll(t)!=="body"||sd(s))&&(a=Lg(t)),r){const h=qi(t,!0,o,t);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else s&&(l.x=CO(s));const c=i.left+a.scrollLeft-l.x,u=i.top+a.scrollTop-l.y;return{x:c,y:u,width:i.width,height:i.height}}function jy(e){return Xr(e).position==="static"}function oE(e,t){return!Es(e)||Xr(e).position==="fixed"?null:t?t(e):e.offsetParent}function EO(e,t){const n=ar(e);if(Rg(e))return n;if(!Es(e)){let s=ti(e);for(;s&&!xl(s);){if(Yr(s)&&!jy(s))return s;s=ti(s)}return n}let r=oE(e,t);for(;r&&Tee(r)&&jy(r);)r=oE(r,t);return r&&xl(r)&&jy(r)&&!Fw(r)?n:r||Mee(e)||n}const Uee=async function(e){const t=this.getOffsetParent||EO,n=this.getDimensions,r=await n(e.floating);return{reference:Bee(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Hee(e){return Xr(e).direction==="rtl"}const Kee={convertOffsetParentRelativeRectToViewportRelativeRect:Oee,getDocumentElement:ho,getClippingRect:Fee,getOffsetParent:EO,getElementRects:Uee,getClientRects:Dee,getDimensions:zee,getScale:sl,isElement:Yr,isRTL:Hee};function Wee(e,t){let n=null,r;const s=ho(e);function o(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),o();const{left:c,top:u,width:h,height:p}=e.getBoundingClientRect();if(a||t(),!h||!p)return;const f=Sh(u),S=Sh(s.clientWidth-(c+h)),y=Sh(s.clientHeight-(u+p)),x=Sh(c),v={rootMargin:-f+"px "+-S+"px "+-y+"px "+-x+"px",threshold:er(0,fs(1,l))||1};let w=!0;function C(E){const _=E[0].intersectionRatio;if(_!==l){if(!w)return i();_?i(!1,_):r=setTimeout(()=>{i(!1,1e-7)},1e3)}w=!1}try{n=new IntersectionObserver(C,{...v,root:s.ownerDocument})}catch{n=new IntersectionObserver(C,v)}n.observe(e)}return i(!0),o}function Gee(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Bw(e),u=s||o?[...c?Tu(c):[],...Tu(t)]:[];u.forEach(m=>{s&&m.addEventListener("scroll",n,{passive:!0}),o&&m.addEventListener("resize",n)});const h=c&&a?Wee(c,n):null;let p=-1,f=null;i&&(f=new ResizeObserver(m=>{let[v]=m;v&&v.target===c&&f&&(f.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var w;(w=f)==null||w.observe(t)})),n()}),c&&!l&&f.observe(c),f.observe(t));let S,y=l?qi(e):null;l&&x();function x(){const m=qi(e);y&&(m.x!==y.x||m.y!==y.y||m.width!==y.width||m.height!==y.height)&&n(),y=m,S=requestAnimationFrame(x)}return n(),()=>{var m;u.forEach(v=>{s&&v.removeEventListener("scroll",n),o&&v.removeEventListener("resize",n)}),h==null||h(),(m=f)==null||m.disconnect(),f=null,l&&cancelAnimationFrame(S)}}const Vee=Iee,Yee=Eee,Xee=bee,qee=_ee,Zee=Pee,iE=wee,Qee=kee,Jee=(e,t,n)=>{const r=new Map,s={platform:Kee,...n},o={...s.platform,_c:r};return xee(e,t,{...s,platform:o})};var yp=typeof document<"u"?P.useLayoutEffect:P.useEffect;function Tf(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,s;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Tf(e[r],t[r]))return!1;return!0}if(s=Object.keys(e),n=s.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&e.$$typeof)&&!Tf(e[o],t[o]))return!1}return!0}return e!==e&&t!==t}function kO(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function aE(e,t){const n=kO(e);return Math.round(t*n)/n}function lE(e){const t=P.useRef(e);return yp(()=>{t.current=e}),t}function ete(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[u,h]=P.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,f]=P.useState(r);Tf(p,r)||f(r);const[S,y]=P.useState(null),[x,m]=P.useState(null),v=P.useCallback(B=>{B!==_.current&&(_.current=B,y(B))},[]),w=P.useCallback(B=>{B!==I.current&&(I.current=B,m(B))},[]),C=o||S,E=i||x,_=P.useRef(null),I=P.useRef(null),k=P.useRef(u),T=l!=null,M=lE(l),D=lE(s),$=P.useCallback(()=>{if(!_.current||!I.current)return;const B={placement:t,strategy:n,middleware:p};D.current&&(B.platform=D.current),Jee(_.current,I.current,B).then(z=>{const W={...z,isPositioned:!0};j.current&&!Tf(k.current,W)&&(k.current=W,ia.flushSync(()=>{h(W)}))})},[p,t,n,D]);yp(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,h(B=>({...B,isPositioned:!1})))},[c]);const j=P.useRef(!1);yp(()=>(j.current=!0,()=>{j.current=!1}),[]),yp(()=>{if(C&&(_.current=C),E&&(I.current=E),C&&E){if(M.current)return M.current(C,E,$);$()}},[C,E,$,M,T]);const O=P.useMemo(()=>({reference:_,floating:I,setReference:v,setFloating:w}),[v,w]),R=P.useMemo(()=>({reference:C,floating:E}),[C,E]),H=P.useMemo(()=>{const B={position:n,left:0,top:0};if(!R.floating)return B;const z=aE(R.floating,u.x),W=aE(R.floating,u.y);return a?{...B,transform:"translate("+z+"px, "+W+"px)",...kO(R.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:z,top:W}},[n,a,R.floating,u.x,u.y]);return P.useMemo(()=>({...u,update:$,refs:O,elements:R,floatingStyles:H}),[u,$,O,R,H])}const tte=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:s}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?iE({element:r.current,padding:s}).fn(n):{}:r?iE({element:r,padding:s}).fn(n):{}}}},nte=(e,t)=>({...Vee(e),options:[e,t]}),rte=(e,t)=>({...Yee(e),options:[e,t]}),ste=(e,t)=>({...Qee(e),options:[e,t]}),ote=(e,t)=>({...Xee(e),options:[e,t]}),ite=(e,t)=>({...qee(e),options:[e,t]}),ate=(e,t)=>({...Zee(e),options:[e,t]}),lte=(e,t)=>({...tte(e),options:[e,t]});var cte="Arrow",_O=P.forwardRef((e,t)=>{const{children:n,width:r=10,height:s=5,...o}=e;return d.jsx(_e.svg,{...o,ref:t,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});_O.displayName=cte;var ute=_O;function TO(e){const[t,n]=P.useState(void 0);return Qo(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const o=s[0];let i,a;if("borderBoxSize"in o){const l=o.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var Uw="Popper",[MO,$g]=Ms(Uw),[dte,AO]=MO(Uw),jO=e=>{const{__scopePopper:t,children:n}=e,[r,s]=P.useState(null);return d.jsx(dte,{scope:t,anchor:r,onAnchorChange:s,children:n})};jO.displayName=Uw;var OO="PopperAnchor",DO=P.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...s}=e,o=AO(OO,n),i=P.useRef(null),a=qe(t,i);return P.useEffect(()=>{o.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(_e.div,{...s,ref:a})});DO.displayName=OO;var Hw="PopperContent",[hte,pte]=MO(Hw),RO=P.forwardRef((e,t)=>{var Oe,nt,je,it,Fe,Xn;const{__scopePopper:n,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:f="optimized",onPlaced:S,...y}=e,x=AO(Hw,n),[m,v]=P.useState(null),w=qe(t,Nt=>v(Nt)),[C,E]=P.useState(null),_=TO(C),I=(_==null?void 0:_.width)??0,k=(_==null?void 0:_.height)??0,T=r+(o!=="center"?"-"+o:""),M=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(c)?c:[c],$=D.length>0,j={padding:M,boundary:D.filter(gte),altBoundary:$},{refs:O,floatingStyles:R,placement:H,isPositioned:B,middlewareData:z}=ete({strategy:"fixed",placement:T,whileElementsMounted:(...Nt)=>Gee(...Nt,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[nte({mainAxis:s+k,alignmentAxis:i}),l&&rte({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?ste():void 0,...j}),l&&ote({...j}),ite({...j,apply:({elements:Nt,rects:_n,availableWidth:St,availableHeight:Qt})=>{const{width:As,height:Nl}=_n.reference,mo=Nt.floating.style;mo.setProperty("--radix-popper-available-width",`${St}px`),mo.setProperty("--radix-popper-available-height",`${Qt}px`),mo.setProperty("--radix-popper-anchor-width",`${As}px`),mo.setProperty("--radix-popper-anchor-height",`${Nl}px`)}}),C&<e({element:C,padding:a}),mte({arrowWidth:I,arrowHeight:k}),p&&ate({strategy:"referenceHidden",...j})]}),[W,Y]=NO(H),q=Xt(S);Qo(()=>{B&&(q==null||q())},[B,q]);const le=(Oe=z.arrow)==null?void 0:Oe.x,ge=(nt=z.arrow)==null?void 0:nt.y,be=((je=z.arrow)==null?void 0:je.centerOffset)!==0,[J,Ue]=P.useState();return Qo(()=>{m&&Ue(window.getComputedStyle(m).zIndex)},[m]),d.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...R,transform:B?R.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(it=z.transformOrigin)==null?void 0:it.x,(Fe=z.transformOrigin)==null?void 0:Fe.y].join(" "),...((Xn=z.hide)==null?void 0:Xn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(hte,{scope:n,placedSide:W,onArrowChange:E,arrowX:le,arrowY:ge,shouldHideArrow:be,children:d.jsx(_e.div,{"data-side":W,"data-align":Y,...y,ref:w,style:{...y.style,animation:B?void 0:"none"}})})})});RO.displayName=Hw;var LO="PopperArrow",fte={top:"bottom",right:"left",bottom:"top",left:"right"},$O=P.forwardRef(function(t,n){const{__scopePopper:r,...s}=t,o=pte(LO,r),i=fte[o.placedSide];return d.jsx("span",{ref:o.onArrowChange,style:{position:"absolute",left:o.arrowX,top:o.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[o.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[o.placedSide],visibility:o.shouldHideArrow?"hidden":void 0},children:d.jsx(ute,{...s,ref:n,style:{...s.style,display:"block"}})})});$O.displayName=LO;function gte(e){return e!==null}var mte=e=>({name:"transformOrigin",options:e,fn(t){var x,m,v;const{placement:n,rects:r,middlewareData:s}=t,i=((x=s.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,u]=NO(n),h={start:"0%",center:"50%",end:"100%"}[u],p=(((m=s.arrow)==null?void 0:m.x)??0)+a/2,f=(((v=s.arrow)==null?void 0:v.y)??0)+l/2;let S="",y="";return c==="bottom"?(S=i?h:`${p}px`,y=`${-l}px`):c==="top"?(S=i?h:`${p}px`,y=`${r.floating.height+l}px`):c==="right"?(S=`${-l}px`,y=i?h:`${f}px`):c==="left"&&(S=`${r.floating.width+l}px`,y=i?h:`${f}px`),{data:{x:S,y}}}});function NO(e){const[t,n="center"]=e.split("-");return[t,n]}var Kw=jO,Ww=DO,FO=RO,zO=$O,Gw="Popover",[BO,Aae]=Ms(Gw,[$g]),od=$g(),[yte,di]=BO(Gw),UO=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:i=!1}=e,a=od(t),l=P.useRef(null),[c,u]=P.useState(!1),[h=!1,p]=ui({prop:r,defaultProp:s,onChange:o});return d.jsx(Kw,{...a,children:d.jsx(yte,{scope:t,contentId:qs(),triggerRef:l,open:h,onOpenChange:p,onOpenToggle:P.useCallback(()=>p(f=>!f),[p]),hasCustomAnchor:c,onCustomAnchorAdd:P.useCallback(()=>u(!0),[]),onCustomAnchorRemove:P.useCallback(()=>u(!1),[]),modal:i,children:n})})};UO.displayName=Gw;var HO="PopoverAnchor",Ste=P.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=di(HO,n),o=od(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=s;return P.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(Ww,{...o,...r,ref:t})});Ste.displayName=HO;var KO="PopoverTrigger",WO=P.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=di(KO,n),o=od(n),i=qe(t,s.triggerRef),a=d.jsx(_e.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":qO(s.open),...r,ref:i,onClick:re(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:d.jsx(Ww,{asChild:!0,...o,children:a})});WO.displayName=KO;var Vw="PopoverPortal",[vte,xte]=BO(Vw,{forceMount:void 0}),GO=e=>{const{__scopePopover:t,forceMount:n,children:r,container:s}=e,o=di(Vw,t);return d.jsx(vte,{scope:t,forceMount:n,children:d.jsx(Qr,{present:n||o.open,children:d.jsx(rd,{asChild:!0,container:s,children:r})})})};GO.displayName=Vw;var wl="PopoverContent",VO=P.forwardRef((e,t)=>{const n=xte(wl,e.__scopePopover),{forceMount:r=n.forceMount,...s}=e,o=di(wl,e.__scopePopover);return d.jsx(Qr,{present:r||o.open,children:o.modal?d.jsx(wte,{...s,ref:t}):d.jsx(bte,{...s,ref:t})})});VO.displayName=wl;var wte=P.forwardRef((e,t)=>{const n=di(wl,e.__scopePopover),r=P.useRef(null),s=qe(t,r),o=P.useRef(!1);return P.useEffect(()=>{const i=r.current;if(i)return Iw(i)},[]),d.jsx(Ig,{as:Yi,allowPinchZoom:!0,children:d.jsx(YO,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:re(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),o.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:re(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;o.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:re(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),bte=P.forwardRef((e,t)=>{const n=di(wl,e.__scopePopover),r=P.useRef(!1),s=P.useRef(!1);return d.jsx(YO,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,o),o.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),YO=P.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=e,p=di(wl,n),f=od(n);return Cw(),d.jsx(Pg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:d.jsx(nd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:d.jsx(FO,{"data-state":qO(p.open),role:"dialog",id:p.contentId,...f,...h,ref:t,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),XO="PopoverClose",Pte=P.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=di(XO,n);return d.jsx(_e.button,{type:"button",...r,ref:t,onClick:re(e.onClick,()=>s.onOpenChange(!1))})});Pte.displayName=XO;var Cte="PopoverArrow",Ite=P.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,s=od(n);return d.jsx(zO,{...s,...r,ref:t})});Ite.displayName=Cte;function qO(e){return e?"open":"closed"}var Yw=UO,Xw=WO,qw=GO,Zw=VO;function po(e,t){const n=F(),r=P.useRef(!1),s=Zt(),o=P.useCallback(a=>{r.current=a,n.run(()=>{a?(n.complete(),n.addOpenMenu(e)):n.updateInstanceState({openMenus:n.getOpenMenus().filter(l=>!l.startsWith(e))}),t==null||t(a)})},[n,e,t]),i=K("is menu open",()=>n.getOpenMenus().includes(e),[n,e]);return P.useEffect(()=>(r.current&&(s("open-menu",{source:"unknown",id:e}),n.addOpenMenu(e)),()=>{r.current&&(n.deleteOpenMenu(e),n.getOpenMenus().forEach(a=>{a.startsWith(e)&&(s("close-menu",{source:"unknown",id:e}),n.deleteOpenMenu(a))}),r.current=!1)}),[n,e,s]),[i,o]}function Qw({id:e,children:t,onOpenChange:n,open:r}){const[s,o]=po(e,n);return d.jsx(Yw,{onOpenChange:o,open:r||s,children:d.jsx("div",{className:"tlui-popover",children:t})})}function Jw({children:e}){return d.jsx(Xw,{asChild:!0,dir:"ltr",children:e})}function e1({side:e,children:t,align:n="center",sideOffset:r=8,alignOffset:s=0}){const o=$t();return d.jsx(qw,{container:o,children:d.jsx(Zw,{className:"tlui-popover__content",side:e,sideOffset:r,align:n,alignOffset:s,dir:"ltr",children:t})})}const ZO=P.createContext(null);function Ng(){const e=P.useContext(ZO);if(!e)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function Mr({type:e,sourceId:t,children:n}){return d.jsx(ZO.Provider,{value:{type:e,sourceId:t},children:n})}function Ete(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>{if(!r)return!1;if(e.isShapeOfType(r,"arrow")){const s=Ln(e,r);if(s.start||s.end)return!1}return!0})}const QO=()=>{const e=F();return K("threeStackableItems",()=>Ete(e).length>2,[e])},fo=()=>{const e=F();return K("isInSelectState",()=>e.isIn("select"),[e])},JO=()=>{const e=F();return K("allow group",()=>{const t=e.getSelectedShapes();if(t.length<2)return!1;for(const n of t)if(e.isShapeOfType(n,"arrow")){const r=Ln(e,n);if(r.start&&!t.some(s=>s.id===r.start.toId)||r.end&&!t.some(s=>s.id===r.end.toId))return!1}return!0},[e])},eD=()=>{const e=F();return K("allowUngroup",()=>e.getSelectedShapeIds().some(t=>{var n;return((n=e.getShape(t))==null?void 0:n.type)==="group"}),[e])},kte=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function tD(e,t){const n=F();return K("selectedShapes",()=>n.getSelectedShapes().length>=e,[n,e,t])}function En(e,t){const n=F();return K("selectedShapes",()=>{const r=n.getSelectedShapes().filter(s=>!n.isShapeOrAncestorLocked(s)).length;return e===void 0?r:r>=e},[n])}function _te(){const e=F();return K("showAutoSizeToggle",()=>{const t=e.getSelectedShapes();return t.length===1&&e.isShapeOfType(t[0],"text")&&t[0].props.autoSize===!1},[e])}function nD(){const e=F();return K("hasLinkShapeSelected",()=>{const t=e.getOnlySelectedShape();return!!(t&&t.type!=="embed"&&"url"in t.props&&!t.isLocked)},[e])}function Tte(){const e=F();return K("onlyFlippableShape",()=>{const t=e.getOnlySelectedShape();return t&&(e.isShapeOfType(t,"group")||e.isShapeOfType(t,"image")||e.isShapeOfType(t,"arrow")||e.isShapeOfType(t,"line")||e.isShapeOfType(t,"draw"))},[e])}function rD(){const e=F();return K("useCanRedo",()=>e.getCanRedo(),[e])}function sD(){const e=F();return K("useCanUndo",()=>e.getCanUndo(),[e])}var Mte=P.createContext(void 0);function t1(e){const t=P.useContext(Mte);return e||t||"ltr"}var Oy="rovingFocusGroup.onEntryFocus",Ate={bubbles:!1,cancelable:!0},Fg="RovingFocusGroup",[Jv,oD,jte]=Eg(Fg),[Ote,iD]=Ms(Fg,[jte]),[Dte,Rte]=Ote(Fg),aD=P.forwardRef((e,t)=>d.jsx(Jv.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(Jv.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(Lte,{...e,ref:t})})}));aD.displayName=Fg;var Lte=P.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:s=!1,dir:o,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=e,p=P.useRef(null),f=qe(t,p),S=t1(o),[y=null,x]=ui({prop:i,defaultProp:a,onChange:l}),[m,v]=P.useState(!1),w=Xt(c),C=oD(n),E=P.useRef(!1),[_,I]=P.useState(0);return P.useEffect(()=>{const k=p.current;if(k)return k.addEventListener(Oy,w),()=>k.removeEventListener(Oy,w)},[w]),d.jsx(Dte,{scope:n,orientation:r,dir:S,loop:s,currentTabStopId:y,onItemFocus:P.useCallback(k=>x(k),[x]),onItemShiftTab:P.useCallback(()=>v(!0),[]),onFocusableItemAdd:P.useCallback(()=>I(k=>k+1),[]),onFocusableItemRemove:P.useCallback(()=>I(k=>k-1),[]),children:d.jsx(_e.div,{tabIndex:m||_===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...e.style},onMouseDown:re(e.onMouseDown,()=>{E.current=!0}),onFocus:re(e.onFocus,k=>{const T=!E.current;if(k.target===k.currentTarget&&T&&!m){const M=new CustomEvent(Oy,Ate);if(k.currentTarget.dispatchEvent(M),!M.defaultPrevented){const D=C().filter(H=>H.focusable),$=D.find(H=>H.active),j=D.find(H=>H.id===y),R=[$,j,...D].filter(Boolean).map(H=>H.ref.current);uD(R,u)}}E.current=!1}),onBlur:re(e.onBlur,()=>v(!1))})})}),lD="RovingFocusGroupItem",cD=P.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:s=!1,tabStopId:o,...i}=e,a=qs(),l=o||a,c=Rte(lD,n),u=c.currentTabStopId===l,h=oD(n),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return P.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),d.jsx(Jv.ItemSlot,{scope:n,id:l,focusable:r,active:s,children:d.jsx(_e.span,{tabIndex:u?0:-1,"data-orientation":c.orientation,...i,ref:t,onMouseDown:re(e.onMouseDown,S=>{r?c.onItemFocus(l):S.preventDefault()}),onFocus:re(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:re(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){c.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const y=Fte(S,c.orientation,c.dir);if(y!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let m=h().filter(v=>v.focusable).map(v=>v.ref.current);if(y==="last")m.reverse();else if(y==="prev"||y==="next"){y==="prev"&&m.reverse();const v=m.indexOf(S.currentTarget);m=c.loop?zte(m,v+1):m.slice(v+1)}setTimeout(()=>uD(m))}})})})});cD.displayName=lD;var $te={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Nte(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Fte(e,t,n){const r=Nte(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return $te[r]}function uD(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function zte(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Bte=aD,Ute=cD,ex=["Enter"," "],Hte=["ArrowDown","PageUp","Home"],dD=["ArrowUp","PageDown","End"],Kte=[...Hte,...dD],Wte={ltr:[...ex,"ArrowRight"],rtl:[...ex,"ArrowLeft"]},Gte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},id="Menu",[Mu,Vte,Yte]=Eg(id),[la,zg]=Ms(id,[Yte,$g,iD]),ad=$g(),hD=iD(),[pD,hi]=la(id),[Xte,ld]=la(id),fD=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:s,onOpenChange:o,modal:i=!0}=e,a=ad(t),[l,c]=P.useState(null),u=P.useRef(!1),h=Xt(o),p=t1(s);return P.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",S,{capture:!0,once:!0}),document.addEventListener("pointermove",S,{capture:!0,once:!0})},S=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",S,{capture:!0}),document.removeEventListener("pointermove",S,{capture:!0})}},[]),d.jsx(Kw,{...a,children:d.jsx(pD,{scope:t,open:n,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(Xte,{scope:t,onClose:P.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};fD.displayName=id;var qte="MenuAnchor",n1=P.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,s=ad(n);return d.jsx(Ww,{...s,...r,ref:t})});n1.displayName=qte;var r1="MenuPortal",[Zte,gD]=la(r1,{forceMount:void 0}),mD=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:s}=e,o=hi(r1,t);return d.jsx(Zte,{scope:t,forceMount:n,children:d.jsx(Qr,{present:n||o.open,children:d.jsx(rd,{asChild:!0,container:s,children:r})})})};mD.displayName=r1;var kr="MenuContent",[Qte,s1]=la(kr),yD=P.forwardRef((e,t)=>{const n=gD(kr,e.__scopeMenu),{forceMount:r=n.forceMount,...s}=e,o=hi(kr,e.__scopeMenu),i=ld(kr,e.__scopeMenu);return d.jsx(Mu.Provider,{scope:e.__scopeMenu,children:d.jsx(Qr,{present:r||o.open,children:d.jsx(Mu.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(Jte,{...s,ref:t}):d.jsx(ene,{...s,ref:t})})})})}),Jte=P.forwardRef((e,t)=>{const n=hi(kr,e.__scopeMenu),r=P.useRef(null),s=qe(t,r);return P.useEffect(()=>{const o=r.current;if(o)return Iw(o)},[]),d.jsx(o1,{...e,ref:s,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:re(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ene=P.forwardRef((e,t)=>{const n=hi(kr,e.__scopeMenu);return d.jsx(o1,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),o1=P.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:s,onOpenAutoFocus:o,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,disableOutsideScroll:S,...y}=e,x=hi(kr,n),m=ld(kr,n),v=ad(n),w=hD(n),C=Vte(n),[E,_]=P.useState(null),I=P.useRef(null),k=qe(t,I,x.onContentChange),T=P.useRef(0),M=P.useRef(""),D=P.useRef(0),$=P.useRef(null),j=P.useRef("right"),O=P.useRef(0),R=S?Ig:P.Fragment,H=S?{as:Yi,allowPinchZoom:!0}:void 0,B=W=>{var Oe,nt;const Y=M.current+W,q=C().filter(je=>!je.disabled),le=document.activeElement,ge=(Oe=q.find(je=>je.ref.current===le))==null?void 0:Oe.textValue,be=q.map(je=>je.textValue),J=hne(be,Y,ge),Ue=(nt=q.find(je=>je.textValue===J))==null?void 0:nt.ref.current;(function je(it){M.current=it,window.clearTimeout(T.current),it!==""&&(T.current=window.setTimeout(()=>je(""),1e3))})(Y),Ue&&setTimeout(()=>Ue.focus())};P.useEffect(()=>()=>window.clearTimeout(T.current),[]),Cw();const z=P.useCallback(W=>{var q,le;return j.current===((q=$.current)==null?void 0:q.side)&&fne(W,(le=$.current)==null?void 0:le.area)},[]);return d.jsx(Qte,{scope:n,searchRef:M,onItemEnter:P.useCallback(W=>{z(W)&&W.preventDefault()},[z]),onItemLeave:P.useCallback(W=>{var Y;z(W)||((Y=I.current)==null||Y.focus(),_(null))},[z]),onTriggerLeave:P.useCallback(W=>{z(W)&&W.preventDefault()},[z]),pointerGraceTimerRef:D,onPointerGraceIntentChange:P.useCallback(W=>{$.current=W},[]),children:d.jsx(R,{...H,children:d.jsx(Pg,{asChild:!0,trapped:s,onMountAutoFocus:re(o,W=>{var Y;W.preventDefault(),(Y=I.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(nd,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:d.jsx(Bte,{asChild:!0,...w,dir:m.dir,orientation:"vertical",loop:r,currentTabStopId:E,onCurrentTabStopIdChange:_,onEntryFocus:re(l,W=>{m.isUsingKeyboardRef.current||W.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(FO,{role:"menu","aria-orientation":"vertical","data-state":DD(x.open),"data-radix-menu-content":"",dir:m.dir,...v,...y,ref:k,style:{outline:"none",...y.style},onKeyDown:re(y.onKeyDown,W=>{const q=W.target.closest("[data-radix-menu-content]")===W.currentTarget,le=W.ctrlKey||W.altKey||W.metaKey,ge=W.key.length===1;q&&(W.key==="Tab"&&W.preventDefault(),!le&&ge&&B(W.key));const be=I.current;if(W.target!==be||!Kte.includes(W.key))return;W.preventDefault();const Ue=C().filter(Oe=>!Oe.disabled).map(Oe=>Oe.ref.current);dD.includes(W.key)&&Ue.reverse(),une(Ue)}),onBlur:re(e.onBlur,W=>{W.currentTarget.contains(W.target)||(window.clearTimeout(T.current),M.current="")}),onPointerMove:re(e.onPointerMove,Au(W=>{const Y=W.target,q=O.current!==W.clientX;if(W.currentTarget.contains(Y)&&q){const le=W.clientX>O.current?"right":"left";j.current=le,O.current=W.clientX}}))})})})})})})});yD.displayName=kr;var tne="MenuGroup",i1=P.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(_e.div,{role:"group",...r,ref:t})});i1.displayName=tne;var nne="MenuLabel",SD=P.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(_e.div,{...r,ref:t})});SD.displayName=nne;var Mf="MenuItem",cE="menu.itemSelect",Bg=P.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...s}=e,o=P.useRef(null),i=ld(Mf,e.__scopeMenu),a=s1(Mf,e.__scopeMenu),l=qe(t,o),c=P.useRef(!1),u=()=>{const h=o.current;if(!n&&h){const p=new CustomEvent(cE,{bubbles:!0,cancelable:!0});h.addEventListener(cE,f=>r==null?void 0:r(f),{once:!0}),Pw(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(vD,{...s,ref:l,disabled:n,onClick:re(e.onClick,u),onPointerDown:h=>{var p;(p=e.onPointerDown)==null||p.call(e,h),c.current=!0},onPointerUp:re(e.onPointerUp,h=>{var p;c.current||(p=h.currentTarget)==null||p.click()}),onKeyDown:re(e.onKeyDown,h=>{const p=a.searchRef.current!=="";n||p&&h.key===" "||ex.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Bg.displayName=Mf;var vD=P.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:s,...o}=e,i=s1(Mf,n),a=hD(n),l=P.useRef(null),c=qe(t,l),[u,h]=P.useState(!1),[p,f]=P.useState("");return P.useEffect(()=>{const S=l.current;S&&f((S.textContent??"").trim())},[o.children]),d.jsx(Mu.ItemSlot,{scope:n,disabled:r,textValue:s??p,children:d.jsx(Ute,{asChild:!0,...a,focusable:!r,children:d.jsx(_e.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...o,ref:c,onPointerMove:re(e.onPointerMove,Au(S=>{r?i.onItemLeave(S):(i.onItemEnter(S),S.defaultPrevented||S.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:re(e.onPointerLeave,Au(S=>i.onItemLeave(S))),onFocus:re(e.onFocus,()=>h(!0)),onBlur:re(e.onBlur,()=>h(!1))})})})}),rne="MenuCheckboxItem",xD=P.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...s}=e;return d.jsx(ID,{scope:e.__scopeMenu,checked:n,children:d.jsx(Bg,{role:"menuitemcheckbox","aria-checked":Af(n)?"mixed":n,...s,ref:t,"data-state":c1(n),onSelect:re(s.onSelect,()=>r==null?void 0:r(Af(n)?!0:!n),{checkForDefaultPrevented:!1})})})});xD.displayName=rne;var wD="MenuRadioGroup",[sne,one]=la(wD,{value:void 0,onValueChange:()=>{}}),bD=P.forwardRef((e,t)=>{const{value:n,onValueChange:r,...s}=e,o=Xt(r);return d.jsx(sne,{scope:e.__scopeMenu,value:n,onValueChange:o,children:d.jsx(i1,{...s,ref:t})})});bD.displayName=wD;var PD="MenuRadioItem",CD=P.forwardRef((e,t)=>{const{value:n,...r}=e,s=one(PD,e.__scopeMenu),o=n===s.value;return d.jsx(ID,{scope:e.__scopeMenu,checked:o,children:d.jsx(Bg,{role:"menuitemradio","aria-checked":o,...r,ref:t,"data-state":c1(o),onSelect:re(r.onSelect,()=>{var i;return(i=s.onValueChange)==null?void 0:i.call(s,n)},{checkForDefaultPrevented:!1})})})});CD.displayName=PD;var a1="MenuItemIndicator",[ID,ine]=la(a1,{checked:!1}),ED=P.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...s}=e,o=ine(a1,n);return d.jsx(Qr,{present:r||Af(o.checked)||o.checked===!0,children:d.jsx(_e.span,{...s,ref:t,"data-state":c1(o.checked)})})});ED.displayName=a1;var ane="MenuSeparator",kD=P.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(_e.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});kD.displayName=ane;var lne="MenuArrow",_D=P.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,s=ad(n);return d.jsx(zO,{...s,...r,ref:t})});_D.displayName=lne;var l1="MenuSub",[cne,TD]=la(l1),MD=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:s}=e,o=hi(l1,t),i=ad(t),[a,l]=P.useState(null),[c,u]=P.useState(null),h=Xt(s);return P.useEffect(()=>(o.open===!1&&h(!1),()=>h(!1)),[o.open,h]),d.jsx(Kw,{...i,children:d.jsx(pD,{scope:t,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(cne,{scope:t,contentId:qs(),triggerId:qs(),trigger:a,onTriggerChange:l,children:n})})})};MD.displayName=l1;var Rc="MenuSubTrigger",AD=P.forwardRef((e,t)=>{const n=hi(Rc,e.__scopeMenu),r=ld(Rc,e.__scopeMenu),s=TD(Rc,e.__scopeMenu),o=s1(Rc,e.__scopeMenu),i=P.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=o,c={__scopeMenu:e.__scopeMenu},u=P.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return P.useEffect(()=>u,[u]),P.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),d.jsx(n1,{asChild:!0,...c,children:d.jsx(vD,{id:s.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":s.contentId,"data-state":DD(n.open),...e,ref:bg(t,s.onTriggerChange),onClick:h=>{var p;(p=e.onClick)==null||p.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:re(e.onPointerMove,Au(h=>{o.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(o.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:re(e.onPointerLeave,Au(h=>{var f,S;u();const p=(f=n.content)==null?void 0:f.getBoundingClientRect();if(p){const y=(S=n.content)==null?void 0:S.dataset.side,x=y==="right",m=x?-5:5,v=p[x?"left":"right"],w=p[x?"right":"left"];o.onPointerGraceIntentChange({area:[{x:h.clientX+m,y:h.clientY},{x:v,y:p.top},{x:w,y:p.top},{x:w,y:p.bottom},{x:v,y:p.bottom}],side:y}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>o.onPointerGraceIntentChange(null),300)}else{if(o.onTriggerLeave(h),h.defaultPrevented)return;o.onPointerGraceIntentChange(null)}})),onKeyDown:re(e.onKeyDown,h=>{var f;const p=o.searchRef.current!=="";e.disabled||p&&h.key===" "||Wte[r.dir].includes(h.key)&&(n.onOpenChange(!0),(f=n.content)==null||f.focus(),h.preventDefault())})})})});AD.displayName=Rc;var jD="MenuSubContent",OD=P.forwardRef((e,t)=>{const n=gD(kr,e.__scopeMenu),{forceMount:r=n.forceMount,...s}=e,o=hi(kr,e.__scopeMenu),i=ld(kr,e.__scopeMenu),a=TD(jD,e.__scopeMenu),l=P.useRef(null),c=qe(t,l);return d.jsx(Mu.Provider,{scope:e.__scopeMenu,children:d.jsx(Qr,{present:r||o.open,children:d.jsx(Mu.Slot,{scope:e.__scopeMenu,children:d.jsx(o1,{id:a.contentId,"aria-labelledby":a.triggerId,...s,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:re(e.onFocusOutside,u=>{u.target!==a.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:re(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:re(e.onKeyDown,u=>{var f;const h=u.currentTarget.contains(u.target),p=Gte[i.dir].includes(u.key);h&&p&&(o.onOpenChange(!1),(f=a.trigger)==null||f.focus(),u.preventDefault())})})})})})});OD.displayName=jD;function DD(e){return e?"open":"closed"}function Af(e){return e==="indeterminate"}function c1(e){return Af(e)?"indeterminate":e?"checked":"unchecked"}function une(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function dne(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function hne(e,t,n){const s=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,o=n?e.indexOf(n):-1;let i=dne(e,Math.max(o,0));s.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(s.toLowerCase()));return l!==n?l:void 0}function pne(e,t){const{x:n,y:r}=e;let s=!1;for(let o=0,i=t.length-1;o<t.length;i=o++){const a=t[o].x,l=t[o].y,c=t[i].x,u=t[i].y;l>r!=u>r&&n<(c-a)*(r-l)/(u-l)+a&&(s=!s)}return s}function fne(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return pne(n,t)}function Au(e){return t=>t.pointerType==="mouse"?e(t):void 0}var RD=fD,LD=n1,$D=mD,ND=yD,FD=i1,zD=SD,BD=Bg,UD=xD,HD=bD,KD=CD,WD=ED,GD=kD,VD=_D,YD=MD,XD=AD,qD=OD,u1="ContextMenu",[gne,jae]=Ms(u1,[zg]),pn=zg(),[mne,ZD]=gne(u1),QD=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:s,modal:o=!0}=e,[i,a]=P.useState(!1),l=pn(t),c=Xt(r),u=P.useCallback(h=>{a(h),c(h)},[c]);return d.jsx(mne,{scope:t,open:i,onOpenChange:u,modal:o,children:d.jsx(RD,{...l,dir:s,open:i,onOpenChange:u,modal:o,children:n})})};QD.displayName=u1;var JD="ContextMenuTrigger",eR=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...s}=e,o=ZD(JD,n),i=pn(n),a=P.useRef({x:0,y:0}),l=P.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=P.useRef(0),u=P.useCallback(()=>window.clearTimeout(c.current),[]),h=p=>{a.current={x:p.clientX,y:p.clientY},o.onOpenChange(!0)};return P.useEffect(()=>u,[u]),P.useEffect(()=>void(r&&u()),[r,u]),d.jsxs(d.Fragment,{children:[d.jsx(LD,{...i,virtualRef:l}),d.jsx(_e.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...s,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:re(e.onContextMenu,p=>{u(),h(p),p.preventDefault()}),onPointerDown:r?e.onPointerDown:re(e.onPointerDown,vh(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?e.onPointerMove:re(e.onPointerMove,vh(u)),onPointerCancel:r?e.onPointerCancel:re(e.onPointerCancel,vh(u)),onPointerUp:r?e.onPointerUp:re(e.onPointerUp,vh(u))})]})});eR.displayName=JD;var yne="ContextMenuPortal",d1=e=>{const{__scopeContextMenu:t,...n}=e,r=pn(t);return d.jsx($D,{...r,...n})};d1.displayName=yne;var tR="ContextMenuContent",nR=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=ZD(tR,n),o=pn(n),i=P.useRef(!1);return d.jsx(ND,{...o,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=e.onCloseAutoFocus)==null||l.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=e.onInteractOutside)==null||l.call(e,a),!a.defaultPrevented&&!s.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});nR.displayName=tR;var Sne="ContextMenuGroup",rR=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(FD,{...s,...r,ref:t})});rR.displayName=Sne;var vne="ContextMenuLabel",xne=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(zD,{...s,...r,ref:t})});xne.displayName=vne;var wne="ContextMenuItem",sR=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(BD,{...s,...r,ref:t})});sR.displayName=wne;var bne="ContextMenuCheckboxItem",oR=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(UD,{...s,...r,ref:t})});oR.displayName=bne;var Pne="ContextMenuRadioGroup",Cne=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(HD,{...s,...r,ref:t})});Cne.displayName=Pne;var Ine="ContextMenuRadioItem",Ene=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(KD,{...s,...r,ref:t})});Ene.displayName=Ine;var kne="ContextMenuItemIndicator",_ne=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(WD,{...s,...r,ref:t})});_ne.displayName=kne;var Tne="ContextMenuSeparator",Mne=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(GD,{...s,...r,ref:t})});Mne.displayName=Tne;var Ane="ContextMenuArrow",jne=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(VD,{...s,...r,ref:t})});jne.displayName=Ane;var One="ContextMenuSub",iR=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,open:s,defaultOpen:o}=e,i=pn(t),[a,l]=ui({prop:s,defaultProp:o,onChange:r});return d.jsx(YD,{...i,open:a,onOpenChange:l,children:n})};iR.displayName=One;var Dne="ContextMenuSubTrigger",aR=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(XD,{...s,...r,ref:t})});aR.displayName=Dne;var Rne="ContextMenuSubContent",lR=P.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,s=pn(n);return d.jsx(qD,{...s,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});lR.displayName=Rne;function vh(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var Lne=QD,$ne=eR,Nne=d1,Fne=nR,zne=oR;const cR=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Bne=cR?"⌘":"Ctrl",Une=cR?"⌥":"Alt";function uR(e){return e.split(",")[0].split("").map(t=>{const n=t.replace(/\$/g,Bne).replace(/\?/g,Une).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function tx(e){return"— "+uR(e).join(" ")}function Hne(e){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}var h1="DropdownMenu",[Kne,Oae]=Ms(h1,[zg]),fn=zg(),[Wne,dR]=Kne(h1),hR=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:s,defaultOpen:o,onOpenChange:i,modal:a=!0}=e,l=fn(t),c=P.useRef(null),[u=!1,h]=ui({prop:s,defaultProp:o,onChange:i});return d.jsx(Wne,{scope:t,triggerId:qs(),triggerRef:c,contentId:qs(),open:u,onOpenChange:h,onOpenToggle:P.useCallback(()=>h(p=>!p),[h]),modal:a,children:d.jsx(RD,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:n})})};hR.displayName=h1;var pR="DropdownMenuTrigger",fR=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...s}=e,o=dR(pR,n),i=fn(n);return d.jsx(LD,{asChild:!0,...i,children:d.jsx(_e.button,{type:"button",id:o.triggerId,"aria-haspopup":"menu","aria-expanded":o.open,"aria-controls":o.open?o.contentId:void 0,"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...s,ref:bg(t,o.triggerRef),onPointerDown:re(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(o.onOpenToggle(),o.open||a.preventDefault())}),onKeyDown:re(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&o.onOpenToggle(),a.key==="ArrowDown"&&o.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});fR.displayName=pR;var Gne="DropdownMenuPortal",gR=e=>{const{__scopeDropdownMenu:t,...n}=e,r=fn(t);return d.jsx($D,{...r,...n})};gR.displayName=Gne;var mR="DropdownMenuContent",yR=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=dR(mR,n),o=fn(n),i=P.useRef(!1);return d.jsx(ND,{id:s.contentId,"aria-labelledby":s.triggerId,...o,...r,ref:t,onCloseAutoFocus:re(e.onCloseAutoFocus,a=>{var l;i.current||(l=s.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:re(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!s.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});yR.displayName=mR;var Vne="DropdownMenuGroup",SR=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(FD,{...s,...r,ref:t})});SR.displayName=Vne;var Yne="DropdownMenuLabel",Xne=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(zD,{...s,...r,ref:t})});Xne.displayName=Yne;var qne="DropdownMenuItem",vR=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(BD,{...s,...r,ref:t})});vR.displayName=qne;var Zne="DropdownMenuCheckboxItem",xR=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(UD,{...s,...r,ref:t})});xR.displayName=Zne;var Qne="DropdownMenuRadioGroup",Jne=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(HD,{...s,...r,ref:t})});Jne.displayName=Qne;var ere="DropdownMenuRadioItem",tre=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(KD,{...s,...r,ref:t})});tre.displayName=ere;var nre="DropdownMenuItemIndicator",rre=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(WD,{...s,...r,ref:t})});rre.displayName=nre;var sre="DropdownMenuSeparator",ore=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(GD,{...s,...r,ref:t})});ore.displayName=sre;var ire="DropdownMenuArrow",are=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(VD,{...s,...r,ref:t})});are.displayName=ire;var lre=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:s,defaultOpen:o}=e,i=fn(t),[a=!1,l]=ui({prop:r,defaultProp:o,onChange:s});return d.jsx(YD,{...i,open:a,onOpenChange:l,children:n})},cre="DropdownMenuSubTrigger",wR=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(XD,{...s,...r,ref:t})});wR.displayName=cre;var ure="DropdownMenuSubContent",bR=P.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,s=fn(n);return d.jsx(qD,{...s,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});bR.displayName=ure;var p1=hR,f1=fR,Ug=gR,g1=yR,dre=SR,hre=vR,pre=xR,fre=lre,gre=wR,mre=bR;function Zi({id:e,children:t,modal:n=!1,debugOpen:r=!1}){const[s,o]=po(e);return d.jsx(p1,{open:r||s,dir:"ltr",modal:n,onOpenChange:o,children:t})}function Qi({children:e,...t}){return d.jsx(f1,{dir:"ltr",asChild:!0,onTouchEnd:n=>Ee(n),...t,children:e})}function Ji({side:e="bottom",align:t="start",sideOffset:n=8,alignOffset:r=8,children:s}){const o=$t();return d.jsx(Ug,{container:o,children:d.jsx(g1,{className:"tlui-menu",side:e,sideOffset:n,align:t,alignOffset:r,collisionPadding:4,children:s})})}function yre({id:e,children:t}){const[n,r]=po(e);return d.jsx(fre,{open:n,onOpenChange:r,children:t})}function Sre({id:e,label:t,title:n,disabled:r}){return d.jsx(gre,{dir:"ltr",asChild:!0,disabled:r,children:d.jsxs(ue,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:n,children:[d.jsx(bt,{children:t}),d.jsx(ve,{icon:"chevron-right",small:!0})]})})}function vre({id:e,alignOffset:t=-1,sideOffset:n=-4,size:r="small",children:s}){const o=$t();return d.jsx(Ug,{container:o,children:d.jsx(mre,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:t,sideOffset:n,collisionPadding:4,"data-size":r,children:s})})}function xre({children:e}){return d.jsx(dre,{dir:"ltr",className:"tlui-menu__group",children:e})}function ju({noClose:e,children:t}){return d.jsx(hre,{dir:"ltr",asChild:!0,onClick:e?Ee:void 0,children:t})}function Zc({children:e,visibleOnMobileLayout:t=!1}){const n=In();return!t&&n<yt.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:uR(e).map((r,s)=>d.jsx("span",{children:r},s))})}function U({disabled:e=!1,spinner:t=!1,readonlyOk:n=!1,id:r,kbd:s,label:o,icon:i,onSelect:a,noClose:l,isSelected:c}){const{type:u,sourceId:h}=Ng(),p=we(),[f,S]=P.useState(!1);if(uo()&&!n)return null;const x=ku(o,u),m=s?tx(s):void 0,v=x?p(x):void 0,w=v&&m?`${v} ${m}`:v;switch(u){case"menu":return d.jsx(ju,{children:d.jsxs(ue,{type:"menu","data-testid":`${h}.${r}`,disabled:e,title:w,onClick:C=>{l&&Ee(C),f?S(!1):a(h)},children:[d.jsx(bt,{children:v}),s&&d.jsx(Zc,{children:s})]})});case"context-menu":return e?null:d.jsxs(sR,{dir:"ltr",title:w,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:C=>{l&&Ee(C),f?S(!1):a(h)},children:[d.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),s&&d.jsx(Zc,{children:s}),t&&d.jsx(Hne,{})]});case"panel":return d.jsxs(ue,{"data-testid":`${h}.${r}`,type:"menu",title:w,disabled:e,onClick:()=>a(h),children:[d.jsx(bt,{children:v}),i&&d.jsx(ve,{icon:i})]});case"small-icons":case"icons":return d.jsx(ue,{"data-testid":`${h}.${r}`,type:"icon",title:w,disabled:e,onClick:()=>a(h),children:d.jsx(ve,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return s?d.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${h}.${r}`,children:[d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:d.jsx(Zc,{visibleOnMobileLayout:!0,children:s})})]}):(console.warn(`Menu item '${o}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return d.jsxs(ue,{type:"low",onClick:()=>a(h),children:[d.jsx(ve,{icon:i}),d.jsx(bt,{children:v})]});case"toolbar":return d.jsx(ue,{type:"tool","data-testid":`tools.${r}`,"aria-label":x,"data-value":r,onClick:()=>a("toolbar"),title:w,onTouchStart:C=>{Ee(C),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:d.jsx(ve,{icon:i})});case"toolbar-overflow":return d.jsx(ju,{"aria-label":o,children:d.jsx(ue,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:w,role:"radio","aria-checked":c?"true":"false","data-value":r,children:d.jsx(ve,{icon:i})})});default:throw un(u)}}function wre(){return d.jsxs(d.Fragment,{children:[d.jsx(bre,{}),d.jsx(Pre,{}),d.jsx(Cre,{}),d.jsx(Ire,{}),d.jsx(Ere,{}),d.jsx(Tre,{}),d.jsx(Mre,{}),d.jsx(Are,{})]})}function bre(){const e=ae(),t=En(2),n=fo(),r=t&&n;return d.jsxs(d.Fragment,{children:[d.jsx(U,{...e["align-left"],disabled:!r}),d.jsx(U,{...e["align-center-horizontal"],disabled:!r}),d.jsx(U,{...e["align-right"],disabled:!r}),d.jsx(U,{...e["stretch-horizontal"],disabled:!r}),d.jsx(U,{...e["align-top"],disabled:!r}),d.jsx(U,{...e["align-center-vertical"],disabled:!r}),d.jsx(U,{...e["align-bottom"],disabled:!r}),d.jsx(U,{...e["stretch-vertical"],disabled:!r})]})}function Pre(){const e=ae(),t=En(3),n=fo(),r=t&&n;return d.jsxs(d.Fragment,{children:[d.jsx(U,{...e["distribute-horizontal"],disabled:!r}),d.jsx(U,{...e["distribute-vertical"],disabled:!r})]})}function Cre(){const e=ae(),t=QO(),n=fo(),r=t&&n;return d.jsxs(d.Fragment,{children:[d.jsx(U,{...e["stack-horizontal"],disabled:!r}),d.jsx(U,{...e["stack-vertical"],disabled:!r})]})}function Ire(){const e=ae(),t=En(1),n=fo(),r=t&&n;return d.jsxs(d.Fragment,{children:[d.jsx(U,{...e["send-to-back"],disabled:!r}),d.jsx(U,{...e["send-backward"],disabled:!r}),d.jsx(U,{...e["bring-forward"],disabled:!r}),d.jsx(U,{...e["bring-to-front"],disabled:!r})]})}function Ere(){return In()<yt.TABLET_SM?d.jsx(kre,{}):d.jsx(_re,{})}function kre(){const e=ae(),t=F(),n=K("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(U,{...e["zoom-to-100"],disabled:n})}function _re(){const e=ae(),t=En(1),n=fo(),r=t&&n;return d.jsx(U,{...e["rotate-ccw"],disabled:!r})}function Tre(){const e=ae(),t=En(1),n=fo(),r=t&&n;return d.jsx(U,{...e["rotate-cw"],disabled:!r})}function Mre(){const e=ae(),t=nD(),n=fo(),r=t&&n;return d.jsx(U,{...e["edit-link"],disabled:!r})}function Are(){const e=JO(),t=eD();return e?d.jsx(uE,{}):t?d.jsx(jre,{}):d.jsx(uE,{})}function uE(){const e=ae(),t=En(2),n=fo(),r=t&&n;return d.jsx(U,{...e.group,disabled:!r})}function jre(){const e=ae();return d.jsx(U,{...e.ungroup})}const Ore=P.memo(function({children:t}){const n=we(),r=In(),s=uo(),o=F(),i=K("should display quick actions when in readonly",()=>o.isInAny("hand","zoom"),[o]),a=t??d.jsx(wre,{});if(!(s&&!i))return d.jsxs(Qw,{id:"actions-menu",children:[d.jsx(Jw,{children:d.jsx(ue,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:d.jsx(ve,{icon:"dots-vertical",small:!0})})}),d.jsx(e1,{side:r>=yt.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(Mr,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function Yn({id:e,kbd:t,label:n,readonlyOk:r,onSelect:s,toggle:o=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=Ng(),u=uo(),h=we();if(u&&!r)return null;const p=ku(n,l),f=p?h(p):void 0;switch(l){case"menu":return d.jsxs(pre,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:f,onSelect:S=>{s==null||s(c),Ee(S)},disabled:i,checked:a,children:[d.jsx(Is,{small:!0,icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),t&&d.jsx(Zc,{children:t})]});case"context-menu":return d.jsxs(zne,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:f,onSelect:S=>{s(c),Ee(S)},disabled:i,checked:a,children:[d.jsx(Is,{small:!0,icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),t&&d.jsx(Zc,{children:t})]},e);default:return null}}function pe({id:e,label:t,children:n}){const{type:r,sourceId:s}=Ng(),o=we(),i=ku(t,r),a=i?o(i):void 0;switch(r){case"panel":return d.jsx("div",{className:"tlui-menu__group","data-testid":`${s}-group.${e}`,children:n});case"menu":return d.jsx(xre,{"data-testid":`${s}-group.${e}`,children:n});case"context-menu":return d.jsx(rR,{dir:"ltr",className:"tlui-menu__group","data-testid":`${s}-group.${e}`,children:n});case"keyboard-shortcuts":return d.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${s}-group.${e}`,children:[d.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),d.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:n})]});default:return n}}function kn({id:e,disabled:t=!1,label:n,size:r="small",children:s}){const{type:o,sourceId:i}=Ng(),a=$t(),l=we(),c=n?typeof n=="string"?n:n[o]??n.default:void 0,u=c?l(c):void 0;switch(o){case"menu":return d.jsxs(yre,{id:`${i}-sub.${e}`,children:[d.jsx(Sre,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:t,label:u,title:u}),d.jsx(vre,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:s})]});case"context-menu":return t?null:d.jsxs(Dre,{id:`${i}-sub.${e}`,children:[d.jsx(aR,{dir:"ltr",disabled:t,asChild:!0,children:d.jsxs(ue,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[d.jsx(bt,{children:u}),d.jsx(ve,{icon:"chevron-right",small:!0})]})}),d.jsx(d1,{container:a,children:d.jsx(lR,{"data-testid":`${i}-sub-content.${e}`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:s})})]});default:return s}}function Dre({id:e,children:t}){const[n,r]=po(e);return d.jsx(iR,{open:n,onOpenChange:r,children:t})}function PR(){const e=ae();return _te()?d.jsx(U,{...e["toggle-auto-size"]}):null}function CR(){const e=ae();return nD()?d.jsx(U,{...e["edit-link"]}):null}function Rre(){const e=ae();return En(1)?d.jsx(U,{...e.duplicate}):null}function IR(){const e=ae(),t=F();return K("should display flatten option",()=>{if(t.getSelectedShapeIds().length===0)return!1;const s=t.getOnlySelectedShape();return!(s&&t.isShapeOfType(s,"image"))},[t])?d.jsx(U,{...e["flatten-to-image"]}):null}function ER(){const e=ae();return JO()?d.jsx(U,{...e.group}):null}function kR(){const e=ae();return eD()?d.jsx(U,{...e.ungroup}):null}function _R(){const e=F(),t=ae();return K("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(s=>e.isShapeOfType(s,"frame"))},[e])?d.jsx(U,{...t["remove-frame"]}):null}function TR(){const e=F(),t=ae();return K("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?d.jsx(U,{...t["fit-frame-to-content"]}):null}function MR(){const e=F(),t=ae();return K("selected shapes",()=>e.getSelectedShapes().length>0,[e])?d.jsx(U,{...t["toggle-lock"]}):null}function m1(){const e=ae(),t=F(),n=K("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(Yn,{...e["toggle-transparent"],checked:n,toggle:!0})}function Lre(){const e=F(),t=ae(),n=K("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return d.jsx(U,{...t["unlock-all"],disabled:!n})}function AR(){const e=F(),t=K("zoomed to 100",()=>e.getZoomLevel()===1,[e]),n=ae();return d.jsx(U,{...n["zoom-to-100"],noClose:!0,disabled:t})}function jR(){const e=F(),t=K("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),n=ae();return d.jsx(U,{...n["zoom-to-fit"],disabled:!t,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function OR(){const e=F(),t=K("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),n=ae();return d.jsx(U,{...n["zoom-to-selection"],disabled:!t,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function DR(){return d.jsxs(pe,{id:"clipboard",children:[d.jsx(Nre,{}),d.jsx(Fre,{}),d.jsx(zre,{}),d.jsx(Rre,{}),d.jsx(Bre,{})]})}function $re(){var r;const e=F(),t=ae(),n=K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return d.jsxs(kn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!n,children:[d.jsxs(pe,{id:"copy-as-group",children:[d.jsx(U,{...t["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&d.jsx(U,{...t["copy-as-png"]}),d.jsx(U,{...t["copy-as-json"]})]}),d.jsx(pe,{id:"copy-as-bg",children:d.jsx(m1,{})})]})}function Nre(){const e=ae(),t=En(1);return d.jsx(U,{...e.cut,disabled:!t})}function Fre(){const e=ae(),t=tD(1);return d.jsx(U,{...e.copy,disabled:!t})}function zre(){const e=ae(),t=kte;return d.jsx(U,{...e.paste,disabled:!t})}function RR(){const e=F(),t=ae();return K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?d.jsxs(pe,{id:"conversions",children:[d.jsx($re,{}),d.jsxs(kn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[d.jsxs(pe,{id:"export-as-group",children:[d.jsx(U,{...t["export-as-svg"]}),d.jsx(U,{...t["export-as-png"]}),d.jsx(U,{...t["export-as-json"]})]}),d.jsx(pe,{id:"export-as-bg",children:d.jsx(m1,{})})]})]}):null}function LR(){const e=ae(),t=F(),n=K("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(U,{...e["select-all"],disabled:!n})}function Bre(){const e=ae(),t=En(1);return d.jsx(U,{...e.delete,disabled:!t})}function Ure(){return tD(1)?d.jsxs(kn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(ER,{}),d.jsx(kR,{}),d.jsx(IR,{}),d.jsx(CR,{}),d.jsx(TR,{}),d.jsx(_R,{}),d.jsx(NR,{}),d.jsx($R,{}),d.jsx(PR,{}),d.jsx(MR,{})]}):null}function Hre(){const e=En(2),t=Tte(),n=ae();return e||t?d.jsxs(kn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&d.jsxs(pe,{id:"align",children:[d.jsx(U,{...n["align-left"]}),d.jsx(U,{...n["align-center-horizontal"]}),d.jsx(U,{...n["align-right"]}),d.jsx(U,{...n["align-top"]}),d.jsx(U,{...n["align-center-vertical"]}),d.jsx(U,{...n["align-bottom"]})]}),d.jsx(Kre,{}),e&&d.jsxs(pe,{id:"stretch",children:[d.jsx(U,{...n["stretch-horizontal"]}),d.jsx(U,{...n["stretch-vertical"]})]}),(e||t)&&d.jsxs(pe,{id:"flip",children:[d.jsx(U,{...n["flip-horizontal"]}),d.jsx(U,{...n["flip-vertical"]})]}),d.jsx(Wre,{})]}):null}function Kre(){const e=ae();return En(3)?d.jsxs(pe,{id:"distribute",children:[d.jsx(U,{...e["distribute-horizontal"]}),d.jsx(U,{...e["distribute-vertical"]})]}):null}function Wre(){const e=ae(),t=En(2),n=QO();return t?d.jsxs(pe,{id:"order",children:[d.jsx(U,{...e.pack}),n&&d.jsx(U,{...e["stack-horizontal"]}),n&&d.jsx(U,{...e["stack-vertical"]})]}):null}function Gre(){const e=ae();return En(1)?d.jsx(kn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(pe,{id:"reorder",children:[d.jsx(U,{...e["bring-to-front"]}),d.jsx(U,{...e["bring-forward"]}),d.jsx(U,{...e["send-backward"]}),d.jsx(U,{...e["send-to-back"]})]})}):null}function Vre(){const e=F(),t=K("pages",()=>e.getPages(),[e]),n=K("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=es(),s=ae(),o=Zt();return En(1)?d.jsxs(kn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(pe,{id:"pages",children:t.map(a=>d.jsx(U,{id:a.id,disabled:n===a.id,label:a.name,onSelect:()=>{e.mark("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),a.id);const l=e.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(n)}}]}),o("move-to-page",{source:"context-menu"})}},a.id))}),d.jsx(pe,{id:"new-page",children:d.jsx(U,{...s["move-to-new-page"]})})]}):null}function $R(){const e=F(),t=ae();return K("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?d.jsx(U,{...t["convert-to-bookmark"]}):null}function NR(){const e=F(),t=ae();return K("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&Ro(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?d.jsx(U,{...t["convert-to-embed"]}):null}function Yre(){const e=ae(),t=F(),n=K("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(Yn,{...e["toggle-snap-mode"],checked:n})}function Xre(){const e=ae(),t=F(),n=K("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(Yn,{...e["toggle-tool-lock"],checked:n})}function qre(){const e=ae(),t=F(),n=K("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(Yn,{...e["toggle-grid"],checked:n})}function Zre(){const e=ae(),t=F(),n=K("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(Yn,{...e["toggle-wrap-mode"],checked:n})}function Qre(){const e=ae(),t=F(),n=K("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(Yn,{...e["toggle-focus-mode"],checked:n})}function Jre(){const e=ae(),t=F(),n=K("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(Yn,{...e["toggle-edge-scrolling"],checked:n===1})}function ese(){const e=ae(),t=F(),n=K("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(Yn,{...e["toggle-reduce-motion"],checked:n===0})}function tse(){const e=ae(),t=F(),n=K("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(Yn,{...e["toggle-debug-mode"],checked:n})}function nse(){const e=ae(),t=F(),n=K("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(Yn,{...e["toggle-dynamic-size-mode"],checked:n})}function rse(){const e=ae(),t=F(),n=K("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(Yn,{...e["toggle-paste-at-cursor"],checked:n})}function sse(){const e=F(),t=ae();return K("show cursor chat",()=>e.getCurrentToolId()==="select"&&!e.getInstanceState().isCoarsePointer,[e])?d.jsx(U,{...t["open-cursor-chat"]}):null}function ose(){const e=F(),t=Dg();return K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?d.jsxs(d.Fragment,{children:[t&&d.jsx(sse,{}),d.jsxs(pe,{id:"modify",children:[d.jsx(Ure,{}),d.jsx(Hre,{}),d.jsx(Gre,{}),d.jsx(Vre,{})]}),d.jsx(DR,{}),d.jsx(RR,{}),d.jsx(pe,{id:"select-all",children:d.jsx(LR,{})})]}):null}const ise=P.memo(function({children:t}){const n=F(),{Canvas:r}=ot(),s=P.useCallback(c=>{if(c){if(n.getInstanceState().isCoarsePointer){const u=n.getSelectedShapes(),{inputs:{currentPagePoint:h}}=n,p=n.getShapesAtPoint(h);if(!n.getSelectedShapes().length||!p.some(f=>u.includes(f))){const f=p.filter(S=>n.isShapeOrAncestorLocked(S));f.length&&n.select(...f.map(S=>S.id))}}}else{const u=n.getOnlySelectedShape();u&&n.isShapeOrAncestorLocked(u)&&n.setSelectedShapes([])}},[n]),o=$t(),[i,a]=po("context menu",s),l=t??d.jsx(ose,{});return d.jsxs(Lne,{dir:"ltr",onOpenChange:a,modal:!1,children:[d.jsx($ne,{onContextMenu:void 0,dir:"ltr",children:r?d.jsx(r,{}):null}),i&&d.jsx(Nne,{container:o,children:d.jsx(Fne,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Ee,children:d.jsx(Mr,{type:"context-menu",sourceId:"context-menu",children:l})})})]})}),ase=2e3,lse=5e3,cse=Lt(function(){const t=F(),{isChatting:n,chatMessage:r}=t.getInstanceState(),s=P.useRef(-1),[o,i]=P.useState("");return P.useEffect(()=>{if(!n&&r||n){const l=n?lse:ase;s.current=t.timers.setTimeout(()=>{t.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),t.focus()},l)}return()=>{clearTimeout(s.current)}},[t,r,n]),n?d.jsx(dse,{value:o,setValue:i,chatMessage:r}):r.trim()?d.jsx(use,{chatMessage:r}):null});function FR(e){const t=F();P.useLayoutEffect(()=>{var i;if(!e.current)return;const{x:r,y:s}=t.inputs.currentScreenPoint;(i=e.current)==null||i.style.setProperty("transform",`translate(${r}px, ${s}px)`);function o(a){var u;const{minX:l,minY:c}=t.getViewportScreenBounds();(u=e.current)==null||u.style.setProperty("transform",`translate(${a.clientX-l}px, ${a.clientY-c}px)`)}return window.addEventListener("pointermove",o),()=>{window.removeEventListener("pointermove",o)}},[e,t])}const use=({chatMessage:e})=>{const t=F(),n=P.useRef(null);return FR(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:t.user.getColor()},children:e})},dse=Lt(function({chatMessage:t,value:n,setValue:r}){const s=F(),o=we(),i=P.useRef(null),a=t||o("cursor-chat.type-to-chat");FR(i),P.useLayoutEffect(()=>{const p=i.current;if(!p)return;const f=s.textMeasure.measureText(n||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});p.style.setProperty("width",f.w+"px")},[s,n,a]),P.useLayoutEffect(()=>{const p=s.timers.requestAnimationFrame(()=>{var f;(f=i.current)==null||f.focus()});return()=>{cancelAnimationFrame(p)}},[s]);const l=P.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),c=P.useCallback(p=>{const{value:f}=p.target;r(f.slice(0,64)),s.updateInstanceState({chatMessage:f})},[s,r]),u=P.useCallback(p=>{const f=i.current;if(!f)return;const{value:S}=f;switch(p.key){case"Enter":{if(Ee(p),p.stopPropagation(),!S){l();return}r("");break}case"Escape":{Ee(p),p.stopPropagation(),l();break}}},[l,r]),h=P.useCallback(p=>{p.stopPropagation()},[]);return d.jsx("input",{ref:i,className:"tl-cursor-chat",style:{backgroundColor:s.user.getColor()},onBlur:l,onChange:c,onKeyDown:u,onPaste:h,value:n,placeholder:a,spellCheck:!1})});function nx({checked:e}){return d.jsx(Is,{icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function hse(){const e=F(),{addToast:t}=es(),{addDialog:n}=aa(),[r,s]=Ce.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(pe,{id:"items",children:[d.jsx(U,{id:"add-toast",onSelect:()=>{t({id:ct(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),t({id:ct(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"info",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),t({id:ct(),title:"Something maybe bad happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"warning",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),t({id:ct(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),d.jsx(U,{id:"show-dialog",label:"Show dialog",onSelect:()=>{n({component:({onClose:o})=>d.jsx(gse,{displayDontShowAgain:!0,onCancel:()=>o(),onContinue:()=>o()}),onClose:()=>{}})}}),d.jsx(U,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>mse(e,100)}),d.jsx(U,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const o=e.getSelectedShapes(),i=o.length===0?e.getRenderingShapes():o;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),d.jsx(U,{id:"throw-error",onSelect:()=>s(!0),label:"Throw error"}),d.jsx(U,{id:"hard-reset",onSelect:b2,label:"Hard reset"})]}),d.jsxs(pe,{id:"flags",children:[d.jsx(pse,{}),d.jsx(fse,{})]})]})}function pse(){const e=Object.values(xt);return e.length?d.jsx(kn,{id:"debug flags",label:"Debug Flags",children:d.jsx(pe,{id:"debug flags",children:e.map(t=>d.jsx(zR,{flag:t},t.name))})}):null}function fse(){const e=Object.values(Wx);return e.length?d.jsx(kn,{id:"feature flags",label:"Feature Flags",children:d.jsx(pe,{id:"feature flags",children:e.map(t=>d.jsx(zR,{flag:t},t.name))})}):null}function gse({title:e="title",body:t="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,onCancel:o,onContinue:i}){const[a,l]=Ce.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(Tg,{children:[d.jsx(Mg,{children:e}),d.jsx(Ag,{})]}),d.jsx(Eu,{style:{maxWidth:350},children:t}),d.jsxs(Dw,{className:"tlui-dialog__footer__actions",children:[s&&d.jsxs(ue,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(nx,{checked:a}),d.jsx(bt,{children:"Don’t show again"})]}),d.jsx(ue,{type:"normal",onClick:o,children:d.jsx(bt,{children:n})}),d.jsx(ue,{type:"primary",onClick:async()=>i(),children:d.jsx(bt,{children:r})})]})]})}const zR=Lt(function({flag:t,onChange:n}){const r=t.get();return d.jsx(Yn,{id:t.name,title:t.name,label:t.name.replace(/([a-z0-9])([A-Z])/g,s=>`${s[0]} ${s[1].toLowerCase()}`).replace(/^[a-z]/,s=>s.toUpperCase()),checked:r,onSelect:()=>{t.set(!r),n==null||n(!r)}})});let dE=0;function mse(e,t){const n=Array(t),r=Math.floor(Math.sqrt(t));for(let s=0;s<t;s++)dE++,n[s]={id:$e("box"+dE),type:"geo",x:s%r*132,y:Math.floor(s/r)*132};e.run(()=>{e.createShapes(n).setSelectedShapes(n.map(s=>s.id))})}function yse({children:e}){const t=e??d.jsx(hse,{});return d.jsxs(Zi,{id:"debug",children:[d.jsx(Qi,{children:d.jsx(ue,{type:"icon",title:"Debug menu",children:d.jsx(ve,{icon:"dots-horizontal"})})}),d.jsx(Ji,{side:"top",align:"end",alignOffset:0,children:d.jsx(Mr,{type:"menu",sourceId:"debug-panel",children:t})})]})}const Sse=P.memo(function(){const{DebugMenu:t}=fi();return d.jsxs("div",{className:"tlui-debug-panel",children:[d.jsx(xse,{}),d.jsx(wse,{}),t&&d.jsx(t,{})]})});function vse(e=!0){const[t,n]=P.useState(0),r=F();P.useEffect(()=>{if(!e)return;const s=()=>n(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,e])}const xse=Lt(function(){vse();const t=F(),n=t.getPath(),r=t.getHoveredShape(),s=t.getOnlySelectedShape(),o=n==="select.idle"||!n.includes("select.")?r:s,i=o&&n.includes("select.")?` / ${o.type||""}${"geo"in o.props?" / "+o.props.geo:""} / [${b.ToInt(t.getPointInShapeSpace(o,t.inputs.currentPagePoint))}]`:"",a=n.startsWith("select.")&&!n.includes(".idle")?` / [${b.ToInt(t.inputs.originPagePoint)}] → [${b.ToInt(t.inputs.currentPagePoint)}] = ${b.Dist(t.inputs.originPagePoint,t.inputs.currentPagePoint).toFixed(0)}`:"";return d.jsx("div",{className:"tlui-debug-panel__current-state",children:`${n}${i}${a}`})});function wse(){const e=F(),t=K("show_fps",()=>xt.showFps.get(),[xt]),n=P.useRef(null);return P.useEffect(()=>{if(!t)return;const r=250;let s=0,o=-1,i=performance.now(),a=0,l=0,c=!1;function u(){if(l++,a=performance.now()-i,a>r){const h=Math.round(l*(r/a)*(1e3/r));h>s&&(s=h);const p=s*.75;(h<p&&!c||h>=p&&c)&&(c=!c),n.current.innerHTML=`FPS ${h.toString()}`,n.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,i=performance.now()}o=e.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(o)}},[t,e]),t?d.jsx("div",{ref:n}):null}const bse=P.memo(function(){const t=In(),{MainMenu:n,QuickActions:r,ActionsMenu:s,PageMenu:o}=fi();return!n&&!o&&t<6?null:d.jsx("div",{className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[n&&d.jsx(n,{}),o&&d.jsx(o,{}),t<6?null:d.jsxs(d.Fragment,{children:[r&&d.jsx(r,{}),s&&d.jsx(s,{})]})]})})});function Pse(){const e=F(),t=ae(),[n,r]=P.useState(!1),s=P.useRef(!1);return Lo("toggle showback to content",()=>{const o=s.current,i=e.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===e.getCulledShapes().size),o!==a&&(r(a),s.current=a)},[e]),n?d.jsx(U,{...t["back-to-content"],onSelect:()=>{t["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Cse(){const e=F(),t=ae();return K("is pen mode",()=>e.getInstanceState().isPenMode,[e])?d.jsx(U,{...t["exit-pen-mode"]}):null}function Ise(){const e=F(),t=ae();return K("is following user",()=>!!e.getInstanceState().followingUserId,[e])?d.jsx(U,{...t["stop-following"]}):null}function Ese(){return d.jsxs(d.Fragment,{children:[d.jsx(Cse,{}),d.jsx(Pse,{}),d.jsx(Ise,{})]})}function kse({children:e}){const t=e??d.jsx(Ese,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(Mr,{type:"helper-buttons",sourceId:"helper-buttons",children:t})})}function _se(){const e=ae(),t=Og(),n=Dg();return d.jsxs(d.Fragment,{children:[d.jsxs(pe,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(U,{...e["toggle-tool-lock"]}),d.jsx(U,{...e["insert-media"]}),d.jsx(U,{...t.select}),d.jsx(U,{...t.draw}),d.jsx(U,{...t.eraser}),d.jsx(U,{...t.hand}),d.jsx(U,{...t.rectangle}),d.jsx(U,{...t.ellipse}),d.jsx(U,{...t.arrow}),d.jsx(U,{...t.line}),d.jsx(U,{...t.text}),d.jsx(U,{...t.frame}),d.jsx(U,{...t.note}),d.jsx(U,{...t.laser})]}),d.jsxs(pe,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(U,{...e["toggle-dark-mode"]}),d.jsx(U,{...e["toggle-focus-mode"]}),d.jsx(U,{...e["toggle-grid"]})]}),d.jsxs(pe,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(U,{...e.undo}),d.jsx(U,{...e.redo}),d.jsx(U,{...e.cut}),d.jsx(U,{...e.copy}),d.jsx(U,{...e.paste}),d.jsx(U,{...e["select-all"]}),d.jsx(U,{...e.delete}),d.jsx(U,{...e.duplicate})]}),d.jsxs(pe,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(U,{...e["zoom-in"]}),d.jsx(U,{...e["zoom-out"]}),d.jsx(U,{...e["zoom-to-100"]}),d.jsx(U,{...e["zoom-to-fit"]}),d.jsx(U,{...e["zoom-to-selection"]})]}),d.jsxs(pe,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(U,{...e["bring-to-front"]}),d.jsx(U,{...e["bring-forward"]}),d.jsx(U,{...e["send-backward"]}),d.jsx(U,{...e["send-to-back"]}),d.jsx(U,{...e.group}),d.jsx(U,{...e.ungroup}),d.jsx(U,{...e["flip-horizontal"]}),d.jsx(U,{...e["flip-vertical"]}),d.jsx(U,{...e["align-top"]}),d.jsx(U,{...e["align-center-vertical"]}),d.jsx(U,{...e["align-bottom"]}),d.jsx(U,{...e["align-left"]}),d.jsx(U,{...e["align-center-horizontal"]}),d.jsx(U,{...e["align-right"]})]}),n&&d.jsx(pe,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:d.jsx(U,{...e["open-cursor-chat"]})})]})}const Tse=P.memo(function({children:t}){const n=we(),r=In(),s=t??d.jsx(_se,{});return d.jsxs(d.Fragment,{children:[d.jsxs(Tg,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(Mg,{children:n("shortcuts-dialog.title")}),d.jsx(Ag,{})]}),d.jsx(Eu,{className:ce("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=yt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=yt.TABLET}),children:d.jsx(Mr,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})}),Mse=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Ase(){const e=F(),t=Zt(),n=K("colorScheme",()=>e.user.getUserPreferences().colorScheme??e.user.getIsDarkMode()?"dark":"light",[e]);return d.jsx(kn,{id:"help menu color-scheme",label:"menu.theme",children:d.jsx(pe,{id:"languages",children:Mse.map(({colorScheme:r,label:s})=>d.jsx(Yn,{id:`color-scheme-${r}`,label:s,checked:r===n,onSelect:()=>{e.user.updateUserPreferences({colorScheme:r}),t("color-scheme",{source:"menu",value:r})}},r))})})}function BR(){const e=F(),t=Zt(),n=K("locale",()=>e.user.getLocale(),[e]);return d.jsx(kn,{id:"help menu language",label:"menu.language",children:d.jsx(pe,{id:"languages",children:iu.map(({locale:r,label:s})=>d.jsx(Yn,{id:`language-${r}`,title:r,label:s,checked:r===n,onSelect:()=>{e.user.updateUserPreferences({locale:r}),t("change-language",{source:"menu",locale:r})}},r))})})}function jse(){return d.jsxs(d.Fragment,{children:[d.jsx(BR,{}),d.jsx(UR,{})]})}function UR(){const{KeyboardShortcutsDialog:e}=fi(),{addDialog:t}=aa();return e?d.jsx(U,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{t({component:e})}}):null}function Ose(){return d.jsxs(d.Fragment,{children:[d.jsx(Rse,{}),d.jsx(Fse,{}),d.jsx(Dse,{}),d.jsx(zse,{}),d.jsx(Use,{}),d.jsx(Bse,{})]})}function Dse(){const e=ae();return d.jsxs(kn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[d.jsxs(pe,{id:"export-all-as-group",children:[d.jsx(U,{...e["export-all-as-svg"]}),d.jsx(U,{...e["export-all-as-png"]}),d.jsx(U,{...e["export-all-as-json"]})]}),d.jsx(pe,{id:"export-all-as-bg",children:d.jsx(m1,{})})]})}function Rse(){const e=F(),t=K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return d.jsxs(kn,{id:"edit",label:"menu.edit",disabled:!t,children:[d.jsx(Nse,{}),d.jsx(DR,{}),d.jsx(RR,{}),d.jsx(Lse,{}),d.jsx($se,{}),d.jsx(pe,{id:"select-all",children:d.jsx(LR,{})})]})}function Lse(){return d.jsxs(pe,{id:"misc",children:[d.jsx(ER,{}),d.jsx(kR,{}),d.jsx(CR,{}),d.jsx(PR,{}),d.jsx(_R,{}),d.jsx(TR,{}),d.jsx(NR,{}),d.jsx($R,{}),d.jsx(IR,{})]})}function $se(){return d.jsxs(pe,{id:"lock",children:[d.jsx(MR,{}),d.jsx(Lre,{})]})}function Nse(){const e=ae(),t=sD(),n=rD();return d.jsxs(pe,{id:"undo-redo",children:[d.jsx(U,{...e.undo,disabled:!t}),d.jsx(U,{...e.redo,disabled:!n})]})}function Fse(){const e=ae();return d.jsx(kn,{id:"view",label:"menu.view",children:d.jsxs(pe,{id:"view-actions",children:[d.jsx(U,{...e["zoom-in"]}),d.jsx(U,{...e["zoom-out"]}),d.jsx(AR,{}),d.jsx(jR,{}),d.jsx(OR,{})]})})}function zse(){const e=ae();return d.jsxs(pe,{id:"extras",children:[d.jsx(U,{...e["insert-embed"]}),d.jsx(U,{...e["insert-media"]})]})}function Bse(){function e(t){window.open(t,"_blank")}return d.jsx(pe,{id:"help",children:d.jsx(kn,{id:"help",label:"menu.help",children:d.jsxs(pe,{id:"help-actions",children:[d.jsx(UR,{}),d.jsx(U,{id:"about",label:"help-menu.docs",icon:"external-link",readonlyOk:!0,onSelect:()=>{e("https://tldraw.dev")}})]})})})}function Use(){return d.jsx(pe,{id:"preferences",children:d.jsxs(kn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(pe,{id:"preferences-actions",children:[d.jsx(Yre,{}),d.jsx(Xre,{}),d.jsx(qre,{}),d.jsx(Zre,{}),d.jsx(Qre,{}),d.jsx(Jre,{}),d.jsx(ese,{}),d.jsx(nse,{}),d.jsx(rse,{}),d.jsx(tse,{})]}),d.jsx(pe,{id:"color-scheme",children:d.jsx(Ase,{})}),d.jsx(pe,{id:"language",children:d.jsx(BR,{})})]})})}const Hse=P.memo(function({children:t}){const n=$t(),[r,s]=po("main menu"),o=we(),i=t??d.jsx(Ose,{});return d.jsxs(p1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(f1,{asChild:!0,dir:"ltr",children:d.jsx(ue,{type:"icon","data-testid":"main-menu.button",title:o("menu.title"),children:d.jsx(ve,{icon:"menu",small:!0})})}),d.jsx(Ug,{container:n,children:d.jsx(g1,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(Mr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),Dy={};function hc(e){if(Dy[e])return Dy[e];const n=document.createElement("canvas").getContext("2d");n.fillStyle=e,n.fillRect(0,0,1,1);const[r,s,o,i]=n.getImageData(0,0,1,1).data,a=new Float32Array([r/255,s/255,o/255,i/255]);return Dy[e]=a,a}const Sp=10,HR=4*6*Sp+12+4*12;function Pa(e,{center:t,radius:n,numArcSegments:r=20,startAngle:s=0,endAngle:o=Le,offset:i=0}){const a=(o-s)/r;let l=i;for(let c=s;c<o;c+=a)e[l++]=t.x,e[l++]=t.y,e[l++]=t.x+Math.cos(c)*n,e[l++]=t.y+Math.sin(c)*n,e[l++]=t.x+Math.cos(c+a)*n,e[l++]=t.y+Math.sin(c+a)*n;return e}function Ca(e,t,n,r,s,o){e[t++]=n,e[t++]=r,e[t++]=n,e[t++]=r+o,e[t++]=n+s,e[t++]=r,e[t++]=n+s,e[t++]=r,e[t++]=n,e[t++]=r+o,e[t++]=n+s,e[t++]=r+o}function Kse(e,t,n){const r=Sp;n=Math.min(n,Math.min(t.w,t.h)/2);const s=Q.ExpandBy(t,-n);if(s.w<=0||s.h<=0)return Pa(e,{center:t.center,radius:n,numArcSegments:Sp*4}),Sp*4*6;let o=0;return Ca(e,o,s.minX,s.minY,s.w,s.h),o+=12,Ca(e,o,s.minX,t.minY,s.w,n),o+=12,Ca(e,o,s.maxX,s.minY,n,s.h),o+=12,Ca(e,o,s.minX,s.maxY,s.w,n),o+=12,Ca(e,o,t.minX,s.minY,n,s.h),o+=12,Pa(e,{numArcSegments:r,offset:o,center:s.point,radius:n,startAngle:Me,endAngle:Me*1.5}),o+=r*6,Pa(e,{numArcSegments:r,offset:o,center:b.Add(s.point,new b(s.w,0)),radius:n,startAngle:Me*1.5,endAngle:Le}),o+=r*6,Pa(e,{numArcSegments:r,offset:o,center:b.Add(s.point,s.size),radius:n,startAngle:0,endAngle:Ve}),o+=r*6,Pa(e,{numArcSegments:r,offset:o,center:b.Add(s.point,new b(0,s.h)),radius:n,startAngle:Ve,endAngle:Me}),HR}function Wse(e){if(!e)throw new Error("Canvas element not found");const t=e.getContext("webgl2",{premultipliedAlpha:!1});if(!t)throw new Error("Failed to get webgl2 context");const n=`#version 300 es
|
|
348
|
-
precision mediump float;
|
|
349
|
-
|
|
350
|
-
in vec2 shapeVertexPosition;
|
|
351
|
-
|
|
352
|
-
uniform vec4 canvasPageBounds;
|
|
353
|
-
|
|
354
|
-
// taken (with thanks) from
|
|
355
|
-
// https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
|
|
356
|
-
void main() {
|
|
357
|
-
// convert the position from pixels to 0.0 to 1.0
|
|
358
|
-
vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
|
|
359
|
-
|
|
360
|
-
// convert from 0->1 to 0->2
|
|
361
|
-
vec2 zeroToTwo = zeroToOne * 2.0;
|
|
362
|
-
|
|
363
|
-
// convert from 0->2 to -1->+1 (clipspace)
|
|
364
|
-
vec2 clipSpace = zeroToTwo - 1.0;
|
|
365
|
-
|
|
366
|
-
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
367
|
-
}`,r=t.createShader(t.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const s=`#version 300 es
|
|
368
|
-
precision mediump float;
|
|
369
|
-
|
|
370
|
-
uniform vec4 fillColor;
|
|
371
|
-
out vec4 outputColor;
|
|
372
|
-
|
|
373
|
-
void main() {
|
|
374
|
-
outputColor = fillColor;
|
|
375
|
-
}`,o=t.createShader(t.FRAGMENT_SHADER);if(!o)throw new Error("Failed to create fragment shader");if(t.shaderSource(o,s),t.compileShader(o),!t.getShaderParameter(o,t.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=t.createProgram();if(!i)throw new Error("Failed to create program");if(t.attachShader(i,r),t.attachShader(i,o),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS))throw new Error("Failed to link program");t.useProgram(i);const a=t.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");t.enableVertexAttribArray(a);const l=t.getUniformLocation(i,"canvasPageBounds"),c=t.getUniformLocation(i,"fillColor");if(!t.createBuffer())throw new Error("Failed to create buffer");if(!t.createBuffer())throw new Error("Failed to create buffer");return{context:t,selectedShapes:xh(t,1024),unselectedShapes:xh(t,4096),viewport:xh(t,HR),collaborators:xh(t,1024),prepareTriangles(p,f){t.bindBuffer(t.ARRAY_BUFFER,p.buffer),t.bufferData(t.ARRAY_BUFFER,p.vertices,t.STATIC_DRAW,0,f),t.enableVertexAttribArray(a),t.vertexAttribPointer(a,2,t.FLOAT,!1,0,0)},drawTrianglesTransparently(p){t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.drawArrays(t.TRIANGLES,0,p/2),t.disable(t.BLEND)},drawTriangles(p){t.drawArrays(t.TRIANGLES,0,p/2)},setFillColor(p){t.uniform4fv(c,p)},setCanvasPageBounds(p){t.uniform4fv(l,p)}}}function xh(e,t){const n=e.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(t)}}function hE(e,t,n){let r=e.vertices.length;for(;r<t+n.length;)r*=2;if(r!=e.vertices.length){const s=new Float32Array(r);s.set(e.vertices),e.vertices=s}e.vertices.set(n,t)}var Gse=Object.defineProperty,Vse=Object.getOwnPropertyDescriptor,pi=(e,t,n,r)=>{for(var s=Vse(t,n),o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(t,n,s)||s);return s&&Gse(t,n,s),s};class go{constructor(t,n,r){g(this,"disposables",[]);g(this,"close",()=>this.disposables.forEach(t=>t()));g(this,"gl");g(this,"shapeGeometryCache");g(this,"colors");g(this,"id",ct());g(this,"canvasBoundingClientRect",Mt("canvasBoundingClientRect",new Q));g(this,"originPagePoint",new b);g(this,"originPageCenter",new b);g(this,"isInViewport",!1);g(this,"getMinimapPagePoint",(t,n)=>{const r=this.getCanvasPageBounds(),s=this.getCanvasScreenBounds();let o=t-s.x,i=n-s.y;return o*=r.width/s.width,i*=r.height/s.height,o+=r.minX,i+=r.minY,new b(o,i,1)});g(this,"minimapScreenPointToPagePoint",(t,n,r=!1,s=!1)=>{const{editor:o}=this,i=o.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(t,n);if(s){const c=this.editor.getCurrentPageBounds()??new Q,u=c.minX-i.width/2,h=c.maxX+i.width/2,p=c.minY-i.height/2,f=c.maxY+i.height/2,S=Math.max(0,u+i.width-a),y=Math.max(0,-(h-i.width-a)),x=Math.max(0,p+i.height-l),m=Math.max(0,-(f-i.height-l));a+=(S-y)/2,l+=(x-m)/2,a=_t(a,u,h),l=_t(l,p,f)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),h=Math.abs(l-c.y);u>h?l=c.y:a=c.x}return new b(a,l)});g(this,"render",()=>{const t=this.gl.context,n=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=n.x,this.elem.height=n.y,t.viewport(0,0,n.x,n.y),t.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),t.clear(t.COLOR_BUFFER_BIT);const r=new Set(this.editor.getSelectedShapeIds()),s=this.colors;let o=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let l=0,c=a.length;l<c;l++){const u=a[l],h=this.shapeGeometryCache.get(u);if(!h)continue;const p=h.length;r.has(u)?(hE(this.gl.selectedShapes,o,h),o+=p):(hE(this.gl.unselectedShapes,i,h),i+=p)}this.drawShapes(this.gl.unselectedShapes,i,s.shapeFill),this.drawShapes(this.gl.selectedShapes,o,s.selectFill),this.drawViewport(),this.drawCollaborators()});this.editor=t,this.elem=n,this.container=r,this.gl=Wse(n),this.shapeGeometryCache=t.store.createComputedCache("webgl-geometry",s=>{const o=t.getShapeMaskedPageBounds(s.id);if(!o)return null;const i=new Float32Array(12);return Ca(i,0,o.x,o.y,o.w,o.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),ra("minimap render",this.render))}_getColors(){const t=getComputedStyle(this.editor.getContainer());return{shapeFill:hc(t.getPropertyValue("--color-text-3").trim()),selectFill:hc(t.getPropertyValue("--color-selected").trim()),viewportFill:hc(t.getPropertyValue("--color-muted-1").trim()),background:hc(t.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const t=this.editor.getViewportPageBounds(),n=this.editor.getCurrentPageBounds();return n?Q.Expand(n,t):t}getContentScreenBounds(){const t=this.getContentPageBounds(),n=this.editor.pageToScreen(t.point),r=this.editor.pageToScreen(new b(t.maxX,t.maxY));return new Q(n.x,n.y,r.x-n.x,r.y-n.y)}_getCanvasBoundingRect(){const{x:t,y:n,width:r,height:s}=this.elem.getBoundingClientRect();return new Q(t,n,r,s)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const t=new ResizeObserver(()=>{const n=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(n)});return t.observe(this.elem),t.observe(this.container),()=>t.disconnect()}getCanvasSize(){const t=this.canvasBoundingClientRect.get(),n=this.getDpr();return new b(t.width*n,t.height*n)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const t=this.getCanvasScreenBounds(),n=this.getContentPageBounds(),r=t.width/t.height;let s=n.width,o=s/r;o<n.height&&(o=n.height,s=o*r);const i=new Q(0,0,s,o);return i.center=n.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:t,y:n,w:r,h:s}=this.getCanvasPageBounds();return new Float32Array([t,n,r,s])}drawShapes(t,n,r){this.gl.prepareTriangles(t,n),this.gl.setFillColor(r),this.gl.drawTriangles(n)}drawViewport(){const t=this.editor.getViewportPageBounds(),n=Kse(this.gl.viewport.vertices,t,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,n),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(n),this.editor.environment.isSafari&&(this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n))}drawCollaborators(){const t=this.editor.getCollaboratorsOnCurrentPage();if(!t.length)return;const n=20,r=n*6,s=r*t.length;this.gl.collaborators.vertices.length<s&&(this.gl.collaborators.vertices=new Float32Array(s));const o=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:l}of t)Pa(o,{center:b.From(l),radius:3*a,offset:i,numArcSegments:n}),i+=r;this.gl.prepareTriangles(this.gl.collaborators,s),i=0;for(const{color:l}of t)this.gl.setFillColor(hc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}pi([G],go.prototype,"getDpr");pi([G],go.prototype,"getContentPageBounds");pi([G],go.prototype,"getContentScreenBounds");pi([G],go.prototype,"getCanvasSize");pi([G],go.prototype,"getCanvasClientPosition");pi([G],go.prototype,"getCanvasPageBounds");pi([G],go.prototype,"getZoom");pi([G],go.prototype,"getCanvasPageBoundsArray");function Yse(){const e=F(),t=$t(),n=P.useRef(null),r=P.useRef(!1),s=P.useRef();P.useEffect(()=>{try{const u=new go(e,n.current,t);return s.current=u,s.current.close}catch(u){e.annotateError(u,{origin:"minimap",willCrashApp:!1}),e.timers.setTimeout(()=>{throw u})}},[e,t]);const o=P.useCallback(u=>{if(!e.getCurrentPageShapeIds().size||!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.originPagePoint.setTo(p),s.current.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(h,{animation:{duration:e.options.animationMediumMs}})},[e]),i=P.useCallback(u=>{if(!s.current)return;const h=u.currentTarget;if(Wu(h,u),!e.getCurrentPageShapeIds().size)return;r.current=!0,s.current.isInViewport=!1;const p=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=e.getViewportPageBounds(),S=s.current.getContentPageBounds();if(new Q(S.x-f.width/2,S.y-f.height/2,S.width+f.width,S.height+f.height).containsPoint(p)&&!f.containsPoint(p)){s.current.isInViewport=f.containsPoint(p);const m=b.Sub(f.center,f.point),v=b.Add(p,m);s.current.originPagePoint.setTo(v),s.current.originPageCenter.setTo(p),e.centerOnPoint(p,{animation:{duration:e.options.animationMediumMs}})}else{const m=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.isInViewport=f.containsPoint(m),s.current.originPagePoint.setTo(m),s.current.originPageCenter.setTo(f.center)}function x(m){h&&Gu(h,m),r.current=!1,document.body.removeEventListener("pointerup",x)}document.body.addEventListener("pointerup",x)},[e]),a=P.useCallback(u=>{if(!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(s.current.isInViewport){const y=s.current.originPagePoint.clone().sub(s.current.originPageCenter);e.centerOnPoint(b.Sub(h,y));return}e.centerOnPoint(h)}const p=s.current.getMinimapPagePoint(u.clientX,u.clientY),f=e.pageToScreen(p),S={type:"pointer",target:"canvas",name:"pointer_move",...Nn(u),point:f,isPen:e.getInstanceState().isPenMode};e.dispatch(S)},[e]),l=P.useCallback(u=>{const h=u2(u);e.dispatch({type:"wheel",name:"wheel",delta:h,point:new b(u.clientX,u.clientY),shiftKey:u.shiftKey,altKey:u.altKey,ctrlKey:u.metaKey||u.ctrlKey})},[e]),c=td();return P.useEffect(()=>{e.timers.setTimeout(()=>{var u,h;(u=s.current)==null||u.updateColors(),(h=s.current)==null||h.render()})},[c,e]),d.jsx("div",{className:"tlui-minimap",children:d.jsx("canvas",{role:"img","aria-label":"minimap",ref:n,className:"tlui-minimap__canvas",onDoubleClick:o,onPointerMove:a,onPointerDown:i,onWheel:l})})}function Xse(e,t){const[n,r]=Ce.useState(t);Ce.useLayoutEffect(()=>{const o=Ux(e);if(o)try{r(JSON.parse(o))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const s=Ce.useCallback(o=>{r(i=>{const a=typeof o=="function"?o(i):o;return Hx(e,JSON.stringify(a)),a})},[e]);return[n,s]}const qse=P.memo(function(){const t=ae(),n=we(),r=In(),[s,o]=Xse("minimap",!0),i=P.useCallback(()=>{o(c=>!c)},[o]),{ZoomMenu:a,Minimap:l}=fi();return r<yt.MOBILE?null:d.jsxs("div",{className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<yt.TABLET?d.jsx(a,{}):s?d.jsxs(d.Fragment,{children:[a&&d.jsx(a,{}),l&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(ve,{icon:s?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(ku(t["zoom-out"].label))} ${tx(t["zoom-out"].kbd)}`,onClick:()=>t["zoom-out"].onSelect("navigation-zone"),children:d.jsx(ve,{icon:"minus"})}),a&&d.jsx(a,{}),d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(ku(t["zoom-in"].label))} ${tx(t["zoom-in"].kbd)}`,onClick:()=>t["zoom-in"].onSelect("navigation-zone"),children:d.jsx(ve,{icon:"plus"})}),l&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(ve,{icon:s?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=yt.TABLET&&!s&&d.jsx(l,{})]})}),Zse=function({name:t,id:n,isCurrentPage:r}){const s=F(),o=Zt(),i=P.useRef(null),a=P.useCallback(()=>{s.mark("rename page")},[s]),l=P.useCallback(c=>{s.renamePage(n,c||"New Page"),o("rename-page",{source:"page-menu"})},[s,n,o]);return d.jsx(jg,{className:"tlui-page-menu__item__input",ref:c=>i.current=c,defaultValue:t,onValueChange:l,onFocus:a,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},rx=(e,t,n,r,s)=>{let o;const i=e.getPages(),a=n>r?i[r-1]:i[r],l=n>r?i[r]:i[r+1];a&&!l?o=zr(a.index):!a&&l?o=CB(i[0].index):o=ru(a.index,l.index),o!==i[n].index&&(e.mark("moving page"),e.updatePage({id:t,index:o}),s("move-page",{source:"page-menu"}))},pE=Lt(function({index:t,listSize:n,item:r,onRename:s}){const o=F(),i=we(),a=o.getPages(),l=Zt(),c=P.useCallback(()=>{o.mark("creating page");const f=Qs.createId();o.duplicatePage(r.id,f),l("duplicate-page",{source:"page-menu"})},[o,r,l]),u=P.useCallback(()=>{rx(o,r.id,t,t-1,l)},[o,r,t,l]),h=P.useCallback(()=>{rx(o,r.id,t,t+1,l)},[o,r,t,l]),p=P.useCallback(()=>{o.mark("deleting page"),o.deletePage(r.id),l("delete-page",{source:"page-menu"})},[o,r,l]);return d.jsxs(Zi,{id:`page item submenu ${t}`,children:[d.jsx(Qi,{children:d.jsx(ue,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(ve,{icon:"dots-vertical"})})}),d.jsx(Ji,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(Mr,{type:"menu",sourceId:"page-menu",children:[d.jsxs(pe,{id:"modify",children:[s&&d.jsx(U,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),d.jsx(U,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=o.options.maxPages}),t>0&&d.jsx(U,{id:"move-up",onSelect:u,label:"page-menu.submenu.move-up"}),t<n-1&&d.jsx(U,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:h})]}),n>1&&d.jsx(pe,{id:"delete",children:d.jsx(U,{id:"delete",onSelect:p,label:"page-menu.submenu.delete"})})]})})]})}),Qse=P.memo(function(){const t=F(),n=Zt(),r=we(),s=In(),o=P.useCallback(()=>m(!1),[]),[i,a]=po("page-menu",o),l=36,c=P.useRef(null),u=K("pages",()=>t.getPages(),[t]),h=K("currentPage",()=>t.getCurrentPage(),[t]),p=K("currentPageId",()=>t.getCurrentPageId(),[t]),f=uo(),S=K("maxPageCountReached",()=>t.getPages().length>=t.options.maxPages,[t]),y=K("isCoarsePointer",()=>t.getInstanceState().isCoarsePointer,[t]),[x,m]=P.useState(!1),v=P.useCallback(()=>{f||m(j=>!j)},[f]),w=P.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[C,E]=P.useState(Object.fromEntries(u.map((j,O)=>[j.id,{y:O*l,offsetY:0,isSelected:!1}])));P.useLayoutEffect(()=>{E(Object.fromEntries(u.map((j,O)=>[j.id,{y:O*l,offsetY:0,isSelected:!1}])))},[l,u]),P.useEffect(()=>{i&&t.timers.requestAnimationFrame(()=>{const j=document.querySelector(`[data-testid="page-menu-item-${p}"]`);if(j){const O=c.current;if(!O)return;const R=j.offsetTop,H=O.scrollTop;R<H&&O.scrollTo({top:R});const B=R+l,z=O.scrollTop+O.offsetHeight;B>z&&O.scrollTo({top:B-O.offsetHeight})}})},[l,p,i,t]);const _=P.useCallback(j=>{const{clientY:O,currentTarget:R}=j,{dataset:{id:H,index:B}}=R;if(!H||!B)return;const z=w.current;Wu(j.currentTarget,j),z.status="pointing",z.pointing={id:H,index:+B};const Y=C[H].y;z.startY=O,z.startIndex=Math.max(0,Math.min(Math.round(Y/l),u.length-1))},[l,u.length,C]),I=P.useCallback(j=>{const O=w.current;if(O.status==="pointing"){const{clientY:R}=j,H=R-O.startY;Math.abs(H)>5&&(O.status="dragging")}if(O.status==="dragging"){const{clientY:R}=j,H=R-O.startY,B=C[O.pointing.id],{startIndex:z,pointing:W}=O,Y=B.y+H,q=Math.max(0,Math.min(Math.round(Y/l),u.length-1)),le={...C};if(le[W.id]={y:B.y,offsetY:H,isSelected:!0},q!==O.dragIndex){O.dragIndex=q;for(let ge=0;ge<u.length;ge++){const be=u[ge];if(be.id===O.pointing.id)continue;let{y:J}=le[be.id];q===z?J=ge*l:q<z?q<=ge&&ge<z?J=(ge+1)*l:J=ge*l:q>z&&(q>=ge&&ge>z?J=(ge-1)*l:J=ge*l),J!==le[be.id].y&&(le[be.id]={y:J,offsetY:0,isSelected:!0})}}E(le)}},[l,u,C]),k=P.useCallback(j=>{const O=w.current;if(O.status==="dragging"){const{id:R,index:H}=O.pointing;rx(t,R,H,O.dragIndex,n)}Gu(j.currentTarget,j),O.status="idle"},[t,n]),T=P.useCallback(j=>{const O=w.current;j.key==="Escape"&&(O.status==="dragging"&&E(Object.fromEntries(u.map((R,H)=>[R.id,{y:H*l,offsetY:0,isSelected:!1}]))),O.status="idle")},[l,u]),M=P.useCallback(()=>{f||(t.run(()=>{t.mark("creating page");const j=Qs.createId();t.createPage({name:r("page-menu.new-page-initial-name"),id:j}),t.setCurrentPage(j),m(!0)}),n("new-page",{source:"page-menu"}))},[t,r,f,n]),D=P.useCallback(j=>{t.setCurrentPage(j),n("change-page",{source:"page-menu"})},[t,n]),$=P.useCallback((j,O)=>{t.renamePage(j,O),n("rename-page",{source:"page-menu"})},[t,n]);return d.jsxs(Qw,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(Jw,{"data-testid":"main.page-menu",children:d.jsxs(ue,{type:"menu",title:h.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[d.jsx("div",{className:"tlui-page-menu__name",children:h.name}),d.jsx(ve,{icon:"chevron-down",small:!0})]})}),d.jsx(e1,{side:"bottom",align:"start",sideOffset:6,children:d.jsxs("div",{className:"tlui-page-menu__wrapper",children:[d.jsxs("div",{className:"tlui-page-menu__header",children:[d.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!f&&d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsx(ue,{type:"icon","data-testid":"page-menu.edit",title:r(x?"page-menu.edit-done":"page-menu.edit-start"),onClick:v,children:d.jsx(ve,{icon:x?"check":"edit"})}),d.jsx(ue,{type:"icon","data-testid":"page-menu.create",title:r(S?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:S,onClick:M,children:d.jsx(ve,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((j,O)=>{const R=C[j.id]??{position:O*40,offsetY:0};return x?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:j.id===h.id?888:O,transform:`translate(0px, ${R.y+R.offsetY}px)`},children:[d.jsx(ue,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:_,onPointerUp:k,onPointerMove:I,onKeyDown:T,"data-id":j.id,"data-index":O,children:d.jsx(ve,{icon:"drag-handle-dots"})}),s<yt.TABLET_SM&&y?d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const H=window.prompt("Rename page",j.name);H&&H!==j.name&&$(j.id,H)},onDoubleClick:v,children:[d.jsx(nx,{checked:j.id===h.id}),d.jsx(bt,{children:j.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:d.jsx(Zse,{id:j.id,name:j.name,isCurrentPage:j.id===h.id})}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":x,children:d.jsx(pE,{index:O,item:j,listSize:u.length})})]},j.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>D(j.id),onDoubleClick:v,title:r("page-menu.go-to-page"),children:[d.jsx(nx,{checked:j.id===h.id}),d.jsx(bt,{children:j.name})]}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(pE,{index:O,item:j,listSize:u.length,onRename:()=>{if(t.environment.isIos){const H=window.prompt("Rename page",j.name);H&&H!==j.name&&$(j.id,H)}else m(!0),p!==j.id&&D(j.id)}})})]},j.id)})})]})})]})});function Jse(){const e=ae(),t=F(),n=sD(),r=rD(),s=En(1),o=uo(),i=K("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]),a=fo(),l=s&&a;if(!(o&&!i))return d.jsxs(d.Fragment,{children:[d.jsx(U,{...e.undo,disabled:!n}),d.jsx(U,{...e.redo,disabled:!r}),d.jsx(U,{...e.delete,disabled:!l}),d.jsx(U,{...e.duplicate,disabled:!l})]})}const eoe=P.memo(function({children:t}){const n=t??d.jsx(Jse,{});return d.jsx(Mr,{type:"small-icons",sourceId:"quick-actions",children:n})});function toe({userId:e}){const t=Yf(e);return t?d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:t.color},children:t.userName==="New User"?"":t.userName[0]??""},e):null}const noe=Lt(function({userId:t}){const n=F(),r=we(),s=Zt(),o=Yf(t),i=P.useCallback(()=>{n.getInstanceState().followingUserId===t?(n.stopFollowingUser(),s("stop-following",{source:"people-menu"})):(n.startFollowingUser(t),s("start-following",{source:"people-menu"}))},[n,t,s]),a=(o==null?void 0:o.followingUserId)===n.user.getId(),l=n.getInstanceState().followingUserId===t;return o?d.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal",children:[d.jsxs(ue,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>n.zoomToUser(t),onDoubleClick:i,children:[d.jsx(Is,{icon:"color",color:o.color}),d.jsx("div",{className:"tlui-people-menu__name",children:o.userName??"New User"})]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:i,disabled:a,"data-active":l||a,children:d.jsx(ve,{icon:a?"leading":l?"following":"follow"})})]}):null});function roe({count:e}){return d.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(e)})}const soe=Lt(function(){const t=F(),n=$t(),r=we(),s=Zt(),o=P.useRef(!1),[i,a]=P.useState(!1),l=P.useCallback(y=>{a(y)},[]),c=t.user.getColor(),u=P.useCallback(y=>{t.user.updateUserPreferences({color:y}),s("set-color",{source:"people-menu"})},[t,s]),{handleButtonClick:h,handleButtonPointerDown:p,handleButtonPointerEnter:f,handleButtonPointerUp:S}=Ce.useMemo(()=>{const y=()=>{o.current=!1,window.removeEventListener("pointerup",y)};return{handleButtonClick:C=>{const{id:E}=C.currentTarget.dataset;E&&c!==E&&u(E)},handleButtonPointerDown:C=>{const{id:E}=C.currentTarget.dataset;E&&(u(E),o.current=!0,window.addEventListener("pointerup",y))},handleButtonPointerEnter:C=>{if(!o.current)return;const{id:E}=C.currentTarget.dataset;E&&u(E)},handleButtonPointerUp:C=>{const{id:E}=C.currentTarget.dataset;E&&u(E)}}},[c,u]);return d.jsxs(Yw,{onOpenChange:l,open:i,children:[d.jsx(Xw,{dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__color",style:{color:t.user.getColor()},title:r("people-menu.change-color"),children:d.jsx(ve,{icon:"color"})})}),d.jsx(qw,{container:n,children:d.jsx(Zw,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:d.jsx("div",{className:"tlui-buttons__grid",children:jS.map(y=>d.jsx(ue,{type:"icon","data-id":y,"data-testid":y,"aria-label":y,"data-state":c===y?"hinted":void 0,title:y,className:"tlui-button-grid__button",style:{color:y},onPointerEnter:f,onPointerDown:p,onPointerUp:S,onClick:h,children:d.jsx(ve,{icon:"color"})},y))})})})]})});function ooe(){const e=F(),t=Zt(),n=K("userName",()=>e.user.getName(),[]),r=we(),s=P.useRef(n),o=P.useRef(n),[i,a]=P.useState(!1),l=P.useCallback(()=>{a(h=>!h)},[]),c=P.useCallback(h=>{o.current=h,e.user.updateUserPreferences({name:h})},[e]),u=P.useCallback(()=>{s.current!==o.current&&(t("change-user-name",{source:"people-menu"}),s.current=o.current)},[t]);return d.jsxs("div",{className:"tlui-people-menu__user",children:[d.jsx(soe,{}),i?d.jsx(jg,{className:"tlui-people-menu__user__input",defaultValue:n,onValueChange:c,onComplete:l,onCancel:l,onBlur:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{i||a(!0)},children:n}),n==="New User"?d.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")}):null]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:d.jsx(ve,{icon:i?"check":"edit"})})]})}const ioe=Lt(function({children:t}){const n=we(),r=$t(),s=F(),o=g2(),i=K("user",()=>s.user.getColor(),[s]),a=K("user",()=>s.user.getName(),[s]),[l,c]=po("people menu");return d.jsxs(Yw,{onOpenChange:c,open:l,children:[d.jsx(Xw,{dir:"ltr",asChild:!0,children:d.jsxs("button",{className:"tlui-people-menu__avatars-button",title:n("people-menu.title"),children:[o.length>5&&d.jsx(roe,{count:o.length-5}),d.jsxs("div",{className:"tlui-people-menu__avatars",children:[o.slice(-5).map(u=>d.jsx(toe,{userId:u},u)),d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx(qw,{container:r,children:d.jsx(Zw,{dir:"ltr",className:"tlui-menu",align:"end",side:"bottom",sideOffset:2,alignOffset:-5,children:d.jsxs("div",{className:"tlui-people-menu__wrapper",children:[d.jsx("div",{className:"tlui-people-menu__section",children:d.jsx(ooe,{})}),o.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:o.map(u=>d.jsx(noe,{userId:u},u+"_presence"))}),t]})})})]})});function aoe(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(ioe,{})})}const loe=Object.freeze([cr,Ni,Fi,Ps]);function KR(e=loe){const t=F();return K("getRelevantStyles",()=>{var o;const n=new kv(t.getSharedStyles()),r=!!((o=t.root.getCurrent())!=null&&o.shapeType),s=t.isIn("select")&&t.getSelectedShapeIds().length>0;if(n.size===0&&t.isIn("select")&&t.getSelectedShapeIds().length===0)for(const i of e)n.applyValue(i,t.getStyleForNextShape(i));return r||s||n.size>0?n:null},[t])}const Ir={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},Ti=P.memo(function(t){const{uiType:n,items:r,title:s,style:o,value:i,onValueChange:a,theme:l}=t,c=F(),u=we(),h=P.useRef(!1),p=P.useRef(null),{handleButtonClick:f,handleButtonPointerDown:S,handleButtonPointerEnter:y,handleButtonPointerUp:x}=P.useMemo(()=>{const m=()=>{h.current=!1,window.removeEventListener("pointerup",m);const _=p.current;_&&["TEXTAREA","INPUT"].includes(_.nodeName)&&_.focus(),p.current=null};return{handleButtonClick:_=>{const{id:I}=_.currentTarget.dataset;i.type==="shared"&&i.value===I||(c.mark("point picker item"),a(o,I))},handleButtonPointerDown:_=>{const{id:I}=_.currentTarget.dataset;c.mark("point picker item"),a(o,I),h.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",m)},handleButtonPointerEnter:_=>{if(!h.current)return;const{id:I}=_.currentTarget.dataset;a(o,I)},handleButtonPointerUp:_=>{const{id:I}=_.currentTarget.dataset;i.type==="shared"&&i.value===I||a(o,I)}}},[i,c,a,o]);return d.jsx("div",{"data-testid":`style.${n}`,className:ce("tlui-buttons__grid"),children:r.map(m=>d.jsx(ue,{type:"icon","data-id":m.value,"data-testid":`style.${n}.${m.value}`,"aria-label":m.value,"data-state":i.type==="shared"&&i.value===m.value?"hinted":void 0,title:s+" — "+u(`${n}-style.${m.value}`),className:ce("tlui-button-grid__button"),style:o===cr?{color:l[m.value].solid}:void 0,onPointerEnter:y,onPointerDown:S,onPointerUp:x,onClick:f,children:d.jsx(ve,{icon:m.icon})},m.value))})});function WR(e,[t,n]){return Math.min(n,Math.max(t,e))}function coe(e){const t=P.useRef({value:e,previous:e});return P.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var GR=["PageUp","PageDown"],VR=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],YR={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},$l="Slider",[sx,uoe,doe]=Eg($l),[XR,Dae]=Ms($l,[doe]),[hoe,Hg]=XR($l),qR=P.forwardRef((e,t)=>{const{name:n,min:r=0,max:s=100,step:o=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:h=()=>{},onValueCommit:p=()=>{},inverted:f=!1,...S}=e,y=P.useRef(new Set),x=P.useRef(0),v=i==="horizontal"?poe:foe,[w=[],C]=ui({prop:u,defaultProp:c,onChange:M=>{var $;($=[...y.current][x.current])==null||$.focus(),h(M)}}),E=P.useRef(w);function _(M){const D=voe(w,M);T(M,D)}function I(M){T(M,x.current)}function k(){const M=E.current[x.current];w[x.current]!==M&&p(w)}function T(M,D,{commit:$}={commit:!1}){const j=Poe(o),O=Coe(Math.round((M-r)/o)*o+r,j),R=WR(O,[r,s]);C((H=[])=>{const B=yoe(H,R,D);if(boe(B,l*o)){x.current=B.indexOf(R);const z=String(B)!==String(H);return z&&$&&p(B),z?B:H}else return H})}return d.jsx(hoe,{scope:e.__scopeSlider,name:n,disabled:a,min:r,max:s,valueIndexToChangeRef:x,thumbs:y.current,values:w,orientation:i,children:d.jsx(sx.Provider,{scope:e.__scopeSlider,children:d.jsx(sx.Slot,{scope:e.__scopeSlider,children:d.jsx(v,{"aria-disabled":a,"data-disabled":a?"":void 0,...S,ref:t,onPointerDown:re(S.onPointerDown,()=>{a||(E.current=w)}),min:r,max:s,inverted:f,onSlideStart:a?void 0:_,onSlideMove:a?void 0:I,onSlideEnd:a?void 0:k,onHomeKeyDown:()=>!a&&T(r,0,{commit:!0}),onEndKeyDown:()=>!a&&T(s,w.length-1,{commit:!0}),onStepKeyDown:({event:M,direction:D})=>{if(!a){const O=GR.includes(M.key)||M.shiftKey&&VR.includes(M.key)?10:1,R=x.current,H=w[R],B=o*O*D;T(H+B,R,{commit:!0})}}})})})})});qR.displayName=$l;var[ZR,QR]=XR($l,{startEdge:"left",endEdge:"right",size:"width",direction:1}),poe=P.forwardRef((e,t)=>{const{min:n,max:r,dir:s,inverted:o,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[h,p]=P.useState(null),f=qe(t,w=>p(w)),S=P.useRef(),y=t1(s),x=y==="ltr",m=x&&!o||!x&&o;function v(w){const C=S.current||h.getBoundingClientRect(),E=[0,C.width],I=y1(E,m?[n,r]:[r,n]);return S.current=C,I(w-C.left)}return d.jsx(ZR,{scope:e.__scopeSlider,startEdge:m?"left":"right",endEdge:m?"right":"left",direction:m?1:-1,size:"width",children:d.jsx(JR,{dir:y,"data-orientation":"horizontal",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:w=>{const C=v(w.clientX);i==null||i(C)},onSlideMove:w=>{const C=v(w.clientX);a==null||a(C)},onSlideEnd:()=>{S.current=void 0,l==null||l()},onStepKeyDown:w=>{const E=YR[m?"from-left":"from-right"].includes(w.key);c==null||c({event:w,direction:E?-1:1})}})})}),foe=P.forwardRef((e,t)=>{const{min:n,max:r,inverted:s,onSlideStart:o,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=P.useRef(null),h=qe(t,u),p=P.useRef(),f=!s;function S(y){const x=p.current||u.current.getBoundingClientRect(),m=[0,x.height],w=y1(m,f?[r,n]:[n,r]);return p.current=x,w(y-x.top)}return d.jsx(ZR,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:d.jsx(JR,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:y=>{const x=S(y.clientY);o==null||o(x)},onSlideMove:y=>{const x=S(y.clientY);i==null||i(x)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:y=>{const m=YR[f?"from-bottom":"from-top"].includes(y.key);l==null||l({event:y,direction:m?-1:1})}})})}),JR=P.forwardRef((e,t)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:s,onSlideEnd:o,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=Hg($l,n);return d.jsx(_e.span,{...c,ref:t,onKeyDown:re(e.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):GR.concat(VR).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:re(e.onPointerDown,h=>{const p=h.target;p.setPointerCapture(h.pointerId),h.preventDefault(),u.thumbs.has(p)?p.focus():r(h)}),onPointerMove:re(e.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&s(h)}),onPointerUp:re(e.onPointerUp,h=>{const p=h.target;p.hasPointerCapture(h.pointerId)&&(p.releasePointerCapture(h.pointerId),o(h))})})}),eL="SliderTrack",tL=P.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,s=Hg(eL,n);return d.jsx(_e.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:t})});tL.displayName=eL;var ox="SliderRange",nL=P.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,s=Hg(ox,n),o=QR(ox,n),i=P.useRef(null),a=qe(t,i),l=s.values.length,c=s.values.map(p=>sL(p,s.min,s.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(_e.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...e.style,[o.startEdge]:u+"%",[o.endEdge]:h+"%"}})});nL.displayName=ox;var ix="SliderThumb",rL=P.forwardRef((e,t)=>{const n=uoe(e.__scopeSlider),[r,s]=P.useState(null),o=qe(t,a=>s(a)),i=P.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return d.jsx(goe,{...e,ref:o,index:i})}),goe=P.forwardRef((e,t)=>{const{__scopeSlider:n,index:r,name:s,...o}=e,i=Hg(ix,n),a=QR(ix,n),[l,c]=P.useState(null),u=qe(t,v=>c(v)),h=l?!!l.closest("form"):!0,p=TO(l),f=i.values[r],S=f===void 0?0:sL(f,i.min,i.max),y=Soe(r,i.values.length),x=p==null?void 0:p[a.size],m=x?xoe(x,S,a.direction):0;return P.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${S}% + ${m}px)`},children:[d.jsx(sx.ItemSlot,{scope:e.__scopeSlider,children:d.jsx(_e.span,{role:"slider","aria-label":e["aria-label"]||y,"aria-valuemin":i.min,"aria-valuenow":f,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...o,ref:u,style:f===void 0?{display:"none"}:e.style,onFocus:re(e.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&d.jsx(moe,{name:s??(i.name?i.name+(i.values.length>1?"[]":""):void 0),value:f},r)]})});rL.displayName=ix;var moe=e=>{const{value:t,...n}=e,r=P.useRef(null),s=coe(t);return P.useEffect(()=>{const o=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(s!==t&&l){const c=new Event("input",{bubbles:!0});l.call(o,t),o.dispatchEvent(c)}},[s,t]),d.jsx("input",{style:{display:"none"},...n,ref:r,defaultValue:t})};function yoe(e=[],t,n){const r=[...e];return r[n]=t,r.sort((s,o)=>s-o)}function sL(e,t,n){const o=100/(n-t)*(e-t);return WR(o,[0,100])}function Soe(e,t){return t>2?`Value ${e+1} of ${t}`:t===2?["Minimum","Maximum"][e]:void 0}function voe(e,t){if(e.length===1)return 0;const n=e.map(s=>Math.abs(s-t)),r=Math.min(...n);return n.indexOf(r)}function xoe(e,t,n){const r=e/2,o=y1([0,50],[0,r]);return(r-o(t)*n)*n}function woe(e){return e.slice(0,-1).map((t,n)=>e[n+1]-t)}function boe(e,t){if(t>0){const n=woe(e);return Math.min(...n)>=t}return!0}function y1(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Poe(e){return(String(e).split(".")[1]||"").length}function Coe(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}var Ioe=qR,Eoe=tL,koe=nL,_oe=rL;const Toe=P.memo(function(t){const{title:n,steps:r,value:s,label:o,onValueChange:i}=t,a=F(),l=we(),c=P.useCallback(p=>{i(p[0])},[i]),u=P.useCallback(()=>{a.mark("click slider")},[a]),h=P.useCallback(()=>{s&&i(s)},[s,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(Ioe,{"data-testid":t["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:s?[s]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:h,title:n+" — "+l(o),children:[d.jsx(Eoe,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&d.jsx(koe,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&d.jsx(_oe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Moe({label:e,uiTypeA:t,uiTypeB:n,labelA:r,labelB:s,itemsA:o,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const p=we(),f=P.useMemo(()=>{var y;return((y=o.find(x=>c.type==="shared"&&c.value===x.value))==null?void 0:y.icon)??"mixed"},[o,c]),S=P.useMemo(()=>{var y;return((y=i.find(x=>u.type==="shared"&&u.value===x.value))==null?void 0:y.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:p(e),className:"tlui-style-panel__double-select-picker-label",children:p(e)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(Zi,{id:`style panel ${t} A`,children:[d.jsx(Qi,{children:d.jsx(ue,{type:"icon","data-testid":`style.${t}`,title:p(r)+" — "+(c===null||c.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${c.value}`)),children:d.jsx(ve,{icon:f,small:!0,invertIcon:!0})})}),d.jsx(Ji,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map((y,x)=>d.jsx(ju,{"data-testid":`style.${t}.${y.value}`,children:d.jsx(ue,{type:"icon",onClick:()=>h(a,y.value),title:`${p(r)} — ${p(`${t}-style.${y.value}`)}`,children:d.jsx(ve,{icon:y.icon,invertIcon:!0})},y.value)},x))})})]}),d.jsxs(Zi,{id:`style panel ${n}`,children:[d.jsx(Qi,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}`,title:p(s)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${n}-style.${u.value}`)),children:d.jsx(ve,{icon:S,small:!0})})}),d.jsx(Ji,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(y=>d.jsx(ju,{children:d.jsx(ue,{type:"icon",title:`${p(s)} — ${p(`${n}-style.${y.value}`)}`,"data-testid":`style.${n}.${y.value}`,onClick:()=>h(l,y.value),children:d.jsx(ve,{icon:y.icon})})},y.value))})})]})]})]})}const Aoe=P.memo(Moe);function joe({id:e,label:t,uiType:n,style:r,items:s,type:o,value:i,onValueChange:a}){const l=we(),c=F(),u=P.useMemo(()=>{var f;return(f=s.find(S=>i.type==="shared"&&S.value===i.value))==null?void 0:f.icon},[s,i]),h=i.type==="mixed"?l("style-panel.mixed"):l(`${n}-style.${i.value}`),p=t?l(t):"";return d.jsxs(Zi,{id:`style panel ${e}`,children:[d.jsx(Qi,{children:d.jsxs(ue,{type:o,"data-testid":`style.${n}`,title:h,children:[d.jsx(bt,{children:p}),d.jsx(ve,{icon:u??"mixed"})]})}),d.jsx(Ji,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map(f=>d.jsx(ju,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}.${f.value}`,title:l(`${n}-style.${f.value}`),onClick:()=>{c.mark("select style dropdown item"),a(r,f.value)},children:d.jsx(ve,{icon:f.icon})})},f.value))})})]})}const S1=P.memo(joe);function Ooe({styles:e}){const t=td();if(!e)return null;const n=e.get(Ur),r=e.get(Lp),s=e.get(Rp),o=e.get(zp),i=e.get(bs),a=n===void 0,l=r===void 0&&s===void 0,c=o===void 0,u=i===void 0,h=lo({isDarkMode:t});return d.jsxs(d.Fragment,{children:[d.jsx(Doe,{theme:h,styles:e}),!u&&d.jsx(Roe,{theme:h,styles:e}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(Loe,{styles:e}),d.jsx(Noe,{styles:e}),d.jsx($oe,{styles:e})]})]})}function cd(){const e=F(),t=Zt();return Ce.useMemo(()=>function(r,s){e.run(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(r,s),e.setStyleForNextShapes(r,s),e.updateInstanceState({isChangingStyle:!0})}),t("set-style",{source:"style-panel",id:r.id,value:s})},[e,t])}function Doe({styles:e,theme:t}){const n=we(),r=F(),s=cd(),o=e.get(cr),i=e.get(Fi),a=e.get(Ni),l=e.get(Ps),c=i!==void 0||a!==void 0||l!==void 0;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[o===void 0?null:d.jsx(Ti,{title:n("style-panel.color"),uiType:"color",style:cr,items:Ir.color,value:o,onValueChange:s,theme:t}),d.jsx(Foe,{})]}),c&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:d.jsx(Ti,{title:n("style-panel.fill"),uiType:"fill",style:Fi,items:Ir.fill,value:i,onValueChange:s,theme:t}),a===void 0?null:d.jsx(Ti,{title:n("style-panel.dash"),uiType:"dash",style:Ni,items:Ir.dash,value:a,onValueChange:s,theme:t}),l===void 0?null:d.jsx(Ti,{title:n("style-panel.size"),uiType:"size",style:Ps,items:Ir.size,value:l,onValueChange:(u,h)=>{s(u,h);const p=r.getSelectedShapeIds();p.length>0&&Ke(r,p)},theme:t})]})]})}function Roe({theme:e,styles:t}){const n=we(),r=cd(),s=t.get(bs),o=t.get(kS),i=t.get(Np),a=t.get(Fp);return s===void 0&&i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[s===void 0?null:d.jsx(Ti,{title:n("style-panel.font"),uiType:"font",style:bs,items:Ir.font,value:s,onValueChange:r,theme:e}),o===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Ti,{title:n("style-panel.align"),uiType:"align",style:kS,items:Ir.textAlign,value:o,onValueChange:r,theme:e}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(ve,{icon:"vertical-align-middle"})})})]}),i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Ti,{title:n("style-panel.align"),uiType:"align",style:Np,items:Ir.horizontalAlign,value:i,onValueChange:r,theme:e}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:a===void 0?d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(ve,{icon:"vertical-align-middle"})}):d.jsx(S1,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:Fp,items:Ir.verticalAlign,value:a,onValueChange:r})})]})]})}function Loe({styles:e}){const t=cd(),n=e.get(Ur);return n===void 0?null:d.jsx(S1,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:Ur,items:Ir.geo,value:n,onValueChange:t})}function $oe({styles:e}){const t=cd(),n=e.get(zp);return n===void 0?null:d.jsx(S1,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:zp,items:Ir.spline,value:n,onValueChange:t})}function Noe({styles:e}){const t=cd(),n=e.get(Lp),r=e.get(Rp);return!n||!r?null:d.jsx(Aoe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Rp,itemsA:Ir.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Lp,itemsB:Ir.arrowheadEnd,valueB:n,onValueChange:t,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const pc=[.1,.25,.5,.75,1];function Foe(){const e=F(),t=K("opacity",()=>e.getSharedOpacity(),[e]),n=Zt(),r=we(),s=Ce.useCallback(i=>{const a=pc[i];e.run(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(a),e.setOpacityForNextShapes(a),e.updateInstanceState({isChangingStyle:!0})}),n("set-style",{source:"style-panel",id:"opacity",value:i})},[e,n]);if(t===void 0)return null;const o=t.type==="mixed"?-1:pc.indexOf(dB(pc,i=>Math.abs(i-t.value)));return d.jsx(Toe,{"data-testid":"style.opacity",value:o>=0?o:pc.length-1,label:t.type==="mixed"?"style-panel.mixed":`opacity-style.${t.value}`,onValueChange:s,steps:pc.length-1,title:r("style-panel.opacity")})}const zoe=P.memo(function({isMobile:t,children:n}){const r=F(),s=KR(),o=P.useCallback(()=>{t||r.updateInstanceState({isChangingStyle:!1})},[r,t]),i=n??d.jsx(Ooe,{styles:s});return d.jsx("div",{className:ce("tlui-style-panel",{"tlui-style-panel__wrapper":!t}),"data-ismobile":t,onPointerLeave:o,children:i})});function Boe(){const e=F(),t=we(),n=KR(),r=n==null?void 0:n.get(cr),s=lo({isDarkMode:e.user.getIsDarkMode()}),o=((r==null?void 0:r.type)==="shared"?s[r.value]:s.black).solid,i=K("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=P.useCallback(c=>{c||e.updateInstanceState({isChangingStyle:!1})},[e]),{StylePanel:l}=fi();return l?d.jsxs(Qw,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(Jw,{children:d.jsx(ue,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":o},title:t("style-panel.title"),disabled:i,children:d.jsx(ve,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),d.jsx(e1,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function Uoe(){return d.jsxs(d.Fragment,{children:[d.jsx(Koe,{}),d.jsx(Woe,{}),d.jsx(Goe,{}),d.jsx(Voe,{}),d.jsx(Yoe,{}),d.jsx(Xoe,{}),d.jsx(qoe,{}),d.jsx(Zoe,{}),d.jsx(Qoe,{}),d.jsx(Joe,{}),d.jsx(tie,{}),d.jsx(eie,{}),d.jsx(sie,{}),d.jsx(aie,{}),d.jsx(nie,{}),d.jsx(iie,{}),d.jsx(oie,{}),d.jsx(rie,{}),d.jsx(lie,{}),d.jsx(cie,{}),d.jsx(uie,{}),d.jsx(die,{}),d.jsx(hie,{}),d.jsx(pie,{}),d.jsx(fie,{}),d.jsx(gie,{}),d.jsx(yie,{}),d.jsx(mie,{})]})}function Hoe(e){var r;const t=F(),n=(r=e.meta)==null?void 0:r.geo;return K("is tool selected",()=>{const s=t.getCurrentToolId(),o=t.getSharedStyles().getAsKnownValue(Ur);return n?s==="geo"&&o===n:s===e.id},[t,e.id,n])}function He({tool:e}){const t=Og(),n=Hoe(t[e]);return d.jsx(U,{...t[e],isSelected:n})}function Koe(){return d.jsx(He,{tool:"select"})}function Woe(){return d.jsx(He,{tool:"hand"})}function Goe(){return d.jsx(He,{tool:"draw"})}function Voe(){return d.jsx(He,{tool:"eraser"})}function Yoe(){return d.jsx(He,{tool:"arrow"})}function Xoe(){return d.jsx(He,{tool:"text"})}function qoe(){return d.jsx(He,{tool:"note"})}function Zoe(){const e=Og();return d.jsx(U,{...e.asset})}function Qoe(){return d.jsx(He,{tool:"rectangle"})}function Joe(){return d.jsx(He,{tool:"ellipse"})}function eie(){return d.jsx(He,{tool:"diamond"})}function tie(){return d.jsx(He,{tool:"triangle"})}function nie(){return d.jsx(He,{tool:"rhombus"})}function rie(){return d.jsx(He,{tool:"heart"})}function sie(){return d.jsx(He,{tool:"hexagon"})}function oie(){return d.jsx(He,{tool:"cloud"})}function iie(){return d.jsx(He,{tool:"star"})}function aie(){return d.jsx(He,{tool:"oval"})}function lie(){return d.jsx(He,{tool:"x-box"})}function cie(){return d.jsx(He,{tool:"check-box"})}function uie(){return d.jsx(He,{tool:"arrow-left"})}function die(){return d.jsx(He,{tool:"arrow-up"})}function hie(){return d.jsx(He,{tool:"arrow-down"})}function pie(){return d.jsx(He,{tool:"arrow-right"})}function fie(){return d.jsx(He,{tool:"line"})}function gie(){return d.jsx(He,{tool:"highlight"})}function mie(){return d.jsx(He,{tool:"frame"})}function yie(){return d.jsx(He,{tool:"laser"})}const Ry=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Ly(e,t,n,r){e.addEventListener?e.addEventListener(t,n,r):e.attachEvent&&e.attachEvent("on".concat(t),n)}function fc(e,t,n,r){e.removeEventListener?e.removeEventListener(t,n,r):e.detachEvent&&e.detachEvent("on".concat(t),n)}function oL(e,t){const n=t.slice(0,t.length-1);for(let r=0;r<n.length;r++)n[r]=e[n[r].toLowerCase()];return n}function iL(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function Sie(e,t){const n=e.length>=t.length?e:t,r=e.length>=t.length?t:e;let s=!0;for(let o=0;o<n.length;o++)r.indexOf(n[o])===-1&&(s=!1);return s}const Ou={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":Ry?173:189,"=":Ry?61:187,";":Ry?59:186,"'":222,"[":219,"]":221,"\\":220},ks={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},ax={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Bt={16:!1,18:!1,17:!1,91:!1},dt={};for(let e=1;e<20;e++)Ou["f".concat(e)]=111+e;let We=[],Qc=null,aL="all";const Fs=new Map,ud=e=>Ou[e.toLowerCase()]||ks[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),vie=e=>Object.keys(Ou).find(t=>Ou[t]===e),xie=e=>Object.keys(ks).find(t=>ks[t]===e);function lL(e){aL=e||"all"}function Du(){return aL||"all"}function wie(){return We.slice(0)}function bie(){return We.map(e=>vie(e)||xie(e)||String.fromCharCode(e))}function Pie(){const e=[];return Object.keys(dt).forEach(t=>{dt[t].forEach(n=>{let{key:r,scope:s,mods:o,shortcut:i}=n;e.push({scope:s,shortcut:i,mods:o,keys:r.split("+").map(a=>ud(a))})})}),e}function Cie(e){const t=e.target||e.srcElement,{tagName:n}=t;let r=!0;const s=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(s||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(r=!1),r}function Iie(e){return typeof e=="string"&&(e=ud(e)),We.indexOf(e)!==-1}function Eie(e,t){let n,r;e||(e=Du());for(const s in dt)if(Object.prototype.hasOwnProperty.call(dt,s))for(n=dt[s],r=0;r<n.length;)n[r].scope===e?n.splice(r,1).forEach(i=>{let{element:a}=i;return v1(a)}):r++;Du()===e&&lL(t||"all")}function kie(e){let t=e.keyCode||e.which||e.charCode;const n=We.indexOf(t);if(n>=0&&We.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&We.splice(0,We.length),(t===93||t===224)&&(t=91),t in Bt){Bt[t]=!1;for(const r in ks)ks[r]===t&&(zn[r]=!1)}}function cL(e){if(typeof e>"u")Object.keys(dt).forEach(s=>{Array.isArray(dt[s])&&dt[s].forEach(o=>wh(o)),delete dt[s]}),v1(null);else if(Array.isArray(e))e.forEach(s=>{s.key&&wh(s)});else if(typeof e=="object")e.key&&wh(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];let[s,o]=n;typeof s=="function"&&(o=s,s=""),wh({key:e,scope:s,method:o,splitKey:"+"})}}const wh=e=>{let{key:t,scope:n,method:r,splitKey:s="+"}=e;iL(t).forEach(i=>{const a=i.split(s),l=a.length,c=a[l-1],u=c==="*"?"*":ud(c);if(!dt[u])return;n||(n=Du());const h=l>1?oL(ks,a):[],p=[];dt[u]=dt[u].filter(f=>{const y=(r?f.method===r:!0)&&f.scope===n&&Sie(f.mods,h);return y&&p.push(f.element),!y}),p.forEach(f=>v1(f))})};function fE(e,t,n,r){if(t.element!==r)return;let s;if(t.scope===n||t.scope==="all"){s=t.mods.length>0;for(const o in Bt)Object.prototype.hasOwnProperty.call(Bt,o)&&(!Bt[o]&&t.mods.indexOf(+o)>-1||Bt[o]&&t.mods.indexOf(+o)===-1)&&(s=!1);(t.mods.length===0&&!Bt[16]&&!Bt[18]&&!Bt[17]&&!Bt[91]||s||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(We),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function gE(e,t){const n=dt["*"];let r=e.keyCode||e.which||e.charCode;if(!zn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),We.indexOf(r)===-1&&r!==229&&We.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=ax[a];e[a]&&We.indexOf(l)===-1?We.push(l):!e[a]&&We.indexOf(l)>-1?We.splice(We.indexOf(l),1):a==="metaKey"&&e[a]&&We.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(We=We.slice(We.indexOf(l))))}),r in Bt){Bt[r]=!0;for(const a in ks)ks[a]===r&&(zn[a]=!0);if(!n)return}for(const a in Bt)Object.prototype.hasOwnProperty.call(Bt,a)&&(Bt[a]=e[ax[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(We.indexOf(17)===-1&&We.push(17),We.indexOf(18)===-1&&We.push(18),Bt[17]=!0,Bt[18]=!0);const s=Du();if(n)for(let a=0;a<n.length;a++)n[a].scope===s&&(e.type==="keydown"&&n[a].keydown||e.type==="keyup"&&n[a].keyup)&&fE(e,n[a],s,t);if(!(r in dt))return;const o=dt[r],i=o.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&o[a].keydown||e.type==="keyup"&&o[a].keyup)&&o[a].key){const l=o[a],{splitKey:c}=l,u=l.key.split(c),h=[];for(let p=0;p<u.length;p++)h.push(ud(u[p]));h.sort().join("")===We.sort().join("")&&fE(e,l,s,t)}}function zn(e,t,n){We=[];const r=iL(e);let s=[],o="all",i=document,a=0,l=!1,c=!0,u="+",h=!1,p=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(o=t.scope),t.element&&(i=t.element),t.keyup&&(l=t.keyup),t.keydown!==void 0&&(c=t.keydown),t.capture!==void 0&&(h=t.capture),typeof t.splitKey=="string"&&(u=t.splitKey),t.single===!0&&(p=!0)),typeof t=="string"&&(o=t),p&&cL(e,o);a<r.length;a++)e=r[a].split(u),s=[],e.length>1&&(s=oL(ks,e)),e=e[e.length-1],e=e==="*"?"*":ud(e),e in dt||(dt[e]=[]),dt[e].push({keyup:l,keydown:c,scope:o,mods:s,shortcut:r[a],method:n,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!Fs.has(i)){const f=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return gE(y,i)},S=function(){let y=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;gE(y,i),kie(y)};Fs.set(i,{keydownListener:f,keyupListenr:S,capture:h}),Ly(i,"keydown",f,h),Ly(i,"keyup",S,h)}if(!Qc){const f=()=>{We=[]};Qc={listener:f,capture:h},Ly(window,"focus",f,h)}}}function _ie(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(dt).forEach(n=>{dt[n].filter(s=>s.scope===t&&s.shortcut===e).forEach(s=>{s&&s.method&&s.method()})})}function v1(e){const t=Object.values(dt).flat();if(t.findIndex(r=>{let{element:s}=r;return s===e})<0){const{keydownListener:r,keyupListenr:s,capture:o}=Fs.get(e)||{};r&&s&&(fc(e,"keyup",s,o),fc(e,"keydown",r,o),Fs.delete(e))}if((t.length<=0||Fs.size<=0)&&(Object.keys(Fs).forEach(s=>{const{keydownListener:o,keyupListenr:i,capture:a}=Fs.get(s)||{};o&&i&&(fc(s,"keyup",i,a),fc(s,"keydown",o,a),Fs.delete(s))}),Fs.clear(),Object.keys(dt).forEach(s=>delete dt[s]),Qc)){const{listener:s,capture:o}=Qc;fc(window,"focus",s,o),Qc=null}}const $y={getPressedKeyString:bie,setScope:lL,getScope:Du,deleteScope:Eie,getPressedKeyCodes:wie,getAllKeyCodes:Pie,isPressed:Iie,filter:Cie,trigger:_ie,unbind:cL,keyMap:Ou,modifier:ks,modifierMap:ax};for(const e in $y)Object.prototype.hasOwnProperty.call($y,e)&&(zn[e]=$y[e]);if(typeof window<"u"){const e=window.hotkeys;zn.noConflict=t=>(t&&window.hotkeys===zn&&(window.hotkeys=e),zn),window.hotkeys=zn}const mE=["copy","cut","paste","asset"];function Tie(){const e=F(),t=uo(),n=ae(),r=Og(),s=K("is focused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!s)return;const o=new Array,i=(l,c)=>{zn(l,{element:document.body},c),o.push(()=>{zn.unbind(l,c)})},a=(l,c)=>{zn(l,{element:document.body,keyup:!0,keydown:!1},c),o.push(()=>{zn.unbind(l,c)})};for(const l of Object.values(n))l.kbd&&(t&&!l.readonlyOk||mE.includes(l.id)||i(yE(l.kbd),c=>{Lc(e)||(Ee(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&e.getInstanceState().isReadonly||mE.includes(l.id)||i(yE(l.kbd),c=>{Lc(e)||(Ee(c),l.onSelect("kbd"))});return i(",",l=>{if(Lc(e)||e.inputs.keys.has("Comma"))return;Ee(l),e.focus(),e.inputs.keys.add("Comma");const{x:c,y:u,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_down",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),a(",",l=>{if(Lc(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),()=>{o.forEach(l=>l())}},[n,r,t,e,s])}function yE(e){return Mie(e).map(t=>{let n="";const r=t.split("");return r.length===1?n=r[0]:r[0]==="!"?n=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?n=`alt+shift+${r[2]}`:n=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?n=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?n=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:n=`cmd+${r[1]},ctrl+${r[1]}`:n=t,n}).join(",")}function Mie(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function Lc(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const Aie=P.createContext(!1);function jie({children:e}){const t=F(),n=y2(),r=In(),s=we(),o=Math.min(8,5+r),[i,a]=P.useState(0),l=P.useRef(null),[c,u]=P.useState(null),h=P.useMemo(()=>{const f=c?`:not([data-value="${c}"])`:"";return`
|
|
376
|
-
#${n}_main > *:nth-child(n + ${o+(c?1:2)})${f} {
|
|
377
|
-
display: none;
|
|
378
|
-
}
|
|
379
|
-
#${n}_more > *:nth-child(-n + ${o}) {
|
|
380
|
-
display: none;
|
|
381
|
-
}
|
|
382
|
-
`},[c,n,o]),p=qM(()=>{if(!l.current)return;const f=Array.from(l.current.children);a(f.length),f.findIndex(x=>x.getAttribute("data-value")===c)<=o&&u(null);const y=Array.from(l.current.children).findIndex(x=>x.getAttribute("aria-checked")==="true");y!==-1&&y>=o&&u(f[y].getAttribute("data-value"))});return P.useLayoutEffect(()=>{p()}),P.useLayoutEffect(()=>{if(!l.current)return;const f=new MutationObserver(p);return f.observe(l.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{f.disconnect()}},[p]),P.useEffect(()=>{const f=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[S,y]of f)zn(S,x=>{var w;if(Lc(t))return;Ee(x);const v=Array.from(((w=l.current)==null?void 0:w.children)??[]).filter(C=>!(C instanceof HTMLElement)||C.tagName.toLowerCase()!=="button"?!1:!!(C.offsetWidth||C.offsetHeight))[y];v&&v.click()});return()=>{zn.unbind("1,2,3,4,5,6,7,8,9,0")}},[t]),d.jsxs(d.Fragment,{children:[d.jsx("style",{children:h}),d.jsxs("div",{className:ce("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<yt.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${n}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(Mr,{type:"toolbar",sourceId:"toolbar",children:e})}),i>o+1&&d.jsx(Aie.Provider,{value:!0,children:d.jsxs(Zi,{id:"toolbar overflow",modal:!1,children:[d.jsx(Qi,{children:d.jsx(ue,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:d.jsx(ve,{icon:"chevron-up"})})}),d.jsx(Ji,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx(Mr,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}function Oie({activeToolId:e}){const t=F(),n=In(),r=we(),s=K("is tool locked",()=>t.getInstanceState().isToolLocked,[t]),o=K("current tool",()=>t.getCurrentTool(),[t]);return!e||!o.isLockable?null:d.jsx(ue,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ce("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<yt.TABLET_SM}),onClick:()=>t.updateInstanceState({isToolLocked:!s}),children:d.jsx(ve,{icon:s?"lock":"unlock",small:!0})})}const Die=P.memo(function({children:t}){const n=F(),r=In(),s=uo(),o=K("current tool id",()=>n.getCurrentToolId(),[n]),{ActionsMenu:i,QuickActions:a}=fi();return d.jsx("div",{className:"tlui-toolbar",children:d.jsxs("div",{className:"tlui-toolbar__inner",children:[d.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&d.jsxs("div",{className:"tlui-toolbar__extras",children:[r<yt.TABLET&&d.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&d.jsx(a,{}),i&&d.jsx(i,{})]}),d.jsx(Oie,{activeToolId:o})]}),d.jsx(jie,{children:t??d.jsx(Uoe,{})})]}),r<yt.TABLET_SM&&!s&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(Boe,{})})]})})});function Rie(){const e=we();return d.jsxs("div",{className:ce("tlui-offline-indicator"),children:[e("status.offline"),d.jsx(Is,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function Lie({maxWidth:e=420,ignoreRightWidth:t=0,stylePanelWidth:n=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:o}){const i=P.useRef(null),a=In(),l=P.useCallback(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),f=u.offsetWidth,S=h.offsetWidth,y=p.offsetWidth,x=c.offsetWidth-t;let m=(f-x)/2;f%2!==0&&(m-=.5);const v=S+r,w=c.offsetLeft,C=Math.min(f-y-S-2*r,e),E=Math.max(m,v)-w;p.offsetWidth>n&&a<=6?c.style.setProperty("max-width",C-s+"px"):c.style.setProperty("max-width",C+"px"),c.style.setProperty("transform",`translate(${E}px, 0px)`)},[a,t,r,e,s,n]);return P.useLayoutEffect(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),f=new ResizeObserver(l);return f.observe(h),f.observe(p),f.observe(u),f.observe(c),l(),()=>{f.disconnect()}},[l]),P.useLayoutEffect(()=>{l()}),d.jsx("div",{ref:i,className:"tlui-top-panel__container",children:o})}function $ie(){const e=lee()==="offline";return d.jsx(Lie,{children:e&&d.jsx(Rie,{})})}function Nie(){const e=ae();return d.jsxs(d.Fragment,{children:[d.jsx(U,{...e["zoom-in"],noClose:!0}),d.jsx(U,{...e["zoom-out"],noClose:!0}),d.jsx(AR,{}),d.jsx(jR,{}),d.jsx(OR,{})]})}const Fie=P.memo(function({children:t}){const n=$t(),[r,s]=po("zoom menu"),o=t??d.jsx(Nie,{});return d.jsxs(p1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(f1,{asChild:!0,dir:"ltr",children:d.jsx(zie,{})}),d.jsx(Ug,{container:n,children:d.jsx(g1,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(Mr,{type:"menu",sourceId:"zoom-menu",children:o})})})]})}),zie=P.forwardRef(function(t,n){const r=F(),s=In(),o=K("zoom",()=>r.getZoomLevel(),[r]),i=we(),a=P.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.jsx(ue,{ref:n,...t,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:s<yt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:s<yt.MOBILE?"zoom-in":void 0,children:s<yt.MOBILE?null:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(o*100),"%"]})})}),uL=P.createContext(null);function Bie({overrides:e={},children:t}){const n=Xf(e),r=Dg();return d.jsx(uL.Provider,{value:P.useMemo(()=>({ContextMenu:ise,ActionsMenu:Ore,HelpMenu:null,ZoomMenu:Fie,MainMenu:Hse,Minimap:Yse,StylePanel:zoe,PageMenu:Qse,NavigationPanel:qse,Toolbar:Die,KeyboardShortcutsDialog:Tse,QuickActions:eoe,HelperButtons:kse,DebugPanel:Sse,DebugMenu:yse,MenuPanel:bse,SharePanel:r?aoe:null,CursorChatBubble:r?cse:null,TopPanel:r?$ie:null,...n}),[n,r]),children:t})}function fi(){const e=P.useContext(uL);if(!e)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}function Uie({overrides:e,components:t,assetUrls:n,onUiEvent:r,forceMobile:s,children:o}){return d.jsx(Mq,{assetUrls:SJ(n),children:d.jsx(Oq,{overrides:PJ(e),children:d.jsx(LQ,{onEvent:r,children:d.jsx(dJ,{children:d.jsx($Q,{children:d.jsx(xJ,{forceMobile:s,children:d.jsx(Bie,{overrides:t,children:d.jsx(Hie,{overrides:e,children:o})})})})})})})})}function Hie({overrides:e,children:t}){const n=CJ(e);return d.jsx(dee,{overrides:n.actions,children:d.jsx(vJ,{overrides:n.tools,children:t})})}function Kie(){const e=F(),{addToast:t}=es();P.useEffect(()=>{function n({name:r,count:s}){t({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${s}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return e.addListener("max-shapes",n),()=>{e.removeListener("max-shapes",n)}},[e,t])}const Wie=Ce.memo(function({renderDebugMenuItems:t,children:n,hideUi:r,components:s,...o}){return d.jsx(Uie,{...o,components:s,children:d.jsx(Gie,{hideUi:r,renderDebugMenuItems:t,children:n})})}),Gie=Ce.memo(function({children:t,hideUi:n,...r}){return d.jsxs(d.Fragment,{children:[t,n?null:d.jsx(Vie,{...r})]})}),Vie=Ce.memo(function(){const t=F(),n=we(),r=In(),s=uo(),o=K("focus",()=>t.getInstanceState().isFocusMode,[t]),i=K("debug",()=>t.getInstanceState().isDebugMode,[t]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:h,HelpMenu:p,NavigationPanel:f,HelperButtons:S,DebugPanel:y,CursorChatBubble:x}=fi();Tie(),QJ(),Kie();const{"toggle-focus-mode":m}=ae();return d.jsxs("div",{className:ce("tlui-layout",{"tlui-layout__mobile":r<yt.TABLET_SM}),"data-breakpoint":r,children:[o?d.jsx("div",{className:"tlui-layout__top",children:d.jsx(ue,{type:"icon",className:"tlui-focus-button",title:n("focus-mode.toggle-focus-mode"),onClick:()=>m.onSelect("menu"),children:d.jsx(ve,{icon:"dot"})})}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"tlui-layout__top",children:[d.jsxs("div",{className:"tlui-layout__top__left",children:[c&&d.jsx(c,{}),S&&d.jsx(S,{})]}),d.jsx("div",{className:"tlui-layout__top__center",children:l&&d.jsx(l,{})}),d.jsxs("div",{className:"tlui-layout__top__right",children:[a&&d.jsx(a,{}),u&&r>=yt.TABLET_SM&&!s&&d.jsx(u,{})]})]}),d.jsxs("div",{className:"tlui-layout__bottom",children:[d.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&d.jsx(f,{}),h&&d.jsx(h,{}),p&&d.jsx(p,{})]}),i&&y&&d.jsx(y,{})]})]}),d.jsx(gJ,{}),d.jsx(zQ,{}),d.jsx(mJ,{}),d.jsx(BQ,{}),x&&d.jsx(x,{})]})});async function Yie(e,t){const{url:n,style:r="normal",weight:s="500",display:o,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=t,h={style:r,weight:s,display:o,featureSettings:i,stretch:a,unicodeRange:l,variant:c},p=new FontFace(e,`url(${n})`,h);return await p.load(),document.fonts.add(p),p.$$_url=n,p.$$_fontface=`
|
|
383
|
-
@font-face {
|
|
384
|
-
font-family: ${p.family};
|
|
385
|
-
font-stretch: ${p.stretch};
|
|
386
|
-
font-weight: ${p.weight};
|
|
387
|
-
font-style: ${p.style};
|
|
388
|
-
src: url("${n}") format("${u}")
|
|
389
|
-
}`,p}const bh=(e,t)=>{const[n,r]=P.useState(2);return P.useEffect(()=>{let s=!1;return r(2),Yie(e,t).then(()=>{s||r(0)}).catch(o=>{s||(console.error(o),r(1))}),()=>{s=!0}},[e,t]),n};function Xie(e){return{draw:{url:e.fonts.draw,format:e.fonts.draw.split(".").pop()},serif:{url:e.fonts.serif,format:e.fonts.serif.split(".").pop()},sansSerif:{url:e.fonts.sansSerif,format:e.fonts.sansSerif.split(".").pop()},monospace:{url:e.fonts.monospace,format:e.fonts.monospace.split(".").pop()}}}function dL(e){const t=P.useMemo(()=>Xie(e),[e]),n=[bh("tldraw_draw",t.draw),bh("tldraw_serif",t.serif),bh("tldraw_sans",t.sansSerif),bh("tldraw_mono",t.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function qie(e){const{children:t,maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:s,acceptedVideoMimeTypes:o,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:u=[],...h}=e,p=Xf(a),f=P.useMemo(()=>({Scribble:QC,ShapeIndicators:pY,CollaboratorScribble:QC,SelectionForeground:uY,SelectionBackground:lY,Handles:rY,...p}),[p]),S=zc(l),y=P.useMemo(()=>[...WA,...S],[S]),x=zc(c),m=P.useMemo(()=>[...dA,...x],[x]),v=zc(u),w=P.useMemo(()=>[...oZ,...pX,...v],[v]),C=iO(h.assetUrls),{done:E,error:_}=dL(C);return _?d.jsx(aA,{children:"Could not load assets. Please refresh the page."}):E?d.jsx(HV,{initialState:"select",...h,components:f,shapeUtils:y,bindingUtils:m,tools:w,children:d.jsxs(Wie,{...h,components:f,children:[d.jsx(Zie,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:s,acceptedVideoMimeTypes:o,onMount:i}),t]})}):d.jsx(aw,{children:d.jsx(i0,{})})}function Zie({maxImageDimension:e=5e3,maxAssetSize:t=10*1024*1024,acceptedImageMimeTypes:n=Bx,acceptedVideoMimeTypes:r=Kk,onMount:s}){const o=F(),i=es(),a=we();lA(()=>{const u=[];return u.push(Hq(o)),XY(o,{maxImageDimension:e,maxAssetSize:t,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),u.push(o.store.props.onEditorMount(o)),u.push(s==null?void 0:s(o)),()=>{u.forEach(h=>h==null?void 0:h())}});const{Canvas:l}=ot(),{ContextMenu:c}=fi();return c?d.jsx(c,{}):l?d.jsx(l,{}):null}P.memo(function(t){const[n,r]=P.useState(null),[s,o]=P.useState(null),i=zc(t.shapeUtils??[]),a=P.useMemo(()=>[...WA,...i],[i]),l=zc(t.bindingUtils??[]),c=P.useMemo(()=>[...dA,...l],[l]),u=XV({snapshot:t.snapshot,shapeUtils:a}),h=iO(),{done:p,error:f}=dL(h),{pageId:S,bounds:y,scale:x,background:m,padding:v,darkMode:w,preserveAspectRatio:C,format:E="svg",licenseKey:_}=t;return P.useLayoutEffect(()=>{if(!s||!u||!p)return;let I=!1;const k=document.createElement("div");s.appendChild(k),s.classList.add("tl-container","tl-theme__light");const T=new Z({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>k,licenseKey:_});S&&T.setCurrentPage(S);const M=T.getCurrentPageShapeIds();async function D(){const $=await T.getSvgString([...M],{bounds:y,scale:x,background:m,padding:v,darkMode:w,preserveAspectRatio:C});if($&&!I){if(E==="svg"){if(!I){const j=new Blob([$.svg],{type:"image/svg+xml"}),O=URL.createObjectURL(j);r(O)}}else if(E==="png"){const j=await gO(T,$.svg,{type:E,quality:1,scale:2,width:$.width,height:$.height});if(j&&!I){const O=URL.createObjectURL(j);r(O)}}}T.dispose()}return D(),()=>{I=!0}},[E,s,u,a,c,S,y,x,m,v,w,C,p,f,_]),f?d.jsx(aA,{children:"Could not load assets."}):p?d.jsx("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:n&&d.jsx("img",{src:n,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):d.jsx(aw,{children:d.jsx(i0,{})})});P.memo(function({children:t}){const n=we(),r=In(),s=t??d.jsx(jse,{});return r<yt.MOBILE?null:d.jsx("div",{className:"tlui-help-menu",children:d.jsxs(Zi,{id:"help menu",children:[d.jsx(Qi,{children:d.jsx(ue,{type:"help",title:n("help-menu.title"),"data-testid":"help-menu.button",children:d.jsx(ve,{icon:"question-mark",small:!0})})}),d.jsx(Ji,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(Mr,{type:"menu",sourceId:"help-menu",children:s})})]})})});const Qie=1,Jie=xe({schemaVersion:dn(1),storeVersion:Mh,recordVersions:Op(fe,xe({version:Mh,subTypeVersions:Op(fe,Mh).optional(),subTypeKey:fe.optional()}))}),eae=xe({schemaVersion:dn(2),sequences:Op(fe,Mh)}),tae=xe({tldrawFileFormatVersion:eU,schema:tU("schemaVersion",{1:Jie,2:eae}),records:Ht(xe({id:fe,typeName:fe}).allowUnknownProperties())});function nae(e){var t;try{return!!((t=e.document)!=null&&t.version)}catch{return!1}}function rae({json:e,schema:t}){let n;try{n=tae.validate(JSON.parse(e))}catch(s){try{if(n=JSON.parse(e),nae(n))return yn.err({type:"v1File",data:n})}catch{}return yn.err({type:"notATldrawFile",cause:s})}if(n.tldrawFileFormatVersion>Qie)return yn.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r;try{const s=sae(n.records),o=Object.fromEntries(s.map(i=>[i.id,i]));r=t.migrateStoreSnapshot({store:o,schema:n.schema})}catch(s){return yn.err({type:"invalidRecords",cause:s})}if(r.type==="error")return yn.err({type:"migrationFailed",reason:r.reason});try{return yn.ok(Iu({initialData:r.value,schema:t}))}catch(s){return yn.err({type:"invalidRecords",cause:s})}}function sae(e){const t=new Set;for(const n of e)n.typeName==="shape"&&"assetId"in n.props&&n.props.assetId&&t.add(n.props.assetId);return e.filter(n=>n.typeName!=="asset"||t.has(n.id))}function oae(){const[e,t]=P.useState();function n(r){window.editor=r,e===void 0?fetch("/tldr-data").then(async s=>{if(!s.ok){console.log(`No tldr data to load from local endpoint (${s.status})`);return}return s.text()}).then(s=>{if(s===void 0)return;const o=rae({json:s,schema:r.store.schema});o.ok?(console.log("Loaded tldr file from local endpoint"),t(o.value)):console.error(`Couldn't parse tldr file: ${String(o.error.type)}`)}).catch(s=>{console.error("Couldn't fetch data:",s)}):(r.zoomToFit(),r.clearOpenMenus())}return d.jsx("div",{style:{inset:0,position:"fixed"},children:d.jsx(qie,{assetUrls:U3(),onMount:n,store:e})})}Iv.createRoot(document.querySelector("#root")).render(d.jsx(Ce.StrictMode,{children:d.jsx(oae,{})}));
|