@kitschpatrol/tldraw-cli 4.6.19 → 4.6.21

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,431 +0,0 @@
1
- var iN=Object.defineProperty;var aN=(t,e,n)=>e in t?iN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var E=(t,e,n)=>aN(t,typeof e!="symbol"?e+"":e,n);function lN(t,e){for(var n=0;n<e.length;n++){const r=e[n];if(typeof r!="string"&&!Array.isArray(r)){for(const o in r)if(o!=="default"&&!(o in t)){const s=Object.getOwnPropertyDescriptor(r,o);s&&Object.defineProperty(t,o,s.get?s:{enumerable:!0,get:()=>r[o]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const s of o)if(s.type==="childList")for(const i of s.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(o){const s={};return o.integrity&&(s.integrity=o.integrity),o.referrerPolicy&&(s.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?s.credentials="include":o.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(o){if(o.ep)return;o.ep=!0;const s=n(o);fetch(o.href,s)}})();var cn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function fi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var UE={exports:{}},Gf={},HE={exports:{}},ke={};/**
2
- * @license React
3
- * react.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var Hu=Symbol.for("react.element"),cN=Symbol.for("react.portal"),uN=Symbol.for("react.fragment"),dN=Symbol.for("react.strict_mode"),hN=Symbol.for("react.profiler"),pN=Symbol.for("react.provider"),fN=Symbol.for("react.context"),gN=Symbol.for("react.forward_ref"),mN=Symbol.for("react.suspense"),yN=Symbol.for("react.memo"),SN=Symbol.for("react.lazy"),Xb=Symbol.iterator;function vN(t){return t===null||typeof t!="object"?null:(t=Xb&&t[Xb]||t["@@iterator"],typeof t=="function"?t:null)}var KE={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},WE=Object.assign,GE={};function Ol(t,e,n){this.props=t,this.context=e,this.refs=GE,this.updater=n||KE}Ol.prototype.isReactComponent={};Ol.prototype.setState=function(t,e){if(typeof t!="object"&&typeof t!="function"&&t!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")};Ol.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function VE(){}VE.prototype=Ol.prototype;function l0(t,e,n){this.props=t,this.context=e,this.refs=GE,this.updater=n||KE}var c0=l0.prototype=new VE;c0.constructor=l0;WE(c0,Ol.prototype);c0.isPureReactComponent=!0;var qb=Array.isArray,YE=Object.prototype.hasOwnProperty,u0={current:null},XE={key:!0,ref:!0,__self:!0,__source:!0};function qE(t,e,n){var r,o={},s=null,i=null;if(e!=null)for(r in e.ref!==void 0&&(i=e.ref),e.key!==void 0&&(s=""+e.key),e)YE.call(e,r)&&!XE.hasOwnProperty(r)&&(o[r]=e[r]);var a=arguments.length-2;if(a===1)o.children=n;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];o.children=l}if(t&&t.defaultProps)for(r in a=t.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:Hu,type:t,key:s,ref:i,props:o,_owner:u0.current}}function xN(t,e){return{$$typeof:Hu,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}function d0(t){return typeof t=="object"&&t!==null&&t.$$typeof===Hu}function wN(t){var e={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(n){return e[n]})}var Zb=/\/+/g;function Em(t,e){return typeof t=="object"&&t!==null&&t.key!=null?wN(""+t.key):e.toString(36)}function Oh(t,e,n,r,o){var s=typeof t;(s==="undefined"||s==="boolean")&&(t=null);var i=!1;if(t===null)i=!0;else switch(s){case"string":case"number":i=!0;break;case"object":switch(t.$$typeof){case Hu:case cN:i=!0}}if(i)return i=t,o=o(i),t=r===""?"."+Em(i,0):r,qb(o)?(n="",t!=null&&(n=t.replace(Zb,"$&/")+"/"),Oh(o,e,n,"",function(c){return c})):o!=null&&(d0(o)&&(o=xN(o,n+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(Zb,"$&/")+"/")+t)),e.push(o)),1;if(i=0,r=r===""?".":r+":",qb(t))for(var a=0;a<t.length;a++){s=t[a];var l=r+Em(s,a);i+=Oh(s,e,n,l,o)}else if(l=vN(t),typeof l=="function")for(t=l.call(t),a=0;!(s=t.next()).done;)s=s.value,l=r+Em(s,a++),i+=Oh(s,e,n,l,o);else if(s==="object")throw e=String(t),Error("Objects are not valid as a React child (found: "+(e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e)+"). If you meant to render a collection of children, use an array instead.");return i}function Td(t,e,n){if(t==null)return t;var r=[],o=0;return Oh(t,r,"","",function(s){return e.call(n,s,o++)}),r}function bN(t){if(t._status===-1){var e=t._result;e=e(),e.then(function(n){(t._status===0||t._status===-1)&&(t._status=1,t._result=n)},function(n){(t._status===0||t._status===-1)&&(t._status=2,t._result=n)}),t._status===-1&&(t._status=0,t._result=e)}if(t._status===1)return t._result.default;throw t._result}var wn={current:null},Dh={transition:null},PN={ReactCurrentDispatcher:wn,ReactCurrentBatchConfig:Dh,ReactCurrentOwner:u0};function ZE(){throw Error("act(...) is not supported in production builds of React.")}ke.Children={map:Td,forEach:function(t,e,n){Td(t,function(){e.apply(this,arguments)},n)},count:function(t){var e=0;return Td(t,function(){e++}),e},toArray:function(t){return Td(t,function(e){return e})||[]},only:function(t){if(!d0(t))throw Error("React.Children.only expected to receive a single React element child.");return t}};ke.Component=Ol;ke.Fragment=uN;ke.Profiler=hN;ke.PureComponent=l0;ke.StrictMode=dN;ke.Suspense=mN;ke.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=PN;ke.act=ZE;ke.cloneElement=function(t,e,n){if(t==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+t+".");var r=WE({},t.props),o=t.key,s=t.ref,i=t._owner;if(e!=null){if(e.ref!==void 0&&(s=e.ref,i=u0.current),e.key!==void 0&&(o=""+e.key),t.type&&t.type.defaultProps)var a=t.type.defaultProps;for(l in e)YE.call(e,l)&&!XE.hasOwnProperty(l)&&(r[l]=e[l]===void 0&&a!==void 0?a[l]:e[l])}var l=arguments.length-2;if(l===1)r.children=n;else if(1<l){a=Array(l);for(var c=0;c<l;c++)a[c]=arguments[c+2];r.children=a}return{$$typeof:Hu,type:t.type,key:o,ref:s,props:r,_owner:i}};ke.createContext=function(t){return t={$$typeof:fN,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},t.Provider={$$typeof:pN,_context:t},t.Consumer=t};ke.createElement=qE;ke.createFactory=function(t){var e=qE.bind(null,t);return e.type=t,e};ke.createRef=function(){return{current:null}};ke.forwardRef=function(t){return{$$typeof:gN,render:t}};ke.isValidElement=d0;ke.lazy=function(t){return{$$typeof:SN,_payload:{_status:-1,_result:t},_init:bN}};ke.memo=function(t,e){return{$$typeof:yN,type:t,compare:e===void 0?null:e}};ke.startTransition=function(t){var e=Dh.transition;Dh.transition={};try{t()}finally{Dh.transition=e}};ke.unstable_act=ZE;ke.useCallback=function(t,e){return wn.current.useCallback(t,e)};ke.useContext=function(t){return wn.current.useContext(t)};ke.useDebugValue=function(){};ke.useDeferredValue=function(t){return wn.current.useDeferredValue(t)};ke.useEffect=function(t,e){return wn.current.useEffect(t,e)};ke.useId=function(){return wn.current.useId()};ke.useImperativeHandle=function(t,e,n){return wn.current.useImperativeHandle(t,e,n)};ke.useInsertionEffect=function(t,e){return wn.current.useInsertionEffect(t,e)};ke.useLayoutEffect=function(t,e){return wn.current.useLayoutEffect(t,e)};ke.useMemo=function(t,e){return wn.current.useMemo(t,e)};ke.useReducer=function(t,e,n){return wn.current.useReducer(t,e,n)};ke.useRef=function(t){return wn.current.useRef(t)};ke.useState=function(t){return wn.current.useState(t)};ke.useSyncExternalStore=function(t,e,n){return wn.current.useSyncExternalStore(t,e,n)};ke.useTransition=function(){return wn.current.useTransition()};ke.version="18.3.1";HE.exports=ke;var w=HE.exports;const Ie=fi(w),CN=lN({__proto__:null,default:Ie},[w]);/**
10
- * @license React
11
- * react-jsx-runtime.production.min.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var _N=w,IN=Symbol.for("react.element"),EN=Symbol.for("react.fragment"),kN=Object.prototype.hasOwnProperty,TN=_N.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,MN={key:!0,ref:!0,__self:!0,__source:!0};function QE(t,e,n){var r,o={},s=null,i=null;n!==void 0&&(s=""+n),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(i=e.ref);for(r in e)kN.call(e,r)&&!MN.hasOwnProperty(r)&&(o[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)o[r]===void 0&&(o[r]=e[r]);return{$$typeof:IN,type:t,key:s,ref:i,props:o,_owner:TN.current}}Gf.Fragment=EN;Gf.jsx=QE;Gf.jsxs=QE;UE.exports=Gf;var d=UE.exports,US={},JE={exports:{}},mr={},e2={exports:{}},t2={};/**
18
- * @license React
19
- * scheduler.production.min.js
20
- *
21
- * Copyright (c) Facebook, Inc. and its 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
- */(function(t){function e(N,H){var Y=N.length;N.push(H);e:for(;0<Y;){var ee=Y-1>>>1,ce=N[ee];if(0<o(ce,H))N[ee]=H,N[Y]=ce,Y=ee;else break e}}function n(N){return N.length===0?null:N[0]}function r(N){if(N.length===0)return null;var H=N[0],Y=N.pop();if(Y!==H){N[0]=Y;e:for(var ee=0,ce=N.length,ge=ce>>>1;ee<ge;){var Te=2*(ee+1)-1,se=N[Te],We=Te+1,$e=N[We];if(0>o(se,Y))We<ce&&0>o($e,se)?(N[ee]=$e,N[We]=Y,ee=We):(N[ee]=se,N[Te]=Y,ee=Te);else if(We<ce&&0>o($e,Y))N[ee]=$e,N[We]=Y,ee=We;else break e}}return H}function o(N,H){var Y=N.sortIndex-H.sortIndex;return Y!==0?Y:N.id-H.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;t.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();t.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,h=null,p=3,f=!1,g=!1,m=!1,v=typeof setTimeout=="function"?setTimeout:null,S=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function b(N){for(var H=n(c);H!==null;){if(H.callback===null)r(c);else if(H.startTime<=N)r(c),H.sortIndex=H.expirationTime,e(l,H);else break;H=n(c)}}function P(N){if(m=!1,b(N),!g)if(n(l)!==null)g=!0,z(C);else{var H=n(c);H!==null&&K(P,H.startTime-N)}}function C(N,H){g=!1,m&&(m=!1,S(_),_=-1),f=!0;var Y=p;try{for(b(H),h=n(l);h!==null&&(!(h.expirationTime>H)||N&&!R());){var ee=h.callback;if(typeof ee=="function"){h.callback=null,p=h.priorityLevel;var ce=ee(h.expirationTime<=H);H=t.unstable_now(),typeof ce=="function"?h.callback=ce:h===n(l)&&r(l),b(H)}else r(l);h=n(l)}if(h!==null)var ge=!0;else{var Te=n(c);Te!==null&&K(P,Te.startTime-H),ge=!1}return ge}finally{h=null,p=Y,f=!1}}var I=!1,T=null,_=-1,k=5,M=-1;function R(){return!(t.unstable_now()-M<k)}function j(){if(T!==null){var N=t.unstable_now();M=N;var H=!0;try{H=T(!0,N)}finally{H?O():(I=!1,T=null)}}else I=!1}var O;if(typeof y=="function")O=function(){y(j)};else if(typeof MessageChannel<"u"){var D=new MessageChannel,B=D.port2;D.port1.onmessage=j,O=function(){B.postMessage(null)}}else O=function(){v(j,0)};function z(N){T=N,I||(I=!0,O())}function K(N,H){_=v(function(){N(t.unstable_now())},H)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(N){N.callback=null},t.unstable_continueExecution=function(){g||f||(g=!0,z(C))},t.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"):k=0<N?Math.floor(1e3/N):5},t.unstable_getCurrentPriorityLevel=function(){return p},t.unstable_getFirstCallbackNode=function(){return n(l)},t.unstable_next=function(N){switch(p){case 1:case 2:case 3:var H=3;break;default:H=p}var Y=p;p=H;try{return N()}finally{p=Y}},t.unstable_pauseExecution=function(){},t.unstable_requestPaint=function(){},t.unstable_runWithPriority=function(N,H){switch(N){case 1:case 2:case 3:case 4:case 5:break;default:N=3}var Y=p;p=N;try{return H()}finally{p=Y}},t.unstable_scheduleCallback=function(N,H,Y){var ee=t.unstable_now();switch(typeof Y=="object"&&Y!==null?(Y=Y.delay,Y=typeof Y=="number"&&0<Y?ee+Y:ee):Y=ee,N){case 1:var ce=-1;break;case 2:ce=250;break;case 5:ce=1073741823;break;case 4:ce=1e4;break;default:ce=5e3}return ce=Y+ce,N={id:u++,callback:H,priorityLevel:N,startTime:Y,expirationTime:ce,sortIndex:-1},Y>ee?(N.sortIndex=Y,e(c,N),n(l)===null&&N===n(c)&&(m?(S(_),_=-1):m=!0,K(P,Y-ee))):(N.sortIndex=ce,e(l,N),g||f||(g=!0,z(C))),N},t.unstable_shouldYield=R,t.unstable_wrapCallback=function(N){var H=p;return function(){var Y=p;p=H;try{return N.apply(this,arguments)}finally{p=Y}}}})(t2);e2.exports=t2;var AN=e2.exports;/**
26
- * @license React
27
- * react-dom.production.min.js
28
- *
29
- * Copyright (c) Facebook, Inc. and its 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 jN=w,hr=AN;function X(t){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+t,n=1;n<arguments.length;n++)e+="&args[]="+encodeURIComponent(arguments[n]);return"Minified React error #"+t+"; visit "+e+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var n2=new Set,au={};function da(t,e){yl(t,e),yl(t+"Capture",e)}function yl(t,e){for(au[t]=e,t=0;t<e.length;t++)n2.add(e[t])}var cs=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),HS=Object.prototype.hasOwnProperty,ON=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,Qb={},Jb={};function DN(t){return HS.call(Jb,t)?!0:HS.call(Qb,t)?!1:ON.test(t)?Jb[t]=!0:(Qb[t]=!0,!1)}function RN(t,e,n,r){if(n!==null&&n.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(t=t.toLowerCase().slice(0,5),t!=="data-"&&t!=="aria-");default:return!1}}function LN(t,e,n,r){if(e===null||typeof e>"u"||RN(t,e,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function bn(t,e,n,r,o,s,i){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=n,this.propertyName=t,this.type=e,this.sanitizeURL=s,this.removeEmptyString=i}var Yt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){Yt[t]=new bn(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];Yt[e]=new bn(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){Yt[t]=new bn(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){Yt[t]=new bn(t,2,!1,t,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(t){Yt[t]=new bn(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){Yt[t]=new bn(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){Yt[t]=new bn(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){Yt[t]=new bn(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){Yt[t]=new bn(t,5,!1,t.toLowerCase(),null,!1,!1)});var h0=/[\-:]([a-z])/g;function p0(t){return t[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(t){var e=t.replace(h0,p0);Yt[e]=new bn(e,1,!1,t,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(t){var e=t.replace(h0,p0);Yt[e]=new bn(e,1,!1,t,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(t){var e=t.replace(h0,p0);Yt[e]=new bn(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){Yt[t]=new bn(t,1,!1,t.toLowerCase(),null,!1,!1)});Yt.xlinkHref=new bn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){Yt[t]=new bn(t,1,!1,t.toLowerCase(),null,!0,!0)});function f0(t,e,n,r){var o=Yt.hasOwnProperty(e)?Yt[e]:null;(o!==null?o.type!==0:r||!(2<e.length)||e[0]!=="o"&&e[0]!=="O"||e[1]!=="n"&&e[1]!=="N")&&(LN(e,n,o,r)&&(n=null),r||o===null?DN(e)&&(n===null?t.removeAttribute(e):t.setAttribute(e,""+n)):o.mustUseProperty?t[o.propertyName]=n===null?o.type===3?!1:"":n:(e=o.attributeName,r=o.attributeNamespace,n===null?t.removeAttribute(e):(o=o.type,n=o===3||o===4&&n===!0?"":""+n,r?t.setAttributeNS(r,e,n):t.setAttribute(e,n))))}var Ss=jN.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Md=Symbol.for("react.element"),La=Symbol.for("react.portal"),$a=Symbol.for("react.fragment"),g0=Symbol.for("react.strict_mode"),KS=Symbol.for("react.profiler"),r2=Symbol.for("react.provider"),o2=Symbol.for("react.context"),m0=Symbol.for("react.forward_ref"),WS=Symbol.for("react.suspense"),GS=Symbol.for("react.suspense_list"),y0=Symbol.for("react.memo"),Rs=Symbol.for("react.lazy"),s2=Symbol.for("react.offscreen"),eP=Symbol.iterator;function rc(t){return t===null||typeof t!="object"?null:(t=eP&&t[eP]||t["@@iterator"],typeof t=="function"?t:null)}var ft=Object.assign,km;function Mc(t){if(km===void 0)try{throw Error()}catch(n){var e=n.stack.trim().match(/\n( *(at )?)/);km=e&&e[1]||""}return`
34
- `+km+t}var Tm=!1;function Mm(t,e){if(!t||Tm)return"";Tm=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(e)if(e=function(){throw Error()},Object.defineProperty(e.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(e,[])}catch(c){var r=c}Reflect.construct(t,[],e)}else{try{e.call()}catch(c){r=c}t.call(e.prototype)}else{try{throw Error()}catch(c){r=c}t()}}catch(c){if(c&&r&&typeof c.stack=="string"){for(var o=c.stack.split(`
35
- `),s=r.stack.split(`
36
- `),i=o.length-1,a=s.length-1;1<=i&&0<=a&&o[i]!==s[a];)a--;for(;1<=i&&0<=a;i--,a--)if(o[i]!==s[a]){if(i!==1||a!==1)do if(i--,a--,0>a||o[i]!==s[a]){var l=`
37
- `+o[i].replace(" at new "," at ");return t.displayName&&l.includes("<anonymous>")&&(l=l.replace("<anonymous>",t.displayName)),l}while(1<=i&&0<=a);break}}}finally{Tm=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?Mc(t):""}function $N(t){switch(t.tag){case 5:return Mc(t.type);case 16:return Mc("Lazy");case 13:return Mc("Suspense");case 19:return Mc("SuspenseList");case 0:case 2:case 15:return t=Mm(t.type,!1),t;case 11:return t=Mm(t.type.render,!1),t;case 1:return t=Mm(t.type,!0),t;default:return""}}function VS(t){if(t==null)return null;if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case $a:return"Fragment";case La:return"Portal";case KS:return"Profiler";case g0:return"StrictMode";case WS:return"Suspense";case GS:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case o2:return(t.displayName||"Context")+".Consumer";case r2:return(t._context.displayName||"Context")+".Provider";case m0:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case y0:return e=t.displayName||null,e!==null?e:VS(t.type)||"Memo";case Rs:e=t._payload,t=t._init;try{return VS(t(e))}catch{}}return null}function FN(t){var e=t.type;switch(t.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return t=e.render,t=t.displayName||t.name||"",e.displayName||(t!==""?"ForwardRef("+t+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return VS(e);case 8:return e===g0?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function oi(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function i2(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function NN(t){var e=i2(t)?"checked":"value",n=Object.getOwnPropertyDescriptor(t.constructor.prototype,e),r=""+t[e];if(!t.hasOwnProperty(e)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var o=n.get,s=n.set;return Object.defineProperty(t,e,{configurable:!0,get:function(){return o.call(this)},set:function(i){r=""+i,s.call(this,i)}}),Object.defineProperty(t,e,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(i){r=""+i},stopTracking:function(){t._valueTracker=null,delete t[e]}}}}function Ad(t){t._valueTracker||(t._valueTracker=NN(t))}function a2(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=i2(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Tp(t){if(t=t||(typeof document<"u"?document:void 0),typeof t>"u")return null;try{return t.activeElement||t.body}catch{return t.body}}function YS(t,e){var n=e.checked;return ft({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function tP(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=oi(e.value!=null?e.value:n),t._wrapperState={initialChecked:r,initialValue:n,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function l2(t,e){e=e.checked,e!=null&&f0(t,"checked",e,!1)}function XS(t,e){l2(t,e);var n=oi(e.value),r=e.type;if(n!=null)r==="number"?(n===0&&t.value===""||t.value!=n)&&(t.value=""+n):t.value!==""+n&&(t.value=""+n);else if(r==="submit"||r==="reset"){t.removeAttribute("value");return}e.hasOwnProperty("value")?qS(t,e.type,n):e.hasOwnProperty("defaultValue")&&qS(t,e.type,oi(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function nP(t,e,n){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+t._wrapperState.initialValue,n||e===t.value||(t.value=e),t.defaultValue=e}n=t.name,n!==""&&(t.name=""),t.defaultChecked=!!t._wrapperState.initialChecked,n!==""&&(t.name=n)}function qS(t,e,n){(e!=="number"||Tp(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var Ac=Array.isArray;function ol(t,e,n,r){if(t=t.options,e){e={};for(var o=0;o<n.length;o++)e["$"+n[o]]=!0;for(n=0;n<t.length;n++)o=e.hasOwnProperty("$"+t[n].value),t[n].selected!==o&&(t[n].selected=o),o&&r&&(t[n].defaultSelected=!0)}else{for(n=""+oi(n),e=null,o=0;o<t.length;o++){if(t[o].value===n){t[o].selected=!0,r&&(t[o].defaultSelected=!0);return}e!==null||t[o].disabled||(e=t[o])}e!==null&&(e.selected=!0)}}function ZS(t,e){if(e.dangerouslySetInnerHTML!=null)throw Error(X(91));return ft({},e,{value:void 0,defaultValue:void 0,children:""+t._wrapperState.initialValue})}function rP(t,e){var n=e.value;if(n==null){if(n=e.children,e=e.defaultValue,n!=null){if(e!=null)throw Error(X(92));if(Ac(n)){if(1<n.length)throw Error(X(93));n=n[0]}e=n}e==null&&(e=""),n=e}t._wrapperState={initialValue:oi(n)}}function c2(t,e){var n=oi(e.value),r=oi(e.defaultValue);n!=null&&(n=""+n,n!==t.value&&(t.value=n),e.defaultValue==null&&t.defaultValue!==n&&(t.defaultValue=n)),r!=null&&(t.defaultValue=""+r)}function oP(t){var e=t.textContent;e===t._wrapperState.initialValue&&e!==""&&e!==null&&(t.value=e)}function u2(t){switch(t){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function QS(t,e){return t==null||t==="http://www.w3.org/1999/xhtml"?u2(e):t==="http://www.w3.org/2000/svg"&&e==="foreignObject"?"http://www.w3.org/1999/xhtml":t}var jd,d2=function(t){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(e,n,r,o){MSApp.execUnsafeLocalFunction(function(){return t(e,n,r,o)})}:t}(function(t,e){if(t.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in t)t.innerHTML=e;else{for(jd=jd||document.createElement("div"),jd.innerHTML="<svg>"+e.valueOf().toString()+"</svg>",e=jd.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function lu(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Kc={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},zN=["Webkit","ms","Moz","O"];Object.keys(Kc).forEach(function(t){zN.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Kc[e]=Kc[t]})});function h2(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Kc.hasOwnProperty(t)&&Kc[t]?(""+e).trim():e+"px"}function p2(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=h2(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,o):t[n]=o}}var BN=ft({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function JS(t,e){if(e){if(BN[t]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(X(137,t));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(X(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(X(61))}if(e.style!=null&&typeof e.style!="object")throw Error(X(62))}}function ev(t,e){if(t.indexOf("-")===-1)return typeof e.is=="string";switch(t){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var tv=null;function S0(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var nv=null,sl=null,il=null;function sP(t){if(t=Gu(t)){if(typeof nv!="function")throw Error(X(280));var e=t.stateNode;e&&(e=Zf(e),nv(t.stateNode,t.type,e))}}function f2(t){sl?il?il.push(t):il=[t]:sl=t}function g2(){if(sl){var t=sl,e=il;if(il=sl=null,sP(t),e)for(t=0;t<e.length;t++)sP(e[t])}}function m2(t,e){return t(e)}function y2(){}var Am=!1;function S2(t,e,n){if(Am)return t(e,n);Am=!0;try{return m2(t,e,n)}finally{Am=!1,(sl!==null||il!==null)&&(y2(),g2())}}function cu(t,e){var n=t.stateNode;if(n===null)return null;var r=Zf(n);if(r===null)return null;n=r[e];e:switch(e){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(t=t.type,r=!(t==="button"||t==="input"||t==="select"||t==="textarea")),t=!r;break e;default:t=!1}if(t)return null;if(n&&typeof n!="function")throw Error(X(231,e,typeof n));return n}var rv=!1;if(cs)try{var oc={};Object.defineProperty(oc,"passive",{get:function(){rv=!0}}),window.addEventListener("test",oc,oc),window.removeEventListener("test",oc,oc)}catch{rv=!1}function UN(t,e,n,r,o,s,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{e.apply(n,c)}catch(u){this.onError(u)}}var Wc=!1,Mp=null,Ap=!1,ov=null,HN={onError:function(t){Wc=!0,Mp=t}};function KN(t,e,n,r,o,s,i,a,l){Wc=!1,Mp=null,UN.apply(HN,arguments)}function WN(t,e,n,r,o,s,i,a,l){if(KN.apply(this,arguments),Wc){if(Wc){var c=Mp;Wc=!1,Mp=null}else throw Error(X(198));Ap||(Ap=!0,ov=c)}}function ha(t){var e=t,n=t;if(t.alternate)for(;e.return;)e=e.return;else{t=e;do e=t,e.flags&4098&&(n=e.return),t=e.return;while(t)}return e.tag===3?n:null}function v2(t){if(t.tag===13){var e=t.memoizedState;if(e===null&&(t=t.alternate,t!==null&&(e=t.memoizedState)),e!==null)return e.dehydrated}return null}function iP(t){if(ha(t)!==t)throw Error(X(188))}function GN(t){var e=t.alternate;if(!e){if(e=ha(t),e===null)throw Error(X(188));return e!==t?null:t}for(var n=t,r=e;;){var o=n.return;if(o===null)break;var s=o.alternate;if(s===null){if(r=o.return,r!==null){n=r;continue}break}if(o.child===s.child){for(s=o.child;s;){if(s===n)return iP(o),t;if(s===r)return iP(o),e;s=s.sibling}throw Error(X(188))}if(n.return!==r.return)n=o,r=s;else{for(var i=!1,a=o.child;a;){if(a===n){i=!0,n=o,r=s;break}if(a===r){i=!0,r=o,n=s;break}a=a.sibling}if(!i){for(a=s.child;a;){if(a===n){i=!0,n=s,r=o;break}if(a===r){i=!0,r=s,n=o;break}a=a.sibling}if(!i)throw Error(X(189))}}if(n.alternate!==r)throw Error(X(190))}if(n.tag!==3)throw Error(X(188));return n.stateNode.current===n?t:e}function x2(t){return t=GN(t),t!==null?w2(t):null}function w2(t){if(t.tag===5||t.tag===6)return t;for(t=t.child;t!==null;){var e=w2(t);if(e!==null)return e;t=t.sibling}return null}var b2=hr.unstable_scheduleCallback,aP=hr.unstable_cancelCallback,VN=hr.unstable_shouldYield,YN=hr.unstable_requestPaint,vt=hr.unstable_now,XN=hr.unstable_getCurrentPriorityLevel,v0=hr.unstable_ImmediatePriority,P2=hr.unstable_UserBlockingPriority,jp=hr.unstable_NormalPriority,qN=hr.unstable_LowPriority,C2=hr.unstable_IdlePriority,Vf=null,Po=null;function ZN(t){if(Po&&typeof Po.onCommitFiberRoot=="function")try{Po.onCommitFiberRoot(Vf,t,void 0,(t.current.flags&128)===128)}catch{}}var Yr=Math.clz32?Math.clz32:e6,QN=Math.log,JN=Math.LN2;function e6(t){return t>>>=0,t===0?32:31-(QN(t)/JN|0)|0}var Od=64,Dd=4194304;function jc(t){switch(t&-t){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return t&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return t}}function Op(t,e){var n=t.pendingLanes;if(n===0)return 0;var r=0,o=t.suspendedLanes,s=t.pingedLanes,i=n&268435455;if(i!==0){var a=i&~o;a!==0?r=jc(a):(s&=i,s!==0&&(r=jc(s)))}else i=n&~o,i!==0?r=jc(i):s!==0&&(r=jc(s));if(r===0)return 0;if(e!==0&&e!==r&&!(e&o)&&(o=r&-r,s=e&-e,o>=s||o===16&&(s&4194240)!==0))return e;if(r&4&&(r|=n&16),e=t.entangledLanes,e!==0)for(t=t.entanglements,e&=r;0<e;)n=31-Yr(e),o=1<<n,r|=t[n],e&=~o;return r}function t6(t,e){switch(t){case 1:case 2:case 4:return e+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function n6(t,e){for(var n=t.suspendedLanes,r=t.pingedLanes,o=t.expirationTimes,s=t.pendingLanes;0<s;){var i=31-Yr(s),a=1<<i,l=o[i];l===-1?(!(a&n)||a&r)&&(o[i]=t6(a,e)):l<=e&&(t.expiredLanes|=a),s&=~a}}function sv(t){return t=t.pendingLanes&-1073741825,t!==0?t:t&1073741824?1073741824:0}function _2(){var t=Od;return Od<<=1,!(Od&4194240)&&(Od=64),t}function jm(t){for(var e=[],n=0;31>n;n++)e.push(t);return e}function Ku(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-Yr(e),t[e]=n}function r6(t,e){var n=t.pendingLanes&~e;t.pendingLanes=e,t.suspendedLanes=0,t.pingedLanes=0,t.expiredLanes&=e,t.mutableReadLanes&=e,t.entangledLanes&=e,e=t.entanglements;var r=t.eventTimes;for(t=t.expirationTimes;0<n;){var o=31-Yr(n),s=1<<o;e[o]=0,r[o]=-1,t[o]=-1,n&=~s}}function x0(t,e){var n=t.entangledLanes|=e;for(t=t.entanglements;n;){var r=31-Yr(n),o=1<<r;o&e|t[r]&e&&(t[r]|=e),n&=~o}}var ze=0;function I2(t){return t&=-t,1<t?4<t?t&268435455?16:536870912:4:1}var E2,w0,k2,T2,M2,iv=!1,Rd=[],Vs=null,Ys=null,Xs=null,uu=new Map,du=new Map,$s=[],o6="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function lP(t,e){switch(t){case"focusin":case"focusout":Vs=null;break;case"dragenter":case"dragleave":Ys=null;break;case"mouseover":case"mouseout":Xs=null;break;case"pointerover":case"pointerout":uu.delete(e.pointerId);break;case"gotpointercapture":case"lostpointercapture":du.delete(e.pointerId)}}function sc(t,e,n,r,o,s){return t===null||t.nativeEvent!==s?(t={blockedOn:e,domEventName:n,eventSystemFlags:r,nativeEvent:s,targetContainers:[o]},e!==null&&(e=Gu(e),e!==null&&w0(e)),t):(t.eventSystemFlags|=r,e=t.targetContainers,o!==null&&e.indexOf(o)===-1&&e.push(o),t)}function s6(t,e,n,r,o){switch(e){case"focusin":return Vs=sc(Vs,t,e,n,r,o),!0;case"dragenter":return Ys=sc(Ys,t,e,n,r,o),!0;case"mouseover":return Xs=sc(Xs,t,e,n,r,o),!0;case"pointerover":var s=o.pointerId;return uu.set(s,sc(uu.get(s)||null,t,e,n,r,o)),!0;case"gotpointercapture":return s=o.pointerId,du.set(s,sc(du.get(s)||null,t,e,n,r,o)),!0}return!1}function A2(t){var e=Fi(t.target);if(e!==null){var n=ha(e);if(n!==null){if(e=n.tag,e===13){if(e=v2(n),e!==null){t.blockedOn=e,M2(t.priority,function(){k2(n)});return}}else if(e===3&&n.stateNode.current.memoizedState.isDehydrated){t.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}t.blockedOn=null}function Rh(t){if(t.blockedOn!==null)return!1;for(var e=t.targetContainers;0<e.length;){var n=av(t.domEventName,t.eventSystemFlags,e[0],t.nativeEvent);if(n===null){n=t.nativeEvent;var r=new n.constructor(n.type,n);tv=r,n.target.dispatchEvent(r),tv=null}else return e=Gu(n),e!==null&&w0(e),t.blockedOn=n,!1;e.shift()}return!0}function cP(t,e,n){Rh(t)&&n.delete(e)}function i6(){iv=!1,Vs!==null&&Rh(Vs)&&(Vs=null),Ys!==null&&Rh(Ys)&&(Ys=null),Xs!==null&&Rh(Xs)&&(Xs=null),uu.forEach(cP),du.forEach(cP)}function ic(t,e){t.blockedOn===e&&(t.blockedOn=null,iv||(iv=!0,hr.unstable_scheduleCallback(hr.unstable_NormalPriority,i6)))}function hu(t){function e(o){return ic(o,t)}if(0<Rd.length){ic(Rd[0],t);for(var n=1;n<Rd.length;n++){var r=Rd[n];r.blockedOn===t&&(r.blockedOn=null)}}for(Vs!==null&&ic(Vs,t),Ys!==null&&ic(Ys,t),Xs!==null&&ic(Xs,t),uu.forEach(e),du.forEach(e),n=0;n<$s.length;n++)r=$s[n],r.blockedOn===t&&(r.blockedOn=null);for(;0<$s.length&&(n=$s[0],n.blockedOn===null);)A2(n),n.blockedOn===null&&$s.shift()}var al=Ss.ReactCurrentBatchConfig,Dp=!0;function a6(t,e,n,r){var o=ze,s=al.transition;al.transition=null;try{ze=1,b0(t,e,n,r)}finally{ze=o,al.transition=s}}function l6(t,e,n,r){var o=ze,s=al.transition;al.transition=null;try{ze=4,b0(t,e,n,r)}finally{ze=o,al.transition=s}}function b0(t,e,n,r){if(Dp){var o=av(t,e,n,r);if(o===null)Um(t,e,r,Rp,n),lP(t,r);else if(s6(o,t,e,n,r))r.stopPropagation();else if(lP(t,r),e&4&&-1<o6.indexOf(t)){for(;o!==null;){var s=Gu(o);if(s!==null&&E2(s),s=av(t,e,n,r),s===null&&Um(t,e,r,Rp,n),s===o)break;o=s}o!==null&&r.stopPropagation()}else Um(t,e,r,null,n)}}var Rp=null;function av(t,e,n,r){if(Rp=null,t=S0(r),t=Fi(t),t!==null)if(e=ha(t),e===null)t=null;else if(n=e.tag,n===13){if(t=v2(e),t!==null)return t;t=null}else if(n===3){if(e.stateNode.current.memoizedState.isDehydrated)return e.tag===3?e.stateNode.containerInfo:null;t=null}else e!==t&&(t=null);return Rp=t,null}function j2(t){switch(t){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(XN()){case v0:return 1;case P2:return 4;case jp:case qN:return 16;case C2:return 536870912;default:return 16}default:return 16}}var Us=null,P0=null,Lh=null;function O2(){if(Lh)return Lh;var t,e=P0,n=e.length,r,o="value"in Us?Us.value:Us.textContent,s=o.length;for(t=0;t<n&&e[t]===o[t];t++);var i=n-t;for(r=1;r<=i&&e[n-r]===o[s-r];r++);return Lh=o.slice(t,1<r?1-r:void 0)}function $h(t){var e=t.keyCode;return"charCode"in t?(t=t.charCode,t===0&&e===13&&(t=13)):t=e,t===10&&(t=13),32<=t||t===13?t:0}function Ld(){return!0}function uP(){return!1}function yr(t){function e(n,r,o,s,i){this._reactName=n,this._targetInst=o,this.type=r,this.nativeEvent=s,this.target=i,this.currentTarget=null;for(var a in t)t.hasOwnProperty(a)&&(n=t[a],this[a]=n?n(s):s[a]);return this.isDefaultPrevented=(s.defaultPrevented!=null?s.defaultPrevented:s.returnValue===!1)?Ld:uP,this.isPropagationStopped=uP,this}return ft(e.prototype,{preventDefault:function(){this.defaultPrevented=!0;var n=this.nativeEvent;n&&(n.preventDefault?n.preventDefault():typeof n.returnValue!="unknown"&&(n.returnValue=!1),this.isDefaultPrevented=Ld)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=Ld)},persist:function(){},isPersistent:Ld}),e}var Dl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(t){return t.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},C0=yr(Dl),Wu=ft({},Dl,{view:0,detail:0}),c6=yr(Wu),Om,Dm,ac,Yf=ft({},Wu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:_0,button:0,buttons:0,relatedTarget:function(t){return t.relatedTarget===void 0?t.fromElement===t.srcElement?t.toElement:t.fromElement:t.relatedTarget},movementX:function(t){return"movementX"in t?t.movementX:(t!==ac&&(ac&&t.type==="mousemove"?(Om=t.screenX-ac.screenX,Dm=t.screenY-ac.screenY):Dm=Om=0,ac=t),Om)},movementY:function(t){return"movementY"in t?t.movementY:Dm}}),dP=yr(Yf),u6=ft({},Yf,{dataTransfer:0}),d6=yr(u6),h6=ft({},Wu,{relatedTarget:0}),Rm=yr(h6),p6=ft({},Dl,{animationName:0,elapsedTime:0,pseudoElement:0}),f6=yr(p6),g6=ft({},Dl,{clipboardData:function(t){return"clipboardData"in t?t.clipboardData:window.clipboardData}}),m6=yr(g6),y6=ft({},Dl,{data:0}),hP=yr(y6),S6={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},v6={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},x6={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function w6(t){var e=this.nativeEvent;return e.getModifierState?e.getModifierState(t):(t=x6[t])?!!e[t]:!1}function _0(){return w6}var b6=ft({},Wu,{key:function(t){if(t.key){var e=S6[t.key]||t.key;if(e!=="Unidentified")return e}return t.type==="keypress"?(t=$h(t),t===13?"Enter":String.fromCharCode(t)):t.type==="keydown"||t.type==="keyup"?v6[t.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:_0,charCode:function(t){return t.type==="keypress"?$h(t):0},keyCode:function(t){return t.type==="keydown"||t.type==="keyup"?t.keyCode:0},which:function(t){return t.type==="keypress"?$h(t):t.type==="keydown"||t.type==="keyup"?t.keyCode:0}}),P6=yr(b6),C6=ft({},Yf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),pP=yr(C6),_6=ft({},Wu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:_0}),I6=yr(_6),E6=ft({},Dl,{propertyName:0,elapsedTime:0,pseudoElement:0}),k6=yr(E6),T6=ft({},Yf,{deltaX:function(t){return"deltaX"in t?t.deltaX:"wheelDeltaX"in t?-t.wheelDeltaX:0},deltaY:function(t){return"deltaY"in t?t.deltaY:"wheelDeltaY"in t?-t.wheelDeltaY:"wheelDelta"in t?-t.wheelDelta:0},deltaZ:0,deltaMode:0}),M6=yr(T6),A6=[9,13,27,32],I0=cs&&"CompositionEvent"in window,Gc=null;cs&&"documentMode"in document&&(Gc=document.documentMode);var j6=cs&&"TextEvent"in window&&!Gc,D2=cs&&(!I0||Gc&&8<Gc&&11>=Gc),fP=" ",gP=!1;function R2(t,e){switch(t){case"keyup":return A6.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function L2(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var Fa=!1;function O6(t,e){switch(t){case"compositionend":return L2(e);case"keypress":return e.which!==32?null:(gP=!0,fP);case"textInput":return t=e.data,t===fP&&gP?null:t;default:return null}}function D6(t,e){if(Fa)return t==="compositionend"||!I0&&R2(t,e)?(t=O2(),Lh=P0=Us=null,Fa=!1,t):null;switch(t){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1<e.char.length)return e.char;if(e.which)return String.fromCharCode(e.which)}return null;case"compositionend":return D2&&e.locale!=="ko"?null:e.data;default:return null}}var R6={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function mP(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e==="input"?!!R6[t.type]:e==="textarea"}function $2(t,e,n,r){f2(r),e=Lp(e,"onChange"),0<e.length&&(n=new C0("onChange","change",null,n,r),t.push({event:n,listeners:e}))}var Vc=null,pu=null;function L6(t){Y2(t,0)}function Xf(t){var e=Ba(t);if(a2(e))return t}function $6(t,e){if(t==="change")return e}var F2=!1;if(cs){var Lm;if(cs){var $m="oninput"in document;if(!$m){var yP=document.createElement("div");yP.setAttribute("oninput","return;"),$m=typeof yP.oninput=="function"}Lm=$m}else Lm=!1;F2=Lm&&(!document.documentMode||9<document.documentMode)}function SP(){Vc&&(Vc.detachEvent("onpropertychange",N2),pu=Vc=null)}function N2(t){if(t.propertyName==="value"&&Xf(pu)){var e=[];$2(e,pu,t,S0(t)),S2(L6,e)}}function F6(t,e,n){t==="focusin"?(SP(),Vc=e,pu=n,Vc.attachEvent("onpropertychange",N2)):t==="focusout"&&SP()}function N6(t){if(t==="selectionchange"||t==="keyup"||t==="keydown")return Xf(pu)}function z6(t,e){if(t==="click")return Xf(e)}function B6(t,e){if(t==="input"||t==="change")return Xf(e)}function U6(t,e){return t===e&&(t!==0||1/t===1/e)||t!==t&&e!==e}var Qr=typeof Object.is=="function"?Object.is:U6;function fu(t,e){if(Qr(t,e))return!0;if(typeof t!="object"||t===null||typeof e!="object"||e===null)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var o=n[r];if(!HS.call(e,o)||!Qr(t[o],e[o]))return!1}return!0}function vP(t){for(;t&&t.firstChild;)t=t.firstChild;return t}function xP(t,e){var n=vP(t);t=0;for(var r;n;){if(n.nodeType===3){if(r=t+n.textContent.length,t<=e&&r>=e)return{node:n,offset:e-t};t=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=vP(n)}}function z2(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?z2(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function B2(){for(var t=window,e=Tp();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Tp(t.document)}return e}function E0(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e&&(e==="input"&&(t.type==="text"||t.type==="search"||t.type==="tel"||t.type==="url"||t.type==="password")||e==="textarea"||t.contentEditable==="true")}function H6(t){var e=B2(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&z2(n.ownerDocument.documentElement,n)){if(r!==null&&E0(n)){if(e=r.start,t=r.end,t===void 0&&(t=e),"selectionStart"in n)n.selectionStart=e,n.selectionEnd=Math.min(t,n.value.length);else if(t=(e=n.ownerDocument||document)&&e.defaultView||window,t.getSelection){t=t.getSelection();var o=n.textContent.length,s=Math.min(r.start,o);r=r.end===void 0?s:Math.min(r.end,o),!t.extend&&s>r&&(o=r,r=s,s=o),o=xP(n,s);var i=xP(n,r);o&&i&&(t.rangeCount!==1||t.anchorNode!==o.node||t.anchorOffset!==o.offset||t.focusNode!==i.node||t.focusOffset!==i.offset)&&(e=e.createRange(),e.setStart(o.node,o.offset),t.removeAllRanges(),s>r?(t.addRange(e),t.extend(i.node,i.offset)):(e.setEnd(i.node,i.offset),t.addRange(e)))}}for(e=[],t=n;t=t.parentNode;)t.nodeType===1&&e.push({element:t,left:t.scrollLeft,top:t.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n<e.length;n++)t=e[n],t.element.scrollLeft=t.left,t.element.scrollTop=t.top}}var K6=cs&&"documentMode"in document&&11>=document.documentMode,Na=null,lv=null,Yc=null,cv=!1;function wP(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;cv||Na==null||Na!==Tp(r)||(r=Na,"selectionStart"in r&&E0(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Yc&&fu(Yc,r)||(Yc=r,r=Lp(lv,"onSelect"),0<r.length&&(e=new C0("onSelect","select",null,e,n),t.push({event:e,listeners:r}),e.target=Na)))}function $d(t,e){var n={};return n[t.toLowerCase()]=e.toLowerCase(),n["Webkit"+t]="webkit"+e,n["Moz"+t]="moz"+e,n}var za={animationend:$d("Animation","AnimationEnd"),animationiteration:$d("Animation","AnimationIteration"),animationstart:$d("Animation","AnimationStart"),transitionend:$d("Transition","TransitionEnd")},Fm={},U2={};cs&&(U2=document.createElement("div").style,"AnimationEvent"in window||(delete za.animationend.animation,delete za.animationiteration.animation,delete za.animationstart.animation),"TransitionEvent"in window||delete za.transitionend.transition);function qf(t){if(Fm[t])return Fm[t];if(!za[t])return t;var e=za[t],n;for(n in e)if(e.hasOwnProperty(n)&&n in U2)return Fm[t]=e[n];return t}var H2=qf("animationend"),K2=qf("animationiteration"),W2=qf("animationstart"),G2=qf("transitionend"),V2=new Map,bP="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function gi(t,e){V2.set(t,e),da(e,[t])}for(var Nm=0;Nm<bP.length;Nm++){var zm=bP[Nm],W6=zm.toLowerCase(),G6=zm[0].toUpperCase()+zm.slice(1);gi(W6,"on"+G6)}gi(H2,"onAnimationEnd");gi(K2,"onAnimationIteration");gi(W2,"onAnimationStart");gi("dblclick","onDoubleClick");gi("focusin","onFocus");gi("focusout","onBlur");gi(G2,"onTransitionEnd");yl("onMouseEnter",["mouseout","mouseover"]);yl("onMouseLeave",["mouseout","mouseover"]);yl("onPointerEnter",["pointerout","pointerover"]);yl("onPointerLeave",["pointerout","pointerover"]);da("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));da("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));da("onBeforeInput",["compositionend","keypress","textInput","paste"]);da("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));da("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));da("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Oc="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),V6=new Set("cancel close invalid load scroll toggle".split(" ").concat(Oc));function PP(t,e,n){var r=t.type||"unknown-event";t.currentTarget=n,WN(r,e,void 0,t),t.currentTarget=null}function Y2(t,e){e=(e&4)!==0;for(var n=0;n<t.length;n++){var r=t[n],o=r.event;r=r.listeners;e:{var s=void 0;if(e)for(var i=r.length-1;0<=i;i--){var a=r[i],l=a.instance,c=a.currentTarget;if(a=a.listener,l!==s&&o.isPropagationStopped())break e;PP(o,a,c),s=l}else for(i=0;i<r.length;i++){if(a=r[i],l=a.instance,c=a.currentTarget,a=a.listener,l!==s&&o.isPropagationStopped())break e;PP(o,a,c),s=l}}}if(Ap)throw t=ov,Ap=!1,ov=null,t}function et(t,e){var n=e[fv];n===void 0&&(n=e[fv]=new Set);var r=t+"__bubble";n.has(r)||(X2(e,t,2,!1),n.add(r))}function Bm(t,e,n){var r=0;e&&(r|=4),X2(n,t,r,e)}var Fd="_reactListening"+Math.random().toString(36).slice(2);function gu(t){if(!t[Fd]){t[Fd]=!0,n2.forEach(function(n){n!=="selectionchange"&&(V6.has(n)||Bm(n,!1,t),Bm(n,!0,t))});var e=t.nodeType===9?t:t.ownerDocument;e===null||e[Fd]||(e[Fd]=!0,Bm("selectionchange",!1,e))}}function X2(t,e,n,r){switch(j2(e)){case 1:var o=a6;break;case 4:o=l6;break;default:o=b0}n=o.bind(null,e,n,t),o=void 0,!rv||e!=="touchstart"&&e!=="touchmove"&&e!=="wheel"||(o=!0),r?o!==void 0?t.addEventListener(e,n,{capture:!0,passive:o}):t.addEventListener(e,n,!0):o!==void 0?t.addEventListener(e,n,{passive:o}):t.addEventListener(e,n,!1)}function Um(t,e,n,r,o){var s=r;if(!(e&1)&&!(e&2)&&r!==null)e:for(;;){if(r===null)return;var i=r.tag;if(i===3||i===4){var a=r.stateNode.containerInfo;if(a===o||a.nodeType===8&&a.parentNode===o)break;if(i===4)for(i=r.return;i!==null;){var l=i.tag;if((l===3||l===4)&&(l=i.stateNode.containerInfo,l===o||l.nodeType===8&&l.parentNode===o))return;i=i.return}for(;a!==null;){if(i=Fi(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}S2(function(){var c=s,u=S0(n),h=[];e:{var p=V2.get(t);if(p!==void 0){var f=C0,g=t;switch(t){case"keypress":if($h(n)===0)break e;case"keydown":case"keyup":f=P6;break;case"focusin":g="focus",f=Rm;break;case"focusout":g="blur",f=Rm;break;case"beforeblur":case"afterblur":f=Rm;break;case"click":if(n.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":f=dP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=d6;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=I6;break;case H2:case K2:case W2:f=f6;break;case G2:f=k6;break;case"scroll":f=c6;break;case"wheel":f=M6;break;case"copy":case"cut":case"paste":f=m6;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=pP}var m=(e&4)!==0,v=!m&&t==="scroll",S=m?p!==null?p+"Capture":null:p;m=[];for(var y=c,b;y!==null;){b=y;var P=b.stateNode;if(b.tag===5&&P!==null&&(b=P,S!==null&&(P=cu(y,S),P!=null&&m.push(mu(y,P,b)))),v)break;y=y.return}0<m.length&&(p=new f(p,g,null,n,u),h.push({event:p,listeners:m}))}}if(!(e&7)){e:{if(p=t==="mouseover"||t==="pointerover",f=t==="mouseout"||t==="pointerout",p&&n!==tv&&(g=n.relatedTarget||n.fromElement)&&(Fi(g)||g[us]))break e;if((f||p)&&(p=u.window===u?u:(p=u.ownerDocument)?p.defaultView||p.parentWindow:window,f?(g=n.relatedTarget||n.toElement,f=c,g=g?Fi(g):null,g!==null&&(v=ha(g),g!==v||g.tag!==5&&g.tag!==6)&&(g=null)):(f=null,g=c),f!==g)){if(m=dP,P="onMouseLeave",S="onMouseEnter",y="mouse",(t==="pointerout"||t==="pointerover")&&(m=pP,P="onPointerLeave",S="onPointerEnter",y="pointer"),v=f==null?p:Ba(f),b=g==null?p:Ba(g),p=new m(P,y+"leave",f,n,u),p.target=v,p.relatedTarget=b,P=null,Fi(u)===c&&(m=new m(S,y+"enter",g,n,u),m.target=b,m.relatedTarget=v,P=m),v=P,f&&g)t:{for(m=f,S=g,y=0,b=m;b;b=wa(b))y++;for(b=0,P=S;P;P=wa(P))b++;for(;0<y-b;)m=wa(m),y--;for(;0<b-y;)S=wa(S),b--;for(;y--;){if(m===S||S!==null&&m===S.alternate)break t;m=wa(m),S=wa(S)}m=null}else m=null;f!==null&&CP(h,p,f,m,!1),g!==null&&v!==null&&CP(h,v,g,m,!0)}}e:{if(p=c?Ba(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var C=$6;else if(mP(p))if(F2)C=B6;else{C=N6;var I=F6}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(C=z6);if(C&&(C=C(t,c))){$2(h,C,n,u);break e}I&&I(t,p,c),t==="focusout"&&(I=p._wrapperState)&&I.controlled&&p.type==="number"&&qS(p,"number",p.value)}switch(I=c?Ba(c):window,t){case"focusin":(mP(I)||I.contentEditable==="true")&&(Na=I,lv=c,Yc=null);break;case"focusout":Yc=lv=Na=null;break;case"mousedown":cv=!0;break;case"contextmenu":case"mouseup":case"dragend":cv=!1,wP(h,n,u);break;case"selectionchange":if(K6)break;case"keydown":case"keyup":wP(h,n,u)}var T;if(I0)e:{switch(t){case"compositionstart":var _="onCompositionStart";break e;case"compositionend":_="onCompositionEnd";break e;case"compositionupdate":_="onCompositionUpdate";break e}_=void 0}else Fa?R2(t,n)&&(_="onCompositionEnd"):t==="keydown"&&n.keyCode===229&&(_="onCompositionStart");_&&(D2&&n.locale!=="ko"&&(Fa||_!=="onCompositionStart"?_==="onCompositionEnd"&&Fa&&(T=O2()):(Us=u,P0="value"in Us?Us.value:Us.textContent,Fa=!0)),I=Lp(c,_),0<I.length&&(_=new hP(_,t,null,n,u),h.push({event:_,listeners:I}),T?_.data=T:(T=L2(n),T!==null&&(_.data=T)))),(T=j6?O6(t,n):D6(t,n))&&(c=Lp(c,"onBeforeInput"),0<c.length&&(u=new hP("onBeforeInput","beforeinput",null,n,u),h.push({event:u,listeners:c}),u.data=T))}Y2(h,e)})}function mu(t,e,n){return{instance:t,listener:e,currentTarget:n}}function Lp(t,e){for(var n=e+"Capture",r=[];t!==null;){var o=t,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=cu(t,n),s!=null&&r.unshift(mu(t,s,o)),s=cu(t,e),s!=null&&r.push(mu(t,s,o))),t=t.return}return r}function wa(t){if(t===null)return null;do t=t.return;while(t&&t.tag!==5);return t||null}function CP(t,e,n,r,o){for(var s=e._reactName,i=[];n!==null&&n!==r;){var a=n,l=a.alternate,c=a.stateNode;if(l!==null&&l===r)break;a.tag===5&&c!==null&&(a=c,o?(l=cu(n,s),l!=null&&i.unshift(mu(n,l,a))):o||(l=cu(n,s),l!=null&&i.push(mu(n,l,a)))),n=n.return}i.length!==0&&t.push({event:e,listeners:i})}var Y6=/\r\n?/g,X6=/\u0000|\uFFFD/g;function _P(t){return(typeof t=="string"?t:""+t).replace(Y6,`
38
- `).replace(X6,"")}function Nd(t,e,n){if(e=_P(e),_P(t)!==e&&n)throw Error(X(425))}function $p(){}var uv=null,dv=null;function hv(t,e){return t==="textarea"||t==="noscript"||typeof e.children=="string"||typeof e.children=="number"||typeof e.dangerouslySetInnerHTML=="object"&&e.dangerouslySetInnerHTML!==null&&e.dangerouslySetInnerHTML.__html!=null}var pv=typeof setTimeout=="function"?setTimeout:void 0,q6=typeof clearTimeout=="function"?clearTimeout:void 0,IP=typeof Promise=="function"?Promise:void 0,Z6=typeof queueMicrotask=="function"?queueMicrotask:typeof IP<"u"?function(t){return IP.resolve(null).then(t).catch(Q6)}:pv;function Q6(t){setTimeout(function(){throw t})}function Hm(t,e){var n=e,r=0;do{var o=n.nextSibling;if(t.removeChild(n),o&&o.nodeType===8)if(n=o.data,n==="/$"){if(r===0){t.removeChild(o),hu(e);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=o}while(n);hu(e)}function qs(t){for(;t!=null;t=t.nextSibling){var e=t.nodeType;if(e===1||e===3)break;if(e===8){if(e=t.data,e==="$"||e==="$!"||e==="$?")break;if(e==="/$")return null}}return t}function EP(t){t=t.previousSibling;for(var e=0;t;){if(t.nodeType===8){var n=t.data;if(n==="$"||n==="$!"||n==="$?"){if(e===0)return t;e--}else n==="/$"&&e++}t=t.previousSibling}return null}var Rl=Math.random().toString(36).slice(2),mo="__reactFiber$"+Rl,yu="__reactProps$"+Rl,us="__reactContainer$"+Rl,fv="__reactEvents$"+Rl,J6="__reactListeners$"+Rl,ez="__reactHandles$"+Rl;function Fi(t){var e=t[mo];if(e)return e;for(var n=t.parentNode;n;){if(e=n[us]||n[mo]){if(n=e.alternate,e.child!==null||n!==null&&n.child!==null)for(t=EP(t);t!==null;){if(n=t[mo])return n;t=EP(t)}return e}t=n,n=t.parentNode}return null}function Gu(t){return t=t[mo]||t[us],!t||t.tag!==5&&t.tag!==6&&t.tag!==13&&t.tag!==3?null:t}function Ba(t){if(t.tag===5||t.tag===6)return t.stateNode;throw Error(X(33))}function Zf(t){return t[yu]||null}var gv=[],Ua=-1;function mi(t){return{current:t}}function nt(t){0>Ua||(t.current=gv[Ua],gv[Ua]=null,Ua--)}function Xe(t,e){Ua++,gv[Ua]=t.current,t.current=e}var si={},hn=mi(si),Hn=mi(!1),Vi=si;function Sl(t,e){var n=t.type.contextTypes;if(!n)return si;var r=t.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var o={},s;for(s in n)o[s]=e[s];return r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=e,t.__reactInternalMemoizedMaskedChildContext=o),o}function Kn(t){return t=t.childContextTypes,t!=null}function Fp(){nt(Hn),nt(hn)}function kP(t,e,n){if(hn.current!==si)throw Error(X(168));Xe(hn,e),Xe(Hn,n)}function q2(t,e,n){var r=t.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var o in r)if(!(o in e))throw Error(X(108,FN(t)||"Unknown",o));return ft({},n,r)}function Np(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||si,Vi=hn.current,Xe(hn,t),Xe(Hn,Hn.current),!0}function TP(t,e,n){var r=t.stateNode;if(!r)throw Error(X(169));n?(t=q2(t,e,Vi),r.__reactInternalMemoizedMergedChildContext=t,nt(Hn),nt(hn),Xe(hn,t)):nt(Hn),Xe(Hn,n)}var qo=null,Qf=!1,Km=!1;function Z2(t){qo===null?qo=[t]:qo.push(t)}function tz(t){Qf=!0,Z2(t)}function yi(){if(!Km&&qo!==null){Km=!0;var t=0,e=ze;try{var n=qo;for(ze=1;t<n.length;t++){var r=n[t];do r=r(!0);while(r!==null)}qo=null,Qf=!1}catch(o){throw qo!==null&&(qo=qo.slice(t+1)),b2(v0,yi),o}finally{ze=e,Km=!1}}return null}var Ha=[],Ka=0,zp=null,Bp=0,_r=[],Ir=0,Yi=null,Qo=1,Jo="";function Di(t,e){Ha[Ka++]=Bp,Ha[Ka++]=zp,zp=t,Bp=e}function Q2(t,e,n){_r[Ir++]=Qo,_r[Ir++]=Jo,_r[Ir++]=Yi,Yi=t;var r=Qo;t=Jo;var o=32-Yr(r)-1;r&=~(1<<o),n+=1;var s=32-Yr(e)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,Qo=1<<32-Yr(e)+o|n<<o|r,Jo=s+t}else Qo=1<<s|n<<o|r,Jo=t}function k0(t){t.return!==null&&(Di(t,1),Q2(t,1,0))}function T0(t){for(;t===zp;)zp=Ha[--Ka],Ha[Ka]=null,Bp=Ha[--Ka],Ha[Ka]=null;for(;t===Yi;)Yi=_r[--Ir],_r[Ir]=null,Jo=_r[--Ir],_r[Ir]=null,Qo=_r[--Ir],_r[Ir]=null}var ir=null,or=null,it=!1,Hr=null;function J2(t,e){var n=kr(5,null,null,0);n.elementType="DELETED",n.stateNode=e,n.return=t,e=t.deletions,e===null?(t.deletions=[n],t.flags|=16):e.push(n)}function MP(t,e){switch(t.tag){case 5:var n=t.type;return e=e.nodeType!==1||n.toLowerCase()!==e.nodeName.toLowerCase()?null:e,e!==null?(t.stateNode=e,ir=t,or=qs(e.firstChild),!0):!1;case 6:return e=t.pendingProps===""||e.nodeType!==3?null:e,e!==null?(t.stateNode=e,ir=t,or=null,!0):!1;case 13:return e=e.nodeType!==8?null:e,e!==null?(n=Yi!==null?{id:Qo,overflow:Jo}:null,t.memoizedState={dehydrated:e,treeContext:n,retryLane:1073741824},n=kr(18,null,null,0),n.stateNode=e,n.return=t,t.child=n,ir=t,or=null,!0):!1;default:return!1}}function mv(t){return(t.mode&1)!==0&&(t.flags&128)===0}function yv(t){if(it){var e=or;if(e){var n=e;if(!MP(t,e)){if(mv(t))throw Error(X(418));e=qs(n.nextSibling);var r=ir;e&&MP(t,e)?J2(r,n):(t.flags=t.flags&-4097|2,it=!1,ir=t)}}else{if(mv(t))throw Error(X(418));t.flags=t.flags&-4097|2,it=!1,ir=t}}}function AP(t){for(t=t.return;t!==null&&t.tag!==5&&t.tag!==3&&t.tag!==13;)t=t.return;ir=t}function zd(t){if(t!==ir)return!1;if(!it)return AP(t),it=!0,!1;var e;if((e=t.tag!==3)&&!(e=t.tag!==5)&&(e=t.type,e=e!=="head"&&e!=="body"&&!hv(t.type,t.memoizedProps)),e&&(e=or)){if(mv(t))throw ek(),Error(X(418));for(;e;)J2(t,e),e=qs(e.nextSibling)}if(AP(t),t.tag===13){if(t=t.memoizedState,t=t!==null?t.dehydrated:null,!t)throw Error(X(317));e:{for(t=t.nextSibling,e=0;t;){if(t.nodeType===8){var n=t.data;if(n==="/$"){if(e===0){or=qs(t.nextSibling);break e}e--}else n!=="$"&&n!=="$!"&&n!=="$?"||e++}t=t.nextSibling}or=null}}else or=ir?qs(t.stateNode.nextSibling):null;return!0}function ek(){for(var t=or;t;)t=qs(t.nextSibling)}function vl(){or=ir=null,it=!1}function M0(t){Hr===null?Hr=[t]:Hr.push(t)}var nz=Ss.ReactCurrentBatchConfig;function lc(t,e,n){if(t=n.ref,t!==null&&typeof t!="function"&&typeof t!="object"){if(n._owner){if(n=n._owner,n){if(n.tag!==1)throw Error(X(309));var r=n.stateNode}if(!r)throw Error(X(147,t));var o=r,s=""+t;return e!==null&&e.ref!==null&&typeof e.ref=="function"&&e.ref._stringRef===s?e.ref:(e=function(i){var a=o.refs;i===null?delete a[s]:a[s]=i},e._stringRef=s,e)}if(typeof t!="string")throw Error(X(284));if(!n._owner)throw Error(X(290,t))}return t}function Bd(t,e){throw t=Object.prototype.toString.call(e),Error(X(31,t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t))}function jP(t){var e=t._init;return e(t._payload)}function tk(t){function e(S,y){if(t){var b=S.deletions;b===null?(S.deletions=[y],S.flags|=16):b.push(y)}}function n(S,y){if(!t)return null;for(;y!==null;)e(S,y),y=y.sibling;return null}function r(S,y){for(S=new Map;y!==null;)y.key!==null?S.set(y.key,y):S.set(y.index,y),y=y.sibling;return S}function o(S,y){return S=ei(S,y),S.index=0,S.sibling=null,S}function s(S,y,b){return S.index=b,t?(b=S.alternate,b!==null?(b=b.index,b<y?(S.flags|=2,y):b):(S.flags|=2,y)):(S.flags|=1048576,y)}function i(S){return t&&S.alternate===null&&(S.flags|=2),S}function a(S,y,b,P){return y===null||y.tag!==6?(y=Zm(b,S.mode,P),y.return=S,y):(y=o(y,b),y.return=S,y)}function l(S,y,b,P){var C=b.type;return C===$a?u(S,y,b.props.children,P,b.key):y!==null&&(y.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Rs&&jP(C)===y.type)?(P=o(y,b.props),P.ref=lc(S,y,b),P.return=S,P):(P=Kh(b.type,b.key,b.props,null,S.mode,P),P.ref=lc(S,y,b),P.return=S,P)}function c(S,y,b,P){return y===null||y.tag!==4||y.stateNode.containerInfo!==b.containerInfo||y.stateNode.implementation!==b.implementation?(y=Qm(b,S.mode,P),y.return=S,y):(y=o(y,b.children||[]),y.return=S,y)}function u(S,y,b,P,C){return y===null||y.tag!==7?(y=Hi(b,S.mode,P,C),y.return=S,y):(y=o(y,b),y.return=S,y)}function h(S,y,b){if(typeof y=="string"&&y!==""||typeof y=="number")return y=Zm(""+y,S.mode,b),y.return=S,y;if(typeof y=="object"&&y!==null){switch(y.$$typeof){case Md:return b=Kh(y.type,y.key,y.props,null,S.mode,b),b.ref=lc(S,null,y),b.return=S,b;case La:return y=Qm(y,S.mode,b),y.return=S,y;case Rs:var P=y._init;return h(S,P(y._payload),b)}if(Ac(y)||rc(y))return y=Hi(y,S.mode,b,null),y.return=S,y;Bd(S,y)}return null}function p(S,y,b,P){var C=y!==null?y.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return C!==null?null:a(S,y,""+b,P);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case Md:return b.key===C?l(S,y,b,P):null;case La:return b.key===C?c(S,y,b,P):null;case Rs:return C=b._init,p(S,y,C(b._payload),P)}if(Ac(b)||rc(b))return C!==null?null:u(S,y,b,P,null);Bd(S,b)}return null}function f(S,y,b,P,C){if(typeof P=="string"&&P!==""||typeof P=="number")return S=S.get(b)||null,a(y,S,""+P,C);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case Md:return S=S.get(P.key===null?b:P.key)||null,l(y,S,P,C);case La:return S=S.get(P.key===null?b:P.key)||null,c(y,S,P,C);case Rs:var I=P._init;return f(S,y,b,I(P._payload),C)}if(Ac(P)||rc(P))return S=S.get(b)||null,u(y,S,P,C,null);Bd(y,P)}return null}function g(S,y,b,P){for(var C=null,I=null,T=y,_=y=0,k=null;T!==null&&_<b.length;_++){T.index>_?(k=T,T=null):k=T.sibling;var M=p(S,T,b[_],P);if(M===null){T===null&&(T=k);break}t&&T&&M.alternate===null&&e(S,T),y=s(M,y,_),I===null?C=M:I.sibling=M,I=M,T=k}if(_===b.length)return n(S,T),it&&Di(S,_),C;if(T===null){for(;_<b.length;_++)T=h(S,b[_],P),T!==null&&(y=s(T,y,_),I===null?C=T:I.sibling=T,I=T);return it&&Di(S,_),C}for(T=r(S,T);_<b.length;_++)k=f(T,S,_,b[_],P),k!==null&&(t&&k.alternate!==null&&T.delete(k.key===null?_:k.key),y=s(k,y,_),I===null?C=k:I.sibling=k,I=k);return t&&T.forEach(function(R){return e(S,R)}),it&&Di(S,_),C}function m(S,y,b,P){var C=rc(b);if(typeof C!="function")throw Error(X(150));if(b=C.call(b),b==null)throw Error(X(151));for(var I=C=null,T=y,_=y=0,k=null,M=b.next();T!==null&&!M.done;_++,M=b.next()){T.index>_?(k=T,T=null):k=T.sibling;var R=p(S,T,M.value,P);if(R===null){T===null&&(T=k);break}t&&T&&R.alternate===null&&e(S,T),y=s(R,y,_),I===null?C=R:I.sibling=R,I=R,T=k}if(M.done)return n(S,T),it&&Di(S,_),C;if(T===null){for(;!M.done;_++,M=b.next())M=h(S,M.value,P),M!==null&&(y=s(M,y,_),I===null?C=M:I.sibling=M,I=M);return it&&Di(S,_),C}for(T=r(S,T);!M.done;_++,M=b.next())M=f(T,S,_,M.value,P),M!==null&&(t&&M.alternate!==null&&T.delete(M.key===null?_:M.key),y=s(M,y,_),I===null?C=M:I.sibling=M,I=M);return t&&T.forEach(function(j){return e(S,j)}),it&&Di(S,_),C}function v(S,y,b,P){if(typeof b=="object"&&b!==null&&b.type===$a&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case Md:e:{for(var C=b.key,I=y;I!==null;){if(I.key===C){if(C=b.type,C===$a){if(I.tag===7){n(S,I.sibling),y=o(I,b.props.children),y.return=S,S=y;break e}}else if(I.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Rs&&jP(C)===I.type){n(S,I.sibling),y=o(I,b.props),y.ref=lc(S,I,b),y.return=S,S=y;break e}n(S,I);break}else e(S,I);I=I.sibling}b.type===$a?(y=Hi(b.props.children,S.mode,P,b.key),y.return=S,S=y):(P=Kh(b.type,b.key,b.props,null,S.mode,P),P.ref=lc(S,y,b),P.return=S,S=P)}return i(S);case La:e:{for(I=b.key;y!==null;){if(y.key===I)if(y.tag===4&&y.stateNode.containerInfo===b.containerInfo&&y.stateNode.implementation===b.implementation){n(S,y.sibling),y=o(y,b.children||[]),y.return=S,S=y;break e}else{n(S,y);break}else e(S,y);y=y.sibling}y=Qm(b,S.mode,P),y.return=S,S=y}return i(S);case Rs:return I=b._init,v(S,y,I(b._payload),P)}if(Ac(b))return g(S,y,b,P);if(rc(b))return m(S,y,b,P);Bd(S,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,y!==null&&y.tag===6?(n(S,y.sibling),y=o(y,b),y.return=S,S=y):(n(S,y),y=Zm(b,S.mode,P),y.return=S,S=y),i(S)):n(S,y)}return v}var xl=tk(!0),nk=tk(!1),Up=mi(null),Hp=null,Wa=null,A0=null;function j0(){A0=Wa=Hp=null}function O0(t){var e=Up.current;nt(Up),t._currentValue=e}function Sv(t,e,n){for(;t!==null;){var r=t.alternate;if((t.childLanes&e)!==e?(t.childLanes|=e,r!==null&&(r.childLanes|=e)):r!==null&&(r.childLanes&e)!==e&&(r.childLanes|=e),t===n)break;t=t.return}}function ll(t,e){Hp=t,A0=Wa=null,t=t.dependencies,t!==null&&t.firstContext!==null&&(t.lanes&e&&(Nn=!0),t.firstContext=null)}function jr(t){var e=t._currentValue;if(A0!==t)if(t={context:t,memoizedValue:e,next:null},Wa===null){if(Hp===null)throw Error(X(308));Wa=t,Hp.dependencies={lanes:0,firstContext:t}}else Wa=Wa.next=t;return e}var Ni=null;function D0(t){Ni===null?Ni=[t]:Ni.push(t)}function rk(t,e,n,r){var o=e.interleaved;return o===null?(n.next=n,D0(e)):(n.next=o.next,o.next=n),e.interleaved=n,ds(t,r)}function ds(t,e){t.lanes|=e;var n=t.alternate;for(n!==null&&(n.lanes|=e),n=t,t=t.return;t!==null;)t.childLanes|=e,n=t.alternate,n!==null&&(n.childLanes|=e),n=t,t=t.return;return n.tag===3?n.stateNode:null}var Ls=!1;function R0(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function ok(t,e){t=t.updateQueue,e.updateQueue===t&&(e.updateQueue={baseState:t.baseState,firstBaseUpdate:t.firstBaseUpdate,lastBaseUpdate:t.lastBaseUpdate,shared:t.shared,effects:t.effects})}function ns(t,e){return{eventTime:t,lane:e,tag:0,payload:null,callback:null,next:null}}function Zs(t,e,n){var r=t.updateQueue;if(r===null)return null;if(r=r.shared,Oe&2){var o=r.pending;return o===null?e.next=e:(e.next=o.next,o.next=e),r.pending=e,ds(t,n)}return o=r.interleaved,o===null?(e.next=e,D0(r)):(e.next=o.next,o.next=e),r.interleaved=e,ds(t,n)}function Fh(t,e,n){if(e=e.updateQueue,e!==null&&(e=e.shared,(n&4194240)!==0)){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,x0(t,n)}}function OP(t,e){var n=t.updateQueue,r=t.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var o=null,s=null;if(n=n.firstBaseUpdate,n!==null){do{var i={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};s===null?o=s=i:s=s.next=i,n=n.next}while(n!==null);s===null?o=s=e:s=s.next=e}else o=s=e;n={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:s,shared:r.shared,effects:r.effects},t.updateQueue=n;return}t=n.lastBaseUpdate,t===null?n.firstBaseUpdate=e:t.next=e,n.lastBaseUpdate=e}function Kp(t,e,n,r){var o=t.updateQueue;Ls=!1;var s=o.firstBaseUpdate,i=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var l=a,c=l.next;l.next=null,i===null?s=c:i.next=c,i=l;var u=t.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=c:a.next=c,u.lastBaseUpdate=l))}if(s!==null){var h=o.baseState;i=0,u=c=l=null,a=s;do{var p=a.lane,f=a.eventTime;if((r&p)===p){u!==null&&(u=u.next={eventTime:f,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var g=t,m=a;switch(p=e,f=n,m.tag){case 1:if(g=m.payload,typeof g=="function"){h=g.call(f,h,p);break e}h=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=m.payload,p=typeof g=="function"?g.call(f,h,p):g,p==null)break e;h=ft({},h,p);break e;case 2:Ls=!0}}a.callback!==null&&a.lane!==0&&(t.flags|=64,p=o.effects,p===null?o.effects=[a]:p.push(a))}else f={eventTime:f,lane:p,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(c=u=f,l=h):u=u.next=f,i|=p;if(a=a.next,a===null){if(a=o.shared.pending,a===null)break;p=a,a=p.next,p.next=null,o.lastBaseUpdate=p,o.shared.pending=null}}while(!0);if(u===null&&(l=h),o.baseState=l,o.firstBaseUpdate=c,o.lastBaseUpdate=u,e=o.shared.interleaved,e!==null){o=e;do i|=o.lane,o=o.next;while(o!==e)}else s===null&&(o.shared.lanes=0);qi|=i,t.lanes=i,t.memoizedState=h}}function DP(t,e,n){if(t=e.effects,e.effects=null,t!==null)for(e=0;e<t.length;e++){var r=t[e],o=r.callback;if(o!==null){if(r.callback=null,r=n,typeof o!="function")throw Error(X(191,o));o.call(r)}}}var Vu={},Co=mi(Vu),Su=mi(Vu),vu=mi(Vu);function zi(t){if(t===Vu)throw Error(X(174));return t}function L0(t,e){switch(Xe(vu,e),Xe(Su,t),Xe(Co,Vu),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:QS(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=QS(e,t)}nt(Co),Xe(Co,e)}function wl(){nt(Co),nt(Su),nt(vu)}function sk(t){zi(vu.current);var e=zi(Co.current),n=QS(e,t.type);e!==n&&(Xe(Su,t),Xe(Co,n))}function $0(t){Su.current===t&&(nt(Co),nt(Su))}var ut=mi(0);function Wp(t){for(var e=t;e!==null;){if(e.tag===13){var n=e.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break;for(;e.sibling===null;){if(e.return===null||e.return===t)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var Wm=[];function F0(){for(var t=0;t<Wm.length;t++)Wm[t]._workInProgressVersionPrimary=null;Wm.length=0}var Nh=Ss.ReactCurrentDispatcher,Gm=Ss.ReactCurrentBatchConfig,Xi=0,pt=null,_t=null,kt=null,Gp=!1,Xc=!1,xu=0,rz=0;function en(){throw Error(X(321))}function N0(t,e){if(e===null)return!1;for(var n=0;n<e.length&&n<t.length;n++)if(!Qr(t[n],e[n]))return!1;return!0}function z0(t,e,n,r,o,s){if(Xi=s,pt=e,e.memoizedState=null,e.updateQueue=null,e.lanes=0,Nh.current=t===null||t.memoizedState===null?az:lz,t=n(r,o),Xc){s=0;do{if(Xc=!1,xu=0,25<=s)throw Error(X(301));s+=1,kt=_t=null,e.updateQueue=null,Nh.current=cz,t=n(r,o)}while(Xc)}if(Nh.current=Vp,e=_t!==null&&_t.next!==null,Xi=0,kt=_t=pt=null,Gp=!1,e)throw Error(X(300));return t}function B0(){var t=xu!==0;return xu=0,t}function fo(){var t={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return kt===null?pt.memoizedState=kt=t:kt=kt.next=t,kt}function Or(){if(_t===null){var t=pt.alternate;t=t!==null?t.memoizedState:null}else t=_t.next;var e=kt===null?pt.memoizedState:kt.next;if(e!==null)kt=e,_t=t;else{if(t===null)throw Error(X(310));_t=t,t={memoizedState:_t.memoizedState,baseState:_t.baseState,baseQueue:_t.baseQueue,queue:_t.queue,next:null},kt===null?pt.memoizedState=kt=t:kt=kt.next=t}return kt}function wu(t,e){return typeof e=="function"?e(t):e}function Vm(t){var e=Or(),n=e.queue;if(n===null)throw Error(X(311));n.lastRenderedReducer=t;var r=_t,o=r.baseQueue,s=n.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,n.pending=null}if(o!==null){s=o.next,r=r.baseState;var a=i=null,l=null,c=s;do{var u=c.lane;if((Xi&u)===u)l!==null&&(l=l.next={lane:0,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null}),r=c.hasEagerState?c.eagerState:t(r,c.action);else{var h={lane:u,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=h,i=r):l=l.next=h,pt.lanes|=u,qi|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,Qr(r,e.memoizedState)||(Nn=!0),e.memoizedState=r,e.baseState=i,e.baseQueue=l,n.lastRenderedState=r}if(t=n.interleaved,t!==null){o=t;do s=o.lane,pt.lanes|=s,qi|=s,o=o.next;while(o!==t)}else o===null&&(n.lanes=0);return[e.memoizedState,n.dispatch]}function Ym(t){var e=Or(),n=e.queue;if(n===null)throw Error(X(311));n.lastRenderedReducer=t;var r=n.dispatch,o=n.pending,s=e.memoizedState;if(o!==null){n.pending=null;var i=o=o.next;do s=t(s,i.action),i=i.next;while(i!==o);Qr(s,e.memoizedState)||(Nn=!0),e.memoizedState=s,e.baseQueue===null&&(e.baseState=s),n.lastRenderedState=s}return[s,r]}function ik(){}function ak(t,e){var n=pt,r=Or(),o=e(),s=!Qr(r.memoizedState,o);if(s&&(r.memoizedState=o,Nn=!0),r=r.queue,U0(uk.bind(null,n,r,t),[t]),r.getSnapshot!==e||s||kt!==null&&kt.memoizedState.tag&1){if(n.flags|=2048,bu(9,ck.bind(null,n,r,o,e),void 0,null),jt===null)throw Error(X(349));Xi&30||lk(n,e,o)}return o}function lk(t,e,n){t.flags|=16384,t={getSnapshot:e,value:n},e=pt.updateQueue,e===null?(e={lastEffect:null,stores:null},pt.updateQueue=e,e.stores=[t]):(n=e.stores,n===null?e.stores=[t]:n.push(t))}function ck(t,e,n,r){e.value=n,e.getSnapshot=r,dk(e)&&hk(t)}function uk(t,e,n){return n(function(){dk(e)&&hk(t)})}function dk(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!Qr(t,n)}catch{return!0}}function hk(t){var e=ds(t,1);e!==null&&Xr(e,t,1,-1)}function RP(t){var e=fo();return typeof t=="function"&&(t=t()),e.memoizedState=e.baseState=t,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:wu,lastRenderedState:t},e.queue=t,t=t.dispatch=iz.bind(null,pt,t),[e.memoizedState,t]}function bu(t,e,n,r){return t={tag:t,create:e,destroy:n,deps:r,next:null},e=pt.updateQueue,e===null?(e={lastEffect:null,stores:null},pt.updateQueue=e,e.lastEffect=t.next=t):(n=e.lastEffect,n===null?e.lastEffect=t.next=t:(r=n.next,n.next=t,t.next=r,e.lastEffect=t)),t}function pk(){return Or().memoizedState}function zh(t,e,n,r){var o=fo();pt.flags|=t,o.memoizedState=bu(1|e,n,void 0,r===void 0?null:r)}function Jf(t,e,n,r){var o=Or();r=r===void 0?null:r;var s=void 0;if(_t!==null){var i=_t.memoizedState;if(s=i.destroy,r!==null&&N0(r,i.deps)){o.memoizedState=bu(e,n,s,r);return}}pt.flags|=t,o.memoizedState=bu(1|e,n,s,r)}function LP(t,e){return zh(8390656,8,t,e)}function U0(t,e){return Jf(2048,8,t,e)}function fk(t,e){return Jf(4,2,t,e)}function gk(t,e){return Jf(4,4,t,e)}function mk(t,e){if(typeof e=="function")return t=t(),e(t),function(){e(null)};if(e!=null)return t=t(),e.current=t,function(){e.current=null}}function yk(t,e,n){return n=n!=null?n.concat([t]):null,Jf(4,4,mk.bind(null,e,t),n)}function H0(){}function Sk(t,e){var n=Or();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&N0(e,r[1])?r[0]:(n.memoizedState=[t,e],t)}function vk(t,e){var n=Or();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&N0(e,r[1])?r[0]:(t=t(),n.memoizedState=[t,e],t)}function xk(t,e,n){return Xi&21?(Qr(n,e)||(n=_2(),pt.lanes|=n,qi|=n,t.baseState=!0),e):(t.baseState&&(t.baseState=!1,Nn=!0),t.memoizedState=n)}function oz(t,e){var n=ze;ze=n!==0&&4>n?n:4,t(!0);var r=Gm.transition;Gm.transition={};try{t(!1),e()}finally{ze=n,Gm.transition=r}}function wk(){return Or().memoizedState}function sz(t,e,n){var r=Js(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},bk(t))Pk(e,n);else if(n=rk(t,e,n,r),n!==null){var o=xn();Xr(n,t,r,o),Ck(n,e,r)}}function iz(t,e,n){var r=Js(t),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(bk(t))Pk(e,o);else{var s=t.alternate;if(t.lanes===0&&(s===null||s.lanes===0)&&(s=e.lastRenderedReducer,s!==null))try{var i=e.lastRenderedState,a=s(i,n);if(o.hasEagerState=!0,o.eagerState=a,Qr(a,i)){var l=e.interleaved;l===null?(o.next=o,D0(e)):(o.next=l.next,l.next=o),e.interleaved=o;return}}catch{}finally{}n=rk(t,e,o,r),n!==null&&(o=xn(),Xr(n,t,r,o),Ck(n,e,r))}}function bk(t){var e=t.alternate;return t===pt||e!==null&&e===pt}function Pk(t,e){Xc=Gp=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function Ck(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,x0(t,n)}}var Vp={readContext:jr,useCallback:en,useContext:en,useEffect:en,useImperativeHandle:en,useInsertionEffect:en,useLayoutEffect:en,useMemo:en,useReducer:en,useRef:en,useState:en,useDebugValue:en,useDeferredValue:en,useTransition:en,useMutableSource:en,useSyncExternalStore:en,useId:en,unstable_isNewReconciler:!1},az={readContext:jr,useCallback:function(t,e){return fo().memoizedState=[t,e===void 0?null:e],t},useContext:jr,useEffect:LP,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,zh(4194308,4,mk.bind(null,e,t),n)},useLayoutEffect:function(t,e){return zh(4194308,4,t,e)},useInsertionEffect:function(t,e){return zh(4,2,t,e)},useMemo:function(t,e){var n=fo();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=fo();return e=n!==void 0?n(e):e,r.memoizedState=r.baseState=e,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:t,lastRenderedState:e},r.queue=t,t=t.dispatch=sz.bind(null,pt,t),[r.memoizedState,t]},useRef:function(t){var e=fo();return t={current:t},e.memoizedState=t},useState:RP,useDebugValue:H0,useDeferredValue:function(t){return fo().memoizedState=t},useTransition:function(){var t=RP(!1),e=t[0];return t=oz.bind(null,t[1]),fo().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=pt,o=fo();if(it){if(n===void 0)throw Error(X(407));n=n()}else{if(n=e(),jt===null)throw Error(X(349));Xi&30||lk(r,e,n)}o.memoizedState=n;var s={value:n,getSnapshot:e};return o.queue=s,LP(uk.bind(null,r,s,t),[t]),r.flags|=2048,bu(9,ck.bind(null,r,s,n,e),void 0,null),n},useId:function(){var t=fo(),e=jt.identifierPrefix;if(it){var n=Jo,r=Qo;n=(r&~(1<<32-Yr(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=xu++,0<n&&(e+="H"+n.toString(32)),e+=":"}else n=rz++,e=":"+e+"r"+n.toString(32)+":";return t.memoizedState=e},unstable_isNewReconciler:!1},lz={readContext:jr,useCallback:Sk,useContext:jr,useEffect:U0,useImperativeHandle:yk,useInsertionEffect:fk,useLayoutEffect:gk,useMemo:vk,useReducer:Vm,useRef:pk,useState:function(){return Vm(wu)},useDebugValue:H0,useDeferredValue:function(t){var e=Or();return xk(e,_t.memoizedState,t)},useTransition:function(){var t=Vm(wu)[0],e=Or().memoizedState;return[t,e]},useMutableSource:ik,useSyncExternalStore:ak,useId:wk,unstable_isNewReconciler:!1},cz={readContext:jr,useCallback:Sk,useContext:jr,useEffect:U0,useImperativeHandle:yk,useInsertionEffect:fk,useLayoutEffect:gk,useMemo:vk,useReducer:Ym,useRef:pk,useState:function(){return Ym(wu)},useDebugValue:H0,useDeferredValue:function(t){var e=Or();return _t===null?e.memoizedState=t:xk(e,_t.memoizedState,t)},useTransition:function(){var t=Ym(wu)[0],e=Or().memoizedState;return[t,e]},useMutableSource:ik,useSyncExternalStore:ak,useId:wk,unstable_isNewReconciler:!1};function zr(t,e){if(t&&t.defaultProps){e=ft({},e),t=t.defaultProps;for(var n in t)e[n]===void 0&&(e[n]=t[n]);return e}return e}function vv(t,e,n,r){e=t.memoizedState,n=n(r,e),n=n==null?e:ft({},e,n),t.memoizedState=n,t.lanes===0&&(t.updateQueue.baseState=n)}var eg={isMounted:function(t){return(t=t._reactInternals)?ha(t)===t:!1},enqueueSetState:function(t,e,n){t=t._reactInternals;var r=xn(),o=Js(t),s=ns(r,o);s.payload=e,n!=null&&(s.callback=n),e=Zs(t,s,o),e!==null&&(Xr(e,t,o,r),Fh(e,t,o))},enqueueReplaceState:function(t,e,n){t=t._reactInternals;var r=xn(),o=Js(t),s=ns(r,o);s.tag=1,s.payload=e,n!=null&&(s.callback=n),e=Zs(t,s,o),e!==null&&(Xr(e,t,o,r),Fh(e,t,o))},enqueueForceUpdate:function(t,e){t=t._reactInternals;var n=xn(),r=Js(t),o=ns(n,r);o.tag=2,e!=null&&(o.callback=e),e=Zs(t,o,r),e!==null&&(Xr(e,t,r,n),Fh(e,t,r))}};function $P(t,e,n,r,o,s,i){return t=t.stateNode,typeof t.shouldComponentUpdate=="function"?t.shouldComponentUpdate(r,s,i):e.prototype&&e.prototype.isPureReactComponent?!fu(n,r)||!fu(o,s):!0}function _k(t,e,n){var r=!1,o=si,s=e.contextType;return typeof s=="object"&&s!==null?s=jr(s):(o=Kn(e)?Vi:hn.current,r=e.contextTypes,s=(r=r!=null)?Sl(t,o):si),e=new e(n,s),t.memoizedState=e.state!==null&&e.state!==void 0?e.state:null,e.updater=eg,t.stateNode=e,e._reactInternals=t,r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=o,t.__reactInternalMemoizedMaskedChildContext=s),e}function FP(t,e,n,r){t=e.state,typeof e.componentWillReceiveProps=="function"&&e.componentWillReceiveProps(n,r),typeof e.UNSAFE_componentWillReceiveProps=="function"&&e.UNSAFE_componentWillReceiveProps(n,r),e.state!==t&&eg.enqueueReplaceState(e,e.state,null)}function xv(t,e,n,r){var o=t.stateNode;o.props=n,o.state=t.memoizedState,o.refs={},R0(t);var s=e.contextType;typeof s=="object"&&s!==null?o.context=jr(s):(s=Kn(e)?Vi:hn.current,o.context=Sl(t,s)),o.state=t.memoizedState,s=e.getDerivedStateFromProps,typeof s=="function"&&(vv(t,e,s,n),o.state=t.memoizedState),typeof e.getDerivedStateFromProps=="function"||typeof o.getSnapshotBeforeUpdate=="function"||typeof o.UNSAFE_componentWillMount!="function"&&typeof o.componentWillMount!="function"||(e=o.state,typeof o.componentWillMount=="function"&&o.componentWillMount(),typeof o.UNSAFE_componentWillMount=="function"&&o.UNSAFE_componentWillMount(),e!==o.state&&eg.enqueueReplaceState(o,o.state,null),Kp(t,n,o,r),o.state=t.memoizedState),typeof o.componentDidMount=="function"&&(t.flags|=4194308)}function bl(t,e){try{var n="",r=e;do n+=$N(r),r=r.return;while(r);var o=n}catch(s){o=`
39
- Error generating stack: `+s.message+`
40
- `+s.stack}return{value:t,source:e,stack:o,digest:null}}function Xm(t,e,n){return{value:t,source:null,stack:n??null,digest:e??null}}function wv(t,e){try{console.error(e.value)}catch(n){setTimeout(function(){throw n})}}var uz=typeof WeakMap=="function"?WeakMap:Map;function Ik(t,e,n){n=ns(-1,n),n.tag=3,n.payload={element:null};var r=e.value;return n.callback=function(){Xp||(Xp=!0,Av=r),wv(t,e)},n}function Ek(t,e,n){n=ns(-1,n),n.tag=3;var r=t.type.getDerivedStateFromError;if(typeof r=="function"){var o=e.value;n.payload=function(){return r(o)},n.callback=function(){wv(t,e)}}var s=t.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(n.callback=function(){wv(t,e),typeof r!="function"&&(Qs===null?Qs=new Set([this]):Qs.add(this));var i=e.stack;this.componentDidCatch(e.value,{componentStack:i!==null?i:""})}),n}function NP(t,e,n){var r=t.pingCache;if(r===null){r=t.pingCache=new uz;var o=new Set;r.set(e,o)}else o=r.get(e),o===void 0&&(o=new Set,r.set(e,o));o.has(n)||(o.add(n),t=Cz.bind(null,t,e,n),e.then(t,t))}function zP(t){do{var e;if((e=t.tag===13)&&(e=t.memoizedState,e=e!==null?e.dehydrated!==null:!0),e)return t;t=t.return}while(t!==null);return null}function BP(t,e,n,r,o){return t.mode&1?(t.flags|=65536,t.lanes=o,t):(t===e?t.flags|=65536:(t.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(e=ns(-1,1),e.tag=2,Zs(n,e,1))),n.lanes|=1),t)}var dz=Ss.ReactCurrentOwner,Nn=!1;function yn(t,e,n,r){e.child=t===null?nk(e,null,n,r):xl(e,t.child,n,r)}function UP(t,e,n,r,o){n=n.render;var s=e.ref;return ll(e,o),r=z0(t,e,n,r,s,o),n=B0(),t!==null&&!Nn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,hs(t,e,o)):(it&&n&&k0(e),e.flags|=1,yn(t,e,r,o),e.child)}function HP(t,e,n,r,o){if(t===null){var s=n.type;return typeof s=="function"&&!Z0(s)&&s.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(e.tag=15,e.type=s,kk(t,e,s,r,o)):(t=Kh(n.type,null,r,e,e.mode,o),t.ref=e.ref,t.return=e,e.child=t)}if(s=t.child,!(t.lanes&o)){var i=s.memoizedProps;if(n=n.compare,n=n!==null?n:fu,n(i,r)&&t.ref===e.ref)return hs(t,e,o)}return e.flags|=1,t=ei(s,r),t.ref=e.ref,t.return=e,e.child=t}function kk(t,e,n,r,o){if(t!==null){var s=t.memoizedProps;if(fu(s,r)&&t.ref===e.ref)if(Nn=!1,e.pendingProps=r=s,(t.lanes&o)!==0)t.flags&131072&&(Nn=!0);else return e.lanes=t.lanes,hs(t,e,o)}return bv(t,e,n,r,o)}function Tk(t,e,n){var r=e.pendingProps,o=r.children,s=t!==null?t.memoizedState:null;if(r.mode==="hidden")if(!(e.mode&1))e.memoizedState={baseLanes:0,cachePool:null,transitions:null},Xe(Va,tr),tr|=n;else{if(!(n&1073741824))return t=s!==null?s.baseLanes|n:n,e.lanes=e.childLanes=1073741824,e.memoizedState={baseLanes:t,cachePool:null,transitions:null},e.updateQueue=null,Xe(Va,tr),tr|=t,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:n,Xe(Va,tr),tr|=r}else s!==null?(r=s.baseLanes|n,e.memoizedState=null):r=n,Xe(Va,tr),tr|=r;return yn(t,e,o,n),e.child}function Mk(t,e){var n=e.ref;(t===null&&n!==null||t!==null&&t.ref!==n)&&(e.flags|=512,e.flags|=2097152)}function bv(t,e,n,r,o){var s=Kn(n)?Vi:hn.current;return s=Sl(e,s),ll(e,o),n=z0(t,e,n,r,s,o),r=B0(),t!==null&&!Nn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,hs(t,e,o)):(it&&r&&k0(e),e.flags|=1,yn(t,e,n,o),e.child)}function KP(t,e,n,r,o){if(Kn(n)){var s=!0;Np(e)}else s=!1;if(ll(e,o),e.stateNode===null)Bh(t,e),_k(e,n,r),xv(e,n,r,o),r=!0;else if(t===null){var i=e.stateNode,a=e.memoizedProps;i.props=a;var l=i.context,c=n.contextType;typeof c=="object"&&c!==null?c=jr(c):(c=Kn(n)?Vi:hn.current,c=Sl(e,c));var u=n.getDerivedStateFromProps,h=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";h||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||l!==c)&&FP(e,i,r,c),Ls=!1;var p=e.memoizedState;i.state=p,Kp(e,r,i,o),l=e.memoizedState,a!==r||p!==l||Hn.current||Ls?(typeof u=="function"&&(vv(e,n,u,r),l=e.memoizedState),(a=Ls||$P(e,n,a,r,p,l,c))?(h||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(e.flags|=4194308)):(typeof i.componentDidMount=="function"&&(e.flags|=4194308),e.memoizedProps=r,e.memoizedState=l),i.props=r,i.state=l,i.context=c,r=a):(typeof i.componentDidMount=="function"&&(e.flags|=4194308),r=!1)}else{i=e.stateNode,ok(t,e),a=e.memoizedProps,c=e.type===e.elementType?a:zr(e.type,a),i.props=c,h=e.pendingProps,p=i.context,l=n.contextType,typeof l=="object"&&l!==null?l=jr(l):(l=Kn(n)?Vi:hn.current,l=Sl(e,l));var f=n.getDerivedStateFromProps;(u=typeof f=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==h||p!==l)&&FP(e,i,r,l),Ls=!1,p=e.memoizedState,i.state=p,Kp(e,r,i,o);var g=e.memoizedState;a!==h||p!==g||Hn.current||Ls?(typeof f=="function"&&(vv(e,n,f,r),g=e.memoizedState),(c=Ls||$P(e,n,c,r,p,g,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,g,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,g,l)),typeof i.componentDidUpdate=="function"&&(e.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(e.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===t.memoizedProps&&p===t.memoizedState||(e.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===t.memoizedProps&&p===t.memoizedState||(e.flags|=1024),e.memoizedProps=r,e.memoizedState=g),i.props=r,i.state=g,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===t.memoizedProps&&p===t.memoizedState||(e.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===t.memoizedProps&&p===t.memoizedState||(e.flags|=1024),r=!1)}return Pv(t,e,n,r,s,o)}function Pv(t,e,n,r,o,s){Mk(t,e);var i=(e.flags&128)!==0;if(!r&&!i)return o&&TP(e,n,!1),hs(t,e,s);r=e.stateNode,dz.current=e;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,t!==null&&i?(e.child=xl(e,t.child,null,s),e.child=xl(e,null,a,s)):yn(t,e,a,s),e.memoizedState=r.state,o&&TP(e,n,!0),e.child}function Ak(t){var e=t.stateNode;e.pendingContext?kP(t,e.pendingContext,e.pendingContext!==e.context):e.context&&kP(t,e.context,!1),L0(t,e.containerInfo)}function WP(t,e,n,r,o){return vl(),M0(o),e.flags|=256,yn(t,e,n,r),e.child}var Cv={dehydrated:null,treeContext:null,retryLane:0};function _v(t){return{baseLanes:t,cachePool:null,transitions:null}}function jk(t,e,n){var r=e.pendingProps,o=ut.current,s=!1,i=(e.flags&128)!==0,a;if((a=i)||(a=t!==null&&t.memoizedState===null?!1:(o&2)!==0),a?(s=!0,e.flags&=-129):(t===null||t.memoizedState!==null)&&(o|=1),Xe(ut,o&1),t===null)return yv(e),t=e.memoizedState,t!==null&&(t=t.dehydrated,t!==null)?(e.mode&1?t.data==="$!"?e.lanes=8:e.lanes=1073741824:e.lanes=1,null):(i=r.children,t=r.fallback,s?(r=e.mode,s=e.child,i={mode:"hidden",children:i},!(r&1)&&s!==null?(s.childLanes=0,s.pendingProps=i):s=rg(i,r,0,null),t=Hi(t,r,n,null),s.return=e,t.return=e,s.sibling=t,e.child=s,e.child.memoizedState=_v(n),e.memoizedState=Cv,t):K0(e,i));if(o=t.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return hz(t,e,i,r,a,o,n);if(s){s=r.fallback,i=e.mode,o=t.child,a=o.sibling;var l={mode:"hidden",children:r.children};return!(i&1)&&e.child!==o?(r=e.child,r.childLanes=0,r.pendingProps=l,e.deletions=null):(r=ei(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=ei(a,s):(s=Hi(s,i,n,null),s.flags|=2),s.return=e,r.return=e,r.sibling=s,e.child=r,r=s,s=e.child,i=t.child.memoizedState,i=i===null?_v(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=t.childLanes&~n,e.memoizedState=Cv,r}return s=t.child,t=s.sibling,r=ei(s,{mode:"visible",children:r.children}),!(e.mode&1)&&(r.lanes=n),r.return=e,r.sibling=null,t!==null&&(n=e.deletions,n===null?(e.deletions=[t],e.flags|=16):n.push(t)),e.child=r,e.memoizedState=null,r}function K0(t,e){return e=rg({mode:"visible",children:e},t.mode,0,null),e.return=t,t.child=e}function Ud(t,e,n,r){return r!==null&&M0(r),xl(e,t.child,null,n),t=K0(e,e.pendingProps.children),t.flags|=2,e.memoizedState=null,t}function hz(t,e,n,r,o,s,i){if(n)return e.flags&256?(e.flags&=-257,r=Xm(Error(X(422))),Ud(t,e,i,r)):e.memoizedState!==null?(e.child=t.child,e.flags|=128,null):(s=r.fallback,o=e.mode,r=rg({mode:"visible",children:r.children},o,0,null),s=Hi(s,o,i,null),s.flags|=2,r.return=e,s.return=e,r.sibling=s,e.child=r,e.mode&1&&xl(e,t.child,null,i),e.child.memoizedState=_v(i),e.memoizedState=Cv,s);if(!(e.mode&1))return Ud(t,e,i,null);if(o.data==="$!"){if(r=o.nextSibling&&o.nextSibling.dataset,r)var a=r.dgst;return r=a,s=Error(X(419)),r=Xm(s,r,void 0),Ud(t,e,i,r)}if(a=(i&t.childLanes)!==0,Nn||a){if(r=jt,r!==null){switch(i&-i){case 4:o=2;break;case 16:o=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:o=32;break;case 536870912:o=268435456;break;default:o=0}o=o&(r.suspendedLanes|i)?0:o,o!==0&&o!==s.retryLane&&(s.retryLane=o,ds(t,o),Xr(r,t,o,-1))}return q0(),r=Xm(Error(X(421))),Ud(t,e,i,r)}return o.data==="$?"?(e.flags|=128,e.child=t.child,e=_z.bind(null,t),o._reactRetry=e,null):(t=s.treeContext,or=qs(o.nextSibling),ir=e,it=!0,Hr=null,t!==null&&(_r[Ir++]=Qo,_r[Ir++]=Jo,_r[Ir++]=Yi,Qo=t.id,Jo=t.overflow,Yi=e),e=K0(e,r.children),e.flags|=4096,e)}function GP(t,e,n){t.lanes|=e;var r=t.alternate;r!==null&&(r.lanes|=e),Sv(t.return,e,n)}function qm(t,e,n,r,o){var s=t.memoizedState;s===null?t.memoizedState={isBackwards:e,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:o}:(s.isBackwards=e,s.rendering=null,s.renderingStartTime=0,s.last=r,s.tail=n,s.tailMode=o)}function Ok(t,e,n){var r=e.pendingProps,o=r.revealOrder,s=r.tail;if(yn(t,e,r.children,n),r=ut.current,r&2)r=r&1|2,e.flags|=128;else{if(t!==null&&t.flags&128)e:for(t=e.child;t!==null;){if(t.tag===13)t.memoizedState!==null&&GP(t,n,e);else if(t.tag===19)GP(t,n,e);else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break e;for(;t.sibling===null;){if(t.return===null||t.return===e)break e;t=t.return}t.sibling.return=t.return,t=t.sibling}r&=1}if(Xe(ut,r),!(e.mode&1))e.memoizedState=null;else switch(o){case"forwards":for(n=e.child,o=null;n!==null;)t=n.alternate,t!==null&&Wp(t)===null&&(o=n),n=n.sibling;n=o,n===null?(o=e.child,e.child=null):(o=n.sibling,n.sibling=null),qm(e,!1,o,n,s);break;case"backwards":for(n=null,o=e.child,e.child=null;o!==null;){if(t=o.alternate,t!==null&&Wp(t)===null){e.child=o;break}t=o.sibling,o.sibling=n,n=o,o=t}qm(e,!0,n,null,s);break;case"together":qm(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function Bh(t,e){!(e.mode&1)&&t!==null&&(t.alternate=null,e.alternate=null,e.flags|=2)}function hs(t,e,n){if(t!==null&&(e.dependencies=t.dependencies),qi|=e.lanes,!(n&e.childLanes))return null;if(t!==null&&e.child!==t.child)throw Error(X(153));if(e.child!==null){for(t=e.child,n=ei(t,t.pendingProps),e.child=n,n.return=e;t.sibling!==null;)t=t.sibling,n=n.sibling=ei(t,t.pendingProps),n.return=e;n.sibling=null}return e.child}function pz(t,e,n){switch(e.tag){case 3:Ak(e),vl();break;case 5:sk(e);break;case 1:Kn(e.type)&&Np(e);break;case 4:L0(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,o=e.memoizedProps.value;Xe(Up,r._currentValue),r._currentValue=o;break;case 13:if(r=e.memoizedState,r!==null)return r.dehydrated!==null?(Xe(ut,ut.current&1),e.flags|=128,null):n&e.child.childLanes?jk(t,e,n):(Xe(ut,ut.current&1),t=hs(t,e,n),t!==null?t.sibling:null);Xe(ut,ut.current&1);break;case 19:if(r=(n&e.childLanes)!==0,t.flags&128){if(r)return Ok(t,e,n);e.flags|=128}if(o=e.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Xe(ut,ut.current),r)break;return null;case 22:case 23:return e.lanes=0,Tk(t,e,n)}return hs(t,e,n)}var Dk,Iv,Rk,Lk;Dk=function(t,e){for(var n=e.child;n!==null;){if(n.tag===5||n.tag===6)t.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};Iv=function(){};Rk=function(t,e,n,r){var o=t.memoizedProps;if(o!==r){t=e.stateNode,zi(Co.current);var s=null;switch(n){case"input":o=YS(t,o),r=YS(t,r),s=[];break;case"select":o=ft({},o,{value:void 0}),r=ft({},r,{value:void 0}),s=[];break;case"textarea":o=ZS(t,o),r=ZS(t,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(t.onclick=$p)}JS(n,r);var i;n=null;for(c in o)if(!r.hasOwnProperty(c)&&o.hasOwnProperty(c)&&o[c]!=null)if(c==="style"){var a=o[c];for(i in a)a.hasOwnProperty(i)&&(n||(n={}),n[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(au.hasOwnProperty(c)?s||(s=[]):(s=s||[]).push(c,null));for(c in r){var l=r[c];if(a=o!=null?o[c]:void 0,r.hasOwnProperty(c)&&l!==a&&(l!=null||a!=null))if(c==="style")if(a){for(i in a)!a.hasOwnProperty(i)||l&&l.hasOwnProperty(i)||(n||(n={}),n[i]="");for(i in l)l.hasOwnProperty(i)&&a[i]!==l[i]&&(n||(n={}),n[i]=l[i])}else n||(s||(s=[]),s.push(c,n)),n=l;else c==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,a=a?a.__html:void 0,l!=null&&a!==l&&(s=s||[]).push(c,l)):c==="children"?typeof l!="string"&&typeof l!="number"||(s=s||[]).push(c,""+l):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(au.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&et("scroll",t),s||a===l||(s=[])):(s=s||[]).push(c,l))}n&&(s=s||[]).push("style",n);var c=s;(e.updateQueue=c)&&(e.flags|=4)}};Lk=function(t,e,n,r){n!==r&&(e.flags|=4)};function cc(t,e){if(!it)switch(t.tailMode){case"hidden":e=t.tail;for(var n=null;e!==null;)e.alternate!==null&&(n=e),e=e.sibling;n===null?t.tail=null:n.sibling=null;break;case"collapsed":n=t.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?e||t.tail===null?t.tail=null:t.tail.sibling=null:r.sibling=null}}function tn(t){var e=t.alternate!==null&&t.alternate.child===t.child,n=0,r=0;if(e)for(var o=t.child;o!==null;)n|=o.lanes|o.childLanes,r|=o.subtreeFlags&14680064,r|=o.flags&14680064,o.return=t,o=o.sibling;else for(o=t.child;o!==null;)n|=o.lanes|o.childLanes,r|=o.subtreeFlags,r|=o.flags,o.return=t,o=o.sibling;return t.subtreeFlags|=r,t.childLanes=n,e}function fz(t,e,n){var r=e.pendingProps;switch(T0(e),e.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return tn(e),null;case 1:return Kn(e.type)&&Fp(),tn(e),null;case 3:return r=e.stateNode,wl(),nt(Hn),nt(hn),F0(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(t===null||t.child===null)&&(zd(e)?e.flags|=4:t===null||t.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,Hr!==null&&(Dv(Hr),Hr=null))),Iv(t,e),tn(e),null;case 5:$0(e);var o=zi(vu.current);if(n=e.type,t!==null&&e.stateNode!=null)Rk(t,e,n,r,o),t.ref!==e.ref&&(e.flags|=512,e.flags|=2097152);else{if(!r){if(e.stateNode===null)throw Error(X(166));return tn(e),null}if(t=zi(Co.current),zd(e)){r=e.stateNode,n=e.type;var s=e.memoizedProps;switch(r[mo]=e,r[yu]=s,t=(e.mode&1)!==0,n){case"dialog":et("cancel",r),et("close",r);break;case"iframe":case"object":case"embed":et("load",r);break;case"video":case"audio":for(o=0;o<Oc.length;o++)et(Oc[o],r);break;case"source":et("error",r);break;case"img":case"image":case"link":et("error",r),et("load",r);break;case"details":et("toggle",r);break;case"input":tP(r,s),et("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},et("invalid",r);break;case"textarea":rP(r,s),et("invalid",r)}JS(n,s),o=null;for(var i in s)if(s.hasOwnProperty(i)){var a=s[i];i==="children"?typeof a=="string"?r.textContent!==a&&(s.suppressHydrationWarning!==!0&&Nd(r.textContent,a,t),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Nd(r.textContent,a,t),o=["children",""+a]):au.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&et("scroll",r)}switch(n){case"input":Ad(r),nP(r,s,!0);break;case"textarea":Ad(r),oP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=$p)}r=o,e.updateQueue=r,r!==null&&(e.flags|=4)}else{i=o.nodeType===9?o:o.ownerDocument,t==="http://www.w3.org/1999/xhtml"&&(t=u2(n)),t==="http://www.w3.org/1999/xhtml"?n==="script"?(t=i.createElement("div"),t.innerHTML="<script><\/script>",t=t.removeChild(t.firstChild)):typeof r.is=="string"?t=i.createElement(n,{is:r.is}):(t=i.createElement(n),n==="select"&&(i=t,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):t=i.createElementNS(t,n),t[mo]=e,t[yu]=r,Dk(t,e,!1,!1),e.stateNode=t;e:{switch(i=ev(n,r),n){case"dialog":et("cancel",t),et("close",t),o=r;break;case"iframe":case"object":case"embed":et("load",t),o=r;break;case"video":case"audio":for(o=0;o<Oc.length;o++)et(Oc[o],t);o=r;break;case"source":et("error",t),o=r;break;case"img":case"image":case"link":et("error",t),et("load",t),o=r;break;case"details":et("toggle",t),o=r;break;case"input":tP(t,r),o=YS(t,r),et("invalid",t);break;case"option":o=r;break;case"select":t._wrapperState={wasMultiple:!!r.multiple},o=ft({},r,{value:void 0}),et("invalid",t);break;case"textarea":rP(t,r),o=ZS(t,r),et("invalid",t);break;default:o=r}JS(n,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?p2(t,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&d2(t,l)):s==="children"?typeof l=="string"?(n!=="textarea"||l!=="")&&lu(t,l):typeof l=="number"&&lu(t,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(au.hasOwnProperty(s)?l!=null&&s==="onScroll"&&et("scroll",t):l!=null&&f0(t,s,l,i))}switch(n){case"input":Ad(t),nP(t,r,!1);break;case"textarea":Ad(t),oP(t);break;case"option":r.value!=null&&t.setAttribute("value",""+oi(r.value));break;case"select":t.multiple=!!r.multiple,s=r.value,s!=null?ol(t,!!r.multiple,s,!1):r.defaultValue!=null&&ol(t,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(t.onclick=$p)}switch(n){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(e.flags|=4)}e.ref!==null&&(e.flags|=512,e.flags|=2097152)}return tn(e),null;case 6:if(t&&e.stateNode!=null)Lk(t,e,t.memoizedProps,r);else{if(typeof r!="string"&&e.stateNode===null)throw Error(X(166));if(n=zi(vu.current),zi(Co.current),zd(e)){if(r=e.stateNode,n=e.memoizedProps,r[mo]=e,(s=r.nodeValue!==n)&&(t=ir,t!==null))switch(t.tag){case 3:Nd(r.nodeValue,n,(t.mode&1)!==0);break;case 5:t.memoizedProps.suppressHydrationWarning!==!0&&Nd(r.nodeValue,n,(t.mode&1)!==0)}s&&(e.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[mo]=e,e.stateNode=r}return tn(e),null;case 13:if(nt(ut),r=e.memoizedState,t===null||t.memoizedState!==null&&t.memoizedState.dehydrated!==null){if(it&&or!==null&&e.mode&1&&!(e.flags&128))ek(),vl(),e.flags|=98560,s=!1;else if(s=zd(e),r!==null&&r.dehydrated!==null){if(t===null){if(!s)throw Error(X(318));if(s=e.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(X(317));s[mo]=e}else vl(),!(e.flags&128)&&(e.memoizedState=null),e.flags|=4;tn(e),s=!1}else Hr!==null&&(Dv(Hr),Hr=null),s=!0;if(!s)return e.flags&65536?e:null}return e.flags&128?(e.lanes=n,e):(r=r!==null,r!==(t!==null&&t.memoizedState!==null)&&r&&(e.child.flags|=8192,e.mode&1&&(t===null||ut.current&1?It===0&&(It=3):q0())),e.updateQueue!==null&&(e.flags|=4),tn(e),null);case 4:return wl(),Iv(t,e),t===null&&gu(e.stateNode.containerInfo),tn(e),null;case 10:return O0(e.type._context),tn(e),null;case 17:return Kn(e.type)&&Fp(),tn(e),null;case 19:if(nt(ut),s=e.memoizedState,s===null)return tn(e),null;if(r=(e.flags&128)!==0,i=s.rendering,i===null)if(r)cc(s,!1);else{if(It!==0||t!==null&&t.flags&128)for(t=e.child;t!==null;){if(i=Wp(t),i!==null){for(e.flags|=128,cc(s,!1),r=i.updateQueue,r!==null&&(e.updateQueue=r,e.flags|=4),e.subtreeFlags=0,r=n,n=e.child;n!==null;)s=n,t=r,s.flags&=14680066,i=s.alternate,i===null?(s.childLanes=0,s.lanes=t,s.child=null,s.subtreeFlags=0,s.memoizedProps=null,s.memoizedState=null,s.updateQueue=null,s.dependencies=null,s.stateNode=null):(s.childLanes=i.childLanes,s.lanes=i.lanes,s.child=i.child,s.subtreeFlags=0,s.deletions=null,s.memoizedProps=i.memoizedProps,s.memoizedState=i.memoizedState,s.updateQueue=i.updateQueue,s.type=i.type,t=i.dependencies,s.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext}),n=n.sibling;return Xe(ut,ut.current&1|2),e.child}t=t.sibling}s.tail!==null&&vt()>Pl&&(e.flags|=128,r=!0,cc(s,!1),e.lanes=4194304)}else{if(!r)if(t=Wp(i),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),cc(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!it)return tn(e),null}else 2*vt()-s.renderingStartTime>Pl&&n!==1073741824&&(e.flags|=128,r=!0,cc(s,!1),e.lanes=4194304);s.isBackwards?(i.sibling=e.child,e.child=i):(n=s.last,n!==null?n.sibling=i:e.child=i,s.last=i)}return s.tail!==null?(e=s.tail,s.rendering=e,s.tail=e.sibling,s.renderingStartTime=vt(),e.sibling=null,n=ut.current,Xe(ut,r?n&1|2:n&1),e):(tn(e),null);case 22:case 23:return X0(),r=e.memoizedState!==null,t!==null&&t.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?tr&1073741824&&(tn(e),e.subtreeFlags&6&&(e.flags|=8192)):tn(e),null;case 24:return null;case 25:return null}throw Error(X(156,e.tag))}function gz(t,e){switch(T0(e),e.tag){case 1:return Kn(e.type)&&Fp(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return wl(),nt(Hn),nt(hn),F0(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return $0(e),null;case 13:if(nt(ut),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(X(340));vl()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return nt(ut),null;case 4:return wl(),null;case 10:return O0(e.type._context),null;case 22:case 23:return X0(),null;case 24:return null;default:return null}}var Hd=!1,an=!1,mz=typeof WeakSet=="function"?WeakSet:Set,re=null;function Ga(t,e){var n=t.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){mt(t,e,r)}else n.current=null}function Ev(t,e,n){try{n()}catch(r){mt(t,e,r)}}var VP=!1;function yz(t,e){if(uv=Dp,t=B2(),E0(t)){if("selectionStart"in t)var n={start:t.selectionStart,end:t.selectionEnd};else e:{n=(n=t.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var o=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{n.nodeType,s.nodeType}catch{n=null;break e}var i=0,a=-1,l=-1,c=0,u=0,h=t,p=null;t:for(;;){for(var f;h!==n||o!==0&&h.nodeType!==3||(a=i+o),h!==s||r!==0&&h.nodeType!==3||(l=i+r),h.nodeType===3&&(i+=h.nodeValue.length),(f=h.firstChild)!==null;)p=h,h=f;for(;;){if(h===t)break t;if(p===n&&++c===o&&(a=i),p===s&&++u===r&&(l=i),(f=h.nextSibling)!==null)break;h=p,p=h.parentNode}h=f}n=a===-1||l===-1?null:{start:a,end:l}}else n=null}n=n||{start:0,end:0}}else n=null;for(dv={focusedElem:t,selectionRange:n},Dp=!1,re=e;re!==null;)if(e=re,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,re=t;else for(;re!==null;){e=re;try{var g=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var m=g.memoizedProps,v=g.memoizedState,S=e.stateNode,y=S.getSnapshotBeforeUpdate(e.elementType===e.type?m:zr(e.type,m),v);S.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var b=e.stateNode.containerInfo;b.nodeType===1?b.textContent="":b.nodeType===9&&b.documentElement&&b.removeChild(b.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(X(163))}}catch(P){mt(e,e.return,P)}if(t=e.sibling,t!==null){t.return=e.return,re=t;break}re=e.return}return g=VP,VP=!1,g}function qc(t,e,n){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var o=r=r.next;do{if((o.tag&t)===t){var s=o.destroy;o.destroy=void 0,s!==void 0&&Ev(e,n,s)}o=o.next}while(o!==r)}}function tg(t,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var n=e=e.next;do{if((n.tag&t)===t){var r=n.create;n.destroy=r()}n=n.next}while(n!==e)}}function kv(t){var e=t.ref;if(e!==null){var n=t.stateNode;switch(t.tag){case 5:t=n;break;default:t=n}typeof e=="function"?e(t):e.current=t}}function $k(t){var e=t.alternate;e!==null&&(t.alternate=null,$k(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[mo],delete e[yu],delete e[fv],delete e[J6],delete e[ez])),t.stateNode=null,t.return=null,t.dependencies=null,t.memoizedProps=null,t.memoizedState=null,t.pendingProps=null,t.stateNode=null,t.updateQueue=null}function Fk(t){return t.tag===5||t.tag===3||t.tag===4}function YP(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||Fk(t.return))return null;t=t.return}for(t.sibling.return=t.return,t=t.sibling;t.tag!==5&&t.tag!==6&&t.tag!==18;){if(t.flags&2||t.child===null||t.tag===4)continue e;t.child.return=t,t=t.child}if(!(t.flags&2))return t.stateNode}}function Tv(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.nodeType===8?n.parentNode.insertBefore(t,e):n.insertBefore(t,e):(n.nodeType===8?(e=n.parentNode,e.insertBefore(t,n)):(e=n,e.appendChild(t)),n=n._reactRootContainer,n!=null||e.onclick!==null||(e.onclick=$p));else if(r!==4&&(t=t.child,t!==null))for(Tv(t,e,n),t=t.sibling;t!==null;)Tv(t,e,n),t=t.sibling}function Mv(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.insertBefore(t,e):n.appendChild(t);else if(r!==4&&(t=t.child,t!==null))for(Mv(t,e,n),t=t.sibling;t!==null;)Mv(t,e,n),t=t.sibling}var Nt=null,Br=!1;function Ts(t,e,n){for(n=n.child;n!==null;)Nk(t,e,n),n=n.sibling}function Nk(t,e,n){if(Po&&typeof Po.onCommitFiberUnmount=="function")try{Po.onCommitFiberUnmount(Vf,n)}catch{}switch(n.tag){case 5:an||Ga(n,e);case 6:var r=Nt,o=Br;Nt=null,Ts(t,e,n),Nt=r,Br=o,Nt!==null&&(Br?(t=Nt,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):Nt.removeChild(n.stateNode));break;case 18:Nt!==null&&(Br?(t=Nt,n=n.stateNode,t.nodeType===8?Hm(t.parentNode,n):t.nodeType===1&&Hm(t,n),hu(t)):Hm(Nt,n.stateNode));break;case 4:r=Nt,o=Br,Nt=n.stateNode.containerInfo,Br=!0,Ts(t,e,n),Nt=r,Br=o;break;case 0:case 11:case 14:case 15:if(!an&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){o=r=r.next;do{var s=o,i=s.destroy;s=s.tag,i!==void 0&&(s&2||s&4)&&Ev(n,e,i),o=o.next}while(o!==r)}Ts(t,e,n);break;case 1:if(!an&&(Ga(n,e),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){mt(n,e,a)}Ts(t,e,n);break;case 21:Ts(t,e,n);break;case 22:n.mode&1?(an=(r=an)||n.memoizedState!==null,Ts(t,e,n),an=r):Ts(t,e,n);break;default:Ts(t,e,n)}}function XP(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new mz),e.forEach(function(r){var o=Iz.bind(null,t,r);n.has(r)||(n.add(r),r.then(o,o))})}}function Nr(t,e){var n=e.deletions;if(n!==null)for(var r=0;r<n.length;r++){var o=n[r];try{var s=t,i=e,a=i;e:for(;a!==null;){switch(a.tag){case 5:Nt=a.stateNode,Br=!1;break e;case 3:Nt=a.stateNode.containerInfo,Br=!0;break e;case 4:Nt=a.stateNode.containerInfo,Br=!0;break e}a=a.return}if(Nt===null)throw Error(X(160));Nk(s,i,o),Nt=null,Br=!1;var l=o.alternate;l!==null&&(l.return=null),o.return=null}catch(c){mt(o,e,c)}}if(e.subtreeFlags&12854)for(e=e.child;e!==null;)zk(e,t),e=e.sibling}function zk(t,e){var n=t.alternate,r=t.flags;switch(t.tag){case 0:case 11:case 14:case 15:if(Nr(e,t),uo(t),r&4){try{qc(3,t,t.return),tg(3,t)}catch(m){mt(t,t.return,m)}try{qc(5,t,t.return)}catch(m){mt(t,t.return,m)}}break;case 1:Nr(e,t),uo(t),r&512&&n!==null&&Ga(n,n.return);break;case 5:if(Nr(e,t),uo(t),r&512&&n!==null&&Ga(n,n.return),t.flags&32){var o=t.stateNode;try{lu(o,"")}catch(m){mt(t,t.return,m)}}if(r&4&&(o=t.stateNode,o!=null)){var s=t.memoizedProps,i=n!==null?n.memoizedProps:s,a=t.type,l=t.updateQueue;if(t.updateQueue=null,l!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&l2(o,s),ev(a,i);var c=ev(a,s);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?p2(o,h):u==="dangerouslySetInnerHTML"?d2(o,h):u==="children"?lu(o,h):f0(o,u,h,c)}switch(a){case"input":XS(o,s);break;case"textarea":c2(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?ol(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?ol(o,!!s.multiple,s.defaultValue,!0):ol(o,!!s.multiple,s.multiple?[]:"",!1))}o[yu]=s}catch(m){mt(t,t.return,m)}}break;case 6:if(Nr(e,t),uo(t),r&4){if(t.stateNode===null)throw Error(X(162));o=t.stateNode,s=t.memoizedProps;try{o.nodeValue=s}catch(m){mt(t,t.return,m)}}break;case 3:if(Nr(e,t),uo(t),r&4&&n!==null&&n.memoizedState.isDehydrated)try{hu(e.containerInfo)}catch(m){mt(t,t.return,m)}break;case 4:Nr(e,t),uo(t);break;case 13:Nr(e,t),uo(t),o=t.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(V0=vt())),r&4&&XP(t);break;case 22:if(u=n!==null&&n.memoizedState!==null,t.mode&1?(an=(c=an)||u,Nr(e,t),an=c):Nr(e,t),uo(t),r&8192){if(c=t.memoizedState!==null,(t.stateNode.isHidden=c)&&!u&&t.mode&1)for(re=t,u=t.child;u!==null;){for(h=re=u;re!==null;){switch(p=re,f=p.child,p.tag){case 0:case 11:case 14:case 15:qc(4,p,p.return);break;case 1:Ga(p,p.return);var g=p.stateNode;if(typeof g.componentWillUnmount=="function"){r=p,n=p.return;try{e=r,g.props=e.memoizedProps,g.state=e.memoizedState,g.componentWillUnmount()}catch(m){mt(r,n,m)}}break;case 5:Ga(p,p.return);break;case 22:if(p.memoizedState!==null){ZP(h);continue}}f!==null?(f.return=p,re=f):ZP(h)}u=u.sibling}e:for(u=null,h=t;;){if(h.tag===5){if(u===null){u=h;try{o=h.stateNode,c?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=h.stateNode,l=h.memoizedProps.style,i=l!=null&&l.hasOwnProperty("display")?l.display:null,a.style.display=h2("display",i))}catch(m){mt(t,t.return,m)}}}else if(h.tag===6){if(u===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(m){mt(t,t.return,m)}}else if((h.tag!==22&&h.tag!==23||h.memoizedState===null||h===t)&&h.child!==null){h.child.return=h,h=h.child;continue}if(h===t)break e;for(;h.sibling===null;){if(h.return===null||h.return===t)break e;u===h&&(u=null),h=h.return}u===h&&(u=null),h.sibling.return=h.return,h=h.sibling}}break;case 19:Nr(e,t),uo(t),r&4&&XP(t);break;case 21:break;default:Nr(e,t),uo(t)}}function uo(t){var e=t.flags;if(e&2){try{e:{for(var n=t.return;n!==null;){if(Fk(n)){var r=n;break e}n=n.return}throw Error(X(160))}switch(r.tag){case 5:var o=r.stateNode;r.flags&32&&(lu(o,""),r.flags&=-33);var s=YP(t);Mv(t,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=YP(t);Tv(t,a,i);break;default:throw Error(X(161))}}catch(l){mt(t,t.return,l)}t.flags&=-3}e&4096&&(t.flags&=-4097)}function Sz(t,e,n){re=t,Bk(t)}function Bk(t,e,n){for(var r=(t.mode&1)!==0;re!==null;){var o=re,s=o.child;if(o.tag===22&&r){var i=o.memoizedState!==null||Hd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||an;a=Hd;var c=an;if(Hd=i,(an=l)&&!c)for(re=o;re!==null;)i=re,l=i.child,i.tag===22&&i.memoizedState!==null?QP(o):l!==null?(l.return=i,re=l):QP(o);for(;s!==null;)re=s,Bk(s),s=s.sibling;re=o,Hd=a,an=c}qP(t)}else o.subtreeFlags&8772&&s!==null?(s.return=o,re=s):qP(t)}}function qP(t){for(;re!==null;){var e=re;if(e.flags&8772){var n=e.alternate;try{if(e.flags&8772)switch(e.tag){case 0:case 11:case 15:an||tg(5,e);break;case 1:var r=e.stateNode;if(e.flags&4&&!an)if(n===null)r.componentDidMount();else{var o=e.elementType===e.type?n.memoizedProps:zr(e.type,n.memoizedProps);r.componentDidUpdate(o,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=e.updateQueue;s!==null&&DP(e,s,r);break;case 3:var i=e.updateQueue;if(i!==null){if(n=null,e.child!==null)switch(e.child.tag){case 5:n=e.child.stateNode;break;case 1:n=e.child.stateNode}DP(e,i,n)}break;case 5:var a=e.stateNode;if(n===null&&e.flags&4){n=a;var l=e.memoizedProps;switch(e.type){case"button":case"input":case"select":case"textarea":l.autoFocus&&n.focus();break;case"img":l.src&&(n.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(e.memoizedState===null){var c=e.alternate;if(c!==null){var u=c.memoizedState;if(u!==null){var h=u.dehydrated;h!==null&&hu(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(X(163))}an||e.flags&512&&kv(e)}catch(p){mt(e,e.return,p)}}if(e===t){re=null;break}if(n=e.sibling,n!==null){n.return=e.return,re=n;break}re=e.return}}function ZP(t){for(;re!==null;){var e=re;if(e===t){re=null;break}var n=e.sibling;if(n!==null){n.return=e.return,re=n;break}re=e.return}}function QP(t){for(;re!==null;){var e=re;try{switch(e.tag){case 0:case 11:case 15:var n=e.return;try{tg(4,e)}catch(l){mt(e,n,l)}break;case 1:var r=e.stateNode;if(typeof r.componentDidMount=="function"){var o=e.return;try{r.componentDidMount()}catch(l){mt(e,o,l)}}var s=e.return;try{kv(e)}catch(l){mt(e,s,l)}break;case 5:var i=e.return;try{kv(e)}catch(l){mt(e,i,l)}}}catch(l){mt(e,e.return,l)}if(e===t){re=null;break}var a=e.sibling;if(a!==null){a.return=e.return,re=a;break}re=e.return}}var vz=Math.ceil,Yp=Ss.ReactCurrentDispatcher,W0=Ss.ReactCurrentOwner,Mr=Ss.ReactCurrentBatchConfig,Oe=0,jt=null,Ct=null,Vt=0,tr=0,Va=mi(0),It=0,Pu=null,qi=0,ng=0,G0=0,Zc=null,Ln=null,V0=0,Pl=1/0,Yo=null,Xp=!1,Av=null,Qs=null,Kd=!1,Hs=null,qp=0,Qc=0,jv=null,Uh=-1,Hh=0;function xn(){return Oe&6?vt():Uh!==-1?Uh:Uh=vt()}function Js(t){return t.mode&1?Oe&2&&Vt!==0?Vt&-Vt:nz.transition!==null?(Hh===0&&(Hh=_2()),Hh):(t=ze,t!==0||(t=window.event,t=t===void 0?16:j2(t.type)),t):1}function Xr(t,e,n,r){if(50<Qc)throw Qc=0,jv=null,Error(X(185));Ku(t,n,r),(!(Oe&2)||t!==jt)&&(t===jt&&(!(Oe&2)&&(ng|=n),It===4&&Fs(t,Vt)),Wn(t,r),n===1&&Oe===0&&!(e.mode&1)&&(Pl=vt()+500,Qf&&yi()))}function Wn(t,e){var n=t.callbackNode;n6(t,e);var r=Op(t,t===jt?Vt:0);if(r===0)n!==null&&aP(n),t.callbackNode=null,t.callbackPriority=0;else if(e=r&-r,t.callbackPriority!==e){if(n!=null&&aP(n),e===1)t.tag===0?tz(JP.bind(null,t)):Z2(JP.bind(null,t)),Z6(function(){!(Oe&6)&&yi()}),n=null;else{switch(I2(r)){case 1:n=v0;break;case 4:n=P2;break;case 16:n=jp;break;case 536870912:n=C2;break;default:n=jp}n=Xk(n,Uk.bind(null,t))}t.callbackPriority=e,t.callbackNode=n}}function Uk(t,e){if(Uh=-1,Hh=0,Oe&6)throw Error(X(327));var n=t.callbackNode;if(cl()&&t.callbackNode!==n)return null;var r=Op(t,t===jt?Vt:0);if(r===0)return null;if(r&30||r&t.expiredLanes||e)e=Zp(t,r);else{e=r;var o=Oe;Oe|=2;var s=Kk();(jt!==t||Vt!==e)&&(Yo=null,Pl=vt()+500,Ui(t,e));do try{bz();break}catch(a){Hk(t,a)}while(!0);j0(),Yp.current=s,Oe=o,Ct!==null?e=0:(jt=null,Vt=0,e=It)}if(e!==0){if(e===2&&(o=sv(t),o!==0&&(r=o,e=Ov(t,o))),e===1)throw n=Pu,Ui(t,0),Fs(t,r),Wn(t,vt()),n;if(e===6)Fs(t,r);else{if(o=t.current.alternate,!(r&30)&&!xz(o)&&(e=Zp(t,r),e===2&&(s=sv(t),s!==0&&(r=s,e=Ov(t,s))),e===1))throw n=Pu,Ui(t,0),Fs(t,r),Wn(t,vt()),n;switch(t.finishedWork=o,t.finishedLanes=r,e){case 0:case 1:throw Error(X(345));case 2:Ri(t,Ln,Yo);break;case 3:if(Fs(t,r),(r&130023424)===r&&(e=V0+500-vt(),10<e)){if(Op(t,0)!==0)break;if(o=t.suspendedLanes,(o&r)!==r){xn(),t.pingedLanes|=t.suspendedLanes&o;break}t.timeoutHandle=pv(Ri.bind(null,t,Ln,Yo),e);break}Ri(t,Ln,Yo);break;case 4:if(Fs(t,r),(r&4194240)===r)break;for(e=t.eventTimes,o=-1;0<r;){var i=31-Yr(r);s=1<<i,i=e[i],i>o&&(o=i),r&=~s}if(r=o,r=vt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*vz(r/1960))-r,10<r){t.timeoutHandle=pv(Ri.bind(null,t,Ln,Yo),r);break}Ri(t,Ln,Yo);break;case 5:Ri(t,Ln,Yo);break;default:throw Error(X(329))}}}return Wn(t,vt()),t.callbackNode===n?Uk.bind(null,t):null}function Ov(t,e){var n=Zc;return t.current.memoizedState.isDehydrated&&(Ui(t,e).flags|=256),t=Zp(t,e),t!==2&&(e=Ln,Ln=n,e!==null&&Dv(e)),t}function Dv(t){Ln===null?Ln=t:Ln.push.apply(Ln,t)}function xz(t){for(var e=t;;){if(e.flags&16384){var n=e.updateQueue;if(n!==null&&(n=n.stores,n!==null))for(var r=0;r<n.length;r++){var o=n[r],s=o.getSnapshot;o=o.value;try{if(!Qr(s(),o))return!1}catch{return!1}}}if(n=e.child,e.subtreeFlags&16384&&n!==null)n.return=e,e=n;else{if(e===t)break;for(;e.sibling===null;){if(e.return===null||e.return===t)return!0;e=e.return}e.sibling.return=e.return,e=e.sibling}}return!0}function Fs(t,e){for(e&=~G0,e&=~ng,t.suspendedLanes|=e,t.pingedLanes&=~e,t=t.expirationTimes;0<e;){var n=31-Yr(e),r=1<<n;t[n]=-1,e&=~r}}function JP(t){if(Oe&6)throw Error(X(327));cl();var e=Op(t,0);if(!(e&1))return Wn(t,vt()),null;var n=Zp(t,e);if(t.tag!==0&&n===2){var r=sv(t);r!==0&&(e=r,n=Ov(t,r))}if(n===1)throw n=Pu,Ui(t,0),Fs(t,e),Wn(t,vt()),n;if(n===6)throw Error(X(345));return t.finishedWork=t.current.alternate,t.finishedLanes=e,Ri(t,Ln,Yo),Wn(t,vt()),null}function Y0(t,e){var n=Oe;Oe|=1;try{return t(e)}finally{Oe=n,Oe===0&&(Pl=vt()+500,Qf&&yi())}}function Zi(t){Hs!==null&&Hs.tag===0&&!(Oe&6)&&cl();var e=Oe;Oe|=1;var n=Mr.transition,r=ze;try{if(Mr.transition=null,ze=1,t)return t()}finally{ze=r,Mr.transition=n,Oe=e,!(Oe&6)&&yi()}}function X0(){tr=Va.current,nt(Va)}function Ui(t,e){t.finishedWork=null,t.finishedLanes=0;var n=t.timeoutHandle;if(n!==-1&&(t.timeoutHandle=-1,q6(n)),Ct!==null)for(n=Ct.return;n!==null;){var r=n;switch(T0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Fp();break;case 3:wl(),nt(Hn),nt(hn),F0();break;case 5:$0(r);break;case 4:wl();break;case 13:nt(ut);break;case 19:nt(ut);break;case 10:O0(r.type._context);break;case 22:case 23:X0()}n=n.return}if(jt=t,Ct=t=ei(t.current,null),Vt=tr=e,It=0,Pu=null,G0=ng=qi=0,Ln=Zc=null,Ni!==null){for(e=0;e<Ni.length;e++)if(n=Ni[e],r=n.interleaved,r!==null){n.interleaved=null;var o=r.next,s=n.pending;if(s!==null){var i=s.next;s.next=o,r.next=i}n.pending=r}Ni=null}return t}function Hk(t,e){do{var n=Ct;try{if(j0(),Nh.current=Vp,Gp){for(var r=pt.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Gp=!1}if(Xi=0,kt=_t=pt=null,Xc=!1,xu=0,W0.current=null,n===null||n.return===null){It=1,Pu=e,Ct=null;break}e:{var s=t,i=n.return,a=n,l=e;if(e=Vt,a.flags|=32768,l!==null&&typeof l=="object"&&typeof l.then=="function"){var c=l,u=a,h=u.tag;if(!(u.mode&1)&&(h===0||h===11||h===15)){var p=u.alternate;p?(u.updateQueue=p.updateQueue,u.memoizedState=p.memoizedState,u.lanes=p.lanes):(u.updateQueue=null,u.memoizedState=null)}var f=zP(i);if(f!==null){f.flags&=-257,BP(f,i,a,s,e),f.mode&1&&NP(s,c,e),e=f,l=c;var g=e.updateQueue;if(g===null){var m=new Set;m.add(l),e.updateQueue=m}else g.add(l);break e}else{if(!(e&1)){NP(s,c,e),q0();break e}l=Error(X(426))}}else if(it&&a.mode&1){var v=zP(i);if(v!==null){!(v.flags&65536)&&(v.flags|=256),BP(v,i,a,s,e),M0(bl(l,a));break e}}s=l=bl(l,a),It!==4&&(It=2),Zc===null?Zc=[s]:Zc.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,e&=-e,s.lanes|=e;var S=Ik(s,l,e);OP(s,S);break e;case 1:a=l;var y=s.type,b=s.stateNode;if(!(s.flags&128)&&(typeof y.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&(Qs===null||!Qs.has(b)))){s.flags|=65536,e&=-e,s.lanes|=e;var P=Ek(s,a,e);OP(s,P);break e}}s=s.return}while(s!==null)}Gk(n)}catch(C){e=C,Ct===n&&n!==null&&(Ct=n=n.return);continue}break}while(!0)}function Kk(){var t=Yp.current;return Yp.current=Vp,t===null?Vp:t}function q0(){(It===0||It===3||It===2)&&(It=4),jt===null||!(qi&268435455)&&!(ng&268435455)||Fs(jt,Vt)}function Zp(t,e){var n=Oe;Oe|=2;var r=Kk();(jt!==t||Vt!==e)&&(Yo=null,Ui(t,e));do try{wz();break}catch(o){Hk(t,o)}while(!0);if(j0(),Oe=n,Yp.current=r,Ct!==null)throw Error(X(261));return jt=null,Vt=0,It}function wz(){for(;Ct!==null;)Wk(Ct)}function bz(){for(;Ct!==null&&!VN();)Wk(Ct)}function Wk(t){var e=Yk(t.alternate,t,tr);t.memoizedProps=t.pendingProps,e===null?Gk(t):Ct=e,W0.current=null}function Gk(t){var e=t;do{var n=e.alternate;if(t=e.return,e.flags&32768){if(n=gz(n,e),n!==null){n.flags&=32767,Ct=n;return}if(t!==null)t.flags|=32768,t.subtreeFlags=0,t.deletions=null;else{It=6,Ct=null;return}}else if(n=fz(n,e,tr),n!==null){Ct=n;return}if(e=e.sibling,e!==null){Ct=e;return}Ct=e=t}while(e!==null);It===0&&(It=5)}function Ri(t,e,n){var r=ze,o=Mr.transition;try{Mr.transition=null,ze=1,Pz(t,e,n,r)}finally{Mr.transition=o,ze=r}return null}function Pz(t,e,n,r){do cl();while(Hs!==null);if(Oe&6)throw Error(X(327));n=t.finishedWork;var o=t.finishedLanes;if(n===null)return null;if(t.finishedWork=null,t.finishedLanes=0,n===t.current)throw Error(X(177));t.callbackNode=null,t.callbackPriority=0;var s=n.lanes|n.childLanes;if(r6(t,s),t===jt&&(Ct=jt=null,Vt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||Kd||(Kd=!0,Xk(jp,function(){return cl(),null})),s=(n.flags&15990)!==0,n.subtreeFlags&15990||s){s=Mr.transition,Mr.transition=null;var i=ze;ze=1;var a=Oe;Oe|=4,W0.current=null,yz(t,n),zk(n,t),H6(dv),Dp=!!uv,dv=uv=null,t.current=n,Sz(n),YN(),Oe=a,ze=i,Mr.transition=s}else t.current=n;if(Kd&&(Kd=!1,Hs=t,qp=o),s=t.pendingLanes,s===0&&(Qs=null),ZN(n.stateNode),Wn(t,vt()),e!==null)for(r=t.onRecoverableError,n=0;n<e.length;n++)o=e[n],r(o.value,{componentStack:o.stack,digest:o.digest});if(Xp)throw Xp=!1,t=Av,Av=null,t;return qp&1&&t.tag!==0&&cl(),s=t.pendingLanes,s&1?t===jv?Qc++:(Qc=0,jv=t):Qc=0,yi(),null}function cl(){if(Hs!==null){var t=I2(qp),e=Mr.transition,n=ze;try{if(Mr.transition=null,ze=16>t?16:t,Hs===null)var r=!1;else{if(t=Hs,Hs=null,qp=0,Oe&6)throw Error(X(331));var o=Oe;for(Oe|=4,re=t.current;re!==null;){var s=re,i=s.child;if(re.flags&16){var a=s.deletions;if(a!==null){for(var l=0;l<a.length;l++){var c=a[l];for(re=c;re!==null;){var u=re;switch(u.tag){case 0:case 11:case 15:qc(8,u,s)}var h=u.child;if(h!==null)h.return=u,re=h;else for(;re!==null;){u=re;var p=u.sibling,f=u.return;if($k(u),u===c){re=null;break}if(p!==null){p.return=f,re=p;break}re=f}}}var g=s.alternate;if(g!==null){var m=g.child;if(m!==null){g.child=null;do{var v=m.sibling;m.sibling=null,m=v}while(m!==null)}}re=s}}if(s.subtreeFlags&2064&&i!==null)i.return=s,re=i;else e:for(;re!==null;){if(s=re,s.flags&2048)switch(s.tag){case 0:case 11:case 15:qc(9,s,s.return)}var S=s.sibling;if(S!==null){S.return=s.return,re=S;break e}re=s.return}}var y=t.current;for(re=y;re!==null;){i=re;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,re=b;else e:for(i=y;re!==null;){if(a=re,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:tg(9,a)}}catch(C){mt(a,a.return,C)}if(a===i){re=null;break e}var P=a.sibling;if(P!==null){P.return=a.return,re=P;break e}re=a.return}}if(Oe=o,yi(),Po&&typeof Po.onPostCommitFiberRoot=="function")try{Po.onPostCommitFiberRoot(Vf,t)}catch{}r=!0}return r}finally{ze=n,Mr.transition=e}}return!1}function eC(t,e,n){e=bl(n,e),e=Ik(t,e,1),t=Zs(t,e,1),e=xn(),t!==null&&(Ku(t,1,e),Wn(t,e))}function mt(t,e,n){if(t.tag===3)eC(t,t,n);else for(;e!==null;){if(e.tag===3){eC(e,t,n);break}else if(e.tag===1){var r=e.stateNode;if(typeof e.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Qs===null||!Qs.has(r))){t=bl(n,t),t=Ek(e,t,1),e=Zs(e,t,1),t=xn(),e!==null&&(Ku(e,1,t),Wn(e,t));break}}e=e.return}}function Cz(t,e,n){var r=t.pingCache;r!==null&&r.delete(e),e=xn(),t.pingedLanes|=t.suspendedLanes&n,jt===t&&(Vt&n)===n&&(It===4||It===3&&(Vt&130023424)===Vt&&500>vt()-V0?Ui(t,0):G0|=n),Wn(t,e)}function Vk(t,e){e===0&&(t.mode&1?(e=Dd,Dd<<=1,!(Dd&130023424)&&(Dd=4194304)):e=1);var n=xn();t=ds(t,e),t!==null&&(Ku(t,e,n),Wn(t,n))}function _z(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),Vk(t,n)}function Iz(t,e){var n=0;switch(t.tag){case 13:var r=t.stateNode,o=t.memoizedState;o!==null&&(n=o.retryLane);break;case 19:r=t.stateNode;break;default:throw Error(X(314))}r!==null&&r.delete(e),Vk(t,n)}var Yk;Yk=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Hn.current)Nn=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Nn=!1,pz(t,e,n);Nn=!!(t.flags&131072)}else Nn=!1,it&&e.flags&1048576&&Q2(e,Bp,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;Bh(t,e),t=e.pendingProps;var o=Sl(e,hn.current);ll(e,n),o=z0(null,e,r,t,o,n);var s=B0();return e.flags|=1,typeof o=="object"&&o!==null&&typeof o.render=="function"&&o.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,Kn(r)?(s=!0,Np(e)):s=!1,e.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,R0(e),o.updater=eg,e.stateNode=o,o._reactInternals=e,xv(e,r,t,n),e=Pv(null,e,r,!0,s,n)):(e.tag=0,it&&s&&k0(e),yn(null,e,o,n),e=e.child),e;case 16:r=e.elementType;e:{switch(Bh(t,e),t=e.pendingProps,o=r._init,r=o(r._payload),e.type=r,o=e.tag=kz(r),t=zr(r,t),o){case 0:e=bv(null,e,r,t,n);break e;case 1:e=KP(null,e,r,t,n);break e;case 11:e=UP(null,e,r,t,n);break e;case 14:e=HP(null,e,r,zr(r.type,t),n);break e}throw Error(X(306,r,""))}return e;case 0:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:zr(r,o),bv(t,e,r,o,n);case 1:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:zr(r,o),KP(t,e,r,o,n);case 3:e:{if(Ak(e),t===null)throw Error(X(387));r=e.pendingProps,s=e.memoizedState,o=s.element,ok(t,e),Kp(e,r,null,n);var i=e.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},e.updateQueue.baseState=s,e.memoizedState=s,e.flags&256){o=bl(Error(X(423)),e),e=WP(t,e,r,n,o);break e}else if(r!==o){o=bl(Error(X(424)),e),e=WP(t,e,r,n,o);break e}else for(or=qs(e.stateNode.containerInfo.firstChild),ir=e,it=!0,Hr=null,n=nk(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(vl(),r===o){e=hs(t,e,n);break e}yn(t,e,r,n)}e=e.child}return e;case 5:return sk(e),t===null&&yv(e),r=e.type,o=e.pendingProps,s=t!==null?t.memoizedProps:null,i=o.children,hv(r,o)?i=null:s!==null&&hv(r,s)&&(e.flags|=32),Mk(t,e),yn(t,e,i,n),e.child;case 6:return t===null&&yv(e),null;case 13:return jk(t,e,n);case 4:return L0(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=xl(e,null,r,n):yn(t,e,r,n),e.child;case 11:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:zr(r,o),UP(t,e,r,o,n);case 7:return yn(t,e,e.pendingProps,n),e.child;case 8:return yn(t,e,e.pendingProps.children,n),e.child;case 12:return yn(t,e,e.pendingProps.children,n),e.child;case 10:e:{if(r=e.type._context,o=e.pendingProps,s=e.memoizedProps,i=o.value,Xe(Up,r._currentValue),r._currentValue=i,s!==null)if(Qr(s.value,i)){if(s.children===o.children&&!Hn.current){e=hs(t,e,n);break e}}else for(s=e.child,s!==null&&(s.return=e);s!==null;){var a=s.dependencies;if(a!==null){i=s.child;for(var l=a.firstContext;l!==null;){if(l.context===r){if(s.tag===1){l=ns(-1,n&-n),l.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var u=c.pending;u===null?l.next=l:(l.next=u.next,u.next=l),c.pending=l}}s.lanes|=n,l=s.alternate,l!==null&&(l.lanes|=n),Sv(s.return,n,e),a.lanes|=n;break}l=l.next}}else if(s.tag===10)i=s.type===e.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(X(341));i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),Sv(i,n,e),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===e){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}yn(t,e,o.children,n),e=e.child}return e;case 9:return o=e.type,r=e.pendingProps.children,ll(e,n),o=jr(o),r=r(o),e.flags|=1,yn(t,e,r,n),e.child;case 14:return r=e.type,o=zr(r,e.pendingProps),o=zr(r.type,o),HP(t,e,r,o,n);case 15:return kk(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:zr(r,o),Bh(t,e),e.tag=1,Kn(r)?(t=!0,Np(e)):t=!1,ll(e,n),_k(e,r,o),xv(e,r,o,n),Pv(null,e,r,!0,t,n);case 19:return Ok(t,e,n);case 22:return Tk(t,e,n)}throw Error(X(156,e.tag))};function Xk(t,e){return b2(t,e)}function Ez(t,e,n,r){this.tag=t,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function kr(t,e,n,r){return new Ez(t,e,n,r)}function Z0(t){return t=t.prototype,!(!t||!t.isReactComponent)}function kz(t){if(typeof t=="function")return Z0(t)?1:0;if(t!=null){if(t=t.$$typeof,t===m0)return 11;if(t===y0)return 14}return 2}function ei(t,e){var n=t.alternate;return n===null?(n=kr(t.tag,e,t.key,t.mode),n.elementType=t.elementType,n.type=t.type,n.stateNode=t.stateNode,n.alternate=t,t.alternate=n):(n.pendingProps=e,n.type=t.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=t.flags&14680064,n.childLanes=t.childLanes,n.lanes=t.lanes,n.child=t.child,n.memoizedProps=t.memoizedProps,n.memoizedState=t.memoizedState,n.updateQueue=t.updateQueue,e=t.dependencies,n.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},n.sibling=t.sibling,n.index=t.index,n.ref=t.ref,n}function Kh(t,e,n,r,o,s){var i=2;if(r=t,typeof t=="function")Z0(t)&&(i=1);else if(typeof t=="string")i=5;else e:switch(t){case $a:return Hi(n.children,o,s,e);case g0:i=8,o|=8;break;case KS:return t=kr(12,n,e,o|2),t.elementType=KS,t.lanes=s,t;case WS:return t=kr(13,n,e,o),t.elementType=WS,t.lanes=s,t;case GS:return t=kr(19,n,e,o),t.elementType=GS,t.lanes=s,t;case s2:return rg(n,o,s,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case r2:i=10;break e;case o2:i=9;break e;case m0:i=11;break e;case y0:i=14;break e;case Rs:i=16,r=null;break e}throw Error(X(130,t==null?t:typeof t,""))}return e=kr(i,n,e,o),e.elementType=t,e.type=r,e.lanes=s,e}function Hi(t,e,n,r){return t=kr(7,t,r,e),t.lanes=n,t}function rg(t,e,n,r){return t=kr(22,t,r,e),t.elementType=s2,t.lanes=n,t.stateNode={isHidden:!1},t}function Zm(t,e,n){return t=kr(6,t,null,e),t.lanes=n,t}function Qm(t,e,n){return e=kr(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function Tz(t,e,n,r,o){this.tag=e,this.containerInfo=t,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=jm(0),this.expirationTimes=jm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=jm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function Q0(t,e,n,r,o,s,i,a,l){return t=new Tz(t,e,n,a,l),e===1?(e=1,s===!0&&(e|=8)):e=0,s=kr(3,null,null,e),t.current=s,s.stateNode=t,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},R0(s),t}function Mz(t,e,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:La,key:r==null?null:""+r,children:t,containerInfo:e,implementation:n}}function qk(t){if(!t)return si;t=t._reactInternals;e:{if(ha(t)!==t||t.tag!==1)throw Error(X(170));var e=t;do{switch(e.tag){case 3:e=e.stateNode.context;break e;case 1:if(Kn(e.type)){e=e.stateNode.__reactInternalMemoizedMergedChildContext;break e}}e=e.return}while(e!==null);throw Error(X(171))}if(t.tag===1){var n=t.type;if(Kn(n))return q2(t,n,e)}return e}function Zk(t,e,n,r,o,s,i,a,l){return t=Q0(n,r,!0,t,o,s,i,a,l),t.context=qk(null),n=t.current,r=xn(),o=Js(n),s=ns(r,o),s.callback=e??null,Zs(n,s,o),t.current.lanes=o,Ku(t,o,r),Wn(t,r),t}function og(t,e,n,r){var o=e.current,s=xn(),i=Js(o);return n=qk(n),e.context===null?e.context=n:e.pendingContext=n,e=ns(s,i),e.payload={element:t},r=r===void 0?null:r,r!==null&&(e.callback=r),t=Zs(o,e,i),t!==null&&(Xr(t,o,i,s),Fh(t,o,i)),i}function Qp(t){if(t=t.current,!t.child)return null;switch(t.child.tag){case 5:return t.child.stateNode;default:return t.child.stateNode}}function tC(t,e){if(t=t.memoizedState,t!==null&&t.dehydrated!==null){var n=t.retryLane;t.retryLane=n!==0&&n<e?n:e}}function J0(t,e){tC(t,e),(t=t.alternate)&&tC(t,e)}function Az(){return null}var Qk=typeof reportError=="function"?reportError:function(t){console.error(t)};function ew(t){this._internalRoot=t}sg.prototype.render=ew.prototype.render=function(t){var e=this._internalRoot;if(e===null)throw Error(X(409));og(t,e,null,null)};sg.prototype.unmount=ew.prototype.unmount=function(){var t=this._internalRoot;if(t!==null){this._internalRoot=null;var e=t.containerInfo;Zi(function(){og(null,t,null,null)}),e[us]=null}};function sg(t){this._internalRoot=t}sg.prototype.unstable_scheduleHydration=function(t){if(t){var e=T2();t={blockedOn:null,target:t,priority:e};for(var n=0;n<$s.length&&e!==0&&e<$s[n].priority;n++);$s.splice(n,0,t),n===0&&A2(t)}};function tw(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)}function ig(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11&&(t.nodeType!==8||t.nodeValue!==" react-mount-point-unstable "))}function nC(){}function jz(t,e,n,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=Qp(i);s.call(c)}}var i=Zk(e,r,t,0,null,!1,!1,"",nC);return t._reactRootContainer=i,t[us]=i.current,gu(t.nodeType===8?t.parentNode:t),Zi(),i}for(;o=t.lastChild;)t.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=Qp(l);a.call(c)}}var l=Q0(t,0,!1,null,null,!1,!1,"",nC);return t._reactRootContainer=l,t[us]=l.current,gu(t.nodeType===8?t.parentNode:t),Zi(function(){og(e,l,n,r)}),l}function ag(t,e,n,r,o){var s=n._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var l=Qp(i);a.call(l)}}og(e,i,t,o)}else i=jz(n,e,t,o,r);return Qp(i)}E2=function(t){switch(t.tag){case 3:var e=t.stateNode;if(e.current.memoizedState.isDehydrated){var n=jc(e.pendingLanes);n!==0&&(x0(e,n|1),Wn(e,vt()),!(Oe&6)&&(Pl=vt()+500,yi()))}break;case 13:Zi(function(){var r=ds(t,1);if(r!==null){var o=xn();Xr(r,t,1,o)}}),J0(t,1)}};w0=function(t){if(t.tag===13){var e=ds(t,134217728);if(e!==null){var n=xn();Xr(e,t,134217728,n)}J0(t,134217728)}};k2=function(t){if(t.tag===13){var e=Js(t),n=ds(t,e);if(n!==null){var r=xn();Xr(n,t,e,r)}J0(t,e)}};T2=function(){return ze};M2=function(t,e){var n=ze;try{return ze=t,e()}finally{ze=n}};nv=function(t,e,n){switch(e){case"input":if(XS(t,n),e=n.name,n.type==="radio"&&e!=null){for(n=t;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll("input[name="+JSON.stringify(""+e)+'][type="radio"]'),e=0;e<n.length;e++){var r=n[e];if(r!==t&&r.form===t.form){var o=Zf(r);if(!o)throw Error(X(90));a2(r),XS(r,o)}}}break;case"textarea":c2(t,n);break;case"select":e=n.value,e!=null&&ol(t,!!n.multiple,e,!1)}};m2=Y0;y2=Zi;var Oz={usingClientEntryPoint:!1,Events:[Gu,Ba,Zf,f2,g2,Y0]},uc={findFiberByHostInstance:Fi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},Dz={bundleType:uc.bundleType,version:uc.version,rendererPackageName:uc.rendererPackageName,rendererConfig:uc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Ss.ReactCurrentDispatcher,findHostInstanceByFiber:function(t){return t=x2(t),t===null?null:t.stateNode},findFiberByHostInstance:uc.findFiberByHostInstance||Az,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Wd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Wd.isDisabled&&Wd.supportsFiber)try{Vf=Wd.inject(Dz),Po=Wd}catch{}}mr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Oz;mr.createPortal=function(t,e){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!tw(e))throw Error(X(200));return Mz(t,e,null,n)};mr.createRoot=function(t,e){if(!tw(t))throw Error(X(299));var n=!1,r="",o=Qk;return e!=null&&(e.unstable_strictMode===!0&&(n=!0),e.identifierPrefix!==void 0&&(r=e.identifierPrefix),e.onRecoverableError!==void 0&&(o=e.onRecoverableError)),e=Q0(t,1,!1,null,null,n,!1,r,o),t[us]=e.current,gu(t.nodeType===8?t.parentNode:t),new ew(e)};mr.findDOMNode=function(t){if(t==null)return null;if(t.nodeType===1)return t;var e=t._reactInternals;if(e===void 0)throw typeof t.render=="function"?Error(X(188)):(t=Object.keys(t).join(","),Error(X(268,t)));return t=x2(e),t=t===null?null:t.stateNode,t};mr.flushSync=function(t){return Zi(t)};mr.hydrate=function(t,e,n){if(!ig(e))throw Error(X(200));return ag(null,t,e,!0,n)};mr.hydrateRoot=function(t,e,n){if(!tw(t))throw Error(X(405));var r=n!=null&&n.hydratedSources||null,o=!1,s="",i=Qk;if(n!=null&&(n.unstable_strictMode===!0&&(o=!0),n.identifierPrefix!==void 0&&(s=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),e=Zk(e,null,t,1,n??null,o,!1,s,i),t[us]=e.current,gu(t),r)for(t=0;t<r.length;t++)n=r[t],o=n._getVersion,o=o(n._source),e.mutableSourceEagerHydrationData==null?e.mutableSourceEagerHydrationData=[n,o]:e.mutableSourceEagerHydrationData.push(n,o);return new sg(e)};mr.render=function(t,e,n){if(!ig(e))throw Error(X(200));return ag(null,t,e,!1,n)};mr.unmountComponentAtNode=function(t){if(!ig(t))throw Error(X(40));return t._reactRootContainer?(Zi(function(){ag(null,null,t,!1,function(){t._reactRootContainer=null,t[us]=null})}),!0):!1};mr.unstable_batchedUpdates=Y0;mr.unstable_renderSubtreeIntoContainer=function(t,e,n,r){if(!ig(n))throw Error(X(200));if(t==null||t._reactInternals===void 0)throw Error(X(38));return ag(t,e,n,!1,r)};mr.version="18.3.1-next-f1338f8080-20240426";function Jk(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Jk)}catch(t){console.error(t)}}Jk(),JE.exports=mr;var ps=JE.exports;const Rz=fi(ps);var eT,rC=ps;eT=US.createRoot=rC.createRoot,US.hydrateRoot=rC.hydrateRoot;function ae(t,e={}){const n=typeof t=="string"?t:t.src;if(typeof e=="function")return e(n);const{baseUrl:r=""}=e;return n.startsWith("data:")||n.match(/^https?:\/\//)?n:`${r.replace(/\/$/,"")}/${n.replace(/^\.?\//,"")}`}function Lz(t){const e=ae("./icons/icon/0_merged.svg",t);return{fonts:{monospace:ae("./fonts/IBMPlexMono-Medium.woff2",t),sansSerif:ae("./fonts/IBMPlexSans-Medium.woff2",t),serif:ae("./fonts/IBMPlexSerif-Medium.woff2",t),draw:ae("./fonts/Shantell_Sans-Tldrawish.woff2",t)},icons:{"align-bottom":e+"#align-bottom","align-center-horizontal":e+"#align-center-horizontal","align-center-vertical":e+"#align-center-vertical","align-left":e+"#align-left","align-right":e+"#align-right","align-top":e+"#align-top","arrow-left":e+"#arrow-left","arrowhead-arrow":e+"#arrowhead-arrow","arrowhead-bar":e+"#arrowhead-bar","arrowhead-diamond":e+"#arrowhead-diamond","arrowhead-dot":e+"#arrowhead-dot","arrowhead-none":e+"#arrowhead-none","arrowhead-square":e+"#arrowhead-square","arrowhead-triangle-inverted":e+"#arrowhead-triangle-inverted","arrowhead-triangle":e+"#arrowhead-triangle",blob:e+"#blob","bring-forward":e+"#bring-forward","bring-to-front":e+"#bring-to-front",broken:e+"#broken","check-circle":e+"#check-circle",check:e+"#check","chevron-down":e+"#chevron-down","chevron-left":e+"#chevron-left","chevron-right":e+"#chevron-right","chevron-up":e+"#chevron-up","chevrons-ne":e+"#chevrons-ne","chevrons-sw":e+"#chevrons-sw","clipboard-copied":e+"#clipboard-copied","clipboard-copy":e+"#clipboard-copy",color:e+"#color","cross-2":e+"#cross-2","cross-circle":e+"#cross-circle","dash-dashed":e+"#dash-dashed","dash-dotted":e+"#dash-dotted","dash-draw":e+"#dash-draw","dash-solid":e+"#dash-solid",disconnected:e+"#disconnected",discord:e+"#discord","distribute-horizontal":e+"#distribute-horizontal","distribute-vertical":e+"#distribute-vertical",dot:e+"#dot","dots-horizontal":e+"#dots-horizontal","dots-vertical":e+"#dots-vertical","drag-handle-dots":e+"#drag-handle-dots",duplicate:e+"#duplicate",edit:e+"#edit","external-link":e+"#external-link","fill-fill":e+"#fill-fill","fill-none":e+"#fill-none","fill-pattern":e+"#fill-pattern","fill-semi":e+"#fill-semi","fill-solid":e+"#fill-solid",follow:e+"#follow",following:e+"#following","font-draw":e+"#font-draw","font-mono":e+"#font-mono","font-sans":e+"#font-sans","font-serif":e+"#font-serif","geo-arrow-down":e+"#geo-arrow-down","geo-arrow-left":e+"#geo-arrow-left","geo-arrow-right":e+"#geo-arrow-right","geo-arrow-up":e+"#geo-arrow-up","geo-check-box":e+"#geo-check-box","geo-cloud":e+"#geo-cloud","geo-diamond":e+"#geo-diamond","geo-ellipse":e+"#geo-ellipse","geo-heart":e+"#geo-heart","geo-hexagon":e+"#geo-hexagon","geo-octagon":e+"#geo-octagon","geo-oval":e+"#geo-oval","geo-pentagon":e+"#geo-pentagon","geo-rectangle":e+"#geo-rectangle","geo-rhombus-2":e+"#geo-rhombus-2","geo-rhombus":e+"#geo-rhombus","geo-star":e+"#geo-star","geo-trapezoid":e+"#geo-trapezoid","geo-triangle":e+"#geo-triangle","geo-x-box":e+"#geo-x-box",github:e+"#github",group:e+"#group","horizontal-align-end":e+"#horizontal-align-end","horizontal-align-middle":e+"#horizontal-align-middle","horizontal-align-start":e+"#horizontal-align-start","info-circle":e+"#info-circle",leading:e+"#leading",link:e+"#link",lock:e+"#lock",menu:e+"#menu",minus:e+"#minus",mixed:e+"#mixed",pack:e+"#pack",plus:e+"#plus","question-mark-circle":e+"#question-mark-circle","question-mark":e+"#question-mark",redo:e+"#redo","reset-zoom":e+"#reset-zoom","rotate-ccw":e+"#rotate-ccw","rotate-cw":e+"#rotate-cw","send-backward":e+"#send-backward","send-to-back":e+"#send-to-back","share-1":e+"#share-1","size-extra-large":e+"#size-extra-large","size-large":e+"#size-large","size-medium":e+"#size-medium","size-small":e+"#size-small","spline-cubic":e+"#spline-cubic","spline-line":e+"#spline-line","stack-horizontal":e+"#stack-horizontal","stack-vertical":e+"#stack-vertical","status-offline":e+"#status-offline","stretch-horizontal":e+"#stretch-horizontal","stretch-vertical":e+"#stretch-vertical","text-align-center":e+"#text-align-center","text-align-left":e+"#text-align-left","text-align-right":e+"#text-align-right","toggle-off":e+"#toggle-off","toggle-on":e+"#toggle-on","tool-arrow":e+"#tool-arrow","tool-eraser":e+"#tool-eraser","tool-frame":e+"#tool-frame","tool-hand":e+"#tool-hand","tool-highlight":e+"#tool-highlight","tool-laser":e+"#tool-laser","tool-line":e+"#tool-line","tool-media":e+"#tool-media","tool-note":e+"#tool-note","tool-pencil":e+"#tool-pencil","tool-pointer":e+"#tool-pointer","tool-screenshot":e+"#tool-screenshot","tool-text":e+"#tool-text",trash:e+"#trash",twitter:e+"#twitter",undo:e+"#undo",ungroup:e+"#ungroup",unlock:e+"#unlock","vertical-align-end":e+"#vertical-align-end","vertical-align-middle":e+"#vertical-align-middle","vertical-align-start":e+"#vertical-align-start","warning-triangle":e+"#warning-triangle","zoom-in":e+"#zoom-in","zoom-out":e+"#zoom-out"},translations:{ar:ae("./translations/ar.json",t),ca:ae("./translations/ca.json",t),cs:ae("./translations/cs.json",t),da:ae("./translations/da.json",t),de:ae("./translations/de.json",t),en:ae("./translations/en.json",t),es:ae("./translations/es.json",t),fa:ae("./translations/fa.json",t),fi:ae("./translations/fi.json",t),fr:ae("./translations/fr.json",t),gl:ae("./translations/gl.json",t),he:ae("./translations/he.json",t),"hi-in":ae("./translations/hi-in.json",t),hr:ae("./translations/hr.json",t),hu:ae("./translations/hu.json",t),id:ae("./translations/id.json",t),it:ae("./translations/it.json",t),ja:ae("./translations/ja.json",t),"ko-kr":ae("./translations/ko-kr.json",t),ku:ae("./translations/ku.json",t),languages:ae("./translations/languages.json",t),main:ae("./translations/main.json",t),my:ae("./translations/my.json",t),ne:ae("./translations/ne.json",t),no:ae("./translations/no.json",t),pl:ae("./translations/pl.json",t),"pt-br":ae("./translations/pt-br.json",t),"pt-pt":ae("./translations/pt-pt.json",t),ro:ae("./translations/ro.json",t),ru:ae("./translations/ru.json",t),sl:ae("./translations/sl.json",t),sv:ae("./translations/sv.json",t),te:ae("./translations/te.json",t),th:ae("./translations/th.json",t),tr:ae("./translations/tr.json",t),uk:ae("./translations/uk.json",t),vi:ae("./translations/vi.json",t),"zh-cn":ae("./translations/zh-cn.json",t),"zh-tw":ae("./translations/zh-tw.json",t)},embedIcons:{codepen:ae("./embed-icons/codepen.png",t),codesandbox:ae("./embed-icons/codesandbox.png",t),desmos:ae("./embed-icons/desmos.png",t),excalidraw:ae("./embed-icons/excalidraw.png",t),felt:ae("./embed-icons/felt.png",t),figma:ae("./embed-icons/figma.png",t),github_gist:ae("./embed-icons/github_gist.png",t),google_calendar:ae("./embed-icons/google_calendar.png",t),google_maps:ae("./embed-icons/google_maps.png",t),google_slides:ae("./embed-icons/google_slides.png",t),observable:ae("./embed-icons/observable.png",t),replit:ae("./embed-icons/replit.png",t),scratch:ae("./embed-icons/scratch.png",t),spotify:ae("./embed-icons/spotify.png",t),tldraw:ae("./embed-icons/tldraw.png",t),val_town:ae("./embed-icons/val_town.png",t),vimeo:ae("./embed-icons/vimeo.png",t),youtube:ae("./embed-icons/youtube.png",t)}}}const Jm="__TLDRAW_LIBRARY_VERSIONS__";function $z(){if(globalThis[Jm])return globalThis[Jm];const t={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,Jm,{value:t,writable:!1,configurable:!1,enumerable:!1}),t}function Si(t,e,n){if(!t||!e||!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=$z();if(r.versions.push({name:t,version:e,modules:n}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,oC(r)},100)}catch{oC(r)}}function oC(t){if(!t.versions.length||t.didWarn)return;const e=t.versions.sort((a,l)=>sC(a.version,l.version)),n=e[e.length-1].version,r=new Set,o=new Map;for(const a of e){if(o.has(a.name)){r.delete(a.name),ey(o,a.name,new Set).add(a.version);continue}a.version===n?r.add(a.name):(r.delete(a.name),ey(o,a.name,new Set).add(a.version))}if(o.size>0){const a=[`${Uo("[tldraw]",["bold","bgRed","textWhite"])} ${Uo("You have multiple versions of tldraw libraries installed. This can lead to bugs and unexpected behavior.",["textRed","bold"])}`,"",`The latest version you have installed is ${Uo(`v${n}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${Uo(l,["bold"])}`),"","The following libraries are not on the latest version, or have multiple versions installed:",...Array.from(o,([l,c])=>{const u=Array.from(c).sort(sC).map(h=>Uo(`v${h}`,h===n?["textGreen"]:["textRed"]));return` • ❌ ${Uo(l,["bold"])} (${u.join(", ")})`})];console.log(a.join(`
41
- `)),t.didWarn=!0;return}const s=new Map;for(const a of e)ey(s,a.name,{version:a.version,modules:[]}).modules.push(a.modules);const i=new Map;for(const[a,l]of s)l.modules.length>1&&i.set(a,l);if(i.size>0){const a=[`${Uo("[tldraw]",["bold","bgRed","textWhite"])} ${Uo("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(i,([l,c])=>{const u=c.modules.map((h,p)=>h==="esm"?` ${p+1}. ES Modules`:` ${p+1}. CommonJS`).join(`
42
- `);return` • ❌ ${Uo(l,["bold"])} v${c.version}:
43
- ${u}`}),"","You should configure your bundler to only import one version of each library."];console.log(a.join(`
44
- `)),t.didWarn=!0;return}}function sC(t,e){const n=t.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/),r=e.match(/^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/);return!n||!r?t.localeCompare(e):n[1]!==r[1]?Number(n[1])-Number(r[1]):n[2]!==r[2]?Number(n[2])-Number(r[2]):n[3]!==r[3]?Number(n[3])-Number(r[3]):n[4]&&r[4]?n[4].localeCompare(r[4]):n[4]?1:r[4]?-1:0}const Fz={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function Uo(t,e=[]){return`\x1B[${e.map(n=>Fz[n]).join(";")}m${t}\x1B[m`}function ey(t,e,n){return t.has(e)?t.get(e):(t.set(e,n),n)}var tT="Expected a function",iC=NaN,Nz="[object Symbol]",zz=/^\s+|\s+$/g,Bz=/^[-+]0x[0-9a-f]+$/i,Uz=/^0b[01]+$/i,Hz=/^0o[0-7]+$/i,Kz=parseInt,Wz=typeof cn=="object"&&cn&&cn.Object===Object&&cn,Gz=typeof self=="object"&&self&&self.Object===Object&&self,Vz=Wz||Gz||Function("return this")(),Yz=Object.prototype,Xz=Yz.toString,qz=Math.max,Zz=Math.min,ty=function(){return Vz.Date.now()};function Qz(t,e,n){var r,o,s,i,a,l,c=0,u=!1,h=!1,p=!0;if(typeof t!="function")throw new TypeError(tT);e=aC(e)||0,Jp(n)&&(u=!!n.leading,h="maxWait"in n,s=h?qz(aC(n.maxWait)||0,e):s,p="trailing"in n?!!n.trailing:p);function f(I){var T=r,_=o;return r=o=void 0,c=I,i=t.apply(_,T),i}function g(I){return c=I,a=setTimeout(S,e),u?f(I):i}function m(I){var T=I-l,_=I-c,k=e-T;return h?Zz(k,s-_):k}function v(I){var T=I-l,_=I-c;return l===void 0||T>=e||T<0||h&&_>=s}function S(){var I=ty();if(v(I))return y(I);a=setTimeout(S,m(I))}function y(I){return a=void 0,p&&r?f(I):(r=o=void 0,i)}function b(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function P(){return a===void 0?i:y(ty())}function C(){var I=ty(),T=v(I);if(r=arguments,o=this,l=I,T){if(a===void 0)return g(l);if(h)return a=setTimeout(S,e),f(l)}return a===void 0&&(a=setTimeout(S,e)),i}return C.cancel=b,C.flush=P,C}function Jz(t,e,n){var r=!0,o=!0;if(typeof t!="function")throw new TypeError(tT);return Jp(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),Qz(t,e,{leading:r,maxWait:e,trailing:o})}function Jp(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function e8(t){return!!t&&typeof t=="object"}function t8(t){return typeof t=="symbol"||e8(t)&&Xz.call(t)==Nz}function aC(t){if(typeof t=="number")return t;if(t8(t))return iC;if(Jp(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=Jp(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=t.replace(zz,"");var n=Uz.test(t);return n||Hz.test(t)?Kz(t.slice(2),n?2:8):Bz.test(t)?iC:+t}var n8=Jz;const nT=fi(n8);var r8=200,nw="__lodash_hash_undefined__",o8=1/0,s8="[object Function]",i8="[object GeneratorFunction]",a8=/[\\^$.*+?()[\]{}|]/g,l8=/^\[object .+?Constructor\]$/,c8=typeof cn=="object"&&cn&&cn.Object===Object&&cn,u8=typeof self=="object"&&self&&self.Object===Object&&self,rw=c8||u8||Function("return this")();function d8(t,e){var n=t?t.length:0;return!!n&&p8(t,e,0)>-1}function h8(t,e,n,r){for(var o=t.length,s=n+-1;++s<o;)if(e(t[s],s,t))return s;return-1}function p8(t,e,n){if(e!==e)return h8(t,f8,n);for(var r=n-1,o=t.length;++r<o;)if(t[r]===e)return r;return-1}function f8(t){return t!==t}function g8(t,e){return t.has(e)}function m8(t,e){return t==null?void 0:t[e]}function y8(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function rT(t){var e=-1,n=Array(t.size);return t.forEach(function(r){n[++e]=r}),n}var S8=Array.prototype,v8=Function.prototype,oT=Object.prototype,ny=rw["__core-js_shared__"],lC=function(){var t=/[^.]+$/.exec(ny&&ny.keys&&ny.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),sT=v8.toString,ow=oT.hasOwnProperty,x8=oT.toString,w8=RegExp("^"+sT.call(ow).replace(a8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),b8=S8.splice,P8=sw(rw,"Map"),ry=sw(rw,"Set"),Cu=sw(Object,"create");function Qi(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function C8(){this.__data__=Cu?Cu(null):{}}function _8(t){return this.has(t)&&delete this.__data__[t]}function I8(t){var e=this.__data__;if(Cu){var n=e[t];return n===nw?void 0:n}return ow.call(e,t)?e[t]:void 0}function E8(t){var e=this.__data__;return Cu?e[t]!==void 0:ow.call(e,t)}function k8(t,e){var n=this.__data__;return n[t]=Cu&&e===void 0?nw:e,this}Qi.prototype.clear=C8;Qi.prototype.delete=_8;Qi.prototype.get=I8;Qi.prototype.has=E8;Qi.prototype.set=k8;function Ll(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function T8(){this.__data__=[]}function M8(t){var e=this.__data__,n=lg(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():b8.call(e,n,1),!0}function A8(t){var e=this.__data__,n=lg(e,t);return n<0?void 0:e[n][1]}function j8(t){return lg(this.__data__,t)>-1}function O8(t,e){var n=this.__data__,r=lg(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}Ll.prototype.clear=T8;Ll.prototype.delete=M8;Ll.prototype.get=A8;Ll.prototype.has=j8;Ll.prototype.set=O8;function $l(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function D8(){this.__data__={hash:new Qi,map:new(P8||Ll),string:new Qi}}function R8(t){return cg(this,t).delete(t)}function L8(t){return cg(this,t).get(t)}function $8(t){return cg(this,t).has(t)}function F8(t,e){return cg(this,t).set(t,e),this}$l.prototype.clear=D8;$l.prototype.delete=R8;$l.prototype.get=L8;$l.prototype.has=$8;$l.prototype.set=F8;function ef(t){var e=-1,n=t?t.length:0;for(this.__data__=new $l;++e<n;)this.add(t[e])}function N8(t){return this.__data__.set(t,nw),this}function z8(t){return this.__data__.has(t)}ef.prototype.add=ef.prototype.push=N8;ef.prototype.has=z8;function lg(t,e){for(var n=t.length;n--;)if(Y8(t[n][0],e))return n;return-1}function B8(t){if(!iT(t)||W8(t))return!1;var e=X8(t)||y8(t)?w8:l8;return e.test(G8(t))}function U8(t,e,n){var r=-1,o=d8,s=t.length,i=!0,a=[],l=a;if(s>=r8){var c=H8(t);if(c)return rT(c);i=!1,o=g8,l=new ef}else l=a;e:for(;++r<s;){var u=t[r],h=u;if(u=u!==0?u:0,i&&h===h){for(var p=l.length;p--;)if(l[p]===h)continue e;a.push(u)}else o(l,h,n)||(l!==a&&l.push(h),a.push(u))}return a}var H8=ry&&1/rT(new ry([,-0]))[1]==o8?function(t){return new ry(t)}:q8;function cg(t,e){var n=t.__data__;return K8(e)?n[typeof e=="string"?"string":"hash"]:n.map}function sw(t,e){var n=m8(t,e);return B8(n)?n:void 0}function K8(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function W8(t){return!!lC&&lC in t}function G8(t){if(t!=null){try{return sT.call(t)}catch{}try{return t+""}catch{}}return""}function V8(t){return t&&t.length?U8(t):[]}function Y8(t,e){return t===e||t!==t&&e!==e}function X8(t){var e=iT(t)?x8.call(t):"";return e==s8||e==i8}function iT(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function q8(){}var Z8=V8;const Q8=fi(Z8),Dc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},J8=Dc.Good;class aT{constructor(){E(this,"startTime",0);E(this,"name","");E(this,"frames",0);E(this,"started",!1);E(this,"frame",null);E(this,"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,n=e===0?0:Math.floor(this.frames/e),r=n>55?Dc.Good:n>30?Dc.Mid:Dc.Poor,o=r===Dc.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${n}%c fps`,`color: white; background: ${J8};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${r};color: ${o};`,"font-weight: normal")}isStarted(){return this.started}}function iw(t,e){const n=[];e:for(const r of t){for(const o of n)if(e?e(r,o):r===o)continue e;n.push(r)}return n}function ye(t){return t.filter(e=>e!=null)}function Ut(t){return t[t.length-1]}function e9(t,e){let n,r=1/0;for(const o of t){const s=e(o);s<r&&(n=o,r=s)}return n}function t9(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!Object.is(t[n],e[n]))return!1;return!0}function lT(t){const e=(...n)=>{try{return t(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const _u=()=>{},Sn={ok(t){return{ok:!0,value:t}},err(t){return{ok:!1,error:t}}};function Tt(t,e){const n=e&&t&&typeof t=="object"&&e in t?t[e]:t;throw new Error(`Unknown switch case ${n}`)}const Re=lT((t,e)=>{if(!t)throw new Error(e||"Assertion Error")}),nr=lT((t,e)=>{if(t==null)throw new Error(e??"value must be defined");return t});function aw(){let t,e;const n=new Promise((r,o)=>{t=r,e=o});return Object.assign(n,{resolve:t,reject:e})}function Rv(t){return new Promise(e=>setTimeout(e,t))}function ar(...t){if(t.length===2){const[e,n]=t;n.addInitializer(function(){Re(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");const o=e.bind(this),s=Reflect.defineProperty(this,n.name,{value:o,writable:!0,configurable:!0});Re(s,"Cannot bind a non-configurable class method.")})}else{const[e,n,r]=t;if(!r||typeof r.value!="function")throw new TypeError(`Only methods can be decorated with @bind. <${n}> is not a method!`);return{configurable:!0,get(){const o=r.value.bind(this);return Object.defineProperty(this,n,{value:o,configurable:!0,writable:!0}),o}}}}class Eo{constructor(){E(this,"items",new WeakMap)}get(e,n){return this.items.has(e)||this.items.set(e,n(e)),this.items.get(e)}}function lw(t,e){let n;const r=(...o)=>(n||(n={},n.promise=new Promise((s,i)=>{n.resolve=s,n.reject=i})),clearTimeout(n.timeout),n.latestArgs=o,n.timeout=setTimeout(()=>{const s=n;n=void 0;try{s.resolve(t(...s.latestArgs))}catch(i){s.reject(i)}},e),n.promise);return r.cancel=()=>{n&&clearTimeout(n.timeout)},r}const cC=new WeakMap;function cw(t,e){if(typeof t!="object"||t===null)return;let n=cC.get(t);n||(n={tags:{},extras:{}},cC.set(t,n)),e.tags&&(n.tags={...n.tags,...e.tags}),e.extras&&(n.extras={...n.extras,...e.extras})}async function Jr(t,e){return window.fetch(t,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const Iu=(t,e)=>{const n=new window.Image(t,e);return n.referrerPolicy="strict-origin-when-cross-origin",n};class rs{static async dataUrlToArrayBuffer(e){return Jr(e).then(function(n){return n.arrayBuffer()})}static async blobToDataUrl(e){return await new Promise((n,r)=>{if(e){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((n,r)=>{if(e){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsText(e)}})}}function Lv(t){let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e+""}function uC(t){const e=new DataView(t);let n=0;for(let r=0;r<e.byteLength;r++)n=(n<<5)-n+e.getUint8(r),n|=0;return n+""}/*!
45
- * MIT License: https://github.com/ai/nanoid/blob/main/LICENSE
46
- * Modified code originally from <https://github.com/ai/nanoid>
47
- * Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
48
- *
49
- * `nanoid` is currently only distributed as an ES module. Some tools (jest, playwright) don't
50
- * properly support ESM-only code yet, and tldraw itself is distributed as both an ES module and a
51
- * CommonJS module. By including nanoid here, we can make sure it works well in every environment
52
- * where tldraw is used. We can also remove some unused features like custom alphabets.
53
- */const dC=globalThis.crypto,n9="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",r9=128;let Li,Ya;function o9(t){!Li||Li.length<t?(Li=new Uint8Array(t*r9),dC.getRandomValues(Li),Ya=0):Ya+t>Li.length&&(dC.getRandomValues(Li),Ya=0),Ya+=t}function s9(t=21){o9(t-=0);let e="";for(let n=Ya-t;n<Ya;n++)e+=n9[Li[n]&63];return e}let i9=s9;function Ke(t){return i9(t)}/*!
54
- * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
55
- * Copyright (c) Philip van Heemstra
56
- */function a9(t){const e=new Uint8Array(t);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,i,a,l,c=1024){if(!i)return-1;i=new RegExp(i,"g");const u=i.source.length,h=new TextDecoder,p=s.length;if(typeof l>"u"&&(l=p),a>=p||l<=0||a>=l)return-1;s=s.subarray(a,l);let f=-1,g=0,m=0,v="";e:for(;g<s.length;){const S=g+c,y=s.subarray(g,S),b=h.decode(y,{stream:!0}),P=v+b;let C,I=-1;for(;(C=i.exec(P))!==null;){I=C.index-v.length,f=m+I;break e}g=S,m+=b.length;const T=I>-1?I+u:b.length-u;v=b.slice(T)}return f>=0&&(f+=a>=0?a:p+a),f}const o=r(e,"IDAT",12);return o>=12?r(e,"acTL",8,o)>=8:!1}const l9=t=>new Uint8Array(t)[3]===44;/*!
57
- * MIT License
58
- * Modified code originally from <https://github.com/qzb/is-animated>
59
- * Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
60
- */function hC(t,e){let n=0;for(;t[e+n];)n+=t[e+n]+1;return n+1}function c9(t){return new TextDecoder("ascii").decode(t.slice(0,3))==="GIF"}function u9(t){const e=new Uint8Array(t);let n,r,o=0,s=0;if(!c9(t))return!1;for(n=e[10]&128,r=e[10]&7,o+=6,o+=7,o+=n?3*Math.pow(2,r+1):0;s<2&&o<e.length;)switch(e[o]){case 44:s+=1,n=e[o+9]&128,r=e[o+9]&7,o+=10,o+=n?3*Math.pow(2,r+1):0,o+=hC(e,o+1)+1;break;case 33:o+=2,o+=hC(e,o);break;case 59:o=e.length;break;default:o=e.length;break}return s>1}/*!
61
- * MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
62
- * Copyright: 2014 Alex Gorbatchev
63
- * Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
64
- */let $v=[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"&&($v=new Int32Array($v));const d9=(t,e)=>{let n=~~e^-1;for(let r=0;r<t.length;r++)n=$v[(n^t[r])&255]^n>>>8;return n^-1},pC=4,fC=4;class yo{static isPng(e,n){return e.getUint8(n+0)===137&&e.getUint8(n+1)===80&&e.getUint8(n+2)===78&&e.getUint8(n+3)===71&&e.getUint8(n+4)===13&&e.getUint8(n+5)===10&&e.getUint8(n+6)===26&&e.getUint8(n+7)===10}static getChunkType(e,n){return[String.fromCharCode(e.getUint8(n)),String.fromCharCode(e.getUint8(n+1)),String.fromCharCode(e.getUint8(n+2)),String.fromCharCode(e.getUint8(n+3))].join("")}static readChunks(e,n=0){const r={};if(!yo.isPng(e,n))throw new Error("Not a PNG");for(n+=8;n<=e.buffer.byteLength;){const o=n,s=e.getInt32(n);n+=4;const i=yo.getChunkType(e,n);if(i==="IDAT"&&r[i]){n+=s+pC+fC;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:n+4,size:s},n+=s+pC+fC}return r}static parsePhys(e,n){return{ppux:e.getUint32(n),ppuy:e.getUint32(n+4),unit:e.getUint8(n+4)}}static findChunk(e,n){return yo.readChunks(e)[n]}static setPhysChunk(e,n=1,r){let o=46,s=0;const i=yo.findChunk(e,"pHYs");i&&(o=i.start,s=i.size);const a=yo.findChunk(e,"IDAT");a&&(o=a.start,s=0);const l=new ArrayBuffer(21),c=new DataView(l);c.setUint32(0,9),c.setUint8(4,112),c.setUint8(5,72),c.setUint8(6,89),c.setUint8(7,115);const u=2835.5;c.setInt32(8,u*n),c.setInt32(12,u*n),c.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));c.setInt32(17,d9(h));const p=e.buffer.slice(0,o),f=e.buffer.slice(o+s);return new Blob([p,l,f],r)}}/*!
65
- * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
66
- * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
67
- */function h9(t){return!t||t.length<12?!1:t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80}function p9(t){const e=new Uint8Array(t);return!h9(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const cT=Object.freeze(["image/svg+xml"]),uT=Object.freeze(["image/jpeg","image/png","image/webp"]),dT=Object.freeze(["image/gif","image/apng","image/avif"]),ug=Object.freeze([...uT,...cT,...dT]),uw=Object.freeze(["video/mp4","video/webm","video/quicktime"]),f9=[...ug,...uw].join(",");class sr{static loadVideo(e){return new Promise((n,r)=>{const o=document.createElement("video");o.onloadeddata=()=>n(o),o.onerror=s=>{console.error(s),r(new Error("Could not load video"))},o.crossOrigin="anonymous",o.src=e})}static async getVideoFrameAsDataUrl(e,n=0){const r=aw();let o=!1;const s=()=>{if(!o)if(e.readyState>=e.HAVE_METADATA)o=!0,e.currentTime=n;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())}},i=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",i),e.addEventListener("stalled",i),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",i),e.removeEventListener("stalled",i)}}static loadImage(e){return new Promise((n,r)=>{const o=Iu();o.onload=()=>n(o),o.onerror=s=>{console.error(s),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.referrerPolicy="strict-origin-when-cross-origin",o.src=e})}static async getVideoSize(e){return sr.usingObjectURL(e,async n=>{const r=await sr.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const n=await sr.usingObjectURL(e,sr.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(yo.isPng(r,0)){const o=yo.findChunk(r,"pHYs");if(o){const s=yo.parsePhys(r,o.dataOffset);if(s.unit===0&&s.ppux===s.ppuy){const i=Math.max(s.ppux/2834.5,1);return{w:Math.round(n.naturalWidth/i),h:Math.round(n.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:n.naturalWidth,h:n.naturalHeight}}return{w:n.naturalWidth,h:n.naturalHeight}}static async isAnimated(e){return e.type==="image/gif"?u9(await e.arrayBuffer()):e.type==="image/avif"?l9(await e.arrayBuffer()):e.type==="image/webp"?p9(await e.arrayBuffer()):e.type==="image/apng"?a9(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return dT.includes(e||"")}static isStaticImageType(e){return uT.includes(e||"")}static isVectorImageType(e){return cT.includes(e||"")}static isImageType(e){return ug.includes(e)}static async usingObjectURL(e,n){const r=URL.createObjectURL(e);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function Ee(t,e,n){return t+(e-t)*n}function ro(t=""){let e=0,n=0,r=0,o=0;function s(){const i=e^e<<11;return e=n,n=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<t.length+64;i++)e^=t.charCodeAt(i)|0,s();return s}function Cl(t,e,n,r=!1){const[o,s]=e,[i,a]=n,l=i+(t-o)/(s-o)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function qr(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function zn(t,e){if(qr(t,e))return t[e]}function gC(t){return Object.keys(t)}function ct(t){return Object.values(t)}function Gn(t){return Object.entries(t)}function hT(t){return Object.fromEntries(t)}function Jc(t,e){const n={};let r=!1;for(const[o,s]of Gn(t))e(o,s)?n[o]=s:r=!0;return r?n:t}function Yu(t,e){const n={};for(const[r,o]of Gn(t)){const s=e(r,o);n[r]=s}return n}function pT(t,e){if(t===e)return!0;const n=new Set(Object.keys(t)),r=new Set(Object.keys(e));if(n.size!==r.size)return!1;for(const o of n)if(!r.has(o)||!Object.is(t[o],e[o]))return!1;return!0}function g9(t){const e=m9(t.chars),n=y9(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),o=S9(r,e.length);return{chars:t.chars,byChar:e.byChar,byCode:e.byCode,length:e.length,first:e.byCode[0],last:e.byCode[e.length-1],firstPositive:n.firstPositive,mostPositive:n.mostPositive,firstNegative:n.firstNegative,mostNegative:n.mostNegative,jitterRange:r,paddingDict:o}}function m9(t){const e={},n={},r=t.length;for(let o=0;o<r;o++){const s=t[o];e[o]=s,n[s]=o}return{byCode:e,byChar:n,length:r}}function y9(t,e,n,r){const o=e?t.byChar[e]:Math.ceil(t.length/2),s=n?t.byChar[n]:t.length-1,i=r?t.byChar[r]:0;if(o===void 0||s===void 0||i===void 0)throw new Error("invalid charSet");if(s-o<3)throw new Error("mostPositive must be at least 3 characters away from neutral");if(o-i<3)throw new Error("mostNegative must be at least 3 characters away from neutral");return{firstPositive:t.byCode[o],mostPositive:t.byCode[s],firstNegative:t.byCode[o-1],mostNegative:t.byCode[i]}}function S9(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var oy=null;function dw(){return oy||(oy=g9({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Ks(t,e,n){const r=n.byChar[t],o=n.byChar[e];return Math.abs(r-o)}function hw(t,e){const n=t[0];if(n>e.mostPositive||n<e.mostNegative)throw new Error("invalid firstChar on key");return n===e.mostPositive?Ks(n,e.firstPositive,e)+1+tf(t.slice(1),"positive",e):n===e.mostNegative?Ks(n,e.firstNegative,e)+1+tf(t.slice(1),"negative",e):n>=e.firstPositive?Ks(n,e.firstPositive,e)+2:Ks(n,e.firstNegative,e)+2}function tf(t,e,n){const r=t[0];if(r>n.mostPositive||r<n.mostNegative)throw new Error("invalid firstChar on key");return r===n.mostPositive&&e==="positive"?Ks(r,n.mostNegative,n)+1+tf(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Ks(r,n.mostPositive,n)+1+tf(t.slice(1),e,n):e==="positive"?Ks(r,n.mostNegative,n)+2:Ks(r,n.mostPositive,n)+2}function dg(t,e,n,r,o){const s=Math.max(t.length,e.length);return n==="start"?[t.padStart(s,r),e.padStart(s,r)]:[t.padEnd(s,r),e.padEnd(s,r)]}function v9(t,e,n){let[r,o]=dg(t,e,"end",n.first),s=Fv(r,o,n);s===1&&(r=r.padEnd(r.length+1,n.first),s=n.length);const i=mT(Math.floor(s/2),n);return pw(r,i,n)}function Fv(t,e,n){const[r,o]=dg(t,e,"end",n.first).sort(),s=fT(o,r,n);return x9(s,n)}function pw(t,e,n){const r=n.length,[o,s]=dg(t,e,"start",n.first),i=[];let a=0;for(let l=o.length-1;l>=0;l--){const c=n.byChar[o[l]],u=n.byChar[s[l]],h=c+u+a;a=Math.floor(h/r);const p=h%r;i.unshift(n.byCode[p])}return a>0&&i.unshift(n.byCode[a]),i.join("")}function fT(t,e,n){const r=n.length,[o,s]=dg(t,e,"start",n.first),i=[];let a=0;for(let l=o.length-1;l>=0;l--){let c=n.byChar[o[l]];const u=n.byChar[s[l]]+a;c<u?(a=1,c+=r):a=0;const h=c-u;i.unshift(n.byCode[h])}if(a>0)throw new Error("Subtraction result is negative. Ensure a is greater than or equal to b.");for(;i.length>1&&i[0]===n.byCode[0];)i.shift();return i.join("")}function gT(t,e){return pw(t,e.byCode[1],e)}function Nv(t,e){return fT(t,e.byCode[1],e)}function mT(t,e){if(t===0)return e.byCode[0];let n="";const r=e.length;for(;t>0;)n=e.byCode[t%r]+n,t=Math.floor(t/r);return n}function x9(t,e){let n=0;const r=t.length,o=e.length;for(let s=0;s<r;s++)n+=e.byChar[t[s]]*Math.pow(o,r-s-1);return n}function w9(t){return t.firstPositive+t.byCode[0]}function b9(t,e){return hw(t,e)===t.length}function mC(t,e){nf(t,e)}function nf(t,e){const n=vT(t,e),r=hw(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function yT(t,e){if(!b9(t,e))throw new Error("invalid integer length: "+t)}function ST(t,e){yT(t,e);const[n,r]=xT(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=gT(r,e);return n+i}const s=C9(n,e);return wT(s,"lower",e)}function P9(t,e){yT(t,e);const[n,r]=xT(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Nv(r,e);return n+i}const s=_9(n,e);return wT(s,"upper",e)}function vT(t,e){let n=0;if(t[0]===e.mostPositive)for(;t[n]===e.mostPositive;)n=n+1;if(t[0]===e.mostNegative)for(;t[n]===e.mostNegative;)n=n+1;return t.slice(0,n+1)}function xT(t,e){const n=vT(t,e),r=t.slice(n.length);return[n,r]}function C9(t,e){const n=t>=e.firstPositive,r=gT(t,e),o=t[t.length-1]===e.mostPositive,s=r[r.length-1]===e.mostPositive;return n&&s?r+e.mostNegative:!n&&o?t.slice(0,t.length-1):r}function _9(t,e){const n=t>=e.firstPositive,r=t[t.length-1]===e.mostNegative;if(n&&r){const o=t.slice(0,t.length-1);return Nv(o,e)}return!n&&r?t+e.mostPositive:Nv(t,e)}function wT(t,e,n){const r=hw(t,n),o=e==="upper"?n.byCode[n.length-1]:n.byCode[0];return t+o.repeat(r-t.length)}function bT(t,e){const n=mT(Math.floor(Math.random()*e.jitterRange),e);return pw(t,n,e)}function I9(t,e,n){const r=t.padEnd(t.length+e,n.first);return bT(r,n)}function E9(t,e,n){const r=nf(t,n),o=ST(r,n);let s=0;if(e!==null){const a=Fv(t,e,n);a<n.jitterRange+1&&(s=Math.max(s,yC(a,n)))}const i=Fv(t,o,n);return i<n.jitterRange+1&&(s=Math.max(s,yC(i,n))),s}function yC(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([o,s])=>s>n);return r?parseInt(r[0]):0}function k9(t,e,n=dw()){if(t!==null&&mC(t,n),e!==null&&mC(e,n),t===null&&e===null)return w9(n);if(t===null){const r=nf(e,n);return P9(r,n)}if(e===null){const r=nf(t,n);return ST(r,n)}if(t>=e)throw new Error(t+" >= "+e);return v9(t,e,n)}function PT(t,e,n=dw()){const r=k9(t,e,n),o=E9(r,e,n);return o?I9(r,o,n):bT(r,n)}function CT(t,e,n,r=dw()){return T9(t,e,n,r,PT,CT)}function T9(t,e,n,r,o,s){if(n===0)return[];if(n===1)return[o(t,e,r)];if(e==null){let l=o(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=o(l,e,r),c.push(l);return c}if(t==null){let l=o(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=o(t,l,r),c.push(l);return c.reverse(),c}const i=Math.floor(n/2),a=o(t,e,r);return[...s(t,a,i,r),a,...s(a,e,n-i-1,r)]}const Fl=CT,_T="a0";function M9(t){try{PT(t,null)}catch{throw new Error("invalid index: "+t)}}function _l(t,e,n){return Fl(t??null,e??null,n)}function sy(t,e){return Fl(t??null,null,e)}function Eu(t,e){return Fl(t??null,e??null,1)[0]}function vo(t=null){return Fl(t,null,1)[0]}function A9(t=null){return Fl(null,t,1)[0]}function ku(t,e="a1"){return[e,...Fl(e,null,t)]}function ln(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function j9(t,e){return t.id>e.id?1:-1}function fw(t){try{return localStorage.getItem(t)}catch{return null}}function gw(t,e){try{localStorage.setItem(t,e)}catch{}}function O9(){try{localStorage.clear()}catch{}}function IT(t){try{return sessionStorage.getItem(t)}catch{return null}}function mw(t,e){try{sessionStorage.setItem(t,e)}catch{}}function ET(t){try{sessionStorage.removeItem(t)}catch{}}function D9(){try{sessionStorage.clear()}catch{}}const R9=()=>typeof process<"u"&&!1,Xa=[],L9=60,Wh=Math.ceil(1e3/L9);let dc,iy=0,zv=0;const $9=()=>{const t=Xa.splice(0,Xa.length);for(const e of t)e()};function kT(){if(dc)return;const t=Date.now(),e=t-zv;if(iy+e<Wh){dc=requestAnimationFrame(()=>{dc=void 0,kT()});return}dc=requestAnimationFrame(()=>{dc=void 0,zv=t,iy=Math.min(iy+e-Wh,Wh*10),$9()})}let SC=!1;function TT(t){return R9()?(t(),()=>{}):(Xa.includes(t)||(Xa.push(t),SC||(SC=!0,zv=Date.now()-Wh-1),kT()),()=>{const e=Xa.indexOf(t);e>-1&&Xa.splice(e,1)})}class F9{constructor(){E(this,"timeouts",[]);E(this,"intervals",[]);E(this,"rafs",[])}setTimeout(e,n,...r){const o=window.setTimeout(e,n,r);return this.timeouts.push(o),o}setInterval(e,n,...r){const o=window.setInterval(e,n,r);return this.intervals.push(o),o}requestAnimationFrame(e){const n=window.requestAnimationFrame(e);return this.rafs.push(n),n}dispose(){this.timeouts.forEach(e=>clearTimeout(e)),this.intervals.forEach(e=>clearInterval(e)),this.rafs.forEach(e=>cancelAnimationFrame(e)),this.timeouts.length=0,this.intervals.length=0,this.rafs.length=0}}const fe=(t,e)=>{try{return new URL(t,e)}catch{return}};function N9(t){return t!==void 0}function z9(){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]:[t=>t&&JSON.parse(JSON.stringify(t)),!1]}const MT=z9(),tt=MT[0];MT[1];const B9=Object.getPrototypeOf(tt({}));Si("@tldraw/utils","3.2.0","esm");var hc=function(t){return t&&t.Math===Math&&t},Pn=hc(typeof globalThis=="object"&&globalThis)||hc(typeof window=="object"&&window)||hc(typeof self=="object"&&self)||hc(typeof cn=="object"&&cn)||hc(typeof cn=="object"&&cn)||function(){return this}()||Function("return this")(),yw={},Cn=function(t){try{return!!t()}catch{return!0}},U9=Cn,vi=!U9(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),H9=Cn,hg=!H9(function(){var t=(function(){}).bind();return typeof t!="function"||t.hasOwnProperty("prototype")}),K9=hg,Gd=Function.prototype.call,vs=K9?Gd.bind(Gd):function(){return Gd.apply(Gd,arguments)},AT={},jT={}.propertyIsEnumerable,OT=Object.getOwnPropertyDescriptor,W9=OT&&!jT.call({1:2},1);AT.f=W9?function(e){var n=OT(this,e);return!!n&&n.enumerable}:jT;var DT=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}},RT=hg,LT=Function.prototype,Bv=LT.call,G9=RT&&LT.bind.bind(Bv,Bv),Dt=RT?G9:function(t){return function(){return Bv.apply(t,arguments)}},$T=Dt,V9=$T({}.toString),Y9=$T("".slice),Nl=function(t){return Y9(V9(t),8,-1)},X9=Dt,q9=Cn,Z9=Nl,ay=Object,Q9=X9("".split),J9=q9(function(){return!ay("z").propertyIsEnumerable(0)})?function(t){return Z9(t)==="String"?Q9(t,""):ay(t)}:ay,pg=function(t){return t==null},eB=pg,tB=TypeError,zl=function(t){if(eB(t))throw new tB("Can't call method on "+t);return t},nB=J9,rB=zl,fg=function(t){return nB(rB(t))},ly=typeof document=="object"&&document.all,_n=typeof ly>"u"&&ly!==void 0?function(t){return typeof t=="function"||t===ly}:function(t){return typeof t=="function"},oB=_n,pa=function(t){return typeof t=="object"?t!==null:oB(t)},cy=Pn,sB=_n,iB=function(t){return sB(t)?t:void 0},gg=function(t,e){return arguments.length<2?iB(cy[t]):cy[t]&&cy[t][e]},aB=Dt,FT=aB({}.isPrototypeOf),lB=Pn,vC=lB.navigator,xC=vC&&vC.userAgent,cB=xC?String(xC):"",NT=Pn,uy=cB,wC=NT.process,bC=NT.Deno,PC=wC&&wC.versions||bC&&bC.version,CC=PC&&PC.v8,Kr,rf;CC&&(Kr=CC.split("."),rf=Kr[0]>0&&Kr[0]<4?1:+(Kr[0]+Kr[1]));!rf&&uy&&(Kr=uy.match(/Edge\/(\d+)/),(!Kr||Kr[1]>=74)&&(Kr=uy.match(/Chrome\/(\d+)/),Kr&&(rf=+Kr[1])));var uB=rf,_C=uB,dB=Cn,hB=Pn,pB=hB.String,zT=!!Object.getOwnPropertySymbols&&!dB(function(){var t=Symbol("symbol detection");return!pB(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&_C&&_C<41}),fB=zT,BT=fB&&!Symbol.sham&&typeof Symbol.iterator=="symbol",gB=gg,mB=_n,yB=FT,SB=BT,vB=Object,UT=SB?function(t){return typeof t=="symbol"}:function(t){var e=gB("Symbol");return mB(e)&&yB(e.prototype,vB(t))},xB=String,wB=function(t){try{return xB(t)}catch{return"Object"}},bB=_n,PB=wB,CB=TypeError,Sw=function(t){if(bB(t))return t;throw new CB(PB(t)+" is not a function")},_B=Sw,IB=pg,vw=function(t,e){var n=t[e];return IB(n)?void 0:_B(n)},dy=vs,hy=_n,py=pa,EB=TypeError,kB=function(t,e){var n,r;if(e==="string"&&hy(n=t.toString)&&!py(r=dy(n,t))||hy(n=t.valueOf)&&!py(r=dy(n,t))||e!=="string"&&hy(n=t.toString)&&!py(r=dy(n,t)))return r;throw new EB("Can't convert object to primitive value")},HT={exports:{}},IC=Pn,TB=Object.defineProperty,xw=function(t,e){try{TB(IC,t,{value:e,configurable:!0,writable:!0})}catch{IC[t]=e}return e},MB=Pn,AB=xw,EC="__core-js_shared__",kC=HT.exports=MB[EC]||AB(EC,{});(kC.versions||(kC.versions=[])).push({version:"3.38.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.1/LICENSE",source:"https://github.com/zloirock/core-js"});var ww=HT.exports,TC=ww,bw=function(t,e){return TC[t]||(TC[t]=e||{})},jB=zl,OB=Object,Xu=function(t){return OB(jB(t))},DB=Dt,RB=Xu,LB=DB({}.hasOwnProperty),xi=Object.hasOwn||function(e,n){return LB(RB(e),n)},$B=Dt,FB=0,NB=Math.random(),zB=$B(1 .toString),KT=function(t){return"Symbol("+(t===void 0?"":t)+")_"+zB(++FB+NB,36)},BB=Pn,UB=bw,MC=xi,HB=KT,KB=zT,WB=BT,qa=BB.Symbol,fy=UB("wks"),GB=WB?qa.for||qa:qa&&qa.withoutSetter||HB,xs=function(t){return MC(fy,t)||(fy[t]=KB&&MC(qa,t)?qa[t]:GB("Symbol."+t)),fy[t]},VB=vs,AC=pa,jC=UT,YB=vw,XB=kB,qB=xs,ZB=TypeError,QB=qB("toPrimitive"),JB=function(t,e){if(!AC(t)||jC(t))return t;var n=YB(t,QB),r;if(n){if(e===void 0&&(e="default"),r=VB(n,t,e),!AC(r)||jC(r))return r;throw new ZB("Can't convert object to primitive value")}return e===void 0&&(e="number"),XB(t,e)},e7=JB,t7=UT,WT=function(t){var e=e7(t,"string");return t7(e)?e:e+""},n7=Pn,OC=pa,Uv=n7.document,r7=OC(Uv)&&OC(Uv.createElement),GT=function(t){return r7?Uv.createElement(t):{}},o7=vi,s7=Cn,i7=GT,VT=!o7&&!s7(function(){return Object.defineProperty(i7("div"),"a",{get:function(){return 7}}).a!==7}),a7=vi,l7=vs,c7=AT,u7=DT,d7=fg,h7=WT,p7=xi,f7=VT,DC=Object.getOwnPropertyDescriptor;yw.f=a7?DC:function(e,n){if(e=d7(e),n=h7(n),f7)try{return DC(e,n)}catch{}if(p7(e,n))return u7(!l7(c7.f,e,n),e[n])};var Bl={},g7=vi,m7=Cn,YT=g7&&m7(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),y7=pa,S7=String,v7=TypeError,fa=function(t){if(y7(t))return t;throw new v7(S7(t)+" is not an object")},x7=vi,w7=VT,b7=YT,Vd=fa,RC=WT,P7=TypeError,gy=Object.defineProperty,C7=Object.getOwnPropertyDescriptor,my="enumerable",yy="configurable",Sy="writable";Bl.f=x7?b7?function(e,n,r){if(Vd(e),n=RC(n),Vd(r),typeof e=="function"&&n==="prototype"&&"value"in r&&Sy in r&&!r[Sy]){var o=C7(e,n);o&&o[Sy]&&(e[n]=r.value,r={configurable:yy in r?r[yy]:o[yy],enumerable:my in r?r[my]:o[my],writable:!1})}return gy(e,n,r)}:gy:function(e,n,r){if(Vd(e),n=RC(n),Vd(r),w7)try{return gy(e,n,r)}catch{}if("get"in r||"set"in r)throw new P7("Accessors not supported");return"value"in r&&(e[n]=r.value),e};var _7=vi,I7=Bl,E7=DT,Pw=_7?function(t,e,n){return I7.f(t,e,E7(1,n))}:function(t,e,n){return t[e]=n,t},XT={exports:{}},Hv=vi,k7=xi,qT=Function.prototype,T7=Hv&&Object.getOwnPropertyDescriptor,Cw=k7(qT,"name"),M7=Cw&&(function(){}).name==="something",A7=Cw&&(!Hv||Hv&&T7(qT,"name").configurable),j7={EXISTS:Cw,PROPER:M7,CONFIGURABLE:A7},O7=Dt,D7=_n,Kv=ww,R7=O7(Function.toString);D7(Kv.inspectSource)||(Kv.inspectSource=function(t){return R7(t)});var ZT=Kv.inspectSource,L7=Pn,$7=_n,LC=L7.WeakMap,F7=$7(LC)&&/native code/.test(String(LC)),N7=bw,z7=KT,$C=N7("keys"),QT=function(t){return $C[t]||($C[t]=z7(t))},_w={},B7=F7,JT=Pn,U7=pa,H7=Pw,vy=xi,xy=ww,K7=QT,W7=_w,FC="Object already initialized",Wv=JT.TypeError,G7=JT.WeakMap,of,Tu,sf,V7=function(t){return sf(t)?Tu(t):of(t,{})},Y7=function(t){return function(e){var n;if(!U7(e)||(n=Tu(e)).type!==t)throw new Wv("Incompatible receiver, "+t+" required");return n}};if(B7||xy.state){var ho=xy.state||(xy.state=new G7);ho.get=ho.get,ho.has=ho.has,ho.set=ho.set,of=function(t,e){if(ho.has(t))throw new Wv(FC);return e.facade=t,ho.set(t,e),e},Tu=function(t){return ho.get(t)||{}},sf=function(t){return ho.has(t)}}else{var ba=K7("state");W7[ba]=!0,of=function(t,e){if(vy(t,ba))throw new Wv(FC);return e.facade=t,H7(t,ba,e),e},Tu=function(t){return vy(t,ba)?t[ba]:{}},sf=function(t){return vy(t,ba)}}var eM={set:of,get:Tu,has:sf,enforce:V7,getterFor:Y7},Iw=Dt,X7=Cn,q7=_n,Yd=xi,Gv=vi,Z7=j7.CONFIGURABLE,Q7=ZT,tM=eM,J7=tM.enforce,eU=tM.get,NC=String,Gh=Object.defineProperty,tU=Iw("".slice),nU=Iw("".replace),rU=Iw([].join),oU=Gv&&!X7(function(){return Gh(function(){},"length",{value:8}).length!==8}),sU=String(String).split("String"),iU=XT.exports=function(t,e,n){tU(NC(e),0,7)==="Symbol("&&(e="["+nU(NC(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!Yd(t,"name")||Z7&&t.name!==e)&&(Gv?Gh(t,"name",{value:e,configurable:!0}):t.name=e),oU&&n&&Yd(n,"arity")&&t.length!==n.arity&&Gh(t,"length",{value:n.arity});try{n&&Yd(n,"constructor")&&n.constructor?Gv&&Gh(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch{}var r=J7(t);return Yd(r,"source")||(r.source=rU(sU,typeof e=="string"?e:"")),t};Function.prototype.toString=iU(function(){return q7(this)&&eU(this).source||Q7(this)},"toString");var aU=XT.exports,lU=_n,cU=Bl,uU=aU,dU=xw,nM=function(t,e,n,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:e;if(lU(n)&&uU(n,s,r),r.global)o?t[e]=n:dU(e,n);else{try{r.unsafe?t[e]&&(o=!0):delete t[e]}catch{}o?t[e]=n:cU.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},rM={},hU=Math.ceil,pU=Math.floor,fU=Math.trunc||function(e){var n=+e;return(n>0?pU:hU)(n)},gU=fU,ga=function(t){var e=+t;return e!==e||e===0?0:gU(e)},mU=ga,yU=Math.max,SU=Math.min,vU=function(t,e){var n=mU(t);return n<0?yU(n+e,0):SU(n,e)},xU=ga,wU=Math.min,oM=function(t){var e=xU(t);return e>0?wU(e,9007199254740991):0},bU=oM,qu=function(t){return bU(t.length)},PU=fg,CU=vU,_U=qu,zC=function(t){return function(e,n,r){var o=PU(e),s=_U(o);if(s===0)return!t&&-1;var i=CU(r,s),a;if(t&&n!==n){for(;s>i;)if(a=o[i++],a!==a)return!0}else for(;s>i;i++)if((t||i in o)&&o[i]===n)return t||i||0;return!t&&-1}},IU={includes:zC(!0),indexOf:zC(!1)},EU=Dt,wy=xi,kU=fg,TU=IU.indexOf,MU=_w,BC=EU([].push),sM=function(t,e){var n=kU(t),r=0,o=[],s;for(s in n)!wy(MU,s)&&wy(n,s)&&BC(o,s);for(;e.length>r;)wy(n,s=e[r++])&&(~TU(o,s)||BC(o,s));return o},Ew=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],AU=sM,jU=Ew,OU=jU.concat("length","prototype");rM.f=Object.getOwnPropertyNames||function(e){return AU(e,OU)};var iM={};iM.f=Object.getOwnPropertySymbols;var DU=gg,RU=Dt,LU=rM,$U=iM,FU=fa,NU=RU([].concat),zU=DU("Reflect","ownKeys")||function(e){var n=LU.f(FU(e)),r=$U.f;return r?NU(n,r(e)):n},UC=xi,BU=zU,UU=yw,HU=Bl,KU=function(t,e,n){for(var r=BU(e),o=HU.f,s=UU.f,i=0;i<r.length;i++){var a=r[i];!UC(t,a)&&!(n&&UC(n,a))&&o(t,a,s(e,a))}},WU=Cn,GU=_n,VU=/#|\.prototype\./,Zu=function(t,e){var n=XU[YU(t)];return n===ZU?!0:n===qU?!1:GU(e)?WU(e):!!e},YU=Zu.normalize=function(t){return String(t).replace(VU,".").toLowerCase()},XU=Zu.data={},qU=Zu.NATIVE="N",ZU=Zu.POLYFILL="P",QU=Zu,Xd=Pn,JU=yw.f,eH=Pw,tH=nM,nH=xw,rH=KU,oH=QU,Ul=function(t,e){var n=t.target,r=t.global,o=t.stat,s,i,a,l,c,u;if(r?i=Xd:o?i=Xd[n]||nH(n,{}):i=Xd[n]&&Xd[n].prototype,i)for(a in e){if(c=e[a],t.dontCallGetSet?(u=JU(i,a),l=u&&u.value):l=i[a],s=oH(r?a:n+(o?".":"#")+a,t.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;rH(c,l)}(t.sham||l&&l.sham)&&eH(c,"sham",!0),tH(i,a,c,t)}},aM={},sH=sM,iH=Ew,aH=Object.keys||function(e){return sH(e,iH)},lH=vi,cH=YT,uH=Bl,dH=fa,hH=fg,pH=aH;aM.f=lH&&!cH?Object.defineProperties:function(e,n){dH(e);for(var r=hH(n),o=pH(n),s=o.length,i=0,a;s>i;)uH.f(e,a=o[i++],r[a]);return e};var fH=gg,gH=fH("document","documentElement"),mH=fa,yH=aM,HC=Ew,SH=_w,vH=gH,xH=GT,wH=QT,KC=">",WC="<",Vv="prototype",Yv="script",lM=wH("IE_PROTO"),by=function(){},cM=function(t){return WC+Yv+KC+t+WC+"/"+Yv+KC},GC=function(t){t.write(cM("")),t.close();var e=t.parentWindow.Object;return t=null,e},bH=function(){var t=xH("iframe"),e="java"+Yv+":",n;return t.style.display="none",vH.appendChild(t),t.src=String(e),n=t.contentWindow.document,n.open(),n.write(cM("document.F=Object")),n.close(),n.F},qd,Vh=function(){try{qd=new ActiveXObject("htmlfile")}catch{}Vh=typeof document<"u"?document.domain&&qd?GC(qd):bH():GC(qd);for(var t=HC.length;t--;)delete Vh[Vv][HC[t]];return Vh()};SH[lM]=!0;var uM=Object.create||function(e,n){var r;return e!==null?(by[Vv]=mH(e),r=new by,by[Vv]=null,r[lM]=e):r=Vh(),n===void 0?r:yH.f(r,n)},PH=xs,CH=uM,_H=Bl.f,Xv=PH("unscopables"),qv=Array.prototype;qv[Xv]===void 0&&_H(qv,Xv,{configurable:!0,value:CH(null)});var kw=function(t){qv[Xv][t]=!0},IH=Ul,EH=Xu,kH=qu,TH=ga,MH=kw;IH({target:"Array",proto:!0},{at:function(e){var n=EH(this),r=kH(n),o=TH(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:n[s]}});MH("at");var AH=Pn,jH=Dt,Qu=function(t,e){return jH(AH[t].prototype[e])},OH=Qu;OH("Array","at");var DH=Nl,dM=Array.isArray||function(e){return DH(e)==="Array"},RH=TypeError,LH=9007199254740991,$H=function(t){if(t>LH)throw RH("Maximum allowed index exceeded");return t},FH=Nl,NH=Dt,zH=function(t){if(FH(t)==="Function")return NH(t)},VC=zH,BH=Sw,UH=hg,HH=VC(VC.bind),KH=function(t,e){return BH(t),e===void 0?t:UH?HH(t,e):function(){return t.apply(e,arguments)}},WH=dM,GH=qu,VH=$H,YH=KH,hM=function(t,e,n,r,o,s,i,a){for(var l=o,c=0,u=i?YH(i,a):!1,h,p;c<r;)c in n&&(h=u?u(n[c],c,e):n[c],s>0&&WH(h)?(p=GH(h),l=hM(t,e,h,p,l,s-1)-1):(VH(l+1),t[l]=h),l++),c++;return l},pM=hM,XH=xs,qH=XH("toStringTag"),fM={};fM[qH]="z";var ZH=String(fM)==="[object z]",QH=ZH,JH=_n,Yh=Nl,eK=xs,tK=eK("toStringTag"),nK=Object,rK=Yh(function(){return arguments}())==="Arguments",oK=function(t,e){try{return t[e]}catch{}},gM=QH?Yh:function(t){var e,n,r;return t===void 0?"Undefined":t===null?"Null":typeof(n=oK(e=nK(t),tK))=="string"?n:rK?Yh(e):(r=Yh(e))==="Object"&&JH(e.callee)?"Arguments":r},sK=Dt,iK=Cn,mM=_n,aK=gM,lK=gg,cK=ZT,yM=function(){},SM=lK("Reflect","construct"),Tw=/^\s*(?:class|function)\b/,uK=sK(Tw.exec),dK=!Tw.test(yM),pc=function(e){if(!mM(e))return!1;try{return SM(yM,[],e),!0}catch{return!1}},vM=function(e){if(!mM(e))return!1;switch(aK(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return dK||!!uK(Tw,cK(e))}catch{return!0}};vM.sham=!0;var hK=!SM||iK(function(){var t;return pc(pc.call)||!pc(Object)||!pc(function(){t=!0})||t})?vM:pc,YC=dM,pK=hK,fK=pa,gK=xs,mK=gK("species"),XC=Array,yK=function(t){var e;return YC(t)&&(e=t.constructor,pK(e)&&(e===XC||YC(e.prototype))?e=void 0:fK(e)&&(e=e[mK],e===null&&(e=void 0))),e===void 0?XC:e},SK=yK,xM=function(t,e){return new(SK(t))(e===0?0:e)},vK=Ul,xK=pM,wK=Sw,bK=Xu,PK=qu,CK=xM;vK({target:"Array",proto:!0},{flatMap:function(e){var n=bK(this),r=PK(n),o;return wK(e),o=CK(n,0),o.length=xK(o,n,n,r,0,1,e,arguments.length>1?arguments[1]:void 0),o}});var _K=kw;_K("flatMap");var IK=Qu;IK("Array","flatMap");var EK=Ul,kK=pM,TK=Xu,MK=qu,AK=ga,jK=xM;EK({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,n=TK(this),r=MK(n),o=jK(n,0);return o.length=kK(o,n,n,r,0,e===void 0?1:AK(e)),o}});var OK=kw;OK("flat");var DK=Qu;DK("Array","flat");var RK=gM,LK=String,Ju=function(t){if(RK(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return LK(t)},$K=Ul,FK=Dt,NK=zl,zK=ga,BK=Ju,UK=Cn,HK=FK("".charAt),KK=UK(function(){return"𠮷".at(-2)!=="\uD842"});$K({target:"String",proto:!0,forced:KK},{at:function(e){var n=BK(NK(this)),r=n.length,o=zK(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:HK(n,s)}});var WK=Qu;WK("String","at");var GK=fa,wM=function(){var t=GK(this),e="";return t.hasIndices&&(e+="d"),t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.unicodeSets&&(e+="v"),t.sticky&&(e+="y"),e},Mw=Cn,VK=Pn,Aw=VK.RegExp,jw=Mw(function(){var t=Aw("a","y");return t.lastIndex=2,t.exec("abcd")!==null}),YK=jw||Mw(function(){return!Aw("a","y").sticky}),XK=jw||Mw(function(){var t=Aw("^r","gy");return t.lastIndex=2,t.exec("str")!==null}),qK={BROKEN_CARET:XK,MISSED_STICKY:YK,UNSUPPORTED_Y:jw},ZK=Cn,QK=Pn,JK=QK.RegExp,eW=ZK(function(){var t=JK(".","s");return!(t.dotAll&&t.test(`
68
- `)&&t.flags==="s")}),tW=Cn,nW=Pn,rW=nW.RegExp,oW=tW(function(){var t=rW("(?<a>b)","g");return t.exec("b").groups.a!=="b"||"b".replace(t,"$<a>c")!=="bc"}),Za=vs,mg=Dt,sW=Ju,iW=wM,aW=qK,lW=bw,cW=uM,uW=eM.get,dW=eW,hW=oW,pW=lW("native-string-replace",String.prototype.replace),af=RegExp.prototype.exec,Zv=af,fW=mg("".charAt),gW=mg("".indexOf),mW=mg("".replace),Py=mg("".slice),Qv=function(){var t=/a/,e=/b*/g;return Za(af,t,"a"),Za(af,e,"a"),t.lastIndex!==0||e.lastIndex!==0}(),bM=aW.BROKEN_CARET,Jv=/()??/.exec("")[1]!==void 0,yW=Qv||Jv||bM||dW||hW;yW&&(Zv=function(e){var n=this,r=uW(n),o=sW(e),s=r.raw,i,a,l,c,u,h,p;if(s)return s.lastIndex=n.lastIndex,i=Za(Zv,s,o),n.lastIndex=s.lastIndex,i;var f=r.groups,g=bM&&n.sticky,m=Za(iW,n),v=n.source,S=0,y=o;if(g&&(m=mW(m,"y",""),gW(m,"g")===-1&&(m+="g"),y=Py(o,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&fW(o,n.lastIndex-1)!==`
69
- `)&&(v="(?: "+v+")",y=" "+y,S++),a=new RegExp("^(?:"+v+")",m)),Jv&&(a=new RegExp("^"+v+"$(?!\\s)",m)),Qv&&(l=n.lastIndex),c=Za(af,g?a:n,y),g?c?(c.input=Py(c.input,S),c[0]=Py(c[0],S),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:Qv&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),Jv&&c&&c.length>1&&Za(pW,c[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(c[u]=void 0)}),c&&f)for(c.groups=h=cW(null),u=0;u<f.length;u++)p=f[u],h[p[0]]=c[p[1]];return c});var Ow=Zv,SW=Ul,qC=Ow;SW({target:"RegExp",proto:!0,forced:/./.exec!==qC},{exec:qC});var vW=hg,PM=Function.prototype,ZC=PM.apply,QC=PM.call,xW=typeof Reflect=="object"&&Reflect.apply||(vW?QC.bind(ZC):function(){return QC.apply(ZC,arguments)}),JC=vs,e_=nM,wW=Ow,t_=Cn,CM=xs,bW=Pw,PW=CM("species"),Cy=RegExp.prototype,CW=function(t,e,n,r){var o=CM(t),s=!t_(function(){var c={};return c[o]=function(){return 7},""[t](c)!==7}),i=s&&!t_(function(){var c=!1,u=/a/;return t==="split"&&(u={},u.constructor={},u.constructor[PW]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return c=!0,null},u[o](""),!c});if(!s||!i||n){var a=/./[o],l=e(o,""[t],function(c,u,h,p,f){var g=u.exec;return g===wW||g===Cy.exec?s&&!f?{done:!0,value:JC(a,u,h,p)}:{done:!0,value:JC(c,h,u,p)}:{done:!1}});e_(String.prototype,t,l[0]),e_(Cy,o,l[1])}r&&bW(Cy[o],"sham",!0)},Dw=Dt,_W=ga,IW=Ju,EW=zl,kW=Dw("".charAt),n_=Dw("".charCodeAt),TW=Dw("".slice),r_=function(t){return function(e,n){var r=IW(EW(e)),o=_W(n),s=r.length,i,a;return o<0||o>=s?t?"":void 0:(i=n_(r,o),i<55296||i>56319||o+1===s||(a=n_(r,o+1))<56320||a>57343?t?kW(r,o):i:t?TW(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},MW={codeAt:r_(!1),charAt:r_(!0)},AW=MW.charAt,jW=function(t,e,n){return e+(n?AW(t,e).length:1)},Rw=Dt,OW=Xu,DW=Math.floor,_y=Rw("".charAt),RW=Rw("".replace),Iy=Rw("".slice),LW=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,$W=/\$([$&'`]|\d{1,2})/g,_M=function(t,e,n,r,o,s){var i=n+t.length,a=r.length,l=$W;return o!==void 0&&(o=OW(o),l=LW),RW(s,l,function(c,u){var h;switch(_y(u,0)){case"$":return"$";case"&":return t;case"`":return Iy(e,0,n);case"'":return Iy(e,i);case"<":h=o[Iy(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=DW(p/10);return f===0?c:f<=a?r[f-1]===void 0?_y(u,1):r[f-1]+_y(u,1):c}h=r[p-1]}return h===void 0?"":h})},o_=vs,FW=fa,NW=_n,zW=Nl,BW=Ow,UW=TypeError,HW=function(t,e){var n=t.exec;if(NW(n)){var r=o_(n,t,e);return r!==null&&FW(r),r}if(zW(t)==="RegExp")return o_(BW,t,e);throw new UW("RegExp#exec called on incompatible receiver")},KW=xW,s_=vs,yg=Dt,WW=CW,GW=Cn,VW=fa,YW=_n,XW=pg,qW=ga,ZW=oM,Pa=Ju,QW=zl,JW=jW,eG=vw,tG=_M,nG=HW,rG=xs,ex=rG("replace"),oG=Math.max,sG=Math.min,iG=yg([].concat),Ey=yg([].push),i_=yg("".indexOf),a_=yg("".slice),aG=function(t){return t===void 0?t:String(t)},lG=function(){return"a".replace(/./,"$0")==="$0"}(),l_=function(){return/./[ex]?/./[ex]("a","$0")==="":!1}(),cG=!GW(function(){var t=/./;return t.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(t,"$<a>")!=="7"});WW("replace",function(t,e,n){var r=l_?"$":"$0";return[function(s,i){var a=QW(this),l=XW(s)?void 0:eG(s,ex);return l?s_(l,s,a,i):s_(e,Pa(a),s,i)},function(o,s){var i=VW(this),a=Pa(o);if(typeof s=="string"&&i_(s,r)===-1&&i_(s,"$<")===-1){var l=n(e,i,a,s);if(l.done)return l.value}var c=YW(s);c||(s=Pa(s));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=nG(i,a),!(f===null||(Ey(p,f),!u));){var g=Pa(f[0]);g===""&&(i.lastIndex=JW(a,ZW(i.lastIndex),h))}for(var m="",v=0,S=0;S<p.length;S++){f=p[S];for(var y=Pa(f[0]),b=oG(sG(qW(f.index),a.length),0),P=[],C,I=1;I<f.length;I++)Ey(P,aG(f[I]));var T=f.groups;if(c){var _=iG([y],P,b,a);T!==void 0&&Ey(_,T),C=Pa(KW(s,void 0,_))}else C=tG(y,a,b,P,T,s);b>=v&&(m+=a_(a,v,b)+C,v=b+y.length)}return m+a_(a,v)}]},!cG||!lG||l_);var uG=pa,dG=Nl,hG=xs,pG=hG("match"),fG=function(t){var e;return uG(t)&&((e=t[pG])!==void 0?!!e:dG(t)==="RegExp")},gG=vs,mG=xi,yG=FT,SG=wM,c_=RegExp.prototype,vG=function(t){var e=t.flags;return e===void 0&&!("flags"in c_)&&!mG(t,"flags")&&yG(c_,t)?gG(SG,t):e},xG=Ul,wG=vs,Lw=Dt,u_=zl,bG=_n,PG=pg,CG=fG,fc=Ju,_G=vw,IG=vG,EG=_M,kG=xs,TG=kG("replace"),MG=TypeError,ky=Lw("".indexOf);Lw("".replace);var d_=Lw("".slice),AG=Math.max;xG({target:"String",proto:!0},{replaceAll:function(e,n){var r=u_(this),o,s,i,a,l,c,u,h,p,f,g=0,m="";if(!PG(e)){if(o=CG(e),o&&(s=fc(u_(IG(e))),!~ky(s,"g")))throw new MG("`.replaceAll` does not allow non-global regexes");if(i=_G(e,TG),i)return wG(i,e,r,n)}for(a=fc(r),l=fc(e),c=bG(n),c||(n=fc(n)),u=l.length,h=AG(1,u),p=ky(a,l);p!==-1;)f=c?fc(n(l,p,a)):EG(l,a,p,[],void 0,n),m+=d_(a,g,p)+f,g=p+u,p=p+h>a.length?-1:ky(a,l,p+h);return g<a.length&&(m+=d_(a,g)),m}});var jG=Qu;jG("String","replaceAll");class Xh{constructor(e){E(this,"nextValue");E(this,"diff");this.previousValue=e}get(){var r,o,s,i;const e=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,n=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(e===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(e,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(e),this.diff??(this.diff={}),n?(r=this.diff.removed)==null||r.delete(e):((o=this.diff).added??(o.added=new Set),this.diff.added.add(e))}add(e){var o,s,i;const n=this.previousValue.has(e);if(n)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(e))?this._add(e,n):void 0;(i=this.nextValue)!=null&&i.has(e)||this._add(e,n)}_remove(e,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(e),this.diff??(this.diff={}),n?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(e)):(o=this.diff.added)==null||o.delete(e)}remove(e){var o,s,i,a;const n=this.previousValue.has(e);if(!n)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(e))?this._remove(e,n):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(e)||this._remove(e,n)}}class Sg{constructor(e,n){E(this,"createDefaultProperties");E(this,"validator");E(this,"ephemeralKeys");E(this,"ephemeralKeySet");E(this,"scope");this.typeName=e,this.createDefaultProperties=n.createDefaultProperties,this.validator=n.validator??{validate:o=>o},this.scope=n.scope??"document",this.ephemeralKeys=n.ephemeralKeys;const r=new Set;if(n.ephemeralKeys)for(const[o,s]of Gn(n.ephemeralKeys))s&&r.add(o);this.ephemeralKeySet=r}create(e){const n={...this.createDefaultProperties(),id:this.createId()};for(const[r,o]of Object.entries(e))o!==void 0&&(n[r]=o);return n.typeName=this.typeName,n}clone(e){return{...tt(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??Ke())}createCustomId(e){return this.typeName+":"+e}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==null?void 0:e.typeName)===this.typeName}isId(e){if(!e)return!1;for(let n=0;n<this.typeName.length;n++)if(e[n]!==this.typeName[n])return!1;return e[this.typeName.length]===":"}withDefaultProperties(e){return new Sg(this.typeName,{createDefaultProperties:e,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(e,n){return n&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(n,e):this.validator.validate(e)}}function Do(t,e){return new Sg(t,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function lf(){return{added:{},updated:{},removed:{}}}function tx(t){const e={added:t.removed,removed:t.added,updated:{}};for(const[n,r]of Object.values(t.updated))e.updated[n.id]=[r,n];return e}function IM(t){return Object.keys(t.added).length===0&&Object.keys(t.updated).length===0&&Object.keys(t.removed).length===0}function $w(t){const e={added:{},removed:{},updated:{}};return eu(e,t),e}function eu(t,e){for(const n of e){for(const[r,o]of Gn(n.added))if(t.removed[r]){const s=t.removed[r];delete t.removed[r],s!==o&&(t.updated[r]=[s,o])}else t.added[r]=o;for(const[r,[o,s]]of Gn(n.updated)){if(t.added[r]){t.added[r]=s,delete t.updated[r],delete t.removed[r];continue}if(t.updated[r]){t.updated[r]=[t.updated[r][0],s],delete t.removed[r];continue}t.updated[r]=n.updated[r],delete t.removed[r]}for(const[r,o]of Gn(n.removed))t.added[r]?delete t.added[r]:t.updated[r]?(t.removed[r]=t.updated[r][0],delete t.updated[r]):t.removed[r]=o}}function EM(t){return t&&typeof t=="object"&&"parents"in t}function kM(t){for(let e=0,n=t.parents.length;e<n;e++)if(t.parents[e].__unsafe__getWithoutCapture(!0),t.parents[e].lastChangedEpoch!==t.parentEpochs[e])return!0;return!1}function cf(t,e){if(t.children.remove(e)&&t.children.isEmpty&&EM(t))for(let n=0,r=t.parents.length;n<r;n++)cf(t.parents[n],t)}function Fw(t,e){if(t.children.add(e)&&EM(t))for(let n=0,r=t.parents.length;n<r;n++)Fw(t.parents[n],t)}function TM(t,e){return t===e||Object.is(t,e)||!!(t&&e&&typeof t.equals=="function"&&t.equals(e))}function wi(t,e){const n=Symbol.for(`com.tldraw.state/${t}`),r=globalThis;return r[n]??(r[n]=e()),r[n]}const os=wi("empty_array",()=>Object.freeze([])),h_=8;class uf{constructor(){E(this,"arraySize",0);E(this,"array",Array(h_));E(this,"set",null)}get isEmpty(){if(this.array)return this.arraySize===0;if(this.set)return this.set.size===0;throw new Error("no set or array")}add(e){if(this.array)return this.array.indexOf(e)!==-1?!1:this.arraySize<h_?(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 n=this.array.indexOf(e);return n===-1?!1:(this.array[n]=void 0,this.arraySize--,n!==this.arraySize&&(this.array[n]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return this.set.has(e)?(this.set.delete(e),!0):!1;throw new Error("no set or array")}visit(e){if(this.array){for(let n=0;n<this.arraySize;n++){const r=this.array[n];typeof r<"u"&&e(r)}return}if(this.set){this.set.forEach(e);return}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 lr=Symbol.for("com.tldraw.state/RESET_VALUE");class MM{constructor(e){E(this,"index",0);E(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,n,r){if(r!==void 0){if(r===lr){this.clear();return}this.buffer[this.index]=[e,n,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(e){const{index:n,capacity:r,buffer:o}=this;for(let s=0;s<r;s++){const i=(n-1+r-s)%r,a=o[i];if(!a)return lr;const[l,c]=a;if(s===0&&e>=c)return[];if(l<=e&&e<c){const u=s+1,h=new Array(u);for(let p=0;p<u;p++)h[p]=o[(i+p)%r][2];return h}}return lr}}class OG{constructor(e,n){E(this,"offset",0);E(this,"maybeRemoved");this.below=e,this.child=n}}const st=wi("capture",()=>({stack:null}));function Zd(t){const e=st.stack;st.stack=null;try{return t()}finally{st.stack=e}}function AM(t){st.stack=new OG(st.stack,t),t.parentSet.clear()}function jM(){const t=st.stack;if(st.stack=t.below,t.offset<t.child.parents.length){for(let e=t.offset;e<t.child.parents.length;e++){const n=t.child.parents[e];t.child.parentSet.has(n)||cf(n,t.child)}t.child.parents.length=t.offset,t.child.parentEpochs.length=t.offset}if(t.maybeRemoved)for(let e=0;e<t.maybeRemoved.length;e++){const n=t.maybeRemoved[e];t.child.parentSet.has(n)||cf(n,t.child)}}function df(t){if(st.stack){if(st.stack.child.parentSet.has(t))return;if(st.stack.child.parentSet.add(t),st.stack.child.isActivelyListening&&Fw(t,st.stack.child),st.stack.offset<st.stack.child.parents.length){const n=st.stack.child.parents[st.stack.offset];n!==t&&(st.stack.maybeRemoved?st.stack.maybeRemoved.push(n):st.stack.maybeRemoved=[n])}st.stack.child.parents[st.stack.offset]=t,st.stack.child.parentEpochs[st.stack.offset]=t.lastChangedEpoch,st.stack.offset++}}const Ws=-1;class DG{constructor(e,n,r){E(this,"_isActivelyListening",!1);E(this,"lastTraversedEpoch",Ws);E(this,"lastReactedEpoch",Ws);E(this,"_scheduleCount",0);E(this,"parentSet",new uf);E(this,"parentEpochs",[]);E(this,"parents",[]);E(this,"_scheduleEffect");E(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=e,this.runEffect=n,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==Dn()){if(this.parents.length&&!kM(this)){this.lastReactedEpoch=Dn();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let e=0,n=this.parents.length;e<n;e++)Fw(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,n=this.parents.length;e<n;e++)cf(this.parents[e],this)}execute(){try{AM(this);const e=Dn(),n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,n}finally{jM()}}}const Hl=wi("EffectScheduler",()=>DG);function ii(t,e,n){const r=new Hl(t,e,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function RG(t,e,n){const r=new Hl(t,e,n);return{scheduler:r,start:o=>{const s=(o==null?void 0:o.force)??!1;r.attach(),s?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}class LG{constructor(e){E(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){this.isRoot?OM(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,n)=>{this.parent.initialAtomValues.has(n)||this.parent.initialAtomValues.set(n,e)})}abort(){Ue.globalEpoch++,this.initialAtomValues.forEach((e,n)=>{var r;n.set(e),(r=n.historyBuffer)==null||r.clear()}),this.commit()}}const Ue=wi("transactions",()=>({globalEpoch:Ws+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Ws+1}));function $G(){return Ue.reactionEpoch}function Dn(){return Ue.globalEpoch}function FG(){return Ue.globalIsReacting}function Nw(t,e){e.lastTraversedEpoch!==Ue.globalEpoch&&(e.lastTraversedEpoch=Ue.globalEpoch,e instanceof Hl?t.add(e):e.children.visit(n=>Nw(t,n)))}function OM(t){var e;if(Ue.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{Ue.globalIsReacting=!0,Ue.reactionEpoch=Ue.globalEpoch;const n=new Set;for(const o of t)o.children.visit(s=>Nw(n,s));for(const o of n)o.maybeScheduleEffect();let r=0;for(;(e=Ue.cleanupReactors)!=null&&e.size;){if(r++>1e3)throw new Error("Reaction update depth limit exceeded");const o=Ue.cleanupReactors;Ue.cleanupReactors=null;for(const s of o)s.maybeScheduleEffect()}}finally{Ue.cleanupReactors=null,Ue.globalIsReacting=!1}}function NG(t,e){if(Ue.globalIsReacting){const n=Ue.cleanupReactors??(Ue.cleanupReactors=new Set);t.children.visit(r=>Nw(n,r))}else Ue.currentTransaction?Ue.currentTransaction.initialAtomValues.has(t)||Ue.currentTransaction.initialAtomValues.set(t,e):OM([t])}function zG(){Ue.globalEpoch++}function BG(t){const e=new LG(Ue.currentTransaction);Ue.currentTransaction=e;try{let n,r=!1;try{n=t(()=>r=!0)}catch(o){throw e.abort(),o}return r?e.abort():e.commit(),n}finally{Ue.currentTransaction=Ue.currentTransaction.parent}}function _o(t){return Ue.currentTransaction?t():BG(t)}class UG{constructor(e,n,r){E(this,"isEqual");E(this,"computeDiff");E(this,"lastChangedEpoch",Dn());E(this,"children",new uf);E(this,"historyBuffer");this.name=e,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new MM(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return df(this),this.current}set(e,n){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,e))??TM(this.current,e))return this.current;zG(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Dn(),n??((s=this.computeDiff)==null?void 0:s.call(this,this.current,e,this.lastChangedEpoch,Dn()))??lr),this.lastChangedEpoch=Dn();const r=this.current;return this.current=e,NG(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var n;return df(this),e>=this.lastChangedEpoch?os:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??lr}}const HG=wi("Atom",()=>UG);function Mt(t,e,n){return new HG(t,e,n)}let p_=!1;function KG(){p_||(p_=!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.
70
-
71
- // Before
72
- @computed
73
- get foo() {
74
- return 'foo'
75
- }
76
-
77
- // After
78
- @computed
79
- getFoo() {
80
- return 'foo'
81
- }
82
- `))}const Rc=Symbol.for("com.tldraw.state/UNINITIALIZED");function Ki(t){return t===Rc}const nx=wi("WithDiff",()=>class{constructor(e,n){this.value=e,this.diff=n}});function Lc(t,e){return new nx(t,e)}class WG{constructor(e,n,r){E(this,"lastChangedEpoch",Ws);E(this,"lastTraversedEpoch",Ws);E(this,"lastCheckedEpoch",Ws);E(this,"parentSet",new uf);E(this,"parents",[]);E(this,"parentEpochs",[]);E(this,"children",new uf);E(this,"historyBuffer");E(this,"state",Rc);E(this,"error",null);E(this,"computeDiff");E(this,"isEqual");this.name=e,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new MM(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??TM}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var o;const n=this.lastChangedEpoch===Ws,r=Dn();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&FG()&&this.lastTraversedEpoch<$G()||!kM(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{AM(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof nx?s.value:s,a=this.state===Rc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=s instanceof nx?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Dn(),l??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,Dn()))??lr)}this.lastChangedEpoch=Dn(),this.state=i}return this.error=null,this.lastCheckedEpoch=Dn(),this.state}catch(s){if(this.state!==Rc&&(this.state=Rc,this.lastChangedEpoch=Dn()),this.lastCheckedEpoch=Dn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!e)throw s;return this.state}finally{jM()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{df(this)}}getDiffSince(e){var n;return this.__unsafe__getWithoutCapture(!0),df(this),e>=this.lastChangedEpoch?os:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??lr}}const vg=wi("Computed",()=>WG);function GG(t={},e,n,r){const o=r.value,s=Symbol.for("__@tldraw/state__computed__"+n);return r.value=function(){let i=this[s];return i||(i=new vg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[DM]=!0,r}function VG(t={},e,n,r){const o=r.get,s=Symbol.for("__@tldraw/state__computed__"+n);return r.get=function(){let i=this[s];return i||(i=new vg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function YG(t,e,n){Re(n.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(n.name)),o=function(){let s=this[r];return s||(s=new vg(String(n.name),e.bind(this),t),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:s})),s.get()};return o[DM]=!0,o}function f_(t={},e){if(e.length===2){const[n,r]=e;return YG(t,n,r)}else{const[n,r,o]=e;return o.get?(KG(),VG(t,n,r,o)):GG(t,n,r,o)}}const DM="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const t=arguments[0];return(...e)=>f_(t,e)}else return typeof arguments[0]=="string"?new vg(arguments[0],arguments[1],arguments[2]):f_(void 0,arguments)}const RM=1,XG=wi("apiVersion",()=>RM);if(XG!==RM)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");Si("@tldraw/state","3.2.0","esm");var hf={exports:{}};hf.exports;(function(t,e){var n=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",p="[object Error]",f="[object Function]",g="[object GeneratorFunction]",m="[object Map]",v="[object Number]",S="[object Null]",y="[object Object]",b="[object Promise]",P="[object Proxy]",C="[object RegExp]",I="[object Set]",T="[object String]",_="[object Symbol]",k="[object Undefined]",M="[object WeakMap]",R="[object ArrayBuffer]",j="[object DataView]",O="[object Float32Array]",D="[object Float64Array]",B="[object Int8Array]",z="[object Int16Array]",K="[object Int32Array]",N="[object Uint8Array]",H="[object Uint8ClampedArray]",Y="[object Uint16Array]",ee="[object Uint32Array]",ce=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,Te=/^(?:0|[1-9]\d*)$/,se={};se[O]=se[D]=se[B]=se[z]=se[K]=se[N]=se[H]=se[Y]=se[ee]=!0,se[a]=se[l]=se[R]=se[u]=se[j]=se[h]=se[p]=se[f]=se[m]=se[v]=se[y]=se[C]=se[I]=se[T]=se[M]=!1;var We=typeof cn=="object"&&cn&&cn.Object===Object&&cn,$e=typeof self=="object"&&self&&self.Object===Object&&self,ot=We||$e||Function("return this")(),Le=e&&!e.nodeType&&e,at=Le&&!0&&t&&!t.nodeType&&t,Be=at&&at.exports===Le,Zn=Be&&We.process,$t=function(){try{return Zn&&Zn.binding&&Zn.binding("util")}catch{}}(),Mn=$t&&$t.isTypedArray;function yt(A,L){for(var V=-1,ne=A==null?0:A.length,Qe=0,Se=[];++V<ne;){var gt=A[V];L(gt,V,A)&&(Se[Qe++]=gt)}return Se}function Qt(A,L){for(var V=-1,ne=L.length,Qe=A.length;++V<ne;)A[Qe+V]=L[V];return A}function No(A,L){for(var V=-1,ne=A==null?0:A.length;++V<ne;)if(L(A[V],V,A))return!0;return!1}function Ql(A,L){for(var V=-1,ne=Array(A);++V<A;)ne[V]=L(V);return ne}function _s(A){return function(L){return A(L)}}function t4(A,L){return A.has(L)}function n4(A,L){return A==null?void 0:A[L]}function r4(A){var L=-1,V=Array(A.size);return A.forEach(function(ne,Qe){V[++L]=[Qe,ne]}),V}function o4(A,L){return function(V){return A(L(V))}}function s4(A){var L=-1,V=Array(A.size);return A.forEach(function(ne){V[++L]=ne}),V}var i4=Array.prototype,a4=Function.prototype,wd=Object.prototype,xm=ot["__core-js_shared__"],Ab=a4.toString,co=wd.hasOwnProperty,jb=function(){var A=/[^.]+$/.exec(xm&&xm.keys&&xm.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),Ob=wd.toString,l4=RegExp("^"+Ab.call(co).replace(ce,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Db=Be?ot.Buffer:void 0,bd=ot.Symbol,Rb=ot.Uint8Array,Lb=wd.propertyIsEnumerable,c4=i4.splice,Ei=bd?bd.toStringTag:void 0,$b=Object.getOwnPropertySymbols,u4=Db?Db.isBuffer:void 0,d4=o4(Object.keys,Object),wm=xa(ot,"DataView"),Jl=xa(ot,"Map"),bm=xa(ot,"Promise"),Pm=xa(ot,"Set"),Cm=xa(ot,"WeakMap"),ec=xa(Object,"create"),h4=Mi(wm),p4=Mi(Jl),f4=Mi(bm),g4=Mi(Pm),m4=Mi(Cm),Fb=bd?bd.prototype:void 0,_m=Fb?Fb.valueOf:void 0;function ki(A){var L=-1,V=A==null?0:A.length;for(this.clear();++L<V;){var ne=A[L];this.set(ne[0],ne[1])}}function y4(){this.__data__=ec?ec(null):{},this.size=0}function S4(A){var L=this.has(A)&&delete this.__data__[A];return this.size-=L?1:0,L}function v4(A){var L=this.__data__;if(ec){var V=L[A];return V===r?void 0:V}return co.call(L,A)?L[A]:void 0}function x4(A){var L=this.__data__;return ec?L[A]!==void 0:co.call(L,A)}function w4(A,L){var V=this.__data__;return this.size+=this.has(A)?0:1,V[A]=ec&&L===void 0?r:L,this}ki.prototype.clear=y4,ki.prototype.delete=S4,ki.prototype.get=v4,ki.prototype.has=x4,ki.prototype.set=w4;function zo(A){var L=-1,V=A==null?0:A.length;for(this.clear();++L<V;){var ne=A[L];this.set(ne[0],ne[1])}}function b4(){this.__data__=[],this.size=0}function P4(A){var L=this.__data__,V=Cd(L,A);if(V<0)return!1;var ne=L.length-1;return V==ne?L.pop():c4.call(L,V,1),--this.size,!0}function C4(A){var L=this.__data__,V=Cd(L,A);return V<0?void 0:L[V][1]}function _4(A){return Cd(this.__data__,A)>-1}function I4(A,L){var V=this.__data__,ne=Cd(V,A);return ne<0?(++this.size,V.push([A,L])):V[ne][1]=L,this}zo.prototype.clear=b4,zo.prototype.delete=P4,zo.prototype.get=C4,zo.prototype.has=_4,zo.prototype.set=I4;function Ti(A){var L=-1,V=A==null?0:A.length;for(this.clear();++L<V;){var ne=A[L];this.set(ne[0],ne[1])}}function E4(){this.size=0,this.__data__={hash:new ki,map:new(Jl||zo),string:new ki}}function k4(A){var L=_d(this,A).delete(A);return this.size-=L?1:0,L}function T4(A){return _d(this,A).get(A)}function M4(A){return _d(this,A).has(A)}function A4(A,L){var V=_d(this,A),ne=V.size;return V.set(A,L),this.size+=V.size==ne?0:1,this}Ti.prototype.clear=E4,Ti.prototype.delete=k4,Ti.prototype.get=T4,Ti.prototype.has=M4,Ti.prototype.set=A4;function Pd(A){var L=-1,V=A==null?0:A.length;for(this.__data__=new Ti;++L<V;)this.add(A[L])}function j4(A){return this.__data__.set(A,r),this}function O4(A){return this.__data__.has(A)}Pd.prototype.add=Pd.prototype.push=j4,Pd.prototype.has=O4;function Is(A){var L=this.__data__=new zo(A);this.size=L.size}function D4(){this.__data__=new zo,this.size=0}function R4(A){var L=this.__data__,V=L.delete(A);return this.size=L.size,V}function L4(A){return this.__data__.get(A)}function $4(A){return this.__data__.has(A)}function F4(A,L){var V=this.__data__;if(V instanceof zo){var ne=V.__data__;if(!Jl||ne.length<n-1)return ne.push([A,L]),this.size=++V.size,this;V=this.__data__=new Ti(ne)}return V.set(A,L),this.size=V.size,this}Is.prototype.clear=D4,Is.prototype.delete=R4,Is.prototype.get=L4,Is.prototype.has=$4,Is.prototype.set=F4;function N4(A,L){var V=Id(A),ne=!V&&eN(A),Qe=!V&&!ne&&Im(A),Se=!V&&!ne&&!Qe&&Vb(A),gt=V||ne||Qe||Se,Et=gt?Ql(A.length,String):[],Ft=Et.length;for(var lt in A)co.call(A,lt)&&!(gt&&(lt=="length"||Qe&&(lt=="offset"||lt=="parent")||Se&&(lt=="buffer"||lt=="byteLength"||lt=="byteOffset")||X4(lt,Ft)))&&Et.push(lt);return Et}function Cd(A,L){for(var V=A.length;V--;)if(Hb(A[V][0],L))return V;return-1}function z4(A,L,V){var ne=L(A);return Id(A)?ne:Qt(ne,V(A))}function tc(A){return A==null?A===void 0?k:S:Ei&&Ei in Object(A)?V4(A):J4(A)}function Nb(A){return nc(A)&&tc(A)==a}function zb(A,L,V,ne,Qe){return A===L?!0:A==null||L==null||!nc(A)&&!nc(L)?A!==A&&L!==L:B4(A,L,V,ne,zb,Qe)}function B4(A,L,V,ne,Qe,Se){var gt=Id(A),Et=Id(L),Ft=gt?l:Es(A),lt=Et?l:Es(L);Ft=Ft==a?y:Ft,lt=lt==a?y:lt;var Qn=Ft==y,Fr=lt==y,Jt=Ft==lt;if(Jt&&Im(A)){if(!Im(L))return!1;gt=!0,Qn=!1}if(Jt&&!Qn)return Se||(Se=new Is),gt||Vb(A)?Bb(A,L,V,ne,Qe,Se):W4(A,L,Ft,V,ne,Qe,Se);if(!(V&o)){var xr=Qn&&co.call(A,"__wrapped__"),wr=Fr&&co.call(L,"__wrapped__");if(xr||wr){var ks=xr?A.value():A,Bo=wr?L.value():L;return Se||(Se=new Is),Qe(ks,Bo,V,ne,Se)}}return Jt?(Se||(Se=new Is),G4(A,L,V,ne,Qe,Se)):!1}function U4(A){if(!Gb(A)||Z4(A))return!1;var L=Kb(A)?l4:ge;return L.test(Mi(A))}function H4(A){return nc(A)&&Wb(A.length)&&!!se[tc(A)]}function K4(A){if(!Q4(A))return d4(A);var L=[];for(var V in Object(A))co.call(A,V)&&V!="constructor"&&L.push(V);return L}function Bb(A,L,V,ne,Qe,Se){var gt=V&o,Et=A.length,Ft=L.length;if(Et!=Ft&&!(gt&&Ft>Et))return!1;var lt=Se.get(A);if(lt&&Se.get(L))return lt==L;var Qn=-1,Fr=!0,Jt=V&s?new Pd:void 0;for(Se.set(A,L),Se.set(L,A);++Qn<Et;){var xr=A[Qn],wr=L[Qn];if(ne)var ks=gt?ne(wr,xr,Qn,L,A,Se):ne(xr,wr,Qn,A,L,Se);if(ks!==void 0){if(ks)continue;Fr=!1;break}if(Jt){if(!No(L,function(Bo,Ai){if(!t4(Jt,Ai)&&(xr===Bo||Qe(xr,Bo,V,ne,Se)))return Jt.push(Ai)})){Fr=!1;break}}else if(!(xr===wr||Qe(xr,wr,V,ne,Se))){Fr=!1;break}}return Se.delete(A),Se.delete(L),Fr}function W4(A,L,V,ne,Qe,Se,gt){switch(V){case j:if(A.byteLength!=L.byteLength||A.byteOffset!=L.byteOffset)return!1;A=A.buffer,L=L.buffer;case R:return!(A.byteLength!=L.byteLength||!Se(new Rb(A),new Rb(L)));case u:case h:case v:return Hb(+A,+L);case p:return A.name==L.name&&A.message==L.message;case C:case T:return A==L+"";case m:var Et=r4;case I:var Ft=ne&o;if(Et||(Et=s4),A.size!=L.size&&!Ft)return!1;var lt=gt.get(A);if(lt)return lt==L;ne|=s,gt.set(A,L);var Qn=Bb(Et(A),Et(L),ne,Qe,Se,gt);return gt.delete(A),Qn;case _:if(_m)return _m.call(A)==_m.call(L)}return!1}function G4(A,L,V,ne,Qe,Se){var gt=V&o,Et=Ub(A),Ft=Et.length,lt=Ub(L),Qn=lt.length;if(Ft!=Qn&&!gt)return!1;for(var Fr=Ft;Fr--;){var Jt=Et[Fr];if(!(gt?Jt in L:co.call(L,Jt)))return!1}var xr=Se.get(A);if(xr&&Se.get(L))return xr==L;var wr=!0;Se.set(A,L),Se.set(L,A);for(var ks=gt;++Fr<Ft;){Jt=Et[Fr];var Bo=A[Jt],Ai=L[Jt];if(ne)var Yb=gt?ne(Ai,Bo,Jt,L,A,Se):ne(Bo,Ai,Jt,A,L,Se);if(!(Yb===void 0?Bo===Ai||Qe(Bo,Ai,V,ne,Se):Yb)){wr=!1;break}ks||(ks=Jt=="constructor")}if(wr&&!ks){var Ed=A.constructor,kd=L.constructor;Ed!=kd&&"constructor"in A&&"constructor"in L&&!(typeof Ed=="function"&&Ed instanceof Ed&&typeof kd=="function"&&kd instanceof kd)&&(wr=!1)}return Se.delete(A),Se.delete(L),wr}function Ub(A){return z4(A,rN,Y4)}function _d(A,L){var V=A.__data__;return q4(L)?V[typeof L=="string"?"string":"hash"]:V.map}function xa(A,L){var V=n4(A,L);return U4(V)?V:void 0}function V4(A){var L=co.call(A,Ei),V=A[Ei];try{A[Ei]=void 0;var ne=!0}catch{}var Qe=Ob.call(A);return ne&&(L?A[Ei]=V:delete A[Ei]),Qe}var Y4=$b?function(A){return A==null?[]:(A=Object(A),yt($b(A),function(L){return Lb.call(A,L)}))}:oN,Es=tc;(wm&&Es(new wm(new ArrayBuffer(1)))!=j||Jl&&Es(new Jl)!=m||bm&&Es(bm.resolve())!=b||Pm&&Es(new Pm)!=I||Cm&&Es(new Cm)!=M)&&(Es=function(A){var L=tc(A),V=L==y?A.constructor:void 0,ne=V?Mi(V):"";if(ne)switch(ne){case h4:return j;case p4:return m;case f4:return b;case g4:return I;case m4:return M}return L});function X4(A,L){return L=L??i,!!L&&(typeof A=="number"||Te.test(A))&&A>-1&&A%1==0&&A<L}function q4(A){var L=typeof A;return L=="string"||L=="number"||L=="symbol"||L=="boolean"?A!=="__proto__":A===null}function Z4(A){return!!jb&&jb in A}function Q4(A){var L=A&&A.constructor,V=typeof L=="function"&&L.prototype||wd;return A===V}function J4(A){return Ob.call(A)}function Mi(A){if(A!=null){try{return Ab.call(A)}catch{}try{return A+""}catch{}}return""}function Hb(A,L){return A===L||A!==A&&L!==L}var eN=Nb(function(){return arguments}())?Nb:function(A){return nc(A)&&co.call(A,"callee")&&!Lb.call(A,"callee")},Id=Array.isArray;function tN(A){return A!=null&&Wb(A.length)&&!Kb(A)}var Im=u4||sN;function nN(A,L){return zb(A,L)}function Kb(A){if(!Gb(A))return!1;var L=tc(A);return L==f||L==g||L==c||L==P}function Wb(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function Gb(A){var L=typeof A;return A!=null&&(L=="object"||L=="function")}function nc(A){return A!=null&&typeof A=="object"}var Vb=Mn?_s(Mn):H4;function rN(A){return tN(A)?N4(A):K4(A)}function oN(){return[]}function sN(){return!1}t.exports=nN})(hf,hf.exports);var qG=hf.exports;const ZG=fi(qG);function QG(t){if(t.length===0)return new Set;const e=t[0],n=t.slice(1),r=new Set;for(const o of e)n.every(s=>s.has(o))&&r.add(o);return r}function JG(t,e){const n={};for(const r of e)t.has(r)||(n.added??(n.added=new Set),n.added.add(r));for(const r of t)e.has(r)||(n.removed??(n.removed=new Set),n.removed.add(r));return n.added||n.removed?n:void 0}function g_(t,e){for(const[n,r]of Object.entries(t)){const o=r,s=e[n];if("eq"in o&&s!==o.eq||"neq"in o&&s===o.neq||"gt"in o&&(typeof s!="number"||s<=o.gt))return!1}return!0}function m_(t,e,n){const r=Object.fromEntries(Object.keys(n).map(o=>[o,new Set]));for(const[o,s]of Object.entries(n))if("eq"in s){const a=t.index(e,o).get().get(s.eq);if(a)for(const l of a)r[o].add(l)}else if("neq"in s){const i=t.index(e,o);for(const[a,l]of i.get())if(a!==s.neq)for(const c of l)r[o].add(c)}else if("gt"in s){const i=t.index(e,o);for(const[a,l]of i.get())if(a>s.gt)for(const c of l)r[o].add(c)}return QG(Object.values(r))}class eV{constructor(e,n){E(this,"indexCache",new Map);E(this,"historyCache",new Map);this.atoms=e,this.history=n}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const n=G("filterHistory:"+e,(r,o)=>{if(Ki(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===lr)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of s){for(const h of ct(u.added))if(h.typeName===e)if(i.removed[h.id]){const p=i.removed[h.id];delete i.removed[h.id],l--,p!==h&&(i.updated[h.id]=[p,h],c++)}else i.added[h.id]=h,a++;for(const[h,p]of ct(u.updated))p.typeName===e&&(i.added[p.id]?i.added[p.id]=p:i.updated[p.id]?i.updated[p.id]=[i.updated[p.id][0],p]:(i.updated[p.id]=[h,p],c++));for(const h of ct(u.removed))h.typeName===e&&(i.added[h.id]?(delete i.added[h.id],a--):i.updated[h.id]?(i.removed[h.id]=i.updated[h.id][0],delete i.updated[h.id],c--,l++):(i.removed[h.id]=h,l++))}return a||l||c?Lc(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(e,n),n}index(e,n){const r=e+":"+n;if(this.indexCache.has(r))return this.indexCache.get(r);const o=this.__uncached_createIndex(e,n);return this.indexCache.set(r,o),o}__uncached_createIndex(e,n){const r=this.filterHistory(e),o=()=>{r.get();const s=new Map;for(const i of ct(this.atoms.get())){const a=i.get();if(a.typeName===e){const l=a[n];s.has(l)||s.set(l,new Set),s.get(l).add(a.id)}}return s};return G("index:"+e+":"+n,(s,i)=>{if(Ki(s))return o();const a=r.getDiffSince(i);if(a===lr)return o();const l=new Map,c=(f,g)=>{let m=l.get(f);m||(m=new Xh(s.get(f)??new Set)),m.add(g),l.set(f,m)},u=(f,g)=>{let m=l.get(f);m||(m=new Xh(s.get(f)??new Set)),m.remove(g),l.set(f,m)};for(const f of a){for(const g of ct(f.added))if(g.typeName===e){const m=g[n];c(m,g.id)}for(const[g,m]of ct(f.updated))if(m.typeName===e){const v=g[n],S=m[n];v!==S&&(u(v,m.id),c(S,m.id))}for(const g of ct(f.removed))if(g.typeName===e){const m=g[n];u(m,g.id)}}let h,p;for(const[f,g]of l){const m=g.get();m&&(h||(h=new Map(s)),p||(p=new Map),m.value.size===0?h.delete(f):h.set(f,m.value),p.set(f,m.diff))}return h&&p?Lc(h,p):s},{historyLength:100})}record(e,n=()=>({}),r="record:"+e+(n?":"+n.toString():"")){const o=this.ids(e,n,r);return G(r,()=>{var s;for(const i of o.get())return(s=this.atoms.get()[i])==null?void 0:s.get()})}records(e,n=()=>({}),r="records:"+e+(n?":"+n.toString():"")){const o=this.ids(e,n,"ids:"+r);return G(r,()=>[...o.get()].map(s=>{const i=this.atoms.get()[s];if(!i)throw new Error("no atom found for record id: "+s);return i.get()}))}ids(e,n=()=>({}),r="ids:"+e+(n?":"+n.toString():"")){const o=this.filterHistory(e),s=()=>{o.get();const l=n();return Object.keys(l).length===0?new Set(ct(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===e?u.id:[]})):m_(this,e,l)},i=l=>{const c=s(),u=JG(l,c);return u?Lc(c,u):l},a=G("ids_query:"+r,n,{isEqual:ZG});return G("query:"+r,(l,c)=>{const u=a.get();if(Ki(l))return s();if(c<a.lastChangedEpoch)return i(l);const h=o.getDiffSince(c);if(h===lr)return i(l);const p=new Xh(l);for(const g of h){for(const m of ct(g.added))m.typeName===e&&g_(u,m)&&p.add(m.id);for(const[m,v]of ct(g.updated))v.typeName===e&&(g_(u,v)?p.add(v.id):p.remove(v.id));for(const m of ct(g.removed))m.typeName===e&&p.remove(m.id)}const f=p.get();return f?Lc(f.value,f.diff):l},{historyLength:50})}exec(e,n){const r=m_(this,e,n);if(r.size===0)return os;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class tV{constructor(e){E(this,"_beforeCreateHandlers",{});E(this,"_afterCreateHandlers",{});E(this,"_beforeChangeHandlers",{});E(this,"_afterChangeHandlers",{});E(this,"_beforeDeleteHandlers",{});E(this,"_afterDeleteHandlers",{});E(this,"_operationCompleteHandlers",[]);E(this,"_isEnabled",!0);this.store=e}isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,n){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let o=e;for(const s of r)o=s(o,n);return o}return e}handleAfterCreate(e,n){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const o of r)o(e,n)}handleBeforeChange(e,n,r){if(!this._isEnabled)return n;const o=this._beforeChangeHandlers[n.typeName];if(o){let s=n;for(const i of o)s=i(e,s,r);return s}return n}handleAfterChange(e,n,r){if(!this._isEnabled)return;const o=this._afterChangeHandlers[n.typeName];if(o)for(const s of o)s(e,n,r)}handleBeforeDelete(e,n){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const o of r)if(o(e,n)===!1)return!1}return!0}handleAfterDelete(e,n){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const o of r)o(e,n)}handleOperationComplete(e){if(this._isEnabled)for(const n of this._operationCompleteHandlers)n(e)}register(e){const n=[];for(const[r,o]of Object.entries(e))o!=null&&o.beforeCreate&&n.push(this.registerBeforeCreateHandler(r,o.beforeCreate)),o!=null&&o.afterCreate&&n.push(this.registerAfterCreateHandler(r,o.afterCreate)),o!=null&&o.beforeChange&&n.push(this.registerBeforeChangeHandler(r,o.beforeChange)),o!=null&&o.afterChange&&n.push(this.registerAfterChangeHandler(r,o.afterChange)),o!=null&&o.beforeDelete&&n.push(this.registerBeforeDeleteHandler(r,o.beforeDelete)),o!=null&&o.afterDelete&&n.push(this.registerAfterDeleteHandler(r,o.afterDelete));return()=>{for(const r of n)r()}}registerBeforeCreateHandler(e,n){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(n),()=>ji(this._beforeCreateHandlers[e],n)}registerAfterCreateHandler(e,n){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(n),()=>ji(this._afterCreateHandlers[e],n)}registerBeforeChangeHandler(e,n){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(n),()=>ji(this._beforeChangeHandlers[e],n)}registerAfterChangeHandler(e,n){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(n),()=>ji(this._afterChangeHandlers[e],n)}registerBeforeDeleteHandler(e,n){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(n),()=>ji(this._beforeDeleteHandlers[e],n)}registerAfterDeleteHandler(e,n){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(n),()=>ji(this._afterDeleteHandlers[e],n)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>ji(this._operationCompleteHandlers,e)}}function ji(t,e){const n=t.indexOf(e);n>=0&&t.splice(n,1)}class zw{constructor(e){E(this,"id");E(this,"atoms",Mt("store_atoms",{}));E(this,"history",Mt("history",0,{historyLength:1e3}));E(this,"query",new eV(this.atoms,this.history));E(this,"listeners",new Set);E(this,"historyAccumulator",new rV);E(this,"historyReactor");E(this,"schema");E(this,"props");E(this,"scopedTypes");E(this,"sideEffects",new tV(this));E(this,"isMergingRemoteChanges",!1);E(this,"_integrityChecker");E(this,"_isPossiblyCorrupted",!1);E(this,"pendingAfterEvents",null);E(this,"_isInAtomicOp",!1);const{initialData:n,schema:r,id:o}=e;this.id=o??Ke(),this.schema=r,this.props=e.props,n&&this.atoms.set(hT(Gn(n).map(([s,i])=>[s,Mt("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=RG("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=TT(s)}),this.scopedTypes={document:new Set(ct(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(ct(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(ct(this.schema.types).filter(s=>s.scope==="presence").map(s=>s.typeName))}}cancelHistoryReactor(){}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:n,source:r}of e){let o=null,s=null,i=null;for(const{onHistory:a,filters:l}of this.listeners)if(!(l.source!=="all"&&l.source!==r))if(l.scope!=="all")if(l.scope==="document"){if(s??(s=this.filterChangesByScope(n,"document")),!s)continue;a({changes:s,source:r})}else if(l.scope==="session"){if(o??(o=this.filterChangesByScope(n,"session")),!o)continue;a({changes:o,source:r})}else{if(i??(i=this.filterChangesByScope(n,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:n,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,n){const r={added:Jc(e.added,(o,s)=>this.scopedTypes[n].has(s.typeName)),updated:Jc(e.updated,(o,s)=>this.scopedTypes[n].has(s[1].typeName)),removed:Jc(e.removed,(o,s)=>this.scopedTypes[n].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(n=>this.schema.validateRecord(this,n,e,null))}put(e,n){this.atomic(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.isMergingRemoteChanges?"remote":"user";for(let u=0,h=e.length;u<h;u++){a=e[u];const p=(i??s)[a.id];if(p){const f=p.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(f,a,c),this.schema.validateRecord(this,a,n??"updateRecord",f)===f)continue;p.set(a),l=!0;const m=p.__unsafe__getWithoutCapture();r[a.id]=[f,m],this.addDiffForAfterEvent(f,m)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),o[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...s}),i[a.id]=Mt("atom:"+a.id,a)}i&&this.atoms.set(i),l&&this.updateHistory({added:o,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const n=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const s of e){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&n.add(s)}let o;this.atoms.update(s=>{let i;for(const a of e){if(n.has(a)||!(a in s))continue;i||(i={...s}),o||(o={}),delete i[a];const l=s[a].get();o[a]=l,this.addDiffForAfterEvent(l,null)}return i??s}),o&&this.updateHistory({added:{},updated:{},removed:o})})}get(e){var n;return(n=this.atoms.get()[e])==null?void 0:n.get()}unsafeGetWithoutCapture(e){var n;return(n=this.atoms.__unsafe__getWithoutCapture()[e])==null?void 0:n.__unsafe__getWithoutCapture()}serialize(e="document"){const n={};for(const[r,o]of Gn(this.atoms.get())){const s=o.get();(e==="all"||this.scopedTypes[e].has(s.typeName))&&(n[r]=s)}return n}getStoreSnapshot(e="document"){return{store:this.serialize(e),schema:this.schema.serialize()}}getSnapshot(e="document"){return console.warn("[tldraw] `Store.getSnapshot` is deprecated and will be removed in a future release. Use `getSnapshot` from the `tldraw` package instead."),this.getStoreSnapshot(e)}migrateSnapshot(e){const n=this.schema.migrateStoreSnapshot(e);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);return{store:n.value,schema:this.schema.serialize()}}loadStoreSnapshot(e){const n=this.schema.migrateStoreSnapshot(e);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(n.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}loadSnapshot(e){console.warn("[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead."),this.loadStoreSnapshot(e)}allRecords(){return ct(this.atoms.get()).map(e=>e.get())}clear(){this.remove(gC(this.atoms.get()))}update(e,n){const r=this.atoms.get()[e];if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])}has(e){return!!this.atoms.get()[e]}listen(e,n){this._flushHistory();const r={onHistory:e,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.listeners.add(r),this.historyReactor.scheduler.isActivelyListening||this.historyReactor.start(),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,_o(e)}finally{this.isMergingRemoteChanges=!1}}extractingChanges(e){const n=[],r=this.historyAccumulator.addInterceptor(o=>n.push(o.changes));try{return _o(e),$w(n)}finally{r()}}applyDiff(e,{runCallbacks:n=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const o=ct(e.added);for(const[i,a]of ct(e.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){o.push(a);continue}let u=null;for(const[h,p]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(p,zn(c,h))||(u||(u={...c}),u[h]=p);u&&o.push(u)}else o.push(a)}const s=gC(e.removed);o.length&&this.put(o),s.length&&this.remove(s)},n)}createComputedCache(e,n,r){const o=new Eo;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=r?G(i.name+":equals",()=>i.get(),{isEqual:r}):i;return G(e+":"+s,()=>n(a.get()))}).get()}}}createSelectedComputedCache(e,n,r){const o=new Eo;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=G(e+":"+s+":selector",()=>n(i.get()));return G(e+":"+s,()=>r(a.get()))}).get()}}}ensureStoreIsUsable(){this.atomic(()=>{var e;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(e=this._integrityChecker)==null||e.call(this)})}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}addDiffForAfterEvent(e,n){if(Re(this.pendingAfterEvents,"must be in event operation"),e===n||(e&&n&&Re(e.id===n.id),!e&&!n))return;const r=(e||n).id,o=this.pendingAfterEvents.get(r);o?o.after=n:this.pendingAfterEvents.set(r,{before:e,after:n})}flushAtomicCallbacks(){let e=0;const n=this.isMergingRemoteChanges?"remote":"user";for(;this.pendingAfterEvents;){const r=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(e++,e>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:o,after:s}of r.values())o&&s?this.sideEffects.handleAfterChange(o,s,n):o&&!s?this.sideEffects.handleAfterDelete(o,n):!o&&s&&this.sideEffects.handleAfterCreate(s,n);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(n)}}}atomic(e,n=!0){return _o(()=>{if(this._isInAtomicOp)return this.pendingAfterEvents||(this.pendingAfterEvents=new Map),e();this.pendingAfterEvents=new Map;const r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(n??r),this._isInAtomicOp=!0;try{const o=e();return this.flushAtomicCallbacks(),o}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(r),this._isInAtomicOp=!1}})}addHistoryInterceptor(e){return this.historyAccumulator.addInterceptor(n=>e(n,this.isMergingRemoteChanges?"remote":"user"))}}function nV(t){if(t.length===0)return[];const e=[];let n=[t[0]],r;for(let o=1,s=t.length;o<s;o++)r=t[o],n[0].source!==r.source&&(e.push(n),n=[]),n.push(r);return e.push(n),e.map(o=>({source:o[0].source,changes:$w(o.map(s=>s.changes))}))}class rV{constructor(){E(this,"_history",[]);E(this,"_interceptors",new Set)}addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const n of this._interceptors)n(e)}flush(){const e=nV(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function oV(t,e,n){const r=new Eo;return{get(o,s){return r.get(o,()=>(o instanceof zw?o:o.store).createComputedCache(t,l=>e(o,l),n)).get(s)}}}function sV(t){const e=[];for(let n=t.length-1;n>=0;n--){const r=t[n];if("id"in r)e.unshift(r);else{const o=r.dependsOn,s=e[0];s&&(e[0]={...s,dependsOn:o.concat(s.dependsOn??[])})}}return e}function ul({sequence:t,sequenceId:e,retroactive:n=!0}){const r={sequenceId:e,retroactive:n,sequence:sV(t)};return LM(r),r}function Yn(t,e){return Object.fromEntries(Gn(e).map(([n,r])=>[n,`${t}/${r}`]))}function Sr(t){const e=t.sequenceId;return ul({sequenceId:e,retroactive:t.retroactive??!0,sequence:t.sequence.map(n=>"id"in n?{...n,scope:"record",filter:r=>{var o,s;return r.typeName===t.recordType&&(((o=n.filter)==null?void 0:o.call(n,r))??!0)&&(((s=t.filter)==null?void 0:s.call(t,r))??!0)}}:n)})}function iV(t){const e=new Map(t.map(s=>[s.id,s])),n=new Set,r=[];function o(s){Re(!n.has(s.id),`Circular dependency in migrations: ${s.id}`),n.add(s.id);const{version:i,sequenceId:a}=pf(s.id),l=e.get(`${a}/${i-1}`);if(l&&o(l),s.dependsOn)for(const c of s.dependsOn){const u=e.get(c);u&&o(u)}e.delete(s.id),r.push(s)}for(const s of e.values())o(s);return r}function pf(t){const[e,n]=t.split("/");return{sequenceId:e,version:parseInt(n)}}function y_(t,e){e&&Re(t.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${t}'`),Re(t.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${t}'`)}function LM(t){if(Re(!t.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${t.sequenceId}`),Re(t.sequenceId.length,"sequenceId must be a non-empty string"),t.sequence.length===0)return;y_(t.sequence[0].id,t.sequenceId);let e=pf(t.sequence[0].id).version;Re(e===1,`Expected the first migrationId to be '${t.sequenceId}/1' but got '${t.sequence[0].id}'`);for(let n=1;n<t.sequence.length;n++){const r=t.sequence[n].id;y_(r,t.sequenceId);const o=pf(r).version;Re(o===e+1,`Migration id numbers must increase in increments of 1, expected ${t.sequenceId}/${e+1} but got '${t.sequence[n].id}'`),e=o}}var js=(t=>(t.IncompatibleSubtype="incompatible-subtype",t.UnknownType="unknown-type",t.TargetVersionTooNew="target-version-too-new",t.TargetVersionTooOld="target-version-too-old",t.MigrationError="migration-error",t.UnrecognizedSubtype="unrecognized-subtype",t))(js||{});function aV(t){if(t.schemaVersion>2||t.schemaVersion<1)return Sn.err("Bad schema version");if(t.schemaVersion===2)return Sn.ok(t);const e={schemaVersion:2,sequences:{"com.tldraw.store":t.storeVersion}};for(const[n,r]of Object.entries(t.recordVersions))if(e.sequences[`com.tldraw.${n}`]=r.version,"subTypeKey"in r)for(const[o,s]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${n}.${o}`]=s;return Sn.ok(e)}class Bw{constructor(e,n){E(this,"migrations",{});E(this,"sortedMigrations");var o;this.types=e,this.options=n;for(const s of n.migrations??[])Re(!this.migrations[s.sequenceId],`Duplicate migration sequenceId ${s.sequenceId}`),LM(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=iV(r);for(const s of this.sortedMigrations)if((o=s.dependsOn)!=null&&o.length)for(const i of s.dependsOn){const a=r.find(l=>l.id===i);Re(a,`Migration '${s.id}' depends on missing migration '${i}'`)}}static create(e,n){return new Bw(e,n??{})}validateRecord(e,n,r,o){try{const s=zn(this.types,n.typeName);if(!s)throw new Error(`Missing definition for record type ${n.typeName}`);return s.validate(n,o??void 0)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:n,phase:r,recordBefore:o,error:s});throw s}}getMigrationsSince(e){const n=aV(e);if(!n.ok)return n;const r=n.value,o=new Set(Object.keys(r.sequences).filter(i=>this.migrations[i]));for(const i in this.migrations)r.sequences[i]===void 0&&this.migrations[i].retroactive&&o.add(i);if(o.size===0)return Sn.ok([]);const s=new Set;for(const i of o){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)s.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return Sn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))s.add(u.id)}return Sn.ok(this.sortedMigrations.filter(({id:i})=>s.has(i)))}migratePersistedRecord(e,n,r="up"){const o=this.getMigrationsSince(n);if(!o.ok)return console.error("Error migrating record",o.error),{type:"error",reason:js.MigrationError};let s=o.value;if(s.length===0)return{type:"success",value:e};if(s.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?js.TargetVersionTooOld:js.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:js.TargetVersionTooOld};s=s.slice().reverse()}e=tt(e);try{for(const i of s){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(e):!0))continue;const l=i[r](e);l&&(e=tt(l))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:js.MigrationError}}return{type:"success",value:e}}migrateStoreSnapshot(e){let{store:n}=e;const r=this.getMigrationsSince(e.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:js.MigrationError};const o=r.value;if(o.length===0)return{type:"success",value:n};n=tt(n);try{for(const s of o)if(s.scope==="record")for(const[i,a]of Object.entries(n)){if(!(s.filter?s.filter(a):!0))continue;const c=s.up(a);c&&(n[i]=tt(c))}else if(s.scope==="store"){const i=s.up(n);i&&(n=tt(i))}else Tt(s)}catch(s){return console.error("Error migrating store",s),{type:"error",reason:js.MigrationError}}return{type:"success",value:n}}createIntegrityChecker(e){var n,r;return((r=(n=this.options).createIntegrityChecker)==null?void 0:r.call(n,e))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:n})=>[e,n.length?pf(n.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const n=zn(this.types,e);return Re(n,"record type does not exists"),n}}Si("@tldraw/store","3.2.0","esm");function lV(t){if(!t.length)return null;let e="";for(const n of t)typeof n=="number"?e+=`.${n}`:n.startsWith("(")?e.endsWith(")")?e=`${e.slice(0,-1)}, ${n.slice(1)}`:e+=n:e+=`.${n}`;return e=e.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),e.startsWith(".")?e.slice(1):e}class Me extends Error{constructor(n,r=[]){const o=lV(r),s=n.split(`
83
- `).map((i,a)=>a===0?i:` ${i}`).join(`
84
- `);super(r?`At ${o}: ${s}`:s);E(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function Vn(t,e){try{return e()}catch(n){throw n instanceof Me?new Me(n.rawMessage,[t,...n.path]):new Me(n.toString(),[t])}}function ai(t){if(t===null)return"null";if(Array.isArray(t))return"an array";const e=typeof t;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:Tt(e)}}class In{constructor(e,n){this.validationFn=e,this.validateUsingKnownGoodVersionFn=n}validate(e){return this.validationFn(e)}validateUsingKnownGoodVersion(e,n){return Object.is(e,n)?e:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(e,n):this.validate(n)}isValid(e){try{return this.validate(e),!0}catch{return!1}}nullable(){return fV(this)}optional(){return FM(this)}refine(e){return new In(n=>e(this.validate(n)),(n,r)=>{const o=this.validateUsingKnownGoodVersion(n,r);return Object.is(n,o)?n:e(o)})}check(e,n){return typeof e=="string"?this.refine(r=>(Vn(`(check ${e})`,()=>n(r)),r)):this.refine(r=>(e(r),r))}}class cV extends In{constructor(e){super(n=>{const r=S_.validate(n);for(let o=0;o<r.length;o++)Vn(o,()=>e.validate(r[o]));return r},(n,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const o=S_.validate(r);let s=n.length!==o.length;for(let i=0;i<o.length;i++){const a=o[i];if(i>=n.length){s=!0,Vn(i,()=>e.validate(a));continue}if(Object.is(n[i],a))continue;const l=Vn(i,()=>e.validateUsingKnownGoodVersion(n[i],a));Object.is(l,n[i])||(s=!0)}return s?r:n}),this.itemValidator=e}nonEmpty(){return this.check(e=>{if(e.length===0)throw new Me("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new Me("Expected an array with length greater than 1")})}}class ff extends In{constructor(e,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${ai(r)}`);for(const[o,s]of Object.entries(e))Vn(o,()=>{s.validate(zn(r,o))});if(!n){for(const o of Object.keys(r))if(!qr(e,o))throw new Me("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Me(`Expected object, got ${ai(o)}`);let s=!1;for(const[i,a]of Object.entries(e)){const l=zn(r,i),c=zn(o,i);if(Object.is(l,c))continue;const u=Vn(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(s=!0)}if(!n){for(const i of Object.keys(o))if(!qr(e,i))throw new Me("Unexpected property",[i])}for(const i of Object.keys(r))if(!qr(o,i)){s=!0;break}return s?o:r}),this.config=e,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new ff(this.config,!0)}extend(e){return new ff({...this.config,...e})}}class xg extends In{constructor(e,n,r,o){super(s=>{this.expectObject(s);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(s);return i===void 0?this.unknownValueValidation(s,a):Vn(`(${e} = ${a})`,()=>i.validate(s))},(s,i)=>{this.expectObject(i),this.expectObject(s);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):zn(s,e)!==zn(i,e)?Vn(`(${e} = ${l})`,()=>a.validate(i)):Vn(`(${e} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(s,i):a.validate(i))}),this.key=e,this.config=n,this.unknownValueValidation=r,this.useNumberKeys=o}expectObject(e){if(typeof e!="object"||e===null)throw new Me(`Expected an object, got ${ai(e)}`,[])}getMatchingSchemaAndVariant(e){const n=zn(e,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new Me(`Expected a string for key "${this.key}", got ${ai(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Me(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:qr(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(e){return new xg(this.key,this.config,e,this.useNumberKeys)}}class uV extends In{constructor(e,n){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${ai(r)}`);for(const[o,s]of Object.entries(r))Vn(o,()=>{e.validate(o),n.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Me(`Expected object, got ${ai(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!qr(r,i)){s=!0,Vn(i,()=>{e.validate(i),n.validate(a)});continue}const l=zn(r,i),c=a;if(Object.is(l,c))continue;const u=Vn(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(s=!0)}for(const i of Object.keys(r))if(!qr(o,i)){s=!0;break}return s?o:r}),this.keyValidator=e,this.valueValidator=n}}function Uw(t){return new In(e=>{if(typeof e!==t)throw new Me(`Expected ${t}, got ${ai(e)}`);return e})}const dV=new In(t=>t),me=Uw("string"),pe=Uw("number").check(t=>{if(Number.isNaN(t))throw new Me("Expected a number, got NaN");if(!Number.isFinite(t))throw new Me(`Expected a finite number, got ${t}`)}),gf=pe.check(t=>{if(t<0)throw new Me(`Expected a positive number, got ${t}`)}),bt=pe.check(t=>{if(t<=0)throw new Me(`Expected a non-zero positive number, got ${t}`)}),$M=pe.check(t=>{if(!Number.isInteger(t))throw new Me(`Expected an integer, got ${t}`)}),qh=$M.check(t=>{if(t<0)throw new Me(`Expected a positive integer, got ${t}`)}),hV=$M.check(t=>{if(t<=0)throw new Me(`Expected a non-zero positive integer, got ${t}`)}),xe=Uw("boolean");function pn(t){return new In(e=>{if(e!==t)throw new Me(`Expected ${t}, got ${JSON.stringify(e)}`);return t})}const S_=new In(t=>{if(!Array.isArray(t))throw new Me(`Expected an array, got ${ai(t)}`);return t});function Kt(t){return new cV(t)}function Pe(t){return new ff(t)}function rx(t){return typeof t=="object"&&t!==null&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null||Object.getPrototypeOf(t)===B9)}function ox(t){return t===null||typeof t=="number"||typeof t=="string"||typeof t=="boolean"?!0:Array.isArray(t)?t.every(ox):rx(t)?Object.values(t).every(ox):!1}const Wt=new In(t=>{if(ox(t))return t;throw new Me(`Expected json serializable value, got ${typeof t}`)},(t,e)=>{if(Array.isArray(t)&&Array.isArray(e)){let n=t.length!==e.length;for(let r=0;r<e.length;r++){if(r>=t.length){n=!0,Wt.validate(e[r]);continue}const o=t[r],s=e[r];if(Object.is(o,s))continue;const i=Wt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}return n?e:t}else if(rx(t)&&rx(e)){let n=!1;for(const r of Object.keys(e)){if(!qr(t,r)){n=!0,Wt.validate(e[r]);continue}const o=t[r],s=e[r];if(Object.is(o,s))continue;const i=Wt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}for(const r of Object.keys(t))if(!qr(e,r)){n=!0;break}return n?e:t}else return Wt.validate(e)});function mf(t,e){return new uV(t,e)}function Hw(t,e){return new xg(t,e,(n,r)=>{throw new Me(`Expected one of ${Object.keys(e).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!1)}function pV(t,e){return new xg(t,e,(n,r)=>{throw new Me(`Expected one of ${Object.keys(e).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!0)}function Ro(t,e){return new In(n=>Vn(t,()=>e.validate(n)),(n,r)=>Vn(t,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(n,r):e.validate(r)))}function wg(t){return new In(e=>{if(!t.has(e)){const n=Array.from(t,r=>JSON.stringify(r)).join(" or ");throw new Me(`Expected ${n}, got ${e}`)}return e})}function FM(t){return new In(e=>{if(e!==void 0)return t.validate(e)},(e,n)=>{if(!(e===void 0&&n===void 0)&&n!==void 0)return t.validateUsingKnownGoodVersion&&e!==void 0?t.validateUsingKnownGoodVersion(e,n):t.validate(n)})}function fV(t){return new In(e=>e===null?null:t.validate(e),(e,n)=>n===null?null:t.validateUsingKnownGoodVersion&&e!==null?t.validateUsingKnownGoodVersion(e,n):t.validate(n))}function bg(...t){return wg(new Set(t))}function Kw(t){try{return new URL(t)}catch{if(t.startsWith("/")||t.startsWith("./"))try{return new URL(t,"http://example.com")}catch{throw new Me(`Expected a valid url, got ${JSON.stringify(t)}`)}throw new Me(`Expected a valid url, got ${JSON.stringify(t)}`)}}const gV=new Set(["http:","https:","mailto:"]),pr=me.check(t=>{if(t==="")return;const e=Kw(t);if(!gV.has(e.protocol.toLowerCase()))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)}),mV=new Set(["http:","https:","data:","asset:"]),Ji=me.check(t=>{if(t==="")return;const e=Kw(t);if(!mV.has(e.protocol.toLowerCase()))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});me.check(t=>{if(t==="")return;if(!Kw(t).protocol.toLowerCase().match(/^https?:$/))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});const Ww=me.refine(t=>{try{return M9(t),t}catch{throw new Me(`Expected an index key, got ${JSON.stringify(t)}`)}});Si("@tldraw/validate","3.2.0","esm");function cr(t){return me.refine(e=>{if(!e.startsWith(`${t}:`))throw new Error(`${t} ID must start with "${t}:"`);return e})}const Pg=cr("asset");function Gw(t,e){return Pe({id:Pg,typeName:pn("asset"),type:pn(t),props:e,meta:Wt})}const ea=Pe({x:pe,y:pe,z:pe.optional()}),tu=Pe({x:pe,y:pe,w:pe,h:pe}),NM=pe.check(t=>{if(t<0||t>1)throw new Me("Opacity must be between 0 and 1")}),yV=me.refine(t=>{if(!t.startsWith("page:")&&!t.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return t}),Pr=cr("shape");function SV(t,e,n){return Pe({id:Pr,typeName:pn("shape"),x:pe,y:pe,rotation:pe,index:Ww,parentId:yV,type:pn(t),isLocked:xe,opacity:NM,props:e?Pe(e):Wt,meta:n?Pe(n):Wt})}const vV=cr("binding");function xV(t,e,n){return Pe({id:vV,typeName:pn("binding"),type:pn(t),fromId:Pr,toId:Pr,props:e?Pe(e):Wt,meta:n?Pe(n):Wt})}Yn("com.tldraw.binding",{});Sr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Wi(t){return`binding:${Ke()}`}function wV(t){return Do("binding",{scope:"document",validator:Ro("binding",Hw("type",Yu(t,(e,{props:n,meta:r})=>xV(e,n,r))))}).withDefaultProperties(()=>({meta:{}}))}class qt{constructor(e,n,r){this.id=e,this.defaultValue=n,this.type=r}static define(e,n){const{defaultValue:r,type:o=dV}=n;return new qt(e,r,o)}static defineEnum(e,n){const{defaultValue:r,values:o}=n;return new bV(e,r,o)}setDefaultValue(e){this.defaultValue=e}validate(e){return this.type.validate(e)}validateUsingKnownGoodVersion(e,n){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(e,n):this.validate(n)}}class bV extends qt{constructor(e,n,r){super(e,n,bg(...r)),this.values=r}}const Qd=Yn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),PV=Sr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:Qd.AddIsLocked,up:t=>{t.isLocked=!1},down:t=>{delete t.isLocked}},{id:Qd.HoistOpacity,up:t=>{t.opacity=Number(t.props.opacity??"1"),delete t.props.opacity},down:t=>{const e=t.opacity;delete t.opacity,t.props.opacity=e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}},{id:Qd.AddMeta,up:t=>{t.meta={}}},{id:Qd.AddWhite,up:t=>{},down:t=>{t.props.color==="white"&&(t.props.color="black")}}]});function Qa(t){return t?t.typeName==="shape":!1}function Rn(t){return t?t.startsWith("shape:"):!1}function Ne(t){return`shape:${t??Ke()}`}function zM(t){const e=new Map;for(const[n,r]of Object.entries(t))if(r instanceof qt){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,n)}return e}function oo(t,e){return Yu(e,(n,r)=>`com.tldraw.shape.${t}/${r}`)}function CV(t){return Do("shape",{scope:"document",validator:Ro("shape",Hw("type",Yu(t,(e,{props:n,meta:r})=>SV(e,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function v_(t,e){const n=[];for(const[r,{migrations:o}]of Object.entries(e)){const s=`com.tldraw.${t}.${r}`;o?"sequenceId"in o?(Re(s===o.sequenceId,`sequenceId mismatch for ${r} ${Sg} migrations. Expected '${s}', got '${o.sequenceId}'`),n.push(o)):"sequence"in o?n.push(ul({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?BM(t,r,i):i)})):n.push(ul({sequenceId:s,retroactive:!1,sequence:Object.keys(o.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${s}/${i}`,scope:"record",filter:a=>a.typeName===t&&a.type===r,up:a=>{const l=o.migrators[i].up(a);if(l)return l},down:a=>{const l=o.migrators[i].down(a);if(l)return l}}))})):n.push(ul({sequenceId:s,retroactive:!1,sequence:[]}))}return n}function BM(t,e,n){return{id:n.id,dependsOn:n.dependsOn,scope:"record",filter:r=>r.typeName===t&&r.type===e,up:r=>{const o=n.up(r.props);o&&(r.props=o)},down:typeof n.down=="function"?r=>{const o=n.down(r.props);o&&(r.props=o)}:void 0}}const UM=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],yf={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",fill:"#4465e9",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#9fa8b2",fill:"#9fa8b2",note:{fill:"#C0CAD3",text:"#000000"},semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",note:{fill:"#9BC4FD",text:"#000000"},semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#4cb05e",fill:"#4cb05e",note:{fill:"#98D08A",text:"#000000"},semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#f87777",fill:"#f87777",note:{fill:"#F7A5A1",text:"#000000"},semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e085f4",fill:"#e085f4",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#e16919",fill:"#e16919",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",fill:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",fill:"#4f72fc",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",fill:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",fill:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",fill:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",fill:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",fill:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",fill:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function ws(t){return t.isDarkMode?yf.darkMode:yf.lightMode}const fr=qt.defineEnum("tldraw:color",{defaultValue:"black",values:UM}),HM=qt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:UM}),ta=qt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),na=qt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),ko=qt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),KM={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},To=qt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),WM=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Sf=qt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:WM}),vf=qt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:WM}),GM={labelColor:HM,color:fr,fill:na,dash:ta,size:To,arrowheadStart:Sf,arrowheadEnd:vf,font:ko,start:ea,end:ea,bend:pe,text:me,labelPosition:pe,scale:bt},Oa=oo("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function Jd(t){return BM("shape","arrow",t)}const VM=ul({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[Jd({id:Oa.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"}),Jd({id:Oa.AddIsPrecise,up:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise=!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5)),e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5))},down:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise||(t.normalizedAnchor={x:.5,y:.5}),delete t.isPrecise),e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise)}}),Jd({id:Oa.AddLabelPosition,up:t=>{t.labelPosition=.5},down:t=>{delete t.labelPosition}}),{id:Oa.ExtractBindings,scope:"store",up:t=>{const e=Object.values(t).filter(n=>n.typeName==="shape"&&n.type==="arrow");for(const n of e){const{start:r,end:o}=n.props;if(r.type==="binding"){const s=Wi(),i={typeName:"binding",id:s,type:"arrow",fromId:n.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};t[s]=i,n.props.start={x:0,y:0}}else delete n.props.start.type;if(o.type==="binding"){const s=Wi(),i={typeName:"binding",id:s,type:"arrow",fromId:n.id,toId:o.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:o.normalizedAnchor,isExact:o.isExact,isPrecise:o.isPrecise}};t[s]=i,n.props.end={x:0,y:0}}else delete n.props.end.type}}},Jd({id:Oa.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}})]}),YM={terminal:bg("start","end"),normalizedAnchor:ea,isExact:xe,isPrecise:xe},XM={sequence:[{dependsOn:[Oa.ExtractBindings]}]},_V=Ro("camera",Pe({typeName:pn("camera"),id:cr("camera"),x:pe,y:pe,z:pe,meta:Wt})),IV=Yn("com.tldraw.camera",{AddMeta:1}),EV=Sr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:IV.AddMeta,up:t=>{t.meta={}}}]}),xo=Do("camera",{validator:_V,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),kV=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"]),qM=wg(kV),TV=Pe({type:qM,rotation:pe}),MV=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),AV=wg(MV),jV=new Set(["starting","paused","active","stopping"]),ZM=Pe({id:me,points:Kt(ea),size:gf,color:AV,opacity:pe,state:wg(jV),delay:pe,shrink:pe,taper:xe}),Mu=cr("page"),OV=Ro("page",Pe({typeName:pn("page"),id:Mu,name:me,index:Ww,meta:Wt})),DV=Yn("com.tldraw.page",{AddMeta:1}),RV=Sr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:DV.AddMeta,up:t=>{t.meta={}}}]}),gr=Do("page",{validator:OV,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function jn(t){return gr.isId(t)}const LV={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 QM(t){return t?Jc(t,e=>LV[e]):null}cr("instance");function $V(t){const e={};for(const[r,o]of t)e[r]=FM(o);const n=Ro("instance",Pe({typeName:pn("instance"),id:cr("instance"),currentPageId:Mu,followingUserId:me.nullable(),brush:tu.nullable(),opacityForNextShape:NM,stylesForNextShape:Pe(e),cursor:TV,scribbles:Kt(ZM),isFocusMode:xe,isDebugMode:xe,isToolLocked:xe,exportBackground:xe,screenBounds:tu,insets:Kt(xe),zoomBrush:tu.nullable(),isPenMode:xe,isGridMode:xe,chatMessage:me,isChatting:xe,highlightedUserIds:Kt(me),isFocused:xe,devicePixelRatio:pe,isCoarsePointer:xe,isHoveringCanvas:xe.nullable(),openMenus:Kt(me),isChangingStyle:xe,isReadonly:xe,meta:Wt,duplicateProps:Pe({shapeIds:Kt(cr("shape")),offset:Pe({x:pe,y:pe})}).nullable()}));return Do("instance",{validator:n,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const Je=Yn("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}),FV=Sr({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:Je.AddTransparentExportBgs,up:t=>({...t,exportBackground:!0})},{id:Je.RemoveDialog,up:({dialog:t,...e})=>e},{id:Je.AddToolLockMode,up:t=>({...t,isToolLocked:!1})},{id:Je.RemoveExtraPropsForNextShape,up:({propsForNextShape:t,...e})=>({...e,propsForNextShape:Object.fromEntries(Object.entries(t).filter(([n])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(n)))})},{id:Je.AddLabelColor,up:({propsForNextShape:t,...e})=>({...e,propsForNextShape:{...t,labelColor:"black"}})},{id:Je.AddFollowingUserId,up:t=>({...t,followingUserId:null})},{id:Je.RemoveAlignJustify,up:t=>{let e=t.propsForNextShape.align;return e==="justify"&&(e="start"),{...t,propsForNextShape:{...t.propsForNextShape,align:e}}}},{id:Je.AddZoom,up:t=>({...t,zoomBrush:null})},{id:Je.AddVerticalAlign,up:t=>({...t,propsForNextShape:{...t.propsForNextShape,verticalAlign:"middle"}})},{id:Je.AddScribbleDelay,up:t=>t.scribble!==null?{...t,scribble:{...t.scribble,delay:0}}:{...t}},{id:Je.RemoveUserId,up:({userId:t,...e})=>e},{id:Je.AddIsPenModeAndIsGridMode,up:t=>({...t,isPenMode:!1,isGridMode:!1})},{id:Je.HoistOpacity,up:({propsForNextShape:{opacity:t,...e},...n})=>({...n,opacityForNextShape:Number(t??"1"),propsForNextShape:e})},{id:Je.AddChat,up:t=>({...t,chatMessage:"",isChatting:!1})},{id:Je.AddHighlightedUserIds,up:t=>({...t,highlightedUserIds:[]})},{id:Je.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:t,...e})=>({...e,stylesForNextShape:{}})},{id:Je.AddMeta,up:t=>({...t,meta:{}})},{id:Je.RemoveCursorColor,up:t=>{const{color:e,...n}=t.cursor;return{...t,cursor:n}}},{id:Je.AddLonelyProperties,up:t=>({...t,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:Je.ReadOnlyReadonly,up:({isReadOnly:t,...e})=>({...e,isReadonly:t})},{id:Je.AddHoveringCanvas,up:t=>({...t,isHoveringCanvas:null})},{id:Je.AddScribbles,up:({scribble:t,...e})=>({...e,scribbles:[]})},{id:Je.AddInset,up:t=>({...t,insets:[!1,!1,!1,!1]}),down:({insets:t,...e})=>({...e})},{id:Je.AddDuplicateProps,up:t=>({...t,duplicateProps:null}),down:({duplicateProps:t,...e})=>({...e})},{id:Je.RemoveCanMoveCamera,up:({canMoveCamera:t,...e})=>({...e}),down:t=>({...t,canMoveCamera:!0})}]}),vn="instance:instance",NV=Ro("instance_page_state",Pe({typeName:pn("instance_page_state"),id:cr("instance_page_state"),pageId:Mu,selectedShapeIds:Kt(Pr),hintingShapeIds:Kt(Pr),erasingShapeIds:Kt(Pr),hoveredShapeId:Pr.nullable(),editingShapeId:Pr.nullable(),croppingShapeId:Pr.nullable(),focusedGroupId:Pr.nullable(),meta:Wt})),gc=Yn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),zV=Sr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:gc.AddCroppingId,up(t){t.croppingShapeId=null}},{id:gc.RemoveInstanceIdAndCameraId,up(t){delete t.instanceId,delete t.cameraId}},{id:gc.AddMeta,up:t=>{t.meta={}}},{id:gc.RenameProperties,up:t=>{},down:t=>{}},{id:gc.RenamePropertiesAgain,up:t=>{t.selectedShapeIds=t.selectedIds,delete t.selectedIds,t.hintingShapeIds=t.hintingIds,delete t.hintingIds,t.erasingShapeIds=t.erasingIds,delete t.erasingIds,t.hoveredShapeId=t.hoveredId,delete t.hoveredId,t.editingShapeId=t.editingId,delete t.editingId,t.croppingShapeId=t.croppingShapeId??t.croppingId??null,delete t.croppingId,t.focusedGroupId=t.focusLayerId,delete t.focusLayerId},down:t=>{t.selectedIds=t.selectedShapeIds,delete t.selectedShapeIds,t.hintingIds=t.hintingShapeIds,delete t.hintingShapeIds,t.erasingIds=t.erasingShapeIds,delete t.erasingShapeIds,t.hoveredId=t.hoveredShapeId,delete t.hoveredShapeId,t.editingId=t.editingShapeId,delete t.editingShapeId,t.croppingId=t.croppingShapeId,delete t.croppingShapeId,t.focusLayerId=t.focusedGroupId,delete t.focusedGroupId}}]}),Gr=Do("instance_page_state",{validator:NV,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:{}})),BV=Ro("pointer",Pe({typeName:pn("pointer"),id:cr("pointer"),x:pe,y:pe,lastActivityTimestamp:pe,meta:Wt})),UV=Yn("com.tldraw.pointer",{AddMeta:1}),HV=Sr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:UV.AddMeta,up:t=>{t.meta={}}}]}),Vw=Do("pointer",{validator:BV,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),xf=Vw.createId("pointer"),KV=Ro("instance_presence",Pe({typeName:pn("instance_presence"),id:cr("instance_presence"),userId:me,userName:me,lastActivityTimestamp:pe,followingUserId:me.nullable(),cursor:Pe({x:pe,y:pe,type:qM,rotation:pe}),color:me,camera:Pe({x:pe,y:pe,z:pe}),screenBounds:tu,selectedShapeIds:Kt(cr("shape")),currentPageId:cr("page"),brush:tu.nullable(),scribbles:Kt(ZM),chatMessage:me,meta:Wt})),mc=Yn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),WV=Sr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:mc.AddScribbleDelay,up:t=>{t.scribble!==null&&(t.scribble.delay=0)}},{id:mc.RemoveInstanceId,up:t=>{delete t.instanceId}},{id:mc.AddChatMessage,up:t=>{t.chatMessage=""}},{id:mc.AddMeta,up:t=>{t.meta={}}},{id:mc.RenameSelectedShapeIds,up:t=>{}}]}),GV=Do("instance_presence",{validator:KV,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:0,followingUserId:null,color:"#FF0000",camera:{x:0,y:0,z:1},cursor:{x:0,y:0,type:"default",rotation:0},screenBounds:{x:0,y:0,w:1,h:1},selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),VV=Ro("document",Pe({typeName:pn("document"),id:pn("document:document"),gridSize:pe,name:me,meta:Wt})),x_=Yn("com.tldraw.document",{AddName:1,AddMeta:2}),YV=Sr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:x_.AddName,up:t=>{t.name=""},down:t=>{delete t.name}},{id:x_.AddMeta,up:t=>{t.meta={}}}]}),Yw=Do("document",{validator:VV,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),sx=Yw.createId("document");function XV(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function w_(t){t.typeName==="asset"&&("src"in t&&(t.src="<redacted>"),"src"in t.props&&(t.props.src="<redacted>"))}function qV({error:t,phase:e,record:n,recordBefore:r}){throw cw(t,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?w_(tt(r)):void 0,recordAfter:w_(tt(n))}}),t}function ZV(){return[gr.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function QV(t){const e=t.query.ids("page"),n=t.query.records("instance_page_state"),r=()=>{if(!t.has(sx))return t.put([Yw.create({id:sx,name:t.props.defaultName})]),r();if(!t.has(xf))return t.put([Vw.create({id:xf})]),r();const o=e.get();if(o.size===0)return t.put(ZV()),r();const s=()=>[...o].map(u=>t.get(u)).sort(XV)[0].id,i=t.get(vn);if(i){if(!o.has(i.currentPageId))return t.put([{...i,currentPageId:s()}]),r()}else return t.put([t.schema.types.instance.create({id:vn,currentPageId:s(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const u of o){const h=Gr.createId(u);t.get(h)||a.add(h);const f=xo.createId(u);t.has(f)||l.add(f)}a.size>0&&t.put([...a].map(u=>Gr.create({id:u,pageId:Gr.parseId(u)}))),l.size>0&&t.put([...l].map(u=>xo.create({id:u})));const c=n.get();for(const u of c){if(!o.has(u.pageId)){t.remove([u.id]);continue}if(u.croppingShapeId&&!t.has(u.croppingShapeId))return t.put([{...u,croppingShapeId:null}]),r();if(u.focusedGroupId&&!t.has(u.focusedGroupId))return t.put([{...u,focusedGroupId:null}]),r();if(u.hoveredShapeId&&!t.has(u.hoveredShapeId))return t.put([{...u,hoveredShapeId:null}]),r();const h=u.selectedShapeIds.filter(g=>t.has(g));if(h.length!==u.selectedShapeIds.length)return t.put([{...u,selectedShapeIds:h}]),r();const p=u.hintingShapeIds.filter(g=>t.has(g));if(p.length!==u.hintingShapeIds.length)return t.put([{...u,hintingShapeIds:p}]),r();const f=u.erasingShapeIds.filter(g=>t.has(g));if(f.length!==u.erasingShapeIds.length)return t.put([{...u,erasingShapeIds:f}]),r()}};return r}const JV=Gw("bookmark",Pe({title:me,description:me,image:me,favicon:me,src:Ji.nullable()})),b_=Yn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),eY=Sr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:t=>t.type==="bookmark",sequence:[{id:b_.MakeUrlsValid,up:t=>{Ji.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:b_.AddFavicon,up:t=>{Ji.isValid(t.props.favicon)||(t.props.favicon="")},down:t=>{delete t.props.favicon}}]}),tY=Gw("image",Pe({w:pe,h:pe,name:me,isAnimated:xe,mimeType:me.nullable(),src:Ji.nullable(),fileSize:bt.optional()})),yc=Yn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),nY=Sr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:t=>t.type==="image",sequence:[{id:yc.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:yc.RenameWidthHeight,up:t=>{t.props.w=t.props.width,t.props.h=t.props.height,delete t.props.width,delete t.props.height},down:t=>{t.props.width=t.props.w,t.props.height=t.props.h,delete t.props.w,delete t.props.h}},{id:yc.MakeUrlsValid,up:t=>{Ji.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:yc.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:yc.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),rY=Gw("video",Pe({w:pe,h:pe,name:me,isAnimated:xe,mimeType:me.nullable(),src:Ji.nullable(),fileSize:pe.optional()})),Sc=Yn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),oY=Sr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:t=>t.type==="video",sequence:[{id:Sc.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Sc.RenameWidthHeight,up:t=>{t.props.w=t.props.width,t.props.h=t.props.height,delete t.props.width,delete t.props.height},down:t=>{t.props.width=t.props.w,t.props.height=t.props.h,delete t.props.w,delete t.props.h}},{id:Sc.MakeUrlsValid,up:t=>{Ji.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Sc.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Sc.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),sY=Ro("asset",Hw("type",{image:tY,video:rY,bookmark:JV})),iY=Yn("com.tldraw.asset",{AddMeta:1}),aY=Sr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:iY.AddMeta,up:t=>{t.meta={}}}]}),Ns=Do("asset",{validator:sY,scope:"document"}).withDefaultProperties(()=>({meta:{}})),JM={w:bt,h:bt,assetId:Pg.nullable(),url:pr},P_=oo("bookmark",{NullAssetId:1,MakeUrlsValid:2}),eA={sequence:[{id:P_.NullAssetId,up:t=>{t.assetId===void 0&&(t.assetId=null)},down:"retired"},{id:P_.MakeUrlsValid,up:t=>{pr.isValid(t.url)||(t.url="")},down:t=>{}}]},tA=Pe({type:bg("free","straight"),points:Kt(ea)}),nA={color:fr,fill:na,dash:ta,size:To,segments:Kt(tA),isComplete:xe,isClosed:xe,isPen:xe,scale:bt},C_=oo("draw",{AddInPen:1,AddScale:2}),rA={sequence:[{id:C_.AddInPen,up:t=>{const{points:e}=t.segments[0];if(e.length===0){t.isPen=!1;return}let n=!(e[0].z===0||e[0].z===.5);e[1]&&(n=n&&!(e[1].z===0||e[1].z===.5)),t.isPen=n},down:"retired"},{id:C_.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},lY=/(^\/r\/[^/]+\/?$)/,cY=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(lY))return t}},{hostnames:["figma.com"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{hostnames:["google.*"],fromEmbedUrl:t=>{const e=fe(t);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"),[o,s]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${o},${s},${r}z`}}},{hostnames:["val.town"],fromEmbedUrl:t=>{const e=fe(t),n=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:t=>{const e=fe(t),n=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{hostnames:["codepen.io"],fromEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,o,s]=n;return`https://codepen.io/${o}/pen/${s}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,o]=n;return`https://scratch.mit.edu/projects/${o}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],fromEmbedUrl:t=>{const e=fe(t);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:t=>{const e=fe(t),n=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&n){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const o of r)e.searchParams.delete(o);return e.searchParams.set("cid",n),e.href}}},{hostnames:["docs.google.*"],fromEmbedUrl:t=>{const e=fe(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}}},{hostnames:["gist.github.com"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return t.split("/").pop()?t:void 0}},{hostnames:["replit.com"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{hostnames:["open.spotify.com"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{hostnames:["vimeo.com","player.vimeo.com"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.hostname==="player.vimeo.com"){const n=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(n)return"https://vimeo.com/"+n[1]}}},{hostnames:["excalidraw.com"],fromEmbedUrl:t=>{const e=fe(t);if(e&&e.hash.match(/#room=/))return t}},{hostnames:["observablehq.com"],fromEmbedUrl:t=>{const e=fe(t);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:t=>{const e=fe(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],oA={w:bt,h:bt,url:me},eh=oo("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),sA={sequence:[{id:eh.GenOriginalUrlInEmbed,up:t=>{try{const e=t.url,n=new URL(e).host.replace("www.","");let r;for(const o of cY)if(o.hostnames.includes(n))try{r=o.fromEmbedUrl(e)}catch(s){console.warn(s)}t.tmpOldUrl=t.url,t.url=r??""}catch{t.url="",t.tmpOldUrl=t.url}},down:"retired"},{id:eh.RemoveDoesResize,up:t=>{delete t.doesResize},down:"retired"},{id:eh.RemoveTmpOldUrl,up:t=>{delete t.tmpOldUrl},down:"retired"},{id:eh.RemovePermissionOverrides,up:t=>{delete t.overridePermissions},down:"retired"}]},iA={w:bt,h:bt,name:me},aA={sequence:[]},wf=qt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),bf=qt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Vr=qt.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),lA={geo:Vr,labelColor:HM,color:fr,fill:na,dash:ta,size:To,font:ko,align:wf,verticalAlign:bf,url:pr,w:bt,h:bt,growY:gf,text:me,scale:bt},Ho=oo("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),cA={sequence:[{id:Ho.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Ho.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"},{id:Ho.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Ho.AddCheckBox,up:t=>{},down:"retired"},{id:Ho.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Ho.MigrateLegacyAlign,up:t=>{let e;switch(t.align){case"start":e="start-legacy";break;case"end":e="end-legacy";break;default:e="middle-legacy";break}t.align=e},down:"retired"},{id:Ho.AddCloud,up:t=>{},down:"retired"},{id:Ho.MakeUrlsValid,up:t=>{pr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Ho.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},uA={},dA={sequence:[]},hA={color:fr,size:To,segments:Kt(tA),isComplete:xe,isPen:xe,scale:bt},uY=oo("highlight",{AddScale:1}),pA={sequence:[{id:uY.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},dY=Pe({topLeft:ea,bottomRight:ea}),fA={w:bt,h:bt,playing:xe,url:pr,assetId:Pg.nullable(),crop:dY.nullable(),flipX:xe,flipY:xe},th=oo("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),gA={sequence:[{id:th.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:th.AddCropProp,up:t=>{t.crop=null},down:t=>{delete t.crop}},{id:th.MakeUrlsValid,up:t=>{pr.isValid(t.url)||(t.url="")},down:t=>{}},{id:th.AddFlipProps,up:t=>{t.flipX=!1,t.flipY=!1},down:t=>{delete t.flipX,delete t.flipY}}]},Pf=qt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),hY=Pe({id:me,index:Ww,x:pe,y:pe}),mA={color:fr,dash:ta,size:To,spline:Pf,points:mf(me,hY),scale:bt},vc=oo("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),yA={sequence:[{id:vc.AddSnapHandles,up:t=>{for(const e of Object.values(t.handles))e.canSnap=!0},down:"retired"},{id:vc.RemoveExtraHandleProps,up:t=>{t.handles=hT(Object.values(t.handles).map(e=>[e.index,{x:e.x,y:e.y}]))},down:t=>{const e=Object.entries(t.handles).map(([n,r])=>({index:n,...r})).sort(ln);t.handles=Object.fromEntries(e.map((n,r)=>{const o=r===0?"start":r===e.length-1?"end":`handle:${n.index}`;return[o,{id:o,type:"vertex",canBind:!1,canSnap:!0,index:n.index,x:n.x,y:n.y}]}))}},{id:vc.HandlesToPoints,up:t=>{const e=Object.entries(t.handles).map(([n,{x:r,y:o}])=>({x:r,y:o,index:n})).sort(ln);t.points=e.map(({x:n,y:r})=>({x:n,y:r})),delete t.handles},down:t=>{const e=ku(t.points.length);t.handles=Object.fromEntries(t.points.map((n,r)=>[e[r],{x:n.x,y:n.y}])),delete t.points}},{id:vc.PointIndexIds,up:t=>{const e=ku(t.points.length);t.points=Object.fromEntries(t.points.map((n,r)=>{const o=e[r];return[o,{id:o,index:o,x:n.x,y:n.y}]}))},down:t=>{const e=Object.values(t.points).sort(ln);t.points=e.map(({x:n,y:r})=>({x:n,y:r}))}},{id:vc.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},SA={color:fr,size:To,font:ko,fontSizeAdjustment:gf,align:wf,verticalAlign:bf,growY:gf,url:pr,text:me,scale:bt},Oi=oo("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7}),vA={sequence:[{id:Oi.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Oi.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Oi.MigrateLegacyAlign,up:t=>{switch(t.align){case"start":t.align="start-legacy";return;case"end":t.align="end-legacy";return;default:t.align="middle-legacy";return}},down:"retired"},{id:Oi.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Oi.MakeUrlsValid,up:t=>{pr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Oi.AddFontSizeAdjustment,up:t=>{t.fontSizeAdjustment=0},down:t=>{delete t.fontSizeAdjustment}},{id:Oi.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},ix=qt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),xA={color:fr,size:To,font:ko,textAlign:ix,w:bt,text:me,scale:bt,autoSize:xe},__=oo("text",{RemoveJustify:1,AddTextAlign:2}),wA={sequence:[{id:__.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:__.AddTextAlign,up:t=>{t.textAlign=t.align,delete t.align},down:t=>{t.align=t.textAlign,delete t.textAlign}}]},bA={w:bt,h:bt,time:pe,playing:xe,url:pr,assetId:Pg.nullable()},I_=oo("video",{AddUrlProp:1,MakeUrlsValid:2}),PA={sequence:[{id:I_.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:I_.MakeUrlsValid,up:t=>{pr.isValid(t.url)||(t.url="")},down:t=>{}}]},nh=Yn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),pY=ul({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:nh.RemoveCodeAndIconShapeTypes,scope:"store",up:t=>{for(const[e,n]of Gn(t))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete t[e]}},{id:nh.AddInstancePresenceType,scope:"store",up(t){}},{id:nh.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:t=>{for(const[e,n]of Gn(t))n.typeName.match(/^(user|user_presence)$/)&&delete t[e]}},{id:nh.RemoveUserDocument,scope:"store",up:t=>{for(const[e,n]of Gn(t))n.typeName.match("user_document")&&delete t[e]}}]}),fY={arrow:{migrations:VM,props:GM},bookmark:{migrations:eA,props:JM},draw:{migrations:rA,props:nA},embed:{migrations:sA,props:oA},frame:{migrations:aA,props:iA},geo:{migrations:cA,props:lA},group:{migrations:dA,props:uA},highlight:{migrations:pA,props:hA},image:{migrations:gA,props:fA},line:{migrations:yA,props:mA},note:{migrations:vA,props:SA},text:{migrations:wA,props:xA},video:{migrations:PA,props:bA}},gY={arrow:{migrations:XM,props:YM}};function mY({shapes:t=fY,bindings:e=gY,migrations:n}={}){const r=new Map;for(const a of ct(t))for(const l of zM(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 o=CV(t),s=wV(e),i=$V(r);return Bw.create({asset:Ns,binding:s,camera:xo,document:Yw,instance:i,instance_page_state:Gr,page:gr,instance_presence:GV,pointer:Vw,shape:o},{migrations:[pY,aY,EV,YV,FV,zV,RV,WV,HV,PV,eY,nY,oY,...v_("shape",t),...v_("binding",e),...n??[]],onValidationFailure:qV,createIntegrityChecker:QV})}const Au=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"uk",label:"Ukrainian"},{locale:"he",label:"עברית"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ku",label:"کوردی"},{locale:"ne",label:"नेपाली"},{locale:"hi-in",label:"हिन्दी"},{locale:"te",label:"తెలుగు"},{locale:"th",label:"ภาษาไทย"},{locale:"my",label:"မြန်မာစာ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function yY(){const t=typeof window<"u"?window.navigator.languages??["en"]:["en"];return SY(t)}function SY(t){for(const e of t){const n=vY(e);if(n)return n}return"en"}const E_={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function vY(t){const e=Au.find(o=>o.locale===t.toLowerCase());if(e)return e.locale;const[n,r]=t.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Au.find(s=>s.locale===n);if(o)return o.locale}return n in E_?E_[n]:null}Si("@tldraw/tlschema","3.2.0","esm");function Cg(t,e){const n=Ie.useRef(e);n.current=e;const[r,o,s]=Ie.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),l=new Hl(`useStateTracking(${t})`,()=>{var u;return(u=n.current)==null?void 0:u.call(n)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[t]);return Ie.useSyncExternalStore(o,s,s),Ie.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const k_={apply(t,e,n){return Cg(t.displayName??t.name??"tracked(???)",()=>t.apply(e,n))}},xY=Symbol.for("react.memo"),wY=Symbol.for("react.forward_ref");function Rt(t){let e=null;const n=t.$$typeof;return n===xY&&(t=t.type,e=t.compare),n===wY?w.memo(w.forwardRef(new Proxy(t.render,k_))):w.memo(new Proxy(t,k_),e)}function bY(){const t=arguments[0],e=arguments[1],n=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return w.useMemo(()=>G(`useComputed(${t})`,e,n),r)}function ss(t,e,n=os){w.useEffect(()=>{const r=new Hl(t,e);return r.attach(),r.execute(),()=>{r.detach()}},n)}function U(){const t=arguments,e=t.length===3?t[2]:[t[0]],n=t.length===3?t[0]:`useValue(${t[0].name})`,r=w.useRef(!0);r.current=!0;const o=w.useMemo(()=>t.length===1?t[0]:G(n,()=>{if(r.current)return t[1]();try{return t[1]()}catch{return{}}}),e);try{const{subscribe:s,getSnapshot:i}=w.useMemo(()=>({subscribe:a=>ii(`useValue(${n})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return w.useSyncExternalStore(s,i,i)}finally{r.current=!1}}Si("@tldraw/state-react","3.2.0","esm");var CA={exports:{}};/*!
85
- Copyright (c) 2018 Jed Watson.
86
- Licensed under the MIT License (MIT), see
87
- http://jedwatson.github.io/classnames
88
- */(function(t){(function(){var e={}.hasOwnProperty;function n(){for(var s="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(s=o(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 n.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var i="";for(var a in s)e.call(s,a)&&s[a]&&(i=o(i,a));return i}function o(s,i){return i?s?s+" "+i:s+i:s}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})(CA);var PY=CA.exports;const le=fi(PY),_A="3.2.0",T_={major:"2024-09-13T14:36:29.063Z",minor:"2024-09-26T10:41:32.405Z",patch:"2024-09-26T10:41:32.405Z"},CY={error:null};class Xw extends w.Component{constructor(){super(...arguments);E(this,"state",CY)}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){var r,o;(o=(r=this.props).onError)==null||o.call(r,n)}render(){const{error:n}=this.state;if(n!==null){const{fallback:r}=this.props;return d.jsx(r,{error:n})}return this.props.children}}function ju({children:t,fallback:e,...n}){return e===null?t:d.jsx(Xw,{fallback:e,...n,children:t})}const _g=w.createContext(null);function F(){const t=Ie.useContext(_g);if(!t)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return t}function _Y(){return d.jsx("div",{className:"tl-background"})}function Kl(t,e,n,r,o,s){w.useLayoutEffect(()=>{const i=t.current;if(!i||e===void 0)return;let a=`translate(${e}px, ${n}px)`;r!==void 0&&(a+=` scale(${r})`),o!==void 0&&(a+=` rotate(${o}rad)`),s&&(a+=` translate(${s.x}px, ${s.y}px)`),i.style.transform=a})}const At={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>t*(2-t),easeInOutQuad:t=>t<.5?2*t*t:-1+(4-2*t)*t,easeInCubic:t=>t*t*t,easeOutCubic:t=>--t*t*t+1,easeInOutCubic:t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,easeInQuart:t=>t*t*t*t,easeOutQuart:t=>1- --t*t*t*t,easeInOutQuart:t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t,easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>1+--t*t*t*t*t,easeInOutQuint:t=>t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t,easeInSine:t=>1-Math.cos(t*Math.PI/2),easeOutSine:t=>Math.sin(t*Math.PI/2),easeInOutSine:t=>-(Math.cos(Math.PI*t)-1)/2,easeInExpo:t=>t<=0?0:Math.pow(2,10*t-10),easeOutExpo:t=>t>=1?1:1-Math.pow(2,-10*t),easeInOutExpo:t=>t<=0?0:t>=1?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2};class x{constructor(e=0,n=0,r=1){this.x=e,this.y=n,this.z=r}get pressure(){return this.z}set(e=this.x,n=this.y,r=this.z){return this.x=e,this.y=n,this.z=r,this}setTo({x:e=0,y:n=0,z:r=1}){return this.x=e,this.y=n,this.z=r,this}rot(e){if(e===0)return this;const{x:n,y:r}=this,o=Math.sin(e),s=Math.cos(e);return this.x=n*s-r*o,this.y=n*o+r*s,this}rotWith(e,n){if(n===0)return this;const r=this.x-e.x,o=this.y-e.y,s=Math.sin(n),i=Math.cos(n);return this.x=e.x+(r*i-o*s),this.y=e.y+(r*s+o*i),this}clone(){const{x:e,y:n,z:r}=this;return new x(e,n,r)}sub(e){return this.x-=e.x,this.y-=e.y,this}subXY(e,n){return this.x-=e,this.y-=n,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,n){return this.x+=e,this.y+=n,this}addScalar(e){return this.x+=e,this.y+=e,this}clamp(e,n){return this.x=Math.max(this.x,e),this.y=Math.max(this.y,e),n!==void 0&&(this.x=Math.min(this.x,n),this.y=Math.min(this.y,n)),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,n){const r=x.Tan(e,this);return this.add(r.mul(n))}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 x.Dpr(this,e)}cpr(e){return x.Cpr(this,e)}len2(){return x.Len2(this)}len(){return x.Len(this)}pry(e){return x.Pry(this,e)}per(){const{x:e,y:n}=this;return this.x=n,this.y=-e,this}uni(){return x.Uni(this)}tan(e){return x.Tan(this,e)}dist(e){return x.Dist(this,e)}distanceToLineSegment(e,n){return x.DistanceToLineSegment(e,n,this)}slope(e){return x.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 x.Angle(this,e)}toAngle(){return x.ToAngle(this)}lrp(e,n){return this.x=this.x+(e.x-this.x)*n,this.y=this.y+(e.y-this.y)*n,this}equals(e){return x.Equals(this,e)}equalsXY(e,n){return x.EqualsXY(this,e,n)}norm(){const e=this.len();return this.x=e===0?0:this.x/e,this.y=e===0?0:this.y/e,this}toFixed(){return x.ToFixed(this)}toString(){return x.ToString(x.ToFixed(this))}toJson(){return x.ToJson(this)}toArray(){return x.ToArray(this)}static Add(e,n){return new x(e.x+n.x,e.y+n.y)}static AddXY(e,n,r){return new x(e.x+n,e.y+r)}static Sub(e,n){return new x(e.x-n.x,e.y-n.y)}static SubXY(e,n,r){return new x(e.x-n,e.y-r)}static AddScalar(e,n){return new x(e.x+n,e.y+n)}static SubScalar(e,n){return new x(e.x-n,e.y-n)}static Div(e,n){return new x(e.x/n,e.y/n)}static Mul(e,n){return new x(e.x*n,e.y*n)}static DivV(e,n){return new x(e.x/n.x,e.y/n.y)}static MulV(e,n){return new x(e.x*n.x,e.y*n.y)}static Neg(e){return new x(-e.x,-e.y)}static Per(e){return new x(e.y,-e.x)}static Abs(e){return new x(Math.abs(e.x),Math.abs(e.y))}static Dist(e,n){return((e.y-n.y)**2+(e.x-n.x)**2)**.5}static DistMin(e,n,r){return(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y)<r**2}static Dist2(e,n){return(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y)}static Dpr(e,n){return e.x*n.x+e.y*n.y}static Cross(e,n){return new x(e.y*n.z-e.z*n.y,e.z*n.x-e.x*n.z)}static Cpr(e,n){return e.x*n.y-n.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,n){return x.Dpr(e,n)/x.Len(n)}static Uni(e){return x.Div(e,x.Len(e))}static Tan(e,n){return x.Uni(x.Sub(e,n))}static Min(e,n){return new x(Math.min(e.x,n.x),Math.min(e.y,n.y))}static Max(e,n){return new x(Math.max(e.x,n.x),Math.max(e.y,n.y))}static From({x:e,y:n,z:r=1}){return new x(e,n,r)}static FromArray(e){return new x(e[0],e[1])}static Rot(e,n=0){const r=Math.sin(n),o=Math.cos(n);return new x(e.x*o-e.y*r,e.x*r+e.y*o)}static RotWith(e,n,r){const o=e.x-n.x,s=e.y-n.y,i=Math.sin(r),a=Math.cos(r);return new x(n.x+(o*a-s*i),n.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(e,n,r){return x.Mul(n,x.Sub(r,e).pry(n)).add(e)}static NearestPointOnLineSegment(e,n,r,o=!0){if(x.Equals(e,r)||x.Equals(n,r))return x.From(r);const s=x.Tan(n,e),i=x.Add(e,x.Mul(s,x.Sub(r,e).pry(s)));if(o){if(i.x<Math.min(e.x,n.x))return x.Cast(e.x<n.x?e:n);if(i.x>Math.max(e.x,n.x))return x.Cast(e.x>n.x?e:n);if(i.y<Math.min(e.y,n.y))return x.Cast(e.y<n.y?e:n);if(i.y>Math.max(e.y,n.y))return x.Cast(e.y>n.y?e:n)}return i}static DistanceToLineThroughPoint(e,n,r){return x.Dist(r,x.NearestPointOnLineThroughPoint(e,n,r))}static DistanceToLineSegment(e,n,r,o=!0){return x.Dist(r,x.NearestPointOnLineSegment(e,n,r,o))}static Snap(e,n=1){return new x(Math.round(e.x/n)*n,Math.round(e.y/n)*n)}static Cast(e){return e instanceof x?e:x.From(e)}static Slope(e,n){return e.x===n.y?NaN:(e.y-n.y)/(e.x-n.x)}static IsNaN(e){return isNaN(e.x)||isNaN(e.y)}static Angle(e,n){return Math.atan2(n.y-e.y,n.x-e.x)}static Lrp(e,n,r){return x.Sub(n,e).mul(r).add(e)}static Med(e,n){return new x((e.x+n.x)/2,(e.y+n.y)/2)}static Equals(e,n){return Math.abs(e.x-n.x)<1e-4&&Math.abs(e.y-n.y)<1e-4}static EqualsXY(e,n,r){return e.x===n&&e.y===r}static Clockwise(e,n,r){return(r.x-e.x)*(n.y-e.y)-(n.x-e.x)*(r.y-e.y)<0}static Rescale(e,n){const r=x.Len(e);return new x(n*e.x/r,n*e.y/r)}static ScaleWithOrigin(e,n,r){return x.Sub(e,r).mul(n).add(r)}static ToFixed(e){return new x(Zo(e.x),Zo(e.y))}static ToInt(e){return new x(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,n,r){return x.Add(e,x.Tan(n,e).mul(r))}static ToString(e){return`${e.x}, ${e.y}`}static ToAngle(e){let n=Math.atan2(e.y,e.x);return n<0&&(n+=Math.PI*2),n}static FromAngle(e,n=1){return new x(Math.cos(e)*n,Math.sin(e)*n)}static ToArray(e){return[e.x,e.y,e.z]}static ToJson(e){const{x:n,y:r,z:o}=e;return{x:n,y:r,z:o}}static Average(e){const n=e.length,r=new x(0,0);if(n===0)return r;for(let o=0;o<n;o++)r.add(e[o]);return r.div(n)}static Clamp(e,n,r){return r===void 0?new x(Math.min(Math.max(e.x,n)),Math.min(Math.max(e.y,n))):new x(Math.min(Math.max(e.x,n),r),Math.min(Math.max(e.y,n),r))}static PointsBetween(e,n,r=6){const o=[];for(let s=0;s<r;s++){const i=At.easeInQuad(s/(r-1)),a=x.Lrp(e,n,i);a.z=Math.min(1,.5+Math.abs(.5-IY(i))*.65),o.push(a)}return o}static SnapToGrid(e,n=8){return new x(Math.round(e.x/n)*n,Math.round(e.y/n)*n)}}const IY=t=>t<.5?2*t*t:-1+(4-2*t)*t;function je(t){return`${$(t.x)},${$(t.y)} `}function $n(t,e){return`${$((t.x+e.x)/2)},${$((t.y+e.y)/2)} `}const De=Math.PI,qe=De/2,Fe=De*2,EY=Math.sin;function zt(t,e,n){return Math.max(e,typeof n<"u"?Math.min(t,n):t)}function rh(t,e=1e10){return t?Math.round(t*e)/e:0}function ti(t,e,n=1e-6){return Math.abs(t-e)<=n}function IA(t,e){const n=Math.pow(t-e,2)/Math.pow(t+e,2);return De*(t+e)*(1+3*n/(10+Math.sqrt(4-3*n)))}function ni(t){return t=t%Fe,t<0?t=t+Fe:t===0&&(t=0),t}function ed(t,e){return t=ni(t),e=ni(e),t>e&&(e+=Fe),e-t}function EA(t,e){return Fe-ed(t,e)}function Zh(t,e){const n=(e-t)%Fe;return 2*n%Fe-n}function ax(t){return(Fe+t)%Fe}function Cf(t,e){const n=Fe/e;let r=Math.floor((ax(t)+n/2)/n)*n%Fe;return r<De&&(r+=Fe),r>De&&(r-=Fe),r}function kA(t,e){return t===e||ti(t%(Math.PI/2)-e%(Math.PI/2),0)}function kY(t){return t*De/180}function TY(t){return t*180/De}function ra(t,e,n){return new x(t.x,t.y).add(x.FromAngle(n,e))}function Ty(t,e,n){const r=t/2,o=e/2,s=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let g=0;g<n;g++){const m=Fe/n,v=-qe+g*m,S=r+r*Math.cos(v),y=o+o*Math.sin(v);S<i&&(i=S),y<l&&(l=y),S>a&&(a=S),y>c&&(c=y),s.push(new x(S,y))}const u=a-i,h=c-l,p=t-u,f=e-h;if(p!==0||f!==0)for(let g=0;g<s.length;g++){const m=s[g];m.x=(m.x-i)/u*t,m.y=(m.y-l)/h*e}return s}function xc(t,e,n,r){return t<r&&n<e}function Ur(t,e,n,r){const o=Math.max(t,n),s=Math.min(e,r);return o<=s?[o,s]:null}function M_(t,e,n){return(e.x-t.x)*(n.y-t.y)-(n.x-t.x)*(e.y-t.y)}function ur(t,e){let n=0,r,o;for(let s=0;s<e.length;s++){if(r=e[s],r.x===t.x&&r.y===t.y||(o=e[(s+1)%e.length],x.Dist(t,r)+x.Dist(t,o)===x.Dist(r,o)))return!0;r.y<=t.y?o.y>t.y&&M_(r,o,t)>0&&(n+=1):o.y<=t.y&&M_(r,o,t)<0&&(n-=1)}return n!==0}function $(t){return Math.round(t*1e4)/1e4}function Zo(t){return Math.round(t*100)/100}const A_=t=>Math.abs(t)<Number.MAX_SAFE_INTEGER;function zs(t,e,n){return n<0?ed(t,e):EA(t,e)}function lx(t,e,n,r){let o;if(Math.abs(t)>De){o=Zh(e,r);const s=Zh(r,n);return Math.abs(o)<Math.abs(s)?o/t:(t-s)/t}else{o=Zh(e,r);const s=o/t;return Math.sign(o)!==Math.sign(t)?Math.abs(s)>.5?1:0:s}}function MY(t,e,n,r){const o=2*((e-t)%Fe)%Fe-(e-t)%Fe;return r?(Fe-Math.abs(o))*(n?1:-1):o}function qw(t,e,n){const r=-2*(t.x*(e.y-n.y)-t.y*(e.x-n.x)+e.x*n.y-n.x*e.y),o=((t.x*t.x+t.y*t.y)*(n.y-e.y)+(e.x*e.x+e.y*e.y)*(t.y-n.y)+(n.x*n.x+n.y*n.y)*(e.y-t.y))/r,s=((t.x*t.x+t.y*t.y)*(e.x-n.x)+(e.x*e.x+e.y*e.y)*(n.x-t.x)+(n.x*n.x+n.y*n.y)*(t.x-e.x))/r;return!Number.isFinite(o)||!Number.isFinite(s)?null:new x(o,s)}function AY(t,e,n,r,o){if(n===null)return[x.From(t),x.From(e)];const s=[],i=x.Angle(n,t),a=x.Angle(n,e),l=ed(i,a);for(let c=0;c<o;c++){const u=c/(o-1),h=i+l*u,p=ra(n,r,h);s.push(p)}return s}const My=({brush:t,color:e,opacity:n,className:r})=>{const o=w.useRef(null);Kl(o,t.x,t.y);const s=$(Math.max(1,t.w)),i=$(Math.max(1,t.h));return d.jsx("svg",{className:"tl-overlays__item",ref:o,children:e?d.jsxs("g",{className:"tl-brush",opacity:n,children:[d.jsx("rect",{width:s,height:i,fill:e,opacity:.75}),d.jsx("rect",{width:s,height:i,fill:"none",stroke:e,opacity:.1})]}):d.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},j_={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Ay={duration:0,easing:At.easeInOutCubic},O_={CAMERA_MOVE:-10},jY=["top","right","bottom","left"],D_=0,Zw=2,oh=1,R_=5,OY=128;var jy={};const DY={},TA=An("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),xt={logPreventDefaults:An("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:An("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:An("logElementRemoves",{defaults:{all:!1}}),debugSvg:An("debugSvg",{defaults:{all:!1}}),showFps:An("showFps",{defaults:{all:!1}}),measurePerformance:An("measurePerformance",{defaults:{all:!1}}),throwToBlob:An("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:An("reconnectOnPing",{defaults:{all:!1}}),debugCursors:An("debugCursors",{defaults:{all:!1}}),forceSrgb:An("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:An("debugGeometry",{defaults:{all:!1}}),hideShapes:An("hideShapes",{defaults:{all:!1}}),editOnType:An("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const t=Element.prototype.removeChild;ii("element removal logging",()=>{xt.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),t.call(this,e)}:Element.prototype.removeChild=t})}function An(t,{defaults:e,shouldStoreForSession:n=!0}){return RY({name:t,defaults:e,shouldStoreForSession:n})}function RY(t){const e=$Y(t),n=t.shouldStoreForSession?LY(t.name):null,r=Mt(`debug:${t.name}`,n??e);return typeof window<"u"&&(t.shouldStoreForSession&&ii(`debug:${t.name}`,()=>{const o=r.get();o===e?ET(`tldraw_debug:${t.name}`):mw(`tldraw_debug:${t.name}`,JSON.stringify(o))}),Object.defineProperty(window,`tldraw${t.name.replace(/^[a-z]/,o=>o.toUpperCase())}`,{get(){return r.get()},set(o){r.set(o)},configurable:!0})),Object.assign(r,t)}function LY(t){try{return JSON.parse(IT(`tldraw_debug:${t}`)??"null")}catch{return null}}function Oy(t){try{return t()}catch{return null}}function $Y(t){switch(Oy(()=>jy.TLDRAW_ENV)??Oy(()=>jy.VERCEL_PUBLIC_TLDRAW_ENV)??Oy(()=>jy.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return t.defaults.production??t.defaults.all;case"preview":case"staging":return t.defaults.staging??t.defaults.all;default:return t.defaults.development??t.defaults.all}}function _f(t){if(t instanceof HTMLElement)return t;if(t.parentElement)return _f(t.parentElement);throw Error("Could not find a parent element of an HTML type!")}function we(t){t.preventDefault(),xt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",t)}function td(t,e){if(t.setPointerCapture(e.pointerId),xt.logPointerCaptures.get()){const n=TA.get();n.set(t,(n.get(t)??0)+1),console.warn("setPointerCapture called on element:",t,e)}}function nd(t,e){if(t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),xt.logPointerCaptures.get())){const n=TA.get();n.get(t)===1?n.delete(t):n.has(t)?n.set(t,n.get(t)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",t,e)}}const Ot=t=>t.stopPropagation(),nn=(t,e,n)=>{t&&t.style.setProperty(e,n)};function Bn(t){return t.isKilled=!0,{point:{x:t.clientX,y:t.clientY,z:t.pressure},shiftKey:t.shiftKey,altKey:t.altKey,ctrlKey:t.metaKey||t.ctrlKey,pointerId:t.pointerId,button:t.button,isPen:t.pointerType==="pen"}}function MA(){const t=F();return w.useMemo(function(){let r,o;function s(m){if(!m.isKilled){if(m.button===Zw){t.dispatch({type:"pointer",target:"canvas",name:"right_click",...Bn(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(td(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Bn(m)}))}}function i(m){m.isKilled||m.clientX===r&&m.clientY===o||(r=m.clientX,o=m.clientY,t.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Bn(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,o=m.clientY,nd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Bn(m)}))}function l(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!0:null})}function c(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!1:null})}function u(m){m.isKilled=!0,we(m)}function h(m){m.isKilled=!0,m.target instanceof HTMLElement&&m.target.tagName!=="A"&&m.target.tagName!=="TEXTAREA"&&!(t.getEditingShape()&&m.target.className.includes("tl-text-content"))&&we(m)}function p(m){we(m)}async function f(m){var S,y;if(we(m),!((y=(S=m.dataTransfer)==null?void 0:S.files)!=null&&y.length))return;const v=Array.from(m.dataTransfer.files);await t.putExternalContent({type:"files",files:v,point:t.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function g(m){Ot(m)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:h,onClick:g}},[t])}function FY(){const t=F();w.useEffect(()=>{let e=t.getInstanceState().isCoarsePointer;const n=i=>{const a=i.pointerType!=="mouse";e!==a&&(e=a,t.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",n,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),o=t.environment.isFirefox&&!t.environment.isAndroid&&!t.environment.isIos,s=()=>{const i=o?!1:r.matches;e===i&&(e=i,t.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",s),s()),()=>{window.removeEventListener("pointerdown",n,{capture:!0}),r&&r.removeEventListener("change",s)}},[t])}const AA=w.createContext(null);function NY({container:t,children:e}){return d.jsx(AA.Provider,{value:t,children:e})}function Lt(){return nr(w.useContext(AA),"useContainer used outside of <Tldraw />")}function zY(){const t=F(),e=Lt(),n=U("isFocused",()=>t.getIsFocused(),[t]);w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=l=>{l.type==="change"&&o()};i.addEventListener?i.addEventListener("change",o):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",o):i.removeListener&&i.removeListener(a)},t.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{r==null||r()}},[t]),w.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(t.isIn("zoom")||!t.getPath().endsWith(".idle"))&&!sh()&&we(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){we(a);return}break}case"Tab":{if(sh()||t.getIsMenuOpen())return;break}case",":return;case"Escape":{if((t.getEditingShape()||t.getSelectedShapeIds().length>0)&&we(a),t.getOpenMenus().length>0)return;t.inputs.keys.has("Escape")||(t.inputs.keys.add("Escape"),t.cancel(),e.focus());return}default:if(sh()||t.getIsMenuOpen())return}const l={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};t.dispatch(l)},o=a=>{if(a.isKilled||(a.isKilled=!0,sh()||t.getIsMenuOpen())||a.key===",")return;const l={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};t.dispatch(l)};function s(a){var l,c;if(e.contains(a.target)){const u=a.touches[0].pageX,h=a.touches[0].radiusX||0;(u-h<10||u+h>t.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),we(a))}}const i=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&we(a)};return e.addEventListener("touchstart",s,{passive:!1}),e.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",we),document.addEventListener("gesturechange",we),document.addEventListener("gestureend",we),e.addEventListener("keydown",r),e.addEventListener("keyup",o),()=>{e.removeEventListener("touchstart",s),e.removeEventListener("wheel",i),document.removeEventListener("gesturestart",we),document.removeEventListener("gesturechange",we),document.removeEventListener("gestureend",we),e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}},[t,e,n])}const BY=["input","select","button","textarea"];function sh(){const{activeElement:t}=document;return!!(t&&(t.getAttribute("contenteditable")||BY.indexOf(t.tagName.toLowerCase())>-1))}const UY=["textarea","input"];function HY(t){const e=F();w.useEffect(()=>{const n=t.current;if(!n)return;const r=o=>{var s;if(o instanceof PointerEvent&&o.pointerType==="pen"){o.isKilled=!0;const{target:i}=o;if(UY.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||e.isIn("select.editing_shape"))return;we(o)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[e,t])}function KY(t,e,n){return Math.max(e,Math.min(t,n))}const Gt={toVector(t,e){return t===void 0&&(t=e),Array.isArray(t)?t:[t,t]},add(t,e){return[t[0]+e[0],t[1]+e[1]]},sub(t,e){return[t[0]-e[0],t[1]-e[1]]},addTo(t,e){t[0]+=e[0],t[1]+=e[1]},subTo(t,e){t[0]-=e[0],t[1]-=e[1]}};function L_(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function $_(t,e,n,r=.15){return r===0?KY(t,e,n):t<e?-L_(e-t,n-e,r)+e:t>n?+L_(t-n,n-e,r)+n:t}function WY(t,[e,n],[r,o]){const[[s,i],[a,l]]=t;return[$_(e,s,i,r),$_(n,a,l,o)]}function GY(t,e){if(typeof t!="object"||t===null)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function VY(t){var e=GY(t,"string");return typeof e=="symbol"?e:String(e)}function on(t,e,n){return e=VY(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function F_(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function dt(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?F_(Object(n),!0).forEach(function(r){on(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):F_(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const jA={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 N_(t){return t?t[0].toUpperCase()+t.slice(1):""}const YY=["enter","leave"];function XY(t=!1,e){return t&&!YY.includes(e)}function qY(t,e="",n=!1){const r=jA[t],o=r&&r[e]||e;return"on"+N_(t)+N_(o)+(XY(n,o)?"Capture":"")}const ZY=["gotpointercapture","lostpointercapture"];function QY(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=ZY.includes(e)?"capturecapture":"capture",o=!!~e.indexOf(r);return o&&(e=e.replace("capture","")),{device:e,capture:o,passive:n}}function JY(t,e=""){const n=jA[t],r=n&&n[e]||e;return t+r}function OA(t){return"touches"in t}function eX(t){return OA(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function tX(t){return Array.from(t.touches).filter(e=>{var n,r;return e.target===t.currentTarget||((n=t.currentTarget)===null||n===void 0||(r=n.contains)===null||r===void 0?void 0:r.call(n,e.target))})}function cx(t,e){try{const n=e.clientX-t.clientX,r=e.clientY-t.clientY,o=(e.clientX+t.clientX)/2,s=(e.clientY+t.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[o,s]}}catch{}return null}function nX(t){return tX(t).map(e=>e.identifier)}function z_(t,e){const[n,r]=Array.from(t.touches).filter(o=>e.includes(o.identifier));return cx(n,r)}const B_=40,U_=800;function DA(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=B_,n*=B_):r===2&&(e*=U_,n*=U_),[e,n]}function rX(t){const e={};if("buttons"in t&&(e.buttons=t.buttons),"shiftKey"in t){const{shiftKey:n,altKey:r,metaKey:o,ctrlKey:s}=t;Object.assign(e,{shiftKey:n,altKey:r,metaKey:o,ctrlKey:s})}return e}function If(t,...e){return typeof t=="function"?t(...e):t}function oX(){}function sX(...t){return t.length===0?oX:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function H_(t,e){return Object.assign({},e,t||{})}const iX=32;class RA{constructor(e,n,r){this.ctrl=e,this.args=n,this.key=r,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(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:n,ingKey:r,args:o}=this;n[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=o,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 n=this.state,r=this.config;n._active||(this.reset(),this.computeInitial(),n._active=!0,n.target=e.target,n.currentTarget=e.currentTarget,n.lastOffset=r.from?If(r.from,n):n.offset,n.offset=n.lastOffset,n.startTime=n.timeStamp=e.timeStamp)}computeValues(e){const n=this.state;n._values=e,n.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:n,config:r,shared:o}=this;n.args=this.args;let s=0;if(e&&(n.event=e,r.preventDefault&&e.cancelable&&n.event.preventDefault(),n.type=e.type,o.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,o.locked=!!document.pointerLockElement,Object.assign(o,rX(e)),o.down=o.pressed=o.buttons%2===1||o.touches>0,s=e.timeStamp-n.timeStamp,n.timeStamp=e.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const I=n._delta.map(Math.abs);Gt.addTo(n._distance,I)}this.axisIntent&&this.axisIntent(e);const[i,a]=n._movement,[l,c]=r.threshold,{_step:u,values:h}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[I,T]=h;p[0]=u[0]!==!1?I-u[0]:0,p[1]=u[1]!==!1?T-u[1]:0}else p[0]=u[0]!==!1?i-u[0]:0,p[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(p);const f=n.offset,g=n._active&&!n._blocked||n.active;g&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=o[this.ingKey]=n._active,e&&(n.first&&("bounds"in r&&(n._bounds=If(r.bounds,n)),this.setup&&this.setup()),n.movement=p,this.computeOffset()));const[m,v]=n.offset,[[S,y],[b,P]]=n._bounds;n.overflow=[m<S?-1:m>y?1:0,v<b?-1:v>P?1:0],n._movementBound[0]=n.overflow[0]?n._movementBound[0]===!1?n._movement[0]:n._movementBound[0]:!1,n._movementBound[1]=n.overflow[1]?n._movementBound[1]===!1?n._movement[1]:n._movementBound[1]:!1;const C=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=WY(n._bounds,n.offset,C),n.delta=Gt.sub(n.offset,f),this.computeMovement(),g&&(!n.last||s>iX)){n.delta=Gt.sub(n.offset,f);const I=n.delta.map(Math.abs);Gt.addTo(n.distance,I),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&s>0&&(n.velocity=[I[0]/s,I[1]/s],n.timeDelta=s)}}emit(){const e=this.state,n=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const o=this.handler(dt(dt(dt({},n),e),{},{[this.aliasKey]:e.values}));o!==void 0&&(e.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function aX([t,e],n){const r=Math.abs(t),o=Math.abs(e);if(r>o&&r>n)return"x";if(o>r&&o>n)return"y"}class lX extends RA{constructor(...e){super(...e),on(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=Gt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Gt.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const n=this.state,r=this.config;if(!n.axis&&e){const o=typeof r.axisThreshold=="object"?r.axisThreshold[eX(e)]:r.axisThreshold;n.axis=aX(n._movement,o)}n._blocked=(r.lockDirection||!!r.axis)&&!n.axis||!!r.axis&&r.axis!==n.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 cX=t=>t,K_=.15,LA={enabled(t=!0){return t},eventOptions(t,e,n){return dt(dt({},n.shared.eventOptions),t)},preventDefault(t=!1){return t},triggerAllEvents(t=!1){return t},rubberband(t=0){switch(t){case!0:return[K_,K_];case!1:return[0,0];default:return Gt.toVector(t)}},from(t){if(typeof t=="function")return t;if(t!=null)return Gt.toVector(t)},transform(t,e,n){const r=t||n.shared.transform;return this.hasCustomTransform=!!r,r||cX},threshold(t){return Gt.toVector(t,0)}},uX=0,rd=dt(dt({},LA),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=uX){return t},bounds(t={}){if(typeof t=="function")return s=>rd.bounds(t(s));if("current"in t)return()=>t.current;if(typeof HTMLElement=="function"&&t instanceof HTMLElement)return t;const{left:e=-1/0,right:n=1/0,top:r=-1/0,bottom:o=1/0}=t;return[[e,n],[r,o]]}}),od=typeof window<"u"&&window.document&&window.document.createElement;function $A(){return od&&"ontouchstart"in window}function dX(){return $A()||od&&window.navigator.maxTouchPoints>1}function hX(){return od&&"onpointerdown"in window}function pX(){return od&&"exitPointerLock"in window.document}function fX(){try{return"constructor"in GestureEvent}catch{return!1}}const Er={isBrowser:od,gesture:fX(),touch:$A(),touchscreen:dX(),pointer:hX(),pointerLock:pX()},gX=250,mX=180,yX=.5,SX=50,vX=250,xX=10,W_={mouse:0,touch:0,pen:8};dt(dt({},rd),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&Er.pointerLock,Er.touch&&n?"touch":this.pointerLock?"mouse":Er.pointer&&!o?"pointer":Er.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?gX:void 0,!(!Er.touchscreen||n===!1))return t||(n!==void 0?"y":void 0)},pointerCapture(t,e,{pointer:{capture:n=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&n},threshold(t,e,{filterTaps:n=!1,tapsThreshold:r=3,axis:o=void 0}){const s=Gt.toVector(t,n?r:o?1:0);return this.filterTaps=n,this.tapsThreshold=r,s},swipe({velocity:t=yX,distance:e=SX,duration:n=vX}={}){return{velocity:this.transform(Gt.toVector(t)),distance:this.transform(Gt.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return mX;case!1:return 0;default:return t}},axisThreshold(t){return t?dt(dt({},W_),t):W_},keyboardDisplacement(t=xX){return t}});function FA(t){const[e,n]=t.overflow,[r,o]=t._delta,[s,i]=t._direction;(e<0&&r>0&&s<0||e>0&&r<0&&s>0)&&(t._movement[0]=t._movementBound[0]),(n<0&&o>0&&i<0||n>0&&o<0&&i>0)&&(t._movement[1]=t._movementBound[1])}const wX=30,bX=100;class PX extends RA{constructor(...e){super(...e),on(this,"ingKey","pinching"),on(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:n,lastOffset:r}=this.state;e==="wheel"?this.state.offset=Gt.add(n,r):this.state.offset=[(1+n[0])*r[0],n[1]+r[1]]}computeMovement(){const{offset:e,lastOffset:n}=this.state;this.state.movement=[e[0]/n[0],e[1]-n[1]]}axisIntent(){const e=this.state,[n,r]=e._movement;if(!e.axis){const o=Math.abs(n)*wX-Math.abs(r);o<0?e.axis="angle":o>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 n=this.state,r=this.ctrl.touchIds;if(n._active&&n._touchIds.every(s=>r.has(s))||r.size<2)return;this.start(e),n._touchIds=Array.from(r).slice(0,2);const o=z_(e,n._touchIds);o&&this.pinchStart(e,o)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const n=this.state,r=n._pointerEvents,o=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>o.has(i))||(r.size<2&&r.set(e.pointerId,e),n._pointerEvents.size<2))return;this.start(e);const s=cx(...Array.from(r.values()));s&&this.pinchStart(e,s)}pinchStart(e,n){const r=this.state;r.origin=n.origin,this.computeValues([n.distance,n.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const n=z_(e,this.state._touchIds);n&&this.pinchMove(e,n)}pointerMove(e){const n=this.state._pointerEvents;if(n.has(e.pointerId)&&n.set(e.pointerId,e),!this.state._active)return;const r=cx(...Array.from(n.values()));r&&this.pinchMove(e,r)}pinchMove(e,n){const r=this.state,o=r._values[1],s=n.angle-o;let i=0;Math.abs(s)>270&&(i+=Math.sign(s)),this.computeValues([n.distance,n.angle-360*i]),r.origin=n.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(n=>!this.ctrl.touchIds.has(n))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const n=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}n._pointerEvents.has(e.pointerId)&&n._pointerEvents.delete(e.pointerId),n._active&&n._pointerEvents.size<2&&(n._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const n=this.state;n._active||(this.start(e),this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const n=this.state;this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY];const r=n._movement;n._movement=[e.scale-1,e.rotation],n._delta=Gt.sub(n._movement,r),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const n=this.config.modifierKey;n&&(Array.isArray(n)?!n.find(r=>e[r]):!e[n])||(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=[-DA(e)[1]/bX*r.offset[0],0],Gt.addTo(r._movement,r._delta),FA(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 n=this.config.device;n&&(e(n,"start",this[n+"Start"].bind(this)),e(n,"change",this[n+"Move"].bind(this)),e(n,"end",this[n+"End"].bind(this)),e(n,"cancel",this[n+"End"].bind(this)),e("lostPointerCapture","",this[n+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const CX=dt(dt({},LA),{},{device(t,e,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!Er.touch&&Er.gesture)return"gesture";if(Er.touch&&r)return"touch";if(Er.touchscreen){if(Er.pointer)return"pointer";if(Er.touch)return"touch"}},bounds(t,e,{scaleBounds:n={},angleBounds:r={}}){const o=i=>{const a=H_(If(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=H_(If(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[o(),s()]:i=>[o(i),s(i)]},threshold(t,e,n){return this.lockDirection=n.axis==="lock",Gt.toVector(t,this.lockDirection?[.1,3]:0)},modifierKey(t){return t===void 0?"ctrlKey":t},pinchOnWheel(t=!0){return t}});dt(dt({},rd),{},{mouseOnly:(t=!0)=>t});class _X extends lX{constructor(...e){super(...e),on(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 n=this.state;n._delta=DA(e),Gt.addTo(n._movement,n._delta),FA(n),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 IX=rd;dt(dt({},rd),{},{mouseOnly:(t=!0)=>t});const Qw=new Map,ux=new Map;function EX(t){Qw.set(t.key,t.engine),ux.set(t.key,t.resolver)}const kX={key:"pinch",engine:PX,resolver:CX},TX={key:"wheel",engine:_X,resolver:IX};function MX(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,s;for(s=0;s<r.length;s++)o=r[s],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}function AX(t,e){if(t==null)return{};var n=MX(t,e),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(o=0;o<s.length;o++)r=s[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}const jX={target(t){if(t)return()=>"current"in t?t.current:t},enabled(t=!0){return t},window(t=Er.isBrowser?window:void 0){return t},eventOptions({passive:t=!0,capture:e=!1}={}){return{passive:t,capture:e}},transform(t){return t}},OX=["target","eventOptions","window","enabled","transform"];function Qh(t={},e){const n={};for(const[r,o]of Object.entries(e))switch(typeof o){case"function":n[r]=o.call(n,t[r],r,t);break;case"object":n[r]=Qh(t[r],o);break;case"boolean":o&&(n[r]=t[r]);break}return n}function DX(t,e,n={}){const r=t,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=AX(r,OX);if(n.shared=Qh({target:o,eventOptions:s,window:i,enabled:a,transform:l},jX),e){const u=ux.get(e);n[e]=Qh(dt({shared:n.shared},c),u)}else for(const u in c){const h=ux.get(u);h&&(n[u]=Qh(dt({shared:n.shared},c[u]),h))}return n}class NA{constructor(e,n){on(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=n}add(e,n,r,o,s){const i=this._listeners,a=JY(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=dt(dt({},l),s);e.addEventListener(a,o,c);const u=()=>{e.removeEventListener(a,o,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class RX{constructor(){on(this,"_timeouts",new Map)}add(e,n,r=140,...o){this.remove(e),this._timeouts.set(e,window.setTimeout(n,r,...o))}remove(e){const n=this._timeouts.get(e);n&&window.clearTimeout(n)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class LX{constructor(e){on(this,"gestures",new Set),on(this,"_targetEventStore",new NA(this)),on(this,"gestureEventStores",{}),on(this,"gestureTimeoutStores",{}),on(this,"handlers",{}),on(this,"config",{}),on(this,"pointerIds",new Set),on(this,"touchIds",new Set),on(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),$X(this,e)}setEventIds(e){if(OA(e))return this.touchIds=new Set(nX(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,n){this.handlers=e,this.nativeHandlers=n}applyConfig(e,n){this.config=DX(e,n,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 n=this.config.shared,r={};let o;if(!(n.target&&(o=n.target(),!o))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],l=G_(r,a.eventOptions,!!o);if(a.enabled){const c=Qw.get(i);new c(this,e,i).bind(l)}}const s=G_(r,n.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](dt(dt({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const s in r)r[s]=sX(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=QY(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function Ca(t,e){t.gestures.add(e),t.gestureEventStores[e]=new NA(t,e),t.gestureTimeoutStores[e]=new RX}function $X(t,e){e.drag&&Ca(t,"drag"),e.wheel&&Ca(t,"wheel"),e.scroll&&Ca(t,"scroll"),e.move&&Ca(t,"move"),e.pinch&&Ca(t,"pinch"),e.hover&&Ca(t,"hover")}const G_=(t,e,n)=>(r,o,s,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:e.capture,h=(c=i.passive)!==null&&c!==void 0?c:e.passive;let p=a?r:qY(r,o,u);n&&h&&(p+="Passive"),t[p]=t[p]||[],t[p].push(s)},FX=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function NX(t){const e={},n={},r=new Set;for(let o in t)FX.test(o)?(r.add(RegExp.lastMatch),n[o]=t[o]):e[o]=t[o];return[n,e,r]}function _a(t,e,n,r,o,s){if(!t.has(n)||!Qw.has(r))return;const i=n+"Start",a=n+"End",l=c=>{let u;return c.first&&i in e&&e[i](c),n in e&&(u=e[n](c)),c.last&&a in e&&e[a](c),u};o[r]=l,s[r]=s[r]||{}}function zX(t,e){const[n,r,o]=NX(t),s={};return _a(o,n,"onDrag","drag",s,e),_a(o,n,"onWheel","wheel",s,e),_a(o,n,"onScroll","scroll",s,e),_a(o,n,"onPinch","pinch",s,e),_a(o,n,"onMove","move",s,e),_a(o,n,"onHover","hover",s,e),{handlers:s,config:e,nativeHandlers:r}}function BX(t,e={},n,r){const o=Ie.useMemo(()=>new LX(t),[]);if(o.applyHandlers(t,r),o.applyConfig(e,n),Ie.useEffect(o.effect.bind(o)),Ie.useEffect(()=>o.clean.bind(o),[]),e.target===void 0)return o.bind.bind(o)}function UX(t){return t.forEach(EX),function(n,r){const{handlers:o,nativeHandlers:s,config:i}=zX(n,r||{});return BX(o,i,void 0,s)}}const V_=10,HX=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function zA(t){let{deltaY:e,deltaX:n}=t,r=0;return t.ctrlKey||t.altKey||t.metaKey?r=(Math.abs(e)>V_?V_*Math.sign(e):e)/100:t.shiftKey&&!HX&&(n=e,e=0),{x:-n,y:-e,z:-r}}const KX=UX([TX,kX]);let Ia;const WX=t=>Ia===void 0?(Ia=t,!1):t-Ia>120&&t-Ia<160?(Ia=t,!0):(Ia=t,!1);function GX(t){const e=F(),n=w.useMemo(()=>{let r="not sure";const o=({event:m})=>{if(!e.getInstanceState().isFocused||(r="not sure",WX(Date.now())))return;const v=e.getEditingShapeId();if(v){const b=e.getShape(v);if(b&&e.getShapeUtil(b).canScroll(b)){const C=e.getShapePageBounds(v);if(C!=null&&C.containsPoint(e.inputs.currentPagePoint))return}}we(m),Ot(m);const S=zA(m);if(S.x===0&&S.y===0)return;const y={type:"wheel",name:"wheel",delta:S,point:new x(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey};e.dispatch(y)};let s=1,i=1,a=1,l=0;const c=new x,u=new x,h=m=>{const v=t.current;r="not sure";const{event:S,origin:y,da:b}=m;S instanceof WheelEvent||(S.target===v||v!=null&&v.contains(S.target))&&(u.x=y[0],u.y=y[1],c.x=y[0],c.y=y[1],s=b[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:y[0],y:y[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey}))},p=m=>{if(m&&(r="zooming"),r==="zooming")return;const v=Math.abs(l-s),S=x.Dist(c,u);switch(r){case"not sure":{v>24?r="zooming":S>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:h,onPinchEnd:m=>{const v=t.current,{event:S,origin:y,offset:b}=m;if(S instanceof WheelEvent||!(S.target===v||v!=null&&v.contains(S.target)))return;const P=b[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:y[0],y:y[1],z:P},delta:{x:y[0],y:y[1]},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey})})},onPinch:m=>{const v=t.current,{event:S,origin:y,offset:b,da:P}=m;if(S instanceof WheelEvent||!(S.target===v||v!=null&&v.contains(S.target)))return;const C=m.type==="gesturechange"||m.type==="gestureend";l=P[0];const I=y[0]-u.x,T=y[1]-u.y;switch(u.x=y[0],u.y=y[1],p(C),r){case"zooming":{a=b[0],e.dispatch({type:"pinch",name:"pinch",point:{x:y[0],y:y[1],z:a},delta:{x:I,y:T},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:y[0],y:y[1],z:i},delta:{x:I,y:T},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}}}}},[e,t]);KX(n,{target:t,eventOptions:{passive:!1},pinch:{from:()=>[e.getZoomLevel(),0],scaleBounds:()=>{const r=e.getBaseZoom(),o=e.getCameraOptions().zoomSteps,s=o[0]*r,i=o[o.length-1]*r;return{from:e.getZoomLevel(),max:i,min:s}}}})}function Dy(t,e,n){const r=t.getShape(e),o=t.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===n)}}function VX(t,e){const n=F();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=_f(l.currentTarget);td(c,l);const{shape:u,handle:h}=Dy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...Bn(l)})};let o,s;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===o&&l.clientY===s)return;o=l.clientX,s=l.clientY;const{shape:c,handle:u}=Dy(n,t,e);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...Bn(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=_f(l.currentTarget);nd(c,l);const{shape:u,handle:h}=Dy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...Bn(l)})}}},[n,t,e])}function YX(t){const e=F();w.useLayoutEffect(()=>{const n=nT(()=>{t.current&&e.updateViewportScreenBounds(t.current)},200,{trailing:!0}),r=e.timers.setInterval(n,1e3);window.addEventListener("resize",n);const o=new ResizeObserver(a=>{a[0].contentRect&&n()}),s=t.current;let i=null;return s&&(o.observe(s),i=XX(s),i.addEventListener("scroll",n)),()=>{clearInterval(r),window.removeEventListener("resize",n),o.disconnect(),i==null||i.removeEventListener("scroll",n),n.cancel()}},[e,t])}/*!
89
- * Author: excalidraw
90
- * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
91
- * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
92
- */const XX=t=>{let e=t.parentElement;for(;e;){if(e===document.body)return document;const{overflowY:n}=window.getComputedStyle(e);if(e.scrollHeight>e.clientHeight&&(n==="auto"||n==="scroll"||n==="overlay"))return e;e=e.parentElement}return document};class Z{constructor(e=0,n=0,r=0,o=0){E(this,"x",0);E(this,"y",0);E(this,"w",0);E(this,"h",0);this.x=e,this.y=n,this.w=r,this.h=o}get point(){return new x(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 midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get minY(){return this.y}set minY(e){this.y=e}get midY(){return this.y+this.h/2}get maxY(){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 x(this.midX,this.midY)}set center(e){this.minX=e.x-this.width/2,this.minY=e.y-this.height/2}get corners(){return[new x(this.minX,this.minY),new x(this.maxX,this.minY),new x(this.maxX,this.maxY),new x(this.minX,this.maxY)]}get cornersAndCenter(){return[new x(this.minX,this.minY),new x(this.maxX,this.minY),new x(this.maxX,this.maxY),new x(this.minX,this.maxY),this.center]}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 x(this.w,this.h)}toFixed(){return this.x=rh(this.x),this.y=rh(this.y),this.w=rh(this.w),this.h=rh(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,n=0,r=0,o=0){return this.x=e,this.y=n,this.w=r,this.h=o,this}expand(e){const n=Math.min(this.minX,e.minX),r=Math.min(this.minY,e.minY),o=Math.max(this.maxX,e.maxX),s=Math.max(this.maxY,e.maxY);return this.x=n,this.y=r,this.w=o-n,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:n,w:r,h:o}=this;return new Z(e,n,r,o)}translate(e){return this.x+=e.x,this.y+=e.y,this}snapToGrid(e){const n=Math.round(this.minX/e)*e,r=Math.round(this.minY/e)*e,o=Math.round(this.maxX/e)*e,s=Math.round(this.maxY/e)*e;this.minX=n,this.minY=r,this.width=Math.max(1,o-n),this.height=Math.max(1,s-r)}collides(e){return Z.Collides(this,e)}contains(e){return Z.Contains(this,e)}includes(e){return Z.Includes(this,e)}containsPoint(e,n=0){return Z.ContainsPoint(this,e,n)}getHandlePoint(e){switch(e){case"top_left":return new x(this.minX,this.minY);case"top_right":return new x(this.maxX,this.minY);case"bottom_left":return new x(this.minX,this.maxY);case"bottom_right":return new x(this.maxX,this.maxY);case"top":return new x(this.midX,this.minY);case"right":return new x(this.maxX,this.midY);case"bottom":return new x(this.midX,this.maxY);case"left":return new x(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(e,n,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:u,maxY:h}=this;switch(e){case"left":case"top_left":case"bottom_left":{l+=n;break}case"right":case"top_right":case"bottom_right":{u+=n;break}}switch(e){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{h+=r;break}}const p=(u-l)/(i-o),f=(h-c)/(a-s),g=p<0,m=f<0;if(g){const v=u;u=l,l=v}if(m){const v=h;h=c,c=v}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(h-c)}union(e){const n=Math.min(this.minX,e.x),r=Math.min(this.minY,e.y),o=Math.max(this.maxX,e.w+e.x),s=Math.max(this.maxY,e.h+e.y);return this.x=n,this.y=r,this.width=o-n,this.height=s-r,this}static From(e){return new Z(e.x,e.y,e.w,e.h)}static FromCenter(e,n){return new Z(e.x-n.x/2,e.y-n.y/2,n.x,n.y)}static FromPoints(e){if(e.length===0)return new Z;let n=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,l=e.length;a<l;a++)i=e[a],n=Math.min(i.x,n),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new Z(n,r,o-n,s-r)}static Expand(e,n){const r=Math.min(n.minX,e.minX),o=Math.min(n.minY,e.minY),s=Math.max(n.maxX,e.maxX),i=Math.max(n.maxY,e.maxY);return new Z(r,o,s-r,i-o)}static ExpandBy(e,n){return new Z(e.minX-n,e.minY-n,e.width+n*2,e.height+n*2)}static Collides(e,n){return!(e.maxX<n.minX||e.minX>n.maxX||e.maxY<n.minY||e.minY>n.maxY)}static Contains(e,n){return e.minX<n.minX&&e.minY<n.minY&&e.maxY>n.maxY&&e.maxX>n.maxX}static Includes(e,n){return Z.Collides(e,n)||Z.Contains(e,n)}static ContainsPoint(e,n,r=0){return!(n.x<e.minX-r||n.y<e.minY-r||n.x>e.maxX+r||n.y>e.maxY+r)}static Common(e){let n=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<e.length;i++){const a=e[i];n=Math.min(n,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new Z(n,r,o-n,s-r)}static Sides(e,n=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,n,r,o,s=!1){const{minX:i,minY:a,maxX:l,maxY:c}=e;let{minX:u,minY:h,maxX:p,maxY:f}=e;switch(n){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(n){case"top":case"top_left":case"top_right":{h+=o;break}case"bottom":case"bottom_left":case"bottom_right":{f+=o;break}}const g=(p-u)/(l-i),m=(f-h)/(c-a),v=g<0,S=m<0;if(s){const b=(l-i)/(c-a),P=Math.abs(p-u),C=Math.abs(f-h),I=P*(m<0?1:-1)*(1/b),T=C*(g<0?1:-1)*b,_=b<P/C;switch(n){case"top_left":{_?h=f+I:u=p+T;break}case"top_right":{_?h=f+I:p=u-T;break}case"bottom_right":{_?f=h-I:p=u-T;break}case"bottom_left":{_?f=h-I:u=p+T;break}case"bottom":case"top":{const k=(u+p)/2,M=C*b;u=k-M/2,p=k+M/2;break}case"left":case"right":{const k=(h+f)/2,M=P/b;h=k-M/2,f=k+M/2;break}}}if(v){const b=p;p=u,u=b}if(S){const b=f;f=h,h=b}const y=new Z(u,h,Math.abs(p-u),Math.abs(f-h));return{box:y,scaleX:+(y.width/e.width*(g>0?1:-1)).toFixed(5),scaleY:+(y.height/e.height*(m>0?1:-1)).toFixed(5)}}equals(e){return Z.Equals(this,e)}static Equals(e,n){return n.x===e.x&&n.y===e.y&&n.w===e.w&&n.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 Z(e.x,e.y,Math.max(1,e.w),Math.max(1,e.h))}}function qX(t){switch(t){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 t}}function ZX(t){switch(t){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 t}}function QX(t){return t==="top_left"||t==="top_right"||t==="bottom_right"||t==="bottom_left"}class q{constructor(e,n,r,o,s,i){E(this,"a",1);E(this,"b",0);E(this,"c",0);E(this,"d",1);E(this,"e",0);E(this,"f",0);this.a=e,this.b=n,this.c=r,this.d=o,this.e=s,this.f=i}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 n=e,{a:r,b:o,c:s,d:i,e:a,f:l}=this;return this.a=r*n.a+s*n.b,this.c=r*n.c+s*n.d,this.e=r*n.e+s*n.f+a,this.b=o*n.a+i*n.b,this.d=o*n.c+i*n.d,this.f=o*n.e+i*n.f+l,this}rotate(e,n,r){return e===0?this:n===void 0?this.multiply(q.Rotate(e)):this.translate(n,r).multiply(q.Rotate(e)).translate(-n,-r)}translate(e,n){return this.multiply(q.Translate(e,n))}scale(e,n){return this.multiply(q.Scale(e,n))}invert(){const{a:e,b:n,c:r,d:o,e:s,f:i}=this,a=e*o-n*r;return this.a=o/a,this.b=n/-a,this.c=r/-a,this.d=e/a,this.e=(o*s-r*i)/-a,this.f=(n*s-e*i)/a,this}applyToPoint(e){return q.applyToPoint(this,e)}applyToPoints(e){return q.applyToPoints(this,e)}rotation(){return q.Rotation(this)}point(){return q.Point(this)}decomposed(){return q.Decompose(this)}toCssString(){return q.toCssString(this)}setTo(e){return Object.assign(this,e),this}decompose(){return q.Decompose(this)}clone(){return new q(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new q(1,0,0,1,0,0)}static Translate(e,n){return new q(1,0,0,1,e,n)}static Rotate(e,n,r){if(e===0)return q.Identity();const o=Math.cos(e),s=Math.sin(e),i=new q(o,s,-s,o,0,0);return n===void 0?i:q.Compose(q.Translate(n,r),i,q.Translate(-n,-r))}static Scale(e,n,r,o){const s=new q(e,0,0,n,0,0);return r===void 0?s:q.Compose(q.Translate(r,o),s,q.Translate(-r,-o))}static Multiply(e,n){return{a:e.a*n.a+e.c*n.b,c:e.a*n.c+e.c*n.d,e:e.a*n.e+e.c*n.f+e.e,b:e.b*n.a+e.d*n.b,d:e.b*n.c+e.d*n.d,f:e.b*n.e+e.d*n.f+e.f}}static Inverse(e){const n=e.a*e.d-e.b*e.c;return{a:e.d/n,b:e.b/-n,c:e.c/-n,d:e.a/n,e:(e.d*e.e-e.c*e.f)/-n,f:(e.b*e.e-e.a*e.f)/n}}static Absolute(e){const n=e.a*e.d-e.b*e.c;return{a:e.d/n,b:e.b/-n,c:e.c/-n,d:e.a/n,e:(e.d*e.e-e.c*e.f)/n,f:(e.b*e.e-e.a*e.f)/-n}}static Compose(...e){const n=q.Identity();for(let r=0,o=e.length;r<o;r++)n.multiply(e[r]);return n}static Point(e){return new x(e.e,e.f)}static Rotation(e){let n;if(e.a!==0||e.c!==0){const r=(e.a*e.a+e.c*e.c)**.5;n=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;n=qe+Math.acos(e.b/r)*(e.d>0?-1:1)}else n=0;return ax(n)}static Decompose(e){let n,r,o;if(e.a!==0||e.c!==0){const s=(e.a*e.a+e.c*e.c)**.5;n=s,r=(e.a*e.d-e.b*e.c)/s,o=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;n=(e.a*e.d-e.b*e.c)/s,r=s,o=qe+Math.acos(e.b/s)*(e.d>0?-1:1)}else n=0,r=0,o=0;return{x:e.e,y:e.f,scaleX:n,scaleY:r,rotation:ax(o)}}static Smooth(e,n=1e10){return e.a=Math.round(e.a*n)/n,e.b=Math.round(e.b*n)/n,e.c=Math.round(e.c*n)/n,e.d=Math.round(e.d*n)/n,e.e=Math.round(e.e*n)/n,e.f=Math.round(e.f*n)/n,e}static toCssString(e){return`matrix(${$(e.a)}, ${$(e.b)}, ${$(e.c)}, ${$(e.d)}, ${$(e.e)}, ${$(e.f)})`}static applyToPoint(e,n){return new x(e.a*n.x+e.c*n.y+e.e,e.b*n.x+e.d*n.y+e.f,n.z)}static applyToXY(e,n,r){return[e.a*n+e.c*r+e.e,e.b*n+e.d*r+e.f]}static applyToPoints(e,n){return n.map(r=>new x(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,n){return new Z(e.e+n.minX,e.f+n.minY,n.width,n.height)}static From(e){return new q(e.a,e.b,e.c,e.d,e.e,e.f)}static Cast(e){return e instanceof q?e:q.From(e)}}class bi{constructor(e){E(this,"isFilled",!1);E(this,"isClosed",!0);E(this,"isLabel",!1);E(this,"debugColor");E(this,"ignore");E(this,"_vertices");E(this,"_bounds");E(this,"_area");E(this,"_length");this.isFilled=e.isFilled,this.isClosed=e.isClosed,this.isLabel=e.isLabel??!1,this.debugColor=e.debugColor,this.ignore=e.ignore}hitTestPoint(e,n=0,r=!1){return this.isClosed&&(this.isFilled||r)&&ur(e,this.vertices)?!0:x.Dist2(e,this.nearestPoint(e))<=n*n}distanceToPoint(e,n=!1){return e.dist(this.nearestPoint(e))*(this.isClosed&&(this.isFilled||n)&&ur(e,this.vertices)?-1:1)}distanceToLineSegment(e,n){if(e.equals(n))return this.distanceToPoint(e);const{vertices:r}=this;let o,s=1/0,i,a,l;for(let c=0;c<r.length;c++)a=r[c],l=x.NearestPointOnLineSegment(e,n,a,!0),i=x.Dist2(a,l),i<s&&(s=i,o=l);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&ur(o,this.vertices)?-s:s}hitTestLineSegment(e,n,r=0){return this.distanceToLineSegment(e,n)<=r}nearestPointOnLineSegment(e,n){const{vertices:r}=this;let o,s=1/0,i,a,l;for(let c=0;c<r.length;c++)a=r[c],l=x.NearestPointOnLineSegment(e,n,a,!0),i=x.Dist2(a,l),i<s&&(s=i,o=l);if(!o)throw Error("nearest point not found");return o}isPointInBounds(e,n=0){const{bounds:r}=this;return!(e.x<r.minX-n||e.y<r.minY-n||e.x>r.maxX+n||e.y>r.maxY+n)}get vertices(){return this._vertices||(this._vertices=this.getVertices()),this._vertices}getBounds(){return Z.FromPoints(this.vertices)}get bounds(){return this._bounds||(this._bounds=this.getBounds()),this._bounds}get center(){return this.bounds.center}get area(){return this._area||(this._area=this.getArea()),this._area}getArea(){if(!this.isClosed)return 0;const{vertices:e}=this;let n=0;for(let r=0,o=e.length;r<o;r++){const s=e[r],i=e[(r+1)%o];n+=s.x*i.y-i.x*s.y}return n/2}toSimpleSvgPath(){let e="";const{vertices:n}=this,r=n.length;if(r===0)return e;e+=`M${n[0].x},${n[0].y}`;for(let o=1;o<r;o++)e+=`L${n[o].x},${n[o].y}`;return this.isClosed&&(e+="Z"),e}get length(){return this._length?this._length:(this._length=this.getLength(),this._length)}getLength(){const{vertices:e}=this;let n,r=e[0],o=0;for(let s=1;s<e.length;s++)n=e[s],o+=x.Dist2(r,n),r=n;return Math.sqrt(o)}}class eo extends bi{constructor(n){super({...n,isClosed:!0,isFilled:!1});E(this,"children",[]);E(this,"ignoredChildren",[]);for(const r of n.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(n=>!n.isLabel).flatMap(n=>n.vertices)}nearestPoint(n){let r=1/0,o;const{children:s}=this;if(s.length===0)throw Error("no children");let i,a;for(const l of s)i=l.nearestPoint(n),a=x.Dist2(i,n),a<r&&(r=a,o=i);if(!o)throw Error("nearest point not found");return o}distanceToPoint(n,r=!1){return Math.min(...this.children.map((o,s)=>o.distanceToPoint(n,r||s>0)))}hitTestPoint(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestPoint(n,r,o))}hitTestLineSegment(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestLineSegment(n,r,o))}getArea(){return this.children[0].area}toSimpleSvgPath(){let n="";for(const o of this.children)n+=o.toSimpleSvgPath();const r=Z.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],l=i.dist(a),c=r[(o+1)%s],u=i.dist(c),h=i.clone().lrp(a,4/l),p=i,f=i.clone().lrp(c,4/u);n+=`M${h.x},${h.y} L${p.x},${p.y} L${f.x},${f.y} `}return n}getLength(){return this.children.reduce((n,r)=>r.isLabel?n:n+r.length,0)}getSvgPathData(){return this.children.map((n,r)=>n.isLabel?"":n.getSvgPathData(r===0)).join(" ")}}function JX(t=!0){const[e,n]=w.useState(0),r=F();w.useEffect(()=>{if(!t)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,t])}const eq=Rt(function({showStroke:e=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const o=F();JX(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return d.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=o.getShape(l.id);if(c.type==="group")return null;const u=o.getShapeGeometry(c),h=o.getShapePageTransform(c),p=o.getPointInShapeSpace(c,a),f=u.nearestPoint(p),g=u.distanceToPoint(p,!0),m=Math.abs(g)*s,v=g<0,{vertices:S}=u;return d.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&d.jsx("g",{stroke:u.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:d.jsx(BA,{geometry:u})}),n&&S.map((y,b)=>d.jsx("circle",{cx:y.x,cy:y.y,r:2/s,fill:`hsl(${Cl(b,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${b}`)),r&&m<150&&d.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-m/150,stroke:v?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function BA({geometry:t}){return t instanceof eo?d.jsx(d.Fragment,{children:[...t.children,...t.ignoredChildren].map((e,n)=>d.jsx(BA,{geometry:e},n))}):d.jsx("path",{d:t.toSimpleSvgPath()})}function UA(t){return Q8(t)}function HA(){const t=F(),e=bY("userIds",()=>UA(t.getCollaborators().map(n=>n.userId)).sort(),{isEqual:(n,r)=>{var o;return n.join(",")===((o=r.join)==null?void 0:o.call(r,","))}},[t]);return U(e)}function Ig(t){const e=F();return U(`latestPresence:${t}`,()=>e.getCollaborators().find(r=>r.userId===t),[e,t])??null}const tq=Rt(function(){return HA().map(n=>d.jsx(nq,{collaboratorId:n},n))}),nq=Rt(function({collaboratorId:e}){const n=F(),r=Ig(e),o=oq(n,r);if(!(r&&r.currentPageId===n.getCurrentPageId()))return null;switch(o){case"inactive":{const{followingUserId:s,highlightedUserIds:i}=n.getInstanceState();if(!(s===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=n.getInstanceState();if(r.followingUserId===n.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return d.jsx(rq,{latestPresence:r})}),rq=Rt(function({latestPresence:e}){const n=F(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=rt(),l=n.getZoomLevel(),c=n.getViewportPageBounds(),{userId:u,chatMessage:h,brush:p,scribbles:f,selectedShapeIds:g,userName:m,cursor:v,color:S}=e,y=!(v.x<c.minX-12/l||v.y<c.minY-16/l||v.x>c.maxX-12/l||v.y>c.maxY-16/l);return d.jsxs(d.Fragment,{children:[p&&r?d.jsx(r,{className:"tl-collaborator__brush",brush:p,color:S,opacity:.1},u+"_brush"):null,y&&s?d.jsx(s,{className:"tl-collaborator__cursor",point:v,color:S,zoom:l,name:m!=="New User"?m:null,chatMessage:h},u+"_cursor"):i?d.jsx(i,{className:"tl-collaborator__cursor-hint",point:v,color:S,zoom:l,viewport:c},u+"_cursor_hint"):null,o&&f.length?d.jsx(d.Fragment,{children:f.map(b=>d.jsx(o,{className:"tl-collaborator__scribble",scribble:b,color:S,zoom:l,opacity:b.color==="laser"?.5:.1},u+"_scribble_"+b.id))}):null,a&&g.filter(b=>!n.isShapeHidden(b)).map(b=>d.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:b,color:S,opacity:.5},u+"_"+b))]})});function Y_(t,e){return e>t.options.collaboratorInactiveTimeoutMs?"inactive":e>t.options.collaboratorIdleTimeoutMs?"idle":"active"}function oq(t,e){const n=w.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,o]=w.useState(()=>Y_(t,Date.now()-n.current));return w.useEffect(()=>{const s=t.timers.setInterval(()=>{o(Y_(t,Date.now()-n.current))},t.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[t]),e&&(n.current=e.lastActivityTimestamp),r}const KA=w.memo(function({id:e,shape:n,util:r,index:o,backgroundIndex:s,opacity:i}){const a=F(),{ShapeErrorFallback:l}=rt(),c=w.useRef(null),u=w.useRef(null),h=w.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});ss("set shape stuff",()=>{const g=a.getShape(e);if(!g)return;const m=h.current,v=a.getShapeClipPath(e)??"none";v!==m.clipPath&&(nn(c.current,"clip-path",v),nn(u.current,"clip-path",v),m.clipPath=v);const S=a.getShapePageTransform(e),y=q.toCssString(S),b=a.getShapeGeometry(g).bounds;y!==m.transform&&(nn(c.current,"transform",y),nn(u.current,"transform",y),m.transform=y);const P=Math.max(b.width,1),C=Math.max(b.height,1);(P!==m.width||C!==m.height)&&(nn(c.current,"width",P+"px"),nn(c.current,"height",C+"px"),nn(u.current,"width",P+"px"),nn(u.current,"height",C+"px"),m.width=P,m.height=C)},[a]),ss("set opacity and z-index",()=>{const g=c.current,m=u.current;nn(g,"opacity",i),nn(m,"opacity",i),nn(g,"z-index",o),nn(m,"z-index",s)},[i,o,s]),ss("set display",()=>{if(!a.getShape(e))return;const v=a.getCulledShapes().has(e);v!==h.current.isCulled&&(nn(c.current,"display",v?"none":"block"),nn(u.current,"display",v?"none":"block"),h.current.isCulled=v)},[a]);const p=w.useCallback(g=>a.annotateError(g,{origin:"shape",willCrashApp:!1}),[a]);if(!n)return null;const f="fill"in n.props&&n.props.fill!=="none";return d.jsxs(d.Fragment,{children:[r.backgroundComponent&&d.jsx("div",{ref:u,className:"tl-shape tl-shape-background","data-shape-type":n.type,draggable:!1,children:d.jsx(ju,{fallback:l,onError:p,children:d.jsx(GA,{shape:n,util:r})})}),d.jsx("div",{ref:c,className:"tl-shape","data-shape-type":n.type,"data-shape-is-filled":f,draggable:!1,children:d.jsx(ju,{fallback:l,onError:p,children:d.jsx(WA,{shape:n,util:r})})})]})}),WA=w.memo(function({shape:e,util:n}){return Cg("InnerShape:"+e.type,()=>n.component(n.editor.store.unsafeGetWithoutCapture(e.id)))},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta),GA=w.memo(function({shape:e,util:n}){return Cg("InnerShape:"+e.type,()=>{var r;return(r=n.backgroundComponent)==null?void 0:r.call(n,n.editor.store.unsafeGetWithoutCapture(e.id))})},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta);function sq({className:t}){const e=F(),{Background:n,SvgDefs:r,ShapeIndicators:o}=rt(),s=w.useRef(null),i=w.useRef(null),a=w.useRef(null),l=Lt();YX(s),zY(),FY(),GX(s),HY(s);const c=w.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});ss("position layers",function(){const{x:y,y:b,z:P}=e.getCamera();if(c.current.allowTextOutline&&e.environment.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&P<e.options.textShadowLod!==c.current.lodDisableTextOutline){const T=P<e.options.textShadowLod;l.style.setProperty("--tl-text-outline",T?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=T}const C=P>=1?Cl(P,[1,8],[.125,.5],!0):Cl(P,[.1,1],[-2,.125],!0),I=`scale(${$(P)}) translate(${$(y+C)}px,${$(b+C)}px)`;nn(i.current,"transform",I),nn(a.current,"transform",I)},[e,l]);const u=MA(),h=U("shapeSvgDefs",()=>{const S=new Map;for(const y of ct(e.shapeUtils)){if(!y)return;const b=y.getCanvasSvgDefs();for(const{key:P,component:C}of b)S.has(P)||S.set(P,d.jsx(C,{},P))}return[...S.values()]},[e]),p=U("debug_shapes",()=>xt.hideShapes.get(),[xt]),f=U("debug_svg",()=>xt.debugSvg.get(),[xt]),g=U("debug_geometry",()=>xt.debugGeometry.get(),[xt]),m=U("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),v=U("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return d.jsxs(d.Fragment,{children:[d.jsxs("div",{ref:s,draggable:!1,"data-iseditinganything":m,"data-isselectinganything":v,className:le("tl-canvas",t),"data-testid":"canvas",...u,children:[d.jsx("svg",{className:"tl-svg-context",children:d.jsxs("defs",{children:[h,d.jsx(vq,{}),d.jsx(xq,{}),r&&d.jsx(r,{})]})}),n&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(n,{})}),d.jsx(aq,{}),d.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(Cq,{}),d.jsx(Pq,{}),p?null:f?d.jsx(gq,{}):d.jsx(yq,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:a,className:"tl-html-layer",children:[g?d.jsx(eq,{}):null,d.jsx(hq,{}),d.jsx(cq,{}),d.jsx(lq,{}),d.jsx(uq,{}),o&&d.jsx(o,{}),d.jsx(Sq,{}),d.jsx(dq,{}),d.jsx(bq,{}),d.jsx(tq,{})]})}),d.jsx(_q,{})]}),d.jsx(iq,{})]})}function iq(){const{InFrontOfTheCanvas:t}=rt();return t?d.jsx(t,{}):null}function aq(){const t=F(),e=U("gridSize",()=>t.getDocumentSettings().gridSize,[t]),{x:n,y:r,z:o}=U("camera",()=>t.getCamera(),[t]),s=U("isGridMode",()=>t.getInstanceState().isGridMode,[t]),{Grid:i}=rt();return i&&s?d.jsx(i,{x:n,y:r,z:o,size:e}):null}function lq(){const t=F(),e=U("scribbles",()=>t.getInstanceState().scribbles,[t]),n=U("zoomLevel",()=>t.getZoomLevel(),[t]),{Scribble:r}=rt();return r&&e.length?e.map(o=>d.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:n},o.id)):null}function cq(){const t=F(),e=U("brush",()=>t.getInstanceState().brush,[t]),{Brush:n}=rt();return n&&e?d.jsx(n,{className:"tl-user-brush",brush:e}):null}function uq(){const t=F(),e=U("zoomBrush",()=>t.getInstanceState().zoomBrush,[t]),{ZoomBrush:n}=rt();return n&&e?d.jsx(n,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function dq(){const t=F(),e=U("snapLines",()=>t.snaps.getIndicators(),[t]),n=U("zoomLevel",()=>t.getZoomLevel(),[t]),{SnapIndicator:r}=rt();return r&&e.length>0?e.map(o=>d.jsx(r,{className:"tl-user-snapline",line:o,zoom:n},o.id)):null}function hq(){const t=F(),e=U("handles shapeIdWithHandles",()=>{const{isReadonly:n,isChangingStyle:r}=t.getInstanceState();if(n||r)return!1;const o=t.getOnlySelectedShape();return!o||!t.getShapeHandles(o)?!1:o.id},[t]);return e?d.jsx(pq,{shapeId:e}):null}function pq({shapeId:t}){const e=F(),{Handles:n}=rt(),r=U("zoomLevel",()=>e.getZoomLevel(),[e]),o=U("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),s=U("handles transform",()=>e.getShapePageTransform(t),[e,t]),i=U("handles",()=>{const l=e.getShapeHandles(t);if(!l)return null;const c=(o?e.options.coarseHandleRadius:e.options.handleRadius)/r*2;return l.filter(u=>u.type!=="virtual"||!l.some(h=>h!==u&&h.type==="vertex"&&x.Dist(u,h)<c)).sort(u=>u.type==="vertex"?1:-1)},[e,r,o,t]),a=U("isHidden",()=>e.isShapeHidden(t),[e,t]);return!n||!i||!s||a?null:d.jsx(n,{children:d.jsx("g",{transform:q.toCssString(s),children:i.map(l=>d.jsx(fq,{shapeId:t,handle:l,zoom:r,isCoarse:o},l.id))})})}function fq({shapeId:t,handle:e,zoom:n,isCoarse:r}){const o=VX(t,e.id),{Handle:s}=rt();return s?d.jsx("g",{"aria-label":"handle",transform:`translate(${e.x}, ${e.y})`,...o,children:d.jsx(s,{shapeId:t,handle:e,zoom:n,isCoarse:r})}):null}function gq(){const t=F();return U("rendering shapes",()=>t.getRenderingShapes(),[t]).map(n=>d.jsxs(w.Fragment,{children:[d.jsx(KA,{...n}),d.jsx(wq,{id:n.id,mode:"iframe"})]},n.id+"_fragment"))}function mq(){const t=F(),e=w.useRef(new Set);return ss("reflow for culled shapes",()=>{const n=t.getCulledShapes();if(e.current.size===n.size&&[...n].every(o=>e.current.has(o)))return;e.current=n;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[t]),null}function yq(){const t=F(),e=U("rendering shapes",()=>t.getRenderingShapes(),[t]);return d.jsxs(d.Fragment,{children:[e.map(n=>d.jsx(KA,{...n},n.id+"_shape")),t.environment.isSafari&&d.jsx(mq,{})]})}function Sq(){const t=F(),{ShapeIndicator:e}=rt(),n=U("hinting shape ids",()=>iw(t.getHintingShapeIds()),[t]);return!n.length||!e?null:n.map(r=>d.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function vq(){return d.jsxs("g",{id:"cursor",children:[d.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),d.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function xq(){return d.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function wq({id:t,mode:e}){const n=F(),[r,o]=w.useState(null),s=U("is in root",()=>{const i=n.getShape(t);return(i==null?void 0:i.parentId)===n.getCurrentPageId()},[n,t]);return w.useEffect(()=>{if(!s)return;let i=null;const a=ii("shape to svg",async()=>{const l=Math.random();i=l;const u=n.isShapeOfType(t,"frame")?0:10;let h=n.getShapePageBounds(t);if(!h)return;h=h.clone().expandBy(u);const p=await n.getSvgString([t],{padding:u,background:n.getInstanceState().exportBackground});if(i!==l||!p)return;const f=`data:image/svg+xml;utf8,${encodeURIComponent(p.svg)}`;o({src:f,bounds:h})});return()=>{i=null,a()}},[n,t,s]),!s||!r?null:e==="iframe"?d.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"}}):d.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 bq(){const t=F(),e=U("selection rotation",()=>t.getSelectionRotation(),[t]),n=U("selection bounds",()=>t.getSelectionRotatedPageBounds(),[t]),{SelectionForeground:r}=rt();return!n||!r?null:d.jsx(r,{bounds:n,rotation:e})}function Pq(){const t=F(),e=U("selection rotation",()=>t.getSelectionRotation(),[t]),n=U("selection bounds",()=>t.getSelectionRotatedPageBounds(),[t]),{SelectionBackground:r}=rt();return!n||!r?null:d.jsx(r,{bounds:n,rotation:e})}function Cq(){const{OnTheCanvas:t}=rt();return t?d.jsx(t,{}):null}function _q(){const t=F(),e=U("camera state",()=>t.getCameraState(),[t]);return d.jsx("div",{className:le("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function Iq({className:t,zoom:e,point:n,color:r,viewport:o,opacity:s=1}){const i=w.useRef(null);return Kl(i,zt(n.x,o.minX+5/e,o.maxX-5/e),zt(n.y,o.minY+5/e,o.maxY-5/e),1/e,x.Angle(o.center,n)),d.jsxs("svg",{ref:i,className:le("tl-overlays__item",t),children:[d.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),d.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const X_=w.memo(function({className:e,zoom:n,point:r,color:o,name:s,chatMessage:i}){const a=w.useRef(null);return Kl(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n),r?d.jsxs("div",{ref:a,className:le("tl-overlays__item",e),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:"#cursor",color:o})}),i?d.jsxs(d.Fragment,{children:[s&&d.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),d.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&d.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function VA(){return w.useId().replace(/:/g,"_")}function Eq({x:t,y:e,z:n,size:r}){const o=`grid_${VA()}`,s=F(),{gridSteps:i}=s.options;return d.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[d.jsx("defs",{children:i.map(({min:a,mid:l,step:c},u)=>{const h=c*r*n,p=.5+t*n,f=.5+e*n,g=p>0?p%h:h+p%h,m=f>0?f%h:h+f%h,v=n<l?Cl(n,[a,l],[0,1]):1;return d.jsx("pattern",{id:`${o}_${c}`,width:h,height:h,patternUnits:"userSpaceOnUse",children:d.jsx("circle",{className:"tl-grid-dot",cx:g,cy:m,r:1,opacity:v})},u)})}),i.map(({step:a},l)=>d.jsx("rect",{width:"100%",height:"100%",fill:`url(#${o}_${a})`},l))]})}function kq({handle:t,isCoarse:e,className:n,zoom:r}){const o=F(),s=(e?o.options.coarseHandleRadius:o.options.handleRadius)/r;if(t.type==="clone"){const a=3/r,l=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,c=jY.indexOf(t.id);return d.jsxs("g",{className:le(`tl-handle tl-handle__${t.type}`,n),children:[d.jsx("circle",{className:"tl-handle__bg",r:s}),d.jsx("path",{className:"tl-handle__fg",d:l,transform:`rotate(${-90+90*c})`})]})}const i=(t.type==="create"&&e?3:4)/Math.max(r,.25);return d.jsxs("g",{className:le(`tl-handle tl-handle__${t.type}`,n),children:[d.jsx("circle",{className:"tl-handle__bg",r:s}),d.jsx("circle",{className:"tl-handle__fg",r:i})]})}const Tq=({children:t})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:t}),Mq=()=>{const{Spinner:t}=rt();return d.jsx(m1,{children:t?d.jsx(t,{}):null})};function Jw(t,e=!0){const n=t.length;if(n<2)return"";let r=t[0],o=t[1];if(n===2)return`M${je(r)}L${je(o)}`;let s="";for(let i=2,a=n-1;i<a;i++)r=t[i],o=t[i+1],s+=$n(r,o);return e?`M${$n(t[0],t[1])}Q${je(t[1])}${$n(t[1],t[2])}T${s}${$n(t[n-1],t[0])}${$n(t[0],t[1])}Z`:`M${je(t[0])}Q${je(t[1])}${$n(t[1],t[2])}${t.length>3?"T":""}${s}L${je(t[n-1])}`}function q_({scribble:t,zoom:e,color:n,opacity:r,className:o}){return t.points.length?d.jsx("svg",{className:o&&le("tl-overlays__item",o),children:d.jsx("path",{className:"tl-scribble",d:Jw(t.points,!1),stroke:n??`var(--color-${t.color})`,fill:"none",strokeWidth:8/e,opacity:r??t.opacity})}):null}function YA({bounds:t,rotation:e}){const n=w.useRef(null);return Kl(n,t.x,t.y,1,e),w.useLayoutEffect(()=>{const r=n.current;r&&(r.style.width=$(Math.max(1,t.width))+"px",r.style.height=$(Math.max(1,t.height))+"px")},[t.width,t.height]),d.jsx("div",{ref:n,className:"tl-selection__bg",draggable:!1})}function Aq({bounds:t,rotation:e}){const n=F(),r=w.useRef(null),o=U("only selected shape",()=>n.getOnlySelectedShape(),[n]),s=o?n.getShapeUtil(o).expandSelectionOutlinePx(o):0;return Kl(r,t==null?void 0:t.x,t==null?void 0:t.y,1,e,{x:-s,y:-s}),t=t.clone().expandBy(s).zeroFix(),d.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsx("rect",{className:le("tl-selection__fg__outline"),width:$(t.width),height:$(t.height)})})}const jq=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),Oq=({shape:t,util:e})=>Cg("Indicator: "+t.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(t.id))),Dq=({editor:t,id:e})=>{const n=U("shape for indicator",()=>t.store.get(e),[t,e]),{ShapeIndicatorErrorFallback:r}=rt();return!n||n.isLocked?null:d.jsx(ju,{fallback:r,onError:o=>t.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(Oq,{shape:n,util:t.getShapeUtil(n)},n.id)})},Z_=w.memo(function({shapeId:e,className:n,color:r,hidden:o,opacity:s}){const i=F(),a=w.useRef(null);return ss("indicator transform",()=>{const l=a.current;if(!l)return;const c=i.getShapePageTransform(e);c&&l.style.setProperty("transform",c.toCssString())},[i,e]),w.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",o?"none":"block")},[o]),d.jsx("svg",{ref:a,className:le("tl-overlays__item",n),children:d.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:d.jsx(Dq,{editor:i,id:e})})})}),Rq=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),XA=w.memo(function(){const e=F(),n=w.useRef(new Set),r=U("should display selected ids",()=>{const i=n.current,a=new Set;if(e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!e.getInstanceState().isChangingStyle){const l=e.getSelectedShapeIds();for(const c of l)a.add(c);if(e.isInAny("select.idle","select.editing_shape")){const c=e.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const u=e.getHoveredShapeId();u&&a.add(u)}}}if(i.size!==a.size)return n.current=a,a;for(const l of a)if(!i.has(l))return n.current=a,a;return i},[e]),o=U("rendering shapes",()=>e.getRenderingShapes(),[e]),{ShapeIndicator:s}=rt();return s?o.map(({id:i})=>d.jsx(s,{shapeId:i,hidden:!r.has(i)},i+"_indicator")):null});function Lq({points:t,zoom:e}){const n=2.5/e,r=t.reduce((p,f)=>Math.min(p,f.x),1/0),o=t.reduce((p,f)=>Math.max(p,f.x),-1/0),s=t.reduce((p,f)=>Math.min(p,f.y),1/0),i=t.reduce((p,f)=>Math.max(p,f.y),-1/0),a=t.some(p=>p.x===r&&p.y===s);let l,c,u,h;return a?(l=r,c=s,u=o,h=i):(l=r,c=i,u=o,h=s),d.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[d.jsx("line",{x1:l,y1:c,x2:u,y2:h}),t.map((p,f)=>d.jsx("g",{transform:`translate(${p.x},${p.y})`,children:d.jsx("path",{className:"tl-snap-point",d:`M ${-n},${-n} L ${n},${n} M ${-n},${n} L ${n},${-n}`})},f))]})}function $q({gaps:t,direction:e,zoom:n}){const r=3.5/n;let o=[-1/0,1/0],s=null;const i=e==="horizontal";for(const l of t){if(s=Ur(o[0],o[1],i?l.startEdge[0].y:l.startEdge[0].x,i?l.startEdge[1].y:l.startEdge[1].x),s)o=s;else continue;if(s=Ur(o[0],o[1],i?l.endEdge[0].y:l.endEdge[0].x,i?l.endEdge[1].y:l.endEdge[1].x),s)o=s;else continue}if(o===null)return null;const a=(o[0]+o[1])/2;return d.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:t.map(({startEdge:l,endEdge:c},u)=>d.jsx(w.Fragment,{children:i?d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),d.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),d.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),d.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),d.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),d.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),d.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},u))})}function Fq({className:t,line:e,zoom:n}){return d.jsx("svg",{className:le("tl-overlays__item",t),children:e.type==="points"?d.jsx(Lq,{...e,zoom:n}):e.type==="gaps"?d.jsx($q,{...e,zoom:n}):null})}function e1(){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const Nq=()=>null;function qA(t,e){const n=w.useRef(t);return e(t,n.current)?n.current:(n.current=t,t)}const zq=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:t9(t,e));function Bs(t){return qA(t,zq)}const Bq=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:pT(t,e));function sd(t){return qA(t,Bq)}const ZA=w.createContext(null);function Uq({overrides:t={},children:e}){const n=sd(t),r=w.useMemo(()=>({Background:_Y,SvgDefs:Nq,Brush:My,ZoomBrush:My,CollaboratorBrush:My,Cursor:X_,CollaboratorCursor:X_,CollaboratorHint:Iq,CollaboratorShapeIndicator:Z_,Grid:Eq,Scribble:q_,SnapIndicator:Fq,Handles:Tq,Handle:kq,CollaboratorScribble:q_,ErrorFallback:JA,ShapeErrorFallback:jq,ShapeIndicatorErrorFallback:Rq,Spinner:e1,SelectionBackground:YA,SelectionForeground:Aq,ShapeIndicators:XA,ShapeIndicator:Z_,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:sq,LoadingScreen:Mq,...n}),[n]);return d.jsx(ZA.Provider,{value:r,children:e})}function rt(){const t=w.useContext(ZA);if(!t)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return t}const Eg={openWindow(t,e){window.open(t,e,"noopener noreferrer")},refreshPage(){window.location.reload()},async hardReset(){var t;return await((t=window.__tldraw__hardReset)==null?void 0:t.call(window))}};function QA(){Eg.hardReset()}function Hq(){Eg.refreshPage()}const Kq="https://github.com/tldraw/tldraw/issues/new",JA=({error:t,editor:e})=>{const n=w.useRef(null),[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(!1);let c=null;try{c=rt().Canvas??null}catch{}const u=t instanceof Error?t.message:String(t),h=t instanceof Error?t.stack:null,p=U("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[f,g]=w.useState(null);w.useLayoutEffect(()=>{var C;p!==null&&g(p);let b=(C=n.current)==null?void 0:C.parentElement,P=!1;for(;b;){if(b.classList.contains("tl-theme__dark")||b.classList.contains("tl-theme__light")){P=!0;break}b=b.parentElement}if(P){g(null);return}typeof window<"u"&&"matchMedia"in window&&g(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),w.useEffect(()=>{if(s){const b=e==null?void 0:e.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(b)}},[s,e]);const m=()=>{const b=document.createElement("textarea");b.value=h??u,document.body.appendChild(b),b.select(),document.execCommand("copy"),b.remove(),i(!0)},v=()=>{Hq()},S=async()=>{QA()},y=new URL(Kq);return y.searchParams.set("title",u),y.searchParams.set("labels","bug"),y.searchParams.set("body",`Hey, I ran into an error while using tldraw:
93
-
94
- \`\`\`js
95
- ${h??u}
96
- \`\`\`
97
-
98
- My browser: ${navigator.userAgent}`),d.jsxs("div",{ref:n,className:le("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[d.jsx("div",{className:"tl-error-boundary__overlay"}),e&&d.jsx(Xw,{onError:_u,fallback:()=>null,children:d.jsx(_g.Provider,{value:e,children:d.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?d.jsx(c,{}):null})})}),d.jsx("div",{className:le("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Are you sure?"}),d.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),d.jsx("button",{className:"tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Something's gone wrong."}),d.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",d.jsx("a",{href:y.toString(),children:"create a GitHub issue"})," or"," ",d.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&d.jsxs(d.Fragment,{children:["Message:",d.jsx("h4",{children:d.jsx("code",{children:u})}),"Stack trace:",d.jsxs("div",{className:"tl-error-boundary__content__error",children:[d.jsx("pre",{children:d.jsx("code",{children:h??u})}),d.jsx("button",{onClick:m,children:s?"Copied!":"Copy"})]})]}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),d.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[d.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),d.jsx("button",{className:"tl-error-boundary__refresh",onClick:v,children:"Refresh Page"})]})]})]})})]})},ej="TLDRAW_USER_DATA_v3",tj=Pe({id:me,name:me.nullable().optional(),locale:me.nullable().optional(),color:me.nullable().optional(),colorScheme:bg("light","dark","system").optional(),animationSpeed:pe.nullable().optional(),edgeScrollSpeed:pe.nullable().optional(),isSnapMode:xe.nullable().optional(),isWrapMode:xe.nullable().optional(),isDynamicSizeMode:xe.nullable().optional(),isPasteAtCursorMode:xe.nullable().optional()}),Go={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},t1=Math.max(...Object.values(Go));function Wq(t){t.version<Go.AddAnimationSpeed&&(t.user.animationSpeed=1),t.version<Go.AddIsSnapMode&&(t.user.isSnapMode=!1),t.version<Go.MakeFieldsNullable,t.version<Go.AddEdgeScrollSpeed&&(t.user.edgeScrollSpeed=1),t.version<Go.AddExcalidrawSelectMode&&(t.user.isWrapMode=!1),t.version<Go.AllowSystemColorScheme&&(t.user.isDarkMode===!0?t.user.colorScheme="dark":t.user.isDarkMode===!1&&(t.user.colorScheme="light"),delete t.user.isDarkMode),t.version<Go.AddDynamicSizeMode&&(t.user.isDynamicSizeMode=!1),t.version<Go.AddPasteAtCursor&&(t.user.isPasteAtCursorMode=!1),t.version=t1}const dx=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function nj(){return dx[Math.floor(Math.random()*dx.length)]}function Gq(){var t,e;return typeof window<"u"&&"matchMedia"in window?((e=(t=window.matchMedia)==null?void 0:t.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:e.matches)??!1:!1}const Ko=Object.freeze({name:"New User",locale:yY(),color:nj(),edgeScrollSpeed:1,animationSpeed:Gq()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"system"});function Ry(){return{id:Ke(),color:nj()}}function rj(t){if(t===null||typeof t!="object"||!("version"in t)||!("user"in t)||typeof t.version!="number")return Ry();const e=tt(t);Wq(e);try{return tj.validate(e.user)}catch{return Ry()}}function Vq(){const t=JSON.parse(fw(ej)||"null")??null;return rj(t)}const kg=Mt("globalUserData",null);function Yq(){gw(ej,JSON.stringify({version:t1,user:kg.get()}))}function oj(t){tj.validate(t),kg.set(t),Yq(),qq()}const Xq=typeof process<"u"&&!1,dl=typeof BroadcastChannel<"u"&&!Xq?new BroadcastChannel("tldraw-user-sync"):null;dl==null||dl.addEventListener("message",t=>{const e=t.data;(e==null?void 0:e.type)===ij&&(e==null?void 0:e.origin)!==sj()&&kg.set(rj(e.data))});let Ly=null;function sj(){return Ly===null&&(Ly=Ke()),Ly}const ij="tldraw-user-preferences-change";function qq(){dl==null||dl.postMessage({type:ij,origin:sj(),data:{user:aj(),version:t1}})}function aj(){let t=kg.get();return t||(t=Vq(),oj(t)),t}const Zq=G("defaultLocalStorageUserPrefs",()=>aj());function lj(t={}){return{userPreferences:t.userPreferences??Zq,setUserPreferences:t.setUserPreferences??oj}}var cj={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function o(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function s(l,c,u,h,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new o(u,h||l,p),g=n?n+c:c;return l._events[g]?l._events[g].fn?l._events[g]=[l._events[g],f]:l._events[g].push(f):(l._events[g]=f,l._eventsCount++),l}function i(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],u,h;if(this._eventsCount===0)return c;for(h in u=this._events)e.call(u,h)&&c.push(n?h.slice(1):h);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=n?n+c:c,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var p=0,f=h.length,g=new Array(f);p<f;p++)g[p]=h[p].fn;return g},a.prototype.listenerCount=function(c){var u=n?n+c:c,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,u,h,p,f,g){var m=n?n+c:c;if(!this._events[m])return!1;var v=this._events[m],S=arguments.length,y,b;if(v.fn){switch(v.once&&this.removeListener(c,v.fn,void 0,!0),S){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,u),!0;case 3:return v.fn.call(v.context,u,h),!0;case 4:return v.fn.call(v.context,u,h,p),!0;case 5:return v.fn.call(v.context,u,h,p,f),!0;case 6:return v.fn.call(v.context,u,h,p,f,g),!0}for(b=1,y=new Array(S-1);b<S;b++)y[b-1]=arguments[b];v.fn.apply(v.context,y)}else{var P=v.length,C;for(b=0;b<P;b++)switch(v[b].once&&this.removeListener(c,v[b].fn,void 0,!0),S){case 1:v[b].fn.call(v[b].context);break;case 2:v[b].fn.call(v[b].context,u);break;case 3:v[b].fn.call(v[b].context,u,h);break;case 4:v[b].fn.call(v[b].context,u,h,p);break;default:if(!y)for(C=1,y=new Array(S-1);C<S;C++)y[C-1]=arguments[C];v[b].fn.apply(v[b].context,y)}}return!0},a.prototype.on=function(c,u,h){return s(this,c,u,h,!1)},a.prototype.once=function(c,u,h){return s(this,c,u,h,!0)},a.prototype.removeListener=function(c,u,h,p){var f=n?n+c:c;if(!this._events[f])return this;if(!u)return i(this,f),this;var g=this._events[f];if(g.fn)g.fn===u&&(!p||g.once)&&(!h||g.context===h)&&i(this,f);else{for(var m=0,v=[],S=g.length;m<S;m++)(g[m].fn!==u||p&&!g[m].once||h&&g[m].context!==h)&&v.push(g[m]);v.length?this._events[f]=v.length===1?v[0]:v:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=n?n+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a})(cj);var Qq=cj.exports;const Jq=fi(Qq),hl="TLDRAW_TAB_ID_v2",Io=globalThis.window;function eZ(){return Io?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(Io.navigator.platform)||Io.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const Ef=Io?Io[hl]??IT(hl)??"TLDRAW_INSTANCE_STATE_V1_"+Ke():"<error>";Io&&(Io[hl]=Ef,eZ()?mw(hl,Ef):ET(hl));Io==null||Io.addEventListener("beforeunload",()=>{mw(hl,Ef)});const uj={Initial:0},Tg=Math.max(...Object.values(uj));function tZ(t){t.version<uj.Initial,t.version=Tg}const dj=Pe({version:pe,currentPageId:Mu.optional(),isFocusMode:xe.optional(),exportBackground:xe.optional(),isDebugMode:xe.optional(),isToolLocked:xe.optional(),isGridMode:xe.optional(),pageStates:Kt(Pe({pageId:Mu,camera:Pe({x:pe,y:pe,z:pe}).optional(),selectedShapeIds:Kt(Pr).optional(),focusedGroupId:Pr.nullable().optional()})).optional()});function nZ(t){if(!t||typeof t!="object")return console.warn("Invalid instance state"),null;if(!("version"in t)||typeof t.version!="number")return console.warn("No version in instance state"),null;t.version!==Tg&&(t=tt(t),tZ(t));try{return dj.validate(t)}catch(e){return console.warn(e),null}}function n1(t){const e=t.query.ids("page");return G("sessionStateSnapshot",()=>{const n=t.get(vn);if(!n)return null;const r=[...e.get()];return{version:Tg,currentPageId:n.currentPageId,exportBackground:n.exportBackground,isFocusMode:n.isFocusMode,isDebugMode:n.isDebugMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,pageStates:r.map(o=>{const s=t.get(Gr.createId(o)),i=t.get(xo.createId(o));return{pageId:o,camera:{x:(i==null?void 0:i.x)??0,y:(i==null?void 0:i.y)??0,z:(i==null?void 0:i.z)??1},selectedShapeIds:(s==null?void 0:s.selectedShapeIds)??[],focusedGroupId:(s==null?void 0:s.focusedGroupId)??null}})}})}function hx(t,e,n){const r=nZ(e);if(!r)return;const o=QM(t.get(vn)),s=n!=null&&n.forceOverwrite?r:o,i=n!=null&&n.forceOverwrite?o:r,a=t.schema.types.instance.create({id:vn,...o,currentPageId:r.currentPageId,isDebugMode:(s==null?void 0:s.isDebugMode)??(i==null?void 0:i.isDebugMode),isFocusMode:(s==null?void 0:s.isFocusMode)??(i==null?void 0:i.isFocusMode),isToolLocked:(s==null?void 0:s.isToolLocked)??(i==null?void 0:i.isToolLocked),isGridMode:(s==null?void 0:s.isGridMode)??(i==null?void 0:i.isGridMode),exportBackground:(s==null?void 0:s.exportBackground)??(i==null?void 0:i.exportBackground)});t.atomic(()=>{var l,c,u;for(const h of r.pageStates??[]){if(!t.has(h.pageId))continue;const p=xo.createId(h.pageId),f=Gr.createId(h.pageId),g=t.get(p),m=t.get(f);t.put([xo.create({id:p,x:((l=h.camera)==null?void 0:l.x)??(g==null?void 0:g.x),y:((c=h.camera)==null?void 0:c.y)??(g==null?void 0:g.y),z:((u=h.camera)==null?void 0:u.z)??(g==null?void 0:g.z)}),Gr.create({id:f,pageId:h.pageId,selectedShapeIds:h.selectedShapeIds??(m==null?void 0:m.selectedShapeIds),focusedGroupId:h.focusedGroupId??(m==null?void 0:m.focusedGroupId)})])}t.put([a]),t.ensureStoreIsUsable()})}function rZ(t){var o;const e=[];for(const s of Object.values(t))(o=s.typeName)!=null&&o.match(/^(instance.*|pointer|camera)$/)&&e.push(s);const n=e.filter(s=>s.typeName==="instance"&&s.id!==vn)[0];if(!n)return null;const r={version:Tg,currentPageId:n.currentPageId,exportBackground:!!n.exportBackground,isFocusMode:!!n.isFocusMode,isDebugMode:!!n.isDebugMode,isToolLocked:!!n.isToolLocked,isGridMode:!1,pageStates:e.filter(s=>s.typeName==="instance_page_state"&&s.instanceId===n.id).map(s=>{const i=t[s.cameraId]??{x:0,y:0,z:1};return{pageId:s.pageId,camera:{x:i.x,y:i.y,z:i.z},selectedShapeIds:s.selectedShapeIds,focusedGroupId:s.focusedGroupId}})};try{return dj.validate(r),r}catch{return null}}function hj(t,e,n){let r={};if("store"in e){const i=t.schema.migrateStoreSnapshot(e);if(i.type!=="success")throw new Error("Failed to migrate store snapshot: "+i.reason);r.document={schema:t.schema.serialize(),store:Jc(i.value,(a,{typeName:l})=>t.scopedTypes.document.has(l))}}else r=e;const o=QM(t.get(vn)),s=pj.get(t,n1).get();t.atomic(()=>{r.document&&t.loadStoreSnapshot(r.document),o&&t.update(vn,i=>({...i,...o})),s&&hx(t,s),r.session&&hx(t,r.session,{forceOverwrite:n==null?void 0:n.forceOverwriteSessionState})})}const pj=new Eo;function oZ(t){const n=pj.get(t,n1).get();if(!n)throw new Error("Session state is not ready yet");return{document:t.getStoreSnapshot(),session:n}}function fj(t){const e=[],n=new Set;for(const r of t){if(n.has(r.type))throw new Error(`Binding type "${r.type}" is defined more than once`);e.push(r),n.add(r.type)}return e}function li({children:t,className:e="",...n}){return d.jsx("svg",{...n,className:le("tl-svg-container",e),children:t})}function r1(t,e,n,r){const o=t.x-n.x,s=t.y-n.y,i=r.x-n.x,a=r.y-n.y,l=e.x-t.x,c=e.y-t.y,u=i*s-a*o,h=l*s-c*o,p=a*l-i*c;if(u===0||h===0||p===0)return null;if(p!==0){const f=u/p,g=h/p;if(0<=f&&f<=1&&0<=g&&g<=1)return x.AddXY(t,f*l,f*c)}return null}function id(t,e,n,r){const o=(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y),s=2*((e.x-t.x)*(t.x-n.x)+(e.y-t.y)*(t.y-n.y)),i=n.x*n.x+n.y*n.y+t.x*t.x+t.y*t.y-2*(n.x*t.x+n.y*t.y)-r*r,a=s*s-4*o*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-s+l)/(2*o),u=(-s-l)/(2*o);if((c<0||c>1)&&(u<0||u>1))return null;const h=[];return 0<=c&&c<=1&&h.push(x.Lrp(t,e,c)),0<=u&&u<=1&&h.push(x.Lrp(t,e,u)),h.length===0?null:h}function sZ(t,e,n){const r=[];let o;for(let s=0,i=n.length-1;s<i;s++)o=r1(t,e,n[s],n[s+1]),o&&r.push(o);return r.length===0?null:r}function o1(t,e,n){const r=[];let o;for(let s=1,i=n.length;s<i+1;s++)o=r1(t,e,n[s-1],n[s%n.length]),o&&r.push(o);return r.length===0?null:r}function iZ(t,e,n,r){let o=n.x-t.x,s=n.y-t.y;const i=Math.sqrt(o*o+s*s),a=(i*i-r*r+e*e)/(2*i),l=Math.sqrt(e*e-a*a);return o/=i,s/=i,[new x(t.x+o*a-s*l,t.y+s*a+o*l),new x(t.x+o*a+s*l,t.y+s*a-o*l)]}function px(t,e,n){const r=[];let o,s,i;for(let a=0,l=n.length;a<l;a++)o=n[a],s=n[(a+1)%n.length],i=id(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function Q_(t,e,n){const r=[];let o,s,i;for(let a=1,l=n.length;a<l;a++)o=n[a-1],s=n[a],i=id(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function ih(t,e,n){return(n.y-t.y)*(e.x-t.x)>(e.y-t.y)*(n.x-t.x)}function s1(t,e,n,r){return ih(t,n,r)!==ih(e,n,r)&&ih(t,e,n)!==ih(t,e,r)}function J_(t,e){const n=new Map;let r,o,s,i;for(let a=0,l=t.length;a<l;a++)if(r=t[a],ur(r,e)){const c=$y(r);n.has(c)||n.set(c,r)}for(let a=0,l=e.length;a<l;a++)if(r=e[a],ur(r,t)){const c=$y(r);n.has(c)||n.set(c,r)}for(let a=0,l=t.length;a<l;a++){r=t[a],o=t[(a+1)%t.length];for(let c=0,u=e.length;c<u;c++){s=e[c],i=e[(c+1)%e.length];const h=r1(r,o,s,i);if(h!==null){const p=$y(h);n.has(p)||n.set(p,h)}}}return n.size===0?null:aZ([...n.values()])}function $y(t){return`${t.x},${t.y}`}function aZ(t){const e=x.Average(t);return t.sort((n,r)=>x.Angle(e,n)-x.Angle(e,r))}function gj(t,e){let n,r,o,s;for(let i=0,a=t.length;i<a;i++){n=t[i],r=t[(i+1)%a];for(let l=0,c=e.length;l<c;l++)if(o=e[l],s=e[(l+1)%c],s1(n,r,o,s))return!0}return!1}function lZ(t,e){let n,r,o,s;for(let i=0,a=t.length;i<a;i++){n=t[i],r=t[(i+1)%a];for(let l=1,c=e.length;l<c;l++)if(o=e[l-1],s=e[l],s1(n,r,o,s))return!0}return!1}class es extends bi{constructor(n){super({...n,isClosed:!1,isFilled:!1});E(this,"start");E(this,"end");E(this,"d");E(this,"u");E(this,"ul");const{start:r,end:o}=n;this.start=r,this.end=o,this.d=r.clone().sub(o),this.u=this.d.clone().uni(),this.ul=this.u.len()}getLength(){return this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(n){const{start:r,end:o,u:s,ul:i}=this;if(i===0)return r;const a=x.Sub(n,r).dpr(s)/i,l=r.x+s.x*a;if(l<Math.min(r.x,o.x))return r.x<o.x?r:o;if(l>Math.max(r.x,o.x))return r.x>o.x?r:o;const c=r.y+s.y*a;return c<Math.min(r.y,o.y)?r.y<o.y?r:o:c>Math.max(r.y,o.y)?r.y>o.y?r:o:new x(l,c)}hitTestLineSegment(n,r,o=0){return s1(n,r,this.start,this.end)||this.distanceToLineSegment(n,r)<=o}getSvgPathData(n=!0){const{start:r,end:o}=this;return`${n?`M${r.toFixed()}`:""} L${o.toFixed()}`}}class Wl extends bi{constructor(n){super({isClosed:!1,isFilled:!1,...n});E(this,"points");E(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:n}=this;for(let r=0,o=n.length-1;r<o;r++){const s=n[r],i=n[r+1];this._segments.push(new es({start:s,end:i}))}this.isClosed&&this._segments.push(new es({start:n[n.length-1],end:n[0]}))}return this._segments}getLength(){return this.segments.reduce((n,r)=>n+r.length,0)}getVertices(){return this.points}nearestPoint(n){const{segments:r}=this;let o=this.points[0],s=1/0,i,a;for(let l=0;l<r.length;l++)i=r[l].nearestPoint(n),a=x.Dist2(i,n),a<s&&(o=i,s=a);if(!o)throw Error("nearest point not found");return o}hitTestLineSegment(n,r,o=0){const{segments:s}=this;for(let i=0,a=s.length;i<a;i++)if(s[i].hitTestLineSegment(n,r,o))return!0;return!1}getSvgPathData(){const{vertices:n}=this;return n.length<2?"":n.reduce((r,o,s)=>s===0?`M ${o.x} ${o.y}`:`${r} L ${o.x} ${o.y}`,"")}}class St extends Wl{constructor(e){super({...e}),this.isClosed=!0}}class fs extends St{constructor(n){const{x:r=0,y:o=0,width:s,height:i}=n;super({...n,points:[new x(r,o),new x(r+s,o),new x(r+s,o+i),new x(r,o+i)]});E(this,"x");E(this,"y");E(this,"w");E(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new Z(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:n,y:r,w:o,h:s}=this;return`M${n},${r} h${o} v${s} h-${o}z`}}class Zr{constructor(e){this.editor=e}canSnap(e){return!0}canScroll(e){return!1}canBind(e){return!0}canEdit(e){return!1}canResize(e){return!0}canEditInReadOnly(e){return!1}canCrop(e){return!1}canBeLaidOut(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}canReceiveNewChildrenOfType(e,n){return!1}canDropShapes(e,n){return!1}expandSelectionOutlinePx(e){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(e){return{}}getHandleSnapGeometry(e){return{}}getText(e){}}E(Zr,"props"),E(Zr,"migrations"),E(Zr,"type");function Wr(t,e,n={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed",forceSolid:c=!1}=n;let u=0,h=0,p=1,f=0,g=0;if(c)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(l){case"dashed":{p=1,u=Math.min(e*a,t/4);break}case"dotted":{p=100,u=e/p;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(t+=u/2,g+=u/2):s==="skip"&&(t-=u,g-=u),i==="outset"?t+=u/2:i==="skip"&&(t-=u)),h=Math.floor(t/u/(2*p)),h-=h%o,h<3&&l==="dashed"?t/e<4?(u=t,h=1,f=0):(u=t*(1/3),f=t*(1/3)):(u=t/h/(2*p),r?(g=u/2,f=(t-h*u)/h):f=(t-h*u)/Math.max(1,h-1)),{strokeDasharray:[u,f].join(" "),strokeDashoffset:g.toString()}}function eI({bounds:t,className:e}){const n=F(),r=U("zoom level",()=>n.getZoomLevel(),[n]);return d.jsx("g",{className:e,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:t.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=Wr(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return d.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class Jh extends Zr{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const n=this.editor.getSortedChildIdsForParent(e.id);return n.length===0?new fs({width:1,height:1,isFilled:!1}):new eo({children:n.map(r=>{const o=this.editor.getShape(r),s=this.editor.getShapeGeometry(r),i=this.editor.getShapeLocalTransform(o).applyToPoints(s.vertices);return s.isClosed?new St({points:i,isFilled:!0}):new Wl({points:i})})})}component(e){const n=this.editor.getErasingShapeIds().includes(e.id),{hintingShapeIds:r}=this.editor.getCurrentPageState(),o=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(!n&&(s||o))return null;const i=this.editor.getShapeGeometry(e).bounds;return d.jsx(li,{id:e.id,children:d.jsx(eI,{className:"tl-group",bounds:i})})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx(eI,{className:"",bounds:n})}onChildrenChange(e){const n=this.editor.getSortedChildIdsForParent(e.id);if(n.length===0){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([e.id]);return}else if(n.length===1){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(n,e.parentId),this.editor.deleteShapes([e.id]);return}}}E(Jh,"type","group"),E(Jh,"props",uA),E(Jh,"migrations",dA);const mj=[Jh],cZ=new Set(mj.map(t=>t.type));function yj(t){const e=[...mj],n=new Set;for(const r of t){if(cZ.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(n.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);e.push(r),n.add(r.type)}return e}function Sj(t,e){const n=new Map;return async function(o){const s=n.get(o);if(s)return s;const i=(async()=>{try{const a=await Jr(o,e);return Re(a.ok),await t(a)}catch(a){return console.error(a),null}})();return n.set(o,i),i}}const Mg=Sj(async t=>await rs.blobToDataUrl(await t.blob())),uZ=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,dZ=/@font-face\s*{([^}]+)}/gi,vj=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,hZ=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function pZ(t){return Array.from(t.matchAll(uZ),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function xj(t,e){return Array.from(t.matchAll(dZ),n=>{const r=n[1],o=Array.from(r.matchAll(vj),i=>{var l;const a=i[1]||i[2]||i[3];return{original:a,resolved:((l=fe(a,e))==null?void 0:l.href)??null}}),s=new Set(Array.from(r.matchAll(hZ),i=>(i[1]||i[2]||i[3]).toLowerCase()));return{fontFace:r,urls:o,fontFamilies:s}})}function fZ(t){const e=/\s*(?:([^'"][^;\n\s,]+)|"([^"]+)"|'([^']+)')\s*/gi,n=/\s*,\s*/gi,r=new Set;for(;;){const o=e.exec(t);if(!o)break;const s=o[1]||o[2]||o[3];if(r.add(s.toLowerCase()),n.lastIndex=e.lastIndex,!n.exec(t))break;e.lastIndex=n.lastIndex}return r}function wj(t){return!(t.startsWith("-")||t.startsWith("animation")||t.startsWith("transition")||t==="cursor"||t==="pointer-events"||t==="user-select"||t==="touch-action")}function gZ(t,e){return{imports:pZ(t),fontFaces:xj(t,e)}}function mZ(t){return Array.from(t.matchAll(vj),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}const yZ=new Set(["border-collapse","border-spacing","caption-side","color","cursor","direction","empty-cells","font-family","font-size","font-style","font-variant","font-weight","font-size-adjust","font-stretch","font","letter-spacing","line-height","list-style-image","list-style-position","list-style-type","list-style","orphans","quotes","tab-size","text-align","text-align-last","text-decoration-color","text-indent","text-justify","text-shadow","text-transform","visibility","white-space","widows","word-break","word-spacing","word-wrap"]);function bj(t){return yZ.has(t)}var SZ=Object.create,Pj=Object.defineProperty,vZ=Object.getOwnPropertyDescriptor,xZ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Cj=t=>{throw TypeError(t)},_j=(t,e,n)=>e in t?Pj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,wZ=t=>[,,,SZ(null)],Ij=["class","method","getter","setter","accessor","field","value","get","set"],Ej=t=>t!==void 0&&typeof t!="function"?Cj("Function expected"):t,bZ=(t,e,n,r,o)=>({kind:Ij[t],name:e,metadata:r,addInitializer:s=>n._?Cj("Already initialized"):o.push(Ej(s||null))}),PZ=(t,e)=>_j(e,xZ("metadata"),t[3]),CZ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},_Z=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=Ij[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,vZ(o,n)),S=r.length-1;S>=0;S--)l=bZ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,Ej(i)&&(v[g]=i);return v&&Pj(o,n,v),o},ah=(t,e,n)=>_j(t,typeof e!="symbol"?e+"":e,n),kj,Ag;kj=[ar];class i1{constructor(){CZ(Ag,5,this),ah(this,"fontFacesPromise",null),ah(this,"foundFontNames",new Set),ah(this,"fontFacesToEmbed",new Set),ah(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){Re(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=IZ()}onFontFamilyValue(e){Re(this.fontFacesPromise,"FontEmbedder not started");const n=fZ(e);for(const r of n){if(this.foundFontNames.has(r))return;this.foundFontNames.add(r),this.pendingPromises.push(this.fontFacesPromise.then(o=>{const s=o.filter(i=>i.fontFamilies.has(r));for(const i of s)if(!this.fontFacesToEmbed.has(i)){this.fontFacesToEmbed.add(i);for(const a of i.urls)!a.resolved||a.embedded||(a.embedded=Mg(a.resolved))}}))}}async createCss(){await Promise.all(this.pendingPromises);let e="";for(const n of this.fontFacesToEmbed){let r=`@font-face {${n.fontFace}}`;for(const o of n.urls){if(!o.embedded)continue;const s=await o.embedded;s&&(r=r.replace(o.original,s))}e+=r}return e}}Ag=wZ();_Z(Ag,1,"onFontFamilyValue",kj,i1);PZ(Ag,i1);async function IZ(){const t=[];for(const e of document.styleSheets){let n;try{n=e.cssRules}catch{}if(n)for(const r of e.cssRules)r instanceof CSSFontFaceRule?t.push(xj(r.cssText,e.href??document.baseURI)):r instanceof CSSImportRule&&t.push(fx(r.href));else e.href&&t.push(fx(e.href))}return ye(await Promise.all(t)).flat()}const fx=Sj(async t=>{const e=gZ(await t.text(),t.url),n=await Promise.all(e.imports.map(({url:r})=>fx(new URL(r,t.url).href)));return[...e.fontFaces,...ye(n).flat()]});function Tj(t){if(t.shadowRoot)return t.shadowRoot.childNodes;if(MZ(t)){const e=t.assignedNodes();if(e!=null&&e.length)return e}return t.childNodes}function*gx(t){for(const e of Tj(t))EZ(e)&&(yield e)}function jg(t){var e;return((e=t.ownerDocument)==null?void 0:e.defaultView)??globalThis}function EZ(t){return t instanceof jg(t).Element}function kZ(t){return t instanceof jg(t).ShadowRoot}function TZ(t){return"getRootNode"in t&&kZ(t.getRootNode())}function MZ(t){return TZ(t)&&t instanceof jg(t).HTMLSlotElement}function AZ(t){return t.style}function a1(t,e){return jg(t).getComputedStyle(t,e)}const Gi={};class jZ{constructor(e){E(this,"styles",new Map);E(this,"fonts",new i1);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const n=Array.from(gx(e));for(;n.length;){const r=n.pop();n.push(...gx(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:n=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const o=n?LZ(e.tagName.toLowerCase()):Gi,s=r?((a=this.styles.get(e.parentElement))==null?void 0:a.self)??Gi:Gi,i={self:OZ(e,{defaultStyles:o,parentStyles:s}),before:tI(e,"::before"),after:tI(e,"::after")};this.styles.set(e,i)}fetchResources(){const e=[];for(const n of this.styles.values())for(const r of ct(n))if(r)for(const[o,s]of Object.entries(r)){if(!s)continue;o==="font-family"&&this.fonts.onFontFamilyValue(s);const i=mZ(s);i.length!==0&&e.push(...i.map(async({url:a,original:l})=>{const c=await Mg(a)??"data:";r[o]=s.replace(l,`url("${c}")`)}))}return Promise.all(e)}unwrapCustomElements(){const e=new Set,n=(r,o)=>{if(e.has(r))return;e.add(r);const s=r.shadowRoot;if(s){const i=document.createElement("div");this.styles.set(i,this.styles.get(r)),i.setAttribute("data-tl-custom-element",r.tagName),(o??r.parentElement).appendChild(i);for(const a of s.childNodes)a instanceof Element?n(a,i):i.appendChild(a.cloneNode(!0));r.remove()}else if(o){if(r.tagName.toLowerCase()==="style")return;const i=r.cloneNode(!1);this.styles.set(i,this.styles.get(r)),o.appendChild(i);for(const a of Tj(r))a instanceof Element?n(a,i):i.appendChild(a.cloneNode(!0))}};for(const r of this.styles.keys())n(r,null)}embedStyles(){let e="";for(const[n,r]of this.styles){if(r.after||r.before){const s=`pseudo-${Ke()}`;n.classList.add(s),r.before&&(e+=`.${s}::before {${nI(r.before)}}
99
- `),r.after&&(e+=`.${s}::after {${nI(r.after)}}
100
- `)}const o=AZ(n);for(const[s,i]of Object.entries(r.self))i&&o.setProperty(s,i);o.fontKerning==="auto"&&(o.fontKerning="normal")}return e}async getFontFaceCss(){return await this.fonts.createCss()}dispose(){RZ()}}function OZ(t,{defaultStyles:e,parentStyles:n}){return t.computedStyleMap?Mj(t.computedStyleMap(),{defaultStyles:e,parentStyles:n}):l1(a1(t),{defaultStyles:e,parentStyles:n})}function tI(t,e){const n=a1(t,e),r=n.getPropertyValue("content");if(!(r===""||r==="none"))return l1(n,{defaultStyles:Gi,parentStyles:Gi})}function Mj(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t.keys()){if(!wj(o))continue;const s=t.get(o).toString();e[o]!==s&&(n[o]===s&&bj(o)||(r[o]=s))}return r}function l1(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t){if(!wj(o))continue;const s=t.getPropertyValue(o);e[o]!==s&&(n[o]===s&&bj(o)||(r[o]=s))}return r}function nI(t){let e="";for(const[n,r]of Object.entries(t))e+=`${n}: ${r};`;return e}let pl;const rI={};function DZ(){if(!pl){const t=document.createElement("iframe");t.style.display="none",document.body.appendChild(t);const e=nr(t.contentDocument,"frame must have a document"),n=document.createElementNS("http://www.w3.org/2000/svg","svg"),r=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");n.appendChild(r),e.body.appendChild(n),pl={iframe:t,foreignObject:r,document:e}}return pl}function RZ(){pl&&(document.body.removeChild(pl.iframe),pl=void 0)}const oI={defaultStyles:Gi,parentStyles:Gi};function LZ(t){let e=rI[t];if(!e){const{foreignObject:n,document:r}=DZ(),o=r.createElement(t);n.appendChild(o),e=o.computedStyleMap?Mj(o.computedStyleMap(),oI):l1(a1(o),oI),n.removeChild(o),rI[t]=e}return e}function $Z(t,e){Array.from(t.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function sI(t,e){return t.replaceWith(e),e}async function nu(t,e){const n=document.createElement("img");e&&$Z(e,n),n.setAttribute("src",t??"data:"),n.setAttribute("decoding","sync"),n.setAttribute("loading","eager");try{await n.decode()}catch{}return n}async function FZ(t){try{const e=t.toDataURL();return await nu(e,t)}catch{return await nu(null,t)}}async function NZ(t){try{const e=await sr.getVideoFrameAsDataUrl(t);return nu(e,t)}catch(e){console.error("Could not get video frame",e)}if(t.poster){const e=await Mg(t.poster);return nu(e,t)}return nu(null,t)}async function Aj(t){if(t instanceof HTMLCanvasElement)return sI(t,await FZ(t));if(t instanceof HTMLVideoElement)return sI(t,await NZ(t));if(t instanceof HTMLImageElement){const e=t.currentSrc||t.src,n=await Mg(e);t.setAttribute("src",n??"data:"),t.setAttribute("decoding","sync"),t.setAttribute("loading","eager");try{await t.decode()}catch{}return t}else t instanceof HTMLInputElement?t.setAttribute("value",t.value):t instanceof HTMLTextAreaElement&&(t.textContent=t.value);await Promise.all(Array.from(gx(t),e=>Aj(e)))}function Og(t){const e=w.useRef();return w.useLayoutEffect(()=>{e.current=t}),w.useDebugValue(t),w.useCallback((...n)=>{const r=e.current;return Re(r,"fn does not exist"),r(...n)},[])}const c1=w.createContext(null);function zZ({context:t,editor:e,children:n}){return d.jsx(_g.Provider,{value:e,children:d.jsx(c1.Provider,{value:t,children:n})})}function ad(){return w.useContext(c1)}function BZ(){const t=w.useContext(c1),[e]=w.useState(aw);return w.useEffect(()=>(t==null||t.waitUntil(e),()=>{e.resolve()}),[e,t]),Og(()=>{e.resolve()})}var UZ=Object.create,jj=Object.defineProperty,HZ=Object.getOwnPropertyDescriptor,KZ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Oj=t=>{throw TypeError(t)},Dj=(t,e,n)=>e in t?jj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,WZ=t=>[,,,UZ(null)],Rj=["class","method","getter","setter","accessor","field","value","get","set"],Lj=t=>t!==void 0&&typeof t!="function"?Oj("Function expected"):t,GZ=(t,e,n,r,o)=>({kind:Rj[t],name:e,metadata:r,addInitializer:s=>n._?Oj("Already initialized"):o.push(Lj(s||null))}),VZ=(t,e)=>Dj(e,KZ("metadata"),t[3]),YZ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},XZ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=Rj[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,HZ(o,n)),S=r.length-1;S>=0;S--)l=GZ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,Lj(i)&&(v[g]=i);return v&&jj(o,n,v),o},iI=(t,e,n)=>Dj(t,typeof e!="symbol"?e+"":e,n),$j,Dg;$j=[ar];class u1{constructor(e){this.maxDelayTimeMs=e,YZ(Dg,5,this),iI(this,"isResolved",!1),iI(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(n=>console.error("Error whilst waiting for export:",n)))}async resolvePromises(){let e=null;for(;this.promisesToWaitFor.length!==e;)e=this.promisesToWaitFor.length,await Promise.allSettled(this.promisesToWaitFor),await Rv(0)}async resolve(){const e=Rv(this.maxDelayTimeMs).then(()=>"timeout"),n=this.resolvePromises().then(()=>"resolved");await Promise.race([e,n])==="timeout"&&console.warn("[tldraw] Export delay timed out after ${this.maxDelayTimeMs}ms"),this.isResolved=!0}}Dg=WZ();XZ(Dg,1,"waitUntil",$j,u1);VZ(Dg,u1);function qZ(t,e,n={}){var S,y;if(!window.document)throw Error("No document");const{scale:r=1,background:o=!1,padding:s=t.options.defaultSvgPadding,preserveAspectRatio:i}=n,a=n.darkMode??t.user.getIsDarkMode(),l=t.getShapeAndDescendantIds(e),c=t.getUnorderedRenderingShapes(!1).filter(({id:b})=>l.has(b));let u=null;if(n.bounds)u=n.bounds;else for(const{id:b}of c){const P=t.getShapeMaskedPageBounds(b);P&&(u?u.union(P):u=P.clone())}if(!u)return;const h=e.length===1&&t.isShapeOfType(t.getShape(e[0]),"frame")?e[0]:null;h||u.expandBy(s);const p=u.width*r,f=u.height*r;try{(y=(S=document.body).focus)==null||y.call(S)}catch{}const g=new u1(t.options.maxExportDelayMs),m=aw();return g.waitUntil(m),{jsx:d.jsx(ZZ,{editor:t,preserveAspectRatio:i,scale:r,bbox:u,background:o,singleFrameShapeId:h,isDarkMode:a,renderingShapes:c,onMount:m.resolve,waitUntil:g.waitUntil}),width:p,height:f,exportDelay:g}}function ZZ({editor:t,preserveAspectRatio:e,scale:n,bbox:r,background:o,singleFrameShapeId:s,isDarkMode:i,renderingShapes:a,onMount:l,waitUntil:c}){const u=ws({isDarkMode:i}),[h,p]=w.useState({}),f=Og(y=>{qr(h,y.key)||c((async()=>{const b=await y.getElement();b&&ps.flushSync(()=>p(P=>({...P,[y.key]:b})))})())}),g=w.useMemo(()=>({isDarkMode:i,waitUntil:c,addExportDef:f}),[i,c,f]),[m,v]=w.useState(null),S=w.useRef(!1);return w.useLayoutEffect(()=>{if(S.current)throw new Error("SvgExport should only render once - do not use with react strict mode");S.current=!0,(async()=>{const y={},b=a.map(async({id:C,opacity:I,index:T,backgroundIndex:_})=>{var j,O;if(C===s)return[];const k=t.getShape(C);if(t.isShapeOfType(k,"group"))return[];const M=[],R=t.getShapeUtil(k);if(R.toSvg||R.toBackgroundSvg){const[D,B]=await Promise.all([(j=R.toSvg)==null?void 0:j.call(R,k,g),(O=R.toBackgroundSvg)==null?void 0:O.call(R,k,g)]),z=t.getShapePageTransform(k);let K=z.toCssString();"scale"in k.props&&k.props.scale!==1&&(K=`${K} scale(${k.props.scale}, ${k.props.scale})`);const N=t.getShapeMask(k.id),H=N?q.From(q.Inverse(z)).applyToPoints(N):null,Y=`mask_${k.id.replace(":","_")}`;H&&(y[Y]=d.jsx("clipPath",{id:Y,children:d.jsx("path",{d:`M${H.map(({x:ee,y:ce})=>`${ee},${ce}`).join("L")}Z`})})),D&&M.push({zIndex:T,element:d.jsx("g",{transform:K,opacity:I,clipPath:N?`url(#${Y})`:void 0,children:D},`fg_${k.id}`)}),B&&M.push({zIndex:_,element:d.jsx("g",{transform:K,opacity:I,clipPath:N?`url(#${Y})`:void 0,children:B},`bg_${k.id}`)})}else M.push({zIndex:T,element:d.jsx(aI,{shape:k,util:R,component:WA,className:"tl-shape",bbox:r,opacity:I},`fg_${k.id}`)}),R.backgroundComponent&&M.push({zIndex:_,element:d.jsx(aI,{shape:k,util:R,component:GA,className:"tl-shape tl-shape-background",bbox:r,opacity:I},`bg_${k.id}`)});return M}),P=(await Promise.all(b)).flat();ps.flushSync(()=>{v(P.sort((C,I)=>C.zIndex-I.zIndex).map(({element:C})=>C)),p(C=>({...C,...y}))})})()},[r,t,g,a,s]),w.useEffect(()=>{m!==null&&l()},[l,m]),d.jsx(zZ,{editor:t,context:g,children:d.jsxs("svg",{preserveAspectRatio:e,direction:"ltr",width:r.width*n,height:r.height*n,viewBox:`${r.minX} ${r.minY} ${r.width} ${r.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:o?s?u.solid:u.background:"transparent"},"data-color-mode":i?"dark":"light",className:`tl-container tl-theme__force-sRGB ${i?"tl-theme__dark":"tl-theme__light"}`,children:[d.jsx("defs",{children:Object.entries(h).map(([y,b])=>d.jsx(w.Fragment,{children:b},y))}),m]})})}function aI({shape:t,util:e,className:n,component:r,bbox:o,opacity:s}){const i=F(),a=q.Translate(-o.minX,-o.minY).multiply(i.getShapePageTransform(t.id)),l=i.getShapeGeometry(t.id).bounds,c=Math.max(l.width,1),u=Math.max(l.height,1);return d.jsx(Xw,{fallback:()=>null,children:d.jsx("foreignObject",{x:o.minX,y:o.minY,width:o.w,height:o.h,className:"tl-shape-foreign-object",children:d.jsx("div",{className:n,"data-shape-type":t.type,style:{clipPath:i.getShapeClipPath(t.id),transform:a.toCssString(),width:c,height:u,opacity:s},children:d.jsx(r,{shape:t,util:e})})})})}async function QZ(t,e,n={}){const r=qZ(t,e,n);if(!r)return;const o=t.getContainer(),s=document.createElement("div");s.className="tldraw-svg-export",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}),o.appendChild(s);const i=eT(s);try{ps.flushSync(()=>{i.render(r.jsx)}),await r.exportDelay.resolve();const a=s.firstElementChild;return Re(a instanceof SVGSVGElement,"Expected an SVG element"),await JZ(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{i.unmount(),o.removeChild(s)},0)}}async function JZ(t){const e=[...t.querySelectorAll("foreignObject.tl-shape-foreign-object > *")];if(!e.length)return;const n=new jZ(t);try{n.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(s=>Aj(s)));for(const s of e)n.readRootElementStyles(s);await n.fetchResources();const r=await n.getFontFaceCss();n.unwrapCustomElements();const o=n.embedStyles();if(r||o){const s=document.createElementNS("http://www.w3.org/2000/svg","style");s.textContent=`${r}
101
- ${o}`,t.prepend(s)}}finally{n.dispose()}}const eQ={maxShapesPerPage:4e3,maxFilesAtOnce:100,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,defaultSvgPadding:32,cameraSlideFriction:.09,maxPointsPerDrawShape:500,gridSteps:[{min:-1,mid:.15,step:64},{min:.05,mid:.375,step:16},{min:.15,mid:1,step:4},{min:.7,mid:2.5,step:1}],collaboratorInactiveTimeoutMs:6e4,collaboratorIdleTimeoutMs:3e3,collaboratorCheckIntervalMs:1200,cameraMovingTimeoutMs:64,hitTestMargin:8,edgeScrollDelay:200,edgeScrollEaseDuration:200,edgeScrollSpeed:25,edgeScrollDistance:8,coarsePointerWidth:12,coarseHandleRadius:20,handleRadius:12,longPressDurationMs:500,textShadowLod:.35,adjacentShapeMargin:10,flattenImageBoundsExpand:64,flattenImageBoundsPadding:16,laserDelayMs:1200,maxExportDelayMs:5e3,temporaryAssetPreviewLifetimeMs:18e4};function lI(t,e){if(!e)return!1;switch(t.type){case"mixed":return e.type==="mixed";case"shared":return e.type==="shared"&&t.value===e.value;default:throw Tt(t)}}class tQ{constructor(e){E(this,"map");this.map=new Map(e)}get(e){return this.map.get(e)}getAsKnownValue(e){const n=this.get(e);if(n&&n.type!=="mixed")return n.value}get size(){return this.map.size}equals(e){if(this.size!==e.size)return!1;const n=new Set;for(const[r,o]of this){if(!lI(o,e.get(r)))return!1;n.add(r)}for(const[r,o]of e)if(!n.has(r)&&!lI(o,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 mx extends tQ{set(e,n){this.map.set(e,n)}applyValue(e,n){const r=this.get(e);if(!r){this.set(e,{type:"shared",value:n});return}switch(r.type){case"mixed":return;case"shared":r.value!==n&&this.set(e,{type:"mixed"});return;default:Tt(r,"type")}}}function nQ(t,e,n){return Jr(t).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:n})})}const rQ="https://cdn.tldraw.com";function Gs(){return`${rQ}/${_A}`}function oQ(t){switch(t.type){case"shapes":return`s${t.shapeIds.map(n=>Fy(n.slice(6))).join(".")}`;case"page":return"p"+Fy(gr.parseId(t.pageId));case"viewport":{const{bounds:e,pageId:n}=t;let r=`v${Math.round(e.x)}.${Math.round(e.y)}.${Math.round(e.w)}.${Math.round(e.h)}`;return n&&(r+="."+Fy(gr.parseId(n))),r}default:Tt(t)}}function sQ(t){switch(t[0]){case"s":return{type:"shapes",shapeIds:t.slice(1).split(".").filter(Boolean).map(r=>Ne(decodeURIComponent(r)))};case"p":return{type:"page",pageId:gr.createId(decodeURIComponent(t.slice(1)))};case"v":{const[n,r,o,s,i]=t.slice(1).split(".");return{type:"viewport",bounds:new Z(Number(n),Number(r),Number(o),Number(s)),pageId:i?gr.createId(decodeURIComponent(i)):void 0}}default:throw Error("Invalid deep link string")}}function Fy(t){return encodeURIComponent(t).replace(/\./g,"%2E")}function iQ(t,e){var o;let n=t;const r=new Set(e);for(;r.has(n);)n=(o=/^.*(\d+)$/.exec(n))!=null&&o[1]?n.replace(/(\d+)(?=\D?)$/,s=>(+s+1).toString()):`${n} 1`;return n}function lh(t,e,n){if(n.length===0)return[];const r=new Map;for(const s of ye(n.map(i=>t.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:ye(t.getSortedChildIdsForParent(i).map(a=>t.getShape(a))),moving:new Set}),r.get(i).moving.add(s)}const o=[];switch(e){case"toBack":{r.forEach(({moving:s,children:i})=>aQ(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>lQ(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>cQ(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>uQ(s,i,o));break}}return o}function aQ(t,e,n){const r=e.length;if(t.size===r)return;let o,s;for(let i=0;i<r;i++){const a=e[i];if(t.has(a))o=a.index,t.delete(a);else{s=a.index;break}}if(t.size!==0){const i=_l(o,s,t.size);n.push(...Array.from(t.values()).sort(ln).map((a,l)=>({...a,index:i[l]})))}}function lQ(t,e,n){const r=e.length;if(t.size===r)return;let o,s;for(let i=r-1;i>-1;i--){const a=e[i];if(t.has(a))s=a.index,t.delete(a);else{o=a.index;break}}if(t.size!==0){const i=_l(o,s,t.size);n.push(...Array.from(t.values()).sort(ln).map((a,l)=>({...a,index:i[l]})))}}function cQ(t,e,n){var s;const r=e.length;if(t.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=t.has(e[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:l}=o;_l(e[i].index,(s=e[i+1])==null?void 0:s.index,i-l).forEach((c,u)=>n.push({...e[l+u],index:c})),o={name:"skipping"};break}}}}function uQ(t,e,n){var s;const r=e.length;if(t.size===r)return;let o={name:"skipping"};for(let i=r-1;i>-1;i--){const a=t.has(e[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;_l((s=e[i-1])==null?void 0:s.index,e[i].index,o.selectIndex-i).forEach((l,c)=>{n.push({...e[i+c+1],index:l})}),o={name:"skipping"};break}}}}function Fj({editor:t,ids:e}){const n=ye(e.map(i=>t.getShape(i))),r=t.getShapesSharedRotation(e),o=t.getShapesRotatedPageBounds(e);if(!o)return null;const s=o.center.clone().rotWith(o.point,r);return{pageCenter:s,initialCursorAngle:s.angle(t.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:n.map(i=>({shape:i,initialPagePoint:t.getShapePageTransform(i.id).point()}))}}function ep({delta:t,editor:e,snapshot:n,stage:r,centerOverride:o}){const{pageCenter:s,shapeSnapshots:i}=n;e.updateShapes(i.map(({shape:l,initialPagePoint:c})=>{const u=Rn(l.parentId)?e.getShapePageTransform(l.parentId):q.Identity(),h=x.RotWith(c,o??s,t),p=q.applyToPoint(q.Inverse(u),h),f=ni(l.rotation+t);return{id:l.id,type:l.type,x:p.x,y:p.y,rotation:f}}));const a=[];i.forEach(({shape:l})=>{var p,f,g;const c=e.getShape(l.id);if(!c)return;const u=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const m=(p=u.onRotateStart)==null?void 0:p.call(u,l);m&&a.push(m)}const h=(f=u.onRotate)==null?void 0:f.call(u,l,c);if(h&&a.push(h),r==="end"||r==="one-off"){const m=(g=u.onRotateEnd)==null?void 0:g.call(u,l,c);m&&a.push(m)}}),a.length>0&&e.updateShapes(a)}const dQ=t=>{const{store:e}=t,n=e.query.filterHistory("binding"),r=e.query.records("binding");function o(){const s=r.get(),i=new Map;for(const a of s){const{fromId:l,toId:c}=a,u=i.get(l);u?u.push(a):i.set(l,[a]);const h=i.get(c);h?h.push(a):i.set(c,[a])}return i}return G("arrowBindingsIndex",(s,i)=>{if(Ki(s))return o();const a=s,l=n.getDiffSince(i);if(l===lr)return o();let c;function u(f){c??(c=new Map(a));const g=c.get(f.fromId),m=g==null?void 0:g.filter(y=>y.id!==f.id);m!=null&&m.length?c.set(f.fromId,m):c.delete(f.fromId);const v=c.get(f.toId),S=v==null?void 0:v.filter(y=>y.id!==f.id);S!=null&&S.length?c.set(f.toId,S):c.delete(f.toId)}function h(f){c??(c=new Map(a));let g=c.get(f);return g?g===a.get(f)&&(g=g.slice(0),c.set(f,g)):(g=[],c.set(f,g)),g}function p(f){h(f.fromId).push(f),h(f.toId).push(f)}for(const f of l){for(const g of ct(f.added))p(g);for(const[g,m]of ct(f.updated))u(g),p(m);for(const g of ct(f.removed))u(g)}return c??a})};function hQ(t,e,n){const r=t.getShapeMaskedPageBounds(e);return r===void 0?!0:!n.includes(r)}const pQ=t=>{function e(n){const r=n.getCurrentPageShapeIds(),o=n.getViewportPageBounds(),s=new Set;return r.forEach(i=>{hQ(n,i,o)&&s.add(i)}),s}return G("getCulledShapes",n=>{if(Ki(n))return e(t);const r=e(t);if(n.size!==r.size)return r;for(const o of n)if(!r.has(o))return r;return n})},fQ=t=>{const e=t.query.ids("shape"),n=t.query.filterHistory("shape");function r(){const o={},s=e.get(),i=Array(s.size);return s.forEach(a=>i.push(t.get(a))),i.sort(ln),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return G("parentsToChildrenWithIndexes",(o,s)=>{if(Ki(o))return r();const i=n.getDiffSince(s);if(i===lr)return r();if(i.length===0)return o;let a=null;const l=h=>{a||(a={...o}),a[h]?a[h]===o[h]&&(a[h]=[...a[h]]):a[h]=[]},c=new Set;let u;for(let h=0,p=i.length;h<p;h++){u=i[h];for(const f of Object.values(u.added))Qa(f)&&(l(f.parentId),a[f.parentId].push(f.id),c.add(a[f.parentId]));for(const[f,g]of Object.values(u.updated))if(Qa(g)&&Qa(f)){if(f.parentId!==g.parentId)l(f.parentId),l(g.parentId),a[f.parentId].splice(a[f.parentId].indexOf(g.id),1),a[g.parentId].push(g.id),c.add(a[g.parentId]);else if(f.index!==g.index){l(g.parentId);const m=a[g.parentId].indexOf(g.id);a[g.parentId][m]=g.id,c.add(a[g.parentId])}}for(const f of Object.values(u.removed))Qa(f)&&(l(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const h of c){const p=ye(h.map(f=>t.get(f)));p.sort(ln),h.splice(0,h.length,...p.map(f=>f.id))}return a??o})},Ny=(t,e,n)=>{for(;!jn(n.parentId);){const r=t.get(n.parentId);if(!r)return!1;n=r}return n.parentId===e},gQ=(t,e)=>{const n=t.query.ids("shape");let r=null;function o(){const s=e();return r=s,new Set([...n.get()].filter(i=>Ny(t,s,t.get(i))))}return G("_shapeIdsInCurrentPage",(s,i)=>{if(Ki(s))return o();const a=e();if(a!==r)return o();const l=t.history.getDiffSince(i);if(l===lr)return o();const c=new Xh(s);for(const h of l){for(const p of Object.values(h.added))Qa(p)&&Ny(t,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))Qa(f)&&(Ny(t,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(h.removed))Rn(p)&&c.remove(p)}const u=c.get();return u?Lc(u.value,u.diff):s})};var mQ=Object.create,Nj=Object.defineProperty,yQ=Object.getOwnPropertyDescriptor,SQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),zj=t=>{throw TypeError(t)},Bj=(t,e,n)=>e in t?Nj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,vQ=t=>[,,,mQ(null)],Uj=["class","method","getter","setter","accessor","field","value","get","set"],Hj=t=>t!==void 0&&typeof t!="function"?zj("Function expected"):t,xQ=(t,e,n,r,o)=>({kind:Uj[t],name:e,metadata:r,addInitializer:s=>n._?zj("Already initialized"):o.push(Hj(s||null))}),wQ=(t,e)=>Bj(e,SQ("metadata"),t[3]),bQ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},Kj=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=Uj[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,yQ(o,n)),S=r.length-1;S>=0;S--)l=xQ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,Hj(i)&&(v[g]=i);return v&&Nj(o,n,v),o},Ea=(t,e,n)=>Bj(t,typeof e!="symbol"?e+"":e,n),Wj,Gj,ld;const PQ=40;Gj=[ar],Wj=[ar];class Rg{constructor(e){this.editor=e,bQ(ld,5,this),Ea(this,"_clickId",""),Ea(this,"_clickTimeout"),Ea(this,"_clickScreenPoint"),Ea(this,"_previousScreenPoint"),Ea(this,"_clickState","idle"),Ea(this,"lastPointerInfo",{})}_getClickTimeout(e,n=Ke()){this._clickId=n,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===e&&this._clickId===n){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},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=x.From(e.point),this._previousScreenPoint&&x.Dist2(this._previousScreenPoint,this._clickScreenPoint)>PQ**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=x.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&&x.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"}}ld=vQ();Kj(ld,1,"_getClickTimeout",Gj,Rg);Kj(ld,1,"cancelDoubleClickTimeout",Wj,Rg);wQ(ld,Rg);class CQ{constructor(e){E(this,"_isEdgeScrolling",!1);E(this,"_edgeScrollDuration",-1);this.editor=e}updateEdgeScrolling(e){const{editor:n}=this,r=this.getEdgeScroll();if(r.x===0&&r.y===0)this._isEdgeScrolling&&(this._isEdgeScrolling=!1,this._edgeScrollDuration=0);else if(this._isEdgeScrolling||(this._isEdgeScrolling=!0,this._edgeScrollDuration=0),this._edgeScrollDuration+=e,this._edgeScrollDuration>n.options.edgeScrollDelay){const o=n.options.edgeScrollEaseDuration>0?At.easeInCubic(Math.min(1,this._edgeScrollDuration/(n.options.edgeScrollDelay+n.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*o,y:r.y*o})}}getEdgeProximityFactors(e,n,r,o,s){const{editor:i}=this,a=i.options.edgeScrollDistance,l=r?i.options.coarsePointerWidth:0,c=e-l,u=e+l,h=o?0:a,p=s?n:n-a;return c<h?Math.min(1,(h-c)/a):u>p?-Math.min(1,(u-p)/a):0}getEdgeScroll(){const{editor:e}=this,{inputs:{currentScreenPoint:{x:n,y:r}}}=e,o=e.getViewportScreenBounds(),{isCoarsePointer:s,insets:[i,a,l,c]}=e.getInstanceState(),u=this.getEdgeProximityFactors(n,o.w,s,c,a),h=this.getEdgeProximityFactors(r,o.h,s,i,l);return{x:u,y:h}}moveCameraWhenCloseToEdge(e){const{editor:n}=this;if(!n.inputs.isDragging||n.inputs.isPanning||n.getCameraOptions().isLocked||e.x===0&&e.y===0)return;const r=n.getViewportScreenBounds(),o=r.w<1e3?.612:1,s=r.h<1e3?.612:1,i=n.getZoomLevel(),a=n.user.getEdgeScrollSpeed()*n.options.edgeScrollSpeed,l=a*e.x*o/i,c=a*e.y*s/i,{x:u,y:h,z:p}=n.getCamera();n.setCamera(new x(u+l,h+c,p))}}class _Q{constructor(e){E(this,"isSafari");E(this,"isIos");E(this,"isChromeForIos");E(this,"isFirefox");E(this,"isAndroid");this.editor=e,typeof window<"u"&&"navigator"in window?(this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),this.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),this.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),this.isFirefox=/firefox/i.test(navigator.userAgent),this.isAndroid=/android/i.test(navigator.userAgent)):(this.isSafari=!1,this.isIos=!1,this.isChromeForIos=!1,this.isFirefox=!1,this.isAndroid=!1)}}class IQ{constructor(e,n){E(this,"disposeSideEffectListener");this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(o,s)=>{o.isFocused!==s.isFocused&&this.updateContainerClass()});const r=e.getInstanceState().isFocused;n!==r&&e.updateInstanceState({isFocused:!!n}),this.updateContainerClass()}updateContainerClass(){const e=this.editor.getContainer();this.editor.getInstanceState().isFocused?e.classList.add("tl-container__focused"):e.classList.remove("tl-container__focused")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var e;(e=this.disposeSideEffectListener)==null||e.call(this)}}function wc(t){return kQ}class EQ{constructor(){E(this,"length",0);E(this,"head",null);E(this,"tail",this)}push(e){return new d1(e,this)}toArray(){return os}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const kQ=new EQ;class d1{constructor(e,n){E(this,"length");this.head=e,this.tail=n,this.length=n.length+1}push(e){return new d1(e,this)}toArray(){return Array.from(this)}[Symbol.iterator](){let e=this;return{next(){if(e.length){const n=e.head;return e=e.tail,{value:n,done:!1}}else return{value:void 0,done:!0}}}}}class TQ{constructor(e){E(this,"store");E(this,"dispose");E(this,"state","recording");E(this,"pendingDiff",new AQ);E(this,"stacks",Mt("HistoryManager.stacks",{undos:wc(),redos:wc()},{isEqual:(e,n)=>e.undos===n.undos&&e.redos===n.redos}));E(this,"annotateError");E(this,"_isInBatch",!1);this.store=e.store,this.annotateError=e.annotateError??_u,this.dispose=this.store.addHistoryInterceptor((n,r)=>{if(r==="user")switch(this.state){case"recording":this.pendingDiff.apply(n.changes),this.stacks.update(({undos:o})=>({undos:o,redos:wc()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(n.changes);break;case"paused":break;default:Tt(this.state)}})}flushPendingDiff(){if(this.pendingDiff.isEmpty())return;const e=this.pendingDiff.clear();this.stacks.update(({undos:n,redos:r})=>({undos:n.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}batch(e,n){const r=this.state;r!=="paused"&&(n!=null&&n.history)&&(this.state=MQ[n.history]);try{if(this._isInBatch)return _o(e),this;this._isInBatch=!0;try{_o(e)}catch(o){throw this.annotateError(o),o}finally{this._isInBatch=!1}return this}finally{this.state=r}}_undo({pushToRedoStack:e,toMark:n=void 0}){var o;const r=this.state;this.state="paused";try{let{undos:s,redos:i}=this.stacks.get();const a=this.pendingDiff.clear(),l=IM(a),c=tx(a);e&&!l&&(i=i.push({type:"diff",diff:a}));let u=!1;if(l)for(;((o=s.head)==null?void 0:o.type)==="stop";){const h=s.head;if(s=s.tail,e&&(i=i.push(h)),h.id===n){u=!0;break}}if(!u)e:for(;s.head;){const h=s.head;switch(s=s.tail,e&&(i=i.push(h)),h.type){case"diff":eu(c,[tx(h.diff)]);break;case"stop":if(!n)break e;if(h.id===n){u=!0;break e}break;default:Tt(h)}}if(!u&&n)return this;this.store.applyDiff(c,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:s,redos:i})}finally{this.state=r}return this}undo(){return this._undo({pushToRedoStack:!0}),this}redo(){var n;const e=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:r,redos:o}=this.stacks.get();if(o.length===0)return this;for(;((n=o.head)==null?void 0:n.type)==="stop";)r=r.push(o.head),o=o.tail;const s=lf();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")eu(s,[i.diff]);else break}this.store.applyDiff(s,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:o})}finally{this.state=e}return this}bail(){return this._undo({pushToRedoStack:!1}),this}bailToMark(e){return this._undo({pushToRedoStack:!1,toMark:e}),this}squashToMark(e){var s;let n=this.stacks.get().undos;const r=[];for(;n.head&&!(n.head.type==="stop"&&n.head.id===e);)n.head.type==="diff"&&r.push(n.head.diff),n=n.tail;if(!n.head||((s=n.head)==null?void 0:s.id)!==e)return console.error("Could not find mark to squash to: ",e),this;if(r.length===0)return this;const o=lf();return eu(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:n.push({type:"diff",diff:o}),redos:i})),this}_mark(e){_o(()=>{this.flushPendingDiff(),this.stacks.update(({undos:n,redos:r})=>({undos:n.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:wc(),redos:wc()}),this.pendingDiff.clear()}getMarkIdMatching(e){let n=this.stacks.get().undos;for(;n.head;){if(n.head.type==="stop"&&n.head.id.includes(e))return n.head.id;n=n.tail}return null}debug(){const{undos:e,redos:n}=this.stacks.get();return{undos:e.toArray(),redos:n.toArray(),pendingDiff:this.pendingDiff.debug(),state:this.state}}}const MQ={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class AQ{constructor(){E(this,"diff",lf());E(this,"isEmptyAtom",Mt("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=lf(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){eu(this.diff,[e]),this.isEmptyAtom.set(IM(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class jQ{constructor(e){E(this,"scribbleItems",new Map);E(this,"state","paused");this.editor=e}addScribble(e,n=Ke()){const r={id:n,scribble:{id:n,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(n,r),r}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}stop(e){const n=this.scribbleItems.get(e);if(!n)throw Error(`Scribble with id ${e} not found`);return n.delayRemaining=Math.min(n.delayRemaining,200),n.scribble.state="stopping",n}addPoint(e,n,r,o=.5){const s=this.scribbleItems.get(e);if(!s)throw Error(`Scribble with id ${e} not found`);const{prev:i}=s,a={x:n,y:r,z:o};return(!i||x.Dist(i,a)>=1)&&(s.next=a),s}tick(e){this.scribbleItems.size!==0&&this.editor.run(()=>{this.scribbleItems.forEach(n=>{if(n.scribble.state==="starting"){const{next:l,prev:c}=n;l&&l!==c&&(n.prev=l,n.scribble.points.push(l)),n.scribble.points.length>8&&(n.scribble.state="active");return}n.delayRemaining>0&&(n.delayRemaining=Math.max(0,n.delayRemaining-e)),n.timeoutMs+=e,n.timeoutMs>=16&&(n.timeoutMs=0);const{delayRemaining:r,timeoutMs:o,prev:s,next:i,scribble:a}=n;switch(a.state){case"active":{i&&i!==s?(n.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):o===0&&(a.points.length>1?a.points.shift():n.delayRemaining=a.delay);break}case"stopping":{if(n.delayRemaining===0&&o===0){if(a.points.length===1){this.scribbleItems.delete(n.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:n})=>({...n,points:[...n.points]})).slice(-5)})})}}var OQ=Object.create,Vj=Object.defineProperty,DQ=Object.getOwnPropertyDescriptor,RQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Yj=t=>{throw TypeError(t)},Xj=(t,e,n)=>e in t?Vj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,LQ=t=>[,,,OQ(null)],qj=["class","method","getter","setter","accessor","field","value","get","set"],Zj=t=>t!==void 0&&typeof t!="function"?Yj("Function expected"):t,$Q=(t,e,n,r,o)=>({kind:qj[t],name:e,metadata:r,addInitializer:s=>n._?Yj("Already initialized"):o.push(Zj(s||null))}),FQ=(t,e)=>Xj(e,RQ("metadata"),t[3]),NQ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},Lg=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=qj[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,DQ(o,n)),S=r.length-1;S>=0;S--)l=$Q(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,Zj(i)&&(v[g]=i);return v&&Vj(o,n,v),o},zQ=(t,e,n)=>Xj(t,e+"",n),Qj,Jj,eO,tO,ma;const de=t=>Math.round(t*10**8)/10**8;function Vo(t,e,n,r,o){const s=t.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&de(a.length)===de(n)&&Ur(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(s.length===0)return[];const i=new Set;return s.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(l)){i.add(l);const c=Vo(t,l,n,r,Ur(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function BQ(t){t.sort((e,n)=>n.gaps.length-e.gaps.length);for(let e=t.length-1;e>0;e--){const n=t[e];for(let r=e-1;r>=0;r--){const o=t[r];if(o.direction===n.direction&&n.gaps.every(s=>o.gaps.some(i=>de(s.startEdge[0].x)===de(i.startEdge[0].x)&&de(s.startEdge[0].y)===de(i.startEdge[0].y)&&de(s.startEdge[1].x)===de(i.startEdge[1].x)&&de(s.startEdge[1].y)===de(i.startEdge[1].y))&&o.gaps.some(i=>de(s.endEdge[0].x)===de(i.endEdge[0].x)&&de(s.endEdge[0].y)===de(i.endEdge[0].y)&&de(s.endEdge[1].x)===de(i.endEdge[1].x)&&de(s.endEdge[1].y)===de(i.endEdge[1].y)))){t.splice(e,1);break}}}}tO=[G],eO=[G],Jj=[G],Qj=[G];class Gl{constructor(e){this.manager=e,NQ(ma,5,this),zQ(this,"editor"),this.editor=e.editor}getSnapPointsCache(){const{editor:e}=this;return e.store.createComputedCache("snapPoints",n=>{const r=e.getShapePageTransform(n.id);if(!r)return;const s=e.getShapeUtil(n).getBoundsSnapGeometry(n).points??e.getShapeGeometry(n).bounds.cornersAndCenter;if(!(!r||!s))return s.map((i,a)=>{const{x:l,y:c}=q.applyToPoint(r,i);return{x:l,y:c,id:`${n.id}:${a}`}})})}getSnapPoints(e){return this.getSnapPointsCache().get(e)??[]}getSnappablePoints(){const e=this.getSnapPointsCache(),n=this.manager.getSnappableShapes(),r=[];for(const o of n){const s=e.get(o);s&&r.push(...s)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:nr(this.editor.getShapePageBounds(e))}))}getVisibleGaps(){const e=[],n=[];let r,o;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++)o=s[l],r.pageBounds.maxX<o.pageBounds.minX&&xc(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&e.push({startNode:r,endNode:o,startEdge:[new x(r.pageBounds.maxX,r.pageBounds.minY),new x(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new x(o.pageBounds.minX,o.pageBounds.minY),new x(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Ur(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const i=s.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let l=a+1;l<i.length;l++)o=i[l],r.pageBounds.maxY<o.pageBounds.minY&&xc(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&n.push({startNode:r,endNode:o,startEdge:[new x(r.pageBounds.minX,r.pageBounds.maxY),new x(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new x(o.pageBounds.minX,o.pageBounds.minY),new x(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Ur(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)})}return{horizontal:e,vertical:n}}snapTranslateShapes({lockedAxis:e,initialSelectionPageBounds:n,initialSelectionSnapPoints:r,dragDelta:o}){var v,S;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=n.clone().translate(o),l=r.map(({x:y,y:b},P)=>({id:"selection:"+P,x:y+o.x,y:b+o.y})),c=i,u=[],h=[],p=new x(s,s);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const f=new x(e==="x"?0:((v=u[0])==null?void 0:v.nudge)??0,e==="y"?0:((S=h[0])==null?void 0:S.nudge)??0);p.x=0,p.y=0,u.length=0,h.length=0,l.forEach(y=>{y.x+=f.x,y.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const g=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),m=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...m,...g]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:n,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var T,_;const i=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=Z.Resize(e,r,s?n.x*2:n.x,s?n.y*2:n.y,o);let u=r;l<0&&(u=ZX(u)),c<0&&(u=qX(u)),s&&(a.center=e.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",f=cI(u,a),g=this.getSnappablePoints(),m=[],v=[],S=new x(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:f});const y=new x(h?0:((T=m[0])==null?void 0:T.nudge)??0,p?0:((_=v[0])==null?void 0:_.nudge)??0);if(o&&QX(u)&&y.len()!==0){const k=m.length&&v.length?Math.abs(y.x)<Math.abs(y.y)?"x":"y":m.length?"x":"y",M=e.aspectRatio;k==="x"?(v.length=0,y.y=y.x/M,(u==="bottom_left"||u==="top_right")&&(y.y=-y.y)):(m.length=0,y.x=y.y*M,(u==="bottom_left"||u==="top_right")&&(y.x=-y.x))}const b=x.Add(n,y),{box:P}=Z.Resize(e,r,s?b.x*2:b.x,s?b.y*2:b.y,o);s&&(P.center=e.center);const C=cI("any",P);m.length=0,v.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:C});const I=this.getPointSnapLines({nearestSnapsX:m,nearestSnapsY:v});return this.manager.setIndicators([...I]),{nudge:y}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:n,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of e)for(const a of n){const l=x.Sub(i,a),c=Math.abs(l.x),u=Math.abs(l.y);de(c)<=de(r.x)&&(de(c)<de(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),de(u)<=de(r.y)&&(de(u)<de(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:e,minOffset:n,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!xc(a.breadthIntersection[0],a.breadthIntersection[1],e.minY,e.maxY))continue;const c=a.startEdge[0].x+a.length/2-e.center.x;if(a.length>e.width&&de(Math.abs(c))<=de(n.x)){de(Math.abs(c))<de(n.x)&&(r.length=0),n.x=Math.abs(c);const S={type:"gap_center",gap:a,nudge:c},y=r.find(({type:P})=>P==="gap_center"),b=y&&Ur(a.breadthIntersection[0],a.breadthIntersection[1],y.gap.breadthIntersection[0],y.gap.breadthIntersection[1]);y&&y.gap.length>a.length&&b?r[r.indexOf(y)]=S:(!y||!b)&&r.push(S)}const h=a.startNode.pageBounds.minX-a.length,p=e.maxX,f=h-p;de(Math.abs(f))<=de(n.x)&&(de(Math.abs(f))<de(n.x)&&(r.length=0),n.x=Math.abs(f),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:f}));const g=a.endNode.pageBounds.maxX+a.length,m=e.minX,v=g-m;de(Math.abs(v))<=de(n.x)&&(de(Math.abs(v))<de(n.x)&&(r.length=0),n.x=Math.abs(v),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:v}))}for(const a of i){if(!xc(a.breadthIntersection[0],a.breadthIntersection[1],e.minX,e.maxX))continue;const c=a.startEdge[0].y+a.length/2-e.center.y;if(a.length>e.height&&de(Math.abs(c))<=de(n.y)){de(Math.abs(c))<de(n.y)&&(o.length=0),n.y=Math.abs(c);const S={type:"gap_center",gap:a,nudge:c},y=o.find(({type:P})=>P==="gap_center"),b=y&&xc(y.gap.breadthIntersection[0],y.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);y&&y.gap.length>a.length&&b?o[o.indexOf(y)]=S:(!y||!b)&&o.push(S);continue}const h=a.startNode.pageBounds.minY-a.length,p=e.maxY,f=h-p;de(Math.abs(f))<=de(n.y)&&(de(Math.abs(f))<de(n.y)&&(o.length=0),n.y=Math.abs(f),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:f}));const g=a.endNode.pageBounds.maxY+a.length,m=e.minY,v=g-m;de(Math.abs(v))<=de(n.y)&&(de(Math.abs(v))<de(n.y)&&(o.length=0),n.y=Math.abs(v),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:v}))}}getPointSnapLines({nearestSnapsX:e,nearestSnapsY:n}){const r={},o={};if(e.length>0){for(const s of e)if(s.type==="points"){const i=de(s.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(s.points)}}if(n.length>0){for(const s of n)if(s.type==="points"){const i=de(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:Ke(),type:"points",points:iw(s.map(i=>x.From(i.otherPoint)).concat(s.map(i=>x.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:e,nearestSnapsX:n,nearestSnapsY:r}){const{vertical:o,horizontal:s}=this.getVisibleGaps(),i={top:e.sides[0],right:e.sides[1],bottom:[e.corners[3],e.corners[2]],left:[e.corners[0],e.corners[3]]},a=[];if(n.length>0)for(const l of n){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:f,endEdge:g}}=l;switch(l.type){case"gap_center":{const m=(f-e.width)/2,v=Ur(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:Ke(),gaps:[...Vo(s,h.id,m,"backward",v),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:g},...Vo(s,p.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Ur(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:Ke(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(v=>v.clone().addXY(-h.pageBounds.width,0))},{startEdge:u,endEdge:g},...Vo(s,p.id,f,"forward",m)]:[...Vo(s,h.id,f,"backward",m),{startEdge:u,endEdge:g},{startEdge:g.map(v=>v.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:f,endEdge:g}}=l;switch(l.type){case"gap_center":{const m=(f-e.height)/2,v=Ur(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:Ke(),gaps:[...Vo(o,h.id,m,"backward",v),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:g},...Vo(o,l.gap.endNode.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Ur(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:Ke(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(v=>v.clone().addXY(0,-h.pageBounds.height))},{startEdge:u,endEdge:g},...Vo(o,p.id,f,"forward",m)]:[...Vo(o,h.id,f,"backward",m),{startEdge:u,endEdge:g},{startEdge:g.map(v=>v.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return BQ(a),a}}ma=LQ();Lg(ma,1,"getSnapPointsCache",tO,Gl);Lg(ma,1,"getSnappablePoints",eO,Gl);Lg(ma,1,"getSnappableGapNodes",Jj,Gl);Lg(ma,1,"getVisibleGaps",Qj,Gl);FQ(ma,Gl);function cI(t,e){const{minX:n,maxX:r,minY:o,maxY:s}=e,i=[];switch(t){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:n,y:o})}switch(t){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:o})}switch(t){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:s})}switch(t){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:n,y:s})}return i}var UQ=Object.create,nO=Object.defineProperty,HQ=Object.getOwnPropertyDescriptor,KQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),rO=t=>{throw TypeError(t)},oO=(t,e,n)=>e in t?nO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,WQ=t=>[,,,UQ(null)],sO=["class","method","getter","setter","accessor","field","value","get","set"],iO=t=>t!==void 0&&typeof t!="function"?rO("Function expected"):t,GQ=(t,e,n,r,o)=>({kind:sO[t],name:e,metadata:r,addInitializer:s=>n._?rO("Already initialized"):o.push(iO(s||null))}),VQ=(t,e)=>oO(e,KQ("metadata"),t[3]),YQ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},XQ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=sO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,HQ(o,n)),S=r.length-1;S>=0;S--)l=GQ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,iO(i)&&(v[g]=i);return v&&nO(o,n,v),o},qQ=(t,e,n)=>oO(t,e+"",n),aO,$g;const ZQ=()=>null,QQ=()=>[];aO=[G];class h1{constructor(e){this.manager=e,YQ($g,5,this),qQ(this,"editor"),this.editor=e.editor}getSnapGeometryCache(){const{editor:e}=this;return e.store.createComputedCache("handle snap geometry",n=>{const r=e.getShapeUtil(n).getHandleSnapGeometry(n),o=r.getSelfSnapOutline?r.getSelfSnapOutline.bind(r):ZQ,s=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):QQ;return{outline:r.outline===void 0?e.getShapeGeometry(n):r.outline,points:r.points??[],getSelfSnapOutline:o,getSelfSnapPoints:s}})}*iterateSnapPointsInPageSpace(e,n){var o,s;const r=(o=this.getSnapGeometryCache().get(e))==null?void 0:o.getSelfSnapPoints(n);if(r&&r.length){const i=nr(this.editor.getShapePageTransform(e));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.points;if(!a||!a.length)continue;const l=nr(this.editor.getShapePageTransform(i));for(const c of a)yield l.applyToPoint(c)}}*iterateSnapOutlines(e,n){var o,s;const r=(o=this.getSnapGeometryCache().get(e))==null?void 0:o.getSelfSnapOutline(n);r&&(yield{shapeId:e,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:e,handle:n,handleInPageSpace:r}){const o=this.manager.getSnapThreshold();let s=o,i=null;for(const c of this.iterateSnapPointsInPageSpace(e,n))x.DistMin(r,c,s)&&(s=x.Dist(r,c),i=c);if(i)return i;let a=o,l=null;for(const{shapeId:c,outline:u}of this.iterateSnapOutlines(e,n)){const h=nr(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),f=u.nearestPoint(p),g=h.applyToPoint(f);x.DistMin(r,g,a)&&(a=x.Dist(r,g),l=g)}return l||null}snapHandle({currentShapeId:e,handle:n}){const o=nr(this.editor.getShapePageTransform(e)).applyToPoint(n),s=this.getHandleSnapPosition({currentShapeId:e,handle:n,handleInPageSpace:o});return s?(this.manager.setIndicators([{id:Ke(),type:"points",points:[s]}]),{nudge:x.Sub(s,o)}):null}}$g=WQ();XQ($g,1,"getSnapGeometryCache",aO,h1);VQ($g,h1);var JQ=Object.create,lO=Object.defineProperty,eJ=Object.getOwnPropertyDescriptor,tJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),cO=t=>{throw TypeError(t)},uO=(t,e,n)=>e in t?lO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nJ=t=>[,,,JQ(null)],dO=["class","method","getter","setter","accessor","field","value","get","set"],hO=t=>t!==void 0&&typeof t!="function"?cO("Function expected"):t,rJ=(t,e,n,r,o)=>({kind:dO[t],name:e,metadata:r,addInitializer:s=>n._?cO("Already initialized"):o.push(hO(s||null))}),oJ=(t,e)=>uO(e,tJ("metadata"),t[3]),sJ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},p1=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=dO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,eJ(o,n)),S=r.length-1;S>=0;S--)l=rJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,hO(i)&&(v[g]=i);return v&&lO(o,n,v),o},zy=(t,e,n)=>uO(t,typeof e!="symbol"?e+"":e,n),pO,fO,gO,Vl;gO=[G],fO=[G],pO=[G];class cd{constructor(e){this.editor=e,sJ(Vl,5,this),zy(this,"shapeBounds"),zy(this,"handles"),zy(this,"_snapIndicators",Mt("snapLines",void 0)),this.shapeBounds=new Gl(this),this.handles=new h1(this)}getIndicators(){return this._snapIndicators.get()??os}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,n=e.getViewportPageBounds(),r=e.getSelectedShapeIds(),o=new Set,s=i=>{if(Rn(i)){const l=e.getShape(i);l&&e.isShapeOfType(l,"frame")&&o.add(i)}const a=e.getSortedChildIdsForParent(i);for(const l of a){if(r.includes(l))continue;const c=e.getShape(l);if(!c||!e.getShapeUtil(c).canSnap(c))continue;const h=e.getShapePageBounds(l);if(h&&n.includes(h)){if(e.isShapeOfType(c,"group")){s(l);continue}o.add(l)}}};return s(this.getCurrentCommonAncestor()??e.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Vl=nJ();p1(Vl,1,"getSnapThreshold",gO,cd);p1(Vl,1,"getSnappableShapes",fO,cd);p1(Vl,1,"getCurrentCommonAncestor",pO,cd);oJ(Vl,cd);const iJ=/\r?\n|\r/g;function uI(t){return t.replace(iJ,`
102
- `).split(`
103
- `).map(e=>e||" ").join(`
104
- `)}const aJ={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},lJ=/\s/;class cJ{constructor(e){E(this,"baseElm");this.editor=e;const n=this.editor.getContainer(),r=document.createElement("div");r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,n.appendChild(r),this.baseElm=r,e.disposables.add(()=>{r.remove()})}measureText(e,n){var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-style",n.fontStyle),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("font-size",n.fontSize+"px"),r.style.setProperty("line-height",n.lineHeight*n.fontSize+"px"),r.style.setProperty("max-width",n.maxWidth===null?null:n.maxWidth+"px"),r.style.setProperty("min-width",n.minWidth===null?null:n.minWidth+"px"),r.style.setProperty("padding",n.padding),r.style.setProperty("overflow-wrap",n.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=uI(e);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}}measureElementTextNodeSpans(e,{shouldTruncateToFirstLine:n=!1}={}){const r=[],o=e.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,l=e.childNodes[0];let c=0,u=null,h=null,p=0,f=0,g=!1;for(const m of e.childNodes)if(m.nodeType===Node.TEXT_NODE)for(const v of m.textContent??""){a.setStart(l,c),a.setEnd(l,c+v.length);const S=a.getClientRects(),y=S[S.length-1],b=y.top+i,P=y.left+s,C=y.right+s,I=P<f,T=lJ.test(v);if(T!==h||b!==p||!u){if(u){if(n&&b!==p){g=!0;break}r.push(u)}u={box:{x:P,y:b,w:y.width,h:y.height},text:v},f=P}else I&&(u.box.x=P),u.box.w=I?u.box.w+y.width:C-u.box.x,u.text+=v;v===`
105
- `&&(f=0),h=T,p=b,c+=v.length}return u&&r.push(u),{spans:r,didTruncate:g}}measureTextSpans(e,n){var c;if(e==="")return[];const r=(c=this.baseElm)==null?void 0:c.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(n.width-n.padding*2);r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("width",`${o}px`),r.style.setProperty("height","min-content"),r.style.setProperty("font-size",`${n.fontSize}px`),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("line-height",`${n.lineHeight*n.fontSize}px`),r.style.setProperty("text-align",aJ[n.textAlign]);const s=n.overflow==="truncate-ellipsis"||n.overflow==="truncate-clip";s&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=uI(e);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(n.overflow==="truncate-ellipsis"&&l){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}px`),r.textContent=i;const h=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,p=h[h.length-1];return h.push({text:"…",box:{x:Math.min(p.box.x+p.box.w,n.width-n.padding-u),y:p.box.y,w:u,h:p.box.h}}),h}return r.remove(),a}}var uJ=Object.create,mO=Object.defineProperty,dJ=Object.getOwnPropertyDescriptor,hJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),yO=t=>{throw TypeError(t)},SO=(t,e,n)=>e in t?mO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,pJ=t=>[,,,uJ(null)],vO=["class","method","getter","setter","accessor","field","value","get","set"],xO=t=>t!==void 0&&typeof t!="function"?yO("Function expected"):t,fJ=(t,e,n,r,o)=>({kind:vO[t],name:e,metadata:r,addInitializer:s=>n._?yO("Already initialized"):o.push(xO(s||null))}),gJ=(t,e)=>SO(e,hJ("metadata"),t[3]),mJ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},wO=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=vO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,dJ(o,n)),S=r.length-1;S>=0;S--)l=fJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,xO(i)&&(v[g]=i);return v&&mO(o,n,v),o},ch=(t,e,n)=>SO(t,typeof e!="symbol"?e+"":e,n),bO,PO,ud;const dI=(typeof process<"u",TT);PO=[ar],bO=[ar];class Fg{constructor(e){this.editor=e,mJ(ud,5,this),ch(this,"cancelRaf"),ch(this,"isPaused",!0),ch(this,"now",0),ch(this,"prevPoint",new x),this.editor.disposables.add(this.dispose),this.start()}start(){var e;this.isPaused=!1,(e=this.cancelRaf)==null||e.call(this),this.cancelRaf=dI(this.tick),this.now=Date.now()}tick(){if(this.isPaused)return;const e=Date.now(),n=e-this.now;this.now=e,this.updatePointerVelocity(n),this.editor.emit("frame",n),this.editor.emit("tick",n),this.cancelRaf=dI(this.tick)}dispose(){var e;this.isPaused=!0,(e=this.cancelRaf)==null||e.call(this)}updatePointerVelocity(e){const{prevPoint:n,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(e===0)return;const s=x.Sub(r,n);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new x(0,0),l=o.clone().lrp(a.mul(i/e),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),o.equals(l)||(this.editor.inputs.pointerVelocity=l)}}ud=pJ();wO(ud,1,"tick",PO,Fg);wO(ud,1,"dispose",bO,Fg);gJ(ud,Fg);var yJ=Object.create,CO=Object.defineProperty,SJ=Object.getOwnPropertyDescriptor,vJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),_O=t=>{throw TypeError(t)},IO=(t,e,n)=>e in t?CO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,xJ=t=>[,,,yJ(null)],EO=["class","method","getter","setter","accessor","field","value","get","set"],kO=t=>t!==void 0&&typeof t!="function"?_O("Function expected"):t,wJ=(t,e,n,r,o)=>({kind:EO[t],name:e,metadata:r,addInitializer:s=>n._?_O("Already initialized"):o.push(kO(s||null))}),bJ=(t,e)=>IO(e,vJ("metadata"),t[3]),PJ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},Rr=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=EO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,SJ(o,n)),S=r.length-1;S>=0;S--)l=wJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,kO(i)&&(v[g]=i);return v&&CO(o,n,v),o},CJ=(t,e,n)=>IO(t,e+"",n),TO,MO,AO,jO,OO,DO,RO,LO,$O,FO,NO,zO,En;zO=[G],NO=[G],FO=[G],$O=[G],LO=[G],RO=[G],DO=[G],OO=[G],jO=[G],AO=[G],MO=[G],TO=[G];class Xn{constructor(e,n){if(this.user=e,this.inferDarkMode=n,PJ(En,5,this),CJ(this,"systemColorScheme",Mt("systemColorScheme","light")),typeof window>"u"||!("matchMedia"in window))return;const r=window.matchMedia("(prefers-color-scheme: dark)");r!=null&&r.matches&&this.systemColorScheme.set("dark"),r==null||r.addEventListener("change",o=>{o.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")})}updateUserPreferences(e){this.user.setUserPreferences({...this.user.userPreferences.get(),...e})}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme){case"dark":return!0;case"light":return!1;case"system":return this.systemColorScheme.get()==="dark";default:return this.inferDarkMode?this.systemColorScheme.get()==="dark":!1}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??Ko.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??Ko.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??Ko.name}getLocale(){return this.user.userPreferences.get().locale??Ko.locale}getColor(){return this.user.userPreferences.get().color??Ko.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??Ko.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??Ko.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??Ko.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??Ko.isPasteAtCursorMode}}En=xJ();Rr(En,1,"getUserPreferences",zO,Xn);Rr(En,1,"getIsDarkMode",NO,Xn);Rr(En,1,"getEdgeScrollSpeed",FO,Xn);Rr(En,1,"getAnimationSpeed",$O,Xn);Rr(En,1,"getId",LO,Xn);Rr(En,1,"getName",RO,Xn);Rr(En,1,"getLocale",DO,Xn);Rr(En,1,"getColor",OO,Xn);Rr(En,1,"getIsSnapMode",jO,Xn);Rr(En,1,"getIsWrapMode",AO,Xn);Rr(En,1,"getIsDynamicResizeMode",MO,Xn);Rr(En,1,"getIsPasteAtCursorMode",TO,Xn);bJ(En,Xn);const _J={wheel:"onWheel",pointer_down:"onPointerDown",pointer_move:"onPointerMove",long_press:"onLongPress",pointer_up:"onPointerUp",right_click:"onRightClick",middle_click:"onMiddleClick",key_down:"onKeyDown",key_up:"onKeyUp",key_repeat:"onKeyRepeat",cancel:"onCancel",complete:"onComplete",interrupt:"onInterrupt",double_click:"onDoubleClick",triple_click:"onTripleClick",quadruple_click:"onQuadrupleClick",tick:"onTick"},IJ=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class ie{constructor(e,n){E(this,"performanceTracker");E(this,"id");E(this,"type");E(this,"shapeType");E(this,"initial");E(this,"children");E(this,"isLockable");E(this,"parent");E(this,"_path");E(this,"_current");E(this,"_isActive");E(this,"_currentToolIdMask",Mt("curent tool id mask",void 0));this.editor=e;const{id:r,children:o,initial:s,isLockable:i}=this.constructor;this.id=r,this._isActive=Mt("toolIsActive"+this.id,!1),this._current=Mt("toolState"+this.id,void 0),this._path=G("toolPath"+this.id,()=>{const a=this.getCurrent();return this.id+(a?`.${a.getPath()}`:"")}),this.parent=n??{},this.parent?o&&s?(this.type="branch",this.initial=s,this.children=Object.fromEntries(o().map(a=>[a.id,new a(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",o&&s&&(this.initial=s,this.children=Object.fromEntries(o().map(a=>[a.id,new a(this.editor,this)])),this._current.set(this.children[this.initial]))),this.isLockable=i,this.performanceTracker=new aT}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}transition(e,n={}){var s;const r=e.split(".");let o=this;for(let i=0;i<r.length;i++){const a=r[i],l=o.getCurrent(),c=(s=o.children)==null?void 0:s[a];if(!c)throw Error(`${o.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(n,a),o._current.set(c),c.enter(n,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;o=c}return this}handleEvent(e){var o;const n=_J[e.name],r=this._current.__unsafe__getWithoutCapture();(o=this[n])==null||o.call(this,e),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(e)}enter(e,n){var r;if(xt.measurePerformance.get()&&IJ.includes(this.id)&&this.performanceTracker.start(this.id),this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,e,n),this.children&&this.initial&&this.getIsActive()){const o=this.children[this.initial];this._current.set(o),o.enter(e,n)}}exit(e,n){var r,o;xt.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,e,n),this.getIsActive()||(o=this.getCurrent())==null||o.exit(e,n)}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(e){this._currentToolIdMask.set(e)}}E(ie,"id"),E(ie,"initial"),E(ie,"children"),E(ie,"isLockable",!0);class yx extends ie{static children(){return[]}onKeyDown(e){var n;switch(e.code){case"KeyZ":{if(!(e.shiftKey||e.ctrlKey)){const r=this.getCurrent();r&&((n=r.getCurrent())==null?void 0:n.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...e,onInteractionEnd:r.id})}break}}}}E(yx,"id","root"),E(yx,"initial","");var EJ=Object.create,BO=Object.defineProperty,kJ=Object.getOwnPropertyDescriptor,UO=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),HO=t=>{throw TypeError(t)},KO=(t,e,n)=>e in t?BO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,TJ=t=>[,,,EJ((t==null?void 0:t[UO("metadata")])??null)],WO=["class","method","getter","setter","accessor","field","value","get","set"],GO=t=>t!==void 0&&typeof t!="function"?HO("Function expected"):t,MJ=(t,e,n,r,o)=>({kind:WO[t],name:e,metadata:r,addInitializer:s=>n._?HO("Already initialized"):o.push(GO(s||null))}),AJ=(t,e)=>KO(e,UO("metadata"),t[3]),jJ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},te=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=WO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,kJ(o,n)),S=r.length-1;S>=0;S--)l=MJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,GO(i)&&(v[g]=i);return v&&BO(o,n,v),o},he=(t,e,n)=>KO(t,typeof e!="symbol"?e+"":e,n),VO,YO,XO,qO,ZO,QO,JO,eD,tD,nD,rD,oD,sD,iD,aD,lD,cD,uD,dD,hD,pD,fD,gD,mD,yD,SD,vD,xD,wD,bD,PD,CD,_D,ID,ED,kD,TD,MD,AD,jD,OD,DD,RD,LD,$D,FD,ND,zD,BD,UD,HD,KD,WD,GD,VD,YD,XD,qD,ZD,QD,JD,eR,tR,nR,rR,oR,sR,iR,aR,lR,Sx,J;class Q extends(Sx=Jq,lR=[G],aR=[G],iR=[G],sR=[G],oR=[G],rR=[G],nR=[G],tR=[G],eR=[G],JD=[G],QD=[G],ZD=[G],qD=[G],XD=[G],YD=[G],VD=[G],GD=[G],WD=[G],KD=[G],HD=[G],UD=[G],BD=[G],zD=[G],ND=[G],FD=[G],$D=[G],LD=[G],RD=[G],DD=[G],OD=[G],jD=[G],AD=[G],MD=[G],TD=[G],kD=[G],ED=[G],ID=[G],_D=[G],CD=[G],PD=[G],bD=[G],wD=[G],xD=[G],vD=[G],SD=[G],yD=[G],mD=[G],gD=[G],fD=[G],pD=[G],hD=[G],dD=[G],uD=[G],cD=[G],lD=[G],aD=[G],iD=[G],sD=[G],oD=[G],rD=[G],nD=[G],tD=[G],eD=[G],JO=[G],QO=[G({isEqual:(e,n)=>e.equals(n)})],ZO=[G],qO=[G],XO=[ar],YO=[ar],VO=[ar],Sx){constructor({store:e,user:n,shapeUtils:r,bindingUtils:o,tools:s,getContainer:i,cameraOptions:a,initialState:l,autoFocus:c,inferDarkMode:u,options:h,isShapeHidden:p}){super(),jJ(J,5,this),he(this,"_isShapeHiddenPredicate"),he(this,"options"),he(this,"store"),he(this,"root"),he(this,"disposables",new Set),he(this,"isDisposed",!1),he(this,"_tickManager"),he(this,"snaps"),he(this,"timers"),he(this,"user"),he(this,"textMeasure"),he(this,"environment"),he(this,"scribbles"),he(this,"sideEffects"),he(this,"edgeScrollManager"),he(this,"focusManager"),he(this,"getContainer"),he(this,"shapeUtils"),he(this,"styleProps"),he(this,"bindingUtils"),he(this,"history"),he(this,"_shouldIgnoreShapeLock",!1),he(this,"_crashingError",null),he(this,"_isChangingStyleTimeout",-1),he(this,"_cameraOptions",Mt("camera options",j_)),he(this,"_viewportAnimation",null),he(this,"_willSetInitialBounds",!0),he(this,"_isLockedOnFollowingUser",Mt("isLockedOnFollowingUser",!1)),he(this,"_cameraState",Mt("camera state","idle")),he(this,"_cameraStateTimeoutRemaining",0),he(this,"_currentPageShapeIds"),he(this,"_parentIdsToChildIds"),he(this,"animatingShapes",new Map),he(this,"externalAssetContentHandlers",{file:null,url:null}),he(this,"temporaryAssetPreview",new Map),he(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null}),he(this,"inputs",{originPagePoint:new x,originScreenPoint:new x,previousPagePoint:new x,previousScreenPoint:new x,currentPagePoint:new x,currentScreenPoint:new x,keys:new Set,buttons:new Set,isPen:!1,shiftKey:!1,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,isSpacebarPanning:!1,pointerVelocity:new x}),he(this,"_clickManager",new Rg(this)),he(this,"_prevCursor","default"),he(this,"_shiftKeyTimeout",-1),he(this,"_altKeyTimeout",-1),he(this,"_ctrlKeyTimeout",-1),he(this,"_restoreToolId","select"),he(this,"_pinchStart",1),he(this,"_didPinch",!1),he(this,"_selectedShapeIdsAtPointerDown",[]),he(this,"_longPressTimeout",-1),he(this,"capturedPointerId",null),he(this,"performanceTracker"),he(this,"performanceTrackerTimeout",-1),he(this,"_pendingEventsForNextTick",[]),this._isShapeHiddenPredicate=p,this.options={...eQ,...h},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new TQ({store:e,annotateError:k=>{this.annotateError(k,{origin:"history.batch",willCrashApp:!0}),this.crash(k)}}),this.snaps=new cd(this),this.timers=new F9,this.disposables.add(this.timers.dispose.bind(this.timers)),this._cameraOptions.set({...j_,...a}),this.user=new Xn(n??lj(),u??!1),this.getContainer=i,this.textMeasure=new cJ(this),this._tickManager=new Fg(this);class f extends yx{}E(f,"initial",l??""),this.root=new f(this),this.root.children={};const g=yj(r),m={},v={},S=new Map;for(const k of g){const M=new k(this);m[k.type]=M;const R=zM(k.props??{});v[k.type]=R;for(const j of R.keys())if(!S.has(j.id))S.set(j.id,j);else if(S.get(j.id)!==j)throw Error(`Multiple style props with id "${j.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=m,this.styleProps=v;const y=fj(o),b={};for(const k of y){const M=new k(this);b[k.type]=M}this.bindingUtils=b;for(const k of[...s]){if(qr(this.root.children,k.id))throw Error(`Can't override tool with id "${k.id}"`);this.root.children[k.id]=new k(this,this.root)}this.environment=new _Q(this),this.scribbles=new jQ(this);const P=(k,M)=>{let R=null;const j=k.selectedShapeIds.filter(B=>!M.has(B));j.length!==k.selectedShapeIds.length&&(R||(R={...k}),R.selectedShapeIds=j);const O=k.erasingShapeIds.filter(B=>!M.has(B));O.length!==k.erasingShapeIds.length&&(R||(R={...k}),R.erasingShapeIds=O),k.hoveredShapeId&&M.has(k.hoveredShapeId)&&(R||(R={...k}),R.hoveredShapeId=null),k.editingShapeId&&M.has(k.editingShapeId)&&(R||(R={...k}),R.editingShapeId=null);const D=k.hintingShapeIds.filter(B=>!M.has(B));return D.length!==k.hintingShapeIds.length&&(R||(R={...k}),R.hintingShapeIds=D),k.focusedGroupId&&M.has(k.focusedGroupId)&&(R||(R={...k}),R.focusedGroupId=null),R};this.sideEffects=this.store.sideEffects;let C=new Map;const I=new Set,T=new Set;let _=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var k,M,R,j;I.clear();for(const O of T){T.delete(O);const D=this.getShape(O);if(!D)continue;const B=this.getShapeUtil(D),z=(k=B.onChildrenChange)==null?void 0:k.call(B,D);z!=null&&z.length&&this.updateShapes(z)}if(_.size){const O=_;_=new Set;for(const D of O){const B=this.getBindingUtil(D);(M=B.onOperationComplete)==null||M.call(B)}}if(C.size){const O=C;C=new Map;for(const D of O.values())(j=(R=this.getBindingUtil(D.binding)).onAfterDelete)==null||j.call(R,D)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(k,M)=>{var R,j,O,D;for(const B of this.getBindingsInvolvingShape(M))_.add(B.type),B.fromId===M.id&&((j=(R=this.getBindingUtil(B)).onAfterChangeFromShape)==null||j.call(R,{binding:B,shapeBefore:k,shapeAfter:M})),B.toId===M.id&&((D=(O=this.getBindingUtil(B)).onAfterChangeToShape)==null||D.call(O,{binding:B,shapeBefore:k,shapeAfter:M}));if(k.parentId!==M.parentId){const B=z=>{var N,H,Y,ee;const K=this.getShape(z);if(K)for(const ce of this.getBindingsInvolvingShape(K))_.add(ce.type),ce.fromId===K.id&&((H=(N=this.getBindingUtil(ce)).onAfterChangeFromShape)==null||H.call(N,{binding:ce,shapeBefore:K,shapeAfter:K})),ce.toId===K.id&&((ee=(Y=this.getBindingUtil(ce)).onAfterChangeToShape)==null||ee.call(Y,{binding:ce,shapeBefore:K,shapeAfter:K}))};B(M.id),this.visitDescendants(M.id,B)}if(k.parentId!==M.parentId&&jn(M.parentId)){const B=new Set([k.id]);this.visitDescendants(k.id,z=>{B.add(z)});for(const z of this.getPageStates()){if(z.pageId===M.parentId)continue;const K=P(z,B);K&&this.store.put([K])}}k.parentId&&Rn(k.parentId)&&T.add(k.parentId),M.parentId!==k.parentId&&Rn(M.parentId)&&T.add(M.parentId)},beforeDelete:k=>{var O,D,B,z;if(I.has(k.id))return;k.parentId&&Rn(k.parentId)&&T.add(k.parentId),I.add(k.id);const M=[];for(const K of this.getBindingsInvolvingShape(k)){_.add(K.type),M.push(K.id);const N=this.getBindingUtil(K);K.fromId===k.id?((O=N.onBeforeIsolateToShape)==null||O.call(N,{binding:K,removedShape:k}),(D=N.onBeforeDeleteFromShape)==null||D.call(N,{binding:K,shape:k})):((B=N.onBeforeIsolateFromShape)==null||B.call(N,{binding:K,removedShape:k}),(z=N.onBeforeDeleteToShape)==null||z.call(N,{binding:K,shape:k}))}M.length&&this.deleteBindings(M);const R=new Set([k.id]),j=ye(this.getPageStates().map(K=>P(K,R)));j.length&&this.store.put(j)}},binding:{beforeCreate:k=>{var R,j;const M=(j=(R=this.getBindingUtil(k)).onBeforeCreate)==null?void 0:j.call(R,{binding:k});return M||k},afterCreate:k=>{var M,R;_.add(k.type),(R=(M=this.getBindingUtil(k)).onAfterCreate)==null||R.call(M,{binding:k})},beforeChange:(k,M)=>{var j,O;const R=(O=(j=this.getBindingUtil(M)).onBeforeChange)==null?void 0:O.call(j,{bindingBefore:k,bindingAfter:M});return R||M},afterChange:(k,M)=>{var R,j;_.add(M.type),(j=(R=this.getBindingUtil(M)).onAfterChange)==null||j.call(R,{bindingBefore:k,bindingAfter:M})},beforeDelete:k=>{var M,R;(R=(M=this.getBindingUtil(k)).onBeforeDelete)==null||R.call(M,{binding:k})},afterDelete:k=>{var M,R;(R=(M=this.getBindingUtil(k)).onAfterDelete)==null||R.call(M,{binding:k}),_.add(k.type)}},page:{afterCreate:k=>{const M=xo.createId(k.id),R=Gr.createId(k.id);this.store.has(M)||this.store.put([xo.create({id:M})]),this.store.has(R)||this.store.put([Gr.create({id:R,pageId:k.id})])},afterDelete:(k,M)=>{var O,D;if(((O=this.getInstanceState())==null?void 0:O.currentPageId)===k.id){const B=(D=this.getPages().find(z=>z.id!==k.id))==null?void 0:D.id;B?this.store.put([{...this.getInstanceState(),currentPageId:B}]):M==="user"&&this.store.ensureStoreIsUsable()}const R=xo.createId(k.id),j=Gr.createId(k.id);this.store.remove([R,j])}},instance:{afterChange:(k,M,R)=>{var j;if(!this.store.has(M.currentPageId)){const O=this.store.has(k.currentPageId)?k.currentPageId:(j=this.getPages()[0])==null?void 0:j.id;O?this.store.update(M.id,D=>({...D,currentPageId:O})):R==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(k,M)=>{if((k==null?void 0:k.selectedShapeIds)!==(M==null?void 0:M.selectedShapeIds)){const R=M.selectedShapeIds.filter(O=>{var B,z;let D=(B=this.getShape(O))==null?void 0:B.parentId;for(;Rn(D);){if(M.selectedShapeIds.includes(D))return!1;D=(z=this.getShape(D))==null?void 0:z.parentId}return!0});let j=null;if(R.length>0){const O=this.findCommonAncestor(ye(R.map(D=>this.getShape(D))),D=>this.isShapeOfType(D,"group"));O&&(j=O)}else M!=null&&M.focusedGroupId&&(j=M.focusedGroupId);(R.length!==M.selectedShapeIds.length||j!==M.focusedGroupId)&&this.store.put([{...M,selectedShapeIds:R,focusedGroupId:j??null}])}}}})),this._currentPageShapeIds=gQ(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=fQ(this.store),this.disposables.add(this.store.listen(k=>{this.emit("change",k)})),this.disposables.add(this.history.dispose),this.run(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})},{history:"ignore"}),l&&this.root.children[l]===void 0)throw Error(`No state found for initialState "${l}".`);this.root.enter(void 0,"initial"),this.edgeScrollManager=new CQ(this),this.focusManager=new IQ(this,c),this.disposables.add(this.focusManager.dispose.bind(this.focusManager)),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.on("tick",this._flushEventsForTick),this.timers.requestAnimationFrame(()=>{this._tickManager.start()}),this.performanceTracker=new aT}getIsShapeHiddenCache(){return this._isShapeHiddenPredicate?this.store.createComputedCache("isShapeHidden",e=>this.findShapeAncestor(e,r=>this.isShapeHidden(r))?!0:this._isShapeHiddenPredicate(e,this)??!1):null}isShapeHidden(e){return this._isShapeHiddenPredicate?!!this.getIsShapeHiddenCache().get(typeof e=="string"?e:e.id):!1}dispose(){this.disposables.forEach(e=>e()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(e){const n=typeof e=="string"?e:e.type,r=zn(this.shapeUtils,n);return Re(r,`No shape util found for type "${n}"`),r}getBindingUtil(e){const n=typeof e=="string"?e:e.type,r=zn(this.bindingUtils,n);return Re(r,`No binding util found for type "${n}"`),r}undo(){return this._flushEventsForTick(0),this.complete(),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.complete(),this.history.redo(),this}clearHistory(){return this.history.clear(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(e){return console.warn(typeof e=="string"?`[tldraw] \`editor.history.mark("${e}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`:"[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead."),this.history._mark(e??Ke()),this}markHistoryStoppingPoint(e){const n=`[${e??"stop"}]_${Ke()}`;return this.history._mark(n),n}getMarkIdMatching(e){return this.history.getMarkIdMatching(e)}squashToMark(e){return this.history.squashToMark(e),this}bail(){return this.history.bail(),this}bailToMark(e){return this.history.bailToMark(e),this}run(e,n){const r=this._shouldIgnoreShapeLock;this._shouldIgnoreShapeLock=(n==null?void 0:n.ignoreShapeLock)??r;try{this.history.batch(e,n)}finally{this._shouldIgnoreShapeLock=r}return this}batch(e,n){return this.run(e,n)}annotateError(e,{origin:n,willCrashApp:r,tags:o,extras:s}){const i=this.createErrorAnnotations(n,r);return cw(e,{tags:{...i.tags,...o},extras:{...i.extras,...s}}),r&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(e,n){try{const r=this.getEditingShapeId();return{tags:{origin:e,willCrashApp:n},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes(),editingShape:r?this.getShape(r):void 0,inputs:this.inputs}}}catch{return{tags:{origin:e,willCrashApp:n},extras:{}}}}getCrashingError(){return this._crashingError}crash(e){return this._crashingError=e,this.store.markAsPossiblyCorrupted(),this.emit("crash",{error:e}),this}getPath(){return this.root.getPath().split("root.")[1]}isIn(e){const n=e.split(".").reverse();let r=this.root;for(;n.length>0;){const o=n.pop();if(!o)return!0;const s=r.getCurrent();if((s==null?void 0:s.id)===o){if(n.length===0)return!0;r=s;continue}else return!1}return!1}isInAny(...e){return e.some(n=>this.isIn(n))}setCurrentTool(e,n={}){return this.root.transition(e,n),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const e=this.getCurrentTool();return e?e.getCurrentToolIdMask()??e.id:""}getStateDescendant(e){var o;const n=e.split(".").reverse();let r=this.root;for(;n.length>0;){const s=n.pop();if(!s)return r;const i=(o=r.children)==null?void 0:o[s];if(!i)return;r=i}return r}getDocumentSettings(){return this.store.get(sx)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(vn)}updateInstanceState(e,n){return this._updateInstanceState(e,{history:"ignore",...n}),e.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),e.isChangingStyle===!0&&(this._isChangingStyleTimeout=this.timers.setTimeout(()=>{this._updateInstanceState({isChangingStyle:!1},{history:"ignore"})},2e3))),this}_updateInstanceState(e,n){this.run(()=>{this.store.put([{...this.getInstanceState(),...e}])},n)}getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(e){const n=new Set(this.getOpenMenus());return n.has(e)||(n.add(e),this.updateInstanceState({openMenus:[...n]})),this}deleteOpenMenu(e){const n=new Set(this.getOpenMenus());return n.has(e)&&(n.delete(e),this.updateInstanceState({openMenus:[...n]})),this}clearOpenMenus(){return this.getOpenMenus().length&&this.updateInstanceState({openMenus:[]}),this}getIsMenuOpen(){return this.getOpenMenus().length>0}setCursor(e){return this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...e}}),this}getPageStates(){return this._getPageStatesQuery().get()}_getPageStatesQuery(){return this.store.query.records("instance_page_state")}getCurrentPageState(){return this.store.get(this._getCurrentPageStateId())}_getCurrentPageStateId(){return Gr.createId(this.getCurrentPageId())}updateCurrentPageState(e){return this._updateCurrentPageState(e),this}_updateCurrentPageState(e){this.store.update(e.id??this.getCurrentPageState().id,n=>({...n,...e}))}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:e}=this.getCurrentPageState();return ye(e.map(n=>this.store.get(n)))}setSelectedShapes(e){return this.run(()=>{const n=e.map(s=>typeof s=="string"?s:s.id),{selectedShapeIds:r}=this.getCurrentPageState(),o=new Set(r);if(n.length===o.size&&n.every(s=>o.has(s)))return null;this.store.put([{...this.getCurrentPageState(),selectedShapeIds:n}])},{history:"record-preserveRedoStack"})}isAncestorSelected(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null,r=this.getShape(n);if(!r)return!1;const o=this.getSelectedShapeIds();return!!this.findShapeAncestor(r,s=>o.includes(s.id))}select(...e){const n=typeof e[0]=="string"?e:e.map(r=>r.id);return this.setSelectedShapes(n),this}deselect(...e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=this.getSelectedShapeIds();return r.length>0&&n.length>0&&this.setSelectedShapes(r.filter(o=>!n.includes(o))),this}selectAll(){const e=this.getSortedChildIdsForParent(this.getCurrentPageId());return e.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(e)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var e;return((e=this.getOnlySelectedShape())==null?void 0:e.id)??null}getOnlySelectedShape(){const e=this.getSelectedShapes();return e.length===1?e[0]:null}getShapesPageBounds(e){const n=ye(e.map(r=>this.getShapePageBounds(r)));return n.length===0?null:Z.Common(n)}getSelectionPageBounds(){return this.getShapesPageBounds(this.getSelectedShapeIds())}getShapesSharedRotation(e){let n=!1,r=0;for(let o=0,s=e.length;o<s;o++){const i=this.getShapePageTransform(e[o]);if(i)if(n){if(i.rotation()!==r)return 0}else n=!0,r=i.rotation()}return r}getSelectionRotation(){return this.getShapesSharedRotation(this.getSelectedShapeIds())}getShapesRotatedPageBounds(e){if(e.length===0)return;const n=this.getShapesSharedRotation(e);if(n===0)return this.getShapesPageBounds(e)??void 0;if(e.length===1){const o=this.getShapeGeometry(e[0]).bounds.clone(),s=this.getShapePageTransform(e[0]);return o.point=s.applyToPoint(o.point),o}const r=Z.FromPoints(e.flatMap(o=>{const s=this.getShapePageTransform(o);return s?s.applyToPoints(this.getShapeGeometry(o).bounds.corners):[]}).map(o=>o.rot(-n)));return r.point=r.point.rot(n),r}getSelectionRotatedPageBounds(){return this.getShapesRotatedPageBounds(this.getSelectedShapeIds())}getSelectionRotatedScreenBounds(){const e=this.getSelectionRotatedPageBounds();if(!e)return;const{x:n,y:r}=this.pageToScreen(e.point),o=this.getZoomLevel();return new Z(n,r,e.width*o,e.height*o)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const e=this.getFocusedGroupId();return e?this.getShape(e):void 0}setFocusedGroup(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(n!==null){const r=this.getShape(n);if(!r)throw Error(`Editor.setFocusedGroup: Shape with id ${n} does not exist`);if(!this.isShapeOfType(r,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${r.type}`)}return n===this.getFocusedGroupId()?this:this.run(()=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:n}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const e=this.getFocusedGroup();if(e){const n=this.findShapeAncestor(e,r=>this.isShapeOfType(r,"group"));this.setFocusedGroup((n==null?void 0:n.id)??null),this.select(e.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const e=this.getEditingShapeId();return e?this.getShape(e):void 0}setEditingShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(n!==this.getEditingShapeId()){if(n){const r=this.getShape(n);if(r&&this.getShapeUtil(r).canEdit(r))return this.run(()=>{this._updateCurrentPageState({editingShapeId:n})},{history:"ignore"}),this}this.run(()=>{this._updateCurrentPageState({editingShapeId:null})},{history:"ignore"})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const e=this.getHoveredShapeId();return e?this.getShape(e):void 0}setHoveredShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;return n===this.getHoveredShapeId()?this:(this.run(()=>{this.updateCurrentPageState({hoveredShapeId:n})},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const e=this.getHintingShapeIds();return ye(e.map(n=>this.getShape(n)))}setHintingShapes(e){const n=typeof e[0]=="string"?e:e.map(r=>r.id);return this.run(()=>{this._updateCurrentPageState({hintingShapeIds:iw(n)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return ye(e.map(n=>this.getShape(n)))}setErasingShapes(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id);n.sort();const r=this.getErasingShapeIds();return this.run(()=>{if(n.length===r.length){for(let o=0;o<n.length;o++)if(n[o]!==r[o]){this._updateCurrentPageState({erasingShapeIds:n});break}}else this._updateCurrentPageState({erasingShapeIds:n})},{history:"ignore"}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;return n!==this.getCroppingShapeId()&&this.run(()=>{if(!n)this.updateCurrentPageState({croppingShapeId:null});else{const r=this.getShape(n),o=this.getShapeUtil(r);r&&o.canCrop(r)&&this.updateCurrentPageState({croppingShapeId:n})}},{history:"ignore"}),this}_unsafe_getCameraId(){return xo.createId(this.getCurrentPageId())}getCamera(){const e=this.store.get(this._unsafe_getCameraId());if(this._isLockedOnFollowingUser.get()){const n=this.getCameraForFollowing();if(n)return{...e,...n}}return e}getViewportPageBoundsForFollowing(){const e=this.getInstanceState().followingUserId;if(!e)return null;const n=this.getCollaborators().find(h=>h.userId===e);if(!n)return null;const{w:r,h:o}=n.screenBounds,{x:s,y:i,z:a}=n.camera,l=new Z(-s,-i,r/a,o/a),c=this.getViewportScreenBounds().clone(),u=c.width/c.height;return c.width=l.width,c.height=c.width/u,c.height<l.height&&(c.height=l.height,c.width=c.height*u),c.center=l.center,c}getCameraForFollowing(){const e=this.getViewportPageBoundsForFollowing();return e?{x:-e.x,y:-e.y,z:this.getViewportScreenBounds().w/e.width}:null}getZoomLevel(){return this.getCamera().z}getInitialZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.initialZoom==="default")return 1;const{zx:n,zy:r}=pI(this,e);switch(e.constraints.initialZoom){case"fit-min":return Math.max(n,r);case"fit-max":return Math.min(n,r);case"fit-x":return n;case"fit-y":return r;case"fit-min-100":return Math.min(1,Math.max(n,r));case"fit-max-100":return Math.min(1,Math.min(n,r));case"fit-x-100":return Math.min(1,n);case"fit-y-100":return Math.min(1,r);default:throw Tt(e.constraints.initialZoom)}}getBaseZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.baseZoom==="default")return 1;const{zx:n,zy:r}=pI(this,e);switch(e.constraints.baseZoom){case"fit-min":return Math.max(n,r);case"fit-max":return Math.min(n,r);case"fit-x":return n;case"fit-y":return r;case"fit-min-100":return Math.min(1,Math.max(n,r));case"fit-max-100":return Math.min(1,Math.min(n,r));case"fit-x-100":return Math.min(1,n);case"fit-y-100":return Math.min(1,r);default:throw Tt(e.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(e){var r;const n=tt({...this._cameraOptions.__unsafe__getWithoutCapture(),...e});return((r=n.zoomSteps)==null?void 0:r.length)<1&&(n.zoomSteps=[1]),this._cameraOptions.set(n),this}getConstrainedCamera(e,n){const r=this.getCamera();let{x:o,y:s,z:i=r.z}=e;if(!(n!=null&&n.force)){const a=this.getCameraOptions(),l=a.zoomSteps[0],c=Ut(a.zoomSteps),u=this.getViewportScreenBounds();if(a.constraints){const{constraints:h}=a,p=Math.min(h.padding.y,u.w/2),f=Math.min(h.padding.x,u.h/2),g=Z.From(a.constraints.bounds),m=(u.w-f*2)/g.w,v=(u.h-p*2)/g.h,S=this.getBaseZoom(),y=c*S,b=l*S;if(n!=null&&n.reset&&(i=this.getInitialZoom()),i<b||i>y){const{x:j,y:O,z:D}=r,B=-j+u.w/D/2,z=-O+u.h/D/2;i=zt(i,b,y);const K=-j+u.w/i/2,N=-O+u.h/i/2;o=j+K-B,s=O+N-z}const P=f/i-g.x,C=p/i-g.y,I=(u.w-f*2)/i-g.w,T=(u.h-p*2)/i-g.h,_=P+I*h.origin.x,k=C+T*h.origin.y,M=typeof h.behavior=="string"?h.behavior:h.behavior.x,R=typeof h.behavior=="string"?h.behavior:h.behavior.y;if(n!=null&&n.reset)o=_,s=k;else{switch(M){case"fixed":{o=_;break}case"contain":{i<m?o=_:o=zt(o,P+I,P);break}case"inside":{i<m?o=zt(o,P,(u.w-f)/i-g.w):o=zt(o,P+I,P);break}case"outside":{o=zt(o,f/i-g.w,(u.w-f)/i);break}case"free":break;default:throw Tt(M)}switch(R){case"fixed":{s=k;break}case"contain":{i<v?s=k:s=zt(s,C+T,C);break}case"inside":{i<v?s=zt(s,C,(u.h-p)/i-g.h):s=zt(s,C+T,C);break}case"outside":{s=zt(s,p/i-g.h,(u.h-p)/i);break}case"free":break;default:throw Tt(R)}}}else if(i>c||i<l){const{x:h,y:p,z:f}=r;i=zt(i,l,c),o=h+(-h+u.w/i/2)-(-h+u.w/f/2),s=p+(-p+u.h/i/2)-(-p+u.h/f/2)}}return{x:o,y:s,z:i}}_setCamera(e,n){const r=this.getCamera(),{x:o,y:s,z:i}=this.getConstrainedCamera(e,n);return r.x===o&&r.y===s&&r.z===i?this:(_o(()=>{const a={...r,x:o,y:s,z:i};this.run(()=>{this.store.put([a])},{history:"ignore"});const{currentScreenPoint:l,currentPagePoint:c}=this.inputs,{screenBounds:u}=this.store.unsafeGetWithoutCapture(vn);if(l.x/i-o!==c.x||l.y/i-s!==c.y){const h={type:"pointer",target:"canvas",name:"pointer_move",point:x.AddXY(l,u.x,u.y),pointerId:O_.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,button:0,isPen:this.getInstanceState().isPenMode??!1};n!=null&&n.immediate?this._flushEventForTick(h):this.dispatch(h)}this._tickCameraState()}),this)}setCamera(e,n){const{isLocked:r}=this._cameraOptions.__unsafe__getWithoutCapture();if(r&&!(n!=null&&n.force))return this;this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser();const o=x.Cast(e);Number.isFinite(o.x)||(o.x=0),Number.isFinite(o.y)||(o.y=0),(o.z===void 0||!Number.isFinite(o.z))&&(e.z=this.getZoomLevel());const s=this.getConstrainedCamera(o,n);if(n!=null&&n.animation){const{width:i,height:a}=this.getViewportScreenBounds();this._animateToViewport(new Z(-s.x,-s.y,i/s.z,a/s.z),n)}else this._setCamera(s,{...n,force:!0});return this}centerOnPoint(e,n){const{isLocked:r}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const{width:o,height:s}=this.getViewportPageBounds();return this.setCamera(new x(-(e.x-o/2),-(e.y-s/2),this.getCamera().z),n),this}zoomToFit(e){const n=[...this.getCurrentPageShapeIds()];if(n.length<=0)return this;const r=Z.Common(ye(n.map(o=>this.getShapePageBounds(o))));return this.zoomToBounds(r,e),this}resetZoom(e=this.getViewportScreenCenter(),n){const{isLocked:r,constraints:o}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const s=this.getCamera(),{x:i,y:a,z:l}=s,{x:c,y:u}=e;let h=1;if(o){const p=this.getInitialZoom();l!==p&&(h=p)}return this.setCamera(new x(i+(c/h-c)-(c/l-c),a+(u/h-u)-(u/l-u),h),n),this}zoomIn(e=this.getViewportScreenCenter(),n){const{isLocked:r}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const{x:o,y:s,z:i}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const l=this.getBaseZoom();let c=Ut(a)*l;for(let u=1;u<a.length;u++){const h=a[u-1]*l,p=a[u]*l;if(!(p-i<=(p-h)/2)){c=p;break}}this.setCamera(new x(o+(e.x/c-e.x)-(e.x/i-e.x),s+(e.y/c-e.y)-(e.y/i-e.y),c),n)}return this}zoomOut(e=this.getViewportScreenCenter(),n){const{isLocked:r}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const{zoomSteps:o}=this.getCameraOptions();if(o!==null&&o.length>1){const s=this.getBaseZoom(),{x:i,y:a,z:l}=this.getCamera();let c=o[0]*s;for(let u=o.length-1;u>0;u--){const h=o[u-1]*s,p=o[u]*s;if(!(p-l>=(p-h)/2)){c=h;break}}this.setCamera(new x(i+(e.x/c-e.x)-(e.x/l-e.x),a+(e.y/c-e.y)-(e.y/l-e.y),c),n)}return this}zoomToSelection(e){const{isLocked:n}=this.getCameraOptions();if(n&&!(e!=null&&e.force))return this;const r=this.getSelectionPageBounds();return r&&this.zoomToBounds(r,{targetZoom:Math.max(1,this.getZoomLevel()),...e}),this}zoomToBounds(e,n){const r=this._cameraOptions.__unsafe__getWithoutCapture();if(r.isLocked&&!(n!=null&&n.force))return this;const o=this.getViewportScreenBounds(),s=(n==null?void 0:n.inset)??Math.min(OY,o.width*.28),i=this.getBaseZoom(),a=r.zoomSteps[0],l=Ut(r.zoomSteps);let c=zt(Math.min((o.width-s)/e.w,(o.height-s)/e.h),a*i,l*i);return(n==null?void 0:n.targetZoom)!==void 0&&(c=Math.min(n.targetZoom,c)),this.setCamera(new x(-e.x+(o.width-e.w*c)/2/c,-e.y+(o.height-e.h*c)/2/c,c),n),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(e){if(!this._viewportAnimation)return;this._viewportAnimation.elapsed+=e;const{elapsed:n,easing:r,duration:o,start:s,end:i}=this._viewportAnimation;if(n>o){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new x(-i.x,-i.y,this.getViewportScreenBounds().width/i.width));return}const a=o-n,l=r(1-a/o),c=s.minX+(i.minX-s.minX)*l,u=s.minY+(i.minY-s.minY)*l,h=s.maxX+(i.maxX-s.maxX)*l;this._setCamera(new x(-c,-u,this.getViewportScreenBounds().width/(h-c)),{force:!0})}_animateToViewport(e,n={animation:Ay}){const{animation:r,...o}=n;if(!r)return;const{duration:s=0,easing:i=At.easeInOutCubic}=r,a=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),s===0||a===0?this._setCamera(new x(-e.x,-e.y,this.getViewportScreenBounds().width/e.width),{...o}):(this._viewportAnimation={elapsed:0,duration:s/a,easing:i,start:l.clone(),end:e.clone()},this.once("stop-camera-animation",()=>{this.off("tick",this._animateViewport),this._viewportAnimation=null}),this.on("tick",this._animateViewport),this)}slideCamera(e={}){const{isLocked:n}=this.getCameraOptions();if(n&&!(e!=null&&e.force))return this;if(this.user.getAnimationSpeed()===0)return this;this.stopCameraAnimation();const{speed:o,friction:s=this.options.cameraSlideFriction,direction:i,speedThreshold:a=.01}=e;let l=Math.min(o,1);const c=()=>{this.off("tick",u),this.off("stop-camera-animation",c)};this.once("stop-camera-animation",c);const u=h=>{const{x:p,y:f,z:g}=this.getCamera(),m=x.Mul(i,l*h/g);l*=1-s,l<a?c():this._setCamera(new x(p+m.x,f+m.y,g))};return this.on("tick",u),this}zoomToUser(e,n={animation:{duration:500}}){const r=this.getCollaborators().find(o=>o.userId===e);return r?(this.run(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const o=r.currentPageId===this.getCurrentPageId();o||this.setCurrentPage(r.currentPageId),n&&n.animation&&!o&&(n.animation=void 0),this.centerOnPoint(r.cursor,n);const{highlightedUserIds:s}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...s,e]}),this.timers.setTimeout(()=>{const i=[...this.getInstanceState().highlightedUserIds],a=i.indexOf(e);a<0||(i.splice(a,1),this.updateInstanceState({highlightedUserIds:i}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(e,n=!1){if(e instanceof HTMLElement){const a=e.getBoundingClientRect();e=new Z(a.left||a.x,a.top||a.y,Math.max(a.width,1),Math.max(a.height,1))}else e.width=Math.max(e.width,1),e.height=Math.max(e.height,1);const r=[e.minY!==0,!ti(document.body.scrollWidth,e.maxX,1),!ti(document.body.scrollHeight,e.maxY,1),e.minX!==0],{_willSetInitialBounds:o}=this;this._willSetInitialBounds=!1;const{screenBounds:s,insets:i}=this.getInstanceState();if(e.equals(s)&&r.every((a,l)=>a===i[l]))return this;if(o)this.updateInstanceState({screenBounds:e.toJson(),insets:r}),this.setCamera(this.getCamera());else if(n&&!this.getInstanceState().followingUserId){const a=this.getViewportPageBounds().center;this.updateInstanceState({screenBounds:e.toJson(),insets:r}),this.centerOnPoint(a)}else this.updateInstanceState({screenBounds:e.toJson(),insets:r}),this._setCamera(x.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:e,y:n,w:r,h:o}=this.getInstanceState().screenBounds;return new Z(e,n,r,o)}getViewportScreenCenter(){const e=this.getViewportScreenBounds();return new x(e.midX-e.minX,e.midY-e.minY)}getViewportPageBounds(){const{w:e,h:n}=this.getViewportScreenBounds(),{x:r,y:o,z:s}=this.getCamera();return new Z(-r,-o,e/s,n/s)}screenToPage(e){const{screenBounds:n}=this.store.unsafeGetWithoutCapture(vn),{x:r,y:o,z:s=1}=this.getCamera();return new x((e.x-n.x)/s-r,(e.y-n.y)/s-o,e.z??.5)}pageToScreen(e){const{screenBounds:n}=this.store.unsafeGetWithoutCapture(vn),{x:r,y:o,z:s=1}=this.getCamera();return new x((e.x+r)*s+n.x,(e.y+o)*s+n.y,e.z??.5)}pageToViewport(e){const{x:n,y:r,z:o=1}=this.getCamera();return new x((e.x+n)*o,(e.y+r)*o,e.z??.5)}_getCollaboratorsQuery(){return this.store.query.records("instance_presence",()=>({userId:{neq:this.user.getId()}}))}getCollaborators(){const e=this._getCollaboratorsQuery().get();return e.length?[...new Set(e.map(r=>r.userId))].sort().map(r=>e.filter(s=>s.userId===r).sort((s,i)=>i.lastActivityTimestamp-s.lastActivityTimestamp)[0]):os}getCollaboratorsOnCurrentPage(){const e=this.getCurrentPageId();return this.getCollaborators().filter(n=>n.currentPageId===e)}startFollowingUser(e){this.stopFollowingUser();const n=this._getCollaboratorsQuery().get().filter(s=>s.userId===e);if(!n.length)return console.warn("User not found"),this;const r=this.user.getId();if(r||console.warn("You should set the userId for the current instance before following a user"),n.some(s=>s.followingUserId===r))return this;const o=G("latestLeaderPresence",()=>this.getCollaborators().find(s=>s.userId===e));return _o(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const s=ii("update current page",()=>{const l=o.get();if(!l){this.stopFollowingUser();return}l.currentPageId!==this.getCurrentPageId()&&this.getPage(l.currentPageId)&&this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:l.currentPageId}]),this._isLockedOnFollowingUser.set(!0)},{history:"ignore"})}),i=()=>{s(),this._isLockedOnFollowingUser.set(!1),this.off("frame",a),this.off("stop-following",i)},a=()=>{if(!o.get()){this.stopFollowingUser();return}if(this._isLockedOnFollowingUser.get())return;const c=this.user.getAnimationSpeed();if(c===0){this._isLockedOnFollowingUser.set(!0);return}const u=this.getViewportPageBoundsForFollowing();if(!u){this.stopFollowingUser();return}const h=this.getViewportPageBounds(),p=Math.abs(u.minX-h.minX)+Math.abs(u.maxX-h.maxX),f=Math.abs(u.minY-h.minY)+Math.abs(u.maxY-h.maxY);if(p<this.options.followChaseViewportSnap&&f<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const g=zt(c*.5,.1,.8),m=new Z(Ee(h.minX,u.minX,g),Ee(h.minY,u.minY,g),Ee(h.width,u.width,g),Ee(h.height,u.height,g)),v=new x(-m.x,-m.y,this.getViewportScreenBounds().width/m.width);this.stopCameraAnimation(),this._setCamera(v)};this.once("stop-following",i),this.addListener("frame",a),a()}),this}stopFollowingUser(){return this.run(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")},{history:"ignore"}),this}getUnorderedRenderingShapes(e){const n=[];let r=this.options.maxShapesPerPage*2,o=this.options.maxShapesPerPage;const s=this.getErasingShapeIds(),i=(l,c,u)=>{const h=this.getShape(l);if(!h||this.isShapeHidden(h))return;c*=h.opacity;let p=!1;const f=this.getShapeUtil(h);e&&(p=!u&&s.includes(l),p&&(c*=.32)),n.push({id:l,shape:h,util:f,index:r,backgroundIndex:o,opacity:c}),r+=1,o+=1;const g=this.getSortedChildIdsForParent(l);if(!g.length)return;let m=null;f.providesBackgroundForChildren(h)&&(m=o,o=r,r+=this.options.maxShapesPerPage);for(const v of g)i(v,c,u||p);m!==null&&(o=m)},a=e?[this.getCurrentPage()]:this.getPages();for(const l of a)for(const c of this.getSortedChildIdsForParent(l.id))i(c,1,!1);return n}_decayCameraStateTimeout(e){this._cameraStateTimeoutRemaining-=e,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))}_tickCameraState(){this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(j9)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(ln)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(e){return this.store.get(typeof e=="string"?e:e.id)}getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getCurrentPageShapeIdsSorted(){return Array.from(this.getCurrentPageShapeIds()).sort()}getPageShapeIds(e){const n=typeof e=="string"?e:e.id,r=this.store.query.exec("shape",{parentId:{eq:n}});return this.getShapeAndDescendantIds(r.map(o=>o.id))}setCurrentPage(e){const n=typeof e=="string"?e:e.id;return this.store.has(n)?(this.stopFollowingUser(),this.complete(),this.run(()=>{this.store.put([{...this.getInstanceState(),currentPageId:n}])},{history:"record-preserveRedoStack"})):(console.error("Tried to set the current page id to a page that doesn't exist."),this)}updatePage(e){return this.getInstanceState().isReadonly?this:this.getPage(e.id)?this.run(()=>this.store.update(e.id,r=>({...r,...e}))):this}createPage(e){return this.run(()=>{if(this.getInstanceState().isReadonly||this.getPages().length>=this.options.maxPages)return;const n=this.getPages(),r=iQ(e.name??"Page 1",n.map(i=>i.name));let o=e.index;(!o||n.some(i=>i.index===o))&&(o=vo(n[n.length-1].index));const s=gr.create({meta:{},...e,name:r,index:o});this.store.put([s])}),this}deletePage(e){const n=typeof e=="string"?e:e.id;return this.run(()=>{if(this.getInstanceState().isReadonly)return;const r=this.getPages();if(r.length===1)return;const o=this.getPage(n);if(o){if(n===this.getCurrentPageId()){const s=r.findIndex(a=>a.id===n),i=r[s-1]??r[s+1];this.setCurrentPage(i.id)}this.store.remove([o.id])}}),this}duplicatePage(e,n=gr.createId()){if(this.getPages().length>=this.options.maxPages)return this;const r=typeof e=="string"?e:e.id,o=this.getPage(r);if(!o)return this;const s={...this.getCamera()},i=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(o.id));return this.run(()=>{var c;const a=this.getPages(),l=Eu(o.index,(c=a[a.indexOf(o)+1])==null?void 0:c.index);if(this.createPage({name:o.name+" Copy",id:n,index:l}),this.setCurrentPage(n),this.setCamera(s),i)return this.putContentOntoCurrentPage(i)}),this}renamePage(e,n){const r=typeof e=="string"?e:e.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:r,name:n}),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(e){return this.getInstanceState().isReadonly?this:e.length<=0?this:(this.run(()=>this.store.put(e),{history:"ignore"}),this)}updateAssets(e){return this.getInstanceState().isReadonly?this:e.length<=0?this:(this.run(()=>{this.store.put(e.map(n=>({...this.store.get(n.id),...n})))},{history:"ignore"}),this)}deleteAssets(e){if(this.getInstanceState().isReadonly)return this;const n=typeof e[0]=="string"?e:e.map(r=>r.id);return n.length<=0?this:(this.run(()=>this.store.remove(n),{history:"ignore"}),this)}getAsset(e){return this.store.get(typeof e=="string"?e:e.id)}async resolveAssetUrl(e,n){if(!e)return null;const r=this.getAsset(e);if(!r)return null;const{screenScale:o=1,shouldResolveToOriginal:s=!1}=n,a=Math.max(.125,(u=>Math.pow(2,Math.ceil(Math.log2(u))))(o)),l="connection"in navigator?navigator.connection.effectiveType:null,c=this.getInstanceState().devicePixelRatio;return await this.store.props.assets.resolve(r,{screenScale:o||1,steppedScreenScale:a,dpr:c,networkEffectiveType:l,shouldResolveToOriginal:s})}async uploadAsset(e,n){return await this.store.props.assets.upload(e,n)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",e=>this.getShapeUtil(e).getGeometry(e),(e,n)=>e.props===n.props)}getShapeGeometry(e){return this._getShapeGeometryCache().get(typeof e=="string"?e:e.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",e=>{var n,r;return(r=(n=this.getShapeUtil(e)).getHandles)==null?void 0:r.call(n,e)})}getShapeHandles(e){return this._getShapeHandlesCache().get(typeof e=="string"?e:e.id)}getShapeLocalTransform(e){const n=typeof e=="string"?e:e.id,r=this.getShape(n);if(!r)throw Error("Editor.getTransform: shape not found");return q.Identity().translate(r.x,r.y).rotate(r.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",e=>{if(jn(e.parentId))return this.getShapeLocalTransform(e);const n=this._getShapePageTransformCache().get(e.parentId)??q.Identity();return q.Compose(n,this.getShapeLocalTransform(e))})}getShapeParentTransform(e){const n=typeof e=="string"?e:e.id,r=this.getShape(n);return!r||jn(r.parentId)?q.Identity():this._getShapePageTransformCache().get(r.parentId)??q.Identity()}getShapePageTransform(e){const n=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(n)??q.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",e=>{const n=this._getShapePageTransformCache().get(e.id);return n?Z.FromPoints(q.applyToPoints(n,this.getShapeGeometry(e).vertices)):new Z})}getShapePageBounds(e){return this._getShapePageBoundsCache().get(typeof e=="string"?e:e.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",e=>{const n=this._getShapeMaskCache().get(e.id);if(!n)return;if(n.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const r=this._getShapePageTransformCache().get(e.id);return r?`polygon(${q.applyToPoints(q.Inverse(r),n).map(s=>`${s.x}px ${s.y}px`).join(",")})`:void 0})}getShapeClipPath(e){return this._getShapeClipPathCache().get(typeof e=="string"?e:e.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",e=>{if(jn(e.parentId))return;const n=this.getShapeAncestors(e.id).filter(o=>this.isShapeOfType(o,"frame"));return n.length===0?void 0:n.map(o=>this._getShapePageTransformCache().get(o.id).applyToPoints(this.getShapeGeometry(o).vertices)).reduce((o,s)=>{if(!(s&&o))return;const i=J_(o,s);return i?i.map(x.Cast):[]})})}getShapeMask(e){return this._getShapeMaskCache().get(typeof e=="string"?e:e.id)}getShapeMaskedPageBounds(e){return typeof e!="string"&&(e=e.id),this._getShapeMaskedPageBoundsCache().get(e)}_getShapeMaskedPageBoundsCache(){return this.store.createComputedCache("shapeMaskedPageBoundsCache",e=>{const n=this._getShapePageBoundsCache().get(e.id);if(!n)return;const r=this._getShapeMaskCache().get(e.id);if(r){if(r.length===0)return;const{corners:o}=n;if(o.every((i,a)=>i&&x.Equals(i,r[a])))return n.clone();const s=J_(r,o);return s?Z.FromPoints(s):void 0}return n})}getShapeAncestors(e,n=[]){const r=typeof e=="string"?e:e.id,o=this.getShape(r);if(!o)return n;const s=o.parentId;if(jn(s))return n.reverse(),n;const i=this.store.get(s);return i?(n.push(i),this.getShapeAncestors(i,n)):n}findShapeAncestor(e,n){const r=typeof e=="string"?e:e.id,o=this.getShape(r);if(!o)return;const s=o.parentId;if(jn(s))return;const i=this.getShape(s);if(i)return n(i)?i:this.findShapeAncestor(i,n)}hasAncestor(e,n){const r=typeof e=="string"?e:e==null?void 0:e.id,o=r&&this.getShape(r);return o?o.parentId===n?!0:this.hasAncestor(this.getShapeParent(o),n):!1}findCommonAncestor(e,n){var l;if(e.length===0)return;const r=typeof e[0]=="string"?e:e.map(c=>c.id),o=ye(r.map(c=>this.getShape(c)));if(o.length===1){const c=o[0].parentId;return jn(c)?void 0:n?(l=this.findShapeAncestor(o[0],n))==null?void 0:l.id:c}const[s,...i]=o;let a=this.getShapeParent(s);for(;a;){if(n&&!n(a)){a=this.getShapeParent(a);continue}if(i.every(c=>this.hasAncestor(c,a.id)))return a.id;a=this.getShapeParent(a)}}isShapeOrAncestorLocked(e){const n=typeof e=="string"?this.getShape(e):e;return n===void 0?!1:n.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(n))}_notVisibleShapes(){return pQ(this)}getCulledShapes(){const e=this._notVisibleShapes().get(),n=this.getSelectedShapeIds(),r=this.getEditingShapeId(),o=new Set(e);return r&&o.delete(r),n.forEach(s=>{o.delete(s)}),o}getCurrentPageBounds(){let e;return this.getCurrentPageShapeIdsSorted().forEach(n=>{const r=this.getShapeMaskedPageBounds(n);r&&(e?e=e.expand(r):e=r.clone())}),e}getSelectedShapeAtPoint(e){const n=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(r=>r.type!=="group"&&n.includes(r.id)).reverse().find(r=>this.isPointInShape(r,e,{hitInside:!0,margin:0}))}getShapeAtPoint(e,n={}){const r=this.getZoomLevel(),o=this.getViewportPageBounds(),{filter:s,margin:i=0,hitLocked:a=!1,hitLabels:l=!1,hitInside:c=!1,hitFrameInside:u=!1}=n;let h=1/0,p=null,f=1/0,g=null;const m=(n.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(v=>{if(v.isLocked&&!a||this.isShapeHidden(v)||this.isShapeOfType(v,"group"))return!1;const S=this.getShapeMask(v);return S&&!ur(e,S)?!1:s?s(v):!0});for(let v=m.length-1;v>=0;v--){const S=m[v],y=this.getShapeGeometry(S),b=y instanceof eo,P=this.getPointInShapeSpace(S,e);if((this.isShapeOfType(S,"arrow")||this.isShapeOfType(S,"geo")&&S.props.fill==="none")&&S.props.text.trim()){for(const I of y.children)if(I.isLabel&&I.isPointInBounds(P))return S}if(this.isShapeOfType(S,"frame")){const I=y.distanceToPoint(P,c);if(Math.abs(I)<=i)return g||S;if(y.hitTestPoint(P,0,!0))return g||p||(u?S:void 0);continue}let C;if(b){let I=1/0;for(const T of y.children){if(T.isLabel&&!l)continue;const _=T.distanceToPoint(P,c);_<I&&(I=_)}C=I}else i===0&&(y.bounds.w<1||y.bounds.h<1)||y.bounds.containsPoint(P,i)?C=y.distanceToPoint(P,c):C=1/0;if(y.isClosed){if(C<=i){if(y.isFilled||b&&y.children[0].isFilled)return g||S;if(this.getShapePageBounds(S).contains(o))continue;if(Math.abs(C)<i)Math.abs(C)<f&&(f=Math.abs(C),g=S);else if(!g){const{area:I}=y;I<h&&(h=I,p=S)}}}else if(C<this.options.hitTestMargin/r)return S}return g||p||void 0}getShapesAtPoint(e,n={}){return this.getCurrentPageShapes().filter(r=>!this.isShapeHidden(r)&&this.isPointInShape(r,e,n))}isPointInShape(e,n,r={}){const{hitInside:o=!1,margin:s=0}=r,i=typeof e=="string"?e:e.id,a=this.getShapeMask(i);return a&&!ur(n,a)?!1:this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(e,n),s,o)}getPointInShapeSpace(e,n){const r=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(r).clone().invert().applyToPoint(n)}getPointInParentSpace(e,n){const r=typeof e=="string"?e:e.id,o=this.getShape(r);if(!o)return new x(0,0);if(jn(o.parentId))return x.From(n);const s=this.getShapePageTransform(o.parentId);return s?s.clone().invert().applyToPoint(n):x.From(n)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),e=>this.store.get(e))}getCurrentPageShapesSorted(){const e=[],n=this.getSortedChildIdsForParent(this.getCurrentPageId());for(let r=0,o=n.length;r<o;r++)cR(this,n[r],e);return e}getCurrentPageRenderingShapesSorted(){const e=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:n})=>!e.has(n)&&!this.isShapeHidden(n))}isShapeOfType(e,n){const r=typeof e=="string"?this.getShape(e):e;return r?r.type===n:!1}getShape(e){const n=typeof e=="string"?e:e.id;if(Rn(n))return this.store.get(n)}getShapeParent(e){const n=typeof e=="string"?e:e==null?void 0:e.id;if(!n)return;const r=this.getShape(n);if(!(r===void 0||!Rn(r.parentId)))return this.store.get(r.parentId)}getShapeNearestSibling(e,n){return n?n.parentId===e.parentId?n:this.findShapeAncestor(n,o=>o.parentId===e.parentId):void 0}isShapeInPage(e,n=this.getCurrentPageId()){const r=typeof e=="string"?e:e.id,o=this.getShape(r);if(!o)return!1;let s=!1;if(o.parentId===n)s=!0;else{let i=this.getShape(o.parentId);e:for(;i;){if(i.parentId===n){s=!0;break e}i=this.getShape(i.parentId)}}return s}getAncestorPageId(e){const n=typeof e=="string"?e:e==null?void 0:e.id,r=n&&this.getShape(n);if(r)return jn(r.parentId)?r.parentId:this.getAncestorPageId(this.getShape(r.parentId))}reparentShapes(e,n,r){const o=typeof e[0]=="string"?e:e.map(p=>p.id);if(o.length===0)return this;const s=[],i=jn(n)?q.Identity():this.getShapePageTransform(n),a=i.rotation();let l=[];const c=ye(this.getSortedChildIdsForParent(n).map(p=>this.getShape(p)));if(r){const p=c.find(f=>f.index===r);if(p){const f=c[c.indexOf(p)+1];f?l=_l(r,f.index,o.length):l=sy(r,o.length)}else{const f=c.sort(ln).find(g=>g.index>r);f?l=_l(r,f.index,o.length):l=sy(r,o.length)}}else{const p=c.length&&c[c.length-1];l=p?sy(p.index,o.length):ku(o.length)}const u=i.clone().invert(),h=ye(o.map(p=>this.getShape(p)));return this.run(()=>{for(let p=0;p<h.length;p++){const f=h[p],g=this.getShapePageTransform(f);if(!g)continue;const m=g.point();if(!m)continue;const v=u.applyToPoint(m),S=g.rotation()-a;s.push({id:f.id,type:f.type,parentId:n,x:v.x,y:v.y,rotation:S,index:l[p]})}this.updateShapes(s)},{ignoreShapeLock:!0}),this}getHighestIndexForParent(e){const n=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[n];if(!r||r.length===0)return"a1";const o=this.getShape(r[r.length-1]);return vo(o.index)}getSortedChildIdsForParent(e){const n=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[n];return r||os}visitDescendants(e,n){const r=typeof e=="string"?e:e.id,o=this.getSortedChildIdsForParent(r);for(const s of o)n(s)!==!1&&this.visitDescendants(s,n);return this}getShapeAndDescendantIds(e){const n=new Set;for(const r of e.map(o=>this.getShape(o)).sort(ln))n.add(r.id),this.visitDescendants(r,o=>{n.add(o)});return n}getDroppingOverShape(e,n=[]){const r=this.getCurrentPageShapesSorted();for(let o=r.length-1;o>=0;o--){const s=r[o];if(this.isShapeHidden(s)||this.getSelectedShapeIds().includes(s.id)||!this.getShapeUtil(s).canDropShapes(s,n)||n.find(a=>a.id===s.id||this.hasAncestor(s,a.id)))continue;const i=this.getShapeMaskedPageBounds(s.id);if(i&&i.containsPoint(e)&&this.getShapeGeometry(s).hitTestPoint(this.getPointInShapeSpace(s,e),0,!0))return s}}getOutermostSelectableShape(e,n){const r=typeof e=="string"?e:e.id,o=this.getShape(r);let s=o,i=o;const a=this.getFocusedGroup();for(;i;){if(this.isShapeOfType(i,"group")&&(a==null?void 0:a.id)!==i.id&&!this.hasAncestor(a,i.id)&&((n==null?void 0:n(i))??!0))s=i;else if((a==null?void 0:a.id)===i.id)break;i=this.getShapeParent(i)}return s}_getBindingsIndexCache(){const e=dQ(this);return this.store.createComputedCache("bindingsIndex",n=>e.get().get(n.id))}getBinding(e){return this.store.get(e)}getBindingsFromShape(e,n){const r=typeof e=="string"?e:e.id;return this.getBindingsInvolvingShape(r).filter(o=>o.fromId===r&&o.type===n)}getBindingsToShape(e,n){const r=typeof e=="string"?e:e.id;return this.getBindingsInvolvingShape(r).filter(o=>o.toId===r&&o.type===n)}getBindingsInvolvingShape(e,n){const r=typeof e=="string"?e:e.id,o=this._getBindingsIndexCache().get(r)??os;return n?o.filter(s=>s.type===n):o}createBindings(e){const n=[];for(const r of e){const o=this.getShape(r.fromId),s=this.getShape(r.toId);if(!o||!s||!this.canBindShapes({fromShape:o,toShape:s,binding:r}))continue;const a=this.getBindingUtil(r.type).getDefaultProps(),l=this.store.schema.types.binding.create({...r,id:r.id??Wi(),props:{...a,...r.props}});n.push(l)}return this.store.put(n),this}createBinding(e){return this.createBindings([e])}updateBindings(e){const n=[];for(const r of e){if(!r)continue;const o=this.getBinding(r.id);if(!o)continue;const s=po(o,r);if(s===o)continue;const i=this.getShape(s.fromId),a=this.getShape(s.toId);!i||!a||this.canBindShapes({fromShape:i,toShape:a,binding:s})&&n.push(s)}return this.store.put(n),this}updateBinding(e){return this.updateBindings([e])}deleteBindings(e,{isolateShapes:n=!1}={}){const r=e.map(o=>typeof o=="string"?o:o.id);return n?this.store.atomic(()=>{var o,s;for(const i of r){const a=this.getBinding(i);if(!a)continue;const l=this.getBindingUtil(a);(o=l.onBeforeIsolateFromShape)==null||o.call(l,{binding:a,removedShape:this.getShape(a.toId)}),(s=l.onBeforeIsolateToShape)==null||s.call(l,{binding:a,removedShape:this.getShape(a.fromId)}),this.store.remove([i])}}):this.store.remove(r),this}deleteBinding(e,n){return this.deleteBindings([e],n)}canBindShapes({fromShape:e,toShape:n,binding:r}){const o=typeof e=="string"?e:e.type,s=typeof n=="string"?n:n.type,i=typeof r=="string"?r:r.type,a={fromShapeType:o,toShapeType:s,bindingType:i};return o===s?this.getShapeUtil(o).canBind(a):this.getShapeUtil(o).canBind(a)&&this.getShapeUtil(s).canBind(a)}rotateShapesBy(e,n,r){const o=typeof e[0]=="string"?e:e.map(i=>i.id);if(o.length<=0)return this;const s=Fj({editor:this,ids:o});return s?(ep({delta:n,snapshot:s,editor:this,stage:"one-off",centerOverride:r==null?void 0:r.center}),this):this}getChangesToTranslateShape(e,n){var s,i,a;let r=e;const o=this.getShapeUtil(e);return r=po(r,((s=o.onTranslateStart)==null?void 0:s.call(o,r))??void 0),r=po(r,{id:e.id,type:e.type,x:n.x,y:n.y}),r=po(r,((i=o.onTranslate)==null?void 0:i.call(o,e,r))??void 0),r=po(r,((a=o.onTranslateEnd)==null?void 0:a.call(o,e,r))??void 0),r}nudgeShapes(e,n){const r=typeof e[0]=="string"?e:e.map(s=>s.id);if(r.length<=0)return this;const o=[];for(const s of r){const i=this.getShape(s),a=x.From(n),l=this.getShapeParentTransform(i);l&&a.rot(-l.rotation()),o.push(this.getChangesToTranslateShape(i,a.add(i)))}return this.updateShapes(o),this}duplicateShapes(e,n){return this.run(()=>{const r=typeof e[0]=="string"?e:e.map(p=>p.id);if(r.length<=0)return this;const o=new Set(r),s=this.getShapeAndDescendantIds(r),i=[...s].reverse(),a=new Map;for(const p of s)a.set(p,Ne());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=hI(this,s,p=>{const f=[];for(const m of p){const v=this.getBinding(m);if(!v)continue;const S=Wi();f.push({...v,id:S,fromId:nr(a.get(v.fromId)),toId:nr(a.get(v.toId))})}const g=[];for(const m of i){const v=nr(a.get(m)),S=this.getShape(m);if(!S)continue;let y=0,b=0;if(n&&o.has(m)){const P=this.getShapeParentTransform(S),C=new x(n.x,n.y).rot(-P.rotation());y=C.x,b=C.y}g.push({shape:{...S,id:v,x:S.x+y,y:S.y+b,index:"a1",parentId:a.get(S.parentId)??S.parentId},originalShape:S})}return{shapesToCreateWithOriginals:g,bindingsToCreate:f}});l.forEach(({shape:p,originalShape:f})=>{const g=f.parentId,m=this.getSortedChildIdsForParent(g),v=m.indexOf(f.id),S=m[v+1],y=S?this.getShape(S):void 0,b=Eu(f.index,y==null?void 0:y.index);p.index=b});const u=l.map(({shape:p})=>p);if(u.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){uh(this);return}if(this.createShapes(u),this.createBindings(c),this.setSelectedShapes(ye(r.map(p=>a.get(p)))),n!==void 0){const p=this.getSelectionPageBounds(),f=this.getViewportPageBounds();p&&!f.contains(p)&&this.centerOnPoint(p.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(e,n){const r=typeof e[0]=="string"?e:e.map(a=>a.id);if(r.length===0)return this;if(this.getInstanceState().isReadonly)return this;const o=this.getCurrentPageId();if(n===o)return this;if(!this.store.has(n))return this;const s=this.getContentFromCurrentPage(r);if(!s)return this;if(this.getPageShapeIds(n).size+s.shapes.length>this.options.maxShapesPerPage)return uh(this,n),this;const i=this.getCamera().z;return this.run(()=>{this.deleteShapes(r),this.setCurrentPage(n),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(s,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:i}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(e){const n=typeof e[0]=="string"?e:e.map(i=>i.id);if(this.getInstanceState().isReadonly||n.length===0)return this;let r=!0,o=!0;const s=[];for(const i of n){const a=this.getShape(i);a&&(s.push(a),a.isLocked?o=!1:r=!1)}return this.run(()=>{o?(this.updateShapes(s.map(i=>({id:i.id,type:i.type,isLocked:!0}))),this.setSelectedShapes([])):r?this.updateShapes(s.map(i=>({id:i.id,type:i.type,isLocked:!1}))):this.updateShapes(s.map(i=>({id:i.id,type:i.type,isLocked:!0})))}),this}sendToBack(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=lh(this,"toBack",n);return r&&this.updateShapes(r),this}sendBackward(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=lh(this,"backward",n);return r&&this.updateShapes(r),this}bringForward(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=lh(this,"forward",n);return r&&this.updateShapes(r),this}bringToFront(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=lh(this,"toFront",n);return r&&this.updateShapes(r),this}flipShapes(e,n){const r=typeof e[0]=="string"?e:e.map(i=>i.id);if(this.getInstanceState().isReadonly)return this;let o=ye(r.map(i=>this.getShape(i)));if(!o.length)return this;o=ye(o.map(i=>this.isShapeOfType(i,"group")?this.getSortedChildIdsForParent(i.id).map(a=>this.getShape(a)):i).flat());const s=Z.Common(ye(o.map(i=>this.getShapePageBounds(i)))).center;return this.run(()=>{for(const i of o){const a=this.getShapeGeometry(i).bounds,l=this.getShapePageTransform(i.id);l&&this.resizeShape(i.id,{x:n==="horizontal"?-1:1,y:n==="vertical"?-1:1},{initialBounds:a,initialPageTransform:l,initialShape:i,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(i).isAspectRatioLocked(i),scaleOrigin:s,scaleAxisRotation:0})}}),this}stackShapes(e,n,r){const o=typeof e[0]=="string"?e:e.map(m=>m.id);if(this.getInstanceState().isReadonly)return this;const s=o.map(m=>this.getShape(m)).filter(m=>m?this.getShapeUtil(m).canBeLaidOut(m):!1),i=s.length;if(r===0&&i<3||i<2)return this;const a=Object.fromEntries(s.map(m=>[m.id,this.getShapePageBounds(m)]));let l,c,u,h;n==="horizontal"?(l="x",c="minX",u="maxX",h="width"):(l="y",c="minY",u="maxY",h="height");let p;if(r===0){const m=[];s.sort((S,y)=>a[S.id][c]-a[y.id][c]);for(let S=0;S<i-1;S++){const y=s[S],b=s[S+1],P=a[y.id],I=a[b.id][c]-P[u],T=m.find(_=>_.gap===I);T?T.count++:m.push({gap:I,count:1})}let v=0;m.forEach(S=>{S.count>v&&(v=S.count,p=S.gap)}),v===1&&(p=Math.max(0,m.reduce((S,y)=>S+y.gap*y.count,0)/(i-1)))}else p=r;const f=[];let g=a[s[0].id][u];return s.forEach((m,v)=>{var C,I;if(v===0)return;const S={x:0,y:0};S[l]=g+p-a[m.id][l];const y=this.getShapeParent(m),b=y?x.Rot(S,-this.getShapePageTransform(y).decompose().rotation):S,P=(I=(C=this.getShapeUtil(m)).onTranslateStart)==null?void 0:I.call(C,m);f.push(P?{...P,[l]:m[l]+b[l]}:{id:m.id,type:m.type,[l]:m[l]+b[l]}),g+=a[m.id][h]+p}),this.updateShapes(f),this}packShapes(e,n){var I,T;const r=typeof e[0]=="string"?e:e.map(_=>_.id);if(this.getInstanceState().isReadonly)return this;if(r.length<2)return this;const o=r.map(_=>this.getShape(_)).filter(_=>_?this.getShapeUtil(_).canBeLaidOut(_):!1),s={},i={};let a,l,c=0;for(let _=0;_<o.length;_++)a=o[_],l=this.getShapePageBounds(a),s[a.id]=l,i[a.id]=l.clone(),c+=l.width*l.height;const u=Z.Common(ye(Object.values(s))),h=u.width;o.sort((_,k)=>s[k.id].height-s[_.id].height);const p=Math.max(Math.ceil(Math.sqrt(c/.95)),h),f=[new Z(u.x,u.y,p,1/0)];let g=0,m=0,v,S;for(let _=0;_<o.length;_++){a=o[_],l=i[a.id];for(let k=f.length-1;k>=0;k--)if(v=f[k],!(l.width>v.width||l.height>v.height)){l.x=v.x,l.y=v.y,m=Math.max(m,l.maxY),g=Math.max(g,l.maxX),l.width===v.width&&l.height===v.height?(S=f.pop(),k<f.length&&(f[k]=S)):l.height===v.height?(v.x+=l.width+n,v.width-=l.width+n):l.width===v.width?(v.y+=l.height+n,v.height-=l.height+n):(f.push(new Z(v.x+(l.width+n),v.y,v.width-(l.width+n),l.height)),v.y+=l.height+n,v.height-=l.height+n);break}}const y=Z.Common(Object.values(i)),b=x.Sub(u.center,y.center);let P;const C=[];for(let _=0;_<o.length;_++){a=o[_],l=s[a.id],P=i[a.id];const k=x.Sub(P.point,l.point).add(b),M=this.getShapeParentTransform(a);M&&k.rot(-M.rotation());const R={id:a.id,type:a.type,x:a.x+k.x,y:a.y+k.y},j=(T=(I=this.getShapeUtil(a)).onTranslateStart)==null?void 0:T.call(I,{...a,...R});j?C.push({...R,...j}):C.push(R)}return C.length&&this.updateShapes(C),this}alignShapes(e,n){const r=typeof e[0]=="string"?e:e.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(r.length<2)return this;const o=ye(r.map(l=>this.getShape(l))),s=Object.fromEntries(o.map(l=>[l.id,this.getShapePageBounds(l)])),i=Z.Common(ye(Object.values(s))),a=[];return o.forEach(l=>{const c=s[l.id];if(!c)return;const u={x:0,y:0};switch(n){case"top":{u.y=i.minY-c.minY;break}case"center-vertical":{u.y=i.midY-c.minY-c.height/2;break}case"bottom":{u.y=i.maxY-c.minY-c.height;break}case"left":{u.x=i.minX-c.minX;break}case"center-horizontal":{u.x=i.midX-c.minX-c.width/2;break}case"right":{u.x=i.maxX-c.minX-c.width;break}}const h=this.getShapeParent(l),p=h?x.Rot(u,-this.getShapePageTransform(h).decompose().rotation):u;a.push(this.getChangesToTranslateShape(l,x.Add(l,p)))}),this.updateShapes(a),this}distributeShapes(e,n){const r=typeof e[0]=="string"?e:e.map(y=>y.id);if(this.getInstanceState().isReadonly)return this;if(r.length<3)return this;const o=r.length,s=ye(r.map(y=>this.getShape(y))),i=Object.fromEntries(s.map(y=>[y.id,this.getShapePageBounds(y)]));let a,l,c,u,h;n==="horizontal"?(a="x",l="minX",c="maxX",u="midX",h="width"):(a="y",l="minY",c="maxY",u="midY",h="height");const p=[],f=s.sort((y,b)=>i[y.id][l]-i[b.id][l])[0],g=s.sort((y,b)=>i[b.id][c]-i[y.id][c])[0],m=i[f.id][u],v=(i[g.id][u]-m)/(o-1),S=m+v;return s.filter(y=>y!==f&&y!==g).sort((y,b)=>i[y.id][u]-i[b.id][u]).forEach((y,b)=>{const P={x:0,y:0};P[a]=S+v*b-i[y.id][h]/2-i[y.id][a];const C=this.getShapeParent(y),I=C?x.Rot(P,-this.getShapePageTransform(C).rotation()):P;p.push(this.getChangesToTranslateShape(y,x.Add(y,I)))}),this.updateShapes(p),this}stretchShapes(e,n){const r=typeof e[0]=="string"?e:e.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(r.length<2)return this;const o=ye(r.map(l=>this.getShape(l))),s=Object.fromEntries(r.map(l=>[l,this.getShapeGeometry(l).bounds])),i=Object.fromEntries(r.map(l=>[l,this.getShapePageBounds(l)])),a=Z.Common(ye(Object.values(i)));switch(n){case"vertical":{this.run(()=>{for(const l of o){if(this.getShapePageTransform(l).rotation()%Fe)continue;const u=s[l.id],h=i[l.id],p=new x(0,a.minY-h.minY),f=this.getShapeParentTransform(l);f&&p.rot(-f.rotation());const{x:g,y:m}=x.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:m}]);const v=new x(1,a.height/h.height);this.resizeShape(l.id,v,{initialBounds:u,scaleOrigin:new x(h.center.x,a.minY),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}case"horizontal":{this.run(()=>{for(const l of o){const c=s[l.id],u=i[l.id];if(this.getShapePageTransform(l).rotation()%Fe)continue;const p=new x(a.minX-u.minX,0),f=this.getShapeParentTransform(l);f&&p.rot(-f.rotation());const{x:g,y:m}=x.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:m}]);const v=new x(a.width/u.width,1);this.resizeShape(l.id,v,{initialBounds:c,scaleOrigin:new x(a.minX,u.center.y),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}}return this}resizeShape(e,n,r={}){var f,g,m;const o=typeof e=="string"?e:e.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(n.x)||(n=new x(1,n.y)),Number.isFinite(n.y)||(n=new x(n.x,1));const s=r.initialShape??this.getShape(o);if(!s)return this;const i=r.scaleOrigin??((f=this.getShapePageBounds(o))==null?void 0:f.center);if(!i)return this;const a=r.initialPageTransform?q.Cast(r.initialPageTransform):this.getShapePageTransform(o);if(!a)return this;const l=a.rotation();if(l==null)return this;const c=r.scaleAxisRotation??l,u=r.initialBounds??this.getShapeGeometry(o).bounds;if(!u)return this;const h=r.isAspectRatioLocked??this.getShapeUtil(s).isAspectRatioLocked(s);if(!kA(l,c))return this._resizeUnalignedShape(o,n,{...r,initialBounds:u,scaleOrigin:i,scaleAxisRotation:c,initialPageTransform:a,isAspectRatioLocked:h,initialShape:s});const p=this.getShapeUtil(s);if(h&&(Math.abs(n.x)>Math.abs(n.y)?n=new x(n.x,Math.sign(n.y)*Math.abs(n.x)):n=new x(Math.sign(n.x)*Math.abs(n.y),n.y)),p.onResize&&p.canResize(s)){const v=this._scalePagePoint(q.applyToPoint(a,new x(0,0)),i,n,c),S=this.getPointInParentSpace(s.id,v),y=new x(n.x,n.y),b=ti((l-c)%Math.PI,0);y.x=b?n.x:n.y,y.y=b?n.y:n.x;const P=q.applyToPoint(a,new x),{x:C,y:I}=this.getPointInParentSpace(s.id,P);let T=s;r.skipStartAndEndCallbacks||(T=po(s,((g=p.onResizeStart)==null?void 0:g.call(p,s))??void 0)),T=po(T,{id:o,type:s.type,x:S.x,y:S.y,...p.onResize({...s,x:C,y:I},{newPoint:S,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:y.x,scaleY:y.y,initialBounds:u,initialShape:s})}),r.skipStartAndEndCallbacks||(T=po(T,((m=p.onResizeEnd)==null?void 0:m.call(p,s,T))??void 0)),this.updateShapes([T])}else{const v=q.applyToPoint(a,u.center),S=this._scalePagePoint(v,i,n,c),y=this.getPointInParentSpace(s.id,v),b=this.getPointInParentSpace(s.id,S),P=x.Sub(b,y);this.updateShapes([{id:o,type:s.type,x:s.x+P.x,y:s.y+P.y}])}return this}_scalePagePoint(e,n,r,o){const s=x.RotWith(e,n,-o).sub(n),i=x.MulV(s,r);return x.Add(i,n).rotWith(n,o)}_resizeUnalignedShape(e,n,r){const{type:o}=r.initialShape,s=new x(n.x,n.y);if(Math.abs(n.x)>Math.abs(n.y)?s.x=Math.sign(n.x)*Math.abs(n.y):s.y=Math.sign(n.y)*Math.abs(n.x),this.resizeShape(e,s,{initialShape:r.initialShape,initialBounds:r.initialBounds,isAspectRatioLocked:r.isAspectRatioLocked}),Math.sign(n.x)*Math.sign(n.y)<0){let{rotation:v}=q.Decompose(r.initialPageTransform);v-=2*v,this.updateShapes([{id:e,type:o,rotation:v}])}const i=q.applyToPoint(r.initialPageTransform,r.initialBounds.center),a=this._scalePagePoint(i,r.scaleOrigin,n,r.scaleAxisRotation),l=this.getShapePageBounds(e),c=this.getShapePageTransform(e),u=l.center,h=c.point();if(!u||!h)return this;const p=x.Sub(a,u),f=x.Add(h,p),{x:g,y:m}=this.getPointInParentSpace(e,f);return this.updateShapes([{id:e,type:o,x:g,y:m}]),this}getInitialMetaForShape(e){return{}}createShape(e){return this.createShapes([e]),this}createShapes(e){if(!Array.isArray(e))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");if(this.getInstanceState().isReadonly)return this;if(e.length<=0)return this;const n=this.getCurrentPageShapeIds();if(e.length+n.size>this.options.maxShapesPerPage)return uh(this),this;const o=this.getFocusedGroupId();return this.run(()=>{var u,h;const s=this.getCurrentPageShapesSorted(),i=e.map(p=>{if(p.id||(p={id:Ne(),...p}),!p.parentId||!(this.store.has(p.parentId)||e.some(f=>f.id===p.parentId))){let f=this.getFocusedGroupId();for(let m=s.length-1;m>=0;m--){const v=s[m];if(!this.isShapeHidden(v)&&this.getShapeUtil(v).canReceiveNewChildrenOfType(v,p.type)&&this.isPointInShape(v,{x:p.x??0,y:p.y??0},{margin:0,hitInside:!0})){f=v.id;break}}const g=p.parentId;if(f===p.id&&(f=o),f!==g&&(p={...p},p.parentId=f,Rn(f))){const m=this.getPointInShapeSpace(this.getShape(f),{x:p.x??0,y:p.y??0});p.x=m.x,p.y=m.y,p.rotation=-this.getShapePageTransform(f).rotation()+(p.rotation??0)}}return p}),a=new Map,l=[],{opacityForNextShape:c}=this.getInstanceState();for(const p of i){const f=this.getShapeUtil(p);let g=p.index;if(!g){const y=p.parentId??o;a.has(y)||a.set(y,this.getHighestIndexForParent(y)),g=a.get(y),a.set(y,vo(g))}const m=f.getDefaultProps();for(const[y,b]of this.styleProps[p.type])m[b]=this.getStyleForNextShape(y);let v=this.store.schema.types.shape.create({...p,index:g,opacity:p.opacity??c,parentId:p.parentId??o,props:"props"in p?{...m,...p.props}:m});if(v.index===void 0)throw Error("no index!");const S=(h=(u=this.getShapeUtil(v)).onBeforeCreate)==null?void 0:h.call(u,v);S&&(v=S),l.push(v)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)}),this}animateShape(e,n={animation:Ay}){return this.animateShapes([e],n)}animateShapes(e,n={animation:Ay}){if(!n.animation)return this;const{duration:r=500,easing:o=At.linear}=n.animation,s=Ke();let i=r,a;const l=[];let c,u;for(let p=0,f=e.length;p<f;p++){if(c=e[p],!c)continue;const g=this.getShape(c.id);g&&(u={start:tt(g),end:po(tt(g),c)},l.push(u),this.animatingShapes.set(g.id,s))}const h=p=>{var v,S;if(i-=p,i<0){const{animatingShapes:y}=this,b=e.filter(P=>P&&y.get(P.id)===s);b.length&&this.updateShapes(b),this.off("tick",h);return}a=o(1-i/r);const{animatingShapes:f}=this,g=[];let m;for(let y=0,b=l.length;y<b;y++){const{start:P,end:C}=l[y];m=f.get(P.id),m===s&&g.push({...C,x:P.x+(C.x-P.x)*a,y:P.y+(C.y-P.y)*a,opacity:P.opacity+(C.opacity-P.opacity)*a,rotation:P.rotation+(C.rotation-P.rotation)*a,props:((S=(v=this.getShapeUtil(C)).getInterpolatedProps)==null?void 0:S.call(v,P,C,a))??C.props})}this._updateShapes(g)};return this.on("tick",h),this}groupShapes(e,n={}){var g;const{groupId:r=Ne(),select:o=!0}=n;if(!Array.isArray(e))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const s=typeof e[0]=="string"?e:e.map(m=>m.id);if(s.length<=1)return this;const i=ye((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(m=>this.getShape(m))),a=i.sort(ln).map(m=>m.id),l=Z.Common(ye(i.map(m=>this.getShapePageBounds(m)))),{x:c,y:u}=l.point,h=this.findCommonAncestor(i)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const p=i.filter(m=>m.parentId===h).sort(ln),f=(g=p[p.length-1])==null?void 0:g.index;return this.run(()=>{this.createShapes([{id:r,type:"group",parentId:h,index:f,x:c,y:u,opacity:1,props:{}}]),this.reparentShapes(a,r),o&&this.select(r)}),this}ungroupShapes(e,n={}){if(this.getInstanceState().isReadonly)return this;const{select:r=!0}=n,o=typeof e[0]=="string"?e:e.map(l=>l.id),s=ye((this._shouldIgnoreShapeLock?o:this._getUnlockedShapeIds(o)).map(l=>this.getShape(l)));if(s.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const i=new Set,a=[];return s.forEach(l=>{this.isShapeOfType(l,"group")?a.push(l):i.add(l.id)}),a.length===0?this:(this.run(()=>{let l;for(let c=0,u=a.length;c<u;c++){l=a[c];const h=this.getSortedChildIdsForParent(l.id);for(let p=0,f=h.length;p<f;p++)i.add(h[p]);this.reparentShapes(h,l.parentId,l.index)}this.deleteShapes(a.map(c=>c.id)),r&&this.select(...i)}),this)}updateShape(e){return this.updateShapes([e]),this}updateShapes(e){const n=Array(e.length);for(let r=0,o=e.length;r<o;r++){const s=e[r];if(!s)continue;const i=this.getShape(s.id);if(i){if(!this._shouldIgnoreShapeLock){if(i.isLocked){if(!(Object.hasOwn(s,"isLocked")&&!s.isLocked))continue}else if(this.isShapeOrAncestorLocked(i))continue}this.animatingShapes.delete(s.id),n.push(s)}}return this._updateShapes(n),this}_updateShapes(e){this.getInstanceState().isReadonly||this.run(()=>{var s,i;const n=[];let r,o;for(let a=0,l=e.length;a<l;a++){const c=e[a];c&&(r=this.getShape(c.id),r&&(o=po(r,c),o!==r&&(o=((i=(s=this.getShapeUtil(r)).onBeforeUpdate)==null?void 0:i.call(s,r,o))??o,n.push(o))))}this.store.put(n)})}_getUnlockedShapeIds(e){return e.filter(n=>{var r;return!((r=this.getShape(n))!=null&&r.isLocked)})}deleteShapes(e){if(this.getInstanceState().isReadonly)return this;if(!Array.isArray(e))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");const n=typeof e[0]=="string"?e:e.map(s=>s.id),r=this._shouldIgnoreShapeLock?n:this._getUnlockedShapeIds(n);if(r.length===0)return this;const o=new Set(r);for(const s of r)this.visitDescendants(s,i=>{o.add(i)});return this.run(()=>this.store.remove([...o]))}deleteShape(e){return this.deleteShapes([typeof e=="string"?e:e.id]),this}_extractSharedStyles(e,n){if(this.isShapeOfType(e,"group")){const r=this._parentIdsToChildIds.get()[e.id];if(!r)return;for(let o=0,s=r.length;o<s;o++)this._extractSharedStyles(this.getShape(r[o]),n)}else for(const[r,o]of this.styleProps[e.type])n.applyValue(r,zn(e.props,o))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),n=new mx;for(const r of e)this._extractSharedStyles(r,n);return n}getStyleForNextShape(e){const n=this.getInstanceState().stylesForNextShape[e.id];return n===void 0?e.defaultValue:n}getShapeStyleIfExists(e,n){const r=this.styleProps[e.type].get(n);if(r!==void 0)return zn(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),n=new mx;if(!e)return n;if(e.shapeType)for(const r of this.styleProps[e.shapeType].keys())n.applyValue(r,this.getStyleForNextShape(r));return n}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const e=[],n=o=>{const s=this.getShape(o);if(s)if(this.isShapeOfType(s,"group"))for(const i of this.getSortedChildIdsForParent(s.id))n(i);else e.push(s)};for(const o of this.getSelectedShapeIds())n(o);let r=null;for(const o of e)if(r===null)r=o.opacity;else if(r!==o.opacity)return{type:"mixed"};if(r!==null)return{type:"shared",value:r}}return{type:"shared",value:this.getInstanceState().opacityForNextShape}}setOpacityForNextShapes(e,n){return this.updateInstanceState({opacityForNextShape:e},n),this}setOpacityForSelectedShapes(e){const n=this.getSelectedShapes();if(n.length>0){const r=[],o=s=>{if(this.isShapeOfType(s,"group")){const i=this.getSortedChildIdsForParent(s);for(const a of i)o(this.getShape(a))}else r.push(s)};for(const s of n)o(s);this.updateShapes(r.map(s=>({id:s.id,type:s.type,opacity:e})))}return this}setStyleForNextShapes(e,n,r){const o=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...o,[e.id]:n}},r),this}setStyleForSelectedShapes(e,n){const r=this.getSelectedShapes();if(r.length>0){const o=[],s=i=>{if(this.isShapeOfType(i,"group")){const a=this.getSortedChildIdsForParent(i.id);for(const l of a)s(this.getShape(l))}else{const a=this.getShapeUtil(i),l=this.styleProps[i.type].get(e);if(l){const c={id:i.id,type:i.type,props:{[l]:n}};o.push({util:a,originalShape:i,updatePartial:c})}}};for(const i of r)s(i);this.updateShapes(o.map(({updatePartial:i})=>i))}return this}registerExternalAssetHandler(e,n){return this.externalAssetContentHandlers[e]=n,this}createTemporaryAssetPreview(e,n){if(this.temporaryAssetPreview.has(e))return this.temporaryAssetPreview.get(e);const r=URL.createObjectURL(n);return this.temporaryAssetPreview.set(e,r),setTimeout(()=>{this.temporaryAssetPreview.delete(e),URL.revokeObjectURL(r)},this.options.temporaryAssetPreviewLifetimeMs),r}getTemporaryAssetPreview(e){return this.temporaryAssetPreview.get(e)}async getAssetForExternalContent(e){var n,r;return await((r=(n=this.externalAssetContentHandlers)[e.type])==null?void 0:r.call(n,e))}hasExternalAssetHandler(e){return!!this.externalAssetContentHandlers[e]}registerExternalContentHandler(e,n){return this.externalContentHandlers[e]=n,this}async putExternalContent(e){var n,r;return(r=(n=this.externalContentHandlers)[e.type])==null?void 0:r.call(n,e)}getContentFromCurrentPage(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id);if(!n||n.length===0)return;const r=this.getShapeAndDescendantIds(n);return hI(this,r,o=>{const s=[];for(const u of o){const h=this.getBinding(u);h&&s.push(h)}const i=[],a=[];for(const u of r){const h=this.getShape(u);if(!h)continue;if(!r.has(h.parentId)){const f=this.getShapePageTransform(h.id),g=f.point();a.push({...h,x:g.x,y:g.y,rotation:f.rotation(),parentId:this.getCurrentPageId()}),i.push(h.id)}else a.push(h)}const l=[],c=new Set;for(const u of a){if(!("assetId"in u.props))continue;const h=u.props.assetId;if(!h||c.has(h))continue;c.add(h);const p=this.getAsset(h);p&&l.push(p)}return{schema:this.store.schema.serialize(),shapes:a,rootShapeIds:i,bindings:s,assets:l}})}async resolveAssetsInContent(e){if(!e)return;const n=[];return await Promise.allSettled(e.assets.map(async r=>{var o,s;if((r.type==="image"||r.type==="video")&&!((o=r.props.src)!=null&&o.startsWith("data:image"))&&!((s=r.props.src)!=null&&s.startsWith("http"))){const i=tt(r),a=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});i.props.src=await rs.blobToDataUrl(await Jr(a).then(l=>l.blob())),n.push(i)}else n.push(r)})),e.assets=n,e}putContentOntoCurrentPage(e,n={}){var M,R;if(this.getInstanceState().isReadonly)return this;if(!e.schema)throw Error(`Could not put content:
106
- content is missing a schema.`);const{select:r=!1,preserveIds:o=!1,preservePosition:s=!1}=n;let{point:i=void 0}=n;const a=this.getCurrentPageId(),{rootShapeIds:l}=e,c=[],u=[],h=[],p={store:{...Object.fromEntries(e.assets.map(j=>[j.id,j])),...Object.fromEntries(e.shapes.map(j=>[j.id,j])),...Object.fromEntries(((M=e.bindings)==null?void 0:M.map(j=>[j.id,j]))??[])},schema:e.schema},f=this.store.schema.migrateStoreSnapshot(p);if(f.type==="error")throw Error("Could not put content: could not migrate content");for(const j of Object.values(f.value))switch(j.typeName){case"asset":{c.push(j);break}case"shape":{u.push(j);break}case"binding":{h.push(j);break}}const g=new Map(o?u.map(j=>[j.id,j.id]):u.map(j=>[j.id,Ne()])),m=new Map(o?h.map(j=>[j.id,j.id]):h.map(j=>[j.id,Wi()]));let v=this.getCurrentPageId(),S=1/0,y=[];for(const j of this.getSelectedShapes()){if(S===0)break;const O=this.isShapeOfType(j,"frame"),D=this.getShapeAncestors(j);O&&D.push(j);const B=O?D.length+1:D.length;if(B<S)S=B,y=D,v=O?j.id:j.parentId;else if(B===S){if(y.length!==D.length)throw Error(`Ancestors: ${y.length} !== ${D.length}`);if(y.length===0){v=a;break}else{v=a;for(let z=0;z<y.length&&D[z]===y[z];z++)v=D[z].id}}}let b=!1;if(!jn(v)){const j=this.getShape(v);if(j){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(j)))v=a;else if(l.length===1){const O=u.find(D=>D.id===l[0]);this.isShapeOfType(j,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(j==null?void 0:j.props.w)&&O.props.h===(j==null?void 0:j.props.h)&&(b=!0)}}else v=a}b||(b=g.has(v)),b&&(v=this.getShape(v).parentId);let P=this.getHighestIndexForParent(v);const C=[],I=u.map(j=>{const O=g.get(j.id),D={...j,id:O};return l.includes(j.id)&&(D.parentId=a,C.push(D)),g.has(D.parentId)?D.parentId=g.get(j.parentId):(l.push(D.id),D.index=P,P=vo(P)),D});if(I.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return uh(this),this;const T=h.map(j=>({...j,id:nr(m.get(j.id)),fromId:nr(g.get(j.fromId)),toId:nr(g.get(j.toId))})),_=[],k=[];for(const j of c)this.store.has(j.id)||((j.type==="image"||j.type==="video")&&((R=j.props.src)!=null&&R.startsWith("data:image"))&&(k.push(tt(j)),j.props.src=null),_.push(j));return Promise.allSettled(k.map(async j=>{const O=await nQ(j.props.src,j.props.name,j.props.mimeType??"image/png"),D=await this.getAssetForExternalContent({type:"file",file:O,assetId:j.id});if(!D){this.deleteAssets([j.id]);return}this.updateAssets([{...D,id:j.id}])})),this.run(()=>{_.length>0&&this.createAssets(_),this.createShapes(I),this.createBindings(T),r&&this.select(...C.map(z=>z.id)),v!==a&&this.reparentShapes(C.map(z=>z.id),v);const j=I.map(z=>this.getShape(z.id)),O=Z.Common(j.map(z=>this.getShapePageBounds(z)));if(i===void 0)if(jn(v)){const z=this.getViewportPageBounds();s||z.includes(Z.From(O))?i=O.center:i=z.center}else{const z=this.getShape(v);i=q.applyToPoint(this.getShapePageTransform(z),this.getShapeGeometry(z).bounds.center)}if(C.length===1){const z=C[0];if(this.isShapeOfType(z,"frame"))for(;this.getShapesAtPoint(i).some(K=>this.isShapeOfType(K,"frame")&&K.props.w===z.props.w&&K.props.h===z.props.h);)i.x+=O.w+16}const D=Z.Common(ye(C.map(({id:z})=>this.getShapePageBounds(z)))).center,B=x.Sub(i,D);this.updateShapes(C.map(({id:z})=>{const K=this.getShape(z),N=this.getShapeParentTransform(z).decompose().rotation,H=x.Rot(B,-N);return{id:K.id,type:K.type,x:K.x+H.x,y:K.y+H.y}}))}),this}async getSvgElement(e,n={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id);if(r.length!==0)return QZ(this,r,n)}async getSvgString(e,n={}){const r=await this.getSvgElement(e,n);return r?{svg:new XMLSerializer().serializeToString(r.svg),width:r.width,height:r.height}:void 0}async getSvg(e,n={}){const r=await this.getSvgElement(e,n);if(r)return r.svg}_updateInputsFromEvent(e){const{pointerVelocity:n,previousScreenPoint:r,previousPagePoint:o,currentScreenPoint:s,currentPagePoint:i}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(vn),{x:l,y:c,z:u}=Zd(()=>this.getCamera()),h=e.point.x-a.x,p=e.point.y-a.y,f=e.point.z??.5;r.setTo(s),o.setTo(i),s.set(h,p);const g=h/u-l,m=p/u-c;isFinite(g)&&isFinite(m)&&i.set(g,m,f),this.inputs.isPen=e.type==="pointer"&&e.isPen,(e.name==="pointer_down"||this.inputs.isPinching)&&(n.set(0,0),this.inputs.originScreenPoint.setTo(s),this.inputs.originPagePoint.setTo(i)),this.run(()=>{var v;this.store.put([{id:xf,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===O_.CAMERA_MOVE?((v=this.store.unsafeGetWithoutCapture(xf))==null?void 0:v.lastActivityTimestamp)??this._tickManager.now:this._tickManager.now,meta:{}}])},{history:"ignore"})}cancel(){return this.dispatch({type:"misc",name:"cancel"}),this}interrupt(){return this.dispatch({type:"misc",name:"interrupt"}),this}complete(){return this.dispatch({type:"misc",name:"complete"}),this}focus({focusContainer:e=!0}={}){return this.getIsFocused()?this:(e&&this.focusManager.focus(),this.updateInstanceState({isFocused:!0}),this)}blur({blurContainer:e=!0}={}){return this.getIsFocused()?(e?this.focusManager.blur():this.complete(),this.updateInstanceState({isFocused:!1}),this):this}getIsFocused(){return this.getInstanceState().isFocused}getSnapshot(){return oZ(this.store)}loadSnapshot(e,n){return hj(this.store,e,n),this}_zoomToFitPageContentAt100Percent(){const e=this.getCurrentPageBounds();e&&this.zoomToBounds(e,{immediate:!0,targetZoom:this.getBaseZoom()})}_navigateToDeepLink(e){this.run(()=>{switch(e.type){case"page":{const n=this.getPage(e.pageId);n&&this.setCurrentPage(n),this._zoomToFitPageContentAt100Percent();return}case"shapes":{const n=ye(e.shapeIds.map(i=>this.getShape(i))),r={};for(const i of n){const a=this.getAncestorPageId(i);a&&(r[a]??(r[a]=[]),r[a].push(i))}const[o,s]=Object.entries(r).sort(([i,a],[l,c])=>c.length-a.length)[0]??["",[]];if(!o||!s.length)this._zoomToFitPageContentAt100Percent();else{this.setCurrentPage(o);const i=Z.Common(s.map(a=>this.getShapePageBounds(a)));this.zoomToBounds(i,{immediate:!0,targetZoom:this.getBaseZoom()})}return}case"viewport":{if(e.pageId){if(!this.getPage(e.pageId)){this._zoomToFitPageContentAt100Percent();return}this.setCurrentPage(e.pageId)}this.zoomToBounds(e.bounds,{immediate:!0,inset:0});return}default:Tt(e)}})}navigateToDeepLink(e){if(e&&"type"in e)return this._navigateToDeepLink(e),this;const r=new URL((e==null?void 0:e.url)??window.location.href).searchParams.get((e==null?void 0:e.param)??"d");if(!r)return this._zoomToFitPageContentAt100Percent(),this;try{this._navigateToDeepLink(sQ(r))}catch(o){console.warn(o),this._zoomToFitPageContentAt100Percent()}return this}createDeepLink(e){const n=new URL((e==null?void 0:e.url)??window.location.href);return n.searchParams.set((e==null?void 0:e.param)??"d",oQ((e==null?void 0:e.to)??{type:"viewport",pageId:this.options.maxPages===1?void 0:this.getCurrentPageId(),bounds:this.getViewportPageBounds()})),n}registerDeepLinkListener(e){if(e!=null&&e.getUrl&&!(e!=null&&e.onChange))throw Error("[tldraw:urlStateSync] If you specify getUrl, you must also specify the onChange callback.");const n=G("url with state",()=>{var l,c;const i=((l=e==null?void 0:e.getUrl)==null?void 0:l.call(e,this))??window.location.href;return this.createDeepLink({param:e==null?void 0:e.param,url:i,to:(c=e==null?void 0:e.getTarget)==null?void 0:c.call(e,this)}).toString()}),r=(e==null?void 0:e.onChange)??(()=>{var a;const i=this.createDeepLink({param:e==null?void 0:e.param,to:(a=e==null?void 0:e.getTarget)==null?void 0:a.call(e,this)});window.history.replaceState({},document.title,i.toString())}),o=lw(i=>i(),(e==null?void 0:e.debounceMs)??500),s=ii("update url on state change",()=>r(new URL(n.get()),this),{scheduleEffect:o});return()=>{s(),o.cancel()}}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_setShiftKeyTimeout(){this.inputs.shiftKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Shift",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ShiftLeft"})}_setAltKeyTimeout(){this.inputs.altKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Alt",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"AltLeft"})}_setCtrlKeyTimeout(){this.inputs.ctrlKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Ctrl",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ControlLeft"})}dispatch(e){return this._pendingEventsForNextTick.push(e),e.type==="pointer"&&e.name==="pointer_move"||e.type==="wheel"||e.type==="pinch"||this._flushEventsForTick(0),this}_flushEventsForTick(e){this.run(()=>{if(this._pendingEventsForNextTick.length>0){const n=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const r of n)this._flushEventForTick(r)}e>0&&this.root.handleEvent({type:"misc",name:"tick",elapsed:e}),this.scribbles.tick(e)})}_flushEventForTick(e){if(this.getCrashingError())return this;const{inputs:n}=this,{type:r}=e;if(e.type==="misc"){(e.name==="cancel"||e.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}))),this.root.handleEvent(e);return}e.shiftKey?(clearTimeout(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,n.shiftKey=!0):!e.shiftKey&&n.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),e.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,n.altKey=!0):!e.altKey&&n.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),e.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,n.ctrlKey=!0):!e.ctrlKey&&n.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:o,currentPagePoint:s}=n;n.isPointing||(n.isDragging=!1);const i=this.store.unsafeGetWithoutCapture(vn),a=this.store.get(this._getCurrentPageStateId()),l=this._cameraOptions.__unsafe__getWithoutCapture();switch(r){case"pinch":{if(l.isLocked)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(e),e.name){case"pinch_start":{if(n.isPinching)return;n.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=[...a.selectedShapeIds]),this._didPinch=!0,n.isPinching=!0,this.interrupt());return}case"pinch":{if(!n.isPinching)return;const{point:{z:c=1},delta:{x:u,y:h}}=e,{x:p,y:f}=x.SubXY(e.point,i.screenBounds.x,i.screenBounds.y);this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:g,y:m,z:v}=Zd(()=>this.getCamera()),{panSpeed:S,zoomSpeed:y}=l;this._setCamera(new x(g+u*S/v-p/v+p/(c*y),m+h*S/v-f/v+f/(c*y),c*y),{immediate:!0});return}case"pinch_end":{if(!n.isPinching)return this;n.isPinching=!1;const{_selectedShapeIdsAtPointerDown:c}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,c.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(c)}));return}}}case"wheel":{if(l.isLocked)return;if(this._updateInputsFromEvent(e),!this.getIsMenuOpen()){const{panSpeed:c,zoomSpeed:u,wheelBehavior:h}=l;if(h!=="none"){this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:p,y:f,z:g}=Zd(()=>this.getCamera()),{x:m,y:v,z:S=0}=e.delta;let y=h;switch(n.ctrlKey&&(y=h==="pan"?"zoom":"pan"),y){case"zoom":{const{x:b,y:P}=this.inputs.currentScreenPoint;let C=S;h==="zoom"&&(Math.abs(v)>10?C=10*Math.sign(v)/100:C=v/100);const I=g+(C??0)*u*g;this._setCamera(new x(p+(b/I-b)-(b/g-b),f+(P/I-P)-(P/g-P),I),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new x(p+m*c/g,f+v*c/g,g),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}}break}case"pointer":{if(n.isPinching)return;this._updateInputsFromEvent(e);const{isPen:c}=e,{isPenMode:u}=i;switch(e.name){case"pointer_down":{if(u&&!c)return;if(this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{this.dispatch({...e,point:this.inputs.currentScreenPoint,name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),e.button===D_&&(this.capturedPointerId=e.pointerId),n.buttons.add(e.button),n.isPointing=!0,n.isDragging=!1,!u&&c&&this.updateInstanceState({isPenMode:!0}),e.button===R_?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===oh&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!c&&u)return;const{x:h,y:p,z:f}=Zd(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:g,previousScreenPoint:m}=this.inputs,{panSpeed:v}=l,S=x.Sub(g,m);this.setCamera(new x(h+S.x*v/f,p+S.y*v/f,f),{immediate:!0}),this.maybeTrackPerformance("Panning");return}n.isPointing&&!n.isDragging&&x.Dist2(o,s)*this.getZoomLevel()>(i.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/f&&(n.isDragging=!0,clearTimeout(this._longPressTimeout));break}case"pointer_up":{if(n.isDragging=!1,n.isPointing=!1,clearTimeout(this._longPressTimeout),n.buttons.delete(e.button),this.getIsMenuOpen()||i.isPenMode&&!c)return;if(this.capturedPointerId===e.pointerId&&(this.capturedPointerId=null,e.button=0),n.isPanning){n.keys.has("Space")||(n.isPanning=!1,n.isSpacebarPanning=!1);const h=this.inputs.pointerVelocity,p=Math.min(2,h.len());switch(e.button){case D_:{this.setCursor({type:"grab",rotation:0});break}case oh:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}p>0&&this.slideCamera({speed:p,direction:h})}else e.button===R_&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(e.key==="ShiftRight"&&(e.key="ShiftLeft"),e.key==="AltRight"&&(e.key="AltLeft"),e.code==="ControlRight"&&(e.code="ControlLeft"),e.name){case"key_down":{if(n.keys.add(e.code),e.code==="Space"&&!e.ctrlKey&&(this.inputs.isPanning||(this._prevCursor=i.cursor.type),this.inputs.isPanning=!0,this.inputs.isSpacebarPanning=!0,clearTimeout(this._longPressTimeout),this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0})),this.inputs.isSpacebarPanning){let c;switch(e.code){case"ArrowUp":{c=new x(0,-1);break}case"ArrowRight":{c=new x(1,0);break}case"ArrowDown":{c=new x(0,1);break}case"ArrowLeft":{c=new x(-1,0);break}}if(c){const u=this.getViewportPageBounds(),h=u.clone().translate(c.mulV({x:u.w,y:u.h}));this._animateToViewport(h,{animation:{duration:320}})}}break}case"key_up":{n.keys.delete(e.code),e.code==="Space"&&(this.inputs.buttons.has(oh)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===oh?e.name="middle_click":e.button===Zw&&(e.name="right_click");const{isPenMode:c}=this.store.unsafeGetWithoutCapture(vn);if(e.isPen===c){const u=this._clickManager.handlePointerEvent(e);if(e.name!==u.name){this.root.handleEvent(e),this.emit("event",e),this.root.handleEvent(u),this.emit("event",u);return}}}return this.root.handleEvent(e),this.emit("event",e),e.type==="pointer"&&e.name==="pointer_down"&&this.clearOpenMenus(),this}maybeTrackPerformance(e){xt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(e),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}J=TJ(Sx);te(J,1,"getIsShapeHiddenCache",lR,Q);te(J,1,"getCanUndo",aR,Q);te(J,1,"getCanRedo",iR,Q);te(J,1,"getPath",sR,Q);te(J,1,"getCurrentTool",oR,Q);te(J,1,"getCurrentToolId",rR,Q);te(J,1,"getDocumentSettings",nR,Q);te(J,1,"getInstanceState",tR,Q);te(J,1,"getOpenMenus",eR,Q);te(J,1,"getIsMenuOpen",JD,Q);te(J,1,"getPageStates",QD,Q);te(J,1,"_getPageStatesQuery",ZD,Q);te(J,1,"getCurrentPageState",qD,Q);te(J,1,"_getCurrentPageStateId",XD,Q);te(J,1,"getSelectedShapeIds",YD,Q);te(J,1,"getSelectedShapes",VD,Q);te(J,1,"getOnlySelectedShapeId",GD,Q);te(J,1,"getOnlySelectedShape",WD,Q);te(J,1,"getSelectionPageBounds",KD,Q);te(J,1,"getSelectionRotation",HD,Q);te(J,1,"getSelectionRotatedPageBounds",UD,Q);te(J,1,"getSelectionRotatedScreenBounds",BD,Q);te(J,1,"getFocusedGroupId",zD,Q);te(J,1,"getFocusedGroup",ND,Q);te(J,1,"getEditingShapeId",FD,Q);te(J,1,"getEditingShape",$D,Q);te(J,1,"getHoveredShapeId",LD,Q);te(J,1,"getHoveredShape",RD,Q);te(J,1,"getHintingShapeIds",DD,Q);te(J,1,"getHintingShape",OD,Q);te(J,1,"getErasingShapeIds",jD,Q);te(J,1,"getErasingShapes",AD,Q);te(J,1,"_unsafe_getCameraId",MD,Q);te(J,1,"getCamera",TD,Q);te(J,1,"getViewportPageBoundsForFollowing",kD,Q);te(J,1,"getCameraForFollowing",ED,Q);te(J,1,"getZoomLevel",ID,Q);te(J,1,"getViewportScreenBounds",_D,Q);te(J,1,"getViewportScreenCenter",CD,Q);te(J,1,"getViewportPageBounds",PD,Q);te(J,1,"_getCollaboratorsQuery",bD,Q);te(J,1,"getCollaborators",wD,Q);te(J,1,"getCollaboratorsOnCurrentPage",xD,Q);te(J,1,"getRenderingShapes",vD,Q);te(J,1,"_getAllPagesQuery",SD,Q);te(J,1,"getPages",yD,Q);te(J,1,"getCurrentPageId",mD,Q);te(J,1,"getCurrentPageShapeIdsSorted",gD,Q);te(J,1,"_getAllAssetsQuery",fD,Q);te(J,1,"_getShapeGeometryCache",pD,Q);te(J,1,"_getShapeHandlesCache",hD,Q);te(J,1,"_getShapePageTransformCache",dD,Q);te(J,1,"_getShapePageBoundsCache",uD,Q);te(J,1,"_getShapeClipPathCache",cD,Q);te(J,1,"_getShapeMaskCache",lD,Q);te(J,1,"_getShapeMaskedPageBoundsCache",aD,Q);te(J,1,"_notVisibleShapes",iD,Q);te(J,1,"getCulledShapes",sD,Q);te(J,1,"getCurrentPageBounds",oD,Q);te(J,1,"getCurrentPageShapes",rD,Q);te(J,1,"getCurrentPageShapesSorted",nD,Q);te(J,1,"getCurrentPageRenderingShapesSorted",tD,Q);te(J,1,"_getBindingsIndexCache",eD,Q);te(J,1,"_getSelectionSharedStyles",JO,Q);te(J,1,"getSharedStyles",QO,Q);te(J,1,"getSharedOpacity",ZO,Q);te(J,1,"getIsFocused",qO,Q);te(J,1,"_setShiftKeyTimeout",XO,Q);te(J,1,"_setAltKeyTimeout",YO,Q);te(J,1,"_setCtrlKeyTimeout",VO,Q);AJ(J,Q);function uh(t,e=t.getCurrentPageId()){const n=t.getPage(e).name;t.emit("max-shapes",{name:n,pageId:e,count:t.options.maxShapesPerPage})}function po(t,e){if(!e)return t;let n=null;const r=Object.entries(e);for(let o=0,s=r.length;o<s;o++){const[i,a]=r[o];if(a!==void 0&&!(i==="id"||i==="type"||i==="typeName")&&a!==t[i]){if(n||(n={...t}),i==="props"||i==="meta"){n[i]={...t[i]};for(const[l,c]of Object.entries(a))c!==void 0&&(n[i][l]=c);continue}n[i]=a}}return n||t}function cR(t,e,n){const r=t.getShape(e);if(!r)return;n.push(r);const o=t.getSortedChildIdsForParent(e);for(let s=0,i=o.length;s<i;s++)cR(t,o[s],n)}function hI(t,e,n){let r;if(t.run(()=>{const o=t.store.extractingChanges(()=>{const s=new Set,i=new Set;for(const a of e)if(t.getShape(a))for(const c of t.getBindingsInvolvingShape(a)){const u=e.has(c.fromId),h=e.has(c.toId);if(u&&h){s.add(c.id);continue}(!u||!h)&&i.add(c.id)}t.deleteBindings([...i],{isolateShapes:!0});try{r=Sn.ok(n(s))}catch(a){r=Sn.err(a)}});t.store.applyDiff(tx(o))},{history:"ignore"}),r.ok)return r.value;throw r.error}function pI(t,e){if(!e.constraints)throw Error("Should have constraints here");const{padding:{x:n,y:r}}=e.constraints,o=t.getViewportScreenBounds(),s=Z.From(e.constraints.bounds),i=(o.w-n*2)/s.w,a=(o.h-r*2)/s.h;return{zx:i,zy:a}}function dd(){const t=F(),e=ad();return U("isDarkMode",()=>(e==null?void 0:e.isDarkMode)??t.user.getIsDarkMode(),[e,t])}const fI="<path d='m19.7432 17.0869-4.072 4.068 2.829 2.828-8.473-.013-.013-8.47 2.841 2.842 4.075-4.068 1.414-1.415-2.844-2.842h8.486v8.484l-2.83-2.827z' fill='%23fff'/><path d='m18.6826 16.7334-4.427 4.424 1.828 1.828-5.056-.016-.014-5.054 1.842 1.841 4.428-4.422 2.474-2.475-1.844-1.843h5.073v5.071l-1.83-1.828z' fill='%23000'/>",gI="<path d='m9 17.9907v.005l5.997 5.996.001-3.999h1.999 2.02v4l5.98-6.001-5.98-5.999.001 4.019-2.021.002h-2l.001-4.022zm1.411.003 3.587-3.588-.001 2.587h3.5 2.521v-2.585l3.565 3.586-3.564 3.585-.001-2.585h-2.521l-3.499-.001-.001 2.586z' fill='%23fff'/><path d='m17.4971 18.9932h2.521v2.586l3.565-3.586-3.565-3.585v2.605h-2.521-3.5v-2.607l-3.586 3.587 3.586 3.586v-2.587z' fill='%23000'/>",dh='<path d="M22.4789 9.45728L25.9935 12.9942L22.4789 16.5283V14.1032C18.126 14.1502 14.6071 17.6737 14.5675 22.0283H17.05L13.513 25.543L9.97889 22.0283H12.5674C12.6071 16.5691 17.0214 12.1503 22.4789 12.1031L22.4789 9.45728Z" fill="black"/><path fill-rule="evenodd" clip-rule="evenodd" d="M21.4789 7.03223L27.4035 12.9945L21.4789 18.9521V15.1868C18.4798 15.6549 16.1113 18.0273 15.649 21.0284H19.475L13.5128 26.953L7.55519 21.0284H11.6189C12.1243 15.8155 16.2679 11.6677 21.4789 11.1559L21.4789 7.03223ZM22.4789 12.1031C17.0214 12.1503 12.6071 16.5691 12.5674 22.0284H9.97889L13.513 25.543L17.05 22.0284H14.5675C14.5705 21.6896 14.5947 21.3558 14.6386 21.0284C15.1157 17.4741 17.9266 14.6592 21.4789 14.1761C21.8063 14.1316 22.1401 14.1069 22.4789 14.1032V16.5284L25.9935 12.9942L22.4789 9.45729L22.4789 12.1031Z" fill="white"/>';function Ms(t,e,n,r,o,s=16,i=16){const a=(-n-e)*(De/180),l=Math.sin(a),c=Math.cos(a),u=1*c-1*l,h=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${h}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${e+n} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+t.replaceAll('"',"'")+`</g></svg>") ${s} ${i}, pointer`}const OJ=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],DJ={none:()=>"none","ew-resize":(t,e,n)=>Ms(gI,t,0,e,n),"ns-resize":(t,e,n)=>Ms(gI,t,90,e,n),"nesw-resize":(t,e,n)=>Ms(fI,t,0,e,n),"nwse-resize":(t,e,n)=>Ms(fI,t,90,e,n),"nwse-rotate":(t,e,n)=>Ms(dh,t,0,e,n),"nesw-rotate":(t,e,n)=>Ms(dh,t,90,e,n),"senw-rotate":(t,e,n)=>Ms(dh,t,180,e,n),"swne-rotate":(t,e,n)=>Ms(dh,t,270,e,n)};function Jn(t,e=0,n="black"){return DJ[t](TY(e),!1,n)}function RJ(){const t=F(),e=Lt(),n=dd();ss("useCursor",()=>{const{type:r,rotation:o}=t.getInstanceState().cursor;if(OJ.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",Jn(r,o,n?"white":"black"))},[t,e,n])}function LJ(){const t=F(),e=Lt(),n=dd(),r=U(xt.forceSrgb);Ie.useEffect(()=>{n?(e.setAttribute("data-color-mode","dark"),e.classList.remove("tl-theme__light"),e.classList.add("tl-theme__dark")):(e.setAttribute("data-color-mode","light"),e.classList.remove("tl-theme__dark"),e.classList.add("tl-theme__light")),r?e.classList.add("tl-theme__force-sRGB"):e.classList.remove("tl-theme__force-sRGB")},[t,e,r,n])}function $J(){const[t,e]=w.useState(0);w.useEffect(()=>e(n=>n+1),[])}const FJ=t=>t.props.src,NJ={upload:(t,e)=>rs.blobToDataUrl(e)};function zJ(t){return"schema"in t&&t.schema?t.schema:mY({shapes:"shapeUtils"in t&&t.shapeUtils?mI(yj(t.shapeUtils)):void 0,bindings:"bindingUtils"in t&&t.bindingUtils?mI(fj(t.bindingUtils)):void 0,migrations:"migrations"in t?t.migrations:void 0})}function Ou({initialData:t,defaultName:e="",id:n,assets:r=NJ,onMount:o,collaboration:s,...i}={}){const a=zJ(i),l=new zw({id:n,schema:a,initialData:t,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??FJ},onMount:c=>{Re(c instanceof Q),o==null||o(c)},collaboration:s}});if(i.snapshot){if(t)throw new Error("Cannot provide both initialData and snapshot");hj(l,i.snapshot)}return l}function mI(t){return Object.fromEntries(t.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}const BJ=(t,e)=>e.some(n=>t instanceof n);let yI,SI;function UJ(){return yI||(yI=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function HJ(){return SI||(SI=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const uR=new WeakMap,vx=new WeakMap,dR=new WeakMap,By=new WeakMap,f1=new WeakMap;function KJ(t){const e=new Promise((n,r)=>{const o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{n(is(t.result)),o()},i=()=>{r(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return e.then(n=>{n instanceof IDBCursor&&uR.set(n,t)}).catch(()=>{}),f1.set(e,t),e}function WJ(t){if(vx.has(t))return;const e=new Promise((n,r)=>{const o=()=>{t.removeEventListener("complete",s),t.removeEventListener("error",i),t.removeEventListener("abort",i)},s=()=>{n(),o()},i=()=>{r(t.error||new DOMException("AbortError","AbortError")),o()};t.addEventListener("complete",s),t.addEventListener("error",i),t.addEventListener("abort",i)});vx.set(t,e)}let xx={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return vx.get(t);if(e==="objectStoreNames")return t.objectStoreNames||dR.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return is(t[e])},set(t,e,n){return t[e]=n,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function GJ(t){xx=t(xx)}function VJ(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...n){const r=t.call(Uy(this),e,...n);return dR.set(r,e.sort?e.sort():[e]),is(r)}:HJ().includes(t)?function(...e){return t.apply(Uy(this),e),is(uR.get(this))}:function(...e){return is(t.apply(Uy(this),e))}}function YJ(t){return typeof t=="function"?VJ(t):(t instanceof IDBTransaction&&WJ(t),BJ(t,UJ())?new Proxy(t,xx):t)}function is(t){if(t instanceof IDBRequest)return KJ(t);if(By.has(t))return By.get(t);const e=YJ(t);return e!==t&&(By.set(t,e),f1.set(e,t)),e}const Uy=t=>f1.get(t);function hR(t,e,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(t,e),a=is(i);return r&&i.addEventListener("upgradeneeded",l=>{r(is(i.result),l.oldVersion,l.newVersion,is(i.transaction),l)}),n&&i.addEventListener("blocked",l=>n(l.oldVersion,l.newVersion,l)),a.then(l=>{s&&l.addEventListener("close",()=>s()),o&&l.addEventListener("versionchange",c=>o(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function pR(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);return e&&n.addEventListener("blocked",r=>e(r.oldVersion,r)),is(n).then(()=>{})}const XJ=["get","getKey","getAll","getAllKeys","count"],qJ=["put","add","delete","clear"],Hy=new Map;function vI(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(Hy.get(e))return Hy.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,o=qJ.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(o||XJ.includes(n)))return;const s=async function(i,...a){const l=this.transaction(i,o?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[n](...a),o&&l.done]))[0]};return Hy.set(e,s),s}GJ(t=>({...t,get:(e,n,r)=>vI(e,n)||t.get(e,n,r),has:(e,n)=>!!vI(e,n)||t.has(e,n)}));const ZJ="TLDRAW_DOCUMENT_v2",QJ="TLDRAW_ASSET_STORE_v1",fR="TLDRAW_DB_NAME_INDEX_v2",_e={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function gR(t){const e=ZJ+t;return eee(e),await hR(e,4,{upgrade(n){n.objectStoreNames.contains(_e.Records)||n.createObjectStore(_e.Records),n.objectStoreNames.contains(_e.Schema)||n.createObjectStore(_e.Schema),n.objectStoreNames.contains(_e.SessionState)||n.createObjectStore(_e.SessionState),n.objectStoreNames.contains(_e.Assets)||n.createObjectStore(_e.Assets)}})}async function JJ(t){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(p=>p.name):g1(),n=QJ+t;if(!e.find(p=>p===n))return;const o=await hR(n,1,{upgrade(p){p.objectStoreNames.contains("assets")||p.createObjectStore("assets")}});if(!o.objectStoreNames.contains("assets"))return;const s=o.transaction(["assets"],"readonly"),i=s.objectStore("assets"),a=await i.getAllKeys(),l=await Promise.all(a.map(async p=>[p,await i.get(p)]));await s.done;const c=await gR(t),u=c.transaction([_e.Assets],"readwrite"),h=u.objectStore(_e.Assets);for(const[p,f]of l)h.put(f,p);await u.done,o.close(),c.close(),await pR(n)}const iu=class iu{constructor(e){E(this,"getDbPromise");E(this,"isClosed",!1);E(this,"pendingTransactionSet",new Set);iu.connectedInstances.add(this),this.getDbPromise=(async()=>(await JJ(e),await gR(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(_u)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),iu.connectedInstances.delete(this))}tx(e,n,r){const o=(async()=>{Re(!this.isClosed,"db is closed");const i=(await this.getDb()).transaction(n,e),a=i.done.catch(l=>{if(!this.isClosed)throw l});try{return await r(i)}finally{this.isClosed?i.abort():await a}})();return this.pendingTransactionSet.add(o),o.finally(()=>this.pendingTransactionSet.delete(o)),o}async load({sessionId:e}={}){return await this.tx("readonly",[_e.Records,_e.Schema,_e.SessionState],async n=>{var l,c;const r=n.objectStore(_e.Records),o=n.objectStore(_e.Schema),s=n.objectStore(_e.SessionState);let i=e?(l=await s.get(e))==null?void 0:l.snapshot:null;return i||(i=(c=(await s.getAll()).sort((h,p)=>h.updatedAt-p.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await o.get(_e.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:n,sessionId:r,sessionStateSnapshot:o}){await this.tx("readwrite",[_e.Records,_e.Schema,_e.SessionState],async s=>{const i=s.objectStore(_e.Records),a=s.objectStore(_e.Schema),l=s.objectStore(_e.SessionState);for(const[c,u]of Object.entries(n.added))await i.put(u,c);for(const[c,u]of Object.values(n.updated))await i.put(u,u.id);for(const c of Object.keys(n.removed))await i.delete(c);a.put(e.serialize(),_e.Schema),o&&r?l.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:e,snapshot:n,sessionId:r,sessionStateSnapshot:o}){await this.tx("readwrite",[_e.Records,_e.Schema,_e.SessionState],async s=>{const i=s.objectStore(_e.Records),a=s.objectStore(_e.Schema),l=s.objectStore(_e.SessionState);await i.clear();for(const[c,u]of Object.entries(n))await i.put(u,c);a.put(e.serialize(),_e.Schema),o&&r?l.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[_e.SessionState],async e=>{const n=e.objectStore(_e.SessionState),r=(await n.getAll()).sort((s,i)=>s.updatedAt-i.updatedAt);if(r.length<10){await e.done;return}const o=r.slice(0,r.length-10);for(const{id:s}of o)await n.delete(s)})}async getAsset(e){return await this.tx("readonly",[_e.Assets],async n=>await n.objectStore(_e.Assets).get(e))}async storeAsset(e,n){await this.tx("readwrite",[_e.Assets],async r=>{await r.objectStore(_e.Assets).put(n,e)})}};E(iu,"connectedInstances",new Set);let kf=iu;function g1(){const t=JSON.parse(fw(fR)||"[]")??[];return Array.isArray(t)?t:[]}function eee(t){const e=new Set(g1());e.add(t),gw(fR,JSON.stringify([...e]))}function tee(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
107
-
108
- Keep seeing this message?
109
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
110
- • If your hard disk is full, try clearing up some space and then reload the page.`)}function nee(){window.alert(`Oops! We could not access your browser's storage—and the app won't work correctly without that. We now need to reload the page and try again.
111
-
112
- Keep seeing this message?
113
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const ree=350,oee=1e4,xI=Symbol("UPDATE_INSTANCE_STATE"),see=t=>t;class iee{constructor(e){E(this,"onmessage")}postMessage(e){}close(){}}const aee=typeof BroadcastChannel>"u"?iee:BroadcastChannel;class lee{constructor(e,{persistenceKey:n,sessionId:r=Ef,onLoad:o,onLoadError:s},i=new aee(`tldraw-tab-sync-${n}`)){E(this,"disposables",new Set);E(this,"diffQueue",[]);E(this,"didDispose",!1);E(this,"shouldDoFullDBWrite",!0);E(this,"isReloading",!1);E(this,"persistenceKey");E(this,"sessionId");E(this,"serializedSchema");E(this,"isDebugging",!1);E(this,"documentTypes");E(this,"$sessionStateSnapshot");E(this,"db");E(this,"initTime",Date.now());E(this,"isPersisting",!1);E(this,"didLastWriteError",!1);E(this,"scheduledPersistTimeout",null);this.store=e,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=n,this.sessionId=r,this.db=new kf(n),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=n1(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(see({type:"diff",storeId:this.store.id,changes:a,schema:this.serializedSchema})),this.schedulePersist()},{source:"user",scope:"document"})),this.disposables.add(e.listen(()=>{this.diffQueue.push(xI),this.schedulePersist()},{scope:"session"})),this.connect(o,s),this.documentTypes=new Set(Object.values(this.store.schema.types).filter(a=>a.scope==="document").map(a=>a.typeName))}debug(...e){this.isDebugging&&console.debug(...e)}async connect(e,n){this.debug("connecting");let r;try{r=await this.db.load({sessionId:this.sessionId})}catch(o){n(o),nee();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const o=Object.fromEntries(r.records.map(a=>[a.id,a])),s=r.sessionStateSnapshot??rZ(o),i=this.store.schema.migrateStoreSnapshot({store:o,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(i.type==="error"){console.error("failed to migrate store",i),n(new Error(`Failed to migrate store: ${i.reason}`));return}this.store.mergeRemoteChanges(()=>{this.store.put(Object.values(i.value).filter(a=>this.documentTypes.has(a.typeName)),"initialize")}),s&&hx(this.store,s)}this.channel.onmessage=({data:o})=>{var a,l;this.debug("got message",o);const s=o,i=this.store.schema.getMigrationsSince(s.schema);if(i.ok){if(i.value.length>0){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}}else{if(Date.now()-this.initTime<5e3){n(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(l=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||l.call(a);return}s.type==="diff"&&(this.debug("applying diff"),_o(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(s.changes),this.store.ensureStoreIsUsable()})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),e(this)}catch(o){if(this.debug("error loading data from store",o),this.didDispose)return;n(o);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(e=>e())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?oee:ree))}persistIfNeeded(){this.debug("persistIfNeeded",{isPersisting:this.isPersisting,isReloading:this.isReloading,shouldDoFullDBWrite:this.shouldDoFullDBWrite,diffQueueLength:this.diffQueue.length,storeIsPossiblyCorrupt:this.store.isPossiblyCorrupted()}),this.scheduledPersistTimeout&&(clearTimeout(this.scheduledPersistTimeout),this.scheduledPersistTimeout=null),!this.isPersisting&&(this.isReloading||this.store.isPossiblyCorrupted()||(this.shouldDoFullDBWrite||this.diffQueue.length>0)&&this.doPersist())}async doPersist(){if(Re(!this.isPersisting,"persist already in progress"),this.didDispose)return;this.isPersisting=!0,this.debug("doPersist start");const e=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await this.db.storeSnapshot({schema:this.store.schema,snapshot:this.store.serialize(),sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const n=$w(e.filter(r=>r!==xI));await this.db.storeChanges({changes:n,schema:this.store.schema,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()})}this.didLastWriteError=!1}catch(n){this.shouldDoFullDBWrite=!0,this.didLastWriteError=!0,console.error("failed to store changes in indexed db",n),tee(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function mR(t){const e=w.useRef(t),[n,r]=w.useState(t);n!==e.current&&r(e.current);const o=w.useCallback(s=>{typeof s=="function"?e.current=s(e.current):e.current=s,r(e.current)},[]);return[n,o]}function cee(t){const[e,n]=mR({status:"loading"});return t=sd(t),w.useEffect(()=>{const{persistenceKey:r,sessionId:o,...s}=t;if(!r){n({status:"not-synced",store:Ou(s)});return}n({status:"loading"});const i=new Eo,a={upload:async(h,p)=>(await u.db.storeAsset(h.id,p),h.id),resolve:async h=>h.props.src?h.props.src.startsWith("asset:")?await i.get(h,async()=>{const p=await u.db.getAsset(h.id);return p?URL.createObjectURL(p):null}):h.props.src:null,...s.assets},l=Ou({...s,assets:a});let c=!1;const u=new lee(l,{sessionId:o,persistenceKey:r,onLoad(){c||n({store:l,status:"synced-local"})},onLoadError(h){c||n({status:"error",error:h})}});return()=>{c=!0,u.close()}},[t,n]),e}function uee(){const t=F(),e=Lt();w.useEffect(()=>{const n=s=>e.style.setProperty("--tl-zoom",s.toString()),r=lw(n,100),o=new Hl("useZoomCss",()=>{t.getCurrentPageShapeIds().size<300?n(t.getZoomLevel()):r(t.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[t,e])}function wx(t){const e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let r=0,o=t.length;r<o;r++)n[r]=t.charCodeAt(r);return e}function dee(t){const e=atob(t),n=wx(e);return crypto.subtle.importKey("spki",new Uint8Array(n),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const hee=5,$c={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},pee=Math.max(...Object.values($c)),Fc={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},fee=Object.keys(Fc).length,Ky="sales@tldraw.com",gee=`${Gs()}/watermarks/watermark-track.svg`;class Ng{constructor(e,n,r){E(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");E(this,"isDevelopment");E(this,"isTest");E(this,"isCryptoAvailable");E(this,"state",Mt("license state","pending"));E(this,"verbose",!0);this.isTest=!1,this.isDevelopment=this.getIsDevelopment(r),this.publicKey=n||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,this.getLicenseFromKey(e).then(o=>{const s=mee(o);!this.isDevelopment&&s&&Jr(gee),s?this.state.set("unlicensed"):o.isLicensedWithWatermark?this.state.set("licensed-with-watermark"):this.state.set("licensed")})}getIsDevelopment(e){return e==="development"?!0:e==="production"?!1:window.location.protocol!=="https:"}async extractLicenseKey(e){const[n,r]=e.split("."),[o,s]=n.split("/");if(!o.startsWith("tldraw-"))throw new Error(`Unsupported prefix '${o}'`);const i=await dee(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(wx(atob(r))),new Uint8Array(wx(atob(s))))}catch(c){throw console.error(c),new Error("Could not perform signature validation")}if(!a)throw new Error("Invalid signature");let l;try{l=JSON.parse(atob(s))}catch{throw new Error("Could not parse object")}return l.length>fee&&this.outputMessages(["License key contains some unknown properties.","You may want to update tldraw packages to a newer version to get access to new functionality."]),{id:l[Fc.ID],hosts:l[Fc.HOSTS],flags:l[Fc.FLAGS],expiryDate:l[Fc.EXPIRY_DATE]}}async getLicenseFromKey(e){if(!e)return this.isDevelopment||this.outputNoLicenseKeyProvided(),{isLicenseParseable:!1,reason:"no-key-provided"};if(this.isDevelopment&&!this.isCryptoAvailable)return this.verbose&&(console.log("tldraw: you seem to be in a development environment that does not support crypto. License not verified."),console.log("You should check that this works in production separately.")),{isLicenseParseable:!1,reason:"has-key-development-mode"};let n=e.replace(/[\u200B-\u200D\uFEFF]/g,"");n=n.replace(/\r?\n|\r/g,"");try{const r=await this.extractLicenseKey(n),o=new Date(r.expiryDate),s=this.isFlagEnabled(r.flags,$c.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,$c.PERPETUAL_LICENSE),a={license:r,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(r),expiryDate:o,isAnnualLicense:s,isAnnualLicenseExpired:s&&this.isAnnualLicenseExpired(o),isPerpetualLicense:i,isPerpetualLicenseExpired:i&&this.isPerpetualLicenseExpired(o),isInternalLicense:this.isFlagEnabled(r.flags,$c.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,$c.WITH_WATERMARK)};return this.outputLicenseInfoIfNeeded(a),a}catch(r){return this.outputInvalidLicenseKey(r.message),{isLicenseParseable:!1,reason:"invalid-license-key"}}}isDomainValid(e){const n=window.location.hostname.toLowerCase();return e.hosts.some(r=>{const o=r.toLowerCase().trim();if(o===n||`www.${o}`===n||o===`www.${n}`||r==="*")return!0;if(r.includes("*")){const s=new RegExp(r.replace(/\*/g,".*?"));return s.test(n)||s.test(`www.${n}`)}return!1})}getExpirationDateWithoutGracePeriod(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}getExpirationDateWithGracePeriod(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+hee+1)}isAnnualLicenseExpired(e){const n=this.getExpirationDateWithGracePeriod(e),r=new Date>=n;return!r&&new Date>=this.getExpirationDateWithoutGracePeriod(e)&&this.outputMessages(["tldraw license is about to expire, you are in a grace period.",`Please reach out to ${Ky} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const n=this.getExpirationDateWithGracePeriod(e),r={major:new Date(T_.major),minor:new Date(T_.minor)};return r.major>=n||r.minor>=n}isFlagEnabled(e,n){return(e&n)===n}outputNoLicenseKeyProvided(){}outputInvalidLicenseKey(e){this.outputMessages(["Invalid tldraw license key",`Reason: ${e}`])}outputLicenseInfoIfNeeded(e){e.isAnnualLicenseExpired&&this.outputMessages(["Your tldraw license has expired!",`Please reach out to ${Ky} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${Ky} if you would like to use tldraw on other domains.`]),e.license.flags>=pee*2&&this.outputMessages(["This tldraw license contains some unknown flags.","You may want to update tldraw packages to a newer version to get access to new functionality."])}outputMessages(e){if(!this.isTest&&this.verbose){this.outputDelimiter();for(const n of e)console.log(`%c${n}`,"color: white; background: crimson; padding: 2px; border-radius: 3px;");this.outputDelimiter()}}outputDelimiter(){console.log("%c-------------------------------------------------------------------","color: white; background: crimson; padding: 2px; border-radius: 3px;")}}E(Ng,"className","tl-watermark_SEE-LICENSE");function mee(t){if(!t.isLicenseParseable||!t.isDomainValid&&!t.isDevelopment)return!0;if(t.isPerpetualLicenseExpired||t.isAnnualLicenseExpired){if(t.isInternalLicense)throw new Error("License: Internal license expired.");return!0}return!1}const yR=w.createContext({}),yee=()=>w.useContext(yR);function See({licenseKey:t,children:e}){const[n]=w.useState(()=>new Ng(t));return d.jsx(yR.Provider,{value:n,children:e})}const vee='<svg xmlns="http://www.w3.org/2000/svg" width="3001" height="1000" fill="none"><path fill="#000" d="M590.656 300.449c0 49.706-40.294 90-90 90-49.705 0-90-40.294-90-90 0-49.705 40.295-90 90-90 49.706 0 90 40.295 90 90M569.431 719.011c-15.247 32.821-56.006 91.589-98.338 91.438-32.004-.115-38.642-30.904-17.414-50.856 17.381-16.337 28.246-48.075 31.995-72.719.415-2.728-1.556-5.197-4.272-5.679-39.666-7.04-70.746-40.877-70.746-83.417 0-48.23 38.983-87.329 87.07-87.329 39.936 0 70.172 22.237 83.369 52.397 18.839 43.055 7.117 115.733-11.664 156.165M2613.29 385.681V239.319c0-11.363 9.22-20.569 20.59-20.569h8.26c11.37 0 20.59 9.206 20.59 20.569v36.911c0 8.629 7 15.625 15.63 15.625h35.25c8.63 0 15.63-6.996 15.63-15.625v-36.911c0-11.363 9.22-20.569 20.59-20.569h8.17c11.37 0 20.59 9.206 20.59 20.569v146.362c0 11.363-9.22 20.569-20.59 20.569h-8.17c-11.37 0-20.59-9.206-20.59-20.569v-36.999c0-8.63-7-15.625-15.63-15.625h-35.25c-8.63 0-15.63 6.995-15.63 15.625v36.999c0 11.363-9.22 20.569-20.59 20.569h-8.26c-11.37 0-20.59-9.206-20.59-20.569M2391.97 239.319v146.362c0 11.348-9.16 20.569-20.49 20.569h-8.2c-11.33 0-20.49-9.221-20.49-20.569V239.319c0-11.348 9.16-20.569 20.49-20.569h8.2c11.33 0 20.49 9.221 20.49 20.569M2098.23 391.43l-42.69-146.361c-3.85-13.171 6.06-26.319 19.79-26.319h10.6c9.59 0 17.93 6.611 20.08 15.952l17.01 73.045c1.48 6.348 10.47 6.478 12.14.176l19.47-73.838c2.38-9.04 10.57-15.335 19.93-15.335h12.1c9.37 0 17.56 6.3 19.94 15.346l19.49 74.067c1.66 6.305 10.65 6.178 12.13-.171l17.09-73.294c2.15-9.339 10.49-15.948 20.08-15.948h10.53c13.72 0 23.63 13.141 19.79 26.31l-42.63 146.361c-2.56 8.789-10.63 14.829-19.79 14.829h-15.68c-9.12 0-17.16-5.98-19.76-14.709l-21.17-71.059c-1.77-5.948-10.19-5.957-11.97-.012l-21.33 71.071c-2.6 8.729-10.64 14.709-19.76 14.709h-15.59c-9.17 0-17.23-6.035-19.8-14.82M2443.23 218.75h118.59c11.38 0 20.62 9.195 20.62 20.557s-9.24 20.556-20.62 20.556h-24.79c-5.53 0-10 4.477-10 10v115.818c0 11.368-9.25 20.569-20.63 20.569h-7.65c-11.39 0-20.63-9.201-20.63-20.569V269.863c0-5.523-4.48-10-10-10h-24.89c-11.37 0-20.61-9.195-20.61-20.556s9.24-20.557 20.61-20.557M1174.15 218.75h24.64c8.35 0 15.88 5.042 19.04 12.764l34.61 83.942c2.13 5.161 9.44 5.155 11.56-.01l34.43-83.932a20.58 20.58 0 0 1 19.04-12.764h24.64c11.37 0 20.58 9.208 20.58 20.569v146.362c0 11.361-9.21 20.569-20.58 20.569h-7.09c-11.36 0-20.58-9.208-20.58-20.569l-.12-50.645c-.01-6.888-9.53-8.688-12.06-2.283l-23.46 59.332a20.57 20.57 0 0 1-19.14 13.009h-3.03a20.57 20.57 0 0 1-19.15-13.046l-23.47-59.68c-2.52-6.416-12.05-4.623-12.06 2.271l-.13 51.042c0 11.361-9.21 20.569-20.57 20.569h-7.1c-11.36 0-20.57-9.208-20.57-20.569V239.319c0-11.361 9.21-20.569 20.57-20.569"/><path fill="#000" fill-rule="evenodd" d="m1449.94 391.836 6.12-19.392a6.255 6.255 0 0 1 5.96-4.369l50.22-.061a6.24 6.24 0 0 1 5.96 4.348l6.23 19.486c2.71 8.581 10.71 14.402 19.74 14.402h9.34c14.13 0 24.15-13.791 19.61-27.151l-49.74-146.361c-2.85-8.37-10.74-13.988-19.61-13.988h-33.16c-8.87 0-16.77 5.618-19.61 13.988l-49.74 146.361c-4.54 13.36 5.48 27.151 19.61 27.151h9.32c9.04 0 17.04-5.827 19.75-14.414m31.1-98.858c1.85-5.807 10.08-5.796 11.91.016l8.83 27.916c1.28 4.028-1.73 8.134-5.96 8.134h-17.74c-4.23 0-7.24-4.119-5.95-8.151zM1681.81 406.25c18.91 0 35.39-3.686 49.36-11.168 13.97-7.544 24.73-18.394 32.24-32.489 7.56-14.105 11.29-30.866 11.29-50.182 0-19.256-3.73-35.957-11.29-50.004-7.57-14.094-18.35-24.912-32.32-32.397-13.91-7.545-30.4-11.26-49.37-11.26h-49.5c-11.38 0-20.63 9.201-20.63 20.569v146.362c0 11.368 9.25 20.569 20.63 20.569zm23.13-47.701c-6.62 3.215-14.85 4.886-24.79 4.886-10.49 0-19-8.507-19-19v-64.34c0-10.149 8.23-18.376 18.38-18.376 10.18 0 18.56 1.703 25.23 4.974 6.59 3.149 11.63 8.315 15.08 15.633 3.45 7.269 5.28 17.268 5.28 30.162 0 12.891-1.82 22.951-5.28 30.347-3.39 7.319-8.36 12.509-14.9 15.714" clip-rule="evenodd"/><path fill="#000" d="M1804.21 385.681V239.319c0-11.361 9.21-20.569 20.58-20.569h91.28c11.36 0 20.57 9.202 20.57 20.557s-9.21 20.556-20.57 20.556h-54.64a7.807 7.807 0 0 0-7.81 7.813v16.366a7.806 7.806 0 0 0 7.81 7.812h48.13c11.37 0 20.58 9.246 20.58 20.602s-9.21 20.601-20.58 20.601h-48.13a7.806 7.806 0 0 0-7.81 7.812v16.455a7.807 7.807 0 0 0 7.81 7.813h54.64c11.36 0 20.57 9.202 20.57 20.556s-9.21 20.557-20.57 20.557h-91.28c-11.37 0-20.58-9.208-20.58-20.569"/><path fill="#000" fill-rule="evenodd" d="M2875.5 68.75h-2750c-31.066 0-56.25 25.184-56.25 56.25v750c0 31.066 25.184 56.25 56.25 56.25h2750c31.07 0 56.25-25.184 56.25-56.25V125c0-31.066-25.18-56.25-56.25-56.25M125.5 0C56.464 0 .5 55.964.5 125v750c0 69.036 55.965 125 125 125h2750c69.04 0 125-55.964 125-125V125c0-69.036-55.96-125-125-125z" clip-rule="evenodd"/><path fill="#000" d="M2476.06 804.813c-10.54 0-19.82-6.947-22.81-17.068L2390.79 575.7c-4.49-15.248 6.92-30.534 22.8-30.534h27.75c11.1 0 20.72 7.686 23.18 18.52L2489 671.402c2.07 9.093 14.93 9.321 17.32.308l28.83-108.844c2.76-10.435 12.19-17.7 22.98-17.7h25.17c10.8 0 20.25 7.293 22.99 17.755l28.27 107.739c2.36 9.001 15.18 8.829 17.3-.232l25.01-106.888c2.51-10.763 12.1-18.374 23.14-18.374h27.87c15.88 0 27.29 15.286 22.8 30.534l-62.46 212.045a23.78 23.78 0 0 1-22.81 17.068h-32.12c-10.39 0-19.58-6.763-22.69-16.696l-32.08-102.694c-2.62-8.397-14.51-8.331-17.04.095l-30.74 102.346c-3.02 10.061-12.27 16.949-22.76 16.949zM1742.44 804.813h-75.81c-13.09 0-23.71-10.656-23.71-23.801V568.967c0-13.145 10.62-23.801 23.71-23.801h74.8c26.6 0 49.59 5.198 68.95 15.594 19.45 10.312 34.44 25.187 44.96 44.627 10.61 19.355 15.91 42.556 15.91 69.602q0 40.57-15.78 69.73c-10.53 19.355-25.43 34.231-44.71 44.627-19.28 10.311-42.05 15.467-68.32 15.467m-29.3-83.642c0 13.145 10.61 23.801 23.71 23.801h3.06c12.8 0 23.7-2.07 32.71-6.212 9.09-4.141 16-11.283 20.71-21.426q7.2-15.213 7.2-42.345 0-27.13-7.32-42.344c-4.8-10.143-11.87-17.285-21.22-21.426-9.26-4.142-20.63-6.212-34.1-6.212h-1.04c-13.1 0-23.71 10.656-23.71 23.801zM1460.86 804.813c-13.12 0-23.76-10.656-23.76-23.801V568.967c0-13.145 10.64-23.801 23.76-23.801h22.84c13.13 0 23.76 10.656 23.76 23.801v155.247c0 13.145 10.64 23.801 23.76 23.801h57.27c13.12 0 23.76 10.656 23.76 23.801v9.196c0 13.145-10.64 23.801-23.76 23.801zM1204.45 601.964c-13.13 0-23.77-10.656-23.77-23.801v-9.196c0-13.145 10.64-23.801 23.77-23.801h177.89c13.13 0 23.78 10.656 23.78 23.801v9.196c0 13.145-10.65 23.801-23.78 23.801h-39.38c-8.21 0-14.86 6.66-14.86 14.875v164.173c0 13.145-10.64 23.801-23.78 23.801h-21.85c-13.13 0-23.78-10.656-23.78-23.801V616.839c0-8.215-6.65-14.875-14.86-14.875z"/><path fill="#000" fill-rule="evenodd" d="M2223.05 787.891c-3.02 10.047-12.27 16.922-22.74 16.922h-25.43c-16.19 0-27.64-15.862-22.57-31.261l69.88-212.045c3.21-9.753 12.31-16.341 22.56-16.341h61.84c10.25 0 19.35 6.588 22.56 16.341l69.87 212.045c5.08 15.399-6.37 31.261-22.56 31.261h-25.43c-10.48 0-19.72-6.875-22.74-16.922l-6.7-22.2a14.84 14.84 0 0 0-14.21-10.576h-63.42c-6.55 0-12.32 4.296-14.22 10.576zm76.13-96.945-14.13-48.436c-2.46-8.451-14.36-8.602-17.04-.217l-15.46 48.436c-1.84 5.759 2.45 11.645 8.48 11.645h29.6c5.94 0 10.22-5.715 8.55-11.428" clip-rule="evenodd"/><path fill="#000" d="M1939.6 804.813c-13.13 0-23.77-10.656-23.77-23.801V568.967c0-13.145 10.64-23.801 23.77-23.801h88.13c19.24 0 36.08 3.508 50.51 10.523s25.65 17.115 33.67 30.3q12.03 19.779 12.03 47.416c0 18.595-4.14 34.273-12.41 47.036-7.64 11.913-18.18 21.101-31.63 27.564-16.98 8.159-36 11.104-54.7 11.104h-43.07c-76.56 0 4.08-135.84 4.08-84.706v7.996c0 12.117 9.81 21.941 21.91 21.941 8.12 0 16.3-.345 24.04-3.043 5.91-2.113 10.43-5.451 13.55-10.015 3.2-4.565 4.81-10.523 4.81-17.877 0-7.437-1.61-13.481-4.81-18.129-3.12-4.733-7.64-8.199-13.55-10.396-7.05-2.766-14.67-3.423-22.18-3.423-13.13 0-23.77 10.656-23.77 23.801v47.71c0 11.825 11.14 16.003 19.91 20.752 12.31 6.671 7.58 25.389-6.42 25.389-7.45 0-13.49 6.048-13.49 13.508v48.395c0 13.145-10.63 23.801-23.76 23.801zm134.89-106.758 5.41 9.95 33.51 61.622c8.62 15.86-2.84 35.186-20.87 35.186h-22.27c-8.74 0-16.77-4.798-20.92-12.496l-35.05-65.04a15.52 15.52 0 0 0-13.66-8.168c-42.24 0 40.62-82.154 73.85-21.054M931.652 0h68.748v1000h-68.748z"/></svg>',xee='<svg xmlns="http://www.w3.org/2000/svg" width="400" height="1601" fill="none"><path fill="#000" d="M72 1319.8c0-10.73 7.071-20.18 17.372-23.22l215.823-63.62c15.519-4.57 31.078 7.05 31.078 23.22v28.26c0 11.31-7.824 21.1-18.85 23.61l-109.636 24.94c-9.254 2.1-9.487 15.2-.313 17.63l110.784 29.37a24.21 24.21 0 0 1 18.015 23.4v25.64c0 11-7.423 20.62-18.071 23.41l-109.659 28.79c-9.162 2.41-8.986 15.47.236 17.63l108.792 25.46c10.955 2.56 18.702 12.33 18.702 23.57v28.39c0 16.17-15.559 27.79-31.078 23.22l-215.823-63.62c-10.3-3.04-17.372-12.49-17.372-23.22v-32.72c0-10.59 6.883-19.95 16.994-23.11l104.523-32.67c8.547-2.67 8.479-14.79-.096-17.36l-104.17-31.3C79.01 1372.42 72 1363 72 1352.31zM72 572.638V495.43c0-13.336 10.846-24.147 24.225-24.147h215.823c13.379 0 24.225 10.811 24.225 24.147v76.179q0 40.645-15.872 70.228-15.743 29.712-45.422 45.79-29.55 16.206-70.843 16.206-41.292 0-70.971-16.078-29.55-16.077-45.422-45.532Q72 612.767 72 572.638m85.132-29.84c-13.379 0-24.225 10.81-24.225 24.146v3.122q0 19.55 6.323 33.313 6.323 13.89 21.807 21.094 15.485 7.332 43.099 7.331t43.1-7.46q15.484-7.33 21.807-21.608 6.323-14.15 6.323-34.728v-1.064c0-13.336-10.846-24.146-24.225-24.146zM72 285.858c0-13.363 10.846-24.197 24.225-24.197h215.823c13.379 0 24.225 10.834 24.225 24.197v23.27c0 13.364-10.846 24.197-24.225 24.197H154.035c-13.379 0-24.225 10.834-24.225 24.197v58.328c0 13.364-10.846 24.197-24.225 24.197h-9.36C82.845 440.047 72 429.214 72 415.85zM278.463 24.72c0-13.374 10.846-24.216 24.225-24.216h9.36c13.379 0 24.225 10.842 24.225 24.216v181.174c0 13.374-10.846 24.216-24.225 24.216h-9.36c-13.379 0-24.225-10.842-24.225-24.216v-40.108c0-8.359-6.779-15.135-15.141-15.135H96.225c-13.38 0-24.225-10.842-24.225-24.216v-22.256c0-13.374 10.846-24.216 24.225-24.216h167.097c8.362 0 15.141-6.776 15.141-15.135z"/><path fill="#000" fill-rule="evenodd" d="M89.224 1062.13C78.997 1059.04 72 1049.63 72 1038.96v-25.9c0-16.486 16.145-28.147 31.818-22.979l215.823 71.169a24.19 24.19 0 0 1 16.632 22.98v62.97c0 10.45-6.706 19.71-16.632 22.98l-215.823 71.17C88.145 1246.51 72 1234.86 72 1218.37v-25.9c0-10.67 6.997-20.08 17.224-23.17l22.595-6.81a15.13 15.13 0 0 0 10.765-14.48v-64.59a15.13 15.13 0 0 0-10.765-14.48zm98.672 77.53 49.299-14.39c8.601-2.51 8.755-14.62.22-17.35l-49.299-15.75c-5.861-1.88-11.852 2.49-11.852 8.64v30.14c0 6.05 5.817 10.41 11.632 8.71" clip-rule="evenodd"/><path fill="#000" d="M72 773.439c0-13.367 10.846-24.203 24.225-24.203h215.823c13.379 0 24.225 10.836 24.225 24.203v89.762q0 29.395-10.711 51.439-10.71 22.046-30.84 34.293t-48.261 12.248q-28.388 0-47.873-12.635-18.187-11.672-28.056-32.218c-8.303-17.289-11.301-36.661-11.301-55.705v-43.867c0-77.976 138.26 4.16 86.215 4.16h-8.138c-12.334 0-22.332 9.989-22.332 22.311 0 8.269.351 16.6 3.097 24.487q3.225 9.024 10.194 13.794 6.968 4.899 18.194 4.899 11.356 0 18.453-4.899 7.226-4.77 10.581-13.794c2.815-7.188 3.484-14.944 3.484-22.596 0-13.366-10.846-24.202-24.225-24.202h-48.56c-12.036 0-16.288 11.345-21.122 20.272-6.79 12.539-25.841 7.72-25.841-6.536 0-7.586-6.156-13.736-13.749-13.736H96.225C82.845 820.916 72 810.08 72 796.714zm108.66 137.378-10.128 5.511-62.72 34.131C91.67 959.243 72 947.569 72 929.205V906.52a24.2 24.2 0 0 1 12.719-21.299l66.199-35.696a15.82 15.82 0 0 0 8.313-13.921c0-43.012 83.618 41.371 21.429 75.213"/></svg>',wee=`data:image/svg+xml;utf8,${encodeURIComponent(vee)}`,bee=`data:image/svg+xml;utf8,${encodeURIComponent(xee)}`,Pee=w.memo(function(){const e=yee(),n=F(),r=U("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),[o,s]=w.useState(null);return ss("set watermark src",async()=>{["licensed-with-watermark","unlicensed"].includes(e.state.get())&&s(r?bee:wee)},[e,r]),o?d.jsxs(d.Fragment,{children:[d.jsx(_ee,{}),d.jsx(Cee,{src:o})]}):null}),Cee=w.memo(function({src:e}){const n=F(),r=U("debug mode",()=>n.getInstanceState().isDebugMode,[n]),o=U("is menu open",()=>n.getIsMenuOpen(),[n]),s=U("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),i=MA(),a=`url('${e}') center 100% / 100% no-repeat`,l="https://tldraw.dev";return d.jsx("div",{className:Ng.className,"data-debug":r,"data-menu":o,"data-mobile":s,draggable:!1,...i,children:d.jsx("a",{target:"_blank",href:l,rel:"noreferrer",draggable:!1,onPointerDown:c=>{Ot(c),we(c)},onClick:()=>Eg.openWindow(l,"_blank"),style:{mask:a,WebkitMask:a}})})}),_ee=w.memo(function(){const e=Ng.className,n=`/* ------------------- SEE LICENSE -------------------
114
- The tldraw watermark is part of tldraw's license. It is shown for unlicensed
115
- or "licensed-with-watermark" users. By using this library, you agree to
116
- preserve the watermark's behavior, keeping it visible, unobscured, and
117
- available to user-interaction.
118
-
119
- To remove the watermark, please purchase a license at tldraw.dev.
120
- */
121
-
122
- .${e} {
123
- position: absolute;
124
- bottom: var(--space-2);
125
- right: var(--space-2);
126
- width: 96px;
127
- height: 32px;
128
- display: flex;
129
- align-items: center;
130
- justify-content: center;
131
- z-index: 2147483647 !important;
132
- background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
133
- opacity: 1;
134
- border-radius: 5px;
135
- pointer-events: all;
136
- padding: 2px;
137
- box-sizing: content-box;
138
- }
139
-
140
- .${e} > a {
141
- position: absolute;
142
- width: 96px;
143
- height: 32px;
144
- pointer-events: all;
145
- cursor: inherit;
146
- color: var(--color-text);
147
- opacity: .38;
148
- background-color: currentColor;
149
- }
150
-
151
-
152
- .${e}[data-menu='true'] {
153
- pointer-events: none;
154
- }
155
-
156
- .${e}[data-debug='true'] {
157
- bottom: 46px;
158
- }
159
-
160
- .${e}[data-mobile='true'] {
161
- border-radius: 4px 0px 0px 4px;
162
- right: -2px;
163
- width: 8px;
164
- height: 48px;
165
- }
166
-
167
- .${e}[data-mobile='true'] > a {
168
- width: 8px;
169
- height: 32px;
170
- }
171
-
172
- @media (hover: hover) {
173
- .${e} > a {
174
- pointer-events: none;
175
- }
176
-
177
- .${e}:hover {
178
- background-color: var(--color-background);
179
- transition: background-color 0.2s ease-in-out;
180
- transition-delay: 0.32s;
181
- }
182
-
183
- .${e}:hover > a {
184
- animation: delayed_link 0.2s forwards ease-in-out;
185
- animation-delay: 0.32s;
186
- }
187
- }
188
-
189
-
190
- @keyframes delayed_link {
191
- 0% {
192
- cursor: inherit;
193
- opacity: .38;
194
- pointer-events: none;
195
- }
196
- 100% {
197
- cursor: pointer;
198
- opacity: 1;
199
- pointer-events: all;
200
- }
201
- }`;return d.jsx("style",{children:n})}),Iee=[],Eee=[],kee=[],Tee="tl-container",Mee=w.memo(function({store:e,components:n,className:r,user:o,...s}){const[i,a]=w.useState(null),l=w.useMemo(()=>o??lj(),[o]),c=(n==null?void 0:n.ErrorFallback)===void 0?JA:n==null?void 0:n.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??Iee,bindingUtils:s.bindingUtils??Eee,tools:s.tools??kee,components:n};return d.jsx("div",{ref:a,"data-tldraw":_A,draggable:!1,className:le(`${Tee} tl-theme__light`,r),onPointerDown:Ot,tabIndex:-1,children:d.jsx(ju,{fallback:c,onError:h=>cw(h,{tags:{origin:"react.tldraw-before-app"}}),children:i&&d.jsx(See,{licenseKey:s.licenseKey,children:d.jsx(NY,{container:i,children:d.jsx(Uq,{overrides:n,children:e?e instanceof zw?d.jsx(vR,{...u,store:e,user:l}):d.jsx(SR,{...u,store:e,user:l}):d.jsx(Aee,{...u,store:e,user:l})})})})})})});function Aee(t){const{defaultName:e,snapshot:n,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:l,assets:c}=t,u=cee({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:n,assets:c});return d.jsx(SR,{...t,store:u,user:l})}const SR=w.memo(function({store:e,user:n,...r}){const o=Lt();w.useLayoutEffect(()=>{n.userPreferences.get().colorScheme==="dark"&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,n]);const{LoadingScreen:s}=rt();switch(e.status){case"error":throw e.error;case"loading":return s?d.jsx(s,{}):null}return d.jsx(vR,{...r,store:e.store,user:n})}),Wy=()=>document.location.search.includes("tldraw_preserve_focus");function vR({onMount:t,children:e,store:n,tools:r,shapeUtils:o,bindingUtils:s,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:u,options:h,licenseKey:p,deepLinks:f,isShapeHidden:g}){const{ErrorFallback:m}=rt(),v=Lt(),[S,y]=mR(null),b=w.useRef(null),P=sd(f===!0?{}:f),C=w.useRef({autoFocus:l&&!Wy(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P});w.useLayoutEffect(()=>{C.current={autoFocus:l&&!Wy(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P}},[l,c,a,u,P]),w.useLayoutEffect(()=>{const{autoFocus:_,inferDarkMode:k,initialState:M,cameraOptions:R,deepLinks:j}=C.current,O=new Q({store:n,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>v,user:i,initialState:M,autoFocus:_,inferDarkMode:k,cameraOptions:R,options:h,licenseKey:p,isShapeHidden:g});return O.updateViewportScreenBounds(b.current??v),j&&(j!=null&&j.getUrl?O.navigateToDeepLink({...j,url:j.getUrl(O)}):O.navigateToDeepLink(j)),y(O),()=>{O.dispose()}},[s,v,h,o,n,r,i,y,p,g]),w.useLayoutEffect(()=>{if(S&&P)return S.registerDeepLinkListener(P)},[S,P]),w.useLayoutEffect(()=>{S&&u&&S.setCameraOptions(u)},[S,u]);const I=w.useSyncExternalStore(w.useCallback(_=>S?(S.on("crash",_),()=>S.off("crash",_)):()=>{},[S]),()=>(S==null?void 0:S.getCrashingError())??null);w.useEffect(function(){if(!S)return;function k(){S&&S.focus()}function M(){S&&S.blur()}if(l&&Wy())return S.getContainer().addEventListener("pointerdown",k),document.body.addEventListener("pointerdown",M),()=>{var R;(R=S.getContainer())==null||R.removeEventListener("pointerdown",k),document.body.removeEventListener("pointerdown",M)}},[S,l]);const{Canvas:T}=rt();return S?d.jsx(ju,{fallback:m,onError:_=>S.annotateError(_,{origin:"react.tldraw",willCrashApp:!0}),children:I?d.jsx(Oee,{crashingError:I}):d.jsx(_g.Provider,{value:S,children:d.jsxs(jee,{onMount:t,children:[e??(T?d.jsx(T,{}):null),d.jsx(Pee,{})]})})}):d.jsx("div",{className:"tl-canvas",ref:b})}function jee({children:t,onMount:e}){return uee(),RJ(),LJ(),$J(),wR(n=>{const r=n.store.props.onMount(n),o=e==null?void 0:e(n);return()=>{r==null||r(),o==null||o()}}),t}function Oee({crashingError:t}){throw t}function m1({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function xR({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function wR(t){const e=F(),n=Og(r=>{let o;return r.run(()=>{o=t==null?void 0:t(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,o});Ie.useLayoutEffect(()=>{if(e)return n==null?void 0:n(e)},[e,n])}function ri({children:t,className:e="",...n}){return d.jsx("div",{...n,className:le("tl-html-container",e),children:t})}class tp{constructor(e){this.editor=e}}E(tp,"props"),E(tp,"migrations"),E(tp,"type");function zg(t,e,n={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let h=t.props.w*s,p=t.props.h*i;const f=new x(0,0);if(h>0){if(h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=h-a;break}case"top":case"bottom":{f.x=(h-a)/2;break}default:f.x=0}h=a}}else if(f.x=h,h=-h,h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-h;break}default:f.x=-a}h=a}if(p>0){if(p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=p-c;break}case"right":case"left":{f.y=(p-c)/2;break}default:f.y=0}p=c}}else if(f.y=p,p=-p,p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-c}p=c}const{x:g,y:m}=f.rot(t.rotation).add(r);return{...t,x:g,y:m,props:{w:Math.min(l,h),h:Math.min(u,p)}}}class Yl extends Zr{getGeometry(e){return new fs({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,n){return zg(e,n)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,n,r){return{...n.props,w:Ee(e.props.w,n.props.w,r),h:Ee(e.props.h,n.props.h,r)}}}var bS;let Dee=(bS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(bS,"id","idle"),bS);var PS;let Ree=(PS=class extends ie{constructor(){super(...arguments);E(this,"wasFocusedOnEnter",!1)}onEnter(){this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()}onPointerMove(n){if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=Ne(),i=this.editor.markHistoryStoppingPoint(`creating_box:${s}`);this.editor.createShapes([{id:s,type:o,x:r.x,y:r.y,props:{w:1,h:1}}]).select(s);const a=this.parent;this.editor.setCurrentTool("select.resizing",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:i,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?l=>{var c;return(c=a.onCreate)==null?void 0:c.call(a,l)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:n}=this.editor.inputs;if(!this.wasFocusedOnEnter)return;const r=this.parent.shapeType,o=Ne();this.editor.markHistoryStoppingPoint(`creating_box:${o}`),this.editor.createShapes([{id:o,type:r,x:n.x,y:n.y}]);const s=this.editor.getShape(o);if(!s){this.cancel();return}let{w:i,h:a}=s.props;const l=new x(i/2,a/2),c=this.editor.getShapeParentTransform(s);c&&l.rot(-c.rotation());let u=1;this.editor.user.getIsDynamicResizeMode()&&(u=1/this.editor.getZoomLevel(),i*=u,a*=u,l.mul(u));const h=tt(s);h.x=s.x-l.x,h.y=s.y-l.y,h.props.w=i,h.props.h=a,"scale"in s.props&&(h.props.scale=u),this.editor.updateShape(h),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},E(PS,"id","pointing"),PS);class bx extends ie{static children(){return[Dee,Ree]}}E(bx,"id","box"),E(bx,"initial","idle");function Bg(t){const e=F();return U("isEditing",()=>e.getEditingShapeId()===t,[e,t])}function go(t){const e=F();return w.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===Zw){e.dispatch({type:"pointer",target:"selection",handle:t,name:"right_click",...Bn(c)});return}if(c.button!==0)return;const u=_f(c.currentTarget);function h(){u.removeEventListener("pointerup",h),nd(u,c)}td(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:t,...Bn(c)}),Ot(c)};let s,i;function a(c){c.isKilled||c.button===0&&(c.clientX===s&&c.clientY===i||(s=c.clientX,i=c.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:t,...Bn(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:t,...Bn(c)})}}},[e,t])}function Lee(t){const[e,n]=w.useState(()=>({store:Ou(t),opts:t}));if(!pT(e.opts,t)){const r={store:Ou(t),opts:t};return n(r),r.store}return e.store}const $ee=20,Fee=8;function y1(t,e=$ee){return Math.max(Fee,Math.ceil(t/e))}class Ja extends bi{constructor(n){super({...n,isFilled:!1,isClosed:!1});E(this,"_center");E(this,"radius");E(this,"start");E(this,"end");E(this,"largeArcFlag");E(this,"sweepFlag");E(this,"measure");E(this,"angleStart");E(this,"angleEnd");const{center:r,sweepFlag:o,largeArcFlag:s,start:i,end:a}=n;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=x.Angle(r,i),this.angleEnd=x.Angle(r,a),this.radius=x.Dist(r,i),this.measure=MY(this.angleStart,this.angleEnd,o,s),this.start=i,this.end=a,this.sweepFlag=o,this.largeArcFlag=s,this._center=r}nearestPoint(n){const{_center:r,measure:o,radius:s,angleEnd:i,angleStart:a,start:l,end:c}=this,u=lx(o,a,i,r.angle(n));if(u<=0)return l;if(u>=1)return c;const h=r.clone().add(n.clone().sub(r).uni().mul(s));let p,f=1/0,g;for(const m of[l,c,h])g=x.Dist2(n,m),g<f&&(p=m,f=g);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(n,r){const{_center:o,radius:s,measure:i,angleStart:a,angleEnd:l}=this,c=id(n,r,o,s);return c===null?!1:c.some(u=>{const h=lx(i,a,l,o.angle(u));return h>=0&&h<=1})}getVertices(){const{_center:n,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let l=0,c=y1(Math.abs(o));l<c+1;l++){const u=l/c*r,h=i+u;a.push(ra(n,s,h))}return a}getSvgPathData(n=!0){const{start:r,end:o,radius:s,largeArcFlag:i,sweepFlag:a}=this;return`${n?`M${r.toFixed()}`:""} A${s} ${s} 0 ${i} ${a} ${o.toFixed()}`}getLength(){return this.measure*this.radius}}class S1 extends bi{constructor(n){super({isClosed:!0,...n});E(this,"_center");E(this,"radius");E(this,"x");E(this,"y");this.config=n;const{x:r=0,y:o=0,radius:s}=n;this.x=r,this.y=o,this._center=new x(s+r,s+o),this.radius=s}getBounds(){return new Z(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,o=Fe*r,s=[];for(let i=0,a=y1(o);i<a;i++){const l=i/a*Fe;s.push(ra(n,r,l))}return s}nearestPoint(n){const{_center:r,radius:o}=this;return r.equals(n)?x.AddXY(r,o,0):r.clone().add(n.clone().sub(r).uni().mul(o))}hitTestLineSegment(n,r,o=0){const{_center:s,radius:i}=this;return id(n,r,s,i+o)!==null}getSvgPathData(){const{_center:n,radius:r}=this;return`M${n.x+r},${n.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class sn extends Wl{constructor(n){const{start:r,cp1:o,cp2:s,end:i}=n;super({...n,points:[r,i]});E(this,"a");E(this,"b");E(this,"c");E(this,"d");this.a=r,this.b=o,this.c=s,this.d=i}getVertices(){const n=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;n.push(new x((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*o.x+3*(1-c)*(c*c)*s.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*o.y+3*(1-c)*(c*c)*s.y+c*c*c*i.y))}return n}midPoint(){return sn.GetAtT(this,.5)}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(n),s=x.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}getSvgPathData(n=!0){const{a:r,b:o,c:s,d:i}=this;return`${n?`M ${r.toFixed()} `:""} C${o.toFixed()} ${s.toFixed()} ${i.toFixed()}`}static GetAtT(n,r){const{a:o,b:s,c:i,d:a}=n;return new x((1-r)*(1-r)*(1-r)*o.x+3*((1-r)*(1-r))*r*s.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*o.y+3*((1-r)*(1-r))*r*s.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(n=32){let r,o=this.a,s=0;for(let i=1;i<=n;i++)r=sn.GetAtT(this,i/n),s+=x.Dist(o,r),o=r;return s}}class Nee extends bi{constructor(n){super({...n,isClosed:!1,isFilled:!1});E(this,"points");E(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?n[0]:n[i-1],l=n[i],c=n[i+1],u=i===o?c:n[i+2],h=l,p=i===0?a:new x(l.x+(c.x-a.x)/6*s,l.y+(c.y-a.y)/6*s),f=i===o?c:new x(c.x-(u.x-l.x)/6*s,c.y-(u.y-l.y)/6*s),g=c;this._segments.push(new sn({start:h,cp1:p,cp2:f,end:g}))}}return this._segments}getLength(){return this.segments.reduce((n,r)=>n+r.length,0)}getVertices(){const n=this.segments.reduce((r,o)=>r.concat(o.vertices),[]);return n.push(this.points[this.points.length-1]),n}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(n),s=x.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.segments.some(o=>o.hitTestLineSegment(n,r))}getSvgPathData(){let n=this.segments.reduce((r,o,s)=>r+o.getSvgPathData(s===0),"");return this.isClosed&&(n+="Z"),n}}class zee extends bi{constructor(n){super({...n,isClosed:!0});E(this,"w");E(this,"h");E(this,"_edges");this.config=n;const{width:r,height:o}=n;this.w=r,this.h=o}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,o=n.length;r<o;r++){const s=n[r],i=n[(r+1)%o];this._edges.push(new es({start:s,end:i}))}}return this._edges}getVertices(){const n=Math.max(1,this.w),r=Math.max(1,this.h),o=n/2,s=r/2,i=Math.pow(o-s,2)/Math.pow(o+s,2),a=De*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),l=y1(a),c=Fe/l,u=Math.cos(c),h=Math.sin(c);let p=0,f=1,g=0,m=1;const v=Array(l);for(let S=0;S<l;S++)v[S]=new x(o+o*f,s+s*p),g=h*f+u*p,m=u*f-h*p,p=g,f=m;return v}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(n),s=x.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(o=>o.hitTestLineSegment(n,r))}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{w:n,h:r}=this,o=n/2,s=r/2,i=Math.max(0,o),a=Math.max(0,s);return IA(i,a)}getSvgPathData(n=!1){const{w:r,h:o}=this,s=r/2,i=o/2,a=Math.max(0,s),l=Math.max(0,i);return`${n?`M${s-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class Bee extends bi{constructor(n){super({...n,isClosed:!0});E(this,"w");E(this,"h");E(this,"a");E(this,"b");E(this,"c");E(this,"d");this.config=n;const{width:r,height:o}=n;if(this.w=r,this.h=o,o>r){const s=r/2;this.a=new Ja({start:new x(0,s),end:new x(r,s),center:new x(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new es({start:new x(r,s),end:new x(r,o-s)}),this.c=new Ja({start:new x(r,o-s),end:new x(0,o-s),center:new x(r/2,o-s),sweepFlag:1,largeArcFlag:1}),this.d=new es({start:new x(0,o-s),end:new x(0,s)})}else{const s=o/2;this.a=new Ja({start:new x(s,o),end:new x(s,0),center:new x(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new es({start:new x(s,0),end:new x(r-s,0)}),this.c=new Ja({start:new x(r-s,0),end:new x(r-s,o),center:new x(r-s,s),sweepFlag:1,largeArcFlag:1}),this.d=new es({start:new x(r-s,o),end:new x(s,o)})}}nearestPoint(n){let r,o=1/0,s,i;const{a,b:l,c,d:u}=this;for(const h of[a,l,c,u])i=h.nearestPoint(n),s=x.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){const{a:o,b:s,c:i,d:a}=this;return[o,s,i,a].some(l=>l.hitTestLineSegment(n,r))}getVertices(){const{a:n,b:r,c:o,d:s}=this;return[n,r,o,s].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{h:n,w:r}=this;return n>r?(De*(r/2)+(n-r))*2:(De*(n/2)+(r-n))*2}getSvgPathData(){const{a:n,b:r,c:o,d:s}=this;return[n,r,o,s].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function Uee({shouldReload:t=!0}={}){D9();for(const e of kf.connectedInstances)await e.close();await Promise.all(g1().map(e=>pR(e))),O9(),t&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Uee);function Hee(t,e="_blank"){Eg.openWindow(t,e)}Si("@tldraw/editor","3.2.0","esm");function Ve(t,e){var o;const n=new Set;for(const s of e){const i=t.getShape(s);if(!i)continue;t.getShapeUtil(i).onDragShapesOut&&n.add(i);const a=t.getShape(i.parentId);a&&t.getShapeUtil(a).onDragShapesOut&&n.add(a)}const r=new Map;for(const s of n){const i=bR(t,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=t.getShapeUtil(s),l=ye(i.map(c=>t.getShape(c)));(o=a.onDragShapesOut)==null||o.call(a,s,l)}}function bR(t,e){const n=t.getSortedChildIdsForParent(e.id);if(n.length===0)return[];const r=t.getShapePageBounds(e);if(!r)return[];let o,s,i;const a=[];for(const l of n){const c=t.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}o??(o=t.getShapeGeometry(e)),s??(s=t.getShapePageTransform(e)),i??(i=s.applyToPoints(o.vertices));const u=t.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:h,isClosed:p}=t.getShapeGeometry(l);if(!h.some(f=>ur(f,u))){if(p){if(gj(u,h))continue}else if(lZ(u,h))continue;a.push(l)}}return a}function Tf(t,e,n=!1){t.select(e),t.setEditingShape(e),t.setCurrentTool("select.editing_shape",{target:"shape",shape:e}),n&&t.emit("select-all-text",{shapeId:e.id}),PR(t)}const Kee=16;function PR(t){const e=t.getSelectionPageBounds(),n=t.getViewportPageBounds();if(e&&!n.contains(e)){const r=e.clone().expandBy(Kee/t.getZoomLevel()).expand(n),o=n.clone().translate({x:(r.center.x-n.center.x)*2,y:(r.center.y-n.center.y)*2});t.zoomToBounds(o,{animation:{duration:t.options.animationMediumMs},inset:0})}}function Wee(t,e){const n=ye(e.map(o=>t.getShape(o)).filter(o=>o&&t.isShapeOfType(o,"frame")));if(!n.length)return;const r=[];t.run(()=>{n.map(o=>{const s=t.getSortedChildIdsForParent(o.id);s.length&&(t.reparentShapes(s,o.parentId,o.index),r.push(...s))}),t.setSelectedShapes(r),t.deleteShapes(e)})}const Gee=50;function Vee(t,e,n={}){const r=t.getShape(e);if(!r)return;const o=t.getSortedChildIdsForParent(r.id),s=ye(o.map(f=>t.getShape(f)));if(!s.length)return;const i=Z.FromPoints(s.flatMap(f=>{const g=t.getShapeGeometry(f.id);return t.getShapeLocalTransform(f).applyToPoints(g.vertices)})),{padding:a=Gee}=n,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,h=a-i.minY;if(u===0&&h===0&&r.props.w===l&&r.props.h===c)return;const p=new x(u,h).rot(r.rotation);t.run(()=>{const f=o.map(g=>{const m=t.getShape(g);return{id:m.id,type:m.type,x:m.x+u,y:m.y+h}});f.push({id:r.id,type:r.type,x:r.x-p.x,y:r.y-p.y,props:{w:l,h:c}}),t.updateShapes(f)})}const CR=w.createContext(null);function Yee({assetUrls:t,children:e}){return w.useEffect(()=>{for(const n of Object.values(t.icons)){const r=Iu();r.src=n,r.decode()}for(const n of Object.values(t.embedIcons)){const r=Iu();r.src=n,r.decode()}},[t]),d.jsx(CR.Provider,{value:t,children:e})}function v1(){const t=w.useContext(CR);if(!t)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return t}const Px={"action.convert-to-bookmark":"Convert to Bookmark","action.convert-to-embed":"Convert to Embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","action.export-as-json.short":"JSON","action.export-as-json":"Export as JSON","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-json.short":"JSON","action.export-all-as-json":"Export as JSON","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.fork-project-on-tldraw":"Fork project on tldraw","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.paste-error-title":"Pasting failed","action.paste-error-description":"Could not paste due to missing clipboard permissions. Please enable the permissions and try again.","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-paste-at-cursor.menu":"Paste at cursor","action.toggle-paste-at-cursor":"Toggle paste at cursor","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.size-too-big":"File size is too big","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","theme.dark":"Dark","theme.light":"Light","theme.system":"System","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","fill-style.fill":"Fill","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","tool.pointer-down":"Pointer down","menu.title":"Menu","menu.theme":"Theme","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.help":"Help","menu.view":"View","context-menu.edit":"Edit","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy editor link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","document-name-menu.copy-link":"Copy link","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About tldraw","help-menu.docs":"Documentation & API","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","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},Xee=new Set(["ar","fa","he","ur","ku"]),ka={locale:"en",label:"English",messages:Px,dir:"ltr"};async function qee(t,e){if(!(await Jr(e.translations.en)).ok)return console.warn("No main translations found."),ka;if(t==="en")return ka;const r=Au.find(a=>a.locale===t);if(!r)return console.warn(`No translation found for locale ${t}`),ka;const s=await(await Jr(e.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${t}`),ka;const i=[];for(const a in ka.messages)s[a]||i.push(a);return i.length>0,{locale:t,label:r.label,dir:Xee.has(r.locale)?"rtl":"ltr",messages:{...ka.messages,...s}}}const _R=w.createContext(null);function IR(){const t=w.useContext(_R);if(!t)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return t}const Zee=Rt(function({overrides:e,children:n}){const o=F().user.getLocale(),s=v1(),[i,a]=w.useState(()=>e&&e.en?{locale:"en",label:"English",dir:"ltr",messages:{...Px,...e.en}}:{locale:"en",label:"English",dir:"ltr",messages:Px});return w.useEffect(()=>{let l=!1;async function c(){const u=await qee(o,s);u&&!l&&(e&&e[o]?a({...u,messages:{...u.messages,...e[o]}}):a(u))}return c(),()=>{l=!0}},[s,o,e]),d.jsx(_R.Provider,{value:i,children:n})});function Ce(){const t=IR();return w.useCallback(function(n){return t.messages[n]??n},[t])}const ue=w.forwardRef(function({children:e,disabled:n,type:r,...o},s){return d.jsx("button",{ref:s,type:"button",draggable:!1,disabled:n,...o,className:le("tlui-button",`tlui-button__${r}`,o.className),children:e})});function wt({children:t}){return d.jsx("span",{className:"tlui-button__label",children:t})}function oe(t,e,{checkForDefaultPrevented:n=!0}={}){return function(o){if(t==null||t(o),n===!1||!o.defaultPrevented)return e==null?void 0:e(o)}}function Qee(t,e){typeof t=="function"?t(e):t!=null&&(t.current=e)}function Ug(...t){return e=>t.forEach(n=>Qee(n,e))}function Ze(...t){return w.useCallback(Ug(...t),t)}function Jee(t,e){const n=w.createContext(e);function r(s){const{children:i,...a}=s,l=w.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})}function o(s){const i=w.useContext(n);if(i)return i;if(e!==void 0)return e;throw new Error(`\`${s}\` must be used within \`${t}\``)}return r.displayName=t+"Provider",[r,o]}function Lo(t,e=[]){let n=[];function r(s,i){const a=w.createContext(i),l=n.length;n=[...n,i];function c(h){const{scope:p,children:f,...g}=h,m=(p==null?void 0:p[t][l])||a,v=w.useMemo(()=>g,Object.values(g));return d.jsx(m.Provider,{value:v,children:f})}function u(h,p){const f=(p==null?void 0:p[t][l])||a,g=w.useContext(f);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return c.displayName=s+"Provider",[c,u]}const o=()=>{const s=n.map(i=>w.createContext(i));return function(a){const l=(a==null?void 0:a[t])||s;return w.useMemo(()=>({[`__scope${t}`]:{...a,[t]:l}}),[a,l])}};return o.scopeName=t,[r,ete(o,...e)]}function ete(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(s)[`__scope${c}`];return{...a,...h}},{});return w.useMemo(()=>({[`__scope${e.scopeName}`]:i}),[i])}};return n.scopeName=e.scopeName,n}var ci=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{},tte=CN.useId||(()=>{}),nte=0;function as(t){const[e,n]=w.useState(tte());return ci(()=>{t||n(r=>r??String(nte++))},[t]),t||(e?`radix-${e}`:"")}function Xt(t){const e=w.useRef(t);return w.useEffect(()=>{e.current=t}),w.useMemo(()=>(...n)=>{var r;return(r=e.current)==null?void 0:r.call(e,...n)},[])}function Pi({prop:t,defaultProp:e,onChange:n=()=>{}}){const[r,o]=rte({defaultProp:e,onChange:n}),s=t!==void 0,i=s?t:r,a=Xt(n),l=w.useCallback(c=>{if(s){const h=typeof c=="function"?c(t):c;h!==t&&a(h)}else o(c)},[s,t,o,a]);return[i,l]}function rte({defaultProp:t,onChange:e}){const n=w.useState(t),[r]=n,o=w.useRef(r),s=Xt(e);return w.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),n}var oa=w.forwardRef((t,e)=>{const{children:n,...r}=t,o=w.Children.toArray(n),s=o.find(ste);if(s){const i=s.props.children,a=o.map(l=>l===s?w.Children.count(i)>1?w.Children.only(null):w.isValidElement(i)?i.props.children:null:l);return d.jsx(Cx,{...r,ref:e,children:w.isValidElement(i)?w.cloneElement(i,void 0,a):null})}return d.jsx(Cx,{...r,ref:e,children:n})});oa.displayName="Slot";var Cx=w.forwardRef((t,e)=>{const{children:n,...r}=t;if(w.isValidElement(n)){const o=ate(n);return w.cloneElement(n,{...ite(r,n.props),ref:e?Ug(e,o):o})}return w.Children.count(n)>1?w.Children.only(null):null});Cx.displayName="SlotClone";var ote=({children:t})=>d.jsx(d.Fragment,{children:t});function ste(t){return w.isValidElement(t)&&t.type===ote}function ite(t,e){const n={...e};for(const r in e){const o=t[r],s=e[r];/^on[A-Z]/.test(r)?o&&s?n[r]=(...a)=>{s(...a),o(...a)}:o&&(n[r]=o):r==="style"?n[r]={...o,...s}:r==="className"&&(n[r]=[o,s].filter(Boolean).join(" "))}return{...t,...n}}function ate(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var lte=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ae=lte.reduce((t,e)=>{const n=w.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?oa:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(a,{...i,ref:o})});return n.displayName=`Primitive.${e}`,{...t,[e]:n}},{});function x1(t,e){t&&ps.flushSync(()=>t.dispatchEvent(e))}function cte(t,e=globalThis==null?void 0:globalThis.document){const n=Xt(t);w.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var ute="DismissableLayer",_x="dismissableLayer.update",dte="dismissableLayer.pointerDownOutside",hte="dismissableLayer.focusOutside",wI,ER=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),hd=w.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=t,c=w.useContext(ER),[u,h]=w.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=w.useState({}),g=Ze(e,T=>h(T)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=m.indexOf(v),y=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,P=y>=S,C=fte(T=>{const _=T.target,k=[...c.branches].some(M=>M.contains(_));!P||k||(o==null||o(T),i==null||i(T),T.defaultPrevented||a==null||a())},p),I=gte(T=>{const _=T.target;[...c.branches].some(M=>M.contains(_))||(s==null||s(T),i==null||i(T),T.defaultPrevented||a==null||a())},p);return cte(T=>{y===c.layers.size-1&&(r==null||r(T),!T.defaultPrevented&&a&&(T.preventDefault(),a()))},p),w.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(wI=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),bI(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=wI)}},[u,p,n,c]),w.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),bI())},[u,c]),w.useEffect(()=>{const T=()=>f({});return document.addEventListener(_x,T),()=>document.removeEventListener(_x,T)},[]),d.jsx(Ae.div,{...l,ref:g,style:{pointerEvents:b?P?"auto":"none":void 0,...t.style},onFocusCapture:oe(t.onFocusCapture,I.onFocusCapture),onBlurCapture:oe(t.onBlurCapture,I.onBlurCapture),onPointerDownCapture:oe(t.onPointerDownCapture,C.onPointerDownCapture)})});hd.displayName=ute;var pte="DismissableLayerBranch",kR=w.forwardRef((t,e)=>{const n=w.useContext(ER),r=w.useRef(null),o=Ze(e,r);return w.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),d.jsx(Ae.div,{...t,ref:o})});kR.displayName=pte;function fte(t,e=globalThis==null?void 0:globalThis.document){const n=Xt(t),r=w.useRef(!1),o=w.useRef(()=>{});return w.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){TR(dte,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",o.current),o.current=l,e.addEventListener("click",o.current,{once:!0})):l()}else e.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{e.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),e.removeEventListener("pointerdown",s),e.removeEventListener("click",o.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function gte(t,e=globalThis==null?void 0:globalThis.document){const n=Xt(t),r=w.useRef(!1);return w.useEffect(()=>{const o=s=>{s.target&&!r.current&&TR(hte,n,{originalEvent:s},{discrete:!1})};return e.addEventListener("focusin",o),()=>e.removeEventListener("focusin",o)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function bI(){const t=new CustomEvent(_x);document.dispatchEvent(t)}function TR(t,e,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&o.addEventListener(t,e,{once:!0}),r?x1(o,s):o.dispatchEvent(s)}var mte=hd,yte=kR,Gy="focusScope.autoFocusOnMount",Vy="focusScope.autoFocusOnUnmount",PI={bubbles:!1,cancelable:!0},Ste="FocusScope",Hg=w.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=t,[a,l]=w.useState(null),c=Xt(o),u=Xt(s),h=w.useRef(null),p=Ze(e,m=>l(m)),f=w.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;w.useEffect(()=>{if(r){let m=function(b){if(f.paused||!a)return;const P=b.target;a.contains(P)?h.current=P:Os(h.current,{select:!0})},v=function(b){if(f.paused||!a)return;const P=b.relatedTarget;P!==null&&(a.contains(P)||Os(h.current,{select:!0}))},S=function(b){if(document.activeElement===document.body)for(const C of b)C.removedNodes.length>0&&Os(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const y=new MutationObserver(S);return a&&y.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),y.disconnect()}}},[r,a,f.paused]),w.useEffect(()=>{if(a){_I.add(f);const m=document.activeElement;if(!a.contains(m)){const S=new CustomEvent(Gy,PI);a.addEventListener(Gy,c),a.dispatchEvent(S),S.defaultPrevented||(vte(Cte(MR(a)),{select:!0}),document.activeElement===m&&Os(a))}return()=>{a.removeEventListener(Gy,c),setTimeout(()=>{const S=new CustomEvent(Vy,PI);a.addEventListener(Vy,u),a.dispatchEvent(S),S.defaultPrevented||Os(m??document.body,{select:!0}),a.removeEventListener(Vy,u),_I.remove(f)},0)}}},[a,c,u,f]);const g=w.useCallback(m=>{if(!n&&!r||f.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,S=document.activeElement;if(v&&S){const y=m.currentTarget,[b,P]=xte(y);b&&P?!m.shiftKey&&S===P?(m.preventDefault(),n&&Os(b,{select:!0})):m.shiftKey&&S===b&&(m.preventDefault(),n&&Os(P,{select:!0})):S===y&&m.preventDefault()}},[n,r,f.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:p,onKeyDown:g})});Hg.displayName=Ste;function vte(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Os(r,{select:e}),document.activeElement!==n)return}function xte(t){const e=MR(t),n=CI(e,t),r=CI(e.reverse(),t);return[n,r]}function MR(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function CI(t,e){for(const n of t)if(!wte(n,{upTo:e}))return n}function wte(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function bte(t){return t instanceof HTMLInputElement&&"select"in t}function Os(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&bte(t)&&e&&t.select()}}var _I=Pte();function Pte(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=II(t,e),t.unshift(e)},remove(e){var n;t=II(t,e),(n=t[0])==null||n.resume()}}}function II(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function Cte(t){return t.filter(e=>e.tagName!=="A")}var _te="Portal",pd=w.forwardRef((t,e)=>{var a;const{container:n,...r}=t,[o,s]=w.useState(!1);ci(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Rz.createPortal(d.jsx(Ae.div,{...r,ref:e}),i):null});pd.displayName=_te;function Ite(t,e){return w.useReducer((n,r)=>e[n][r]??n,t)}var so=t=>{const{present:e,children:n}=t,r=Ete(e),o=typeof n=="function"?n({present:r.isPresent}):w.Children.only(n),s=Ze(r.ref,kte(o));return typeof n=="function"||r.isPresent?w.cloneElement(o,{ref:s}):null};so.displayName="Presence";function Ete(t){const[e,n]=w.useState(),r=w.useRef({}),o=w.useRef(t),s=w.useRef("none"),i=t?"mounted":"unmounted",[a,l]=Ite(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=hh(r.current);s.current=a==="mounted"?c:"none"},[a]),ci(()=>{const c=r.current,u=o.current;if(u!==t){const p=s.current,f=hh(c);t?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&p!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=t}},[t,l]),ci(()=>{if(e){const c=h=>{const f=hh(r.current).includes(h.animationName);h.target===e&&f&&ps.flushSync(()=>l("ANIMATION_END"))},u=h=>{h.target===e&&(s.current=hh(r.current))};return e.addEventListener("animationstart",u),e.addEventListener("animationcancel",c),e.addEventListener("animationend",c),()=>{e.removeEventListener("animationstart",u),e.removeEventListener("animationcancel",c),e.removeEventListener("animationend",c)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:w.useCallback(c=>{c&&(r.current=getComputedStyle(c)),n(c)},[])}}function hh(t){return(t==null?void 0:t.animationName)||"none"}function kte(t){var r,o;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var Yy=0;function w1(){w.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??EI()),document.body.insertAdjacentElement("beforeend",t[1]??EI()),Yy++,()=>{Yy===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),Yy--}},[])}function EI(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.cssText="outline: none; opacity: 0; position: fixed; pointer-events: none",t}var So=function(){return So=Object.assign||function(e){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},So.apply(this,arguments)};function AR(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]]);return n}function Tte(t,e,n){if(n||arguments.length===2)for(var r=0,o=e.length,s;r<o;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))}var np="right-scroll-bar-position",rp="width-before-scroll-bar",Mte="with-scroll-bars-hidden",Ate="--removed-body-scroll-bar-size";function Xy(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function jte(t,e){var n=w.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=e,n.facade}var Ote=typeof window<"u"?w.useLayoutEffect:w.useEffect,kI=new WeakMap;function Dte(t,e){var n=jte(null,function(r){return t.forEach(function(o){return Xy(o,r)})});return Ote(function(){var r=kI.get(n);if(r){var o=new Set(r),s=new Set(t),i=n.current;o.forEach(function(a){s.has(a)||Xy(a,null)}),s.forEach(function(a){o.has(a)||Xy(a,i)})}kI.set(n,t)},[t]),n}function Rte(t){return t}function Lte(t,e){e===void 0&&(e=Rte);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:t},useMedium:function(s){var i=e(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),n}}}};return o}function $te(t){t===void 0&&(t={});var e=Lte(null);return e.options=So({async:!0,ssr:!1},t),e}var jR=function(t){var e=t.sideCar,n=AR(t,["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 w.createElement(r,So({},n))};jR.isSideCarExport=!0;function Fte(t,e){return t.useMedium(e),jR}var OR=$te(),qy=function(){},Kg=w.forwardRef(function(t,e){var n=w.useRef(null),r=w.useState({onScrollCapture:qy,onWheelCapture:qy,onTouchMoveCapture:qy}),o=r[0],s=r[1],i=t.forwardProps,a=t.children,l=t.className,c=t.removeScrollBar,u=t.enabled,h=t.shards,p=t.sideCar,f=t.noIsolation,g=t.inert,m=t.allowPinchZoom,v=t.as,S=v===void 0?"div":v,y=t.gapMode,b=AR(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),P=p,C=Dte([n,e]),I=So(So({},b),o);return w.createElement(w.Fragment,null,u&&w.createElement(P,{sideCar:OR,removeScrollBar:c,shards:h,noIsolation:f,inert:g,setCallbacks:s,allowPinchZoom:!!m,lockRef:n,gapMode:y}),i?w.cloneElement(w.Children.only(a),So(So({},I),{ref:C})):w.createElement(S,So({},I,{className:l,ref:C}),a))});Kg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Kg.classNames={fullWidth:rp,zeroRight:np};var Nte=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function zte(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=Nte();return e&&t.setAttribute("nonce",e),t}function Bte(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function Ute(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Hte=function(){var t=0,e=null;return{add:function(n){t==0&&(e=zte())&&(Bte(e,n),Ute(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Kte=function(){var t=Hte();return function(e,n){w.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},DR=function(){var t=Kte(),e=function(n){var r=n.styles,o=n.dynamic;return t(r,o),null};return e},Wte={left:0,top:0,right:0,gap:0},Zy=function(t){return parseInt(t||"",10)||0},Gte=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],o=e[t==="padding"?"paddingRight":"marginRight"];return[Zy(n),Zy(r),Zy(o)]},Vte=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return Wte;var e=Gte(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},Yte=DR(),fl="data-scroll-locked",Xte=function(t,e,n,r){var o=t.left,s=t.top,i=t.right,a=t.gap;return n===void 0&&(n="margin"),`
202
- .`.concat(Mte,` {
203
- overflow: hidden `).concat(r,`;
204
- padding-right: `).concat(a,"px ").concat(r,`;
205
- }
206
- body[`).concat(fl,`] {
207
- overflow: hidden `).concat(r,`;
208
- overscroll-behavior: contain;
209
- `).concat([e&&"position: relative ".concat(r,";"),n==="margin"&&`
210
- padding-left: `.concat(o,`px;
211
- padding-top: `).concat(s,`px;
212
- padding-right: `).concat(i,`px;
213
- margin-left:0;
214
- margin-top:0;
215
- margin-right: `).concat(a,"px ").concat(r,`;
216
- `),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
217
- }
218
-
219
- .`).concat(np,` {
220
- right: `).concat(a,"px ").concat(r,`;
221
- }
222
-
223
- .`).concat(rp,` {
224
- margin-right: `).concat(a,"px ").concat(r,`;
225
- }
226
-
227
- .`).concat(np," .").concat(np,` {
228
- right: 0 `).concat(r,`;
229
- }
230
-
231
- .`).concat(rp," .").concat(rp,` {
232
- margin-right: 0 `).concat(r,`;
233
- }
234
-
235
- body[`).concat(fl,`] {
236
- `).concat(Ate,": ").concat(a,`px;
237
- }
238
- `)},TI=function(){var t=parseInt(document.body.getAttribute(fl)||"0",10);return isFinite(t)?t:0},qte=function(){w.useEffect(function(){return document.body.setAttribute(fl,(TI()+1).toString()),function(){var t=TI()-1;t<=0?document.body.removeAttribute(fl):document.body.setAttribute(fl,t.toString())}},[])},Zte=function(t){var e=t.noRelative,n=t.noImportant,r=t.gapMode,o=r===void 0?"margin":r;qte();var s=w.useMemo(function(){return Vte(o)},[o]);return w.createElement(Yte,{styles:Xte(s,!e,o,n?"":"!important")})},Ix=!1;if(typeof window<"u")try{var ph=Object.defineProperty({},"passive",{get:function(){return Ix=!0,!0}});window.addEventListener("test",ph,ph),window.removeEventListener("test",ph,ph)}catch{Ix=!1}var Ta=Ix?{passive:!1}:!1,Qte=function(t){return t.tagName==="TEXTAREA"},RR=function(t,e){var n=window.getComputedStyle(t);return n[e]!=="hidden"&&!(n.overflowY===n.overflowX&&!Qte(t)&&n[e]==="visible")},Jte=function(t){return RR(t,"overflowY")},ene=function(t){return RR(t,"overflowX")},MI=function(t,e){var n=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=LR(t,r);if(o){var s=$R(t,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},tne=function(t){var e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;return[e,n,r]},nne=function(t){var e=t.scrollLeft,n=t.scrollWidth,r=t.clientWidth;return[e,n,r]},LR=function(t,e){return t==="v"?Jte(e):ene(e)},$R=function(t,e){return t==="v"?tne(e):nne(e)},rne=function(t,e){return t==="h"&&e==="rtl"?-1:1},one=function(t,e,n,r,o){var s=rne(t,window.getComputedStyle(e).direction),i=s*r,a=n.target,l=e.contains(a),c=!1,u=i>0,h=0,p=0;do{var f=$R(t,a),g=f[0],m=f[1],v=f[2],S=m-v-s*g;(g||S)&&LR(t,a)&&(h+=S,p+=g),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(e.contains(a)||e===a));return(u&&(Math.abs(h)<1||!o)||!u&&(Math.abs(p)<1||!o))&&(c=!0),c},fh=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},AI=function(t){return[t.deltaX,t.deltaY]},jI=function(t){return t&&"current"in t?t.current:t},sne=function(t,e){return t[0]===e[0]&&t[1]===e[1]},ine=function(t){return`
239
- .block-interactivity-`.concat(t,` {pointer-events: none;}
240
- .allow-interactivity-`).concat(t,` {pointer-events: all;}
241
- `)},ane=0,Ma=[];function lne(t){var e=w.useRef([]),n=w.useRef([0,0]),r=w.useRef(),o=w.useState(ane++)[0],s=w.useState(DR)[0],i=w.useRef(t);w.useEffect(function(){i.current=t},[t]),w.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(o));var m=Tte([t.lockRef.current],(t.shards||[]).map(jI),!0).filter(Boolean);return m.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[t.inert,t.lockRef.current,t.shards]);var a=w.useCallback(function(m,v){if("touches"in m&&m.touches.length===2)return!i.current.allowPinchZoom;var S=fh(m),y=n.current,b="deltaX"in m?m.deltaX:y[0]-S[0],P="deltaY"in m?m.deltaY:y[1]-S[1],C,I=m.target,T=Math.abs(b)>Math.abs(P)?"h":"v";if("touches"in m&&T==="h"&&I.type==="range")return!1;var _=MI(T,I);if(!_)return!0;if(_?C=T:(C=T==="v"?"h":"v",_=MI(T,I)),!_)return!1;if(!r.current&&"changedTouches"in m&&(b||P)&&(r.current=C),!C)return!0;var k=r.current||C;return one(k,v,m,k==="h"?b:P,!0)},[]),l=w.useCallback(function(m){var v=m;if(!(!Ma.length||Ma[Ma.length-1]!==s)){var S="deltaY"in v?AI(v):fh(v),y=e.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&sne(C.delta,S)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var b=(i.current.shards||[]).map(jI).filter(Boolean).filter(function(C){return C.contains(v.target)}),P=b.length>0?a(v,b[0]):!i.current.noIsolation;P&&v.cancelable&&v.preventDefault()}}},[]),c=w.useCallback(function(m,v,S,y){var b={name:m,delta:v,target:S,should:y,shadowParent:cne(S)};e.current.push(b),setTimeout(function(){e.current=e.current.filter(function(P){return P!==b})},1)},[]),u=w.useCallback(function(m){n.current=fh(m),r.current=void 0},[]),h=w.useCallback(function(m){c(m.type,AI(m),m.target,a(m,t.lockRef.current))},[]),p=w.useCallback(function(m){c(m.type,fh(m),m.target,a(m,t.lockRef.current))},[]);w.useEffect(function(){return Ma.push(s),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,Ta),document.addEventListener("touchmove",l,Ta),document.addEventListener("touchstart",u,Ta),function(){Ma=Ma.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,Ta),document.removeEventListener("touchmove",l,Ta),document.removeEventListener("touchstart",u,Ta)}},[]);var f=t.removeScrollBar,g=t.inert;return w.createElement(w.Fragment,null,g?w.createElement(s,{styles:ine(o)}):null,f?w.createElement(Zte,{gapMode:t.gapMode}):null)}function cne(t){for(var e=null;t!==null;)t instanceof ShadowRoot&&(e=t.host,t=t.host),t=t.parentNode;return e}const une=Fte(OR,lne);var Wg=w.forwardRef(function(t,e){return w.createElement(Kg,So({},t,{ref:e,sideCar:une}))});Wg.classNames=Kg.classNames;var dne=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},Aa=new WeakMap,gh=new WeakMap,mh={},Qy=0,FR=function(t){return t&&(t.host||FR(t.parentNode))},hne=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=FR(n);return r&&t.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",t,". Doing nothing"),null)}).filter(function(n){return!!n})},pne=function(t,e,n,r){var o=hne(e,Array.isArray(t)?t:[t]);mh[n]||(mh[n]=new WeakMap);var s=mh[n],i=[],a=new Set,l=new Set(o),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};o.forEach(c);var u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(p){if(a.has(p))u(p);else try{var f=p.getAttribute(r),g=f!==null&&f!=="false",m=(Aa.get(p)||0)+1,v=(s.get(p)||0)+1;Aa.set(p,m),s.set(p,v),i.push(p),m===1&&g&&gh.set(p,!0),v===1&&p.setAttribute(n,"true"),g||p.setAttribute(r,"true")}catch(S){console.error("aria-hidden: cannot operate on ",p,S)}})};return u(e),a.clear(),Qy++,function(){i.forEach(function(h){var p=Aa.get(h)-1,f=s.get(h)-1;Aa.set(h,p),s.set(h,f),p||(gh.has(h)||h.removeAttribute(r),gh.delete(h)),f||h.removeAttribute(n)}),Qy--,Qy||(Aa=new WeakMap,Aa=new WeakMap,gh=new WeakMap,mh={})}},b1=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),o=dne(t);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),pne(r,o,n,"aria-hidden")):function(){return null}},P1="Dialog",[NR,Cfe]=Lo(P1),[fne,io]=NR(P1),zR=t=>{const{__scopeDialog:e,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=t,a=w.useRef(null),l=w.useRef(null),[c=!1,u]=Pi({prop:r,defaultProp:o,onChange:s});return d.jsx(fne,{scope:e,triggerRef:a,contentRef:l,contentId:as(),titleId:as(),descriptionId:as(),open:c,onOpenChange:u,onOpenToggle:w.useCallback(()=>u(h=>!h),[u]),modal:i,children:n})};zR.displayName=P1;var BR="DialogTrigger",gne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=io(BR,n),s=Ze(e,o.triggerRef);return d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":I1(o.open),...r,ref:s,onClick:oe(t.onClick,o.onOpenToggle)})});gne.displayName=BR;var C1="DialogPortal",[mne,UR]=NR(C1,{forceMount:void 0}),HR=t=>{const{__scopeDialog:e,forceMount:n,children:r,container:o}=t,s=io(C1,e);return d.jsx(mne,{scope:e,forceMount:n,children:w.Children.map(r,i=>d.jsx(so,{present:n||s.open,children:d.jsx(pd,{asChild:!0,container:o,children:i})}))})};HR.displayName=C1;var Mf="DialogOverlay",KR=w.forwardRef((t,e)=>{const n=UR(Mf,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=io(Mf,t.__scopeDialog);return s.modal?d.jsx(so,{present:r||s.open,children:d.jsx(yne,{...o,ref:e})}):null});KR.displayName=Mf;var yne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=io(Mf,n);return d.jsx(Wg,{as:oa,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ae.div,{"data-state":I1(o.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),sa="DialogContent",WR=w.forwardRef((t,e)=>{const n=UR(sa,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=io(sa,t.__scopeDialog);return d.jsx(so,{present:r||s.open,children:s.modal?d.jsx(Sne,{...o,ref:e}):d.jsx(vne,{...o,ref:e})})});WR.displayName=sa;var Sne=w.forwardRef((t,e)=>{const n=io(sa,t.__scopeDialog),r=w.useRef(null),o=Ze(e,n.contentRef,r);return w.useEffect(()=>{const s=r.current;if(s)return b1(s)},[]),d.jsx(GR,{...t,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:oe(t.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:oe(t.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:oe(t.onFocusOutside,s=>s.preventDefault())})}),vne=w.forwardRef((t,e)=>{const n=io(sa,t.__scopeDialog),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(GR,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=t.onCloseAutoFocus)==null||i.call(t,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=t.onInteractOutside)==null||l.call(t,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),GR=w.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=t,a=io(sa,n),l=w.useRef(null),c=Ze(e,l);return w1(),d.jsxs(d.Fragment,{children:[d.jsx(Hg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(hd,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":I1(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(wne,{titleId:a.titleId}),d.jsx(Pne,{contentRef:l,descriptionId:a.descriptionId})]})]})}),_1="DialogTitle",VR=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=io(_1,n);return d.jsx(Ae.h2,{id:o.titleId,...r,ref:e})});VR.displayName=_1;var YR="DialogDescription",xne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=io(YR,n);return d.jsx(Ae.p,{id:o.descriptionId,...r,ref:e})});xne.displayName=YR;var XR="DialogClose",qR=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=io(XR,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});qR.displayName=XR;function I1(t){return t?"open":"closed"}var ZR="DialogTitleWarning",[_fe,QR]=Jee(ZR,{contentName:sa,titleName:_1,docsSlug:"dialog"}),wne=({titleId:t})=>{const e=QR(ZR),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
242
-
243
- If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
244
-
245
- For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return w.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},bne="DialogDescriptionWarning",Pne=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${QR(bne).contentName}}.`;return w.useEffect(()=>{var s;const o=(s=t.current)==null?void 0:s.getAttribute("aria-describedby");e&&o&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},Cne=zR,_ne=HR,Ine=KR,Ene=WR;const Mo=w.memo(function({small:e,invertIcon:n,icon:r,color:o,className:s,...i}){const a=v1(),l=a.icons[r]??a.icons["question-mark-circle"],c=w.useRef(null);return w.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),r==="none"?d.jsx("div",{className:le("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":e},s)}):d.jsx("div",{...i,ref:c,className:le("tlui-icon",{"tlui-icon__small":e},s),style:{color:o,mask:`url(${l}) center 100% / 100% no-repeat`,transform:n?"scale(-1, 1)":void 0}})});function be({icon:t,small:e,invertIcon:n}){return d.jsx(Mo,{className:"tlui-button__icon",icon:t,small:e,invertIcon:n})}function Gg({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__header",t),children:e})}function Vg({className:t,children:e}){return d.jsx(VR,{dir:"ltr",className:le("tlui-dialog__header__title",t),children:e})}function Yg(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(qR,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon","aria-label":"Close",onTouchEnd:t=>t.target.click(),children:d.jsx(be,{small:!0,icon:"cross-2"})})})})}function Du({className:t,children:e,style:n}){return d.jsx("div",{className:le("tlui-dialog__body",t),style:n,children:e})}function E1({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__footer",t),children:e})}const Xg=w.forwardRef(function({className:e,label:n,icon:r,iconLeft:o,autoSelect:s=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:p,onBlur:f,shouldManuallyMaintainScrollPositionWhenFocused:g=!1,children:m,value:v},S){const y=F(),b=w.useRef(null);w.useImperativeHandle(S,()=>b.current);const P=Ce(),C=w.useRef(a??""),I=w.useRef(a??""),[T,_]=w.useState(!1),k=w.useCallback(O=>{_(!0);const D=O.currentTarget;I.current=D.value,y.timers.requestAnimationFrame(()=>{s&&D.select()}),p==null||p()},[s,p,y.timers]),M=w.useCallback(O=>{const D=O.currentTarget.value;I.current=D,u==null||u(D)},[u]),R=w.useCallback(O=>{switch(O.key){case"Enter":{O.currentTarget.blur(),Ot(O),c==null||c(O.currentTarget.value);break}case"Escape":{O.currentTarget.value=C.current,h==null||h(O.currentTarget.value),O.currentTarget.blur(),Ot(O);break}}},[c,h]),j=w.useCallback(O=>{_(!1);const D=O.currentTarget.value;f==null||f(D)},[f]);return w.useEffect(()=>{if(!y.environment.isIos)return;const O=window.visualViewport;if(T&&g&&O){const D=()=>{var B;(B=b.current)==null||B.scrollIntoView({block:"center"})};return O.addEventListener("resize",D),O.addEventListener("scroll",D),y.timers.requestAnimationFrame(()=>{var B;(B=b.current)==null||B.scrollIntoView({block:"center"})}),()=>{O.removeEventListener("resize",D),O.removeEventListener("scroll",D)}}},[y,T,g]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,n&&d.jsx("label",{children:P(n)}),o&&d.jsx(Mo,{icon:o,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:le("tlui-input",e),type:"text",defaultValue:a,onKeyUp:R,onChange:M,onFocus:k,onBlur:j,autoFocus:i,placeholder:l,value:v}),r&&d.jsx(Mo,{icon:r,small:!!n})]})});function OI(t){return pr.isValid(t)?{isValid:!0,hasProtocol:!0}:pr.isValid("https://"+t)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const kne=Rt(function({onClose:e}){const r=F().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(Tne,{onClose:e,selectedShape:r}):null}),Tne=Rt(function({onClose:e,selectedShape:n}){const r=F(),o=Ce(),s=w.useRef(null);w.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var g;return(g=s.current)==null?void 0:g.focus()})},[r]);const i=w.useRef(n.props.url),[a,l]=w.useState(()=>{const g=OI(n.props.url),m=g.isValid===!0?g.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:m,safe:m,valid:!0}}),c=w.useCallback(g=>{const m=g.replace(/https?:\/\/(https?:\/\/)/,(y,b)=>b),v=OI(m),S=v.isValid===!0?v.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:S,valid:v.isValid})},[]),u=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(r.updateShapes([{id:g.id,type:g.type,props:{url:""}}]),e())},[r,e]),h=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(g&&"url"in g.props&&g.props.url!==a.safe&&r.updateShapes([{id:g.id,type:g.type,props:{url:a.safe}}]),e())},[r,e,a]),p=w.useCallback(()=>{e()},[e]);if(!n)return e(),null;const f=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(Gg,{children:[d.jsx(Vg,{children:o("edit-link-dialog.title")}),d.jsx(Yg,{})]}),d.jsx(Du,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(Xg,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:p}),d.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),d.jsxs(E1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:p,onTouchEnd:p,children:d.jsx(wt,{children:o("edit-link-dialog.cancel")})}),f?d.jsx(ue,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(wt,{children:o("edit-link-dialog.clear")})}):d.jsx(ue,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(wt,{children:o("edit-link-dialog.save")})})]})]})});var Mne={};const DI=/(^\/r\/[^/]+\/?$)/,k1=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,overridePermissions:{"allow-top-navigation":!0},toEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(DI))return t},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(DI))return t}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{if(t.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!t.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${t}`},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:t=>{if(t.includes("/maps/")){const e=t.match(/@(.*),(.*),(.*)z/);let n;if(e){const[,r,o,s]=e;n=`https://${new URL(t).host.replace("www.","")}/maps/embed/v1/view?key=${Mne.NEXT_PUBLIC_GC_API_KEY}&center=${r},${o}&zoom=${s}`}else n="";return n}},fromEmbedUrl:t=>{const e=fe(t);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"),[o,s]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${o},${s},${r}z`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=fe(t),n=e&&e.pathname.match(/\/v\/(.+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:t=>{const e=fe(t),n=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=fe(t),n=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:t=>{const e=fe(t),n=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,n=t.match(e);if(n){const[r,o,s]=n;return`https://codepen.io/${o}/embed/${s}`}},fromEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,o,s]=n;return`https://codepen.io/${o}/pen/${s}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:t=>{const e=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,n=t.match(e);if(n){const[r,o]=n;return`https://scratch.mit.edu/projects/embed/${o}`}},fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,o]=n;return`https://scratch.mit.edu/projects/${o}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:t=>{const e=fe(t);if(!e)return;const n=e.hostname.replace(/^www./,"");if(n==="youtu.be")return`https://www.youtube.com/embed/${e.pathname.split("/").filter(Boolean)[0]}`;if((n==="youtube.com"||n==="m.youtube.com")&&e.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${e.searchParams.get("v")}`},fromEmbedUrl:t=>{const e=fe(t);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]}`}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:t=>{const e=fe(t),n=e==null?void 0:e.searchParams.get("cid");if(e!=null&&e.pathname.match(/\/calendar\/u\/0/)&&n){e.pathname="/calendar/embed";const r=Array.from(e.searchParams.keys());for(const o of r)e.searchParams.delete(o);return e.searchParams.set("src",n),e.href}},fromEmbedUrl:t=>{const e=fe(t),n=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&n){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const o of r)e.searchParams.delete(o);return e.searchParams.set("cid",n),e.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:t=>{const e=fe(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/pub\/?$/))){e.pathname=e.pathname.replace(/\/pub$/,"/embed");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}},fromEmbedUrl:t=>{const e=fe(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return t.split("/").pop()?t:void 0},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return t.split("/").pop()?t:void 0}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${t}?embed=true`},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:t=>{const e=fe(t);if(e&&e.hostname==="vimeo.com"&&e.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+e.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.hostname==="player.vimeo.com"){const n=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(n)return"https://vimeo.com/"+n[1]}}},{type:"excalidraw",title:"Excalidraw",hostnames:["excalidraw.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:t=>{const e=fe(t);if(e&&e.hash.match(/#room=/))return t},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.hash.match(/#room=/))return t}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:t=>{const e=fe(t);if(e&&e.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}/embed${e.pathname}?cell=*`;if(e&&e.pathname.match(/^\/d\/([^/]+)\/?$/)){const n=e.pathname.replace(/^\/d/,"");return`${e.origin}/embed${n}?cell=*`}},fromEmbedUrl:t=>{const e=fe(t);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-*`}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,toEmbedUrl:t=>{const e=fe(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${t}?embed`},fromEmbedUrl:t=>{const e=fe(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],Ane={"allow-downloads-without-user-activation":!1,"allow-downloads":!1,"allow-modals":!1,"allow-orientation-lock":!1,"allow-pointer-lock":!1,"allow-popups":!0,"allow-popups-to-escape-sandbox":!1,"allow-presentation":!1,"allow-storage-access-by-user-activation":!1,"allow-top-navigation":!1,"allow-top-navigation-by-user-activation":!1,"allow-scripts":!0,"allow-same-origin":!0,"allow-forms":!0},jne=k1.map(t=>t.type);function One(t){return jne.includes(t)}function Dne(t){return"icon"in t}function JR(){return F().getShapeUtil("embed")}function T1(){const t=JR();return e=>t?t.getEmbedDefinition(e):void 0}function Rne(){const t=JR();return t?t.getEmbedDefinitions():[]}const e3=Rt(function({onClose:e}){const n=F(),r=Ce(),o=v1(),[s,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[h,p]=w.useState(!1),f=w.useRef(-1),g=Rne(),m=T1();return d.jsxs(d.Fragment,{children:[d.jsxs(Gg,{children:[d.jsx(Vg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),d.jsx(Yg,{})]}),s?d.jsxs(d.Fragment,{children:[d.jsxs(Du,{className:"tlui-embed-dialog__enter",children:[d.jsx(Xg,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:v=>{l(v);const S=m(a);u(S&&S.definition.type===s.type?S:null),p(!1),clearTimeout(f.current),f.current=n.timers.setTimeout(()=>p(!S),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(Mo,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(E1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(wt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(ue,{type:"normal",onClick:e,children:d.jsx(wt,{children:r("embed-dialog.cancel")})}),d.jsx(ue,{type:"primary",disabled:!c,onClick:()=>{c&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageBounds().center,embed:c.definition}),e())},children:d.jsx(wt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(Du,{className:"tlui-embed-dialog__list",children:g.map(v=>{const S=One(v.type)?o.embedIcons[v.type]:Dne(v)?v.icon:void 0;return d.jsxs(ue,{type:"menu",onClick:()=>i(v),children:[d.jsx(wt,{children:v.title}),S&&d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${S})`}})]},v.type)})})})]})});var M1={exports:{}};M1.exports;(function(t){var e=function(){var n=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(l,c){if(!s[l]){s[l]={};for(var u=0;u<l.length;u++)s[l][l.charAt(u)]=u}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return n(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),h=0,p=c.length;h<p;h++){var f=c.charCodeAt(h);u[h*2]=f>>>8,u[h*2+1]=f%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var p=[];return c.forEach(function(f){p.push(n(f))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return o.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(o,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return n(c)})},_compress:function(l,c,u){if(l==null)return"";var h,p,f={},g={},m="",v="",S="",y=2,b=3,P=2,C=[],I=0,T=0,_;for(_=0;_<l.length;_+=1)if(m=l.charAt(_),Object.prototype.hasOwnProperty.call(f,m)||(f[m]=b++,g[m]=!0),v=S+m,Object.prototype.hasOwnProperty.call(f,v))S=v;else{if(Object.prototype.hasOwnProperty.call(g,S)){if(S.charCodeAt(0)<256){for(h=0;h<P;h++)I=I<<1,T==c-1?(T=0,C.push(u(I)),I=0):T++;for(p=S.charCodeAt(0),h=0;h<8;h++)I=I<<1|p&1,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=p>>1}else{for(p=1,h=0;h<P;h++)I=I<<1|p,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=0;for(p=S.charCodeAt(0),h=0;h<16;h++)I=I<<1|p&1,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=p>>1}y--,y==0&&(y=Math.pow(2,P),P++),delete g[S]}else for(p=f[S],h=0;h<P;h++)I=I<<1|p&1,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=p>>1;y--,y==0&&(y=Math.pow(2,P),P++),f[v]=b++,S=String(m)}if(S!==""){if(Object.prototype.hasOwnProperty.call(g,S)){if(S.charCodeAt(0)<256){for(h=0;h<P;h++)I=I<<1,T==c-1?(T=0,C.push(u(I)),I=0):T++;for(p=S.charCodeAt(0),h=0;h<8;h++)I=I<<1|p&1,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=p>>1}else{for(p=1,h=0;h<P;h++)I=I<<1|p,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=0;for(p=S.charCodeAt(0),h=0;h<16;h++)I=I<<1|p&1,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=p>>1}y--,y==0&&(y=Math.pow(2,P),P++),delete g[S]}else for(p=f[S],h=0;h<P;h++)I=I<<1|p&1,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=p>>1;y--,y==0&&(y=Math.pow(2,P),P++)}for(p=2,h=0;h<P;h++)I=I<<1|p&1,T==c-1?(T=0,C.push(u(I)),I=0):T++,p=p>>1;for(;;)if(I=I<<1,T==c-1){C.push(u(I));break}else T++;return C.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],p=4,f=4,g=3,m="",v=[],S,y,b,P,C,I,T,_={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)h[S]=S;for(b=0,C=Math.pow(2,2),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;switch(b){case 0:for(b=0,C=Math.pow(2,8),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;T=n(b);break;case 1:for(b=0,C=Math.pow(2,16),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;T=n(b);break;case 2:return""}for(h[3]=T,y=T,v.push(T);;){if(_.index>l)return"";for(b=0,C=Math.pow(2,g),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;switch(T=b){case 0:for(b=0,C=Math.pow(2,8),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;h[f++]=n(b),T=f-1,p--;break;case 1:for(b=0,C=Math.pow(2,16),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;h[f++]=n(b),T=f-1,p--;break;case 2:return v.join("")}if(p==0&&(p=Math.pow(2,g),g++),h[T])m=h[T];else if(T===f)m=y+y.charAt(0);else return null;v.push(m),h[f++]=y+m.charAt(0),p--,y=m,p==0&&(p=Math.pow(2,g),g++)}}};return a}();t!=null?t.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})})(M1);var Lne=M1.exports;const t3=fi(Lne),n3=()=>{},r3=w.createContext(null);function $ne({onEvent:t,children:e}){return d.jsx(r3.Provider,{value:t??n3,children:e})}function Zt(){return w.useContext(r3)??n3}async function Fne(t,e,n){var S,y,b;const{elements:r,files:o}=e,s={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:t.store.schema.serialize()},i=new Map,a=new Map,l=t.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(P=>{if(c.set(P.id,Ne()),P.boundElements!==null)for(const C of P.boundElements)C.type==="text"&&h.add(C.id)});let p=_T;for(const P of r){if(h.has(P.id))continue;const C=c.get(P.id),I={id:C,typeName:"shape",parentId:l,index:p,x:P.x,y:P.y,rotation:0,isLocked:P.locked,opacity:Nne(P.opacity),meta:{}};switch(P.angle!==0&&a.set(C,P.angle),P.groupIds&&P.groupIds.length>0?i.has(P.groupIds[0])?(S=i.get(P.groupIds[0]))==null||S.push(C):i.set(P.groupIds[0],[C]):u.push(C),P.type){case"rectangle":case"ellipse":case"diamond":{let T="",_="middle";if(P.boundElements!==null){for(const M of P.boundElements)if(M.type==="text"){const R=r.find(j=>j.id===M.id);R&&(T=R.text,_=Wne[R.textAlign])}}const k=P.backgroundColor==="transparent"?P.strokeColor:P.backgroundColor;s.shapes.push({...I,type:"geo",props:{geo:P.type,url:P.link??"",w:P.width,h:P.height,size:yh[P.strokeWidth]??"draw",color:bc[k]??"black",text:T,align:_,dash:Sh(P),fill:Yne(P)}});break}case"freedraw":{s.shapes.push({...I,type:"draw",props:{dash:Sh(P),size:yh[P.strokeWidth],color:bc[P.strokeColor]??"black",segments:[{type:"free",points:P.points.map(([T,_,k=.5])=>({x:T,y:_,z:k}))}]}});break}case"line":{if(P.points.slice().length<2)break;const _=ku(P.points.length);s.shapes.push({...I,type:"line",props:{dash:Sh(P),size:yh[P.strokeWidth],color:bc[P.strokeColor]??"black",spline:P.roundness?"cubic":"line",points:{...Object.fromEntries(P.points.map(([k,M],R)=>{const j=_[R];return[j,{id:j,index:j,x:k,y:M}]}))}}});break}case"arrow":{let T="";if(P.boundElements!==null){for(const j of P.boundElements)if(j.type==="text"){const O=r.find(D=>D.id===j.id);O&&(T=O.text)}}const _=P.points[0],k=P.points[P.points.length-1],M=c.get((y=P.startBinding)==null?void 0:y.elementId),R=c.get((b=P.endBinding)==null?void 0:b.elementId);s.shapes.push({...I,type:"arrow",props:{text:T,bend:Vne(P,_,k),dash:Sh(P),size:yh[P.strokeWidth]??"m",color:bc[P.strokeColor]??"black",start:{x:_[0],y:_[1]},end:{x:k[0],y:k[1]},arrowheadEnd:RI[P.endArrowhead]??"none",arrowheadStart:RI[P.startArrowhead]??"none"}}),M&&s.bindings.push({id:Wi(),typeName:"binding",type:"arrow",fromId:C,toId:M,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),R&&s.bindings.push({id:Wi(),typeName:"binding",type:"arrow",fromId:C,toId:R,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:T,scale:_}=Bne(P.fontSize);s.shapes.push({...I,type:"text",props:{size:T,scale:_,font:Une[P.fontFamily]??"draw",color:bc[P.strokeColor]??"black",text:P.text,textAlign:Gne[P.textAlign]}});break}case"image":{const T=o[P.fileId];if(!T)break;const _=Ns.createId();s.assets.push({id:_,typeName:"asset",type:"image",props:{w:P.width,h:P.height,fileSize:T.size,name:P.id??"Untitled",isAnimated:!1,mimeType:T.mimeType,src:T.dataURL},meta:{}}),s.shapes.push({...I,type:"image",props:{w:P.width,h:P.height,assetId:_}})}}p=vo(p)}const f=n??(t.inputs.shiftKey?t.inputs.currentPagePoint:void 0);t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(s,{point:f,select:!1,preserveIds:!0});for(const P of i.values())if(P.length>1){t.groupShapes(P);const C=t.getShape(P[0]);C!=null&&C.parentId&&Rn(C.parentId)&&u.push(C.parentId)}for(const[P,C]of a)t.select(P),t.rotateShapesBy([P],C);const g=ye(u.map(P=>t.getShape(P))),m=Z.Common(g.map(P=>t.getShapePageBounds(P))),v=t.getViewportPageBounds().center;t.updateShapes(g.map(P=>{const C={x:(P.x??0)-(m.x+m.w/2),y:(P.y??0)-(m.y+m.h/2)};return{id:P.id,type:P.type,x:v.x+C.x,y:v.y+C.y}})),t.setSelectedShapes(u)}const Nne=t=>{const e=t/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},yh={1:"s",2:"m",3:"l",4:"xl"},zne={16:"s",20:"m",28:"l",36:"xl"};function Bne(t){const e=zne[t];return e?{size:e,scale:1}:t<16?{size:"s",scale:t/16}:t>36?{size:"xl",scale:t/36}:{size:"m",scale:1}}const Une={1:"draw",2:"sans",3:"mono"},bc={"#ffffff":"grey","#000000":"black","#343a40":"black","#495057":"grey","#c92a2a":"red","#a61e4d":"light-red","#862e9c":"violet","#5f3dc4":"light-violet","#364fc7":"blue","#1864ab":"light-blue","#0b7285":"light-green","#087f5b":"light-green","#2b8a3e":"green","#5c940d":"light-green","#e67700":"yellow","#d9480f":"orange","#ced4da":"grey","#868e96":"grey","#fa5252":"light-red","#e64980":"red","#be4bdb":"light-violet","#7950f2":"violet","#4c6ef5":"blue","#228be6":"light-blue","#15aabf":"light-green","#12b886":"green","#40c057":"green","#82c91e":"light-green","#fab005":"yellow","#fd7e14":"orange","#212529":"grey"},Hne={solid:"draw",dashed:"dashed",dotted:"dotted"},Kne={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Wne={left:"start",center:"middle",right:"end"},Gne={left:"start",center:"middle",right:"end"},RI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Vne(t,e,n){let r=0;if(t.points.length>2){const o=new x(e[0],e[1]),s=new x(n[0],n[1]),i=new x(t.points[1][0],t.points[1][1]),a=x.Sub(s,o),l=x.Per(a),c=x.Med(s,o),u=x.Sub(c,l),h=x.Add(c,l),p=x.NearestPointOnLineSegment(u,h,i,!1);r=x.Dist(p,c),x.Clockwise(p,s,c)&&(r*=-1)}return r}const Sh=t=>{let e=Hne[t.strokeStyle]??"draw";return e==="draw"&&t.roughness===0&&(e="solid"),e},Yne=t=>t.backgroundColor==="transparent"?"none":Kne[t.fillStyle]??"solid";async function Xne(t,e,n,r){const s=(await Promise.all(e.map(async i=>await(await Jr(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"files",files:s,point:n,ignoreParent:!1,sources:r}),e.forEach(i=>URL.revokeObjectURL(i))}function qne(t,e,n){const r=t.getSelectionPageBounds();t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(e,{point:n,select:!0});const o=t.getSelectionPageBounds();r&&o&&(r!=null&&r.collides(o))&&(t.updateInstanceState({isChangingStyle:!0}),t.timers.setTimeout(()=>{t.updateInstanceState({isChangingStyle:!1})},150))}async function Ex(t,e,n,r){return t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"url",point:n,url:e,sources:r})}function Zne(t){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t.trim(),e.body.textContent||e.body.innerText||""}const Qne=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},Jne=t=>{const e=t.split(/[\n\s]/);for(const n of e)try{const r=new URL(n);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return UA(e)},ere=t=>/^<svg/.test(t),tre=["input","select","textarea"];function Jy(t){const{activeElement:e}=document;return t.getIsMenuOpen()||e&&(e.getAttribute("contenteditable")||tre.indexOf(e.tagName.toLowerCase())>-1)}const nre=t=>t.types.find(e=>e.match(/^image\//)),eS=(t,e,n,r)=>{const o=Jne(e);if(o)for(const s of o)Ex(t,s,n);else Qne(e)?Ex(t,e,n):ere(e)?(t.markHistoryStoppingPoint("paste"),t.putExternalContent({type:"svg-text",text:e,point:n,sources:r})):(t.markHistoryStoppingPoint("paste"),t.putExternalContent({type:"text",text:e,point:n,sources:r}))},rre=async(t,e,n)=>{if(t.getEditingShapeId()!==null)return;if(!e)throw Error("No clipboard data");const r=[];for(const o of Object.values(e.items))switch(o.kind){case"file":{r.push({type:"file",source:new Promise(s=>s(o.getAsFile()))});break}case"string":{o.type==="text/html"?r.push({type:"html",source:new Promise(s=>o.getAsString(s))}):o.type==="text/plain"?r.push({type:"text",source:new Promise(s=>o.getAsString(s))}):r.push({type:o.type,source:new Promise(s=>o.getAsString(s))});break}}s3(t,r,n)},o3=async(t,e,n)=>{const r=[];for(const o of e){if(nre(o))for(const s of o.types)s.match(/^image\//)&&r.push({type:"blob",source:o.getType(s)});o.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const s=await o.getType("text/html");return await rs.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await rs.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await rs.blobToText(s)})()})}return await s3(t,r,n)};async function s3(t,e,n){const r=e.filter(s=>(s.type==="file"||s.type==="blob")&&s.source!==null);if(r.length){if(r.length>t.options.maxFilesAtOnce)throw Error("Too many files");const i=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await Xne(t,i,n)}const o=await Promise.all(e.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=t3.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(h);if(p.type!=="application/tldraw"&&i({type:"error",data:p,reason:`found tldraw data comment but JSON was of a different type: ${p.type}`}),typeof p.data=="string"){i({type:"error",data:p,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:p.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const h=JSON.parse(l);if(h.type==="excalidraw/clipboard"){i({type:"excalidraw",data:h});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){qne(t,s.data,n);return}for(const s of o)if(s.type==="excalidraw"){Fne(t,s.data,n);return}for(const s of o)if(s.type==="text"&&s.subtype==="html"){const a=new DOMParser().parseFromString(s.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");eS(t,c,n,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){eS(t,Zne(s.data),n,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Ex(t,s.data,n,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){eS(t,s.data,n,o);return}}const Af=async t=>{var r;const e=await t.resolveAssetsInContent(t.getContentFromCurrentPage(t.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=t3.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:e}));if(!(typeof navigator>"u")){const o=e.shapes.map(s=>t.getShapeUtil(s).getText(s)).filter(N9);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<div data-tldraw>${n}</div>`],{type:"text/html"});let i=o.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":s,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<div data-tldraw>${n}</div>`)}};function ore(){const t=F(),e=Zt(),n=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Af(t),e("copy",{source:i}))},[t,e]),r=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Af(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:i}))},[t,e]),o=w.useCallback(async function(i,a,l){t.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(o3(t,i,l),e("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{o(c,a,l)}))},[t,e]);return{copy:n,cut:r,paste:o}}function sre(){const t=F(),e=Zt(),n=U("editor.isFocused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!n)return;const r=async l=>{t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||Jy(t)||(we(l),await Af(t),e("copy",{source:"kbd"}))};async function o(l){t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||Jy(t)||(we(l),await Af(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,t.timers.requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){Ot(l);return}if(t.getEditingShapeId()!==null||Jy(t))return;let c,u=!1;t.inputs.shiftKey&&(u=!0),t.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=t.inputs.currentPagePoint),l.clipboardData&&!t.inputs.shiftKey?rre(t,l.clipboardData,c):navigator.clipboard.read().then(h=>{Array.isArray(h)&&h[0]instanceof ClipboardItem&&o3(t,h,c)}),we(l),e("paste",{source:"kbd"})};return document.addEventListener("copy",r),document.addEventListener("cut",o),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",o),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[t,e,n])}/*!
246
- * canvas-size
247
- * v1.2.6
248
- * https://github.com/jhildenbiddle/canvas-size
249
- * (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
250
- * MIT license
251
- */function ire(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,o,s,i,a=[],l=!0,c=!1;try{if(s=(n=n.call(t)).next,e===0){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=s.call(n)).done)&&(a.push(r.value),a.length!==e);l=!0);}catch(u){c=!0,o=u}finally{try{if(!l&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function LI(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function er(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?LI(Object(n),!0).forEach(function(r){are(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):LI(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function are(t,e,n){return e=mre(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function lre(t,e){if(t==null)return{};var n={},r=Object.keys(t),o,s;for(s=0;s<r.length;s++)o=r[s],!(e.indexOf(o)>=0)&&(n[o]=t[o]);return n}function cre(t,e){if(t==null)return{};var n=lre(t,e),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(o=0;o<s.length;o++)r=s[o],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function $I(t,e){return dre(t)||ire(t,e)||i3(t,e)||fre()}function vh(t){return ure(t)||hre(t)||i3(t)||pre()}function ure(t){if(Array.isArray(t))return kx(t)}function dre(t){if(Array.isArray(t))return t}function hre(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function i3(t,e){if(t){if(typeof t=="string")return kx(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return kx(t,e)}}function kx(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function pre(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
252
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fre(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
253
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function gre(t,e){if(typeof t!="object"||t===null)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function mre(t){var e=gre(t,"string");return typeof e=="symbol"?e:String(e)}function ru(t){var e=t.sizes.shift(),n=Math.max(Math.ceil(e[0]),1),r=Math.max(Math.ceil(e[1]),1),o=[n-1,r-1,1,1],s=Date.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,l;i?(a=new OffscreenCanvas(1,1),l=new OffscreenCanvas(n,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,l=document.createElement("canvas"),l.width=n,l.height=r);var c=a.getContext("2d"),u=l.getContext("2d");u&&(u.fillRect.apply(u,o),c.drawImage(l,n-1,r-1,1,1,0,0,1,1));var h=c&&c.getImageData(0,0,1,1).data[3]!==0,p=Date.now()-s;return[a,l].forEach(function(f){f.height=0,f.width=0}),i?(postMessage({width:n,height:r,benchmark:p,isTestPass:h}),!h&&t.sizes.length&&ru(t)):h?t.onSuccess(n,r,p):(t.onError(n,r,p),t.sizes.length&&ru(t)),h}var tS={area:[16384,14188,11402,11180,10836,8192,4096,1],height:[8388607,65535,32767,16384,8192,4096,1],width:[4194303,65535,32767,16384,8192,4096,1]},yre=["onError","onSuccess"],el={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},Pc={};function nS(t){var e=t.width===t.height,n=t.height===1,r=t.width===1,o=[];if(!t.width||!t.height)t.sizes.forEach(function(u){var h=e||n?u:1,p=e||r?u:1;o.push([h,p])});else for(var s=t.min||el.min,i=t.step||el.step,a=Math.max(t.width,t.height);a>=s;){var l=e||n?a:1,c=e||r?a:1;o.push([l,c]),a-=i}return o}function xh(t){var e=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),o=t.onError,s=t.onSuccess,i=cre(t,yre),a=null;if(!e)return!1;if(t.useWorker&&n){var l=`
254
- var canvasTest = `.concat(ru.toString(),`;
255
- onmessage = function(e) {
256
- canvasTest(e.data);
257
- };
258
- `),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(h){var p=h.data,f=p.width,g=p.height,m=p.benchmark,v=p.isTestPass;v?(Pc[r].onSuccess(f,g,m),delete Pc[r]):Pc[r].onError(f,g,m)}}if(t.usePromise)return new Promise(function(h,p){var f=er(er({},t),{},{onError:function(S,y,b){var P;if(t.sizes.length===0)P=!0;else{var C=t.sizes.slice(-1),I=$I(C,1),T=$I(I[0],2),_=T[0],k=T[1];P=S===_&&y===k}o(S,y,b),P&&p({width:S,height:y,benchmark:b})},onSuccess:function(S,y,b){s(S,y,b),h({width:S,height:y,benchmark:b})}});if(a){var g=f.onError,m=f.onSuccess;Pc[r]={onError:g,onSuccess:m},a.postMessage(i)}else ru(f)});if(a)Pc[r]={onError:o,onSuccess:s},a.postMessage(i);else return ru(t)}var rS={maxArea:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=nS({width:e.max,height:e.max,min:e.min,step:e.step,sizes:vh(tS.area)}),r=er(er(er({},el),e),{},{sizes:n});return xh(r)},maxHeight:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=nS({width:1,height:e.max,min:e.min,step:e.step,sizes:vh(tS.height)}),r=er(er(er({},el),e),{},{sizes:n});return xh(r)},maxWidth:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=nS({width:e.max,height:1,min:e.min,step:e.step,sizes:vh(tS.width)}),r=er(er(er({},el),e),{},{sizes:n});return xh(r)},test:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=er(er({},el),e);return n.sizes=vh(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),xh(n)}};let oS=null;function Sre(){return oS||(oS=vre()),oS}async function vre(){const t=await rS.maxWidth({usePromise:!0}),e=await rS.maxHeight({usePromise:!0}),n=await rS.maxArea({usePromise:!0});return{maxWidth:t.width,maxHeight:e.height,maxArea:n.width*n.height}}const FI=8192,xre=4096*4096;async function wre(t,e){if(t<=FI&&e<=FI&&t*e<=xre)return[t,e];const{maxWidth:n,maxHeight:r,maxArea:o}=await Sre(),s=t/e;if(t>n&&(t=n,e=t/s),e>r&&(e=r,t=e*s),t*e>o){const i=Math.sqrt(o/(t*e));t*=i,e*=i}return[t,e]}async function a3(t,e,n){const{type:r,quality:o,scale:s,width:i,height:a}=n;let[l,c]=await wre(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,h=await rs.blobToDataUrl(new Blob([e],{type:"image/svg+xml"})),p=await new Promise(g=>{const m=Iu();m.crossOrigin="anonymous",m.onload=async()=>{t.environment.isSafari&&await Rv(250);const v=document.createElement("canvas"),S=v.getContext("2d");v.width=l,v.height=c,S.imageSmoothingEnabled=!0,S.imageSmoothingQuality="high",S.drawImage(m,0,0,l,c),URL.revokeObjectURL(h),g(v)},m.onerror=()=>{g(null)},m.src=h});if(!p)return null;const f=await new Promise(g=>p.toBlob(m=>{(!m||xt.throwToBlob.get())&&g(null),g(m)},"image/"+r,o));if(!f)return null;if(r==="png"){const g=new DataView(await f.arrayBuffer());return yo.setPhysChunk(g,u,{type:"image/"+r})}else return f}async function l3(t,e,n){const r=await t.getSvgString(e!=null&&e.length?e:[...t.getCurrentPageShapeIds()],{scale:1,background:t.getInstanceState().exportBackground,...n});if(!r)throw new Error("Could not construct SVG.");return r}async function Tx(t,e,n,r={}){var o;switch(n){case"svg":return(o=await l3(t,e,r))==null?void 0:o.svg;case"json":{const s=await t.resolveAssetsInContent(t.getContentFromCurrentPage(e));return JSON.stringify(s)}default:Tt(n)}}async function c3({editor:t,ids:e,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await Tx(t,e,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Tx(t,e,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await l3(t,e,r);if(!o)throw new Error("Could not construct image.");const s=await a3(t,o.svg,{type:n,quality:1,scale:2,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:Tt(n)}}const bre={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function Pre(t,e,n,r={}){return{blobPromise:c3({editor:t,ids:e,format:n,opts:r}),mimeType:bre[n]}}function Cre(t,e,n="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=Pre(t,e,n,r);return o.catch(i=>{console.error(i)}),window.navigator.clipboard.write([new ClipboardItem({[s]:o})]).catch(i=>(console.error(i),o.then(a=>window.navigator.clipboard.write([new ClipboardItem({[s]:a})]))))}switch(n){case"json":case"svg":return _re(async()=>Tx(t,e,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Tt(n)}}async function _re(t){var e,n;await((n=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:n.call(e,await t()))}function qg(t){const e=t+"CollectionProvider",[n,r]=Lo(e),[o,s]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:g,children:m}=f,v=Ie.useRef(null),S=Ie.useRef(new Map).current;return d.jsx(o,{scope:g,itemMap:S,collectionRef:v,children:m})};i.displayName=e;const a=t+"CollectionSlot",l=Ie.forwardRef((f,g)=>{const{scope:m,children:v}=f,S=s(a,m),y=Ze(g,S.collectionRef);return d.jsx(oa,{ref:y,children:v})});l.displayName=a;const c=t+"CollectionItemSlot",u="data-radix-collection-item",h=Ie.forwardRef((f,g)=>{const{scope:m,children:v,...S}=f,y=Ie.useRef(null),b=Ze(g,y),P=s(c,m);return Ie.useEffect(()=>(P.itemMap.set(y,{ref:y,...S}),()=>void P.itemMap.delete(y))),d.jsx(oa,{[u]:"",ref:b,children:v})});h.displayName=c;function p(f){const g=s(t+"CollectionConsumer",f);return Ie.useCallback(()=>{const v=g.collectionRef.current;if(!v)return[];const S=Array.from(v.querySelectorAll(`[${u}]`));return Array.from(g.itemMap.values()).sort((P,C)=>S.indexOf(P.ref.current)-S.indexOf(C.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},p,r]}var Ire="VisuallyHidden",A1=w.forwardRef((t,e)=>d.jsx(Ae.span,{...t,ref:e,style:{position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal",...t.style}}));A1.displayName=Ire;var j1="ToastProvider",[O1,Ere,kre]=qg("Toast"),[u3,Ife]=Lo("Toast",[kre]),[Tre,Zg]=u3(j1),d3=t=>{const{__scopeToast:e,label:n="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=t,[a,l]=w.useState(null),[c,u]=w.useState(0),h=w.useRef(!1),p=w.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${j1}\`. Expected non-empty \`string\`.`),d.jsx(O1.Provider,{scope:e,children:d.jsx(Tre,{scope:e,label:n,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:w.useCallback(()=>u(f=>f+1),[]),onToastRemove:w.useCallback(()=>u(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:p,children:i})})};d3.displayName=j1;var h3="ToastViewport",Mre=["F8"],Mx="toast.viewportPause",Ax="toast.viewportResume",p3=w.forwardRef((t,e)=>{const{__scopeToast:n,hotkey:r=Mre,label:o="Notifications ({hotkey})",...s}=t,i=Zg(h3,n),a=Ere(n),l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),h=w.useRef(null),p=Ze(e,h,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=i.toastCount>0;w.useEffect(()=>{const v=S=>{var b;r.every(P=>S[P]||S.code===P)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r]),w.useEffect(()=>{const v=l.current,S=h.current;if(g&&v&&S){const y=()=>{if(!i.isClosePausedRef.current){const I=new CustomEvent(Mx);S.dispatchEvent(I),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const I=new CustomEvent(Ax);S.dispatchEvent(I),i.isClosePausedRef.current=!1}},P=I=>{!v.contains(I.relatedTarget)&&b()},C=()=>{v.contains(document.activeElement)||b()};return v.addEventListener("focusin",y),v.addEventListener("focusout",P),v.addEventListener("pointermove",y),v.addEventListener("pointerleave",C),window.addEventListener("blur",y),window.addEventListener("focus",b),()=>{v.removeEventListener("focusin",y),v.removeEventListener("focusout",P),v.removeEventListener("pointermove",y),v.removeEventListener("pointerleave",C),window.removeEventListener("blur",y),window.removeEventListener("focus",b)}}},[g,i.isClosePausedRef]);const m=w.useCallback(({tabbingDirection:v})=>{const y=a().map(b=>{const P=b.ref.current,C=[P,...Hre(P)];return v==="forwards"?C:C.reverse()});return(v==="forwards"?y.reverse():y).flat()},[a]);return w.useEffect(()=>{const v=h.current;if(v){const S=y=>{var C,I,T;const b=y.altKey||y.ctrlKey||y.metaKey;if(y.key==="Tab"&&!b){const _=document.activeElement,k=y.shiftKey;if(y.target===v&&k){(C=c.current)==null||C.focus();return}const j=m({tabbingDirection:k?"backwards":"forwards"}),O=j.findIndex(D=>D===_);sS(j.slice(O+1))?y.preventDefault():k?(I=c.current)==null||I.focus():(T=u.current)==null||T.focus()}};return v.addEventListener("keydown",S),()=>v.removeEventListener("keydown",S)}},[a,m]),d.jsxs(yte,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&d.jsx(jx,{ref:c,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"forwards"});sS(v)}}),d.jsx(O1.Slot,{scope:n,children:d.jsx(Ae.ol,{tabIndex:-1,...s,ref:p})}),g&&d.jsx(jx,{ref:u,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"backwards"});sS(v)}})]})});p3.displayName=h3;var f3="ToastFocusProxy",jx=w.forwardRef((t,e)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=t,s=Zg(f3,n);return d.jsx(A1,{"aria-hidden":!0,tabIndex:0,...o,ref:e,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=s.viewport)!=null&&c.contains(a))&&r()}})});jx.displayName=f3;var Qg="Toast",Are="toast.swipeStart",jre="toast.swipeMove",Ore="toast.swipeCancel",Dre="toast.swipeEnd",g3=w.forwardRef((t,e)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=t,[a=!0,l]=Pi({prop:r,defaultProp:o,onChange:s});return d.jsx(so,{present:n||a,children:d.jsx($re,{open:a,...i,ref:e,onClose:()=>l(!1),onPause:Xt(t.onPause),onResume:Xt(t.onResume),onSwipeStart:oe(t.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:oe(t.onSwipeMove,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:oe(t.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:oe(t.onSwipeEnd,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});g3.displayName=Qg;var[Rre,Lre]=u3(Qg,{onClose(){}}),$re=w.forwardRef((t,e)=>{const{__scopeToast:n,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:p,onSwipeEnd:f,...g}=t,m=Zg(Qg,n),[v,S]=w.useState(null),y=Ze(e,D=>S(D)),b=w.useRef(null),P=w.useRef(null),C=o||m.duration,I=w.useRef(0),T=w.useRef(C),_=w.useRef(0),{onToastAdd:k,onToastRemove:M}=m,R=Xt(()=>{var B;(v==null?void 0:v.contains(document.activeElement))&&((B=m.viewport)==null||B.focus()),i()}),j=w.useCallback(D=>{!D||D===1/0||(window.clearTimeout(_.current),I.current=new Date().getTime(),_.current=window.setTimeout(R,D))},[R]);w.useEffect(()=>{const D=m.viewport;if(D){const B=()=>{j(T.current),c==null||c()},z=()=>{const K=new Date().getTime()-I.current;T.current=T.current-K,window.clearTimeout(_.current),l==null||l()};return D.addEventListener(Mx,z),D.addEventListener(Ax,B),()=>{D.removeEventListener(Mx,z),D.removeEventListener(Ax,B)}}},[m.viewport,C,l,c,j]),w.useEffect(()=>{s&&!m.isClosePausedRef.current&&j(C)},[s,C,m.isClosePausedRef,j]),w.useEffect(()=>(k(),()=>M()),[k,M]);const O=w.useMemo(()=>v?b3(v):null,[v]);return m.viewport?d.jsxs(d.Fragment,{children:[O&&d.jsx(Fre,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:O}),d.jsx(Rre,{scope:n,onClose:R,children:ps.createPortal(d.jsx(O1.ItemSlot,{scope:n,children:d.jsx(mte,{asChild:!0,onEscapeKeyDown:oe(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||R(),m.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(Ae.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":m.swipeDirection,...g,ref:y,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:oe(t.onKeyDown,D=>{D.key==="Escape"&&(a==null||a(D.nativeEvent),D.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,R()))}),onPointerDown:oe(t.onPointerDown,D=>{D.button===0&&(b.current={x:D.clientX,y:D.clientY})}),onPointerMove:oe(t.onPointerMove,D=>{if(!b.current)return;const B=D.clientX-b.current.x,z=D.clientY-b.current.y,K=!!P.current,N=["left","right"].includes(m.swipeDirection),H=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,Y=N?H(0,B):0,ee=N?0:H(0,z),ce=D.pointerType==="touch"?10:2,ge={x:Y,y:ee},Te={originalEvent:D,delta:ge};K?(P.current=ge,wh(jre,h,Te,{discrete:!1})):NI(ge,m.swipeDirection,ce)?(P.current=ge,wh(Are,u,Te,{discrete:!1}),D.target.setPointerCapture(D.pointerId)):(Math.abs(B)>ce||Math.abs(z)>ce)&&(b.current=null)}),onPointerUp:oe(t.onPointerUp,D=>{const B=P.current,z=D.target;if(z.hasPointerCapture(D.pointerId)&&z.releasePointerCapture(D.pointerId),P.current=null,b.current=null,B){const K=D.currentTarget,N={originalEvent:D,delta:B};NI(B,m.swipeDirection,m.swipeThreshold)?wh(Dre,f,N,{discrete:!0}):wh(Ore,p,N,{discrete:!0}),K.addEventListener("click",H=>H.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),Fre=t=>{const{__scopeToast:e,children:n,...r}=t,o=Zg(Qg,e),[s,i]=w.useState(!1),[a,l]=w.useState(!1);return Bre(()=>i(!0)),w.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(pd,{asChild:!0,children:d.jsx(A1,{...r,children:s&&d.jsxs(d.Fragment,{children:[o.label," ",n]})})})},Nre="ToastTitle",m3=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});m3.displayName=Nre;var zre="ToastDescription",y3=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});y3.displayName=zre;var S3="ToastAction",v3=w.forwardRef((t,e)=>{const{altText:n,...r}=t;return n.trim()?d.jsx(w3,{altText:n,asChild:!0,children:d.jsx(D1,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${S3}\`. Expected non-empty \`string\`.`),null)});v3.displayName=S3;var x3="ToastClose",D1=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t,o=Lre(x3,n);return d.jsx(w3,{asChild:!0,children:d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,o.onClose)})})});D1.displayName=x3;var w3=w.forwardRef((t,e)=>{const{__scopeToast:n,altText:r,...o}=t;return d.jsx(Ae.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...o,ref:e})});function b3(t){const e=[];return Array.from(t.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),Ure(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",s=r.dataset.radixToastAnnounceExclude==="";if(!o)if(s){const i=r.dataset.radixToastAnnounceAlt;i&&e.push(i)}else e.push(...b3(r))}}),e}function wh(t,e,n,{discrete:r}){const o=n.originalEvent.currentTarget,s=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e&&o.addEventListener(t,e,{once:!0}),r?x1(o,s):o.dispatchEvent(s)}var NI=(t,e,n=0)=>{const r=Math.abs(t.x),o=Math.abs(t.y),s=r>o;return e==="left"||e==="right"?s&&r>n:!s&&o>n};function Bre(t=()=>{}){const e=Xt(t);ci(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[e])}function Ure(t){return t.nodeType===t.ELEMENT_NODE}function Hre(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function sS(t){const e=document.activeElement;return t.some(n=>n===e?!0:(n.focus(),document.activeElement!==e))}var Kre=g3,Wre=m3,Gre=y3,Vre=v3,zI=D1;const P3=w.createContext(null);function Yre({children:t}){const[e,n]=w.useState([]),r=w.useCallback(i=>{const a=i.id??Ke();return n(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=w.useCallback(i=>(n(a=>a.filter(l=>l.id!==i)),i),[]),s=w.useCallback(()=>{n(()=>[])},[]);return d.jsx(d3,{children:d.jsx(P3.Provider,{value:{toasts:e,addToast:r,removeToast:o,clearToasts:s},children:t})})}function ao(){const t=w.useContext(P3);if(!t)throw new Error("useToasts must be used within a ToastsProvider");return t}function Xre(){const t=F(),{addToast:e}=ao(),n=Ce();return w.useCallback((r,o="svg")=>{Cre(t,r,o).catch(()=>{e({id:"copy-fail",severity:"warning",title:n("toast.error.copy-fail.title"),description:n("toast.error.copy-fail.desc")})})},[t,e,n])}async function qre(t,e,n="png",r,o={}){if(!r&&(r=`shapes at ${BI()}`,e.length===1)){const a=t.getShape(e[0]);t.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${BI()}`}r+=`.${n}`;const s=await c3({editor:t,ids:e,format:n,opts:o}),i=new File([s],r,{type:s.type});Zre(i)}function BI(){const t=new Date,e=String(t.getFullYear()).slice(2),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0"),s=String(t.getMinutes()).padStart(2,"0"),i=String(t.getSeconds()).padStart(2,"0");return`${e}-${n}-${r} ${o}.${s}.${i}`}function Zre(t){const e=document.createElement("a"),n=URL.createObjectURL(t);e.href=n,e.download=t.name,e.click(),URL.revokeObjectURL(n)}function Qre(){const t=F(),{addToast:e}=ao(),n=Ce();return w.useCallback((r,o="png",s)=>{qre(t,r,o,s,{scale:1,background:t.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),e({id:"export-fail",title:n("toast.error.export-fail.title"),description:n("toast.error.export-fail.desc"),severity:"error"})})},[t,e,n])}async function Jre(t,e,n){const r=ye(e.map(a=>{const l=t.getShape(a);if(!(!l||t.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||t.isShapeOfType(a,"image"))return}const o=[];if(n!==void 0){const a=r.map(l=>({shape:l,bounds:t.getShapeMaskedPageBounds(l).clone().expandBy(n)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){o[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of o)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||o.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Z.Common(r.map(l=>t.getShapeMaskedPageBounds(l)));o.push({shapes:r,bounds:a})}const s=t.options.flattenImageBoundsPadding;for(const a of o){n!==void 0&&a.bounds.expandBy(-n);const l=await t.getSvgString(a.shapes,{padding:s});if(!(l!=null&&l.svg))continue;const c=new Blob([l.svg],{type:"image/svg+xml"}),u=await t.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});u&&(a.asset=u)}const i=[];return _o(()=>{for(const a of o){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=t.findCommonAncestor(u)??t.getCurrentPageId();if(!h)continue;let p="a1";for(const S of u)if(S.parentId===h){S.index>p&&(p=S.index);break}let f,g,m;if(Rn(h)){const S=t.getShape(h);if(!S)continue;const y=t.getPointInShapeSpace(S,{x:c.x,y:c.y});m=t.getShapePageTransform(h).rotation(),y.sub(new x(s,s).rot(-m)),f=y.x,g=y.y}else f=c.x-s,g=c.y-s,m=0;t.deleteShapes(u),t.createAssets([{...l,id:l.id}]);const v=Ne();t.createShape({id:v,type:"image",index:p,parentId:h,x:f,y:g,rotation:-m,props:{assetId:l.id,w:c.w+s*2,h:c.h+s*2}}),i.push(v)}}),i}const C3=Ie.createContext([]);function _3(){const t=F(),e=w.useRef(),n=Bs(Ie.useContext(C3));return w.useEffect(()=>{const r=window.document.createElement("input");r.type="file",r.accept=(n==null?void 0:n.join(","))??f9,r.multiple=!0,e.current=r;async function o(s){const i=s.target.files;!i||i.length===0||(t.markHistoryStoppingPoint("insert media"),await t.putExternalContent({type:"files",files:Array.from(i),point:t.getViewportPageBounds().center,ignoreParent:!1}),r.value="")}return r.addEventListener("change",o),()=>{e.current=void 0,r.removeEventListener("change",o)}},[t,n]),w.useCallback(()=>{var r;(r=e.current)==null||r.click()},[e])}function Jg(){return F().store.props.collaboration!==void 0}function eoe(){const t=F();return U("sync status",()=>{var e;return(e=t.store.props.collaboration)!=null&&e.status?t.store.props.collaboration.status.get():null},[t])}function toe(){const t=F(),e=w.useRef(null),n=w.useRef(null);return w.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(S,y)=>{S&&(S.innerHTML=""),y&&document.head.contains(y)&&document.head.removeChild(y),S&&document.body.contains(S)&&document.body.removeChild(S)};i(e.current,n.current),e.current=o,n.current=s;const a=`tl-print-surface-${Ke()}`;o.className=a,s.innerHTML=`
259
- .${a} {
260
- display: none;
261
- }
262
-
263
- .${a} svg {
264
- max-width: 100%;
265
- height: 100%;
266
- display: block;
267
- }
268
-
269
- @media print {
270
- html, body {
271
- min-height: 100%;
272
- height: 100%;
273
- margin: 0;
274
- }
275
-
276
- body {
277
- position: relative;
278
- }
279
-
280
- body > * {
281
- display: none;
282
- }
283
-
284
- .tldraw__editor {
285
- display: none;
286
- }
287
-
288
- .${a} {
289
- display: block !important;
290
- background: white;
291
- min-height: 100%;
292
- height: 100%;
293
- max-width: 100%;
294
- }
295
-
296
- .${a}__item {
297
- padding: 10mm;
298
- display: flex;
299
- min-height: 100%;
300
- flex-direction: column;
301
- page-break-after: always;
302
- position: relative;
303
- overflow: hidden;
304
- height: 100%;
305
- }
306
-
307
- .${a}__item__main {
308
- flex: 1;
309
- display: flex;
310
- align-items: center;
311
- justify-content: center;
312
- max-height: 100%;
313
- }
314
-
315
- .${a}__item__header {
316
- display: none;
317
- }
318
-
319
- .${a}__item__footer {
320
- display: none;
321
- text-align: right;
322
- }
323
-
324
- .${a}__item__footer__hide {
325
- display: none;
326
- }
327
-
328
-
329
- }
330
-
331
- `;const l=()=>{document.head.appendChild(s),document.body.appendChild(o)},c=()=>{t.once("tick",()=>{i(o,s)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(S,y,b){try{o.innerHTML+=`<div class="${a}__item">
332
- <div class="${a}__item__header">
333
- ${S.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
334
- </div>
335
- <div class="${a}__item__main">
336
- ${b}
337
- </div>
338
- <div class="${a}__item__footer ${a}__item__footer__${y?"":"hide"}">
339
- ${y??""}
340
- </div>
341
- </div>`}catch(P){console.error(P)}}function h(){t.environment.isChromeForIos?(l(),window.print()):t.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=t.getSelectedShapeIds(),f=t.getCurrentPageId(),g=t.getPages(),v={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(t.getSelectedShapeIds().length>0){const S=await t.getSvgString(p,v);if(S){const y=g.find(b=>b.id===f);u(`tldraw — ${y==null?void 0:y.name}`,null,S.svg),h()}}else{const S=t.getCurrentPage(),y=await t.getSvgString(t.getSortedChildIdsForParent(S.id),v);y&&(u(`tldraw — ${S.name}`,null,y.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[t])}const I3=w.createContext(null);function noe({children:t}){const e=F(),n=Zt(),[r,o]=w.useState([]),s=w.useCallback(c=>{const u=c.id??Ke();return o(h=>[...h.filter(p=>p.id!==c.id),{...c,id:u}]),n("open-menu",{source:"dialog",id:u}),e.addOpenMenu(u),u},[e,n]),i=w.useCallback((c,u)=>(o(h=>h.map(p=>p.id===c?{...p,...u}:p)),n("open-menu",{source:"dialog",id:c}),e.addOpenMenu(c),c),[e,n]),a=w.useCallback(c=>(o(u=>u.filter(h=>{var p;return h.id===c?((p=h.onClose)==null||p.call(h),!1):!0})),n("close-menu",{source:"dialog",id:c}),e.deleteOpenMenu(c),c),[e,n]),l=w.useCallback(()=>{o(c=>(c.forEach(u=>{var h;(h=u.onClose)==null||h.call(u),n("close-menu",{source:"dialog",id:u.id}),e.deleteOpenMenu(u.id)}),[]))},[e,n]);return d.jsx(I3.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:t})}function ya(){const t=w.useContext(I3);if(!t)throw new Error("useDialogs must be used within a DialogsProvider");return t}const E3=w.createContext(null);function roe(t){return Object.fromEntries(t.map(e=>[e.id,e]))}function ja(t,e){if(t.getSelectedShapes().length===0)return t.getDocumentSettings().name||e}function ooe({overrides:t,children:e}){const n=F(),r=Jg(),{addDialog:o,clearDialogs:s}=ya(),{clearToasts:i,addToast:a}=ao(),l=Ce(),c=_3(),u=toe(),{cut:h,copy:p,paste:f}=ore(),g=Xre(),m=Qre(),v=l("document.default-name"),S=T1(),y=Zt(),b=w.useMemo(()=>{function P(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function C(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}const I=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(_){C()&&(P()||(y("edit-link",{source:_}),n.markHistoryStoppingPoint("edit-link"),o({component:kne})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(_){y("insert-embed",{source:_}),o({component:e3})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(_){y("insert-media",{source:_}),c()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(_){y("undo",{source:_}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(_){y("redo",{source:_}),n.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(_){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(y("export-as",{format:"svg",source:_}),m(k,"svg",ja(n,v)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(_){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(y("export-as",{format:"png",source:_}),m(k,"png",ja(n,v)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(_){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(y("export-as",{format:"json",source:_}),m(k,"json",ja(n,v)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(_){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(y("export-all-as",{format:"svg",source:_}),m(Array.from(n.getCurrentPageShapeIds()),"svg",ja(n,v)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(_){const k=Array.from(n.getCurrentPageShapeIds().values());k.length!==0&&(y("export-all-as",{format:"png",source:_}),m(k,"png",ja(n,v)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(_){const k=Array.from(n.getCurrentPageShapeIds().values());k.length!==0&&(y("export-all-as",{format:"json",source:_}),m(k,"json",ja(n,v)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(_){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(y("copy-as",{format:"svg",source:_}),g(k,"svg"))}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,onSelect(_){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(y("copy-as",{format:"png",source:_}),g(k,"png"))}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(_){let k=n.getSelectedShapeIds();k.length===0&&(k=Array.from(n.getCurrentPageShapeIds().values())),k.length!==0&&(y("copy-as",{format:"json",source:_}),g(k,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(_){if(!C()||P())return;y("toggle-auto-size",{source:_}),n.markHistoryStoppingPoint("toggling auto size");const k=n.getSelectedShapes().filter(M=>n.isShapeOfType(M,"text")&&M.props.autoSize===!1);n.updateShapes(k.map(M=>({id:M.id,type:M.type,props:{...M.props,w:8,autoSize:!0}}))),Ve(n,k.map(M=>M.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(_){y("open-embed-link",{source:_});const k=n.getSelectedShapeIds(),M="No embed shapes selected";if(k.length!==1){console.error(M);return}const R=n.getShape(k[0]);if(!R||!n.isShapeOfType(R,"embed")){console.error(M);return}Hee(R.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(_){var k,M;if(((k=n.root.getCurrent())==null?void 0:k.id)!=="zoom"&&(y("zoom-tool",{source:_}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const R=n.root.getCurrent();R&&((M=R.getCurrent())==null?void 0:M.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:R.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(_){C()&&(P()||n.run(()=>{y("convert-to-bookmark",{source:_});const k=n.getSelectedShapes(),M=[],R=[];for(const j of k){if(!j||!n.isShapeOfType(j,"embed")||!j.props.url)continue;const O=new x(j.x,j.y);O.rot(-j.rotation),O.add(new x(j.props.w/2-300/2,j.props.h/2-320/2)),O.rot(j.rotation);const D={id:Ne(),type:"bookmark",rotation:j.rotation,x:O.x,y:O.y,opacity:1,props:{url:j.props.url}};M.push(D),R.push(j.id)}n.markHistoryStoppingPoint("convert shapes to bookmark"),n.deleteShapes(R),n.createShapes(M)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(_){C()&&(P()||(y("convert-to-embed",{source:_}),n.run(()=>{const k=n.getSelectedShapeIds(),M=ye(k.map(O=>n.getShape(O))),R=[],j=[];for(const O of M){if(!n.isShapeOfType(O,"bookmark"))continue;const{url:D}=O.props,B=S(D);if(!B||!B.definition)continue;const{width:z,height:K}=B.definition,N=new x(O.x,O.y);N.rot(-O.rotation),N.add(new x(O.props.w/2-z/2,O.props.h/2-K/2)),N.rot(O.rotation);const H={id:Ne(),type:"embed",x:N.x,y:N.y,rotation:O.rotation,props:{url:D,w:z,h:K}};R.push(H),j.push(O.id)}n.markHistoryStoppingPoint("convert shapes to embed"),n.deleteShapes(j),n.createShapes(R)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(_){if(!C()||P())return;y("duplicate-shapes",{source:_});const k=n.getInstanceState();let M,R;if(k.duplicateProps)M=k.duplicateProps.shapeIds,R=k.duplicateProps.offset;else{M=n.getSelectedShapeIds();const j=Z.Common(ye(M.map(O=>n.getShapePageBounds(O))));R=n.getCameraOptions().isLocked?{x:n.options.adjacentShapeMargin,y:n.options.adjacentShapeMargin}:{x:j.width+n.options.adjacentShapeMargin,y:0}}n.markHistoryStoppingPoint("duplicate shapes"),n.duplicateShapes(M,R),k.duplicateProps&&n.updateInstanceState({duplicateProps:{...k.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(_){C()&&(P()||(y("ungroup-shapes",{source:_}),n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(_){if(!C()||P())return;y("group-shapes",{source:_});const k=n.getOnlySelectedShape();k&&n.isShapeOfType(k,"group")?(n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())):(n.markHistoryStoppingPoint("group"),n.groupShapes(n.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(_){if(!C())return;y("remove-frame",{source:_});const k=n.getSelectedShapes();k.length>0&&k.every(M=>n.isShapeOfType(M,"frame"))&&(n.markHistoryStoppingPoint("remove-frame"),Wee(n,k.map(M=>M.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(_){if(!C())return;y("fit-frame-to-content",{source:_});const k=n.getOnlySelectedShape();k&&n.isShapeOfType(k,"frame")&&(n.markHistoryStoppingPoint("fit-frame-to-content"),Vee(n,k.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"left",source:_}),n.markHistoryStoppingPoint("align left");const k=n.getSelectedShapeIds();n.alignShapes(k,"left"),Ve(n,k)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"center-horizontal",source:_}),n.markHistoryStoppingPoint("align center horizontal");const k=n.getSelectedShapeIds();n.alignShapes(k,"center-horizontal"),Ve(n,k)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"right",source:_}),n.markHistoryStoppingPoint("align right");const k=n.getSelectedShapeIds();n.alignShapes(k,"right"),Ve(n,k)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"center-vertical",source:_}),n.markHistoryStoppingPoint("align center vertical");const k=n.getSelectedShapeIds();n.alignShapes(k,"center-vertical"),Ve(n,k)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"top",source:_}),n.markHistoryStoppingPoint("align top");const k=n.getSelectedShapeIds();n.alignShapes(k,"top"),Ve(n,k)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"bottom",source:_}),n.markHistoryStoppingPoint("align bottom");const k=n.getSelectedShapeIds();n.alignShapes(k,"bottom"),Ve(n,k)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(_){if(!C()||P())return;y("distribute-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("distribute horizontal");const k=n.getSelectedShapeIds();n.distributeShapes(k,"horizontal"),Ve(n,k)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(_){if(!C()||P())return;y("distribute-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("distribute vertical");const k=n.getSelectedShapeIds();n.distributeShapes(k,"vertical"),Ve(n,k)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(_){if(!C()||P())return;y("stretch-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("stretch horizontal");const k=n.getSelectedShapeIds();n.stretchShapes(k,"horizontal"),Ve(n,k)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(_){if(!C()||P())return;y("stretch-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("stretch vertical");const k=n.getSelectedShapeIds();n.stretchShapes(k,"vertical"),Ve(n,k)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(_){if(!C()||P())return;y("flip-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("flip horizontal");const k=n.getSelectedShapeIds();n.flipShapes(k,"horizontal"),Ve(n,k)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(_){if(!C()||P())return;y("flip-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("flip vertical");const k=n.getSelectedShapeIds();n.flipShapes(k,"vertical"),Ve(n,k)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(_){if(!C()||P())return;y("pack-shapes",{source:_}),n.markHistoryStoppingPoint("pack");const k=n.getSelectedShapeIds();n.packShapes(k,n.options.adjacentShapeMargin),Ve(n,k)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(_){if(!C()||P())return;y("stack-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("stack-vertical");const k=n.getSelectedShapeIds();n.stackShapes(k,"vertical",16),Ve(n,k)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(_){if(!C()||P())return;y("stack-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("stack-horizontal");const k=n.getSelectedShapeIds();n.stackShapes(k,"horizontal",16),Ve(n,k)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"toFront",source:_}),n.markHistoryStoppingPoint("bring to front"),n.bringToFront(n.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"forward",source:_}),n.markHistoryStoppingPoint("bring forward"),n.bringForward(n.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"backward",source:_}),n.markHistoryStoppingPoint("send backward"),n.sendBackward(n.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"toBack",source:_}),n.markHistoryStoppingPoint("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(_){C()&&(P()||(n.markHistoryStoppingPoint("cut"),h(_)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(_){C()&&(P()||p(_))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(_){var k;(k=navigator.clipboard)==null||k.read().then(M=>{f(M,_,_==="context-menu"?n.inputs.currentPagePoint:void 0)}).catch(()=>{a({title:l("action.paste-error-title"),description:l("action.paste-error-description"),severity:"error"})})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(_){n.run(()=>{P()||(y("select-all-shapes",{source:_}),n.markHistoryStoppingPoint("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(_){C()&&(P()||(y("select-none-shapes",{source:_}),n.markHistoryStoppingPoint("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(_){C()&&(P()||(y("delete-shapes",{source:_}),n.markHistoryStoppingPoint("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(_){if(!C()||P())return;y("rotate-cw",{source:_}),n.markHistoryStoppingPoint("rotate-cw");const k=n.getSelectionRotation()%(qe/2),M=ti(k,0)||ti(k,qe/2),R=n.getSelectedShapeIds();n.rotateShapesBy(R,qe/2-(M?0:k)),Ve(n,R)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(_){if(!C()||P())return;y("rotate-ccw",{source:_}),n.markHistoryStoppingPoint("rotate-ccw");const k=n.getSelectionRotation()%(qe/2),M=ti(k,0),R=n.getSelectedShapeIds();n.rotateShapesBy(R,M?-(qe/2):-k),Ve(n,R)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(_){y("zoom-in",{source:_}),n.zoomIn(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(_){y("zoom-out",{source:_}),n.zoomOut(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(_){y("reset-zoom",{source:_}),n.resetZoom(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(_){y("zoom-to-fit",{source:_}),n.zoomToFit({animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(_){C()&&(P()||(y("zoom-to-selection",{source:_}),n.zoomToSelection({animation:{duration:n.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(_){y("toggle-snap-mode",{source:_}),n.user.updateUserPreferences({isSnapMode:!n.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(_){const k=n.user.getIsDarkMode()?"light":"dark";y("color-scheme",{source:_,value:k}),n.user.updateUserPreferences({colorScheme:k})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(_){y("toggle-wrap-mode",{source:_}),n.user.updateUserPreferences({isWrapMode:!n.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-dynamic-size-mode",label:{default:"action.toggle-dynamic-size-mode",menu:"action.toggle-dynamic-size-mode.menu"},readonlyOk:!1,onSelect(_){y("toggle-dynamic-size-mode",{source:_}),n.user.updateUserPreferences({isDynamicSizeMode:!n.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-paste-at-cursor",label:{default:"action.toggle-paste-at-cursor",menu:"action.toggle-paste-at-cursor.menu"},readonlyOk:!1,onSelect(_){y("toggle-paste-at-cursor",{source:_}),n.user.updateUserPreferences({isPasteAtCursorMode:!n.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(_){y("toggle-reduce-motion",{source:_}),n.user.updateUserPreferences({animationSpeed:n.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(_){y("toggle-edge-scrolling",{source:_}),n.user.updateUserPreferences({edgeScrollSpeed:n.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(_){y("toggle-transparent",{source:_}),n.updateInstanceState({exportBackground:!n.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(_){y("toggle-tool-lock",{source:_}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(_){y("unlock-all",{source:_});const k=[];for(const M of n.getCurrentPageShapes())M.isLocked&&k.push({id:M.id,type:M.type,isLocked:!1});k.length>0&&n.updateShapes(k)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(_){n.timers.requestAnimationFrame(()=>{n.run(()=>{y("toggle-focus-mode",{source:_}),s(),i(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(_){y("toggle-grid-mode",{source:_}),n.updateInstanceState({isGridMode:!n.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(_){y("toggle-debug-mode",{source:_}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(_){y("print",{source:_}),u()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(_){y("exit-pen-mode",{source:_}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(_){y("stop-following",{source:_}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(_){y("zoom-to-content",{source:_});const k=n.getSelectionPageBounds()??n.getCurrentPageBounds();k&&n.zoomToBounds(k,{targetZoom:Math.min(1,n.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(_){n.markHistoryStoppingPoint("locking"),y("toggle-lock",{source:_}),n.toggleLock(n.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(_){const k=gr.createId(),M=n.getSelectedShapeIds();n.run(()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.createPage({name:l("page-menu.new-page-initial-name"),id:k}),n.moveShapesToPage(M,k)}),y("move-to-new-page",{source:_})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(_){const k=fr;n.run(()=>{n.markHistoryStoppingPoint("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(k,"white"),n.setStyleForNextShapes(k,"white")}),y("set-style",{source:_,id:k.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(_){const k=na;n.run(()=>{n.markHistoryStoppingPoint("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(k,"fill"),n.setStyleForNextShapes(k,"fill")}),y("set-style",{source:_,id:k.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async _=>{const k=n.getSelectedShapeIds();if(k.length===0)return;n.markHistoryStoppingPoint("flattening to image"),y("flatten-to-image",{source:_});const M=await Jre(n,k,n.options.flattenImageBoundsExpand);M!=null&&M.length&&n.setSelectedShapes(M)}}];r&&I.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(_){y("open-cursor-chat",{source:_}),!n.getInstanceState().isCoarsePointer&&n.timers.requestAnimationFrame(()=>{n.updateInstanceState({isChatting:!0})})}});const T=roe(I);return t?t(n,T,void 0):T},[n,y,t,o,a,c,m,g,h,p,f,s,i,u,l,v,r,S]);return d.jsx(E3.Provider,{value:b,children:e})}function Sa(){const t=w.useContext(E3);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Ru(t,e){return t?typeof t=="string"?t:e?t[e]??t.default:void 0:void 0}var soe=w.createContext(void 0);function R1(t){const e=w.useContext(soe);return t||e||"ltr"}const ioe=["top","right","bottom","left"],ui=Math.min,rr=Math.max,jf=Math.round,bh=Math.floor,di=t=>({x:t,y:t}),aoe={left:"right",right:"left",bottom:"top",top:"bottom"},loe={start:"end",end:"start"};function Ox(t,e,n){return rr(t,ui(e,n))}function gs(t,e){return typeof t=="function"?t(e):t}function ms(t){return t.split("-")[0]}function Xl(t){return t.split("-")[1]}function L1(t){return t==="x"?"y":"x"}function $1(t){return t==="y"?"height":"width"}function hi(t){return["top","bottom"].includes(ms(t))?"y":"x"}function F1(t){return L1(hi(t))}function coe(t,e,n){n===void 0&&(n=!1);const r=Xl(t),o=F1(t),s=$1(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=Of(i)),[i,Of(i)]}function uoe(t){const e=Of(t);return[Dx(t),e,Dx(e)]}function Dx(t){return t.replace(/start|end/g,e=>loe[e])}function doe(t,e,n){const r=["left","right"],o=["right","left"],s=["top","bottom"],i=["bottom","top"];switch(t){case"top":case"bottom":return n?e?o:r:e?r:o;case"left":case"right":return e?s:i;default:return[]}}function hoe(t,e,n,r){const o=Xl(t);let s=doe(ms(t),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),e&&(s=s.concat(s.map(Dx)))),s}function Of(t){return t.replace(/left|right|bottom|top/g,e=>aoe[e])}function poe(t){return{top:0,right:0,bottom:0,left:0,...t}}function k3(t){return typeof t!="number"?poe(t):{top:t,right:t,bottom:t,left:t}}function Df(t){const{x:e,y:n,width:r,height:o}=t;return{width:r,height:o,top:n,left:e,right:e+r,bottom:n+o,x:e,y:n}}function UI(t,e,n){let{reference:r,floating:o}=t;const s=hi(e),i=F1(e),a=$1(i),l=ms(e),c=s==="y",u=r.x+r.width/2-o.width/2,h=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let f;switch(l){case"top":f={x:u,y:r.y-o.height};break;case"bottom":f={x:u,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:h};break;case"left":f={x:r.x-o.width,y:h};break;default:f={x:r.x,y:r.y}}switch(Xl(e)){case"start":f[i]-=p*(n&&c?-1:1);break;case"end":f[i]+=p*(n&&c?-1:1);break}return f}const foe=async(t,e,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(e));let c=await i.getElementRects({reference:t,floating:e,strategy:o}),{x:u,y:h}=UI(c,r,l),p=r,f={},g=0;for(let m=0;m<a.length;m++){const{name:v,fn:S}=a[m],{x:y,y:b,data:P,reset:C}=await S({x:u,y:h,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:t,floating:e}});u=y??u,h=b??h,f={...f,[v]:{...f[v],...P}},C&&g<=50&&(g++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:t,floating:e,strategy:o}):C.rects),{x:u,y:h}=UI(c,p,l)),m=-1)}return{x:u,y:h,placement:p,strategy:o,middlewareData:f}};async function Lu(t,e){var n;e===void 0&&(e={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:p=!1,padding:f=0}=gs(e,t),g=k3(f),v=a[p?h==="floating"?"reference":"floating":h],S=Df(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),y=h==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),P=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Df(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:y,offsetParent:b,strategy:l}):y);return{top:(S.top-C.top+g.top)/P.y,bottom:(C.bottom-S.bottom+g.bottom)/P.y,left:(S.left-C.left+g.left)/P.x,right:(C.right-S.right+g.right)/P.x}}const goe=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=e,{element:c,padding:u=0}=gs(t,e)||{};if(c==null)return{};const h=k3(u),p={x:n,y:r},f=F1(o),g=$1(f),m=await i.getDimensions(c),v=f==="y",S=v?"top":"left",y=v?"bottom":"right",b=v?"clientHeight":"clientWidth",P=s.reference[g]+s.reference[f]-p[f]-s.floating[g],C=p[f]-s.reference[f],I=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let T=I?I[b]:0;(!T||!await(i.isElement==null?void 0:i.isElement(I)))&&(T=a.floating[b]||s.floating[g]);const _=P/2-C/2,k=T/2-m[g]/2-1,M=ui(h[S],k),R=ui(h[y],k),j=M,O=T-m[g]-R,D=T/2-m[g]/2+_,B=Ox(j,D,O),z=!l.arrow&&Xl(o)!=null&&D!==B&&s.reference[g]/2-(D<j?M:R)-m[g]/2<0,K=z?D<j?D-j:D-O:0;return{[f]:p[f]+K,data:{[f]:B,centerOffset:D-B-K,...z&&{alignmentOffset:K}},reset:z}}}),moe=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:m=!0,...v}=gs(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const S=ms(o),y=hi(a),b=ms(a)===a,P=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(b||!m?[Of(a)]:uoe(a)),I=g!=="none";!p&&I&&C.push(...hoe(a,m,g,P));const T=[a,...C],_=await Lu(e,v),k=[];let M=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&k.push(_[S]),h){const D=coe(o,i,P);k.push(_[D[0]],_[D[1]])}if(M=[...M,{placement:o,overflows:k}],!k.every(D=>D<=0)){var R,j;const D=(((R=s.flip)==null?void 0:R.index)||0)+1,B=T[D];if(B)return{data:{index:D,overflows:M},reset:{placement:B}};let z=(j=M.filter(K=>K.overflows[0]<=0).sort((K,N)=>K.overflows[1]-N.overflows[1])[0])==null?void 0:j.placement;if(!z)switch(f){case"bestFit":{var O;const K=(O=M.filter(N=>{if(I){const H=hi(N.placement);return H===y||H==="y"}return!0}).map(N=>[N.placement,N.overflows.filter(H=>H>0).reduce((H,Y)=>H+Y,0)]).sort((N,H)=>N[1]-H[1])[0])==null?void 0:O[0];K&&(z=K);break}case"initialPlacement":z=a;break}if(o!==z)return{reset:{placement:z}}}return{}}}};function HI(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function KI(t){return ioe.some(e=>t[e]>=0)}const yoe=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...o}=gs(t,e);switch(r){case"referenceHidden":{const s=await Lu(e,{...o,elementContext:"reference"}),i=HI(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:KI(i)}}}case"escaped":{const s=await Lu(e,{...o,altBoundary:!0}),i=HI(s,n.floating);return{data:{escapedOffsets:i,escaped:KI(i)}}}default:return{}}}}};async function Soe(t,e){const{placement:n,platform:r,elements:o}=t,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=ms(n),a=Xl(n),l=hi(n)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,h=gs(e,t);let{mainAxis:p,crossAxis:f,alignmentAxis:g}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof g=="number"&&(f=a==="end"?g*-1:g),l?{x:f*u,y:p*c}:{x:p*c,y:f*u}}const voe=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=e,l=await Soe(e,t);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},xoe=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:o}=e,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x:S,y}=v;return{x:S,y}}},...l}=gs(t,e),c={x:n,y:r},u=await Lu(e,l),h=hi(ms(o)),p=L1(h);let f=c[p],g=c[h];if(s){const v=p==="y"?"top":"left",S=p==="y"?"bottom":"right",y=f+u[v],b=f-u[S];f=Ox(y,f,b)}if(i){const v=h==="y"?"top":"left",S=h==="y"?"bottom":"right",y=g+u[v],b=g-u[S];g=Ox(y,g,b)}const m=a.fn({...e,[p]:f,[h]:g});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[h]:i}}}}}},woe=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=e,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=gs(t,e),u={x:n,y:r},h=hi(o),p=L1(h);let f=u[p],g=u[h];const m=gs(a,e),v=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const b=p==="y"?"height":"width",P=s.reference[p]-s.floating[b]+v.mainAxis,C=s.reference[p]+s.reference[b]-v.mainAxis;f<P?f=P:f>C&&(f=C)}if(c){var S,y;const b=p==="y"?"width":"height",P=["top","left"].includes(ms(o)),C=s.reference[h]-s.floating[b]+(P&&((S=i.offset)==null?void 0:S[h])||0)+(P?0:v.crossAxis),I=s.reference[h]+s.reference[b]+(P?0:((y=i.offset)==null?void 0:y[h])||0)-(P?v.crossAxis:0);g<C?g=C:g>I&&(g=I)}return{[p]:f,[h]:g}}}},boe=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,r;const{placement:o,rects:s,platform:i,elements:a}=e,{apply:l=()=>{},...c}=gs(t,e),u=await Lu(e,c),h=ms(o),p=Xl(o),f=hi(o)==="y",{width:g,height:m}=s.floating;let v,S;h==="top"||h==="bottom"?(v=h,S=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(S=h,v=p==="end"?"top":"bottom");const y=m-u.top-u.bottom,b=g-u.left-u.right,P=ui(m-u[v],y),C=ui(g-u[S],b),I=!e.middlewareData.shift;let T=P,_=C;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(_=b),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(T=y),I&&!p){const M=rr(u.left,0),R=rr(u.right,0),j=rr(u.top,0),O=rr(u.bottom,0);f?_=g-2*(M!==0||R!==0?M+R:rr(u.left,u.right)):T=m-2*(j!==0||O!==0?j+O:rr(u.top,u.bottom))}await l({...e,availableWidth:_,availableHeight:T});const k=await i.getDimensions(a.floating);return g!==k.width||m!==k.height?{reset:{rects:!0}}:{}}}};function em(){return typeof window<"u"}function ql(t){return T3(t)?(t.nodeName||"").toLowerCase():"#document"}function dr(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function $o(t){var e;return(e=(T3(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function T3(t){return em()?t instanceof Node||t instanceof dr(t).Node:!1}function to(t){return em()?t instanceof Element||t instanceof dr(t).Element:!1}function Ao(t){return em()?t instanceof HTMLElement||t instanceof dr(t).HTMLElement:!1}function WI(t){return!em()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof dr(t).ShadowRoot}function fd(t){const{overflow:e,overflowX:n,overflowY:r,display:o}=no(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!["inline","contents"].includes(o)}function Poe(t){return["table","td","th"].includes(ql(t))}function tm(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function N1(t){const e=z1(),n=to(t)?no(t):t;return n.transform!=="none"||n.perspective!=="none"||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function Coe(t){let e=pi(t);for(;Ao(e)&&!Il(e);){if(N1(e))return e;if(tm(e))return null;e=pi(e)}return null}function z1(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Il(t){return["html","body","#document"].includes(ql(t))}function no(t){return dr(t).getComputedStyle(t)}function nm(t){return to(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function pi(t){if(ql(t)==="html")return t;const e=t.assignedSlot||t.parentNode||WI(t)&&t.host||$o(t);return WI(e)?e.host:e}function M3(t){const e=pi(t);return Il(e)?t.ownerDocument?t.ownerDocument.body:t.body:Ao(e)&&fd(e)?e:M3(e)}function $u(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const o=M3(t),s=o===((r=t.ownerDocument)==null?void 0:r.body),i=dr(o);if(s){const a=Rx(i);return e.concat(i,i.visualViewport||[],fd(o)?o:[],a&&n?$u(a):[])}return e.concat(o,$u(o,[],n))}function Rx(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function A3(t){const e=no(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const o=Ao(t),s=o?t.offsetWidth:n,i=o?t.offsetHeight:r,a=jf(n)!==s||jf(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function B1(t){return to(t)?t:t.contextElement}function gl(t){const e=B1(t);if(!Ao(e))return di(1);const n=e.getBoundingClientRect(),{width:r,height:o,$:s}=A3(e);let i=(s?jf(n.width):n.width)/r,a=(s?jf(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const _oe=di(0);function j3(t){const e=dr(t);return!z1()||!e.visualViewport?_oe:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Ioe(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==dr(t)?!1:e}function ia(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=B1(t);let i=di(1);e&&(r?to(r)&&(i=gl(r)):i=gl(t));const a=Ioe(s,n,r)?j3(s):di(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,h=o.height/i.y;if(s){const p=dr(s),f=r&&to(r)?dr(r):r;let g=p,m=Rx(g);for(;m&&r&&f!==g;){const v=gl(m),S=m.getBoundingClientRect(),y=no(m),b=S.left+(m.clientLeft+parseFloat(y.paddingLeft))*v.x,P=S.top+(m.clientTop+parseFloat(y.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,h*=v.y,l+=b,c+=P,g=dr(m),m=Rx(g)}}return Df({width:u,height:h,x:l,y:c})}function Eoe(t){let{elements:e,rect:n,offsetParent:r,strategy:o}=t;const s=o==="fixed",i=$o(r),a=e?tm(e.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=di(1);const u=di(0),h=Ao(r);if((h||!h&&!s)&&((ql(r)!=="body"||fd(i))&&(l=nm(r)),Ao(r))){const p=ia(r);c=gl(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x,y:n.y*c.y-l.scrollTop*c.y+u.y}}function koe(t){return Array.from(t.getClientRects())}function Lx(t,e){const n=nm(t).scrollLeft;return e?e.left+n:ia($o(t)).left+n}function Toe(t){const e=$o(t),n=nm(t),r=t.ownerDocument.body,o=rr(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),s=rr(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Lx(t);const a=-n.scrollTop;return no(r).direction==="rtl"&&(i+=rr(e.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function Moe(t,e){const n=dr(t),r=$o(t),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const c=z1();(!c||c&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function Aoe(t,e){const n=ia(t,!0,e==="fixed"),r=n.top+t.clientTop,o=n.left+t.clientLeft,s=Ao(t)?gl(t):di(1),i=t.clientWidth*s.x,a=t.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function GI(t,e,n){let r;if(e==="viewport")r=Moe(t,n);else if(e==="document")r=Toe($o(t));else if(to(e))r=Aoe(e,n);else{const o=j3(t);r={...e,x:e.x-o.x,y:e.y-o.y}}return Df(r)}function O3(t,e){const n=pi(t);return n===e||!to(n)||Il(n)?!1:no(n).position==="fixed"||O3(n,e)}function joe(t,e){const n=e.get(t);if(n)return n;let r=$u(t,[],!1).filter(a=>to(a)&&ql(a)!=="body"),o=null;const s=no(t).position==="fixed";let i=s?pi(t):t;for(;to(i)&&!Il(i);){const a=no(i),l=N1(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||fd(i)&&!l&&O3(t,i))?r=r.filter(u=>u!==i):o=a,i=pi(i)}return e.set(t,r),r}function Ooe(t){let{element:e,boundary:n,rootBoundary:r,strategy:o}=t;const i=[...n==="clippingAncestors"?tm(e)?[]:joe(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=GI(e,u,o);return c.top=rr(h.top,c.top),c.right=ui(h.right,c.right),c.bottom=ui(h.bottom,c.bottom),c.left=rr(h.left,c.left),c},GI(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Doe(t){const{width:e,height:n}=A3(t);return{width:e,height:n}}function Roe(t,e,n){const r=Ao(e),o=$o(e),s=n==="fixed",i=ia(t,!0,s,e);let a={scrollLeft:0,scrollTop:0};const l=di(0);if(r||!r&&!s)if((ql(e)!=="body"||fd(o))&&(a=nm(e)),r){const f=ia(e,!0,s,e);l.x=f.x+e.clientLeft,l.y=f.y+e.clientTop}else o&&(l.x=Lx(o));let c=0,u=0;if(o&&!r&&!s){const f=o.getBoundingClientRect();u=f.top+a.scrollTop,c=f.left+a.scrollLeft-Lx(o,f)}const h=i.left+a.scrollLeft-l.x-c,p=i.top+a.scrollTop-l.y-u;return{x:h,y:p,width:i.width,height:i.height}}function iS(t){return no(t).position==="static"}function VI(t,e){if(!Ao(t)||no(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return $o(t)===n&&(n=n.ownerDocument.body),n}function D3(t,e){const n=dr(t);if(tm(t))return n;if(!Ao(t)){let o=pi(t);for(;o&&!Il(o);){if(to(o)&&!iS(o))return o;o=pi(o)}return n}let r=VI(t,e);for(;r&&Poe(r)&&iS(r);)r=VI(r,e);return r&&Il(r)&&iS(r)&&!N1(r)?n:r||Coe(t)||n}const Loe=async function(t){const e=this.getOffsetParent||D3,n=this.getDimensions,r=await n(t.floating);return{reference:Roe(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function $oe(t){return no(t).direction==="rtl"}const Foe={convertOffsetParentRelativeRectToViewportRelativeRect:Eoe,getDocumentElement:$o,getClippingRect:Ooe,getOffsetParent:D3,getElementRects:Loe,getClientRects:koe,getDimensions:Doe,getScale:gl,isElement:to,isRTL:$oe};function Noe(t,e){let n=null,r;const o=$o(t);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const{left:c,top:u,width:h,height:p}=t.getBoundingClientRect();if(a||e(),!h||!p)return;const f=bh(u),g=bh(o.clientWidth-(c+h)),m=bh(o.clientHeight-(u+p)),v=bh(c),y={rootMargin:-f+"px "+-g+"px "+-m+"px "+-v+"px",threshold:rr(0,ui(1,l))||1};let b=!0;function P(C){const I=C[0].intersectionRatio;if(I!==l){if(!b)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}b=!1}try{n=new IntersectionObserver(P,{...y,root:o.ownerDocument})}catch{n=new IntersectionObserver(P,y)}n.observe(t)}return i(!0),s}function zoe(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=B1(t),u=o||s?[...c?$u(c):[],...$u(e)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",n,{passive:!0}),s&&S.addEventListener("resize",n)});const h=c&&a?Noe(c,n):null;let p=-1,f=null;i&&(f=new ResizeObserver(S=>{let[y]=S;y&&y.target===c&&f&&(f.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=f)==null||b.observe(e)})),n()}),c&&!l&&f.observe(c),f.observe(e));let g,m=l?ia(t):null;l&&v();function v(){const S=ia(t);m&&(S.x!==m.x||S.y!==m.y||S.width!==m.width||S.height!==m.height)&&n(),m=S,g=requestAnimationFrame(v)}return n(),()=>{var S;u.forEach(y=>{o&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),h==null||h(),(S=f)==null||S.disconnect(),f=null,l&&cancelAnimationFrame(g)}}const Boe=voe,Uoe=xoe,Hoe=moe,Koe=boe,Woe=yoe,YI=goe,Goe=woe,Voe=(t,e,n)=>{const r=new Map,o={platform:Foe,...n},s={...o.platform,_c:r};return foe(t,e,{...o,platform:s})};var op=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Rf(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,o;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!Rf(t[r],e[r]))return!1;return!0}if(o=Object.keys(t),n=o.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&t.$$typeof)&&!Rf(t[s],e[s]))return!1}return!0}return t!==t&&e!==e}function R3(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function XI(t,e){const n=R3(t);return Math.round(e*n)/n}function aS(t){const e=w.useRef(t);return op(()=>{e.current=t}),e}function Yoe(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=t,[u,h]=w.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[p,f]=w.useState(r);Rf(p,r)||f(r);const[g,m]=w.useState(null),[v,S]=w.useState(null),y=w.useCallback(N=>{N!==I.current&&(I.current=N,m(N))},[]),b=w.useCallback(N=>{N!==T.current&&(T.current=N,S(N))},[]),P=s||g,C=i||v,I=w.useRef(null),T=w.useRef(null),_=w.useRef(u),k=l!=null,M=aS(l),R=aS(o),j=aS(c),O=w.useCallback(()=>{if(!I.current||!T.current)return;const N={placement:e,strategy:n,middleware:p};R.current&&(N.platform=R.current),Voe(I.current,T.current,N).then(H=>{const Y={...H,isPositioned:j.current!==!1};D.current&&!Rf(_.current,Y)&&(_.current=Y,ps.flushSync(()=>{h(Y)}))})},[p,e,n,R,j]);op(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,h(N=>({...N,isPositioned:!1})))},[c]);const D=w.useRef(!1);op(()=>(D.current=!0,()=>{D.current=!1}),[]),op(()=>{if(P&&(I.current=P),C&&(T.current=C),P&&C){if(M.current)return M.current(P,C,O);O()}},[P,C,O,M,k]);const B=w.useMemo(()=>({reference:I,floating:T,setReference:y,setFloating:b}),[y,b]),z=w.useMemo(()=>({reference:P,floating:C}),[P,C]),K=w.useMemo(()=>{const N={position:n,left:0,top:0};if(!z.floating)return N;const H=XI(z.floating,u.x),Y=XI(z.floating,u.y);return a?{...N,transform:"translate("+H+"px, "+Y+"px)",...R3(z.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:Y}},[n,a,z.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:O,refs:B,elements:z,floatingStyles:K}),[u,O,B,z,K])}const Xoe=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:o}=typeof t=="function"?t(n):t;return r&&e(r)?r.current!=null?YI({element:r.current,padding:o}).fn(n):{}:r?YI({element:r,padding:o}).fn(n):{}}}},qoe=(t,e)=>({...Boe(t),options:[t,e]}),Zoe=(t,e)=>({...Uoe(t),options:[t,e]}),Qoe=(t,e)=>({...Goe(t),options:[t,e]}),Joe=(t,e)=>({...Hoe(t),options:[t,e]}),ese=(t,e)=>({...Koe(t),options:[t,e]}),tse=(t,e)=>({...Woe(t),options:[t,e]}),nse=(t,e)=>({...Xoe(t),options:[t,e]});var rse="Arrow",L3=w.forwardRef((t,e)=>{const{children:n,width:r=10,height:o=5,...s}=t;return d.jsx(Ae.svg,{...s,ref:e,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});L3.displayName=rse;var ose=L3;function $3(t){const[e,n]=w.useState(void 0);return ci(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=t.offsetWidth,a=t.offsetHeight;n({width:i,height:a})});return r.observe(t,{box:"border-box"}),()=>r.unobserve(t)}else n(void 0)},[t]),e}var U1="Popper",[F3,rm]=Lo(U1),[sse,N3]=F3(U1),z3=t=>{const{__scopePopper:e,children:n}=t,[r,o]=w.useState(null);return d.jsx(sse,{scope:e,anchor:r,onAnchorChange:o,children:n})};z3.displayName=U1;var B3="PopperAnchor",U3=w.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...o}=t,s=N3(B3,n),i=w.useRef(null),a=Ze(e,i);return w.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(Ae.div,{...o,ref:a})});U3.displayName=B3;var H1="PopperContent",[ise,ase]=F3(H1),H3=w.forwardRef((t,e)=>{var $e,ot,Le,at,Be,Zn;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:f="optimized",onPlaced:g,...m}=t,v=N3(H1,n),[S,y]=w.useState(null),b=Ze(e,$t=>y($t)),[P,C]=w.useState(null),I=$3(P),T=(I==null?void 0:I.width)??0,_=(I==null?void 0:I.height)??0,k=r+(s!=="center"?"-"+s:""),M=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},R=Array.isArray(c)?c:[c],j=R.length>0,O={padding:M,boundary:R.filter(cse),altBoundary:j},{refs:D,floatingStyles:B,placement:z,isPositioned:K,middlewareData:N}=Yoe({strategy:"fixed",placement:k,whileElementsMounted:(...$t)=>zoe(...$t,{animationFrame:f==="always"}),elements:{reference:v.anchor},middleware:[qoe({mainAxis:o+_,alignmentAxis:i}),l&&Zoe({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Qoe():void 0,...O}),l&&Joe({...O}),ese({...O,apply:({elements:$t,rects:Mn,availableWidth:yt,availableHeight:Qt})=>{const{width:No,height:Ql}=Mn.reference,_s=$t.floating.style;_s.setProperty("--radix-popper-available-width",`${yt}px`),_s.setProperty("--radix-popper-available-height",`${Qt}px`),_s.setProperty("--radix-popper-anchor-width",`${No}px`),_s.setProperty("--radix-popper-anchor-height",`${Ql}px`)}}),P&&nse({element:P,padding:a}),use({arrowWidth:T,arrowHeight:_}),p&&tse({strategy:"referenceHidden",...O})]}),[H,Y]=G3(z),ee=Xt(g);ci(()=>{K&&(ee==null||ee())},[K,ee]);const ce=($e=N.arrow)==null?void 0:$e.x,ge=(ot=N.arrow)==null?void 0:ot.y,Te=((Le=N.arrow)==null?void 0:Le.centerOffset)!==0,[se,We]=w.useState();return ci(()=>{S&&We(window.getComputedStyle(S).zIndex)},[S]),d.jsx("div",{ref:D.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:K?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:se,"--radix-popper-transform-origin":[(at=N.transformOrigin)==null?void 0:at.x,(Be=N.transformOrigin)==null?void 0:Be.y].join(" "),...((Zn=N.hide)==null?void 0:Zn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(ise,{scope:n,placedSide:H,onArrowChange:C,arrowX:ce,arrowY:ge,shouldHideArrow:Te,children:d.jsx(Ae.div,{"data-side":H,"data-align":Y,...m,ref:b,style:{...m.style,animation:K?void 0:"none"}})})})});H3.displayName=H1;var K3="PopperArrow",lse={top:"bottom",right:"left",bottom:"top",left:"right"},W3=w.forwardRef(function(e,n){const{__scopePopper:r,...o}=e,s=ase(K3,r),i=lse[s.placedSide];return d.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:d.jsx(ose,{...o,ref:n,style:{...o.style,display:"block"}})})});W3.displayName=K3;function cse(t){return t!==null}var use=t=>({name:"transformOrigin",options:t,fn(e){var v,S,y;const{placement:n,rects:r,middlewareData:o}=e,i=((v=o.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:t.arrowWidth,l=i?0:t.arrowHeight,[c,u]=G3(n),h={start:"0%",center:"50%",end:"100%"}[u],p=(((S=o.arrow)==null?void 0:S.x)??0)+a/2,f=(((y=o.arrow)==null?void 0:y.y)??0)+l/2;let g="",m="";return c==="bottom"?(g=i?h:`${p}px`,m=`${-l}px`):c==="top"?(g=i?h:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,m=i?h:`${f}px`):c==="left"&&(g=`${r.floating.width+l}px`,m=i?h:`${f}px`),{data:{x:g,y:m}}}});function G3(t){const[e,n="center"]=t.split("-");return[e,n]}var K1=z3,W1=U3,V3=H3,Y3=W3,lS="rovingFocusGroup.onEntryFocus",dse={bubbles:!1,cancelable:!0},om="RovingFocusGroup",[$x,X3,hse]=qg(om),[pse,q3]=Lo(om,[hse]),[fse,gse]=pse(om),Z3=w.forwardRef((t,e)=>d.jsx($x.Provider,{scope:t.__scopeRovingFocusGroup,children:d.jsx($x.Slot,{scope:t.__scopeRovingFocusGroup,children:d.jsx(mse,{...t,ref:e})})}));Z3.displayName=om;var mse=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=t,p=w.useRef(null),f=Ze(e,p),g=R1(s),[m=null,v]=Pi({prop:i,defaultProp:a,onChange:l}),[S,y]=w.useState(!1),b=Xt(c),P=X3(n),C=w.useRef(!1),[I,T]=w.useState(0);return w.useEffect(()=>{const _=p.current;if(_)return _.addEventListener(lS,b),()=>_.removeEventListener(lS,b)},[b]),d.jsx(fse,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:m,onItemFocus:w.useCallback(_=>v(_),[v]),onItemShiftTab:w.useCallback(()=>y(!0),[]),onFocusableItemAdd:w.useCallback(()=>T(_=>_+1),[]),onFocusableItemRemove:w.useCallback(()=>T(_=>_-1),[]),children:d.jsx(Ae.div,{tabIndex:S||I===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...t.style},onMouseDown:oe(t.onMouseDown,()=>{C.current=!0}),onFocus:oe(t.onFocus,_=>{const k=!C.current;if(_.target===_.currentTarget&&k&&!S){const M=new CustomEvent(lS,dse);if(_.currentTarget.dispatchEvent(M),!M.defaultPrevented){const R=P().filter(z=>z.focusable),j=R.find(z=>z.active),O=R.find(z=>z.id===m),B=[j,O,...R].filter(Boolean).map(z=>z.ref.current);eL(B,u)}}C.current=!1}),onBlur:oe(t.onBlur,()=>y(!1))})})}),Q3="RovingFocusGroupItem",J3=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,...i}=t,a=as(),l=s||a,c=gse(Q3,n),u=c.currentTabStopId===l,h=X3(n),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return w.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),d.jsx($x.ItemSlot,{scope:n,id:l,focusable:r,active:o,children:d.jsx(Ae.span,{tabIndex:u?0:-1,"data-orientation":c.orientation,...i,ref:e,onMouseDown:oe(t.onMouseDown,g=>{r?c.onItemFocus(l):g.preventDefault()}),onFocus:oe(t.onFocus,()=>c.onItemFocus(l)),onKeyDown:oe(t.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){c.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const m=vse(g,c.orientation,c.dir);if(m!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(y=>y.focusable).map(y=>y.ref.current);if(m==="last")S.reverse();else if(m==="prev"||m==="next"){m==="prev"&&S.reverse();const y=S.indexOf(g.currentTarget);S=c.loop?xse(S,y+1):S.slice(y+1)}setTimeout(()=>eL(S))}})})})});J3.displayName=Q3;var yse={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Sse(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function vse(t,e,n){const r=Sse(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return yse[r]}function eL(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function xse(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var wse=Z3,bse=J3,Fx=["Enter"," "],Pse=["ArrowDown","PageUp","Home"],tL=["ArrowUp","PageDown","End"],Cse=[...Pse,...tL],_se={ltr:[...Fx,"ArrowRight"],rtl:[...Fx,"ArrowLeft"]},Ise={ltr:["ArrowLeft"],rtl:["ArrowRight"]},gd="Menu",[Fu,Ese,kse]=qg(gd),[va,sm]=Lo(gd,[kse,rm,q3]),md=rm(),nL=q3(),[rL,Ci]=va(gd),[Tse,yd]=va(gd),oL=t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=t,a=md(e),[l,c]=w.useState(null),u=w.useRef(!1),h=Xt(s),p=R1(o);return w.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),d.jsx(K1,{...a,children:d.jsx(rL,{scope:e,open:n,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(Tse,{scope:e,onClose:w.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};oL.displayName=gd;var Mse="MenuAnchor",G1=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=md(n);return d.jsx(W1,{...o,...r,ref:e})});G1.displayName=Mse;var V1="MenuPortal",[Ase,sL]=va(V1,{forceMount:void 0}),iL=t=>{const{__scopeMenu:e,forceMount:n,children:r,container:o}=t,s=Ci(V1,e);return d.jsx(Ase,{scope:e,forceMount:n,children:d.jsx(so,{present:n||s.open,children:d.jsx(pd,{asChild:!0,container:o,children:r})})})};iL.displayName=V1;var Ar="MenuContent",[jse,Y1]=va(Ar),aL=w.forwardRef((t,e)=>{const n=sL(Ar,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=Ci(Ar,t.__scopeMenu),i=yd(Ar,t.__scopeMenu);return d.jsx(Fu.Provider,{scope:t.__scopeMenu,children:d.jsx(so,{present:r||s.open,children:d.jsx(Fu.Slot,{scope:t.__scopeMenu,children:i.modal?d.jsx(Ose,{...o,ref:e}):d.jsx(Dse,{...o,ref:e})})})})}),Ose=w.forwardRef((t,e)=>{const n=Ci(Ar,t.__scopeMenu),r=w.useRef(null),o=Ze(e,r);return w.useEffect(()=>{const s=r.current;if(s)return b1(s)},[]),d.jsx(X1,{...t,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:oe(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Dse=w.forwardRef((t,e)=>{const n=Ci(Ar,t.__scopeMenu);return d.jsx(X1,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),X1=w.forwardRef((t,e)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,disableOutsideScroll:g,...m}=t,v=Ci(Ar,n),S=yd(Ar,n),y=md(n),b=nL(n),P=Ese(n),[C,I]=w.useState(null),T=w.useRef(null),_=Ze(e,T,v.onContentChange),k=w.useRef(0),M=w.useRef(""),R=w.useRef(0),j=w.useRef(null),O=w.useRef("right"),D=w.useRef(0),B=g?Wg:w.Fragment,z=g?{as:oa,allowPinchZoom:!0}:void 0,K=H=>{var $e,ot;const Y=M.current+H,ee=P().filter(Le=>!Le.disabled),ce=document.activeElement,ge=($e=ee.find(Le=>Le.ref.current===ce))==null?void 0:$e.textValue,Te=ee.map(Le=>Le.textValue),se=Gse(Te,Y,ge),We=(ot=ee.find(Le=>Le.textValue===se))==null?void 0:ot.ref.current;(function Le(at){M.current=at,window.clearTimeout(k.current),at!==""&&(k.current=window.setTimeout(()=>Le(""),1e3))})(Y),We&&setTimeout(()=>We.focus())};w.useEffect(()=>()=>window.clearTimeout(k.current),[]),w1();const N=w.useCallback(H=>{var ee,ce;return O.current===((ee=j.current)==null?void 0:ee.side)&&Yse(H,(ce=j.current)==null?void 0:ce.area)},[]);return d.jsx(jse,{scope:n,searchRef:M,onItemEnter:w.useCallback(H=>{N(H)&&H.preventDefault()},[N]),onItemLeave:w.useCallback(H=>{var Y;N(H)||((Y=T.current)==null||Y.focus(),I(null))},[N]),onTriggerLeave:w.useCallback(H=>{N(H)&&H.preventDefault()},[N]),pointerGraceTimerRef:R,onPointerGraceIntentChange:w.useCallback(H=>{j.current=H},[]),children:d.jsx(B,{...z,children:d.jsx(Hg,{asChild:!0,trapped:o,onMountAutoFocus:oe(s,H=>{var Y;H.preventDefault(),(Y=T.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(hd,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:d.jsx(wse,{asChild:!0,...b,dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:I,onEntryFocus:oe(l,H=>{S.isUsingKeyboardRef.current||H.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(V3,{role:"menu","aria-orientation":"vertical","data-state":CL(v.open),"data-radix-menu-content":"",dir:S.dir,...y,...m,ref:_,style:{outline:"none",...m.style},onKeyDown:oe(m.onKeyDown,H=>{const ee=H.target.closest("[data-radix-menu-content]")===H.currentTarget,ce=H.ctrlKey||H.altKey||H.metaKey,ge=H.key.length===1;ee&&(H.key==="Tab"&&H.preventDefault(),!ce&&ge&&K(H.key));const Te=T.current;if(H.target!==Te||!Cse.includes(H.key))return;H.preventDefault();const We=P().filter($e=>!$e.disabled).map($e=>$e.ref.current);tL.includes(H.key)&&We.reverse(),Kse(We)}),onBlur:oe(t.onBlur,H=>{H.currentTarget.contains(H.target)||(window.clearTimeout(k.current),M.current="")}),onPointerMove:oe(t.onPointerMove,Nu(H=>{const Y=H.target,ee=D.current!==H.clientX;if(H.currentTarget.contains(Y)&&ee){const ce=H.clientX>D.current?"right":"left";O.current=ce,D.current=H.clientX}}))})})})})})})});aL.displayName=Ar;var Rse="MenuGroup",q1=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"group",...r,ref:e})});q1.displayName=Rse;var Lse="MenuLabel",lL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});lL.displayName=Lse;var Lf="MenuItem",qI="menu.itemSelect",im=w.forwardRef((t,e)=>{const{disabled:n=!1,onSelect:r,...o}=t,s=w.useRef(null),i=yd(Lf,t.__scopeMenu),a=Y1(Lf,t.__scopeMenu),l=Ze(e,s),c=w.useRef(!1),u=()=>{const h=s.current;if(!n&&h){const p=new CustomEvent(qI,{bubbles:!0,cancelable:!0});h.addEventListener(qI,f=>r==null?void 0:r(f),{once:!0}),x1(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(cL,{...o,ref:l,disabled:n,onClick:oe(t.onClick,u),onPointerDown:h=>{var p;(p=t.onPointerDown)==null||p.call(t,h),c.current=!0},onPointerUp:oe(t.onPointerUp,h=>{var p;c.current||(p=h.currentTarget)==null||p.click()}),onKeyDown:oe(t.onKeyDown,h=>{const p=a.searchRef.current!=="";n||p&&h.key===" "||Fx.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});im.displayName=Lf;var cL=w.forwardRef((t,e)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=t,i=Y1(Lf,n),a=nL(n),l=w.useRef(null),c=Ze(e,l),[u,h]=w.useState(!1),[p,f]=w.useState("");return w.useEffect(()=>{const g=l.current;g&&f((g.textContent??"").trim())},[s.children]),d.jsx(Fu.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:d.jsx(bse,{asChild:!0,...a,focusable:!r,children:d.jsx(Ae.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:oe(t.onPointerMove,Nu(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:oe(t.onPointerLeave,Nu(g=>i.onItemLeave(g))),onFocus:oe(t.onFocus,()=>h(!0)),onBlur:oe(t.onBlur,()=>h(!1))})})})}),$se="MenuCheckboxItem",uL=w.forwardRef((t,e)=>{const{checked:n=!1,onCheckedChange:r,...o}=t;return d.jsx(gL,{scope:t.__scopeMenu,checked:n,children:d.jsx(im,{role:"menuitemcheckbox","aria-checked":$f(n)?"mixed":n,...o,ref:e,"data-state":J1(n),onSelect:oe(o.onSelect,()=>r==null?void 0:r($f(n)?!0:!n),{checkForDefaultPrevented:!1})})})});uL.displayName=$se;var dL="MenuRadioGroup",[Fse,Nse]=va(dL,{value:void 0,onValueChange:()=>{}}),hL=w.forwardRef((t,e)=>{const{value:n,onValueChange:r,...o}=t,s=Xt(r);return d.jsx(Fse,{scope:t.__scopeMenu,value:n,onValueChange:s,children:d.jsx(q1,{...o,ref:e})})});hL.displayName=dL;var pL="MenuRadioItem",fL=w.forwardRef((t,e)=>{const{value:n,...r}=t,o=Nse(pL,t.__scopeMenu),s=n===o.value;return d.jsx(gL,{scope:t.__scopeMenu,checked:s,children:d.jsx(im,{role:"menuitemradio","aria-checked":s,...r,ref:e,"data-state":J1(s),onSelect:oe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});fL.displayName=pL;var Z1="MenuItemIndicator",[gL,zse]=va(Z1,{checked:!1}),mL=w.forwardRef((t,e)=>{const{__scopeMenu:n,forceMount:r,...o}=t,s=zse(Z1,n);return d.jsx(so,{present:r||$f(s.checked)||s.checked===!0,children:d.jsx(Ae.span,{...o,ref:e,"data-state":J1(s.checked)})})});mL.displayName=Z1;var Bse="MenuSeparator",yL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});yL.displayName=Bse;var Use="MenuArrow",SL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=md(n);return d.jsx(Y3,{...o,...r,ref:e})});SL.displayName=Use;var Q1="MenuSub",[Hse,vL]=va(Q1),xL=t=>{const{__scopeMenu:e,children:n,open:r=!1,onOpenChange:o}=t,s=Ci(Q1,e),i=md(e),[a,l]=w.useState(null),[c,u]=w.useState(null),h=Xt(o);return w.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),d.jsx(K1,{...i,children:d.jsx(rL,{scope:e,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(Hse,{scope:e,contentId:as(),triggerId:as(),trigger:a,onTriggerChange:l,children:n})})})};xL.displayName=Q1;var Nc="MenuSubTrigger",wL=w.forwardRef((t,e)=>{const n=Ci(Nc,t.__scopeMenu),r=yd(Nc,t.__scopeMenu),o=vL(Nc,t.__scopeMenu),s=Y1(Nc,t.__scopeMenu),i=w.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:t.__scopeMenu},u=w.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return w.useEffect(()=>u,[u]),w.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),d.jsx(G1,{asChild:!0,...c,children:d.jsx(cL,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":CL(n.open),...t,ref:Ug(e,o.onTriggerChange),onClick:h=>{var p;(p=t.onClick)==null||p.call(t,h),!(t.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:oe(t.onPointerMove,Nu(h=>{s.onItemEnter(h),!h.defaultPrevented&&!t.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:oe(t.onPointerLeave,Nu(h=>{var f,g;u();const p=(f=n.content)==null?void 0:f.getBoundingClientRect();if(p){const m=(g=n.content)==null?void 0:g.dataset.side,v=m==="right",S=v?-5:5,y=p[v?"left":"right"],b=p[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+S,y:h.clientY},{x:y,y:p.top},{x:b,y:p.top},{x:b,y:p.bottom},{x:y,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:oe(t.onKeyDown,h=>{var f;const p=s.searchRef.current!=="";t.disabled||p&&h.key===" "||_se[r.dir].includes(h.key)&&(n.onOpenChange(!0),(f=n.content)==null||f.focus(),h.preventDefault())})})})});wL.displayName=Nc;var bL="MenuSubContent",PL=w.forwardRef((t,e)=>{const n=sL(Ar,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=Ci(Ar,t.__scopeMenu),i=yd(Ar,t.__scopeMenu),a=vL(bL,t.__scopeMenu),l=w.useRef(null),c=Ze(e,l);return d.jsx(Fu.Provider,{scope:t.__scopeMenu,children:d.jsx(so,{present:r||s.open,children:d.jsx(Fu.Slot,{scope:t.__scopeMenu,children:d.jsx(X1,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:oe(t.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:oe(t.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:oe(t.onKeyDown,u=>{var f;const h=u.currentTarget.contains(u.target),p=Ise[i.dir].includes(u.key);h&&p&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),u.preventDefault())})})})})})});PL.displayName=bL;function CL(t){return t?"open":"closed"}function $f(t){return t==="indeterminate"}function J1(t){return $f(t)?"indeterminate":t?"checked":"unchecked"}function Kse(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}function Wse(t,e){return t.map((n,r)=>t[(e+r)%t.length])}function Gse(t,e,n){const o=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,s=n?t.indexOf(n):-1;let i=Wse(t,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function Vse(t,e){const{x:n,y:r}=t;let o=!1;for(let s=0,i=e.length-1;s<e.length;i=s++){const a=e[s].x,l=e[s].y,c=e[i].x,u=e[i].y;l>r!=u>r&&n<(c-a)*(r-l)/(u-l)+a&&(o=!o)}return o}function Yse(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return Vse(n,e)}function Nu(t){return e=>e.pointerType==="mouse"?t(e):void 0}var _L=oL,IL=G1,EL=iL,kL=aL,TL=q1,ML=lL,AL=im,jL=uL,OL=hL,DL=fL,RL=mL,LL=yL,$L=SL,FL=xL,NL=wL,zL=PL,eb="ContextMenu",[Xse,Efe]=Lo(eb,[sm]),fn=sm(),[qse,BL]=Xse(eb),UL=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,dir:o,modal:s=!0}=t,[i,a]=w.useState(!1),l=fn(e),c=Xt(r),u=w.useCallback(h=>{a(h),c(h)},[c]);return d.jsx(qse,{scope:e,open:i,onOpenChange:u,modal:s,children:d.jsx(_L,{...l,dir:o,open:i,onOpenChange:u,modal:s,children:n})})};UL.displayName=eb;var HL="ContextMenuTrigger",KL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,disabled:r=!1,...o}=t,s=BL(HL,n),i=fn(n),a=w.useRef({x:0,y:0}),l=w.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=w.useRef(0),u=w.useCallback(()=>window.clearTimeout(c.current),[]),h=p=>{a.current={x:p.clientX,y:p.clientY},s.onOpenChange(!0)};return w.useEffect(()=>u,[u]),w.useEffect(()=>void(r&&u()),[r,u]),d.jsxs(d.Fragment,{children:[d.jsx(IL,{...i,virtualRef:l}),d.jsx(Ae.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...o,ref:e,style:{WebkitTouchCallout:"none",...t.style},onContextMenu:r?t.onContextMenu:oe(t.onContextMenu,p=>{u(),h(p),p.preventDefault()}),onPointerDown:r?t.onPointerDown:oe(t.onPointerDown,Ph(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?t.onPointerMove:oe(t.onPointerMove,Ph(u)),onPointerCancel:r?t.onPointerCancel:oe(t.onPointerCancel,Ph(u)),onPointerUp:r?t.onPointerUp:oe(t.onPointerUp,Ph(u))})]})});KL.displayName=HL;var Zse="ContextMenuPortal",tb=t=>{const{__scopeContextMenu:e,...n}=t,r=fn(e);return d.jsx(EL,{...r,...n})};tb.displayName=Zse;var WL="ContextMenuContent",GL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=BL(WL,n),s=fn(n),i=w.useRef(!1);return d.jsx(kL,{...s,...r,ref:e,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=t.onCloseAutoFocus)==null||l.call(t,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=t.onInteractOutside)==null||l.call(t,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});GL.displayName=WL;var Qse="ContextMenuGroup",VL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(TL,{...o,...r,ref:e})});VL.displayName=Qse;var Jse="ContextMenuLabel",eie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(ML,{...o,...r,ref:e})});eie.displayName=Jse;var tie="ContextMenuItem",YL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(AL,{...o,...r,ref:e})});YL.displayName=tie;var nie="ContextMenuCheckboxItem",XL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(jL,{...o,...r,ref:e})});XL.displayName=nie;var rie="ContextMenuRadioGroup",oie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(OL,{...o,...r,ref:e})});oie.displayName=rie;var sie="ContextMenuRadioItem",iie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(DL,{...o,...r,ref:e})});iie.displayName=sie;var aie="ContextMenuItemIndicator",lie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(RL,{...o,...r,ref:e})});lie.displayName=aie;var cie="ContextMenuSeparator",uie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(LL,{...o,...r,ref:e})});uie.displayName=cie;var die="ContextMenuArrow",hie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx($L,{...o,...r,ref:e})});hie.displayName=die;var pie="ContextMenuSub",qL=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,open:o,defaultOpen:s}=t,i=fn(e),[a,l]=Pi({prop:o,defaultProp:s,onChange:r});return d.jsx(FL,{...i,open:a,onOpenChange:l,children:n})};qL.displayName=pie;var fie="ContextMenuSubTrigger",ZL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(NL,{...o,...r,ref:e})});ZL.displayName=fie;var gie="ContextMenuSubContent",QL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=fn(n);return d.jsx(zL,{...o,...r,ref:e,style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});QL.displayName=gie;function Ph(t){return e=>e.pointerType!=="mouse"?t(e):void 0}var mie=UL,yie=KL,Sie=tb,vie=GL,xie=XL,nb="DropdownMenu",[wie,kfe]=Lo(nb,[sm]),gn=sm(),[bie,JL]=wie(nb),e$=t=>{const{__scopeDropdownMenu:e,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=t,l=gn(e),c=w.useRef(null),[u=!1,h]=Pi({prop:o,defaultProp:s,onChange:i});return d.jsx(bie,{scope:e,triggerId:as(),triggerRef:c,contentId:as(),open:u,onOpenChange:h,onOpenToggle:w.useCallback(()=>h(p=>!p),[h]),modal:a,children:d.jsx(_L,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:n})})};e$.displayName=nb;var t$="DropdownMenuTrigger",n$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=t,s=JL(t$,n),i=gn(n);return d.jsx(IL,{asChild:!0,...i,children:d.jsx(Ae.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:Ug(e,s.triggerRef),onPointerDown:oe(t.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:oe(t.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});n$.displayName=t$;var Pie="DropdownMenuPortal",r$=t=>{const{__scopeDropdownMenu:e,...n}=t,r=gn(e);return d.jsx(EL,{...r,...n})};r$.displayName=Pie;var o$="DropdownMenuContent",s$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=JL(o$,n),s=gn(n),i=w.useRef(!1);return d.jsx(kL,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:e,onCloseAutoFocus:oe(t.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:oe(t.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});s$.displayName=o$;var Cie="DropdownMenuGroup",i$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(TL,{...o,...r,ref:e})});i$.displayName=Cie;var _ie="DropdownMenuLabel",Iie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(ML,{...o,...r,ref:e})});Iie.displayName=_ie;var Eie="DropdownMenuItem",a$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(AL,{...o,...r,ref:e})});a$.displayName=Eie;var kie="DropdownMenuCheckboxItem",l$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(jL,{...o,...r,ref:e})});l$.displayName=kie;var Tie="DropdownMenuRadioGroup",Mie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(OL,{...o,...r,ref:e})});Mie.displayName=Tie;var Aie="DropdownMenuRadioItem",jie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(DL,{...o,...r,ref:e})});jie.displayName=Aie;var Oie="DropdownMenuItemIndicator",Die=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(RL,{...o,...r,ref:e})});Die.displayName=Oie;var Rie="DropdownMenuSeparator",Lie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(LL,{...o,...r,ref:e})});Lie.displayName=Rie;var $ie="DropdownMenuArrow",Fie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx($L,{...o,...r,ref:e})});Fie.displayName=$ie;var Nie=t=>{const{__scopeDropdownMenu:e,children:n,open:r,onOpenChange:o,defaultOpen:s}=t,i=gn(e),[a=!1,l]=Pi({prop:r,defaultProp:s,onChange:o});return d.jsx(FL,{...i,open:a,onOpenChange:l,children:n})},zie="DropdownMenuSubTrigger",c$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(NL,{...o,...r,ref:e})});c$.displayName=zie;var Bie="DropdownMenuSubContent",u$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=gn(n);return d.jsx(zL,{...o,...r,ref:e,style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});u$.displayName=Bie;var rb=e$,ob=n$,am=r$,sb=s$,Uie=i$,Hie=a$,Kie=l$,Wie=Nie,Gie=c$,Vie=u$;function bs(){const t=F();return U("isReadonlyMode",()=>t.getInstanceState().isReadonly,[t])}const cS=[0,389,436,476,580,640,840,1023];var Pt=(t=>(t[t.ZERO=0]="ZERO",t[t.MOBILE_XXS=1]="MOBILE_XXS",t[t.MOBILE_XS=2]="MOBILE_XS",t[t.MOBILE_SM=3]="MOBILE_SM",t[t.MOBILE=4]="MOBILE",t[t.TABLET_SM=5]="TABLET_SM",t[t.TABLET=6]="TABLET",t[t.DESKTOP=7]="DESKTOP",t))(Pt||{});const d$=Ie.createContext(null);function Yie({forceMobile:t=!1,children:e}){const n=F(),r=U("breakpoint",()=>{const{width:o}=n.getViewportScreenBounds(),s=t?Pt.MOBILE_SM:cS.length-1;for(let i=0;i<s;i++)if(o>cS[i]&&o<=cS[i+1])return i;return s},[n]);return d.jsx(d$.Provider,{value:r,children:e})}function kn(){const t=w.useContext(d$);if(t===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return t}const h$=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Xie=h$?"⌘":"Ctrl",qie=h$?"⌥":"Alt";function p$(t){return t===","?[","]:t.split(",")[0].split("").map(e=>{const n=e.replace(/\$/g,Xie).replace(/\?/g,qie).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function Nx(t){return"— "+p$(t).join(" ")}function ou({children:t,visibleOnMobileLayout:e=!1}){const n=kn();return!e&&n<Pt.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:p$(t).map((r,o)=>d.jsx("span",{children:r},o))})}const f$=w.createContext(null);function lm(){const t=w.useContext(f$);if(!t)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return t}function Dr({type:t,sourceId:e,children:n}){return d.jsx(f$.Provider,{value:{type:t,sourceId:e},children:n})}function cm({id:t,kbd:e,label:n,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=lm(),u=bs(),h=Ce();if(u&&!r)return null;const p=Ru(n,l),f=p?h(p):void 0;switch(l){case"menu":return d.jsxs(Kie,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:f,onSelect:g=>{o==null||o(c),we(g)},disabled:i,checked:a,children:[d.jsx(Mo,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),e&&d.jsx(ou,{children:e})]});case"context-menu":return d.jsxs(xie,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:f,onSelect:g=>{o(c),we(g)},disabled:i,checked:a,children:[d.jsx(Mo,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),e&&d.jsx(ou,{children:e})]},t);default:return null}}function lo({actionId:t="",...e}){const r=Sa()[t];return r?d.jsx(cm,{...r,...e}):null}function Zie(t){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...t,children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}function Ps(t,e){const n=F(),r=w.useRef(!1),o=Zt(),s=w.useCallback(a=>{r.current=a,n.run(()=>{a?(n.complete(),n.addOpenMenu(t)):n.updateInstanceState({openMenus:n.getOpenMenus().filter(l=>!l.startsWith(t))}),e==null||e(a)})},[n,t,e]),i=U("is menu open",()=>n.getOpenMenus().includes(t),[n,t]);return w.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:t}),n.addOpenMenu(t)),()=>{r.current&&(n.deleteOpenMenu(t),n.getOpenMenus().forEach(a=>{a.startsWith(t)&&(o("close-menu",{source:"unknown",id:t}),n.deleteOpenMenu(a))}),r.current=!1)}),[n,t,o]),[i,s]}function aa({id:t,children:e,modal:n=!1,debugOpen:r=!1}){const[o,s]=Ps(t);return d.jsx(rb,{open:r||o,dir:"ltr",modal:n,onOpenChange:s,children:e})}function la({children:t,...e}){return d.jsx(ob,{dir:"ltr",asChild:!0,onTouchEnd:n=>we(n),...e,children:t})}function ca({side:t="bottom",align:e="start",sideOffset:n=8,alignOffset:r=8,children:o}){const s=Lt();return d.jsx(am,{container:s,children:d.jsx(sb,{className:"tlui-menu",side:t,sideOffset:n,align:e,alignOffset:r,collisionPadding:4,children:o})})}function Qie({id:t,children:e}){const[n,r]=Ps(t);return d.jsx(Wie,{open:n,onOpenChange:r,children:e})}function Jie({id:t,label:e,title:n,disabled:r}){return d.jsx(Gie,{dir:"ltr",asChild:!0,disabled:r,children:d.jsxs(ue,{"data-testid":t,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:n,children:[d.jsx(wt,{children:e}),d.jsx(be,{icon:"chevron-right",small:!0})]})})}function eae({id:t,alignOffset:e=-1,sideOffset:n=-4,size:r="small",children:o}){const s=Lt();return d.jsx(am,{container:s,children:d.jsx(Vie,{"data-testid":t,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:n,collisionPadding:4,"data-size":r,children:o})})}function tae({children:t}){return d.jsx(Uie,{dir:"ltr",className:"tlui-menu__group",children:t})}function zu({noClose:t,children:e}){return d.jsx(Hie,{dir:"ltr",asChild:!0,onClick:t?we:void 0,children:e})}function Ht({disabled:t=!1,spinner:e=!1,readonlyOk:n=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:l,isSelected:c}){const{type:u,sourceId:h}=lm(),p=Ce(),[f,g]=w.useState(!1);if(bs()&&!n)return null;const v=Ru(s,u),S=o?Nx(o):void 0,y=v?p(v):void 0,b=y&&S?`${y} ${S}`:y;switch(u){case"menu":return d.jsx(zu,{children:d.jsxs(ue,{type:"menu","data-testid":`${h}.${r}`,disabled:t,title:b,onClick:P=>{l&&we(P),f?g(!1):a(h)},children:[d.jsx(wt,{children:y}),o&&d.jsx(ou,{children:o})]})});case"context-menu":return t?null:d.jsxs(YL,{dir:"ltr",title:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:P=>{l&&we(P),f?g(!1):a(h)},children:[d.jsx("span",{className:"tlui-button__label",draggable:!1,children:y}),o&&d.jsx(ou,{children:o}),e&&d.jsx(Zie,{})]});case"panel":return d.jsxs(ue,{"data-testid":`${h}.${r}`,type:"menu",title:b,disabled:t,onClick:()=>a(h),children:[d.jsx(wt,{children:y}),i&&d.jsx(be,{icon:i})]});case"small-icons":case"icons":return d.jsx(ue,{"data-testid":`${h}.${r}`,type:"icon",title:b,disabled:t,onClick:()=>a(h),children:d.jsx(be,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return o?d.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${h}.${r}`,children:[d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:y}),d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:d.jsx(ou,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return d.jsxs(ue,{type:"low",onClick:()=>a(h),children:[d.jsx(be,{icon:i}),d.jsx(wt,{children:y})]});case"toolbar":return d.jsx(ue,{type:"tool","data-testid":`tools.${r}`,"aria-label":v,"data-value":r,onClick:()=>a("toolbar"),title:b,disabled:t,onTouchStart:P=>{we(P),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:d.jsx(be,{icon:i})});case"toolbar-overflow":return d.jsx(zu,{"aria-label":s,children:d.jsx(ue,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:b,disabled:t,role:"radio","aria-checked":c?"true":"false","data-value":r,children:d.jsx(be,{icon:i})})});default:throw Tt(u)}}function W({actionId:t="",...e}){const r=Sa()[t];return r?d.jsx(Ht,{...r,...e}):null}const g$=w.createContext(null);function nae({overrides:t,children:e}){const n=F(),r=Zt(),{addDialog:o}=ya(),s=_3(),i=w.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){n.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){n.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){n.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){n.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...Vr.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){n.run(()=>{n.setStyleForNextShapes(Vr,c),n.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){n.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){n.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){n.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){n.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){s(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){n.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){n.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(c){o({component:e3}),r("select-tool",{source:c,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){n.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}}];a.push();const l=Object.fromEntries(a.map(c=>[c.id,c]));return t?t(n,l,{insertMedia:s}):l},[t,n,r,s,o]);return d.jsx(g$.Provider,{value:i,children:e})}function ib(){const t=w.useContext(g$);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function On({toolId:t="",...e}){const r=ib()[t];return r?d.jsx(Ht,{...r,...e}):null}function rae({children:t}){const e=F();return U("shouldDisplayHandles",()=>{if(e.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(e.isInAny("select.editing_shape")){const r=e.getOnlySelectedShape();return r&&e.isShapeOfType(r,"note")}return!1},[e])?d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:t}):null}const{PI:oae}=Math,ml=oae+1e-4;function m$(t,e={}){const{size:n=16,smoothing:r=.5}=e;if(t.length===0||n<=0)return{left:[],right:[]};const o=t[0],s=t[t.length-1],i=s.runningLength,a=Math.pow(n*r,2),l=[],c=[];let u=t[0].vector,h=t[0].point,p=h,f=h,g=p,m=!1,v;for(let S=0;S<t.length;S++){v=t[S];const{point:y,vector:b}=t[S],P=v.vector.dpr(u),C=(S<t.length-1?t[S+1]:t[S]).vector,I=S<t.length-1?C.dpr(v.vector):1,T=P<0&&!m,_=I!==null&&I<.2;if(T||_){if(I>-.62&&i-v.runningLength>v.radius){const M=u.clone().mul(v.radius);u.clone().cpr(C)<0?(f=x.Add(y,M),g=x.Sub(y,M)):(f=x.Sub(y,M),g=x.Add(y,M)),l.push(f),c.push(g)}else{const M=u.clone().mul(v.radius).per(),R=x.Sub(v.input,M);for(let j=1/13,O=0;O<1;O+=j)f=x.RotWith(R,v.input,ml*O),l.push(f),g=x.RotWith(R,v.input,ml+ml*-O),c.push(g)}h=f,p=g,_&&(m=!0);continue}if(m=!1,v===o||v===s){const M=x.Per(b).mul(v.radius);l.push(x.Sub(y,M)),c.push(x.Add(y,M));continue}const k=x.Lrp(C,b,I).per().mul(v.radius);f=x.Sub(y,k),(S<=1||x.Dist2(h,f)>a)&&(l.push(f),h=f),g=x.Add(y,k),(S<=1||x.Dist2(p,g)>a)&&(c.push(g),p=g),u=b}return{left:l,right:c}}function ab(t,e={}){const{size:n=16,start:r={},end:o={},last:s=!1}=e,{cap:i=!0}=r,{cap:a=!0}=o;if(t.length===0||n<=0)return[];const l=t[0],c=t[t.length-1],u=c.runningLength,h=r.taper===!1?0:r.taper===!0?Math.max(n,u):r.taper,p=o.taper===!1?0:o.taper===!0?Math.max(n,u):o.taper,{left:f,right:g}=m$(t,e),m=l.point,v=t.length>1?t[t.length-1].point:x.AddXY(l.point,1,1);if(t.length===1&&(!(h||p)||s)){const P=x.Add(m,x.Sub(m,v).uni().per().mul(-l.radius)),C=[];for(let I=1/13,T=I;T<=1;T+=I)C.push(x.RotWith(P,m,ml*2*T));return C}const S=[];if(!(h||p&&t.length===1))if(i)for(let P=1/8,C=P;C<=1;C+=P){const I=x.RotWith(g[0],m,ml*C);S.push(I)}else{const P=x.Sub(f[0],g[0]),C=x.Mul(P,.5),I=x.Mul(P,.51);S.push(x.Sub(m,C),x.Sub(m,I),x.Add(m,I),x.Add(m,C))}const y=[],b=c.vector.clone().per().neg();if(p||h&&t.length===1)y.push(v);else if(a){const P=x.Add(v,x.Mul(b,c.radius));for(let C=1/29,I=C;I<1;I+=C)y.push(x.RotWith(P,v,ml*3*I))}else y.push(x.Add(v,x.Mul(b,c.radius)),x.Add(v,x.Mul(b,c.radius*.99)),x.Sub(v,x.Mul(b,c.radius*.99)),x.Sub(v,x.Mul(b,c.radius)));return f.concat(y,g.reverse(),S)}const sae=.025,iae=.01;function jo(t,e={}){var v;const{streamline:n=.5,size:r=16,simulatePressure:o=!1}=e;if(t.length===0)return[];const s=.15+(1-n)*.85;let i=t.map(x.From),a=0;if(!o){let S=i[0];for(;S&&!(S.z>=sae);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=iae);)i.pop(),S=i[i.length-1]}if(i.length===0)return[{point:x.From(t[0]),input:x.From(t[0]),pressure:o?.5:.15,vector:new x(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(x.Dist2(l,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(x.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=e.last||!e.simulatePressure||i.length>1&&x.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&e.simulatePressure){const S=i[1];i=i.slice(0,-1);for(let y=1;y<5;y++){const b=x.Lrp(i[0],S,y/4);b.z=(i[0].z+(S.z-i[0].z))*y/4,i.push(b)}}const h=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new x(1,1),distance:0,runningLength:0,radius:1}];let p=0,f=h[0],g,m;u&&n>0&&i.push(i[i.length-1].clone());for(let S=1,y=i.length;S<y;S++)g=!s||e.last&&S===y-1?i[S].clone():i[S].clone().lrp(f.point,1-s),!f.point.equals(g)&&(m=x.Dist(g,f.point),p+=m,!(S<4&&p<r)&&(f={input:i[S],point:g,pressure:o?.5:i[S].z,vector:x.Sub(f.point,g).uni(),distance:m,runningLength:p,radius:1},h.push(f)));if((v=h[1])!=null&&v.vector&&(h[0].vector=h[1].vector.clone()),p<1){const S=Math.max(.5,...h.map(y=>y.pressure));h.forEach(y=>y.pressure=S)}return h}const{min:As}=Math,uS=.275;function um(t,e){const{size:n=16,thinning:r=.5,simulatePressure:o=!0,easing:s=v=>v,start:i={},end:a={}}=e,{easing:l=At.easeOutQuad}=i,{easing:c=At.easeOutCubic}=a,u=t[t.length-1].runningLength;let h,p=t[0].pressure,f;if(!o&&u<n){const v=t.reduce((S,y)=>Math.max(S,y.pressure),.5);return t.forEach(S=>{S.pressure=v,S.radius=n*s(.5-r*(.5-S.pressure))}),t}else{let v;for(let S=0,y=t.length;S<y&&(f=t[S],!(f.runningLength>n*5));S++){const b=As(1,f.distance/n);if(o){const P=As(1,1-b);v=As(1,p+(P-p)*(b*uS))}else v=As(1,p+(f.pressure-p)*.5);p=p+(v-p)*.5}for(let S=0;S<t.length;S++){if(f=t[S],r){let{pressure:y}=f;const b=As(1,f.distance/n);if(o){const P=As(1,1-b);y=As(1,p+(P-p)*(b*uS))}else y=As(1,p+(y-p)*(b*uS));f.radius=n*s(.5-r*(.5-y)),p=y}else f.radius=n/2;h===void 0&&(h=f.radius)}}const g=i.taper===!1?0:i.taper===!0?Math.max(n,u):i.taper,m=a.taper===!1?0:a.taper===!0?Math.max(n,u):a.taper;if(g||m)for(let v=0;v<t.length;v++){f=t[v];const{runningLength:S}=f,y=S<g?l(S/g):1,b=u-S<m?c((u-S)/m):1;f.radius=Math.max(.01,f.radius*Math.min(y,b))}return t}function aae(t,e={}){return ab(um(jo(t,e),e),e)}function ZI({scribble:t,zoom:e,color:n,opacity:r,className:o}){if(!t.points.length)return null;const s=aae(t.points,{size:t.size/e,start:{taper:t.taper,easing:At.linear},last:t.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(s.length<4){const a=t.size/e/2,{x:l,y:c}=t.points[t.points.length-1];i=`M ${l-a},${c} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=Jw(s);return d.jsx("svg",{className:o&&le("tl-overlays__item",o),children:d.jsx("path",{className:"tl-scribble",d:i,fill:n??`var(--color-${t.color})`,opacity:r??t.opacity})})}const lae=({bounds:t,rotation:e})=>{const n=F();return U("should display",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[n])?d.jsx(YA,{bounds:t,rotation:e}):null};function cae({size:t,width:e,height:n,hideAlternateHandles:r}){const o=$(t/3),s=o/2;return d.jsxs("svg",{className:"tl-overlays__item",children:[d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
342
- ${$(0-s)},${$(t)}
343
- ${$(0-s)},${$(0-s)}
344
- ${$(t)},${$(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:$(e/2-t),y1:$(0-s),x2:$(e/2+t),y2:$(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),d.jsx("polyline",{className:le("tl-corner-crop-handle",{"tl-hidden":r}),points:`
345
- ${$(e-t)},${$(0-s)}
346
- ${$(e+s)},${$(0-s)}
347
- ${$(e+s)},${$(t)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:$(e+s),y1:$(n/2-t),x2:$(e+s),y2:$(n/2+t),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
348
- ${$(e+s)},${$(n-t)}
349
- ${$(e+s)},${$(n+s)}
350
- ${$(e-t)},${$(n+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:$(e/2-t),y1:$(n+s),x2:$(e/2+t),y2:$(n+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),d.jsx("polyline",{className:le("tl-corner-crop-handle",{"tl-hidden":r}),points:`
351
- ${$(0+t)},${$(n+s)}
352
- ${$(0-s)},${$(n+s)}
353
- ${$(0-s)},${$(n-t)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:$(0-s),y1:$(n/2-t),x2:$(0-s),y2:$(n/2+t),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const uae=Rt(function({bounds:e,rotation:n}){const r=F(),o=w.useRef(null),s=bs(),i=go("top"),a=go("right"),l=go("bottom"),c=go("left"),u=go("top_left"),h=go("top_right"),p=go("bottom_right"),f=go("bottom_left"),g=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,v=r.getOnlySelectedShape(),S=v&&r.isShapeOrAncestorLocked(v),y=v?r.getShapeUtil(v).expandSelectionOutlinePx(v):0;if(Kl(o,e==null?void 0:e.x,e==null?void 0:e.y,1,r.getSelectionRotation(),{x:-y,y:-y}),v&&r.isShapeHidden(v)||!e)return null;e=e.clone().expandBy(y).zeroFix();const b=r.getZoomLevel(),P=r.getInstanceState().isChangingStyle,C=e.width,I=e.height,T=8/b,_=C<T*2,k=I<T*2,M=C<T*4,R=I<T*4,j=C<T*5,O=I<T*5,D=m?1.75:1,B=6/b*D,z=(M?B/2:B)*(D*.75),K=(R?B/2:B)*(D*.75),N=(v?!r.getShapeUtil(v).hideSelectionBoundsFg(v):!0)&&!P;let H=N&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle","select.pointing_resize_handle")||N&&r.isIn("select.resizing")&&v&&r.isShapeOfType(v,"text");v&&H&&r.environment.isFirefox&&r.isShapeOfType(v,"embed")&&(H=!1);const Y=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!P&&!s,ee=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!P&&!s,ce=!m&&!(_||k)&&(ee||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!S,ge=m&&(!M||!R)&&(ee||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!S,Te=ee&&(v?r.getShapeUtil(v).canResize(v)&&!r.getShapeUtil(v).hideResizeHandles(v):!0)&&!Y&&!S,se=_||k,We=_&&k,$e=j||O,ot=Te||Y,Le=!ce,at=!ee||!ge,Be=!ee||!ot,Zn=!ee||!ot||se,$t=!ee||!ot||se,Mn=!ee||!ot||We&&!Y;let yt=!0,Qt=!0;if(Y)yt=$e,Qt=$e;else if(Te){yt=se||We||m;const _s=m&&v&&v.type==="text";Qt=yt&&!_s}const No=Math.min(24/b,I-K*3),Ql=ee&&m&&v&&r.isShapeOfType(v,"text")&&No*b>=4;return d.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsxs("g",{ref:o,children:[H&&d.jsx("rect",{className:"tl-selection__fg__outline",width:$(C),height:$(I)}),d.jsx(Ch,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:B,corner:"top_left_rotate",cursor:g?Jn("nwse-rotate",n):void 0,isHidden:Le}),d.jsx(Ch,{"data-testid":"selection.rotate.top-right",cx:C+B*3,cy:0,targetSize:B,corner:"top_right_rotate",cursor:g?Jn("nesw-rotate",n):void 0,isHidden:Le}),d.jsx(Ch,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:I+B*3,targetSize:B,corner:"bottom_left_rotate",cursor:g?Jn("swne-rotate",n):void 0,isHidden:Le}),d.jsx(Ch,{"data-testid":"selection.rotate.bottom-right",cx:C+B*3,cy:I+B*3,targetSize:B,corner:"bottom_right_rotate",cursor:g?Jn("senw-rotate",n):void 0,isHidden:Le}),d.jsx(hae,{"data-testid":"selection.rotate.mobile",cx:M?-B*1.5:C/2,cy:M?I/2:-B*1.5,size:T,isHidden:at}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":yt}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:$(0-(R?K*2:K)),width:$(C),height:$(Math.max(1,K*2)),style:g?{cursor:Jn("ns-resize",n)}:void 0,...i}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Qt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:$(C-(M?0:z)),y:0,height:$(I),width:$(Math.max(1,z*2)),style:g?{cursor:Jn("ew-resize",n)}:void 0,...a}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":yt}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:$(I-(R?0:K)),width:$(C),height:$(Math.max(1,K*2)),style:g?{cursor:Jn("ns-resize",n)}:void 0,...l}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Qt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:$(0-(M?z*2:z)),y:0,height:$(I),width:$(Math.max(1,z*2)),style:g?{cursor:Jn("ew-resize",n)}:void 0,...c}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Be}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:$(0-(M?z*2:z*1.5)),y:$(0-(R?K*2:K*1.5)),width:$(z*3),height:$(K*3),style:g?{cursor:Jn("nwse-resize",n)}:void 0,...u}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Zn}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:$(C-(M?0:z*1.5)),y:$(0-(R?K*2:K*1.5)),width:$(z*3),height:$(K*3),style:g?{cursor:Jn("nesw-resize",n)}:void 0,...h}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Mn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:$(C-(M?z:z*1.5)),y:$(I-(R?K:K*1.5)),width:$(z*3),height:$(K*3),style:g?{cursor:Jn("nwse-resize",n)}:void 0,...p}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":$t}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:$(0-(M?z*3:z*1.5)),y:$(I-(R?0:K*1.5)),width:$(z*3),height:$(K*3),style:g?{cursor:Jn("nesw-resize",n)}:void 0,...f}),Te&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.resize.top-left",className:le("tl-corner-handle",{"tl-hidden":Be}),"aria-label":"top_left handle",x:$(0-T/2),y:$(0-T/2),width:$(T),height:$(T)}),d.jsx("rect",{"data-testid":"selection.resize.top-right",className:le("tl-corner-handle",{"tl-hidden":Zn}),"aria-label":"top_right handle",x:$(C-T/2),y:$(0-T/2),width:$(T),height:$(T)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:le("tl-corner-handle",{"tl-hidden":Mn}),"aria-label":"bottom_right handle",x:$(C-T/2),y:$(I-T/2),width:$(T),height:$(T)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:le("tl-corner-handle",{"tl-hidden":$t}),"aria-label":"bottom_left handle",x:$(0-T/2),y:$(I-T/2),width:$(T),height:$(T)})]}),Ql&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:$(0-T/4),y:$(I/2-No/2),rx:T/4,width:$(T/2),height:$(No)}),d.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:T/4,x:$(C-T/4),y:$(I/2-No/2),width:$(T/2),height:$(No)})]}),Y&&d.jsx(cae,{size:T,width:C,height:I,hideAlternateHandles:$e})]})})}),Ch=function({cx:e,cy:n,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=go(o);return d.jsx("rect",{className:le("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:$(e-r*3),y:$(n-r*3),width:$(Math.max(1,r*3)),height:$(Math.max(1,r*3)),cursor:s,...l})},dae=Math.sqrt(Math.PI),hae=function({cx:e,cy:n,size:r,isHidden:o,"data-testid":s}){const i=go("mobile_rotate"),a=F(),l=U("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return d.jsxs("g",{children:[d.jsx("circle",{"data-testid":s,pointerEvents:"all",className:le("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:e,cy:n,r:c,...i}),d.jsx("circle",{className:le("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:e,cy:n,r:r/dae})]})};function pae(){const t=F();return U("is in a valid select state",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle"),[t])?d.jsx(XA,{}):null}function zx(t,e,n){const{arrowheadStart:r,arrowheadEnd:o}=e.props,s=tl(t,e,n),i=s.start.clone(),a=s.end.clone(),l=x.Med(i,a);if(x.Equals(i,a))return{bindings:n,isStraight:!0,start:{handle:i,point:i,arrowhead:e.props.arrowheadStart},end:{handle:a,point:a,arrowhead:e.props.arrowheadEnd},middle:l,isValid:!1,length:0};const c=x.Sub(a,i).uni(),u=Ff(t,e,"start"),h=Ff(t,e,"end"),p=t.getShapePageTransform(e);QI(a,s.start,p,h),QI(i,s.end,p,u);let f=0,g=0,m=0,v=0,S=nl*e.props.scale;const y=u&&h&&u.shape===h.shape,b=u&&h?lb(t,u.shape.id,h.shape.id):"safe";b==="safe"&&u&&h&&!y&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(nl*e.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(nl*e.props.scale))));const P=x.Sub(a,i),C=x.Len(P)?P.uni():x.From(P),I=!x.Equals(C,c);y||(b!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(m=bo[e.props.size]/2+("size"in u.shape.props?bo[u.shape.props.size]/2:0),f=(Nf+m)*e.props.scale,S+=m*e.props.scale),b!=="end-contains-start"&&h&&o!=="none"&&!h.isExact&&(v=bo[e.props.size]/2+("size"in h.shape.props?bo[h.shape.props.size]/2:0),g=(Nf+v)*e.props.scale,S+=v*e.props.scale));const T=i.clone().add(C.clone().mul(f*(I?-1:1))),_=a.clone().sub(C.clone().mul(g*(I?-1:1)));x.DistMin(T,_,S)&&(f!==0&&g!==0?(f*=-1.5,g*=-1.5):f!==0?f*=-1:g!==0&&(g*=-1)),i.add(C.clone().mul(f*(I?-1:1))),a.sub(C.clone().mul(g*(I?-1:1))),I?(u&&h&&a.setTo(x.Add(i,C.clone().mul(-nl*e.props.scale))),l.setTo(x.Med(s.start,s.end))):l.setTo(x.Med(i,a));const k=x.Dist(i,a);return{bindings:n,isStraight:!0,start:{handle:s.start,point:i,arrowhead:e.props.arrowheadStart},end:{handle:s.end,point:a,arrowhead:e.props.arrowheadEnd},middle:l,isValid:k>0,length:k}}function QI(t,e,n,r){if(r===void 0||r.isExact)return;const o=q.applyToPoint(n,e),s=q.applyToPoint(n,t),i=q.applyToPoint(q.Inverse(r.transform),o),a=q.applyToPoint(q.Inverse(r.transform),s),l=r.isClosed,u=(l?o1:sZ)(i,a,r.outline);let h;if(u!==null&&(h=u.sort((g,m)=>x.Dist2(g,i)-x.Dist2(m,i))[0]??(l?void 0:a)),h===void 0)return;const p=q.applyToPoint(r.transform,h),f=q.applyToPoint(q.Inverse(n),p);t.setTo(f),r.didIntersect=!0}function fae(t,e,n){const{arrowheadEnd:r,arrowheadStart:o}=e.props,s=e.props.bend;if(Math.abs(s)>Math.abs(e.props.bend*(vae*e.props.scale)))return zx(t,e,n);const i=tl(t,e,n),a=x.Med(i.start,i.end),l=x.Sub(i.end,i.start),c=x.Len(l)?l.uni():x.From(l),u=x.Add(a,c.per().mul(-s)),h=Ff(t,e,"start"),p=Ff(t,e,"end"),f=i.start.clone(),g=i.end.clone(),m=u.clone();if(x.Equals(f,g))return{bindings:n,isStraight:!0,start:{handle:f,point:f,arrowhead:e.props.arrowheadStart},end:{handle:g,point:g,arrowhead:e.props.arrowheadEnd},middle:m,isValid:!1,length:0};const v=e.props.bend<0,S=v?ed:EA,y=JI(f,g,m),b=x.Angle(y.center,f),P=x.Angle(y.center,g),C=S(b,P);if(y.length===0||y.size===0||!A_(y.length)||!A_(y.size))return zx(t,e,n);const I=f.clone(),T=g.clone(),_=m.clone(),k=t.getShapePageTransform(e);let M=0,R=0,j=nl*e.props.scale;if(h&&!h.isExact){const Y=q.applyToPoint(k,I),ee=q.applyToPoint(k,y.center),ce=q.applyToPoint(k,T),ge=q.Inverse(h.transform),Te=q.applyToPoint(ge,Y),se=q.applyToPoint(ge,ee),We=q.applyToPoint(ge,ce),{isClosed:$e}=h,ot=$e?px:Q_;let Le,at=ot(se,y.radius,h.outline);if(at){const Be=se.angle(Te),Zn=se.angle(We),$t=S(Be,Zn);at=at.filter(yt=>S(Be,se.angle(yt))<=$t);const Mn=$t*.25;at.sort($e?(yt,Qt)=>Math.abs(S(Be,se.angle(yt))-Mn)<Math.abs(S(Be,se.angle(Qt))-Mn)?-1:1:(yt,Qt)=>S(Be,se.angle(yt))<S(Be,se.angle(Qt))?-1:1),Le=at[0]??($e?void 0:Te)}else Le=$e?void 0:Te;if(Le&&(I.setTo(t.getPointInShapeSpace(e,q.applyToPoint(h.transform,Le))),h.didIntersect=!0,o!=="none")){const Be=bo[e.props.size]/2+("size"in h.shape.props?bo[h.shape.props.size]/2:0);M=(Nf+Be)*e.props.scale,j+=Be*e.props.scale}}if(p&&!p.isExact){const Y=q.applyToPoint(k,I),ee=q.applyToPoint(k,T),ce=q.applyToPoint(k,y.center),ge=q.Inverse(p.transform),Te=q.applyToPoint(ge,Y),se=q.applyToPoint(ge,ce),We=q.applyToPoint(ge,ee),$e=p.isClosed,ot=$e?px:Q_;let Le,at=ot(se,y.radius,p.outline);if(at){const Be=se.angle(Te),Zn=se.angle(We),$t=S(Be,Zn),Mn=$t*.75;at=at.filter(yt=>S(Be,se.angle(yt))<=$t),at.sort($e?(yt,Qt)=>Math.abs(S(Be,se.angle(yt))-Mn)<Math.abs(S(Be,se.angle(Qt))-Mn)?-1:1:(yt,Qt)=>S(Be,se.angle(yt))<S(Be,se.angle(Qt))?-1:1),at[0]?Le=at[0]:Le=$e?void 0:We}else Le=$e?void 0:We;if(Le&&(T.setTo(t.getPointInShapeSpace(e,q.applyToPoint(p.transform,Le))),p.didIntersect=!0,r!=="none")){const Be=bo[e.props.size]/2+("size"in p.shape.props?bo[p.shape.props.size]/2:0);R=(Nf+Be)*e.props.scale,j+=Be*e.props.scale}}let O=x.Angle(y.center,I),D=x.Angle(y.center,T),B=S(O,D),z=B*y.radius;const K=I.clone(),N=T.clone();if(M!==0&&K.setTo(y.center).add(x.FromAngle(O+B*(M/z*(v?1:-1))).mul(y.radius)),R!==0&&N.setTo(y.center).add(x.FromAngle(D+B*(R/z*(v?-1:1))).mul(y.radius)),x.DistMin(K,N,j)&&(M!==0&&R!==0?(M*=-1.5,R*=-1.5):M!==0?M*=-2:R!==0&&(R*=-2)),M!==0&&I.setTo(y.center).add(x.FromAngle(O+B*(M/z*(v?1:-1))).mul(y.radius)),R!==0&&T.setTo(y.center).add(x.FromAngle(D+B*(R/z*(v?-1:1))).mul(y.radius)),h&&p&&!h.isExact&&!p.isExact){O=x.Angle(y.center,I),D=x.Angle(y.center,T),B=S(O,D),z=B*y.radius;const Y=lb(t,h.shape.id,p.shape.id);Y==="double-bound"&&z<30?(I.setTo(f),T.setTo(g),_.setTo(m)):Y==="safe"&&(h&&!h.didIntersect&&I.setTo(f),(p&&!p.didIntersect||S(b,O)>S(b,D))&&T.setTo(y.center).add(x.FromAngle(O+B*(Math.min(.9,nl*e.props.scale/z)*(v?1:-1))).mul(y.radius)))}gae(y.center,y.radius,I,T,_,C,v),I.equals(T)&&(I.setTo(_.clone().addXY(1,1)),T.setTo(_.clone().subXY(1,1))),f.setTo(I),g.setTo(T),m.setTo(_);const H=JI(f,g,m);return{bindings:n,isStraight:!1,start:{point:f,handle:i.start,arrowhead:e.props.arrowheadStart},end:{point:g,handle:i.end,arrowhead:e.props.arrowheadEnd},middle:m,handleArc:y,bodyArc:H,isValid:H.length!==0&&isFinite(H.center.x)&&isFinite(H.center.y)}}function JI(t,e,n){const r=qw(t,e,n)??x.Med(t,e),o=x.Dist(r,t),s=+x.Clockwise(t,n,e),i=((t.y-e.y)**2+(t.x-e.x)**2)**.5,a=((e.y-n.y)**2+(e.x-n.x)**2)**.5,l=((n.y-t.y)**2+(n.x-t.x)**2)**.5,c=Math.acos((a*a+l*l-i*i)/(2*a*l))*2,u=+(De>c),h=(Fe-c)*(s?1:-1),p=h*o;return{center:r,radius:o,size:h,length:p,largeArcFlag:u,sweepFlag:s}}function gae(t,e,n,r,o,s,i){const a=x.Angle(t,n),l=x.Angle(t,r);let c=ed(a,l);if(i||(c=Fe-c),o.setTo(t).add(x.FromAngle(a+c*(.5*(i?1:-1))).mul(e)),c>s){o.rotWith(t,De);const u=r.clone();r.setTo(n),n.setTo(u)}}const mae=8;function yae(t){return Math.abs(t.props.bend)<mae*t.props.scale}function Ff(t,e,n){const r=t.getBindingsFromShape(e,"arrow").find(l=>l.props.terminal===n);if(!r)return;const o=t.getShape(r.toId);if(!o)return;const s=t.getShapePageTransform(o),i=t.getShapeGeometry(o),a=i instanceof eo?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function eE(t,e,n,r){const o=t.getShape(n.toId);if(o){const{point:s,size:i}=t.getShapeGeometry(o).bounds,a=x.Add(s,x.MulV(n.props.isPrecise||r?n.props.normalizedAnchor:{x:.5,y:.5},i)),l=q.applyToPoint(t.getShapePageTransform(o),a);return q.applyToPoint(q.Inverse(e),l)}else return new x(0,0)}function Fn(t,e){const n=t.getBindingsFromShape(e,"arrow");return{start:n.find(r=>r.props.terminal==="start"),end:n.find(r=>r.props.terminal==="end")}}const Sae=oV("arrow info",(t,e)=>{const n=Fn(t,e);return yae(e)?zx(t,e,n):fae(t,e,n)});function wo(t,e){const n=typeof e=="string"?e:e.id;return Sae.get(t,n)}function tl(t,e,n){var a,l;const r=t.getShapePageTransform(e),o=lb(t,(a=n.start)==null?void 0:a.toId,(l=n.end)==null?void 0:l.toId),s=n.start?eE(t,r,n.start,o==="double-bound"||o==="start-contains-end"):x.From(e.props.start),i=n.end?eE(t,r,n.end,o==="double-bound"||o==="end-contains-start"):x.From(e.props.end);return{start:s,end:i}}function Cc(t,e,n,r){const o=typeof e=="string"?e:e.id,s=typeof n=="string"?n:n.id,i=t.getBindingsFromShape(o,"arrow").filter(l=>l.props.terminal===r.terminal);i.length>1&&t.deleteBindings(i.slice(1));const a=i[0];a?t.updateBinding({...a,toId:s,props:r}):t.createBinding({type:"arrow",fromId:o,toId:s,props:r})}function sp(t,e,n){const r=t.getBindingsFromShape(e,"arrow").filter(o=>o.props.terminal===n);t.deleteBindings(r)}const nl=10,Nf=10,vae=10,bo={s:2,m:3.5,l:5,xl:10};function lb(t,e,n){if(!e||!n)return"safe";if(e===n)return"double-bound";const r=t.getShapePageBounds(e),o=t.getShapePageBounds(n);if(r&&o){if(r.contains(o))return"start-contains-end";if(o.contains(r))return"end-contains-start"}return"safe"}class ip extends tp{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const n=this.editor.getShape(e.fromId);n&&dS(this.editor,n)}onAfterChange({bindingAfter:e}){const n=this.editor.getShape(e.fromId);n&&dS(this.editor,n)}onAfterChangeFromShape({shapeAfter:e}){dS(this.editor,e)}onAfterChangeToShape({binding:e}){y$(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const n=this.editor.getShape(e.fromId);n&&zf({editor:this.editor,arrow:n,terminal:e.props.terminal})}}E(ip,"type","arrow"),E(ip,"props",YM),E(ip,"migrations",XM);function y$(t,e){var v;const n=t.getShape(e);if(!n)return;const r=Fn(t,n),{start:o,end:s}=r,i=o?t.getShape(o.toId):void 0,a=s?t.getShape(s.toId):void 0,l=t.getAncestorPageId(n);if(!l)return;let c;if(i&&a)c=t.findCommonAncestor([i,a])??l;else if(i||a){const S=(v=i||a)==null?void 0:v.parentId;S&&S===n.parentId?c=n.parentId:c=l}else return;c&&c!==n.parentId&&t.reparentShapes([e],c);const u=t.getShape(e);if(!u)throw Error("no reparented arrow");const h=t.getShapeNearestSibling(u,i),p=t.getShapeNearestSibling(u,a);let f;if(h&&p)f=h.index>p.index?h:p;else if(h&&!p)f=h;else if(p&&!h)f=p;else return;let g;const m=t.getSortedChildIdsForParent(f.parentId).map(S=>t.getShape(S)).filter(S=>S.index>f.index);if(m.length){const S=m.find(y=>y.type!=="arrow");if(u.index>f.index&&(!S||u.index<S.index))return;g=Eu(f.index,m[0].index)}else g=vo(f.index);g!==u.index&&t.updateShapes([{id:e,type:"arrow",index:g}])}function dS(t,e){const n=Fn(t,e);for(const r of["start","end"]){const o=n[r];if(!o)continue;const s=t.getShape(o.toId),i=t.getAncestorPageId(e)===t.getAncestorPageId(s);(!s||!i)&&zf({editor:t,arrow:e,terminal:r,unbind:!0})}y$(t,e.id)}function zf({editor:t,arrow:e,terminal:n,unbind:r=!1,useHandle:o=!1}){const s=wo(t,e);if(!s)throw new Error("expected arrow info");const i=o?s.start.handle:s.start.point,a=o?s.end.handle:s.end.point,l=n==="start"?i:a,c={id:e.id,type:"arrow",props:{[n]:{x:l.x,y:l.y},bend:e.props.bend}};if(!s.isStraight){const u=n==="start"?i:s.start.handle,h=n==="end"?a:s.end.handle,p=x.Med(u,h),f=x.Sub(u,h).per().uni().mul(s.handleArc.radius*2*Math.sign(e.props.bend)),g=id(s.handleArc.center,x.Add(p,f),s.handleArc.center,s.handleArc.radius);Re((g==null?void 0:g.length)===1);const m=x.Dist(p,g[0])*Math.sign(e.props.bend);ti(m,c.props.bend)||(c.props.bend=m)}t.updateShape(c),r&&sp(t,e,n)}const S$=[ip],dn={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},un={s:2,m:3.5,l:5,xl:10},El={s:18,m:24,l:36,xl:44},ls={s:18,m:22,l:26,xl:32},xae={s:18,m:20,l:24,xl:28},ys={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},wae=20,Bf=4.25,Cr=16;function bae(t,e){const n=t.w/e.w,r=t.h/e.h;return n<=1&&r<=1?t:n>r?{w:t.w/n,h:t.h/n}:{w:t.w/r,h:t.h/r}}/*!
354
- * MIT License
355
- * Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
356
- * Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
357
- */const rl=" ",mn=class mn{static insertTextFirefox(e,n){e.setRangeText(n,e.selectionStart||0,e.selectionEnd||0,"end"),e.dispatchEvent(new InputEvent("input",{data:n,inputType:"insertText",isComposing:!1}))}static insert(e,n){const r=e.ownerDocument,o=r.activeElement;o!==e&&e.focus(),r.execCommand("insertText",!1,n)||mn.insertTextFirefox(e,n),o===r.body?e.blur():o instanceof HTMLElement&&o!==e&&o.focus()}static set(e,n){e.select(),mn.insert(e,n)}static getSelection(e){const{selectionStart:n,selectionEnd:r}=e;return e.value.slice(n||void 0,r||void 0)}static wrapSelection(e,n,r){const{selectionStart:o,selectionEnd:s}=e,i=mn.getSelection(e);mn.insert(e,n+i+(r??n)),e.selectionStart=(o||0)+n.length,e.selectionEnd=(s||0)+n.length}static replace(e,n,r){let o=0;e.value.replace(n,(...s)=>{const i=o+s[s.length-2],a=s[0].length;e.selectionStart=i,e.selectionEnd=i+a;const l=typeof r=="string"?r:r(...s);return mn.insert(e,l),e.selectionStart=i,o+=l.length-a,l})}static findLineEnd(e,n){const r=e.lastIndexOf(`
358
- `,n-1)+1;return e.charAt(r)!==" "?n:r+1}static indent(e){var a;const{selectionStart:n,selectionEnd:r,value:o}=e,s=o.slice(n,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const l=o.lastIndexOf(`
359
- `,n-1)+1,c=e.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${rl}`),h=u.length-c.length;e.setSelectionRange(l,r-1),mn.insert(e,u),e.setSelectionRange(n+1,r+h)}else mn.insert(e,rl)}static unindent(e){const{selectionStart:n,selectionEnd:r,value:o}=e,s=o.lastIndexOf(`
360
- `,n-1)+1,i=mn.findLineEnd(o,r),a=e.value.slice(s,i),l=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),c=a.length-l.length;e.setSelectionRange(s,i),mn.insert(e,l);const u=/\t| {1,2}/.exec(o.slice(s,n)),h=u?u[0].length:0,p=n-h;e.setSelectionRange(n-h,Math.max(p,r-c))}static indentCE(e){var l;const n=window.getSelection(),r=e.innerText,o=_h(e)??0,s=_h(e)??0,i=r.slice(o,s),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
361
- `,o-1)+1,u=r.slice(c,s-1),p=u.replace(/^|\n/g,`$&${rl}`).length-u.length;n&&n.setBaseAndExtent(e,o+1,e,s+p)}else{const c=window.getSelection();e.innerText=r.slice(0,o)+rl+r.slice(o),c==null||c.setBaseAndExtent(e,o+1,e,o+2)}}static unindentCE(e){const n=window.getSelection(),r=e.innerText,o=_h(e)??0,s=_h(e)??0,i=r.lastIndexOf(`
362
- `,o-1)+1,a=mn.findLineEnd(r,s),l=r.slice(i,a),c=l.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=l.length-c.length;if(n){n.setBaseAndExtent(e,i,e,a);const h=/\t| {1,2}/.exec(r.slice(i,o)),p=h?h[0].length:0,f=o-p;n.setBaseAndExtent(e,o-p,e,Math.max(f,s-u))}}static normalizeText(e){return e.replace(mn.fixNewLines,`
363
- `)}static normalizeTextForDom(e){return e.replace(mn.fixNewLines,`
364
- `).split(`
365
- `).map(n=>n||" ").join(`
366
- `)}};E(mn,"fixNewLines",/\r?\n|\r/g);let kl=mn;function _h(t){if(typeof window.getSelection>"u")return;const e=window.getSelection();if(!e)return;let n=0;if(e.rangeCount!==0){const r=e.getRangeAt(0),o=r.cloneRange();o.selectNodeContents(t),o.setEnd(r.endContainer,r.endOffset),n=o.toString().length}return n}const Pae=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function v$(t){return Pae.test(t)}function Cae(t){return t.replace(/\t/g,rl)}function _ae(t){const e=t.split(`
367
- `);for(;e[0]&&e[0].trim().length===0;)e.shift();let n=1/0;for(const r of e)if(r.trim().length>0){const o=r.length-r.trimStart().length;n=Math.min(n,o)}return e.map(r=>r.slice(n)).join(`
368
- `)}const x$={"&amp;":"&","&quot;":'"',"&apos;":"'","&#34;":'"',"&#38;":"&","&#39;":"'","&#8211;":"–","&#8212;":"—","&#8216;":"‘","&#8217;":"’","&#8220;":"“","&#8221;":"”","&#8230;":"…"},Iae=new RegExp(Object.keys(x$).join("|"),"g");function Eae(t){return t.replace(Iae,e=>x$[e])}function kae(t){return t.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function Tae(t){return kae(_ae(Cae(t)))}function Mae(t,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:s,msg:i}){t.registerExternalAssetHandler("file",async({file:a,assetId:l})=>{const c=r.includes(a.type),u=o.includes(a.type);!c&&!u&&s.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),Re(c||u,`File type not allowed: ${a.type}`),a.size>n&&s.addToast({title:i("assets.files.size-too-big"),severity:"error"}),Re(a.size<=n,`File size too big: ${(a.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`);const h=uC(await a.arrayBuffer());l=l??Ns.createId(h);const p=await tE(a,l,c,u);if(isFinite(e)){const f={w:p.props.w,h:p.props.h},g=bae(f,{w:e,h:e});f!==g&&sr.isStaticImageType(a.type)&&(p.props.w=g.w,p.props.h=g.h)}return p.props.src=await t.uploadAsset(p,a),Ns.create(p)}),t.registerExternalAssetHandler("url",async({url:a})=>{var c,u,h,p,f;let l;try{const m=await(await Jr(a,{method:"GET",mode:"no-cors"})).text(),v=new DOMParser().parseFromString(m,"text/html");l={image:((c=v.head.querySelector('meta[property="og:image"]'))==null?void 0:c.getAttribute("content"))??"",favicon:((u=v.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:u.getAttribute("href"))??((h=v.head.querySelector('link[rel="icon"]'))==null?void 0:h.getAttribute("href"))??"",title:((p=v.head.querySelector('meta[property="og:title"]'))==null?void 0:p.getAttribute("content"))??a,description:((f=v.head.querySelector('meta[property="og:description"]'))==null?void 0:f.getAttribute("content"))??""},l.image.startsWith("http")||(l.image=new URL(l.image,a).href),l.favicon.startsWith("http")||(l.favicon=new URL(l.favicon,a).href)}catch(g){console.error(g),s.addToast({title:i("assets.url.failed"),severity:"error"}),l={image:"",favicon:"",title:"",description:""}}return{id:Ns.createId(Lv(a)),typeName:"asset",type:"bookmark",props:{src:a,description:l.description,image:l.image,favicon:l.favicon,title:l.title},meta:{}}}),t.registerExternalContentHandler("svg-text",async({point:a,text:l})=>{const c=a??(t.inputs.shiftKey?t.inputs.currentPagePoint:t.getViewportPageBounds().center),u=new DOMParser().parseFromString(l,"image/svg+xml").querySelector("svg");if(!u)throw new Error("No <svg/> element present");let h=parseFloat(u.getAttribute("width")||"0"),p=parseFloat(u.getAttribute("height")||"0");if(!(h&&p)){document.body.appendChild(u);const g=u.getBoundingClientRect();document.body.removeChild(u),h=g.width,p=g.height}const f=await t.getAssetForExternalContent({type:"file",file:new File([l],"asset.svg",{type:"image/svg+xml"})});if(!f)throw Error("Could not create an asset");nE(t,[f],c)}),t.registerExternalContentHandler("embed",({point:a,url:l,embed:c})=>{const u=a??(t.inputs.shiftKey?t.inputs.currentPagePoint:t.getViewportPageBounds().center),{width:h,height:p}=c,f=Ne(),g={id:f,type:"embed",x:u.x-(h||450)/2,y:u.y-(p||450)/2,props:{w:h,h:p,url:l}};t.createShapes([g]).select(f)}),t.registerExternalContentHandler("files",async({point:a,files:l})=>{if(l.length>t.options.maxFilesAtOnce)throw Error("Too many files");const c=a??(t.inputs.shiftKey?t.inputs.currentPagePoint:t.getViewportPageBounds().center),u=new x(c.x,c.y),h=[],p=[];for(const f of l){if(f.size>n){s.addToast({title:i("assets.files.size-too-big"),severity:"error"}),console.warn(`File size too big: ${(f.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`);continue}if(!f.type){s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error("No mime type");continue}if(!r.concat(o).includes(f.type)){s.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),console.warn(`${f.name} not loaded - Mime type not allowed ${f.type}.`);continue}const g=r.includes(f.type),m=o.includes(f.type),v=uC(await f.arrayBuffer()),S=Ns.createId(v),y=await tE(f,S,g,m);let b;g&&(b=t.createTemporaryAssetPreview(S,f)),h.push(y),p.push({asset:y,file:f,temporaryAssetPreview:b})}Promise.allSettled(p.map(async f=>{try{const g=await t.getAssetForExternalContent({type:"file",file:f.file});if(!g)throw Error("Could not create an asset");t.updateAssets([{...g,id:f.asset.id}])}catch(g){s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(g);return}})),nE(t,h,u)}),t.registerExternalContentHandler("text",async({point:a,text:l})=>{const c=a??(t.inputs.shiftKey?t.inputs.currentPagePoint:t.getViewportPageBounds().center),u=t.getShapeUtil("text").getDefaultProps(),h=Tae(l),p=t.getOnlySelectedShape();if(p&&"text"in p.props){t.updateShapes([{id:p.id,type:p.type,props:{text:h}}]);return}let f,g,m,v="middle";const S=h.split(`
369
- `).length>1,y=v$(h);S&&(v=S?y?"end":"start":"middle");const b=t.textMeasure.measureText(h,{...dn,fontFamily:ys[u.font],fontSize:El[u.size],maxWidth:null}),P=Math.min(S?t.getViewportPageBounds().width*.9:920,Math.max(200,t.getViewportPageBounds().width*.9));if(b.w>P){const C=t.textMeasure.measureText(h,{...dn,fontFamily:ys[u.font],fontSize:El[u.size],maxWidth:P});f=C.w,g=C.h,m=!1,v=y?"end":"start"}else f=b.w,g=b.h,m=!0;c.y-g/2<t.getViewportPageBounds().minY+40&&(c.y=t.getViewportPageBounds().minY+40+g/2),t.createShapes([{id:Ne(),type:"text",x:c.x-f/2,y:c.y-g/2,props:{text:h,textAlign:v,autoSize:m,w:f}}])}),t.registerExternalContentHandler("url",async({point:a,url:l})=>{const c=t.getShapeUtil("embed"),u=c==null?void 0:c.getEmbedDefinition(l);if(u)return t.putExternalContent({type:"embed",url:u.url,point:a,embed:u.definition});const h=a??(t.inputs.shiftKey?t.inputs.currentPagePoint:t.getViewportPageBounds().center),p=Ns.createId(Lv(l)),f=Aae(t,l,h);let g=t.getAsset(p),m=!1;if(!g){m=!0;try{const v=await t.getAssetForExternalContent({type:"url",url:l});if(!v)throw Error("Could not create an asset");g=v}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}t.run(()=>{m&&t.createAssets([g]),t.updateShapes([{id:f.id,type:f.type,props:{assetId:g.id}}])})})}async function tE(t,e,n,r){let o=t.type;t.type==="video/quicktime"&&(o="video/mp4");const s=n?await sr.getImageSize(t):await sr.getVideoSize(t),i=await sr.isAnimated(t)||r;return{id:e,type:n?"image":"video",typeName:"asset",props:{name:t.name,src:"",w:s.w,h:s.h,fileSize:t.size,mimeType:o,isAnimated:i},meta:{}}}async function nE(t,e,n){if(!e.length)return[];const r=x.From(n),o=[];for(let s=0;s<e.length;s++){const i=e[s];switch(i.type){case"image":{o.push({id:Ne(),type:"image",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w;break}case"video":o.push({id:Ne(),type:"video",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w}}return t.run(()=>{const s=e.filter(i=>!t.getAsset(i.id));s.length&&t.createAssets(s),t.createShapes(o).select(...o.map(i=>i.id)),w$(t,n)}),o.map(s=>s.id)}function w$(t,e){const n=t.getViewportPageBounds();let r=t.getSelectionPageBounds();if(r){const o=r.center.sub(e);t.updateShapes(t.getSelectedShapes().map(s=>{const i=t.getShapeParentTransform(s).decompose().rotation,a=x.Rot(o,-i);return{id:s.id,type:s.type,x:s.x-a.x,y:s.y-a.y}}))}r=t.getSelectionPageBounds(),r&&!n.contains(r)&&t.zoomToSelection()}function Aae(t,e,n){const r={id:Ne(),type:"bookmark",x:n.x-150,y:n.y-160,opacity:1,props:{assetId:null,url:e}};return t.run(()=>{t.createShapes([r]).select(r.id),w$(t,n)}),t.getShape(r.id)}var CS;let jae=(CS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}onKeyUp(e){var n;if(e.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const r=this.editor.getOnlySelectedShape();r&&this.editor.getShapeUtil(r).canEdit(r)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(r.id),(n=this.editor.root.getCurrent())==null||n.transition("editing_shape",{...e,target:"shape",shape:r}))}}},E(CS,"id","idle"),CS);var _S;let Oae=(_S=class extends ie{constructor(){super(...arguments);E(this,"shape");E(this,"markId","");E(this,"preciseTimeout",-1);E(this,"didTimeout",!1)}onEnter(){this.markId="",this.didTimeout=!1;const n=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.canBindShapes({fromShape:"arrow",toShape:r,binding:"arrow"}),margin:0,hitInside:!0,renderingOnly:!0});n?this.editor.setHintingShapes([n.id]):this.createArrowShape(),this.startPreciseTimeout()}onExit(){this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()}onPointerMove(){if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:{id:"end",type:"vertex",index:"a3",x:0,y:0},isCreating:!0,creatingMarkId:this.markId||void 0,onInteractionEnd:"arrow"})}}onPointerUp(){this.cancel()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u;const{originPagePoint:n}=this.editor.inputs,r=Ne();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`),this.editor.createShape({id:r,type:"arrow",x:n.x,y:n.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=s.find(h=>h.id==="start"),c=(u=i.onHandleDrag)==null?void 0:u.call(i,o,{handle:{...l,x:0,y:0},isPrecise:!0,initial:a});c&&this.editor.updateShapes([c]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var o,s;const n=this.shape;if(!n)throw Error("expected shape");const r=this.editor.getShapeHandles(n);if(!r)throw Error("expected handles for arrow");{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=r.find(u=>u.id==="start"),c=(o=i.onHandleDrag)==null?void 0:o.call(i,n,{handle:{...l,x:0,y:0},isPrecise:this.didTimeout,initial:a});c&&this.editor.updateShapes([c])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint),c=r.find(h=>h.id==="end"),u=(s=i.onHandleDrag)==null?void 0:s.call(i,this.editor.getShape(n),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(n.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},E(_S,"id","pointing"),_S);class Bx extends ie{constructor(){super(...arguments);E(this,"shapeType","arrow")}static children(){return[jae,Oae]}}E(Bx,"id","arrow"),E(Bx,"initial","idle");class cb extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"initialShape");E(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");E(this,"util",this.editor.getShapeUtil(this.shapeType));E(this,"isPen",!1);E(this,"isPenOrStylus",!1);E(this,"segmentMode","free");E(this,"didJustShiftClickToExtendPreviousShapeLine",!1);E(this,"pagePointWhereCurrentSegmentChanged",{});E(this,"pagePointWhereNextSegmentChanged",null);E(this,"lastRecordedPoint",{});E(this,"mergeNextPoint",!1);E(this,"currentLineLength",0);E(this,"canDraw",!1);E(this,"markId",null)}onEnter(n){this.markId=null,this.info=n,this.canDraw=!this.editor.getIsMenuOpen(),this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.canDraw&&this.startShape()}onPointerMove(){const{inputs:n}=this.editor;if(this.isPen&&!n.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&n.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(this.isPenOrStylus?x.Dist(n.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=n.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape())}onKeyDown(n){if(n.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()}onKeyUp(n){if(n.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()}onExit(){this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()}canClose(){return this.shapeType!=="highlight"}getIsClosed(n,r,o){if(!this.canClose())return!1;const s=un[r],i=n[0].points[0],a=n[n.length-1],l=a.points[a.points.length-1];return i!==l&&this.currentLineLength>s*4*o&&x.DistMin(i,l,s*2*o)}startShape(){const{inputs:{originPagePoint:n,isPen:r}}=this.editor;this.markId=this.editor.markHistoryStoppingPoint("draw start");const{z:o=.5}=this.info.point;this.isPen=r,this.isPenOrStylus=r||o>0&&o<.5||o>.5&&o<1;const s=this.isPenOrStylus?o*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=n.clone(),this.initialShape){const a=this.editor.getShape(this.initialShape.id);if(a&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const l=Ut(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=Ut(l.points);if(!c)throw Error("Expected a previous point!");const{x:u,y:h}=this.editor.getPointInShapeSpace(a,n).toFixed(),p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+s.toFixed(2)},{x:u,y:h,z:+s.toFixed(2)}]},f=q.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=f,this.pagePointWhereNextSegmentChanged=null;const g=[...a.props.segments,p];this.currentLineLength<un[a.props.size]*4&&(this.currentLineLength=this.getLineLength(g));const m={id:a.id,type:this.shapeType,props:{segments:g}};this.canClose()&&(m.props.isClosed=this.getIsClosed(g,a.props.size,a.props.scale)),this.editor.updateShapes([m]);return}}this.pagePointWhereCurrentSegmentChanged=n.clone();const i=Ne();this.editor.createShapes([{id:i,type:this.shapeType,x:n.x,y:n.y,props:{isPen:this.isPenOrStylus,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+s.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(i)}updateDrawingShape(){const{initialShape:n}=this,{inputs:r}=this.editor;if(!n)return;const{id:o,props:{size:s,scale:i}}=n,a=this.editor.getShape(o);if(!a)return;const{segments:l}=a.props,{x:c,y:u,z:h}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),p=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,f={x:c,y:u,z:p};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:g}=this;if(g===null)throw Error("We should have a point where the segment changed");if(x.Dist2(g,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const v=Ut(l);if(!v)throw Error("Expected a previous segment!");const S=Ut(v.points);if(!S)throw Error("Expected a previous last point!");let y;const b=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(v.type==="straight"){this.currentLineLength+=x.Dist(S,b),y={type:"straight",points:[{...S},b]};const C=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=q.applyToPoint(C,S)}else y={type:"straight",points:[b,f]};const P={id:o,type:this.shapeType,props:{segments:[...l,y]}};this.canClose()&&(P.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([P])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:g}=this;if(g===null)throw Error("We should have a point where the segment changed");if(x.Dist2(g,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const v=l.slice(),S=v[v.length-1],y=Ut(S.points);if(!y)throw Error("No previous point!");const b={type:"free",points:[...x.PointsBetween(y,f,6).map(I=>({x:Zo(I.x),y:Zo(I.y),z:Zo(I.z)}))]},P=[...v,b];this.currentLineLength<un[a.props.size]*4&&(this.currentLineLength=this.getLineLength(P));const C={id:o,type:this.shapeType,props:{segments:P}};this.canClose()&&(C.props.isClosed=this.getIsClosed(P,s,i)),this.editor.updateShapes([C])}break}case"straight":{const g=l.slice(),m=g[g.length-1],{pagePointWhereCurrentSegmentChanged:v}=this,{ctrlKey:S,currentPagePoint:y}=this.editor.inputs;if(!v)throw Error("We should have a point where the segment changed");let b,P=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(P=!S,this.didJustShiftClickToExtendPreviousShapeLine=!1):P=!S;let C=this.editor.getPointInShapeSpace(a,y).toFixed().toJson(),I=!1,T;if((this.editor.user.getIsSnapMode()?!S:S)&&g.length>2){let M,R=8/this.editor.getZoomLevel();for(let j=0,O=l.length-2;j<O;j++){const D=l[j];if(!D)break;if(D.type==="free")continue;const B=D.points[0],z=Ut(D.points);if(!(B&&z))continue;const K=x.NearestPointOnLineSegment(B,z,C);if(x.DistMin(K,C,R)){M=K.toFixed().toJson(),R=x.Dist(K,C),T=D;break}}M&&(I=!0,C=M)}if(I&&T){const M=this.editor.getShapePageTransform(a),R=T.points[0],j=Ut(T.points);if(!j)throw Error("Expected a last point!");const O=q.applyToPoint(M,R),D=q.applyToPoint(M,j),B=q.applyToPoint(M,C);this.editor.snaps.setIndicators([{id:Ke(),type:"points",points:[O,B,D]}])}else{if(this.editor.snaps.clearIndicators(),P){const M=x.Angle(v,y),j=Cf(M,24)-M;b=x.RotWith(y,v,j)}else b=y;C=this.editor.getPointInShapeSpace(a,b).toFixed().toJson()}this.currentLineLength+=x.Dist(m.points[0],C),g[g.length-1]={...m,type:"straight",points:[m.points[0],C]};const k={id:o,type:this.shapeType,props:{segments:g}};this.canClose()&&(k.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([k]);break}case"free":{const g=l.slice(),m=g[g.length-1],v=[...m.points];if(v.length&&this.mergeNextPoint){const{z:y}=v[v.length-1];v[v.length-1]={x:f.x,y:f.y,z:y?Math.max(y,f.z):f.z}}else this.currentLineLength+=x.Dist(v[v.length-1],f),v.push(f);g[g.length-1]={...m,points:v},this.currentLineLength<un[a.props.size]*4&&(this.currentLineLength=this.getLineLength(g));const S={id:o,type:this.shapeType,props:{segments:g}};if(this.canClose()&&(S.props.isClosed=this.getIsClosed(g,s,i)),this.editor.updateShapes([S]),v.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const y=Ne(),b=this.editor.getShape(o).props;this.editor.createShapes([{id:y,type:this.shapeType,x:Zo(r.currentPagePoint.x),y:Zo(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:b.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(h*1.25).toFixed():.5}]}]}}]),this.initialShape=tt(this.editor.getShape(y)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(n){let r=0;for(const o of n)for(let s=0;s<o.points.length-1;s++){const i=o.points[s],a=o.points[s+1];r+=x.Dist2(a,i)}return Math.sqrt(r)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:n}=this;n&&(this.editor.updateShapes([{id:n.id,type:n.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}E(cb,"id","drawing");var IS;let b$=(IS=class extends ie{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(IS,"id","idle"),IS);class ap extends ie{constructor(){super(...arguments);E(this,"shapeType","draw")}static children(){return[b$,cb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}E(ap,"id","draw"),E(ap,"initial","idle"),E(ap,"isLockable",!1);class Ux extends bx{constructor(){super(...arguments);E(this,"shapeType","frame")}onCreate(n){if(!n)return;const r=this.editor.getShapePageBounds(n),o=[],s=this.editor.getShapeAncestors(n).map(i=>i.id);this.editor.getSortedChildIdsForParent(n.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===n.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&Dae(a,s,n)&&o.push(a.id)}),this.editor.reparentShapes(o,n.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")}}E(Ux,"id","frame"),E(Ux,"initial","idle");function Dae(t,e,n){return e.includes(t.id)?!1:t.parentId===n.parentId}var ES;let Rae=(ES=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onKeyUp(e){var n;if(e.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const r=this.editor.getOnlySelectedShape();r&&this.editor.getShapeUtil(r).canEdit(r)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(r.id),(n=this.editor.root.getCurrent())==null||n.transition("editing_shape",{...e,target:"shape",shape:r}))}}onCancel(){this.editor.setCurrentTool("select")}},E(ES,"id","idle"),ES);var kS;let Lae=(kS=class extends ie{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=Ne(),o=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`);this.editor.createShapes([{id:r,type:"geo",x:n.x,y:n.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(Vr),scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]).select(r).setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,n=Ne();this.editor.markHistoryStoppingPoint(`creating_geo:${n}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,o=this.editor.getStyleForNextShape(Vr),s=o==="star"?{w:200,h:190}:o==="cloud"?{w:300,h:180}:{w:200,h:200};this.editor.createShapes([{id:n,type:"geo",x:e.x,y:e.y,props:{geo:this.editor.getStyleForNextShape(Vr),scale:r,...s}}]);const i=this.editor.getShape(n);if(!i)return;const{w:a,h:l}=i.props,c=new x(a/2,l/2).mul(r),u=this.editor.getShapeParentTransform(i);u&&c.rot(-u.rotation()),this.editor.select(n),this.editor.updateShape({id:i.id,type:"geo",x:i.x-c.x,y:i.y-c.y,props:{geo:this.editor.getStyleForNextShape(Vr),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},E(kS,"id","pointing"),kS);class Hx extends ie{constructor(){super(...arguments);E(this,"shapeType","geo")}static children(){return[Rae,Lae]}}E(Hx,"id","geo"),E(Hx,"initial","idle");class lp extends ie{constructor(){super(...arguments);E(this,"shapeType","highlight")}static children(){return[b$,cb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}E(lp,"id","highlight"),E(lp,"initial","idle"),E(lp,"isLockable",!1);var TS;let $ae=(TS=class extends ie{constructor(){super(...arguments);E(this,"shapeId","")}onEnter(n){this.shapeId=n.shapeId,this.editor.setCursor({type:"cross",rotation:0})}onPointerDown(){this.parent.transition("pointing",{shapeId:this.shapeId})}onCancel(){this.editor.setCurrentTool("select")}},E(TS,"id","idle"),TS);const rE=2;var MS;let Fae=(MS=class extends ie{constructor(){super(...arguments);E(this,"shape",{});E(this,"markId")}onEnter(n){const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=n.shapeId&&this.editor.getShape(n.shapeId);if(s&&r.shiftKey){this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${s.id}`),this.shape=s;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(f=>f.type==="vertex").sort(ln),l=a[a.length-1],c=a[a.length-2],u=q.applyToPoint(this.editor.getShapeParentTransform(this.shape),new x(this.shape.x,this.shape.y)),h=x.Sub(o,u).addXY(.1,.1),p=tt(this.shape.props.points);if(x.DistMin(l,c,rE)||x.DistMin(h,l,rE))p[l.id]={id:l.id,index:l.index,x:h.x,y:h.y};else{const f=vo(l.index);p[f]={id:f,index:f,x:h.x,y:h.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:p}}])}else{const i=Ne();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${i}`),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(i),this.shape=this.editor.getShape(i)}}onPointerMove(){if(this.shape&&this.editor.inputs.isDragging){const n=this.editor.getShapeHandles(this.shape);if(!n)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Ut(n);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,creatingMarkId:this.markId,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators()}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}},E(MS,"id","pointing"),MS);class Kx extends ie{constructor(){super(...arguments);E(this,"shapeType","line")}static children(){return[$ae,Fae]}}E(Kx,"id","line"),E(Kx,"initial","idle");var AS;let Nae=(AS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(AS,"id","idle"),AS);const zae=0,He=200,dm=new x(He/2,He/2),P$=10,Bae=t=>[[["a1"],new x(He*.5,He*-.5-t.options.adjacentShapeMargin)],[["a2"],new x(He*1.5+t.options.adjacentShapeMargin,He*.5)],[["a3"],new x(He*.5,He*1.5+t.options.adjacentShapeMargin)],[["a4"],new x(He*-.5-t.options.adjacentShapeMargin,He*.5)]];function Uae(t,e){if(e===1)return Bae(t);const n=He*e,r=t.options.adjacentShapeMargin*e;return[[["a1"],new x(n*.5,n*-.5-r)],[["a2"],new x(n*1.5+r,n*.5)],[["a3"],new x(n*.5,n*1.5+r)],[["a4"],new x(n*-.5-r,n*.5)]]}function C$(t,e,n,r,o,s){return Object.fromEntries(Uae(t,s).map(([i,a],l)=>{const c=a.clone();return l===0&&o?c.y-=o:l===2&&r&&(c.y+=r),[i,c.rot(n).add(e)]}))}function _$(t,e,n,r){const o=new Set(t.getSelectedShapeIds()),s=(He+t.options.adjacentShapeMargin+r)**2,i=new Map,a=[];for(const u of t.getCurrentPageShapes()){if(!t.isShapeOfType(u,"note")||n!==u.props.scale||o.has(u.id))continue;const h=t.getShapePageTransform(u.id);e===h.rotation()&&(i.set(u,t.getShapePageBounds(u).center),a.push(...Object.values(C$(t,h.point(),e,u.props.growY,r,n))))}const l=a.length;let c;for(const[u,h]of i)for(let p=0;p<l;p++)c=a[p],c&&(x.Dist2(h,c)>s||t.isPointInShape(u,c)&&(a[p]=void 0));return ye(a)}function I$(t,e,n,r,o=!1){let s;const i=t.getCurrentPageShapesSorted(),a=(He+t.options.adjacentShapeMargin**2)**e.props.scale;for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="note"&&c.id!==e.id){const u=t.getShapePageBounds(c);if(u&&x.Dist2(u.center,n)<a&&t.isPointInShape(c,n)){s=c;break}}}if(t.complete(),!s||o){t.markHistoryStoppingPoint("creating note shape");const l=Ne();t.createShape({id:l,type:"note",x:n.x,y:n.y,rotation:r,opacity:e.opacity,props:{...e.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const c=t.getShape(l);if(!c)return;const u=t.getPointInParentSpace(c,x.Sub(n,x.Rot(dm.clone().mul(c.props.scale),r)));t.updateShape({id:l,type:"note",x:u.x,y:u.y}),s=t.getShape(l)}return PR(t),s}var jS;let Hae=(jS=class extends ie{constructor(){super(...arguments);E(this,"dragged",!1);E(this,"info",{});E(this,"wasFocusedOnEnter",!1);E(this,"markId","");E(this,"shape",{})}onEnter(){const{editor:n}=this;if(this.wasFocusedOnEnter=!n.getIsMenuOpen(),this.wasFocusedOnEnter){const r=Ne();this.markId=n.markHistoryStoppingPoint(`creating_note:${r}`);const o=this.editor.inputs.originPagePoint.clone(),s=oE(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=sE(this.editor,r,o)}}onPointerMove(n){if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=Ne(),o=this.editor.inputs.originPagePoint.clone(),s=oE(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=sE(this.editor,r,o)}this.editor.setCurrentTool("select.translating",{...n,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,creatingMarkId:this.markId,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}}onPointerUp(){this.complete()}onInterrupt(){this.cancel()}onComplete(){this.complete()}onCancel(){this.cancel()}complete(){this.wasFocusedOnEnter&&(this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):(this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape",{...this.info,target:"shape",shape:this.shape})))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}},E(jS,"id","pointing"),jS);function oE(t,e,n){let r=P$/t.getZoomLevel(),o;for(const s of _$(t,0,n,0)){const i=x.Sub(e,s),a=i.len();a<r&&(r=a,o=i)}return o}function sE(t,e,n){t.createShape({id:e,type:"note",x:n.x,y:n.y,props:{scale:t.user.getIsDynamicResizeMode()?1/t.getZoomLevel():1}}).select(e);const r=t.getShape(e),o=t.getShapeGeometry(r).bounds;return t.updateShapes([{id:e,type:"note",x:r.x-o.width/2,y:r.y-o.height/2}]),t.getShape(e)}class Wx extends ie{constructor(){super(...arguments);E(this,"shapeType","note")}static children(){return[Nae,Hae]}}E(Wx,"id","note"),E(Wx,"initial","idle");function Kae(t){const e=t.getShapeAtPoint(t.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:t.options.hitTestMargin/t.getZoomLevel(),renderingOnly:!0});if(!e)return t.setHoveredShape(null);let n;const r=t.getOutermostSelectableShape(e);return r===e||r.id===t.getFocusedGroupId()||t.getSelectedShapeIds().includes(r.id)?n=e:n=r,t.setHoveredShape(n.id)}const ts=nT(Kae,32);var OS;let Wae=(OS=class extends ie{onPointerMove(e){switch(e.target){case"shape":case"canvas":ts(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){ts.cancel()}onKeyDown(e){var n;if(e.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const r=this.editor.getOnlySelectedShape();r&&this.editor.getShapeUtil(r).canEdit(r)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(r.id),(n=this.editor.root.getCurrent())==null||n.transition("editing_shape",{...e,target:"shape",shape:r}))}}onCancel(){this.editor.setCurrentTool("select")}},E(OS,"id","idle"),OS);var DS;let Gae=(DS=class extends ie{constructor(){super(...arguments);E(this,"shape");E(this,"markId","");E(this,"enterTime",0)}onEnter(){this.enterTime=Date.now()}onExit(){this.editor.setHintingShapes([])}onPointerMove(n){if(Date.now()-this.enterTime<150)return;const{editor:r}=this,{isPointing:o}=r.inputs;if(!o)return;const{originPagePoint:s,currentPagePoint:i}=r.inputs,a=Math.abs(s.x-i.x),c=Math.sqrt(r.getInstanceState().isCoarsePointer?r.options.coarseDragDistanceSquared:r.options.dragDistanceSquared)*6/r.getZoomLevel();if(a>c){const u=Ne();this.markId=r.markHistoryStoppingPoint(`creating_text:${u}`);const h=this.createTextShape(u,s,!1,a);if(!h){this.cancel();return}this.shape=r.getShape(h),r.select(u),r.setCurrentTool("select.resizing",{...n,target:"selection",handle:"right",isCreating:!0,creatingMarkId:this.markId,creationCursorOffset:{x:a,y:1},onInteractionEnd:"text",onCreate:()=>{r.setEditingShape(h.id),r.setCurrentTool("select.editing_shape")}})}}onPointerUp(){this.complete()}onComplete(){this.cancel()}onCancel(){this.cancel()}onInterrupt(){this.cancel()}complete(){var s;this.editor.markHistoryStoppingPoint("creating text shape");const n=Ne(),{originPagePoint:r}=this.editor.inputs;this.createTextShape(n,r,!0,20)&&(this.editor.select(n),this.editor.setEditingShape(n),this.editor.setCurrentTool("select"),(s=this.editor.root.getCurrent())==null||s.transition("editing_shape"))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(n,r,o,s){this.editor.createShape({id:n,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:o,w:s,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const i=this.editor.getShape(n);if(!i){this.cancel();return}const a=this.editor.getShapePageBounds(i),l=new x;if(o)switch(i.props.textAlign){case"start":{l.x=0;break}case"middle":{l.x=-a.width/2;break}case"end":{l.x=-a.width;break}}else l.x=0;if(l.y=-a.height/2,Rn(i.parentId)){const c=this.editor.getShapeParentTransform(i);l.rot(-c.rotation())}return this.editor.updateShape({...i,x:i.x+l.x,y:i.y+l.y}),i}},E(DS,"id","pointing"),DS);class cp extends ie{constructor(){super(...arguments);E(this,"shapeType","text")}static children(){return[Wae,Gae]}}E(cp,"id","text"),E(cp,"initial","idle"),E(cp,"isLockable",!1);const Vae=[cp,ap,Hx,Wx,Kx,Ux,Bx,lp];function Lr(){return ws({isDarkMode:dd()})}function hm(t){return{key:`${ko.id}:${t}`,async getElement(){const e=Yae(t);if(!e)return null;const n=e.$$_url,r=e.$$_fontface;if(!n||!r)return null;const o=await(await Jr(n)).blob(),s=await rs.blobToDataUrl(o),i=r.replace(n,s);return d.jsx("style",{children:i})}}}function Yae(t){const e=KM[t];for(const n of document.fonts)if(e.includes(n.family))return n;return null}function ub(t){return{key:`${ko.id}:${t}`,async getElement(){return t!=="pattern"?null:d.jsx(Xae,{})}}}function Xae(){const t=Lr(),e=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:"hash_pattern_mask",children:[d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),d.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[d.jsx("line",{x1:e*1,y1:e*3,x2:e*3,y2:e*1}),d.jsx("line",{x1:e*5,y1:e*7,x2:e*7,y2:e*5}),d.jsx("line",{x1:e*9,y1:e*11,x2:e*11,y2:e*9})]})]}),d.jsx("pattern",{id:Uf(1,t.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:t.solid,mask:"url(#hash_pattern_mask)"})})]})}function db(){return{key:`${ko.id}:pattern`,component:Jae}}const zc=8,iE=(t,e,n)=>new Promise((r,o)=>{const s=zc*e*t,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?yf.darkMode.solid:yf.lightMode.solid,a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*e*t;const l=8/12,c=u=>u*e*t;a.beginPath(),a.moveTo(c(l*1),c(l*3)),a.lineTo(c(l*3),c(l*1)),a.moveTo(c(l*5),c(l*7)),a.lineTo(c(l*7),c(l*5)),a.moveTo(c(l*9),c(l*11)),a.lineTo(c(l*11),c(l*9)),a.stroke(),i.toBlob(u=>{!u||xt.throwToBlob.get()?o():r(u)})}),aE=(t,e)=>{const n=document.createElement("canvas");n.width=t[0],n.height=t[1];const r=n.getContext("2d");return r?(e(r),n.toDataURL()):""};let hS=null;function qae(){return hS||(hS={white:aE([1,1],t=>{t.fillStyle="#f8f9fa",t.fillRect(0,0,1,1)}),black:aE([1,1],t=>{t.fillStyle="#212529",t.fillRect(0,0,1,1)})}),hS}function E$(t){return Math.ceil(Math.log2(Math.max(1,t)))}function Uf(t,e){const n=E$(t);return`tldraw_hash_pattern_${e}_${n}`}function k$(t){const e=[],r=E$(t);for(let o=0;o<=r;o++)e.push(Math.pow(2,o));return e}function Zae(t){const e=qae();return k$(t).flatMap(n=>[{zoom:n,url:e.white,theme:"light"},{zoom:n,url:e.black,theme:"dark"}])}function Qae(){const t=F(),e=U("devicePixelRatio",()=>t.getInstanceState().devicePixelRatio,[t]),n=U("maxZoom",()=>Math.ceil(Ut(t.getCameraOptions().zoomSteps)),[t]),[r,o]=w.useState(!1),[s,i]=w.useState(()=>Zae(n));return w.useEffect(()=>{const l=Promise.all(k$(n).flatMap(u=>[iE(e,u,!1).then(h=>({zoom:u,theme:"light",url:URL.createObjectURL(h)})),iE(e,u,!0).then(h=>({zoom:u,theme:"dark",url:URL.createObjectURL(h)}))]));let c=!1;return l.then(u=>{c||(i(u),o(!0))}),()=>{c=!0,o(!1),l.then(u=>{for(const{url:h}of u)URL.revokeObjectURL(h)})}},[e,n]),{defs:d.jsx(d.Fragment,{children:s.map(l=>{const c=Uf(l.zoom,l.theme);return d.jsx("pattern",{id:c,width:zc,height:zc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:l.url,width:zc,height:zc})},c)})}),isReady:r}}function Jae(){const t=F(),e=w.useRef(null),{defs:n,isReady:r}=Qae();return w.useEffect(()=>{if(r&&t.environment.isSafari){const o=T$(e.current);o&&t.timers.requestAnimationFrame(()=>{o.style.display="none",t.timers.requestAnimationFrame(()=>{o.style.display=""})})}},[t,r]),d.jsx("g",{ref:e,"data-testid":r?"ready-pattern-fill-defs":void 0,children:n})}function T$(t){return t.classList.contains("tl-html-layer")?t:t.parentElement?T$(t.parentElement):null}const rn=Ie.memo(function({theme:e,d:n,color:r,fill:o,scale:s}){switch(o){case"none":return null;case"solid":return d.jsx("path",{fill:e[r].semi,d:n});case"semi":return d.jsx("path",{fill:e.solid,d:n});case"fill":return d.jsx("path",{fill:e[r].fill,d:n});case"pattern":return d.jsx(ele,{theme:e,color:r,fill:o,d:n,scale:s})}});function ele({d:t,color:e,theme:n}){const r=F(),o=ad(),s=U("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:n[e].pattern,d:t}),d.jsx("path",{fill:o?`url(#${Uf(1,n.id)})`:i?n[e].semi:`url(#${Uf(s,n.id)})`,d:t})]})}function tle(t){return t.replace(/\s/g," ")}function Gx(t,e,n){const{padding:r=0}=n;if(e.length===0)return null;const o=Z.From(e[0].box);for(const{box:c}of e)o.union(c);const s=r+(n.offsetX??0),i=(n.offsetY??0)+n.fontSize/2+(n.verticalTextAlign==="start"?r:n.verticalTextAlign==="end"?n.height-r-o.height:(Math.ceil(n.height)-o.height)/2);let a=null;const l=[];for(const{text:c,box:u}of e)a!==null&&u.y>a&&l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
370
- `},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,unicodeBidi:"plaintext",children:tle(c)},l.length)),a=u.y;return d.jsx("text",{fontSize:n.fontSize,fontFamily:n.fontFamily,fontStyle:n.fontStyle,fontWeight:n.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:n.stroke,strokeWidth:n.strokeWidth,fill:n.fill,children:l})}function nle(t,e,n,r){if((t==="start-legacy"||t==="end-legacy")&&n.length!==0){const o=Z.From(n[0].box);for(const{box:s}of n)o.union(s);if(t==="start-legacy")return(r-2*e-o.width)/2;if(t==="end-legacy")return-(r-2*e-o.width)/2}}function rle(t){return t==="start-legacy"||t==="middle-legacy"||t==="end-legacy"}function pm({fontSize:t,font:e,align:n,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:l=!0}){const c=F(),u=Lr(),h={fontSize:t,fontFamily:KM[e],textAlign:n,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:dn.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:s,stroke:void 0,strokeWidth:void 0},p=c.textMeasure.measureTextSpans(o,h),f=nle(n,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const g=Gx(c,p,h);let m=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,m=Gx(c,p,h)),d.jsxs(d.Fragment,{children:[m,g]})}const ole=w.forwardRef(function({isEditing:e,text:n,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){return d.jsx("textarea",{ref:c,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!e,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:n,onFocus:r,onChange:o,onKeyDown:s,onBlur:i,onTouchEnd:Ot,onContextMenu:e?Ot:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:we})});function sle(t,e,n){const r=F(),o=w.useRef(null),s=U("isEditing",()=>r.getEditingShapeId()===t,[r]),i=U("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);w.useEffect(()=>{function u({shapeId:h}){var p;h===t&&((p=o.current)==null||p.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,t,s]),w.useEffect(()=>{var u,h,p,f;s&&(document.activeElement!==o.current&&((u=o.current)==null||u.focus()),r.getInstanceState().isCoarsePointer&&((h=o.current)==null||h.select()),r.environment.isSafari&&((p=o.current)==null||p.blur(),(f=o.current)==null||f.focus()))},[r,s]);const a=w.useCallback(u=>{if(r.getEditingShapeId()===t)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&r.complete();break}}},[r,t]),l=w.useCallback(u=>{if(r.getEditingShapeId()!==t)return;let h=kl.normalizeText(u.currentTarget.value);const p=h.replace(/\t/g,rl);if(p!==h){const f=u.currentTarget.selectionStart;u.currentTarget.value=p,u.currentTarget.selectionStart=f+(p.length-h.length),u.currentTarget.selectionEnd=f+(p.length-h.length),h=p}r.updateShape({id:t,type:e,props:{text:h}})},[r,t,e]),c=w.useCallback(u=>{r.dispatch({...Bn(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(t)}),Ot(u)},[r,t]);return{rInput:o,handleFocus:_u,handleBlur:_u,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:Ot,isEmpty:n.trim().length===0,isEditing:s,isEditingAnything:i}}const fm=Ie.memo(function({id:e,type:n,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:f,classNamePrefix:g,style:m,textWidth:v,textHeight:S}){const{rInput:y,isEmpty:b,isEditing:P,isEditingAnything:C,...I}=sle(e,n,r),[T,_]=w.useState(r);w.useEffect(()=>{P||_(r)},[P,r]);const k=kl.normalizeTextForDom(r),M=k.length>0,R=rle(l);if(!P&&!M)return null;const j=g||"tl-text";return d.jsx("div",{className:`${j}-label tl-text-wrapper`,"data-font":s,"data-align":l,"data-hastext":!b,"data-isediting":P,"data-iseditinganything":C,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||R?"center":l,alignItems:c==="middle"?"center":c,padding:p,...m},children:d.jsxs("div",{className:`${j}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(v||0),color:o,width:v?Math.ceil(v):void 0,height:S?Math.ceil(S):void 0},children:[d.jsx("div",{className:`${j} tl-text tl-text-content`,dir:"auto",children:k.split(`
371
- `).map((O,D)=>d.jsx("div",{dir:"auto",children:O},D))}),(C||h)&&d.jsx(ole,{ref:y,text:r,isEditing:P,...I,handleKeyDown:f??I.handleKeyDown},T)]})})}),ile=new Eo;function ale(t){return ile.get(t,()=>t.store.createComputedCache("arrowLabelSize",e=>{const n=wo(t,e);let r=0,o=0;const s=n.isStraight?new es({start:x.From(n.start.point),end:x.From(n.end.point)}):new Ja({center:x.Cast(n.handleArc.center),start:x.Cast(n.start.point),end:x.Cast(n.end.point),sweepFlag:n.bodyArc.sweepFlag,largeArcFlag:n.bodyArc.largeArcFlag});if(e.props.text.trim()){const i=s.bounds,a=Vx(e),{w:l,h:c}=t.textMeasure.measureText(e.props.text,{...dn,fontFamily:ys[e.props.font],fontSize:a,maxWidth:null});r=l,o=c;let u=!1;if(i.width>i.height?(r=Math.max(Math.min(l,64),Math.min(i.width-64,l)),u=!0):r>16*a&&(r=16*a,u=!0),u){const{w:h,h:p}=t.textMeasure.measureText(e.props.text,{...dn,fontFamily:ys[e.props.font],fontSize:a,maxWidth:r});r=h,o=p}}return new x(r,o).addScalar(Bf*2*e.props.scale)}))}function hb(t,e){return e.props.text.trim()===""?new x(0,0).addScalar(Bf*2*e.props.scale):ale(t).get(e.id)??new x(0,0)}function M$(t){const e=un[t.props.size];return(wae+(e-un.s)*2+(e===un.xl?20:0))*t.props.scale}function lle(t,e,n){const r=hb(t,e),o=M$(e),s=x.Nudge(n.start.point,n.end.point,o),i=x.Nudge(n.end.point,n.start.point,o),a=o1(s,i,Z.FromCenter(n.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;x.Dist2(l,s)>x.Dist2(c,s)&&([c,l]=a);const u=s.add(x.Sub(n.middle,l)),h=i.add(x.Sub(n.middle,c)),p=x.Dist(n.start.point,u)/n.length,f=x.Dist(n.start.point,h)/n.length;return{start:p,end:f}}function cle(t,e,n){const r=hb(t,e),o=M$(e),s=Math.sign(e.props.bend),i=o/n.handleArc.radius*s,a=x.Angle(n.bodyArc.center,n.start.point)-i,l=x.Angle(n.bodyArc.center,n.end.point)+i,c=ra(n.bodyArc.center,n.bodyArc.radius,a),u=ra(n.bodyArc.center,n.bodyArc.radius,l),h=[],p=cE(n.bodyArc.center,n.bodyArc.radius,a,l,s,Z.FromCenter(c,r).corners);h.push(new St({points:Z.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const f=cE(n.bodyArc.center,n.bodyArc.radius,a,l,s,Z.FromCenter(u,r).corners);h.push(new St({points:Z.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const T of[...p??[],...f??[],c,u])h.push(new S1({x:T.x-3,y:T.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const g=(p&&uE(n.start.point,p))??n.middle,m=(f&&uE(n.end.point,f))??n.middle,v=x.Angle(n.bodyArc.center,n.start.point),S=x.Angle(n.bodyArc.center,n.end.point),y=x.Angle(n.bodyArc.center,g),b=x.Angle(n.bodyArc.center,m);if(zs(v,y,s)>zs(v,b,s))return{start:.5,end:.5,dbg:h};const P=zs(v,S,s),C=zs(v,y,s)/P,I=zs(v,b,s)/P;return{start:C,end:I,dbg:h}}function up(t,e){let n;const r=[],o=wo(t,e),s={hasStartBinding:!!o.bindings.start,hasEndBinding:!!o.bindings.end,hasStartArrowhead:o.start.arrowhead!=="none",hasEndArrowhead:o.end.arrowhead!=="none"};if(o.isStraight){const a=lle(t,e,o),l=lE(t,e,a,s);n=x.Lrp(o.start.point,o.end.point,l)}else{const a=cle(t,e,o);a.dbg&&r.push(...a.dbg);const l=lE(t,e,a,s),c=ule(x.Angle(o.bodyArc.center,o.start.point),x.Angle(o.bodyArc.center,o.end.point),Math.sign(e.props.bend),l);n=ra(o.bodyArc.center,o.bodyArc.radius,c)}const i=hb(t,e);return{box:Z.FromCenter(n,i),debugGeom:r}}function lE(t,e,n,r){const{hasEndArrowhead:o,hasEndBinding:s,hasStartBinding:i,hasStartArrowhead:a}=r,l=D$(t,e);let c=zt(e.props.labelPosition,a||i?n.start:0,o||s?n.end:1);const u=Math.min(.02,500/l*.02);return c=c>=.5-u&&c<=.5+u?.5:c,c}function cE(t,e,n,r,o,s){const i=px(t,e,s),a=zs(n,r,o);return i==null?void 0:i.filter(l=>{const c=zs(n,x.Angle(t,l),o);return c>=0&&c<=a})}function uE(t,e){let n=null,r=-1/0;for(const o of e){const s=x.Dist2(t,o);s>r&&(n=o,r=s)}return n}function ule(t,e,n,r){const o=zs(t,e,n);return t+o*r*n*-1}function Vx(t){return xae[t.props.size]*t.props.scale}function dle(t,e,n){const r=e==="end"?t.end.point:t.start.point,o=e==="end"?t.start.point:t.end.point,s=t.isStraight?x.Dist(o,r):Math.abs(t.bodyArc.length),i=Math.max(Math.min(s/5,n*3),n);let a;if(t.isStraight)a=x.Nudge(r,o,i);else{const l=iZ(r,i,t.handleArc.center,t.handleArc.radius);a=e==="end"?t.handleArc.sweepFlag?l[0]:l[1]:t.handleArc.sweepFlag?l[1]:l[0]}return x.IsNaN(a)&&(a=t.start.point),{point:r,int:a}}function hle({point:t,int:e}){const n=x.RotWith(e,t,De/6),r=x.RotWith(e,t,-De/6);return`M ${n.x} ${n.y} L ${t.x} ${t.y} L ${r.x} ${r.y}`}function ple({point:t,int:e}){const n=x.RotWith(e,t,De/6),r=x.RotWith(e,t,-De/6);return`M ${n.x} ${n.y} L ${t.x} ${t.y} L ${r.x} ${r.y} Z`}function fle({point:t,int:e}){const n=x.Sub(e,t).div(2),r=x.Add(t,x.Rot(n,qe)),o=x.Sub(t,x.Rot(n,qe));return`M ${r.x} ${r.y} L ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function gle({point:t,int:e}){const n=x.Lrp(t,e,.45),r=x.Dist(n,t);return`M ${n.x-r},${n.y}
372
- a ${r},${r} 0 1,0 ${r*2},0
373
- a ${r},${r} 0 1,0 -${r*2},0 `}function mle({point:t,int:e}){const n=x.Lrp(t,e,.75),r=x.RotWith(n,t,De/4),o=x.RotWith(n,t,-De/4),s=x.Lrp(r,o,.5);return s.add(x.Sub(s,t)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${t.x} ${t.y} L ${o.x} ${o.y} Z`}function yle({int:t,point:e}){const n=x.Lrp(e,t,.85),r=x.Sub(n,e).div(2),o=x.Add(e,x.Rot(r,qe)),s=x.Sub(e,x.Rot(r,qe)),i=x.Add(n,x.Rot(r,qe)),a=x.Sub(n,x.Rot(r,qe));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function Sle({int:t,point:e}){const n=x.Sub(t,e).div(2),r=x.Add(e,x.Rot(n,qe)),o=x.Sub(e,x.Rot(n,qe));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function Hf(t,e,n){const r=e==="end"?t.end.arrowhead:t.start.arrowhead;if(r==="none")return;const o=dle(t,e,n);if(o){switch(r){case"bar":return Sle(o);case"square":return yle(o);case"diamond":return mle(o);case"dot":return gle(o);case"inverted":return fle(o);case"arrow":return hle(o);case"triangle":return ple(o)}return""}}function vle(t){const{start:e,end:n,handleArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=t;return`M${e.handle.x},${e.handle.y} A${r} ${r} 0 ${o} ${s} ${n.handle.x},${n.handle.y}`}function A$(t){const{start:e,end:n,bodyArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=t;return`M${e.point.x},${e.point.y} A${r} ${r} 0 ${o} ${s} ${n.point.x},${n.point.y}`}function j$(t,e){return`M${t.x},${t.y}L${e.x},${e.y}`}function xle(t){return j$(t.start.handle,t.end.handle)}function O$(t){return j$(t.start.point,t.end.point)}let wle=0;class dp extends Zr{constructor(){super(...arguments);E(this,"_resizeInitialBindings",new Eo)}canEdit(){return!0}canBind({toShapeType:n}){return n!=="arrow"}canSnap(){return!1}hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsBg(){return!0}hideSelectionBoundsFg(){return!0}canBeLaidOut(n){const r=Fn(this.editor,n);return!r.start&&!r.end}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{x:0,y:0},end:{x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw",scale:1}}getGeometry(n){const r=wo(this.editor,n),o=[],s=r.isStraight?new es({start:x.From(r.start.point),end:x.From(r.end.point)}):new Ja({center:x.Cast(r.handleArc.center),start:x.Cast(r.start.point),end:x.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(n.props.text.trim()){const a=up(this.editor,n);o.push(...a.debugGeom),i=new fs({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new eo({children:[...i?[s,i]:[s],...o]})}getHandles(n){const r=wo(this.editor,n);return[{id:"start",type:"vertex",index:"a0",x:r.start.handle.x,y:r.start.handle.y},{id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y}].filter(Boolean)}getText(n){return n.props.text}onHandleDrag(n,{handle:r,isPrecise:o}){const s=r.id,i=Fn(this.editor,n);if(s==="middle"){const{start:I,end:T}=tl(this.editor,n,i),_=x.Sub(T,I),k=x.Per(_),M=x.Med(T,I),R=x.Sub(M,k),j=x.Add(M,k),O=x.NearestPointOnLineSegment(R,j,r,!1);let D=x.Dist(O,M);return x.Clockwise(O,T,M)&&(D*=-1),{id:n.id,type:n.type,props:{bend:D}}}const a={id:n.id,type:"arrow",props:{}},l=i[s],u=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return sp(this.editor,n,s),a.props[s]={x:r.x,y:r.y},a;const h=this.editor.getShapePageTransform(n.id).applyToPoint(r),p=this.editor.getShapeAtPoint(h,{hitInside:!0,hitFrameInside:!0,margin:0,filter:I=>!I.isLocked&&this.editor.canBindShapes({fromShape:n,toShape:I,binding:"arrow"})});if(!p)return sp(this.editor,n,s),a.props[s]={x:r.x,y:r.y},a;const f=this.editor.getShapeGeometry(p),g=Z.ZeroFix(f.bounds),v=this.editor.getShapePageTransform(a.id).applyToPoint(r),S=this.editor.getPointInShapeSpace(p,v);let y=o;y||(!l||l&&p.id!==l.toId)&&(y=this.editor.inputs.pointerVelocity.len()<.5),o||(f.isClosed||(y=!0),u&&p.id===u.toId&&u.props.isPrecise&&(y=!0));const b={x:(S.x-g.minX)/g.width,y:(S.y-g.minY)/g.height};y&&x.Dist(S,g.center)<Math.max(4,Math.min(Math.min(g.width,g.height)*.15,16))/this.editor.getZoomLevel()&&(b.x=.5,b.y=.5);const P={terminal:s,normalizedAnchor:b,isPrecise:y,isExact:this.editor.inputs.altKey};Cc(this.editor,n,p.id,P),this.editor.setHintingShapes([p.id]);const C=Fn(this.editor,n);return C.start&&C.end&&C.start.toId===C.end.toId&&x.Equals(C.start.props.normalizedAnchor,C.end.props.normalizedAnchor)&&Cc(this.editor,n,C.end.toId,{...C.end.props,normalizedAnchor:{x:C.end.props.normalizedAnchor.x+.05,y:C.end.props.normalizedAnchor.y}}),a}onTranslateStart(n){const r=Fn(this.editor,n),o=tl(this.editor,n,r),s=this.editor.getShapePageTransform(n.id),i=this.editor.getSelectedShapeIds();if(!(r.start&&(i.includes(r.start.toId)||this.editor.isAncestorSelected(r.start.toId))||r.end&&(i.includes(r.end.toId)||this.editor.isAncestorSelected(r.end.toId)))){hE.set(n,{pagePosition:s.applyToPoint(n),terminalBindings:Yu(o,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:s.applyToPoint(l)}:null})}),r.start&&(zf({editor:this.editor,arrow:n,terminal:"start",useHandle:!0}),n=this.editor.getShape(n.id)),r.end&&zf({editor:this.editor,arrow:n,terminal:"end",useHandle:!0});for(const a of["start","end"]){const l=r[a];l&&this.editor.updateBinding({...l,props:{...l.props,isPrecise:!0}})}}}onTranslate(n,r){const o=hE.get(n);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=x.Sub(s.applyToPoint(r),o.pagePosition);for(const a of Object.values(o.terminalBindings)){if(!a)continue;const l=x.Add(a.pagePosition,x.Mul(i,.5)),c=this.editor.getShapeAtPoint(l,{hitInside:!0,hitFrameInside:!0,margin:0,filter:u=>!u.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:u,binding:"arrow"})});if((c==null?void 0:c.id)===a.binding.toId){const u=Z.ZeroFix(this.editor.getShapeGeometry(c).bounds),h=this.editor.getPointInShapeSpace(c,l),p={x:(h.x-u.minX)/u.width,y:(h.y-u.minY)/u.height};Cc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else sp(this.editor,r,a.binding.props.terminal)}}onResize(n,r){const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(n,()=>Fn(this.editor,n)),a=tl(this.editor,n,i),{start:l,end:c}=tt(n.props);let{bend:u}=n.props;i.start||(l.x=a.start.x*o,l.y=a.start.y*s),i.end||(c.x=a.end.x*o,c.y=a.end.y*s);const h=Math.abs(o),p=Math.abs(s),f=i!=null&&i.start?x.From(i.start.props.normalizedAnchor):null,g=i!=null&&i.end?x.From(i.end.props.normalizedAnchor):null;return o<0&&s>=0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.x=1-f.x),g&&(g.x=1-g.x)):o>=0&&s<0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.y=1-f.y),g&&(g.y=1-g.y)):o>=0&&s>=0?u!==0&&(u*=Math.max(h,p)):o<0&&s<0&&(u!==0&&(u*=Math.max(h,p)),f&&(f.x=1-f.x,f.y=1-f.y),g&&(g.x=1-g.x,g.y=1-g.y)),i.start&&f&&Cc(this.editor,n,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&g&&Cc(this.editor,n,i.end.toId,{...i.end.props,normalizedAnchor:g.toJson()}),{props:{start:l,end:c,bend:u}}}onDoubleClickHandle(n,r){switch(r.id){case"start":return{id:n.id,type:n.type,props:{...n.props,arrowheadStart:n.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:n.id,type:n.type,props:{...n.props,arrowheadEnd:n.props.arrowheadEnd==="none"?"arrow":"none"}}}}component(n){const r=Lr(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,i=wo(this.editor,n);if(!(i!=null&&i.isValid))return null;const a=up(this.editor,n),l=n.id===this.editor.getOnlySelectedShapeId(),u=this.editor.getEditingShapeId()===n.id||n.props.text;return d.jsxs(d.Fragment,{children:[d.jsx(li,{id:n.id,style:{minWidth:50,minHeight:50},children:d.jsx(dE,{shape:n,shouldDisplayHandles:s&&(o==null?void 0:o.id)===n.id})}),u&&d.jsx(fm,{id:n.id,classNamePrefix:"tl-arrow",type:"arrow",font:n.props.font,fontSize:Vx(n),lineHeight:dn.lineHeight,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:r[n.props.labelColor].solid,textWidth:a.box.w-Bf*2*n.props.scale,isSelected:l,padding:0,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)`}})]})}indicator(n){const r=Bg(n.id),o=wo(this.editor,n);if(!o)return null;const{start:s,end:i}=tl(this.editor,n,o==null?void 0:o.bindings),a=this.editor.getShapeGeometry(n),l=a.bounds,c=n.props.text.trim()?a.children[1]:null;if(x.Equals(s,i))return null;const u=un[n.props.size]*n.props.scale,h=o.start.arrowhead&&Hf(o,"start",u),p=o.end.arrowhead&&Hf(o,"end",u),f=o.isStraight?O$(o):A$(o),g=h&&o.start.arrowhead!=="arrow"||p&&o.end.arrowhead!=="arrow"||!!c,m=(n.id+"_clip").replace(":","_");return r&&c?d.jsx("rect",{x:$(c.x),y:$(c.y),width:c.w,height:c.h,rx:3.5*n.props.scale,ry:3.5*n.props.scale}):d.jsxs("g",{children:[g&&d.jsx("defs",{children:d.jsxs("mask",{id:m,children:[d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.w+200,height:l.h+200,fill:"white"}),c&&d.jsx("rect",{x:$(c.x),y:$(c.y),width:c.w,height:c.h,fill:"black",rx:3.5*n.props.scale,ry:3.5*n.props.scale}),h&&d.jsx("path",{d:h,fill:o.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&d.jsx("path",{d:p,fill:o.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{...g?{mask:`url(#${m})`}:void 0,children:[g&&d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.width+200,height:l.height+200,opacity:0}),d.jsx("path",{d:f})]}),h&&d.jsx("path",{d:h}),p&&d.jsx("path",{d:p}),c&&d.jsx("rect",{x:$(c.x),y:$(c.y),width:c.w,height:c.h,rx:3.5,ry:3.5})]})}onEditEnd(n){const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])}toSvg(n,r){r.addExportDef(ub(n.props.fill)),n.props.text&&r.addExportDef(hm(n.props.font));const o=ws(r),s=1/n.props.scale;return d.jsxs("g",{transform:`scale(${s})`,children:[d.jsx(dE,{shape:n,shouldDisplayHandles:!1}),d.jsx(pm,{fontSize:Vx(n),font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:o[n.props.labelColor].solid,bounds:up(this.editor,n).box.clone().expandBy(-Bf*n.props.scale),padding:0})]})}getCanvasSvgDefs(){return[db(),{key:"arrow:dot",component:ble},{key:"arrow:cross",component:Ple}]}getInterpolatedProps(n,r,o){return{...o>.5?r.props:n.props,scale:Ee(n.props.scale,r.props.scale,o),start:{x:Ee(n.props.start.x,r.props.start.x,o),y:Ee(n.props.start.y,r.props.start.y,o)},end:{x:Ee(n.props.end.x,r.props.end.x,o),y:Ee(n.props.end.y,r.props.end.y,o)},bend:Ee(n.props.bend,r.props.bend,o),labelPosition:Ee(n.props.labelPosition,r.props.labelPosition,o)}}}E(dp,"type","arrow"),E(dp,"props",GM),E(dp,"migrations",VM);function D$(t,e){const n=wo(t,e);return n.isStraight?x.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const dE=Rt(function({shape:e,shouldDisplayHandles:n}){const r=F(),o=Lr(),s=wo(r,e),i=Z.ZeroFix(r.getShapeGeometry(e).bounds),a=Fn(r,e),l=U("force solid",()=>r.getZoomLevel()<.2,[r]),c=Ie.useMemo(()=>r.environment.isSafari?wle+=1:0,[e]);if(!(s!=null&&s.isValid))return null;const u=un[e.props.size]*e.props.scale,h=s.start.arrowhead&&Hf(s,"start",u),p=s.end.arrowhead&&Hf(s,"end",u),f=s.isStraight?O$(s):A$(s);let g=null;if(n){const C=2/r.getZoomLevel(),{strokeDasharray:I,strokeDashoffset:T}=Wr(D$(r,e),C,{end:"skip",start:"skip",lengthRatio:2.5});g=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?xle(s):vle(s),strokeDasharray:I,strokeDashoffset:T,strokeWidth:C,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:m,strokeDashoffset:v}=Wr(s.isStraight?s.length:Math.abs(s.bodyArc.length),u,{style:e.props.dash,forceSolid:l}),S=up(r,e),y=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),b=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),P=(e.id+"_clip"+(r.environment.isSafari?`_${c}`:"")).replace(":","_");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsxs("mask",{id:P,children:[d.jsx("rect",{x:$(-100+i.minX),y:$(-100+i.minY),width:$(i.width+200),height:$(i.height+200),fill:"white"}),e.props.text.trim()&&d.jsx("rect",{x:S.box.x,y:S.box.y,width:S.box.w,height:S.box.h,fill:"black",rx:4,ry:4}),h&&y&&d.jsx("path",{d:h,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&b&&d.jsx("path",{d:p,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{fill:"none",stroke:o[e.props.color].solid,strokeWidth:u,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[g,d.jsxs("g",{mask:`url(#${P})`,children:[d.jsx("rect",{x:$(i.minX-100),y:$(i.minY-100),width:$(i.width+200),height:$(i.height+200),opacity:0}),d.jsx("path",{d:f,strokeDasharray:m,strokeDashoffset:v})]}),h&&y&&e.props.fill!=="none"&&d.jsx(rn,{theme:o,d:h,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),p&&b&&e.props.fill!=="none"&&d.jsx(rn,{theme:o,d:p,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),h&&d.jsx("path",{d:h}),p&&d.jsx("path",{d:p})]})]})}),hE=new WeakMap;function ble(){return d.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:d.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function Ple(){return d.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[d.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),d.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const pE="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E";function Tl({url:t,zoomLevel:e}){return d.jsx("a",{className:le("tl-hyperlink-button",{"tl-hyperlink-button__hidden":e<.32}),href:t,target:"_blank",rel:"noopener noreferrer",onPointerDown:Ot,onPointerUp:Ot,title:t,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${pE}") center 100% / 100% no-repeat`,WebkitMask:`url("${pE}") center 100% / 100% no-repeat`}})})}const fE="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E",Cle=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function Kf(t){return Cle.map(n=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=n,l=new x(r,o),{x:c,y:u}=l.rot(-t);return`${c}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}const _le=300,R$=320,Ile=46,Ele=101;class hp extends Yl{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:_le,h:R$,assetId:null}}component(e){return d.jsx(kle,{shape:e,util:this})}indicator(e){return d.jsx("rect",{width:$(e.props.w),height:$(e.props.h),rx:"6",ry:"6"})}onBeforeCreate(e){return gE(this.editor,e)}onBeforeUpdate(e,n){if(e.props.url!==n.props.url)if(pr.isValid(n.props.url))Mle(this.editor,n);else return{...n,props:{...n.props,url:e.props.url}};if(e.props.assetId!==n.props.assetId)return gE(this.editor,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:Ee(e.props.w,n.props.w,r),h:Ee(e.props.h,n.props.h,r)}}}E(hp,"type","bookmark"),E(hp,"props",JM),E(hp,"migrations",eA);function kle({shape:t,util:e}){const n=t.props.assetId?e.editor.getAsset(t.props.assetId):null,r=!!ad()&&e.editor.environment.isSafari,o=e.editor.getShapePageTransform(t).rotation(),s=Tle(t),[i,a]=w.useState(!0),l=()=>a(!1);return d.jsx(ri,{children:d.jsxs("div",{className:le("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:Kf(o),maxHeight:t.props.h},children:[(!n||n.props.image)&&d.jsxs("div",{className:"tl-bookmark__image_container",children:[n?d.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:n==null?void 0:n.props.image,alt:(n==null?void 0:n.props.title)||""}):d.jsx("div",{className:"tl-bookmark__placeholder"}),(n==null?void 0:n.props.image)&&d.jsx(Tl,{url:t.props.url,zoomLevel:e.editor.getZoomLevel()})]}),d.jsxs("div",{className:"tl-bookmark__copy_container",children:[n!=null&&n.props.title?d.jsx("h2",{className:"tl-bookmark__heading",children:Eae(n.props.title)}):null,n!=null&&n.props.description&&(n!=null&&n.props.image)?d.jsx("p",{className:"tl-bookmark__description",children:n.props.description}):null,d.jsxs("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Ot,onPointerUp:Ot,onClick:Ot,children:[i&&(n!=null&&n.props.favicon)?d.jsx("img",{className:"tl-bookmark__favicon",src:n==null?void 0:n.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",onError:l,alt:`favicon of ${s}`}):d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${fE}") center 100% / 100% no-repeat`,WebkitMask:`url("${fE}") center 100% / 100% no-repeat`}}),d.jsx("span",{children:s})]})]})]})})}function gE(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):null;let r=R$;return n&&(n.props.image||(n.props.title?r=Ele:r=Ile)),{...e,props:{...e.props,h:r}}}const Tle=t=>{try{return new URL(t.props.url).hostname.replace(/^www\./,"")}catch{return t.props.url}};function Mle(t,e){const{url:n}=e.props,r=Ns.createId(Lv(n));t.getAsset(r)?e.props.assetId!==r&&t.updateShapes([{id:e.id,type:e.type,props:{assetId:r}}]):(t.updateShapes([{id:e.id,type:e.type,props:{assetId:null}}]),Ale(t,e))}const Ale=lw(async(t,e)=>{if(t.isDisposed)return;const{url:n}=e.props,r=await t.getAssetForExternalContent({type:"url",url:n});r&&t.run(()=>{t.createAssets([r]),t.updateShapes([{id:e.id,type:e.type,props:{assetId:r.id}}])})},500);function ua(t,e=!1){const n=t.length;if(n<2)return"";let r=t[0].point,o=t[1].point;if(n===2)return`M${je(r)}L${je(o)}`;let s="";for(let i=2,a=n-1;i<a;i++)r=t[i].point,o=t[i+1].point,s+=$n(r,o);return e?`M${$n(t[0].point,t[1].point)}Q${je(t[1].point)}${$n(t[1].point,t[2].point)}T${s}${$n(t[n-1].point,t[0].point)}${$n(t[0].point,t[1].point)}Z`:`M${je(t[0].point)}Q${je(t[1].point)}${$n(t[1].point,t[2].point)}${t.length>3?"T":""}${s}L${je(t[n-1].point)}`}function jle(t,e={}){const{start:n={},end:r={}}=e,{cap:o=!0}=n,{cap:s=!0}=r;Re(!n.taper&&!r.taper,"cap taper not supported here"),Re(!n.easing&&!r.easing,"cap easing not supported here"),Re(o&&s,"cap must be true");const i=jo(t,e);um(i,e);const a=Ole(i);let l="";for(const c of a)l+=Rle(c,e);return l}function Ole(t){if(t.length<=2)return[t];const e=[];let n=[t[0]],r=x.Sub(t[1].point,t[0].point).uni(),o,s,i,a,l;for(let c=1,u=t.length;c<u-1;c++){if(i=t[c-1],a=t[c],l=t[c+1],o=x.Sub(l.point,a.point).uni(),s=x.Dpr(r,o),r=o,s<-.8){const h={...a,point:a.input};n.push(h),e.push(pS(n)),n=[h];continue}if(n.push(a),!(s>.7)&&(x.Dist2(i.point,a.point)+x.Dist2(a.point,l.point))/((i.radius+a.radius+l.radius)/3)**2<1.5){n.push(a),e.push(pS(n)),n=[a];continue}}return n.push(t[t.length-1]),e.push(pS(n)),e}function pS(t){const e=t[0];let n;for(;t.length>2&&(n=t[1],x.Dist2(e.point,n.point)<((e.radius+n.radius)/2*.5)**2);)t.splice(1,1);const r=t[t.length-1];let o;for(;t.length>2&&(o=t[t.length-2],x.Dist2(r.point,o.point)<((r.radius+o.radius)/2*.5)**2);)t.splice(t.length-2,1);return t.length>1&&(t[0]={...t[0],vector:x.Sub(t[0].point,t[1].point).uni()},t[t.length-1]={...t[t.length-1],vector:x.Sub(t[t.length-2].point,t[t.length-1].point).uni()}),t}function Dle(t,e,n){return"M "+t+" "+e+" m -"+n+", 0 a "+n+","+n+" 0 1,1 "+n*2+",0 a "+n+","+n+" 0 1,1 -"+n*2+",0"}function Rle(t,e={}){if(t.length===0)return"";if(t.length===1)return Dle(t[0].point.x,t[0].point.y,t[0].radius);const{left:n,right:r}=m$(t,e);r.reverse();let o=`M${je(n[0])}T`;for(let s=1;s<n.length;s++)o+=$n(n[s-1],n[s]);{const s=t[t.length-1],i=s.radius,a=s.vector.clone().per().neg(),l=x.Add(s.point,x.Mul(a,i)),c=x.Add(s.point,x.Mul(a,-i));o+=`${je(l)}A${$(i)},${$(i)} 0 0 1 ${je(c)}T`}for(let s=1;s<r.length;s++)o+=$n(r[s-1],r[s]);{const s=t[0],i=s.radius,a=s.vector.clone().per(),l=x.Add(s.point,x.Mul(a,i)),c=x.Add(s.point,x.Mul(a,-i));o+=`${je(l)}A${$(i)},${$(i)} 0 0 1 ${je(c)}Z`}return o}const L$=(t,e,n)=>{const r=[],o=[];t.forEach(c=>r.push(...c.points)),e.forEach(c=>o.push(...c.points));const s=Math.max(r.length,o.length),i=[],a=[];for(let c=0;c<s;c++)i.push(r[c]||r[r.length-1]),a.push(o[c]||o[o.length-1]);return[{type:"free",points:i.map((c,u)=>{let h=.5;return a[u].z!==void 0&&c.z!==void 0&&(h=Ee(c.z,a[u].z,n)),{x:Ee(c.x,a[u].x,n),y:Ee(c.y,a[u].y,n),z:h}})}]},Lle=t=>t*.65+EY(t*De/2)*.35,$le=t=>({size:t,thinning:.5,streamline:Cl(t,[9,16],[.64,.74],!0),smoothing:.62,easing:At.easeOutSine,simulatePressure:!0}),Fle=t=>({size:1+t*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Lle}),mE=t=>({size:t,thinning:0,streamline:Cl(t,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:At.linear}),Nle=t=>({size:t,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:At.linear});function pb({strokeWidth:t,showAsComplete:e}){return{size:1+t,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:At.easeOutSine,last:e}}function Yx(t,e,n,r){const o=t.isComplete||n;return r?t.isPen?{...Nle(e),last:o}:{...mE(e),last:o}:t.dash==="draw"?t.isPen?{...Fle(e),last:o}:{...$le(e),last:o}:{...mE(e),last:o}}function Ml(t){const e=[];for(const n of t)if(n.type==="free"||n.points.length<2)e.push(...n.points.map(x.Cast));else{const r=Math.max(4,Math.floor(x.Dist(n.points[0],n.points[1])/16));e.push(...x.PointsBetween(n.points[0],n.points[1],r))}return e}function zle(t,e,n){return{draw:"none",solid:"none",dotted:`${n<.2?0:.1} ${e*2}`,dashed:`${e*2} ${e*2}`}[t.props.dash]}class pp extends Zr{hideResizeHandles(e){return fS(e)}hideRotateHandle(e){return fS(e)}hideSelectionBoundsFg(e){return fS(e)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(e){const n=Ml(e.props.segments),r=(un[e.props.size]+1)*e.props.scale;if(e.props.segments.length===1){const s=Z.FromPoints(n);if(s.width<r*2&&s.height<r*2)return new S1({x:-r,y:-r,radius:r,isFilled:!0})}const o=jo(n,Yx(e.props,r,e.props.isPen,!0)).map(s=>s.point);return e.props.isClosed?new St({points:o,isFilled:e.props.fill!=="none"}):new Wl({points:o})}component(e){return d.jsx(li,{id:e.id,children:d.jsx(yE,{shape:e,zoomLevel:this.editor.getZoomLevel()})})}indicator(e){var u;const n=Ml(e.props.segments);let r=(un[e.props.size]+1)*e.props.scale;const o=this.editor.getZoomLevel();!(o<.5&&o<1.5/r)&&!e.props.isPen&&e.props.dash==="draw"&&n.length===1&&(r+=ro(e.id)()*(r/6));const i=e.props.isComplete||((u=Ut(e.props.segments))==null?void 0:u.type)==="straight",a=Yx(e.props,r,i,!0),l=jo(n,a),c=l.length>1?ua(l,e.props.isClosed):$$(n[0],r);return d.jsx("path",{d:c})}toSvg(e,n){n.addExportDef(ub(e.props.fill));const r=1/e.props.scale;return d.jsx("g",{transform:`scale(${r})`,children:d.jsx(yE,{shape:e,zoomLevel:1})})}getCanvasSvgDefs(){return[db()]}onResize(e,n){const{scaleX:r,scaleY:o}=n,s=[];for(const i of e.props.segments)s.push({...i,points:i.points.map(({x:a,y:l,z:c})=>({x:Zo(r*a),y:Zo(o*l),z:c}))});return{props:{segments:s}}}expandSelectionOutlinePx(e){const n=e.props.dash==="draw"?1.6:1;return un[e.props.size]*n/2*e.props.scale}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,segments:L$(e.props.segments,n.props.segments,r),scale:Ee(e.props.scale,n.props.scale,r)}}}E(pp,"type","draw"),E(pp,"props",nA),E(pp,"migrations",rA);function $$(t,e){const n=(e+1)*.5;return`M ${t.x} ${t.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function fS(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function yE({shape:t,zoomLevel:e}){var h;const n=Lr(),r=Ml(t.props.segments),o=t.props.isComplete||((h=Ut(t.props.segments))==null?void 0:h.type)==="straight";let s=(un[t.props.size]+1)*t.props.scale;const i=e<.5&&e<1.5/s;!i&&!t.props.isPen&&t.props.dash==="draw"&&r.length===1&&(s+=ro(t.id)()*(s/6));const a=Yx(t.props,s,o,i);if(!i&&t.props.dash==="draw")return d.jsxs(d.Fragment,{children:[t.props.isClosed&&t.props.fill&&r.length>1?d.jsx(rn,{d:ua(jo(r,a),t.props.isClosed),theme:n,color:t.props.color,fill:t.props.isClosed?t.props.fill:"none",scale:t.props.scale}):null,d.jsx("path",{d:jle(r,a),strokeLinecap:"round",fill:n[t.props.color].solid})]});const l=jo(r,a),c=l.length<2,u=c?$$(r[0],0):ua(l,t.props.isClosed);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{d:u,theme:n,color:t.props.color,fill:c||t.props.isClosed?t.props.fill:"none",scale:t.props.scale}),d.jsx("path",{d:u,strokeLinecap:"round",fill:c?n[t.props.color].solid:"none",stroke:n[t.props.color].solid,strokeWidth:s,strokeDasharray:c?"none":zle(t,s,e),strokeDashoffset:"0"})]})}function Ble(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Ule(t,e){const n=fe(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(F$(o.hostnames,r)){const s=o.fromEmbedUrl(e);if(s)return{definition:o,url:s,embedUrl:e}}}const Hle=t=>t.split("*").map(e=>Ble(e)).join(".+"),F$=(t,e)=>!!t.find(n=>{const r=new RegExp(Hle(n));return e.match(r)});function Kle(t,e){const n=fe(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(F$(o.hostnames,r)){const s=o.toEmbedUrl(e);if(s)return{definition:o,embedUrl:s,url:e}}}function Wle(t,e){try{return Kle(t,e)??Ule(t,e)}catch{return}}const Gle=t=>Object.entries(t).filter(([e,n])=>n).map(([e])=>e).join(" ");class fp extends Yl{constructor(){super(...arguments);E(this,"embedDefinitions",k1)}setEmbedDefinitions(n){this.embedDefinitions=n}getEmbedDefinitions(){return this.embedDefinitions}getEmbedDefinition(n){return Wle(this.embedDefinitions,n)}getText(n){return n.props.url}hideSelectionBoundsFg(n){return!this.canResize(n)}canEdit(){return!0}canResize(n){var r,o;return!!((o=(r=this.getEmbedDefinition(n.props.url))==null?void 0:r.definition)!=null&&o.doesResize)}canEditInReadOnly(){return!0}getDefaultProps(){return{w:300,h:300,url:""}}isAspectRatioLocked(n){const r=this.getEmbedDefinition(n.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1}onResize(n,r){const o=this.isAspectRatioLocked(n),s=this.getEmbedDefinition(n.props.url);let i=(s==null?void 0:s.definition.minWidth)??200,a=(s==null?void 0:s.definition.minHeight)??200;if(o){const l=n.props.w/n.props.h;l>1?i*=l:a/=l}return zg(n,r,{minWidth:i,minHeight:a})}component(n){const r=ad(),{w:o,h:s,url:i}=n.props,a=Bg(n.id),l=this.getEmbedDefinition(i),c=U("is hovering",()=>{const{editingShapeId:g,hoveredShapeId:m}=this.editor.getCurrentPageState();if(g&&m!==g){const v=this.editor.getShape(g);if(v&&this.editor.isShapeOfType(v,"embed"))return!0}return!1},[]),u=this.editor.getShapePageTransform(n).rotation();if(r)return d.jsx(ri,{className:"tl-embed-container",id:n.id,children:d.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:Kf(u),borderRadius:(l==null?void 0:l.definition.overrideOutlineRadius)??8,background:(l==null?void 0:l.definition.backgroundColor)??"var(--color-background)",width:o,height:s}})});const h=a||c;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(l==null?void 0:l.definition.type)==="tldraw")return null;if((l==null?void 0:l.definition.type)==="github_gist"){const g=l.url.split("/").pop();if(!g)throw Error("No gist id!");return d.jsx(ri,{className:"tl-embed-container",id:n.id,children:d.jsx(Vle,{id:g,width:$(o),height:$(s),isInteractive:h,pageRotation:u})})}const f=Gle({...Ane,...(l==null?void 0:l.definition.overridePermissions)??{}});return d.jsx(ri,{className:"tl-embed-container",id:n.id,children:l!=null&&l.definition?d.jsx("iframe",{className:"tl-embed",sandbox:f,src:l.embedUrl,width:$(o),height:$(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:h?"auto":"none",zIndex:h?"":"-1",boxShadow:Kf(u),borderRadius:(l==null?void 0:l.definition.overrideOutlineRadius)??8,background:l==null?void 0:l.definition.backgroundColor}}):null})}indicator(n){const r=this.getEmbedDefinition(n.props.url);return d.jsx("rect",{width:$(n.props.w),height:$(n.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}getInterpolatedProps(n,r,o){return{...o>.5?r.props:n.props,w:Ee(n.props.w,r.props.w,o),h:Ee(n.props.h,r.props.h,o)}}}E(fp,"type","embed"),E(fp,"props",oA),E(fp,"migrations",sA);function Vle({id:t,file:e,isInteractive:n,width:r,height:o,style:s,pageRotation:i}){return d.jsx("iframe",{className:"tl-embed",draggable:!1,width:$(r),height:$(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:n?"all":"none",zIndex:n?"":"-1",boxShadow:Kf(i)},srcDoc:`
374
- <html>
375
- <head>
376
- <base target="_blank">
377
- </head>
378
- <body>
379
- <script src=${`https://gist.github.com/${t}.js${e?`?file=${e}`:""}`}><\/script>
380
- <style type="text/css">
381
- * { margin: 0px; }
382
- table { height: 100%; background-color: red; }
383
- .gist { background-color: none; height: 100%; }
384
- .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
385
- </style>
386
- </body>
387
- </html>`})}const Yle=w.forwardRef(({id:t,name:e,isEditing:n},r)=>{const o=F(),s=w.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Ot(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=w.useCallback(l=>{const c=o.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==h&&o.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,o]),a=w.useCallback(l=>{const c=o.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value;u!==h&&o.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,o]);return d.jsxs("div",{className:`tl-frame-label ${n?"tl-frame-label__editing":""}`,children:[d.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:n?void 0:"none"},value:e,autoFocus:!0,onKeyDown:s,onBlur:i,onChange:a}),N$(e,"Frame")+"​"]})}),Xle=function({id:e,name:n,width:r,height:o}){const s=F(),i=U("shape rotation",()=>ni(s.getShapePageTransform(e).rotation()),[s,e]),a=Bg(e),l=w.useRef(null),c=w.useCallback(g=>{const m=Bn(g);g.preventDefault(),s.getEditingShapeId()!==e&&s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(e),...m})},[s,e]);w.useEffect(()=>{const g=l.current;g&&a&&(g.focus(),g.select())},[l,a]);const h=((i+Math.PI/4)*(2/Math.PI)+4)%4,p=["top","left","bottom","right"][Math.floor(h)];let f;switch(p){case"top":f="";break;case"right":f=`translate(${$(r)}px, 0px) rotate(90deg)`;break;case"bottom":f=`translate(${$(r)}px, ${$(o)}px) rotate(180deg)`;break;case"left":f=`translate(0px, ${$(o)}px) rotate(270deg)`;break}return d.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(p==="top"||p==="bottom"?r:o)}px + var(--space-5))`,bottom:"100%",transform:`${f} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:c,children:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(Yle,{ref:l,id:e,name:n,isEditing:a})})})};function N$(t,e){return t.match(/^\s*$/)?e:t}class gp extends Yl{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){return new fs({width:e.props.w,height:e.props.h,isFilled:!1})}getText(e){return e.props.name}component(e){const n=this.editor.getShapeGeometry(e).bounds,r=Lr(),o=U("is creating this shape",()=>{const s=this.editor.getStateDescendant("select.resizing");if(!s||!s.getIsActive())return!1;const i=s==null?void 0:s.info;return i?i.isCreating&&this.editor.getOnlySelectedShapeId()===e.id:!1},[e.id]);return d.jsxs(d.Fragment,{children:[d.jsx(li,{children:d.jsx("rect",{className:le("tl-frame__body",{"tl-frame__creating":o}),width:n.width,height:n.height,fill:r.solid,stroke:r.text})}),o?null:d.jsx(Xle,{id:e.id,name:e.props.name,width:n.width,height:n.height})]})}toSvg(e,n){const r=ws({isDarkMode:n.isDarkMode}),i=((ni(this.editor.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,a=Math.floor(i);let l;switch(a){case 0:l="";break;case 3:l=`translate(${$(e.props.w)}, 0) rotate(90)`;break;case 2:l=`translate(${$(e.props.w)}, ${$(e.props.h)}) rotate(180)`;break;case 1:l=`translate(0, ${$(e.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}const c={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:e.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",fill:r.text},u=this.editor.textMeasure.measureTextSpans(N$(e.props.name,"Frame")+"​",c),h=u[0],p=Ut(u),f=p.box.w+p.box.x-h.box.x,g=Gx(this.editor,u,{offsetY:-c.height-2,...c});return d.jsxs(d.Fragment,{children:[d.jsx("rect",{width:e.props.w,height:e.props.h,fill:r.solid,stroke:r.black.solid,strokeWidth:1,rx:1,ry:1}),d.jsxs("g",{transform:l,children:[d.jsx("rect",{x:-8,y:-c.height-4,width:f+16,height:c.height,fill:r.background,rx:4,ry:4}),g]})]})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx("rect",{width:$(n.width),height:$(n.height),className:"tl-frame-indicator"})}canReceiveNewChildrenOfType(e,n){return!e.isLocked}providesBackgroundForChildren(){return!0}canDropShapes(e,n){return!e.isLocked}onDragShapesOver(e,n){n.every(r=>r.parentId===e.id)||this.editor.reparentShapes(n,e.id)}onDragShapesOut(e,n){const r=this.editor.getShape(e.parentId);r&&this.editor.isShapeOfType(r,"group")?this.editor.reparentShapes(n,r.id):this.editor.reparentShapes(n,this.editor.getCurrentPageId())}onResize(e,n){return zg(e,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:Ee(e.props.w,n.props.w,r),h:Ee(e.props.h,n.props.h,r)}}}E(gp,"type","frame"),E(gp,"props",iA),E(gp,"migrations",aA);function SE(t,e){return t>e?(De*(e/2)+(t-e))*2:(De*(t/2)+(e-t))*2}function z$(t,e){return fb(t,e).map((n,r)=>n.getSvgPathData(r===0)).join(" ")+" Z"}function qle(t,e,n,r){const o=t/4,s=e/4,i=ro(r),a=n*.75,l=y=>y.addXY(i()*a,i()*a),c=new x(t/2,e),u=new x(0,s*1.2),h=new x(t/2,s*.9),p=new x(t,s*1.2),f=l(new x(t/2,e)),g=l(new x(0,s*1.2)),m=l(new x(t/2,s*.9)),v=l(new x(t,s*1.2));return[new sn({start:c,cp1:new x(o*1.5,s*3),cp2:new x(0,s*2.5),end:u}),new sn({start:u,cp1:new x(0,-s*.32),cp2:new x(o*1.85,-s*.32),end:h}),new sn({start:h,cp1:new x(o*2.15,-s*.32),cp2:new x(t,-s*.32),end:p}),new sn({start:p,cp1:new x(t,s*2.5),cp2:new x(o*2.5,s*3),end:f}),new sn({start:f,cp1:new x(o*1.5,s*3),cp2:new x(0,s*2.5),end:g}),new sn({start:g,cp1:new x(0,-s*.32),cp2:new x(o*1.85,-s*.32),end:m}),new sn({start:m,cp1:new x(o*2.15,-s*.32),cp2:new x(t,-s*.32),end:v}),new sn({start:v,cp1:new x(t,s*2.5),cp2:new x(o*2.5,s*3),end:c})].map((y,b)=>y.getSvgPathData(b===0)).join(" ")+" Z"}function fb(t,e){const n=t/4,r=e/4;return[new sn({start:new x(t/2,e),cp1:new x(n*1.5,r*3),cp2:new x(0,r*2.5),end:new x(0,r*1.2)}),new sn({start:new x(0,r*1.2),cp1:new x(0,-r*.32),cp2:new x(n*1.85,-r*.32),end:new x(t/2,r*.9)}),new sn({start:new x(t/2,r*.9),cp1:new x(n*2.15,-r*.32),cp2:new x(t,-r*.32),end:new x(t,r*1.2)}),new sn({start:new x(t,r*1.2),cp1:new x(t,r*2.5),cp2:new x(n*2.5,r*3),end:new x(t/2,e)})]}function Zle(t){return{size:1+t,thinning:.25,end:{taper:t},start:{taper:t},streamline:0,smoothing:1,simulatePressure:!1}}function Qle(t,e,n,r){const o=ro(t),s=e/2,i=n/2,a=IA(s,i),l=[],c=Fe*o(),u=Fe+qe/2+Math.abs(o())*qe,h=Math.max(16,a/10);for(let p=0;p<h;p++){const f=p/(h-1),g=c+f*u,m=Math.cos(g),v=Math.sin(g);l.push(new x(s*m+e*.5+.05*o(),i*v+n/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?At.easeInOutSine(f):At.easeInExpo(f)))/2)))}return jo(l,Zle(r))}function Jle(t,e,n,r){return ua(Qle(t,e,n,r))}function Xx(t){let e="M";const n=t.length;let r,o,s;for(let i=0,a=n;i<a;i+=3)r=t[i],o=t[i+1],s=t[i+2],e+=`${je(r)}L${je(o)}Q${je(s)}`;return e+=`${je(t[0])}`,e}function qx(t,e,n,r,o){const s=[],i=ro(t);let a=e[0],l;const c=e.length;for(let u=0,h=c*o;u<h;u++){l=x.AddXY(e[(u+1)%c],i()*n,i()*n);const p=x.Sub(l,a),f=x.Len(p),g=x.Div(p,f).mul(Math.min(f/4,r));s.push(x.Add(a,g),x.Add(l,g.neg()),l),a=l}return s}function ece(t,e,n){const r=Math.min(t,e)/2,o=Math.max(t,e)-r*2,i=(Math.PI*(r*2)+2*o)/n,a=t>e?[{type:"straight",start:new x(r,0),delta:new x(1,0)},{type:"arc",center:new x(t-r,r),startAngle:-De/2},{type:"straight",start:new x(t-r,e),delta:new x(-1,0)},{type:"arc",center:new x(r,r),startAngle:De/2}]:[{type:"straight",start:new x(t,r),delta:new x(0,1)},{type:"arc",center:new x(r,e-r),startAngle:0},{type:"straight",start:new x(0,e-r),delta:new x(0,-1)},{type:"arc",center:new x(r,r),startAngle:De}];let l=0;const c=[];for(let u=0;u<n;u++){const h=a[0];h.type==="straight"?c.push(x.Add(h.start,x.Mul(h.delta,l))):c.push(ra(h.center,r,h.startAngle+l/r)),l+=i;let p=h.type==="straight"?o:De*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?o:De*r}return c}const tce={s:50,m:70,l:100,xl:130},nce=.2;function gm(t,e,n,r,o){const s=ro(n),i=SE(t,e),a=Math.max(Math.ceil(i/tce[r]),6,Math.ceil(i/Math.min(t,e))),l=i/a*nce,c=Math.max(t-l*2,1),u=Math.max(e-l*2,1),p=SE(c,u)/a,f=(t-c)/2,g=(e-u)/2,m=ece(c,u,a).map(P=>P.addXY(f,g)),v=t<20?0:l*.3,S=e<20?0:l*.3,y=m.slice(0);for(let P=0;P<Math.floor(a/2);P++)y[P]=x.AddXY(y[P],s()*v*o,s()*S*o),y[a-P-1]=x.AddXY(y[a-P-1],s()*v*o,s()*S*o);const b=[];for(let P=0;P<y.length;P++){const C=P===y.length-1?0:P+1,I=y[P],T=y[C],_=m[P],k=m[C],M=x.Dist(_,k),R=p-M,O=x.Dist(I,T)/M,D=(Math.max(f,g)+R)*O,B=x.Lrp(_,k,.5).add(x.Sub(k,_).uni().per().mul(D));B.x<0?B.x=0:B.x>t&&(B.x=t),B.y<0?B.y=0:B.y>e&&(B.y=e);const z=qw(I,T,B),K=x.Dist(z||x.Average([I,T]),I);b.push({leftPoint:I,rightPoint:T,arcPoint:B,center:z,radius:K})}return b}function rce(t,e,n,r,o){const s=[],i=gm(t,e,n,r,o);for(const{center:a,radius:l,leftPoint:c,rightPoint:u}of i)s.push(...AY(c,u,a,l,10));return s}function Zx(t,e,n,r,o){const s=gm(t,e,n,r,o);let i=`M${s[0].leftPoint.toFixed()}`;for(const{leftPoint:a,rightPoint:l,radius:c,center:u}of s){if(u===null){i+=` L${l.toFixed()}`;continue}const h=x.Clockwise(a,l,u)?"0":"1";i+=` A${$(c)},${$(c)} 0 ${h},1 ${l.toFixed()}`}return i+=" Z",i}const oce={s:.5,m:.7,l:.9,xl:1.6};function sce(t,e,n,r,o){const s=ro(n),i=oce[r]*o,a=gm(t,e,n,r,o),u=a.reduce((g,m)=>g+x.Dist2(m.leftPoint,m.rightPoint),0)/a.length>(i*15)**2?g=>x.AddXY(g,s()*i*2,s()*i*2):g=>g;let h=`M${a[0].leftPoint.toFixed()}`,p=u(a[0].leftPoint),f=`M${p.toFixed()}`;for(const{leftPoint:g,center:m,rightPoint:v,radius:S,arcPoint:y}of a){if(m===null){h+=` L${v.toFixed()}`;const _=u(v);f+=` L${_.toFixed()}`,p=_;continue}const b=x.Clockwise(g,v,m)?"0":"1";h+=` A${$(S)},${$(S)} 0 ${b},1 ${v.toFixed()}`;const P=u(v),C=u(y),I=qw(p,P,C);if(!I){f+=` L${P.toFixed()}`,p=P;continue}const T=Math.abs(x.Dist(I,p));f+=` A${$(T)},${$(T)} 0 ${b},1 ${P.toFixed()}`,p=P}return h+f+" Z"}function Qx(t,e){switch(t.geo){case"x-box":return ice(t.w,t.h,e,t.dash);case"check-box":return ace(t.w,t.h);default:return}}function ice(t,e,n,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new x(0,0),new x(t/2,e/2)],[new x(t,e),new x(t/2,e/2)],[new x(0,e),new x(t/2,e/2)],[new x(t,0),new x(t/2,e/2)]];const s=a=>Math.max(0,Math.min(t,a)),i=a=>Math.max(0,Math.min(e,a));return[[new x(s(n*o),i(n*o)),new x(s(t-n*o),i(e-n*o))],[new x(s(n*o),i(e-n*o)),new x(s(t-n*o),i(n*o))]]}function ace(t,e){const n=Math.min(t,e)*.82,r=(t-n)/2,o=(e-n)/2,s=a=>Math.max(0,Math.min(t,a)),i=a=>Math.max(0,Math.min(e,a));return[[new x(s(r+n*.25),i(o+n*.52)),new x(s(r+n*.45),i(o+n*.82))],[new x(s(r+n*.45),i(o+n*.82)),new x(s(r+n*.82),i(o+n*.22))]]}function vE({shape:t,shouldScale:e,forceSolid:n}){const r=e?t.props.scale:1,o=F(),s=Lr(),{id:i,props:a}=t,{w:l,color:c,fill:u,dash:h,growY:p,size:f,scale:g}=a,m=un[f]*r,v=a.h+p;switch(a.geo){case"cloud":if(h==="solid"){const S=Zx(l,v,i,f,g);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}else if(h==="draw"){const S=sce(l,v,i,f,g);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}else{const S=Zx(l,v,i,f,g),y=gm(l,v,i,f,g);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("g",{strokeWidth:m,stroke:s[c].solid,fill:"none",pointerEvents:"all",children:y.map(({leftPoint:b,rightPoint:P,center:C,radius:I},T)=>{const _=C?I*ni(ni(x.Angle(C,P))-ni(x.Angle(C,b))):x.Dist(b,P),{strokeDasharray:k,strokeDashoffset:M}=Wr(_,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("path",{d:C?`M${b.x},${b.y}A${I},${I},0,0,1,${P.x},${P.y}`:`M${b.x},${b.y}L${P.x},${P.y}`,strokeDasharray:k,strokeDashoffset:M},T)})})]})}case"ellipse":{const S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=S.length,{strokeDasharray:P,strokeDashoffset:C}=Wr(b<64?b*2:b,m,{style:h,snap:4,closed:!0,forceSolid:n});return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,strokeWidth:m,fill:"none",stroke:s[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else{const P=(e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t)).getSvgPathData(!0);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:P,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}}case"oval":{const S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=S.getLength(),{strokeDasharray:P,strokeDashoffset:C}=Wr(b<64?b*2:b,m,{style:h,snap:4,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,strokeWidth:m,fill:"none",stroke:s[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}case"heart":if(h==="dashed"||h==="dotted"||h==="solid"){const S=z$(l,v),y=fb(l,v);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:S,color:c,fill:u,scale:r}),y.map((b,P)=>{const{strokeDasharray:C,strokeDashoffset:I}=Wr(b.length,m,{style:h,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsx("path",{d:b.getSvgPathData(),strokeWidth:m,fill:"none",stroke:s[c].solid,strokeDasharray:C,strokeDashoffset:I,pointerEvents:"all"},`curve_${P}`)})]})}else{const S=qle(l,v,m,t.id);return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}default:{const S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S instanceof eo?S.children[0].vertices:S.vertices,b=Qx(t.props,m);if(h==="solid"){let P="M"+y[0]+"L"+y.slice(1)+"Z";if(b)for(const[C,I]of b)P+=`M${C.x},${C.y}L${I.x},${I.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:P,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}else if(h==="dashed"||h==="dotted"){const P="M"+y[0]+"L"+y.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:P,color:c,fill:u,scale:r}),d.jsxs("g",{strokeWidth:m,stroke:s[c].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(y.length)).map((C,I)=>{const T=x.ToFixed(y[I]),_=x.ToFixed(y[(I+1)%y.length]),k=x.Dist(T,_),{strokeDasharray:M,strokeDashoffset:R}=Wr(k,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("line",{x1:T.x,y1:T.y,x2:_.x,y2:_.y,strokeDasharray:M,strokeDashoffset:R},I)}),b&&b.map(([C,I],T)=>{const _=x.Dist(C,I),{strokeDasharray:k,strokeDashoffset:M}=Wr(_,m,{style:h,start:"skip",end:"skip",snap:h==="dotted"?4:void 0,forceSolid:n});return d.jsx("path",{d:`M${C.x},${C.y}L${I.x},${I.y}`,stroke:s[c].solid,strokeWidth:m,fill:"none",strokeDasharray:k,strokeDashoffset:M},`line_fg_${T}`)})]})]})}else if(h==="draw"){let P=Xx(qx(i,y,m/3,m*2,2));if(b)for(const[I,T]of b)P+=`M${I.toFixed()}L${T.toFixed()}`;const C=Xx(qx(i,y,0,m*2,1));return d.jsxs(d.Fragment,{children:[d.jsx(rn,{theme:s,d:C,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}}}}const xE=17*3;class mp extends Yl{canEdit(){return!0}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:"",scale:1}}getGeometry(e){const n=Math.max(1,e.props.w),r=Math.max(1,e.props.h+e.props.growY),o=n/2,s=r/2,i=e.props.fill!=="none";let a;switch(e.props.geo){case"cloud":{a=new St({points:rce(n,r,e.id,e.props.size,e.props.scale),isFilled:i});break}case"triangle":{a=new St({points:[new x(o,0),new x(n,r),new x(0,r)],isFilled:i});break}case"diamond":{a=new St({points:[new x(o,0),new x(n,s),new x(o,r),new x(0,s)],isFilled:i});break}case"pentagon":{a=new St({points:Ty(n,r,5),isFilled:i});break}case"hexagon":{a=new St({points:Ty(n,r,6),isFilled:i});break}case"octagon":{a=new St({points:Ty(n,r,8),isFilled:i});break}case"ellipse":{a=new zee({width:n,height:r,isFilled:i});break}case"oval":{a=new Bee({width:n,height:r,isFilled:i});break}case"star":{const y=Fe/5/2,b=Math.floor(5/4)*2,P=5*2-b,C=0,I=Math.floor(5/2)*2,T=Math.cos(-qe+b*y)*n/2,_=Math.cos(-qe+P*y)*n/2,k=Math.sin(-qe+C*y)*r/2,M=Math.sin(-qe+I*y)*r/2,R=n-Math.abs(T-_),j=r-Math.abs(M-k),O=n/2+_-(n/2-T),D=r/2+k-(r/2-M),B=1,z=(n-O)/2,K=(r-D)/2,N=(n+R)/2,H=(r+j)/2,Y=N*B/2,ee=H*B/2;a=new St({points:Array.from(Array(5*2)).map((ce,ge)=>{const Te=-qe+ge*y;return new x(z+(ge%2?Y:N)*Math.cos(Te),K+(ge%2?ee:H)*Math.sin(Te))}),isFilled:i});break}case"rhombus":{const S=Math.min(n*.38,r*.38);a=new St({points:[new x(S,0),new x(n,0),new x(n-S,r),new x(0,r)],isFilled:i});break}case"rhombus-2":{const S=Math.min(n*.38,r*.38);a=new St({points:[new x(0,0),new x(n-S,0),new x(n,r),new x(S,r)],isFilled:i});break}case"trapezoid":{const S=Math.min(n*.38,r*.38);a=new St({points:[new x(S,0),new x(n-S,0),new x(n,r),new x(0,r)],isFilled:i});break}case"arrow-right":{const S=Math.min(n,r)*.38,y=r*.16;a=new St({points:[new x(0,y),new x(n-S,y),new x(n-S,0),new x(n,r/2),new x(n-S,r),new x(n-S,r-y),new x(0,r-y)],isFilled:i});break}case"arrow-left":{const S=Math.min(n,r)*.38,y=r*.16;a=new St({points:[new x(S,0),new x(S,y),new x(n,y),new x(n,r-y),new x(S,r-y),new x(S,r),new x(0,r/2)],isFilled:i});break}case"arrow-up":{const S=n*.16,y=Math.min(n,r)*.38;a=new St({points:[new x(n/2,0),new x(n,y),new x(n-S,y),new x(n-S,r),new x(S,r),new x(S,y),new x(0,y)],isFilled:i});break}case"arrow-down":{const S=n*.16,y=Math.min(n,r)*.38;a=new St({points:[new x(S,0),new x(n-S,0),new x(n-S,r-y),new x(n,r-y),new x(n/2,r),new x(0,r-y),new x(S,r-y)],isFilled:i});break}case"check-box":case"x-box":case"rectangle":{a=new fs({width:n,height:r,isFilled:i});break}case"heart":{const y=fb(n,r).reduce((b,P)=>(b.push(...P.vertices),b),[]);a=new St({points:y,isFilled:i});break}default:Tt(e.props.geo)}const l=Ih(this.editor,e),c=n/e.props.scale,u=r/e.props.scale,h=Math.min(100,c/2),p=Math.min(ls[e.props.size]*dn.lineHeight+Cr*2,u/2),f=Math.min(c,Math.max(l.w,Math.min(h,Math.max(1,c-8)))),g=Math.min(u,Math.max(l.h,Math.min(p,Math.max(1,u-8)))),m=Qx(e.props,un[e.props.size]*e.props.scale),v=m?m.map(S=>new Wl({points:S})):[];return new eo({children:[a,new fs({x:e.props.align==="start"?0:e.props.align==="end"?(c-f)*e.props.scale:(c-f)/2*e.props.scale,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?(u-g)*e.props.scale:(u-g)/2*e.props.scale,width:f*e.props.scale,height:g*e.props.scale,isFilled:!0,isLabel:!0}),...v]})}getHandleSnapGeometry(e){const n=this.getGeometry(e),r=n.children[0];switch(e.props.geo){case"arrow-down":case"arrow-left":case"arrow-right":case"arrow-up":case"check-box":case"diamond":case"hexagon":case"octagon":case"pentagon":case"rectangle":case"rhombus":case"rhombus-2":case"star":case"trapezoid":case"triangle":case"x-box":return{outline:r,points:[...r.getVertices(),n.bounds.center]};case"cloud":case"ellipse":case"heart":case"oval":return{outline:r,points:[n.bounds.center]};default:Tt(e.props.geo)}}getText(e){return e.props.text}onEditEnd(e){const{id:n,type:r,props:{text:o}}=e;o.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:o.trimEnd()}}])}component(e){const{id:n,type:r,props:o}=e,{fill:s,font:i,align:a,verticalAlign:l,size:c,text:u}=o,h=Lr(),{editor:p}=this,f=U("isGeoOnlySelected",()=>e.id===p.getOnlySelectedShapeId(),[]),m=p.getEditingShapeId()!==null||e.props.text,v=U("force solid",()=>p.getZoomLevel()<.2,[p]);return d.jsxs(d.Fragment,{children:[d.jsx(li,{id:n,children:d.jsx(vE,{shape:e,shouldScale:!0,forceSolid:v})}),m&&d.jsx(ri,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+o.growY},children:d.jsx(fm,{id:n,type:r,font:i,fontSize:ls[c]*e.props.scale,lineHeight:dn.lineHeight,padding:Cr*e.props.scale,fill:s,align:a,verticalAlign:l,text:u,isSelected:f,labelColor:h[o.labelColor].solid,wrap:!0})}),e.props.url&&d.jsx(Tl,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(e){const{id:n,props:r}=e,{w:o,size:s}=r,i=r.h+r.growY,a=un[s],l=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?d.jsx("path",{d:Jle(n,o,i,a)}):d.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:z$(o,i)});case"oval":return d.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:Zx(o,i,n,s,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),u=c instanceof eo?c.children[0].vertices:c.vertices;let h;if(r.dash==="draw"){const f=qx(n,u,0,a*2*e.props.scale,1);h=Xx(f)}else h="M"+u[0]+"L"+u.slice(1)+"Z";const p=Qx(e.props,a);if(p)for(const[f,g]of p)h+=`M${f.x},${f.y}L${g.x},${g.y}`;return d.jsx("path",{d:h})}}}toSvg(e,n){const r={...e,props:{...e.props,w:e.props.w/e.props.scale,h:e.props.h/e.props.scale}},o=r.props;n.addExportDef(ub(o.fill));let s;if(o.text){n.addExportDef(hm(o.font));const i=ws(n),a=new Z(0,0,o.w,o.h+o.growY);s=d.jsx(pm,{fontSize:ls[o.size],font:o.font,align:o.align,verticalAlign:o.verticalAlign,text:o.text,labelColor:i[o.labelColor].solid,bounds:a,padding:16})}return d.jsxs(d.Fragment,{children:[d.jsx(vE,{shouldScale:!1,shape:r,forceSolid:!1}),s]})}getCanvasSvgDefs(){return[db()]}onResize(e,{handle:n,newPoint:r,scaleX:o,scaleY:s,initialShape:i}){const a=i.props.w/i.props.scale,l=i.props.h/i.props.scale,c=i.props.growY/i.props.scale;let u=a*o,h=(l+c)*s,p=0,f=0;const g=xE;if(e.props.text.trim()){let P=Math.max(Math.abs(u),g),C=Math.max(Math.abs(h),g);P<g&&C===g&&(P=g),P===g&&C<g&&(C=g);const I=Ih(this.editor,{...e,props:{...e.props,w:P*e.props.scale,h:C*e.props.scale}}),T=Math.max(Math.abs(u),I.w)*Math.sign(u),_=Math.max(Math.abs(h),I.h)*Math.sign(h);p=Math.abs(T)-Math.abs(u),f=Math.abs(_)-Math.abs(h),u=T,h=_}const m=u*e.props.scale,v=h*e.props.scale,S=new x(0,0);o<0&&(S.x+=m),(n==="left"||n==="top_left"||n==="bottom_left")&&(S.x+=o<0?p:-p),s<0&&(S.y+=v),(n==="top"||n==="top_left"||n==="top_right")&&(S.y+=s<0?f:-f);const{x:y,y:b}=S.rot(e.rotation).add(r);return{x:y,y:b,props:{w:Math.max(Math.abs(m),1),h:Math.max(Math.abs(v),1),growY:0}}}onBeforeCreate(e){if(!e.props.text)return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const n=e.props.h/e.props.scale,r=Ih(this.editor,e).h;let o=null;if(r>n?o=r-n:e.props.growY&&(o=0),o!==null)return{...e,props:{...e.props,growY:o*e.props.scale}}}onBeforeUpdate(e,n){const r=e.props.text,o=n.props.text;if(r===o&&e.props.font===n.props.font&&e.props.size===n.props.size)return;if(r&&!o)return{...n,props:{...n.props,growY:0}};const s=e.props.w/e.props.scale,i=e.props.h/e.props.scale,a=e.props.growY/e.props.scale,l=Ih(this.editor,n);if(!r&&o&&o.length===1){let u=Math.max(s,l.w),h=Math.max(i,l.h);const p=xE;return s<p&&i<p&&(u=Math.max(u,p),h=Math.max(h,p),u=Math.max(u,h),h=Math.max(u,h)),{...n,props:{...n.props,w:u*n.props.scale,h:h*n.props.scale,growY:0}}}let c=null;if(l.h>i?c=l.h-i:a&&(c=0),c!==null){const u=n.props.w/n.props.scale;return{...n,props:{...n.props,growY:c*n.props.scale,w:Math.max(u,l.w)*n.props.scale}}}if(l.w>s)return{...n,props:{...n.props,w:l.w*n.props.scale}}}onDoubleClick(e){if(this.editor.inputs.altKey)switch(e.props.geo){case"rectangle":return{...e,props:{geo:"check-box"}};case"check-box":return{...e,props:{geo:"rectangle"}}}}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:Ee(e.props.w,n.props.w,r),h:Ee(e.props.h,n.props.h,r),scale:Ee(e.props.scale,n.props.scale,r)}}}E(mp,"type","geo"),E(mp,"props",lA),E(mp,"migrations",cA);function Ih(t,e){const{text:n,font:r,size:o,w:s}=e.props;if(!n)return{w:0,h:0};const i=t.textMeasure.measureText("w",{...dn,fontFamily:ys[r],fontSize:ls[o],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=t.textMeasure.measureText(n,{...dn,fontFamily:ys[r],fontSize:ls[o],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[o]),Math.ceil(s/e.props.scale-Cr*2))});return{w:l.w+Cr*2,h:l.h+Cr*2}}function lce(){const[t,e]=w.useState(!1);return w.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),o=matchMedia("(color-gamut: p3)");e(r&&o.matches);const s=()=>e(r&&o.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[]),U(xt.forceSrgb)||!t?"srgb":"p3"}const wE=.35,bE=.82;class yp extends Zr{hideResizeHandles(e){return Eh(e)}hideRotateHandle(e){return Eh(e)}hideSelectionBoundsFg(e){return Eh(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(e){const n=$i(e);if(Eh(e))return new S1({x:-n/2,y:-n/2,radius:n/2,isFilled:!0});const{strokePoints:r,sw:o}=PE(e,n,!0),s=pb({strokeWidth:o,showAsComplete:!0});return um(r,s),new St({points:ab(r,s),isFilled:!0})}component(e){const n=gS(this.editor,e),r=$i(e);return d.jsx(li,{id:e.id,children:d.jsx(kh,{shape:e,forceSolid:n,strokeWidth:r,opacity:wE})})}backgroundComponent(e){const n=gS(this.editor,e),r=$i(e);return d.jsx(li,{id:e.id,children:d.jsx(kh,{shape:e,forceSolid:n,strokeWidth:r,opacity:bE})})}indicator(e){const n=gS(this.editor,e),r=$i(e),{strokePoints:o,sw:s}=PE(e,r,n),i=Ml(e.props.segments);let a;return o.length<2?a=uce(i[0],s):a=ua(o,!1),d.jsx("path",{d:a})}toSvg(e){const n=$i(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(kh,{forceSolid:r,strokeWidth:n,shape:e,opacity:wE})})}toBackgroundSvg(e){const n=$i(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(kh,{forceSolid:r,strokeWidth:n,shape:e,opacity:bE})})}onResize(e,n){const{scaleX:r,scaleY:o}=n,s=[];for(const i of e.props.segments)s.push({...i,points:i.points.map(({x:a,y:l,z:c})=>({x:r*a,y:o*l,z:c}))});return{props:{segments:s}}}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,...n.props,segments:L$(e.props.segments,n.props.segments,r),scale:Ee(e.props.scale,n.props.scale,r)}}}E(yp,"type","highlight"),E(yp,"props",hA),E(yp,"migrations",pA);function cce(t){return`M ${t.x} ${t.y} m -${.1}, 0 a ${.1},${.1} 0 1,0 ${.1*2},0 a ${.1},${.1} 0 1,0 -${.1*2},0`}function uce(t,e){const n=e/2;return`M ${t.x} ${t.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function PE(t,e,n){var l;const r=Ml(t.props.segments),o=t.props.isComplete||((l=Ut(t.props.segments))==null?void 0:l.type)==="straight";let s=e;!n&&!t.props.isPen&&r.length===1&&(s+=ro(t.id)()*(e/6));const i=pb({strokeWidth:s,showAsComplete:o});return{strokePoints:jo(r,i),sw:s}}function $i(t){return El[t.props.size]*1.12*t.props.scale}function Eh(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function kh({strokeWidth:t,forceSolid:e,shape:n,opacity:r}){var p;const o=Lr(),s=Ml(n.props.segments);let i=t;!e&&!n.props.isPen&&s.length===1&&(i+=ro(n.id)()*(i/6));const a=pb({strokeWidth:i,showAsComplete:n.props.isComplete||((p=Ut(n.props.segments))==null?void 0:p.type)==="straight"}),l=jo(s,a),c=l.length>1?ua(l,!1):cce(n.props.segments[0].points[0]),u=lce(),h=o[n.props.color].highlight[u];return d.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function gS(t,e){return U("forceSolid",()=>{const n=$i(e),r=t.getZoomLevel();return n/r<1.5},[t])}function B$(){return d.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),d.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),d.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function U$(t){const{shapeId:e,assetId:n,width:r}=t,o=F(),[s,i]=w.useState(null),[a,l]=w.useState(!1),c=!!ad(),u=n?o.getAsset(n):null,p=o.getCulledShapes().has(e),f=w.useRef(!1),g=BZ();w.useEffect(()=>{s&&(f.current=!0)},[s]);const m=u&&"w"in u.props?r/u.props.w:1,v=U("zoom level",()=>o.getZoomLevel()*m,[o,m]);return w.useEffect(()=>{s&&(f.current=!0)},[s]),w.useEffect(()=>{if(!c&&p)return;if(n&&!(u!=null&&u.props.src)){const b=o.getTemporaryAssetPreview(n);if(b){i(b),l(!0),g();return}}let S=!1;async function y(){const b=await o.resolveAssetUrl(n,{screenScale:v,shouldResolveToOriginal:c});S||(i(b),l(!1),g())}if(f.current){const b=o.timers.setTimeout(y,500);return()=>{clearTimeout(b),S=!0}}else return y(),()=>{S=!0}},[n,u==null?void 0:u.props.src,p,v,o,c,g]),{asset:u,url:s,isPlaceholder:a}}function H$(){const[t,e]=w.useState(!1);return w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{e(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),t}async function dce(t){const n=await(await Jr(t)).blob();return rs.blobToDataUrl(n)}class Sp extends Yl{isAspectRatioLocked(){return!0}canCrop(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null,flipX:!1,flipY:!1}}onResize(e,n){let r=zg(e,n);const{flipX:o,flipY:s}=n.initialShape.props,{scaleX:i,scaleY:a,mode:l}=n;if(r={...r,props:{...r.props,flipX:i<0!==o,flipY:a<0!==s}},!e.props.crop)return r;const c=l==="scale_shape"&&i===-1||l==="resize_bounds"&&o!==r.props.flipX,u=l==="scale_shape"&&a===-1||l==="resize_bounds"&&s!==r.props.flipY,{topLeft:h,bottomRight:p}=e.props.crop;return r.props.crop={topLeft:{x:c?1-p.x:h.x,y:u?1-p.y:h.y},bottomRight:{x:c?1-h.x:p.x,y:u?1-h.y:p.y}},r}isAnimated(e){const n=e.props.assetId?this.editor.getAsset(e.props.assetId):void 0;return n?"mimeType"in n.props&&sr.isAnimatedImageType(n==null?void 0:n.props.mimeType)||"isAnimated"in n.props&&n.props.isAnimated:!1}component(e){var S;const n=this.editor.getCroppingShapeId()===e.id,r=H$(),[o,s]=w.useState(""),[i,a]=w.useState(null),l=e.id===this.editor.getOnlySelectedShapeId(),{asset:c,url:u}=U$({shapeId:e.id,assetId:e.props.assetId,width:e.props.w});if(w.useEffect(()=>{if(u&&this.isAnimated(e)){let y=!1;const b=Iu();return b.onload=()=>{if(y)return;const P=document.createElement("canvas");P.width=b.width,P.height=b.height;const C=P.getContext("2d");C&&(C.drawImage(b,0,0),s(P.toDataURL()),a(u))},b.crossOrigin="anonymous",b.src=u,()=>{y=!0}}},[r,u,e]),(c==null?void 0:c.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const h=l&&n&&this.editor.isIn("select.crop"),p=r&&(((S=c==null?void 0:c.props.mimeType)==null?void 0:S.includes("video"))||this.isAnimated(e)),f=CE(e),g=u===i?null:u,m=p?o:i;if(!u&&!(c!=null&&c.props.src))return d.jsxs(ri,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,color:"var(--color-text-3)",backgroundColor:"var(--color-low)",border:"1px solid var(--color-low-border)"},children:[d.jsx("div",{className:le("tl-image-container",c&&"tl-image-container-loading"),style:f,children:c?null:d.jsx(B$,{})}),"url"in e.props&&e.props.url&&d.jsx(Tl,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]});const v=this.isAnimated(e)?"anonymous":void 0;return d.jsxs(d.Fragment,{children:[h&&m&&d.jsx("div",{style:f,children:d.jsx("img",{className:"tl-image",style:{..._c(e),opacity:.1},crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),d.jsxs(ri,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h},children:[d.jsxs("div",{className:le("tl-image-container"),style:f,children:[m&&d.jsx("img",{className:"tl-image",style:_c(e),crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},m),g&&d.jsx("img",{className:"tl-image",style:_c(e),crossOrigin:v,src:g,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>a(g)},g)]}),e.props.url&&d.jsx(Tl,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]})]})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:d.jsx("rect",{width:$(e.props.w),height:$(e.props.h)})}async toSvg(e){if(!e.props.assetId||!this.editor.getAsset(e.props.assetId))return null;let r=await this.editor.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});if(!r)return null;(r.startsWith("blob:")||r.startsWith("http")||r.startsWith("/")||r.startsWith("./"))&&(r=await dce(r)||"");const o=CE(e),s=e.props.crop;if(o.transform&&s){const{transform:i,width:a,height:l}=o,c=(s.bottomRight.x-s.topLeft.x)*a,u=(s.bottomRight.y-s.topLeft.y)*l,h=[new x(0,0),new x(c,0),new x(c,u),new x(0,u)],p=`cropClipPath_${e.id.replace(":","_")}`,f=_c(e,{width:a,height:l});return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:p,children:d.jsx("polygon",{points:h.map(g=>`${g.x},${g.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${p})`,children:d.jsx("image",{href:r,width:a,height:l,style:f?{...f,transform:`${i} ${f.transform}`}:{transform:i}})})]})}else return d.jsx("image",{href:r,width:e.props.w,height:e.props.h,style:_c(e,{width:e.props.w,height:e.props.h})})}onDoubleClickEdge(e){const n=e.props;if(!n||this.editor.getCroppingShapeId()!==e.id)return;const r=tt(n.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},o=1/(r.bottomRight.x-r.topLeft.x)*e.props.w,s=1/(r.bottomRight.y-r.topLeft.y)*e.props.h,i=new x(r.topLeft.x*o,r.topLeft.y*s).rot(e.rotation),a={id:e.id,type:e.type,x:e.x-i.x,y:e.y-i.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:o,h:s}};this.editor.updateShapes([a])}getInterpolatedProps(e,n,r){function o(s,i){var h,p,f,g;if(s.props.crop===null&&i.props.crop===null)return null;const a=((h=s.props.crop)==null?void 0:h.topLeft)||{x:0,y:0},l=((p=s.props.crop)==null?void 0:p.bottomRight)||{x:1,y:1},c=((f=i.props.crop)==null?void 0:f.topLeft)||{x:0,y:0},u=((g=i.props.crop)==null?void 0:g.bottomRight)||{x:1,y:1};return{topLeft:{x:Ee(a.x,c.x,r),y:Ee(a.y,c.y,r)},bottomRight:{x:Ee(l.x,u.x,r),y:Ee(l.y,u.y,r)}}}return{...r>.5?n.props:e.props,w:Ee(e.props.w,n.props.w,r),h:Ee(e.props.h,n.props.h,r),crop:o(e,n)}}}E(Sp,"type","image"),E(Sp,"props",fA),E(Sp,"migrations",gA);function CE(t){const e=t.props.crop,n=e==null?void 0:e.topLeft;if(!n)return{width:t.props.w,height:t.props.h};const r=1/(e.bottomRight.x-e.topLeft.x)*t.props.w,o=1/(e.bottomRight.y-e.topLeft.y)*t.props.h,s=-n.x*r,i=-n.y*o;return{transform:`translate(${s}px, ${i}px)`,width:r,height:o}}function _c(t,e){const{flipX:n,flipY:r}=t.props;if(!n&&!r)return;const o=`scale(${n?-1:1}, ${r?-1:1})`;return{transform:`${e?`translate(${n?e.width:0}px, ${r?e.height:0}px)`:""} ${o}`,transformOrigin:e?"0 0":"center center"}}function K$(t){return{size:t,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function W$(t,e,n){const r=e.vertices,o=K$(n);return jo(r,o)}function hce(t,e,n){const r=K$(n);return ab(um(W$(t,e,n),r),r)}function pce(t,e,n){const r=hce(t,e,n);return Jw(r)}function fce(t,e,n){if(t.props.dash==="draw"){const r=W$(t,e,n);return ua(r)}return e.getSvgPathData()}function G$(t,e,n){let r=`M ${je(e[0])}L`,o=`M ${je(e[0])}L`;const s=n/3,i=n*2,a=ro(t);let l=e[0],c,u=e[0],h;const p=e.length;for(let f=0,g=p-1;f<g;f++){c=e[f+1],h=x.AddXY(e[f+1],a()*s,a()*s);const m=x.Sub(c,l),v=x.Len(m),S=x.Div(m,v).mul(Math.min(v/4,i)),y=x.Add(l,S),b=x.Add(c,S.neg()),P=x.Sub(h,u),C=x.Len(P),I=x.Div(P,C).mul(Math.min(C/4,i)),T=x.Add(u,I),_=x.Add(h,I.neg());f===g-1?(r+=`${je(y)}L ${je(c)}`,o+=`${je(T)}L ${je(h)}`):(r+=`${je(y)}L ${je(b)}Q ${je(c)}`,o+=`${je(T)}L ${je(_)}Q ${je(h)}`,l=c,u=h)}return[r,r+o]}const gce=new Eo;class vp extends Zr{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,n]=ku(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[e]:{id:e,index:e,x:0,y:0},[n]:{id:n,index:n,x:.1,y:.1}},scale:1}}getGeometry(e){return Uc(e)}getHandles(e){return gce.get(e.props,()=>{const n=Uc(e),r=Bc(e),o=r.map(s=>({...s,id:s.index,type:"vertex",canSnap:!0}));for(let s=0;s<r.length-1;s++){const i=Eu(r[s].index,r[s+1].index),l=n.segments[s].midPoint();o.push({id:i,type:"create",index:i,x:l.x,y:l.y,canSnap:!0})}return o.sort(ln)})}onResize(e,n){const{scaleX:r,scaleY:o}=n;return{props:{points:Yu(e.props.points,(s,{id:i,index:a,x:l,y:c})=>({id:i,index:a,x:l*r,y:c*o}))}}}onHandleDrag(e,{handle:n}){if(n.type==="vertex")return{...e,props:{...e.props,points:{...e.props.points,[n.id]:{id:n.id,index:n.index,x:n.x,y:n.y}}}}}component(e){return d.jsx(li,{id:e.id,children:d.jsx(_E,{shape:e})})}indicator(e){const n=bo[e.props.size]*e.props.scale,r=Uc(e),{dash:o}=e.props;let s;if(e.props.spline==="line"){const i=r.points;if(o==="solid"||o==="dotted"||o==="dashed")s="M"+i[0]+"L"+i.slice(1);else{const[a]=G$(e.id,i,n);s=a}}else s=fce(e,r,n);return d.jsx("path",{d:s})}toSvg(e){return d.jsx(_E,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const n=Bc(e);return{points:n,getSelfSnapPoints:r=>{const o=this.getHandles(e).filter(s=>s.type==="vertex").findIndex(s=>s.id===r.id);return n.filter((s,i)=>Math.abs(i-o)>1).map(x.From)},getSelfSnapOutline:r=>{const o=this.getHandles(e).filter(i=>i.type==="vertex").findIndex(i=>i.id===r.id),s=Uc(e).segments.filter((i,a)=>a!==o-1&&a!==o);return s.length?new eo({children:s}):null}}}getInterpolatedProps(e,n,r){const o=Bc(e),s=Bc(n),i=[],a=[];let l=_T;if(o.length>s.length)for(let c=0;c<o.length;c++)i[c]={...o[c]},s[c]===void 0?a[c]={...s[s.length-1],id:l}:a[c]={...s[c],id:l},l=vo(l);else if(s.length>o.length)for(let c=0;c<s.length;c++)a[c]={...s[c]},o[c]===void 0?i[c]={...o[o.length-1],id:l}:i[c]={...o[c],id:l},l=vo(l);else for(let c=0;c<s.length;c++)i[c]=o[c],a[c]=s[c];return{...r>.5?n.props:e.props,points:Object.fromEntries(i.map((c,u)=>{const h=a[u];return[c.id,{...c,x:Ee(c.x,h.x,r),y:Ee(c.y,h.y,r)}]})),scale:Ee(e.props.scale,n.props.scale,r)}}}E(vp,"type","line"),E(vp,"props",mA),E(vp,"migrations",yA);function Bc(t){return Object.values(t.props.points).sort(ln)}function Uc(t){const e=Bc(t).map(x.From);switch(t.props.spline){case"cubic":return new Nee({points:e});case"line":return new Wl({points:e})}}function _E({shape:t,shouldScale:e=!1,forceSolid:n=!1}){const r=Lr(),o=Uc(t),{dash:s,color:i,size:a}=t.props,l=1/t.props.scale,c=e?l:1,u=bo[a]*t.props.scale;if(t.props.spline==="line"){if(s==="solid"){const h=o.points,p="M"+h[0]+"L"+h.slice(1);return d.jsx("path",{d:p,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}if(s==="dashed"||s==="dotted")return d.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:o.segments.map((h,p)=>{const{strokeDasharray:f,strokeDashoffset:g}=n?{strokeDasharray:"none",strokeDashoffset:"none"}:Wr(h.length,u,{style:s,start:p>0?"outset":"none",end:p<o.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:f,strokeDashoffset:g,d:h.getSvgPathData(!0),fill:"none"},p)})});if(s==="draw"){const h=o.points,[p,f]=G$(t.id,h,u);return d.jsx("path",{d:f,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}}if(t.props.spline==="cubic"){const h=o.getSvgPathData();if(s==="solid")return d.jsx("path",{strokeWidth:u,stroke:r[i].solid,fill:"none",d:h,transform:`scale(${c})`});if(s==="dashed"||s==="dotted")return d.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:o.segments.map((p,f)=>{const{strokeDasharray:g,strokeDashoffset:m}=Wr(p.length,u,{style:s,start:f>0?"outset":"none",end:f<o.segments.length-1?"outset":"none",forceSolid:n});return d.jsx("path",{strokeDasharray:g,strokeDashoffset:m,d:p.getSvgPathData(),fill:"none"},f)})});if(s==="draw")return d.jsx("path",{d:pce(t,o,u),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${c})`})}}class xp extends Zr{canEdit(){return!0}hideResizeHandles(){return!0}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(e){const{labelHeight:n,labelWidth:r}=V$(this.editor,e),{scale:o}=e.props,s=n*o,i=r*o,a=He*o,l=Th(e);return new eo({children:[new fs({width:a,height:l,isFilled:!0}),new fs({x:e.props.align==="start"?0:e.props.align==="end"?a-i:(a-i)/2,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?l-s:(l-s)/2,width:i,height:s,isFilled:!0,isLabel:!0})]})}getHandles(e){const{scale:n}=e.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const o=this.editor.getZoomLevel();if(o*n<.25)return[];const s=Th(e),i=He*n,a=zae/o*n;return o*n<.5?[{id:"bottom",index:"a3",type:"clone",x:i/2,y:s+a}]:[{id:"top",index:"a1",type:"clone",x:i/2,y:-a},{id:"right",index:"a2",type:"clone",x:i+a,y:s/2},{id:"bottom",index:"a3",type:"clone",x:i/2,y:s+a},{id:"left",index:"a4",type:"clone",x:-a,y:s/2}]}getText(e){return e.props.text}component(e){const{id:n,type:r,props:{scale:o,color:s,font:i,size:a,align:l,text:c,verticalAlign:u,fontSizeAdjustment:h}}=e,p=Sce(n),f=Lr(),g=He*o,m=Th(e),v=U("shape rotation",()=>{var b;return((b=this.editor.getShapePageTransform(n))==null?void 0:b.rotation())??0},[this.editor]),S=U("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),y=e.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:n,className:"tl-note__container",style:{width:g,height:m,backgroundColor:f[s].note.fill,borderBottom:S?`${3*o}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:S?"none":vce(e.id,v,o)},children:d.jsx(fm,{id:n,type:r,font:i,fontSize:(h||ls[a])*o,lineHeight:dn.lineHeight,align:l,verticalAlign:u,text:c,isNote:!0,isSelected:y,labelColor:f[s].note.text,wrap:!0,padding:16*o,onKeyDown:p})}),"url"in e.props&&e.props.url&&d.jsx(Tl,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(e){const{scale:n}=e.props;return d.jsx("rect",{rx:n,width:$(He*n),height:$(Th(e))})}toSvg(e,n){e.props.text&&n.addExportDef(hm(e.props.font));const r=ws({isDarkMode:n.isDarkMode}),o=xce(e);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:He-10,height:o.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:He,height:o.h,fill:r[e.props.color].note.fill}),d.jsx(pm,{fontSize:e.props.fontSizeAdjustment||ls[e.props.size],font:e.props.font,align:e.props.align,verticalAlign:e.props.verticalAlign,text:e.props.text,labelColor:r[e.props.color].note.text,bounds:o,stroke:!1})]})}onBeforeCreate(e){return IE(this.editor,e)}onBeforeUpdate(e,n){if(!(e.props.text===n.props.text&&e.props.font===n.props.font&&e.props.size===n.props.size))return IE(this.editor,n)}onEditEnd(e){const{id:n,type:r,props:{text:o}}=e;o.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:o.trimEnd()}}])}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,scale:Ee(e.props.scale,n.props.scale,r)}}}E(xp,"type","note"),E(xp,"props",SA),E(xp,"migrations",vA);function IE(t,e){const{labelHeight:n,fontSizeAdjustment:r}=V$(t,e),o=Math.max(0,n-He);if(o!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:o,fontSizeAdjustment:r}}}function mce(t,e){const{text:n}=e.props;if(!n)return{labelHeight:ls[e.props.size]*dn.lineHeight+Cr*2,labelWidth:100,fontSizeAdjustment:0};const r=ls[e.props.size];let o=0,s=0,i=He,a=He;const l=1;do{o=Math.min(r,r-s);const c=t.textMeasure.measureText(n,{...dn,fontFamily:ys[e.props.font],fontSize:o,maxWidth:He-Cr*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Cr*2,a=c.w+Cr*2,o<=14){const u=t.textMeasure.measureText(n,{...dn,fontFamily:ys[e.props.font],fontSize:o,maxWidth:He-Cr*2-l});i=u.h+Cr*2,a=u.w+Cr*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const yce=new Eo;function V$(t,e){return yce.get(e,()=>mce(t,e))}function Sce(t){const e=F(),n=IR();return w.useCallback(r=>{const o=e.getShape(t);if(!o)return;const s=r.key==="Tab",i=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(s||i){r.preventDefault();const a=e.getShapePageTransform(t),l=a.rotation(),c=!!(n.dir==="rtl"||v$(o.props.text)),u=(He+e.options.adjacentShapeMargin+(i&&!r.shiftKey?o.props.growY:0))*o.props.scale,h=new x(s?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(dm.clone().mul(o.props.scale)).rot(l).add(a.point()),p=I$(e,o,h,l);p&&(e.markHistoryStoppingPoint("editing adjacent shape"),Tf(e,p,!0))}},[t,e,n.dir])}function Th(t){return(He+t.props.growY)*t.props.scale}function vce(t,e,n){const r=ro(t),o=Math.abs(r())+.5,s=Math.cos(e),i=5*n,a=4*n,l=6*n,c=7*n;return`0px ${i-o}px ${i}px -${i}px rgba(15, 23, 31, .6),
388
- 0px ${(a+o*c)*Math.max(0,s)}px ${l+o*c}px -${a+o*l}px rgba(15, 23, 31, ${(.3+o*.1).toFixed(2)}),
389
- 0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+s)/2)).toFixed(2)})`}function xce(t){return new Z(0,0,He,He+t.props.growY)}function wce(t,{initialBounds:e,scaleX:n,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new x(0,0);n<0&&(i.x=-(e.width*s)),r<0&&(i.y=-(e.height*s));const{x:a,y:l}=x.Add(o,i.rot(t.rotation));return{x:a,y:l,props:{scale:s*t.props.scale}}}const bce=new Eo;class wp extends Zr{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return bce.get(e.props,n=>EE(this.editor,n))}getGeometry(e){const{scale:n}=e.props,{width:r,height:o}=this.getMinDimensions(e);return new fs({width:r*n,height:o*n,isFilled:!0,isLabel:!0})}getText(e){return e.props.text}canEdit(){return!0}isAspectRatioLocked(){return!0}component(e){const{id:n,props:{font:r,size:o,text:s,color:i,scale:a,textAlign:l}}=e,{width:c,height:u}=this.getMinDimensions(e),h=e.id===this.editor.getOnlySelectedShapeId(),p=Lr(),f=Pce(n);return d.jsx(fm,{id:n,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:El[o],lineHeight:dn.lineHeight,align:l,verticalAlign:"middle",text:s,labelColor:p[i].solid,isSelected:h,textWidth:c,textHeight:u,style:{transform:`scale(${a})`,transformOrigin:"top left"},wrap:!0,onKeyDown:f})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds,r=F();return e.props.autoSize&&r.getEditingShapeId()===e.id?null:d.jsx("rect",{width:$(n.width),height:$(n.height)})}toSvg(e,n){e.props.text&&n.addExportDef(hm(e.props.font));const r=this.editor.getShapeGeometry(e).bounds,o=r.width/(e.props.scale??1),s=r.height/(e.props.scale??1),i=ws(n);return d.jsx(pm,{fontSize:El[e.props.size],font:e.props.font,align:e.props.textAlign,verticalAlign:"middle",text:e.props.text,labelColor:i[e.props.color].solid,bounds:new Z(0,0,o,s),padding:0})}onResize(e,n){const{newPoint:r,initialBounds:o,initialShape:s,scaleX:i,handle:a}=n;if(n.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:e.id,type:e.type,...wce(e,n)};{const l=Math.max(1,Math.abs(o.width*i)),{x:c,y:u}=i<0?x.Sub(r,x.FromAngle(e.rotation).mul(l)):r;return{id:e.id,type:e.type,x:c,y:u,props:{w:l/s.props.scale,autoSize:!1}}}}onEditEnd(e){const{id:n,type:r,props:{text:o}}=e,s=e.props.text.trimEnd();s.length===0?this.editor.deleteShapes([e.id]):s!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:o.trimEnd()}}])}onBeforeUpdate(e,n){if(!n.props.autoSize)return;const r=e.props.size!==n.props.size||e.props.textAlign!==n.props.textAlign||e.props.font!==n.props.font||e.props.scale!==1&&n.props.scale===1,o=e.props.text!==n.props.text;if(!r&&!o)return;const s=this.getMinDimensions(e),i=EE(this.editor,n.props),a=s.width*e.props.scale,l=s.height*e.props.scale,c=i.width*n.props.scale,u=i.height*n.props.scale;let h;switch(n.props.textAlign){case"middle":{h=new x((c-a)/2,o?0:(u-l)/2);break}case"end":{h=new x(c-a,o?0:(u-l)/2);break}default:{if(o)break;h=new x(0,(u-l)/2);break}}if(h){h.rot(n.rotation);const{x:p,y:f}=n;return{...n,x:p-h.x,y:f-h.y,props:{...n.props,w:c}}}else return{...n,props:{...n.props,w:c}}}}E(wp,"type","text"),E(wp,"props",xA),E(wp,"migrations",wA);function EE(t,e){const{font:n,text:r,autoSize:o,size:s,w:i}=e,a=o?16:Math.max(16,i),l=El[s],c=o?null:Math.floor(Math.max(a,i)),u=t.textMeasure.measureText(r,{...dn,fontFamily:ys[n],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function Pce(t){const e=F();return w.useCallback(n=>{if(e.getEditingShapeId()===t)switch(n.key){case"Enter":{(n.ctrlKey||n.metaKey)&&e.complete();break}case"Tab":{we(n),n.shiftKey?kl.unindent(n.currentTarget):kl.indent(n.currentTarget);break}}},[e,t])}class bp extends Yl{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){const{editor:n}=this,r=n.getShapeGeometry(e).bounds.w*n.getZoomLevel()>=110,{asset:o,url:s}=U$({shapeId:e.id,assetId:e.props.assetId,width:e.props.w}),i=Bg(e.id),a=H$(),{Spinner:l}=rt(),c=w.useRef(null),[u,h]=w.useState(!1),[p,f]=w.useState(!1);w.useEffect(()=>{const m=()=>f(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",m),()=>document.removeEventListener("fullscreenchange",m)});const g=w.useCallback(m=>{m.currentTarget&&h(!0)},[]);return w.useEffect(()=>{const m=c.current;m&&i&&document.activeElement!==m&&m.focus()},[i,u]),w.useEffect(()=>{if(a){const m=c.current;if(!m)return;m.pause(),m.currentTime=0}},[c,a]),d.jsxs(d.Fragment,{children:[d.jsx(ri,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:o?"transparent":"var(--color-low)",border:o?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:o?l&&!o.props.src?d.jsx(l,{}):s?d.jsxs(d.Fragment,{children:[d.jsx("video",{ref:c,style:i?{pointerEvents:"all"}:u?void 0:{display:"none"},className:le("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":p}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:i&&r,onLoadedData:g,hidden:!u,children:d.jsx("source",{src:s})}),!u&&l&&d.jsx(l,{})]}):null:d.jsx(B$,{})})})}),"url"in e.props&&e.props.url&&d.jsx(Tl,{url:e.props.url,zoomLevel:n.getZoomLevel()})]})}indicator(e){return d.jsx("rect",{width:$(e.props.w),height:$(e.props.h)})}async toSvg(e){const n=await Cce(this.editor,e);return n?d.jsx("image",{href:n,width:e.props.w,height:e.props.h}):null}}E(bp,"type","video"),E(bp,"props",bA),E(bp,"migrations",PA);async function Cce(t,e){const n=await t.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});if(!n)return null;const r=await sr.loadVideo(n);return sr.getVideoFrameAsDataUrl(r,0)}const Y$=[wp,hp,pp,mp,xp,vp,gp,dp,yp,fp,Sp,bp];function _ce(t){return t.sideEffects.register({instance_page_state:{afterChange:(e,n)=>{if(e.croppingShapeId!==n.croppingShapeId){const r=t.isIn("select.crop");!e.croppingShapeId&&n.croppingShapeId?r||t.setCurrentTool("select.crop.idle"):e.croppingShapeId&&!n.croppingShapeId&&r&&t.setCurrentTool("select.idle")}e.editingShapeId!==n.editingShapeId&&(!e.editingShapeId&&n.editingShapeId?t.isIn("select.editing_shape")||t.setCurrentTool("select.editing_shape"):e.editingShapeId&&!n.editingShapeId&&t.isIn("select.editing_shape")&&t.setCurrentTool("select.idle"))}}})}class X$ extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"scribbleId","id");E(this,"markId","");E(this,"excludedShapeIds",new Set)}onEnter(n){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>{if(this.editor.isShapeOrAncestorLocked(s))return!0;if(this.editor.isShapeOfType(s,"group")||this.editor.isShapeOfType(s,"frame")){const i=this.editor.getPointInShapeSpace(s,r);return this.editor.getShapeGeometry(s).bounds.containsPoint(i)}return!1}).map(s=>s.id));const o=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=o.id,this.update()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}update(){const{editor:n,excludedShapeIds:r}=this,o=n.getErasingShapeIds(),s=n.getZoomLevel(),i=n.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=n;this.pushPointToScribble();const c=new Set(o),u=this.editor.options.hitTestMargin/s;for(const h of i){if(n.isShapeOfType(h,"group"))continue;const p=n.getShapeMask(h.id);if(p&&!ur(a,p))continue;const f=n.getShapeGeometry(h),g=n.getShapePageTransform(h);if(!f||!g)continue;const m=g.clone().invert(),v=m.applyToPoint(l),S=m.applyToPoint(a),{bounds:y}=f;y.minX-u>Math.max(v.x,S.x)||y.minY-u>Math.max(v.y,S.y)||y.maxX+u<Math.min(v.x,S.x)||y.maxY+u<Math.min(v.y,S.y)||f.hitTestLineSegment(v,S,u)&&c.add(n.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),n.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.setErasingShapes([]),n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}E(X$,"id","erasing");var RS;let Ice=(RS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},E(RS,"id","idle"),RS);var LS;let Ece=(LS=class extends ie{onEnter(){const e=this.editor.getZoomLevel(),n=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,o=new Set,s=o.size;for(let i=n.length,a=i-1;a>=0;a--){const l=n[a];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,r,{hitInside:!1,margin:this.editor.options.hitTestMargin/e})){const c=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(c,"frame")&&o.size>s)break;o.add(c.id)}}this.editor.setErasingShapes([...o])}onLongPress(e){this.startErasing(e)}onPointerMove(e){this.editor.inputs.isDragging&&this.startErasing(e)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}startErasing(e){this.parent.transition("erasing",e)}complete(){const e=this.editor.getErasingShapeIds();e.length&&(this.editor.markHistoryStoppingPoint("erase end"),this.editor.deleteShapes(e)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},E(LS,"id","pointing"),LS);class Pp extends ie{static children(){return[Ice,Ece,X$]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}E(Pp,"id","eraser"),E(Pp,"initial","idle"),E(Pp,"isLockable",!1);class q$ extends ie{constructor(){super(...arguments);E(this,"initialCamera",new x)}onEnter(){this.initialCamera=x.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:o,originScreenPoint:s}=r.inputs,i=x.Sub(o,s).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,o=Math.min(r.len(),2);o>.1&&this.editor.slideCamera({speed:o,direction:r}),this.parent.transition("idle")}}E(q$,"id","dragging");var $S;let kce=($S=class extends ie{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},E($S,"id","idle"),$S);var FS;let Tce=(FS=class extends ie{onEnter(){this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})}onLongPress(){this.startDragging()}onPointerMove(){this.editor.inputs.isDragging&&this.startDragging()}startDragging(){this.parent.transition("dragging")}onPointerUp(){this.complete()}onCancel(){this.complete()}onComplete(){this.complete()}onInterrupt(){this.complete()}complete(){this.parent.transition("idle")}},E(FS,"id","pointing"),FS);class Cp extends ie{static children(){return[kce,Tce,q$]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomIn(n,{animation:{duration:220,easing:At.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomOut(n,{animation:{duration:320,easing:At.easeOutQuint}})}}onQuadrupleClick(e){if(e.phase==="settle"){const n=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:r}}=this.editor;n===1?this.editor.zoomToFit({animation:{duration:400,easing:At.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:At.easeOutQuint}})}}}E(Cp,"id","hand"),E(Cp,"initial","idle"),E(Cp,"isLockable",!1);var NS;let Mce=(NS=class extends ie{onPointerDown(e){this.parent.transition("lasering",e)}},E(NS,"id","idle"),NS);class Z$ extends ie{constructor(){super(...arguments);E(this,"scribbleId","id")}onEnter(){const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:this.editor.options.laserDelayMs,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.pushPointToScribble()}onPointerUp(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onCancel(){this.cancel()}onComplete(){this.complete()}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}E(Z$,"id","lasering");class _p extends ie{static children(){return[Mce,Z$]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}E(_p,"id","laser"),E(_p,"initial","idle"),E(_p,"isLockable",!1);class Q$ extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"initialSelectedShapeIds",[]);E(this,"excludedShapeIds",new Set);E(this,"isWrapMode",!1);E(this,"initialStartShape",null)}onEnter(n){const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",n);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>this.editor.isShapeOfType(s,"group")||this.editor.isShapeOrAncestorLocked(s)).map(s=>s.id)),this.info=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(o)[0],this.hitTestShapes()}onExit(){this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(n){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",n)}onKeyDown(n){this.editor.inputs.altKey?this.parent.transition("scribble_brushing",n):this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:n,excludedShapeIds:r,isWrapMode:o}=this,{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=n,c=new Set(a?this.initialSelectedShapeIds:[]),u=o?!l:l,h=Z.FromPoints([s,i]),{corners:p}=h;let f,g,m,v,S,y;const b=n.getCurrentPageRenderingShapesSorted(),P=n.getCurrentPageId();e:for(let T=0,_=b.length;T<_;T++){if(m=b[T],r.has(m.id)||c.has(m.id)||(v=n.getShapePageBounds(m),!v))continue e;if(h.contains(v)){this.handleHit(m,i,P,c,p);continue e}if(u||n.isShapeOfType(m,"frame"))continue e;if(h.collides(v)){if(S=n.getShapePageTransform(m),!S)continue e;y=S.clone().invert().applyToPoints(p);const k=n.getShapeGeometry(m);t:for(let M=0;M<4;M++)if(f=y[M],g=y[(M+1)%4],k.hitTestLineSegment(f,g,0)){this.handleHit(m,i,P,c,p);break t}}}n.getInstanceState().isCoarsePointer;const C=n.getInstanceState().brush;(!C||!h.equals(C))&&n.updateInstanceState({brush:{...h.toJson()}});const I=n.getSelectedShapeIds();(I.length!==c.size||I.some(T=>!c.has(T)))&&n.setSelectedShapes(Array.from(c))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(n,r,o,s,i){if(n.parentId===o){s.add(n.id);return}const a=this.editor.getOutermostSelectableShape(n),l=this.editor.getShapeMask(a.id);l&&!gj(l,i)&&!ur(r,l)||s.add(a.id)}}E(Q$,"id","brushing");const Al={bottom:"ns-resize",top:"ns-resize",left:"ew-resize",right:"ew-resize",bottom_left:"nesw-resize",bottom_right:"nwse-resize",top_left:"nwse-resize",top_right:"nesw-resize",bottom_left_rotate:"swne-rotate",bottom_right_rotate:"senw-rotate",top_left_rotate:"nwse-rotate",top_right_rotate:"nesw-rotate",mobile_rotate:"grabbing"};class J$ extends ie{constructor(){super(...arguments);E(this,"info",{})}updateCursor(){const n=this.editor.getSelectedShapes(),r=Al[this.info.handle];this.editor.setCursor({type:r,rotation:n.length===1?this.editor.getSelectionRotation():0})}onEnter(n){this.info=n,this.updateCursor()}onPointerMove(){this.editor.inputs.isDragging&&this.startResizing()}onLongPress(){this.startResizing()}startResizing(){this.editor.getInstanceState().isReadonly||this.parent.transition("resizing",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}E(J$,"id","pointing_resize_handle");const br=8;class gb extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"markId","");E(this,"snapshot",{})}onEnter(n){this.info=n,this.markId=this.editor.markHistoryStoppingPoint("cropping"),this.snapshot=this.createSnapshot(),this.updateShapes()}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=Al[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}getDefaultCrop(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}updateShapes(){const{shape:n,cursorHandleOffset:r}=this.snapshot;if(!n||!this.editor.getShapeUtil("image"))return;const s=n.props,i=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),l=i.clone().sub(a).rot(-n.rotation),c=s.crop??this.getDefaultCrop(),u=tt(c),h=new x(n.x,n.y),p=new x(0,0),f=1/(c.bottomRight.x-c.topLeft.x)*s.w,g=1/(c.bottomRight.y-c.topLeft.y)*s.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(g<br)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/g,g*(u.bottomRight.y-u.topLeft.y)<br?(u.topLeft.y=u.bottomRight.y-br/g,p.y=(u.topLeft.y-c.topLeft.y)*g):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-c.topLeft.y)*g):p.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(g<br)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/g),g*(u.bottomRight.y-u.topLeft.y)<br&&(u.bottomRight.y=u.topLeft.y+br/g);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<br)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<br?(u.topLeft.x=u.bottomRight.x-br/f,p.x=(u.topLeft.x-c.topLeft.x)*f):u.topLeft.x<=0?(u.topLeft.x=0,p.x=(u.topLeft.x-c.topLeft.x)*f):p.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(f<br)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<br&&(u.bottomRight.x=u.topLeft.x+br/f);break}}if(!m)return;h.add(p.rot(n.rotation));const v={id:n.id,type:n.type,x:h.x,y:h.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*f,h:(u.bottomRight.y-u.topLeft.y)*g}};this.editor.updateShapes([v]),this.updateCursor()}complete(){this.updateShapes(),Ve(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const n=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),s=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(s.getHandlePoint(this.info.handle),s.point,n),a=x.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}E(gb,"id","cropping");function e5(t,e=!1){const n=t.getZoomLevel(),{inputs:{currentPagePoint:r}}=t;return t.getShapeAtPoint(r,{hitInside:!1,hitLabels:e,margin:t.options.hitTestMargin/n,renderingOnly:!0})??t.getSelectedShapeAtPoint(r)}function t5(t,e,n){if(!e)throw Error("Needs to translate a cropped shape!");const{crop:r}=e.props;if(!r)return;const o=t.inputs.shiftKey?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;o==="x"?n.x=0:o==="y"&&(n.y=0),n.rot(-e.rotation);const s=1/(r.bottomRight.x-r.topLeft.x)*e.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*e.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=tt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-n.x/s)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-n.y/i)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:e.id,type:e.type,props:{crop:c}}}var zS;let Ace=(zS=class extends ie{onEnter(){this.editor.setCursor({type:"default",rotation:0});const e=this.editor.getOnlySelectedShape();e&&this.editor.setCroppingShape(e.id)}onExit(){this.editor.setCursor({type:"default",rotation:0})}onCancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}onPointerDown(e){var n;if(!this.editor.getIsMenuOpen()){if(e.ctrlKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{const r=e5(this.editor);if(r&&!this.editor.isShapeOfType(r,"group")){this.onPointerDown({...e,shape:r,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(e);break}case"shape":{if(e.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",e);return}else(n=this.editor.getShapeUtil(e.shape))!=null&&n.canCrop(e.shape)?(this.editor.setCroppingShape(e.shape.id),this.editor.setSelectedShapes([e.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",e)):(this.cancel(),this.editor.root.handleEvent(e));break}case"selection":{switch(e.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...e,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...e,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}}onDoubleClick(e){var s;if(this.editor.inputs.shiftKey||e.phase!=="up")return;const n=this.editor.getCroppingShapeId();if(!n)return;const r=this.editor.getShape(n);if(!r)return;const o=this.editor.getShapeUtil(r);if(o){if(e.target==="selection"){(s=o.onDoubleClickEdge)==null||s.call(o,r);return}this.cancel(),this.editor.root.handleEvent(e)}}onKeyDown(){this.nudgeCroppingImage(!1)}onKeyRepeat(){this.nudgeCroppingImage(!0)}onKeyUp(e){switch(e.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(e=!1){const{editor:{inputs:{keys:n}}}=this,r=n.has("ShiftLeft"),o=new x(0,0);if(n.has("ArrowLeft")&&(o.x+=1),n.has("ArrowRight")&&(o.x-=1),n.has("ArrowUp")&&(o.y+=1),n.has("ArrowDown")&&(o.y-=1),o.equals(new x(0,0)))return;r&&o.mul(10);const s=this.editor.getShape(this.editor.getCroppingShapeId());if(!s)return;const i=t5(this.editor,s,o);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},E(zS,"id","idle"),zS);class n5 extends ie{onCancel(){this.editor.setCurrentTool("select.crop.idle",{})}onPointerMove(e){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",e)}onPointerUp(e){this.editor.setCurrentTool("select.crop.idle",e)}}E(n5,"id","pointing_crop");class mb extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=Al[this.info.handle];this.editor.setCursor({type:o,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){this.editor.inputs.isDragging&&this.startCropping()}onLongPress(){this.startCropping()}startCropping(){this.editor.getInstanceState().isReadonly||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}onPointerUp(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}E(mb,"id","pointing_crop_handle");class r5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"markId","");E(this,"snapshot",{})}onEnter(n){this.info=n,this.snapshot=this.createSnapshot(),this.markId=this.editor.markHistoryStoppingPoint("translating_crop"),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onKeyDown(n){switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}}onKeyUp(n){switch(n.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const n=this.snapshot.shape;if(!n)return;const{originPagePoint:r,currentPagePoint:o}=this.editor.inputs,s=o.clone().sub(r),i=t5(this.editor,n,s);i&&this.editor.updateShapes([i])}}E(r5,"id","translating_crop");class Jx extends ie{constructor(){super(...arguments);E(this,"markId","");E(this,"didExit",!1)}static children(){return[Ace,r5,n5,mb,gb]}onEnter(){this.didExit=!1,this.markId=this.editor.markHistoryStoppingPoint("crop")}onExit(){this.didExit||(this.didExit=!0,this.editor.squashToMark(this.markId))}onCancel(){this.didExit||(this.didExit=!0,this.editor.bailToMark(this.markId))}}E(Jx,"id","crop"),E(Jx,"initial","idle");class o5 extends ie{constructor(){super(...arguments);E(this,"shapeId","");E(this,"initialHandle",{});E(this,"initialAdjacentHandle",null);E(this,"initialPagePoint",{});E(this,"markId","");E(this,"initialPageTransform");E(this,"initialPageRotation");E(this,"info",{});E(this,"isPrecise",!1);E(this,"isPreciseId",null);E(this,"pointingId",null);E(this,"exactTimeout",-1)}onEnter(n){const{shape:r,isCreating:o,creatingMarkId:s,handle:i}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId="",o)if(s)this.markId=s;else{const c=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);c&&(this.markId=c)}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");if(this.initialHandle=tt(i),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[i.index]:{id:i.index,index:i.index,x:i.x,y:i.y}}}});const u=this.editor.getShapeHandles(r).find(h=>h.index===i.index);this.initialHandle=tt(u)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.setCursor({type:o?"cross":"grabbing",rotation:0});const a=this.editor.getShapeHandles(r).sort(ln),l=a.findIndex(c=>c.id===n.handle.id);this.initialAdjacentHandle=null;for(let c=l+1;c<a.length;c++){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(!this.initialAdjacentHandle)for(let c=a.length-1;c>=0;c--){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=Fn(this.editor,r)[n.handle.id];this.isPrecise=!1,c?(this.editor.setHintingShapes([c.toId]),this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.update(),this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),Ve(this.editor,[this.shapeId]);const{onInteractionEnd:n}=this.info;if(this.editor.getInstanceState().isToolLocked&&n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:n}=this.info;if(n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var T;const{editor:n,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:h,shiftKey:p,ctrlKey:f,altKey:g,pointerVelocity:m}}=n,v=this.info.shape,S=n.getShape(r);if(!S)return;const y=n.getShapeUtil(S);let b=h.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const _=x.Angle(a,b),M=Cf(_,24)-_;b=x.RotWith(b,a,M)}n.snaps.clearIndicators();let P={...s,x:b.x,y:b.y};if(s.canSnap&&(c?!f:f)){if(!n.getShapePageTransform(S.id))throw Error("Expected a page transform");const k=u.handles.snapHandle({currentShapeId:r,handle:P});k&&(k.nudge.rot(-n.getShapeParentTransform(S).rotation()),b.add(k.nudge),P={...s,x:b.x,y:b.y})}const C=(T=y.onHandleDrag)==null?void 0:T.call(y,S,{handle:P,isPrecise:this.isPrecise||g,initial:v}),I={id:S.id,type:S.type,...C};if(s.type==="vertex"&&this.editor.isShapeOfType(S,"arrow")){const _=Fn(n,S)[s.id];_?l[0]!==_.toId&&(n.setHintingShapes([_.toId]),this.pointingId=_.toId,this.isPrecise=m.len()<.5||g,this.isPreciseId=this.isPrecise?_.toId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&n.updateShapes([I])}}E(o5,"id","dragging_handle");function s5(t){return t.isLabel?[t]:t instanceof eo?t.children.filter(e=>e.isLabel):[]}class i5 extends ie{constructor(){super(...arguments);E(this,"hitShapeForPointerUp",null)}onEnter(){const n=this.editor.getEditingShape();if(!n)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,ts(this.editor),this.editor.select(n)}onExit(){var s;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),ts.cancel();const r=this.editor.getShape(n),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r)}onPointerMove(n){if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly||this.hitShapeForPointerUp.isLocked)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",n),this.hitShapeForPointerUp=null;return}switch(n.target){case"shape":case"canvas":{ts(this.editor);return}}}onPointerDown(n){switch(this.hitShapeForPointerUp=null,n.target){case"shape":{const{shape:r}=n,o=this.editor.getEditingShape();if(!o)throw Error("Expected an editing shape!");const s=this.editor.getShapeUtil(r).getGeometry(r),i=s5(s),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(o,"text")&&o.props.text.trim()==="";if(a&&!l){const c=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(c,0)&&a.hitTestPoint(c)){if(r.id===o.id)return;this.hitShapeForPointerUp=r,this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===o.id)this.editor.isShapeOfType(r,"frame")&&(this.editor.setEditingShape(null),this.parent.transition("idle",n));else{this.parent.transition("pointing_shape",n);return}return}break}}this.parent.transition("idle",n),this.editor.root.handleEvent(n)}onPointerUp(n){const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const o=this.editor.getShapeUtil(r);if(!r.isLocked){if(this.editor.getInstanceState().isReadonly&&!o.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),ts(this.editor)}}onComplete(n){this.parent.transition("idle",n)}onCancel(n){this.parent.transition("idle",n)}}E(i5,"id","editing_shape");function kE(t){const e=t.getOnlySelectedShape();return!!(e&&!t.isShapeOrAncestorLocked(e)&&t.getShapeUtil(e).canCrop(e))}function Wf(t){const e=t.getSelectedShapeIds(),{shiftKey:n,altKey:r,currentPagePoint:o}=t.inputs,s=t.getShapeAtPoint(o,{hitInside:!1,margin:t.options.hitTestMargin/t.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:i=>!i.isLocked});if(s){const i=t.getOutermostSelectableShape(s);if(n&&!r)t.cancelDoubleClick(),e.includes(i.id)?(t.markHistoryStoppingPoint("deselecting shape"),t.deselect(i)):(t.markHistoryStoppingPoint("shift selecting shape"),t.setSelectedShapes([...e,i.id]));else{let a;i===s||i.id===t.getFocusedGroupId()||e.includes(i.id)?a=s:a=i,a&&!e.includes(a.id)&&(t.markHistoryStoppingPoint("selecting shape"),t.select(a.id))}}else{if(n)return;{e.length>0&&(t.markHistoryStoppingPoint("selecting none"),t.selectNone());const i=t.getFocusedGroupId();if(Rn(i)){const a=t.getShape(i);t.isPointInShape(a,o,{margin:0,hitInside:!0})||t.setFocusedGroup(null)}}}}const jce=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var BS;let Oce=(BS=class extends ie{constructor(){super(...arguments);E(this,"isDarwin",window.navigator.userAgent.toLowerCase().indexOf("mac")>-1)}onEnter(){this.parent.setCurrentToolIdMask(void 0),ts(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){ts.cancel()}onPointerMove(){ts(this.editor)}onPointerDown(n){if(this.editor.getIsMenuOpen())return;const r=n.ctrlKey&&kE(this.editor);if(n.ctrlKey&&!r){if(n.target==="shape"&&this.isDarwin&&this.editor.inputs.keys.has("ControlLeft")&&!this.editor.isShapeOrAncestorLocked(n.shape)){this.parent.transition("pointing_shape",n);return}this.parent.transition("brushing",n);return}switch(n.target){case"canvas":{const o=e5(this.editor);if(o&&!o.isLocked){this.onPointerDown({...n,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&TE(this.editor,a)){this.onPointerDown({...n,target:"selection"});return}this.parent.transition("pointing_canvas",n);break}case"shape":{const{shape:o}=n;if(this.isOverArrowLabelTest(o)){this.parent.transition("pointing_arrow_label",n);break}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",n);break}this.parent.transition("pointing_shape",n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",n):this.parent.transition("pointing_handle",n);break}case"selection":{switch(n.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",n);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("crop.pointing_crop_handle",n):this.parent.transition("pointing_resize_handle",n);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...n,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",n)}}break}}}onDoubleClick(n){var r,o,s,i;if(!(this.editor.inputs.shiftKey||n.phase!=="up"))switch(n.target){case"canvas":{const a=this.editor.getHoveredShape(),l=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),c=this.editor.getFocusedGroupId();if(l){if(this.editor.isShapeOfType(l,"group")){Wf(this.editor);return}else{const u=this.editor.getShape(l.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(c&&u.id===c)){Wf(this.editor);return}}this.onDoubleClick({...n,shape:l,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(n);break}case"selection":{if(this.editor.getInstanceState().isReadonly)break;const a=this.editor.getOnlySelectedShape();if(a){const l=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(n.handle==="right"||n.handle==="left"||n.handle==="top"||n.handle==="bottom"){const c=(r=l.onDoubleClickEdge)==null?void 0:r.call(l,a);if(c){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([c]),Ve(this.editor,[a.id]);return}}if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",n);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,n,!0)}break}case"shape":{const{shape:a}=n,l=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(l.onDoubleClick){const c=(o=l.onDoubleClick)==null?void 0:o.call(l,a);if(c){this.editor.updateShapes([c]);return}}if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.markHistoryStoppingPoint("select and crop"),this.editor.select((s=n.shape)==null?void 0:s.id),this.parent.transition("crop",n);return}this.shouldStartEditingShape(a)?this.startEditingShape(a,n,!0):this.handleDoubleClickOnCanvas(n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:l}=n,c=this.editor.getShapeUtil(a),u=(i=c.onDoubleClickHandle)==null?void 0:i.call(c,a,l);u?this.editor.updateShapes([u]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,n,!0)}}}onRightClick(n){switch(n.target){case"canvas":{const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...n,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&TE(this.editor,a)){this.onRightClick({...n,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=n,s=this.editor.getOutermostSelectableShape(o,i=>!r.includes(i.id));!r.includes(s.id)&&!this.editor.findShapeAncestor(s,i=>r.includes(i.id))&&(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}}onCancel(){this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.markHistoryStoppingPoint("clearing selection"),this.editor.selectNone())}onKeyDown(n){switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(xt.editOnType.get()&&!jce.includes(n.key)&&!n.altKey&&!n.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...n,target:"shape",shape:r},!0);return}}}onKeyRepeat(n){switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}}onKeyUp(n){switch(n.code){case"Enter":{const r=this.editor.getSelectedShapes();if(r.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(r.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const o=this.editor.getOnlySelectedShape();if(o&&this.shouldStartEditingShape(o)){this.startEditingShape(o,{...n,target:"shape",shape:o},!0);return}kE(this.editor)&&this.parent.transition("crop",n);break}}}shouldStartEditingShape(n=this.editor.getOnlySelectedShape()){return!n||this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||!this.canInteractWithShapeInReadOnly(n)?!1:this.editor.getShapeUtil(n).canEdit(n)}startEditingShape(n,r,o){this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||(this.editor.markHistoryStoppingPoint("editing shape"),Tf(this.editor,n,o),this.parent.transition("editing_shape",r))}isOverArrowLabelTest(n){if(!n)return!1;const r=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(n,"arrow")){const o=this.editor.getShapeGeometry(n).children[1];if(o&&ur(r,o.vertices))return!0}return!1}handleDoubleClickOnCanvas(n){if(this.editor.getInstanceState().isReadonly)return;this.editor.markHistoryStoppingPoint("creating text shape");const r=Ne(),{x:o,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:o,y:s,props:{text:"",autoSize:!0}}]);const i=this.editor.getShape(r);if(!i)return;const a=this.editor.getShapeUtil(i);this.editor.getInstanceState().isReadonly&&!a.canEditInReadOnly(i)||(this.editor.setEditingShape(r),this.editor.select(r),this.parent.transition("editing_shape",n))}nudgeSelectedShapes(n=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new x(0,0);if(r.has("ArrowLeft")&&(s.x-=1),r.has("ArrowRight")&&(s.x+=1),r.has("ArrowUp")&&(s.y-=1),r.has("ArrowDown")&&(s.y+=1),s.equals(new x(0,0)))return;n||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*Lce:i:o?Dce:Rce,l=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(l,s.mul(a)),Ve(this.editor,l)}canInteractWithShapeInReadOnly(n){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(n).canEditInReadOnly(n))}},E(BS,"id","idle"),BS);const Dce=10,Rce=1,Lce=5;function TE(t,e){const n=t.getSelectionRotatedPageBounds();if(!n)return!1;const r=t.getSelectionRotation();return r?ur(e,n.corners.map(o=>x.RotWith(o,n.point,r))):n.containsPoint(e)}class a5 extends ie{constructor(){super(...arguments);E(this,"shapeId","");E(this,"markId","");E(this,"wasAlreadySelected",!1);E(this,"didDrag",!1);E(this,"info",{});E(this,"_labelDragOffset",new x(0,0))}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(n){const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const s=this.editor.getShapeGeometry(r).children[1];if(!s)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);this._labelDragOffset=x.Sub(s.center,a),this.markId=this.editor.markHistoryStoppingPoint("label-drag start"),this.editor.setSelectedShapes([this.shapeId])}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){const{isDragging:n}=this.editor.inputs;if(!n)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=wo(this.editor,r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(x.Add(a,this._labelDragOffset));let c;if(o.isStraight){const u=x.Dist(o.start.point,o.end.point);c=1-x.Dist(o.end.point,l)/u}else{const{_center:u,measure:h,angleEnd:p,angleStart:f}=s.children[0];c=lx(h,f,p,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})}onPointerUp(){const n=this.editor.getShape(this.shapeId);n&&(this.didDrag||!this.wasAlreadySelected?this.complete():(this.editor.setEditingShape(n.id),this.editor.setCurrentTool("select.editing_shape")))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}E(a5,"id","pointing_arrow_label");class l5 extends ie{onEnter(){const{inputs:e}=this.editor;e.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.markHistoryStoppingPoint("selecting none"),this.editor.selectNone())}onPointerMove(e){this.editor.inputs.isDragging&&this.parent.transition("brushing",e)}onPointerUp(){Wf(this.editor),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}E(l5,"id","pointing_canvas");class c5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const o=Fn(this.editor,r)[n.handle.id];o&&this.editor.setHintingShapes([o.toId])}this.editor.setCursor({type:"grabbing",rotation:0})}onExit(){this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})}onPointerUp(){const{shape:n,handle:r}=this.info;if(this.editor.isShapeOfType(n,"note")){const{editor:o}=this,s=ME(o,n,r,!1);if(s){Tf(o,s,!0);return}}this.parent.transition("idle",this.info)}onPointerMove(){const{editor:n}=this;n.inputs.isDragging&&this.startDraggingHandle()}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){const{editor:n}=this;if(n.getInstanceState().isReadonly)return;const{shape:r,handle:o}=this.info;if(n.isShapeOfType(r,"note")){const s=ME(n,r,o,!0);if(s){const i=n.getPointInParentSpace(s,n.inputs.originPagePoint).sub(x.Rot(dm.clone().mul(r.props.scale),s.rotation));n.updateShape({...s,x:i.x,y:i.y}),n.setHoveredShape(s.id).select(s.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:n.getShape(s),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{Tf(n,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}E(c5,"id","pointing_handle");function ME(t,e,n,r){const o=t.getShapePageTransform(e.id),s=o.point(),i=o.rotation(),l=C$(t,s,i,e.props.growY,0,e.props.scale)[n.index];if(l)return I$(t,e,l,i,r)}class u5 extends ie{constructor(){super(...arguments);E(this,"info",{})}updateCursor(){this.editor.setCursor({type:Al[this.info.handle],rotation:this.editor.getSelectionRotation()})}onEnter(n){this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.editor.inputs.isDragging&&this.startRotating()}onLongPress(){this.startRotating()}startRotating(){this.editor.getInstanceState().isReadonly||this.parent.transition("rotating",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}E(u5,"id","pointing_rotate_handle");class d5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n}onPointerUp(n){Wf(this.editor),this.parent.transition("idle",n)}onPointerMove(n){this.editor.inputs.isDragging&&this.startTranslating(n)}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",n)}onDoubleClick(n){var s,i;const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(o){this.parent.transition("idle"),(i=(s=this.parent).onDoubleClick)==null||i.call(s,{...n,target:"shape",shape:this.editor.getShape(o)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}E(d5,"id","pointing_selection");class h5 extends ie{constructor(){super(...arguments);E(this,"hitShape",{});E(this,"hitShapeForPointerUp",{});E(this,"isDoubleClick",!1);E(this,"didSelectOnEnter",!1)}onEnter(n){const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:l}}=this.editor;this.hitShape=n.shape,this.isDoubleClick=!1;const c=this.editor.getOutermostSelectableShape(n.shape),u=this.editor.findShapeAncestor(c,h=>r.includes(h.id));if(this.editor.getShapeUtil(n.shape).onClick||c.id===s||r.includes(c.id)||u||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=c;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(c.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...r,c.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([c.id]))}onPointerUp(n){var u;const r=this.editor.getSelectedShapeIds(),o=this.editor.getFocusedGroupId(),s=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i,shiftKey:a}}=this.editor,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/s,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const h=this.editor.getShapeUtil(c);if(h.onClick){const p=(u=h.onClick)==null?void 0:u.call(h,c);if(p){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",n);return}}if(c.id===o){r.length>0?(this.editor.markHistoryStoppingPoint("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",n);return}}if(!this.didSelectOnEnter){const h=this.editor.getOutermostSelectableShape(l,p=>!r.includes(p.id));if(r.includes(h.id))if(a)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const p=this.editor.getShapeUtil(c).getGeometry(c),f=s5(p),g=f.length===1?f[0]:void 0;if(g){const m=this.editor.getPointInShapeSpace(c,i);if(g.bounds.containsPoint(m,0)&&g.hitTestPoint(m)){this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(c.id);const v=this.editor.getShapeUtil(c);this.editor.getInstanceState().isReadonly&&!v.canEditInReadOnly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:c.id}))});return}}}this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c);else if(a){const p=this.editor.getShapeAncestors(h);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(f=>!p.find(g=>g.id===f)),h.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",n)}onDoubleClick(){this.isDoubleClick=!0}onPointerMove(n){this.editor.inputs.isDragging&&this.startTranslating(n)}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getInstanceState().isReadonly||(this.editor.focus(),this.parent.transition("translating",n))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}E(h5,"id","pointing_shape");class p5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"markId","");E(this,"didHoldCommand",!1);E(this,"creationCursorOffset",{x:0,y:0});E(this,"snapshot",{})}onEnter(n){const{isCreating:r=!1,creatingMarkId:o,creationCursorOffset:s={x:0,y:0}}=n;if(this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=s,this.snapshot=this._createSnapshot(),this.markId="",r)if(o)this.markId=o;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("starting resizing");r&&this.editor.setCursor({type:"cross",rotation:0}),this.handleResizeStart(),this.updateShapes()}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var n,r;if(Ve(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(n=this.info).onCreate)==null||r.call(n,this.editor.getOnlySelectedShape());return}if(this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd){this.editor.setCurrentTool(this.info.onInteractionEnd,{});return}this.parent.transition("idle")}handleResizeStart(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:o})=>{var a;const s=this.editor.getShapeUtil(o),i=(a=s.onResizeStart)==null?void 0:a.call(s,o);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:o})=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onResizeEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:n,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot;let h=r||!u;if(s.size===1){const _=[...s.values()][0];this.editor.isShapeOfType(_.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),g=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:_}=this.editor.getDocumentSettings();f.snapToGrid(_)}const m=this.info.handle,v=AE(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%qe===0){const{nudge:_}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:x.Sub(f,g),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:AE(m,c),isAspectRatioLocked:h,isResizingFromCenter:n});f.add(_)}const y=x.RotWith(n?i.center:i.getHandlePoint(v),i.point,c),b=x.Sub(f,y).rot(-c),P=x.Sub(g,y).rot(-c),C=x.DivV(b,P);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const I=m==="top"||m==="bottom",T=m==="left"||m==="right";h?T?C.y=Math.abs(C.x):I?C.x=Math.abs(C.y):Math.abs(C.x)>Math.abs(C.y)?C.y=Math.abs(C.x)*(C.y<0?-1:1):C.x=Math.abs(C.y)*(C.x<0?-1:1):(I&&(C.x=1),T&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:c});for(const _ of s.keys()){const k=s.get(_);this.editor.resizeShape(_,C,{initialShape:k.shape,initialBounds:k.bounds,initialPageTransform:k.pageTransform,dragHandle:m,mode:l.length===1&&_===l[0]?"resize_bounds":"scale_shape",scaleOrigin:y,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:_,children:k}of o){if(!k.length)continue;const M=s.get(_).shape,R=this.editor.getShape(_);if(!(M&&R))continue;const j=R.x-M.x,O=R.y-M.y,D=new x(j,O).rot(-M.rotation);if(D.x!==0||D.y!==0)for(const B of k)this.editor.updateShape({id:B.id,type:B.type,x:B.x-D.x,y:B.y-D.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:_}of o)if(_.length)for(const k of _)this.editor.updateShape({id:k.id,type:k.type,x:k.x,y:k.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==o&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==o&&(i.type="nwse-resize");break}}i.rotation=s,this.editor.setCursor(i)}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()}_createSnapshot(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=x.Sub(o,i),l=new Map,c=[];n.forEach(h=>{const p=this.editor.getShape(h);if(p){if(p.type==="frame"&&c.push({id:h,children:ye(this.editor.getSortedChildIdsForParent(p).map(f=>this.editor.getShape(f)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&n.length===1)return;this.editor.visitDescendants(p.id,f=>{const g=this.editor.getShape(f);if(g&&(l.set(g.id,this._createShapeSnapshot(g)),this.editor.isShapeOfType(g,"frame")))return!1})}});const u=![...l.values()].some(h=>!kA(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}}_createShapeSnapshot(n){const r=this.editor.getShapePageTransform(n),o=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:q.Decompose(r).rotation,isAspectRatioLocked:o.isAspectRatioLocked(n)}}}E(p5,"id","resizing");const mS=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function AE(t,e){e=e%Fe;const n=Math.round(e/(De/4)),r=mS.indexOf(t);return mS[(r+n)%mS.length]}const jE=Math.PI/180;class f5 extends ie{constructor(){super(...arguments);E(this,"snapshot",{});E(this,"info",{});E(this,"markId","")}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=Fj({editor:this.editor,ids:this.editor.getSelectedShapeIds()});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});ep({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:Al[this.info.handle],rotation:o+this.snapshot.initialShapesRotation})}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}update(){const n=this._getRotationFromPointerPosition({snapToNearestDegree:!1});ep({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:Al[this.info.handle],rotation:n+this.snapshot.initialShapesRotation})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)}complete(){ep({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ve(this.editor,this.snapshot.shapeSnapshots.map(n=>n.shape.id)),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)}_getRotationFromPointerPosition({snapToNearestDegree:n}){const r=this.editor.getSelectionRotation(),o=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:s,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialShapesRotation:l}=this.snapshot;if(!o)return l;const u=o.center.clone().rotWith(o.point,r).angle(i)-a;let h=l+u;if(s)h=Cf(h,24);else if(n&&(h=Math.round(h/jE)*jE,this.editor.getInstanceState().isCoarsePointer)){const p=Cf(h,4),f=Zh(h,p);Math.abs(f)<kY(5)&&(h=p)}return h-l}}E(f5,"id","rotating");class g5 extends ie{constructor(){super(...arguments);E(this,"hits",new Set);E(this,"size",0);E(this,"scribbleId","id");E(this,"initialSelectedShapeIds",new Set);E(this,"newlySelectedShapeIds",new Set)}onEnter(){this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const n=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=n.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.updateScribbleSelection(!0)}onPointerUp(){this.complete()}onKeyDown(){this.updateScribbleSelection(!1)}onKeyUp(){this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")}onCancel(){this.cancel()}onComplete(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}updateScribbleSelection(n){const{editor:r}=this,o=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const h=o;let p,f,g,m;const v=0;for(let b=0,P=h.length;b<P;b++){if(p=h[b],r.isShapeOfType(p,"group")||c.has(p.id)||r.isShapeOrAncestorLocked(p)||(f=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&f.bounds.containsPoint(r.getPointInShapeSpace(p,i))))continue;const C=r.getShapePageTransform(p);if(!f||!C)continue;const I=C.clone().invert();g=I.applyToPoint(a),m=I.applyToPoint(l);const{bounds:T}=f;if(!(T.minX-v>Math.max(g.x,m.x)||T.minY-v>Math.max(g.y,m.y)||T.maxX+v<Math.min(g.x,m.x)||T.maxY+v<Math.min(g.y,m.y))&&f.hitTestLineSegment(g,m,v)){const _=this.editor.getOutermostSelectableShape(p),k=this.editor.getShapeMask(_.id);if(k&&o1(a,l,k)!==null&&!ur(l,k))continue;c.add(_.id)}}const S=r.getSelectedShapeIds(),y=new Set(s?[...c,...u]:[...c]);(S.length!==y.size||S.some(b=>!y.has(b)))&&this.editor.setSelectedShapes(Array.from(y))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}E(g5,"id","scribble_brushing");var $ce=Object.create,m5=Object.defineProperty,Fce=Object.getOwnPropertyDescriptor,Nce=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),y5=t=>{throw TypeError(t)},S5=(t,e,n)=>e in t?m5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zce=t=>[,,,$ce(null)],v5=["class","method","getter","setter","accessor","field","value","get","set"],x5=t=>t!==void 0&&typeof t!="function"?y5("Function expected"):t,Bce=(t,e,n,r,o)=>({kind:v5[t],name:e,metadata:r,addInitializer:s=>n._?y5("Already initialized"):o.push(x5(s||null))}),Uce=(t,e)=>S5(e,Nce("metadata"),t[3]),Hce=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},Kce=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=v5[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,Fce(o,n)),S=r.length-1;S>=0;S--)l=Bce(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,x5(i)&&(v[g]=i);return v&&m5(o,n,v),o},yS=(t,e,n)=>S5(t,typeof e!="symbol"?e+"":e,n),w5,mm;const Wce=20,Gce=100;w5=[ar];class yb{constructor(e){this.editor=e,Hce(mm,5,this),yS(this,"prevDroppingShapeId",null),yS(this,"droppingNodeTimer",null),yS(this,"first",!0),e.disposables.add(this.dispose)}updateDroppingNode(e,n){var r;this.first&&(this.editor.setHintingShapes(e.map(o=>this.editor.findShapeAncestor(o,s=>s.type!=="group")).filter(o=>o)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,e))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(e,Wce,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Gce,n))}setDragTimer(e,n,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.run(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,e,r)}),this.droppingNodeTimer=null},n)}handleDrag(e,n,r){var l,c,u,h,p;n=ye(n.map(f=>this.editor.getShape(f.id)));const o=((l=this.editor.getDroppingOverShape(e,n))==null?void 0:l.id)??null;if(o===this.prevDroppingShapeId){this.hintParents(n);return}const{prevDroppingShapeId:s}=this,i=s&&this.editor.getShape(s),a=o&&this.editor.getShape(o);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,n)),a&&((p=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(h,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=o}hintParents(e){const n=new Map;for(const o of e){const s=this.editor.findShapeAncestor(o,i=>i.type!=="group");s&&(n.has(s.id)||n.set(s.id,[]),n.get(s.id).push(o.id))}const r=[];for(const[o,s]of n){const i=this.editor.getShape(o);i&&bR(this.editor,i).length<s.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(e){var r,o;const{prevDroppingShapeId:n}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,e),n){const s=this.editor.getShape(n);if(!s)return;(o=(r=this.editor.getShapeUtil(s)).onDropShapesOver)==null||o.call(r,s,e)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}dispose(){this.clear()}}mm=zce();Kce(mm,1,"dispose",w5,yb);Uce(mm,yb);var Vce=Object.create,b5=Object.defineProperty,Yce=Object.getOwnPropertyDescriptor,P5=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),C5=t=>{throw TypeError(t)},_5=(t,e,n)=>e in t?b5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Xce=t=>[,,,Vce((t==null?void 0:t[P5("metadata")])??null)],I5=["class","method","getter","setter","accessor","field","value","get","set"],E5=t=>t!==void 0&&typeof t!="function"?C5("Function expected"):t,qce=(t,e,n,r,o)=>({kind:I5[t],name:e,metadata:r,addInitializer:s=>n._?C5("Already initialized"):o.push(E5(s||null))}),Zce=(t,e)=>_5(e,P5("metadata"),t[3]),Qce=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},Jce=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=I5[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,Yce(o,n)),S=r.length-1;S>=0;S--)l=qce(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,E5(i)&&(v[g]=i);return v&&b5(o,n,v),o},Ds=(t,e,n)=>_5(t,typeof e!="symbol"?e+"":e,n),k5,e0,ym;class Sm extends(e0=ie,k5=[ar],e0){constructor(){super(...arguments),Qce(ym,5,this),Ds(this,"info",{}),Ds(this,"selectionSnapshot",{}),Ds(this,"snapshot",{}),Ds(this,"markId",""),Ds(this,"isCloning",!1),Ds(this,"isCreating",!1),Ds(this,"dragAndDropManager",new yb(this.editor))}onCreate(e){}onEnter(e){var s;const{isCreating:n=!1,creatingMarkId:r,onCreate:o=()=>{}}=e;if(!((s=this.editor.getSelectedShapeIds())!=null&&s.length)){this.parent.transition("idle");return}if(this.info=e,this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.isCreating=n,this.markId="",n)if(r)this.markId=r;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("translating");if(this.onCreate=o,this.isCloning=!1,this.info=e,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=OE(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()}onTick({elapsed:e}){const{editor:n}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),n.edgeScrollManager.updateEdgeScrolling(e)}onPointerMove(){this.updateShapes()}onKeyDown(){if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()}onKeyUp(){if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}startCloning(){this.isCreating||(this.isCloning=!0,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate cloning"),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=OE(this.editor),this.handleStart(),this.updateShapes())}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate"),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){var e;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),Ve(this.editor,this.snapshot.movingShapes.map(n=>n.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(e=this.onCreate)==null||e.call(this,this.editor.getOnlySelectedShape()):this.parent.transition("idle")}cancel(){this.reset(),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.parent.transition("idle",this.info)}handleStart(){const{movingShapes:e}=this.snapshot,n=[];e.forEach(r=>{var i;const o=this.editor.getShapeUtil(r),s=(i=o.onTranslateStart)==null?void 0:i.call(o,r);s&&n.push(s)}),n.length>0&&this.editor.updateShapes(n),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:e}=this.snapshot;if(this.isCloning&&e.length>0){const r=x.Average(e.map(s=>this.editor.getShapePageTransform(s.id).point())),o=x.Sub(r,this.selectionSnapshot.averagePagePoint);x.IsNaN(o)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(s=>s.id),offset:{x:o.x,y:o.y}}})}const n=[];e.forEach(r=>{var a;const o=this.editor.getShape(r.id),s=this.editor.getShapeUtil(r),i=(a=s.onTranslateEnd)==null?void 0:a.call(s,r,o);i&&n.push(i)}),n.length>0&&this.editor.updateShapes(n)}updateShapes(){const{snapshot:e}=this;this.dragAndDropManager.updateDroppingNode(e.movingShapes,this.updateParentTransforms),eue({editor:this.editor,snapshot:e});const{movingShapes:n}=e,r=[];n.forEach(o=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onTranslate)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateParentTransforms(){const{editor:e,snapshot:{shapeSnapshots:n}}=this;n.forEach(r=>{const o=e.getShape(r.shape.id);if(!o)return null;const s=jn(o.parentId)?null:q.Inverse(e.getShapePageTransform(o.parentId));r.parentTransform=s})}}ym=Xce(e0);Jce(ym,1,"updateParentTransforms",k5,Sm);Zce(ym,Sm);Ds(Sm,"id","translating");function OE(t){var h;const e=[],n=[],r=t.getSelectedShapeIds(),o=ye(r.map(p=>{const f=t.getShape(p);if(!f)return null;e.push(f);const g=t.getShapePageTransform(p),m=g.point(),v=g.rotation();n.push(m);const S=gr.isId(f.parentId)?null:q.Inverse(t.getShapePageTransform(f.parentId));return{shape:f,pagePoint:m,pageRotation:v,parentTransform:S}})),s=t.getOnlySelectedShape();let i=[];if(s)i=t.snaps.shapeBounds.getSnapPoints(s.id);else{const p=t.getSelectionPageBounds();p&&(i=p.cornersAndCenter.map((f,g)=>({id:"selection:"+g,x:f.x,y:f.y})))}let a,l;const{originPagePoint:c}=t.inputs,u=o.filter(p=>t.isShapeOfType(p.shape,"note")&&t.isPointInShape(p.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const p=t.getCurrentPageShapesSorted();l=(h=u.map(f=>({snapshot:f,index:p.findIndex(g=>g.id===f.shape.id)})).sort((f,g)=>g.index-f.index)[0])==null?void 0:h.snapshot}return l&&(a=_$(t,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:x.Average(n),movingShapes:e,shapeSnapshots:o,initialPageBounds:t.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function eue({editor:t,snapshot:e}){const{inputs:n}=t,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=e,c=t.getInstanceState().isGridMode,u=t.getDocumentSettings().gridSize,h=x.Sub(n.currentPagePoint,n.originPagePoint),p=t.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;if(p==="x"?h.x=0:p==="y"&&(h.y=0),t.snaps.clearIndicators(),(t.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey)&&t.inputs.pointerVelocity.len()<.5){const{nudge:v}=t.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:s,lockedAxis:p,initialSelectionSnapPoints:i});h.add(v)}else if(r&&o){const{scale:v}=r.shape.props,S=r.pagePoint.clone().add(h).add(dm.clone().mul(v).rot(r.pageRotation));let y=P$/t.getZoomLevel(),b=new x(0,0);for(const P of o){const C=x.Sub(S,P),I=C.len();I<y&&(y=I,b=C)}h.sub(b)}const g=x.Add(l,h);c&&!n.ctrlKey&&g.snapToGrid(u);const m=x.Sub(g,l);t.updateShapes(ye(a.map(({shape:v,pagePoint:S,parentTransform:y})=>{const b=x.Add(S,m),P=y?q.applyToPoint(y,b):b;return{id:v.id,type:v.type,x:P.x,y:P.y}})))}class Ip extends ie{constructor(){super(...arguments);E(this,"reactor")}static children(){return[Jx,gb,Oce,l5,h5,Sm,Q$,g5,mb,d5,J$,i5,p5,f5,u5,a5,c5,o5]}cleanUpDuplicateProps(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const o=new Set(r.duplicateProps.shapeIds);n.length===o.size&&n.every(s=>o.has(s))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=ii("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){typeof process<"u",console.error(n)}})}onExit(){var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}E(Ip,"id","select"),E(Ip,"initial","idle"),E(Ip,"isLockable",!1);class T5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n}onPointerDown(){this.parent.transition("pointing",this.info)}}E(T5,"id","idle");class M5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n}onPointerUp(){this.complete()}onPointerMove(){this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{animation:{duration:220}}):this.editor.zoomIn(n,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}E(M5,"id","pointing");class A5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"zoomBrush",new Z)}onEnter(n){this.info=n,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Z.FromPoints([n,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:n}=this,r=8/this.editor.getZoomLevel();if(n.width<r&&n.height<r){const o=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(o,{animation:{duration:220}}):this.editor.zoomIn(o,{animation:{duration:220}})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:o,animation:{duration:220}})}this.parent.transition("idle",this.info)}}E(A5,"id","zoom_brushing");class Ep extends ie{constructor(){super(...arguments);E(this,"info",{})}static children(){return[T5,A5,M5]}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)}onKeyDown(){this.updateCursor()}onKeyUp(n){this.updateCursor(),n.code==="KeyZ"&&this.complete()}onInterrupt(){this.complete()}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}E(Ep,"id","zoom"),E(Ep,"initial","idle"),E(Ep,"isLockable",!1);const tue=[Pp,Cp,_p,Ep,Ip],nue=({id:t,component:e,onClose:n})=>{const{removeDialog:r}=ya(),o=Lt(),s=w.useCallback(i=>{if(!i){if(n)try{n()}catch(a){console.warn(a)}r(t)}},[t,n,r]);return d.jsx(Cne,{onOpenChange:s,defaultOpen:!0,children:d.jsx(_ne,{container:o,children:d.jsx(Ine,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:d.jsx(Ene,{dir:"ltr",className:"tlui-dialog__content",children:d.jsx(e,{onClose:()=>s(!1)})})})})})};function rue(){const{dialogs:t}=ya();return t.map(e=>d.jsx(nue,{...e},e.id))}const oue=Ie.memo(rue);function sue(){const t=F(),e=U("follow",()=>t.getInstanceState().followingUserId,[t]);return e?d.jsx(iue,{userId:e}):null}function iue({userId:t}){const e=Ig(t);return e?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}const aue={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function lue({toast:t}){const{removeToast:e}=ao(),n=Ce(),r=i=>{i||e(t.id)},o=t.actions&&t.actions.length>0,s=t.icon||t.severity&&aue[t.severity];return d.jsxs(Kre,{onOpenChange:r,className:"tlui-toast__container",duration:t.keepOpen?1/0:5e3,"data-severity":t.severity,children:[s&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(Mo,{icon:s})}),d.jsxs("div",{className:"tlui-toast__main",children:[d.jsxs("div",{className:"tlui-toast__content",children:[t.title&&d.jsx(Wre,{className:"tlui-toast__title",children:t.title}),t.description&&d.jsx(Gre,{className:"tlui-toast__description",children:t.description})]}),t.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[t.actions.map((i,a)=>d.jsx(Vre,{altText:i.label,asChild:!0,onClick:i.onClick,children:d.jsx(ue,{type:i.type,children:d.jsx(wt,{children:i.label})})},a)),d.jsx(zI,{asChild:!0,children:d.jsx(ue,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:d.jsx(wt,{children:t.closeLabel??n("toast.close")})})})]})]}),!o&&d.jsx(zI,{asChild:!0,children:d.jsx(ue,{type:"normal",className:"tlui-toast__close",children:d.jsx(wt,{children:t.closeLabel??n("toast.close")})})})]})}function cue(){const{toasts:t}=ao();return t.map(e=>d.jsx(lue,{toast:e},e.id))}const uue=w.memo(cue);function due(){const t=F(),{toasts:e}=ao(),[n,r]=w.useState(!1);return w.useEffect(()=>{let o=-1;return e.length?r(!0):o=t.timers.setTimeout(()=>{r(!1)},1e3),()=>{clearTimeout(o)}},[e.length,r,t]),n?d.jsx(p3,{className:"tlui-toast__viewport"}):null}let t0={fonts:{draw:`${Gs()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${Gs()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${Gs()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${Gs()}/fonts/IBMPlexMono-Medium.woff2`}};function j5(t){return w.useMemo(()=>t?{fonts:{...t0.fonts,...t==null?void 0:t.fonts}}:t0,[t])}const hue=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bring-forward","bring-to-front","broken","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","color","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","leading","link","lock","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","stretch-horizontal","stretch-vertical","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];let Ic={...t0,icons:Object.fromEntries(hue.map(t=>[t,`${Gs()}/icons/icon/0_merged.svg#${t}`])),translations:Object.fromEntries(Au.map(t=>[t.locale,`${Gs()}/translations/${t.locale}.json`])),embedIcons:Object.fromEntries(k1.map(t=>[t.type,`${Gs()}/embed-icons/${t.type}.png`]))};function pue(t){return t?{fonts:Object.assign({...Ic.fonts},{...t==null?void 0:t.fonts}),icons:Object.assign({...Ic.icons},{...t==null?void 0:t.icons}),embedIcons:Object.assign({...Ic.embedIcons},{...t==null?void 0:t.embedIcons}),translations:Object.assign({...Ic.translations},{...t==null?void 0:t.translations})}:Ic}function fue(){const{addToast:t,removeToast:e,clearToasts:n}=ao(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=ya(),l=kn()<Pt.TABLET_SM,c=Ce();return w.useMemo(()=>({addToast:t,removeToast:e,clearToasts:n,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:c,isMobile:l}),[r,t,o,n,c,s,e,i,l])}function gue(t,e){const n={};for(const r of t)if(r.translations)for(const[o,s]of Gn(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return{actions:(r,o)=>{for(const s of t)s.actions&&(o=s.actions(r,o,e));return o},tools:(r,o,s)=>{for(const i of t)i.tools&&(o=i.tools(r,o,{...e,...s}));return o},translations:n}}function O5(t){return w.useMemo(()=>t,t)}function mue(t){const e=O5(t==null?[]:Array.isArray(t)?t:[t]);return w.useMemo(()=>{const n={};for(const r of e)if(r.translations)for(const[o,s]of Gn(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return n},[e])}function yue(t){const e=fue(),n=O5(t==null?[]:Array.isArray(t)?t:[t]);return w.useMemo(()=>gue(n,e),[n,e])}var Sb="Popover",[D5,Vfe]=Lo(Sb,[rm]),Sd=rm(),[Sue,_i]=D5(Sb),R5=t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=t,a=Sd(e),l=w.useRef(null),[c,u]=w.useState(!1),[h=!1,p]=Pi({prop:r,defaultProp:o,onChange:s});return d.jsx(K1,{...a,children:d.jsx(Sue,{scope:e,contentId:as(),triggerRef:l,open:h,onOpenChange:p,onOpenToggle:w.useCallback(()=>p(f=>!f),[p]),hasCustomAnchor:c,onCustomAnchorAdd:w.useCallback(()=>u(!0),[]),onCustomAnchorRemove:w.useCallback(()=>u(!1),[]),modal:i,children:n})})};R5.displayName=Sb;var L5="PopoverAnchor",vue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=_i(L5,n),s=Sd(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=o;return w.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(W1,{...s,...r,ref:e})});vue.displayName=L5;var $5="PopoverTrigger",F5=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=_i($5,n),s=Sd(n),i=Ze(e,o.triggerRef),a=d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":H5(o.open),...r,ref:i,onClick:oe(t.onClick,o.onOpenToggle)});return o.hasCustomAnchor?a:d.jsx(W1,{asChild:!0,...s,children:a})});F5.displayName=$5;var vb="PopoverPortal",[xue,wue]=D5(vb,{forceMount:void 0}),N5=t=>{const{__scopePopover:e,forceMount:n,children:r,container:o}=t,s=_i(vb,e);return d.jsx(xue,{scope:e,forceMount:n,children:d.jsx(so,{present:n||s.open,children:d.jsx(pd,{asChild:!0,container:o,children:r})})})};N5.displayName=vb;var jl="PopoverContent",z5=w.forwardRef((t,e)=>{const n=wue(jl,t.__scopePopover),{forceMount:r=n.forceMount,...o}=t,s=_i(jl,t.__scopePopover);return d.jsx(so,{present:r||s.open,children:s.modal?d.jsx(bue,{...o,ref:e}):d.jsx(Pue,{...o,ref:e})})});z5.displayName=jl;var bue=w.forwardRef((t,e)=>{const n=_i(jl,t.__scopePopover),r=w.useRef(null),o=Ze(e,r),s=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return b1(i)},[]),d.jsx(Wg,{as:oa,allowPinchZoom:!0,children:d.jsx(B5,{...t,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:oe(t.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:oe(t.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:oe(t.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),Pue=w.forwardRef((t,e)=>{const n=_i(jl,t.__scopePopover),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(B5,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=t.onCloseAutoFocus)==null||i.call(t,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=t.onInteractOutside)==null||l.call(t,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),B5=w.forwardRef((t,e)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=t,p=_i(jl,n),f=Sd(n);return w1(),d.jsx(Hg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(hd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:d.jsx(V3,{"data-state":H5(p.open),role:"dialog",id:p.contentId,...f,...h,ref:e,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),U5="PopoverClose",Cue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=_i(U5,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});Cue.displayName=U5;var _ue="PopoverArrow",Iue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Sd(n);return d.jsx(Y3,{...o,...r,ref:e})});Iue.displayName=_ue;function H5(t){return t?"open":"closed"}var xb=R5,wb=F5,bb=N5,Pb=z5;function Cb({id:t,children:e,onOpenChange:n,open:r}){const[o,s]=Ps(t,n);return d.jsx(xb,{onOpenChange:s,open:r||o,children:d.jsx("div",{className:"tlui-popover",children:e})})}function _b({children:t}){return d.jsx(wb,{asChild:!0,dir:"ltr",children:t})}function Ib({side:t,children:e,align:n="center",sideOffset:r=8,alignOffset:o=0,disableEscapeKeyDown:s=!1}){const i=Lt();return d.jsx(bb,{container:i,children:d.jsx(Pb,{className:"tlui-popover__content",side:t,sideOffset:r,align:n,alignOffset:o,dir:"ltr",onEscapeKeyDown:a=>s&&a.preventDefault(),children:e})})}function Eue(t){return t.getSelectedShapeIds().map(r=>t.getShape(r)).filter(r=>{if(!r)return!1;if(t.isShapeOfType(r,"arrow")){const o=Fn(t,r);if(o.start||o.end)return!1}return!0})}const K5=()=>{const t=F();return U("threeStackableItems",()=>Eue(t).length>2,[t])},Cs=()=>{const t=F();return U("isInSelectState",()=>t.isIn("select"),[t])},W5=()=>{const t=F();return U("allow group",()=>{const e=t.getSelectedShapes();if(e.length<2)return!1;for(const n of e)if(t.isShapeOfType(n,"arrow")){const r=Fn(t,n);if(r.start&&!e.some(o=>o.id===r.start.toId)||r.end&&!e.some(o=>o.id===r.end.toId))return!1}return!0},[t])},G5=()=>{const t=F();return U("allowUngroup",()=>t.getSelectedShapeIds().some(e=>{var n;return((n=t.getShape(e))==null?void 0:n.type)==="group"}),[t])},kue=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function V5(t,e){const n=F();return U("selectedShapes",()=>n.getSelectedShapes().length>=t,[n,t,e])}function Tn(t,e){const n=F();return U("selectedShapes",()=>{const r=n.getSelectedShapes().filter(o=>!n.isShapeOrAncestorLocked(o)).length;return t===void 0?r:r>=t},[n])}function Tue(){const t=F();return U("showAutoSizeToggle",()=>{const e=t.getSelectedShapes();return e.length===1&&t.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[t])}function Y5(){const t=F();return U("hasLinkShapeSelected",()=>{const e=t.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[t])}function Mue(){const t=F();return U("onlyFlippableShape",()=>{const e=t.getOnlySelectedShape();return e&&(t.isShapeOfType(e,"group")||t.isShapeOfType(e,"image")||t.isShapeOfType(e,"arrow")||t.isShapeOfType(e,"line")||t.isShapeOfType(e,"draw"))},[t])}function X5(){const t=F();return U("useCanRedo",()=>t.getCanRedo(),[t])}function q5(){const t=F();return U("useCanUndo",()=>t.getCanUndo(),[t])}function Aue(){return d.jsxs(d.Fragment,{children:[d.jsx(jue,{}),d.jsx(Oue,{}),d.jsx(Due,{}),d.jsx(Rue,{}),d.jsx(Lue,{}),d.jsx(Nue,{}),d.jsx(zue,{}),d.jsx(Bue,{})]})}function jue(){const t=Tn(2),e=Cs(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"align-left",disabled:!n}),d.jsx(W,{actionId:"align-center-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-right",disabled:!n}),d.jsx(W,{actionId:"stretch-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-top",disabled:!n}),d.jsx(W,{actionId:"align-center-vertical",disabled:!n}),d.jsx(W,{actionId:"align-bottom",disabled:!n}),d.jsx(W,{actionId:"stretch-vertical",disabled:!n})]})}function Oue(){const t=Tn(3),e=Cs(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"distribute-horizontal",disabled:!n}),d.jsx(W,{actionId:"distribute-vertical",disabled:!n})]})}function Due(){const t=K5(),e=Cs(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"stack-horizontal",disabled:!n}),d.jsx(W,{actionId:"stack-vertical",disabled:!n})]})}function Rue(){const t=Tn(1),e=Cs(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"send-to-back",disabled:!n}),d.jsx(W,{actionId:"send-backward",disabled:!n}),d.jsx(W,{actionId:"bring-forward",disabled:!n}),d.jsx(W,{actionId:"bring-to-front",disabled:!n})]})}function Lue(){return kn()<Pt.TABLET_SM?d.jsx($ue,{}):d.jsx(Fue,{})}function $ue(){const t=F(),e=U("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",disabled:e})}function Fue(){const t=Tn(1),e=Cs(),n=t&&e;return d.jsx(W,{actionId:"rotate-ccw",disabled:!n})}function Nue(){const t=Tn(1),e=Cs(),n=t&&e;return d.jsx(W,{actionId:"rotate-cw",disabled:!n})}function zue(){const t=Y5(),e=Cs(),n=t&&e;return d.jsx(W,{actionId:"edit-link",disabled:!n})}function Bue(){const t=W5(),e=G5();return t?d.jsx(DE,{}):e?d.jsx(Uue,{}):d.jsx(DE,{})}function DE(){const t=Tn(2),e=Cs(),n=t&&e;return d.jsx(W,{actionId:"group",disabled:!n})}function Uue(){return d.jsx(W,{actionId:"ungroup"})}const Hue=w.memo(function({children:e}){const n=Ce(),r=kn(),o=bs(),s=F(),i=U("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=e??d.jsx(Aue,{});if(!(o&&!i))return d.jsxs(Cb,{id:"actions-menu",children:[d.jsx(_b,{children:d.jsx(ue,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(Ib,{side:r>=Pt.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(Dr,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function ve({id:t,label:e,children:n}){const{type:r,sourceId:o}=lm(),s=Ce(),i=Ru(e,r),a=i?s(i):void 0;switch(r){case"panel":return d.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${t}`,children:n});case"menu":return d.jsx(tae,{"data-testid":`${o}-group.${t}`,children:n});case"context-menu":return d.jsx(VL,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${t}`,children:n});case"keyboard-shortcuts":return d.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${t}`,children:[d.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),d.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:n})]});default:return n}}function qn({id:t,disabled:e=!1,label:n,size:r="small",children:o}){const{type:s,sourceId:i}=lm(),a=Lt(),l=Ce(),c=n?typeof n=="string"?n:n[s]??n.default:void 0,u=c?l(c):void 0;switch(s){case"menu":return d.jsxs(Qie,{id:`${i}-sub.${t}`,children:[d.jsx(Jie,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:e,label:u,title:u}),d.jsx(eae,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return e?null:d.jsxs(Kue,{id:`${i}-sub.${t}`,children:[d.jsx(ZL,{dir:"ltr",disabled:e,asChild:!0,children:d.jsxs(ue,{"data-testid":`${i}-sub-trigger.${t}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[d.jsx(wt,{children:u}),d.jsx(be,{icon:"chevron-right",small:!0})]})}),d.jsx(tb,{container:a,children:d.jsx(QL,{"data-testid":`${i}-sub-content.${t}`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:o})})]});default:return o}}function Kue({id:t,children:e}){const[n,r]=Ps(t);return d.jsx(qL,{open:n,onOpenChange:r,children:e})}function Z5(){return Tue()?d.jsx(W,{actionId:"toggle-auto-size"}):null}function Q5(){return Y5()?d.jsx(W,{actionId:"edit-link"}):null}function Wue(){return Tn(1)?d.jsx(W,{actionId:"duplicate"}):null}function J5(){const t=F();return U("should display flatten option",()=>{if(t.getSelectedShapeIds().length===0)return!1;const r=t.getOnlySelectedShape();return!(r&&t.isShapeOfType(r,"image"))},[t])?d.jsx(W,{actionId:"flatten-to-image"}):null}function eF(){return W5()?d.jsx(W,{actionId:"group"}):null}function tF(){return G5()?d.jsx(W,{actionId:"ungroup"}):null}function nF(){const t=F();return U("allow unframe",()=>{const n=t.getSelectedShapes();return n.length===0?!1:n.every(r=>t.isShapeOfType(r,"frame"))},[t])?d.jsx(W,{actionId:"remove-frame"}):null}function rF(){const t=F();return U("allow fit frame to content",()=>{const n=t.getOnlySelectedShape();return n?t.isShapeOfType(n,"frame")&&t.getSortedChildIdsForParent(n).length>0:!1},[t])?d.jsx(W,{actionId:"fit-frame-to-content"}):null}function oF(){const t=F();return U("selected shapes",()=>t.getSelectedShapes().length>0,[t])?d.jsx(W,{actionId:"toggle-lock"}):null}function Eb(){const t=F(),e=U("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(lo,{actionId:"toggle-transparent",checked:e,toggle:!0})}function Gue(){const t=F(),e=U("any shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"unlock-all",disabled:!e})}function sF(){const t=F(),e=U("zoomed to 100",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function iF(){const t=F(),e=U("has shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function aF(){const t=F(),e=U("has shapes",()=>t.getSelectedShapeIds().length>0,[t]);return d.jsx(W,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function lF(){return d.jsxs(ve,{id:"clipboard",children:[d.jsx(Yue,{}),d.jsx(Xue,{}),d.jsx(que,{}),d.jsx(Wue,{}),d.jsx(Zue,{})]})}function Vue(){var n;const t=F(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsxs(qn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[d.jsxs(ve,{id:"copy-as-group",children:[d.jsx(W,{actionId:"copy-as-svg"}),!!((n=window.navigator.clipboard)!=null&&n.write)&&d.jsx(W,{actionId:"copy-as-png"}),d.jsx(W,{actionId:"copy-as-json"})]}),d.jsx(ve,{id:"copy-as-bg",children:d.jsx(Eb,{})})]})}function Yue(){const t=Tn(1);return d.jsx(W,{actionId:"cut",disabled:!t})}function Xue(){const t=V5(1);return d.jsx(W,{actionId:"copy",disabled:!t})}function que(){const t=kue;return d.jsx(W,{actionId:"paste",disabled:!t})}function cF(){const t=F();return U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t])?d.jsxs(ve,{id:"conversions",children:[d.jsx(Vue,{}),d.jsxs(qn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[d.jsxs(ve,{id:"export-as-group",children:[d.jsx(W,{actionId:"export-as-svg"}),d.jsx(W,{actionId:"export-as-png"}),d.jsx(W,{actionId:"export-as-json"})]}),d.jsx(ve,{id:"export-as-bg",children:d.jsx(Eb,{})})]})]}):null}function uF(){const t=F(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"select-all",disabled:!e})}function Zue(){const t=Tn(1);return d.jsx(W,{actionId:"delete",disabled:!t})}function Que(){return V5(1)?d.jsxs(qn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(eF,{}),d.jsx(tF,{}),d.jsx(J5,{}),d.jsx(Q5,{}),d.jsx(rF,{}),d.jsx(nF,{}),d.jsx(hF,{}),d.jsx(dF,{}),d.jsx(Z5,{}),d.jsx(oF,{})]}):null}function Jue(){const t=Tn(2),e=Mue();return t||e?d.jsxs(qn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[t&&d.jsxs(ve,{id:"align",children:[d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"})]}),d.jsx(ede,{}),t&&d.jsxs(ve,{id:"stretch",children:[d.jsx(W,{actionId:"stretch-horizontal"}),d.jsx(W,{actionId:"stretch-vertical"})]}),(t||e)&&d.jsxs(ve,{id:"flip",children:[d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"})]}),d.jsx(tde,{})]}):null}function ede(){return Tn(3)?d.jsxs(ve,{id:"distribute",children:[d.jsx(W,{actionId:"distribute-horizontal"}),d.jsx(W,{actionId:"distribute-vertical"})]}):null}function tde(){const t=Tn(2),e=K5();return t?d.jsxs(ve,{id:"order",children:[d.jsx(W,{actionId:"pack"}),e&&d.jsx(W,{actionId:"stack-horizontal"}),e&&d.jsx(W,{actionId:"stack-vertical"})]}):null}function nde(){return Tn(1)?d.jsx(qn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(ve,{id:"reorder",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"})]})}):null}function rde(){const t=F(),e=U("pages",()=>t.getPages(),[t]),n=U("current page id",()=>t.getCurrentPageId(),[t]),{addToast:r}=ao(),o=Zt();return Tn(1)?d.jsxs(qn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ve,{id:"pages",children:e.map(i=>d.jsx(Ht,{id:i.id,disabled:n===i.id,label:i.name,onSelect:()=>{t.markHistoryStoppingPoint("move_shapes_to_page"),t.moveShapesToPage(t.getSelectedShapeIds(),i.id);const a=t.getPage(i.id);a&&r({title:"Changed Page",description:`Moved to ${a.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{t.markHistoryStoppingPoint("change-page"),t.setCurrentPage(n)}}]}),o("move-to-page",{source:"context-menu"})}},i.id))}),d.jsx(ve,{id:"new-page",children:d.jsx(W,{actionId:"move-to-new-page"})})]}):null}function dF(){const t=F();return U("oneEmbedSelected",()=>{const n=t.getOnlySelectedShape();return n?!!(t.isShapeOfType(n,"embed")&&n.props.url&&!t.isShapeOrAncestorLocked(n)):!1},[t])?d.jsx(W,{actionId:"convert-to-bookmark"}):null}function hF(){const t=F(),e=T1();return U("oneEmbeddableBookmarkSelected",()=>{const r=t.getOnlySelectedShape();return r?!!(t.isShapeOfType(r,"bookmark")&&r.props.url&&e(r.props.url)&&!t.isShapeOrAncestorLocked(r)):!1},[t])?d.jsx(W,{actionId:"convert-to-embed"}):null}function ode(){const t=F(),e=U("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(lo,{actionId:"toggle-snap-mode",checked:e})}function sde(){const t=F(),e=U("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(lo,{actionId:"toggle-tool-lock",checked:e})}function ide(){const t=F(),e=U("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(lo,{actionId:"toggle-grid",checked:e})}function ade(){const t=F(),e=U("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(lo,{actionId:"toggle-wrap-mode",checked:e})}function lde(){const t=F(),e=U("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(lo,{actionId:"toggle-focus-mode",checked:e})}function cde(){const t=F(),e=U("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(lo,{actionId:"toggle-edge-scrolling",checked:e===1})}function ude(){const t=F(),e=U("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(lo,{actionId:"toggle-reduce-motion",checked:e===0})}function dde(){const t=F(),e=U("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(lo,{actionId:"toggle-debug-mode",checked:e})}function hde(){const t=F(),e=U("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(lo,{actionId:"toggle-dynamic-size-mode",checked:e})}function pde(){const t=F(),e=U("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(lo,{actionId:"toggle-paste-at-cursor",checked:e})}function fde(){const t=F();return U("show cursor chat",()=>t.getCurrentToolId()==="select"&&!t.getInstanceState().isCoarsePointer,[t])?d.jsx(W,{actionId:"open-cursor-chat"}):null}function gde(){const t=F(),e=Jg(),n=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]),r=U("isSinglePageMode",()=>t.options.maxPages<=1,[t]);return n?d.jsxs(d.Fragment,{children:[e&&d.jsx(fde,{}),d.jsxs(ve,{id:"modify",children:[d.jsx(Que,{}),d.jsx(Jue,{}),d.jsx(nde,{}),!r&&d.jsx(rde,{})]}),d.jsx(lF,{}),d.jsx(cF,{}),d.jsx(ve,{id:"select-all",children:d.jsx(uF,{})})]}):null}const mde=w.memo(function({children:e,disabled:n=!1}){const r=F(),{Canvas:o}=rt(),s=w.useCallback(u=>{if(u){if(r.getInstanceState().isCoarsePointer){const h=r.getSelectedShapes(),{inputs:{currentPagePoint:p}}=r,f=r.getShapesAtPoint(p);if(!r.getSelectedShapes().length||!f.some(g=>h.includes(g))){const g=f.filter(m=>r.isShapeOrAncestorLocked(m));g.length&&r.select(...g.map(m=>m.id))}}}else{const h=r.getOnlySelectedShape();h&&r.isShapeOrAncestorLocked(h)&&r.setSelectedShapes([])}},[r]),i=Lt(),[a,l]=Ps("context menu",s),c=e??d.jsx(gde,{});return d.jsxs(mie,{dir:"ltr",onOpenChange:l,modal:!1,children:[d.jsx(yie,{onContextMenu:void 0,dir:"ltr",disabled:n,children:o?d.jsx(o,{}):null}),a&&d.jsx(Sie,{container:i,children:d.jsx(vie,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:we,children:d.jsx(Dr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),yde=2e3,Sde=5e3,vde=Rt(function(){const e=F(),{isChatting:n,chatMessage:r}=e.getInstanceState(),o=w.useRef(-1),[s,i]=w.useState("");return w.useEffect(()=>{if(!n&&r||n){const l=n?Sde:yde;o.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},l)}return()=>{clearTimeout(o.current)}},[e,r,n]),n?d.jsx(wde,{value:s,setValue:i,chatMessage:r}):r.trim()?d.jsx(xde,{chatMessage:r}):null});function pF(t){const e=F();w.useLayoutEffect(()=>{var i;if(!t.current)return;const{x:r,y:o}=e.inputs.currentScreenPoint;(i=t.current)==null||i.style.setProperty("transform",`translate(${r}px, ${o}px)`);function s(a){var u;const{minX:l,minY:c}=e.getViewportScreenBounds();(u=t.current)==null||u.style.setProperty("transform",`translate(${a.clientX-l}px, ${a.clientY-c}px)`)}return window.addEventListener("pointermove",s),()=>{window.removeEventListener("pointermove",s)}},[t,e])}const xde=({chatMessage:t})=>{const e=F(),n=w.useRef(null);return pF(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:t})},wde=Rt(function({chatMessage:e,value:n,setValue:r}){const o=F(),s=Ce(),i=w.useRef(null),a=e||s("cursor-chat.type-to-chat");pF(i),w.useLayoutEffect(()=>{const p=i.current;if(!p)return;const f=o.textMeasure.measureText(n||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});p.style.setProperty("width",f.w+"px")},[o,n,a]),w.useLayoutEffect(()=>{const p=o.timers.requestAnimationFrame(()=>{var f;(f=i.current)==null||f.focus()});return()=>{cancelAnimationFrame(p)}},[o]);const l=w.useCallback(()=>{o.updateInstanceState({isChatting:!1}),o.focus()},[o]),c=w.useCallback(p=>{const{value:f}=p.target;r(f.slice(0,64)),o.updateInstanceState({chatMessage:f})},[o,r]),u=w.useCallback(p=>{const f=i.current;if(!f)return;const{value:g}=f;switch(p.key){case"Enter":{if(we(p),p.stopPropagation(),!g){l();return}r("");break}case"Escape":{we(p),p.stopPropagation(),l();break}}},[l,r]),h=w.useCallback(p=>{p.stopPropagation()},[]);return d.jsx("input",{ref:i,className:"tl-cursor-chat",style:{backgroundColor:o.user.getColor()},onBlur:l,onChange:c,onKeyDown:u,onPaste:h,value:n,placeholder:a,spellCheck:!1})});function n0({checked:t}){return d.jsx(Mo,{icon:t?"check":"none",className:"tlui-button__icon",small:!0})}function bde(){const t=F(),{addToast:e}=ao(),{addDialog:n}=ya(),[r,o]=Ie.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"items",children:[d.jsx(Ht,{id:"add-toast",onSelect:()=>{e({id:Ke(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:Ke(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"info",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),e({id:Ke(),title:"Something maybe bad happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"warning",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),e({id:Ke(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),d.jsx(Ht,{id:"show-dialog",label:"Show dialog",onSelect:()=>{n({component:({onClose:s})=>d.jsx(_de,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),d.jsx(Ht,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>Ide(t,100)}),d.jsx(Ht,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const s=t.getSelectedShapes(),i=s.length===0?t.getRenderingShapes():s;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),d.jsx(Ht,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),d.jsx(Ht,{id:"hard-reset",onSelect:QA,label:"Hard reset"})]}),d.jsxs(ve,{id:"flags",children:[d.jsx(Pde,{}),d.jsx(Cde,{})]})]})}function Pde(){const t=Object.values(xt);return t.length?d.jsx(qn,{id:"debug flags",label:"Debug Flags",children:d.jsx(ve,{id:"debug flags",children:t.map(e=>d.jsx(fF,{flag:e},e.name))})}):null}function Cde(){const t=Object.values(DY);return t.length?d.jsx(qn,{id:"feature flags",label:"Feature Flags",children:d.jsx(ve,{id:"feature flags",children:t.map(e=>d.jsx(fF,{flag:e},e.name))})}):null}function _de({title:t="title",body:e="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=Ie.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(Gg,{children:[d.jsx(Vg,{children:t}),d.jsx(Yg,{})]}),d.jsx(Du,{style:{maxWidth:350},children:e}),d.jsxs(E1,{className:"tlui-dialog__footer__actions",children:[o&&d.jsxs(ue,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(n0,{checked:a}),d.jsx(wt,{children:"Don’t show again"})]}),d.jsx(ue,{type:"normal",onClick:s,children:d.jsx(wt,{children:n})}),d.jsx(ue,{type:"primary",onClick:async()=>i(),children:d.jsx(wt,{children:r})})]})]})}const fF=Rt(function({flag:e,onChange:n}){const r=e.get();return d.jsx(cm,{id:e.name,title:e.name,label:e.name.replace(/([a-z0-9])([A-Z])/g,o=>`${o[0]} ${o[1].toLowerCase()}`).replace(/^[a-z]/,o=>o.toUpperCase()),checked:r,onSelect:()=>{e.set(!r),n==null||n(!r)}})});let RE=0;function Ide(t,e){const n=Array(e),r=Math.floor(Math.sqrt(e));for(let o=0;o<e;o++)RE++,n[o]={id:Ne("box"+RE),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};t.run(()=>{t.createShapes(n).setSelectedShapes(n.map(o=>o.id))})}function Ede({children:t}){const e=t??d.jsx(bde,{});return d.jsxs(aa,{id:"debug",children:[d.jsx(la,{children:d.jsx(ue,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(ca,{side:"top",align:"end",alignOffset:0,children:d.jsx(Dr,{type:"menu",sourceId:"debug-panel",children:e})})]})}const kde=w.memo(function(){const{DebugMenu:e}=Ii();return d.jsxs("div",{className:"tlui-debug-panel",children:[d.jsx(Mde,{}),d.jsx(Ade,{}),e&&d.jsx(e,{})]})});function Tde(t=!0){const[e,n]=w.useState(0),r=F();w.useEffect(()=>{if(!t)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,t])}const Mde=Rt(function(){Tde();const e=F(),n=e.getPath(),r=e.getHoveredShape(),o=e.getOnlySelectedShape(),s=n==="select.idle"||!n.includes("select.")?r:o,i=s&&n.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${x.ToInt(e.getPointInShapeSpace(s,e.inputs.currentPagePoint))}]`:"",a=n.startsWith("select.")&&!n.includes(".idle")?` / [${x.ToInt(e.inputs.originPagePoint)}] → [${x.ToInt(e.inputs.currentPagePoint)}] = ${x.Dist(e.inputs.originPagePoint,e.inputs.currentPagePoint).toFixed(0)}`:"";return d.jsx("div",{className:"tlui-debug-panel__current-state",children:`${n}${i}${a}`})});function Ade(){const t=F(),e=U("show_fps",()=>xt.showFps.get(),[xt]),n=w.useRef(null);return w.useEffect(()=>{if(!e)return;const r=250;let o=0,s=-1,i=performance.now(),a=0,l=0,c=!1;function u(){if(l++,a=performance.now()-i,a>r){const h=Math.round(l*(r/a)*(1e3/r));h>o&&(o=h);const p=o*.75;(h<p&&!c||h>=p&&c)&&(c=!c),n.current.innerHTML=`FPS ${h.toString()}`,n.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,i=performance.now()}s=t.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(s)}},[e,t]),e?d.jsx("div",{ref:n}):null}const jde=w.memo(function(){const e=kn(),{MainMenu:n,QuickActions:r,ActionsMenu:o,PageMenu:s}=Ii(),i=F(),a=U("isSinglePageMode",()=>i.options.maxPages<=1,[i]);return!n&&!s&&e<6?null:d.jsx("div",{className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[n&&d.jsx(n,{}),s&&!a&&d.jsx(s,{}),e<6?null:d.jsxs(d.Fragment,{children:[r&&d.jsx(r,{}),o&&d.jsx(o,{})]})]})})});function Ode(){const t=F(),e=Sa(),[n,r]=w.useState(!1),o=w.useRef(!1);return ss("toggle showback to content",()=>{const s=o.current,i=t.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===t.getCulledShapes().size),s!==a&&(r(a),o.current=a)},[t]),n?d.jsx(W,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Dde(){const t=F();return U("is pen mode",()=>t.getInstanceState().isPenMode,[t])?d.jsx(W,{actionId:"exit-pen-mode"}):null}function Rde(){const t=F(),e=Sa();return U("is following user",()=>!!t.getInstanceState().followingUserId,[t])?d.jsx(Ht,{...e["stop-following"]}):null}function Lde(){return d.jsxs(d.Fragment,{children:[d.jsx(Dde,{}),d.jsx(Ode,{}),d.jsx(Rde,{})]})}function $de({children:t}){const e=t??d.jsx(Lde,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(Dr,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function Fde(){const t=Jg();return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(W,{actionId:"toggle-tool-lock"}),d.jsx(W,{actionId:"insert-media"}),d.jsx(On,{toolId:"select"}),d.jsx(On,{toolId:"draw"}),d.jsx(On,{toolId:"eraser"}),d.jsx(On,{toolId:"hand"}),d.jsx(On,{toolId:"rectangle"}),d.jsx(On,{toolId:"ellipse"}),d.jsx(On,{toolId:"arrow"}),d.jsx(On,{toolId:"line"}),d.jsx(On,{toolId:"text"}),d.jsx(On,{toolId:"frame"}),d.jsx(On,{toolId:"note"}),d.jsx(On,{toolId:"laser"}),d.jsx(Ht,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),d.jsxs(ve,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(W,{actionId:"toggle-dark-mode"}),d.jsx(W,{actionId:"toggle-focus-mode"}),d.jsx(W,{actionId:"toggle-grid"})]}),d.jsxs(ve,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(W,{actionId:"undo"}),d.jsx(W,{actionId:"redo"}),d.jsx(W,{actionId:"cut"}),d.jsx(W,{actionId:"copy"}),d.jsx(W,{actionId:"paste"}),d.jsx(W,{actionId:"select-all"}),d.jsx(W,{actionId:"delete"}),d.jsx(W,{actionId:"duplicate"})]}),d.jsxs(ve,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx(W,{actionId:"zoom-to-100"}),d.jsx(W,{actionId:"zoom-to-fit"}),d.jsx(W,{actionId:"zoom-to-selection"})]}),d.jsxs(ve,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"}),d.jsx(W,{actionId:"group"}),d.jsx(W,{actionId:"ungroup"}),d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"}),d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"})]}),t&&d.jsx(ve,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:d.jsx(W,{actionId:"open-cursor-chat"})})]})}const Nde=w.memo(function({children:e}){const n=Ce(),r=kn(),o=e??d.jsx(Fde,{});return d.jsxs(d.Fragment,{children:[d.jsxs(Gg,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(Vg,{children:n("shortcuts-dialog.title")}),d.jsx(Yg,{})]}),d.jsx(Du,{className:le("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=Pt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=Pt.TABLET}),children:d.jsx(Dr,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})}),zde=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Bde(){const t=F(),e=Zt(),n=U("colorScheme",()=>t.user.getUserPreferences().colorScheme??(t.user.getIsDarkMode()?"dark":"light"),[t]);return d.jsx(qn,{id:"help menu color-scheme",label:"menu.theme",children:d.jsx(ve,{id:"languages",children:zde.map(({colorScheme:r,label:o})=>d.jsx(cm,{id:`color-scheme-${r}`,label:o,checked:r===n,onSelect:()=>{t.user.updateUserPreferences({colorScheme:r}),e("color-scheme",{source:"menu",value:r})}},r))})})}function gF(){const t=F(),e=Zt(),n=U("locale",()=>t.user.getLocale(),[t]);return d.jsx(qn,{id:"help menu language",label:"menu.language",children:d.jsx(ve,{id:"languages",children:Au.map(({locale:r,label:o})=>d.jsx(cm,{id:`language-${r}`,title:r,label:o,checked:r===n,onSelect:()=>{t.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})})}function Ude(){return d.jsxs(d.Fragment,{children:[d.jsx(gF,{}),d.jsx(mF,{})]})}function mF(){const{KeyboardShortcutsDialog:t}=Ii(),{addDialog:e}=ya(),n=w.useCallback(()=>{t&&e({component:t})},[e,t]);return t?d.jsx(Ht,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:n}):null}function Hde(){return d.jsxs(d.Fragment,{children:[d.jsx(Wde,{}),d.jsx(Xde,{}),d.jsx(Kde,{}),d.jsx(qde,{}),d.jsx(Zde,{})]})}function Kde(){return d.jsxs(qn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[d.jsxs(ve,{id:"export-all-as-group",children:[d.jsx(W,{actionId:"export-all-as-svg"}),d.jsx(W,{actionId:"export-all-as-png"}),d.jsx(W,{actionId:"export-all-as-json"})]}),d.jsx(ve,{id:"export-all-as-bg",children:d.jsx(Eb,{})})]})}function Wde(){const t=F(),e=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]);return d.jsxs(qn,{id:"edit",label:"menu.edit",disabled:!e,children:[d.jsx(Yde,{}),d.jsx(lF,{}),d.jsx(cF,{}),d.jsx(Gde,{}),d.jsx(Vde,{}),d.jsx(ve,{id:"select-all",children:d.jsx(uF,{})})]})}function Gde(){return d.jsxs(ve,{id:"misc",children:[d.jsx(eF,{}),d.jsx(tF,{}),d.jsx(Q5,{}),d.jsx(Z5,{}),d.jsx(nF,{}),d.jsx(rF,{}),d.jsx(hF,{}),d.jsx(dF,{}),d.jsx(J5,{})]})}function Vde(){return d.jsxs(ve,{id:"lock",children:[d.jsx(oF,{}),d.jsx(Gue,{})]})}function Yde(){const t=q5(),e=X5();return d.jsxs(ve,{id:"undo-redo",children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}function Xde(){return d.jsx(qn,{id:"view",label:"menu.view",children:d.jsxs(ve,{id:"view-actions",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx(sF,{}),d.jsx(iF,{}),d.jsx(aF,{})]})})}function qde(){return d.jsxs(ve,{id:"extras",children:[d.jsx(W,{actionId:"insert-embed"}),d.jsx(W,{actionId:"insert-media"})]})}function Zde(){return d.jsxs(ve,{id:"preferences",children:[d.jsxs(qn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ve,{id:"preferences-actions",children:[d.jsx(ode,{}),d.jsx(sde,{}),d.jsx(ide,{}),d.jsx(ade,{}),d.jsx(lde,{}),d.jsx(cde,{}),d.jsx(ude,{}),d.jsx(hde,{}),d.jsx(pde,{}),d.jsx(dde,{})]}),d.jsx(ve,{id:"color-scheme",children:d.jsx(Bde,{})})]}),d.jsx(gF,{}),d.jsx(mF,{})]})}const Qde=w.memo(function({children:e}){const n=Lt(),[r,o]=Ps("main menu"),s=Ce(),i=e??d.jsx(Hde,{});return d.jsxs(rb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(ob,{asChild:!0,dir:"ltr",children:d.jsx(ue,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:d.jsx(be,{icon:"menu",small:!0})})}),d.jsx(am,{container:n,children:d.jsx(sb,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(Dr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),SS={};function Ec(t){if(SS[t])return SS[t];const n=document.createElement("canvas").getContext("2d");n.fillStyle=t,n.fillRect(0,0,1,1);const[r,o,s,i]=n.getImageData(0,0,1,1).data,a=new Float32Array([r/255,o/255,s/255,i/255]);return SS[t]=a,a}const kp=10,yF=4*6*kp+12+4*12;function Da(t,{center:e,radius:n,numArcSegments:r=20,startAngle:o=0,endAngle:s=Fe,offset:i=0}){const a=(s-o)/r;let l=i;for(let c=o;c<s;c+=a)t[l++]=e.x,t[l++]=e.y,t[l++]=e.x+Math.cos(c)*n,t[l++]=e.y+Math.sin(c)*n,t[l++]=e.x+Math.cos(c+a)*n,t[l++]=e.y+Math.sin(c+a)*n;return t}function Ra(t,e,n,r,o,s){t[e++]=n,t[e++]=r,t[e++]=n,t[e++]=r+s,t[e++]=n+o,t[e++]=r,t[e++]=n+o,t[e++]=r,t[e++]=n,t[e++]=r+s,t[e++]=n+o,t[e++]=r+s}function Jde(t,e,n){const r=kp;n=Math.min(n,Math.min(e.w,e.h)/2);const o=Z.ExpandBy(e,-n);if(o.w<=0||o.h<=0)return Da(t,{center:e.center,radius:n,numArcSegments:kp*4}),kp*4*6;let s=0;return Ra(t,s,o.minX,o.minY,o.w,o.h),s+=12,Ra(t,s,o.minX,e.minY,o.w,n),s+=12,Ra(t,s,o.maxX,o.minY,n,o.h),s+=12,Ra(t,s,o.minX,o.maxY,o.w,n),s+=12,Ra(t,s,e.minX,o.minY,n,o.h),s+=12,Da(t,{numArcSegments:r,offset:s,center:o.point,radius:n,startAngle:De,endAngle:De*1.5}),s+=r*6,Da(t,{numArcSegments:r,offset:s,center:x.Add(o.point,new x(o.w,0)),radius:n,startAngle:De*1.5,endAngle:Fe}),s+=r*6,Da(t,{numArcSegments:r,offset:s,center:x.Add(o.point,o.size),radius:n,startAngle:0,endAngle:qe}),s+=r*6,Da(t,{numArcSegments:r,offset:s,center:x.Add(o.point,new x(0,o.h)),radius:n,startAngle:qe,endAngle:De}),yF}function ehe(t){if(!t)throw new Error("Canvas element not found");const e=t.getContext("webgl2",{premultipliedAlpha:!1});if(!e)throw new Error("Failed to get webgl2 context");const n=`#version 300 es
390
- precision mediump float;
391
-
392
- in vec2 shapeVertexPosition;
393
-
394
- uniform vec4 canvasPageBounds;
395
-
396
- // taken (with thanks) from
397
- // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
398
- void main() {
399
- // convert the position from pixels to 0.0 to 1.0
400
- vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
401
-
402
- // convert from 0->1 to 0->2
403
- vec2 zeroToTwo = zeroToOne * 2.0;
404
-
405
- // convert from 0->2 to -1->+1 (clipspace)
406
- vec2 clipSpace = zeroToTwo - 1.0;
407
-
408
- gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
409
- }`,r=e.createShader(e.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const o=`#version 300 es
410
- precision mediump float;
411
-
412
- uniform vec4 fillColor;
413
- out vec4 outputColor;
414
-
415
- void main() {
416
- outputColor = fillColor;
417
- }`,s=e.createShader(e.FRAGMENT_SHADER);if(!s)throw new Error("Failed to create fragment shader");if(e.shaderSource(s,o),e.compileShader(s),!e.getShaderParameter(s,e.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=e.createProgram();if(!i)throw new Error("Failed to create program");if(e.attachShader(i,r),e.attachShader(i,s),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(i);const a=e.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(i,"canvasPageBounds"),c=e.getUniformLocation(i,"fillColor");if(!e.createBuffer())throw new Error("Failed to create buffer");if(!e.createBuffer())throw new Error("Failed to create buffer");return{context:e,selectedShapes:Mh(e,1024),unselectedShapes:Mh(e,4096),viewport:Mh(e,yF),collaborators:Mh(e,1024),prepareTriangles(p,f){e.bindBuffer(e.ARRAY_BUFFER,p.buffer),e.bufferData(e.ARRAY_BUFFER,p.vertices,e.STATIC_DRAW,0,f),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(p){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,p/2),e.disable(e.BLEND)},drawTriangles(p){e.drawArrays(e.TRIANGLES,0,p/2)},setFillColor(p){e.uniform4fv(c,p)},setCanvasPageBounds(p){e.uniform4fv(l,p)}}}function Mh(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(e)}}function LE(t,e,n){let r=t.vertices.length;for(;r<e+n.length;)r*=2;if(r!=t.vertices.length){const o=new Float32Array(r);o.set(t.vertices),t.vertices=o}t.vertices.set(n,e)}var the=Object.create,SF=Object.defineProperty,nhe=Object.getOwnPropertyDescriptor,rhe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),vF=t=>{throw TypeError(t)},xF=(t,e,n)=>e in t?SF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ohe=t=>[,,,the(null)],wF=["class","method","getter","setter","accessor","field","value","get","set"],bF=t=>t!==void 0&&typeof t!="function"?vF("Function expected"):t,she=(t,e,n,r,o)=>({kind:wF[t],name:e,metadata:r,addInitializer:s=>n._?vF("Already initialized"):o.push(bF(s||null))}),ihe=(t,e)=>xF(e,rhe("metadata"),t[3]),ahe=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},Fo=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=wF[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,nhe(o,n)),S=r.length-1;S>=0;S--)l=she(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,bF(i)&&(v[g]=i);return v&&SF(o,n,v),o},Wo=(t,e,n)=>xF(t,typeof e!="symbol"?e+"":e,n),PF,CF,_F,IF,EF,kF,TF,MF,AF,jF,vr;jF=[ar],AF=[G],MF=[G],TF=[G],kF=[G],EF=[G],IF=[G],_F=[G],CF=[G],PF=[ar];class $r{constructor(e,n,r){this.editor=e,this.elem=n,this.container=r,ahe(vr,5,this),Wo(this,"disposables",[]),Wo(this,"gl"),Wo(this,"shapeGeometryCache"),Wo(this,"colors"),Wo(this,"id",Ke()),Wo(this,"canvasBoundingClientRect",Mt("canvasBoundingClientRect",new Z)),Wo(this,"originPagePoint",new x),Wo(this,"originPageCenter",new x),Wo(this,"isInViewport",!1),this.gl=ehe(n),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",o=>{const s=e.getShapeMaskedPageBounds(o.id);if(!s)return null;const i=new Float32Array(12);return Ra(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),ii("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Ec(e.getPropertyValue("--color-text-3").trim()),selectFill:Ec(e.getPropertyValue("--color-selected").trim()),viewportFill:Ec(e.getPropertyValue("--color-muted-1").trim()),background:Ec(e.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const e=this.editor.getViewportPageBounds(),n=this.editor.getCurrentPageBounds();return n?Z.Expand(n,e):e}getContentScreenBounds(){const e=this.getContentPageBounds(),n=this.editor.pageToScreen(e.point),r=this.editor.pageToScreen(new x(e.maxX,e.maxY));return new Z(n.x,n.y,r.x-n.x,r.y-n.y)}_getCanvasBoundingRect(){const{x:e,y:n,width:r,height:o}=this.elem.getBoundingClientRect();return new Z(e,n,r,o)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const e=new ResizeObserver(()=>{const n=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(n)});return e.observe(this.elem),e.observe(this.container),()=>e.disconnect()}getCanvasSize(){const e=this.canvasBoundingClientRect.get(),n=this.getDpr();return new x(e.width*n,e.height*n)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const e=this.getCanvasScreenBounds(),n=this.getContentPageBounds(),r=e.width/e.height;let o=n.width,s=o/r;s<n.height&&(s=n.height,o=s*r);const i=new Z(0,0,o,s);return i.center=n.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:e,y:n,w:r,h:o}=this.getCanvasPageBounds();return new Float32Array([e,n,r,o])}getMinimapPagePoint(e,n){const r=this.getCanvasPageBounds(),o=this.getCanvasScreenBounds();let s=e-o.x,i=n-o.y;return s*=r.width/o.width,i*=r.height/o.height,s+=r.minX,i+=r.minY,new x(s,i,1)}minimapScreenPointToPagePoint(e,n,r=!1,o=!1){const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(e,n);if(o){const c=this.editor.getCurrentPageBounds()??new Z,u=c.minX-i.width/2,h=c.maxX+i.width/2,p=c.minY-i.height/2,f=c.maxY+i.height/2,g=Math.max(0,u+i.width-a),m=Math.max(0,-(h-i.width-a)),v=Math.max(0,p+i.height-l),S=Math.max(0,-(f-i.height-l));a+=(g-m)/2,l+=(v-S)/2,a=zt(a,u,h),l=zt(l,p,f)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),h=Math.abs(l-c.y);u>h?l=c.y:a=c.x}return new x(a,l)}render(){const e=this.gl.context,n=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=n.x,this.elem.height=n.y,e.viewport(0,0,n.x,n.y),e.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),e.clear(e.COLOR_BUFFER_BIT);const r=new Set(this.editor.getSelectedShapeIds()),o=this.colors;let s=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let l=0,c=a.length;l<c;l++){const u=a[l],h=this.shapeGeometryCache.get(u);if(!h)continue;const p=h.length;r.has(u)?(LE(this.gl.selectedShapes,s,h),s+=p):(LE(this.gl.unselectedShapes,i,h),i+=p)}this.drawShapes(this.gl.unselectedShapes,i,o.shapeFill),this.drawShapes(this.gl.selectedShapes,s,o.selectFill),this.drawViewport(),this.drawCollaborators()}drawShapes(e,n,r){this.gl.prepareTriangles(e,n),this.gl.setFillColor(r),this.gl.drawTriangles(n)}drawViewport(){const e=this.editor.getViewportPageBounds(),n=Jde(this.gl.viewport.vertices,e,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,n),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(n),this.editor.environment.isSafari&&(this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n))}drawCollaborators(){const e=this.editor.getCollaboratorsOnCurrentPage();if(!e.length)return;const n=20,r=n*6,o=r*e.length;this.gl.collaborators.vertices.length<o&&(this.gl.collaborators.vertices=new Float32Array(o));const s=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:l}of e)Da(s,{center:x.From(l),radius:3*a,offset:i,numArcSegments:n}),i+=r;this.gl.prepareTriangles(this.gl.collaborators,o),i=0;for(const{color:l}of e)this.gl.setFillColor(Ec(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}vr=ohe();Fo(vr,1,"close",jF,$r);Fo(vr,1,"getDpr",AF,$r);Fo(vr,1,"getContentPageBounds",MF,$r);Fo(vr,1,"getContentScreenBounds",TF,$r);Fo(vr,1,"getCanvasSize",kF,$r);Fo(vr,1,"getCanvasClientPosition",EF,$r);Fo(vr,1,"getCanvasPageBounds",IF,$r);Fo(vr,1,"getZoom",_F,$r);Fo(vr,1,"getCanvasPageBoundsArray",CF,$r);Fo(vr,1,"render",PF,$r);ihe(vr,$r);function lhe(){const t=F(),e=Lt(),n=w.useRef(null),r=w.useRef(!1),o=w.useRef();w.useEffect(()=>{try{const u=new $r(t,n.current,e);return o.current=u,o.current.close}catch(u){t.annotateError(u,{origin:"minimap",willCrashApp:!1}),t.timers.setTimeout(()=>{throw u})}},[t,e]);const s=w.useCallback(u=>{if(!t.getCurrentPageShapeIds().size||!o.current)return;const h=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.originPagePoint.setTo(p),o.current.originPageCenter.setTo(t.getViewportPageBounds().center),t.centerOnPoint(h,{animation:{duration:t.options.animationMediumMs}})},[t]),i=w.useCallback(u=>{if(!o.current)return;const h=u.currentTarget;if(td(h,u),!t.getCurrentPageShapeIds().size)return;r.current=!0,o.current.isInViewport=!1;const p=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=t.getViewportPageBounds(),g=o.current.getContentPageBounds();if(new Z(g.x-f.width/2,g.y-f.height/2,g.width+f.width,g.height+f.height).containsPoint(p)&&!f.containsPoint(p)){o.current.isInViewport=f.containsPoint(p);const S=x.Sub(f.center,f.point),y=x.Add(p,S);o.current.originPagePoint.setTo(y),o.current.originPageCenter.setTo(p),t.centerOnPoint(p,{animation:{duration:t.options.animationMediumMs}})}else{const S=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.isInViewport=f.containsPoint(S),o.current.originPagePoint.setTo(S),o.current.originPageCenter.setTo(f.center)}function v(S){h&&nd(h,S),r.current=!1,document.body.removeEventListener("pointerup",v)}document.body.addEventListener("pointerup",v)},[t]),a=w.useCallback(u=>{if(!o.current)return;const h=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(o.current.isInViewport){const m=o.current.originPagePoint.clone().sub(o.current.originPageCenter);t.centerOnPoint(x.Sub(h,m));return}t.centerOnPoint(h)}const p=o.current.getMinimapPagePoint(u.clientX,u.clientY),f=t.pageToScreen(p),g={type:"pointer",target:"canvas",name:"pointer_move",...Bn(u),point:f,isPen:t.getInstanceState().isPenMode};t.dispatch(g)},[t]),l=w.useCallback(u=>{const h=zA(u);t.dispatch({type:"wheel",name:"wheel",delta:h,point:new x(u.clientX,u.clientY),shiftKey:u.shiftKey,altKey:u.altKey,ctrlKey:u.metaKey||u.ctrlKey})},[t]),c=dd();return w.useEffect(()=>{t.timers.setTimeout(()=>{var u,h;(u=o.current)==null||u.updateColors(),(h=o.current)==null||h.render()})},[c,t]),d.jsx("div",{className:"tlui-minimap",children:d.jsx("canvas",{role:"img","aria-label":"minimap",ref:n,className:"tlui-minimap__canvas",onDoubleClick:s,onPointerMove:a,onPointerDown:i,onWheel:l})})}function che(t,e){const[n,r]=Ie.useState(e);Ie.useLayoutEffect(()=>{const s=fw(t);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${t} from local storage.`)}},[t]);const o=Ie.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return gw(t,JSON.stringify(a)),a})},[t]);return[n,o]}const uhe=w.memo(function(){const e=Sa(),n=Ce(),r=kn(),[o,s]=che("minimap",!0),i=w.useCallback(()=>{s(c=>!c)},[s]),{ZoomMenu:a,Minimap:l}=Ii();return r<Pt.MOBILE?null:d.jsxs("div",{className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<Pt.TABLET?d.jsx(a,{}):o?d.jsxs(d.Fragment,{children:[a&&d.jsx(a,{}),l&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(Ru(e["zoom-out"].label))} ${Nx(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"minus"})}),a&&d.jsx(a,{}),d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(Ru(e["zoom-in"].label))} ${Nx(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"plus"})}),l&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=Pt.TABLET&&!o&&d.jsx(l,{})]})}),dhe=function({name:e,id:n,isCurrentPage:r,onCancel:o}){const s=F(),i=Zt(),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(()=>{l.current=s.markHistoryStoppingPoint("rename page")},[s]),u=w.useCallback(p=>{s.renamePage(n,p||"New Page"),i("rename-page",{source:"page-menu"})},[s,n,i]),h=w.useCallback(()=>{l.current&&s.bailToMark(l.current),o()},[s,o]);return d.jsx(Xg,{className:"tlui-page-menu__item__input",ref:p=>a.current=p,defaultValue:e,onValueChange:u,onCancel:h,onFocus:c,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},r0=(t,e,n,r,o)=>{let s;const i=t.getPages(),a=n>r?i[r-1]:i[r],l=n>r?i[r]:i[r+1];a&&!l?s=vo(a.index):!a&&l?s=A9(i[0].index):s=Eu(a.index,l.index),s!==i[n].index&&(t.markHistoryStoppingPoint("moving page"),t.updatePage({id:e,index:s}),o("move-page",{source:"page-menu"}))},$E=Rt(function({index:e,listSize:n,item:r,onRename:o}){const s=F(),i=Ce(),a=s.getPages(),l=Zt(),c=w.useCallback(()=>{s.markHistoryStoppingPoint("creating page");const f=gr.createId();s.duplicatePage(r.id,f),l("duplicate-page",{source:"page-menu"})},[s,r,l]),u=w.useCallback(()=>{r0(s,r.id,e,e-1,l)},[s,r,e,l]),h=w.useCallback(()=>{r0(s,r.id,e,e+1,l)},[s,r,e,l]),p=w.useCallback(()=>{s.markHistoryStoppingPoint("deleting page"),s.deletePage(r.id),l("delete-page",{source:"page-menu"})},[s,r,l]);return d.jsxs(aa,{id:`page item submenu ${e}`,children:[d.jsx(la,{children:d.jsx(ue,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical"})})}),d.jsx(ca,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(Dr,{type:"menu",sourceId:"page-menu",children:[d.jsxs(ve,{id:"modify",children:[o&&d.jsx(Ht,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),d.jsx(Ht,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=s.options.maxPages}),e>0&&d.jsx(Ht,{id:"move-up",onSelect:u,label:"page-menu.submenu.move-up"}),e<n-1&&d.jsx(Ht,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:h})]}),n>1&&d.jsx(ve,{id:"delete",children:d.jsx(Ht,{id:"delete",onSelect:p,label:"page-menu.submenu.delete"})})]})})]})}),hhe=w.memo(function(){const e=F(),n=Zt(),r=Ce(),o=kn(),s=w.useCallback(()=>S(!1),[]),[i,a]=Ps("page-menu",s),l=36,c=w.useRef(null),u=U("pages",()=>e.getPages(),[e]),h=U("currentPage",()=>e.getCurrentPage(),[e]),p=U("currentPageId",()=>e.getCurrentPageId(),[e]),f=bs(),g=U("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),m=U("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[v,S]=w.useState(!1),y=w.useCallback(()=>{f||S(O=>!O)},[f]),b=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,C]=w.useState(Object.fromEntries(u.map((O,D)=>[O.id,{y:D*l,offsetY:0,isSelected:!1}])));w.useLayoutEffect(()=>{C(Object.fromEntries(u.map((O,D)=>[O.id,{y:D*l,offsetY:0,isSelected:!1}])))},[l,u]),w.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const O=document.querySelector(`[data-testid="page-menu-item-${p}"]`);if(O){const D=c.current;if(!D)return;const B=O.offsetTop,z=D.scrollTop;B<z&&D.scrollTo({top:B});const K=B+l,N=D.scrollTop+D.offsetHeight;K>N&&D.scrollTo({top:K-D.offsetHeight})}})},[l,p,i,e]);const I=w.useCallback(O=>{const{clientY:D,currentTarget:B}=O,{dataset:{id:z,index:K}}=B;if(!z||!K)return;const N=b.current;td(O.currentTarget,O),N.status="pointing",N.pointing={id:z,index:+K};const Y=P[z].y;N.startY=D,N.startIndex=Math.max(0,Math.min(Math.round(Y/l),u.length-1))},[l,u.length,P]),T=w.useCallback(O=>{const D=b.current;if(D.status==="pointing"){const{clientY:B}=O,z=B-D.startY;Math.abs(z)>5&&(D.status="dragging")}if(D.status==="dragging"){const{clientY:B}=O,z=B-D.startY,K=P[D.pointing.id],{startIndex:N,pointing:H}=D,Y=K.y+z,ee=Math.max(0,Math.min(Math.round(Y/l),u.length-1)),ce={...P};if(ce[H.id]={y:K.y,offsetY:z,isSelected:!0},ee!==D.dragIndex){D.dragIndex=ee;for(let ge=0;ge<u.length;ge++){const Te=u[ge];if(Te.id===D.pointing.id)continue;let{y:se}=ce[Te.id];ee===N?se=ge*l:ee<N?ee<=ge&&ge<N?se=(ge+1)*l:se=ge*l:ee>N&&(ee>=ge&&ge>N?se=(ge-1)*l:se=ge*l),se!==ce[Te.id].y&&(ce[Te.id]={y:se,offsetY:0,isSelected:!0})}}C(ce)}},[l,u,P]),_=w.useCallback(O=>{const D=b.current;if(D.status==="dragging"){const{id:B,index:z}=D.pointing;r0(e,B,z,D.dragIndex,n)}nd(O.currentTarget,O),D.status="idle"},[e,n]),k=w.useCallback(O=>{const D=b.current;O.key==="Escape"&&(D.status==="dragging"&&C(Object.fromEntries(u.map((B,z)=>[B.id,{y:z*l,offsetY:0,isSelected:!1}]))),D.status="idle")},[l,u]),M=w.useCallback(()=>{f||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const O=gr.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:O}),e.setCurrentPage(O),S(!0)}),n("new-page",{source:"page-menu"}))},[e,r,f,n]),R=w.useCallback(O=>{e.setCurrentPage(O),n("change-page",{source:"page-menu"})},[e,n]),j=w.useCallback((O,D)=>{e.renamePage(O,D),n("rename-page",{source:"page-menu"})},[e,n]);return d.jsxs(Cb,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(_b,{"data-testid":"main.page-menu",children:d.jsxs(ue,{type:"menu",title:h.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[d.jsx("div",{className:"tlui-page-menu__name",children:h.name}),d.jsx(be,{icon:"chevron-down",small:!0})]})}),d.jsx(Ib,{side:"bottom",align:"start",sideOffset:6,disableEscapeKeyDown:v,children:d.jsxs("div",{className:"tlui-page-menu__wrapper",children:[d.jsxs("div",{className:"tlui-page-menu__header",children:[d.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!f&&d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsx(ue,{type:"icon","data-testid":"page-menu.edit",title:r(v?"page-menu.edit-done":"page-menu.edit-start"),onClick:y,children:d.jsx(be,{icon:v?"check":"edit"})}),d.jsx(ue,{type:"icon","data-testid":"page-menu.create",title:r(g?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:g,onClick:M,children:d.jsx(be,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((O,D)=>{const B=P[O.id]??{position:D*40,offsetY:0};return v?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:O.id===h.id?888:D,transform:`translate(0px, ${B.y+B.offsetY}px)`},children:[d.jsx(ue,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:I,onPointerUp:_,onPointerMove:T,onKeyDown:k,"data-id":O.id,"data-index":D,children:d.jsx(be,{icon:"drag-handle-dots"})}),o<Pt.TABLET_SM&&m?d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const z=window.prompt("Rename page",O.name);z&&z!==O.name&&j(O.id,z)},onDoubleClick:y,children:[d.jsx(n0,{checked:O.id===h.id}),d.jsx(wt,{children:O.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:d.jsx(dhe,{id:O.id,name:O.name,isCurrentPage:O.id===h.id,onCancel:()=>{S(!1),e.clearOpenMenus()}})}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":v,children:d.jsx($E,{index:D,item:O,listSize:u.length})})]},O.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>R(O.id),onDoubleClick:y,title:r("page-menu.go-to-page"),children:[d.jsx(n0,{checked:O.id===h.id}),d.jsx(wt,{children:O.name})]}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx($E,{index:D,item:O,listSize:u.length,onRename:()=>{if(e.environment.isIos){const z=window.prompt("Rename page",O.name);z&&z!==O.name&&j(O.id,z)}else S(!0),p!==O.id&&R(O.id)}})})]},O.id)})})]})})]})});function phe(){const t=F(),e=q5(),n=X5(),r=Tn(1),o=bs(),s=U("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]),i=Cs(),a=r&&i;if(!(o&&!s))return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"undo",disabled:!e}),d.jsx(W,{actionId:"redo",disabled:!n}),d.jsx(W,{actionId:"delete",disabled:!a}),d.jsx(W,{actionId:"duplicate",disabled:!a})]})}const fhe=w.memo(function({children:e}){const n=e??d.jsx(phe,{});return d.jsx(Dr,{type:"small-icons",sourceId:"quick-actions",children:n})});function ghe({userId:t}){const e=Ig(t);return e?d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:e.color},children:e.userName==="New User"?"":e.userName[0]??""},t):null}const mhe=Rt(function({userId:e}){const n=F(),r=Ce(),o=Zt(),s=Ig(e),i=w.useCallback(()=>{n.getInstanceState().followingUserId===e?(n.stopFollowingUser(),o("stop-following",{source:"people-menu"})):(n.startFollowingUser(e),o("start-following",{source:"people-menu"}))},[n,e,o]),a=(s==null?void 0:s.followingUserId)===n.user.getId(),l=n.getInstanceState().followingUserId===e;return s?d.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal",children:[d.jsxs(ue,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>n.zoomToUser(e),onDoubleClick:i,children:[d.jsx(Mo,{icon:"color",color:s.color}),d.jsx("div",{className:"tlui-people-menu__name",children:s.userName??"New User"})]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:i,disabled:a,"data-active":l||a,children:d.jsx(be,{icon:a?"leading":l?"following":"follow"})})]}):null});function yhe({count:t}){return d.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(t)})}const She=Rt(function(){const e=F(),n=Lt(),r=Ce(),o=Zt(),s=w.useRef(!1),[i,a]=w.useState(!1),l=w.useCallback(m=>{a(m)},[]),c=e.user.getColor(),u=w.useCallback(m=>{e.user.updateUserPreferences({color:m}),o("set-color",{source:"people-menu"})},[e,o]),{handleButtonClick:h,handleButtonPointerDown:p,handleButtonPointerEnter:f,handleButtonPointerUp:g}=Ie.useMemo(()=>{const m=()=>{s.current=!1,window.removeEventListener("pointerup",m)};return{handleButtonClick:P=>{const{id:C}=P.currentTarget.dataset;C&&c!==C&&u(C)},handleButtonPointerDown:P=>{const{id:C}=P.currentTarget.dataset;C&&(u(C),s.current=!0,window.addEventListener("pointerup",m))},handleButtonPointerEnter:P=>{if(!s.current)return;const{id:C}=P.currentTarget.dataset;C&&u(C)},handleButtonPointerUp:P=>{const{id:C}=P.currentTarget.dataset;C&&u(C)}}},[c,u]);return d.jsxs(xb,{onOpenChange:l,open:i,children:[d.jsx(wb,{dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:d.jsx(be,{icon:"color"})})}),d.jsx(bb,{container:n,children:d.jsx(Pb,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:d.jsx("div",{className:"tlui-buttons__grid",children:dx.map(m=>d.jsx(ue,{type:"icon","data-id":m,"data-testid":m,"aria-label":m,"data-state":c===m?"hinted":void 0,title:m,className:"tlui-button-grid__button",style:{color:m},onPointerEnter:f,onPointerDown:p,onPointerUp:g,onClick:h,children:d.jsx(be,{icon:"color"})},m))})})})]})});function vhe(){const t=F(),e=Zt(),n=U("userName",()=>t.user.getName(),[]),r=Ce(),o=w.useRef(n),s=w.useRef(n),[i,a]=w.useState(!1),l=w.useCallback(()=>{a(p=>!p)},[]),c=w.useCallback(p=>{s.current=p,t.user.updateUserPreferences({name:p})},[t]),u=w.useCallback(()=>{o.current!==s.current&&(e("change-user-name",{source:"people-menu"}),o.current=s.current)},[e]),h=w.useCallback(()=>{a(!1),t.user.updateUserPreferences({name:o.current}),t.clearOpenMenus()},[t]);return d.jsxs("div",{className:"tlui-people-menu__user",children:[d.jsx(She,{}),i?d.jsx(Xg,{className:"tlui-people-menu__user__input",defaultValue:n,onValueChange:c,onComplete:l,onCancel:h,onBlur:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{i||a(!0)},children:n}),n==="New User"?d.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")}):null]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:d.jsx(be,{icon:i?"check":"edit"})})]})}const xhe=Rt(function({children:e}){const n=Ce(),r=Lt(),o=F(),s=HA(),i=U("user",()=>o.user.getColor(),[o]),a=U("user",()=>o.user.getName(),[o]),[l,c]=Ps("people menu");return d.jsxs(xb,{onOpenChange:c,open:l,children:[d.jsx(wb,{dir:"ltr",asChild:!0,children:d.jsxs("button",{className:"tlui-people-menu__avatars-button",title:n("people-menu.title"),children:[s.length>5&&d.jsx(yhe,{count:s.length-5}),d.jsxs("div",{className:"tlui-people-menu__avatars",children:[s.slice(-5).map(u=>d.jsx(ghe,{userId:u},u)),d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx(bb,{container:r,children:d.jsx(Pb,{dir:"ltr",className:"tlui-menu",align:"end",side:"bottom",sideOffset:2,alignOffset:-5,onEscapeKeyDown:we,children:d.jsxs("div",{className:"tlui-people-menu__wrapper",children:[d.jsx("div",{className:"tlui-people-menu__section",children:d.jsx(vhe,{})}),s.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:s.map(u=>d.jsx(mhe,{userId:u},u+"_presence"))}),e]})})})]})});function whe(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(xhe,{})})}const bhe=Object.freeze([fr,ta,na,To]);function OF(t=bhe){const e=F();return U("getRelevantStyles",()=>{var s;const n=new mx(e.getSharedStyles()),r=!!((s=e.root.getCurrent())!=null&&s.shapeType),o=e.isIn("select")&&e.getSelectedShapeIds().length>0;if(n.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const i of t)n.applyValue(i,e.getStyleForNextShape(i));return r||o||n.size>0?n:null},[e])}const Tr={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},Bi=w.memo(function(e){const{uiType:n,items:r,title:o,style:s,value:i,onValueChange:a,theme:l}=e,c=F(),u=Ce(),h=w.useRef(!1),p=w.useRef(null),{handleButtonClick:f,handleButtonPointerDown:g,handleButtonPointerEnter:m,handleButtonPointerUp:v}=w.useMemo(()=>{const S=()=>{h.current=!1,window.removeEventListener("pointerup",S);const I=p.current;I&&["TEXTAREA","INPUT"].includes(I.nodeName)&&I.focus(),p.current=null};return{handleButtonClick:I=>{const{id:T}=I.currentTarget.dataset;i.type==="shared"&&i.value===T||(c.markHistoryStoppingPoint("point picker item"),a(s,T))},handleButtonPointerDown:I=>{const{id:T}=I.currentTarget.dataset;c.markHistoryStoppingPoint("point picker item"),a(s,T),h.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",S)},handleButtonPointerEnter:I=>{if(!h.current)return;const{id:T}=I.currentTarget.dataset;a(s,T)},handleButtonPointerUp:I=>{const{id:T}=I.currentTarget.dataset;i.type==="shared"&&i.value===T||a(s,T)}}},[i,c,a,s]);return d.jsx("div",{"data-testid":`style.${n}`,className:le("tlui-buttons__grid"),children:r.map(S=>d.jsx(ue,{type:"icon","data-id":S.value,"data-testid":`style.${n}.${S.value}`,"aria-label":S.value,"data-state":i.type==="shared"&&i.value===S.value?"hinted":void 0,title:o+" — "+u(`${n}-style.${S.value}`),className:le("tlui-button-grid__button"),style:s===fr?{color:l[S.value].solid}:void 0,onPointerEnter:m,onPointerDown:g,onPointerUp:v,onClick:f,children:d.jsx(be,{icon:S.icon})},S.value))})});function DF(t,[e,n]){return Math.min(n,Math.max(e,t))}function Phe(t){const e=w.useRef({value:t,previous:t});return w.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}var RF=["PageUp","PageDown"],LF=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],$F={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Zl="Slider",[o0,Che,_he]=qg(Zl),[FF,Yfe]=Lo(Zl,[_he]),[Ihe,vm]=FF(Zl),NF=w.forwardRef((t,e)=>{const{name:n,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:h=()=>{},onValueCommit:p=()=>{},inverted:f=!1,...g}=t,m=w.useRef(new Set),v=w.useRef(0),y=i==="horizontal"?Ehe:khe,[b=[],P]=Pi({prop:u,defaultProp:c,onChange:M=>{var j;(j=[...m.current][v.current])==null||j.focus(),h(M)}}),C=w.useRef(b);function I(M){const R=Ohe(b,M);k(M,R)}function T(M){k(M,v.current)}function _(){const M=C.current[v.current];b[v.current]!==M&&p(b)}function k(M,R,{commit:j}={commit:!1}){const O=$he(s),D=Fhe(Math.round((M-r)/s)*s+r,O),B=DF(D,[r,o]);P((z=[])=>{const K=Ahe(z,B,R);if(Lhe(K,l*s)){v.current=K.indexOf(B);const N=String(K)!==String(z);return N&&j&&p(K),N?K:z}else return z})}return d.jsx(Ihe,{scope:t.__scopeSlider,name:n,disabled:a,min:r,max:o,valueIndexToChangeRef:v,thumbs:m.current,values:b,orientation:i,children:d.jsx(o0.Provider,{scope:t.__scopeSlider,children:d.jsx(o0.Slot,{scope:t.__scopeSlider,children:d.jsx(y,{"aria-disabled":a,"data-disabled":a?"":void 0,...g,ref:e,onPointerDown:oe(g.onPointerDown,()=>{a||(C.current=b)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:I,onSlideMove:a?void 0:T,onSlideEnd:a?void 0:_,onHomeKeyDown:()=>!a&&k(r,0,{commit:!0}),onEndKeyDown:()=>!a&&k(o,b.length-1,{commit:!0}),onStepKeyDown:({event:M,direction:R})=>{if(!a){const D=RF.includes(M.key)||M.shiftKey&&LF.includes(M.key)?10:1,B=v.current,z=b[B],K=s*D*R;k(z+K,B,{commit:!0})}}})})})})});NF.displayName=Zl;var[zF,BF]=FF(Zl,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Ehe=w.forwardRef((t,e)=>{const{min:n,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=t,[h,p]=w.useState(null),f=Ze(e,b=>p(b)),g=w.useRef(),m=R1(o),v=m==="ltr",S=v&&!s||!v&&s;function y(b){const P=g.current||h.getBoundingClientRect(),C=[0,P.width],T=kb(C,S?[n,r]:[r,n]);return g.current=P,T(b-P.left)}return d.jsx(zF,{scope:t.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width",children:d.jsx(UF,{dir:m,"data-orientation":"horizontal",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const P=y(b.clientX);i==null||i(P)},onSlideMove:b=>{const P=y(b.clientX);a==null||a(P)},onSlideEnd:()=>{g.current=void 0,l==null||l()},onStepKeyDown:b=>{const C=$F[S?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:C?-1:1})}})})}),khe=w.forwardRef((t,e)=>{const{min:n,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=t,u=w.useRef(null),h=Ze(e,u),p=w.useRef(),f=!o;function g(m){const v=p.current||u.current.getBoundingClientRect(),S=[0,v.height],b=kb(S,f?[r,n]:[n,r]);return p.current=v,b(m-v.top)}return d.jsx(zF,{scope:t.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:d.jsx(UF,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const v=g(m.clientY);s==null||s(v)},onSlideMove:m=>{const v=g(m.clientY);i==null||i(v)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:m=>{const S=$F[f?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:S?-1:1})}})})}),UF=w.forwardRef((t,e)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=t,u=vm(Zl,n);return d.jsx(Ae.span,{...c,ref:e,onKeyDown:oe(t.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):RF.concat(LF).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:oe(t.onPointerDown,h=>{const p=h.target;p.setPointerCapture(h.pointerId),h.preventDefault(),u.thumbs.has(p)?p.focus():r(h)}),onPointerMove:oe(t.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&o(h)}),onPointerUp:oe(t.onPointerUp,h=>{const p=h.target;p.hasPointerCapture(h.pointerId)&&(p.releasePointerCapture(h.pointerId),s(h))})})}),HF="SliderTrack",KF=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=vm(HF,n);return d.jsx(Ae.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:e})});KF.displayName=HF;var s0="SliderRange",WF=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=vm(s0,n),s=BF(s0,n),i=w.useRef(null),a=Ze(e,i),l=o.values.length,c=o.values.map(p=>VF(p,o.min,o.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(Ae.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:a,style:{...t.style,[s.startEdge]:u+"%",[s.endEdge]:h+"%"}})});WF.displayName=s0;var i0="SliderThumb",GF=w.forwardRef((t,e)=>{const n=Che(t.__scopeSlider),[r,o]=w.useState(null),s=Ze(e,a=>o(a)),i=w.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return d.jsx(The,{...t,ref:s,index:i})}),The=w.forwardRef((t,e)=>{const{__scopeSlider:n,index:r,name:o,...s}=t,i=vm(i0,n),a=BF(i0,n),[l,c]=w.useState(null),u=Ze(e,y=>c(y)),h=l?!!l.closest("form"):!0,p=$3(l),f=i.values[r],g=f===void 0?0:VF(f,i.min,i.max),m=jhe(r,i.values.length),v=p==null?void 0:p[a.size],S=v?Dhe(v,g,a.direction):0;return w.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${g}% + ${S}px)`},children:[d.jsx(o0.ItemSlot,{scope:t.__scopeSlider,children:d.jsx(Ae.span,{role:"slider","aria-label":t["aria-label"]||m,"aria-valuemin":i.min,"aria-valuenow":f,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...s,ref:u,style:f===void 0?{display:"none"}:t.style,onFocus:oe(t.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&d.jsx(Mhe,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),value:f},r)]})});GF.displayName=i0;var Mhe=t=>{const{value:e,...n}=t,r=w.useRef(null),o=Phe(e);return w.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==e&&l){const c=new Event("input",{bubbles:!0});l.call(s,e),s.dispatchEvent(c)}},[o,e]),d.jsx("input",{style:{display:"none"},...n,ref:r,defaultValue:e})};function Ahe(t=[],e,n){const r=[...t];return r[n]=e,r.sort((o,s)=>o-s)}function VF(t,e,n){const s=100/(n-e)*(t-e);return DF(s,[0,100])}function jhe(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}function Ohe(t,e){if(t.length===1)return 0;const n=t.map(o=>Math.abs(o-e)),r=Math.min(...n);return n.indexOf(r)}function Dhe(t,e,n){const r=t/2,s=kb([0,50],[0,r]);return(r-s(e)*n)*n}function Rhe(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}function Lhe(t,e){if(e>0){const n=Rhe(t);return Math.min(...n)>=e}return!0}function kb(t,e){return n=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(t[1]-t[0]);return e[0]+r*(n-t[0])}}function $he(t){return(String(t).split(".")[1]||"").length}function Fhe(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}var Nhe=NF,zhe=KF,Bhe=WF,Uhe=GF;const Hhe=w.memo(function(e){const{title:n,steps:r,value:o,label:s,onValueChange:i}=e,a=F(),l=Ce(),c=w.useCallback(p=>{i(p[0])},[i]),u=w.useCallback(()=>{a.markHistoryStoppingPoint("click slider")},[a]),h=w.useCallback(()=>{o&&i(o)},[o,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(Nhe,{"data-testid":e["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:h,title:n+" — "+l(s),children:[d.jsx(zhe,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&d.jsx(Bhe,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&d.jsx(Uhe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Khe({label:t,uiTypeA:e,uiTypeB:n,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const p=Ce(),f=w.useMemo(()=>{var m;return((m=s.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:m.icon)??"mixed"},[s,c]),g=w.useMemo(()=>{var m;return((m=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:m.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:p(t),className:"tlui-style-panel__double-select-picker-label",children:p(t)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(aa,{id:`style panel ${e} A`,children:[d.jsx(la,{children:d.jsx(ue,{type:"icon","data-testid":`style.${e}`,title:p(r)+" — "+(c===null||c.type==="mixed"?p("style-panel.mixed"):p(`${e}-style.${c.value}`)),children:d.jsx(be,{icon:f,small:!0,invertIcon:!0})})}),d.jsx(ca,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map((m,v)=>d.jsx(zu,{"data-testid":`style.${e}.${m.value}`,children:d.jsx(ue,{type:"icon",onClick:()=>h(a,m.value),title:`${p(r)} — ${p(`${e}-style.${m.value}`)}`,children:d.jsx(be,{icon:m.icon,invertIcon:!0})},m.value)},v))})})]}),d.jsxs(aa,{id:`style panel ${n}`,children:[d.jsx(la,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}`,title:p(o)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${n}-style.${u.value}`)),children:d.jsx(be,{icon:g,small:!0})})}),d.jsx(ca,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(zu,{children:d.jsx(ue,{type:"icon",title:`${p(o)} — ${p(`${n}-style.${m.value}`)}`,"data-testid":`style.${n}.${m.value}`,onClick:()=>h(l,m.value),children:d.jsx(be,{icon:m.icon})})},m.value))})})]})]})]})}const Whe=w.memo(Khe);function Ghe({id:t,label:e,uiType:n,style:r,items:o,type:s,value:i,onValueChange:a}){const l=Ce(),c=F(),u=w.useMemo(()=>{var f;return(f=o.find(g=>i.type==="shared"&&g.value===i.value))==null?void 0:f.icon},[o,i]),h=i.type==="mixed"?l("style-panel.mixed"):l(`${n}-style.${i.value}`),p=e?l(e):"";return d.jsxs(aa,{id:`style panel ${t}`,children:[d.jsx(la,{children:d.jsxs(ue,{type:s,"data-testid":`style.${n}`,title:h,children:[d.jsx(wt,{children:p}),d.jsx(be,{icon:u??"mixed"})]})}),d.jsx(ca,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>d.jsx(zu,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}.${f.value}`,title:l(`${n}-style.${f.value}`),onClick:()=>{c.markHistoryStoppingPoint("select style dropdown item"),a(r,f.value)},children:d.jsx(be,{icon:f.icon})})},f.value))})})]})}const Tb=w.memo(Ghe);function Vhe({styles:t}){const e=dd();if(!t)return null;const n=t.get(Vr),r=t.get(vf),o=t.get(Sf),s=t.get(Pf),i=t.get(ko),a=n===void 0,l=r===void 0&&o===void 0,c=s===void 0,u=i===void 0,h=ws({isDarkMode:e});return d.jsxs(d.Fragment,{children:[d.jsx(Yhe,{theme:h,styles:t}),!u&&d.jsx(Xhe,{theme:h,styles:t}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(qhe,{styles:t}),d.jsx(Qhe,{styles:t}),d.jsx(Zhe,{styles:t})]})]})}function vd(){const t=F(),e=Zt();return Ie.useMemo(()=>function(r,o){t.run(()=>{t.isIn("select")&&t.setStyleForSelectedShapes(r,o),t.setStyleForNextShapes(r,o),t.updateInstanceState({isChangingStyle:!0})}),e("set-style",{source:"style-panel",id:r.id,value:o})},[t,e])}function Yhe({styles:t,theme:e}){const n=Ce(),r=F(),o=vd(),s=t.get(fr),i=t.get(na),a=t.get(ta),l=t.get(To),c=i!==void 0||a!==void 0||l!==void 0;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:d.jsx(Bi,{title:n("style-panel.color"),uiType:"color",style:fr,items:Tr.color,value:s,onValueChange:o,theme:e}),d.jsx(Jhe,{})]}),c&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:d.jsx(Bi,{title:n("style-panel.fill"),uiType:"fill",style:na,items:Tr.fill,value:i,onValueChange:o,theme:e}),a===void 0?null:d.jsx(Bi,{title:n("style-panel.dash"),uiType:"dash",style:ta,items:Tr.dash,value:a,onValueChange:o,theme:e}),l===void 0?null:d.jsx(Bi,{title:n("style-panel.size"),uiType:"size",style:To,items:Tr.size,value:l,onValueChange:(u,h)=>{o(u,h);const p=r.getSelectedShapeIds();p.length>0&&Ve(r,p)},theme:e})]})]})}function Xhe({theme:t,styles:e}){const n=Ce(),r=vd(),o=e.get(ko),s=e.get(ix),i=e.get(wf),a=e.get(bf);return o===void 0&&i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:d.jsx(Bi,{title:n("style-panel.font"),uiType:"font",style:ko,items:Tr.font,value:o,onValueChange:r,theme:t}),s===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Bi,{title:n("style-panel.align"),uiType:"align",style:ix,items:Tr.textAlign,value:s,onValueChange:r,theme:t}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})})})]}),i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Bi,{title:n("style-panel.align"),uiType:"align",style:wf,items:Tr.horizontalAlign,value:i,onValueChange:r,theme:t}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:a===void 0?d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})}):d.jsx(Tb,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:bf,items:Tr.verticalAlign,value:a,onValueChange:r})})]})]})}function qhe({styles:t}){const e=vd(),n=t.get(Vr);return n===void 0?null:d.jsx(Tb,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:Vr,items:Tr.geo,value:n,onValueChange:e})}function Zhe({styles:t}){const e=vd(),n=t.get(Pf);return n===void 0?null:d.jsx(Tb,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:Pf,items:Tr.spline,value:n,onValueChange:e})}function Qhe({styles:t}){const e=vd(),n=t.get(vf),r=t.get(Sf);return!n||!r?null:d.jsx(Whe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Sf,itemsA:Tr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:vf,itemsB:Tr.arrowheadEnd,valueB:n,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const kc=[.1,.25,.5,.75,1];function Jhe(){const t=F(),e=U("opacity",()=>t.getSharedOpacity(),[t]),n=Zt(),r=Ce(),o=Ie.useCallback(i=>{const a=kc[i];t.run(()=>{t.isIn("select")&&t.setOpacityForSelectedShapes(a),t.setOpacityForNextShapes(a),t.updateInstanceState({isChangingStyle:!0})}),n("set-style",{source:"style-panel",id:"opacity",value:i})},[t,n]);if(e===void 0)return null;const s=e.type==="mixed"?-1:kc.indexOf(e9(kc,i=>Math.abs(i-e.value)));return d.jsx(Hhe,{"data-testid":"style.opacity",value:s>=0?s:kc.length-1,label:e.type==="mixed"?"style-panel.mixed":`opacity-style.${e.value}`,onValueChange:o,steps:kc.length-1,title:r("style-panel.opacity")})}const epe=w.memo(function({isMobile:e,children:n}){const r=F(),o=OF(),s=w.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),i=n??d.jsx(Vhe,{styles:o});return d.jsx("div",{className:le("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:s,children:i})});function tpe(){const t=F(),e=Ce(),n=OF(),r=n==null?void 0:n.get(fr),o=ws({isDarkMode:t.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=U("disable style panel",()=>t.isInAny("hand","zoom","eraser","laser"),[t]),a=w.useCallback(c=>{c||t.updateInstanceState({isChangingStyle:!1})},[t]),{StylePanel:l}=Ii();return l?d.jsxs(Cb,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(_b,{children:d.jsx(ue,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:e("style-panel.title"),disabled:i,children:d.jsx(be,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),d.jsx(Ib,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function npe(){return d.jsxs(d.Fragment,{children:[d.jsx(ope,{}),d.jsx(spe,{}),d.jsx(ipe,{}),d.jsx(ape,{}),d.jsx(lpe,{}),d.jsx(cpe,{}),d.jsx(upe,{}),d.jsx(dpe,{}),d.jsx(hpe,{}),d.jsx(ppe,{}),d.jsx(gpe,{}),d.jsx(fpe,{}),d.jsx(Spe,{}),d.jsx(wpe,{}),d.jsx(mpe,{}),d.jsx(xpe,{}),d.jsx(vpe,{}),d.jsx(ype,{}),d.jsx(bpe,{}),d.jsx(Ppe,{}),d.jsx(Cpe,{}),d.jsx(_pe,{}),d.jsx(Ipe,{}),d.jsx(Epe,{}),d.jsx(kpe,{}),d.jsx(Tpe,{}),d.jsx(Ape,{}),d.jsx(Mpe,{})]})}function rpe(t){var r;const e=F(),n=(r=t.meta)==null?void 0:r.geo;return U("is tool selected",()=>{const o=e.getCurrentToolId(),s=e.getSharedStyles().getAsKnownValue(Vr);return n?o==="geo"&&s===n:o===t.id},[e,t.id,n])}function Ge({tool:t}){const e=ib(),n=rpe(e[t]);return d.jsx(On,{toolId:t,isSelected:n})}function ope(){return d.jsx(Ge,{tool:"select"})}function spe(){return d.jsx(Ge,{tool:"hand"})}function ipe(){return d.jsx(Ge,{tool:"draw"})}function ape(){return d.jsx(Ge,{tool:"eraser"})}function lpe(){return d.jsx(Ge,{tool:"arrow"})}function cpe(){return d.jsx(Ge,{tool:"text"})}function upe(){return d.jsx(Ge,{tool:"note"})}function dpe(){return d.jsx(On,{toolId:"asset"})}function hpe(){return d.jsx(Ge,{tool:"rectangle"})}function ppe(){return d.jsx(Ge,{tool:"ellipse"})}function fpe(){return d.jsx(Ge,{tool:"diamond"})}function gpe(){return d.jsx(Ge,{tool:"triangle"})}function mpe(){return d.jsx(Ge,{tool:"rhombus"})}function ype(){return d.jsx(Ge,{tool:"heart"})}function Spe(){return d.jsx(Ge,{tool:"hexagon"})}function vpe(){return d.jsx(Ge,{tool:"cloud"})}function xpe(){return d.jsx(Ge,{tool:"star"})}function wpe(){return d.jsx(Ge,{tool:"oval"})}function bpe(){return d.jsx(Ge,{tool:"x-box"})}function Ppe(){return d.jsx(Ge,{tool:"check-box"})}function Cpe(){return d.jsx(Ge,{tool:"arrow-left"})}function _pe(){return d.jsx(Ge,{tool:"arrow-up"})}function Ipe(){return d.jsx(Ge,{tool:"arrow-down"})}function Epe(){return d.jsx(Ge,{tool:"arrow-right"})}function kpe(){return d.jsx(Ge,{tool:"line"})}function Tpe(){return d.jsx(Ge,{tool:"highlight"})}function Mpe(){return d.jsx(Ge,{tool:"frame"})}function Ape(){return d.jsx(Ge,{tool:"laser"})}const vS=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function xS(t,e,n,r){t.addEventListener?t.addEventListener(e,n,r):t.attachEvent&&t.attachEvent("on".concat(e),n)}function Tc(t,e,n,r){t.removeEventListener?t.removeEventListener(e,n,r):t.detachEvent&&t.detachEvent("on".concat(e),n)}function YF(t,e){const n=e.slice(0,e.length-1);for(let r=0;r<n.length;r++)n[r]=t[n[r].toLowerCase()];return n}function XF(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function jpe(t,e){const n=t.length>=e.length?t:e,r=t.length>=e.length?e:t;let o=!0;for(let s=0;s<n.length;s++)r.indexOf(n[s])===-1&&(o=!1);return o}const Bu={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":vS?173:189,"=":vS?61:187,";":vS?59:186,"'":222,"[":219,"]":221,"\\":220},Oo={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},a0={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Bt={16:!1,18:!1,17:!1,91:!1},ht={};for(let t=1;t<20;t++)Bu["f".concat(t)]=111+t;let Ye=[],su=null,qF="all";const Xo=new Map,xd=t=>Bu[t.toLowerCase()]||Oo[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),Ope=t=>Object.keys(Bu).find(e=>Bu[e]===t),Dpe=t=>Object.keys(Oo).find(e=>Oo[e]===t);function ZF(t){qF=t||"all"}function Uu(){return qF||"all"}function Rpe(){return Ye.slice(0)}function Lpe(){return Ye.map(t=>Ope(t)||Dpe(t)||String.fromCharCode(t))}function $pe(){const t=[];return Object.keys(ht).forEach(e=>{ht[e].forEach(n=>{let{key:r,scope:o,mods:s,shortcut:i}=n;t.push({scope:o,shortcut:i,mods:s,keys:r.split("+").map(a=>xd(a))})})}),t}function Fpe(t){const e=t.target||t.srcElement,{tagName:n}=e;let r=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return(e.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!e.readOnly)&&(r=!1),r}function Npe(t){return typeof t=="string"&&(t=xd(t)),Ye.indexOf(t)!==-1}function zpe(t,e){let n,r;t||(t=Uu());for(const o in ht)if(Object.prototype.hasOwnProperty.call(ht,o))for(n=ht[o],r=0;r<n.length;)n[r].scope===t?n.splice(r,1).forEach(i=>{let{element:a}=i;return Mb(a)}):r++;Uu()===t&&ZF(e||"all")}function Bpe(t){let e=t.keyCode||t.which||t.charCode;const n=Ye.indexOf(e);if(n>=0&&Ye.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&Ye.splice(0,Ye.length),(e===93||e===224)&&(e=91),e in Bt){Bt[e]=!1;for(const r in Oo)Oo[r]===e&&(Un[r]=!1)}}function QF(t){if(typeof t>"u")Object.keys(ht).forEach(o=>{Array.isArray(ht[o])&&ht[o].forEach(s=>Ah(s)),delete ht[o]}),Mb(null);else if(Array.isArray(t))t.forEach(o=>{o.key&&Ah(o)});else if(typeof t=="object")t.key&&Ah(t);else if(typeof t=="string"){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];let[o,s]=n;typeof o=="function"&&(s=o,o=""),Ah({key:t,scope:o,method:s,splitKey:"+"})}}const Ah=t=>{let{key:e,scope:n,method:r,splitKey:o="+"}=t;XF(e).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":xd(c);if(!ht[u])return;n||(n=Uu());const h=l>1?YF(Oo,a):[],p=[];ht[u]=ht[u].filter(f=>{const m=(r?f.method===r:!0)&&f.scope===n&&jpe(f.mods,h);return m&&p.push(f.element),!m}),p.forEach(f=>Mb(f))})};function FE(t,e,n,r){if(e.element!==r)return;let o;if(e.scope===n||e.scope==="all"){o=e.mods.length>0;for(const s in Bt)Object.prototype.hasOwnProperty.call(Bt,s)&&(!Bt[s]&&e.mods.indexOf(+s)>-1||Bt[s]&&e.mods.indexOf(+s)===-1)&&(o=!1);(e.mods.length===0&&!Bt[16]&&!Bt[18]&&!Bt[17]&&!Bt[91]||o||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(Ye),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function NE(t,e){const n=ht["*"];let r=t.keyCode||t.which||t.charCode;if(!Un.filter.call(this,t))return;if((r===93||r===224)&&(r=91),Ye.indexOf(r)===-1&&r!==229&&Ye.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=a0[a];t[a]&&Ye.indexOf(l)===-1?Ye.push(l):!t[a]&&Ye.indexOf(l)>-1?Ye.splice(Ye.indexOf(l),1):a==="metaKey"&&t[a]&&Ye.length===3&&(t.ctrlKey||t.shiftKey||t.altKey||(Ye=Ye.slice(Ye.indexOf(l))))}),r in Bt){Bt[r]=!0;for(const a in Oo)Oo[a]===r&&(Un[a]=!0);if(!n)return}for(const a in Bt)Object.prototype.hasOwnProperty.call(Bt,a)&&(Bt[a]=t[a0[a]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(Ye.indexOf(17)===-1&&Ye.push(17),Ye.indexOf(18)===-1&&Ye.push(18),Bt[17]=!0,Bt[18]=!0);const o=Uu();if(n)for(let a=0;a<n.length;a++)n[a].scope===o&&(t.type==="keydown"&&n[a].keydown||t.type==="keyup"&&n[a].keyup)&&FE(t,n[a],o,e);if(!(r in ht))return;const s=ht[r],i=s.length;for(let a=0;a<i;a++)if((t.type==="keydown"&&s[a].keydown||t.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,u=l.key.split(c),h=[];for(let p=0;p<u.length;p++)h.push(xd(u[p]));h.sort().join("")===Ye.sort().join("")&&FE(t,l,o,e)}}function Un(t,e,n){Ye=[];const r=XF(t);let o=[],s="all",i=document,a=0,l=!1,c=!0,u="+",h=!1,p=!1;for(n===void 0&&typeof e=="function"&&(n=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(s=e.scope),e.element&&(i=e.element),e.keyup&&(l=e.keyup),e.keydown!==void 0&&(c=e.keydown),e.capture!==void 0&&(h=e.capture),typeof e.splitKey=="string"&&(u=e.splitKey),e.single===!0&&(p=!0)),typeof e=="string"&&(s=e),p&&QF(t,s);a<r.length;a++)t=r[a].split(u),o=[],t.length>1&&(o=YF(Oo,t)),t=t[t.length-1],t=t==="*"?"*":xd(t),t in ht||(ht[t]=[]),ht[t].push({keyup:l,keydown:c,scope:s,mods:o,shortcut:r[a],method:n,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!Xo.has(i)){const f=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return NE(m,i)},g=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;NE(m,i),Bpe(m)};Xo.set(i,{keydownListener:f,keyupListenr:g,capture:h}),xS(i,"keydown",f,h),xS(i,"keyup",g,h)}if(!su){const f=()=>{Ye=[]};su={listener:f,capture:h},xS(window,"focus",f,h)}}}function Upe(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ht).forEach(n=>{ht[n].filter(o=>o.scope===e&&o.shortcut===t).forEach(o=>{o&&o.method&&o.method()})})}function Mb(t){const e=Object.values(ht).flat();if(e.findIndex(r=>{let{element:o}=r;return o===t})<0){const{keydownListener:r,keyupListenr:o,capture:s}=Xo.get(t)||{};r&&o&&(Tc(t,"keyup",o,s),Tc(t,"keydown",r,s),Xo.delete(t))}if((e.length<=0||Xo.size<=0)&&(Object.keys(Xo).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=Xo.get(o)||{};s&&i&&(Tc(o,"keyup",i,a),Tc(o,"keydown",s,a),Xo.delete(o))}),Xo.clear(),Object.keys(ht).forEach(o=>delete ht[o]),su)){const{listener:o,capture:s}=su;Tc(window,"focus",o,s),su=null}}const wS={getPressedKeyString:Lpe,setScope:ZF,getScope:Uu,deleteScope:zpe,getPressedKeyCodes:Rpe,getAllKeyCodes:$pe,isPressed:Npe,filter:Fpe,trigger:Upe,unbind:QF,keyMap:Bu,modifier:Oo,modifierMap:a0};for(const t in wS)Object.prototype.hasOwnProperty.call(wS,t)&&(Un[t]=wS[t]);if(typeof window<"u"){const t=window.hotkeys;Un.noConflict=e=>(e&&window.hotkeys===Un&&(window.hotkeys=t),Un),window.hotkeys=Un}const zE=["copy","cut","paste","asset"];function Hpe(){const t=F(),e=bs(),n=Sa(),r=ib(),o=U("is focused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!o)return;const s=new Array,i=(l,c)=>{Un(l,{element:document.body},c),s.push(()=>{Un.unbind(l,c)})},a=(l,c)=>{Un(l,{element:document.body,keyup:!0,keydown:!1},c),s.push(()=>{Un.unbind(l,c)})};for(const l of Object.values(n))l.kbd&&(e&&!l.readonlyOk||zE.includes(l.id)||i(BE(l.kbd),c=>{Hc(t)||(we(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&t.getInstanceState().isReadonly||zE.includes(l.id)||i(BE(l.kbd),c=>{Hc(t)||(we(c),l.onSelect("kbd"))});return i(",",l=>{if(Hc(t)||t.inputs.keys.has("Comma"))return;we(l),t.focus(),t.inputs.keys.add("Comma");const{x:c,y:u,z:h}=t.inputs.currentPagePoint,p=t.pageToScreen({x:c,y:u}),f={type:"pointer",name:"pointer_down",point:{x:p.x,y:p.y,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(f)}),a(",",l=>{if(Hc(t)||!t.inputs.keys.has("Comma"))return;t.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=t.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(p)}),()=>{s.forEach(l=>l())}},[n,r,e,t,o])}function BE(t){return Kpe(t).map(e=>{let n="";const r=e.split("");return r.length===1?n=r[0]:r[0]==="!"?n=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?n=`alt+shift+${r[2]}`:n=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?n=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?n=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:n=`cmd+${r[1]},ctrl+${r[1]}`:n=e,n}).join(",")}function Kpe(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function Hc(t){return t.getIsMenuOpen()||t.getEditingShapeId()!==null||t.getCrashingError()}const Wpe=w.createContext(!1);function Gpe({children:t}){const e=F(),n=VA(),r=kn(),o=Ce(),s=Math.min(8,5+r),[i,a]=w.useState(0),l=w.useRef(null),[c,u]=w.useState(null),h=w.useMemo(()=>{const f=c?`:not([data-value="${c}"])`:"";return`
418
- #${n}_main > *:nth-child(n + ${s+(c?1:2)})${f} {
419
- display: none;
420
- }
421
- #${n}_more > *:nth-child(-n + ${s}) {
422
- display: none;
423
- }
424
- `},[c,n,s]),p=Og(()=>{if(!l.current)return;const f=Array.from(l.current.children);a(f.length),f.findIndex(v=>v.getAttribute("data-value")===c)<=s&&u(null);const m=Array.from(l.current.children).findIndex(v=>v.getAttribute("aria-checked")==="true");m!==-1&&m>=s&&u(f[m].getAttribute("data-value"))});return w.useLayoutEffect(()=>{p()}),w.useLayoutEffect(()=>{if(!l.current)return;const f=new MutationObserver(p);return f.observe(l.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{f.disconnect()}},[p]),w.useEffect(()=>{const f=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[g,m]of f)Un(g,v=>{var b;if(Hc(e))return;we(v);const y=Array.from(((b=l.current)==null?void 0:b.children)??[]).filter(P=>!(P instanceof HTMLElement)||P.tagName.toLowerCase()!=="button"?!1:!!(P.offsetWidth||P.offsetHeight))[m];y&&y.click()});return()=>{Un.unbind("1,2,3,4,5,6,7,8,9,0")}},[e]),d.jsxs(d.Fragment,{children:[d.jsx("style",{children:h}),d.jsxs("div",{className:le("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<Pt.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${n}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(Dr,{type:"toolbar",sourceId:"toolbar",children:t})}),i>s+1&&d.jsx(Wpe.Provider,{value:!0,children:d.jsxs(aa,{id:"toolbar overflow",modal:!1,children:[d.jsx(la,{children:d.jsx(ue,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:d.jsx(be,{icon:"chevron-up"})})}),d.jsx(ca,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx(Dr,{type:"toolbar-overflow",sourceId:"toolbar",children:t})})})]})})]})]})}function Vpe({activeToolId:t}){const e=F(),n=kn(),r=Ce(),o=U("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),s=U("current tool",()=>e.getCurrentTool(),[e]);return!t||!s.isLockable?null:d.jsx(ue,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:le("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<Pt.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!o}),children:d.jsx(be,{icon:o?"lock":"unlock",small:!0})})}const Ype=w.memo(function({children:e}){const n=F(),r=kn(),o=bs(),s=U("current tool id",()=>n.getCurrentToolId(),[n]),{ActionsMenu:i,QuickActions:a}=Ii();return d.jsx("div",{className:"tlui-toolbar",children:d.jsxs("div",{className:"tlui-toolbar__inner",children:[d.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&d.jsxs("div",{className:"tlui-toolbar__extras",children:[r<Pt.TABLET&&d.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&d.jsx(a,{}),i&&d.jsx(i,{})]}),d.jsx(Vpe,{activeToolId:s})]}),d.jsx(Gpe,{children:e??d.jsx(npe,{})})]}),r<Pt.TABLET_SM&&!o&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(tpe,{})})]})})});function Xpe(){const t=Ce();return d.jsxs("div",{className:le("tlui-offline-indicator"),children:[t("status.offline"),d.jsx(Mo,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function qpe({maxWidth:t=420,ignoreRightWidth:e=0,stylePanelWidth:n=148,marginBetweenZones:r=12,squeezeAmount:o=52,children:s}){const i=w.useRef(null),a=kn(),l=w.useCallback(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),f=u.offsetWidth,g=h.offsetWidth,m=p.offsetWidth,v=c.offsetWidth-e;let S=(f-v)/2;f%2!==0&&(S-=.5);const y=g+r,b=c.offsetLeft,P=Math.min(f-m-g-2*r,t),C=Math.max(S,y)-b;p.offsetWidth>n&&a<=6?c.style.setProperty("max-width",P-o+"px"):c.style.setProperty("max-width",P+"px"),c.style.setProperty("transform",`translate(${C}px, 0px)`)},[a,e,r,t,o,n]);return w.useLayoutEffect(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),f=new ResizeObserver(l);return f.observe(h),f.observe(p),f.observe(u),f.observe(c),l(),()=>{f.disconnect()}},[l]),w.useLayoutEffect(()=>{l()}),d.jsx("div",{ref:i,className:"tlui-top-panel__container",children:s})}function Zpe(){const t=eoe()==="offline";return d.jsx(qpe,{children:t&&d.jsx(Xpe,{})})}function Qpe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"zoom-in",noClose:!0}),d.jsx(W,{actionId:"zoom-out",noClose:!0}),d.jsx(sF,{}),d.jsx(iF,{}),d.jsx(aF,{})]})}const Jpe=w.memo(function({children:e}){const n=Lt(),[r,o]=Ps("zoom menu"),s=e??d.jsx(Qpe,{});return d.jsxs(rb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(ob,{asChild:!0,dir:"ltr",children:d.jsx(efe,{})}),d.jsx(am,{container:n,children:d.jsx(sb,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(Dr,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),efe=w.forwardRef(function(e,n){const r=F(),o=kn(),s=U("zoom",()=>r.getZoomLevel(),[r]),i=Ce(),a=w.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.jsx(ue,{ref:n,...e,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<Pt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:o<Pt.MOBILE?null:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),JF=w.createContext(null);function tfe({overrides:t={},children:e}){const n=sd(t),r=Jg();return d.jsx(JF.Provider,{value:w.useMemo(()=>({ContextMenu:mde,ActionsMenu:Hue,HelpMenu:null,ZoomMenu:Jpe,MainMenu:Qde,Minimap:lhe,StylePanel:epe,PageMenu:hhe,NavigationPanel:uhe,Toolbar:Ype,KeyboardShortcutsDialog:Nde,QuickActions:fhe,HelperButtons:$de,DebugPanel:kde,DebugMenu:Ede,MenuPanel:jde,SharePanel:r?whe:null,CursorChatBubble:r?vde:null,TopPanel:r?Zpe:null,...n}),[n,r]),children:e})}function Ii(){const t=w.useContext(JF);if(!t)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return t}function nfe({overrides:t,components:e,assetUrls:n,onUiEvent:r,forceMobile:o,mediaMimeTypes:s,children:i}){return d.jsx(C3.Provider,{value:s,children:d.jsx(Yee,{assetUrls:pue(n),children:d.jsx(Zee,{overrides:mue(t),children:d.jsx($ne,{onEvent:r,children:d.jsx(Yre,{children:d.jsx(noe,{children:d.jsx(Yie,{forceMobile:o,children:d.jsx(tfe,{overrides:e,children:d.jsx(rfe,{overrides:t,children:i})})})})})})})})})}function rfe({overrides:t,children:e}){const n=yue(t);return d.jsx(ooe,{overrides:n.actions,children:d.jsx(nae,{overrides:n.tools,children:e})})}function ofe(){const t=F(),{addToast:e}=ao();w.useEffect(()=>{function n({name:r,count:o}){e({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${o}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return t.addListener("max-shapes",n),()=>{t.removeListener("max-shapes",n)}},[t,e])}const sfe=Ie.memo(function({renderDebugMenuItems:e,children:n,hideUi:r,components:o,...s}){return d.jsx(nfe,{...s,components:o,children:d.jsx(ife,{hideUi:r,renderDebugMenuItems:e,children:n})})}),ife=Ie.memo(function({children:e,hideUi:n,...r}){return d.jsxs(d.Fragment,{children:[e,n?null:d.jsx(afe,{...r})]})}),afe=Ie.memo(function(){const e=F(),n=Ce(),r=kn(),o=bs(),s=U("focus",()=>e.getInstanceState().isFocusMode,[e]),i=U("debug",()=>e.getInstanceState().isDebugMode,[e]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:h,HelpMenu:p,NavigationPanel:f,HelperButtons:g,DebugPanel:m,CursorChatBubble:v}=Ii();Hpe(),sre(),ofe();const{"toggle-focus-mode":S}=Sa();return d.jsxs("div",{className:le("tlui-layout",{"tlui-layout__mobile":r<Pt.TABLET_SM}),"data-breakpoint":r,children:[s?d.jsx("div",{className:"tlui-layout__top",children:d.jsx(ue,{type:"icon",className:"tlui-focus-button",title:n("focus-mode.toggle-focus-mode"),onClick:()=>S.onSelect("menu"),children:d.jsx(be,{icon:"dot"})})}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"tlui-layout__top",children:[d.jsxs("div",{className:"tlui-layout__top__left",children:[c&&d.jsx(c,{}),g&&d.jsx(g,{})]}),d.jsx("div",{className:"tlui-layout__top__center",children:l&&d.jsx(l,{})}),d.jsxs("div",{className:"tlui-layout__top__right",children:[a&&d.jsx(a,{}),u&&r>=Pt.TABLET_SM&&!o&&d.jsx(u,{})]})]}),d.jsxs("div",{className:"tlui-layout__bottom",children:[d.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&d.jsx(f,{}),h&&d.jsx(h,{}),p&&d.jsx(p,{})]}),i&&m&&d.jsx(m,{})]})]}),d.jsx(uue,{}),d.jsx(oue,{}),d.jsx(due,{}),d.jsx(sue,{}),v&&d.jsx(v,{})]})});async function lfe(t,e){const{url:n,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=e,h={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c},p=new FontFace(t,`url(${n})`,h);return await p.load(),document.fonts.add(p),p.$$_url=n,p.$$_fontface=`
425
- @font-face {
426
- font-family: ${p.family};
427
- font-stretch: ${p.stretch};
428
- font-weight: ${p.weight};
429
- font-style: ${p.style};
430
- src: url("${n}") format("${u}")
431
- }`,p}const jh=(t,e)=>{const[n,r]=w.useState(2);return w.useEffect(()=>{let o=!1;return r(2),lfe(t,e).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[t,e]),n};function cfe(t){return{draw:{url:t.fonts.draw,format:t.fonts.draw.split(".").pop()},serif:{url:t.fonts.serif,format:t.fonts.serif.split(".").pop()},sansSerif:{url:t.fonts.sansSerif,format:t.fonts.sansSerif.split(".").pop()},monospace:{url:t.fonts.monospace,format:t.fonts.monospace.split(".").pop()}}}function e4(t){const e=w.useMemo(()=>cfe(t),[t]),n=[jh("tldraw_draw",e.draw),jh("tldraw_serif",e.serif),jh("tldraw_sans",e.sansSerif),jh("tldraw_mono",e.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function ufe(t){const{children:e,maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:u=[],embeds:h,...p}=t,f=sd(a),g=w.useMemo(()=>({Scribble:ZI,ShapeIndicators:pae,CollaboratorScribble:ZI,SelectionForeground:uae,SelectionBackground:lae,Handles:rae,...f}),[f]),m=Bs(l),v=w.useMemo(()=>[...Y$,...m],[m]),S=Bs(c),y=w.useMemo(()=>[...S$,...S],[S]),b=Bs(u),P=w.useMemo(()=>[...tue,...Vae,...b],[b]),C=Bs(o??ug),I=Bs(s??uw),T=w.useMemo(()=>[...C,...I],[C,I]),_=j5(p.assetUrls),{done:k,error:M}=e4(_);return M?d.jsx(xR,{children:"Could not load assets. Please refresh the page."}):k?d.jsx(Mee,{initialState:"select",...p,components:g,shapeUtils:v,bindingUtils:y,tools:P,children:d.jsxs(sfe,{...p,components:g,mediaMimeTypes:T,children:[d.jsx(dfe,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:C,acceptedVideoMimeTypes:I,onMount:i,embeds:h}),e]})}):d.jsx(m1,{children:d.jsx(e1,{})})}function dfe({maxImageDimension:t=5e3,maxAssetSize:e=10*1024*1024,acceptedImageMimeTypes:n=ug,acceptedVideoMimeTypes:r=uw,onMount:o,embeds:s}){const i=F(),a=ao(),l=Ce();wR(()=>{const h=i.getShapeUtil("embed");h&&s&&h.setEmbedDefinitions(s);const p=[];return p.push(_ce(i)),Mae(i,{maxImageDimension:t,maxAssetSize:e,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:a,msg:l}),p.push(i.store.props.onMount(i)),p.push(o==null?void 0:o(i)),()=>{p.forEach(f=>f==null?void 0:f())}});const{Canvas:c}=rt(),{ContextMenu:u}=Ii();return u?d.jsx(u,{}):c?d.jsx(c,{}):null}w.memo(function(e){const[n,r]=w.useState(null),[o,s]=w.useState(null),i=Bs(e.shapeUtils??[]),a=w.useMemo(()=>[...Y$,...i],[i]),l=Bs(e.bindingUtils??[]),c=w.useMemo(()=>[...S$,...l],[l]),u=Lee({snapshot:e.snapshot,shapeUtils:a}),h=j5(e.assetUrls),{done:p,error:f}=e4(h),{pageId:g,bounds:m,scale:v,background:S,padding:y,darkMode:b,preserveAspectRatio:P,format:C="svg",licenseKey:I}=e;return w.useLayoutEffect(()=>{if(!o||!u||!p)return;let T=!1;const _=document.createElement("div");o.appendChild(_),o.classList.add("tl-container","tl-theme__light");const k=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>_,licenseKey:I});g&&k.setCurrentPage(g);const M=k.getCurrentPageShapeIds();async function R(){const j=await k.getSvgString([...M],{bounds:m,scale:v,background:S,padding:y,darkMode:b,preserveAspectRatio:P});if(j&&!T){if(C==="svg"){if(!T){const O=new Blob([j.svg],{type:"image/svg+xml"}),D=URL.createObjectURL(O);r(D)}}else if(C==="png"){const O=await a3(k,j.svg,{type:C,quality:1,scale:2,width:j.width,height:j.height});if(O&&!T){const D=URL.createObjectURL(O);r(D)}}}k.dispose()}return R(),()=>{T=!0}},[C,o,u,a,c,g,m,v,S,y,b,P,p,f,I]),f?d.jsx(xR,{children:"Could not load assets."}):p?d.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:n&&d.jsx("img",{src:n,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):d.jsx(m1,{children:d.jsx(e1,{})})});w.memo(function({children:e}){const n=Ce(),r=kn(),o=e??d.jsx(Ude,{});return r<Pt.MOBILE?null:d.jsx("div",{className:"tlui-help-menu",children:d.jsxs(aa,{id:"help menu",children:[d.jsx(la,{children:d.jsx(ue,{type:"help",title:n("help-menu.title"),"data-testid":"help-menu.button",children:d.jsx(be,{icon:"question-mark",small:!0})})}),d.jsx(ca,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(Dr,{type:"menu",sourceId:"help-menu",children:o})})]})})});const hfe=1,pfe=Pe({schemaVersion:pn(1),storeVersion:qh,recordVersions:mf(me,Pe({version:qh,subTypeVersions:mf(me,qh).optional(),subTypeKey:me.optional()}))}),ffe=Pe({schemaVersion:pn(2),sequences:mf(me,qh)}),gfe=Pe({tldrawFileFormatVersion:hV,schema:pV("schemaVersion",{1:pfe,2:ffe}),records:Kt(Pe({id:me,typeName:me}).allowUnknownProperties())});function mfe(t){var e;try{return!!((e=t.document)!=null&&e.version)}catch{return!1}}function yfe({json:t,schema:e}){let n;try{n=gfe.validate(JSON.parse(t))}catch(s){try{if(n=JSON.parse(t),mfe(n))return Sn.err({type:"v1File",data:n})}catch{}return Sn.err({type:"notATldrawFile",cause:s})}if(n.tldrawFileFormatVersion>hfe)return Sn.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r,o;try{const s=Sfe(n.records);o=Object.fromEntries(s.map(i=>[i.id,i])),r=e.migrateStoreSnapshot({store:o,schema:n.schema})}catch(s){return Sn.err({type:"invalidRecords",cause:s})}if(r.type==="error")return Sn.err({type:"migrationFailed",reason:r.reason});try{return Sn.ok(Ou({snapshot:{store:o,schema:n.schema},schema:e}))}catch(s){return Sn.err({type:"invalidRecords",cause:s})}}function Sfe(t){const e=new Set;for(const n of t)n.typeName==="shape"&&"assetId"in n.props&&n.props.assetId&&e.add(n.props.assetId);return t.filter(n=>n.typeName!=="asset"||e.has(n.id))}Si("tldraw","3.2.0","esm");function vfe(){const[t,e]=w.useState();function n(r){window.editor=r,t===void 0?fetch("/tldr-data").then(async o=>{if(!o.ok){console.log(`No tldr data to load from local endpoint (${o.status})`);return}return o.text()}).then(o=>{if(o===void 0)return;const s=yfe({json:o,schema:r.store.schema});s.ok?(console.log("Loaded tldr file from local endpoint"),e(s.value)):console.error(`Couldn't parse tldr file: ${String(s.error.type)}`)}).catch(o=>{console.error("Couldn't fetch data:",o)}):(r.zoomToFit(),r.clearOpenMenus())}return d.jsx("div",{style:{inset:0,position:"fixed"},children:d.jsx(ufe,{assetUrls:Lz(),onMount:n,store:t})})}US.createRoot(document.querySelector("#root")).render(d.jsx(Ie.StrictMode,{children:d.jsx(vfe,{})}));