@kitschpatrol/tldraw-cli 4.6.25 → 4.6.27

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,425 +0,0 @@
1
- var LN=Object.defineProperty;var $N=(t,e,n)=>e in t?LN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var I=(t,e,n)=>$N(t,typeof e!="symbol"?e+"":e,n);function FN(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 dn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function xi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var f2={exports:{}},tg={},g2={exports:{}},Ie={};/**
2
- * @license React
3
- * react.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var Ju=Symbol.for("react.element"),NN=Symbol.for("react.portal"),zN=Symbol.for("react.fragment"),BN=Symbol.for("react.strict_mode"),UN=Symbol.for("react.profiler"),HN=Symbol.for("react.provider"),KN=Symbol.for("react.context"),WN=Symbol.for("react.forward_ref"),GN=Symbol.for("react.suspense"),VN=Symbol.for("react.memo"),YN=Symbol.for("react.lazy"),yP=Symbol.iterator;function XN(t){return t===null||typeof t!="object"?null:(t=yP&&t[yP]||t["@@iterator"],typeof t=="function"?t:null)}var m2={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},y2=Object.assign,S2={};function Ul(t,e,n){this.props=t,this.context=e,this.refs=S2,this.updater=n||m2}Ul.prototype.isReactComponent={};Ul.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")};Ul.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function v2(){}v2.prototype=Ul.prototype;function v0(t,e,n){this.props=t,this.context=e,this.refs=S2,this.updater=n||m2}var x0=v0.prototype=new v2;x0.constructor=v0;y2(x0,Ul.prototype);x0.isPureReactComponent=!0;var SP=Array.isArray,x2=Object.prototype.hasOwnProperty,w0={current:null},w2={key:!0,ref:!0,__self:!0,__source:!0};function b2(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)x2.call(e,r)&&!w2.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:Ju,type:t,key:s,ref:i,props:o,_owner:w0.current}}function qN(t,e){return{$$typeof:Ju,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}function b0(t){return typeof t=="object"&&t!==null&&t.$$typeof===Ju}function ZN(t){var e={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(n){return e[n]})}var vP=/\/+/g;function $m(t,e){return typeof t=="object"&&t!==null&&t.key!=null?ZN(""+t.key):e.toString(36)}function Hh(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 Ju:case NN:i=!0}}if(i)return i=t,o=o(i),t=r===""?"."+$m(i,0):r,SP(o)?(n="",t!=null&&(n=t.replace(vP,"$&/")+"/"),Hh(o,e,n,"",function(c){return c})):o!=null&&(b0(o)&&(o=qN(o,n+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(vP,"$&/")+"/")+t)),e.push(o)),1;if(i=0,r=r===""?".":r+":",SP(t))for(var a=0;a<t.length;a++){s=t[a];var l=r+$m(s,a);i+=Hh(s,e,n,l,o)}else if(l=XN(t),typeof l=="function")for(t=l.call(t),a=0;!(s=t.next()).done;)s=s.value,l=r+$m(s,a++),i+=Hh(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 Nd(t,e,n){if(t==null)return t;var r=[],o=0;return Hh(t,r,"","",function(s){return e.call(n,s,o++)}),r}function QN(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 Cn={current:null},Kh={transition:null},JN={ReactCurrentDispatcher:Cn,ReactCurrentBatchConfig:Kh,ReactCurrentOwner:w0};function P2(){throw Error("act(...) is not supported in production builds of React.")}Ie.Children={map:Nd,forEach:function(t,e,n){Nd(t,function(){e.apply(this,arguments)},n)},count:function(t){var e=0;return Nd(t,function(){e++}),e},toArray:function(t){return Nd(t,function(e){return e})||[]},only:function(t){if(!b0(t))throw Error("React.Children.only expected to receive a single React element child.");return t}};Ie.Component=Ul;Ie.Fragment=zN;Ie.Profiler=UN;Ie.PureComponent=v0;Ie.StrictMode=BN;Ie.Suspense=GN;Ie.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=JN;Ie.act=P2;Ie.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=y2({},t.props),o=t.key,s=t.ref,i=t._owner;if(e!=null){if(e.ref!==void 0&&(s=e.ref,i=w0.current),e.key!==void 0&&(o=""+e.key),t.type&&t.type.defaultProps)var a=t.type.defaultProps;for(l in e)x2.call(e,l)&&!w2.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:Ju,type:t.type,key:o,ref:s,props:r,_owner:i}};Ie.createContext=function(t){return t={$$typeof:KN,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},t.Provider={$$typeof:HN,_context:t},t.Consumer=t};Ie.createElement=b2;Ie.createFactory=function(t){var e=b2.bind(null,t);return e.type=t,e};Ie.createRef=function(){return{current:null}};Ie.forwardRef=function(t){return{$$typeof:WN,render:t}};Ie.isValidElement=b0;Ie.lazy=function(t){return{$$typeof:YN,_payload:{_status:-1,_result:t},_init:QN}};Ie.memo=function(t,e){return{$$typeof:VN,type:t,compare:e===void 0?null:e}};Ie.startTransition=function(t){var e=Kh.transition;Kh.transition={};try{t()}finally{Kh.transition=e}};Ie.unstable_act=P2;Ie.useCallback=function(t,e){return Cn.current.useCallback(t,e)};Ie.useContext=function(t){return Cn.current.useContext(t)};Ie.useDebugValue=function(){};Ie.useDeferredValue=function(t){return Cn.current.useDeferredValue(t)};Ie.useEffect=function(t,e){return Cn.current.useEffect(t,e)};Ie.useId=function(){return Cn.current.useId()};Ie.useImperativeHandle=function(t,e,n){return Cn.current.useImperativeHandle(t,e,n)};Ie.useInsertionEffect=function(t,e){return Cn.current.useInsertionEffect(t,e)};Ie.useLayoutEffect=function(t,e){return Cn.current.useLayoutEffect(t,e)};Ie.useMemo=function(t,e){return Cn.current.useMemo(t,e)};Ie.useReducer=function(t,e,n){return Cn.current.useReducer(t,e,n)};Ie.useRef=function(t){return Cn.current.useRef(t)};Ie.useState=function(t){return Cn.current.useState(t)};Ie.useSyncExternalStore=function(t,e,n){return Cn.current.useSyncExternalStore(t,e,n)};Ie.useTransition=function(){return Cn.current.useTransition()};Ie.version="18.3.1";g2.exports=Ie;var w=g2.exports;const Te=xi(w),e6=FN({__proto__:null,default:Te},[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 t6=w,n6=Symbol.for("react.element"),r6=Symbol.for("react.fragment"),o6=Object.prototype.hasOwnProperty,s6=t6.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i6={key:!0,ref:!0,__self:!0,__source:!0};function C2(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)o6.call(e,r)&&!i6.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:n6,type:t,key:s,ref:i,props:o,_owner:s6.current}}tg.Fragment=r6;tg.jsx=C2;tg.jsxs=C2;f2.exports=tg;var d=f2.exports,QS={},_2={exports:{}},Sr={},I2={exports:{}},E2={};/**
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(R,H){var Y=R.length;R.push(H);e:for(;0<Y;){var ee=Y-1>>>1,he=R[ee];if(0<o(he,H))R[ee]=H,R[Y]=he,Y=ee;else break e}}function n(R){return R.length===0?null:R[0]}function r(R){if(R.length===0)return null;var H=R[0],Y=R.pop();if(Y!==H){R[0]=Y;e:for(var ee=0,he=R.length,ue=he>>>1;ee<ue;){var ke=2*(ee+1)-1,se=R[ke],We=ke+1,Fe=R[We];if(0>o(se,Y))We<he&&0>o(Fe,se)?(R[ee]=Fe,R[We]=Y,ee=We):(R[ee]=se,R[ke]=Y,ee=ke);else if(We<he&&0>o(Fe,Y))R[ee]=Fe,R[We]=Y,ee=We;else break e}}return H}function o(R,H){var Y=R.sortIndex-H.sortIndex;return Y!==0?Y:R.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,y=typeof clearTimeout=="function"?clearTimeout:null,S=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(R){for(var H=n(c);H!==null;){if(H.callback===null)r(c);else if(H.startTime<=R)r(c),H.sortIndex=H.expirationTime,e(l,H);else break;H=n(c)}}function P(R){if(m=!1,b(R),!g)if(n(l)!==null)g=!0,B(C);else{var H=n(c);H!==null&&K(P,H.startTime-R)}}function C(R,H){g=!1,m&&(m=!1,y(k),k=-1),f=!0;var Y=p;try{for(b(H),h=n(l);h!==null&&(!(h.expirationTime>H)||R&&!j());){var ee=h.callback;if(typeof ee=="function"){h.callback=null,p=h.priorityLevel;var he=ee(h.expirationTime<=H);H=t.unstable_now(),typeof he=="function"?h.callback=he:h===n(l)&&r(l),b(H)}else r(l);h=n(l)}if(h!==null)var ue=!0;else{var ke=n(c);ke!==null&&K(P,ke.startTime-H),ue=!1}return ue}finally{h=null,p=Y,f=!1}}var _=!1,E=null,k=-1,D=5,T=-1;function j(){return!(t.unstable_now()-T<D)}function $(){if(E!==null){var R=t.unstable_now();T=R;var H=!0;try{H=E(!0,R)}finally{H?M():(_=!1,E=null)}}else _=!1}var M;if(typeof S=="function")M=function(){S($)};else if(typeof MessageChannel<"u"){var O=new MessageChannel,F=O.port2;O.port1.onmessage=$,M=function(){F.postMessage(null)}}else M=function(){v($,0)};function B(R){E=R,_||(_=!0,M())}function K(R,H){k=v(function(){R(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(R){R.callback=null},t.unstable_continueExecution=function(){g||f||(g=!0,B(C))},t.unstable_forceFrameRate=function(R){0>R||125<R?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):D=0<R?Math.floor(1e3/R):5},t.unstable_getCurrentPriorityLevel=function(){return p},t.unstable_getFirstCallbackNode=function(){return n(l)},t.unstable_next=function(R){switch(p){case 1:case 2:case 3:var H=3;break;default:H=p}var Y=p;p=H;try{return R()}finally{p=Y}},t.unstable_pauseExecution=function(){},t.unstable_requestPaint=function(){},t.unstable_runWithPriority=function(R,H){switch(R){case 1:case 2:case 3:case 4:case 5:break;default:R=3}var Y=p;p=R;try{return H()}finally{p=Y}},t.unstable_scheduleCallback=function(R,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,R){case 1:var he=-1;break;case 2:he=250;break;case 5:he=1073741823;break;case 4:he=1e4;break;default:he=5e3}return he=Y+he,R={id:u++,callback:H,priorityLevel:R,startTime:Y,expirationTime:he,sortIndex:-1},Y>ee?(R.sortIndex=Y,e(c,R),n(l)===null&&R===n(c)&&(m?(y(k),k=-1):m=!0,K(P,Y-ee))):(R.sortIndex=he,e(l,R),g||f||(g=!0,B(C))),R},t.unstable_shouldYield=j,t.unstable_wrapCallback=function(R){var H=p;return function(){var Y=p;p=H;try{return R.apply(this,arguments)}finally{p=Y}}}})(E2);I2.exports=E2;var a6=I2.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 l6=w,fr=a6;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 k2=new Set,yu={};function va(t,e){Il(t,e),Il(t+"Capture",e)}function Il(t,e){for(yu[t]=e,t=0;t<e.length;t++)k2.add(e[t])}var Ss=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),JS=Object.prototype.hasOwnProperty,c6=/^[: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]*$/,xP={},wP={};function u6(t){return JS.call(wP,t)?!0:JS.call(xP,t)?!1:c6.test(t)?wP[t]=!0:(xP[t]=!0,!1)}function d6(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 h6(t,e,n,r){if(e===null||typeof e>"u"||d6(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 _n(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 _n(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 _n(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){Yt[t]=new _n(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){Yt[t]=new _n(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 _n(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){Yt[t]=new _n(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){Yt[t]=new _n(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){Yt[t]=new _n(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){Yt[t]=new _n(t,5,!1,t.toLowerCase(),null,!1,!1)});var P0=/[\-:]([a-z])/g;function C0(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(P0,C0);Yt[e]=new _n(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(P0,C0);Yt[e]=new _n(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(P0,C0);Yt[e]=new _n(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){Yt[t]=new _n(t,1,!1,t.toLowerCase(),null,!1,!1)});Yt.xlinkHref=new _n("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){Yt[t]=new _n(t,1,!1,t.toLowerCase(),null,!0,!0)});function _0(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")&&(h6(e,n,o,r)&&(n=null),r||o===null?u6(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 _s=l6.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,zd=Symbol.for("react.element"),Wa=Symbol.for("react.portal"),Ga=Symbol.for("react.fragment"),I0=Symbol.for("react.strict_mode"),ev=Symbol.for("react.profiler"),T2=Symbol.for("react.provider"),M2=Symbol.for("react.context"),E0=Symbol.for("react.forward_ref"),tv=Symbol.for("react.suspense"),nv=Symbol.for("react.suspense_list"),k0=Symbol.for("react.memo"),Hs=Symbol.for("react.lazy"),A2=Symbol.for("react.offscreen"),bP=Symbol.iterator;function fc(t){return t===null||typeof t!="object"?null:(t=bP&&t[bP]||t["@@iterator"],typeof t=="function"?t:null)}var gt=Object.assign,Fm;function Nc(t){if(Fm===void 0)try{throw Error()}catch(n){var e=n.stack.trim().match(/\n( *(at )?)/);Fm=e&&e[1]||""}return`
34
- `+Fm+t}var Nm=!1;function zm(t,e){if(!t||Nm)return"";Nm=!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{Nm=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?Nc(t):""}function p6(t){switch(t.tag){case 5:return Nc(t.type);case 16:return Nc("Lazy");case 13:return Nc("Suspense");case 19:return Nc("SuspenseList");case 0:case 2:case 15:return t=zm(t.type,!1),t;case 11:return t=zm(t.type.render,!1),t;case 1:return t=zm(t.type,!0),t;default:return""}}function rv(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 Ga:return"Fragment";case Wa:return"Portal";case ev:return"Profiler";case I0:return"StrictMode";case tv:return"Suspense";case nv:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case M2:return(t.displayName||"Context")+".Consumer";case T2:return(t._context.displayName||"Context")+".Provider";case E0:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case k0:return e=t.displayName||null,e!==null?e:rv(t.type)||"Memo";case Hs:e=t._payload,t=t._init;try{return rv(t(e))}catch{}}return null}function f6(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 rv(e);case 8:return e===I0?"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 hi(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function j2(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function g6(t){var e=j2(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 Bd(t){t._valueTracker||(t._valueTracker=g6(t))}function O2(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=j2(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Fp(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 ov(t,e){var n=e.checked;return gt({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function PP(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=hi(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 D2(t,e){e=e.checked,e!=null&&_0(t,"checked",e,!1)}function sv(t,e){D2(t,e);var n=hi(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")?iv(t,e.type,n):e.hasOwnProperty("defaultValue")&&iv(t,e.type,hi(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function CP(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 iv(t,e,n){(e!=="number"||Fp(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var zc=Array.isArray;function pl(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=""+hi(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 av(t,e){if(e.dangerouslySetInnerHTML!=null)throw Error(X(91));return gt({},e,{value:void 0,defaultValue:void 0,children:""+t._wrapperState.initialValue})}function _P(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(zc(n)){if(1<n.length)throw Error(X(93));n=n[0]}e=n}e==null&&(e=""),n=e}t._wrapperState={initialValue:hi(n)}}function R2(t,e){var n=hi(e.value),r=hi(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 IP(t){var e=t.textContent;e===t._wrapperState.initialValue&&e!==""&&e!==null&&(t.value=e)}function L2(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 lv(t,e){return t==null||t==="http://www.w3.org/1999/xhtml"?L2(e):t==="http://www.w3.org/2000/svg"&&e==="foreignObject"?"http://www.w3.org/1999/xhtml":t}var Ud,$2=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(Ud=Ud||document.createElement("div"),Ud.innerHTML="<svg>"+e.valueOf().toString()+"</svg>",e=Ud.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function Su(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Jc={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},m6=["Webkit","ms","Moz","O"];Object.keys(Jc).forEach(function(t){m6.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Jc[e]=Jc[t]})});function F2(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Jc.hasOwnProperty(t)&&Jc[t]?(""+e).trim():e+"px"}function N2(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=F2(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,o):t[n]=o}}var y6=gt({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 cv(t,e){if(e){if(y6[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 uv(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 dv=null;function T0(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var hv=null,fl=null,gl=null;function EP(t){if(t=nd(t)){if(typeof hv!="function")throw Error(X(280));var e=t.stateNode;e&&(e=ig(e),hv(t.stateNode,t.type,e))}}function z2(t){fl?gl?gl.push(t):gl=[t]:fl=t}function B2(){if(fl){var t=fl,e=gl;if(gl=fl=null,EP(t),e)for(t=0;t<e.length;t++)EP(e[t])}}function U2(t,e){return t(e)}function H2(){}var Bm=!1;function K2(t,e,n){if(Bm)return t(e,n);Bm=!0;try{return U2(t,e,n)}finally{Bm=!1,(fl!==null||gl!==null)&&(H2(),B2())}}function vu(t,e){var n=t.stateNode;if(n===null)return null;var r=ig(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 pv=!1;if(Ss)try{var gc={};Object.defineProperty(gc,"passive",{get:function(){pv=!0}}),window.addEventListener("test",gc,gc),window.removeEventListener("test",gc,gc)}catch{pv=!1}function S6(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 eu=!1,Np=null,zp=!1,fv=null,v6={onError:function(t){eu=!0,Np=t}};function x6(t,e,n,r,o,s,i,a,l){eu=!1,Np=null,S6.apply(v6,arguments)}function w6(t,e,n,r,o,s,i,a,l){if(x6.apply(this,arguments),eu){if(eu){var c=Np;eu=!1,Np=null}else throw Error(X(198));zp||(zp=!0,fv=c)}}function xa(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 W2(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 kP(t){if(xa(t)!==t)throw Error(X(188))}function b6(t){var e=t.alternate;if(!e){if(e=xa(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 kP(o),t;if(s===r)return kP(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 G2(t){return t=b6(t),t!==null?V2(t):null}function V2(t){if(t.tag===5||t.tag===6)return t;for(t=t.child;t!==null;){var e=V2(t);if(e!==null)return e;t=t.sibling}return null}var Y2=fr.unstable_scheduleCallback,TP=fr.unstable_cancelCallback,P6=fr.unstable_shouldYield,C6=fr.unstable_requestPaint,wt=fr.unstable_now,_6=fr.unstable_getCurrentPriorityLevel,M0=fr.unstable_ImmediatePriority,X2=fr.unstable_UserBlockingPriority,Bp=fr.unstable_NormalPriority,I6=fr.unstable_LowPriority,q2=fr.unstable_IdlePriority,ng=null,Mo=null;function E6(t){if(Mo&&typeof Mo.onCommitFiberRoot=="function")try{Mo.onCommitFiberRoot(ng,t,void 0,(t.current.flags&128)===128)}catch{}}var eo=Math.clz32?Math.clz32:M6,k6=Math.log,T6=Math.LN2;function M6(t){return t>>>=0,t===0?32:31-(k6(t)/T6|0)|0}var Hd=64,Kd=4194304;function Bc(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 Up(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=Bc(a):(s&=i,s!==0&&(r=Bc(s)))}else i=n&~o,i!==0?r=Bc(i):s!==0&&(r=Bc(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-eo(e),o=1<<n,r|=t[n],e&=~o;return r}function A6(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 j6(t,e){for(var n=t.suspendedLanes,r=t.pingedLanes,o=t.expirationTimes,s=t.pendingLanes;0<s;){var i=31-eo(s),a=1<<i,l=o[i];l===-1?(!(a&n)||a&r)&&(o[i]=A6(a,e)):l<=e&&(t.expiredLanes|=a),s&=~a}}function gv(t){return t=t.pendingLanes&-1073741825,t!==0?t:t&1073741824?1073741824:0}function Z2(){var t=Hd;return Hd<<=1,!(Hd&4194240)&&(Hd=64),t}function Um(t){for(var e=[],n=0;31>n;n++)e.push(t);return e}function ed(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-eo(e),t[e]=n}function O6(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-eo(n),s=1<<o;e[o]=0,r[o]=-1,t[o]=-1,n&=~s}}function A0(t,e){var n=t.entangledLanes|=e;for(t=t.entanglements;n;){var r=31-eo(n),o=1<<r;o&e|t[r]&e&&(t[r]|=e),n&=~o}}var Be=0;function Q2(t){return t&=-t,1<t?4<t?t&268435455?16:536870912:4:1}var J2,j0,ek,tk,nk,mv=!1,Wd=[],ti=null,ni=null,ri=null,xu=new Map,wu=new Map,Ws=[],D6="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 MP(t,e){switch(t){case"focusin":case"focusout":ti=null;break;case"dragenter":case"dragleave":ni=null;break;case"mouseover":case"mouseout":ri=null;break;case"pointerover":case"pointerout":xu.delete(e.pointerId);break;case"gotpointercapture":case"lostpointercapture":wu.delete(e.pointerId)}}function mc(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=nd(e),e!==null&&j0(e)),t):(t.eventSystemFlags|=r,e=t.targetContainers,o!==null&&e.indexOf(o)===-1&&e.push(o),t)}function R6(t,e,n,r,o){switch(e){case"focusin":return ti=mc(ti,t,e,n,r,o),!0;case"dragenter":return ni=mc(ni,t,e,n,r,o),!0;case"mouseover":return ri=mc(ri,t,e,n,r,o),!0;case"pointerover":var s=o.pointerId;return xu.set(s,mc(xu.get(s)||null,t,e,n,r,o)),!0;case"gotpointercapture":return s=o.pointerId,wu.set(s,mc(wu.get(s)||null,t,e,n,r,o)),!0}return!1}function rk(t){var e=Wi(t.target);if(e!==null){var n=xa(e);if(n!==null){if(e=n.tag,e===13){if(e=W2(n),e!==null){t.blockedOn=e,nk(t.priority,function(){ek(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 Wh(t){if(t.blockedOn!==null)return!1;for(var e=t.targetContainers;0<e.length;){var n=yv(t.domEventName,t.eventSystemFlags,e[0],t.nativeEvent);if(n===null){n=t.nativeEvent;var r=new n.constructor(n.type,n);dv=r,n.target.dispatchEvent(r),dv=null}else return e=nd(n),e!==null&&j0(e),t.blockedOn=n,!1;e.shift()}return!0}function AP(t,e,n){Wh(t)&&n.delete(e)}function L6(){mv=!1,ti!==null&&Wh(ti)&&(ti=null),ni!==null&&Wh(ni)&&(ni=null),ri!==null&&Wh(ri)&&(ri=null),xu.forEach(AP),wu.forEach(AP)}function yc(t,e){t.blockedOn===e&&(t.blockedOn=null,mv||(mv=!0,fr.unstable_scheduleCallback(fr.unstable_NormalPriority,L6)))}function bu(t){function e(o){return yc(o,t)}if(0<Wd.length){yc(Wd[0],t);for(var n=1;n<Wd.length;n++){var r=Wd[n];r.blockedOn===t&&(r.blockedOn=null)}}for(ti!==null&&yc(ti,t),ni!==null&&yc(ni,t),ri!==null&&yc(ri,t),xu.forEach(e),wu.forEach(e),n=0;n<Ws.length;n++)r=Ws[n],r.blockedOn===t&&(r.blockedOn=null);for(;0<Ws.length&&(n=Ws[0],n.blockedOn===null);)rk(n),n.blockedOn===null&&Ws.shift()}var ml=_s.ReactCurrentBatchConfig,Hp=!0;function $6(t,e,n,r){var o=Be,s=ml.transition;ml.transition=null;try{Be=1,O0(t,e,n,r)}finally{Be=o,ml.transition=s}}function F6(t,e,n,r){var o=Be,s=ml.transition;ml.transition=null;try{Be=4,O0(t,e,n,r)}finally{Be=o,ml.transition=s}}function O0(t,e,n,r){if(Hp){var o=yv(t,e,n,r);if(o===null)Qm(t,e,r,Kp,n),MP(t,r);else if(R6(o,t,e,n,r))r.stopPropagation();else if(MP(t,r),e&4&&-1<D6.indexOf(t)){for(;o!==null;){var s=nd(o);if(s!==null&&J2(s),s=yv(t,e,n,r),s===null&&Qm(t,e,r,Kp,n),s===o)break;o=s}o!==null&&r.stopPropagation()}else Qm(t,e,r,null,n)}}var Kp=null;function yv(t,e,n,r){if(Kp=null,t=T0(r),t=Wi(t),t!==null)if(e=xa(t),e===null)t=null;else if(n=e.tag,n===13){if(t=W2(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 Kp=t,null}function ok(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(_6()){case M0:return 1;case X2:return 4;case Bp:case I6:return 16;case q2:return 536870912;default:return 16}default:return 16}}var qs=null,D0=null,Gh=null;function sk(){if(Gh)return Gh;var t,e=D0,n=e.length,r,o="value"in qs?qs.value:qs.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 Gh=o.slice(t,1<r?1-r:void 0)}function Vh(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 Gd(){return!0}function jP(){return!1}function vr(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)?Gd:jP,this.isPropagationStopped=jP,this}return gt(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=Gd)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=Gd)},persist:function(){},isPersistent:Gd}),e}var Hl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(t){return t.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},R0=vr(Hl),td=gt({},Hl,{view:0,detail:0}),N6=vr(td),Hm,Km,Sc,rg=gt({},td,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:L0,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!==Sc&&(Sc&&t.type==="mousemove"?(Hm=t.screenX-Sc.screenX,Km=t.screenY-Sc.screenY):Km=Hm=0,Sc=t),Hm)},movementY:function(t){return"movementY"in t?t.movementY:Km}}),OP=vr(rg),z6=gt({},rg,{dataTransfer:0}),B6=vr(z6),U6=gt({},td,{relatedTarget:0}),Wm=vr(U6),H6=gt({},Hl,{animationName:0,elapsedTime:0,pseudoElement:0}),K6=vr(H6),W6=gt({},Hl,{clipboardData:function(t){return"clipboardData"in t?t.clipboardData:window.clipboardData}}),G6=vr(W6),V6=gt({},Hl,{data:0}),DP=vr(V6),Y6={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},X6={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"},q6={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function Z6(t){var e=this.nativeEvent;return e.getModifierState?e.getModifierState(t):(t=q6[t])?!!e[t]:!1}function L0(){return Z6}var Q6=gt({},td,{key:function(t){if(t.key){var e=Y6[t.key]||t.key;if(e!=="Unidentified")return e}return t.type==="keypress"?(t=Vh(t),t===13?"Enter":String.fromCharCode(t)):t.type==="keydown"||t.type==="keyup"?X6[t.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:L0,charCode:function(t){return t.type==="keypress"?Vh(t):0},keyCode:function(t){return t.type==="keydown"||t.type==="keyup"?t.keyCode:0},which:function(t){return t.type==="keypress"?Vh(t):t.type==="keydown"||t.type==="keyup"?t.keyCode:0}}),J6=vr(Q6),ez=gt({},rg,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),RP=vr(ez),tz=gt({},td,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:L0}),nz=vr(tz),rz=gt({},Hl,{propertyName:0,elapsedTime:0,pseudoElement:0}),oz=vr(rz),sz=gt({},rg,{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}),iz=vr(sz),az=[9,13,27,32],$0=Ss&&"CompositionEvent"in window,tu=null;Ss&&"documentMode"in document&&(tu=document.documentMode);var lz=Ss&&"TextEvent"in window&&!tu,ik=Ss&&(!$0||tu&&8<tu&&11>=tu),LP=" ",$P=!1;function ak(t,e){switch(t){case"keyup":return az.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function lk(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var Va=!1;function cz(t,e){switch(t){case"compositionend":return lk(e);case"keypress":return e.which!==32?null:($P=!0,LP);case"textInput":return t=e.data,t===LP&&$P?null:t;default:return null}}function uz(t,e){if(Va)return t==="compositionend"||!$0&&ak(t,e)?(t=sk(),Gh=D0=qs=null,Va=!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 ik&&e.locale!=="ko"?null:e.data;default:return null}}var dz={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 FP(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e==="input"?!!dz[t.type]:e==="textarea"}function ck(t,e,n,r){z2(r),e=Wp(e,"onChange"),0<e.length&&(n=new R0("onChange","change",null,n,r),t.push({event:n,listeners:e}))}var nu=null,Pu=null;function hz(t){xk(t,0)}function og(t){var e=qa(t);if(O2(e))return t}function pz(t,e){if(t==="change")return e}var uk=!1;if(Ss){var Gm;if(Ss){var Vm="oninput"in document;if(!Vm){var NP=document.createElement("div");NP.setAttribute("oninput","return;"),Vm=typeof NP.oninput=="function"}Gm=Vm}else Gm=!1;uk=Gm&&(!document.documentMode||9<document.documentMode)}function zP(){nu&&(nu.detachEvent("onpropertychange",dk),Pu=nu=null)}function dk(t){if(t.propertyName==="value"&&og(Pu)){var e=[];ck(e,Pu,t,T0(t)),K2(hz,e)}}function fz(t,e,n){t==="focusin"?(zP(),nu=e,Pu=n,nu.attachEvent("onpropertychange",dk)):t==="focusout"&&zP()}function gz(t){if(t==="selectionchange"||t==="keyup"||t==="keydown")return og(Pu)}function mz(t,e){if(t==="click")return og(e)}function yz(t,e){if(t==="input"||t==="change")return og(e)}function Sz(t,e){return t===e&&(t!==0||1/t===1/e)||t!==t&&e!==e}var so=typeof Object.is=="function"?Object.is:Sz;function Cu(t,e){if(so(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(!JS.call(e,o)||!so(t[o],e[o]))return!1}return!0}function BP(t){for(;t&&t.firstChild;)t=t.firstChild;return t}function UP(t,e){var n=BP(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=BP(n)}}function hk(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?hk(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function pk(){for(var t=window,e=Fp();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Fp(t.document)}return e}function F0(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 vz(t){var e=pk(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&hk(n.ownerDocument.documentElement,n)){if(r!==null&&F0(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=UP(n,s);var i=UP(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 xz=Ss&&"documentMode"in document&&11>=document.documentMode,Ya=null,Sv=null,ru=null,vv=!1;function HP(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;vv||Ya==null||Ya!==Fp(r)||(r=Ya,"selectionStart"in r&&F0(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}),ru&&Cu(ru,r)||(ru=r,r=Wp(Sv,"onSelect"),0<r.length&&(e=new R0("onSelect","select",null,e,n),t.push({event:e,listeners:r}),e.target=Ya)))}function Vd(t,e){var n={};return n[t.toLowerCase()]=e.toLowerCase(),n["Webkit"+t]="webkit"+e,n["Moz"+t]="moz"+e,n}var Xa={animationend:Vd("Animation","AnimationEnd"),animationiteration:Vd("Animation","AnimationIteration"),animationstart:Vd("Animation","AnimationStart"),transitionend:Vd("Transition","TransitionEnd")},Ym={},fk={};Ss&&(fk=document.createElement("div").style,"AnimationEvent"in window||(delete Xa.animationend.animation,delete Xa.animationiteration.animation,delete Xa.animationstart.animation),"TransitionEvent"in window||delete Xa.transitionend.transition);function sg(t){if(Ym[t])return Ym[t];if(!Xa[t])return t;var e=Xa[t],n;for(n in e)if(e.hasOwnProperty(n)&&n in fk)return Ym[t]=e[n];return t}var gk=sg("animationend"),mk=sg("animationiteration"),yk=sg("animationstart"),Sk=sg("transitionend"),vk=new Map,KP="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 wi(t,e){vk.set(t,e),va(e,[t])}for(var Xm=0;Xm<KP.length;Xm++){var qm=KP[Xm],wz=qm.toLowerCase(),bz=qm[0].toUpperCase()+qm.slice(1);wi(wz,"on"+bz)}wi(gk,"onAnimationEnd");wi(mk,"onAnimationIteration");wi(yk,"onAnimationStart");wi("dblclick","onDoubleClick");wi("focusin","onFocus");wi("focusout","onBlur");wi(Sk,"onTransitionEnd");Il("onMouseEnter",["mouseout","mouseover"]);Il("onMouseLeave",["mouseout","mouseover"]);Il("onPointerEnter",["pointerout","pointerover"]);Il("onPointerLeave",["pointerout","pointerover"]);va("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));va("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));va("onBeforeInput",["compositionend","keypress","textInput","paste"]);va("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));va("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));va("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Uc="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(" "),Pz=new Set("cancel close invalid load scroll toggle".split(" ").concat(Uc));function WP(t,e,n){var r=t.type||"unknown-event";t.currentTarget=n,w6(r,e,void 0,t),t.currentTarget=null}function xk(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;WP(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;WP(o,a,c),s=l}}}if(zp)throw t=fv,zp=!1,fv=null,t}function et(t,e){var n=e[Cv];n===void 0&&(n=e[Cv]=new Set);var r=t+"__bubble";n.has(r)||(wk(e,t,2,!1),n.add(r))}function Zm(t,e,n){var r=0;e&&(r|=4),wk(n,t,r,e)}var Yd="_reactListening"+Math.random().toString(36).slice(2);function _u(t){if(!t[Yd]){t[Yd]=!0,k2.forEach(function(n){n!=="selectionchange"&&(Pz.has(n)||Zm(n,!1,t),Zm(n,!0,t))});var e=t.nodeType===9?t:t.ownerDocument;e===null||e[Yd]||(e[Yd]=!0,Zm("selectionchange",!1,e))}}function wk(t,e,n,r){switch(ok(e)){case 1:var o=$6;break;case 4:o=F6;break;default:o=O0}n=o.bind(null,e,n,t),o=void 0,!pv||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 Qm(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=Wi(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}K2(function(){var c=s,u=T0(n),h=[];e:{var p=vk.get(t);if(p!==void 0){var f=R0,g=t;switch(t){case"keypress":if(Vh(n)===0)break e;case"keydown":case"keyup":f=J6;break;case"focusin":g="focus",f=Wm;break;case"focusout":g="blur",f=Wm;break;case"beforeblur":case"afterblur":f=Wm;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=OP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=B6;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=nz;break;case gk:case mk:case yk:f=K6;break;case Sk:f=oz;break;case"scroll":f=N6;break;case"wheel":f=iz;break;case"copy":case"cut":case"paste":f=G6;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=RP}var m=(e&4)!==0,v=!m&&t==="scroll",y=m?p!==null?p+"Capture":null:p;m=[];for(var S=c,b;S!==null;){b=S;var P=b.stateNode;if(b.tag===5&&P!==null&&(b=P,y!==null&&(P=vu(S,y),P!=null&&m.push(Iu(S,P,b)))),v)break;S=S.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!==dv&&(g=n.relatedTarget||n.fromElement)&&(Wi(g)||g[vs]))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?Wi(g):null,g!==null&&(v=xa(g),g!==v||g.tag!==5&&g.tag!==6)&&(g=null)):(f=null,g=c),f!==g)){if(m=OP,P="onMouseLeave",y="onMouseEnter",S="mouse",(t==="pointerout"||t==="pointerover")&&(m=RP,P="onPointerLeave",y="onPointerEnter",S="pointer"),v=f==null?p:qa(f),b=g==null?p:qa(g),p=new m(P,S+"leave",f,n,u),p.target=v,p.relatedTarget=b,P=null,Wi(u)===c&&(m=new m(y,S+"enter",g,n,u),m.target=b,m.relatedTarget=v,P=m),v=P,f&&g)t:{for(m=f,y=g,S=0,b=m;b;b=Ta(b))S++;for(b=0,P=y;P;P=Ta(P))b++;for(;0<S-b;)m=Ta(m),S--;for(;0<b-S;)y=Ta(y),b--;for(;S--;){if(m===y||y!==null&&m===y.alternate)break t;m=Ta(m),y=Ta(y)}m=null}else m=null;f!==null&&GP(h,p,f,m,!1),g!==null&&v!==null&&GP(h,v,g,m,!0)}}e:{if(p=c?qa(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var C=pz;else if(FP(p))if(uk)C=yz;else{C=gz;var _=fz}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(C=mz);if(C&&(C=C(t,c))){ck(h,C,n,u);break e}_&&_(t,p,c),t==="focusout"&&(_=p._wrapperState)&&_.controlled&&p.type==="number"&&iv(p,"number",p.value)}switch(_=c?qa(c):window,t){case"focusin":(FP(_)||_.contentEditable==="true")&&(Ya=_,Sv=c,ru=null);break;case"focusout":ru=Sv=Ya=null;break;case"mousedown":vv=!0;break;case"contextmenu":case"mouseup":case"dragend":vv=!1,HP(h,n,u);break;case"selectionchange":if(xz)break;case"keydown":case"keyup":HP(h,n,u)}var E;if($0)e:{switch(t){case"compositionstart":var k="onCompositionStart";break e;case"compositionend":k="onCompositionEnd";break e;case"compositionupdate":k="onCompositionUpdate";break e}k=void 0}else Va?ak(t,n)&&(k="onCompositionEnd"):t==="keydown"&&n.keyCode===229&&(k="onCompositionStart");k&&(ik&&n.locale!=="ko"&&(Va||k!=="onCompositionStart"?k==="onCompositionEnd"&&Va&&(E=sk()):(qs=u,D0="value"in qs?qs.value:qs.textContent,Va=!0)),_=Wp(c,k),0<_.length&&(k=new DP(k,t,null,n,u),h.push({event:k,listeners:_}),E?k.data=E:(E=lk(n),E!==null&&(k.data=E)))),(E=lz?cz(t,n):uz(t,n))&&(c=Wp(c,"onBeforeInput"),0<c.length&&(u=new DP("onBeforeInput","beforeinput",null,n,u),h.push({event:u,listeners:c}),u.data=E))}xk(h,e)})}function Iu(t,e,n){return{instance:t,listener:e,currentTarget:n}}function Wp(t,e){for(var n=e+"Capture",r=[];t!==null;){var o=t,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=vu(t,n),s!=null&&r.unshift(Iu(t,s,o)),s=vu(t,e),s!=null&&r.push(Iu(t,s,o))),t=t.return}return r}function Ta(t){if(t===null)return null;do t=t.return;while(t&&t.tag!==5);return t||null}function GP(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=vu(n,s),l!=null&&i.unshift(Iu(n,l,a))):o||(l=vu(n,s),l!=null&&i.push(Iu(n,l,a)))),n=n.return}i.length!==0&&t.push({event:e,listeners:i})}var Cz=/\r\n?/g,_z=/\u0000|\uFFFD/g;function VP(t){return(typeof t=="string"?t:""+t).replace(Cz,`
38
- `).replace(_z,"")}function Xd(t,e,n){if(e=VP(e),VP(t)!==e&&n)throw Error(X(425))}function Gp(){}var xv=null,wv=null;function bv(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,Iz=typeof clearTimeout=="function"?clearTimeout:void 0,YP=typeof Promise=="function"?Promise:void 0,Ez=typeof queueMicrotask=="function"?queueMicrotask:typeof YP<"u"?function(t){return YP.resolve(null).then(t).catch(kz)}:Pv;function kz(t){setTimeout(function(){throw t})}function Jm(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),bu(e);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=o}while(n);bu(e)}function oi(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 XP(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 Kl=Math.random().toString(36).slice(2),Po="__reactFiber$"+Kl,Eu="__reactProps$"+Kl,vs="__reactContainer$"+Kl,Cv="__reactEvents$"+Kl,Tz="__reactListeners$"+Kl,Mz="__reactHandles$"+Kl;function Wi(t){var e=t[Po];if(e)return e;for(var n=t.parentNode;n;){if(e=n[vs]||n[Po]){if(n=e.alternate,e.child!==null||n!==null&&n.child!==null)for(t=XP(t);t!==null;){if(n=t[Po])return n;t=XP(t)}return e}t=n,n=t.parentNode}return null}function nd(t){return t=t[Po]||t[vs],!t||t.tag!==5&&t.tag!==6&&t.tag!==13&&t.tag!==3?null:t}function qa(t){if(t.tag===5||t.tag===6)return t.stateNode;throw Error(X(33))}function ig(t){return t[Eu]||null}var _v=[],Za=-1;function bi(t){return{current:t}}function nt(t){0>Za||(t.current=_v[Za],_v[Za]=null,Za--)}function Xe(t,e){Za++,_v[Za]=t.current,t.current=e}var pi={},gn=bi(pi),Gn=bi(!1),ta=pi;function El(t,e){var n=t.type.contextTypes;if(!n)return pi;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 Vn(t){return t=t.childContextTypes,t!=null}function Vp(){nt(Gn),nt(gn)}function qP(t,e,n){if(gn.current!==pi)throw Error(X(168));Xe(gn,e),Xe(Gn,n)}function bk(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,f6(t)||"Unknown",o));return gt({},n,r)}function Yp(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||pi,ta=gn.current,Xe(gn,t),Xe(Gn,Gn.current),!0}function ZP(t,e,n){var r=t.stateNode;if(!r)throw Error(X(169));n?(t=bk(t,e,ta),r.__reactInternalMemoizedMergedChildContext=t,nt(Gn),nt(gn),Xe(gn,t)):nt(Gn),Xe(Gn,n)}var is=null,ag=!1,ey=!1;function Pk(t){is===null?is=[t]:is.push(t)}function Az(t){ag=!0,Pk(t)}function Pi(){if(!ey&&is!==null){ey=!0;var t=0,e=Be;try{var n=is;for(Be=1;t<n.length;t++){var r=n[t];do r=r(!0);while(r!==null)}is=null,ag=!1}catch(o){throw is!==null&&(is=is.slice(t+1)),Y2(M0,Pi),o}finally{Be=e,ey=!1}}return null}var Qa=[],Ja=0,Xp=null,qp=0,kr=[],Tr=0,na=null,ls=1,cs="";function Bi(t,e){Qa[Ja++]=qp,Qa[Ja++]=Xp,Xp=t,qp=e}function Ck(t,e,n){kr[Tr++]=ls,kr[Tr++]=cs,kr[Tr++]=na,na=t;var r=ls;t=cs;var o=32-eo(r)-1;r&=~(1<<o),n+=1;var s=32-eo(e)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,ls=1<<32-eo(e)+o|n<<o|r,cs=s+t}else ls=1<<s|n<<o|r,cs=t}function N0(t){t.return!==null&&(Bi(t,1),Ck(t,1,0))}function z0(t){for(;t===Xp;)Xp=Qa[--Ja],Qa[Ja]=null,qp=Qa[--Ja],Qa[Ja]=null;for(;t===na;)na=kr[--Tr],kr[Tr]=null,cs=kr[--Tr],kr[Tr]=null,ls=kr[--Tr],kr[Tr]=null}var cr=null,ir=null,at=!1,Yr=null;function _k(t,e){var n=Ar(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 QP(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,cr=t,ir=oi(e.firstChild),!0):!1;case 6:return e=t.pendingProps===""||e.nodeType!==3?null:e,e!==null?(t.stateNode=e,cr=t,ir=null,!0):!1;case 13:return e=e.nodeType!==8?null:e,e!==null?(n=na!==null?{id:ls,overflow:cs}:null,t.memoizedState={dehydrated:e,treeContext:n,retryLane:1073741824},n=Ar(18,null,null,0),n.stateNode=e,n.return=t,t.child=n,cr=t,ir=null,!0):!1;default:return!1}}function Iv(t){return(t.mode&1)!==0&&(t.flags&128)===0}function Ev(t){if(at){var e=ir;if(e){var n=e;if(!QP(t,e)){if(Iv(t))throw Error(X(418));e=oi(n.nextSibling);var r=cr;e&&QP(t,e)?_k(r,n):(t.flags=t.flags&-4097|2,at=!1,cr=t)}}else{if(Iv(t))throw Error(X(418));t.flags=t.flags&-4097|2,at=!1,cr=t}}}function JP(t){for(t=t.return;t!==null&&t.tag!==5&&t.tag!==3&&t.tag!==13;)t=t.return;cr=t}function qd(t){if(t!==cr)return!1;if(!at)return JP(t),at=!0,!1;var e;if((e=t.tag!==3)&&!(e=t.tag!==5)&&(e=t.type,e=e!=="head"&&e!=="body"&&!bv(t.type,t.memoizedProps)),e&&(e=ir)){if(Iv(t))throw Ik(),Error(X(418));for(;e;)_k(t,e),e=oi(e.nextSibling)}if(JP(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){ir=oi(t.nextSibling);break e}e--}else n!=="$"&&n!=="$!"&&n!=="$?"||e++}t=t.nextSibling}ir=null}}else ir=cr?oi(t.stateNode.nextSibling):null;return!0}function Ik(){for(var t=ir;t;)t=oi(t.nextSibling)}function kl(){ir=cr=null,at=!1}function B0(t){Yr===null?Yr=[t]:Yr.push(t)}var jz=_s.ReactCurrentBatchConfig;function vc(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 Zd(t,e){throw t=Object.prototype.toString.call(e),Error(X(31,t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t))}function eC(t){var e=t._init;return e(t._payload)}function Ek(t){function e(y,S){if(t){var b=y.deletions;b===null?(y.deletions=[S],y.flags|=16):b.push(S)}}function n(y,S){if(!t)return null;for(;S!==null;)e(y,S),S=S.sibling;return null}function r(y,S){for(y=new Map;S!==null;)S.key!==null?y.set(S.key,S):y.set(S.index,S),S=S.sibling;return y}function o(y,S){return y=li(y,S),y.index=0,y.sibling=null,y}function s(y,S,b){return y.index=b,t?(b=y.alternate,b!==null?(b=b.index,b<S?(y.flags|=2,S):b):(y.flags|=2,S)):(y.flags|=1048576,S)}function i(y){return t&&y.alternate===null&&(y.flags|=2),y}function a(y,S,b,P){return S===null||S.tag!==6?(S=ay(b,y.mode,P),S.return=y,S):(S=o(S,b),S.return=y,S)}function l(y,S,b,P){var C=b.type;return C===Ga?u(y,S,b.props.children,P,b.key):S!==null&&(S.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Hs&&eC(C)===S.type)?(P=o(S,b.props),P.ref=vc(y,S,b),P.return=y,P):(P=ep(b.type,b.key,b.props,null,y.mode,P),P.ref=vc(y,S,b),P.return=y,P)}function c(y,S,b,P){return S===null||S.tag!==4||S.stateNode.containerInfo!==b.containerInfo||S.stateNode.implementation!==b.implementation?(S=ly(b,y.mode,P),S.return=y,S):(S=o(S,b.children||[]),S.return=y,S)}function u(y,S,b,P,C){return S===null||S.tag!==7?(S=qi(b,y.mode,P,C),S.return=y,S):(S=o(S,b),S.return=y,S)}function h(y,S,b){if(typeof S=="string"&&S!==""||typeof S=="number")return S=ay(""+S,y.mode,b),S.return=y,S;if(typeof S=="object"&&S!==null){switch(S.$$typeof){case zd:return b=ep(S.type,S.key,S.props,null,y.mode,b),b.ref=vc(y,null,S),b.return=y,b;case Wa:return S=ly(S,y.mode,b),S.return=y,S;case Hs:var P=S._init;return h(y,P(S._payload),b)}if(zc(S)||fc(S))return S=qi(S,y.mode,b,null),S.return=y,S;Zd(y,S)}return null}function p(y,S,b,P){var C=S!==null?S.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return C!==null?null:a(y,S,""+b,P);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case zd:return b.key===C?l(y,S,b,P):null;case Wa:return b.key===C?c(y,S,b,P):null;case Hs:return C=b._init,p(y,S,C(b._payload),P)}if(zc(b)||fc(b))return C!==null?null:u(y,S,b,P,null);Zd(y,b)}return null}function f(y,S,b,P,C){if(typeof P=="string"&&P!==""||typeof P=="number")return y=y.get(b)||null,a(S,y,""+P,C);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case zd:return y=y.get(P.key===null?b:P.key)||null,l(S,y,P,C);case Wa:return y=y.get(P.key===null?b:P.key)||null,c(S,y,P,C);case Hs:var _=P._init;return f(y,S,b,_(P._payload),C)}if(zc(P)||fc(P))return y=y.get(b)||null,u(S,y,P,C,null);Zd(S,P)}return null}function g(y,S,b,P){for(var C=null,_=null,E=S,k=S=0,D=null;E!==null&&k<b.length;k++){E.index>k?(D=E,E=null):D=E.sibling;var T=p(y,E,b[k],P);if(T===null){E===null&&(E=D);break}t&&E&&T.alternate===null&&e(y,E),S=s(T,S,k),_===null?C=T:_.sibling=T,_=T,E=D}if(k===b.length)return n(y,E),at&&Bi(y,k),C;if(E===null){for(;k<b.length;k++)E=h(y,b[k],P),E!==null&&(S=s(E,S,k),_===null?C=E:_.sibling=E,_=E);return at&&Bi(y,k),C}for(E=r(y,E);k<b.length;k++)D=f(E,y,k,b[k],P),D!==null&&(t&&D.alternate!==null&&E.delete(D.key===null?k:D.key),S=s(D,S,k),_===null?C=D:_.sibling=D,_=D);return t&&E.forEach(function(j){return e(y,j)}),at&&Bi(y,k),C}function m(y,S,b,P){var C=fc(b);if(typeof C!="function")throw Error(X(150));if(b=C.call(b),b==null)throw Error(X(151));for(var _=C=null,E=S,k=S=0,D=null,T=b.next();E!==null&&!T.done;k++,T=b.next()){E.index>k?(D=E,E=null):D=E.sibling;var j=p(y,E,T.value,P);if(j===null){E===null&&(E=D);break}t&&E&&j.alternate===null&&e(y,E),S=s(j,S,k),_===null?C=j:_.sibling=j,_=j,E=D}if(T.done)return n(y,E),at&&Bi(y,k),C;if(E===null){for(;!T.done;k++,T=b.next())T=h(y,T.value,P),T!==null&&(S=s(T,S,k),_===null?C=T:_.sibling=T,_=T);return at&&Bi(y,k),C}for(E=r(y,E);!T.done;k++,T=b.next())T=f(E,y,k,T.value,P),T!==null&&(t&&T.alternate!==null&&E.delete(T.key===null?k:T.key),S=s(T,S,k),_===null?C=T:_.sibling=T,_=T);return t&&E.forEach(function($){return e(y,$)}),at&&Bi(y,k),C}function v(y,S,b,P){if(typeof b=="object"&&b!==null&&b.type===Ga&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case zd:e:{for(var C=b.key,_=S;_!==null;){if(_.key===C){if(C=b.type,C===Ga){if(_.tag===7){n(y,_.sibling),S=o(_,b.props.children),S.return=y,y=S;break e}}else if(_.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Hs&&eC(C)===_.type){n(y,_.sibling),S=o(_,b.props),S.ref=vc(y,_,b),S.return=y,y=S;break e}n(y,_);break}else e(y,_);_=_.sibling}b.type===Ga?(S=qi(b.props.children,y.mode,P,b.key),S.return=y,y=S):(P=ep(b.type,b.key,b.props,null,y.mode,P),P.ref=vc(y,S,b),P.return=y,y=P)}return i(y);case Wa:e:{for(_=b.key;S!==null;){if(S.key===_)if(S.tag===4&&S.stateNode.containerInfo===b.containerInfo&&S.stateNode.implementation===b.implementation){n(y,S.sibling),S=o(S,b.children||[]),S.return=y,y=S;break e}else{n(y,S);break}else e(y,S);S=S.sibling}S=ly(b,y.mode,P),S.return=y,y=S}return i(y);case Hs:return _=b._init,v(y,S,_(b._payload),P)}if(zc(b))return g(y,S,b,P);if(fc(b))return m(y,S,b,P);Zd(y,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,S!==null&&S.tag===6?(n(y,S.sibling),S=o(S,b),S.return=y,y=S):(n(y,S),S=ay(b,y.mode,P),S.return=y,y=S),i(y)):n(y,S)}return v}var Tl=Ek(!0),kk=Ek(!1),Zp=bi(null),Qp=null,el=null,U0=null;function H0(){U0=el=Qp=null}function K0(t){var e=Zp.current;nt(Zp),t._currentValue=e}function kv(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 yl(t,e){Qp=t,U0=el=null,t=t.dependencies,t!==null&&t.firstContext!==null&&(t.lanes&e&&(Hn=!0),t.firstContext=null)}function Rr(t){var e=t._currentValue;if(U0!==t)if(t={context:t,memoizedValue:e,next:null},el===null){if(Qp===null)throw Error(X(308));el=t,Qp.dependencies={lanes:0,firstContext:t}}else el=el.next=t;return e}var Gi=null;function W0(t){Gi===null?Gi=[t]:Gi.push(t)}function Tk(t,e,n,r){var o=e.interleaved;return o===null?(n.next=n,W0(e)):(n.next=o.next,o.next=n),e.interleaved=n,xs(t,r)}function xs(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 Ks=!1;function G0(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Mk(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 hs(t,e){return{eventTime:t,lane:e,tag:0,payload:null,callback:null,next:null}}function si(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,xs(t,n)}return o=r.interleaved,o===null?(e.next=e,W0(r)):(e.next=o.next,o.next=e),r.interleaved=e,xs(t,n)}function Yh(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,A0(t,n)}}function tC(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 Jp(t,e,n,r){var o=t.updateQueue;Ks=!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=gt({},h,p);break e;case 2:Ks=!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);oa|=i,t.lanes=i,t.memoizedState=h}}function nC(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 rd={},Ao=bi(rd),ku=bi(rd),Tu=bi(rd);function Vi(t){if(t===rd)throw Error(X(174));return t}function V0(t,e){switch(Xe(Tu,e),Xe(ku,t),Xe(Ao,rd),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:lv(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=lv(e,t)}nt(Ao),Xe(Ao,e)}function Ml(){nt(Ao),nt(ku),nt(Tu)}function Ak(t){Vi(Tu.current);var e=Vi(Ao.current),n=lv(e,t.type);e!==n&&(Xe(ku,t),Xe(Ao,n))}function Y0(t){ku.current===t&&(nt(Ao),nt(ku))}var dt=bi(0);function ef(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 ty=[];function X0(){for(var t=0;t<ty.length;t++)ty[t]._workInProgressVersionPrimary=null;ty.length=0}var Xh=_s.ReactCurrentDispatcher,ny=_s.ReactCurrentBatchConfig,ra=0,ft=null,kt=null,jt=null,tf=!1,ou=!1,Mu=0,Oz=0;function tn(){throw Error(X(321))}function q0(t,e){if(e===null)return!1;for(var n=0;n<e.length&&n<t.length;n++)if(!so(t[n],e[n]))return!1;return!0}function Z0(t,e,n,r,o,s){if(ra=s,ft=e,e.memoizedState=null,e.updateQueue=null,e.lanes=0,Xh.current=t===null||t.memoizedState===null?$z:Fz,t=n(r,o),ou){s=0;do{if(ou=!1,Mu=0,25<=s)throw Error(X(301));s+=1,jt=kt=null,e.updateQueue=null,Xh.current=Nz,t=n(r,o)}while(ou)}if(Xh.current=nf,e=kt!==null&&kt.next!==null,ra=0,jt=kt=ft=null,tf=!1,e)throw Error(X(300));return t}function Q0(){var t=Mu!==0;return Mu=0,t}function wo(){var t={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return jt===null?ft.memoizedState=jt=t:jt=jt.next=t,jt}function Lr(){if(kt===null){var t=ft.alternate;t=t!==null?t.memoizedState:null}else t=kt.next;var e=jt===null?ft.memoizedState:jt.next;if(e!==null)jt=e,kt=t;else{if(t===null)throw Error(X(310));kt=t,t={memoizedState:kt.memoizedState,baseState:kt.baseState,baseQueue:kt.baseQueue,queue:kt.queue,next:null},jt===null?ft.memoizedState=jt=t:jt=jt.next=t}return jt}function Au(t,e){return typeof e=="function"?e(t):e}function ry(t){var e=Lr(),n=e.queue;if(n===null)throw Error(X(311));n.lastRenderedReducer=t;var r=kt,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((ra&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,ft.lanes|=u,oa|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,so(r,e.memoizedState)||(Hn=!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,ft.lanes|=s,oa|=s,o=o.next;while(o!==t)}else o===null&&(n.lanes=0);return[e.memoizedState,n.dispatch]}function oy(t){var e=Lr(),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);so(s,e.memoizedState)||(Hn=!0),e.memoizedState=s,e.baseQueue===null&&(e.baseState=s),n.lastRenderedState=s}return[s,r]}function jk(){}function Ok(t,e){var n=ft,r=Lr(),o=e(),s=!so(r.memoizedState,o);if(s&&(r.memoizedState=o,Hn=!0),r=r.queue,J0(Lk.bind(null,n,r,t),[t]),r.getSnapshot!==e||s||jt!==null&&jt.memoizedState.tag&1){if(n.flags|=2048,ju(9,Rk.bind(null,n,r,o,e),void 0,null),Rt===null)throw Error(X(349));ra&30||Dk(n,e,o)}return o}function Dk(t,e,n){t.flags|=16384,t={getSnapshot:e,value:n},e=ft.updateQueue,e===null?(e={lastEffect:null,stores:null},ft.updateQueue=e,e.stores=[t]):(n=e.stores,n===null?e.stores=[t]:n.push(t))}function Rk(t,e,n,r){e.value=n,e.getSnapshot=r,$k(e)&&Fk(t)}function Lk(t,e,n){return n(function(){$k(e)&&Fk(t)})}function $k(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!so(t,n)}catch{return!0}}function Fk(t){var e=xs(t,1);e!==null&&to(e,t,1,-1)}function rC(t){var e=wo();return typeof t=="function"&&(t=t()),e.memoizedState=e.baseState=t,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Au,lastRenderedState:t},e.queue=t,t=t.dispatch=Lz.bind(null,ft,t),[e.memoizedState,t]}function ju(t,e,n,r){return t={tag:t,create:e,destroy:n,deps:r,next:null},e=ft.updateQueue,e===null?(e={lastEffect:null,stores:null},ft.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 Nk(){return Lr().memoizedState}function qh(t,e,n,r){var o=wo();ft.flags|=t,o.memoizedState=ju(1|e,n,void 0,r===void 0?null:r)}function lg(t,e,n,r){var o=Lr();r=r===void 0?null:r;var s=void 0;if(kt!==null){var i=kt.memoizedState;if(s=i.destroy,r!==null&&q0(r,i.deps)){o.memoizedState=ju(e,n,s,r);return}}ft.flags|=t,o.memoizedState=ju(1|e,n,s,r)}function oC(t,e){return qh(8390656,8,t,e)}function J0(t,e){return lg(2048,8,t,e)}function zk(t,e){return lg(4,2,t,e)}function Bk(t,e){return lg(4,4,t,e)}function Uk(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 Hk(t,e,n){return n=n!=null?n.concat([t]):null,lg(4,4,Uk.bind(null,e,t),n)}function ew(){}function Kk(t,e){var n=Lr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&q0(e,r[1])?r[0]:(n.memoizedState=[t,e],t)}function Wk(t,e){var n=Lr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&q0(e,r[1])?r[0]:(t=t(),n.memoizedState=[t,e],t)}function Gk(t,e,n){return ra&21?(so(n,e)||(n=Z2(),ft.lanes|=n,oa|=n,t.baseState=!0),e):(t.baseState&&(t.baseState=!1,Hn=!0),t.memoizedState=n)}function Dz(t,e){var n=Be;Be=n!==0&&4>n?n:4,t(!0);var r=ny.transition;ny.transition={};try{t(!1),e()}finally{Be=n,ny.transition=r}}function Vk(){return Lr().memoizedState}function Rz(t,e,n){var r=ai(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Yk(t))Xk(e,n);else if(n=Tk(t,e,n,r),n!==null){var o=Pn();to(n,t,r,o),qk(n,e,r)}}function Lz(t,e,n){var r=ai(t),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Yk(t))Xk(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,so(a,i)){var l=e.interleaved;l===null?(o.next=o,W0(e)):(o.next=l.next,l.next=o),e.interleaved=o;return}}catch{}finally{}n=Tk(t,e,o,r),n!==null&&(o=Pn(),to(n,t,r,o),qk(n,e,r))}}function Yk(t){var e=t.alternate;return t===ft||e!==null&&e===ft}function Xk(t,e){ou=tf=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function qk(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,A0(t,n)}}var nf={readContext:Rr,useCallback:tn,useContext:tn,useEffect:tn,useImperativeHandle:tn,useInsertionEffect:tn,useLayoutEffect:tn,useMemo:tn,useReducer:tn,useRef:tn,useState:tn,useDebugValue:tn,useDeferredValue:tn,useTransition:tn,useMutableSource:tn,useSyncExternalStore:tn,useId:tn,unstable_isNewReconciler:!1},$z={readContext:Rr,useCallback:function(t,e){return wo().memoizedState=[t,e===void 0?null:e],t},useContext:Rr,useEffect:oC,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,qh(4194308,4,Uk.bind(null,e,t),n)},useLayoutEffect:function(t,e){return qh(4194308,4,t,e)},useInsertionEffect:function(t,e){return qh(4,2,t,e)},useMemo:function(t,e){var n=wo();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=wo();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=Rz.bind(null,ft,t),[r.memoizedState,t]},useRef:function(t){var e=wo();return t={current:t},e.memoizedState=t},useState:rC,useDebugValue:ew,useDeferredValue:function(t){return wo().memoizedState=t},useTransition:function(){var t=rC(!1),e=t[0];return t=Dz.bind(null,t[1]),wo().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=ft,o=wo();if(at){if(n===void 0)throw Error(X(407));n=n()}else{if(n=e(),Rt===null)throw Error(X(349));ra&30||Dk(r,e,n)}o.memoizedState=n;var s={value:n,getSnapshot:e};return o.queue=s,oC(Lk.bind(null,r,s,t),[t]),r.flags|=2048,ju(9,Rk.bind(null,r,s,n,e),void 0,null),n},useId:function(){var t=wo(),e=Rt.identifierPrefix;if(at){var n=cs,r=ls;n=(r&~(1<<32-eo(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=Mu++,0<n&&(e+="H"+n.toString(32)),e+=":"}else n=Oz++,e=":"+e+"r"+n.toString(32)+":";return t.memoizedState=e},unstable_isNewReconciler:!1},Fz={readContext:Rr,useCallback:Kk,useContext:Rr,useEffect:J0,useImperativeHandle:Hk,useInsertionEffect:zk,useLayoutEffect:Bk,useMemo:Wk,useReducer:ry,useRef:Nk,useState:function(){return ry(Au)},useDebugValue:ew,useDeferredValue:function(t){var e=Lr();return Gk(e,kt.memoizedState,t)},useTransition:function(){var t=ry(Au)[0],e=Lr().memoizedState;return[t,e]},useMutableSource:jk,useSyncExternalStore:Ok,useId:Vk,unstable_isNewReconciler:!1},Nz={readContext:Rr,useCallback:Kk,useContext:Rr,useEffect:J0,useImperativeHandle:Hk,useInsertionEffect:zk,useLayoutEffect:Bk,useMemo:Wk,useReducer:oy,useRef:Nk,useState:function(){return oy(Au)},useDebugValue:ew,useDeferredValue:function(t){var e=Lr();return kt===null?e.memoizedState=t:Gk(e,kt.memoizedState,t)},useTransition:function(){var t=oy(Au)[0],e=Lr().memoizedState;return[t,e]},useMutableSource:jk,useSyncExternalStore:Ok,useId:Vk,unstable_isNewReconciler:!1};function Kr(t,e){if(t&&t.defaultProps){e=gt({},e),t=t.defaultProps;for(var n in t)e[n]===void 0&&(e[n]=t[n]);return e}return e}function Tv(t,e,n,r){e=t.memoizedState,n=n(r,e),n=n==null?e:gt({},e,n),t.memoizedState=n,t.lanes===0&&(t.updateQueue.baseState=n)}var cg={isMounted:function(t){return(t=t._reactInternals)?xa(t)===t:!1},enqueueSetState:function(t,e,n){t=t._reactInternals;var r=Pn(),o=ai(t),s=hs(r,o);s.payload=e,n!=null&&(s.callback=n),e=si(t,s,o),e!==null&&(to(e,t,o,r),Yh(e,t,o))},enqueueReplaceState:function(t,e,n){t=t._reactInternals;var r=Pn(),o=ai(t),s=hs(r,o);s.tag=1,s.payload=e,n!=null&&(s.callback=n),e=si(t,s,o),e!==null&&(to(e,t,o,r),Yh(e,t,o))},enqueueForceUpdate:function(t,e){t=t._reactInternals;var n=Pn(),r=ai(t),o=hs(n,r);o.tag=2,e!=null&&(o.callback=e),e=si(t,o,r),e!==null&&(to(e,t,r,n),Yh(e,t,r))}};function sC(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?!Cu(n,r)||!Cu(o,s):!0}function Zk(t,e,n){var r=!1,o=pi,s=e.contextType;return typeof s=="object"&&s!==null?s=Rr(s):(o=Vn(e)?ta:gn.current,r=e.contextTypes,s=(r=r!=null)?El(t,o):pi),e=new e(n,s),t.memoizedState=e.state!==null&&e.state!==void 0?e.state:null,e.updater=cg,t.stateNode=e,e._reactInternals=t,r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=o,t.__reactInternalMemoizedMaskedChildContext=s),e}function iC(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&&cg.enqueueReplaceState(e,e.state,null)}function Mv(t,e,n,r){var o=t.stateNode;o.props=n,o.state=t.memoizedState,o.refs={},G0(t);var s=e.contextType;typeof s=="object"&&s!==null?o.context=Rr(s):(s=Vn(e)?ta:gn.current,o.context=El(t,s)),o.state=t.memoizedState,s=e.getDerivedStateFromProps,typeof s=="function"&&(Tv(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&&cg.enqueueReplaceState(o,o.state,null),Jp(t,n,o,r),o.state=t.memoizedState),typeof o.componentDidMount=="function"&&(t.flags|=4194308)}function Al(t,e){try{var n="",r=e;do n+=p6(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 sy(t,e,n){return{value:t,source:null,stack:n??null,digest:e??null}}function Av(t,e){try{console.error(e.value)}catch(n){setTimeout(function(){throw n})}}var zz=typeof WeakMap=="function"?WeakMap:Map;function Qk(t,e,n){n=hs(-1,n),n.tag=3,n.payload={element:null};var r=e.value;return n.callback=function(){of||(of=!0,Bv=r),Av(t,e)},n}function Jk(t,e,n){n=hs(-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(){Av(t,e)}}var s=t.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(n.callback=function(){Av(t,e),typeof r!="function"&&(ii===null?ii=new Set([this]):ii.add(this));var i=e.stack;this.componentDidCatch(e.value,{componentStack:i!==null?i:""})}),n}function aC(t,e,n){var r=t.pingCache;if(r===null){r=t.pingCache=new zz;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=e8.bind(null,t,e,n),e.then(t,t))}function lC(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 cC(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=hs(-1,1),e.tag=2,si(n,e,1))),n.lanes|=1),t)}var Bz=_s.ReactCurrentOwner,Hn=!1;function xn(t,e,n,r){e.child=t===null?kk(e,null,n,r):Tl(e,t.child,n,r)}function uC(t,e,n,r,o){n=n.render;var s=e.ref;return yl(e,o),r=Z0(t,e,n,r,s,o),n=Q0(),t!==null&&!Hn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,ws(t,e,o)):(at&&n&&N0(e),e.flags|=1,xn(t,e,r,o),e.child)}function dC(t,e,n,r,o){if(t===null){var s=n.type;return typeof s=="function"&&!lw(s)&&s.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(e.tag=15,e.type=s,eT(t,e,s,r,o)):(t=ep(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:Cu,n(i,r)&&t.ref===e.ref)return ws(t,e,o)}return e.flags|=1,t=li(s,r),t.ref=e.ref,t.return=e,e.child=t}function eT(t,e,n,r,o){if(t!==null){var s=t.memoizedProps;if(Cu(s,r)&&t.ref===e.ref)if(Hn=!1,e.pendingProps=r=s,(t.lanes&o)!==0)t.flags&131072&&(Hn=!0);else return e.lanes=t.lanes,ws(t,e,o)}return jv(t,e,n,r,o)}function tT(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(nl,or),or|=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(nl,or),or|=t,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:n,Xe(nl,or),or|=r}else s!==null?(r=s.baseLanes|n,e.memoizedState=null):r=n,Xe(nl,or),or|=r;return xn(t,e,o,n),e.child}function nT(t,e){var n=e.ref;(t===null&&n!==null||t!==null&&t.ref!==n)&&(e.flags|=512,e.flags|=2097152)}function jv(t,e,n,r,o){var s=Vn(n)?ta:gn.current;return s=El(e,s),yl(e,o),n=Z0(t,e,n,r,s,o),r=Q0(),t!==null&&!Hn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,ws(t,e,o)):(at&&r&&N0(e),e.flags|=1,xn(t,e,n,o),e.child)}function hC(t,e,n,r,o){if(Vn(n)){var s=!0;Yp(e)}else s=!1;if(yl(e,o),e.stateNode===null)Zh(t,e),Zk(e,n,r),Mv(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=Rr(c):(c=Vn(n)?ta:gn.current,c=El(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)&&iC(e,i,r,c),Ks=!1;var p=e.memoizedState;i.state=p,Jp(e,r,i,o),l=e.memoizedState,a!==r||p!==l||Gn.current||Ks?(typeof u=="function"&&(Tv(e,n,u,r),l=e.memoizedState),(a=Ks||sC(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,Mk(t,e),a=e.memoizedProps,c=e.type===e.elementType?a:Kr(e.type,a),i.props=c,h=e.pendingProps,p=i.context,l=n.contextType,typeof l=="object"&&l!==null?l=Rr(l):(l=Vn(n)?ta:gn.current,l=El(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)&&iC(e,i,r,l),Ks=!1,p=e.memoizedState,i.state=p,Jp(e,r,i,o);var g=e.memoizedState;a!==h||p!==g||Gn.current||Ks?(typeof f=="function"&&(Tv(e,n,f,r),g=e.memoizedState),(c=Ks||sC(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 Ov(t,e,n,r,s,o)}function Ov(t,e,n,r,o,s){nT(t,e);var i=(e.flags&128)!==0;if(!r&&!i)return o&&ZP(e,n,!1),ws(t,e,s);r=e.stateNode,Bz.current=e;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,t!==null&&i?(e.child=Tl(e,t.child,null,s),e.child=Tl(e,null,a,s)):xn(t,e,a,s),e.memoizedState=r.state,o&&ZP(e,n,!0),e.child}function rT(t){var e=t.stateNode;e.pendingContext?qP(t,e.pendingContext,e.pendingContext!==e.context):e.context&&qP(t,e.context,!1),V0(t,e.containerInfo)}function pC(t,e,n,r,o){return kl(),B0(o),e.flags|=256,xn(t,e,n,r),e.child}var Dv={dehydrated:null,treeContext:null,retryLane:0};function Rv(t){return{baseLanes:t,cachePool:null,transitions:null}}function oT(t,e,n){var r=e.pendingProps,o=dt.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(dt,o&1),t===null)return Ev(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=hg(i,r,0,null),t=qi(t,r,n,null),s.return=e,t.return=e,s.sibling=t,e.child=s,e.child.memoizedState=Rv(n),e.memoizedState=Dv,t):tw(e,i));if(o=t.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return Uz(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=li(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=li(a,s):(s=qi(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?Rv(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=t.childLanes&~n,e.memoizedState=Dv,r}return s=t.child,t=s.sibling,r=li(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 tw(t,e){return e=hg({mode:"visible",children:e},t.mode,0,null),e.return=t,t.child=e}function Qd(t,e,n,r){return r!==null&&B0(r),Tl(e,t.child,null,n),t=tw(e,e.pendingProps.children),t.flags|=2,e.memoizedState=null,t}function Uz(t,e,n,r,o,s,i){if(n)return e.flags&256?(e.flags&=-257,r=sy(Error(X(422))),Qd(t,e,i,r)):e.memoizedState!==null?(e.child=t.child,e.flags|=128,null):(s=r.fallback,o=e.mode,r=hg({mode:"visible",children:r.children},o,0,null),s=qi(s,o,i,null),s.flags|=2,r.return=e,s.return=e,r.sibling=s,e.child=r,e.mode&1&&Tl(e,t.child,null,i),e.child.memoizedState=Rv(i),e.memoizedState=Dv,s);if(!(e.mode&1))return Qd(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=sy(s,r,void 0),Qd(t,e,i,r)}if(a=(i&t.childLanes)!==0,Hn||a){if(r=Rt,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,xs(t,o),to(r,t,o,-1))}return aw(),r=sy(Error(X(421))),Qd(t,e,i,r)}return o.data==="$?"?(e.flags|=128,e.child=t.child,e=t8.bind(null,t),o._reactRetry=e,null):(t=s.treeContext,ir=oi(o.nextSibling),cr=e,at=!0,Yr=null,t!==null&&(kr[Tr++]=ls,kr[Tr++]=cs,kr[Tr++]=na,ls=t.id,cs=t.overflow,na=e),e=tw(e,r.children),e.flags|=4096,e)}function fC(t,e,n){t.lanes|=e;var r=t.alternate;r!==null&&(r.lanes|=e),kv(t.return,e,n)}function iy(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 sT(t,e,n){var r=e.pendingProps,o=r.revealOrder,s=r.tail;if(xn(t,e,r.children,n),r=dt.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&&fC(t,n,e);else if(t.tag===19)fC(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(dt,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&&ef(t)===null&&(o=n),n=n.sibling;n=o,n===null?(o=e.child,e.child=null):(o=n.sibling,n.sibling=null),iy(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&&ef(t)===null){e.child=o;break}t=o.sibling,o.sibling=n,n=o,o=t}iy(e,!0,n,null,s);break;case"together":iy(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function Zh(t,e){!(e.mode&1)&&t!==null&&(t.alternate=null,e.alternate=null,e.flags|=2)}function ws(t,e,n){if(t!==null&&(e.dependencies=t.dependencies),oa|=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=li(t,t.pendingProps),e.child=n,n.return=e;t.sibling!==null;)t=t.sibling,n=n.sibling=li(t,t.pendingProps),n.return=e;n.sibling=null}return e.child}function Hz(t,e,n){switch(e.tag){case 3:rT(e),kl();break;case 5:Ak(e);break;case 1:Vn(e.type)&&Yp(e);break;case 4:V0(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,o=e.memoizedProps.value;Xe(Zp,r._currentValue),r._currentValue=o;break;case 13:if(r=e.memoizedState,r!==null)return r.dehydrated!==null?(Xe(dt,dt.current&1),e.flags|=128,null):n&e.child.childLanes?oT(t,e,n):(Xe(dt,dt.current&1),t=ws(t,e,n),t!==null?t.sibling:null);Xe(dt,dt.current&1);break;case 19:if(r=(n&e.childLanes)!==0,t.flags&128){if(r)return sT(t,e,n);e.flags|=128}if(o=e.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Xe(dt,dt.current),r)break;return null;case 22:case 23:return e.lanes=0,tT(t,e,n)}return ws(t,e,n)}var iT,Lv,aT,lT;iT=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}};Lv=function(){};aT=function(t,e,n,r){var o=t.memoizedProps;if(o!==r){t=e.stateNode,Vi(Ao.current);var s=null;switch(n){case"input":o=ov(t,o),r=ov(t,r),s=[];break;case"select":o=gt({},o,{value:void 0}),r=gt({},r,{value:void 0}),s=[];break;case"textarea":o=av(t,o),r=av(t,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(t.onclick=Gp)}cv(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"&&(yu.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"&&(yu.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)}};lT=function(t,e,n,r){n!==r&&(e.flags|=4)};function xc(t,e){if(!at)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 nn(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 Kz(t,e,n){var r=e.pendingProps;switch(z0(e),e.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return nn(e),null;case 1:return Vn(e.type)&&Vp(),nn(e),null;case 3:return r=e.stateNode,Ml(),nt(Gn),nt(gn),X0(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(t===null||t.child===null)&&(qd(e)?e.flags|=4:t===null||t.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,Yr!==null&&(Kv(Yr),Yr=null))),Lv(t,e),nn(e),null;case 5:Y0(e);var o=Vi(Tu.current);if(n=e.type,t!==null&&e.stateNode!=null)aT(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 nn(e),null}if(t=Vi(Ao.current),qd(e)){r=e.stateNode,n=e.type;var s=e.memoizedProps;switch(r[Po]=e,r[Eu]=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<Uc.length;o++)et(Uc[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":PP(r,s),et("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},et("invalid",r);break;case"textarea":_P(r,s),et("invalid",r)}cv(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&&Xd(r.textContent,a,t),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Xd(r.textContent,a,t),o=["children",""+a]):yu.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&et("scroll",r)}switch(n){case"input":Bd(r),CP(r,s,!0);break;case"textarea":Bd(r),IP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Gp)}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=L2(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[Po]=e,t[Eu]=r,iT(t,e,!1,!1),e.stateNode=t;e:{switch(i=uv(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<Uc.length;o++)et(Uc[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":PP(t,r),o=ov(t,r),et("invalid",t);break;case"option":o=r;break;case"select":t._wrapperState={wasMultiple:!!r.multiple},o=gt({},r,{value:void 0}),et("invalid",t);break;case"textarea":_P(t,r),o=av(t,r),et("invalid",t);break;default:o=r}cv(n,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?N2(t,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&$2(t,l)):s==="children"?typeof l=="string"?(n!=="textarea"||l!=="")&&Su(t,l):typeof l=="number"&&Su(t,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(yu.hasOwnProperty(s)?l!=null&&s==="onScroll"&&et("scroll",t):l!=null&&_0(t,s,l,i))}switch(n){case"input":Bd(t),CP(t,r,!1);break;case"textarea":Bd(t),IP(t);break;case"option":r.value!=null&&t.setAttribute("value",""+hi(r.value));break;case"select":t.multiple=!!r.multiple,s=r.value,s!=null?pl(t,!!r.multiple,s,!1):r.defaultValue!=null&&pl(t,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(t.onclick=Gp)}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 nn(e),null;case 6:if(t&&e.stateNode!=null)lT(t,e,t.memoizedProps,r);else{if(typeof r!="string"&&e.stateNode===null)throw Error(X(166));if(n=Vi(Tu.current),Vi(Ao.current),qd(e)){if(r=e.stateNode,n=e.memoizedProps,r[Po]=e,(s=r.nodeValue!==n)&&(t=cr,t!==null))switch(t.tag){case 3:Xd(r.nodeValue,n,(t.mode&1)!==0);break;case 5:t.memoizedProps.suppressHydrationWarning!==!0&&Xd(r.nodeValue,n,(t.mode&1)!==0)}s&&(e.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[Po]=e,e.stateNode=r}return nn(e),null;case 13:if(nt(dt),r=e.memoizedState,t===null||t.memoizedState!==null&&t.memoizedState.dehydrated!==null){if(at&&ir!==null&&e.mode&1&&!(e.flags&128))Ik(),kl(),e.flags|=98560,s=!1;else if(s=qd(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[Po]=e}else kl(),!(e.flags&128)&&(e.memoizedState=null),e.flags|=4;nn(e),s=!1}else Yr!==null&&(Kv(Yr),Yr=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||dt.current&1?Tt===0&&(Tt=3):aw())),e.updateQueue!==null&&(e.flags|=4),nn(e),null);case 4:return Ml(),Lv(t,e),t===null&&_u(e.stateNode.containerInfo),nn(e),null;case 10:return K0(e.type._context),nn(e),null;case 17:return Vn(e.type)&&Vp(),nn(e),null;case 19:if(nt(dt),s=e.memoizedState,s===null)return nn(e),null;if(r=(e.flags&128)!==0,i=s.rendering,i===null)if(r)xc(s,!1);else{if(Tt!==0||t!==null&&t.flags&128)for(t=e.child;t!==null;){if(i=ef(t),i!==null){for(e.flags|=128,xc(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(dt,dt.current&1|2),e.child}t=t.sibling}s.tail!==null&&wt()>jl&&(e.flags|=128,r=!0,xc(s,!1),e.lanes=4194304)}else{if(!r)if(t=ef(i),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),xc(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!at)return nn(e),null}else 2*wt()-s.renderingStartTime>jl&&n!==1073741824&&(e.flags|=128,r=!0,xc(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=wt(),e.sibling=null,n=dt.current,Xe(dt,r?n&1|2:n&1),e):(nn(e),null);case 22:case 23:return iw(),r=e.memoizedState!==null,t!==null&&t.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?or&1073741824&&(nn(e),e.subtreeFlags&6&&(e.flags|=8192)):nn(e),null;case 24:return null;case 25:return null}throw Error(X(156,e.tag))}function Wz(t,e){switch(z0(e),e.tag){case 1:return Vn(e.type)&&Vp(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return Ml(),nt(Gn),nt(gn),X0(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Y0(e),null;case 13:if(nt(dt),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(X(340));kl()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return nt(dt),null;case 4:return Ml(),null;case 10:return K0(e.type._context),null;case 22:case 23:return iw(),null;case 24:return null;default:return null}}var Jd=!1,ln=!1,Gz=typeof WeakSet=="function"?WeakSet:Set,re=null;function tl(t,e){var n=t.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){yt(t,e,r)}else n.current=null}function $v(t,e,n){try{n()}catch(r){yt(t,e,r)}}var gC=!1;function Vz(t,e){if(xv=Hp,t=pk(),F0(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(wv={focusedElem:t,selectionRange:n},Hp=!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,y=e.stateNode,S=y.getSnapshotBeforeUpdate(e.elementType===e.type?m:Kr(e.type,m),v);y.__reactInternalSnapshotBeforeUpdate=S}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){yt(e,e.return,P)}if(t=e.sibling,t!==null){t.return=e.return,re=t;break}re=e.return}return g=gC,gC=!1,g}function su(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&&$v(e,n,s)}o=o.next}while(o!==r)}}function ug(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 Fv(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 cT(t){var e=t.alternate;e!==null&&(t.alternate=null,cT(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[Po],delete e[Eu],delete e[Cv],delete e[Tz],delete e[Mz])),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 uT(t){return t.tag===5||t.tag===3||t.tag===4}function mC(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||uT(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 Nv(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=Gp));else if(r!==4&&(t=t.child,t!==null))for(Nv(t,e,n),t=t.sibling;t!==null;)Nv(t,e,n),t=t.sibling}function zv(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(zv(t,e,n),t=t.sibling;t!==null;)zv(t,e,n),t=t.sibling}var Nt=null,Wr=!1;function Ls(t,e,n){for(n=n.child;n!==null;)dT(t,e,n),n=n.sibling}function dT(t,e,n){if(Mo&&typeof Mo.onCommitFiberUnmount=="function")try{Mo.onCommitFiberUnmount(ng,n)}catch{}switch(n.tag){case 5:ln||tl(n,e);case 6:var r=Nt,o=Wr;Nt=null,Ls(t,e,n),Nt=r,Wr=o,Nt!==null&&(Wr?(t=Nt,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):Nt.removeChild(n.stateNode));break;case 18:Nt!==null&&(Wr?(t=Nt,n=n.stateNode,t.nodeType===8?Jm(t.parentNode,n):t.nodeType===1&&Jm(t,n),bu(t)):Jm(Nt,n.stateNode));break;case 4:r=Nt,o=Wr,Nt=n.stateNode.containerInfo,Wr=!0,Ls(t,e,n),Nt=r,Wr=o;break;case 0:case 11:case 14:case 15:if(!ln&&(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)&&$v(n,e,i),o=o.next}while(o!==r)}Ls(t,e,n);break;case 1:if(!ln&&(tl(n,e),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){yt(n,e,a)}Ls(t,e,n);break;case 21:Ls(t,e,n);break;case 22:n.mode&1?(ln=(r=ln)||n.memoizedState!==null,Ls(t,e,n),ln=r):Ls(t,e,n);break;default:Ls(t,e,n)}}function yC(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new Gz),e.forEach(function(r){var o=n8.bind(null,t,r);n.has(r)||(n.add(r),r.then(o,o))})}}function Hr(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,Wr=!1;break e;case 3:Nt=a.stateNode.containerInfo,Wr=!0;break e;case 4:Nt=a.stateNode.containerInfo,Wr=!0;break e}a=a.return}if(Nt===null)throw Error(X(160));dT(s,i,o),Nt=null,Wr=!1;var l=o.alternate;l!==null&&(l.return=null),o.return=null}catch(c){yt(o,e,c)}}if(e.subtreeFlags&12854)for(e=e.child;e!==null;)hT(e,t),e=e.sibling}function hT(t,e){var n=t.alternate,r=t.flags;switch(t.tag){case 0:case 11:case 14:case 15:if(Hr(e,t),mo(t),r&4){try{su(3,t,t.return),ug(3,t)}catch(m){yt(t,t.return,m)}try{su(5,t,t.return)}catch(m){yt(t,t.return,m)}}break;case 1:Hr(e,t),mo(t),r&512&&n!==null&&tl(n,n.return);break;case 5:if(Hr(e,t),mo(t),r&512&&n!==null&&tl(n,n.return),t.flags&32){var o=t.stateNode;try{Su(o,"")}catch(m){yt(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&&D2(o,s),uv(a,i);var c=uv(a,s);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?N2(o,h):u==="dangerouslySetInnerHTML"?$2(o,h):u==="children"?Su(o,h):_0(o,u,h,c)}switch(a){case"input":sv(o,s);break;case"textarea":R2(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?pl(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?pl(o,!!s.multiple,s.defaultValue,!0):pl(o,!!s.multiple,s.multiple?[]:"",!1))}o[Eu]=s}catch(m){yt(t,t.return,m)}}break;case 6:if(Hr(e,t),mo(t),r&4){if(t.stateNode===null)throw Error(X(162));o=t.stateNode,s=t.memoizedProps;try{o.nodeValue=s}catch(m){yt(t,t.return,m)}}break;case 3:if(Hr(e,t),mo(t),r&4&&n!==null&&n.memoizedState.isDehydrated)try{bu(e.containerInfo)}catch(m){yt(t,t.return,m)}break;case 4:Hr(e,t),mo(t);break;case 13:Hr(e,t),mo(t),o=t.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(ow=wt())),r&4&&yC(t);break;case 22:if(u=n!==null&&n.memoizedState!==null,t.mode&1?(ln=(c=ln)||u,Hr(e,t),ln=c):Hr(e,t),mo(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:su(4,p,p.return);break;case 1:tl(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){yt(r,n,m)}}break;case 5:tl(p,p.return);break;case 22:if(p.memoizedState!==null){vC(h);continue}}f!==null?(f.return=p,re=f):vC(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=F2("display",i))}catch(m){yt(t,t.return,m)}}}else if(h.tag===6){if(u===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(m){yt(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:Hr(e,t),mo(t),r&4&&yC(t);break;case 21:break;default:Hr(e,t),mo(t)}}function mo(t){var e=t.flags;if(e&2){try{e:{for(var n=t.return;n!==null;){if(uT(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&&(Su(o,""),r.flags&=-33);var s=mC(t);zv(t,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=mC(t);Nv(t,a,i);break;default:throw Error(X(161))}}catch(l){yt(t,t.return,l)}t.flags&=-3}e&4096&&(t.flags&=-4097)}function Yz(t,e,n){re=t,pT(t)}function pT(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||Jd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||ln;a=Jd;var c=ln;if(Jd=i,(ln=l)&&!c)for(re=o;re!==null;)i=re,l=i.child,i.tag===22&&i.memoizedState!==null?xC(o):l!==null?(l.return=i,re=l):xC(o);for(;s!==null;)re=s,pT(s),s=s.sibling;re=o,Jd=a,ln=c}SC(t)}else o.subtreeFlags&8772&&s!==null?(s.return=o,re=s):SC(t)}}function SC(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:ln||ug(5,e);break;case 1:var r=e.stateNode;if(e.flags&4&&!ln)if(n===null)r.componentDidMount();else{var o=e.elementType===e.type?n.memoizedProps:Kr(e.type,n.memoizedProps);r.componentDidUpdate(o,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=e.updateQueue;s!==null&&nC(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}nC(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&&bu(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(X(163))}ln||e.flags&512&&Fv(e)}catch(p){yt(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 vC(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 xC(t){for(;re!==null;){var e=re;try{switch(e.tag){case 0:case 11:case 15:var n=e.return;try{ug(4,e)}catch(l){yt(e,n,l)}break;case 1:var r=e.stateNode;if(typeof r.componentDidMount=="function"){var o=e.return;try{r.componentDidMount()}catch(l){yt(e,o,l)}}var s=e.return;try{Fv(e)}catch(l){yt(e,s,l)}break;case 5:var i=e.return;try{Fv(e)}catch(l){yt(e,i,l)}}}catch(l){yt(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 Xz=Math.ceil,rf=_s.ReactCurrentDispatcher,nw=_s.ReactCurrentOwner,Or=_s.ReactCurrentBatchConfig,Oe=0,Rt=null,It=null,Vt=0,or=0,nl=bi(0),Tt=0,Ou=null,oa=0,dg=0,rw=0,iu=null,Nn=null,ow=0,jl=1/0,rs=null,of=!1,Bv=null,ii=null,eh=!1,Zs=null,sf=0,au=0,Uv=null,Qh=-1,Jh=0;function Pn(){return Oe&6?wt():Qh!==-1?Qh:Qh=wt()}function ai(t){return t.mode&1?Oe&2&&Vt!==0?Vt&-Vt:jz.transition!==null?(Jh===0&&(Jh=Z2()),Jh):(t=Be,t!==0||(t=window.event,t=t===void 0?16:ok(t.type)),t):1}function to(t,e,n,r){if(50<au)throw au=0,Uv=null,Error(X(185));ed(t,n,r),(!(Oe&2)||t!==Rt)&&(t===Rt&&(!(Oe&2)&&(dg|=n),Tt===4&&Gs(t,Vt)),Yn(t,r),n===1&&Oe===0&&!(e.mode&1)&&(jl=wt()+500,ag&&Pi()))}function Yn(t,e){var n=t.callbackNode;j6(t,e);var r=Up(t,t===Rt?Vt:0);if(r===0)n!==null&&TP(n),t.callbackNode=null,t.callbackPriority=0;else if(e=r&-r,t.callbackPriority!==e){if(n!=null&&TP(n),e===1)t.tag===0?Az(wC.bind(null,t)):Pk(wC.bind(null,t)),Ez(function(){!(Oe&6)&&Pi()}),n=null;else{switch(Q2(r)){case 1:n=M0;break;case 4:n=X2;break;case 16:n=Bp;break;case 536870912:n=q2;break;default:n=Bp}n=wT(n,fT.bind(null,t))}t.callbackPriority=e,t.callbackNode=n}}function fT(t,e){if(Qh=-1,Jh=0,Oe&6)throw Error(X(327));var n=t.callbackNode;if(Sl()&&t.callbackNode!==n)return null;var r=Up(t,t===Rt?Vt:0);if(r===0)return null;if(r&30||r&t.expiredLanes||e)e=af(t,r);else{e=r;var o=Oe;Oe|=2;var s=mT();(Rt!==t||Vt!==e)&&(rs=null,jl=wt()+500,Xi(t,e));do try{Qz();break}catch(a){gT(t,a)}while(!0);H0(),rf.current=s,Oe=o,It!==null?e=0:(Rt=null,Vt=0,e=Tt)}if(e!==0){if(e===2&&(o=gv(t),o!==0&&(r=o,e=Hv(t,o))),e===1)throw n=Ou,Xi(t,0),Gs(t,r),Yn(t,wt()),n;if(e===6)Gs(t,r);else{if(o=t.current.alternate,!(r&30)&&!qz(o)&&(e=af(t,r),e===2&&(s=gv(t),s!==0&&(r=s,e=Hv(t,s))),e===1))throw n=Ou,Xi(t,0),Gs(t,r),Yn(t,wt()),n;switch(t.finishedWork=o,t.finishedLanes=r,e){case 0:case 1:throw Error(X(345));case 2:Ui(t,Nn,rs);break;case 3:if(Gs(t,r),(r&130023424)===r&&(e=ow+500-wt(),10<e)){if(Up(t,0)!==0)break;if(o=t.suspendedLanes,(o&r)!==r){Pn(),t.pingedLanes|=t.suspendedLanes&o;break}t.timeoutHandle=Pv(Ui.bind(null,t,Nn,rs),e);break}Ui(t,Nn,rs);break;case 4:if(Gs(t,r),(r&4194240)===r)break;for(e=t.eventTimes,o=-1;0<r;){var i=31-eo(r);s=1<<i,i=e[i],i>o&&(o=i),r&=~s}if(r=o,r=wt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Xz(r/1960))-r,10<r){t.timeoutHandle=Pv(Ui.bind(null,t,Nn,rs),r);break}Ui(t,Nn,rs);break;case 5:Ui(t,Nn,rs);break;default:throw Error(X(329))}}}return Yn(t,wt()),t.callbackNode===n?fT.bind(null,t):null}function Hv(t,e){var n=iu;return t.current.memoizedState.isDehydrated&&(Xi(t,e).flags|=256),t=af(t,e),t!==2&&(e=Nn,Nn=n,e!==null&&Kv(e)),t}function Kv(t){Nn===null?Nn=t:Nn.push.apply(Nn,t)}function qz(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(!so(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 Gs(t,e){for(e&=~rw,e&=~dg,t.suspendedLanes|=e,t.pingedLanes&=~e,t=t.expirationTimes;0<e;){var n=31-eo(e),r=1<<n;t[n]=-1,e&=~r}}function wC(t){if(Oe&6)throw Error(X(327));Sl();var e=Up(t,0);if(!(e&1))return Yn(t,wt()),null;var n=af(t,e);if(t.tag!==0&&n===2){var r=gv(t);r!==0&&(e=r,n=Hv(t,r))}if(n===1)throw n=Ou,Xi(t,0),Gs(t,e),Yn(t,wt()),n;if(n===6)throw Error(X(345));return t.finishedWork=t.current.alternate,t.finishedLanes=e,Ui(t,Nn,rs),Yn(t,wt()),null}function sw(t,e){var n=Oe;Oe|=1;try{return t(e)}finally{Oe=n,Oe===0&&(jl=wt()+500,ag&&Pi())}}function sa(t){Zs!==null&&Zs.tag===0&&!(Oe&6)&&Sl();var e=Oe;Oe|=1;var n=Or.transition,r=Be;try{if(Or.transition=null,Be=1,t)return t()}finally{Be=r,Or.transition=n,Oe=e,!(Oe&6)&&Pi()}}function iw(){or=nl.current,nt(nl)}function Xi(t,e){t.finishedWork=null,t.finishedLanes=0;var n=t.timeoutHandle;if(n!==-1&&(t.timeoutHandle=-1,Iz(n)),It!==null)for(n=It.return;n!==null;){var r=n;switch(z0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Vp();break;case 3:Ml(),nt(Gn),nt(gn),X0();break;case 5:Y0(r);break;case 4:Ml();break;case 13:nt(dt);break;case 19:nt(dt);break;case 10:K0(r.type._context);break;case 22:case 23:iw()}n=n.return}if(Rt=t,It=t=li(t.current,null),Vt=or=e,Tt=0,Ou=null,rw=dg=oa=0,Nn=iu=null,Gi!==null){for(e=0;e<Gi.length;e++)if(n=Gi[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}Gi=null}return t}function gT(t,e){do{var n=It;try{if(H0(),Xh.current=nf,tf){for(var r=ft.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}tf=!1}if(ra=0,jt=kt=ft=null,ou=!1,Mu=0,nw.current=null,n===null||n.return===null){Tt=1,Ou=e,It=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=lC(i);if(f!==null){f.flags&=-257,cC(f,i,a,s,e),f.mode&1&&aC(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)){aC(s,c,e),aw();break e}l=Error(X(426))}}else if(at&&a.mode&1){var v=lC(i);if(v!==null){!(v.flags&65536)&&(v.flags|=256),cC(v,i,a,s,e),B0(Al(l,a));break e}}s=l=Al(l,a),Tt!==4&&(Tt=2),iu===null?iu=[s]:iu.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,e&=-e,s.lanes|=e;var y=Qk(s,l,e);tC(s,y);break e;case 1:a=l;var S=s.type,b=s.stateNode;if(!(s.flags&128)&&(typeof S.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&(ii===null||!ii.has(b)))){s.flags|=65536,e&=-e,s.lanes|=e;var P=Jk(s,a,e);tC(s,P);break e}}s=s.return}while(s!==null)}ST(n)}catch(C){e=C,It===n&&n!==null&&(It=n=n.return);continue}break}while(!0)}function mT(){var t=rf.current;return rf.current=nf,t===null?nf:t}function aw(){(Tt===0||Tt===3||Tt===2)&&(Tt=4),Rt===null||!(oa&268435455)&&!(dg&268435455)||Gs(Rt,Vt)}function af(t,e){var n=Oe;Oe|=2;var r=mT();(Rt!==t||Vt!==e)&&(rs=null,Xi(t,e));do try{Zz();break}catch(o){gT(t,o)}while(!0);if(H0(),Oe=n,rf.current=r,It!==null)throw Error(X(261));return Rt=null,Vt=0,Tt}function Zz(){for(;It!==null;)yT(It)}function Qz(){for(;It!==null&&!P6();)yT(It)}function yT(t){var e=xT(t.alternate,t,or);t.memoizedProps=t.pendingProps,e===null?ST(t):It=e,nw.current=null}function ST(t){var e=t;do{var n=e.alternate;if(t=e.return,e.flags&32768){if(n=Wz(n,e),n!==null){n.flags&=32767,It=n;return}if(t!==null)t.flags|=32768,t.subtreeFlags=0,t.deletions=null;else{Tt=6,It=null;return}}else if(n=Kz(n,e,or),n!==null){It=n;return}if(e=e.sibling,e!==null){It=e;return}It=e=t}while(e!==null);Tt===0&&(Tt=5)}function Ui(t,e,n){var r=Be,o=Or.transition;try{Or.transition=null,Be=1,Jz(t,e,n,r)}finally{Or.transition=o,Be=r}return null}function Jz(t,e,n,r){do Sl();while(Zs!==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(O6(t,s),t===Rt&&(It=Rt=null,Vt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||eh||(eh=!0,wT(Bp,function(){return Sl(),null})),s=(n.flags&15990)!==0,n.subtreeFlags&15990||s){s=Or.transition,Or.transition=null;var i=Be;Be=1;var a=Oe;Oe|=4,nw.current=null,Vz(t,n),hT(n,t),vz(wv),Hp=!!xv,wv=xv=null,t.current=n,Yz(n),C6(),Oe=a,Be=i,Or.transition=s}else t.current=n;if(eh&&(eh=!1,Zs=t,sf=o),s=t.pendingLanes,s===0&&(ii=null),E6(n.stateNode),Yn(t,wt()),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(of)throw of=!1,t=Bv,Bv=null,t;return sf&1&&t.tag!==0&&Sl(),s=t.pendingLanes,s&1?t===Uv?au++:(au=0,Uv=t):au=0,Pi(),null}function Sl(){if(Zs!==null){var t=Q2(sf),e=Or.transition,n=Be;try{if(Or.transition=null,Be=16>t?16:t,Zs===null)var r=!1;else{if(t=Zs,Zs=null,sf=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:su(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(cT(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:su(9,s,s.return)}var y=s.sibling;if(y!==null){y.return=s.return,re=y;break e}re=s.return}}var S=t.current;for(re=S;re!==null;){i=re;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,re=b;else e:for(i=S;re!==null;){if(a=re,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:ug(9,a)}}catch(C){yt(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,Pi(),Mo&&typeof Mo.onPostCommitFiberRoot=="function")try{Mo.onPostCommitFiberRoot(ng,t)}catch{}r=!0}return r}finally{Be=n,Or.transition=e}}return!1}function bC(t,e,n){e=Al(n,e),e=Qk(t,e,1),t=si(t,e,1),e=Pn(),t!==null&&(ed(t,1,e),Yn(t,e))}function yt(t,e,n){if(t.tag===3)bC(t,t,n);else for(;e!==null;){if(e.tag===3){bC(e,t,n);break}else if(e.tag===1){var r=e.stateNode;if(typeof e.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(ii===null||!ii.has(r))){t=Al(n,t),t=Jk(e,t,1),e=si(e,t,1),t=Pn(),e!==null&&(ed(e,1,t),Yn(e,t));break}}e=e.return}}function e8(t,e,n){var r=t.pingCache;r!==null&&r.delete(e),e=Pn(),t.pingedLanes|=t.suspendedLanes&n,Rt===t&&(Vt&n)===n&&(Tt===4||Tt===3&&(Vt&130023424)===Vt&&500>wt()-ow?Xi(t,0):rw|=n),Yn(t,e)}function vT(t,e){e===0&&(t.mode&1?(e=Kd,Kd<<=1,!(Kd&130023424)&&(Kd=4194304)):e=1);var n=Pn();t=xs(t,e),t!==null&&(ed(t,e,n),Yn(t,n))}function t8(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),vT(t,n)}function n8(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),vT(t,n)}var xT;xT=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Gn.current)Hn=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Hn=!1,Hz(t,e,n);Hn=!!(t.flags&131072)}else Hn=!1,at&&e.flags&1048576&&Ck(e,qp,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;Zh(t,e),t=e.pendingProps;var o=El(e,gn.current);yl(e,n),o=Z0(null,e,r,t,o,n);var s=Q0();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,Vn(r)?(s=!0,Yp(e)):s=!1,e.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,G0(e),o.updater=cg,e.stateNode=o,o._reactInternals=e,Mv(e,r,t,n),e=Ov(null,e,r,!0,s,n)):(e.tag=0,at&&s&&N0(e),xn(null,e,o,n),e=e.child),e;case 16:r=e.elementType;e:{switch(Zh(t,e),t=e.pendingProps,o=r._init,r=o(r._payload),e.type=r,o=e.tag=o8(r),t=Kr(r,t),o){case 0:e=jv(null,e,r,t,n);break e;case 1:e=hC(null,e,r,t,n);break e;case 11:e=uC(null,e,r,t,n);break e;case 14:e=dC(null,e,r,Kr(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:Kr(r,o),jv(t,e,r,o,n);case 1:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Kr(r,o),hC(t,e,r,o,n);case 3:e:{if(rT(e),t===null)throw Error(X(387));r=e.pendingProps,s=e.memoizedState,o=s.element,Mk(t,e),Jp(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=Al(Error(X(423)),e),e=pC(t,e,r,n,o);break e}else if(r!==o){o=Al(Error(X(424)),e),e=pC(t,e,r,n,o);break e}else for(ir=oi(e.stateNode.containerInfo.firstChild),cr=e,at=!0,Yr=null,n=kk(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(kl(),r===o){e=ws(t,e,n);break e}xn(t,e,r,n)}e=e.child}return e;case 5:return Ak(e),t===null&&Ev(e),r=e.type,o=e.pendingProps,s=t!==null?t.memoizedProps:null,i=o.children,bv(r,o)?i=null:s!==null&&bv(r,s)&&(e.flags|=32),nT(t,e),xn(t,e,i,n),e.child;case 6:return t===null&&Ev(e),null;case 13:return oT(t,e,n);case 4:return V0(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=Tl(e,null,r,n):xn(t,e,r,n),e.child;case 11:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Kr(r,o),uC(t,e,r,o,n);case 7:return xn(t,e,e.pendingProps,n),e.child;case 8:return xn(t,e,e.pendingProps.children,n),e.child;case 12:return xn(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(Zp,r._currentValue),r._currentValue=i,s!==null)if(so(s.value,i)){if(s.children===o.children&&!Gn.current){e=ws(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=hs(-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),kv(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),kv(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}xn(t,e,o.children,n),e=e.child}return e;case 9:return o=e.type,r=e.pendingProps.children,yl(e,n),o=Rr(o),r=r(o),e.flags|=1,xn(t,e,r,n),e.child;case 14:return r=e.type,o=Kr(r,e.pendingProps),o=Kr(r.type,o),dC(t,e,r,o,n);case 15:return eT(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Kr(r,o),Zh(t,e),e.tag=1,Vn(r)?(t=!0,Yp(e)):t=!1,yl(e,n),Zk(e,r,o),Mv(e,r,o,n),Ov(null,e,r,!0,t,n);case 19:return sT(t,e,n);case 22:return tT(t,e,n)}throw Error(X(156,e.tag))};function wT(t,e){return Y2(t,e)}function r8(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 Ar(t,e,n,r){return new r8(t,e,n,r)}function lw(t){return t=t.prototype,!(!t||!t.isReactComponent)}function o8(t){if(typeof t=="function")return lw(t)?1:0;if(t!=null){if(t=t.$$typeof,t===E0)return 11;if(t===k0)return 14}return 2}function li(t,e){var n=t.alternate;return n===null?(n=Ar(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 ep(t,e,n,r,o,s){var i=2;if(r=t,typeof t=="function")lw(t)&&(i=1);else if(typeof t=="string")i=5;else e:switch(t){case Ga:return qi(n.children,o,s,e);case I0:i=8,o|=8;break;case ev:return t=Ar(12,n,e,o|2),t.elementType=ev,t.lanes=s,t;case tv:return t=Ar(13,n,e,o),t.elementType=tv,t.lanes=s,t;case nv:return t=Ar(19,n,e,o),t.elementType=nv,t.lanes=s,t;case A2:return hg(n,o,s,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case T2:i=10;break e;case M2:i=9;break e;case E0:i=11;break e;case k0:i=14;break e;case Hs:i=16,r=null;break e}throw Error(X(130,t==null?t:typeof t,""))}return e=Ar(i,n,e,o),e.elementType=t,e.type=r,e.lanes=s,e}function qi(t,e,n,r){return t=Ar(7,t,r,e),t.lanes=n,t}function hg(t,e,n,r){return t=Ar(22,t,r,e),t.elementType=A2,t.lanes=n,t.stateNode={isHidden:!1},t}function ay(t,e,n){return t=Ar(6,t,null,e),t.lanes=n,t}function ly(t,e,n){return e=Ar(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function s8(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=Um(0),this.expirationTimes=Um(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Um(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function cw(t,e,n,r,o,s,i,a,l){return t=new s8(t,e,n,a,l),e===1?(e=1,s===!0&&(e|=8)):e=0,s=Ar(3,null,null,e),t.current=s,s.stateNode=t,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},G0(s),t}function i8(t,e,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Wa,key:r==null?null:""+r,children:t,containerInfo:e,implementation:n}}function bT(t){if(!t)return pi;t=t._reactInternals;e:{if(xa(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(Vn(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(Vn(n))return bk(t,n,e)}return e}function PT(t,e,n,r,o,s,i,a,l){return t=cw(n,r,!0,t,o,s,i,a,l),t.context=bT(null),n=t.current,r=Pn(),o=ai(n),s=hs(r,o),s.callback=e??null,si(n,s,o),t.current.lanes=o,ed(t,o,r),Yn(t,r),t}function pg(t,e,n,r){var o=e.current,s=Pn(),i=ai(o);return n=bT(n),e.context===null?e.context=n:e.pendingContext=n,e=hs(s,i),e.payload={element:t},r=r===void 0?null:r,r!==null&&(e.callback=r),t=si(o,e,i),t!==null&&(to(t,o,i,s),Yh(t,o,i)),i}function lf(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 PC(t,e){if(t=t.memoizedState,t!==null&&t.dehydrated!==null){var n=t.retryLane;t.retryLane=n!==0&&n<e?n:e}}function uw(t,e){PC(t,e),(t=t.alternate)&&PC(t,e)}var CT=typeof reportError=="function"?reportError:function(t){console.error(t)};function dw(t){this._internalRoot=t}fg.prototype.render=dw.prototype.render=function(t){var e=this._internalRoot;if(e===null)throw Error(X(409));pg(t,e,null,null)};fg.prototype.unmount=dw.prototype.unmount=function(){var t=this._internalRoot;if(t!==null){this._internalRoot=null;var e=t.containerInfo;sa(function(){pg(null,t,null,null)}),e[vs]=null}};function fg(t){this._internalRoot=t}fg.prototype.unstable_scheduleHydration=function(t){if(t){var e=tk();t={blockedOn:null,target:t,priority:e};for(var n=0;n<Ws.length&&e!==0&&e<Ws[n].priority;n++);Ws.splice(n,0,t),n===0&&rk(t)}};function hw(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)}function gg(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11&&(t.nodeType!==8||t.nodeValue!==" react-mount-point-unstable "))}function CC(){}function a8(t,e,n,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=lf(i);s.call(c)}}var i=PT(e,r,t,0,null,!1,!1,"",CC);return t._reactRootContainer=i,t[vs]=i.current,_u(t.nodeType===8?t.parentNode:t),sa(),i}for(;o=t.lastChild;)t.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=lf(l);a.call(c)}}var l=cw(t,0,!1,null,null,!1,!1,"",CC);return t._reactRootContainer=l,t[vs]=l.current,_u(t.nodeType===8?t.parentNode:t),sa(function(){pg(e,l,n,r)}),l}function mg(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=lf(i);a.call(l)}}pg(e,i,t,o)}else i=a8(n,e,t,o,r);return lf(i)}J2=function(t){switch(t.tag){case 3:var e=t.stateNode;if(e.current.memoizedState.isDehydrated){var n=Bc(e.pendingLanes);n!==0&&(A0(e,n|1),Yn(e,wt()),!(Oe&6)&&(jl=wt()+500,Pi()))}break;case 13:sa(function(){var r=xs(t,1);if(r!==null){var o=Pn();to(r,t,1,o)}}),uw(t,1)}};j0=function(t){if(t.tag===13){var e=xs(t,134217728);if(e!==null){var n=Pn();to(e,t,134217728,n)}uw(t,134217728)}};ek=function(t){if(t.tag===13){var e=ai(t),n=xs(t,e);if(n!==null){var r=Pn();to(n,t,e,r)}uw(t,e)}};tk=function(){return Be};nk=function(t,e){var n=Be;try{return Be=t,e()}finally{Be=n}};hv=function(t,e,n){switch(e){case"input":if(sv(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=ig(r);if(!o)throw Error(X(90));O2(r),sv(r,o)}}}break;case"textarea":R2(t,n);break;case"select":e=n.value,e!=null&&pl(t,!!n.multiple,e,!1)}};U2=sw;H2=sa;var l8={usingClientEntryPoint:!1,Events:[nd,qa,ig,z2,B2,sw]},wc={findFiberByHostInstance:Wi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},c8={bundleType:wc.bundleType,version:wc.version,rendererPackageName:wc.rendererPackageName,rendererConfig:wc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:_s.ReactCurrentDispatcher,findHostInstanceByFiber:function(t){return t=G2(t),t===null?null:t.stateNode},findFiberByHostInstance:wc.findFiberByHostInstance,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 th=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!th.isDisabled&&th.supportsFiber)try{ng=th.inject(c8),Mo=th}catch{}}Sr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=l8;Sr.createPortal=function(t,e){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!hw(e))throw Error(X(200));return i8(t,e,null,n)};Sr.createRoot=function(t,e){if(!hw(t))throw Error(X(299));var n=!1,r="",o=CT;return e!=null&&(e.unstable_strictMode===!0&&(n=!0),e.identifierPrefix!==void 0&&(r=e.identifierPrefix),e.onRecoverableError!==void 0&&(o=e.onRecoverableError)),e=cw(t,1,!1,null,null,n,!1,r,o),t[vs]=e.current,_u(t.nodeType===8?t.parentNode:t),new dw(e)};Sr.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=G2(e),t=t===null?null:t.stateNode,t};Sr.flushSync=function(t){return sa(t)};Sr.hydrate=function(t,e,n){if(!gg(e))throw Error(X(200));return mg(null,t,e,!0,n)};Sr.hydrateRoot=function(t,e,n){if(!hw(t))throw Error(X(405));var r=n!=null&&n.hydratedSources||null,o=!1,s="",i=CT;if(n!=null&&(n.unstable_strictMode===!0&&(o=!0),n.identifierPrefix!==void 0&&(s=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),e=PT(e,null,t,1,n??null,o,!1,s,i),t[vs]=e.current,_u(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 fg(e)};Sr.render=function(t,e,n){if(!gg(e))throw Error(X(200));return mg(null,t,e,!1,n)};Sr.unmountComponentAtNode=function(t){if(!gg(t))throw Error(X(40));return t._reactRootContainer?(sa(function(){mg(null,null,t,!1,function(){t._reactRootContainer=null,t[vs]=null})}),!0):!1};Sr.unstable_batchedUpdates=sw;Sr.unstable_renderSubtreeIntoContainer=function(t,e,n,r){if(!gg(n))throw Error(X(200));if(t==null||t._reactInternals===void 0)throw Error(X(38));return mg(t,e,n,!1,r)};Sr.version="18.3.1-next-f1338f8080-20240426";function _T(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(_T)}catch(t){console.error(t)}}_T(),_2.exports=Sr;var wa=_2.exports;const u8=xi(wa);var IT,_C=wa;IT=QS.createRoot=_C.createRoot,QS.hydrateRoot=_C.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 d8(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),so:ae("./translations/so.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 cy="__TLDRAW_LIBRARY_VERSIONS__";function h8(){if(globalThis[cy])return globalThis[cy];const t={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,cy,{value:t,writable:!1,configurable:!1,enumerable:!1}),t}function Ci(t,e,n){if(!t||!e||!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=h8();if(r.versions.push({name:t,version:e,modules:n}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,IC(r)},100)}catch{IC(r)}}function IC(t){if(!t.versions.length||t.didWarn)return;const e=t.versions.sort((a,l)=>EC(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),uy(o,a.name,new Set).add(a.version);continue}a.version===n?r.add(a.name):(r.delete(a.name),uy(o,a.name,new Set).add(a.version))}if(o.size>0){const a=[`${Qo("[tldraw]",["bold","bgRed","textWhite"])} ${Qo("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 ${Qo(`v${n}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${Qo(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(EC).map(h=>Qo(`v${h}`,h===n?["textGreen"]:["textRed"]));return` • ❌ ${Qo(l,["bold"])} (${u.join(", ")})`})];console.log(a.join(`
41
- `)),t.didWarn=!0;return}const s=new Map;for(const a of e)uy(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=[`${Qo("[tldraw]",["bold","bgRed","textWhite"])} ${Qo("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` • ❌ ${Qo(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 EC(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 p8={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function Qo(t,e=[]){return`\x1B[${e.map(n=>p8[n]).join(";")}m${t}\x1B[m`}function uy(t,e,n){return t.has(e)?t.get(e):(t.set(e,n),n)}var ET="Expected a function",kC=NaN,f8="[object Symbol]",g8=/^\s+|\s+$/g,m8=/^[-+]0x[0-9a-f]+$/i,y8=/^0b[01]+$/i,S8=/^0o[0-7]+$/i,v8=parseInt,x8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,w8=typeof self=="object"&&self&&self.Object===Object&&self,b8=x8||w8||Function("return this")(),P8=Object.prototype,C8=P8.toString,_8=Math.max,I8=Math.min,dy=function(){return b8.Date.now()};function E8(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(ET);e=TC(e)||0,cf(n)&&(u=!!n.leading,h="maxWait"in n,s=h?_8(TC(n.maxWait)||0,e):s,p="trailing"in n?!!n.trailing:p);function f(_){var E=r,k=o;return r=o=void 0,c=_,i=t.apply(k,E),i}function g(_){return c=_,a=setTimeout(y,e),u?f(_):i}function m(_){var E=_-l,k=_-c,D=e-E;return h?I8(D,s-k):D}function v(_){var E=_-l,k=_-c;return l===void 0||E>=e||E<0||h&&k>=s}function y(){var _=dy();if(v(_))return S(_);a=setTimeout(y,m(_))}function S(_){return a=void 0,p&&r?f(_):(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:S(dy())}function C(){var _=dy(),E=v(_);if(r=arguments,o=this,l=_,E){if(a===void 0)return g(l);if(h)return a=setTimeout(y,e),f(l)}return a===void 0&&(a=setTimeout(y,e)),i}return C.cancel=b,C.flush=P,C}function k8(t,e,n){var r=!0,o=!0;if(typeof t!="function")throw new TypeError(ET);return cf(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),E8(t,e,{leading:r,maxWait:e,trailing:o})}function cf(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function T8(t){return!!t&&typeof t=="object"}function M8(t){return typeof t=="symbol"||T8(t)&&C8.call(t)==f8}function TC(t){if(typeof t=="number")return t;if(M8(t))return kC;if(cf(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=cf(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=t.replace(g8,"");var n=y8.test(t);return n||S8.test(t)?v8(t.slice(2),n?2:8):m8.test(t)?kC:+t}var A8=k8;const kT=xi(A8);var j8=200,pw="__lodash_hash_undefined__",O8=1/0,D8="[object Function]",R8="[object GeneratorFunction]",L8=/[\\^$.*+?()[\]{}|]/g,$8=/^\[object .+?Constructor\]$/,F8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,N8=typeof self=="object"&&self&&self.Object===Object&&self,fw=F8||N8||Function("return this")();function z8(t,e){var n=t?t.length:0;return!!n&&U8(t,e,0)>-1}function B8(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 U8(t,e,n){if(e!==e)return B8(t,H8,n);for(var r=n-1,o=t.length;++r<o;)if(t[r]===e)return r;return-1}function H8(t){return t!==t}function K8(t,e){return t.has(e)}function W8(t,e){return t==null?void 0:t[e]}function G8(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function TT(t){var e=-1,n=Array(t.size);return t.forEach(function(r){n[++e]=r}),n}var V8=Array.prototype,Y8=Function.prototype,MT=Object.prototype,hy=fw["__core-js_shared__"],MC=function(){var t=/[^.]+$/.exec(hy&&hy.keys&&hy.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),AT=Y8.toString,gw=MT.hasOwnProperty,X8=MT.toString,q8=RegExp("^"+AT.call(gw).replace(L8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Z8=V8.splice,Q8=mw(fw,"Map"),py=mw(fw,"Set"),Du=mw(Object,"create");function ia(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 J8(){this.__data__=Du?Du(null):{}}function e9(t){return this.has(t)&&delete this.__data__[t]}function t9(t){var e=this.__data__;if(Du){var n=e[t];return n===pw?void 0:n}return gw.call(e,t)?e[t]:void 0}function n9(t){var e=this.__data__;return Du?e[t]!==void 0:gw.call(e,t)}function r9(t,e){var n=this.__data__;return n[t]=Du&&e===void 0?pw:e,this}ia.prototype.clear=J8;ia.prototype.delete=e9;ia.prototype.get=t9;ia.prototype.has=n9;ia.prototype.set=r9;function Wl(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 o9(){this.__data__=[]}function s9(t){var e=this.__data__,n=yg(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():Z8.call(e,n,1),!0}function i9(t){var e=this.__data__,n=yg(e,t);return n<0?void 0:e[n][1]}function a9(t){return yg(this.__data__,t)>-1}function l9(t,e){var n=this.__data__,r=yg(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}Wl.prototype.clear=o9;Wl.prototype.delete=s9;Wl.prototype.get=i9;Wl.prototype.has=a9;Wl.prototype.set=l9;function Gl(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 c9(){this.__data__={hash:new ia,map:new(Q8||Wl),string:new ia}}function u9(t){return Sg(this,t).delete(t)}function d9(t){return Sg(this,t).get(t)}function h9(t){return Sg(this,t).has(t)}function p9(t,e){return Sg(this,t).set(t,e),this}Gl.prototype.clear=c9;Gl.prototype.delete=u9;Gl.prototype.get=d9;Gl.prototype.has=h9;Gl.prototype.set=p9;function uf(t){var e=-1,n=t?t.length:0;for(this.__data__=new Gl;++e<n;)this.add(t[e])}function f9(t){return this.__data__.set(t,pw),this}function g9(t){return this.__data__.has(t)}uf.prototype.add=uf.prototype.push=f9;uf.prototype.has=g9;function yg(t,e){for(var n=t.length;n--;)if(P9(t[n][0],e))return n;return-1}function m9(t){if(!jT(t)||x9(t))return!1;var e=C9(t)||G8(t)?q8:$8;return e.test(w9(t))}function y9(t,e,n){var r=-1,o=z8,s=t.length,i=!0,a=[],l=a;if(s>=j8){var c=S9(t);if(c)return TT(c);i=!1,o=K8,l=new uf}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 S9=py&&1/TT(new py([,-0]))[1]==O8?function(t){return new py(t)}:_9;function Sg(t,e){var n=t.__data__;return v9(e)?n[typeof e=="string"?"string":"hash"]:n.map}function mw(t,e){var n=W8(t,e);return m9(n)?n:void 0}function v9(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function x9(t){return!!MC&&MC in t}function w9(t){if(t!=null){try{return AT.call(t)}catch{}try{return t+""}catch{}}return""}function b9(t){return t&&t.length?y9(t):[]}function P9(t,e){return t===e||t!==t&&e!==e}function C9(t){var e=jT(t)?X8.call(t):"";return e==D8||e==R8}function jT(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function _9(){}var I9=b9;const E9=xi(I9);function OT(t){const e=(...n)=>{try{return t(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const Ru=()=>{},wn={ok(t){return{ok:!0,value:t}},err(t){return{ok:!1,error:t}}};function Ot(t,e){const n=e&&t&&typeof t=="object"&&e in t?t[e]:t;throw new Error(`Unknown switch case ${n}`)}const Le=OT((t,e)=>{if(!t)throw new Error(e||"Assertion Error")}),zn=OT((t,e)=>{if(t==null)throw new Error(e??"value must be defined");return t});function yw(){let t,e;const n=new Promise((r,o)=>{t=r,e=o});return Object.assign(n,{resolve:t,reject:e})}function Wv(t){return new Promise(e=>setTimeout(e,t))}const Hc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},k9=Hc.Good;class DT{constructor(){I(this,"startTime",0);I(this,"name","");I(this,"frames",0);I(this,"started",!1);I(this,"frame",null);I(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?Hc.Good:n>30?Hc.Mid:Hc.Poor,o=r===Hc.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${n}%c fps`,`color: white; background: ${k9};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 Sw(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 me(t){return t.filter(e=>e!=null)}function Ut(t){return t[t.length-1]}function T9(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 M9(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 RT(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 Kn(...t){if(t.length===2){const[e,n]=t;n.addInitializer(function(){Le(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});Le(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 Ro{constructor(){I(this,"items",new WeakMap)}get(e,n){return this.items.has(e)||this.items.set(e,n(e)),this.items.get(e)}}function vg(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 AC=new WeakMap;function vw(t,e){if(typeof t!="object"||t===null)return;let n=AC.get(t);n||(n={tags:{},extras:{}},AC.set(t,n)),e.tags&&(n.tags={...n.tags,...e.tags}),e.extras&&(n.extras={...n.extras,...e.extras})}async function Lo(t,e){return window.fetch(t,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const Lu=(t,e)=>{const n=new window.Image(t,e);return n.referrerPolicy="strict-origin-when-cross-origin",n};class Zr{static async dataUrlToArrayBuffer(e){return Lo(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)}})}static rewriteMimeType(e,n){return e.type===n?e:e instanceof File?new File([e],e.name,{type:n}):new Blob([e],{type:n})}}function Gv(t){let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e+""}function jC(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 OC=globalThis.crypto,A9="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",j9=128;let Hi,rl;function O9(t){!Hi||Hi.length<t?(Hi=new Uint8Array(t*j9),OC.getRandomValues(Hi),rl=0):rl+t>Hi.length&&(OC.getRandomValues(Hi),rl=0),rl+=t}function D9(t=21){O9(t-=0);let e="";for(let n=rl-t;n<rl;n++)e+=A9[Hi[n]&63];return e}let R9=D9;function ze(t){return R9(t)}/*!
54
- * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
55
- * Copyright (c) Philip van Heemstra
56
- */function L9(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 y=g+c,S=s.subarray(g,y),b=h.decode(S,{stream:!0}),P=v+b;let C,_=-1;for(;(C=i.exec(P))!==null;){_=C.index-v.length,f=m+_;break e}g=y,m+=b.length;const E=_>-1?_+u:b.length-u;v=b.slice(E)}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 $9=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 DC(t,e){let n=0;for(;t[e+n];)n+=t[e+n]+1;return n+1}function F9(t){return new TextDecoder("ascii").decode(t.slice(0,3))==="GIF"}function N9(t){const e=new Uint8Array(t);let n,r,o=0,s=0;if(!F9(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+=DC(e,o+1)+1;break;case 33:o+=2,o+=DC(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 Vv=[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"&&(Vv=new Int32Array(Vv));const z9=(t,e)=>{let n=~~e^-1;for(let r=0;r<t.length;r++)n=Vv[(n^t[r])&255]^n>>>8;return n^-1},RC=4,LC=4;class Co{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(!Co.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=Co.getChunkType(e,n);if(i==="IDAT"&&r[i]){n+=s+RC+LC;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:n+4,size:s},n+=s+RC+LC}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 Co.readChunks(e)[n]}static setPhysChunk(e,n=1,r){let o=46,s=0;const i=Co.findChunk(e,"pHYs");i&&(o=i.start,s=i.size);const a=Co.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,z9(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 B9(t){return!t||t.length<12?!1:t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80}function U9(t){const e=new Uint8Array(t);return!B9(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const LT=Object.freeze(["image/svg+xml"]),$T=Object.freeze(["image/jpeg","image/png","image/webp"]),FT=Object.freeze(["image/gif","image/apng","image/avif"]),xg=Object.freeze([...$T,...LT,...FT]),xw=Object.freeze(["video/mp4","video/webm","video/quicktime"]),H9=[...xg,...xw].join(",");class ar{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=yw();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=Lu();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 ar.usingObjectURL(e,async n=>{const r=await ar.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const n=await ar.usingObjectURL(e,ar.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(Co.isPng(r,0)){const o=Co.findChunk(r,"pHYs");if(o){const s=Co.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"?N9(await e.arrayBuffer()):e.type==="image/avif"?$9(await e.arrayBuffer()):e.type==="image/webp"?U9(await e.arrayBuffer()):e.type==="image/apng"?L9(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return FT.includes(e||"")}static isStaticImageType(e){return $T.includes(e||"")}static isVectorImageType(e){return LT.includes(e||"")}static isImageType(e){return xg.includes(e)}static async usingObjectURL(e,n){const r=URL.createObjectURL(e);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function _e(t,e,n){return t+(e-t)*n}function co(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 Ol(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 no(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function hn(t,e){if(no(t,e))return t[e]}function $C(t){return Object.keys(t)}function ut(t){return Object.values(t)}function Xn(t){return Object.entries(t)}function ww(t){return Object.fromEntries(t)}function lu(t,e){const n={};let r=!1;for(const[o,s]of Xn(t))e(o,s)?n[o]=s:r=!0;return r?n:t}function od(t,e){const n={};for(const[r,o]of Xn(t)){const s=e(r,o);n[r]=s}return n}function NT(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 K9(t){const e=W9(t.chars),n=G9(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),o=V9(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 W9(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 G9(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 V9(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var fy=null;function bw(){return fy||(fy=K9({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Qs(t,e,n){const r=n.byChar[t],o=n.byChar[e];return Math.abs(r-o)}function Pw(t,e){const n=t[0];if(n>e.mostPositive||n<e.mostNegative)throw new Error("invalid firstChar on key");return n===e.mostPositive?Qs(n,e.firstPositive,e)+1+df(t.slice(1),"positive",e):n===e.mostNegative?Qs(n,e.firstNegative,e)+1+df(t.slice(1),"negative",e):n>=e.firstPositive?Qs(n,e.firstPositive,e)+2:Qs(n,e.firstNegative,e)+2}function df(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"?Qs(r,n.mostNegative,n)+1+df(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Qs(r,n.mostPositive,n)+1+df(t.slice(1),e,n):e==="positive"?Qs(r,n.mostNegative,n)+2:Qs(r,n.mostPositive,n)+2}function wg(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 Y9(t,e,n){let[r,o]=wg(t,e,"end",n.first),s=Yv(r,o,n);s===1&&(r=r.padEnd(r.length+1,n.first),s=n.length);const i=UT(Math.floor(s/2),n);return Cw(r,i,n)}function Yv(t,e,n){const[r,o]=wg(t,e,"end",n.first).sort(),s=zT(o,r,n);return X9(s,n)}function Cw(t,e,n){const r=n.length,[o,s]=wg(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 zT(t,e,n){const r=n.length,[o,s]=wg(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 BT(t,e){return Cw(t,e.byCode[1],e)}function Xv(t,e){return zT(t,e.byCode[1],e)}function UT(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 q9(t){return t.firstPositive+t.byCode[0]}function Z9(t,e){return Pw(t,e)===t.length}function FC(t,e){hf(t,e)}function hf(t,e){const n=WT(t,e),r=Pw(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function HT(t,e){if(!Z9(t,e))throw new Error("invalid integer length: "+t)}function KT(t,e){HT(t,e);const[n,r]=GT(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=BT(r,e);return n+i}const s=J9(n,e);return VT(s,"lower",e)}function Q9(t,e){HT(t,e);const[n,r]=GT(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Xv(r,e);return n+i}const s=e7(n,e);return VT(s,"upper",e)}function WT(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 GT(t,e){const n=WT(t,e),r=t.slice(n.length);return[n,r]}function J9(t,e){const n=t>=e.firstPositive,r=BT(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 e7(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 Xv(o,e)}return!n&&r?t+e.mostPositive:Xv(t,e)}function VT(t,e,n){const r=Pw(t,n),o=e==="upper"?n.byCode[n.length-1]:n.byCode[0];return t+o.repeat(r-t.length)}function YT(t,e){const n=UT(Math.floor(Math.random()*e.jitterRange),e);return Cw(t,n,e)}function t7(t,e,n){const r=t.padEnd(t.length+e,n.first);return YT(r,n)}function n7(t,e,n){const r=hf(t,n),o=KT(r,n);let s=0;if(e!==null){const a=Yv(t,e,n);a<n.jitterRange+1&&(s=Math.max(s,NC(a,n)))}const i=Yv(t,o,n);return i<n.jitterRange+1&&(s=Math.max(s,NC(i,n))),s}function NC(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([o,s])=>s>n);return r?parseInt(r[0]):0}function r7(t,e,n=bw()){if(t!==null&&FC(t,n),e!==null&&FC(e,n),t===null&&e===null)return q9(n);if(t===null){const r=hf(e,n);return Q9(r,n)}if(e===null){const r=hf(t,n);return KT(r,n)}if(t>=e)throw new Error(t+" >= "+e);return Y9(t,e,n)}function XT(t,e,n=bw()){const r=r7(t,e,n),o=n7(r,e,n);return o?t7(r,o,n):YT(r,n)}function qT(t,e,n,r=bw()){return o7(t,e,n,r,XT,qT)}function o7(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 Vl=qT,ZT="a0";function s7(t){try{XT(t,null)}catch{throw new Error("invalid index: "+t)}}function Dl(t,e,n){return Vl(t??null,e??null,n)}function gy(t,e){return Vl(t??null,null,e)}function $u(t,e){return Vl(t??null,e??null,1)[0]}function Io(t=null){return Vl(t,null,1)[0]}function i7(t=null){return Vl(null,t,1)[0]}function Fu(t,e="a1"){return[e,...Vl(e,null,t)]}function cn(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function a7(t,e){return t.id>e.id?1:-1}function _w(t){try{return localStorage.getItem(t)}catch{return null}}function Iw(t,e){try{localStorage.setItem(t,e)}catch{}}function l7(){try{localStorage.clear()}catch{}}function QT(t){try{return sessionStorage.getItem(t)}catch{return null}}function Ew(t,e){try{sessionStorage.setItem(t,e)}catch{}}function JT(t){try{sessionStorage.removeItem(t)}catch{}}function c7(){try{sessionStorage.clear()}catch{}}const ol=[],u7=60,tp=Math.ceil(1e3/u7);let bc,my=0,qv=0;const d7=()=>{const t=ol.splice(0,ol.length);for(const e of t)e()};function eM(){if(bc)return;const t=Date.now(),e=t-qv;if(my+e<tp){bc=requestAnimationFrame(()=>{bc=void 0,eM()});return}bc=requestAnimationFrame(()=>{bc=void 0,qv=t,my=Math.min(my+e-tp,tp*10),d7()})}let zC=!1;function tM(t){return ol.includes(t)||(ol.push(t),zC||(zC=!0,qv=Date.now()-tp-1),eM()),()=>{const e=ol.indexOf(t);e>-1&&ol.splice(e,1)}}class h7{constructor(){I(this,"timeouts",new Map);I(this,"intervals",new Map);I(this,"rafs",new Map);this.setTimeout=this.setTimeout.bind(this),this.setInterval=this.setInterval.bind(this),this.requestAnimationFrame=this.requestAnimationFrame.bind(this),this.dispose=this.dispose.bind(this)}setTimeout(e,n,r,...o){const s=window.setTimeout(n,r,o),i=this.timeouts.get(e)??[];return this.timeouts.set(e,[...i,s]),s}setInterval(e,n,r,...o){const s=window.setInterval(n,r,o),i=this.intervals.get(e)??[];return this.intervals.set(e,[...i,s]),s}requestAnimationFrame(e,n){const r=window.requestAnimationFrame(n),o=this.rafs.get(e)??[];return this.rafs.set(e,[...o,r]),r}dispose(e){var n,r,o;(n=this.timeouts.get(e))==null||n.forEach(s=>clearTimeout(s)),(r=this.intervals.get(e))==null||r.forEach(s=>clearInterval(s)),(o=this.rafs.get(e))==null||o.forEach(s=>cancelAnimationFrame(s)),this.timeouts.delete(e),this.intervals.delete(e),this.rafs.delete(e)}disposeAll(){for(const e of this.timeouts.keys())this.dispose(e)}forContext(e){return{setTimeout:(n,r,...o)=>this.setTimeout(e,n,r,o),setInterval:(n,r,...o)=>this.setInterval(e,n,r,o),requestAnimationFrame:n=>this.requestAnimationFrame(e,n),dispose:()=>this.dispose(e)}}}const ge=(t,e)=>{try{return new URL(t,e)}catch{return}};function p7(t){return t!==void 0}function f7(){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 nM=f7(),tt=nM[0];nM[1];const g7=Object.getPrototypeOf(tt({}));Ci("@tldraw/utils","3.7.0-canary.383dfd14bf86","esm");var Pc=function(t){return t&&t.Math===Math&&t},In=Pc(typeof globalThis=="object"&&globalThis)||Pc(typeof window=="object"&&window)||Pc(typeof self=="object"&&self)||Pc(typeof dn=="object"&&dn)||Pc(typeof dn=="object"&&dn)||function(){return this}()||Function("return this")(),kw={},En=function(t){try{return!!t()}catch{return!0}},m7=En,_i=!m7(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),y7=En,bg=!y7(function(){var t=(function(){}).bind();return typeof t!="function"||t.hasOwnProperty("prototype")}),S7=bg,nh=Function.prototype.call,Is=S7?nh.bind(nh):function(){return nh.apply(nh,arguments)},rM={},oM={}.propertyIsEnumerable,sM=Object.getOwnPropertyDescriptor,v7=sM&&!oM.call({1:2},1);rM.f=v7?function(e){var n=sM(this,e);return!!n&&n.enumerable}:oM;var iM=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}},aM=bg,lM=Function.prototype,Zv=lM.call,x7=aM&&lM.bind.bind(Zv,Zv),Lt=aM?x7:function(t){return function(){return Zv.apply(t,arguments)}},cM=Lt,w7=cM({}.toString),b7=cM("".slice),Yl=function(t){return b7(w7(t),8,-1)},P7=Lt,C7=En,_7=Yl,yy=Object,I7=P7("".split),E7=C7(function(){return!yy("z").propertyIsEnumerable(0)})?function(t){return _7(t)==="String"?I7(t,""):yy(t)}:yy,Pg=function(t){return t==null},k7=Pg,T7=TypeError,Xl=function(t){if(k7(t))throw new T7("Can't call method on "+t);return t},M7=E7,A7=Xl,Cg=function(t){return M7(A7(t))},Sy=typeof document=="object"&&document.all,kn=typeof Sy>"u"&&Sy!==void 0?function(t){return typeof t=="function"||t===Sy}:function(t){return typeof t=="function"},j7=kn,ba=function(t){return typeof t=="object"?t!==null:j7(t)},vy=In,O7=kn,D7=function(t){return O7(t)?t:void 0},_g=function(t,e){return arguments.length<2?D7(vy[t]):vy[t]&&vy[t][e]},R7=Lt,uM=R7({}.isPrototypeOf),L7=In,BC=L7.navigator,UC=BC&&BC.userAgent,$7=UC?String(UC):"",dM=In,xy=$7,HC=dM.process,KC=dM.Deno,WC=HC&&HC.versions||KC&&KC.version,GC=WC&&WC.v8,Xr,pf;GC&&(Xr=GC.split("."),pf=Xr[0]>0&&Xr[0]<4?1:+(Xr[0]+Xr[1]));!pf&&xy&&(Xr=xy.match(/Edge\/(\d+)/),(!Xr||Xr[1]>=74)&&(Xr=xy.match(/Chrome\/(\d+)/),Xr&&(pf=+Xr[1])));var F7=pf,VC=F7,N7=En,z7=In,B7=z7.String,hM=!!Object.getOwnPropertySymbols&&!N7(function(){var t=Symbol("symbol detection");return!B7(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&VC&&VC<41}),U7=hM,pM=U7&&!Symbol.sham&&typeof Symbol.iterator=="symbol",H7=_g,K7=kn,W7=uM,G7=pM,V7=Object,fM=G7?function(t){return typeof t=="symbol"}:function(t){var e=H7("Symbol");return K7(e)&&W7(e.prototype,V7(t))},Y7=String,X7=function(t){try{return Y7(t)}catch{return"Object"}},q7=kn,Z7=X7,Q7=TypeError,Tw=function(t){if(q7(t))return t;throw new Q7(Z7(t)+" is not a function")},J7=Tw,eB=Pg,Mw=function(t,e){var n=t[e];return eB(n)?void 0:J7(n)},wy=Is,by=kn,Py=ba,tB=TypeError,nB=function(t,e){var n,r;if(e==="string"&&by(n=t.toString)&&!Py(r=wy(n,t))||by(n=t.valueOf)&&!Py(r=wy(n,t))||e!=="string"&&by(n=t.toString)&&!Py(r=wy(n,t)))return r;throw new tB("Can't convert object to primitive value")},gM={exports:{}},YC=In,rB=Object.defineProperty,Aw=function(t,e){try{rB(YC,t,{value:e,configurable:!0,writable:!0})}catch{YC[t]=e}return e},oB=In,sB=Aw,XC="__core-js_shared__",qC=gM.exports=oB[XC]||sB(XC,{});(qC.versions||(qC.versions=[])).push({version:"3.39.0",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.39.0/LICENSE",source:"https://github.com/zloirock/core-js"});var jw=gM.exports,ZC=jw,Ow=function(t,e){return ZC[t]||(ZC[t]=e||{})},iB=Xl,aB=Object,sd=function(t){return aB(iB(t))},lB=Lt,cB=sd,uB=lB({}.hasOwnProperty),Ii=Object.hasOwn||function(e,n){return uB(cB(e),n)},dB=Lt,hB=0,pB=Math.random(),fB=dB(1 .toString),mM=function(t){return"Symbol("+(t===void 0?"":t)+")_"+fB(++hB+pB,36)},gB=In,mB=Ow,QC=Ii,yB=mM,SB=hM,vB=pM,sl=gB.Symbol,Cy=mB("wks"),xB=vB?sl.for||sl:sl&&sl.withoutSetter||yB,Es=function(t){return QC(Cy,t)||(Cy[t]=SB&&QC(sl,t)?sl[t]:xB("Symbol."+t)),Cy[t]},wB=Is,JC=ba,e_=fM,bB=Mw,PB=nB,CB=Es,_B=TypeError,IB=CB("toPrimitive"),EB=function(t,e){if(!JC(t)||e_(t))return t;var n=bB(t,IB),r;if(n){if(e===void 0&&(e="default"),r=wB(n,t,e),!JC(r)||e_(r))return r;throw new _B("Can't convert object to primitive value")}return e===void 0&&(e="number"),PB(t,e)},kB=EB,TB=fM,yM=function(t){var e=kB(t,"string");return TB(e)?e:e+""},MB=In,t_=ba,Qv=MB.document,AB=t_(Qv)&&t_(Qv.createElement),SM=function(t){return AB?Qv.createElement(t):{}},jB=_i,OB=En,DB=SM,vM=!jB&&!OB(function(){return Object.defineProperty(DB("div"),"a",{get:function(){return 7}}).a!==7}),RB=_i,LB=Is,$B=rM,FB=iM,NB=Cg,zB=yM,BB=Ii,UB=vM,n_=Object.getOwnPropertyDescriptor;kw.f=RB?n_:function(e,n){if(e=NB(e),n=zB(n),UB)try{return n_(e,n)}catch{}if(BB(e,n))return FB(!LB($B.f,e,n),e[n])};var ql={},HB=_i,KB=En,xM=HB&&KB(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),WB=ba,GB=String,VB=TypeError,Pa=function(t){if(WB(t))return t;throw new VB(GB(t)+" is not an object")},YB=_i,XB=vM,qB=xM,rh=Pa,r_=yM,ZB=TypeError,_y=Object.defineProperty,QB=Object.getOwnPropertyDescriptor,Iy="enumerable",Ey="configurable",ky="writable";ql.f=YB?qB?function(e,n,r){if(rh(e),n=r_(n),rh(r),typeof e=="function"&&n==="prototype"&&"value"in r&&ky in r&&!r[ky]){var o=QB(e,n);o&&o[ky]&&(e[n]=r.value,r={configurable:Ey in r?r[Ey]:o[Ey],enumerable:Iy in r?r[Iy]:o[Iy],writable:!1})}return _y(e,n,r)}:_y:function(e,n,r){if(rh(e),n=r_(n),rh(r),XB)try{return _y(e,n,r)}catch{}if("get"in r||"set"in r)throw new ZB("Accessors not supported");return"value"in r&&(e[n]=r.value),e};var JB=_i,eU=ql,tU=iM,Dw=JB?function(t,e,n){return eU.f(t,e,tU(1,n))}:function(t,e,n){return t[e]=n,t},wM={exports:{}},Jv=_i,nU=Ii,bM=Function.prototype,rU=Jv&&Object.getOwnPropertyDescriptor,Rw=nU(bM,"name"),oU=Rw&&(function(){}).name==="something",sU=Rw&&(!Jv||Jv&&rU(bM,"name").configurable),iU={EXISTS:Rw,PROPER:oU,CONFIGURABLE:sU},aU=Lt,lU=kn,ex=jw,cU=aU(Function.toString);lU(ex.inspectSource)||(ex.inspectSource=function(t){return cU(t)});var PM=ex.inspectSource,uU=In,dU=kn,o_=uU.WeakMap,hU=dU(o_)&&/native code/.test(String(o_)),pU=Ow,fU=mM,s_=pU("keys"),CM=function(t){return s_[t]||(s_[t]=fU(t))},Lw={},gU=hU,_M=In,mU=ba,yU=Dw,Ty=Ii,My=jw,SU=CM,vU=Lw,i_="Object already initialized",tx=_M.TypeError,xU=_M.WeakMap,ff,Nu,gf,wU=function(t){return gf(t)?Nu(t):ff(t,{})},bU=function(t){return function(e){var n;if(!mU(e)||(n=Nu(e)).type!==t)throw new tx("Incompatible receiver, "+t+" required");return n}};if(gU||My.state){var yo=My.state||(My.state=new xU);yo.get=yo.get,yo.has=yo.has,yo.set=yo.set,ff=function(t,e){if(yo.has(t))throw new tx(i_);return e.facade=t,yo.set(t,e),e},Nu=function(t){return yo.get(t)||{}},gf=function(t){return yo.has(t)}}else{var Ma=SU("state");vU[Ma]=!0,ff=function(t,e){if(Ty(t,Ma))throw new tx(i_);return e.facade=t,yU(t,Ma,e),e},Nu=function(t){return Ty(t,Ma)?t[Ma]:{}},gf=function(t){return Ty(t,Ma)}}var IM={set:ff,get:Nu,has:gf,enforce:wU,getterFor:bU},$w=Lt,PU=En,CU=kn,oh=Ii,nx=_i,_U=iU.CONFIGURABLE,IU=PM,EM=IM,EU=EM.enforce,kU=EM.get,a_=String,np=Object.defineProperty,TU=$w("".slice),MU=$w("".replace),AU=$w([].join),jU=nx&&!PU(function(){return np(function(){},"length",{value:8}).length!==8}),OU=String(String).split("String"),DU=wM.exports=function(t,e,n){TU(a_(e),0,7)==="Symbol("&&(e="["+MU(a_(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!oh(t,"name")||_U&&t.name!==e)&&(nx?np(t,"name",{value:e,configurable:!0}):t.name=e),jU&&n&&oh(n,"arity")&&t.length!==n.arity&&np(t,"length",{value:n.arity});try{n&&oh(n,"constructor")&&n.constructor?nx&&np(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch{}var r=EU(t);return oh(r,"source")||(r.source=AU(OU,typeof e=="string"?e:"")),t};Function.prototype.toString=DU(function(){return CU(this)&&kU(this).source||IU(this)},"toString");var RU=wM.exports,LU=kn,$U=ql,FU=RU,NU=Aw,kM=function(t,e,n,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:e;if(LU(n)&&FU(n,s,r),r.global)o?t[e]=n:NU(e,n);else{try{r.unsafe?t[e]&&(o=!0):delete t[e]}catch{}o?t[e]=n:$U.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},TM={},zU=Math.ceil,BU=Math.floor,UU=Math.trunc||function(e){var n=+e;return(n>0?BU:zU)(n)},HU=UU,Ca=function(t){var e=+t;return e!==e||e===0?0:HU(e)},KU=Ca,WU=Math.max,GU=Math.min,VU=function(t,e){var n=KU(t);return n<0?WU(n+e,0):GU(n,e)},YU=Ca,XU=Math.min,MM=function(t){var e=YU(t);return e>0?XU(e,9007199254740991):0},qU=MM,id=function(t){return qU(t.length)},ZU=Cg,QU=VU,JU=id,l_=function(t){return function(e,n,r){var o=ZU(e),s=JU(o);if(s===0)return!t&&-1;var i=QU(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}},eH={includes:l_(!0),indexOf:l_(!1)},tH=Lt,Ay=Ii,nH=Cg,rH=eH.indexOf,oH=Lw,c_=tH([].push),AM=function(t,e){var n=nH(t),r=0,o=[],s;for(s in n)!Ay(oH,s)&&Ay(n,s)&&c_(o,s);for(;e.length>r;)Ay(n,s=e[r++])&&(~rH(o,s)||c_(o,s));return o},Fw=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],sH=AM,iH=Fw,aH=iH.concat("length","prototype");TM.f=Object.getOwnPropertyNames||function(e){return sH(e,aH)};var jM={};jM.f=Object.getOwnPropertySymbols;var lH=_g,cH=Lt,uH=TM,dH=jM,hH=Pa,pH=cH([].concat),fH=lH("Reflect","ownKeys")||function(e){var n=uH.f(hH(e)),r=dH.f;return r?pH(n,r(e)):n},u_=Ii,gH=fH,mH=kw,yH=ql,SH=function(t,e,n){for(var r=gH(e),o=yH.f,s=mH.f,i=0;i<r.length;i++){var a=r[i];!u_(t,a)&&!(n&&u_(n,a))&&o(t,a,s(e,a))}},vH=En,xH=kn,wH=/#|\.prototype\./,ad=function(t,e){var n=PH[bH(t)];return n===_H?!0:n===CH?!1:xH(e)?vH(e):!!e},bH=ad.normalize=function(t){return String(t).replace(wH,".").toLowerCase()},PH=ad.data={},CH=ad.NATIVE="N",_H=ad.POLYFILL="P",IH=ad,sh=In,EH=kw.f,kH=Dw,TH=kM,MH=Aw,AH=SH,jH=IH,Zl=function(t,e){var n=t.target,r=t.global,o=t.stat,s,i,a,l,c,u;if(r?i=sh:o?i=sh[n]||MH(n,{}):i=sh[n]&&sh[n].prototype,i)for(a in e){if(c=e[a],t.dontCallGetSet?(u=EH(i,a),l=u&&u.value):l=i[a],s=jH(r?a:n+(o?".":"#")+a,t.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;AH(c,l)}(t.sham||l&&l.sham)&&kH(c,"sham",!0),TH(i,a,c,t)}},OM={},OH=AM,DH=Fw,RH=Object.keys||function(e){return OH(e,DH)},LH=_i,$H=xM,FH=ql,NH=Pa,zH=Cg,BH=RH;OM.f=LH&&!$H?Object.defineProperties:function(e,n){NH(e);for(var r=zH(n),o=BH(n),s=o.length,i=0,a;s>i;)FH.f(e,a=o[i++],r[a]);return e};var UH=_g,HH=UH("document","documentElement"),KH=Pa,WH=OM,d_=Fw,GH=Lw,VH=HH,YH=SM,XH=CM,h_=">",p_="<",rx="prototype",ox="script",DM=XH("IE_PROTO"),jy=function(){},RM=function(t){return p_+ox+h_+t+p_+"/"+ox+h_},f_=function(t){t.write(RM("")),t.close();var e=t.parentWindow.Object;return t=null,e},qH=function(){var t=YH("iframe"),e="java"+ox+":",n;return t.style.display="none",VH.appendChild(t),t.src=String(e),n=t.contentWindow.document,n.open(),n.write(RM("document.F=Object")),n.close(),n.F},ih,rp=function(){try{ih=new ActiveXObject("htmlfile")}catch{}rp=typeof document<"u"?document.domain&&ih?f_(ih):qH():f_(ih);for(var t=d_.length;t--;)delete rp[rx][d_[t]];return rp()};GH[DM]=!0;var LM=Object.create||function(e,n){var r;return e!==null?(jy[rx]=KH(e),r=new jy,jy[rx]=null,r[DM]=e):r=rp(),n===void 0?r:WH.f(r,n)},ZH=Es,QH=LM,JH=ql.f,sx=ZH("unscopables"),ix=Array.prototype;ix[sx]===void 0&&JH(ix,sx,{configurable:!0,value:QH(null)});var Nw=function(t){ix[sx][t]=!0},eK=Zl,tK=sd,nK=id,rK=Ca,oK=Nw;eK({target:"Array",proto:!0},{at:function(e){var n=tK(this),r=nK(n),o=rK(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:n[s]}});oK("at");var sK=In,iK=Lt,ld=function(t,e){return iK(sK[t].prototype[e])},aK=ld;aK("Array","at");var lK=Yl,$M=Array.isArray||function(e){return lK(e)==="Array"},cK=TypeError,uK=9007199254740991,dK=function(t){if(t>uK)throw cK("Maximum allowed index exceeded");return t},hK=Yl,pK=Lt,fK=function(t){if(hK(t)==="Function")return pK(t)},g_=fK,gK=Tw,mK=bg,yK=g_(g_.bind),SK=function(t,e){return gK(t),e===void 0?t:mK?yK(t,e):function(){return t.apply(e,arguments)}},vK=$M,xK=id,wK=dK,bK=SK,FM=function(t,e,n,r,o,s,i,a){for(var l=o,c=0,u=i?bK(i,a):!1,h,p;c<r;)c in n&&(h=u?u(n[c],c,e):n[c],s>0&&vK(h)?(p=xK(h),l=FM(t,e,h,p,l,s-1)-1):(wK(l+1),t[l]=h),l++),c++;return l},NM=FM,PK=Es,CK=PK("toStringTag"),zM={};zM[CK]="z";var _K=String(zM)==="[object z]",IK=_K,EK=kn,op=Yl,kK=Es,TK=kK("toStringTag"),MK=Object,AK=op(function(){return arguments}())==="Arguments",jK=function(t,e){try{return t[e]}catch{}},BM=IK?op:function(t){var e,n,r;return t===void 0?"Undefined":t===null?"Null":typeof(n=jK(e=MK(t),TK))=="string"?n:AK?op(e):(r=op(e))==="Object"&&EK(e.callee)?"Arguments":r},OK=Lt,DK=En,UM=kn,RK=BM,LK=_g,$K=PM,HM=function(){},KM=LK("Reflect","construct"),zw=/^\s*(?:class|function)\b/,FK=OK(zw.exec),NK=!zw.test(HM),Cc=function(e){if(!UM(e))return!1;try{return KM(HM,[],e),!0}catch{return!1}},WM=function(e){if(!UM(e))return!1;switch(RK(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return NK||!!FK(zw,$K(e))}catch{return!0}};WM.sham=!0;var zK=!KM||DK(function(){var t;return Cc(Cc.call)||!Cc(Object)||!Cc(function(){t=!0})||t})?WM:Cc,m_=$M,BK=zK,UK=ba,HK=Es,KK=HK("species"),y_=Array,WK=function(t){var e;return m_(t)&&(e=t.constructor,BK(e)&&(e===y_||m_(e.prototype))?e=void 0:UK(e)&&(e=e[KK],e===null&&(e=void 0))),e===void 0?y_:e},GK=WK,GM=function(t,e){return new(GK(t))(e===0?0:e)},VK=Zl,YK=NM,XK=Tw,qK=sd,ZK=id,QK=GM;VK({target:"Array",proto:!0},{flatMap:function(e){var n=qK(this),r=ZK(n),o;return XK(e),o=QK(n,0),o.length=YK(o,n,n,r,0,1,e,arguments.length>1?arguments[1]:void 0),o}});var JK=Nw;JK("flatMap");var eW=ld;eW("Array","flatMap");var tW=Zl,nW=NM,rW=sd,oW=id,sW=Ca,iW=GM;tW({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,n=rW(this),r=oW(n),o=iW(n,0);return o.length=nW(o,n,n,r,0,e===void 0?1:sW(e)),o}});var aW=Nw;aW("flat");var lW=ld;lW("Array","flat");var cW=BM,uW=String,cd=function(t){if(cW(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return uW(t)},dW=Zl,hW=Lt,pW=Xl,fW=Ca,gW=cd,mW=En,yW=hW("".charAt),SW=mW(function(){return"𠮷".at(-2)!=="\uD842"});dW({target:"String",proto:!0,forced:SW},{at:function(e){var n=gW(pW(this)),r=n.length,o=fW(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:yW(n,s)}});var vW=ld;vW("String","at");var xW=Pa,VM=function(){var t=xW(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},Bw=En,wW=In,Uw=wW.RegExp,Hw=Bw(function(){var t=Uw("a","y");return t.lastIndex=2,t.exec("abcd")!==null}),bW=Hw||Bw(function(){return!Uw("a","y").sticky}),PW=Hw||Bw(function(){var t=Uw("^r","gy");return t.lastIndex=2,t.exec("str")!==null}),CW={BROKEN_CARET:PW,MISSED_STICKY:bW,UNSUPPORTED_Y:Hw},_W=En,IW=In,EW=IW.RegExp,kW=_W(function(){var t=EW(".","s");return!(t.dotAll&&t.test(`
68
- `)&&t.flags==="s")}),TW=En,MW=In,AW=MW.RegExp,jW=TW(function(){var t=AW("(?<a>b)","g");return t.exec("b").groups.a!=="b"||"b".replace(t,"$<a>c")!=="bc"}),il=Is,Ig=Lt,OW=cd,DW=VM,RW=CW,LW=Ow,$W=LM,FW=IM.get,NW=kW,zW=jW,BW=LW("native-string-replace",String.prototype.replace),mf=RegExp.prototype.exec,ax=mf,UW=Ig("".charAt),HW=Ig("".indexOf),KW=Ig("".replace),Oy=Ig("".slice),lx=function(){var t=/a/,e=/b*/g;return il(mf,t,"a"),il(mf,e,"a"),t.lastIndex!==0||e.lastIndex!==0}(),YM=RW.BROKEN_CARET,cx=/()??/.exec("")[1]!==void 0,WW=lx||cx||YM||NW||zW;WW&&(ax=function(e){var n=this,r=FW(n),o=OW(e),s=r.raw,i,a,l,c,u,h,p;if(s)return s.lastIndex=n.lastIndex,i=il(ax,s,o),n.lastIndex=s.lastIndex,i;var f=r.groups,g=YM&&n.sticky,m=il(DW,n),v=n.source,y=0,S=o;if(g&&(m=KW(m,"y",""),HW(m,"g")===-1&&(m+="g"),S=Oy(o,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&UW(o,n.lastIndex-1)!==`
69
- `)&&(v="(?: "+v+")",S=" "+S,y++),a=new RegExp("^(?:"+v+")",m)),cx&&(a=new RegExp("^"+v+"$(?!\\s)",m)),lx&&(l=n.lastIndex),c=il(mf,g?a:n,S),g?c?(c.input=Oy(c.input,y),c[0]=Oy(c[0],y),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:lx&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),cx&&c&&c.length>1&&il(BW,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=$W(null),u=0;u<f.length;u++)p=f[u],h[p[0]]=c[p[1]];return c});var Kw=ax,GW=Zl,S_=Kw;GW({target:"RegExp",proto:!0,forced:/./.exec!==S_},{exec:S_});var VW=bg,XM=Function.prototype,v_=XM.apply,x_=XM.call,YW=typeof Reflect=="object"&&Reflect.apply||(VW?x_.bind(v_):function(){return x_.apply(v_,arguments)}),w_=Is,b_=kM,XW=Kw,P_=En,qM=Es,qW=Dw,ZW=qM("species"),Dy=RegExp.prototype,QW=function(t,e,n,r){var o=qM(t),s=!P_(function(){var c={};return c[o]=function(){return 7},""[t](c)!==7}),i=s&&!P_(function(){var c=!1,u=/a/;return t==="split"&&(u={},u.constructor={},u.constructor[ZW]=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===XW||g===Dy.exec?s&&!f?{done:!0,value:w_(a,u,h,p)}:{done:!0,value:w_(c,h,u,p)}:{done:!1}});b_(String.prototype,t,l[0]),b_(Dy,o,l[1])}r&&qW(Dy[o],"sham",!0)},Ww=Lt,JW=Ca,eG=cd,tG=Xl,nG=Ww("".charAt),C_=Ww("".charCodeAt),rG=Ww("".slice),__=function(t){return function(e,n){var r=eG(tG(e)),o=JW(n),s=r.length,i,a;return o<0||o>=s?t?"":void 0:(i=C_(r,o),i<55296||i>56319||o+1===s||(a=C_(r,o+1))<56320||a>57343?t?nG(r,o):i:t?rG(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},oG={codeAt:__(!1),charAt:__(!0)},sG=oG.charAt,iG=function(t,e,n){return e+(n?sG(t,e).length:1)},Gw=Lt,aG=sd,lG=Math.floor,Ry=Gw("".charAt),cG=Gw("".replace),Ly=Gw("".slice),uG=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,dG=/\$([$&'`]|\d{1,2})/g,ZM=function(t,e,n,r,o,s){var i=n+t.length,a=r.length,l=dG;return o!==void 0&&(o=aG(o),l=uG),cG(s,l,function(c,u){var h;switch(Ry(u,0)){case"$":return"$";case"&":return t;case"`":return Ly(e,0,n);case"'":return Ly(e,i);case"<":h=o[Ly(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=lG(p/10);return f===0?c:f<=a?r[f-1]===void 0?Ry(u,1):r[f-1]+Ry(u,1):c}h=r[p-1]}return h===void 0?"":h})},I_=Is,hG=Pa,pG=kn,fG=Yl,gG=Kw,mG=TypeError,yG=function(t,e){var n=t.exec;if(pG(n)){var r=I_(n,t,e);return r!==null&&hG(r),r}if(fG(t)==="RegExp")return I_(gG,t,e);throw new mG("RegExp#exec called on incompatible receiver")},SG=YW,E_=Is,Eg=Lt,vG=QW,xG=En,wG=Pa,bG=kn,PG=Pg,CG=Ca,_G=MM,Aa=cd,IG=Xl,EG=iG,kG=Mw,TG=ZM,MG=yG,AG=Es,ux=AG("replace"),jG=Math.max,OG=Math.min,DG=Eg([].concat),$y=Eg([].push),k_=Eg("".indexOf),T_=Eg("".slice),RG=function(t){return t===void 0?t:String(t)},LG=function(){return"a".replace(/./,"$0")==="$0"}(),M_=function(){return/./[ux]?/./[ux]("a","$0")==="":!1}(),$G=!xG(function(){var t=/./;return t.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(t,"$<a>")!=="7"});vG("replace",function(t,e,n){var r=M_?"$":"$0";return[function(s,i){var a=IG(this),l=PG(s)?void 0:kG(s,ux);return l?E_(l,s,a,i):E_(e,Aa(a),s,i)},function(o,s){var i=wG(this),a=Aa(o);if(typeof s=="string"&&k_(s,r)===-1&&k_(s,"$<")===-1){var l=n(e,i,a,s);if(l.done)return l.value}var c=bG(s);c||(s=Aa(s));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=MG(i,a),!(f===null||($y(p,f),!u));){var g=Aa(f[0]);g===""&&(i.lastIndex=EG(a,_G(i.lastIndex),h))}for(var m="",v=0,y=0;y<p.length;y++){f=p[y];for(var S=Aa(f[0]),b=jG(OG(CG(f.index),a.length),0),P=[],C,_=1;_<f.length;_++)$y(P,RG(f[_]));var E=f.groups;if(c){var k=DG([S],P,b,a);E!==void 0&&$y(k,E),C=Aa(SG(s,void 0,k))}else C=TG(S,a,b,P,E,s);b>=v&&(m+=T_(a,v,b)+C,v=b+S.length)}return m+T_(a,v)}]},!$G||!LG||M_);var FG=ba,NG=Yl,zG=Es,BG=zG("match"),UG=function(t){var e;return FG(t)&&((e=t[BG])!==void 0?!!e:NG(t)==="RegExp")},HG=Is,KG=Ii,WG=uM,GG=VM,A_=RegExp.prototype,VG=function(t){var e=t.flags;return e===void 0&&!("flags"in A_)&&!KG(t,"flags")&&WG(A_,t)?HG(GG,t):e},YG=Zl,XG=Is,Vw=Lt,j_=Xl,qG=kn,ZG=Pg,QG=UG,_c=cd,JG=Mw,eV=VG,tV=ZM,nV=Es,rV=nV("replace"),oV=TypeError,Fy=Vw("".indexOf);Vw("".replace);var O_=Vw("".slice),sV=Math.max;YG({target:"String",proto:!0},{replaceAll:function(e,n){var r=j_(this),o,s,i,a,l,c,u,h,p,f,g=0,m="";if(!ZG(e)){if(o=QG(e),o&&(s=_c(j_(eV(e))),!~Fy(s,"g")))throw new oV("`.replaceAll` does not allow non-global regexes");if(i=JG(e,rV),i)return XG(i,e,r,n)}for(a=_c(r),l=_c(e),c=qG(n),c||(n=_c(n)),u=l.length,h=sV(1,u),p=Fy(a,l);p!==-1;)f=c?_c(n(l,p,a)):tV(l,a,p,[],void 0,n),m+=O_(a,g,p)+f,g=p+u,p=p+h>a.length?-1:Fy(a,l,p+h);return g<a.length&&(m+=O_(a,g)),m}});var iV=ld;iV("String","replaceAll");function QM(t){return t&&typeof t=="object"&&"parents"in t}function JM(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 yf(t,e){if(t.children.remove(e)&&t.children.isEmpty&&QM(t))for(let n=0,r=t.parents.length;n<r;n++)yf(t.parents[n],t)}function Yw(t,e){if(t.children.add(e)&&QM(t))for(let n=0,r=t.parents.length;n<r;n++)Yw(t.parents[n],t)}function eA(t,e){return t===e||Object.is(t,e)||!!(t&&e&&typeof t.equals=="function"&&t.equals(e))}function Ei(t,e){const n=Symbol.for(`com.tldraw.state/${t}`),r=globalThis;return r[n]??(r[n]=e()),r[n]}const ps=Ei("empty_array",()=>Object.freeze([])),D_=8;class Sf{constructor(){I(this,"arraySize",0);I(this,"array",Array(D_));I(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<D_?(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 ur=Symbol.for("com.tldraw.state/RESET_VALUE");class tA{constructor(e){I(this,"index",0);I(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,n,r){if(r!==void 0){if(r===ur){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 ur;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 ur}}class aV{constructor(e,n){I(this,"offset",0);I(this,"maybeRemoved");this.below=e,this.child=n}}const st=Ei("capture",()=>({stack:null}));function ah(t){const e=st.stack;st.stack=null;try{return t()}finally{st.stack=e}}function nA(t){st.stack=new aV(st.stack,t),t.parentSet.clear()}function rA(){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)||yf(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)||yf(n,t.child)}}function vf(t){if(st.stack){if(st.stack.child.parentSet.has(t))return;if(st.stack.child.parentSet.add(t),st.stack.child.isActivelyListening&&Yw(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 Js=-1;class lV{constructor(e,n,r){I(this,"_isActivelyListening",!1);I(this,"lastTraversedEpoch",Js);I(this,"lastReactedEpoch",Js);I(this,"_scheduleCount",0);I(this,"parentSet",new Sf);I(this,"parentEpochs",[]);I(this,"parents",[]);I(this,"_scheduleEffect");I(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!==$n()){if(this.parents.length&&!JM(this)){this.lastReactedEpoch=$n();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++)Yw(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,n=this.parents.length;e<n;e++)yf(this.parents[e],this)}execute(){try{nA(this);const e=$n(),n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,n}finally{rA()}}}const Ql=Ei("EffectScheduler",()=>lV);function jo(t,e,n){const r=new Ql(t,e,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function cV(t,e,n){const r=new Ql(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 uV{constructor(e){I(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(Re.globalIsReacting)for(const e of this.initialAtomValues.keys())sA(e);else this.isRoot?oA(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,n)=>{this.parent.initialAtomValues.has(n)||this.parent.initialAtomValues.set(n,e)})}abort(){Re.globalEpoch++,this.initialAtomValues.forEach((e,n)=>{var r;n.set(e),(r=n.historyBuffer)==null||r.clear()}),this.commit()}}const Re=Ei("transactions",()=>({globalEpoch:Js+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Js+1}));function dV(){return Re.reactionEpoch}function $n(){return Re.globalEpoch}function hV(){return Re.globalIsReacting}function Xw(t,e){e.lastTraversedEpoch!==Re.globalEpoch&&(e.lastTraversedEpoch=Re.globalEpoch,e instanceof Ql?t.add(e):e.children.visit(n=>Xw(t,n)))}function oA(t){var n;if(Re.globalIsReacting)throw new Error("flushChanges cannot be called during a reaction");const e=Re.currentTransaction;try{Re.currentTransaction=null,Re.globalIsReacting=!0,Re.reactionEpoch=Re.globalEpoch;const r=new Set;for(const s of t)s.children.visit(i=>Xw(r,i));for(const s of r)s.maybeScheduleEffect();let o=0;for(;(n=Re.cleanupReactors)!=null&&n.size;){if(o++>1e3)throw new Error("Reaction update depth limit exceeded");const s=Re.cleanupReactors;Re.cleanupReactors=null;for(const i of s)i.maybeScheduleEffect()}}finally{Re.cleanupReactors=null,Re.globalIsReacting=!1,Re.currentTransaction=e}}function pV(t,e){Re.currentTransaction?Re.currentTransaction.initialAtomValues.has(t)||Re.currentTransaction.initialAtomValues.set(t,e):Re.globalIsReacting?sA(t):oA([t])}function sA(t){const e=Re.cleanupReactors??(Re.cleanupReactors=new Set);t.children.visit(n=>Xw(e,n))}function fV(){Re.globalEpoch++}function gV(t){const e=new uV(Re.currentTransaction);Re.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{Re.currentTransaction=Re.currentTransaction.parent}}function Oo(t){return Re.currentTransaction?t():gV(t)}class mV{constructor(e,n,r){I(this,"isEqual");I(this,"computeDiff");I(this,"lastChangedEpoch",$n());I(this,"children",new Sf);I(this,"historyBuffer");this.name=e,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new tA(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return vf(this),this.current}set(e,n){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,e))??eA(this.current,e))return this.current;fV(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,$n(),n??((s=this.computeDiff)==null?void 0:s.call(this,this.current,e,this.lastChangedEpoch,$n()))??ur),this.lastChangedEpoch=$n();const r=this.current;return this.current=e,pV(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var n;return vf(this),e>=this.lastChangedEpoch?ps:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const yV=Ei("Atom",()=>mV);function Et(t,e,n){return new yV(t,e,n)}let R_=!1;function SV(){R_||(R_=!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 Kc=Symbol.for("com.tldraw.state/UNINITIALIZED");function Zi(t){return t===Kc}const dx=Ei("WithDiff",()=>class{constructor(e,n){this.value=e,this.diff=n}});function Wc(t,e){return new dx(t,e)}class vV{constructor(e,n,r){I(this,"lastChangedEpoch",Js);I(this,"lastTraversedEpoch",Js);I(this,"lastCheckedEpoch",Js);I(this,"parentSet",new Sf);I(this,"parents",[]);I(this,"parentEpochs",[]);I(this,"children",new Sf);I(this,"historyBuffer");I(this,"state",Kc);I(this,"error",null);I(this,"computeDiff");I(this,"isEqual");this.name=e,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new tA(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??eA}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var o;const n=this.lastChangedEpoch===Js,r=$n();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&hV()&&this.lastTraversedEpoch<dV()||!JM(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{nA(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof dx?s.value:s,a=this.state===Kc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=s instanceof dx?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,$n(),l??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,$n()))??ur)}this.lastChangedEpoch=$n(),this.state=i}return this.error=null,this.lastCheckedEpoch=$n(),this.state}catch(s){if(this.state!==Kc&&(this.state=Kc,this.lastChangedEpoch=$n()),this.lastCheckedEpoch=$n(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!e)throw s;return this.state}finally{rA()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{vf(this)}}getDiffSince(e){var n;return this.__unsafe__getWithoutCapture(!0),vf(this),e>=this.lastChangedEpoch?ps:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const kg=Ei("Computed",()=>vV);function xV(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 kg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[iA]=!0,r}function wV(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 kg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function bV(t,e,n){Le(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 kg(String(n.name),e.bind(this),t),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:s})),s.get()};return o[iA]=!0,o}function L_(t={},e){if(e.length===2){const[n,r]=e;return bV(t,n,r)}else{const[n,r,o]=e;return o.get?(SV(),wV(t,n,r,o)):xV(t,n,r,o)}}const iA="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const t=arguments[0];return(...e)=>L_(t,e)}else return typeof arguments[0]=="string"?new kg(arguments[0],arguments[1],arguments[2]):L_(void 0,arguments)}const aA=1,PV=Ei("apiVersion",()=>aA);if(PV!==aA)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");Ci("@tldraw/state","3.7.0-canary.383dfd14bf86","esm");function Tg(t,e,n=[]){const r=Te.useRef(e);r.current=e;const[o,s,i]=Te.useMemo(()=>{let a=null;const l=h=>(a=h,()=>{a=null}),c=new Ql(`useStateTracking(${t})`,()=>{var h;return(h=r.current)==null?void 0:h.call(r)},{scheduleEffect(){a==null||a()}});return[c,l,()=>c.scheduleCount]},[t,...n]);return Te.useSyncExternalStore(s,i,i),Te.useEffect(()=>(o.attach(),o.maybeScheduleEffect(),()=>{o.detach()}),[o]),o.execute()}const $_={apply(t,e,n){return Tg(t.displayName??t.name??"tracked(???)",()=>t.apply(e,n))}},CV=Symbol.for("react.memo"),_V=Symbol.for("react.forward_ref");function qt(t){let e=null;const n=t.$$typeof;return n===CV&&(t=t.type,e=t.compare),n===_V?w.memo(w.forwardRef(new Proxy(t.render,$_))):w.memo(new Proxy(t,$_),e)}function qw(t,e,n){return w.useState(()=>{const r=typeof e=="function"?e():e;return Et(`useAtom(${t})`,r,n)})[0]}function IV(){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 ci(t,e,n=ps){w.useEffect(()=>{const r=new Ql(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=>jo(`useValue(${n})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return w.useSyncExternalStore(s,i,i)}finally{r.current=!1}}Ci("@tldraw/state-react","3.7.0-canary.383dfd14bf86","esm");const EV=(t,e)=>e.some(n=>t instanceof n);let F_,N_;function kV(){return F_||(F_=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function TV(){return N_||(N_=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const lA=new WeakMap,hx=new WeakMap,cA=new WeakMap,Ny=new WeakMap,Zw=new WeakMap;function MV(t){const e=new Promise((n,r)=>{const o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{n(fs(t.result)),o()},i=()=>{r(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return e.then(n=>{n instanceof IDBCursor&&lA.set(n,t)}).catch(()=>{}),Zw.set(e,t),e}function AV(t){if(hx.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)});hx.set(t,e)}let px={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return hx.get(t);if(e==="objectStoreNames")return t.objectStoreNames||cA.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return fs(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 jV(t){px=t(px)}function OV(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...n){const r=t.call(zy(this),e,...n);return cA.set(r,e.sort?e.sort():[e]),fs(r)}:TV().includes(t)?function(...e){return t.apply(zy(this),e),fs(lA.get(this))}:function(...e){return fs(t.apply(zy(this),e))}}function DV(t){return typeof t=="function"?OV(t):(t instanceof IDBTransaction&&AV(t),EV(t,kV())?new Proxy(t,px):t)}function fs(t){if(t instanceof IDBRequest)return MV(t);if(Ny.has(t))return Ny.get(t);const e=DV(t);return e!==t&&(Ny.set(t,e),Zw.set(e,t)),e}const zy=t=>Zw.get(t);function uA(t,e,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(t,e),a=fs(i);return r&&i.addEventListener("upgradeneeded",l=>{r(fs(i.result),l.oldVersion,l.newVersion,fs(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 dA(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);return e&&n.addEventListener("blocked",r=>e(r.oldVersion,r)),fs(n).then(()=>{})}const RV=["get","getKey","getAll","getAllKeys","count"],LV=["put","add","delete","clear"],By=new Map;function z_(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(By.get(e))return By.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,o=LV.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(o||RV.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 By.set(e,s),s}jV(t=>({...t,get:(e,n,r)=>z_(e,n)||t.get(e,n,r),has:(e,n)=>!!z_(e,n)||t.has(e,n)}));const $V="TLDRAW_DOCUMENT_v2",FV="TLDRAW_ASSET_STORE_v1",hA="TLDRAW_DB_NAME_INDEX_v2",Ce={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function pA(t){const e=$V+t;return zV(e),await uA(e,4,{upgrade(n){n.objectStoreNames.contains(Ce.Records)||n.createObjectStore(Ce.Records),n.objectStoreNames.contains(Ce.Schema)||n.createObjectStore(Ce.Schema),n.objectStoreNames.contains(Ce.SessionState)||n.createObjectStore(Ce.SessionState),n.objectStoreNames.contains(Ce.Assets)||n.createObjectStore(Ce.Assets)}})}async function NV(t){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(p=>p.name):Qw(),n=FV+t;if(!e.find(p=>p===n))return;const o=await uA(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 pA(t),u=c.transaction([Ce.Assets],"readwrite"),h=u.objectStore(Ce.Assets);for(const[p,f]of l)h.put(f,p);await u.done,o.close(),c.close(),await dA(n)}const mu=class mu{constructor(e){I(this,"getDbPromise");I(this,"isClosed",!1);I(this,"pendingTransactionSet",new Set);mu.connectedInstances.add(this),this.getDbPromise=(async()=>(await NV(e),await pA(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Ru)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),mu.connectedInstances.delete(this))}tx(e,n,r){const o=(async()=>{Le(!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",[Ce.Records,Ce.Schema,Ce.SessionState],async n=>{var l,c;const r=n.objectStore(Ce.Records),o=n.objectStore(Ce.Schema),s=n.objectStore(Ce.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(Ce.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:n,sessionId:r,sessionStateSnapshot:o}){await this.tx("readwrite",[Ce.Records,Ce.Schema,Ce.SessionState],async s=>{const i=s.objectStore(Ce.Records),a=s.objectStore(Ce.Schema),l=s.objectStore(Ce.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(),Ce.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",[Ce.Records,Ce.Schema,Ce.SessionState],async s=>{const i=s.objectStore(Ce.Records),a=s.objectStore(Ce.Schema),l=s.objectStore(Ce.SessionState);await i.clear();for(const[c,u]of Object.entries(n))await i.put(u,c);a.put(e.serialize(),Ce.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",[Ce.SessionState],async e=>{const n=e.objectStore(Ce.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",[Ce.Assets],async n=>await n.objectStore(Ce.Assets).get(e))}async storeAsset(e,n){await this.tx("readwrite",[Ce.Assets],async r=>{await r.objectStore(Ce.Assets).put(n,e)})}};I(mu,"connectedInstances",new Set);let xf=mu;function Qw(){const t=JSON.parse(_w(hA)||"[]")??[];return Array.isArray(t)?t:[]}function zV(t){const e=new Set(Qw());e.add(t),Iw(hA,JSON.stringify([...e]))}class sp{constructor(e){I(this,"nextValue");I(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 Mg{constructor(e,n){I(this,"createDefaultProperties");I(this,"validator");I(this,"ephemeralKeys");I(this,"ephemeralKeySet");I(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 Xn(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??ze())}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 Mg(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 Ko(t,e){return new Mg(t,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function wf(){return{added:{},updated:{},removed:{}}}function fx(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 fA(t){return Object.keys(t.added).length===0&&Object.keys(t.updated).length===0&&Object.keys(t.removed).length===0}function Jw(t){const e={added:{},removed:{},updated:{}};return cu(e,t),e}function cu(t,e){for(const n of e){for(const[r,o]of Xn(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 Xn(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 Xn(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}}var bf={exports:{}};bf.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]",y="[object Null]",S="[object Object]",b="[object Promise]",P="[object Proxy]",C="[object RegExp]",_="[object Set]",E="[object String]",k="[object Symbol]",D="[object Undefined]",T="[object WeakMap]",j="[object ArrayBuffer]",$="[object DataView]",M="[object Float32Array]",O="[object Float64Array]",F="[object Int8Array]",B="[object Int16Array]",K="[object Int32Array]",R="[object Uint8Array]",H="[object Uint8ClampedArray]",Y="[object Uint16Array]",ee="[object Uint32Array]",he=/[\\^$.*+?()[\]{}|]/g,ue=/^\[object .+?Constructor\]$/,ke=/^(?:0|[1-9]\d*)$/,se={};se[M]=se[O]=se[F]=se[B]=se[K]=se[R]=se[H]=se[Y]=se[ee]=!0,se[a]=se[l]=se[j]=se[u]=se[$]=se[h]=se[p]=se[f]=se[m]=se[v]=se[S]=se[C]=se[_]=se[E]=se[T]=!1;var We=typeof dn=="object"&&dn&&dn.Object===Object&&dn,Fe=typeof self=="object"&&self&&self.Object===Object&&self,ot=We||Fe||Function("return this")(),$e=e&&!e.nodeType&&e,lt=$e&&!0&&t&&!t.nodeType&&t,Ue=lt&&lt.exports===$e,er=Ue&&We.process,$t=function(){try{return er&&er.binding&&er.binding("util")}catch{}}(),On=$t&&$t.isTypedArray;function vt(A,L){for(var V=-1,ne=A==null?0:A.length,Qe=0,Se=[];++V<ne;){var mt=A[V];L(mt,V,A)&&(Se[Qe++]=mt)}return Se}function Jt(A,L){for(var V=-1,ne=L.length,Qe=A.length;++V<ne;)A[Qe+V]=L[V];return A}function Xo(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 cc(A,L){for(var V=-1,ne=Array(A);++V<A;)ne[V]=L(V);return ne}function js(A){return function(L){return A(L)}}function A4(A,L){return A.has(L)}function j4(A,L){return A==null?void 0:A[L]}function O4(A){var L=-1,V=Array(A.size);return A.forEach(function(ne,Qe){V[++L]=[Qe,ne]}),V}function D4(A,L){return function(V){return A(L(V))}}function R4(A){var L=-1,V=Array(A.size);return A.forEach(function(ne){V[++L]=ne}),V}var L4=Array.prototype,$4=Function.prototype,Ad=Object.prototype,Mm=ot["__core-js_shared__"],Jb=$4.toString,go=Ad.hasOwnProperty,eP=function(){var A=/[^.]+$/.exec(Mm&&Mm.keys&&Mm.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),tP=Ad.toString,F4=RegExp("^"+Jb.call(go).replace(he,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),nP=Ue?ot.Buffer:void 0,jd=ot.Symbol,rP=ot.Uint8Array,oP=Ad.propertyIsEnumerable,N4=L4.splice,Ri=jd?jd.toStringTag:void 0,sP=Object.getOwnPropertySymbols,z4=nP?nP.isBuffer:void 0,B4=D4(Object.keys,Object),Am=ka(ot,"DataView"),uc=ka(ot,"Map"),jm=ka(ot,"Promise"),Om=ka(ot,"Set"),Dm=ka(ot,"WeakMap"),dc=ka(Object,"create"),U4=Fi(Am),H4=Fi(uc),K4=Fi(jm),W4=Fi(Om),G4=Fi(Dm),iP=jd?jd.prototype:void 0,Rm=iP?iP.valueOf:void 0;function Li(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 V4(){this.__data__=dc?dc(null):{},this.size=0}function Y4(A){var L=this.has(A)&&delete this.__data__[A];return this.size-=L?1:0,L}function X4(A){var L=this.__data__;if(dc){var V=L[A];return V===r?void 0:V}return go.call(L,A)?L[A]:void 0}function q4(A){var L=this.__data__;return dc?L[A]!==void 0:go.call(L,A)}function Z4(A,L){var V=this.__data__;return this.size+=this.has(A)?0:1,V[A]=dc&&L===void 0?r:L,this}Li.prototype.clear=V4,Li.prototype.delete=Y4,Li.prototype.get=X4,Li.prototype.has=q4,Li.prototype.set=Z4;function qo(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 Q4(){this.__data__=[],this.size=0}function J4(A){var L=this.__data__,V=Dd(L,A);if(V<0)return!1;var ne=L.length-1;return V==ne?L.pop():N4.call(L,V,1),--this.size,!0}function eN(A){var L=this.__data__,V=Dd(L,A);return V<0?void 0:L[V][1]}function tN(A){return Dd(this.__data__,A)>-1}function nN(A,L){var V=this.__data__,ne=Dd(V,A);return ne<0?(++this.size,V.push([A,L])):V[ne][1]=L,this}qo.prototype.clear=Q4,qo.prototype.delete=J4,qo.prototype.get=eN,qo.prototype.has=tN,qo.prototype.set=nN;function $i(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 rN(){this.size=0,this.__data__={hash:new Li,map:new(uc||qo),string:new Li}}function oN(A){var L=Rd(this,A).delete(A);return this.size-=L?1:0,L}function sN(A){return Rd(this,A).get(A)}function iN(A){return Rd(this,A).has(A)}function aN(A,L){var V=Rd(this,A),ne=V.size;return V.set(A,L),this.size+=V.size==ne?0:1,this}$i.prototype.clear=rN,$i.prototype.delete=oN,$i.prototype.get=sN,$i.prototype.has=iN,$i.prototype.set=aN;function Od(A){var L=-1,V=A==null?0:A.length;for(this.__data__=new $i;++L<V;)this.add(A[L])}function lN(A){return this.__data__.set(A,r),this}function cN(A){return this.__data__.has(A)}Od.prototype.add=Od.prototype.push=lN,Od.prototype.has=cN;function Os(A){var L=this.__data__=new qo(A);this.size=L.size}function uN(){this.__data__=new qo,this.size=0}function dN(A){var L=this.__data__,V=L.delete(A);return this.size=L.size,V}function hN(A){return this.__data__.get(A)}function pN(A){return this.__data__.has(A)}function fN(A,L){var V=this.__data__;if(V instanceof qo){var ne=V.__data__;if(!uc||ne.length<n-1)return ne.push([A,L]),this.size=++V.size,this;V=this.__data__=new $i(ne)}return V.set(A,L),this.size=V.size,this}Os.prototype.clear=uN,Os.prototype.delete=dN,Os.prototype.get=hN,Os.prototype.has=pN,Os.prototype.set=fN;function gN(A,L){var V=Ld(A),ne=!V&&MN(A),Qe=!V&&!ne&&Lm(A),Se=!V&&!ne&&!Qe&&gP(A),mt=V||ne||Qe||Se,At=mt?cc(A.length,String):[],Ft=At.length;for(var ct in A)go.call(A,ct)&&!(mt&&(ct=="length"||Qe&&(ct=="offset"||ct=="parent")||Se&&(ct=="buffer"||ct=="byteLength"||ct=="byteOffset")||_N(ct,Ft)))&&At.push(ct);return At}function Dd(A,L){for(var V=A.length;V--;)if(dP(A[V][0],L))return V;return-1}function mN(A,L,V){var ne=L(A);return Ld(A)?ne:Jt(ne,V(A))}function hc(A){return A==null?A===void 0?D:y:Ri&&Ri in Object(A)?PN(A):TN(A)}function aP(A){return pc(A)&&hc(A)==a}function lP(A,L,V,ne,Qe){return A===L?!0:A==null||L==null||!pc(A)&&!pc(L)?A!==A&&L!==L:yN(A,L,V,ne,lP,Qe)}function yN(A,L,V,ne,Qe,Se){var mt=Ld(A),At=Ld(L),Ft=mt?l:Ds(A),ct=At?l:Ds(L);Ft=Ft==a?S:Ft,ct=ct==a?S:ct;var tr=Ft==S,Ur=ct==S,en=Ft==ct;if(en&&Lm(A)){if(!Lm(L))return!1;mt=!0,tr=!1}if(en&&!tr)return Se||(Se=new Os),mt||gP(A)?cP(A,L,V,ne,Qe,Se):wN(A,L,Ft,V,ne,Qe,Se);if(!(V&o)){var Pr=tr&&go.call(A,"__wrapped__"),Cr=Ur&&go.call(L,"__wrapped__");if(Pr||Cr){var Rs=Pr?A.value():A,Zo=Cr?L.value():L;return Se||(Se=new Os),Qe(Rs,Zo,V,ne,Se)}}return en?(Se||(Se=new Os),bN(A,L,V,ne,Qe,Se)):!1}function SN(A){if(!fP(A)||EN(A))return!1;var L=hP(A)?F4:ue;return L.test(Fi(A))}function vN(A){return pc(A)&&pP(A.length)&&!!se[hc(A)]}function xN(A){if(!kN(A))return B4(A);var L=[];for(var V in Object(A))go.call(A,V)&&V!="constructor"&&L.push(V);return L}function cP(A,L,V,ne,Qe,Se){var mt=V&o,At=A.length,Ft=L.length;if(At!=Ft&&!(mt&&Ft>At))return!1;var ct=Se.get(A);if(ct&&Se.get(L))return ct==L;var tr=-1,Ur=!0,en=V&s?new Od:void 0;for(Se.set(A,L),Se.set(L,A);++tr<At;){var Pr=A[tr],Cr=L[tr];if(ne)var Rs=mt?ne(Cr,Pr,tr,L,A,Se):ne(Pr,Cr,tr,A,L,Se);if(Rs!==void 0){if(Rs)continue;Ur=!1;break}if(en){if(!Xo(L,function(Zo,Ni){if(!A4(en,Ni)&&(Pr===Zo||Qe(Pr,Zo,V,ne,Se)))return en.push(Ni)})){Ur=!1;break}}else if(!(Pr===Cr||Qe(Pr,Cr,V,ne,Se))){Ur=!1;break}}return Se.delete(A),Se.delete(L),Ur}function wN(A,L,V,ne,Qe,Se,mt){switch(V){case $:if(A.byteLength!=L.byteLength||A.byteOffset!=L.byteOffset)return!1;A=A.buffer,L=L.buffer;case j:return!(A.byteLength!=L.byteLength||!Se(new rP(A),new rP(L)));case u:case h:case v:return dP(+A,+L);case p:return A.name==L.name&&A.message==L.message;case C:case E:return A==L+"";case m:var At=O4;case _:var Ft=ne&o;if(At||(At=R4),A.size!=L.size&&!Ft)return!1;var ct=mt.get(A);if(ct)return ct==L;ne|=s,mt.set(A,L);var tr=cP(At(A),At(L),ne,Qe,Se,mt);return mt.delete(A),tr;case k:if(Rm)return Rm.call(A)==Rm.call(L)}return!1}function bN(A,L,V,ne,Qe,Se){var mt=V&o,At=uP(A),Ft=At.length,ct=uP(L),tr=ct.length;if(Ft!=tr&&!mt)return!1;for(var Ur=Ft;Ur--;){var en=At[Ur];if(!(mt?en in L:go.call(L,en)))return!1}var Pr=Se.get(A);if(Pr&&Se.get(L))return Pr==L;var Cr=!0;Se.set(A,L),Se.set(L,A);for(var Rs=mt;++Ur<Ft;){en=At[Ur];var Zo=A[en],Ni=L[en];if(ne)var mP=mt?ne(Ni,Zo,en,L,A,Se):ne(Zo,Ni,en,A,L,Se);if(!(mP===void 0?Zo===Ni||Qe(Zo,Ni,V,ne,Se):mP)){Cr=!1;break}Rs||(Rs=en=="constructor")}if(Cr&&!Rs){var $d=A.constructor,Fd=L.constructor;$d!=Fd&&"constructor"in A&&"constructor"in L&&!(typeof $d=="function"&&$d instanceof $d&&typeof Fd=="function"&&Fd instanceof Fd)&&(Cr=!1)}return Se.delete(A),Se.delete(L),Cr}function uP(A){return mN(A,ON,CN)}function Rd(A,L){var V=A.__data__;return IN(L)?V[typeof L=="string"?"string":"hash"]:V.map}function ka(A,L){var V=j4(A,L);return SN(V)?V:void 0}function PN(A){var L=go.call(A,Ri),V=A[Ri];try{A[Ri]=void 0;var ne=!0}catch{}var Qe=tP.call(A);return ne&&(L?A[Ri]=V:delete A[Ri]),Qe}var CN=sP?function(A){return A==null?[]:(A=Object(A),vt(sP(A),function(L){return oP.call(A,L)}))}:DN,Ds=hc;(Am&&Ds(new Am(new ArrayBuffer(1)))!=$||uc&&Ds(new uc)!=m||jm&&Ds(jm.resolve())!=b||Om&&Ds(new Om)!=_||Dm&&Ds(new Dm)!=T)&&(Ds=function(A){var L=hc(A),V=L==S?A.constructor:void 0,ne=V?Fi(V):"";if(ne)switch(ne){case U4:return $;case H4:return m;case K4:return b;case W4:return _;case G4:return T}return L});function _N(A,L){return L=L??i,!!L&&(typeof A=="number"||ke.test(A))&&A>-1&&A%1==0&&A<L}function IN(A){var L=typeof A;return L=="string"||L=="number"||L=="symbol"||L=="boolean"?A!=="__proto__":A===null}function EN(A){return!!eP&&eP in A}function kN(A){var L=A&&A.constructor,V=typeof L=="function"&&L.prototype||Ad;return A===V}function TN(A){return tP.call(A)}function Fi(A){if(A!=null){try{return Jb.call(A)}catch{}try{return A+""}catch{}}return""}function dP(A,L){return A===L||A!==A&&L!==L}var MN=aP(function(){return arguments}())?aP:function(A){return pc(A)&&go.call(A,"callee")&&!oP.call(A,"callee")},Ld=Array.isArray;function AN(A){return A!=null&&pP(A.length)&&!hP(A)}var Lm=z4||RN;function jN(A,L){return lP(A,L)}function hP(A){if(!fP(A))return!1;var L=hc(A);return L==f||L==g||L==c||L==P}function pP(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function fP(A){var L=typeof A;return A!=null&&(L=="object"||L=="function")}function pc(A){return A!=null&&typeof A=="object"}var gP=On?js(On):vN;function ON(A){return AN(A)?gN(A):xN(A)}function DN(){return[]}function RN(){return!1}t.exports=jN})(bf,bf.exports);var BV=bf.exports;const gA=xi(BV);function UV(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 HV(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 B_(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 U_(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 UV(Object.values(r))}class KV{constructor(e,n){I(this,"indexCache",new Map);I(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(Zi(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===ur)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 ut(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 ut(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 ut(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?Wc(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 ut(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(Zi(s))return o();const a=r.getDiffSince(i);if(a===ur)return o();const l=new Map,c=(f,g)=>{let m=l.get(f);m||(m=new sp(s.get(f)??new Set)),m.add(g),l.set(f,m)},u=(f,g)=>{let m=l.get(f);m||(m=new sp(s.get(f)??new Set)),m.remove(g),l.set(f,m)};for(const f of a){for(const g of ut(f.added))if(g.typeName===e){const m=g[n];c(m,g.id)}for(const[g,m]of ut(f.updated))if(m.typeName===e){const v=g[n],y=m[n];v!==y&&(u(v,m.id),c(y,m.id))}for(const g of ut(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?Wc(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,()=>{const s=this.atoms.get();return[...o.get()].map(i=>{const a=s[i];if(!a)throw new Error("no atom found for record id: "+i);return a.get()})},{isEqual:RT})}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(ut(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===e?u.id:[]})):U_(this,e,l)},i=l=>{const c=s(),u=HV(l,c);return u?Wc(c,u):l},a=G("ids_query:"+r,n,{isEqual:gA});return G("query:"+r,(l,c)=>{const u=a.get();if(Zi(l))return s();if(c<a.lastChangedEpoch)return i(l);const h=o.getDiffSince(c);if(h===ur)return i(l);const p=new sp(l);for(const g of h){for(const m of ut(g.added))m.typeName===e&&B_(u,m)&&p.add(m.id);for(const[m,v]of ut(g.updated))v.typeName===e&&(B_(u,v)?p.add(v.id):p.remove(v.id));for(const m of ut(g.removed))m.typeName===e&&p.remove(m.id)}const f=p.get();return f?Wc(f.value,f.diff):l},{historyLength:50})}exec(e,n){const r=U_(this,e,n);if(r.size===0)return ps;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class WV{constructor(e){I(this,"_beforeCreateHandlers",{});I(this,"_afterCreateHandlers",{});I(this,"_beforeChangeHandlers",{});I(this,"_afterChangeHandlers",{});I(this,"_beforeDeleteHandlers",{});I(this,"_afterDeleteHandlers",{});I(this,"_operationCompleteHandlers",[]);I(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),()=>zi(this._beforeCreateHandlers[e],n)}registerAfterCreateHandler(e,n){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(n),()=>zi(this._afterCreateHandlers[e],n)}registerBeforeChangeHandler(e,n){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(n),()=>zi(this._beforeChangeHandlers[e],n)}registerAfterChangeHandler(e,n){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(n),()=>zi(this._afterChangeHandlers[e],n)}registerBeforeDeleteHandler(e,n){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(n),()=>zi(this._beforeDeleteHandlers[e],n)}registerAfterDeleteHandler(e,n){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(n),()=>zi(this._afterDeleteHandlers[e],n)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>zi(this._operationCompleteHandlers,e)}}function zi(t,e){const n=t.indexOf(e);n>=0&&t.splice(n,1)}class e1{constructor(e){I(this,"id");I(this,"atoms",Et("store_atoms",{}));I(this,"history",Et("history",0,{historyLength:1e3}));I(this,"query",new KV(this.atoms,this.history));I(this,"listeners",new Set);I(this,"historyAccumulator",new VV);I(this,"historyReactor");I(this,"schema");I(this,"props");I(this,"scopedTypes");I(this,"sideEffects",new WV(this));I(this,"isMergingRemoteChanges",!1);I(this,"_integrityChecker");I(this,"_isPossiblyCorrupted",!1);I(this,"pendingAfterEvents",null);I(this,"_isInAtomicOp",!1);const{initialData:n,schema:r,id:o}=e;this.id=o??ze(),this.schema=r,this.props=e.props,n&&this.atoms.set(ww(Xn(n).map(([s,i])=>[s,Et("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=cV("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=tM(s)}),this.scopedTypes={document:new Set(ut(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(ut(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(ut(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:lu(e.added,(o,s)=>this.scopedTypes[n].has(s.typeName)),updated:lu(e.updated,(o,s)=>this.scopedTypes[n].has(s[1].typeName)),removed:lu(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]=Et("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 Xn(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 ut(this.atoms.get()).map(e=>e.get())}clear(){this.remove($C(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.historyReactor.scheduler.isActivelyListening||(this.historyReactor.start(),this.historyReactor.scheduler.execute()),this.listeners.add(r),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}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,Oo(e)}finally{this.isMergingRemoteChanges=!1,this.ensureStoreIsUsable()}}extractingChanges(e){const n=[],r=this.historyAccumulator.addInterceptor(o=>n.push(o.changes));try{return Oo(e),Jw(n)}finally{r()}}applyDiff(e,{runCallbacks:n=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const o=ut(e.added);for(const[i,a]of ut(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,hn(c,h))||(u||(u={...c}),u[h]=p);u&&o.push(u)}else o.push(a)}const s=$C(e.removed);o.length&&this.put(o),s.length&&this.remove(s)},n)}createComputedCache(e,n,r){const o=new Ro;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 Ro;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(Le(this.pendingAfterEvents,"must be in event operation"),e===n||(e&&n&&Le(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 Oo(()=>{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 GV(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:Jw(o.map(s=>s.changes))}))}class VV{constructor(){I(this,"_history",[]);I(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=GV(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function YV(t,e,n){const r=new Ro;return{get(o,s){return r.get(o,()=>(o instanceof e1?o:o.store).createComputedCache(t,l=>e(o,l),n)).get(s)}}}function XV(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 vl({sequence:t,sequenceId:e,retroactive:n=!0}){const r={sequenceId:e,retroactive:n,sequence:XV(t)};return mA(r),r}function Zn(t,e){return Object.fromEntries(Xn(e).map(([n,r])=>[n,`${t}/${r}`]))}function xr(t){const e=t.sequenceId;return vl({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 qV(t){const e=new Map(t.map(s=>[s.id,s])),n=new Set,r=[];function o(s){Le(!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 H_(t,e){e&&Le(t.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${t}'`),Le(t.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${t}'`)}function mA(t){if(Le(!t.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${t.sequenceId}`),Le(t.sequenceId.length,"sequenceId must be a non-empty string"),t.sequence.length===0)return;H_(t.sequence[0].id,t.sequenceId);let e=Pf(t.sequence[0].id).version;Le(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;H_(r,t.sequenceId);const o=Pf(r).version;Le(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 zs=(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))(zs||{});function ZV(t){if(t.schemaVersion>2||t.schemaVersion<1)return wn.err("Bad schema version");if(t.schemaVersion===2)return wn.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 wn.ok(e)}class t1{constructor(e,n){I(this,"migrations",{});I(this,"sortedMigrations");var o;this.types=e,this.options=n;for(const s of n.migrations??[])Le(!this.migrations[s.sequenceId],`Duplicate migration sequenceId ${s.sequenceId}`),mA(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=qV(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);Le(a,`Migration '${s.id}' depends on missing migration '${i}'`)}}static create(e,n){return new t1(e,n??{})}validateRecord(e,n,r,o){try{const s=hn(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=ZV(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 wn.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 wn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))s.add(u.id)}return wn.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:zs.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"?zs.TargetVersionTooOld:zs.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:zs.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:zs.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:zs.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 Ot(s)}catch(s){return console.error("Error migrating store",s),{type:"error",reason:zs.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=hn(this.types,e);return Le(n,"record type does not exists"),n}}Ci("@tldraw/store","3.7.0-canary.383dfd14bf86","esm");function QV(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=QV(r),s=n.split(`
83
- `).map((i,a)=>a===0?i:` ${i}`).join(`
84
- `);super(r?`At ${o}: ${s}`:s);I(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function qn(t,e){try{return e()}catch(n){throw n instanceof Me?new Me(n.rawMessage,[t,...n.path]):new Me(n.toString(),[t])}}function fi(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:Ot(e)}}class Tn{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 oY(this)}optional(){return SA(this)}refine(e){return new Tn(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=>(qn(`(check ${e})`,()=>n(r)),r)):this.refine(r=>(e(r),r))}}class JV extends Tn{constructor(e){super(n=>{const r=K_.validate(n);for(let o=0;o<r.length;o++)qn(o,()=>e.validate(r[o]));return r},(n,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const o=K_.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,qn(i,()=>e.validate(a));continue}if(Object.is(n[i],a))continue;const l=qn(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 Cf extends Tn{constructor(e,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${fi(r)}`);for(const[o,s]of Object.entries(e))qn(o,()=>{s.validate(hn(r,o))});if(!n){for(const o of Object.keys(r))if(!no(e,o))throw new Me("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Me(`Expected object, got ${fi(o)}`);let s=!1;for(const[i,a]of Object.entries(e)){const l=hn(r,i),c=hn(o,i);if(Object.is(l,c))continue;const u=qn(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(!no(e,i))throw new Me("Unexpected property",[i])}for(const i of Object.keys(r))if(!no(o,i)){s=!0;break}return s?o:r}),this.config=e,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new Cf(this.config,!0)}extend(e){return new Cf({...this.config,...e})}}class Ag extends Tn{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):qn(`(${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):hn(s,e)!==hn(i,e)?qn(`(${e} = ${l})`,()=>a.validate(i)):qn(`(${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 ${fi(e)}`,[])}getMatchingSchemaAndVariant(e){const n=hn(e,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new Me(`Expected a string for key "${this.key}", got ${fi(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Me(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:no(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(e){return new Ag(this.key,this.config,e,this.useNumberKeys)}}class eY extends Tn{constructor(e,n){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${fi(r)}`);for(const[o,s]of Object.entries(r))qn(o,()=>{e.validate(o),n.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Me(`Expected object, got ${fi(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!no(r,i)){s=!0,qn(i,()=>{e.validate(i),n.validate(a)});continue}const l=hn(r,i),c=a;if(Object.is(l,c))continue;const u=qn(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(s=!0)}for(const i of Object.keys(r))if(!no(o,i)){s=!0;break}return s?o:r}),this.keyValidator=e,this.valueValidator=n}}function n1(t){return new Tn(e=>{if(typeof e!==t)throw new Me(`Expected ${t}, got ${fi(e)}`);return e})}const tY=new Tn(t=>t),ye=n1("string"),fe=n1("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}`)}),_f=fe.check(t=>{if(t<0)throw new Me(`Expected a positive number, got ${t}`)}),Ct=fe.check(t=>{if(t<=0)throw new Me(`Expected a non-zero positive number, got ${t}`)}),yA=fe.check(t=>{if(!Number.isInteger(t))throw new Me(`Expected an integer, got ${t}`)}),ip=yA.check(t=>{if(t<0)throw new Me(`Expected a positive integer, got ${t}`)}),nY=yA.check(t=>{if(t<=0)throw new Me(`Expected a non-zero positive integer, got ${t}`)}),we=n1("boolean");function mn(t){return new Tn(e=>{if(e!==t)throw new Me(`Expected ${t}, got ${JSON.stringify(e)}`);return t})}const K_=new Tn(t=>{if(!Array.isArray(t))throw new Me(`Expected an array, got ${fi(t)}`);return t});function Kt(t){return new JV(t)}function Pe(t){return new Cf(t)}function gx(t){return typeof t=="object"&&t!==null&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null||Object.getPrototypeOf(t)===g7)}function mx(t){return t===null||typeof t=="number"||typeof t=="string"||typeof t=="boolean"?!0:Array.isArray(t)?t.every(mx):gx(t)?Object.values(t).every(mx):!1}const Wt=new Tn(t=>{if(mx(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(gx(t)&&gx(e)){let n=!1;for(const r of Object.keys(e)){if(!no(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(!no(e,r)){n=!0;break}return n?e:t}else return Wt.validate(e)});function If(t,e){return new eY(t,e)}function r1(t,e){return new Ag(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 rY(t,e){return new Ag(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 Wo(t,e){return new Tn(n=>qn(t,()=>e.validate(n)),(n,r)=>qn(t,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(n,r):e.validate(r)))}function jg(t){return new Tn(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 SA(t){return new Tn(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 oY(t){return new Tn(e=>e===null?null:t.validate(e),(e,n)=>n===null?null:t.validateUsingKnownGoodVersion&&e!==null?t.validateUsingKnownGoodVersion(e,n):t.validate(n))}function Og(...t){return jg(new Set(t))}function o1(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 sY=new Set(["http:","https:","mailto:"]),gr=ye.check(t=>{if(t==="")return;const e=o1(t);if(!sY.has(e.protocol.toLowerCase()))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)}),iY=new Set(["http:","https:","data:","asset:"]),aa=ye.check(t=>{if(t==="")return;const e=o1(t);if(!iY.has(e.protocol.toLowerCase()))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});ye.check(t=>{if(t==="")return;if(!o1(t).protocol.toLowerCase().match(/^https?:$/))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});const s1=ye.refine(t=>{try{return s7(t),t}catch{throw new Me(`Expected an index key, got ${JSON.stringify(t)}`)}});Ci("@tldraw/validate","3.7.0-canary.383dfd14bf86","esm");function dr(t){return ye.refine(e=>{if(!e.startsWith(`${t}:`))throw new Error(`${t} ID must start with "${t}:"`);return e})}const Dg=dr("asset");function i1(t,e){return Pe({id:Dg,typeName:mn("asset"),type:mn(t),props:e,meta:Wt})}const la=Pe({x:fe,y:fe,z:fe.optional()}),uu=Pe({x:fe,y:fe,w:fe,h:fe}),vA=fe.check(t=>{if(t<0||t>1)throw new Me("Opacity must be between 0 and 1")}),aY=ye.refine(t=>{if(!t.startsWith("page:")&&!t.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return t}),Ir=dr("shape");function lY(t,e,n){return Pe({id:Ir,typeName:mn("shape"),x:fe,y:fe,rotation:fe,index:s1,parentId:aY,type:mn(t),isLocked:we,opacity:vA,props:e?Pe(e):Wt,meta:n?Pe(n):Wt})}const cY=dr("binding");function uY(t,e,n){return Pe({id:cY,typeName:mn("binding"),type:mn(t),fromId:Ir,toId:Ir,props:e?Pe(e):Wt,meta:n?Pe(n):Wt})}Zn("com.tldraw.binding",{});xr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Qi(t){return`binding:${ze()}`}function dY(t){return Ko("binding",{scope:"document",validator:Wo("binding",r1("type",od(t,(e,{props:n,meta:r})=>uY(e,n,r))))}).withDefaultProperties(()=>({meta:{}}))}class Zt{constructor(e,n,r){this.id=e,this.defaultValue=n,this.type=r}static define(e,n){const{defaultValue:r,type:o=tY}=n;return new Zt(e,r,o)}static defineEnum(e,n){const{defaultValue:r,values:o}=n;return new hY(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 hY extends Zt{constructor(e,n,r){super(e,n,Og(...r)),this.values=r}}const lh=Zn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),pY=xr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:lh.AddIsLocked,up:t=>{t.isLocked=!1},down:t=>{delete t.isLocked}},{id:lh.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:lh.AddMeta,up:t=>{t.meta={}}},{id:lh.AddWhite,up:t=>{},down:t=>{t.props.color==="white"&&(t.props.color="black")}}]});function al(t){return t?t.typeName==="shape":!1}function Fn(t){return t?t.startsWith("shape:"):!1}function Ke(t){return`shape:${t??ze()}`}function xA(t){const e=new Map;for(const[n,r]of Object.entries(t))if(r instanceof Zt){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 uo(t,e){return od(e,(n,r)=>`com.tldraw.shape.${t}/${r}`)}function fY(t){return Ko("shape",{scope:"document",validator:Wo("shape",r1("type",od(t,(e,{props:n,meta:r})=>lY(e,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function W_(t,e){const n=[];for(const[r,{migrations:o}]of Object.entries(e)){const s=`com.tldraw.${t}.${r}`;o?"sequenceId"in o?(Le(s===o.sequenceId,`sequenceId mismatch for ${r} ${Mg} migrations. Expected '${s}', got '${o.sequenceId}'`),n.push(o)):"sequence"in o?n.push(vl({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?wA(t,r,i):i)})):n.push(vl({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(vl({sequenceId:s,retroactive:!1,sequence:[]}))}return n}function wA(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 bA=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],Ef={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 ks(t){return t.isDarkMode?Ef.darkMode:Ef.lightMode}const mr=Zt.defineEnum("tldraw:color",{defaultValue:"black",values:bA}),a1=Zt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:bA}),ca=Zt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),ua=Zt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),$o=Zt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),PA={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Fo=Zt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),CA=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],kf=Zt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:CA}),Tf=Zt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:CA}),_A={labelColor:a1,color:mr,fill:ua,dash:ca,size:Fo,arrowheadStart:kf,arrowheadEnd:Tf,font:$o,start:la,end:la,bend:fe,text:ye,labelPosition:fe,scale:Ct},Ua=uo("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function ch(t){return wA("shape","arrow",t)}const IA=vl({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[ch({id:Ua.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"}),ch({id:Ua.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)}}),ch({id:Ua.AddLabelPosition,up:t=>{t.labelPosition=.5},down:t=>{delete t.labelPosition}}),{id:Ua.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=Qi(),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=Qi(),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}}},ch({id:Ua.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}})]}),EA={terminal:Og("start","end"),normalizedAnchor:la,isExact:we,isPrecise:we},kA={sequence:[{dependsOn:[Ua.ExtractBindings]}]},gY=Wo("camera",Pe({typeName:mn("camera"),id:dr("camera"),x:fe,y:fe,z:fe,meta:Wt})),mY=Zn("com.tldraw.camera",{AddMeta:1}),yY=xr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:mY.AddMeta,up:t=>{t.meta={}}}]}),Eo=Ko("camera",{validator:gY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),SY=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"]),TA=jg(SY),vY=Pe({type:TA,rotation:fe}),xY=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),wY=jg(xY),bY=new Set(["starting","paused","active","stopping"]),MA=Pe({id:ye,points:Kt(la),size:_f,color:wY,opacity:fe,state:jg(bY),delay:fe,shrink:fe,taper:we}),zu=dr("page"),PY=Wo("page",Pe({typeName:mn("page"),id:zu,name:ye,index:s1,meta:Wt})),CY=Zn("com.tldraw.page",{AddMeta:1}),_Y=xr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:CY.AddMeta,up:t=>{t.meta={}}}]}),yr=Ko("page",{validator:PY,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Rn(t){return yr.isId(t)}const IY={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 AA(t){return t?lu(t,e=>IY[e]):null}dr("instance");function EY(t){const e={};for(const[r,o]of t)e[r]=SA(o);const n=Wo("instance",Pe({typeName:mn("instance"),id:dr("instance"),currentPageId:zu,followingUserId:ye.nullable(),brush:uu.nullable(),opacityForNextShape:vA,stylesForNextShape:Pe(e),cursor:vY,scribbles:Kt(MA),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:uu,insets:Kt(we),zoomBrush:uu.nullable(),isPenMode:we,isGridMode:we,chatMessage:ye,isChatting:we,highlightedUserIds:Kt(ye),isFocused:we,devicePixelRatio:fe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:Kt(ye),isChangingStyle:we,isReadonly:we,meta:Wt,duplicateProps:Pe({shapeIds:Kt(dr("shape")),offset:Pe({x:fe,y:fe})}).nullable()}));return Ko("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=Zn("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}),kY=xr({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})}]}),bn="instance:instance",TY=Wo("instance_page_state",Pe({typeName:mn("instance_page_state"),id:dr("instance_page_state"),pageId:zu,selectedShapeIds:Kt(Ir),hintingShapeIds:Kt(Ir),erasingShapeIds:Kt(Ir),hoveredShapeId:Ir.nullable(),editingShapeId:Ir.nullable(),croppingShapeId:Ir.nullable(),focusedGroupId:Ir.nullable(),meta:Wt})),Ic=Zn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),MY=xr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Ic.AddCroppingId,up(t){t.croppingShapeId=null}},{id:Ic.RemoveInstanceIdAndCameraId,up(t){delete t.instanceId,delete t.cameraId}},{id:Ic.AddMeta,up:t=>{t.meta={}}},{id:Ic.RenameProperties,up:t=>{},down:t=>{}},{id:Ic.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}}]}),Qr=Ko("instance_page_state",{validator:TY,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:{}})),AY=Wo("pointer",Pe({typeName:mn("pointer"),id:dr("pointer"),x:fe,y:fe,lastActivityTimestamp:fe,meta:Wt})),jY=Zn("com.tldraw.pointer",{AddMeta:1}),OY=xr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:jY.AddMeta,up:t=>{t.meta={}}}]}),l1=Ko("pointer",{validator:AY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Mf=l1.createId("pointer"),DY=Wo("instance_presence",Pe({typeName:mn("instance_presence"),id:dr("instance_presence"),userId:ye,userName:ye,lastActivityTimestamp:fe.nullable(),followingUserId:ye.nullable(),cursor:Pe({x:fe,y:fe,type:TA,rotation:fe}).nullable(),color:ye,camera:Pe({x:fe,y:fe,z:fe}).nullable(),screenBounds:uu.nullable(),selectedShapeIds:Kt(dr("shape")),currentPageId:dr("page"),brush:uu.nullable(),scribbles:Kt(MA),chatMessage:ye,meta:Wt})),ja=Zn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),RY=xr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:ja.AddScribbleDelay,up:t=>{t.scribble!==null&&(t.scribble.delay=0)}},{id:ja.RemoveInstanceId,up:t=>{delete t.instanceId}},{id:ja.AddChatMessage,up:t=>{t.chatMessage=""}},{id:ja.AddMeta,up:t=>{t.meta={}}},{id:ja.RenameSelectedShapeIds,up:t=>{}},{id:ja.NullableCameraCursor,up:t=>{},down:t=>{t.camera===null&&(t.camera={x:0,y:0,z:1}),t.lastActivityTimestamp===null&&(t.lastActivityTimestamp=0),t.cursor===null&&(t.cursor={type:"default",x:0,y:0,rotation:0}),t.screenBounds===null&&(t.screenBounds={x:0,y:0,w:1,h:1})}}]}),LY=Ko("instance_presence",{validator:DY,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),$Y=Wo("document",Pe({typeName:mn("document"),id:mn("document:document"),gridSize:fe,name:ye,meta:Wt})),G_=Zn("com.tldraw.document",{AddName:1,AddMeta:2}),FY=xr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:G_.AddName,up:t=>{t.name=""},down:t=>{delete t.name}},{id:G_.AddMeta,up:t=>{t.meta={}}}]}),c1=Ko("document",{validator:$Y,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),yx=c1.createId("document");function NY(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function V_(t){t.typeName==="asset"&&("src"in t&&(t.src="<redacted>"),"src"in t.props&&(t.props.src="<redacted>"))}function zY({error:t,phase:e,record:n,recordBefore:r}){throw vw(t,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?V_(tt(r)):void 0,recordAfter:V_(tt(n))}}),t}function BY(){return[yr.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function UY(t){const e=t.query.ids("page"),n=t.query.records("instance_page_state"),r=()=>{if(!t.has(yx))return t.put([c1.create({id:yx,name:t.props.defaultName})]),r();if(!t.has(Mf))return t.put([l1.create({id:Mf})]),r();const o=e.get();if(o.size===0)return t.put(BY()),r();const s=()=>[...o].map(u=>t.get(u)).sort(NY)[0].id,i=t.get(bn);if(i){if(!o.has(i.currentPageId))return t.put([{...i,currentPageId:s()}]),r()}else return t.put([t.schema.types.instance.create({id:bn,currentPageId:s(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const u of o){const h=Qr.createId(u);t.get(h)||a.add(h);const f=Eo.createId(u);t.has(f)||l.add(f)}a.size>0&&t.put([...a].map(u=>Qr.create({id:u,pageId:Qr.parseId(u)}))),l.size>0&&t.put([...l].map(u=>Eo.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 HY=i1("bookmark",Pe({title:ye,description:ye,image:ye,favicon:ye,src:aa.nullable()})),Y_=Zn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),KY=xr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:t=>t.type==="bookmark",sequence:[{id:Y_.MakeUrlsValid,up:t=>{aa.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Y_.AddFavicon,up:t=>{aa.isValid(t.props.favicon)||(t.props.favicon="")},down:t=>{delete t.props.favicon}}]}),WY=i1("image",Pe({w:fe,h:fe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:aa.nullable(),fileSize:Ct.optional()})),Ec=Zn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),GY=xr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:t=>t.type==="image",sequence:[{id:Ec.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Ec.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:Ec.MakeUrlsValid,up:t=>{aa.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Ec.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Ec.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),VY=i1("video",Pe({w:fe,h:fe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:aa.nullable(),fileSize:fe.optional()})),kc=Zn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),YY=xr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:t=>t.type==="video",sequence:[{id:kc.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:kc.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:kc.MakeUrlsValid,up:t=>{aa.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:kc.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:kc.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),XY=Wo("asset",r1("type",{image:WY,video:VY,bookmark:HY})),qY=Zn("com.tldraw.asset",{AddMeta:1}),ZY=xr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:qY.AddMeta,up:t=>{t.meta={}}}]}),Vs=Ko("asset",{validator:XY,scope:"document"}).withDefaultProperties(()=>({meta:{}})),jA={w:Ct,h:Ct,assetId:Dg.nullable(),url:gr},X_=uo("bookmark",{NullAssetId:1,MakeUrlsValid:2}),OA={sequence:[{id:X_.NullAssetId,up:t=>{t.assetId===void 0&&(t.assetId=null)},down:"retired"},{id:X_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},DA=Pe({type:Og("free","straight"),points:Kt(la)}),RA={color:mr,fill:ua,dash:ca,size:Fo,segments:Kt(DA),isComplete:we,isClosed:we,isPen:we,scale:Ct},q_=uo("draw",{AddInPen:1,AddScale:2}),LA={sequence:[{id:q_.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:q_.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},QY=/(^\/r\/[^/]+\/?$)/,JY=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(QY))return t}},{hostnames:["figma.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{hostnames:["google.*"],fromEmbedUrl:t=>{const e=ge(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=ge(t),n=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:t=>{const e=ge(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=ge(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=ge(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=ge(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=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return t.split("/").pop()?t:void 0}},{hostnames:["replit.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:t=>{const e=ge(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=ge(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=ge(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=ge(t);if(e&&e.hash.match(/#room=/))return t}},{hostnames:["observablehq.com"],fromEmbedUrl:t=>{const e=ge(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=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],$A={w:Ct,h:Ct,url:ye},uh=uo("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),FA={sequence:[{id:uh.GenOriginalUrlInEmbed,up:t=>{try{const e=t.url,n=new URL(e).host.replace("www.","");let r;for(const o of JY)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:uh.RemoveDoesResize,up:t=>{delete t.doesResize},down:"retired"},{id:uh.RemoveTmpOldUrl,up:t=>{delete t.tmpOldUrl},down:"retired"},{id:uh.RemovePermissionOverrides,up:t=>{delete t.overridePermissions},down:"retired"}]},NA={w:Ct,h:Ct,name:ye},zA={sequence:[]},Af=Zt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),jf=Zt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Jr=Zt.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"]}),BA={geo:Jr,labelColor:a1,color:mr,fill:ua,dash:ca,size:Fo,font:$o,align:Af,verticalAlign:jf,url:gr,w:Ct,h:Ct,growY:_f,text:ye,scale:Ct},Jo=uo("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),UA={sequence:[{id:Jo.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Jo.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"},{id:Jo.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Jo.AddCheckBox,up:t=>{},down:"retired"},{id:Jo.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Jo.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:Jo.AddCloud,up:t=>{},down:"retired"},{id:Jo.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Jo.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},HA={},KA={sequence:[]},WA={color:mr,size:Fo,segments:Kt(DA),isComplete:we,isPen:we,scale:Ct},eX=uo("highlight",{AddScale:1}),GA={sequence:[{id:eX.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},tX=Pe({topLeft:la,bottomRight:la}),VA={w:Ct,h:Ct,playing:we,url:gr,assetId:Dg.nullable(),crop:tX.nullable(),flipX:we,flipY:we},dh=uo("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),YA={sequence:[{id:dh.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:dh.AddCropProp,up:t=>{t.crop=null},down:t=>{delete t.crop}},{id:dh.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:dh.AddFlipProps,up:t=>{t.flipX=!1,t.flipY=!1},down:t=>{delete t.flipX,delete t.flipY}}]},Of=Zt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),nX=Pe({id:ye,index:s1,x:fe,y:fe}),XA={color:mr,dash:ca,size:Fo,spline:Of,points:If(ye,nX),scale:Ct},Tc=uo("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),qA={sequence:[{id:Tc.AddSnapHandles,up:t=>{for(const e of Object.values(t.handles))e.canSnap=!0},down:"retired"},{id:Tc.RemoveExtraHandleProps,up:t=>{t.handles=ww(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(cn);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:Tc.HandlesToPoints,up:t=>{const e=Object.entries(t.handles).map(([n,{x:r,y:o}])=>({x:r,y:o,index:n})).sort(cn);t.points=e.map(({x:n,y:r})=>({x:n,y:r})),delete t.handles},down:t=>{const e=Fu(t.points.length);t.handles=Object.fromEntries(t.points.map((n,r)=>[e[r],{x:n.x,y:n.y}])),delete t.points}},{id:Tc.PointIndexIds,up:t=>{const e=Fu(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(cn);t.points=e.map(({x:n,y:r})=>({x:n,y:r}))}},{id:Tc.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},ZA={color:mr,labelColor:a1,size:Fo,font:$o,fontSizeAdjustment:_f,align:Af,verticalAlign:jf,growY:_f,url:gr,text:ye,scale:Ct},$s=uo("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8}),QA={sequence:[{id:$s.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:$s.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:$s.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:$s.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:$s.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:$s.AddFontSizeAdjustment,up:t=>{t.fontSizeAdjustment=0},down:t=>{delete t.fontSizeAdjustment}},{id:$s.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}},{id:$s.AddLabelColor,up:t=>{t.labelColor="black"},down:t=>{delete t.labelColor}}]},Sx=Zt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),JA={color:mr,size:Fo,font:$o,textAlign:Sx,w:Ct,text:ye,scale:Ct,autoSize:we},Z_=uo("text",{RemoveJustify:1,AddTextAlign:2}),ej={sequence:[{id:Z_.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Z_.AddTextAlign,up:t=>{t.textAlign=t.align,delete t.align},down:t=>{t.align=t.textAlign,delete t.textAlign}}]},tj={w:Ct,h:Ct,time:fe,playing:we,url:gr,assetId:Dg.nullable()},Q_=uo("video",{AddUrlProp:1,MakeUrlsValid:2}),nj={sequence:[{id:Q_.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Q_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},hh=Zn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),rX=vl({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:hh.RemoveCodeAndIconShapeTypes,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete t[e]}},{id:hh.AddInstancePresenceType,scope:"store",up(t){}},{id:hh.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match(/^(user|user_presence)$/)&&delete t[e]}},{id:hh.RemoveUserDocument,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match("user_document")&&delete t[e]}}]}),oX={arrow:{migrations:IA,props:_A},bookmark:{migrations:OA,props:jA},draw:{migrations:LA,props:RA},embed:{migrations:FA,props:$A},frame:{migrations:zA,props:NA},geo:{migrations:UA,props:BA},group:{migrations:KA,props:HA},highlight:{migrations:GA,props:WA},image:{migrations:YA,props:VA},line:{migrations:qA,props:XA},note:{migrations:QA,props:ZA},text:{migrations:ej,props:JA},video:{migrations:nj,props:tj}},sX={arrow:{migrations:kA,props:EA}};function iX({shapes:t=oX,bindings:e=sX,migrations:n}={}){const r=new Map;for(const a of ut(t))for(const l of xA(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=fY(t),s=dY(e),i=EY(r);return t1.create({asset:Vs,binding:s,camera:Eo,document:c1,instance:i,instance_page_state:Qr,page:yr,instance_presence:LY,pointer:l1,shape:o},{migrations:[rX,ZY,yY,FY,kY,MY,_Y,RY,OY,pY,KY,GY,YY,...W_("shape",t),...W_("binding",e),...n??[]],onValidationFailure:zY,createIntegrityChecker:UY})}const Bu=[{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:"so",label:"Somali"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"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 aX(){const t=typeof window<"u"?window.navigator.languages??["en"]:["en"];return lX(t)}function lX(t){for(const e of t){const n=cX(e);if(n)return n}return"en"}const J_={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function cX(t){const e=Bu.find(o=>o.locale===t.toLowerCase());if(e)return e.locale;const[n,r]=t.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Bu.find(s=>s.locale===n);if(o)return o.locale}return n in J_?J_[n]:null}Ci("@tldraw/tlschema","3.7.0-canary.383dfd14bf86","esm");var rj={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})()})(rj);var uX=rj.exports;const le=xi(uX),oj="3.7.0-canary.383dfd14bf86",eI={major:"2024-09-13T14:36:29.063Z",minor:"2024-12-20T18:17:08.886Z",patch:"2024-12-20T18:17:08.886Z"},dX={error:null};class u1 extends w.Component{constructor(){super(...arguments);I(this,"state",dX)}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 Uu({children:t,fallback:e,...n}){return e===null?t:d.jsx(u1,{fallback:e,...n,children:t})}function d1(t,e){return Rg(`${t}_${e}`)}function Jl(t){return Rg(`${w.useId()}${t??""}`)}function ro(t){const e=zn(w.useContext(sj));return Rg(`${e}_${t}`)}function Rg(t){return t.replace(/:/g,"_")}const sj=w.createContext(null);function hX({children:t}){const e=Jl();return d.jsx(sj.Provider,{value:e,children:t})}const h1=w.createContext(null);function z(){const t=Te.useContext(h1);if(!t)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return t}function ki(){return Te.useContext(h1)}function p1({editor:t,children:e}){return d.jsx(h1.Provider,{value:t,children:d.jsx(hX,{children:e})})}function pX(){return d.jsx("div",{className:"tl-background"})}function ec(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 Dt={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(as(e.x),as(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=Dt.easeInQuad(s/(r-1)),a=x.Lrp(e,n,i);a.z=Math.min(1,.5+Math.abs(.5-fX(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 fX=t=>t<.5?2*t*t:-1+(4-2*t)*t;function je(t){return`${N(t.x)},${N(t.y)} `}function Bn(t,e){return`${N((t.x+e.x)/2)},${N((t.y+e.y)/2)} `}const De=Math.PI,qe=De/2,Ne=De*2,gX=Math.sin;function zt(t,e,n){return Math.max(e,typeof n<"u"?Math.min(t,n):t)}function ph(t,e=1e10){return t?Math.round(t*e)/e:0}function ui(t,e,n=1e-6){return Math.abs(t-e)<=n}function ij(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 Ji(t){return t=t%Ne,t<0?t=t+Ne:t===0&&(t=0),t}function ud(t,e){return t=Ji(t),e=Ji(e),t>e&&(e+=Ne),e-t}function aj(t,e){return Ne-ud(t,e)}function ap(t,e){const n=(e-t)%Ne;return 2*n%Ne-n}function vx(t){return(Ne+t)%Ne}function Df(t,e){const n=Ne/e;let r=Math.floor((vx(t)+n/2)/n)*n%Ne;return r<De&&(r+=Ne),r>De&&(r-=Ne),r}function lj(t,e){return t===e||ui(t%(Math.PI/2)-e%(Math.PI/2),0)}function mX(t){return t*De/180}function yX(t){return t*180/De}function da(t,e,n){return new x(t.x,t.y).add(x.FromAngle(n,e))}function Uy(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=Ne/n,v=-qe+g*m,y=r+r*Math.cos(v),S=o+o*Math.sin(v);y<i&&(i=y),S<l&&(l=S),y>a&&(a=y),S>c&&(c=S),s.push(new x(y,S))}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 Mc(t,e,n,r){return t<r&&n<e}function Gr(t,e,n,r){const o=Math.max(t,n),s=Math.min(e,r);return o<=s?[o,s]:null}function tI(t,e,n){return(e.x-t.x)*(n.y-t.y)-(n.x-t.x)*(e.y-t.y)}function hr(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&&tI(r,o,t)>0&&(n+=1):o.y<=t.y&&tI(r,o,t)<0&&(n-=1)}return n!==0}function N(t){return Math.round(t*1e4)/1e4}function as(t){return Math.round(t*100)/100}const nI=t=>Math.abs(t)<Number.MAX_SAFE_INTEGER;function Ys(t,e,n){return n<0?ud(t,e):aj(t,e)}function xx(t,e,n,r){let o;if(Math.abs(t)>De){o=ap(e,r);const s=ap(r,n);return Math.abs(o)<Math.abs(s)?o/t:(t-s)/t}else{o=ap(e,r);const s=o/t;return Math.sign(o)!==Math.sign(t)?Math.abs(s)>.5?1:0:s}}function SX(t,e,n,r){const o=2*((e-t)%Ne)%Ne-(e-t)%Ne;return r?(Ne-Math.abs(o))*(n?1:-1):o}function f1(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 vX(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=ud(i,a);for(let c=0;c<o;c++){const u=c/(o-1),h=i+l*u,p=da(n,r,h);s.push(p)}return s}const Hy=({brush:t,color:e,opacity:n,className:r})=>{const o=w.useRef(null);ec(o,t.x,t.y);const s=N(Math.max(1,t.w)),i=N(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})})},Ge={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1};typeof window<"u"&&"navigator"in window&&(Ge.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Ge.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Ge.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Ge.isFirefox=/firefox/i.test(navigator.userAgent),Ge.isAndroid=/android/i.test(navigator.userAgent),Ge.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1);const rI={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Ky={duration:0,easing:Dt.easeInOutCubic},oI={CAMERA_MOVE:-10},xX=["top","right","bottom","left"],sI=0,g1=2,fh=1,iI=5,wX=128;var Wy={};const bX={},cj=Dn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),bt={logPreventDefaults:Dn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Dn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Dn("logElementRemoves",{defaults:{all:!1}}),debugSvg:Dn("debugSvg",{defaults:{all:!1}}),showFps:Dn("showFps",{defaults:{all:!1}}),measurePerformance:Dn("measurePerformance",{defaults:{all:!1}}),throwToBlob:Dn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Dn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Dn("debugCursors",{defaults:{all:!1}}),forceSrgb:Dn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Dn("debugGeometry",{defaults:{all:!1}}),hideShapes:Dn("hideShapes",{defaults:{all:!1}}),editOnType:Dn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const t=Element.prototype.removeChild;jo("element removal logging",()=>{bt.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),t.call(this,e)}:Element.prototype.removeChild=t})}function Dn(t,{defaults:e,shouldStoreForSession:n=!0}){return PX({name:t,defaults:e,shouldStoreForSession:n})}function PX(t){const e=_X(t),n=t.shouldStoreForSession?CX(t.name):null,r=Et(`debug:${t.name}`,n??e);return typeof window<"u"&&(t.shouldStoreForSession&&jo(`debug:${t.name}`,()=>{const o=r.get();o===e?JT(`tldraw_debug:${t.name}`):Ew(`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 CX(t){try{return JSON.parse(QT(`tldraw_debug:${t}`)??"null")}catch{return null}}function Gy(t){try{return t()}catch{return null}}function _X(t){switch(Gy(()=>Wy.TLDRAW_ENV)??Gy(()=>Wy.VERCEL_PUBLIC_TLDRAW_ENV)??Gy(()=>Wy.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 Rf(t){if(t instanceof HTMLElement)return t;if(t.parentElement)return Rf(t.parentElement);throw Error("Could not find a parent element of an HTML type!")}function xe(t){t.preventDefault(),bt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",t)}function dd(t,e){if(t.setPointerCapture(e.pointerId),bt.logPointerCaptures.get()){const n=cj.get();n.set(t,(n.get(t)??0)+1),console.warn("setPointerCapture called on element:",t,e)}}function hd(t,e){if(t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),bt.logPointerCaptures.get())){const n=cj.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 _t=t=>t.stopPropagation(),rn=(t,e,n)=>{t&&t.style.setProperty(e,n)},un=t=>Ge.isDarwin?t.metaKey:t.ctrlKey||t.metaKey;function lr(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,metaKey:t.metaKey,accelKey:un(t),pointerId:t.pointerId,button:t.button,isPen:t.pointerType==="pen"}}function m1(){const t=z();return w.useMemo(function(){let r,o;function s(m){if(!m.isKilled){if(m.button===g1){t.dispatch({type:"pointer",target:"canvas",name:"right_click",...lr(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(dd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...lr(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",...lr(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,o=m.clientY,hd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...lr(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,xe(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"))&&xe(m)}function p(m){xe(m)}async function f(m){var y,S;if(xe(m),_t(m),!((S=(y=m.dataTransfer)==null?void 0:y.files)!=null&&S.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){_t(m)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:h,onClick:g}},[t])}function IX(){const t=z();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=Ge.isFirefox&&!Ge.isAndroid&&!Ge.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 uj=w.createContext(null);function dj({container:t,children:e}){return d.jsx(uj.Provider,{value:t,children:e})}function Mt(){return zn(w.useContext(uj),"useContainer used outside of <Tldraw />")}function EX(){const t=z(),e=Mt(),n=U("isFocused",()=>t.getIsFocused(),[t]);w.useEffect(()=>{if(!e)return;function r(o){if(o.isSpecialRedispatchedEvent)return;xe(o),_t(o);const s=e.querySelector(".tl-canvas");if(!s)return;const i=new DragEvent(o.type,o);i.isSpecialRedispatchedEvent=!0,s.dispatchEvent(i)}return e.addEventListener("dragover",r),e.addEventListener("drop",r),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",r)}},[e]),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"))&&!gh(t)&&xe(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){xe(a);return}break}case"Tab":{if(gh(t))return;break}case",":return;case"Escape":{if((t.getEditingShape()||t.getSelectedShapeIds().length>0)&&xe(a),t.menus.getOpenMenus().length>0)return;t.inputs.keys.has("Escape")||(t.inputs.keys.add("Escape"),t.cancel(),e.focus());return}default:if(gh(t))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,metaKey:a.metaKey,accelKey:un(a)};t.dispatch(l)},o=a=>{if(a.isKilled||(a.isKilled=!0,gh(t))||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,metaKey:a.metaKey,accelKey:un(a)};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()),xe(a))}}const i=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&xe(a)};return e.addEventListener("touchstart",s,{passive:!1}),e.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",xe),document.addEventListener("gesturechange",xe),document.addEventListener("gestureend",xe),e.addEventListener("keydown",r),e.addEventListener("keyup",o),()=>{e.removeEventListener("touchstart",s),e.removeEventListener("wheel",i),document.removeEventListener("gesturestart",xe),document.removeEventListener("gesturechange",xe),document.removeEventListener("gestureend",xe),e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}},[t,e,n])}const kX=["input","select","button","textarea"];function gh(t){const{activeElement:e}=document;return t.menus.hasOpenMenus()||e&&(e.getAttribute("contenteditable")||kX.indexOf(e.tagName.toLowerCase())>-1)}const TX=["textarea","input"];function MX(t){const e=z();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(TX.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||e.isIn("select.editing_shape"))return;xe(o)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[e,t])}function AX(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 aI(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function lI(t,e,n,r=.15){return r===0?AX(t,e,n):t<e?-aI(e-t,n-e,r)+e:t>n?+aI(t-n,n-e,r)+n:t}function jX(t,[e,n],[r,o]){const[[s,i],[a,l]]=t;return[lI(e,s,i,r),lI(n,a,l,o)]}function OX(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 DX(t){var e=OX(t,"string");return typeof e=="symbol"?e:String(e)}function sn(t,e,n){return e=DX(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function cI(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 ht(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?cI(Object(n),!0).forEach(function(r){sn(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):cI(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const hj={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 uI(t){return t?t[0].toUpperCase()+t.slice(1):""}const RX=["enter","leave"];function LX(t=!1,e){return t&&!RX.includes(e)}function $X(t,e="",n=!1){const r=hj[t],o=r&&r[e]||e;return"on"+uI(t)+uI(o)+(LX(n,o)?"Capture":"")}const FX=["gotpointercapture","lostpointercapture"];function NX(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=FX.includes(e)?"capturecapture":"capture",o=!!~e.indexOf(r);return o&&(e=e.replace("capture","")),{device:e,capture:o,passive:n}}function zX(t,e=""){const n=hj[t],r=n&&n[e]||e;return t+r}function pj(t){return"touches"in t}function BX(t){return pj(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function UX(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 wx(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 HX(t){return UX(t).map(e=>e.identifier)}function dI(t,e){const[n,r]=Array.from(t.touches).filter(o=>e.includes(o.identifier));return wx(n,r)}const hI=40,pI=800;function fj(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=hI,n*=hI):r===2&&(e*=pI,n*=pI),[e,n]}function KX(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 Lf(t,...e){return typeof t=="function"?t(...e):t}function WX(){}function GX(...t){return t.length===0?WX:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function fI(t,e){return Object.assign({},e,t||{})}const VX=32;class gj{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?Lf(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,KX(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 _=n._delta.map(Math.abs);Gt.addTo(n._distance,_)}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[_,E]=h;p[0]=u[0]!==!1?_-u[0]:0,p[1]=u[1]!==!1?E-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=Lf(r.bounds,n)),this.setup&&this.setup()),n.movement=p,this.computeOffset()));const[m,v]=n.offset,[[y,S],[b,P]]=n._bounds;n.overflow=[m<y?-1:m>S?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=jX(n._bounds,n.offset,C),n.delta=Gt.sub(n.offset,f),this.computeMovement(),g&&(!n.last||s>VX)){n.delta=Gt.sub(n.offset,f);const _=n.delta.map(Math.abs);Gt.addTo(n.distance,_),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&s>0&&(n.velocity=[_[0]/s,_[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(ht(ht(ht({},n),e),{},{[this.aliasKey]:e.values}));o!==void 0&&(e.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function YX([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 XX extends gj{constructor(...e){super(...e),sn(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=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[BX(e)]:r.axisThreshold;n.axis=YX(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 qX=t=>t,gI=.15,mj={enabled(t=!0){return t},eventOptions(t,e,n){return ht(ht({},n.shared.eventOptions),t)},preventDefault(t=!1){return t},triggerAllEvents(t=!1){return t},rubberband(t=0){switch(t){case!0:return[gI,gI];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||qX},threshold(t){return Gt.toVector(t,0)}},ZX=0,pd=ht(ht({},mj),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=ZX){return t},bounds(t={}){if(typeof t=="function")return s=>pd.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]]}}),fd=typeof window<"u"&&window.document&&window.document.createElement;function yj(){return fd&&"ontouchstart"in window}function QX(){return yj()||fd&&window.navigator.maxTouchPoints>1}function JX(){return fd&&"onpointerdown"in window}function eq(){return fd&&"exitPointerLock"in window.document}function tq(){try{return"constructor"in GestureEvent}catch{return!1}}const Mr={isBrowser:fd,gesture:tq(),touch:yj(),touchscreen:QX(),pointer:JX(),pointerLock:eq()},nq=250,rq=180,oq=.5,sq=50,iq=250,aq=10,mI={mouse:0,touch:0,pen:8};ht(ht({},pd),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&Mr.pointerLock,Mr.touch&&n?"touch":this.pointerLock?"mouse":Mr.pointer&&!o?"pointer":Mr.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?nq:void 0,!(!Mr.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=oq,distance:e=sq,duration:n=iq}={}){return{velocity:this.transform(Gt.toVector(t)),distance:this.transform(Gt.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return rq;case!1:return 0;default:return t}},axisThreshold(t){return t?ht(ht({},mI),t):mI},keyboardDisplacement(t=aq){return t}});function Sj(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 lq=30,cq=100;class uq extends gj{constructor(...e){super(...e),sn(this,"ingKey","pinching"),sn(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const 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)*lq-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=dI(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=wx(...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=dI(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=wx(...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=[-fj(e)[1]/cq*r.offset[0],0],Gt.addTo(r._movement,r._delta),Sj(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 dq=ht(ht({},mj),{},{device(t,e,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!Mr.touch&&Mr.gesture)return"gesture";if(Mr.touch&&r)return"touch";if(Mr.touchscreen){if(Mr.pointer)return"pointer";if(Mr.touch)return"touch"}},bounds(t,e,{scaleBounds:n={},angleBounds:r={}}){const o=i=>{const a=fI(Lf(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=fI(Lf(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}});ht(ht({},pd),{},{mouseOnly:(t=!0)=>t});class hq extends XX{constructor(...e){super(...e),sn(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=fj(e),Gt.addTo(n._movement,n._delta),Sj(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 pq=pd;ht(ht({},pd),{},{mouseOnly:(t=!0)=>t});const y1=new Map,bx=new Map;function fq(t){y1.set(t.key,t.engine),bx.set(t.key,t.resolver)}const gq={key:"pinch",engine:uq,resolver:dq},mq={key:"wheel",engine:hq,resolver:pq};function yq(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 Sq(t,e){if(t==null)return{};var n=yq(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 vq={target(t){if(t)return()=>"current"in t?t.current:t},enabled(t=!0){return t},window(t=Mr.isBrowser?window:void 0){return t},eventOptions({passive:t=!0,capture:e=!1}={}){return{passive:t,capture:e}},transform(t){return t}},xq=["target","eventOptions","window","enabled","transform"];function lp(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]=lp(t[r],o);break;case"boolean":o&&(n[r]=t[r]);break}return n}function wq(t,e,n={}){const r=t,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=Sq(r,xq);if(n.shared=lp({target:o,eventOptions:s,window:i,enabled:a,transform:l},vq),e){const u=bx.get(e);n[e]=lp(ht({shared:n.shared},c),u)}else for(const u in c){const h=bx.get(u);h&&(n[u]=lp(ht({shared:n.shared},c[u]),h))}return n}class vj{constructor(e,n){sn(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=n}add(e,n,r,o,s){const i=this._listeners,a=zX(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ht(ht({},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 bq{constructor(){sn(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 Pq{constructor(e){sn(this,"gestures",new Set),sn(this,"_targetEventStore",new vj(this)),sn(this,"gestureEventStores",{}),sn(this,"gestureTimeoutStores",{}),sn(this,"handlers",{}),sn(this,"config",{}),sn(this,"pointerIds",new Set),sn(this,"touchIds",new Set),sn(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),Cq(this,e)}setEventIds(e){if(pj(e))return this.touchIds=new Set(HX(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=wq(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=yI(r,a.eventOptions,!!o);if(a.enabled){const c=y1.get(i);new c(this,e,i).bind(l)}}const s=yI(r,n.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](ht(ht({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const s in r)r[s]=GX(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=NX(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function Oa(t,e){t.gestures.add(e),t.gestureEventStores[e]=new vj(t,e),t.gestureTimeoutStores[e]=new bq}function Cq(t,e){e.drag&&Oa(t,"drag"),e.wheel&&Oa(t,"wheel"),e.scroll&&Oa(t,"scroll"),e.move&&Oa(t,"move"),e.pinch&&Oa(t,"pinch"),e.hover&&Oa(t,"hover")}const yI=(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:$X(r,o,u);n&&h&&(p+="Passive"),t[p]=t[p]||[],t[p].push(s)},_q=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Iq(t){const e={},n={},r=new Set;for(let o in t)_q.test(o)?(r.add(RegExp.lastMatch),n[o]=t[o]):e[o]=t[o];return[n,e,r]}function Da(t,e,n,r,o,s){if(!t.has(n)||!y1.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 Eq(t,e){const[n,r,o]=Iq(t),s={};return Da(o,n,"onDrag","drag",s,e),Da(o,n,"onWheel","wheel",s,e),Da(o,n,"onScroll","scroll",s,e),Da(o,n,"onPinch","pinch",s,e),Da(o,n,"onMove","move",s,e),Da(o,n,"onHover","hover",s,e),{handlers:s,config:e,nativeHandlers:r}}function kq(t,e={},n,r){const o=Te.useMemo(()=>new Pq(t),[]);if(o.applyHandlers(t,r),o.applyConfig(e,n),Te.useEffect(o.effect.bind(o)),Te.useEffect(()=>o.clean.bind(o),[]),e.target===void 0)return o.bind.bind(o)}function Tq(t){return t.forEach(fq),function(n,r){const{handlers:o,nativeHandlers:s,config:i}=Eq(n,r||{});return kq(o,i,void 0,s)}}const SI=10,Mq=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function xj(t){let{deltaY:e,deltaX:n}=t,r=0;return t.ctrlKey||t.altKey||t.metaKey?r=(Math.abs(e)>SI?SI*Math.sign(e):e)/100:t.shiftKey&&!Mq&&(n=e,e=0),{x:-n,y:-e,z:-r}}const Aq=Tq([mq,gq]);let Ra;const jq=t=>Ra===void 0?(Ra=t,!1):t-Ra>120&&t-Ra<160?(Ra=t,!0):(Ra=t,!1);function Oq(t){const e=z(),n=w.useMemo(()=>{let r="not sure";const o=({event:m})=>{if(!e.getInstanceState().isFocused||(r="not sure",jq(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}}xe(m),_t(m);const y=xj(m);if(y.x===0&&y.y===0)return;const S={type:"wheel",name:"wheel",delta:y,point:new x(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey,metaKey:m.metaKey,accelKey:un(m)};e.dispatch(S)};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:y,origin:S,da:b}=m;y instanceof WheelEvent||(y.target===v||v!=null&&v.contains(y.target))&&(u.x=S[0],u.y=S[1],c.x=S[0],c.y=S[1],s=b[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:S[0],y:S[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)}))},p=m=>{if(m&&(r="zooming"),r==="zooming")return;const v=Math.abs(l-s),y=x.Dist(c,u);switch(r){case"not sure":{v>24?r="zooming":y>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:h,onPinchEnd:m=>{const v=t.current,{event:y,origin:S,offset:b}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const P=b[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:S[0],y:S[1],z:P},delta:{x:S[0],y:S[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)})})},onPinch:m=>{const v=t.current,{event:y,origin:S,offset:b,da:P}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const C=m.type==="gesturechange"||m.type==="gestureend";l=P[0];const _=S[0]-u.x,E=S[1]-u.y;switch(u.x=S[0],u.y=S[1],p(C),r){case"zooming":{a=b[0],e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:a},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:i},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}}}}},[e,t]);Aq(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 Vy(t,e,n){const r=t.getShape(e),o=t.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===n)}}function Dq(t,e){const n=z();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Rf(l.currentTarget);dd(c,l);const{shape:u,handle:h}=Vy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...lr(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}=Vy(n,t,e);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...lr(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Rf(l.currentTarget);hd(c,l);const{shape:u,handle:h}=Vy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...lr(l)})}}},[n,t,e])}function Rq(t){const e=z();w.useLayoutEffect(()=>{const n=kT(()=>{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=Lq(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 Lq=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){I(this,"x",0);I(this,"y",0);I(this,"w",0);I(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=ph(this.x),this.y=ph(this.y),this.w=ph(this.w),this.h=ph(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,y=m<0;if(s){const b=(l-i)/(c-a),P=Math.abs(p-u),C=Math.abs(f-h),_=P*(m<0?1:-1)*(1/b),E=C*(g<0?1:-1)*b,k=b<P/C;switch(n){case"top_left":{k?h=f+_:u=p+E;break}case"top_right":{k?h=f+_:p=u-E;break}case"bottom_right":{k?f=h-_:p=u-E;break}case"bottom_left":{k?f=h-_:u=p+E;break}case"bottom":case"top":{const D=(u+p)/2,T=C*b;u=D-T/2,p=D+T/2;break}case"left":case"right":{const D=(h+f)/2,T=P/b;h=D-T/2,f=D+T/2;break}}}if(v){const b=p;p=u,u=b}if(y){const b=f;f=h,h=b}const S=new Z(u,h,Math.abs(p-u),Math.abs(f-h));return{box:S,scaleX:+(S.width/e.width*(g>0?1:-1)).toFixed(5),scaleY:+(S.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 $q(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 Fq(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 Nq(t){return t==="top_left"||t==="top_right"||t==="bottom_right"||t==="bottom_left"}class q{constructor(e,n,r,o,s,i){I(this,"a",1);I(this,"b",0);I(this,"c",0);I(this,"d",1);I(this,"e",0);I(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 vx(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:vx(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(${N(e.a)}, ${N(e.b)}, ${N(e.c)}, ${N(e.d)}, ${N(e.e)}, ${N(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 Ti{constructor(e){I(this,"isFilled",!1);I(this,"isClosed",!0);I(this,"isLabel",!1);I(this,"debugColor");I(this,"ignore");I(this,"_vertices");I(this,"_bounds");I(this,"_area");I(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)&&hr(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)&&hr(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&&hr(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 $r extends Ti{constructor(n){super({...n,isClosed:!0,isFilled:!1});I(this,"children",[]);I(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 zq(t=!0){const[e,n]=w.useState(0),r=z();w.useEffect(()=>{if(!t)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,t])}const Bq=qt(function({showStroke:e=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const o=z();zq(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:y}=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(wj,{geometry:u})}),n&&y.map((S,b)=>d.jsx("circle",{cx:S.x,cy:S.y,r:2/s,fill:`hsl(${Ol(b,[0,y.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 wj({geometry:t}){return t instanceof $r?d.jsx(d.Fragment,{children:[...t.children,...t.ignoredChildren].map((e,n)=>d.jsx(wj,{geometry:e},n))}):d.jsx("path",{d:t.toSimpleSvgPath()})}function bj(t){return E9(t)}function Pj(){const t=z(),e=IV("userIds",()=>bj(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 Lg(t){const e=z();return U(`latestPresence:${t}`,()=>e.getCollaborators().find(r=>r.userId===t),[e,t])??null}const Uq=qt(function(){return Pj().map(n=>d.jsx(Hq,{collaboratorId:n},n))}),Hq=qt(function({collaboratorId:e}){const n=z(),r=Lg(e),o=Wq(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(Kq,{latestPresence:r})}),Kq=qt(function({latestPresence:e}){const n=z(),{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:y}=e;if(!v)return null;const S=!(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:y,opacity:.1},u+"_brush"):null,S&&s?d.jsx(s,{className:"tl-collaborator__cursor",point:v,color:y,zoom:l,name:m!=="New User"?m:null,chatMessage:h??""},u+"_cursor"):i?d.jsx(i,{className:"tl-collaborator__cursor-hint",point:v,color:y,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:y,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:y,opacity:.5},u+"_"+b))]})});function vI(t,e){return e>t.options.collaboratorInactiveTimeoutMs?"inactive":e>t.options.collaboratorIdleTimeoutMs?"idle":"active"}function Wq(t,e){const n=w.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,o]=w.useState(()=>vI(t,Date.now()-n.current));return w.useEffect(()=>{const s=t.timers.setInterval(()=>{o(vI(t,Date.now()-n.current))},t.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[t]),e&&(n.current=e.lastActivityTimestamp??1/0),r}function Gq(){const t=z(),e=U("is menu open",()=>t.menus.hasAnyOpenMenus(),[t]),[n,r]=w.useState(!1),o=e||n,s=m1(),i=w.useRef({isDown:!1,isDragging:!1,start:new x}),a=w.useCallback(u=>{u.button===0&&(r(!0),i.current={isDown:!0,isDragging:!1,start:new x(u.clientX,u.clientY)}),t.menus.clearOpenMenus()},[t]),l=w.useCallback(u=>{var h,p,f;if(i.current.isDown){if(i.current.isDragging){(h=s.onPointerMove)==null||h.call(s,u);return}if(x.Dist2(i.current.start,new x(u.clientX,u.clientY))>t.options.dragDistanceSquared){i.current={...i.current,isDown:!0,isDragging:!0};const{x:g,y:m}=i.current.start;(p=s.onPointerDown)==null||p.call(s,{...u,clientX:g,clientY:m,button:0}),(f=s.onPointerMove)==null||f.call(s,u)}}},[s,t]),c=w.useCallback(u=>{var h;(h=s.onPointerUp)==null||h.call(s,u),r(!1),i.current={isDown:!1,isDragging:!1,start:new x(u.clientX,u.clientY)}},[s]);return o&&d.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...s,onPointerDown:a,onPointerMove:l,onPointerUp:c})}const Cj=w.memo(function({id:e,shape:n,util:r,index:o,backgroundIndex:s,opacity:i}){const a=z(),{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});ci("set shape stuff",()=>{const g=a.getShape(e);if(!g)return;const m=h.current,v=a.getShapeClipPath(e)??"none";v!==m.clipPath&&(rn(c.current,"clip-path",v),rn(u.current,"clip-path",v),m.clipPath=v);const y=a.getShapePageTransform(e),S=q.toCssString(y),b=a.getShapeGeometry(g).bounds;S!==m.transform&&(rn(c.current,"transform",S),rn(u.current,"transform",S),m.transform=S);const P=Math.max(b.width,1),C=Math.max(b.height,1);(P!==m.width||C!==m.height)&&(rn(c.current,"width",P+"px"),rn(c.current,"height",C+"px"),rn(u.current,"width",P+"px"),rn(u.current,"height",C+"px"),m.width=P,m.height=C)},[a]),ci("set opacity and z-index",()=>{const g=c.current,m=u.current;rn(g,"opacity",i),rn(m,"opacity",i),rn(g,"z-index",o),rn(m,"z-index",s)},[i,o,s]),ci("set display",()=>{if(!a.getShape(e))return;const v=a.getCulledShapes().has(e);v!==h.current.isCulled&&(rn(c.current,"display",v?"none":"block"),rn(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,"data-shape-id":n.id,draggable:!1,children:d.jsx(Uu,{fallback:l,onError:p,children:d.jsx(Ij,{shape:n,util:r})})}),d.jsx("div",{ref:c,className:"tl-shape","data-shape-type":n.type,"data-shape-is-filled":f,"data-shape-id":n.id,draggable:!1,children:d.jsx(Uu,{fallback:l,onError:p,children:d.jsx(_j,{shape:n,util:r})})})]})}),_j=w.memo(function({shape:e,util:n}){return Tg("InnerShape:"+e.type,()=>n.component(n.editor.store.unsafeGetWithoutCapture(e.id)),[n,e.id])},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta&&t.util===e.util),Ij=w.memo(function({shape:e,util:n}){return Tg("InnerShape:"+e.type,()=>{var r;return(r=n.backgroundComponent)==null?void 0:r.call(n,n.editor.store.unsafeGetWithoutCapture(e.id))},[n,e.id])},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta&&t.util===e.util);function Vq({className:t}){const e=z(),{Background:n,SvgDefs:r,ShapeIndicators:o}=rt(),s=w.useRef(null),i=w.useRef(null),a=w.useRef(null),l=Mt();Rq(s),EX(),IX(),Oq(s),MX(s);const c=w.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});ci("position layers",function(){const{x:S,y:b,z:P}=e.getCamera();if(c.current.allowTextOutline&&Ge.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&P<e.options.textShadowLod!==c.current.lodDisableTextOutline){const E=P<e.options.textShadowLod;l.style.setProperty("--tl-text-outline",E?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=E}const C=P>=1?Ol(P,[1,8],[.125,.5],!0):Ol(P,[.1,1],[-2,.125],!0),_=`scale(${N(P)}) translate(${N(S+C)}px,${N(b+C)}px)`;rn(i.current,"transform",_),rn(a.current,"transform",_)},[e,l]);const u=m1(),h=U("shapeSvgDefs",()=>{const y=new Map;for(const S of ut(e.shapeUtils)){if(!S)return;const b=S.getCanvasSvgDefs();for(const{key:P,component:C}of b)y.has(P)||y.set(P,d.jsx(C,{},P))}return[...y.values()]},[e]),p=U("debug_shapes",()=>bt.hideShapes.get(),[bt]),f=U("debug_svg",()=>bt.debugSvg.get(),[bt]),g=U("debug_geometry",()=>bt.debugGeometry.get(),[bt]),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(aZ,{}),d.jsx(lZ,{}),r&&d.jsx(r,{})]})}),n&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(n,{})}),d.jsx(Xq,{}),d.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(hZ,{}),d.jsx(dZ,{}),p?null:f?d.jsx(rZ,{}):d.jsx(sZ,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:a,className:"tl-html-layer",children:[g?d.jsx(Bq,{}):null,d.jsx(eZ,{}),d.jsx(Zq,{}),d.jsx(qq,{}),d.jsx(Qq,{}),o&&d.jsx(o,{}),d.jsx(iZ,{}),d.jsx(Jq,{}),d.jsx(uZ,{}),d.jsx(Uq,{})]})}),d.jsx(pZ,{})]}),d.jsx(Gq,{}),d.jsx(Yq,{})]})}function Yq(){const{InFrontOfTheCanvas:t}=rt();return t?d.jsx(t,{}):null}function Xq(){const t=z(),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 qq(){const t=z(),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 Zq(){const t=z(),e=U("brush",()=>t.getInstanceState().brush,[t]),{Brush:n}=rt();return n&&e?d.jsx(n,{className:"tl-user-brush",brush:e}):null}function Qq(){const t=z(),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 Jq(){const t=z(),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 eZ(){const t=z(),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(tZ,{shapeId:e}):null}function tZ({shapeId:t}){const e=z(),{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(nZ,{shapeId:t,handle:l,zoom:r,isCoarse:o},l.id))})})}function nZ({shapeId:t,handle:e,zoom:n,isCoarse:r}){const o=Dq(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 rZ(){const t=z();return U("rendering shapes",()=>t.getRenderingShapes(),[t]).map(n=>d.jsxs(w.Fragment,{children:[d.jsx(Cj,{...n}),d.jsx(cZ,{id:n.id,mode:"iframe"})]},n.id+"_fragment"))}function oZ(){const t=z(),e=w.useRef(new Set);return ci("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 sZ(){const t=z(),e=U("rendering shapes",()=>t.getRenderingShapes(),[t]);return d.jsxs(d.Fragment,{children:[e.map(n=>d.jsx(Cj,{...n},n.id+"_shape")),Ge.isSafari&&d.jsx(oZ,{})]})}function iZ(){const t=z(),{ShapeIndicator:e}=rt(),n=U("hinting shape ids",()=>Sw(t.getHintingShapeIds()),[t]);return!n.length||!e?null:n.map(r=>d.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function aZ(){return d.jsxs("g",{id:ro("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 lZ(){const t=ro("cursor_hint");return d.jsx("path",{id:t,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function cZ({id:t,mode:e}){const n=z(),[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=jo("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 uZ(){const t=z(),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 dZ(){const t=z(),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 hZ(){const{OnTheCanvas:t}=rt();return t?d.jsx(t,{}):null}function pZ(){const t=z(),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 fZ({className:t,zoom:e,point:n,color:r,viewport:o,opacity:s=1}){const i=w.useRef(null);ec(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));const a=ro("cursor_hint");return d.jsxs("svg",{ref:i,className:le("tl-overlays__item",t),children:[d.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--color-background)"}),d.jsx("use",{href:`#${a}`,color:r,opacity:s})]})}const xI=w.memo(function({className:e,zoom:n,point:r,color:o,name:s,chatMessage:i}){const a=w.useRef(null);ec(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n);const l=ro("cursor");return r?d.jsxs("div",{ref:a,className:le("tl-overlays__item",e),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:`#${l}`,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 gZ({x:t,y:e,z:n,size:r}){const o=Jl("grid"),s=z(),{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?Ol(n,[a,l],[0,1]):1;return d.jsx("pattern",{id:d1(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 mZ({handle:t,isCoarse:e,className:n,zoom:r}){const o=z(),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=xX.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 yZ=({children:t})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:t}),SZ=()=>{const{Spinner:t}=rt();return d.jsx(D1,{children:t?d.jsx(t,{}):null})};function S1(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+=Bn(r,o);return e?`M${Bn(t[0],t[1])}Q${je(t[1])}${Bn(t[1],t[2])}T${s}${Bn(t[n-1],t[0])}${Bn(t[0],t[1])}Z`:`M${je(t[0])}Q${je(t[1])}${Bn(t[1],t[2])}${t.length>3?"T":""}${s}L${je(t[n-1])}`}function wI({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:S1(t.points,!1),stroke:n??`var(--color-${t.color})`,fill:"none",strokeWidth:8/e,opacity:r??t.opacity})}):null}function Ej({bounds:t,rotation:e}){const n=w.useRef(null);return ec(n,t.x,t.y,1,e),w.useLayoutEffect(()=>{const r=n.current;r&&(r.style.width=N(Math.max(1,t.width))+"px",r.style.height=N(Math.max(1,t.height))+"px")},[t.width,t.height]),d.jsx("div",{ref:n,className:"tl-selection__bg",draggable:!1})}function vZ({bounds:t,rotation:e}){const n=z(),r=w.useRef(null),o=U("only selected shape",()=>n.getOnlySelectedShape(),[n]),s=o?n.getShapeUtil(o).expandSelectionOutlinePx(o):0;return ec(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:N(t.width),height:N(t.height)})})}const xZ=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),wZ=({shape:t,util:e})=>Tg("Indicator: "+t.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(t.id))),bZ=({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(Uu,{fallback:r,onError:o=>t.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(wZ,{shape:n,util:t.getShapeUtil(n)},n.id)})},bI=w.memo(function({shapeId:e,className:n,color:r,hidden:o,opacity:s}){const i=z(),a=w.useRef(null);return ci("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(bZ,{editor:i,id:e})})})}),PZ=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),kj=w.memo(function(){const e=z(),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 CZ({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 _Z({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=Gr(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=Gr(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 IZ({className:t,line:e,zoom:n}){return d.jsx("svg",{className:le("tl-overlays__item",t),children:e.type==="points"?d.jsx(CZ,{...e,zoom:n}):e.type==="gaps"?d.jsx(_Z,{...e,zoom:n}):null})}function v1(){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 EZ=()=>null;function Tj(t,e){const n=w.useRef(t);return e(t,n.current)?n.current:(n.current=t,t)}const kZ=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:RT(t,e));function Xs(t){return Tj(t,kZ)}const TZ=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:NT(t,e));function tc(t){return Tj(t,TZ)}const Mj=w.createContext(null);function MZ({overrides:t={},children:e}){const n=tc(t),r=w.useMemo(()=>({Background:pX,SvgDefs:EZ,Brush:Hy,ZoomBrush:Hy,CollaboratorBrush:Hy,Cursor:xI,CollaboratorCursor:xI,CollaboratorHint:fZ,CollaboratorShapeIndicator:bI,Grid:gZ,Scribble:wI,SnapIndicator:IZ,Handles:yZ,Handle:mZ,CollaboratorScribble:wI,ErrorFallback:jj,ShapeErrorFallback:xZ,ShapeIndicatorErrorFallback:PZ,Spinner:v1,SelectionBackground:Ej,SelectionForeground:vZ,ShapeIndicators:kj,ShapeIndicator:bI,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:Vq,LoadingScreen:SZ,...n}),[n]);return d.jsx(Mj.Provider,{value:r,children:e})}function rt(){const t=w.useContext(Mj);if(!t)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return t}const $g={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 Aj(){$g.hardReset()}function AZ(){$g.refreshPage()}const jZ="https://github.com/tldraw/tldraw/issues/new",jj=({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=()=>{AZ()},y=async()=>{Aj()},S=new URL(jZ);return S.searchParams.set("title",u),S.searchParams.set("labels","bug"),S.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(u1,{onError:Ru,fallback:()=>null,children:d.jsx(p1,{editor: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:y,children:"Reset data"})]})]}):d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Something went wrong"}),d.jsx("p",{children:"Please refresh the page to continue."}),d.jsxs("p",{children:["If you keep seeing this screen, you can create a"," ",d.jsx("a",{href:S.toString(),children:"GitHub issue"})," or ask for help on"," ",d.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"Discord"}),". If you are still stuck, you can reset the tldraw data on your machine. This may erase the project you were working on, so try to get help first."]}),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"})]})]})]})})]})},Oj="TLDRAW_USER_DATA_v3",Dj=Pe({id:ye,name:ye.nullable().optional(),color:ye.nullable().optional(),locale:ye.nullable().optional(),animationSpeed:fe.nullable().optional(),edgeScrollSpeed:fe.nullable().optional(),colorScheme:Og("light","dark","system").optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional(),isDynamicSizeMode:we.nullable().optional(),isPasteAtCursorMode:we.nullable().optional()}),ts={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},x1=Math.max(...Object.values(ts));function OZ(t){t.version<ts.AddAnimationSpeed&&(t.user.animationSpeed=1),t.version<ts.AddIsSnapMode&&(t.user.isSnapMode=!1),t.version<ts.MakeFieldsNullable,t.version<ts.AddEdgeScrollSpeed&&(t.user.edgeScrollSpeed=1),t.version<ts.AddExcalidrawSelectMode&&(t.user.isWrapMode=!1),t.version<ts.AllowSystemColorScheme&&(t.user.isDarkMode===!0?t.user.colorScheme="dark":t.user.isDarkMode===!1&&(t.user.colorScheme="light"),delete t.user.isDarkMode),t.version<ts.AddDynamicSizeMode&&(t.user.isDynamicSizeMode=!1),t.version<ts.AddPasteAtCursor&&(t.user.isPasteAtCursorMode=!1),t.version=x1}const Px=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function Rj(){return Px[Math.floor(Math.random()*Px.length)]}function DZ(){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 xo=Object.freeze({name:"New User",locale:aX(),color:Rj(),edgeScrollSpeed:1,animationSpeed:DZ()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"light"});function Yy(){return{id:ze(),color:Rj()}}function Lj(t){if(t===null||typeof t!="object"||!("version"in t)||!("user"in t)||typeof t.version!="number")return Yy();const e=tt(t);OZ(e);try{return Dj.validate(e.user)}catch{return Yy()}}function RZ(){const t=JSON.parse(_w(Oj)||"null")??null;return Lj(t)}const Fg=Et("globalUserData",null);function LZ(){Iw(Oj,JSON.stringify({version:x1,user:Fg.get()}))}function $j(t){Dj.validate(t),Fg.set(t),LZ(),FZ()}const $Z=typeof process<"u"&&!1,xl=typeof BroadcastChannel<"u"&&!$Z?new BroadcastChannel("tldraw-user-sync"):null;xl==null||xl.addEventListener("message",t=>{const e=t.data;(e==null?void 0:e.type)===Nj&&(e==null?void 0:e.origin)!==Fj()&&Fg.set(Lj(e.data))});let Xy=null;function Fj(){return Xy===null&&(Xy=ze()),Xy}const Nj="tldraw-user-preferences-change";function FZ(){xl==null||xl.postMessage({type:Nj,origin:Fj(),data:{user:zj(),version:x1}})}function zj(){let t=Fg.get();return t||(t=RZ(),$j(t)),t}const NZ=G("defaultLocalStorageUserPrefs",()=>zj());function Bj(t={}){return{userPreferences:t.userPreferences??NZ,setUserPreferences:t.setUserPreferences??$j}}var Uj={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],y=arguments.length,S,b;if(v.fn){switch(v.once&&this.removeListener(c,v.fn,void 0,!0),y){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,S=new Array(y-1);b<y;b++)S[b-1]=arguments[b];v.fn.apply(v.context,S)}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),y){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(!S)for(C=1,S=new Array(y-1);C<y;C++)S[C-1]=arguments[C];v[b].fn.apply(v[b].context,S)}}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=[],y=g.length;m<y;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})(Uj);var zZ=Uj.exports;const BZ=xi(zZ),wl="TLDRAW_TAB_ID_v2",gs=globalThis.window;function UZ(){return gs?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(gs.navigator.platform)||Ge.isDarwin&&"ontouchend"in document:!1}const $f=gs?gs[wl]??QT(wl)??"TLDRAW_INSTANCE_STATE_V1_"+ze():"<error>";gs&&(gs[wl]=$f,UZ()?Ew(wl,$f):JT(wl));gs==null||gs.addEventListener("beforeunload",()=>{Ew(wl,$f)});const Hj={Initial:0},Ng=Math.max(...Object.values(Hj));function HZ(t){t.version<Hj.Initial,t.version=Ng}const Kj=Pe({version:fe,currentPageId:zu.optional(),isFocusMode:we.optional(),exportBackground:we.optional(),isDebugMode:we.optional(),isToolLocked:we.optional(),isGridMode:we.optional(),pageStates:Kt(Pe({pageId:zu,camera:Pe({x:fe,y:fe,z:fe}).optional(),selectedShapeIds:Kt(Ir).optional(),focusedGroupId:Ir.nullable().optional()})).optional()});function KZ(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!==Ng&&(t=tt(t),HZ(t));try{return Kj.validate(t)}catch(e){return console.warn(e),null}}function w1(t){const e=t.query.ids("page");return G("sessionStateSnapshot",()=>{const n=t.get(bn);if(!n)return null;const r=[...e.get()];return{version:Ng,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(Qr.createId(o)),i=t.get(Eo.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}})}},{isEqual:gA})}function Cx(t,e,n){const r=KZ(e);if(!r)return;const o=AA(t.get(bn)),s=n!=null&&n.forceOverwrite?r:o,i=n!=null&&n.forceOverwrite?o:r,a=t.schema.types.instance.create({id:bn,...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=Eo.createId(h.pageId),f=Qr.createId(h.pageId),g=t.get(p),m=t.get(f);t.put([Eo.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)}),Qr.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 WZ(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!==bn)[0];if(!n)return null;const r={version:Ng,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 Kj.validate(r),r}catch{return null}}function Wj(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:lu(i.value,(a,{typeName:l})=>t.scopedTypes.document.has(l))}}else r=e;const o=AA(t.get(bn)),s=Gj.get(t,w1).get();t.atomic(()=>{r.document&&t.loadStoreSnapshot(r.document),o&&t.update(bn,i=>({...i,...o})),s&&Cx(t,s),r.session&&Cx(t,r.session,{forceOverwrite:n==null?void 0:n.forceOverwriteSessionState})})}const Gj=new Ro;function GZ(t){const n=Gj.get(t,w1).get();if(!n)throw new Error("Session state is not ready yet");return{document:t.getStoreSnapshot(),session:n}}function Vj(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 gi({children:t,className:e="",...n}){return d.jsx("svg",{...n,className:le("tl-svg-container",e),children:t})}function b1(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 gd(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 VZ(t,e,n){const r=[];let o;for(let s=0,i=n.length-1;s<i;s++)o=b1(t,e,n[s],n[s+1]),o&&r.push(o);return r.length===0?null:r}function P1(t,e,n){const r=[];let o;for(let s=1,i=n.length;s<i+1;s++)o=b1(t,e,n[s-1],n[s%n.length]),o&&r.push(o);return r.length===0?null:r}function YZ(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 _x(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=gd(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function PI(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=gd(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function mh(t,e,n){return(n.y-t.y)*(e.x-t.x)>(e.y-t.y)*(n.x-t.x)}function C1(t,e,n,r){return mh(t,n,r)!==mh(e,n,r)&&mh(t,e,n)!==mh(t,e,r)}function CI(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],hr(r,e)){const c=qy(r);n.has(c)||n.set(c,r)}for(let a=0,l=e.length;a<l;a++)if(r=e[a],hr(r,t)){const c=qy(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=b1(r,o,s,i);if(h!==null){const p=qy(h);n.has(p)||n.set(p,h)}}}return n.size===0?null:XZ([...n.values()])}function qy(t){return`${t.x},${t.y}`}function XZ(t){const e=x.Average(t);return t.sort((n,r)=>x.Angle(e,n)-x.Angle(e,r))}function _1(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],C1(n,r,o,s))return!0}return!1}function qZ(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],C1(n,r,o,s))return!0}return!1}class us extends Ti{constructor(n){super({...n,isClosed:!1,isFilled:!1});I(this,"start");I(this,"end");I(this,"d");I(this,"u");I(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,d:s,u:i,ul:a}=this;if(s.len()===0||a===0)return r;const l=x.Sub(n,r).dpr(i)/a,c=r.x+i.x*l;if(c<Math.min(r.x,o.x))return r.x<o.x?r:o;if(c>Math.max(r.x,o.x))return r.x>o.x?r:o;const u=r.y+i.y*l;return u<Math.min(r.y,o.y)?r.y<o.y?r:o:u>Math.max(r.y,o.y)?r.y>o.y?r:o:new x(c,u)}hitTestLineSegment(n,r,o=0){return C1(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 nc extends Ti{constructor(n){super({isClosed:!1,isFilled:!1,...n});I(this,"points");I(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 us({start:s,end:i}))}this.isClosed&&this._segments.push(new us({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 xt extends nc{constructor(e){super({...e}),this.isClosed=!0}}class No extends xt{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)]});I(this,"x");I(this,"y");I(this,"w");I(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 oo{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){}}I(oo,"props"),I(oo,"migrations"),I(oo,"type");function qr(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 _I({bounds:t,className:e}){const n=z(),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}=qr(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 cp extends oo{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const n=this.editor.getSortedChildIdsForParent(e.id);return n.length===0?new No({width:1,height:1,isFilled:!1}):new $r({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 xt({points:i,isFilled:!0}):new nc({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(gi,{children:d.jsx(_I,{className:"tl-group",bounds:i})})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx(_I,{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}}}I(cp,"type","group"),I(cp,"props",HA),I(cp,"migrations",KA);const Yj=[cp],ZZ=new Set(Yj.map(t=>t.type));function Xj(t){const e=[...Yj],n=new Set;for(const r of t){if(ZZ.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 qj(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 Lo(o,e);return Le(a.ok),await t(a)}catch(a){return console.error(a),null}})();return n.set(o,i),i}}const zg=qj(async t=>await Zr.blobToDataUrl(await t.blob())),QZ=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,JZ=/@font-face\s*{([^}]+)}/gi,Zj=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,eQ=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function tQ(t){return Array.from(t.matchAll(QZ),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function Qj(t,e){return Array.from(t.matchAll(JZ),n=>{const r=n[1],o=Array.from(r.matchAll(Zj),i=>{var l;const a=i[1]||i[2]||i[3];return{original:a,resolved:((l=ge(a,e))==null?void 0:l.href)??null}}),s=new Set(Array.from(r.matchAll(eQ),i=>(i[1]||i[2]||i[3]).toLowerCase()));return{fontFace:r,urls:o,fontFamilies:s}})}function nQ(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 Jj(t){return!(t.startsWith("-")||t.startsWith("animation")||t.startsWith("transition")||t==="cursor"||t==="pointer-events"||t==="user-select"||t==="touch-action")}function rQ(t,e){return{imports:tQ(t),fontFaces:Qj(t,e)}}function oQ(t){return Array.from(t.matchAll(Zj),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}const sQ=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 eO(t){return sQ.has(t)}var iQ=Object.create,tO=Object.defineProperty,aQ=Object.getOwnPropertyDescriptor,lQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),nO=t=>{throw TypeError(t)},rO=(t,e,n)=>e in t?tO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,cQ=t=>[,,,iQ(null)],oO=["class","method","getter","setter","accessor","field","value","get","set"],sO=t=>t!==void 0&&typeof t!="function"?nO("Function expected"):t,uQ=(t,e,n,r,o)=>({kind:oO[t],name:e,metadata:r,addInitializer:s=>n._?nO("Already initialized"):o.push(sO(s||null))}),dQ=(t,e)=>rO(e,lQ("metadata"),t[3]),hQ=(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},pQ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=oO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,aQ(o,n)),y=r.length-1;y>=0;y--)l=uQ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,sO(i)&&(v[g]=i);return v&&tO(o,n,v),o},yh=(t,e,n)=>rO(t,typeof e!="symbol"?e+"":e,n),iO,Bg;iO=[Kn];class I1{constructor(){hQ(Bg,5,this),yh(this,"fontFacesPromise",null),yh(this,"foundFontNames",new Set),yh(this,"fontFacesToEmbed",new Set),yh(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){Le(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=fQ()}onFontFamilyValue(e){Le(this.fontFacesPromise,"FontEmbedder not started");const n=nQ(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=zg(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}}Bg=cQ();pQ(Bg,1,"onFontFamilyValue",iO,I1);dQ(Bg,I1);async function fQ(){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(Qj(r.cssText,e.href??document.baseURI)):r instanceof CSSImportRule&&t.push(Ix(r.href));else e.href&&t.push(Ix(e.href))}return me(await Promise.all(t)).flat()}const Ix=qj(async t=>{const e=rQ(await t.text(),t.url),n=await Promise.all(e.imports.map(({url:r})=>Ix(new URL(r,t.url).href)));return[...e.fontFaces,...me(n).flat()]});function aO(t){if(t.shadowRoot)return t.shadowRoot.childNodes;if(SQ(t)){const e=t.assignedNodes();if(e!=null&&e.length)return e}return t.childNodes}function*Ex(t){for(const e of aO(t))gQ(e)&&(yield e)}function Ug(t){var e;return((e=t.ownerDocument)==null?void 0:e.defaultView)??globalThis}function gQ(t){return t instanceof Ug(t).Element}function mQ(t){return t instanceof Ug(t).ShadowRoot}function yQ(t){return"getRootNode"in t&&mQ(t.getRootNode())}function SQ(t){return yQ(t)&&t instanceof Ug(t).HTMLSlotElement}function vQ(t){return t.style}function E1(t,e){return Ug(t).getComputedStyle(t,e)}const ea={};class xQ{constructor(e){I(this,"styles",new Map);I(this,"fonts",new I1);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const n=Array.from(Ex(e));for(;n.length;){const r=n.pop();n.push(...Ex(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:n=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const o=n?CQ(e.tagName.toLowerCase()):ea,s=r?((a=this.styles.get(e.parentElement))==null?void 0:a.self)??ea:ea,i={self:wQ(e,{defaultStyles:o,parentStyles:s}),before:II(e,"::before"),after:II(e,"::after")};this.styles.set(e,i)}fetchResources(){const e=[];for(const n of this.styles.values())for(const r of ut(n))if(r)for(const[o,s]of Object.entries(r)){if(!s)continue;o==="font-family"&&this.fonts.onFontFamilyValue(s);const i=oQ(s);i.length!==0&&e.push(...i.map(async({url:a,original:l})=>{const c=await zg(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 aO(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-${ze()}`;n.classList.add(s),r.before&&(e+=`.${s}::before {${EI(r.before)}}
99
- `),r.after&&(e+=`.${s}::after {${EI(r.after)}}
100
- `)}const o=vQ(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(){PQ()}}function wQ(t,{defaultStyles:e,parentStyles:n}){return t.computedStyleMap?lO(t.computedStyleMap(),{defaultStyles:e,parentStyles:n}):k1(E1(t),{defaultStyles:e,parentStyles:n})}function II(t,e){const n=E1(t,e),r=n.getPropertyValue("content");if(!(r===""||r==="none"))return k1(n,{defaultStyles:ea,parentStyles:ea})}function lO(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t.keys()){if(!Jj(o))continue;const s=t.get(o).toString();e[o]!==s&&(n[o]===s&&eO(o)||(r[o]=s))}return r}function k1(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t){if(!Jj(o))continue;const s=t.getPropertyValue(o);e[o]!==s&&(n[o]===s&&eO(o)||(r[o]=s))}return r}function EI(t){let e="";for(const[n,r]of Object.entries(t))e+=`${n}: ${r};`;return e}let bl;const kI={};function bQ(){if(!bl){const t=document.createElement("iframe");t.style.display="none",document.body.appendChild(t);const e=zn(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),bl={iframe:t,foreignObject:r,document:e}}return bl}function PQ(){bl&&(document.body.removeChild(bl.iframe),bl=void 0)}const TI={defaultStyles:ea,parentStyles:ea};function CQ(t){let e=kI[t];if(!e){const{foreignObject:n,document:r}=bQ(),o=r.createElement(t);n.appendChild(o),e=o.computedStyleMap?lO(o.computedStyleMap(),TI):k1(E1(o),TI),n.removeChild(o),kI[t]=e}return e}function _Q(t,e){Array.from(t.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function MI(t,e){return t.replaceWith(e),e}async function du(t,e){const n=document.createElement("img");e&&_Q(e,n),n.setAttribute("src",t??"data:"),n.setAttribute("decoding","sync"),n.setAttribute("loading","eager");try{await n.decode()}catch{}return n}async function IQ(t){try{const e=t.toDataURL();return await du(e,t)}catch{return await du(null,t)}}async function EQ(t){try{const e=await ar.getVideoFrameAsDataUrl(t);return du(e,t)}catch(e){console.error("Could not get video frame",e)}if(t.poster){const e=await zg(t.poster);return du(e,t)}return du(null,t)}async function cO(t){if(t instanceof HTMLCanvasElement)return MI(t,await IQ(t));if(t instanceof HTMLVideoElement)return MI(t,await EQ(t));if(t instanceof HTMLImageElement){const e=t.currentSrc||t.src,n=await zg(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(Ex(t),e=>cO(e)))}function Hg(t){const e=w.useRef();return w.useLayoutEffect(()=>{e.current=t}),w.useDebugValue(t),w.useCallback((...n)=>{const r=e.current;return Le(r,"fn does not exist"),r(...n)},[])}const T1=w.createContext(null);function kQ({context:t,editor:e,children:n}){const r=e.options.exportProvider;return d.jsx(p1,{editor:e,children:d.jsx(dj,{container:e.getContainer(),children:d.jsx(T1.Provider,{value:t,children:d.jsx(r,{children:n})})})})}function md(){return w.useContext(T1)}function TQ(){const t=w.useContext(T1),[e]=w.useState(yw);return w.useEffect(()=>(t==null||t.waitUntil(e),()=>{e.resolve()}),[e,t]),Hg(()=>{e.resolve()})}var MQ=Object.create,uO=Object.defineProperty,AQ=Object.getOwnPropertyDescriptor,jQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),dO=t=>{throw TypeError(t)},hO=(t,e,n)=>e in t?uO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,OQ=t=>[,,,MQ(null)],pO=["class","method","getter","setter","accessor","field","value","get","set"],fO=t=>t!==void 0&&typeof t!="function"?dO("Function expected"):t,DQ=(t,e,n,r,o)=>({kind:pO[t],name:e,metadata:r,addInitializer:s=>n._?dO("Already initialized"):o.push(fO(s||null))}),RQ=(t,e)=>hO(e,jQ("metadata"),t[3]),LQ=(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},$Q=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=pO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,AQ(o,n)),y=r.length-1;y>=0;y--)l=DQ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,fO(i)&&(v[g]=i);return v&&uO(o,n,v),o},AI=(t,e,n)=>hO(t,typeof e!="symbol"?e+"":e,n),gO,Kg;gO=[Kn];class M1{constructor(e){this.maxDelayTimeMs=e,LQ(Kg,5,this),AI(this,"isResolved",!1),AI(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 Wv(0)}async resolve(){const e=Wv(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}}Kg=OQ();$Q(Kg,1,"waitUntil",gO,M1);RQ(Kg,M1);function FQ(t,e,n={}){var y,S;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{(S=(y=document.body).focus)==null||S.call(y)}catch{}const g=new M1(t.options.maxExportDelayMs),m=yw();return g.waitUntil(m),{jsx:d.jsx(NQ,{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 NQ({editor:t,preserveAspectRatio:e,scale:n,bbox:r,background:o,singleFrameShapeId:s,isDarkMode:i,renderingShapes:a,onMount:l,waitUntil:c}){const u=Jl(),h=ks({isDarkMode:i}),p=qw("export state",{defsById:{},shapeElements:null}),{defsById:f,shapeElements:g}=U(p),m=Hg(S=>{p.update(b=>{if(no(b.defsById,S.key))return b;const P=Promise.resolve(S.getElement());return c(P.then(C=>{p.update(_=>({..._,defsById:{..._.defsById,[S.key]:{pending:!1,element:C}}}))})),{...b,defsById:{...b.defsById,[S.key]:{pending:!0,element:P}}}})}),v=w.useMemo(()=>({isDarkMode:i,waitUntil:c,addExportDef:m}),[i,c,m]),y=w.useRef(!1);return w.useLayoutEffect(()=>{if(y.current)throw new Error("SvgExport should only render once - do not use with react strict mode");y.current=!0,(async()=>{const S={},b=a.map(async({id:C,opacity:_,index:E,backgroundIndex:k})=>{var $,M;if(C===s)return[];const D=t.getShape(C);if(t.isShapeOfType(D,"group"))return[];const T=[],j=t.getShapeUtil(D);if(j.toSvg||j.toBackgroundSvg){const[O,F]=await Promise.all([($=j.toSvg)==null?void 0:$.call(j,D,v),(M=j.toBackgroundSvg)==null?void 0:M.call(j,D,v)]),B=t.getShapePageTransform(D);let K=B.toCssString(),R=1;"scale"in D.props&&D.props.scale!==1&&(R=D.props.scale,K=`${K} scale(${D.props.scale}, ${D.props.scale})`);const H=t.getShapeMask(D.id),Y=H?q.From(q.Inverse(B)).applyToPoints(H):null,ee=d1(u,D.id);Y&&(S[ee]={pending:!1,element:d.jsx("clipPath",{id:ee,children:d.jsx("path",{d:`M${Y.map(({x:he,y:ue})=>`${he/R},${ue/R}`).join("L")}Z`})})}),O&&T.push({zIndex:E,element:d.jsx("g",{transform:K,opacity:_,clipPath:H?`url(#${ee})`:void 0,children:O},`fg_${D.id}`)}),F&&T.push({zIndex:k,element:d.jsx("g",{transform:K,opacity:_,clipPath:H?`url(#${ee})`:void 0,children:F},`bg_${D.id}`)})}else T.push({zIndex:E,element:d.jsx(jI,{shape:D,util:j,component:_j,className:"tl-shape",bbox:r,opacity:_},`fg_${D.id}`)}),j.backgroundComponent&&T.push({zIndex:k,element:d.jsx(jI,{shape:D,util:j,component:Ij,className:"tl-shape tl-shape-background",bbox:r,opacity:_},`bg_${D.id}`)});return T}),P=(await Promise.all(b)).flat();wa.flushSync(()=>{p.update(C=>({...C,shapeElements:P.sort((_,E)=>_.zIndex-E.zIndex).map(({element:_})=>_),defsById:{...C.defsById,...S}}))})})()},[r,t,v,u,a,s,p]),w.useEffect(()=>{g!==null&&l()},[l,g]),d.jsx(kQ,{editor:t,context:v,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?h.solid:h.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(f).map(([S,b])=>b.pending?null:d.jsx(w.Fragment,{children:b.element},S))}),g]})})}function jI({shape:t,util:e,className:n,component:r,bbox:o,opacity:s}){const i=z(),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(u1,{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})})})})}let zQ=1;async function BQ(t,e,n={}){const r=FQ(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=IT(s,{identifierPrefix:`export_${zQ++}_`});try{await Promise.resolve(),wa.flushSync(()=>{i.render(r.jsx)}),await r.exportDelay.resolve();const a=s.firstElementChild;return Le(a instanceof SVGSVGElement,"Expected an SVG element"),await UQ(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{i.unmount(),o.removeChild(s)},0)}}async function UQ(t){const e=[...t.querySelectorAll("foreignObject.tl-shape-foreign-object > *")];if(!e.length)return;const n=new xQ(t);try{n.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(s=>cO(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 Vr={menus:Et("open menus",[]),getOpenMenus(t){return t?this.menus.get().filter(e=>e.endsWith("-"+t)):this.menus.get()},addOpenMenu(t,e=""){const n=e?`${t}-${e}`:t,r=new Set(this.menus.get());r.has(n)||(r.add(n),this.menus.set([...r]))},deleteOpenMenu(t,e=""){const n=e?`${t}-${e}`:t,r=new Set(this.menus.get());r.has(n)&&(r.delete(n),this.menus.set([...r]))},clearOpenMenus(t){this.menus.set(t?this.menus.get().filter(e=>!e.endsWith("-"+t)):[])},_hiddenMenus:[],hideOpenMenus(t){if(this._hiddenMenus=[...this.getOpenMenus(t)],this._hiddenMenus.length!==0)for(const e of this._hiddenMenus)this.deleteOpenMenu(e,t)},showOpenMenus(t){if(this._hiddenMenus.length!==0){for(const e of this._hiddenMenus)this.addOpenMenu(e,t);this._hiddenMenus=[]}},isMenuOpen(t,e){return this.getOpenMenus(e).includes(t)},hasOpenMenus(t){return this.getOpenMenus(t).length>0},hasAnyOpenMenus(){return this.getOpenMenus().length>0},forContext(t){return{getOpenMenus:()=>this.getOpenMenus(t),addOpenMenu:e=>this.addOpenMenu(e,t),deleteOpenMenu:e=>this.deleteOpenMenu(e,t),clearOpenMenus:()=>this.clearOpenMenus(t),isMenuOpen:e=>this.isMenuOpen(e,t),hasOpenMenus:()=>this.hasOpenMenus(t),hasAnyOpenMenus:()=>this.hasAnyOpenMenus()}}},kx=new h7,HQ={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,actionShortcutsLocation:"swap",createTextOnCanvasDoubleClick:!0,exportProvider:w.Fragment};function OI(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 Ot(t)}}class KQ{constructor(e){I(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(!OI(o,e.get(r)))return!1;n.add(r)}for(const[r,o]of e)if(!n.has(r)&&!OI(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 Tx extends KQ{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:Ot(r,"type")}}}function WQ(t,e,n){return Lo(t).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:n})})}const GQ="https://cdn.tldraw.com";function ei(){return`${GQ}/${oj}`}function VQ(t){switch(t.type){case"shapes":return`s${t.shapeIds.map(n=>Zy(n.slice(6))).join(".")}`;case"page":return"p"+Zy(yr.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+="."+Zy(yr.parseId(n))),r}default:Ot(t)}}function YQ(t){switch(t[0]){case"s":return{type:"shapes",shapeIds:t.slice(1).split(".").filter(Boolean).map(r=>Ke(decodeURIComponent(r)))};case"p":return{type:"page",pageId:yr.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?yr.createId(decodeURIComponent(i)):void 0}}default:throw Error("Invalid deep link string")}}function Zy(t){return encodeURIComponent(t).replace(/\./g,"%2E")}function XQ(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 Sh(t,e,n,r){if(n.length===0)return[];const o=new Map;for(const i of me(n.map(a=>t.getShape(a)))){const{parentId:a}=i;o.has(a)||o.set(a,{children:me(t.getSortedChildIdsForParent(a).map(l=>t.getShape(l))),moving:new Set}),o.get(a).moving.add(i)}const s=[];switch(e){case"toBack":{o.forEach(({moving:i,children:a})=>qQ(i,a,s));break}case"toFront":{o.forEach(({moving:i,children:a})=>ZQ(i,a,s));break}case"forward":{o.forEach(({moving:i,children:a})=>QQ(t,i,a,s,r));break}case"backward":{o.forEach(({moving:i,children:a})=>JQ(t,i,a,s,r));break}}return s}function qQ(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=Dl(o,s,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function ZQ(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=Dl(o,s,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function DI(t,e){const n=t.getShapeGeometry(e),r=t.getShapePageTransform(e);return!n||!r?null:r.applyToPoints(n.vertices)}function mO(t,e){const n=Array.from(e).map(o=>{const s=DI(t,o);return s?{shape:o,vertices:s}:null}).filter(Boolean);return o=>{const s=DI(t,o);return s?n.some(i=>_1(i.vertices,s)):!1}}function QQ(t,e,n,r,o){var l;const s=mO(t,e),i=n.length;if(e.size===i)return;let a={name:"skipping"};for(let c=0;c<i;c++){const u=e.has(n[c]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(u||!(o!=null&&o.considerAllShapes)&&!s(n[c]))continue;const{selectIndex:h}=a;Dl(n[c].index,(l=n[c+1])==null?void 0:l.index,c-h).forEach((p,f)=>{const g=n[h+f];e.has(g)&&r.push({...g,index:p})}),a={name:"skipping"};break}}}}function JQ(t,e,n,r,o){var l;const s=mO(t,e),i=n.length;if(e.size===i)return;let a={name:"skipping"};for(let c=i-1;c>-1;c--){const u=e.has(n[c]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(u||!(o!=null&&o.considerAllShapes)&&!s(n[c]))continue;Dl((l=n[c-1])==null?void 0:l.index,n[c].index,a.selectIndex-c).forEach((h,p)=>{const f=n[c+p+1];e.has(f)&&r.push({...f,index:h})}),a={name:"skipping"};break}}}}function yO({editor:t,ids:e}){const n=me(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 up({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=Fn(l.parentId)?e.getShapePageTransform(l.parentId):q.Identity(),h=x.RotWith(c,o??s,t),p=q.applyToPoint(q.Inverse(u),h),f=Ji(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 eJ=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(Zi(s))return o();const a=s,l=n.getDiffSince(i);if(l===ur)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(S=>S.id!==f.id);m!=null&&m.length?c.set(f.fromId,m):c.delete(f.fromId);const v=c.get(f.toId),y=v==null?void 0:v.filter(S=>S.id!==f.id);y!=null&&y.length?c.set(f.toId,y):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 ut(f.added))p(g);for(const[g,m]of ut(f.updated))u(g),p(m);for(const g of ut(f.removed))u(g)}return c??a})};function tJ(t,e,n){const r=t.getShapeMaskedPageBounds(e);return r===void 0?!0:!n.includes(r)}const nJ=t=>{function e(n){const r=n.getCurrentPageShapeIds(),o=n.getViewportPageBounds(),s=new Set;return r.forEach(i=>{tJ(n,i,o)&&s.add(i)}),s}return G("getCulledShapes",n=>{if(Zi(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})},rJ=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(cn),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return G("parentsToChildrenWithIndexes",(o,s)=>{if(Zi(o))return r();const i=n.getDiffSince(s);if(i===ur)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))al(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(al(g)&&al(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))al(f)&&(l(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const h of c){const p=me(h.map(f=>t.get(f)));p.sort(cn),h.splice(0,h.length,...p.map(f=>f.id))}return a??o})},Qy=(t,e,n)=>{for(;!Rn(n.parentId);){const r=t.get(n.parentId);if(!r)return!1;n=r}return n.parentId===e},oJ=(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=>Qy(t,s,t.get(i))))}return G("_shapeIdsInCurrentPage",(s,i)=>{if(Zi(s))return o();const a=e();if(a!==r)return o();const l=t.history.getDiffSince(i);if(l===ur)return o();const c=new sp(s);for(const h of l){for(const p of Object.values(h.added))al(p)&&Qy(t,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))al(f)&&(Qy(t,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(h.removed))Fn(p)&&c.remove(p)}const u=c.get();return u?Wc(u.value,u.diff):s})};var sJ=Object.create,SO=Object.defineProperty,iJ=Object.getOwnPropertyDescriptor,aJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),vO=t=>{throw TypeError(t)},xO=(t,e,n)=>e in t?SO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,lJ=t=>[,,,sJ(null)],wO=["class","method","getter","setter","accessor","field","value","get","set"],bO=t=>t!==void 0&&typeof t!="function"?vO("Function expected"):t,cJ=(t,e,n,r,o)=>({kind:wO[t],name:e,metadata:r,addInitializer:s=>n._?vO("Already initialized"):o.push(bO(s||null))}),uJ=(t,e)=>xO(e,aJ("metadata"),t[3]),dJ=(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},PO=(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,iJ(o,n)),y=r.length-1;y>=0;y--)l=cJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,bO(i)&&(v[g]=i);return v&&SO(o,n,v),o},La=(t,e,n)=>xO(t,typeof e!="symbol"?e+"":e,n),CO,_O,yd;const hJ=40;_O=[Kn],CO=[Kn];class Wg{constructor(e){this.editor=e,dJ(yd,5,this),La(this,"_clickId",""),La(this,"_clickTimeout"),La(this,"_clickScreenPoint"),La(this,"_previousScreenPoint"),La(this,"_clickState","idle"),La(this,"lastPointerInfo",{})}_getClickTimeout(e,n=ze()){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)>hJ**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"}}yd=lJ();PO(yd,1,"_getClickTimeout",_O,Wg);PO(yd,1,"cancelDoubleClickTimeout",CO,Wg);uJ(yd,Wg);class pJ{constructor(e){I(this,"_isEdgeScrolling",!1);I(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?Dt.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 fJ{constructor(e,n){I(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 Ac(t){return mJ}class gJ{constructor(){I(this,"length",0);I(this,"head",null);I(this,"tail",this)}push(e){return new A1(e,this)}toArray(){return ps}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const mJ=new gJ;class A1{constructor(e,n){I(this,"length");this.head=e,this.tail=n,this.length=n.length+1}push(e){return new A1(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 yJ{constructor(e){I(this,"store");I(this,"dispose");I(this,"state","recording");I(this,"pendingDiff",new vJ);I(this,"stacks",Et("HistoryManager.stacks",{undos:Ac(),redos:Ac()},{isEqual:(e,n)=>e.undos===n.undos&&e.redos===n.redos}));I(this,"annotateError");I(this,"_isInBatch",!1);this.store=e.store,this.annotateError=e.annotateError??Ru,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:Ac()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(n.changes);break;case"paused":break;default:Ot(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=SJ[n.history]);try{if(this._isInBatch)return Oo(e),this;this._isInBatch=!0;try{Oo(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=fA(a),c=fx(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":cu(c,[fx(h.diff)]);break;case"stop":if(!n)break e;if(h.id===n){u=!0;break e}break;default:Ot(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=wf();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")cu(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=wf();return cu(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:n.push({type:"diff",diff:o}),redos:i})),this}_mark(e){Oo(()=>{this.flushPendingDiff(),this.stacks.update(({undos:n,redos:r})=>({undos:n.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:Ac(),redos:Ac()}),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 SJ={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class vJ{constructor(){I(this,"diff",wf());I(this,"isEmptyAtom",Et("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=wf(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){cu(this.diff,[e]),this.isEmptyAtom.set(fA(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class xJ{constructor(e){I(this,"scribbleItems",new Map);I(this,"state","paused");this.editor=e}addScribble(e,n=ze()){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 wJ=Object.create,IO=Object.defineProperty,bJ=Object.getOwnPropertyDescriptor,PJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),EO=t=>{throw TypeError(t)},kO=(t,e,n)=>e in t?IO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,CJ=t=>[,,,wJ(null)],TO=["class","method","getter","setter","accessor","field","value","get","set"],MO=t=>t!==void 0&&typeof t!="function"?EO("Function expected"):t,_J=(t,e,n,r,o)=>({kind:TO[t],name:e,metadata:r,addInitializer:s=>n._?EO("Already initialized"):o.push(MO(s||null))}),IJ=(t,e)=>kO(e,PJ("metadata"),t[3]),EJ=(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},Gg=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=TO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,bJ(o,n)),y=r.length-1;y>=0;y--)l=_J(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,MO(i)&&(v[g]=i);return v&&IO(o,n,v),o},kJ=(t,e,n)=>kO(t,e+"",n),AO,jO,OO,DO,_a;const pe=t=>Math.round(t*10**8)/10**8;function ns(t,e,n,r,o){const s=t.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&pe(a.length)===pe(n)&&Gr(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=ns(t,l,n,r,Gr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function TJ(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=>pe(s.startEdge[0].x)===pe(i.startEdge[0].x)&&pe(s.startEdge[0].y)===pe(i.startEdge[0].y)&&pe(s.startEdge[1].x)===pe(i.startEdge[1].x)&&pe(s.startEdge[1].y)===pe(i.startEdge[1].y))&&o.gaps.some(i=>pe(s.endEdge[0].x)===pe(i.endEdge[0].x)&&pe(s.endEdge[0].y)===pe(i.endEdge[0].y)&&pe(s.endEdge[1].x)===pe(i.endEdge[1].x)&&pe(s.endEdge[1].y)===pe(i.endEdge[1].y)))){t.splice(e,1);break}}}}DO=[G],OO=[G],jO=[G],AO=[G];class rc{constructor(e){this.manager=e,EJ(_a,5,this),kJ(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:zn(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&&Mc(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:Gr(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&&Mc(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:Gr(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,y;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=n.clone().translate(o),l=r.map(({x:S,y:b},P)=>({id:"selection:"+P,x:S+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:((y=h[0])==null?void 0:y.nudge)??0);p.x=0,p.y=0,u.length=0,h.length=0,l.forEach(S=>{S.x+=f.x,S.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 E,k;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=Fq(u)),c<0&&(u=$q(u)),s&&(a.center=e.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",f=RI(u,a),g=this.getSnappablePoints(),m=[],v=[],y=new x(i,i);this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:f});const S=new x(h?0:((E=m[0])==null?void 0:E.nudge)??0,p?0:((k=v[0])==null?void 0:k.nudge)??0);if(o&&Nq(u)&&S.len()!==0){const D=m.length&&v.length?Math.abs(S.x)<Math.abs(S.y)?"x":"y":m.length?"x":"y",T=e.aspectRatio;D==="x"?(v.length=0,S.y=S.x/T,(u==="bottom_left"||u==="top_right")&&(S.y=-S.y)):(m.length=0,S.x=S.y*T,(u==="bottom_left"||u==="top_right")&&(S.x=-S.x))}const b=x.Add(n,S),{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=RI("any",P);m.length=0,v.length=0,y.x=0,y.y=0,this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:C});const _=this.getPointSnapLines({nearestSnapsX:m,nearestSnapsY:v});return this.manager.setIndicators([..._]),{nudge:S}}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);pe(c)<=pe(r.x)&&(pe(c)<pe(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),pe(u)<=pe(r.y)&&(pe(u)<pe(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(!Mc(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&&pe(Math.abs(c))<=pe(n.x)){pe(Math.abs(c))<pe(n.x)&&(r.length=0),n.x=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},S=r.find(({type:P})=>P==="gap_center"),b=S&&Gr(a.breadthIntersection[0],a.breadthIntersection[1],S.gap.breadthIntersection[0],S.gap.breadthIntersection[1]);S&&S.gap.length>a.length&&b?r[r.indexOf(S)]=y:(!S||!b)&&r.push(y)}const h=a.startNode.pageBounds.minX-a.length,p=e.maxX,f=h-p;pe(Math.abs(f))<=pe(n.x)&&(pe(Math.abs(f))<pe(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;pe(Math.abs(v))<=pe(n.x)&&(pe(Math.abs(v))<pe(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(!Mc(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&&pe(Math.abs(c))<=pe(n.y)){pe(Math.abs(c))<pe(n.y)&&(o.length=0),n.y=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},S=o.find(({type:P})=>P==="gap_center"),b=S&&Mc(S.gap.breadthIntersection[0],S.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);S&&S.gap.length>a.length&&b?o[o.indexOf(S)]=y:(!S||!b)&&o.push(y);continue}const h=a.startNode.pageBounds.minY-a.length,p=e.maxY,f=h-p;pe(Math.abs(f))<=pe(n.y)&&(pe(Math.abs(f))<pe(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;pe(Math.abs(v))<=pe(n.y)&&(pe(Math.abs(v))<pe(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=pe(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=pe(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:ze(),type:"points",points:Sw(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=Gr(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:ze(),gaps:[...ns(s,h.id,m,"backward",v),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:g},...ns(s,p.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Gr(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:ze(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(v=>v.clone().addXY(-h.pageBounds.width,0))},{startEdge:u,endEdge:g},...ns(s,p.id,f,"forward",m)]:[...ns(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=Gr(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:ze(),gaps:[...ns(o,h.id,m,"backward",v),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:g},...ns(o,l.gap.endNode.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Gr(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:ze(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(v=>v.clone().addXY(0,-h.pageBounds.height))},{startEdge:u,endEdge:g},...ns(o,p.id,f,"forward",m)]:[...ns(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 TJ(a),a}}_a=CJ();Gg(_a,1,"getSnapPointsCache",DO,rc);Gg(_a,1,"getSnappablePoints",OO,rc);Gg(_a,1,"getSnappableGapNodes",jO,rc);Gg(_a,1,"getVisibleGaps",AO,rc);IJ(_a,rc);function RI(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 MJ=Object.create,RO=Object.defineProperty,AJ=Object.getOwnPropertyDescriptor,jJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),LO=t=>{throw TypeError(t)},$O=(t,e,n)=>e in t?RO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,OJ=t=>[,,,MJ(null)],FO=["class","method","getter","setter","accessor","field","value","get","set"],NO=t=>t!==void 0&&typeof t!="function"?LO("Function expected"):t,DJ=(t,e,n,r,o)=>({kind:FO[t],name:e,metadata:r,addInitializer:s=>n._?LO("Already initialized"):o.push(NO(s||null))}),RJ=(t,e)=>$O(e,jJ("metadata"),t[3]),LJ=(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},$J=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=FO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,AJ(o,n)),y=r.length-1;y>=0;y--)l=DJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,NO(i)&&(v[g]=i);return v&&RO(o,n,v),o},FJ=(t,e,n)=>$O(t,e+"",n),zO,Vg;const NJ=()=>null,zJ=()=>[];zO=[G];class j1{constructor(e){this.manager=e,LJ(Vg,5,this),FJ(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):NJ,s=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):zJ;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=zn(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=zn(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=zn(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=zn(this.editor.getShapePageTransform(e)).applyToPoint(n),s=this.getHandleSnapPosition({currentShapeId:e,handle:n,handleInPageSpace:o});return s?(this.manager.setIndicators([{id:ze(),type:"points",points:[s]}]),{nudge:x.Sub(s,o)}):null}}Vg=OJ();$J(Vg,1,"getSnapGeometryCache",zO,j1);RJ(Vg,j1);var BJ=Object.create,BO=Object.defineProperty,UJ=Object.getOwnPropertyDescriptor,HJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),UO=t=>{throw TypeError(t)},HO=(t,e,n)=>e in t?BO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,KJ=t=>[,,,BJ(null)],KO=["class","method","getter","setter","accessor","field","value","get","set"],WO=t=>t!==void 0&&typeof t!="function"?UO("Function expected"):t,WJ=(t,e,n,r,o)=>({kind:KO[t],name:e,metadata:r,addInitializer:s=>n._?UO("Already initialized"):o.push(WO(s||null))}),GJ=(t,e)=>HO(e,HJ("metadata"),t[3]),VJ=(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},O1=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=KO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,UJ(o,n)),y=r.length-1;y>=0;y--)l=WJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,WO(i)&&(v[g]=i);return v&&BO(o,n,v),o},Jy=(t,e,n)=>HO(t,typeof e!="symbol"?e+"":e,n),GO,VO,YO,oc;YO=[G],VO=[G],GO=[G];class Sd{constructor(e){this.editor=e,VJ(oc,5,this),Jy(this,"shapeBounds"),Jy(this,"handles"),Jy(this,"_snapIndicators",Et("snapLines",void 0)),this.shapeBounds=new rc(this),this.handles=new j1(this)}getIndicators(){return this._snapIndicators.get()??ps}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(Fn(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())}}oc=KJ();O1(oc,1,"getSnapThreshold",YO,Sd);O1(oc,1,"getSnappableShapes",VO,Sd);O1(oc,1,"getCurrentCommonAncestor",GO,Sd);GJ(oc,Sd);const YJ=/\r?\n|\r/g;function LI(t){return t.replace(YJ,`
102
- `).split(`
103
- `).map(e=>e||" ").join(`
104
- `)}const XJ={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},qJ=/\s/;class ZJ{constructor(e){I(this,"baseElem");this.editor=e,this.baseElem=document.createElement("div"),this.baseElem.classList.add("tl-text"),this.baseElem.classList.add("tl-text-measure"),this.baseElem.tabIndex=-1}measureText(e,n){const r=this.baseElem.cloneNode();this.editor.getContainer().appendChild(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=LI(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 y=a.getClientRects(),S=y[y.length-1],b=S.top+i,P=S.left+s,C=S.right+s,_=P<f,E=qJ.test(v);if(E!==h||b!==p||!u){if(u){if(n&&b!==p){g=!0;break}r.push(u)}u={box:{x:P,y:b,w:S.width,h:S.height},text:v},f=P}else _&&(u.box.x=P),u.box.w=_?u.box.w+S.width:C-u.box.x,u.text+=v;v===`
105
- `&&(f=0),h=E,p=b,c+=v.length}return u&&r.push(u),{spans:r,didTruncate:g}}measureTextSpans(e,n){if(e==="")return[];const r=this.baseElem.cloneNode();this.editor.getContainer().appendChild(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",XJ[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=LI(e);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(n.overflow==="truncate-ellipsis"&&l){r.textContent="…";const c=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-c}px`),r.textContent=i;const u=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,h=u[u.length-1];return u.push({text:"…",box:{x:Math.min(h.box.x+h.box.w,n.width-n.padding-c),y:h.box.y,w:c,h:h.box.h}}),u}return r.remove(),a}}var QJ=Object.create,XO=Object.defineProperty,JJ=Object.getOwnPropertyDescriptor,eee=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),qO=t=>{throw TypeError(t)},ZO=(t,e,n)=>e in t?XO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,tee=t=>[,,,QJ(null)],QO=["class","method","getter","setter","accessor","field","value","get","set"],JO=t=>t!==void 0&&typeof t!="function"?qO("Function expected"):t,nee=(t,e,n,r,o)=>({kind:QO[t],name:e,metadata:r,addInitializer:s=>n._?qO("Already initialized"):o.push(JO(s||null))}),ree=(t,e)=>ZO(e,eee("metadata"),t[3]),oee=(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},eD=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=QO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,JJ(o,n)),y=r.length-1;y>=0;y--)l=nee(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,JO(i)&&(v[g]=i);return v&&XO(o,n,v),o},vh=(t,e,n)=>ZO(t,typeof e!="symbol"?e+"":e,n),tD,nD,vd;const $I=tM;nD=[Kn],tD=[Kn];class Yg{constructor(e){this.editor=e,oee(vd,5,this),vh(this,"cancelRaf"),vh(this,"isPaused",!0),vh(this,"now",0),vh(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=$I(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=$I(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)}}vd=tee();eD(vd,1,"tick",nD,Yg);eD(vd,1,"dispose",tD,Yg);ree(vd,Yg);var see=Object.create,rD=Object.defineProperty,iee=Object.getOwnPropertyDescriptor,aee=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),oD=t=>{throw TypeError(t)},sD=(t,e,n)=>e in t?rD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,lee=t=>[,,,see(null)],iD=["class","method","getter","setter","accessor","field","value","get","set"],aD=t=>t!==void 0&&typeof t!="function"?oD("Function expected"):t,cee=(t,e,n,r,o)=>({kind:iD[t],name:e,metadata:r,addInitializer:s=>n._?oD("Already initialized"):o.push(aD(s||null))}),uee=(t,e)=>sD(e,aee("metadata"),t[3]),dee=(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},Nr=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=iD[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,iee(o,n)),y=r.length-1;y>=0;y--)l=cee(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,aD(i)&&(v[g]=i);return v&&rD(o,n,v),o},FI=(t,e,n)=>sD(t,typeof e!="symbol"?e+"":e,n),lD,cD,uD,dD,hD,pD,fD,gD,mD,yD,SD,vD,Mn;vD=[G],SD=[G],yD=[G],mD=[G],gD=[G],fD=[G],pD=[G],hD=[G],dD=[G],uD=[G],cD=[G],lD=[G];class Qn{constructor(e,n){if(this.user=e,this.inferDarkMode=n,dee(Mn,5,this),FI(this,"systemColorScheme",Et("systemColorScheme","light")),FI(this,"disposables",new Set),typeof window>"u"||!("matchMedia"in window))return;const r=window.matchMedia("(prefers-color-scheme: dark)");r!=null&&r.matches&&this.systemColorScheme.set("dark");const o=s=>{s.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")};r==null||r.addEventListener("change",o),this.disposables.add(()=>r==null?void 0:r.removeEventListener("change",o))}dispose(){this.disposables.forEach(e=>e())}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??xo.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??xo.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??xo.name}getLocale(){return this.user.userPreferences.get().locale??xo.locale}getColor(){return this.user.userPreferences.get().color??xo.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??xo.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??xo.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??xo.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??xo.isPasteAtCursorMode}}Mn=lee();Nr(Mn,1,"getUserPreferences",vD,Qn);Nr(Mn,1,"getIsDarkMode",SD,Qn);Nr(Mn,1,"getEdgeScrollSpeed",yD,Qn);Nr(Mn,1,"getAnimationSpeed",mD,Qn);Nr(Mn,1,"getId",gD,Qn);Nr(Mn,1,"getName",fD,Qn);Nr(Mn,1,"getLocale",pD,Qn);Nr(Mn,1,"getColor",hD,Qn);Nr(Mn,1,"getIsSnapMode",dD,Qn);Nr(Mn,1,"getIsWrapMode",uD,Qn);Nr(Mn,1,"getIsDynamicResizeMode",cD,Qn);Nr(Mn,1,"getIsPasteAtCursorMode",lD,Qn);uee(Mn,Qn);const hee={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"},pee=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class ie{constructor(e,n){I(this,"performanceTracker");I(this,"id");I(this,"type");I(this,"shapeType");I(this,"initial");I(this,"children");I(this,"isLockable");I(this,"parent");I(this,"_path");I(this,"_current");I(this,"_isActive");I(this,"_currentToolIdMask",Et("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=Et("toolIsActive"+this.id,!1),this._current=Et("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 DT}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=hee[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(bt.measurePerformance.get()&&pee.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;bt.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)}}I(ie,"id"),I(ie,"initial"),I(ie,"children"),I(ie,"isLockable",!0);class Mx 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}}}}I(Mx,"id","root"),I(Mx,"initial","");var fee=Object.create,xD=Object.defineProperty,gee=Object.getOwnPropertyDescriptor,wD=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),bD=t=>{throw TypeError(t)},PD=(t,e,n)=>e in t?xD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,mee=t=>[,,,fee((t==null?void 0:t[wD("metadata")])??null)],CD=["class","method","getter","setter","accessor","field","value","get","set"],_D=t=>t!==void 0&&typeof t!="function"?bD("Function expected"):t,yee=(t,e,n,r,o)=>({kind:CD[t],name:e,metadata:r,addInitializer:s=>n._?bD("Already initialized"):o.push(_D(s||null))}),See=(t,e)=>PD(e,wD("metadata"),t[3]),vee=(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=CD[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,gee(o,n)),y=r.length-1;y>=0;y--)l=yee(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,_D(i)&&(v[g]=i);return v&&xD(o,n,v),o},de=(t,e,n)=>PD(t,typeof e!="symbol"?e+"":e,n),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,cR,uR,dR,hR,pR,fR,gR,mR,yR,SR,vR,xR,wR,bR,PR,CR,_R,IR,ER,kR,TR,MR,AR,jR,OR,DR,RR,LR,$R,FR,NR,zR,BR,UR,HR,Ax,J;class Q extends(Ax=BZ,HR=[G],UR=[G],BR=[G],zR=[G],NR=[G],FR=[G],$R=[G],LR=[G],RR=[G],DR=[G],OR=[G],jR=[G],AR=[G],MR=[G],TR=[G],kR=[G],ER=[G],IR=[G],_R=[G],CR=[G],PR=[G],bR=[G],wR=[G],xR=[G],vR=[G],SR=[G],yR=[G],mR=[G],gR=[G],fR=[G],pR=[G],hR=[G],dR=[G],uR=[G],cR=[G],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({isEqual:(e,n)=>e.equals(n)})],jD=[G],AD=[G],MD=[G],TD=[Kn],kD=[Kn],ED=[Kn],ID=[Kn],Ax){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}){var D;super(),vee(J,5,this),de(this,"_isShapeHiddenPredicate"),de(this,"options"),de(this,"contextId",ze()),de(this,"store"),de(this,"root"),de(this,"disposables",new Set),de(this,"isDisposed",!1),de(this,"_tickManager"),de(this,"snaps"),de(this,"timers",kx.forContext(this.contextId)),de(this,"user"),de(this,"textMeasure"),de(this,"environment",Ge),de(this,"scribbles"),de(this,"sideEffects"),de(this,"edgeScrollManager"),de(this,"focusManager"),de(this,"getContainer"),de(this,"shapeUtils"),de(this,"styleProps"),de(this,"bindingUtils"),de(this,"history"),de(this,"_shouldIgnoreShapeLock",!1),de(this,"_crashingError",null),de(this,"_isChangingStyleTimeout",-1),de(this,"menus",Vr.forContext(this.contextId)),de(this,"_cameraOptions",Et("camera options",rI)),de(this,"_viewportAnimation",null),de(this,"_willSetInitialBounds",!0),de(this,"_isLockedOnFollowingUser",Et("isLockedOnFollowingUser",!1)),de(this,"_cameraState",Et("camera state","idle")),de(this,"_cameraStateTimeoutRemaining",0),de(this,"_currentPageShapeIds"),de(this,"_parentIdsToChildIds"),de(this,"animatingShapes",new Map),de(this,"externalAssetContentHandlers",{file:null,url:null}),de(this,"temporaryAssetPreview",new Map),de(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null}),de(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,metaKey:!1,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,isSpacebarPanning:!1,pointerVelocity:new x}),de(this,"_clickManager",new Wg(this)),de(this,"_prevCursor","default"),de(this,"_shiftKeyTimeout",-1),de(this,"_altKeyTimeout",-1),de(this,"_ctrlKeyTimeout",-1),de(this,"_metaKeyTimeout",-1),de(this,"_restoreToolId","select"),de(this,"_pinchStart",1),de(this,"_didPinch",!1),de(this,"_selectedShapeIdsAtPointerDown",[]),de(this,"_longPressTimeout",-1),de(this,"capturedPointerId",null),de(this,"performanceTracker"),de(this,"performanceTrackerTimeout",-1),de(this,"_pendingEventsForNextTick",[]),this._isShapeHiddenPredicate=p,this.options={...HQ,...h},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new yJ({store:e,annotateError:T=>{this.annotateError(T,{origin:"history.batch",willCrashApp:!0}),this.crash(T)}}),this.snaps=new Sd(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...rI,...a}),this.user=new Qn(n??Bj(),u??!1),this.disposables.add(()=>this.user.dispose()),this.getContainer=i,this.textMeasure=new ZJ(this),this._tickManager=new Yg(this);class f extends Mx{}I(f,"initial",l??""),this.root=new f(this),this.root.children={};const g=Xj(r),m={},v={},y=new Map;for(const T of g){const j=new T(this);m[T.type]=j;const $=xA(T.props??{});v[T.type]=$;for(const M of $.keys())if(!y.has(M.id))y.set(M.id,M);else if(y.get(M.id)!==M)throw Error(`Multiple style props with id "${M.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=m,this.styleProps=v;const S=Vj(o),b={};for(const T of S){const j=new T(this);b[T.type]=j}this.bindingUtils=b;for(const T of[...s]){if(no(this.root.children,T.id))throw Error(`Can't override tool with id "${T.id}"`);this.root.children[T.id]=new T(this,this.root)}this.scribbles=new xJ(this);const P=(T,j)=>{let $=null;const M=T.selectedShapeIds.filter(B=>!j.has(B));M.length!==T.selectedShapeIds.length&&($||($={...T}),$.selectedShapeIds=M);const O=T.erasingShapeIds.filter(B=>!j.has(B));O.length!==T.erasingShapeIds.length&&($||($={...T}),$.erasingShapeIds=O),T.hoveredShapeId&&j.has(T.hoveredShapeId)&&($||($={...T}),$.hoveredShapeId=null),T.editingShapeId&&j.has(T.editingShapeId)&&($||($={...T}),$.editingShapeId=null);const F=T.hintingShapeIds.filter(B=>!j.has(B));return F.length!==T.hintingShapeIds.length&&($||($={...T}),$.hintingShapeIds=F),T.focusedGroupId&&j.has(T.focusedGroupId)&&($||($={...T}),$.focusedGroupId=null),$};this.sideEffects=this.store.sideEffects;let C=new Map;const _=new Set,E=new Set;let k=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var T,j,$,M;_.clear();for(const O of E){E.delete(O);const F=this.getShape(O);if(!F)continue;const B=this.getShapeUtil(F),K=(T=B.onChildrenChange)==null?void 0:T.call(B,F);K!=null&&K.length&&this.updateShapes(K)}if(k.size){const O=k;k=new Set;for(const F of O){const B=this.getBindingUtil(F);(j=B.onOperationComplete)==null||j.call(B)}}if(C.size){const O=C;C=new Map;for(const F of O.values())(M=($=this.getBindingUtil(F.binding)).onAfterDelete)==null||M.call($,F)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(T,j)=>{var $,M,O,F;for(const B of this.getBindingsInvolvingShape(j))k.add(B.type),B.fromId===j.id&&((M=($=this.getBindingUtil(B)).onAfterChangeFromShape)==null||M.call($,{binding:B,shapeBefore:T,shapeAfter:j})),B.toId===j.id&&((F=(O=this.getBindingUtil(B)).onAfterChangeToShape)==null||F.call(O,{binding:B,shapeBefore:T,shapeAfter:j}));if(T.parentId!==j.parentId){const B=K=>{var H,Y,ee,he;const R=this.getShape(K);if(R)for(const ue of this.getBindingsInvolvingShape(R))k.add(ue.type),ue.fromId===R.id&&((Y=(H=this.getBindingUtil(ue)).onAfterChangeFromShape)==null||Y.call(H,{binding:ue,shapeBefore:R,shapeAfter:R})),ue.toId===R.id&&((he=(ee=this.getBindingUtil(ue)).onAfterChangeToShape)==null||he.call(ee,{binding:ue,shapeBefore:R,shapeAfter:R}))};B(j.id),this.visitDescendants(j.id,B)}if(T.parentId!==j.parentId&&Rn(j.parentId)){const B=new Set([T.id]);this.visitDescendants(T.id,K=>{B.add(K)});for(const K of this.getPageStates()){if(K.pageId===j.parentId)continue;const R=P(K,B);R&&this.store.put([R])}}T.parentId&&Fn(T.parentId)&&E.add(T.parentId),j.parentId!==T.parentId&&Fn(j.parentId)&&E.add(j.parentId)},beforeDelete:T=>{var O,F,B,K;if(_.has(T.id))return;T.parentId&&Fn(T.parentId)&&E.add(T.parentId),_.add(T.id);const j=[];for(const R of this.getBindingsInvolvingShape(T)){k.add(R.type),j.push(R.id);const H=this.getBindingUtil(R);R.fromId===T.id?((O=H.onBeforeIsolateToShape)==null||O.call(H,{binding:R,removedShape:T}),(F=H.onBeforeDeleteFromShape)==null||F.call(H,{binding:R,shape:T})):((B=H.onBeforeIsolateFromShape)==null||B.call(H,{binding:R,removedShape:T}),(K=H.onBeforeDeleteToShape)==null||K.call(H,{binding:R,shape:T}))}j.length&&this.deleteBindings(j);const $=new Set([T.id]),M=me(this.getPageStates().map(R=>P(R,$)));M.length&&this.store.put(M)}},binding:{beforeCreate:T=>{var $,M;const j=(M=($=this.getBindingUtil(T)).onBeforeCreate)==null?void 0:M.call($,{binding:T});return j||T},afterCreate:T=>{var j,$;k.add(T.type),($=(j=this.getBindingUtil(T)).onAfterCreate)==null||$.call(j,{binding:T})},beforeChange:(T,j)=>{var M,O;const $=(O=(M=this.getBindingUtil(j)).onBeforeChange)==null?void 0:O.call(M,{bindingBefore:T,bindingAfter:j});return $||j},afterChange:(T,j)=>{var $,M;k.add(j.type),(M=($=this.getBindingUtil(j)).onAfterChange)==null||M.call($,{bindingBefore:T,bindingAfter:j})},beforeDelete:T=>{var j,$;($=(j=this.getBindingUtil(T)).onBeforeDelete)==null||$.call(j,{binding:T})},afterDelete:T=>{var j,$;($=(j=this.getBindingUtil(T)).onAfterDelete)==null||$.call(j,{binding:T}),k.add(T.type)}},page:{afterCreate:T=>{const j=Eo.createId(T.id),$=Qr.createId(T.id);this.store.has(j)||this.store.put([Eo.create({id:j})]),this.store.has($)||this.store.put([Qr.create({id:$,pageId:T.id})])},afterDelete:(T,j)=>{var O,F;if(((O=this.getInstanceState())==null?void 0:O.currentPageId)===T.id){const B=(F=this.getPages().find(K=>K.id!==T.id))==null?void 0:F.id;B?this.store.put([{...this.getInstanceState(),currentPageId:B}]):j==="user"&&this.store.ensureStoreIsUsable()}const $=Eo.createId(T.id),M=Qr.createId(T.id);this.store.remove([$,M])}},instance:{afterChange:(T,j,$)=>{var M;if(!this.store.has(j.currentPageId)){const O=this.store.has(T.currentPageId)?T.currentPageId:(M=this.getPages()[0])==null?void 0:M.id;O?this.store.update(j.id,F=>({...F,currentPageId:O})):$==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(T,j)=>{if((T==null?void 0:T.selectedShapeIds)!==(j==null?void 0:j.selectedShapeIds)){const $=j.selectedShapeIds.filter(O=>{var B,K;let F=(B=this.getShape(O))==null?void 0:B.parentId;for(;Fn(F);){if(j.selectedShapeIds.includes(F))return!1;F=(K=this.getShape(F))==null?void 0:K.parentId}return!0});let M=null;if($.length>0){const O=this.findCommonAncestor(me($.map(F=>this.getShape(F))),F=>this.isShapeOfType(F,"group"));O&&(M=O)}else j!=null&&j.focusedGroupId&&(M=j.focusedGroupId);($.length!==j.selectedShapeIds.length||M!==j.focusedGroupId)&&this.store.put([{...j,selectedShapeIds:$,focusedGroupId:M??null}])}}}})),this._currentPageShapeIds=oJ(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=rJ(this.store),this.disposables.add(this.store.listen(T=>{this.emit("change",T)})),this.disposables.add(this.history.dispose),this.run(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})},{history:"ignore"}),l&&this.root.children[l]===void 0)throw Error(`No state found for initialState "${l}".`);if(this.root.enter(void 0,"initial"),this.edgeScrollManager=new pJ(this),this.focusManager=new fJ(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 DT,(D=this.store.props.collaboration)!=null&&D.mode){const T=this.store.props.collaboration.mode;this.disposables.add(jo("update collaboration mode",()=>{this.store.put([{...this.getInstanceState(),isReadonly:T.get()==="readonly"}])}))}}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=hn(this.shapeUtils,n);return Le(r,`No shape util found for type "${n}"`),r}getBindingUtil(e){const n=typeof e=="string"?e:e.type,r=hn(this.bindingUtils,n);return Le(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??ze()),this}markHistoryStoppingPoint(e){const n=`[${e??"stop"}]_${ze()}`;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 vw(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(yx)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(bn)}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.menus.getOpenMenus()}addOpenMenu(e){return this.menus.addOpenMenu(e),this}deleteOpenMenu(e){return this.menus.deleteOpenMenu(e),this}clearOpenMenus(){return this.menus.clearOpenMenus(),this}getIsMenuOpen(){return this.menus.hasAnyOpenMenus()}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 Qr.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 me(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=me(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 me(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:Sw(n)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return me(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 Eo.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||!n.camera||!n.screenBounds)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}=zI(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 Ot(e.constraints.initialZoom)}}getBaseZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.baseZoom==="default")return 1;const{zx:n,zy:r}=zI(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 Ot(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.setCamera(this.getCamera()),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,y=this.getBaseZoom(),S=c*y,b=l*y;if(n!=null&&n.reset&&(i=this.getInitialZoom()),i<b||i>S){const{x:$,y:M,z:O}=r,F=-$+u.w/O/2,B=-M+u.h/O/2;i=zt(i,b,S);const K=-$+u.w/i/2,R=-M+u.h/i/2;o=$+K-F,s=M+R-B}const P=f/i-g.x,C=p/i-g.y,_=(u.w-f*2)/i-g.w,E=(u.h-p*2)/i-g.h,k=P+_*h.origin.x,D=C+E*h.origin.y,T=typeof h.behavior=="string"?h.behavior:h.behavior.x,j=typeof h.behavior=="string"?h.behavior:h.behavior.y;if(n!=null&&n.reset)o=k,s=D;else{switch(T){case"fixed":{o=k;break}case"contain":{i<m?o=k:o=zt(o,P+_,P);break}case"inside":{i<m?o=zt(o,P,(u.w-f)/i-g.w):o=zt(o,P+_,P);break}case"outside":{o=zt(o,f/i-g.w,(u.w-f)/i);break}case"free":break;default:throw Ot(T)}switch(j){case"fixed":{s=D;break}case"contain":{i<v?s=D:s=zt(s,C+E,C);break}case"inside":{i<v?s=zt(s,C,(u.h-p)/i-g.h):s=zt(s,C+E,C);break}case"outside":{s=zt(s,p/i-g.h,(u.h-p)/i);break}case"free":break;default:throw Ot(j)}}}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:(Oo(()=>{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(bn);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:oI.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),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(me(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(wX,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:Ky}){const{animation:r,...o}=n;if(!r)return;const{duration:s=0,easing:i=Dt.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(s=>s.userId===e);if(!r)return this;const o=r.cursor;return o?(this.run(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const s=r.currentPageId===this.getCurrentPageId();s||this.setCurrentPage(r.currentPageId),n&&n.animation&&!s&&(n.animation=void 0),this.centerOnPoint(o,n);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,e]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],l=a.indexOf(e);l<0||(a.splice(l,1),this.updateInstanceState({highlightedUserIds:a}))},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,!ui(document.body.scrollWidth,e.maxX,1),!ui(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(bn),{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(bn),{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=>M9(e.filter(s=>s.userId===r),s=>s.lastActivityTimestamp??0)):ps}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 Oo(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const s=jo("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(_e(h.minX,u.minX,g),_e(h.minY,u.minY,g),_e(h.width,u.width,g),_e(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(a7)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return Array.from(this._getAllPagesQuery().get()).sort(cn)}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}]),this.setCamera(this.getCamera())},{history:"record-preserveRedoStack"})):(console.error("Tried to set the current page id to a page that doesn't exist."),this)}updatePage(e){return this.getIsReadonly()?this:this.getPage(e.id)?this.run(()=>this.store.update(e.id,r=>({...r,...e}))):this}createPage(e){return this.run(()=>{if(this.getIsReadonly()||this.getPages().length>=this.options.maxPages)return;const n=this.getPages(),r=XQ(e.name??"Page 1",n.map(i=>i.name));let o=e.index;(!o||n.some(i=>i.index===o))&&(o=Io(n[n.length-1].index));const s=yr.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.getIsReadonly())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=yr.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=$u(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.getIsReadonly()?this:(this.updatePage({id:r,name:n}),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(e){return this.getIsReadonly()?this:e.length<=0?this:(this.run(()=>this.store.put(e),{history:"ignore"}),this)}updateAssets(e){return this.getIsReadonly()?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.getIsReadonly())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,r){return await this.store.props.assets.upload(e,n,r)}_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(Rn(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||Rn(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(Rn(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=CI(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=CI(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(Rn(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(Rn(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=me(r.map(c=>this.getShape(c)));if(o.length===1){const c=o[0].parentId;return Rn(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 nJ(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 y=this.getShapeMask(v);return y&&!hr(e,y)?!1:s?s(v):!0});for(let v=m.length-1;v>=0;v--){const y=m[v],S=this.getShapeGeometry(y),b=S instanceof $r,P=this.getPointInShapeSpace(y,e);if(this.isShapeOfType(y,"frame")||(this.isShapeOfType(y,"arrow")||this.isShapeOfType(y,"geo")&&y.props.fill==="none")&&y.props.text.trim()){for(const _ of S.children)if(_.isLabel&&_.isPointInBounds(P))return y}if(this.isShapeOfType(y,"frame")){const _=S.distanceToPoint(P,c);if(Math.abs(_)<=i)return g||y;if(S.hitTestPoint(P,0,!0))return g||p||(u?y:void 0);continue}let C;if(b){let _=1/0;for(const E of S.children){if(E.isLabel&&!l)continue;const k=E.distanceToPoint(P,c);k<_&&(_=k)}C=_}else i===0&&(S.bounds.w<1||S.bounds.h<1)||S.bounds.containsPoint(P,i)?C=S.distanceToPoint(P,c):C=1/0;if(S.isClosed){if(C<=i){if(S.isFilled||b&&S.children[0].isFilled)return g||y;if(this.getShapePageBounds(y).contains(o))continue;if(Math.abs(C)<i)Math.abs(C)<f&&(f=Math.abs(C),g=y);else if(!g){const{area:_}=S;_<h&&(h=_,p=y)}}}else if(C<this.options.hitTestMargin/r)return y}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&&!hr(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(Rn(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++)KR(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(Fn(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||!Fn(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 Rn(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=Rn(n)?q.Identity():this.getShapePageTransform(n),a=i.rotation();let l=[];const c=me(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=Dl(r,f.index,o.length):l=gy(r,o.length)}else{const f=c.sort(cn).find(g=>g.index>r);f?l=Dl(r,f.index,o.length):l=gy(r,o.length)}}else{const p=c.length&&c[c.length-1];l=p?gy(p.index,o.length):Fu(o.length)}const u=i.clone().invert(),h=me(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),y=g.rotation()-a;s.push({id:f.id,type:f.type,parentId:n,x:v.x,y:v.y,rotation:y,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 Io(o.index)}getSortedChildIdsForParent(e){const n=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[n];return r||ps}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(cn))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=eJ(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)??ps;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??Qi(),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=So(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=yO({editor:this,ids:o});return s?(up({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=So(r,((s=o.onTranslateStart)==null?void 0:s.call(o,r))??void 0),r=So(r,{id:e.id,type:e.type,x:n.x,y:n.y}),r=So(r,((i=o.onTranslate)==null?void 0:i.call(o,e,r))??void 0),r=So(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,Ke());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=NI(this,s,p=>{const f=[];for(const m of p){const v=this.getBinding(m);if(!v)continue;const y=Qi();f.push({...v,id:y,fromId:zn(a.get(v.fromId)),toId:zn(a.get(v.toId))})}const g=[];for(const m of i){const v=zn(a.get(m)),y=this.getShape(m);if(!y)continue;let S=0,b=0;if(n&&o.has(m)){const P=this.getShapeParentTransform(y),C=new x(n.x,n.y).rot(-P.rotation());S=C.x,b=C.y}g.push({shape:{...y,id:v,x:y.x+S,y:y.y+b,index:"a1",parentId:a.get(y.parentId)??y.parentId},originalShape:y})}return{shapesToCreateWithOriginals:g,bindingsToCreate:f}});l.forEach(({shape:p,originalShape:f})=>{const g=f.parentId,m=this.getSortedChildIdsForParent(g),v=m.indexOf(f.id),y=m[v+1],S=y?this.getShape(y):void 0,b=$u(f.index,S==null?void 0:S.index);p.index=b});const u=l.map(({shape:p})=>p);if(u.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){xh(this);return}if(this.createShapes(u),this.createBindings(c),this.setSelectedShapes(me(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.getIsReadonly())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 xh(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.getIsReadonly()||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=Sh(this,"toBack",n,{considerAllShapes:!0});return r&&this.updateShapes(r),this}sendBackward(e,n={}){const r=typeof e[0]=="string"?e:e.map(s=>s.id),o=Sh(this,"backward",r,n);return o&&this.updateShapes(o),this}bringForward(e,n={}){const r=typeof e[0]=="string"?e:e.map(s=>s.id),o=Sh(this,"forward",r,n);return o&&this.updateShapes(o),this}bringToFront(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=Sh(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.getIsReadonly())return this;let o=me(r.map(i=>this.getShape(i)));if(!o.length)return this;o=me(o.map(i=>this.isShapeOfType(i,"group")?this.getSortedChildIdsForParent(i.id).map(a=>this.getShape(a)):i).flat());const s=Z.Common(me(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.getIsReadonly())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((y,S)=>a[y.id][c]-a[S.id][c]);for(let y=0;y<i-1;y++){const S=s[y],b=s[y+1],P=a[S.id],_=a[b.id][c]-P[u],E=m.find(k=>k.gap===_);E?E.count++:m.push({gap:_,count:1})}let v=0;m.forEach(y=>{y.count>v&&(v=y.count,p=y.gap)}),v===1&&(p=Math.max(0,m.reduce((y,S)=>y+S.gap*S.count,0)/(i-1)))}else p=r;const f=[];let g=a[s[0].id][u];return s.forEach((m,v)=>{var C,_;if(v===0)return;const y={x:0,y:0};y[l]=g+p-a[m.id][l];const S=this.getShapeParent(m),b=S?x.Rot(y,-this.getShapePageTransform(S).decompose().rotation):y,P=(_=(C=this.getShapeUtil(m)).onTranslateStart)==null?void 0:_.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 _,E;const r=typeof e[0]=="string"?e:e.map(k=>k.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const o=r.map(k=>this.getShape(k)).filter(k=>k?this.getShapeUtil(k).canBeLaidOut(k):!1),s={},i={};let a,l,c=0;for(let k=0;k<o.length;k++)a=o[k],l=this.getShapePageBounds(a),s[a.id]=l,i[a.id]=l.clone(),c+=l.width*l.height;const u=Z.Common(me(Object.values(s))),h=u.width;o.sort((k,D)=>s[D.id].height-s[k.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,y;for(let k=0;k<o.length;k++){a=o[k],l=i[a.id];for(let D=f.length-1;D>=0;D--)if(v=f[D],!(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?(y=f.pop(),D<f.length&&(f[D]=y)):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 S=Z.Common(Object.values(i)),b=x.Sub(u.center,S.center);let P;const C=[];for(let k=0;k<o.length;k++){a=o[k],l=s[a.id],P=i[a.id];const D=x.Sub(P.point,l.point).add(b),T=this.getShapeParentTransform(a);T&&D.rot(-T.rotation());const j={id:a.id,type:a.type,x:a.x+D.x,y:a.y+D.y},$=(E=(_=this.getShapeUtil(a)).onTranslateStart)==null?void 0:E.call(_,{...a,...j});$?C.push({...j,...$}):C.push(j)}return C.length&&this.updateShapes(C),this}alignShapes(e,n){const r=typeof e[0]=="string"?e:e.map(l=>l.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const o=me(r.map(l=>this.getShape(l))),s=Object.fromEntries(o.map(l=>[l.id,this.getShapePageBounds(l)])),i=Z.Common(me(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(S=>S.id);if(this.getIsReadonly())return this;if(r.length<3)return this;const o=r.length,s=me(r.map(S=>this.getShape(S))),i=Object.fromEntries(s.map(S=>[S.id,this.getShapePageBounds(S)]));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((S,b)=>i[S.id][l]-i[b.id][l])[0],g=s.sort((S,b)=>i[b.id][c]-i[S.id][c])[0],m=i[f.id][u],v=(i[g.id][u]-m)/(o-1),y=m+v;return s.filter(S=>S!==f&&S!==g).sort((S,b)=>i[S.id][u]-i[b.id][u]).forEach((S,b)=>{const P={x:0,y:0};P[a]=y+v*b-i[S.id][h]/2-i[S.id][a];const C=this.getShapeParent(S),_=C?x.Rot(P,-this.getShapePageTransform(C).rotation()):P;p.push(this.getChangesToTranslateShape(S,x.Add(S,_)))}),this.updateShapes(p),this}stretchShapes(e,n){const r=typeof e[0]=="string"?e:e.map(l=>l.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const o=me(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(me(Object.values(i)));switch(n){case"vertical":{this.run(()=>{for(const l of o){if(this.getShapePageTransform(l).rotation()%Ne)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()%Ne)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.getIsReadonly())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(!lj(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),y=this.getPointInParentSpace(s.id,v),S=new x(n.x,n.y),b=ui((l-c)%Math.PI,0);S.x=b?n.x:n.y,S.y=b?n.y:n.x;const P=q.applyToPoint(a,new x),{x:C,y:_}=this.getPointInParentSpace(s.id,P);let E=s;r.skipStartAndEndCallbacks||(E=So(s,((g=p.onResizeStart)==null?void 0:g.call(p,s))??void 0)),E=So(E,{id:o,type:s.type,x:y.x,y:y.y,...p.onResize({...s,x:C,y:_},{newPoint:y,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:S.x,scaleY:S.y,initialBounds:u,initialShape:s})}),r.skipStartAndEndCallbacks||(E=So(E,((m=p.onResizeEnd)==null?void 0:m.call(p,s,E))??void 0)),this.updateShapes([E])}else{const v=q.applyToPoint(a,u.center),y=this._scalePagePoint(v,i,n,c),S=this.getPointInParentSpace(s.id,v),b=this.getPointInParentSpace(s.id,y),P=x.Sub(b,S);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.getIsReadonly())return this;if(e.length<=0)return this;const n=this.getCurrentPageShapeIds();if(e.length+n.size>this.options.maxShapesPerPage)return xh(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:Ke(),...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,Fn(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 S=p.parentId??o;a.has(S)||a.set(S,this.getHighestIndexForParent(S)),g=a.get(S),a.set(S,Io(g))}const m=f.getDefaultProps();for(const[S,b]of this.styleProps[p.type])m[b]=this.getStyleForNextShape(S);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 y=(h=(u=this.getShapeUtil(v)).onBeforeCreate)==null?void 0:h.call(u,v);y&&(v=y),l.push(v)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)}),this}animateShape(e,n={animation:Ky}){return this.animateShapes([e],n)}animateShapes(e,n={animation:Ky}){if(!n.animation)return this;const{duration:r=500,easing:o=Dt.linear}=n.animation,s=ze();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:So(tt(g),c)},l.push(u),this.animatingShapes.set(g.id,s))}const h=p=>{var v,y;if(i-=p,i<0){const{animatingShapes:S}=this,b=e.filter(P=>P&&S.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 S=0,b=l.length;S<b;S++){const{start:P,end:C}=l[S];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:((y=(v=this.getShapeUtil(C)).getInterpolatedProps)==null?void 0:y.call(v,P,C,a))??C.props})}this._updateShapes(g)};return this.on("tick",h),this}groupShapes(e,n={}){var g;const{groupId:r=Ke(),select:o=!0}=n;if(!Array.isArray(e))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getIsReadonly())return this;const s=typeof e[0]=="string"?e:e.map(m=>m.id);if(s.length<=1)return this;const i=me((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(m=>this.getShape(m))),a=i.sort(cn).map(m=>m.id),l=Z.Common(me(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(cn),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.getIsReadonly())return this;const{select:r=!0}=n,o=typeof e[0]=="string"?e:e.map(l=>l.id),s=me((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.getIsReadonly()||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=So(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.getIsReadonly())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,hn(e.props,o))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),n=new Tx;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 hn(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),n=new Tx;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 NI(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,i;if((r.type==="image"||r.type==="video")&&!((o=r.props.src)!=null&&o.startsWith("data:image"))&&!((s=r.props.src)!=null&&s.startsWith("data:video"))&&!((i=r.props.src)!=null&&i.startsWith("http"))){const a=tt(r),l=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});a.props.src=await Zr.blobToDataUrl(await Lo(l).then(c=>c.blob())),n.push(a)}else n.push(r)})),e.assets=n,e}putContentOntoCurrentPage(e,n={}){var T,j,$;if(this.getIsReadonly())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(M=>[M.id,M])),...Object.fromEntries(e.shapes.map(M=>[M.id,M])),...Object.fromEntries(((T=e.bindings)==null?void 0:T.map(M=>[M.id,M]))??[])},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 M of Object.values(f.value))switch(M.typeName){case"asset":{c.push(M);break}case"shape":{u.push(M);break}case"binding":{h.push(M);break}}const g=new Map(o?u.map(M=>[M.id,M.id]):u.map(M=>[M.id,Ke()])),m=new Map(o?h.map(M=>[M.id,M.id]):h.map(M=>[M.id,Qi()]));let v=this.getCurrentPageId(),y=1/0,S=[];for(const M of this.getSelectedShapes()){if(y===0)break;const O=this.isShapeOfType(M,"frame"),F=this.getShapeAncestors(M);O&&F.push(M);const B=O?F.length+1:F.length;if(B<y)y=B,S=F,v=O?M.id:M.parentId;else if(B===y){if(S.length!==F.length)throw Error(`Ancestors: ${S.length} !== ${F.length}`);if(S.length===0){v=a;break}else{v=a;for(let K=0;K<S.length&&F[K]===S[K];K++)v=F[K].id}}}let b=!1;if(!Rn(v)){const M=this.getShape(v);if(M){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(M)))v=a;else if(l.length===1){const O=u.find(F=>F.id===l[0]);this.isShapeOfType(M,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(M==null?void 0:M.props.w)&&O.props.h===(M==null?void 0:M.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=[],_=u.map(M=>{const O=g.get(M.id),F={...M,id:O};return l.includes(M.id)&&(F.parentId=a,C.push(F)),g.has(F.parentId)?F.parentId=g.get(M.parentId):(l.push(F.id),F.index=P,P=Io(P)),F});if(_.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return xh(this),this;const E=h.map(M=>({...M,id:zn(m.get(M.id)),fromId:zn(g.get(M.fromId)),toId:zn(g.get(M.toId))})),k=[],D=[];for(const M of c)this.store.has(M.id)||((M.type==="image"&&((j=M.props.src)!=null&&j.startsWith("data:image"))||M.type==="video"&&(($=M.props.src)!=null&&$.startsWith("data:video")))&&(D.push(tt(M)),M.props.src=null),k.push(M));return Promise.allSettled(D.map(async M=>{const O=await WQ(M.props.src,M.props.name,M.props.mimeType??"image/png"),F=await this.getAssetForExternalContent({type:"file",file:O,assetId:M.id});if(!F){this.deleteAssets([M.id]);return}this.updateAssets([{...F,id:M.id}])})),this.run(()=>{k.length>0&&this.createAssets(k),this.createShapes(_),this.createBindings(E),r&&this.select(...C.map(K=>K.id)),v!==a&&this.reparentShapes(C.map(K=>K.id),v);const M=_.map(K=>this.getShape(K.id)),O=Z.Common(M.map(K=>this.getShapePageBounds(K)));if(i===void 0)if(Rn(v)){const K=this.getViewportPageBounds();s||K.includes(Z.From(O))?i=O.center:i=K.center}else{const K=this.getShape(v);i=q.applyToPoint(this.getShapePageTransform(K),this.getShapeGeometry(K).bounds.center)}if(C.length===1){const K=C[0];if(this.isShapeOfType(K,"frame"))for(;this.getShapesAtPoint(i).some(R=>this.isShapeOfType(R,"frame")&&R.props.w===K.props.w&&R.props.h===K.props.h);)i.x+=O.w+16}const F=Z.Common(me(C.map(({id:K})=>this.getShapePageBounds(K)))).center,B=x.Sub(i,F);this.updateShapes(C.map(({id:K})=>{const R=this.getShape(K),H=this.getShapeParentTransform(K).decompose().rotation,Y=x.Rot(B,-H);return{id:R.id,type:R.type,x:R.x+Y.x,y:R.y+Y.y}}))}),this}async getSvgElement(e,n={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id);if(r.length!==0)return BQ(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(bn),{x:l,y:c,z:u}=ah(()=>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:Mf,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===oI.CAMERA_MOVE?((v=this.store.unsafeGetWithoutCapture(Mf))==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}getIsReadonly(){return this.getInstanceState().isReadonly}getSnapshot(){return GZ(this.store)}loadSnapshot(e,n){return Wj(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=me(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:Ot(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(YQ(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",VQ((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=vg(i=>i(),(e==null?void 0:e.debounceMs)??500),s=jo("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,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),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,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),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,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),code:"ControlLeft"})}_setMetaKeyTimeout(){this.inputs.metaKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Meta",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),code:"MetaLeft"})}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)),e.metaKey?(clearTimeout(this._metaKeyTimeout),this._metaKeyTimeout=-1,n.metaKey=!0):!e.metaKey&&n.metaKey&&this._metaKeyTimeout===-1&&(this._metaKeyTimeout=this.timers.setTimeout(this._setMetaKeyTimeout,150));const{originPagePoint:o,currentPagePoint:s}=n;n.isPointing||(n.isDragging=!1);const i=this.store.unsafeGetWithoutCapture(bn),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}=ah(()=>this.getCamera()),{panSpeed:y,zoomSpeed:S}=l;this._setCamera(new x(g+u*y/v-p/v+p/(c*S),m+h*y/v-f/v+f/(c*S),c*S),{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;this._updateInputsFromEvent(e);const{panSpeed:c,zoomSpeed:u,wheelBehavior:h}=l;if(h!=="none"){this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:p,y:f,z:g}=ah(()=>this.getCamera()),{x:m,y:v,z:y=0}=e.delta;let S=h;switch(n.ctrlKey&&(S=h==="pan"?"zoom":"pan"),S){case"zoom":{const{x:b,y:P}=this.inputs.currentScreenPoint;let C=y;h==="zoom"&&(Math.abs(v)>10?C=10*Math.sign(v)/100:C=v/100);const _=g+(C??0)*u*g;this._setCamera(new x(p+(b/_-b)-(b/g-b),f+(P/_-P)-(P/g-P),_),{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(()=>{const h=this.getViewportScreenBounds();this.dispatch({...e,point:this.inputs.originScreenPoint.clone().addXY(h.x,h.y),name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),e.button===sI&&(this.capturedPointerId=e.pointerId),n.buttons.add(e.button),n.isPointing=!0,n.isDragging=!1,!u&&c&&this.updateInstanceState({isPenMode:!0}),e.button===iI?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===fh&&(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}=ah(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:g,previousScreenPoint:m}=this.inputs,{panSpeed:v}=l,y=x.Sub(g,m);this.setCamera(new x(h+y.x*v/f,p+y.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),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 sI:{this.setCursor({type:"grab",rotation:0});break}case fh: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===iI&&(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.code==="MetaRight"&&(e.code="MetaLeft"),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(fh)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===fh?e.name="middle_click":e.button===g1&&(e.name="right_click");const{isPenMode:c}=this.store.unsafeGetWithoutCapture(bn);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.menus.clearOpenMenus(),this}maybeTrackPerformance(e){bt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(e),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}J=mee(Ax);te(J,1,"getIsShapeHiddenCache",HR,Q);te(J,1,"getCanUndo",UR,Q);te(J,1,"getCanRedo",BR,Q);te(J,1,"getPath",zR,Q);te(J,1,"getCurrentTool",NR,Q);te(J,1,"getCurrentToolId",FR,Q);te(J,1,"getDocumentSettings",$R,Q);te(J,1,"getInstanceState",LR,Q);te(J,1,"getOpenMenus",RR,Q);te(J,1,"getIsMenuOpen",DR,Q);te(J,1,"getPageStates",OR,Q);te(J,1,"_getPageStatesQuery",jR,Q);te(J,1,"getCurrentPageState",AR,Q);te(J,1,"_getCurrentPageStateId",MR,Q);te(J,1,"getSelectedShapeIds",TR,Q);te(J,1,"getSelectedShapes",kR,Q);te(J,1,"getOnlySelectedShapeId",ER,Q);te(J,1,"getOnlySelectedShape",IR,Q);te(J,1,"getSelectionPageBounds",_R,Q);te(J,1,"getSelectionRotation",CR,Q);te(J,1,"getSelectionRotatedPageBounds",PR,Q);te(J,1,"getSelectionRotatedScreenBounds",bR,Q);te(J,1,"getFocusedGroupId",wR,Q);te(J,1,"getFocusedGroup",xR,Q);te(J,1,"getEditingShapeId",vR,Q);te(J,1,"getEditingShape",SR,Q);te(J,1,"getHoveredShapeId",yR,Q);te(J,1,"getHoveredShape",mR,Q);te(J,1,"getHintingShapeIds",gR,Q);te(J,1,"getHintingShape",fR,Q);te(J,1,"getErasingShapeIds",pR,Q);te(J,1,"getErasingShapes",hR,Q);te(J,1,"_unsafe_getCameraId",dR,Q);te(J,1,"getCamera",uR,Q);te(J,1,"getViewportPageBoundsForFollowing",cR,Q);te(J,1,"getCameraForFollowing",lR,Q);te(J,1,"getZoomLevel",aR,Q);te(J,1,"getViewportScreenBounds",iR,Q);te(J,1,"getViewportScreenCenter",sR,Q);te(J,1,"getViewportPageBounds",oR,Q);te(J,1,"_getCollaboratorsQuery",rR,Q);te(J,1,"getCollaborators",nR,Q);te(J,1,"getCollaboratorsOnCurrentPage",tR,Q);te(J,1,"getRenderingShapes",eR,Q);te(J,1,"_getAllPagesQuery",JD,Q);te(J,1,"getPages",QD,Q);te(J,1,"getCurrentPageId",ZD,Q);te(J,1,"getCurrentPageShapeIdsSorted",qD,Q);te(J,1,"_getAllAssetsQuery",XD,Q);te(J,1,"_getShapeGeometryCache",YD,Q);te(J,1,"_getShapeHandlesCache",VD,Q);te(J,1,"_getShapePageTransformCache",GD,Q);te(J,1,"_getShapePageBoundsCache",WD,Q);te(J,1,"_getShapeClipPathCache",KD,Q);te(J,1,"_getShapeMaskCache",HD,Q);te(J,1,"_getShapeMaskedPageBoundsCache",UD,Q);te(J,1,"_notVisibleShapes",BD,Q);te(J,1,"getCulledShapes",zD,Q);te(J,1,"getCurrentPageBounds",ND,Q);te(J,1,"getCurrentPageShapes",FD,Q);te(J,1,"getCurrentPageShapesSorted",$D,Q);te(J,1,"getCurrentPageRenderingShapesSorted",LD,Q);te(J,1,"_getBindingsIndexCache",RD,Q);te(J,1,"_getSelectionSharedStyles",DD,Q);te(J,1,"getSharedStyles",OD,Q);te(J,1,"getSharedOpacity",jD,Q);te(J,1,"getIsFocused",AD,Q);te(J,1,"getIsReadonly",MD,Q);te(J,1,"_setShiftKeyTimeout",TD,Q);te(J,1,"_setAltKeyTimeout",kD,Q);te(J,1,"_setCtrlKeyTimeout",ED,Q);te(J,1,"_setMetaKeyTimeout",ID,Q);See(J,Q);function xh(t,e=t.getCurrentPageId()){const n=t.getPage(e).name;t.emit("max-shapes",{name:n,pageId:e,count:t.options.maxShapesPerPage})}function So(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))n[i][l]=c;continue}n[i]=a}}return n||t}function KR(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++)KR(t,o[s],n)}function NI(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=wn.ok(n(s))}catch(a){r=wn.err(a)}});t.store.applyDiff(fx(o))},{history:"ignore"}),r.ok)return r.value;throw r.error}function zI(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 xd(){const t=z(),e=md();return U("isDarkMode",()=>(e==null?void 0:e.isDarkMode)??t.user.getIsDarkMode(),[e,t])}const BI="<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'/>",UI="<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'/>",wh='<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 Fs(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 xee=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],wee={none:()=>"none","ew-resize":(t,e,n)=>Fs(UI,t,0,e,n),"ns-resize":(t,e,n)=>Fs(UI,t,90,e,n),"nesw-resize":(t,e,n)=>Fs(BI,t,0,e,n),"nwse-resize":(t,e,n)=>Fs(BI,t,90,e,n),"nwse-rotate":(t,e,n)=>Fs(wh,t,0,e,n),"nesw-rotate":(t,e,n)=>Fs(wh,t,90,e,n),"senw-rotate":(t,e,n)=>Fs(wh,t,180,e,n),"swne-rotate":(t,e,n)=>Fs(wh,t,270,e,n)};function nr(t,e=0,n="black"){return wee[t](yX(e),!1,n)}function bee(){const t=z(),e=Mt(),n=xd();ci("useCursor",()=>{const{type:r,rotation:o}=t.getInstanceState().cursor;if(xee.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",nr(r,o,n?"white":"black"))},[t,e,n])}function Pee(){const t=z(),e=Mt(),n=xd(),r=U(bt.forceSrgb);Te.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 Cee(){const[t,e]=w.useState(0);w.useEffect(()=>e(n=>n+1),[])}const _ee=t=>t.props.src,Iee={upload:(t,e)=>Zr.blobToDataUrl(e)};function Eee(t){return"schema"in t&&t.schema?t.schema:iX({shapes:"shapeUtils"in t&&t.shapeUtils?HI(Xj(t.shapeUtils)):void 0,bindings:"bindingUtils"in t&&t.bindingUtils?HI(Vj(t.bindingUtils)):void 0,migrations:"migrations"in t?t.migrations:void 0})}function Hu({initialData:t,defaultName:e="",id:n,assets:r=Iee,onMount:o,collaboration:s,...i}={}){const a=Eee(i),l=new e1({id:n,schema:a,initialData:t,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??_ee},onMount:c=>{Le(c instanceof Q),o==null||o(c)},collaboration:s}});if(i.snapshot){if(t)throw new Error("Cannot provide both initialData and snapshot");Wj(l,i.snapshot)}return l}function HI(t){return Object.fromEntries(t.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}function kee(){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 Tee(){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 Mee=350,Aee=1e4,KI=Symbol("UPDATE_INSTANCE_STATE"),jee=t=>t;class Oee{constructor(e){I(this,"onmessage")}postMessage(e){}close(){}}const Dee=typeof BroadcastChannel>"u"?Oee:BroadcastChannel;class Ree{constructor(e,{persistenceKey:n,sessionId:r=$f,onLoad:o,onLoadError:s},i=new Dee(`tldraw-tab-sync-${n}`)){I(this,"disposables",new Set);I(this,"diffQueue",[]);I(this,"didDispose",!1);I(this,"shouldDoFullDBWrite",!0);I(this,"isReloading",!1);I(this,"persistenceKey");I(this,"sessionId");I(this,"serializedSchema");I(this,"isDebugging",!1);I(this,"documentTypes");I(this,"$sessionStateSnapshot");I(this,"db");I(this,"initTime",Date.now());I(this,"isPersisting",!1);I(this,"didLastWriteError",!1);I(this,"scheduledPersistTimeout",null);this.store=e,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=n,this.sessionId=r,this.db=new xf(n),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=w1(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(jee({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(KI),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),Tee();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const o=Object.fromEntries(r.records.map(l=>[l.id,l])),s=r.sessionStateSnapshot??WZ(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}const a=Object.values(i.value).filter(l=>this.documentTypes.has(l.typeName));a.length>0&&this.store.mergeRemoteChanges(()=>{this.store.put(a,"initialize")}),s&&Cx(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"),Oo(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(s.changes)})}))},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?Aee:Mee))}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(Le(!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=Jw(e.filter(r=>r!==KI));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),kee(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function WR(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 Lee(t){const[e,n]=WR({status:"loading"});return t=tc(t),w.useEffect(()=>{const{persistenceKey:r,sessionId:o,...s}=t;if(!r){n({status:"not-synced",store:Hu(s)});return}n({status:"loading"});const i=new Ro,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=Hu({...s,assets:a});let c=!1;const u=new Ree(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 $ee(){const t=z(),e=Mt();w.useEffect(()=>{const n=s=>e.style.setProperty("--tl-zoom",s.toString()),r=vg(n,100),o=new Ql("useZoomCss",()=>{t.getCurrentPageShapeIds().size<300?n(t.getZoomLevel()):r(t.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[t,e])}function jx(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 Fee(t){const e=atob(t),n=jx(e);return crypto.subtle.importKey("spki",new Uint8Array(n),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const Nee=5,Gc={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},zee=Math.max(...Object.values(Gc)),Vc={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},Bee=Object.keys(Vc).length,eS="sales@tldraw.com",Uee=`${ei()}/watermarks/watermark-track.svg`;class Xg{constructor(e,n,r){I(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");I(this,"isDevelopment");I(this,"isTest");I(this,"isCryptoAvailable");I(this,"state",Et("license state","pending"));I(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=Hee(o);!this.isDevelopment&&s&&Lo(Uee),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 Fee(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(jx(atob(r))),new Uint8Array(jx(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>Bee&&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[Vc.ID],hosts:l[Vc.HOSTS],flags:l[Vc.FLAGS],expiryDate:l[Vc.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,Gc.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,Gc.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,Gc.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,Gc.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()+Nee+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 ${eS} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const n=this.getExpirationDateWithGracePeriod(e),r={major:new Date(eI.major),minor:new Date(eI.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 ${eS} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${eS} if you would like to use tldraw on other domains.`]),e.license.flags>=zee*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;")}}I(Xg,"className","tl-watermark_SEE-LICENSE");function Hee(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 GR=w.createContext({}),Kee=()=>w.useContext(GR);function Wee({licenseKey:t,children:e}){const[n]=w.useState(()=>new Xg(t));return d.jsx(GR.Provider,{value:n,children:e})}function Mi(t){if(!t)throw Error("usePassThroughWheelEvents must be passed a ref");const e=Mt();w.useEffect(()=>{function n(o){if(o.isSpecialRedispatchedEvent)return;xe(o);const s=e.querySelector(".tl-canvas");if(!s)return;const i=new WheelEvent("wheel",o);i.isSpecialRedispatchedEvent=!0,s.dispatchEvent(i)}const r=t.current;if(r)return r.addEventListener("wheel",n,{passive:!1}),()=>{r.removeEventListener("wheel",n)}},[e,t])}const Gee='<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>',Vee='<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>';function Yee(t){return U("watermarkState",()=>t.state.get(),[t])}const Xee=`data:image/svg+xml;utf8,${encodeURIComponent(Gee)}`,qee=`data:image/svg+xml;utf8,${encodeURIComponent(Vee)}`,Zee=w.memo(function(){const e=Kee(),n=z(),r=U("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),o=Yee(e);return["licensed-with-watermark","unlicensed"].includes(o)?d.jsxs(d.Fragment,{children:[d.jsx(Jee,{}),d.jsx(Qee,{src:r?qee:Xee})]}):null}),Qee=w.memo(function({src:e}){const n=z(),r=U("debug mode",()=>n.getInstanceState().isDebugMode,[n]),o=U("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),s=m1(),i=w.useRef(null);Mi(i);const a=`url('${e}') center 100% / 100% no-repeat`,l="https://tldraw.dev";return d.jsx("div",{ref:i,className:Xg.className,"data-debug":r,"data-mobile":o,draggable:!1,...s,children:Ge.isWebview?d.jsx("a",{draggable:!1,role:"button",onPointerDown:c=>{_t(c),xe(c)},onClick:()=>$g.openWindow(l,"_blank"),style:{mask:a,WebkitMask:a}}):d.jsx("a",{href:l,target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:c=>{_t(c)},style:{mask:a,WebkitMask:a}})})}),Jee=w.memo(function(){const e=Xg.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: var(--layer-watermark) !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
- .${e}[data-debug='true'] {
152
- bottom: 46px;
153
- }
154
-
155
- .${e}[data-mobile='true'] {
156
- border-radius: 4px 0px 0px 4px;
157
- right: -2px;
158
- width: 8px;
159
- height: 48px;
160
- }
161
-
162
- .${e}[data-mobile='true'] > a {
163
- width: 8px;
164
- height: 32px;
165
- }
166
-
167
- @media (hover: hover) {
168
- .${e} > a {
169
- pointer-events: none;
170
- }
171
-
172
- .${e}:hover {
173
- background-color: var(--color-background);
174
- transition: background-color 0.2s ease-in-out;
175
- transition-delay: 0.32s;
176
- }
177
-
178
- .${e}:hover > a {
179
- animation: delayed_link 0.2s forwards ease-in-out;
180
- animation-delay: 0.32s;
181
- }
182
- }
183
-
184
- @keyframes delayed_link {
185
- 0% {
186
- cursor: inherit;
187
- opacity: .38;
188
- pointer-events: none;
189
- }
190
- 100% {
191
- cursor: pointer;
192
- opacity: 1;
193
- pointer-events: all;
194
- }
195
- }`;return d.jsx("style",{children:n})}),ete=[],tte=[],nte=[],rte="tl-container",ote=w.memo(function({store:e,components:n,className:r,user:o,options:s,...i}){const[a,l]=w.useState(null),c=w.useMemo(()=>o??Bj(),[o]),u=(n==null?void 0:n.ErrorFallback)===void 0?jj:n==null?void 0:n.ErrorFallback,h={...i,shapeUtils:i.shapeUtils??ete,bindingUtils:i.bindingUtils??tte,tools:i.tools??nte,components:n,options:tc(s)};return d.jsx("div",{ref:l,"data-tldraw":oj,draggable:!1,className:le(`${rte} tl-theme__light`,r),onPointerDown:_t,tabIndex:-1,children:d.jsx(Uu,{fallback:u,onError:p=>vw(p,{tags:{origin:"react.tldraw-before-app"}}),children:a&&d.jsx(Wee,{licenseKey:i.licenseKey,children:d.jsx(dj,{container:a,children:d.jsx(MZ,{overrides:n,children:e?e instanceof e1?d.jsx(YR,{...h,store:e,user:c}):d.jsx(VR,{...h,store:e,user:c}):d.jsx(ste,{...h,store:e,user:c})})})})})})});function ste(t){const{defaultName:e,snapshot:n,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:l,assets:c}=t,u=Lee({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:n,assets:c});return d.jsx(VR,{...t,store:u,user:l})}const VR=w.memo(function({store:e,user:n,...r}){const o=Mt();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(YR,{...r,store:e.store,user:n})}),tS=()=>document.location.search.includes("tldraw_preserve_focus");function YR({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=Mt(),[y,S]=WR(null),b=w.useRef(null),P=tc(f===!0?{}:f),C=w.useRef({autoFocus:l&&!tS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P});w.useLayoutEffect(()=>{C.current={autoFocus:l&&!tS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P}},[l,c,a,u,P]),w.useLayoutEffect(()=>{const{autoFocus:k,inferDarkMode:D,initialState:T,cameraOptions:j,deepLinks:$}=C.current,M=new Q({store:n,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>v,user:i,initialState:T,autoFocus:k,inferDarkMode:D,cameraOptions:j,options:h,licenseKey:p,isShapeHidden:g});return M.updateViewportScreenBounds(b.current??v),$&&($!=null&&$.getUrl?M.navigateToDeepLink({...$,url:$.getUrl(M)}):M.navigateToDeepLink($)),S(M),()=>{M.dispose()}},[s,v,h,o,n,r,i,S,p,g]),w.useLayoutEffect(()=>{if(y&&P)return y.registerDeepLinkListener(P)},[y,P]),w.useLayoutEffect(()=>{y&&u&&y.setCameraOptions(u)},[y,u]);const _=w.useSyncExternalStore(w.useCallback(k=>y?(y.on("crash",k),()=>y.off("crash",k)):()=>{},[y]),()=>(y==null?void 0:y.getCrashingError())??null);w.useEffect(function(){if(!y)return;function D(){y&&y.focus()}function T(){y&&y.blur()}if(l&&tS())return y.getContainer().addEventListener("pointerdown",D),document.body.addEventListener("pointerdown",T),()=>{var j;(j=y.getContainer())==null||j.removeEventListener("pointerdown",D),document.body.removeEventListener("pointerdown",T)}},[y,l]);const{Canvas:E}=rt();return y?d.jsx(Uu,{fallback:m,onError:k=>y.annotateError(k,{origin:"react.tldraw",willCrashApp:!0}),children:_?d.jsx(ate,{crashingError:_}):d.jsx(p1,{editor:y,children:d.jsxs(ite,{onMount:t,children:[e??(E?d.jsx(E,{},y.contextId):null),d.jsx(Zee,{})]})})}):d.jsx("div",{className:"tl-canvas",ref:b})}function ite({children:t,onMount:e}){return $ee(),bee(),Pee(),Cee(),qR(n=>{const r=n.store.props.onMount(n),o=e==null?void 0:e(n);return()=>{r==null||r(),o==null||o()}}),t}function ate({crashingError:t}){throw t}function D1({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 qR(t){const e=z(),n=Hg(r=>{let o;return r.run(()=>{o=t==null?void 0:t(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,o});Te.useLayoutEffect(()=>{if(e)return n==null?void 0:n(e)},[e,n])}function di({children:t,className:e="",...n}){return d.jsx("div",{...n,className:le("tl-html-container",e),children:t})}class dp{constructor(e){this.editor=e}}I(dp,"props"),I(dp,"migrations"),I(dp,"type");function qg(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 sc extends oo{getGeometry(e){return new No({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,n){return qg(e,n)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,n,r){return{...n.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}var jS;let lte=(jS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(jS,"id","idle"),jS);var OS;let cte=(OS=class extends ie{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=this.parent.shapeType,o=Ke(),s=this.editor.markHistoryStoppingPoint(`creating_box:${o}`),i=io(n,this.editor);this.editor.createShapes([{id:o,type:r,x:i.x,y:i.y,props:{w:1,h:1}}]).select(o);const a=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:s,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:e}=this.editor.inputs,n=this.parent.shapeType,r=Ke();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:n,x:e.x,y:e.y}]);const o=this.editor.getShape(r);if(!o){this.cancel();return}let{w:s,h:i}=o.props;const a=new x(s/2,i/2),l=this.editor.getShapeParentTransform(o);l&&a.rot(-l.rotation());let c=1;this.editor.user.getIsDynamicResizeMode()&&(c=1/this.editor.getZoomLevel(),s*=c,i*=c,a.mul(c));const u=tt(o),h=io(new x(o.x-a.x,o.y-a.y),this.editor);u.x=h.x,u.y=h.y,u.props.w=s,u.props.h=i,"scale"in o.props&&(u.props.scale=c),this.editor.updateShape(u),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},I(OS,"id","pointing"),OS);function io(t,e){const n=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return n?t.clone().snapToGrid(r):t.clone()}class Ox extends ie{static children(){return[lte,cte]}}I(Ox,"id","box"),I(Ox,"initial","idle");function ute(t,e,n){const r=w.useRef(!1),o=w.useCallback(i=>{r.current=i,i?Vr.addOpenMenu(t):Vr.deleteOpenMenu(t),e==null||e(i)},[t,e]),s=U("is menu open",()=>Vr.getOpenMenus().includes(t),[t]);return w.useEffect(()=>(r.current&&(n==null||n("open-menu"),Vr.addOpenMenu(t)),()=>{r.current&&(Vr.deleteOpenMenu(t),Vr.getOpenMenus().forEach(i=>{i.startsWith(t)&&(n==null||n("close-menu"),Vr.deleteOpenMenu(i))}),r.current=!1)}),[t,n]),[s,o]}function Zg(t){const e=z();return U("isEditing",()=>e.getEditingShapeId()===t,[e,t])}function bo(t){const e=z();return w.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===g1){e.dispatch({type:"pointer",target:"selection",handle:t,name:"right_click",...lr(c)});return}if(c.button!==0)return;const u=Rf(c.currentTarget);function h(){u.removeEventListener("pointerup",h),hd(u,c)}dd(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:t,...lr(c)}),_t(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,...lr(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:t,...lr(c)})}}},[e,t])}function dte(t){const[e,n]=w.useState(()=>({store:Hu(t),opts:t}));if(!NT(e.opts,t)){const r={store:Hu(t),opts:t};return n(r),r.store}return e.store}const hte=20,pte=8;function R1(t,e=hte){return Math.max(pte,Math.ceil(t/e))}class ll extends Ti{constructor(n){super({...n,isFilled:!1,isClosed:!1});I(this,"_center");I(this,"radius");I(this,"start");I(this,"end");I(this,"largeArcFlag");I(this,"sweepFlag");I(this,"measure");I(this,"angleStart");I(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=SX(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=xx(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=gd(n,r,o,s);return c===null?!1:c.some(u=>{const h=xx(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=R1(Math.abs(o));l<c+1;l++){const u=l/c*r,h=i+u;a.push(da(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 L1 extends Ti{constructor(n){super({isClosed:!0,...n});I(this,"_center");I(this,"radius");I(this,"x");I(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=Ne*r,s=[];for(let i=0,a=R1(o);i<a;i++){const l=i/a*Ne;s.push(da(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 gd(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 an extends nc{constructor(n){const{start:r,cp1:o,cp2:s,end:i}=n;super({...n,points:[r,i]});I(this,"a");I(this,"b");I(this,"c");I(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 an.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=an.GetAtT(this,i/n),s+=x.Dist(o,r),o=r;return s}}class fte extends Ti{constructor(n){super({...n,isClosed:!1,isFilled:!1});I(this,"points");I(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 an({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 gte extends Ti{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(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 us({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=R1(a),c=Ne/l,u=Math.cos(c),h=Math.sin(c);let p=0,f=1,g=0,m=1;const v=Array(l);for(let y=0;y<l;y++)v[y]=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 ij(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 mte extends Ti{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(this,"a");I(this,"b");I(this,"c");I(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 ll({start:new x(0,s),end:new x(r,s),center:new x(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new us({start:new x(r,s),end:new x(r,o-s)}),this.c=new ll({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 us({start:new x(0,o-s),end:new x(0,s)})}else{const s=o/2;this.a=new ll({start:new x(s,o),end:new x(s,0),center:new x(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new us({start:new x(s,0),end:new x(r-s,0)}),this.c=new ll({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 us({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 yte({shouldReload:t=!0}={}){c7();for(const e of xf.connectedInstances)await e.close();await Promise.all(Qw().map(e=>dA(e))),l7(),t&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=yte);function Ste(t,e="_blank"){$g.openWindow(t,e)}Ci("@tldraw/editor","3.7.0-canary.383dfd14bf86","esm");function ZR(){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}const QR=()=>{},JR=w.createContext(null);function vte({onEvent:t,children:e}){return d.jsx(JR.Provider,{value:t??QR,children:e})}function Qt(){return w.useContext(JR)??QR}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 xte(t,e){const n=w.createContext(e),r=s=>{const{children:i,...a}=s,l=w.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=t+"Provider";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,o]}function Go(t,e=[]){let n=[];function r(s,i){const a=w.createContext(i),l=n.length;n=[...n,i];const c=h=>{var y;const{scope:p,children:f,...g}=h,m=((y=p==null?void 0:p[t])==null?void 0:y[l])||a,v=w.useMemo(()=>g,Object.values(g));return d.jsx(m.Provider,{value:v,children:f})};c.displayName=s+"Provider";function u(h,p){var m;const f=((m=p==null?void 0:p[t])==null?void 0:m[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,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,wte(o,...e)]}function wte(...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}function WI(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function Qg(...t){return e=>{let n=!1;const r=t.map(o=>{const s=WI(o,e);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():WI(t[o],null)}}}}function Ze(...t){return w.useCallback(Qg(...t),t)}var ha=w.forwardRef((t,e)=>{const{children:n,...r}=t,o=w.Children.toArray(n),s=o.find(Pte);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(Dx,{...r,ref:e,children:w.isValidElement(i)?w.cloneElement(i,void 0,a):null})}return d.jsx(Dx,{...r,ref:e,children:n})});ha.displayName="Slot";var Dx=w.forwardRef((t,e)=>{const{children:n,...r}=t;if(w.isValidElement(n)){const o=_te(n);return w.cloneElement(n,{...Cte(r,n.props),ref:e?Qg(e,o):o})}return w.Children.count(n)>1?w.Children.only(null):null});Dx.displayName="SlotClone";var bte=({children:t})=>d.jsx(d.Fragment,{children:t});function Pte(t){return w.isValidElement(t)&&t.type===bte}function Cte(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 _te(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 Ite=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ae=Ite.reduce((t,e)=>{const n=w.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?ha: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 $1(t,e){t&&wa.flushSync(()=>t.dispatchEvent(e))}function Jg(t){const e=t+"CollectionProvider",[n,r]=Go(e),[o,s]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:g,children:m}=f,v=Te.useRef(null),y=Te.useRef(new Map).current;return d.jsx(o,{scope:g,itemMap:y,collectionRef:v,children:m})};i.displayName=e;const a=t+"CollectionSlot",l=Te.forwardRef((f,g)=>{const{scope:m,children:v}=f,y=s(a,m),S=Ze(g,y.collectionRef);return d.jsx(ha,{ref:S,children:v})});l.displayName=a;const c=t+"CollectionItemSlot",u="data-radix-collection-item",h=Te.forwardRef((f,g)=>{const{scope:m,children:v,...y}=f,S=Te.useRef(null),b=Ze(g,S),P=s(c,m);return Te.useEffect(()=>(P.itemMap.set(S,{ref:S,...y}),()=>void P.itemMap.delete(S))),d.jsx(ha,{[u]:"",ref:b,children:v})});h.displayName=c;function p(f){const g=s(t+"CollectionConsumer",f);return Te.useCallback(()=>{const v=g.collectionRef.current;if(!v)return[];const y=Array.from(v.querySelectorAll(`[${u}]`));return Array.from(g.itemMap.values()).sort((P,C)=>y.indexOf(P.ref.current)-y.indexOf(C.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},p,r]}var Ete=w.createContext(void 0);function F1(t){const e=w.useContext(Ete);return t||e||"ltr"}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 kte(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 Tte="DismissableLayer",Rx="dismissableLayer.update",Mte="dismissableLayer.pointerDownOutside",Ate="dismissableLayer.focusOutside",GI,e3=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),wd=w.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=t,c=w.useContext(e3),[u,h]=w.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=w.useState({}),g=Ze(e,E=>h(E)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=m.indexOf(v),S=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,P=S>=y,C=Ote(E=>{const k=E.target,D=[...c.branches].some(T=>T.contains(k));!P||D||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},p),_=Dte(E=>{const k=E.target;[...c.branches].some(T=>T.contains(k))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},p);return kte(E=>{S===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},p),w.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(GI=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),VI(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=GI)}},[u,p,n,c]),w.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),VI())},[u,c]),w.useEffect(()=>{const E=()=>f({});return document.addEventListener(Rx,E),()=>document.removeEventListener(Rx,E)},[]),d.jsx(Ae.div,{...l,ref:g,style:{pointerEvents:b?P?"auto":"none":void 0,...t.style},onFocusCapture:oe(t.onFocusCapture,_.onFocusCapture),onBlurCapture:oe(t.onBlurCapture,_.onBlurCapture),onPointerDownCapture:oe(t.onPointerDownCapture,C.onPointerDownCapture)})});wd.displayName=Tte;var jte="DismissableLayerBranch",t3=w.forwardRef((t,e)=>{const n=w.useContext(e3),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})});t3.displayName=jte;function Ote(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(){n3(Mte,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 Dte(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&&n3(Ate,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 VI(){const t=new CustomEvent(Rx);document.dispatchEvent(t)}function n3(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?$1(o,s):o.dispatchEvent(s)}var Rte=wd,Lte=t3,nS=0;function N1(){w.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??YI()),document.body.insertAdjacentElement("beforeend",t[1]??YI()),nS++,()=>{nS===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),nS--}},[])}function YI(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var rS="focusScope.autoFocusOnMount",oS="focusScope.autoFocusOnUnmount",XI={bubbles:!1,cancelable:!0},$te="FocusScope",em=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:Bs(h.current,{select:!0})},v=function(b){if(f.paused||!a)return;const P=b.relatedTarget;P!==null&&(a.contains(P)||Bs(h.current,{select:!0}))},y=function(b){if(document.activeElement===document.body)for(const C of b)C.removedNodes.length>0&&Bs(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const S=new MutationObserver(y);return a&&S.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),S.disconnect()}}},[r,a,f.paused]),w.useEffect(()=>{if(a){ZI.add(f);const m=document.activeElement;if(!a.contains(m)){const y=new CustomEvent(rS,XI);a.addEventListener(rS,c),a.dispatchEvent(y),y.defaultPrevented||(Fte(Hte(r3(a)),{select:!0}),document.activeElement===m&&Bs(a))}return()=>{a.removeEventListener(rS,c),setTimeout(()=>{const y=new CustomEvent(oS,XI);a.addEventListener(oS,u),a.dispatchEvent(y),y.defaultPrevented||Bs(m??document.body,{select:!0}),a.removeEventListener(oS,u),ZI.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,y=document.activeElement;if(v&&y){const S=m.currentTarget,[b,P]=Nte(S);b&&P?!m.shiftKey&&y===P?(m.preventDefault(),n&&Bs(b,{select:!0})):m.shiftKey&&y===b&&(m.preventDefault(),n&&Bs(P,{select:!0})):y===S&&m.preventDefault()}},[n,r,f.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:p,onKeyDown:g})});em.displayName=$te;function Fte(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Bs(r,{select:e}),document.activeElement!==n)return}function Nte(t){const e=r3(t),n=qI(e,t),r=qI(e.reverse(),t);return[n,r]}function r3(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 qI(t,e){for(const n of t)if(!zte(n,{upTo:e}))return n}function zte(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 Bs(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&Bte(t)&&e&&t.select()}}var ZI=Ute();function Ute(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=QI(t,e),t.unshift(e)},remove(e){var n;t=QI(t,e),(n=t[0])==null||n.resume()}}}function QI(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function Hte(t){return t.filter(e=>e.tagName!=="A")}var mi=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{},Kte=e6.useId||(()=>{}),Wte=0;function ms(t){const[e,n]=w.useState(Kte());return mi(()=>{t||n(r=>r??String(Wte++))},[t]),t||(e?`radix-${e}`:"")}const Gte=["top","right","bottom","left"],yi=Math.min,sr=Math.max,Ff=Math.round,bh=Math.floor,Do=t=>({x:t,y:t}),Vte={left:"right",right:"left",bottom:"top",top:"bottom"},Yte={start:"end",end:"start"};function Lx(t,e,n){return sr(t,yi(e,n))}function bs(t,e){return typeof t=="function"?t(e):t}function Ps(t){return t.split("-")[0]}function ic(t){return t.split("-")[1]}function z1(t){return t==="x"?"y":"x"}function B1(t){return t==="y"?"height":"width"}function Si(t){return["top","bottom"].includes(Ps(t))?"y":"x"}function U1(t){return z1(Si(t))}function Xte(t,e,n){n===void 0&&(n=!1);const r=ic(t),o=U1(t),s=B1(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=Nf(i)),[i,Nf(i)]}function qte(t){const e=Nf(t);return[$x(t),e,$x(e)]}function $x(t){return t.replace(/start|end/g,e=>Yte[e])}function Zte(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 Qte(t,e,n,r){const o=ic(t);let s=Zte(Ps(t),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),e&&(s=s.concat(s.map($x)))),s}function Nf(t){return t.replace(/left|right|bottom|top/g,e=>Vte[e])}function Jte(t){return{top:0,right:0,bottom:0,left:0,...t}}function o3(t){return typeof t!="number"?Jte(t):{top:t,right:t,bottom:t,left:t}}function zf(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 JI(t,e,n){let{reference:r,floating:o}=t;const s=Si(e),i=U1(e),a=B1(i),l=Ps(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(ic(e)){case"start":f[i]-=p*(n&&c?-1:1);break;case"end":f[i]+=p*(n&&c?-1:1);break}return f}const ene=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}=JI(c,r,l),p=r,f={},g=0;for(let m=0;m<a.length;m++){const{name:v,fn:y}=a[m],{x:S,y:b,data:P,reset:C}=await y({x:u,y:h,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:t,floating:e}});u=S??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}=JI(c,p,l)),m=-1)}return{x:u,y:h,placement:p,strategy:o,middlewareData:f}};async function Ku(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}=bs(e,t),g=o3(f),v=a[p?h==="floating"?"reference":"floating":h],y=zf(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})),S=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=zf(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:S,offsetParent:b,strategy:l}):S);return{top:(y.top-C.top+g.top)/P.y,bottom:(C.bottom-y.bottom+g.bottom)/P.y,left:(y.left-C.left+g.left)/P.x,right:(C.right-y.right+g.right)/P.x}}const tne=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}=bs(t,e)||{};if(c==null)return{};const h=o3(u),p={x:n,y:r},f=U1(o),g=B1(f),m=await i.getDimensions(c),v=f==="y",y=v?"top":"left",S=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],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=_?_[b]:0;(!E||!await(i.isElement==null?void 0:i.isElement(_)))&&(E=a.floating[b]||s.floating[g]);const k=P/2-C/2,D=E/2-m[g]/2-1,T=yi(h[y],D),j=yi(h[S],D),$=T,M=E-m[g]-j,O=E/2-m[g]/2+k,F=Lx($,O,M),B=!l.arrow&&ic(o)!=null&&O!==F&&s.reference[g]/2-(O<$?T:j)-m[g]/2<0,K=B?O<$?O-$:O-M:0;return{[f]:p[f]+K,data:{[f]:F,centerOffset:O-F-K,...B&&{alignmentOffset:K}},reset:B}}}),nne=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}=bs(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=Ps(o),S=Si(a),b=Ps(a)===a,P=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(b||!m?[Nf(a)]:qte(a)),_=g!=="none";!p&&_&&C.push(...Qte(a,m,g,P));const E=[a,...C],k=await Ku(e,v),D=[];let T=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&D.push(k[y]),h){const O=Xte(o,i,P);D.push(k[O[0]],k[O[1]])}if(T=[...T,{placement:o,overflows:D}],!D.every(O=>O<=0)){var j,$;const O=(((j=s.flip)==null?void 0:j.index)||0)+1,F=E[O];if(F)return{data:{index:O,overflows:T},reset:{placement:F}};let B=($=T.filter(K=>K.overflows[0]<=0).sort((K,R)=>K.overflows[1]-R.overflows[1])[0])==null?void 0:$.placement;if(!B)switch(f){case"bestFit":{var M;const K=(M=T.filter(R=>{if(_){const H=Si(R.placement);return H===S||H==="y"}return!0}).map(R=>[R.placement,R.overflows.filter(H=>H>0).reduce((H,Y)=>H+Y,0)]).sort((R,H)=>R[1]-H[1])[0])==null?void 0:M[0];K&&(B=K);break}case"initialPlacement":B=a;break}if(o!==B)return{reset:{placement:B}}}return{}}}};function eE(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function tE(t){return Gte.some(e=>t[e]>=0)}const rne=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...o}=bs(t,e);switch(r){case"referenceHidden":{const s=await Ku(e,{...o,elementContext:"reference"}),i=eE(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:tE(i)}}}case"escaped":{const s=await Ku(e,{...o,altBoundary:!0}),i=eE(s,n.floating);return{data:{escapedOffsets:i,escaped:tE(i)}}}default:return{}}}}};async function one(t,e){const{placement:n,platform:r,elements:o}=t,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Ps(n),a=ic(n),l=Si(n)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,h=bs(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 sne=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 one(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}}}}},ine=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:y,y:S}=v;return{x:y,y:S}}},...l}=bs(t,e),c={x:n,y:r},u=await Ku(e,l),h=Si(Ps(o)),p=z1(h);let f=c[p],g=c[h];if(s){const v=p==="y"?"top":"left",y=p==="y"?"bottom":"right",S=f+u[v],b=f-u[y];f=Lx(S,f,b)}if(i){const v=h==="y"?"top":"left",y=h==="y"?"bottom":"right",S=g+u[v],b=g-u[y];g=Lx(S,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}}}}}},ane=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}=bs(t,e),u={x:n,y:r},h=Si(o),p=z1(h);let f=u[p],g=u[h];const m=bs(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 y,S;const b=p==="y"?"width":"height",P=["top","left"].includes(Ps(o)),C=s.reference[h]-s.floating[b]+(P&&((y=i.offset)==null?void 0:y[h])||0)+(P?0:v.crossAxis),_=s.reference[h]+s.reference[b]+(P?0:((S=i.offset)==null?void 0:S[h])||0)-(P?v.crossAxis:0);g<C?g=C:g>_&&(g=_)}return{[p]:f,[h]:g}}}},lne=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}=bs(t,e),u=await Ku(e,c),h=Ps(o),p=ic(o),f=Si(o)==="y",{width:g,height:m}=s.floating;let v,y;h==="top"||h==="bottom"?(v=h,y=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=h,v=p==="end"?"top":"bottom");const S=m-u.top-u.bottom,b=g-u.left-u.right,P=yi(m-u[v],S),C=yi(g-u[y],b),_=!e.middlewareData.shift;let E=P,k=C;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(k=b),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(E=S),_&&!p){const T=sr(u.left,0),j=sr(u.right,0),$=sr(u.top,0),M=sr(u.bottom,0);f?k=g-2*(T!==0||j!==0?T+j:sr(u.left,u.right)):E=m-2*($!==0||M!==0?$+M:sr(u.top,u.bottom))}await l({...e,availableWidth:k,availableHeight:E});const D=await i.getDimensions(a.floating);return g!==D.width||m!==D.height?{reset:{rects:!0}}:{}}}};function tm(){return typeof window<"u"}function ac(t){return s3(t)?(t.nodeName||"").toLowerCase():"#document"}function pr(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Vo(t){var e;return(e=(s3(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function s3(t){return tm()?t instanceof Node||t instanceof pr(t).Node:!1}function ao(t){return tm()?t instanceof Element||t instanceof pr(t).Element:!1}function zo(t){return tm()?t instanceof HTMLElement||t instanceof pr(t).HTMLElement:!1}function nE(t){return!tm()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof pr(t).ShadowRoot}function bd(t){const{overflow:e,overflowX:n,overflowY:r,display:o}=lo(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!["inline","contents"].includes(o)}function cne(t){return["table","td","th"].includes(ac(t))}function nm(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function H1(t){const e=K1(),n=ao(t)?lo(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 une(t){let e=vi(t);for(;zo(e)&&!Rl(e);){if(H1(e))return e;if(nm(e))return null;e=vi(e)}return null}function K1(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Rl(t){return["html","body","#document"].includes(ac(t))}function lo(t){return pr(t).getComputedStyle(t)}function rm(t){return ao(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function vi(t){if(ac(t)==="html")return t;const e=t.assignedSlot||t.parentNode||nE(t)&&t.host||Vo(t);return nE(e)?e.host:e}function i3(t){const e=vi(t);return Rl(e)?t.ownerDocument?t.ownerDocument.body:t.body:zo(e)&&bd(e)?e:i3(e)}function Wu(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const o=i3(t),s=o===((r=t.ownerDocument)==null?void 0:r.body),i=pr(o);if(s){const a=Fx(i);return e.concat(i,i.visualViewport||[],bd(o)?o:[],a&&n?Wu(a):[])}return e.concat(o,Wu(o,[],n))}function Fx(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function a3(t){const e=lo(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const o=zo(t),s=o?t.offsetWidth:n,i=o?t.offsetHeight:r,a=Ff(n)!==s||Ff(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function W1(t){return ao(t)?t:t.contextElement}function Pl(t){const e=W1(t);if(!zo(e))return Do(1);const n=e.getBoundingClientRect(),{width:r,height:o,$:s}=a3(e);let i=(s?Ff(n.width):n.width)/r,a=(s?Ff(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const dne=Do(0);function l3(t){const e=pr(t);return!K1()||!e.visualViewport?dne:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function hne(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==pr(t)?!1:e}function pa(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=W1(t);let i=Do(1);e&&(r?ao(r)&&(i=Pl(r)):i=Pl(t));const a=hne(s,n,r)?l3(s):Do(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=pr(s),f=r&&ao(r)?pr(r):r;let g=p,m=Fx(g);for(;m&&r&&f!==g;){const v=Pl(m),y=m.getBoundingClientRect(),S=lo(m),b=y.left+(m.clientLeft+parseFloat(S.paddingLeft))*v.x,P=y.top+(m.clientTop+parseFloat(S.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,h*=v.y,l+=b,c+=P,g=pr(m),m=Fx(g)}}return zf({width:u,height:h,x:l,y:c})}function G1(t,e){const n=rm(t).scrollLeft;return e?e.left+n:pa(Vo(t)).left+n}function c3(t,e,n){n===void 0&&(n=!1);const r=t.getBoundingClientRect(),o=r.left+e.scrollLeft-(n?0:G1(t,r)),s=r.top+e.scrollTop;return{x:o,y:s}}function pne(t){let{elements:e,rect:n,offsetParent:r,strategy:o}=t;const s=o==="fixed",i=Vo(r),a=e?nm(e.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=Do(1);const u=Do(0),h=zo(r);if((h||!h&&!s)&&((ac(r)!=="body"||bd(i))&&(l=rm(r)),zo(r))){const f=pa(r);c=Pl(r),u.x=f.x+r.clientLeft,u.y=f.y+r.clientTop}const p=i&&!h&&!s?c3(i,l,!0):Do(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+p.x,y:n.y*c.y-l.scrollTop*c.y+u.y+p.y}}function fne(t){return Array.from(t.getClientRects())}function gne(t){const e=Vo(t),n=rm(t),r=t.ownerDocument.body,o=sr(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),s=sr(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+G1(t);const a=-n.scrollTop;return lo(r).direction==="rtl"&&(i+=sr(e.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function mne(t,e){const n=pr(t),r=Vo(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=K1();(!c||c&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function yne(t,e){const n=pa(t,!0,e==="fixed"),r=n.top+t.clientTop,o=n.left+t.clientLeft,s=zo(t)?Pl(t):Do(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 rE(t,e,n){let r;if(e==="viewport")r=mne(t,n);else if(e==="document")r=gne(Vo(t));else if(ao(e))r=yne(e,n);else{const o=l3(t);r={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return zf(r)}function u3(t,e){const n=vi(t);return n===e||!ao(n)||Rl(n)?!1:lo(n).position==="fixed"||u3(n,e)}function Sne(t,e){const n=e.get(t);if(n)return n;let r=Wu(t,[],!1).filter(a=>ao(a)&&ac(a)!=="body"),o=null;const s=lo(t).position==="fixed";let i=s?vi(t):t;for(;ao(i)&&!Rl(i);){const a=lo(i),l=H1(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||bd(i)&&!l&&u3(t,i))?r=r.filter(u=>u!==i):o=a,i=vi(i)}return e.set(t,r),r}function vne(t){let{element:e,boundary:n,rootBoundary:r,strategy:o}=t;const i=[...n==="clippingAncestors"?nm(e)?[]:Sne(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=rE(e,u,o);return c.top=sr(h.top,c.top),c.right=yi(h.right,c.right),c.bottom=yi(h.bottom,c.bottom),c.left=sr(h.left,c.left),c},rE(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function xne(t){const{width:e,height:n}=a3(t);return{width:e,height:n}}function wne(t,e,n){const r=zo(e),o=Vo(e),s=n==="fixed",i=pa(t,!0,s,e);let a={scrollLeft:0,scrollTop:0};const l=Do(0);if(r||!r&&!s)if((ac(e)!=="body"||bd(o))&&(a=rm(e)),r){const p=pa(e,!0,s,e);l.x=p.x+e.clientLeft,l.y=p.y+e.clientTop}else o&&(l.x=G1(o));const c=o&&!r&&!s?c3(o,a):Do(0),u=i.left+a.scrollLeft-l.x-c.x,h=i.top+a.scrollTop-l.y-c.y;return{x:u,y:h,width:i.width,height:i.height}}function sS(t){return lo(t).position==="static"}function oE(t,e){if(!zo(t)||lo(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Vo(t)===n&&(n=n.ownerDocument.body),n}function d3(t,e){const n=pr(t);if(nm(t))return n;if(!zo(t)){let o=vi(t);for(;o&&!Rl(o);){if(ao(o)&&!sS(o))return o;o=vi(o)}return n}let r=oE(t,e);for(;r&&cne(r)&&sS(r);)r=oE(r,e);return r&&Rl(r)&&sS(r)&&!H1(r)?n:r||une(t)||n}const bne=async function(t){const e=this.getOffsetParent||d3,n=this.getDimensions,r=await n(t.floating);return{reference:wne(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Pne(t){return lo(t).direction==="rtl"}const Cne={convertOffsetParentRelativeRectToViewportRelativeRect:pne,getDocumentElement:Vo,getClippingRect:vne,getOffsetParent:d3,getElementRects:bne,getClientRects:fne,getDimensions:xne,getScale:Pl,isElement:ao,isRTL:Pne};function _ne(t,e){let n=null,r;const o=Vo(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),S={rootMargin:-f+"px "+-g+"px "+-m+"px "+-v+"px",threshold:sr(0,yi(1,l))||1};let b=!0;function P(C){const _=C[0].intersectionRatio;if(_!==l){if(!b)return i();_?i(!1,_):r=setTimeout(()=>{i(!1,1e-7)},1e3)}b=!1}try{n=new IntersectionObserver(P,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(P,S)}n.observe(t)}return i(!0),s}function Ine(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=W1(t),u=o||s?[...c?Wu(c):[],...Wu(e)]:[];u.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const h=c&&a?_ne(c,n):null;let p=-1,f=null;i&&(f=new ResizeObserver(y=>{let[S]=y;S&&S.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?pa(t):null;l&&v();function v(){const y=pa(t);m&&(y.x!==m.x||y.y!==m.y||y.width!==m.width||y.height!==m.height)&&n(),m=y,g=requestAnimationFrame(v)}return n(),()=>{var y;u.forEach(S=>{o&&S.removeEventListener("scroll",n),s&&S.removeEventListener("resize",n)}),h==null||h(),(y=f)==null||y.disconnect(),f=null,l&&cancelAnimationFrame(g)}}const Ene=sne,kne=ine,Tne=nne,Mne=lne,Ane=rne,sE=tne,jne=ane,One=(t,e,n)=>{const r=new Map,o={platform:Cne,...n},s={...o.platform,_c:r};return ene(t,e,{...o,platform:s})};var hp=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Bf(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(!Bf(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)&&!Bf(t[s],e[s]))return!1}return!0}return t!==t&&e!==e}function h3(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function iE(t,e){const n=h3(t);return Math.round(e*n)/n}function iS(t){const e=w.useRef(t);return hp(()=>{e.current=t}),e}function Dne(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);Bf(p,r)||f(r);const[g,m]=w.useState(null),[v,y]=w.useState(null),S=w.useCallback(R=>{R!==_.current&&(_.current=R,m(R))},[]),b=w.useCallback(R=>{R!==E.current&&(E.current=R,y(R))},[]),P=s||g,C=i||v,_=w.useRef(null),E=w.useRef(null),k=w.useRef(u),D=l!=null,T=iS(l),j=iS(o),$=iS(c),M=w.useCallback(()=>{if(!_.current||!E.current)return;const R={placement:e,strategy:n,middleware:p};j.current&&(R.platform=j.current),One(_.current,E.current,R).then(H=>{const Y={...H,isPositioned:$.current!==!1};O.current&&!Bf(k.current,Y)&&(k.current=Y,wa.flushSync(()=>{h(Y)}))})},[p,e,n,j,$]);hp(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,h(R=>({...R,isPositioned:!1})))},[c]);const O=w.useRef(!1);hp(()=>(O.current=!0,()=>{O.current=!1}),[]),hp(()=>{if(P&&(_.current=P),C&&(E.current=C),P&&C){if(T.current)return T.current(P,C,M);M()}},[P,C,M,T,D]);const F=w.useMemo(()=>({reference:_,floating:E,setReference:S,setFloating:b}),[S,b]),B=w.useMemo(()=>({reference:P,floating:C}),[P,C]),K=w.useMemo(()=>{const R={position:n,left:0,top:0};if(!B.floating)return R;const H=iE(B.floating,u.x),Y=iE(B.floating,u.y);return a?{...R,transform:"translate("+H+"px, "+Y+"px)",...h3(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:Y}},[n,a,B.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:M,refs:F,elements:B,floatingStyles:K}),[u,M,F,B,K])}const Rne=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?sE({element:r.current,padding:o}).fn(n):{}:r?sE({element:r,padding:o}).fn(n):{}}}},Lne=(t,e)=>({...Ene(t),options:[t,e]}),$ne=(t,e)=>({...kne(t),options:[t,e]}),Fne=(t,e)=>({...jne(t),options:[t,e]}),Nne=(t,e)=>({...Tne(t),options:[t,e]}),zne=(t,e)=>({...Mne(t),options:[t,e]}),Bne=(t,e)=>({...Ane(t),options:[t,e]}),Une=(t,e)=>({...Rne(t),options:[t,e]});var Hne="Arrow",p3=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"})})});p3.displayName=Hne;var Kne=p3;function f3(t){const[e,n]=w.useState(void 0);return mi(()=>{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 V1="Popper",[g3,om]=Go(V1),[Wne,m3]=g3(V1),y3=t=>{const{__scopePopper:e,children:n}=t,[r,o]=w.useState(null);return d.jsx(Wne,{scope:e,anchor:r,onAnchorChange:o,children:n})};y3.displayName=V1;var S3="PopperAnchor",v3=w.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...o}=t,s=m3(S3,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})});v3.displayName=S3;var Y1="PopperContent",[Gne,Vne]=g3(Y1),x3=w.forwardRef((t,e)=>{var Fe,ot,$e,lt,Ue,er;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=m3(Y1,n),[y,S]=w.useState(null),b=Ze(e,$t=>S($t)),[P,C]=w.useState(null),_=f3(P),E=(_==null?void 0:_.width)??0,k=(_==null?void 0:_.height)??0,D=r+(s!=="center"?"-"+s:""),T=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},j=Array.isArray(c)?c:[c],$=j.length>0,M={padding:T,boundary:j.filter(Xne),altBoundary:$},{refs:O,floatingStyles:F,placement:B,isPositioned:K,middlewareData:R}=Dne({strategy:"fixed",placement:D,whileElementsMounted:(...$t)=>Ine(...$t,{animationFrame:f==="always"}),elements:{reference:v.anchor},middleware:[Lne({mainAxis:o+k,alignmentAxis:i}),l&&$ne({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Fne():void 0,...M}),l&&Nne({...M}),zne({...M,apply:({elements:$t,rects:On,availableWidth:vt,availableHeight:Jt})=>{const{width:Xo,height:cc}=On.reference,js=$t.floating.style;js.setProperty("--radix-popper-available-width",`${vt}px`),js.setProperty("--radix-popper-available-height",`${Jt}px`),js.setProperty("--radix-popper-anchor-width",`${Xo}px`),js.setProperty("--radix-popper-anchor-height",`${cc}px`)}}),P&&Une({element:P,padding:a}),qne({arrowWidth:E,arrowHeight:k}),p&&Bne({strategy:"referenceHidden",...M})]}),[H,Y]=P3(B),ee=Xt(g);mi(()=>{K&&(ee==null||ee())},[K,ee]);const he=(Fe=R.arrow)==null?void 0:Fe.x,ue=(ot=R.arrow)==null?void 0:ot.y,ke=(($e=R.arrow)==null?void 0:$e.centerOffset)!==0,[se,We]=w.useState();return mi(()=>{y&&We(window.getComputedStyle(y).zIndex)},[y]),d.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...F,transform:K?F.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:se,"--radix-popper-transform-origin":[(lt=R.transformOrigin)==null?void 0:lt.x,(Ue=R.transformOrigin)==null?void 0:Ue.y].join(" "),...((er=R.hide)==null?void 0:er.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(Gne,{scope:n,placedSide:H,onArrowChange:C,arrowX:he,arrowY:ue,shouldHideArrow:ke,children:d.jsx(Ae.div,{"data-side":H,"data-align":Y,...m,ref:b,style:{...m.style,animation:K?void 0:"none"}})})})});x3.displayName=Y1;var w3="PopperArrow",Yne={top:"bottom",right:"left",bottom:"top",left:"right"},b3=w.forwardRef(function(e,n){const{__scopePopper:r,...o}=e,s=Vne(w3,r),i=Yne[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(Kne,{...o,ref:n,style:{...o.style,display:"block"}})})});b3.displayName=w3;function Xne(t){return t!==null}var qne=t=>({name:"transformOrigin",options:t,fn(e){var v,y,S;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]=P3(n),h={start:"0%",center:"50%",end:"100%"}[u],p=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,f=(((S=o.arrow)==null?void 0:S.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 P3(t){const[e,n="center"]=t.split("-");return[e,n]}var X1=y3,q1=v3,C3=x3,_3=b3,Zne="Portal",Pd=w.forwardRef((t,e)=>{var a;const{container:n,...r}=t,[o,s]=w.useState(!1);mi(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?u8.createPortal(d.jsx(Ae.div,{...r,ref:e}),i):null});Pd.displayName=Zne;function Qne(t,e){return w.useReducer((n,r)=>e[n][r]??n,t)}var ho=t=>{const{present:e,children:n}=t,r=Jne(e),o=typeof n=="function"?n({present:r.isPresent}):w.Children.only(n),s=Ze(r.ref,ere(o));return typeof n=="function"||r.isPresent?w.cloneElement(o,{ref:s}):null};ho.displayName="Presence";function Jne(t){const[e,n]=w.useState(),r=w.useRef({}),o=w.useRef(t),s=w.useRef("none"),i=t?"mounted":"unmounted",[a,l]=Qne(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=Ph(r.current);s.current=a==="mounted"?c:"none"},[a]),mi(()=>{const c=r.current,u=o.current;if(u!==t){const p=s.current,f=Ph(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]),mi(()=>{if(e){let c;const u=e.ownerDocument.defaultView??window,h=f=>{const m=Ph(r.current).includes(f.animationName);if(f.target===e&&m&&(l("ANIMATION_END"),!o.current)){const v=e.style.animationFillMode;e.style.animationFillMode="forwards",c=u.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=v)})}},p=f=>{f.target===e&&(s.current=Ph(r.current))};return e.addEventListener("animationstart",p),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{u.clearTimeout(c),e.removeEventListener("animationstart",p),e.removeEventListener("animationcancel",h),e.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:w.useCallback(c=>{c&&(r.current=getComputedStyle(c)),n(c)},[])}}function Ph(t){return(t==null?void 0:t.animationName)||"none"}function ere(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)}function Ai({prop:t,defaultProp:e,onChange:n=()=>{}}){const[r,o]=tre({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 tre({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 aS="rovingFocusGroup.onEntryFocus",nre={bubbles:!1,cancelable:!0},sm="RovingFocusGroup",[Nx,I3,rre]=Jg(sm),[ore,E3]=Go(sm,[rre]),[sre,ire]=ore(sm),k3=w.forwardRef((t,e)=>d.jsx(Nx.Provider,{scope:t.__scopeRovingFocusGroup,children:d.jsx(Nx.Slot,{scope:t.__scopeRovingFocusGroup,children:d.jsx(are,{...t,ref:e})})}));k3.displayName=sm;var are=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=F1(s),[m=null,v]=Ai({prop:i,defaultProp:a,onChange:l}),[y,S]=w.useState(!1),b=Xt(c),P=I3(n),C=w.useRef(!1),[_,E]=w.useState(0);return w.useEffect(()=>{const k=p.current;if(k)return k.addEventListener(aS,b),()=>k.removeEventListener(aS,b)},[b]),d.jsx(sre,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:m,onItemFocus:w.useCallback(k=>v(k),[v]),onItemShiftTab:w.useCallback(()=>S(!0),[]),onFocusableItemAdd:w.useCallback(()=>E(k=>k+1),[]),onFocusableItemRemove:w.useCallback(()=>E(k=>k-1),[]),children:d.jsx(Ae.div,{tabIndex:y||_===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,k=>{const D=!C.current;if(k.target===k.currentTarget&&D&&!y){const T=new CustomEvent(aS,nre);if(k.currentTarget.dispatchEvent(T),!T.defaultPrevented){const j=P().filter(B=>B.focusable),$=j.find(B=>B.active),M=j.find(B=>B.id===m),F=[$,M,...j].filter(Boolean).map(B=>B.ref.current);A3(F,u)}}C.current=!1}),onBlur:oe(t.onBlur,()=>S(!1))})})}),T3="RovingFocusGroupItem",M3=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,...i}=t,a=ms(),l=s||a,c=ire(T3,n),u=c.currentTabStopId===l,h=I3(n),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return w.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),d.jsx(Nx.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=ure(g,c.orientation,c.dir);if(m!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let y=h().filter(S=>S.focusable).map(S=>S.ref.current);if(m==="last")y.reverse();else if(m==="prev"||m==="next"){m==="prev"&&y.reverse();const S=y.indexOf(g.currentTarget);y=c.loop?dre(y,S+1):y.slice(S+1)}setTimeout(()=>A3(y))}})})})});M3.displayName=T3;var lre={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function cre(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function ure(t,e,n){const r=cre(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return lre[r]}function A3(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function dre(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var hre=k3,pre=M3,fre=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},$a=new WeakMap,Ch=new WeakMap,_h={},lS=0,j3=function(t){return t&&(t.host||j3(t.parentNode))},gre=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=j3(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})},mre=function(t,e,n,r){var o=gre(e,Array.isArray(t)?t:[t]);_h[n]||(_h[n]=new WeakMap);var s=_h[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=($a.get(p)||0)+1,v=(s.get(p)||0)+1;$a.set(p,m),s.set(p,v),i.push(p),m===1&&g&&Ch.set(p,!0),v===1&&p.setAttribute(n,"true"),g||p.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",p,y)}})};return u(e),a.clear(),lS++,function(){i.forEach(function(h){var p=$a.get(h)-1,f=s.get(h)-1;$a.set(h,p),s.set(h,f),p||(Ch.has(h)||h.removeAttribute(r),Ch.delete(h)),f||h.removeAttribute(n)}),lS--,lS||($a=new WeakMap,$a=new WeakMap,Ch=new WeakMap,_h={})}},Z1=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),o=fre(t);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),mre(r,o,n,"aria-hidden")):function(){return null}},_o=function(){return _o=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},_o.apply(this,arguments)};function O3(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 yre(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 pp="right-scroll-bar-position",fp="width-before-scroll-bar",Sre="with-scroll-bars-hidden",vre="--removed-body-scroll-bar-size";function cS(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function xre(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 wre=typeof window<"u"?w.useLayoutEffect:w.useEffect,aE=new WeakMap;function bre(t,e){var n=xre(null,function(r){return t.forEach(function(o){return cS(o,r)})});return wre(function(){var r=aE.get(n);if(r){var o=new Set(r),s=new Set(t),i=n.current;o.forEach(function(a){s.has(a)||cS(a,null)}),s.forEach(function(a){o.has(a)||cS(a,i)})}aE.set(n,t)},[t]),n}function Pre(t){return t}function Cre(t,e){e===void 0&&(e=Pre);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 _re(t){t===void 0&&(t={});var e=Cre(null);return e.options=_o({async:!0,ssr:!1},t),e}var D3=function(t){var e=t.sideCar,n=O3(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,_o({},n))};D3.isSideCarExport=!0;function Ire(t,e){return t.useMedium(e),D3}var R3=_re(),uS=function(){},im=w.forwardRef(function(t,e){var n=w.useRef(null),r=w.useState({onScrollCapture:uS,onWheelCapture:uS,onTouchMoveCapture:uS}),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,y=v===void 0?"div":v,S=t.gapMode,b=O3(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),P=p,C=bre([n,e]),_=_o(_o({},b),o);return w.createElement(w.Fragment,null,u&&w.createElement(P,{sideCar:R3,removeScrollBar:c,shards:h,noIsolation:f,inert:g,setCallbacks:s,allowPinchZoom:!!m,lockRef:n,gapMode:S}),i?w.cloneElement(w.Children.only(a),_o(_o({},_),{ref:C})):w.createElement(y,_o({},_,{className:l,ref:C}),a))});im.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};im.classNames={fullWidth:fp,zeroRight:pp};var Ere=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function kre(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=Ere();return e&&t.setAttribute("nonce",e),t}function Tre(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function Mre(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Are=function(){var t=0,e=null;return{add:function(n){t==0&&(e=kre())&&(Tre(e,n),Mre(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},jre=function(){var t=Are();return function(e,n){w.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},L3=function(){var t=jre(),e=function(n){var r=n.styles,o=n.dynamic;return t(r,o),null};return e},Ore={left:0,top:0,right:0,gap:0},dS=function(t){return parseInt(t||"",10)||0},Dre=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[dS(n),dS(r),dS(o)]},Rre=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return Ore;var e=Dre(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])}},Lre=L3(),Cl="data-scroll-locked",$re=function(t,e,n,r){var o=t.left,s=t.top,i=t.right,a=t.gap;return n===void 0&&(n="margin"),`
196
- .`.concat(Sre,` {
197
- overflow: hidden `).concat(r,`;
198
- padding-right: `).concat(a,"px ").concat(r,`;
199
- }
200
- body[`).concat(Cl,`] {
201
- overflow: hidden `).concat(r,`;
202
- overscroll-behavior: contain;
203
- `).concat([e&&"position: relative ".concat(r,";"),n==="margin"&&`
204
- padding-left: `.concat(o,`px;
205
- padding-top: `).concat(s,`px;
206
- padding-right: `).concat(i,`px;
207
- margin-left:0;
208
- margin-top:0;
209
- margin-right: `).concat(a,"px ").concat(r,`;
210
- `),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
211
- }
212
-
213
- .`).concat(pp,` {
214
- right: `).concat(a,"px ").concat(r,`;
215
- }
216
-
217
- .`).concat(fp,` {
218
- margin-right: `).concat(a,"px ").concat(r,`;
219
- }
220
-
221
- .`).concat(pp," .").concat(pp,` {
222
- right: 0 `).concat(r,`;
223
- }
224
-
225
- .`).concat(fp," .").concat(fp,` {
226
- margin-right: 0 `).concat(r,`;
227
- }
228
-
229
- body[`).concat(Cl,`] {
230
- `).concat(vre,": ").concat(a,`px;
231
- }
232
- `)},lE=function(){var t=parseInt(document.body.getAttribute(Cl)||"0",10);return isFinite(t)?t:0},Fre=function(){w.useEffect(function(){return document.body.setAttribute(Cl,(lE()+1).toString()),function(){var t=lE()-1;t<=0?document.body.removeAttribute(Cl):document.body.setAttribute(Cl,t.toString())}},[])},Nre=function(t){var e=t.noRelative,n=t.noImportant,r=t.gapMode,o=r===void 0?"margin":r;Fre();var s=w.useMemo(function(){return Rre(o)},[o]);return w.createElement(Lre,{styles:$re(s,!e,o,n?"":"!important")})},zx=!1;if(typeof window<"u")try{var Ih=Object.defineProperty({},"passive",{get:function(){return zx=!0,!0}});window.addEventListener("test",Ih,Ih),window.removeEventListener("test",Ih,Ih)}catch{zx=!1}var Fa=zx?{passive:!1}:!1,zre=function(t){return t.tagName==="TEXTAREA"},$3=function(t,e){if(!(t instanceof Element))return!1;var n=window.getComputedStyle(t);return n[e]!=="hidden"&&!(n.overflowY===n.overflowX&&!zre(t)&&n[e]==="visible")},Bre=function(t){return $3(t,"overflowY")},Ure=function(t){return $3(t,"overflowX")},cE=function(t,e){var n=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=F3(t,r);if(o){var s=N3(t,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Hre=function(t){var e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;return[e,n,r]},Kre=function(t){var e=t.scrollLeft,n=t.scrollWidth,r=t.clientWidth;return[e,n,r]},F3=function(t,e){return t==="v"?Bre(e):Ure(e)},N3=function(t,e){return t==="v"?Hre(e):Kre(e)},Wre=function(t,e){return t==="h"&&e==="rtl"?-1:1},Gre=function(t,e,n,r,o){var s=Wre(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=N3(t,a),g=f[0],m=f[1],v=f[2],y=m-v-s*g;(g||y)&&F3(t,a)&&(h+=y,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},Eh=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},uE=function(t){return[t.deltaX,t.deltaY]},dE=function(t){return t&&"current"in t?t.current:t},Vre=function(t,e){return t[0]===e[0]&&t[1]===e[1]},Yre=function(t){return`
233
- .block-interactivity-`.concat(t,` {pointer-events: none;}
234
- .allow-interactivity-`).concat(t,` {pointer-events: all;}
235
- `)},Xre=0,Na=[];function qre(t){var e=w.useRef([]),n=w.useRef([0,0]),r=w.useRef(),o=w.useState(Xre++)[0],s=w.useState(L3)[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=yre([t.lockRef.current],(t.shards||[]).map(dE),!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||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var y=Eh(m),S=n.current,b="deltaX"in m?m.deltaX:S[0]-y[0],P="deltaY"in m?m.deltaY:S[1]-y[1],C,_=m.target,E=Math.abs(b)>Math.abs(P)?"h":"v";if("touches"in m&&E==="h"&&_.type==="range")return!1;var k=cE(E,_);if(!k)return!0;if(k?C=E:(C=E==="v"?"h":"v",k=cE(E,_)),!k)return!1;if(!r.current&&"changedTouches"in m&&(b||P)&&(r.current=C),!C)return!0;var D=r.current||C;return Gre(D,v,m,D==="h"?b:P,!0)},[]),l=w.useCallback(function(m){var v=m;if(!(!Na.length||Na[Na.length-1]!==s)){var y="deltaY"in v?uE(v):Eh(v),S=e.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&Vre(C.delta,y)})[0];if(S&&S.should){v.cancelable&&v.preventDefault();return}if(!S){var b=(i.current.shards||[]).map(dE).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,y,S){var b={name:m,delta:v,target:y,should:S,shadowParent:Zre(y)};e.current.push(b),setTimeout(function(){e.current=e.current.filter(function(P){return P!==b})},1)},[]),u=w.useCallback(function(m){n.current=Eh(m),r.current=void 0},[]),h=w.useCallback(function(m){c(m.type,uE(m),m.target,a(m,t.lockRef.current))},[]),p=w.useCallback(function(m){c(m.type,Eh(m),m.target,a(m,t.lockRef.current))},[]);w.useEffect(function(){return Na.push(s),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,Fa),document.addEventListener("touchmove",l,Fa),document.addEventListener("touchstart",u,Fa),function(){Na=Na.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,Fa),document.removeEventListener("touchmove",l,Fa),document.removeEventListener("touchstart",u,Fa)}},[]);var f=t.removeScrollBar,g=t.inert;return w.createElement(w.Fragment,null,g?w.createElement(s,{styles:Yre(o)}):null,f?w.createElement(Nre,{gapMode:t.gapMode}):null)}function Zre(t){for(var e=null;t!==null;)t instanceof ShadowRoot&&(e=t.host,t=t.host),t=t.parentNode;return e}const Qre=Ire(R3,qre);var am=w.forwardRef(function(t,e){return w.createElement(im,_o({},t,{ref:e,sideCar:Qre}))});am.classNames=im.classNames;var Bx=["Enter"," "],Jre=["ArrowDown","PageUp","Home"],z3=["ArrowUp","PageDown","End"],eoe=[...Jre,...z3],toe={ltr:[...Bx,"ArrowRight"],rtl:[...Bx,"ArrowLeft"]},noe={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Cd="Menu",[Gu,roe,ooe]=Jg(Cd),[Ia,lm]=Go(Cd,[ooe,om,E3]),_d=om(),B3=E3(),[U3,ji]=Ia(Cd),[soe,Id]=Ia(Cd),H3=t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=t,a=_d(e),[l,c]=w.useState(null),u=w.useRef(!1),h=Xt(s),p=F1(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(X1,{...a,children:d.jsx(U3,{scope:e,open:n,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(soe,{scope:e,onClose:w.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};H3.displayName=Cd;var ioe="MenuAnchor",Q1=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=_d(n);return d.jsx(q1,{...o,...r,ref:e})});Q1.displayName=ioe;var J1="MenuPortal",[aoe,K3]=Ia(J1,{forceMount:void 0}),W3=t=>{const{__scopeMenu:e,forceMount:n,children:r,container:o}=t,s=ji(J1,e);return d.jsx(aoe,{scope:e,forceMount:n,children:d.jsx(ho,{present:n||s.open,children:d.jsx(Pd,{asChild:!0,container:o,children:r})})})};W3.displayName=J1;var Dr="MenuContent",[loe,eb]=Ia(Dr),G3=w.forwardRef((t,e)=>{const n=K3(Dr,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=ji(Dr,t.__scopeMenu),i=Id(Dr,t.__scopeMenu);return d.jsx(Gu.Provider,{scope:t.__scopeMenu,children:d.jsx(ho,{present:r||s.open,children:d.jsx(Gu.Slot,{scope:t.__scopeMenu,children:i.modal?d.jsx(coe,{...o,ref:e}):d.jsx(uoe,{...o,ref:e})})})})}),coe=w.forwardRef((t,e)=>{const n=ji(Dr,t.__scopeMenu),r=w.useRef(null),o=Ze(e,r);return w.useEffect(()=>{const s=r.current;if(s)return Z1(s)},[]),d.jsx(tb,{...t,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:oe(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),uoe=w.forwardRef((t,e)=>{const n=ji(Dr,t.__scopeMenu);return d.jsx(tb,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),tb=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=ji(Dr,n),y=Id(Dr,n),S=_d(n),b=B3(n),P=roe(n),[C,_]=w.useState(null),E=w.useRef(null),k=Ze(e,E,v.onContentChange),D=w.useRef(0),T=w.useRef(""),j=w.useRef(0),$=w.useRef(null),M=w.useRef("right"),O=w.useRef(0),F=g?am:w.Fragment,B=g?{as:ha,allowPinchZoom:!0}:void 0,K=H=>{var Fe,ot;const Y=T.current+H,ee=P().filter($e=>!$e.disabled),he=document.activeElement,ue=(Fe=ee.find($e=>$e.ref.current===he))==null?void 0:Fe.textValue,ke=ee.map($e=>$e.textValue),se=boe(ke,Y,ue),We=(ot=ee.find($e=>$e.textValue===se))==null?void 0:ot.ref.current;(function $e(lt){T.current=lt,window.clearTimeout(D.current),lt!==""&&(D.current=window.setTimeout(()=>$e(""),1e3))})(Y),We&&setTimeout(()=>We.focus())};w.useEffect(()=>()=>window.clearTimeout(D.current),[]),N1();const R=w.useCallback(H=>{var ee,he;return M.current===((ee=$.current)==null?void 0:ee.side)&&Coe(H,(he=$.current)==null?void 0:he.area)},[]);return d.jsx(loe,{scope:n,searchRef:T,onItemEnter:w.useCallback(H=>{R(H)&&H.preventDefault()},[R]),onItemLeave:w.useCallback(H=>{var Y;R(H)||((Y=E.current)==null||Y.focus(),_(null))},[R]),onTriggerLeave:w.useCallback(H=>{R(H)&&H.preventDefault()},[R]),pointerGraceTimerRef:j,onPointerGraceIntentChange:w.useCallback(H=>{$.current=H},[]),children:d.jsx(F,{...B,children:d.jsx(em,{asChild:!0,trapped:o,onMountAutoFocus:oe(s,H=>{var Y;H.preventDefault(),(Y=E.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(wd,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:d.jsx(hre,{asChild:!0,...b,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:_,onEntryFocus:oe(l,H=>{y.isUsingKeyboardRef.current||H.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(C3,{role:"menu","aria-orientation":"vertical","data-state":cL(v.open),"data-radix-menu-content":"",dir:y.dir,...S,...m,ref:k,style:{outline:"none",...m.style},onKeyDown:oe(m.onKeyDown,H=>{const ee=H.target.closest("[data-radix-menu-content]")===H.currentTarget,he=H.ctrlKey||H.altKey||H.metaKey,ue=H.key.length===1;ee&&(H.key==="Tab"&&H.preventDefault(),!he&&ue&&K(H.key));const ke=E.current;if(H.target!==ke||!eoe.includes(H.key))return;H.preventDefault();const We=P().filter(Fe=>!Fe.disabled).map(Fe=>Fe.ref.current);z3.includes(H.key)&&We.reverse(),xoe(We)}),onBlur:oe(t.onBlur,H=>{H.currentTarget.contains(H.target)||(window.clearTimeout(D.current),T.current="")}),onPointerMove:oe(t.onPointerMove,Vu(H=>{const Y=H.target,ee=O.current!==H.clientX;if(H.currentTarget.contains(Y)&&ee){const he=H.clientX>O.current?"right":"left";M.current=he,O.current=H.clientX}}))})})})})})})});G3.displayName=Dr;var doe="MenuGroup",nb=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"group",...r,ref:e})});nb.displayName=doe;var hoe="MenuLabel",V3=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});V3.displayName=hoe;var Uf="MenuItem",hE="menu.itemSelect",cm=w.forwardRef((t,e)=>{const{disabled:n=!1,onSelect:r,...o}=t,s=w.useRef(null),i=Id(Uf,t.__scopeMenu),a=eb(Uf,t.__scopeMenu),l=Ze(e,s),c=w.useRef(!1),u=()=>{const h=s.current;if(!n&&h){const p=new CustomEvent(hE,{bubbles:!0,cancelable:!0});h.addEventListener(hE,f=>r==null?void 0:r(f),{once:!0}),$1(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(Y3,{...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===" "||Bx.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});cm.displayName=Uf;var Y3=w.forwardRef((t,e)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=t,i=eb(Uf,n),a=B3(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(Gu.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:d.jsx(pre,{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,Vu(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:oe(t.onPointerLeave,Vu(g=>i.onItemLeave(g))),onFocus:oe(t.onFocus,()=>h(!0)),onBlur:oe(t.onBlur,()=>h(!1))})})})}),poe="MenuCheckboxItem",X3=w.forwardRef((t,e)=>{const{checked:n=!1,onCheckedChange:r,...o}=t;return d.jsx(eL,{scope:t.__scopeMenu,checked:n,children:d.jsx(cm,{role:"menuitemcheckbox","aria-checked":Hf(n)?"mixed":n,...o,ref:e,"data-state":sb(n),onSelect:oe(o.onSelect,()=>r==null?void 0:r(Hf(n)?!0:!n),{checkForDefaultPrevented:!1})})})});X3.displayName=poe;var q3="MenuRadioGroup",[foe,goe]=Ia(q3,{value:void 0,onValueChange:()=>{}}),Z3=w.forwardRef((t,e)=>{const{value:n,onValueChange:r,...o}=t,s=Xt(r);return d.jsx(foe,{scope:t.__scopeMenu,value:n,onValueChange:s,children:d.jsx(nb,{...o,ref:e})})});Z3.displayName=q3;var Q3="MenuRadioItem",J3=w.forwardRef((t,e)=>{const{value:n,...r}=t,o=goe(Q3,t.__scopeMenu),s=n===o.value;return d.jsx(eL,{scope:t.__scopeMenu,checked:s,children:d.jsx(cm,{role:"menuitemradio","aria-checked":s,...r,ref:e,"data-state":sb(s),onSelect:oe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});J3.displayName=Q3;var rb="MenuItemIndicator",[eL,moe]=Ia(rb,{checked:!1}),tL=w.forwardRef((t,e)=>{const{__scopeMenu:n,forceMount:r,...o}=t,s=moe(rb,n);return d.jsx(ho,{present:r||Hf(s.checked)||s.checked===!0,children:d.jsx(Ae.span,{...o,ref:e,"data-state":sb(s.checked)})})});tL.displayName=rb;var yoe="MenuSeparator",nL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});nL.displayName=yoe;var Soe="MenuArrow",rL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=_d(n);return d.jsx(_3,{...o,...r,ref:e})});rL.displayName=Soe;var ob="MenuSub",[voe,oL]=Ia(ob),sL=t=>{const{__scopeMenu:e,children:n,open:r=!1,onOpenChange:o}=t,s=ji(ob,e),i=_d(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(X1,{...i,children:d.jsx(U3,{scope:e,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(voe,{scope:e,contentId:ms(),triggerId:ms(),trigger:a,onTriggerChange:l,children:n})})})};sL.displayName=ob;var Yc="MenuSubTrigger",iL=w.forwardRef((t,e)=>{const n=ji(Yc,t.__scopeMenu),r=Id(Yc,t.__scopeMenu),o=oL(Yc,t.__scopeMenu),s=eb(Yc,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(Q1,{asChild:!0,...c,children:d.jsx(Y3,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":cL(n.open),...t,ref:Qg(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,Vu(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,Vu(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",y=v?-5:5,S=p[v?"left":"right"],b=p[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+y,y:h.clientY},{x:S,y:p.top},{x:b,y:p.top},{x:b,y:p.bottom},{x:S,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===" "||toe[r.dir].includes(h.key)&&(n.onOpenChange(!0),(f=n.content)==null||f.focus(),h.preventDefault())})})})});iL.displayName=Yc;var aL="MenuSubContent",lL=w.forwardRef((t,e)=>{const n=K3(Dr,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=ji(Dr,t.__scopeMenu),i=Id(Dr,t.__scopeMenu),a=oL(aL,t.__scopeMenu),l=w.useRef(null),c=Ze(e,l);return d.jsx(Gu.Provider,{scope:t.__scopeMenu,children:d.jsx(ho,{present:r||s.open,children:d.jsx(Gu.Slot,{scope:t.__scopeMenu,children:d.jsx(tb,{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=noe[i.dir].includes(u.key);h&&p&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),u.preventDefault())})})})})})});lL.displayName=aL;function cL(t){return t?"open":"closed"}function Hf(t){return t==="indeterminate"}function sb(t){return Hf(t)?"indeterminate":t?"checked":"unchecked"}function xoe(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}function woe(t,e){return t.map((n,r)=>t[(e+r)%t.length])}function boe(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=woe(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 Poe(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 Coe(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return Poe(n,e)}function Vu(t){return e=>e.pointerType==="mouse"?t(e):void 0}var uL=H3,dL=Q1,hL=W3,pL=G3,fL=nb,gL=V3,mL=cm,yL=X3,SL=Z3,vL=J3,xL=tL,wL=nL,bL=rL,PL=sL,CL=iL,_L=lL,ib="ContextMenu",[_oe,uge]=Go(ib,[lm]),yn=lm(),[Ioe,IL]=_oe(ib),EL=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,dir:o,modal:s=!0}=t,[i,a]=w.useState(!1),l=yn(e),c=Xt(r),u=w.useCallback(h=>{a(h),c(h)},[c]);return d.jsx(Ioe,{scope:e,open:i,onOpenChange:u,modal:s,children:d.jsx(uL,{...l,dir:o,open:i,onOpenChange:u,modal:s,children:n})})};EL.displayName=ib;var kL="ContextMenuTrigger",TL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,disabled:r=!1,...o}=t,s=IL(kL,n),i=yn(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(dL,{...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,kh(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?t.onPointerMove:oe(t.onPointerMove,kh(u)),onPointerCancel:r?t.onPointerCancel:oe(t.onPointerCancel,kh(u)),onPointerUp:r?t.onPointerUp:oe(t.onPointerUp,kh(u))})]})});TL.displayName=kL;var Eoe="ContextMenuPortal",ab=t=>{const{__scopeContextMenu:e,...n}=t,r=yn(e);return d.jsx(hL,{...r,...n})};ab.displayName=Eoe;var ML="ContextMenuContent",AL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=IL(ML,n),s=yn(n),i=w.useRef(!1);return d.jsx(pL,{...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)"}})});AL.displayName=ML;var koe="ContextMenuGroup",jL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(fL,{...o,...r,ref:e})});jL.displayName=koe;var Toe="ContextMenuLabel",Moe=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(gL,{...o,...r,ref:e})});Moe.displayName=Toe;var Aoe="ContextMenuItem",OL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(mL,{...o,...r,ref:e})});OL.displayName=Aoe;var joe="ContextMenuCheckboxItem",DL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(yL,{...o,...r,ref:e})});DL.displayName=joe;var Ooe="ContextMenuRadioGroup",Doe=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(SL,{...o,...r,ref:e})});Doe.displayName=Ooe;var Roe="ContextMenuRadioItem",Loe=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(vL,{...o,...r,ref:e})});Loe.displayName=Roe;var $oe="ContextMenuItemIndicator",Foe=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(xL,{...o,...r,ref:e})});Foe.displayName=$oe;var Noe="ContextMenuSeparator",zoe=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(wL,{...o,...r,ref:e})});zoe.displayName=Noe;var Boe="ContextMenuArrow",Uoe=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(bL,{...o,...r,ref:e})});Uoe.displayName=Boe;var Hoe="ContextMenuSub",RL=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,open:o,defaultOpen:s}=t,i=yn(e),[a,l]=Ai({prop:o,defaultProp:s,onChange:r});return d.jsx(PL,{...i,open:a,onOpenChange:l,children:n})};RL.displayName=Hoe;var Koe="ContextMenuSubTrigger",LL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(CL,{...o,...r,ref:e})});LL.displayName=Koe;var Woe="ContextMenuSubContent",$L=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=yn(n);return d.jsx(_L,{...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)"}})});$L.displayName=Woe;function kh(t){return e=>e.pointerType!=="mouse"?t(e):void 0}var Goe=EL,Voe=TL,Yoe=ab,Xoe=AL,qoe=DL,lb="DropdownMenu",[Zoe,dge]=Go(lb,[lm]),Sn=lm(),[Qoe,FL]=Zoe(lb),NL=t=>{const{__scopeDropdownMenu:e,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=t,l=Sn(e),c=w.useRef(null),[u=!1,h]=Ai({prop:o,defaultProp:s,onChange:i});return d.jsx(Qoe,{scope:e,triggerId:ms(),triggerRef:c,contentId:ms(),open:u,onOpenChange:h,onOpenToggle:w.useCallback(()=>h(p=>!p),[h]),modal:a,children:d.jsx(uL,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:n})})};NL.displayName=lb;var zL="DropdownMenuTrigger",BL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=t,s=FL(zL,n),i=Sn(n);return d.jsx(dL,{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:Qg(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())})})})});BL.displayName=zL;var Joe="DropdownMenuPortal",UL=t=>{const{__scopeDropdownMenu:e,...n}=t,r=Sn(e);return d.jsx(hL,{...r,...n})};UL.displayName=Joe;var HL="DropdownMenuContent",KL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=FL(HL,n),s=Sn(n),i=w.useRef(!1);return d.jsx(pL,{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)"}})});KL.displayName=HL;var ese="DropdownMenuGroup",WL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(fL,{...o,...r,ref:e})});WL.displayName=ese;var tse="DropdownMenuLabel",nse=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(gL,{...o,...r,ref:e})});nse.displayName=tse;var rse="DropdownMenuItem",GL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(mL,{...o,...r,ref:e})});GL.displayName=rse;var ose="DropdownMenuCheckboxItem",VL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(yL,{...o,...r,ref:e})});VL.displayName=ose;var sse="DropdownMenuRadioGroup",ise=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(SL,{...o,...r,ref:e})});ise.displayName=sse;var ase="DropdownMenuRadioItem",lse=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(vL,{...o,...r,ref:e})});lse.displayName=ase;var cse="DropdownMenuItemIndicator",use=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(xL,{...o,...r,ref:e})});use.displayName=cse;var dse="DropdownMenuSeparator",hse=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(wL,{...o,...r,ref:e})});hse.displayName=dse;var pse="DropdownMenuArrow",fse=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(bL,{...o,...r,ref:e})});fse.displayName=pse;var gse=t=>{const{__scopeDropdownMenu:e,children:n,open:r,onOpenChange:o,defaultOpen:s}=t,i=Sn(e),[a=!1,l]=Ai({prop:r,defaultProp:s,onChange:o});return d.jsx(PL,{...i,open:a,onOpenChange:l,children:n})},mse="DropdownMenuSubTrigger",YL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(CL,{...o,...r,ref:e})});YL.displayName=mse;var yse="DropdownMenuSubContent",XL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=Sn(n);return d.jsx(_L,{...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)"}})});XL.displayName=yse;var cb=NL,ub=BL,um=UL,db=KL,Sse=WL,vse=GL,xse=VL,wse=gse,bse=YL,Pse=XL;function Ye(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=qL(t,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=t.getShapeUtil(s),l=me(i.map(c=>t.getShape(c)));(o=a.onDragShapesOut)==null||o.call(a,s,l)}}function qL(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=>hr(f,u))){if(p){if(_1(u,h))continue}else if(qZ(u,h))continue;a.push(l)}}return a}function Kf(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})}function Cse(t,e){const n=me(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 _se=50;function Ise(t,e,n={}){const r=t.getShape(e);if(!r)return;const o=t.getSortedChildIdsForParent(r.id),s=me(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=_se}=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 ZL=w.createContext(null);function Ese({assetUrls:t,children:e}){return w.useEffect(()=>{for(const n of Object.values(t.icons)){const r=Lu();r.src=n,r.decode()}for(const n of Object.values(t.embedIcons)){const r=Lu();r.src=n,r.decode()}},[t]),d.jsx(ZL.Provider,{value:t,children:e})}function hb(){const t=w.useContext(ZL);if(!t)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return t}const Ux={"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.import-tldr-file":"Import file...","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.label-align":"Label align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.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..."},kse=new Set(["ar","fa","he","ur","ku"]),za={locale:"en",label:"English",messages:Ux,dir:"ltr"};async function Tse(t,e){if(!(await Lo(e.translations.en)).ok)return console.warn("No main translations found."),za;if(t==="en")return za;const r=Bu.find(i=>i.locale===t);if(!r)return console.warn(`No translation found for locale ${t}`),za;const s=await(await Lo(e.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${t}`),za;for(const i in za.messages)s[i];return{locale:t,label:r.label,dir:kse.has(r.locale)?"rtl":"ltr",messages:{...za.messages,...s}}}const QL=w.createContext(null);function JL(){const t=w.useContext(QL);if(!t)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return t}function Mse({overrides:t,locale:e,children:n}){const r=hb(),[o,s]=w.useState(()=>t&&t.en?{locale:"en",label:"English",dir:"ltr",messages:{...Ux,...t.en}}:{locale:"en",label:"English",dir:"ltr",messages:Ux});return w.useEffect(()=>{let i=!1;async function a(){const l=await Tse(e,r);l&&!i&&(t&&t[e]?s({...l,messages:{...l.messages,...t[e]}}):s(l))}return a(),()=>{i=!0}},[r,e,t]),d.jsx(QL.Provider,{value:o,children:n})}function Ee(){const t=JL();return w.useCallback(function(n){return t.messages[n]??n},[t])}const ce=w.forwardRef(function({children:e,type:n,...r},o){return d.jsx("button",{ref:o,type:"button",draggable:!1,...r,className:le("tlui-button",`tlui-button__${n}`,r.className),children:e})});function Pt({children:t}){return d.jsx("span",{className:"tlui-button__label",children:t})}var pb="Dialog",[e$,hge]=Go(pb),[Ase,po]=e$(pb),t$=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]=Ai({prop:r,defaultProp:o,onChange:s});return d.jsx(Ase,{scope:e,triggerRef:a,contentRef:l,contentId:ms(),titleId:ms(),descriptionId:ms(),open:c,onOpenChange:u,onOpenToggle:w.useCallback(()=>u(h=>!h),[u]),modal:i,children:n})};t$.displayName=pb;var n$="DialogTrigger",jse=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=po(n$,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":mb(o.open),...r,ref:s,onClick:oe(t.onClick,o.onOpenToggle)})});jse.displayName=n$;var fb="DialogPortal",[Ose,r$]=e$(fb,{forceMount:void 0}),o$=t=>{const{__scopeDialog:e,forceMount:n,children:r,container:o}=t,s=po(fb,e);return d.jsx(Ose,{scope:e,forceMount:n,children:w.Children.map(r,i=>d.jsx(ho,{present:n||s.open,children:d.jsx(Pd,{asChild:!0,container:o,children:i})}))})};o$.displayName=fb;var Wf="DialogOverlay",s$=w.forwardRef((t,e)=>{const n=r$(Wf,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=po(Wf,t.__scopeDialog);return s.modal?d.jsx(ho,{present:r||s.open,children:d.jsx(Dse,{...o,ref:e})}):null});s$.displayName=Wf;var Dse=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=po(Wf,n);return d.jsx(am,{as:ha,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ae.div,{"data-state":mb(o.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),fa="DialogContent",i$=w.forwardRef((t,e)=>{const n=r$(fa,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=po(fa,t.__scopeDialog);return d.jsx(ho,{present:r||s.open,children:s.modal?d.jsx(Rse,{...o,ref:e}):d.jsx(Lse,{...o,ref:e})})});i$.displayName=fa;var Rse=w.forwardRef((t,e)=>{const n=po(fa,t.__scopeDialog),r=w.useRef(null),o=Ze(e,n.contentRef,r);return w.useEffect(()=>{const s=r.current;if(s)return Z1(s)},[]),d.jsx(a$,{...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())})}),Lse=w.forwardRef((t,e)=>{const n=po(fa,t.__scopeDialog),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(a$,{...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()}})}),a$=w.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=t,a=po(fa,n),l=w.useRef(null),c=Ze(e,l);return N1(),d.jsxs(d.Fragment,{children:[d.jsx(em,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(wd,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":mb(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(Fse,{titleId:a.titleId}),d.jsx(zse,{contentRef:l,descriptionId:a.descriptionId})]})]})}),gb="DialogTitle",l$=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=po(gb,n);return d.jsx(Ae.h2,{id:o.titleId,...r,ref:e})});l$.displayName=gb;var c$="DialogDescription",$se=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=po(c$,n);return d.jsx(Ae.p,{id:o.descriptionId,...r,ref:e})});$se.displayName=c$;var u$="DialogClose",d$=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=po(u$,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});d$.displayName=u$;function mb(t){return t?"open":"closed"}var h$="DialogTitleWarning",[pge,p$]=xte(h$,{contentName:fa,titleName:gb,docsSlug:"dialog"}),Fse=({titleId:t})=>{const e=p$(h$),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
236
-
237
- If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
238
-
239
- 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},Nse="DialogDescriptionWarning",zse=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${p$(Nse).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},Bse=t$,Use=o$,Hse=s$,Kse=i$;const Bo=w.memo(function({small:e,invertIcon:n,icon:r,color:o,className:s,...i}){const a=hb(),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(Bo,{className:"tlui-button__icon",icon:t,small:e,invertIcon:n})}function dm({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__header",t),children:e})}function hm({className:t,children:e}){return d.jsx(l$,{dir:"ltr",className:le("tlui-dialog__header__title",t),children:e})}function pm(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(d$,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(ce,{type:"icon","aria-label":"Close",onTouchEnd:t=>t.target.click(),children:d.jsx(be,{small:!0,icon:"cross-2"})})})})}function Yu({className:t,children:e,style:n}){return d.jsx("div",{className:le("tlui-dialog__body",t),style:n,children:e})}function yb({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__footer",t),children:e})}const fm=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},y){const S=ki(),b=w.useRef(null);w.useImperativeHandle(y,()=>b.current);const P=Ee(),C=w.useRef(a??""),_=w.useRef(a??""),[E,k]=w.useState(!1),D=w.useCallback(M=>{k(!0);const O=M.currentTarget;_.current=O.value,S?S.timers.requestAnimationFrame(()=>{s&&O.select()}):kx.requestAnimationFrame("anon",()=>{s&&O.select()}),p==null||p()},[s,S,p]),T=w.useCallback(M=>{const O=M.currentTarget.value;_.current=O,u==null||u(O)},[u]),j=w.useCallback(M=>{switch(M.key){case"Enter":{M.currentTarget.blur(),_t(M),c==null||c(M.currentTarget.value);break}case"Escape":{M.currentTarget.value=C.current,h==null||h(M.currentTarget.value),M.currentTarget.blur(),_t(M);break}}},[c,h]),$=w.useCallback(M=>{k(!1);const O=M.currentTarget.value;f==null||f(O)},[f]);return w.useEffect(()=>{if(!Ge.isIos)return;const M=window.visualViewport;if(E&&g&&M){const O=()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})};return M.addEventListener("resize",O),M.addEventListener("scroll",O),S?S.timers.requestAnimationFrame(()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}):kx.requestAnimationFrame("anon",()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}),()=>{M.removeEventListener("resize",O),M.removeEventListener("scroll",O)}}},[E,S,g]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,n&&d.jsx("label",{children:P(n)}),o&&d.jsx(Bo,{icon:o,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:le("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:j,onChange:T,onFocus:D,onBlur:$,autoFocus:i,placeholder:l,value:v}),r&&d.jsx(Bo,{icon:r,small:!!n})]})});function pE(t){return gr.isValid(t)?{isValid:!0,hasProtocol:!0}:gr.isValid("https://"+t)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Wse=qt(function({onClose:e}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(Gse,{onClose:e,selectedShape:r}):null}),Gse=qt(function({onClose:e,selectedShape:n}){const r=z(),o=Ee(),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=pE(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?:\/\/)/,(S,b)=>b),v=pE(m),y=v.isValid===!0?v.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:y,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(dm,{children:[d.jsx(hm,{children:o("edit-link-dialog.title")}),d.jsx(pm,{})]}),d.jsx(Yu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(fm,{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(yb,{className:"tlui-dialog__footer__actions",children:[d.jsx(ce,{type:"normal",onClick:p,onTouchEnd:p,children:d.jsx(Pt,{children:o("edit-link-dialog.cancel")})}),f?d.jsx(ce,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(Pt,{children:o("edit-link-dialog.clear")})}):d.jsx(ce,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(Pt,{children:o("edit-link-dialog.save")})})]})]})});var Vse={};const fE=/(^\/r\/[^/]+\/?$)/,Sb=[{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=ge(t);if(e&&e.pathname.match(fE))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(fE))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=ge(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=${Vse.NEXT_PUBLIC_GC_API_KEY}&center=${r},${o}&zoom=${s}`}else n="";return n}},fromEmbedUrl:t=>{const e=ge(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=ge(t),n=e&&e.pathname.match(/\/v\/(.+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:t=>{const e=ge(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=ge(t),n=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:t=>{const e=ge(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=ge(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=ge(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=ge(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=ge(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=ge(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=ge(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=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return t.split("/").pop()?t:void 0},fromEmbedUrl:t=>{const e=ge(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=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${t}?embed=true`},fromEmbedUrl:t=>{const e=ge(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=ge(t);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=ge(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=ge(t);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=ge(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=ge(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=ge(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=ge(t);if(e&&e.hash.match(/#room=/))return t},fromEmbedUrl:t=>{const e=ge(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=ge(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=ge(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=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${t}?embed`},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],Yse={"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},Xse=Sb.map(t=>t.type);function qse(t){return Xse.includes(t)}function Zse(t){return"icon"in t}function f$(){return z().getShapeUtil("embed")}function vb(){const t=f$();return e=>t?t.getEmbedDefinition(e):void 0}function Qse(){const t=f$();return t?t.getEmbedDefinitions():[]}const g$=qt(function({onClose:e}){const n=z(),r=Ee(),o=hb(),[s,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[h,p]=w.useState(!1),f=w.useRef(-1),g=Qse(),m=vb();return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),d.jsx(pm,{})]}),s?d.jsxs(d.Fragment,{children:[d.jsxs(Yu,{className:"tlui-embed-dialog__enter",children:[d.jsx(fm,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:v=>{l(v);const y=m(v);u(y&&y.definition.type===s.type?y:null),p(!1),clearTimeout(f.current),f.current=n.timers.setTimeout(()=>p(!y),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(Bo,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(yb,{className:"tlui-dialog__footer__actions",children:[d.jsx(ce,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(Pt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(ce,{type:"normal",onClick:e,children:d.jsx(Pt,{children:r("embed-dialog.cancel")})}),d.jsx(ce,{type:"primary",disabled:!c,onClick:()=>{c&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageBounds().center,embed:c.definition}),e())},children:d.jsx(Pt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(Yu,{className:"tlui-embed-dialog__list",children:g.map(v=>{const y=qse(v.type)?o.embedIcons[v.type]:Zse(v)?v.icon:void 0;return d.jsxs(ce,{type:"menu",onClick:()=>i(v),children:[d.jsx(Pt,{children:v.title}),y&&d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${y})`}})]},v.type)})})})]})});async function Jse(t,e,n){const r=me(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 Oo(()=>{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 y of u)if(y.parentId===h){y.index>p&&(p=y.index);break}let f,g,m;if(Fn(h)){const y=t.getShape(h);if(!y)continue;const S=t.getPointInShapeSpace(y,{x:c.x,y:c.y});m=t.getShapePageTransform(h).rotation(),S.sub(new x(s,s).rot(-m)),f=S.x,g=S.y}else f=c.x-s,g=c.y-s,m=0;t.deleteShapes(u),t.createAssets([{...l,id:l.id}]);const v=Ke();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}function gm(){const t=ki();return(t==null?void 0:t.store.props.collaboration)!==void 0}function eie(){const t=ki();return U("sync status",()=>{var e;return(e=t==null?void 0:t.store.props.collaboration)!=null&&e.status?t.store.props.collaboration.status.get():null},[t])}const hS=[0,389,436,476,580,640,840,1023];var St=(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))(St||{});const m$=Te.createContext(null);function tie({forceMobile:t=!1,children:e}){const n=ki(),r=U("breakpoint",()=>{const{width:o}=(n==null?void 0:n.getViewportScreenBounds())??{width:window.innerWidth},s=t?St.MOBILE_SM:hS.length-1;for(let i=0;i<s;i++)if(o>hS[i]&&o<=hS[i+1])return i;return s},[n]);return d.jsx(m$.Provider,{value:r,children:e})}function An(){const t=w.useContext(m$);if(t===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return t}const y$=w.createContext(null);function nie({context:t,children:e}){const n=Qt(),r=qw("dialogs",[]),o=w.useMemo(()=>({dialogs:r,addDialog(s){const i=s.id??ze();return r.update(a=>[...a.filter(l=>l.id!==s.id),{...s,id:i}]),n("open-menu",{source:"dialog",id:i}),Vr.addOpenMenu(i,t),i},removeDialog(s){var a;const i=r.get().find(l=>l.id===s);return i&&((a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:s}),Vr.deleteOpenMenu(s,t),r.update(l=>l.filter(c=>c!==i))),s},clearDialogs(){const s=r.get();s.length!==0&&(s.forEach(i=>{var a;(a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:i.id}),Vr.deleteOpenMenu(i.id,t)}),r.set([]))}}),[n,r,t]);return d.jsx(y$.Provider,{value:o,children:e})}function Ed(){const t=w.useContext(y$);if(!t)throw new Error("useDialogs must be used within a DialogsProvider");return t}var rie="VisuallyHidden",xb=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}}));xb.displayName=rie;var wb="ToastProvider",[bb,oie,sie]=Jg("Toast"),[S$,fge]=Go("Toast",[sie]),[iie,mm]=S$(wb),v$=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 \`${wb}\`. Expected non-empty \`string\`.`),d.jsx(bb.Provider,{scope:e,children:d.jsx(iie,{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})})};v$.displayName=wb;var x$="ToastViewport",aie=["F8"],Hx="toast.viewportPause",Kx="toast.viewportResume",w$=w.forwardRef((t,e)=>{const{__scopeToast:n,hotkey:r=aie,label:o="Notifications ({hotkey})",...s}=t,i=mm(x$,n),a=oie(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=y=>{var b;r.length!==0&&r.every(P=>y[P]||y.code===P)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r]),w.useEffect(()=>{const v=l.current,y=h.current;if(g&&v&&y){const S=()=>{if(!i.isClosePausedRef.current){const _=new CustomEvent(Hx);y.dispatchEvent(_),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const _=new CustomEvent(Kx);y.dispatchEvent(_),i.isClosePausedRef.current=!1}},P=_=>{!v.contains(_.relatedTarget)&&b()},C=()=>{v.contains(document.activeElement)||b()};return v.addEventListener("focusin",S),v.addEventListener("focusout",P),v.addEventListener("pointermove",S),v.addEventListener("pointerleave",C),window.addEventListener("blur",S),window.addEventListener("focus",b),()=>{v.removeEventListener("focusin",S),v.removeEventListener("focusout",P),v.removeEventListener("pointermove",S),v.removeEventListener("pointerleave",C),window.removeEventListener("blur",S),window.removeEventListener("focus",b)}}},[g,i.isClosePausedRef]);const m=w.useCallback(({tabbingDirection:v})=>{const S=a().map(b=>{const P=b.ref.current,C=[P,...xie(P)];return v==="forwards"?C:C.reverse()});return(v==="forwards"?S.reverse():S).flat()},[a]);return w.useEffect(()=>{const v=h.current;if(v){const y=S=>{var C,_,E;const b=S.altKey||S.ctrlKey||S.metaKey;if(S.key==="Tab"&&!b){const k=document.activeElement,D=S.shiftKey;if(S.target===v&&D){(C=c.current)==null||C.focus();return}const $=m({tabbingDirection:D?"backwards":"forwards"}),M=$.findIndex(O=>O===k);pS($.slice(M+1))?S.preventDefault():D?(_=c.current)==null||_.focus():(E=u.current)==null||E.focus()}};return v.addEventListener("keydown",y),()=>v.removeEventListener("keydown",y)}},[a,m]),d.jsxs(Lte,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&d.jsx(Wx,{ref:c,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"forwards"});pS(v)}}),d.jsx(bb.Slot,{scope:n,children:d.jsx(Ae.ol,{tabIndex:-1,...s,ref:p})}),g&&d.jsx(Wx,{ref:u,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"backwards"});pS(v)}})]})});w$.displayName=x$;var b$="ToastFocusProxy",Wx=w.forwardRef((t,e)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=t,s=mm(b$,n);return d.jsx(xb,{"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()}})});Wx.displayName=b$;var ym="Toast",lie="toast.swipeStart",cie="toast.swipeMove",uie="toast.swipeCancel",die="toast.swipeEnd",P$=w.forwardRef((t,e)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=t,[a=!0,l]=Ai({prop:r,defaultProp:o,onChange:s});return d.jsx(ho,{present:n||a,children:d.jsx(fie,{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)})})})});P$.displayName=ym;var[hie,pie]=S$(ym,{onClose(){}}),fie=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=mm(ym,n),[v,y]=w.useState(null),S=Ze(e,O=>y(O)),b=w.useRef(null),P=w.useRef(null),C=o||m.duration,_=w.useRef(0),E=w.useRef(C),k=w.useRef(0),{onToastAdd:D,onToastRemove:T}=m,j=Xt(()=>{var F;(v==null?void 0:v.contains(document.activeElement))&&((F=m.viewport)==null||F.focus()),i()}),$=w.useCallback(O=>{!O||O===1/0||(window.clearTimeout(k.current),_.current=new Date().getTime(),k.current=window.setTimeout(j,O))},[j]);w.useEffect(()=>{const O=m.viewport;if(O){const F=()=>{$(E.current),c==null||c()},B=()=>{const K=new Date().getTime()-_.current;E.current=E.current-K,window.clearTimeout(k.current),l==null||l()};return O.addEventListener(Hx,B),O.addEventListener(Kx,F),()=>{O.removeEventListener(Hx,B),O.removeEventListener(Kx,F)}}},[m.viewport,C,l,c,$]),w.useEffect(()=>{s&&!m.isClosePausedRef.current&&$(C)},[s,C,m.isClosePausedRef,$]),w.useEffect(()=>(D(),()=>T()),[D,T]);const M=w.useMemo(()=>v?M$(v):null,[v]);return m.viewport?d.jsxs(d.Fragment,{children:[M&&d.jsx(gie,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:M}),d.jsx(hie,{scope:n,onClose:j,children:wa.createPortal(d.jsx(bb.ItemSlot,{scope:n,children:d.jsx(Rte,{asChild:!0,onEscapeKeyDown:oe(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||j(),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:S,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:oe(t.onKeyDown,O=>{O.key==="Escape"&&(a==null||a(O.nativeEvent),O.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,j()))}),onPointerDown:oe(t.onPointerDown,O=>{O.button===0&&(b.current={x:O.clientX,y:O.clientY})}),onPointerMove:oe(t.onPointerMove,O=>{if(!b.current)return;const F=O.clientX-b.current.x,B=O.clientY-b.current.y,K=!!P.current,R=["left","right"].includes(m.swipeDirection),H=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,Y=R?H(0,F):0,ee=R?0:H(0,B),he=O.pointerType==="touch"?10:2,ue={x:Y,y:ee},ke={originalEvent:O,delta:ue};K?(P.current=ue,Th(cie,h,ke,{discrete:!1})):gE(ue,m.swipeDirection,he)?(P.current=ue,Th(lie,u,ke,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(F)>he||Math.abs(B)>he)&&(b.current=null)}),onPointerUp:oe(t.onPointerUp,O=>{const F=P.current,B=O.target;if(B.hasPointerCapture(O.pointerId)&&B.releasePointerCapture(O.pointerId),P.current=null,b.current=null,F){const K=O.currentTarget,R={originalEvent:O,delta:F};gE(F,m.swipeDirection,m.swipeThreshold)?Th(die,f,R,{discrete:!0}):Th(uie,p,R,{discrete:!0}),K.addEventListener("click",H=>H.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),gie=t=>{const{__scopeToast:e,children:n,...r}=t,o=mm(ym,e),[s,i]=w.useState(!1),[a,l]=w.useState(!1);return Sie(()=>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(xb,{...r,children:s&&d.jsxs(d.Fragment,{children:[o.label," ",n]})})})},mie="ToastTitle",C$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});C$.displayName=mie;var yie="ToastDescription",_$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});_$.displayName=yie;var I$="ToastAction",E$=w.forwardRef((t,e)=>{const{altText:n,...r}=t;return n.trim()?d.jsx(T$,{altText:n,asChild:!0,children:d.jsx(Pb,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${I$}\`. Expected non-empty \`string\`.`),null)});E$.displayName=I$;var k$="ToastClose",Pb=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t,o=pie(k$,n);return d.jsx(T$,{asChild:!0,children:d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,o.onClose)})})});Pb.displayName=k$;var T$=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 M$(t){const e=[];return Array.from(t.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),vie(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(...M$(r))}}),e}function Th(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?$1(o,s):o.dispatchEvent(s)}var gE=(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 Sie(t=()=>{}){const e=Xt(t);mi(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[e])}function vie(t){return t.nodeType===t.ELEMENT_NODE}function xie(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 pS(t){const e=document.activeElement;return t.some(n=>n===e?!0:(n.focus(),document.activeElement!==e))}var wie=P$,bie=C$,Pie=_$,Cie=E$,mE=Pb;const A$=w.createContext(null);function _ie({children:t}){const e=qw("toasts",[]),n=w.useMemo(()=>({toasts:e,addToast(r){const o=r.id??ze();return e.update(s=>[...s.filter(i=>i.id!==r.id),{...r,id:o}]),o},removeToast(r){return e.update(o=>o.filter(s=>s.id!==r)),r},clearToasts(){e.set([])}}),[e]);return d.jsx(v$,{children:d.jsx(A$.Provider,{value:n,children:t})})}function Ts(){const t=w.useContext(A$);if(!t)throw new Error("useToasts must be used within a ToastsProvider");return t}var Cb={exports:{}};Cb.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="",y="",S=2,b=3,P=2,C=[],_=0,E=0,k;for(k=0;k<l.length;k+=1)if(m=l.charAt(k),Object.prototype.hasOwnProperty.call(f,m)||(f[m]=b++,g[m]=!0),v=y+m,Object.prototype.hasOwnProperty.call(f,v))y=v;else{if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(p=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|p&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=p>>1}else{for(p=1,h=0;h<P;h++)_=_<<1|p,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=0;for(p=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|p&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=p>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(p=f[y],h=0;h<P;h++)_=_<<1|p&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=p>>1;S--,S==0&&(S=Math.pow(2,P),P++),f[v]=b++,y=String(m)}if(y!==""){if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(p=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|p&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=p>>1}else{for(p=1,h=0;h<P;h++)_=_<<1|p,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=0;for(p=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|p&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=p>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(p=f[y],h=0;h<P;h++)_=_<<1|p&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=p>>1;S--,S==0&&(S=Math.pow(2,P),P++)}for(p=2,h=0;h<P;h++)_=_<<1|p&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,p=p>>1;for(;;)if(_=_<<1,E==c-1){C.push(u(_));break}else E++;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=[],y,S,b,P,C,_,E,k={val:u(0),position:c,index:1};for(y=0;y<3;y+=1)h[y]=y;for(b=0,C=Math.pow(2,2),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 2:return""}for(h[3]=E,S=E,v.push(E);;){if(k.index>l)return"";for(b=0,C=Math.pow(2,g),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(E=b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[f++]=n(b),E=f-1,p--;break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[f++]=n(b),E=f-1,p--;break;case 2:return v.join("")}if(p==0&&(p=Math.pow(2,g),g++),h[E])m=h[E];else if(E===f)m=S+S.charAt(0);else return null;v.push(m),h[f++]=S+m.charAt(0),p--,S=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})})(Cb);var Iie=Cb.exports;const j$=xi(Iie),_b="web image/vnd.tldraw+png",Eie={"image/png":_b},kie={[_b]:"image/png"};function Tie(t){return hn(Eie,t)??null}function Mie(t){return hn(kie,t)??t}function Aie(t){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(t)}function jie(t){const e=Object.entries(t);for(const[n,r]of e)r.catch(o=>console.error(o));return navigator.clipboard.write([new ClipboardItem(t)]).catch(n=>(console.error(n),Promise.all(e.map(async([r,o])=>[r,await o])).then(r=>{const o=ww(r);return navigator.clipboard.write([new ClipboardItem(o)])})))}async function Oie(t,e,n){var y,S,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,Ke()),P.boundElements!==null)for(const C of P.boundElements)C.type==="text"&&h.add(C.id)});let p=ZT;for(const P of r){if(h.has(P.id))continue;const C=c.get(P.id),_={id:C,typeName:"shape",parentId:l,index:p,x:P.x,y:P.y,rotation:0,isLocked:P.locked,opacity:Die(P.opacity),meta:{}};switch(P.angle!==0&&a.set(C,P.angle),P.groupIds&&P.groupIds.length>0?i.has(P.groupIds[0])?(y=i.get(P.groupIds[0]))==null||y.push(C):i.set(P.groupIds[0],[C]):u.push(C),P.type){case"rectangle":case"ellipse":case"diamond":{let E="",k="middle";if(P.boundElements!==null){for(const T of P.boundElements)if(T.type==="text"){const j=r.find($=>$.id===T.id);j&&(E=j.text,k=Bie[j.textAlign])}}const D=P.backgroundColor==="transparent"?P.strokeColor:P.backgroundColor;s.shapes.push({..._,type:"geo",props:{geo:P.type,url:P.link??"",w:P.width,h:P.height,size:Mh[P.strokeWidth]??"draw",color:jc[D]??"black",text:E,align:k,dash:Ah(P),fill:Kie(P)}});break}case"freedraw":{s.shapes.push({..._,type:"draw",props:{dash:Ah(P),size:Mh[P.strokeWidth],color:jc[P.strokeColor]??"black",segments:[{type:"free",points:P.points.map(([E,k,D=.5])=>({x:E,y:k,z:D}))}]}});break}case"line":{if(P.points.slice().length<2)break;const k=Fu(P.points.length);s.shapes.push({..._,type:"line",props:{dash:Ah(P),size:Mh[P.strokeWidth],color:jc[P.strokeColor]??"black",spline:P.roundness?"cubic":"line",points:{...Object.fromEntries(P.points.map(([D,T],j)=>{const $=k[j];return[$,{id:$,index:$,x:D,y:T}]}))}}});break}case"arrow":{let E="";if(P.boundElements!==null){for(const $ of P.boundElements)if($.type==="text"){const M=r.find(O=>O.id===$.id);M&&(E=M.text)}}const k=P.points[0],D=P.points[P.points.length-1],T=c.get((S=P.startBinding)==null?void 0:S.elementId),j=c.get((b=P.endBinding)==null?void 0:b.elementId);s.shapes.push({..._,type:"arrow",props:{text:E,bend:Hie(P,k,D),dash:Ah(P),size:Mh[P.strokeWidth]??"m",color:jc[P.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:D[0],y:D[1]},arrowheadEnd:yE[P.endArrowhead]??"none",arrowheadStart:yE[P.startArrowhead]??"none"}}),T&&s.bindings.push({id:Qi(),typeName:"binding",type:"arrow",fromId:C,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),j&&s.bindings.push({id:Qi(),typeName:"binding",type:"arrow",fromId:C,toId:j,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:E,scale:k}=Lie(P.fontSize);s.shapes.push({..._,type:"text",props:{size:E,scale:k,font:$ie[P.fontFamily]??"draw",color:jc[P.strokeColor]??"black",text:P.text,textAlign:Uie[P.textAlign]}});break}case"image":{const E=o[P.fileId];if(!E)break;const k=Vs.createId();s.assets.push({id:k,typeName:"asset",type:"image",props:{w:P.width,h:P.height,fileSize:E.size,name:P.id??"Untitled",isAnimated:!1,mimeType:E.mimeType,src:E.dataURL},meta:{}}),s.shapes.push({..._,type:"image",props:{w:P.width,h:P.height,assetId:k}})}}p=Io(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&&Fn(C.parentId)&&u.push(C.parentId)}for(const[P,C]of a)t.select(P),t.rotateShapesBy([P],C);const g=me(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 Die=t=>{const e=t/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},Mh={1:"s",2:"m",3:"l",4:"xl"},Rie={16:"s",20:"m",28:"l",36:"xl"};function Lie(t){const e=Rie[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 $ie={1:"draw",2:"sans",3:"mono"},Fie={gray:["#f8f9fa","#e9ecef","#ced4da","#868e96","#343a40"],red:["#fff5f5","#ffc9c9","#ff8787","#fa5252","#e03131"],pink:["#fff0f6","#fcc2d7","#f783ac","#e64980","#c2255c"],grape:["#f8f0fc","#eebefa","#da77f2","#be4bdb","#9c36b5"],violet:["#f3f0ff","#d0bfff","#9775fa","#7950f2","#6741d9"],indigo:["#edf2ff","#bac8ff","#748ffc","#4c6ef5","#3b5bdb"],blue:["#e7f5ff","#a5d8ff","#4dabf7","#228be6","#1971c2"],cyan:["#e3fafc","#99e9f2","#3bc9db","#15aabf","#0c8599"],teal:["#e6fcf5","#96f2d7","#38d9a9","#12b886","#099268"],green:["#ebfbee","#b2f2bb","#69db7c","#40c057","#2f9e44"],lime:["#f4fce3","#d8f5a2","#a9e34b","#82c91e","#66a80f"],yellow:["#fff9db","#ffec99","#ffd43b","#fab005","#f08c00"],orange:["#fff4e6","#ffd8a8","#ffa94d","#fd7e14","#e8590c"]};function vo(t,e,n){const r=[0,1,2,3,4].map(o=>Fie[t][o]);return Object.fromEntries(r.map((o,s)=>[o,s<3?e:n]))}const jc={...vo("gray","grey","black"),...vo("red","light-red","red"),...vo("pink","light-red","red"),...vo("grape","light-violet","violet"),...vo("blue","light-blue","blue"),...vo("cyan","light-blue","blue"),...vo("teal","light-green","green"),...vo("green","light-green","green"),...vo("yellow","yellow","orange"),...vo("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},Nie={solid:"draw",dashed:"dashed",dotted:"dotted"},zie={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Bie={left:"start",center:"middle",right:"end"},Uie={left:"start",center:"middle",right:"end"},yE={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Hie(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 Ah=t=>{let e=Nie[t.strokeStyle]??"draw";return e==="draw"&&t.roughness===0&&(e="solid"),e},Kie=t=>t.backgroundColor==="transparent"?"none":zie[t.fillStyle]??"solid";async function Wie(t,e,n,r){const o=e.map(s=>s instanceof File?s:new File([s],"tldrawFile",{type:s.type}));t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"files",files:o,point:n,ignoreParent:!1,sources:r})}function Gie(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 Gx(t,e,n,r){return t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"url",point:n,url:e,sources:r})}const Vie=[_b,"image/png","image/jpeg","image/webp","image/svg+xml"];function Yie(t){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t.trim(),e.body.textContent||e.body.innerText||""}const Xie=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},qie=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 bj(e)},Zie=t=>/^<svg/.test(t),Qie=["input","select","textarea"];function fS(t){const{activeElement:e}=document;return t.menus.hasAnyOpenMenus()||e&&(e.getAttribute("contenteditable")||Qie.indexOf(e.tagName.toLowerCase())>-1)}const gS=(t,e,n,r)=>{const o=qie(e);if(o)for(const s of o)Gx(t,s,n);else Xie(e)?Gx(t,e,n):Zie(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}))},Jie=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}}D$(t,r,n)},O$=async(t,e,n)=>{const r=[];for(const o of e){for(const s of Vie)if(o.types.includes(s)){const i=o.getType(s).then(a=>Zr.rewriteMimeType(a,Mie(s)));r.push({type:"blob",source:i});break}o.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const s=await o.getType("text/html");return await Zr.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await Zr.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await Zr.blobToText(s)})()})}return await D$(t,r,n)};async function D$(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 s=me(await Promise.all(r.map(i=>i.source)));return await Wie(t,s,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=j$.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"){Gie(t,s.data,n);return}for(const s of o)if(s.type==="excalidraw"){Oie(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");gS(t,c,n,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){gS(t,Yie(s.data),n,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Gx(t,s.data,n,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){gS(t,s.data,n,o);return}}const Gf=async t=>{var r;const e=await t.resolveAssetsInContent(t.getContentFromCurrentPage(t.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=j$.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(p7);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 eae(){const t=z(),e=Qt(),n=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Gf(t),e("copy",{source:i}))},[t,e]),r=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Gf(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?(O$(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 tae(){const t=z(),e=Qt(),n=U("editor.isFocused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!n)return;const r=async l=>{t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||fS(t)||(xe(l),await Gf(t),e("copy",{source:"kbd"}))};async function o(l){t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||fS(t)||(xe(l),await Gf(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=>{var p;if(s){_t(l);return}if(t.getEditingShapeId()!==null||fS(t))return;let c,u=!1;t.inputs.shiftKey&&(u=!0),t.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=t.inputs.currentPagePoint);const h=()=>{l.clipboardData&&Jie(t,l.clipboardData,c)};(p=navigator.clipboard)!=null&&p.read?navigator.clipboard.read().then(f=>{Array.isArray(f)&&f[0]instanceof ClipboardItem&&O$(t,f,c)},()=>{h()}):h(),xe(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])}/*!
240
- * canvas-size
241
- * v1.2.6
242
- * https://github.com/jhildenbiddle/canvas-size
243
- * (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
244
- * MIT license
245
- */function nae(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 SE(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 rr(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?SE(Object(n),!0).forEach(function(r){rae(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):SE(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function rae(t,e,n){return e=hae(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function oae(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 sae(t,e){if(t==null)return{};var n=oae(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 vE(t,e){return aae(t)||nae(t,e)||R$(t,e)||uae()}function jh(t){return iae(t)||lae(t)||R$(t)||cae()}function iae(t){if(Array.isArray(t))return Vx(t)}function aae(t){if(Array.isArray(t))return t}function lae(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function R$(t,e){if(t){if(typeof t=="string")return Vx(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 Vx(t,e)}}function Vx(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 cae(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
246
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function uae(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
247
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function dae(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 hae(t){var e=dae(t,"string");return typeof e=="symbol"?e:String(e)}function hu(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&&hu(t)):h?t.onSuccess(n,r,p):(t.onError(n,r,p),t.sizes.length&&hu(t)),h}var mS={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]},pae=["onError","onSuccess"],cl={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},Oc={};function yS(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||cl.min,i=t.step||cl.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 Oh(t){var e=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),o=t.onError,s=t.onSuccess,i=sae(t,pae),a=null;if(!e)return!1;if(t.useWorker&&n){var l=`
248
- var canvasTest = `.concat(hu.toString(),`;
249
- onmessage = function(e) {
250
- canvasTest(e.data);
251
- };
252
- `),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?(Oc[r].onSuccess(f,g,m),delete Oc[r]):Oc[r].onError(f,g,m)}}if(t.usePromise)return new Promise(function(h,p){var f=rr(rr({},t),{},{onError:function(y,S,b){var P;if(t.sizes.length===0)P=!0;else{var C=t.sizes.slice(-1),_=vE(C,1),E=vE(_[0],2),k=E[0],D=E[1];P=y===k&&S===D}o(y,S,b),P&&p({width:y,height:S,benchmark:b})},onSuccess:function(y,S,b){s(y,S,b),h({width:y,height:S,benchmark:b})}});if(a){var g=f.onError,m=f.onSuccess;Oc[r]={onError:g,onSuccess:m},a.postMessage(i)}else hu(f)});if(a)Oc[r]={onError:o,onSuccess:s},a.postMessage(i);else return hu(t)}var SS={maxArea:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=yS({width:e.max,height:e.max,min:e.min,step:e.step,sizes:jh(mS.area)}),r=rr(rr(rr({},cl),e),{},{sizes:n});return Oh(r)},maxHeight:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=yS({width:1,height:e.max,min:e.min,step:e.step,sizes:jh(mS.height)}),r=rr(rr(rr({},cl),e),{},{sizes:n});return Oh(r)},maxWidth:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=yS({width:e.max,height:1,min:e.min,step:e.step,sizes:jh(mS.width)}),r=rr(rr(rr({},cl),e),{},{sizes:n});return Oh(r)},test:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=rr(rr({},cl),e);return n.sizes=jh(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),Oh(n)}};let vS=null;function fae(){return vS||(vS=gae()),vS}async function gae(){const t=await SS.maxWidth({usePromise:!0}),e=await SS.maxHeight({usePromise:!0}),n=await SS.maxArea({usePromise:!0});return{maxWidth:t.width,maxHeight:e.height,maxArea:n.width*n.height}}const xE=8192,mae=4096*4096;async function yae(t,e){if(t<=xE&&e<=xE&&t*e<=mae)return[t,e];const{maxWidth:n,maxHeight:r,maxArea:o}=await fae(),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 L$(t,e,n){const{type:r,width:o,height:s,quality:i=1,pixelRatio:a=2}=n;let[l,c]=await yae(o*a,s*a);l=Math.floor(l),c=Math.floor(c);const u=l/o,h=await Zr.blobToDataUrl(new Blob([e],{type:"image/svg+xml"})),p=await new Promise(g=>{const m=Lu();m.crossOrigin="anonymous",m.onload=async()=>{Ge.isSafari&&await Wv(250);const v=document.createElement("canvas"),y=v.getContext("2d");v.width=l,v.height=c,y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.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||bt.throwToBlob.get())&&g(null),g(m)},"image/"+r,i));if(!f)return null;if(r==="png"){const g=new DataView(await f.arrayBuffer());return Co.setPhysChunk(g,u,{type:"image/"+r})}else return f}async function $$(t,e,n){const r=await t.getSvgString(e!=null&&e.length?e:[...t.getCurrentPageShapeIds()],{scale:n.scale??1,background:t.getInstanceState().exportBackground,...n});if(!r)throw new Error("Could not construct SVG.");return r}async function Yx(t,e,n,r={}){var o;switch(n){case"svg":return(o=await $$(t,e,r))==null?void 0:o.svg;case"json":{const s=await t.resolveAssetsInContent(t.getContentFromCurrentPage(e));return JSON.stringify(s)}default:Ot(n)}}async function F$({editor:t,ids:e,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await Yx(t,e,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Yx(t,e,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await $$(t,e,r);if(!o)throw new Error("Could not construct image.");const s=await L$(t,o.svg,{type:n,quality:r.quality,pixelRatio:r.pixelRatio,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:Ot(n)}}const Sae={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function vae(t,e,n,r={}){return{blobPromise:F$({editor:t,ids:e,format:n,opts:r}),mimeType:Sae[n]}}function xae(t,e,n="svg",r={}){if(!navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(navigator.clipboard.write){const{blobPromise:o,mimeType:s}=vae(t,e,n,r),i={[s]:o},a=Tie(s);return a&&Aie(a)&&(i[a]=o.then(l=>Zr.rewriteMimeType(l,a))),jie(i)}switch(n){case"json":case"svg":return wae(async()=>Yx(t,e,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Ot(n)}}async function wae(t){var e,n;await((n=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:n.call(e,await t()))}function bae(){const t=z(),{addToast:e}=Ts(),n=Ee();return w.useCallback((r,o="svg")=>{xae(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 Pae(t,e,n="png",r,o={}){if(!r&&(r=`shapes at ${wE()}`,e.length===1)){const a=t.getShape(e[0]);t.isShapeOfType(a,"frame")?r=a.props.name||"frame":r=`${Rg(a.id)} at ${wE()}`}r+=`.${n}`;const s=await F$({editor:t,ids:e,format:n,opts:o}),i=new File([s],r,{type:s.type});Cae(i)}function wE(){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 Cae(t){const e=document.createElement("a"),n=URL.createObjectURL(t);e.href=n,e.download=t.name,e.click(),URL.revokeObjectURL(n)}function _ae(){const t=z(),{addToast:e}=Ts(),n=Ee();return w.useCallback((r,o="png",s)=>{Pae(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])}const N$=Te.createContext([]);function Iae(){const t=z(),e=w.useRef(),n=Xs(Te.useContext(N$));return w.useEffect(()=>{const r=window.document.createElement("input");r.type="file",r.accept=(n==null?void 0:n.join(","))??H9,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 Eae(){const t=z(),e=w.useRef(null),n=w.useRef(null);return w.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(y,S)=>{y&&(y.innerHTML=""),S&&document.head.contains(S)&&document.head.removeChild(S),y&&document.body.contains(y)&&document.body.removeChild(y)};i(e.current,n.current),e.current=o,n.current=s;const a=`tl-print-surface-${ze()}`;o.className=a,s.innerHTML=`
253
- .${a} {
254
- display: none;
255
- }
256
-
257
- .${a} svg {
258
- max-width: 100%;
259
- height: 100%;
260
- display: block;
261
- }
262
-
263
- @media print {
264
- html, body {
265
- min-height: 100%;
266
- height: 100%;
267
- margin: 0;
268
- }
269
-
270
- body {
271
- position: relative;
272
- }
273
-
274
- body > * {
275
- display: none;
276
- }
277
-
278
- .tldraw__editor {
279
- display: none;
280
- }
281
-
282
- .${a} {
283
- display: block !important;
284
- background: white;
285
- min-height: 100%;
286
- height: 100%;
287
- max-width: 100%;
288
- }
289
-
290
- .${a}__item {
291
- padding: 10mm;
292
- display: flex;
293
- min-height: 100%;
294
- flex-direction: column;
295
- page-break-after: always;
296
- position: relative;
297
- overflow: hidden;
298
- height: 100%;
299
- }
300
-
301
- .${a}__item__main {
302
- flex: 1;
303
- display: flex;
304
- align-items: center;
305
- justify-content: center;
306
- max-height: 100%;
307
- }
308
-
309
- .${a}__item__header {
310
- display: none;
311
- }
312
-
313
- .${a}__item__footer {
314
- display: none;
315
- text-align: right;
316
- }
317
-
318
- .${a}__item__footer__hide {
319
- display: none;
320
- }
321
-
322
-
323
- }
324
-
325
- `;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(y,S,b){try{o.innerHTML+=`<div class="${a}__item">
326
- <div class="${a}__item__header">
327
- ${y.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
328
- </div>
329
- <div class="${a}__item__main">
330
- ${b}
331
- </div>
332
- <div class="${a}__item__footer ${a}__item__footer__${S?"":"hide"}">
333
- ${S??""}
334
- </div>
335
- </div>`}catch(P){console.error(P)}}function h(){Ge.isChromeForIos?(l(),window.print()):Ge.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 y=await t.getSvgString(p,v);if(y){const S=g.find(b=>b.id===f);u(`tldraw — ${S==null?void 0:S.name}`,null,y.svg),h()}}else{const y=t.getCurrentPage(),S=await t.getSvgString(t.getSortedChildIdsForParent(y.id),v);S&&(u(`tldraw — ${y.name}`,null,S.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[t])}function Ib(){const{addToast:t,removeToast:e,clearToasts:n}=Ts(),{addDialog:r,clearDialogs:o,removeDialog:s}=Ed(),i=Ee(),a=Iae(),l=Eae(),{cut:c,copy:u,paste:h}=eae(),p=bae(),f=_ae(),g=vb(),v=An()<St.TABLET_SM;return w.useMemo(()=>({addToast:t,removeToast:e,clearToasts:n,addDialog:r,removeDialog:s,clearDialogs:o,msg:i,isMobile:v,insertMedia:a,printSelectionOrPages:l,cut:c,copy:u,paste:h,copyAs:p,exportAs:f,getEmbedDefinition:g}),[t,e,n,r,s,o,i,v,a,l,c,u,h,p,f,g])}function kae(t,e){const n={};for(const r of t)if(r.translations)for(const[o,s]of Xn(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return{actions:(r,o,s)=>{for(const i of t)i.actions&&(o=i.actions(r,o,s));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 z$(t){return w.useMemo(()=>t,t)}function Tae(t){const e=z$(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 Xn(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return n},[e])}function Mae(t){const e=Ib(),n=z$(t==null?[]:Array.isArray(t)?t:[t]);return w.useMemo(()=>kae(n,e),[n,e])}const B$=w.createContext(null);function Aae(t){return Object.fromEntries(t.map(e=>[e.id,e]))}function Ba(t,e){if(t.getSelectedShapes().length===0)return t.getDocumentSettings().name||e}function jae({overrides:t,children:e}){const n=z(),r=gm(),o=Ib(),s=Qt(),i=o.msg("document.default-name"),a=w.useMemo(()=>{function l(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function c(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}const u=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(p){c()&&(l()||(s("edit-link",{source:p}),n.markHistoryStoppingPoint("edit-link"),o.addDialog({component:Wse})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(p){s("insert-embed",{source:p}),o.addDialog({component:g$})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(p){s("insert-media",{source:p}),o.insertMedia()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(p){s("undo",{source:p}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(p){s("redo",{source:p}),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(p){let f=n.getSelectedShapeIds();f.length===0&&(f=Array.from(n.getCurrentPageShapeIds().values())),f.length!==0&&(s("export-as",{format:"svg",source:p}),o.exportAs(f,"svg",Ba(n,i)))}},{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(p){let f=n.getSelectedShapeIds();f.length===0&&(f=Array.from(n.getCurrentPageShapeIds().values())),f.length!==0&&(s("export-as",{format:"png",source:p}),o.exportAs(f,"png",Ba(n,i)))}},{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(p){let f=n.getSelectedShapeIds();f.length===0&&(f=Array.from(n.getCurrentPageShapeIds().values())),f.length!==0&&(s("export-as",{format:"json",source:p}),o.exportAs(f,"json",Ba(n,i)))}},{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(p){let f=n.getSelectedShapeIds();f.length===0&&(f=Array.from(n.getCurrentPageShapeIds().values())),f.length!==0&&(s("export-all-as",{format:"svg",source:p}),o.exportAs(Array.from(n.getCurrentPageShapeIds()),"svg",Ba(n,i)))}},{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(p){const f=Array.from(n.getCurrentPageShapeIds().values());f.length!==0&&(s("export-all-as",{format:"png",source:p}),o.exportAs(f,"png",Ba(n,i)))}},{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(p){const f=Array.from(n.getCurrentPageShapeIds().values());f.length!==0&&(s("export-all-as",{format:"json",source:p}),o.exportAs(f,"json",Ba(n,i)))}},{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(p){let f=n.getSelectedShapeIds();f.length===0&&(f=Array.from(n.getCurrentPageShapeIds().values())),f.length!==0&&(s("copy-as",{format:"svg",source:p}),o.copyAs(f,"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(p){let f=n.getSelectedShapeIds();f.length===0&&(f=Array.from(n.getCurrentPageShapeIds().values())),f.length!==0&&(s("copy-as",{format:"png",source:p}),o.copyAs(f,"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(p){let f=n.getSelectedShapeIds();f.length===0&&(f=Array.from(n.getCurrentPageShapeIds().values())),f.length!==0&&(s("copy-as",{format:"json",source:p}),o.copyAs(f,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(p){if(!c()||l())return;s("toggle-auto-size",{source:p}),n.markHistoryStoppingPoint("toggling auto size");const f=n.getSelectedShapes().filter(g=>n.isShapeOfType(g,"text")&&g.props.autoSize===!1);n.updateShapes(f.map(g=>({id:g.id,type:g.type,props:{...g.props,w:8,autoSize:!0}}))),Ye(n,f.map(g=>g.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(p){s("open-embed-link",{source:p});const f=n.getSelectedShapeIds(),g="No embed shapes selected";if(f.length!==1){console.error(g);return}const m=n.getShape(f[0]);if(!m||!n.isShapeOfType(m,"embed")){console.error(g);return}Ste(m.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(p){var f,g;if(((f=n.root.getCurrent())==null?void 0:f.id)!=="zoom"&&(s("zoom-tool",{source:p}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const m=n.root.getCurrent();m&&((g=m.getCurrent())==null?void 0:g.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:m.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(p){c()&&(l()||n.run(()=>{s("convert-to-bookmark",{source:p});const f=n.getSelectedShapes(),g=[],m=[];for(const v of f){if(!v||!n.isShapeOfType(v,"embed")||!v.props.url)continue;const y=new x(v.x,v.y);y.rot(-v.rotation),y.add(new x(v.props.w/2-300/2,v.props.h/2-320/2)),y.rot(v.rotation);const S={id:Ke(),type:"bookmark",rotation:v.rotation,x:y.x,y:y.y,opacity:1,props:{url:v.props.url}};g.push(S),m.push(v.id)}n.markHistoryStoppingPoint("convert shapes to bookmark"),n.deleteShapes(m),n.createShapes(g)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(p){c()&&(l()||(s("convert-to-embed",{source:p}),n.run(()=>{const f=n.getSelectedShapeIds(),g=me(f.map(y=>n.getShape(y))),m=[],v=[];for(const y of g){if(!n.isShapeOfType(y,"bookmark"))continue;const{url:S}=y.props,b=o.getEmbedDefinition(S);if(!b||!b.definition)continue;const{width:P,height:C}=b.definition,_=new x(y.x,y.y);_.rot(-y.rotation),_.add(new x(y.props.w/2-P/2,y.props.h/2-C/2)),_.rot(y.rotation);const E={id:Ke(),type:"embed",x:_.x,y:_.y,rotation:y.rotation,props:{url:S,w:P,h:C}};m.push(E),v.push(y.id)}n.markHistoryStoppingPoint("convert shapes to embed"),n.deleteShapes(v),n.createShapes(m)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(p){if(!c()||l())return;s("duplicate-shapes",{source:p});const f=n.getInstanceState();let g,m;if(f.duplicateProps)g=f.duplicateProps.shapeIds,m=f.duplicateProps.offset;else{g=n.getSelectedShapeIds();const v=Z.Common(me(g.map(y=>n.getShapePageBounds(y))));m=n.getCameraOptions().isLocked?{x:n.options.adjacentShapeMargin,y:n.options.adjacentShapeMargin}:{x:v.width+n.options.adjacentShapeMargin,y:0}}n.markHistoryStoppingPoint("duplicate shapes"),n.duplicateShapes(g,m),f.duplicateProps&&n.updateInstanceState({duplicateProps:{...f.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(p){c()&&(l()||(s("ungroup-shapes",{source:p}),n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(p){if(!c()||l())return;s("group-shapes",{source:p});const f=n.getOnlySelectedShape();f&&n.isShapeOfType(f,"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(p){if(!c())return;s("remove-frame",{source:p});const f=n.getSelectedShapes();f.length>0&&f.every(g=>n.isShapeOfType(g,"frame"))&&(n.markHistoryStoppingPoint("remove-frame"),Cse(n,f.map(g=>g.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(p){if(!c())return;s("fit-frame-to-content",{source:p});const f=n.getOnlySelectedShape();f&&n.isShapeOfType(f,"frame")&&(n.markHistoryStoppingPoint("fit-frame-to-content"),Ise(n,f.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(p){if(!c()||l())return;s("align-shapes",{operation:"left",source:p}),n.markHistoryStoppingPoint("align left");const f=n.getSelectedShapeIds();n.alignShapes(f,"left"),Ye(n,f)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(p){if(!c()||l())return;s("align-shapes",{operation:"center-horizontal",source:p}),n.markHistoryStoppingPoint("align center horizontal");const f=n.getSelectedShapeIds();n.alignShapes(f,"center-horizontal"),Ye(n,f)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(p){if(!c()||l())return;s("align-shapes",{operation:"right",source:p}),n.markHistoryStoppingPoint("align right");const f=n.getSelectedShapeIds();n.alignShapes(f,"right"),Ye(n,f)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(p){if(!c()||l())return;s("align-shapes",{operation:"center-vertical",source:p}),n.markHistoryStoppingPoint("align center vertical");const f=n.getSelectedShapeIds();n.alignShapes(f,"center-vertical"),Ye(n,f)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(p){if(!c()||l())return;s("align-shapes",{operation:"top",source:p}),n.markHistoryStoppingPoint("align top");const f=n.getSelectedShapeIds();n.alignShapes(f,"top"),Ye(n,f)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(p){if(!c()||l())return;s("align-shapes",{operation:"bottom",source:p}),n.markHistoryStoppingPoint("align bottom");const f=n.getSelectedShapeIds();n.alignShapes(f,"bottom"),Ye(n,f)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(p){if(!c()||l())return;s("distribute-shapes",{operation:"horizontal",source:p}),n.markHistoryStoppingPoint("distribute horizontal");const f=n.getSelectedShapeIds();n.distributeShapes(f,"horizontal"),Ye(n,f)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(p){if(!c()||l())return;s("distribute-shapes",{operation:"vertical",source:p}),n.markHistoryStoppingPoint("distribute vertical");const f=n.getSelectedShapeIds();n.distributeShapes(f,"vertical"),Ye(n,f)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(p){if(!c()||l())return;s("stretch-shapes",{operation:"horizontal",source:p}),n.markHistoryStoppingPoint("stretch horizontal");const f=n.getSelectedShapeIds();n.stretchShapes(f,"horizontal"),Ye(n,f)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(p){if(!c()||l())return;s("stretch-shapes",{operation:"vertical",source:p}),n.markHistoryStoppingPoint("stretch vertical");const f=n.getSelectedShapeIds();n.stretchShapes(f,"vertical"),Ye(n,f)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(p){if(!c()||l())return;s("flip-shapes",{operation:"horizontal",source:p}),n.markHistoryStoppingPoint("flip horizontal");const f=n.getSelectedShapeIds();n.flipShapes(f,"horizontal"),Ye(n,f)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(p){if(!c()||l())return;s("flip-shapes",{operation:"vertical",source:p}),n.markHistoryStoppingPoint("flip vertical");const f=n.getSelectedShapeIds();n.flipShapes(f,"vertical"),Ye(n,f)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(p){if(!c()||l())return;s("pack-shapes",{source:p}),n.markHistoryStoppingPoint("pack");const f=n.getSelectedShapeIds();n.packShapes(f,n.options.adjacentShapeMargin),Ye(n,f)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(p){if(!c()||l())return;s("stack-shapes",{operation:"vertical",source:p}),n.markHistoryStoppingPoint("stack-vertical");const f=n.getSelectedShapeIds();n.stackShapes(f,"vertical",16),Ye(n,f)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(p){if(!c()||l())return;s("stack-shapes",{operation:"horizontal",source:p}),n.markHistoryStoppingPoint("stack-horizontal");const f=n.getSelectedShapeIds();n.stackShapes(f,"horizontal",16),Ye(n,f)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(p){c()&&(l()||(s("reorder-shapes",{operation:"toFront",source:p}),n.markHistoryStoppingPoint("bring to front"),n.bringToFront(n.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(p){c()&&(l()||(s("reorder-shapes",{operation:"forward",source:p}),n.markHistoryStoppingPoint("bring forward"),n.bringForward(n.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(p){c()&&(l()||(s("reorder-shapes",{operation:"backward",source:p}),n.markHistoryStoppingPoint("send backward"),n.sendBackward(n.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(p){c()&&(l()||(s("reorder-shapes",{operation:"toBack",source:p}),n.markHistoryStoppingPoint("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(p){c()&&(l()||(n.markHistoryStoppingPoint("cut"),o.cut(p)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(p){c()&&(l()||o.copy(p))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(p){var f;(f=navigator.clipboard)==null||f.read().then(g=>{o.paste(g,p,p==="context-menu"?n.inputs.currentPagePoint:void 0)}).catch(()=>{o.addToast({title:o.msg("action.paste-error-title"),description:o.msg("action.paste-error-description"),severity:"error"})})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(p){n.run(()=>{l()||(s("select-all-shapes",{source:p}),n.markHistoryStoppingPoint("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(p){c()&&(l()||(s("select-none-shapes",{source:p}),n.markHistoryStoppingPoint("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(p){c()&&(l()||(s("delete-shapes",{source:p}),n.markHistoryStoppingPoint("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(p){if(!c()||l())return;s("rotate-cw",{source:p}),n.markHistoryStoppingPoint("rotate-cw");const f=n.getSelectionRotation()%(qe/2),g=ui(f,0)||ui(f,qe/2),m=n.getSelectedShapeIds();n.rotateShapesBy(m,qe/2-(g?0:f)),Ye(n,m)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(p){if(!c()||l())return;s("rotate-ccw",{source:p}),n.markHistoryStoppingPoint("rotate-ccw");const f=n.getSelectionRotation()%(qe/2),g=ui(f,0),m=n.getSelectedShapeIds();n.rotateShapesBy(m,g?-(qe/2):-f),Ye(n,m)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(p){s("zoom-in",{source:p}),n.zoomIn(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(p){s("zoom-out",{source:p}),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(p){s("reset-zoom",{source:p}),n.resetZoom(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(p){s("zoom-to-fit",{source:p}),n.zoomToFit({animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(p){c()&&(l()||(s("zoom-to-selection",{source:p}),n.zoomToSelection({animation:{duration:n.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(p){s("toggle-snap-mode",{source:p}),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(p){const f=n.user.getIsDarkMode()?"light":"dark";s("color-scheme",{source:p,value:f}),n.user.updateUserPreferences({colorScheme:f})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(p){s("toggle-wrap-mode",{source:p}),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(p){s("toggle-dynamic-size-mode",{source:p}),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(p){s("toggle-paste-at-cursor",{source:p}),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(p){s("toggle-reduce-motion",{source:p}),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(p){s("toggle-edge-scrolling",{source:p}),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(p){s("toggle-transparent",{source:p}),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(p){s("toggle-tool-lock",{source:p}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(p){s("unlock-all",{source:p});const f=[];for(const g of n.getCurrentPageShapes())g.isLocked&&f.push({id:g.id,type:g.type,isLocked:!1});f.length>0&&n.updateShapes(f)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(p){n.timers.requestAnimationFrame(()=>{n.run(()=>{s("toggle-focus-mode",{source:p}),o.clearDialogs(),o.clearToasts(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(p){s("toggle-grid-mode",{source:p}),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(p){s("toggle-debug-mode",{source:p}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(p){s("print",{source:p}),o.printSelectionOrPages()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(p){s("exit-pen-mode",{source:p}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(p){s("stop-following",{source:p}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(p){s("zoom-to-content",{source:p});const f=n.getSelectionPageBounds()??n.getCurrentPageBounds();f&&n.zoomToBounds(f,{targetZoom:Math.min(1,n.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(p){n.markHistoryStoppingPoint("locking"),s("toggle-lock",{source:p}),n.toggleLock(n.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(p){const f=yr.createId(),g=n.getSelectedShapeIds();n.run(()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.createPage({name:o.msg("page-menu.new-page-initial-name"),id:f}),n.moveShapesToPage(g,f)}),s("move-to-new-page",{source:p})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(p){const f=mr;n.run(()=>{n.markHistoryStoppingPoint("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(f,"white"),n.setStyleForNextShapes(f,"white")}),s("set-style",{source:p,id:f.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(p){const f=ua;n.run(()=>{n.markHistoryStoppingPoint("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(f,"fill"),n.setStyleForNextShapes(f,"fill")}),s("set-style",{source:p,id:f.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async p=>{const f=n.getSelectedShapeIds();if(f.length===0)return;n.markHistoryStoppingPoint("flattening to image"),s("flatten-to-image",{source:p});const g=await Jse(n,f,n.options.flattenImageBoundsExpand);g!=null&&g.length&&n.setSelectedShapes(g)}}];r&&u.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(p){s("open-cursor-chat",{source:p}),!n.getInstanceState().isCoarsePointer&&n.timers.requestAnimationFrame(()=>{n.updateInstanceState({isChatting:!0})})}});const h=Aae(u);return t?t(n,h,o):h},[o,n,s,t,i,r]);return d.jsx(B$.Provider,{value:a,children:e})}function Ea(){const t=w.useContext(B$);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Xu(t,e){return t?typeof t=="string"?t:e?t[e]??t.default:void 0:void 0}function wr(){const t=ki();return U("isReadonlyMode",()=>!!(t!=null&&t.getIsReadonly()),[t])}const Oae=Ge.isDarwin?"⌘":"Ctrl",Dae=Ge.isDarwin?"⌥":"Alt";function U$(t){return t===","?[","]:t.split(",")[0].split("").map(e=>{const n=e.replace(/\$/g,Oae).replace(/\?/g,Dae).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function Xx(t){return"— "+U$(t).join(" ")}function pu({children:t,visibleOnMobileLayout:e=!1}){const n=An();return!e&&n<St.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:U$(t).map((r,o)=>d.jsx("span",{children:r},o))})}const H$=w.createContext(null);function Sm(){const t=w.useContext(H$);if(!t)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return t}function Fr({type:t,sourceId:e,children:n}){return d.jsx(H$.Provider,{value:{type:t,sourceId:e},children:n})}function vm({id:t,kbd:e,label:n,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=Sm(),u=wr(),h=Ee();if(u&&!r)return null;const p=Xu(n,l),f=p?h(p):void 0;switch(l){case"menu":return d.jsxs(xse,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:f,onSelect:g=>{o==null||o(c),xe(g)},disabled:i,checked:a,children:[d.jsx(Bo,{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(pu,{children:e})]});case"context-menu":return d.jsxs(qoe,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:f,onSelect:g=>{o(c),xe(g)},disabled:i,checked:a,children:[d.jsx(Bo,{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(pu,{children:e})]},t);default:return null}}function Ms(t,e){const n=ki(),r=w.useCallback(i=>{i&&(n==null||n.complete()),e==null||e(i)},[n,e]),o=Qt(),s=w.useCallback(i=>{o(i,{source:"unknown",id:t})},[t,o]);return ute(n?`${t}-${n.contextId}`:t,r,s)}function ga({id:t,children:e,modal:n=!1,debugOpen:r=!1}){const[o,s]=Ms(t);return d.jsx(cb,{open:r||o,dir:"ltr",modal:n,onOpenChange:s,children:e})}function ma({children:t,...e}){return d.jsx(ub,{dir:"ltr",asChild:!0,onTouchEnd:n=>xe(n),...e,children:t})}function ya({className:t,side:e="bottom",align:n="start",sideOffset:r=8,alignOffset:o=8,children:s}){const i=Mt();return d.jsx(um,{container:i,children:d.jsx(db,{className:le("tlui-menu",t),side:e,sideOffset:r,align:n,alignOffset:o,collisionPadding:4,children:s})})}function Rae({id:t,children:e}){const[n,r]=Ms(t);return d.jsx(wse,{open:n,onOpenChange:r,children:e})}function Lae({id:t,label:e,title:n,disabled:r}){return d.jsx(bse,{dir:"ltr",asChild:!0,disabled:r,children:d.jsxs(ce,{"data-testid":t,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:n,children:[d.jsx(Pt,{children:e}),d.jsx(be,{icon:"chevron-right",small:!0})]})})}function $ae({id:t,alignOffset:e=-1,sideOffset:n=-6,size:r="small",children:o}){const s=Mt();return d.jsx(um,{container:s,children:d.jsx(Pse,{"data-testid":t,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:n,collisionPadding:4,"data-size":r,children:o})})}function Fae({children:t}){return d.jsx(Sse,{dir:"ltr",className:"tlui-menu__group",children:t})}function qu({noClose:t,children:e}){return d.jsx(vse,{dir:"ltr",asChild:!0,onClick:t?xe:void 0,children:e})}function ve({id:t,label:e,children:n}){const{type:r,sourceId:o}=Sm(),s=Ee(),i=Xu(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(Fae,{"data-testid":`${o}-group.${t}`,children:n});case"context-menu":return d.jsx(jL,{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 Jn({id:t,disabled:e=!1,label:n,size:r="small",children:o}){const{type:s,sourceId:i}=Sm(),a=Mt(),l=Ee(),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(Rae,{id:`${i}-sub.${t}`,children:[d.jsx(Lae,{id:`${i}-sub.${t}-button`,disabled:e,label:u,title:u}),d.jsx($ae,{id:`${i}-sub.${t}-content`,size:r,children:o})]});case"context-menu":return e?null:d.jsxs(Nae,{id:`${i}-sub.${t}`,children:[d.jsx(LL,{dir:"ltr",disabled:e,asChild:!0,children:d.jsxs(ce,{"data-testid":`${i}-sub.${t}-button`,type:"menu",className:"tlui-menu__submenu__trigger",children:[d.jsx(Pt,{children:u}),d.jsx(be,{icon:"chevron-right",small:!0})]})}),d.jsx(ab,{container:a,children:d.jsx($L,{"data-testid":`${i}-sub.${t}-content`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:o})})]});default:return o}}function Nae({id:t,children:e}){const[n,r]=Ms(t);return d.jsx(RL,{open:n,onOpenChange:r,children:e})}const zae=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Bae(){const t=z(),e=Qt(),n=U("colorScheme",()=>t.user.getUserPreferences().colorScheme??(t.user.getIsDarkMode()?"dark":"light"),[t]);return d.jsx(Jn,{id:"help menu color-scheme",label:"menu.theme",children:d.jsx(ve,{id:"theme",children:zae.map(({colorScheme:r,label:o})=>d.jsx(vm,{id:`color-scheme-${r}`,label:o,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({colorScheme:r}),e("color-scheme",{source:"menu",value:r})}},r))})})}const Uae=({id:t,component:e,onClose:n})=>{const{removeDialog:r}=Ed(),o=Mt(),s=w.useCallback(i=>{if(!i){if(n)try{n()}catch(a){console.warn(a)}r(t)}},[t,n,r]);return d.jsx(Bse,{onOpenChange:s,defaultOpen:!0,children:d.jsx(Use,{container:o,children:d.jsx(Hse,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:d.jsx(Kse,{dir:"ltr",className:"tlui-dialog__content","aria-describedby":void 0,children:d.jsx(e,{onClose:()=>s(!1)})})})})})},Hae=w.memo(function(){const{dialogs:e}=Ed();return U("dialogs",()=>e.get(),[e]).map(r=>d.jsx(Uae,{...r},r.id))}),Kae=4e3,Wae={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function Gae({toast:t}){const{removeToast:e}=Ts(),n=Ee(),r=i=>{i||e(t.id)},o=t.actions&&t.actions.length>0,s=t.icon||t.severity&&Wae[t.severity];return d.jsxs(wie,{onOpenChange:r,className:"tlui-toast__container",duration:t.keepOpen?1/0:Kae,"data-severity":t.severity,children:[s&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(Bo,{icon:s})}),d.jsxs("div",{className:"tlui-toast__main","data-title":!!t.title,"data-description":!!t.description,"data-actions":!!t.actions,children:[d.jsxs("div",{className:"tlui-toast__content",children:[t.title&&d.jsx(bie,{className:"tlui-toast__title",children:t.title}),t.description&&d.jsx(Pie,{className:"tlui-toast__description",children:t.description})]}),t.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[t.actions.map((i,a)=>d.jsx(Cie,{altText:i.label,asChild:!0,onClick:i.onClick,children:d.jsx(ce,{type:i.type,children:d.jsx(Pt,{children:i.label})})},a)),d.jsx(mE,{asChild:!0,children:d.jsx(ce,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:d.jsx(Pt,{children:t.closeLabel??n("toast.close")})})})]})]}),!o&&d.jsx(mE,{asChild:!0,children:d.jsx(ce,{type:"normal",className:"tlui-toast__close",children:d.jsx(Pt,{children:t.closeLabel??n("toast.close")})})})]})}const Vae=w.memo(function(){const{toasts:e}=Ts(),n=U("toasts",()=>e.get(),[]);return d.jsxs(d.Fragment,{children:[n.map(r=>d.jsx(Gae,{toast:r},r.id)),d.jsx(w$,{className:"tlui-toast__viewport"})]})});function fo({actionId:t="",...e}){const r=Ea()[t];return r?d.jsx(vm,{...r,...e}):null}function bE(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 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}=Sm(),p=Ee(),[f,g]=w.useState(!1);if(wr()&&!n)return null;const v=Xu(s,u),y=o?Xx(o):void 0,S=v?p(v):void 0,b=S&&y?`${S} ${y}`:S;switch(u){case"menu":return d.jsx(qu,{children:d.jsxs(ce,{type:"menu","data-testid":`${h}.${r}`,disabled:t,title:b,onClick:P=>{l&&xe(P),f?g(!1):a(h)},children:[d.jsx(Pt,{children:S}),o&&d.jsx(pu,{children:o})]})});case"context-menu":return t?null:d.jsxs(OL,{dir:"ltr",title:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:P=>{l&&xe(P),f?g(!1):a(h)},children:[d.jsx("span",{className:"tlui-button__label",draggable:!1,children:S}),o&&d.jsx(pu,{children:o}),e&&d.jsx(bE,{})]});case"panel":return d.jsxs(ce,{"data-testid":`${h}.${r}`,type:"menu",title:b,disabled:t,onClick:()=>a(h),children:[d.jsx(Pt,{children:S}),e?d.jsx(bE,{}):i&&d.jsx(be,{icon:i})]});case"small-icons":case"icons":return d.jsx(ce,{"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:S}),d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:d.jsx(pu,{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(ce,{type:"low",onClick:()=>a(h),children:[d.jsx(be,{icon:i}),d.jsx(Pt,{children:S})]});case"toolbar":return d.jsx(ce,{type:"tool","data-testid":`tools.${r}`,"aria-label":v,"data-value":r,onClick:()=>a("toolbar"),title:b,disabled:t,onTouchStart:P=>{xe(P),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:d.jsx(be,{icon:i})});case"toolbar-overflow":return d.jsx(qu,{"aria-label":s,children:d.jsx(ce,{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 Ot(u)}}function W({actionId:t="",...e}){const r=Ea()[t];return r?d.jsx(Ht,{...r,...e}):null}const K$=w.createContext(null);function Yae({overrides:t,children:e}){const n=z(),r=Qt(),o=Ib(),s=w.useMemo(()=>{const i=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(l){if(n.isIn("select")){const c=n.root.getCurrent();c.exit({},c.id),c.enter({},c.id)}n.setCurrentTool("select"),r("select-tool",{source:l,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(l){n.setCurrentTool("hand"),r("select-tool",{source:l,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(l){n.setCurrentTool("eraser"),r("select-tool",{source:l,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(l){n.setCurrentTool("draw"),r("select-tool",{source:l,id:"draw"})}},...[...Jr.values].map(l=>({id:l,label:`tool.${l}`,meta:{geo:l},kbd:l==="rectangle"?"r":l==="ellipse"?"o":void 0,icon:"geo-"+l,onSelect(c){n.run(()=>{n.setStyleForNextShapes(Jr,l),n.setCurrentTool("geo"),r("select-tool",{source:c,id:`geo-${l}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(l){n.setCurrentTool("arrow"),r("select-tool",{source:l,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(l){n.setCurrentTool("line"),r("select-tool",{source:l,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(l){n.setCurrentTool("frame"),r("select-tool",{source:l,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(l){n.setCurrentTool("text"),r("select-tool",{source:l,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(l){o.insertMedia(),r("select-tool",{source:l,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(l){n.setCurrentTool("note"),r("select-tool",{source:l,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(l){n.setCurrentTool("laser"),r("select-tool",{source:l,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(l){o.addDialog({component:g$}),r("select-tool",{source:l,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(l){n.setCurrentTool("highlight"),r("select-tool",{source:l,id:"highlight"})}}];i.push();const a=Object.fromEntries(i.map(l=>[l.id,l]));return t?t(n,a,o):a},[t,n,r,o]);return d.jsx(K$.Provider,{value:s,children:e})}function Eb(){const t=w.useContext(K$);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Ln({toolId:t="",...e}){const r=Eb()[t];return r?d.jsx(Ht,{...r,...e}):null}function Xae({children:t}){const e=z();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:qae}=Math,_l=qae+1e-4;function W$(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 y=0;y<t.length;y++){v=t[y];const{point:S,vector:b}=t[y],P=v.vector.dpr(u),C=(y<t.length-1?t[y+1]:t[y]).vector,_=y<t.length-1?C.dpr(v.vector):1,E=P<0&&!m,k=_!==null&&_<.2;if(E||k){if(_>-.62&&i-v.runningLength>v.radius){const T=u.clone().mul(v.radius);u.clone().cpr(C)<0?(f=x.Add(S,T),g=x.Sub(S,T)):(f=x.Sub(S,T),g=x.Add(S,T)),l.push(f),c.push(g)}else{const T=u.clone().mul(v.radius).per(),j=x.Sub(v.input,T);for(let $=1/13,M=0;M<1;M+=$)f=x.RotWith(j,v.input,_l*M),l.push(f),g=x.RotWith(j,v.input,_l+_l*-M),c.push(g)}h=f,p=g,k&&(m=!0);continue}if(m=!1,v===o||v===s){const T=x.Per(b).mul(v.radius);l.push(x.Sub(S,T)),c.push(x.Add(S,T));continue}const D=x.Lrp(C,b,_).per().mul(v.radius);f=x.Sub(S,D),(y<=1||x.Dist2(h,f)>a)&&(l.push(f),h=f),g=x.Add(S,D),(y<=1||x.Dist2(p,g)>a)&&(c.push(g),p=g),u=b}return{left:l,right:c}}function kb(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}=W$(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 _=1/13,E=_;E<=1;E+=_)C.push(x.RotWith(P,m,_l*2*E));return C}const y=[];if(!(h||p&&t.length===1))if(i)for(let P=1/8,C=P;C<=1;C+=P){const _=x.RotWith(g[0],m,_l*C);y.push(_)}else{const P=x.Sub(f[0],g[0]),C=x.Mul(P,.5),_=x.Mul(P,.51);y.push(x.Sub(m,C),x.Sub(m,_),x.Add(m,_),x.Add(m,C))}const S=[],b=c.vector.clone().per().neg();if(p||h&&t.length===1)S.push(v);else if(a){const P=x.Add(v,x.Mul(b,c.radius));for(let C=1/29,_=C;_<1;_+=C)S.push(x.RotWith(P,v,_l*3*_))}else S.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(S,g.reverse(),y)}const Zae=.025,Qae=.01;function Uo(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 y=i[0];for(;y&&!(y.z>=Zae);)i.shift(),y=i[0]}if(!o){let y=i[i.length-1];for(;y&&!(y.z>=Qae);)i.pop(),y=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 y=i[1];i=i.slice(0,-1);for(let S=1;S<5;S++){const b=x.Lrp(i[0],y,S/4);b.z=(i[0].z+(y.z-i[0].z))*S/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 y=1,S=i.length;y<S;y++)g=!s||e.last&&y===S-1?i[y].clone():i[y].clone().lrp(f.point,1-s),!f.point.equals(g)&&(m=x.Dist(g,f.point),p+=m,!(y<4&&p<r)&&(f={input:i[y],point:g,pressure:o?.5:i[y].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 y=Math.max(.5,...h.map(S=>S.pressure));h.forEach(S=>S.pressure=y)}return h}const{min:Ns}=Math,xS=.275;function xm(t,e){const{size:n=16,thinning:r=.5,simulatePressure:o=!0,easing:s=v=>v,start:i={},end:a={}}=e,{easing:l=Dt.easeOutQuad}=i,{easing:c=Dt.easeOutCubic}=a,u=t[t.length-1].runningLength;let h,p=t[0].pressure,f;if(!o&&u<n){const v=t.reduce((y,S)=>Math.max(y,S.pressure),.5);return t.forEach(y=>{y.pressure=v,y.radius=n*s(.5-r*(.5-y.pressure))}),t}else{let v;for(let y=0,S=t.length;y<S&&(f=t[y],!(f.runningLength>n*5));y++){const b=Ns(1,f.distance/n);if(o){const P=Ns(1,1-b);v=Ns(1,p+(P-p)*(b*xS))}else v=Ns(1,p+(f.pressure-p)*.5);p=p+(v-p)*.5}for(let y=0;y<t.length;y++){if(f=t[y],r){let{pressure:S}=f;const b=Ns(1,f.distance/n);if(o){const P=Ns(1,1-b);S=Ns(1,p+(P-p)*(b*xS))}else S=Ns(1,p+(S-p)*(b*xS));f.radius=n*s(.5-r*(.5-S)),p=S}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:y}=f,S=y<g?l(y/g):1,b=u-y<m?c((u-y)/m):1;f.radius=Math.max(.01,f.radius*Math.min(S,b))}return t}function Jae(t,e={}){return kb(xm(Uo(t,e),e),e)}function PE({scribble:t,zoom:e,color:n,opacity:r,className:o}){if(!t.points.length)return null;const s=Jae(t.points,{size:t.size/e,start:{taper:t.taper,easing:Dt.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=S1(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 ele=({bounds:t,rotation:e})=>{const n=z();return U("should display",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[n])?d.jsx(Ej,{bounds:t,rotation:e}):null};function tle({size:t,width:e,height:n,hideAlternateHandles:r}){const o=N(t/3),s=o/2;return d.jsxs("svg",{className:"tl-overlays__item",children:[d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
336
- ${N(0-s)},${N(t)}
337
- ${N(0-s)},${N(0-s)}
338
- ${N(t)},${N(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:N(e/2-t),y1:N(0-s),x2:N(e/2+t),y2:N(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:`
339
- ${N(e-t)},${N(0-s)}
340
- ${N(e+s)},${N(0-s)}
341
- ${N(e+s)},${N(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:N(e+s),y1:N(n/2-t),x2:N(e+s),y2:N(n/2+t),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
342
- ${N(e+s)},${N(n-t)}
343
- ${N(e+s)},${N(n+s)}
344
- ${N(e-t)},${N(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:N(e/2-t),y1:N(n+s),x2:N(e/2+t),y2:N(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:`
345
- ${N(0+t)},${N(n+s)}
346
- ${N(0-s)},${N(n+s)}
347
- ${N(0-s)},${N(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:N(0-s),y1:N(n/2-t),x2:N(0-s),y2:N(n/2+t),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const nle=qt(function({bounds:e,rotation:n}){const r=z(),o=w.useRef(null),s=wr(),i=bo("top"),a=bo("right"),l=bo("bottom"),c=bo("left"),u=bo("top_left"),h=bo("top_right"),p=bo("bottom_right"),f=bo("bottom_left"),g=r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,v=r.getOnlySelectedShape(),y=v&&r.isShapeOrAncestorLocked(v),S=v?r.getShapeUtil(v).expandSelectionOutlinePx(v):0;if(ec(o,e==null?void 0:e.x,e==null?void 0:e.y,1,r.getSelectionRotation(),{x:-S,y:-S}),v&&r.isShapeHidden(v)||!e)return null;e=e.clone().expandBy(S).zeroFix();const b=r.getZoomLevel(),P=r.getInstanceState().isChangingStyle,C=e.width,_=e.height,E=8/b,k=C<E*2,D=_<E*2,T=C<E*4,j=_<E*4,$=C<E*5,M=_<E*5,O=m?1.75:1,F=6/b*O,B=(T?F/2:F)*(O*.75),K=(j?F/2:F)*(O*.75),R=(v?!r.getShapeUtil(v).hideSelectionBoundsFg(v):!0)&&!P;let H=R&&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")||R&&r.isIn("select.resizing")&&v&&r.isShapeOfType(v,"text");v&&H&&Ge.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,he=!m&&!(k||D)&&(ee||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!y,ue=m&&(!T||!j)&&(ee||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!y,ke=ee&&(v?r.getShapeUtil(v).canResize(v)&&!r.getShapeUtil(v).hideResizeHandles(v):!0)&&!Y&&!y,se=k||D,We=k&&D,Fe=$||M,ot=ke||Y,$e=!he,lt=!ee||!ue,Ue=!ee||!ot,er=!ee||!ot||se,$t=!ee||!ot||se,On=!ee||!ot||We&&!Y;let vt=!0,Jt=!0;if(Y)vt=Fe,Jt=Fe;else if(ke){vt=se||We||m;const js=m&&v&&v.type==="text";Jt=vt&&!js}const Xo=Math.min(24/b,_-K*3),cc=ee&&m&&v&&r.isShapeOfType(v,"text")&&Xo*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:N(C),height:N(_)}),d.jsx(Dh,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:F,corner:"top_left_rotate",cursor:g?nr("nwse-rotate",n):void 0,isHidden:$e}),d.jsx(Dh,{"data-testid":"selection.rotate.top-right",cx:C+F*3,cy:0,targetSize:F,corner:"top_right_rotate",cursor:g?nr("nesw-rotate",n):void 0,isHidden:$e}),d.jsx(Dh,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:_+F*3,targetSize:F,corner:"bottom_left_rotate",cursor:g?nr("swne-rotate",n):void 0,isHidden:$e}),d.jsx(Dh,{"data-testid":"selection.rotate.bottom-right",cx:C+F*3,cy:_+F*3,targetSize:F,corner:"bottom_right_rotate",cursor:g?nr("senw-rotate",n):void 0,isHidden:$e}),d.jsx(ole,{"data-testid":"selection.rotate.mobile",cx:T?-F*1.5:C/2,cy:T?_/2:-F*1.5,size:E,isHidden:lt}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":vt}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:N(0-(j?K*2:K)),width:N(C),height:N(Math.max(1,K*2)),style:g?{cursor:nr("ns-resize",n)}:void 0,...i}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Jt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:N(C-(T?0:B)),y:0,height:N(_),width:N(Math.max(1,B*2)),style:g?{cursor:nr("ew-resize",n)}:void 0,...a}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":vt}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:N(_-(j?0:K)),width:N(C),height:N(Math.max(1,K*2)),style:g?{cursor:nr("ns-resize",n)}:void 0,...l}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Jt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:N(0-(T?B*2:B)),y:0,height:N(_),width:N(Math.max(1,B*2)),style:g?{cursor:nr("ew-resize",n)}:void 0,...c}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Ue}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:N(0-(T?B*2:B*1.5)),y:N(0-(j?K*2:K*1.5)),width:N(B*3),height:N(K*3),style:g?{cursor:nr("nwse-resize",n)}:void 0,...u}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":er}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:N(C-(T?0:B*1.5)),y:N(0-(j?K*2:K*1.5)),width:N(B*3),height:N(K*3),style:g?{cursor:nr("nesw-resize",n)}:void 0,...h}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":On}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:N(C-(T?B:B*1.5)),y:N(_-(j?K:K*1.5)),width:N(B*3),height:N(K*3),style:g?{cursor:nr("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:N(0-(T?B*3:B*1.5)),y:N(_-(j?0:K*1.5)),width:N(B*3),height:N(K*3),style:g?{cursor:nr("nesw-resize",n)}:void 0,...f}),ke&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.resize.top-left",className:le("tl-corner-handle",{"tl-hidden":Ue}),"aria-label":"top_left handle",x:N(0-E/2),y:N(0-E/2),width:N(E),height:N(E)}),d.jsx("rect",{"data-testid":"selection.resize.top-right",className:le("tl-corner-handle",{"tl-hidden":er}),"aria-label":"top_right handle",x:N(C-E/2),y:N(0-E/2),width:N(E),height:N(E)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:le("tl-corner-handle",{"tl-hidden":On}),"aria-label":"bottom_right handle",x:N(C-E/2),y:N(_-E/2),width:N(E),height:N(E)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:le("tl-corner-handle",{"tl-hidden":$t}),"aria-label":"bottom_left handle",x:N(0-E/2),y:N(_-E/2),width:N(E),height:N(E)})]}),cc&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:N(0-E/4),y:N(_/2-Xo/2),rx:E/4,width:N(E/2),height:N(Xo)}),d.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:E/4,x:N(C-E/4),y:N(_/2-Xo/2),width:N(E/2),height:N(Xo)})]}),Y&&d.jsx(tle,{size:E,width:C,height:_,hideAlternateHandles:Fe})]})})}),Dh=function({cx:e,cy:n,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=bo(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:N(e-r*3),y:N(n-r*3),width:N(Math.max(1,r*3)),height:N(Math.max(1,r*3)),cursor:s,...l})},rle=Math.sqrt(Math.PI),ole=function({cx:e,cy:n,size:r,isHidden:o,"data-testid":s}){const i=bo("mobile_rotate"),a=z(),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/rle})]})};function sle(){const t=z();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(kj,{}):null}function qx(t,e,n){const{arrowheadStart:r,arrowheadEnd:o}=e.props,s=ul(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=Vf(t,e,"start"),h=Vf(t,e,"end"),p=t.getShapePageTransform(e);CE(a,s.start,p,h),CE(i,s.end,p,u);let f=0,g=0,m=0,v=0,y=dl*e.props.scale;const S=u&&h&&u.shape===h.shape,b=u&&h?Tb(t,u.shape.id,h.shape.id):"safe";b==="safe"&&u&&h&&!S&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(dl*e.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(dl*e.props.scale))));const P=x.Sub(a,i),C=x.Len(P)?P.uni():x.From(P),_=!x.Equals(C,c);S||(b!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(m=To[e.props.size]/2+("size"in u.shape.props?To[u.shape.props.size]/2:0),f=(Yf+m)*e.props.scale,y+=m*e.props.scale),b!=="end-contains-start"&&h&&o!=="none"&&!h.isExact&&(v=To[e.props.size]/2+("size"in h.shape.props?To[h.shape.props.size]/2:0),g=(Yf+v)*e.props.scale,y+=v*e.props.scale));const E=i.clone().add(C.clone().mul(f*(_?-1:1))),k=a.clone().sub(C.clone().mul(g*(_?-1:1)));x.DistMin(E,k,y)&&(f!==0&&g!==0?(f*=-1.5,g*=-1.5):f!==0?f*=-1:g!==0&&(g*=-1)),i.add(C.clone().mul(f*(_?-1:1))),a.sub(C.clone().mul(g*(_?-1:1))),_?(u&&h&&a.setTo(x.Add(i,C.clone().mul(-dl*e.props.scale))),l.setTo(x.Med(s.start,s.end))):l.setTo(x.Med(i,a));const D=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:D>0,length:D}}function CE(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?P1:VZ)(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 ile(t,e,n){const{arrowheadEnd:r,arrowheadStart:o}=e.props,s=e.props.bend;if(Math.abs(s)>Math.abs(e.props.bend*(dle*e.props.scale)))return qx(t,e,n);const i=ul(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=Vf(t,e,"start"),p=Vf(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,y=v?ud:aj,S=_E(f,g,m),b=x.Angle(S.center,f),P=x.Angle(S.center,g),C=y(b,P);if(S.length===0||S.size===0||!nI(S.length)||!nI(S.size))return qx(t,e,n);const _=f.clone(),E=g.clone(),k=m.clone(),D=t.getShapePageTransform(e);let T=0,j=0,$=dl*e.props.scale;if(h&&!h.isExact){const Y=q.applyToPoint(D,_),ee=q.applyToPoint(D,S.center),he=q.applyToPoint(D,E),ue=q.Inverse(h.transform),ke=q.applyToPoint(ue,Y),se=q.applyToPoint(ue,ee),We=q.applyToPoint(ue,he),{isClosed:Fe}=h,ot=Fe?_x:PI;let $e,lt=ot(se,S.radius,h.outline);if(lt){const Ue=se.angle(ke),er=se.angle(We),$t=y(Ue,er);lt=lt.filter(vt=>y(Ue,se.angle(vt))<=$t);const On=$t*.25;lt.sort(Fe?(vt,Jt)=>Math.abs(y(Ue,se.angle(vt))-On)<Math.abs(y(Ue,se.angle(Jt))-On)?-1:1:(vt,Jt)=>y(Ue,se.angle(vt))<y(Ue,se.angle(Jt))?-1:1),$e=lt[0]??(Fe?void 0:ke)}else $e=Fe?void 0:ke;if($e&&(_.setTo(t.getPointInShapeSpace(e,q.applyToPoint(h.transform,$e))),h.didIntersect=!0,o!=="none")){const Ue=To[e.props.size]/2+("size"in h.shape.props?To[h.shape.props.size]/2:0);T=(Yf+Ue)*e.props.scale,$+=Ue*e.props.scale}}if(p&&!p.isExact){const Y=q.applyToPoint(D,_),ee=q.applyToPoint(D,E),he=q.applyToPoint(D,S.center),ue=q.Inverse(p.transform),ke=q.applyToPoint(ue,Y),se=q.applyToPoint(ue,he),We=q.applyToPoint(ue,ee),Fe=p.isClosed,ot=Fe?_x:PI;let $e,lt=ot(se,S.radius,p.outline);if(lt){const Ue=se.angle(ke),er=se.angle(We),$t=y(Ue,er),On=$t*.75;lt=lt.filter(vt=>y(Ue,se.angle(vt))<=$t),lt.sort(Fe?(vt,Jt)=>Math.abs(y(Ue,se.angle(vt))-On)<Math.abs(y(Ue,se.angle(Jt))-On)?-1:1:(vt,Jt)=>y(Ue,se.angle(vt))<y(Ue,se.angle(Jt))?-1:1),lt[0]?$e=lt[0]:$e=Fe?void 0:We}else $e=Fe?void 0:We;if($e&&(E.setTo(t.getPointInShapeSpace(e,q.applyToPoint(p.transform,$e))),p.didIntersect=!0,r!=="none")){const Ue=To[e.props.size]/2+("size"in p.shape.props?To[p.shape.props.size]/2:0);j=(Yf+Ue)*e.props.scale,$+=Ue*e.props.scale}}let M=x.Angle(S.center,_),O=x.Angle(S.center,E),F=y(M,O),B=F*S.radius;const K=_.clone(),R=E.clone();if(T!==0&&K.setTo(S.center).add(x.FromAngle(M+F*(T/B*(v?1:-1))).mul(S.radius)),j!==0&&R.setTo(S.center).add(x.FromAngle(O+F*(j/B*(v?-1:1))).mul(S.radius)),x.DistMin(K,R,$)&&(T!==0&&j!==0?(T*=-1.5,j*=-1.5):T!==0?T*=-2:j!==0&&(j*=-2)),T!==0&&_.setTo(S.center).add(x.FromAngle(M+F*(T/B*(v?1:-1))).mul(S.radius)),j!==0&&E.setTo(S.center).add(x.FromAngle(O+F*(j/B*(v?-1:1))).mul(S.radius)),h&&p&&!h.isExact&&!p.isExact){M=x.Angle(S.center,_),O=x.Angle(S.center,E),F=y(M,O),B=F*S.radius;const Y=Tb(t,h.shape.id,p.shape.id);Y==="double-bound"&&B<30?(_.setTo(f),E.setTo(g),k.setTo(m)):Y==="safe"&&(h&&!h.didIntersect&&_.setTo(f),(p&&!p.didIntersect||y(b,M)>y(b,O))&&E.setTo(S.center).add(x.FromAngle(M+F*(Math.min(.9,dl*e.props.scale/B)*(v?1:-1))).mul(S.radius)))}ale(S.center,S.radius,_,E,k,C,v),_.equals(E)&&(_.setTo(k.clone().addXY(1,1)),E.setTo(k.clone().subXY(1,1))),f.setTo(_),g.setTo(E),m.setTo(k);const H=_E(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:S,bodyArc:H,isValid:H.length!==0&&isFinite(H.center.x)&&isFinite(H.center.y)}}function _E(t,e,n){const r=f1(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=(Ne-c)*(s?1:-1),p=h*o;return{center:r,radius:o,size:h,length:p,largeArcFlag:u,sweepFlag:s}}function ale(t,e,n,r,o,s,i){const a=x.Angle(t,n),l=x.Angle(t,r);let c=ud(a,l);if(i||(c=Ne-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 lle=8;function cle(t){return Math.abs(t.props.bend)<lle*t.props.scale}function Vf(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 $r?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function IE(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 Un(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 ule=YV("arrow info",(t,e)=>{const n=Un(t,e);return cle(e)?qx(t,e,n):ile(t,e,n)});function ko(t,e){const n=typeof e=="string"?e:e.id;return ule.get(t,n)}function ul(t,e,n){var a,l;const r=t.getShapePageTransform(e),o=Tb(t,(a=n.start)==null?void 0:a.toId,(l=n.end)==null?void 0:l.toId),s=n.start?IE(t,r,n.start,o==="double-bound"||o==="start-contains-end"):x.From(e.props.start),i=n.end?IE(t,r,n.end,o==="double-bound"||o==="end-contains-start"):x.From(e.props.end);return{start:s,end:i}}function Dc(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 gp(t,e,n){const r=t.getBindingsFromShape(e,"arrow").filter(o=>o.props.terminal===n);t.deleteBindings(r)}const dl=10,Yf=10,dle=10,To={s:2,m:3.5,l:5,xl:10};function Tb(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 mp extends dp{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const n=this.editor.getShape(e.fromId);n&&wS(this.editor,n)}onAfterChange({bindingAfter:e}){const n=this.editor.getShape(e.fromId);n&&wS(this.editor,n)}onAfterChangeFromShape({shapeAfter:e}){wS(this.editor,e)}onAfterChangeToShape({binding:e}){G$(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const n=this.editor.getShape(e.fromId);n&&Xf({editor:this.editor,arrow:n,terminal:e.props.terminal})}}I(mp,"type","arrow"),I(mp,"props",EA),I(mp,"migrations",kA);function G$(t,e){var v;const n=t.getShape(e);if(!n)return;const r=Un(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 y=(v=i||a)==null?void 0:v.parentId;y&&y===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(y=>t.getShape(y)).filter(y=>y.index>f.index);if(m.length){const y=m.find(S=>S.type!=="arrow");if(u.index>f.index&&(!y||u.index<y.index))return;g=$u(f.index,m[0].index)}else g=Io(f.index);g!==u.index&&t.updateShapes([{id:e,type:"arrow",index:g}])}function wS(t,e){const n=Un(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)&&Xf({editor:t,arrow:e,terminal:r,unbind:!0})}G$(t,e.id)}function Xf({editor:t,arrow:e,terminal:n,unbind:r=!1,useHandle:o=!1}){const s=ko(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=gd(s.handleArc.center,x.Add(p,f),s.handleArc.center,s.handleArc.radius);Le((g==null?void 0:g.length)===1);const m=x.Dist(p,g[0])*Math.sign(e.props.bend);ui(m,c.props.bend)||(c.props.bend=m)}t.updateShape(c),r&&gp(t,e,n)}const V$=[mp],fn={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},pn={s:2,m:3.5,l:5,xl:10},Ll={s:18,m:24,l:36,xl:44},ys={s:18,m:22,l:26,xl:32},hle={s:18,m:20,l:24,xl:28},Cs={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},ple=20,qf=4.25,Er=16;function fle(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}}/*!
348
- * MIT License
349
- * Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
350
- * Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
351
- */const hl=" ",vn=class vn{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)||vn.insertTextFirefox(e,n),o===r.body?e.blur():o instanceof HTMLElement&&o!==e&&o.focus()}static set(e,n){e.select(),vn.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=vn.getSelection(e);vn.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 vn.insert(e,l),e.selectionStart=i,o+=l.length-a,l})}static findLineEnd(e,n){const r=e.lastIndexOf(`
352
- `,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(`
353
- `,n-1)+1,c=e.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${hl}`),h=u.length-c.length;e.setSelectionRange(l,r-1),vn.insert(e,u),e.setSelectionRange(n+1,r+h)}else vn.insert(e,hl)}static unindent(e){const{selectionStart:n,selectionEnd:r,value:o}=e,s=o.lastIndexOf(`
354
- `,n-1)+1,i=vn.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),vn.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=Rh(e)??0,s=Rh(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(`
355
- `,o-1)+1,u=r.slice(c,s-1),p=u.replace(/^|\n/g,`$&${hl}`).length-u.length;n&&n.setBaseAndExtent(e,o+1,e,s+p)}else{const c=window.getSelection();e.innerText=r.slice(0,o)+hl+r.slice(o),c==null||c.setBaseAndExtent(e,o+1,e,o+2)}}static unindentCE(e){const n=window.getSelection(),r=e.innerText,o=Rh(e)??0,s=Rh(e)??0,i=r.lastIndexOf(`
356
- `,o-1)+1,a=vn.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(vn.fixNewLines,`
357
- `)}static normalizeTextForDom(e){return e.replace(vn.fixNewLines,`
358
- `).split(`
359
- `).map(n=>n||" ").join(`
360
- `)}};I(vn,"fixNewLines",/\r?\n|\r/g);let $l=vn;function Rh(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 gle=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function Y$(t){return gle.test(t)}function mle(t){return t.replace(/\t/g,hl)}function yle(t){const e=t.split(`
361
- `);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(`
362
- `)}const X$={"&amp;":"&","&quot;":'"',"&apos;":"'","&#34;":'"',"&#38;":"&","&#39;":"'","&#8211;":"–","&#8212;":"—","&#8216;":"‘","&#8217;":"’","&#8220;":"“","&#8221;":"”","&#8230;":"…"},Sle=new RegExp(Object.keys(X$).join("|"),"g");function vle(t){return t.replace(Sle,e=>X$[e])}function xle(t){return t.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function wle(t){return xle(yle(mle(t)))}function ble(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"}),Le(c||u,`File type not allowed: ${a.type}`),a.size>n&&s.addToast({title:i("assets.files.size-too-big"),severity:"error"}),Le(a.size<=n,`File size too big: ${(a.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`);const h=jC(await a.arrayBuffer());l=l??Vs.createId(h);const p=await EE(a,l,c,u);if(isFinite(e)){const f={w:p.props.w,h:p.props.h},g=fle(f,{w:e,h:e});f!==g&&ar.isStaticImageType(a.type)&&(p.props.w=g.w,p.props.h=g.h)}return p.props.src=await t.uploadAsset(p,a),Vs.create(p)}),t.registerExternalAssetHandler("url",async({url:a})=>{var c,u,h,p,f;let l;try{const m=await(await Lo(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:Vs.createId(Gv(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");kE(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=Ke(),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=jC(await f.arrayBuffer()),y=Vs.createId(v),S=await EE(f,y,g,m);let b;g&&(b=t.createTemporaryAssetPreview(y,f)),h.push(S),p.push({asset:S,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}})),kE(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=wle(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 y=h.split(`
363
- `).length>1,S=Y$(h);y&&(v=y?S?"end":"start":"middle");const b=t.textMeasure.measureText(h,{...fn,fontFamily:Cs[u.font],fontSize:Ll[u.size],maxWidth:null}),P=Math.min(y?t.getViewportPageBounds().width*.9:920,Math.max(200,t.getViewportPageBounds().width*.9));if(b.w>P){const C=t.textMeasure.measureText(h,{...fn,fontFamily:Cs[u.font],fontSize:Ll[u.size],maxWidth:P});f=C.w,g=C.h,m=!1,v=S?"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:Ke(),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=Vs.createId(Gv(l)),f=Ple(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 EE(t,e,n,r){let o=t.type;t.type==="video/quicktime"&&(o="video/mp4");const s=n?await ar.getImageSize(t):await ar.getVideoSize(t),i=await ar.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 kE(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:Ke(),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:Ke(),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)),q$(t,n)}),o.map(s=>s.id)}function q$(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}}))}if(r=t.getSelectionPageBounds(),r&&t.getInstanceState().isGridMode){const o=t.getDocumentSettings().gridSize,s=new x(r.minX,r.minY),i=s.clone().snapToGrid(o),a=x.Sub(s,i);t.updateShapes(t.getSelectedShapes().map(l=>{const c={x:l.x-a.x,y:l.y-a.y};return{id:l.id,type:l.type,x:c.x,y:c.y}}))}r=t.getSelectionPageBounds(),r&&!n.contains(r)&&t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})}function Ple(t,e,n){const r={id:Ke(),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),q$(t,n)}),t.getShape(r.id)}var DS;let Cle=(DS=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.getIsReadonly())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}))}}},I(DS,"id","idle"),DS);var RS;let _le=(RS=class extends ie{constructor(){super(...arguments);I(this,"shape");I(this,"markId","");I(this,"preciseTimeout",-1);I(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 h;const{originPagePoint:n}=this.editor.inputs,r=Ke();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`);const o=io(n,this.editor);this.editor.createShape({id:r,type:"arrow",x:o.x,y:o.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const s=this.editor.getShape(r);if(!s)throw Error("expected shape");const i=this.editor.getShapeHandles(s);if(!i)throw Error("expected handles for arrow");const a=this.editor.getShapeUtil("arrow"),l=this.shape,c=i.find(p=>p.id==="start"),u=(h=a.onHandleDrag)==null?void 0:h.call(a,s,{handle:{...c,x:0,y:0},isPrecise:!0,initial:l});u&&this.editor.updateShapes([u]),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)}},I(RS,"id","pointing"),RS);class Zx extends ie{constructor(){super(...arguments);I(this,"shapeType","arrow")}static children(){return[Cle,_le]}}I(Zx,"id","arrow"),I(Zx,"initial","idle");class Mb extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"initialShape");I(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");I(this,"util",this.editor.getShapeUtil(this.shapeType));I(this,"isPen",!1);I(this,"isPenOrStylus",!1);I(this,"segmentMode","free");I(this,"didJustShiftClickToExtendPreviousShapeLine",!1);I(this,"pagePointWhereCurrentSegmentChanged",{});I(this,"pagePointWhereNextSegmentChanged",null);I(this,"lastRecordedPoint",{});I(this,"mergeNextPoint",!1);I(this,"currentLineLength",0);I(this,"markId",null)}onEnter(n){this.markId=null,this.info=n,this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.startShape()}onPointerMove(){const{inputs:n}=this.editor;if(this.isPen&&!n.isPen&&this.markId){this.editor.bailToMark(this.markId),this.startShape();return}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=pn[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<pn[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=Ke();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 y=Ut(v.points);if(!y)throw Error("Expected a previous last point!");let S;const b=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(v.type==="straight"){this.currentLineLength+=x.Dist(y,b),S={type:"straight",points:[{...y},b]};const C=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=q.applyToPoint(C,y)}else S={type:"straight",points:[b,f]};const P={id:o,type:this.shapeType,props:{segments:[...l,S]}};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(),y=v[v.length-1],S=Ut(y.points);if(!S)throw Error("No previous point!");const b={type:"free",points:[...x.PointsBetween(S,f,6).map(_=>({x:as(_.x),y:as(_.y),z:as(_.z)}))]},P=[...v,b];this.currentLineLength<pn[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:y,currentPagePoint:S}=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=!y,this.didJustShiftClickToExtendPreviousShapeLine=!1):P=!y;let C=this.editor.getPointInShapeSpace(a,S).toFixed().toJson(),_=!1,E;if((this.editor.user.getIsSnapMode()?!y:y)&&g.length>2){let T,j=8/this.editor.getZoomLevel();for(let $=0,M=l.length-2;$<M;$++){const O=l[$];if(!O)break;if(O.type==="free")continue;const F=O.points[0],B=Ut(O.points);if(!(F&&B))continue;const K=x.NearestPointOnLineSegment(F,B,C);if(x.DistMin(K,C,j)){T=K.toFixed().toJson(),j=x.Dist(K,C),E=O;break}}T&&(_=!0,C=T)}if(_&&E){const T=this.editor.getShapePageTransform(a),j=E.points[0],$=Ut(E.points);if(!$)throw Error("Expected a last point!");const M=q.applyToPoint(T,j),O=q.applyToPoint(T,$),F=q.applyToPoint(T,C);this.editor.snaps.setIndicators([{id:ze(),type:"points",points:[M,F,O]}])}else{if(this.editor.snaps.clearIndicators(),P){const T=x.Angle(v,S),$=Df(T,24)-T;b=x.RotWith(S,v,$)}else b=S;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 D={id:o,type:this.shapeType,props:{segments:g}};this.canClose()&&(D.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([D]);break}case"free":{const g=l.slice(),m=g[g.length-1],v=[...m.points];if(v.length&&this.mergeNextPoint){const{z:S}=v[v.length-1];v[v.length-1]={x:f.x,y:f.y,z:S?Math.max(S,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<pn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(g));const y={id:o,type:this.shapeType,props:{segments:g}};if(this.canClose()&&(y.props.isClosed=this.getIsClosed(g,s,i)),this.editor.updateShapes([y]),v.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const S=Ke(),b=this.editor.getShape(o).props;this.editor.createShapes([{id:S,type:this.shapeType,x:as(r.currentPagePoint.x),y:as(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(S)),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(){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)}}I(Mb,"id","drawing");var LS;let Z$=(LS=class extends ie{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(LS,"id","idle"),LS);class yp extends ie{constructor(){super(...arguments);I(this,"shapeType","draw")}static children(){return[Z$,Mb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}I(yp,"id","draw"),I(yp,"initial","idle"),I(yp,"isLockable",!1);class Qx extends Ox{constructor(){super(...arguments);I(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)&&Ile(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")}}I(Qx,"id","frame"),I(Qx,"initial","idle");function Ile(t,e,n){return e.includes(t.id)?!1:t.parentId===n.parentId}var $S;let Ele=($S=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.getIsReadonly())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")}},I($S,"id","idle"),$S);var FS;let kle=(FS=class extends ie{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=Ke(),o=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`),s=io(n,this.editor);this.editor.createShapes([{id:r,type:"geo",x:s.x,y:s.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(Jr),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=Ke();this.editor.markHistoryStoppingPoint(`creating_geo:${n}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,o=this.editor.getStyleForNextShape(Jr),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(Jr),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());const h=io(new x(i.x-c.x,i.y-c.y),this.editor);this.editor.select(n),this.editor.updateShape({id:i.id,type:"geo",x:h.x,y:h.y,props:{geo:this.editor.getStyleForNextShape(Jr),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},I(FS,"id","pointing"),FS);class Jx extends ie{constructor(){super(...arguments);I(this,"shapeType","geo")}static children(){return[Ele,kle]}}I(Jx,"id","geo"),I(Jx,"initial","idle");class Sp extends ie{constructor(){super(...arguments);I(this,"shapeType","highlight")}static children(){return[Z$,Mb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}I(Sp,"id","highlight"),I(Sp,"initial","idle"),I(Sp,"isLockable",!1);var NS;let Tle=(NS=class extends ie{constructor(){super(...arguments);I(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")}},I(NS,"id","idle"),NS);const TE=2;var zS;let Mle=(zS=class extends ie{constructor(){super(...arguments);I(this,"shape",{});I(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(g=>g.type==="vertex").sort(cn),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=io(h,this.editor),f=tt(this.shape.props.points);if(x.DistMin(l,c,TE)||x.DistMin(p,l,TE))f[l.id]={id:l.id,index:l.index,x:p.x,y:p.y};else{const g=Io(l.index);f[g]={id:g,index:g,x:p.x,y:p.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:f}}])}else{const i=Ke();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${i}`);const a=io(o,this.editor);this.editor.createShapes([{id:i,type:"line",x:a.x,y:a.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()}},I(zS,"id","pointing"),zS);class e0 extends ie{constructor(){super(...arguments);I(this,"shapeType","line")}static children(){return[Tle,Mle]}}I(e0,"id","line"),I(e0,"initial","idle");var BS;let Ale=(BS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(BS,"id","idle"),BS);const jle=0,He=200,wm=new x(He/2,He/2),Q$=10,Ole=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 Dle(t,e){if(e===1)return Ole(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 J$(t,e,n,r,o,s){return Object.fromEntries(Dle(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 e5(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(J$(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 me(a)}function t5(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=Ke();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(wm.clone().mul(c.props.scale),r)));t.updateShape({id:l,type:"note",x:u.x,y:u.y}),s=t.getShape(l)}return Lle(t),s}const Rle=16;function Lle(t){const e=t.getSelectionPageBounds(),n=t.getViewportPageBounds();if(e&&!n.contains(e)){const r=e.clone().expandBy(Rle/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})}}var US;let $le=(US=class extends ie{constructor(){super(...arguments);I(this,"dragged",!1);I(this,"info",{});I(this,"markId","");I(this,"shape",{})}onEnter(){const{editor:n}=this,r=Ke();this.markId=n.markHistoryStoppingPoint(`creating_note:${r}`);const o=this.editor.inputs.originPagePoint.clone(),s=Fle(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=Nle(this.editor,r,o)}onPointerMove(n){this.editor.inputs.isDragging&&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.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)}},I(US,"id","pointing"),US);function Fle(t,e,n){let r=Q$/t.getZoomLevel(),o;for(const s of e5(t,0,n,0)){const i=x.Sub(e,s),a=i.len();a<r&&(r=a,o=i)}return o}function Nle(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,s=io(new x(r.x-o.width/2,r.y-o.height/2),t);return t.updateShapes([{id:e,type:"note",x:s.x,y:s.y}]),t.getShape(e)}class t0 extends ie{constructor(){super(...arguments);I(this,"shapeType","note")}static children(){return[Ale,$le]}}I(t0,"id","note"),I(t0,"initial","idle");function zle(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 ds=kT(zle,32);var HS;let Ble=(HS=class extends ie{onPointerMove(e){switch(e.target){case"shape":case"canvas":ds(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){ds.cancel()}onKeyDown(e){var n;if(e.key==="Enter"){if(this.editor.getIsReadonly())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")}},I(HS,"id","idle"),HS);var KS;let Ule=(KS=class extends ie{constructor(){super(...arguments);I(this,"shape");I(this,"markId","");I(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=Ke();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)}})}}onPointerUp(){this.complete()}onComplete(){this.cancel()}onCancel(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.editor.markHistoryStoppingPoint("creating text shape");const n=Ke(),{originPagePoint:r}=this.editor.inputs;this.createTextShape(n,r,!0,20)&&(this.editor.select(n),this.editor.setEditingShape(n))}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,Fn(i.parentId)){const h=this.editor.getShapeParentTransform(i);l.rot(-h.rotation())}const c=i.x+l.x,u=i.y+l.y;if(this.editor.getInstanceState().isGridMode){const h=new x(c,u),p=io(h,this.editor),f=x.Sub(h,p);this.editor.updateShape({...i,x:c-f.x,y:u-f.y})}else this.editor.updateShape({...i,x:c,y:u});return i}},I(KS,"id","pointing"),KS);class n0 extends ie{constructor(){super(...arguments);I(this,"shapeType","text")}static children(){return[Ble,Ule]}}I(n0,"id","text"),I(n0,"initial","idle");const Hle=[n0,yp,Jx,t0,e0,Qx,Zx,Sp];function zr(){return ks({isDarkMode:xd()})}function bm(t){return{key:`${$o.id}:${t}`,async getElement(){const e=Kle(t);if(!e)return null;const{url:n,fontFaceRule:r}=e,o=await(await Lo(n)).blob(),s=await Zr.blobToDataUrl(o),i=r.replace(n,s);return d.jsx("style",{children:i})}}}function Kle(t){const e=PA[t];for(const n of document.fonts)if(e.includes(n.family)&&"$$_url"in n&&typeof n.$$_url=="string"&&"$$_fontface"in n&&typeof n.$$_fontface=="string")return{url:n.$$_url,fontFaceRule:n.$$_fontface};return null}function Ab(t){return{key:`${$o.id}:${t}`,async getElement(){return t!=="pattern"?null:d.jsx(Wle,{})}}}function Wle(){const t=Ob(),e=Jl(),n=zr(),r=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:e,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:r*1,y1:r*3,x2:r*3,y2:r*1}),d.jsx("line",{x1:r*5,y1:r*7,x2:r*7,y2:r*5}),d.jsx("line",{x1:r*9,y1:r*11,x2:r*11,y2:r*9})]})]}),d.jsx("pattern",{id:t(1,n.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:n.solid,mask:`url(#${e})`})})]})}function jb(){return{key:`${$o.id}:pattern`,component:Xle}}const Xc=8,ME=(t,e,n)=>new Promise((r,o)=>{const s=Xc*e*t,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?Ef.darkMode.solid:Ef.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||bt.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 bS=null;function Gle(){return bS||(bS={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)})}),bS}function n5(t){return Math.ceil(Math.log2(Math.max(1,t)))}function Ob(){const t=ro("hash_pattern");return w.useCallback((e,n)=>{const r=n5(e);return d1(t,`${n}_${r}`)},[t])}function r5(t){const e=[],r=n5(t);for(let o=0;o<=r;o++)e.push(Math.pow(2,o));return e}function Vle(t){const e=Gle();return r5(t).flatMap(n=>[{zoom:n,url:e.white,theme:"light"},{zoom:n,url:e.black,theme:"dark"}])}function Yle(){const t=z(),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(()=>Vle(n)),a=Ob();return w.useEffect(()=>{const c=Promise.all(r5(n).flatMap(h=>[ME(e,h,!1).then(p=>({zoom:h,theme:"light",url:URL.createObjectURL(p)})),ME(e,h,!0).then(p=>({zoom:h,theme:"dark",url:URL.createObjectURL(p)}))]));let u=!1;return c.then(h=>{u||(i(h),o(!0))}),()=>{u=!0,o(!1),c.then(h=>{for(const{url:p}of h)URL.revokeObjectURL(p)})}},[e,n]),{defs:d.jsx(d.Fragment,{children:s.map(c=>{const u=a(c.zoom,c.theme);return d.jsx("pattern",{id:u,width:Xc,height:Xc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:c.url,width:Xc,height:Xc})},u)})}),isReady:r}}function Xle(){const t=z(),e=w.useRef(null),{defs:n,isReady:r}=Yle();return w.useEffect(()=>{if(r&&Ge.isSafari){const o=o5(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 o5(t){return t.classList.contains("tl-html-layer")?t:t.parentElement?o5(t.parentElement):null}const on=Te.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(qle,{theme:e,color:r,fill:o,d:n,scale:s})}});function qle({d:t,color:e,theme:n}){const r=z(),o=md(),s=U("zoomLevel",()=>r.getZoomLevel(),[r]),i=Ob(),a=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:n[e].pattern,d:t}),d.jsx("path",{fill:o?`url(#${i(1,n.id)})`:a?n[e].semi:`url(#${i(s,n.id)})`,d:t})]})}function Zle(t){return t.replace(/\s/g," ")}function r0(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:`
364
- `},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,unicodeBidi:"plaintext",children:Zle(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 Qle(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 Jle(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=z(),u=zr(),h={fontSize:t,fontFamily:PA[e],textAlign:n,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:fn.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=Qle(n,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const g=r0(c,p,h);let m=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,m=r0(c,p,h)),d.jsxs(d.Fragment,{children:[m,g]})}const ece=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:_t,onContextMenu:e?_t:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:xe})});function tce(t,e,n){const r=z(),o=w.useRef(null),s=U("isEditing",()=>r.getEditingShapeId()===t,[r]),i=U("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);w.useEffect(()=>{function u(h){var p;h.shapeId===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()),Ge.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=$l.normalizeText(u.currentTarget.value);const p=h.replace(/\t/g,hl);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({...lr(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(t)}),_t(u)},[r,t]);return{rInput:o,handleFocus:Ru,handleBlur:Ru,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:_t,isEmpty:n.trim().length===0,isEditing:s,isEditingAnything:i}}const Cm=Te.memo(function({shapeId: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:y}){const{rInput:S,isEmpty:b,isEditing:P,isEditingAnything:C,..._}=tce(e,n,r),[E,k]=w.useState(r);w.useEffect(()=>{P||k(r)},[P,r]);const D=$l.normalizeTextForDom(r),T=D.length>0,j=Jle(l);if(!P&&!T)return null;const $=g||"tl-text";return d.jsx("div",{className:`${$}-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"||j?"center":l,alignItems:c==="middle"?"center":c,padding:p,...m},children:d.jsxs("div",{className:`${$}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(v||0),color:o,width:v?Math.ceil(v):void 0,height:y?Math.ceil(y):void 0},children:[d.jsx("div",{className:`${$} tl-text tl-text-content`,dir:"auto",children:D.split(`
365
- `).map((M,O)=>d.jsx("div",{dir:"auto",children:M},O))}),(C||h)&&d.jsx(ece,{ref:S,text:r,isEditing:P,..._,handleKeyDown:f??_.handleKeyDown},E)]})})}),nce=new Ro;function rce(t){return nce.get(t,()=>t.store.createComputedCache("arrowLabelSize",e=>{const n=ko(t,e);let r=0,o=0;const s=n.isStraight?new us({start:x.From(n.start.point),end:x.From(n.end.point)}):new ll({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=o0(e),{w:l,h:c}=t.textMeasure.measureText(e.props.text,{...fn,fontFamily:Cs[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,{...fn,fontFamily:Cs[e.props.font],fontSize:a,maxWidth:r});r=h,o=p}}return new x(r,o).addScalar(qf*2*e.props.scale)}))}function Db(t,e){return e.props.text.trim()===""?new x(0,0).addScalar(qf*2*e.props.scale):rce(t).get(e.id)??new x(0,0)}function s5(t){const e=pn[t.props.size];return(ple+(e-pn.s)*2+(e===pn.xl?20:0))*t.props.scale}function oce(t,e,n){const r=Db(t,e),o=s5(e),s=x.Nudge(n.start.point,n.end.point,o),i=x.Nudge(n.end.point,n.start.point,o),a=P1(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 sce(t,e,n){const r=Db(t,e),o=s5(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=da(n.bodyArc.center,n.bodyArc.radius,a),u=da(n.bodyArc.center,n.bodyArc.radius,l),h=[],p=OE(n.bodyArc.center,n.bodyArc.radius,a,l,s,Z.FromCenter(c,r).corners);h.push(new xt({points:Z.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const f=OE(n.bodyArc.center,n.bodyArc.radius,a,l,s,Z.FromCenter(u,r).corners);h.push(new xt({points:Z.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const E of[...p??[],...f??[],c,u])h.push(new L1({x:E.x-3,y:E.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const g=(p&&DE(n.start.point,p))??n.middle,m=(f&&DE(n.end.point,f))??n.middle,v=x.Angle(n.bodyArc.center,n.start.point),y=x.Angle(n.bodyArc.center,n.end.point),S=x.Angle(n.bodyArc.center,g),b=x.Angle(n.bodyArc.center,m);if(Ys(v,S,s)>Ys(v,b,s))return{start:.5,end:.5,dbg:h};const P=Ys(v,y,s),C=Ys(v,S,s)/P,_=Ys(v,b,s)/P;return{start:C,end:_,dbg:h}}function vp(t,e){let n;const r=[],o=ko(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=oce(t,e,o),l=jE(t,e,a,s);n=x.Lrp(o.start.point,o.end.point,l)}else{const a=sce(t,e,o);a.dbg&&r.push(...a.dbg);const l=jE(t,e,a,s),c=ice(x.Angle(o.bodyArc.center,o.start.point),x.Angle(o.bodyArc.center,o.end.point),Math.sign(e.props.bend),l);n=da(o.bodyArc.center,o.bodyArc.radius,c)}const i=Db(t,e);return{box:Z.FromCenter(n,i),debugGeom:r}}function jE(t,e,n,r){const{hasEndArrowhead:o,hasEndBinding:s,hasStartBinding:i,hasStartArrowhead:a}=r,l=c5(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 OE(t,e,n,r,o,s){const i=_x(t,e,s),a=Ys(n,r,o);return i==null?void 0:i.filter(l=>{const c=Ys(n,x.Angle(t,l),o);return c>=0&&c<=a})}function DE(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 ice(t,e,n,r){const o=Ys(t,e,n);return t+o*r*n*-1}function o0(t){return hle[t.props.size]*t.props.scale}function ace(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=YZ(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 lce({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 cce({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 ${r.x} ${r.y} L ${t.x} ${t.y} Z`}function uce({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 dce({point:t,int:e}){const n=x.Lrp(t,e,.45),r=x.Dist(n,t);return`M ${n.x-r},${n.y}
366
- a ${r},${r} 0 1,0 ${r*2},0
367
- a ${r},${r} 0 1,0 -${r*2},0 `}function hce({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 ${o.x} ${o.y} ${t.x} ${t.y} L ${r.x} ${r.y} Z`}function pce({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 fce({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 Zf(t,e,n){const r=e==="end"?t.end.arrowhead:t.start.arrowhead;if(r==="none")return;const o=ace(t,e,n);if(o){switch(r){case"bar":return fce(o);case"square":return pce(o);case"diamond":return hce(o);case"dot":return dce(o);case"inverted":return uce(o);case"arrow":return lce(o);case"triangle":return cce(o)}return""}}function gce(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 i5(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 a5(t,e){return`M${t.x},${t.y}L${e.x},${e.y}`}function mce(t){return a5(t.start.handle,t.end.handle)}function l5(t){return a5(t.start.point,t.end.point)}class xp extends oo{constructor(){super(...arguments);I(this,"_resizeInitialBindings",new Ro)}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=Un(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=ko(this.editor,n),o=[],s=r.isStraight?new us({start:x.From(r.start.point),end:x.From(r.end.point)}):new ll({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=vp(this.editor,n);o.push(...a.debugGeom),i=new No({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new $r({children:[...i?[s,i]:[s],...o]})}getHandles(n){const r=ko(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=Un(this.editor,n);if(s==="middle"){const{start:_,end:E}=ul(this.editor,n,i),k=x.Sub(E,_),D=x.Per(k),T=x.Med(E,_),j=x.Sub(T,D),$=x.Add(T,D),M=x.NearestPointOnLineSegment(j,$,r,!1);let O=x.Dist(M,T);return x.Clockwise(M,E,T)&&(O*=-1),{id:n.id,type:n.type,props:{bend:O}}}const a={id:n.id,type:"arrow",props:{}},l=i[s],u=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return gp(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:_=>!_.isLocked&&this.editor.canBindShapes({fromShape:n,toShape:_,binding:"arrow"})});if(!p){gp(this.editor,n,s);const _=io(new x(r.x,r.y),this.editor);return a.props[s]={x:_.x,y:_.y},a}const f=this.editor.getShapeGeometry(p),g=Z.ZeroFix(f.bounds),v=this.editor.getShapePageTransform(a.id).applyToPoint(r),y=this.editor.getPointInShapeSpace(p,v);let S=o;S||(!l||l&&p.id!==l.toId)&&(S=this.editor.inputs.pointerVelocity.len()<.5),o||(f.isClosed||(S=!0),u&&p.id===u.toId&&u.props.isPrecise&&(S=!0));const b={x:(y.x-g.minX)/g.width,y:(y.y-g.minY)/g.height};S&&x.Dist(y,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:S,isExact:this.editor.inputs.altKey};Dc(this.editor,n,p.id,P),this.editor.setHintingShapes([p.id]);const C=Un(this.editor,n);return C.start&&C.end&&C.start.toId===C.end.toId&&x.Equals(C.start.props.normalizedAnchor,C.end.props.normalizedAnchor)&&Dc(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=Un(this.editor,n),o=ul(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)))){LE.set(n,{pagePosition:s.applyToPoint(n),terminalBindings:od(o,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:s.applyToPoint(l)}:null})}),r.start&&(Xf({editor:this.editor,arrow:n,terminal:"start",useHandle:!0}),n=this.editor.getShape(n.id)),r.end&&Xf({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=LE.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};Dc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else gp(this.editor,r,a.binding.props.terminal)}}onResize(n,r){const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(n,()=>Un(this.editor,n)),a=ul(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&&Dc(this.editor,n,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&g&&Dc(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=zr(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),i=ko(this.editor,n);if(!(i!=null&&i.isValid))return null;const a=vp(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(gi,{style:{minWidth:50,minHeight:50},children:d.jsx(RE,{shape:n,shouldDisplayHandles:s&&(o==null?void 0:o.id)===n.id})}),u&&d.jsx(Cm,{shapeId:n.id,classNamePrefix:"tl-arrow",type:"arrow",font:n.props.font,fontSize:o0(n),lineHeight:fn.lineHeight,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:r[n.props.labelColor].solid,textWidth:a.box.w-qf*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=Zg(n.id),o=ro(n.id+"_clip"),s=ko(this.editor,n);if(!s)return null;const{start:i,end:a}=ul(this.editor,n,s==null?void 0:s.bindings),l=this.editor.getShapeGeometry(n),c=l.bounds,u=n.props.text.trim()?l.children[1]:null;if(x.Equals(i,a))return null;const h=pn[n.props.size]*n.props.scale,p=s.start.arrowhead&&Zf(s,"start",h),f=s.end.arrowhead&&Zf(s,"end",h),g=s.isStraight?l5(s):i5(s),m=p&&s.start.arrowhead!=="arrow"||f&&s.end.arrowhead!=="arrow"||!!u;if(r&&u)return d.jsx("rect",{x:N(u.x),y:N(u.y),width:u.w,height:u.h,rx:3.5*n.props.scale,ry:3.5*n.props.scale});const v=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),y=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow");return d.jsxs("g",{children:[m&&d.jsx("defs",{children:d.jsx(u5,{hasText:n.props.text.trim().length>0,bounds:c,labelBounds:u?u.getBounds():new Z(0,0,0,0),as:v&&p?p:"",ae:y&&f?f:""})}),d.jsxs("g",{style:{clipPath:m?`url(#${o})`:void 0,WebkitClipPath:m?`url(#${o})`:void 0},children:[m&&d.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),d.jsx("path",{d:g})]}),p&&d.jsx("path",{d:p}),f&&d.jsx("path",{d:f}),u&&d.jsx("rect",{x:N(u.x),y:N(u.y),width:u.w,height:u.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(Ab(n.props.fill)),n.props.text&&r.addExportDef(bm(n.props.font));const o=ks(r),s=1/n.props.scale;return d.jsxs("g",{transform:`scale(${s})`,children:[d.jsx(RE,{shape:n,shouldDisplayHandles:!1}),d.jsx(Pm,{fontSize:o0(n),font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:o[n.props.labelColor].solid,bounds:vp(this.editor,n).box.clone().expandBy(-qf*n.props.scale),padding:0})]})}getCanvasSvgDefs(){return[jb(),{key:"arrow:dot",component:yce},{key:"arrow:cross",component:Sce}]}getInterpolatedProps(n,r,o){return{...o>.5?r.props:n.props,scale:_e(n.props.scale,r.props.scale,o),start:{x:_e(n.props.start.x,r.props.start.x,o),y:_e(n.props.start.y,r.props.start.y,o)},end:{x:_e(n.props.end.x,r.props.end.x,o),y:_e(n.props.end.y,r.props.end.y,o)},bend:_e(n.props.bend,r.props.bend,o),labelPosition:_e(n.props.labelPosition,r.props.labelPosition,o)}}}I(xp,"type","arrow"),I(xp,"props",_A),I(xp,"migrations",IA);function c5(t,e){const n=ko(t,e);return n.isStraight?x.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const RE=qt(function({shape:e,shouldDisplayHandles:n}){const r=z(),o=zr(),s=ko(r,e),i=Z.ZeroFix(r.getShapeGeometry(e).bounds),a=Un(r,e),l=U("force solid",()=>r.getZoomLevel()<.2,[r]),c=ro(e.id+"_clip"),u=ro("arrowhead-dot"),h=ro("arrowhead-cross");if(!(s!=null&&s.isValid))return null;const p=pn[e.props.size]*e.props.scale,f=s.start.arrowhead&&Zf(s,"start",p),g=s.end.arrowhead&&Zf(s,"end",p),m=s.isStraight?l5(s):i5(s);let v=null;if(n){const _=2/r.getZoomLevel(),{strokeDasharray:E,strokeDashoffset:k}=qr(c5(r,e),_,{end:"skip",start:"skip",lengthRatio:2.5});v=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?mce(s):gce(s),strokeDasharray:E,strokeDashoffset:k,strokeWidth:_,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?`url(#${h})`:`url(#${u})`:"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?`url(#${h})`:`url(#${u})`:"",opacity:.16}):null}const{strokeDasharray:y,strokeDashoffset:S}=qr(s.isStraight?s.length:Math.abs(s.bodyArc.length),p,{style:e.props.dash,forceSolid:l}),b=vp(r,e),P=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),C=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:c,children:d.jsx(u5,{hasText:e.props.text.trim().length>0,bounds:i,labelBounds:b.box,as:P&&f?f:"",ae:C&&g?g:""})})}),d.jsxs("g",{fill:"none",stroke:o[e.props.color].solid,strokeWidth:p,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[v,d.jsxs("g",{style:{clipPath:`url(#${c})`,WebkitClipPath:`url(#${c})`},children:[d.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),d.jsx("path",{d:m,strokeDasharray:y,strokeDashoffset:S})]}),f&&P&&e.props.fill!=="none"&&d.jsx(on,{theme:o,d:f,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),g&&C&&e.props.fill!=="none"&&d.jsx(on,{theme:o,d:g,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),f&&d.jsx("path",{d:f}),g&&d.jsx("path",{d:g})]})]})});function u5({hasText:t,bounds:e,labelBounds:n,as:r,ae:o}){const s=`M${N(e.minX-100)},${N(e.minY-100)} h${e.width+200} v${e.height+200} h-${e.width+200} Z`,i=`M${N(n.minX)},${N(n.minY)} v${n.height} h${n.width} v-${n.height} Z`;return d.jsx("path",{d:`${s}${t?i:""}${r}${o}`})}const LE=new WeakMap;function yce(){const t=ro("arrowhead-dot");return d.jsx("marker",{id:t,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 Sce(){const t=ro("arrowhead-cross");return d.jsxs("marker",{id:t,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 $E="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 Fl({url:t}){const e=z(),n=U("zoomLevel",()=>e.getZoomLevel()<.32,[e]);return d.jsx("a",{className:le("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n}),href:t,target:"_blank",rel:"noopener noreferrer",onPointerDown:_t,onPointerUp:_t,title:t,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${$E}") center 100% / 100% no-repeat`,WebkitMask:`url("${$E}") 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",vce=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function Qf(t){return vce.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 xce=300,d5=320,wce=46,bce=101;class wp extends sc{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:xce,h:d5,assetId:null}}component(e){return d.jsx(Pce,{shape:e,util:this})}indicator(e){return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h),rx:"6",ry:"6"})}onBeforeCreate(e){return NE(this.editor,e)}onBeforeUpdate(e,n){if(e.props.url!==n.props.url)if(gr.isValid(n.props.url))_ce(this.editor,n);else return{...n,props:{...n.props,url:e.props.url}};if(e.props.assetId!==n.props.assetId)return NE(this.editor,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}I(wp,"type","bookmark"),I(wp,"props",jA),I(wp,"migrations",OA);function Pce({shape:t,util:e}){const n=t.props.assetId?e.editor.getAsset(t.props.assetId):null,r=!!md()&&Ge.isSafari,o=e.editor.getShapePageTransform(t).rotation(),s=Cce(t),[i,a]=w.useState(!0),l=()=>a(!1);return d.jsx(di,{children:d.jsxs("div",{className:le("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:Qf(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(Fl,{url:t.props.url})]}),d.jsxs("div",{className:"tl-bookmark__copy_container",children:[n!=null&&n.props.title?d.jsx("h2",{className:"tl-bookmark__heading",children:vle(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:_t,onPointerUp:_t,onClick:_t,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 NE(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):null;let r=d5;return n&&(n.props.image||(n.props.title?r=bce:r=wce)),{...e,props:{...e.props,h:r}}}const Cce=t=>{try{return new URL(t.props.url).hostname.replace(/^www\./,"")}catch{return t.props.url}};function _ce(t,e){const{url:n}=e.props,r=Vs.createId(Gv(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}}]),Ice(t,e))}const Ice=vg(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 Sa(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+=Bn(r,o);return e?`M${Bn(t[0].point,t[1].point)}Q${je(t[1].point)}${Bn(t[1].point,t[2].point)}T${s}${Bn(t[n-1].point,t[0].point)}${Bn(t[0].point,t[1].point)}Z`:`M${je(t[0].point)}Q${je(t[1].point)}${Bn(t[1].point,t[2].point)}${t.length>3?"T":""}${s}L${je(t[n-1].point)}`}function Ece(t,e={}){const{start:n={},end:r={}}=e,{cap:o=!0}=n,{cap:s=!0}=r;Le(!n.taper&&!r.taper,"cap taper not supported here"),Le(!n.easing&&!r.easing,"cap easing not supported here"),Le(o&&s,"cap must be true");const i=Uo(t,e);xm(i,e);const a=kce(i);let l="";for(const c of a)l+=Mce(c,e);return l}function kce(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 Tce(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 Mce(t,e={}){if(t.length===0)return"";if(t.length===1)return Tce(t[0].point.x,t[0].point.y,t[0].radius);const{left:n,right:r}=W$(t,e);r.reverse();let o=`M${je(n[0])}T`;for(let s=1;s<n.length;s++)o+=Bn(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${N(i)},${N(i)} 0 0 1 ${je(c)}T`}for(let s=1;s<r.length;s++)o+=Bn(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${N(i)},${N(i)} 0 0 1 ${je(c)}Z`}return o}const h5=(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=_e(c.z,a[u].z,n)),{x:_e(c.x,a[u].x,n),y:_e(c.y,a[u].y,n),z:h}})}]},Ace=t=>t*.65+gX(t*De/2)*.35,jce=t=>({size:t,thinning:.5,streamline:Ol(t,[9,16],[.64,.74],!0),smoothing:.62,easing:Dt.easeOutSine,simulatePressure:!0}),Oce=t=>({size:1+t*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Ace}),zE=t=>({size:t,thinning:0,streamline:Ol(t,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:Dt.linear}),Dce=t=>({size:t,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Dt.linear});function Rb({strokeWidth:t,showAsComplete:e}){return{size:1+t,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:Dt.easeOutSine,last:e}}function s0(t,e,n,r){const o=t.isComplete||n;return r?t.isPen?{...Dce(e),last:o}:{...zE(e),last:o}:t.dash==="draw"?t.isPen?{...Oce(e),last:o}:{...jce(e),last:o}:{...zE(e),last:o}}function Nl(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 Rce(t,e,n){return{draw:"none",solid:"none",dotted:`${n} ${e*2}`,dashed:`${e*2} ${e*2}`}[t.props.dash]}class bp extends oo{hideResizeHandles(e){return CS(e)}hideRotateHandle(e){return CS(e)}hideSelectionBoundsFg(e){return CS(e)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(e){const n=Nl(e.props.segments),r=(pn[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 L1({x:-r,y:-r,radius:r,isFilled:!0})}const o=Uo(n,s0(e.props,r,e.props.isPen,!0)).map(s=>s.point);return e.props.isClosed?new xt({points:o,isFilled:e.props.fill!=="none"}):new nc({points:o})}component(e){return d.jsx(gi,{children:d.jsx(BE,{shape:e})})}indicator(e){var u;const n=Nl(e.props.segments);let r=(pn[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+=co(e.id)()*(r/6));const i=e.props.isComplete||((u=Ut(e.props.segments))==null?void 0:u.type)==="straight",a=s0(e.props,r,i,!0),l=Uo(n,a),c=l.length>1?Sa(l,e.props.isClosed):p5(n[0],r);return d.jsx("path",{d:c})}toSvg(e,n){n.addExportDef(Ab(e.props.fill));const r=1/e.props.scale;return d.jsx("g",{transform:`scale(${r})`,children:d.jsx(BE,{shape:e,zoomOverride:1})})}getCanvasSvgDefs(){return[jb()]}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:as(r*a),y:as(o*l),z:c}))});return{props:{segments:s}}}expandSelectionOutlinePx(e){const n=e.props.dash==="draw"?1.6:1;return pn[e.props.size]*n/2*e.props.scale}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,segments:h5(e.props.segments,n.props.segments,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(bp,"type","draw"),I(bp,"props",RA),I(bp,"migrations",LA);function p5(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 CS(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function BE({shape:t,zoomOverride:e}){var f;const n=zr(),r=z(),o=Nl(t.props.segments),s=t.props.isComplete||((f=Ut(t.props.segments))==null?void 0:f.type)==="straight";let i=(pn[t.props.size]+1)*t.props.scale;const a=U("force solid",()=>{const g=e??r.getZoomLevel();return g<.5&&g<1.5/i},[r,i,e]),l=U("dot adjustment",()=>(e??r.getZoomLevel())<.2?0:.1,[r,e]);!a&&!t.props.isPen&&t.props.dash==="draw"&&o.length===1&&(i+=co(t.id)()*(i/6));const c=s0(t.props,i,s,a);if(!a&&t.props.dash==="draw")return d.jsxs(d.Fragment,{children:[t.props.isClosed&&t.props.fill&&o.length>1?d.jsx(on,{d:Sa(Uo(o,c),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:Ece(o,c),strokeLinecap:"round",fill:n[t.props.color].solid})]});const u=Uo(o,c),h=u.length<2,p=h?p5(o[0],0):Sa(u,t.props.isClosed);return d.jsxs(d.Fragment,{children:[d.jsx(on,{d:p,theme:n,color:t.props.color,fill:h||t.props.isClosed?t.props.fill:"none",scale:t.props.scale}),d.jsx("path",{d:p,strokeLinecap:"round",fill:h?n[t.props.color].solid:"none",stroke:n[t.props.color].solid,strokeWidth:i,strokeDasharray:h?"none":Rce(t,i,l),strokeDashoffset:"0"})]})}function Lce(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function $ce(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(f5(o.hostnames,r)){const s=o.fromEmbedUrl(e);if(s)return{definition:o,url:s,embedUrl:e}}}const Fce=t=>t.split("*").map(e=>Lce(e)).join(".+"),f5=(t,e)=>!!t.find(n=>{const r=new RegExp(Fce(n));return e.match(r)});function Nce(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(f5(o.hostnames,r)){const s=o.toEmbedUrl(e);if(s)return{definition:o,embedUrl:s,url:e}}}function zce(t,e){try{return Nce(t,e)??$ce(t,e)}catch{return}}const Bce=t=>Object.entries(t).filter(([e,n])=>n).map(([e])=>e).join(" "),ss=class ss extends sc{static setEmbedDefinitions(e){ss.embedDefinitions=e}getEmbedDefinitions(){return ss.embedDefinitions}getEmbedDefinition(e){return zce(ss.embedDefinitions,e)}getText(e){return e.props.url}hideSelectionBoundsFg(e){return!this.canResize(e)}canEdit(){return!0}canResize(e){var n,r;return!!((r=(n=this.getEmbedDefinition(e.props.url))==null?void 0:n.definition)!=null&&r.doesResize)}canEditInReadOnly(){return!0}getDefaultProps(){return{w:300,h:300,url:""}}isAspectRatioLocked(e){const n=this.getEmbedDefinition(e.props.url);return(n==null?void 0:n.definition.isAspectRatioLocked)??!1}onResize(e,n){const r=this.isAspectRatioLocked(e),o=this.getEmbedDefinition(e.props.url);let s=(o==null?void 0:o.definition.minWidth)??200,i=(o==null?void 0:o.definition.minHeight)??200;if(r){const a=e.props.w/e.props.h;a>1?s*=a:i/=a}return qg(e,n,{minWidth:s,minHeight:i})}component(e){const n=md(),{w:r,h:o,url:s}=e.props,i=Zg(e.id),a=this.getEmbedDefinition(s),l=U("is hovering",()=>{const{editingShapeId:f,hoveredShapeId:g}=this.editor.getCurrentPageState();if(f&&g!==f){const m=this.editor.getShape(f);if(m&&this.editor.isShapeOfType(m,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(e).rotation();if(n)return d.jsx(di,{className:"tl-embed-container",id:e.id,children:d.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:Qf(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:(a==null?void 0:a.definition.backgroundColor)??"var(--color-background)",width:r,height:o}})});const u=i||l;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const f=a.url.split("/").pop();if(!f)throw Error("No gist id!");return d.jsx(di,{className:"tl-embed-container",id:e.id,children:d.jsx(Uce,{id:f,width:N(r),height:N(o),isInteractive:u,pageRotation:c})})}const p=Bce({...Yse,...(a==null?void 0:a.definition.overridePermissions)??{}});return d.jsx(di,{className:"tl-embed-container",id:e.id,children:a!=null&&a.definition?d.jsx("iframe",{className:"tl-embed",sandbox:p,src:a.embedUrl,width:N(r),height:N(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:Qf(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(e){const n=this.getEmbedDefinition(e.props.url);return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h),rx:(n==null?void 0:n.definition.overrideOutlineRadius)??8,ry:(n==null?void 0:n.definition.overrideOutlineRadius)??8})}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}};I(ss,"type","embed"),I(ss,"props",$A),I(ss,"migrations",FA),I(ss,"embedDefinitions",Sb);let Jf=ss;function Uce({id:t,file:e,isInteractive:n,width:r,height:o,style:s,pageRotation:i}){return d.jsx("iframe",{className:"tl-embed",draggable:!1,width:N(r),height:N(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:n?"all":"none",zIndex:n?"":"-1",boxShadow:Qf(i)},srcDoc:`
368
- <html>
369
- <head>
370
- <base target="_blank">
371
- </head>
372
- <body>
373
- <script src=${`https://gist.github.com/${t}.js${e?`?file=${e}`:""}`}><\/script>
374
- <style type="text/css">
375
- * { margin: 0px; }
376
- table { height: 100%; background-color: red; }
377
- .gist { background-color: none; height: 100%; }
378
- .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
379
- </style>
380
- </body>
381
- </html>`})}function i0(t,e){const o=((Ji(t.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4;return Math.floor(o)}function UE(t,e,n){const r=t.textMeasure.measureTextSpans(m5(e.props.name,"Frame")+"​",n),o=r[0],s=Ut(r),i=s.box.w+s.box.x-o.box.x;return{box:new Z(0,-n.height,i,n.height),spans:r}}function HE(t,e){return{fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:t.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",fill:e,offsetY:-34,offsetX:2}}function g5(t,e,n){const r=n?"":"px",o=n?"":"deg";let s;switch(e){case 0:s="";break;case 3:s=`translate(${N(t.props.w)}${r}, 0${r}) rotate(90${o})`;break;case 2:s=`translate(${N(t.props.w)}${r}, ${N(t.props.h)}${r}) rotate(180${o})`;break;case 1:s=`translate(0${r}, ${N(t.props.h)}${r}) rotate(270${o})`;break;default:throw Error("labelSide out of bounds")}return s}const Hce=w.forwardRef(({id:t,name:e,isEditing:n},r)=>{const o=z(),s=w.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(_t(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}),m5(e,"Frame")+"​"]})});function Kce({id:t,name:e,width:n,height:r}){const o=z(),{side:s,translation:i}=U("shape rotation",()=>{const c=o.getShape(t);if(!c)return{side:0,translation:"translate(0, 0)"};const u=i0(o,c);return{side:u,translation:g5(c,u,!1)}},[o,t]),a=w.useRef(null),l=Zg(t);return w.useEffect(()=>{const c=a.current;c&&l&&(c.focus(),c.select())},[a,l]),d.jsx("div",{className:"tl-frame-heading",style:{overflow:l?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(s===0||s===2?n:r)}px + var(--space-5))`,bottom:"100%",transform:`${i} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},children:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(Hce,{ref:a,id:t,name:e,isEditing:l})})})}function m5(t,e){return t.match(/^\s*$/)?e:t}class Pp extends sc{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){const{editor:n}=this,r=n.getZoomLevel(),o=HE(e,"black"),s=UE(n,e,o),i=i0(n,e);let a,l,c,u;const{w:h,h:p}=s.box,f=Math.min(h,e.props.w*r),g=Math.min(p,e.props.h*r);switch(i){case 0:{a=-8/r,l=(-p-4)/r,c=(f+16)/r,u=p/r;break}case 1:{a=(-p-4)/r,u=(g+16)/r,l=e.props.h-u+8/r,c=p/r;break}case 2:{a=e.props.w-(f+8)/r,l=e.props.h+4/r,c=(g+16)/r,u=p/r;break}case 3:{a=e.props.w+4/r,u=(g+16)/r,l=-8/r,c=p/r;break}}return new $r({children:[new No({width:e.props.w,height:e.props.h,isFilled:!1}),new No({x:a,y:l,width:c,height:u,isFilled:!0,isLabel:!0})]})}getText(e){return e.props.name}component(e){const n=this.editor.getShapeGeometry(e).bounds,r=zr(),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(gi,{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(Kce,{id:e.id,name:e.props.name,width:n.width,height:n.height})]})}toSvg(e,n){const r=ks({isDarkMode:n.isDarkMode}),o=i0(this.editor,e),s=g5(e,o,!0),i=HE(e,r.text),{box:a,spans:l}=UE(this.editor,e,i),c=r0(this.editor,l,i);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:s,children:[d.jsx("rect",{x:a.x-8,y:a.y-4,width:a.width+20,height:a.height,fill:r.background,rx:4,ry:4}),c]})]})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx("rect",{width:N(n.width),height:N(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 qg(e,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}I(Pp,"type","frame"),I(Pp,"props",NA),I(Pp,"migrations",zA);function KE(t,e){return t>e?(De*(e/2)+(t-e))*2:(De*(t/2)+(e-t))*2}function y5(t,e){return Lb(t,e).map((n,r)=>n.getSvgPathData(r===0)).join(" ")+" Z"}function Wce(t,e,n,r){const o=t/4,s=e/4,i=co(r),a=n*.75,l=S=>S.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 an({start:c,cp1:new x(o*1.5,s*3),cp2:new x(0,s*2.5),end:u}),new an({start:u,cp1:new x(0,-s*.32),cp2:new x(o*1.85,-s*.32),end:h}),new an({start:h,cp1:new x(o*2.15,-s*.32),cp2:new x(t,-s*.32),end:p}),new an({start:p,cp1:new x(t,s*2.5),cp2:new x(o*2.5,s*3),end:f}),new an({start:f,cp1:new x(o*1.5,s*3),cp2:new x(0,s*2.5),end:g}),new an({start:g,cp1:new x(0,-s*.32),cp2:new x(o*1.85,-s*.32),end:m}),new an({start:m,cp1:new x(o*2.15,-s*.32),cp2:new x(t,-s*.32),end:v}),new an({start:v,cp1:new x(t,s*2.5),cp2:new x(o*2.5,s*3),end:c})].map((S,b)=>S.getSvgPathData(b===0)).join(" ")+" Z"}function Lb(t,e){const n=t/4,r=e/4;return[new an({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 an({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 an({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 an({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 Gce(t){return{size:1+t,thinning:.25,end:{taper:t},start:{taper:t},streamline:0,smoothing:1,simulatePressure:!1}}function Vce(t,e,n,r){const o=co(t),s=e/2,i=n/2,a=ij(s,i),l=[],c=Ne*o(),u=Ne+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?Dt.easeInOutSine(f):Dt.easeInExpo(f)))/2)))}return Uo(l,Gce(r))}function Yce(t,e,n,r){return Sa(Vce(t,e,n,r))}function a0(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 l0(t,e,n,r,o){const s=[],i=co(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 Xce(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(da(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 qce={s:50,m:70,l:100,xl:130},Zce=.2;function _m(t,e,n,r,o){const s=co(n),i=KE(t,e),a=Math.max(Math.ceil(i/qce[r]),6,Math.ceil(i/Math.min(t,e))),l=i/a*Zce,c=Math.max(t-l*2,1),u=Math.max(e-l*2,1),p=KE(c,u)/a,f=(t-c)/2,g=(e-u)/2,m=Xce(c,u,a).map(P=>P.addXY(f,g)),v=t<20?0:l*.3,y=e<20?0:l*.3,S=m.slice(0);for(let P=0;P<Math.floor(a/2);P++)S[P]=x.AddXY(S[P],s()*v*o,s()*y*o),S[a-P-1]=x.AddXY(S[a-P-1],s()*v*o,s()*y*o);const b=[];for(let P=0;P<S.length;P++){const C=P===S.length-1?0:P+1,_=S[P],E=S[C],k=m[P],D=m[C],T=x.Dist(k,D),j=p-T,M=x.Dist(_,E)/T,O=(Math.max(f,g)+j)*M,F=x.Lrp(k,D,.5).add(x.Sub(D,k).uni().per().mul(O));F.x<0?F.x=0:F.x>t&&(F.x=t),F.y<0?F.y=0:F.y>e&&(F.y=e);const B=f1(_,E,F),K=x.Dist(B||x.Average([_,E]),_);b.push({leftPoint:_,rightPoint:E,arcPoint:F,center:B,radius:K})}return b}function Qce(t,e,n,r,o){const s=[],i=_m(t,e,n,r,o);for(const{center:a,radius:l,leftPoint:c,rightPoint:u}of i)s.push(...vX(c,u,a,l,10));return s}function c0(t,e,n,r,o){const s=_m(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${N(c)},${N(c)} 0 ${h},1 ${l.toFixed()}`}return i+=" Z",i}const Jce={s:.5,m:.7,l:.9,xl:1.6};function eue(t,e,n,r,o){const s=co(n),i=Jce[r]*o,a=_m(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:y,arcPoint:S}of a){if(m===null){h+=` L${v.toFixed()}`;const k=u(v);f+=` L${k.toFixed()}`,p=k;continue}const b=x.Clockwise(g,v,m)?"0":"1";h+=` A${N(y)},${N(y)} 0 ${b},1 ${v.toFixed()}`;const P=u(v),C=u(S),_=f1(p,P,C);if(!_){f+=` L${P.toFixed()}`,p=P;continue}const E=Math.abs(x.Dist(_,p));f+=` A${N(E)},${N(E)} 0 ${b},1 ${P.toFixed()}`,p=P}return h+f+" Z"}function u0(t,e){switch(t.geo){case"x-box":return tue(t.w,t.h,e,t.dash);case"check-box":return nue(t.w,t.h);default:return}}function tue(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 nue(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 WE({shape:t,shouldScale:e,forceSolid:n}){const r=e?t.props.scale:1,o=z(),s=zr(),{id:i,props:a}=t,{w:l,color:c,fill:u,dash:h,growY:p,size:f,scale:g}=a,m=pn[f]*r,v=a.h+p;switch(a.geo){case"cloud":if(h==="solid"){const y=c0(l,v,i,f,g);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}else if(h==="draw"){const y=eue(l,v,i,f,g);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}else{const y=c0(l,v,i,f,g),S=_m(l,v,i,f,g);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("g",{strokeWidth:m,stroke:s[c].solid,fill:"none",pointerEvents:"all",children:S.map(({leftPoint:b,rightPoint:P,center:C,radius:_},E)=>{const k=C?_*Ji(Ji(x.Angle(C,P))-Ji(x.Angle(C,b))):x.Dist(b,P),{strokeDasharray:D,strokeDashoffset:T}=qr(k,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("path",{d:C?`M${b.x},${b.y}A${_},${_},0,0,1,${P.x},${P.y}`:`M${b.x},${b.y}L${P.x},${P.y}`,strokeDasharray:D,strokeDashoffset:T},E)})})]})}case"ellipse":{const y=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),S=y.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=y.length,{strokeDasharray:P,strokeDashoffset:C}=qr(b<64?b*2:b,m,{style:h,snap:4,closed:!0,forceSolid:n});return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,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(on,{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 y=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),S=y.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=y.getLength(),{strokeDasharray:P,strokeDashoffset:C}=qr(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(on,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,strokeWidth:m,fill:"none",stroke:s[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}case"heart":if(h==="dashed"||h==="dotted"||h==="solid"){const y=y5(l,v),S=Lb(l,v);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:y,color:c,fill:u,scale:r}),S.map((b,P)=>{const{strokeDasharray:C,strokeDashoffset:_}=qr(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:_,pointerEvents:"all"},`curve_${P}`)})]})}else{const y=Wce(l,v,m,t.id);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}default:{const y=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),S=y instanceof $r?y.children[0].vertices:y.vertices,b=u0(t.props,m);if(h==="solid"){let P="M"+S[0]+"L"+S.slice(1)+"Z";if(b)for(const[C,_]of b)P+=`M${C.x},${C.y}L${_.x},${_.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(on,{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"+S[0]+"L"+S.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(on,{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(S.length)).map((C,_)=>{const E=x.ToFixed(S[_]),k=x.ToFixed(S[(_+1)%S.length]),D=x.Dist(E,k),{strokeDasharray:T,strokeDashoffset:j}=qr(D,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("line",{x1:E.x,y1:E.y,x2:k.x,y2:k.y,strokeDasharray:T,strokeDashoffset:j},_)}),b&&b.map(([C,_],E)=>{const k=x.Dist(C,_),{strokeDasharray:D,strokeDashoffset:T}=qr(k,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${_.x},${_.y}`,stroke:s[c].solid,strokeWidth:m,fill:"none",strokeDasharray:D,strokeDashoffset:T},`line_fg_${E}`)})]})]})}else if(h==="draw"){let P=a0(l0(i,S,m/3,m*2,2));if(b)for(const[_,E]of b)P+=`M${_.toFixed()}L${E.toFixed()}`;const C=a0(l0(i,S,0,m*2,1));return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:C,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}}}}const GE=17*3;class Cp extends sc{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 xt({points:Qce(n,r,e.id,e.props.size,e.props.scale),isFilled:i});break}case"triangle":{a=new xt({points:[new x(o,0),new x(n,r),new x(0,r)],isFilled:i});break}case"diamond":{a=new xt({points:[new x(o,0),new x(n,s),new x(o,r),new x(0,s)],isFilled:i});break}case"pentagon":{a=new xt({points:Uy(n,r,5),isFilled:i});break}case"hexagon":{a=new xt({points:Uy(n,r,6),isFilled:i});break}case"octagon":{a=new xt({points:Uy(n,r,8),isFilled:i});break}case"ellipse":{a=new gte({width:n,height:r,isFilled:i});break}case"oval":{a=new mte({width:n,height:r,isFilled:i});break}case"star":{const S=Ne/5/2,b=Math.floor(5/4)*2,P=5*2-b,C=0,_=Math.floor(5/2)*2,E=Math.cos(-qe+b*S)*n/2,k=Math.cos(-qe+P*S)*n/2,D=Math.sin(-qe+C*S)*r/2,T=Math.sin(-qe+_*S)*r/2,j=n-Math.abs(E-k),$=r-Math.abs(T-D),M=n/2+k-(n/2-E),O=r/2+D-(r/2-T),F=1,B=(n-M)/2,K=(r-O)/2,R=(n+j)/2,H=(r+$)/2,Y=R*F/2,ee=H*F/2;a=new xt({points:Array.from(Array(5*2)).map((he,ue)=>{const ke=-qe+ue*S;return new x(B+(ue%2?Y:R)*Math.cos(ke),K+(ue%2?ee:H)*Math.sin(ke))}),isFilled:i});break}case"rhombus":{const y=Math.min(n*.38,r*.38);a=new xt({points:[new x(y,0),new x(n,0),new x(n-y,r),new x(0,r)],isFilled:i});break}case"rhombus-2":{const y=Math.min(n*.38,r*.38);a=new xt({points:[new x(0,0),new x(n-y,0),new x(n,r),new x(y,r)],isFilled:i});break}case"trapezoid":{const y=Math.min(n*.38,r*.38);a=new xt({points:[new x(y,0),new x(n-y,0),new x(n,r),new x(0,r)],isFilled:i});break}case"arrow-right":{const y=Math.min(n,r)*.38,S=r*.16;a=new xt({points:[new x(0,S),new x(n-y,S),new x(n-y,0),new x(n,r/2),new x(n-y,r),new x(n-y,r-S),new x(0,r-S)],isFilled:i});break}case"arrow-left":{const y=Math.min(n,r)*.38,S=r*.16;a=new xt({points:[new x(y,0),new x(y,S),new x(n,S),new x(n,r-S),new x(y,r-S),new x(y,r),new x(0,r/2)],isFilled:i});break}case"arrow-up":{const y=n*.16,S=Math.min(n,r)*.38;a=new xt({points:[new x(n/2,0),new x(n,S),new x(n-y,S),new x(n-y,r),new x(y,r),new x(y,S),new x(0,S)],isFilled:i});break}case"arrow-down":{const y=n*.16,S=Math.min(n,r)*.38;a=new xt({points:[new x(y,0),new x(n-y,0),new x(n-y,r-S),new x(n,r-S),new x(n/2,r),new x(0,r-S),new x(y,r-S)],isFilled:i});break}case"check-box":case"x-box":case"rectangle":{a=new No({width:n,height:r,isFilled:i});break}case"heart":{const S=Lb(n,r).reduce((b,P)=>(b.push(...P.vertices),b),[]);a=new xt({points:S,isFilled:i});break}default:Ot(e.props.geo)}const l=Lh(this.editor,e),c=n/e.props.scale,u=r/e.props.scale,h=Math.min(100,c/2),p=Math.min(ys[e.props.size]*fn.lineHeight+Er*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=u0(e.props,pn[e.props.size]*e.props.scale),v=m?m.map(y=>new nc({points:y})):[];return new $r({children:[a,new No({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:Ot(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=zr(),{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(gi,{children:d.jsx(WE,{shape:e,shouldScale:!0,forceSolid:v})}),m&&d.jsx(di,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+o.growY},children:d.jsx(Cm,{shapeId:n,type:r,font:i,fontSize:ys[c]*e.props.scale,lineHeight:fn.lineHeight,padding:Er*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(Fl,{url:e.props.url})]})}indicator(e){const{id:n,props:r}=e,{w:o,size:s}=r,i=r.h+r.growY,a=pn[s],l=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?d.jsx("path",{d:Yce(n,o,i,a)}):d.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:y5(o,i)});case"oval":return d.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:c0(o,i,n,s,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),u=c instanceof $r?c.children[0].vertices:c.vertices;let h;if(r.dash==="draw"){const f=l0(n,u,0,a*2*e.props.scale,1);h=a0(f)}else h="M"+u[0]+"L"+u.slice(1)+"Z";const p=u0(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(Ab(o.fill));let s;if(o.text){n.addExportDef(bm(o.font));const i=ks(n),a=new Z(0,0,o.w,o.h+o.growY);s=d.jsx(Pm,{fontSize:ys[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(WE,{shouldScale:!1,shape:r,forceSolid:!1}),s]})}getCanvasSvgDefs(){return[jb()]}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=GE;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 _=Lh(this.editor,{...e,props:{...e.props,w:P*e.props.scale,h:C*e.props.scale}}),E=Math.max(Math.abs(u),_.w)*Math.sign(u),k=Math.max(Math.abs(h),_.h)*Math.sign(h);p=Math.abs(E)-Math.abs(u),f=Math.abs(k)-Math.abs(h),u=E,h=k}const m=u*e.props.scale,v=h*e.props.scale,y=new x(0,0);o<0&&(y.x+=m),(n==="left"||n==="top_left"||n==="bottom_left")&&(y.x+=o<0?p:-p),s<0&&(y.y+=v),(n==="top"||n==="top_left"||n==="top_right")&&(y.y+=s<0?f:-f);const{x:S,y:b}=y.rot(e.rotation).add(r);return{x:S,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=Lh(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=Lh(this.editor,n);if(!r&&o&&o.length===1){let u=Math.max(s,l.w),h=Math.max(i,l.h);const p=GE;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:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(Cp,"type","geo"),I(Cp,"props",BA),I(Cp,"migrations",UA);function Lh(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",{...fn,fontFamily:Cs[r],fontSize:ys[o],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=t.textMeasure.measureText(n,{...fn,fontFamily:Cs[r],fontSize:ys[o],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[o]),Math.ceil(s/e.props.scale-Er*2))});return{w:l.w+Er*2,h:l.h+Er*2}}function rue(){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(bt.forceSrgb)||!t?"srgb":"p3"}const VE=.35,YE=.82;class _p extends oo{hideResizeHandles(e){return $h(e)}hideRotateHandle(e){return $h(e)}hideSelectionBoundsFg(e){return $h(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(e){const n=Ki(e);if($h(e))return new L1({x:-n/2,y:-n/2,radius:n/2,isFilled:!0});const{strokePoints:r,sw:o}=XE(e,n,!0),s=Rb({strokeWidth:o,showAsComplete:!0});return xm(r,s),new xt({points:kb(r,s),isFilled:!0})}component(e){const n=_S(this.editor,e),r=Ki(e);return d.jsx(gi,{children:d.jsx(Fh,{shape:e,forceSolid:n,strokeWidth:r,opacity:VE})})}backgroundComponent(e){const n=_S(this.editor,e),r=Ki(e);return d.jsx(gi,{children:d.jsx(Fh,{shape:e,forceSolid:n,strokeWidth:r,opacity:YE})})}indicator(e){const n=_S(this.editor,e),r=Ki(e),{strokePoints:o,sw:s}=XE(e,r,n),i=Nl(e.props.segments);let a;return o.length<2?a=sue(i[0],s):a=Sa(o,!1),d.jsx("path",{d:a})}toSvg(e){const n=Ki(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(Fh,{forceSolid:r,strokeWidth:n,shape:e,opacity:VE})})}toBackgroundSvg(e){const n=Ki(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(Fh,{forceSolid:r,strokeWidth:n,shape:e,opacity:YE})})}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:h5(e.props.segments,n.props.segments,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(_p,"type","highlight"),I(_p,"props",WA),I(_p,"migrations",GA);function oue(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 sue(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 XE(t,e,n){var l;const r=Nl(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+=co(t.id)()*(e/6));const i=Rb({strokeWidth:s,showAsComplete:o});return{strokePoints:Uo(r,i),sw:s}}function Ki(t){return Ll[t.props.size]*1.12*t.props.scale}function $h(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function Fh({strokeWidth:t,forceSolid:e,shape:n,opacity:r}){var p;const o=zr(),s=Nl(n.props.segments);let i=t;!e&&!n.props.isPen&&s.length===1&&(i+=co(n.id)()*(i/6));const a=Rb({strokeWidth:i,showAsComplete:n.props.isComplete||((p=Ut(n.props.segments))==null?void 0:p.type)==="straight"}),l=Uo(s,a),c=l.length>1?Sa(l,!1):oue(n.props.segments[0].points[0]),u=rue(),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 _S(t,e){return U("forceSolid",()=>{const n=Ki(e),r=t.getZoomLevel();return n/r<1.5},[t])}function S5(){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 v5({shapeId:t,assetId:e}){const n=z(),r=!!md(),o=TQ(),s=w.useMemo(()=>vg(qE,500),[]),[i,a]=w.useState(()=>({asset:e?n.getAsset(e)??null:null,url:null})),l=w.useRef(!1),c=w.useRef(null);return w.useEffect(()=>{if(!e)return;let u=!1,h;const p=jo("update state",()=>{if(!r&&n.getCulledShapes().has(t))return;const f=n.getAsset(e);if(!f)return;const g=n.getShape(t);if(!g)return;if(!f.props.src){const y=n.getTemporaryAssetPreview(f.id);if(y){c.current!==y&&(c.current=y,a(S=>({...S,isPlaceholder:!0,url:y})),o());return}}const m=n.getZoomLevel()*(g.props.w/f.props.w);function v(y,S){u||c.current!==S&&(l.current=!0,c.current=S,a({asset:y,url:S}),o())}l.current?(s(n,e,m,r,y=>v(f,y)),h=s.cancel):qE(n,e,m,r,y=>v(f,y))});return()=>{p(),h==null||h(),u=!0}},[n,e,r,o,t,s]),i}function qE(t,e,n,r,o){t.resolveAssetUrl(e,{screenScale:n,shouldResolveToOriginal:r}).then(s=>{o(s)})}async function iue(t){const n=await(await Lo(t)).blob();return Zr.blobToDataUrl(n)}class Ip extends sc{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=qg(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}component(e){return d.jsx(aue,{shape:e})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:d.jsx("rect",{width:N(e.props.w),height:N(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});return r?((r.startsWith("blob:")||r.startsWith("http")||r.startsWith("/")||r.startsWith("./"))&&(r=await iue(r)||""),d.jsx(cue,{shape:e,src:r})):null}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:_e(a.x,c.x,r),y:_e(a.y,c.y,r)},bottomRight:{x:_e(l.x,u.x,r),y:_e(l.y,u.y,r)}}}return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r),crop:o(e,n)}}}I(Ip,"type","image"),I(Ip,"props",VA),I(Ip,"migrations",YA);const aue=w.memo(function({shape:e}){var y;const n=z(),{asset:r,url:o}=v5({shapeId:e.id,assetId:e.props.assetId}),s=ZR(),[i,a]=w.useState(""),[l,c]=w.useState(null),u=lue(n,e);w.useEffect(()=>{if(o&&u){let S=!1;const b=Lu();return b.onload=()=>{if(S)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),a(P.toDataURL()),c(o))},b.crossOrigin="anonymous",b.src=o,()=>{S=!0}}},[n,u,s,o]);const h=U("show crop preview",()=>e.id===n.getOnlySelectedShapeId()&&n.getCroppingShapeId()===e.id&&n.isIn("select.crop"),[n,e.id]),p=s&&(((y=r==null?void 0:r.props.mimeType)==null?void 0:y.includes("video"))||u),f=x5(e),g=o===l?null:o,m=p?i:l;if(!o&&!(r!=null&&r.props.src))return d.jsxs(di,{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",r&&"tl-image-container-loading"),style:f,children:r?null:d.jsx(S5,{})}),"url"in e.props&&e.props.url&&d.jsx(Fl,{url:e.props.url})]});const v=u?"anonymous":void 0;return d.jsxs(d.Fragment,{children:[h&&m&&d.jsx("div",{style:f,children:d.jsx("img",{className:"tl-image",style:{...fu(e),opacity:.1},crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),d.jsxs(di,{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:fu(e),crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},m),g&&d.jsx("img",{className:"tl-image",style:fu(e),crossOrigin:v,src:g,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>c(g)},g)]}),e.props.url&&d.jsx(Fl,{url:e.props.url})]})]})});function lue(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):void 0;return n?"mimeType"in n.props&&ar.isAnimatedImageType(n==null?void 0:n.props.mimeType)||"isAnimated"in n.props&&n.props.isAnimated:!1}function x5(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 fu(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 cue({shape:t,src:e}){const n=Jl(),r=x5(t),o=t.props.crop;if(r.transform&&o){const{transform:s,width:i,height:a}=r,l=(o.bottomRight.x-o.topLeft.x)*i,c=(o.bottomRight.y-o.topLeft.y)*a,u=[new x(0,0),new x(l,0),new x(l,c),new x(0,c)],h=fu(t,{width:i,height:a});return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:n,children:d.jsx("polygon",{points:u.map(p=>`${p.x},${p.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${n})`,children:d.jsx("image",{href:e,width:i,height:a,style:h?{...h,transform:`${s} ${h.transform}`}:{transform:s}})})]})}else return d.jsx("image",{href:e,width:t.props.w,height:t.props.h,style:fu(t,{width:t.props.w,height:t.props.h})})}function w5(t){return{size:t,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function b5(t,e,n){const r=e.vertices,o=w5(n);return Uo(r,o)}function uue(t,e,n){const r=w5(n);return kb(xm(b5(t,e,n),r),r)}function due(t,e,n){const r=uue(t,e,n);return S1(r)}function hue(t,e,n){if(t.props.dash==="draw"){const r=b5(t,e,n);return Sa(r)}return e.getSvgPathData()}function P5(t,e,n){let r=`M ${je(e[0])}L`,o=`M ${je(e[0])}L`;const s=n/3,i=n*2,a=co(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),y=x.Div(m,v).mul(Math.min(v/4,i)),S=x.Add(l,y),b=x.Add(c,y.neg()),P=x.Sub(h,u),C=x.Len(P),_=x.Div(P,C).mul(Math.min(C/4,i)),E=x.Add(u,_),k=x.Add(h,_.neg());f===g-1?(r+=`${je(S)}L ${je(c)}`,o+=`${je(E)}L ${je(h)}`):(r+=`${je(S)}L ${je(b)}Q ${je(c)}`,o+=`${je(E)}L ${je(k)}Q ${je(h)}`,l=c,u=h)}return[r,r+o]}const pue=new Ro;class Ep extends oo{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,n]=Fu(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 Zc(e)}getHandles(e){return pue.get(e.props,()=>{const n=Zc(e),r=qc(e),o=r.map(s=>({...s,id:s.index,type:"vertex",canSnap:!0}));for(let s=0;s<r.length-1;s++){const i=$u(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(cn)})}onResize(e,n){const{scaleX:r,scaleY:o}=n;return{props:{points:od(e.props.points,(s,{id:i,index:a,x:l,y:c})=>({id:i,index:a,x:l*r,y:c*o}))}}}onBeforeCreate(e){const{props:{points:n}}=e,r=Object.keys(n);if(r.length<2)return;const o=n[r[0]];if(r.every(i=>{const a=n[i];return a.x===o.x&&a.y===o.y})){const i=r[r.length-1];return n[i]={...n[i],x:n[i].x+.1,y:n[i].y+.1},e}}onHandleDrag(e,{handle:n}){if(n.type!=="vertex")return;const r=io(new x(n.x,n.y),this.editor);return{...e,props:{...e.props,points:{...e.props.points,[n.id]:{id:n.id,index:n.index,x:r.x,y:r.y}}}}}component(e){return d.jsx(gi,{children:d.jsx(ZE,{shape:e})})}indicator(e){const n=To[e.props.size]*e.props.scale,r=Zc(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]=P5(e.id,i,n);s=a}}else s=hue(e,r,n);return d.jsx("path",{d:s})}toSvg(e){return d.jsx(ZE,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const n=qc(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=Zc(e).segments.filter((i,a)=>a!==o-1&&a!==o);return s.length?new $r({children:s}):null}}}getInterpolatedProps(e,n,r){const o=qc(e),s=qc(n),i=[],a=[];let l=ZT;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=Io(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=Io(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:_e(c.x,h.x,r),y:_e(c.y,h.y,r)}]})),scale:_e(e.props.scale,n.props.scale,r)}}}I(Ep,"type","line"),I(Ep,"props",XA),I(Ep,"migrations",qA);function qc(t){return Object.values(t.props.points).sort(cn)}function Zc(t){const e=qc(t).map(x.From);switch(t.props.spline){case"cubic":return new fte({points:e});case"line":return new nc({points:e})}}function ZE({shape:t,shouldScale:e=!1,forceSolid:n=!1}){const r=zr(),o=Zc(t),{dash:s,color:i,size:a}=t.props,l=1/t.props.scale,c=e?l:1,u=To[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"}:qr(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]=P5(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}=qr(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:due(t,o,u),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${c})`})}}class kp extends oo{canEdit(){return!0}hideResizeHandles(){return!0}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(e){const{labelHeight:n,labelWidth:r}=C5(this.editor,e),{scale:o}=e.props,s=n*o,i=r*o,a=He*o,l=Nh(e);return new $r({children:[new No({width:a,height:l,isFilled:!0}),new No({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=Nh(e),i=He*n,a=jle/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:{labelColor:o,scale:s,color:i,font:a,size:l,align:c,text:u,verticalAlign:h,fontSizeAdjustment:p}}=e,f=mue(n),g=zr(),m=He*s,v=Nh(e),y=U("shape rotation",()=>{var C;return((C=this.editor.getShapePageTransform(n))==null?void 0:C.rotation())??0},[this.editor]),S=U("zoom",()=>this.editor.getZoomLevel()<.35/s,[s,this.editor]),b=U("dark mode",()=>this.editor.user.getIsDarkMode(),[this.editor]),P=e.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:n,className:"tl-note__container",style:{width:m,height:v,backgroundColor:g[i].note.fill,borderBottom:S?b?`${2*s}px solid rgb(20, 20, 20)`:`${2*s}px solid rgb(144, 144, 144)`:"none",boxShadow:S?"none":yue(e.id,y,s)},children:d.jsx(Cm,{shapeId:n,type:r,font:a,fontSize:(p||ys[l])*s,lineHeight:fn.lineHeight,align:c,verticalAlign:h,text:u,isNote:!0,isSelected:P,labelColor:o==="black"?g[i].note.text:g[o].fill,wrap:!0,padding:16*s,onKeyDown:f})}),"url"in e.props&&e.props.url&&d.jsx(Fl,{url:e.props.url})]})}indicator(e){const{scale:n}=e.props;return d.jsx("rect",{rx:n,width:N(He*n),height:N(Nh(e))})}toSvg(e,n){e.props.text&&n.addExportDef(bm(e.props.font));const r=ks({isDarkMode:n.isDarkMode}),o=Sue(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||ys[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 QE(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 QE(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:_e(e.props.scale,n.props.scale,r)}}}I(kp,"type","note"),I(kp,"props",ZA),I(kp,"migrations",QA);function QE(t,e){const{labelHeight:n,fontSizeAdjustment:r}=C5(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 fue(t,e){const{text:n}=e.props;if(!n)return{labelHeight:ys[e.props.size]*fn.lineHeight+Er*2,labelWidth:100,fontSizeAdjustment:0};const r=ys[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,{...fn,fontFamily:Cs[e.props.font],fontSize:o,maxWidth:He-Er*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Er*2,a=c.w+Er*2,o<=14){const u=t.textMeasure.measureText(n,{...fn,fontFamily:Cs[e.props.font],fontSize:o,maxWidth:He-Er*2-l});i=u.h+Er*2,a=u.w+Er*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const gue=new Ro;function C5(t,e){return gue.get(e,()=>fue(t,e))}function mue(t){const e=z(),n=JL();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"||Y$(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(wm.clone().mul(o.props.scale)).rot(l).add(a.point()),p=t5(e,o,h,l);p&&(e.markHistoryStoppingPoint("editing adjacent shape"),Kf(e,p,!0))}},[t,e,n.dir])}function Nh(t){return(He+t.props.growY)*t.props.scale}function yue(t,e,n){const r=co(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),
382
- 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)}),
383
- 0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+s)/2)).toFixed(2)})`}function Sue(t){return new Z(0,0,He,He+t.props.growY)}function vue(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 xue=new Ro;class Tp extends oo{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return xue.get(e.props,n=>JE(this.editor,n))}getGeometry(e){const{scale:n}=e.props,{width:r,height:o}=this.getMinDimensions(e);return new No({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=zr(),f=wue(n);return d.jsx(Cm,{shapeId:n,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:Ll[o],lineHeight:fn.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=z();return e.props.autoSize&&r.getEditingShapeId()===e.id?null:d.jsx("rect",{width:N(n.width),height:N(n.height)})}toSvg(e,n){e.props.text&&n.addExportDef(bm(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=ks(n);return d.jsx(Pm,{fontSize:Ll[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,...vue(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=JE(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}}}}I(Tp,"type","text"),I(Tp,"props",JA),I(Tp,"migrations",ej);function JE(t,e){const{font:n,text:r,autoSize:o,size:s,w:i}=e,a=o?16:Math.max(16,i),l=Ll[s],c=o?null:Math.floor(Math.max(a,i)),u=t.textMeasure.measureText(r,{...fn,fontFamily:Cs[n],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function wue(t){const e=z();return w.useCallback(n=>{if(e.getEditingShapeId()===t)switch(n.key){case"Enter":{(n.ctrlKey||n.metaKey)&&e.complete();break}case"Tab":{xe(n),n.shiftKey?$l.unindent(n.currentTarget):$l.indent(n.currentTarget);break}}},[e,t])}class Mp extends sc{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){return d.jsx(bue,{shape:e})}indicator(e){return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){const n=await Pue(this.editor,e);return n?d.jsx("image",{href:n,width:e.props.w,height:e.props.h}):null}}I(Mp,"type","video"),I(Mp,"props",tj),I(Mp,"migrations",nj);const bue=w.memo(function({shape:e}){const n=z(),r=n.getShapeGeometry(e).bounds.w*n.getZoomLevel()>=110,o=Zg(e.id),s=ZR(),{Spinner:i}=rt(),{asset:a,url:l}=v5({shapeId:e.id,assetId:e.props.assetId}),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&&o&&document.activeElement!==m&&m.focus()},[o,u]),w.useEffect(()=>{if(s){const m=c.current;if(!m)return;m.pause(),m.currentTime=0}},[c,s]),d.jsxs(d.Fragment,{children:[d.jsx(di,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:a?i&&!a.props.src?d.jsx(i,{}):l?d.jsxs(d.Fragment,{children:[d.jsx("video",{ref:c,style:o?{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:o&&r,onLoadedData:g,hidden:!u,children:d.jsx("source",{src:l})}),!u&&i&&d.jsx(i,{})]}):null:d.jsx(S5,{})})})}),"url"in e.props&&e.props.url&&d.jsx(Fl,{url:e.props.url})]})});async function Pue(t,e){const n=await t.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});if(!n)return null;const r=await ar.loadVideo(n);return ar.getVideoFrameAsDataUrl(r,0)}const _5=[Tp,wp,bp,Cp,kp,Ep,Pp,xp,_p,Jf,Ip,Mp];function Cue(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")}if(e.editingShapeId!==n.editingShapeId)if(!e.editingShapeId&&n.editingShapeId){if(!t.isIn("select.editing_shape")){const r=t.getEditingShape();r&&r.type==="text"&&t.isInAny("text.pointing","select.resizing")&&t.getInstanceState().isToolLocked?t.setCurrentTool("select.editing_shape",{isCreatingTextWhileToolLocked:!0}):t.setCurrentTool("select.editing_shape")}}else e.editingShapeId&&!n.editingShapeId&&t.isIn("select.editing_shape")&&t.setCurrentTool("select.idle")}}})}class I5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"scribbleId","id");I(this,"markId","");I(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.setErasingShapes([]),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&&!hr(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),y=m.applyToPoint(a),{bounds:S}=f;S.minX-u>Math.max(v.x,y.x)||S.minY-u>Math.max(v.y,y.y)||S.maxX+u<Math.min(v.x,y.x)||S.maxY+u<Math.min(v.y,y.y)||f.hitTestLineSegment(v,y,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),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}I(I5,"id","erasing");var WS;let _ue=(WS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(WS,"id","idle"),WS);var GS;let Iue=(GS=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)}onExit(e,n){n!=="erasing"&&this.editor.setErasingShapes([])}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.parent.transition("idle")}cancel(){this.parent.transition("idle")}},I(GS,"id","pointing"),GS);class Ap extends ie{static children(){return[_ue,Iue,I5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(Ap,"id","eraser"),I(Ap,"initial","idle"),I(Ap,"isLockable",!1);class E5 extends ie{constructor(){super(...arguments);I(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")}}I(E5,"id","dragging");var VS;let Eue=(VS=class extends ie{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(VS,"id","idle"),VS);var YS;let kue=(YS=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")}},I(YS,"id","pointing"),YS);class jp extends ie{static children(){return[Eue,kue,E5]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomIn(n,{animation:{duration:220,easing:Dt.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomOut(n,{animation:{duration:320,easing:Dt.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:Dt.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:Dt.easeOutQuint}})}}}I(jp,"id","hand"),I(jp,"initial","idle"),I(jp,"isLockable",!1);var XS;let Tue=(XS=class extends ie{onPointerDown(e){this.parent.transition("lasering",e)}},I(XS,"id","idle"),XS);class k5 extends ie{constructor(){super(...arguments);I(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")}}I(k5,"id","lasering");class Op extends ie{static children(){return[Tue,k5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(Op,"id","laser"),I(Op,"initial","idle"),I(Op,"isLockable",!1);class T5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"initialSelectedShapeIds",[]);I(this,"excludedShapeIds",new Set);I(this,"isWrapMode",!1);I(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,y,S;const b=n.getCurrentPageRenderingShapesSorted(),P=n.getCurrentPageId();e:for(let E=0,k=b.length;E<k;E++){if(m=b[E],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(y=n.getShapePageTransform(m),!y)continue e;S=y.clone().invert().applyToPoints(p);const D=n.getShapeGeometry(m);t:for(let T=0;T<4;T++)if(f=S[T],g=S[(T+1)%4],D.hitTestLineSegment(f,g,0)){this.handleHit(m,i,P,c,p);break t}}}const C=n.getInstanceState().brush;(!C||!h.equals(C))&&n.updateInstanceState({brush:{...h.toJson()}});const _=n.getSelectedShapeIds();(_.length!==c.size||_.some(E=>!c.has(E)))&&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&&!_1(l,i)&&!hr(r,l)||s.add(a.id)}}I(T5,"id","brushing");const zl={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 M5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){const n=this.editor.getSelectedShapes(),r=zl[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.getIsReadonly()||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")}}I(M5,"id","pointing_resize_handle");const _r=8;class $b extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(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=zl[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<_r)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/g,g*(u.bottomRight.y-u.topLeft.y)<_r?(u.topLeft.y=u.bottomRight.y-_r/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<_r)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/g),g*(u.bottomRight.y-u.topLeft.y)<_r&&(u.bottomRight.y=u.topLeft.y+_r/g);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<_r)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<_r?(u.topLeft.x=u.bottomRight.x-_r/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<_r)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<_r&&(u.bottomRight.x=u.topLeft.x+_r/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(),Ye(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}}}I($b,"id","cropping");function A5(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 j5(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 qS;let Mue=(qS=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(e.accelKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{const r=A5(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=j5(this.editor,s,o);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},I(qS,"id","idle"),qS);class O5 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)}}I(O5,"id","pointing_crop");class Fb extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=zl[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.getIsReadonly()||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"))}}I(Fb,"id","pointing_crop_handle");class D5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(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=j5(this.editor,n,s);i&&this.editor.updateShapes([i])}}I(D5,"id","translating_crop");class d0 extends ie{constructor(){super(...arguments);I(this,"markId","");I(this,"didExit",!1)}static children(){return[Mue,D5,O5,Fb,$b]}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))}}I(d0,"id","crop"),I(d0,"initial","idle");class R5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"initialHandle",{});I(this,"initialAdjacentHandle",null);I(this,"initialPagePoint",{});I(this,"markId","");I(this,"initialPageTransform");I(this,"initialPageRotation");I(this,"info",{});I(this,"isPrecise",!1);I(this,"isPreciseId",null);I(this,"pointingId",null);I(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(cn),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=Un(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(),Ye(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 E;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,y=n.getShape(r);if(!y)return;const S=n.getShapeUtil(y);let b=h.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const k=x.Angle(a,b),T=Df(k,24)-k;b=x.RotWith(b,a,T)}n.snaps.clearIndicators();let P={...s,x:b.x,y:b.y};if(s.canSnap&&(c?!f:f)){if(!n.getShapePageTransform(y.id))throw Error("Expected a page transform");const D=u.handles.snapHandle({currentShapeId:r,handle:P});D&&(D.nudge.rot(-n.getShapeParentTransform(y).rotation()),b.add(D.nudge),P={...s,x:b.x,y:b.y})}const C=(E=S.onHandleDrag)==null?void 0:E.call(S,y,{handle:P,isPrecise:this.isPrecise||g,initial:v}),_={id:y.id,type:y.type,...C};if(s.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const k=Un(n,y)[s.id];k?l[0]!==k.toId&&(n.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=m.len()<.5||g,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&n.updateShapes([_])}}I(R5,"id","dragging_handle");function L5(t){return t.isLabel?[t]:t instanceof $r?t.children.filter(e=>e.isLabel):[]}class $5 extends ie{constructor(){super(...arguments);I(this,"hitShapeForPointerUp",null);I(this,"info",{})}onEnter(n){const r=this.editor.getEditingShape();if(!r)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,this.info=n,n.isCreatingTextWhileToolLocked&&this.parent.setCurrentToolIdMask("text"),ds(this.editor),this.editor.select(r)}onExit(){var s;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),ds.cancel();const r=this.editor.getShape(n),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r),this.info.isCreatingTextWhileToolLocked&&(this.parent.setCurrentToolIdMask(void 0),this.editor.setCurrentTool("text",{}))}onPointerMove(n){if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getIsReadonly()||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":{ds(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=L5(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.getIsReadonly()&&!o.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),ds(this.editor)}}onComplete(n){this.parent.transition("idle",n)}onCancel(n){this.parent.transition("idle",n)}}I($5,"id","editing_shape");function e2(t){const e=t.getOnlySelectedShape();return!!(e&&!t.isShapeOrAncestorLocked(e)&&t.getShapeUtil(e).canCrop(e))}function eg(t,e){const n=t.getSelectedShapeIds(),{currentPagePoint:r}=t.inputs,{shiftKey:o,altKey:s,accelKey:i}=e,a=o||i,l=t.getShapeAtPoint(r,{hitInside:!1,margin:t.options.hitTestMargin/t.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:c=>!c.isLocked});if(l){const c=t.getOutermostSelectableShape(l);if(a&&!s)t.cancelDoubleClick(),n.includes(c.id)?(t.markHistoryStoppingPoint("deselecting shape"),t.deselect(c)):(t.markHistoryStoppingPoint("shift selecting shape"),t.setSelectedShapes([...n,c.id]));else{let u;c===l||c.id===t.getFocusedGroupId()||n.includes(c.id)?u=l:u=c,u&&!n.includes(u.id)&&(t.markHistoryStoppingPoint("selecting shape"),t.select(u.id))}}else{if(a)return;{n.length>0&&(t.markHistoryStoppingPoint("selecting none"),t.selectNone());const c=t.getFocusedGroupId();if(Fn(c)){const u=t.getShape(c);t.isPointInShape(u,r,{margin:0,hitInside:!0})||t.setFocusedGroup(null)}}}}const Aue=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var ZS;let jue=(ZS=class extends ie{onEnter(){this.parent.setCurrentToolIdMask(void 0),ds(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){ds.cancel()}onPointerMove(){ds(this.editor)}onPointerDown(e){const n=e.ctrlKey&&e2(this.editor);switch(e.target){case"canvas":{const r=A5(this.editor);if(r&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}const o=this.editor.getSelectedShapeIds(),s=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((o.length>1||s&&!this.editor.getShapeUtil(s).hideSelectionBoundsBg(s))&&t2(this.editor,i)){this.onPointerDown({...e,target:"selection"});return}this.parent.transition("pointing_canvas",e);break}case"shape":{const{shape:r}=e;if(this.isOverArrowLabelTest(r)){this.parent.transition("pointing_arrow_label",e);break}if(this.editor.isShapeOrAncestorLocked(r)){this.parent.transition("pointing_canvas",e);break}this.parent.transition("pointing_shape",e);break}case"handle":{if(this.editor.getIsReadonly())break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",e):this.parent.transition("pointing_handle",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":{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_rotate_handle",e);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{if(n)this.parent.transition("crop.pointing_crop_handle",e);else{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_resize_handle",e)}break}default:{const r=this.editor.getHoveredShape();if(r&&!this.editor.getSelectedShapeIds().includes(r.id)&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}this.parent.transition("pointing_selection",e)}}break}}}onDoubleClick(e){var n,r,o,s;if(!(this.editor.inputs.shiftKey||e.phase!=="up")&&!(e.ctrlKey||e.shiftKey))switch(e.target){case"canvas":{const i=this.editor.getHoveredShape(),a=i&&!this.editor.isShapeOfType(i,"group")?i:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(a){if(this.editor.isShapeOfType(a,"group")){eg(this.editor,e);return}else{const c=this.editor.getShape(a.parentId);if(c&&this.editor.isShapeOfType(c,"group")&&!(l&&c.id===l)){eg(this.editor,e);return}}this.onDoubleClick({...e,shape:a,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(e);break}case"selection":{if(this.editor.getIsReadonly())break;const i=this.editor.getOnlySelectedShape();if(i){const a=this.editor.getShapeUtil(i);if(!this.canInteractWithShapeInReadOnly(i))return;if(e.handle==="right"||e.handle==="left"||e.handle==="top"||e.handle==="bottom"){const l=(n=a.onDoubleClickEdge)==null?void 0:n.call(a,i);if(l){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([l]),Ye(this.editor,[i.id]);return}}if(a.canCrop(i)&&!this.editor.isShapeOrAncestorLocked(i)){this.parent.transition("crop",e);return}this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}break}case"shape":{const{shape:i}=e,a=this.editor.getShapeUtil(i);if(i.type!=="video"&&i.type!=="embed"&&this.editor.getIsReadonly())break;if(a.onDoubleClick){const l=(r=a.onDoubleClick)==null?void 0:r.call(a,i);if(l){this.editor.updateShapes([l]);return}}if(a.canCrop(i)&&!this.editor.isShapeOrAncestorLocked(i)){this.editor.markHistoryStoppingPoint("select and crop"),this.editor.select((o=e.shape)==null?void 0:o.id),this.parent.transition("crop",e);return}this.shouldStartEditingShape(i)?this.startEditingShape(i,e,!0):this.handleDoubleClickOnCanvas(e);break}case"handle":{if(this.editor.getIsReadonly())break;const{shape:i,handle:a}=e,l=this.editor.getShapeUtil(i),c=(s=l.onDoubleClickHandle)==null?void 0:s.call(l,i,a);c?this.editor.updateShapes([c]):this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}}}onRightClick(e){switch(e.target){case"canvas":{const n=this.editor.getHoveredShape(),r=n&&!this.editor.isShapeOfType(n,"group")?n:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!0,renderingOnly:!0});if(r){this.onRightClick({...e,shape:r,target:"shape"});return}const o=this.editor.getSelectedShapeIds(),s=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((o.length>1||s&&!this.editor.getShapeUtil(s).hideSelectionBoundsBg(s))&&t2(this.editor,i)){this.onRightClick({...e,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:n}=this.editor.getCurrentPageState(),{shape:r}=e,o=this.editor.getOutermostSelectableShape(r,s=>!n.includes(s.id));!n.includes(o.id)&&!this.editor.findShapeAncestor(o,s=>n.includes(s.id))&&(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([o.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(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(bt.editOnType.get()&&!Aue.includes(e.key)&&!e.altKey&&!e.ctrlKey){const n=this.editor.getOnlySelectedShape();if(n&&this.editor.isShapeOfType(n,"note")&&this.shouldStartEditingShape(n)){this.startEditingShape(n,{...e,target:"shape",shape:n},!0);return}}}onKeyRepeat(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}}onKeyUp(e){switch(e.code){case"Enter":{const n=this.editor.getSelectedShapes();if(n.every(o=>this.editor.isShapeOfType(o,"group"))){this.editor.setSelectedShapes(n.flatMap(o=>this.editor.getSortedChildIdsForParent(o.id)));return}const r=this.editor.getOnlySelectedShape();if(r&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...e,target:"shape",shape:r},!0);return}e2(this.editor)&&this.parent.transition("crop",e);break}}}shouldStartEditingShape(e=this.editor.getOnlySelectedShape()){return!e||this.editor.isShapeOrAncestorLocked(e)&&e.type!=="embed"||!this.canInteractWithShapeInReadOnly(e)?!1:this.editor.getShapeUtil(e).canEdit(e)}startEditingShape(e,n,r){this.editor.isShapeOrAncestorLocked(e)&&e.type!=="embed"||(this.editor.markHistoryStoppingPoint("editing shape"),Kf(this.editor,e,r),this.parent.transition("editing_shape",n))}isOverArrowLabelTest(e){if(!e)return!1;const n=this.editor.getPointInShapeSpace(e,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(e,"arrow")){const r=this.editor.getShapeGeometry(e).children[1];if(r&&hr(n,r.vertices))return!0}return!1}handleDoubleClickOnCanvas(e){if(this.editor.getIsReadonly()||!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");const n=Ke(),{x:r,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:n,type:"text",x:r,y:o,props:{text:"",autoSize:!0}}]);const s=this.editor.getShape(n);if(!s)return;const i=this.editor.getShapeUtil(s);this.editor.getIsReadonly()&&!i.canEditInReadOnly(s)||(this.editor.setEditingShape(n),this.editor.select(n),this.parent.transition("editing_shape",e))}nudgeSelectedShapes(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;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:s}=this.editor.getDocumentSettings(),i=this.editor.getInstanceState().isGridMode?r?s*Rue:s:r?Oue:Due,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,o.mul(i)),Ye(this.editor,a)}canInteractWithShapeInReadOnly(e){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(e).canEditInReadOnly(e))}},I(ZS,"id","idle"),ZS);const Oue=10,Due=1,Rue=5;function t2(t,e){const n=t.getSelectionRotatedPageBounds();if(!n)return!1;const r=t.getSelectionRotation();return r?hr(e,n.corners.map(o=>x.RotWith(o,n.point,r))):n.containsPoint(e)}class F5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"markId","");I(this,"wasAlreadySelected",!1);I(this,"didDrag",!1);I(this,"didCtrlOnEnter",!1);I(this,"info",{});I(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.didCtrlOnEnter=n.accelKey,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;if(this.didCtrlOnEnter){this.parent.transition("brushing",this.info);return}const r=this.editor.getShape(this.shapeId);if(!r)return;const o=ko(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=xx(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.getIsReadonly()||(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")}}I(F5,"id","pointing_arrow_label");class N5 extends ie{onEnter(e){e.shiftKey||e.accelKey||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(e){eg(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}I(N5,"id","pointing_canvas");class z5 extends ie{constructor(){super(...arguments);I(this,"didCtrlOnEnter",!1);I(this,"info",{})}onEnter(n){this.info=n,this.didCtrlOnEnter=n.accelKey;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const o=Un(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=n2(o,n,r,!1);if(s){Kf(o,s,!0);return}}this.parent.transition("idle",this.info)}onPointerMove(n){const{editor:r}=this;r.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",n):this.startDraggingHandle())}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){const{editor:n}=this;if(n.getIsReadonly())return;const{shape:r,handle:o}=this.info;if(n.isShapeOfType(r,"note")){const s=n2(n,r,o,!0);if(s){const i=n.getPointInParentSpace(s,n.inputs.originPagePoint).sub(x.Rot(wm.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:()=>{Kf(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")}}I(z5,"id","pointing_handle");function n2(t,e,n,r){const o=t.getShapePageTransform(e.id),s=o.point(),i=o.rotation(),l=J$(t,s,i,e.props.growY,0,e.props.scale)[n.index];if(l)return t5(t,e,l,i,r)}class B5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){this.editor.setCursor({type:zl[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.getIsReadonly()||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")}}I(B5,"id","pointing_rotate_handle");class U5 extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerUp(n){eg(this.editor,n),this.parent.transition("idle",n)}onPointerMove(n){this.editor.inputs.isDragging&&this.startTranslating(n)}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getIsReadonly()||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")}}I(U5,"id","pointing_selection");class H5 extends ie{constructor(){super(...arguments);I(this,"hitShape",{});I(this,"hitShapeForPointerUp",{});I(this,"isDoubleClick",!1);I(this,"didCtrlOnEnter",!1);I(this,"didSelectOnEnter",!1)}onEnter(n){const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i}}=this.editor,{shiftKey:a,altKey:l,accelKey:c}=n;this.hitShape=n.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=c;const u=this.editor.getOutermostSelectableShape(n.shape),h=this.editor.findShapeAncestor(u,p=>r.includes(p.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(n.shape).onClick||u.id===s||r.includes(u.id)||h||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=u;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(u.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...r,u.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([u.id]))}onPointerUp(n){var u;const r=this.editor.getSelectedShapeIds(),o=this.editor.getFocusedGroupId(),s=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i}}=this.editor,a=n.shiftKey||n.accelKey,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=L5(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.getIsReadonly()&&!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.didCtrlOnEnter?this.parent.transition("brushing",n):this.startTranslating(n))}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getIsReadonly()||(this.editor.focus(),this.parent.transition("translating",n))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(H5,"id","pointing_shape");class K5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"didHoldCommand",!1);I(this,"creationCursorOffset",{x:0,y:0});I(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(Ye(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 k=[...s.values()][0];this.editor.isShapeOfType(k.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),g=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:k}=this.editor.getDocumentSettings();f.snapToGrid(k)}const m=this.info.handle,v=r2(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%qe===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:x.Sub(f,g),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:r2(m,c),isAspectRatioLocked:h,isResizingFromCenter:n});f.add(k)}const S=x.RotWith(n?i.center:i.getHandlePoint(v),i.point,c),b=x.Sub(f,S).rot(-c),P=x.Sub(g,S).rot(-c),C=x.DivV(b,P);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const _=m==="top"||m==="bottom",E=m==="left"||m==="right";h?E?C.y=Math.abs(C.x):_?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):(_&&(C.x=1),E&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:c});for(const k of s.keys()){const D=s.get(k);this.editor.resizeShape(k,C,{initialShape:D.shape,initialBounds:D.bounds,initialPageTransform:D.pageTransform,dragHandle:m,mode:l.length===1&&k===l[0]?"resize_bounds":"scale_shape",scaleOrigin:S,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:D}of o){if(!D.length)continue;const T=s.get(k).shape,j=this.editor.getShape(k);if(!(T&&j))continue;const $=j.x-T.x,M=j.y-T.y,O=new x($,M).rot(-T.rotation);if(O.x!==0||O.y!==0)for(const F of D)this.editor.updateShape({id:F.id,type:F.type,x:F.x-O.x,y:F.y-O.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of o)if(k.length)for(const D of k)this.editor.updateShape({id:D.id,type:D.type,x:D.x,y:D.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:me(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=>!lj(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)}}}I(K5,"id","resizing");const IS=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function r2(t,e){e=e%Ne;const n=Math.round(e/(De/4)),r=IS.indexOf(t);return IS[(r+n)%IS.length]}const o2=Math.PI/180;class W5 extends ie{constructor(){super(...arguments);I(this,"snapshot",{});I(this,"info",{});I(this,"markId","")}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=yO({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});up({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:zl[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});up({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:zl[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(){up({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ye(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=Df(h,24);else if(n&&(h=Math.round(h/o2)*o2,this.editor.getInstanceState().isCoarsePointer)){const p=Df(h,4),f=ap(h,p);Math.abs(f)<mX(5)&&(h=p)}return h-l}}I(W5,"id","rotating");class G5 extends ie{constructor(){super(...arguments);I(this,"hits",new Set);I(this,"size",0);I(this,"scribbleId","id");I(this,"initialSelectedShapeIds",new Set);I(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 _=C.clone().invert();g=_.applyToPoint(a),m=_.applyToPoint(l);const{bounds:E}=f;if(!(E.minX-v>Math.max(g.x,m.x)||E.minY-v>Math.max(g.y,m.y)||E.maxX+v<Math.min(g.x,m.x)||E.maxY+v<Math.min(g.y,m.y))&&f.hitTestLineSegment(g,m,v)){const k=this.editor.getOutermostSelectableShape(p),D=this.editor.getShapeMask(k.id);if(D&&P1(a,l,D)!==null&&!hr(l,D))continue;c.add(k.id)}}const y=r.getSelectedShapeIds(),S=new Set(s?[...c,...u]:[...c]);(y.length!==S.size||y.some(b=>!S.has(b)))&&this.editor.setSelectedShapes(Array.from(S))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}I(G5,"id","scribble_brushing");var Lue=Object.create,V5=Object.defineProperty,$ue=Object.getOwnPropertyDescriptor,Fue=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Y5=t=>{throw TypeError(t)},X5=(t,e,n)=>e in t?V5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nue=t=>[,,,Lue(null)],q5=["class","method","getter","setter","accessor","field","value","get","set"],Z5=t=>t!==void 0&&typeof t!="function"?Y5("Function expected"):t,zue=(t,e,n,r,o)=>({kind:q5[t],name:e,metadata:r,addInitializer:s=>n._?Y5("Already initialized"):o.push(Z5(s||null))}),Bue=(t,e)=>X5(e,Fue("metadata"),t[3]),Uue=(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},Hue=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=q5[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,$ue(o,n)),y=r.length-1;y>=0;y--)l=zue(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,Z5(i)&&(v[g]=i);return v&&V5(o,n,v),o},ES=(t,e,n)=>X5(t,typeof e!="symbol"?e+"":e,n),Q5,Im;const Kue=20,Wue=100;Q5=[Kn];class Nb{constructor(e){this.editor=e,Uue(Im,5,this),ES(this,"prevDroppingShapeId",null),ES(this,"droppingNodeTimer",null),ES(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,Kue,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Wue,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=me(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&&qL(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()}}Im=Nue();Hue(Im,1,"dispose",Q5,Nb);Bue(Im,Nb);var Gue=Object.create,J5=Object.defineProperty,Vue=Object.getOwnPropertyDescriptor,eF=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),tF=t=>{throw TypeError(t)},nF=(t,e,n)=>e in t?J5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Yue=t=>[,,,Gue((t==null?void 0:t[eF("metadata")])??null)],rF=["class","method","getter","setter","accessor","field","value","get","set"],oF=t=>t!==void 0&&typeof t!="function"?tF("Function expected"):t,Xue=(t,e,n,r,o)=>({kind:rF[t],name:e,metadata:r,addInitializer:s=>n._?tF("Already initialized"):o.push(oF(s||null))}),que=(t,e)=>nF(e,eF("metadata"),t[3]),Zue=(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},Que=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=rF[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,Vue(o,n)),y=r.length-1;y>=0;y--)l=Xue(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,oF(i)&&(v[g]=i);return v&&J5(o,n,v),o},Us=(t,e,n)=>nF(t,typeof e!="symbol"?e+"":e,n),sF,h0,Em;class km extends(h0=ie,sF=[Kn],h0){constructor(){super(...arguments),Zue(Em,5,this),Us(this,"info",{}),Us(this,"selectionSnapshot",{}),Us(this,"snapshot",{}),Us(this,"markId",""),Us(this,"isCloning",!1),Us(this,"isCreating",!1),Us(this,"dragAndDropManager",new Nb(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=s2(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=s2(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),Ye(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),Jue({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=Rn(o.parentId)?null:q.Inverse(e.getShapePageTransform(o.parentId));r.parentTransform=s})}}Em=Yue(h0);Que(Em,1,"updateParentTransforms",sF,km);que(Em,km);Us(km,"id","translating");function s2(t){var h;const e=[],n=[],r=t.getSelectedShapeIds(),o=me(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 y=yr.isId(f.parentId)?null:q.Inverse(t.getShapePageTransform(f.parentId));return{shape:f,pagePoint:m,pageRotation:v,parentTransform:y}})),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=e5(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 Jue({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;p==="x"?h.x=0:p==="y"&&(h.y=0),t.snaps.clearIndicators();const f=t.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey;let g=!1;if(f&&t.inputs.pointerVelocity.len()<.5){const{nudge:S}=t.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:s,lockedAxis:p,initialSelectionSnapPoints:i});h.add(S)}else if(r&&o){const{scale:S}=r.shape.props,b=r.pagePoint.clone().add(h).add(wm.clone().mul(S).rot(r.pageRotation));let P=Q$/t.getZoomLevel(),C=new x(0,0);for(const _ of o){const E=x.Sub(b,_),k=E.len();k<P&&(g=!0,P=k,C=E)}h.sub(C)}const m=x.Add(l,h),v=t.snaps.getIndicators();c&&!n.ctrlKey&&!g&&v.length===0&&m.snapToGrid(u);const y=x.Sub(m,l);t.updateShapes(me(a.map(({shape:S,pagePoint:b,parentTransform:P})=>{const C=x.Add(b,y),_=P?q.applyToPoint(P,C):C;return{id:S.id,type:S.type,x:_.x,y:_.y}})))}class Dp extends ie{constructor(){super(...arguments);I(this,"reactor")}static children(){return[d0,$b,jue,N5,H5,km,T5,G5,Fb,U5,M5,$5,K5,W5,B5,F5,z5,R5]}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=jo("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){console.error(n)}})}onExit(){var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}I(Dp,"id","select"),I(Dp,"initial","idle"),I(Dp,"isLockable",!1);class iF extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerDown(){this.parent.transition("pointing",this.info)}}I(iF,"id","idle");class aF extends ie{constructor(){super(...arguments);I(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)}}I(aF,"id","pointing");class lF extends ie{constructor(){super(...arguments);I(this,"info",{});I(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)}}I(lF,"id","zoom_brushing");class Rp extends ie{constructor(){super(...arguments);I(this,"info",{})}static children(){return[iF,lF,aF]}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})}}I(Rp,"id","zoom"),I(Rp,"initial","idle"),I(Rp,"isLockable",!1);const ede=[Ap,jp,Op,Rp,Dp];function tde(){const t=z(),e=U("follow",()=>t.getInstanceState().followingUserId,[t]);return e?d.jsx(nde,{userId:e}):null}function nde({userId:t}){const e=Lg(t);return e?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let p0={fonts:{draw:`${ei()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${ei()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${ei()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${ei()}/fonts/IBMPlexMono-Medium.woff2`}};function cF(t){return w.useMemo(()=>t?{fonts:{...p0.fonts,...t==null?void 0:t.fonts}}:p0,[t])}const rde=["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 Rc={...p0,icons:Object.fromEntries(rde.map(t=>[t,`${ei()}/icons/icon/0_merged.svg#${t}`])),translations:Object.fromEntries(Bu.map(t=>[t.locale,`${ei()}/translations/${t.locale}.json`])),embedIcons:Object.fromEntries(Sb.map(t=>[t.type,`${ei()}/embed-icons/${t.type}.png`]))};function ode(t){return t?{fonts:Object.assign({...Rc.fonts},{...t==null?void 0:t.fonts}),icons:Object.assign({...Rc.icons},{...t==null?void 0:t.icons}),embedIcons:Object.assign({...Rc.embedIcons},{...t==null?void 0:t.embedIcons}),translations:Object.assign({...Rc.translations},{...t==null?void 0:t.translations})}:Rc}var zb="Popover",[uF,Oge]=Go(zb,[om]),kd=om(),[sde,Oi]=uF(zb),dF=t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=t,a=kd(e),l=w.useRef(null),[c,u]=w.useState(!1),[h=!1,p]=Ai({prop:r,defaultProp:o,onChange:s});return d.jsx(X1,{...a,children:d.jsx(sde,{scope:e,contentId:ms(),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})})};dF.displayName=zb;var hF="PopoverAnchor",ide=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Oi(hF,n),s=kd(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=o;return w.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(q1,{...s,...r,ref:e})});ide.displayName=hF;var pF="PopoverTrigger",fF=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Oi(pF,n),s=kd(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":vF(o.open),...r,ref:i,onClick:oe(t.onClick,o.onOpenToggle)});return o.hasCustomAnchor?a:d.jsx(q1,{asChild:!0,...s,children:a})});fF.displayName=pF;var Bb="PopoverPortal",[ade,lde]=uF(Bb,{forceMount:void 0}),gF=t=>{const{__scopePopover:e,forceMount:n,children:r,container:o}=t,s=Oi(Bb,e);return d.jsx(ade,{scope:e,forceMount:n,children:d.jsx(ho,{present:n||s.open,children:d.jsx(Pd,{asChild:!0,container:o,children:r})})})};gF.displayName=Bb;var Bl="PopoverContent",mF=w.forwardRef((t,e)=>{const n=lde(Bl,t.__scopePopover),{forceMount:r=n.forceMount,...o}=t,s=Oi(Bl,t.__scopePopover);return d.jsx(ho,{present:r||s.open,children:s.modal?d.jsx(cde,{...o,ref:e}):d.jsx(ude,{...o,ref:e})})});mF.displayName=Bl;var cde=w.forwardRef((t,e)=>{const n=Oi(Bl,t.__scopePopover),r=w.useRef(null),o=Ze(e,r),s=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return Z1(i)},[]),d.jsx(am,{as:ha,allowPinchZoom:!0,children:d.jsx(yF,{...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})})})}),ude=w.forwardRef((t,e)=>{const n=Oi(Bl,t.__scopePopover),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(yF,{...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()}})}),yF=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=Oi(Bl,n),f=kd(n);return N1(),d.jsx(em,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(wd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:d.jsx(C3,{"data-state":vF(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)"}})})})}),SF="PopoverClose",dde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Oi(SF,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});dde.displayName=SF;var hde="PopoverArrow",pde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=kd(n);return d.jsx(_3,{...o,...r,ref:e})});pde.displayName=hde;function vF(t){return t?"open":"closed"}var Ub=dF,Hb=fF,Kb=gF,Wb=mF;function Gb({id:t,children:e,onOpenChange:n,open:r}){const[o,s]=Ms(t,n);return d.jsx(Ub,{onOpenChange:s,open:r||o,children:d.jsx("div",{className:"tlui-popover",children:e})})}function Vb({children:t}){return d.jsx(Hb,{asChild:!0,dir:"ltr",children:t})}function Yb({side:t,children:e,align:n="center",sideOffset:r=8,alignOffset:o=0,disableEscapeKeyDown:s=!1}){const i=Mt();return d.jsx(Kb,{container:i,children:d.jsx(Wb,{className:"tlui-popover__content",side:t,sideOffset:r,align:n,alignOffset:o,dir:"ltr",onEscapeKeyDown:a=>s&&a.preventDefault(),children:e})})}function fde(t){return t.getSelectedShapeIds().map(r=>t.getShape(r)).filter(r=>{if(!r)return!1;if(t.isShapeOfType(r,"arrow")){const o=Un(t,r);if(o.start||o.end)return!1}return!0})}const xF=()=>{const t=z();return U("threeStackableItems",()=>fde(t).length>2,[t])},As=()=>{const t=z();return U("isInSelectState",()=>t.isIn("select"),[t])},wF=()=>{const t=z();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=Un(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])},bF=()=>{const t=z();return U("allowUngroup",()=>t.getSelectedShapeIds().some(e=>{var n;return((n=t.getShape(e))==null?void 0:n.type)==="group"}),[t])},gde=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function PF(t,e){const n=z();return U("selectedShapes",()=>n.getSelectedShapes().length>=t,[n,t,e])}function jn(t,e){const n=z();return U("selectedShapes",()=>{const r=n.getSelectedShapes().filter(o=>!n.isShapeOrAncestorLocked(o)).length;return t===void 0?r:r>=t},[n])}function mde(){const t=z();return U("showAutoSizeToggle",()=>{const e=t.getSelectedShapes();return e.length===1&&t.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[t])}function CF(){const t=z();return U("hasLinkShapeSelected",()=>{const e=t.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[t])}function yde(){const t=z();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 _F(){const t=z();return U("useCanRedo",()=>t.getCanRedo(),[t])}function IF(){const t=z();return U("useCanUndo",()=>t.getCanUndo(),[t])}function Sde(){return d.jsxs(d.Fragment,{children:[d.jsx(vde,{}),d.jsx(xde,{}),d.jsx(wde,{}),d.jsx(bde,{}),d.jsx(Pde,{}),d.jsx(Ide,{}),d.jsx(Ede,{}),d.jsx(kde,{})]})}function vde(){const t=jn(2),e=As(),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 xde(){const t=jn(3),e=As(),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 wde(){const t=xF(),e=As(),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 bde(){const t=jn(1),e=As(),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 Pde(){return An()<St.TABLET_SM?d.jsx(Cde,{}):d.jsx(_de,{})}function Cde(){const t=z(),e=U("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",disabled:e})}function _de(){const t=jn(1),e=As(),n=t&&e;return d.jsx(W,{actionId:"rotate-ccw",disabled:!n})}function Ide(){const t=jn(1),e=As(),n=t&&e;return d.jsx(W,{actionId:"rotate-cw",disabled:!n})}function Ede(){const t=CF(),e=As(),n=t&&e;return d.jsx(W,{actionId:"edit-link",disabled:!n})}function kde(){const t=wF(),e=bF();return t?d.jsx(i2,{}):e?d.jsx(Tde,{}):d.jsx(i2,{})}function i2(){const t=jn(2),e=As(),n=t&&e;return d.jsx(W,{actionId:"group",disabled:!n})}function Tde(){return d.jsx(W,{actionId:"ungroup"})}const Mde=w.memo(function({children:e}){const n=Ee(),r=An(),o=wr(),s=w.useRef(null);Mi(s);const i=z(),a=U("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),l=e??d.jsx(Sde,{});if(!(o&&!a))return d.jsxs(Gb,{id:"actions-menu",children:[d.jsx(Vb,{children:d.jsx(ce,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(Yb,{side:r>=St.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{ref:s,className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(Fr,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function EF(){return mde()?d.jsx(W,{actionId:"toggle-auto-size"}):null}function kF(){return CF()?d.jsx(W,{actionId:"edit-link"}):null}function Ade(){return jn(1)?d.jsx(W,{actionId:"duplicate"}):null}function TF(){const t=z();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 MF(){return wF()?d.jsx(W,{actionId:"group"}):null}function AF(){return bF()?d.jsx(W,{actionId:"ungroup"}):null}function jF(){const t=z();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 OF(){const t=z();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 DF(){const t=z();return U("selected shapes",()=>t.getSelectedShapes().length>0,[t])?d.jsx(W,{actionId:"toggle-lock"}):null}function Xb(){const t=z(),e=U("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(fo,{actionId:"toggle-transparent",checked:e,toggle:!0})}function jde(){const t=z(),e=U("any shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"unlock-all",disabled:!e})}function RF(){const t=z(),e=U("zoomed to 100",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function LF(){const t=z(),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 $F(){const t=z(),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 FF(){return d.jsxs(ve,{id:"clipboard",children:[d.jsx(Dde,{}),d.jsx(Rde,{}),d.jsx(Lde,{}),d.jsx(Ade,{}),d.jsx($de,{})]})}function Ode(){var n;const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsxs(Jn,{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(Xb,{})})]})}function Dde(){const t=jn(1);return d.jsx(W,{actionId:"cut",disabled:!t})}function Rde(){const t=PF(1);return d.jsx(W,{actionId:"copy",disabled:!t})}function Lde(){const t=gde;return d.jsx(W,{actionId:"paste",disabled:!t})}function NF(){const t=z();return U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t])?d.jsxs(ve,{id:"conversions",children:[d.jsx(Ode,{}),d.jsxs(Jn,{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(Xb,{})})]})]}):null}function zF(){const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"select-all",disabled:!e})}function $de(){const t=jn(1);return d.jsx(W,{actionId:"delete",disabled:!t})}function Fde(){const t=wr();return!PF(1)||t?null:d.jsxs(Jn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(MF,{}),d.jsx(AF,{}),d.jsx(TF,{}),d.jsx(kF,{}),d.jsx(OF,{}),d.jsx(jF,{}),d.jsx(UF,{}),d.jsx(BF,{}),d.jsx(EF,{}),d.jsx(DF,{})]})}function Nde(){const t=jn(2),e=yde();return wr()||!(t||e)?null:d.jsxs(Jn,{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(zde,{}),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(Bde,{})]})}function zde(){return jn(3)?d.jsxs(ve,{id:"distribute",children:[d.jsx(W,{actionId:"distribute-horizontal"}),d.jsx(W,{actionId:"distribute-vertical"})]}):null}function Bde(){const t=jn(2),e=xF();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 Ude(){const t=wr(),e=jn(1);return t||!e?null:d.jsx(Jn,{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"})]})})}function Hde(){const t=z(),e=U("pages",()=>t.getPages(),[t]),n=U("current page id",()=>t.getCurrentPageId(),[t]),{addToast:r}=Ts(),o=Qt(),s=wr();return!jn(1)||s?null:d.jsxs(Jn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ve,{id:"pages",children:e.map(a=>d.jsx(Ht,{id:a.id,disabled:n===a.id,label:a.name.length>30?`${a.name.slice(0,30)}…`:a.name,onSelect:()=>{t.markHistoryStoppingPoint("move_shapes_to_page"),t.moveShapesToPage(t.getSelectedShapeIds(),a.id);const l=t.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{t.markHistoryStoppingPoint("change-page"),t.setCurrentPage(n)}}]}),o("move-to-page",{source:"context-menu"})}},a.id))}),d.jsx(ve,{id:"new-page",children:d.jsx(W,{actionId:"move-to-new-page"})})]})}function BF(){const t=z();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 UF(){const t=z(),e=vb();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 Kde(){const t=z(),e=U("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(fo,{actionId:"toggle-snap-mode",checked:e})}function Wde(){const t=z(),e=U("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(fo,{actionId:"toggle-tool-lock",checked:e})}function Gde(){const t=z(),e=U("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(fo,{actionId:"toggle-grid",checked:e})}function Vde(){const t=z(),e=U("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(fo,{actionId:"toggle-wrap-mode",checked:e})}function Yde(){const t=z(),e=U("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(fo,{actionId:"toggle-focus-mode",checked:e})}function Xde(){const t=z(),e=U("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(fo,{actionId:"toggle-edge-scrolling",checked:e===1})}function qde(){const t=z(),e=U("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(fo,{actionId:"toggle-reduce-motion",checked:e===0})}function Zde(){const t=z(),e=U("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(fo,{actionId:"toggle-debug-mode",checked:e})}function Qde(){const t=z(),e=U("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(fo,{actionId:"toggle-dynamic-size-mode",checked:e})}function Jde(){const t=z(),e=U("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(fo,{actionId:"toggle-paste-at-cursor",checked:e})}function ehe(){const t=z();return U("show cursor chat",()=>t.getCurrentToolId()==="select"&&!t.getInstanceState().isCoarsePointer,[t])?d.jsx(W,{actionId:"open-cursor-chat"}):null}function the(){const t=z(),e=gm(),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(ehe,{}),d.jsxs(ve,{id:"modify",children:[d.jsx(Fde,{}),d.jsx(Nde,{}),d.jsx(Ude,{}),!r&&d.jsx(Hde,{})]}),d.jsx(FF,{}),d.jsx(NF,{}),d.jsx(ve,{id:"select-all",children:d.jsx(zF,{})})]}):null}const nhe=w.memo(function({children:e,disabled:n=!1}){const r=z(),{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=Mt(),[a,l]=Ms("context menu",s),c=e??d.jsx(the,{});return d.jsxs(Goe,{dir:"ltr",onOpenChange:l,modal:!1,children:[d.jsx(Voe,{onContextMenu:void 0,dir:"ltr",disabled:n,children:o?d.jsx(o,{}):null}),a&&d.jsx(Yoe,{container:i,children:d.jsx(Xoe,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:xe,children:d.jsx(Fr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),rhe=2e3,ohe=5e3,she=qt(function(){const e=z(),{isChatting:n,chatMessage:r}=e.getInstanceState(),o=w.useRef(-1),[s,i]=w.useState("");return w.useEffect(()=>{if(!n&&r||n){const l=n?ohe:rhe;o.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},l)}return()=>{clearTimeout(o.current)}},[e,r,n]),n?d.jsx(ahe,{value:s,setValue:i,chatMessage:r}):r.trim()?d.jsx(ihe,{chatMessage:r}):null});function HF(t){const e=z();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 ihe=({chatMessage:t})=>{const e=z(),n=w.useRef(null);return HF(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:t})},ahe=qt(function({chatMessage:e,value:n,setValue:r}){const o=z(),s=Ee(),i=w.useRef(null),a=e||s("cursor-chat.type-to-chat");HF(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(xe(p),p.stopPropagation(),!g){l();return}r("");break}case"Escape":{xe(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 f0({checked:t}){return d.jsx(Bo,{icon:t?"check":"none",className:"tlui-button__icon",small:!0})}function lhe(){const t=z(),{addToast:e}=Ts(),{addDialog:n}=Ed(),[r,o]=Te.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"items",children:[d.jsx(Ht,{id:"add-toast",onSelect:()=>{e({id:ze(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:ze(),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:ze(),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:ze(),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(dhe,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),d.jsx(Ht,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>hhe(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:Aj,label:"Hard reset"})]}),d.jsxs(ve,{id:"flags",children:[d.jsx(che,{}),d.jsx(uhe,{})]})]})}function che(){const t=Object.values(bt);return t.length?d.jsx(Jn,{id:"debug flags",label:"Debug Flags",children:d.jsx(ve,{id:"debug flags",children:t.map(e=>d.jsx(KF,{flag:e},e.name))})}):null}function uhe(){const t=Object.values(bX);return t.length?d.jsx(Jn,{id:"feature flags",label:"Feature Flags",children:d.jsx(ve,{id:"feature flags",children:t.map(e=>d.jsx(KF,{flag:e},e.name))})}):null}function dhe({title:t="title",body:e="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=Te.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:t}),d.jsx(pm,{})]}),d.jsx(Yu,{style:{maxWidth:350},children:e}),d.jsxs(yb,{className:"tlui-dialog__footer__actions",children:[o&&d.jsxs(ce,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(f0,{checked:a}),d.jsx(Pt,{children:"Don’t show again"})]}),d.jsx(ce,{type:"normal",onClick:s,children:d.jsx(Pt,{children:n})}),d.jsx(ce,{type:"primary",onClick:async()=>i(),children:d.jsx(Pt,{children:r})})]})]})}const KF=qt(function({flag:e,onChange:n}){const r=e.get();return d.jsx(vm,{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 a2=0;function hhe(t,e){const n=Array(e),r=Math.floor(Math.sqrt(e));for(let o=0;o<e;o++)a2++,n[o]={id:Ke("box"+a2),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};t.run(()=>{t.createShapes(n).setSelectedShapes(n.map(o=>o.id))})}function phe({children:t}){const e=t??d.jsx(lhe,{});return d.jsxs(ga,{id:"debug",children:[d.jsx(ma,{children:d.jsx(ce,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(ya,{side:"top",align:"end",alignOffset:0,children:d.jsx(Fr,{type:"menu",sourceId:"debug-panel",children:e})})]})}const fhe=w.memo(function(){const{DebugMenu:e}=Di(),n=w.useRef(null);return Mi(n),d.jsxs("div",{ref:n,className:"tlui-debug-panel",children:[d.jsx(mhe,{}),d.jsx(yhe,{}),e&&d.jsx(e,{})]})});function ghe(t=!0){const[e,n]=w.useState(0),r=z();w.useEffect(()=>{if(!t)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,t])}const mhe=qt(function(){ghe();const e=z(),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 yhe(){const t=z(),e=U("show_fps",()=>bt.showFps.get(),[bt]),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 She=w.memo(function(){const e=An(),n=w.useRef(null);Mi(n);const{MainMenu:r,QuickActions:o,ActionsMenu:s,PageMenu:i}=Di(),a=z(),l=U("isSinglePageMode",()=>a.options.maxPages<=1,[a]),c=a.options.actionShortcutsLocation==="menu"?!0:a.options.actionShortcutsLocation==="toolbar"?!1:e>=St.TABLET;return!r&&!i&&!c?null:d.jsx("div",{ref:n,className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[r&&d.jsx(r,{}),i&&!l&&d.jsx(i,{}),c?d.jsxs(d.Fragment,{children:[o&&d.jsx(o,{}),s&&d.jsx(s,{})]}):null]})})});function vhe(){const t=z(),e=Ea(),[n,r]=w.useState(!1),o=w.useRef(!1);return ci("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 xhe(){const t=z();return U("is pen mode",()=>t.getInstanceState().isPenMode,[t])?d.jsx(W,{actionId:"exit-pen-mode"}):null}function whe(){const t=z(),e=Ea();return U("is following user",()=>!!t.getInstanceState().followingUserId,[t])?d.jsx(Ht,{...e["stop-following"]}):null}function bhe(){return d.jsxs(d.Fragment,{children:[d.jsx(xhe,{}),d.jsx(vhe,{}),d.jsx(whe,{})]})}function Phe({children:t}){const e=t??d.jsx(bhe,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(Fr,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function Che(){const t=gm();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(Ln,{toolId:"select"}),d.jsx(Ln,{toolId:"draw"}),d.jsx(Ln,{toolId:"eraser"}),d.jsx(Ln,{toolId:"hand"}),d.jsx(Ln,{toolId:"rectangle"}),d.jsx(Ln,{toolId:"ellipse"}),d.jsx(Ln,{toolId:"arrow"}),d.jsx(Ln,{toolId:"line"}),d.jsx(Ln,{toolId:"text"}),d.jsx(Ln,{toolId:"frame"}),d.jsx(Ln,{toolId:"note"}),d.jsx(Ln,{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 _he=w.memo(function({children:e}){const n=Ee(),r=An(),o=e??d.jsx(Che,{});return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(hm,{children:n("shortcuts-dialog.title")}),d.jsx(pm,{})]}),d.jsx(Yu,{className:le("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=St.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=St.TABLET}),children:d.jsx(Fr,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})});function WF(){const t=ki(),e=Qt(),n=U("locale",()=>t==null?void 0:t.user.getLocale(),[t]);return t?d.jsx(Jn,{id:"help menu language",label:"menu.language",children:d.jsx(ve,{id:"languages",children:Bu.map(({locale:r,label:o})=>d.jsx(vm,{id:`language-${r}`,title:r,label:o,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})}):null}function Ihe(){return d.jsxs(d.Fragment,{children:[d.jsx(WF,{}),d.jsx(GF,{})]})}function GF(){const{KeyboardShortcutsDialog:t}=Di(),{addDialog:e}=Ed(),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 Ehe(){return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"basic",children:[d.jsx(The,{}),d.jsx(Ohe,{}),d.jsx(khe,{}),d.jsx(Dhe,{})]}),d.jsx(Rhe,{})]})}function khe(){return d.jsxs(Jn,{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(Xb,{})})]})}function The(){const t=z(),e=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]);return d.jsxs(Jn,{id:"edit",label:"menu.edit",disabled:!e,children:[d.jsx(jhe,{}),d.jsx(FF,{}),d.jsx(NF,{}),d.jsx(Mhe,{}),d.jsx(Ahe,{}),d.jsx(ve,{id:"select-all",children:d.jsx(zF,{})})]})}function Mhe(){return d.jsxs(ve,{id:"misc",children:[d.jsx(MF,{}),d.jsx(AF,{}),d.jsx(kF,{}),d.jsx(EF,{}),d.jsx(jF,{}),d.jsx(OF,{}),d.jsx(UF,{}),d.jsx(BF,{}),d.jsx(TF,{})]})}function Ahe(){return d.jsxs(ve,{id:"lock",children:[d.jsx(DF,{}),d.jsx(jde,{})]})}function jhe(){const t=IF(),e=_F();return d.jsxs(ve,{id:"undo-redo",children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}function Ohe(){return d.jsx(Jn,{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(RF,{}),d.jsx(LF,{}),d.jsx($F,{})]})})}function Dhe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"insert-embed"}),d.jsx(W,{actionId:"insert-media"})]})}function Rhe(){return d.jsxs(ve,{id:"preferences",children:[d.jsxs(Jn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ve,{id:"preferences-actions",children:[d.jsx(Kde,{}),d.jsx(Wde,{}),d.jsx(Gde,{}),d.jsx(Vde,{}),d.jsx(Yde,{}),d.jsx(Xde,{}),d.jsx(qde,{}),d.jsx(Qde,{}),d.jsx(Jde,{}),d.jsx(Zde,{})]}),d.jsx(ve,{id:"color-scheme",children:d.jsx(Bae,{})})]}),d.jsx(WF,{}),d.jsx(GF,{})]})}const Lhe=w.memo(function({children:e}){const n=Mt(),[r,o]=Ms("main menu"),s=Ee(),i=e??d.jsx(Ehe,{});return d.jsxs(cb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(ub,{asChild:!0,dir:"ltr",children:d.jsx(ce,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:d.jsx(be,{icon:"menu",small:!0})})}),d.jsx(um,{container:n,children:d.jsx(db,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(Fr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),kS={};function Lc(t){if(kS[t])return kS[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 kS[t]=a,a}const Lp=10,VF=4*6*Lp+12+4*12;function Ha(t,{center:e,radius:n,numArcSegments:r=20,startAngle:o=0,endAngle:s=Ne,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 Ka(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 $he(t,e,n){const r=Lp;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 Ha(t,{center:e.center,radius:n,numArcSegments:Lp*4}),Lp*4*6;let s=0;return Ka(t,s,o.minX,o.minY,o.w,o.h),s+=12,Ka(t,s,o.minX,e.minY,o.w,n),s+=12,Ka(t,s,o.maxX,o.minY,n,o.h),s+=12,Ka(t,s,o.minX,o.maxY,o.w,n),s+=12,Ka(t,s,e.minX,o.minY,n,o.h),s+=12,Ha(t,{numArcSegments:r,offset:s,center:o.point,radius:n,startAngle:De,endAngle:De*1.5}),s+=r*6,Ha(t,{numArcSegments:r,offset:s,center:x.Add(o.point,new x(o.w,0)),radius:n,startAngle:De*1.5,endAngle:Ne}),s+=r*6,Ha(t,{numArcSegments:r,offset:s,center:x.Add(o.point,o.size),radius:n,startAngle:0,endAngle:qe}),s+=r*6,Ha(t,{numArcSegments:r,offset:s,center:x.Add(o.point,new x(0,o.h)),radius:n,startAngle:qe,endAngle:De}),VF}function Fhe(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
384
- precision mediump float;
385
-
386
- in vec2 shapeVertexPosition;
387
-
388
- uniform vec4 canvasPageBounds;
389
-
390
- // taken (with thanks) from
391
- // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
392
- void main() {
393
- // convert the position from pixels to 0.0 to 1.0
394
- vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
395
-
396
- // convert from 0->1 to 0->2
397
- vec2 zeroToTwo = zeroToOne * 2.0;
398
-
399
- // convert from 0->2 to -1->+1 (clipspace)
400
- vec2 clipSpace = zeroToTwo - 1.0;
401
-
402
- gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
403
- }`,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
404
- precision mediump float;
405
-
406
- uniform vec4 fillColor;
407
- out vec4 outputColor;
408
-
409
- void main() {
410
- outputColor = fillColor;
411
- }`,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:zh(e,1024),unselectedShapes:zh(e,4096),viewport:zh(e,VF),collaborators:zh(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 zh(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(e)}}function l2(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 Nhe=Object.create,YF=Object.defineProperty,zhe=Object.getOwnPropertyDescriptor,Bhe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),XF=t=>{throw TypeError(t)},qF=(t,e,n)=>e in t?YF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Uhe=t=>[,,,Nhe(null)],ZF=["class","method","getter","setter","accessor","field","value","get","set"],QF=t=>t!==void 0&&typeof t!="function"?XF("Function expected"):t,Hhe=(t,e,n,r,o)=>({kind:ZF[t],name:e,metadata:r,addInitializer:s=>n._?XF("Already initialized"):o.push(QF(s||null))}),Khe=(t,e)=>qF(e,Bhe("metadata"),t[3]),Whe=(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},Yo=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=ZF[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,zhe(o,n)),y=r.length-1;y>=0;y--)l=Hhe(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,QF(i)&&(v[g]=i);return v&&YF(o,n,v),o},es=(t,e,n)=>qF(t,typeof e!="symbol"?e+"":e,n),JF,e4,t4,n4,r4,o4,s4,i4,a4,l4,br;l4=[Kn],a4=[G],i4=[G],s4=[G],o4=[G],r4=[G],n4=[G],t4=[G],e4=[G],JF=[Kn];class Br{constructor(e,n,r){this.editor=e,this.elem=n,this.container=r,Whe(br,5,this),es(this,"disposables",[]),es(this,"gl"),es(this,"shapeGeometryCache"),es(this,"colors"),es(this,"id",ze()),es(this,"canvasBoundingClientRect",Et("canvasBoundingClientRect",new Z)),es(this,"originPagePoint",new x),es(this,"originPageCenter",new x),es(this,"isInViewport",!1),this.gl=Fhe(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 Ka(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),jo("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Lc(e.getPropertyValue("--color-text-3").trim()),selectFill:Lc(e.getPropertyValue("--color-selected").trim()),viewportFill:Lc(e.getPropertyValue("--color-muted-1").trim()),background:Lc(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),y=Math.max(0,-(f-i.height-l));a+=(g-m)/2,l+=(v-y)/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)?(l2(this.gl.selectedShapes,s,h),s+=p):(l2(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=$he(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),Ge.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)l&&(Ha(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(Lc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}br=Uhe();Yo(br,1,"close",l4,Br);Yo(br,1,"getDpr",a4,Br);Yo(br,1,"getContentPageBounds",i4,Br);Yo(br,1,"getContentScreenBounds",s4,Br);Yo(br,1,"getCanvasSize",o4,Br);Yo(br,1,"getCanvasClientPosition",r4,Br);Yo(br,1,"getCanvasPageBounds",n4,Br);Yo(br,1,"getZoom",t4,Br);Yo(br,1,"getCanvasPageBoundsArray",e4,Br);Yo(br,1,"render",JF,Br);Khe(br,Br);function Ghe(){const t=z(),e=Mt(),n=w.useRef(null),r=w.useRef(!1),o=w.useRef();w.useEffect(()=>{try{const u=new Br(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(dd(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 y=x.Sub(f.center,f.point),S=x.Add(p,y);o.current.originPagePoint.setTo(S),o.current.originPageCenter.setTo(p),t.centerOnPoint(p,{animation:{duration:t.options.animationMediumMs}})}else{const y=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.isInViewport=f.containsPoint(y),o.current.originPagePoint.setTo(y),o.current.originPageCenter.setTo(f.center)}function v(y){h&&hd(h,y),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",...lr(u),point:f,isPen:t.getInstanceState().isPenMode};t.dispatch(g)},[t]),l=w.useCallback(u=>{const h=xj(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,metaKey:u.metaKey,accelKey:un(u)})},[t]),c=xd();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,onWheelCapture:l})})}function Vhe(t,e){const[n,r]=Te.useState(e);Te.useLayoutEffect(()=>{const s=_w(t);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${t} from local storage.`)}},[t]);const o=Te.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return Iw(t,JSON.stringify(a)),a})},[t]);return[n,o]}const Yhe=w.memo(function(){const e=Ea(),n=Ee(),r=An(),o=w.useRef(null);Mi(o);const[s,i]=Vhe("minimap",!0),a=w.useCallback(()=>{i(u=>!u)},[i]),{ZoomMenu:l,Minimap:c}=Di();return r<St.MOBILE?null:d.jsxs("div",{ref:o,className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:l&&r<St.TABLET?d.jsx(l,{}):s?d.jsxs(d.Fragment,{children:[l&&d.jsx(l,{}),c&&d.jsx(ce,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:d.jsx(be,{icon:s?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(ce,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(Xu(e["zoom-out"].label))} ${Xx(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"minus"})}),l&&d.jsx(l,{}),d.jsx(ce,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(Xu(e["zoom-in"].label))} ${Xx(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"plus"})}),c&&d.jsx(ce,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:d.jsx(be,{icon:s?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=St.TABLET&&!s&&d.jsx(c,{})]})}),Xhe=function({name:e,id:n,isCurrentPage:r,onCancel:o}){const s=z(),i=Qt(),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(fm,{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})},g0=(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=Io(a.index):!a&&l?s=i7(i[0].index):s=$u(a.index,l.index),s!==i[n].index&&(t.markHistoryStoppingPoint("moving page"),t.updatePage({id:e,index:s}),o("move-page",{source:"page-menu"}))},c2=qt(function({index:e,listSize:n,item:r,onRename:o}){const s=z(),i=Ee(),a=s.getPages(),l=Qt(),c=w.useCallback(()=>{s.markHistoryStoppingPoint("creating page");const f=yr.createId();s.duplicatePage(r.id,f),l("duplicate-page",{source:"page-menu"})},[s,r,l]),u=w.useCallback(()=>{g0(s,r.id,e,e-1,l)},[s,r,e,l]),h=w.useCallback(()=>{g0(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(ga,{id:`page item submenu ${e}`,children:[d.jsx(ma,{children:d.jsx(ce,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(ya,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(Fr,{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"})})]})})]})}),qhe=w.memo(function(){const e=z(),n=Qt(),r=Ee(),o=An(),s=w.useCallback(()=>y(!1),[]),[i,a]=Ms("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=wr(),g=U("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),m=U("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[v,y]=w.useState(!1),S=w.useCallback(()=>{f||y(M=>!M)},[f]),b=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,C]=w.useState(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])));w.useLayoutEffect(()=>{C(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])))},[l,u]),w.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const M=document.querySelector(`[data-testid="page-menu-item-${p}"]`);if(M){const O=c.current;if(!O)return;const F=M.offsetTop,B=O.scrollTop;F<B&&O.scrollTo({top:F});const K=F+l,R=O.scrollTop+O.offsetHeight;K>R&&O.scrollTo({top:K-O.offsetHeight})}})},[l,p,i,e]);const _=w.useCallback(M=>{const{clientY:O,currentTarget:F}=M,{dataset:{id:B,index:K}}=F;if(!B||!K)return;const R=b.current;dd(M.currentTarget,M),R.status="pointing",R.pointing={id:B,index:+K};const Y=P[B].y;R.startY=O,R.startIndex=Math.max(0,Math.min(Math.round(Y/l),u.length-1))},[l,u.length,P]),E=w.useCallback(M=>{const O=b.current;if(O.status==="pointing"){const{clientY:F}=M,B=F-O.startY;Math.abs(B)>5&&(O.status="dragging")}if(O.status==="dragging"){const{clientY:F}=M,B=F-O.startY,K=P[O.pointing.id],{startIndex:R,pointing:H}=O,Y=K.y+B,ee=Math.max(0,Math.min(Math.round(Y/l),u.length-1)),he={...P};if(he[H.id]={y:K.y,offsetY:B,isSelected:!0},ee!==O.dragIndex){O.dragIndex=ee;for(let ue=0;ue<u.length;ue++){const ke=u[ue];if(ke.id===O.pointing.id)continue;let{y:se}=he[ke.id];ee===R?se=ue*l:ee<R?ee<=ue&&ue<R?se=(ue+1)*l:se=ue*l:ee>R&&(ee>=ue&&ue>R?se=(ue-1)*l:se=ue*l),se!==he[ke.id].y&&(he[ke.id]={y:se,offsetY:0,isSelected:!0})}}C(he)}},[l,u,P]),k=w.useCallback(M=>{const O=b.current;if(O.status==="dragging"){const{id:F,index:B}=O.pointing;g0(e,F,B,O.dragIndex,n)}hd(M.currentTarget,M),O.status="idle"},[e,n]),D=w.useCallback(M=>{const O=b.current;M.key==="Escape"&&(O.status==="dragging"&&C(Object.fromEntries(u.map((F,B)=>[F.id,{y:B*l,offsetY:0,isSelected:!1}]))),O.status="idle")},[l,u]),T=w.useCallback(()=>{f||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const M=yr.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:M}),e.setCurrentPage(M),y(!0)}),n("new-page",{source:"page-menu"}))},[e,r,f,n]),j=w.useCallback(M=>{e.setCurrentPage(M),n("change-page",{source:"page-menu"})},[e,n]),$=w.useCallback((M,O)=>{e.renamePage(M,O),n("rename-page",{source:"page-menu"})},[e,n]);return d.jsxs(Gb,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(Vb,{"data-testid":"main.page-menu",children:d.jsxs(ce,{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(Yb,{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(ce,{type:"icon","data-testid":"page-menu.edit",title:r(v?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:d.jsx(be,{icon:v?"check":"edit"})}),d.jsx(ce,{type:"icon","data-testid":"page-menu.create",title:r(g?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:g,onClick:T,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((M,O)=>{const F=P[M.id]??{position:O*40,offsetY:0};return v?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:M.id===h.id?888:O,transform:`translate(0px, ${F.y+F.offsetY}px)`},children:[d.jsx(ce,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:_,onPointerUp:k,onPointerMove:E,onKeyDown:D,"data-id":M.id,"data-index":O,children:d.jsx(be,{icon:"drag-handle-dots"})}),o<St.TABLET_SM&&m?d.jsxs(ce,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const B=window.prompt("Rename page",M.name);B&&B!==M.name&&$(M.id,B)},onDoubleClick:S,children:[d.jsx(f0,{checked:M.id===h.id}),d.jsx(Pt,{children:M.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:d.jsx(Xhe,{id:M.id,name:M.name,isCurrentPage:M.id===h.id,onCancel:()=>{y(!1),e.menus.clearOpenMenus()}})}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":v,children:d.jsx(c2,{index:O,item:M,listSize:u.length})})]},M.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(ce,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>j(M.id),onDoubleClick:S,title:r("page-menu.go-to-page"),children:[d.jsx(f0,{checked:M.id===h.id}),d.jsx(Pt,{children:M.name})]}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(c2,{index:O,item:M,listSize:u.length,onRename:()=>{if(Ge.isIos){const B=window.prompt("Rename page",M.name);B&&B!==M.name&&$(M.id,B)}else y(!0),p!==M.id&&j(M.id)}})})]},M.id)})})]})})]})});function Zhe(){const t=z(),e=wr(),n=U("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]);if(!(e&&!n))return d.jsxs(d.Fragment,{children:[d.jsx(Jhe,{}),d.jsx(Qhe,{})]})}function Qhe(){const t=jn(1),e=As(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"delete",disabled:!n}),d.jsx(W,{actionId:"duplicate",disabled:!n})]})}function Jhe(){const t=IF(),e=_F();return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}const epe=w.memo(function({children:e}){const n=e??d.jsx(Zhe,{});return d.jsx(Fr,{type:"small-icons",sourceId:"quick-actions",children:n})});function tpe({userId:t}){const e=Lg(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 npe=qt(function({userId:e}){const n=z(),r=Ee(),o=Qt(),s=Lg(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(ce,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>n.zoomToUser(e),onDoubleClick:i,children:[d.jsx(Bo,{icon:"color",color:s.color}),d.jsx("div",{className:"tlui-people-menu__name",children:s.userName??"New User"})]}),d.jsx(ce,{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 rpe({count:t}){return d.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(t)})}const ope=qt(function(){const e=z(),n=Mt(),r=Ee(),o=Qt(),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}=Te.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(Ub,{onOpenChange:l,open:i,children:[d.jsx(Hb,{dir:"ltr",asChild:!0,children:d.jsx(ce,{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(Kb,{container:n,children:d.jsx(Wb,{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:Px.map(m=>d.jsx(ce,{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 spe(){const t=z(),e=Qt(),n=U("userName",()=>t.user.getName(),[]),r=Ee(),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.menus.clearOpenMenus()},[t]);return d.jsxs("div",{className:"tlui-people-menu__user",children:[d.jsx(ope,{}),i?d.jsx(fm,{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(ce,{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"})})]})}function ipe({displayUserWhenAlone:t,children:e}){const n=Ee(),r=Mt(),o=z(),s=Pj(),i=U("user",()=>o.user.getColor(),[o]),a=U("user",()=>o.user.getName(),[o]),[l,c]=Ms("people menu");return d.jsxs(Ub,{onOpenChange:c,open:l,children:[d.jsx(Hb,{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(rpe,{count:s.length-5}),d.jsxs("div",{className:"tlui-people-menu__avatars",children:[s.slice(-5).map(u=>d.jsx(tpe,{userId:u},u)),(t||s.length>0)&&d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx(Kb,{container:r,children:d.jsx(Wb,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,onEscapeKeyDown:xe,children:d.jsxs("div",{className:"tlui-people-menu__wrapper",children:[d.jsx("div",{className:"tlui-people-menu__section",children:d.jsx(spe,{})}),s.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:s.map(u=>d.jsx(npe,{userId:u},u+"_presence"))}),e]})})})]})}function ape(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(ipe,{displayUserWhenAlone:!0})})}const lpe=Object.freeze([mr,ca,ua,Fo]);function c4(t=lpe){const e=z();return U("getRelevantStyles",()=>{var s;const n=new Tx(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 jr={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"}]},Yi=w.memo(function(e){const{uiType:n,items:r,title:o,style:s,value:i,onValueChange:a,onHistoryMark:l,theme:c}=e,u=Ee(),h=w.useRef(!1),p=w.useRef(null),{handleButtonClick:f,handleButtonPointerDown:g,handleButtonPointerEnter:m,handleButtonPointerUp:v}=w.useMemo(()=>{const y=()=>{h.current=!1,window.removeEventListener("pointerup",y);const _=p.current;_&&["TEXTAREA","INPUT"].includes(_.nodeName)&&_.focus(),p.current=null};return{handleButtonClick:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||(l==null||l("point picker item"),a(s,E))},handleButtonPointerDown:_=>{const{id:E}=_.currentTarget.dataset;l==null||l("point picker item"),a(s,E),h.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:_=>{if(!h.current)return;const{id:E}=_.currentTarget.dataset;a(s,E)},handleButtonPointerUp:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||a(s,E)}}},[i,l,a,s]);return d.jsx("div",{"data-testid":`style.${n}`,className:le("tlui-buttons__grid"),children:r.map(y=>d.jsx(ce,{type:"icon","data-id":y.value,"data-testid":`style.${n}.${y.value}`,"aria-label":y.value,"data-state":i.type==="shared"&&i.value===y.value?"hinted":void 0,title:o+" — "+u(`${n}-style.${y.value}`),className:le("tlui-button-grid__button"),style:s===mr?{color:c[y.value].solid}:void 0,onPointerEnter:m,onPointerDown:g,onPointerUp:v,onClick:f,children:d.jsx(be,{icon:y.icon})},y.value))})});function u4(t,[e,n]){return Math.min(n,Math.max(e,t))}function cpe(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 d4=["PageUp","PageDown"],h4=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],p4={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},lc="Slider",[m0,upe,dpe]=Jg(lc),[f4,Dge]=Go(lc,[dpe]),[hpe,Tm]=f4(lc),g4=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,form:g,...m}=t,v=w.useRef(new Set),y=w.useRef(0),b=i==="horizontal"?ppe:fpe,[P=[],C]=Ai({prop:u,defaultProp:c,onChange:j=>{var M;(M=[...v.current][y.current])==null||M.focus(),h(j)}}),_=w.useRef(P);function E(j){const $=vpe(P,j);T(j,$)}function k(j){T(j,y.current)}function D(){const j=_.current[y.current];P[y.current]!==j&&p(P)}function T(j,$,{commit:M}={commit:!1}){const O=Ppe(s),F=Cpe(Math.round((j-r)/s)*s+r,O),B=u4(F,[r,o]);C((K=[])=>{const R=ype(K,B,$);if(bpe(R,l*s)){y.current=R.indexOf(B);const H=String(R)!==String(K);return H&&M&&p(R),H?R:K}else return K})}return d.jsx(hpe,{scope:t.__scopeSlider,name:n,disabled:a,min:r,max:o,valueIndexToChangeRef:y,thumbs:v.current,values:P,orientation:i,form:g,children:d.jsx(m0.Provider,{scope:t.__scopeSlider,children:d.jsx(m0.Slot,{scope:t.__scopeSlider,children:d.jsx(b,{"aria-disabled":a,"data-disabled":a?"":void 0,...m,ref:e,onPointerDown:oe(m.onPointerDown,()=>{a||(_.current=P)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:E,onSlideMove:a?void 0:k,onSlideEnd:a?void 0:D,onHomeKeyDown:()=>!a&&T(r,0,{commit:!0}),onEndKeyDown:()=>!a&&T(o,P.length-1,{commit:!0}),onStepKeyDown:({event:j,direction:$})=>{if(!a){const F=d4.includes(j.key)||j.shiftKey&&h4.includes(j.key)?10:1,B=y.current,K=P[B],R=s*F*$;T(K+R,B,{commit:!0})}}})})})})});g4.displayName=lc;var[m4,y4]=f4(lc,{startEdge:"left",endEdge:"right",size:"width",direction:1}),ppe=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(void 0),m=F1(o),v=m==="ltr",y=v&&!s||!v&&s;function S(b){const P=g.current||h.getBoundingClientRect(),C=[0,P.width],E=qb(C,y?[n,r]:[r,n]);return g.current=P,E(b-P.left)}return d.jsx(m4,{scope:t.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:d.jsx(S4,{dir:m,"data-orientation":"horizontal",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const P=S(b.clientX);i==null||i(P)},onSlideMove:b=>{const P=S(b.clientX);a==null||a(P)},onSlideEnd:()=>{g.current=void 0,l==null||l()},onStepKeyDown:b=>{const C=p4[y?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:C?-1:1})}})})}),fpe=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(void 0),f=!o;function g(m){const v=p.current||u.current.getBoundingClientRect(),y=[0,v.height],b=qb(y,f?[r,n]:[n,r]);return p.current=v,b(m-v.top)}return d.jsx(m4,{scope:t.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:d.jsx(S4,{"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 y=p4[f?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:y?-1:1})}})})}),S4=w.forwardRef((t,e)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=t,u=Tm(lc,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()):d4.concat(h4).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))})})}),v4="SliderTrack",x4=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=Tm(v4,n);return d.jsx(Ae.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:e})});x4.displayName=v4;var y0="SliderRange",w4=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=Tm(y0,n),s=y4(y0,n),i=w.useRef(null),a=Ze(e,i),l=o.values.length,c=o.values.map(p=>P4(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+"%"}})});w4.displayName=y0;var S0="SliderThumb",b4=w.forwardRef((t,e)=>{const n=upe(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(gpe,{...t,ref:s,index:i})}),gpe=w.forwardRef((t,e)=>{const{__scopeSlider:n,index:r,name:o,...s}=t,i=Tm(S0,n),a=y4(S0,n),[l,c]=w.useState(null),u=Ze(e,S=>c(S)),h=l?i.form||!!l.closest("form"):!0,p=f3(l),f=i.values[r],g=f===void 0?0:P4(f,i.min,i.max),m=Spe(r,i.values.length),v=p==null?void 0:p[a.size],y=v?xpe(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}% + ${y}px)`},children:[d.jsx(m0.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(mpe,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:f},r)]})});b4.displayName=S0;var mpe=t=>{const{value:e,...n}=t,r=w.useRef(null),o=cpe(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 ype(t=[],e,n){const r=[...t];return r[n]=e,r.sort((o,s)=>o-s)}function P4(t,e,n){const s=100/(n-e)*(t-e);return u4(s,[0,100])}function Spe(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}function vpe(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 xpe(t,e,n){const r=t/2,s=qb([0,50],[0,r]);return(r-s(e)*n)*n}function wpe(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}function bpe(t,e){if(e>0){const n=wpe(t);return Math.min(...n)>=e}return!0}function qb(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 Ppe(t){return(String(t).split(".")[1]||"").length}function Cpe(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}var _pe=g4,Ipe=x4,Epe=w4,kpe=b4;const Tpe=w.memo(function({onHistoryMark:e,title:n,steps:r,value:o,label:s,onValueChange:i,["data-testid"]:a}){const l=Ee(),c=w.useCallback(p=>{i(p[0])},[i]),u=w.useCallback(()=>{e("click slider")},[e]),h=w.useCallback(()=>{o&&i(o)},[o,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(_pe,{"data-testid":a,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(Ipe,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&d.jsx(Epe,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&d.jsx(kpe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Mpe({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=Ee(),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(ga,{id:`style panel ${e} A`,children:[d.jsx(ma,{children:d.jsx(ce,{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(ya,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map((m,v)=>d.jsx(qu,{"data-testid":`style.${e}.${m.value}`,children:d.jsx(ce,{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(ga,{id:`style panel ${n}`,children:[d.jsx(ma,{children:d.jsx(ce,{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(ya,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(qu,{children:d.jsx(ce,{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 Ape=w.memo(Mpe);function jpe({id:t,label:e,uiType:n,stylePanelType:r,style:o,items:s,type:i,value:a,onValueChange:l}){const c=Ee(),u=z(),h=w.useMemo(()=>{var m;return(m=s.find(v=>a.type==="shared"&&v.value===a.value))==null?void 0:m.icon},[s,a]),p=c(`style-panel.${r}`),f=a.type==="mixed"?c("style-panel.mixed"):p+" — "+c(`${n}-style.${a.value}`),g=e?c(e):"";return d.jsxs(ga,{id:`style panel ${t}`,children:[d.jsx(ma,{children:d.jsxs(ce,{type:i,"data-testid":`style.${n}`,title:f,children:[g&&d.jsx(Pt,{children:g}),d.jsx(be,{icon:h??"mixed"})]})}),d.jsx(ya,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map(m=>d.jsx(qu,{children:d.jsx(ce,{type:"icon","data-testid":`style.${n}.${m.value}`,title:p+" — "+c(`${n}-style.${m.value}`),onClick:()=>{u.markHistoryStoppingPoint("select style dropdown item"),l(o,m.value)},children:d.jsx(be,{icon:m.icon})})},m.value))})})]})}const Zb=w.memo(jpe);function Ope({styles:t}){const e=xd();if(!t)return null;const n=t.get(Jr),r=t.get(Tf),o=t.get(kf),s=t.get(Of),i=t.get($o),a=n===void 0,l=r===void 0&&o===void 0,c=s===void 0,u=i===void 0,h=ks({isDarkMode:e});return d.jsxs(d.Fragment,{children:[d.jsx(Dpe,{theme:h,styles:t}),!u&&d.jsx(Rpe,{theme:h,styles:t}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(Lpe,{styles:t}),d.jsx(Fpe,{styles:t}),d.jsx($pe,{styles:t})]})]})}function Td(){const t=z(),e=Qt();return Te.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 Dpe({styles:t,theme:e}){const n=Ee(),r=z(),o=w.useCallback(h=>r.markHistoryStoppingPoint(h),[r]),s=Td(),i=t.get(mr),a=t.get(ua),l=t.get(ca),c=t.get(Fo),u=a!==void 0||l!==void 0||c!==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:[i===void 0?null:d.jsx(Yi,{title:n("style-panel.color"),uiType:"color",style:mr,items:jr.color,value:i,onValueChange:s,theme:e,onHistoryMark:o}),d.jsx(Npe,{})]}),u&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:d.jsx(Yi,{title:n("style-panel.fill"),uiType:"fill",style:ua,items:jr.fill,value:a,onValueChange:s,theme:e,onHistoryMark:o}),l===void 0?null:d.jsx(Yi,{title:n("style-panel.dash"),uiType:"dash",style:ca,items:jr.dash,value:l,onValueChange:s,theme:e,onHistoryMark:o}),c===void 0?null:d.jsx(Yi,{title:n("style-panel.size"),uiType:"size",style:Fo,items:jr.size,value:c,onValueChange:(h,p)=>{s(h,p);const f=r.getSelectedShapeIds();f.length>0&&Ye(r,f)},theme:e,onHistoryMark:o})]})]})}function Rpe({theme:t,styles:e}){const n=Ee(),r=Td(),o=z(),s=w.useCallback(u=>o.markHistoryStoppingPoint(u),[o]),i=e.get($o),a=e.get(Sx),l=e.get(Af),c=e.get(jf);return i===void 0&&l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[i===void 0?null:d.jsx(Yi,{title:n("style-panel.font"),uiType:"font",style:$o,items:jr.font,value:i,onValueChange:r,theme:t,onHistoryMark:s}),a===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Yi,{title:n("style-panel.align"),uiType:"align",style:Sx,items:jr.textAlign,value:a,onValueChange:r,theme:t,onHistoryMark:s}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(ce,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})})})]}),l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Yi,{title:n("style-panel.label-align"),uiType:"align",style:Af,items:jr.horizontalAlign,value:l,onValueChange:r,theme:t,onHistoryMark:s}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?d.jsx(ce,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})}):d.jsx(Zb,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:jf,items:jr.verticalAlign,value:c,onValueChange:r})})]})]})}function Lpe({styles:t}){const e=Td(),n=t.get(Jr);return n===void 0?null:d.jsx(Zb,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:Jr,items:jr.geo,value:n,onValueChange:e})}function $pe({styles:t}){const e=Td(),n=t.get(Of);return n===void 0?null:d.jsx(Zb,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:Of,items:jr.spline,value:n,onValueChange:e})}function Fpe({styles:t}){const e=Td(),n=t.get(Tf),r=t.get(kf);return!n||!r?null:d.jsx(Ape,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:kf,itemsA:jr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Tf,itemsB:jr.arrowheadEnd,valueB:n,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const $c=[.1,.25,.5,.75,1];function Npe(){const t=z(),e=w.useCallback(a=>t.markHistoryStoppingPoint(a),[t]),n=U("opacity",()=>t.getSharedOpacity(),[t]),r=Qt(),o=Ee(),s=Te.useCallback(a=>{const l=$c[a];t.run(()=>{t.isIn("select")&&t.setOpacityForSelectedShapes(l),t.setOpacityForNextShapes(l),t.updateInstanceState({isChangingStyle:!0})}),r("set-style",{source:"style-panel",id:"opacity",value:a})},[t,r]);if(n===void 0)return null;const i=n.type==="mixed"?-1:$c.indexOf(T9($c,a=>Math.abs(a-n.value)));return d.jsx(Tpe,{"data-testid":"style.opacity",value:i>=0?i:$c.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:s,steps:$c.length-1,title:o("style-panel.opacity"),onHistoryMark:e})}const zpe=w.memo(function({isMobile:e,children:n}){const r=z(),o=w.useRef(null);Mi(o);const s=c4(),i=w.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=n??d.jsx(Ope,{styles:s});return d.jsx("div",{ref:o,className:le("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:i,children:a})});function Bpe(){const t=z(),e=Ee(),n=c4(),r=n==null?void 0:n.get(mr),o=ks({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}=Di();return l?d.jsxs(Gb,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(Vb,{children:d.jsx(ce,{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(Yb,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function Upe(){return d.jsxs(d.Fragment,{children:[d.jsx(Kpe,{}),d.jsx(Wpe,{}),d.jsx(Gpe,{}),d.jsx(Vpe,{}),d.jsx(Ype,{}),d.jsx(Xpe,{}),d.jsx(qpe,{}),d.jsx(Zpe,{}),d.jsx(Qpe,{}),d.jsx(Jpe,{}),d.jsx(tfe,{}),d.jsx(efe,{}),d.jsx(ofe,{}),d.jsx(afe,{}),d.jsx(nfe,{}),d.jsx(ife,{}),d.jsx(sfe,{}),d.jsx(rfe,{}),d.jsx(lfe,{}),d.jsx(cfe,{}),d.jsx(ufe,{}),d.jsx(dfe,{}),d.jsx(hfe,{}),d.jsx(pfe,{}),d.jsx(ffe,{}),d.jsx(gfe,{}),d.jsx(yfe,{}),d.jsx(mfe,{})]})}function Hpe(t){var r;const e=z(),n=(r=t.meta)==null?void 0:r.geo;return U("is tool selected",()=>{const o=e.getCurrentToolId(),s=e.getSharedStyles().getAsKnownValue(Jr);return n?o==="geo"&&s===n:o===t.id},[e,t.id,n])}function Ve({tool:t}){const e=Eb(),n=Hpe(e[t]);return d.jsx(Ln,{toolId:t,isSelected:n})}function Kpe(){return d.jsx(Ve,{tool:"select"})}function Wpe(){return d.jsx(Ve,{tool:"hand"})}function Gpe(){return d.jsx(Ve,{tool:"draw"})}function Vpe(){return d.jsx(Ve,{tool:"eraser"})}function Ype(){return d.jsx(Ve,{tool:"arrow"})}function Xpe(){return d.jsx(Ve,{tool:"text"})}function qpe(){return d.jsx(Ve,{tool:"note"})}function Zpe(){return d.jsx(Ln,{toolId:"asset"})}function Qpe(){return d.jsx(Ve,{tool:"rectangle"})}function Jpe(){return d.jsx(Ve,{tool:"ellipse"})}function efe(){return d.jsx(Ve,{tool:"diamond"})}function tfe(){return d.jsx(Ve,{tool:"triangle"})}function nfe(){return d.jsx(Ve,{tool:"rhombus"})}function rfe(){return d.jsx(Ve,{tool:"heart"})}function ofe(){return d.jsx(Ve,{tool:"hexagon"})}function sfe(){return d.jsx(Ve,{tool:"cloud"})}function ife(){return d.jsx(Ve,{tool:"star"})}function afe(){return d.jsx(Ve,{tool:"oval"})}function lfe(){return d.jsx(Ve,{tool:"x-box"})}function cfe(){return d.jsx(Ve,{tool:"check-box"})}function ufe(){return d.jsx(Ve,{tool:"arrow-left"})}function dfe(){return d.jsx(Ve,{tool:"arrow-up"})}function hfe(){return d.jsx(Ve,{tool:"arrow-down"})}function pfe(){return d.jsx(Ve,{tool:"arrow-right"})}function ffe(){return d.jsx(Ve,{tool:"line"})}function gfe(){return d.jsx(Ve,{tool:"highlight"})}function mfe(){return d.jsx(Ve,{tool:"frame"})}function yfe(){return d.jsx(Ve,{tool:"laser"})}const TS=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function MS(t,e,n,r){t.addEventListener?t.addEventListener(e,n,r):t.attachEvent&&t.attachEvent("on".concat(e),n)}function Fc(t,e,n,r){t.removeEventListener?t.removeEventListener(e,n,r):t.detachEvent&&t.detachEvent("on".concat(e),n)}function C4(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 _4(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 Sfe(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 Zu={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,"-":TS?173:189,"=":TS?61:187,";":TS?59:186,"'":222,"[":219,"]":221,"\\":220},Ho={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},$p={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},pt={};for(let t=1;t<20;t++)Zu["f".concat(t)]=111+t;let it=[],gu=null,I4="all";const os=new Map,Md=t=>Zu[t.toLowerCase()]||Ho[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),vfe=t=>Object.keys(Zu).find(e=>Zu[e]===t),xfe=t=>Object.keys(Ho).find(e=>Ho[e]===t);function E4(t){I4=t||"all"}function Qu(){return I4||"all"}function wfe(){return it.slice(0)}function bfe(){return it.map(t=>vfe(t)||xfe(t)||String.fromCharCode(t))}function Pfe(){const t=[];return Object.keys(pt).forEach(e=>{pt[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=>Md(a))})})}),t}function Cfe(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 _fe(t){return typeof t=="string"&&(t=Md(t)),it.indexOf(t)!==-1}function Ife(t,e){let n,r;t||(t=Qu());for(const o in pt)if(Object.prototype.hasOwnProperty.call(pt,o))for(n=pt[o],r=0;r<n.length;)n[r].scope===t?n.splice(r,1).forEach(i=>{let{element:a}=i;return Qb(a)}):r++;Qu()===t&&E4(e||"all")}function Efe(t){let e=t.keyCode||t.which||t.charCode;const n=it.indexOf(e);if(n>=0&&it.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&it.splice(0,it.length),(e===93||e===224)&&(e=91),e in Bt){Bt[e]=!1;for(const r in Ho)Ho[r]===e&&(Wn[r]=!1)}}function k4(t){if(typeof t>"u")Object.keys(pt).forEach(o=>{Array.isArray(pt[o])&&pt[o].forEach(s=>Bh(s)),delete pt[o]}),Qb(null);else if(Array.isArray(t))t.forEach(o=>{o.key&&Bh(o)});else if(typeof t=="object")t.key&&Bh(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=""),Bh({key:t,scope:o,method:s,splitKey:"+"})}}const Bh=t=>{let{key:e,scope:n,method:r,splitKey:o="+"}=t;_4(e).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Md(c);if(!pt[u])return;n||(n=Qu());const h=l>1?C4(Ho,a):[],p=[];pt[u]=pt[u].filter(f=>{const m=(r?f.method===r:!0)&&f.scope===n&&Sfe(f.mods,h);return m&&p.push(f.element),!m}),p.forEach(f=>Qb(f))})};function u2(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(it),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function d2(t,e){const n=pt["*"];let r=t.keyCode||t.which||t.charCode;if(!Wn.filter.call(this,t))return;if((r===93||r===224)&&(r=91),it.indexOf(r)===-1&&r!==229&&it.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=$p[a];t[a]&&it.indexOf(l)===-1?it.push(l):!t[a]&&it.indexOf(l)>-1?it.splice(it.indexOf(l),1):a==="metaKey"&&t[a]&&(it=it.filter(c=>c in $p||c===r))}),r in Bt){Bt[r]=!0;for(const a in Ho)Ho[a]===r&&(Wn[a]=!0);if(!n)return}for(const a in Bt)Object.prototype.hasOwnProperty.call(Bt,a)&&(Bt[a]=t[$p[a]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(it.indexOf(17)===-1&&it.push(17),it.indexOf(18)===-1&&it.push(18),Bt[17]=!0,Bt[18]=!0);const o=Qu();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)&&u2(t,n[a],o,e);if(!(r in pt))return;const s=pt[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(Md(u[p]));h.sort().join("")===it.sort().join("")&&u2(t,l,o,e)}}function Wn(t,e,n){it=[];const r=_4(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&&k4(t,s);a<r.length;a++)t=r[a].split(u),o=[],t.length>1&&(o=C4(Ho,t)),t=t[t.length-1],t=t==="*"?"*":Md(t),t in pt||(pt[t]=[]),pt[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(!os.has(i)){const f=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return d2(m,i)},g=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;d2(m,i),Efe(m)};os.set(i,{keydownListener:f,keyupListenr:g,capture:h}),MS(i,"keydown",f,h),MS(i,"keyup",g,h)}if(!gu){const f=()=>{it=[]};gu={listener:f,capture:h},MS(window,"focus",f,h)}}}function kfe(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(pt).forEach(n=>{pt[n].filter(o=>o.scope===e&&o.shortcut===t).forEach(o=>{o&&o.method&&o.method()})})}function Qb(t){const e=Object.values(pt).flat();if(e.findIndex(r=>{let{element:o}=r;return o===t})<0){const{keydownListener:r,keyupListenr:o,capture:s}=os.get(t)||{};r&&o&&(Fc(t,"keyup",o,s),Fc(t,"keydown",r,s),os.delete(t))}if((e.length<=0||os.size<=0)&&(Object.keys(os).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=os.get(o)||{};s&&i&&(Fc(o,"keyup",i,a),Fc(o,"keydown",s,a),os.delete(o))}),os.clear(),Object.keys(pt).forEach(o=>delete pt[o]),gu)){const{listener:o,capture:s}=gu;Fc(window,"focus",o,s),gu=null}}const AS={getPressedKeyString:bfe,setScope:E4,getScope:Qu,deleteScope:Ife,getPressedKeyCodes:wfe,getAllKeyCodes:Pfe,isPressed:_fe,filter:Cfe,trigger:kfe,unbind:k4,keyMap:Zu,modifier:Ho,modifierMap:$p};for(const t in AS)Object.prototype.hasOwnProperty.call(AS,t)&&(Wn[t]=AS[t]);if(typeof window<"u"){const t=window.hotkeys;Wn.noConflict=e=>(e&&window.hotkeys===Wn&&(window.hotkeys=t),Wn),window.hotkeys=Wn}const h2=["copy","cut","paste","asset"];function Tfe(){const t=z(),e=wr(),n=Ea(),r=Eb(),o=U("is focused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!o)return;const s=new Array,i=(l,c)=>{Wn(l,{element:document.body},c),s.push(()=>{Wn.unbind(l,c)})},a=(l,c)=>{Wn(l,{element:document.body,keyup:!0,keydown:!1},c),s.push(()=>{Wn.unbind(l,c)})};for(const l of Object.values(n))l.kbd&&(e&&!l.readonlyOk||h2.includes(l.id)||i(p2(l.kbd),c=>{Qc(t)||(xe(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&t.getIsReadonly()||h2.includes(l.id)||i(p2(l.kbd),c=>{Qc(t)||(xe(c),l.onSelect("kbd"))});return i(",",l=>{if(Qc(t)||t.inputs.keys.has("Comma"))return;xe(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,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(f)}),a(",",l=>{if(Qc(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,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(p)}),()=>{s.forEach(l=>l())}},[n,r,e,t,o])}function p2(t){return Mfe(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 Mfe(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 Qc(t){return t.menus.hasAnyOpenMenus()||t.getEditingShapeId()!==null||t.getCrashingError()}const Afe=w.createContext(!1);function jfe({children:t}){const e=z(),n=Jl(),r=An(),o=Ee(),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`
412
- #${n}_main > *:nth-child(n + ${s+(c?1:2)})${f} {
413
- display: none;
414
- }
415
- #${n}_more > *:nth-child(-n + ${s}) {
416
- display: none;
417
- }
418
- `},[c,n,s]),p=Hg(()=>{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)Wn(g,v=>{var b;if(Qc(e))return;xe(v);const S=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];S&&S.click()});return()=>{Wn.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<St.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${n}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(Fr,{type:"toolbar",sourceId:"toolbar",children:t})}),i>s+1&&d.jsx(Afe.Provider,{value:!0,children:d.jsxs(ga,{id:"toolbar overflow",modal:!1,children:[d.jsx(ma,{children:d.jsx(ce,{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(ya,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx(Fr,{type:"toolbar-overflow",sourceId:"toolbar",children:t})})})]})})]})]})}function Ofe({activeToolId:t}){const e=z(),n=An(),r=Ee(),o=U("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),s=U("current tool",()=>e.getCurrentTool(),[e]);return!t||!s.isLockable?null:d.jsx(ce,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:le("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<St.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!o}),children:d.jsx(be,{icon:o?"lock":"unlock",small:!0})})}const Dfe=w.memo(function({children:e}){const n=z(),r=An(),o=wr(),s=U("current tool id",()=>n.getCurrentToolId(),[n]),i=w.useRef(null);Mi(i);const{ActionsMenu:a,QuickActions:l}=Di(),c=n.options.actionShortcutsLocation==="menu"?!1:n.options.actionShortcutsLocation==="toolbar"?!0:r<St.TABLET;return d.jsx("div",{ref:i,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:[c&&d.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[l&&d.jsx(l,{}),a&&d.jsx(a,{})]}),d.jsx(Ofe,{activeToolId:s})]}),d.jsx(jfe,{children:e??d.jsx(Upe,{})})]}),r<St.TABLET_SM&&!o&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(Bpe,{})})]})})});function Rfe(){const t=Ee();return d.jsxs("div",{className:le("tlui-offline-indicator"),children:[t("status.offline"),d.jsx(Bo,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function Lfe({maxWidth:t=420,ignoreRightWidth:e=0,stylePanelWidth:n=148,marginBetweenZones:r=12,squeezeAmount:o=52,children:s}){const i=w.useRef(null),a=An(),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 y=(f-v)/2;f%2!==0&&(y-=.5);const S=g+r,b=c.offsetLeft,P=Math.min(f-m-g-2*r,t),C=Math.max(y,S)-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 $fe(){const t=eie()==="offline";return d.jsx(Lfe,{children:t&&d.jsx(Rfe,{})})}function Ffe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"zoom-in",noClose:!0}),d.jsx(W,{actionId:"zoom-out",noClose:!0}),d.jsx(RF,{}),d.jsx(LF,{}),d.jsx($F,{})]})}const Nfe=w.memo(function({children:e}){const n=Mt(),[r,o]=Ms("zoom menu"),s=e??d.jsx(Ffe,{});return d.jsxs(cb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(ub,{asChild:!0,dir:"ltr",children:d.jsx(zfe,{})}),d.jsx(um,{container:n,children:d.jsx(db,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(Fr,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),zfe=w.forwardRef(function(e,n){const r=z(),o=An(),s=U("zoom",()=>r.getZoomLevel(),[r]),i=Ee(),a=w.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.jsx(ce,{ref:n,...e,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<St.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:o<St.MOBILE?null:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),T4=w.createContext(null);function Bfe({overrides:t={},children:e}){const n=tc(t),r=gm();return d.jsx(T4.Provider,{value:w.useMemo(()=>({ContextMenu:nhe,ActionsMenu:Mde,HelpMenu:null,ZoomMenu:Nfe,MainMenu:Lhe,Minimap:Ghe,StylePanel:zpe,PageMenu:qhe,NavigationPanel:Yhe,Toolbar:Dfe,KeyboardShortcutsDialog:_he,QuickActions:epe,HelperButtons:Phe,DebugPanel:fhe,DebugMenu:phe,MenuPanel:She,SharePanel:r?ape:null,CursorChatBubble:r?she:null,TopPanel:r?$fe:null,...n}),[n,r]),children:e})}function Di(){const t=w.useContext(T4);if(!t)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return t}const Ufe=qt(function({overrides:e,components:n,assetUrls:r,onUiEvent:o,forceMobile:s,mediaMimeTypes:i,children:a}){const l=ki();return d.jsx(N$.Provider,{value:i,children:d.jsx(Ese,{assetUrls:ode(r),children:d.jsx(Mse,{overrides:Tae(e),locale:(l==null?void 0:l.user.getLocale())??xo.locale,children:d.jsx(vte,{onEvent:o,children:d.jsx(_ie,{children:d.jsx(nie,{context:l==null?void 0:l.contextId,children:d.jsx(tie,{forceMobile:s,children:d.jsx(Bfe,{overrides:n,children:l?d.jsx(Hfe,{overrides:e,children:a}):a})})})})})})})})});function Hfe({overrides:t,children:e}){const n=Mae(t);return d.jsx(jae,{overrides:n.actions,children:d.jsx(Yae,{overrides:n.tools,children:e})})}function Kfe(){const t=z(),{addToast:e}=Ts();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 Wfe=Te.memo(function({renderDebugMenuItems:e,children:n,hideUi:r,components:o,...s}){return d.jsx(Ufe,{...s,components:o,children:d.jsx(Gfe,{hideUi:r,renderDebugMenuItems:e,children:n})})}),Gfe=Te.memo(function({children:e,hideUi:n,...r}){return d.jsxs(d.Fragment,{children:[e,n?null:d.jsx(Vfe,{...r})]})}),Vfe=Te.memo(function(){const e=z(),n=Ee(),r=An(),o=wr(),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}=Di();Tfe(),tae(),Kfe();const{"toggle-focus-mode":y}=Ea();return d.jsxs("div",{className:le("tlui-layout",{"tlui-layout__mobile":r<St.TABLET_SM}),"data-breakpoint":r,children:[s?d.jsx("div",{className:"tlui-layout__top",children:d.jsx(ce,{type:"icon",className:"tlui-focus-button",title:n("focus-mode.toggle-focus-mode"),onClick:()=>y.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>=St.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(Vae,{}),d.jsx(Hae,{}),d.jsx(tde,{}),v&&d.jsx(v,{})]})});async function Yfe(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=`
419
- @font-face {
420
- font-family: ${p.family};
421
- font-stretch: ${p.stretch};
422
- font-weight: ${p.weight};
423
- font-style: ${p.style};
424
- src: url("${n}") format("${u}")
425
- }`,p}const Uh=(t,e)=>{const[n,r]=w.useState(2);return w.useEffect(()=>{let o=!1;return r(2),Yfe(t,e).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[t,e]),n};function Xfe(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 M4(t){const e=w.useMemo(()=>Xfe(t),[t]),n=[Uh("tldraw_draw",e.draw),Uh("tldraw_serif",e.serif),Uh("tldraw_sans",e.sansSerif),Uh("tldraw_mono",e.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function qfe(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=tc(a),g=w.useMemo(()=>({Scribble:PE,ShapeIndicators:sle,CollaboratorScribble:PE,SelectionForeground:nle,SelectionBackground:ele,Handles:Xae,...f}),[f]),m=Xs(l),v=w.useMemo(()=>[..._5,...m],[m]),y=Xs(c),S=w.useMemo(()=>[...V$,...y],[y]),b=Xs(u),P=w.useMemo(()=>[...ede,...Hle,...b],[b]),C=Xs(o??xg),_=Xs(s??xw),E=w.useMemo(()=>[...C,..._],[C,_]),k=cF(p.assetUrls),{done:D,error:T}=M4(k);return T?d.jsx(XR,{children:"Could not load assets. Please refresh the page."}):D?(v.find($=>$.type==="embed")&&h&&Jf.setEmbedDefinitions(h),d.jsx(ote,{initialState:"select",...p,components:g,shapeUtils:v,bindingUtils:S,tools:P,children:d.jsxs(Wfe,{...p,components:g,mediaMimeTypes:E,children:[d.jsx(Zfe,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:C,acceptedVideoMimeTypes:_,onMount:i}),e]})})):d.jsx(D1,{children:d.jsx(v1,{})})}function Zfe({maxImageDimension:t=5e3,maxAssetSize:e=10*1024*1024,acceptedImageMimeTypes:n=xg,acceptedVideoMimeTypes:r=xw,onMount:o}){const s=z(),i=Ts(),a=Ee();qR(()=>{const u=[];return u.push(Cue(s)),ble(s,{maxImageDimension:t,maxAssetSize:e,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),u.push(s.store.props.onMount(s)),u.push(o==null?void 0:o(s)),()=>{u.forEach(h=>h==null?void 0:h())}});const{Canvas:l}=rt(),{ContextMenu:c}=Di();return c?d.jsx(c,{}):l?d.jsx(l,{}):null}w.memo(function(e){const[n,r]=w.useState(null),[o,s]=w.useState(null),i=Xs(e.shapeUtils??[]),a=w.useMemo(()=>[..._5,...i],[i]),l=Xs(e.bindingUtils??[]),c=w.useMemo(()=>[...V$,...l],[l]),u=dte({snapshot:e.snapshot,shapeUtils:a}),h=cF(e.assetUrls),{done:p,error:f}=M4(h),{pageId:g,bounds:m,scale:v,pixelRatio:y,background:S,padding:b,darkMode:P,preserveAspectRatio:C,format:_="svg",licenseKey:E}=e;return w.useLayoutEffect(()=>{if(!o||!u||!p)return;let k=!1;const D=document.createElement("div");o.appendChild(D),o.classList.add("tl-container","tl-theme__light");const T=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>D,licenseKey:E});g&&T.setCurrentPage(g);const j=T.getCurrentPageShapeIds();async function $(){const M=await T.getSvgString([...j],{bounds:m,scale:v,background:S,padding:b,darkMode:P,preserveAspectRatio:C});if(M&&!k){if(_==="svg"){if(!k){const O=new Blob([M.svg],{type:"image/svg+xml"}),F=URL.createObjectURL(O);r(F)}}else if(_==="png"){const O=await L$(T,M.svg,{type:_,width:M.width,height:M.height,pixelRatio:y});if(O&&!k){const F=URL.createObjectURL(O);r(F)}}}T.dispose()}return $(),()=>{k=!0}},[_,o,u,a,c,g,m,v,S,b,P,C,p,f,E,y]),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(D1,{children:d.jsx(v1,{})})});w.memo(function({children:e}){const n=Ee(),r=An(),o=w.useRef(null);Mi(o);const s=e??d.jsx(Ihe,{});return r<St.MOBILE?null:d.jsx("div",{ref:o,className:"tlui-help-menu",children:d.jsxs(ga,{id:"help menu",children:[d.jsx(ma,{children:d.jsx(ce,{type:"help",title:n("help-menu.title"),"data-testid":"help-menu.button",children:d.jsx(be,{icon:"question-mark",small:!0})})}),d.jsx(ya,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(Fr,{type:"menu",sourceId:"help-menu",children:s})})]})})});const Qfe=1,Jfe=Pe({schemaVersion:mn(1),storeVersion:ip,recordVersions:If(ye,Pe({version:ip,subTypeVersions:If(ye,ip).optional(),subTypeKey:ye.optional()}))}),ege=Pe({schemaVersion:mn(2),sequences:If(ye,ip)}),tge=Pe({tldrawFileFormatVersion:nY,schema:rY("schemaVersion",{1:Jfe,2:ege}),records:Kt(Pe({id:ye,typeName:ye}).allowUnknownProperties())});function nge(t){var e;try{return!!((e=t.document)!=null&&e.version)}catch{return!1}}function rge({json:t,schema:e}){let n;try{n=tge.validate(JSON.parse(t))}catch(s){try{if(n=JSON.parse(t),nge(n))return wn.err({type:"v1File",data:n})}catch{}return wn.err({type:"notATldrawFile",cause:s})}if(n.tldrawFileFormatVersion>Qfe)return wn.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r,o;try{const s=oge(n.records);o=Object.fromEntries(s.map(i=>[i.id,i])),r=e.migrateStoreSnapshot({store:o,schema:n.schema})}catch(s){return wn.err({type:"invalidRecords",cause:s})}if(r.type==="error")return wn.err({type:"migrationFailed",reason:r.reason});try{return wn.ok(Hu({snapshot:{store:o,schema:n.schema},schema:e}))}catch(s){return wn.err({type:"invalidRecords",cause:s})}}function oge(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))}Ci("tldraw","3.7.0-canary.383dfd14bf86","esm");function sge(){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=rge({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(qfe,{assetUrls:d8(),onMount:n,store:t})})}QS.createRoot(document.querySelector("#root")).render(d.jsx(Te.StrictMode,{children:d.jsx(sge,{})}));