@kitschpatrol/tldraw-cli 5.0.1 → 5.0.2

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,44 +1,4 @@
1
- function IX(n,e){for(var t=0;t<e.length;t++){const r=e[t];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in n)){const s=Object.getOwnPropertyDescriptor(r,i);s&&Object.defineProperty(n,i,s.get?s:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function t(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=t(i);fetch(i.href,s)}})();var Rr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ja(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var eC={exports:{}},Jp={};/**
2
- * @license React
3
- * react-jsx-runtime.production.js
4
- *
5
- * Copyright (c) Meta Platforms, Inc. and 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 eR;function MX(){if(eR)return Jp;eR=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function t(r,i,s){var o=null;if(s!==void 0&&(o=""+s),i.key!==void 0&&(o=""+i.key),"key"in i){s={};for(var a in i)a!=="key"&&(s[a]=i[a])}else s=i;return i=s.ref,{$$typeof:n,type:r,key:o,ref:i!==void 0?i:null,props:s}}return Jp.Fragment=e,Jp.jsx=t,Jp.jsxs=t,Jp}var tR;function kX(){return tR||(tR=1,eC.exports=MX()),eC.exports}var m=kX(),tC={exports:{}},ut={};/**
10
- * @license React
11
- * react.production.js
12
- *
13
- * Copyright (c) Meta Platforms, Inc. and 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 nR;function AX(){if(nR)return ut;nR=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.portal"),t=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),s=Symbol.for("react.consumer"),o=Symbol.for("react.context"),a=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),u=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),h=Symbol.for("react.activity"),g=Symbol.iterator;function y(U){return U===null||typeof U!="object"?null:(U=g&&U[g]||U["@@iterator"],typeof U=="function"?U:null)}var b={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},v=Object.assign,w={};function x(U,re,le){this.props=U,this.context=re,this.refs=w,this.updater=le||b}x.prototype.isReactComponent={},x.prototype.setState=function(U,re){if(typeof U!="object"&&typeof U!="function"&&U!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,U,re,"setState")},x.prototype.forceUpdate=function(U){this.updater.enqueueForceUpdate(this,U,"forceUpdate")};function T(){}T.prototype=x.prototype;function P(U,re,le){this.props=U,this.context=re,this.refs=w,this.updater=le||b}var M=P.prototype=new T;M.constructor=P,v(M,x.prototype),M.isPureReactComponent=!0;var k=Array.isArray;function A(){}var O={H:null,A:null,T:null,S:null},R=Object.prototype.hasOwnProperty;function F(U,re,le){var Se=le.ref;return{$$typeof:n,type:U,key:re,ref:Se!==void 0?Se:null,props:le}}function z(U,re){return F(U.type,re,U.props)}function j(U){return typeof U=="object"&&U!==null&&U.$$typeof===n}function $(U){var re={"=":"=0",":":"=2"};return"$"+U.replace(/[=:]/g,function(le){return re[le]})}var H=/\/+/g;function B(U,re){return typeof U=="object"&&U!==null&&U.key!=null?$(""+U.key):re.toString(36)}function G(U){switch(U.status){case"fulfilled":return U.value;case"rejected":throw U.reason;default:switch(typeof U.status=="string"?U.then(A,A):(U.status="pending",U.then(function(re){U.status==="pending"&&(U.status="fulfilled",U.value=re)},function(re){U.status==="pending"&&(U.status="rejected",U.reason=re)})),U.status){case"fulfilled":return U.value;case"rejected":throw U.reason}}throw U}function N(U,re,le,Se,fe){var Me=typeof U;(Me==="undefined"||Me==="boolean")&&(U=null);var ve=!1;if(U===null)ve=!0;else switch(Me){case"bigint":case"string":case"number":ve=!0;break;case"object":switch(U.$$typeof){case n:case e:ve=!0;break;case f:return ve=U._init,N(ve(U._payload),re,le,Se,fe)}}if(ve)return fe=fe(U),ve=Se===""?"."+B(U,0):Se,k(fe)?(le="",ve!=null&&(le=ve.replace(H,"$&/")+"/"),N(fe,re,le,"",function(He){return He})):fe!=null&&(j(fe)&&(fe=z(fe,le+(fe.key==null||U&&U.key===fe.key?"":(""+fe.key).replace(H,"$&/")+"/")+ve)),re.push(fe)),1;ve=0;var _e=Se===""?".":Se+":";if(k(U))for(var Oe=0;Oe<U.length;Oe++)Se=U[Oe],Me=_e+B(Se,Oe),ve+=N(Se,re,le,Me,fe);else if(Oe=y(U),typeof Oe=="function")for(U=Oe.call(U),Oe=0;!(Se=U.next()).done;)Se=Se.value,Me=_e+B(Se,Oe++),ve+=N(Se,re,le,Me,fe);else if(Me==="object"){if(typeof U.then=="function")return N(G(U),re,le,Se,fe);throw re=String(U),Error("Objects are not valid as a React child (found: "+(re==="[object Object]"?"object with keys {"+Object.keys(U).join(", ")+"}":re)+"). If you meant to render a collection of children, use an array instead.")}return ve}function Y(U,re,le){if(U==null)return U;var Se=[],fe=0;return N(U,Se,"","",function(Me){return re.call(le,Me,fe++)}),Se}function W(U){if(U._status===-1){var re=U._result;re=re(),re.then(function(le){(U._status===0||U._status===-1)&&(U._status=1,U._result=le)},function(le){(U._status===0||U._status===-1)&&(U._status=2,U._result=le)}),U._status===-1&&(U._status=0,U._result=re)}if(U._status===1)return U._result.default;throw U._result}var Q=typeof reportError=="function"?reportError:function(U){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var re=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof U=="object"&&U!==null&&typeof U.message=="string"?String(U.message):String(U),error:U});if(!window.dispatchEvent(re))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",U);return}console.error(U)},de={map:Y,forEach:function(U,re,le){Y(U,function(){re.apply(this,arguments)},le)},count:function(U){var re=0;return Y(U,function(){re++}),re},toArray:function(U){return Y(U,function(re){return re})||[]},only:function(U){if(!j(U))throw Error("React.Children.only expected to receive a single React element child.");return U}};return ut.Activity=h,ut.Children=de,ut.Component=x,ut.Fragment=t,ut.Profiler=i,ut.PureComponent=P,ut.StrictMode=r,ut.Suspense=l,ut.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=O,ut.__COMPILER_RUNTIME={__proto__:null,c:function(U){return O.H.useMemoCache(U)}},ut.cache=function(U){return function(){return U.apply(null,arguments)}},ut.cacheSignal=function(){return null},ut.cloneElement=function(U,re,le){if(U==null)throw Error("The argument must be a React element, but you passed "+U+".");var Se=v({},U.props),fe=U.key;if(re!=null)for(Me in re.key!==void 0&&(fe=""+re.key),re)!R.call(re,Me)||Me==="key"||Me==="__self"||Me==="__source"||Me==="ref"&&re.ref===void 0||(Se[Me]=re[Me]);var Me=arguments.length-2;if(Me===1)Se.children=le;else if(1<Me){for(var ve=Array(Me),_e=0;_e<Me;_e++)ve[_e]=arguments[_e+2];Se.children=ve}return F(U.type,fe,Se)},ut.createContext=function(U){return U={$$typeof:o,_currentValue:U,_currentValue2:U,_threadCount:0,Provider:null,Consumer:null},U.Provider=U,U.Consumer={$$typeof:s,_context:U},U},ut.createElement=function(U,re,le){var Se,fe={},Me=null;if(re!=null)for(Se in re.key!==void 0&&(Me=""+re.key),re)R.call(re,Se)&&Se!=="key"&&Se!=="__self"&&Se!=="__source"&&(fe[Se]=re[Se]);var ve=arguments.length-2;if(ve===1)fe.children=le;else if(1<ve){for(var _e=Array(ve),Oe=0;Oe<ve;Oe++)_e[Oe]=arguments[Oe+2];fe.children=_e}if(U&&U.defaultProps)for(Se in ve=U.defaultProps,ve)fe[Se]===void 0&&(fe[Se]=ve[Se]);return F(U,Me,fe)},ut.createRef=function(){return{current:null}},ut.forwardRef=function(U){return{$$typeof:a,render:U}},ut.isValidElement=j,ut.lazy=function(U){return{$$typeof:f,_payload:{_status:-1,_result:U},_init:W}},ut.memo=function(U,re){return{$$typeof:u,type:U,compare:re===void 0?null:re}},ut.startTransition=function(U){var re=O.T,le={};O.T=le;try{var Se=U(),fe=O.S;fe!==null&&fe(le,Se),typeof Se=="object"&&Se!==null&&typeof Se.then=="function"&&Se.then(A,Q)}catch(Me){Q(Me)}finally{re!==null&&le.types!==null&&(re.types=le.types),O.T=re}},ut.unstable_useCacheRefresh=function(){return O.H.useCacheRefresh()},ut.use=function(U){return O.H.use(U)},ut.useActionState=function(U,re,le){return O.H.useActionState(U,re,le)},ut.useCallback=function(U,re){return O.H.useCallback(U,re)},ut.useContext=function(U){return O.H.useContext(U)},ut.useDebugValue=function(){},ut.useDeferredValue=function(U,re){return O.H.useDeferredValue(U,re)},ut.useEffect=function(U,re){return O.H.useEffect(U,re)},ut.useEffectEvent=function(U){return O.H.useEffectEvent(U)},ut.useId=function(){return O.H.useId()},ut.useImperativeHandle=function(U,re,le){return O.H.useImperativeHandle(U,re,le)},ut.useInsertionEffect=function(U,re){return O.H.useInsertionEffect(U,re)},ut.useLayoutEffect=function(U,re){return O.H.useLayoutEffect(U,re)},ut.useMemo=function(U,re){return O.H.useMemo(U,re)},ut.useOptimistic=function(U,re){return O.H.useOptimistic(U,re)},ut.useReducer=function(U,re,le){return O.H.useReducer(U,re,le)},ut.useRef=function(U){return O.H.useRef(U)},ut.useState=function(U){return O.H.useState(U)},ut.useSyncExternalStore=function(U,re,le){return O.H.useSyncExternalStore(U,re,le)},ut.useTransition=function(){return O.H.useTransition()},ut.version="19.2.0",ut}var rR;function pI(){return rR||(rR=1,tC.exports=AX()),tC.exports}var E=pI();const Ge=Ja(E),SB=IX({__proto__:null,default:Ge},[E]);var nC={exports:{}},Qp={},rC={exports:{}},iC={};/**
18
- * @license React
19
- * scheduler.production.js
20
- *
21
- * Copyright (c) Meta Platforms, Inc. and affiliates.
22
- *
23
- * This source code is licensed under the MIT license found in the
24
- * LICENSE file in the root directory of this source tree.
25
- */var iR;function OX(){return iR||(iR=1,(function(n){function e(N,Y){var W=N.length;N.push(Y);e:for(;0<W;){var Q=W-1>>>1,de=N[Q];if(0<i(de,Y))N[Q]=Y,N[W]=de,W=Q;else break e}}function t(N){return N.length===0?null:N[0]}function r(N){if(N.length===0)return null;var Y=N[0],W=N.pop();if(W!==Y){N[0]=W;e:for(var Q=0,de=N.length,U=de>>>1;Q<U;){var re=2*(Q+1)-1,le=N[re],Se=re+1,fe=N[Se];if(0>i(le,W))Se<de&&0>i(fe,le)?(N[Q]=fe,N[Se]=W,Q=Se):(N[Q]=le,N[re]=W,Q=re);else if(Se<de&&0>i(fe,W))N[Q]=fe,N[Se]=W,Q=Se;else break e}}return Y}function i(N,Y){var W=N.sortIndex-Y.sortIndex;return W!==0?W:N.id-Y.id}if(n.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var s=performance;n.unstable_now=function(){return s.now()}}else{var o=Date,a=o.now();n.unstable_now=function(){return o.now()-a}}var l=[],u=[],f=1,h=null,g=3,y=!1,b=!1,v=!1,w=!1,x=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,P=typeof setImmediate<"u"?setImmediate:null;function M(N){for(var Y=t(u);Y!==null;){if(Y.callback===null)r(u);else if(Y.startTime<=N)r(u),Y.sortIndex=Y.expirationTime,e(l,Y);else break;Y=t(u)}}function k(N){if(v=!1,M(N),!b)if(t(l)!==null)b=!0,A||(A=!0,$());else{var Y=t(u);Y!==null&&G(k,Y.startTime-N)}}var A=!1,O=-1,R=5,F=-1;function z(){return w?!0:!(n.unstable_now()-F<R)}function j(){if(w=!1,A){var N=n.unstable_now();F=N;var Y=!0;try{e:{b=!1,v&&(v=!1,T(O),O=-1),y=!0;var W=g;try{t:{for(M(N),h=t(l);h!==null&&!(h.expirationTime>N&&z());){var Q=h.callback;if(typeof Q=="function"){h.callback=null,g=h.priorityLevel;var de=Q(h.expirationTime<=N);if(N=n.unstable_now(),typeof de=="function"){h.callback=de,M(N),Y=!0;break t}h===t(l)&&r(l),M(N)}else r(l);h=t(l)}if(h!==null)Y=!0;else{var U=t(u);U!==null&&G(k,U.startTime-N),Y=!1}}break e}finally{h=null,g=W,y=!1}Y=void 0}}finally{Y?$():A=!1}}}var $;if(typeof P=="function")$=function(){P(j)};else if(typeof MessageChannel<"u"){var H=new MessageChannel,B=H.port2;H.port1.onmessage=j,$=function(){B.postMessage(null)}}else $=function(){x(j,0)};function G(N,Y){O=x(function(){N(n.unstable_now())},Y)}n.unstable_IdlePriority=5,n.unstable_ImmediatePriority=1,n.unstable_LowPriority=4,n.unstable_NormalPriority=3,n.unstable_Profiling=null,n.unstable_UserBlockingPriority=2,n.unstable_cancelCallback=function(N){N.callback=null},n.unstable_forceFrameRate=function(N){0>N||125<N?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):R=0<N?Math.floor(1e3/N):5},n.unstable_getCurrentPriorityLevel=function(){return g},n.unstable_next=function(N){switch(g){case 1:case 2:case 3:var Y=3;break;default:Y=g}var W=g;g=Y;try{return N()}finally{g=W}},n.unstable_requestPaint=function(){w=!0},n.unstable_runWithPriority=function(N,Y){switch(N){case 1:case 2:case 3:case 4:case 5:break;default:N=3}var W=g;g=N;try{return Y()}finally{g=W}},n.unstable_scheduleCallback=function(N,Y,W){var Q=n.unstable_now();switch(typeof W=="object"&&W!==null?(W=W.delay,W=typeof W=="number"&&0<W?Q+W:Q):W=Q,N){case 1:var de=-1;break;case 2:de=250;break;case 5:de=1073741823;break;case 4:de=1e4;break;default:de=5e3}return de=W+de,N={id:f++,callback:Y,priorityLevel:N,startTime:W,expirationTime:de,sortIndex:-1},W>Q?(N.sortIndex=W,e(u,N),t(l)===null&&N===t(u)&&(v?(T(O),O=-1):v=!0,G(k,W-Q))):(N.sortIndex=de,e(l,N),b||y||(b=!0,A||(A=!0,$()))),N},n.unstable_shouldYield=z,n.unstable_wrapCallback=function(N){var Y=g;return function(){var W=g;g=Y;try{return N.apply(this,arguments)}finally{g=W}}}})(iC)),iC}var sR;function DX(){return sR||(sR=1,rC.exports=OX()),rC.exports}var sC={exports:{}},mi={};/**
26
- * @license React
27
- * react-dom.production.js
28
- *
29
- * Copyright (c) Meta Platforms, Inc. and affiliates.
30
- *
31
- * This source code is licensed under the MIT license found in the
32
- * LICENSE file in the root directory of this source tree.
33
- */var oR;function RX(){if(oR)return mi;oR=1;var n=pI();function e(l){var u="https://react.dev/errors/"+l;if(1<arguments.length){u+="?args[]="+encodeURIComponent(arguments[1]);for(var f=2;f<arguments.length;f++)u+="&args[]="+encodeURIComponent(arguments[f])}return"Minified React error #"+l+"; visit "+u+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function t(){}var r={d:{f:t,r:function(){throw Error(e(522))},D:t,C:t,L:t,m:t,X:t,S:t,M:t},p:0,findDOMNode:null},i=Symbol.for("react.portal");function s(l,u,f){var h=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:i,key:h==null?null:""+h,children:l,containerInfo:u,implementation:f}}var o=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function a(l,u){if(l==="font")return"";if(typeof u=="string")return u==="use-credentials"?u:""}return mi.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=r,mi.createPortal=function(l,u){var f=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!u||u.nodeType!==1&&u.nodeType!==9&&u.nodeType!==11)throw Error(e(299));return s(l,u,null,f)},mi.flushSync=function(l){var u=o.T,f=r.p;try{if(o.T=null,r.p=2,l)return l()}finally{o.T=u,r.p=f,r.d.f()}},mi.preconnect=function(l,u){typeof l=="string"&&(u?(u=u.crossOrigin,u=typeof u=="string"?u==="use-credentials"?u:"":void 0):u=null,r.d.C(l,u))},mi.prefetchDNS=function(l){typeof l=="string"&&r.d.D(l)},mi.preinit=function(l,u){if(typeof l=="string"&&u&&typeof u.as=="string"){var f=u.as,h=a(f,u.crossOrigin),g=typeof u.integrity=="string"?u.integrity:void 0,y=typeof u.fetchPriority=="string"?u.fetchPriority:void 0;f==="style"?r.d.S(l,typeof u.precedence=="string"?u.precedence:void 0,{crossOrigin:h,integrity:g,fetchPriority:y}):f==="script"&&r.d.X(l,{crossOrigin:h,integrity:g,fetchPriority:y,nonce:typeof u.nonce=="string"?u.nonce:void 0})}},mi.preinitModule=function(l,u){if(typeof l=="string")if(typeof u=="object"&&u!==null){if(u.as==null||u.as==="script"){var f=a(u.as,u.crossOrigin);r.d.M(l,{crossOrigin:f,integrity:typeof u.integrity=="string"?u.integrity:void 0,nonce:typeof u.nonce=="string"?u.nonce:void 0})}}else u==null&&r.d.M(l)},mi.preload=function(l,u){if(typeof l=="string"&&typeof u=="object"&&u!==null&&typeof u.as=="string"){var f=u.as,h=a(f,u.crossOrigin);r.d.L(l,f,{crossOrigin:h,integrity:typeof u.integrity=="string"?u.integrity:void 0,nonce:typeof u.nonce=="string"?u.nonce:void 0,type:typeof u.type=="string"?u.type:void 0,fetchPriority:typeof u.fetchPriority=="string"?u.fetchPriority:void 0,referrerPolicy:typeof u.referrerPolicy=="string"?u.referrerPolicy:void 0,imageSrcSet:typeof u.imageSrcSet=="string"?u.imageSrcSet:void 0,imageSizes:typeof u.imageSizes=="string"?u.imageSizes:void 0,media:typeof u.media=="string"?u.media:void 0})}},mi.preloadModule=function(l,u){if(typeof l=="string")if(u){var f=a(u.as,u.crossOrigin);r.d.m(l,{as:typeof u.as=="string"&&u.as!=="script"?u.as:void 0,crossOrigin:f,integrity:typeof u.integrity=="string"?u.integrity:void 0})}else r.d.m(l)},mi.requestFormReset=function(l){r.d.r(l)},mi.unstable_batchedUpdates=function(l,u){return l(u)},mi.useFormState=function(l,u,f){return o.H.useFormState(l,u,f)},mi.useFormStatus=function(){return o.H.useHostTransitionStatus()},mi.version="19.2.0",mi}var aR;function bB(){if(aR)return sC.exports;aR=1;function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}return n(),sC.exports=RX(),sC.exports}/**
34
- * @license React
35
- * react-dom-client.production.js
36
- *
37
- * Copyright (c) Meta Platforms, Inc. and affiliates.
38
- *
39
- * This source code is licensed under the MIT license found in the
40
- * LICENSE file in the root directory of this source tree.
41
- */var lR;function jX(){if(lR)return Qp;lR=1;var n=DX(),e=pI(),t=bB();function r(c){var d="https://react.dev/errors/"+c;if(1<arguments.length){d+="?args[]="+encodeURIComponent(arguments[1]);for(var p=2;p<arguments.length;p++)d+="&args[]="+encodeURIComponent(arguments[p])}return"Minified React error #"+c+"; visit "+d+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function i(c){return!(!c||c.nodeType!==1&&c.nodeType!==9&&c.nodeType!==11)}function s(c){var d=c,p=c;if(c.alternate)for(;d.return;)d=d.return;else{c=d;do d=c,(d.flags&4098)!==0&&(p=d.return),c=d.return;while(c)}return d.tag===3?p:null}function o(c){if(c.tag===13){var d=c.memoizedState;if(d===null&&(c=c.alternate,c!==null&&(d=c.memoizedState)),d!==null)return d.dehydrated}return null}function a(c){if(c.tag===31){var d=c.memoizedState;if(d===null&&(c=c.alternate,c!==null&&(d=c.memoizedState)),d!==null)return d.dehydrated}return null}function l(c){if(s(c)!==c)throw Error(r(188))}function u(c){var d=c.alternate;if(!d){if(d=s(c),d===null)throw Error(r(188));return d!==c?null:c}for(var p=c,S=d;;){var C=p.return;if(C===null)break;var _=C.alternate;if(_===null){if(S=C.return,S!==null){p=S;continue}break}if(C.child===_.child){for(_=C.child;_;){if(_===p)return l(C),c;if(_===S)return l(C),d;_=_.sibling}throw Error(r(188))}if(p.return!==S.return)p=C,S=_;else{for(var D=!1,L=C.child;L;){if(L===p){D=!0,p=C,S=_;break}if(L===S){D=!0,S=C,p=_;break}L=L.sibling}if(!D){for(L=_.child;L;){if(L===p){D=!0,p=_,S=C;break}if(L===S){D=!0,S=_,p=C;break}L=L.sibling}if(!D)throw Error(r(189))}}if(p.alternate!==S)throw Error(r(190))}if(p.tag!==3)throw Error(r(188));return p.stateNode.current===p?c:d}function f(c){var d=c.tag;if(d===5||d===26||d===27||d===6)return c;for(c=c.child;c!==null;){if(d=f(c),d!==null)return d;c=c.sibling}return null}var h=Object.assign,g=Symbol.for("react.element"),y=Symbol.for("react.transitional.element"),b=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),w=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),P=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),k=Symbol.for("react.suspense"),A=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),F=Symbol.for("react.activity"),z=Symbol.for("react.memo_cache_sentinel"),j=Symbol.iterator;function $(c){return c===null||typeof c!="object"?null:(c=j&&c[j]||c["@@iterator"],typeof c=="function"?c:null)}var H=Symbol.for("react.client.reference");function B(c){if(c==null)return null;if(typeof c=="function")return c.$$typeof===H?null:c.displayName||c.name||null;if(typeof c=="string")return c;switch(c){case v:return"Fragment";case x:return"Profiler";case w:return"StrictMode";case k:return"Suspense";case A:return"SuspenseList";case F:return"Activity"}if(typeof c=="object")switch(c.$$typeof){case b:return"Portal";case P:return c.displayName||"Context";case T:return(c._context.displayName||"Context")+".Consumer";case M:var d=c.render;return c=c.displayName,c||(c=d.displayName||d.name||"",c=c!==""?"ForwardRef("+c+")":"ForwardRef"),c;case O:return d=c.displayName||null,d!==null?d:B(c.type)||"Memo";case R:d=c._payload,c=c._init;try{return B(c(d))}catch{}}return null}var G=Array.isArray,N=e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=t.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W={pending:!1,data:null,method:null,action:null},Q=[],de=-1;function U(c){return{current:c}}function re(c){0>de||(c.current=Q[de],Q[de]=null,de--)}function le(c,d){de++,Q[de]=c.current,c.current=d}var Se=U(null),fe=U(null),Me=U(null),ve=U(null);function _e(c,d){switch(le(Me,d),le(fe,c),le(Se,null),d.nodeType){case 9:case 11:c=(c=d.documentElement)&&(c=c.namespaceURI)?CD(c):0;break;default:if(c=d.tagName,d=d.namespaceURI)d=CD(d),c=TD(d,c);else switch(c){case"svg":c=1;break;case"math":c=2;break;default:c=0}}re(Se),le(Se,c)}function Oe(){re(Se),re(fe),re(Me)}function He(c){c.memoizedState!==null&&le(ve,c);var d=Se.current,p=TD(d,c.type);d!==p&&(le(fe,c),le(Se,p))}function Bt(c){fe.current===c&&(re(Se),re(fe)),ve.current===c&&(re(ve),Yp._currentValue=W)}var qt,At;function _t(c){if(qt===void 0)try{throw Error()}catch(p){var d=p.stack.trim().match(/\n( *(at )?)/);qt=d&&d[1]||"",At=-1<p.stack.indexOf(`
1
+ function IX(n,e){for(var t=0;t<e.length;t++){const r=e[t];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in n)){const s=Object.getOwnPropertyDescriptor(r,i);s&&Object.defineProperty(n,i,s.get?s:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function t(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=t(i);fetch(i.href,s)}})();var Rr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ja(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var eC={exports:{}},Jp={};var eR;function MX(){if(eR)return Jp;eR=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function t(r,i,s){var o=null;if(s!==void 0&&(o=""+s),i.key!==void 0&&(o=""+i.key),"key"in i){s={};for(var a in i)a!=="key"&&(s[a]=i[a])}else s=i;return i=s.ref,{$$typeof:n,type:r,key:o,ref:i!==void 0?i:null,props:s}}return Jp.Fragment=e,Jp.jsx=t,Jp.jsxs=t,Jp}var tR;function kX(){return tR||(tR=1,eC.exports=MX()),eC.exports}var m=kX(),tC={exports:{}},ut={};var nR;function AX(){if(nR)return ut;nR=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.portal"),t=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),s=Symbol.for("react.consumer"),o=Symbol.for("react.context"),a=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),u=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),h=Symbol.for("react.activity"),g=Symbol.iterator;function y(U){return U===null||typeof U!="object"?null:(U=g&&U[g]||U["@@iterator"],typeof U=="function"?U:null)}var b={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},v=Object.assign,w={};function x(U,re,le){this.props=U,this.context=re,this.refs=w,this.updater=le||b}x.prototype.isReactComponent={},x.prototype.setState=function(U,re){if(typeof U!="object"&&typeof U!="function"&&U!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,U,re,"setState")},x.prototype.forceUpdate=function(U){this.updater.enqueueForceUpdate(this,U,"forceUpdate")};function T(){}T.prototype=x.prototype;function P(U,re,le){this.props=U,this.context=re,this.refs=w,this.updater=le||b}var M=P.prototype=new T;M.constructor=P,v(M,x.prototype),M.isPureReactComponent=!0;var k=Array.isArray;function A(){}var O={H:null,A:null,T:null,S:null},R=Object.prototype.hasOwnProperty;function F(U,re,le){var Se=le.ref;return{$$typeof:n,type:U,key:re,ref:Se!==void 0?Se:null,props:le}}function z(U,re){return F(U.type,re,U.props)}function j(U){return typeof U=="object"&&U!==null&&U.$$typeof===n}function $(U){var re={"=":"=0",":":"=2"};return"$"+U.replace(/[=:]/g,function(le){return re[le]})}var H=/\/+/g;function B(U,re){return typeof U=="object"&&U!==null&&U.key!=null?$(""+U.key):re.toString(36)}function G(U){switch(U.status){case"fulfilled":return U.value;case"rejected":throw U.reason;default:switch(typeof U.status=="string"?U.then(A,A):(U.status="pending",U.then(function(re){U.status==="pending"&&(U.status="fulfilled",U.value=re)},function(re){U.status==="pending"&&(U.status="rejected",U.reason=re)})),U.status){case"fulfilled":return U.value;case"rejected":throw U.reason}}throw U}function N(U,re,le,Se,fe){var Me=typeof U;(Me==="undefined"||Me==="boolean")&&(U=null);var ve=!1;if(U===null)ve=!0;else switch(Me){case"bigint":case"string":case"number":ve=!0;break;case"object":switch(U.$$typeof){case n:case e:ve=!0;break;case f:return ve=U._init,N(ve(U._payload),re,le,Se,fe)}}if(ve)return fe=fe(U),ve=Se===""?"."+B(U,0):Se,k(fe)?(le="",ve!=null&&(le=ve.replace(H,"$&/")+"/"),N(fe,re,le,"",function(He){return He})):fe!=null&&(j(fe)&&(fe=z(fe,le+(fe.key==null||U&&U.key===fe.key?"":(""+fe.key).replace(H,"$&/")+"/")+ve)),re.push(fe)),1;ve=0;var _e=Se===""?".":Se+":";if(k(U))for(var Oe=0;Oe<U.length;Oe++)Se=U[Oe],Me=_e+B(Se,Oe),ve+=N(Se,re,le,Me,fe);else if(Oe=y(U),typeof Oe=="function")for(U=Oe.call(U),Oe=0;!(Se=U.next()).done;)Se=Se.value,Me=_e+B(Se,Oe++),ve+=N(Se,re,le,Me,fe);else if(Me==="object"){if(typeof U.then=="function")return N(G(U),re,le,Se,fe);throw re=String(U),Error("Objects are not valid as a React child (found: "+(re==="[object Object]"?"object with keys {"+Object.keys(U).join(", ")+"}":re)+"). If you meant to render a collection of children, use an array instead.")}return ve}function Y(U,re,le){if(U==null)return U;var Se=[],fe=0;return N(U,Se,"","",function(Me){return re.call(le,Me,fe++)}),Se}function W(U){if(U._status===-1){var re=U._result;re=re(),re.then(function(le){(U._status===0||U._status===-1)&&(U._status=1,U._result=le)},function(le){(U._status===0||U._status===-1)&&(U._status=2,U._result=le)}),U._status===-1&&(U._status=0,U._result=re)}if(U._status===1)return U._result.default;throw U._result}var Q=typeof reportError=="function"?reportError:function(U){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var re=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof U=="object"&&U!==null&&typeof U.message=="string"?String(U.message):String(U),error:U});if(!window.dispatchEvent(re))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",U);return}console.error(U)},de={map:Y,forEach:function(U,re,le){Y(U,function(){re.apply(this,arguments)},le)},count:function(U){var re=0;return Y(U,function(){re++}),re},toArray:function(U){return Y(U,function(re){return re})||[]},only:function(U){if(!j(U))throw Error("React.Children.only expected to receive a single React element child.");return U}};return ut.Activity=h,ut.Children=de,ut.Component=x,ut.Fragment=t,ut.Profiler=i,ut.PureComponent=P,ut.StrictMode=r,ut.Suspense=l,ut.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=O,ut.__COMPILER_RUNTIME={__proto__:null,c:function(U){return O.H.useMemoCache(U)}},ut.cache=function(U){return function(){return U.apply(null,arguments)}},ut.cacheSignal=function(){return null},ut.cloneElement=function(U,re,le){if(U==null)throw Error("The argument must be a React element, but you passed "+U+".");var Se=v({},U.props),fe=U.key;if(re!=null)for(Me in re.key!==void 0&&(fe=""+re.key),re)!R.call(re,Me)||Me==="key"||Me==="__self"||Me==="__source"||Me==="ref"&&re.ref===void 0||(Se[Me]=re[Me]);var Me=arguments.length-2;if(Me===1)Se.children=le;else if(1<Me){for(var ve=Array(Me),_e=0;_e<Me;_e++)ve[_e]=arguments[_e+2];Se.children=ve}return F(U.type,fe,Se)},ut.createContext=function(U){return U={$$typeof:o,_currentValue:U,_currentValue2:U,_threadCount:0,Provider:null,Consumer:null},U.Provider=U,U.Consumer={$$typeof:s,_context:U},U},ut.createElement=function(U,re,le){var Se,fe={},Me=null;if(re!=null)for(Se in re.key!==void 0&&(Me=""+re.key),re)R.call(re,Se)&&Se!=="key"&&Se!=="__self"&&Se!=="__source"&&(fe[Se]=re[Se]);var ve=arguments.length-2;if(ve===1)fe.children=le;else if(1<ve){for(var _e=Array(ve),Oe=0;Oe<ve;Oe++)_e[Oe]=arguments[Oe+2];fe.children=_e}if(U&&U.defaultProps)for(Se in ve=U.defaultProps,ve)fe[Se]===void 0&&(fe[Se]=ve[Se]);return F(U,Me,fe)},ut.createRef=function(){return{current:null}},ut.forwardRef=function(U){return{$$typeof:a,render:U}},ut.isValidElement=j,ut.lazy=function(U){return{$$typeof:f,_payload:{_status:-1,_result:U},_init:W}},ut.memo=function(U,re){return{$$typeof:u,type:U,compare:re===void 0?null:re}},ut.startTransition=function(U){var re=O.T,le={};O.T=le;try{var Se=U(),fe=O.S;fe!==null&&fe(le,Se),typeof Se=="object"&&Se!==null&&typeof Se.then=="function"&&Se.then(A,Q)}catch(Me){Q(Me)}finally{re!==null&&le.types!==null&&(re.types=le.types),O.T=re}},ut.unstable_useCacheRefresh=function(){return O.H.useCacheRefresh()},ut.use=function(U){return O.H.use(U)},ut.useActionState=function(U,re,le){return O.H.useActionState(U,re,le)},ut.useCallback=function(U,re){return O.H.useCallback(U,re)},ut.useContext=function(U){return O.H.useContext(U)},ut.useDebugValue=function(){},ut.useDeferredValue=function(U,re){return O.H.useDeferredValue(U,re)},ut.useEffect=function(U,re){return O.H.useEffect(U,re)},ut.useEffectEvent=function(U){return O.H.useEffectEvent(U)},ut.useId=function(){return O.H.useId()},ut.useImperativeHandle=function(U,re,le){return O.H.useImperativeHandle(U,re,le)},ut.useInsertionEffect=function(U,re){return O.H.useInsertionEffect(U,re)},ut.useLayoutEffect=function(U,re){return O.H.useLayoutEffect(U,re)},ut.useMemo=function(U,re){return O.H.useMemo(U,re)},ut.useOptimistic=function(U,re){return O.H.useOptimistic(U,re)},ut.useReducer=function(U,re,le){return O.H.useReducer(U,re,le)},ut.useRef=function(U){return O.H.useRef(U)},ut.useState=function(U){return O.H.useState(U)},ut.useSyncExternalStore=function(U,re,le){return O.H.useSyncExternalStore(U,re,le)},ut.useTransition=function(){return O.H.useTransition()},ut.version="19.2.0",ut}var rR;function pI(){return rR||(rR=1,tC.exports=AX()),tC.exports}var E=pI();const Ge=Ja(E),SB=IX({__proto__:null,default:Ge},[E]);var nC={exports:{}},Qp={},rC={exports:{}},iC={};var iR;function OX(){return iR||(iR=1,(function(n){function e(N,Y){var W=N.length;N.push(Y);e:for(;0<W;){var Q=W-1>>>1,de=N[Q];if(0<i(de,Y))N[Q]=Y,N[W]=de,W=Q;else break e}}function t(N){return N.length===0?null:N[0]}function r(N){if(N.length===0)return null;var Y=N[0],W=N.pop();if(W!==Y){N[0]=W;e:for(var Q=0,de=N.length,U=de>>>1;Q<U;){var re=2*(Q+1)-1,le=N[re],Se=re+1,fe=N[Se];if(0>i(le,W))Se<de&&0>i(fe,le)?(N[Q]=fe,N[Se]=W,Q=Se):(N[Q]=le,N[re]=W,Q=re);else if(Se<de&&0>i(fe,W))N[Q]=fe,N[Se]=W,Q=Se;else break e}}return Y}function i(N,Y){var W=N.sortIndex-Y.sortIndex;return W!==0?W:N.id-Y.id}if(n.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var s=performance;n.unstable_now=function(){return s.now()}}else{var o=Date,a=o.now();n.unstable_now=function(){return o.now()-a}}var l=[],u=[],f=1,h=null,g=3,y=!1,b=!1,v=!1,w=!1,x=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,P=typeof setImmediate<"u"?setImmediate:null;function M(N){for(var Y=t(u);Y!==null;){if(Y.callback===null)r(u);else if(Y.startTime<=N)r(u),Y.sortIndex=Y.expirationTime,e(l,Y);else break;Y=t(u)}}function k(N){if(v=!1,M(N),!b)if(t(l)!==null)b=!0,A||(A=!0,$());else{var Y=t(u);Y!==null&&G(k,Y.startTime-N)}}var A=!1,O=-1,R=5,F=-1;function z(){return w?!0:!(n.unstable_now()-F<R)}function j(){if(w=!1,A){var N=n.unstable_now();F=N;var Y=!0;try{e:{b=!1,v&&(v=!1,T(O),O=-1),y=!0;var W=g;try{t:{for(M(N),h=t(l);h!==null&&!(h.expirationTime>N&&z());){var Q=h.callback;if(typeof Q=="function"){h.callback=null,g=h.priorityLevel;var de=Q(h.expirationTime<=N);if(N=n.unstable_now(),typeof de=="function"){h.callback=de,M(N),Y=!0;break t}h===t(l)&&r(l),M(N)}else r(l);h=t(l)}if(h!==null)Y=!0;else{var U=t(u);U!==null&&G(k,U.startTime-N),Y=!1}}break e}finally{h=null,g=W,y=!1}Y=void 0}}finally{Y?$():A=!1}}}var $;if(typeof P=="function")$=function(){P(j)};else if(typeof MessageChannel<"u"){var H=new MessageChannel,B=H.port2;H.port1.onmessage=j,$=function(){B.postMessage(null)}}else $=function(){x(j,0)};function G(N,Y){O=x(function(){N(n.unstable_now())},Y)}n.unstable_IdlePriority=5,n.unstable_ImmediatePriority=1,n.unstable_LowPriority=4,n.unstable_NormalPriority=3,n.unstable_Profiling=null,n.unstable_UserBlockingPriority=2,n.unstable_cancelCallback=function(N){N.callback=null},n.unstable_forceFrameRate=function(N){0>N||125<N?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):R=0<N?Math.floor(1e3/N):5},n.unstable_getCurrentPriorityLevel=function(){return g},n.unstable_next=function(N){switch(g){case 1:case 2:case 3:var Y=3;break;default:Y=g}var W=g;g=Y;try{return N()}finally{g=W}},n.unstable_requestPaint=function(){w=!0},n.unstable_runWithPriority=function(N,Y){switch(N){case 1:case 2:case 3:case 4:case 5:break;default:N=3}var W=g;g=N;try{return Y()}finally{g=W}},n.unstable_scheduleCallback=function(N,Y,W){var Q=n.unstable_now();switch(typeof W=="object"&&W!==null?(W=W.delay,W=typeof W=="number"&&0<W?Q+W:Q):W=Q,N){case 1:var de=-1;break;case 2:de=250;break;case 5:de=1073741823;break;case 4:de=1e4;break;default:de=5e3}return de=W+de,N={id:f++,callback:Y,priorityLevel:N,startTime:W,expirationTime:de,sortIndex:-1},W>Q?(N.sortIndex=W,e(u,N),t(l)===null&&N===t(u)&&(v?(T(O),O=-1):v=!0,G(k,W-Q))):(N.sortIndex=de,e(l,N),b||y||(b=!0,A||(A=!0,$()))),N},n.unstable_shouldYield=z,n.unstable_wrapCallback=function(N){var Y=g;return function(){var W=g;g=Y;try{return N.apply(this,arguments)}finally{g=W}}}})(iC)),iC}var sR;function DX(){return sR||(sR=1,rC.exports=OX()),rC.exports}var sC={exports:{}},mi={};var oR;function RX(){if(oR)return mi;oR=1;var n=pI();function e(l){var u="https://react.dev/errors/"+l;if(1<arguments.length){u+="?args[]="+encodeURIComponent(arguments[1]);for(var f=2;f<arguments.length;f++)u+="&args[]="+encodeURIComponent(arguments[f])}return"Minified React error #"+l+"; visit "+u+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function t(){}var r={d:{f:t,r:function(){throw Error(e(522))},D:t,C:t,L:t,m:t,X:t,S:t,M:t},p:0,findDOMNode:null},i=Symbol.for("react.portal");function s(l,u,f){var h=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:i,key:h==null?null:""+h,children:l,containerInfo:u,implementation:f}}var o=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function a(l,u){if(l==="font")return"";if(typeof u=="string")return u==="use-credentials"?u:""}return mi.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=r,mi.createPortal=function(l,u){var f=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!u||u.nodeType!==1&&u.nodeType!==9&&u.nodeType!==11)throw Error(e(299));return s(l,u,null,f)},mi.flushSync=function(l){var u=o.T,f=r.p;try{if(o.T=null,r.p=2,l)return l()}finally{o.T=u,r.p=f,r.d.f()}},mi.preconnect=function(l,u){typeof l=="string"&&(u?(u=u.crossOrigin,u=typeof u=="string"?u==="use-credentials"?u:"":void 0):u=null,r.d.C(l,u))},mi.prefetchDNS=function(l){typeof l=="string"&&r.d.D(l)},mi.preinit=function(l,u){if(typeof l=="string"&&u&&typeof u.as=="string"){var f=u.as,h=a(f,u.crossOrigin),g=typeof u.integrity=="string"?u.integrity:void 0,y=typeof u.fetchPriority=="string"?u.fetchPriority:void 0;f==="style"?r.d.S(l,typeof u.precedence=="string"?u.precedence:void 0,{crossOrigin:h,integrity:g,fetchPriority:y}):f==="script"&&r.d.X(l,{crossOrigin:h,integrity:g,fetchPriority:y,nonce:typeof u.nonce=="string"?u.nonce:void 0})}},mi.preinitModule=function(l,u){if(typeof l=="string")if(typeof u=="object"&&u!==null){if(u.as==null||u.as==="script"){var f=a(u.as,u.crossOrigin);r.d.M(l,{crossOrigin:f,integrity:typeof u.integrity=="string"?u.integrity:void 0,nonce:typeof u.nonce=="string"?u.nonce:void 0})}}else u==null&&r.d.M(l)},mi.preload=function(l,u){if(typeof l=="string"&&typeof u=="object"&&u!==null&&typeof u.as=="string"){var f=u.as,h=a(f,u.crossOrigin);r.d.L(l,f,{crossOrigin:h,integrity:typeof u.integrity=="string"?u.integrity:void 0,nonce:typeof u.nonce=="string"?u.nonce:void 0,type:typeof u.type=="string"?u.type:void 0,fetchPriority:typeof u.fetchPriority=="string"?u.fetchPriority:void 0,referrerPolicy:typeof u.referrerPolicy=="string"?u.referrerPolicy:void 0,imageSrcSet:typeof u.imageSrcSet=="string"?u.imageSrcSet:void 0,imageSizes:typeof u.imageSizes=="string"?u.imageSizes:void 0,media:typeof u.media=="string"?u.media:void 0})}},mi.preloadModule=function(l,u){if(typeof l=="string")if(u){var f=a(u.as,u.crossOrigin);r.d.m(l,{as:typeof u.as=="string"&&u.as!=="script"?u.as:void 0,crossOrigin:f,integrity:typeof u.integrity=="string"?u.integrity:void 0})}else r.d.m(l)},mi.requestFormReset=function(l){r.d.r(l)},mi.unstable_batchedUpdates=function(l,u){return l(u)},mi.useFormState=function(l,u,f){return o.H.useFormState(l,u,f)},mi.useFormStatus=function(){return o.H.useHostTransitionStatus()},mi.version="19.2.0",mi}var aR;function bB(){if(aR)return sC.exports;aR=1;function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}return n(),sC.exports=RX(),sC.exports}var lR;function jX(){if(lR)return Qp;lR=1;var n=DX(),e=pI(),t=bB();function r(c){var d="https://react.dev/errors/"+c;if(1<arguments.length){d+="?args[]="+encodeURIComponent(arguments[1]);for(var p=2;p<arguments.length;p++)d+="&args[]="+encodeURIComponent(arguments[p])}return"Minified React error #"+c+"; visit "+d+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function i(c){return!(!c||c.nodeType!==1&&c.nodeType!==9&&c.nodeType!==11)}function s(c){var d=c,p=c;if(c.alternate)for(;d.return;)d=d.return;else{c=d;do d=c,(d.flags&4098)!==0&&(p=d.return),c=d.return;while(c)}return d.tag===3?p:null}function o(c){if(c.tag===13){var d=c.memoizedState;if(d===null&&(c=c.alternate,c!==null&&(d=c.memoizedState)),d!==null)return d.dehydrated}return null}function a(c){if(c.tag===31){var d=c.memoizedState;if(d===null&&(c=c.alternate,c!==null&&(d=c.memoizedState)),d!==null)return d.dehydrated}return null}function l(c){if(s(c)!==c)throw Error(r(188))}function u(c){var d=c.alternate;if(!d){if(d=s(c),d===null)throw Error(r(188));return d!==c?null:c}for(var p=c,S=d;;){var C=p.return;if(C===null)break;var _=C.alternate;if(_===null){if(S=C.return,S!==null){p=S;continue}break}if(C.child===_.child){for(_=C.child;_;){if(_===p)return l(C),c;if(_===S)return l(C),d;_=_.sibling}throw Error(r(188))}if(p.return!==S.return)p=C,S=_;else{for(var D=!1,L=C.child;L;){if(L===p){D=!0,p=C,S=_;break}if(L===S){D=!0,S=C,p=_;break}L=L.sibling}if(!D){for(L=_.child;L;){if(L===p){D=!0,p=_,S=C;break}if(L===S){D=!0,S=_,p=C;break}L=L.sibling}if(!D)throw Error(r(189))}}if(p.alternate!==S)throw Error(r(190))}if(p.tag!==3)throw Error(r(188));return p.stateNode.current===p?c:d}function f(c){var d=c.tag;if(d===5||d===26||d===27||d===6)return c;for(c=c.child;c!==null;){if(d=f(c),d!==null)return d;c=c.sibling}return null}var h=Object.assign,g=Symbol.for("react.element"),y=Symbol.for("react.transitional.element"),b=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),w=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),P=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),k=Symbol.for("react.suspense"),A=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),F=Symbol.for("react.activity"),z=Symbol.for("react.memo_cache_sentinel"),j=Symbol.iterator;function $(c){return c===null||typeof c!="object"?null:(c=j&&c[j]||c["@@iterator"],typeof c=="function"?c:null)}var H=Symbol.for("react.client.reference");function B(c){if(c==null)return null;if(typeof c=="function")return c.$$typeof===H?null:c.displayName||c.name||null;if(typeof c=="string")return c;switch(c){case v:return"Fragment";case x:return"Profiler";case w:return"StrictMode";case k:return"Suspense";case A:return"SuspenseList";case F:return"Activity"}if(typeof c=="object")switch(c.$$typeof){case b:return"Portal";case P:return c.displayName||"Context";case T:return(c._context.displayName||"Context")+".Consumer";case M:var d=c.render;return c=c.displayName,c||(c=d.displayName||d.name||"",c=c!==""?"ForwardRef("+c+")":"ForwardRef"),c;case O:return d=c.displayName||null,d!==null?d:B(c.type)||"Memo";case R:d=c._payload,c=c._init;try{return B(c(d))}catch{}}return null}var G=Array.isArray,N=e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=t.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W={pending:!1,data:null,method:null,action:null},Q=[],de=-1;function U(c){return{current:c}}function re(c){0>de||(c.current=Q[de],Q[de]=null,de--)}function le(c,d){de++,Q[de]=c.current,c.current=d}var Se=U(null),fe=U(null),Me=U(null),ve=U(null);function _e(c,d){switch(le(Me,d),le(fe,c),le(Se,null),d.nodeType){case 9:case 11:c=(c=d.documentElement)&&(c=c.namespaceURI)?CD(c):0;break;default:if(c=d.tagName,d=d.namespaceURI)d=CD(d),c=TD(d,c);else switch(c){case"svg":c=1;break;case"math":c=2;break;default:c=0}}re(Se),le(Se,c)}function Oe(){re(Se),re(fe),re(Me)}function He(c){c.memoizedState!==null&&le(ve,c);var d=Se.current,p=TD(d,c.type);d!==p&&(le(fe,c),le(Se,p))}function Bt(c){fe.current===c&&(re(Se),re(fe)),ve.current===c&&(re(ve),Yp._currentValue=W)}var qt,At;function _t(c){if(qt===void 0)try{throw Error()}catch(p){var d=p.stack.trim().match(/\n( *(at )?)/);qt=d&&d[1]||"",At=-1<p.stack.indexOf(`
42
2
  at`)?" (<anonymous>)":-1<p.stack.indexOf("@")?"@unknown:0:0":""}return`
43
3
  `+qt+c+At}var $t=!1;function Gn(c,d){if(!c||$t)return"";$t=!0;var p=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var S={DetermineComponentFrameRoot:function(){try{if(d){var ye=function(){throw Error()};if(Object.defineProperty(ye.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ye,[])}catch(ue){var ae=ue}Reflect.construct(c,[],ye)}else{try{ye.call()}catch(ue){ae=ue}c.call(ye.prototype)}}else{try{throw Error()}catch(ue){ae=ue}(ye=c())&&typeof ye.catch=="function"&&ye.catch(function(){})}}catch(ue){if(ue&&ae&&typeof ue.stack=="string")return[ue.stack,ae.stack]}return[null,null]}};S.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var C=Object.getOwnPropertyDescriptor(S.DetermineComponentFrameRoot,"name");C&&C.configurable&&Object.defineProperty(S.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var _=S.DetermineComponentFrameRoot(),D=_[0],L=_[1];if(D&&L){var V=D.split(`
44
4
  `),oe=L.split(`
@@ -50,33 +10,7 @@ Error generating stack: `+S.message+`
50
10
  `)),n.didWarn=!0;return}const s=new Map;for(const a of e)aC(s,a.name,{version:a.version,modules:[]}).modules.push(a.modules);const o=new Map;for(const[a,l]of s)l.modules.length>1&&o.set(a,l);if(o.size>0){const a=[`${Al("[tldraw]",["bold","bgRed","textWhite"])} ${Al("You have multiple instances of some tldraw libraries active. This can lead to bugs and unexpected behavior. ",["textRed","bold"])}`,"","This usually means that your bundler is misconfigured, and is importing the same library multiple times - usually once as an ES Module, and once as a CommonJS module.","","The following libraries have been imported multiple times:",...Array.from(o,([l,u])=>{const f=u.modules.map((h,g)=>h==="esm"?` ${g+1}. ES Modules`:` ${g+1}. CommonJS`).join(`
51
11
  `);return` • ❌ ${Al(l,["bold"])} v${u.version}:
52
12
  ${f}`}),"","You should configure your bundler to only import one version of each library."];console.log(a.join(`
53
- `)),n.didWarn=!0;return}}function dR(n,e){const t=n.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/),r=e.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/);return!t||!r?n.localeCompare(e):t[1]!==r[1]?Number(t[1])-Number(r[1]):t[2]!==r[2]?Number(t[2])-Number(r[2]):t[3]!==r[3]?Number(t[3])-Number(r[3]):t[4]&&r[4]?t[4].localeCompare(r[4]):t[4]?1:r[4]?-1:0}const FX={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function Al(n,e=[]){return`\x1B[${e.map(t=>FX[t]).join(";")}m${n}\x1B[m`}function aC(n,e,t){return n.has(e)?n.get(e):(n.set(e,t),t)}var Sg={exports:{}};Sg.exports;var hR;function UX(){return hR||(hR=1,(function(n,e){var t=200,r="__lodash_hash_undefined__",i=1,s=2,o=9007199254740991,a="[object Arguments]",l="[object Array]",u="[object AsyncFunction]",f="[object Boolean]",h="[object Date]",g="[object Error]",y="[object Function]",b="[object GeneratorFunction]",v="[object Map]",w="[object Number]",x="[object Null]",T="[object Object]",P="[object Promise]",M="[object Proxy]",k="[object RegExp]",A="[object Set]",O="[object String]",R="[object Symbol]",F="[object Undefined]",z="[object WeakMap]",j="[object ArrayBuffer]",$="[object DataView]",H="[object Float32Array]",B="[object Float64Array]",G="[object Int8Array]",N="[object Int16Array]",Y="[object Int32Array]",W="[object Uint8Array]",Q="[object Uint8ClampedArray]",de="[object Uint16Array]",U="[object Uint32Array]",re=/[\\^$.*+?()[\]{}|]/g,le=/^\[object .+?Constructor\]$/,Se=/^(?:0|[1-9]\d*)$/,fe={};fe[H]=fe[B]=fe[G]=fe[N]=fe[Y]=fe[W]=fe[Q]=fe[de]=fe[U]=!0,fe[a]=fe[l]=fe[j]=fe[f]=fe[$]=fe[h]=fe[g]=fe[y]=fe[v]=fe[w]=fe[T]=fe[k]=fe[A]=fe[O]=fe[z]=!1;var Me=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,ve=typeof self=="object"&&self&&self.Object===Object&&self,_e=Me||ve||Function("return this")(),Oe=e&&!e.nodeType&&e,He=Oe&&!0&&n&&!n.nodeType&&n,Bt=He&&He.exports===Oe,qt=Bt&&Me.process,At=(function(){try{return qt&&qt.binding&&qt.binding("util")}catch{}})(),_t=At&&At.isTypedArray;function $t(K,J){for(var be=-1,ke=K==null?0:K.length,jt=0,ot=[];++be<ke;){var en=K[be];J(en,be,K)&&(ot[jt++]=en)}return ot}function Gn(K,J){for(var be=-1,ke=J.length,jt=K.length;++be<ke;)K[jt+be]=J[be];return K}function yr(K,J){for(var be=-1,ke=K==null?0:K.length;++be<ke;)if(J(K[be],be,K))return!0;return!1}function Er(K,J){for(var be=-1,ke=Array(K);++be<K;)ke[be]=J(be);return ke}function Hr(K){return function(J){return K(J)}}function li(K,J){return K.has(J)}function ci(K,J){return K?.[J]}function ol(K){var J=-1,be=Array(K.size);return K.forEach(function(ke,jt){be[++J]=[jt,ke]}),be}function ic(K,J){return function(be){return K(J(be))}}function ar(K){var J=-1,be=Array(K.size);return K.forEach(function(ke){be[++J]=ke}),be}var Ni=Array.prototype,go=Function.prototype,Wo=Object.prototype,ls=_e["__core-js_shared__"],al=go.toString,ce=Wo.hasOwnProperty,Ie=(function(){var K=/[^.]+$/.exec(ls&&ls.keys&&ls.keys.IE_PROTO||"");return K?"Symbol(src)_1."+K:""})(),Xe=Wo.toString,Ot=RegExp("^"+al.call(ce).replace(re,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Gt=Bt?_e.Buffer:void 0,pn=_e.Symbol,kn=_e.Uint8Array,zi=Wo.propertyIsEnumerable,$r=Ni.splice,cs=pn?pn.toStringTag:void 0,ui=Object.getOwnPropertySymbols,us=Gt?Gt.isBuffer:void 0,Xo=ic(Object.keys,Object),Rs=fi(_e,"DataView"),js=fi(_e,"Map"),Ls=fi(_e,"Promise"),Ns=fi(_e,"Set"),sc=fi(_e,"WeakMap"),Zo=fi(Object,"create"),ll=ze(Rs),dp=ze(js),Jd=ze(Ls),ds=ze(Ns),Qd=ze(sc),oc=pn?pn.prototype:void 0,cl=oc?oc.valueOf:void 0;function mo(K){var J=-1,be=K==null?0:K.length;for(this.clear();++J<be;){var ke=K[J];this.set(ke[0],ke[1])}}function eh(){this.__data__=Zo?Zo(null):{},this.size=0}function _r(K){var J=this.has(K)&&delete this.__data__[K];return this.size-=J?1:0,J}function Yn(K){var J=this.__data__;if(Zo){var be=J[K];return be===r?void 0:be}return ce.call(J,K)?J[K]:void 0}function Pr(K){var J=this.__data__;return Zo?J[K]!==void 0:ce.call(J,K)}function xa(K,J){var be=this.__data__;return this.size+=this.has(K)?0:1,be[K]=Zo&&J===void 0?r:J,this}mo.prototype.clear=eh,mo.prototype.delete=_r,mo.prototype.get=Yn,mo.prototype.has=Pr,mo.prototype.set=xa;function Bi(K){var J=-1,be=K==null?0:K.length;for(this.clear();++J<be;){var ke=K[J];this.set(ke[0],ke[1])}}function hp(){this.__data__=[],this.size=0}function ac(K){var J=this.__data__,be=Ln(J,K);if(be<0)return!1;var ke=J.length-1;return be==ke?J.pop():$r.call(J,be,1),--this.size,!0}function th(K){var J=this.__data__,be=Ln(J,K);return be<0?void 0:J[be][1]}function ul(K){return Ln(this.__data__,K)>-1}function hs(K,J){var be=this.__data__,ke=Ln(be,K);return ke<0?(++this.size,be.push([K,J])):be[ke][1]=J,this}Bi.prototype.clear=hp,Bi.prototype.delete=ac,Bi.prototype.get=th,Bi.prototype.has=ul,Bi.prototype.set=hs;function di(K){var J=-1,be=K==null?0:K.length;for(this.clear();++J<be;){var ke=K[J];this.set(ke[0],ke[1])}}function va(){this.size=0,this.__data__={hash:new mo,map:new(js||Bi),string:new mo}}function dl(K){var J=pl(this,K).delete(K);return this.size-=J?1:0,J}function wa(K){return pl(this,K).get(K)}function jn(K){return pl(this,K).has(K)}function nh(K,J){var be=pl(this,K),ke=be.size;return be.set(K,J),this.size+=be.size==ke?0:1,this}di.prototype.clear=va,di.prototype.delete=dl,di.prototype.get=wa,di.prototype.has=jn,di.prototype.set=nh;function yo(K){var J=-1,be=K==null?0:K.length;for(this.__data__=new di;++J<be;)this.add(K[J])}function Jo(K){return this.__data__.set(K,r),this}function Qo(K){return this.__data__.has(K)}yo.prototype.add=yo.prototype.push=Jo,yo.prototype.has=Qo;function So(K){var J=this.__data__=new Bi(K);this.size=J.size}function rh(){this.__data__=new Bi,this.size=0}function ih(K){var J=this.__data__,be=J.delete(K);return this.size=J.size,be}function fp(K){return this.__data__.get(K)}function hl(K){return this.__data__.has(K)}function lc(K,J){var be=this.__data__;if(be instanceof Bi){var ke=be.__data__;if(!js||ke.length<t-1)return ke.push([K,J]),this.size=++be.size,this;be=this.__data__=new di(ke)}return be.set(K,J),this.size=be.size,this}So.prototype.clear=rh,So.prototype.delete=ih,So.prototype.get=fp,So.prototype.has=hl,So.prototype.set=lc;function zs(K,J){var be=an(K),ke=!be&&rt(K),jt=!be&&!ke&&vn(K),ot=!be&&!ke&&!jt&&Tn(K),en=be||ke||jt||ot,lr=en?Er(K.length,String):[],Xn=lr.length;for(var ln in K)ce.call(K,ln)&&!(en&&(ln=="length"||jt&&(ln=="offset"||ln=="parent")||ot&&(ln=="buffer"||ln=="byteLength"||ln=="byteOffset")||Bu(ln,Xn)))&&lr.push(ln);return lr}function Ln(K,J){for(var be=K.length;be--;)if(Qt(K[be][0],J))return be;return-1}function ea(K,J,be){var ke=J(K);return an(K)?ke:Gn(ke,be(K))}function hi(K){return K==null?K===void 0?F:x:cs&&cs in Object(K)?sh(K):Ce(K)}function cc(K){return Cn(K)&&hi(K)==a}function Lu(K,J,be,ke,jt){return K===J?!0:K==null||J==null||!Cn(K)&&!Cn(J)?K!==K&&J!==J:uc(K,J,be,ke,Lu,jt)}function uc(K,J,be,ke,jt,ot){var en=an(K),lr=an(J),Xn=en?l:Fi(K),ln=lr?l:Fi(J);Xn=Xn==a?T:Xn,ln=ln==a?T:ln;var xr=Xn==T,gi=ln==T,vr=Xn==ln;if(vr&&vn(K)){if(!vn(J))return!1;en=!0,xr=!1}if(vr&&!xr)return ot||(ot=new So),en||Tn(K)?Nu(K,J,be,ke,jt,ot):fl(K,J,Xn,be,ke,jt,ot);if(!(be&i)){var ps=xr&&ce.call(K,"__wrapped__"),gs=gi&&ce.call(J,"__wrapped__");if(ps||gs){var Ca=ps?K.value():K,Bs=gs?J.value():J;return ot||(ot=new So),jt(Ca,Bs,be,ke,ot)}}return vr?(ot||(ot=new So),ta(K,J,be,ke,jt,ot)):!1}function pp(K){if(!zn(K)||q(K))return!1;var J=Wn(K)?Ot:le;return J.test(ze(K))}function Nn(K){return Cn(K)&&wn(K.length)&&!!fe[hi(K)]}function dc(K){if(!ie(K))return Xo(K);var J=[];for(var be in Object(K))ce.call(K,be)&&be!="constructor"&&J.push(be);return J}function Nu(K,J,be,ke,jt,ot){var en=be&i,lr=K.length,Xn=J.length;if(lr!=Xn&&!(en&&Xn>lr))return!1;var ln=ot.get(K);if(ln&&ot.get(J))return ln==J;var xr=-1,gi=!0,vr=be&s?new yo:void 0;for(ot.set(K,J),ot.set(J,K);++xr<lr;){var ps=K[xr],gs=J[xr];if(ke)var Ca=en?ke(gs,ps,xr,J,K,ot):ke(ps,gs,xr,K,J,ot);if(Ca!==void 0){if(Ca)continue;gi=!1;break}if(vr){if(!yr(J,function(Bs,gl){if(!li(vr,gl)&&(ps===Bs||jt(ps,Bs,be,ke,ot)))return vr.push(gl)})){gi=!1;break}}else if(!(ps===gs||jt(ps,gs,be,ke,ot))){gi=!1;break}}return ot.delete(K),ot.delete(J),gi}function fl(K,J,be,ke,jt,ot,en){switch(be){case $:if(K.byteLength!=J.byteLength||K.byteOffset!=J.byteOffset)return!1;K=K.buffer,J=J.buffer;case j:return!(K.byteLength!=J.byteLength||!ot(new kn(K),new kn(J)));case f:case h:case w:return Qt(+K,+J);case g:return K.name==J.name&&K.message==J.message;case k:case O:return K==J+"";case v:var lr=ol;case A:var Xn=ke&i;if(lr||(lr=ar),K.size!=J.size&&!Xn)return!1;var ln=en.get(K);if(ln)return ln==J;ke|=s,en.set(K,J);var xr=Nu(lr(K),lr(J),ke,jt,ot,en);return en.delete(K),xr;case R:if(cl)return cl.call(K)==cl.call(J)}return!1}function ta(K,J,be,ke,jt,ot){var en=be&i,lr=zu(K),Xn=lr.length,ln=zu(J),xr=ln.length;if(Xn!=xr&&!en)return!1;for(var gi=Xn;gi--;){var vr=lr[gi];if(!(en?vr in J:ce.call(J,vr)))return!1}var ps=ot.get(K);if(ps&&ot.get(J))return ps==J;var gs=!0;ot.set(K,J),ot.set(J,K);for(var Ca=en;++gi<Xn;){vr=lr[gi];var Bs=K[vr],gl=J[vr];if(ke)var Py=en?ke(gl,Bs,vr,J,K,ot):ke(Bs,gl,vr,K,J,ot);if(!(Py===void 0?Bs===gl||jt(Bs,gl,be,ke,ot):Py)){gs=!1;break}Ca||(Ca=vr=="constructor")}if(gs&&!Ca){var ah=K.constructor,lh=J.constructor;ah!=lh&&"constructor"in K&&"constructor"in J&&!(typeof ah=="function"&&ah instanceof ah&&typeof lh=="function"&&lh instanceof lh)&&(gs=!1)}return ot.delete(K),ot.delete(J),gs}function zu(K){return ea(K,fs,hc)}function pl(K,J){var be=K.__data__;return oh(J)?be[typeof J=="string"?"string":"hash"]:be.map}function fi(K,J){var be=ci(K,J);return pp(be)?be:void 0}function sh(K){var J=ce.call(K,cs),be=K[cs];try{K[cs]=void 0;var ke=!0}catch{}var jt=Xe.call(K);return ke&&(J?K[cs]=be:delete K[cs]),jt}var hc=ui?function(K){return K==null?[]:(K=Object(K),$t(ui(K),function(J){return zi.call(K,J)}))}:pi,Fi=hi;(Rs&&Fi(new Rs(new ArrayBuffer(1)))!=$||js&&Fi(new js)!=v||Ls&&Fi(Ls.resolve())!=P||Ns&&Fi(new Ns)!=A||sc&&Fi(new sc)!=z)&&(Fi=function(K){var J=hi(K),be=J==T?K.constructor:void 0,ke=be?ze(be):"";if(ke)switch(ke){case ll:return $;case dp:return v;case Jd:return P;case ds:return A;case Qd:return z}return J});function Bu(K,J){return J=J??o,!!J&&(typeof K=="number"||Se.test(K))&&K>-1&&K%1==0&&K<J}function oh(K){var J=typeof K;return J=="string"||J=="number"||J=="symbol"||J=="boolean"?K!=="__proto__":K===null}function q(K){return!!Ie&&Ie in K}function ie(K){var J=K&&K.constructor,be=typeof J=="function"&&J.prototype||Wo;return K===be}function Ce(K){return Xe.call(K)}function ze(K){if(K!=null){try{return al.call(K)}catch{}try{return K+""}catch{}}return""}function Qt(K,J){return K===J||K!==K&&J!==J}var rt=cc((function(){return arguments})())?cc:function(K){return Cn(K)&&ce.call(K,"callee")&&!zi.call(K,"callee")},an=Array.isArray;function Sr(K){return K!=null&&wn(K.length)&&!Wn(K)}var vn=us||bo;function br(K,J){return Lu(K,J)}function Wn(K){if(!zn(K))return!1;var J=hi(K);return J==y||J==b||J==u||J==M}function wn(K){return typeof K=="number"&&K>-1&&K%1==0&&K<=o}function zn(K){var J=typeof K;return K!=null&&(J=="object"||J=="function")}function Cn(K){return K!=null&&typeof K=="object"}var Tn=_t?Hr(_t):Nn;function fs(K){return Sr(K)?zs(K):dc(K)}function pi(){return[]}function bo(){return!1}n.exports=br})(Sg,Sg.exports)),Sg.exports}var HX=UX();const vu=Ja(HX);var bg={exports:{}};bg.exports;var fR;function $X(){return fR||(fR=1,(function(n,e){var t=200,r="__lodash_hash_undefined__",i=1,s=2,o=9007199254740991,a="[object Arguments]",l="[object Array]",u="[object Boolean]",f="[object Date]",h="[object Error]",g="[object Function]",y="[object GeneratorFunction]",b="[object Map]",v="[object Number]",w="[object Object]",x="[object Promise]",T="[object RegExp]",P="[object Set]",M="[object String]",k="[object Symbol]",A="[object WeakMap]",O="[object ArrayBuffer]",R="[object DataView]",F="[object Float32Array]",z="[object Float64Array]",j="[object Int8Array]",$="[object Int16Array]",H="[object Int32Array]",B="[object Uint8Array]",G="[object Uint8ClampedArray]",N="[object Uint16Array]",Y="[object Uint32Array]",W=/[\\^$.*+?()[\]{}|]/g,Q=/^\[object .+?Constructor\]$/,de=/^(?:0|[1-9]\d*)$/,U={};U[F]=U[z]=U[j]=U[$]=U[H]=U[B]=U[G]=U[N]=U[Y]=!0,U[a]=U[l]=U[O]=U[u]=U[R]=U[f]=U[h]=U[g]=U[b]=U[v]=U[w]=U[T]=U[P]=U[M]=U[A]=!1;var re=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,le=typeof self=="object"&&self&&self.Object===Object&&self,Se=re||le||Function("return this")(),fe=e&&!e.nodeType&&e,Me=fe&&!0&&n&&!n.nodeType&&n,ve=Me&&Me.exports===fe,_e=ve&&re.process,Oe=(function(){try{return _e&&_e.binding("util")}catch{}})(),He=Oe&&Oe.isTypedArray;function Bt(q,ie){for(var Ce=-1,ze=q?q.length:0;++Ce<ze;)if(ie(q[Ce],Ce,q))return!0;return!1}function qt(q,ie){for(var Ce=-1,ze=Array(q);++Ce<q;)ze[Ce]=ie(Ce);return ze}function At(q){return function(ie){return q(ie)}}function _t(q,ie){return q?.[ie]}function $t(q){var ie=!1;if(q!=null&&typeof q.toString!="function")try{ie=!!(q+"")}catch{}return ie}function Gn(q){var ie=-1,Ce=Array(q.size);return q.forEach(function(ze,Qt){Ce[++ie]=[Qt,ze]}),Ce}function yr(q,ie){return function(Ce){return q(ie(Ce))}}function Er(q){var ie=-1,Ce=Array(q.size);return q.forEach(function(ze){Ce[++ie]=ze}),Ce}var Hr=Array.prototype,li=Function.prototype,ci=Object.prototype,ol=Se["__core-js_shared__"],ic=(function(){var q=/[^.]+$/.exec(ol&&ol.keys&&ol.keys.IE_PROTO||"");return q?"Symbol(src)_1."+q:""})(),ar=li.toString,Ni=ci.hasOwnProperty,go=ci.toString,Wo=RegExp("^"+ar.call(Ni).replace(W,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ls=Se.Symbol,al=Se.Uint8Array,ce=ci.propertyIsEnumerable,Ie=Hr.splice,Xe=yr(Object.keys,Object),Ot=ea(Se,"DataView"),Gt=ea(Se,"Map"),pn=ea(Se,"Promise"),kn=ea(Se,"Set"),zi=ea(Se,"WeakMap"),$r=ea(Object,"create"),cs=Nn(Ot),ui=Nn(Gt),us=Nn(pn),Xo=Nn(kn),Rs=Nn(zi),js=ls?ls.prototype:void 0,Ls=js?js.valueOf:void 0;function Ns(q){var ie=-1,Ce=q?q.length:0;for(this.clear();++ie<Ce;){var ze=q[ie];this.set(ze[0],ze[1])}}function sc(){this.__data__=$r?$r(null):{}}function Zo(q){return this.has(q)&&delete this.__data__[q]}function ll(q){var ie=this.__data__;if($r){var Ce=ie[q];return Ce===r?void 0:Ce}return Ni.call(ie,q)?ie[q]:void 0}function dp(q){var ie=this.__data__;return $r?ie[q]!==void 0:Ni.call(ie,q)}function Jd(q,ie){var Ce=this.__data__;return Ce[q]=$r&&ie===void 0?r:ie,this}Ns.prototype.clear=sc,Ns.prototype.delete=Zo,Ns.prototype.get=ll,Ns.prototype.has=dp,Ns.prototype.set=Jd;function ds(q){var ie=-1,Ce=q?q.length:0;for(this.clear();++ie<Ce;){var ze=q[ie];this.set(ze[0],ze[1])}}function Qd(){this.__data__=[]}function oc(q){var ie=this.__data__,Ce=yo(ie,q);if(Ce<0)return!1;var ze=ie.length-1;return Ce==ze?ie.pop():Ie.call(ie,Ce,1),!0}function cl(q){var ie=this.__data__,Ce=yo(ie,q);return Ce<0?void 0:ie[Ce][1]}function mo(q){return yo(this.__data__,q)>-1}function eh(q,ie){var Ce=this.__data__,ze=yo(Ce,q);return ze<0?Ce.push([q,ie]):Ce[ze][1]=ie,this}ds.prototype.clear=Qd,ds.prototype.delete=oc,ds.prototype.get=cl,ds.prototype.has=mo,ds.prototype.set=eh;function _r(q){var ie=-1,Ce=q?q.length:0;for(this.clear();++ie<Ce;){var ze=q[ie];this.set(ze[0],ze[1])}}function Yn(){this.__data__={hash:new Ns,map:new(Gt||ds),string:new Ns}}function Pr(q){return Ln(this,q).delete(q)}function xa(q){return Ln(this,q).get(q)}function Bi(q){return Ln(this,q).has(q)}function hp(q,ie){return Ln(this,q).set(q,ie),this}_r.prototype.clear=Yn,_r.prototype.delete=Pr,_r.prototype.get=xa,_r.prototype.has=Bi,_r.prototype.set=hp;function ac(q){var ie=-1,Ce=q?q.length:0;for(this.__data__=new _r;++ie<Ce;)this.add(q[ie])}function th(q){return this.__data__.set(q,r),this}function ul(q){return this.__data__.has(q)}ac.prototype.add=ac.prototype.push=th,ac.prototype.has=ul;function hs(q){this.__data__=new ds(q)}function di(){this.__data__=new ds}function va(q){return this.__data__.delete(q)}function dl(q){return this.__data__.get(q)}function wa(q){return this.__data__.has(q)}function jn(q,ie){var Ce=this.__data__;if(Ce instanceof ds){var ze=Ce.__data__;if(!Gt||ze.length<t-1)return ze.push([q,ie]),this;Ce=this.__data__=new _r(ze)}return Ce.set(q,ie),this}hs.prototype.clear=di,hs.prototype.delete=va,hs.prototype.get=dl,hs.prototype.has=wa,hs.prototype.set=jn;function nh(q,ie){var Ce=fl(q)||Nu(q)?qt(q.length,String):[],ze=Ce.length,Qt=!!ze;for(var rt in q)Ni.call(q,rt)&&!(Qt&&(rt=="length"||cc(rt,ze)))&&Ce.push(rt);return Ce}function yo(q,ie){for(var Ce=q.length;Ce--;)if(dc(q[Ce][0],ie))return Ce;return-1}function Jo(q){return go.call(q)}function Qo(q,ie,Ce,ze,Qt){return q===ie?!0:q==null||ie==null||!hc(q)&&!Fi(ie)?q!==q&&ie!==ie:So(q,ie,Qo,Ce,ze,Qt)}function So(q,ie,Ce,ze,Qt,rt){var an=fl(q),Sr=fl(ie),vn=l,br=l;an||(vn=hi(q),vn=vn==a?w:vn),Sr||(br=hi(ie),br=br==a?w:br);var Wn=vn==w&&!$t(q),wn=br==w&&!$t(ie),zn=vn==br;if(zn&&!Wn)return rt||(rt=new hs),an||Bu(q)?hl(q,ie,Ce,ze,Qt,rt):lc(q,ie,vn,Ce,ze,Qt,rt);if(!(Qt&s)){var Cn=Wn&&Ni.call(q,"__wrapped__"),Tn=wn&&Ni.call(ie,"__wrapped__");if(Cn||Tn){var fs=Cn?q.value():q,pi=Tn?ie.value():ie;return rt||(rt=new hs),Ce(fs,pi,ze,Qt,rt)}}return zn?(rt||(rt=new hs),zs(q,ie,Ce,ze,Qt,rt)):!1}function rh(q){if(!hc(q)||uc(q))return!1;var ie=fi(q)||$t(q)?Wo:Q;return ie.test(Nn(q))}function ih(q){return Fi(q)&&sh(q.length)&&!!U[go.call(q)]}function fp(q){if(!pp(q))return Xe(q);var ie=[];for(var Ce in Object(q))Ni.call(q,Ce)&&Ce!="constructor"&&ie.push(Ce);return ie}function hl(q,ie,Ce,ze,Qt,rt){var an=Qt&s,Sr=q.length,vn=ie.length;if(Sr!=vn&&!(an&&vn>Sr))return!1;var br=rt.get(q);if(br&&rt.get(ie))return br==ie;var Wn=-1,wn=!0,zn=Qt&i?new ac:void 0;for(rt.set(q,ie),rt.set(ie,q);++Wn<Sr;){var Cn=q[Wn],Tn=ie[Wn];if(ze)var fs=an?ze(Tn,Cn,Wn,ie,q,rt):ze(Cn,Tn,Wn,q,ie,rt);if(fs!==void 0){if(fs)continue;wn=!1;break}if(zn){if(!Bt(ie,function(pi,bo){if(!zn.has(bo)&&(Cn===pi||Ce(Cn,pi,ze,Qt,rt)))return zn.add(bo)})){wn=!1;break}}else if(!(Cn===Tn||Ce(Cn,Tn,ze,Qt,rt))){wn=!1;break}}return rt.delete(q),rt.delete(ie),wn}function lc(q,ie,Ce,ze,Qt,rt,an){switch(Ce){case R:if(q.byteLength!=ie.byteLength||q.byteOffset!=ie.byteOffset)return!1;q=q.buffer,ie=ie.buffer;case O:return!(q.byteLength!=ie.byteLength||!ze(new al(q),new al(ie)));case u:case f:case v:return dc(+q,+ie);case h:return q.name==ie.name&&q.message==ie.message;case T:case M:return q==ie+"";case b:var Sr=Gn;case P:var vn=rt&s;if(Sr||(Sr=Er),q.size!=ie.size&&!vn)return!1;var br=an.get(q);if(br)return br==ie;rt|=i,an.set(q,ie);var Wn=hl(Sr(q),Sr(ie),ze,Qt,rt,an);return an.delete(q),Wn;case k:if(Ls)return Ls.call(q)==Ls.call(ie)}return!1}function zs(q,ie,Ce,ze,Qt,rt){var an=Qt&s,Sr=oh(q),vn=Sr.length,br=oh(ie),Wn=br.length;if(vn!=Wn&&!an)return!1;for(var wn=vn;wn--;){var zn=Sr[wn];if(!(an?zn in ie:Ni.call(ie,zn)))return!1}var Cn=rt.get(q);if(Cn&&rt.get(ie))return Cn==ie;var Tn=!0;rt.set(q,ie),rt.set(ie,q);for(var fs=an;++wn<vn;){zn=Sr[wn];var pi=q[zn],bo=ie[zn];if(ze)var K=an?ze(bo,pi,zn,ie,q,rt):ze(pi,bo,zn,q,ie,rt);if(!(K===void 0?pi===bo||Ce(pi,bo,ze,Qt,rt):K)){Tn=!1;break}fs||(fs=zn=="constructor")}if(Tn&&!fs){var J=q.constructor,be=ie.constructor;J!=be&&"constructor"in q&&"constructor"in ie&&!(typeof J=="function"&&J instanceof J&&typeof be=="function"&&be instanceof be)&&(Tn=!1)}return rt.delete(q),rt.delete(ie),Tn}function Ln(q,ie){var Ce=q.__data__;return Lu(ie)?Ce[typeof ie=="string"?"string":"hash"]:Ce.map}function ea(q,ie){var Ce=_t(q,ie);return rh(Ce)?Ce:void 0}var hi=Jo;(Ot&&hi(new Ot(new ArrayBuffer(1)))!=R||Gt&&hi(new Gt)!=b||pn&&hi(pn.resolve())!=x||kn&&hi(new kn)!=P||zi&&hi(new zi)!=A)&&(hi=function(q){var ie=go.call(q),Ce=ie==w?q.constructor:void 0,ze=Ce?Nn(Ce):void 0;if(ze)switch(ze){case cs:return R;case ui:return b;case us:return x;case Xo:return P;case Rs:return A}return ie});function cc(q,ie){return ie=ie??o,!!ie&&(typeof q=="number"||de.test(q))&&q>-1&&q%1==0&&q<ie}function Lu(q){var ie=typeof q;return ie=="string"||ie=="number"||ie=="symbol"||ie=="boolean"?q!=="__proto__":q===null}function uc(q){return!!ic&&ic in q}function pp(q){var ie=q&&q.constructor,Ce=typeof ie=="function"&&ie.prototype||ci;return q===Ce}function Nn(q){if(q!=null){try{return ar.call(q)}catch{}try{return q+""}catch{}}return""}function dc(q,ie){return q===ie||q!==q&&ie!==ie}function Nu(q){return zu(q)&&Ni.call(q,"callee")&&(!ce.call(q,"callee")||go.call(q)==a)}var fl=Array.isArray;function ta(q){return q!=null&&sh(q.length)&&!fi(q)}function zu(q){return Fi(q)&&ta(q)}function pl(q,ie,Ce){Ce=typeof Ce=="function"?Ce:void 0;var ze=Ce?Ce(q,ie):void 0;return ze===void 0?Qo(q,ie,Ce):!!ze}function fi(q){var ie=hc(q)?go.call(q):"";return ie==g||ie==y}function sh(q){return typeof q=="number"&&q>-1&&q%1==0&&q<=o}function hc(q){var ie=typeof q;return!!q&&(ie=="object"||ie=="function")}function Fi(q){return!!q&&typeof q=="object"}var Bu=He?At(He):ih;function oh(q){return ta(q)?nh(q):fp(q)}n.exports=pl})(bg,bg.exports)),bg.exports}var KX=$X();const qX=Ja(KX);var lC,pR;function VX(){if(pR)return lC;pR=1;var n="Expected a function",e=NaN,t="[object Symbol]",r=/^\s+|\s+$/g,i=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,o=/^0o[0-7]+$/i,a=parseInt,l=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,u=typeof self=="object"&&self&&self.Object===Object&&self,f=l||u||Function("return this")(),h=Object.prototype,g=h.toString,y=Math.max,b=Math.min,v=function(){return f.Date.now()};function w(A,O,R){var F,z,j,$,H,B,G=0,N=!1,Y=!1,W=!0;if(typeof A!="function")throw new TypeError(n);O=k(O)||0,T(R)&&(N=!!R.leading,Y="maxWait"in R,j=Y?y(k(R.maxWait)||0,O):j,W="trailing"in R?!!R.trailing:W);function Q(_e){var Oe=F,He=z;return F=z=void 0,G=_e,$=A.apply(He,Oe),$}function de(_e){return G=_e,H=setTimeout(le,O),N?Q(_e):$}function U(_e){var Oe=_e-B,He=_e-G,Bt=O-Oe;return Y?b(Bt,j-He):Bt}function re(_e){var Oe=_e-B,He=_e-G;return B===void 0||Oe>=O||Oe<0||Y&&He>=j}function le(){var _e=v();if(re(_e))return Se(_e);H=setTimeout(le,U(_e))}function Se(_e){return H=void 0,W&&F?Q(_e):(F=z=void 0,$)}function fe(){H!==void 0&&clearTimeout(H),G=0,F=B=z=H=void 0}function Me(){return H===void 0?$:Se(v())}function ve(){var _e=v(),Oe=re(_e);if(F=arguments,z=this,B=_e,Oe){if(H===void 0)return de(B);if(Y)return H=setTimeout(le,O),Q(B)}return H===void 0&&(H=setTimeout(le,O)),$}return ve.cancel=fe,ve.flush=Me,ve}function x(A,O,R){var F=!0,z=!0;if(typeof A!="function")throw new TypeError(n);return T(R)&&(F="leading"in R?!!R.leading:F,z="trailing"in R?!!R.trailing:z),w(A,O,{leading:F,maxWait:O,trailing:z})}function T(A){var O=typeof A;return!!A&&(O=="object"||O=="function")}function P(A){return!!A&&typeof A=="object"}function M(A){return typeof A=="symbol"||P(A)&&g.call(A)==t}function k(A){if(typeof A=="number")return A;if(M(A))return e;if(T(A)){var O=typeof A.valueOf=="function"?A.valueOf():A;A=T(O)?O+"":O}if(typeof A!="string")return A===0?A:+A;A=A.replace(r,"");var R=s.test(A);return R||o.test(A)?a(A.slice(2),R?2:8):i.test(A)?e:+A}return lC=x,lC}var GX=VX();const vB=Ja(GX);var cC,gR;function YX(){if(gR)return cC;gR=1;var n=200,e="__lodash_hash_undefined__",t=1/0,r="[object Function]",i="[object GeneratorFunction]",s=/[\\^$.*+?()[\]{}|]/g,o=/^\[object .+?Constructor\]$/,a=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,l=typeof self=="object"&&self&&self.Object===Object&&self,u=a||l||Function("return this")();function f(ce,Ie){var Xe=ce?ce.length:0;return!!Xe&&g(ce,Ie,0)>-1}function h(ce,Ie,Xe,Ot){for(var Gt=ce.length,pn=Xe+-1;++pn<Gt;)if(Ie(ce[pn],pn,ce))return pn;return-1}function g(ce,Ie,Xe){if(Ie!==Ie)return h(ce,y,Xe);for(var Ot=Xe-1,Gt=ce.length;++Ot<Gt;)if(ce[Ot]===Ie)return Ot;return-1}function y(ce){return ce!==ce}function b(ce,Ie){return ce.has(Ie)}function v(ce,Ie){return ce?.[Ie]}function w(ce){var Ie=!1;if(ce!=null&&typeof ce.toString!="function")try{Ie=!!(ce+"")}catch{}return Ie}function x(ce){var Ie=-1,Xe=Array(ce.size);return ce.forEach(function(Ot){Xe[++Ie]=Ot}),Xe}var T=Array.prototype,P=Function.prototype,M=Object.prototype,k=u["__core-js_shared__"],A=(function(){var ce=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||"");return ce?"Symbol(src)_1."+ce:""})(),O=P.toString,R=M.hasOwnProperty,F=M.toString,z=RegExp("^"+O.call(R).replace(s,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),j=T.splice,$=ci(u,"Map"),H=ci(u,"Set"),B=ci(Object,"create");function G(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.clear();++Ie<Xe;){var Ot=ce[Ie];this.set(Ot[0],Ot[1])}}function N(){this.__data__=B?B(null):{}}function Y(ce){return this.has(ce)&&delete this.__data__[ce]}function W(ce){var Ie=this.__data__;if(B){var Xe=Ie[ce];return Xe===e?void 0:Xe}return R.call(Ie,ce)?Ie[ce]:void 0}function Q(ce){var Ie=this.__data__;return B?Ie[ce]!==void 0:R.call(Ie,ce)}function de(ce,Ie){var Xe=this.__data__;return Xe[ce]=B&&Ie===void 0?e:Ie,this}G.prototype.clear=N,G.prototype.delete=Y,G.prototype.get=W,G.prototype.has=Q,G.prototype.set=de;function U(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.clear();++Ie<Xe;){var Ot=ce[Ie];this.set(Ot[0],Ot[1])}}function re(){this.__data__=[]}function le(ce){var Ie=this.__data__,Xe=Gn(Ie,ce);if(Xe<0)return!1;var Ot=Ie.length-1;return Xe==Ot?Ie.pop():j.call(Ie,Xe,1),!0}function Se(ce){var Ie=this.__data__,Xe=Gn(Ie,ce);return Xe<0?void 0:Ie[Xe][1]}function fe(ce){return Gn(this.__data__,ce)>-1}function Me(ce,Ie){var Xe=this.__data__,Ot=Gn(Xe,ce);return Ot<0?Xe.push([ce,Ie]):Xe[Ot][1]=Ie,this}U.prototype.clear=re,U.prototype.delete=le,U.prototype.get=Se,U.prototype.has=fe,U.prototype.set=Me;function ve(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.clear();++Ie<Xe;){var Ot=ce[Ie];this.set(Ot[0],Ot[1])}}function _e(){this.__data__={hash:new G,map:new($||U),string:new G}}function Oe(ce){return li(this,ce).delete(ce)}function He(ce){return li(this,ce).get(ce)}function Bt(ce){return li(this,ce).has(ce)}function qt(ce,Ie){return li(this,ce).set(ce,Ie),this}ve.prototype.clear=_e,ve.prototype.delete=Oe,ve.prototype.get=He,ve.prototype.has=Bt,ve.prototype.set=qt;function At(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.__data__=new ve;++Ie<Xe;)this.add(ce[Ie])}function _t(ce){return this.__data__.set(ce,e),this}function $t(ce){return this.__data__.has(ce)}At.prototype.add=At.prototype.push=_t,At.prototype.has=$t;function Gn(ce,Ie){for(var Xe=ce.length;Xe--;)if(go(ce[Xe][0],Ie))return Xe;return-1}function yr(ce){if(!ls(ce)||ic(ce))return!1;var Ie=Wo(ce)||w(ce)?z:o;return Ie.test(ar(ce))}function Er(ce,Ie,Xe){var Ot=-1,Gt=f,pn=ce.length,kn=!0,zi=[],$r=zi;if(pn>=n){var cs=Hr(ce);if(cs)return x(cs);kn=!1,Gt=b,$r=new At}else $r=zi;e:for(;++Ot<pn;){var ui=ce[Ot],us=ui;if(ui=ui!==0?ui:0,kn&&us===us){for(var Xo=$r.length;Xo--;)if($r[Xo]===us)continue e;zi.push(ui)}else Gt($r,us,Xe)||($r!==zi&&$r.push(us),zi.push(ui))}return zi}var Hr=H&&1/x(new H([,-0]))[1]==t?function(ce){return new H(ce)}:al;function li(ce,Ie){var Xe=ce.__data__;return ol(Ie)?Xe[typeof Ie=="string"?"string":"hash"]:Xe.map}function ci(ce,Ie){var Xe=v(ce,Ie);return yr(Xe)?Xe:void 0}function ol(ce){var Ie=typeof ce;return Ie=="string"||Ie=="number"||Ie=="symbol"||Ie=="boolean"?ce!=="__proto__":ce===null}function ic(ce){return!!A&&A in ce}function ar(ce){if(ce!=null){try{return O.call(ce)}catch{}try{return ce+""}catch{}}return""}function Ni(ce){return ce&&ce.length?Er(ce):[]}function go(ce,Ie){return ce===Ie||ce!==ce&&Ie!==Ie}function Wo(ce){var Ie=ls(ce)?F.call(ce):"";return Ie==r||Ie==i}function ls(ce){var Ie=typeof ce;return!!ce&&(Ie=="object"||Ie=="function")}function al(){}return cC=Ni,cC}var WX=YX();const XX=Ja(WX);function gI(n,e){const t=[];e:for(const r of n){for(const i of t)if(e?e(r,i):r===i)continue e;t.push(r)}return t}function tt(n){return n.filter(e=>e!=null)}function Zr(n){return n[n.length-1]}function wB(n,e){let t,r=1/0;for(const i of n){const s=e(i);s<r&&(t=i,r=s)}return t}function ZX(n,e){let t,r=-1/0;for(const i of n){const s=e(i);s>r&&(t=i,r=s)}return t}function qb(n,e){if(n===e)return!0;if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!Object.is(n[t],e[t]))return!1;return!0}function Fg(n,e,t){const r=new Set(e.map(s=>s[n])),i=[];for(const s of t)r.has(s[n])||i.push(s);for(const s of e)i.push(s);return i}function CB(n){const e=(...t)=>{try{return n(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const om=()=>{},Hi={ok(n){return{ok:!0,value:n}},err(n){return{ok:!1,error:n}}};function kt(n,e){const t=e&&n&&typeof n=="object"&&e in n?n[e]:n;throw new Error(`Unknown switch case ${t}`)}const Be=CB((n,e)=>{if(!n)throw new Error(e||"Assertion Error")}),Mr=CB((n,e)=>{if(n==null)throw new Error(e??"value must be defined");return n});function mI(){let n,e;const t=new Promise((r,i)=>{n=r,e=i});return Object.assign(t,{resolve:n,reject:e})}function D_(n){return new Promise(e=>setTimeout(e,n))}/*!
54
- * MIT License: https://github.com/NoHomey/bind-decorator/blob/master/License
55
- * Copyright (c) 2016 Ivo Stratev
56
- */function Is(...n){if(n.length===2){const[e,t]=n;t.addInitializer(function(){Be(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");const i=e.bind(this),s=Reflect.defineProperty(this,t.name,{value:i,writable:!0,configurable:!0});Be(s,"Cannot bind a non-configurable class method.")})}else{const[e,t,r]=n;if(!r||typeof r.value!="function")throw new TypeError(`Only methods can be decorated with @bind. <${t}> is not a method!`);return{configurable:!0,get(){const i=r.value.bind(this);return Object.defineProperty(this,t,{value:i,configurable:!0,writable:!0}),i}}}}class Ii{items=new WeakMap;get(e,t){return this.items.has(e)||this.items.set(e,t(e)),this.items.get(e)}}function Sv(n,e){let t;const r=(...i)=>(t||(t={},t.promise=new Promise((s,o)=>{t.resolve=s,t.reject=o})),clearTimeout(t.timeout),t.latestArgs=i,t.timeout=setTimeout(()=>{const s=t;t=void 0;try{s.resolve(n(...s.latestArgs))}catch(o){s.reject(o)}},e),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const mR=new WeakMap;function yI(n,e){if(typeof n!="object"||n===null)return;let t=mR.get(n);t||(t={tags:{},extras:{}},mR.set(n,t)),e.tags&&(t.tags={...t.tags,...e.tags}),e.extras&&(t.extras={...t.extras,...e.extras})}async function Gl(n,e){return window.fetch(n,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const am=(n,e)=>{const t=new window.Image(n,e);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Ci{static async urlToArrayBuffer(e){return await(await Gl(e)).arrayBuffer()}static async urlToBlob(e){return await(await Gl(e)).blob()}static async urlToDataUrl(e){if(e.startsWith("data:"))return e;const t=await Ci.urlToBlob(e);return await Ci.blobToDataUrl(t)}static async blobToDataUrl(e){return await new Promise((t,r)=>{if(e){const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s=>r(s),i.onabort=s=>r(s),i.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((t,r)=>{if(e){const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s=>r(s),i.onabort=s=>r(s),i.readAsText(e)}})}static rewriteMimeType(e,t){return e.type===t?e:e instanceof File?new File([e],e.name,{type:t}):new Blob([e],{type:t})}}function SI(n){let e=0;for(let t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e|=0;return e+""}function TB(n){const e=new DataView(n);let t=0;for(let r=0;r<e.byteLength;r++)t=(t<<5)-t+e.getUint8(r),t|=0;return t+""}/*!
57
- * MIT License: https://github.com/ai/nanoid/blob/main/LICENSE
58
- * Modified code originally from <https://github.com/ai/nanoid>
59
- * Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
60
- *
61
- * `nanoid` is currently only distributed as an ES module. Some tools (jest, playwright) don't
62
- * properly support ESM-only code yet, and tldraw itself is distributed as both an ES module and a
63
- * CommonJS module. By including nanoid here, we can make sure it works well in every environment
64
- * where tldraw is used. We can also remove some unused features like custom alphabets.
65
- */const yR=globalThis.crypto,JX="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",QX=128;let rd,cf;function eZ(n){!rd||rd.length<n?(rd=new Uint8Array(n*QX),yR.getRandomValues(rd),cf=0):cf+n>rd.length&&(yR.getRandomValues(rd),cf=0),cf+=n}function tZ(n=21){eZ(n-=0);let e="";for(let t=cf-n;t<cf;t++)e+=JX[rd[t]&63];return e}let nZ=tZ;function zt(n){return nZ(n)}/*!
66
- * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
67
- * Copyright (c) Philip van Heemstra
68
- */function rZ(n){const e=new Uint8Array(n);if(!e||!(typeof Buffer<"u"&&Buffer.isBuffer(e)||e instanceof Uint8Array)||e.length<16||!(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10))return!1;function r(s,o,a,l,u=1024){if(!o)return-1;o=new RegExp(o,"g");const f=o.source.length,h=new TextDecoder,g=s.length;if(typeof l>"u"&&(l=g),a>=g||l<=0||a>=l)return-1;s=s.subarray(a,l);let y=-1,b=0,v=0,w="";e:for(;b<s.length;){const x=b+u,T=s.subarray(b,x),P=h.decode(T,{stream:!0}),M=w+P;let k,A=-1;for(;(k=o.exec(M))!==null;){A=k.index-w.length,y=v+A;break e}b=x,v+=P.length;const O=A>-1?A+f:P.length-f;w=P.slice(O)}return y>=0&&(y+=a>=0?a:g+a),y}const i=r(e,"IDAT",12);return i>=12?r(e,"acTL",8,i)>=8:!1}const iZ=n=>new Uint8Array(n)[3]===44;/*!
69
- * MIT License
70
- * Modified code originally from <https://github.com/qzb/is-animated>
71
- * Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
72
- */function SR(n,e){let t=0;for(;n[e+t];)t+=n[e+t]+1;return t+1}function sZ(n){return new TextDecoder("ascii").decode(n.slice(0,3))==="GIF"}function oZ(n){const e=new Uint8Array(n);let t,r,i=0,s=0;if(!sZ(n))return!1;for(t=e[10]&128,r=e[10]&7,i+=6,i+=7,i+=t?3*Math.pow(2,r+1):0;s<2&&i<e.length;)switch(e[i]){case 44:s+=1,t=e[i+9]&128,r=e[i+9]&7,i+=10,i+=t?3*Math.pow(2,r+1):0,i+=SR(e,i+1)+1;break;case 33:i+=2,i+=SR(e,i);break;case 59:i=e.length;break;default:i=e.length;break}return s>1}/*!
73
- * MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
74
- * Copyright: 2014 Alex Gorbatchev
75
- * Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
76
- */let R_=[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"&&(R_=new Int32Array(R_));const aZ=(n,e)=>{let t=-1;for(let r=0;r<n.length;r++)t=R_[(t^n[r])&255]^t>>>8;return t^-1},bR=4,xR=4;class La{static isPng(e,t){return e.getUint8(t+0)===137&&e.getUint8(t+1)===80&&e.getUint8(t+2)===78&&e.getUint8(t+3)===71&&e.getUint8(t+4)===13&&e.getUint8(t+5)===10&&e.getUint8(t+6)===26&&e.getUint8(t+7)===10}static getChunkType(e,t){return[String.fromCharCode(e.getUint8(t)),String.fromCharCode(e.getUint8(t+1)),String.fromCharCode(e.getUint8(t+2)),String.fromCharCode(e.getUint8(t+3))].join("")}static readChunks(e,t=0){const r={};if(!La.isPng(e,t))throw new Error("Not a PNG");for(t+=8;t<=e.buffer.byteLength;){const i=t,s=e.getInt32(t);t+=4;const o=La.getChunkType(e,t);if(o==="IDAT"&&r[o]){t+=s+bR+xR;continue}if(o==="IEND")break;r[o]={start:i,dataOffset:t+4,size:s},t+=s+bR+xR}return r}static parsePhys(e,t){return{ppux:e.getUint32(t),ppuy:e.getUint32(t+4),unit:e.getUint8(t+8)}}static findChunk(e,t){return La.readChunks(e)[t]}static setPhysChunk(e,t=1,r){let i=46,s=0;const o=La.findChunk(e,"pHYs");o&&(i=o.start,s=o.size);const a=La.findChunk(e,"IDAT");a&&(i=a.start,s=0);const l=new ArrayBuffer(21),u=new DataView(l);u.setUint32(0,9),u.setUint8(4,112),u.setUint8(5,72),u.setUint8(6,89),u.setUint8(7,115);const f=2835.5;u.setInt32(8,f*t),u.setInt32(12,f*t),u.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));u.setInt32(17,aZ(h));const g=e.buffer.slice(0,i),y=e.buffer.slice(i+s);return new Blob([g,l,y],r)}}/*!
77
- * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
78
- * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
79
- */function lZ(n){return!n||n.length<12?!1:n[8]===87&&n[9]===69&&n[10]===66&&n[11]===80}function cZ(n){const e=new Uint8Array(n);return!lZ(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const EB=Object.freeze(["image/svg+xml"]),_B=Object.freeze(["image/jpeg","image/png","image/webp"]),PB=Object.freeze(["image/gif","image/apng","image/avif"]),Gf=Object.freeze([..._B,...EB,...PB]),bv=Object.freeze(["video/mp4","video/webm","video/quicktime"]),uZ=Object.freeze([...Gf,...bv]);uZ.join(",");class Js{static loadVideo(e){return new Promise((t,r)=>{const i=document.createElement("video");i.onloadeddata=()=>t(i),i.onerror=s=>{console.error(s),r(new Error("Could not load video"))},i.crossOrigin="anonymous",i.src=e})}static async getVideoFrameAsDataUrl(e,t=0){const r=mI();let i=!1;const s=()=>{if(!i)if(e.readyState>=e.HAVE_METADATA)i=!0,e.currentTime=t;else return;if(e.readyState>=e.HAVE_CURRENT_DATA){const a=document.createElement("canvas");a.width=e.videoWidth,a.height=e.videoHeight;const l=a.getContext("2d");if(!l)throw new Error("Could not get 2d context");l.drawImage(e,0,0),r.resolve(a.toDataURL())}},o=a=>{console.error(a),r.reject(new Error("Could not get video frame"))};e.addEventListener("loadedmetadata",s),e.addEventListener("loadeddata",s),e.addEventListener("canplay",s),e.addEventListener("seeked",s),e.addEventListener("error",o),e.addEventListener("stalled",o),s();try{return await r}finally{e.removeEventListener("loadedmetadata",s),e.removeEventListener("loadeddata",s),e.removeEventListener("canplay",s),e.removeEventListener("seeked",s),e.removeEventListener("error",o),e.removeEventListener("stalled",o)}}static getImageAndDimensions(e){return new Promise((t,r)=>{const i=am();i.onload=()=>{let s;i.naturalWidth?s={w:i.naturalWidth,h:i.naturalHeight}:(document.body.appendChild(i),s={w:i.clientWidth,h:i.clientHeight},document.body.removeChild(i)),t({...s,image:i})},i.onerror=s=>{console.error(s),r(new Error("Could not load image"))},i.crossOrigin="anonymous",i.referrerPolicy="strict-origin-when-cross-origin",i.style.visibility="hidden",i.style.position="absolute",i.style.opacity="0",i.style.zIndex="-9999",i.src=e})}static async getVideoSize(e){return Js.usingObjectURL(e,async t=>{const r=await Js.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const{w:t,h:r}=await Js.usingObjectURL(e,Js.getImageAndDimensions);try{if(e.type==="image/png"){const i=new DataView(await e.arrayBuffer());if(La.isPng(i,0)){const s=La.findChunk(i,"pHYs");if(s){const o=La.parsePhys(i,s.dataOffset);if(o.unit===1&&o.ppux===o.ppuy){const l=Math.max(o.ppux/2834.645669291339,1);return{w:Math.round(t/l),h:Math.round(r/l)}}}}}}catch(i){return console.error(i),{w:t,h:r}}return{w:t,h:r}}static async isAnimated(e){return e.type==="image/gif"?oZ(await e.arrayBuffer()):e.type==="image/avif"?iZ(await e.arrayBuffer()):e.type==="image/webp"?cZ(await e.arrayBuffer()):e.type==="image/apng"?rZ(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return PB.includes(e||"")}static isStaticImageType(e){return _B.includes(e||"")}static isVectorImageType(e){return EB.includes(e||"")}static isImageType(e){return Gf.includes(e||"")}static async usingObjectURL(e,t){const r=URL.createObjectURL(e);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function at(n,e,t){return n+(e-n)*t}function lm(n,e,t){return(t-n)/(e-n)}function Ud(n=""){let e=0,t=0,r=0,i=0;function s(){const o=e^e<<11;return e=t,t=r,r=i,i^=(i>>>19^o^o>>>8)>>>0,i/4294967296*2}for(let o=0;o<n.length+64;o++)e^=n.charCodeAt(o)|0,s();return s}function pa(n,e,t,r=!1){const[i,s]=e,[o,a]=t,l=o+(n-i)/(s-i)*(a-o);return r?o<a?Math.max(Math.min(l,a),o):Math.max(Math.min(l,o),a):l}function Fo(n,e){return Object.prototype.hasOwnProperty.call(n,e)}function tr(n,e){if(Fo(n,e))return n[e]}function Ug(n){return Object.keys(n)}function Hn(n){return Object.values(n)}function Yi(n){return Object.entries(n)}function IB(n){return Object.fromEntries(n)}function Hg(n,e){const t={};let r=!1;for(const[i,s]of Yi(n))e(i,s)?t[i]=s:r=!0;return r?t:n}function wu(n,e){const t={};for(const r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=e(r,n[r]));return t}function MB(n,e){if(n===e)return!0;const t=new Set(Object.keys(n)),r=new Set(Object.keys(e));if(t.size!==r.size)return!1;for(const i of t)if(!r.has(i)||!Object.is(n[i],e[i]))return!1;return!0}function dZ(n,e){const t=[];for(const r in n)Object.is(n[r],e[r])||t.push(r);return t}function hZ(n,e,t=1e-6){return qX(n,e,(r,i)=>{if(typeof r=="number"&&typeof i=="number")return Math.abs(r-i)<t})}const xg={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},fZ=xg.Good;class kB{startTime=0;name="";frames=0;started=!1;frame=null;recordFrame=()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))};start(e){this.name=e,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 e=(performance.now()-this.startTime)/1e3,t=e===0?0:Math.floor(this.frames/e),r=t>55?xg.Good:t>30?xg.Mid:xg.Poor,i=r===xg.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${t}%c fps`,`color: white; background: ${fZ};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${r};color: ${i};`,"font-weight: normal")}isStarted(){return this.started}}const AB="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function uf(n,e,t){const r=t[0];if(e!=null&&n>=e)throw new Error(n+" >= "+e);if(n.slice(-1)===r||e&&e.slice(-1)===r)throw new Error("trailing zero");if(e){let o=0;for(;(n[o]||r)===e[o];)o++;if(o>0)return e.slice(0,o)+uf(n.slice(o),e.slice(o),t)}const i=n?t.indexOf(n[0]):0,s=e!=null?t.indexOf(e[0]):t.length;if(s-i>1){const o=Math.round(.5*(i+s));return t[o]}else return e&&e.length>1?e.slice(0,1):t[i]+uf(n.slice(1),null,t)}function OB(n){if(n.length!==DB(n[0]))throw new Error("invalid integer part of order key: "+n)}function DB(n){if(n>="a"&&n<="z")return n.charCodeAt(0)-97+2;if(n>="A"&&n<="Z")return 90-n.charCodeAt(0)+2;throw new Error("invalid order key head: "+n)}function vg(n){const e=DB(n[0]);if(e>n.length)throw new Error("invalid order key: "+n);return n.slice(0,e)}function vR(n,e){if(n==="A"+e[0].repeat(26))throw new Error("invalid order key: "+n);const t=vg(n);if(n.slice(t.length).slice(-1)===e[0])throw new Error("invalid order key: "+n)}function wR(n,e){OB(n);const[t,...r]=n.split("");let i=!0;for(let s=r.length-1;i&&s>=0;s--){const o=e.indexOf(r[s])+1;o===e.length?r[s]=e[0]:(r[s]=e[o],i=!1)}if(i){if(t==="Z")return"a"+e[0];if(t==="z")return null;const s=String.fromCharCode(t.charCodeAt(0)+1);return s>"a"?r.push(e[0]):r.pop(),s+r.join("")}else return t+r.join("")}function pZ(n,e){OB(n);const[t,...r]=n.split("");let i=!0;for(let s=r.length-1;i&&s>=0;s--){const o=e.indexOf(r[s])-1;o===-1?r[s]=e.slice(-1):(r[s]=e[o],i=!1)}if(i){if(t==="a")return"Z"+e.slice(-1);if(t==="A")return null;const s=String.fromCharCode(t.charCodeAt(0)-1);return s<"Z"?r.push(e.slice(-1)):r.pop(),s+r.join("")}else return t+r.join("")}function Vc(n,e,t=AB){if(n!=null&&vR(n,t),e!=null&&vR(e,t),n!=null&&e!=null&&n>=e)throw new Error(n+" >= "+e);if(n==null){if(e==null)return"a"+t[0];const l=vg(e),u=e.slice(l.length);if(l==="A"+t[0].repeat(26))return l+uf("",u,t);if(l<e)return l;const f=pZ(l,t);if(f==null)throw new Error("cannot decrement any more");return f}if(e==null){const l=vg(n),u=n.slice(l.length),f=wR(l,t);return f??l+uf(u,null,t)}const r=vg(n),i=n.slice(r.length),s=vg(e),o=e.slice(s.length);if(r===s)return r+uf(i,o,t);const a=wR(r,t);if(a==null)throw new Error("cannot increment any more");return a<e?a:r+uf(i,null,t)}function Vb(n,e,t,r=AB){if(t===0)return[];if(t===1)return[Vc(n,e,r)];if(e==null){let o=Vc(n,e,r);const a=[o];for(let l=0;l<t-1;l++)o=Vc(o,e,r),a.push(o);return a}if(n==null){let o=Vc(n,e,r);const a=[o];for(let l=0;l<t-1;l++)o=Vc(n,o,r),a.push(o);return a.reverse(),a}const i=Math.floor(t/2),s=Vc(n,e,r);return[...Vb(n,s,i,r),s,...Vb(s,e,t-i-1,r)]}const gZ=30,mZ=()=>Math.random()<.5;function RB(n,e){if(!Number.isInteger(e))throw new Error(`"${n}" must be an integer, got '${e}'`);if(e<0)throw new Error(`"${n}" must be greater than or equal to 0, got '${e}'`)}function jB(n,e,t){const{digits:r,jitterBits:i=gZ,getRandomBit:s=mZ}=t??{};RB("jitterBits",i);let o=i,a=n,l=e,u=Vc(n,e,r);for(;o>0;)(s()?1:0)===1?a=u:l=u,u=Vc(a,l,r),o--;return u}function yZ(n,e,t,r){const{digits:i,jitterBits:s}=r??{};if(RB("n",t),t===0)return[];if(s===0)return Vb(n,e,t,i);const o=Vb(n,e,t+1,i),a=[];for(let l=0;l<t;l++){const u=o[l],f=o[l+1];a.push(jB(u,f,r))}return a}const Yf=yZ,bI="a0";function SZ(n){try{jB(n,null)}catch{throw new Error("invalid index: "+n)}}function vd(n,e,t){return Yf(n??null,e??null,t)}function uC(n,e){return Yf(n??null,null,e)}function Mf(n,e){return Yf(n??null,e??null,1)[0]}function Lo(n=null){return Yf(n,null,1)[0]}function bZ(n=null){return Yf(null,n,1)[0]}function cm(n,e="a1"){return[e,...Yf(e,null,n)]}function kr(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function xZ(n,e){return n.id>e.id?1:-1}function xI(n){try{return localStorage.getItem(n)}catch{return null}}function vI(n,e){try{localStorage.setItem(n,e)}catch{}}function vZ(){try{localStorage.clear()}catch{}}function LB(n){try{return sessionStorage.getItem(n)}catch{return null}}function wI(n,e){try{sessionStorage.setItem(n,e)}catch{}}function NB(n){try{sessionStorage.removeItem(n)}catch{}}function wZ(){try{sessionStorage.clear()}catch{}}const df=[],CZ=60,zB=Math.floor(1e3/CZ)*.9;let dC,AS,hC=-zB;const CR=()=>{const n=df.splice(0,df.length);for(const e of n)e()};function BB(n=!1){if(dC)return;const e=Date.now();if(e-hC<zB){dC=requestAnimationFrame(()=>{dC=void 0,BB(!0)});return}if(n){if(AS)return;hC=e,CR()}else{if(AS)return;AS=requestAnimationFrame(()=>{AS=void 0,hC=e,CR()})}}function CI(n){return df.includes(n)||(df.push(n),BB()),()=>{const e=df.indexOf(n);e>-1&&df.splice(e,1)}}class TZ{timeouts=new Map;intervals=new Map;rafs=new Map;constructor(){this.setTimeout=this.setTimeout.bind(this),this.setInterval=this.setInterval.bind(this),this.requestAnimationFrame=this.requestAnimationFrame.bind(this),this.dispose=this.dispose.bind(this)}setTimeout(e,t,r,...i){const s=window.setTimeout(t,r,i),o=this.timeouts.get(e)??[];return this.timeouts.set(e,[...o,s]),s}setInterval(e,t,r,...i){const s=window.setInterval(t,r,i),o=this.intervals.get(e)??[];return this.intervals.set(e,[...o,s]),s}requestAnimationFrame(e,t){const r=window.requestAnimationFrame(t),i=this.rafs.get(e)??[];return this.rafs.set(e,[...i,r]),r}dispose(e){this.timeouts.get(e)?.forEach(t=>clearTimeout(t)),this.intervals.get(e)?.forEach(t=>clearInterval(t)),this.rafs.get(e)?.forEach(t=>cancelAnimationFrame(t)),this.timeouts.delete(e),this.intervals.delete(e),this.rafs.delete(e)}disposeAll(){for(const e of this.timeouts.keys())this.dispose(e)}forContext(e){return{setTimeout:(t,r,...i)=>this.setTimeout(e,t,r,i),setInterval:(t,r,...i)=>this.setInterval(e,t,r,i),requestAnimationFrame:t=>this.requestAnimationFrame(e,t),dispose:()=>this.dispose(e)}}}const it=(n,e)=>{try{return new URL(n,e)}catch{return}};function EZ(n){return n!==void 0}function _Z(){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]:[n=>n&&JSON.parse(JSON.stringify(n)),!1]}const FB=_Z(),Qn=FB[0];FB[1];const PZ=Object.getPrototypeOf(Qn({})),TR=new Set;function IZ(n){TR.has(n)||(TR.add(n),console.warn(`[tldraw] ${n}`))}xu("@tldraw/utils","4.1.2","esm");var ER={},eg,_R;function Mi(){if(_R)return eg;_R=1;var n=function(e){return e&&e.Math===Math&&e};return eg=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof Rr=="object"&&Rr)||n(typeof eg=="object"&&eg)||(function(){return this})()||Function("return this")(),eg}var fC={},pC,PR;function ki(){return PR||(PR=1,pC=function(n){try{return!!n()}catch{return!0}}),pC}var gC,IR;function Cu(){if(IR)return gC;IR=1;var n=ki();return gC=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),gC}var mC,MR;function xv(){if(MR)return mC;MR=1;var n=ki();return mC=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),mC}var yC,kR;function Jl(){if(kR)return yC;kR=1;var n=xv(),e=Function.prototype.call;return yC=n?e.bind(e):function(){return e.apply(e,arguments)},yC}var SC={},AR;function MZ(){if(AR)return SC;AR=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return SC.f=t?function(i){var s=e(this,i);return!!s&&s.enumerable}:n,SC}var bC,OR;function UB(){return OR||(OR=1,bC=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),bC}var xC,DR;function Br(){if(DR)return xC;DR=1;var n=xv(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return xC=n?r:function(i){return function(){return t.apply(i,arguments)}},xC}var vC,RR;function Wf(){if(RR)return vC;RR=1;var n=Br(),e=n({}.toString),t=n("".slice);return vC=function(r){return t(e(r),8,-1)},vC}var wC,jR;function kZ(){if(jR)return wC;jR=1;var n=Br(),e=ki(),t=Wf(),r=Object,i=n("".split);return wC=e(function(){return!r("z").propertyIsEnumerable(0)})?function(s){return t(s)==="String"?i(s,""):r(s)}:r,wC}var CC,LR;function HB(){return LR||(LR=1,CC=function(n){return n==null}),CC}var TC,NR;function Xf(){if(NR)return TC;NR=1;var n=HB(),e=TypeError;return TC=function(t){if(n(t))throw new e("Can't call method on "+t);return t},TC}var EC,zR;function vv(){if(zR)return EC;zR=1;var n=kZ(),e=Xf();return EC=function(t){return n(e(t))},EC}var _C,BR;function is(){if(BR)return _C;BR=1;var n=typeof document=="object"&&document.all;return _C=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},_C}var PC,FR;function Ql(){if(FR)return PC;FR=1;var n=is();return PC=function(e){return typeof e=="object"?e!==null:n(e)},PC}var IC,UR;function wv(){if(UR)return IC;UR=1;var n=Mi(),e=is(),t=function(r){return e(r)?r:void 0};return IC=function(r,i){return arguments.length<2?t(n[r]):n[r]&&n[r][i]},IC}var MC,HR;function $B(){if(HR)return MC;HR=1;var n=Br();return MC=n({}.isPrototypeOf),MC}var kC,$R;function AZ(){if($R)return kC;$R=1;var n=Mi(),e=n.navigator,t=e&&e.userAgent;return kC=t?String(t):"",kC}var AC,KR;function OZ(){if(KR)return AC;KR=1;var n=Mi(),e=AZ(),t=n.process,r=n.Deno,i=t&&t.versions||r&&r.version,s=i&&i.v8,o,a;return s&&(o=s.split("."),a=o[0]>0&&o[0]<4?1:+(o[0]+o[1])),!a&&e&&(o=e.match(/Edge\/(\d+)/),(!o||o[1]>=74)&&(o=e.match(/Chrome\/(\d+)/),o&&(a=+o[1]))),AC=a,AC}var OC,qR;function KB(){if(qR)return OC;qR=1;var n=OZ(),e=ki(),t=Mi(),r=t.String;return OC=!!Object.getOwnPropertySymbols&&!e(function(){var i=Symbol("symbol detection");return!r(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&n&&n<41}),OC}var DC,VR;function qB(){if(VR)return DC;VR=1;var n=KB();return DC=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",DC}var RC,GR;function VB(){if(GR)return RC;GR=1;var n=wv(),e=is(),t=$B(),r=qB(),i=Object;return RC=r?function(s){return typeof s=="symbol"}:function(s){var o=n("Symbol");return e(o)&&t(o.prototype,i(s))},RC}var jC,YR;function DZ(){if(YR)return jC;YR=1;var n=String;return jC=function(e){try{return n(e)}catch{return"Object"}},jC}var LC,WR;function TI(){if(WR)return LC;WR=1;var n=is(),e=DZ(),t=TypeError;return LC=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},LC}var NC,XR;function EI(){if(XR)return NC;XR=1;var n=TI(),e=HB();return NC=function(t,r){var i=t[r];return e(i)?void 0:n(i)},NC}var zC,ZR;function RZ(){if(ZR)return zC;ZR=1;var n=Jl(),e=is(),t=Ql(),r=TypeError;return zC=function(i,s){var o,a;if(s==="string"&&e(o=i.toString)&&!t(a=n(o,i))||e(o=i.valueOf)&&!t(a=n(o,i))||s!=="string"&&e(o=i.toString)&&!t(a=n(o,i)))return a;throw new r("Can't convert object to primitive value")},zC}var BC={exports:{}},FC,JR;function GB(){return JR||(JR=1,FC=!1),FC}var UC,QR;function _I(){if(QR)return UC;QR=1;var n=Mi(),e=Object.defineProperty;return UC=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},UC}var ej;function PI(){if(ej)return BC.exports;ej=1;var n=GB(),e=Mi(),t=_I(),r="__core-js_shared__",i=BC.exports=e[r]||t(r,{});return(i.versions||(i.versions=[])).push({version:"3.46.0",mode:n?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru), 2025 CoreJS Company (core-js.io)",license:"https://github.com/zloirock/core-js/blob/v3.46.0/LICENSE",source:"https://github.com/zloirock/core-js"}),BC.exports}var HC,tj;function II(){if(tj)return HC;tj=1;var n=PI();return HC=function(e,t){return n[e]||(n[e]=t||{})},HC}var $C,nj;function $m(){if(nj)return $C;nj=1;var n=Xf(),e=Object;return $C=function(t){return e(n(t))},$C}var KC,rj;function Tu(){if(rj)return KC;rj=1;var n=Br(),e=$m(),t=n({}.hasOwnProperty);return KC=Object.hasOwn||function(i,s){return t(e(i),s)},KC}var qC,ij;function YB(){if(ij)return qC;ij=1;var n=Br(),e=0,t=Math.random(),r=n(1.1.toString);return qC=function(i){return"Symbol("+(i===void 0?"":i)+")_"+r(++e+t,36)},qC}var VC,sj;function ec(){if(sj)return VC;sj=1;var n=Mi(),e=II(),t=Tu(),r=YB(),i=KB(),s=qB(),o=n.Symbol,a=e("wks"),l=s?o.for||o:o&&o.withoutSetter||r;return VC=function(u){return t(a,u)||(a[u]=i&&t(o,u)?o[u]:l("Symbol."+u)),a[u]},VC}var GC,oj;function jZ(){if(oj)return GC;oj=1;var n=Jl(),e=Ql(),t=VB(),r=EI(),i=RZ(),s=ec(),o=TypeError,a=s("toPrimitive");return GC=function(l,u){if(!e(l)||t(l))return l;var f=r(l,a),h;if(f){if(u===void 0&&(u="default"),h=n(f,l,u),!e(h)||t(h))return h;throw new o("Can't convert object to primitive value")}return u===void 0&&(u="number"),i(l,u)},GC}var YC,aj;function WB(){if(aj)return YC;aj=1;var n=jZ(),e=VB();return YC=function(t){var r=n(t,"string");return e(r)?r:r+""},YC}var WC,lj;function XB(){if(lj)return WC;lj=1;var n=Mi(),e=Ql(),t=n.document,r=e(t)&&e(t.createElement);return WC=function(i){return r?t.createElement(i):{}},WC}var XC,cj;function ZB(){if(cj)return XC;cj=1;var n=Cu(),e=ki(),t=XB();return XC=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),XC}var uj;function JB(){if(uj)return fC;uj=1;var n=Cu(),e=Jl(),t=MZ(),r=UB(),i=vv(),s=WB(),o=Tu(),a=ZB(),l=Object.getOwnPropertyDescriptor;return fC.f=n?l:function(f,h){if(f=i(f),h=s(h),a)try{return l(f,h)}catch{}if(o(f,h))return r(!e(t.f,f,h),f[h])},fC}var ZC={},JC,dj;function QB(){if(dj)return JC;dj=1;var n=Cu(),e=ki();return JC=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),JC}var QC,hj;function Hd(){if(hj)return QC;hj=1;var n=Ql(),e=String,t=TypeError;return QC=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},QC}var fj;function Km(){if(fj)return ZC;fj=1;var n=Cu(),e=ZB(),t=QB(),r=Hd(),i=WB(),s=TypeError,o=Object.defineProperty,a=Object.getOwnPropertyDescriptor,l="enumerable",u="configurable",f="writable";return ZC.f=n?t?function(g,y,b){if(r(g),y=i(y),r(b),typeof g=="function"&&y==="prototype"&&"value"in b&&f in b&&!b[f]){var v=a(g,y);v&&v[f]&&(g[y]=b.value,b={configurable:u in b?b[u]:v[u],enumerable:l in b?b[l]:v[l],writable:!1})}return o(g,y,b)}:o:function(g,y,b){if(r(g),y=i(y),r(b),e)try{return o(g,y,b)}catch{}if("get"in b||"set"in b)throw new s("Accessors not supported");return"value"in b&&(g[y]=b.value),g},ZC}var eT,pj;function MI(){if(pj)return eT;pj=1;var n=Cu(),e=Km(),t=UB();return eT=n?function(r,i,s){return e.f(r,i,t(1,s))}:function(r,i,s){return r[i]=s,r},eT}var tT={exports:{}},nT,gj;function LZ(){if(gj)return nT;gj=1;var n=Cu(),e=Tu(),t=Function.prototype,r=n&&Object.getOwnPropertyDescriptor,i=e(t,"name"),s=i&&(function(){}).name==="something",o=i&&(!n||n&&r(t,"name").configurable);return nT={EXISTS:i,PROPER:s,CONFIGURABLE:o},nT}var rT,mj;function e4(){if(mj)return rT;mj=1;var n=Br(),e=is(),t=PI(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(i){return r(i)}),rT=t.inspectSource,rT}var iT,yj;function NZ(){if(yj)return iT;yj=1;var n=Mi(),e=is(),t=n.WeakMap;return iT=e(t)&&/native code/.test(String(t)),iT}var sT,Sj;function t4(){if(Sj)return sT;Sj=1;var n=II(),e=YB(),t=n("keys");return sT=function(r){return t[r]||(t[r]=e(r))},sT}var oT,bj;function kI(){return bj||(bj=1,oT={}),oT}var aT,xj;function n4(){if(xj)return aT;xj=1;var n=NZ(),e=Mi(),t=Ql(),r=MI(),i=Tu(),s=PI(),o=t4(),a=kI(),l="Object already initialized",u=e.TypeError,f=e.WeakMap,h,g,y,b=function(T){return y(T)?g(T):h(T,{})},v=function(T){return function(P){var M;if(!t(P)||(M=g(P)).type!==T)throw new u("Incompatible receiver, "+T+" required");return M}};if(n||s.state){var w=s.state||(s.state=new f);w.get=w.get,w.has=w.has,w.set=w.set,h=function(T,P){if(w.has(T))throw new u(l);return P.facade=T,w.set(T,P),P},g=function(T){return w.get(T)||{}},y=function(T){return w.has(T)}}else{var x=o("state");a[x]=!0,h=function(T,P){if(i(T,x))throw new u(l);return P.facade=T,r(T,x,P),P},g=function(T){return i(T,x)?T[x]:{}},y=function(T){return i(T,x)}}return aT={set:h,get:g,has:y,enforce:b,getterFor:v},aT}var vj;function zZ(){if(vj)return tT.exports;vj=1;var n=Br(),e=ki(),t=is(),r=Tu(),i=Cu(),s=LZ().CONFIGURABLE,o=e4(),a=n4(),l=a.enforce,u=a.get,f=String,h=Object.defineProperty,g=n("".slice),y=n("".replace),b=n([].join),v=i&&!e(function(){return h(function(){},"length",{value:8}).length!==8}),w=String(String).split("String"),x=tT.exports=function(T,P,M){g(f(P),0,7)==="Symbol("&&(P="["+y(f(P),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),M&&M.getter&&(P="get "+P),M&&M.setter&&(P="set "+P),(!r(T,"name")||s&&T.name!==P)&&(i?h(T,"name",{value:P,configurable:!0}):T.name=P),v&&M&&r(M,"arity")&&T.length!==M.arity&&h(T,"length",{value:M.arity});try{M&&r(M,"constructor")&&M.constructor?i&&h(T,"prototype",{writable:!1}):T.prototype&&(T.prototype=void 0)}catch{}var k=l(T);return r(k,"source")||(k.source=b(w,typeof P=="string"?P:"")),T};return Function.prototype.toString=x(function(){return t(this)&&u(this).source||o(this)},"toString"),tT.exports}var lT,wj;function r4(){if(wj)return lT;wj=1;var n=is(),e=Km(),t=zZ(),r=_I();return lT=function(i,s,o,a){a||(a={});var l=a.enumerable,u=a.name!==void 0?a.name:s;if(n(o)&&t(o,u,a),a.global)l?i[s]=o:r(s,o);else{try{a.unsafe?i[s]&&(l=!0):delete i[s]}catch{}l?i[s]=o:e.f(i,s,{value:o,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return i},lT}var cT={},uT,Cj;function BZ(){if(Cj)return uT;Cj=1;var n=Math.ceil,e=Math.floor;return uT=Math.trunc||function(r){var i=+r;return(i>0?e:n)(i)},uT}var dT,Tj;function $d(){if(Tj)return dT;Tj=1;var n=BZ();return dT=function(e){var t=+e;return t!==t||t===0?0:n(t)},dT}var hT,Ej;function FZ(){if(Ej)return hT;Ej=1;var n=$d(),e=Math.max,t=Math.min;return hT=function(r,i){var s=n(r);return s<0?e(s+i,0):t(s,i)},hT}var fT,_j;function i4(){if(_j)return fT;_j=1;var n=$d(),e=Math.min;return fT=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},fT}var pT,Pj;function qm(){if(Pj)return pT;Pj=1;var n=i4();return pT=function(e){return n(e.length)},pT}var gT,Ij;function UZ(){if(Ij)return gT;Ij=1;var n=vv(),e=FZ(),t=qm(),r=function(i){return function(s,o,a){var l=n(s),u=t(l);if(u===0)return!i&&-1;var f=e(a,u),h;if(i&&o!==o){for(;u>f;)if(h=l[f++],h!==h)return!0}else for(;u>f;f++)if((i||f in l)&&l[f]===o)return i||f||0;return!i&&-1}};return gT={includes:r(!0),indexOf:r(!1)},gT}var mT,Mj;function s4(){if(Mj)return mT;Mj=1;var n=Br(),e=Tu(),t=vv(),r=UZ().indexOf,i=kI(),s=n([].push);return mT=function(o,a){var l=t(o),u=0,f=[],h;for(h in l)!e(i,h)&&e(l,h)&&s(f,h);for(;a.length>u;)e(l,h=a[u++])&&(~r(f,h)||s(f,h));return f},mT}var yT,kj;function AI(){return kj||(kj=1,yT=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),yT}var Aj;function HZ(){if(Aj)return cT;Aj=1;var n=s4(),e=AI(),t=e.concat("length","prototype");return cT.f=Object.getOwnPropertyNames||function(i){return n(i,t)},cT}var ST={},Oj;function $Z(){return Oj||(Oj=1,ST.f=Object.getOwnPropertySymbols),ST}var bT,Dj;function KZ(){if(Dj)return bT;Dj=1;var n=wv(),e=Br(),t=HZ(),r=$Z(),i=Hd(),s=e([].concat);return bT=n("Reflect","ownKeys")||function(a){var l=t.f(i(a)),u=r.f;return u?s(l,u(a)):l},bT}var xT,Rj;function qZ(){if(Rj)return xT;Rj=1;var n=Tu(),e=KZ(),t=JB(),r=Km();return xT=function(i,s,o){for(var a=e(s),l=r.f,u=t.f,f=0;f<a.length;f++){var h=a[f];!n(i,h)&&!(o&&n(o,h))&&l(i,h,u(s,h))}},xT}var vT,jj;function VZ(){if(jj)return vT;jj=1;var n=ki(),e=is(),t=/#|\.prototype\./,r=function(l,u){var f=s[i(l)];return f===a?!0:f===o?!1:e(u)?n(u):!!u},i=r.normalize=function(l){return String(l).replace(t,".").toLowerCase()},s=r.data={},o=r.NATIVE="N",a=r.POLYFILL="P";return vT=r,vT}var wT,Lj;function Zf(){if(Lj)return wT;Lj=1;var n=Mi(),e=JB().f,t=MI(),r=r4(),i=_I(),s=qZ(),o=VZ();return wT=function(a,l){var u=a.target,f=a.global,h=a.stat,g,y,b,v,w,x;if(f?y=n:h?y=n[u]||i(u,{}):y=n[u]&&n[u].prototype,y)for(b in l){if(w=l[b],a.dontCallGetSet?(x=e(y,b),v=x&&x.value):v=y[b],g=o(f?b:u+(h?".":"#")+b,a.forced),!g&&v!==void 0){if(typeof w==typeof v)continue;s(w,v)}(a.sham||v&&v.sham)&&t(w,"sham",!0),r(y,b,w,a)}},wT}var CT={},TT,Nj;function GZ(){if(Nj)return TT;Nj=1;var n=s4(),e=AI();return TT=Object.keys||function(r){return n(r,e)},TT}var zj;function YZ(){if(zj)return CT;zj=1;var n=Cu(),e=QB(),t=Km(),r=Hd(),i=vv(),s=GZ();return CT.f=n&&!e?Object.defineProperties:function(a,l){r(a);for(var u=i(l),f=s(l),h=f.length,g=0,y;h>g;)t.f(a,y=f[g++],u[y]);return a},CT}var ET,Bj;function WZ(){if(Bj)return ET;Bj=1;var n=wv();return ET=n("document","documentElement"),ET}var _T,Fj;function o4(){if(Fj)return _T;Fj=1;var n=Hd(),e=YZ(),t=AI(),r=kI(),i=WZ(),s=XB(),o=t4(),a=">",l="<",u="prototype",f="script",h=o("IE_PROTO"),g=function(){},y=function(T){return l+f+a+T+l+"/"+f+a},b=function(T){T.write(y("")),T.close();var P=T.parentWindow.Object;return T=null,P},v=function(){var T=s("iframe"),P="java"+f+":",M;return T.style.display="none",i.appendChild(T),T.src=String(P),M=T.contentWindow.document,M.open(),M.write(y("document.F=Object")),M.close(),M.F},w,x=function(){try{w=new ActiveXObject("htmlfile")}catch{}x=typeof document<"u"?document.domain&&w?b(w):v():b(w);for(var T=t.length;T--;)delete x[u][t[T]];return x()};return r[h]=!0,_T=Object.create||function(P,M){var k;return P!==null?(g[u]=n(P),k=new g,g[u]=null,k[h]=P):k=x(),M===void 0?k:e.f(k,M)},_T}var PT,Uj;function OI(){if(Uj)return PT;Uj=1;var n=ec(),e=o4(),t=Km().f,r=n("unscopables"),i=Array.prototype;return i[r]===void 0&&t(i,r,{configurable:!0,value:e(null)}),PT=function(s){i[r][s]=!0},PT}var Hj;function XZ(){if(Hj)return ER;Hj=1;var n=Zf(),e=$m(),t=qm(),r=$d(),i=OI();return n({target:"Array",proto:!0},{at:function(o){var a=e(this),l=t(a),u=r(o),f=u>=0?u:l+u;return f<0||f>=l?void 0:a[f]}}),i("at"),ER}var IT,$j;function Vm(){if($j)return IT;$j=1;var n=Mi(),e=Br();return IT=function(t,r){return e(n[t].prototype[r])},IT}var MT,Kj;function ZZ(){if(Kj)return MT;Kj=1,XZ();var n=Vm();return MT=n("Array","at"),MT}var kT,qj;function JZ(){if(qj)return kT;qj=1;var n=ZZ();return kT=n,kT}JZ();var Vj={},AT,Gj;function a4(){if(Gj)return AT;Gj=1;var n=Wf();return AT=Array.isArray||function(t){return n(t)==="Array"},AT}var OT,Yj;function QZ(){if(Yj)return OT;Yj=1;var n=TypeError,e=9007199254740991;return OT=function(t){if(t>e)throw n("Maximum allowed index exceeded");return t},OT}var DT,Wj;function eJ(){if(Wj)return DT;Wj=1;var n=Wf(),e=Br();return DT=function(t){if(n(t)==="Function")return e(t)},DT}var RT,Xj;function tJ(){if(Xj)return RT;Xj=1;var n=eJ(),e=TI(),t=xv(),r=n(n.bind);return RT=function(i,s){return e(i),s===void 0?i:t?r(i,s):function(){return i.apply(s,arguments)}},RT}var jT,Zj;function l4(){if(Zj)return jT;Zj=1;var n=a4(),e=qm(),t=QZ(),r=tJ(),i=function(s,o,a,l,u,f,h,g){for(var y=u,b=0,v=h?r(h,g):!1,w,x;b<l;)b in a&&(w=v?v(a[b],b,o):a[b],f>0&&n(w)?(x=e(w),y=i(s,o,w,x,y,f-1)-1):(t(y+1),s[y]=w),y++),b++;return y};return jT=i,jT}var LT,Jj;function nJ(){if(Jj)return LT;Jj=1;var n=ec(),e=n("toStringTag"),t={};return t[e]="z",LT=String(t)==="[object z]",LT}var NT,Qj;function c4(){if(Qj)return NT;Qj=1;var n=nJ(),e=is(),t=Wf(),r=ec(),i=r("toStringTag"),s=Object,o=t((function(){return arguments})())==="Arguments",a=function(l,u){try{return l[u]}catch{}};return NT=n?t:function(l){var u,f,h;return l===void 0?"Undefined":l===null?"Null":typeof(f=a(u=s(l),i))=="string"?f:o?t(u):(h=t(u))==="Object"&&e(u.callee)?"Arguments":h},NT}var zT,eL;function rJ(){if(eL)return zT;eL=1;var n=Br(),e=ki(),t=is(),r=c4(),i=wv(),s=e4(),o=function(){},a=i("Reflect","construct"),l=/^\s*(?:class|function)\b/,u=n(l.exec),f=!l.test(o),h=function(b){if(!t(b))return!1;try{return a(o,[],b),!0}catch{return!1}},g=function(b){if(!t(b))return!1;switch(r(b)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return f||!!u(l,s(b))}catch{return!0}};return g.sham=!0,zT=!a||e(function(){var y;return h(h.call)||!h(Object)||!h(function(){y=!0})||y})?g:h,zT}var BT,tL;function iJ(){if(tL)return BT;tL=1;var n=a4(),e=rJ(),t=Ql(),r=ec(),i=r("species"),s=Array;return BT=function(o){var a;return n(o)&&(a=o.constructor,e(a)&&(a===s||n(a.prototype))?a=void 0:t(a)&&(a=a[i],a===null&&(a=void 0))),a===void 0?s:a},BT}var FT,nL;function u4(){if(nL)return FT;nL=1;var n=iJ();return FT=function(e,t){return new(n(e))(t===0?0:t)},FT}var rL;function sJ(){if(rL)return Vj;rL=1;var n=Zf(),e=l4(),t=TI(),r=$m(),i=qm(),s=u4();return n({target:"Array",proto:!0},{flatMap:function(a){var l=r(this),u=i(l),f;return t(a),f=s(l,0),f.length=e(f,l,l,u,0,1,a,arguments.length>1?arguments[1]:void 0),f}}),Vj}var iL={},sL;function oJ(){if(sL)return iL;sL=1;var n=OI();return n("flatMap"),iL}var UT,oL;function aJ(){if(oL)return UT;oL=1,sJ(),oJ();var n=Vm();return UT=n("Array","flatMap"),UT}var HT,aL;function lJ(){if(aL)return HT;aL=1;var n=aJ();return HT=n,HT}lJ();var lL={},cL;function cJ(){if(cL)return lL;cL=1;var n=Zf(),e=l4(),t=$m(),r=qm(),i=$d(),s=u4();return n({target:"Array",proto:!0},{flat:function(){var a=arguments.length?arguments[0]:void 0,l=t(this),u=r(l),f=s(l,0);return f.length=e(f,l,l,u,0,a===void 0?1:i(a)),f}}),lL}var uL={},dL;function uJ(){if(dL)return uL;dL=1;var n=OI();return n("flat"),uL}var $T,hL;function dJ(){if(hL)return $T;hL=1,cJ(),uJ();var n=Vm();return $T=n("Array","flat"),$T}var KT,fL;function hJ(){if(fL)return KT;fL=1;var n=dJ();return KT=n,KT}hJ();var pL={},qT,gL;function Gm(){if(gL)return qT;gL=1;var n=c4(),e=String;return qT=function(t){if(n(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return e(t)},qT}var mL;function fJ(){if(mL)return pL;mL=1;var n=Zf(),e=Br(),t=Xf(),r=$d(),i=Gm(),s=ki(),o=e("".charAt),a=s(function(){return"𠮷".at(-2)!=="\uD842"});return n({target:"String",proto:!0,forced:a},{at:function(u){var f=i(t(this)),h=f.length,g=r(u),y=g>=0?g:h+g;return y<0||y>=h?void 0:o(f,y)}}),pL}var VT,yL;function pJ(){if(yL)return VT;yL=1,fJ();var n=Vm();return VT=n("String","at"),VT}var GT,SL;function gJ(){if(SL)return GT;SL=1;var n=pJ();return GT=n,GT}gJ();var bL={},YT,xL;function d4(){if(xL)return YT;xL=1;var n=Hd();return YT=function(){var e=n(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},YT}var WT,vL;function mJ(){if(vL)return WT;vL=1;var n=ki(),e=Mi(),t=e.RegExp,r=n(function(){var o=t("a","y");return o.lastIndex=2,o.exec("abcd")!==null}),i=r||n(function(){return!t("a","y").sticky}),s=r||n(function(){var o=t("^r","gy");return o.lastIndex=2,o.exec("str")!==null});return WT={BROKEN_CARET:s,MISSED_STICKY:i,UNSUPPORTED_Y:r},WT}var XT,wL;function yJ(){if(wL)return XT;wL=1;var n=ki(),e=Mi(),t=e.RegExp;return XT=n(function(){var r=t(".","s");return!(r.dotAll&&r.test(`
13
+ `)),n.didWarn=!0;return}}function dR(n,e){const t=n.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/),r=e.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/);return!t||!r?n.localeCompare(e):t[1]!==r[1]?Number(t[1])-Number(r[1]):t[2]!==r[2]?Number(t[2])-Number(r[2]):t[3]!==r[3]?Number(t[3])-Number(r[3]):t[4]&&r[4]?t[4].localeCompare(r[4]):t[4]?1:r[4]?-1:0}const FX={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function Al(n,e=[]){return`\x1B[${e.map(t=>FX[t]).join(";")}m${n}\x1B[m`}function aC(n,e,t){return n.has(e)?n.get(e):(n.set(e,t),t)}var Sg={exports:{}};Sg.exports;var hR;function UX(){return hR||(hR=1,(function(n,e){var t=200,r="__lodash_hash_undefined__",i=1,s=2,o=9007199254740991,a="[object Arguments]",l="[object Array]",u="[object AsyncFunction]",f="[object Boolean]",h="[object Date]",g="[object Error]",y="[object Function]",b="[object GeneratorFunction]",v="[object Map]",w="[object Number]",x="[object Null]",T="[object Object]",P="[object Promise]",M="[object Proxy]",k="[object RegExp]",A="[object Set]",O="[object String]",R="[object Symbol]",F="[object Undefined]",z="[object WeakMap]",j="[object ArrayBuffer]",$="[object DataView]",H="[object Float32Array]",B="[object Float64Array]",G="[object Int8Array]",N="[object Int16Array]",Y="[object Int32Array]",W="[object Uint8Array]",Q="[object Uint8ClampedArray]",de="[object Uint16Array]",U="[object Uint32Array]",re=/[\\^$.*+?()[\]{}|]/g,le=/^\[object .+?Constructor\]$/,Se=/^(?:0|[1-9]\d*)$/,fe={};fe[H]=fe[B]=fe[G]=fe[N]=fe[Y]=fe[W]=fe[Q]=fe[de]=fe[U]=!0,fe[a]=fe[l]=fe[j]=fe[f]=fe[$]=fe[h]=fe[g]=fe[y]=fe[v]=fe[w]=fe[T]=fe[k]=fe[A]=fe[O]=fe[z]=!1;var Me=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,ve=typeof self=="object"&&self&&self.Object===Object&&self,_e=Me||ve||Function("return this")(),Oe=e&&!e.nodeType&&e,He=Oe&&!0&&n&&!n.nodeType&&n,Bt=He&&He.exports===Oe,qt=Bt&&Me.process,At=(function(){try{return qt&&qt.binding&&qt.binding("util")}catch{}})(),_t=At&&At.isTypedArray;function $t(K,J){for(var be=-1,ke=K==null?0:K.length,jt=0,ot=[];++be<ke;){var en=K[be];J(en,be,K)&&(ot[jt++]=en)}return ot}function Gn(K,J){for(var be=-1,ke=J.length,jt=K.length;++be<ke;)K[jt+be]=J[be];return K}function yr(K,J){for(var be=-1,ke=K==null?0:K.length;++be<ke;)if(J(K[be],be,K))return!0;return!1}function Er(K,J){for(var be=-1,ke=Array(K);++be<K;)ke[be]=J(be);return ke}function Hr(K){return function(J){return K(J)}}function li(K,J){return K.has(J)}function ci(K,J){return K?.[J]}function ol(K){var J=-1,be=Array(K.size);return K.forEach(function(ke,jt){be[++J]=[jt,ke]}),be}function ic(K,J){return function(be){return K(J(be))}}function ar(K){var J=-1,be=Array(K.size);return K.forEach(function(ke){be[++J]=ke}),be}var Ni=Array.prototype,go=Function.prototype,Wo=Object.prototype,ls=_e["__core-js_shared__"],al=go.toString,ce=Wo.hasOwnProperty,Ie=(function(){var K=/[^.]+$/.exec(ls&&ls.keys&&ls.keys.IE_PROTO||"");return K?"Symbol(src)_1."+K:""})(),Xe=Wo.toString,Ot=RegExp("^"+al.call(ce).replace(re,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Gt=Bt?_e.Buffer:void 0,pn=_e.Symbol,kn=_e.Uint8Array,zi=Wo.propertyIsEnumerable,$r=Ni.splice,cs=pn?pn.toStringTag:void 0,ui=Object.getOwnPropertySymbols,us=Gt?Gt.isBuffer:void 0,Xo=ic(Object.keys,Object),Rs=fi(_e,"DataView"),js=fi(_e,"Map"),Ls=fi(_e,"Promise"),Ns=fi(_e,"Set"),sc=fi(_e,"WeakMap"),Zo=fi(Object,"create"),ll=ze(Rs),dp=ze(js),Jd=ze(Ls),ds=ze(Ns),Qd=ze(sc),oc=pn?pn.prototype:void 0,cl=oc?oc.valueOf:void 0;function mo(K){var J=-1,be=K==null?0:K.length;for(this.clear();++J<be;){var ke=K[J];this.set(ke[0],ke[1])}}function eh(){this.__data__=Zo?Zo(null):{},this.size=0}function _r(K){var J=this.has(K)&&delete this.__data__[K];return this.size-=J?1:0,J}function Yn(K){var J=this.__data__;if(Zo){var be=J[K];return be===r?void 0:be}return ce.call(J,K)?J[K]:void 0}function Pr(K){var J=this.__data__;return Zo?J[K]!==void 0:ce.call(J,K)}function xa(K,J){var be=this.__data__;return this.size+=this.has(K)?0:1,be[K]=Zo&&J===void 0?r:J,this}mo.prototype.clear=eh,mo.prototype.delete=_r,mo.prototype.get=Yn,mo.prototype.has=Pr,mo.prototype.set=xa;function Bi(K){var J=-1,be=K==null?0:K.length;for(this.clear();++J<be;){var ke=K[J];this.set(ke[0],ke[1])}}function hp(){this.__data__=[],this.size=0}function ac(K){var J=this.__data__,be=Ln(J,K);if(be<0)return!1;var ke=J.length-1;return be==ke?J.pop():$r.call(J,be,1),--this.size,!0}function th(K){var J=this.__data__,be=Ln(J,K);return be<0?void 0:J[be][1]}function ul(K){return Ln(this.__data__,K)>-1}function hs(K,J){var be=this.__data__,ke=Ln(be,K);return ke<0?(++this.size,be.push([K,J])):be[ke][1]=J,this}Bi.prototype.clear=hp,Bi.prototype.delete=ac,Bi.prototype.get=th,Bi.prototype.has=ul,Bi.prototype.set=hs;function di(K){var J=-1,be=K==null?0:K.length;for(this.clear();++J<be;){var ke=K[J];this.set(ke[0],ke[1])}}function va(){this.size=0,this.__data__={hash:new mo,map:new(js||Bi),string:new mo}}function dl(K){var J=pl(this,K).delete(K);return this.size-=J?1:0,J}function wa(K){return pl(this,K).get(K)}function jn(K){return pl(this,K).has(K)}function nh(K,J){var be=pl(this,K),ke=be.size;return be.set(K,J),this.size+=be.size==ke?0:1,this}di.prototype.clear=va,di.prototype.delete=dl,di.prototype.get=wa,di.prototype.has=jn,di.prototype.set=nh;function yo(K){var J=-1,be=K==null?0:K.length;for(this.__data__=new di;++J<be;)this.add(K[J])}function Jo(K){return this.__data__.set(K,r),this}function Qo(K){return this.__data__.has(K)}yo.prototype.add=yo.prototype.push=Jo,yo.prototype.has=Qo;function So(K){var J=this.__data__=new Bi(K);this.size=J.size}function rh(){this.__data__=new Bi,this.size=0}function ih(K){var J=this.__data__,be=J.delete(K);return this.size=J.size,be}function fp(K){return this.__data__.get(K)}function hl(K){return this.__data__.has(K)}function lc(K,J){var be=this.__data__;if(be instanceof Bi){var ke=be.__data__;if(!js||ke.length<t-1)return ke.push([K,J]),this.size=++be.size,this;be=this.__data__=new di(ke)}return be.set(K,J),this.size=be.size,this}So.prototype.clear=rh,So.prototype.delete=ih,So.prototype.get=fp,So.prototype.has=hl,So.prototype.set=lc;function zs(K,J){var be=an(K),ke=!be&&rt(K),jt=!be&&!ke&&vn(K),ot=!be&&!ke&&!jt&&Tn(K),en=be||ke||jt||ot,lr=en?Er(K.length,String):[],Xn=lr.length;for(var ln in K)ce.call(K,ln)&&!(en&&(ln=="length"||jt&&(ln=="offset"||ln=="parent")||ot&&(ln=="buffer"||ln=="byteLength"||ln=="byteOffset")||Bu(ln,Xn)))&&lr.push(ln);return lr}function Ln(K,J){for(var be=K.length;be--;)if(Qt(K[be][0],J))return be;return-1}function ea(K,J,be){var ke=J(K);return an(K)?ke:Gn(ke,be(K))}function hi(K){return K==null?K===void 0?F:x:cs&&cs in Object(K)?sh(K):Ce(K)}function cc(K){return Cn(K)&&hi(K)==a}function Lu(K,J,be,ke,jt){return K===J?!0:K==null||J==null||!Cn(K)&&!Cn(J)?K!==K&&J!==J:uc(K,J,be,ke,Lu,jt)}function uc(K,J,be,ke,jt,ot){var en=an(K),lr=an(J),Xn=en?l:Fi(K),ln=lr?l:Fi(J);Xn=Xn==a?T:Xn,ln=ln==a?T:ln;var xr=Xn==T,gi=ln==T,vr=Xn==ln;if(vr&&vn(K)){if(!vn(J))return!1;en=!0,xr=!1}if(vr&&!xr)return ot||(ot=new So),en||Tn(K)?Nu(K,J,be,ke,jt,ot):fl(K,J,Xn,be,ke,jt,ot);if(!(be&i)){var ps=xr&&ce.call(K,"__wrapped__"),gs=gi&&ce.call(J,"__wrapped__");if(ps||gs){var Ca=ps?K.value():K,Bs=gs?J.value():J;return ot||(ot=new So),jt(Ca,Bs,be,ke,ot)}}return vr?(ot||(ot=new So),ta(K,J,be,ke,jt,ot)):!1}function pp(K){if(!zn(K)||q(K))return!1;var J=Wn(K)?Ot:le;return J.test(ze(K))}function Nn(K){return Cn(K)&&wn(K.length)&&!!fe[hi(K)]}function dc(K){if(!ie(K))return Xo(K);var J=[];for(var be in Object(K))ce.call(K,be)&&be!="constructor"&&J.push(be);return J}function Nu(K,J,be,ke,jt,ot){var en=be&i,lr=K.length,Xn=J.length;if(lr!=Xn&&!(en&&Xn>lr))return!1;var ln=ot.get(K);if(ln&&ot.get(J))return ln==J;var xr=-1,gi=!0,vr=be&s?new yo:void 0;for(ot.set(K,J),ot.set(J,K);++xr<lr;){var ps=K[xr],gs=J[xr];if(ke)var Ca=en?ke(gs,ps,xr,J,K,ot):ke(ps,gs,xr,K,J,ot);if(Ca!==void 0){if(Ca)continue;gi=!1;break}if(vr){if(!yr(J,function(Bs,gl){if(!li(vr,gl)&&(ps===Bs||jt(ps,Bs,be,ke,ot)))return vr.push(gl)})){gi=!1;break}}else if(!(ps===gs||jt(ps,gs,be,ke,ot))){gi=!1;break}}return ot.delete(K),ot.delete(J),gi}function fl(K,J,be,ke,jt,ot,en){switch(be){case $:if(K.byteLength!=J.byteLength||K.byteOffset!=J.byteOffset)return!1;K=K.buffer,J=J.buffer;case j:return!(K.byteLength!=J.byteLength||!ot(new kn(K),new kn(J)));case f:case h:case w:return Qt(+K,+J);case g:return K.name==J.name&&K.message==J.message;case k:case O:return K==J+"";case v:var lr=ol;case A:var Xn=ke&i;if(lr||(lr=ar),K.size!=J.size&&!Xn)return!1;var ln=en.get(K);if(ln)return ln==J;ke|=s,en.set(K,J);var xr=Nu(lr(K),lr(J),ke,jt,ot,en);return en.delete(K),xr;case R:if(cl)return cl.call(K)==cl.call(J)}return!1}function ta(K,J,be,ke,jt,ot){var en=be&i,lr=zu(K),Xn=lr.length,ln=zu(J),xr=ln.length;if(Xn!=xr&&!en)return!1;for(var gi=Xn;gi--;){var vr=lr[gi];if(!(en?vr in J:ce.call(J,vr)))return!1}var ps=ot.get(K);if(ps&&ot.get(J))return ps==J;var gs=!0;ot.set(K,J),ot.set(J,K);for(var Ca=en;++gi<Xn;){vr=lr[gi];var Bs=K[vr],gl=J[vr];if(ke)var Py=en?ke(gl,Bs,vr,J,K,ot):ke(Bs,gl,vr,K,J,ot);if(!(Py===void 0?Bs===gl||jt(Bs,gl,be,ke,ot):Py)){gs=!1;break}Ca||(Ca=vr=="constructor")}if(gs&&!Ca){var ah=K.constructor,lh=J.constructor;ah!=lh&&"constructor"in K&&"constructor"in J&&!(typeof ah=="function"&&ah instanceof ah&&typeof lh=="function"&&lh instanceof lh)&&(gs=!1)}return ot.delete(K),ot.delete(J),gs}function zu(K){return ea(K,fs,hc)}function pl(K,J){var be=K.__data__;return oh(J)?be[typeof J=="string"?"string":"hash"]:be.map}function fi(K,J){var be=ci(K,J);return pp(be)?be:void 0}function sh(K){var J=ce.call(K,cs),be=K[cs];try{K[cs]=void 0;var ke=!0}catch{}var jt=Xe.call(K);return ke&&(J?K[cs]=be:delete K[cs]),jt}var hc=ui?function(K){return K==null?[]:(K=Object(K),$t(ui(K),function(J){return zi.call(K,J)}))}:pi,Fi=hi;(Rs&&Fi(new Rs(new ArrayBuffer(1)))!=$||js&&Fi(new js)!=v||Ls&&Fi(Ls.resolve())!=P||Ns&&Fi(new Ns)!=A||sc&&Fi(new sc)!=z)&&(Fi=function(K){var J=hi(K),be=J==T?K.constructor:void 0,ke=be?ze(be):"";if(ke)switch(ke){case ll:return $;case dp:return v;case Jd:return P;case ds:return A;case Qd:return z}return J});function Bu(K,J){return J=J??o,!!J&&(typeof K=="number"||Se.test(K))&&K>-1&&K%1==0&&K<J}function oh(K){var J=typeof K;return J=="string"||J=="number"||J=="symbol"||J=="boolean"?K!=="__proto__":K===null}function q(K){return!!Ie&&Ie in K}function ie(K){var J=K&&K.constructor,be=typeof J=="function"&&J.prototype||Wo;return K===be}function Ce(K){return Xe.call(K)}function ze(K){if(K!=null){try{return al.call(K)}catch{}try{return K+""}catch{}}return""}function Qt(K,J){return K===J||K!==K&&J!==J}var rt=cc((function(){return arguments})())?cc:function(K){return Cn(K)&&ce.call(K,"callee")&&!zi.call(K,"callee")},an=Array.isArray;function Sr(K){return K!=null&&wn(K.length)&&!Wn(K)}var vn=us||bo;function br(K,J){return Lu(K,J)}function Wn(K){if(!zn(K))return!1;var J=hi(K);return J==y||J==b||J==u||J==M}function wn(K){return typeof K=="number"&&K>-1&&K%1==0&&K<=o}function zn(K){var J=typeof K;return K!=null&&(J=="object"||J=="function")}function Cn(K){return K!=null&&typeof K=="object"}var Tn=_t?Hr(_t):Nn;function fs(K){return Sr(K)?zs(K):dc(K)}function pi(){return[]}function bo(){return!1}n.exports=br})(Sg,Sg.exports)),Sg.exports}var HX=UX();const vu=Ja(HX);var bg={exports:{}};bg.exports;var fR;function $X(){return fR||(fR=1,(function(n,e){var t=200,r="__lodash_hash_undefined__",i=1,s=2,o=9007199254740991,a="[object Arguments]",l="[object Array]",u="[object Boolean]",f="[object Date]",h="[object Error]",g="[object Function]",y="[object GeneratorFunction]",b="[object Map]",v="[object Number]",w="[object Object]",x="[object Promise]",T="[object RegExp]",P="[object Set]",M="[object String]",k="[object Symbol]",A="[object WeakMap]",O="[object ArrayBuffer]",R="[object DataView]",F="[object Float32Array]",z="[object Float64Array]",j="[object Int8Array]",$="[object Int16Array]",H="[object Int32Array]",B="[object Uint8Array]",G="[object Uint8ClampedArray]",N="[object Uint16Array]",Y="[object Uint32Array]",W=/[\\^$.*+?()[\]{}|]/g,Q=/^\[object .+?Constructor\]$/,de=/^(?:0|[1-9]\d*)$/,U={};U[F]=U[z]=U[j]=U[$]=U[H]=U[B]=U[G]=U[N]=U[Y]=!0,U[a]=U[l]=U[O]=U[u]=U[R]=U[f]=U[h]=U[g]=U[b]=U[v]=U[w]=U[T]=U[P]=U[M]=U[A]=!1;var re=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,le=typeof self=="object"&&self&&self.Object===Object&&self,Se=re||le||Function("return this")(),fe=e&&!e.nodeType&&e,Me=fe&&!0&&n&&!n.nodeType&&n,ve=Me&&Me.exports===fe,_e=ve&&re.process,Oe=(function(){try{return _e&&_e.binding("util")}catch{}})(),He=Oe&&Oe.isTypedArray;function Bt(q,ie){for(var Ce=-1,ze=q?q.length:0;++Ce<ze;)if(ie(q[Ce],Ce,q))return!0;return!1}function qt(q,ie){for(var Ce=-1,ze=Array(q);++Ce<q;)ze[Ce]=ie(Ce);return ze}function At(q){return function(ie){return q(ie)}}function _t(q,ie){return q?.[ie]}function $t(q){var ie=!1;if(q!=null&&typeof q.toString!="function")try{ie=!!(q+"")}catch{}return ie}function Gn(q){var ie=-1,Ce=Array(q.size);return q.forEach(function(ze,Qt){Ce[++ie]=[Qt,ze]}),Ce}function yr(q,ie){return function(Ce){return q(ie(Ce))}}function Er(q){var ie=-1,Ce=Array(q.size);return q.forEach(function(ze){Ce[++ie]=ze}),Ce}var Hr=Array.prototype,li=Function.prototype,ci=Object.prototype,ol=Se["__core-js_shared__"],ic=(function(){var q=/[^.]+$/.exec(ol&&ol.keys&&ol.keys.IE_PROTO||"");return q?"Symbol(src)_1."+q:""})(),ar=li.toString,Ni=ci.hasOwnProperty,go=ci.toString,Wo=RegExp("^"+ar.call(Ni).replace(W,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ls=Se.Symbol,al=Se.Uint8Array,ce=ci.propertyIsEnumerable,Ie=Hr.splice,Xe=yr(Object.keys,Object),Ot=ea(Se,"DataView"),Gt=ea(Se,"Map"),pn=ea(Se,"Promise"),kn=ea(Se,"Set"),zi=ea(Se,"WeakMap"),$r=ea(Object,"create"),cs=Nn(Ot),ui=Nn(Gt),us=Nn(pn),Xo=Nn(kn),Rs=Nn(zi),js=ls?ls.prototype:void 0,Ls=js?js.valueOf:void 0;function Ns(q){var ie=-1,Ce=q?q.length:0;for(this.clear();++ie<Ce;){var ze=q[ie];this.set(ze[0],ze[1])}}function sc(){this.__data__=$r?$r(null):{}}function Zo(q){return this.has(q)&&delete this.__data__[q]}function ll(q){var ie=this.__data__;if($r){var Ce=ie[q];return Ce===r?void 0:Ce}return Ni.call(ie,q)?ie[q]:void 0}function dp(q){var ie=this.__data__;return $r?ie[q]!==void 0:Ni.call(ie,q)}function Jd(q,ie){var Ce=this.__data__;return Ce[q]=$r&&ie===void 0?r:ie,this}Ns.prototype.clear=sc,Ns.prototype.delete=Zo,Ns.prototype.get=ll,Ns.prototype.has=dp,Ns.prototype.set=Jd;function ds(q){var ie=-1,Ce=q?q.length:0;for(this.clear();++ie<Ce;){var ze=q[ie];this.set(ze[0],ze[1])}}function Qd(){this.__data__=[]}function oc(q){var ie=this.__data__,Ce=yo(ie,q);if(Ce<0)return!1;var ze=ie.length-1;return Ce==ze?ie.pop():Ie.call(ie,Ce,1),!0}function cl(q){var ie=this.__data__,Ce=yo(ie,q);return Ce<0?void 0:ie[Ce][1]}function mo(q){return yo(this.__data__,q)>-1}function eh(q,ie){var Ce=this.__data__,ze=yo(Ce,q);return ze<0?Ce.push([q,ie]):Ce[ze][1]=ie,this}ds.prototype.clear=Qd,ds.prototype.delete=oc,ds.prototype.get=cl,ds.prototype.has=mo,ds.prototype.set=eh;function _r(q){var ie=-1,Ce=q?q.length:0;for(this.clear();++ie<Ce;){var ze=q[ie];this.set(ze[0],ze[1])}}function Yn(){this.__data__={hash:new Ns,map:new(Gt||ds),string:new Ns}}function Pr(q){return Ln(this,q).delete(q)}function xa(q){return Ln(this,q).get(q)}function Bi(q){return Ln(this,q).has(q)}function hp(q,ie){return Ln(this,q).set(q,ie),this}_r.prototype.clear=Yn,_r.prototype.delete=Pr,_r.prototype.get=xa,_r.prototype.has=Bi,_r.prototype.set=hp;function ac(q){var ie=-1,Ce=q?q.length:0;for(this.__data__=new _r;++ie<Ce;)this.add(q[ie])}function th(q){return this.__data__.set(q,r),this}function ul(q){return this.__data__.has(q)}ac.prototype.add=ac.prototype.push=th,ac.prototype.has=ul;function hs(q){this.__data__=new ds(q)}function di(){this.__data__=new ds}function va(q){return this.__data__.delete(q)}function dl(q){return this.__data__.get(q)}function wa(q){return this.__data__.has(q)}function jn(q,ie){var Ce=this.__data__;if(Ce instanceof ds){var ze=Ce.__data__;if(!Gt||ze.length<t-1)return ze.push([q,ie]),this;Ce=this.__data__=new _r(ze)}return Ce.set(q,ie),this}hs.prototype.clear=di,hs.prototype.delete=va,hs.prototype.get=dl,hs.prototype.has=wa,hs.prototype.set=jn;function nh(q,ie){var Ce=fl(q)||Nu(q)?qt(q.length,String):[],ze=Ce.length,Qt=!!ze;for(var rt in q)Ni.call(q,rt)&&!(Qt&&(rt=="length"||cc(rt,ze)))&&Ce.push(rt);return Ce}function yo(q,ie){for(var Ce=q.length;Ce--;)if(dc(q[Ce][0],ie))return Ce;return-1}function Jo(q){return go.call(q)}function Qo(q,ie,Ce,ze,Qt){return q===ie?!0:q==null||ie==null||!hc(q)&&!Fi(ie)?q!==q&&ie!==ie:So(q,ie,Qo,Ce,ze,Qt)}function So(q,ie,Ce,ze,Qt,rt){var an=fl(q),Sr=fl(ie),vn=l,br=l;an||(vn=hi(q),vn=vn==a?w:vn),Sr||(br=hi(ie),br=br==a?w:br);var Wn=vn==w&&!$t(q),wn=br==w&&!$t(ie),zn=vn==br;if(zn&&!Wn)return rt||(rt=new hs),an||Bu(q)?hl(q,ie,Ce,ze,Qt,rt):lc(q,ie,vn,Ce,ze,Qt,rt);if(!(Qt&s)){var Cn=Wn&&Ni.call(q,"__wrapped__"),Tn=wn&&Ni.call(ie,"__wrapped__");if(Cn||Tn){var fs=Cn?q.value():q,pi=Tn?ie.value():ie;return rt||(rt=new hs),Ce(fs,pi,ze,Qt,rt)}}return zn?(rt||(rt=new hs),zs(q,ie,Ce,ze,Qt,rt)):!1}function rh(q){if(!hc(q)||uc(q))return!1;var ie=fi(q)||$t(q)?Wo:Q;return ie.test(Nn(q))}function ih(q){return Fi(q)&&sh(q.length)&&!!U[go.call(q)]}function fp(q){if(!pp(q))return Xe(q);var ie=[];for(var Ce in Object(q))Ni.call(q,Ce)&&Ce!="constructor"&&ie.push(Ce);return ie}function hl(q,ie,Ce,ze,Qt,rt){var an=Qt&s,Sr=q.length,vn=ie.length;if(Sr!=vn&&!(an&&vn>Sr))return!1;var br=rt.get(q);if(br&&rt.get(ie))return br==ie;var Wn=-1,wn=!0,zn=Qt&i?new ac:void 0;for(rt.set(q,ie),rt.set(ie,q);++Wn<Sr;){var Cn=q[Wn],Tn=ie[Wn];if(ze)var fs=an?ze(Tn,Cn,Wn,ie,q,rt):ze(Cn,Tn,Wn,q,ie,rt);if(fs!==void 0){if(fs)continue;wn=!1;break}if(zn){if(!Bt(ie,function(pi,bo){if(!zn.has(bo)&&(Cn===pi||Ce(Cn,pi,ze,Qt,rt)))return zn.add(bo)})){wn=!1;break}}else if(!(Cn===Tn||Ce(Cn,Tn,ze,Qt,rt))){wn=!1;break}}return rt.delete(q),rt.delete(ie),wn}function lc(q,ie,Ce,ze,Qt,rt,an){switch(Ce){case R:if(q.byteLength!=ie.byteLength||q.byteOffset!=ie.byteOffset)return!1;q=q.buffer,ie=ie.buffer;case O:return!(q.byteLength!=ie.byteLength||!ze(new al(q),new al(ie)));case u:case f:case v:return dc(+q,+ie);case h:return q.name==ie.name&&q.message==ie.message;case T:case M:return q==ie+"";case b:var Sr=Gn;case P:var vn=rt&s;if(Sr||(Sr=Er),q.size!=ie.size&&!vn)return!1;var br=an.get(q);if(br)return br==ie;rt|=i,an.set(q,ie);var Wn=hl(Sr(q),Sr(ie),ze,Qt,rt,an);return an.delete(q),Wn;case k:if(Ls)return Ls.call(q)==Ls.call(ie)}return!1}function zs(q,ie,Ce,ze,Qt,rt){var an=Qt&s,Sr=oh(q),vn=Sr.length,br=oh(ie),Wn=br.length;if(vn!=Wn&&!an)return!1;for(var wn=vn;wn--;){var zn=Sr[wn];if(!(an?zn in ie:Ni.call(ie,zn)))return!1}var Cn=rt.get(q);if(Cn&&rt.get(ie))return Cn==ie;var Tn=!0;rt.set(q,ie),rt.set(ie,q);for(var fs=an;++wn<vn;){zn=Sr[wn];var pi=q[zn],bo=ie[zn];if(ze)var K=an?ze(bo,pi,zn,ie,q,rt):ze(pi,bo,zn,q,ie,rt);if(!(K===void 0?pi===bo||Ce(pi,bo,ze,Qt,rt):K)){Tn=!1;break}fs||(fs=zn=="constructor")}if(Tn&&!fs){var J=q.constructor,be=ie.constructor;J!=be&&"constructor"in q&&"constructor"in ie&&!(typeof J=="function"&&J instanceof J&&typeof be=="function"&&be instanceof be)&&(Tn=!1)}return rt.delete(q),rt.delete(ie),Tn}function Ln(q,ie){var Ce=q.__data__;return Lu(ie)?Ce[typeof ie=="string"?"string":"hash"]:Ce.map}function ea(q,ie){var Ce=_t(q,ie);return rh(Ce)?Ce:void 0}var hi=Jo;(Ot&&hi(new Ot(new ArrayBuffer(1)))!=R||Gt&&hi(new Gt)!=b||pn&&hi(pn.resolve())!=x||kn&&hi(new kn)!=P||zi&&hi(new zi)!=A)&&(hi=function(q){var ie=go.call(q),Ce=ie==w?q.constructor:void 0,ze=Ce?Nn(Ce):void 0;if(ze)switch(ze){case cs:return R;case ui:return b;case us:return x;case Xo:return P;case Rs:return A}return ie});function cc(q,ie){return ie=ie??o,!!ie&&(typeof q=="number"||de.test(q))&&q>-1&&q%1==0&&q<ie}function Lu(q){var ie=typeof q;return ie=="string"||ie=="number"||ie=="symbol"||ie=="boolean"?q!=="__proto__":q===null}function uc(q){return!!ic&&ic in q}function pp(q){var ie=q&&q.constructor,Ce=typeof ie=="function"&&ie.prototype||ci;return q===Ce}function Nn(q){if(q!=null){try{return ar.call(q)}catch{}try{return q+""}catch{}}return""}function dc(q,ie){return q===ie||q!==q&&ie!==ie}function Nu(q){return zu(q)&&Ni.call(q,"callee")&&(!ce.call(q,"callee")||go.call(q)==a)}var fl=Array.isArray;function ta(q){return q!=null&&sh(q.length)&&!fi(q)}function zu(q){return Fi(q)&&ta(q)}function pl(q,ie,Ce){Ce=typeof Ce=="function"?Ce:void 0;var ze=Ce?Ce(q,ie):void 0;return ze===void 0?Qo(q,ie,Ce):!!ze}function fi(q){var ie=hc(q)?go.call(q):"";return ie==g||ie==y}function sh(q){return typeof q=="number"&&q>-1&&q%1==0&&q<=o}function hc(q){var ie=typeof q;return!!q&&(ie=="object"||ie=="function")}function Fi(q){return!!q&&typeof q=="object"}var Bu=He?At(He):ih;function oh(q){return ta(q)?nh(q):fp(q)}n.exports=pl})(bg,bg.exports)),bg.exports}var KX=$X();const qX=Ja(KX);var lC,pR;function VX(){if(pR)return lC;pR=1;var n="Expected a function",e=NaN,t="[object Symbol]",r=/^\s+|\s+$/g,i=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,o=/^0o[0-7]+$/i,a=parseInt,l=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,u=typeof self=="object"&&self&&self.Object===Object&&self,f=l||u||Function("return this")(),h=Object.prototype,g=h.toString,y=Math.max,b=Math.min,v=function(){return f.Date.now()};function w(A,O,R){var F,z,j,$,H,B,G=0,N=!1,Y=!1,W=!0;if(typeof A!="function")throw new TypeError(n);O=k(O)||0,T(R)&&(N=!!R.leading,Y="maxWait"in R,j=Y?y(k(R.maxWait)||0,O):j,W="trailing"in R?!!R.trailing:W);function Q(_e){var Oe=F,He=z;return F=z=void 0,G=_e,$=A.apply(He,Oe),$}function de(_e){return G=_e,H=setTimeout(le,O),N?Q(_e):$}function U(_e){var Oe=_e-B,He=_e-G,Bt=O-Oe;return Y?b(Bt,j-He):Bt}function re(_e){var Oe=_e-B,He=_e-G;return B===void 0||Oe>=O||Oe<0||Y&&He>=j}function le(){var _e=v();if(re(_e))return Se(_e);H=setTimeout(le,U(_e))}function Se(_e){return H=void 0,W&&F?Q(_e):(F=z=void 0,$)}function fe(){H!==void 0&&clearTimeout(H),G=0,F=B=z=H=void 0}function Me(){return H===void 0?$:Se(v())}function ve(){var _e=v(),Oe=re(_e);if(F=arguments,z=this,B=_e,Oe){if(H===void 0)return de(B);if(Y)return H=setTimeout(le,O),Q(B)}return H===void 0&&(H=setTimeout(le,O)),$}return ve.cancel=fe,ve.flush=Me,ve}function x(A,O,R){var F=!0,z=!0;if(typeof A!="function")throw new TypeError(n);return T(R)&&(F="leading"in R?!!R.leading:F,z="trailing"in R?!!R.trailing:z),w(A,O,{leading:F,maxWait:O,trailing:z})}function T(A){var O=typeof A;return!!A&&(O=="object"||O=="function")}function P(A){return!!A&&typeof A=="object"}function M(A){return typeof A=="symbol"||P(A)&&g.call(A)==t}function k(A){if(typeof A=="number")return A;if(M(A))return e;if(T(A)){var O=typeof A.valueOf=="function"?A.valueOf():A;A=T(O)?O+"":O}if(typeof A!="string")return A===0?A:+A;A=A.replace(r,"");var R=s.test(A);return R||o.test(A)?a(A.slice(2),R?2:8):i.test(A)?e:+A}return lC=x,lC}var GX=VX();const vB=Ja(GX);var cC,gR;function YX(){if(gR)return cC;gR=1;var n=200,e="__lodash_hash_undefined__",t=1/0,r="[object Function]",i="[object GeneratorFunction]",s=/[\\^$.*+?()[\]{}|]/g,o=/^\[object .+?Constructor\]$/,a=typeof Rr=="object"&&Rr&&Rr.Object===Object&&Rr,l=typeof self=="object"&&self&&self.Object===Object&&self,u=a||l||Function("return this")();function f(ce,Ie){var Xe=ce?ce.length:0;return!!Xe&&g(ce,Ie,0)>-1}function h(ce,Ie,Xe,Ot){for(var Gt=ce.length,pn=Xe+-1;++pn<Gt;)if(Ie(ce[pn],pn,ce))return pn;return-1}function g(ce,Ie,Xe){if(Ie!==Ie)return h(ce,y,Xe);for(var Ot=Xe-1,Gt=ce.length;++Ot<Gt;)if(ce[Ot]===Ie)return Ot;return-1}function y(ce){return ce!==ce}function b(ce,Ie){return ce.has(Ie)}function v(ce,Ie){return ce?.[Ie]}function w(ce){var Ie=!1;if(ce!=null&&typeof ce.toString!="function")try{Ie=!!(ce+"")}catch{}return Ie}function x(ce){var Ie=-1,Xe=Array(ce.size);return ce.forEach(function(Ot){Xe[++Ie]=Ot}),Xe}var T=Array.prototype,P=Function.prototype,M=Object.prototype,k=u["__core-js_shared__"],A=(function(){var ce=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||"");return ce?"Symbol(src)_1."+ce:""})(),O=P.toString,R=M.hasOwnProperty,F=M.toString,z=RegExp("^"+O.call(R).replace(s,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),j=T.splice,$=ci(u,"Map"),H=ci(u,"Set"),B=ci(Object,"create");function G(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.clear();++Ie<Xe;){var Ot=ce[Ie];this.set(Ot[0],Ot[1])}}function N(){this.__data__=B?B(null):{}}function Y(ce){return this.has(ce)&&delete this.__data__[ce]}function W(ce){var Ie=this.__data__;if(B){var Xe=Ie[ce];return Xe===e?void 0:Xe}return R.call(Ie,ce)?Ie[ce]:void 0}function Q(ce){var Ie=this.__data__;return B?Ie[ce]!==void 0:R.call(Ie,ce)}function de(ce,Ie){var Xe=this.__data__;return Xe[ce]=B&&Ie===void 0?e:Ie,this}G.prototype.clear=N,G.prototype.delete=Y,G.prototype.get=W,G.prototype.has=Q,G.prototype.set=de;function U(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.clear();++Ie<Xe;){var Ot=ce[Ie];this.set(Ot[0],Ot[1])}}function re(){this.__data__=[]}function le(ce){var Ie=this.__data__,Xe=Gn(Ie,ce);if(Xe<0)return!1;var Ot=Ie.length-1;return Xe==Ot?Ie.pop():j.call(Ie,Xe,1),!0}function Se(ce){var Ie=this.__data__,Xe=Gn(Ie,ce);return Xe<0?void 0:Ie[Xe][1]}function fe(ce){return Gn(this.__data__,ce)>-1}function Me(ce,Ie){var Xe=this.__data__,Ot=Gn(Xe,ce);return Ot<0?Xe.push([ce,Ie]):Xe[Ot][1]=Ie,this}U.prototype.clear=re,U.prototype.delete=le,U.prototype.get=Se,U.prototype.has=fe,U.prototype.set=Me;function ve(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.clear();++Ie<Xe;){var Ot=ce[Ie];this.set(Ot[0],Ot[1])}}function _e(){this.__data__={hash:new G,map:new($||U),string:new G}}function Oe(ce){return li(this,ce).delete(ce)}function He(ce){return li(this,ce).get(ce)}function Bt(ce){return li(this,ce).has(ce)}function qt(ce,Ie){return li(this,ce).set(ce,Ie),this}ve.prototype.clear=_e,ve.prototype.delete=Oe,ve.prototype.get=He,ve.prototype.has=Bt,ve.prototype.set=qt;function At(ce){var Ie=-1,Xe=ce?ce.length:0;for(this.__data__=new ve;++Ie<Xe;)this.add(ce[Ie])}function _t(ce){return this.__data__.set(ce,e),this}function $t(ce){return this.__data__.has(ce)}At.prototype.add=At.prototype.push=_t,At.prototype.has=$t;function Gn(ce,Ie){for(var Xe=ce.length;Xe--;)if(go(ce[Xe][0],Ie))return Xe;return-1}function yr(ce){if(!ls(ce)||ic(ce))return!1;var Ie=Wo(ce)||w(ce)?z:o;return Ie.test(ar(ce))}function Er(ce,Ie,Xe){var Ot=-1,Gt=f,pn=ce.length,kn=!0,zi=[],$r=zi;if(pn>=n){var cs=Hr(ce);if(cs)return x(cs);kn=!1,Gt=b,$r=new At}else $r=zi;e:for(;++Ot<pn;){var ui=ce[Ot],us=ui;if(ui=ui!==0?ui:0,kn&&us===us){for(var Xo=$r.length;Xo--;)if($r[Xo]===us)continue e;zi.push(ui)}else Gt($r,us,Xe)||($r!==zi&&$r.push(us),zi.push(ui))}return zi}var Hr=H&&1/x(new H([,-0]))[1]==t?function(ce){return new H(ce)}:al;function li(ce,Ie){var Xe=ce.__data__;return ol(Ie)?Xe[typeof Ie=="string"?"string":"hash"]:Xe.map}function ci(ce,Ie){var Xe=v(ce,Ie);return yr(Xe)?Xe:void 0}function ol(ce){var Ie=typeof ce;return Ie=="string"||Ie=="number"||Ie=="symbol"||Ie=="boolean"?ce!=="__proto__":ce===null}function ic(ce){return!!A&&A in ce}function ar(ce){if(ce!=null){try{return O.call(ce)}catch{}try{return ce+""}catch{}}return""}function Ni(ce){return ce&&ce.length?Er(ce):[]}function go(ce,Ie){return ce===Ie||ce!==ce&&Ie!==Ie}function Wo(ce){var Ie=ls(ce)?F.call(ce):"";return Ie==r||Ie==i}function ls(ce){var Ie=typeof ce;return!!ce&&(Ie=="object"||Ie=="function")}function al(){}return cC=Ni,cC}var WX=YX();const XX=Ja(WX);function gI(n,e){const t=[];e:for(const r of n){for(const i of t)if(e?e(r,i):r===i)continue e;t.push(r)}return t}function tt(n){return n.filter(e=>e!=null)}function Zr(n){return n[n.length-1]}function wB(n,e){let t,r=1/0;for(const i of n){const s=e(i);s<r&&(t=i,r=s)}return t}function ZX(n,e){let t,r=-1/0;for(const i of n){const s=e(i);s>r&&(t=i,r=s)}return t}function qb(n,e){if(n===e)return!0;if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!Object.is(n[t],e[t]))return!1;return!0}function Fg(n,e,t){const r=new Set(e.map(s=>s[n])),i=[];for(const s of t)r.has(s[n])||i.push(s);for(const s of e)i.push(s);return i}function CB(n){const e=(...t)=>{try{return n(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const om=()=>{},Hi={ok(n){return{ok:!0,value:n}},err(n){return{ok:!1,error:n}}};function kt(n,e){const t=e&&n&&typeof n=="object"&&e in n?n[e]:n;throw new Error(`Unknown switch case ${t}`)}const Be=CB((n,e)=>{if(!n)throw new Error(e||"Assertion Error")}),Mr=CB((n,e)=>{if(n==null)throw new Error(e??"value must be defined");return n});function mI(){let n,e;const t=new Promise((r,i)=>{n=r,e=i});return Object.assign(t,{resolve:n,reject:e})}function D_(n){return new Promise(e=>setTimeout(e,n))}function Is(...n){if(n.length===2){const[e,t]=n;t.addInitializer(function(){Be(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");const i=e.bind(this),s=Reflect.defineProperty(this,t.name,{value:i,writable:!0,configurable:!0});Be(s,"Cannot bind a non-configurable class method.")})}else{const[e,t,r]=n;if(!r||typeof r.value!="function")throw new TypeError(`Only methods can be decorated with @bind. <${t}> is not a method!`);return{configurable:!0,get(){const i=r.value.bind(this);return Object.defineProperty(this,t,{value:i,configurable:!0,writable:!0}),i}}}}class Ii{items=new WeakMap;get(e,t){return this.items.has(e)||this.items.set(e,t(e)),this.items.get(e)}}function Sv(n,e){let t;const r=(...i)=>(t||(t={},t.promise=new Promise((s,o)=>{t.resolve=s,t.reject=o})),clearTimeout(t.timeout),t.latestArgs=i,t.timeout=setTimeout(()=>{const s=t;t=void 0;try{s.resolve(n(...s.latestArgs))}catch(o){s.reject(o)}},e),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const mR=new WeakMap;function yI(n,e){if(typeof n!="object"||n===null)return;let t=mR.get(n);t||(t={tags:{},extras:{}},mR.set(n,t)),e.tags&&(t.tags={...t.tags,...e.tags}),e.extras&&(t.extras={...t.extras,...e.extras})}async function Gl(n,e){return window.fetch(n,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const am=(n,e)=>{const t=new window.Image(n,e);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Ci{static async urlToArrayBuffer(e){return await(await Gl(e)).arrayBuffer()}static async urlToBlob(e){return await(await Gl(e)).blob()}static async urlToDataUrl(e){if(e.startsWith("data:"))return e;const t=await Ci.urlToBlob(e);return await Ci.blobToDataUrl(t)}static async blobToDataUrl(e){return await new Promise((t,r)=>{if(e){const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s=>r(s),i.onabort=s=>r(s),i.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((t,r)=>{if(e){const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s=>r(s),i.onabort=s=>r(s),i.readAsText(e)}})}static rewriteMimeType(e,t){return e.type===t?e:e instanceof File?new File([e],e.name,{type:t}):new Blob([e],{type:t})}}function SI(n){let e=0;for(let t=0;t<n.length;t++)e=(e<<5)-e+n.charCodeAt(t),e|=0;return e+""}function TB(n){const e=new DataView(n);let t=0;for(let r=0;r<e.byteLength;r++)t=(t<<5)-t+e.getUint8(r),t|=0;return t+""}const yR=globalThis.crypto,JX="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",QX=128;let rd,cf;function eZ(n){!rd||rd.length<n?(rd=new Uint8Array(n*QX),yR.getRandomValues(rd),cf=0):cf+n>rd.length&&(yR.getRandomValues(rd),cf=0),cf+=n}function tZ(n=21){eZ(n-=0);let e="";for(let t=cf-n;t<cf;t++)e+=JX[rd[t]&63];return e}let nZ=tZ;function zt(n){return nZ(n)}function rZ(n){const e=new Uint8Array(n);if(!e||!(typeof Buffer<"u"&&Buffer.isBuffer(e)||e instanceof Uint8Array)||e.length<16||!(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10))return!1;function r(s,o,a,l,u=1024){if(!o)return-1;o=new RegExp(o,"g");const f=o.source.length,h=new TextDecoder,g=s.length;if(typeof l>"u"&&(l=g),a>=g||l<=0||a>=l)return-1;s=s.subarray(a,l);let y=-1,b=0,v=0,w="";e:for(;b<s.length;){const x=b+u,T=s.subarray(b,x),P=h.decode(T,{stream:!0}),M=w+P;let k,A=-1;for(;(k=o.exec(M))!==null;){A=k.index-w.length,y=v+A;break e}b=x,v+=P.length;const O=A>-1?A+f:P.length-f;w=P.slice(O)}return y>=0&&(y+=a>=0?a:g+a),y}const i=r(e,"IDAT",12);return i>=12?r(e,"acTL",8,i)>=8:!1}const iZ=n=>new Uint8Array(n)[3]===44;function SR(n,e){let t=0;for(;n[e+t];)t+=n[e+t]+1;return t+1}function sZ(n){return new TextDecoder("ascii").decode(n.slice(0,3))==="GIF"}function oZ(n){const e=new Uint8Array(n);let t,r,i=0,s=0;if(!sZ(n))return!1;for(t=e[10]&128,r=e[10]&7,i+=6,i+=7,i+=t?3*Math.pow(2,r+1):0;s<2&&i<e.length;)switch(e[i]){case 44:s+=1,t=e[i+9]&128,r=e[i+9]&7,i+=10,i+=t?3*Math.pow(2,r+1):0,i+=SR(e,i+1)+1;break;case 33:i+=2,i+=SR(e,i);break;case 59:i=e.length;break;default:i=e.length;break}return s>1}let R_=[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"&&(R_=new Int32Array(R_));const aZ=(n,e)=>{let t=-1;for(let r=0;r<n.length;r++)t=R_[(t^n[r])&255]^t>>>8;return t^-1},bR=4,xR=4;class La{static isPng(e,t){return e.getUint8(t+0)===137&&e.getUint8(t+1)===80&&e.getUint8(t+2)===78&&e.getUint8(t+3)===71&&e.getUint8(t+4)===13&&e.getUint8(t+5)===10&&e.getUint8(t+6)===26&&e.getUint8(t+7)===10}static getChunkType(e,t){return[String.fromCharCode(e.getUint8(t)),String.fromCharCode(e.getUint8(t+1)),String.fromCharCode(e.getUint8(t+2)),String.fromCharCode(e.getUint8(t+3))].join("")}static readChunks(e,t=0){const r={};if(!La.isPng(e,t))throw new Error("Not a PNG");for(t+=8;t<=e.buffer.byteLength;){const i=t,s=e.getInt32(t);t+=4;const o=La.getChunkType(e,t);if(o==="IDAT"&&r[o]){t+=s+bR+xR;continue}if(o==="IEND")break;r[o]={start:i,dataOffset:t+4,size:s},t+=s+bR+xR}return r}static parsePhys(e,t){return{ppux:e.getUint32(t),ppuy:e.getUint32(t+4),unit:e.getUint8(t+8)}}static findChunk(e,t){return La.readChunks(e)[t]}static setPhysChunk(e,t=1,r){let i=46,s=0;const o=La.findChunk(e,"pHYs");o&&(i=o.start,s=o.size);const a=La.findChunk(e,"IDAT");a&&(i=a.start,s=0);const l=new ArrayBuffer(21),u=new DataView(l);u.setUint32(0,9),u.setUint8(4,112),u.setUint8(5,72),u.setUint8(6,89),u.setUint8(7,115);const f=2835.5;u.setInt32(8,f*t),u.setInt32(12,f*t),u.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));u.setInt32(17,aZ(h));const g=e.buffer.slice(0,i),y=e.buffer.slice(i+s);return new Blob([g,l,y],r)}}function lZ(n){return!n||n.length<12?!1:n[8]===87&&n[9]===69&&n[10]===66&&n[11]===80}function cZ(n){const e=new Uint8Array(n);return!lZ(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const EB=Object.freeze(["image/svg+xml"]),_B=Object.freeze(["image/jpeg","image/png","image/webp"]),PB=Object.freeze(["image/gif","image/apng","image/avif"]),Gf=Object.freeze([..._B,...EB,...PB]),bv=Object.freeze(["video/mp4","video/webm","video/quicktime"]),uZ=Object.freeze([...Gf,...bv]);uZ.join(",");class Js{static loadVideo(e){return new Promise((t,r)=>{const i=document.createElement("video");i.onloadeddata=()=>t(i),i.onerror=s=>{console.error(s),r(new Error("Could not load video"))},i.crossOrigin="anonymous",i.src=e})}static async getVideoFrameAsDataUrl(e,t=0){const r=mI();let i=!1;const s=()=>{if(!i)if(e.readyState>=e.HAVE_METADATA)i=!0,e.currentTime=t;else return;if(e.readyState>=e.HAVE_CURRENT_DATA){const a=document.createElement("canvas");a.width=e.videoWidth,a.height=e.videoHeight;const l=a.getContext("2d");if(!l)throw new Error("Could not get 2d context");l.drawImage(e,0,0),r.resolve(a.toDataURL())}},o=a=>{console.error(a),r.reject(new Error("Could not get video frame"))};e.addEventListener("loadedmetadata",s),e.addEventListener("loadeddata",s),e.addEventListener("canplay",s),e.addEventListener("seeked",s),e.addEventListener("error",o),e.addEventListener("stalled",o),s();try{return await r}finally{e.removeEventListener("loadedmetadata",s),e.removeEventListener("loadeddata",s),e.removeEventListener("canplay",s),e.removeEventListener("seeked",s),e.removeEventListener("error",o),e.removeEventListener("stalled",o)}}static getImageAndDimensions(e){return new Promise((t,r)=>{const i=am();i.onload=()=>{let s;i.naturalWidth?s={w:i.naturalWidth,h:i.naturalHeight}:(document.body.appendChild(i),s={w:i.clientWidth,h:i.clientHeight},document.body.removeChild(i)),t({...s,image:i})},i.onerror=s=>{console.error(s),r(new Error("Could not load image"))},i.crossOrigin="anonymous",i.referrerPolicy="strict-origin-when-cross-origin",i.style.visibility="hidden",i.style.position="absolute",i.style.opacity="0",i.style.zIndex="-9999",i.src=e})}static async getVideoSize(e){return Js.usingObjectURL(e,async t=>{const r=await Js.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const{w:t,h:r}=await Js.usingObjectURL(e,Js.getImageAndDimensions);try{if(e.type==="image/png"){const i=new DataView(await e.arrayBuffer());if(La.isPng(i,0)){const s=La.findChunk(i,"pHYs");if(s){const o=La.parsePhys(i,s.dataOffset);if(o.unit===1&&o.ppux===o.ppuy){const l=Math.max(o.ppux/2834.645669291339,1);return{w:Math.round(t/l),h:Math.round(r/l)}}}}}}catch(i){return console.error(i),{w:t,h:r}}return{w:t,h:r}}static async isAnimated(e){return e.type==="image/gif"?oZ(await e.arrayBuffer()):e.type==="image/avif"?iZ(await e.arrayBuffer()):e.type==="image/webp"?cZ(await e.arrayBuffer()):e.type==="image/apng"?rZ(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return PB.includes(e||"")}static isStaticImageType(e){return _B.includes(e||"")}static isVectorImageType(e){return EB.includes(e||"")}static isImageType(e){return Gf.includes(e||"")}static async usingObjectURL(e,t){const r=URL.createObjectURL(e);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function at(n,e,t){return n+(e-n)*t}function lm(n,e,t){return(t-n)/(e-n)}function Ud(n=""){let e=0,t=0,r=0,i=0;function s(){const o=e^e<<11;return e=t,t=r,r=i,i^=(i>>>19^o^o>>>8)>>>0,i/4294967296*2}for(let o=0;o<n.length+64;o++)e^=n.charCodeAt(o)|0,s();return s}function pa(n,e,t,r=!1){const[i,s]=e,[o,a]=t,l=o+(n-i)/(s-i)*(a-o);return r?o<a?Math.max(Math.min(l,a),o):Math.max(Math.min(l,o),a):l}function Fo(n,e){return Object.prototype.hasOwnProperty.call(n,e)}function tr(n,e){if(Fo(n,e))return n[e]}function Ug(n){return Object.keys(n)}function Hn(n){return Object.values(n)}function Yi(n){return Object.entries(n)}function IB(n){return Object.fromEntries(n)}function Hg(n,e){const t={};let r=!1;for(const[i,s]of Yi(n))e(i,s)?t[i]=s:r=!0;return r?t:n}function wu(n,e){const t={};for(const r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=e(r,n[r]));return t}function MB(n,e){if(n===e)return!0;const t=new Set(Object.keys(n)),r=new Set(Object.keys(e));if(t.size!==r.size)return!1;for(const i of t)if(!r.has(i)||!Object.is(n[i],e[i]))return!1;return!0}function dZ(n,e){const t=[];for(const r in n)Object.is(n[r],e[r])||t.push(r);return t}function hZ(n,e,t=1e-6){return qX(n,e,(r,i)=>{if(typeof r=="number"&&typeof i=="number")return Math.abs(r-i)<t})}const xg={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},fZ=xg.Good;class kB{startTime=0;name="";frames=0;started=!1;frame=null;recordFrame=()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))};start(e){this.name=e,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 e=(performance.now()-this.startTime)/1e3,t=e===0?0:Math.floor(this.frames/e),r=t>55?xg.Good:t>30?xg.Mid:xg.Poor,i=r===xg.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${t}%c fps`,`color: white; background: ${fZ};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${r};color: ${i};`,"font-weight: normal")}isStarted(){return this.started}}const AB="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function uf(n,e,t){const r=t[0];if(e!=null&&n>=e)throw new Error(n+" >= "+e);if(n.slice(-1)===r||e&&e.slice(-1)===r)throw new Error("trailing zero");if(e){let o=0;for(;(n[o]||r)===e[o];)o++;if(o>0)return e.slice(0,o)+uf(n.slice(o),e.slice(o),t)}const i=n?t.indexOf(n[0]):0,s=e!=null?t.indexOf(e[0]):t.length;if(s-i>1){const o=Math.round(.5*(i+s));return t[o]}else return e&&e.length>1?e.slice(0,1):t[i]+uf(n.slice(1),null,t)}function OB(n){if(n.length!==DB(n[0]))throw new Error("invalid integer part of order key: "+n)}function DB(n){if(n>="a"&&n<="z")return n.charCodeAt(0)-97+2;if(n>="A"&&n<="Z")return 90-n.charCodeAt(0)+2;throw new Error("invalid order key head: "+n)}function vg(n){const e=DB(n[0]);if(e>n.length)throw new Error("invalid order key: "+n);return n.slice(0,e)}function vR(n,e){if(n==="A"+e[0].repeat(26))throw new Error("invalid order key: "+n);const t=vg(n);if(n.slice(t.length).slice(-1)===e[0])throw new Error("invalid order key: "+n)}function wR(n,e){OB(n);const[t,...r]=n.split("");let i=!0;for(let s=r.length-1;i&&s>=0;s--){const o=e.indexOf(r[s])+1;o===e.length?r[s]=e[0]:(r[s]=e[o],i=!1)}if(i){if(t==="Z")return"a"+e[0];if(t==="z")return null;const s=String.fromCharCode(t.charCodeAt(0)+1);return s>"a"?r.push(e[0]):r.pop(),s+r.join("")}else return t+r.join("")}function pZ(n,e){OB(n);const[t,...r]=n.split("");let i=!0;for(let s=r.length-1;i&&s>=0;s--){const o=e.indexOf(r[s])-1;o===-1?r[s]=e.slice(-1):(r[s]=e[o],i=!1)}if(i){if(t==="a")return"Z"+e.slice(-1);if(t==="A")return null;const s=String.fromCharCode(t.charCodeAt(0)-1);return s<"Z"?r.push(e.slice(-1)):r.pop(),s+r.join("")}else return t+r.join("")}function Vc(n,e,t=AB){if(n!=null&&vR(n,t),e!=null&&vR(e,t),n!=null&&e!=null&&n>=e)throw new Error(n+" >= "+e);if(n==null){if(e==null)return"a"+t[0];const l=vg(e),u=e.slice(l.length);if(l==="A"+t[0].repeat(26))return l+uf("",u,t);if(l<e)return l;const f=pZ(l,t);if(f==null)throw new Error("cannot decrement any more");return f}if(e==null){const l=vg(n),u=n.slice(l.length),f=wR(l,t);return f??l+uf(u,null,t)}const r=vg(n),i=n.slice(r.length),s=vg(e),o=e.slice(s.length);if(r===s)return r+uf(i,o,t);const a=wR(r,t);if(a==null)throw new Error("cannot increment any more");return a<e?a:r+uf(i,null,t)}function Vb(n,e,t,r=AB){if(t===0)return[];if(t===1)return[Vc(n,e,r)];if(e==null){let o=Vc(n,e,r);const a=[o];for(let l=0;l<t-1;l++)o=Vc(o,e,r),a.push(o);return a}if(n==null){let o=Vc(n,e,r);const a=[o];for(let l=0;l<t-1;l++)o=Vc(n,o,r),a.push(o);return a.reverse(),a}const i=Math.floor(t/2),s=Vc(n,e,r);return[...Vb(n,s,i,r),s,...Vb(s,e,t-i-1,r)]}const gZ=30,mZ=()=>Math.random()<.5;function RB(n,e){if(!Number.isInteger(e))throw new Error(`"${n}" must be an integer, got '${e}'`);if(e<0)throw new Error(`"${n}" must be greater than or equal to 0, got '${e}'`)}function jB(n,e,t){const{digits:r,jitterBits:i=gZ,getRandomBit:s=mZ}=t??{};RB("jitterBits",i);let o=i,a=n,l=e,u=Vc(n,e,r);for(;o>0;)(s()?1:0)===1?a=u:l=u,u=Vc(a,l,r),o--;return u}function yZ(n,e,t,r){const{digits:i,jitterBits:s}=r??{};if(RB("n",t),t===0)return[];if(s===0)return Vb(n,e,t,i);const o=Vb(n,e,t+1,i),a=[];for(let l=0;l<t;l++){const u=o[l],f=o[l+1];a.push(jB(u,f,r))}return a}const Yf=yZ,bI="a0";function SZ(n){try{jB(n,null)}catch{throw new Error("invalid index: "+n)}}function vd(n,e,t){return Yf(n??null,e??null,t)}function uC(n,e){return Yf(n??null,null,e)}function Mf(n,e){return Yf(n??null,e??null,1)[0]}function Lo(n=null){return Yf(n,null,1)[0]}function bZ(n=null){return Yf(null,n,1)[0]}function cm(n,e="a1"){return[e,...Yf(e,null,n)]}function kr(n,e){return n.index<e.index?-1:n.index>e.index?1:0}function xZ(n,e){return n.id>e.id?1:-1}function xI(n){try{return localStorage.getItem(n)}catch{return null}}function vI(n,e){try{localStorage.setItem(n,e)}catch{}}function vZ(){try{localStorage.clear()}catch{}}function LB(n){try{return sessionStorage.getItem(n)}catch{return null}}function wI(n,e){try{sessionStorage.setItem(n,e)}catch{}}function NB(n){try{sessionStorage.removeItem(n)}catch{}}function wZ(){try{sessionStorage.clear()}catch{}}const df=[],CZ=60,zB=Math.floor(1e3/CZ)*.9;let dC,AS,hC=-zB;const CR=()=>{const n=df.splice(0,df.length);for(const e of n)e()};function BB(n=!1){if(dC)return;const e=Date.now();if(e-hC<zB){dC=requestAnimationFrame(()=>{dC=void 0,BB(!0)});return}if(n){if(AS)return;hC=e,CR()}else{if(AS)return;AS=requestAnimationFrame(()=>{AS=void 0,hC=e,CR()})}}function CI(n){return df.includes(n)||(df.push(n),BB()),()=>{const e=df.indexOf(n);e>-1&&df.splice(e,1)}}class TZ{timeouts=new Map;intervals=new Map;rafs=new Map;constructor(){this.setTimeout=this.setTimeout.bind(this),this.setInterval=this.setInterval.bind(this),this.requestAnimationFrame=this.requestAnimationFrame.bind(this),this.dispose=this.dispose.bind(this)}setTimeout(e,t,r,...i){const s=window.setTimeout(t,r,i),o=this.timeouts.get(e)??[];return this.timeouts.set(e,[...o,s]),s}setInterval(e,t,r,...i){const s=window.setInterval(t,r,i),o=this.intervals.get(e)??[];return this.intervals.set(e,[...o,s]),s}requestAnimationFrame(e,t){const r=window.requestAnimationFrame(t),i=this.rafs.get(e)??[];return this.rafs.set(e,[...i,r]),r}dispose(e){this.timeouts.get(e)?.forEach(t=>clearTimeout(t)),this.intervals.get(e)?.forEach(t=>clearInterval(t)),this.rafs.get(e)?.forEach(t=>cancelAnimationFrame(t)),this.timeouts.delete(e),this.intervals.delete(e),this.rafs.delete(e)}disposeAll(){for(const e of this.timeouts.keys())this.dispose(e)}forContext(e){return{setTimeout:(t,r,...i)=>this.setTimeout(e,t,r,i),setInterval:(t,r,...i)=>this.setInterval(e,t,r,i),requestAnimationFrame:t=>this.requestAnimationFrame(e,t),dispose:()=>this.dispose(e)}}}const it=(n,e)=>{try{return new URL(n,e)}catch{return}};function EZ(n){return n!==void 0}function _Z(){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]:[n=>n&&JSON.parse(JSON.stringify(n)),!1]}const FB=_Z(),Qn=FB[0];FB[1];const PZ=Object.getPrototypeOf(Qn({})),TR=new Set;function IZ(n){TR.has(n)||(TR.add(n),console.warn(`[tldraw] ${n}`))}xu("@tldraw/utils","4.1.2","esm");var ER={},eg,_R;function Mi(){if(_R)return eg;_R=1;var n=function(e){return e&&e.Math===Math&&e};return eg=n(typeof globalThis=="object"&&globalThis)||n(typeof window=="object"&&window)||n(typeof self=="object"&&self)||n(typeof Rr=="object"&&Rr)||n(typeof eg=="object"&&eg)||(function(){return this})()||Function("return this")(),eg}var fC={},pC,PR;function ki(){return PR||(PR=1,pC=function(n){try{return!!n()}catch{return!0}}),pC}var gC,IR;function Cu(){if(IR)return gC;IR=1;var n=ki();return gC=!n(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),gC}var mC,MR;function xv(){if(MR)return mC;MR=1;var n=ki();return mC=!n(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),mC}var yC,kR;function Jl(){if(kR)return yC;kR=1;var n=xv(),e=Function.prototype.call;return yC=n?e.bind(e):function(){return e.apply(e,arguments)},yC}var SC={},AR;function MZ(){if(AR)return SC;AR=1;var n={}.propertyIsEnumerable,e=Object.getOwnPropertyDescriptor,t=e&&!n.call({1:2},1);return SC.f=t?function(i){var s=e(this,i);return!!s&&s.enumerable}:n,SC}var bC,OR;function UB(){return OR||(OR=1,bC=function(n,e){return{enumerable:!(n&1),configurable:!(n&2),writable:!(n&4),value:e}}),bC}var xC,DR;function Br(){if(DR)return xC;DR=1;var n=xv(),e=Function.prototype,t=e.call,r=n&&e.bind.bind(t,t);return xC=n?r:function(i){return function(){return t.apply(i,arguments)}},xC}var vC,RR;function Wf(){if(RR)return vC;RR=1;var n=Br(),e=n({}.toString),t=n("".slice);return vC=function(r){return t(e(r),8,-1)},vC}var wC,jR;function kZ(){if(jR)return wC;jR=1;var n=Br(),e=ki(),t=Wf(),r=Object,i=n("".split);return wC=e(function(){return!r("z").propertyIsEnumerable(0)})?function(s){return t(s)==="String"?i(s,""):r(s)}:r,wC}var CC,LR;function HB(){return LR||(LR=1,CC=function(n){return n==null}),CC}var TC,NR;function Xf(){if(NR)return TC;NR=1;var n=HB(),e=TypeError;return TC=function(t){if(n(t))throw new e("Can't call method on "+t);return t},TC}var EC,zR;function vv(){if(zR)return EC;zR=1;var n=kZ(),e=Xf();return EC=function(t){return n(e(t))},EC}var _C,BR;function is(){if(BR)return _C;BR=1;var n=typeof document=="object"&&document.all;return _C=typeof n>"u"&&n!==void 0?function(e){return typeof e=="function"||e===n}:function(e){return typeof e=="function"},_C}var PC,FR;function Ql(){if(FR)return PC;FR=1;var n=is();return PC=function(e){return typeof e=="object"?e!==null:n(e)},PC}var IC,UR;function wv(){if(UR)return IC;UR=1;var n=Mi(),e=is(),t=function(r){return e(r)?r:void 0};return IC=function(r,i){return arguments.length<2?t(n[r]):n[r]&&n[r][i]},IC}var MC,HR;function $B(){if(HR)return MC;HR=1;var n=Br();return MC=n({}.isPrototypeOf),MC}var kC,$R;function AZ(){if($R)return kC;$R=1;var n=Mi(),e=n.navigator,t=e&&e.userAgent;return kC=t?String(t):"",kC}var AC,KR;function OZ(){if(KR)return AC;KR=1;var n=Mi(),e=AZ(),t=n.process,r=n.Deno,i=t&&t.versions||r&&r.version,s=i&&i.v8,o,a;return s&&(o=s.split("."),a=o[0]>0&&o[0]<4?1:+(o[0]+o[1])),!a&&e&&(o=e.match(/Edge\/(\d+)/),(!o||o[1]>=74)&&(o=e.match(/Chrome\/(\d+)/),o&&(a=+o[1]))),AC=a,AC}var OC,qR;function KB(){if(qR)return OC;qR=1;var n=OZ(),e=ki(),t=Mi(),r=t.String;return OC=!!Object.getOwnPropertySymbols&&!e(function(){var i=Symbol("symbol detection");return!r(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&n&&n<41}),OC}var DC,VR;function qB(){if(VR)return DC;VR=1;var n=KB();return DC=n&&!Symbol.sham&&typeof Symbol.iterator=="symbol",DC}var RC,GR;function VB(){if(GR)return RC;GR=1;var n=wv(),e=is(),t=$B(),r=qB(),i=Object;return RC=r?function(s){return typeof s=="symbol"}:function(s){var o=n("Symbol");return e(o)&&t(o.prototype,i(s))},RC}var jC,YR;function DZ(){if(YR)return jC;YR=1;var n=String;return jC=function(e){try{return n(e)}catch{return"Object"}},jC}var LC,WR;function TI(){if(WR)return LC;WR=1;var n=is(),e=DZ(),t=TypeError;return LC=function(r){if(n(r))return r;throw new t(e(r)+" is not a function")},LC}var NC,XR;function EI(){if(XR)return NC;XR=1;var n=TI(),e=HB();return NC=function(t,r){var i=t[r];return e(i)?void 0:n(i)},NC}var zC,ZR;function RZ(){if(ZR)return zC;ZR=1;var n=Jl(),e=is(),t=Ql(),r=TypeError;return zC=function(i,s){var o,a;if(s==="string"&&e(o=i.toString)&&!t(a=n(o,i))||e(o=i.valueOf)&&!t(a=n(o,i))||s!=="string"&&e(o=i.toString)&&!t(a=n(o,i)))return a;throw new r("Can't convert object to primitive value")},zC}var BC={exports:{}},FC,JR;function GB(){return JR||(JR=1,FC=!1),FC}var UC,QR;function _I(){if(QR)return UC;QR=1;var n=Mi(),e=Object.defineProperty;return UC=function(t,r){try{e(n,t,{value:r,configurable:!0,writable:!0})}catch{n[t]=r}return r},UC}var ej;function PI(){if(ej)return BC.exports;ej=1;var n=GB(),e=Mi(),t=_I(),r="__core-js_shared__",i=BC.exports=e[r]||t(r,{});return(i.versions||(i.versions=[])).push({version:"3.46.0",mode:n?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru), 2025 CoreJS Company (core-js.io)",license:"https://github.com/zloirock/core-js/blob/v3.46.0/LICENSE",source:"https://github.com/zloirock/core-js"}),BC.exports}var HC,tj;function II(){if(tj)return HC;tj=1;var n=PI();return HC=function(e,t){return n[e]||(n[e]=t||{})},HC}var $C,nj;function $m(){if(nj)return $C;nj=1;var n=Xf(),e=Object;return $C=function(t){return e(n(t))},$C}var KC,rj;function Tu(){if(rj)return KC;rj=1;var n=Br(),e=$m(),t=n({}.hasOwnProperty);return KC=Object.hasOwn||function(i,s){return t(e(i),s)},KC}var qC,ij;function YB(){if(ij)return qC;ij=1;var n=Br(),e=0,t=Math.random(),r=n(1.1.toString);return qC=function(i){return"Symbol("+(i===void 0?"":i)+")_"+r(++e+t,36)},qC}var VC,sj;function ec(){if(sj)return VC;sj=1;var n=Mi(),e=II(),t=Tu(),r=YB(),i=KB(),s=qB(),o=n.Symbol,a=e("wks"),l=s?o.for||o:o&&o.withoutSetter||r;return VC=function(u){return t(a,u)||(a[u]=i&&t(o,u)?o[u]:l("Symbol."+u)),a[u]},VC}var GC,oj;function jZ(){if(oj)return GC;oj=1;var n=Jl(),e=Ql(),t=VB(),r=EI(),i=RZ(),s=ec(),o=TypeError,a=s("toPrimitive");return GC=function(l,u){if(!e(l)||t(l))return l;var f=r(l,a),h;if(f){if(u===void 0&&(u="default"),h=n(f,l,u),!e(h)||t(h))return h;throw new o("Can't convert object to primitive value")}return u===void 0&&(u="number"),i(l,u)},GC}var YC,aj;function WB(){if(aj)return YC;aj=1;var n=jZ(),e=VB();return YC=function(t){var r=n(t,"string");return e(r)?r:r+""},YC}var WC,lj;function XB(){if(lj)return WC;lj=1;var n=Mi(),e=Ql(),t=n.document,r=e(t)&&e(t.createElement);return WC=function(i){return r?t.createElement(i):{}},WC}var XC,cj;function ZB(){if(cj)return XC;cj=1;var n=Cu(),e=ki(),t=XB();return XC=!n&&!e(function(){return Object.defineProperty(t("div"),"a",{get:function(){return 7}}).a!==7}),XC}var uj;function JB(){if(uj)return fC;uj=1;var n=Cu(),e=Jl(),t=MZ(),r=UB(),i=vv(),s=WB(),o=Tu(),a=ZB(),l=Object.getOwnPropertyDescriptor;return fC.f=n?l:function(f,h){if(f=i(f),h=s(h),a)try{return l(f,h)}catch{}if(o(f,h))return r(!e(t.f,f,h),f[h])},fC}var ZC={},JC,dj;function QB(){if(dj)return JC;dj=1;var n=Cu(),e=ki();return JC=n&&e(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),JC}var QC,hj;function Hd(){if(hj)return QC;hj=1;var n=Ql(),e=String,t=TypeError;return QC=function(r){if(n(r))return r;throw new t(e(r)+" is not an object")},QC}var fj;function Km(){if(fj)return ZC;fj=1;var n=Cu(),e=ZB(),t=QB(),r=Hd(),i=WB(),s=TypeError,o=Object.defineProperty,a=Object.getOwnPropertyDescriptor,l="enumerable",u="configurable",f="writable";return ZC.f=n?t?function(g,y,b){if(r(g),y=i(y),r(b),typeof g=="function"&&y==="prototype"&&"value"in b&&f in b&&!b[f]){var v=a(g,y);v&&v[f]&&(g[y]=b.value,b={configurable:u in b?b[u]:v[u],enumerable:l in b?b[l]:v[l],writable:!1})}return o(g,y,b)}:o:function(g,y,b){if(r(g),y=i(y),r(b),e)try{return o(g,y,b)}catch{}if("get"in b||"set"in b)throw new s("Accessors not supported");return"value"in b&&(g[y]=b.value),g},ZC}var eT,pj;function MI(){if(pj)return eT;pj=1;var n=Cu(),e=Km(),t=UB();return eT=n?function(r,i,s){return e.f(r,i,t(1,s))}:function(r,i,s){return r[i]=s,r},eT}var tT={exports:{}},nT,gj;function LZ(){if(gj)return nT;gj=1;var n=Cu(),e=Tu(),t=Function.prototype,r=n&&Object.getOwnPropertyDescriptor,i=e(t,"name"),s=i&&(function(){}).name==="something",o=i&&(!n||n&&r(t,"name").configurable);return nT={EXISTS:i,PROPER:s,CONFIGURABLE:o},nT}var rT,mj;function e4(){if(mj)return rT;mj=1;var n=Br(),e=is(),t=PI(),r=n(Function.toString);return e(t.inspectSource)||(t.inspectSource=function(i){return r(i)}),rT=t.inspectSource,rT}var iT,yj;function NZ(){if(yj)return iT;yj=1;var n=Mi(),e=is(),t=n.WeakMap;return iT=e(t)&&/native code/.test(String(t)),iT}var sT,Sj;function t4(){if(Sj)return sT;Sj=1;var n=II(),e=YB(),t=n("keys");return sT=function(r){return t[r]||(t[r]=e(r))},sT}var oT,bj;function kI(){return bj||(bj=1,oT={}),oT}var aT,xj;function n4(){if(xj)return aT;xj=1;var n=NZ(),e=Mi(),t=Ql(),r=MI(),i=Tu(),s=PI(),o=t4(),a=kI(),l="Object already initialized",u=e.TypeError,f=e.WeakMap,h,g,y,b=function(T){return y(T)?g(T):h(T,{})},v=function(T){return function(P){var M;if(!t(P)||(M=g(P)).type!==T)throw new u("Incompatible receiver, "+T+" required");return M}};if(n||s.state){var w=s.state||(s.state=new f);w.get=w.get,w.has=w.has,w.set=w.set,h=function(T,P){if(w.has(T))throw new u(l);return P.facade=T,w.set(T,P),P},g=function(T){return w.get(T)||{}},y=function(T){return w.has(T)}}else{var x=o("state");a[x]=!0,h=function(T,P){if(i(T,x))throw new u(l);return P.facade=T,r(T,x,P),P},g=function(T){return i(T,x)?T[x]:{}},y=function(T){return i(T,x)}}return aT={set:h,get:g,has:y,enforce:b,getterFor:v},aT}var vj;function zZ(){if(vj)return tT.exports;vj=1;var n=Br(),e=ki(),t=is(),r=Tu(),i=Cu(),s=LZ().CONFIGURABLE,o=e4(),a=n4(),l=a.enforce,u=a.get,f=String,h=Object.defineProperty,g=n("".slice),y=n("".replace),b=n([].join),v=i&&!e(function(){return h(function(){},"length",{value:8}).length!==8}),w=String(String).split("String"),x=tT.exports=function(T,P,M){g(f(P),0,7)==="Symbol("&&(P="["+y(f(P),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),M&&M.getter&&(P="get "+P),M&&M.setter&&(P="set "+P),(!r(T,"name")||s&&T.name!==P)&&(i?h(T,"name",{value:P,configurable:!0}):T.name=P),v&&M&&r(M,"arity")&&T.length!==M.arity&&h(T,"length",{value:M.arity});try{M&&r(M,"constructor")&&M.constructor?i&&h(T,"prototype",{writable:!1}):T.prototype&&(T.prototype=void 0)}catch{}var k=l(T);return r(k,"source")||(k.source=b(w,typeof P=="string"?P:"")),T};return Function.prototype.toString=x(function(){return t(this)&&u(this).source||o(this)},"toString"),tT.exports}var lT,wj;function r4(){if(wj)return lT;wj=1;var n=is(),e=Km(),t=zZ(),r=_I();return lT=function(i,s,o,a){a||(a={});var l=a.enumerable,u=a.name!==void 0?a.name:s;if(n(o)&&t(o,u,a),a.global)l?i[s]=o:r(s,o);else{try{a.unsafe?i[s]&&(l=!0):delete i[s]}catch{}l?i[s]=o:e.f(i,s,{value:o,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return i},lT}var cT={},uT,Cj;function BZ(){if(Cj)return uT;Cj=1;var n=Math.ceil,e=Math.floor;return uT=Math.trunc||function(r){var i=+r;return(i>0?e:n)(i)},uT}var dT,Tj;function $d(){if(Tj)return dT;Tj=1;var n=BZ();return dT=function(e){var t=+e;return t!==t||t===0?0:n(t)},dT}var hT,Ej;function FZ(){if(Ej)return hT;Ej=1;var n=$d(),e=Math.max,t=Math.min;return hT=function(r,i){var s=n(r);return s<0?e(s+i,0):t(s,i)},hT}var fT,_j;function i4(){if(_j)return fT;_j=1;var n=$d(),e=Math.min;return fT=function(t){var r=n(t);return r>0?e(r,9007199254740991):0},fT}var pT,Pj;function qm(){if(Pj)return pT;Pj=1;var n=i4();return pT=function(e){return n(e.length)},pT}var gT,Ij;function UZ(){if(Ij)return gT;Ij=1;var n=vv(),e=FZ(),t=qm(),r=function(i){return function(s,o,a){var l=n(s),u=t(l);if(u===0)return!i&&-1;var f=e(a,u),h;if(i&&o!==o){for(;u>f;)if(h=l[f++],h!==h)return!0}else for(;u>f;f++)if((i||f in l)&&l[f]===o)return i||f||0;return!i&&-1}};return gT={includes:r(!0),indexOf:r(!1)},gT}var mT,Mj;function s4(){if(Mj)return mT;Mj=1;var n=Br(),e=Tu(),t=vv(),r=UZ().indexOf,i=kI(),s=n([].push);return mT=function(o,a){var l=t(o),u=0,f=[],h;for(h in l)!e(i,h)&&e(l,h)&&s(f,h);for(;a.length>u;)e(l,h=a[u++])&&(~r(f,h)||s(f,h));return f},mT}var yT,kj;function AI(){return kj||(kj=1,yT=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]),yT}var Aj;function HZ(){if(Aj)return cT;Aj=1;var n=s4(),e=AI(),t=e.concat("length","prototype");return cT.f=Object.getOwnPropertyNames||function(i){return n(i,t)},cT}var ST={},Oj;function $Z(){return Oj||(Oj=1,ST.f=Object.getOwnPropertySymbols),ST}var bT,Dj;function KZ(){if(Dj)return bT;Dj=1;var n=wv(),e=Br(),t=HZ(),r=$Z(),i=Hd(),s=e([].concat);return bT=n("Reflect","ownKeys")||function(a){var l=t.f(i(a)),u=r.f;return u?s(l,u(a)):l},bT}var xT,Rj;function qZ(){if(Rj)return xT;Rj=1;var n=Tu(),e=KZ(),t=JB(),r=Km();return xT=function(i,s,o){for(var a=e(s),l=r.f,u=t.f,f=0;f<a.length;f++){var h=a[f];!n(i,h)&&!(o&&n(o,h))&&l(i,h,u(s,h))}},xT}var vT,jj;function VZ(){if(jj)return vT;jj=1;var n=ki(),e=is(),t=/#|\.prototype\./,r=function(l,u){var f=s[i(l)];return f===a?!0:f===o?!1:e(u)?n(u):!!u},i=r.normalize=function(l){return String(l).replace(t,".").toLowerCase()},s=r.data={},o=r.NATIVE="N",a=r.POLYFILL="P";return vT=r,vT}var wT,Lj;function Zf(){if(Lj)return wT;Lj=1;var n=Mi(),e=JB().f,t=MI(),r=r4(),i=_I(),s=qZ(),o=VZ();return wT=function(a,l){var u=a.target,f=a.global,h=a.stat,g,y,b,v,w,x;if(f?y=n:h?y=n[u]||i(u,{}):y=n[u]&&n[u].prototype,y)for(b in l){if(w=l[b],a.dontCallGetSet?(x=e(y,b),v=x&&x.value):v=y[b],g=o(f?b:u+(h?".":"#")+b,a.forced),!g&&v!==void 0){if(typeof w==typeof v)continue;s(w,v)}(a.sham||v&&v.sham)&&t(w,"sham",!0),r(y,b,w,a)}},wT}var CT={},TT,Nj;function GZ(){if(Nj)return TT;Nj=1;var n=s4(),e=AI();return TT=Object.keys||function(r){return n(r,e)},TT}var zj;function YZ(){if(zj)return CT;zj=1;var n=Cu(),e=QB(),t=Km(),r=Hd(),i=vv(),s=GZ();return CT.f=n&&!e?Object.defineProperties:function(a,l){r(a);for(var u=i(l),f=s(l),h=f.length,g=0,y;h>g;)t.f(a,y=f[g++],u[y]);return a},CT}var ET,Bj;function WZ(){if(Bj)return ET;Bj=1;var n=wv();return ET=n("document","documentElement"),ET}var _T,Fj;function o4(){if(Fj)return _T;Fj=1;var n=Hd(),e=YZ(),t=AI(),r=kI(),i=WZ(),s=XB(),o=t4(),a=">",l="<",u="prototype",f="script",h=o("IE_PROTO"),g=function(){},y=function(T){return l+f+a+T+l+"/"+f+a},b=function(T){T.write(y("")),T.close();var P=T.parentWindow.Object;return T=null,P},v=function(){var T=s("iframe"),P="java"+f+":",M;return T.style.display="none",i.appendChild(T),T.src=String(P),M=T.contentWindow.document,M.open(),M.write(y("document.F=Object")),M.close(),M.F},w,x=function(){try{w=new ActiveXObject("htmlfile")}catch{}x=typeof document<"u"?document.domain&&w?b(w):v():b(w);for(var T=t.length;T--;)delete x[u][t[T]];return x()};return r[h]=!0,_T=Object.create||function(P,M){var k;return P!==null?(g[u]=n(P),k=new g,g[u]=null,k[h]=P):k=x(),M===void 0?k:e.f(k,M)},_T}var PT,Uj;function OI(){if(Uj)return PT;Uj=1;var n=ec(),e=o4(),t=Km().f,r=n("unscopables"),i=Array.prototype;return i[r]===void 0&&t(i,r,{configurable:!0,value:e(null)}),PT=function(s){i[r][s]=!0},PT}var Hj;function XZ(){if(Hj)return ER;Hj=1;var n=Zf(),e=$m(),t=qm(),r=$d(),i=OI();return n({target:"Array",proto:!0},{at:function(o){var a=e(this),l=t(a),u=r(o),f=u>=0?u:l+u;return f<0||f>=l?void 0:a[f]}}),i("at"),ER}var IT,$j;function Vm(){if($j)return IT;$j=1;var n=Mi(),e=Br();return IT=function(t,r){return e(n[t].prototype[r])},IT}var MT,Kj;function ZZ(){if(Kj)return MT;Kj=1,XZ();var n=Vm();return MT=n("Array","at"),MT}var kT,qj;function JZ(){if(qj)return kT;qj=1;var n=ZZ();return kT=n,kT}JZ();var Vj={},AT,Gj;function a4(){if(Gj)return AT;Gj=1;var n=Wf();return AT=Array.isArray||function(t){return n(t)==="Array"},AT}var OT,Yj;function QZ(){if(Yj)return OT;Yj=1;var n=TypeError,e=9007199254740991;return OT=function(t){if(t>e)throw n("Maximum allowed index exceeded");return t},OT}var DT,Wj;function eJ(){if(Wj)return DT;Wj=1;var n=Wf(),e=Br();return DT=function(t){if(n(t)==="Function")return e(t)},DT}var RT,Xj;function tJ(){if(Xj)return RT;Xj=1;var n=eJ(),e=TI(),t=xv(),r=n(n.bind);return RT=function(i,s){return e(i),s===void 0?i:t?r(i,s):function(){return i.apply(s,arguments)}},RT}var jT,Zj;function l4(){if(Zj)return jT;Zj=1;var n=a4(),e=qm(),t=QZ(),r=tJ(),i=function(s,o,a,l,u,f,h,g){for(var y=u,b=0,v=h?r(h,g):!1,w,x;b<l;)b in a&&(w=v?v(a[b],b,o):a[b],f>0&&n(w)?(x=e(w),y=i(s,o,w,x,y,f-1)-1):(t(y+1),s[y]=w),y++),b++;return y};return jT=i,jT}var LT,Jj;function nJ(){if(Jj)return LT;Jj=1;var n=ec(),e=n("toStringTag"),t={};return t[e]="z",LT=String(t)==="[object z]",LT}var NT,Qj;function c4(){if(Qj)return NT;Qj=1;var n=nJ(),e=is(),t=Wf(),r=ec(),i=r("toStringTag"),s=Object,o=t((function(){return arguments})())==="Arguments",a=function(l,u){try{return l[u]}catch{}};return NT=n?t:function(l){var u,f,h;return l===void 0?"Undefined":l===null?"Null":typeof(f=a(u=s(l),i))=="string"?f:o?t(u):(h=t(u))==="Object"&&e(u.callee)?"Arguments":h},NT}var zT,eL;function rJ(){if(eL)return zT;eL=1;var n=Br(),e=ki(),t=is(),r=c4(),i=wv(),s=e4(),o=function(){},a=i("Reflect","construct"),l=/^\s*(?:class|function)\b/,u=n(l.exec),f=!l.test(o),h=function(b){if(!t(b))return!1;try{return a(o,[],b),!0}catch{return!1}},g=function(b){if(!t(b))return!1;switch(r(b)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return f||!!u(l,s(b))}catch{return!0}};return g.sham=!0,zT=!a||e(function(){var y;return h(h.call)||!h(Object)||!h(function(){y=!0})||y})?g:h,zT}var BT,tL;function iJ(){if(tL)return BT;tL=1;var n=a4(),e=rJ(),t=Ql(),r=ec(),i=r("species"),s=Array;return BT=function(o){var a;return n(o)&&(a=o.constructor,e(a)&&(a===s||n(a.prototype))?a=void 0:t(a)&&(a=a[i],a===null&&(a=void 0))),a===void 0?s:a},BT}var FT,nL;function u4(){if(nL)return FT;nL=1;var n=iJ();return FT=function(e,t){return new(n(e))(t===0?0:t)},FT}var rL;function sJ(){if(rL)return Vj;rL=1;var n=Zf(),e=l4(),t=TI(),r=$m(),i=qm(),s=u4();return n({target:"Array",proto:!0},{flatMap:function(a){var l=r(this),u=i(l),f;return t(a),f=s(l,0),f.length=e(f,l,l,u,0,1,a,arguments.length>1?arguments[1]:void 0),f}}),Vj}var iL={},sL;function oJ(){if(sL)return iL;sL=1;var n=OI();return n("flatMap"),iL}var UT,oL;function aJ(){if(oL)return UT;oL=1,sJ(),oJ();var n=Vm();return UT=n("Array","flatMap"),UT}var HT,aL;function lJ(){if(aL)return HT;aL=1;var n=aJ();return HT=n,HT}lJ();var lL={},cL;function cJ(){if(cL)return lL;cL=1;var n=Zf(),e=l4(),t=$m(),r=qm(),i=$d(),s=u4();return n({target:"Array",proto:!0},{flat:function(){var a=arguments.length?arguments[0]:void 0,l=t(this),u=r(l),f=s(l,0);return f.length=e(f,l,l,u,0,a===void 0?1:i(a)),f}}),lL}var uL={},dL;function uJ(){if(dL)return uL;dL=1;var n=OI();return n("flat"),uL}var $T,hL;function dJ(){if(hL)return $T;hL=1,cJ(),uJ();var n=Vm();return $T=n("Array","flat"),$T}var KT,fL;function hJ(){if(fL)return KT;fL=1;var n=dJ();return KT=n,KT}hJ();var pL={},qT,gL;function Gm(){if(gL)return qT;gL=1;var n=c4(),e=String;return qT=function(t){if(n(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return e(t)},qT}var mL;function fJ(){if(mL)return pL;mL=1;var n=Zf(),e=Br(),t=Xf(),r=$d(),i=Gm(),s=ki(),o=e("".charAt),a=s(function(){return"𠮷".at(-2)!=="\uD842"});return n({target:"String",proto:!0,forced:a},{at:function(u){var f=i(t(this)),h=f.length,g=r(u),y=g>=0?g:h+g;return y<0||y>=h?void 0:o(f,y)}}),pL}var VT,yL;function pJ(){if(yL)return VT;yL=1,fJ();var n=Vm();return VT=n("String","at"),VT}var GT,SL;function gJ(){if(SL)return GT;SL=1;var n=pJ();return GT=n,GT}gJ();var bL={},YT,xL;function d4(){if(xL)return YT;xL=1;var n=Hd();return YT=function(){var e=n(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},YT}var WT,vL;function mJ(){if(vL)return WT;vL=1;var n=ki(),e=Mi(),t=e.RegExp,r=n(function(){var o=t("a","y");return o.lastIndex=2,o.exec("abcd")!==null}),i=r||n(function(){return!t("a","y").sticky}),s=r||n(function(){var o=t("^r","gy");return o.lastIndex=2,o.exec("str")!==null});return WT={BROKEN_CARET:s,MISSED_STICKY:i,UNSUPPORTED_Y:r},WT}var XT,wL;function yJ(){if(wL)return XT;wL=1;var n=ki(),e=Mi(),t=e.RegExp;return XT=n(function(){var r=t(".","s");return!(r.dotAll&&r.test(`
80
14
  `)&&r.flags==="s")}),XT}var ZT,CL;function SJ(){if(CL)return ZT;CL=1;var n=ki(),e=Mi(),t=e.RegExp;return ZT=n(function(){var r=t("(?<a>b)","g");return r.exec("b").groups.a!=="b"||"b".replace(r,"$<a>c")!=="bc"}),ZT}var JT,TL;function DI(){if(TL)return JT;TL=1;var n=Jl(),e=Br(),t=Gm(),r=d4(),i=mJ(),s=II(),o=o4(),a=n4().get,l=yJ(),u=SJ(),f=s("native-string-replace",String.prototype.replace),h=RegExp.prototype.exec,g=h,y=e("".charAt),b=e("".indexOf),v=e("".replace),w=e("".slice),x=(function(){var k=/a/,A=/b*/g;return n(h,k,"a"),n(h,A,"a"),k.lastIndex!==0||A.lastIndex!==0})(),T=i.BROKEN_CARET,P=/()??/.exec("")[1]!==void 0,M=x||P||T||l||u;return M&&(g=function(A){var O=this,R=a(O),F=t(A),z=R.raw,j,$,H,B,G,N,Y;if(z)return z.lastIndex=O.lastIndex,j=n(g,z,F),O.lastIndex=z.lastIndex,j;var W=R.groups,Q=T&&O.sticky,de=n(r,O),U=O.source,re=0,le=F;if(Q&&(de=v(de,"y",""),b(de,"g")===-1&&(de+="g"),le=w(F,O.lastIndex),O.lastIndex>0&&(!O.multiline||O.multiline&&y(F,O.lastIndex-1)!==`
81
15
  `)&&(U="(?: "+U+")",le=" "+le,re++),$=new RegExp("^(?:"+U+")",de)),P&&($=new RegExp("^"+U+"$(?!\\s)",de)),x&&(H=O.lastIndex),B=n(h,Q?$:O,le),Q?B?(B.input=w(B.input,re),B[0]=w(B[0],re),B.index=O.lastIndex,O.lastIndex+=B[0].length):O.lastIndex=0:x&&B&&(O.lastIndex=O.global?B.index+B[0].length:H),P&&B&&B.length>1&&n(f,B[0],$,function(){for(G=1;G<arguments.length-2;G++)arguments[G]===void 0&&(B[G]=void 0)}),B&&W)for(B.groups=N=o(null),G=0;G<W.length;G++)Y=W[G],N[Y[0]]=B[Y[1]];return B}),JT=g,JT}var EL;function h4(){if(EL)return bL;EL=1;var n=Zf(),e=DI();return n({target:"RegExp",proto:!0,forced:/./.exec!==e},{exec:e}),bL}var _L={},QT,PL;function bJ(){if(PL)return QT;PL=1;var n=xv(),e=Function.prototype,t=e.apply,r=e.call;return QT=typeof Reflect=="object"&&Reflect.apply||(n?r.bind(t):function(){return r.apply(t,arguments)}),QT}var eE,IL;function xJ(){if(IL)return eE;IL=1,h4();var n=Jl(),e=r4(),t=DI(),r=ki(),i=ec(),s=MI(),o=i("species"),a=RegExp.prototype;return eE=function(l,u,f,h){var g=i(l),y=!r(function(){var x={};return x[g]=function(){return 7},""[l](x)!==7}),b=y&&!r(function(){var x=!1,T=/a/;return l==="split"&&(T={},T.constructor={},T.constructor[o]=function(){return T},T.flags="",T[g]=/./[g]),T.exec=function(){return x=!0,null},T[g](""),!x});if(!y||!b||f){var v=/./[g],w=u(g,""[l],function(x,T,P,M,k){var A=T.exec;return A===t||A===a.exec?y&&!k?{done:!0,value:n(v,T,P,M)}:{done:!0,value:n(x,P,T,M)}:{done:!1}});e(String.prototype,l,w[0]),e(a,g,w[1])}h&&s(a[g],"sham",!0)},eE}var tE,ML;function vJ(){if(ML)return tE;ML=1;var n=Br(),e=$d(),t=Gm(),r=Xf(),i=n("".charAt),s=n("".charCodeAt),o=n("".slice),a=function(l){return function(u,f){var h=t(r(u)),g=e(f),y=h.length,b,v;return g<0||g>=y?l?"":void 0:(b=s(h,g),b<55296||b>56319||g+1===y||(v=s(h,g+1))<56320||v>57343?l?i(h,g):b:l?o(h,g,g+2):(b-55296<<10)+(v-56320)+65536)}};return tE={codeAt:a(!1),charAt:a(!0)},tE}var nE,kL;function wJ(){if(kL)return nE;kL=1;var n=vJ().charAt;return nE=function(e,t,r){return t+(r?n(e,t).length:1)},nE}var rE,AL;function f4(){if(AL)return rE;AL=1;var n=Br(),e=$m(),t=Math.floor,r=n("".charAt),i=n("".replace),s=n("".slice),o=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,a=/\$([$&'`]|\d{1,2})/g;return rE=function(l,u,f,h,g,y){var b=f+l.length,v=h.length,w=a;return g!==void 0&&(g=e(g),w=o),i(y,w,function(x,T){var P;switch(r(T,0)){case"$":return"$";case"&":return l;case"`":return s(u,0,f);case"'":return s(u,b);case"<":P=g[s(T,1,-1)];break;default:var M=+T;if(M===0)return x;if(M>v){var k=t(M/10);return k===0?x:k<=v?h[k-1]===void 0?r(T,1):h[k-1]+r(T,1):x}P=h[M-1]}return P===void 0?"":P})},rE}var iE,OL;function CJ(){if(OL)return iE;OL=1;var n=Mi(),e=ki(),t=n.RegExp,r=!e(function(){var i=!0;try{t(".","d")}catch{i=!1}var s={},o="",a=i?"dgimsy":"gimsy",l=function(g,y){Object.defineProperty(s,g,{get:function(){return o+=y,!0}})},u={dotAll:"s",global:"g",ignoreCase:"i",multiline:"m",sticky:"y"};i&&(u.hasIndices="d");for(var f in u)l(f,u[f]);var h=Object.getOwnPropertyDescriptor(t.prototype,"flags").get.call(s);return h!==a||o!==a});return iE={correct:r},iE}var sE,DL;function p4(){if(DL)return sE;DL=1;var n=Jl(),e=Tu(),t=$B(),r=CJ(),i=d4(),s=RegExp.prototype;return sE=r.correct?function(o){return o.flags}:function(o){return!r.correct&&t(s,o)&&!e(o,"flags")?n(i,o):o.flags},sE}var oE,RL;function TJ(){if(RL)return oE;RL=1;var n=Jl(),e=Hd(),t=is(),r=Wf(),i=DI(),s=TypeError;return oE=function(o,a){var l=o.exec;if(t(l)){var u=n(l,o,a);return u!==null&&e(u),u}if(r(o)==="RegExp")return n(i,o,a);throw new s("RegExp#exec called on incompatible receiver")},oE}var jL;function EJ(){if(jL)return _L;jL=1;var n=bJ(),e=Jl(),t=Br(),r=xJ(),i=ki(),s=Hd(),o=is(),a=Ql(),l=$d(),u=i4(),f=Gm(),h=Xf(),g=wJ(),y=EI(),b=f4(),v=p4(),w=TJ(),x=ec(),T=x("replace"),P=Math.max,M=Math.min,k=t([].concat),A=t([].push),O=t("".indexOf),R=t("".slice),F=function(H){return H===void 0?H:String(H)},z=(function(){return"a".replace(/./,"$0")==="$0"})(),j=(function(){return/./[T]?/./[T]("a","$0")==="":!1})(),$=!i(function(){var H=/./;return H.exec=function(){var B=[];return B.groups={a:"7"},B},"".replace(H,"$<a>")!=="7"});return r("replace",function(H,B,G){var N=j?"$":"$0";return[function(W,Q){var de=h(this),U=a(W)?y(W,T):void 0;return U?e(U,W,de,Q):e(B,f(de),W,Q)},function(Y,W){var Q=s(this),de=f(Y);if(typeof W=="string"&&O(W,N)===-1&&O(W,"$<")===-1){var U=G(B,Q,de,W);if(U.done)return U.value}var re=o(W);re||(W=f(W));var le=f(v(Q)),Se=O(le,"g")!==-1,fe;Se&&(fe=O(le,"u")!==-1,Q.lastIndex=0);for(var Me=[],ve;ve=w(Q,de),!(ve===null||(A(Me,ve),!Se));){var _e=f(ve[0]);_e===""&&(Q.lastIndex=g(de,u(Q.lastIndex),fe))}for(var Oe="",He=0,Bt=0;Bt<Me.length;Bt++){ve=Me[Bt];for(var qt=f(ve[0]),At=P(M(l(ve.index),de.length),0),_t=[],$t,Gn=1;Gn<ve.length;Gn++)A(_t,F(ve[Gn]));var yr=ve.groups;if(re){var Er=k([qt],_t,At,de);yr!==void 0&&A(Er,yr),$t=f(n(W,void 0,Er))}else $t=b(qt,de,At,_t,yr,W);At>=He&&(Oe+=R(de,He,At)+$t,He=At+qt.length)}return Oe+R(de,He)}]},!$||!z||j),_L}var LL={},aE,NL;function _J(){if(NL)return aE;NL=1;var n=Ql(),e=Wf(),t=ec(),r=t("match");return aE=function(i){var s;return n(i)&&((s=i[r])!==void 0?!!s:e(i)==="RegExp")},aE}var zL;function PJ(){if(zL)return LL;zL=1;var n=Zf(),e=Jl(),t=Br(),r=Xf(),i=is(),s=Ql(),o=_J(),a=Gm(),l=EI(),u=p4(),f=f4(),h=ec(),g=GB(),y=h("replace"),b=TypeError,v=t("".indexOf),w=t("".replace),x=t("".slice),T=Math.max;return n({target:"String",proto:!0},{replaceAll:function(M,k){var A=r(this),O,R,F,z,j,$,H,B,G,N,Y=0,W="";if(s(M)){if(O=o(M),O&&(R=a(r(u(M))),!~v(R,"g")))throw new b("`.replaceAll` does not allow non-global regexes");if(F=l(M,y),F)return e(F,M,A,k);if(g&&O)return w(a(A),M,k)}for(z=a(A),j=a(M),$=i(k),$||(k=a(k)),H=j.length,B=T(1,H),G=v(z,j);G!==-1;)N=$?a(k(j,G,z)):f(j,z,G,[],void 0,k),W+=x(z,Y,G)+N,Y=G+H,G=G+B>z.length?-1:v(z,j,G+B);return Y<z.length&&(W+=x(z,Y)),W}}),LL}var lE,BL;function IJ(){if(BL)return lE;BL=1,h4(),EJ(),PJ();var n=Vm();return lE=n("String","replaceAll"),lE}var cE,FL;function MJ(){if(FL)return cE;FL=1;var n=IJ();return cE=n,cE}MJ();function g4(n){return n&&typeof n=="object"&&"parents"in n}function m4(n){for(let e=0,t=n.parents.length;e<t;e++)if(n.parents[e].__unsafe__getWithoutCapture(!0),n.parents[e].lastChangedEpoch!==n.parentEpochs[e])return!0;return!1}function Gb(n,e){if(n.children.remove(e)&&n.children.isEmpty&&g4(n))for(let t=0,r=n.parents.length;t<r;t++)Gb(n.parents[t],n)}function RI(n,e){if(n.children.add(e)&&g4(n))for(let t=0,r=n.parents.length;t<r;t++)RI(n.parents[t],n)}function y4(n,e){return n===e||Object.is(n,e)||!!(n&&e&&typeof n.equals=="function"&&n.equals(e))}function Eu(n,e){const t=Symbol.for(`com.tldraw.state/${n}`),r=globalThis;return r[t]??=e(),r[t]}const qn=Eu("empty_array",()=>Object.freeze([])),UL=8;class Yb{arraySize=0;array=Array(UL);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(e){if(this.array)return this.array.indexOf(e)!==-1?!1:this.arraySize<UL?(this.array[this.arraySize]=e,this.arraySize++,!0):(this.set=new Set(this.array),this.array=null,this.set.add(e),!0);if(this.set)return this.set.has(e)?!1:(this.set.add(e),!0);throw new Error("no set or array")}remove(e){if(this.array){const t=this.array.indexOf(e);return t===-1?!1:(this.array[t]=void 0,this.arraySize--,t!==this.arraySize&&(this.array[t]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return this.set.has(e)?(this.set.delete(e),!0):!1;throw new Error("no set or array")}visit(e){if(this.array){for(let t=0;t<this.arraySize;t++){const r=this.array[t];typeof r<"u"&&e(r)}return}if(this.set){this.set.forEach(e);return}throw new Error("no set or array")}*[Symbol.iterator](){if(this.array)for(let e=0;e<this.arraySize;e++){const t=this.array[e];typeof t<"u"&&(yield t)}else if(this.set)yield*this.set;else throw new Error("no set or array")}has(e){return this.array?this.array.indexOf(e)!==-1:this.set.has(e)}clear(){this.set?this.set.clear():(this.arraySize=0,this.array=[])}size(){return this.set?this.set.size:this.arraySize}}const eo=Symbol.for("com.tldraw.state/RESET_VALUE");class S4{constructor(e){this.capacity=e,this.buffer=new Array(e)}index=0;buffer;pushEntry(e,t,r){if(r!==void 0){if(r===eo){this.clear();return}this.buffer[this.index]=[e,t,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(e){const{index:t,capacity:r,buffer:i}=this;for(let s=0;s<r;s++){const o=(t-1+r-s)%r,a=i[o];if(!a)return eo;const[l,u]=a;if(s===0&&e>=u)return[];if(l<=e&&e<u){const f=s+1,h=new Array(f);for(let g=0;g<f;g++)h[g]=i[(o+g)%r][2];return h}}return eo}}const Qc=-1;class kJ{constructor(e,t,r){this.name=e,this.runEffect=t,this._scheduleEffect=r?.scheduleEffect}_isActivelyListening=!1;get isActivelyListening(){return this._isActivelyListening}lastTraversedEpoch=Qc;lastReactedEpoch=Qc;_scheduleCount=0;__debug_ancestor_epochs__=null;get scheduleCount(){return this._scheduleCount}parentSet=new Yb;parentEpochs=[];parents=[];_scheduleEffect;maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==Ts()){if(this.parents.length&&!m4(this)){this.lastReactedEpoch=Ts();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}maybeExecute=()=>{this._isActivelyListening&&this.execute()};attach(){this._isActivelyListening=!0;for(let e=0,t=this.parents.length;e<t;e++)RI(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,t=this.parents.length;e<t;e++)Gb(this.parents[e],this)}execute(){try{w4(this);const e=Ts(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,t}finally{C4()}}}const Kd=Eu("EffectScheduler",()=>kJ);function Ms(n,e,t){const r=new Kd(n,e,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function AJ(n,e,t){const r=new Kd(n,e,t);return{scheduler:r,start:i=>{const s=i?.force??!1;r.attach(),s?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}let OJ=class{constructor(e,t){this.parent=e,this.isSync=t}asyncProcessCount=0;initialAtomValues=new Map;get isRoot(){return this.parent===null}commit(){if(Vt.globalIsReacting)for(const e of this.initialAtomValues.keys())x4(e);else this.isRoot?b4(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,e)})}abort(){Vt.globalEpoch++,this.initialAtomValues.forEach((e,t)=>{t.set(e),t.historyBuffer?.clear()}),this.commit()}};const Vt=Eu("transactions",()=>({globalEpoch:Qc+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Qc+1}));function DJ(){return Vt.reactionEpoch}function Ts(){return Vt.globalEpoch}function RJ(){return Vt.globalIsReacting}function jI(n,e){e.lastTraversedEpoch!==Vt.globalEpoch&&(e.lastTraversedEpoch=Vt.globalEpoch,e instanceof Kd?n.add(e):e.children.visit(t=>jI(n,t)))}function b4(n){if(Vt.globalIsReacting)throw new Error("flushChanges cannot be called during a reaction");const e=Vt.currentTransaction;try{Vt.currentTransaction=null,Vt.globalIsReacting=!0,Vt.reactionEpoch=Vt.globalEpoch;const t=new Set;for(const i of n)i.children.visit(s=>jI(t,s));for(const i of t)i.maybeScheduleEffect();let r=0;for(;Vt.cleanupReactors?.size;){if(r++>1e3)throw new Error("Reaction update depth limit exceeded");const i=Vt.cleanupReactors;Vt.cleanupReactors=null;for(const s of i)s.maybeScheduleEffect()}}finally{Vt.cleanupReactors=null,Vt.globalIsReacting=!1,Vt.currentTransaction=e}}function jJ(n,e){Vt.currentTransaction?Vt.currentTransaction.initialAtomValues.has(n)||Vt.currentTransaction.initialAtomValues.set(n,e):Vt.globalIsReacting?x4(n):b4([n])}function x4(n){const e=Vt.cleanupReactors??=new Set;n.children.visit(t=>jI(e,t))}function LJ(){Vt.globalEpoch++}function NJ(n){const e=new OJ(Vt.currentTransaction,!0);Vt.currentTransaction=e;try{let t,r=!1;try{t=n(()=>r=!0)}catch(i){throw e.abort(),i}if(Vt.currentTransaction!==e)throw new Error("Transaction boundaries overlap");return r?e.abort():e.commit(),t}finally{Vt.currentTransaction=e.parent}}function to(n){return Vt.currentTransaction?n():NJ(n)}let HL=!1;function zJ(){HL||(HL=!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.
82
16
 
@@ -92,18 +26,10 @@ getFoo() {
92
26
  return 'foo'
93
27
  }
94
28
  `))}const xi=Symbol.for("com.tldraw.state/UNINITIALIZED");function pd(n){return n===xi}const j_=Eu("WithDiff",()=>class{constructor(e,t){this.value=e,this.diff=t}});function wg(n,e){return new j_(n,e)}class BJ{constructor(e,t,r){this.name=e,this.derive=t,r?.historyLength&&(this.historyBuffer=new S4(r.historyLength)),this.computeDiff=r?.computeDiff,this.isEqual=r?.isEqual??y4}lastChangedEpoch=Qc;lastTraversedEpoch=Qc;__debug_ancestor_epochs__=null;lastCheckedEpoch=Qc;parentSet=new Yb;parents=[];parentEpochs=[];children=new Yb;get isActivelyListening(){return!this.children.isEmpty}historyBuffer;state=xi;error=null;computeDiff;isEqual;__unsafe__getWithoutCapture(e){const t=this.lastChangedEpoch===Qc,r=Ts();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&RJ()&&this.lastTraversedEpoch<DJ()||!m4(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{w4(this);const i=this.derive(this.state,this.lastCheckedEpoch),s=i instanceof j_?i.value:i,o=this.state===xi;if(o||!this.isEqual(s,this.state)){if(this.historyBuffer&&!o){const a=i instanceof j_?i.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Ts(),a??this.computeDiff?.(this.state,s,this.lastCheckedEpoch,Ts())??eo)}this.lastChangedEpoch=Ts(),this.state=s}return this.error=null,this.lastCheckedEpoch=Ts(),this.state}catch(i){if(this.state!==xi&&(this.state=xi,this.lastChangedEpoch=Ts()),this.lastCheckedEpoch=Ts(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:i},!e)throw i;return this.state}finally{C4()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Wb(this)}}getDiffSince(e){return this.__unsafe__getWithoutCapture(!0),Wb(this),e>=this.lastChangedEpoch?qn:this.historyBuffer?.getChangesSince(e)??eo}}const Ym=Eu("Computed",()=>BJ);function FJ(n={},e,t,r){const i=r.value,s=Symbol.for("__@tldraw/state__computed__"+t);return r.value=function(){let o=this[s];return o||(o=new Ym(t,i.bind(this),n),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()},r.value[v4]=!0,r}function UJ(n={},e,t,r){const i=r.get,s=Symbol.for("__@tldraw/state__computed__"+t);return r.get=function(){let o=this[s];return o||(o=new Ym(t,i.bind(this),n),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()},r}function HJ(n,e,t){Be(t.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(t.name)),i=function(){let s=this[r];return s||(s=new Ym(String(t.name),e.bind(this),n),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:s})),s.get()};return i[v4]=!0,i}function $L(n={},e){if(e.length===2){const[t,r]=e;return HJ(n,t,r)}else{const[t,r,i]=e;return i.get?(zJ(),UJ(n,t,r,i)):FJ(n,t,r,i)}}const v4="@@__isComputedMethod__@@";function pe(){if(arguments.length===1){const n=arguments[0];return(...e)=>$L(n,e)}else return typeof arguments[0]=="string"?new Ym(arguments[0],arguments[1],arguments[2]):$L(void 0,arguments)}function LI(n){return!!(n&&n instanceof Ym)}class $J{constructor(e,t){this.below=e,this.child=t}offset=0;maybeRemoved}const _n=Eu("capture",()=>({stack:null}));function Cg(n){const e=_n.stack;_n.stack=null;try{return n()}finally{_n.stack=e}}function w4(n){if(_n.stack=new $J(_n.stack,n),n.__debug_ancestor_epochs__){const e=n.__debug_ancestor_epochs__;n.__debug_ancestor_epochs__=null;for(const t of n.parents)t.__unsafe__getWithoutCapture(!0);KJ(n,e)}n.parentSet.clear()}function C4(){const n=_n.stack;if(_n.stack=n.below,n.offset<n.child.parents.length){for(let e=n.offset;e<n.child.parents.length;e++){const t=n.child.parents[e];n.child.parentSet.has(t)||Gb(t,n.child)}n.child.parents.length=n.offset,n.child.parentEpochs.length=n.offset}if(n.maybeRemoved)for(let e=0;e<n.maybeRemoved.length;e++){const t=n.maybeRemoved[e];n.child.parentSet.has(t)||Gb(t,n.child)}n.child.__debug_ancestor_epochs__&&T4(n.child,n.child.__debug_ancestor_epochs__)}function Wb(n){if(_n.stack){if(_n.stack.child.parentSet.has(n))return;if(_n.stack.child.parentSet.add(n),_n.stack.child.isActivelyListening&&RI(n,_n.stack.child),_n.stack.offset<_n.stack.child.parents.length){const t=_n.stack.child.parents[_n.stack.offset];t!==n&&(_n.stack.maybeRemoved?_n.stack.maybeRemoved.push(t):_n.stack.maybeRemoved=[t])}_n.stack.child.parents[_n.stack.offset]=n,_n.stack.child.parentEpochs[_n.stack.offset]=n.lastChangedEpoch,_n.stack.offset++}}function T4(n,e){for(let t=0;t<n.parents.length;t++){const r=n.parents[t],i=n.parentEpochs[t];e.set(r,i),LI(r)&&T4(r,e)}return e}function E4(n,e){const t={};for(let r=0;r<n.parents.length;r++){const i=n.parents[r];if(!e.has(i))continue;const s=e.get(i);i.lastChangedEpoch!==s&&(LI(i)?t[i.name]=E4(i,e):t[i.name]=null)}return t}function KJ(n,e){const t=E4(n,e);if(Object.keys(t).length===0){console.log(`Effect(${n.name}) was executed manually.`);return}let r=LI(n)?`Computed(${n.name}) is recomputing because:`:`Effect(${n.name}) is executing because:`;function i(s,o){const a=`
95
- `+" ".repeat(o)+"↳ ";for(const[l,u]of Object.entries(s))u?(r+=`${a}Computed(${l}) changed`,i(u,o+2)):r+=`${a}Atom(${l}) changed`}i(t,1),console.log(r)}class qJ{constructor(e,t,r){this.name=e,this.current=t,this.isEqual=r?.isEqual??null,r&&(r.historyLength&&(this.historyBuffer=new S4(r.historyLength)),this.computeDiff=r.computeDiff)}isEqual;computeDiff;lastChangedEpoch=Ts();children=new Yb;historyBuffer;__unsafe__getWithoutCapture(e){return this.current}get(){return Wb(this),this.current}set(e,t){if(this.isEqual?.(this.current,e)??y4(this.current,e))return this.current;LJ(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Ts(),t??this.computeDiff?.(this.current,e,this.lastChangedEpoch,Ts())??eo),this.lastChangedEpoch=Ts();const r=this.current;return this.current=e,jJ(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){return Wb(this),e>=this.lastChangedEpoch?qn:this.historyBuffer?.getChangesSince(e)??eo}}const VJ=Eu("Atom",()=>qJ);function bn(n,e,t){return new VJ(n,e,t)}const _4=1,GJ=Eu("apiVersion",()=>_4);if(GJ!==_4)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");xu("@tldraw/state","4.1.2","esm");function Cv(n,e,t=[]){const r=Ge.useRef(e);r.current=e;const[i,s,o]=Ge.useMemo(()=>{let a=null;const l=h=>(a=h,()=>{a=null}),u=new Kd(`useStateTracking(${n})`,()=>r.current?.(),{scheduleEffect(){a?.()}});return[u,l,()=>u.scheduleCount]},[n,...t]);return Ge.useSyncExternalStore(s,o,o),Ge.useEffect(()=>(i.attach(),i.maybeScheduleEffect(),()=>{i.detach()}),[i]),i.execute()}const KL={apply(n,e,t){return Cv(n.displayName??n.name??"tracked(???)",()=>n.apply(e,t))}},YJ=Symbol.for("react.memo"),WJ=Symbol.for("react.forward_ref");function sr(n){let e=null;const t=n.$$typeof;return t===YJ&&(n=n.type,e=n.compare),t===WJ?E.memo(E.forwardRef(new Proxy(n.render,KL))):E.memo(new Proxy(n,KL),e)}function Wm(n,e,t){return E.useState(()=>{const r=typeof e=="function"?e():e;return bn(`useAtom(${n})`,r,t)})[0]}function XJ(){const n=arguments[0],e=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return E.useMemo(()=>pe(`useComputed(${n})`,e,t),r)}function wd(n,e,t=qn){E.useEffect(()=>{const r=new Kd(n,e);return r.attach(),r.execute(),()=>{r.detach()}},t)}function NI(n,e,t=[]){E.useEffect(()=>{let r;const i=new Kd(n,e,{scheduleEffect:s=>{r=CI(s)}});return i.attach(),i.execute(),()=>{i.detach(),r?.()}},t)}function ee(){const n=arguments,e=n.length===3?n[2]:[n[0]],t=n.length===3?n[0]:`useValue(${n[0].name})`,{$val:r,subscribe:i,getSnapshot:s}=E.useMemo(()=>{const o=n.length===1?n[0]:pe(t,n[1]);return{$val:o,subscribe:a=>Ms(`useValue(${t})`,()=>{try{o.get()}catch{}a()}),getSnapshot:()=>o.lastChangedEpoch}},e);return E.useSyncExternalStore(i,s,s),r.__unsafe__getWithoutCapture()}xu("@tldraw/state-react","4.1.2","esm");/*!
96
- * This file was lovingly and delicately extracted from Immutable.js
97
- * MIT License: https://github.com/immutable-js/immutable-js/blob/main/LICENSE
98
- * Copyright (c) 2014-present, Lee Byron and other contributors.
99
- */function zI(n){return n>>>1&1073741824|n&3221225471}const ZJ=Object.prototype.valueOf;function Cd(n){if(n==null)return qL(n);if(typeof n.hashCode=="function")return zI(n.hashCode(n));const e=nQ(n);if(e==null)return qL(e);switch(typeof e){case"boolean":return e?1108378657:1108378656;case"number":return JJ(e);case"string":return e.length>rQ?QJ(e):L_(e);case"object":case"function":return tQ(e);case"symbol":return eQ(e);default:if(typeof e.toString=="function")return L_(e.toString());throw new Error("Value type "+typeof e+" cannot be hashed.")}}function qL(n){return n===null?1108378658:1108378659}function JJ(n){if(n!==n||n===1/0)return 0;let e=n|0;for(e!==n&&(e^=n*4294967295);n>4294967295;)n/=4294967295,e^=n;return zI(e)}function QJ(n){let e=hE[n];return e===void 0&&(e=L_(n),dE===iQ&&(dE=0,hE={}),dE++,hE[n]=e),e}function L_(n){let e=0;for(let t=0;t<n.length;t++)e=31*e+n.charCodeAt(t)|0;return zI(e)}function eQ(n){let e=GL[n];return e!==void 0||(e=P4(),GL[n]=e),e}function tQ(n){let e=VL.get(n);return e!==void 0||(e=P4(),VL.set(n,e)),e}function nQ(n){return n.valueOf!==ZJ&&typeof n.valueOf=="function"?n.valueOf(n):n}function P4(){const n=++uE;return uE&1073741824&&(uE=0),n}const VL=new WeakMap,GL=Object.create(null);let uE=0;const rQ=16,iQ=255;let dE=0,hE={};const kf=5,Xm=1<<kf,Af=Xm-1,Yl={};function YL(){return{value:!1}}function la(n){n&&(n.value=!0)}function BI(n,e){e=e||0;const t=Math.max(0,n.length-e),r=new Array(t);for(let i=0;i<t;i++)r[i]=n[i+e];return r}const Of=Object.is;class I4{}class FI{_root;size;__ownerID;__hash;__altered;constructor(e){return e==null?Sf():e instanceof FI?e:Sf().withMutations(t=>{for(const[r,i]of e)t.set(r,i)})}get(e,t){return this._root?this._root.get(0,void 0,e,t):t}set(e,t){return ZL(this,e,t)}delete(e){return ZL(this,e,Yl)}deleteAll(e){return this.withMutations(t=>{for(const r of e)t.delete(r)})}__ensureOwner(e){return e===this.__ownerID?this:e?$I(this.size,this._root,e,this.__hash):this.size===0?Sf():(this.__ownerID=e,this.__altered=!1,this)}withMutations(e){const t=this.asMutable();return e(t),t.wasAltered()?t.__ensureOwner(this.__ownerID):this}wasAltered(){return this.__altered}asMutable(){return this.__ownerID?this:this.__ensureOwner(new I4)}[Symbol.iterator](){return this.entries()[Symbol.iterator]()}entries(){return new fE(this,sQ,!1)}keys(){return new fE(this,M4,!1)}values(){return new fE(this,k4,!1)}}class UI{constructor(e,t){this.ownerID=e,this.entries=t}get(e,t,r,i){const s=this.entries;for(let o=0,a=s.length;o<a;o++)if(Of(r,s[o][0]))return s[o][1];return i}update(e,t,r,i,s,o,a){const l=s===Yl,u=this.entries;let f=0;const h=u.length;for(;f<h&&!Of(i,u[f][0]);f++);const g=f<h;if(g?u[f][1]===s:l)return this;if(la(a),(l||!g)&&la(o),l&&u.length===1)return;if(!g&&!l&&u.length>=fQ)return lQ(e,u,i,s);const y=e&&e===this.ownerID,b=y?u:BI(u);return g?l?f===h-1?b.pop():b[f]=b.pop():b[f]=[i,s]:b.push([i,s]),y?(this.entries=b,this):new UI(e,b)}}class Tv{constructor(e,t,r){this.ownerID=e,this.bitmap=t,this.nodes=r}get(e,t,r,i){t===void 0&&(t=Cd(r));const s=1<<((e===0?t:t>>>e)&Af),o=this.bitmap;return(o&s)===0?i:this.nodes[QL(o&s-1)].get(e+kf,t,r,i)}update(e,t,r,i,s,o,a){r===void 0&&(r=Cd(i));const l=(t===0?r:r>>>t)&Af,u=1<<l,f=this.bitmap,h=(f&u)!==0;if(!h&&s===Yl)return this;const g=QL(f&u-1),y=this.nodes,b=h?y[g]:void 0,v=KI(b,e,t+kf,r,i,s,o,a);if(v===b)return this;if(!h&&v&&y.length>=pQ)return uQ(e,y,f,l,v);if(h&&!v&&y.length===2&&JL(y[g^1]))return y[g^1];if(h&&v&&y.length===1&&JL(v))return v;const w=e&&e===this.ownerID,x=h?v?f:f^u:f|u,T=h?v?A4(y,g,v,w):hQ(y,g,w):dQ(y,g,v,w);return w?(this.bitmap=x,this.nodes=T,this):new Tv(e,x,T)}}class HI{constructor(e,t,r){this.ownerID=e,this.count=t,this.nodes=r}get(e,t,r,i){t===void 0&&(t=Cd(r));const s=(e===0?t:t>>>e)&Af,o=this.nodes[s];return o?o.get(e+kf,t,r,i):i}update(e,t,r,i,s,o,a){r===void 0&&(r=Cd(i));const l=(t===0?r:r>>>t)&Af,u=s===Yl,f=this.nodes,h=f[l];if(u&&!h)return this;const g=KI(h,e,t+kf,r,i,s,o,a);if(g===h)return this;let y=this.count;if(!h)y++;else if(!g&&(y--,y<gQ))return cQ(e,f,y,l);const b=e&&e===this.ownerID,v=A4(f,l,g,b);return b?(this.count=y,this.nodes=v,this):new HI(e,y,v)}}class Ev{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entries=r}get(e,t,r,i){const s=this.entries;for(let o=0,a=s.length;o<a;o++)if(Of(r,s[o][0]))return s[o][1];return i}update(e,t,r,i,s,o,a){r===void 0&&(r=Cd(i));const l=s===Yl;if(r!==this.keyHash)return l?this:(la(a),la(o),qI(this,e,t,r,[i,s]));const u=this.entries;let f=0;const h=u.length;for(;f<h&&!Of(i,u[f][0]);f++);const g=f<h;if(g?u[f][1]===s:l)return this;if(la(a),(l||!g)&&la(o),l&&h===2)return new qd(e,this.keyHash,u[f^1]);const y=e&&e===this.ownerID,b=y?u:BI(u);return g?l?f===h-1?b.pop():b[f]=b.pop():b[f]=[i,s]:b.push([i,s]),y?(this.entries=b,this):new Ev(e,this.keyHash,b)}}class qd{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entry=r}get(e,t,r,i){return Of(r,this.entry[0])?this.entry[1]:i}update(e,t,r,i,s,o,a){const l=s===Yl,u=Of(i,this.entry[0]);if(u?s===this.entry[1]:l)return this;if(la(a),l){la(o);return}return u?e&&e===this.ownerID?(this.entry[1]=s,this):new qd(e,this.keyHash,[i,s]):(la(o),qI(this,e,t,Cd(i),[i,s]))}}class fE{constructor(e,t,r){this._type=t,this._reverse=r,this._stack=e._root&&WL(e._root)}_stack;[Symbol.iterator](){return this}next(){const e=this._type;let t=this._stack;for(;t;){const r=t.node,i=t.index++;let s;if(r.entry){if(i===0)return pE(e,r.entry)}else if("entries"in r&&r.entries){if(s=r.entries.length-1,i<=s)return pE(e,r.entries[this._reverse?s-i:i])}else if(s=r.nodes.length-1,i<=s){const o=r.nodes[this._reverse?s-i:i];if(o){if(o.entry)return pE(e,o.entry);t=this._stack=WL(o,t)}continue}t=this._stack=this._stack.__prev}return aQ()}}function pE(n,e){return oQ(n,e[0],e[1])}function WL(n,e){return{node:n,index:0,__prev:e}}const M4=0,k4=1,sQ=2;function oQ(n,e,t,r){const i=n===M4?e:n===k4?t:[e,t];return r?r.value=i:r={value:i,done:!1},r}function aQ(){return{value:void 0,done:!0}}function $I(n,e,t,r){const i=Object.create(FI.prototype);return i.size=n,i._root=e,i.__ownerID=t,i.__hash=r,i.__altered=!1,i}let XL;function Sf(){return XL||(XL=$I(0))}function ZL(n,e,t){let r,i;if(n._root){const s=YL(),o=YL();if(r=KI(n._root,n.__ownerID,0,void 0,e,t,s,o),!o.value)return n;i=n.size+(s.value?t===Yl?-1:1:0)}else{if(t===Yl)return n;i=1,r=new UI(n.__ownerID,[[e,t]])}return n.__ownerID?(n.size=i,n._root=r,n.__hash=void 0,n.__altered=!0,n):r?$I(i,r):Sf()}function KI(n,e,t,r,i,s,o,a){return n?n.update(e,t,r,i,s,o,a):s===Yl?n:(la(a),la(o),new qd(e,r,[i,s]))}function JL(n){return n.constructor===qd||n.constructor===Ev}function qI(n,e,t,r,i){if(n.keyHash===r)return new Ev(e,r,[n.entry,i]);const s=(t===0?n.keyHash:n.keyHash>>>t)&Af,o=(t===0?r:r>>>t)&Af;let a;const l=s===o?[qI(n,e,t+kf,r,i)]:(a=new qd(e,r,i),s<o?[n,a]:[a,n]);return new Tv(e,1<<s|1<<o,l)}function lQ(n,e,t,r){n||(n=new I4);let i=new qd(n,Cd(t),[t,r]);for(let s=0;s<e.length;s++){const o=e[s];i=i.update(n,0,void 0,o[0],o[1])}return i}function cQ(n,e,t,r){let i=0,s=0;const o=new Array(t);for(let a=0,l=1,u=e.length;a<u;a++,l<<=1){const f=e[a];f!==void 0&&a!==r&&(i|=l,o[s++]=f)}return new Tv(n,i,o)}function uQ(n,e,t,r,i){let s=0;const o=new Array(Xm);for(let a=0;t!==0;a++,t>>>=1)o[a]=t&1?e[s++]:void 0;return o[r]=i,new HI(n,s+1,o)}function QL(n){return n-=n>>1&1431655765,n=(n&858993459)+(n>>2&858993459),n=n+(n>>4)&252645135,n+=n>>8,n+=n>>16,n&127}function A4(n,e,t,r){const i=r?n:BI(n);return i[e]=t,i}function dQ(n,e,t,r){const i=n.length+1;if(r&&e+1===i)return n[e]=t,n;const s=new Array(i);let o=0;for(let a=0;a<i;a++)a===e?(s[a]=t,o=-1):s[a]=n[a+o];return s}function hQ(n,e,t){const r=n.length-1;if(t&&e===r)return n.pop(),n;const i=new Array(r);let s=0;for(let o=0;o<r;o++)o===e&&(s=1),i[o]=n[o+s];return i}const fQ=Xm/4,pQ=Xm/2,gQ=Xm/4;class N_{constructor(e,t){this.name=e;let r=Sf();t&&(r=r.withMutations(i=>{for(const[s,o]of t)i.set(s,bn(`${e}:${String(s)}`,o))})),this.atoms=bn(`${e}:atoms`,r)}atoms;getAtom(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t){this.atoms.get();return}return t}get(e){const t=this.getAtom(e)?.get();return Be(t!==xi),t}__unsafe__getWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t)return;const r=t.__unsafe__getWithoutCapture();return Be(r!==xi),r}has(e){const t=this.getAtom(e);return t?t.get()!==xi:!1}__unsafe__hasWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(Be(t.__unsafe__getWithoutCapture()!==xi),!0):!1}set(e,t){const r=this.atoms.__unsafe__getWithoutCapture().get(e);return r?r.set(t):this.atoms.update(i=>i.set(e,bn(`${this.name}:${String(e)}`,t))),this}update(e,t){const r=this.atoms.__unsafe__getWithoutCapture().get(e);if(!r)throw new Error(`AtomMap: key ${e} not found`);const i=r.__unsafe__getWithoutCapture();Be(i!==xi),r.set(t(i))}delete(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(to(()=>{t.set(xi),this.atoms.update(r=>r.delete(e))}),!0):!1}deleteMany(e){return to(()=>{const t=[],r=this.atoms.get().withMutations(i=>{for(const s of e){const o=i.get(s);if(!o)continue;const a=o.get();Be(a!==xi),t.push([s,a]),i.delete(s),o.set(xi)}});return t.length&&this.atoms.set(r),t})}clear(){return to(()=>{for(const e of this.atoms.__unsafe__getWithoutCapture().values())e.set(xi);this.atoms.set(Sf())})}*entries(){for(const[e,t]of this.atoms.get()){const r=t.get();Be(r!==xi),yield[e,r]}}*keys(){for(const e of this.atoms.get().keys())yield e}*values(){for(const e of this.atoms.get().values()){const t=e.get();Be(t!==xi),yield t}}get size(){return this.atoms.get().size}forEach(e,t){for(const[r,i]of this.entries())e.call(t,i,r,this)}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="AtomMap"}class Ib{constructor(e){this.previousValue=e}nextValue;diff;get(){const e=this.diff?.removed?.size??0,t=this.diff?.added?.size??0;if(!(e===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(e,t){this.nextValue??=new Set(this.previousValue),this.nextValue.add(e),this.diff??={},t?this.diff.removed?.delete(e):(this.diff.added??=new Set,this.diff.added.add(e))}add(e){const t=this.previousValue.has(e);if(t)return this.diff?.removed?.has(e)?this._add(e,t):void 0;this.nextValue?.has(e)||this._add(e,t)}_remove(e,t){this.nextValue??=new Set(this.previousValue),this.nextValue.delete(e),this.diff??={},t?(this.diff.removed??=new Set,this.diff.removed.add(e)):this.diff.added?.delete(e)}remove(e){const t=this.previousValue.has(e);if(!t)return this.diff?.added?.has(e)?this._remove(e,t):void 0;this.diff?.removed?.has(e)||this._remove(e,t)}}function mQ(n){const e=[];for(let t=n.length-1;t>=0;t--){const r=n[t];if("id"in r)e.unshift(r);else{const i=r.dependsOn,s=e[0];s&&(e[0]={...s,dependsOn:i.concat(s.dependsOn??[])})}}return e}function bf({sequence:n,sequenceId:e,retroactive:t=!0}){const r={sequenceId:e,retroactive:t,sequence:mQ(n)};return O4(r),r}function Ds(n,e){return Object.fromEntries(Yi(e).map(([t,r])=>[t,`${n}/${r}`]))}function lo(n){const e=n.sequenceId;return bf({sequenceId:e,retroactive:n.retroactive??!0,sequence:n.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>r.typeName===n.recordType&&(t.filter?.(r)??!0)&&(n.filter?.(r)??!0)}:t)})}function yQ(n){if(n.length===0)return[];const e=new Map(n.map(l=>[l.id,l])),t=new Map,r=new Map,i=new Map;for(const l of n)r.set(l.id,0),t.set(l.id,new Set),i.set(l.id,new Set);for(const l of n){const{version:u,sequenceId:f}=Xb(l.id),h=`${f}/${u-1}`;if(e.has(h)&&(t.get(h).add(l.id),r.set(l.id,r.get(l.id)+1)),l.dependsOn)for(const g of l.dependsOn)e.has(g)&&(t.get(g).add(l.id),i.get(l.id).add(g),r.set(l.id,r.get(l.id)+1))}const s=n.filter(l=>r.get(l.id)===0),o=[],a=new Set;for(;s.length>0;){let l,u=-1/0;for(const h of s){let g=0;for(const y of t.get(h.id)||[])a.has(y)||(g+=1,i.get(y).has(h.id)&&(g+=100));(g>u||g===u&&h.id.localeCompare(l?.id??"")<0)&&(l=h,u=g)}const f=l;s.splice(s.indexOf(f),1),o.push(f),a.add(f.id);for(const h of t.get(f.id)||[])a.has(h)||(r.set(h,r.get(h)-1),r.get(h)===0&&s.push(e.get(h)))}if(o.length!==n.length){const l=n.filter(u=>!a.has(u.id));Be(!1,`Circular dependency in migrations: ${l[0].id}`)}return o}function Xb(n){const[e,t]=n.split("/");return{sequenceId:e,version:parseInt(t)}}function e3(n,e){e&&Be(n.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${n}'`),Be(n.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${n}'`)}function O4(n){if(Be(!n.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${n.sequenceId}`),Be(n.sequenceId.length,"sequenceId must be a non-empty string"),n.sequence.length===0)return;e3(n.sequence[0].id,n.sequenceId);let e=Xb(n.sequence[0].id).version;Be(e===1,`Expected the first migrationId to be '${n.sequenceId}/1' but got '${n.sequence[0].id}'`);for(let t=1;t<n.sequence.length;t++){const r=n.sequence[t].id;e3(r,n.sequenceId);const i=Xb(r).version;Be(i===e+1,`Migration id numbers must increase in increments of 1, expected ${n.sequenceId}/${e+1} but got '${n.sequence[t].id}'`),e=i}}var Uc=(n=>(n.IncompatibleSubtype="incompatible-subtype",n.UnknownType="unknown-type",n.TargetVersionTooNew="target-version-too-new",n.TargetVersionTooOld="target-version-too-old",n.MigrationError="migration-error",n.UnrecognizedSubtype="unrecognized-subtype",n))(Uc||{});function Zb(){return{added:{},updated:{},removed:{}}}function z_(n){const e={added:n.removed,removed:n.added,updated:{}};for(const[t,r]of Object.values(n.updated))e.updated[t.id]=[r,t];return e}function D4(n){return Object.keys(n.added).length===0&&Object.keys(n.updated).length===0&&Object.keys(n.removed).length===0}function VI(n,e){const t=e?.mutateFirstDiff?n[0]:{added:{},removed:{},updated:{}};return $g(t,n),t}function $g(n,e){for(const t of e){for(const[r,i]of Yi(t.added))if(n.removed[r]){const s=n.removed[r];delete n.removed[r],s!==i&&(n.updated[r]=[s,i])}else n.added[r]=i;for(const[r,[i,s]]of Yi(t.updated)){if(n.added[r]){n.added[r]=s,delete n.updated[r],delete n.removed[r];continue}if(n.updated[r]){n.updated[r]=[n.updated[r][0],s],delete n.removed[r];continue}n.updated[r]=t.updated[r],delete n.removed[r]}for(const[r,i]of Yi(t.removed))n.added[r]?delete n.added[r]:n.updated[r]?(n.removed[r]=n.updated[r][0],delete n.updated[r]):n.removed[r]=i}}class _v{constructor(e,t){this.typeName=e,this.createDefaultProperties=t.createDefaultProperties,this.validator=t.validator??{validate:i=>i},this.scope=t.scope??"document",this.ephemeralKeys=t.ephemeralKeys;const r=new Set;if(t.ephemeralKeys)for(const[i,s]of Yi(t.ephemeralKeys))s&&r.add(i);this.ephemeralKeySet=r}createDefaultProperties;validator;ephemeralKeys;ephemeralKeySet;scope;create(e){const t={...this.createDefaultProperties(),id:"id"in e?e.id:this.createId()};for(const[r,i]of Object.entries(e))i!==void 0&&(t[r]=i);return t.typeName=this.typeName,t}clone(e){return{...Qn(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??zt())}parseId(e){if(!this.isId(e))throw new Error(`ID "${e}" is not a valid ID for type "${this.typeName}"`);return e.slice(this.typeName.length+1)}isInstance(e){return e?.typeName===this.typeName}isId(e){if(!e)return!1;for(let t=0;t<this.typeName.length;t++)if(e[t]!==this.typeName[t])return!1;return e[this.typeName.length]===":"}withDefaultProperties(e){return new _v(this.typeName,{createDefaultProperties:e,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(e,t){return t&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(t,e):this.validator.validate(e)}}function Qa(n,e){return new _v(n,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function SQ(n){if(n.length===0)return new Set;const e=n[0],t=n.slice(1),r=new Set;for(const i of e)t.every(s=>s.has(i))&&r.add(i);return r}function bQ(n,e){const t={};for(const r of e)n.has(r)||(t.added??=new Set,t.added.add(r));for(const r of n)e.has(r)||(t.removed??=new Set,t.removed.add(r));return t.added||t.removed?t:void 0}function t3(n,e){for(const[t,r]of Object.entries(n)){const i=r,s=e[t];if("eq"in i&&s!==i.eq||"neq"in i&&s===i.neq||"gt"in i&&(typeof s!="number"||s<=i.gt))return!1}return!0}function n3(n,e,t){const r=Object.fromEntries(Object.keys(t).map(i=>[i,new Set]));for(const[i,s]of Object.entries(t))if("eq"in s){const a=n.index(e,i).get().get(s.eq);if(a)for(const l of a)r[i].add(l)}else if("neq"in s){const o=n.index(e,i);for(const[a,l]of o.get())if(a!==s.neq)for(const u of l)r[i].add(u)}else if("gt"in s){const o=n.index(e,i);for(const[a,l]of o.get())if(a>s.gt)for(const u of l)r[i].add(u)}return SQ(Object.values(r))}class xQ{constructor(e,t){this.recordMap=e,this.history=t}indexCache=new Map;historyCache=new Map;filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const t=pe("filterHistory:"+e,(r,i)=>{if(pd(r))return this.history.get();const s=this.history.getDiffSince(i);if(s===eo)return this.history.get();const o={added:{},removed:{},updated:{}};let a=0,l=0,u=0;for(const f of s){for(const h of Hn(f.added))if(h.typeName===e)if(o.removed[h.id]){const g=o.removed[h.id];delete o.removed[h.id],l--,g!==h&&(o.updated[h.id]=[g,h],u++)}else o.added[h.id]=h,a++;for(const[h,g]of Hn(f.updated))g.typeName===e&&(o.added[g.id]?o.added[g.id]=g:o.updated[g.id]?o.updated[g.id]=[o.updated[g.id][0],g]:(o.updated[g.id]=[h,g],u++));for(const h of Hn(f.removed))h.typeName===e&&(o.added[h.id]?(delete o.added[h.id],a--):o.updated[h.id]?(o.removed[h.id]=o.updated[h.id][0],delete o.updated[h.id],u--,l++):(o.removed[h.id]=h,l++))}return a||l||u?wg(this.history.get(),o):r},{historyLength:100});return this.historyCache.set(e,t),t}index(e,t){const r=e+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const i=this.__uncached_createIndex(e,t);return this.indexCache.set(r,i),i}__uncached_createIndex(e,t){const r=this.filterHistory(e),i=()=>{r.get();const s=new Map;for(const o of this.recordMap.values())if(o.typeName===e){const a=o[t];s.has(a)||s.set(a,new Set),s.get(a).add(o.id)}return s};return pe("index:"+e+":"+t,(s,o)=>{if(pd(s))return i();const a=r.getDiffSince(o);if(a===eo)return i();const l=new Map,u=(y,b)=>{let v=l.get(y);v||(v=new Ib(s.get(y)??new Set)),v.add(b),l.set(y,v)},f=(y,b)=>{let v=l.get(y);v||(v=new Ib(s.get(y)??new Set)),v.remove(b),l.set(y,v)};for(const y of a){for(const b of Hn(y.added))if(b.typeName===e){const v=b[t];u(v,b.id)}for(const[b,v]of Hn(y.updated))if(v.typeName===e){const w=b[t],x=v[t];w!==x&&(f(w,v.id),u(x,v.id))}for(const b of Hn(y.removed))if(b.typeName===e){const v=b[t];f(v,b.id)}}let h,g;for(const[y,b]of l){const v=b.get();v&&(h||(h=new Map(s)),g||(g=new Map),v.value.size===0?h.delete(y):h.set(y,v.value),g.set(y,v.diff))}return h&&g?wg(h,g):s},{historyLength:100})}record(e,t=()=>({}),r="record:"+e+(t?":"+t.toString():"")){const i=this.ids(e,t,r);return pe(r,()=>{for(const s of i.get())return this.recordMap.get(s)})}records(e,t=()=>({}),r="records:"+e+(t?":"+t.toString():"")){const i=this.ids(e,t,"ids:"+r);return pe(r,()=>Array.from(i.get(),s=>this.recordMap.get(s)),{isEqual:qb})}ids(e,t=()=>({}),r="ids:"+e+(t?":"+t.toString():"")){const i=this.filterHistory(e),s=()=>{i.get();const l=t();if(Object.keys(l).length===0){const u=new Set;for(const f of this.recordMap.values())f.typeName===e&&u.add(f.id);return u}return n3(this,e,l)},o=l=>{const u=s(),f=bQ(l,u);return f?wg(u,f):l},a=pe("ids_query:"+r,t,{isEqual:vu});return pe("query:"+r,(l,u)=>{const f=a.get();if(pd(l))return s();if(u<a.lastChangedEpoch)return o(l);const h=i.getDiffSince(u);if(h===eo)return o(l);const g=new Ib(l);for(const b of h){for(const v of Hn(b.added))v.typeName===e&&t3(f,v)&&g.add(v.id);for(const[v,w]of Hn(b.updated))w.typeName===e&&(t3(f,w)?g.add(w.id):g.remove(w.id));for(const v of Hn(b.removed))v.typeName===e&&g.remove(v.id)}const y=g.get();return y?wg(y.value,y.diff):l},{historyLength:50})}exec(e,t){const r=n3(this,e,t);return r.size===0?qn:Array.from(r,i=>this.recordMap.get(i))}}class vQ{constructor(e){this.store=e}_beforeCreateHandlers={};_afterCreateHandlers={};_beforeChangeHandlers={};_afterChangeHandlers={};_beforeDeleteHandlers={};_afterDeleteHandlers={};_operationCompleteHandlers=[];_isEnabled=!0;isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,t){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let i=e;for(const s of r)i=s(i,t);return i}return e}handleAfterCreate(e,t){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const i of r)i(e,t)}handleBeforeChange(e,t,r){if(!this._isEnabled)return t;const i=this._beforeChangeHandlers[t.typeName];if(i){let s=t;for(const o of i)s=o(e,s,r);return s}return t}handleAfterChange(e,t,r){if(!this._isEnabled)return;const i=this._afterChangeHandlers[t.typeName];if(i)for(const s of i)s(e,t,r)}handleBeforeDelete(e,t){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const i of r)if(i(e,t)===!1)return!1}return!0}handleAfterDelete(e,t){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const i of r)i(e,t)}handleOperationComplete(e){if(this._isEnabled)for(const t of this._operationCompleteHandlers)t(e)}register(e){const t=[];for(const[r,i]of Object.entries(e))i?.beforeCreate&&t.push(this.registerBeforeCreateHandler(r,i.beforeCreate)),i?.afterCreate&&t.push(this.registerAfterCreateHandler(r,i.afterCreate)),i?.beforeChange&&t.push(this.registerBeforeChangeHandler(r,i.beforeChange)),i?.afterChange&&t.push(this.registerAfterChangeHandler(r,i.afterChange)),i?.beforeDelete&&t.push(this.registerBeforeDeleteHandler(r,i.beforeDelete)),i?.afterDelete&&t.push(this.registerAfterDeleteHandler(r,i.afterDelete));return()=>{for(const r of t)r()}}registerBeforeCreateHandler(e,t){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(t),()=>td(this._beforeCreateHandlers[e],t)}registerAfterCreateHandler(e,t){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(t),()=>td(this._afterCreateHandlers[e],t)}registerBeforeChangeHandler(e,t){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(t),()=>td(this._beforeChangeHandlers[e],t)}registerAfterChangeHandler(e,t){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(t),()=>td(this._afterChangeHandlers[e],t)}registerBeforeDeleteHandler(e,t){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(t),()=>td(this._beforeDeleteHandlers[e],t)}registerAfterDeleteHandler(e,t){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(t),()=>td(this._afterDeleteHandlers[e],t)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>td(this._operationCompleteHandlers,e)}}function td(n,e){const t=n.indexOf(e);t>=0&&n.splice(t,1)}class GI{id;records;history=bn("history",0,{historyLength:1e3});query;listeners=new Set;historyAccumulator=new CQ;historyReactor;cancelHistoryReactor(){}schema;props;scopedTypes;sideEffects=new vQ(this);constructor(e){const{initialData:t,schema:r,id:i}=e;this.id=i??zt(),this.schema=r,this.props=e.props,t?this.records=new N_("store",Yi(t).map(([s,o])=>[s,this.schema.validateRecord(this,o,"initialize",null)])):this.records=new N_("store"),this.query=new xQ(this.records,this.history),this.historyReactor=AJ("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=CI(s)}),this.scopedTypes={document:new Set(Hn(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(Hn(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(Hn(this.schema.types).filter(s=>s.scope==="presence").map(s=>s.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:t,source:r}of e){let i=null,s=null,o=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(s??=this.filterChangesByScope(t,"document"),!s)continue;a({changes:s,source:r})}else if(l.scope==="session"){if(i??=this.filterChangesByScope(t,"session"),!i)continue;a({changes:i,source:r})}else{if(o??=this.filterChangesByScope(t,"presence"),!o)continue;a({changes:o,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,t){const r={added:Hg(e.added,(i,s)=>this.scopedTypes[t].has(s.typeName)),updated:Hg(e.updated,(i,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:Hg(e.removed,(i,s)=>this.scopedTypes[t].has(s.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(e){this.historyAccumulator.add({changes:e,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,e)}validate(e){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,e,null))}put(e,t){this.atomic(()=>{const r={},i={};let s,o=!1;const a=this.isMergingRemoteChanges?"remote":"user";for(let l=0,u=e.length;l<u;l++){s=e[l];const f=this.records.__unsafe__getWithoutCapture(s.id);if(f){if(s=this.sideEffects.handleBeforeChange(f,s,a),this.schema.validateRecord(this,s,t??"updateRecord",f)===f)continue;s=s,this.records.set(s.id,s),o=!0,r[s.id]=[f,s],this.addDiffForAfterEvent(f,s)}else s=this.sideEffects.handleBeforeCreate(s,a),o=!0,s=this.schema.validateRecord(this,s,t??"createRecord",null),s=s,i[s.id]=s,this.addDiffForAfterEvent(null,s),this.records.set(s.id,s)}o&&this.updateHistory({added:i,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const t=new Set(e),r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const o of e){const a=this.records.__unsafe__getWithoutCapture(o);a&&this.sideEffects.handleBeforeDelete(a,r)===!1&&t.delete(o)}const i=this.records.deleteMany(t);if(i.length===0)return;const s={};for(const[o,a]of i)s[o]=a,this.addDiffForAfterEvent(a,null);this.updateHistory({added:{},updated:{},removed:s})})}get(e){return this.records.get(e)}unsafeGetWithoutCapture(e){return this.records.__unsafe__getWithoutCapture(e)}serialize(e="document"){const t={};for(const[r,i]of this.records)(e==="all"||this.scopedTypes[e].has(i.typeName))&&(t[r]=i);return t}getStoreSnapshot(e="document"){return{store:this.serialize(e),schema:this.schema.serialize()}}migrateSnapshot(e){const t=this.schema.migrateStoreSnapshot(e);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadStoreSnapshot(e){const t=this.schema.migrateStoreSnapshot(e);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(t.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}allRecords(){return Array.from(this.records.values())}clear(){this.remove(Array.from(this.records.keys()))}update(e,t){const r=this.unsafeGetWithoutCapture(e);if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([t(r)])}has(e){return this.records.has(e)}listen(e,t){this._flushHistory();const r={onHistory:e,filters:{source:t?.source??"all",scope:t?.scope??"all"}};return this.historyReactor.scheduler.isActivelyListening||(this.historyReactor.start(),this.historyReactor.scheduler.execute()),this.listeners.add(r),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}isMergingRemoteChanges=!1;mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.atomic(e,!0,!0)}finally{this.ensureStoreIsUsable()}}extractingChanges(e){const t=[],r=this.historyAccumulator.addInterceptor(i=>t.push(i.changes));try{return to(e),VI(t)}finally{r()}}applyDiff(e,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const i=Hn(e.added);for(const[o,a]of Hn(e.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const u=this.get(a.id);if(!u){i.push(a);continue}let f=null;for(const[h,g]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(g,tr(u,h))||(f||(f={...u}),f[h]=g);f&&i.push(f)}else i.push(a)}const s=Ug(e.removed);i.length&&this.put(i),s.length&&this.remove(s)},t)}createCache(e){const t=new Ii;return{get:r=>{const i=this.records.getAtom(r);if(i)return t.get(i,()=>e(r,i)).get()}}}createComputedCache(e,t,r){return this.createCache((i,s)=>{const o=r?.areRecordsEqual?pe(`${e}:${i}:isEqual`,()=>s.get(),{isEqual:r.areRecordsEqual}):s;return pe(e+":"+i,()=>t(o.get()),{isEqual:r?.areResultsEqual})})}_integrityChecker;ensureStoreIsUsable(){this.atomic(()=>{this._integrityChecker??=this.schema.createIntegrityChecker(this),this._integrityChecker?.()})}_isPossiblyCorrupted=!1;markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}pendingAfterEvents=null;addDiffForAfterEvent(e,t){if(Be(this.pendingAfterEvents,"must be in event operation"),e===t||(e&&t&&Be(e.id===t.id),!e&&!t))return;const r=(e||t).id,i=this.pendingAfterEvents.get(r);i?i.after=t:this.pendingAfterEvents.set(r,{before:e,after:t})}flushAtomicCallbacks(e){let t=0,r=e?"remote":"user";for(;this.pendingAfterEvents;){const i=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 i.values())s&&o&&s!==o&&!vu(s,o)?this.sideEffects.handleAfterChange(s,o,r):s&&!o?this.sideEffects.handleAfterDelete(s,r):!s&&o&&this.sideEffects.handleAfterCreate(o,r);this.pendingAfterEvents?r="user":this.sideEffects.handleOperationComplete(r)}}}_isInAtomicOp=!1;atomic(e,t=!0,r=!1){return to(()=>{if(this._isInAtomicOp){this.pendingAfterEvents||(this.pendingAfterEvents=new Map);const s=this.sideEffects.isEnabled();Be(!r,"cannot call mergeRemoteChanges while in atomic operation");try{return s&&!t&&this.sideEffects.setIsEnabled(!1),e()}finally{this.sideEffects.setIsEnabled(s)}}this.pendingAfterEvents=new Map;const i=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(t??i),this._isInAtomicOp=!0,r&&(this.isMergingRemoteChanges=!0);try{const s=e();return this.isMergingRemoteChanges=!1,this.flushAtomicCallbacks(r),s}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(i),this._isInAtomicOp=!1,this.isMergingRemoteChanges=!1}})}addHistoryInterceptor(e){return this.historyAccumulator.addInterceptor(t=>e(t,this.isMergingRemoteChanges?"remote":"user"))}}function wQ(n){if(n.length===0)return[];const e=[];let t=[n[0]],r;for(let i=1,s=n.length;i<s;i++)r=n[i],t[0].source!==r.source&&(e.push(t),t=[]),t.push(r);return e.push(t),e.map(i=>({source:i[0].source,changes:VI(i.map(s=>s.changes))}))}class CQ{_history=[];_interceptors=new Set;addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const t of this._interceptors)t(e)}flush(){const e=wQ(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function Pv(n,e,t){const r=new Ii;return{get(i,s){return r.get(i,()=>(i instanceof GI?i:i.store).createComputedCache(n,l=>e(i,l),t)).get(s)}}}function TQ(n){if(n.schemaVersion>2||n.schemaVersion<1)return Hi.err("Bad schema version");if(n.schemaVersion===2)return Hi.ok(n);const e={schemaVersion:2,sequences:{"com.tldraw.store":n.storeVersion}};for(const[t,r]of Object.entries(n.recordVersions))if(e.sequences[`com.tldraw.${t}`]=r.version,"subTypeKey"in r)for(const[i,s]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${t}.${i}`]=s;return Hi.ok(e)}class YI{constructor(e,t){this.types=e,this.options=t;for(const i of t.migrations??[])Be(!this.migrations[i.sequenceId],`Duplicate migration sequenceId ${i.sequenceId}`),O4(i),this.migrations[i.sequenceId]=i;const r=Object.values(this.migrations).flatMap(i=>i.sequence);this.sortedMigrations=yQ(r);for(const i of this.sortedMigrations)if(i.dependsOn?.length)for(const s of i.dependsOn){const o=r.find(a=>a.id===s);Be(o,`Migration '${i.id}' depends on missing migration '${s}'`)}}static create(e,t){return new YI(e,t??{})}migrations={};sortedMigrations;migrationCache=new WeakMap;validateRecord(e,t,r,i){try{const s=tr(this.types,t.typeName);if(!s)throw new Error(`Missing definition for record type ${t.typeName}`);return s.validate(t,i??void 0)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:t,phase:r,recordBefore:i,error:s});throw s}}getMigrationsSince(e){const t=this.migrationCache.get(e);if(t)return t;const r=TQ(e);if(!r.ok)return this.migrationCache.set(e,r),r;const i=r.value,s=new Set(Object.keys(i.sequences).filter(l=>this.migrations[l]));for(const l in this.migrations)i.sequences[l]===void 0&&this.migrations[l].retroactive&&s.add(l);if(s.size===0){const l=Hi.ok([]);return this.migrationCache.set(e,l),l}const o=new Set;for(const l of s){const u=i.sequences[l];if(typeof u!="number"&&this.migrations[l].retroactive||u===0){for(const g of this.migrations[l].sequence)o.add(g.id);continue}const f=`${l}/${u}`,h=this.migrations[l].sequence.findIndex(g=>g.id===f);if(h===-1){const g=Hi.err("Incompatible schema?");return this.migrationCache.set(e,g),g}for(const g of this.migrations[l].sequence.slice(h+1))o.add(g.id)}const a=Hi.ok(this.sortedMigrations.filter(({id:l})=>o.has(l)));return this.migrationCache.set(e,a),a}migratePersistedRecord(e,t,r="up"){const i=this.getMigrationsSince(t);if(!i.ok)return console.error("Error migrating record",i.error),{type:"error",reason:Uc.MigrationError};let s=i.value;if(s.length===0)return{type:"success",value:e};if(s.some(o=>o.scope==="store"))return{type:"error",reason:r==="down"?Uc.TargetVersionTooOld:Uc.TargetVersionTooNew};if(r==="down"){if(!s.every(o=>o.down))return{type:"error",reason:Uc.TargetVersionTooOld};s=s.slice().reverse()}e=Qn(e);try{for(const o of s){if(o.scope==="store")throw new Error;if(!(o.filter?o.filter(e):!0))continue;const l=o[r](e);l&&(e=Qn(l))}}catch(o){return console.error("Error migrating record",o),{type:"error",reason:Uc.MigrationError}}return{type:"success",value:e}}migrateStoreSnapshot(e,t){let{store:r}=e;const i=this.getMigrationsSince(e.schema);if(!i.ok)return console.error("Error migrating store",i.error),{type:"error",reason:Uc.MigrationError};const s=i.value;if(s.length===0)return{type:"success",value:r};t?.mutateInputStore||(r=Qn(r));try{for(const o of s)if(o.scope==="record")for(const[a,l]of Object.entries(r)){if(!(o.filter?o.filter(l):!0))continue;const f=o.up(l);f&&(r[a]=f)}else if(o.scope==="store"){const a=o.up(r);a&&(r=a)}else kt(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Uc.MigrationError}}return{type:"success",value:r}}createIntegrityChecker(e){return this.options.createIntegrityChecker?.(e)??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:t})=>[e,t.length?Xb(t.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const t=tr(this.types,e);return Be(t,"record type does not exists"),t}}xu("@tldraw/store","4.1.2","esm");function EQ(n){if(!n.length)return null;let e="";for(const t of n)typeof t=="number"?e+=`.${t}`:t.startsWith("(")?e.endsWith(")")?e=`${e.slice(0,-1)}, ${t.slice(1)}`:e+=t:e+=`.${t}`;return e=e.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),e.startsWith(".")?e.slice(1):e}class Rt extends Error{constructor(e,t=[]){const r=EQ(t),i=e.split(`
29
+ `+" ".repeat(o)+"↳ ";for(const[l,u]of Object.entries(s))u?(r+=`${a}Computed(${l}) changed`,i(u,o+2)):r+=`${a}Atom(${l}) changed`}i(t,1),console.log(r)}class qJ{constructor(e,t,r){this.name=e,this.current=t,this.isEqual=r?.isEqual??null,r&&(r.historyLength&&(this.historyBuffer=new S4(r.historyLength)),this.computeDiff=r.computeDiff)}isEqual;computeDiff;lastChangedEpoch=Ts();children=new Yb;historyBuffer;__unsafe__getWithoutCapture(e){return this.current}get(){return Wb(this),this.current}set(e,t){if(this.isEqual?.(this.current,e)??y4(this.current,e))return this.current;LJ(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Ts(),t??this.computeDiff?.(this.current,e,this.lastChangedEpoch,Ts())??eo),this.lastChangedEpoch=Ts();const r=this.current;return this.current=e,jJ(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){return Wb(this),e>=this.lastChangedEpoch?qn:this.historyBuffer?.getChangesSince(e)??eo}}const VJ=Eu("Atom",()=>qJ);function bn(n,e,t){return new VJ(n,e,t)}const _4=1,GJ=Eu("apiVersion",()=>_4);if(GJ!==_4)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");xu("@tldraw/state","4.1.2","esm");function Cv(n,e,t=[]){const r=Ge.useRef(e);r.current=e;const[i,s,o]=Ge.useMemo(()=>{let a=null;const l=h=>(a=h,()=>{a=null}),u=new Kd(`useStateTracking(${n})`,()=>r.current?.(),{scheduleEffect(){a?.()}});return[u,l,()=>u.scheduleCount]},[n,...t]);return Ge.useSyncExternalStore(s,o,o),Ge.useEffect(()=>(i.attach(),i.maybeScheduleEffect(),()=>{i.detach()}),[i]),i.execute()}const KL={apply(n,e,t){return Cv(n.displayName??n.name??"tracked(???)",()=>n.apply(e,t))}},YJ=Symbol.for("react.memo"),WJ=Symbol.for("react.forward_ref");function sr(n){let e=null;const t=n.$$typeof;return t===YJ&&(n=n.type,e=n.compare),t===WJ?E.memo(E.forwardRef(new Proxy(n.render,KL))):E.memo(new Proxy(n,KL),e)}function Wm(n,e,t){return E.useState(()=>{const r=typeof e=="function"?e():e;return bn(`useAtom(${n})`,r,t)})[0]}function XJ(){const n=arguments[0],e=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return E.useMemo(()=>pe(`useComputed(${n})`,e,t),r)}function wd(n,e,t=qn){E.useEffect(()=>{const r=new Kd(n,e);return r.attach(),r.execute(),()=>{r.detach()}},t)}function NI(n,e,t=[]){E.useEffect(()=>{let r;const i=new Kd(n,e,{scheduleEffect:s=>{r=CI(s)}});return i.attach(),i.execute(),()=>{i.detach(),r?.()}},t)}function ee(){const n=arguments,e=n.length===3?n[2]:[n[0]],t=n.length===3?n[0]:`useValue(${n[0].name})`,{$val:r,subscribe:i,getSnapshot:s}=E.useMemo(()=>{const o=n.length===1?n[0]:pe(t,n[1]);return{$val:o,subscribe:a=>Ms(`useValue(${t})`,()=>{try{o.get()}catch{}a()}),getSnapshot:()=>o.lastChangedEpoch}},e);return E.useSyncExternalStore(i,s,s),r.__unsafe__getWithoutCapture()}xu("@tldraw/state-react","4.1.2","esm");function zI(n){return n>>>1&1073741824|n&3221225471}const ZJ=Object.prototype.valueOf;function Cd(n){if(n==null)return qL(n);if(typeof n.hashCode=="function")return zI(n.hashCode(n));const e=nQ(n);if(e==null)return qL(e);switch(typeof e){case"boolean":return e?1108378657:1108378656;case"number":return JJ(e);case"string":return e.length>rQ?QJ(e):L_(e);case"object":case"function":return tQ(e);case"symbol":return eQ(e);default:if(typeof e.toString=="function")return L_(e.toString());throw new Error("Value type "+typeof e+" cannot be hashed.")}}function qL(n){return n===null?1108378658:1108378659}function JJ(n){if(n!==n||n===1/0)return 0;let e=n|0;for(e!==n&&(e^=n*4294967295);n>4294967295;)n/=4294967295,e^=n;return zI(e)}function QJ(n){let e=hE[n];return e===void 0&&(e=L_(n),dE===iQ&&(dE=0,hE={}),dE++,hE[n]=e),e}function L_(n){let e=0;for(let t=0;t<n.length;t++)e=31*e+n.charCodeAt(t)|0;return zI(e)}function eQ(n){let e=GL[n];return e!==void 0||(e=P4(),GL[n]=e),e}function tQ(n){let e=VL.get(n);return e!==void 0||(e=P4(),VL.set(n,e)),e}function nQ(n){return n.valueOf!==ZJ&&typeof n.valueOf=="function"?n.valueOf(n):n}function P4(){const n=++uE;return uE&1073741824&&(uE=0),n}const VL=new WeakMap,GL=Object.create(null);let uE=0;const rQ=16,iQ=255;let dE=0,hE={};const kf=5,Xm=1<<kf,Af=Xm-1,Yl={};function YL(){return{value:!1}}function la(n){n&&(n.value=!0)}function BI(n,e){e=e||0;const t=Math.max(0,n.length-e),r=new Array(t);for(let i=0;i<t;i++)r[i]=n[i+e];return r}const Of=Object.is;class I4{}class FI{_root;size;__ownerID;__hash;__altered;constructor(e){return e==null?Sf():e instanceof FI?e:Sf().withMutations(t=>{for(const[r,i]of e)t.set(r,i)})}get(e,t){return this._root?this._root.get(0,void 0,e,t):t}set(e,t){return ZL(this,e,t)}delete(e){return ZL(this,e,Yl)}deleteAll(e){return this.withMutations(t=>{for(const r of e)t.delete(r)})}__ensureOwner(e){return e===this.__ownerID?this:e?$I(this.size,this._root,e,this.__hash):this.size===0?Sf():(this.__ownerID=e,this.__altered=!1,this)}withMutations(e){const t=this.asMutable();return e(t),t.wasAltered()?t.__ensureOwner(this.__ownerID):this}wasAltered(){return this.__altered}asMutable(){return this.__ownerID?this:this.__ensureOwner(new I4)}[Symbol.iterator](){return this.entries()[Symbol.iterator]()}entries(){return new fE(this,sQ,!1)}keys(){return new fE(this,M4,!1)}values(){return new fE(this,k4,!1)}}class UI{constructor(e,t){this.ownerID=e,this.entries=t}get(e,t,r,i){const s=this.entries;for(let o=0,a=s.length;o<a;o++)if(Of(r,s[o][0]))return s[o][1];return i}update(e,t,r,i,s,o,a){const l=s===Yl,u=this.entries;let f=0;const h=u.length;for(;f<h&&!Of(i,u[f][0]);f++);const g=f<h;if(g?u[f][1]===s:l)return this;if(la(a),(l||!g)&&la(o),l&&u.length===1)return;if(!g&&!l&&u.length>=fQ)return lQ(e,u,i,s);const y=e&&e===this.ownerID,b=y?u:BI(u);return g?l?f===h-1?b.pop():b[f]=b.pop():b[f]=[i,s]:b.push([i,s]),y?(this.entries=b,this):new UI(e,b)}}class Tv{constructor(e,t,r){this.ownerID=e,this.bitmap=t,this.nodes=r}get(e,t,r,i){t===void 0&&(t=Cd(r));const s=1<<((e===0?t:t>>>e)&Af),o=this.bitmap;return(o&s)===0?i:this.nodes[QL(o&s-1)].get(e+kf,t,r,i)}update(e,t,r,i,s,o,a){r===void 0&&(r=Cd(i));const l=(t===0?r:r>>>t)&Af,u=1<<l,f=this.bitmap,h=(f&u)!==0;if(!h&&s===Yl)return this;const g=QL(f&u-1),y=this.nodes,b=h?y[g]:void 0,v=KI(b,e,t+kf,r,i,s,o,a);if(v===b)return this;if(!h&&v&&y.length>=pQ)return uQ(e,y,f,l,v);if(h&&!v&&y.length===2&&JL(y[g^1]))return y[g^1];if(h&&v&&y.length===1&&JL(v))return v;const w=e&&e===this.ownerID,x=h?v?f:f^u:f|u,T=h?v?A4(y,g,v,w):hQ(y,g,w):dQ(y,g,v,w);return w?(this.bitmap=x,this.nodes=T,this):new Tv(e,x,T)}}class HI{constructor(e,t,r){this.ownerID=e,this.count=t,this.nodes=r}get(e,t,r,i){t===void 0&&(t=Cd(r));const s=(e===0?t:t>>>e)&Af,o=this.nodes[s];return o?o.get(e+kf,t,r,i):i}update(e,t,r,i,s,o,a){r===void 0&&(r=Cd(i));const l=(t===0?r:r>>>t)&Af,u=s===Yl,f=this.nodes,h=f[l];if(u&&!h)return this;const g=KI(h,e,t+kf,r,i,s,o,a);if(g===h)return this;let y=this.count;if(!h)y++;else if(!g&&(y--,y<gQ))return cQ(e,f,y,l);const b=e&&e===this.ownerID,v=A4(f,l,g,b);return b?(this.count=y,this.nodes=v,this):new HI(e,y,v)}}class Ev{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entries=r}get(e,t,r,i){const s=this.entries;for(let o=0,a=s.length;o<a;o++)if(Of(r,s[o][0]))return s[o][1];return i}update(e,t,r,i,s,o,a){r===void 0&&(r=Cd(i));const l=s===Yl;if(r!==this.keyHash)return l?this:(la(a),la(o),qI(this,e,t,r,[i,s]));const u=this.entries;let f=0;const h=u.length;for(;f<h&&!Of(i,u[f][0]);f++);const g=f<h;if(g?u[f][1]===s:l)return this;if(la(a),(l||!g)&&la(o),l&&h===2)return new qd(e,this.keyHash,u[f^1]);const y=e&&e===this.ownerID,b=y?u:BI(u);return g?l?f===h-1?b.pop():b[f]=b.pop():b[f]=[i,s]:b.push([i,s]),y?(this.entries=b,this):new Ev(e,this.keyHash,b)}}class qd{constructor(e,t,r){this.ownerID=e,this.keyHash=t,this.entry=r}get(e,t,r,i){return Of(r,this.entry[0])?this.entry[1]:i}update(e,t,r,i,s,o,a){const l=s===Yl,u=Of(i,this.entry[0]);if(u?s===this.entry[1]:l)return this;if(la(a),l){la(o);return}return u?e&&e===this.ownerID?(this.entry[1]=s,this):new qd(e,this.keyHash,[i,s]):(la(o),qI(this,e,t,Cd(i),[i,s]))}}class fE{constructor(e,t,r){this._type=t,this._reverse=r,this._stack=e._root&&WL(e._root)}_stack;[Symbol.iterator](){return this}next(){const e=this._type;let t=this._stack;for(;t;){const r=t.node,i=t.index++;let s;if(r.entry){if(i===0)return pE(e,r.entry)}else if("entries"in r&&r.entries){if(s=r.entries.length-1,i<=s)return pE(e,r.entries[this._reverse?s-i:i])}else if(s=r.nodes.length-1,i<=s){const o=r.nodes[this._reverse?s-i:i];if(o){if(o.entry)return pE(e,o.entry);t=this._stack=WL(o,t)}continue}t=this._stack=this._stack.__prev}return aQ()}}function pE(n,e){return oQ(n,e[0],e[1])}function WL(n,e){return{node:n,index:0,__prev:e}}const M4=0,k4=1,sQ=2;function oQ(n,e,t,r){const i=n===M4?e:n===k4?t:[e,t];return r?r.value=i:r={value:i,done:!1},r}function aQ(){return{value:void 0,done:!0}}function $I(n,e,t,r){const i=Object.create(FI.prototype);return i.size=n,i._root=e,i.__ownerID=t,i.__hash=r,i.__altered=!1,i}let XL;function Sf(){return XL||(XL=$I(0))}function ZL(n,e,t){let r,i;if(n._root){const s=YL(),o=YL();if(r=KI(n._root,n.__ownerID,0,void 0,e,t,s,o),!o.value)return n;i=n.size+(s.value?t===Yl?-1:1:0)}else{if(t===Yl)return n;i=1,r=new UI(n.__ownerID,[[e,t]])}return n.__ownerID?(n.size=i,n._root=r,n.__hash=void 0,n.__altered=!0,n):r?$I(i,r):Sf()}function KI(n,e,t,r,i,s,o,a){return n?n.update(e,t,r,i,s,o,a):s===Yl?n:(la(a),la(o),new qd(e,r,[i,s]))}function JL(n){return n.constructor===qd||n.constructor===Ev}function qI(n,e,t,r,i){if(n.keyHash===r)return new Ev(e,r,[n.entry,i]);const s=(t===0?n.keyHash:n.keyHash>>>t)&Af,o=(t===0?r:r>>>t)&Af;let a;const l=s===o?[qI(n,e,t+kf,r,i)]:(a=new qd(e,r,i),s<o?[n,a]:[a,n]);return new Tv(e,1<<s|1<<o,l)}function lQ(n,e,t,r){n||(n=new I4);let i=new qd(n,Cd(t),[t,r]);for(let s=0;s<e.length;s++){const o=e[s];i=i.update(n,0,void 0,o[0],o[1])}return i}function cQ(n,e,t,r){let i=0,s=0;const o=new Array(t);for(let a=0,l=1,u=e.length;a<u;a++,l<<=1){const f=e[a];f!==void 0&&a!==r&&(i|=l,o[s++]=f)}return new Tv(n,i,o)}function uQ(n,e,t,r,i){let s=0;const o=new Array(Xm);for(let a=0;t!==0;a++,t>>>=1)o[a]=t&1?e[s++]:void 0;return o[r]=i,new HI(n,s+1,o)}function QL(n){return n-=n>>1&1431655765,n=(n&858993459)+(n>>2&858993459),n=n+(n>>4)&252645135,n+=n>>8,n+=n>>16,n&127}function A4(n,e,t,r){const i=r?n:BI(n);return i[e]=t,i}function dQ(n,e,t,r){const i=n.length+1;if(r&&e+1===i)return n[e]=t,n;const s=new Array(i);let o=0;for(let a=0;a<i;a++)a===e?(s[a]=t,o=-1):s[a]=n[a+o];return s}function hQ(n,e,t){const r=n.length-1;if(t&&e===r)return n.pop(),n;const i=new Array(r);let s=0;for(let o=0;o<r;o++)o===e&&(s=1),i[o]=n[o+s];return i}const fQ=Xm/4,pQ=Xm/2,gQ=Xm/4;class N_{constructor(e,t){this.name=e;let r=Sf();t&&(r=r.withMutations(i=>{for(const[s,o]of t)i.set(s,bn(`${e}:${String(s)}`,o))})),this.atoms=bn(`${e}:atoms`,r)}atoms;getAtom(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t){this.atoms.get();return}return t}get(e){const t=this.getAtom(e)?.get();return Be(t!==xi),t}__unsafe__getWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);if(!t)return;const r=t.__unsafe__getWithoutCapture();return Be(r!==xi),r}has(e){const t=this.getAtom(e);return t?t.get()!==xi:!1}__unsafe__hasWithoutCapture(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(Be(t.__unsafe__getWithoutCapture()!==xi),!0):!1}set(e,t){const r=this.atoms.__unsafe__getWithoutCapture().get(e);return r?r.set(t):this.atoms.update(i=>i.set(e,bn(`${this.name}:${String(e)}`,t))),this}update(e,t){const r=this.atoms.__unsafe__getWithoutCapture().get(e);if(!r)throw new Error(`AtomMap: key ${e} not found`);const i=r.__unsafe__getWithoutCapture();Be(i!==xi),r.set(t(i))}delete(e){const t=this.atoms.__unsafe__getWithoutCapture().get(e);return t?(to(()=>{t.set(xi),this.atoms.update(r=>r.delete(e))}),!0):!1}deleteMany(e){return to(()=>{const t=[],r=this.atoms.get().withMutations(i=>{for(const s of e){const o=i.get(s);if(!o)continue;const a=o.get();Be(a!==xi),t.push([s,a]),i.delete(s),o.set(xi)}});return t.length&&this.atoms.set(r),t})}clear(){return to(()=>{for(const e of this.atoms.__unsafe__getWithoutCapture().values())e.set(xi);this.atoms.set(Sf())})}*entries(){for(const[e,t]of this.atoms.get()){const r=t.get();Be(r!==xi),yield[e,r]}}*keys(){for(const e of this.atoms.get().keys())yield e}*values(){for(const e of this.atoms.get().values()){const t=e.get();Be(t!==xi),yield t}}get size(){return this.atoms.get().size}forEach(e,t){for(const[r,i]of this.entries())e.call(t,i,r,this)}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="AtomMap"}class Ib{constructor(e){this.previousValue=e}nextValue;diff;get(){const e=this.diff?.removed?.size??0,t=this.diff?.added?.size??0;if(!(e===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(e,t){this.nextValue??=new Set(this.previousValue),this.nextValue.add(e),this.diff??={},t?this.diff.removed?.delete(e):(this.diff.added??=new Set,this.diff.added.add(e))}add(e){const t=this.previousValue.has(e);if(t)return this.diff?.removed?.has(e)?this._add(e,t):void 0;this.nextValue?.has(e)||this._add(e,t)}_remove(e,t){this.nextValue??=new Set(this.previousValue),this.nextValue.delete(e),this.diff??={},t?(this.diff.removed??=new Set,this.diff.removed.add(e)):this.diff.added?.delete(e)}remove(e){const t=this.previousValue.has(e);if(!t)return this.diff?.added?.has(e)?this._remove(e,t):void 0;this.diff?.removed?.has(e)||this._remove(e,t)}}function mQ(n){const e=[];for(let t=n.length-1;t>=0;t--){const r=n[t];if("id"in r)e.unshift(r);else{const i=r.dependsOn,s=e[0];s&&(e[0]={...s,dependsOn:i.concat(s.dependsOn??[])})}}return e}function bf({sequence:n,sequenceId:e,retroactive:t=!0}){const r={sequenceId:e,retroactive:t,sequence:mQ(n)};return O4(r),r}function Ds(n,e){return Object.fromEntries(Yi(e).map(([t,r])=>[t,`${n}/${r}`]))}function lo(n){const e=n.sequenceId;return bf({sequenceId:e,retroactive:n.retroactive??!0,sequence:n.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>r.typeName===n.recordType&&(t.filter?.(r)??!0)&&(n.filter?.(r)??!0)}:t)})}function yQ(n){if(n.length===0)return[];const e=new Map(n.map(l=>[l.id,l])),t=new Map,r=new Map,i=new Map;for(const l of n)r.set(l.id,0),t.set(l.id,new Set),i.set(l.id,new Set);for(const l of n){const{version:u,sequenceId:f}=Xb(l.id),h=`${f}/${u-1}`;if(e.has(h)&&(t.get(h).add(l.id),r.set(l.id,r.get(l.id)+1)),l.dependsOn)for(const g of l.dependsOn)e.has(g)&&(t.get(g).add(l.id),i.get(l.id).add(g),r.set(l.id,r.get(l.id)+1))}const s=n.filter(l=>r.get(l.id)===0),o=[],a=new Set;for(;s.length>0;){let l,u=-1/0;for(const h of s){let g=0;for(const y of t.get(h.id)||[])a.has(y)||(g+=1,i.get(y).has(h.id)&&(g+=100));(g>u||g===u&&h.id.localeCompare(l?.id??"")<0)&&(l=h,u=g)}const f=l;s.splice(s.indexOf(f),1),o.push(f),a.add(f.id);for(const h of t.get(f.id)||[])a.has(h)||(r.set(h,r.get(h)-1),r.get(h)===0&&s.push(e.get(h)))}if(o.length!==n.length){const l=n.filter(u=>!a.has(u.id));Be(!1,`Circular dependency in migrations: ${l[0].id}`)}return o}function Xb(n){const[e,t]=n.split("/");return{sequenceId:e,version:parseInt(t)}}function e3(n,e){e&&Be(n.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${n}'`),Be(n.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${n}'`)}function O4(n){if(Be(!n.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${n.sequenceId}`),Be(n.sequenceId.length,"sequenceId must be a non-empty string"),n.sequence.length===0)return;e3(n.sequence[0].id,n.sequenceId);let e=Xb(n.sequence[0].id).version;Be(e===1,`Expected the first migrationId to be '${n.sequenceId}/1' but got '${n.sequence[0].id}'`);for(let t=1;t<n.sequence.length;t++){const r=n.sequence[t].id;e3(r,n.sequenceId);const i=Xb(r).version;Be(i===e+1,`Migration id numbers must increase in increments of 1, expected ${n.sequenceId}/${e+1} but got '${n.sequence[t].id}'`),e=i}}var Uc=(n=>(n.IncompatibleSubtype="incompatible-subtype",n.UnknownType="unknown-type",n.TargetVersionTooNew="target-version-too-new",n.TargetVersionTooOld="target-version-too-old",n.MigrationError="migration-error",n.UnrecognizedSubtype="unrecognized-subtype",n))(Uc||{});function Zb(){return{added:{},updated:{},removed:{}}}function z_(n){const e={added:n.removed,removed:n.added,updated:{}};for(const[t,r]of Object.values(n.updated))e.updated[t.id]=[r,t];return e}function D4(n){return Object.keys(n.added).length===0&&Object.keys(n.updated).length===0&&Object.keys(n.removed).length===0}function VI(n,e){const t=e?.mutateFirstDiff?n[0]:{added:{},removed:{},updated:{}};return $g(t,n),t}function $g(n,e){for(const t of e){for(const[r,i]of Yi(t.added))if(n.removed[r]){const s=n.removed[r];delete n.removed[r],s!==i&&(n.updated[r]=[s,i])}else n.added[r]=i;for(const[r,[i,s]]of Yi(t.updated)){if(n.added[r]){n.added[r]=s,delete n.updated[r],delete n.removed[r];continue}if(n.updated[r]){n.updated[r]=[n.updated[r][0],s],delete n.removed[r];continue}n.updated[r]=t.updated[r],delete n.removed[r]}for(const[r,i]of Yi(t.removed))n.added[r]?delete n.added[r]:n.updated[r]?(n.removed[r]=n.updated[r][0],delete n.updated[r]):n.removed[r]=i}}class _v{constructor(e,t){this.typeName=e,this.createDefaultProperties=t.createDefaultProperties,this.validator=t.validator??{validate:i=>i},this.scope=t.scope??"document",this.ephemeralKeys=t.ephemeralKeys;const r=new Set;if(t.ephemeralKeys)for(const[i,s]of Yi(t.ephemeralKeys))s&&r.add(i);this.ephemeralKeySet=r}createDefaultProperties;validator;ephemeralKeys;ephemeralKeySet;scope;create(e){const t={...this.createDefaultProperties(),id:"id"in e?e.id:this.createId()};for(const[r,i]of Object.entries(e))i!==void 0&&(t[r]=i);return t.typeName=this.typeName,t}clone(e){return{...Qn(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??zt())}parseId(e){if(!this.isId(e))throw new Error(`ID "${e}" is not a valid ID for type "${this.typeName}"`);return e.slice(this.typeName.length+1)}isInstance(e){return e?.typeName===this.typeName}isId(e){if(!e)return!1;for(let t=0;t<this.typeName.length;t++)if(e[t]!==this.typeName[t])return!1;return e[this.typeName.length]===":"}withDefaultProperties(e){return new _v(this.typeName,{createDefaultProperties:e,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(e,t){return t&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(t,e):this.validator.validate(e)}}function Qa(n,e){return new _v(n,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function SQ(n){if(n.length===0)return new Set;const e=n[0],t=n.slice(1),r=new Set;for(const i of e)t.every(s=>s.has(i))&&r.add(i);return r}function bQ(n,e){const t={};for(const r of e)n.has(r)||(t.added??=new Set,t.added.add(r));for(const r of n)e.has(r)||(t.removed??=new Set,t.removed.add(r));return t.added||t.removed?t:void 0}function t3(n,e){for(const[t,r]of Object.entries(n)){const i=r,s=e[t];if("eq"in i&&s!==i.eq||"neq"in i&&s===i.neq||"gt"in i&&(typeof s!="number"||s<=i.gt))return!1}return!0}function n3(n,e,t){const r=Object.fromEntries(Object.keys(t).map(i=>[i,new Set]));for(const[i,s]of Object.entries(t))if("eq"in s){const a=n.index(e,i).get().get(s.eq);if(a)for(const l of a)r[i].add(l)}else if("neq"in s){const o=n.index(e,i);for(const[a,l]of o.get())if(a!==s.neq)for(const u of l)r[i].add(u)}else if("gt"in s){const o=n.index(e,i);for(const[a,l]of o.get())if(a>s.gt)for(const u of l)r[i].add(u)}return SQ(Object.values(r))}class xQ{constructor(e,t){this.recordMap=e,this.history=t}indexCache=new Map;historyCache=new Map;filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const t=pe("filterHistory:"+e,(r,i)=>{if(pd(r))return this.history.get();const s=this.history.getDiffSince(i);if(s===eo)return this.history.get();const o={added:{},removed:{},updated:{}};let a=0,l=0,u=0;for(const f of s){for(const h of Hn(f.added))if(h.typeName===e)if(o.removed[h.id]){const g=o.removed[h.id];delete o.removed[h.id],l--,g!==h&&(o.updated[h.id]=[g,h],u++)}else o.added[h.id]=h,a++;for(const[h,g]of Hn(f.updated))g.typeName===e&&(o.added[g.id]?o.added[g.id]=g:o.updated[g.id]?o.updated[g.id]=[o.updated[g.id][0],g]:(o.updated[g.id]=[h,g],u++));for(const h of Hn(f.removed))h.typeName===e&&(o.added[h.id]?(delete o.added[h.id],a--):o.updated[h.id]?(o.removed[h.id]=o.updated[h.id][0],delete o.updated[h.id],u--,l++):(o.removed[h.id]=h,l++))}return a||l||u?wg(this.history.get(),o):r},{historyLength:100});return this.historyCache.set(e,t),t}index(e,t){const r=e+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const i=this.__uncached_createIndex(e,t);return this.indexCache.set(r,i),i}__uncached_createIndex(e,t){const r=this.filterHistory(e),i=()=>{r.get();const s=new Map;for(const o of this.recordMap.values())if(o.typeName===e){const a=o[t];s.has(a)||s.set(a,new Set),s.get(a).add(o.id)}return s};return pe("index:"+e+":"+t,(s,o)=>{if(pd(s))return i();const a=r.getDiffSince(o);if(a===eo)return i();const l=new Map,u=(y,b)=>{let v=l.get(y);v||(v=new Ib(s.get(y)??new Set)),v.add(b),l.set(y,v)},f=(y,b)=>{let v=l.get(y);v||(v=new Ib(s.get(y)??new Set)),v.remove(b),l.set(y,v)};for(const y of a){for(const b of Hn(y.added))if(b.typeName===e){const v=b[t];u(v,b.id)}for(const[b,v]of Hn(y.updated))if(v.typeName===e){const w=b[t],x=v[t];w!==x&&(f(w,v.id),u(x,v.id))}for(const b of Hn(y.removed))if(b.typeName===e){const v=b[t];f(v,b.id)}}let h,g;for(const[y,b]of l){const v=b.get();v&&(h||(h=new Map(s)),g||(g=new Map),v.value.size===0?h.delete(y):h.set(y,v.value),g.set(y,v.diff))}return h&&g?wg(h,g):s},{historyLength:100})}record(e,t=()=>({}),r="record:"+e+(t?":"+t.toString():"")){const i=this.ids(e,t,r);return pe(r,()=>{for(const s of i.get())return this.recordMap.get(s)})}records(e,t=()=>({}),r="records:"+e+(t?":"+t.toString():"")){const i=this.ids(e,t,"ids:"+r);return pe(r,()=>Array.from(i.get(),s=>this.recordMap.get(s)),{isEqual:qb})}ids(e,t=()=>({}),r="ids:"+e+(t?":"+t.toString():"")){const i=this.filterHistory(e),s=()=>{i.get();const l=t();if(Object.keys(l).length===0){const u=new Set;for(const f of this.recordMap.values())f.typeName===e&&u.add(f.id);return u}return n3(this,e,l)},o=l=>{const u=s(),f=bQ(l,u);return f?wg(u,f):l},a=pe("ids_query:"+r,t,{isEqual:vu});return pe("query:"+r,(l,u)=>{const f=a.get();if(pd(l))return s();if(u<a.lastChangedEpoch)return o(l);const h=i.getDiffSince(u);if(h===eo)return o(l);const g=new Ib(l);for(const b of h){for(const v of Hn(b.added))v.typeName===e&&t3(f,v)&&g.add(v.id);for(const[v,w]of Hn(b.updated))w.typeName===e&&(t3(f,w)?g.add(w.id):g.remove(w.id));for(const v of Hn(b.removed))v.typeName===e&&g.remove(v.id)}const y=g.get();return y?wg(y.value,y.diff):l},{historyLength:50})}exec(e,t){const r=n3(this,e,t);return r.size===0?qn:Array.from(r,i=>this.recordMap.get(i))}}class vQ{constructor(e){this.store=e}_beforeCreateHandlers={};_afterCreateHandlers={};_beforeChangeHandlers={};_afterChangeHandlers={};_beforeDeleteHandlers={};_afterDeleteHandlers={};_operationCompleteHandlers=[];_isEnabled=!0;isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,t){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let i=e;for(const s of r)i=s(i,t);return i}return e}handleAfterCreate(e,t){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const i of r)i(e,t)}handleBeforeChange(e,t,r){if(!this._isEnabled)return t;const i=this._beforeChangeHandlers[t.typeName];if(i){let s=t;for(const o of i)s=o(e,s,r);return s}return t}handleAfterChange(e,t,r){if(!this._isEnabled)return;const i=this._afterChangeHandlers[t.typeName];if(i)for(const s of i)s(e,t,r)}handleBeforeDelete(e,t){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const i of r)if(i(e,t)===!1)return!1}return!0}handleAfterDelete(e,t){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const i of r)i(e,t)}handleOperationComplete(e){if(this._isEnabled)for(const t of this._operationCompleteHandlers)t(e)}register(e){const t=[];for(const[r,i]of Object.entries(e))i?.beforeCreate&&t.push(this.registerBeforeCreateHandler(r,i.beforeCreate)),i?.afterCreate&&t.push(this.registerAfterCreateHandler(r,i.afterCreate)),i?.beforeChange&&t.push(this.registerBeforeChangeHandler(r,i.beforeChange)),i?.afterChange&&t.push(this.registerAfterChangeHandler(r,i.afterChange)),i?.beforeDelete&&t.push(this.registerBeforeDeleteHandler(r,i.beforeDelete)),i?.afterDelete&&t.push(this.registerAfterDeleteHandler(r,i.afterDelete));return()=>{for(const r of t)r()}}registerBeforeCreateHandler(e,t){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(t),()=>td(this._beforeCreateHandlers[e],t)}registerAfterCreateHandler(e,t){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(t),()=>td(this._afterCreateHandlers[e],t)}registerBeforeChangeHandler(e,t){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(t),()=>td(this._beforeChangeHandlers[e],t)}registerAfterChangeHandler(e,t){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(t),()=>td(this._afterChangeHandlers[e],t)}registerBeforeDeleteHandler(e,t){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(t),()=>td(this._beforeDeleteHandlers[e],t)}registerAfterDeleteHandler(e,t){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(t),()=>td(this._afterDeleteHandlers[e],t)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>td(this._operationCompleteHandlers,e)}}function td(n,e){const t=n.indexOf(e);t>=0&&n.splice(t,1)}class GI{id;records;history=bn("history",0,{historyLength:1e3});query;listeners=new Set;historyAccumulator=new CQ;historyReactor;cancelHistoryReactor(){}schema;props;scopedTypes;sideEffects=new vQ(this);constructor(e){const{initialData:t,schema:r,id:i}=e;this.id=i??zt(),this.schema=r,this.props=e.props,t?this.records=new N_("store",Yi(t).map(([s,o])=>[s,this.schema.validateRecord(this,o,"initialize",null)])):this.records=new N_("store"),this.query=new xQ(this.records,this.history),this.historyReactor=AJ("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=CI(s)}),this.scopedTypes={document:new Set(Hn(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(Hn(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(Hn(this.schema.types).filter(s=>s.scope==="presence").map(s=>s.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:t,source:r}of e){let i=null,s=null,o=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(s??=this.filterChangesByScope(t,"document"),!s)continue;a({changes:s,source:r})}else if(l.scope==="session"){if(i??=this.filterChangesByScope(t,"session"),!i)continue;a({changes:i,source:r})}else{if(o??=this.filterChangesByScope(t,"presence"),!o)continue;a({changes:o,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,t){const r={added:Hg(e.added,(i,s)=>this.scopedTypes[t].has(s.typeName)),updated:Hg(e.updated,(i,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:Hg(e.removed,(i,s)=>this.scopedTypes[t].has(s.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(e){this.historyAccumulator.add({changes:e,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,e)}validate(e){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,e,null))}put(e,t){this.atomic(()=>{const r={},i={};let s,o=!1;const a=this.isMergingRemoteChanges?"remote":"user";for(let l=0,u=e.length;l<u;l++){s=e[l];const f=this.records.__unsafe__getWithoutCapture(s.id);if(f){if(s=this.sideEffects.handleBeforeChange(f,s,a),this.schema.validateRecord(this,s,t??"updateRecord",f)===f)continue;s=s,this.records.set(s.id,s),o=!0,r[s.id]=[f,s],this.addDiffForAfterEvent(f,s)}else s=this.sideEffects.handleBeforeCreate(s,a),o=!0,s=this.schema.validateRecord(this,s,t??"createRecord",null),s=s,i[s.id]=s,this.addDiffForAfterEvent(null,s),this.records.set(s.id,s)}o&&this.updateHistory({added:i,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const t=new Set(e),r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const o of e){const a=this.records.__unsafe__getWithoutCapture(o);a&&this.sideEffects.handleBeforeDelete(a,r)===!1&&t.delete(o)}const i=this.records.deleteMany(t);if(i.length===0)return;const s={};for(const[o,a]of i)s[o]=a,this.addDiffForAfterEvent(a,null);this.updateHistory({added:{},updated:{},removed:s})})}get(e){return this.records.get(e)}unsafeGetWithoutCapture(e){return this.records.__unsafe__getWithoutCapture(e)}serialize(e="document"){const t={};for(const[r,i]of this.records)(e==="all"||this.scopedTypes[e].has(i.typeName))&&(t[r]=i);return t}getStoreSnapshot(e="document"){return{store:this.serialize(e),schema:this.schema.serialize()}}migrateSnapshot(e){const t=this.schema.migrateStoreSnapshot(e);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadStoreSnapshot(e){const t=this.schema.migrateStoreSnapshot(e);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(t.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}allRecords(){return Array.from(this.records.values())}clear(){this.remove(Array.from(this.records.keys()))}update(e,t){const r=this.unsafeGetWithoutCapture(e);if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([t(r)])}has(e){return this.records.has(e)}listen(e,t){this._flushHistory();const r={onHistory:e,filters:{source:t?.source??"all",scope:t?.scope??"all"}};return this.historyReactor.scheduler.isActivelyListening||(this.historyReactor.start(),this.historyReactor.scheduler.execute()),this.listeners.add(r),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}isMergingRemoteChanges=!1;mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.atomic(e,!0,!0)}finally{this.ensureStoreIsUsable()}}extractingChanges(e){const t=[],r=this.historyAccumulator.addInterceptor(i=>t.push(i.changes));try{return to(e),VI(t)}finally{r()}}applyDiff(e,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const i=Hn(e.added);for(const[o,a]of Hn(e.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const u=this.get(a.id);if(!u){i.push(a);continue}let f=null;for(const[h,g]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(g,tr(u,h))||(f||(f={...u}),f[h]=g);f&&i.push(f)}else i.push(a)}const s=Ug(e.removed);i.length&&this.put(i),s.length&&this.remove(s)},t)}createCache(e){const t=new Ii;return{get:r=>{const i=this.records.getAtom(r);if(i)return t.get(i,()=>e(r,i)).get()}}}createComputedCache(e,t,r){return this.createCache((i,s)=>{const o=r?.areRecordsEqual?pe(`${e}:${i}:isEqual`,()=>s.get(),{isEqual:r.areRecordsEqual}):s;return pe(e+":"+i,()=>t(o.get()),{isEqual:r?.areResultsEqual})})}_integrityChecker;ensureStoreIsUsable(){this.atomic(()=>{this._integrityChecker??=this.schema.createIntegrityChecker(this),this._integrityChecker?.()})}_isPossiblyCorrupted=!1;markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}pendingAfterEvents=null;addDiffForAfterEvent(e,t){if(Be(this.pendingAfterEvents,"must be in event operation"),e===t||(e&&t&&Be(e.id===t.id),!e&&!t))return;const r=(e||t).id,i=this.pendingAfterEvents.get(r);i?i.after=t:this.pendingAfterEvents.set(r,{before:e,after:t})}flushAtomicCallbacks(e){let t=0,r=e?"remote":"user";for(;this.pendingAfterEvents;){const i=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 i.values())s&&o&&s!==o&&!vu(s,o)?this.sideEffects.handleAfterChange(s,o,r):s&&!o?this.sideEffects.handleAfterDelete(s,r):!s&&o&&this.sideEffects.handleAfterCreate(o,r);this.pendingAfterEvents?r="user":this.sideEffects.handleOperationComplete(r)}}}_isInAtomicOp=!1;atomic(e,t=!0,r=!1){return to(()=>{if(this._isInAtomicOp){this.pendingAfterEvents||(this.pendingAfterEvents=new Map);const s=this.sideEffects.isEnabled();Be(!r,"cannot call mergeRemoteChanges while in atomic operation");try{return s&&!t&&this.sideEffects.setIsEnabled(!1),e()}finally{this.sideEffects.setIsEnabled(s)}}this.pendingAfterEvents=new Map;const i=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(t??i),this._isInAtomicOp=!0,r&&(this.isMergingRemoteChanges=!0);try{const s=e();return this.isMergingRemoteChanges=!1,this.flushAtomicCallbacks(r),s}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(i),this._isInAtomicOp=!1,this.isMergingRemoteChanges=!1}})}addHistoryInterceptor(e){return this.historyAccumulator.addInterceptor(t=>e(t,this.isMergingRemoteChanges?"remote":"user"))}}function wQ(n){if(n.length===0)return[];const e=[];let t=[n[0]],r;for(let i=1,s=n.length;i<s;i++)r=n[i],t[0].source!==r.source&&(e.push(t),t=[]),t.push(r);return e.push(t),e.map(i=>({source:i[0].source,changes:VI(i.map(s=>s.changes))}))}class CQ{_history=[];_interceptors=new Set;addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const t of this._interceptors)t(e)}flush(){const e=wQ(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function Pv(n,e,t){const r=new Ii;return{get(i,s){return r.get(i,()=>(i instanceof GI?i:i.store).createComputedCache(n,l=>e(i,l),t)).get(s)}}}function TQ(n){if(n.schemaVersion>2||n.schemaVersion<1)return Hi.err("Bad schema version");if(n.schemaVersion===2)return Hi.ok(n);const e={schemaVersion:2,sequences:{"com.tldraw.store":n.storeVersion}};for(const[t,r]of Object.entries(n.recordVersions))if(e.sequences[`com.tldraw.${t}`]=r.version,"subTypeKey"in r)for(const[i,s]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${t}.${i}`]=s;return Hi.ok(e)}class YI{constructor(e,t){this.types=e,this.options=t;for(const i of t.migrations??[])Be(!this.migrations[i.sequenceId],`Duplicate migration sequenceId ${i.sequenceId}`),O4(i),this.migrations[i.sequenceId]=i;const r=Object.values(this.migrations).flatMap(i=>i.sequence);this.sortedMigrations=yQ(r);for(const i of this.sortedMigrations)if(i.dependsOn?.length)for(const s of i.dependsOn){const o=r.find(a=>a.id===s);Be(o,`Migration '${i.id}' depends on missing migration '${s}'`)}}static create(e,t){return new YI(e,t??{})}migrations={};sortedMigrations;migrationCache=new WeakMap;validateRecord(e,t,r,i){try{const s=tr(this.types,t.typeName);if(!s)throw new Error(`Missing definition for record type ${t.typeName}`);return s.validate(t,i??void 0)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:t,phase:r,recordBefore:i,error:s});throw s}}getMigrationsSince(e){const t=this.migrationCache.get(e);if(t)return t;const r=TQ(e);if(!r.ok)return this.migrationCache.set(e,r),r;const i=r.value,s=new Set(Object.keys(i.sequences).filter(l=>this.migrations[l]));for(const l in this.migrations)i.sequences[l]===void 0&&this.migrations[l].retroactive&&s.add(l);if(s.size===0){const l=Hi.ok([]);return this.migrationCache.set(e,l),l}const o=new Set;for(const l of s){const u=i.sequences[l];if(typeof u!="number"&&this.migrations[l].retroactive||u===0){for(const g of this.migrations[l].sequence)o.add(g.id);continue}const f=`${l}/${u}`,h=this.migrations[l].sequence.findIndex(g=>g.id===f);if(h===-1){const g=Hi.err("Incompatible schema?");return this.migrationCache.set(e,g),g}for(const g of this.migrations[l].sequence.slice(h+1))o.add(g.id)}const a=Hi.ok(this.sortedMigrations.filter(({id:l})=>o.has(l)));return this.migrationCache.set(e,a),a}migratePersistedRecord(e,t,r="up"){const i=this.getMigrationsSince(t);if(!i.ok)return console.error("Error migrating record",i.error),{type:"error",reason:Uc.MigrationError};let s=i.value;if(s.length===0)return{type:"success",value:e};if(s.some(o=>o.scope==="store"))return{type:"error",reason:r==="down"?Uc.TargetVersionTooOld:Uc.TargetVersionTooNew};if(r==="down"){if(!s.every(o=>o.down))return{type:"error",reason:Uc.TargetVersionTooOld};s=s.slice().reverse()}e=Qn(e);try{for(const o of s){if(o.scope==="store")throw new Error;if(!(o.filter?o.filter(e):!0))continue;const l=o[r](e);l&&(e=Qn(l))}}catch(o){return console.error("Error migrating record",o),{type:"error",reason:Uc.MigrationError}}return{type:"success",value:e}}migrateStoreSnapshot(e,t){let{store:r}=e;const i=this.getMigrationsSince(e.schema);if(!i.ok)return console.error("Error migrating store",i.error),{type:"error",reason:Uc.MigrationError};const s=i.value;if(s.length===0)return{type:"success",value:r};t?.mutateInputStore||(r=Qn(r));try{for(const o of s)if(o.scope==="record")for(const[a,l]of Object.entries(r)){if(!(o.filter?o.filter(l):!0))continue;const f=o.up(l);f&&(r[a]=f)}else if(o.scope==="store"){const a=o.up(r);a&&(r=a)}else kt(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Uc.MigrationError}}return{type:"success",value:r}}createIntegrityChecker(e){return this.options.createIntegrityChecker?.(e)??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:t})=>[e,t.length?Xb(t.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const t=tr(this.types,e);return Be(t,"record type does not exists"),t}}xu("@tldraw/store","4.1.2","esm");function EQ(n){if(!n.length)return null;let e="";for(const t of n)typeof t=="number"?e+=`.${t}`:t.startsWith("(")?e.endsWith(")")?e=`${e.slice(0,-1)}, ${t.slice(1)}`:e+=t:e+=`.${t}`;return e=e.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),e.startsWith(".")?e.slice(1):e}class Rt extends Error{constructor(e,t=[]){const r=EQ(t),i=e.split(`
100
30
  `).map((s,o)=>o===0?s:` ${s}`).join(`
101
31
  `);super(t?`At ${r}: ${i}`:i),this.rawMessage=e,this.path=t}name="ValidationError"}function ks(n,e){try{return e()}catch(t){throw t instanceof Rt?new Rt(t.rawMessage,[n,...t.path]):new Rt(t.toString(),[n])}}function uu(n){if(n===null)return"null";if(Array.isArray(n))return"an array";const e=typeof n;switch(e){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${e}`;case"object":return`an ${e}`;case"undefined":return"undefined";default:kt(e)}}class Ai{constructor(e,t){this.validationFn=e,this.validateUsingKnownGoodVersionFn=t}validate(e){return this.validationFn(e)}validateUsingKnownGoodVersion(e,t){return Object.is(e,t)?e:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(e,t):this.validate(t)}isValid(e){try{return this.validate(e),!0}catch{return!1}}nullable(){return OQ(this)}optional(){return j4(this)}refine(e){return new Ai(t=>e(this.validate(t)),(t,r)=>{const i=this.validateUsingKnownGoodVersion(t,r);return Object.is(t,i)?t:e(i)})}check(e,t){return typeof e=="string"?this.refine(r=>(ks(`(check ${e})`,()=>t(r)),r)):this.refine(r=>(e(r),r))}}class _Q extends Ai{constructor(e){super(t=>{const r=r3.validate(t);for(let i=0;i<r.length;i++)ks(i,()=>e.validate(r[i]));return r},(t,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const i=r3.validate(r);let s=t.length!==i.length;for(let o=0;o<i.length;o++){const a=i[o];if(o>=t.length){s=!0,ks(o,()=>e.validate(a));continue}if(Object.is(t[o],a))continue;const l=ks(o,()=>e.validateUsingKnownGoodVersion(t[o],a));Object.is(l,t[o])||(s=!0)}return s?r:t}),this.itemValidator=e}nonEmpty(){return this.check(e=>{if(e.length===0)throw new Rt("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new Rt("Expected an array with length greater than 1")})}}class Jb extends Ai{constructor(e,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Rt(`Expected object, got ${uu(r)}`);for(const[i,s]of Object.entries(e))ks(i,()=>{s.validate(tr(r,i))});if(!t){for(const i of Object.keys(r))if(!Fo(e,i))throw new Rt("Unexpected property",[i])}return r},(r,i)=>{if(typeof i!="object"||i===null)throw new Rt(`Expected object, got ${uu(i)}`);let s=!1;for(const[o,a]of Object.entries(e)){const l=tr(r,o),u=tr(i,o);if(Object.is(l,u))continue;const f=ks(o,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,u):h.validate(u)});Object.is(f,l)||(s=!0)}if(!t){for(const o of Object.keys(i))if(!Fo(e,o))throw new Rt("Unexpected property",[o])}for(const o of Object.keys(r))if(!Fo(i,o)){s=!0;break}return s?i:r}),this.config=e,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new Jb(this.config,!0)}extend(e){return new Jb({...this.config,...e})}}class Iv extends Ai{constructor(e,t,r,i){super(s=>{this.expectObject(s);const{matchingSchema:o,variant:a}=this.getMatchingSchemaAndVariant(s);return o===void 0?this.unknownValueValidation(s,a):ks(`(${e} = ${a})`,()=>o.validate(s))},(s,o)=>{this.expectObject(o),this.expectObject(s);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(o);return a===void 0?this.unknownValueValidation(o,l):tr(s,e)!==tr(o,e)?ks(`(${e} = ${l})`,()=>a.validate(o)):ks(`(${e} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(s,o):a.validate(o))}),this.key=e,this.config=t,this.unknownValueValidation=r,this.useNumberKeys=i}expectObject(e){if(typeof e!="object"||e===null)throw new Rt(`Expected an object, got ${uu(e)}`,[])}getMatchingSchemaAndVariant(e){const t=tr(e,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new Rt(`Expected a string for key "${this.key}", got ${uu(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new Rt(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:Fo(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(e){return new Iv(this.key,this.config,e,this.useNumberKeys)}}class PQ extends Ai{constructor(e,t){super(r=>{if(typeof r!="object"||r===null)throw new Rt(`Expected object, got ${uu(r)}`);for(const[i,s]of Object.entries(r))ks(i,()=>{e.validate(i),t.validate(s)});return r},(r,i)=>{if(typeof i!="object"||i===null)throw new Rt(`Expected object, got ${uu(i)}`);let s=!1;for(const[o,a]of Object.entries(i)){if(!Fo(r,o)){s=!0,ks(o,()=>{e.validate(o),t.validate(a)});continue}const l=tr(r,o),u=a;if(Object.is(l,u))continue;const f=ks(o,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(l,u):t.validate(u));Object.is(f,l)||(s=!0)}for(const o of Object.keys(r))if(!Fo(i,o)){s=!0;break}return s?i:r}),this.keyValidator=e,this.valueValidator=t}}function WI(n){return new Ai(e=>{if(typeof e!==n)throw new Rt(`Expected ${n}, got ${uu(e)}`);return e})}const IQ=new Ai(n=>n),MQ=new Ai(n=>n),dt=WI("string"),Qe=WI("number").check(n=>{if(Number.isNaN(n))throw new Rt("Expected a number, got NaN");if(!Number.isFinite(n))throw new Rt(`Expected a finite number, got ${n}`)}),Qb=Qe.check(n=>{if(n<0)throw new Rt(`Expected a positive number, got ${n}`)}),rr=Qe.check(n=>{if(n<=0)throw new Rt(`Expected a non-zero positive number, got ${n}`)}),R4=Qe.check(n=>{if(!Number.isInteger(n))throw new Rt(`Expected an integer, got ${n}`)}),Mb=R4.check(n=>{if(n<0)throw new Rt(`Expected a positive integer, got ${n}`)}),kQ=R4.check(n=>{if(n<=0)throw new Rt(`Expected a non-zero positive integer, got ${n}`)}),pt=WI("boolean");function Pi(n){return new Ai(e=>{if(e!==n)throw new Rt(`Expected ${n}, got ${JSON.stringify(e)}`);return n})}const r3=new Ai(n=>{if(!Array.isArray(n))throw new Rt(`Expected an array, got ${uu(n)}`);return n});function Dr(n){return new _Q(n)}function Ct(n){return new Jb(n)}function B_(n){return typeof n=="object"&&n!==null&&(Object.getPrototypeOf(n)===Object.prototype||Object.getPrototypeOf(n)===null||Object.getPrototypeOf(n)===PZ)}function F_(n){return n===null||typeof n=="number"||typeof n=="string"||typeof n=="boolean"?!0:Array.isArray(n)?n.every(F_):B_(n)?Object.values(n).every(F_):!1}const ti=new Ai(n=>{if(F_(n))return n;throw new Rt(`Expected json serializable value, got ${typeof n}`)},(n,e)=>{if(Array.isArray(n)&&Array.isArray(e)){let t=n.length!==e.length;for(let r=0;r<e.length;r++){if(r>=n.length){t=!0,ti.validate(e[r]);continue}const i=n[r],s=e[r];if(Object.is(i,s))continue;const o=ti.validateUsingKnownGoodVersion(i,s);Object.is(o,i)||(t=!0)}return t?e:n}else if(B_(n)&&B_(e)){let t=!1;for(const r of Object.keys(e)){if(!Fo(n,r)){t=!0,ti.validate(e[r]);continue}const i=n[r],s=e[r];if(Object.is(i,s))continue;const o=ti.validateUsingKnownGoodVersion(i,s);Object.is(o,i)||(t=!0)}for(const r of Object.keys(n))if(!Fo(e,r)){t=!0;break}return t?e:n}else return ti.validate(e)});function ex(n,e){return new PQ(n,e)}function XI(n,e){return new Iv(n,e,(t,r)=>{throw new Rt(`Expected one of ${Object.keys(e).map(i=>JSON.stringify(i)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!1)}function AQ(n,e){return new Iv(n,e,(t,r)=>{throw new Rt(`Expected one of ${Object.keys(e).map(i=>JSON.stringify(i)).join(" or ")}, got ${JSON.stringify(r)}`,[n])},!0)}function el(n,e){return new Ai(t=>ks(n,()=>e.validate(t)),(t,r)=>ks(n,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(t,r):e.validate(r)))}function Mv(n){return new Ai(e=>{if(!n.has(e)){const t=Array.from(n,r=>JSON.stringify(r)).join(" or ");throw new Rt(`Expected ${t}, got ${e}`)}return e})}function j4(n){return new Ai(e=>{if(e!==void 0)return n.validate(e)},(e,t)=>{if(!(e===void 0&&t===void 0)&&t!==void 0)return n.validateUsingKnownGoodVersion&&e!==void 0?n.validateUsingKnownGoodVersion(e,t):n.validate(t)})}function OQ(n){return new Ai(e=>e===null?null:n.validate(e),(e,t)=>t===null?null:n.validateUsingKnownGoodVersion&&e!==null?n.validateUsingKnownGoodVersion(e,t):n.validate(t))}function Td(...n){return Mv(new Set(n))}function ZI(n){try{return new URL(n)}catch{if(n.startsWith("/")||n.startsWith("./"))try{return new URL(n,"http://example.com")}catch{throw new Rt(`Expected a valid url, got ${JSON.stringify(n)}`)}throw new Rt(`Expected a valid url, got ${JSON.stringify(n)}`)}}const DQ=new Set(["http:","https:","mailto:"]),so=dt.check(n=>{if(n==="")return;const e=ZI(n);if(!DQ.has(e.protocol.toLowerCase()))throw new Rt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)}),RQ=new Set(["http:","https:","data:","asset:"]),Ed=dt.check(n=>{if(n==="")return;const e=ZI(n);if(!RQ.has(e.protocol.toLowerCase()))throw new Rt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});dt.check(n=>{if(n==="")return;if(!ZI(n).protocol.toLowerCase().match(/^https?:$/))throw new Rt(`Expected a valid url, got ${JSON.stringify(n)} (invalid protocol)`)});const JI=dt.refine(n=>{try{return SZ(n),n}catch{throw new Rt(`Expected an index key, got ${JSON.stringify(n)}`)}});xu("@tldraw/validate","4.1.2","esm");function no(n){return dt.refine(e=>{if(!e.startsWith(`${n}:`))throw new Error(`${n} ID must start with "${n}:"`);return e})}const kv=no("asset");function QI(n,e){return Ct({id:kv,typeName:Pi("asset"),type:Pi(n),props:e,meta:ti})}const _d=Ct({x:Qe,y:Qe,z:Qe.optional()}),Kg=Ct({x:Qe,y:Qe,w:Qe,h:Qe}),L4=Qe.check(n=>{if(n<0||n>1)throw new Rt("Opacity must be between 0 and 1")}),jQ=dt.refine(n=>{if(!n.startsWith("page:")&&!n.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return n}),Ao=no("shape");function LQ(n,e,t){return Ct({id:Ao,typeName:Pi("shape"),x:Qe,y:Qe,rotation:Qe,index:JI,parentId:jQ,type:Pi(n),isLocked:pt,opacity:L4,props:e?Ct(e):ti,meta:t?Ct(t):ti})}const NQ=no("binding");function zQ(n,e,t){return Ct({id:NQ,typeName:Pi("binding"),type:Pi(n),fromId:Ao,toId:Ao,props:e?Ct(e):ti,meta:t?Ct(t):ti})}Ds("com.tldraw.binding",{});lo({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function gd(n){return`binding:${zt()}`}function BQ(n,e){return wu(e,(t,r)=>`com.tldraw.binding.${n}/${r}`)}function FQ(n){return Qa("binding",{scope:"document",validator:el("binding",XI("type",wu(n,(e,{props:t,meta:r})=>zQ(e,t,r))))}).withDefaultProperties(()=>({meta:{}}))}const Av=Ct({type:dt,content:Dr(IQ)});function ri(n){return{type:"doc",content:n.split(`
102
- `).map(r=>r?{type:"paragraph",content:[{type:"text",text:r}]}:{type:"paragraph"})}}class Fr{constructor(e,t,r){this.id=e,this.defaultValue=t,this.type=r}static define(e,t){const{defaultValue:r,type:i=MQ}=t;return new Fr(e,r,i)}static defineEnum(e,t){const{defaultValue:r,values:i}=t;return new UQ(e,r,i)}setDefaultValue(e){this.defaultValue=e}validate(e){return this.type.validate(e)}validateUsingKnownGoodVersion(e,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(e,t):this.validate(t)}}class UQ extends Fr{constructor(e,t,r){super(e,t,Td(...r)),this.values=r}}const OS=Ds("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),HQ=lo({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:OS.AddIsLocked,up:n=>{n.isLocked=!1},down:n=>{delete n.isLocked}},{id:OS.HoistOpacity,up:n=>{n.opacity=Number(n.props.opacity??"1"),delete n.props.opacity},down:n=>{const e=n.opacity;delete n.opacity,n.props.opacity=e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}},{id:OS.AddMeta,up:n=>{n.meta={}}},{id:OS.AddWhite,up:n=>{},down:n=>{n.props.color==="white"&&(n.props.color="black")}}]});function hf(n){return n?n.typeName==="shape":!1}function $i(n){return n?n.startsWith("shape:"):!1}function Zt(n){return`shape:${n??zt()}`}function N4(n){const e=new Map;for(const[t,r]of Object.entries(n))if(r instanceof Fr){if(e.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);e.set(r,t)}return e}function Ko(n,e){return wu(e,(t,r)=>`com.tldraw.shape.${n}/${r}`)}function $Q(n){return Qa("shape",{scope:"document",validator:el("shape",XI("type",wu(n,(e,{props:t,meta:r})=>LQ(e,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function i3(n,e){const t=[];for(const[r,{migrations:i}]of Object.entries(e)){const s=`com.tldraw.${n}.${r}`;i?"sequenceId"in i?(Be(s===i.sequenceId,`sequenceId mismatch for ${r} ${_v} migrations. Expected '${s}', got '${i.sequenceId}'`),t.push(i)):"sequence"in i?t.push(bf({sequenceId:s,retroactive:!0,sequence:i.sequence.map(o=>"id"in o?z4(n,r,o):o)})):t.push(bf({sequenceId:s,retroactive:!0,sequence:Object.keys(i.migrators).map(o=>Number(o)).sort((o,a)=>o-a).map(o=>({id:`${s}/${o}`,scope:"record",filter:a=>a.typeName===n&&a.type===r,up:a=>{const l=i.migrators[o].up(a);if(l)return l},down:a=>{const l=i.migrators[o].down(a);if(l)return l}}))})):t.push(bf({sequenceId:s,retroactive:!0,sequence:[]}))}return t}function z4(n,e,t){return{id:t.id,dependsOn:t.dependsOn,scope:"record",filter:r=>r.typeName===n&&r.type===e,up:r=>{const i=t.up(r.props);i&&(r.props=i)},down:typeof t.down=="function"?r=>{const i=t.down(r.props);i&&(r.props=i)}:void 0}}const e2=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],tx={lightMode:{id:"light",text:"#000000",background:"#f9fafb",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",frameHeadingStroke:"#717171",frameHeadingFill:"#ffffff",frameStroke:"#717171",frameFill:"#ffffff",frameText:"#000000",noteFill:"#FCE19C",noteText:"#000000",semi:"#e8e8e8",pattern:"#494949",highlightSrgb:"#fddd00",highlightP3:"color(display-p3 0.972 0.8205 0.05)"},blue:{solid:"#4465e9",fill:"#4465e9",frameHeadingStroke:"#6681ec",frameHeadingFill:"#f9fafe",frameStroke:"#6681ec",frameFill:"#f9fafe",frameText:"#000000",noteFill:"#8AA3FF",noteText:"#000000",semi:"#dce1f8",pattern:"#6681ee",highlightSrgb:"#10acff",highlightP3:"color(display-p3 0.308 0.6632 0.9996)"},green:{solid:"#099268",fill:"#099268",frameHeadingStroke:"#37a684",frameHeadingFill:"#f8fcfa",frameStroke:"#37a684",frameFill:"#f8fcfa",frameText:"#000000",noteFill:"#6FC896",noteText:"#000000",semi:"#d3e9e3",pattern:"#39a785",highlightSrgb:"#00ffc8",highlightP3:"color(display-p3 0.2536 0.984 0.7981)"},grey:{solid:"#9fa8b2",fill:"#9fa8b2",frameHeadingStroke:"#aaaaab",frameHeadingFill:"#fbfcfc",frameStroke:"#aaaaab",frameFill:"#fcfcfd",frameText:"#000000",noteFill:"#C0CAD3",noteText:"#000000",semi:"#eceef0",pattern:"#bcc3c9",highlightSrgb:"#cbe7f1",highlightP3:"color(display-p3 0.8163 0.9023 0.9416)"},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",frameHeadingStroke:"#6cb2f3",frameHeadingFill:"#f8fbfe",frameStroke:"#6cb2f3",frameFill:"#fafcff",frameText:"#000000",noteFill:"#9BC4FD",noteText:"#000000",semi:"#ddedfa",pattern:"#6fbbf8",highlightSrgb:"#00f4ff",highlightP3:"color(display-p3 0.1512 0.9414 0.9996)"},"light-green":{solid:"#4cb05e",fill:"#4cb05e",frameHeadingStroke:"#6dbe7c",frameHeadingFill:"#f8fcf9",frameStroke:"#6dbe7c",frameFill:"#fafdfa",frameText:"#000000",noteFill:"#98D08A",noteText:"#000000",semi:"#dbf0e0",pattern:"#65cb78",highlightSrgb:"#65f641",highlightP3:"color(display-p3 0.563 0.9495 0.3857)"},"light-red":{solid:"#f87777",fill:"#f87777",frameHeadingStroke:"#f89090",frameHeadingFill:"#fffafa",frameStroke:"#f89090",frameFill:"#fffbfb",frameText:"#000000",noteFill:"#F7A5A1",noteText:"#000000",semi:"#f4dadb",pattern:"#fe9e9e",highlightSrgb:"#ff7fa3",highlightP3:"color(display-p3 0.9988 0.5301 0.6397)"},"light-violet":{solid:"#e085f4",fill:"#e085f4",frameHeadingStroke:"#e59bf5",frameHeadingFill:"#fefaff",frameStroke:"#e59bf5",frameFill:"#fefbff",frameText:"#000000",noteFill:"#DFB0F9",noteText:"#000000",semi:"#f5eafa",pattern:"#e9acf8",highlightSrgb:"#ff88ff",highlightP3:"color(display-p3 0.9676 0.5652 0.9999)"},orange:{solid:"#e16919",fill:"#e16919",frameHeadingStroke:"#e68544",frameHeadingFill:"#fef9f6",frameStroke:"#e68544",frameFill:"#fef9f6",frameText:"#000000",noteFill:"#FAA475",noteText:"#000000",semi:"#f8e2d4",pattern:"#f78438",highlightSrgb:"#ffa500",highlightP3:"color(display-p3 0.9988 0.6905 0.266)"},red:{solid:"#e03131",fill:"#e03131",frameHeadingStroke:"#e55757",frameHeadingFill:"#fef7f7",frameStroke:"#e55757",frameFill:"#fef9f9",frameText:"#000000",noteFill:"#FC8282",noteText:"#000000",semi:"#f4dadb",pattern:"#e55959",highlightSrgb:"#ff636e",highlightP3:"color(display-p3 0.9992 0.4376 0.45)"},violet:{solid:"#ae3ec9",fill:"#ae3ec9",frameHeadingStroke:"#bc62d3",frameHeadingFill:"#fcf7fd",frameStroke:"#bc62d3",frameFill:"#fdf9fd",frameText:"#000000",noteFill:"#DB91FD",noteText:"#000000",semi:"#ecdcf2",pattern:"#bd63d3",highlightSrgb:"#c77cff",highlightP3:"color(display-p3 0.7469 0.5089 0.9995)"},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",frameHeadingStroke:"#f3bb6c",frameHeadingFill:"#fefcf8",frameStroke:"#f3bb6c",frameFill:"#fffdfa",frameText:"#000000",noteFill:"#FED49A",noteText:"#000000",semi:"#f9f0e6",pattern:"#fecb92",highlightSrgb:"#fddd00",highlightP3:"color(display-p3 0.972 0.8705 0.05)"},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",frameHeadingStroke:"#7d7d7d",frameHeadingFill:"#ffffff",frameStroke:"#7d7d7d",frameFill:"#ffffff",frameText:"#000000",noteFill:"#FFFFFF",noteText:"#000000",highlightSrgb:"#ffffff",highlightP3:"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",frameHeadingStroke:"#5c5c5c",frameHeadingFill:"#252525",frameStroke:"#5c5c5c",frameFill:"#0c0c0c",frameText:"#f2f2f2",noteFill:"#2c2c2c",noteText:"#f2f2f2",semi:"#2c3036",pattern:"#989898",highlightSrgb:"#d2b700",highlightP3:"color(display-p3 0.8078 0.6225 0.0312)"},blue:{solid:"#4f72fc",fill:"#4f72fc",frameHeadingStroke:"#384994",frameHeadingFill:"#1C2036",frameStroke:"#384994",frameFill:"#11141f",frameText:"#f2f2f2",noteFill:"#2A3F98",noteText:"#f2f2f2",semi:"#262d40",pattern:"#3a4b9e",highlightSrgb:"#0079d2",highlightP3:"color(display-p3 0.0032 0.4655 0.7991)"},green:{solid:"#099268",fill:"#099268",frameHeadingStroke:"#10513C",frameHeadingFill:"#14241f",frameStroke:"#10513C",frameFill:"#0E1614",frameText:"#f2f2f2",noteFill:"#014429",noteText:"#f2f2f2",semi:"#253231",pattern:"#366a53",highlightSrgb:"#009774",highlightP3:"color(display-p3 0.0085 0.582 0.4604)"},grey:{solid:"#9398b0",fill:"#9398b0",frameHeadingStroke:"#42474D",frameHeadingFill:"#23262A",frameStroke:"#42474D",frameFill:"#151719",frameText:"#f2f2f2",noteFill:"#56595F",noteText:"#f2f2f2",semi:"#33373c",pattern:"#7c8187",highlightSrgb:"#9cb4cb",highlightP3:"color(display-p3 0.6299 0.7012 0.7856)"},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",frameHeadingStroke:"#075797",frameHeadingFill:"#142839",frameStroke:"#075797",frameFill:"#0B1823",frameText:"#f2f2f2",noteFill:"#1F5495",noteText:"#f2f2f2",semi:"#2a3642",pattern:"#4d7aa9",highlightSrgb:"#00bdc8",highlightP3:"color(display-p3 0.0023 0.7259 0.7735)"},"light-green":{solid:"#40c057",fill:"#40c057",frameHeadingStroke:"#1C5427",frameHeadingFill:"#18251A",frameStroke:"#1C5427",frameFill:"#0F1911",frameText:"#f2f2f2",noteFill:"#21581D",noteText:"#f2f2f2",semi:"#2a3830",pattern:"#4e874e",highlightSrgb:"#00a000",highlightP3:"color(display-p3 0.2711 0.6172 0.0195)"},"light-red":{solid:"#ff8787",fill:"#ff8787",frameHeadingStroke:"#6f3232",frameHeadingFill:"#341818",frameStroke:"#6f3232",frameFill:"#181212",frameText:"#f2f2f2",noteFill:"#7a3333",noteText:"#f2f2f2",semi:"#3c2b2b",pattern:"#a56767",highlightSrgb:"#db005b",highlightP3:"color(display-p3 0.7849 0.0585 0.3589)"},"light-violet":{solid:"#e599f7",fill:"#e599f7",frameHeadingStroke:"#6c367a",frameHeadingFill:"#2D2230",frameStroke:"#6c367a",frameFill:"#1C151E",frameText:"#f2f2f2",noteFill:"#762F8E",noteText:"#f2f2f2",semi:"#383442",pattern:"#9770a9",highlightSrgb:"#c400c7",highlightP3:"color(display-p3 0.7024 0.0403 0.753)"},orange:{solid:"#f76707",fill:"#f76707",frameHeadingStroke:"#773a0e",frameHeadingFill:"#2f1d13",frameStroke:"#773a0e",frameFill:"#1c1512",frameText:"#f2f2f2",noteFill:"#7c3905",noteText:"#f2f2f2",semi:"#3b2e27",pattern:"#9f552d",highlightSrgb:"#d07a00",highlightP3:"color(display-p3 0.7699 0.4937 0.0085)"},red:{solid:"#e03131",fill:"#e03131",frameHeadingStroke:"#701e1e",frameHeadingFill:"#301616",frameStroke:"#701e1e",frameFill:"#1b1313",frameText:"#f2f2f2",noteFill:"#7e201f",noteText:"#f2f2f2",semi:"#382726",pattern:"#8f3734",highlightSrgb:"#de002c",highlightP3:"color(display-p3 0.7978 0.0509 0.2035)"},violet:{solid:"#ae3ec9",fill:"#ae3ec9",frameHeadingStroke:"#6d1583",frameHeadingFill:"#27152e",frameStroke:"#6d1583",frameFill:"#1b0f21",frameText:"#f2f2f2",noteFill:"#5f1c70",noteText:"#f2f2f2",semi:"#342938",pattern:"#763a8b",highlightSrgb:"#9e00ee",highlightP3:"color(display-p3 0.5651 0.0079 0.8986)"},yellow:{solid:"#ffc034",fill:"#ffc034",frameHeadingStroke:"#684e12",frameHeadingFill:"#2a2113",frameStroke:"#684e12",frameFill:"#1e1911",frameText:"#f2f2f2",noteFill:"#8a5e1c",noteText:"#f2f2f2",semi:"#3b352b",pattern:"#fecb92",highlightSrgb:"#d2b700",highlightP3:"color(display-p3 0.8078 0.7225 0.0312)"},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",frameHeadingStroke:"#ffffff",frameHeadingFill:"#ffffff",frameStroke:"#ffffff",frameFill:"#ffffff",frameText:"#000000",noteFill:"#eaeaea",noteText:"#1d1d1d",highlightSrgb:"#ffffff",highlightP3:"color(display-p3 1 1 1)"}}};function _u(n){return n.isDarkMode?tx.darkMode:tx.lightMode}const Zi=Fr.defineEnum("tldraw:color",{defaultValue:"black",values:e2}),t2=Fr.defineEnum("tldraw:labelColor",{defaultValue:"black",values:e2}),KQ=new Set(e2);function qQ(n){return KQ.has(n)}function Mt(n,e,t){return qQ(e)?n[e][t]:e}const Pd=Fr.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Id=Fr.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),du=Fr.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),VQ={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},qa=Fr.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),GQ=["arc","elbow"],nx=Fr.defineEnum("tldraw:arrowKind",{defaultValue:"arc",values:GQ}),B4=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],U_=Fr.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:B4}),H_=Fr.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:B4}),F4={kind:nx,labelColor:t2,color:Zi,fill:Id,dash:Pd,size:qa,arrowheadStart:U_,arrowheadEnd:H_,font:du,start:_d,end:_d,bend:Qe,richText:Av,labelPosition:Qe,scale:rr,elbowMidPoint:Qe},Hc=Ko("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5,AddElbow:6,AddRichText:7});function zh(n){return z4("shape","arrow",n)}const U4=bf({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[zh({id:Hc.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"}),zh({id:Hc.AddIsPrecise,up:({start:n,end:e})=>{n.type==="binding"&&(n.isPrecise=!(n.normalizedAnchor.x===.5&&n.normalizedAnchor.y===.5)),e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5))},down:({start:n,end:e})=>{n.type==="binding"&&(n.isPrecise||(n.normalizedAnchor={x:.5,y:.5}),delete n.isPrecise),e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise)}}),zh({id:Hc.AddLabelPosition,up:n=>{n.labelPosition=.5},down:n=>{delete n.labelPosition}}),{id:Hc.ExtractBindings,scope:"store",up:n=>{const e=Object.values(n).filter(t=>t.typeName==="shape"&&t.type==="arrow");for(const t of e){const{start:r,end:i}=t.props;if(r.type==="binding"){const s=gd(),o={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};n[s]=o,t.props.start={x:0,y:0}}else delete t.props.start.type;if(i.type==="binding"){const s=gd(),o={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:i.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:i.normalizedAnchor,isExact:i.isExact,isPrecise:i.isPrecise}};n[s]=o,t.props.end={x:0,y:0}}else delete t.props.end.type}}},zh({id:Hc.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}),zh({id:Hc.AddElbow,up:n=>{n.kind="arc",n.elbowMidPoint=.5},down:n=>{delete n.kind,delete n.elbowMidPoint}}),zh({id:Hc.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}})]}),YQ=Td("center","edge-point","edge","none"),H4={terminal:Td("start","end"),normalizedAnchor:_d,isExact:pt,isPrecise:pt,snap:YQ},WQ=BQ("arrow",{AddSnap:1}),$4={sequence:[{dependsOn:[Hc.ExtractBindings]},{id:WQ.AddSnap,up:n=>{n.snap="none"},down:n=>{delete n.snap}}]},XQ=el("camera",Ct({typeName:Pi("camera"),id:no("camera"),x:Qe,y:Qe,z:Qe,meta:ti})),ZQ=Ds("com.tldraw.camera",{AddMeta:1}),JQ=lo({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:ZQ.AddMeta,up:n=>{n.meta={}}}]}),za=Qa("camera",{validator:XQ,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),QQ=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"]),K4=Mv(QQ),eee=Ct({type:K4,rotation:Qe}),tee=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),nee=Mv(tee),ree=new Set(["starting","paused","active","stopping"]),q4=Ct({id:dt,points:Dr(_d),size:Qb,color:nee,opacity:Qe,state:Mv(ree),delay:Qe,shrink:Qe,taper:pt}),um=no("page"),iee=el("page",Ct({typeName:Pi("page"),id:um,name:dt,index:JI,meta:ti})),see=Ds("com.tldraw.page",{AddMeta:1}),oee=lo({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:see.AddMeta,up:n=>{n.meta={}}}]}),Wi=Qa("page",{validator:iee,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Yr(n){return Wi.isId(n)}const aee={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};function V4(n){return n?Hg(n,e=>aee[e]):null}no("instance");function lee(n){const e={};for(const[r,i]of n)e[r]=j4(i);const t=el("instance",Ct({typeName:Pi("instance"),id:no("instance"),currentPageId:um,followingUserId:dt.nullable(),brush:Kg.nullable(),opacityForNextShape:L4,stylesForNextShape:Ct(e),cursor:eee,scribbles:Dr(q4),isFocusMode:pt,isDebugMode:pt,isToolLocked:pt,exportBackground:pt,screenBounds:Kg,insets:Dr(pt),zoomBrush:Kg.nullable(),isPenMode:pt,isGridMode:pt,chatMessage:dt,isChatting:pt,highlightedUserIds:Dr(dt),isFocused:pt,devicePixelRatio:Qe,isCoarsePointer:pt,isHoveringCanvas:pt.nullable(),openMenus:Dr(dt),isChangingStyle:pt,isReadonly:pt,meta:ti,duplicateProps:Ct({shapeIds:Dr(no("shape")),offset:Ct({x:Qe,y:Qe})}).nullable()}));return Qa("instance",{validator:t,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 yn=Ds("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}),cee=lo({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:yn.AddTransparentExportBgs,up:n=>({...n,exportBackground:!0})},{id:yn.RemoveDialog,up:({dialog:n,...e})=>e},{id:yn.AddToolLockMode,up:n=>({...n,isToolLocked:!1})},{id:yn.RemoveExtraPropsForNextShape,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:Object.fromEntries(Object.entries(n).filter(([t])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(t)))})},{id:yn.AddLabelColor,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:{...n,labelColor:"black"}})},{id:yn.AddFollowingUserId,up:n=>({...n,followingUserId:null})},{id:yn.RemoveAlignJustify,up:n=>{let e=n.propsForNextShape.align;return e==="justify"&&(e="start"),{...n,propsForNextShape:{...n.propsForNextShape,align:e}}}},{id:yn.AddZoom,up:n=>({...n,zoomBrush:null})},{id:yn.AddVerticalAlign,up:n=>({...n,propsForNextShape:{...n.propsForNextShape,verticalAlign:"middle"}})},{id:yn.AddScribbleDelay,up:n=>n.scribble!==null?{...n,scribble:{...n.scribble,delay:0}}:{...n}},{id:yn.RemoveUserId,up:({userId:n,...e})=>e},{id:yn.AddIsPenModeAndIsGridMode,up:n=>({...n,isPenMode:!1,isGridMode:!1})},{id:yn.HoistOpacity,up:({propsForNextShape:{opacity:n,...e},...t})=>({...t,opacityForNextShape:Number(n??"1"),propsForNextShape:e})},{id:yn.AddChat,up:n=>({...n,chatMessage:"",isChatting:!1})},{id:yn.AddHighlightedUserIds,up:n=>({...n,highlightedUserIds:[]})},{id:yn.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:n,...e})=>({...e,stylesForNextShape:{}})},{id:yn.AddMeta,up:n=>({...n,meta:{}})},{id:yn.RemoveCursorColor,up:n=>{const{color:e,...t}=n.cursor;return{...n,cursor:t}}},{id:yn.AddLonelyProperties,up:n=>({...n,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:yn.ReadOnlyReadonly,up:({isReadOnly:n,...e})=>({...e,isReadonly:n})},{id:yn.AddHoveringCanvas,up:n=>({...n,isHoveringCanvas:null})},{id:yn.AddScribbles,up:({scribble:n,...e})=>({...e,scribbles:[]})},{id:yn.AddInset,up:n=>({...n,insets:[!1,!1,!1,!1]}),down:({insets:n,...e})=>({...e})},{id:yn.AddDuplicateProps,up:n=>({...n,duplicateProps:null}),down:({duplicateProps:n,...e})=>({...e})},{id:yn.RemoveCanMoveCamera,up:({canMoveCamera:n,...e})=>({...e}),down:n=>({...n,canMoveCamera:!0})}]}),Ki="instance:instance",uee=el("instance_page_state",Ct({typeName:Pi("instance_page_state"),id:no("instance_page_state"),pageId:um,selectedShapeIds:Dr(Ao),hintingShapeIds:Dr(Ao),erasingShapeIds:Dr(Ao),hoveredShapeId:Ao.nullable(),editingShapeId:Ao.nullable(),croppingShapeId:Ao.nullable(),focusedGroupId:Ao.nullable(),meta:ti})),tg=Ds("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),dee=lo({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:tg.AddCroppingId,up(n){n.croppingShapeId=null}},{id:tg.RemoveInstanceIdAndCameraId,up(n){delete n.instanceId,delete n.cameraId}},{id:tg.AddMeta,up:n=>{n.meta={}}},{id:tg.RenameProperties,up:n=>{},down:n=>{}},{id:tg.RenamePropertiesAgain,up:n=>{n.selectedShapeIds=n.selectedIds,delete n.selectedIds,n.hintingShapeIds=n.hintingIds,delete n.hintingIds,n.erasingShapeIds=n.erasingIds,delete n.erasingIds,n.hoveredShapeId=n.hoveredId,delete n.hoveredId,n.editingShapeId=n.editingId,delete n.editingId,n.croppingShapeId=n.croppingShapeId??n.croppingId??null,delete n.croppingId,n.focusedGroupId=n.focusLayerId,delete n.focusLayerId},down:n=>{n.selectedIds=n.selectedShapeIds,delete n.selectedShapeIds,n.hintingIds=n.hintingShapeIds,delete n.hintingShapeIds,n.erasingIds=n.erasingShapeIds,delete n.erasingShapeIds,n.hoveredId=n.hoveredShapeId,delete n.hoveredShapeId,n.editingId=n.editingShapeId,delete n.editingShapeId,n.croppingId=n.croppingShapeId,delete n.croppingShapeId,n.focusLayerId=n.focusedGroupId,delete n.focusedGroupId}}]}),ca=Qa("instance_page_state",{validator:uee,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:{}})),hee=el("pointer",Ct({typeName:Pi("pointer"),id:no("pointer"),x:Qe,y:Qe,lastActivityTimestamp:Qe,meta:ti})),fee=Ds("com.tldraw.pointer",{AddMeta:1}),pee=lo({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:fee.AddMeta,up:n=>{n.meta={}}}]}),n2=Qa("pointer",{validator:hee,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),rx=n2.createId("pointer"),gee=el("instance_presence",Ct({typeName:Pi("instance_presence"),id:no("instance_presence"),userId:dt,userName:dt,lastActivityTimestamp:Qe.nullable(),followingUserId:dt.nullable(),cursor:Ct({x:Qe,y:Qe,type:K4,rotation:Qe}).nullable(),color:dt,camera:Ct({x:Qe,y:Qe,z:Qe}).nullable(),screenBounds:Kg.nullable(),selectedShapeIds:Dr(no("shape")),currentPageId:no("page"),brush:Kg.nullable(),scribbles:Dr(q4),chatMessage:dt,meta:ti})),Bh=Ds("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),mee=lo({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Bh.AddScribbleDelay,up:n=>{n.scribble!==null&&(n.scribble.delay=0)}},{id:Bh.RemoveInstanceId,up:n=>{delete n.instanceId}},{id:Bh.AddChatMessage,up:n=>{n.chatMessage=""}},{id:Bh.AddMeta,up:n=>{n.meta={}}},{id:Bh.RenameSelectedShapeIds,up:n=>{}},{id:Bh.NullableCameraCursor,up:n=>{},down:n=>{n.camera===null&&(n.camera={x:0,y:0,z:1}),n.lastActivityTimestamp===null&&(n.lastActivityTimestamp=0),n.cursor===null&&(n.cursor={type:"default",x:0,y:0,rotation:0}),n.screenBounds===null&&(n.screenBounds={x:0,y:0,w:1,h:1})}}]}),yee=Qa("instance_presence",{validator:gee,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),See=el("document",Ct({typeName:Pi("document"),id:Pi("document:document"),gridSize:Qe,name:dt,meta:ti})),s3=Ds("com.tldraw.document",{AddName:1,AddMeta:2}),bee=lo({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:s3.AddName,up:n=>{n.name=""},down:n=>{delete n.name}},{id:s3.AddMeta,up:n=>{n.meta={}}}]}),r2=Qa("document",{validator:See,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),$_=r2.createId("document");function o3(n){n.typeName==="asset"&&("src"in n&&(n.src="<redacted>"),"src"in n.props&&(n.props.src="<redacted>"))}function xee({error:n,phase:e,record:t,recordBefore:r}){throw yI(n,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?o3(Qn(r)):void 0,recordAfter:o3(Qn(t))}}),n}function vee(){return[Wi.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function wee(n){const e=n.query.ids("page"),t=n.query.records("instance_page_state"),r=()=>{if(!n.has($_))return n.put([r2.create({id:$_,name:n.props.defaultName})]),r();if(!n.has(rx))return n.put([n2.create({id:rx})]),r();const i=e.get();if(i.size===0)return n.put(vee()),r();const s=()=>[...i].map(f=>n.get(f)).sort(kr)[0].id,o=n.get(Ki);if(o){if(!i.has(o.currentPageId))return n.put([{...o,currentPageId:s()}]),r()}else return n.put([n.schema.types.instance.create({id:Ki,currentPageId:s(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const f of i){const h=ca.createId(f);n.get(h)||a.add(h);const y=za.createId(f);n.has(y)||l.add(y)}a.size>0&&n.put([...a].map(f=>ca.create({id:f,pageId:ca.parseId(f)}))),l.size>0&&n.put([...l].map(f=>za.create({id:f})));const u=t.get();for(const f of u){if(!i.has(f.pageId)){n.remove([f.id]);continue}if(f.croppingShapeId&&!n.has(f.croppingShapeId))return n.put([{...f,croppingShapeId:null}]),r();if(f.focusedGroupId&&!n.has(f.focusedGroupId))return n.put([{...f,focusedGroupId:null}]),r();if(f.hoveredShapeId&&!n.has(f.hoveredShapeId))return n.put([{...f,hoveredShapeId:null}]),r();const h=f.selectedShapeIds.filter(b=>n.has(b));if(h.length!==f.selectedShapeIds.length)return n.put([{...f,selectedShapeIds:h}]),r();const g=f.hintingShapeIds.filter(b=>n.has(b));if(g.length!==f.hintingShapeIds.length)return n.put([{...f,hintingShapeIds:g}]),r();const y=f.erasingShapeIds.filter(b=>n.has(b));if(y.length!==f.erasingShapeIds.length)return n.put([{...f,erasingShapeIds:y}]),r()}};return r}const Cee=QI("bookmark",Ct({title:dt,description:dt,image:dt,favicon:dt,src:Ed.nullable()})),a3=Ds("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),Tee=lo({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:n=>n.type==="bookmark",sequence:[{id:a3.MakeUrlsValid,up:n=>{Ed.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:a3.AddFavicon,up:n=>{Ed.isValid(n.props.favicon)||(n.props.favicon="")},down:n=>{delete n.props.favicon}}]}),Eee=QI("image",Ct({w:Qe,h:Qe,name:dt,isAnimated:pt,mimeType:dt.nullable(),src:Ed.nullable(),fileSize:rr.optional()})),ng=Ds("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),_ee=lo({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:n=>n.type==="image",sequence:[{id:ng.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:ng.RenameWidthHeight,up:n=>{n.props.w=n.props.width,n.props.h=n.props.height,delete n.props.width,delete n.props.height},down:n=>{n.props.width=n.props.w,n.props.height=n.props.h,delete n.props.w,delete n.props.h}},{id:ng.MakeUrlsValid,up:n=>{Ed.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:ng.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:ng.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),Pee=QI("video",Ct({w:Qe,h:Qe,name:dt,isAnimated:pt,mimeType:dt.nullable(),src:Ed.nullable(),fileSize:Qe.optional()})),rg=Ds("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),Iee=lo({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:n=>n.type==="video",sequence:[{id:rg.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:rg.RenameWidthHeight,up:n=>{n.props.w=n.props.width,n.props.h=n.props.height,delete n.props.width,delete n.props.height},down:n=>{n.props.width=n.props.w,n.props.height=n.props.h,delete n.props.w,delete n.props.h}},{id:rg.MakeUrlsValid,up:n=>{Ed.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:rg.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:rg.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),Mee=el("asset",XI("type",{image:Eee,video:Pee,bookmark:Cee})),kee=Ds("com.tldraw.asset",{AddMeta:1}),Aee=lo({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:kee.AddMeta,up:n=>{n.meta={}}}]}),Pu=Qa("asset",{validator:Mee,scope:"document"}).withDefaultProperties(()=>({meta:{}})),G4={w:rr,h:rr,assetId:kv.nullable(),url:so},l3=Ko("bookmark",{NullAssetId:1,MakeUrlsValid:2}),Y4={sequence:[{id:l3.NullAssetId,up:n=>{n.assetId===void 0&&(n.assetId=null)},down:"retired"},{id:l3.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}}]},W4=Ct({type:Td("free","straight"),points:Dr(_d)}),X4={color:Zi,fill:Id,dash:Pd,size:qa,segments:Dr(W4),isComplete:pt,isClosed:pt,isPen:pt,scale:rr},c3=Ko("draw",{AddInPen:1,AddScale:2}),Z4={sequence:[{id:c3.AddInPen,up:n=>{const{points:e}=n.segments[0];if(e.length===0){n.isPen=!1;return}let t=!(e[0].z===0||e[0].z===.5);e[1]&&(t=t&&!(e[1].z===0||e[1].z===.5)),n.isPen=t},down:"retired"},{id:c3.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},Oee=/(^\/r\/[^/]+\/?$)/,Dee=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(Oee))return n}},{hostnames:["figma.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/?$/)){const t=e.searchParams.get("url");if(t)return t}}},{hostnames:["google.*"],fromEmbedUrl:n=>{const e=it(n);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[i,s]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${i},${s},${r}z`}}},{hostnames:["val.town"],fromEmbedUrl:n=>{const e=it(n),t=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:n=>{const e=it(n),t=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{hostnames:["codepen.io"],fromEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,i,s]=t;return`https://codepen.io/${i}/pen/${s}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:n=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,i]=t;return`https://scratch.mit.edu/projects/${i}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],fromEmbedUrl:n=>{const e=it(n);if(!e)return;if(e.hostname.replace(/^www./,"")==="youtube.com"){const r=e.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{hostnames:["calendar.google.*"],fromEmbedUrl:n=>{const e=it(n),t=e?.searchParams.get("src");if(e?.pathname.match(/\/calendar\/embed/)&&t){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const i of r)e.searchParams.delete(i);return e.searchParams.set("cid",t),e.href}}},{hostnames:["docs.google.*"],fromEmbedUrl:n=>{const e=it(n);if(e?.pathname.match(/^\/presentation/)&&e?.pathname.match(/\/embed\/?$/)){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const t=Array.from(e.searchParams.keys());for(const r of t)e.searchParams.delete(r);return e.href}}},{hostnames:["gist.github.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return n.split("/").pop()?n:void 0}},{hostnames:["replit.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{hostnames:["open.spotify.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{hostnames:["vimeo.com","player.vimeo.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.hostname==="player.vimeo.com"){const t=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(t)return"https://vimeo.com/"+t[1]}}},{hostnames:["excalidraw.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.hash.match(/#room=/))return n}},{hostnames:["observablehq.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","")}#cell-*`;if(e&&e.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","/d")}#cell-*`}},{hostnames:["desmos.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],J4={w:rr,h:rr,url:dt},DS=Ko("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),Q4={sequence:[{id:DS.GenOriginalUrlInEmbed,up:n=>{try{const e=n.url,t=new URL(e).host.replace("www.","");let r;for(const i of Dee)if(i.hostnames.includes(t))try{r=i.fromEmbedUrl(e)}catch(s){console.warn(s)}n.tmpOldUrl=n.url,n.url=r??""}catch{n.url="",n.tmpOldUrl=n.url}},down:"retired"},{id:DS.RemoveDoesResize,up:n=>{delete n.doesResize},down:"retired"},{id:DS.RemoveTmpOldUrl,up:n=>{delete n.tmpOldUrl},down:"retired"},{id:DS.RemovePermissionOverrides,up:n=>{delete n.overridePermissions},down:"retired"}]},eF={w:rr,h:rr,name:dt,color:Td(...Zi.values)},Ree=Ko("frame",{AddColorProp:1}),tF={sequence:[{id:Ree.AddColorProp,up:n=>{n.color="black"},down:n=>{delete n.color}}]},ix=Fr.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),sx=Fr.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Ba=Fr.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"]}),nF={geo:Ba,dash:Pd,url:so,w:rr,h:rr,growY:Qb,scale:rr,labelColor:t2,color:Zi,fill:Id,size:qa,font:du,align:ix,verticalAlign:sx,richText:Av},Ia=Ko("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9,AddRichText:10}),rF={sequence:[{id:Ia.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:Ia.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"},{id:Ia.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:Ia.AddCheckBox,up:n=>{},down:"retired"},{id:Ia.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:Ia.MigrateLegacyAlign,up:n=>{let e;switch(n.align){case"start":e="start-legacy";break;case"end":e="end-legacy";break;default:e="middle-legacy";break}n.align=e},down:"retired"},{id:Ia.AddCloud,up:n=>{},down:"retired"},{id:Ia.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:Ia.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:Ia.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}}]},iF={},sF={sequence:[]},oF={color:Zi,size:qa,segments:Dr(W4),isComplete:pt,isPen:pt,scale:rr},jee=Ko("highlight",{AddScale:1}),aF={sequence:[{id:jee.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},Lee=Ct({topLeft:_d,bottomRight:_d,isCircle:pt.optional()}),lF={w:rr,h:rr,playing:pt,url:so,assetId:kv.nullable(),crop:Lee.nullable(),flipX:pt,flipY:pt,altText:dt},ig=Ko("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4,AddAltText:5}),cF={sequence:[{id:ig.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:ig.AddCropProp,up:n=>{n.crop=null},down:n=>{delete n.crop}},{id:ig.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:ig.AddFlipProps,up:n=>{n.flipX=!1,n.flipY=!1},down:n=>{delete n.flipX,delete n.flipY}},{id:ig.AddAltText,up:n=>{n.altText=""},down:n=>{delete n.altText}}]},K_=Fr.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),Nee=Ct({id:dt,index:JI,x:Qe,y:Qe}),uF={color:Zi,dash:Pd,size:qa,spline:K_,points:ex(dt,Nee),scale:rr},sg=Ko("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),dF={sequence:[{id:sg.AddSnapHandles,up:n=>{for(const e of Object.values(n.handles))e.canSnap=!0},down:"retired"},{id:sg.RemoveExtraHandleProps,up:n=>{n.handles=IB(Object.values(n.handles).map(e=>[e.index,{x:e.x,y:e.y}]))},down:n=>{const e=Object.entries(n.handles).map(([t,r])=>({index:t,...r})).sort(kr);n.handles=Object.fromEntries(e.map((t,r)=>{const i=r===0?"start":r===e.length-1?"end":`handle:${t.index}`;return[i,{id:i,type:"vertex",canBind:!1,canSnap:!0,index:t.index,x:t.x,y:t.y}]}))}},{id:sg.HandlesToPoints,up:n=>{const e=Object.entries(n.handles).map(([t,{x:r,y:i}])=>({x:r,y:i,index:t})).sort(kr);n.points=e.map(({x:t,y:r})=>({x:t,y:r})),delete n.handles},down:n=>{const e=cm(n.points.length);n.handles=Object.fromEntries(n.points.map((t,r)=>[e[r],{x:t.x,y:t.y}])),delete n.points}},{id:sg.PointIndexIds,up:n=>{const e=cm(n.points.length);n.points=Object.fromEntries(n.points.map((t,r)=>{const i=e[r];return[i,{id:i,index:i,x:t.x,y:t.y}]}))},down:n=>{const e=Object.values(n.points).sort(kr);n.points=e.map(({x:t,y:r})=>({x:t,y:r}))}},{id:sg.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},hF={color:Zi,labelColor:t2,size:qa,font:du,fontSizeAdjustment:Qb,align:ix,verticalAlign:sx,growY:Qb,url:so,richText:Av,scale:rr},Ol=Ko("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8,AddRichText:9}),fF={sequence:[{id:Ol.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:Ol.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:Ol.MigrateLegacyAlign,up:n=>{switch(n.align){case"start":n.align="start-legacy";return;case"end":n.align="end-legacy";return;default:n.align="middle-legacy";return}},down:"retired"},{id:Ol.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:Ol.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:Ol.AddFontSizeAdjustment,up:n=>{n.fontSizeAdjustment=0},down:n=>{delete n.fontSizeAdjustment}},{id:Ol.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:Ol.AddLabelColor,up:n=>{n.labelColor="black"},down:n=>{delete n.labelColor}},{id:Ol.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}}]},q_=Fr.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),pF={color:Zi,size:qa,font:du,textAlign:q_,w:rr,richText:Av,scale:rr,autoSize:pt},gE=Ko("text",{RemoveJustify:1,AddTextAlign:2,AddRichText:3}),gF={sequence:[{id:gE.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:gE.AddTextAlign,up:n=>{n.textAlign=n.align,delete n.align},down:n=>{n.align=n.textAlign,delete n.textAlign}},{id:gE.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}}]},mF={w:rr,h:rr,time:Qe,playing:pt,autoplay:pt,url:so,assetId:kv.nullable(),altText:dt},RS=Ko("video",{AddUrlProp:1,MakeUrlsValid:2,AddAltText:3,AddAutoplay:4}),yF={sequence:[{id:RS.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:RS.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:RS.AddAltText,up:n=>{n.altText=""},down:n=>{delete n.altText}},{id:RS.AddAutoplay,up:n=>{n.autoplay=!0},down:n=>{delete n.autoplay}}]},og=Ds("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4,FixIndexKeys:5}),zee=bf({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:og.RemoveCodeAndIconShapeTypes,scope:"store",up:n=>{for(const[e,t]of Yi(n))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete n[e]}},{id:og.AddInstancePresenceType,scope:"store",up(n){}},{id:og.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:n=>{for(const[e,t]of Yi(n))t.typeName.match(/^(user|user_presence)$/)&&delete n[e]}},{id:og.RemoveUserDocument,scope:"store",up:n=>{for(const[e,t]of Yi(n))t.typeName.match("user_document")&&delete n[e]}},{id:og.FixIndexKeys,scope:"record",up:n=>{if(["shape","page"].includes(n.typeName)&&"index"in n){const e=n;if(e.index.endsWith("0")&&e.index!=="a0"&&(e.index=e.index.slice(0,-1)+d3(3)),n.typeName==="shape"&&e.type==="line"){const t=e;for(const[r,i]of Yi(t.props.points))i.index.endsWith("0")&&i.index!=="a0"&&(i.index=i.index.slice(0,-1)+d3(3))}}},down:()=>{}}]}),u3="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Bee=()=>u3.charAt(Math.floor(Math.random()*u3.length)),d3=n=>Array.from({length:n},Bee).join(""),Fee={arrow:{migrations:U4,props:F4},bookmark:{migrations:Y4,props:G4},draw:{migrations:Z4,props:X4},embed:{migrations:Q4,props:J4},frame:{migrations:tF,props:eF},geo:{migrations:rF,props:nF},group:{migrations:sF,props:iF},highlight:{migrations:aF,props:oF},image:{migrations:cF,props:lF},line:{migrations:dF,props:uF},note:{migrations:fF,props:hF},text:{migrations:gF,props:pF},video:{migrations:yF,props:mF}},Uee={arrow:{migrations:$4,props:H4}};function Hee({shapes:n=Fee,bindings:e=Uee,migrations:t}={}){const r=new Map;for(const a of Hn(n))for(const l of N4(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 i=$Q(n),s=FQ(e),o=lee(r);return YI.create({asset:Pu,binding:s,camera:za,document:r2,instance:o,instance_page_state:ca,page:Wi,instance_presence:yee,pointer:n2,shape:i},{migrations:[zee,Aee,JQ,bee,cee,dee,oee,mee,pee,HQ,Tee,_ee,Iee,...i3("shape",n),...i3("binding",e),...t??[]],onValidationFailure:xee,createIntegrityChecker:wee})}const dm=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ms",label:"Bahasa Melayu"},{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:"tl",label:"Filipino"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"nl",label:"Nederlands"},{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:"sl",label:"Slovenščina"},{locale:"so",label:"Somali"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"el",label:"Ελληνικά"},{locale:"ru",label:"Русский"},{locale:"uk",label:"Українська"},{locale:"he",label:"עברית"},{locale:"ur",label:"اردو"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ne",label:"नेपाली"},{locale:"mr",label:"मराठी"},{locale:"hi-in",label:"हिन्दी"},{locale:"bn",label:"বাংলা"},{locale:"pa",label:"ਪੰਜਾਬੀ"},{locale:"gu-in",label:"ગુજરાતી"},{locale:"ta",label:"தமிழ்"},{locale:"te",label:"తెలుగు"},{locale:"kn",label:"ಕನ್ನಡ"},{locale:"ml",label:"മലയാളം"},{locale:"th",label:"ภาษาไทย"},{locale:"km-kh",label:"ភាសាខ្មែរ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function $ee(){const n=typeof window<"u"&&window.navigator?window.navigator.languages??["en"]:["en"];return Kee(n)}function Kee(n){for(const e of n){const t=qee(e);if(t)return t}return"en"}const h3={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function qee(n){const e=dm.find(i=>i.locale===n.toLowerCase());if(e)return e.locale;const[t,r]=n.split(/[-_]/).map(i=>i.toLowerCase());if(r){const i=dm.find(s=>s.locale===t);if(i)return i.locale}return t in h3?h3[t]:null}xu("@tldraw/tlschema","4.1.2","esm");function Vee(){return m.jsx("div",{className:"tl-background"})}function Zm(n,e,t,r,i,s){E.useLayoutEffect(()=>{const o=n.current;if(!o||e===void 0)return;let a=`translate(${e}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),i!==void 0&&(a+=` rotate(${i}rad)`),s&&(a+=` translate(${s.x}px, ${s.y}px)`),o.style.transform=a})}const Ti={linear:n=>n,easeInQuad:n=>n*n,easeOutQuad:n=>n*(2-n),easeInOutQuad:n=>n<.5?2*n*n:-1+(4-2*n)*n,easeInCubic:n=>n*n*n,easeOutCubic:n=>--n*n*n+1,easeInOutCubic:n=>n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1,easeInQuart:n=>n*n*n*n,easeOutQuart:n=>1- --n*n*n*n,easeInOutQuart:n=>n<.5?8*n*n*n*n:1-8*--n*n*n*n,easeInQuint:n=>n*n*n*n*n,easeOutQuint:n=>1+--n*n*n*n*n,easeInOutQuint:n=>n<.5?16*n*n*n*n*n:1+16*--n*n*n*n*n,easeInSine:n=>1-Math.cos(n*Math.PI/2),easeOutSine:n=>Math.sin(n*Math.PI/2),easeInOutSine:n=>-(Math.cos(Math.PI*n)-1)/2,easeInExpo:n=>n<=0?0:Math.pow(2,10*n-10),easeOutExpo:n=>n>=1?1:1-Math.pow(2,-10*n),easeInOutExpo:n=>n<=0?0:n>=1?1:n<.5?Math.pow(2,20*n-10)/2:(2-Math.pow(2,-20*n+10))/2};class I{constructor(e=0,t=0,r=1){this.x=e,this.y=t,this.z=r}get pressure(){return this.z}set(e=this.x,t=this.y,r=this.z){return this.x=e,this.y=t,this.z=r,this}setTo({x:e=0,y:t=0,z:r=1}){return this.x=e,this.y=t,this.z=r,this}rot(e){if(e===0)return this;const{x:t,y:r}=this,i=Math.sin(e),s=Math.cos(e);return this.x=t*s-r*i,this.y=t*i+r*s,this}rotWith(e,t){if(t===0)return this;const r=this.x-e.x,i=this.y-e.y,s=Math.sin(t),o=Math.cos(t);return this.x=e.x+(r*o-i*s),this.y=e.y+(r*s+i*o),this}clone(){const{x:e,y:t,z:r}=this;return new I(e,t,r)}sub(e){return this.x-=e.x,this.y-=e.y,this}subXY(e,t){return this.x-=e,this.y-=t,this}subScalar(e){return this.x-=e,this.y-=e,this}add(e){return this.x+=e.x,this.y+=e.y,this}addXY(e,t){return this.x+=e,this.y+=t,this}addScalar(e){return this.x+=e,this.y+=e,this}clamp(e,t){return this.x=Math.max(this.x,e),this.y=Math.max(this.y,e),t!==void 0&&(this.x=Math.min(this.x,t),this.y=Math.min(this.y,t)),this}div(e){return this.x/=e,this.y/=e,this}divV(e){return this.x/=e.x,this.y/=e.y,this}mul(e){return this.x*=e,this.y*=e,this}mulV(e){return this.x*=e.x,this.y*=e.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(e,t){const r=I.Tan(e,this);return this.add(r.mul(t))}neg(){return this.x*=-1,this.y*=-1,this}cross(e){return this.x=this.y*e.z-this.z*e.y,this.y=this.z*e.x-this.x*e.z,this}dpr(e){return I.Dpr(this,e)}cpr(e){return I.Cpr(this,e)}len2(){return I.Len2(this)}len(){return I.Len(this)}pry(e){return I.Pry(this,e)}per(){const{x:e,y:t}=this;return this.x=t,this.y=-e,this}uni(){const e=this.len();return e===0?this:(this.x/=e,this.y/=e,this)}tan(e){return this.sub(e).uni()}dist(e){return I.Dist(this,e)}distanceToLineSegment(e,t){return I.DistanceToLineSegment(e,t,this)}slope(e){return I.Slope(this,e)}snapToGrid(e){return this.x=Math.round(this.x/e)*e,this.y=Math.round(this.y/e)*e,this}angle(e){return I.Angle(this,e)}toAngle(){return I.ToAngle(this)}lrp(e,t){return this.x=this.x+(e.x-this.x)*t,this.y=this.y+(e.y-this.y)*t,this}equals(e){return I.Equals(this,e)}equalsXY(e,t){return I.EqualsXY(this,e,t)}toFixed(){return this.x=oa(this.x),this.y=oa(this.y),this}toString(){return I.ToString(I.ToFixed(this))}toJson(){return I.ToJson(this)}toArray(){return I.ToArray(this)}static Add(e,t){return new I(e.x+t.x,e.y+t.y)}static AddXY(e,t,r){return new I(e.x+t,e.y+r)}static Sub(e,t){return new I(e.x-t.x,e.y-t.y)}static SubXY(e,t,r){return new I(e.x-t,e.y-r)}static AddScalar(e,t){return new I(e.x+t,e.y+t)}static SubScalar(e,t){return new I(e.x-t,e.y-t)}static Div(e,t){return new I(e.x/t,e.y/t)}static Mul(e,t){return new I(e.x*t,e.y*t)}static DivV(e,t){return new I(e.x/t.x,e.y/t.y)}static MulV(e,t){return new I(e.x*t.x,e.y*t.y)}static Neg(e){return new I(-e.x,-e.y)}static Per(e){return new I(e.y,-e.x)}static Abs(e){return new I(Math.abs(e.x),Math.abs(e.y))}static Dist(e,t){return((e.y-t.y)**2+(e.x-t.x)**2)**.5}static ManhattanDist(e,t){return Math.abs(e.x-t.x)+Math.abs(e.y-t.y)}static DistMin(e,t,r){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)<r**2}static Dist2(e,t){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)}static Dpr(e,t){return e.x*t.x+e.y*t.y}static Cross(e,t){return new I(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z)}static Cpr(e,t){return e.x*t.y-t.x*e.y}static Len2(e){return e.x*e.x+e.y*e.y}static Len(e){return(e.x*e.x+e.y*e.y)**.5}static Pry(e,t){return I.Dpr(e,t)/I.Len(t)}static Uni(e){const t=I.Len(e);return new I(t===0?0:e.x/t,t===0?0:e.y/t)}static Tan(e,t){return I.Uni(I.Sub(e,t))}static Min(e,t){return new I(Math.min(e.x,t.x),Math.min(e.y,t.y))}static Max(e,t){return new I(Math.max(e.x,t.x),Math.max(e.y,t.y))}static From({x:e,y:t,z:r=1}){return new I(e,t,r)}static FromArray(e){return new I(e[0],e[1])}static Rot(e,t=0){const r=Math.sin(t),i=Math.cos(t);return new I(e.x*i-e.y*r,e.x*r+e.y*i)}static RotWith(e,t,r){const i=e.x-t.x,s=e.y-t.y,o=Math.sin(r),a=Math.cos(r);return new I(t.x+(i*a-s*o),t.y+(i*o+s*a))}static NearestPointOnLineThroughPoint(e,t,r){return I.Mul(t,I.Sub(r,e).pry(t)).add(e)}static NearestPointOnLineSegment(e,t,r,i=!0){if(I.Equals(e,r)||I.Equals(t,r))return I.From(r);const s=I.Tan(t,e),o=I.Add(e,I.Mul(s,I.Sub(r,e).pry(s)));if(i){if(o.x<Math.min(e.x,t.x))return I.Cast(e.x<t.x?e:t);if(o.x>Math.max(e.x,t.x))return I.Cast(e.x>t.x?e:t);if(o.y<Math.min(e.y,t.y))return I.Cast(e.y<t.y?e:t);if(o.y>Math.max(e.y,t.y))return I.Cast(e.y>t.y?e:t)}return o}static DistanceToLineThroughPoint(e,t,r){return I.Dist(r,I.NearestPointOnLineThroughPoint(e,t,r))}static DistanceToLineSegment(e,t,r,i=!0){return I.Dist(r,I.NearestPointOnLineSegment(e,t,r,i))}static Snap(e,t=1){return new I(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}static Cast(e){return e instanceof I?e:I.From(e)}static Slope(e,t){return e.x===t.y?NaN:(e.y-t.y)/(e.x-t.x)}static IsNaN(e){return isNaN(e.x)||isNaN(e.y)}static Angle(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}static AngleBetween(e,t){const r=e.x*t.x+e.y*t.y,i=Math.sqrt((Math.pow(e.x,2)+Math.pow(e.y,2))*(Math.pow(t.x,2)+Math.pow(t.y,2)));return(e.x*t.y-e.y*t.x<0?-1:1)*Math.acos(st(r/i,-1,1))}static Lrp(e,t,r){return I.Sub(t,e).mul(r).add(e)}static Med(e,t){return new I((e.x+t.x)/2,(e.y+t.y)/2)}static Equals(e,t){return Math.abs(e.x-t.x)<1e-4&&Math.abs(e.y-t.y)<1e-4}static EqualsXY(e,t,r){return e.x===t&&e.y===r}static Clockwise(e,t,r){return(r.x-e.x)*(t.y-e.y)-(t.x-e.x)*(r.y-e.y)<0}static Rescale(e,t){const r=I.Len(e);return new I(t*e.x/r,t*e.y/r)}static ScaleWithOrigin(e,t,r){return I.Sub(e,r).mul(t).add(r)}static ToFixed(e){return new I(oa(e.x),oa(e.y))}static ToInt(e){return new I(parseInt(e.x.toFixed(0)),parseInt(e.y.toFixed(0)),parseInt((e.z??0).toFixed(0)))}static ToCss(e){return`${e.x},${e.y}`}static Nudge(e,t,r){return I.Add(e,I.Tan(t,e).mul(r))}static ToString(e){return`${e.x}, ${e.y}`}static ToAngle(e){let t=Math.atan2(e.y,e.x);return t<0&&(t+=Math.PI*2),t}static FromAngle(e,t=1){return new I(Math.cos(e)*t,Math.sin(e)*t)}static ToArray(e){return[e.x,e.y,e.z]}static ToJson(e){const{x:t,y:r,z:i}=e;return{x:t,y:r,z:i}}static Average(e){const t=e.length,r=new I(0,0);if(t===0)return r;for(let i=0;i<t;i++)r.add(e[i]);return r.div(t)}static Clamp(e,t,r){return r===void 0?new I(Math.min(Math.max(e.x,t)),Math.min(Math.max(e.y,t))):new I(Math.min(Math.max(e.x,t),r),Math.min(Math.max(e.y,t),r))}static PointsBetween(e,t,r=6){const i=[];for(let s=0;s<r;s++){const o=Ti.easeInQuad(s/(r-1)),a=I.Lrp(e,t,o);a.z=Math.min(1,.5+Math.abs(.5-Gee(o))*.65),i.push(a)}return i}static SnapToGrid(e,t=8){return new I(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}}const Gee=n=>n<.5?2*n*n:-1+(4-2*n)*n;function Jr(n){return`${Z(n.x)},${Z(n.y)} `}function Es(n,e){return`${Z((n.x+e.x)/2)},${Z((n.y+e.y)/2)} `}const Ht=Math.PI,er=Ht/2,hn=Ht*2,Yee=Math.sin;function st(n,e,t){return Math.max(e,typeof t<"u"?Math.min(n,t):n)}function jS(n,e=1e10){return n?Math.round(n*e)/e:0}function ir(n,e,t=1e-6){return Math.abs(n-e)<=t}function eu(n,e,t=1e-6){return n<e||ir(n,e,t)}function Wee(n,e){const t=Math.pow(n-e,2)/Math.pow(n+e,2);return Ht*(n+e)*(1+3*t/(10+Math.sqrt(4-3*t)))}function ox(n){return n=n%hn,n<0?n=n+hn:n===0&&(n=0),n}function i2(n,e){return n=ox(n),e=ox(e),n>e&&(e+=hn),e-n}function Xee(n,e){return hn-i2(n,e)}function kb(n,e){const t=(e-n)%hn;return 2*t%hn-t}function V_(n){return(hn+n)%hn}function ax(n,e){const t=hn/e;let r=Math.floor((V_(n)+t/2)/t)*t%hn;return r<Ht&&(r+=hn),r>Ht&&(r-=hn),r}function SF(n,e){return n===e||ir(n%(Math.PI/2)-e%(Math.PI/2),0)}function Zee(n){return n*Ht/180}function Jee(n){return n*180/Ht}function s2(n,e,t){return new I(n.x,n.y).add(I.FromAngle(t,e))}function mE(n,e,t){const r=n/2,i=e/2,s=[];let o=1/0,a=-1/0,l=1/0,u=-1/0;for(let b=0;b<t;b++){const v=hn/t,w=-er+b*v,x=r+r*Math.cos(w),T=i+i*Math.sin(w);x<o&&(o=x),T<l&&(l=T),x>a&&(a=x),T>u&&(u=T),s.push(new I(x,T))}const f=a-o,h=u-l,g=n-f,y=e-h;if(g!==0||y!==0)for(let b=0;b<s.length;b++){const v=s[b];v.x=(v.x-o)/f*n,v.y=(v.y-l)/h*e}return s}function ag(n,e,t,r){return n<r&&t<e}function sa(n,e,t,r){const i=Math.max(n,t),s=Math.min(e,r);return i<=s?[i,s]:null}function f3(n,e,t){return(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y)}function Gi(n,e){let t=0,r,i;for(let s=0;s<e.length;s++){if(r=e[s],r.x===n.x&&r.y===n.y||(i=e[(s+1)%e.length],I.Dist(n,r)+I.Dist(n,i)===I.Dist(r,i)))return!0;r.y<=n.y?i.y>n.y&&f3(r,i,n)>0&&(t+=1):i.y<=n.y&&f3(r,i,n)<0&&(t-=1)}return t!==0}function Z(n){return Math.round(n*1e4)/1e4}function oa(n){return Math.round(n*100)/100}const p3=n=>Math.abs(n)<Number.MAX_SAFE_INTEGER;function g3(n,e,t,r){let i;if(Math.abs(n)>Ht){i=kb(e,r);const s=kb(r,t);return Math.abs(i)<Math.abs(s)?i/n:(n-s)/n}else{i=kb(e,r);const s=i/n;return Math.sign(i)!==Math.sign(n)?Math.abs(s)>.5?1:0:s}}function Qee(n,e,t,r){const i=2*((e-n)%hn)%hn-(e-n)%hn;return r?(hn-Math.abs(i))*(t?1:-1):i}function bF(n,e,t){const r=-2*(n.x*(e.y-t.y)-n.y*(e.x-t.x)+e.x*t.y-t.x*e.y),i=((n.x*n.x+n.y*n.y)*(t.y-e.y)+(e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y))/r,s=((n.x*n.x+n.y*n.y)*(e.x-t.x)+(e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x))/r;return!Number.isFinite(i)||!Number.isFinite(s)?null:new I(i,s)}const yE=({brush:n,color:e,opacity:t,className:r})=>{const i=E.useRef(null);Zm(i,n.x,n.y);const s=Z(Math.max(1,n.w)),o=Z(Math.max(1,n.h));return m.jsx("svg",{className:"tl-overlays__item",ref:i,"aria-hidden":"true",children:e?m.jsxs("g",{className:"tl-brush",opacity:t,children:[m.jsx("rect",{width:s,height:o,fill:e,opacity:.75}),m.jsx("rect",{width:s,height:o,fill:"none",stroke:e,opacity:.1})]}):m.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:o})})};var SE={exports:{}};/*!
103
- Copyright (c) 2018 Jed Watson.
104
- Licensed under the MIT License (MIT), see
105
- http://jedwatson.github.io/classnames
106
- */var m3;function ete(){return m3||(m3=1,(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var s="",o=0;o<arguments.length;o++){var a=arguments[o];a&&(s=i(s,r(a)))}return s}function r(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return t.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var o="";for(var a in s)e.call(s,a)&&s[a]&&(o=i(o,a));return o}function i(s,o){return o?s?s+" "+o:s+o:s}n.exports?(t.default=t,n.exports=t):window.classNames=t})()})(SE)),SE.exports}var tte=ete();const Fe=Ja(tte),Nt={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isDarwin:!1,hasCanvasSupport:!1};typeof window<"u"&&"navigator"in window&&(Nt.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Nt.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Nt.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Nt.isFirefox=/firefox/i.test(navigator.userAgent),Nt.isAndroid=/android/i.test(navigator.userAgent),Nt.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Nt.hasCanvasSupport=typeof window<"u"&&"Promise"in window&&"HTMLCanvasElement"in window);const y3={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.05,.1,.25,.5,1,2,4,8]},bE={duration:0,easing:Ti.easeInOutCubic},S3={CAMERA_MOVE:-10},nte=["top","right","bottom","left"],b3=0,o2=2,LS=1,x3=5,rte=128;var xE={};const ite={},xF=Si("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),In={logPreventDefaults:Si("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Si("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Si("logElementRemoves",{defaults:{all:!1}}),debugSvg:Si("debugSvg",{defaults:{all:!1}}),showFps:Si("showFps",{defaults:{all:!1}}),measurePerformance:Si("measurePerformance",{defaults:{all:!1}}),throwToBlob:Si("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Si("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Si("debugCursors",{defaults:{all:!1}}),forceSrgb:Si("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Si("debugGeometry",{defaults:{all:!1}}),hideShapes:Si("hideShapes",{defaults:{all:!1}}),editOnType:Si("editOnType",{defaults:{all:!1}}),a11y:Si("a11y",{defaults:{all:!1}}),debugElbowArrows:Si("debugElbowArrows",{defaults:{all:!1}})};if(typeof Element<"u"){const n=Element.prototype.removeChild;Ms("element removal logging",()=>{In.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),n.call(this,e)}:Element.prototype.removeChild=n})}function Si(n,{defaults:e,shouldStoreForSession:t=!0}){return ste({name:n,defaults:e,shouldStoreForSession:t})}function ste(n){const e=ate(n),t=n.shouldStoreForSession?ote(n.name):null,r=bn(`debug:${n.name}`,t??e);return typeof window<"u"&&(n.shouldStoreForSession&&Ms(`debug:${n.name}`,()=>{const i=r.get();i===e?NB(`tldraw_debug:${n.name}`):wI(`tldraw_debug:${n.name}`,JSON.stringify(i))}),Object.defineProperty(window,`tldraw${n.name.replace(/^[a-z]/,i=>i.toUpperCase())}`,{get(){return r.get()},set(i){r.set(i)},configurable:!0})),Object.assign(r,n,{reset:()=>r.set(e)})}function ote(n){try{return JSON.parse(LB(`tldraw_debug:${n}`)??"null")}catch{return null}}function vE(n){try{return n()}catch{return null}}function ate(n){switch(vE(()=>xE.TLDRAW_ENV)??vE(()=>xE.VERCEL_PUBLIC_TLDRAW_ENV)??vE(()=>xE.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return n.defaults.production??n.defaults.all;case"preview":case"staging":return n.defaults.staging??n.defaults.all;default:return n.defaults.development??n.defaults.all}}function lx(n){if(n.nodeType===Node.ELEMENT_NODE)return n;if(n.parentElement)return lx(n.parentElement);throw Error("Could not find a parent element of an HTML type!")}function nt(n){n.preventDefault(),In.logPreventDefaults.get()&&console.warn("preventDefault called on event:",n)}function Jm(n,e){if(n.setPointerCapture(e.pointerId),In.logPointerCaptures.get()){const t=xF.get();t.set(n,(t.get(n)??0)+1),console.warn("setPointerCapture called on element:",n,e)}}function Qm(n,e){if(n.hasPointerCapture(e.pointerId)&&(n.releasePointerCapture(e.pointerId),In.logPointerCaptures.get())){const t=xF.get();t.get(n)===1?t.delete(n):t.has(n)?t.set(n,t.get(n)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",n,e)}}const bi=(n,e,t)=>{n&&n.style.setProperty(e,t)};function vF(n=!1){const{activeElement:e}=document,t=n?["input","textarea"]:["input","select","button","textarea"];return!!(e&&(e.isContentEditable||t.indexOf(e.tagName.toLowerCase())>-1||e.classList.contains("tlui-slider__thumb")))}const xn=n=>Nt.isDarwin?n.metaKey:n.ctrlKey||n.metaKey;function Ei(n,e){return n.markEventAsHandled(e),{point:{x:e.clientX,y:e.clientY,z:e.pressure},shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,metaKey:e.metaKey,accelKey:xn(e),pointerId:e.pointerId,button:e.button,isPen:e.pointerType==="pen"}}function a2(n,e){return Ov(`${n}_${e}`)}function Vd(n){return Ov(`${E.useId()}${n??""}`)}function da(n){const e=Mr(E.useContext(wF));return Ov(`${e}_${n}`)}function Ov(n){return n.replace(/:/g,"_")}const wF=E.createContext(null);function lte({children:n}){const e=Vd();return m.jsx(wF.Provider,{value:e,children:n})}const l2=E.createContext(null);function te(){const n=Ge.useContext(l2);if(!n)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return n}function Vn(){return Ge.useContext(l2)}function c2({editor:n,children:e}){return m.jsx(l2.Provider,{value:n,children:m.jsx(lte,{children:e})})}function Dv(){const n=te(),e=ee("current tool",()=>n.getCurrentTool(),[n]),t=E.useMemo(function(){function i(y){if(!n.wasEventAlreadyHandled(y)){if(y.button===o2){n.dispatch({type:"pointer",target:"canvas",name:"right_click",...Ei(n,y)});return}y.button!==0&&y.button!==1&&y.button!==5||(Jm(y.currentTarget,y),n.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Ei(n,y)}))}}function s(y){n.wasEventAlreadyHandled(y)||y.button!==0&&y.button!==1&&y.button!==2&&y.button!==5||(Qm(y.currentTarget,y),n.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Ei(n,y)}))}function o(y){if(n.wasEventAlreadyHandled(y)||n.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const b=y.pointerType==="mouse"||y.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:b?!0:null})}function a(y){if(n.wasEventAlreadyHandled(y)||n.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const b=y.pointerType==="mouse"||y.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:b?!1:null})}function l(y){n.wasEventAlreadyHandled(y)||(n.markEventAsHandled(y),nt(y))}function u(y){if(n.wasEventAlreadyHandled(y)||(n.markEventAsHandled(y),!(y.target instanceof HTMLElement)))return;const b=n.getEditingShape()?.id;!(b&&y.target.closest(`[data-shape-id="${b}"]`))&&y.target.tagName!=="A"&&y.target.tagName!=="TEXTAREA"&&!y.target.isContentEditable&&nt(y)}function f(y){n.wasEventAlreadyHandled(y)||nt(y)}async function h(y){if(n.wasEventAlreadyHandled(y))return;if(nt(y),y.stopPropagation(),y.dataTransfer?.files?.length){const v=Array.from(y.dataTransfer.files);await n.putExternalContent({type:"files",files:v,point:n.screenToPage({x:y.clientX,y:y.clientY})});return}const b=y.dataTransfer.getData("url");if(b){await n.putExternalContent({type:"url",url:b,point:n.screenToPage({x:y.clientX,y:y.clientY})});return}}function g(y){n.wasEventAlreadyHandled(y)||y.stopPropagation()}return{onPointerDown:i,onPointerUp:s,onPointerEnter:o,onPointerLeave:a,onDragOver:f,onDrop:h,onTouchStart:l,onTouchEnd:u,onClick:g}},[n]);return E.useEffect(()=>{let r,i;function s(o){if(n.wasEventAlreadyHandled(o)||(n.markEventAsHandled(o),o.clientX===r&&o.clientY===i))return;r=o.clientX,i=o.clientY;const a=e.useCoalescedEvents&&o.getCoalescedEvents?o.getCoalescedEvents():[o];for(const l of a)n.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Ei(n,l)})}return document.body.addEventListener("pointermove",s),()=>{document.body.removeEventListener("pointermove",s)}},[n,e]),t}function cte(){const n=te();E.useEffect(()=>{let e=n.getInstanceState().isCoarsePointer;const t=o=>{const a=o.pointerType!=="mouse";e!==a&&(e=a,n.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",t,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),i=Nt.isFirefox&&!Nt.isAndroid&&!Nt.isIos,s=()=>{const o=i?!1:r.matches;e===o&&(e=o,n.updateInstanceState({isCoarsePointer:o}))};return r&&(r.addEventListener("change",s),s()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",s)}},[n])}const CF=E.createContext(null);function TF({container:n,children:e}){return m.jsx(CF.Provider,{value:n,children:e})}function or(){return Mr(E.useContext(CF),"useContainer used outside of <Tldraw />")}function ute(){const n=te(),e=or(),t=ee("isEditing",()=>n.getEditingShapeId(),[n]),r=ee("isFocused",()=>n.getIsFocused(),[n]);E.useEffect(()=>{if(!e)return;function i(s){if(s.isSpecialRedispatchedEvent)return;nt(s),s.stopPropagation();const o=e.querySelector(".tl-canvas");if(!o)return;const a=new DragEvent(s.type,s);a.isSpecialRedispatchedEvent=!0,o.dispatchEvent(a)}return e.addEventListener("dragover",i),e.addEventListener("drop",i),()=>{e.removeEventListener("dragover",i),e.removeEventListener("drop",i)}},[e]),E.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let i=null;const s=()=>{i?.();const o=`(resolution: ${window.devicePixelRatio}dppx)`,a=matchMedia(o),l=u=>{u.type==="change"&&s()};a.addEventListener?a.addEventListener("change",s):a.addListener&&a.addListener(l),i=()=>{a.removeEventListener?a.removeEventListener("change",s):a.removeListener&&a.removeListener(l)},n.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{i?.()}},[n]),E.useEffect(()=>{if(!r)return;const i=l=>{if(l.altKey&&(n.isIn("zoom")||!n.getPath().endsWith(".idle"))&&!lg(n)&&nt(l),n.wasEventAlreadyHandled(l))return;n.markEventAsHandled(l);const u=!!n.getSelectedShapeIds().length;switch(l.key){case"=":case"-":case"0":{if(l.metaKey||l.ctrlKey){nt(l);return}break}case"Tab":{if(lg(n))return;u&&!t&&nt(l);break}case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{if(lg(n))return;u&&(l.metaKey||l.ctrlKey)&&nt(l);break}case",":return;case"Escape":{if((n.getEditingShape()||n.getSelectedShapeIds().length>0)&&nt(l),n.menus.getOpenMenus().length>0)return;n.inputs.keys.has("Escape")||(n.inputs.keys.add("Escape"),n.cancel(),e.focus());return}default:if(lg(n))return}const f={type:"keyboard",name:l.repeat?"key_repeat":"key_down",key:l.key,code:l.code,shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:xn(l)};n.dispatch(f)},s=l=>{if(n.wasEventAlreadyHandled(l)||(n.markEventAsHandled(l),lg(n))||l.key===",")return;const u={type:"keyboard",name:"key_up",key:l.key,code:l.code,shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:xn(l)};n.dispatch(u)};function o(l){if(e.contains(l.target)){const u=l.touches[0].pageX,f=l.touches[0].radiusX||0;(u-f<10||u+f>n.getViewportScreenBounds().width-10)&&(l.target?.tagName==="BUTTON"&&l.target?.click(),nt(l))}}const a=l=>{e.contains(l.target)&&(l.ctrlKey||l.metaKey)&&nt(l)};return e.addEventListener("touchstart",o,{passive:!1}),e.addEventListener("wheel",a,{passive:!1}),document.addEventListener("gesturestart",nt),document.addEventListener("gesturechange",nt),document.addEventListener("gestureend",nt),e.addEventListener("keydown",i),e.addEventListener("keyup",s),()=>{e.removeEventListener("touchstart",o),e.removeEventListener("wheel",a),document.removeEventListener("gesturestart",nt),document.removeEventListener("gesturechange",nt),document.removeEventListener("gestureend",nt),e.removeEventListener("keydown",i),e.removeEventListener("keyup",s)}},[n,e,r,t])}function lg(n){return n.menus.hasOpenMenus()||vF()}function dte({className:n,zoom:e,point:t,color:r,viewport:i,opacity:s=1}){const o=E.useRef(null);Zm(o,st(t.x,i.minX+5/e,i.maxX-5/e),st(t.y,i.minY+5/e,i.maxY-5/e),1/e,I.Angle(i.center,t));const a=da("cursor_hint");return m.jsxs("svg",{ref:o,className:Fe("tl-overlays__item",n),"aria-hidden":"true",children:[m.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--tl-color-background)"}),m.jsx("use",{href:`#${a}`,color:r,opacity:s})]})}const v3=E.memo(function({className:e,zoom:t,point:r,color:i,name:s,chatMessage:o}){const a=E.useRef(null);Zm(a,r?.x,r?.y,1/t);const l=da("cursor");return r?m.jsxs("div",{ref:a,className:Fe("tl-overlays__item",e),children:[m.jsx("svg",{className:"tl-cursor","aria-hidden":"true",children:m.jsx("use",{href:`#${l}`,color:i})}),o?m.jsxs(m.Fragment,{children:[s&&m.jsx("div",{className:"tl-nametag-title",style:{color:i},children:s}),m.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:i},children:o})]}):s&&m.jsx("div",{className:"tl-nametag",style:{backgroundColor:i},children:s})]}):null}),ey={openWindow(n,e){window.open(n,e,"noopener noreferrer")},refreshPage(){window.location.reload()},async hardReset(){return await window.__tldraw__hardReset?.()}};function EF(){ey.hardReset()}function hte(){ey.refreshPage()}const fte={error:null};class u2 extends E.Component{static getDerivedStateFromError(e){return{error:e}}state=fte;componentDidCatch(e){this.props.onError?.(e)}render(){const{error:e}=this.state;if(e!==null){const{fallback:t}=this.props;return m.jsx(t,{error:e})}return this.props.children}}function hm({children:n,fallback:e,...t}){return e===null?n:m.jsx(u2,{fallback:e,...t,children:n})}const pte="https://github.com/tldraw/tldraw/issues/new",_F=({error:n,editor:e})=>{const t=E.useRef(null),[r,i]=E.useState(!1),[s,o]=E.useState(!1),[a,l]=E.useState(!1);let u=null;try{u=on().Canvas??null}catch{}const f=n instanceof Error?n.message:String(n),h=n instanceof Error?n.stack:null,g=ee("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[y,b]=E.useState(null);E.useLayoutEffect(()=>{g!==null&&b(g);let P=t.current?.parentElement,M=!1;for(;P;){if(P.classList.contains("tl-theme__dark")||P.classList.contains("tl-theme__light")){M=!0;break}P=P.parentElement}if(M){b(null);return}typeof window<"u"&&window.matchMedia&&b(window.matchMedia("(prefers-color-scheme: dark)").matches)},[g]),E.useEffect(()=>{if(s){const P=e?.timers.setTimeout(()=>{o(!1)},2e3);return()=>clearTimeout(P)}},[s,e]);const v=()=>{const P=document.createElement("textarea");P.value=h??f,document.body.appendChild(P),P.select(),document.execCommand("copy"),P.remove(),o(!0)},w=()=>{hte()},x=async()=>{EF()},T=new URL(pte);return T.searchParams.set("title",f),T.searchParams.set("labels","bug"),T.searchParams.set("body",`Hey, I ran into an error while using tldraw:
32
+ `).map(r=>r?{type:"paragraph",content:[{type:"text",text:r}]}:{type:"paragraph"})}}class Fr{constructor(e,t,r){this.id=e,this.defaultValue=t,this.type=r}static define(e,t){const{defaultValue:r,type:i=MQ}=t;return new Fr(e,r,i)}static defineEnum(e,t){const{defaultValue:r,values:i}=t;return new UQ(e,r,i)}setDefaultValue(e){this.defaultValue=e}validate(e){return this.type.validate(e)}validateUsingKnownGoodVersion(e,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(e,t):this.validate(t)}}class UQ extends Fr{constructor(e,t,r){super(e,t,Td(...r)),this.values=r}}const OS=Ds("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),HQ=lo({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:OS.AddIsLocked,up:n=>{n.isLocked=!1},down:n=>{delete n.isLocked}},{id:OS.HoistOpacity,up:n=>{n.opacity=Number(n.props.opacity??"1"),delete n.props.opacity},down:n=>{const e=n.opacity;delete n.opacity,n.props.opacity=e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}},{id:OS.AddMeta,up:n=>{n.meta={}}},{id:OS.AddWhite,up:n=>{},down:n=>{n.props.color==="white"&&(n.props.color="black")}}]});function hf(n){return n?n.typeName==="shape":!1}function $i(n){return n?n.startsWith("shape:"):!1}function Zt(n){return`shape:${n??zt()}`}function N4(n){const e=new Map;for(const[t,r]of Object.entries(n))if(r instanceof Fr){if(e.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);e.set(r,t)}return e}function Ko(n,e){return wu(e,(t,r)=>`com.tldraw.shape.${n}/${r}`)}function $Q(n){return Qa("shape",{scope:"document",validator:el("shape",XI("type",wu(n,(e,{props:t,meta:r})=>LQ(e,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function i3(n,e){const t=[];for(const[r,{migrations:i}]of Object.entries(e)){const s=`com.tldraw.${n}.${r}`;i?"sequenceId"in i?(Be(s===i.sequenceId,`sequenceId mismatch for ${r} ${_v} migrations. Expected '${s}', got '${i.sequenceId}'`),t.push(i)):"sequence"in i?t.push(bf({sequenceId:s,retroactive:!0,sequence:i.sequence.map(o=>"id"in o?z4(n,r,o):o)})):t.push(bf({sequenceId:s,retroactive:!0,sequence:Object.keys(i.migrators).map(o=>Number(o)).sort((o,a)=>o-a).map(o=>({id:`${s}/${o}`,scope:"record",filter:a=>a.typeName===n&&a.type===r,up:a=>{const l=i.migrators[o].up(a);if(l)return l},down:a=>{const l=i.migrators[o].down(a);if(l)return l}}))})):t.push(bf({sequenceId:s,retroactive:!0,sequence:[]}))}return t}function z4(n,e,t){return{id:t.id,dependsOn:t.dependsOn,scope:"record",filter:r=>r.typeName===n&&r.type===e,up:r=>{const i=t.up(r.props);i&&(r.props=i)},down:typeof t.down=="function"?r=>{const i=t.down(r.props);i&&(r.props=i)}:void 0}}const e2=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],tx={lightMode:{id:"light",text:"#000000",background:"#f9fafb",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",frameHeadingStroke:"#717171",frameHeadingFill:"#ffffff",frameStroke:"#717171",frameFill:"#ffffff",frameText:"#000000",noteFill:"#FCE19C",noteText:"#000000",semi:"#e8e8e8",pattern:"#494949",highlightSrgb:"#fddd00",highlightP3:"color(display-p3 0.972 0.8205 0.05)"},blue:{solid:"#4465e9",fill:"#4465e9",frameHeadingStroke:"#6681ec",frameHeadingFill:"#f9fafe",frameStroke:"#6681ec",frameFill:"#f9fafe",frameText:"#000000",noteFill:"#8AA3FF",noteText:"#000000",semi:"#dce1f8",pattern:"#6681ee",highlightSrgb:"#10acff",highlightP3:"color(display-p3 0.308 0.6632 0.9996)"},green:{solid:"#099268",fill:"#099268",frameHeadingStroke:"#37a684",frameHeadingFill:"#f8fcfa",frameStroke:"#37a684",frameFill:"#f8fcfa",frameText:"#000000",noteFill:"#6FC896",noteText:"#000000",semi:"#d3e9e3",pattern:"#39a785",highlightSrgb:"#00ffc8",highlightP3:"color(display-p3 0.2536 0.984 0.7981)"},grey:{solid:"#9fa8b2",fill:"#9fa8b2",frameHeadingStroke:"#aaaaab",frameHeadingFill:"#fbfcfc",frameStroke:"#aaaaab",frameFill:"#fcfcfd",frameText:"#000000",noteFill:"#C0CAD3",noteText:"#000000",semi:"#eceef0",pattern:"#bcc3c9",highlightSrgb:"#cbe7f1",highlightP3:"color(display-p3 0.8163 0.9023 0.9416)"},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",frameHeadingStroke:"#6cb2f3",frameHeadingFill:"#f8fbfe",frameStroke:"#6cb2f3",frameFill:"#fafcff",frameText:"#000000",noteFill:"#9BC4FD",noteText:"#000000",semi:"#ddedfa",pattern:"#6fbbf8",highlightSrgb:"#00f4ff",highlightP3:"color(display-p3 0.1512 0.9414 0.9996)"},"light-green":{solid:"#4cb05e",fill:"#4cb05e",frameHeadingStroke:"#6dbe7c",frameHeadingFill:"#f8fcf9",frameStroke:"#6dbe7c",frameFill:"#fafdfa",frameText:"#000000",noteFill:"#98D08A",noteText:"#000000",semi:"#dbf0e0",pattern:"#65cb78",highlightSrgb:"#65f641",highlightP3:"color(display-p3 0.563 0.9495 0.3857)"},"light-red":{solid:"#f87777",fill:"#f87777",frameHeadingStroke:"#f89090",frameHeadingFill:"#fffafa",frameStroke:"#f89090",frameFill:"#fffbfb",frameText:"#000000",noteFill:"#F7A5A1",noteText:"#000000",semi:"#f4dadb",pattern:"#fe9e9e",highlightSrgb:"#ff7fa3",highlightP3:"color(display-p3 0.9988 0.5301 0.6397)"},"light-violet":{solid:"#e085f4",fill:"#e085f4",frameHeadingStroke:"#e59bf5",frameHeadingFill:"#fefaff",frameStroke:"#e59bf5",frameFill:"#fefbff",frameText:"#000000",noteFill:"#DFB0F9",noteText:"#000000",semi:"#f5eafa",pattern:"#e9acf8",highlightSrgb:"#ff88ff",highlightP3:"color(display-p3 0.9676 0.5652 0.9999)"},orange:{solid:"#e16919",fill:"#e16919",frameHeadingStroke:"#e68544",frameHeadingFill:"#fef9f6",frameStroke:"#e68544",frameFill:"#fef9f6",frameText:"#000000",noteFill:"#FAA475",noteText:"#000000",semi:"#f8e2d4",pattern:"#f78438",highlightSrgb:"#ffa500",highlightP3:"color(display-p3 0.9988 0.6905 0.266)"},red:{solid:"#e03131",fill:"#e03131",frameHeadingStroke:"#e55757",frameHeadingFill:"#fef7f7",frameStroke:"#e55757",frameFill:"#fef9f9",frameText:"#000000",noteFill:"#FC8282",noteText:"#000000",semi:"#f4dadb",pattern:"#e55959",highlightSrgb:"#ff636e",highlightP3:"color(display-p3 0.9992 0.4376 0.45)"},violet:{solid:"#ae3ec9",fill:"#ae3ec9",frameHeadingStroke:"#bc62d3",frameHeadingFill:"#fcf7fd",frameStroke:"#bc62d3",frameFill:"#fdf9fd",frameText:"#000000",noteFill:"#DB91FD",noteText:"#000000",semi:"#ecdcf2",pattern:"#bd63d3",highlightSrgb:"#c77cff",highlightP3:"color(display-p3 0.7469 0.5089 0.9995)"},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",frameHeadingStroke:"#f3bb6c",frameHeadingFill:"#fefcf8",frameStroke:"#f3bb6c",frameFill:"#fffdfa",frameText:"#000000",noteFill:"#FED49A",noteText:"#000000",semi:"#f9f0e6",pattern:"#fecb92",highlightSrgb:"#fddd00",highlightP3:"color(display-p3 0.972 0.8705 0.05)"},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",frameHeadingStroke:"#7d7d7d",frameHeadingFill:"#ffffff",frameStroke:"#7d7d7d",frameFill:"#ffffff",frameText:"#000000",noteFill:"#FFFFFF",noteText:"#000000",highlightSrgb:"#ffffff",highlightP3:"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",frameHeadingStroke:"#5c5c5c",frameHeadingFill:"#252525",frameStroke:"#5c5c5c",frameFill:"#0c0c0c",frameText:"#f2f2f2",noteFill:"#2c2c2c",noteText:"#f2f2f2",semi:"#2c3036",pattern:"#989898",highlightSrgb:"#d2b700",highlightP3:"color(display-p3 0.8078 0.6225 0.0312)"},blue:{solid:"#4f72fc",fill:"#4f72fc",frameHeadingStroke:"#384994",frameHeadingFill:"#1C2036",frameStroke:"#384994",frameFill:"#11141f",frameText:"#f2f2f2",noteFill:"#2A3F98",noteText:"#f2f2f2",semi:"#262d40",pattern:"#3a4b9e",highlightSrgb:"#0079d2",highlightP3:"color(display-p3 0.0032 0.4655 0.7991)"},green:{solid:"#099268",fill:"#099268",frameHeadingStroke:"#10513C",frameHeadingFill:"#14241f",frameStroke:"#10513C",frameFill:"#0E1614",frameText:"#f2f2f2",noteFill:"#014429",noteText:"#f2f2f2",semi:"#253231",pattern:"#366a53",highlightSrgb:"#009774",highlightP3:"color(display-p3 0.0085 0.582 0.4604)"},grey:{solid:"#9398b0",fill:"#9398b0",frameHeadingStroke:"#42474D",frameHeadingFill:"#23262A",frameStroke:"#42474D",frameFill:"#151719",frameText:"#f2f2f2",noteFill:"#56595F",noteText:"#f2f2f2",semi:"#33373c",pattern:"#7c8187",highlightSrgb:"#9cb4cb",highlightP3:"color(display-p3 0.6299 0.7012 0.7856)"},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",frameHeadingStroke:"#075797",frameHeadingFill:"#142839",frameStroke:"#075797",frameFill:"#0B1823",frameText:"#f2f2f2",noteFill:"#1F5495",noteText:"#f2f2f2",semi:"#2a3642",pattern:"#4d7aa9",highlightSrgb:"#00bdc8",highlightP3:"color(display-p3 0.0023 0.7259 0.7735)"},"light-green":{solid:"#40c057",fill:"#40c057",frameHeadingStroke:"#1C5427",frameHeadingFill:"#18251A",frameStroke:"#1C5427",frameFill:"#0F1911",frameText:"#f2f2f2",noteFill:"#21581D",noteText:"#f2f2f2",semi:"#2a3830",pattern:"#4e874e",highlightSrgb:"#00a000",highlightP3:"color(display-p3 0.2711 0.6172 0.0195)"},"light-red":{solid:"#ff8787",fill:"#ff8787",frameHeadingStroke:"#6f3232",frameHeadingFill:"#341818",frameStroke:"#6f3232",frameFill:"#181212",frameText:"#f2f2f2",noteFill:"#7a3333",noteText:"#f2f2f2",semi:"#3c2b2b",pattern:"#a56767",highlightSrgb:"#db005b",highlightP3:"color(display-p3 0.7849 0.0585 0.3589)"},"light-violet":{solid:"#e599f7",fill:"#e599f7",frameHeadingStroke:"#6c367a",frameHeadingFill:"#2D2230",frameStroke:"#6c367a",frameFill:"#1C151E",frameText:"#f2f2f2",noteFill:"#762F8E",noteText:"#f2f2f2",semi:"#383442",pattern:"#9770a9",highlightSrgb:"#c400c7",highlightP3:"color(display-p3 0.7024 0.0403 0.753)"},orange:{solid:"#f76707",fill:"#f76707",frameHeadingStroke:"#773a0e",frameHeadingFill:"#2f1d13",frameStroke:"#773a0e",frameFill:"#1c1512",frameText:"#f2f2f2",noteFill:"#7c3905",noteText:"#f2f2f2",semi:"#3b2e27",pattern:"#9f552d",highlightSrgb:"#d07a00",highlightP3:"color(display-p3 0.7699 0.4937 0.0085)"},red:{solid:"#e03131",fill:"#e03131",frameHeadingStroke:"#701e1e",frameHeadingFill:"#301616",frameStroke:"#701e1e",frameFill:"#1b1313",frameText:"#f2f2f2",noteFill:"#7e201f",noteText:"#f2f2f2",semi:"#382726",pattern:"#8f3734",highlightSrgb:"#de002c",highlightP3:"color(display-p3 0.7978 0.0509 0.2035)"},violet:{solid:"#ae3ec9",fill:"#ae3ec9",frameHeadingStroke:"#6d1583",frameHeadingFill:"#27152e",frameStroke:"#6d1583",frameFill:"#1b0f21",frameText:"#f2f2f2",noteFill:"#5f1c70",noteText:"#f2f2f2",semi:"#342938",pattern:"#763a8b",highlightSrgb:"#9e00ee",highlightP3:"color(display-p3 0.5651 0.0079 0.8986)"},yellow:{solid:"#ffc034",fill:"#ffc034",frameHeadingStroke:"#684e12",frameHeadingFill:"#2a2113",frameStroke:"#684e12",frameFill:"#1e1911",frameText:"#f2f2f2",noteFill:"#8a5e1c",noteText:"#f2f2f2",semi:"#3b352b",pattern:"#fecb92",highlightSrgb:"#d2b700",highlightP3:"color(display-p3 0.8078 0.7225 0.0312)"},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",frameHeadingStroke:"#ffffff",frameHeadingFill:"#ffffff",frameStroke:"#ffffff",frameFill:"#ffffff",frameText:"#000000",noteFill:"#eaeaea",noteText:"#1d1d1d",highlightSrgb:"#ffffff",highlightP3:"color(display-p3 1 1 1)"}}};function _u(n){return n.isDarkMode?tx.darkMode:tx.lightMode}const Zi=Fr.defineEnum("tldraw:color",{defaultValue:"black",values:e2}),t2=Fr.defineEnum("tldraw:labelColor",{defaultValue:"black",values:e2}),KQ=new Set(e2);function qQ(n){return KQ.has(n)}function Mt(n,e,t){return qQ(e)?n[e][t]:e}const Pd=Fr.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Id=Fr.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),du=Fr.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),VQ={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},qa=Fr.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),GQ=["arc","elbow"],nx=Fr.defineEnum("tldraw:arrowKind",{defaultValue:"arc",values:GQ}),B4=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],U_=Fr.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:B4}),H_=Fr.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:B4}),F4={kind:nx,labelColor:t2,color:Zi,fill:Id,dash:Pd,size:qa,arrowheadStart:U_,arrowheadEnd:H_,font:du,start:_d,end:_d,bend:Qe,richText:Av,labelPosition:Qe,scale:rr,elbowMidPoint:Qe},Hc=Ko("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5,AddElbow:6,AddRichText:7});function zh(n){return z4("shape","arrow",n)}const U4=bf({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[zh({id:Hc.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"}),zh({id:Hc.AddIsPrecise,up:({start:n,end:e})=>{n.type==="binding"&&(n.isPrecise=!(n.normalizedAnchor.x===.5&&n.normalizedAnchor.y===.5)),e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5))},down:({start:n,end:e})=>{n.type==="binding"&&(n.isPrecise||(n.normalizedAnchor={x:.5,y:.5}),delete n.isPrecise),e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise)}}),zh({id:Hc.AddLabelPosition,up:n=>{n.labelPosition=.5},down:n=>{delete n.labelPosition}}),{id:Hc.ExtractBindings,scope:"store",up:n=>{const e=Object.values(n).filter(t=>t.typeName==="shape"&&t.type==="arrow");for(const t of e){const{start:r,end:i}=t.props;if(r.type==="binding"){const s=gd(),o={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};n[s]=o,t.props.start={x:0,y:0}}else delete t.props.start.type;if(i.type==="binding"){const s=gd(),o={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:i.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:i.normalizedAnchor,isExact:i.isExact,isPrecise:i.isPrecise}};n[s]=o,t.props.end={x:0,y:0}}else delete t.props.end.type}}},zh({id:Hc.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}),zh({id:Hc.AddElbow,up:n=>{n.kind="arc",n.elbowMidPoint=.5},down:n=>{delete n.kind,delete n.elbowMidPoint}}),zh({id:Hc.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}})]}),YQ=Td("center","edge-point","edge","none"),H4={terminal:Td("start","end"),normalizedAnchor:_d,isExact:pt,isPrecise:pt,snap:YQ},WQ=BQ("arrow",{AddSnap:1}),$4={sequence:[{dependsOn:[Hc.ExtractBindings]},{id:WQ.AddSnap,up:n=>{n.snap="none"},down:n=>{delete n.snap}}]},XQ=el("camera",Ct({typeName:Pi("camera"),id:no("camera"),x:Qe,y:Qe,z:Qe,meta:ti})),ZQ=Ds("com.tldraw.camera",{AddMeta:1}),JQ=lo({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:ZQ.AddMeta,up:n=>{n.meta={}}}]}),za=Qa("camera",{validator:XQ,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),QQ=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"]),K4=Mv(QQ),eee=Ct({type:K4,rotation:Qe}),tee=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),nee=Mv(tee),ree=new Set(["starting","paused","active","stopping"]),q4=Ct({id:dt,points:Dr(_d),size:Qb,color:nee,opacity:Qe,state:Mv(ree),delay:Qe,shrink:Qe,taper:pt}),um=no("page"),iee=el("page",Ct({typeName:Pi("page"),id:um,name:dt,index:JI,meta:ti})),see=Ds("com.tldraw.page",{AddMeta:1}),oee=lo({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:see.AddMeta,up:n=>{n.meta={}}}]}),Wi=Qa("page",{validator:iee,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Yr(n){return Wi.isId(n)}const aee={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};function V4(n){return n?Hg(n,e=>aee[e]):null}no("instance");function lee(n){const e={};for(const[r,i]of n)e[r]=j4(i);const t=el("instance",Ct({typeName:Pi("instance"),id:no("instance"),currentPageId:um,followingUserId:dt.nullable(),brush:Kg.nullable(),opacityForNextShape:L4,stylesForNextShape:Ct(e),cursor:eee,scribbles:Dr(q4),isFocusMode:pt,isDebugMode:pt,isToolLocked:pt,exportBackground:pt,screenBounds:Kg,insets:Dr(pt),zoomBrush:Kg.nullable(),isPenMode:pt,isGridMode:pt,chatMessage:dt,isChatting:pt,highlightedUserIds:Dr(dt),isFocused:pt,devicePixelRatio:Qe,isCoarsePointer:pt,isHoveringCanvas:pt.nullable(),openMenus:Dr(dt),isChangingStyle:pt,isReadonly:pt,meta:ti,duplicateProps:Ct({shapeIds:Dr(no("shape")),offset:Ct({x:Qe,y:Qe})}).nullable()}));return Qa("instance",{validator:t,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 yn=Ds("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}),cee=lo({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:yn.AddTransparentExportBgs,up:n=>({...n,exportBackground:!0})},{id:yn.RemoveDialog,up:({dialog:n,...e})=>e},{id:yn.AddToolLockMode,up:n=>({...n,isToolLocked:!1})},{id:yn.RemoveExtraPropsForNextShape,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:Object.fromEntries(Object.entries(n).filter(([t])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(t)))})},{id:yn.AddLabelColor,up:({propsForNextShape:n,...e})=>({...e,propsForNextShape:{...n,labelColor:"black"}})},{id:yn.AddFollowingUserId,up:n=>({...n,followingUserId:null})},{id:yn.RemoveAlignJustify,up:n=>{let e=n.propsForNextShape.align;return e==="justify"&&(e="start"),{...n,propsForNextShape:{...n.propsForNextShape,align:e}}}},{id:yn.AddZoom,up:n=>({...n,zoomBrush:null})},{id:yn.AddVerticalAlign,up:n=>({...n,propsForNextShape:{...n.propsForNextShape,verticalAlign:"middle"}})},{id:yn.AddScribbleDelay,up:n=>n.scribble!==null?{...n,scribble:{...n.scribble,delay:0}}:{...n}},{id:yn.RemoveUserId,up:({userId:n,...e})=>e},{id:yn.AddIsPenModeAndIsGridMode,up:n=>({...n,isPenMode:!1,isGridMode:!1})},{id:yn.HoistOpacity,up:({propsForNextShape:{opacity:n,...e},...t})=>({...t,opacityForNextShape:Number(n??"1"),propsForNextShape:e})},{id:yn.AddChat,up:n=>({...n,chatMessage:"",isChatting:!1})},{id:yn.AddHighlightedUserIds,up:n=>({...n,highlightedUserIds:[]})},{id:yn.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:n,...e})=>({...e,stylesForNextShape:{}})},{id:yn.AddMeta,up:n=>({...n,meta:{}})},{id:yn.RemoveCursorColor,up:n=>{const{color:e,...t}=n.cursor;return{...n,cursor:t}}},{id:yn.AddLonelyProperties,up:n=>({...n,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:yn.ReadOnlyReadonly,up:({isReadOnly:n,...e})=>({...e,isReadonly:n})},{id:yn.AddHoveringCanvas,up:n=>({...n,isHoveringCanvas:null})},{id:yn.AddScribbles,up:({scribble:n,...e})=>({...e,scribbles:[]})},{id:yn.AddInset,up:n=>({...n,insets:[!1,!1,!1,!1]}),down:({insets:n,...e})=>({...e})},{id:yn.AddDuplicateProps,up:n=>({...n,duplicateProps:null}),down:({duplicateProps:n,...e})=>({...e})},{id:yn.RemoveCanMoveCamera,up:({canMoveCamera:n,...e})=>({...e}),down:n=>({...n,canMoveCamera:!0})}]}),Ki="instance:instance",uee=el("instance_page_state",Ct({typeName:Pi("instance_page_state"),id:no("instance_page_state"),pageId:um,selectedShapeIds:Dr(Ao),hintingShapeIds:Dr(Ao),erasingShapeIds:Dr(Ao),hoveredShapeId:Ao.nullable(),editingShapeId:Ao.nullable(),croppingShapeId:Ao.nullable(),focusedGroupId:Ao.nullable(),meta:ti})),tg=Ds("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),dee=lo({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:tg.AddCroppingId,up(n){n.croppingShapeId=null}},{id:tg.RemoveInstanceIdAndCameraId,up(n){delete n.instanceId,delete n.cameraId}},{id:tg.AddMeta,up:n=>{n.meta={}}},{id:tg.RenameProperties,up:n=>{},down:n=>{}},{id:tg.RenamePropertiesAgain,up:n=>{n.selectedShapeIds=n.selectedIds,delete n.selectedIds,n.hintingShapeIds=n.hintingIds,delete n.hintingIds,n.erasingShapeIds=n.erasingIds,delete n.erasingIds,n.hoveredShapeId=n.hoveredId,delete n.hoveredId,n.editingShapeId=n.editingId,delete n.editingId,n.croppingShapeId=n.croppingShapeId??n.croppingId??null,delete n.croppingId,n.focusedGroupId=n.focusLayerId,delete n.focusLayerId},down:n=>{n.selectedIds=n.selectedShapeIds,delete n.selectedShapeIds,n.hintingIds=n.hintingShapeIds,delete n.hintingShapeIds,n.erasingIds=n.erasingShapeIds,delete n.erasingShapeIds,n.hoveredId=n.hoveredShapeId,delete n.hoveredShapeId,n.editingId=n.editingShapeId,delete n.editingShapeId,n.croppingId=n.croppingShapeId,delete n.croppingShapeId,n.focusLayerId=n.focusedGroupId,delete n.focusedGroupId}}]}),ca=Qa("instance_page_state",{validator:uee,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:{}})),hee=el("pointer",Ct({typeName:Pi("pointer"),id:no("pointer"),x:Qe,y:Qe,lastActivityTimestamp:Qe,meta:ti})),fee=Ds("com.tldraw.pointer",{AddMeta:1}),pee=lo({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:fee.AddMeta,up:n=>{n.meta={}}}]}),n2=Qa("pointer",{validator:hee,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),rx=n2.createId("pointer"),gee=el("instance_presence",Ct({typeName:Pi("instance_presence"),id:no("instance_presence"),userId:dt,userName:dt,lastActivityTimestamp:Qe.nullable(),followingUserId:dt.nullable(),cursor:Ct({x:Qe,y:Qe,type:K4,rotation:Qe}).nullable(),color:dt,camera:Ct({x:Qe,y:Qe,z:Qe}).nullable(),screenBounds:Kg.nullable(),selectedShapeIds:Dr(no("shape")),currentPageId:no("page"),brush:Kg.nullable(),scribbles:Dr(q4),chatMessage:dt,meta:ti})),Bh=Ds("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),mee=lo({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Bh.AddScribbleDelay,up:n=>{n.scribble!==null&&(n.scribble.delay=0)}},{id:Bh.RemoveInstanceId,up:n=>{delete n.instanceId}},{id:Bh.AddChatMessage,up:n=>{n.chatMessage=""}},{id:Bh.AddMeta,up:n=>{n.meta={}}},{id:Bh.RenameSelectedShapeIds,up:n=>{}},{id:Bh.NullableCameraCursor,up:n=>{},down:n=>{n.camera===null&&(n.camera={x:0,y:0,z:1}),n.lastActivityTimestamp===null&&(n.lastActivityTimestamp=0),n.cursor===null&&(n.cursor={type:"default",x:0,y:0,rotation:0}),n.screenBounds===null&&(n.screenBounds={x:0,y:0,w:1,h:1})}}]}),yee=Qa("instance_presence",{validator:gee,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),See=el("document",Ct({typeName:Pi("document"),id:Pi("document:document"),gridSize:Qe,name:dt,meta:ti})),s3=Ds("com.tldraw.document",{AddName:1,AddMeta:2}),bee=lo({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:s3.AddName,up:n=>{n.name=""},down:n=>{delete n.name}},{id:s3.AddMeta,up:n=>{n.meta={}}}]}),r2=Qa("document",{validator:See,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),$_=r2.createId("document");function o3(n){n.typeName==="asset"&&("src"in n&&(n.src="<redacted>"),"src"in n.props&&(n.props.src="<redacted>"))}function xee({error:n,phase:e,record:t,recordBefore:r}){throw yI(n,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?o3(Qn(r)):void 0,recordAfter:o3(Qn(t))}}),n}function vee(){return[Wi.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function wee(n){const e=n.query.ids("page"),t=n.query.records("instance_page_state"),r=()=>{if(!n.has($_))return n.put([r2.create({id:$_,name:n.props.defaultName})]),r();if(!n.has(rx))return n.put([n2.create({id:rx})]),r();const i=e.get();if(i.size===0)return n.put(vee()),r();const s=()=>[...i].map(f=>n.get(f)).sort(kr)[0].id,o=n.get(Ki);if(o){if(!i.has(o.currentPageId))return n.put([{...o,currentPageId:s()}]),r()}else return n.put([n.schema.types.instance.create({id:Ki,currentPageId:s(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const f of i){const h=ca.createId(f);n.get(h)||a.add(h);const y=za.createId(f);n.has(y)||l.add(y)}a.size>0&&n.put([...a].map(f=>ca.create({id:f,pageId:ca.parseId(f)}))),l.size>0&&n.put([...l].map(f=>za.create({id:f})));const u=t.get();for(const f of u){if(!i.has(f.pageId)){n.remove([f.id]);continue}if(f.croppingShapeId&&!n.has(f.croppingShapeId))return n.put([{...f,croppingShapeId:null}]),r();if(f.focusedGroupId&&!n.has(f.focusedGroupId))return n.put([{...f,focusedGroupId:null}]),r();if(f.hoveredShapeId&&!n.has(f.hoveredShapeId))return n.put([{...f,hoveredShapeId:null}]),r();const h=f.selectedShapeIds.filter(b=>n.has(b));if(h.length!==f.selectedShapeIds.length)return n.put([{...f,selectedShapeIds:h}]),r();const g=f.hintingShapeIds.filter(b=>n.has(b));if(g.length!==f.hintingShapeIds.length)return n.put([{...f,hintingShapeIds:g}]),r();const y=f.erasingShapeIds.filter(b=>n.has(b));if(y.length!==f.erasingShapeIds.length)return n.put([{...f,erasingShapeIds:y}]),r()}};return r}const Cee=QI("bookmark",Ct({title:dt,description:dt,image:dt,favicon:dt,src:Ed.nullable()})),a3=Ds("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),Tee=lo({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:n=>n.type==="bookmark",sequence:[{id:a3.MakeUrlsValid,up:n=>{Ed.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:a3.AddFavicon,up:n=>{Ed.isValid(n.props.favicon)||(n.props.favicon="")},down:n=>{delete n.props.favicon}}]}),Eee=QI("image",Ct({w:Qe,h:Qe,name:dt,isAnimated:pt,mimeType:dt.nullable(),src:Ed.nullable(),fileSize:rr.optional()})),ng=Ds("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),_ee=lo({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:n=>n.type==="image",sequence:[{id:ng.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:ng.RenameWidthHeight,up:n=>{n.props.w=n.props.width,n.props.h=n.props.height,delete n.props.width,delete n.props.height},down:n=>{n.props.width=n.props.w,n.props.height=n.props.h,delete n.props.w,delete n.props.h}},{id:ng.MakeUrlsValid,up:n=>{Ed.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:ng.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:ng.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),Pee=QI("video",Ct({w:Qe,h:Qe,name:dt,isAnimated:pt,mimeType:dt.nullable(),src:Ed.nullable(),fileSize:Qe.optional()})),rg=Ds("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),Iee=lo({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:n=>n.type==="video",sequence:[{id:rg.AddIsAnimated,up:n=>{n.props.isAnimated=!1},down:n=>{delete n.props.isAnimated}},{id:rg.RenameWidthHeight,up:n=>{n.props.w=n.props.width,n.props.h=n.props.height,delete n.props.width,delete n.props.height},down:n=>{n.props.width=n.props.w,n.props.height=n.props.h,delete n.props.w,delete n.props.h}},{id:rg.MakeUrlsValid,up:n=>{Ed.isValid(n.props.src)||(n.props.src="")},down:n=>{}},{id:rg.AddFileSize,up:n=>{n.props.fileSize=-1},down:n=>{delete n.props.fileSize}},{id:rg.MakeFileSizeOptional,up:n=>{n.props.fileSize===-1&&(n.props.fileSize=void 0)},down:n=>{n.props.fileSize===void 0&&(n.props.fileSize=-1)}}]}),Mee=el("asset",XI("type",{image:Eee,video:Pee,bookmark:Cee})),kee=Ds("com.tldraw.asset",{AddMeta:1}),Aee=lo({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:kee.AddMeta,up:n=>{n.meta={}}}]}),Pu=Qa("asset",{validator:Mee,scope:"document"}).withDefaultProperties(()=>({meta:{}})),G4={w:rr,h:rr,assetId:kv.nullable(),url:so},l3=Ko("bookmark",{NullAssetId:1,MakeUrlsValid:2}),Y4={sequence:[{id:l3.NullAssetId,up:n=>{n.assetId===void 0&&(n.assetId=null)},down:"retired"},{id:l3.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}}]},W4=Ct({type:Td("free","straight"),points:Dr(_d)}),X4={color:Zi,fill:Id,dash:Pd,size:qa,segments:Dr(W4),isComplete:pt,isClosed:pt,isPen:pt,scale:rr},c3=Ko("draw",{AddInPen:1,AddScale:2}),Z4={sequence:[{id:c3.AddInPen,up:n=>{const{points:e}=n.segments[0];if(e.length===0){n.isPen=!1;return}let t=!(e[0].z===0||e[0].z===.5);e[1]&&(t=t&&!(e[1].z===0||e[1].z===.5)),n.isPen=t},down:"retired"},{id:c3.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},Oee=/(^\/r\/[^/]+\/?$)/,Dee=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(Oee))return n}},{hostnames:["figma.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/?$/)){const t=e.searchParams.get("url");if(t)return t}}},{hostnames:["google.*"],fromEmbedUrl:n=>{const e=it(n);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[i,s]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${i},${s},${r}z`}}},{hostnames:["val.town"],fromEmbedUrl:n=>{const e=it(n),t=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:n=>{const e=it(n),t=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{hostnames:["codepen.io"],fromEmbedUrl:n=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,i,s]=t;return`https://codepen.io/${i}/pen/${s}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:n=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=n.match(e);if(t){const[r,i]=t;return`https://scratch.mit.edu/projects/${i}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],fromEmbedUrl:n=>{const e=it(n);if(!e)return;if(e.hostname.replace(/^www./,"")==="youtube.com"){const r=e.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{hostnames:["calendar.google.*"],fromEmbedUrl:n=>{const e=it(n),t=e?.searchParams.get("src");if(e?.pathname.match(/\/calendar\/embed/)&&t){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const i of r)e.searchParams.delete(i);return e.searchParams.set("cid",t),e.href}}},{hostnames:["docs.google.*"],fromEmbedUrl:n=>{const e=it(n);if(e?.pathname.match(/^\/presentation/)&&e?.pathname.match(/\/embed\/?$/)){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const t=Array.from(e.searchParams.keys());for(const r of t)e.searchParams.delete(r);return e.href}}},{hostnames:["gist.github.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return n.split("/").pop()?n:void 0}},{hostnames:["replit.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{hostnames:["open.spotify.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{hostnames:["vimeo.com","player.vimeo.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.hostname==="player.vimeo.com"){const t=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(t)return"https://vimeo.com/"+t[1]}}},{hostnames:["excalidraw.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.hash.match(/#room=/))return n}},{hostnames:["observablehq.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","")}#cell-*`;if(e&&e.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","/d")}#cell-*`}},{hostnames:["desmos.com"],fromEmbedUrl:n=>{const e=it(n);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return n.replace("?embed","")}}],J4={w:rr,h:rr,url:dt},DS=Ko("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),Q4={sequence:[{id:DS.GenOriginalUrlInEmbed,up:n=>{try{const e=n.url,t=new URL(e).host.replace("www.","");let r;for(const i of Dee)if(i.hostnames.includes(t))try{r=i.fromEmbedUrl(e)}catch(s){console.warn(s)}n.tmpOldUrl=n.url,n.url=r??""}catch{n.url="",n.tmpOldUrl=n.url}},down:"retired"},{id:DS.RemoveDoesResize,up:n=>{delete n.doesResize},down:"retired"},{id:DS.RemoveTmpOldUrl,up:n=>{delete n.tmpOldUrl},down:"retired"},{id:DS.RemovePermissionOverrides,up:n=>{delete n.overridePermissions},down:"retired"}]},eF={w:rr,h:rr,name:dt,color:Td(...Zi.values)},Ree=Ko("frame",{AddColorProp:1}),tF={sequence:[{id:Ree.AddColorProp,up:n=>{n.color="black"},down:n=>{delete n.color}}]},ix=Fr.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),sx=Fr.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Ba=Fr.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"]}),nF={geo:Ba,dash:Pd,url:so,w:rr,h:rr,growY:Qb,scale:rr,labelColor:t2,color:Zi,fill:Id,size:qa,font:du,align:ix,verticalAlign:sx,richText:Av},Ia=Ko("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9,AddRichText:10}),rF={sequence:[{id:Ia.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:Ia.AddLabelColor,up:n=>{n.labelColor="black"},down:"retired"},{id:Ia.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:Ia.AddCheckBox,up:n=>{},down:"retired"},{id:Ia.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:Ia.MigrateLegacyAlign,up:n=>{let e;switch(n.align){case"start":e="start-legacy";break;case"end":e="end-legacy";break;default:e="middle-legacy";break}n.align=e},down:"retired"},{id:Ia.AddCloud,up:n=>{},down:"retired"},{id:Ia.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:Ia.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:Ia.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}}]},iF={},sF={sequence:[]},oF={color:Zi,size:qa,segments:Dr(W4),isComplete:pt,isPen:pt,scale:rr},jee=Ko("highlight",{AddScale:1}),aF={sequence:[{id:jee.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},Lee=Ct({topLeft:_d,bottomRight:_d,isCircle:pt.optional()}),lF={w:rr,h:rr,playing:pt,url:so,assetId:kv.nullable(),crop:Lee.nullable(),flipX:pt,flipY:pt,altText:dt},ig=Ko("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4,AddAltText:5}),cF={sequence:[{id:ig.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:ig.AddCropProp,up:n=>{n.crop=null},down:n=>{delete n.crop}},{id:ig.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:ig.AddFlipProps,up:n=>{n.flipX=!1,n.flipY=!1},down:n=>{delete n.flipX,delete n.flipY}},{id:ig.AddAltText,up:n=>{n.altText=""},down:n=>{delete n.altText}}]},K_=Fr.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),Nee=Ct({id:dt,index:JI,x:Qe,y:Qe}),uF={color:Zi,dash:Pd,size:qa,spline:K_,points:ex(dt,Nee),scale:rr},sg=Ko("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),dF={sequence:[{id:sg.AddSnapHandles,up:n=>{for(const e of Object.values(n.handles))e.canSnap=!0},down:"retired"},{id:sg.RemoveExtraHandleProps,up:n=>{n.handles=IB(Object.values(n.handles).map(e=>[e.index,{x:e.x,y:e.y}]))},down:n=>{const e=Object.entries(n.handles).map(([t,r])=>({index:t,...r})).sort(kr);n.handles=Object.fromEntries(e.map((t,r)=>{const i=r===0?"start":r===e.length-1?"end":`handle:${t.index}`;return[i,{id:i,type:"vertex",canBind:!1,canSnap:!0,index:t.index,x:t.x,y:t.y}]}))}},{id:sg.HandlesToPoints,up:n=>{const e=Object.entries(n.handles).map(([t,{x:r,y:i}])=>({x:r,y:i,index:t})).sort(kr);n.points=e.map(({x:t,y:r})=>({x:t,y:r})),delete n.handles},down:n=>{const e=cm(n.points.length);n.handles=Object.fromEntries(n.points.map((t,r)=>[e[r],{x:t.x,y:t.y}])),delete n.points}},{id:sg.PointIndexIds,up:n=>{const e=cm(n.points.length);n.points=Object.fromEntries(n.points.map((t,r)=>{const i=e[r];return[i,{id:i,index:i,x:t.x,y:t.y}]}))},down:n=>{const e=Object.values(n.points).sort(kr);n.points=e.map(({x:t,y:r})=>({x:t,y:r}))}},{id:sg.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}}]},hF={color:Zi,labelColor:t2,size:qa,font:du,fontSizeAdjustment:Qb,align:ix,verticalAlign:sx,growY:Qb,url:so,richText:Av,scale:rr},Ol=Ko("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8,AddRichText:9}),fF={sequence:[{id:Ol.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:Ol.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:Ol.MigrateLegacyAlign,up:n=>{switch(n.align){case"start":n.align="start-legacy";return;case"end":n.align="end-legacy";return;default:n.align="middle-legacy";return}},down:"retired"},{id:Ol.AddVerticalAlign,up:n=>{n.verticalAlign="middle"},down:"retired"},{id:Ol.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:Ol.AddFontSizeAdjustment,up:n=>{n.fontSizeAdjustment=0},down:n=>{delete n.fontSizeAdjustment}},{id:Ol.AddScale,up:n=>{n.scale=1},down:n=>{delete n.scale}},{id:Ol.AddLabelColor,up:n=>{n.labelColor="black"},down:n=>{delete n.labelColor}},{id:Ol.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}}]},q_=Fr.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),pF={color:Zi,size:qa,font:du,textAlign:q_,w:rr,richText:Av,scale:rr,autoSize:pt},gE=Ko("text",{RemoveJustify:1,AddTextAlign:2,AddRichText:3}),gF={sequence:[{id:gE.RemoveJustify,up:n=>{n.align==="justify"&&(n.align="start")},down:"retired"},{id:gE.AddTextAlign,up:n=>{n.textAlign=n.align,delete n.align},down:n=>{n.align=n.textAlign,delete n.textAlign}},{id:gE.AddRichText,up:n=>{n.richText=ri(n.text),delete n.text}}]},mF={w:rr,h:rr,time:Qe,playing:pt,autoplay:pt,url:so,assetId:kv.nullable(),altText:dt},RS=Ko("video",{AddUrlProp:1,MakeUrlsValid:2,AddAltText:3,AddAutoplay:4}),yF={sequence:[{id:RS.AddUrlProp,up:n=>{n.url=""},down:"retired"},{id:RS.MakeUrlsValid,up:n=>{so.isValid(n.url)||(n.url="")},down:n=>{}},{id:RS.AddAltText,up:n=>{n.altText=""},down:n=>{delete n.altText}},{id:RS.AddAutoplay,up:n=>{n.autoplay=!0},down:n=>{delete n.autoplay}}]},og=Ds("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4,FixIndexKeys:5}),zee=bf({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:og.RemoveCodeAndIconShapeTypes,scope:"store",up:n=>{for(const[e,t]of Yi(n))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete n[e]}},{id:og.AddInstancePresenceType,scope:"store",up(n){}},{id:og.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:n=>{for(const[e,t]of Yi(n))t.typeName.match(/^(user|user_presence)$/)&&delete n[e]}},{id:og.RemoveUserDocument,scope:"store",up:n=>{for(const[e,t]of Yi(n))t.typeName.match("user_document")&&delete n[e]}},{id:og.FixIndexKeys,scope:"record",up:n=>{if(["shape","page"].includes(n.typeName)&&"index"in n){const e=n;if(e.index.endsWith("0")&&e.index!=="a0"&&(e.index=e.index.slice(0,-1)+d3(3)),n.typeName==="shape"&&e.type==="line"){const t=e;for(const[r,i]of Yi(t.props.points))i.index.endsWith("0")&&i.index!=="a0"&&(i.index=i.index.slice(0,-1)+d3(3))}}},down:()=>{}}]}),u3="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Bee=()=>u3.charAt(Math.floor(Math.random()*u3.length)),d3=n=>Array.from({length:n},Bee).join(""),Fee={arrow:{migrations:U4,props:F4},bookmark:{migrations:Y4,props:G4},draw:{migrations:Z4,props:X4},embed:{migrations:Q4,props:J4},frame:{migrations:tF,props:eF},geo:{migrations:rF,props:nF},group:{migrations:sF,props:iF},highlight:{migrations:aF,props:oF},image:{migrations:cF,props:lF},line:{migrations:dF,props:uF},note:{migrations:fF,props:hF},text:{migrations:gF,props:pF},video:{migrations:yF,props:mF}},Uee={arrow:{migrations:$4,props:H4}};function Hee({shapes:n=Fee,bindings:e=Uee,migrations:t}={}){const r=new Map;for(const a of Hn(n))for(const l of N4(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 i=$Q(n),s=FQ(e),o=lee(r);return YI.create({asset:Pu,binding:s,camera:za,document:r2,instance:o,instance_page_state:ca,page:Wi,instance_presence:yee,pointer:n2,shape:i},{migrations:[zee,Aee,JQ,bee,cee,dee,oee,mee,pee,HQ,Tee,_ee,Iee,...i3("shape",n),...i3("binding",e),...t??[]],onValidationFailure:xee,createIntegrityChecker:wee})}const dm=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ms",label:"Bahasa Melayu"},{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:"tl",label:"Filipino"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"nl",label:"Nederlands"},{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:"sl",label:"Slovenščina"},{locale:"so",label:"Somali"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"el",label:"Ελληνικά"},{locale:"ru",label:"Русский"},{locale:"uk",label:"Українська"},{locale:"he",label:"עברית"},{locale:"ur",label:"اردو"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ne",label:"नेपाली"},{locale:"mr",label:"मराठी"},{locale:"hi-in",label:"हिन्दी"},{locale:"bn",label:"বাংলা"},{locale:"pa",label:"ਪੰਜਾਬੀ"},{locale:"gu-in",label:"ગુજરાતી"},{locale:"ta",label:"தமிழ்"},{locale:"te",label:"తెలుగు"},{locale:"kn",label:"ಕನ್ನಡ"},{locale:"ml",label:"മലയാളം"},{locale:"th",label:"ภาษาไทย"},{locale:"km-kh",label:"ភាសាខ្មែរ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function $ee(){const n=typeof window<"u"&&window.navigator?window.navigator.languages??["en"]:["en"];return Kee(n)}function Kee(n){for(const e of n){const t=qee(e);if(t)return t}return"en"}const h3={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function qee(n){const e=dm.find(i=>i.locale===n.toLowerCase());if(e)return e.locale;const[t,r]=n.split(/[-_]/).map(i=>i.toLowerCase());if(r){const i=dm.find(s=>s.locale===t);if(i)return i.locale}return t in h3?h3[t]:null}xu("@tldraw/tlschema","4.1.2","esm");function Vee(){return m.jsx("div",{className:"tl-background"})}function Zm(n,e,t,r,i,s){E.useLayoutEffect(()=>{const o=n.current;if(!o||e===void 0)return;let a=`translate(${e}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),i!==void 0&&(a+=` rotate(${i}rad)`),s&&(a+=` translate(${s.x}px, ${s.y}px)`),o.style.transform=a})}const Ti={linear:n=>n,easeInQuad:n=>n*n,easeOutQuad:n=>n*(2-n),easeInOutQuad:n=>n<.5?2*n*n:-1+(4-2*n)*n,easeInCubic:n=>n*n*n,easeOutCubic:n=>--n*n*n+1,easeInOutCubic:n=>n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1,easeInQuart:n=>n*n*n*n,easeOutQuart:n=>1- --n*n*n*n,easeInOutQuart:n=>n<.5?8*n*n*n*n:1-8*--n*n*n*n,easeInQuint:n=>n*n*n*n*n,easeOutQuint:n=>1+--n*n*n*n*n,easeInOutQuint:n=>n<.5?16*n*n*n*n*n:1+16*--n*n*n*n*n,easeInSine:n=>1-Math.cos(n*Math.PI/2),easeOutSine:n=>Math.sin(n*Math.PI/2),easeInOutSine:n=>-(Math.cos(Math.PI*n)-1)/2,easeInExpo:n=>n<=0?0:Math.pow(2,10*n-10),easeOutExpo:n=>n>=1?1:1-Math.pow(2,-10*n),easeInOutExpo:n=>n<=0?0:n>=1?1:n<.5?Math.pow(2,20*n-10)/2:(2-Math.pow(2,-20*n+10))/2};class I{constructor(e=0,t=0,r=1){this.x=e,this.y=t,this.z=r}get pressure(){return this.z}set(e=this.x,t=this.y,r=this.z){return this.x=e,this.y=t,this.z=r,this}setTo({x:e=0,y:t=0,z:r=1}){return this.x=e,this.y=t,this.z=r,this}rot(e){if(e===0)return this;const{x:t,y:r}=this,i=Math.sin(e),s=Math.cos(e);return this.x=t*s-r*i,this.y=t*i+r*s,this}rotWith(e,t){if(t===0)return this;const r=this.x-e.x,i=this.y-e.y,s=Math.sin(t),o=Math.cos(t);return this.x=e.x+(r*o-i*s),this.y=e.y+(r*s+i*o),this}clone(){const{x:e,y:t,z:r}=this;return new I(e,t,r)}sub(e){return this.x-=e.x,this.y-=e.y,this}subXY(e,t){return this.x-=e,this.y-=t,this}subScalar(e){return this.x-=e,this.y-=e,this}add(e){return this.x+=e.x,this.y+=e.y,this}addXY(e,t){return this.x+=e,this.y+=t,this}addScalar(e){return this.x+=e,this.y+=e,this}clamp(e,t){return this.x=Math.max(this.x,e),this.y=Math.max(this.y,e),t!==void 0&&(this.x=Math.min(this.x,t),this.y=Math.min(this.y,t)),this}div(e){return this.x/=e,this.y/=e,this}divV(e){return this.x/=e.x,this.y/=e.y,this}mul(e){return this.x*=e,this.y*=e,this}mulV(e){return this.x*=e.x,this.y*=e.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(e,t){const r=I.Tan(e,this);return this.add(r.mul(t))}neg(){return this.x*=-1,this.y*=-1,this}cross(e){return this.x=this.y*e.z-this.z*e.y,this.y=this.z*e.x-this.x*e.z,this}dpr(e){return I.Dpr(this,e)}cpr(e){return I.Cpr(this,e)}len2(){return I.Len2(this)}len(){return I.Len(this)}pry(e){return I.Pry(this,e)}per(){const{x:e,y:t}=this;return this.x=t,this.y=-e,this}uni(){const e=this.len();return e===0?this:(this.x/=e,this.y/=e,this)}tan(e){return this.sub(e).uni()}dist(e){return I.Dist(this,e)}distanceToLineSegment(e,t){return I.DistanceToLineSegment(e,t,this)}slope(e){return I.Slope(this,e)}snapToGrid(e){return this.x=Math.round(this.x/e)*e,this.y=Math.round(this.y/e)*e,this}angle(e){return I.Angle(this,e)}toAngle(){return I.ToAngle(this)}lrp(e,t){return this.x=this.x+(e.x-this.x)*t,this.y=this.y+(e.y-this.y)*t,this}equals(e){return I.Equals(this,e)}equalsXY(e,t){return I.EqualsXY(this,e,t)}toFixed(){return this.x=oa(this.x),this.y=oa(this.y),this}toString(){return I.ToString(I.ToFixed(this))}toJson(){return I.ToJson(this)}toArray(){return I.ToArray(this)}static Add(e,t){return new I(e.x+t.x,e.y+t.y)}static AddXY(e,t,r){return new I(e.x+t,e.y+r)}static Sub(e,t){return new I(e.x-t.x,e.y-t.y)}static SubXY(e,t,r){return new I(e.x-t,e.y-r)}static AddScalar(e,t){return new I(e.x+t,e.y+t)}static SubScalar(e,t){return new I(e.x-t,e.y-t)}static Div(e,t){return new I(e.x/t,e.y/t)}static Mul(e,t){return new I(e.x*t,e.y*t)}static DivV(e,t){return new I(e.x/t.x,e.y/t.y)}static MulV(e,t){return new I(e.x*t.x,e.y*t.y)}static Neg(e){return new I(-e.x,-e.y)}static Per(e){return new I(e.y,-e.x)}static Abs(e){return new I(Math.abs(e.x),Math.abs(e.y))}static Dist(e,t){return((e.y-t.y)**2+(e.x-t.x)**2)**.5}static ManhattanDist(e,t){return Math.abs(e.x-t.x)+Math.abs(e.y-t.y)}static DistMin(e,t,r){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)<r**2}static Dist2(e,t){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)}static Dpr(e,t){return e.x*t.x+e.y*t.y}static Cross(e,t){return new I(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z)}static Cpr(e,t){return e.x*t.y-t.x*e.y}static Len2(e){return e.x*e.x+e.y*e.y}static Len(e){return(e.x*e.x+e.y*e.y)**.5}static Pry(e,t){return I.Dpr(e,t)/I.Len(t)}static Uni(e){const t=I.Len(e);return new I(t===0?0:e.x/t,t===0?0:e.y/t)}static Tan(e,t){return I.Uni(I.Sub(e,t))}static Min(e,t){return new I(Math.min(e.x,t.x),Math.min(e.y,t.y))}static Max(e,t){return new I(Math.max(e.x,t.x),Math.max(e.y,t.y))}static From({x:e,y:t,z:r=1}){return new I(e,t,r)}static FromArray(e){return new I(e[0],e[1])}static Rot(e,t=0){const r=Math.sin(t),i=Math.cos(t);return new I(e.x*i-e.y*r,e.x*r+e.y*i)}static RotWith(e,t,r){const i=e.x-t.x,s=e.y-t.y,o=Math.sin(r),a=Math.cos(r);return new I(t.x+(i*a-s*o),t.y+(i*o+s*a))}static NearestPointOnLineThroughPoint(e,t,r){return I.Mul(t,I.Sub(r,e).pry(t)).add(e)}static NearestPointOnLineSegment(e,t,r,i=!0){if(I.Equals(e,r)||I.Equals(t,r))return I.From(r);const s=I.Tan(t,e),o=I.Add(e,I.Mul(s,I.Sub(r,e).pry(s)));if(i){if(o.x<Math.min(e.x,t.x))return I.Cast(e.x<t.x?e:t);if(o.x>Math.max(e.x,t.x))return I.Cast(e.x>t.x?e:t);if(o.y<Math.min(e.y,t.y))return I.Cast(e.y<t.y?e:t);if(o.y>Math.max(e.y,t.y))return I.Cast(e.y>t.y?e:t)}return o}static DistanceToLineThroughPoint(e,t,r){return I.Dist(r,I.NearestPointOnLineThroughPoint(e,t,r))}static DistanceToLineSegment(e,t,r,i=!0){return I.Dist(r,I.NearestPointOnLineSegment(e,t,r,i))}static Snap(e,t=1){return new I(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}static Cast(e){return e instanceof I?e:I.From(e)}static Slope(e,t){return e.x===t.y?NaN:(e.y-t.y)/(e.x-t.x)}static IsNaN(e){return isNaN(e.x)||isNaN(e.y)}static Angle(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}static AngleBetween(e,t){const r=e.x*t.x+e.y*t.y,i=Math.sqrt((Math.pow(e.x,2)+Math.pow(e.y,2))*(Math.pow(t.x,2)+Math.pow(t.y,2)));return(e.x*t.y-e.y*t.x<0?-1:1)*Math.acos(st(r/i,-1,1))}static Lrp(e,t,r){return I.Sub(t,e).mul(r).add(e)}static Med(e,t){return new I((e.x+t.x)/2,(e.y+t.y)/2)}static Equals(e,t){return Math.abs(e.x-t.x)<1e-4&&Math.abs(e.y-t.y)<1e-4}static EqualsXY(e,t,r){return e.x===t&&e.y===r}static Clockwise(e,t,r){return(r.x-e.x)*(t.y-e.y)-(t.x-e.x)*(r.y-e.y)<0}static Rescale(e,t){const r=I.Len(e);return new I(t*e.x/r,t*e.y/r)}static ScaleWithOrigin(e,t,r){return I.Sub(e,r).mul(t).add(r)}static ToFixed(e){return new I(oa(e.x),oa(e.y))}static ToInt(e){return new I(parseInt(e.x.toFixed(0)),parseInt(e.y.toFixed(0)),parseInt((e.z??0).toFixed(0)))}static ToCss(e){return`${e.x},${e.y}`}static Nudge(e,t,r){return I.Add(e,I.Tan(t,e).mul(r))}static ToString(e){return`${e.x}, ${e.y}`}static ToAngle(e){let t=Math.atan2(e.y,e.x);return t<0&&(t+=Math.PI*2),t}static FromAngle(e,t=1){return new I(Math.cos(e)*t,Math.sin(e)*t)}static ToArray(e){return[e.x,e.y,e.z]}static ToJson(e){const{x:t,y:r,z:i}=e;return{x:t,y:r,z:i}}static Average(e){const t=e.length,r=new I(0,0);if(t===0)return r;for(let i=0;i<t;i++)r.add(e[i]);return r.div(t)}static Clamp(e,t,r){return r===void 0?new I(Math.min(Math.max(e.x,t)),Math.min(Math.max(e.y,t))):new I(Math.min(Math.max(e.x,t),r),Math.min(Math.max(e.y,t),r))}static PointsBetween(e,t,r=6){const i=[];for(let s=0;s<r;s++){const o=Ti.easeInQuad(s/(r-1)),a=I.Lrp(e,t,o);a.z=Math.min(1,.5+Math.abs(.5-Gee(o))*.65),i.push(a)}return i}static SnapToGrid(e,t=8){return new I(Math.round(e.x/t)*t,Math.round(e.y/t)*t)}}const Gee=n=>n<.5?2*n*n:-1+(4-2*n)*n;function Jr(n){return`${Z(n.x)},${Z(n.y)} `}function Es(n,e){return`${Z((n.x+e.x)/2)},${Z((n.y+e.y)/2)} `}const Ht=Math.PI,er=Ht/2,hn=Ht*2,Yee=Math.sin;function st(n,e,t){return Math.max(e,typeof t<"u"?Math.min(n,t):n)}function jS(n,e=1e10){return n?Math.round(n*e)/e:0}function ir(n,e,t=1e-6){return Math.abs(n-e)<=t}function eu(n,e,t=1e-6){return n<e||ir(n,e,t)}function Wee(n,e){const t=Math.pow(n-e,2)/Math.pow(n+e,2);return Ht*(n+e)*(1+3*t/(10+Math.sqrt(4-3*t)))}function ox(n){return n=n%hn,n<0?n=n+hn:n===0&&(n=0),n}function i2(n,e){return n=ox(n),e=ox(e),n>e&&(e+=hn),e-n}function Xee(n,e){return hn-i2(n,e)}function kb(n,e){const t=(e-n)%hn;return 2*t%hn-t}function V_(n){return(hn+n)%hn}function ax(n,e){const t=hn/e;let r=Math.floor((V_(n)+t/2)/t)*t%hn;return r<Ht&&(r+=hn),r>Ht&&(r-=hn),r}function SF(n,e){return n===e||ir(n%(Math.PI/2)-e%(Math.PI/2),0)}function Zee(n){return n*Ht/180}function Jee(n){return n*180/Ht}function s2(n,e,t){return new I(n.x,n.y).add(I.FromAngle(t,e))}function mE(n,e,t){const r=n/2,i=e/2,s=[];let o=1/0,a=-1/0,l=1/0,u=-1/0;for(let b=0;b<t;b++){const v=hn/t,w=-er+b*v,x=r+r*Math.cos(w),T=i+i*Math.sin(w);x<o&&(o=x),T<l&&(l=T),x>a&&(a=x),T>u&&(u=T),s.push(new I(x,T))}const f=a-o,h=u-l,g=n-f,y=e-h;if(g!==0||y!==0)for(let b=0;b<s.length;b++){const v=s[b];v.x=(v.x-o)/f*n,v.y=(v.y-l)/h*e}return s}function ag(n,e,t,r){return n<r&&t<e}function sa(n,e,t,r){const i=Math.max(n,t),s=Math.min(e,r);return i<=s?[i,s]:null}function f3(n,e,t){return(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y)}function Gi(n,e){let t=0,r,i;for(let s=0;s<e.length;s++){if(r=e[s],r.x===n.x&&r.y===n.y||(i=e[(s+1)%e.length],I.Dist(n,r)+I.Dist(n,i)===I.Dist(r,i)))return!0;r.y<=n.y?i.y>n.y&&f3(r,i,n)>0&&(t+=1):i.y<=n.y&&f3(r,i,n)<0&&(t-=1)}return t!==0}function Z(n){return Math.round(n*1e4)/1e4}function oa(n){return Math.round(n*100)/100}const p3=n=>Math.abs(n)<Number.MAX_SAFE_INTEGER;function g3(n,e,t,r){let i;if(Math.abs(n)>Ht){i=kb(e,r);const s=kb(r,t);return Math.abs(i)<Math.abs(s)?i/n:(n-s)/n}else{i=kb(e,r);const s=i/n;return Math.sign(i)!==Math.sign(n)?Math.abs(s)>.5?1:0:s}}function Qee(n,e,t,r){const i=2*((e-n)%hn)%hn-(e-n)%hn;return r?(hn-Math.abs(i))*(t?1:-1):i}function bF(n,e,t){const r=-2*(n.x*(e.y-t.y)-n.y*(e.x-t.x)+e.x*t.y-t.x*e.y),i=((n.x*n.x+n.y*n.y)*(t.y-e.y)+(e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y))/r,s=((n.x*n.x+n.y*n.y)*(e.x-t.x)+(e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x))/r;return!Number.isFinite(i)||!Number.isFinite(s)?null:new I(i,s)}const yE=({brush:n,color:e,opacity:t,className:r})=>{const i=E.useRef(null);Zm(i,n.x,n.y);const s=Z(Math.max(1,n.w)),o=Z(Math.max(1,n.h));return m.jsx("svg",{className:"tl-overlays__item",ref:i,"aria-hidden":"true",children:e?m.jsxs("g",{className:"tl-brush",opacity:t,children:[m.jsx("rect",{width:s,height:o,fill:e,opacity:.75}),m.jsx("rect",{width:s,height:o,fill:"none",stroke:e,opacity:.1})]}):m.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:o})})};var SE={exports:{}};var m3;function ete(){return m3||(m3=1,(function(n){(function(){var e={}.hasOwnProperty;function t(){for(var s="",o=0;o<arguments.length;o++){var a=arguments[o];a&&(s=i(s,r(a)))}return s}function r(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return t.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var o="";for(var a in s)e.call(s,a)&&s[a]&&(o=i(o,a));return o}function i(s,o){return o?s?s+" "+o:s+o:s}n.exports?(t.default=t,n.exports=t):window.classNames=t})()})(SE)),SE.exports}var tte=ete();const Fe=Ja(tte),Nt={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isDarwin:!1,hasCanvasSupport:!1};typeof window<"u"&&"navigator"in window&&(Nt.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Nt.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Nt.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Nt.isFirefox=/firefox/i.test(navigator.userAgent),Nt.isAndroid=/android/i.test(navigator.userAgent),Nt.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Nt.hasCanvasSupport=typeof window<"u"&&"Promise"in window&&"HTMLCanvasElement"in window);const y3={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.05,.1,.25,.5,1,2,4,8]},bE={duration:0,easing:Ti.easeInOutCubic},S3={CAMERA_MOVE:-10},nte=["top","right","bottom","left"],b3=0,o2=2,LS=1,x3=5,rte=128;var xE={};const ite={},xF=Si("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),In={logPreventDefaults:Si("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Si("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Si("logElementRemoves",{defaults:{all:!1}}),debugSvg:Si("debugSvg",{defaults:{all:!1}}),showFps:Si("showFps",{defaults:{all:!1}}),measurePerformance:Si("measurePerformance",{defaults:{all:!1}}),throwToBlob:Si("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Si("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Si("debugCursors",{defaults:{all:!1}}),forceSrgb:Si("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Si("debugGeometry",{defaults:{all:!1}}),hideShapes:Si("hideShapes",{defaults:{all:!1}}),editOnType:Si("editOnType",{defaults:{all:!1}}),a11y:Si("a11y",{defaults:{all:!1}}),debugElbowArrows:Si("debugElbowArrows",{defaults:{all:!1}})};if(typeof Element<"u"){const n=Element.prototype.removeChild;Ms("element removal logging",()=>{In.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),n.call(this,e)}:Element.prototype.removeChild=n})}function Si(n,{defaults:e,shouldStoreForSession:t=!0}){return ste({name:n,defaults:e,shouldStoreForSession:t})}function ste(n){const e=ate(n),t=n.shouldStoreForSession?ote(n.name):null,r=bn(`debug:${n.name}`,t??e);return typeof window<"u"&&(n.shouldStoreForSession&&Ms(`debug:${n.name}`,()=>{const i=r.get();i===e?NB(`tldraw_debug:${n.name}`):wI(`tldraw_debug:${n.name}`,JSON.stringify(i))}),Object.defineProperty(window,`tldraw${n.name.replace(/^[a-z]/,i=>i.toUpperCase())}`,{get(){return r.get()},set(i){r.set(i)},configurable:!0})),Object.assign(r,n,{reset:()=>r.set(e)})}function ote(n){try{return JSON.parse(LB(`tldraw_debug:${n}`)??"null")}catch{return null}}function vE(n){try{return n()}catch{return null}}function ate(n){switch(vE(()=>xE.TLDRAW_ENV)??vE(()=>xE.VERCEL_PUBLIC_TLDRAW_ENV)??vE(()=>xE.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return n.defaults.production??n.defaults.all;case"preview":case"staging":return n.defaults.staging??n.defaults.all;default:return n.defaults.development??n.defaults.all}}function lx(n){if(n.nodeType===Node.ELEMENT_NODE)return n;if(n.parentElement)return lx(n.parentElement);throw Error("Could not find a parent element of an HTML type!")}function nt(n){n.preventDefault(),In.logPreventDefaults.get()&&console.warn("preventDefault called on event:",n)}function Jm(n,e){if(n.setPointerCapture(e.pointerId),In.logPointerCaptures.get()){const t=xF.get();t.set(n,(t.get(n)??0)+1),console.warn("setPointerCapture called on element:",n,e)}}function Qm(n,e){if(n.hasPointerCapture(e.pointerId)&&(n.releasePointerCapture(e.pointerId),In.logPointerCaptures.get())){const t=xF.get();t.get(n)===1?t.delete(n):t.has(n)?t.set(n,t.get(n)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",n,e)}}const bi=(n,e,t)=>{n&&n.style.setProperty(e,t)};function vF(n=!1){const{activeElement:e}=document,t=n?["input","textarea"]:["input","select","button","textarea"];return!!(e&&(e.isContentEditable||t.indexOf(e.tagName.toLowerCase())>-1||e.classList.contains("tlui-slider__thumb")))}const xn=n=>Nt.isDarwin?n.metaKey:n.ctrlKey||n.metaKey;function Ei(n,e){return n.markEventAsHandled(e),{point:{x:e.clientX,y:e.clientY,z:e.pressure},shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,metaKey:e.metaKey,accelKey:xn(e),pointerId:e.pointerId,button:e.button,isPen:e.pointerType==="pen"}}function a2(n,e){return Ov(`${n}_${e}`)}function Vd(n){return Ov(`${E.useId()}${n??""}`)}function da(n){const e=Mr(E.useContext(wF));return Ov(`${e}_${n}`)}function Ov(n){return n.replace(/:/g,"_")}const wF=E.createContext(null);function lte({children:n}){const e=Vd();return m.jsx(wF.Provider,{value:e,children:n})}const l2=E.createContext(null);function te(){const n=Ge.useContext(l2);if(!n)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return n}function Vn(){return Ge.useContext(l2)}function c2({editor:n,children:e}){return m.jsx(l2.Provider,{value:n,children:m.jsx(lte,{children:e})})}function Dv(){const n=te(),e=ee("current tool",()=>n.getCurrentTool(),[n]),t=E.useMemo(function(){function i(y){if(!n.wasEventAlreadyHandled(y)){if(y.button===o2){n.dispatch({type:"pointer",target:"canvas",name:"right_click",...Ei(n,y)});return}y.button!==0&&y.button!==1&&y.button!==5||(Jm(y.currentTarget,y),n.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Ei(n,y)}))}}function s(y){n.wasEventAlreadyHandled(y)||y.button!==0&&y.button!==1&&y.button!==2&&y.button!==5||(Qm(y.currentTarget,y),n.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Ei(n,y)}))}function o(y){if(n.wasEventAlreadyHandled(y)||n.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const b=y.pointerType==="mouse"||y.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:b?!0:null})}function a(y){if(n.wasEventAlreadyHandled(y)||n.getInstanceState().isPenMode&&y.pointerType!=="pen")return;const b=y.pointerType==="mouse"||y.pointerType==="pen";n.updateInstanceState({isHoveringCanvas:b?!1:null})}function l(y){n.wasEventAlreadyHandled(y)||(n.markEventAsHandled(y),nt(y))}function u(y){if(n.wasEventAlreadyHandled(y)||(n.markEventAsHandled(y),!(y.target instanceof HTMLElement)))return;const b=n.getEditingShape()?.id;!(b&&y.target.closest(`[data-shape-id="${b}"]`))&&y.target.tagName!=="A"&&y.target.tagName!=="TEXTAREA"&&!y.target.isContentEditable&&nt(y)}function f(y){n.wasEventAlreadyHandled(y)||nt(y)}async function h(y){if(n.wasEventAlreadyHandled(y))return;if(nt(y),y.stopPropagation(),y.dataTransfer?.files?.length){const v=Array.from(y.dataTransfer.files);await n.putExternalContent({type:"files",files:v,point:n.screenToPage({x:y.clientX,y:y.clientY})});return}const b=y.dataTransfer.getData("url");if(b){await n.putExternalContent({type:"url",url:b,point:n.screenToPage({x:y.clientX,y:y.clientY})});return}}function g(y){n.wasEventAlreadyHandled(y)||y.stopPropagation()}return{onPointerDown:i,onPointerUp:s,onPointerEnter:o,onPointerLeave:a,onDragOver:f,onDrop:h,onTouchStart:l,onTouchEnd:u,onClick:g}},[n]);return E.useEffect(()=>{let r,i;function s(o){if(n.wasEventAlreadyHandled(o)||(n.markEventAsHandled(o),o.clientX===r&&o.clientY===i))return;r=o.clientX,i=o.clientY;const a=e.useCoalescedEvents&&o.getCoalescedEvents?o.getCoalescedEvents():[o];for(const l of a)n.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Ei(n,l)})}return document.body.addEventListener("pointermove",s),()=>{document.body.removeEventListener("pointermove",s)}},[n,e]),t}function cte(){const n=te();E.useEffect(()=>{let e=n.getInstanceState().isCoarsePointer;const t=o=>{const a=o.pointerType!=="mouse";e!==a&&(e=a,n.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",t,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),i=Nt.isFirefox&&!Nt.isAndroid&&!Nt.isIos,s=()=>{const o=i?!1:r.matches;e===o&&(e=o,n.updateInstanceState({isCoarsePointer:o}))};return r&&(r.addEventListener("change",s),s()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",s)}},[n])}const CF=E.createContext(null);function TF({container:n,children:e}){return m.jsx(CF.Provider,{value:n,children:e})}function or(){return Mr(E.useContext(CF),"useContainer used outside of <Tldraw />")}function ute(){const n=te(),e=or(),t=ee("isEditing",()=>n.getEditingShapeId(),[n]),r=ee("isFocused",()=>n.getIsFocused(),[n]);E.useEffect(()=>{if(!e)return;function i(s){if(s.isSpecialRedispatchedEvent)return;nt(s),s.stopPropagation();const o=e.querySelector(".tl-canvas");if(!o)return;const a=new DragEvent(s.type,s);a.isSpecialRedispatchedEvent=!0,o.dispatchEvent(a)}return e.addEventListener("dragover",i),e.addEventListener("drop",i),()=>{e.removeEventListener("dragover",i),e.removeEventListener("drop",i)}},[e]),E.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let i=null;const s=()=>{i?.();const o=`(resolution: ${window.devicePixelRatio}dppx)`,a=matchMedia(o),l=u=>{u.type==="change"&&s()};a.addEventListener?a.addEventListener("change",s):a.addListener&&a.addListener(l),i=()=>{a.removeEventListener?a.removeEventListener("change",s):a.removeListener&&a.removeListener(l)},n.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{i?.()}},[n]),E.useEffect(()=>{if(!r)return;const i=l=>{if(l.altKey&&(n.isIn("zoom")||!n.getPath().endsWith(".idle"))&&!lg(n)&&nt(l),n.wasEventAlreadyHandled(l))return;n.markEventAsHandled(l);const u=!!n.getSelectedShapeIds().length;switch(l.key){case"=":case"-":case"0":{if(l.metaKey||l.ctrlKey){nt(l);return}break}case"Tab":{if(lg(n))return;u&&!t&&nt(l);break}case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{if(lg(n))return;u&&(l.metaKey||l.ctrlKey)&&nt(l);break}case",":return;case"Escape":{if((n.getEditingShape()||n.getSelectedShapeIds().length>0)&&nt(l),n.menus.getOpenMenus().length>0)return;n.inputs.keys.has("Escape")||(n.inputs.keys.add("Escape"),n.cancel(),e.focus());return}default:if(lg(n))return}const f={type:"keyboard",name:l.repeat?"key_repeat":"key_down",key:l.key,code:l.code,shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:xn(l)};n.dispatch(f)},s=l=>{if(n.wasEventAlreadyHandled(l)||(n.markEventAsHandled(l),lg(n))||l.key===",")return;const u={type:"keyboard",name:"key_up",key:l.key,code:l.code,shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:xn(l)};n.dispatch(u)};function o(l){if(e.contains(l.target)){const u=l.touches[0].pageX,f=l.touches[0].radiusX||0;(u-f<10||u+f>n.getViewportScreenBounds().width-10)&&(l.target?.tagName==="BUTTON"&&l.target?.click(),nt(l))}}const a=l=>{e.contains(l.target)&&(l.ctrlKey||l.metaKey)&&nt(l)};return e.addEventListener("touchstart",o,{passive:!1}),e.addEventListener("wheel",a,{passive:!1}),document.addEventListener("gesturestart",nt),document.addEventListener("gesturechange",nt),document.addEventListener("gestureend",nt),e.addEventListener("keydown",i),e.addEventListener("keyup",s),()=>{e.removeEventListener("touchstart",o),e.removeEventListener("wheel",a),document.removeEventListener("gesturestart",nt),document.removeEventListener("gesturechange",nt),document.removeEventListener("gestureend",nt),e.removeEventListener("keydown",i),e.removeEventListener("keyup",s)}},[n,e,r,t])}function lg(n){return n.menus.hasOpenMenus()||vF()}function dte({className:n,zoom:e,point:t,color:r,viewport:i,opacity:s=1}){const o=E.useRef(null);Zm(o,st(t.x,i.minX+5/e,i.maxX-5/e),st(t.y,i.minY+5/e,i.maxY-5/e),1/e,I.Angle(i.center,t));const a=da("cursor_hint");return m.jsxs("svg",{ref:o,className:Fe("tl-overlays__item",n),"aria-hidden":"true",children:[m.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--tl-color-background)"}),m.jsx("use",{href:`#${a}`,color:r,opacity:s})]})}const v3=E.memo(function({className:e,zoom:t,point:r,color:i,name:s,chatMessage:o}){const a=E.useRef(null);Zm(a,r?.x,r?.y,1/t);const l=da("cursor");return r?m.jsxs("div",{ref:a,className:Fe("tl-overlays__item",e),children:[m.jsx("svg",{className:"tl-cursor","aria-hidden":"true",children:m.jsx("use",{href:`#${l}`,color:i})}),o?m.jsxs(m.Fragment,{children:[s&&m.jsx("div",{className:"tl-nametag-title",style:{color:i},children:s}),m.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:i},children:o})]}):s&&m.jsx("div",{className:"tl-nametag",style:{backgroundColor:i},children:s})]}):null}),ey={openWindow(n,e){window.open(n,e,"noopener noreferrer")},refreshPage(){window.location.reload()},async hardReset(){return await window.__tldraw__hardReset?.()}};function EF(){ey.hardReset()}function hte(){ey.refreshPage()}const fte={error:null};class u2 extends E.Component{static getDerivedStateFromError(e){return{error:e}}state=fte;componentDidCatch(e){this.props.onError?.(e)}render(){const{error:e}=this.state;if(e!==null){const{fallback:t}=this.props;return m.jsx(t,{error:e})}return this.props.children}}function hm({children:n,fallback:e,...t}){return e===null?n:m.jsx(u2,{fallback:e,...t,children:n})}const pte="https://github.com/tldraw/tldraw/issues/new",_F=({error:n,editor:e})=>{const t=E.useRef(null),[r,i]=E.useState(!1),[s,o]=E.useState(!1),[a,l]=E.useState(!1);let u=null;try{u=on().Canvas??null}catch{}const f=n instanceof Error?n.message:String(n),h=n instanceof Error?n.stack:null,g=ee("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[y,b]=E.useState(null);E.useLayoutEffect(()=>{g!==null&&b(g);let P=t.current?.parentElement,M=!1;for(;P;){if(P.classList.contains("tl-theme__dark")||P.classList.contains("tl-theme__light")){M=!0;break}P=P.parentElement}if(M){b(null);return}typeof window<"u"&&window.matchMedia&&b(window.matchMedia("(prefers-color-scheme: dark)").matches)},[g]),E.useEffect(()=>{if(s){const P=e?.timers.setTimeout(()=>{o(!1)},2e3);return()=>clearTimeout(P)}},[s,e]);const v=()=>{const P=document.createElement("textarea");P.value=h??f,document.body.appendChild(P),P.select(),document.execCommand("copy"),P.remove(),o(!0)},w=()=>{hte()},x=async()=>{EF()},T=new URL(pte);return T.searchParams.set("title",f),T.searchParams.set("labels","bug"),T.searchParams.set("body",`Hey, I ran into an error while using tldraw:
107
33
 
108
34
  \`\`\`js
109
35
  ${h??f}
@@ -112,11 +38,7 @@ ${h??f}
112
38
  My browser: ${navigator.userAgent}`),m.jsxs("div",{ref:t,className:Fe("tl-container tl-error-boundary",y===null?"":y?"tl-theme__dark":"tl-theme__light"),children:[m.jsx("div",{className:"tl-error-boundary__overlay"}),e&&m.jsx(u2,{onError:om,fallback:()=>null,children:m.jsx(c2,{editor:e,children:m.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:u?m.jsx(u,{}):null})})}),m.jsx("div",{className:Fe("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?m.jsxs(m.Fragment,{children:[m.jsx("h2",{children:"Are you sure?"}),m.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),m.jsxs("div",{className:"tl-error-boundary__content__actions",children:[m.jsx("button",{className:"tlui-button",onClick:()=>l(!1),children:"Cancel"}),m.jsx("button",{className:"tlui-button tl-error-boundary__reset",onClick:x,children:"Reset data"})]})]}):m.jsxs(m.Fragment,{children:[m.jsx("h2",{children:"Something went wrong"}),m.jsx("p",{children:"Please refresh your browser."}),m.jsx("p",{children:"If the issue continues after refreshing, you may need to reset the tldraw data stored on your device."}),m.jsxs("p",{children:[m.jsx("strong",{children:"Note:"})," Resetting will erase your current project and any unsaved work."]}),!1,r&&m.jsxs(m.Fragment,{children:["Message:",m.jsx("h4",{children:m.jsx("code",{children:f})}),"Stack trace:",m.jsxs("div",{className:"tl-error-boundary__content__error",children:[m.jsx("pre",{children:m.jsx("code",{children:h??f})}),m.jsx("button",{className:"tlui-button",onClick:v,children:s?"Copied!":"Copy"})]})]}),m.jsxs("div",{className:"tl-error-boundary__content__actions",children:[m.jsx("button",{className:"tlui-button",onClick:()=>i(!r),children:r?"Hide details":"Show details"}),m.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[m.jsx("button",{className:"tlui-button tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),m.jsx("button",{className:"tlui-button tl-error-boundary__refresh",onClick:w,children:"Refresh Page"})]})]})]})})]})};function gte({x:n,y:e,z:t,size:r}){const i=Vd("grid"),s=te(),{gridSteps:o}=s.options;return m.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[m.jsx("defs",{children:o.map(({min:a,mid:l,step:u},f)=>{const h=u*r*t,g=.5+n*t,y=.5+e*t,b=g>0?g%h:h+g%h,v=y>0?y%h:h+y%h,w=t<l?pa(t,[a,l],[0,1]):1;return m.jsx("pattern",{id:a2(i,`${u}`),width:h,height:h,patternUnits:"userSpaceOnUse",children:m.jsx("circle",{className:"tl-grid-dot",cx:b,cy:v,r:1,opacity:w})},f)})}),o.map(({step:a},l)=>m.jsx("rect",{width:"100%",height:"100%",fill:`url(#${i}_${a})`},l))]})}function mte({handle:n,isCoarse:e,className:t,zoom:r}){const i=te(),s=(e?i.options.coarseHandleRadius:i.options.handleRadius)/r;if(n.type==="clone"){const a=3/r,l=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,u=nte.indexOf(n.id);return m.jsxs("g",{className:Fe(`tl-handle tl-handle__${n.type}`,t),children:[m.jsx("circle",{className:"tl-handle__bg",r:s}),m.jsx("path",{className:"tl-handle__fg",d:l,transform:`rotate(${-90+90*u})`})]})}const o=(n.type==="create"&&e?3:4)/Math.max(r,.25);return m.jsxs("g",{className:Fe(`tl-handle tl-handle__${n.type}`,t),children:[m.jsx("circle",{className:"tl-handle__bg",r:s}),m.jsx("circle",{className:"tl-handle__fg",r:o})]})}const yte=({children:n})=>m.jsx("svg",{className:"tl-user-handles tl-overlays__item","aria-hidden":"true",children:n}),d2="4.1.2",w3={major:"2025-09-18T14:39:22.803Z",minor:"2025-10-15T12:23:29.168Z"};function PF(n,e){const t=E.useRef(n);return e(n,t.current)?t.current:(t.current=n,n)}const Ste=(n,e)=>(n??=null,e??=null,n===e?!0:!n||!e?!1:qb(n,e));function Xc(n){return PF(n,Ste)}const bte=(n,e)=>(n??=null,e??=null,n===e?!0:!n||!e?!1:MB(n,e));function Jf(n){return PF(n,bte)}const IF="TLDRAW_USER_DATA_v3",MF=Ct({id:dt,name:dt.nullable().optional(),color:dt.nullable().optional(),locale:dt.nullable().optional(),animationSpeed:Qe.nullable().optional(),areKeyboardShortcutsEnabled:pt.nullable().optional(),edgeScrollSpeed:Qe.nullable().optional(),colorScheme:Td("light","dark","system").optional(),isSnapMode:pt.nullable().optional(),isWrapMode:pt.nullable().optional(),isDynamicSizeMode:pt.nullable().optional(),isPasteAtCursorMode:pt.nullable().optional(),enhancedA11yMode:pt.nullable().optional(),inputMode:Td("trackpad","mouse").nullable().optional()}),Ys={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8,AddKeyboardShortcuts:9,AddShowUiLabels:10,AddPointerPeripheral:11,RenameShowUiLabelsToEnhancedA11yMode:12},h2=Math.max(...Object.values(Ys));function xte(n){n.version<Ys.AddAnimationSpeed&&(n.user.animationSpeed=1),n.version<Ys.AddIsSnapMode&&(n.user.isSnapMode=!1),n.version<Ys.MakeFieldsNullable,n.version<Ys.AddEdgeScrollSpeed&&(n.user.edgeScrollSpeed=1),n.version<Ys.AddExcalidrawSelectMode&&(n.user.isWrapMode=!1),n.version<Ys.AllowSystemColorScheme&&(n.user.isDarkMode===!0?n.user.colorScheme="dark":n.user.isDarkMode===!1&&(n.user.colorScheme="light"),delete n.user.isDarkMode),n.version<Ys.AddDynamicSizeMode&&(n.user.isDynamicSizeMode=!1),n.version<Ys.AddPasteAtCursor&&(n.user.isPasteAtCursorMode=!1),n.version<Ys.AddKeyboardShortcuts&&(n.user.areKeyboardShortcutsEnabled=!0),n.version<Ys.AddShowUiLabels&&(n.user.showUiLabels=!1),n.version<Ys.RenameShowUiLabelsToEnhancedA11yMode&&(n.user.enhancedA11yMode=n.user.showUiLabels,delete n.user.showUiLabels),n.version<Ys.AddPointerPeripheral&&(n.user.inputMode=null),n.version=h2}const G_=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function kF(){return G_[Math.floor(Math.random()*G_.length)]}function vte(){return typeof window<"u"&&window.matchMedia?window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches??!1:!1}const vs=Object.freeze({name:"",locale:$ee(),color:kF(),edgeScrollSpeed:1,animationSpeed:vte()?0:1,areKeyboardShortcutsEnabled:!0,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,enhancedA11yMode:!1,colorScheme:"light",inputMode:null});function wE(){return{id:zt(),color:kF()}}function AF(n){if(n===null||typeof n!="object"||!("version"in n)||!("user"in n)||typeof n.version!="number")return wE();const e=Qn(n);xte(e);try{return MF.validate(e.user)}catch{return wE()}}function wte(){const n=JSON.parse(xI(IF)||"null")??null;return AF(n)}const Rv=bn("globalUserData",null);function Cte(){vI(IF,JSON.stringify({version:h2,user:Rv.get()}))}function OF(n){MF.validate(n),Rv.set(n),Cte(),Tte()}const DF=typeof BroadcastChannel<"u"?new BroadcastChannel("tldraw-user-sync"):null;DF?.addEventListener("message",n=>{const e=n.data;e?.type===jF&&e?.origin!==RF()&&Rv.set(AF(e.data))});let CE=null;function RF(){return CE===null&&(CE=zt()),CE}const jF="tldraw-user-preferences-change";function Tte(){DF?.postMessage({type:jF,origin:RF(),data:{user:LF(),version:h2}})}function LF(){let n=Rv.get();return n||(n=wte(),OF(n)),n}const Ete=pe("defaultLocalStorageUserPrefs",()=>LF());function NF(n={}){return{userPreferences:n.userPreferences??Ete,setUserPreferences:n.setUserPreferences??OF}}var TE={exports:{}},C3;function _te(){return C3||(C3=1,(function(n){var e=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function i(l,u,f){this.fn=l,this.context=u,this.once=f||!1}function s(l,u,f,h,g){if(typeof f!="function")throw new TypeError("The listener must be a function");var y=new i(f,h||l,g),b=t?t+u:u;return l._events[b]?l._events[b].fn?l._events[b]=[l._events[b],y]:l._events[b].push(y):(l._events[b]=y,l._eventsCount++),l}function o(l,u){--l._eventsCount===0?l._events=new r:delete l._events[u]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var u=[],f,h;if(this._eventsCount===0)return u;for(h in f=this._events)e.call(f,h)&&u.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(f)):u},a.prototype.listeners=function(u){var f=t?t+u:u,h=this._events[f];if(!h)return[];if(h.fn)return[h.fn];for(var g=0,y=h.length,b=new Array(y);g<y;g++)b[g]=h[g].fn;return b},a.prototype.listenerCount=function(u){var f=t?t+u:u,h=this._events[f];return h?h.fn?1:h.length:0},a.prototype.emit=function(u,f,h,g,y,b){var v=t?t+u:u;if(!this._events[v])return!1;var w=this._events[v],x=arguments.length,T,P;if(w.fn){switch(w.once&&this.removeListener(u,w.fn,void 0,!0),x){case 1:return w.fn.call(w.context),!0;case 2:return w.fn.call(w.context,f),!0;case 3:return w.fn.call(w.context,f,h),!0;case 4:return w.fn.call(w.context,f,h,g),!0;case 5:return w.fn.call(w.context,f,h,g,y),!0;case 6:return w.fn.call(w.context,f,h,g,y,b),!0}for(P=1,T=new Array(x-1);P<x;P++)T[P-1]=arguments[P];w.fn.apply(w.context,T)}else{var M=w.length,k;for(P=0;P<M;P++)switch(w[P].once&&this.removeListener(u,w[P].fn,void 0,!0),x){case 1:w[P].fn.call(w[P].context);break;case 2:w[P].fn.call(w[P].context,f);break;case 3:w[P].fn.call(w[P].context,f,h);break;case 4:w[P].fn.call(w[P].context,f,h,g);break;default:if(!T)for(k=1,T=new Array(x-1);k<x;k++)T[k-1]=arguments[k];w[P].fn.apply(w[P].context,T)}}return!0},a.prototype.on=function(u,f,h){return s(this,u,f,h,!1)},a.prototype.once=function(u,f,h){return s(this,u,f,h,!0)},a.prototype.removeListener=function(u,f,h,g){var y=t?t+u:u;if(!this._events[y])return this;if(!f)return o(this,y),this;var b=this._events[y];if(b.fn)b.fn===f&&(!g||b.once)&&(!h||b.context===h)&&o(this,y);else{for(var v=0,w=[],x=b.length;v<x;v++)(b[v].fn!==f||g&&!b[v].once||h&&b[v].context!==h)&&w.push(b[v]);w.length?this._events[y]=w.length===1?w[0]:w:o(this,y)}return this},a.prototype.removeAllListeners=function(u){var f;return u?(f=t?t+u:u,this._events[f]&&o(this,f)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,n.exports=a})(TE)),TE.exports}var Pte=_te();const Ite=Ja(Pte),xf="TLDRAW_TAB_ID_v2",Md=globalThis.window;function Mte(){return Md?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(Md.navigator.platform)||Nt.isDarwin&&"ontouchend"in document:!1}const cx=Md?Md[xf]??LB(xf)??"TLDRAW_INSTANCE_STATE_V1_"+zt():"<error>";Md&&(Md[xf]=cx,Mte()?wI(xf,cx):NB(xf));Md?.addEventListener("beforeunload",()=>{wI(xf,cx)});const zF={Initial:0},jv=Math.max(...Object.values(zF));function kte(n){n.version<zF.Initial,n.version=jv}const BF=Ct({version:Qe,currentPageId:um.optional(),isFocusMode:pt.optional(),exportBackground:pt.optional(),isDebugMode:pt.optional(),isToolLocked:pt.optional(),isGridMode:pt.optional(),pageStates:Dr(Ct({pageId:um,camera:Ct({x:Qe,y:Qe,z:Qe}).optional(),selectedShapeIds:Dr(Ao).optional(),focusedGroupId:Ao.nullable().optional()})).optional()});function Ate(n){if(!n||typeof n!="object")return console.warn("Invalid instance state"),null;if(!("version"in n)||typeof n.version!="number")return console.warn("No version in instance state"),null;n.version!==jv&&(n=Qn(n),kte(n));try{return BF.validate(n)}catch(e){return console.warn(e),null}}function f2(n){const e=n.query.ids("page");return pe("sessionStateSnapshot",()=>{const t=n.get(Ki);if(!t)return null;const r=[...e.get()];return{version:jv,currentPageId:t.currentPageId,exportBackground:t.exportBackground,isFocusMode:t.isFocusMode,isDebugMode:t.isDebugMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,pageStates:r.map(i=>{const s=n.get(ca.createId(i)),o=n.get(za.createId(i));return{pageId:i,camera:{x:o?.x??0,y:o?.y??0,z:o?.z??1},selectedShapeIds:s?.selectedShapeIds??[],focusedGroupId:s?.focusedGroupId??null}})}},{isEqual:vu})}function Y_(n,e,t){const r=Ate(e);if(!r)return;const i=V4(n.get(Ki)),s=t?.forceOverwrite?r:i,o=t?.forceOverwrite?i:r,a=n.schema.types.instance.create({id:Ki,...i,currentPageId:r.currentPageId,isDebugMode:s?.isDebugMode??o?.isDebugMode,isFocusMode:s?.isFocusMode??o?.isFocusMode,isToolLocked:s?.isToolLocked??o?.isToolLocked,isGridMode:s?.isGridMode??o?.isGridMode,exportBackground:s?.exportBackground??o?.exportBackground});n.atomic(()=>{for(const l of r.pageStates??[]){if(!n.has(l.pageId))continue;const u=za.createId(l.pageId),f=ca.createId(l.pageId),h=n.get(u),g=n.get(f);n.put([za.create({id:u,x:l.camera?.x??h?.x,y:l.camera?.y??h?.y,z:l.camera?.z??h?.z}),ca.create({id:f,pageId:l.pageId,selectedShapeIds:l.selectedShapeIds??g?.selectedShapeIds,focusedGroupId:l.focusedGroupId??g?.focusedGroupId})])}n.put([a]),n.ensureStoreIsUsable()})}function Ote(n){const e=[];for(const i of Object.values(n))i.typeName?.match(/^(instance.*|pointer|camera)$/)&&e.push(i);const t=e.filter(i=>i.typeName==="instance"&&i.id!==Ki)[0];if(!t)return null;const r={version:jv,currentPageId:t.currentPageId,exportBackground:!!t.exportBackground,isFocusMode:!!t.isFocusMode,isDebugMode:!!t.isDebugMode,isToolLocked:!!t.isToolLocked,isGridMode:!1,pageStates:e.filter(i=>i.typeName==="instance_page_state"&&i.instanceId===t.id).map(i=>{const s=n[i.cameraId]??{x:0,y:0,z:1};return{pageId:i.pageId,camera:{x:s.x,y:s.y,z:s.z},selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId}})};try{return BF.validate(r),r}catch{return null}}function FF(n,e,t){let r={};if("store"in e){const o=n.schema.migrateStoreSnapshot(e);if(o.type!=="success")throw new Error("Failed to migrate store snapshot: "+o.reason);r.document={schema:n.schema.serialize(),store:Hg(o.value,(a,{typeName:l})=>n.scopedTypes.document.has(l))}}else r=e;const i=V4(n.get(Ki)),s=UF.get(n,f2).get();n.atomic(()=>{r.document&&n.loadStoreSnapshot(r.document),i&&n.update(Ki,o=>({...o,...i})),s&&Y_(n,s),r.session&&Y_(n,r.session,{forceOverwrite:t?.forceOverwriteSessionState})})}const UF=new Ii;function Dte(n){const t=UF.get(n,f2).get();if(!t)throw new Error("Session state is not ready yet");return{document:n.getStoreSnapshot(),session:t}}function HF(n){const e=[],t=new Set;for(const r of n){if(t.has(r.type))throw new Error(`Binding type "${r.type}" is defined more than once`);e.push(r),t.add(r.type)}return e}function hu({children:n,className:e="",...t}){return m.jsx("svg",{...t,className:Fe("tl-svg-container",e),"aria-hidden":"true",children:n})}class we{constructor(e=0,t=0,r=0,i=0){this.x=e,this.y=t,this.w=r,this.h=i}x=0;y=0;w=0;h=0;get point(){return new I(this.x,this.y)}set point(e){this.x=e.x,this.y=e.y}get minX(){return this.x}set minX(e){this.x=e}get left(){return this.x}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get right(){return this.x+this.w}get minY(){return this.y}set minY(e){this.y=e}get top(){return this.y}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get bottom(){return this.y+this.h}get width(){return this.w}set width(e){this.w=e}get height(){return this.h}set height(e){this.h=e}get aspectRatio(){return this.width/this.height}get center(){return new I(this.x+this.w/2,this.y+this.h/2)}set center(e){this.x=e.x-this.w/2,this.y=e.y-this.h/2}get corners(){return[new I(this.x,this.y),new I(this.x+this.w,this.y),new I(this.x+this.w,this.y+this.h),new I(this.x,this.y+this.h)]}get cornersAndCenter(){return[new I(this.x,this.y),new I(this.x+this.w,this.y),new I(this.x+this.w,this.y+this.h),new I(this.x,this.y+this.h),new I(this.x+this.w/2,this.y+this.h/2)]}get sides(){const{corners:e}=this;return[[e[0],e[1]],[e[1],e[2]],[e[2],e[3]],[e[3],e[0]]]}get size(){return new I(this.w,this.h)}toFixed(){return this.x=jS(this.x),this.y=jS(this.y),this.w=jS(this.w),this.h=jS(this.h),this}setTo(e){return this.x=e.x,this.y=e.y,this.w=e.w,this.h=e.h,this}set(e=0,t=0,r=0,i=0){return this.x=e,this.y=t,this.w=r,this.h=i,this}expand(e){const t=Math.min(this.x,e.x),r=Math.min(this.y,e.y),i=Math.max(this.x+this.w,e.x+e.w),s=Math.max(this.y+this.h,e.y+e.h);return this.x=t,this.y=r,this.w=i-t,this.h=s-r,this}expandBy(e){return this.x-=e,this.y-=e,this.w+=e*2,this.h+=e*2,this}scale(e){return this.x/=e,this.y/=e,this.w/=e,this.h/=e,this}clone(){const{x:e,y:t,w:r,h:i}=this;return new we(e,t,r,i)}translate(e){return this.x+=e.x,this.y+=e.y,this}snapToGrid(e){const t=Math.round(this.x/e)*e,r=Math.round(this.y/e)*e,i=Math.round((this.x+this.w)/e)*e,s=Math.round((this.y+this.h)/e)*e;this.minX=t,this.minY=r,this.width=Math.max(1,i-t),this.height=Math.max(1,s-r)}collides(e){return we.Collides(this,e)}contains(e){return we.Contains(this,e)}includes(e){return we.Includes(this,e)}containsPoint(e,t=0){return we.ContainsPoint(this,e,t)}getHandlePoint(e){switch(e){case"top_left":return new I(this.x,this.y);case"top_right":return new I(this.x+this.w,this.y);case"bottom_left":return new I(this.x,this.y+this.h);case"bottom_right":return new I(this.x+this.w,this.y+this.h);case"top":return new I(this.x+this.w/2,this.y);case"right":return new I(this.x+this.w,this.y+this.h/2);case"bottom":return new I(this.x+this.w/2,this.y+this.h);case"left":return new I(this.x,this.y+this.h/2)}}toJson(){return{x:this.x,y:this.y,w:this.w,h:this.h}}resize(e,t,r){const{minX:i,minY:s,maxX:o,maxY:a}=this;let{minX:l,minY:u,maxX:f,maxY:h}=this;switch(e){case"left":case"top_left":case"bottom_left":{l+=t;break}case"right":case"top_right":case"bottom_right":{f+=t;break}}switch(e){case"top":case"top_left":case"top_right":{u+=r;break}case"bottom":case"bottom_left":case"bottom_right":{h+=r;break}}const g=(f-l)/(o-i),y=(h-u)/(a-s),b=g<0,v=y<0;if(b){const w=f;f=l,l=w}if(v){const w=h;h=u,u=w}this.minX=l,this.minY=u,this.width=Math.abs(f-l),this.height=Math.abs(h-u)}union(e){const t=Math.min(this.x,e.x),r=Math.min(this.y,e.y),i=Math.max(this.x+this.w,e.x+e.w),s=Math.max(this.y+this.h,e.y+e.h);return this.x=t,this.y=r,this.width=i-t,this.height=s-r,this}static From(e){return new we(e.x,e.y,e.w,e.h)}static FromCenter(e,t){return new we(e.x-t.x/2,e.y-t.y/2,t.x,t.y)}static FromPoints(e){if(e.length===0)return new we;let t=1/0,r=1/0,i=-1/0,s=-1/0,o;for(let a=0,l=e.length;a<l;a++)o=e[a],t=Math.min(o.x,t),r=Math.min(o.y,r),i=Math.max(o.x,i),s=Math.max(o.y,s);return new we(t,r,i-t,s-r)}static Expand(e,t){const r=Math.min(t.minX,e.minX),i=Math.min(t.minY,e.minY),s=Math.max(t.maxX,e.maxX),o=Math.max(t.maxY,e.maxY);return new we(r,i,s-r,o-i)}static ExpandBy(e,t){return new we(e.minX-t,e.minY-t,e.width+t*2,e.height+t*2)}static Collides(e,t){return!(e.maxX<t.minX||e.minX>t.maxX||e.maxY<t.minY||e.minY>t.maxY)}static Contains(e,t){return e.minX<t.minX&&e.minY<t.minY&&e.maxY>t.maxY&&e.maxX>t.maxX}static ContainsApproximately(e,t,r){return eu(e.minX,t.minX,r)&&eu(e.minY,t.minY,r)&&eu(t.maxX,e.maxX,r)&&eu(t.maxY,e.maxY,r)}static Includes(e,t){return we.Collides(e,t)||we.Contains(e,t)}static ContainsPoint(e,t,r=0){return!(t.x<e.minX-r||t.y<e.minY-r||t.x>e.maxX+r||t.y>e.maxY+r)}static Common(e){let t=1/0,r=1/0,i=-1/0,s=-1/0;for(let o=0;o<e.length;o++){const a=e[o];t=Math.min(t,a.minX),r=Math.min(r,a.minY),i=Math.max(i,a.maxX),s=Math.max(s,a.maxY)}return new we(t,r,i-t,s-r)}static Sides(e,t=0){const{corners:r}=e;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]}static Resize(e,t,r,i,s=!1){const{minX:o,minY:a,maxX:l,maxY:u}=e;let{minX:f,minY:h,maxX:g,maxY:y}=e;switch(t){case"left":case"top_left":case"bottom_left":{f+=r;break}case"right":case"top_right":case"bottom_right":{g+=r;break}}switch(t){case"top":case"top_left":case"top_right":{h+=i;break}case"bottom":case"bottom_left":case"bottom_right":{y+=i;break}}const b=(g-f)/(l-o),v=(y-h)/(u-a),w=b<0,x=v<0;if(s){const P=(l-o)/(u-a),M=Math.abs(g-f),k=Math.abs(y-h),A=M*(v<0?1:-1)*(1/P),O=k*(b<0?1:-1)*P,R=P<M/k;switch(t){case"top_left":{R?h=y+A:f=g+O;break}case"top_right":{R?h=y+A:g=f-O;break}case"bottom_right":{R?y=h-A:g=f-O;break}case"bottom_left":{R?y=h-A:f=g+O;break}case"bottom":case"top":{const F=(f+g)/2,z=k*P;f=F-z/2,g=F+z/2;break}case"left":case"right":{const F=(h+y)/2,z=M/P;h=F-z/2,y=F+z/2;break}}}if(w){const P=g;g=f,f=P}if(x){const P=y;y=h,h=P}const T=new we(f,h,Math.abs(g-f),Math.abs(y-h));return{box:T,scaleX:+(T.width/e.width*(b>0?1:-1)).toFixed(5),scaleY:+(T.height/e.height*(v>0?1:-1)).toFixed(5)}}equals(e){return we.Equals(this,e)}static Equals(e,t){return t.x===e.x&&t.y===e.y&&t.w===e.w&&t.h===e.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(e){return new we(e.x,e.y,Math.max(1,e.w),Math.max(1,e.h))}}function Rte(n){switch(n){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 n}}function jte(n){switch(n){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 n}}function Lte(n){return n==="top_left"||n==="top_right"||n==="bottom_right"||n==="bottom_left"}class xe{constructor(e,t,r,i,s,o){this.a=e,this.b=t,this.c=r,this.d=i,this.e=s,this.f=o}a=1;b=0;c=0;d=1;e=0;f=0;equals(e){return this===e||this.a===e.a&&this.b===e.b&&this.c===e.c&&this.d===e.d&&this.e===e.e&&this.f===e.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(e){const t=e,{a:r,b:i,c:s,d:o,e:a,f:l}=this;return this.a=r*t.a+s*t.b,this.c=r*t.c+s*t.d,this.e=r*t.e+s*t.f+a,this.b=i*t.a+o*t.b,this.d=i*t.c+o*t.d,this.f=i*t.e+o*t.f+l,this}rotate(e,t,r){return e===0?this:t===void 0?this.multiply(xe.Rotate(e)):this.translate(t,r).multiply(xe.Rotate(e)).translate(-t,-r)}translate(e,t){return this.multiply(xe.Translate(e,t))}scale(e,t){return this.multiply(xe.Scale(e,t))}invert(){const{a:e,b:t,c:r,d:i,e:s,f:o}=this,a=e*i-t*r;return this.a=i/a,this.b=t/-a,this.c=r/-a,this.d=e/a,this.e=(i*s-r*o)/-a,this.f=(t*s-e*o)/a,this}applyToPoint(e){return xe.applyToPoint(this,e)}applyToPoints(e){return xe.applyToPoints(this,e)}rotation(){return xe.Rotation(this)}point(){return xe.Point(this)}decomposed(){return xe.Decompose(this)}toCssString(){return xe.toCssString(this)}setTo(e){return Object.assign(this,e),this}decompose(){return xe.Decompose(this)}clone(){return new xe(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new xe(1,0,0,1,0,0)}static Translate(e,t){return new xe(1,0,0,1,e,t)}static Rotate(e,t,r){if(e===0)return xe.Identity();const i=Math.cos(e),s=Math.sin(e),o=new xe(i,s,-s,i,0,0);return t===void 0?o:xe.Compose(xe.Translate(t,r),o,xe.Translate(-t,-r))}static Scale(e,t,r,i){const s=new xe(e,0,0,t,0,0);return r===void 0?s:xe.Translate(r,i).multiply(s).translate(-r,-i)}static Multiply(e,t){return{a:e.a*t.a+e.c*t.b,c:e.a*t.c+e.c*t.d,e:e.a*t.e+e.c*t.f+e.e,b:e.b*t.a+e.d*t.b,d:e.b*t.c+e.d*t.d,f:e.b*t.e+e.d*t.f+e.f}}static Inverse(e){const t=e.a*e.d-e.b*e.c;return{a:e.d/t,b:e.b/-t,c:e.c/-t,d:e.a/t,e:(e.d*e.e-e.c*e.f)/-t,f:(e.b*e.e-e.a*e.f)/t}}static Absolute(e){const t=e.a*e.d-e.b*e.c;return{a:e.d/t,b:e.b/-t,c:e.c/-t,d:e.a/t,e:(e.d*e.e-e.c*e.f)/t,f:(e.b*e.e-e.a*e.f)/-t}}static Compose(...e){const t=xe.Identity();for(let r=0,i=e.length;r<i;r++)t.multiply(e[r]);return t}static Point(e){return new I(e.e,e.f)}static Rotation(e){let t;if(e.a!==0||e.c!==0){const r=(e.a*e.a+e.c*e.c)**.5;t=Math.acos(e.a/r)*(e.c>0?-1:1)}else if(e.b!==0||e.d!==0){const r=(e.b*e.b+e.d*e.d)**.5;t=er+Math.acos(e.b/r)*(e.d>0?-1:1)}else t=0;return V_(t)}static Decompose(e){let t,r,i;if(e.a!==0||e.c!==0){const s=(e.a*e.a+e.c*e.c)**.5;t=s,r=(e.a*e.d-e.b*e.c)/s,i=Math.acos(e.a/s)*(e.c>0?-1:1)}else if(e.b!==0||e.d!==0){const s=(e.b*e.b+e.d*e.d)**.5;t=(e.a*e.d-e.b*e.c)/s,r=s,i=er+Math.acos(e.b/s)*(e.d>0?-1:1)}else t=0,r=0,i=0;return{x:e.e,y:e.f,scaleX:t,scaleY:r,rotation:V_(i)}}static Smooth(e,t=1e10){return e.a=Math.round(e.a*t)/t,e.b=Math.round(e.b*t)/t,e.c=Math.round(e.c*t)/t,e.d=Math.round(e.d*t)/t,e.e=Math.round(e.e*t)/t,e.f=Math.round(e.f*t)/t,e}static toCssString(e){return`matrix(${Z(e.a)}, ${Z(e.b)}, ${Z(e.c)}, ${Z(e.d)}, ${Z(e.e)}, ${Z(e.f)})`}static applyToPoint(e,t){return new I(e.a*t.x+e.c*t.y+e.e,e.b*t.x+e.d*t.y+e.f,t.z)}static applyToXY(e,t,r){return[e.a*t+e.c*r+e.e,e.b*t+e.d*r+e.f]}static applyToPoints(e,t){return t.map(r=>new I(e.a*r.x+e.c*r.y+e.e,e.b*r.x+e.d*r.y+e.f,r.z))}static applyToBounds(e,t){return new we(e.e+t.minX,e.f+t.minY,t.width,t.height)}static From(e){return new xe(e.a,e.b,e.c,e.d,e.e,e.f)}static Cast(e){return e instanceof xe?e:xe.From(e)}}function Lv(n,e,t,r,i=1e-10){const s=n.x-t.x,o=n.y-t.y,a=r.x-t.x,l=r.y-t.y,u=e.x-n.x,f=e.y-n.y,h=a*o-l*s,g=u*o-f*s,y=l*u-a*f;if(ir(h,0,i)||ir(g,0,i)||ir(y,0,i))return null;if(y!==0){const b=h/y,v=g/y;if(eu(0,b,i)&&eu(b,1,i)&&eu(0,v,i)&&eu(v,1,i))return I.AddXY(n,b*u,b*f)}return null}function ty(n,e,t,r){const i=(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y),s=2*((e.x-n.x)*(n.x-t.x)+(e.y-n.y)*(n.y-t.y)),o=t.x*t.x+t.y*t.y+n.x*n.x+n.y*n.y-2*(t.x*n.x+t.y*n.y)-r*r,a=s*s-4*i*o;if(a<0||a===0)return null;const l=Math.sqrt(a),u=(-s+l)/(2*i),f=(-s-l)/(2*i);if((u<0||u>1)&&(f<0||f>1))return null;const h=[];return 0<=u&&u<=1&&h.push(I.Lrp(n,e,u)),0<=f&&f<=1&&h.push(I.Lrp(n,e,f)),h.length===0?null:h}function Nte(n,e,t){const r=[];let i;for(let s=0,o=t.length-1;s<o;s++)i=Lv(n,e,t[s],t[s+1]),i&&r.push(i);return r.length===0?null:r}function $F(n,e,t){const r=[];let i;for(let s=1,o=t.length;s<o+1;s++)i=Lv(n,e,t[s-1],t[s%t.length]),i&&r.push(i);return r.length===0?null:r}function zte(n,e,t,r){let i=t.x-n.x,s=t.y-n.y;const o=Math.sqrt(i*i+s*s),a=(o*o-r*r+e*e)/(2*o),l=Math.sqrt(e*e-a*a);return i/=o,s/=o,[new I(n.x+i*a-s*l,n.y+s*a+i*l),new I(n.x+i*a+s*l,n.y+s*a-i*l)]}function Bte(n,e,t){const r=[];let i,s,o;for(let a=0,l=t.length;a<l;a++)i=t[a],s=t[(a+1)%t.length],o=ty(i,s,n,e),o&&r.push(...o);return r.length===0?null:r}function Fte(n,e,t){const r=[];let i,s,o;for(let a=1,l=t.length;a<l;a++)i=t[a-1],s=t[a],o=ty(i,s,n,e),o&&r.push(...o);return r.length===0?null:r}function NS(n,e,t){return(t.y-n.y)*(e.x-n.x)>(e.y-n.y)*(t.x-n.x)}function p2(n,e,t,r){return NS(n,t,r)!==NS(e,t,r)&&NS(n,e,t)!==NS(n,e,r)}function ux(n,e){const t=new Map;let r,i,s,o;for(let a=0,l=n.length;a<l;a++)if(r=n[a],Gi(r,e)){const u=Ab(r);t.has(u)||t.set(u,r)}for(let a=0,l=e.length;a<l;a++)if(r=e[a],Gi(r,n)){const u=Ab(r);t.has(u)||t.set(u,r)}for(let a=0,l=n.length;a<l;a++){r=n[a],i=n[(a+1)%n.length];for(let u=0,f=e.length;u<f;u++){s=e[u],o=e[(u+1)%e.length];const h=Lv(r,i,s,o);if(h!==null){const g=Ab(h);t.has(g)||t.set(g,h)}}}return t.size===0?null:Ute([...t.values()])}function T3(n,e,t,r){const i=new Map;for(let s=0,o=t?n.length:n.length-1;s<o;s++){const a=n[s],l=n[(s+1)%n.length];for(let u=0,f=r?e.length:e.length-1;u<f;u++){const h=e[u],g=e[(u+1)%e.length],y=Lv(a,l,h,g);if(y!==null){const b=Ab(y);i.has(b)||i.set(b,y)}}}return[...i.values()]}function Ab(n){return`${n.x},${n.y}`}function Ute(n){const e=I.Average(n);return n.sort((t,r)=>I.Angle(e,t)-I.Angle(e,r))}function KF(n,e){let t,r,i,s;for(let o=0,a=n.length;o<a;o++){t=n[o],r=n[(o+1)%a];for(let l=0,u=e.length;l<u;l++)if(i=e[l],s=e[(l+1)%u],p2(t,r,i,s))return!0}return!1}function Hte(n,e){let t,r,i,s;for(let o=0,a=n.length;o<a;o++){t=n[o],r=n[(o+1)%a];for(let l=1,u=e.length;l<u;l++)if(i=e[l-1],s=e[l],p2(t,r,i,s))return!0}return!1}const Ha={EXCLUDE_NON_STANDARD:{includeLabels:!1,includeInternal:!1},EXCLUDE_LABELS:{includeLabels:!1,includeInternal:!0}};class Iu{isFilled=!1;isClosed=!0;isLabel=!1;isEmptyLabel=!1;isInternal=!1;excludeFromShapeBounds=!1;debugColor;ignore;constructor(e){const{isLabel:t=!1,isEmptyLabel:r=!1,isInternal:i=!1,excludeFromShapeBounds:s=!1}=e;this.isFilled=e.isFilled,this.isClosed=e.isClosed,this.debugColor=e.debugColor,this.ignore=e.ignore,this.isLabel=t,this.isEmptyLabel=r,this.isInternal=i,this.excludeFromShapeBounds=s}isExcludedByFilter(e){return e?!!(this.isLabel&&!e.includeLabels||this.isInternal&&!e.includeInternal):!1}hitTestPoint(e,t=0,r=!1,i){return this.isClosed&&(this.isFilled||r)&&Gi(e,this.vertices)?!0:I.Dist2(e,this.nearestPoint(e))<=t*t}distanceToPoint(e,t=!1,r){return I.Dist(e,this.nearestPoint(e,r))*(this.isClosed&&(this.isFilled||t)&&Gi(e,this.vertices)?-1:1)}distanceToLineSegment(e,t,r){if(I.Equals(e,t))return this.distanceToPoint(e,!1,r);const{vertices:i}=this;if(i.length===0)throw Error("nearest point not found");if(i.length===1)return I.Dist(e,i[0]);let s,o=1/0,a,l,u;const f=this.isClosed?i.length:i.length-1;for(let h=0;h<i.length;h++){if(l=i[h],h<f){const g=i[(h+1)%i.length];if(p2(e,t,l,g))return 0}u=I.NearestPointOnLineSegment(e,t,l,!0),a=I.Dist2(l,u),a<o&&(o=a,s=u)}if(!s)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&Gi(s,this.vertices)?-o:o}hitTestLineSegment(e,t,r=0,i){return this.distanceToLineSegment(e,t,i)<=r}intersectLineSegment(e,t,r){return(this.isClosed?$F(e,t,this.vertices):Nte(e,t,this.vertices))??[]}intersectCircle(e,t,r){return(this.isClosed?Bte(e,t,this.vertices):Fte(e,t,this.vertices))??[]}intersectPolygon(e,t){return T3(e,this.vertices,!0,this.isClosed)}intersectPolyline(e,t){return T3(e,this.vertices,!1,this.isClosed)}interpolateAlongEdge(e,t){const{vertices:r}=this;if(r.length===0)return new I(0,0);if(r.length===1||e<=0)return r[0];const i=e*this.length;let s=0;for(let o=0;o<(this.isClosed?r.length:r.length-1);o++){const a=r[o],l=r[(o+1)%r.length],u=I.Dist(a,l),f=s+u;if(f>=i)return I.Lrp(a,l,lm(s,f,i));s=f}return this.isClosed?r[0]:r[r.length-1]}uninterpolateAlongEdge(e,t){const{vertices:r,length:i}=this;let s=null,o=1/0,a=0;if(r.length===0||r.length===1)return 0;for(let u=0;u<(this.isClosed?r.length:r.length-1);u++){const f=r[u],h=r[(u+1)%r.length],g=I.NearestPointOnLineSegment(f,h,e,!0),y=I.Dist(g,e);y<o&&(o=y,s={start:f,end:h,nearestPoint:g,distanceToStart:a}),a+=I.Dist(f,h)}return Be(s),(s.distanceToStart+I.Dist(s.start,s.nearestPoint))/i}isPointInBounds(e,t=0){const{bounds:r}=this;return!(e.x<r.minX-t||e.y<r.minY-t||e.x>r.maxX+t||e.y>r.maxY+t)}overlapsPolygon(e){const t=e.map(l=>I.From(l)),{vertices:r,center:i,isFilled:s,isEmptyLabel:o,isClosed:a}=this;if(o)return!1;if(r.some(l=>Gi(l,t)))return!0;if(a){if(s&&(Gi(i,t)||t.every(l=>Gi(l,r)))||KF(t,r))return!0}else if(Hte(t,r))return!0;return!1}transform(e,t){return new g2(this,e,t)}_vertices;get vertices(){return this._vertices||(this._vertices=this.getVertices(Ha.EXCLUDE_LABELS)),this._vertices}getBoundsVertices(){return this.excludeFromShapeBounds?[]:this.vertices}_boundsVertices;get boundsVertices(){return this._boundsVertices||(this._boundsVertices=this.getBoundsVertices()),this._boundsVertices}getBounds(){return we.FromPoints(this.boundsVertices)}_bounds;get bounds(){return this._bounds||(this._bounds=this.getBounds()),this._bounds}get center(){return this.bounds.center}_area;get area(){return this._area||(this._area=this.getArea()),this._area}getArea(){if(!this.isClosed)return 0;const{vertices:e}=this;let t=0;for(let r=0,i=e.length;r<i;r++){const s=e[r],o=e[(r+1)%i];t+=s.x*o.y-o.x*s.y}return t/2}toSimpleSvgPath(){let e="";const{vertices:t}=this,r=t.length;if(r===0)return e;e+=`M${t[0].x},${t[0].y}`;for(let i=1;i<r;i++)e+=`L${t[i].x},${t[i].y}`;return this.isClosed&&(e+="Z"),e}_length;get length(){return this._length?this._length:(this._length=this.getLength(Ha.EXCLUDE_LABELS),this._length)}getLength(e){const t=this.getVertices(e??Ha.EXCLUDE_LABELS);if(t.length===0)return 0;let r=t[0],i=0;for(let s=1;s<t.length;s++){const o=t[s];i+=I.Dist(r,o),r=o}return this.isClosed&&(i+=I.Dist(t[t.length-1],t[0])),i}}class g2 extends Iu{constructor(e,t,r){super(e),this.geometry=e,this.matrix=t,this.inverse=xe.Inverse(t),this.decomposed=xe.Decompose(t),r&&(r.isLabel!=null&&(this.isLabel=r.isLabel),r.isInternal!=null&&(this.isInternal=r.isInternal),r.debugColor!=null&&(this.debugColor=r.debugColor),r.ignore!=null&&(this.ignore=r.ignore)),Be(ir(this.decomposed.scaleX,this.decomposed.scaleY),"non-uniform scaling is not yet supported")}inverse;decomposed;getVertices(e){return this.geometry.getVertices(e).map(t=>xe.applyToPoint(this.matrix,t))}getBoundsVertices(){return this.geometry.getBoundsVertices().map(e=>xe.applyToPoint(this.matrix,e))}nearestPoint(e,t){return xe.applyToPoint(this.matrix,this.geometry.nearestPoint(xe.applyToPoint(this.inverse,e),t))}hitTestPoint(e,t=0,r,i){return this.geometry.hitTestPoint(xe.applyToPoint(this.inverse,e),t/this.decomposed.scaleX,r,i)}distanceToPoint(e,t=!1,r){return this.geometry.distanceToPoint(xe.applyToPoint(this.inverse,e),t,r)*this.decomposed.scaleX}distanceToLineSegment(e,t,r){return this.geometry.distanceToLineSegment(xe.applyToPoint(this.inverse,e),xe.applyToPoint(this.inverse,t),r)*this.decomposed.scaleX}hitTestLineSegment(e,t,r=0,i){return this.geometry.hitTestLineSegment(xe.applyToPoint(this.inverse,e),xe.applyToPoint(this.inverse,t),r/this.decomposed.scaleX,i)}intersectLineSegment(e,t,r){return xe.applyToPoints(this.matrix,this.geometry.intersectLineSegment(xe.applyToPoint(this.inverse,e),xe.applyToPoint(this.inverse,t),r))}intersectCircle(e,t,r){return xe.applyToPoints(this.matrix,this.geometry.intersectCircle(xe.applyToPoint(this.inverse,e),t/this.decomposed.scaleX,r))}intersectPolygon(e,t){return xe.applyToPoints(this.matrix,this.geometry.intersectPolygon(xe.applyToPoints(this.inverse,e),t))}intersectPolyline(e,t){return xe.applyToPoints(this.matrix,this.geometry.intersectPolyline(xe.applyToPoints(this.inverse,e),t))}transform(e,t){return new g2(this.geometry,xe.Multiply(e,this.matrix),{isLabel:t?.isLabel??this.isLabel,isInternal:t?.isInternal??this.isInternal,debugColor:t?.debugColor??this.debugColor,ignore:t?.ignore??this.ignore})}getSvgPathData(){throw new Error("Cannot get SVG path data for transformed geometry.")}}class Os extends Iu{children=[];ignoredChildren=[];constructor(e){super({...e,isClosed:!0,isFilled:!1});const t=r=>{for(const i of r)i instanceof Os?t(i.children):i.ignore?this.ignoredChildren.push(i):this.children.push(i)};if(t(e.children),this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(e){return this.isExcludedByFilter(e)?[]:this.children.filter(t=>!t.isExcludedByFilter(e)).flatMap(t=>t.getVertices(e))}nearestPoint(e,t){let r=1/0,i;const{children:s}=this;if(s.length===0)throw Error("no children");let o,a;for(const l of s)l.isExcludedByFilter(t)||(o=l.nearestPoint(e,t),a=I.Dist2(o,e),a<r&&(r=a,i=o));if(!i)throw Error("nearest point not found");return i}distanceToPoint(e,t=!1,r){let i=1/0;for(const s of this.children){if(s.isExcludedByFilter(r))continue;const o=s.distanceToPoint(e,t,r);o<i&&(i=o)}return i}hitTestPoint(e,t,r,i=Ha.EXCLUDE_LABELS){return!!this.children.filter(s=>!s.isExcludedByFilter(i)).find(s=>s.hitTestPoint(e,t,r))}hitTestLineSegment(e,t,r,i=Ha.EXCLUDE_LABELS){return!!this.children.filter(s=>!s.isExcludedByFilter(i)).find(s=>s.hitTestLineSegment(e,t,r))}intersectLineSegment(e,t,r){return this.children.flatMap(i=>i.isExcludedByFilter(r)?qn:i.intersectLineSegment(e,t,r))}intersectCircle(e,t,r){return this.children.flatMap(i=>i.isExcludedByFilter(r)?qn:i.intersectCircle(e,t,r))}getBoundsVertices(){return this.excludeFromShapeBounds?[]:this.children.flatMap(e=>e.getBoundsVertices())}intersectPolygon(e,t){return this.children.flatMap(r=>r.isExcludedByFilter(t)?qn:r.intersectPolygon(e,t))}intersectPolyline(e,t){return this.children.flatMap(r=>r.isExcludedByFilter(t)?qn:r.intersectPolyline(e,t))}interpolateAlongEdge(e,t){const r=this.getLength(t),i=e*r;let s=0;for(const o of this.children){if(o.isExcludedByFilter(t))continue;const a=o.length,l=s+a;if(l>=i)return o.interpolateAlongEdge(lm(s,l,i),t);s=l}return this.children[this.children.length-1].interpolateAlongEdge(1,t)}uninterpolateAlongEdge(e,t){const r=this.getLength(t);let i=null,s=1/0,o=0;for(const u of this.children){if(u.isExcludedByFilter(t))continue;const f=u.getLength(t),h=o+f,g=u.distanceToPoint(e,!1,t);g<s&&(s=g,i={startLength:o,endLength:h,child:u}),o=h}Be(i);const a=i.child.uninterpolateAlongEdge(e,t);return at(i.startLength,i.endLength,a)/r}transform(e){return new Os({children:this.children.map(t=>t.transform(e)),isLabel:this.isLabel,debugColor:this.debugColor,ignore:this.ignore})}getArea(){return this.children[0].area}toSimpleSvgPath(){let e="";for(const r of this.children)e+=r.toSimpleSvgPath();const t=we.FromPoints(this.boundsVertices).corners;for(let r=0,i=t.length;r<i;r++){const s=t[r],o=t[(r-1+i)%i],a=s.dist(o),l=t[(r+1)%i],u=s.dist(l),f=s.clone().lrp(o,4/a),h=s,g=s.clone().lrp(l,4/u);e+=`M${f.x},${f.y} L${h.x},${h.y} L${g.x},${g.y} `}return e}getLength(e){let t=0;for(const r of this.children)r.isExcludedByFilter(e)||(t+=r.length);return t}getSvgPathData(){return this.children.map((e,t)=>e.isLabel?"":e.getSvgPathData(t===0)).join(" ")}overlapsPolygon(e){return this.children.some(t=>t.overlapsPolygon(e))}}class Df extends Iu{_start;_end;_d;_u;_ul;constructor(e){super({...e,isClosed:!1,isFilled:!1});const{start:t,end:r}=e;this._start=t,this._end=r,this._d=t.clone().sub(r),this._u=this._d.clone().uni(),this._ul=this._u.len()}getLength(){return this._d.len()}getVertices(){return[this._start,this._end]}nearestPoint(e){const{_start:t,_end:r,_d:i,_u:s,_ul:o}=this;if(i.len()===0||o===0)return t;const a=I.Sub(e,t).dpr(s)/o,l=t.x+s.x*a;if(l<Math.min(t.x,r.x))return t.x<r.x?t:r;if(l>Math.max(t.x,r.x))return t.x>r.x?t:r;const u=t.y+s.y*a;return u<Math.min(t.y,r.y)?t.y<r.y?t:r:u>Math.max(t.y,r.y)?t.y>r.y?t:r:new I(l,u)}getSvgPathData(e=!0){const{_start:t,_end:r}=this;return`${e?`M${t.toFixed()}`:""} L${r.toFixed()}`}}class ny extends Iu{_points;_segments;constructor(e){super({isClosed:!1,isFilled:!1,...e});const{points:t}=e;if(this._points=t,t.length<2)throw new Error("Polyline2d: points must be an array of at least 2 points")}get segments(){if(!this._segments){this._segments=[];const{vertices:e}=this;for(let t=0,r=e.length-1;t<r;t++){const i=e[t],s=e[t+1];this._segments.push(new Df({start:i,end:s}))}this.isClosed&&this._segments.push(new Df({start:e[e.length-1],end:e[0]}))}return this._segments}getLength(){return this.segments.reduce((e,t)=>e+t.length,0)}getVertices(){return this._points}nearestPoint(e){const{segments:t}=this;let r=this._points[0],i=1/0,s,o;for(let a=0;a<t.length;a++)s=t[a].nearestPoint(e),o=I.Dist2(s,e),o<i&&(r=s,i=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(e,t,r=0){const{segments:i}=this;for(let s=0,o=i.length;s<o;s++)if(i[s].hitTestLineSegment(e,t,r))return!0;return!1}getSvgPathData(){const{vertices:e}=this;return e.length<2?"":e.reduce((t,r,i)=>i===0?`M ${r.x} ${r.y}`:`${t} L ${r.x} ${r.y}`,"")}}class fm extends ny{constructor(e){if(super({...e}),this.isClosed=!0,e.points.length<3)throw new Error("Polygon2d: points must be an array of at least 3 points")}}class Va extends fm{_x;_y;_w;_h;constructor(e){const{x:t=0,y:r=0,width:i,height:s}=e;super({...e,points:[new I(t,r),new I(t+i,r),new I(t+i,r+s),new I(t,r+s)]}),this._x=t,this._y=r,this._w=i,this._h=s}getBounds(){return new we(this._x,this._y,this._w,this._h)}getSvgPathData(){const{_x:e,_y:t,_w:r,_h:i}=this;return this.negativeZeroFix(),`M${e},${t} h${r} v${i} h${-r}z`}negativeZeroFix(){this._x=zS(this._x),this._y=zS(this._y),this._w=zS(this._w),this._h=zS(this._h)}}function zS(n){return Object.is(n,-0)?0:n}class Mu{constructor(e){this.editor=e}static configure(e){return class extends this{options={...this.options,...e}}}options={};static props;static migrations;static type;getFontFaces(e){return qn}canSnap(e){return!0}canTabTo(e){return!0}canScroll(e){return!1}canBind(e){return!0}canEdit(e){return!1}canResize(e){return!0}canResizeChildren(e){return!0}canEditInReadonly(e){return!1}canCrop(e){return!1}canBeLaidOut(e,t){return!0}canCull(e){return!0}providesBackgroundForChildren(e){return!1}hideResizeHandles(e){return!1}hideRotateHandle(e){return!1}hideSelectionBoundsBg(e){return!1}hideSelectionBoundsFg(e){return!1}isAspectRatioLocked(e){return!1}isExportBoundsContainer(e){return!1}canReceiveNewChildrenOfType(e,t){return!1}expandSelectionOutlinePx(e){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(e){return{}}getHandleSnapGeometry(e){return{}}getText(e){}getAriaDescriptor(e){}}function qF(n,e,t={}){const{closed:r=!1,snap:i=1,start:s="outset",end:o="outset",lengthRatio:a=2,style:l="dashed",forceSolid:u=!1}=t;let f=0,h=0,g=1,y=0,b=0;if(u)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(l){case"dashed":{g=1,f=Math.min(e*a,n/4);break}case"dotted":{g=100,f=e/g;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(n+=f/2,b+=f/2):s==="skip"&&(n-=f,b-=f),o==="outset"?n+=f/2:o==="skip"&&(n-=f)),h=Math.floor(n/f/(2*g)),h-=h%i,h<3&&l==="dashed"?n/e<4?(f=n,h=1,y=0):(f=n*(1/3),y=n*(1/3)):(f=n/h/(2*g),r?(b=f/2,y=(n-h*f)/h):y=(n-h*f)/Math.max(1,h-1)),{strokeDasharray:[f,y].join(" "),strokeDashoffset:b.toString()}}function E3({bounds:n,className:e}){const t=te(),r=ee("zoom level",()=>t.getZoomLevel(),[t]);return m.jsx("g",{className:e,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:n.sides.map((i,s)=>{const{strokeDasharray:o,strokeDashoffset:a}=qF(i[0].dist(i[1]),1/r,{style:"dashed",lengthRatio:4});return m.jsx("line",{x1:i[0].x,y1:i[0].y,x2:i[1].x,y2:i[1].y,strokeDasharray:o,strokeDashoffset:a},s)})})}class $te extends Mu{static type="group";static props=iF;static migrations=sF;hideSelectionBoundsFg(){return!0}canBind(){return!1}canResize(){return!0}canResizeChildren(){return!0}getDefaultProps(){return{}}getGeometry(e){const t=this.editor.getSortedChildIdsForParent(e.id);return t.length===0?new Va({width:1,height:1,isFilled:!1}):new Os({children:t.map(r=>{const i=this.editor.getShape(r);return this.editor.getShapeGeometry(r).transform(this.editor.getShapeLocalTransform(i),{isLabel:!1})})})}component(e){const t=this.editor.getErasingShapeIds().includes(e.id),{hintingShapeIds:r}=this.editor.getCurrentPageState(),i=r.length>0&&r.some(a=>a!==e.id&&this.editor.isShapeOfType(this.editor.getShape(a),"group")),s=this.editor.getCurrentPageState().focusedGroupId!==e.id;if(!t&&(s||i))return null;const o=this.editor.getShapeGeometry(e).bounds;return m.jsx(hu,{children:m.jsx(E3,{className:"tl-group",bounds:o})})}indicator(e){const t=this.editor.getShapeGeometry(e).bounds;return m.jsx(E3,{className:"",bounds:t})}onChildrenChange(e){const t=this.editor.getSortedChildIdsForParent(e.id);if(t.length===0){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([e.id]);return}else if(t.length===1){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(t,e.parentId),this.editor.deleteShapes([e.id]);return}}}const VF=[$te],Kte=new Set(VF.map(n=>n.type));function GF(n){const e=[...VF],t=new Set;for(const r of n){if(Kte.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(t.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);e.push(r),t.add(r.type)}return e}var Gd=bB();const qte=Ja(Gd);function YF(n,e){const t=new Map;return async function(i){const s=t.get(i);if(s)return s;const o=(async()=>{try{const a=await Gl(i,e);return Be(a.ok),await n(a)}catch(a){return console.error(a),null}})();return t.set(i,o),o}}const Nv=YF(async n=>await Ci.blobToDataUrl(await n.blob())),Vte=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,Gte=/@font-face\s*{([^}]+)}/gi,WF=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,Yte=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function Wte(n){return Array.from(n.matchAll(Vte),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function XF(n,e){return Array.from(n.matchAll(Gte),t=>{const r=t[1],i=Array.from(r.matchAll(WF),o=>{const a=o[1]||o[2]||o[3];return{original:a,resolved:it(a,e)?.href??null}}),s=new Set(Array.from(r.matchAll(Yte),o=>(o[1]||o[2]||o[3]).toLowerCase()));return{fontFace:r,urls:i,fontFamilies:s}})}function Xte(n){const e=/\s*(?:([^'"][^;\n\s,]+)|"([^"]+)"|'([^']+)')\s*/gi,t=/\s*,\s*/gi,r=new Set;for(;;){const i=e.exec(n);if(!i)break;const s=i[1]||i[2]||i[3];if(r.add(s.toLowerCase()),t.lastIndex=e.lastIndex,!t.exec(n))break;e.lastIndex=t.lastIndex}return r}function ZF(n){return!(n.startsWith("-")||n.startsWith("animation")||n.startsWith("transition")||n==="cursor"||n==="pointer-events"||n==="user-select"||n==="touch-action")}function Zte(n,e){return{imports:Wte(n),fontFaces:XF(n,e)}}function Jte(n){return Array.from(n.matchAll(WF),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}var Qte=Object.create,JF=Object.defineProperty,ene=Object.getOwnPropertyDescriptor,tne=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),QF=n=>{throw TypeError(n)},e6=(n,e,t)=>e in n?JF(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,nne=n=>[,,,Qte(null)],t6=["class","method","getter","setter","accessor","field","value","get","set"],n6=n=>n!==void 0&&typeof n!="function"?QF("Function expected"):n,rne=(n,e,t,r,i)=>({kind:t6[n],name:e,metadata:r,addInitializer:s=>t._?QF("Already initialized"):i.push(n6(s||null))}),ine=(n,e)=>e6(e,tne("metadata"),n[3]),sne=(n,e,t,r)=>{for(var i=0,s=n[e>>1],o=s&&s.length;i<o;i++)s[i].call(t);return r},one=(n,e,t,r,i,s)=>{for(var o,a,l,u,f=e&7,h=!1,g=!1,y=2,b=t6[f+5],v=n[y]||(n[y]=[]),w=(i=i.prototype,ene(i,t)),x=r.length-1;x>=0;x--)l=rne(f,t,a={},n[3],v),l.static=h,l.private=g,u=l.access={has:T=>t in T},u.get=T=>T[t],o=(0,r[x])(w[b],l),a._=1,n6(o)&&(w[b]=o);return w&&JF(i,t,w),i},BS=(n,e,t)=>e6(n,typeof e!="symbol"?e+"":e,t),r6,zv;const i6="tldraw-svg-export";r6=[Is];class m2{constructor(){sne(zv,5,this),BS(this,"fontFacesPromise",null),BS(this,"foundFontNames",new Set),BS(this,"fontFacesToEmbed",new Set),BS(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){Be(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=ane()}onFontFamilyValue(e){Be(this.fontFacesPromise,"FontEmbedder not started");const t=Xte(e);for(const r of t){if(this.foundFontNames.has(r))return;this.foundFontNames.add(r),this.pendingPromises.push(this.fontFacesPromise.then(i=>{const s=i.filter(o=>o.fontFamilies.has(r));for(const o of s)if(!this.fontFacesToEmbed.has(o)){this.fontFacesToEmbed.add(o);for(const a of o.urls)!a.resolved||a.embedded||(a.embedded=Nv(a.resolved))}}))}}async createCss(){await Promise.all(this.pendingPromises);let e="";for(const t of this.fontFacesToEmbed){let r=`@font-face {${t.fontFace}}`;for(const i of t.urls){if(!i.embedded)continue;const s=await i.embedded;s&&(r=r.replace(i.original,s))}e+=r}return e}}zv=nne();one(zv,1,"onFontFamilyValue",r6,m2);ine(zv,m2);async function ane(){const n=[],e=Array.from(document.styleSheets).filter(t=>!t.ownerNode?.closest(`.${i6}`));for(const t of e){let r;try{r=t.cssRules}catch{}if(r){for(const i of t.cssRules)if(i instanceof CSSFontFaceRule)n.push(XF(i.cssText,t.href??document.baseURI));else if(i instanceof CSSImportRule){const s=new URL(i.href,i.parentStyleSheet?.href??document.baseURI);n.push(W_(s.href))}}else t.href&&n.push(W_(t.href))}return tt(await Promise.all(n)).flat()}const W_=YF(async n=>{const e=Zte(await n.text(),n.url),t=await Promise.all(e.imports.map(({url:r})=>W_(new URL(r,n.url).href)));return[...e.fontFaces,...tt(t).flat()]}),Gs=(n,e,{currentColor:t})=>n==="currentColor"||n===t,bt=(n,e,{parentStyles:t})=>t[e]===n,An=n=>(e,t,{getStyle:r})=>{const i=r(`border-${n}-width`),s=r(`border-${n}-style`);return i==="0px"||s==="none"},s6={"border-block-end-color":Gs,"border-block-start-color":Gs,"border-bottom-color":Gs,"border-inline-end-color":Gs,"border-inline-start-color":Gs,"border-left-color":Gs,"border-right-color":Gs,"border-top-color":Gs,"caret-color":Gs,"column-rule-color":Gs,"outline-color":Gs,"text-decoration":(n,e,{currentColor:t})=>n==="none solid currentColor"||n==="none solid "+t,"text-decoration-color":Gs,"text-emphasis-color":Gs,"border-collapse":bt,"border-spacing":bt,"caption-side":bt,cursor:bt,direction:bt,"empty-cells":bt,"font-family":bt,"font-size":bt,"font-style":bt,"font-variant":bt,"font-weight":bt,"font-size-adjust":bt,"font-stretch":bt,font:bt,"letter-spacing":bt,"line-height":bt,"list-style-image":bt,"list-style-position":bt,"list-style-type":bt,"list-style":bt,orphans:bt,"overflow-wrap":bt,quotes:bt,"stroke-linecap":bt,"stroke-linejoin":bt,"tab-size":bt,"text-align":bt,"text-align-last":bt,"text-indent":bt,"text-justify":bt,"text-shadow":bt,"text-transform":bt,visibility:bt,"white-space":bt,"white-space-collapse":bt,widows:bt,"word-break":bt,"word-spacing":bt,"word-wrap":bt,"border-top":An("top"),"border-right":An("right"),"border-bottom":An("bottom"),"border-left":An("left"),"border-block-end":An("block-end"),"border-block-start":An("block-start"),"border-inline-end":An("inline-end"),"border-inline-start":An("inline-start"),"border-top-style":An("top"),"border-right-style":An("right"),"border-bottom-style":An("bottom"),"border-left-style":An("left"),"border-block-end-style":An("block-end"),"border-block-start-style":An("block-start"),"border-inline-end-style":An("inline-end"),"border-inline-start-style":An("inline-start"),"border-top-width":An("top"),"border-right-width":An("right"),"border-bottom-width":An("bottom"),"border-left-width":An("left"),"border-block-end-width":An("block-end"),"border-block-start-width":An("block-start"),"border-inline-end-width":An("inline-end")};function o6(n){if(n.shadowRoot)return n.shadowRoot.childNodes;if(dne(n)){const e=n.assignedNodes();if(e?.length)return e}return n.childNodes}function*X_(n){for(const e of o6(n))lne(e)&&(yield e)}function Bv(n){return n.ownerDocument?.defaultView??globalThis}function lne(n){return n instanceof Bv(n).Element}function cne(n){return n instanceof Bv(n).ShadowRoot}function une(n){return"getRootNode"in n&&cne(n.getRootNode())}function dne(n){return une(n)&&n instanceof Bv(n).HTMLSlotElement}function hne(n){return n.style}function y2(n,e){return Bv(n).getComputedStyle(n,e)}const Rf={};class fne{constructor(e){this.root=e}styles=new Map;fonts=new m2;readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const t=Array.from(X_(e));for(;t.length;){const r=t.pop();t.push(...X_(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:t=!0,shouldSkipInheritedParentStyles:r=!0}){const i=t?yne(e.tagName.toLowerCase()):Rf,s=Object.assign({},Rf);if(r){let a=e.parentElement;for(;a;){const l=this.styles.get(a)?.self;for(const u in l)s[u]||(s[u]=l[u]);a=a.parentElement}}const o={self:pne(e,{defaultStyles:i,parentStyles:s}),before:_3(e,"::before"),after:_3(e,"::after")};this.styles.set(e,o)}fetchResources(){const e=[];for(const t of this.styles.values())for(const r of Hn(t))if(r)for(const[i,s]of Object.entries(r)){if(!s)continue;i==="font-family"&&this.fonts.onFontFamilyValue(s);const o=Jte(s);o.length!==0&&e.push(...o.map(async({url:a,original:l})=>{const u=await Nv(a)??"data:";r[i]=s.replace(l,`url("${u}")`)}))}return Promise.all(e)}unwrapCustomElements(){const e=new Set,t=(r,i)=>{if(e.has(r))return;e.add(r);const s=r.shadowRoot;if(s){const o=document.createElement("div");this.styles.set(o,this.styles.get(r)),o.setAttribute("data-tl-custom-element",r.tagName),(i??r.parentElement).appendChild(o);for(const a of s.childNodes)a instanceof Element?t(a,o):o.appendChild(a.cloneNode(!0));r.remove()}else if(i){if(r.tagName.toLowerCase()==="style")return;const o=r.cloneNode(!1);this.styles.set(o,this.styles.get(r)),i.appendChild(o);for(const a of o6(r))a instanceof Element?t(a,o):o.appendChild(a.cloneNode(!0))}};for(const r of this.styles.keys())t(r,null)}embedStyles(){let e="";for(const[t,r]of this.styles){if(r.after||r.before){const s=`pseudo-${zt()}`;t.classList.add(s),r.before&&(e+=`.${s}::before {${P3(r.before)}}
113
39
  `),r.after&&(e+=`.${s}::after {${P3(r.after)}}
114
40
  `)}const i=hne(t);for(const[s,o]of Object.entries(r.self))o&&i.setProperty(s,o);i.fontKerning==="auto"&&(i.fontKerning="normal")}return e}async getFontFaceCss(){return await this.fonts.createCss()}dispose(){mne()}}function pne(n,{defaultStyles:e,parentStyles:t}){return n.computedStyleMap?a6(n.computedStyleMap(),{defaultStyles:e,parentStyles:t}):S2(y2(n),{defaultStyles:e,parentStyles:t})}function _3(n,e){const t=y2(n,e),r=t.getPropertyValue("content");if(!(r===""||r==="none"))return S2(t,{defaultStyles:Rf,parentStyles:Rf})}function a6(n,{defaultStyles:e,parentStyles:t}){const r={},s={currentColor:n.get("color")?.toString()||"",parentStyles:t,defaultStyles:e,getStyle:o=>n.get(o)?.toString()??""};for(const o of n.keys()){if(!ZF(o))continue;const a=n.get(o).toString();if(e[o]===a)continue;const l=tr(s6,o);l&&l(a,o,s)||(r[o]=a)}return r}function S2(n,{defaultStyles:e,parentStyles:t}){const r={},s={currentColor:n.color,parentStyles:t,defaultStyles:e,getStyle:o=>n.getPropertyValue(o)};for(const o in n){if(!ZF(o))continue;const a=n.getPropertyValue(o);if(e[o]===a)continue;const l=tr(s6,o);l&&l(a,o,s)||(r[o]=a)}return r}function P3(n){let e="";for(const[t,r]of Object.entries(n))e+=`${t}: ${r};`;return e}let vf;const I3={};function gne(){if(!vf){const n=document.createElement("iframe");n.style.display="none",document.body.appendChild(n);const e=Mr(n.contentDocument,"frame must have a document"),t=document.createElementNS("http://www.w3.org/2000/svg","svg"),r=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");t.appendChild(r),e.body.appendChild(t),vf={iframe:n,foreignObject:r,document:e}}return vf}function mne(){vf&&(document.body.removeChild(vf.iframe),vf=void 0)}const M3={defaultStyles:Rf,parentStyles:Rf};function yne(n){let e=I3[n];if(!e){const{foreignObject:t,document:r}=gne(),i=r.createElement(n);t.appendChild(i),e=i.computedStyleMap?a6(i.computedStyleMap(),M3):S2(y2(i),M3),t.removeChild(i),I3[n]=e}return e}function Sne(n,e){Array.from(n.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function k3(n,e){return n.replaceWith(e),e}async function qg(n,e){const t=document.createElement("img");e&&Sne(e,t),t.setAttribute("src",n??"data:"),t.setAttribute("decoding","sync"),t.setAttribute("loading","eager");try{await t.decode()}catch{}return t}async function bne(n){try{const e=n.toDataURL();return await qg(e,n)}catch{return await qg(null,n)}}async function xne(n){try{const e=await Js.getVideoFrameAsDataUrl(n);return qg(e,n)}catch(e){console.error("Could not get video frame",e)}if(n.poster){const e=await Nv(n.poster);return qg(e,n)}return qg(null,n)}async function l6(n){if(n instanceof HTMLCanvasElement)return k3(n,await bne(n));if(n instanceof HTMLVideoElement)return k3(n,await xne(n));if(n instanceof HTMLImageElement){const e=n.currentSrc||n.src,t=await Nv(e);n.setAttribute("src",t??"data:"),n.setAttribute("decoding","sync"),n.setAttribute("loading","eager");try{await n.decode()}catch{}return n}else n instanceof HTMLInputElement?n.setAttribute("value",n.value):n instanceof HTMLTextAreaElement&&(n.textContent=n.value);await Promise.all(Array.from(X_(n),e=>l6(e)))}const Z_=(n,e)=>n.props===e.props&&n.meta===e.meta,c6=E.memo(function({id:e,shape:t,util:r,index:i,backgroundIndex:s,opacity:o}){const a=te(),{ShapeErrorFallback:l,ShapeWrapper:u}=on(),f=E.useRef(null),h=E.useRef(null);E.useEffect(()=>Ms("load fonts",()=>{const b=a.fonts.getShapeFontFaces(e);a.fonts.requestFonts(b)}),[a,e]);const g=E.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});wd("set shape stuff",()=>{const b=a.getShape(e);if(!b)return;const v=g.current,w=a.getShapeClipPath(e)??"none";w!==v.clipPath&&(bi(f.current,"clip-path",w),bi(h.current,"clip-path",w),v.clipPath=w);const x=a.getShapePageTransform(e),T=xe.toCssString(x),P=a.getShapeGeometry(b).bounds;T!==v.transform&&(bi(f.current,"transform",T),bi(h.current,"transform",T),v.transform=T);const M=Math.max(P.width,1),k=Math.max(P.height,1);(M!==v.width||k!==v.height)&&(bi(f.current,"width",M+"px"),bi(f.current,"height",k+"px"),bi(h.current,"width",M+"px"),bi(h.current,"height",k+"px"),v.width=M,v.height=k)},[a]),E.useLayoutEffect(()=>{const b=f.current,v=h.current;bi(b,"opacity",o),bi(v,"opacity",o),bi(b,"z-index",i),bi(v,"z-index",s)},[o,i,s]),wd("set display",()=>{if(!a.getShape(e))return;const w=a.getCulledShapes().has(e);w!==g.current.isCulled&&(bi(f.current,"display",w?"none":"block"),bi(h.current,"display",w?"none":"block"),g.current.isCulled=w)},[a]);const y=E.useCallback(b=>a.annotateError(b,{origin:"shape",willCrashApp:!1}),[a]);return!t||!u?null:m.jsxs(m.Fragment,{children:[r.backgroundComponent&&m.jsx(u,{ref:h,shape:t,isBackground:!0,children:m.jsx(hm,{fallback:l,onError:y,children:m.jsx(d6,{shape:t,util:r})})}),m.jsx(u,{ref:f,shape:t,isBackground:!1,children:m.jsx(hm,{fallback:l,onError:y,children:m.jsx(u6,{shape:t,util:r})})})]})}),u6=E.memo(function({shape:e,util:t}){return Cv("InnerShape:"+e.type,()=>t.component(t.editor.store.unsafeGetWithoutCapture(e.id)),[t,e.id])},(n,e)=>Z_(n.shape,e.shape)&&n.util===e.util),d6=E.memo(function({shape:e,util:t}){return Cv("InnerShape:"+e.type,()=>t.backgroundComponent?.(t.editor.store.unsafeGetWithoutCapture(e.id)),[t,e.id])},(n,e)=>n.shape.props===e.shape.props&&n.shape.meta===e.shape.meta&&n.util===e.util);function ja(n){const e=E.useRef();return E.useLayoutEffect(()=>{e.current=n}),E.useDebugValue(n),E.useCallback((...t)=>{const r=e.current;return Be(r,"fn does not exist"),r(...t)},[])}const b2=E.createContext(null);function vne({context:n,editor:e,children:t}){const r=e.options.exportProvider;return m.jsx(c2,{editor:e,children:m.jsx(TF,{container:e.getContainer(),children:m.jsx(b2.Provider,{value:n,children:m.jsx(r,{children:t})})})})}function ry(){return E.useContext(b2)}function wne(){const n=E.useContext(b2),[e]=E.useState(mI);return E.useEffect(()=>(n?.waitUntil(e),()=>{e.resolve()}),[e,n]),ja(()=>{e.resolve()})}var Cne=Object.create,h6=Object.defineProperty,Tne=Object.getOwnPropertyDescriptor,Ene=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),f6=n=>{throw TypeError(n)},p6=(n,e,t)=>e in n?h6(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_ne=n=>[,,,Cne(null)],g6=["class","method","getter","setter","accessor","field","value","get","set"],m6=n=>n!==void 0&&typeof n!="function"?f6("Function expected"):n,Pne=(n,e,t,r,i)=>({kind:g6[n],name:e,metadata:r,addInitializer:s=>t._?f6("Already initialized"):i.push(m6(s||null))}),Ine=(n,e)=>p6(e,Ene("metadata"),n[3]),Mne=(n,e,t,r)=>{for(var i=0,s=n[e>>1],o=s&&s.length;i<o;i++)s[i].call(t);return r},kne=(n,e,t,r,i,s)=>{for(var o,a,l,u,f=e&7,h=!1,g=!1,y=2,b=g6[f+5],v=n[y]||(n[y]=[]),w=(i=i.prototype,Tne(i,t)),x=r.length-1;x>=0;x--)l=Pne(f,t,a={},n[3],v),l.static=h,l.private=g,u=l.access={has:T=>t in T},u.get=T=>T[t],o=(0,r[x])(w[b],l),a._=1,m6(o)&&(w[b]=o);return w&&h6(i,t,w),i},A3=(n,e,t)=>p6(n,typeof e!="symbol"?e+"":e,t),y6,Fv;y6=[Is];class x2{constructor(e){this.maxDelayTimeMs=e,Mne(Fv,5,this),A3(this,"isResolved",!1),A3(this,"promisesToWaitFor",[])}waitUntil(e){if(this.isResolved)throw new Error("Cannot `waitUntil` - the export has already been resolved. Make sure to call `waitUntil` as soon as possible during an export - ie within the first react effect after rendering.");this.promisesToWaitFor.push(e.catch(t=>console.error("Error while waiting for export:",t)))}async resolvePromises(){let e=null;for(;this.promisesToWaitFor.length!==e;)e=this.promisesToWaitFor.length,await Promise.allSettled(this.promisesToWaitFor),await D_(0)}async resolve(){const e=D_(this.maxDelayTimeMs).then(()=>"timeout"),t=this.resolvePromises().then(()=>"resolved");await Promise.race([e,t])==="timeout"&&console.warn("[tldraw] Export delay timed out after ${this.maxDelayTimeMs}ms"),this.isResolved=!0}}Fv=_ne();kne(Fv,1,"waitUntil",y6,x2);Ine(Fv,x2);function Ane(n,e,t={}){if(!window.document)throw Error("No document");const{scale:r=1,background:i=n.getInstanceState().exportBackground,padding:s=n.options.defaultSvgPadding,preserveAspectRatio:o}=t,a=t.darkMode??n.user.getIsDarkMode(),l=n.getShapeAndDescendantIds(e),u=n.getUnorderedRenderingShapes(!1).filter(({id:x})=>l.has(x)),f=e.length===1&&n.isShapeOfType(n.getShape(e[0]),"frame")?e[0]:null;let h=null;if(t.bounds?h=t.bounds.clone().expandBy(s):h=One(n,u,s,f),!h)return;const g=h.width*r,y=h.height*r;try{document.body.focus?.()}catch{}const b=new x2(n.options.maxExportDelayMs),v=mI();return b.waitUntil(v),{jsx:m.jsx(Dne,{editor:n,preserveAspectRatio:o,scale:r,pixelRatio:t.pixelRatio??null,bbox:h,background:i,singleFrameShapeId:f,isDarkMode:a,renderingShapes:u,onMount:v.resolve,waitUntil:b.waitUntil}),width:g,height:y,exportDelay:b}}function One(n,e,t,r){let i=!1,s=null;for(const{id:o}of e){const a=n.getShapeMaskedPageBounds(o);if(!a)continue;const l=n.getShape(o),u=n.getShapeUtil(l).isExportBoundsContainer(l);s?u&&we.ContainsApproximately(a,s)?(i=!0,s=a.clone()):(i&&!we.ContainsApproximately(s,a)&&(i=!1),s.union(a)):(i=u,s=a.clone())}return s?(!r&&!i&&s.expandBy(t),s):null}function Dne({editor:n,preserveAspectRatio:e,scale:t,pixelRatio:r,bbox:i,background:s,singleFrameShapeId:o,isDarkMode:a,renderingShapes:l,onMount:u,waitUntil:f}){const h=Vd(),g=_u({isDarkMode:a}),y=Wm("export state",{defsById:{},shapeElements:null}),{defsById:b,shapeElements:v}=ee(y),w=ja(M=>{y.update(k=>{if(Fo(k.defsById,M.key))return k;const A=Promise.resolve(M.getElement());return f(A.then(O=>{y.update(R=>({...R,defsById:{...R.defsById,[M.key]:{pending:!1,element:O}}}))})),{...k,defsById:{...k.defsById,[M.key]:{pending:!0,element:A}}}})}),x=E.useMemo(()=>({isDarkMode:a,waitUntil:f,addExportDef:w,scale:t,pixelRatio:r,async resolveAssetUrl(M,k){const A=n.getAsset(M);return!A||A.type!=="image"&&A.type!=="video"?null:await n.resolveAssetUrl(M,{screenScale:t*(k/A.props.w),shouldResolveToOriginal:r===null,dpr:r??void 0})}}),[a,f,w,t,r,n]),T=E.useRef(!1);E.useLayoutEffect(()=>{if(T.current)throw new Error("SvgExport should only render once - do not use with react strict mode");T.current=!0,(async()=>{const M={},k=l.map(async({id:O,opacity:R,index:F,backgroundIndex:z})=>{if(O===o)return[];const j=n.getShape(O);if(n.isShapeOfType(j,"group"))return[];const $=[],H=n.getShapeUtil(j);if(H.toSvg||H.toBackgroundSvg){const[B,G]=await Promise.all([H.toSvg?.(j,x),H.toBackgroundSvg?.(j,x)]),N=n.getShapePageTransform(j);let Y=N.toCssString(),W=1;"scale"in j.props&&j.props.scale!==1&&(W=j.props.scale,Y=`${Y} scale(${j.props.scale}, ${j.props.scale})`);const Q=n.getShapeMask(j.id),de=Q?xe.From(xe.Inverse(N)).applyToPoints(Q):null,U=a2(h,j.id);de&&(M[U]={pending:!1,element:m.jsx("clipPath",{id:U,children:m.jsx("path",{d:`M${de.map(({x:re,y:le})=>`${re/W},${le/W}`).join("L")}Z`})})}),B&&$.push({zIndex:F,element:m.jsx("g",{transform:Y,opacity:R,clipPath:Q?`url(#${U})`:void 0,children:B},`fg_${j.id}`)}),G&&$.push({zIndex:z,element:m.jsx("g",{transform:Y,opacity:R,clipPath:Q?`url(#${U})`:void 0,children:G},`bg_${j.id}`)})}else $.push({zIndex:F,element:m.jsx(O3,{shape:j,util:H,component:u6,className:"tl-shape",bbox:i,opacity:R},`fg_${j.id}`)}),H.backgroundComponent&&$.push({zIndex:z,element:m.jsx(O3,{shape:j,util:H,component:d6,className:"tl-shape tl-shape-background",bbox:i,opacity:R},`bg_${j.id}`)});return $}),A=(await Promise.all(k)).flat();Gd.flushSync(()=>{y.update(O=>({...O,shapeElements:A.sort((R,F)=>R.zIndex-F.zIndex).map(({element:R})=>R),defsById:{...O.defsById,...M}}))})})()},[i,n,x,h,l,o,y]),E.useEffect(()=>{const M=new Set;for(const{id:k}of l)for(const A of n.fonts.getShapeFontFaces(k))M.add(A);for(const k of M)w({key:zt(),getElement:async()=>{const A=await n.fonts.toEmbeddedCssDeclaration(k);return m.jsx("style",{nonce:n.options.nonce,children:A})}})},[n,l,w]),E.useEffect(()=>{v!==null&&u()},[u,v]);let P=s?g.background:"transparent";if(o&&s)if(n.getShapeUtil("frame")?.options.showColors){const k=n.getShape(o);P=Mt(g,k.props.color,"frameFill")}else P=g.solid;return m.jsx(vne,{editor:n,context:x,children:m.jsxs("svg",{preserveAspectRatio:e,direction:"ltr",width:i.width*t,height:i.height*t,viewBox:`${i.minX} ${i.minY} ${i.width} ${i.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:P},"data-color-mode":a?"dark":"light",className:`tl-container tl-theme__force-sRGB ${a?"tl-theme__dark":"tl-theme__light"}`,children:[m.jsx("defs",{children:Object.entries(b).map(([M,k])=>k.pending?null:m.jsx(E.Fragment,{children:k.element},M))}),v]})})}function O3({shape:n,util:e,className:t,component:r,bbox:i,opacity:s}){const o=te(),a=xe.Translate(-i.minX,-i.minY).multiply(o.getShapePageTransform(n.id)),l=o.getShapeGeometry(n.id).bounds,u=Math.max(l.width,1),f=Math.max(l.height,1);return m.jsx(u2,{fallback:()=>null,children:m.jsx("foreignObject",{x:i.minX,y:i.minY,width:i.w,height:i.h,className:"tl-shape-foreign-object tl-export-embed-styles",children:m.jsx("div",{className:t,"data-shape-type":n.type,style:{clipPath:o.getShapeClipPath(n.id),transform:a.toCssString(),width:u,height:f,opacity:s},children:m.jsx(r,{shape:n,util:e})})})})}let Rne=1;async function jne(n,e,t={}){const r=Ane(n,e,t);if(!r)return;const i=n.getContainer(),s=document.createElement("div");s.className=i6,s.inert=!0,s.tabIndex=-1,Object.assign(s.style,{position:"absolute",top:"0px",left:"0px",width:r.width+"px",height:r.height+"px",pointerEvents:"none",opacity:0}),i.appendChild(s);const o=xB.createRoot(s,{identifierPrefix:`export_${Rne++}_`});try{await Promise.resolve(),Gd.flushSync(()=>{o.render(r.jsx)}),await r.exportDelay.resolve();const a=s.firstElementChild;return Be(a instanceof SVGSVGElement,"Expected an SVG element"),await Lne(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{o.unmount(),i.removeChild(s)},0)}}async function Lne(n){const e=[...n.querySelectorAll("foreignObject.tl-export-embed-styles > *")];if(!e.length)return;const t=new fne(n);try{t.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(s=>l6(s)));for(const s of e)t.readRootElementStyles(s);await t.fetchResources();const r=await t.getFontFaceCss();t.unwrapCustomElements();const i=t.embedStyles();if(r||i){const s=document.createElementNS("http://www.w3.org/2000/svg","style");s.textContent=`${r}
115
- ${i}`,n.prepend(s)}}finally{t.dispose()}}let EE=null;function Nne(){return EE||(EE={maxWidth:_E("width"),maxHeight:_E("height"),maxArea:_E("area")}),EE}/*!
116
- * Extracted from https://github.com/jhildenbiddle/canvas-size
117
- * MIT License: https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE
118
- * Copyright (c) John Hildenbiddle
119
- */const D3=8192,zne=4096*4096,Bne={area:[16384,14188,11402,11180,10836,8192,4096],height:[8388607,65535,32767,16384,8192,4096],width:[4194303,65535,32767,16384,8192,4096]};function _E(n){const e=document.createElement("canvas");e.width=1,e.height=1;const t=e.getContext("2d");for(const r of Bne[n]){const i=n==="height"?1:r,s=n==="width"?1:r,o=document.createElement("canvas");o.width=i,o.height=s,o.getContext("2d").fillRect(i-1,s-1,1,1),t.drawImage(o,i-1,s-1,1,1,0,0,1,1);const l=t.getImageData(0,0,1,1).data[3]!==0;if(o.width=0,o.height=0,l)return e.width=0,e.height=0,n==="area"?r*r:r}throw e.width=0,e.height=0,Error("Failed to determine maximum canvas dimension")}function Fne(n,e){if(n<=D3&&e<=D3&&n*e<=zne)return[n,e];const{maxWidth:t,maxHeight:r,maxArea:i}=Nne(),s=n/e;if(n>t&&(n=t,e=n/s),e>r&&(e=r,n=e*s),n*e>i){const o=Math.sqrt(i/(n*e));n*=o,e*=o}return[n,e]}async function Une(n,e){const{type:t,width:r,height:i,quality:s=1,pixelRatio:o=2}=e;let[a,l]=Fne(r*o,i*o);a=Math.floor(a),l=Math.floor(l);const u=a/r,f=await Ci.blobToDataUrl(new Blob([n],{type:"image/svg+xml"})),h=await new Promise(y=>{const b=am();b.crossOrigin="anonymous",b.onload=async()=>{Nt.isSafari&&await D_(250);const v=document.createElement("canvas"),w=v.getContext("2d");v.width=a,v.height=l,w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(b,0,0,a,l),URL.revokeObjectURL(f),y(v)},b.onerror=()=>{y(null)},b.src=f});if(!h)return null;const g=await new Promise(y=>h.toBlob(b=>{(!b||In.throwToBlob.get())&&y(null),y(b)},"image/"+t,s));if(!g)return null;if(t==="png"){const y=new DataView(await g.arrayBuffer());return La.setPhysChunk(y,u,{type:"image/"+t})}else return g}const qi={menus:bn("open menus",[]),getOpenMenus(n){return n?this.menus.get().filter(e=>e.endsWith("-"+n)):this.menus.get()},addOpenMenu(n,e=""){const t=e?`${n}-${e}`:n,r=new Set(this.menus.get());r.has(t)||(r.add(t),this.menus.set([...r]))},deleteOpenMenu(n,e=""){const t=e?`${n}-${e}`:n,r=new Set(this.menus.get());r.has(t)&&(r.delete(t),this.menus.set([...r]))},clearOpenMenus(n){this.menus.set(n?this.menus.get().filter(e=>!e.endsWith("-"+n)):[])},_hiddenMenus:[],hideOpenMenus(n){if(this._hiddenMenus=[...this.getOpenMenus(n)],this._hiddenMenus.length!==0)for(const e of this._hiddenMenus)this.deleteOpenMenu(e,n)},showOpenMenus(n){if(this._hiddenMenus.length!==0){for(const e of this._hiddenMenus)this.addOpenMenu(e,n);this._hiddenMenus=[]}},isMenuOpen(n,e){return this.getOpenMenus(e).includes(n)},hasOpenMenus(n){return this.getOpenMenus(n).length>0},hasAnyOpenMenus(){return this.getOpenMenus().length>0},forContext(n){return{getOpenMenus:()=>this.getOpenMenus(n),addOpenMenu:e=>this.addOpenMenu(e,n),deleteOpenMenu:e=>this.deleteOpenMenu(e,n),clearOpenMenus:()=>this.clearOpenMenus(n),isMenuOpen:e=>this.isMenuOpen(e,n),hasOpenMenus:()=>this.hasOpenMenus(n),hasAnyOpenMenus:()=>this.hasAnyOpenMenus()}}},dx=new TZ,Hne={maxShapesPerPage:4e3,maxFilesAtOnce:100,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,uiDragDistanceSquared:16,uiCoarseDragDistanceSquared:625,defaultSvgPadding:32,cameraSlideFriction:.09,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,laserDelayMs:1200,maxExportDelayMs:5e3,tooltipDelayMs:700,temporaryAssetPreviewLifetimeMs:18e4,actionShortcutsLocation:"swap",createTextOnCanvasDoubleClick:!0,exportProvider:E.Fragment,enableToolbarKeyboardShortcuts:!0,maxFontsToLoadBeforeRender:1/0,nonce:void 0};function R3(n,e){if(!e)return!1;switch(n.type){case"mixed":return e.type==="mixed";case"shared":return e.type==="shared"&&n.value===e.value;default:throw kt(n)}}class $ne{map;constructor(e){this.map=new Map(e)}get(e){return this.map.get(e)}getAsKnownValue(e){const t=this.get(e);if(t&&t.type!=="mixed")return t.value}get size(){return this.map.size}equals(e){if(this.size!==e.size)return!1;const t=new Set;for(const[r,i]of this){if(!R3(i,e.get(r)))return!1;t.add(r)}for(const[r,i]of e)if(!t.has(r)&&!R3(i,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 J_ extends $ne{set(e,t){this.map.set(e,t)}applyValue(e,t){const r=this.get(e);if(!r){this.set(e,{type:"shared",value:t});return}switch(r.type){case"mixed":return;case"shared":r.value!==t&&this.set(e,{type:"mixed"});return;default:kt(r,"type")}}}function Kne(n,e,t){return Gl(n).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:t})})}const qne="https://cdn.tldraw.com";function fr(){return`${qne}/${d2}`}function Vne(n){switch(n.type){case"shapes":return`s${n.shapeIds.map(t=>PE(t.slice(6))).join(".")}`;case"page":return"p"+PE(Wi.parseId(n.pageId));case"viewport":{const{bounds:e,pageId:t}=n;let r=`v${Math.round(e.x)}.${Math.round(e.y)}.${Math.round(e.w)}.${Math.round(e.h)}`;return t&&(r+="."+PE(Wi.parseId(t))),r}default:kt(n)}}function Gne(n){switch(n[0]){case"s":return{type:"shapes",shapeIds:n.slice(1).split(".").filter(Boolean).map(r=>Zt(decodeURIComponent(r)))};case"p":return{type:"page",pageId:Wi.createId(decodeURIComponent(n.slice(1)))};case"v":{const[t,r,i,s,o]=n.slice(1).split(".");return{type:"viewport",bounds:new we(Number(t),Number(r),Number(i),Number(s)),pageId:o?Wi.createId(decodeURIComponent(o)):void 0}}default:throw Error("Invalid deep link string")}}function PE(n){return encodeURIComponent(n).replace(/\./g,"%2E")}function Yne(n,e){let t=n;const r=new Set(e);for(;r.has(t);)t=/^.*(\d+)$/.exec(t)?.[1]?t.replace(/(\d+)(?=\D?)$/,i=>(+i+1).toString()):`${t} 1`;return t}function FS(n,e,t,r){if(t.length===0)return[];const i=new Map;for(const o of tt(t.map(a=>n.getShape(a)))){const{parentId:a}=o;i.has(a)||i.set(a,{children:tt(n.getSortedChildIdsForParent(a).map(l=>n.getShape(l))),moving:new Set}),i.get(a).moving.add(o)}const s=[];switch(e){case"toBack":{i.forEach(({moving:o,children:a})=>Wne(o,a,s));break}case"toFront":{i.forEach(({moving:o,children:a})=>Xne(o,a,s));break}case"forward":{i.forEach(({moving:o,children:a})=>Zne(n,o,a,s,r));break}case"backward":{i.forEach(({moving:o,children:a})=>Jne(n,o,a,s,r));break}}return s}function Wne(n,e,t){const r=e.length;if(n.size===r)return;let i,s;for(let o=0;o<r;o++){const a=e[o];if(n.has(a))i=a.index,n.delete(a);else{s=a.index;break}}if(n.size!==0){const o=vd(i,s,n.size);t.push(...Array.from(n.values()).sort(kr).map((a,l)=>({...a,index:o[l]})))}}function Xne(n,e,t){const r=e.length;if(n.size===r)return;let i,s;for(let o=r-1;o>-1;o--){const a=e[o];if(n.has(a))s=a.index,n.delete(a);else{i=a.index;break}}if(n.size!==0){const o=vd(i,s,n.size);t.push(...Array.from(n.values()).sort(kr).map((a,l)=>({...a,index:o[l]})))}}function S6(n,e){const t=tt(Array.from(e).map(i=>{const s=n.getShapePageBounds(i);return s?{shape:i,bounds:s}:null}));return i=>{const s=n.getShapePageBounds(i);return s?t.some(o=>o.bounds.includes(s)):!1}}function Zne(n,e,t,r,i){const s=S6(n,e),o=t.length;if(e.size===o)return;let a={name:"skipping"};for(let l=0;l<o;l++){const u=e.has(t[l]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:l};break}case"selecting":{if(u||!i?.considerAllShapes&&!s(t[l]))continue;const{selectIndex:f}=a;vd(t[l].index,t[l+1]?.index,l-f).forEach((h,g)=>{const y=t[f+g];e.has(y)&&r.push({...y,index:h})}),a={name:"skipping"};break}}}}function Jne(n,e,t,r,i){const s=S6(n,e),o=t.length;if(e.size===o)return;let a={name:"skipping"};for(let l=o-1;l>-1;l--){const u=e.has(t[l]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:l};break}case"selecting":{if(u||!i?.considerAllShapes&&!s(t[l]))continue;vd(t[l-1]?.index,t[l].index,a.selectIndex-l).forEach((f,h)=>{const g=t[l+h+1];e.has(g)&&r.push({...g,index:f})}),a={name:"skipping"};break}}}}function b6({editor:n,ids:e}){const t=tt(e.map(o=>n.getShape(o))),r=n.getShapesSharedRotation(e),i=n.getShapesRotatedPageBounds(e);if(!i)return null;const s=i.center.clone().rotWith(i.point,r);return{initialPageCenter:s,initialCursorAngle:s.angle(n.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:t.map(o=>({shape:o,initialPagePoint:n.getShapePageTransform(o.id).point()}))}}function Ob({delta:n,editor:e,snapshot:t,stage:r,centerOverride:i}){const{initialPageCenter:s,shapeSnapshots:o}=t;e.updateShapes(o.map(({shape:l,initialPagePoint:u})=>{const f=$i(l.parentId)?e.getShapePageTransform(l.parentId):xe.Identity(),h=I.RotWith(u,i??s,n),g=xe.applyToPoint(xe.Inverse(f),h),y=ox(l.rotation+n);return{id:l.id,type:l.type,x:g.x,y:g.y,rotation:y}}));const a=[];o.forEach(({shape:l})=>{const u=e.getShape(l.id);if(!u)return;const f=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const g=f.onRotateStart?.(l);g&&a.push(g)}const h=f.onRotate?.(l,u);if(h&&a.push(h),r==="end"||r==="one-off"){const g=f.onRotateEnd?.(l,u);g&&a.push(g)}}),a.length>0&&e.updateShapes(a)}function j3(n){const e=n.get(),t=new Map;for(const r of e){const{fromId:i,toId:s}=r,o=t.get(i);o?o.push(r):t.set(i,[r]);const a=t.get(s);a?a.push(r):t.set(s,[r])}return t}const Qne=n=>{const{store:e}=n,t=e.query.filterHistory("binding"),r=e.query.records("binding");return pe("arrowBindingsIndex",(i,s)=>{if(pd(i))return j3(r);const o=i,a=t.getDiffSince(s);if(a===eo)return j3(r);let l;function u(g){l??=new Map(o);const b=l.get(g.fromId)?.filter(x=>x.id!==g.id);b?.length?l.set(g.fromId,b):l.delete(g.fromId);const w=l.get(g.toId)?.filter(x=>x.id!==g.id);w?.length?l.set(g.toId,w):l.delete(g.toId)}function f(g){l??=new Map(o);let y=l.get(g);return y?y===o.get(g)&&(y=y.slice(0),l.set(g,y)):(y=[],l.set(g,y)),y}function h(g){f(g.fromId).push(g),f(g.toId).push(g)}for(const g of a){for(const y of Hn(g.added))h(y);for(const[y,b]of Hn(g.updated))u(y),h(b);for(const y of Hn(g.removed))u(y)}return l??o})};function ere(n){const e=n.getCurrentPageShapeIds(),t=n.getViewportPageBounds(),r=new Set;return e.forEach(i=>{const s=n.getShape(i);if(!s||!n.getShapeUtil(s.type).canCull(s))return;const a=n.getShapePageBounds(i);(a===void 0||!t.includes(a))&&r.add(i)}),r}function tre(n){return pe("notVisibleShapes",function(t){const r=ere(n);if(pd(t)||t.size!==r.size)return r;for(const i of t)if(!r.has(i))return r;return t})}function L3(n,e){const t={},r=n.get(),i=Array(r.size);return r.forEach(s=>i.push(e.get(s))),i.sort(kr),i.forEach(s=>{t[s.parentId]||(t[s.parentId]=[]),t[s.parentId].push(s.id)}),t}const nre=n=>{const e=n.query.ids("shape"),t=n.query.filterHistory("shape");return pe("parentsToChildrenWithIndexes",(r,i)=>{if(pd(r))return L3(e,n);const s=t.getDiffSince(i);if(s===eo)return L3(e,n);if(s.length===0)return r;let o=null;const a=f=>{o||(o={...r}),o[f]?o[f]===r[f]&&(o[f]=[...o[f]]):o[f]=[]},l=new Set;let u;for(let f=0,h=s.length;f<h;f++){u=s[f];for(const g of Object.values(u.added))hf(g)&&(a(g.parentId),o[g.parentId].push(g.id),l.add(o[g.parentId]));for(const[g,y]of Object.values(u.updated))if(hf(y)&&hf(g)){if(g.parentId!==y.parentId)a(g.parentId),a(y.parentId),o[g.parentId].splice(o[g.parentId].indexOf(y.id),1),o[y.parentId].push(y.id),l.add(o[y.parentId]);else if(g.index!==y.index){a(y.parentId);const b=o[y.parentId].indexOf(y.id);o[y.parentId][b]=y.id,l.add(o[y.parentId])}}for(const g of Object.values(u.removed))hf(g)&&(a(g.parentId),o[g.parentId].splice(o[g.parentId].indexOf(g.id),1))}for(const f of l){const h=tt(f.map(g=>n.get(g)));h.sort(kr),f.splice(0,f.length,...h.map(g=>g.id))}return o??r})},IE=(n,e,t)=>{for(;!Yr(t.parentId);){const r=n.get(t.parentId);if(!r)return!1;t=r}return t.parentId===e},rre=(n,e)=>{const t=n.query.ids("shape");let r=null;function i(){const s=e();return r=s,new Set([...t.get()].filter(o=>IE(n,s,n.get(o))))}return pe("_shapeIdsInCurrentPage",(s,o)=>{if(pd(s))return i();const a=e();if(a!==r)return i();const l=n.history.getDiffSince(o);if(l===eo)return i();const u=new Ib(s);for(const h of l){for(const g of Object.values(h.added))hf(g)&&IE(n,a,g)&&u.add(g.id);for(const[g,y]of Object.values(h.updated))hf(y)&&(IE(n,a,y)?u.add(y.id):u.remove(y.id));for(const g of Object.keys(h.removed))$i(g)&&u.remove(g)}const f=u.get();return f?wg(f.value,f.diff):s})};var ire=Object.create,x6=Object.defineProperty,sre=Object.getOwnPropertyDescriptor,ore=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),v6=n=>{throw TypeError(n)},w6=(n,e,t)=>e in n?x6(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,are=n=>[,,,ire(null)],C6=["class","method","getter","setter","accessor","field","value","get","set"],T6=n=>n!==void 0&&typeof n!="function"?v6("Function expected"):n,lre=(n,e,t,r,i)=>({kind:C6[n],name:e,metadata:r,addInitializer:s=>t._?v6("Already initialized"):i.push(T6(s||null))}),cre=(n,e)=>w6(e,ore("metadata"),n[3]),ure=(n,e,t,r)=>{for(var i=0,s=n[e>>1],o=s&&s.length;i<o;i++)s[i].call(t);return r},E6=(n,e,t,r,i,s)=>{for(var o,a,l,u,f=e&7,h=!1,g=!1,y=2,b=C6[f+5],v=n[y]||(n[y]=[]),w=(i=i.prototype,sre(i,t)),x=r.length-1;x>=0;x--)l=lre(f,t,a={},n[3],v),l.static=h,l.private=g,u=l.access={has:T=>t in T},u.get=T=>T[t],o=(0,r[x])(w[b],l),a._=1,T6(o)&&(w[b]=o);return w&&x6(i,t,w),i},Fh=(n,e,t)=>w6(n,typeof e!="symbol"?e+"":e,t),_6,P6,iy;const dre=40;P6=[Is],_6=[Is];class Uv{constructor(e){this.editor=e,ure(iy,5,this),Fh(this,"_clickId",""),Fh(this,"_clickTimeout"),Fh(this,"_clickScreenPoint"),Fh(this,"_previousScreenPoint"),Fh(this,"_clickState","idle"),Fh(this,"lastPointerInfo",{})}_getClickTimeout(e,t=zt()){this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===e&&this._clickId===t){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"}},e==="idle"||e==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)}get clickState(){return this._clickState}handlePointerEvent(e){switch(e.name){case"pointer_down":{if(!this._clickState)return e;switch(this._clickScreenPoint=I.From(e.point),this._previousScreenPoint&&I.Dist2(this._previousScreenPoint,this._clickScreenPoint)>dre**2&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=e,this._clickState){case"pendingDouble":return this._clickState="pendingTriple",this._clickTimeout=this._getClickTimeout(this._clickState),{...e,type:"click",name:"double_click",phase:"down"};case"pendingTriple":return this._clickState="pendingQuadruple",this._clickTimeout=this._getClickTimeout(this._clickState),{...e,type:"click",name:"triple_click",phase:"down"};case"pendingQuadruple":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...e,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),e}case"pointer_up":{if(!this._clickState)return e;switch(this._clickScreenPoint=I.From(e.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 e}case"pointer_move":return this._clickState!=="idle"&&this._clickScreenPoint&&I.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout(),e}return e}cancelDoubleClickTimeout(){this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"}}iy=are();E6(iy,1,"_getClickTimeout",P6,Uv);E6(iy,1,"cancelDoubleClickTimeout",_6,Uv);cre(iy,Uv);class hre{constructor(e){this.editor=e}_isEdgeScrolling=!1;_edgeScrollDuration=-1;updateEdgeScrolling(e){const{editor:t}=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+=e,this._edgeScrollDuration>t.options.edgeScrollDelay){const i=t.options.edgeScrollEaseDuration>0?Ti.easeInCubic(Math.min(1,this._edgeScrollDuration/(t.options.edgeScrollDelay+t.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*i,y:r.y*i})}}getEdgeProximityFactors(e,t,r,i,s){const{editor:o}=this,a=o.options.edgeScrollDistance,l=r?o.options.coarsePointerWidth:0,u=e-l,f=e+l,h=i?0:a,g=s?t:t-a;return u<h?Math.min(1,(h-u)/a):f>g?-Math.min(1,(f-g)/a):0}getEdgeScroll(){const{editor:e}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=e,i=e.getViewportScreenBounds(),{isCoarsePointer:s,insets:[o,a,l,u]}=e.getInstanceState(),f=this.getEdgeProximityFactors(t,i.w,s,u,a),h=this.getEdgeProximityFactors(r,i.h,s,o,l);return{x:f,y:h}}moveCameraWhenCloseToEdge(e){const{editor:t}=this;if(!t.inputs.isDragging||t.inputs.isPanning||t.getCameraOptions().isLocked||e.x===0&&e.y===0)return;const r=t.getViewportScreenBounds(),i=r.w<1e3?.612:1,s=r.h<1e3?.612:1,o=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,l=a*e.x*i/o,u=a*e.y*s/o,{x:f,y:h,z:g}=t.getCamera();t.setCamera(new I(f+l,h+u,g))}}class fre{constructor(e,t){this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(i,s)=>{i.isFocused!==s.isFocused&&this.updateContainerClass()});const r=e.getInstanceState().isFocused;t!==r&&e.updateInstanceState({isFocused:!!t}),this.updateContainerClass(),document.body.addEventListener("keydown",this.handleKeyDown.bind(this)),document.body.addEventListener("mousedown",this.handleMouseDown.bind(this))}disposeSideEffectListener;updateContainerClass(){const e=this.editor.getContainer();this.editor.getInstanceState().isFocused?e.classList.add("tl-container__focused"):e.classList.remove("tl-container__focused"),e.classList.add("tl-container__no-focus-ring")}handleKeyDown(e){const t=this.editor.getContainer(),r=document.activeElement;this.editor.isIn("select.editing_shape")&&!r?.closest(".tlui-contextual-toolbar")||r===t&&this.editor.getSelectedShapeIds().length>0||["Tab","ArrowUp","ArrowDown"].includes(e.key)&&t.classList.remove("tl-container__no-focus-ring")}handleMouseDown(){this.editor.getContainer().classList.add("tl-container__no-focus-ring")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){document.body.removeEventListener("keydown",this.handleKeyDown.bind(this)),document.body.removeEventListener("mousedown",this.handleMouseDown.bind(this)),this.disposeSideEffectListener?.()}}class pre{constructor(e,t){this.editor=e,this.assetUrls=t,this.shapeFontFacesCache=e.store.createComputedCache("shape font faces",r=>this.editor.getShapeUtil(r).getFontFaces(r),{areResultsEqual:qb,areRecordsEqual:(r,i)=>r.props===i.props&&r.meta===i.meta}),this.shapeFontLoadStateCache=e.store.createCache(r=>{const i=pe("font faces",()=>this.getShapeFontFaces(r));return pe("font load state",()=>i.get().map(o=>this.getFontState(o)),{isEqual:qb})})}shapeFontFacesCache;shapeFontLoadStateCache;getShapeFontFaces(e){const t=typeof e=="string"?e:e.id;return this.shapeFontFacesCache.get(t)??qn}trackFontsForShape(e){const t=typeof e=="string"?e:e.id;this.shapeFontLoadStateCache.get(t)}async loadRequiredFontsForCurrentPage(e=1/0){const t=new Set;for(const i of this.editor.getCurrentPageShapeIds())for(const s of this.getShapeFontFaces(this.editor.getShape(i)))t.add(s);if(t.size>e)return;const r=Array.from(t,i=>this.ensureFontIsLoaded(i));await Promise.all(r)}fontStates=new N_("font states");getFontState(e){return this.fontStates.get(e)??null}ensureFontIsLoaded(e){const t=this.getFontState(e);if(t)return t.loadingPromise;const r=this.findOrCreateFontFace(e),i={state:"loading",instance:r,loadingPromise:r.load().then(()=>{document.fonts.add(r),this.fontStates.update(e,s=>({...s,state:"ready"}))}).catch(s=>{console.error(s),this.fontStates.update(e,o=>({...o,state:"error"}))})};return this.fontStates.set(e,i),i.loadingPromise}fontsToLoad=new Set;requestFonts(e){this.fontsToLoad.size||queueMicrotask(()=>{if(this.editor.isDisposed)return;const t=this.fontsToLoad;this.fontsToLoad=new Set,to(()=>{for(const r of t)this.ensureFontIsLoaded(r)})});for(const t of e)this.fontsToLoad.add(t)}findOrCreateFontFace(e){for(const i of document.fonts)if(i.family===e.family&&Yi(N3).every(([s,o])=>i[s]===(e[s]??o)))return i;const t=this.assetUrls?.[e.src.url]??e.src.url,r=new FontFace(e.family,`url(${JSON.stringify(t)})`,{...wu(N3,i=>e[i]),display:"swap"});return document.fonts.add(r),r}async toEmbeddedCssDeclaration(e){const t=this.assetUrls?.[e.src.url]??e.src.url,r=await Ci.urlToDataUrl(t),i=tt([`url("${r}")`,e.src.format?`format(${e.src.format})`:null,e.src.tech?`tech(${e.src.tech})`:null]).join(" ");return tt(["@font-face {",` font-family: "${e.family}";`,e.ascentOverride?` ascent-override: ${e.ascentOverride};`:null,e.descentOverride?` descent-override: ${e.descentOverride};`:null,e.stretch?` font-stretch: ${e.stretch};`:null,e.style?` font-style: ${e.style};`:null,e.weight?` font-weight: ${e.weight};`:null,e.featureSettings?` font-feature-settings: ${e.featureSettings};`:null,e.lineGapOverride?` line-gap-override: ${e.lineGapOverride};`:null,e.unicodeRange?` unicode-range: ${e.unicodeRange};`:null,` src: ${i};`,"}"]).join(`
41
+ ${i}`,n.prepend(s)}}finally{t.dispose()}}let EE=null;function Nne(){return EE||(EE={maxWidth:_E("width"),maxHeight:_E("height"),maxArea:_E("area")}),EE}const D3=8192,zne=4096*4096,Bne={area:[16384,14188,11402,11180,10836,8192,4096],height:[8388607,65535,32767,16384,8192,4096],width:[4194303,65535,32767,16384,8192,4096]};function _E(n){const e=document.createElement("canvas");e.width=1,e.height=1;const t=e.getContext("2d");for(const r of Bne[n]){const i=n==="height"?1:r,s=n==="width"?1:r,o=document.createElement("canvas");o.width=i,o.height=s,o.getContext("2d").fillRect(i-1,s-1,1,1),t.drawImage(o,i-1,s-1,1,1,0,0,1,1);const l=t.getImageData(0,0,1,1).data[3]!==0;if(o.width=0,o.height=0,l)return e.width=0,e.height=0,n==="area"?r*r:r}throw e.width=0,e.height=0,Error("Failed to determine maximum canvas dimension")}function Fne(n,e){if(n<=D3&&e<=D3&&n*e<=zne)return[n,e];const{maxWidth:t,maxHeight:r,maxArea:i}=Nne(),s=n/e;if(n>t&&(n=t,e=n/s),e>r&&(e=r,n=e*s),n*e>i){const o=Math.sqrt(i/(n*e));n*=o,e*=o}return[n,e]}async function Une(n,e){const{type:t,width:r,height:i,quality:s=1,pixelRatio:o=2}=e;let[a,l]=Fne(r*o,i*o);a=Math.floor(a),l=Math.floor(l);const u=a/r,f=await Ci.blobToDataUrl(new Blob([n],{type:"image/svg+xml"})),h=await new Promise(y=>{const b=am();b.crossOrigin="anonymous",b.onload=async()=>{Nt.isSafari&&await D_(250);const v=document.createElement("canvas"),w=v.getContext("2d");v.width=a,v.height=l,w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(b,0,0,a,l),URL.revokeObjectURL(f),y(v)},b.onerror=()=>{y(null)},b.src=f});if(!h)return null;const g=await new Promise(y=>h.toBlob(b=>{(!b||In.throwToBlob.get())&&y(null),y(b)},"image/"+t,s));if(!g)return null;if(t==="png"){const y=new DataView(await g.arrayBuffer());return La.setPhysChunk(y,u,{type:"image/"+t})}else return g}const qi={menus:bn("open menus",[]),getOpenMenus(n){return n?this.menus.get().filter(e=>e.endsWith("-"+n)):this.menus.get()},addOpenMenu(n,e=""){const t=e?`${n}-${e}`:n,r=new Set(this.menus.get());r.has(t)||(r.add(t),this.menus.set([...r]))},deleteOpenMenu(n,e=""){const t=e?`${n}-${e}`:n,r=new Set(this.menus.get());r.has(t)&&(r.delete(t),this.menus.set([...r]))},clearOpenMenus(n){this.menus.set(n?this.menus.get().filter(e=>!e.endsWith("-"+n)):[])},_hiddenMenus:[],hideOpenMenus(n){if(this._hiddenMenus=[...this.getOpenMenus(n)],this._hiddenMenus.length!==0)for(const e of this._hiddenMenus)this.deleteOpenMenu(e,n)},showOpenMenus(n){if(this._hiddenMenus.length!==0){for(const e of this._hiddenMenus)this.addOpenMenu(e,n);this._hiddenMenus=[]}},isMenuOpen(n,e){return this.getOpenMenus(e).includes(n)},hasOpenMenus(n){return this.getOpenMenus(n).length>0},hasAnyOpenMenus(){return this.getOpenMenus().length>0},forContext(n){return{getOpenMenus:()=>this.getOpenMenus(n),addOpenMenu:e=>this.addOpenMenu(e,n),deleteOpenMenu:e=>this.deleteOpenMenu(e,n),clearOpenMenus:()=>this.clearOpenMenus(n),isMenuOpen:e=>this.isMenuOpen(e,n),hasOpenMenus:()=>this.hasOpenMenus(n),hasAnyOpenMenus:()=>this.hasAnyOpenMenus()}}},dx=new TZ,Hne={maxShapesPerPage:4e3,maxFilesAtOnce:100,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,uiDragDistanceSquared:16,uiCoarseDragDistanceSquared:625,defaultSvgPadding:32,cameraSlideFriction:.09,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,laserDelayMs:1200,maxExportDelayMs:5e3,tooltipDelayMs:700,temporaryAssetPreviewLifetimeMs:18e4,actionShortcutsLocation:"swap",createTextOnCanvasDoubleClick:!0,exportProvider:E.Fragment,enableToolbarKeyboardShortcuts:!0,maxFontsToLoadBeforeRender:1/0,nonce:void 0};function R3(n,e){if(!e)return!1;switch(n.type){case"mixed":return e.type==="mixed";case"shared":return e.type==="shared"&&n.value===e.value;default:throw kt(n)}}class $ne{map;constructor(e){this.map=new Map(e)}get(e){return this.map.get(e)}getAsKnownValue(e){const t=this.get(e);if(t&&t.type!=="mixed")return t.value}get size(){return this.map.size}equals(e){if(this.size!==e.size)return!1;const t=new Set;for(const[r,i]of this){if(!R3(i,e.get(r)))return!1;t.add(r)}for(const[r,i]of e)if(!t.has(r)&&!R3(i,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 J_ extends $ne{set(e,t){this.map.set(e,t)}applyValue(e,t){const r=this.get(e);if(!r){this.set(e,{type:"shared",value:t});return}switch(r.type){case"mixed":return;case"shared":r.value!==t&&this.set(e,{type:"mixed"});return;default:kt(r,"type")}}}function Kne(n,e,t){return Gl(n).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:t})})}const qne="https://cdn.tldraw.com";function fr(){return`${qne}/${d2}`}function Vne(n){switch(n.type){case"shapes":return`s${n.shapeIds.map(t=>PE(t.slice(6))).join(".")}`;case"page":return"p"+PE(Wi.parseId(n.pageId));case"viewport":{const{bounds:e,pageId:t}=n;let r=`v${Math.round(e.x)}.${Math.round(e.y)}.${Math.round(e.w)}.${Math.round(e.h)}`;return t&&(r+="."+PE(Wi.parseId(t))),r}default:kt(n)}}function Gne(n){switch(n[0]){case"s":return{type:"shapes",shapeIds:n.slice(1).split(".").filter(Boolean).map(r=>Zt(decodeURIComponent(r)))};case"p":return{type:"page",pageId:Wi.createId(decodeURIComponent(n.slice(1)))};case"v":{const[t,r,i,s,o]=n.slice(1).split(".");return{type:"viewport",bounds:new we(Number(t),Number(r),Number(i),Number(s)),pageId:o?Wi.createId(decodeURIComponent(o)):void 0}}default:throw Error("Invalid deep link string")}}function PE(n){return encodeURIComponent(n).replace(/\./g,"%2E")}function Yne(n,e){let t=n;const r=new Set(e);for(;r.has(t);)t=/^.*(\d+)$/.exec(t)?.[1]?t.replace(/(\d+)(?=\D?)$/,i=>(+i+1).toString()):`${t} 1`;return t}function FS(n,e,t,r){if(t.length===0)return[];const i=new Map;for(const o of tt(t.map(a=>n.getShape(a)))){const{parentId:a}=o;i.has(a)||i.set(a,{children:tt(n.getSortedChildIdsForParent(a).map(l=>n.getShape(l))),moving:new Set}),i.get(a).moving.add(o)}const s=[];switch(e){case"toBack":{i.forEach(({moving:o,children:a})=>Wne(o,a,s));break}case"toFront":{i.forEach(({moving:o,children:a})=>Xne(o,a,s));break}case"forward":{i.forEach(({moving:o,children:a})=>Zne(n,o,a,s,r));break}case"backward":{i.forEach(({moving:o,children:a})=>Jne(n,o,a,s,r));break}}return s}function Wne(n,e,t){const r=e.length;if(n.size===r)return;let i,s;for(let o=0;o<r;o++){const a=e[o];if(n.has(a))i=a.index,n.delete(a);else{s=a.index;break}}if(n.size!==0){const o=vd(i,s,n.size);t.push(...Array.from(n.values()).sort(kr).map((a,l)=>({...a,index:o[l]})))}}function Xne(n,e,t){const r=e.length;if(n.size===r)return;let i,s;for(let o=r-1;o>-1;o--){const a=e[o];if(n.has(a))s=a.index,n.delete(a);else{i=a.index;break}}if(n.size!==0){const o=vd(i,s,n.size);t.push(...Array.from(n.values()).sort(kr).map((a,l)=>({...a,index:o[l]})))}}function S6(n,e){const t=tt(Array.from(e).map(i=>{const s=n.getShapePageBounds(i);return s?{shape:i,bounds:s}:null}));return i=>{const s=n.getShapePageBounds(i);return s?t.some(o=>o.bounds.includes(s)):!1}}function Zne(n,e,t,r,i){const s=S6(n,e),o=t.length;if(e.size===o)return;let a={name:"skipping"};for(let l=0;l<o;l++){const u=e.has(t[l]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:l};break}case"selecting":{if(u||!i?.considerAllShapes&&!s(t[l]))continue;const{selectIndex:f}=a;vd(t[l].index,t[l+1]?.index,l-f).forEach((h,g)=>{const y=t[f+g];e.has(y)&&r.push({...y,index:h})}),a={name:"skipping"};break}}}}function Jne(n,e,t,r,i){const s=S6(n,e),o=t.length;if(e.size===o)return;let a={name:"skipping"};for(let l=o-1;l>-1;l--){const u=e.has(t[l]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:l};break}case"selecting":{if(u||!i?.considerAllShapes&&!s(t[l]))continue;vd(t[l-1]?.index,t[l].index,a.selectIndex-l).forEach((f,h)=>{const g=t[l+h+1];e.has(g)&&r.push({...g,index:f})}),a={name:"skipping"};break}}}}function b6({editor:n,ids:e}){const t=tt(e.map(o=>n.getShape(o))),r=n.getShapesSharedRotation(e),i=n.getShapesRotatedPageBounds(e);if(!i)return null;const s=i.center.clone().rotWith(i.point,r);return{initialPageCenter:s,initialCursorAngle:s.angle(n.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:t.map(o=>({shape:o,initialPagePoint:n.getShapePageTransform(o.id).point()}))}}function Ob({delta:n,editor:e,snapshot:t,stage:r,centerOverride:i}){const{initialPageCenter:s,shapeSnapshots:o}=t;e.updateShapes(o.map(({shape:l,initialPagePoint:u})=>{const f=$i(l.parentId)?e.getShapePageTransform(l.parentId):xe.Identity(),h=I.RotWith(u,i??s,n),g=xe.applyToPoint(xe.Inverse(f),h),y=ox(l.rotation+n);return{id:l.id,type:l.type,x:g.x,y:g.y,rotation:y}}));const a=[];o.forEach(({shape:l})=>{const u=e.getShape(l.id);if(!u)return;const f=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const g=f.onRotateStart?.(l);g&&a.push(g)}const h=f.onRotate?.(l,u);if(h&&a.push(h),r==="end"||r==="one-off"){const g=f.onRotateEnd?.(l,u);g&&a.push(g)}}),a.length>0&&e.updateShapes(a)}function j3(n){const e=n.get(),t=new Map;for(const r of e){const{fromId:i,toId:s}=r,o=t.get(i);o?o.push(r):t.set(i,[r]);const a=t.get(s);a?a.push(r):t.set(s,[r])}return t}const Qne=n=>{const{store:e}=n,t=e.query.filterHistory("binding"),r=e.query.records("binding");return pe("arrowBindingsIndex",(i,s)=>{if(pd(i))return j3(r);const o=i,a=t.getDiffSince(s);if(a===eo)return j3(r);let l;function u(g){l??=new Map(o);const b=l.get(g.fromId)?.filter(x=>x.id!==g.id);b?.length?l.set(g.fromId,b):l.delete(g.fromId);const w=l.get(g.toId)?.filter(x=>x.id!==g.id);w?.length?l.set(g.toId,w):l.delete(g.toId)}function f(g){l??=new Map(o);let y=l.get(g);return y?y===o.get(g)&&(y=y.slice(0),l.set(g,y)):(y=[],l.set(g,y)),y}function h(g){f(g.fromId).push(g),f(g.toId).push(g)}for(const g of a){for(const y of Hn(g.added))h(y);for(const[y,b]of Hn(g.updated))u(y),h(b);for(const y of Hn(g.removed))u(y)}return l??o})};function ere(n){const e=n.getCurrentPageShapeIds(),t=n.getViewportPageBounds(),r=new Set;return e.forEach(i=>{const s=n.getShape(i);if(!s||!n.getShapeUtil(s.type).canCull(s))return;const a=n.getShapePageBounds(i);(a===void 0||!t.includes(a))&&r.add(i)}),r}function tre(n){return pe("notVisibleShapes",function(t){const r=ere(n);if(pd(t)||t.size!==r.size)return r;for(const i of t)if(!r.has(i))return r;return t})}function L3(n,e){const t={},r=n.get(),i=Array(r.size);return r.forEach(s=>i.push(e.get(s))),i.sort(kr),i.forEach(s=>{t[s.parentId]||(t[s.parentId]=[]),t[s.parentId].push(s.id)}),t}const nre=n=>{const e=n.query.ids("shape"),t=n.query.filterHistory("shape");return pe("parentsToChildrenWithIndexes",(r,i)=>{if(pd(r))return L3(e,n);const s=t.getDiffSince(i);if(s===eo)return L3(e,n);if(s.length===0)return r;let o=null;const a=f=>{o||(o={...r}),o[f]?o[f]===r[f]&&(o[f]=[...o[f]]):o[f]=[]},l=new Set;let u;for(let f=0,h=s.length;f<h;f++){u=s[f];for(const g of Object.values(u.added))hf(g)&&(a(g.parentId),o[g.parentId].push(g.id),l.add(o[g.parentId]));for(const[g,y]of Object.values(u.updated))if(hf(y)&&hf(g)){if(g.parentId!==y.parentId)a(g.parentId),a(y.parentId),o[g.parentId].splice(o[g.parentId].indexOf(y.id),1),o[y.parentId].push(y.id),l.add(o[y.parentId]);else if(g.index!==y.index){a(y.parentId);const b=o[y.parentId].indexOf(y.id);o[y.parentId][b]=y.id,l.add(o[y.parentId])}}for(const g of Object.values(u.removed))hf(g)&&(a(g.parentId),o[g.parentId].splice(o[g.parentId].indexOf(g.id),1))}for(const f of l){const h=tt(f.map(g=>n.get(g)));h.sort(kr),f.splice(0,f.length,...h.map(g=>g.id))}return o??r})},IE=(n,e,t)=>{for(;!Yr(t.parentId);){const r=n.get(t.parentId);if(!r)return!1;t=r}return t.parentId===e},rre=(n,e)=>{const t=n.query.ids("shape");let r=null;function i(){const s=e();return r=s,new Set([...t.get()].filter(o=>IE(n,s,n.get(o))))}return pe("_shapeIdsInCurrentPage",(s,o)=>{if(pd(s))return i();const a=e();if(a!==r)return i();const l=n.history.getDiffSince(o);if(l===eo)return i();const u=new Ib(s);for(const h of l){for(const g of Object.values(h.added))hf(g)&&IE(n,a,g)&&u.add(g.id);for(const[g,y]of Object.values(h.updated))hf(y)&&(IE(n,a,y)?u.add(y.id):u.remove(y.id));for(const g of Object.keys(h.removed))$i(g)&&u.remove(g)}const f=u.get();return f?wg(f.value,f.diff):s})};var ire=Object.create,x6=Object.defineProperty,sre=Object.getOwnPropertyDescriptor,ore=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),v6=n=>{throw TypeError(n)},w6=(n,e,t)=>e in n?x6(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,are=n=>[,,,ire(null)],C6=["class","method","getter","setter","accessor","field","value","get","set"],T6=n=>n!==void 0&&typeof n!="function"?v6("Function expected"):n,lre=(n,e,t,r,i)=>({kind:C6[n],name:e,metadata:r,addInitializer:s=>t._?v6("Already initialized"):i.push(T6(s||null))}),cre=(n,e)=>w6(e,ore("metadata"),n[3]),ure=(n,e,t,r)=>{for(var i=0,s=n[e>>1],o=s&&s.length;i<o;i++)s[i].call(t);return r},E6=(n,e,t,r,i,s)=>{for(var o,a,l,u,f=e&7,h=!1,g=!1,y=2,b=C6[f+5],v=n[y]||(n[y]=[]),w=(i=i.prototype,sre(i,t)),x=r.length-1;x>=0;x--)l=lre(f,t,a={},n[3],v),l.static=h,l.private=g,u=l.access={has:T=>t in T},u.get=T=>T[t],o=(0,r[x])(w[b],l),a._=1,T6(o)&&(w[b]=o);return w&&x6(i,t,w),i},Fh=(n,e,t)=>w6(n,typeof e!="symbol"?e+"":e,t),_6,P6,iy;const dre=40;P6=[Is],_6=[Is];class Uv{constructor(e){this.editor=e,ure(iy,5,this),Fh(this,"_clickId",""),Fh(this,"_clickTimeout"),Fh(this,"_clickScreenPoint"),Fh(this,"_previousScreenPoint"),Fh(this,"_clickState","idle"),Fh(this,"lastPointerInfo",{})}_getClickTimeout(e,t=zt()){this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===e&&this._clickId===t){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"}},e==="idle"||e==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)}get clickState(){return this._clickState}handlePointerEvent(e){switch(e.name){case"pointer_down":{if(!this._clickState)return e;switch(this._clickScreenPoint=I.From(e.point),this._previousScreenPoint&&I.Dist2(this._previousScreenPoint,this._clickScreenPoint)>dre**2&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=e,this._clickState){case"pendingDouble":return this._clickState="pendingTriple",this._clickTimeout=this._getClickTimeout(this._clickState),{...e,type:"click",name:"double_click",phase:"down"};case"pendingTriple":return this._clickState="pendingQuadruple",this._clickTimeout=this._getClickTimeout(this._clickState),{...e,type:"click",name:"triple_click",phase:"down"};case"pendingQuadruple":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...e,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),e}case"pointer_up":{if(!this._clickState)return e;switch(this._clickScreenPoint=I.From(e.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 e}case"pointer_move":return this._clickState!=="idle"&&this._clickScreenPoint&&I.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout(),e}return e}cancelDoubleClickTimeout(){this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"}}iy=are();E6(iy,1,"_getClickTimeout",P6,Uv);E6(iy,1,"cancelDoubleClickTimeout",_6,Uv);cre(iy,Uv);class hre{constructor(e){this.editor=e}_isEdgeScrolling=!1;_edgeScrollDuration=-1;updateEdgeScrolling(e){const{editor:t}=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+=e,this._edgeScrollDuration>t.options.edgeScrollDelay){const i=t.options.edgeScrollEaseDuration>0?Ti.easeInCubic(Math.min(1,this._edgeScrollDuration/(t.options.edgeScrollDelay+t.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*i,y:r.y*i})}}getEdgeProximityFactors(e,t,r,i,s){const{editor:o}=this,a=o.options.edgeScrollDistance,l=r?o.options.coarsePointerWidth:0,u=e-l,f=e+l,h=i?0:a,g=s?t:t-a;return u<h?Math.min(1,(h-u)/a):f>g?-Math.min(1,(f-g)/a):0}getEdgeScroll(){const{editor:e}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=e,i=e.getViewportScreenBounds(),{isCoarsePointer:s,insets:[o,a,l,u]}=e.getInstanceState(),f=this.getEdgeProximityFactors(t,i.w,s,u,a),h=this.getEdgeProximityFactors(r,i.h,s,o,l);return{x:f,y:h}}moveCameraWhenCloseToEdge(e){const{editor:t}=this;if(!t.inputs.isDragging||t.inputs.isPanning||t.getCameraOptions().isLocked||e.x===0&&e.y===0)return;const r=t.getViewportScreenBounds(),i=r.w<1e3?.612:1,s=r.h<1e3?.612:1,o=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,l=a*e.x*i/o,u=a*e.y*s/o,{x:f,y:h,z:g}=t.getCamera();t.setCamera(new I(f+l,h+u,g))}}class fre{constructor(e,t){this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(i,s)=>{i.isFocused!==s.isFocused&&this.updateContainerClass()});const r=e.getInstanceState().isFocused;t!==r&&e.updateInstanceState({isFocused:!!t}),this.updateContainerClass(),document.body.addEventListener("keydown",this.handleKeyDown.bind(this)),document.body.addEventListener("mousedown",this.handleMouseDown.bind(this))}disposeSideEffectListener;updateContainerClass(){const e=this.editor.getContainer();this.editor.getInstanceState().isFocused?e.classList.add("tl-container__focused"):e.classList.remove("tl-container__focused"),e.classList.add("tl-container__no-focus-ring")}handleKeyDown(e){const t=this.editor.getContainer(),r=document.activeElement;this.editor.isIn("select.editing_shape")&&!r?.closest(".tlui-contextual-toolbar")||r===t&&this.editor.getSelectedShapeIds().length>0||["Tab","ArrowUp","ArrowDown"].includes(e.key)&&t.classList.remove("tl-container__no-focus-ring")}handleMouseDown(){this.editor.getContainer().classList.add("tl-container__no-focus-ring")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){document.body.removeEventListener("keydown",this.handleKeyDown.bind(this)),document.body.removeEventListener("mousedown",this.handleMouseDown.bind(this)),this.disposeSideEffectListener?.()}}class pre{constructor(e,t){this.editor=e,this.assetUrls=t,this.shapeFontFacesCache=e.store.createComputedCache("shape font faces",r=>this.editor.getShapeUtil(r).getFontFaces(r),{areResultsEqual:qb,areRecordsEqual:(r,i)=>r.props===i.props&&r.meta===i.meta}),this.shapeFontLoadStateCache=e.store.createCache(r=>{const i=pe("font faces",()=>this.getShapeFontFaces(r));return pe("font load state",()=>i.get().map(o=>this.getFontState(o)),{isEqual:qb})})}shapeFontFacesCache;shapeFontLoadStateCache;getShapeFontFaces(e){const t=typeof e=="string"?e:e.id;return this.shapeFontFacesCache.get(t)??qn}trackFontsForShape(e){const t=typeof e=="string"?e:e.id;this.shapeFontLoadStateCache.get(t)}async loadRequiredFontsForCurrentPage(e=1/0){const t=new Set;for(const i of this.editor.getCurrentPageShapeIds())for(const s of this.getShapeFontFaces(this.editor.getShape(i)))t.add(s);if(t.size>e)return;const r=Array.from(t,i=>this.ensureFontIsLoaded(i));await Promise.all(r)}fontStates=new N_("font states");getFontState(e){return this.fontStates.get(e)??null}ensureFontIsLoaded(e){const t=this.getFontState(e);if(t)return t.loadingPromise;const r=this.findOrCreateFontFace(e),i={state:"loading",instance:r,loadingPromise:r.load().then(()=>{document.fonts.add(r),this.fontStates.update(e,s=>({...s,state:"ready"}))}).catch(s=>{console.error(s),this.fontStates.update(e,o=>({...o,state:"error"}))})};return this.fontStates.set(e,i),i.loadingPromise}fontsToLoad=new Set;requestFonts(e){this.fontsToLoad.size||queueMicrotask(()=>{if(this.editor.isDisposed)return;const t=this.fontsToLoad;this.fontsToLoad=new Set,to(()=>{for(const r of t)this.ensureFontIsLoaded(r)})});for(const t of e)this.fontsToLoad.add(t)}findOrCreateFontFace(e){for(const i of document.fonts)if(i.family===e.family&&Yi(N3).every(([s,o])=>i[s]===(e[s]??o)))return i;const t=this.assetUrls?.[e.src.url]??e.src.url,r=new FontFace(e.family,`url(${JSON.stringify(t)})`,{...wu(N3,i=>e[i]),display:"swap"});return document.fonts.add(r),r}async toEmbeddedCssDeclaration(e){const t=this.assetUrls?.[e.src.url]??e.src.url,r=await Ci.urlToDataUrl(t),i=tt([`url("${r}")`,e.src.format?`format(${e.src.format})`:null,e.src.tech?`tech(${e.src.tech})`:null]).join(" ");return tt(["@font-face {",` font-family: "${e.family}";`,e.ascentOverride?` ascent-override: ${e.ascentOverride};`:null,e.descentOverride?` descent-override: ${e.descentOverride};`:null,e.stretch?` font-stretch: ${e.stretch};`:null,e.style?` font-style: ${e.style};`:null,e.weight?` font-weight: ${e.weight};`:null,e.featureSettings?` font-feature-settings: ${e.featureSettings};`:null,e.lineGapOverride?` line-gap-override: ${e.lineGapOverride};`:null,e.unicodeRange?` unicode-range: ${e.unicodeRange};`:null,` src: ${i};`,"}"]).join(`
120
42
  `)}}const N3={style:"normal",weight:"normal",stretch:"normal",unicodeRange:"U+0-10FFFF",featureSettings:"normal",ascentOverride:"normal",descentOverride:"normal",lineGapOverride:"normal"};class gre{store;dispose;state="recording";pendingDiff=new yre;stacks=bn("HistoryManager.stacks",{undos:cg(),redos:cg()},{isEqual:(e,t)=>e.undos===t.undos&&e.redos===t.redos});annotateError;constructor(e){this.store=e.store,this.annotateError=e.annotateError??om,this.dispose=this.store.addHistoryInterceptor((t,r)=>{if(r==="user")switch(this.state){case"recording":this.pendingDiff.apply(t.changes),this.stacks.update(({undos:i})=>({undos:i,redos:cg()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:kt(this.state)}})}flushPendingDiff(){if(this.pendingDiff.isEmpty())return;const e=this.pendingDiff.clear();this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"diff",diff:e}),redos:r}))}getNumUndos(){return this.stacks.get().undos.length+(this.pendingDiff.isEmpty()?0:1)}getNumRedos(){return this.stacks.get().redos.length}_isInBatch=!1;batch(e,t){const r=this.state;r!=="paused"&&t?.history&&(this.state=mre[t.history]);try{if(this._isInBatch)return to(e),this;this._isInBatch=!0;try{to(e)}catch(i){throw this.annotateError(i),i}finally{this._isInBatch=!1}return this}finally{this.state=r}}_undo({pushToRedoStack:e,toMark:t=void 0}){const r=this.state;this.state="paused";try{let{undos:i,redos:s}=this.stacks.get();const o=this.pendingDiff.clear(),a=D4(o),l=z_(o);e&&!a&&(s=s.push({type:"diff",diff:o}));let u=!1;if(a)for(;i.head?.type==="stop";){const f=i.head;if(i=i.tail,e&&(s=s.push(f)),f.id===t){u=!0;break}}if(!u)e:for(;i.head;){const f=i.head;switch(i=i.tail,e&&(s=s.push(f)),f.type){case"diff":$g(l,[z_(f.diff)]);break;case"stop":if(!t)break e;if(f.id===t){u=!0;break e}break;default:kt(f)}}if(!u&&t)return this;this.store.applyDiff(l,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:i,redos:s})}finally{this.state=r}return this}undo(){return this._undo({pushToRedoStack:!0}),this}redo(){const e=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:t,redos:r}=this.stacks.get();if(r.length===0)return this;for(;r.head?.type==="stop";)t=t.push(r.head),r=r.tail;const i=Zb();for(;r.head;){const s=r.head;if(t=t.push(s),r=r.tail,s.type==="diff")$g(i,[s.diff]);else break}this.store.applyDiff(i,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:t,redos:r})}finally{this.state=e}return this}bail(){return this._undo({pushToRedoStack:!1}),this}bailToMark(e){return e&&this._undo({pushToRedoStack:!1,toMark:e}),this}squashToMark(e){let t=this.stacks.get().undos;const r=[];for(;t.head&&!(t.head.type==="stop"&&t.head.id===e);)t.head.type==="diff"&&r.push(t.head.diff),t=t.tail;if(!t.head||t.head?.id!==e)return console.error("Could not find mark to squash to: ",e),this;if(r.length===0)return this;const i=Zb();return $g(i,r.reverse()),this.stacks.update(({redos:s})=>({undos:t.push({type:"diff",diff:i}),redos:s})),this}_mark(e){to(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:cg(),redos:cg()}),this.pendingDiff.clear()}getMarkIdMatching(e){let t=this.stacks.get().undos;for(;t.head;){if(t.head.type==="stop"&&t.head.id.includes(e))return t.head.id;t=t.tail}return null}debug(){const{undos:e,redos:t}=this.stacks.get();return{undos:e.toArray(),redos:t.toArray(),pendingDiff:this.pendingDiff.debug(),state:this.state}}}const mre={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class yre{diff=Zb();isEmptyAtom=bn("PendingDiff.isEmpty",!0);clear(){const e=this.diff;return this.diff=Zb(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){$g(this.diff,[e]),this.isEmptyAtom.set(D4(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}function cg(n){return bre}class Sre{length=0;head=null;tail=this;push(e){return new v2(e,this)}toArray(){return qn}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const bre=new Sre;class v2{constructor(e,t){this.head=e,this.tail=t,this.length=t.length+1}length;push(e){return new v2(e,this)}toArray(){return Array.from(this)}[Symbol.iterator](){let e=this;return{next(){if(e.length){const t=e.head;return e=e.tail,{value:t,done:!1}}else return{value:void 0,done:!0}}}}}class xre{constructor(e){this.editor=e}scribbleItems=new Map;state="paused";addScribble(e,t=zt()){const r={id:t,scribble:{id:t,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...e,state:"starting"},timeoutMs:0,delayRemaining:e.delay??0,prev:null,next:null};return this.scribbleItems.set(t,r),r}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}stop(e){const t=this.scribbleItems.get(e);if(!t)throw Error(`Scribble with id ${e} not found`);return t.delayRemaining=Math.min(t.delayRemaining,200),t.scribble.state="stopping",t}addPoint(e,t,r,i=.5){const s=this.scribbleItems.get(e);if(!s)throw Error(`Scribble with id ${e} not found`);const{prev:o}=s,a={x:t,y:r,z:i};return(!o||I.Dist(o,a)>=1)&&(s.next=a),s}tick(e){this.scribbleItems.size!==0&&this.editor.run(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next:l,prev:u}=t;l&&l!==u&&(t.prev=l,t.scribble.points.push(l)),t.scribble.points.length>8&&(t.scribble.state="active");return}t.delayRemaining>0&&(t.delayRemaining=Math.max(0,t.delayRemaining-e)),t.timeoutMs+=e,t.timeoutMs>=16&&(t.timeoutMs=0);const{delayRemaining:r,timeoutMs:i,prev:s,next:o,scribble:a}=t;switch(a.state){case"active":{o&&o!==s?(t.prev=o,a.points.push(o),r===0&&a.points.length>8&&a.points.shift()):i===0&&(a.points.length>1?a.points.shift():t.delayRemaining=a.delay);break}case"stopping":{if(t.delayRemaining===0&&i===0){if(a.points.length===1){this.scribbleItems.delete(t.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:t})=>({...t,points:[...t.points]})).slice(-5)})})}}var vre=Object.create,I6=Object.defineProperty,wre=Object.getOwnPropertyDescriptor,Cre=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),M6=n=>{throw TypeError(n)},k6=(n,e,t)=>e in n?I6(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Tre=n=>[,,,vre(null)],A6=["class","method","getter","setter","accessor","field","value","get","set"],O6=n=>n!==void 0&&typeof n!="function"?M6("Function expected"):n,Ere=(n,e,t,r,i)=>({kind:A6[n],name:e,metadata:r,addInitializer:s=>t._?M6("Already initialized"):i.push(O6(s||null))}),_re=(n,e)=>k6(e,Cre("metadata"),n[3]),Pre=(n,e,t,r)=>{for(var i=0,s=n[e>>1],o=s&&s.length;i<o;i++)s[i].call(t);return r},Hv=(n,e,t,r,i,s)=>{for(var o,a,l,u,f=e&7,h=!1,g=!1,y=2,b=A6[f+5],v=n[y]||(n[y]=[]),w=(i=i.prototype,wre(i,t)),x=r.length-1;x>=0;x--)l=Ere(f,t,a={},n[3],v),l.static=h,l.private=g,u=l.access={has:T=>t in T},u.get=T=>T[t],o=(0,r[x])(w[b],l),a._=1,O6(o)&&(w[b]=o);return w&&I6(i,t,w),i},Ire=(n,e,t)=>k6(n,e+"",t),D6,R6,j6,L6,Yd;const Je=n=>Math.round(n*10**8)/10**8;function zl(n,e,t,r,i){const s=n.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&Je(a.length)===Je(t)&&sa(a.breadthIntersection[0],a.breadthIntersection[1],i[0],i[1]));if(s.length===0)return[];const o=new Set;return s.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!o.has(l)){o.add(l);const u=zl(n,l,t,r,sa(a.breadthIntersection[0],a.breadthIntersection[1],i[0],i[1]));s.push(...u)}}),s}function Mre(n){n.sort((e,t)=>t.gaps.length-e.gaps.length);for(let e=n.length-1;e>0;e--){const t=n[e];for(let r=e-1;r>=0;r--){const i=n[r];if(i.direction===t.direction&&t.gaps.every(s=>i.gaps.some(o=>Je(s.startEdge[0].x)===Je(o.startEdge[0].x)&&Je(s.startEdge[0].y)===Je(o.startEdge[0].y)&&Je(s.startEdge[1].x)===Je(o.startEdge[1].x)&&Je(s.startEdge[1].y)===Je(o.startEdge[1].y))&&i.gaps.some(o=>Je(s.endEdge[0].x)===Je(o.endEdge[0].x)&&Je(s.endEdge[0].y)===Je(o.endEdge[0].y)&&Je(s.endEdge[1].x)===Je(o.endEdge[1].x)&&Je(s.endEdge[1].y)===Je(o.endEdge[1].y)))){n.splice(e,1);break}}}}L6=[pe],j6=[pe],R6=[pe],D6=[pe];class Qf{constructor(e){this.manager=e,Pre(Yd,5,this),Ire(this,"editor"),this.editor=e.editor}getSnapPointsCache(){const{editor:e}=this;return e.store.createComputedCache("snapPoints",t=>{const r=e.getShapePageTransform(t.id);if(!r)return;const s=e.getShapeUtil(t).getBoundsSnapGeometry(t).points??e.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!s))return s.map((o,a)=>{const{x:l,y:u}=xe.applyToPoint(r,o);return{x:l,y:u,id:`${t.id}:${a}`}})})}getSnapPoints(e){return this.getSnapPointsCache().get(e)??[]}getSnappablePoints(){const e=this.getSnapPointsCache(),t=this.manager.getSnappableShapes(),r=[];for(const i of t){const s=e.get(i);s&&r.push(...s)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:Mr(this.editor.getShapePageBounds(e))}))}getVisibleGaps(){const e=[],t=[];let r,i;const s=this.getSnappableGapNodes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<s.length;a++){r=s[a];for(let l=a+1;l<s.length;l++)i=s[l],r.pageBounds.maxX<i.pageBounds.minX&&ag(r.pageBounds.minY,r.pageBounds.maxY,i.pageBounds.minY,i.pageBounds.maxY)&&e.push({startNode:r,endNode:i,startEdge:[new I(r.pageBounds.maxX,r.pageBounds.minY),new I(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new I(i.pageBounds.minX,i.pageBounds.minY),new I(i.pageBounds.minX,i.pageBounds.maxY)],length:i.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:sa(r.pageBounds.minY,r.pageBounds.maxY,i.pageBounds.minY,i.pageBounds.maxY)})}const o=s.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<o.length;a++){r=o[a];for(let l=a+1;l<o.length;l++)i=o[l],r.pageBounds.maxY<i.pageBounds.minY&&ag(r.pageBounds.minX,r.pageBounds.maxX,i.pageBounds.minX,i.pageBounds.maxX)&&t.push({startNode:r,endNode:i,startEdge:[new I(r.pageBounds.minX,r.pageBounds.maxY),new I(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new I(i.pageBounds.minX,i.pageBounds.minY),new I(i.pageBounds.maxX,i.pageBounds.minY)],length:i.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:sa(r.pageBounds.minX,r.pageBounds.maxX,i.pageBounds.minX,i.pageBounds.maxX)})}return{horizontal:e,vertical:t}}snapTranslateShapes({lockedAxis:e,initialSelectionPageBounds:t,initialSelectionSnapPoints:r,dragDelta:i}){const s=this.manager.getSnapThreshold(),o=this.getSnappablePoints(),a=t.clone().translate(i),l=r.map(({x:w,y:x},T)=>({id:"selection:"+T,x:w+i.x,y:x+i.y})),u=o,f=[],h=[],g=new I(s,s);this.collectPointSnaps({minOffset:g,nearestSnapsX:f,nearestSnapsY:h,otherNodeSnapPoints:u,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:f,nearestSnapsY:h,minOffset:g});const y=new I(e==="x"?0:f[0]?.nudge??0,e==="y"?0:h[0]?.nudge??0);g.x=0,g.y=0,f.length=0,h.length=0,l.forEach(w=>{w.x+=y.x,w.y+=y.y}),a.translate(y),this.collectPointSnaps({minOffset:g,nearestSnapsX:f,nearestSnapsY:h,otherNodeSnapPoints:u,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:f,nearestSnapsY:h,minOffset:g});const b=this.getPointSnapLines({nearestSnapsX:f,nearestSnapsY:h}),v=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:f,nearestSnapsY:h});return this.manager.setIndicators([...v,...b]),{nudge:y}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:t,handle:r,isAspectRatioLocked:i,isResizingFromCenter:s}){const o=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:u}=we.Resize(e,r,s?t.x*2:t.x,s?t.y*2:t.y,i);let f=r;l<0&&(f=jte(f)),u<0&&(f=Rte(f)),s&&(a.center=e.center);const h=f==="top"||f==="bottom",g=f==="left"||f==="right",y=z3(f,a),b=this.getSnappablePoints(),v=[],w=[],x=new I(o,o);this.collectPointSnaps({minOffset:x,nearestSnapsX:v,nearestSnapsY:w,otherNodeSnapPoints:b,selectionSnapPoints:y});const T=new I(h?0:v[0]?.nudge??0,g?0:w[0]?.nudge??0);if(i&&Lte(f)&&T.len()!==0){const O=v.length&&w.length?Math.abs(T.x)<Math.abs(T.y)?"x":"y":v.length?"x":"y",R=e.aspectRatio;O==="x"?(w.length=0,T.y=T.x/R,(f==="bottom_left"||f==="top_right")&&(T.y=-T.y)):(v.length=0,T.x=T.y*R,(f==="bottom_left"||f==="top_right")&&(T.x=-T.x))}const P=I.Add(t,T),{box:M}=we.Resize(e,r,s?P.x*2:P.x,s?P.y*2:P.y,i);s&&(M.center=e.center);const k=z3("any",M);v.length=0,w.length=0,x.x=0,x.y=0,this.collectPointSnaps({minOffset:x,nearestSnapsX:v,nearestSnapsY:w,otherNodeSnapPoints:b,selectionSnapPoints:k});const A=this.getPointSnapLines({nearestSnapsX:v,nearestSnapsY:w});return this.manager.setIndicators([...A]),{nudge:T}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:i,nearestSnapsY:s}){for(const o of e)for(const a of t){const l=I.Sub(o,a),u=Math.abs(l.x),f=Math.abs(l.y);Je(u)<=Je(r.x)&&(Je(u)<Je(r.x)&&(i.length=0),i.push({type:"points",points:{thisPoint:o,otherPoint:a},nudge:a.x-o.x}),r.x=u),Je(f)<=Je(r.y)&&(Je(f)<Je(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:o,otherPoint:a},nudge:a.y-o.y}),r.y=f)}}collectGapSnaps({selectionPageBounds:e,minOffset:t,nearestSnapsX:r,nearestSnapsY:i}){const{horizontal:s,vertical:o}=this.getVisibleGaps();for(const a of s){if(!ag(a.breadthIntersection[0],a.breadthIntersection[1],e.minY,e.maxY))continue;const u=a.startEdge[0].x+a.length/2-e.center.x;if(a.length>e.width&&Je(Math.abs(u))<=Je(t.x)){Je(Math.abs(u))<Je(t.x)&&(r.length=0),t.x=Math.abs(u);const x={type:"gap_center",gap:a,nudge:u},T=r.find(({type:M})=>M==="gap_center"),P=T&&sa(a.breadthIntersection[0],a.breadthIntersection[1],T.gap.breadthIntersection[0],T.gap.breadthIntersection[1]);T&&T.gap.length>a.length&&P?r[r.indexOf(T)]=x:(!T||!P)&&r.push(x)}const h=a.startNode.pageBounds.minX-a.length,g=e.maxX,y=h-g;Je(Math.abs(y))<=Je(t.x)&&(Je(Math.abs(y))<Je(t.x)&&(r.length=0),t.x=Math.abs(y),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:y}));const b=a.endNode.pageBounds.maxX+a.length,v=e.minX,w=b-v;Je(Math.abs(w))<=Je(t.x)&&(Je(Math.abs(w))<Je(t.x)&&(r.length=0),t.x=Math.abs(w),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:w}))}for(const a of o){if(!ag(a.breadthIntersection[0],a.breadthIntersection[1],e.minX,e.maxX))continue;const u=a.startEdge[0].y+a.length/2-e.center.y;if(a.length>e.height&&Je(Math.abs(u))<=Je(t.y)){Je(Math.abs(u))<Je(t.y)&&(i.length=0),t.y=Math.abs(u);const x={type:"gap_center",gap:a,nudge:u},T=i.find(({type:M})=>M==="gap_center"),P=T&&ag(T.gap.breadthIntersection[0],T.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);T&&T.gap.length>a.length&&P?i[i.indexOf(T)]=x:(!T||!P)&&i.push(x);continue}const h=a.startNode.pageBounds.minY-a.length,g=e.maxY,y=h-g;Je(Math.abs(y))<=Je(t.y)&&(Je(Math.abs(y))<Je(t.y)&&(i.length=0),t.y=Math.abs(y),i.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:y}));const b=a.endNode.pageBounds.maxY+a.length,v=e.minY,w=b-v;Je(Math.abs(w))<=Je(t.y)&&(Je(Math.abs(w))<Je(t.y)&&(i.length=0),t.y=Math.abs(w),i.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:w}))}}getPointSnapLines({nearestSnapsX:e,nearestSnapsY:t}){const r={},i={};if(e.length>0){for(const s of e)if(s.type==="points"){const o=Je(s.points.otherPoint.x);r[o]||(r[o]=[]),r[o].push(s.points)}}if(t.length>0){for(const s of t)if(s.type==="points"){const o=Je(s.points.otherPoint.y);i[o]||(i[o]=[]),i[o].push(s.points)}}return Object.values(r).concat(Object.values(i)).map(s=>({id:zt(),type:"points",points:gI(s.map(o=>I.From(o.otherPoint)).concat(s.map(o=>I.From(o.thisPoint))),(o,a)=>o.equals(a))}))}getGapSnapLines({selectionPageBounds:e,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:i,horizontal:s}=this.getVisibleGaps(),o={top:e.sides[0],right:e.sides[1],bottom:[e.corners[3],e.corners[2]],left:[e.corners[0],e.corners[3]]},a=[];if(t.length>0)for(const l of t){if(l.type==="points")continue;const{gap:{breadthIntersection:u,startEdge:f,startNode:h,endNode:g,length:y,endEdge:b}}=l;switch(l.type){case"gap_center":{const v=(y-e.width)/2,w=sa(u[0],u[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:zt(),gaps:[...zl(s,h.id,v,"backward",w),{startEdge:f,endEdge:o.left},{startEdge:o.right,endEdge:b},...zl(s,g.id,v,"forward",w)]});break}case"gap_duplicate":{const v=sa(u[0],u[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:zt(),gaps:l.protrusionDirection==="left"?[{startEdge:o.right,endEdge:f.map(w=>w.clone().addXY(-h.pageBounds.width,0))},{startEdge:f,endEdge:b},...zl(s,g.id,y,"forward",v)]:[...zl(s,h.id,y,"backward",v),{startEdge:f,endEdge:b},{startEdge:b.map(w=>w.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:o.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:u,startEdge:f,startNode:h,endNode:g,length:y,endEdge:b}}=l;switch(l.type){case"gap_center":{const v=(y-e.height)/2,w=sa(u[0],u[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:zt(),gaps:[...zl(i,h.id,v,"backward",w),{startEdge:f,endEdge:o.top},{startEdge:o.bottom,endEdge:b},...zl(i,l.gap.endNode.id,v,"forward",w)]});break}case"gap_duplicate":{const v=sa(u[0],u[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:zt(),gaps:l.protrusionDirection==="top"?[{startEdge:o.bottom,endEdge:f.map(w=>w.clone().addXY(0,-h.pageBounds.height))},{startEdge:f,endEdge:b},...zl(i,g.id,y,"forward",v)]:[...zl(i,h.id,y,"backward",v),{startEdge:f,endEdge:b},{startEdge:b.map(w=>w.clone().addXY(0,g.pageBounds.height)),endEdge:o.top}]})}break}}return Mre(a),a}}Yd=Tre();Hv(Yd,1,"getSnapPointsCache",L6,Qf);Hv(Yd,1,"getSnappablePoints",j6,Qf);Hv(Yd,1,"getSnappableGapNodes",R6,Qf);Hv(Yd,1,"getVisibleGaps",D6,Qf);_re(Yd,Qf);function z3(n,e){const{minX:t,maxX:r,minY:i,maxY:s}=e,o=[];switch(n){case"top":case"left":case"top_left":case"any":o.push({id:"top_left",handle:"top_left",x:t,y:i})}switch(n){case"top":case"right":case"top_right":case"any":o.push({id:"top_right",handle:"top_right",x:r,y:i})}switch(n){case"bottom":case"right":case"bottom_right":case"any":o.push({id:"bottom_right",handle:"bottom_right",x:r,y:s})}switch(n){case"bottom":case"left":case"bottom_left":case"any":o.push({id:"bottom_left",handle:"bottom_left",x:t,y:s})}return o}var kre=Object.create,N6=Object.defineProperty,Are=Object.getOwnPropertyDescriptor,Ore=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),z6=n=>{throw TypeError(n)},B6=(n,e,t)=>e in n?N6(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Dre=n=>[,,,kre(null)],F6=["class","method","getter","setter","accessor","field","value","get","set"],U6=n=>n!==void 0&&typeof n!="function"?z6("Function expected"):n,Rre=(n,e,t,r,i)=>({kind:F6[n],name:e,metadata:r,addInitializer:s=>t._?z6("Already initialized"):i.push(U6(s||null))}),jre=(n,e)=>B6(e,Ore("metadata"),n[3]),Lre=(n,e,t,r)=>{for(var i=0,s=n[e>>1],o=s&&s.length;i<o;i++)s[i].call(t);return r},Nre=(n,e,t,r,i,s)=>{for(var o,a,l,u,f=e&7,h=!1,g=!1,y=2,b=F6[f+5],v=n[y]||(n[y]=[]),w=(i=i.prototype,Are(i,t)),x=r.length-1;x>=0;x--)l=Rre(f,t,a={},n[3],v),l.static=h,l.private=g,u=l.access={has:T=>t in T},u.get=T=>T[t],o=(0,r[x])(w[b],l),a._=1,U6(o)&&(w[b]=o);return w&&N6(i,t,w),i},zre=(n,e,t)=>B6(n,e+"",t),H6,$v;const Bre=()=>null,Fre=()=>[];H6=[pe];class w2{constructor(e){this.manager=e,Lre($v,5,this),zre(this,"editor"),this.editor=e.editor}getSnapGeometryCache(){const{editor:e}=this;return e.store.createComputedCache("handle snap geometry",t=>{const r=e.getShapeUtil(t).getHandleSnapGeometry(t),i=r.getSelfSnapOutline?r.getSelfSnapOutline.bind(r):Bre,s=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):Fre;return{outline:r.outline===void 0?e.getShapeGeometry(t):r.outline,points:r.points??[],getSelfSnapOutline:i,getSelfSnapPoints:s}})}*iterateSnapPointsInPageSpace(e,t){const r=this.getSnapGeometryCache().get(e)?.getSelfSnapPoints(t);if(r&&r.length){const i=Mr(this.editor.getShapePageTransform(e));for(const s of r)yield i.applyToPoint(s)}for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const s=this.getSnapGeometryCache().get(i)?.points;if(!s||!s.length)continue;const o=Mr(this.editor.getShapePageTransform(i));for(const a of s)yield o.applyToPoint(a)}}*iterateSnapOutlines(e,t){const r=this.getSnapGeometryCache().get(e)?.getSelfSnapOutline(t);r&&(yield{shapeId:e,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const s=this.getSnapGeometryCache().get(i)?.outline;s&&(yield{shapeId:i,outline:s})}}getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:r}){const i=this.manager.getSnapThreshold();let s=i,o=null;for(const u of this.iterateSnapPointsInPageSpace(e,t))I.DistMin(r,u,s)&&(s=I.Dist(r,u),o=u);if(o)return o;let a=i,l=null;for(const{shapeId:u,outline:f}of this.iterateSnapOutlines(e,t)){const h=Mr(this.editor.getShapePageTransform(u)),g=this.editor.getPointInShapeSpace(u,r),y=f.nearestPoint(g),b=h.applyToPoint(y);I.DistMin(r,b,a)&&(a=I.Dist(r,b),l=b)}return l||null}getHandleSnapData({handle:e,currentShapeId:t}){const r=this.manager.getSnapThreshold(),s=Mr(this.editor.getShapePageTransform(t)).applyToPoint(e);let o=null,a=null,l=r,u=r;for(const y of this.iterateSnapPointsInPageSpace(t,e)){const b=Math.abs(s.x-y.x),v=Math.abs(s.y-y.y);b<l&&(l=b,o=y),v<u&&(u=v,a=y)}if(!o&&!a)return null;const f=new I(o?o.x-s.x:0,a?a.y-s.y:0),h=I.Add(s,f),g=[];if(o){const y=new I(o.x,h.y);g.push({id:zt(),type:"points",points:[o,y]})}if(a){const y=new I(h.x,a.y);g.push({id:zt(),type:"points",points:[a,y]})}return{snaps:g,nudge:f}}snapHandle({currentShapeId:e,handle:t}){const i=Mr(this.editor.getShapePageTransform(e)).applyToPoint(t),s=t.canSnap?"point":t.snapType;if(s==="point"){const o=this.getHandleSnapPosition({currentShapeId:e,handle:t,handleInPageSpace:i});return o?(this.manager.setIndicators([{id:zt(),type:"points",points:[o]}]),{nudge:I.Sub(o,i)}):null}if(s==="align"){const o=this.getHandleSnapData({handle:t,currentShapeId:e});return o?(this.manager.setIndicators(o.snaps),{nudge:o.nudge}):null}return null}}$v=Dre();Nre($v,1,"getSnapGeometryCache",H6,w2);jre($v,w2);var Ure=Object.create,$6=Object.defineProperty,Hre=Object.getOwnPropertyDescriptor,$re=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),K6=n=>{throw TypeError(n)},q6=(n,e,t)=>e in n?$6(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Kre=n=>[,,,Ure(null)],V6=["class","method","getter","setter","accessor","field","value","get","set"],G6=n=>n!==void 0&&typeof n!="function"?K6("Function expected"):n,qre=(n,e,t,r,i)=>({kind:V6[n],name:e,metadata:r,addInitializer:s=>t._?K6("Already initialized"):i.push(G6(s||null))}),Vre=(n,e)=>q6(e,$re("metadata"),n[3]),Gre=(n,e,t,r)=>{for(var i=0,s=n[e>>1],o=s&&s.length;i<o;i++)s[i].call(t);return r},C2=(n,e,t,r,i,s)=>{for(var o,a,l,u,f=e&7,h=!1,g=!1,y=2,b=V6[f+5],v=n[y]||(n[y]=[]),w=(i=i.prototype,Hre(i,t)),x=r.length-1;x>=0;x--)l=qre(f,t,a={},n[3],v),l.static=h,l.private=g,u=l.access={has:T=>t in T},u.get=T=>T[t],o=(0,r[x])(w[b],l),a._=1,G6(o)&&(w[b]=o);return w&&$6(i,t,w),i},ME=(n,e,t)=>q6(n,typeof e!="symbol"?e+"":e,t),Y6,W6,X6,ep;X6=[pe],W6=[pe],Y6=[pe];class sy{constructor(e){this.editor=e,Gre(ep,5,this),ME(this,"shapeBounds"),ME(this,"handles"),ME(this,"_snapIndicators",bn("snapLines",void 0)),this.shapeBounds=new Qf(this),this.handles=new w2(this)}getIndicators(){return this._snapIndicators.get()??qn}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(e){this._snapIndicators.set(e)}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:e}=this,t=e.getViewportPageBounds(),r=e.getSelectedShapeIds(),i=new Set,s=o=>{if($i(o)){const l=e.getShape(o);l&&e.isShapeOfType(l,"frame")&&i.add(o)}const a=e.getSortedChildIdsForParent(o);for(const l of a){if(r.includes(l))continue;const u=e.getShape(l);if(!u||!e.getShapeUtil(u).canSnap(u))continue;const h=e.getShapePageBounds(l);if(h&&t.includes(h)){if(e.isShapeOfType(u,"group")){s(l);continue}i.add(l)}}};return s(this.getCurrentCommonAncestor()??e.getCurrentPageId()),i}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}ep=Kre();C2(ep,1,"getSnapThreshold",X6,sy);C2(ep,1,"getSnappableShapes",W6,sy);C2(ep,1,"getCurrentCommonAncestor",Y6,sy);Vre(ep,sy);const Yre=/\r?\n|\r/g;function B3(n){return n.replace(Yre,`
121
43
  `).split(`
122
44
  `).map(e=>e||" ").join(`
@@ -237,11 +159,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
237
159
  opacity: 1;
238
160
  pointer-events: all;
239
161
  }
240
- }`;return m.jsx("style",{nonce:e.options.nonce,children:r})}),xse=[],vse=[],wse=[],Cse="tl-container",Tse=E.memo(function({store:e,components:t,className:r,user:i,options:s,...o}){const[a,l]=E.useState(null),u=E.useMemo(()=>i??NF(),[i]),f=t?.ErrorFallback===void 0?_F:t?.ErrorFallback,h={...o,shapeUtils:o.shapeUtils??xse,bindingUtils:o.bindingUtils??vse,tools:o.tools??wse,components:t,options:Jf(s)};return m.jsx("div",{ref:l,"data-tldraw":d2,draggable:!1,className:Fe(`${Cse} tl-theme__light`,r),tabIndex:-1,role:"application","aria-label":s?.branding??"tldraw",children:m.jsx(hm,{fallback:f,onError:g=>yI(g,{tags:{origin:"react.tldraw-before-app"}}),children:a&&m.jsx(lse,{licenseKey:o.licenseKey,children:m.jsx(TF,{container:a,children:m.jsx(Bse,{overrides:t,children:e?e instanceof GI?m.jsx(i9,{...h,store:e,user:u}):m.jsx(r9,{...h,store:e,user:u}):m.jsx(Ese,{...h,store:e,user:u})})})})})})});function Ese(n){const{defaultName:e,snapshot:t,initialData:r,shapeUtils:i,bindingUtils:s,persistenceKey:o,sessionId:a,user:l,assets:u,migrations:f}=n,h=Zie({shapeUtils:i,bindingUtils:s,initialData:r,persistenceKey:o,sessionId:a,defaultName:e,snapshot:t,assets:u,migrations:f});return m.jsx(r9,{...n,store:h,user:l})}const r9=E.memo(function({store:e,user:t,...r}){const i=or();E.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(i.classList.remove("tl-theme__light"),i.classList.add("tl-theme__dark"))},[i,t]);const{LoadingScreen:s}=on();switch(e.status){case"error":throw e.error;case"loading":return s?m.jsx(s,{}):null}return m.jsx(i9,{...r,store:e.store,user:t})}),DE=()=>document.location.search.includes("tldraw_preserve_focus");function i9({onMount:n,children:e,store:t,tools:r,shapeUtils:i,bindingUtils:s,user:o,initialState:a,autoFocus:l=!0,inferDarkMode:u,cameraOptions:f,textOptions:h,options:g,licenseKey:y,deepLinks:b,getShapeVisibility:v,assetUrls:w}){const{ErrorFallback:x}=on(),T=or(),[P,M]=t9(null),k=E.useRef(null),A=Jf(b===!0?{}:b),O=E.useRef({autoFocus:l&&!DE(),inferDarkMode:u,initialState:a,cameraOptions:f,deepLinks:A});E.useLayoutEffect(()=>{O.current={autoFocus:l&&!DE(),inferDarkMode:u,initialState:a,cameraOptions:f,deepLinks:A}},[l,u,a,f,A]),E.useLayoutEffect(()=>{const{autoFocus:B,inferDarkMode:G,initialState:N,cameraOptions:Y,deepLinks:W}=O.current,Q=new Ae({store:t,shapeUtils:i,bindingUtils:s,tools:r,getContainer:()=>T,user:o,initialState:N,autoFocus:B,inferDarkMode:G,cameraOptions:Y,textOptions:h,options:g,licenseKey:y,getShapeVisibility:v,fontAssetUrls:w?.fonts});return Q.updateViewportScreenBounds(k.current??T),W&&(W?.getUrl?Q.navigateToDeepLink({...W,url:W.getUrl(Q)}):Q.navigateToDeepLink(W)),M(Q),()=>{Q.dispose()}},[s,T,g,i,t,r,o,M,y,v,h,w]),E.useLayoutEffect(()=>{if(P&&A)return P.registerDeepLinkListener(A)},[P,A]),E.useLayoutEffect(()=>{P&&f&&P.setCameraOptions(f)},[P,f]);const R=E.useSyncExternalStore(E.useCallback(B=>P?(P.on("crash",B),()=>P.off("crash",B)):()=>{},[P]),()=>P?.getCrashingError()??null);E.useEffect(function(){if(!P)return;function G(){P&&P.focus()}function N(){P&&P.blur()}if(l&&DE())return P.getContainer().addEventListener("pointerdown",G),document.body.addEventListener("pointerdown",N),()=>{P.getContainer()?.removeEventListener("pointerdown",G),document.body.removeEventListener("pointerdown",N)}},[P,l]);const[F,z]=E.useState(null);let j=F;P!==j?.editor&&(j=null),E.useLayoutEffect(()=>{if(!P)return;if(P.options.maxFontsToLoadBeforeRender===0){z({editor:P,isLoaded:!0});return}let B=!1;return z({editor:P,isLoaded:!1}),P.fonts.loadRequiredFontsForCurrentPage(P.options.maxFontsToLoadBeforeRender).finally(()=>{B||z({editor:P,isLoaded:!0})}),()=>{B=!0}},[P]);const{Canvas:$,LoadingScreen:H}=on();return!P||!j?.isLoaded?m.jsxs(m.Fragment,{children:[H&&m.jsx(H,{}),m.jsx("div",{className:"tl-canvas",ref:k})]}):m.jsx(hm,{fallback:x,onError:B=>P.annotateError(B,{origin:"react.tldraw",willCrashApp:!0}),children:R?m.jsx(Pse,{crashingError:R}):m.jsx(c2,{editor:P,children:m.jsxs(_se,{onMount:n,children:[e??($?m.jsx($,{},P.contextId):null),m.jsx(mse,{})]})})})}function _se({children:n,onMount:e}){return Qie(),Cie(),Tie(),Eie(),Jie(),o9(t=>{const r=t.store.props.onMount(t),i=e?.(t);return()=>{r?.(),i?.()}}),n}function Pse({crashingError:n}){throw n}function s9({children:n}){return m.jsx("div",{className:"tl-loading","aria-busy":"true",tabIndex:0,children:n})}function o9(n){const e=te(),t=ja(r=>{let i;return r.run(()=>{i=n?.(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,i});Ge.useLayoutEffect(()=>{if(e)return t?.(e)},[e,t])}const Ise=()=>{const{Spinner:n}=on();return m.jsx(s9,{children:n?m.jsx(n,{}):null})};function a9(n,e=!0){const t=n.length;if(t<2)return"";let r=n[0],i=n[1];if(t===2)return`M${Jr(r)}L${Jr(i)}`;let s="";for(let o=2,a=t-1;o<a;o++)r=n[o],i=n[o+1],s+=Es(r,i);return e?`M${Es(n[0],n[1])}Q${Jr(n[1])}${Es(n[1],n[2])}T${s}${Es(n[t-1],n[0])}${Es(n[0],n[1])}Z`:`M${Jr(n[0])}Q${Jr(n[1])}${Es(n[1],n[2])}${n.length>3?"T":""}${s}L${Jr(n[t-1])}`}function Q3({scribble:n,zoom:e,color:t,opacity:r,className:i}){return n.points.length?m.jsx("svg",{className:i&&Fe("tl-overlays__item",i),children:m.jsx("path",{className:"tl-scribble",d:a9(n.points,!1),stroke:t??`var(--tl-color-${n.color})`,fill:"none",strokeWidth:8/e,opacity:r??n.opacity})}):null}function Mse({bounds:n,rotation:e}){const t=te(),r=E.useRef(null),i=ee("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=i?t.getShapeUtil(i).expandSelectionOutlinePx(i):0;return Zm(r,n?.x,n?.y,1,e,{x:-s,y:-s}),n=s instanceof we?n.clone().expand(s).zeroFix():n.clone().expandBy(s).zeroFix(),m.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:m.jsx("rect",{className:Fe("tl-selection__fg__outline"),width:Z(n.width),height:Z(n.height)})})}const kse=()=>m.jsx("div",{className:"tl-shape-error-boundary"}),Ase=E.memo(({shape:n,util:e})=>Cv("Indicator: "+n.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(n.id))),(n,e)=>n.shape.props===e.shape.props&&n.shape.meta===e.shape.meta),Ose=E.memo(({editor:n,id:e})=>{const t=ee("shape for indicator",()=>n.store.get(e),[n,e]),{ShapeIndicatorErrorFallback:r}=on();return!t||t.isLocked?null:m.jsx(hm,{fallback:r,onError:i=>n.annotateError(i,{origin:"react.shapeIndicator",willCrashApp:!1}),children:m.jsx(Ase,{shape:t,util:n.getShapeUtil(t)},t.id)})}),eN=E.memo(function({shapeId:e,className:t,color:r,hidden:i,opacity:s}){const o=te(),a=E.useRef(null);return wd("indicator transform",()=>{if(i)return;const l=a.current;if(!l)return;const u=o.getShapePageTransform(e);u&&l.style.setProperty("transform",u.toCssString())},[o,e,i]),E.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",i?"none":"block")},[i]),m.jsx("svg",{ref:a,className:Fe("tl-overlays__item",t),"aria-hidden":"true",children:m.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--tl-color-selected)",opacity:s,children:m.jsx(Ose,{editor:o,id:e})})})}),Dse=()=>m.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),l9=E.memo(function({hideAll:e,showAll:t}){const r=te();if(e&&t)throw Error("You cannot set both hideAll and showAll props to true, cmon now");const i=E.useRef(new Set),s=ee("should display selected ids",()=>{const l=i.current,u=new Set,f=r.getInstanceState(),h=f.isChangingStyle,g=r.isInAny("select.idle","select.editing_shape"),y=r.isInAny("select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","select.pointing_handle");if(h||!(g||y))return i.current=u,u;for(const b of r.getSelectedShapeIds())u.add(b);if(g&&f.isHoveringCanvas&&!f.isCoarsePointer){const b=r.getHoveredShapeId();b&&u.add(b)}if(l.size!==u.size)return i.current=u,u;for(const b of u)if(!l.has(b))return i.current=u,u;return l},[r]),o=ee("rendering shapes",()=>r.getRenderingShapes(),[r]),{ShapeIndicator:a}=on();return a?o.map(({id:l})=>m.jsx(a,{shapeId:l,hidden:!t&&(e||!s.has(l))},l+"_indicator")):null}),Rse=E.forwardRef(function({children:e,shape:t,isBackground:r,...i},s){const o="fill"in t.props&&t.props.fill!=="none";return m.jsx("div",{ref:s,"data-shape-type":t.type,"data-shape-is-filled":r?void 0:o,"data-shape-id":t.id,draggable:!1,...i,className:Fe("tl-shape",r&&"tl-shape-background",i.className),children:e})});function jse({points:n,zoom:e}){const t=2.5/e,r=n.reduce((g,y)=>Math.min(g,y.x),1/0),i=n.reduce((g,y)=>Math.max(g,y.x),-1/0),s=n.reduce((g,y)=>Math.min(g,y.y),1/0),o=n.reduce((g,y)=>Math.max(g,y.y),-1/0),a=n.some(g=>g.x===r&&g.y===s);let l,u,f,h;return a?(l=r,u=s,f=i,h=o):(l=r,u=o,f=i,h=s),m.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[m.jsx("line",{x1:l,y1:u,x2:f,y2:h}),n.map((g,y)=>m.jsx("g",{transform:`translate(${g.x},${g.y})`,children:m.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},y))]})}function Lse({gaps:n,direction:e,zoom:t}){const r=3.5/t;let i=[-1/0,1/0],s=null;const o=e==="horizontal";for(const l of n){if(s=sa(i[0],i[1],o?l.startEdge[0].y:l.startEdge[0].x,o?l.startEdge[1].y:l.startEdge[1].x),s)i=s;else continue;if(s=sa(i[0],i[1],o?l.endEdge[0].y:l.endEdge[0].x,o?l.endEdge[1].y:l.endEdge[1].x),s)i=s;else continue}if(i===null)return null;const a=(i[0]+i[1])/2;return m.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:n.map(({startEdge:l,endEdge:u},f)=>m.jsx(E.Fragment,{children:o?m.jsxs(m.Fragment,{children:[m.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),m.jsx("line",{x1:u[0].x,y1:a-2*r,x2:u[1].x,y2:a+2*r}),m.jsx("line",{x1:l[0].x,y1:a,x2:u[0].x,y2:a}),m.jsx("line",{x1:(l[0].x+u[0].x)/2,y1:a-r,x2:(l[0].x+u[0].x)/2,y2:a+r})]}):m.jsxs(m.Fragment,{children:[m.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),m.jsx("line",{x1:a-2*r,y1:u[0].y,x2:a+2*r,y2:u[1].y}),m.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:u[0].y}),m.jsx("line",{x1:a-r,y1:(l[0].y+u[0].y)/2,x2:a+r,y2:(l[0].y+u[0].y)/2})]})},f))})}function Nse({className:n,line:e,zoom:t}){return m.jsx("svg",{className:Fe("tl-overlays__item",n),"aria-hidden":"true",children:e.type==="points"?m.jsx(jse,{...e,zoom:t}):e.type==="gaps"?m.jsx(Lse,{...e,zoom:t}):null})}function c9(n){return m.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16","aria-hidden":"false",...n,className:Fe("tl-spinner",n.className),children:m.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[m.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),m.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor"})]})})}const zse=()=>null,u9=E.createContext(null);function Bse({overrides:n={},children:e}){const t=Jf(n),r=E.useMemo(()=>({Background:Vee,Brush:yE,Canvas:tae,CollaboratorBrush:yE,CollaboratorCursor:v3,CollaboratorHint:dte,CollaboratorScribble:Q3,CollaboratorShapeIndicator:eN,Cursor:v3,Grid:gte,Handle:mte,Handles:yte,InFrontOfTheCanvas:null,LoadingScreen:Ise,OnTheCanvas:null,Overlays:null,Scribble:Q3,SelectionBackground:null,SelectionForeground:Mse,ShapeIndicator:eN,ShapeIndicators:l9,ShapeWrapper:Rse,SnapIndicator:Nse,Spinner:c9,SvgDefs:zse,ZoomBrush:yE,ErrorFallback:_F,ShapeErrorFallback:kse,ShapeIndicatorErrorFallback:Dse,...t}),[t]);return m.jsx(u9.Provider,{value:r,children:e})}function on(){const n=E.useContext(u9);if(!n)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return n}const Fse=["textarea","input"];function Use(n){const e=te();E.useEffect(()=>{const t=n.current;if(!t)return;const r=i=>{if(i instanceof PointerEvent&&i.pointerType==="pen"){e.markEventAsHandled(i);const{target:s}=i;if(Fse.includes(s.tagName?.toLocaleLowerCase())||s.isContentEditable||e.isIn("select.editing_shape"))return;nt(i)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[e,n])}function Hse(n,e,t){return Math.max(e,Math.min(n,t))}const ni={toVector(n,e){return n===void 0&&(n=e),Array.isArray(n)?n:[n,n]},add(n,e){return[n[0]+e[0],n[1]+e[1]]},sub(n,e){return[n[0]-e[0],n[1]-e[1]]},addTo(n,e){n[0]+=e[0],n[1]+=e[1]},subTo(n,e){n[0]-=e[0],n[1]-=e[1]}};function tN(n,e,t){return e===0||Math.abs(e)===1/0?Math.pow(n,t*5):n*e*t/(e+t*n)}function nN(n,e,t,r=.15){return r===0?Hse(n,e,t):n<e?-tN(e-n,t-e,r)+e:n>t?+tN(n-t,t-e,r)+t:n}function $se(n,[e,t],[r,i]){const[[s,o],[a,l]]=n;return[nN(e,s,o,r),nN(t,a,l,i)]}function Kse(n,e){if(typeof n!="object"||n===null)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var r=t.call(n,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(n)}function qse(n){var e=Kse(n,"string");return typeof e=="symbol"?e:String(e)}function wi(n,e,t){return e=qse(e),e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function rN(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(n,i).enumerable})),t.push.apply(t,r)}return t}function On(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?rN(Object(t),!0).forEach(function(r){wi(n,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):rN(Object(t)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))})}return n}const d9={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 iN(n){return n?n[0].toUpperCase()+n.slice(1):""}const Vse=["enter","leave"];function Gse(n=!1,e){return n&&!Vse.includes(e)}function Yse(n,e="",t=!1){const r=d9[n],i=r&&r[e]||e;return"on"+iN(n)+iN(i)+(Gse(t,i)?"Capture":"")}const Wse=["gotpointercapture","lostpointercapture"];function Xse(n){let e=n.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const r=Wse.includes(e)?"capturecapture":"capture",i=!!~e.indexOf(r);return i&&(e=e.replace("capture","")),{device:e,capture:i,passive:t}}function Zse(n,e=""){const t=d9[n],r=t&&t[e]||e;return n+r}function h9(n){return"touches"in n}function Jse(n){return h9(n)?"touch":"pointerType"in n?n.pointerType:"mouse"}function Qse(n){return Array.from(n.touches).filter(e=>{var t,r;return e.target===n.currentTarget||((t=n.currentTarget)===null||t===void 0||(r=t.contains)===null||r===void 0?void 0:r.call(t,e.target))})}function rP(n,e){try{const t=e.clientX-n.clientX,r=e.clientY-n.clientY,i=(e.clientX+n.clientX)/2,s=(e.clientY+n.clientY)/2,o=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:o,origin:[i,s]}}catch{}return null}function eoe(n){return Qse(n).map(e=>e.identifier)}function sN(n,e){const[t,r]=Array.from(n.touches).filter(i=>e.includes(i.identifier));return rP(t,r)}const oN=40,aN=800;function f9(n){let{deltaX:e,deltaY:t,deltaMode:r}=n;return r===1?(e*=oN,t*=oN):r===2&&(e*=aN,t*=aN),[e,t]}function toe(n){const e={};if("buttons"in n&&(e.buttons=n.buttons),"shiftKey"in n){const{shiftKey:t,altKey:r,metaKey:i,ctrlKey:s}=n;Object.assign(e,{shiftKey:t,altKey:r,metaKey:i,ctrlKey:s})}return e}function hx(n,...e){return typeof n=="function"?n(...e):n}function noe(){}function roe(...n){return n.length===0?noe:n.length===1?n[0]:function(){let e;for(const t of n)e=t.apply(this,arguments)||e;return e}}function lN(n,e){return Object.assign({},e,n||{})}const ioe=32;class p9{constructor(e,t,r){this.ctrl=e,this.args=t,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(e){this.ctrl.state[this.key]=e}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:e,shared:t,ingKey:r,args:i}=this;t[r]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=i,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const t=this.state,r=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=r.from?hx(r.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:r,shared:i}=this;t.args=this.args;let s=0;if(e&&(t.event=e,r.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,i.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,i.locked=!!document.pointerLockElement,Object.assign(i,toe(e)),i.down=i.pressed=i.buttons%2===1||i.touches>0,s=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const A=t._delta.map(Math.abs);ni.addTo(t._distance,A)}this.axisIntent&&this.axisIntent(e);const[o,a]=t._movement,[l,u]=r.threshold,{_step:f,values:h}=t;if(r.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(o)>=l&&h[0]),f[1]===!1&&(f[1]=Math.abs(a)>=u&&h[1])):(f[0]===!1&&(f[0]=Math.abs(o)>=l&&Math.sign(o)*l),f[1]===!1&&(f[1]=Math.abs(a)>=u&&Math.sign(a)*u)),t.intentional=f[0]!==!1||f[1]!==!1,!t.intentional)return;const g=[0,0];if(r.hasCustomTransform){const[A,O]=h;g[0]=f[0]!==!1?A-f[0]:0,g[1]=f[1]!==!1?O-f[1]:0}else g[0]=f[0]!==!1?o-f[0]:0,g[1]=f[1]!==!1?a-f[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(g);const y=t.offset,b=t._active&&!t._blocked||t.active;b&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=i[this.ingKey]=t._active,e&&(t.first&&("bounds"in r&&(t._bounds=hx(r.bounds,t)),this.setup&&this.setup()),t.movement=g,this.computeOffset()));const[v,w]=t.offset,[[x,T],[P,M]]=t._bounds;t.overflow=[v<x?-1:v>T?1:0,w<P?-1:w>M?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const k=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=$se(t._bounds,t.offset,k),t.delta=ni.sub(t.offset,y),this.computeMovement(),b&&(!t.last||s>ioe)){t.delta=ni.sub(t.offset,y);const A=t.delta.map(Math.abs);ni.addTo(t.distance,A),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&s>0&&(t.velocity=[A[0]/s,A[1]/s],t.timeDelta=s)}}emit(){const e=this.state,t=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const i=this.handler(On(On(On({},t),e),{},{[this.aliasKey]:e.values}));i!==void 0&&(e.memo=i)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function soe([n,e],t){const r=Math.abs(n),i=Math.abs(e);if(r>i&&r>t)return"x";if(i>r&&i>t)return"y"}class ooe extends p9{constructor(...e){super(...e),wi(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=ni.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=ni.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,r=this.config;if(!t.axis&&e){const i=typeof r.axisThreshold=="object"?r.axisThreshold[Jse(e)]:r.axisThreshold;t.axis=soe(t._movement,i)}t._blocked=(r.lockDirection||!!r.axis)&&!t.axis||!!r.axis&&r.axis!==t.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const aoe=n=>n,cN=.15,g9={enabled(n=!0){return n},eventOptions(n,e,t){return On(On({},t.shared.eventOptions),n)},preventDefault(n=!1){return n},triggerAllEvents(n=!1){return n},rubberband(n=0){switch(n){case!0:return[cN,cN];case!1:return[0,0];default:return ni.toVector(n)}},from(n){if(typeof n=="function")return n;if(n!=null)return ni.toVector(n)},transform(n,e,t){const r=n||t.shared.transform;return this.hasCustomTransform=!!r,r||aoe},threshold(n){return ni.toVector(n,0)}},loe=0,ay=On(On({},g9),{},{axis(n,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(n=loe){return n},bounds(n={}){if(typeof n=="function")return s=>ay.bounds(n(s));if("current"in n)return()=>n.current;if(typeof HTMLElement=="function"&&n instanceof HTMLElement)return n;const{left:e=-1/0,right:t=1/0,top:r=-1/0,bottom:i=1/0}=n;return[[e,t],[r,i]]}}),ly=typeof window<"u"&&window.document&&window.document.createElement;function m9(){return ly&&"ontouchstart"in window}function coe(){return m9()||ly&&window.navigator.maxTouchPoints>1}function uoe(){return ly&&"onpointerdown"in window}function doe(){return ly&&"exitPointerLock"in window.document}function hoe(){try{return"constructor"in GestureEvent}catch{return!1}}const Ro={isBrowser:ly,gesture:hoe(),touch:m9(),touchscreen:coe(),pointer:uoe(),pointerLock:doe()},foe=250,poe=180,goe=.5,moe=50,yoe=250,Soe=10,uN={mouse:0,touch:0,pen:8};On(On({},ay),{},{device(n,e,{pointer:{touch:t=!1,lock:r=!1,mouse:i=!1}={}}){return this.pointerLock=r&&Ro.pointerLock,Ro.touch&&t?"touch":this.pointerLock?"mouse":Ro.pointer&&!i?"pointer":Ro.touch?"touch":"mouse"},preventScrollAxis(n,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&n?foe:void 0,!(!Ro.touchscreen||t===!1))return n||(t!==void 0?"y":void 0)},pointerCapture(n,e,{pointer:{capture:t=!0,buttons:r=1,keys:i=!0}={}}){return this.pointerButtons=r,this.keys=i,!this.pointerLock&&this.device==="pointer"&&t},threshold(n,e,{filterTaps:t=!1,tapsThreshold:r=3,axis:i=void 0}){const s=ni.toVector(n,t?r:i?1:0);return this.filterTaps=t,this.tapsThreshold=r,s},swipe({velocity:n=goe,distance:e=moe,duration:t=yoe}={}){return{velocity:this.transform(ni.toVector(n)),distance:this.transform(ni.toVector(e)),duration:t}},delay(n=0){switch(n){case!0:return poe;case!1:return 0;default:return n}},axisThreshold(n){return n?On(On({},uN),n):uN},keyboardDisplacement(n=Soe){return n}});function y9(n){const[e,t]=n.overflow,[r,i]=n._delta,[s,o]=n._direction;(e<0&&r>0&&s<0||e>0&&r<0&&s>0)&&(n._movement[0]=n._movementBound[0]),(t<0&&i>0&&o<0||t>0&&i<0&&o>0)&&(n._movement[1]=n._movementBound[1])}const boe=30,xoe=100;class voe extends p9{constructor(...e){super(...e),wi(this,"ingKey","pinching"),wi(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const e=this.state;e._touchIds=[],e.canceled=!1,e.cancel=this.cancel.bind(this),e.turns=0}computeOffset(){const{type:e,movement:t,lastOffset:r}=this.state;e==="wheel"?this.state.offset=ni.add(t,r):this.state.offset=[(1+t[0])*r[0],t[1]+r[1]]}computeMovement(){const{offset:e,lastOffset:t}=this.state;this.state.movement=[e[0]/t[0],e[1]-t[1]]}axisIntent(){const e=this.state,[t,r]=e._movement;if(!e.axis){const i=Math.abs(t)*boe-Math.abs(r);i<0?e.axis="angle":i>0&&(e.axis="scale")}}restrictToAxis(e){this.config.lockDirection&&(this.state.axis==="scale"?e[1]=0:this.state.axis==="angle"&&(e[0]=0))}cancel(){const e=this.state;e.canceled||setTimeout(()=>{e.canceled=!0,e._active=!1,this.compute(),this.emit()},0)}touchStart(e){this.ctrl.setEventIds(e);const t=this.state,r=this.ctrl.touchIds;if(t._active&&t._touchIds.every(s=>r.has(s))||r.size<2)return;this.start(e),t._touchIds=Array.from(r).slice(0,2);const i=sN(e,t._touchIds);i&&this.pinchStart(e,i)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const t=this.state,r=t._pointerEvents,i=this.ctrl.pointerIds;if(t._active&&Array.from(r.keys()).every(o=>i.has(o))||(r.size<2&&r.set(e.pointerId,e),t._pointerEvents.size<2))return;this.start(e);const s=rP(...Array.from(r.values()));s&&this.pinchStart(e,s)}pinchStart(e,t){const r=this.state;r.origin=t.origin,this.computeValues([t.distance,t.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const t=sN(e,this.state._touchIds);t&&this.pinchMove(e,t)}pointerMove(e){const t=this.state._pointerEvents;if(t.has(e.pointerId)&&t.set(e.pointerId,e),!this.state._active)return;const r=rP(...Array.from(t.values()));r&&this.pinchMove(e,r)}pinchMove(e,t){const r=this.state,i=r._values[1],s=t.angle-i;let o=0;Math.abs(s)>270&&(o+=Math.sign(s)),this.computeValues([t.distance,t.angle-360*o]),r.origin=t.origin,r.turns=o,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const t=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}t._pointerEvents.has(e.pointerId)&&t._pointerEvents.delete(e.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const t=this.state;t._active||(this.start(e),this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY];const r=t._movement;t._movement=[e.scale-1,e.rotation],t._delta=ni.sub(t._movement,r),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const t=this.config.modifierKey;t&&(Array.isArray(t)?!t.find(r=>e[r]):!e[t])||(this.state._active?this.wheelChange(e):this.wheelStart(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(e){this.start(e),this.wheelChange(e)}wheelChange(e){"uv"in e||e.cancelable&&e.preventDefault();const r=this.state;r._delta=[-f9(e)[1]/xoe*r.offset[0],0],ni.addTo(r._movement,r._delta),y9(r),this.state.origin=[e.clientX,e.clientY],this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){const t=this.config.device;t&&(e(t,"start",this[t+"Start"].bind(this)),e(t,"change",this[t+"Move"].bind(this)),e(t,"end",this[t+"End"].bind(this)),e(t,"cancel",this[t+"End"].bind(this)),e("lostPointerCapture","",this[t+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const woe=On(On({},g9),{},{device(n,e,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!Ro.touch&&Ro.gesture)return"gesture";if(Ro.touch&&r)return"touch";if(Ro.touchscreen){if(Ro.pointer)return"pointer";if(Ro.touch)return"touch"}},bounds(n,e,{scaleBounds:t={},angleBounds:r={}}){const i=o=>{const a=lN(hx(t,o),{min:-1/0,max:1/0});return[a.min,a.max]},s=o=>{const a=lN(hx(r,o),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[i(),s()]:o=>[i(o),s(o)]},threshold(n,e,t){return this.lockDirection=t.axis==="lock",ni.toVector(n,this.lockDirection?[.1,3]:0)},modifierKey(n){return n===void 0?"ctrlKey":n},pinchOnWheel(n=!0){return n}});On(On({},ay),{},{mouseOnly:(n=!0)=>n});class Coe extends ooe{constructor(...e){super(...e),wi(this,"ingKey","wheeling")}wheel(e){this.state._active||this.start(e),this.wheelChange(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(e){const t=this.state;t._delta=f9(e),ni.addTo(t._movement,t._delta),y9(t),this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("wheel","",this.wheel.bind(this))}}const Toe=ay;On(On({},ay),{},{mouseOnly:(n=!0)=>n});const _2=new Map,iP=new Map;function Eoe(n){_2.set(n.key,n.engine),iP.set(n.key,n.resolver)}const _oe={key:"pinch",engine:voe,resolver:woe},Poe={key:"wheel",engine:Coe,resolver:Toe};function Ioe(n,e){if(n==null)return{};var t={},r=Object.keys(n),i,s;for(s=0;s<r.length;s++)i=r[s],!(e.indexOf(i)>=0)&&(t[i]=n[i]);return t}function Moe(n,e){if(n==null)return{};var t=Ioe(n,e),r,i;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);for(i=0;i<s.length;i++)r=s[i],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(n,r)&&(t[r]=n[r])}return t}const koe={target(n){if(n)return()=>"current"in n?n.current:n},enabled(n=!0){return n},window(n=Ro.isBrowser?window:void 0){return n},eventOptions({passive:n=!0,capture:e=!1}={}){return{passive:n,capture:e}},transform(n){return n}},Aoe=["target","eventOptions","window","enabled","transform"];function Db(n={},e){const t={};for(const[r,i]of Object.entries(e))switch(typeof i){case"function":t[r]=i.call(t,n[r],r,n);break;case"object":t[r]=Db(n[r],i);break;case"boolean":i&&(t[r]=n[r]);break}return t}function Ooe(n,e,t={}){const r=n,{target:i,eventOptions:s,window:o,enabled:a,transform:l}=r,u=Moe(r,Aoe);if(t.shared=Db({target:i,eventOptions:s,window:o,enabled:a,transform:l},koe),e){const f=iP.get(e);t[e]=Db(On({shared:t.shared},u),f)}else for(const f in u){const h=iP.get(f);h&&(t[f]=Db(On({shared:t.shared},u[f]),h))}return t}class S9{constructor(e,t){wi(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,r,i,s){const o=this._listeners,a=Zse(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},u=On(On({},l),s);e.addEventListener(a,i,u);const f=()=>{e.removeEventListener(a,i,u),o.delete(f)};return o.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class Doe{constructor(){wi(this,"_timeouts",new Map)}add(e,t,r=140,...i){this.remove(e),this._timeouts.set(e,window.setTimeout(t,r,...i))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class Roe{constructor(e){wi(this,"gestures",new Set),wi(this,"_targetEventStore",new S9(this)),wi(this,"gestureEventStores",{}),wi(this,"gestureTimeoutStores",{}),wi(this,"handlers",{}),wi(this,"config",{}),wi(this,"pointerIds",new Set),wi(this,"touchIds",new Set),wi(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),joe(this,e)}setEventIds(e){if(h9(e))return this.touchIds=new Set(eoe(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=Ooe(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,r={};let i;if(!(t.target&&(i=t.target(),!i))){if(t.enabled){for(const o of this.gestures){const a=this.config[o],l=dN(r,a.eventOptions,!!i);if(a.enabled){const u=_2.get(o);new u(this,e,o).bind(l)}}const s=dN(r,t.eventOptions,!!i);for(const o in this.nativeHandlers)s(o,"",a=>this.nativeHandlers[o](On(On({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const s in r)r[s]=roe(...r[s]);if(!i)return r;for(const s in r){const{device:o,capture:a,passive:l}=Xse(s);this._targetEventStore.add(i,o,"",r[s],{capture:a,passive:l})}}}}function $h(n,e){n.gestures.add(e),n.gestureEventStores[e]=new S9(n,e),n.gestureTimeoutStores[e]=new Doe}function joe(n,e){e.drag&&$h(n,"drag"),e.wheel&&$h(n,"wheel"),e.scroll&&$h(n,"scroll"),e.move&&$h(n,"move"),e.pinch&&$h(n,"pinch"),e.hover&&$h(n,"hover")}const dN=(n,e,t)=>(r,i,s,o={},a=!1)=>{var l,u;const f=(l=o.capture)!==null&&l!==void 0?l:e.capture,h=(u=o.passive)!==null&&u!==void 0?u:e.passive;let g=a?r:Yse(r,i,f);t&&h&&(g+="Passive"),n[g]=n[g]||[],n[g].push(s)},Loe=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Noe(n){const e={},t={},r=new Set;for(let i in n)Loe.test(i)?(r.add(RegExp.lastMatch),t[i]=n[i]):e[i]=n[i];return[t,e,r]}function Kh(n,e,t,r,i,s){if(!n.has(t)||!_2.has(r))return;const o=t+"Start",a=t+"End",l=u=>{let f;return u.first&&o in e&&e[o](u),t in e&&(f=e[t](u)),u.last&&a in e&&e[a](u),f};i[r]=l,s[r]=s[r]||{}}function zoe(n,e){const[t,r,i]=Noe(n),s={};return Kh(i,t,"onDrag","drag",s,e),Kh(i,t,"onWheel","wheel",s,e),Kh(i,t,"onScroll","scroll",s,e),Kh(i,t,"onPinch","pinch",s,e),Kh(i,t,"onMove","move",s,e),Kh(i,t,"onHover","hover",s,e),{handlers:s,config:e,nativeHandlers:r}}function Boe(n,e={},t,r){const i=Ge.useMemo(()=>new Roe(n),[]);if(i.applyHandlers(n,r),i.applyConfig(e,t),Ge.useEffect(i.effect.bind(i)),Ge.useEffect(()=>i.clean.bind(i),[]),e.target===void 0)return i.bind.bind(i)}function Foe(n){return n.forEach(Eoe),function(t,r){const{handlers:i,nativeHandlers:s,config:o}=zoe(t,r||{});return Boe(i,o,void 0,s)}}const hN=10,Uoe=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function b9(n){let{deltaY:e,deltaX:t}=n,r=0;return n.ctrlKey||n.altKey||n.metaKey?r=(Math.abs(e)>hN?hN*Math.sign(e):e)/100:n.shiftKey&&!Uoe&&(t=e,e=0),{x:-t,y:-e,z:-r}}const Hoe=Foe([Poe,_oe]);let qh;const $oe=n=>qh===void 0?(qh=n,!1):n-qh>120&&n-qh<160?(qh=n,!0):(qh=n,!1);function Koe(n){const e=te(),t=E.useMemo(()=>{let r="not sure";const i=({event:b})=>{if(!e.getInstanceState().isFocused||(r="not sure",$oe(Date.now())))return;const v=e.getEditingShapeId();if(v){const T=e.getShape(v);if(T&&e.getShapeUtil(T).canScroll(T)&&e.getShapePageBounds(v)?.containsPoint(e.inputs.currentPagePoint))return}nt(b),b.stopPropagation();const w=b9(b);if(w.x===0&&w.y===0)return;const x={type:"wheel",name:"wheel",delta:w,point:new I(b.clientX,b.clientY),shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:xn(b)};e.dispatch(x)};let s=1,o=1,a=0;const l=new I,u=new I,f=b=>{const v=n.current;r="not sure";const{event:w,origin:x,da:T}=b;w instanceof WheelEvent||(w.target===v||v?.contains(w.target))&&(u.x=x[0],u.y=x[1],l.x=x[0],l.y=x[1],s=T[0],o=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:x[0],y:x[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)}))},h=b=>{if(b&&(r="zooming"),r==="zooming")return;const v=Math.abs(a-s),w=I.Dist(l,u);switch(r){case"not sure":{v>24?r="zooming":w>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:i,onPinchStart:f,onPinchEnd:b=>{const v=n.current,{event:w,origin:x,offset:T}=b;if(w instanceof WheelEvent||!(w.target===v||v?.contains(w.target)))return;const P=T[0]**e.getCameraOptions().zoomSpeed;r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:x[0],y:x[1],z:P},delta:{x:x[0],y:x[1]},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)})})},onPinch:b=>{const v=n.current,{event:w,origin:x,offset:T,da:P}=b;if(w instanceof WheelEvent||!(w.target===v||v?.contains(w.target)))return;const M=b.type==="gesturechange"||b.type==="gestureend";a=P[0];const k=x[0]-u.x,A=x[1]-u.y;switch(u.x=x[0],u.y=x[1],h(M),r){case"zooming":{const O=T[0]**e.getCameraOptions().zoomSpeed;e.dispatch({type:"pinch",name:"pinch",point:{x:x[0],y:x[1],z:O},delta:{x:k,y:A},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:x[0],y:x[1],z:o},delta:{x:k,y:A},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)});break}}}}},[e,n]);Hoe(t,{target:n,eventOptions:{passive:!1},pinch:{from:()=>{const{zoomSpeed:r}=e.getCameraOptions();return[e.getZoomLevel()**(1/r),0]},scaleBounds:()=>{const r=e.getBaseZoom(),{zoomSteps:i,zoomSpeed:s}=e.getCameraOptions(),o=i[0]*r;return{max:(i[i.length-1]*r)**(1/s),min:o**(1/s)}}}})}function RE(n,e,t){const r=n.getShape(e),i=n.getShapeHandles(r);return{shape:r,handle:i.find(s=>s.id===t)}}function qoe(n,e){const t=te();return E.useMemo(()=>{const r=l=>{if(t.wasEventAlreadyHandled(l))return;const u=lx(l.currentTarget);Jm(u,l);const{shape:f,handle:h}=RE(t,n,e);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:f,name:"pointer_down",...Ei(t,l)})};let i,s;return{onPointerDown:r,onPointerMove:l=>{if(t.wasEventAlreadyHandled(l)||l.clientX===i&&l.clientY===s)return;i=l.clientX,s=l.clientY;const{shape:u,handle:f}=RE(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:u,name:"pointer_move",...Ei(t,l)})},onPointerUp:l=>{if(t.wasEventAlreadyHandled(l))return;const u=lx(l.currentTarget);Qm(u,l);const{shape:f,handle:h}=RE(t,n,e);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:f,name:"pointer_up",...Ei(t,l)})}}},[t,n,e])}function Voe(n){const e=te();E.useLayoutEffect(()=>{const t=vB(()=>{n.current&&e.updateViewportScreenBounds(n.current)},200,{trailing:!0}),r=e.timers.setInterval(t,1e3);window.addEventListener("resize",t);const i=new ResizeObserver(a=>{a[0].contentRect&&t()}),s=n.current;let o=null;return s&&(i.observe(s),o=Goe(s),o.addEventListener("scroll",t)),()=>{clearInterval(r),window.removeEventListener("resize",t),i.disconnect(),o?.removeEventListener("scroll",t),t.cancel()}},[e,n])}/*!
241
- * Author: excalidraw
242
- * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
243
- * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
244
- */const Goe=n=>{let e=n.parentElement;for(;e;){if(e===document.body)return document;const{overflowY:t}=window.getComputedStyle(e);if(e.scrollHeight>e.clientHeight&&(t==="auto"||t==="scroll"||t==="overlay"))return e;e=e.parentElement}return document};function Yoe(n=!0){const[e,t]=E.useState(0),r=te();E.useEffect(()=>{if(!n)return;const i=()=>t(s=>s+1);return r.on("tick",i),()=>{r.off("tick",i)}},[r,n])}const Woe=sr(function({showStroke:e=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const i=te();Yoe(r);const s=i.getZoomLevel(),o=i.getRenderingShapes(),{inputs:{currentPagePoint:a}}=i;return m.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:o.map(l=>{const u=i.getShape(l.id);if(u.type==="group")return null;const f=i.getShapeGeometry(u),h=i.getShapePageTransform(u),g=i.getPointInShapeSpace(u,a),y=f.nearestPoint(g),b=f.distanceToPoint(g,!0),v=Math.abs(b)*s,w=b<0,{vertices:x}=f;return m.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&m.jsx("g",{stroke:f.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:m.jsx(x9,{geometry:f})}),t&&x.map((T,P)=>m.jsx("circle",{cx:T.x,cy:T.y,r:2/s,fill:`hsl(${pa(P,[0,x.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${P}`)),r&&v<150&&m.jsx("line",{x1:y.x,y1:y.y,x2:g.x,y2:g.y,opacity:1-v/150,stroke:w?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function x9({geometry:n}){return n instanceof Os?m.jsx("g",{stroke:n.debugColor,children:[...n.children,...n.ignoredChildren].map((e,t)=>m.jsx(x9,{geometry:e},t))}):m.jsx("path",{d:n.toSimpleSvgPath(),stroke:n.debugColor})}function v9(n){return XX(n)}function w9(){const n=te(),e=XJ("userIds",()=>v9(n.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>t.join(",")===r.join?.(",")},[n]);return ee(e)}function Gv(n){const e=te();return ee(`latestPresence:${n}`,()=>e.getCollaborators().find(r=>r.userId===n),[e,n])??null}const Xoe=sr(function(){return w9().map(t=>m.jsx(Zoe,{collaboratorId:t},t))}),Zoe=sr(function({collaboratorId:e}){const t=te(),r=Gv(e),i=Qoe(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(i){case"inactive":{const{followingUserId:s,highlightedUserIds:o}=t.getInstanceState();if(!(s===r.userId||o.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return m.jsx(Joe,{latestPresence:r})}),Joe=sr(function({latestPresence:e}){const t=te(),{CollaboratorBrush:r,CollaboratorScribble:i,CollaboratorCursor:s,CollaboratorHint:o,CollaboratorShapeIndicator:a}=on(),l=t.getZoomLevel(),u=t.getViewportPageBounds(),{userId:f,chatMessage:h,brush:g,scribbles:y,selectedShapeIds:b,userName:v,cursor:w,color:x}=e;if(!w)return null;const T=!(w.x<u.minX-12/l||w.y<u.minY-16/l||w.x>u.maxX-12/l||w.y>u.maxY-16/l);return m.jsxs(m.Fragment,{children:[g&&r?m.jsx(r,{className:"tl-collaborator__brush",userId:f,brush:g,color:x,opacity:.1},f+"_brush"):null,T&&s?m.jsx(s,{className:"tl-collaborator__cursor",userId:f,point:w,color:x,zoom:l,name:v!=="New User"?v:null,chatMessage:h??""},f+"_cursor"):o?m.jsx(o,{className:"tl-collaborator__cursor-hint",userId:f,point:w,color:x,zoom:l,viewport:u},f+"_cursor_hint"):null,i&&y.length?m.jsx(m.Fragment,{children:y.map(P=>m.jsx(i,{className:"tl-collaborator__scribble",userId:f,scribble:P,color:x,zoom:l,opacity:P.color==="laser"?.5:.1},f+"_scribble_"+P.id))}):null,a&&b.filter(P=>!t.isShapeHidden(P)).map(P=>m.jsx(a,{className:"tl-collaborator__shape-indicator",userId:f,shapeId:P,color:x,opacity:.5},f+"_"+P))]})});function fN(n,e){return e>n.options.collaboratorInactiveTimeoutMs?"inactive":e>n.options.collaboratorIdleTimeoutMs?"idle":"active"}function Qoe(n,e){const t=E.useRef(e?.lastActivityTimestamp??-1),[r,i]=E.useState(()=>fN(n,Date.now()-t.current));return E.useEffect(()=>{const s=n.timers.setInterval(()=>{i(fN(n,Date.now()-t.current))},n.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[n]),e&&(t.current=e.lastActivityTimestamp??1/0),r}function eae(){const n=te(),e=ee("is menu open",()=>n.menus.hasAnyOpenMenus(),[n]),[t,r]=E.useState(!1),i=e||t,s=Dv(),o=E.useRef({isDown:!1,isDragging:!1,start:new I}),a=E.useCallback(f=>{f.button===0&&(r(!0),o.current={isDown:!0,isDragging:!1,start:new I(f.clientX,f.clientY)}),n.menus.clearOpenMenus()},[n]),l=E.useCallback(f=>{if(o.current.isDown&&I.Dist2(o.current.start,new I(f.clientX,f.clientY))>n.options.dragDistanceSquared){o.current={...o.current,isDown:!0,isDragging:!0};const{x:h,y:g}=o.current.start;s.onPointerDown?.({...f,clientX:h,clientY:g,button:0})}},[s,n]),u=E.useCallback(f=>{s.onPointerUp?.(f),r(!1),o.current={isDown:!1,isDragging:!1,start:new I(f.clientX,f.clientY)}},[s]);return i&&m.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...s,onPointerDown:a,onPointerMove:l,onPointerUp:u})}function tae({className:n}){const e=te(),{SelectionBackground:t,Background:r,SvgDefs:i,ShapeIndicators:s}=on(),o=E.useRef(null),a=E.useRef(null),l=E.useRef(null),u=or();Voe(o),ute(),cte(),Koe(o),Use(o);const f=E.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});wd("position layers",function(){const{x:P,y:M,z:k}=e.getCamera();if(f.current.allowTextOutline&&Nt.isSafari&&(u.style.setProperty("--tl-text-outline","none"),f.current.allowTextOutline=!1),f.current.allowTextOutline&&k<e.options.textShadowLod!==f.current.lodDisableTextOutline){const R=k<e.options.textShadowLod;u.style.setProperty("--tl-text-outline",R?"none":"var(--tl-text-outline-reference)"),f.current.lodDisableTextOutline=R}const A=k>=1?pa(k,[1,8],[.125,.5],!0):pa(k,[.1,1],[-2,.125],!0),O=`scale(${Z(k)}) translate(${Z(P+A)}px,${Z(M+A)}px)`;bi(a.current,"transform",O),bi(l.current,"transform",O)},[e,u]);const h=Dv(),g=ee("shapeSvgDefs",()=>{const T=new Map;for(const P of Hn(e.shapeUtils)){if(!P)return;const M=P.getCanvasSvgDefs();for(const{key:k,component:A}of M)T.has(k)||T.set(k,m.jsx(A,{},k))}return[...T.values()]},[e]),y=ee("debug_shapes",()=>In.hideShapes.get(),[In]),b=ee("debug_svg",()=>In.debugSvg.get(),[In]),v=ee("debug_geometry",()=>In.debugGeometry.get(),[In]),w=ee("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),x=ee("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return m.jsxs(m.Fragment,{children:[m.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":w,"data-isselectinganything":x,className:Fe("tl-canvas",n),"data-testid":"canvas",...h,children:[m.jsx("svg",{className:"tl-svg-context","aria-hidden":"true",children:m.jsxs("defs",{children:[g,m.jsx(mae,{}),m.jsx(yae,{}),i&&m.jsx(i,{})]})}),r&&m.jsx("div",{className:"tl-background__wrapper",children:m.jsx(r,{})}),m.jsx(rae,{}),m.jsxs("div",{ref:a,className:"tl-html-layer tl-shapes",draggable:!1,children:[m.jsx(vae,{}),t&&m.jsx(xae,{}),y?null:b?m.jsx(hae,{}):m.jsx(pae,{})]}),m.jsx("div",{className:"tl-overlays",children:m.jsxs("div",{ref:l,className:"tl-html-layer",children:[v?m.jsx(Woe,{}):null,m.jsx(sae,{}),m.jsx(iae,{}),m.jsx(oae,{}),s&&m.jsx(s,{}),m.jsx(gae,{}),m.jsx(aae,{}),m.jsx(bae,{}),m.jsx(lae,{}),m.jsx(dae,{}),m.jsx(Xoe,{})]})}),m.jsx(wae,{})]}),m.jsx("div",{className:"tl-canvas__in-front",onPointerDown:e.markEventAsHandled,onPointerUp:e.markEventAsHandled,onTouchStart:e.markEventAsHandled,onTouchEnd:e.markEventAsHandled,children:m.jsx(nae,{})}),m.jsx(eae,{})]})}function nae(){const{InFrontOfTheCanvas:n}=on();return n?m.jsx(n,{}):null}function rae(){const n=te(),e=ee("gridSize",()=>n.getDocumentSettings().gridSize,[n]),{x:t,y:r,z:i}=ee("camera",()=>n.getCamera(),[n]),s=ee("isGridMode",()=>n.getInstanceState().isGridMode,[n]),{Grid:o}=on();return o&&s?m.jsx(o,{x:t,y:r,z:i,size:e}):null}function iae(){const n=te(),e=ee("scribbles",()=>n.getInstanceState().scribbles,[n]),t=ee("zoomLevel",()=>n.getZoomLevel(),[n]),{Scribble:r}=on();return r&&e.length?e.map(i=>m.jsx(r,{className:"tl-user-scribble",scribble:i,zoom:t},i.id)):null}function sae(){const n=te(),e=ee("brush",()=>n.getInstanceState().brush,[n]),{Brush:t}=on();return t&&e?m.jsx(t,{className:"tl-user-brush",brush:e}):null}function oae(){const n=te(),e=ee("zoomBrush",()=>n.getInstanceState().zoomBrush,[n]),{ZoomBrush:t}=on();return t&&e?m.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function aae(){const n=te(),e=ee("snapLines",()=>n.snaps.getIndicators(),[n]),t=ee("zoomLevel",()=>n.getZoomLevel(),[n]),{SnapIndicator:r}=on();return r&&e.length>0?e.map(i=>m.jsx(r,{className:"tl-user-snapline",line:i,zoom:t},i.id)):null}function lae(){const n=te(),e=ee("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=n.getInstanceState();if(t||r)return!1;const i=n.getOnlySelectedShape();return!i||!n.getShapeHandles(i)?!1:i.id},[n]);return e?m.jsx(cae,{shapeId:e}):null}function cae({shapeId:n}){const e=te(),{Handles:t}=on(),r=ee("zoomLevel",()=>e.getZoomLevel(),[e]),i=ee("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),s=ee("handles transform",()=>e.getShapePageTransform(n),[e,n]),o=ee("handles",()=>{const l=e.getShapeHandles(n);if(!l)return null;const u=(i?e.options.coarseHandleRadius:e.options.handleRadius)/r*2;return l.filter(f=>f.type!=="virtual"||!l.some(h=>h!==f&&h.type==="vertex"&&I.Dist(f,h)<u)).sort(f=>f.type==="vertex"?1:-1)},[e,r,i,n]),a=ee("isHidden",()=>e.isShapeHidden(n),[e,n]);return!t||!o||!s||a?null:m.jsx(t,{children:m.jsx("g",{transform:xe.toCssString(s),children:o.map(l=>m.jsx(uae,{shapeId:n,handle:l,zoom:r,isCoarse:i},l.id))})})}function uae({shapeId:n,handle:e,zoom:t,isCoarse:r}){const i=qoe(n,e.id),{Handle:s}=on();return s?m.jsx("g",{role:"button","aria-label":e.label||"handle",transform:`translate(${e.x}, ${e.y})`,...i,children:m.jsx(s,{shapeId:n,handle:e,zoom:t,isCoarse:r})}):null}function dae(){const{Overlays:n}=on();return n?m.jsx("div",{className:"tl-custom-overlays tl-overlays__item",children:m.jsx(n,{})}):null}function hae(){const n=te();return ee("rendering shapes",()=>n.getRenderingShapes(),[n]).map(t=>m.jsxs(E.Fragment,{children:[m.jsx(c6,{...t}),m.jsx(Sae,{id:t.id,mode:"iframe"})]},t.id+"_fragment"))}function fae(){const n=te(),e=E.useRef(new Set);return wd("reflow for culled shapes",()=>{const t=n.getCulledShapes();if(e.current.size===t.size&&[...t].every(i=>e.current.has(i)))return;e.current=t;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[n]),null}function pae(){const n=te(),e=ee("rendering shapes",()=>n.getRenderingShapes(),[n]);return m.jsxs(m.Fragment,{children:[e.map(t=>m.jsx(c6,{...t},t.id+"_shape")),Nt.isSafari&&m.jsx(fae,{})]})}function gae(){const n=te(),{ShapeIndicator:e}=on(),t=ee("hinting shape ids",()=>gI(n.getHintingShapeIds()),[n]);return!t.length||!e?null:t.map(r=>m.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function mae(){return m.jsxs("g",{id:da("cursor"),children:[m.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[m.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),m.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),m.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[m.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),m.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),m.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[m.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),m.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function yae(){const n=da("cursor_hint");return m.jsx("path",{id:n,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function Sae({id:n,mode:e}){const t=te(),[r,i]=E.useState(null),s=ee("is in root",()=>t.getShape(n)?.parentId===t.getCurrentPageId(),[t,n]);return E.useEffect(()=>{if(!s)return;let o=null;const a=Ms("shape to svg",async()=>{const l=Math.random();o=l;const f=t.isShapeOfType(n,"frame")?0:10;let h=t.getShapePageBounds(n);if(!h)return;h=h.clone().expandBy(f);const g=await t.getSvgString([n],{padding:f});if(o!==l||!g)return;const y=`data:image/svg+xml;utf8,${encodeURIComponent(g.svg)}`;i({src:y,bounds:h})});return()=>{o=null,a()}},[t,n,s]),!s||!r?null:e==="iframe"?m.jsx("iframe",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,border:"none",transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}}):m.jsx("img",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function bae(){const n=te(),e=ee("selection rotation",function(){return n.getSelectionRotation()},[n]),t=ee("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionForeground:r}=on();return!t||!r?null:m.jsx(r,{bounds:t,rotation:e})}function xae(){const n=te(),e=ee("selection rotation",()=>n.getSelectionRotation(),[n]),t=ee("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionBackground:r}=on();return!t||!r?null:m.jsx(r,{bounds:t,rotation:e})}function vae(){const{OnTheCanvas:n}=on();return n?m.jsx(n,{}):null}function wae(){const n=te(),e=ee("camera state",()=>n.getCameraState(),[n]);return m.jsx("div",{className:Fe("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function su({children:n,className:e="",...t}){return m.jsx("div",{...t,className:Fe("tl-html-container",e),children:n})}class Cae{constructor(e){this.editor=e}static props;static migrations;static type}function Yv(n,e,t={}){const{newPoint:r,handle:i,scaleX:s,scaleY:o}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:u=1,maxHeight:f=1/0}=t;let h=n.props.w*s,g=n.props.h*o;const y=new I(0,0);if(h>0){if(h<a){switch(i){case"top_left":case"left":case"bottom_left":{y.x=h-a;break}case"top":case"bottom":{y.x=(h-a)/2;break}default:y.x=0}h=a}}else if(y.x=h,h=-h,h<a){switch(i){case"top_left":case"left":case"bottom_left":{y.x=-h;break}default:y.x=-a}h=a}if(g>0){if(g<u){switch(i){case"top_left":case"top":case"top_right":{y.y=g-u;break}case"right":case"left":{y.y=(g-u)/2;break}default:y.y=0}g=u}}else if(y.y=g,g=-g,g<u){switch(i){case"top_left":case"top":case"top_right":{y.y=-g;break}default:y.y=-u}g=u}const{x:b,y:v}=y.rot(n.rotation).add(r);return{...n,x:b,y:v,props:{w:Math.min(l,h),h:Math.min(f,g)}}}class tp extends Mu{getGeometry(e){return new Va({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,t){return Yv(e,t)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,t,r){return{...t.props,w:at(e.props.w,t.props.w,r),h:at(e.props.h,t.props.h,r)}}}function C9(n,{initialBounds:e,scaleX:t,scaleY:r,newPoint:i,handle:s}){let o;switch(s){case"bottom_left":case"bottom_right":case"top_left":case"top_right":{o=Math.max(.01,Math.max(Math.abs(t),Math.abs(r)));break}case"left":case"right":{o=Math.max(.01,Math.abs(t));break}case"bottom":case"top":{o=Math.max(.01,Math.abs(r));break}default:throw kt(s)}const a=new I(0,0);t<0&&(a.x=-(e.width*o)),r<0&&(a.y=-(e.height*o));const{x:l,y:u}=I.Add(i,a.rot(n.rotation));return{x:l,y:u,props:{scale:o*n.props.scale}}}let Tae=class extends Ve{static id="idle";onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},Eae=class extends Ve{static id="pointing";onPointerMove(e){const{editor:t}=this;if(t.inputs.isDragging){const{originPagePoint:r}=t.inputs,i=this.parent.shapeType,s=Zt(),o=t.markHistoryStoppingPoint(`creating_box:${s}`),a=oo(r,t);if(this.editor.createShapes([{id:s,type:i,x:a.x,y:a.y,props:{w:1,h:1}}]),!t.getShape(s)){this.cancel();return}t.select(s);const u=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:u.onCreate?f=>u.onCreate?.(f):void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,t=this.parent.shapeType,r=Zt();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:t,x:e.x,y:e.y}]);const i=this.editor.getShape(r);if(!i){this.cancel();return}let{w:s,h:o}=i.props;const a=new I(s/2,o/2),l=this.editor.getShapeParentTransform(i);l&&a.rot(-l.rotation());let u=1;this.editor.user.getIsDynamicResizeMode()&&(u=1/this.editor.getZoomLevel(),s*=u,o*=u,a.mul(u));const f=Qn(i),h=oo(new I(i.x-a.x,i.y-a.y),this.editor);f.x=h.x,f.y=h.y,f.props.w=s,f.props.h=o,"scale"in i.props&&(f.props.scale=u),this.editor.updateShape(f),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}};function oo(n,e){const t=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return t?n.clone().snapToGrid(r):n.clone()}class _ae extends Ve{static id="box";static initial="idle";static children(){return[Tae,Eae]}}function Pae(n,e,t){const r=E.useRef(!1),i=E.useCallback(o=>{r.current=o,o?qi.addOpenMenu(n):qi.deleteOpenMenu(n),e?.(o)},[n,e]),s=ee("is menu open",()=>qi.getOpenMenus().includes(n),[n]);return E.useEffect(()=>(r.current&&(t?.("open-menu"),qi.addOpenMenu(n)),()=>{r.current&&(qi.deleteOpenMenu(n),qi.getOpenMenus().forEach(o=>{o.startsWith(n)&&(t?.("close-menu"),qi.deleteOpenMenu(o))}),r.current=!1)}),[n,t]),[s,i]}function cy(n){const e=te();return ee("isEditing",()=>e.getEditingShapeId()===n,[e,n])}function Iae(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=or(),t=Vn();E.useEffect(()=>{function r(s){if(!t?.getInstanceState().isFocused||s.isSpecialRedispatchedEvent)return;nt(s);const o=e.querySelector(".tl-canvas");if(!o)return;const a=new PointerEvent(s.type,s);a.isSpecialRedispatchedEvent=!0,o.dispatchEvent(a)}const i=n.current;if(i)return i.addEventListener("mouseover",r,{passive:!1}),()=>{i.removeEventListener("mouseover",r)}},[e,t,n])}function Aa(n){const e=te();return E.useMemo(function(){const i=u=>{if(e.wasEventAlreadyHandled(u))return;if(u.button===o2){e.dispatch({type:"pointer",target:"selection",handle:n,name:"right_click",...Ei(e,u)});return}if(u.button!==0)return;const f=lx(u.currentTarget);function h(){f.removeEventListener("pointerup",h),Qm(f,u)}Jm(f,u),f.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:n,...Ei(e,u)}),e.markEventAsHandled(u)};let s,o;function a(u){e.wasEventAlreadyHandled(u)||u.button===0&&(u.clientX===s&&u.clientY===o||(s=u.clientX,o=u.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:n,...Ei(e,u)})))}return{onPointerDown:i,onPointerMove:a,onPointerUp:u=>{e.wasEventAlreadyHandled(u)||u.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:n,...Ei(e,u)})}}},[e,n])}function Mae(n){const[e,t]=E.useState(()=>({store:pm(n),opts:n}));if(!MB(e.opts,n)){const r={store:pm(n),opts:n};return t(r),r.store}return e.store}const kae=20,Aae=8;function Wv(n,e=kae){return Math.max(Aae,Math.ceil(n/e))}class T9 extends Iu{_center;_radius;_start;_end;_largeArcFlag;_sweepFlag;_measure;_angleStart;_angleEnd;constructor(e){super({...e,isFilled:!1,isClosed:!1});const{center:t,sweepFlag:r,largeArcFlag:i,start:s,end:o}=e;if(s.equals(o))throw Error("Arc must have different start and end points.");this._angleStart=I.Angle(t,s),this._angleEnd=I.Angle(t,o),this._radius=I.Dist(t,s),this._measure=Qee(this._angleStart,this._angleEnd,r,i),this._start=s,this._end=o,this._sweepFlag=r,this._largeArcFlag=i,this._center=t}nearestPoint(e){const{_center:t,_measure:r,_radius:i,_angleEnd:s,_angleStart:o,_start:a,_end:l}=this,u=g3(r,o,s,t.angle(e));if(u<=0)return a;if(u>=1)return l;const f=I.Sub(e,t).uni().mul(i).add(t);let h,g=1/0,y;for(const b of[a,l,f])y=I.Dist2(e,b),y<g&&(h=b,g=y);if(!h)throw Error("nearest point not found");return h}hitTestLineSegment(e,t){const{_center:r,_radius:i,_measure:s,_angleStart:o,_angleEnd:a}=this,l=ty(e,t,r,i);return l===null?!1:l.some(u=>{const f=g3(s,o,a,r.angle(u));return f>=0&&f<=1})}getVertices(){const{_center:e,_measure:t,length:r,_radius:i,_angleStart:s}=this,o=[];for(let a=0,l=Wv(Math.abs(r));a<l+1;a++){const u=a/l*t,f=s+u;o.push(s2(e,i,f))}return o}getSvgPathData(e=!0){const{_start:t,_end:r,_radius:i,_largeArcFlag:s,_sweepFlag:o}=this;return`${e?`M${t.toFixed()}`:""} A${i} ${i} 0 ${s} ${o} ${r.toFixed()}`}getLength(){return Math.abs(this._measure*this._radius)}}class fx extends Iu{constructor(e){super({isClosed:!0,...e}),this.config=e;const{x:t=0,y:r=0,radius:i}=e;this._x=t,this._y=r,this._center=new I(i+t,i+r),this._radius=i}_center;_radius;_x;_y;getBounds(){return new we(this._x,this._y,this._radius*2,this._radius*2)}getVertices(){const{_center:e,_radius:t}=this,r=hn*t,i=[];for(let s=0,o=Wv(r);s<o;s++){const a=s/o*hn;i.push(s2(e,t,a))}return i}nearestPoint(e){const{_center:t,_radius:r}=this;return t.equals(e)?I.AddXY(t,r,0):I.Sub(e,t).uni().mul(r).add(t)}hitTestLineSegment(e,t,r=0){const{_center:i,_radius:s}=this;return ty(e,t,i,s+r)!==null}getSvgPathData(){const{_center:e,_radius:t}=this;return`M${e.x+t},${e.y} a${t},${t} 0 1,0 ${t*2},0a${t},${t} 0 1,0 -${t*2},0`}}class P2 extends ny{_a;_b;_c;_d;_resolution;constructor(e){const{start:t,cp1:r,cp2:i,end:s}=e;super({...e,points:[t,s]}),this._a=t,this._b=r,this._c=i,this._d=s,this._resolution=e.resolution??10}getVertices(){const e=[],{_a:t,_b:r,_c:i,_d:s}=this;for(let o=0,a=this._resolution;o<=a;o++){const l=o/a;e.push(new I((1-l)*(1-l)*(1-l)*t.x+3*((1-l)*(1-l))*l*r.x+3*(1-l)*(l*l)*i.x+l*l*l*s.x,(1-l)*(1-l)*(1-l)*t.y+3*((1-l)*(1-l))*l*r.y+3*(1-l)*(l*l)*i.y+l*l*l*s.y))}return e}nearestPoint(e){let t,r=1/0,i,s;for(const o of this.segments)s=o.nearestPoint(e),i=I.Dist2(s,e),i<r&&(t=s,r=i);if(!t)throw Error("nearest point not found");return t}getSvgPathData(e=!0){const{_a:t,_b:r,_c:i,_d:s}=this;return`${e?`M ${t.toFixed()} `:""} C${r.toFixed()} ${i.toFixed()} ${s.toFixed()}`}static GetAtT(e,t){const{_a:r,_b:i,_c:s,_d:o}=e;return new I((1-t)*(1-t)*(1-t)*r.x+3*((1-t)*(1-t))*t*i.x+3*(1-t)*(t*t)*s.x+t*t*t*o.x,(1-t)*(1-t)*(1-t)*r.y+3*((1-t)*(1-t))*t*i.y+3*(1-t)*(t*t)*s.y+t*t*t*o.y)}getLength(e,t=32){let r,i=this._a,s=0;for(let o=1;o<=t;o++)r=P2.GetAtT(this,o/t),s+=I.Dist(i,r),i=r;return s}}class Oae extends Iu{constructor(e){super({...e,isClosed:!0}),this.config=e;const{width:t,height:r}=e;this._w=t,this._h=r}_w;_h;_edges;get edges(){if(!this._edges){const{vertices:e}=this;this._edges=[];for(let t=0,r=e.length;t<r;t++){const i=e[t],s=e[(t+1)%r];this._edges.push(new Df({start:i,end:s}))}}return this._edges}getVertices(){const e=Math.max(1,this._w),t=Math.max(1,this._h),r=e/2,i=t/2,s=Math.pow(r-i,2)/Math.pow(r+i,2),o=Ht*(r+i)*(1+3*s/(10+Math.sqrt(4-3*s))),a=Wv(o),l=hn/a,u=Math.cos(l),f=Math.sin(l);let h=0,g=1,y=0,b=1;const v=Array(a);for(let w=0;w<a;w++)v[w]=new I(st(r+r*g,0,e),st(i+i*h,0,t)),y=f*g+u*h,b=u*g-f*h,h=y,g=b;return v}nearestPoint(e){let t,r=1/0,i,s;for(const o of this.edges)s=o.nearestPoint(e),i=I.Dist2(s,e),i<r&&(t=s,r=i);if(!t)throw Error("nearest point not found");return t}hitTestLineSegment(e,t){return this.edges.some(r=>r.hitTestLineSegment(e,t))}getBounds(){return new we(0,0,this._w,this._h)}getLength(){const{_w:e,_h:t}=this,r=e/2,i=t/2,s=Math.max(0,r),o=Math.max(0,i);return Wee(s,o)}getSvgPathData(e=!1){const{_w:t,_h:r}=this,i=t/2,s=r/2,o=Math.max(0,i),a=Math.max(0,s);return`${e?`M${i-o},${s}`:""} a${o},${a},0,1,1,${o*2},0a${o},${a},0,1,1,-${o*2},0`}}function Xt(n,e,t){const r=new Set;for(const a of e){const l=n.getShape(a);if(!l)continue;r.add(l);const u=n.getShape(l.parentId);u&&r.add(u)}const i=new Map;for(const a of r){const l=n.getSortedChildIdsForParent(a);if(t?.filter&&!t.filter(a))i.set(a,l);else{const u=Dae(n,a.id,l);u.length<l.length&&i.set(a,l.filter(f=>!u.includes(f)))}}const s=n.getCurrentPageShapesSorted().map(a=>a.id),o={};for(const[a,l]of i){const u=tt(l.map(g=>n.getShape(g))),{reparenting:f,remainingShapesToReparent:h}=Rae(n,u,(g,y)=>t?.filter&&!t.filter(y)?!1:y.id!==a.id&&s.indexOf(y.id)<s.indexOf(g.id));if(f.forEach((g,y)=>{g.length!==0&&(o[y]||(o[y]={parentId:y,shapeIds:[]}),o[y].shapeIds.push(...g.map(b=>b.id)))}),h.size>0){const g=n.findShapeAncestor(a,y=>n.isShapeOfType(y,"group"))?.id??n.getCurrentPageId();h.forEach(y=>{if(!o[g]){let b;const v=n.getSortedChildIdsForParent(g),w=v.indexOf(a.id);if(w>-1){const x=v[w+1],T=x?n.getShape(x).index:Lo(a.index);b=Mf(a.index,T)}o[g]={parentId:g,shapeIds:[],index:b}}o[g].shapeIds.push(y.id)})}}n.run(()=>{Object.values(o).forEach(({parentId:a,shapeIds:l,index:u})=>{l.length!==0&&(l.sort((f,h)=>s.indexOf(f)<s.indexOf(h)?-1:1),n.reparentShapes(l,a,u))})})}function Dae(n,e,t){if(t.length===0)return qn;const r=n.getShapePageBounds(e);if(!r)return qn;const i=n.getShapeGeometry(e),o=n.getShapePageTransform(e).applyToPoints(i.vertices),a=n.getShape(e);if(!a)return qn;const l=n.getShapePageTransform(e),u=n.getShapeUtil(a.type).getClipPath?.(a),f=u?l.applyToPoints(u):void 0,h=f?ux(f,o):o;return h?t.filter(g=>{const y=n.getShapePageBounds(g);if(!y||!r.includes(y))return!1;const b=n.getShapePageTransform(g).clone().invert().applyToPoints(h);return n.getShapeGeometry(g).overlapsPolygon(b)}):qn}function Rae(n,e,t){const r=new Set(e),i=new Set;for(const u of e){const f=n.getShapeParent(u);f&&n.isShapeOfType(f,"group")&&(i.has(f)||i.add(f))}for(const u of i){const f=tt(n.getSortedChildIdsForParent(u).map(h=>n.getShape(h)));for(const h of f)r.delete(h);r.add(u)}const s=new Map,o=new Map,a=new Set(r),l=n.getCurrentPageShapesSorted().filter(u=>n.getShapeUtil(u).canReceiveNewChildrenOfType?.(u,u.type)&&!a.has(u));e:for(let u=l.length-1;u>=0;u--){const f=l[u],h=n.findShapeAncestor(f,T=>n.isShapeOfType(T,"group"))?.id,g=n.getShapeGeometry(f),y=n.getShapePageTransform(f),b=n.getShapeMask(f),v=y.applyToPoints(g.vertices),w=b?ux(b,v):v;if(!w)continue e;const x=[];t:for(const T of a){if(f.id===T.id||t&&!t(T,f)||(s.has(T.id)||s.set(T.id,n.findShapeAncestor(T,k=>n.isShapeOfType(k,"group"))?.id),s.get(T.id)!==h)||n.findShapeAncestor(f,k=>T.id===k.id))continue t;const M=n.getShapePageTransform(T).clone().invert().applyToPoints(w);if(n.getShapeGeometry(T).overlapsPolygon(M)){if(!n.getShapeUtil(f).canReceiveNewChildrenOfType?.(f,T.type))continue t;T.parentId!==f.id&&x.push(T),a.delete(T);continue t}}x.length&&o.set(f.id,x)}return{reparenting:o,remainingShapesToReparent:a}}function Wr(n){this.content=n}Wr.prototype={constructor:Wr,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var r=t&&t!=n?this.remove(t):this,i=r.find(n),s=r.content.slice();return i==-1?s.push(t||n,e):(s[i+1]=e,t&&(s[i]=t)),new Wr(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Wr(t)},addToStart:function(n,e){return new Wr([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Wr(t)},addBefore:function(n,e,t){var r=this.remove(e),i=r.content.slice(),s=r.find(n);return i.splice(s==-1?i.length:s,0,e,t),new Wr(i)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Wr.from(n),n.size?new Wr(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Wr.from(n),n.size?new Wr(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Wr.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};Wr.from=function(n){if(n instanceof Wr)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Wr(e)};function E9(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=E9(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function _9(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),a=e.child(--s),l=o.nodeSize;if(o==a){t-=l,r-=l;continue}if(!o.sameMarkup(a))return{a:t,b:r};if(o.isText&&o.text!=a.text){let u=0,f=Math.min(o.text.length,a.text.length);for(;u<f&&o.text[o.text.length-u-1]==a.text[a.text.length-u-1];)u++,t--,r--;return{a:t,b:r}}if(o.content.size||a.content.size){let u=_9(o.content,a.content,t-1,r-1);if(u)return u}t-=l,r-=l}}class Te{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,t,r,i=0,s){for(let o=0,a=0;a<t;o++){let l=this.content[o],u=a+l.nodeSize;if(u>e&&r(l,i+a,s||null,o)!==!1&&l.content.size){let f=a+1;l.nodesBetween(Math.max(0,e-f),Math.min(l.content.size,t-f),r,i+f)}a=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(a,l)=>{let u=a.isText?a.text.slice(Math.max(e,l)-l,t-l):a.isLeaf?i?typeof i=="function"?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&u||a.isTextblock)&&r&&(o?o=!1:s+=r),s+=u},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new Te(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let a=this.content[s],l=o+a.nodeSize;l>e&&((o<e||l>t)&&(a.isText?a=a.cut(Math.max(0,e-o),Math.min(a.text.length,t-o)):a=a.cut(Math.max(0,e-o-1),Math.min(a.content.size,t-o-1))),r.push(a),i+=a.nodeSize),o=l}return new Te(r,i)}cutByIndex(e,t){return e==t?Te.empty:e==0&&t==this.content.length?this:new Te(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new Te(i,s)}addToStart(e){return new Te([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Te(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,r=0;t<this.content.length;t++){let i=this.content[t];e(i,r,t),r+=i.nodeSize}}findDiffStart(e,t=0){return E9(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return _9(this,e,t,r)}findIndex(e){if(e==0)return qS(0,e);if(e==this.size)return qS(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,r=0;;t++){let i=this.child(t),s=r+i.nodeSize;if(s>=e)return s==e?qS(t+1,s):qS(t,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return Te.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new Te(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Te.empty;let t,r=0;for(let i=0;i<e.length;i++){let s=e[i];r+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new Te(t||e,r)}static from(e){if(!e)return Te.empty;if(e instanceof Te)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new Te([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}Te.empty=new Te([],0);const jE={index:0,offset:0};function qS(n,e){return jE.index=n,jE.offset=e,jE}function px(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!px(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!px(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}let dn=class sP{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,r=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!r&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&px(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[t.type];if(!r)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=r.create(t.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(t[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return sP.none;if(e instanceof sP)return[e];let t=e.slice();return t.sort((r,i)=>r.type.rank-i.type.rank),t}};dn.none=[];class gx extends Error{}class Le{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=I9(this.content,e+this.openStart,t);return r&&new Le(r,this.openStart,this.openEnd)}removeBetween(e,t){return new Le(P9(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return Le.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Le(Te.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new Le(e,r,i)}}Le.empty=new Le(Te.empty,0,0);function P9(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:a}=n.findIndex(t);if(i==e||s.isText){if(a!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(P9(s.content,e-i-1,t-i-1)))}function I9(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let a=I9(o.content,e-s-1,t,o);return a&&n.replaceChild(i,o.copy(a))}function jae(n,e,t){if(t.openStart>n.depth)throw new gx("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new gx("Inconsistent open depths");return M9(n,e,t,0)}function M9(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r<n.depth-t.openStart){let o=M9(n,e,t,r+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==r&&e.depth==r){let o=n.parent,a=o.content;return yd(o,a.cut(0,n.parentOffset).append(t.content).append(a.cut(e.parentOffset)))}else{let{start:o,end:a}=Lae(t,n);return yd(s,A9(n,o,a,e,r))}else return yd(s,mx(n,e,r))}function k9(n,e){if(!e.type.compatibleContent(n.type))throw new gx("Cannot join "+e.type.name+" onto "+n.type.name)}function oP(n,e,t){let r=n.node(t);return k9(r,e.node(t)),r}function md(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Vg(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(md(n.nodeAfter,r),s++));for(let a=s;a<o;a++)md(i.child(a),r);e&&e.depth==t&&e.textOffset&&md(e.nodeBefore,r)}function yd(n,e){return n.type.checkContent(e),n.copy(e)}function A9(n,e,t,r,i){let s=n.depth>i&&oP(n,e,i+1),o=r.depth>i&&oP(t,r,i+1),a=[];return Vg(null,n,i,a),s&&o&&e.index(i)==t.index(i)?(k9(s,o),md(yd(s,A9(n,e,t,r,i+1)),a)):(s&&md(yd(s,mx(n,e,i+1)),a),Vg(e,t,i,a),o&&md(yd(o,mx(t,r,i+1)),a)),Vg(r,null,i,a),new Te(a)}function mx(n,e,t){let r=[];if(Vg(null,n,t,r),n.depth>t){let i=oP(n,e,t+1);md(yd(i,mx(n,e,t+1)),r)}return Vg(e,null,t,r),new Te(r)}function Lae(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(Te.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class mm{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=r.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return dn.none;if(this.textOffset)return e.child(t).marks;let r=e.maybeChild(t-1),i=e.maybeChild(t);if(!r){let a=r;r=i,i=a}let s=r.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let r=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!i||!r[s].isInSet(i.marks))&&(r=r[s--].removeFromSet(r));return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new yx(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:a,offset:l}=o.content.findIndex(s),u=s-l;if(r.push(o,a,i+l),!u||(o=o.child(a),o.isText))break;s=u-1,i+=l+1}return new mm(t,r,s)}static resolveCached(e,t){let r=pN.get(e);if(r)for(let s=0;s<r.elts.length;s++){let o=r.elts[s];if(o.pos==t)return o}else pN.set(e,r=new Nae);let i=r.elts[r.i]=mm.resolve(e,t);return r.i=(r.i+1)%zae,i}}class Nae{constructor(){this.elts=[],this.i=0}}const zae=12,pN=new WeakMap;class yx{constructor(e,t,r){this.$from=e,this.$to=t,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const Bae=Object.create(null);let ha=class aP{constructor(e,t,r,i=dn.none){this.type=e,this.attrs=t,this.marks=i,this.content=r||Te.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,r,i=0){this.content.nodesBetween(e,t,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,r,i){return this.content.textBetween(e,t,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,r){return this.type==e&&px(this.attrs,t||e.defaultAttrs||Bae)&&dn.sameSet(this.marks,r||dn.none)}copy(e=null){return e==this.content?this:new aP(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new aP(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,r=!1){if(e==t)return Le.empty;let i=this.resolve(e),s=this.resolve(t),o=r?0:i.sharedDepth(t),a=i.start(o),u=i.node(o).content.cut(i.pos-a,s.pos-a);return new Le(u,i.depth-o,s.depth-o)}replace(e,t,r){return jae(this.resolve(e),this.resolve(t),r)}nodeAt(e){for(let t=this;;){let{index:r,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(r),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(t),index:t,offset:r};let i=this.content.child(t-1);return{node:i,index:t-1,offset:r-i.nodeSize}}resolve(e){return mm.resolveCached(this,e)}resolveNoCache(e){return mm.resolve(this,e)}rangeHasMark(e,t,r){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),O9(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=Te.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),a=o&&o.matchFragment(this.content,t);if(!a||!a.validEnd)return!1;for(let l=i;l<s;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,t,r,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(r),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=dn.none;for(let t=0;t<this.marks.length;t++){let r=this.marks[t];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!dn.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=Te.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};ha.prototype.text=void 0;class Sx extends ha{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):O9(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Sx(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Sx(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function O9(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class kd{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Fae(e,t);if(r.next==null)return kd.empty;let i=D9(r);r.next&&r.err("Unexpected trailing text");let s=Gae(Vae(i));return Yae(s,r),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,r=e.childCount){let i=this;for(let s=t;i&&s<r;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let r=0;r<e.next.length;r++)if(this.next[t].type==e.next[r].type)return!0;return!1}fillBefore(e,t=!1,r=0){let i=[this];function s(o,a){let l=o.matchFragment(e,r);if(l&&(!t||l.validEnd))return Te.from(a.map(u=>u.createAndFill()));for(let u=0;u<o.next.length;u++){let{type:f,next:h}=o.next[u];if(!(f.isText||f.hasRequiredAttrs())&&i.indexOf(h)==-1){i.push(h);let g=s(h,a.concat(f));if(g)return g}}return null}return s(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let a=i;a.type;a=a.via)o.push(a.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:a,next:l}=s.next[o];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in t)&&(!i.type||l.validEnd)&&(r.push({match:a.contentMatch,type:a,via:i}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&t(r.next[i].next)}return t(this),e.map((r,i)=>{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o<r.next.length;o++)s+=(o?", ":"")+r.next[o].type.name+"->"+e.indexOf(r.next[o].next);return s}).join(`
162
+ }`;return m.jsx("style",{nonce:e.options.nonce,children:r})}),xse=[],vse=[],wse=[],Cse="tl-container",Tse=E.memo(function({store:e,components:t,className:r,user:i,options:s,...o}){const[a,l]=E.useState(null),u=E.useMemo(()=>i??NF(),[i]),f=t?.ErrorFallback===void 0?_F:t?.ErrorFallback,h={...o,shapeUtils:o.shapeUtils??xse,bindingUtils:o.bindingUtils??vse,tools:o.tools??wse,components:t,options:Jf(s)};return m.jsx("div",{ref:l,"data-tldraw":d2,draggable:!1,className:Fe(`${Cse} tl-theme__light`,r),tabIndex:-1,role:"application","aria-label":s?.branding??"tldraw",children:m.jsx(hm,{fallback:f,onError:g=>yI(g,{tags:{origin:"react.tldraw-before-app"}}),children:a&&m.jsx(lse,{licenseKey:o.licenseKey,children:m.jsx(TF,{container:a,children:m.jsx(Bse,{overrides:t,children:e?e instanceof GI?m.jsx(i9,{...h,store:e,user:u}):m.jsx(r9,{...h,store:e,user:u}):m.jsx(Ese,{...h,store:e,user:u})})})})})})});function Ese(n){const{defaultName:e,snapshot:t,initialData:r,shapeUtils:i,bindingUtils:s,persistenceKey:o,sessionId:a,user:l,assets:u,migrations:f}=n,h=Zie({shapeUtils:i,bindingUtils:s,initialData:r,persistenceKey:o,sessionId:a,defaultName:e,snapshot:t,assets:u,migrations:f});return m.jsx(r9,{...n,store:h,user:l})}const r9=E.memo(function({store:e,user:t,...r}){const i=or();E.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(i.classList.remove("tl-theme__light"),i.classList.add("tl-theme__dark"))},[i,t]);const{LoadingScreen:s}=on();switch(e.status){case"error":throw e.error;case"loading":return s?m.jsx(s,{}):null}return m.jsx(i9,{...r,store:e.store,user:t})}),DE=()=>document.location.search.includes("tldraw_preserve_focus");function i9({onMount:n,children:e,store:t,tools:r,shapeUtils:i,bindingUtils:s,user:o,initialState:a,autoFocus:l=!0,inferDarkMode:u,cameraOptions:f,textOptions:h,options:g,licenseKey:y,deepLinks:b,getShapeVisibility:v,assetUrls:w}){const{ErrorFallback:x}=on(),T=or(),[P,M]=t9(null),k=E.useRef(null),A=Jf(b===!0?{}:b),O=E.useRef({autoFocus:l&&!DE(),inferDarkMode:u,initialState:a,cameraOptions:f,deepLinks:A});E.useLayoutEffect(()=>{O.current={autoFocus:l&&!DE(),inferDarkMode:u,initialState:a,cameraOptions:f,deepLinks:A}},[l,u,a,f,A]),E.useLayoutEffect(()=>{const{autoFocus:B,inferDarkMode:G,initialState:N,cameraOptions:Y,deepLinks:W}=O.current,Q=new Ae({store:t,shapeUtils:i,bindingUtils:s,tools:r,getContainer:()=>T,user:o,initialState:N,autoFocus:B,inferDarkMode:G,cameraOptions:Y,textOptions:h,options:g,licenseKey:y,getShapeVisibility:v,fontAssetUrls:w?.fonts});return Q.updateViewportScreenBounds(k.current??T),W&&(W?.getUrl?Q.navigateToDeepLink({...W,url:W.getUrl(Q)}):Q.navigateToDeepLink(W)),M(Q),()=>{Q.dispose()}},[s,T,g,i,t,r,o,M,y,v,h,w]),E.useLayoutEffect(()=>{if(P&&A)return P.registerDeepLinkListener(A)},[P,A]),E.useLayoutEffect(()=>{P&&f&&P.setCameraOptions(f)},[P,f]);const R=E.useSyncExternalStore(E.useCallback(B=>P?(P.on("crash",B),()=>P.off("crash",B)):()=>{},[P]),()=>P?.getCrashingError()??null);E.useEffect(function(){if(!P)return;function G(){P&&P.focus()}function N(){P&&P.blur()}if(l&&DE())return P.getContainer().addEventListener("pointerdown",G),document.body.addEventListener("pointerdown",N),()=>{P.getContainer()?.removeEventListener("pointerdown",G),document.body.removeEventListener("pointerdown",N)}},[P,l]);const[F,z]=E.useState(null);let j=F;P!==j?.editor&&(j=null),E.useLayoutEffect(()=>{if(!P)return;if(P.options.maxFontsToLoadBeforeRender===0){z({editor:P,isLoaded:!0});return}let B=!1;return z({editor:P,isLoaded:!1}),P.fonts.loadRequiredFontsForCurrentPage(P.options.maxFontsToLoadBeforeRender).finally(()=>{B||z({editor:P,isLoaded:!0})}),()=>{B=!0}},[P]);const{Canvas:$,LoadingScreen:H}=on();return!P||!j?.isLoaded?m.jsxs(m.Fragment,{children:[H&&m.jsx(H,{}),m.jsx("div",{className:"tl-canvas",ref:k})]}):m.jsx(hm,{fallback:x,onError:B=>P.annotateError(B,{origin:"react.tldraw",willCrashApp:!0}),children:R?m.jsx(Pse,{crashingError:R}):m.jsx(c2,{editor:P,children:m.jsxs(_se,{onMount:n,children:[e??($?m.jsx($,{},P.contextId):null),m.jsx(mse,{})]})})})}function _se({children:n,onMount:e}){return Qie(),Cie(),Tie(),Eie(),Jie(),o9(t=>{const r=t.store.props.onMount(t),i=e?.(t);return()=>{r?.(),i?.()}}),n}function Pse({crashingError:n}){throw n}function s9({children:n}){return m.jsx("div",{className:"tl-loading","aria-busy":"true",tabIndex:0,children:n})}function o9(n){const e=te(),t=ja(r=>{let i;return r.run(()=>{i=n?.(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,i});Ge.useLayoutEffect(()=>{if(e)return t?.(e)},[e,t])}const Ise=()=>{const{Spinner:n}=on();return m.jsx(s9,{children:n?m.jsx(n,{}):null})};function a9(n,e=!0){const t=n.length;if(t<2)return"";let r=n[0],i=n[1];if(t===2)return`M${Jr(r)}L${Jr(i)}`;let s="";for(let o=2,a=t-1;o<a;o++)r=n[o],i=n[o+1],s+=Es(r,i);return e?`M${Es(n[0],n[1])}Q${Jr(n[1])}${Es(n[1],n[2])}T${s}${Es(n[t-1],n[0])}${Es(n[0],n[1])}Z`:`M${Jr(n[0])}Q${Jr(n[1])}${Es(n[1],n[2])}${n.length>3?"T":""}${s}L${Jr(n[t-1])}`}function Q3({scribble:n,zoom:e,color:t,opacity:r,className:i}){return n.points.length?m.jsx("svg",{className:i&&Fe("tl-overlays__item",i),children:m.jsx("path",{className:"tl-scribble",d:a9(n.points,!1),stroke:t??`var(--tl-color-${n.color})`,fill:"none",strokeWidth:8/e,opacity:r??n.opacity})}):null}function Mse({bounds:n,rotation:e}){const t=te(),r=E.useRef(null),i=ee("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=i?t.getShapeUtil(i).expandSelectionOutlinePx(i):0;return Zm(r,n?.x,n?.y,1,e,{x:-s,y:-s}),n=s instanceof we?n.clone().expand(s).zeroFix():n.clone().expandBy(s).zeroFix(),m.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:m.jsx("rect",{className:Fe("tl-selection__fg__outline"),width:Z(n.width),height:Z(n.height)})})}const kse=()=>m.jsx("div",{className:"tl-shape-error-boundary"}),Ase=E.memo(({shape:n,util:e})=>Cv("Indicator: "+n.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(n.id))),(n,e)=>n.shape.props===e.shape.props&&n.shape.meta===e.shape.meta),Ose=E.memo(({editor:n,id:e})=>{const t=ee("shape for indicator",()=>n.store.get(e),[n,e]),{ShapeIndicatorErrorFallback:r}=on();return!t||t.isLocked?null:m.jsx(hm,{fallback:r,onError:i=>n.annotateError(i,{origin:"react.shapeIndicator",willCrashApp:!1}),children:m.jsx(Ase,{shape:t,util:n.getShapeUtil(t)},t.id)})}),eN=E.memo(function({shapeId:e,className:t,color:r,hidden:i,opacity:s}){const o=te(),a=E.useRef(null);return wd("indicator transform",()=>{if(i)return;const l=a.current;if(!l)return;const u=o.getShapePageTransform(e);u&&l.style.setProperty("transform",u.toCssString())},[o,e,i]),E.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",i?"none":"block")},[i]),m.jsx("svg",{ref:a,className:Fe("tl-overlays__item",t),"aria-hidden":"true",children:m.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--tl-color-selected)",opacity:s,children:m.jsx(Ose,{editor:o,id:e})})})}),Dse=()=>m.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),l9=E.memo(function({hideAll:e,showAll:t}){const r=te();if(e&&t)throw Error("You cannot set both hideAll and showAll props to true, cmon now");const i=E.useRef(new Set),s=ee("should display selected ids",()=>{const l=i.current,u=new Set,f=r.getInstanceState(),h=f.isChangingStyle,g=r.isInAny("select.idle","select.editing_shape"),y=r.isInAny("select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","select.pointing_handle");if(h||!(g||y))return i.current=u,u;for(const b of r.getSelectedShapeIds())u.add(b);if(g&&f.isHoveringCanvas&&!f.isCoarsePointer){const b=r.getHoveredShapeId();b&&u.add(b)}if(l.size!==u.size)return i.current=u,u;for(const b of u)if(!l.has(b))return i.current=u,u;return l},[r]),o=ee("rendering shapes",()=>r.getRenderingShapes(),[r]),{ShapeIndicator:a}=on();return a?o.map(({id:l})=>m.jsx(a,{shapeId:l,hidden:!t&&(e||!s.has(l))},l+"_indicator")):null}),Rse=E.forwardRef(function({children:e,shape:t,isBackground:r,...i},s){const o="fill"in t.props&&t.props.fill!=="none";return m.jsx("div",{ref:s,"data-shape-type":t.type,"data-shape-is-filled":r?void 0:o,"data-shape-id":t.id,draggable:!1,...i,className:Fe("tl-shape",r&&"tl-shape-background",i.className),children:e})});function jse({points:n,zoom:e}){const t=2.5/e,r=n.reduce((g,y)=>Math.min(g,y.x),1/0),i=n.reduce((g,y)=>Math.max(g,y.x),-1/0),s=n.reduce((g,y)=>Math.min(g,y.y),1/0),o=n.reduce((g,y)=>Math.max(g,y.y),-1/0),a=n.some(g=>g.x===r&&g.y===s);let l,u,f,h;return a?(l=r,u=s,f=i,h=o):(l=r,u=o,f=i,h=s),m.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[m.jsx("line",{x1:l,y1:u,x2:f,y2:h}),n.map((g,y)=>m.jsx("g",{transform:`translate(${g.x},${g.y})`,children:m.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},y))]})}function Lse({gaps:n,direction:e,zoom:t}){const r=3.5/t;let i=[-1/0,1/0],s=null;const o=e==="horizontal";for(const l of n){if(s=sa(i[0],i[1],o?l.startEdge[0].y:l.startEdge[0].x,o?l.startEdge[1].y:l.startEdge[1].x),s)i=s;else continue;if(s=sa(i[0],i[1],o?l.endEdge[0].y:l.endEdge[0].x,o?l.endEdge[1].y:l.endEdge[1].x),s)i=s;else continue}if(i===null)return null;const a=(i[0]+i[1])/2;return m.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:n.map(({startEdge:l,endEdge:u},f)=>m.jsx(E.Fragment,{children:o?m.jsxs(m.Fragment,{children:[m.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),m.jsx("line",{x1:u[0].x,y1:a-2*r,x2:u[1].x,y2:a+2*r}),m.jsx("line",{x1:l[0].x,y1:a,x2:u[0].x,y2:a}),m.jsx("line",{x1:(l[0].x+u[0].x)/2,y1:a-r,x2:(l[0].x+u[0].x)/2,y2:a+r})]}):m.jsxs(m.Fragment,{children:[m.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),m.jsx("line",{x1:a-2*r,y1:u[0].y,x2:a+2*r,y2:u[1].y}),m.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:u[0].y}),m.jsx("line",{x1:a-r,y1:(l[0].y+u[0].y)/2,x2:a+r,y2:(l[0].y+u[0].y)/2})]})},f))})}function Nse({className:n,line:e,zoom:t}){return m.jsx("svg",{className:Fe("tl-overlays__item",n),"aria-hidden":"true",children:e.type==="points"?m.jsx(jse,{...e,zoom:t}):e.type==="gaps"?m.jsx(Lse,{...e,zoom:t}):null})}function c9(n){return m.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16","aria-hidden":"false",...n,className:Fe("tl-spinner",n.className),children:m.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[m.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),m.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor"})]})})}const zse=()=>null,u9=E.createContext(null);function Bse({overrides:n={},children:e}){const t=Jf(n),r=E.useMemo(()=>({Background:Vee,Brush:yE,Canvas:tae,CollaboratorBrush:yE,CollaboratorCursor:v3,CollaboratorHint:dte,CollaboratorScribble:Q3,CollaboratorShapeIndicator:eN,Cursor:v3,Grid:gte,Handle:mte,Handles:yte,InFrontOfTheCanvas:null,LoadingScreen:Ise,OnTheCanvas:null,Overlays:null,Scribble:Q3,SelectionBackground:null,SelectionForeground:Mse,ShapeIndicator:eN,ShapeIndicators:l9,ShapeWrapper:Rse,SnapIndicator:Nse,Spinner:c9,SvgDefs:zse,ZoomBrush:yE,ErrorFallback:_F,ShapeErrorFallback:kse,ShapeIndicatorErrorFallback:Dse,...t}),[t]);return m.jsx(u9.Provider,{value:r,children:e})}function on(){const n=E.useContext(u9);if(!n)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return n}const Fse=["textarea","input"];function Use(n){const e=te();E.useEffect(()=>{const t=n.current;if(!t)return;const r=i=>{if(i instanceof PointerEvent&&i.pointerType==="pen"){e.markEventAsHandled(i);const{target:s}=i;if(Fse.includes(s.tagName?.toLocaleLowerCase())||s.isContentEditable||e.isIn("select.editing_shape"))return;nt(i)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[e,n])}function Hse(n,e,t){return Math.max(e,Math.min(n,t))}const ni={toVector(n,e){return n===void 0&&(n=e),Array.isArray(n)?n:[n,n]},add(n,e){return[n[0]+e[0],n[1]+e[1]]},sub(n,e){return[n[0]-e[0],n[1]-e[1]]},addTo(n,e){n[0]+=e[0],n[1]+=e[1]},subTo(n,e){n[0]-=e[0],n[1]-=e[1]}};function tN(n,e,t){return e===0||Math.abs(e)===1/0?Math.pow(n,t*5):n*e*t/(e+t*n)}function nN(n,e,t,r=.15){return r===0?Hse(n,e,t):n<e?-tN(e-n,t-e,r)+e:n>t?+tN(n-t,t-e,r)+t:n}function $se(n,[e,t],[r,i]){const[[s,o],[a,l]]=n;return[nN(e,s,o,r),nN(t,a,l,i)]}function Kse(n,e){if(typeof n!="object"||n===null)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var r=t.call(n,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(n)}function qse(n){var e=Kse(n,"string");return typeof e=="symbol"?e:String(e)}function wi(n,e,t){return e=qse(e),e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function rN(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(n,i).enumerable})),t.push.apply(t,r)}return t}function On(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?rN(Object(t),!0).forEach(function(r){wi(n,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):rN(Object(t)).forEach(function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))})}return n}const d9={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 iN(n){return n?n[0].toUpperCase()+n.slice(1):""}const Vse=["enter","leave"];function Gse(n=!1,e){return n&&!Vse.includes(e)}function Yse(n,e="",t=!1){const r=d9[n],i=r&&r[e]||e;return"on"+iN(n)+iN(i)+(Gse(t,i)?"Capture":"")}const Wse=["gotpointercapture","lostpointercapture"];function Xse(n){let e=n.substring(2).toLowerCase();const t=!!~e.indexOf("passive");t&&(e=e.replace("passive",""));const r=Wse.includes(e)?"capturecapture":"capture",i=!!~e.indexOf(r);return i&&(e=e.replace("capture","")),{device:e,capture:i,passive:t}}function Zse(n,e=""){const t=d9[n],r=t&&t[e]||e;return n+r}function h9(n){return"touches"in n}function Jse(n){return h9(n)?"touch":"pointerType"in n?n.pointerType:"mouse"}function Qse(n){return Array.from(n.touches).filter(e=>{var t,r;return e.target===n.currentTarget||((t=n.currentTarget)===null||t===void 0||(r=t.contains)===null||r===void 0?void 0:r.call(t,e.target))})}function rP(n,e){try{const t=e.clientX-n.clientX,r=e.clientY-n.clientY,i=(e.clientX+n.clientX)/2,s=(e.clientY+n.clientY)/2,o=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:o,origin:[i,s]}}catch{}return null}function eoe(n){return Qse(n).map(e=>e.identifier)}function sN(n,e){const[t,r]=Array.from(n.touches).filter(i=>e.includes(i.identifier));return rP(t,r)}const oN=40,aN=800;function f9(n){let{deltaX:e,deltaY:t,deltaMode:r}=n;return r===1?(e*=oN,t*=oN):r===2&&(e*=aN,t*=aN),[e,t]}function toe(n){const e={};if("buttons"in n&&(e.buttons=n.buttons),"shiftKey"in n){const{shiftKey:t,altKey:r,metaKey:i,ctrlKey:s}=n;Object.assign(e,{shiftKey:t,altKey:r,metaKey:i,ctrlKey:s})}return e}function hx(n,...e){return typeof n=="function"?n(...e):n}function noe(){}function roe(...n){return n.length===0?noe:n.length===1?n[0]:function(){let e;for(const t of n)e=t.apply(this,arguments)||e;return e}}function lN(n,e){return Object.assign({},e,n||{})}const ioe=32;class p9{constructor(e,t,r){this.ctrl=e,this.args=t,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(e){this.ctrl.state[this.key]=e}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:e,shared:t,ingKey:r,args:i}=this;t[r]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=i,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const t=this.state,r=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=e.target,t.currentTarget=e.currentTarget,t.lastOffset=r.from?hx(r.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=e.timeStamp)}computeValues(e){const t=this.state;t._values=e,t.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:t,config:r,shared:i}=this;t.args=this.args;let s=0;if(e&&(t.event=e,r.preventDefault&&e.cancelable&&t.event.preventDefault(),t.type=e.type,i.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,i.locked=!!document.pointerLockElement,Object.assign(i,toe(e)),i.down=i.pressed=i.buttons%2===1||i.touches>0,s=e.timeStamp-t.timeStamp,t.timeStamp=e.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const A=t._delta.map(Math.abs);ni.addTo(t._distance,A)}this.axisIntent&&this.axisIntent(e);const[o,a]=t._movement,[l,u]=r.threshold,{_step:f,values:h}=t;if(r.hasCustomTransform?(f[0]===!1&&(f[0]=Math.abs(o)>=l&&h[0]),f[1]===!1&&(f[1]=Math.abs(a)>=u&&h[1])):(f[0]===!1&&(f[0]=Math.abs(o)>=l&&Math.sign(o)*l),f[1]===!1&&(f[1]=Math.abs(a)>=u&&Math.sign(a)*u)),t.intentional=f[0]!==!1||f[1]!==!1,!t.intentional)return;const g=[0,0];if(r.hasCustomTransform){const[A,O]=h;g[0]=f[0]!==!1?A-f[0]:0,g[1]=f[1]!==!1?O-f[1]:0}else g[0]=f[0]!==!1?o-f[0]:0,g[1]=f[1]!==!1?a-f[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(g);const y=t.offset,b=t._active&&!t._blocked||t.active;b&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=i[this.ingKey]=t._active,e&&(t.first&&("bounds"in r&&(t._bounds=hx(r.bounds,t)),this.setup&&this.setup()),t.movement=g,this.computeOffset()));const[v,w]=t.offset,[[x,T],[P,M]]=t._bounds;t.overflow=[v<x?-1:v>T?1:0,w<P?-1:w>M?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const k=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=$se(t._bounds,t.offset,k),t.delta=ni.sub(t.offset,y),this.computeMovement(),b&&(!t.last||s>ioe)){t.delta=ni.sub(t.offset,y);const A=t.delta.map(Math.abs);ni.addTo(t.distance,A),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&s>0&&(t.velocity=[A[0]/s,A[1]/s],t.timeDelta=s)}}emit(){const e=this.state,t=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const i=this.handler(On(On(On({},t),e),{},{[this.aliasKey]:e.values}));i!==void 0&&(e.memo=i)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function soe([n,e],t){const r=Math.abs(n),i=Math.abs(e);if(r>i&&r>t)return"x";if(i>r&&i>t)return"y"}class ooe extends p9{constructor(...e){super(...e),wi(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=ni.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=ni.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const t=this.state,r=this.config;if(!t.axis&&e){const i=typeof r.axisThreshold=="object"?r.axisThreshold[Jse(e)]:r.axisThreshold;t.axis=soe(t._movement,i)}t._blocked=(r.lockDirection||!!r.axis)&&!t.axis||!!r.axis&&r.axis!==t.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const aoe=n=>n,cN=.15,g9={enabled(n=!0){return n},eventOptions(n,e,t){return On(On({},t.shared.eventOptions),n)},preventDefault(n=!1){return n},triggerAllEvents(n=!1){return n},rubberband(n=0){switch(n){case!0:return[cN,cN];case!1:return[0,0];default:return ni.toVector(n)}},from(n){if(typeof n=="function")return n;if(n!=null)return ni.toVector(n)},transform(n,e,t){const r=n||t.shared.transform;return this.hasCustomTransform=!!r,r||aoe},threshold(n){return ni.toVector(n,0)}},loe=0,ay=On(On({},g9),{},{axis(n,e,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(n=loe){return n},bounds(n={}){if(typeof n=="function")return s=>ay.bounds(n(s));if("current"in n)return()=>n.current;if(typeof HTMLElement=="function"&&n instanceof HTMLElement)return n;const{left:e=-1/0,right:t=1/0,top:r=-1/0,bottom:i=1/0}=n;return[[e,t],[r,i]]}}),ly=typeof window<"u"&&window.document&&window.document.createElement;function m9(){return ly&&"ontouchstart"in window}function coe(){return m9()||ly&&window.navigator.maxTouchPoints>1}function uoe(){return ly&&"onpointerdown"in window}function doe(){return ly&&"exitPointerLock"in window.document}function hoe(){try{return"constructor"in GestureEvent}catch{return!1}}const Ro={isBrowser:ly,gesture:hoe(),touch:m9(),touchscreen:coe(),pointer:uoe(),pointerLock:doe()},foe=250,poe=180,goe=.5,moe=50,yoe=250,Soe=10,uN={mouse:0,touch:0,pen:8};On(On({},ay),{},{device(n,e,{pointer:{touch:t=!1,lock:r=!1,mouse:i=!1}={}}){return this.pointerLock=r&&Ro.pointerLock,Ro.touch&&t?"touch":this.pointerLock?"mouse":Ro.pointer&&!i?"pointer":Ro.touch?"touch":"mouse"},preventScrollAxis(n,e,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&n?foe:void 0,!(!Ro.touchscreen||t===!1))return n||(t!==void 0?"y":void 0)},pointerCapture(n,e,{pointer:{capture:t=!0,buttons:r=1,keys:i=!0}={}}){return this.pointerButtons=r,this.keys=i,!this.pointerLock&&this.device==="pointer"&&t},threshold(n,e,{filterTaps:t=!1,tapsThreshold:r=3,axis:i=void 0}){const s=ni.toVector(n,t?r:i?1:0);return this.filterTaps=t,this.tapsThreshold=r,s},swipe({velocity:n=goe,distance:e=moe,duration:t=yoe}={}){return{velocity:this.transform(ni.toVector(n)),distance:this.transform(ni.toVector(e)),duration:t}},delay(n=0){switch(n){case!0:return poe;case!1:return 0;default:return n}},axisThreshold(n){return n?On(On({},uN),n):uN},keyboardDisplacement(n=Soe){return n}});function y9(n){const[e,t]=n.overflow,[r,i]=n._delta,[s,o]=n._direction;(e<0&&r>0&&s<0||e>0&&r<0&&s>0)&&(n._movement[0]=n._movementBound[0]),(t<0&&i>0&&o<0||t>0&&i<0&&o>0)&&(n._movement[1]=n._movementBound[1])}const boe=30,xoe=100;class voe extends p9{constructor(...e){super(...e),wi(this,"ingKey","pinching"),wi(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const e=this.state;e._touchIds=[],e.canceled=!1,e.cancel=this.cancel.bind(this),e.turns=0}computeOffset(){const{type:e,movement:t,lastOffset:r}=this.state;e==="wheel"?this.state.offset=ni.add(t,r):this.state.offset=[(1+t[0])*r[0],t[1]+r[1]]}computeMovement(){const{offset:e,lastOffset:t}=this.state;this.state.movement=[e[0]/t[0],e[1]-t[1]]}axisIntent(){const e=this.state,[t,r]=e._movement;if(!e.axis){const i=Math.abs(t)*boe-Math.abs(r);i<0?e.axis="angle":i>0&&(e.axis="scale")}}restrictToAxis(e){this.config.lockDirection&&(this.state.axis==="scale"?e[1]=0:this.state.axis==="angle"&&(e[0]=0))}cancel(){const e=this.state;e.canceled||setTimeout(()=>{e.canceled=!0,e._active=!1,this.compute(),this.emit()},0)}touchStart(e){this.ctrl.setEventIds(e);const t=this.state,r=this.ctrl.touchIds;if(t._active&&t._touchIds.every(s=>r.has(s))||r.size<2)return;this.start(e),t._touchIds=Array.from(r).slice(0,2);const i=sN(e,t._touchIds);i&&this.pinchStart(e,i)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const t=this.state,r=t._pointerEvents,i=this.ctrl.pointerIds;if(t._active&&Array.from(r.keys()).every(o=>i.has(o))||(r.size<2&&r.set(e.pointerId,e),t._pointerEvents.size<2))return;this.start(e);const s=rP(...Array.from(r.values()));s&&this.pinchStart(e,s)}pinchStart(e,t){const r=this.state;r.origin=t.origin,this.computeValues([t.distance,t.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const t=sN(e,this.state._touchIds);t&&this.pinchMove(e,t)}pointerMove(e){const t=this.state._pointerEvents;if(t.has(e.pointerId)&&t.set(e.pointerId,e),!this.state._active)return;const r=rP(...Array.from(t.values()));r&&this.pinchMove(e,r)}pinchMove(e,t){const r=this.state,i=r._values[1],s=t.angle-i;let o=0;Math.abs(s)>270&&(o+=Math.sign(s)),this.computeValues([t.distance,t.angle-360*o]),r.origin=t.origin,r.turns=o,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const t=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}t._pointerEvents.has(e.pointerId)&&t._pointerEvents.delete(e.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const t=this.state;t._active||(this.start(e),this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([e.scale,e.rotation]),t.origin=[e.clientX,e.clientY];const r=t._movement;t._movement=[e.scale-1,e.rotation],t._delta=ni.sub(t._movement,r),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const t=this.config.modifierKey;t&&(Array.isArray(t)?!t.find(r=>e[r]):!e[t])||(this.state._active?this.wheelChange(e):this.wheelStart(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(e){this.start(e),this.wheelChange(e)}wheelChange(e){"uv"in e||e.cancelable&&e.preventDefault();const r=this.state;r._delta=[-f9(e)[1]/xoe*r.offset[0],0],ni.addTo(r._movement,r._delta),y9(r),this.state.origin=[e.clientX,e.clientY],this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){const t=this.config.device;t&&(e(t,"start",this[t+"Start"].bind(this)),e(t,"change",this[t+"Move"].bind(this)),e(t,"end",this[t+"End"].bind(this)),e(t,"cancel",this[t+"End"].bind(this)),e("lostPointerCapture","",this[t+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const woe=On(On({},g9),{},{device(n,e,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!Ro.touch&&Ro.gesture)return"gesture";if(Ro.touch&&r)return"touch";if(Ro.touchscreen){if(Ro.pointer)return"pointer";if(Ro.touch)return"touch"}},bounds(n,e,{scaleBounds:t={},angleBounds:r={}}){const i=o=>{const a=lN(hx(t,o),{min:-1/0,max:1/0});return[a.min,a.max]},s=o=>{const a=lN(hx(r,o),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[i(),s()]:o=>[i(o),s(o)]},threshold(n,e,t){return this.lockDirection=t.axis==="lock",ni.toVector(n,this.lockDirection?[.1,3]:0)},modifierKey(n){return n===void 0?"ctrlKey":n},pinchOnWheel(n=!0){return n}});On(On({},ay),{},{mouseOnly:(n=!0)=>n});class Coe extends ooe{constructor(...e){super(...e),wi(this,"ingKey","wheeling")}wheel(e){this.state._active||this.start(e),this.wheelChange(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(e){const t=this.state;t._delta=f9(e),ni.addTo(t._movement,t._delta),y9(t),this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("wheel","",this.wheel.bind(this))}}const Toe=ay;On(On({},ay),{},{mouseOnly:(n=!0)=>n});const _2=new Map,iP=new Map;function Eoe(n){_2.set(n.key,n.engine),iP.set(n.key,n.resolver)}const _oe={key:"pinch",engine:voe,resolver:woe},Poe={key:"wheel",engine:Coe,resolver:Toe};function Ioe(n,e){if(n==null)return{};var t={},r=Object.keys(n),i,s;for(s=0;s<r.length;s++)i=r[s],!(e.indexOf(i)>=0)&&(t[i]=n[i]);return t}function Moe(n,e){if(n==null)return{};var t=Ioe(n,e),r,i;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);for(i=0;i<s.length;i++)r=s[i],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(n,r)&&(t[r]=n[r])}return t}const koe={target(n){if(n)return()=>"current"in n?n.current:n},enabled(n=!0){return n},window(n=Ro.isBrowser?window:void 0){return n},eventOptions({passive:n=!0,capture:e=!1}={}){return{passive:n,capture:e}},transform(n){return n}},Aoe=["target","eventOptions","window","enabled","transform"];function Db(n={},e){const t={};for(const[r,i]of Object.entries(e))switch(typeof i){case"function":t[r]=i.call(t,n[r],r,n);break;case"object":t[r]=Db(n[r],i);break;case"boolean":i&&(t[r]=n[r]);break}return t}function Ooe(n,e,t={}){const r=n,{target:i,eventOptions:s,window:o,enabled:a,transform:l}=r,u=Moe(r,Aoe);if(t.shared=Db({target:i,eventOptions:s,window:o,enabled:a,transform:l},koe),e){const f=iP.get(e);t[e]=Db(On({shared:t.shared},u),f)}else for(const f in u){const h=iP.get(f);h&&(t[f]=Db(On({shared:t.shared},u[f]),h))}return t}class S9{constructor(e,t){wi(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=t}add(e,t,r,i,s){const o=this._listeners,a=Zse(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},u=On(On({},l),s);e.addEventListener(a,i,u);const f=()=>{e.removeEventListener(a,i,u),o.delete(f)};return o.add(f),f}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class Doe{constructor(){wi(this,"_timeouts",new Map)}add(e,t,r=140,...i){this.remove(e),this._timeouts.set(e,window.setTimeout(t,r,...i))}remove(e){const t=this._timeouts.get(e);t&&window.clearTimeout(t)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class Roe{constructor(e){wi(this,"gestures",new Set),wi(this,"_targetEventStore",new S9(this)),wi(this,"gestureEventStores",{}),wi(this,"gestureTimeoutStores",{}),wi(this,"handlers",{}),wi(this,"config",{}),wi(this,"pointerIds",new Set),wi(this,"touchIds",new Set),wi(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),joe(this,e)}setEventIds(e){if(h9(e))return this.touchIds=new Set(eoe(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,t){this.handlers=e,this.nativeHandlers=t}applyConfig(e,t){this.config=Ooe(e,t,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const t=this.config.shared,r={};let i;if(!(t.target&&(i=t.target(),!i))){if(t.enabled){for(const o of this.gestures){const a=this.config[o],l=dN(r,a.eventOptions,!!i);if(a.enabled){const u=_2.get(o);new u(this,e,o).bind(l)}}const s=dN(r,t.eventOptions,!!i);for(const o in this.nativeHandlers)s(o,"",a=>this.nativeHandlers[o](On(On({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const s in r)r[s]=roe(...r[s]);if(!i)return r;for(const s in r){const{device:o,capture:a,passive:l}=Xse(s);this._targetEventStore.add(i,o,"",r[s],{capture:a,passive:l})}}}}function $h(n,e){n.gestures.add(e),n.gestureEventStores[e]=new S9(n,e),n.gestureTimeoutStores[e]=new Doe}function joe(n,e){e.drag&&$h(n,"drag"),e.wheel&&$h(n,"wheel"),e.scroll&&$h(n,"scroll"),e.move&&$h(n,"move"),e.pinch&&$h(n,"pinch"),e.hover&&$h(n,"hover")}const dN=(n,e,t)=>(r,i,s,o={},a=!1)=>{var l,u;const f=(l=o.capture)!==null&&l!==void 0?l:e.capture,h=(u=o.passive)!==null&&u!==void 0?u:e.passive;let g=a?r:Yse(r,i,f);t&&h&&(g+="Passive"),n[g]=n[g]||[],n[g].push(s)},Loe=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Noe(n){const e={},t={},r=new Set;for(let i in n)Loe.test(i)?(r.add(RegExp.lastMatch),t[i]=n[i]):e[i]=n[i];return[t,e,r]}function Kh(n,e,t,r,i,s){if(!n.has(t)||!_2.has(r))return;const o=t+"Start",a=t+"End",l=u=>{let f;return u.first&&o in e&&e[o](u),t in e&&(f=e[t](u)),u.last&&a in e&&e[a](u),f};i[r]=l,s[r]=s[r]||{}}function zoe(n,e){const[t,r,i]=Noe(n),s={};return Kh(i,t,"onDrag","drag",s,e),Kh(i,t,"onWheel","wheel",s,e),Kh(i,t,"onScroll","scroll",s,e),Kh(i,t,"onPinch","pinch",s,e),Kh(i,t,"onMove","move",s,e),Kh(i,t,"onHover","hover",s,e),{handlers:s,config:e,nativeHandlers:r}}function Boe(n,e={},t,r){const i=Ge.useMemo(()=>new Roe(n),[]);if(i.applyHandlers(n,r),i.applyConfig(e,t),Ge.useEffect(i.effect.bind(i)),Ge.useEffect(()=>i.clean.bind(i),[]),e.target===void 0)return i.bind.bind(i)}function Foe(n){return n.forEach(Eoe),function(t,r){const{handlers:i,nativeHandlers:s,config:o}=zoe(t,r||{});return Boe(i,o,void 0,s)}}const hN=10,Uoe=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function b9(n){let{deltaY:e,deltaX:t}=n,r=0;return n.ctrlKey||n.altKey||n.metaKey?r=(Math.abs(e)>hN?hN*Math.sign(e):e)/100:n.shiftKey&&!Uoe&&(t=e,e=0),{x:-t,y:-e,z:-r}}const Hoe=Foe([Poe,_oe]);let qh;const $oe=n=>qh===void 0?(qh=n,!1):n-qh>120&&n-qh<160?(qh=n,!0):(qh=n,!1);function Koe(n){const e=te(),t=E.useMemo(()=>{let r="not sure";const i=({event:b})=>{if(!e.getInstanceState().isFocused||(r="not sure",$oe(Date.now())))return;const v=e.getEditingShapeId();if(v){const T=e.getShape(v);if(T&&e.getShapeUtil(T).canScroll(T)&&e.getShapePageBounds(v)?.containsPoint(e.inputs.currentPagePoint))return}nt(b),b.stopPropagation();const w=b9(b);if(w.x===0&&w.y===0)return;const x={type:"wheel",name:"wheel",delta:w,point:new I(b.clientX,b.clientY),shiftKey:b.shiftKey,altKey:b.altKey,ctrlKey:b.metaKey||b.ctrlKey,metaKey:b.metaKey,accelKey:xn(b)};e.dispatch(x)};let s=1,o=1,a=0;const l=new I,u=new I,f=b=>{const v=n.current;r="not sure";const{event:w,origin:x,da:T}=b;w instanceof WheelEvent||(w.target===v||v?.contains(w.target))&&(u.x=x[0],u.y=x[1],l.x=x[0],l.y=x[1],s=T[0],o=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:x[0],y:x[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)}))},h=b=>{if(b&&(r="zooming"),r==="zooming")return;const v=Math.abs(a-s),w=I.Dist(l,u);switch(r){case"not sure":{v>24?r="zooming":w>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:i,onPinchStart:f,onPinchEnd:b=>{const v=n.current,{event:w,origin:x,offset:T}=b;if(w instanceof WheelEvent||!(w.target===v||v?.contains(w.target)))return;const P=T[0]**e.getCameraOptions().zoomSpeed;r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:x[0],y:x[1],z:P},delta:{x:x[0],y:x[1]},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)})})},onPinch:b=>{const v=n.current,{event:w,origin:x,offset:T,da:P}=b;if(w instanceof WheelEvent||!(w.target===v||v?.contains(w.target)))return;const M=b.type==="gesturechange"||b.type==="gestureend";a=P[0];const k=x[0]-u.x,A=x[1]-u.y;switch(u.x=x[0],u.y=x[1],h(M),r){case"zooming":{const O=T[0]**e.getCameraOptions().zoomSpeed;e.dispatch({type:"pinch",name:"pinch",point:{x:x[0],y:x[1],z:O},delta:{x:k,y:A},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:x[0],y:x[1],z:o},delta:{x:k,y:A},shiftKey:w.shiftKey,altKey:w.altKey,ctrlKey:w.metaKey||w.ctrlKey,metaKey:w.metaKey,accelKey:xn(w)});break}}}}},[e,n]);Hoe(t,{target:n,eventOptions:{passive:!1},pinch:{from:()=>{const{zoomSpeed:r}=e.getCameraOptions();return[e.getZoomLevel()**(1/r),0]},scaleBounds:()=>{const r=e.getBaseZoom(),{zoomSteps:i,zoomSpeed:s}=e.getCameraOptions(),o=i[0]*r;return{max:(i[i.length-1]*r)**(1/s),min:o**(1/s)}}}})}function RE(n,e,t){const r=n.getShape(e),i=n.getShapeHandles(r);return{shape:r,handle:i.find(s=>s.id===t)}}function qoe(n,e){const t=te();return E.useMemo(()=>{const r=l=>{if(t.wasEventAlreadyHandled(l))return;const u=lx(l.currentTarget);Jm(u,l);const{shape:f,handle:h}=RE(t,n,e);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:f,name:"pointer_down",...Ei(t,l)})};let i,s;return{onPointerDown:r,onPointerMove:l=>{if(t.wasEventAlreadyHandled(l)||l.clientX===i&&l.clientY===s)return;i=l.clientX,s=l.clientY;const{shape:u,handle:f}=RE(t,n,e);f&&t.dispatch({type:"pointer",target:"handle",handle:f,shape:u,name:"pointer_move",...Ei(t,l)})},onPointerUp:l=>{if(t.wasEventAlreadyHandled(l))return;const u=lx(l.currentTarget);Qm(u,l);const{shape:f,handle:h}=RE(t,n,e);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:f,name:"pointer_up",...Ei(t,l)})}}},[t,n,e])}function Voe(n){const e=te();E.useLayoutEffect(()=>{const t=vB(()=>{n.current&&e.updateViewportScreenBounds(n.current)},200,{trailing:!0}),r=e.timers.setInterval(t,1e3);window.addEventListener("resize",t);const i=new ResizeObserver(a=>{a[0].contentRect&&t()}),s=n.current;let o=null;return s&&(i.observe(s),o=Goe(s),o.addEventListener("scroll",t)),()=>{clearInterval(r),window.removeEventListener("resize",t),i.disconnect(),o?.removeEventListener("scroll",t),t.cancel()}},[e,n])}const Goe=n=>{let e=n.parentElement;for(;e;){if(e===document.body)return document;const{overflowY:t}=window.getComputedStyle(e);if(e.scrollHeight>e.clientHeight&&(t==="auto"||t==="scroll"||t==="overlay"))return e;e=e.parentElement}return document};function Yoe(n=!0){const[e,t]=E.useState(0),r=te();E.useEffect(()=>{if(!n)return;const i=()=>t(s=>s+1);return r.on("tick",i),()=>{r.off("tick",i)}},[r,n])}const Woe=sr(function({showStroke:e=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const i=te();Yoe(r);const s=i.getZoomLevel(),o=i.getRenderingShapes(),{inputs:{currentPagePoint:a}}=i;return m.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:o.map(l=>{const u=i.getShape(l.id);if(u.type==="group")return null;const f=i.getShapeGeometry(u),h=i.getShapePageTransform(u),g=i.getPointInShapeSpace(u,a),y=f.nearestPoint(g),b=f.distanceToPoint(g,!0),v=Math.abs(b)*s,w=b<0,{vertices:x}=f;return m.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&m.jsx("g",{stroke:f.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:m.jsx(x9,{geometry:f})}),t&&x.map((T,P)=>m.jsx("circle",{cx:T.x,cy:T.y,r:2/s,fill:`hsl(${pa(P,[0,x.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${P}`)),r&&v<150&&m.jsx("line",{x1:y.x,y1:y.y,x2:g.x,y2:g.y,opacity:1-v/150,stroke:w?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function x9({geometry:n}){return n instanceof Os?m.jsx("g",{stroke:n.debugColor,children:[...n.children,...n.ignoredChildren].map((e,t)=>m.jsx(x9,{geometry:e},t))}):m.jsx("path",{d:n.toSimpleSvgPath(),stroke:n.debugColor})}function v9(n){return XX(n)}function w9(){const n=te(),e=XJ("userIds",()=>v9(n.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>t.join(",")===r.join?.(",")},[n]);return ee(e)}function Gv(n){const e=te();return ee(`latestPresence:${n}`,()=>e.getCollaborators().find(r=>r.userId===n),[e,n])??null}const Xoe=sr(function(){return w9().map(t=>m.jsx(Zoe,{collaboratorId:t},t))}),Zoe=sr(function({collaboratorId:e}){const t=te(),r=Gv(e),i=Qoe(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(i){case"inactive":{const{followingUserId:s,highlightedUserIds:o}=t.getInstanceState();if(!(s===r.userId||o.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return m.jsx(Joe,{latestPresence:r})}),Joe=sr(function({latestPresence:e}){const t=te(),{CollaboratorBrush:r,CollaboratorScribble:i,CollaboratorCursor:s,CollaboratorHint:o,CollaboratorShapeIndicator:a}=on(),l=t.getZoomLevel(),u=t.getViewportPageBounds(),{userId:f,chatMessage:h,brush:g,scribbles:y,selectedShapeIds:b,userName:v,cursor:w,color:x}=e;if(!w)return null;const T=!(w.x<u.minX-12/l||w.y<u.minY-16/l||w.x>u.maxX-12/l||w.y>u.maxY-16/l);return m.jsxs(m.Fragment,{children:[g&&r?m.jsx(r,{className:"tl-collaborator__brush",userId:f,brush:g,color:x,opacity:.1},f+"_brush"):null,T&&s?m.jsx(s,{className:"tl-collaborator__cursor",userId:f,point:w,color:x,zoom:l,name:v!=="New User"?v:null,chatMessage:h??""},f+"_cursor"):o?m.jsx(o,{className:"tl-collaborator__cursor-hint",userId:f,point:w,color:x,zoom:l,viewport:u},f+"_cursor_hint"):null,i&&y.length?m.jsx(m.Fragment,{children:y.map(P=>m.jsx(i,{className:"tl-collaborator__scribble",userId:f,scribble:P,color:x,zoom:l,opacity:P.color==="laser"?.5:.1},f+"_scribble_"+P.id))}):null,a&&b.filter(P=>!t.isShapeHidden(P)).map(P=>m.jsx(a,{className:"tl-collaborator__shape-indicator",userId:f,shapeId:P,color:x,opacity:.5},f+"_"+P))]})});function fN(n,e){return e>n.options.collaboratorInactiveTimeoutMs?"inactive":e>n.options.collaboratorIdleTimeoutMs?"idle":"active"}function Qoe(n,e){const t=E.useRef(e?.lastActivityTimestamp??-1),[r,i]=E.useState(()=>fN(n,Date.now()-t.current));return E.useEffect(()=>{const s=n.timers.setInterval(()=>{i(fN(n,Date.now()-t.current))},n.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[n]),e&&(t.current=e.lastActivityTimestamp??1/0),r}function eae(){const n=te(),e=ee("is menu open",()=>n.menus.hasAnyOpenMenus(),[n]),[t,r]=E.useState(!1),i=e||t,s=Dv(),o=E.useRef({isDown:!1,isDragging:!1,start:new I}),a=E.useCallback(f=>{f.button===0&&(r(!0),o.current={isDown:!0,isDragging:!1,start:new I(f.clientX,f.clientY)}),n.menus.clearOpenMenus()},[n]),l=E.useCallback(f=>{if(o.current.isDown&&I.Dist2(o.current.start,new I(f.clientX,f.clientY))>n.options.dragDistanceSquared){o.current={...o.current,isDown:!0,isDragging:!0};const{x:h,y:g}=o.current.start;s.onPointerDown?.({...f,clientX:h,clientY:g,button:0})}},[s,n]),u=E.useCallback(f=>{s.onPointerUp?.(f),r(!1),o.current={isDown:!1,isDragging:!1,start:new I(f.clientX,f.clientY)}},[s]);return i&&m.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...s,onPointerDown:a,onPointerMove:l,onPointerUp:u})}function tae({className:n}){const e=te(),{SelectionBackground:t,Background:r,SvgDefs:i,ShapeIndicators:s}=on(),o=E.useRef(null),a=E.useRef(null),l=E.useRef(null),u=or();Voe(o),ute(),cte(),Koe(o),Use(o);const f=E.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});wd("position layers",function(){const{x:P,y:M,z:k}=e.getCamera();if(f.current.allowTextOutline&&Nt.isSafari&&(u.style.setProperty("--tl-text-outline","none"),f.current.allowTextOutline=!1),f.current.allowTextOutline&&k<e.options.textShadowLod!==f.current.lodDisableTextOutline){const R=k<e.options.textShadowLod;u.style.setProperty("--tl-text-outline",R?"none":"var(--tl-text-outline-reference)"),f.current.lodDisableTextOutline=R}const A=k>=1?pa(k,[1,8],[.125,.5],!0):pa(k,[.1,1],[-2,.125],!0),O=`scale(${Z(k)}) translate(${Z(P+A)}px,${Z(M+A)}px)`;bi(a.current,"transform",O),bi(l.current,"transform",O)},[e,u]);const h=Dv(),g=ee("shapeSvgDefs",()=>{const T=new Map;for(const P of Hn(e.shapeUtils)){if(!P)return;const M=P.getCanvasSvgDefs();for(const{key:k,component:A}of M)T.has(k)||T.set(k,m.jsx(A,{},k))}return[...T.values()]},[e]),y=ee("debug_shapes",()=>In.hideShapes.get(),[In]),b=ee("debug_svg",()=>In.debugSvg.get(),[In]),v=ee("debug_geometry",()=>In.debugGeometry.get(),[In]),w=ee("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),x=ee("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return m.jsxs(m.Fragment,{children:[m.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":w,"data-isselectinganything":x,className:Fe("tl-canvas",n),"data-testid":"canvas",...h,children:[m.jsx("svg",{className:"tl-svg-context","aria-hidden":"true",children:m.jsxs("defs",{children:[g,m.jsx(mae,{}),m.jsx(yae,{}),i&&m.jsx(i,{})]})}),r&&m.jsx("div",{className:"tl-background__wrapper",children:m.jsx(r,{})}),m.jsx(rae,{}),m.jsxs("div",{ref:a,className:"tl-html-layer tl-shapes",draggable:!1,children:[m.jsx(vae,{}),t&&m.jsx(xae,{}),y?null:b?m.jsx(hae,{}):m.jsx(pae,{})]}),m.jsx("div",{className:"tl-overlays",children:m.jsxs("div",{ref:l,className:"tl-html-layer",children:[v?m.jsx(Woe,{}):null,m.jsx(sae,{}),m.jsx(iae,{}),m.jsx(oae,{}),s&&m.jsx(s,{}),m.jsx(gae,{}),m.jsx(aae,{}),m.jsx(bae,{}),m.jsx(lae,{}),m.jsx(dae,{}),m.jsx(Xoe,{})]})}),m.jsx(wae,{})]}),m.jsx("div",{className:"tl-canvas__in-front",onPointerDown:e.markEventAsHandled,onPointerUp:e.markEventAsHandled,onTouchStart:e.markEventAsHandled,onTouchEnd:e.markEventAsHandled,children:m.jsx(nae,{})}),m.jsx(eae,{})]})}function nae(){const{InFrontOfTheCanvas:n}=on();return n?m.jsx(n,{}):null}function rae(){const n=te(),e=ee("gridSize",()=>n.getDocumentSettings().gridSize,[n]),{x:t,y:r,z:i}=ee("camera",()=>n.getCamera(),[n]),s=ee("isGridMode",()=>n.getInstanceState().isGridMode,[n]),{Grid:o}=on();return o&&s?m.jsx(o,{x:t,y:r,z:i,size:e}):null}function iae(){const n=te(),e=ee("scribbles",()=>n.getInstanceState().scribbles,[n]),t=ee("zoomLevel",()=>n.getZoomLevel(),[n]),{Scribble:r}=on();return r&&e.length?e.map(i=>m.jsx(r,{className:"tl-user-scribble",scribble:i,zoom:t},i.id)):null}function sae(){const n=te(),e=ee("brush",()=>n.getInstanceState().brush,[n]),{Brush:t}=on();return t&&e?m.jsx(t,{className:"tl-user-brush",brush:e}):null}function oae(){const n=te(),e=ee("zoomBrush",()=>n.getInstanceState().zoomBrush,[n]),{ZoomBrush:t}=on();return t&&e?m.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function aae(){const n=te(),e=ee("snapLines",()=>n.snaps.getIndicators(),[n]),t=ee("zoomLevel",()=>n.getZoomLevel(),[n]),{SnapIndicator:r}=on();return r&&e.length>0?e.map(i=>m.jsx(r,{className:"tl-user-snapline",line:i,zoom:t},i.id)):null}function lae(){const n=te(),e=ee("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=n.getInstanceState();if(t||r)return!1;const i=n.getOnlySelectedShape();return!i||!n.getShapeHandles(i)?!1:i.id},[n]);return e?m.jsx(cae,{shapeId:e}):null}function cae({shapeId:n}){const e=te(),{Handles:t}=on(),r=ee("zoomLevel",()=>e.getZoomLevel(),[e]),i=ee("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),s=ee("handles transform",()=>e.getShapePageTransform(n),[e,n]),o=ee("handles",()=>{const l=e.getShapeHandles(n);if(!l)return null;const u=(i?e.options.coarseHandleRadius:e.options.handleRadius)/r*2;return l.filter(f=>f.type!=="virtual"||!l.some(h=>h!==f&&h.type==="vertex"&&I.Dist(f,h)<u)).sort(f=>f.type==="vertex"?1:-1)},[e,r,i,n]),a=ee("isHidden",()=>e.isShapeHidden(n),[e,n]);return!t||!o||!s||a?null:m.jsx(t,{children:m.jsx("g",{transform:xe.toCssString(s),children:o.map(l=>m.jsx(uae,{shapeId:n,handle:l,zoom:r,isCoarse:i},l.id))})})}function uae({shapeId:n,handle:e,zoom:t,isCoarse:r}){const i=qoe(n,e.id),{Handle:s}=on();return s?m.jsx("g",{role:"button","aria-label":e.label||"handle",transform:`translate(${e.x}, ${e.y})`,...i,children:m.jsx(s,{shapeId:n,handle:e,zoom:t,isCoarse:r})}):null}function dae(){const{Overlays:n}=on();return n?m.jsx("div",{className:"tl-custom-overlays tl-overlays__item",children:m.jsx(n,{})}):null}function hae(){const n=te();return ee("rendering shapes",()=>n.getRenderingShapes(),[n]).map(t=>m.jsxs(E.Fragment,{children:[m.jsx(c6,{...t}),m.jsx(Sae,{id:t.id,mode:"iframe"})]},t.id+"_fragment"))}function fae(){const n=te(),e=E.useRef(new Set);return wd("reflow for culled shapes",()=>{const t=n.getCulledShapes();if(e.current.size===t.size&&[...t].every(i=>e.current.has(i)))return;e.current=t;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[n]),null}function pae(){const n=te(),e=ee("rendering shapes",()=>n.getRenderingShapes(),[n]);return m.jsxs(m.Fragment,{children:[e.map(t=>m.jsx(c6,{...t},t.id+"_shape")),Nt.isSafari&&m.jsx(fae,{})]})}function gae(){const n=te(),{ShapeIndicator:e}=on(),t=ee("hinting shape ids",()=>gI(n.getHintingShapeIds()),[n]);return!t.length||!e?null:t.map(r=>m.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function mae(){return m.jsxs("g",{id:da("cursor"),children:[m.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[m.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),m.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),m.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[m.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),m.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),m.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[m.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),m.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function yae(){const n=da("cursor_hint");return m.jsx("path",{id:n,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function Sae({id:n,mode:e}){const t=te(),[r,i]=E.useState(null),s=ee("is in root",()=>t.getShape(n)?.parentId===t.getCurrentPageId(),[t,n]);return E.useEffect(()=>{if(!s)return;let o=null;const a=Ms("shape to svg",async()=>{const l=Math.random();o=l;const f=t.isShapeOfType(n,"frame")?0:10;let h=t.getShapePageBounds(n);if(!h)return;h=h.clone().expandBy(f);const g=await t.getSvgString([n],{padding:f});if(o!==l||!g)return;const y=`data:image/svg+xml;utf8,${encodeURIComponent(g.svg)}`;i({src:y,bounds:h})});return()=>{o=null,a()}},[t,n,s]),!s||!r?null:e==="iframe"?m.jsx("iframe",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,border:"none",transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}}):m.jsx("img",{src:r.src,width:r.bounds.width,height:r.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${r.bounds.x}px, ${r.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function bae(){const n=te(),e=ee("selection rotation",function(){return n.getSelectionRotation()},[n]),t=ee("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionForeground:r}=on();return!t||!r?null:m.jsx(r,{bounds:t,rotation:e})}function xae(){const n=te(),e=ee("selection rotation",()=>n.getSelectionRotation(),[n]),t=ee("selection bounds",()=>n.getSelectionRotatedPageBounds(),[n]),{SelectionBackground:r}=on();return!t||!r?null:m.jsx(r,{bounds:t,rotation:e})}function vae(){const{OnTheCanvas:n}=on();return n?m.jsx(n,{}):null}function wae(){const n=te(),e=ee("camera state",()=>n.getCameraState(),[n]);return m.jsx("div",{className:Fe("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function su({children:n,className:e="",...t}){return m.jsx("div",{...t,className:Fe("tl-html-container",e),children:n})}class Cae{constructor(e){this.editor=e}static props;static migrations;static type}function Yv(n,e,t={}){const{newPoint:r,handle:i,scaleX:s,scaleY:o}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:u=1,maxHeight:f=1/0}=t;let h=n.props.w*s,g=n.props.h*o;const y=new I(0,0);if(h>0){if(h<a){switch(i){case"top_left":case"left":case"bottom_left":{y.x=h-a;break}case"top":case"bottom":{y.x=(h-a)/2;break}default:y.x=0}h=a}}else if(y.x=h,h=-h,h<a){switch(i){case"top_left":case"left":case"bottom_left":{y.x=-h;break}default:y.x=-a}h=a}if(g>0){if(g<u){switch(i){case"top_left":case"top":case"top_right":{y.y=g-u;break}case"right":case"left":{y.y=(g-u)/2;break}default:y.y=0}g=u}}else if(y.y=g,g=-g,g<u){switch(i){case"top_left":case"top":case"top_right":{y.y=-g;break}default:y.y=-u}g=u}const{x:b,y:v}=y.rot(n.rotation).add(r);return{...n,x:b,y:v,props:{w:Math.min(l,h),h:Math.min(f,g)}}}class tp extends Mu{getGeometry(e){return new Va({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,t){return Yv(e,t)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,t,r){return{...t.props,w:at(e.props.w,t.props.w,r),h:at(e.props.h,t.props.h,r)}}}function C9(n,{initialBounds:e,scaleX:t,scaleY:r,newPoint:i,handle:s}){let o;switch(s){case"bottom_left":case"bottom_right":case"top_left":case"top_right":{o=Math.max(.01,Math.max(Math.abs(t),Math.abs(r)));break}case"left":case"right":{o=Math.max(.01,Math.abs(t));break}case"bottom":case"top":{o=Math.max(.01,Math.abs(r));break}default:throw kt(s)}const a=new I(0,0);t<0&&(a.x=-(e.width*o)),r<0&&(a.y=-(e.height*o));const{x:l,y:u}=I.Add(i,a.rot(n.rotation));return{x:l,y:u,props:{scale:o*n.props.scale}}}let Tae=class extends Ve{static id="idle";onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},Eae=class extends Ve{static id="pointing";onPointerMove(e){const{editor:t}=this;if(t.inputs.isDragging){const{originPagePoint:r}=t.inputs,i=this.parent.shapeType,s=Zt(),o=t.markHistoryStoppingPoint(`creating_box:${s}`),a=oo(r,t);if(this.editor.createShapes([{id:s,type:i,x:a.x,y:a.y,props:{w:1,h:1}}]),!t.getShape(s)){this.cancel();return}t.select(s);const u=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:u.onCreate?f=>u.onCreate?.(f):void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,t=this.parent.shapeType,r=Zt();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:t,x:e.x,y:e.y}]);const i=this.editor.getShape(r);if(!i){this.cancel();return}let{w:s,h:o}=i.props;const a=new I(s/2,o/2),l=this.editor.getShapeParentTransform(i);l&&a.rot(-l.rotation());let u=1;this.editor.user.getIsDynamicResizeMode()&&(u=1/this.editor.getZoomLevel(),s*=u,o*=u,a.mul(u));const f=Qn(i),h=oo(new I(i.x-a.x,i.y-a.y),this.editor);f.x=h.x,f.y=h.y,f.props.w=s,f.props.h=o,"scale"in i.props&&(f.props.scale=u),this.editor.updateShape(f),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}};function oo(n,e){const t=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return t?n.clone().snapToGrid(r):n.clone()}class _ae extends Ve{static id="box";static initial="idle";static children(){return[Tae,Eae]}}function Pae(n,e,t){const r=E.useRef(!1),i=E.useCallback(o=>{r.current=o,o?qi.addOpenMenu(n):qi.deleteOpenMenu(n),e?.(o)},[n,e]),s=ee("is menu open",()=>qi.getOpenMenus().includes(n),[n]);return E.useEffect(()=>(r.current&&(t?.("open-menu"),qi.addOpenMenu(n)),()=>{r.current&&(qi.deleteOpenMenu(n),qi.getOpenMenus().forEach(o=>{o.startsWith(n)&&(t?.("close-menu"),qi.deleteOpenMenu(o))}),r.current=!1)}),[n,t]),[s,i]}function cy(n){const e=te();return ee("isEditing",()=>e.getEditingShapeId()===n,[e,n])}function Iae(n){if(!n)throw Error("usePassThroughWheelEvents must be passed a ref");const e=or(),t=Vn();E.useEffect(()=>{function r(s){if(!t?.getInstanceState().isFocused||s.isSpecialRedispatchedEvent)return;nt(s);const o=e.querySelector(".tl-canvas");if(!o)return;const a=new PointerEvent(s.type,s);a.isSpecialRedispatchedEvent=!0,o.dispatchEvent(a)}const i=n.current;if(i)return i.addEventListener("mouseover",r,{passive:!1}),()=>{i.removeEventListener("mouseover",r)}},[e,t,n])}function Aa(n){const e=te();return E.useMemo(function(){const i=u=>{if(e.wasEventAlreadyHandled(u))return;if(u.button===o2){e.dispatch({type:"pointer",target:"selection",handle:n,name:"right_click",...Ei(e,u)});return}if(u.button!==0)return;const f=lx(u.currentTarget);function h(){f.removeEventListener("pointerup",h),Qm(f,u)}Jm(f,u),f.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:n,...Ei(e,u)}),e.markEventAsHandled(u)};let s,o;function a(u){e.wasEventAlreadyHandled(u)||u.button===0&&(u.clientX===s&&u.clientY===o||(s=u.clientX,o=u.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:n,...Ei(e,u)})))}return{onPointerDown:i,onPointerMove:a,onPointerUp:u=>{e.wasEventAlreadyHandled(u)||u.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:n,...Ei(e,u)})}}},[e,n])}function Mae(n){const[e,t]=E.useState(()=>({store:pm(n),opts:n}));if(!MB(e.opts,n)){const r={store:pm(n),opts:n};return t(r),r.store}return e.store}const kae=20,Aae=8;function Wv(n,e=kae){return Math.max(Aae,Math.ceil(n/e))}class T9 extends Iu{_center;_radius;_start;_end;_largeArcFlag;_sweepFlag;_measure;_angleStart;_angleEnd;constructor(e){super({...e,isFilled:!1,isClosed:!1});const{center:t,sweepFlag:r,largeArcFlag:i,start:s,end:o}=e;if(s.equals(o))throw Error("Arc must have different start and end points.");this._angleStart=I.Angle(t,s),this._angleEnd=I.Angle(t,o),this._radius=I.Dist(t,s),this._measure=Qee(this._angleStart,this._angleEnd,r,i),this._start=s,this._end=o,this._sweepFlag=r,this._largeArcFlag=i,this._center=t}nearestPoint(e){const{_center:t,_measure:r,_radius:i,_angleEnd:s,_angleStart:o,_start:a,_end:l}=this,u=g3(r,o,s,t.angle(e));if(u<=0)return a;if(u>=1)return l;const f=I.Sub(e,t).uni().mul(i).add(t);let h,g=1/0,y;for(const b of[a,l,f])y=I.Dist2(e,b),y<g&&(h=b,g=y);if(!h)throw Error("nearest point not found");return h}hitTestLineSegment(e,t){const{_center:r,_radius:i,_measure:s,_angleStart:o,_angleEnd:a}=this,l=ty(e,t,r,i);return l===null?!1:l.some(u=>{const f=g3(s,o,a,r.angle(u));return f>=0&&f<=1})}getVertices(){const{_center:e,_measure:t,length:r,_radius:i,_angleStart:s}=this,o=[];for(let a=0,l=Wv(Math.abs(r));a<l+1;a++){const u=a/l*t,f=s+u;o.push(s2(e,i,f))}return o}getSvgPathData(e=!0){const{_start:t,_end:r,_radius:i,_largeArcFlag:s,_sweepFlag:o}=this;return`${e?`M${t.toFixed()}`:""} A${i} ${i} 0 ${s} ${o} ${r.toFixed()}`}getLength(){return Math.abs(this._measure*this._radius)}}class fx extends Iu{constructor(e){super({isClosed:!0,...e}),this.config=e;const{x:t=0,y:r=0,radius:i}=e;this._x=t,this._y=r,this._center=new I(i+t,i+r),this._radius=i}_center;_radius;_x;_y;getBounds(){return new we(this._x,this._y,this._radius*2,this._radius*2)}getVertices(){const{_center:e,_radius:t}=this,r=hn*t,i=[];for(let s=0,o=Wv(r);s<o;s++){const a=s/o*hn;i.push(s2(e,t,a))}return i}nearestPoint(e){const{_center:t,_radius:r}=this;return t.equals(e)?I.AddXY(t,r,0):I.Sub(e,t).uni().mul(r).add(t)}hitTestLineSegment(e,t,r=0){const{_center:i,_radius:s}=this;return ty(e,t,i,s+r)!==null}getSvgPathData(){const{_center:e,_radius:t}=this;return`M${e.x+t},${e.y} a${t},${t} 0 1,0 ${t*2},0a${t},${t} 0 1,0 -${t*2},0`}}class P2 extends ny{_a;_b;_c;_d;_resolution;constructor(e){const{start:t,cp1:r,cp2:i,end:s}=e;super({...e,points:[t,s]}),this._a=t,this._b=r,this._c=i,this._d=s,this._resolution=e.resolution??10}getVertices(){const e=[],{_a:t,_b:r,_c:i,_d:s}=this;for(let o=0,a=this._resolution;o<=a;o++){const l=o/a;e.push(new I((1-l)*(1-l)*(1-l)*t.x+3*((1-l)*(1-l))*l*r.x+3*(1-l)*(l*l)*i.x+l*l*l*s.x,(1-l)*(1-l)*(1-l)*t.y+3*((1-l)*(1-l))*l*r.y+3*(1-l)*(l*l)*i.y+l*l*l*s.y))}return e}nearestPoint(e){let t,r=1/0,i,s;for(const o of this.segments)s=o.nearestPoint(e),i=I.Dist2(s,e),i<r&&(t=s,r=i);if(!t)throw Error("nearest point not found");return t}getSvgPathData(e=!0){const{_a:t,_b:r,_c:i,_d:s}=this;return`${e?`M ${t.toFixed()} `:""} C${r.toFixed()} ${i.toFixed()} ${s.toFixed()}`}static GetAtT(e,t){const{_a:r,_b:i,_c:s,_d:o}=e;return new I((1-t)*(1-t)*(1-t)*r.x+3*((1-t)*(1-t))*t*i.x+3*(1-t)*(t*t)*s.x+t*t*t*o.x,(1-t)*(1-t)*(1-t)*r.y+3*((1-t)*(1-t))*t*i.y+3*(1-t)*(t*t)*s.y+t*t*t*o.y)}getLength(e,t=32){let r,i=this._a,s=0;for(let o=1;o<=t;o++)r=P2.GetAtT(this,o/t),s+=I.Dist(i,r),i=r;return s}}class Oae extends Iu{constructor(e){super({...e,isClosed:!0}),this.config=e;const{width:t,height:r}=e;this._w=t,this._h=r}_w;_h;_edges;get edges(){if(!this._edges){const{vertices:e}=this;this._edges=[];for(let t=0,r=e.length;t<r;t++){const i=e[t],s=e[(t+1)%r];this._edges.push(new Df({start:i,end:s}))}}return this._edges}getVertices(){const e=Math.max(1,this._w),t=Math.max(1,this._h),r=e/2,i=t/2,s=Math.pow(r-i,2)/Math.pow(r+i,2),o=Ht*(r+i)*(1+3*s/(10+Math.sqrt(4-3*s))),a=Wv(o),l=hn/a,u=Math.cos(l),f=Math.sin(l);let h=0,g=1,y=0,b=1;const v=Array(a);for(let w=0;w<a;w++)v[w]=new I(st(r+r*g,0,e),st(i+i*h,0,t)),y=f*g+u*h,b=u*g-f*h,h=y,g=b;return v}nearestPoint(e){let t,r=1/0,i,s;for(const o of this.edges)s=o.nearestPoint(e),i=I.Dist2(s,e),i<r&&(t=s,r=i);if(!t)throw Error("nearest point not found");return t}hitTestLineSegment(e,t){return this.edges.some(r=>r.hitTestLineSegment(e,t))}getBounds(){return new we(0,0,this._w,this._h)}getLength(){const{_w:e,_h:t}=this,r=e/2,i=t/2,s=Math.max(0,r),o=Math.max(0,i);return Wee(s,o)}getSvgPathData(e=!1){const{_w:t,_h:r}=this,i=t/2,s=r/2,o=Math.max(0,i),a=Math.max(0,s);return`${e?`M${i-o},${s}`:""} a${o},${a},0,1,1,${o*2},0a${o},${a},0,1,1,-${o*2},0`}}function Xt(n,e,t){const r=new Set;for(const a of e){const l=n.getShape(a);if(!l)continue;r.add(l);const u=n.getShape(l.parentId);u&&r.add(u)}const i=new Map;for(const a of r){const l=n.getSortedChildIdsForParent(a);if(t?.filter&&!t.filter(a))i.set(a,l);else{const u=Dae(n,a.id,l);u.length<l.length&&i.set(a,l.filter(f=>!u.includes(f)))}}const s=n.getCurrentPageShapesSorted().map(a=>a.id),o={};for(const[a,l]of i){const u=tt(l.map(g=>n.getShape(g))),{reparenting:f,remainingShapesToReparent:h}=Rae(n,u,(g,y)=>t?.filter&&!t.filter(y)?!1:y.id!==a.id&&s.indexOf(y.id)<s.indexOf(g.id));if(f.forEach((g,y)=>{g.length!==0&&(o[y]||(o[y]={parentId:y,shapeIds:[]}),o[y].shapeIds.push(...g.map(b=>b.id)))}),h.size>0){const g=n.findShapeAncestor(a,y=>n.isShapeOfType(y,"group"))?.id??n.getCurrentPageId();h.forEach(y=>{if(!o[g]){let b;const v=n.getSortedChildIdsForParent(g),w=v.indexOf(a.id);if(w>-1){const x=v[w+1],T=x?n.getShape(x).index:Lo(a.index);b=Mf(a.index,T)}o[g]={parentId:g,shapeIds:[],index:b}}o[g].shapeIds.push(y.id)})}}n.run(()=>{Object.values(o).forEach(({parentId:a,shapeIds:l,index:u})=>{l.length!==0&&(l.sort((f,h)=>s.indexOf(f)<s.indexOf(h)?-1:1),n.reparentShapes(l,a,u))})})}function Dae(n,e,t){if(t.length===0)return qn;const r=n.getShapePageBounds(e);if(!r)return qn;const i=n.getShapeGeometry(e),o=n.getShapePageTransform(e).applyToPoints(i.vertices),a=n.getShape(e);if(!a)return qn;const l=n.getShapePageTransform(e),u=n.getShapeUtil(a.type).getClipPath?.(a),f=u?l.applyToPoints(u):void 0,h=f?ux(f,o):o;return h?t.filter(g=>{const y=n.getShapePageBounds(g);if(!y||!r.includes(y))return!1;const b=n.getShapePageTransform(g).clone().invert().applyToPoints(h);return n.getShapeGeometry(g).overlapsPolygon(b)}):qn}function Rae(n,e,t){const r=new Set(e),i=new Set;for(const u of e){const f=n.getShapeParent(u);f&&n.isShapeOfType(f,"group")&&(i.has(f)||i.add(f))}for(const u of i){const f=tt(n.getSortedChildIdsForParent(u).map(h=>n.getShape(h)));for(const h of f)r.delete(h);r.add(u)}const s=new Map,o=new Map,a=new Set(r),l=n.getCurrentPageShapesSorted().filter(u=>n.getShapeUtil(u).canReceiveNewChildrenOfType?.(u,u.type)&&!a.has(u));e:for(let u=l.length-1;u>=0;u--){const f=l[u],h=n.findShapeAncestor(f,T=>n.isShapeOfType(T,"group"))?.id,g=n.getShapeGeometry(f),y=n.getShapePageTransform(f),b=n.getShapeMask(f),v=y.applyToPoints(g.vertices),w=b?ux(b,v):v;if(!w)continue e;const x=[];t:for(const T of a){if(f.id===T.id||t&&!t(T,f)||(s.has(T.id)||s.set(T.id,n.findShapeAncestor(T,k=>n.isShapeOfType(k,"group"))?.id),s.get(T.id)!==h)||n.findShapeAncestor(f,k=>T.id===k.id))continue t;const M=n.getShapePageTransform(T).clone().invert().applyToPoints(w);if(n.getShapeGeometry(T).overlapsPolygon(M)){if(!n.getShapeUtil(f).canReceiveNewChildrenOfType?.(f,T.type))continue t;T.parentId!==f.id&&x.push(T),a.delete(T);continue t}}x.length&&o.set(f.id,x)}return{reparenting:o,remainingShapesToReparent:a}}function Wr(n){this.content=n}Wr.prototype={constructor:Wr,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var r=t&&t!=n?this.remove(t):this,i=r.find(n),s=r.content.slice();return i==-1?s.push(t||n,e):(s[i+1]=e,t&&(s[i]=t)),new Wr(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Wr(t)},addToStart:function(n,e){return new Wr([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Wr(t)},addBefore:function(n,e,t){var r=this.remove(e),i=r.content.slice(),s=r.find(n);return i.splice(s==-1?i.length:s,0,e,t),new Wr(i)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Wr.from(n),n.size?new Wr(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Wr.from(n),n.size?new Wr(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Wr.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};Wr.from=function(n){if(n instanceof Wr)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Wr(e)};function E9(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=E9(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function _9(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),a=e.child(--s),l=o.nodeSize;if(o==a){t-=l,r-=l;continue}if(!o.sameMarkup(a))return{a:t,b:r};if(o.isText&&o.text!=a.text){let u=0,f=Math.min(o.text.length,a.text.length);for(;u<f&&o.text[o.text.length-u-1]==a.text[a.text.length-u-1];)u++,t--,r--;return{a:t,b:r}}if(o.content.size||a.content.size){let u=_9(o.content,a.content,t-1,r-1);if(u)return u}t-=l,r-=l}}class Te{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,t,r,i=0,s){for(let o=0,a=0;a<t;o++){let l=this.content[o],u=a+l.nodeSize;if(u>e&&r(l,i+a,s||null,o)!==!1&&l.content.size){let f=a+1;l.nodesBetween(Math.max(0,e-f),Math.min(l.content.size,t-f),r,i+f)}a=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(a,l)=>{let u=a.isText?a.text.slice(Math.max(e,l)-l,t-l):a.isLeaf?i?typeof i=="function"?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&u||a.isTextblock)&&r&&(o?o=!1:s+=r),s+=u},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new Te(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let a=this.content[s],l=o+a.nodeSize;l>e&&((o<e||l>t)&&(a.isText?a=a.cut(Math.max(0,e-o),Math.min(a.text.length,t-o)):a=a.cut(Math.max(0,e-o-1),Math.min(a.content.size,t-o-1))),r.push(a),i+=a.nodeSize),o=l}return new Te(r,i)}cutByIndex(e,t){return e==t?Te.empty:e==0&&t==this.content.length?this:new Te(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new Te(i,s)}addToStart(e){return new Te([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Te(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,r=0;t<this.content.length;t++){let i=this.content[t];e(i,r,t),r+=i.nodeSize}}findDiffStart(e,t=0){return E9(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return _9(this,e,t,r)}findIndex(e){if(e==0)return qS(0,e);if(e==this.size)return qS(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,r=0;;t++){let i=this.child(t),s=r+i.nodeSize;if(s>=e)return s==e?qS(t+1,s):qS(t,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return Te.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new Te(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Te.empty;let t,r=0;for(let i=0;i<e.length;i++){let s=e[i];r+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new Te(t||e,r)}static from(e){if(!e)return Te.empty;if(e instanceof Te)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new Te([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}Te.empty=new Te([],0);const jE={index:0,offset:0};function qS(n,e){return jE.index=n,jE.offset=e,jE}function px(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!px(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!px(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}let dn=class sP{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,r=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!r&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&px(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[t.type];if(!r)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=r.create(t.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(t[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return sP.none;if(e instanceof sP)return[e];let t=e.slice();return t.sort((r,i)=>r.type.rank-i.type.rank),t}};dn.none=[];class gx extends Error{}class Le{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=I9(this.content,e+this.openStart,t);return r&&new Le(r,this.openStart,this.openEnd)}removeBetween(e,t){return new Le(P9(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return Le.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Le(Te.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new Le(e,r,i)}}Le.empty=new Le(Te.empty,0,0);function P9(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:a}=n.findIndex(t);if(i==e||s.isText){if(a!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(P9(s.content,e-i-1,t-i-1)))}function I9(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let a=I9(o.content,e-s-1,t,o);return a&&n.replaceChild(i,o.copy(a))}function jae(n,e,t){if(t.openStart>n.depth)throw new gx("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new gx("Inconsistent open depths");return M9(n,e,t,0)}function M9(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r<n.depth-t.openStart){let o=M9(n,e,t,r+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==r&&e.depth==r){let o=n.parent,a=o.content;return yd(o,a.cut(0,n.parentOffset).append(t.content).append(a.cut(e.parentOffset)))}else{let{start:o,end:a}=Lae(t,n);return yd(s,A9(n,o,a,e,r))}else return yd(s,mx(n,e,r))}function k9(n,e){if(!e.type.compatibleContent(n.type))throw new gx("Cannot join "+e.type.name+" onto "+n.type.name)}function oP(n,e,t){let r=n.node(t);return k9(r,e.node(t)),r}function md(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Vg(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(md(n.nodeAfter,r),s++));for(let a=s;a<o;a++)md(i.child(a),r);e&&e.depth==t&&e.textOffset&&md(e.nodeBefore,r)}function yd(n,e){return n.type.checkContent(e),n.copy(e)}function A9(n,e,t,r,i){let s=n.depth>i&&oP(n,e,i+1),o=r.depth>i&&oP(t,r,i+1),a=[];return Vg(null,n,i,a),s&&o&&e.index(i)==t.index(i)?(k9(s,o),md(yd(s,A9(n,e,t,r,i+1)),a)):(s&&md(yd(s,mx(n,e,i+1)),a),Vg(e,t,i,a),o&&md(yd(o,mx(t,r,i+1)),a)),Vg(r,null,i,a),new Te(a)}function mx(n,e,t){let r=[];if(Vg(null,n,t,r),n.depth>t){let i=oP(n,e,t+1);md(yd(i,mx(n,e,t+1)),r)}return Vg(e,null,t,r),new Te(r)}function Lae(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(Te.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class mm{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=r.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return dn.none;if(this.textOffset)return e.child(t).marks;let r=e.maybeChild(t-1),i=e.maybeChild(t);if(!r){let a=r;r=i,i=a}let s=r.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let r=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!i||!r[s].isInSet(i.marks))&&(r=r[s--].removeFromSet(r));return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new yx(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:a,offset:l}=o.content.findIndex(s),u=s-l;if(r.push(o,a,i+l),!u||(o=o.child(a),o.isText))break;s=u-1,i+=l+1}return new mm(t,r,s)}static resolveCached(e,t){let r=pN.get(e);if(r)for(let s=0;s<r.elts.length;s++){let o=r.elts[s];if(o.pos==t)return o}else pN.set(e,r=new Nae);let i=r.elts[r.i]=mm.resolve(e,t);return r.i=(r.i+1)%zae,i}}class Nae{constructor(){this.elts=[],this.i=0}}const zae=12,pN=new WeakMap;class yx{constructor(e,t,r){this.$from=e,this.$to=t,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const Bae=Object.create(null);let ha=class aP{constructor(e,t,r,i=dn.none){this.type=e,this.attrs=t,this.marks=i,this.content=r||Te.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,r,i=0){this.content.nodesBetween(e,t,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,r,i){return this.content.textBetween(e,t,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,r){return this.type==e&&px(this.attrs,t||e.defaultAttrs||Bae)&&dn.sameSet(this.marks,r||dn.none)}copy(e=null){return e==this.content?this:new aP(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new aP(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,r=!1){if(e==t)return Le.empty;let i=this.resolve(e),s=this.resolve(t),o=r?0:i.sharedDepth(t),a=i.start(o),u=i.node(o).content.cut(i.pos-a,s.pos-a);return new Le(u,i.depth-o,s.depth-o)}replace(e,t,r){return jae(this.resolve(e),this.resolve(t),r)}nodeAt(e){for(let t=this;;){let{index:r,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(r),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(t),index:t,offset:r};let i=this.content.child(t-1);return{node:i,index:t-1,offset:r-i.nodeSize}}resolve(e){return mm.resolveCached(this,e)}resolveNoCache(e){return mm.resolve(this,e)}rangeHasMark(e,t,r){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),O9(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=Te.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),a=o&&o.matchFragment(this.content,t);if(!a||!a.validEnd)return!1;for(let l=i;l<s;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,t,r,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(r),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=dn.none;for(let t=0;t<this.marks.length;t++){let r=this.marks[t];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!dn.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=Te.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};ha.prototype.text=void 0;class Sx extends ha{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):O9(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Sx(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Sx(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function O9(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class kd{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Fae(e,t);if(r.next==null)return kd.empty;let i=D9(r);r.next&&r.err("Unexpected trailing text");let s=Gae(Vae(i));return Yae(s,r),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,r=e.childCount){let i=this;for(let s=t;i&&s<r;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let r=0;r<e.next.length;r++)if(this.next[t].type==e.next[r].type)return!0;return!1}fillBefore(e,t=!1,r=0){let i=[this];function s(o,a){let l=o.matchFragment(e,r);if(l&&(!t||l.validEnd))return Te.from(a.map(u=>u.createAndFill()));for(let u=0;u<o.next.length;u++){let{type:f,next:h}=o.next[u];if(!(f.isText||f.hasRequiredAttrs())&&i.indexOf(h)==-1){i.push(h);let g=s(h,a.concat(f));if(g)return g}}return null}return s(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let a=i;a.type;a=a.via)o.push(a.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:a,next:l}=s.next[o];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in t)&&(!i.type||l.validEnd)&&(r.push({match:a.contentMatch,type:a,via:i}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&t(r.next[i].next)}return t(this),e.map((r,i)=>{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o<r.next.length;o++)s+=(o?", ":"")+r.next[o].type.name+"->"+e.indexOf(r.next[o].next);return s}).join(`
245
163
  `)}}kd.empty=new kd(!0);class Fae{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function D9(n){let e=[];do e.push(Uae(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Uae(n){let e=[];do e.push(Hae(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Hae(n){let e=qae(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=$ae(n,e);else break;return e}function gN(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function $ae(n,e){let t=gN(n),r=t;return n.eat(",")&&(n.next!="}"?r=gN(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Kae(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function qae(n){if(n.eat("(")){let e=D9(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Kae(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Vae(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,a,l){let u={term:l,to:a};return e[o].push(u),u}function i(o,a){o.forEach(l=>l.to=a)}function s(o,a){if(o.type=="choice")return o.exprs.reduce((l,u)=>l.concat(s(u,a)),[]);if(o.type=="seq")for(let l=0;;l++){let u=s(o.exprs[l],a);if(l==o.exprs.length-1)return u;i(u,a=t())}else if(o.type=="star"){let l=t();return r(a,l),i(s(o.expr,l),l),[r(l)]}else if(o.type=="plus"){let l=t();return i(s(o.expr,a),l),i(s(o.expr,l),l),[r(l)]}else{if(o.type=="opt")return[r(a)].concat(s(o.expr,a));if(o.type=="range"){let l=a;for(let u=0;u<o.min;u++){let f=t();i(s(o.expr,l),f),l=f}if(o.max==-1)i(s(o.expr,l),l);else for(let u=o.min;u<o.max;u++){let f=t();r(l,f),i(s(o.expr,l),f),l=f}return[r(l)]}else{if(o.type=="name")return[r(a,void 0,o.value)];throw new Error("Unknown expr type")}}}}function R9(n,e){return e-n}function mN(n,e){let t=[];return r(e),t.sort(R9);function r(i){let s=n[i];if(s.length==1&&!s[0].term)return r(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:a,to:l}=s[o];!a&&t.indexOf(l)==-1&&r(l)}}}function Gae(n){let e=Object.create(null);return t(mN(n,0));function t(r){let i=[];r.forEach(o=>{n[o].forEach(({term:a,to:l})=>{if(!a)return;let u;for(let f=0;f<i.length;f++)i[f][0]==a&&(u=i[f][1]);mN(n,l).forEach(f=>{u||i.push([a,u=[]]),u.indexOf(f)==-1&&u.push(f)})})});let s=e[r.join(",")]=new kd(r.indexOf(n.length-1)>-1);for(let o=0;o<i.length;o++){let a=i[o][1].sort(R9);s.next.push({type:i[o][0],next:e[a.join(",")]||t(a)})}return s}}function Yae(n,e){for(let t=0,r=[n];t<r.length;t++){let i=r[t],s=!i.validEnd,o=[];for(let a=0;a<i.next.length;a++){let{type:l,next:u}=i.next[a];o.push(l.name),s&&!(l.isText||l.hasRequiredAttrs())&&(s=!1),r.indexOf(u)==-1&&r.push(u)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function j9(n){let e=Object.create(null);for(let t in n){let r=n[t];if(!r.hasDefault)return null;e[t]=r.default}return e}function L9(n,e){let t=Object.create(null);for(let r in n){let i=e&&e[r];if(i===void 0){let s=n[r];if(s.hasDefault)i=s.default;else throw new RangeError("No value supplied for attribute "+r)}t[r]=i}return t}function N9(n,e,t,r){for(let i in e)if(!(i in n))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${i}`);for(let i in n){let s=n[i];s.validate&&s.validate(e[i])}}function z9(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new Xae(n,r,e[r]);return t}let yN=class B9{constructor(e,t,r){this.name=e,this.schema=t,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=z9(e,r.attrs),this.defaultAttrs=j9(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==kd.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:L9(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ha(this,this.computeAttrs(e),Te.from(t),dn.setFrom(r))}createChecked(e=null,t,r){return t=Te.from(t),this.checkContent(t),new ha(this,this.computeAttrs(e),t,dn.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=Te.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(Te.empty,!0);return s?new ha(this,e,t.append(s),dn.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){N9(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?t&&t.push(e[r]):t||(t=e.slice(0,r));return t?t.length?t:dn.none:e}static compile(e,t){let r=Object.create(null);e.forEach((s,o)=>r[s]=new B9(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Wae(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}class Xae{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Wae(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class Xv{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=z9(e,i.attrs),this.excluded=null;let s=j9(this.attrs);this.instance=s?new dn(this,s):null}create(e=null){return!e&&this.instance?this.instance:new dn(this,L9(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new Xv(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){N9(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class F9{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Wr.from(e.nodes),t.marks=Wr.from(e.marks||{}),this.nodes=yN.compile(this.spec.nodes,this),this.marks=Xv.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",a=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=kd.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=a=="_"?null:a?SN(this,a.split(" ")):a==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:SN(this,o.split(" "))}this.nodeFromJSON=i=>ha.fromJSON(this,i),this.markFromJSON=i=>dn.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof yN){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Sx(r,r.defaultAttrs,e,dn.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function SN(n,e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],s=n.marks[i],o=s;if(s)t.push(s);else for(let a in n.marks){let l=n.marks[a];(i=="_"||l.spec.group&&l.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=l)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Zae(n){return n.tag!=null}function Jae(n){return n.style!=null}let wf=class lP{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Zae(i))this.tags.push(i);else if(Jae(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new xN(this,t,!1);return r.addAll(e,dn.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new xN(this,t,!0);return r.addAll(e,dn.none,t.from,t.to),Le.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let s=this.tags[i];if(tle(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,r,i){for(let s=i?this.styles.indexOf(i)+1:0;s<this.styles.length;s++){let o=this.styles[s],a=o.style;if(!(a.indexOf(e)!=0||o.context&&!r.matchesContext(o.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(o.getAttrs){let l=o.getAttrs(t);if(l===!1)continue;o.attrs=l||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o<t.length;o++){let a=t[o];if((a.priority==null?50:a.priority)<s)break}t.splice(o,0,i)}for(let i in e.marks){let s=e.marks[i].spec.parseDOM;s&&s.forEach(o=>{r(o=vN(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=vN(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new lP(e,lP.schemaRules(e)))}};const U9={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Qae={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},H9={ol:!0,ul:!0},ym=1,cP=2,Gg=4;function bN(n,e,t){return e!=null?(e?ym:0)|(e==="full"?cP:0):n&&n.whitespace=="pre"?ym|cP:t&~Gg}class VS{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=dn.none,this.match=s||(o&Gg?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Te.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&ym)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=Te.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Te.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!U9.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class xN{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=bN(null,t.preserveWhitespace,0)|(r?Gg:0);i?s=new VS(i.type,i.attrs,dn.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new VS(null,null,dn.none,!0,null,o):s=new VS(e.schema.topNodeType,null,dn.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top,s=i.options&cP?"full":this.localPreserveWS||(i.options&ym)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)if(s==="full")r=r.replace(/\r\n?/g,`
246
164
  `);else if(o.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(o.linebreakReplacement.create())){let a=r.split(/\r?\n|\r/);for(let l=0;l<a.length;l++)l&&this.insertNode(o.linebreakReplacement.create(),t,!0),a[l]&&this.insertNode(o.text(a[l]),t,!/\S/.test(a[l]));r=""}else r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let a=i.content[i.content.length-1],l=e.previousSibling;(!a||l&&l.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(r=r.slice(1))}r&&this.insertNode(o.text(r),t,!/\S/.test(r)),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),a;H9.hasOwnProperty(o)&&this.parser.normalizeLists&&ele(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,r));e:if(l?l.ignore:Qae.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let u,f=this.needsBlock;if(U9.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),u=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let h=l&&l.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),u&&this.sync(s),this.needsBlock=f}else{let u=this.readStyles(e,t);u&&this.addElementByRule(e,l,u,l.consuming===!1?a:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
247
165
  `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let s=this.parser.matchedStyles[i],o=r.getPropertyValue(s);if(o)for(let a=void 0;;){let l=this.parser.matchStyle(s,o,this,a);if(!l)break;if(l.ignore)return null;if(l.clearMark?t=t.filter(u=>!l.clearMark(u)):t=t.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)a=l;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(o,t.attrs||null,r,t.preserveWhitespace);l&&(s=!0,r=l)}else{let l=this.parser.schema.marks[t.mark];r=r.concat(l.create(t.attrs))}let a=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof t.contentElement=="string"?l=e.querySelector(t.contentElement):typeof t.contentElement=="function"?l=t.contentElement(e):t.contentElement&&(l=t.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}s&&this.sync(a)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,a=i==null?null:e.childNodes[i];o!=a;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,r){let i,s;for(let o=this.open,a=0;o>=0;o--){let l=this.nodes[o],u=l.findWrapping(e);if(u&&(!i||i.length>u.length+a)&&(i=u,s=l,!u.length))break;if(l.solid){if(r)break;a+=2}}if(!i)return null;this.sync(s);for(let o=0;o<i.length;o++)t=this.enterInner(i[o],null,t,!1);return t}insertNode(e,t,r){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let i=this.findPlace(e,t,r);if(i){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=dn.none;for(let a of i.concat(e.marks))(s.type?s.type.allowsMarkType(a.type):wN(a.type,e.type))&&(o=a.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,r,i){let s=this.findPlace(e.create(t),r,!1);return s&&(s=this.enterInner(e,t,r,!0,i)),s}enterInner(e,t,r,i=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let a=bN(e,s,o.options);o.options&Gg&&o.content.length==0&&(a|=Gg);let l=dn.none;return r=r.filter(u=>(o.type?o.type.allowsMarkType(u.type):wN(u.type,e))?(l=u.addToSet(l),!1):!0),this.nodes.push(new VS(e,t,l,i,null,a)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=ym)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==t&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,r){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&t.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(a,l)=>{for(;a>=0;a--){let u=t[a];if(u==""){if(a==t.length-1||a==0)continue;for(;l>=s;l--)if(o(a-1,l))return!0;return!1}else{let f=l>0||l==0&&i?this.nodes[l].type:r&&l>=s?r.node(l-s).type:null;if(!f||f.name!=u&&!f.isInGroup(u))return!1;l--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function ele(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&H9.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function tle(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function vN(n){let e={};for(let t in n)e[t]=n[t];return e}function wN(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=a=>{s.push(a);for(let l=0;l<a.edgeCount;l++){let{type:u,next:f}=a.edge(l);if(u==e||s.indexOf(f)<0&&o(f))return!0}};if(o(i.contentMatch))return!0}}class Wd{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},r){r||(r=LE(t).createDocumentFragment());let i=r,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let a=0,l=0;for(;a<s.length&&l<o.marks.length;){let u=o.marks[l];if(!this.marks[u.type.name]){l++;continue}if(!u.eq(s[a][0])||u.type.spec.spanning===!1)break;a++,l++}for(;a<s.length;)i=s.pop()[1];for(;l<o.marks.length;){let u=o.marks[l++],f=this.serializeMark(u,o.isInline,t);f&&(s.push([u,i]),i.appendChild(f.dom),i=f.contentDOM||f.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),r}serializeNodeInner(e,t){let{dom:r,contentDOM:i}=Rb(LE(t),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,i)}return r}serializeNode(e,t={}){let r=this.serializeNodeInner(e,t);for(let i=e.marks.length-1;i>=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Rb(LE(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Rb(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Wd(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=CN(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return CN(e.marks)}}function CN(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function LE(n){return n.document||window.document}const TN=new WeakMap;function nle(n){let e=TN.get(n);return e===void 0&&TN.set(n,e=rle(n)),e}function rle(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i<r.length;i++)t(r[i]);else for(let i in r)t(r[i])}return t(n),e}function Rb(n,e,t,r){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let i=e[0],s;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(s=nle(r))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let a,l=t?n.createElementNS(t,i):n.createElement(i),u=e[1],f=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){f=2;for(let h in u)if(u[h]!=null){let g=h.indexOf(" ");g>0?l.setAttributeNS(h.slice(0,g),h.slice(g+1),u[h]):h=="style"&&l.style?l.style.cssText=u[h]:l.setAttribute(h,u[h])}}for(let h=f;h<e.length;h++){let g=e[h];if(g===0){if(h<e.length-1||h>f)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:y,contentDOM:b}=Rb(n,g,t,r);if(l.appendChild(y),b){if(a)throw new RangeError("Multiple content holes");a=b}}}return{dom:l,contentDOM:a}}const $9=65535,K9=Math.pow(2,16);function ile(n,e){return n+e*K9}function EN(n){return n&$9}function sle(n){return(n-(n&$9))/K9}const q9=1,V9=2,jb=4,G9=8;class uP{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&G9)>0}get deletedBefore(){return(this.delInfo&(q9|jb))>0}get deletedAfter(){return(this.delInfo&(V9|jb))>0}get deletedAcross(){return(this.delInfo&jb)>0}}class Zs{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Zs.empty)return Zs.empty}recover(e){let t=0,r=EN(e);if(!this.inverted)for(let i=0;i<r;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+t+sle(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,r){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?i:0);if(l>e)break;let u=this.ranges[a+s],f=this.ranges[a+o],h=l+u;if(e<=h){let g=u?e==l?-1:e==h?1:t:t,y=l+i+(g<0?0:f);if(r)return y;let b=e==(t<0?l:h)?null:ile(a/3,e-l),v=e==l?V9:e==h?q9:jb;return(t<0?e!=l:e!=h)&&(v|=G9),new uP(y,v,b)}i+=f-u}return r?e+i:new uP(e+i,0,null)}touches(e,t){let r=0,i=EN(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?r:0);if(l>e)break;let u=this.ranges[a+s],f=l+u;if(e<=f&&a==i*3)return!0;r+=this.ranges[a+o]-u}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],a=o-(this.inverted?s:0),l=o+(this.inverted?0:s),u=this.ranges[i+t],f=this.ranges[i+r];e(a,a+u,l,l+f),s+=f-u}}invert(){return new Zs(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Zs.empty:new Zs(e<0?[0,-e,0]:[0,0,e])}}Zs.empty=new Zs([]);class Sm{constructor(e,t,r=0,i=e?e.length:0){this.mirror=t,this.from=r,this.to=i,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new Sm(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,r=this._maps.length;t<e._maps.length;t++){let i=e.getMirror(t);this.appendMap(e._maps[t],i!=null&&i<t?r+i:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,r=this._maps.length+e._maps.length;t>=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new Sm;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;r<this.to;r++)e=this._maps[r].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,r){let i=0;for(let s=this.from;s<this.to;s++){let o=this._maps[s],a=o.mapResult(e,t);if(a.recover!=null){let l=this.getMirror(s);if(l!=null&&l>s&&l<this.to){s=l,e=this._maps[l].recover(a.recover);continue}}i|=a.delInfo,e=a.pos}return r?e:new uP(e,i,null)}}const NE=Object.create(null);class Oi{getMap(){return Zs.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=NE[t.stepType];if(!r)throw new RangeError(`No step type ${t.stepType} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in NE)throw new RangeError("Duplicate use of step JSON ID "+e);return NE[e]=t,t.prototype.jsonID=e,t}}class mr{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new mr(e,null)}static fail(e){return new mr(null,e)}static fromReplace(e,t,r,i){try{return mr.ok(e.replace(t,r,i))}catch(s){if(s instanceof gx)return mr.fail(s.message);throw s}}}function I2(n,e,t){let r=[];for(let i=0;i<n.childCount;i++){let s=n.child(i);s.content.size&&(s=s.copy(I2(s.content,e,s))),s.isInline&&(s=e(s,t,i)),r.push(s)}return Te.fromArray(r)}class tu extends Oi{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),s=new Le(I2(t.content,(o,a)=>!o.isAtom||!a.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return mr.fromReplace(e,this.from,this.to,s)}invert(){return new Fa(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new tu(t.pos,r.pos,this.mark)}merge(e){return e instanceof tu&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new tu(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new tu(t.from,t.to,e.markFromJSON(t.mark))}}Oi.jsonID("addMark",tu);class Fa extends Oi{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new Le(I2(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return mr.fromReplace(e,this.from,this.to,r)}invert(){return new tu(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Fa(t.pos,r.pos,this.mark)}merge(e){return e instanceof Fa&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Fa(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Fa(t.from,t.to,e.markFromJSON(t.mark))}}Oi.jsonID("removeMark",Fa);class nu extends Oi{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return mr.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return mr.fromReplace(e,this.pos,this.pos+1,new Le(Te.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(r))return new nu(this.pos,t.marks[i]);return new nu(this.pos,this.mark)}}return new Ad(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new nu(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new nu(t.pos,e.markFromJSON(t.mark))}}Oi.jsonID("addNodeMark",nu);class Ad extends Oi{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return mr.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return mr.fromReplace(e,this.pos,this.pos+1,new Le(Te.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new nu(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ad(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ad(t.pos,e.markFromJSON(t.mark))}}Oi.jsonID("removeNodeMark",Ad);class Ar extends Oi{constructor(e,t,r,i=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=i}apply(e){return this.structure&&dP(e,this.from,this.to)?mr.fail("Structure replace would overwrite content"):mr.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Zs([this.from,this.to-this.from,this.slice.size])}invert(e){return new Ar(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deletedAcross&&r.deletedAcross?null:new Ar(t.pos,Math.max(t.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Ar)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?Le.empty:new Le(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Ar(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?Le.empty:new Le(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Ar(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Ar(t.from,t.to,Le.fromJSON(e,t.slice),!!t.structure)}}Oi.jsonID("replace",Ar);class jr extends Oi{constructor(e,t,r,i,s,o,a=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=i,this.slice=s,this.insert=o,this.structure=a}apply(e){if(this.structure&&(dP(e,this.from,this.gapFrom)||dP(e,this.gapTo,this.to)))return mr.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return mr.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?mr.fromReplace(e,this.from,this.to,r):mr.fail("Content does not fit in gap")}getMap(){return new Zs([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new jr(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||i<t.pos||s>r.pos?null:new jr(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new jr(t.from,t.to,t.gapFrom,t.gapTo,Le.fromJSON(e,t.slice),t.insert,!!t.structure)}}Oi.jsonID("replaceAround",jr);function dP(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function ole(n,e,t,r){let i=[],s=[],o,a;n.doc.nodesBetween(e,t,(l,u,f)=>{if(!l.isInline)return;let h=l.marks;if(!r.isInSet(h)&&f.type.allowsMarkType(r.type)){let g=Math.max(u,e),y=Math.min(u+l.nodeSize,t),b=r.addToSet(h);for(let v=0;v<h.length;v++)h[v].isInSet(b)||(o&&o.to==g&&o.mark.eq(h[v])?o.to=y:i.push(o=new Fa(g,y,h[v])));a&&a.to==g?a.to=y:s.push(a=new tu(g,y,r))}}),i.forEach(l=>n.step(l)),s.forEach(l=>n.step(l))}function ale(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,a)=>{if(!o.isInline)return;s++;let l=null;if(r instanceof Xv){let u=o.marks,f;for(;f=r.isInSet(u);)(l||(l=[])).push(f),u=f.removeFromSet(u)}else r?r.isInSet(o.marks)&&(l=[r]):l=o.marks;if(l&&l.length){let u=Math.min(a+o.nodeSize,t);for(let f=0;f<l.length;f++){let h=l[f],g;for(let y=0;y<i.length;y++){let b=i[y];b.step==s-1&&h.eq(i[y].style)&&(g=b)}g?(g.to=u,g.step=s):i.push({style:h,from:Math.max(a,e),to:u,step:s})}}}),i.forEach(o=>n.step(new Fa(o.from,o.to,o.style)))}function M2(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],a=e+1;for(let l=0;l<s.childCount;l++){let u=s.child(l),f=a+u.nodeSize,h=r.matchType(u.type);if(!h)o.push(new Ar(a,f,Le.empty));else{r=h;for(let g=0;g<u.marks.length;g++)t.allowsMarkType(u.marks[g].type)||n.step(new Fa(a,f,u.marks[g]));if(i&&u.isText&&t.whitespace!="pre"){let g,y=/\r?\n|\r/g,b;for(;g=y.exec(u.text);)b||(b=new Le(Te.from(t.schema.text(" ",t.allowedMarks(u.marks))),0,0)),o.push(new Ar(a+g.index,a+g.index+g[0].length,b))}}a=f}if(!r.validEnd){let l=r.fillBefore(Te.empty,!0);n.replace(a,a,new Le(l,0,0))}for(let l=o.length-1;l>=0;l--)n.step(o[l])}function lle(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function np(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(r<n.depth&&i.canReplace(s,o,t))return r;if(r==0||i.type.spec.isolating||!lle(i,s,o))break}return null}function cle(n,e,t){let{$from:r,$to:i,depth:s}=e,o=r.before(s+1),a=i.after(s+1),l=o,u=a,f=Te.empty,h=0;for(let b=s,v=!1;b>t;b--)v||r.index(b)>0?(v=!0,f=Te.from(r.node(b).copy(f)),h++):l--;let g=Te.empty,y=0;for(let b=s,v=!1;b>t;b--)v||i.after(b+1)<i.end(b)?(v=!0,g=Te.from(i.node(b).copy(g)),y++):u++;n.step(new jr(l,u,o,a,new Le(f.append(g),h,y),f.size-h,!0))}function k2(n,e,t=null,r=n){let i=ule(n,e),s=i&&dle(r,e);return s?i.map(_N).concat({type:e,attrs:t}).concat(s.map(_N)):null}function _N(n){return{type:n,attrs:null}}function ule(n,e){let{parent:t,startIndex:r,endIndex:i}=n,s=t.contentMatchAt(r).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(r,i,o)?s:null}function dle(n,e){let{parent:t,startIndex:r,endIndex:i}=n,s=t.child(r),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let l=(o.length?o[o.length-1]:e).contentMatch;for(let u=r;l&&u<i;u++)l=l.matchType(t.child(u).type);return!l||!l.validEnd?null:o}function hle(n,e,t){let r=Te.empty;for(let o=t.length-1;o>=0;o--){if(r.size){let a=t[o].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=Te.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new jr(i,s,i,s,new Le(r,0,0),t.length,!0))}function fle(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,a)=>{let l=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,l)&&ple(n.doc,n.mapping.slice(s).map(a),r)){let u=null;if(r.schema.linebreakReplacement){let y=r.whitespace=="pre",b=!!r.contentMatch.matchType(r.schema.linebreakReplacement);y&&!b?u=!1:!y&&b&&(u=!0)}u===!1&&W9(n,o,a,s),M2(n,n.mapping.slice(s).map(a,1),r,void 0,u===null);let f=n.mapping.slice(s),h=f.map(a,1),g=f.map(a+o.nodeSize,1);return n.step(new jr(h,g,h+1,g-1,new Le(Te.from(r.create(l,null,o.marks)),0,0),1,!0)),u===!0&&Y9(n,o,a,s),!1}})}function Y9(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,a=/\r?\n|\r/g;for(;o=a.exec(i.text);){let l=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function W9(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(`
@@ -331,11 +249,7 @@ img.ProseMirror-separator {
331
249
  opacity: 0
332
250
  }`;function Ahe(n,e,t){const r=document.querySelector("style[data-tiptap-style]");if(r!==null)return r;const i=document.createElement("style");return e&&i.setAttribute("nonce",e),i.setAttribute("data-tiptap-style",""),i.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(i),i}class Ohe extends zue{constructor(e={}){super(),this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:t})=>{throw t},onPaste:()=>null,onDrop:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("contentError",this.options.onContentError),this.createView(),this.injectCSS(),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:t,slice:r,moved:i})=>this.options.onDrop(t,r,i)),this.on("paste",({event:t,slice:r})=>this.options.onPaste(t,r)),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=Ahe(khe,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.view||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const r=QH(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],i=this.state.reconfigure({plugins:r});return this.view.updateState(i),i}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let r=t;if([].concat(e).forEach(s=>{const o=typeof s=="string"?`${s}$`:s.key;r=r.filter(a=>!a.key.startsWith(o))}),t.length===r.length)return;const i=this.state.reconfigure({plugins:r});return this.view.updateState(i),i}createExtensionManager(){var e,t;const i=[...this.options.enableCoreExtensions?[The,Jue.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)===null||e===void 0?void 0:e.clipboardTextSerializer)===null||t===void 0?void 0:t.blockSeparator}),whe,_he,Phe,Mhe,Che,Ihe].filter(s=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[s.name]!==!1:!0):[],...this.options.extensions].filter(s=>["extension","node","mark"].includes(s?.type));this.extensionManager=new ud(i,this)}createCommandManager(){this.commandManager=new i0({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let t;try{t=CP(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(o){if(!(o instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(o.message))throw o;this.emit("contentError",{editor:this,error:o,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(a=>a.name!=="collaboration"),this.createExtensionManager()}}),t=CP(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const r=i$(t,this.options.autofocus);this.view=new zH(this.options.element,{...this.options.editorProps,attributes:{role:"textbox",...(e=this.options.editorProps)===null||e===void 0?void 0:e.attributes},dispatchTransaction:this.dispatchTransaction.bind(this),state:ff.create({doc:t,selection:r||void 0})});const i=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(i),this.createNodeViews(),this.prependClass();const s=this.view.dom;s.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(o=>{var a;return(a=this.capturedTransaction)===null||a===void 0?void 0:a.step(o)});return}const t=this.state.apply(e),r=!this.state.selection.eq(t.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),r&&this.emit("selectionUpdate",{editor:this,transaction:e});const i=e.getMeta("focus"),s=e.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:e}),s&&this.emit("blur",{editor:this,event:s.event,transaction:e}),!(!e.docChanged||e.getMeta("preventUpdate"))&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return c$(this.state,e)}isActive(e,t){const r=typeof e=="string"?e:null,i=typeof e=="string"?t:e;return ehe(this.state,r,i)}getJSON(){return this.state.doc.toJSON()}getHTML(){return o0(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
333
251
 
334
- `,textSerializers:r={}}=e||{};return l$(this.state.doc,{blockSeparator:t,textSerializers:{...G2(this.schema),...r}})}get isEmpty(){return Z2(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}$node(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelector(e,t))||null}$nodes(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new ad(t,this)}get $doc(){return this.$pos(0)}}function Rd(n){return new a0({find:n.find,handler:({state:e,range:t,match:r})=>{const i=wt(n.getAttributes,void 0,r);if(i===!1||i===null)return null;const{tr:s}=e,o=r[r.length-1],a=r[0];if(o){const l=a.search(/\S/),u=t.from+a.indexOf(o),f=u+o.length;if(X2(t.from,t.to,e.doc).filter(y=>y.mark.type.excluded.find(v=>v===n.type&&v!==y.mark.type)).filter(y=>y.to>u).length)return null;f<t.to&&s.delete(f,t.to),u>t.from&&s.delete(t.from+l,u);const g=t.from+l+o.length;s.addMark(t.from+l,g,n.type.create(i||{})),s.removeStoredMark(n.type)}}})}function Dhe(n){return new a0({find:n.find,handler:({state:e,range:t,match:r})=>{const i=wt(n.getAttributes,void 0,r)||{},{tr:s}=e,o=t.from;let a=t.to;const l=n.type.create(i);if(r[1]){const u=r[0].lastIndexOf(r[1]);let f=o+u;f>a?f=a:a=f+r[1].length;const h=r[0][r[0].length-1];s.insertText(h,o+r[0].length-1),s.replaceWith(f,a,l)}else if(r[0]){const u=n.type.isInline?o:o-1;s.insert(u,n.type.create(i)).delete(s.mapping.map(o),s.mapping.map(a))}s.scrollIntoView()}})}function EP(n){return new a0({find:n.find,handler:({state:e,range:t,match:r})=>{const i=e.doc.resolve(t.from),s=wt(n.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),n.type))return null;e.tr.delete(t.from,t.to).setBlockType(t.from,t.from,n.type,s)}})}function Em(n){return new a0({find:n.find,handler:({state:e,range:t,match:r,chain:i})=>{const s=wt(n.getAttributes,void 0,r)||{},o=e.tr.delete(t.from,t.to),l=o.doc.resolve(t.from).blockRange(),u=l&&k2(l,n.type,s);if(!u)return null;if(o.wrap(l,u),n.keepMarks&&n.editor){const{selection:h,storedMarks:g}=e,{splittableMarks:y}=n.editor.extensionManager,b=g||h.$to.parentOffset&&h.$from.marks();if(b){const v=b.filter(w=>y.includes(w.type.name));o.ensureMarks(v)}}if(n.keepAttributes){const h=n.type.name==="bulletList"||n.type.name==="orderedList"?"listItem":"taskList";i().updateAttributes(h,s).run()}const f=o.doc.resolve(t.from-1).nodeBefore;f&&f.type===n.type&&ku(o.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(r,f))&&o.join(t.from-1)}})}let Sa=class _P{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=wt($e(this,"addOptions",{name:this.name}))),this.storage=wt($e(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new _P(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>l0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new _P(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=wt($e(t,"addOptions",{name:t.name})),t.storage=wt($e(t,"addStorage",{name:t.name,options:t.options})),t}};function pu(n){return new Vue({find:n.find,handler:({state:e,range:t,match:r,pasteEvent:i})=>{const s=wt(n.getAttributes,void 0,r,i);if(s===!1||s===null)return null;const{tr:o}=e,a=r[r.length-1],l=r[0];let u=t.to;if(a){const f=l.search(/\S/),h=t.from+l.indexOf(a),g=h+a.length;if(X2(t.from,t.to,e.doc).filter(b=>b.mark.type.excluded.find(w=>w===n.type&&w!==b.mark.type)).filter(b=>b.to>h).length)return null;g<t.to&&o.delete(g,t.to),h>t.from&&o.delete(t.from+f,h),u=t.from+f+a.length,o.addMark(t.from+f,u,n.type.create(s||{})),o.removeStoredMark(n.type)}}})}function Rhe(n,e){const{selection:t}=n,{$from:r}=t;if(t instanceof We){const s=r.index();return r.parent.canReplaceWith(s,s+1,e)}let i=r.depth;for(;i>=0;){const s=r.index(i);if(r.node(i).contentMatchAt(s).matchType(e))return!0;i-=1}return!1}const jhe=new Ii;function Lhe(n){return jhe.get(n,()=>d0(n.extensions??[]))}function h0(n,e,t){const{tipTapConfig:r,addFontsFromNode:i}=n.getTextOptions();Be(r,"textOptions.tipTapConfig must be set to use rich text"),Be(i,"textOptions.addFontsFromNode must be set to use rich text");const s=Lhe(r),o=ha.fromJSON(s,e),a=new Set;function l(f){a.add(f)}function u(f,h){h=i(f,h,l);for(const g of f.children)u(g,h)}return u(o,t),Array.from(a)}async function Nhe({shouldReload:n=!0}={}){wZ();for(const e of gm.connectedInstances)await e.close();await Promise.all(E2().map(e=>JU(e))),vZ(),n&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Nhe);function zhe(n,e="_blank"){ey.openWindow(n,e)}xu("@tldraw/editor","4.1.2","esm");class Lt{static lineThroughPoints(e,t){const r=new Lt;r.moveTo(e[0].x,e[0].y,{...t,offset:t?.endOffsets??t?.offset});for(let i=1;i<e.length;i++){const s=i===e.length-1;r.lineTo(e[i].x,e[i].y,s?{offset:t?.endOffsets}:void 0)}return r}static cubicSplineThroughPoints(e,t){const r=new Lt,i=e.length,s=i-2,o=1.25;r.moveTo(e[0].x,e[0].y,{...t,offset:t?.endOffsets??t?.offset});for(let a=0;a<i-1;a++){const l=a===0?e[0]:e[a-1],u=e[a],f=e[a+1],h=a===s?f:e[a+2];let g,y,b,v;a===0?(g=l.x,y=l.y):(g=u.x+(f.x-l.x)/6*o,y=u.y+(f.y-l.y)/6*o);let w;a===s?(b=f.x,v=f.y,w={offset:t?.endOffsets}):(b=f.x-(h.x-u.x)/6*o,v=f.y-(h.y-u.y)/6*o),r.cubicBezierTo(f.x,f.y,g,y,b,v,w)}return r}constructor(){}commands=[];lastMoveTo=null;assertHasMoveTo(){return Be(this.lastMoveTo,"Start an SVGPathBuilder with `.moveTo()`"),this.lastMoveTo}moveTo(e,t,r){return this.lastMoveTo={type:"move",x:e,y:t,closeIdx:null,isClose:!1,opts:r},this.commands.push(this.lastMoveTo),this}lineTo(e,t,r){return this.assertHasMoveTo(),this.commands.push({type:"line",x:e,y:t,isClose:!1,opts:r}),this}circularArcTo(e,t,r,i,s,o){return this.arcTo(e,e,t,r,0,i,s,o)}arcTo(e,t,r,i,s,o,a,l){this.assertHasMoveTo();const u=this.commands[this.commands.length-1].x,f=this.commands[this.commands.length-1].y;if(u===o&&f===a)return this;if(e===0||t===0)return this.lineTo(o,a,l);const h=s,g=Math.sin(h),y=Math.cos(h);let b=Math.abs(e),v=Math.abs(t);const w=(u-o)/2,x=(f-a)/2,T=y*w+g*x,P=-g*w+y*x,M=T*T/(b*b)+P*P/(v*v);if(M>1){const ve=Math.sqrt(M);b*=ve,v*=ve}const k=r!==i?1:-1,A=b*b*v*v-b*b*P*P-v*v*T*T,O=b*b*P*P+v*v*T*T;let R=A/O;R=R<0?0:R;const F=k*Math.sqrt(R),z=F*(b*P/v),j=F*(-(v*T)/b),$=y*z-g*j+(u+o)/2,H=g*z+y*j+(f+a)/2,B=(T-z)/b,G=(P-j)/v,N=(-T-z)/b,Y=(-P-j)/v,W=Math.atan2(G,B);let Q=Math.atan2(Y,N);!i&&Q>W?Q-=2*Math.PI:i&&Q<W&&(Q+=2*Math.PI);const de=Q-W,U=Math.max(b,v)*Math.abs(de),re=Math.min(4,Math.ceil(Math.abs(de)/(Math.PI/2))),le=Math.ceil(Wv(U)/re),Se=de/re,fe=ve=>({x:$+b*Math.cos(ve)*y-v*Math.sin(ve)*g,y:H+b*Math.cos(ve)*g+v*Math.sin(ve)*y}),Me=ve=>({x:-b*Math.sin(ve)*y-v*Math.cos(ve)*g,y:-b*Math.sin(ve)*g+v*Math.cos(ve)*y});for(let ve=0;ve<re;ve++){const _e=W+ve*Se,Oe=W+(ve+1)*Se,He=Oe-_e,Bt=fe(_e),qt=fe(Oe),At=Me(_e),_t=Me(Oe),$t=4/3*Math.tan(He/4),Gn=Bt.x+$t*At.x,yr=Bt.y+$t*At.y,Er=qt.x-$t*_t.x,Hr=qt.y-$t*_t.y,li=ve===0?l:{...l,mergeWithPrevious:!0};this.cubicBezierToWithResolution(qt.x,qt.y,Gn,yr,Er,Hr,li,le)}return this}cubicBezierTo(e,t,r,i,s,o,a){return this.cubicBezierToWithResolution(e,t,r,i,s,o,a)}cubicBezierToWithResolution(e,t,r,i,s,o,a,l){return this.assertHasMoveTo(),this.commands.push({type:"cubic",x:e,y:t,cp1:{x:r,y:i},cp2:{x:s,y:o},isClose:!1,opts:a,resolution:l}),this}close(){const e=this.assertHasMoveTo(),t=this.commands[this.commands.length-1];return ir(e.x,t.x)&&ir(e.y,t.y)?t.isClose=!0:this.commands.push({type:"line",x:e.x,y:e.y,isClose:!0}),e.closeIdx=this.commands.length-1,this.lastMoveTo=null,this}toD(e={}){const{startIdx:t=0,endIdx:r=this.commands.length,onlyFilled:i=!1}=e,s=[];let o=!1,a=!1,l=!1;const u=f=>{if(a||f===0)return;a=!0;const h=this.commands[f-1];s.push("M",Z(h.x),Z(h.y))};for(let f=t;f<r;f++){const h=this.commands[f];switch(h.type){case"move":{const g=h.opts?.geometry===!1?!1:h.opts?.geometry?.isFilled??!1;i&&!g?o=!0:(o=!1,a=!0,l=!0,s.push("M",Z(h.x),Z(h.y)));break}case"line":if(o)break;u(f),h.isClose&&l?s.push("Z"):s.push("L",Z(h.x),Z(h.y));break;case"cubic":if(o)break;u(f),s.push("C",Z(h.cp1.x),Z(h.cp1.y),Z(h.cp2.x),Z(h.cp2.y),Z(h.x),Z(h.y));break;default:kt(h,"type")}}return s.join(" ")}toSvg(e){if(e.forceSolid)return this.toSolidSvg(e);switch(e.style){case"solid":return this.toSolidSvg(e);case"dashed":case"dotted":return this.toDashedSvg(e);case"draw":return this.toDrawSvg(e);default:kt(e,"style")}}toGeometry(){const e=[];let t=null;for(let r=0;r<this.commands.length;r++){const i=this.commands[r];i.type==="move"&&(t&&t.opts?.geometry!==!1&&e.push(new PP(this,t.startIdx,r,{...t.opts?.geometry,isFilled:t.opts?.geometry?.isFilled??!1,isClosed:t.moveCommand.closeIdx!==null})),t={startIdx:r,moveCommand:i,opts:i.opts,isClosed:!1}),i.isClose&&(Be(t,"No current move command"),t.isClosed=!0)}return t&&t.opts?.geometry!==!1&&e.push(new PP(this,t.startIdx,this.commands.length,{...t.opts?.geometry,isFilled:t.opts?.geometry?.isFilled??!1,isClosed:t.moveCommand.closeIdx!==null})),Be(e.length>0),e.length===1?e[0]:new Os({children:e})}toSolidSvg(e){const{strokeWidth:t,props:r}=e;return m.jsx("path",{strokeWidth:t,d:this.toD({onlyFilled:e.onlyFilled}),...r})}toDashedSvg(e){const{style:t,strokeWidth:r,snap:i,lengthRatio:s,props:{markerStart:o,markerEnd:a,...l}={}}=e,u=[];let f=!1,h=!1,g,y=null;const b=()=>{if(!y)return;const{startIdx:v,endIdx:w,isFirst:x,isLast:T,length:P,lineOpts:M,pathIsClosed:k}=y;if(y=null,v===w&&this.commands[v].type==="move")return;const A=M?.dashStart??e.start,O=M?.dashEnd??e.end,{strokeDasharray:R,strokeDashoffset:F}=qF(P,r,{style:t,snap:i,lengthRatio:s,start:x?A??(k?"outset":"none"):"outset",end:T?O??(k?"outset":"none"):"outset"}),z=this.toD({startIdx:v,endIdx:w+1});u.push(m.jsx("path",{d:z,strokeDasharray:R,strokeDashoffset:F,markerStart:x?o:void 0,markerEnd:T?a:void 0},u.length))};for(let v=0;v<this.commands.length;v++){const w=this.commands[v],x=this.commands[v-1];if(w.type==="move"){f=w.closeIdx!==null;const k=w.opts?.geometry===!1?!1:w.opts?.geometry?.isFilled??!1;e.onlyFilled&&!k?h=!0:(h=!1,g=w.opts);continue}if(h)continue;const T=this.calculateSegmentLength(x,w),P=x.type==="move",M=w.isClose||v===this.commands.length-1||this.commands[v+1]?.type==="move";y&&w.opts?.mergeWithPrevious?(y.length+=T,y.endIdx=v,y.isLast=M):(b(),y={startIdx:v,endIdx:v,isFirst:P,isLast:M,length:T,lineOpts:g,pathIsClosed:f})}return b(),m.jsx("g",{strokeWidth:r,...l,children:u})}toDrawSvg(e){return m.jsx("path",{strokeWidth:e.strokeWidth,d:this.toDrawD(e),...e.props})}toDrawD(e){const{strokeWidth:t,randomSeed:r,offset:i=t/3,roundness:s=t*2,passes:o=2,onlyFilled:a=!1}=e,l=[],u=this.getCommandInfo(),f=[];let h=null;for(let g=0;g<this.commands.length;g++){const y=this.commands[g],b=y.opts?.offset??i,v=y.opts?.roundness??s;y.type==="move"&&(h=g);const w=y.isClose?Mr(h)+1:!this.commands[g+1]||this.commands[g+1].type==="move"?void 0:g+1,x=w!==void 0&&this.commands[w]&&this.commands[w]?.type!=="move"?u[w]:void 0,T=x5[y.type],P=w!==void 0?x5[this.commands[w].type]:!1,M=u[g],k=M?.tangentEnd,A=x?.tangentStart,O=T&&P&&k&&A&&I.Len2(k)>.01&&I.Len2(A)>.01?pa(Math.abs(I.AngleBetween(k,A)),[Math.PI/2,Math.PI],[v,0],!0):0,F=Math.min(M?.length??1/0,x?.length??1/0)-O*2,z=st(b,0,F/4),j=Math.min(O,(M?.length??1/0)/4),$=Math.min(O,(x?.length??1/0)/4),H={command:y,offsetAmount:z,roundnessBefore:j,roundnessAfter:$,tangentToPrev:u[g]?.tangentEnd,tangentToNext:x?.tangentStart,moveDidClose:!1};if(f.push(H),y.isClose&&h!==null){const B=f[h];B.moveDidClose=!0,B.roundnessAfter=$}else y.type==="move"&&(h=g)}for(let g=0;g<o;g++){const y=Ud(r+g);let b={x:0,y:0},v=!1;for(const{command:w,offsetAmount:x,roundnessBefore:T,roundnessAfter:P,tangentToNext:M,tangentToPrev:k}of f){const A=w.isClose?b:{x:y()*x,y:y()*x};if(w.type==="move"){b=A;const z=w.opts?.geometry===!1?!1:w.opts?.geometry?.isFilled??!1;a&&!z?v=!0:v=!1}if(v)continue;const O=I.Add(w,A),R=M&&P>0?I.Mul(M,-P).add(O):O,F=k&&T>0?I.Mul(k,T).add(O):O;if(R===O||F===O)switch(w.type){case"move":l.push("M",Z(R.x),Z(R.y));break;case"line":l.push("L",Z(R.x),Z(R.y));break;case"cubic":{const z=I.Add(w.cp1,A),j=I.Add(w.cp2,A);l.push("C",Z(z.x),Z(z.y),Z(j.x),Z(j.y),Z(R.x),Z(R.y));break}default:kt(w,"type")}else switch(w.type){case"move":l.push("M",Z(R.x),Z(R.y));break;case"line":l.push("L",Z(F.x),Z(F.y),"Q",Z(O.x),Z(O.y),Z(R.x),Z(R.y));break;case"cubic":{const z=I.Add(w.cp1,A),j=I.Add(w.cp2,A);l.push("C",Z(z.x),Z(z.y),Z(j.x),Z(j.y),Z(O.x),Z(O.y));break}default:kt(w,"type")}}}return l.join(" ")}calculateSegmentLength(e,t){switch(t.type){case"move":return 0;case"line":return I.Dist(e,t);case"cubic":return Mg.length(e.x,e.y,t.cp1.x,t.cp1.y,t.cp2.x,t.cp2.y,t.x,t.y);default:kt(t,"type")}}getCommands(){return this.commands}getCommandInfo(){const e=[];for(let t=1;t<this.commands.length;t++){const r=this.commands[t-1],i=this.commands[t];if(i._info){e[t]=i._info;continue}if(i.type==="move")continue;let s,o;switch(i.type){case"line":s=o=I.Sub(r,i).uni();break;case"cubic":{s=I.Sub(i.cp1,r).uni(),o=I.Sub(i.cp2,i).uni();break}default:kt(i,"type")}i._info={tangentStart:s,tangentEnd:o,length:this.calculateSegmentLength(r,i)},e[t]=i._info}return e}}const x5={line:!0,move:!0,cubic:!1};class PP extends Iu{constructor(e,t,r,i){super(i),this.path=e,this.startIdx=t,this.endIdx=r}_segments=null;getSegments(){if(this._segments)return this._segments;this._segments=[];let e=this.path.commands[this.startIdx];Be(e.type==="move");for(let t=this.startIdx+1;t<this.endIdx;t++){const r=this.path.commands[t];switch(Be(r.type!=="move"),r.type){case"line":this._segments.push(new Df({start:I.From(e),end:I.From(r)}));break;case"cubic":{this._segments.push(new P2({start:I.From(e),cp1:I.From(r.cp1),cp2:I.From(r.cp2),end:I.From(r),resolution:r.resolution}));break}default:kt(r,"type")}e=r}return this._segments}getVertices(e){const t=this.getSegments().flatMap(r=>r.getVertices(e)).filter((r,i,s)=>{const o=s[i-1];return o?!I.Equals(o,r):!0});if(this.isClosed){const r=t[t.length-1],i=t[0];I.Equals(r,i)||t.push(i)}return t}nearestPoint(e,t){let r=null,i=1/0;for(const s of this.getSegments()){const o=s.nearestPoint(e),a=I.Dist2(e,o);a<i&&(i=a,r=o)}return Be(r,"No nearest point found"),r}hitTestLineSegment(e,t,r=0,i){return super.hitTestLineSegment(e,t,r,i)}getSvgPathData(){return this.path.toD({startIdx:this.startIdx,endIdx:this.endIdx})}}/*!
335
- * Adapted from https://github.com/adobe-webplatform/Snap.svg/tree/master
336
- * Apache License: https://github.com/adobe-webplatform/Snap.svg/blob/master/LICENSE
337
- * https://github.com/adobe-webplatform/Snap.svg/blob/c8e483c9694517e24b282f8f59f985629f4994ce/dist/snap.svg.js#L5786
338
- */const Mg={base3(n,e,t,r,i){const s=-3*e+9*t-9*r+3*i,o=n*s+6*e-12*t+6*r;return n*o-3*e+3*t},length(n,e,t,r,i,s,o,a,l=1){l=l>1?1:l<0?0:l;const u=l/2,f=12;let h=0;h=0;for(let g=0;g<f;g++){const y=u*Mg.Tvalues[g]+u,b=Mg.base3(y,n,t,i,o),v=Mg.base3(y,e,r,s,a),w=b*b+v*v;h+=Mg.Cvalues[g]*Math.sqrt(w)}return u*h},Tvalues:[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],Cvalues:[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472]};function u$(){const n=Vn(),e=ee("animationSpeed",()=>n?.user.getAnimationSpeed(),[n]),[t,r]=E.useState(!1);return E.useEffect(()=>{if(e!==void 0){r(e===0);return}if(typeof window>"u"||!("matchMedia"in window))return;const i=window.matchMedia("(prefers-reduced-motion: reduce)"),s=()=>{r(i.matches)};return s(),i.addEventListener("change",s),()=>i.removeEventListener("change",s)},[e]),t}const IP=E.createContext(null);function Bhe({children:n}){const e=Wm("a11y",{msg:"",priority:"assertive"}),t=E.useContext(IP),r=E.useMemo(()=>({currentMsg:e,announce(i){i&&e.set(i)}}),[e]);return t?m.jsx(m.Fragment,{children:n}):m.jsx(IP.Provider,{value:r,children:n})}function f0(){const n=E.useContext(IP);if(!n)throw new Error("useA11y must be used within a A11yContext.Provider");return n}const d$=E.createContext(null);function h$({assetUrls:n,children:e}){return E.useEffect(()=>{for(const t of Object.values(n.icons)){if(!t)continue;const r=am();r.crossOrigin="anonymous",r.src=t,r.decode()}for(const t of Object.values(n.embedIcons)){if(!t)continue;const r=am();r.crossOrigin="anonymous",r.src=t,r.decode()}},[n]),m.jsx(d$.Provider,{value:n,children:e})}function J2(){const n=E.useContext(d$);if(!n)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return n}const MP={"action.toggle-auto-pan":"Auto (trackpad)","action.toggle-auto-zoom":"Auto (mouse)","action.toggle-auto-none":"Auto","action.toggle-mouse":"Mouse","action.toggle-trackpad":"Trackpad","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-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.download-original":"Download original","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","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-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-kbd-shortcuts":"Open keyboard shortcuts","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-keyboard-shortcuts.menu":"Enable keyboard shortcuts","action.toggle-keyboard-shortcuts":"Toggle keyboard shortcuts","action.enhanced-a11y-mode.menu":"Enhanced accessibility mode","action.enhanced-a11y-mode":"Toggle enhanced accessibility mode","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.maximum-size":"Maximum file size is {size}","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.files.amount-too-many":"Too many files","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.cloud":"Cloud","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.heart":"Heart","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus":"Rhombus","geo-style.rhombus-2":"Rhombus left","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","arrow-kind-style.arc":"Arc","arrow-kind-style.elbow":"Elbow","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.heart":"Heart","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.media":"Media","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","tool.pointer-down":"Pointer down","tool.image-zoom":"Zoom","tool.replace-media":"Replace media","tool.flip-horz":"Flip horizontally","tool.flip-vert":"Flip vertically","tool.rotate-cw":"Rotate","tool.aspect-ratio":"Aspect ratio","tool.aspect-ratio.original":"Original","tool.aspect-ratio.square":"Square (1:1)","tool.aspect-ratio.circle":"Circle (1:1)","tool.aspect-ratio.landscape":"Landscape (4:3)","tool.aspect-ratio.portrait":"Portrait (3:4)","tool.aspect-ratio.wide":"Wide (16:9)","tool.image-toolbar-title":"Image tools","tool.image-crop":"Crop image","tool.image-crop-confirm":"Confirm","tool.media-alt-text":"Alternative text","tool.media-alt-text-desc":"Give a description…","tool.media-alt-text-confirm":"Confirm","tool.rich-text-bold":"Bold","tool.rich-text-italic":"Italic","tool.rich-text-code":"Code","tool.rich-text-highlight":"Highlight","tool.rich-text-strikethrough":"Strikethrough","tool.rich-text-link":"Link","tool.rich-text-link-visit":"Visit link","tool.rich-text-link-remove":"Remove link","tool.rich-text-header":"Header","tool.rich-text-bulletList":"Bulleted list","tool.rich-text-toolbar-title":"Text formatting","tool.rich-text-orderedList":"Ordered list","tool.bookmark":"Bookmark","a11y.status":"Status","a11y.skip-to-main-content":"Move focus to canvas","a11y.shape-index":"{num} of {total}","a11y.shape-image":"Image","a11y.shape-video":"Video","a11y.multiple-shapes":"{num} shapes selected","a11y.select-shape":"Select next shape","a11y.select-shape-direction":"Select shape in direction","a11y.enter-leave-container":"Enter/leave container","a11y.repeat-shape":"Repeat shape","a11y.move-shape":"Move shape","a11y.move-shape-faster":"Move shape faster","a11y.rotate-shape-cw":"Rotate shape clockwise","a11y.rotate-shape-ccw":"Rotate shape counterclockwise","a11y.rotate-shape-cw-fine":"Rotate shape clockwise (fine)","a11y.rotate-shape-ccw-fine":"Rotate shape counterclockwise (fine)","a11y.enlarge-shape":"Enlarge shape","a11y.shrink-shape":"Shrink shape","a11y.pan-camera":"Pan camera","a11y.adjust-shape-styles":"Adjust shape styles","a11y.open-context-menu":"Open context menu","a11y.open-keyboard-shortcuts":"Open keyboard shortcuts","menu.title":"Menu","menu.theme":"Theme","menu.accessibility":"Accessibility","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.view":"View","menu.input-mode":"Input mode","context-menu.title":"Context menu","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.copy-link":"Copy editor link","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","document-name-menu.copy-link":"Copy link","status.offline":"Offline","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.avatar-color":"Avatar color","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","people-menu.anonymous-user":"New user","help-menu.import-tldr-file":"Import file…","help-menu.title":"Help and resources","help-menu.about":"About tldraw","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","help-menu.terms":"Terms of service","help-menu.privacy":"Privacy policy","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","edit-link-dialog.external-link":"External link","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.","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","shortcuts-dialog.a11y":"Accessibility","shortcuts-dialog.text-formatting":"Text formatting","style-panel.title":"Styles","style-panel.align":"Align","style-panel.label-align":"Label 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.arrow-kind":"Line","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","style-panel.selected":"selected","tool-panel.title":"Tools","tool-panel.more":"More","navigation-zone.title":"Navigation","navigation-zone.minimap":"Minimap","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","toast.success":"Success","toast.error":"Error","toast.info":"Info","toast.warning":"Warning","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…","app.loading":"Loading tldraw…","handle.resize-top":"Resize top","handle.resize-bottom":"Resize bottom","handle.resize-left":"Resize left","handle.resize-right":"Resize right","handle.resize-top-left":"Resize top left","handle.resize-top-right":"Resize top right","handle.resize-bottom-left":"Resize bottom left","handle.resize-bottom-right":"Resize bottom right","handle.rotate.top_left_rotate":"Rotate top left","handle.rotate.top_right_rotate":"Rotate top right","handle.rotate.bottom_left_rotate":"Rotate bottom left","handle.rotate.bottom_right_rotate":"Rotate bottom right","handle.rotate.mobile_rotate":"Rotate","handle.crop.top":"Crop top","handle.crop.bottom":"Crop bottom","handle.crop.left":"Crop left","handle.crop.right":"Crop right","handle.crop.top-left":"Crop top left","handle.crop.top-right":"Crop top right","handle.crop.bottom-left":"Crop bottom left","handle.crop.bottom-right":"Crop bottom right","ui.close":"Close","ui.checked":"Checked","ui.unchecked":"Unchecked"},Fhe=new Set(["ar","fa","he","ur","ku"]),Yh={locale:"en",label:"English",messages:MP,dir:"ltr"};async function Uhe(n,e){if(!(await Gl(e.translations.en)).ok)return console.warn("No main translations found."),Yh;if(n==="en")return Yh;const r=dm.find(o=>o.locale===n);if(!r)return console.warn(`No translation found for locale ${n}`),Yh;const s=await(await Gl(e.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${n}`),Yh;for(const o in Yh.messages)s[o];return{locale:n,label:r.label,dir:Fhe.has(r.locale)?"rtl":"ltr",messages:{...Yh.messages,...s}}}const f$=E.createContext(null);function p$(){const n=E.useContext(f$);if(!n)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return n}function g$({overrides:n,locale:e,children:t}){const r=J2(),[i,s]=E.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...MP,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:MP});return E.useEffect(()=>{let o=!1;async function a(){const l=await Uhe(e,r);l&&!o&&(n&&n[e]?s({...l,messages:{...l.messages,...n[e]}}):s(l))}return a(),()=>{o=!0}},[r,e,n]),m.jsx(f$.Provider,{value:i,children:t})}function Ne(){const n=p$();return E.useCallback(function(t){return n.messages[t]??t},[n])}const Hhe={normal:"tlui-button__normal",primary:"tlui-button__primary",danger:"tlui-button__danger",low:"tlui-button__low",icon:"tlui-button__icon",tool:"tlui-button__tool",menu:"tlui-button__menu",help:"tlui-button__help"},gt=E.forwardRef(function({children:e,type:t,isActive:r,...i},s){return m.jsx("button",{ref:s,type:"button",draggable:!1,"data-isactive":r,...i,className:Fe("tlui-button",Hhe[t],i.className),children:e})});function $he(){const n=te(),e=Ne(),t=E.useRef(null),r=E.useCallback(i=>{n.markEventAsHandled(i),t.current?.blur();const s=n.getCurrentPageShapesInReadingOrder();s.length&&(n.setSelectedShapes([s[0].id]),n.zoomToSelectionIfOffscreen(256,{animation:{duration:n.options.animationMediumMs},inset:0}),n.timers.setTimeout(()=>n.getContainer().focus(),100))},[n]);return m.jsx(gt,{ref:t,type:"low",tabIndex:0,className:"tl-skip-to-main-content",onClick:r,children:e("a11y.skip-to-main-content")})}const Khe=E.memo(function(){const e=f0(),t=Ne(),r=ee("a11y-msg",()=>e.currentMsg.get(),[]);return Vhe(r.msg),qhe(),r.msg&&m.jsx("div",{"aria-label":t("a11y.status"),"aria-live":r.priority||"assertive",role:"status","aria-hidden":"false",style:{position:"absolute",top:"-10000px",left:"-10000px"},children:r.msg})});function m$(n){const{editor:e,selectedShapeIds:t,msg:r}=n;let i="";const s=t.length;if(s>1)i=r("a11y.multiple-shapes").replace("{num}",s.toString());else if(s===1){const o=t[0],a=e.getShape(o);if(!a)return"";const l=e.getShapeUtil(a.type),u=["image","video"].includes(a.type);let f="";a.type==="geo"?f=r(`geo-style.${a.props.geo}`):u?f=r(`a11y.shape-${a.type}`):f=r(`tool.${a.type}`);const h=e.getCurrentPageShapesInReadingOrder(),g=(h.findIndex(w=>w.id===o)+1).toString(),y=h.length.toString(),b=r("a11y.shape-index").replace("{num}",g).replace("{total}",y),v=l.getAriaDescriptor(a)||l.getText(a)||"";i=(v?`${v}, `:"")+`${f}. ${b}`}return i}const qhe=()=>{const n=Vn(),e=f0(),t=Ne(),r=E.useRef([]);NI("announce selection",()=>{if(!n)return;if(n.isIn("select.idle")){const s=n.getSelectedShapeIds();s!==r.current&&(r.current=s,Cg(()=>{const o=m$({editor:n,selectedShapeIds:s,msg:t});o&&e.announce({msg:o})}))}},[n,e,t])},Vhe=n=>{const e=or();E.useEffect(()=>{if(In.a11y.get()){const t=i=>{console.debug(`%ca11y%c: ${i}`,"color: white; background: #40C057; padding: 2px;border-radius: 3px;","font-weight: normal")},r=i=>{const s=document.activeElement;if(i.key==="Tab"&&s&&s!==document.body&&!s.classList.contains("tl-container")){const o=s.getAttribute("aria-label")||s.getAttribute("title")||s.textContent;o&&t(o)}};return n&&t(n),document.addEventListener("keyup",r),()=>document.removeEventListener("keyup",r)}},[e,n])};function Ghe(n,e){const t=tt(e.map(i=>n.getShape(i)).filter(i=>i&&n.isShapeOfType(i,"frame")));if(!t.length)return;const r=[];n.run(()=>{t.map(i=>{const s=n.getSortedChildIdsForParent(i.id);s.length&&(Xt(n,s,{filter:o=>!t.find(a=>a.id===o.id)}),r.push(...s))}),n.setSelectedShapes(r),n.deleteShapes(e)})}const v5=50;function y$(n,e,t={padding:v5}){const r=we.FromPoints(n.flatMap(u=>{if(!u)return[];const f=e.getShapeGeometry(u.id);return e.getShapeLocalTransform(u)?.applyToPoints(f.vertices)??[]})),i=t.padding??v5,s=r.w+2*i,o=r.h+2*i,a=i-r.minX,l=i-r.minY;return{w:s,h:o,dx:a,dy:l}}function S$(n,e,t={}){const r=n.getShape(e);if(!r)return;const i=n.getSortedChildIdsForParent(r.id),s=tt(i.map(h=>n.getShape(h)));if(!s.length)return;const{w:o,h:a,dx:l,dy:u}=y$(s,n,t);if(l===0&&u===0&&r.props.w===o&&r.props.h===a)return;const f=new I(l,u).rot(r.rotation);n.run(()=>{const h=i.map(g=>{const y=n.getShape(g);return{id:y.id,type:y.type,x:y.x+l,y:y.y+u}});h.push({id:r.id,type:r.type,x:r.x-f.x,y:r.y-f.y,props:{w:o,h:a}}),n.updateShapes(h)})}function nr({children:n}){return m.jsx("span",{className:"tlui-button__label",children:n})}function w5(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function p0(...n){return e=>{let t=!1;const r=n.map(i=>{const s=w5(i,e);return!t&&typeof s=="function"&&(t=!0),s});if(t)return()=>{for(let i=0;i<r.length;i++){const s=r[i];typeof s=="function"?s():w5(n[i],null)}}}}function Jt(...n){return E.useCallback(p0(...n),n)}function jd(n){const e=Yhe(n),t=E.forwardRef((r,i)=>{const{children:s,...o}=r,a=E.Children.toArray(s),l=a.find(Xhe);if(l){const u=l.props.children,f=a.map(h=>h===l?E.Children.count(u)>1?E.Children.only(null):E.isValidElement(u)?u.props.children:null:h);return m.jsx(e,{...o,ref:i,children:E.isValidElement(u)?E.cloneElement(u,void 0,f):null})}return m.jsx(e,{...o,ref:i,children:s})});return t.displayName=`${n}.Slot`,t}var Q2=jd("Slot");function Yhe(n){const e=E.forwardRef((t,r)=>{const{children:i,...s}=t;if(E.isValidElement(i)){const o=Jhe(i),a=Zhe(s,i.props);return i.type!==E.Fragment&&(a.ref=r?p0(r,o):o),E.cloneElement(i,a)}return E.Children.count(i)>1?E.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var b$=Symbol("radix.slottable");function Whe(n){const e=({children:t})=>m.jsx(m.Fragment,{children:t});return e.displayName=`${n}.Slottable`,e.__radixId=b$,e}function Xhe(n){return E.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===b$}function Zhe(n,e){const t={...e};for(const r in e){const i=n[r],s=e[r];/^on[A-Z]/.test(r)?i&&s?t[r]=(...a)=>{const l=s(...a);return i(...a),l}:i&&(t[r]=i):r==="style"?t[r]={...i,...s}:r==="className"&&(t[r]=[i,s].filter(Boolean).join(" "))}return{...n,...t}}function Jhe(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}var Qhe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ht=Qhe.reduce((n,e)=>{const t=jd(`Primitive.${e}`),r=E.forwardRef((i,s)=>{const{asChild:o,...a}=i,l=o?t:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),m.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${e}`,{...n,[e]:r}},{});function eM(n,e){n&&Gd.flushSync(()=>n.dispatchEvent(e))}var efe=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),tfe="VisuallyHidden",g0=E.forwardRef((n,e)=>m.jsx(ht.span,{...n,ref:e,style:{...efe,...n.style}}));g0.displayName=tfe;var nfe=g0;function rfe(n,e){const t=E.createContext(e),r=s=>{const{children:o,...a}=s,l=E.useMemo(()=>a,Object.values(a));return m.jsx(t.Provider,{value:l,children:o})};r.displayName=n+"Provider";function i(s){const o=E.useContext(t);if(o)return o;if(e!==void 0)return e;throw new Error(`\`${s}\` must be used within \`${n}\``)}return[r,i]}function uo(n,e=[]){let t=[];function r(s,o){const a=E.createContext(o),l=t.length;t=[...t,o];const u=h=>{const{scope:g,children:y,...b}=h,v=g?.[n]?.[l]||a,w=E.useMemo(()=>b,Object.values(b));return m.jsx(v.Provider,{value:w,children:y})};u.displayName=s+"Provider";function f(h,g){const y=g?.[n]?.[l]||a,b=E.useContext(y);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[u,f]}const i=()=>{const s=t.map(o=>E.createContext(o));return function(a){const l=a?.[n]||s;return E.useMemo(()=>({[`__scope${n}`]:{...a,[n]:l}}),[a,l])}};return i.scopeName=n,[r,ife(i,...e)]}function ife(...n){const e=n[0];if(n.length===1)return e;const t=()=>{const r=n.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(s){const o=r.reduce((a,{useScope:l,scopeName:u})=>{const h=l(s)[`__scope${u}`];return{...a,...h}},{});return E.useMemo(()=>({[`__scope${e.scopeName}`]:o}),[o])}};return t.scopeName=e.scopeName,t}function m0(n){const e=n+"CollectionProvider",[t,r]=uo(e),[i,s]=t(e,{collectionRef:{current:null},itemMap:new Map}),o=v=>{const{scope:w,children:x}=v,T=Ge.useRef(null),P=Ge.useRef(new Map).current;return m.jsx(i,{scope:w,itemMap:P,collectionRef:T,children:x})};o.displayName=e;const a=n+"CollectionSlot",l=jd(a),u=Ge.forwardRef((v,w)=>{const{scope:x,children:T}=v,P=s(a,x),M=Jt(w,P.collectionRef);return m.jsx(l,{ref:M,children:T})});u.displayName=a;const f=n+"CollectionItemSlot",h="data-radix-collection-item",g=jd(f),y=Ge.forwardRef((v,w)=>{const{scope:x,children:T,...P}=v,M=Ge.useRef(null),k=Jt(w,M),A=s(f,x);return Ge.useEffect(()=>(A.itemMap.set(M,{ref:M,...P}),()=>void A.itemMap.delete(M))),m.jsx(g,{[h]:"",ref:k,children:T})});y.displayName=f;function b(v){const w=s(n+"CollectionConsumer",v);return Ge.useCallback(()=>{const T=w.collectionRef.current;if(!T)return[];const P=Array.from(T.querySelectorAll(`[${h}]`));return Array.from(w.itemMap.values()).sort((A,O)=>P.indexOf(A.ref.current)-P.indexOf(O.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:u,ItemSlot:y},b,r]}function Re(n,e,{checkForDefaultPrevented:t=!0}={}){return function(i){if(n?.(i),t===!1||!i.defaultPrevented)return e?.(i)}}var Wl=globalThis?.document?E.useLayoutEffect:()=>{},sfe=SB[" useInsertionEffect ".trim().toString()]||Wl;function qo({prop:n,defaultProp:e,onChange:t=()=>{},caller:r}){const[i,s,o]=ofe({defaultProp:e,onChange:t}),a=n!==void 0,l=a?n:i;{const f=E.useRef(n!==void 0);E.useEffect(()=>{const h=f.current;h!==a&&console.warn(`${r} is changing from ${h?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=a},[a,r])}const u=E.useCallback(f=>{if(a){const h=afe(f)?f(n):f;h!==n&&o.current?.(h)}else s(f)},[a,n,s,o]);return[l,u]}function ofe({defaultProp:n,onChange:e}){const[t,r]=E.useState(n),i=E.useRef(t),s=E.useRef(e);return sfe(()=>{s.current=e},[e]),E.useEffect(()=>{i.current!==t&&(s.current?.(t),i.current=t)},[t,i]),[t,r,s]}function afe(n){return typeof n=="function"}function lfe(n,e){return E.useReducer((t,r)=>e[t][r]??t,n)}var Vo=n=>{const{present:e,children:t}=n,r=cfe(e),i=typeof t=="function"?t({present:r.isPresent}):E.Children.only(t),s=Jt(r.ref,ufe(i));return typeof t=="function"||r.isPresent?E.cloneElement(i,{ref:s}):null};Vo.displayName="Presence";function cfe(n){const[e,t]=E.useState(),r=E.useRef(null),i=E.useRef(n),s=E.useRef("none"),o=n?"mounted":"unmounted",[a,l]=lfe(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return E.useEffect(()=>{const u=ZS(r.current);s.current=a==="mounted"?u:"none"},[a]),Wl(()=>{const u=r.current,f=i.current;if(f!==n){const g=s.current,y=ZS(u);n?l("MOUNT"):y==="none"||u?.display==="none"?l("UNMOUNT"):l(f&&g!==y?"ANIMATION_OUT":"UNMOUNT"),i.current=n}},[n,l]),Wl(()=>{if(e){let u;const f=e.ownerDocument.defaultView??window,h=y=>{const v=ZS(r.current).includes(CSS.escape(y.animationName));if(y.target===e&&v&&(l("ANIMATION_END"),!i.current)){const w=e.style.animationFillMode;e.style.animationFillMode="forwards",u=f.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=w)})}},g=y=>{y.target===e&&(s.current=ZS(r.current))};return e.addEventListener("animationstart",g),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{f.clearTimeout(u),e.removeEventListener("animationstart",g),e.removeEventListener("animationcancel",h),e.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:E.useCallback(u=>{r.current=u?getComputedStyle(u):null,t(u)},[])}}function ZS(n){return n?.animationName||"none"}function ufe(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}var dfe=SB[" useId ".trim().toString()]||(()=>{}),hfe=0;function $a(n){const[e,t]=E.useState(dfe());return Wl(()=>{t(r=>r??String(hfe++))},[n]),e?`radix-${e}`:""}var ffe=E.createContext(void 0);function fy(n){const e=E.useContext(ffe);return n||e||"ltr"}function ts(n){const e=E.useRef(n);return E.useEffect(()=>{e.current=n}),E.useMemo(()=>(...t)=>e.current?.(...t),[])}function pfe(n,e=globalThis?.document){const t=ts(n);E.useEffect(()=>{const r=i=>{i.key==="Escape"&&t(i)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[t,e])}var gfe="DismissableLayer",kP="dismissableLayer.update",mfe="dismissableLayer.pointerDownOutside",yfe="dismissableLayer.focusOutside",C5,x$=E.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),rp=E.forwardRef((n,e)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:i,onFocusOutside:s,onInteractOutside:o,onDismiss:a,...l}=n,u=E.useContext(x$),[f,h]=E.useState(null),g=f?.ownerDocument??globalThis?.document,[,y]=E.useState({}),b=Jt(e,O=>h(O)),v=Array.from(u.layers),[w]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(w),T=f?v.indexOf(f):-1,P=u.layersWithOutsidePointerEventsDisabled.size>0,M=T>=x,k=bfe(O=>{const R=O.target,F=[...u.branches].some(z=>z.contains(R));!M||F||(i?.(O),o?.(O),O.defaultPrevented||a?.())},g),A=xfe(O=>{const R=O.target;[...u.branches].some(z=>z.contains(R))||(s?.(O),o?.(O),O.defaultPrevented||a?.())},g);return pfe(O=>{T===u.layers.size-1&&(r?.(O),!O.defaultPrevented&&a&&(O.preventDefault(),a()))},g),E.useEffect(()=>{if(f)return t&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(C5=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(f)),u.layers.add(f),T5(),()=>{t&&u.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=C5)}},[f,g,t,u]),E.useEffect(()=>()=>{f&&(u.layers.delete(f),u.layersWithOutsidePointerEventsDisabled.delete(f),T5())},[f,u]),E.useEffect(()=>{const O=()=>y({});return document.addEventListener(kP,O),()=>document.removeEventListener(kP,O)},[]),m.jsx(ht.div,{...l,ref:b,style:{pointerEvents:P?M?"auto":"none":void 0,...n.style},onFocusCapture:Re(n.onFocusCapture,A.onFocusCapture),onBlurCapture:Re(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:Re(n.onPointerDownCapture,k.onPointerDownCapture)})});rp.displayName=gfe;var Sfe="DismissableLayerBranch",v$=E.forwardRef((n,e)=>{const t=E.useContext(x$),r=E.useRef(null),i=Jt(e,r);return E.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),m.jsx(ht.div,{...n,ref:i})});v$.displayName=Sfe;function bfe(n,e=globalThis?.document){const t=ts(n),r=E.useRef(!1),i=E.useRef(()=>{});return E.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){w$(mfe,t,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",i.current),i.current=l,e.addEventListener("click",i.current,{once:!0})):l()}else e.removeEventListener("click",i.current);r.current=!1},o=window.setTimeout(()=>{e.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(o),e.removeEventListener("pointerdown",s),e.removeEventListener("click",i.current)}},[e,t]),{onPointerDownCapture:()=>r.current=!0}}function xfe(n,e=globalThis?.document){const t=ts(n),r=E.useRef(!1);return E.useEffect(()=>{const i=s=>{s.target&&!r.current&&w$(yfe,t,{originalEvent:s},{discrete:!1})};return e.addEventListener("focusin",i),()=>e.removeEventListener("focusin",i)},[e,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function T5(){const n=new CustomEvent(kP);document.dispatchEvent(n)}function w$(n,e,t,{discrete:r}){const i=t.originalEvent.target,s=new CustomEvent(n,{bubbles:!1,cancelable:!0,detail:t});e&&i.addEventListener(n,e,{once:!0}),r?eM(i,s):i.dispatchEvent(s)}var vfe=rp,wfe=v$,QE="focusScope.autoFocusOnMount",e_="focusScope.autoFocusOnUnmount",E5={bubbles:!1,cancelable:!0},Cfe="FocusScope",y0=E.forwardRef((n,e)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:s,...o}=n,[a,l]=E.useState(null),u=ts(i),f=ts(s),h=E.useRef(null),g=Jt(e,v=>l(v)),y=E.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;E.useEffect(()=>{if(r){let v=function(P){if(y.paused||!a)return;const M=P.target;a.contains(M)?h.current=M:Kc(h.current,{select:!0})},w=function(P){if(y.paused||!a)return;const M=P.relatedTarget;M!==null&&(a.contains(M)||Kc(h.current,{select:!0}))},x=function(P){if(document.activeElement===document.body)for(const k of P)k.removedNodes.length>0&&Kc(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",w);const T=new MutationObserver(x);return a&&T.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",w),T.disconnect()}}},[r,a,y.paused]),E.useEffect(()=>{if(a){P5.add(y);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(QE,E5);a.addEventListener(QE,u),a.dispatchEvent(x),x.defaultPrevented||(Tfe(Mfe(C$(a)),{select:!0}),document.activeElement===v&&Kc(a))}return()=>{a.removeEventListener(QE,u),setTimeout(()=>{const x=new CustomEvent(e_,E5);a.addEventListener(e_,f),a.dispatchEvent(x),x.defaultPrevented||Kc(v??document.body,{select:!0}),a.removeEventListener(e_,f),P5.remove(y)},0)}}},[a,u,f,y]);const b=E.useCallback(v=>{if(!t&&!r||y.paused)return;const w=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(w&&x){const T=v.currentTarget,[P,M]=Efe(T);P&&M?!v.shiftKey&&x===M?(v.preventDefault(),t&&Kc(P,{select:!0})):v.shiftKey&&x===P&&(v.preventDefault(),t&&Kc(M,{select:!0})):x===T&&v.preventDefault()}},[t,r,y.paused]);return m.jsx(ht.div,{tabIndex:-1,...o,ref:g,onKeyDown:b})});y0.displayName=Cfe;function Tfe(n,{select:e=!1}={}){const t=document.activeElement;for(const r of n)if(Kc(r,{select:e}),document.activeElement!==t)return}function Efe(n){const e=C$(n),t=_5(e,n),r=_5(e.reverse(),n);return[t,r]}function C$(n){const e=[],t=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;t.nextNode();)e.push(t.currentNode);return e}function _5(n,e){for(const t of n)if(!_fe(t,{upTo:e}))return t}function _fe(n,{upTo:e}){if(getComputedStyle(n).visibility==="hidden")return!0;for(;n;){if(e!==void 0&&n===e)return!1;if(getComputedStyle(n).display==="none")return!0;n=n.parentElement}return!1}function Pfe(n){return n instanceof HTMLInputElement&&"select"in n}function Kc(n,{select:e=!1}={}){if(n&&n.focus){const t=document.activeElement;n.focus({preventScroll:!0}),n!==t&&Pfe(n)&&e&&n.select()}}var P5=Ife();function Ife(){let n=[];return{add(e){const t=n[0];e!==t&&t?.pause(),n=I5(n,e),n.unshift(e)},remove(e){n=I5(n,e),n[0]?.resume()}}}function I5(n,e){const t=[...n],r=t.indexOf(e);return r!==-1&&t.splice(r,1),t}function Mfe(n){return n.filter(e=>e.tagName!=="A")}var kfe="Portal",py=E.forwardRef((n,e)=>{const{container:t,...r}=n,[i,s]=E.useState(!1);Wl(()=>s(!0),[]);const o=t||i&&globalThis?.document?.body;return o?qte.createPortal(m.jsx(ht.div,{...r,ref:e}),o):null});py.displayName=kfe;var t_=0;function tM(){E.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??M5()),document.body.insertAdjacentElement("beforeend",n[1]??M5()),t_++,()=>{t_===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),t_--}},[])}function M5(){const n=document.createElement("span");return n.setAttribute("data-radix-focus-guard",""),n.tabIndex=0,n.style.outline="none",n.style.opacity="0",n.style.position="fixed",n.style.pointerEvents="none",n}var Na=function(){return Na=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++){t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},Na.apply(this,arguments)};function T$(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(n);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(t[r[i]]=n[r[i]]);return t}function Afe(n,e,t){if(t||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return n.concat(s||Array.prototype.slice.call(e))}var Nb="right-scroll-bar-position",zb="width-before-scroll-bar",Ofe="with-scroll-bars-hidden",Dfe="--removed-body-scroll-bar-size";function n_(n,e){return typeof n=="function"?n(e):n&&(n.current=e),n}function Rfe(n,e){var t=E.useState(function(){return{value:n,callback:e,facade:{get current(){return t.value},set current(r){var i=t.value;i!==r&&(t.value=r,t.callback(r,i))}}}})[0];return t.callback=e,t.facade}var jfe=typeof window<"u"?E.useLayoutEffect:E.useEffect,k5=new WeakMap;function Lfe(n,e){var t=Rfe(null,function(r){return n.forEach(function(i){return n_(i,r)})});return jfe(function(){var r=k5.get(t);if(r){var i=new Set(r),s=new Set(n),o=t.current;i.forEach(function(a){s.has(a)||n_(a,null)}),s.forEach(function(a){i.has(a)||n_(a,o)})}k5.set(t,n)},[n]),t}function Nfe(n){return n}function zfe(n,e){e===void 0&&(e=Nfe);var t=[],r=!1,i={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return t.length?t[t.length-1]:n},useMedium:function(s){var o=e(s,r);return t.push(o),function(){t=t.filter(function(a){return a!==o})}},assignSyncMedium:function(s){for(r=!0;t.length;){var o=t;t=[],o.forEach(s)}t={push:function(a){return s(a)},filter:function(){return t}}},assignMedium:function(s){r=!0;var o=[];if(t.length){var a=t;t=[],a.forEach(s),o=t}var l=function(){var f=o;o=[],f.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),t={push:function(f){o.push(f),u()},filter:function(f){return o=o.filter(f),t}}}};return i}function Bfe(n){n===void 0&&(n={});var e=zfe(null);return e.options=Na({async:!0,ssr:!1},n),e}var E$=function(n){var e=n.sideCar,t=T$(n,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return E.createElement(r,Na({},t))};E$.isSideCarExport=!0;function Ffe(n,e){return n.useMedium(e),E$}var _$=Bfe(),r_=function(){},S0=E.forwardRef(function(n,e){var t=E.useRef(null),r=E.useState({onScrollCapture:r_,onWheelCapture:r_,onTouchMoveCapture:r_}),i=r[0],s=r[1],o=n.forwardProps,a=n.children,l=n.className,u=n.removeScrollBar,f=n.enabled,h=n.shards,g=n.sideCar,y=n.noRelative,b=n.noIsolation,v=n.inert,w=n.allowPinchZoom,x=n.as,T=x===void 0?"div":x,P=n.gapMode,M=T$(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=g,A=Lfe([t,e]),O=Na(Na({},M),i);return E.createElement(E.Fragment,null,f&&E.createElement(k,{sideCar:_$,removeScrollBar:u,shards:h,noRelative:y,noIsolation:b,inert:v,setCallbacks:s,allowPinchZoom:!!w,lockRef:t,gapMode:P}),o?E.cloneElement(E.Children.only(a),Na(Na({},O),{ref:A})):E.createElement(T,Na({},O,{className:l,ref:A}),a))});S0.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};S0.classNames={fullWidth:zb,zeroRight:Nb};var Ufe=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Hfe(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var e=Ufe();return e&&n.setAttribute("nonce",e),n}function $fe(n,e){n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}function Kfe(n){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(n)}var qfe=function(){var n=0,e=null;return{add:function(t){n==0&&(e=Hfe())&&($fe(e,t),Kfe(e)),n++},remove:function(){n--,!n&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Vfe=function(){var n=qfe();return function(e,t){E.useEffect(function(){return n.add(e),function(){n.remove()}},[e&&t])}},P$=function(){var n=Vfe(),e=function(t){var r=t.styles,i=t.dynamic;return n(r,i),null};return e},Gfe={left:0,top:0,right:0,gap:0},i_=function(n){return parseInt(n||"",10)||0},Yfe=function(n){var e=window.getComputedStyle(document.body),t=e[n==="padding"?"paddingLeft":"marginLeft"],r=e[n==="padding"?"paddingTop":"marginTop"],i=e[n==="padding"?"paddingRight":"marginRight"];return[i_(t),i_(r),i_(i)]},Wfe=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return Gfe;var e=Yfe(n),t=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-t+e[2]-e[0])}},Xfe=P$(),Ef="data-scroll-locked",Zfe=function(n,e,t,r){var i=n.left,s=n.top,o=n.right,a=n.gap;return t===void 0&&(t="margin"),`
252
+ `,textSerializers:r={}}=e||{};return l$(this.state.doc,{blockSeparator:t,textSerializers:{...G2(this.schema),...r}})}get isEmpty(){return Z2(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}$node(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelector(e,t))||null}$nodes(e,t){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new ad(t,this)}get $doc(){return this.$pos(0)}}function Rd(n){return new a0({find:n.find,handler:({state:e,range:t,match:r})=>{const i=wt(n.getAttributes,void 0,r);if(i===!1||i===null)return null;const{tr:s}=e,o=r[r.length-1],a=r[0];if(o){const l=a.search(/\S/),u=t.from+a.indexOf(o),f=u+o.length;if(X2(t.from,t.to,e.doc).filter(y=>y.mark.type.excluded.find(v=>v===n.type&&v!==y.mark.type)).filter(y=>y.to>u).length)return null;f<t.to&&s.delete(f,t.to),u>t.from&&s.delete(t.from+l,u);const g=t.from+l+o.length;s.addMark(t.from+l,g,n.type.create(i||{})),s.removeStoredMark(n.type)}}})}function Dhe(n){return new a0({find:n.find,handler:({state:e,range:t,match:r})=>{const i=wt(n.getAttributes,void 0,r)||{},{tr:s}=e,o=t.from;let a=t.to;const l=n.type.create(i);if(r[1]){const u=r[0].lastIndexOf(r[1]);let f=o+u;f>a?f=a:a=f+r[1].length;const h=r[0][r[0].length-1];s.insertText(h,o+r[0].length-1),s.replaceWith(f,a,l)}else if(r[0]){const u=n.type.isInline?o:o-1;s.insert(u,n.type.create(i)).delete(s.mapping.map(o),s.mapping.map(a))}s.scrollIntoView()}})}function EP(n){return new a0({find:n.find,handler:({state:e,range:t,match:r})=>{const i=e.doc.resolve(t.from),s=wt(n.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),n.type))return null;e.tr.delete(t.from,t.to).setBlockType(t.from,t.from,n.type,s)}})}function Em(n){return new a0({find:n.find,handler:({state:e,range:t,match:r,chain:i})=>{const s=wt(n.getAttributes,void 0,r)||{},o=e.tr.delete(t.from,t.to),l=o.doc.resolve(t.from).blockRange(),u=l&&k2(l,n.type,s);if(!u)return null;if(o.wrap(l,u),n.keepMarks&&n.editor){const{selection:h,storedMarks:g}=e,{splittableMarks:y}=n.editor.extensionManager,b=g||h.$to.parentOffset&&h.$from.marks();if(b){const v=b.filter(w=>y.includes(w.type.name));o.ensureMarks(v)}}if(n.keepAttributes){const h=n.type.name==="bulletList"||n.type.name==="orderedList"?"listItem":"taskList";i().updateAttributes(h,s).run()}const f=o.doc.resolve(t.from-1).nodeBefore;f&&f.type===n.type&&ku(o.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(r,f))&&o.join(t.from-1)}})}let Sa=class _P{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=wt($e(this,"addOptions",{name:this.name}))),this.storage=wt($e(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new _P(e)}configure(e={}){const t=this.extend({...this.config,addOptions:()=>l0(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){const t=new _P(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=wt($e(t,"addOptions",{name:t.name})),t.storage=wt($e(t,"addStorage",{name:t.name,options:t.options})),t}};function pu(n){return new Vue({find:n.find,handler:({state:e,range:t,match:r,pasteEvent:i})=>{const s=wt(n.getAttributes,void 0,r,i);if(s===!1||s===null)return null;const{tr:o}=e,a=r[r.length-1],l=r[0];let u=t.to;if(a){const f=l.search(/\S/),h=t.from+l.indexOf(a),g=h+a.length;if(X2(t.from,t.to,e.doc).filter(b=>b.mark.type.excluded.find(w=>w===n.type&&w!==b.mark.type)).filter(b=>b.to>h).length)return null;g<t.to&&o.delete(g,t.to),h>t.from&&o.delete(t.from+f,h),u=t.from+f+a.length,o.addMark(t.from+f,u,n.type.create(s||{})),o.removeStoredMark(n.type)}}})}function Rhe(n,e){const{selection:t}=n,{$from:r}=t;if(t instanceof We){const s=r.index();return r.parent.canReplaceWith(s,s+1,e)}let i=r.depth;for(;i>=0;){const s=r.index(i);if(r.node(i).contentMatchAt(s).matchType(e))return!0;i-=1}return!1}const jhe=new Ii;function Lhe(n){return jhe.get(n,()=>d0(n.extensions??[]))}function h0(n,e,t){const{tipTapConfig:r,addFontsFromNode:i}=n.getTextOptions();Be(r,"textOptions.tipTapConfig must be set to use rich text"),Be(i,"textOptions.addFontsFromNode must be set to use rich text");const s=Lhe(r),o=ha.fromJSON(s,e),a=new Set;function l(f){a.add(f)}function u(f,h){h=i(f,h,l);for(const g of f.children)u(g,h)}return u(o,t),Array.from(a)}async function Nhe({shouldReload:n=!0}={}){wZ();for(const e of gm.connectedInstances)await e.close();await Promise.all(E2().map(e=>JU(e))),vZ(),n&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Nhe);function zhe(n,e="_blank"){ey.openWindow(n,e)}xu("@tldraw/editor","4.1.2","esm");class Lt{static lineThroughPoints(e,t){const r=new Lt;r.moveTo(e[0].x,e[0].y,{...t,offset:t?.endOffsets??t?.offset});for(let i=1;i<e.length;i++){const s=i===e.length-1;r.lineTo(e[i].x,e[i].y,s?{offset:t?.endOffsets}:void 0)}return r}static cubicSplineThroughPoints(e,t){const r=new Lt,i=e.length,s=i-2,o=1.25;r.moveTo(e[0].x,e[0].y,{...t,offset:t?.endOffsets??t?.offset});for(let a=0;a<i-1;a++){const l=a===0?e[0]:e[a-1],u=e[a],f=e[a+1],h=a===s?f:e[a+2];let g,y,b,v;a===0?(g=l.x,y=l.y):(g=u.x+(f.x-l.x)/6*o,y=u.y+(f.y-l.y)/6*o);let w;a===s?(b=f.x,v=f.y,w={offset:t?.endOffsets}):(b=f.x-(h.x-u.x)/6*o,v=f.y-(h.y-u.y)/6*o),r.cubicBezierTo(f.x,f.y,g,y,b,v,w)}return r}constructor(){}commands=[];lastMoveTo=null;assertHasMoveTo(){return Be(this.lastMoveTo,"Start an SVGPathBuilder with `.moveTo()`"),this.lastMoveTo}moveTo(e,t,r){return this.lastMoveTo={type:"move",x:e,y:t,closeIdx:null,isClose:!1,opts:r},this.commands.push(this.lastMoveTo),this}lineTo(e,t,r){return this.assertHasMoveTo(),this.commands.push({type:"line",x:e,y:t,isClose:!1,opts:r}),this}circularArcTo(e,t,r,i,s,o){return this.arcTo(e,e,t,r,0,i,s,o)}arcTo(e,t,r,i,s,o,a,l){this.assertHasMoveTo();const u=this.commands[this.commands.length-1].x,f=this.commands[this.commands.length-1].y;if(u===o&&f===a)return this;if(e===0||t===0)return this.lineTo(o,a,l);const h=s,g=Math.sin(h),y=Math.cos(h);let b=Math.abs(e),v=Math.abs(t);const w=(u-o)/2,x=(f-a)/2,T=y*w+g*x,P=-g*w+y*x,M=T*T/(b*b)+P*P/(v*v);if(M>1){const ve=Math.sqrt(M);b*=ve,v*=ve}const k=r!==i?1:-1,A=b*b*v*v-b*b*P*P-v*v*T*T,O=b*b*P*P+v*v*T*T;let R=A/O;R=R<0?0:R;const F=k*Math.sqrt(R),z=F*(b*P/v),j=F*(-(v*T)/b),$=y*z-g*j+(u+o)/2,H=g*z+y*j+(f+a)/2,B=(T-z)/b,G=(P-j)/v,N=(-T-z)/b,Y=(-P-j)/v,W=Math.atan2(G,B);let Q=Math.atan2(Y,N);!i&&Q>W?Q-=2*Math.PI:i&&Q<W&&(Q+=2*Math.PI);const de=Q-W,U=Math.max(b,v)*Math.abs(de),re=Math.min(4,Math.ceil(Math.abs(de)/(Math.PI/2))),le=Math.ceil(Wv(U)/re),Se=de/re,fe=ve=>({x:$+b*Math.cos(ve)*y-v*Math.sin(ve)*g,y:H+b*Math.cos(ve)*g+v*Math.sin(ve)*y}),Me=ve=>({x:-b*Math.sin(ve)*y-v*Math.cos(ve)*g,y:-b*Math.sin(ve)*g+v*Math.cos(ve)*y});for(let ve=0;ve<re;ve++){const _e=W+ve*Se,Oe=W+(ve+1)*Se,He=Oe-_e,Bt=fe(_e),qt=fe(Oe),At=Me(_e),_t=Me(Oe),$t=4/3*Math.tan(He/4),Gn=Bt.x+$t*At.x,yr=Bt.y+$t*At.y,Er=qt.x-$t*_t.x,Hr=qt.y-$t*_t.y,li=ve===0?l:{...l,mergeWithPrevious:!0};this.cubicBezierToWithResolution(qt.x,qt.y,Gn,yr,Er,Hr,li,le)}return this}cubicBezierTo(e,t,r,i,s,o,a){return this.cubicBezierToWithResolution(e,t,r,i,s,o,a)}cubicBezierToWithResolution(e,t,r,i,s,o,a,l){return this.assertHasMoveTo(),this.commands.push({type:"cubic",x:e,y:t,cp1:{x:r,y:i},cp2:{x:s,y:o},isClose:!1,opts:a,resolution:l}),this}close(){const e=this.assertHasMoveTo(),t=this.commands[this.commands.length-1];return ir(e.x,t.x)&&ir(e.y,t.y)?t.isClose=!0:this.commands.push({type:"line",x:e.x,y:e.y,isClose:!0}),e.closeIdx=this.commands.length-1,this.lastMoveTo=null,this}toD(e={}){const{startIdx:t=0,endIdx:r=this.commands.length,onlyFilled:i=!1}=e,s=[];let o=!1,a=!1,l=!1;const u=f=>{if(a||f===0)return;a=!0;const h=this.commands[f-1];s.push("M",Z(h.x),Z(h.y))};for(let f=t;f<r;f++){const h=this.commands[f];switch(h.type){case"move":{const g=h.opts?.geometry===!1?!1:h.opts?.geometry?.isFilled??!1;i&&!g?o=!0:(o=!1,a=!0,l=!0,s.push("M",Z(h.x),Z(h.y)));break}case"line":if(o)break;u(f),h.isClose&&l?s.push("Z"):s.push("L",Z(h.x),Z(h.y));break;case"cubic":if(o)break;u(f),s.push("C",Z(h.cp1.x),Z(h.cp1.y),Z(h.cp2.x),Z(h.cp2.y),Z(h.x),Z(h.y));break;default:kt(h,"type")}}return s.join(" ")}toSvg(e){if(e.forceSolid)return this.toSolidSvg(e);switch(e.style){case"solid":return this.toSolidSvg(e);case"dashed":case"dotted":return this.toDashedSvg(e);case"draw":return this.toDrawSvg(e);default:kt(e,"style")}}toGeometry(){const e=[];let t=null;for(let r=0;r<this.commands.length;r++){const i=this.commands[r];i.type==="move"&&(t&&t.opts?.geometry!==!1&&e.push(new PP(this,t.startIdx,r,{...t.opts?.geometry,isFilled:t.opts?.geometry?.isFilled??!1,isClosed:t.moveCommand.closeIdx!==null})),t={startIdx:r,moveCommand:i,opts:i.opts,isClosed:!1}),i.isClose&&(Be(t,"No current move command"),t.isClosed=!0)}return t&&t.opts?.geometry!==!1&&e.push(new PP(this,t.startIdx,this.commands.length,{...t.opts?.geometry,isFilled:t.opts?.geometry?.isFilled??!1,isClosed:t.moveCommand.closeIdx!==null})),Be(e.length>0),e.length===1?e[0]:new Os({children:e})}toSolidSvg(e){const{strokeWidth:t,props:r}=e;return m.jsx("path",{strokeWidth:t,d:this.toD({onlyFilled:e.onlyFilled}),...r})}toDashedSvg(e){const{style:t,strokeWidth:r,snap:i,lengthRatio:s,props:{markerStart:o,markerEnd:a,...l}={}}=e,u=[];let f=!1,h=!1,g,y=null;const b=()=>{if(!y)return;const{startIdx:v,endIdx:w,isFirst:x,isLast:T,length:P,lineOpts:M,pathIsClosed:k}=y;if(y=null,v===w&&this.commands[v].type==="move")return;const A=M?.dashStart??e.start,O=M?.dashEnd??e.end,{strokeDasharray:R,strokeDashoffset:F}=qF(P,r,{style:t,snap:i,lengthRatio:s,start:x?A??(k?"outset":"none"):"outset",end:T?O??(k?"outset":"none"):"outset"}),z=this.toD({startIdx:v,endIdx:w+1});u.push(m.jsx("path",{d:z,strokeDasharray:R,strokeDashoffset:F,markerStart:x?o:void 0,markerEnd:T?a:void 0},u.length))};for(let v=0;v<this.commands.length;v++){const w=this.commands[v],x=this.commands[v-1];if(w.type==="move"){f=w.closeIdx!==null;const k=w.opts?.geometry===!1?!1:w.opts?.geometry?.isFilled??!1;e.onlyFilled&&!k?h=!0:(h=!1,g=w.opts);continue}if(h)continue;const T=this.calculateSegmentLength(x,w),P=x.type==="move",M=w.isClose||v===this.commands.length-1||this.commands[v+1]?.type==="move";y&&w.opts?.mergeWithPrevious?(y.length+=T,y.endIdx=v,y.isLast=M):(b(),y={startIdx:v,endIdx:v,isFirst:P,isLast:M,length:T,lineOpts:g,pathIsClosed:f})}return b(),m.jsx("g",{strokeWidth:r,...l,children:u})}toDrawSvg(e){return m.jsx("path",{strokeWidth:e.strokeWidth,d:this.toDrawD(e),...e.props})}toDrawD(e){const{strokeWidth:t,randomSeed:r,offset:i=t/3,roundness:s=t*2,passes:o=2,onlyFilled:a=!1}=e,l=[],u=this.getCommandInfo(),f=[];let h=null;for(let g=0;g<this.commands.length;g++){const y=this.commands[g],b=y.opts?.offset??i,v=y.opts?.roundness??s;y.type==="move"&&(h=g);const w=y.isClose?Mr(h)+1:!this.commands[g+1]||this.commands[g+1].type==="move"?void 0:g+1,x=w!==void 0&&this.commands[w]&&this.commands[w]?.type!=="move"?u[w]:void 0,T=x5[y.type],P=w!==void 0?x5[this.commands[w].type]:!1,M=u[g],k=M?.tangentEnd,A=x?.tangentStart,O=T&&P&&k&&A&&I.Len2(k)>.01&&I.Len2(A)>.01?pa(Math.abs(I.AngleBetween(k,A)),[Math.PI/2,Math.PI],[v,0],!0):0,F=Math.min(M?.length??1/0,x?.length??1/0)-O*2,z=st(b,0,F/4),j=Math.min(O,(M?.length??1/0)/4),$=Math.min(O,(x?.length??1/0)/4),H={command:y,offsetAmount:z,roundnessBefore:j,roundnessAfter:$,tangentToPrev:u[g]?.tangentEnd,tangentToNext:x?.tangentStart,moveDidClose:!1};if(f.push(H),y.isClose&&h!==null){const B=f[h];B.moveDidClose=!0,B.roundnessAfter=$}else y.type==="move"&&(h=g)}for(let g=0;g<o;g++){const y=Ud(r+g);let b={x:0,y:0},v=!1;for(const{command:w,offsetAmount:x,roundnessBefore:T,roundnessAfter:P,tangentToNext:M,tangentToPrev:k}of f){const A=w.isClose?b:{x:y()*x,y:y()*x};if(w.type==="move"){b=A;const z=w.opts?.geometry===!1?!1:w.opts?.geometry?.isFilled??!1;a&&!z?v=!0:v=!1}if(v)continue;const O=I.Add(w,A),R=M&&P>0?I.Mul(M,-P).add(O):O,F=k&&T>0?I.Mul(k,T).add(O):O;if(R===O||F===O)switch(w.type){case"move":l.push("M",Z(R.x),Z(R.y));break;case"line":l.push("L",Z(R.x),Z(R.y));break;case"cubic":{const z=I.Add(w.cp1,A),j=I.Add(w.cp2,A);l.push("C",Z(z.x),Z(z.y),Z(j.x),Z(j.y),Z(R.x),Z(R.y));break}default:kt(w,"type")}else switch(w.type){case"move":l.push("M",Z(R.x),Z(R.y));break;case"line":l.push("L",Z(F.x),Z(F.y),"Q",Z(O.x),Z(O.y),Z(R.x),Z(R.y));break;case"cubic":{const z=I.Add(w.cp1,A),j=I.Add(w.cp2,A);l.push("C",Z(z.x),Z(z.y),Z(j.x),Z(j.y),Z(O.x),Z(O.y));break}default:kt(w,"type")}}}return l.join(" ")}calculateSegmentLength(e,t){switch(t.type){case"move":return 0;case"line":return I.Dist(e,t);case"cubic":return Mg.length(e.x,e.y,t.cp1.x,t.cp1.y,t.cp2.x,t.cp2.y,t.x,t.y);default:kt(t,"type")}}getCommands(){return this.commands}getCommandInfo(){const e=[];for(let t=1;t<this.commands.length;t++){const r=this.commands[t-1],i=this.commands[t];if(i._info){e[t]=i._info;continue}if(i.type==="move")continue;let s,o;switch(i.type){case"line":s=o=I.Sub(r,i).uni();break;case"cubic":{s=I.Sub(i.cp1,r).uni(),o=I.Sub(i.cp2,i).uni();break}default:kt(i,"type")}i._info={tangentStart:s,tangentEnd:o,length:this.calculateSegmentLength(r,i)},e[t]=i._info}return e}}const x5={line:!0,move:!0,cubic:!1};class PP extends Iu{constructor(e,t,r,i){super(i),this.path=e,this.startIdx=t,this.endIdx=r}_segments=null;getSegments(){if(this._segments)return this._segments;this._segments=[];let e=this.path.commands[this.startIdx];Be(e.type==="move");for(let t=this.startIdx+1;t<this.endIdx;t++){const r=this.path.commands[t];switch(Be(r.type!=="move"),r.type){case"line":this._segments.push(new Df({start:I.From(e),end:I.From(r)}));break;case"cubic":{this._segments.push(new P2({start:I.From(e),cp1:I.From(r.cp1),cp2:I.From(r.cp2),end:I.From(r),resolution:r.resolution}));break}default:kt(r,"type")}e=r}return this._segments}getVertices(e){const t=this.getSegments().flatMap(r=>r.getVertices(e)).filter((r,i,s)=>{const o=s[i-1];return o?!I.Equals(o,r):!0});if(this.isClosed){const r=t[t.length-1],i=t[0];I.Equals(r,i)||t.push(i)}return t}nearestPoint(e,t){let r=null,i=1/0;for(const s of this.getSegments()){const o=s.nearestPoint(e),a=I.Dist2(e,o);a<i&&(i=a,r=o)}return Be(r,"No nearest point found"),r}hitTestLineSegment(e,t,r=0,i){return super.hitTestLineSegment(e,t,r,i)}getSvgPathData(){return this.path.toD({startIdx:this.startIdx,endIdx:this.endIdx})}}const Mg={base3(n,e,t,r,i){const s=-3*e+9*t-9*r+3*i,o=n*s+6*e-12*t+6*r;return n*o-3*e+3*t},length(n,e,t,r,i,s,o,a,l=1){l=l>1?1:l<0?0:l;const u=l/2,f=12;let h=0;h=0;for(let g=0;g<f;g++){const y=u*Mg.Tvalues[g]+u,b=Mg.base3(y,n,t,i,o),v=Mg.base3(y,e,r,s,a),w=b*b+v*v;h+=Mg.Cvalues[g]*Math.sqrt(w)}return u*h},Tvalues:[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],Cvalues:[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472]};function u$(){const n=Vn(),e=ee("animationSpeed",()=>n?.user.getAnimationSpeed(),[n]),[t,r]=E.useState(!1);return E.useEffect(()=>{if(e!==void 0){r(e===0);return}if(typeof window>"u"||!("matchMedia"in window))return;const i=window.matchMedia("(prefers-reduced-motion: reduce)"),s=()=>{r(i.matches)};return s(),i.addEventListener("change",s),()=>i.removeEventListener("change",s)},[e]),t}const IP=E.createContext(null);function Bhe({children:n}){const e=Wm("a11y",{msg:"",priority:"assertive"}),t=E.useContext(IP),r=E.useMemo(()=>({currentMsg:e,announce(i){i&&e.set(i)}}),[e]);return t?m.jsx(m.Fragment,{children:n}):m.jsx(IP.Provider,{value:r,children:n})}function f0(){const n=E.useContext(IP);if(!n)throw new Error("useA11y must be used within a A11yContext.Provider");return n}const d$=E.createContext(null);function h$({assetUrls:n,children:e}){return E.useEffect(()=>{for(const t of Object.values(n.icons)){if(!t)continue;const r=am();r.crossOrigin="anonymous",r.src=t,r.decode()}for(const t of Object.values(n.embedIcons)){if(!t)continue;const r=am();r.crossOrigin="anonymous",r.src=t,r.decode()}},[n]),m.jsx(d$.Provider,{value:n,children:e})}function J2(){const n=E.useContext(d$);if(!n)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return n}const MP={"action.toggle-auto-pan":"Auto (trackpad)","action.toggle-auto-zoom":"Auto (mouse)","action.toggle-auto-none":"Auto","action.toggle-mouse":"Mouse","action.toggle-trackpad":"Trackpad","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-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.download-original":"Download original","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","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-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-kbd-shortcuts":"Open keyboard shortcuts","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-keyboard-shortcuts.menu":"Enable keyboard shortcuts","action.toggle-keyboard-shortcuts":"Toggle keyboard shortcuts","action.enhanced-a11y-mode.menu":"Enhanced accessibility mode","action.enhanced-a11y-mode":"Toggle enhanced accessibility mode","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.maximum-size":"Maximum file size is {size}","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.files.amount-too-many":"Too many files","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.cloud":"Cloud","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.heart":"Heart","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus":"Rhombus","geo-style.rhombus-2":"Rhombus left","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","arrow-kind-style.arc":"Arc","arrow-kind-style.elbow":"Elbow","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.heart":"Heart","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.media":"Media","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","tool.pointer-down":"Pointer down","tool.image-zoom":"Zoom","tool.replace-media":"Replace media","tool.flip-horz":"Flip horizontally","tool.flip-vert":"Flip vertically","tool.rotate-cw":"Rotate","tool.aspect-ratio":"Aspect ratio","tool.aspect-ratio.original":"Original","tool.aspect-ratio.square":"Square (1:1)","tool.aspect-ratio.circle":"Circle (1:1)","tool.aspect-ratio.landscape":"Landscape (4:3)","tool.aspect-ratio.portrait":"Portrait (3:4)","tool.aspect-ratio.wide":"Wide (16:9)","tool.image-toolbar-title":"Image tools","tool.image-crop":"Crop image","tool.image-crop-confirm":"Confirm","tool.media-alt-text":"Alternative text","tool.media-alt-text-desc":"Give a description…","tool.media-alt-text-confirm":"Confirm","tool.rich-text-bold":"Bold","tool.rich-text-italic":"Italic","tool.rich-text-code":"Code","tool.rich-text-highlight":"Highlight","tool.rich-text-strikethrough":"Strikethrough","tool.rich-text-link":"Link","tool.rich-text-link-visit":"Visit link","tool.rich-text-link-remove":"Remove link","tool.rich-text-header":"Header","tool.rich-text-bulletList":"Bulleted list","tool.rich-text-toolbar-title":"Text formatting","tool.rich-text-orderedList":"Ordered list","tool.bookmark":"Bookmark","a11y.status":"Status","a11y.skip-to-main-content":"Move focus to canvas","a11y.shape-index":"{num} of {total}","a11y.shape-image":"Image","a11y.shape-video":"Video","a11y.multiple-shapes":"{num} shapes selected","a11y.select-shape":"Select next shape","a11y.select-shape-direction":"Select shape in direction","a11y.enter-leave-container":"Enter/leave container","a11y.repeat-shape":"Repeat shape","a11y.move-shape":"Move shape","a11y.move-shape-faster":"Move shape faster","a11y.rotate-shape-cw":"Rotate shape clockwise","a11y.rotate-shape-ccw":"Rotate shape counterclockwise","a11y.rotate-shape-cw-fine":"Rotate shape clockwise (fine)","a11y.rotate-shape-ccw-fine":"Rotate shape counterclockwise (fine)","a11y.enlarge-shape":"Enlarge shape","a11y.shrink-shape":"Shrink shape","a11y.pan-camera":"Pan camera","a11y.adjust-shape-styles":"Adjust shape styles","a11y.open-context-menu":"Open context menu","a11y.open-keyboard-shortcuts":"Open keyboard shortcuts","menu.title":"Menu","menu.theme":"Theme","menu.accessibility":"Accessibility","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.view":"View","menu.input-mode":"Input mode","context-menu.title":"Context menu","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.copy-link":"Copy editor link","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","document-name-menu.copy-link":"Copy link","status.offline":"Offline","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.avatar-color":"Avatar color","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","people-menu.anonymous-user":"New user","help-menu.import-tldr-file":"Import file…","help-menu.title":"Help and resources","help-menu.about":"About tldraw","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","help-menu.terms":"Terms of service","help-menu.privacy":"Privacy policy","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","edit-link-dialog.external-link":"External link","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.","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","shortcuts-dialog.a11y":"Accessibility","shortcuts-dialog.text-formatting":"Text formatting","style-panel.title":"Styles","style-panel.align":"Align","style-panel.label-align":"Label 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.arrow-kind":"Line","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","style-panel.selected":"selected","tool-panel.title":"Tools","tool-panel.more":"More","navigation-zone.title":"Navigation","navigation-zone.minimap":"Minimap","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","toast.success":"Success","toast.error":"Error","toast.info":"Info","toast.warning":"Warning","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…","app.loading":"Loading tldraw…","handle.resize-top":"Resize top","handle.resize-bottom":"Resize bottom","handle.resize-left":"Resize left","handle.resize-right":"Resize right","handle.resize-top-left":"Resize top left","handle.resize-top-right":"Resize top right","handle.resize-bottom-left":"Resize bottom left","handle.resize-bottom-right":"Resize bottom right","handle.rotate.top_left_rotate":"Rotate top left","handle.rotate.top_right_rotate":"Rotate top right","handle.rotate.bottom_left_rotate":"Rotate bottom left","handle.rotate.bottom_right_rotate":"Rotate bottom right","handle.rotate.mobile_rotate":"Rotate","handle.crop.top":"Crop top","handle.crop.bottom":"Crop bottom","handle.crop.left":"Crop left","handle.crop.right":"Crop right","handle.crop.top-left":"Crop top left","handle.crop.top-right":"Crop top right","handle.crop.bottom-left":"Crop bottom left","handle.crop.bottom-right":"Crop bottom right","ui.close":"Close","ui.checked":"Checked","ui.unchecked":"Unchecked"},Fhe=new Set(["ar","fa","he","ur","ku"]),Yh={locale:"en",label:"English",messages:MP,dir:"ltr"};async function Uhe(n,e){if(!(await Gl(e.translations.en)).ok)return console.warn("No main translations found."),Yh;if(n==="en")return Yh;const r=dm.find(o=>o.locale===n);if(!r)return console.warn(`No translation found for locale ${n}`),Yh;const s=await(await Gl(e.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${n}`),Yh;for(const o in Yh.messages)s[o];return{locale:n,label:r.label,dir:Fhe.has(r.locale)?"rtl":"ltr",messages:{...Yh.messages,...s}}}const f$=E.createContext(null);function p$(){const n=E.useContext(f$);if(!n)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return n}function g$({overrides:n,locale:e,children:t}){const r=J2(),[i,s]=E.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...MP,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:MP});return E.useEffect(()=>{let o=!1;async function a(){const l=await Uhe(e,r);l&&!o&&(n&&n[e]?s({...l,messages:{...l.messages,...n[e]}}):s(l))}return a(),()=>{o=!0}},[r,e,n]),m.jsx(f$.Provider,{value:i,children:t})}function Ne(){const n=p$();return E.useCallback(function(t){return n.messages[t]??t},[n])}const Hhe={normal:"tlui-button__normal",primary:"tlui-button__primary",danger:"tlui-button__danger",low:"tlui-button__low",icon:"tlui-button__icon",tool:"tlui-button__tool",menu:"tlui-button__menu",help:"tlui-button__help"},gt=E.forwardRef(function({children:e,type:t,isActive:r,...i},s){return m.jsx("button",{ref:s,type:"button",draggable:!1,"data-isactive":r,...i,className:Fe("tlui-button",Hhe[t],i.className),children:e})});function $he(){const n=te(),e=Ne(),t=E.useRef(null),r=E.useCallback(i=>{n.markEventAsHandled(i),t.current?.blur();const s=n.getCurrentPageShapesInReadingOrder();s.length&&(n.setSelectedShapes([s[0].id]),n.zoomToSelectionIfOffscreen(256,{animation:{duration:n.options.animationMediumMs},inset:0}),n.timers.setTimeout(()=>n.getContainer().focus(),100))},[n]);return m.jsx(gt,{ref:t,type:"low",tabIndex:0,className:"tl-skip-to-main-content",onClick:r,children:e("a11y.skip-to-main-content")})}const Khe=E.memo(function(){const e=f0(),t=Ne(),r=ee("a11y-msg",()=>e.currentMsg.get(),[]);return Vhe(r.msg),qhe(),r.msg&&m.jsx("div",{"aria-label":t("a11y.status"),"aria-live":r.priority||"assertive",role:"status","aria-hidden":"false",style:{position:"absolute",top:"-10000px",left:"-10000px"},children:r.msg})});function m$(n){const{editor:e,selectedShapeIds:t,msg:r}=n;let i="";const s=t.length;if(s>1)i=r("a11y.multiple-shapes").replace("{num}",s.toString());else if(s===1){const o=t[0],a=e.getShape(o);if(!a)return"";const l=e.getShapeUtil(a.type),u=["image","video"].includes(a.type);let f="";a.type==="geo"?f=r(`geo-style.${a.props.geo}`):u?f=r(`a11y.shape-${a.type}`):f=r(`tool.${a.type}`);const h=e.getCurrentPageShapesInReadingOrder(),g=(h.findIndex(w=>w.id===o)+1).toString(),y=h.length.toString(),b=r("a11y.shape-index").replace("{num}",g).replace("{total}",y),v=l.getAriaDescriptor(a)||l.getText(a)||"";i=(v?`${v}, `:"")+`${f}. ${b}`}return i}const qhe=()=>{const n=Vn(),e=f0(),t=Ne(),r=E.useRef([]);NI("announce selection",()=>{if(!n)return;if(n.isIn("select.idle")){const s=n.getSelectedShapeIds();s!==r.current&&(r.current=s,Cg(()=>{const o=m$({editor:n,selectedShapeIds:s,msg:t});o&&e.announce({msg:o})}))}},[n,e,t])},Vhe=n=>{const e=or();E.useEffect(()=>{if(In.a11y.get()){const t=i=>{console.debug(`%ca11y%c: ${i}`,"color: white; background: #40C057; padding: 2px;border-radius: 3px;","font-weight: normal")},r=i=>{const s=document.activeElement;if(i.key==="Tab"&&s&&s!==document.body&&!s.classList.contains("tl-container")){const o=s.getAttribute("aria-label")||s.getAttribute("title")||s.textContent;o&&t(o)}};return n&&t(n),document.addEventListener("keyup",r),()=>document.removeEventListener("keyup",r)}},[e,n])};function Ghe(n,e){const t=tt(e.map(i=>n.getShape(i)).filter(i=>i&&n.isShapeOfType(i,"frame")));if(!t.length)return;const r=[];n.run(()=>{t.map(i=>{const s=n.getSortedChildIdsForParent(i.id);s.length&&(Xt(n,s,{filter:o=>!t.find(a=>a.id===o.id)}),r.push(...s))}),n.setSelectedShapes(r),n.deleteShapes(e)})}const v5=50;function y$(n,e,t={padding:v5}){const r=we.FromPoints(n.flatMap(u=>{if(!u)return[];const f=e.getShapeGeometry(u.id);return e.getShapeLocalTransform(u)?.applyToPoints(f.vertices)??[]})),i=t.padding??v5,s=r.w+2*i,o=r.h+2*i,a=i-r.minX,l=i-r.minY;return{w:s,h:o,dx:a,dy:l}}function S$(n,e,t={}){const r=n.getShape(e);if(!r)return;const i=n.getSortedChildIdsForParent(r.id),s=tt(i.map(h=>n.getShape(h)));if(!s.length)return;const{w:o,h:a,dx:l,dy:u}=y$(s,n,t);if(l===0&&u===0&&r.props.w===o&&r.props.h===a)return;const f=new I(l,u).rot(r.rotation);n.run(()=>{const h=i.map(g=>{const y=n.getShape(g);return{id:y.id,type:y.type,x:y.x+l,y:y.y+u}});h.push({id:r.id,type:r.type,x:r.x-f.x,y:r.y-f.y,props:{w:o,h:a}}),n.updateShapes(h)})}function nr({children:n}){return m.jsx("span",{className:"tlui-button__label",children:n})}function w5(n,e){if(typeof n=="function")return n(e);n!=null&&(n.current=e)}function p0(...n){return e=>{let t=!1;const r=n.map(i=>{const s=w5(i,e);return!t&&typeof s=="function"&&(t=!0),s});if(t)return()=>{for(let i=0;i<r.length;i++){const s=r[i];typeof s=="function"?s():w5(n[i],null)}}}}function Jt(...n){return E.useCallback(p0(...n),n)}function jd(n){const e=Yhe(n),t=E.forwardRef((r,i)=>{const{children:s,...o}=r,a=E.Children.toArray(s),l=a.find(Xhe);if(l){const u=l.props.children,f=a.map(h=>h===l?E.Children.count(u)>1?E.Children.only(null):E.isValidElement(u)?u.props.children:null:h);return m.jsx(e,{...o,ref:i,children:E.isValidElement(u)?E.cloneElement(u,void 0,f):null})}return m.jsx(e,{...o,ref:i,children:s})});return t.displayName=`${n}.Slot`,t}var Q2=jd("Slot");function Yhe(n){const e=E.forwardRef((t,r)=>{const{children:i,...s}=t;if(E.isValidElement(i)){const o=Jhe(i),a=Zhe(s,i.props);return i.type!==E.Fragment&&(a.ref=r?p0(r,o):o),E.cloneElement(i,a)}return E.Children.count(i)>1?E.Children.only(null):null});return e.displayName=`${n}.SlotClone`,e}var b$=Symbol("radix.slottable");function Whe(n){const e=({children:t})=>m.jsx(m.Fragment,{children:t});return e.displayName=`${n}.Slottable`,e.__radixId=b$,e}function Xhe(n){return E.isValidElement(n)&&typeof n.type=="function"&&"__radixId"in n.type&&n.type.__radixId===b$}function Zhe(n,e){const t={...e};for(const r in e){const i=n[r],s=e[r];/^on[A-Z]/.test(r)?i&&s?t[r]=(...a)=>{const l=s(...a);return i(...a),l}:i&&(t[r]=i):r==="style"?t[r]={...i,...s}:r==="className"&&(t[r]=[i,s].filter(Boolean).join(" "))}return{...n,...t}}function Jhe(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}var Qhe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ht=Qhe.reduce((n,e)=>{const t=jd(`Primitive.${e}`),r=E.forwardRef((i,s)=>{const{asChild:o,...a}=i,l=o?t:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),m.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${e}`,{...n,[e]:r}},{});function eM(n,e){n&&Gd.flushSync(()=>n.dispatchEvent(e))}var efe=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),tfe="VisuallyHidden",g0=E.forwardRef((n,e)=>m.jsx(ht.span,{...n,ref:e,style:{...efe,...n.style}}));g0.displayName=tfe;var nfe=g0;function rfe(n,e){const t=E.createContext(e),r=s=>{const{children:o,...a}=s,l=E.useMemo(()=>a,Object.values(a));return m.jsx(t.Provider,{value:l,children:o})};r.displayName=n+"Provider";function i(s){const o=E.useContext(t);if(o)return o;if(e!==void 0)return e;throw new Error(`\`${s}\` must be used within \`${n}\``)}return[r,i]}function uo(n,e=[]){let t=[];function r(s,o){const a=E.createContext(o),l=t.length;t=[...t,o];const u=h=>{const{scope:g,children:y,...b}=h,v=g?.[n]?.[l]||a,w=E.useMemo(()=>b,Object.values(b));return m.jsx(v.Provider,{value:w,children:y})};u.displayName=s+"Provider";function f(h,g){const y=g?.[n]?.[l]||a,b=E.useContext(y);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[u,f]}const i=()=>{const s=t.map(o=>E.createContext(o));return function(a){const l=a?.[n]||s;return E.useMemo(()=>({[`__scope${n}`]:{...a,[n]:l}}),[a,l])}};return i.scopeName=n,[r,ife(i,...e)]}function ife(...n){const e=n[0];if(n.length===1)return e;const t=()=>{const r=n.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(s){const o=r.reduce((a,{useScope:l,scopeName:u})=>{const h=l(s)[`__scope${u}`];return{...a,...h}},{});return E.useMemo(()=>({[`__scope${e.scopeName}`]:o}),[o])}};return t.scopeName=e.scopeName,t}function m0(n){const e=n+"CollectionProvider",[t,r]=uo(e),[i,s]=t(e,{collectionRef:{current:null},itemMap:new Map}),o=v=>{const{scope:w,children:x}=v,T=Ge.useRef(null),P=Ge.useRef(new Map).current;return m.jsx(i,{scope:w,itemMap:P,collectionRef:T,children:x})};o.displayName=e;const a=n+"CollectionSlot",l=jd(a),u=Ge.forwardRef((v,w)=>{const{scope:x,children:T}=v,P=s(a,x),M=Jt(w,P.collectionRef);return m.jsx(l,{ref:M,children:T})});u.displayName=a;const f=n+"CollectionItemSlot",h="data-radix-collection-item",g=jd(f),y=Ge.forwardRef((v,w)=>{const{scope:x,children:T,...P}=v,M=Ge.useRef(null),k=Jt(w,M),A=s(f,x);return Ge.useEffect(()=>(A.itemMap.set(M,{ref:M,...P}),()=>void A.itemMap.delete(M))),m.jsx(g,{[h]:"",ref:k,children:T})});y.displayName=f;function b(v){const w=s(n+"CollectionConsumer",v);return Ge.useCallback(()=>{const T=w.collectionRef.current;if(!T)return[];const P=Array.from(T.querySelectorAll(`[${h}]`));return Array.from(w.itemMap.values()).sort((A,O)=>P.indexOf(A.ref.current)-P.indexOf(O.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:u,ItemSlot:y},b,r]}function Re(n,e,{checkForDefaultPrevented:t=!0}={}){return function(i){if(n?.(i),t===!1||!i.defaultPrevented)return e?.(i)}}var Wl=globalThis?.document?E.useLayoutEffect:()=>{},sfe=SB[" useInsertionEffect ".trim().toString()]||Wl;function qo({prop:n,defaultProp:e,onChange:t=()=>{},caller:r}){const[i,s,o]=ofe({defaultProp:e,onChange:t}),a=n!==void 0,l=a?n:i;{const f=E.useRef(n!==void 0);E.useEffect(()=>{const h=f.current;h!==a&&console.warn(`${r} is changing from ${h?"controlled":"uncontrolled"} to ${a?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=a},[a,r])}const u=E.useCallback(f=>{if(a){const h=afe(f)?f(n):f;h!==n&&o.current?.(h)}else s(f)},[a,n,s,o]);return[l,u]}function ofe({defaultProp:n,onChange:e}){const[t,r]=E.useState(n),i=E.useRef(t),s=E.useRef(e);return sfe(()=>{s.current=e},[e]),E.useEffect(()=>{i.current!==t&&(s.current?.(t),i.current=t)},[t,i]),[t,r,s]}function afe(n){return typeof n=="function"}function lfe(n,e){return E.useReducer((t,r)=>e[t][r]??t,n)}var Vo=n=>{const{present:e,children:t}=n,r=cfe(e),i=typeof t=="function"?t({present:r.isPresent}):E.Children.only(t),s=Jt(r.ref,ufe(i));return typeof t=="function"||r.isPresent?E.cloneElement(i,{ref:s}):null};Vo.displayName="Presence";function cfe(n){const[e,t]=E.useState(),r=E.useRef(null),i=E.useRef(n),s=E.useRef("none"),o=n?"mounted":"unmounted",[a,l]=lfe(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return E.useEffect(()=>{const u=ZS(r.current);s.current=a==="mounted"?u:"none"},[a]),Wl(()=>{const u=r.current,f=i.current;if(f!==n){const g=s.current,y=ZS(u);n?l("MOUNT"):y==="none"||u?.display==="none"?l("UNMOUNT"):l(f&&g!==y?"ANIMATION_OUT":"UNMOUNT"),i.current=n}},[n,l]),Wl(()=>{if(e){let u;const f=e.ownerDocument.defaultView??window,h=y=>{const v=ZS(r.current).includes(CSS.escape(y.animationName));if(y.target===e&&v&&(l("ANIMATION_END"),!i.current)){const w=e.style.animationFillMode;e.style.animationFillMode="forwards",u=f.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=w)})}},g=y=>{y.target===e&&(s.current=ZS(r.current))};return e.addEventListener("animationstart",g),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{f.clearTimeout(u),e.removeEventListener("animationstart",g),e.removeEventListener("animationcancel",h),e.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:E.useCallback(u=>{r.current=u?getComputedStyle(u):null,t(u)},[])}}function ZS(n){return n?.animationName||"none"}function ufe(n){let e=Object.getOwnPropertyDescriptor(n.props,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning;return t?n.ref:(e=Object.getOwnPropertyDescriptor(n,"ref")?.get,t=e&&"isReactWarning"in e&&e.isReactWarning,t?n.props.ref:n.props.ref||n.ref)}var dfe=SB[" useId ".trim().toString()]||(()=>{}),hfe=0;function $a(n){const[e,t]=E.useState(dfe());return Wl(()=>{t(r=>r??String(hfe++))},[n]),e?`radix-${e}`:""}var ffe=E.createContext(void 0);function fy(n){const e=E.useContext(ffe);return n||e||"ltr"}function ts(n){const e=E.useRef(n);return E.useEffect(()=>{e.current=n}),E.useMemo(()=>(...t)=>e.current?.(...t),[])}function pfe(n,e=globalThis?.document){const t=ts(n);E.useEffect(()=>{const r=i=>{i.key==="Escape"&&t(i)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[t,e])}var gfe="DismissableLayer",kP="dismissableLayer.update",mfe="dismissableLayer.pointerDownOutside",yfe="dismissableLayer.focusOutside",C5,x$=E.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),rp=E.forwardRef((n,e)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:i,onFocusOutside:s,onInteractOutside:o,onDismiss:a,...l}=n,u=E.useContext(x$),[f,h]=E.useState(null),g=f?.ownerDocument??globalThis?.document,[,y]=E.useState({}),b=Jt(e,O=>h(O)),v=Array.from(u.layers),[w]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=v.indexOf(w),T=f?v.indexOf(f):-1,P=u.layersWithOutsidePointerEventsDisabled.size>0,M=T>=x,k=bfe(O=>{const R=O.target,F=[...u.branches].some(z=>z.contains(R));!M||F||(i?.(O),o?.(O),O.defaultPrevented||a?.())},g),A=xfe(O=>{const R=O.target;[...u.branches].some(z=>z.contains(R))||(s?.(O),o?.(O),O.defaultPrevented||a?.())},g);return pfe(O=>{T===u.layers.size-1&&(r?.(O),!O.defaultPrevented&&a&&(O.preventDefault(),a()))},g),E.useEffect(()=>{if(f)return t&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(C5=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(f)),u.layers.add(f),T5(),()=>{t&&u.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=C5)}},[f,g,t,u]),E.useEffect(()=>()=>{f&&(u.layers.delete(f),u.layersWithOutsidePointerEventsDisabled.delete(f),T5())},[f,u]),E.useEffect(()=>{const O=()=>y({});return document.addEventListener(kP,O),()=>document.removeEventListener(kP,O)},[]),m.jsx(ht.div,{...l,ref:b,style:{pointerEvents:P?M?"auto":"none":void 0,...n.style},onFocusCapture:Re(n.onFocusCapture,A.onFocusCapture),onBlurCapture:Re(n.onBlurCapture,A.onBlurCapture),onPointerDownCapture:Re(n.onPointerDownCapture,k.onPointerDownCapture)})});rp.displayName=gfe;var Sfe="DismissableLayerBranch",v$=E.forwardRef((n,e)=>{const t=E.useContext(x$),r=E.useRef(null),i=Jt(e,r);return E.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),m.jsx(ht.div,{...n,ref:i})});v$.displayName=Sfe;function bfe(n,e=globalThis?.document){const t=ts(n),r=E.useRef(!1),i=E.useRef(()=>{});return E.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){w$(mfe,t,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",i.current),i.current=l,e.addEventListener("click",i.current,{once:!0})):l()}else e.removeEventListener("click",i.current);r.current=!1},o=window.setTimeout(()=>{e.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(o),e.removeEventListener("pointerdown",s),e.removeEventListener("click",i.current)}},[e,t]),{onPointerDownCapture:()=>r.current=!0}}function xfe(n,e=globalThis?.document){const t=ts(n),r=E.useRef(!1);return E.useEffect(()=>{const i=s=>{s.target&&!r.current&&w$(yfe,t,{originalEvent:s},{discrete:!1})};return e.addEventListener("focusin",i),()=>e.removeEventListener("focusin",i)},[e,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function T5(){const n=new CustomEvent(kP);document.dispatchEvent(n)}function w$(n,e,t,{discrete:r}){const i=t.originalEvent.target,s=new CustomEvent(n,{bubbles:!1,cancelable:!0,detail:t});e&&i.addEventListener(n,e,{once:!0}),r?eM(i,s):i.dispatchEvent(s)}var vfe=rp,wfe=v$,QE="focusScope.autoFocusOnMount",e_="focusScope.autoFocusOnUnmount",E5={bubbles:!1,cancelable:!0},Cfe="FocusScope",y0=E.forwardRef((n,e)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:s,...o}=n,[a,l]=E.useState(null),u=ts(i),f=ts(s),h=E.useRef(null),g=Jt(e,v=>l(v)),y=E.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;E.useEffect(()=>{if(r){let v=function(P){if(y.paused||!a)return;const M=P.target;a.contains(M)?h.current=M:Kc(h.current,{select:!0})},w=function(P){if(y.paused||!a)return;const M=P.relatedTarget;M!==null&&(a.contains(M)||Kc(h.current,{select:!0}))},x=function(P){if(document.activeElement===document.body)for(const k of P)k.removedNodes.length>0&&Kc(a)};document.addEventListener("focusin",v),document.addEventListener("focusout",w);const T=new MutationObserver(x);return a&&T.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",w),T.disconnect()}}},[r,a,y.paused]),E.useEffect(()=>{if(a){P5.add(y);const v=document.activeElement;if(!a.contains(v)){const x=new CustomEvent(QE,E5);a.addEventListener(QE,u),a.dispatchEvent(x),x.defaultPrevented||(Tfe(Mfe(C$(a)),{select:!0}),document.activeElement===v&&Kc(a))}return()=>{a.removeEventListener(QE,u),setTimeout(()=>{const x=new CustomEvent(e_,E5);a.addEventListener(e_,f),a.dispatchEvent(x),x.defaultPrevented||Kc(v??document.body,{select:!0}),a.removeEventListener(e_,f),P5.remove(y)},0)}}},[a,u,f,y]);const b=E.useCallback(v=>{if(!t&&!r||y.paused)return;const w=v.key==="Tab"&&!v.altKey&&!v.ctrlKey&&!v.metaKey,x=document.activeElement;if(w&&x){const T=v.currentTarget,[P,M]=Efe(T);P&&M?!v.shiftKey&&x===M?(v.preventDefault(),t&&Kc(P,{select:!0})):v.shiftKey&&x===P&&(v.preventDefault(),t&&Kc(M,{select:!0})):x===T&&v.preventDefault()}},[t,r,y.paused]);return m.jsx(ht.div,{tabIndex:-1,...o,ref:g,onKeyDown:b})});y0.displayName=Cfe;function Tfe(n,{select:e=!1}={}){const t=document.activeElement;for(const r of n)if(Kc(r,{select:e}),document.activeElement!==t)return}function Efe(n){const e=C$(n),t=_5(e,n),r=_5(e.reverse(),n);return[t,r]}function C$(n){const e=[],t=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;t.nextNode();)e.push(t.currentNode);return e}function _5(n,e){for(const t of n)if(!_fe(t,{upTo:e}))return t}function _fe(n,{upTo:e}){if(getComputedStyle(n).visibility==="hidden")return!0;for(;n;){if(e!==void 0&&n===e)return!1;if(getComputedStyle(n).display==="none")return!0;n=n.parentElement}return!1}function Pfe(n){return n instanceof HTMLInputElement&&"select"in n}function Kc(n,{select:e=!1}={}){if(n&&n.focus){const t=document.activeElement;n.focus({preventScroll:!0}),n!==t&&Pfe(n)&&e&&n.select()}}var P5=Ife();function Ife(){let n=[];return{add(e){const t=n[0];e!==t&&t?.pause(),n=I5(n,e),n.unshift(e)},remove(e){n=I5(n,e),n[0]?.resume()}}}function I5(n,e){const t=[...n],r=t.indexOf(e);return r!==-1&&t.splice(r,1),t}function Mfe(n){return n.filter(e=>e.tagName!=="A")}var kfe="Portal",py=E.forwardRef((n,e)=>{const{container:t,...r}=n,[i,s]=E.useState(!1);Wl(()=>s(!0),[]);const o=t||i&&globalThis?.document?.body;return o?qte.createPortal(m.jsx(ht.div,{...r,ref:e}),o):null});py.displayName=kfe;var t_=0;function tM(){E.useEffect(()=>{const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",n[0]??M5()),document.body.insertAdjacentElement("beforeend",n[1]??M5()),t_++,()=>{t_===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),t_--}},[])}function M5(){const n=document.createElement("span");return n.setAttribute("data-radix-focus-guard",""),n.tabIndex=0,n.style.outline="none",n.style.opacity="0",n.style.position="fixed",n.style.pointerEvents="none",n}var Na=function(){return Na=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++){t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},Na.apply(this,arguments)};function T$(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(n);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(t[r[i]]=n[r[i]]);return t}function Afe(n,e,t){if(t||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return n.concat(s||Array.prototype.slice.call(e))}var Nb="right-scroll-bar-position",zb="width-before-scroll-bar",Ofe="with-scroll-bars-hidden",Dfe="--removed-body-scroll-bar-size";function n_(n,e){return typeof n=="function"?n(e):n&&(n.current=e),n}function Rfe(n,e){var t=E.useState(function(){return{value:n,callback:e,facade:{get current(){return t.value},set current(r){var i=t.value;i!==r&&(t.value=r,t.callback(r,i))}}}})[0];return t.callback=e,t.facade}var jfe=typeof window<"u"?E.useLayoutEffect:E.useEffect,k5=new WeakMap;function Lfe(n,e){var t=Rfe(null,function(r){return n.forEach(function(i){return n_(i,r)})});return jfe(function(){var r=k5.get(t);if(r){var i=new Set(r),s=new Set(n),o=t.current;i.forEach(function(a){s.has(a)||n_(a,null)}),s.forEach(function(a){i.has(a)||n_(a,o)})}k5.set(t,n)},[n]),t}function Nfe(n){return n}function zfe(n,e){e===void 0&&(e=Nfe);var t=[],r=!1,i={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return t.length?t[t.length-1]:n},useMedium:function(s){var o=e(s,r);return t.push(o),function(){t=t.filter(function(a){return a!==o})}},assignSyncMedium:function(s){for(r=!0;t.length;){var o=t;t=[],o.forEach(s)}t={push:function(a){return s(a)},filter:function(){return t}}},assignMedium:function(s){r=!0;var o=[];if(t.length){var a=t;t=[],a.forEach(s),o=t}var l=function(){var f=o;o=[],f.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),t={push:function(f){o.push(f),u()},filter:function(f){return o=o.filter(f),t}}}};return i}function Bfe(n){n===void 0&&(n={});var e=zfe(null);return e.options=Na({async:!0,ssr:!1},n),e}var E$=function(n){var e=n.sideCar,t=T$(n,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return E.createElement(r,Na({},t))};E$.isSideCarExport=!0;function Ffe(n,e){return n.useMedium(e),E$}var _$=Bfe(),r_=function(){},S0=E.forwardRef(function(n,e){var t=E.useRef(null),r=E.useState({onScrollCapture:r_,onWheelCapture:r_,onTouchMoveCapture:r_}),i=r[0],s=r[1],o=n.forwardProps,a=n.children,l=n.className,u=n.removeScrollBar,f=n.enabled,h=n.shards,g=n.sideCar,y=n.noRelative,b=n.noIsolation,v=n.inert,w=n.allowPinchZoom,x=n.as,T=x===void 0?"div":x,P=n.gapMode,M=T$(n,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=g,A=Lfe([t,e]),O=Na(Na({},M),i);return E.createElement(E.Fragment,null,f&&E.createElement(k,{sideCar:_$,removeScrollBar:u,shards:h,noRelative:y,noIsolation:b,inert:v,setCallbacks:s,allowPinchZoom:!!w,lockRef:t,gapMode:P}),o?E.cloneElement(E.Children.only(a),Na(Na({},O),{ref:A})):E.createElement(T,Na({},O,{className:l,ref:A}),a))});S0.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};S0.classNames={fullWidth:zb,zeroRight:Nb};var Ufe=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Hfe(){if(!document)return null;var n=document.createElement("style");n.type="text/css";var e=Ufe();return e&&n.setAttribute("nonce",e),n}function $fe(n,e){n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}function Kfe(n){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(n)}var qfe=function(){var n=0,e=null;return{add:function(t){n==0&&(e=Hfe())&&($fe(e,t),Kfe(e)),n++},remove:function(){n--,!n&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Vfe=function(){var n=qfe();return function(e,t){E.useEffect(function(){return n.add(e),function(){n.remove()}},[e&&t])}},P$=function(){var n=Vfe(),e=function(t){var r=t.styles,i=t.dynamic;return n(r,i),null};return e},Gfe={left:0,top:0,right:0,gap:0},i_=function(n){return parseInt(n||"",10)||0},Yfe=function(n){var e=window.getComputedStyle(document.body),t=e[n==="padding"?"paddingLeft":"marginLeft"],r=e[n==="padding"?"paddingTop":"marginTop"],i=e[n==="padding"?"paddingRight":"marginRight"];return[i_(t),i_(r),i_(i)]},Wfe=function(n){if(n===void 0&&(n="margin"),typeof window>"u")return Gfe;var e=Yfe(n),t=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-t+e[2]-e[0])}},Xfe=P$(),Ef="data-scroll-locked",Zfe=function(n,e,t,r){var i=n.left,s=n.top,o=n.right,a=n.gap;return t===void 0&&(t="margin"),`
339
253
  .`.concat(Ofe,` {
340
254
  overflow: hidden `).concat(r,`;
341
255
  padding-right: `).concat(a,"px ").concat(r,`;