@kitschpatrol/tldraw-cli 4.6.20 → 4.6.22
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.
- package/bin/cli.js +774 -788
- package/dist/lib/index.js +773 -787
- package/dist/tldraw/assets/index-B_dC5v5g.js +425 -0
- package/dist/tldraw/assets/{index-BqIZB63u.css → index-C2Zi_I-5.css} +1 -1
- package/dist/tldraw/index.html +2 -2
- package/dist/tldraw/translations/main.json +1 -0
- package/package.json +13 -13
- package/dist/tldraw/assets/index-ClJZpE8N.js +0 -431
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
var S4=Object.defineProperty;var v4=(t,e,n)=>e in t?S4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var E=(t,e,n)=>v4(t,typeof e!="symbol"?e+"":e,n);function x4(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 mi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var qE={exports:{}},Zf={},ZE={exports:{}},Ee={};/**
|
|
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 Yu=Symbol.for("react.element"),w4=Symbol.for("react.portal"),b4=Symbol.for("react.fragment"),P4=Symbol.for("react.strict_mode"),C4=Symbol.for("react.profiler"),_4=Symbol.for("react.provider"),I4=Symbol.for("react.context"),E4=Symbol.for("react.forward_ref"),k4=Symbol.for("react.suspense"),T4=Symbol.for("react.memo"),M4=Symbol.for("react.lazy"),rP=Symbol.iterator;function A4(t){return t===null||typeof t!="object"?null:(t=rP&&t[rP]||t["@@iterator"],typeof t=="function"?t:null)}var QE={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},JE=Object.assign,e2={};function $l(t,e,n){this.props=t,this.context=e,this.refs=e2,this.updater=n||QE}$l.prototype.isReactComponent={};$l.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")};$l.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function t2(){}t2.prototype=$l.prototype;function fx(t,e,n){this.props=t,this.context=e,this.refs=e2,this.updater=n||QE}var gx=fx.prototype=new t2;gx.constructor=fx;JE(gx,$l.prototype);gx.isPureReactComponent=!0;var oP=Array.isArray,n2=Object.prototype.hasOwnProperty,mx={current:null},r2={key:!0,ref:!0,__self:!0,__source:!0};function o2(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)n2.call(e,r)&&!r2.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:Yu,type:t,key:s,ref:i,props:o,_owner:mx.current}}function j4(t,e){return{$$typeof:Yu,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}function yx(t){return typeof t=="object"&&t!==null&&t.$$typeof===Yu}function O4(t){var e={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(n){return e[n]})}var sP=/\/+/g;function Am(t,e){return typeof t=="object"&&t!==null&&t.key!=null?O4(""+t.key):e.toString(36)}function Nh(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 Yu:case w4:i=!0}}if(i)return i=t,o=o(i),t=r===""?"."+Am(i,0):r,oP(o)?(n="",t!=null&&(n=t.replace(sP,"$&/")+"/"),Nh(o,e,n,"",function(c){return c})):o!=null&&(yx(o)&&(o=j4(o,n+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(sP,"$&/")+"/")+t)),e.push(o)),1;if(i=0,r=r===""?".":r+":",oP(t))for(var a=0;a<t.length;a++){s=t[a];var l=r+Am(s,a);i+=Nh(s,e,n,l,o)}else if(l=A4(t),typeof l=="function")for(t=l.call(t),a=0;!(s=t.next()).done;)s=s.value,l=r+Am(s,a++),i+=Nh(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 Rd(t,e,n){if(t==null)return t;var r=[],o=0;return Nh(t,r,"","",function(s){return e.call(n,s,o++)}),r}function D4(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 Pn={current:null},zh={transition:null},R4={ReactCurrentDispatcher:Pn,ReactCurrentBatchConfig:zh,ReactCurrentOwner:mx};function s2(){throw Error("act(...) is not supported in production builds of React.")}Ee.Children={map:Rd,forEach:function(t,e,n){Rd(t,function(){e.apply(this,arguments)},n)},count:function(t){var e=0;return Rd(t,function(){e++}),e},toArray:function(t){return Rd(t,function(e){return e})||[]},only:function(t){if(!yx(t))throw Error("React.Children.only expected to receive a single React element child.");return t}};Ee.Component=$l;Ee.Fragment=b4;Ee.Profiler=C4;Ee.PureComponent=fx;Ee.StrictMode=P4;Ee.Suspense=k4;Ee.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=R4;Ee.act=s2;Ee.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=JE({},t.props),o=t.key,s=t.ref,i=t._owner;if(e!=null){if(e.ref!==void 0&&(s=e.ref,i=mx.current),e.key!==void 0&&(o=""+e.key),t.type&&t.type.defaultProps)var a=t.type.defaultProps;for(l in e)n2.call(e,l)&&!r2.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:Yu,type:t.type,key:o,ref:s,props:r,_owner:i}};Ee.createContext=function(t){return t={$$typeof:I4,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},t.Provider={$$typeof:_4,_context:t},t.Consumer=t};Ee.createElement=o2;Ee.createFactory=function(t){var e=o2.bind(null,t);return e.type=t,e};Ee.createRef=function(){return{current:null}};Ee.forwardRef=function(t){return{$$typeof:E4,render:t}};Ee.isValidElement=yx;Ee.lazy=function(t){return{$$typeof:M4,_payload:{_status:-1,_result:t},_init:D4}};Ee.memo=function(t,e){return{$$typeof:T4,type:t,compare:e===void 0?null:e}};Ee.startTransition=function(t){var e=zh.transition;zh.transition={};try{t()}finally{zh.transition=e}};Ee.unstable_act=s2;Ee.useCallback=function(t,e){return Pn.current.useCallback(t,e)};Ee.useContext=function(t){return Pn.current.useContext(t)};Ee.useDebugValue=function(){};Ee.useDeferredValue=function(t){return Pn.current.useDeferredValue(t)};Ee.useEffect=function(t,e){return Pn.current.useEffect(t,e)};Ee.useId=function(){return Pn.current.useId()};Ee.useImperativeHandle=function(t,e,n){return Pn.current.useImperativeHandle(t,e,n)};Ee.useInsertionEffect=function(t,e){return Pn.current.useInsertionEffect(t,e)};Ee.useLayoutEffect=function(t,e){return Pn.current.useLayoutEffect(t,e)};Ee.useMemo=function(t,e){return Pn.current.useMemo(t,e)};Ee.useReducer=function(t,e,n){return Pn.current.useReducer(t,e,n)};Ee.useRef=function(t){return Pn.current.useRef(t)};Ee.useState=function(t){return Pn.current.useState(t)};Ee.useSyncExternalStore=function(t,e,n){return Pn.current.useSyncExternalStore(t,e,n)};Ee.useTransition=function(){return Pn.current.useTransition()};Ee.version="18.3.1";ZE.exports=Ee;var w=ZE.exports;const Te=mi(w),L4=x4({__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 $4=w,F4=Symbol.for("react.element"),N4=Symbol.for("react.fragment"),z4=Object.prototype.hasOwnProperty,B4=$4.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,U4={key:!0,ref:!0,__self:!0,__source:!0};function i2(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)z4.call(e,r)&&!U4.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:F4,type:t,key:s,ref:i,props:o,_owner:B4.current}}Zf.Fragment=N4;Zf.jsx=i2;Zf.jsxs=i2;qE.exports=Zf;var d=qE.exports,GS={},a2={exports:{}},Sr={},l2={exports:{}},c2={};/**
|
|
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($,U){var Y=$.length;$.push(U);e:for(;0<Y;){var te=Y-1>>>1,de=$[te];if(0<o(de,U))$[te]=U,$[Y]=de,Y=te;else break e}}function n($){return $.length===0?null:$[0]}function r($){if($.length===0)return null;var U=$[0],Y=$.pop();if(Y!==U){$[0]=Y;e:for(var te=0,de=$.length,he=de>>>1;te<he;){var ke=2*(te+1)-1,se=$[ke],We=ke+1,Fe=$[We];if(0>o(se,Y))We<de&&0>o(Fe,se)?($[te]=Fe,$[We]=Y,te=We):($[te]=se,$[ke]=Y,te=ke);else if(We<de&&0>o(Fe,Y))$[te]=Fe,$[We]=Y,te=We;else break e}}return U}function o($,U){var Y=$.sortIndex-U.sortIndex;return Y!==0?Y:$.id-U.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;t.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();t.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,h=null,p=3,f=!1,g=!1,m=!1,v=typeof setTimeout=="function"?setTimeout:null,S=typeof clearTimeout=="function"?clearTimeout:null,y=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function b($){for(var U=n(c);U!==null;){if(U.callback===null)r(c);else if(U.startTime<=$)r(c),U.sortIndex=U.expirationTime,e(l,U);else break;U=n(c)}}function P($){if(m=!1,b($),!g)if(n(l)!==null)g=!0,L(C);else{var U=n(c);U!==null&&G(P,U.startTime-$)}}function C($,U){g=!1,m&&(m=!1,S(_),_=-1),f=!0;var Y=p;try{for(b(U),h=n(l);h!==null&&(!(h.expirationTime>U)||$&&!D());){var te=h.callback;if(typeof te=="function"){h.callback=null,p=h.priorityLevel;var de=te(h.expirationTime<=U);U=t.unstable_now(),typeof de=="function"?h.callback=de:h===n(l)&&r(l),b(U)}else r(l);h=n(l)}if(h!==null)var he=!0;else{var ke=n(c);ke!==null&&G(P,ke.startTime-U),he=!1}return he}finally{h=null,p=Y,f=!1}}var I=!1,k=null,_=-1,T=5,M=-1;function D(){return!(t.unstable_now()-M<T)}function j(){if(k!==null){var $=t.unstable_now();M=$;var U=!0;try{U=k(!0,$)}finally{U?O():(I=!1,k=null)}}else I=!1}var O;if(typeof y=="function")O=function(){y(j)};else if(typeof MessageChannel<"u"){var R=new MessageChannel,B=R.port2;R.port1.onmessage=j,O=function(){B.postMessage(null)}}else O=function(){v(j,0)};function L($){k=$,I||(I=!0,O())}function G($,U){_=v(function(){$(t.unstable_now())},U)}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($){$.callback=null},t.unstable_continueExecution=function(){g||f||(g=!0,L(C))},t.unstable_forceFrameRate=function($){0>$||125<$?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):T=0<$?Math.floor(1e3/$):5},t.unstable_getCurrentPriorityLevel=function(){return p},t.unstable_getFirstCallbackNode=function(){return n(l)},t.unstable_next=function($){switch(p){case 1:case 2:case 3:var U=3;break;default:U=p}var Y=p;p=U;try{return $()}finally{p=Y}},t.unstable_pauseExecution=function(){},t.unstable_requestPaint=function(){},t.unstable_runWithPriority=function($,U){switch($){case 1:case 2:case 3:case 4:case 5:break;default:$=3}var Y=p;p=$;try{return U()}finally{p=Y}},t.unstable_scheduleCallback=function($,U,Y){var te=t.unstable_now();switch(typeof Y=="object"&&Y!==null?(Y=Y.delay,Y=typeof Y=="number"&&0<Y?te+Y:te):Y=te,$){case 1:var de=-1;break;case 2:de=250;break;case 5:de=1073741823;break;case 4:de=1e4;break;default:de=5e3}return de=Y+de,$={id:u++,callback:U,priorityLevel:$,startTime:Y,expirationTime:de,sortIndex:-1},Y>te?($.sortIndex=Y,e(c,$),n(l)===null&&$===n(c)&&(m?(S(_),_=-1):m=!0,G(P,Y-te))):($.sortIndex=de,e(l,$),g||f||(g=!0,L(C))),$},t.unstable_shouldYield=D,t.unstable_wrapCallback=function($){var U=p;return function(){var Y=p;p=U;try{return $.apply(this,arguments)}finally{p=Y}}}})(c2);l2.exports=c2;var H4=l2.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 K4=w,fr=H4;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 u2=new Set,hu={};function fa(t,e){wl(t,e),wl(t+"Capture",e)}function wl(t,e){for(hu[t]=e,t=0;t<e.length;t++)u2.add(e[t])}var ds=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),VS=Object.prototype.hasOwnProperty,W4=/^[: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]*$/,iP={},aP={};function G4(t){return VS.call(aP,t)?!0:VS.call(iP,t)?!1:W4.test(t)?aP[t]=!0:(iP[t]=!0,!1)}function V4(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 Y4(t,e,n,r){if(e===null||typeof e>"u"||V4(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 Cn(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 Xt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){Xt[t]=new Cn(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];Xt[e]=new Cn(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){Xt[t]=new Cn(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){Xt[t]=new Cn(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){Xt[t]=new Cn(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){Xt[t]=new Cn(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){Xt[t]=new Cn(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){Xt[t]=new Cn(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){Xt[t]=new Cn(t,5,!1,t.toLowerCase(),null,!1,!1)});var Sx=/[\-:]([a-z])/g;function vx(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(Sx,vx);Xt[e]=new Cn(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(Sx,vx);Xt[e]=new Cn(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(Sx,vx);Xt[e]=new Cn(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){Xt[t]=new Cn(t,1,!1,t.toLowerCase(),null,!1,!1)});Xt.xlinkHref=new Cn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){Xt[t]=new Cn(t,1,!1,t.toLowerCase(),null,!0,!0)});function xx(t,e,n,r){var o=Xt.hasOwnProperty(e)?Xt[e]:null;(o!==null?o.type!==0:r||!(2<e.length)||e[0]!=="o"&&e[0]!=="O"||e[1]!=="n"&&e[1]!=="N")&&(Y4(e,n,o,r)&&(n=null),r||o===null?G4(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 vs=K4.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Ld=Symbol.for("react.element"),za=Symbol.for("react.portal"),Ba=Symbol.for("react.fragment"),wx=Symbol.for("react.strict_mode"),YS=Symbol.for("react.profiler"),d2=Symbol.for("react.provider"),h2=Symbol.for("react.context"),bx=Symbol.for("react.forward_ref"),XS=Symbol.for("react.suspense"),qS=Symbol.for("react.suspense_list"),Px=Symbol.for("react.memo"),Ls=Symbol.for("react.lazy"),p2=Symbol.for("react.offscreen"),lP=Symbol.iterator;function lc(t){return t===null||typeof t!="object"?null:(t=lP&&t[lP]||t["@@iterator"],typeof t=="function"?t:null)}var gt=Object.assign,jm;function Rc(t){if(jm===void 0)try{throw Error()}catch(n){var e=n.stack.trim().match(/\n( *(at )?)/);jm=e&&e[1]||""}return`
|
|
34
|
-
`+jm+t}var Om=!1;function Dm(t,e){if(!t||Om)return"";Om=!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{Om=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?Rc(t):""}function X4(t){switch(t.tag){case 5:return Rc(t.type);case 16:return Rc("Lazy");case 13:return Rc("Suspense");case 19:return Rc("SuspenseList");case 0:case 2:case 15:return t=Dm(t.type,!1),t;case 11:return t=Dm(t.type.render,!1),t;case 1:return t=Dm(t.type,!0),t;default:return""}}function ZS(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 Ba:return"Fragment";case za:return"Portal";case YS:return"Profiler";case wx:return"StrictMode";case XS:return"Suspense";case qS:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case h2:return(t.displayName||"Context")+".Consumer";case d2:return(t._context.displayName||"Context")+".Provider";case bx:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Px:return e=t.displayName||null,e!==null?e:ZS(t.type)||"Memo";case Ls:e=t._payload,t=t._init;try{return ZS(t(e))}catch{}}return null}function q4(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 ZS(e);case 8:return e===wx?"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 ii(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function f2(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function Z4(t){var e=f2(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 $d(t){t._valueTracker||(t._valueTracker=Z4(t))}function g2(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=f2(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Dp(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 QS(t,e){var n=e.checked;return gt({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function cP(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=ii(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 m2(t,e){e=e.checked,e!=null&&xx(t,"checked",e,!1)}function JS(t,e){m2(t,e);var n=ii(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")?ev(t,e.type,n):e.hasOwnProperty("defaultValue")&&ev(t,e.type,ii(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function uP(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 ev(t,e,n){(e!=="number"||Dp(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var Lc=Array.isArray;function ll(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=""+ii(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 tv(t,e){if(e.dangerouslySetInnerHTML!=null)throw Error(X(91));return gt({},e,{value:void 0,defaultValue:void 0,children:""+t._wrapperState.initialValue})}function dP(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(Lc(n)){if(1<n.length)throw Error(X(93));n=n[0]}e=n}e==null&&(e=""),n=e}t._wrapperState={initialValue:ii(n)}}function y2(t,e){var n=ii(e.value),r=ii(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 hP(t){var e=t.textContent;e===t._wrapperState.initialValue&&e!==""&&e!==null&&(t.value=e)}function S2(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 nv(t,e){return t==null||t==="http://www.w3.org/1999/xhtml"?S2(e):t==="http://www.w3.org/2000/svg"&&e==="foreignObject"?"http://www.w3.org/1999/xhtml":t}var Fd,v2=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(Fd=Fd||document.createElement("div"),Fd.innerHTML="<svg>"+e.valueOf().toString()+"</svg>",e=Fd.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function pu(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Xc={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},Q4=["Webkit","ms","Moz","O"];Object.keys(Xc).forEach(function(t){Q4.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Xc[e]=Xc[t]})});function x2(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Xc.hasOwnProperty(t)&&Xc[t]?(""+e).trim():e+"px"}function w2(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=x2(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,o):t[n]=o}}var J4=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 rv(t,e){if(e){if(J4[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 ov(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 sv=null;function Cx(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var iv=null,cl=null,ul=null;function pP(t){if(t=Zu(t)){if(typeof iv!="function")throw Error(X(280));var e=t.stateNode;e&&(e=ng(e),iv(t.stateNode,t.type,e))}}function b2(t){cl?ul?ul.push(t):ul=[t]:cl=t}function P2(){if(cl){var t=cl,e=ul;if(ul=cl=null,pP(t),e)for(t=0;t<e.length;t++)pP(e[t])}}function C2(t,e){return t(e)}function _2(){}var Rm=!1;function I2(t,e,n){if(Rm)return t(e,n);Rm=!0;try{return C2(t,e,n)}finally{Rm=!1,(cl!==null||ul!==null)&&(_2(),P2())}}function fu(t,e){var n=t.stateNode;if(n===null)return null;var r=ng(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 av=!1;if(ds)try{var cc={};Object.defineProperty(cc,"passive",{get:function(){av=!0}}),window.addEventListener("test",cc,cc),window.removeEventListener("test",cc,cc)}catch{av=!1}function e6(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 qc=!1,Rp=null,Lp=!1,lv=null,t6={onError:function(t){qc=!0,Rp=t}};function n6(t,e,n,r,o,s,i,a,l){qc=!1,Rp=null,e6.apply(t6,arguments)}function r6(t,e,n,r,o,s,i,a,l){if(n6.apply(this,arguments),qc){if(qc){var c=Rp;qc=!1,Rp=null}else throw Error(X(198));Lp||(Lp=!0,lv=c)}}function ga(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 E2(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 fP(t){if(ga(t)!==t)throw Error(X(188))}function o6(t){var e=t.alternate;if(!e){if(e=ga(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 fP(o),t;if(s===r)return fP(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 k2(t){return t=o6(t),t!==null?T2(t):null}function T2(t){if(t.tag===5||t.tag===6)return t;for(t=t.child;t!==null;){var e=T2(t);if(e!==null)return e;t=t.sibling}return null}var M2=fr.unstable_scheduleCallback,gP=fr.unstable_cancelCallback,s6=fr.unstable_shouldYield,i6=fr.unstable_requestPaint,wt=fr.unstable_now,a6=fr.unstable_getCurrentPriorityLevel,_x=fr.unstable_ImmediatePriority,A2=fr.unstable_UserBlockingPriority,$p=fr.unstable_NormalPriority,l6=fr.unstable_LowPriority,j2=fr.unstable_IdlePriority,Qf=null,_o=null;function c6(t){if(_o&&typeof _o.onCommitFiberRoot=="function")try{_o.onCommitFiberRoot(Qf,t,void 0,(t.current.flags&128)===128)}catch{}}var Zr=Math.clz32?Math.clz32:h6,u6=Math.log,d6=Math.LN2;function h6(t){return t>>>=0,t===0?32:31-(u6(t)/d6|0)|0}var Nd=64,zd=4194304;function $c(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 Fp(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=$c(a):(s&=i,s!==0&&(r=$c(s)))}else i=n&~o,i!==0?r=$c(i):s!==0&&(r=$c(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-Zr(e),o=1<<n,r|=t[n],e&=~o;return r}function p6(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 f6(t,e){for(var n=t.suspendedLanes,r=t.pingedLanes,o=t.expirationTimes,s=t.pendingLanes;0<s;){var i=31-Zr(s),a=1<<i,l=o[i];l===-1?(!(a&n)||a&r)&&(o[i]=p6(a,e)):l<=e&&(t.expiredLanes|=a),s&=~a}}function cv(t){return t=t.pendingLanes&-1073741825,t!==0?t:t&1073741824?1073741824:0}function O2(){var t=Nd;return Nd<<=1,!(Nd&4194240)&&(Nd=64),t}function Lm(t){for(var e=[],n=0;31>n;n++)e.push(t);return e}function Xu(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-Zr(e),t[e]=n}function g6(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-Zr(n),s=1<<o;e[o]=0,r[o]=-1,t[o]=-1,n&=~s}}function Ix(t,e){var n=t.entangledLanes|=e;for(t=t.entanglements;n;){var r=31-Zr(n),o=1<<r;o&e|t[r]&e&&(t[r]|=e),n&=~o}}var Ue=0;function D2(t){return t&=-t,1<t?4<t?t&268435455?16:536870912:4:1}var R2,Ex,L2,$2,F2,uv=!1,Bd=[],Ys=null,Xs=null,qs=null,gu=new Map,mu=new Map,Fs=[],m6="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":Ys=null;break;case"dragenter":case"dragleave":Xs=null;break;case"mouseover":case"mouseout":qs=null;break;case"pointerover":case"pointerout":gu.delete(e.pointerId);break;case"gotpointercapture":case"lostpointercapture":mu.delete(e.pointerId)}}function uc(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=Zu(e),e!==null&&Ex(e)),t):(t.eventSystemFlags|=r,e=t.targetContainers,o!==null&&e.indexOf(o)===-1&&e.push(o),t)}function y6(t,e,n,r,o){switch(e){case"focusin":return Ys=uc(Ys,t,e,n,r,o),!0;case"dragenter":return Xs=uc(Xs,t,e,n,r,o),!0;case"mouseover":return qs=uc(qs,t,e,n,r,o),!0;case"pointerover":var s=o.pointerId;return gu.set(s,uc(gu.get(s)||null,t,e,n,r,o)),!0;case"gotpointercapture":return s=o.pointerId,mu.set(s,uc(mu.get(s)||null,t,e,n,r,o)),!0}return!1}function N2(t){var e=Bi(t.target);if(e!==null){var n=ga(e);if(n!==null){if(e=n.tag,e===13){if(e=E2(n),e!==null){t.blockedOn=e,F2(t.priority,function(){L2(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 Bh(t){if(t.blockedOn!==null)return!1;for(var e=t.targetContainers;0<e.length;){var n=dv(t.domEventName,t.eventSystemFlags,e[0],t.nativeEvent);if(n===null){n=t.nativeEvent;var r=new n.constructor(n.type,n);sv=r,n.target.dispatchEvent(r),sv=null}else return e=Zu(n),e!==null&&Ex(e),t.blockedOn=n,!1;e.shift()}return!0}function yP(t,e,n){Bh(t)&&n.delete(e)}function S6(){uv=!1,Ys!==null&&Bh(Ys)&&(Ys=null),Xs!==null&&Bh(Xs)&&(Xs=null),qs!==null&&Bh(qs)&&(qs=null),gu.forEach(yP),mu.forEach(yP)}function dc(t,e){t.blockedOn===e&&(t.blockedOn=null,uv||(uv=!0,fr.unstable_scheduleCallback(fr.unstable_NormalPriority,S6)))}function yu(t){function e(o){return dc(o,t)}if(0<Bd.length){dc(Bd[0],t);for(var n=1;n<Bd.length;n++){var r=Bd[n];r.blockedOn===t&&(r.blockedOn=null)}}for(Ys!==null&&dc(Ys,t),Xs!==null&&dc(Xs,t),qs!==null&&dc(qs,t),gu.forEach(e),mu.forEach(e),n=0;n<Fs.length;n++)r=Fs[n],r.blockedOn===t&&(r.blockedOn=null);for(;0<Fs.length&&(n=Fs[0],n.blockedOn===null);)N2(n),n.blockedOn===null&&Fs.shift()}var dl=vs.ReactCurrentBatchConfig,Np=!0;function v6(t,e,n,r){var o=Ue,s=dl.transition;dl.transition=null;try{Ue=1,kx(t,e,n,r)}finally{Ue=o,dl.transition=s}}function x6(t,e,n,r){var o=Ue,s=dl.transition;dl.transition=null;try{Ue=4,kx(t,e,n,r)}finally{Ue=o,dl.transition=s}}function kx(t,e,n,r){if(Np){var o=dv(t,e,n,r);if(o===null)Gm(t,e,r,zp,n),mP(t,r);else if(y6(o,t,e,n,r))r.stopPropagation();else if(mP(t,r),e&4&&-1<m6.indexOf(t)){for(;o!==null;){var s=Zu(o);if(s!==null&&R2(s),s=dv(t,e,n,r),s===null&&Gm(t,e,r,zp,n),s===o)break;o=s}o!==null&&r.stopPropagation()}else Gm(t,e,r,null,n)}}var zp=null;function dv(t,e,n,r){if(zp=null,t=Cx(r),t=Bi(t),t!==null)if(e=ga(t),e===null)t=null;else if(n=e.tag,n===13){if(t=E2(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 zp=t,null}function z2(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(a6()){case _x:return 1;case A2:return 4;case $p:case l6:return 16;case j2:return 536870912;default:return 16}default:return 16}}var Hs=null,Tx=null,Uh=null;function B2(){if(Uh)return Uh;var t,e=Tx,n=e.length,r,o="value"in Hs?Hs.value:Hs.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 Uh=o.slice(t,1<r?1-r:void 0)}function Hh(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 Ud(){return!0}function SP(){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)?Ud:SP,this.isPropagationStopped=SP,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=Ud)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=Ud)},persist:function(){},isPersistent:Ud}),e}var Fl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(t){return t.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Mx=vr(Fl),qu=gt({},Fl,{view:0,detail:0}),w6=vr(qu),$m,Fm,hc,Jf=gt({},qu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Ax,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!==hc&&(hc&&t.type==="mousemove"?($m=t.screenX-hc.screenX,Fm=t.screenY-hc.screenY):Fm=$m=0,hc=t),$m)},movementY:function(t){return"movementY"in t?t.movementY:Fm}}),vP=vr(Jf),b6=gt({},Jf,{dataTransfer:0}),P6=vr(b6),C6=gt({},qu,{relatedTarget:0}),Nm=vr(C6),_6=gt({},Fl,{animationName:0,elapsedTime:0,pseudoElement:0}),I6=vr(_6),E6=gt({},Fl,{clipboardData:function(t){return"clipboardData"in t?t.clipboardData:window.clipboardData}}),k6=vr(E6),T6=gt({},Fl,{data:0}),xP=vr(T6),M6={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},A6={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"},j6={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function O6(t){var e=this.nativeEvent;return e.getModifierState?e.getModifierState(t):(t=j6[t])?!!e[t]:!1}function Ax(){return O6}var D6=gt({},qu,{key:function(t){if(t.key){var e=M6[t.key]||t.key;if(e!=="Unidentified")return e}return t.type==="keypress"?(t=Hh(t),t===13?"Enter":String.fromCharCode(t)):t.type==="keydown"||t.type==="keyup"?A6[t.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Ax,charCode:function(t){return t.type==="keypress"?Hh(t):0},keyCode:function(t){return t.type==="keydown"||t.type==="keyup"?t.keyCode:0},which:function(t){return t.type==="keypress"?Hh(t):t.type==="keydown"||t.type==="keyup"?t.keyCode:0}}),R6=vr(D6),L6=gt({},Jf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),wP=vr(L6),$6=gt({},qu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Ax}),F6=vr($6),N6=gt({},Fl,{propertyName:0,elapsedTime:0,pseudoElement:0}),z6=vr(N6),B6=gt({},Jf,{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}),U6=vr(B6),H6=[9,13,27,32],jx=ds&&"CompositionEvent"in window,Zc=null;ds&&"documentMode"in document&&(Zc=document.documentMode);var K6=ds&&"TextEvent"in window&&!Zc,U2=ds&&(!jx||Zc&&8<Zc&&11>=Zc),bP=" ",PP=!1;function H2(t,e){switch(t){case"keyup":return H6.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function K2(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var Ua=!1;function W6(t,e){switch(t){case"compositionend":return K2(e);case"keypress":return e.which!==32?null:(PP=!0,bP);case"textInput":return t=e.data,t===bP&&PP?null:t;default:return null}}function G6(t,e){if(Ua)return t==="compositionend"||!jx&&H2(t,e)?(t=B2(),Uh=Tx=Hs=null,Ua=!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 U2&&e.locale!=="ko"?null:e.data;default:return null}}var V6={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 CP(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e==="input"?!!V6[t.type]:e==="textarea"}function W2(t,e,n,r){b2(r),e=Bp(e,"onChange"),0<e.length&&(n=new Mx("onChange","change",null,n,r),t.push({event:n,listeners:e}))}var Qc=null,Su=null;function Y6(t){nk(t,0)}function eg(t){var e=Wa(t);if(g2(e))return t}function X6(t,e){if(t==="change")return e}var G2=!1;if(ds){var zm;if(ds){var Bm="oninput"in document;if(!Bm){var _P=document.createElement("div");_P.setAttribute("oninput","return;"),Bm=typeof _P.oninput=="function"}zm=Bm}else zm=!1;G2=zm&&(!document.documentMode||9<document.documentMode)}function IP(){Qc&&(Qc.detachEvent("onpropertychange",V2),Su=Qc=null)}function V2(t){if(t.propertyName==="value"&&eg(Su)){var e=[];W2(e,Su,t,Cx(t)),I2(Y6,e)}}function q6(t,e,n){t==="focusin"?(IP(),Qc=e,Su=n,Qc.attachEvent("onpropertychange",V2)):t==="focusout"&&IP()}function Z6(t){if(t==="selectionchange"||t==="keyup"||t==="keydown")return eg(Su)}function Q6(t,e){if(t==="click")return eg(e)}function J6(t,e){if(t==="input"||t==="change")return eg(e)}function ez(t,e){return t===e&&(t!==0||1/t===1/e)||t!==t&&e!==e}var to=typeof Object.is=="function"?Object.is:ez;function vu(t,e){if(to(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(!VS.call(e,o)||!to(t[o],e[o]))return!1}return!0}function EP(t){for(;t&&t.firstChild;)t=t.firstChild;return t}function kP(t,e){var n=EP(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=EP(n)}}function Y2(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?Y2(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function X2(){for(var t=window,e=Dp();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Dp(t.document)}return e}function Ox(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 tz(t){var e=X2(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&Y2(n.ownerDocument.documentElement,n)){if(r!==null&&Ox(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=kP(n,s);var i=kP(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 nz=ds&&"documentMode"in document&&11>=document.documentMode,Ha=null,hv=null,Jc=null,pv=!1;function TP(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;pv||Ha==null||Ha!==Dp(r)||(r=Ha,"selectionStart"in r&&Ox(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}),Jc&&vu(Jc,r)||(Jc=r,r=Bp(hv,"onSelect"),0<r.length&&(e=new Mx("onSelect","select",null,e,n),t.push({event:e,listeners:r}),e.target=Ha)))}function Hd(t,e){var n={};return n[t.toLowerCase()]=e.toLowerCase(),n["Webkit"+t]="webkit"+e,n["Moz"+t]="moz"+e,n}var Ka={animationend:Hd("Animation","AnimationEnd"),animationiteration:Hd("Animation","AnimationIteration"),animationstart:Hd("Animation","AnimationStart"),transitionend:Hd("Transition","TransitionEnd")},Um={},q2={};ds&&(q2=document.createElement("div").style,"AnimationEvent"in window||(delete Ka.animationend.animation,delete Ka.animationiteration.animation,delete Ka.animationstart.animation),"TransitionEvent"in window||delete Ka.transitionend.transition);function tg(t){if(Um[t])return Um[t];if(!Ka[t])return t;var e=Ka[t],n;for(n in e)if(e.hasOwnProperty(n)&&n in q2)return Um[t]=e[n];return t}var Z2=tg("animationend"),Q2=tg("animationiteration"),J2=tg("animationstart"),ek=tg("transitionend"),tk=new Map,MP="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 yi(t,e){tk.set(t,e),fa(e,[t])}for(var Hm=0;Hm<MP.length;Hm++){var Km=MP[Hm],rz=Km.toLowerCase(),oz=Km[0].toUpperCase()+Km.slice(1);yi(rz,"on"+oz)}yi(Z2,"onAnimationEnd");yi(Q2,"onAnimationIteration");yi(J2,"onAnimationStart");yi("dblclick","onDoubleClick");yi("focusin","onFocus");yi("focusout","onBlur");yi(ek,"onTransitionEnd");wl("onMouseEnter",["mouseout","mouseover"]);wl("onMouseLeave",["mouseout","mouseover"]);wl("onPointerEnter",["pointerout","pointerover"]);wl("onPointerLeave",["pointerout","pointerover"]);fa("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));fa("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));fa("onBeforeInput",["compositionend","keypress","textInput","paste"]);fa("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));fa("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));fa("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Fc="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(" "),sz=new Set("cancel close invalid load scroll toggle".split(" ").concat(Fc));function AP(t,e,n){var r=t.type||"unknown-event";t.currentTarget=n,r6(r,e,void 0,t),t.currentTarget=null}function nk(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;AP(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;AP(o,a,c),s=l}}}if(Lp)throw t=lv,Lp=!1,lv=null,t}function tt(t,e){var n=e[Sv];n===void 0&&(n=e[Sv]=new Set);var r=t+"__bubble";n.has(r)||(rk(e,t,2,!1),n.add(r))}function Wm(t,e,n){var r=0;e&&(r|=4),rk(n,t,r,e)}var Kd="_reactListening"+Math.random().toString(36).slice(2);function xu(t){if(!t[Kd]){t[Kd]=!0,u2.forEach(function(n){n!=="selectionchange"&&(sz.has(n)||Wm(n,!1,t),Wm(n,!0,t))});var e=t.nodeType===9?t:t.ownerDocument;e===null||e[Kd]||(e[Kd]=!0,Wm("selectionchange",!1,e))}}function rk(t,e,n,r){switch(z2(e)){case 1:var o=v6;break;case 4:o=x6;break;default:o=kx}n=o.bind(null,e,n,t),o=void 0,!av||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 Gm(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=Bi(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}I2(function(){var c=s,u=Cx(n),h=[];e:{var p=tk.get(t);if(p!==void 0){var f=Mx,g=t;switch(t){case"keypress":if(Hh(n)===0)break e;case"keydown":case"keyup":f=R6;break;case"focusin":g="focus",f=Nm;break;case"focusout":g="blur",f=Nm;break;case"beforeblur":case"afterblur":f=Nm;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=vP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=P6;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=F6;break;case Z2:case Q2:case J2:f=I6;break;case ek:f=z6;break;case"scroll":f=w6;break;case"wheel":f=U6;break;case"copy":case"cut":case"paste":f=k6;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=wP}var m=(e&4)!==0,v=!m&&t==="scroll",S=m?p!==null?p+"Capture":null:p;m=[];for(var y=c,b;y!==null;){b=y;var P=b.stateNode;if(b.tag===5&&P!==null&&(b=P,S!==null&&(P=fu(y,S),P!=null&&m.push(wu(y,P,b)))),v)break;y=y.return}0<m.length&&(p=new f(p,g,null,n,u),h.push({event:p,listeners:m}))}}if(!(e&7)){e:{if(p=t==="mouseover"||t==="pointerover",f=t==="mouseout"||t==="pointerout",p&&n!==sv&&(g=n.relatedTarget||n.fromElement)&&(Bi(g)||g[hs]))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?Bi(g):null,g!==null&&(v=ga(g),g!==v||g.tag!==5&&g.tag!==6)&&(g=null)):(f=null,g=c),f!==g)){if(m=vP,P="onMouseLeave",S="onMouseEnter",y="mouse",(t==="pointerout"||t==="pointerover")&&(m=wP,P="onPointerLeave",S="onPointerEnter",y="pointer"),v=f==null?p:Wa(f),b=g==null?p:Wa(g),p=new m(P,y+"leave",f,n,u),p.target=v,p.relatedTarget=b,P=null,Bi(u)===c&&(m=new m(S,y+"enter",g,n,u),m.target=b,m.relatedTarget=v,P=m),v=P,f&&g)t:{for(m=f,S=g,y=0,b=m;b;b=_a(b))y++;for(b=0,P=S;P;P=_a(P))b++;for(;0<y-b;)m=_a(m),y--;for(;0<b-y;)S=_a(S),b--;for(;y--;){if(m===S||S!==null&&m===S.alternate)break t;m=_a(m),S=_a(S)}m=null}else m=null;f!==null&&jP(h,p,f,m,!1),g!==null&&v!==null&&jP(h,v,g,m,!0)}}e:{if(p=c?Wa(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var C=X6;else if(CP(p))if(G2)C=J6;else{C=Z6;var I=q6}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(C=Q6);if(C&&(C=C(t,c))){W2(h,C,n,u);break e}I&&I(t,p,c),t==="focusout"&&(I=p._wrapperState)&&I.controlled&&p.type==="number"&&ev(p,"number",p.value)}switch(I=c?Wa(c):window,t){case"focusin":(CP(I)||I.contentEditable==="true")&&(Ha=I,hv=c,Jc=null);break;case"focusout":Jc=hv=Ha=null;break;case"mousedown":pv=!0;break;case"contextmenu":case"mouseup":case"dragend":pv=!1,TP(h,n,u);break;case"selectionchange":if(nz)break;case"keydown":case"keyup":TP(h,n,u)}var k;if(jx)e:{switch(t){case"compositionstart":var _="onCompositionStart";break e;case"compositionend":_="onCompositionEnd";break e;case"compositionupdate":_="onCompositionUpdate";break e}_=void 0}else Ua?H2(t,n)&&(_="onCompositionEnd"):t==="keydown"&&n.keyCode===229&&(_="onCompositionStart");_&&(U2&&n.locale!=="ko"&&(Ua||_!=="onCompositionStart"?_==="onCompositionEnd"&&Ua&&(k=B2()):(Hs=u,Tx="value"in Hs?Hs.value:Hs.textContent,Ua=!0)),I=Bp(c,_),0<I.length&&(_=new xP(_,t,null,n,u),h.push({event:_,listeners:I}),k?_.data=k:(k=K2(n),k!==null&&(_.data=k)))),(k=K6?W6(t,n):G6(t,n))&&(c=Bp(c,"onBeforeInput"),0<c.length&&(u=new xP("onBeforeInput","beforeinput",null,n,u),h.push({event:u,listeners:c}),u.data=k))}nk(h,e)})}function wu(t,e,n){return{instance:t,listener:e,currentTarget:n}}function Bp(t,e){for(var n=e+"Capture",r=[];t!==null;){var o=t,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=fu(t,n),s!=null&&r.unshift(wu(t,s,o)),s=fu(t,e),s!=null&&r.push(wu(t,s,o))),t=t.return}return r}function _a(t){if(t===null)return null;do t=t.return;while(t&&t.tag!==5);return t||null}function jP(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=fu(n,s),l!=null&&i.unshift(wu(n,l,a))):o||(l=fu(n,s),l!=null&&i.push(wu(n,l,a)))),n=n.return}i.length!==0&&t.push({event:e,listeners:i})}var iz=/\r\n?/g,az=/\u0000|\uFFFD/g;function OP(t){return(typeof t=="string"?t:""+t).replace(iz,`
|
|
38
|
-
`).replace(az,"")}function Wd(t,e,n){if(e=OP(e),OP(t)!==e&&n)throw Error(X(425))}function Up(){}var fv=null,gv=null;function mv(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 yv=typeof setTimeout=="function"?setTimeout:void 0,lz=typeof clearTimeout=="function"?clearTimeout:void 0,DP=typeof Promise=="function"?Promise:void 0,cz=typeof queueMicrotask=="function"?queueMicrotask:typeof DP<"u"?function(t){return DP.resolve(null).then(t).catch(uz)}:yv;function uz(t){setTimeout(function(){throw t})}function Vm(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),yu(e);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=o}while(n);yu(e)}function Zs(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 RP(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 Nl=Math.random().toString(36).slice(2),So="__reactFiber$"+Nl,bu="__reactProps$"+Nl,hs="__reactContainer$"+Nl,Sv="__reactEvents$"+Nl,dz="__reactListeners$"+Nl,hz="__reactHandles$"+Nl;function Bi(t){var e=t[So];if(e)return e;for(var n=t.parentNode;n;){if(e=n[hs]||n[So]){if(n=e.alternate,e.child!==null||n!==null&&n.child!==null)for(t=RP(t);t!==null;){if(n=t[So])return n;t=RP(t)}return e}t=n,n=t.parentNode}return null}function Zu(t){return t=t[So]||t[hs],!t||t.tag!==5&&t.tag!==6&&t.tag!==13&&t.tag!==3?null:t}function Wa(t){if(t.tag===5||t.tag===6)return t.stateNode;throw Error(X(33))}function ng(t){return t[bu]||null}var vv=[],Ga=-1;function Si(t){return{current:t}}function rt(t){0>Ga||(t.current=vv[Ga],vv[Ga]=null,Ga--)}function qe(t,e){Ga++,vv[Ga]=t.current,t.current=e}var ai={},fn=Si(ai),Gn=Si(!1),qi=ai;function bl(t,e){var n=t.type.contextTypes;if(!n)return ai;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 Hp(){rt(Gn),rt(fn)}function LP(t,e,n){if(fn.current!==ai)throw Error(X(168));qe(fn,e),qe(Gn,n)}function ok(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,q4(t)||"Unknown",o));return gt({},n,r)}function Kp(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||ai,qi=fn.current,qe(fn,t),qe(Gn,Gn.current),!0}function $P(t,e,n){var r=t.stateNode;if(!r)throw Error(X(169));n?(t=ok(t,e,qi),r.__reactInternalMemoizedMergedChildContext=t,rt(Gn),rt(fn),qe(fn,t)):rt(Gn),qe(Gn,n)}var Zo=null,rg=!1,Ym=!1;function sk(t){Zo===null?Zo=[t]:Zo.push(t)}function pz(t){rg=!0,sk(t)}function vi(){if(!Ym&&Zo!==null){Ym=!0;var t=0,e=Ue;try{var n=Zo;for(Ue=1;t<n.length;t++){var r=n[t];do r=r(!0);while(r!==null)}Zo=null,rg=!1}catch(o){throw Zo!==null&&(Zo=Zo.slice(t+1)),M2(_x,vi),o}finally{Ue=e,Ym=!1}}return null}var Va=[],Ya=0,Wp=null,Gp=0,Er=[],kr=0,Zi=null,Jo=1,es="";function $i(t,e){Va[Ya++]=Gp,Va[Ya++]=Wp,Wp=t,Gp=e}function ik(t,e,n){Er[kr++]=Jo,Er[kr++]=es,Er[kr++]=Zi,Zi=t;var r=Jo;t=es;var o=32-Zr(r)-1;r&=~(1<<o),n+=1;var s=32-Zr(e)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,Jo=1<<32-Zr(e)+o|n<<o|r,es=s+t}else Jo=1<<s|n<<o|r,es=t}function Dx(t){t.return!==null&&($i(t,1),ik(t,1,0))}function Rx(t){for(;t===Wp;)Wp=Va[--Ya],Va[Ya]=null,Gp=Va[--Ya],Va[Ya]=null;for(;t===Zi;)Zi=Er[--kr],Er[kr]=null,es=Er[--kr],Er[kr]=null,Jo=Er[--kr],Er[kr]=null}var cr=null,ar=null,at=!1,Gr=null;function ak(t,e){var n=Mr(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 FP(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,ar=Zs(e.firstChild),!0):!1;case 6:return e=t.pendingProps===""||e.nodeType!==3?null:e,e!==null?(t.stateNode=e,cr=t,ar=null,!0):!1;case 13:return e=e.nodeType!==8?null:e,e!==null?(n=Zi!==null?{id:Jo,overflow:es}:null,t.memoizedState={dehydrated:e,treeContext:n,retryLane:1073741824},n=Mr(18,null,null,0),n.stateNode=e,n.return=t,t.child=n,cr=t,ar=null,!0):!1;default:return!1}}function xv(t){return(t.mode&1)!==0&&(t.flags&128)===0}function wv(t){if(at){var e=ar;if(e){var n=e;if(!FP(t,e)){if(xv(t))throw Error(X(418));e=Zs(n.nextSibling);var r=cr;e&&FP(t,e)?ak(r,n):(t.flags=t.flags&-4097|2,at=!1,cr=t)}}else{if(xv(t))throw Error(X(418));t.flags=t.flags&-4097|2,at=!1,cr=t}}}function NP(t){for(t=t.return;t!==null&&t.tag!==5&&t.tag!==3&&t.tag!==13;)t=t.return;cr=t}function Gd(t){if(t!==cr)return!1;if(!at)return NP(t),at=!0,!1;var e;if((e=t.tag!==3)&&!(e=t.tag!==5)&&(e=t.type,e=e!=="head"&&e!=="body"&&!mv(t.type,t.memoizedProps)),e&&(e=ar)){if(xv(t))throw lk(),Error(X(418));for(;e;)ak(t,e),e=Zs(e.nextSibling)}if(NP(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){ar=Zs(t.nextSibling);break e}e--}else n!=="$"&&n!=="$!"&&n!=="$?"||e++}t=t.nextSibling}ar=null}}else ar=cr?Zs(t.stateNode.nextSibling):null;return!0}function lk(){for(var t=ar;t;)t=Zs(t.nextSibling)}function Pl(){ar=cr=null,at=!1}function Lx(t){Gr===null?Gr=[t]:Gr.push(t)}var fz=vs.ReactCurrentBatchConfig;function pc(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 Vd(t,e){throw t=Object.prototype.toString.call(e),Error(X(31,t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t))}function zP(t){var e=t._init;return e(t._payload)}function ck(t){function e(S,y){if(t){var b=S.deletions;b===null?(S.deletions=[y],S.flags|=16):b.push(y)}}function n(S,y){if(!t)return null;for(;y!==null;)e(S,y),y=y.sibling;return null}function r(S,y){for(S=new Map;y!==null;)y.key!==null?S.set(y.key,y):S.set(y.index,y),y=y.sibling;return S}function o(S,y){return S=ti(S,y),S.index=0,S.sibling=null,S}function s(S,y,b){return S.index=b,t?(b=S.alternate,b!==null?(b=b.index,b<y?(S.flags|=2,y):b):(S.flags|=2,y)):(S.flags|=1048576,y)}function i(S){return t&&S.alternate===null&&(S.flags|=2),S}function a(S,y,b,P){return y===null||y.tag!==6?(y=ty(b,S.mode,P),y.return=S,y):(y=o(y,b),y.return=S,y)}function l(S,y,b,P){var C=b.type;return C===Ba?u(S,y,b.props.children,P,b.key):y!==null&&(y.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Ls&&zP(C)===y.type)?(P=o(y,b.props),P.ref=pc(S,y,b),P.return=S,P):(P=qh(b.type,b.key,b.props,null,S.mode,P),P.ref=pc(S,y,b),P.return=S,P)}function c(S,y,b,P){return y===null||y.tag!==4||y.stateNode.containerInfo!==b.containerInfo||y.stateNode.implementation!==b.implementation?(y=ny(b,S.mode,P),y.return=S,y):(y=o(y,b.children||[]),y.return=S,y)}function u(S,y,b,P,C){return y===null||y.tag!==7?(y=Gi(b,S.mode,P,C),y.return=S,y):(y=o(y,b),y.return=S,y)}function h(S,y,b){if(typeof y=="string"&&y!==""||typeof y=="number")return y=ty(""+y,S.mode,b),y.return=S,y;if(typeof y=="object"&&y!==null){switch(y.$$typeof){case Ld:return b=qh(y.type,y.key,y.props,null,S.mode,b),b.ref=pc(S,null,y),b.return=S,b;case za:return y=ny(y,S.mode,b),y.return=S,y;case Ls:var P=y._init;return h(S,P(y._payload),b)}if(Lc(y)||lc(y))return y=Gi(y,S.mode,b,null),y.return=S,y;Vd(S,y)}return null}function p(S,y,b,P){var C=y!==null?y.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return C!==null?null:a(S,y,""+b,P);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case Ld:return b.key===C?l(S,y,b,P):null;case za:return b.key===C?c(S,y,b,P):null;case Ls:return C=b._init,p(S,y,C(b._payload),P)}if(Lc(b)||lc(b))return C!==null?null:u(S,y,b,P,null);Vd(S,b)}return null}function f(S,y,b,P,C){if(typeof P=="string"&&P!==""||typeof P=="number")return S=S.get(b)||null,a(y,S,""+P,C);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case Ld:return S=S.get(P.key===null?b:P.key)||null,l(y,S,P,C);case za:return S=S.get(P.key===null?b:P.key)||null,c(y,S,P,C);case Ls:var I=P._init;return f(S,y,b,I(P._payload),C)}if(Lc(P)||lc(P))return S=S.get(b)||null,u(y,S,P,C,null);Vd(y,P)}return null}function g(S,y,b,P){for(var C=null,I=null,k=y,_=y=0,T=null;k!==null&&_<b.length;_++){k.index>_?(T=k,k=null):T=k.sibling;var M=p(S,k,b[_],P);if(M===null){k===null&&(k=T);break}t&&k&&M.alternate===null&&e(S,k),y=s(M,y,_),I===null?C=M:I.sibling=M,I=M,k=T}if(_===b.length)return n(S,k),at&&$i(S,_),C;if(k===null){for(;_<b.length;_++)k=h(S,b[_],P),k!==null&&(y=s(k,y,_),I===null?C=k:I.sibling=k,I=k);return at&&$i(S,_),C}for(k=r(S,k);_<b.length;_++)T=f(k,S,_,b[_],P),T!==null&&(t&&T.alternate!==null&&k.delete(T.key===null?_:T.key),y=s(T,y,_),I===null?C=T:I.sibling=T,I=T);return t&&k.forEach(function(D){return e(S,D)}),at&&$i(S,_),C}function m(S,y,b,P){var C=lc(b);if(typeof C!="function")throw Error(X(150));if(b=C.call(b),b==null)throw Error(X(151));for(var I=C=null,k=y,_=y=0,T=null,M=b.next();k!==null&&!M.done;_++,M=b.next()){k.index>_?(T=k,k=null):T=k.sibling;var D=p(S,k,M.value,P);if(D===null){k===null&&(k=T);break}t&&k&&D.alternate===null&&e(S,k),y=s(D,y,_),I===null?C=D:I.sibling=D,I=D,k=T}if(M.done)return n(S,k),at&&$i(S,_),C;if(k===null){for(;!M.done;_++,M=b.next())M=h(S,M.value,P),M!==null&&(y=s(M,y,_),I===null?C=M:I.sibling=M,I=M);return at&&$i(S,_),C}for(k=r(S,k);!M.done;_++,M=b.next())M=f(k,S,_,M.value,P),M!==null&&(t&&M.alternate!==null&&k.delete(M.key===null?_:M.key),y=s(M,y,_),I===null?C=M:I.sibling=M,I=M);return t&&k.forEach(function(j){return e(S,j)}),at&&$i(S,_),C}function v(S,y,b,P){if(typeof b=="object"&&b!==null&&b.type===Ba&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case Ld:e:{for(var C=b.key,I=y;I!==null;){if(I.key===C){if(C=b.type,C===Ba){if(I.tag===7){n(S,I.sibling),y=o(I,b.props.children),y.return=S,S=y;break e}}else if(I.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Ls&&zP(C)===I.type){n(S,I.sibling),y=o(I,b.props),y.ref=pc(S,I,b),y.return=S,S=y;break e}n(S,I);break}else e(S,I);I=I.sibling}b.type===Ba?(y=Gi(b.props.children,S.mode,P,b.key),y.return=S,S=y):(P=qh(b.type,b.key,b.props,null,S.mode,P),P.ref=pc(S,y,b),P.return=S,S=P)}return i(S);case za:e:{for(I=b.key;y!==null;){if(y.key===I)if(y.tag===4&&y.stateNode.containerInfo===b.containerInfo&&y.stateNode.implementation===b.implementation){n(S,y.sibling),y=o(y,b.children||[]),y.return=S,S=y;break e}else{n(S,y);break}else e(S,y);y=y.sibling}y=ny(b,S.mode,P),y.return=S,S=y}return i(S);case Ls:return I=b._init,v(S,y,I(b._payload),P)}if(Lc(b))return g(S,y,b,P);if(lc(b))return m(S,y,b,P);Vd(S,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,y!==null&&y.tag===6?(n(S,y.sibling),y=o(y,b),y.return=S,S=y):(n(S,y),y=ty(b,S.mode,P),y.return=S,S=y),i(S)):n(S,y)}return v}var Cl=ck(!0),uk=ck(!1),Vp=Si(null),Yp=null,Xa=null,$x=null;function Fx(){$x=Xa=Yp=null}function Nx(t){var e=Vp.current;rt(Vp),t._currentValue=e}function bv(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 hl(t,e){Yp=t,$x=Xa=null,t=t.dependencies,t!==null&&t.firstContext!==null&&(t.lanes&e&&(Bn=!0),t.firstContext=null)}function Dr(t){var e=t._currentValue;if($x!==t)if(t={context:t,memoizedValue:e,next:null},Xa===null){if(Yp===null)throw Error(X(308));Xa=t,Yp.dependencies={lanes:0,firstContext:t}}else Xa=Xa.next=t;return e}var Ui=null;function zx(t){Ui===null?Ui=[t]:Ui.push(t)}function dk(t,e,n,r){var o=e.interleaved;return o===null?(n.next=n,zx(e)):(n.next=o.next,o.next=n),e.interleaved=n,ps(t,r)}function ps(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 $s=!1;function Bx(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function hk(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 rs(t,e){return{eventTime:t,lane:e,tag:0,payload:null,callback:null,next:null}}function Qs(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,ps(t,n)}return o=r.interleaved,o===null?(e.next=e,zx(r)):(e.next=o.next,o.next=e),r.interleaved=e,ps(t,n)}function Kh(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,Ix(t,n)}}function BP(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 Xp(t,e,n,r){var o=t.updateQueue;$s=!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:$s=!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);Ji|=i,t.lanes=i,t.memoizedState=h}}function UP(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 Qu={},Io=Si(Qu),Pu=Si(Qu),Cu=Si(Qu);function Hi(t){if(t===Qu)throw Error(X(174));return t}function Ux(t,e){switch(qe(Cu,e),qe(Pu,t),qe(Io,Qu),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:nv(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=nv(e,t)}rt(Io),qe(Io,e)}function _l(){rt(Io),rt(Pu),rt(Cu)}function pk(t){Hi(Cu.current);var e=Hi(Io.current),n=nv(e,t.type);e!==n&&(qe(Pu,t),qe(Io,n))}function Hx(t){Pu.current===t&&(rt(Io),rt(Pu))}var dt=Si(0);function qp(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 Xm=[];function Kx(){for(var t=0;t<Xm.length;t++)Xm[t]._workInProgressVersionPrimary=null;Xm.length=0}var Wh=vs.ReactCurrentDispatcher,qm=vs.ReactCurrentBatchConfig,Qi=0,ft=null,kt=null,jt=null,Zp=!1,eu=!1,_u=0,gz=0;function tn(){throw Error(X(321))}function Wx(t,e){if(e===null)return!1;for(var n=0;n<e.length&&n<t.length;n++)if(!to(t[n],e[n]))return!1;return!0}function Gx(t,e,n,r,o,s){if(Qi=s,ft=e,e.memoizedState=null,e.updateQueue=null,e.lanes=0,Wh.current=t===null||t.memoizedState===null?vz:xz,t=n(r,o),eu){s=0;do{if(eu=!1,_u=0,25<=s)throw Error(X(301));s+=1,jt=kt=null,e.updateQueue=null,Wh.current=wz,t=n(r,o)}while(eu)}if(Wh.current=Qp,e=kt!==null&&kt.next!==null,Qi=0,jt=kt=ft=null,Zp=!1,e)throw Error(X(300));return t}function Vx(){var t=_u!==0;return _u=0,t}function mo(){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 Rr(){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 Iu(t,e){return typeof e=="function"?e(t):e}function Zm(t){var e=Rr(),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((Qi&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,Ji|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,to(r,e.memoizedState)||(Bn=!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,Ji|=s,o=o.next;while(o!==t)}else o===null&&(n.lanes=0);return[e.memoizedState,n.dispatch]}function Qm(t){var e=Rr(),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);to(s,e.memoizedState)||(Bn=!0),e.memoizedState=s,e.baseQueue===null&&(e.baseState=s),n.lastRenderedState=s}return[s,r]}function fk(){}function gk(t,e){var n=ft,r=Rr(),o=e(),s=!to(r.memoizedState,o);if(s&&(r.memoizedState=o,Bn=!0),r=r.queue,Yx(Sk.bind(null,n,r,t),[t]),r.getSnapshot!==e||s||jt!==null&&jt.memoizedState.tag&1){if(n.flags|=2048,Eu(9,yk.bind(null,n,r,o,e),void 0,null),Rt===null)throw Error(X(349));Qi&30||mk(n,e,o)}return o}function mk(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 yk(t,e,n,r){e.value=n,e.getSnapshot=r,vk(e)&&xk(t)}function Sk(t,e,n){return n(function(){vk(e)&&xk(t)})}function vk(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!to(t,n)}catch{return!0}}function xk(t){var e=ps(t,1);e!==null&&Qr(e,t,1,-1)}function HP(t){var e=mo();return typeof t=="function"&&(t=t()),e.memoizedState=e.baseState=t,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Iu,lastRenderedState:t},e.queue=t,t=t.dispatch=Sz.bind(null,ft,t),[e.memoizedState,t]}function Eu(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 wk(){return Rr().memoizedState}function Gh(t,e,n,r){var o=mo();ft.flags|=t,o.memoizedState=Eu(1|e,n,void 0,r===void 0?null:r)}function og(t,e,n,r){var o=Rr();r=r===void 0?null:r;var s=void 0;if(kt!==null){var i=kt.memoizedState;if(s=i.destroy,r!==null&&Wx(r,i.deps)){o.memoizedState=Eu(e,n,s,r);return}}ft.flags|=t,o.memoizedState=Eu(1|e,n,s,r)}function KP(t,e){return Gh(8390656,8,t,e)}function Yx(t,e){return og(2048,8,t,e)}function bk(t,e){return og(4,2,t,e)}function Pk(t,e){return og(4,4,t,e)}function Ck(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 _k(t,e,n){return n=n!=null?n.concat([t]):null,og(4,4,Ck.bind(null,e,t),n)}function Xx(){}function Ik(t,e){var n=Rr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&Wx(e,r[1])?r[0]:(n.memoizedState=[t,e],t)}function Ek(t,e){var n=Rr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&Wx(e,r[1])?r[0]:(t=t(),n.memoizedState=[t,e],t)}function kk(t,e,n){return Qi&21?(to(n,e)||(n=O2(),ft.lanes|=n,Ji|=n,t.baseState=!0),e):(t.baseState&&(t.baseState=!1,Bn=!0),t.memoizedState=n)}function mz(t,e){var n=Ue;Ue=n!==0&&4>n?n:4,t(!0);var r=qm.transition;qm.transition={};try{t(!1),e()}finally{Ue=n,qm.transition=r}}function Tk(){return Rr().memoizedState}function yz(t,e,n){var r=ei(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Mk(t))Ak(e,n);else if(n=dk(t,e,n,r),n!==null){var o=bn();Qr(n,t,r,o),jk(n,e,r)}}function Sz(t,e,n){var r=ei(t),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Mk(t))Ak(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,to(a,i)){var l=e.interleaved;l===null?(o.next=o,zx(e)):(o.next=l.next,l.next=o),e.interleaved=o;return}}catch{}finally{}n=dk(t,e,o,r),n!==null&&(o=bn(),Qr(n,t,r,o),jk(n,e,r))}}function Mk(t){var e=t.alternate;return t===ft||e!==null&&e===ft}function Ak(t,e){eu=Zp=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function jk(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,Ix(t,n)}}var Qp={readContext:Dr,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},vz={readContext:Dr,useCallback:function(t,e){return mo().memoizedState=[t,e===void 0?null:e],t},useContext:Dr,useEffect:KP,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,Gh(4194308,4,Ck.bind(null,e,t),n)},useLayoutEffect:function(t,e){return Gh(4194308,4,t,e)},useInsertionEffect:function(t,e){return Gh(4,2,t,e)},useMemo:function(t,e){var n=mo();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=mo();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=yz.bind(null,ft,t),[r.memoizedState,t]},useRef:function(t){var e=mo();return t={current:t},e.memoizedState=t},useState:HP,useDebugValue:Xx,useDeferredValue:function(t){return mo().memoizedState=t},useTransition:function(){var t=HP(!1),e=t[0];return t=mz.bind(null,t[1]),mo().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=ft,o=mo();if(at){if(n===void 0)throw Error(X(407));n=n()}else{if(n=e(),Rt===null)throw Error(X(349));Qi&30||mk(r,e,n)}o.memoizedState=n;var s={value:n,getSnapshot:e};return o.queue=s,KP(Sk.bind(null,r,s,t),[t]),r.flags|=2048,Eu(9,yk.bind(null,r,s,n,e),void 0,null),n},useId:function(){var t=mo(),e=Rt.identifierPrefix;if(at){var n=es,r=Jo;n=(r&~(1<<32-Zr(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=_u++,0<n&&(e+="H"+n.toString(32)),e+=":"}else n=gz++,e=":"+e+"r"+n.toString(32)+":";return t.memoizedState=e},unstable_isNewReconciler:!1},xz={readContext:Dr,useCallback:Ik,useContext:Dr,useEffect:Yx,useImperativeHandle:_k,useInsertionEffect:bk,useLayoutEffect:Pk,useMemo:Ek,useReducer:Zm,useRef:wk,useState:function(){return Zm(Iu)},useDebugValue:Xx,useDeferredValue:function(t){var e=Rr();return kk(e,kt.memoizedState,t)},useTransition:function(){var t=Zm(Iu)[0],e=Rr().memoizedState;return[t,e]},useMutableSource:fk,useSyncExternalStore:gk,useId:Tk,unstable_isNewReconciler:!1},wz={readContext:Dr,useCallback:Ik,useContext:Dr,useEffect:Yx,useImperativeHandle:_k,useInsertionEffect:bk,useLayoutEffect:Pk,useMemo:Ek,useReducer:Qm,useRef:wk,useState:function(){return Qm(Iu)},useDebugValue:Xx,useDeferredValue:function(t){var e=Rr();return kt===null?e.memoizedState=t:kk(e,kt.memoizedState,t)},useTransition:function(){var t=Qm(Iu)[0],e=Rr().memoizedState;return[t,e]},useMutableSource:fk,useSyncExternalStore:gk,useId:Tk,unstable_isNewReconciler:!1};function Ur(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 Pv(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 sg={isMounted:function(t){return(t=t._reactInternals)?ga(t)===t:!1},enqueueSetState:function(t,e,n){t=t._reactInternals;var r=bn(),o=ei(t),s=rs(r,o);s.payload=e,n!=null&&(s.callback=n),e=Qs(t,s,o),e!==null&&(Qr(e,t,o,r),Kh(e,t,o))},enqueueReplaceState:function(t,e,n){t=t._reactInternals;var r=bn(),o=ei(t),s=rs(r,o);s.tag=1,s.payload=e,n!=null&&(s.callback=n),e=Qs(t,s,o),e!==null&&(Qr(e,t,o,r),Kh(e,t,o))},enqueueForceUpdate:function(t,e){t=t._reactInternals;var n=bn(),r=ei(t),o=rs(n,r);o.tag=2,e!=null&&(o.callback=e),e=Qs(t,o,r),e!==null&&(Qr(e,t,r,n),Kh(e,t,r))}};function WP(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?!vu(n,r)||!vu(o,s):!0}function Ok(t,e,n){var r=!1,o=ai,s=e.contextType;return typeof s=="object"&&s!==null?s=Dr(s):(o=Vn(e)?qi:fn.current,r=e.contextTypes,s=(r=r!=null)?bl(t,o):ai),e=new e(n,s),t.memoizedState=e.state!==null&&e.state!==void 0?e.state:null,e.updater=sg,t.stateNode=e,e._reactInternals=t,r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=o,t.__reactInternalMemoizedMaskedChildContext=s),e}function GP(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&&sg.enqueueReplaceState(e,e.state,null)}function Cv(t,e,n,r){var o=t.stateNode;o.props=n,o.state=t.memoizedState,o.refs={},Bx(t);var s=e.contextType;typeof s=="object"&&s!==null?o.context=Dr(s):(s=Vn(e)?qi:fn.current,o.context=bl(t,s)),o.state=t.memoizedState,s=e.getDerivedStateFromProps,typeof s=="function"&&(Pv(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&&sg.enqueueReplaceState(o,o.state,null),Xp(t,n,o,r),o.state=t.memoizedState),typeof o.componentDidMount=="function"&&(t.flags|=4194308)}function Il(t,e){try{var n="",r=e;do n+=X4(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 Jm(t,e,n){return{value:t,source:null,stack:n??null,digest:e??null}}function _v(t,e){try{console.error(e.value)}catch(n){setTimeout(function(){throw n})}}var bz=typeof WeakMap=="function"?WeakMap:Map;function Dk(t,e,n){n=rs(-1,n),n.tag=3,n.payload={element:null};var r=e.value;return n.callback=function(){ef||(ef=!0,Rv=r),_v(t,e)},n}function Rk(t,e,n){n=rs(-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(){_v(t,e)}}var s=t.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(n.callback=function(){_v(t,e),typeof r!="function"&&(Js===null?Js=new Set([this]):Js.add(this));var i=e.stack;this.componentDidCatch(e.value,{componentStack:i!==null?i:""})}),n}function VP(t,e,n){var r=t.pingCache;if(r===null){r=t.pingCache=new bz;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=Lz.bind(null,t,e,n),e.then(t,t))}function YP(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 XP(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=rs(-1,1),e.tag=2,Qs(n,e,1))),n.lanes|=1),t)}var Pz=vs.ReactCurrentOwner,Bn=!1;function vn(t,e,n,r){e.child=t===null?uk(e,null,n,r):Cl(e,t.child,n,r)}function qP(t,e,n,r,o){n=n.render;var s=e.ref;return hl(e,o),r=Gx(t,e,n,r,s,o),n=Vx(),t!==null&&!Bn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,fs(t,e,o)):(at&&n&&Dx(e),e.flags|=1,vn(t,e,r,o),e.child)}function ZP(t,e,n,r,o){if(t===null){var s=n.type;return typeof s=="function"&&!rw(s)&&s.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(e.tag=15,e.type=s,Lk(t,e,s,r,o)):(t=qh(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:vu,n(i,r)&&t.ref===e.ref)return fs(t,e,o)}return e.flags|=1,t=ti(s,r),t.ref=e.ref,t.return=e,e.child=t}function Lk(t,e,n,r,o){if(t!==null){var s=t.memoizedProps;if(vu(s,r)&&t.ref===e.ref)if(Bn=!1,e.pendingProps=r=s,(t.lanes&o)!==0)t.flags&131072&&(Bn=!0);else return e.lanes=t.lanes,fs(t,e,o)}return Iv(t,e,n,r,o)}function $k(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},qe(Za,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,qe(Za,or),or|=t,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:n,qe(Za,or),or|=r}else s!==null?(r=s.baseLanes|n,e.memoizedState=null):r=n,qe(Za,or),or|=r;return vn(t,e,o,n),e.child}function Fk(t,e){var n=e.ref;(t===null&&n!==null||t!==null&&t.ref!==n)&&(e.flags|=512,e.flags|=2097152)}function Iv(t,e,n,r,o){var s=Vn(n)?qi:fn.current;return s=bl(e,s),hl(e,o),n=Gx(t,e,n,r,s,o),r=Vx(),t!==null&&!Bn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,fs(t,e,o)):(at&&r&&Dx(e),e.flags|=1,vn(t,e,n,o),e.child)}function QP(t,e,n,r,o){if(Vn(n)){var s=!0;Kp(e)}else s=!1;if(hl(e,o),e.stateNode===null)Vh(t,e),Ok(e,n,r),Cv(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=Dr(c):(c=Vn(n)?qi:fn.current,c=bl(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)&&GP(e,i,r,c),$s=!1;var p=e.memoizedState;i.state=p,Xp(e,r,i,o),l=e.memoizedState,a!==r||p!==l||Gn.current||$s?(typeof u=="function"&&(Pv(e,n,u,r),l=e.memoizedState),(a=$s||WP(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,hk(t,e),a=e.memoizedProps,c=e.type===e.elementType?a:Ur(e.type,a),i.props=c,h=e.pendingProps,p=i.context,l=n.contextType,typeof l=="object"&&l!==null?l=Dr(l):(l=Vn(n)?qi:fn.current,l=bl(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)&&GP(e,i,r,l),$s=!1,p=e.memoizedState,i.state=p,Xp(e,r,i,o);var g=e.memoizedState;a!==h||p!==g||Gn.current||$s?(typeof f=="function"&&(Pv(e,n,f,r),g=e.memoizedState),(c=$s||WP(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 Ev(t,e,n,r,s,o)}function Ev(t,e,n,r,o,s){Fk(t,e);var i=(e.flags&128)!==0;if(!r&&!i)return o&&$P(e,n,!1),fs(t,e,s);r=e.stateNode,Pz.current=e;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,t!==null&&i?(e.child=Cl(e,t.child,null,s),e.child=Cl(e,null,a,s)):vn(t,e,a,s),e.memoizedState=r.state,o&&$P(e,n,!0),e.child}function Nk(t){var e=t.stateNode;e.pendingContext?LP(t,e.pendingContext,e.pendingContext!==e.context):e.context&&LP(t,e.context,!1),Ux(t,e.containerInfo)}function JP(t,e,n,r,o){return Pl(),Lx(o),e.flags|=256,vn(t,e,n,r),e.child}var kv={dehydrated:null,treeContext:null,retryLane:0};function Tv(t){return{baseLanes:t,cachePool:null,transitions:null}}function zk(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),qe(dt,o&1),t===null)return wv(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=lg(i,r,0,null),t=Gi(t,r,n,null),s.return=e,t.return=e,s.sibling=t,e.child=s,e.child.memoizedState=Tv(n),e.memoizedState=kv,t):qx(e,i));if(o=t.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return Cz(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=ti(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=ti(a,s):(s=Gi(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?Tv(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=t.childLanes&~n,e.memoizedState=kv,r}return s=t.child,t=s.sibling,r=ti(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 qx(t,e){return e=lg({mode:"visible",children:e},t.mode,0,null),e.return=t,t.child=e}function Yd(t,e,n,r){return r!==null&&Lx(r),Cl(e,t.child,null,n),t=qx(e,e.pendingProps.children),t.flags|=2,e.memoizedState=null,t}function Cz(t,e,n,r,o,s,i){if(n)return e.flags&256?(e.flags&=-257,r=Jm(Error(X(422))),Yd(t,e,i,r)):e.memoizedState!==null?(e.child=t.child,e.flags|=128,null):(s=r.fallback,o=e.mode,r=lg({mode:"visible",children:r.children},o,0,null),s=Gi(s,o,i,null),s.flags|=2,r.return=e,s.return=e,r.sibling=s,e.child=r,e.mode&1&&Cl(e,t.child,null,i),e.child.memoizedState=Tv(i),e.memoizedState=kv,s);if(!(e.mode&1))return Yd(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=Jm(s,r,void 0),Yd(t,e,i,r)}if(a=(i&t.childLanes)!==0,Bn||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,ps(t,o),Qr(r,t,o,-1))}return nw(),r=Jm(Error(X(421))),Yd(t,e,i,r)}return o.data==="$?"?(e.flags|=128,e.child=t.child,e=$z.bind(null,t),o._reactRetry=e,null):(t=s.treeContext,ar=Zs(o.nextSibling),cr=e,at=!0,Gr=null,t!==null&&(Er[kr++]=Jo,Er[kr++]=es,Er[kr++]=Zi,Jo=t.id,es=t.overflow,Zi=e),e=qx(e,r.children),e.flags|=4096,e)}function eC(t,e,n){t.lanes|=e;var r=t.alternate;r!==null&&(r.lanes|=e),bv(t.return,e,n)}function ey(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 Bk(t,e,n){var r=e.pendingProps,o=r.revealOrder,s=r.tail;if(vn(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&&eC(t,n,e);else if(t.tag===19)eC(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(qe(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&&qp(t)===null&&(o=n),n=n.sibling;n=o,n===null?(o=e.child,e.child=null):(o=n.sibling,n.sibling=null),ey(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&&qp(t)===null){e.child=o;break}t=o.sibling,o.sibling=n,n=o,o=t}ey(e,!0,n,null,s);break;case"together":ey(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function Vh(t,e){!(e.mode&1)&&t!==null&&(t.alternate=null,e.alternate=null,e.flags|=2)}function fs(t,e,n){if(t!==null&&(e.dependencies=t.dependencies),Ji|=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=ti(t,t.pendingProps),e.child=n,n.return=e;t.sibling!==null;)t=t.sibling,n=n.sibling=ti(t,t.pendingProps),n.return=e;n.sibling=null}return e.child}function _z(t,e,n){switch(e.tag){case 3:Nk(e),Pl();break;case 5:pk(e);break;case 1:Vn(e.type)&&Kp(e);break;case 4:Ux(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,o=e.memoizedProps.value;qe(Vp,r._currentValue),r._currentValue=o;break;case 13:if(r=e.memoizedState,r!==null)return r.dehydrated!==null?(qe(dt,dt.current&1),e.flags|=128,null):n&e.child.childLanes?zk(t,e,n):(qe(dt,dt.current&1),t=fs(t,e,n),t!==null?t.sibling:null);qe(dt,dt.current&1);break;case 19:if(r=(n&e.childLanes)!==0,t.flags&128){if(r)return Bk(t,e,n);e.flags|=128}if(o=e.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),qe(dt,dt.current),r)break;return null;case 22:case 23:return e.lanes=0,$k(t,e,n)}return fs(t,e,n)}var Uk,Mv,Hk,Kk;Uk=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}};Mv=function(){};Hk=function(t,e,n,r){var o=t.memoizedProps;if(o!==r){t=e.stateNode,Hi(Io.current);var s=null;switch(n){case"input":o=QS(t,o),r=QS(t,r),s=[];break;case"select":o=gt({},o,{value:void 0}),r=gt({},r,{value:void 0}),s=[];break;case"textarea":o=tv(t,o),r=tv(t,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(t.onclick=Up)}rv(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"&&(hu.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"&&(hu.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&tt("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)}};Kk=function(t,e,n,r){n!==r&&(e.flags|=4)};function fc(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 Iz(t,e,n){var r=e.pendingProps;switch(Rx(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)&&Hp(),nn(e),null;case 3:return r=e.stateNode,_l(),rt(Gn),rt(fn),Kx(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(t===null||t.child===null)&&(Gd(e)?e.flags|=4:t===null||t.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,Gr!==null&&(Fv(Gr),Gr=null))),Mv(t,e),nn(e),null;case 5:Hx(e);var o=Hi(Cu.current);if(n=e.type,t!==null&&e.stateNode!=null)Hk(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=Hi(Io.current),Gd(e)){r=e.stateNode,n=e.type;var s=e.memoizedProps;switch(r[So]=e,r[bu]=s,t=(e.mode&1)!==0,n){case"dialog":tt("cancel",r),tt("close",r);break;case"iframe":case"object":case"embed":tt("load",r);break;case"video":case"audio":for(o=0;o<Fc.length;o++)tt(Fc[o],r);break;case"source":tt("error",r);break;case"img":case"image":case"link":tt("error",r),tt("load",r);break;case"details":tt("toggle",r);break;case"input":cP(r,s),tt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},tt("invalid",r);break;case"textarea":dP(r,s),tt("invalid",r)}rv(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&&Wd(r.textContent,a,t),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Wd(r.textContent,a,t),o=["children",""+a]):hu.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&tt("scroll",r)}switch(n){case"input":$d(r),uP(r,s,!0);break;case"textarea":$d(r),hP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Up)}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=S2(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[So]=e,t[bu]=r,Uk(t,e,!1,!1),e.stateNode=t;e:{switch(i=ov(n,r),n){case"dialog":tt("cancel",t),tt("close",t),o=r;break;case"iframe":case"object":case"embed":tt("load",t),o=r;break;case"video":case"audio":for(o=0;o<Fc.length;o++)tt(Fc[o],t);o=r;break;case"source":tt("error",t),o=r;break;case"img":case"image":case"link":tt("error",t),tt("load",t),o=r;break;case"details":tt("toggle",t),o=r;break;case"input":cP(t,r),o=QS(t,r),tt("invalid",t);break;case"option":o=r;break;case"select":t._wrapperState={wasMultiple:!!r.multiple},o=gt({},r,{value:void 0}),tt("invalid",t);break;case"textarea":dP(t,r),o=tv(t,r),tt("invalid",t);break;default:o=r}rv(n,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?w2(t,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&v2(t,l)):s==="children"?typeof l=="string"?(n!=="textarea"||l!=="")&&pu(t,l):typeof l=="number"&&pu(t,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(hu.hasOwnProperty(s)?l!=null&&s==="onScroll"&&tt("scroll",t):l!=null&&xx(t,s,l,i))}switch(n){case"input":$d(t),uP(t,r,!1);break;case"textarea":$d(t),hP(t);break;case"option":r.value!=null&&t.setAttribute("value",""+ii(r.value));break;case"select":t.multiple=!!r.multiple,s=r.value,s!=null?ll(t,!!r.multiple,s,!1):r.defaultValue!=null&&ll(t,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(t.onclick=Up)}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)Kk(t,e,t.memoizedProps,r);else{if(typeof r!="string"&&e.stateNode===null)throw Error(X(166));if(n=Hi(Cu.current),Hi(Io.current),Gd(e)){if(r=e.stateNode,n=e.memoizedProps,r[So]=e,(s=r.nodeValue!==n)&&(t=cr,t!==null))switch(t.tag){case 3:Wd(r.nodeValue,n,(t.mode&1)!==0);break;case 5:t.memoizedProps.suppressHydrationWarning!==!0&&Wd(r.nodeValue,n,(t.mode&1)!==0)}s&&(e.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[So]=e,e.stateNode=r}return nn(e),null;case 13:if(rt(dt),r=e.memoizedState,t===null||t.memoizedState!==null&&t.memoizedState.dehydrated!==null){if(at&&ar!==null&&e.mode&1&&!(e.flags&128))lk(),Pl(),e.flags|=98560,s=!1;else if(s=Gd(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[So]=e}else Pl(),!(e.flags&128)&&(e.memoizedState=null),e.flags|=4;nn(e),s=!1}else Gr!==null&&(Fv(Gr),Gr=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):nw())),e.updateQueue!==null&&(e.flags|=4),nn(e),null);case 4:return _l(),Mv(t,e),t===null&&xu(e.stateNode.containerInfo),nn(e),null;case 10:return Nx(e.type._context),nn(e),null;case 17:return Vn(e.type)&&Hp(),nn(e),null;case 19:if(rt(dt),s=e.memoizedState,s===null)return nn(e),null;if(r=(e.flags&128)!==0,i=s.rendering,i===null)if(r)fc(s,!1);else{if(Tt!==0||t!==null&&t.flags&128)for(t=e.child;t!==null;){if(i=qp(t),i!==null){for(e.flags|=128,fc(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 qe(dt,dt.current&1|2),e.child}t=t.sibling}s.tail!==null&&wt()>El&&(e.flags|=128,r=!0,fc(s,!1),e.lanes=4194304)}else{if(!r)if(t=qp(i),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),fc(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!at)return nn(e),null}else 2*wt()-s.renderingStartTime>El&&n!==1073741824&&(e.flags|=128,r=!0,fc(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,qe(dt,r?n&1|2:n&1),e):(nn(e),null);case 22:case 23:return tw(),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 Ez(t,e){switch(Rx(e),e.tag){case 1:return Vn(e.type)&&Hp(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return _l(),rt(Gn),rt(fn),Kx(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Hx(e),null;case 13:if(rt(dt),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(X(340));Pl()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return rt(dt),null;case 4:return _l(),null;case 10:return Nx(e.type._context),null;case 22:case 23:return tw(),null;case 24:return null;default:return null}}var Xd=!1,ln=!1,kz=typeof WeakSet=="function"?WeakSet:Set,re=null;function qa(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 Av(t,e,n){try{n()}catch(r){yt(t,e,r)}}var tC=!1;function Tz(t,e){if(fv=Np,t=X2(),Ox(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(gv={focusedElem:t,selectionRange:n},Np=!1,re=e;re!==null;)if(e=re,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,re=t;else for(;re!==null;){e=re;try{var g=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var m=g.memoizedProps,v=g.memoizedState,S=e.stateNode,y=S.getSnapshotBeforeUpdate(e.elementType===e.type?m:Ur(e.type,m),v);S.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var b=e.stateNode.containerInfo;b.nodeType===1?b.textContent="":b.nodeType===9&&b.documentElement&&b.removeChild(b.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(X(163))}}catch(P){yt(e,e.return,P)}if(t=e.sibling,t!==null){t.return=e.return,re=t;break}re=e.return}return g=tC,tC=!1,g}function tu(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&&Av(e,n,s)}o=o.next}while(o!==r)}}function ig(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 jv(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 Wk(t){var e=t.alternate;e!==null&&(t.alternate=null,Wk(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[So],delete e[bu],delete e[Sv],delete e[dz],delete e[hz])),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 Gk(t){return t.tag===5||t.tag===3||t.tag===4}function nC(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||Gk(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 Ov(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=Up));else if(r!==4&&(t=t.child,t!==null))for(Ov(t,e,n),t=t.sibling;t!==null;)Ov(t,e,n),t=t.sibling}function Dv(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(Dv(t,e,n),t=t.sibling;t!==null;)Dv(t,e,n),t=t.sibling}var zt=null,Hr=!1;function Ms(t,e,n){for(n=n.child;n!==null;)Vk(t,e,n),n=n.sibling}function Vk(t,e,n){if(_o&&typeof _o.onCommitFiberUnmount=="function")try{_o.onCommitFiberUnmount(Qf,n)}catch{}switch(n.tag){case 5:ln||qa(n,e);case 6:var r=zt,o=Hr;zt=null,Ms(t,e,n),zt=r,Hr=o,zt!==null&&(Hr?(t=zt,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):zt.removeChild(n.stateNode));break;case 18:zt!==null&&(Hr?(t=zt,n=n.stateNode,t.nodeType===8?Vm(t.parentNode,n):t.nodeType===1&&Vm(t,n),yu(t)):Vm(zt,n.stateNode));break;case 4:r=zt,o=Hr,zt=n.stateNode.containerInfo,Hr=!0,Ms(t,e,n),zt=r,Hr=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)&&Av(n,e,i),o=o.next}while(o!==r)}Ms(t,e,n);break;case 1:if(!ln&&(qa(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)}Ms(t,e,n);break;case 21:Ms(t,e,n);break;case 22:n.mode&1?(ln=(r=ln)||n.memoizedState!==null,Ms(t,e,n),ln=r):Ms(t,e,n);break;default:Ms(t,e,n)}}function rC(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new kz),e.forEach(function(r){var o=Fz.bind(null,t,r);n.has(r)||(n.add(r),r.then(o,o))})}}function Br(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:zt=a.stateNode,Hr=!1;break e;case 3:zt=a.stateNode.containerInfo,Hr=!0;break e;case 4:zt=a.stateNode.containerInfo,Hr=!0;break e}a=a.return}if(zt===null)throw Error(X(160));Vk(s,i,o),zt=null,Hr=!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;)Yk(e,t),e=e.sibling}function Yk(t,e){var n=t.alternate,r=t.flags;switch(t.tag){case 0:case 11:case 14:case 15:if(Br(e,t),po(t),r&4){try{tu(3,t,t.return),ig(3,t)}catch(m){yt(t,t.return,m)}try{tu(5,t,t.return)}catch(m){yt(t,t.return,m)}}break;case 1:Br(e,t),po(t),r&512&&n!==null&&qa(n,n.return);break;case 5:if(Br(e,t),po(t),r&512&&n!==null&&qa(n,n.return),t.flags&32){var o=t.stateNode;try{pu(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&&m2(o,s),ov(a,i);var c=ov(a,s);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?w2(o,h):u==="dangerouslySetInnerHTML"?v2(o,h):u==="children"?pu(o,h):xx(o,u,h,c)}switch(a){case"input":JS(o,s);break;case"textarea":y2(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?ll(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?ll(o,!!s.multiple,s.defaultValue,!0):ll(o,!!s.multiple,s.multiple?[]:"",!1))}o[bu]=s}catch(m){yt(t,t.return,m)}}break;case 6:if(Br(e,t),po(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(Br(e,t),po(t),r&4&&n!==null&&n.memoizedState.isDehydrated)try{yu(e.containerInfo)}catch(m){yt(t,t.return,m)}break;case 4:Br(e,t),po(t);break;case 13:Br(e,t),po(t),o=t.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(Jx=wt())),r&4&&rC(t);break;case 22:if(u=n!==null&&n.memoizedState!==null,t.mode&1?(ln=(c=ln)||u,Br(e,t),ln=c):Br(e,t),po(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:tu(4,p,p.return);break;case 1:qa(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:qa(p,p.return);break;case 22:if(p.memoizedState!==null){sC(h);continue}}f!==null?(f.return=p,re=f):sC(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=x2("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:Br(e,t),po(t),r&4&&rC(t);break;case 21:break;default:Br(e,t),po(t)}}function po(t){var e=t.flags;if(e&2){try{e:{for(var n=t.return;n!==null;){if(Gk(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&&(pu(o,""),r.flags&=-33);var s=nC(t);Dv(t,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=nC(t);Ov(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 Mz(t,e,n){re=t,Xk(t)}function Xk(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||Xd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||ln;a=Xd;var c=ln;if(Xd=i,(ln=l)&&!c)for(re=o;re!==null;)i=re,l=i.child,i.tag===22&&i.memoizedState!==null?iC(o):l!==null?(l.return=i,re=l):iC(o);for(;s!==null;)re=s,Xk(s),s=s.sibling;re=o,Xd=a,ln=c}oC(t)}else o.subtreeFlags&8772&&s!==null?(s.return=o,re=s):oC(t)}}function oC(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||ig(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:Ur(e.type,n.memoizedProps);r.componentDidUpdate(o,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=e.updateQueue;s!==null&&UP(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}UP(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&&yu(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(X(163))}ln||e.flags&512&&jv(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 sC(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 iC(t){for(;re!==null;){var e=re;try{switch(e.tag){case 0:case 11:case 15:var n=e.return;try{ig(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{jv(e)}catch(l){yt(e,s,l)}break;case 5:var i=e.return;try{jv(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 Az=Math.ceil,Jp=vs.ReactCurrentDispatcher,Zx=vs.ReactCurrentOwner,jr=vs.ReactCurrentBatchConfig,Oe=0,Rt=null,_t=null,Yt=0,or=0,Za=Si(0),Tt=0,ku=null,Ji=0,ag=0,Qx=0,nu=null,Fn=null,Jx=0,El=1/0,Xo=null,ef=!1,Rv=null,Js=null,qd=!1,Ks=null,tf=0,ru=0,Lv=null,Yh=-1,Xh=0;function bn(){return Oe&6?wt():Yh!==-1?Yh:Yh=wt()}function ei(t){return t.mode&1?Oe&2&&Yt!==0?Yt&-Yt:fz.transition!==null?(Xh===0&&(Xh=O2()),Xh):(t=Ue,t!==0||(t=window.event,t=t===void 0?16:z2(t.type)),t):1}function Qr(t,e,n,r){if(50<ru)throw ru=0,Lv=null,Error(X(185));Xu(t,n,r),(!(Oe&2)||t!==Rt)&&(t===Rt&&(!(Oe&2)&&(ag|=n),Tt===4&&Ns(t,Yt)),Yn(t,r),n===1&&Oe===0&&!(e.mode&1)&&(El=wt()+500,rg&&vi()))}function Yn(t,e){var n=t.callbackNode;f6(t,e);var r=Fp(t,t===Rt?Yt:0);if(r===0)n!==null&&gP(n),t.callbackNode=null,t.callbackPriority=0;else if(e=r&-r,t.callbackPriority!==e){if(n!=null&&gP(n),e===1)t.tag===0?pz(aC.bind(null,t)):sk(aC.bind(null,t)),cz(function(){!(Oe&6)&&vi()}),n=null;else{switch(D2(r)){case 1:n=_x;break;case 4:n=A2;break;case 16:n=$p;break;case 536870912:n=j2;break;default:n=$p}n=rT(n,qk.bind(null,t))}t.callbackPriority=e,t.callbackNode=n}}function qk(t,e){if(Yh=-1,Xh=0,Oe&6)throw Error(X(327));var n=t.callbackNode;if(pl()&&t.callbackNode!==n)return null;var r=Fp(t,t===Rt?Yt:0);if(r===0)return null;if(r&30||r&t.expiredLanes||e)e=nf(t,r);else{e=r;var o=Oe;Oe|=2;var s=Qk();(Rt!==t||Yt!==e)&&(Xo=null,El=wt()+500,Wi(t,e));do try{Dz();break}catch(a){Zk(t,a)}while(!0);Fx(),Jp.current=s,Oe=o,_t!==null?e=0:(Rt=null,Yt=0,e=Tt)}if(e!==0){if(e===2&&(o=cv(t),o!==0&&(r=o,e=$v(t,o))),e===1)throw n=ku,Wi(t,0),Ns(t,r),Yn(t,wt()),n;if(e===6)Ns(t,r);else{if(o=t.current.alternate,!(r&30)&&!jz(o)&&(e=nf(t,r),e===2&&(s=cv(t),s!==0&&(r=s,e=$v(t,s))),e===1))throw n=ku,Wi(t,0),Ns(t,r),Yn(t,wt()),n;switch(t.finishedWork=o,t.finishedLanes=r,e){case 0:case 1:throw Error(X(345));case 2:Fi(t,Fn,Xo);break;case 3:if(Ns(t,r),(r&130023424)===r&&(e=Jx+500-wt(),10<e)){if(Fp(t,0)!==0)break;if(o=t.suspendedLanes,(o&r)!==r){bn(),t.pingedLanes|=t.suspendedLanes&o;break}t.timeoutHandle=yv(Fi.bind(null,t,Fn,Xo),e);break}Fi(t,Fn,Xo);break;case 4:if(Ns(t,r),(r&4194240)===r)break;for(e=t.eventTimes,o=-1;0<r;){var i=31-Zr(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*Az(r/1960))-r,10<r){t.timeoutHandle=yv(Fi.bind(null,t,Fn,Xo),r);break}Fi(t,Fn,Xo);break;case 5:Fi(t,Fn,Xo);break;default:throw Error(X(329))}}}return Yn(t,wt()),t.callbackNode===n?qk.bind(null,t):null}function $v(t,e){var n=nu;return t.current.memoizedState.isDehydrated&&(Wi(t,e).flags|=256),t=nf(t,e),t!==2&&(e=Fn,Fn=n,e!==null&&Fv(e)),t}function Fv(t){Fn===null?Fn=t:Fn.push.apply(Fn,t)}function jz(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(!to(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 Ns(t,e){for(e&=~Qx,e&=~ag,t.suspendedLanes|=e,t.pingedLanes&=~e,t=t.expirationTimes;0<e;){var n=31-Zr(e),r=1<<n;t[n]=-1,e&=~r}}function aC(t){if(Oe&6)throw Error(X(327));pl();var e=Fp(t,0);if(!(e&1))return Yn(t,wt()),null;var n=nf(t,e);if(t.tag!==0&&n===2){var r=cv(t);r!==0&&(e=r,n=$v(t,r))}if(n===1)throw n=ku,Wi(t,0),Ns(t,e),Yn(t,wt()),n;if(n===6)throw Error(X(345));return t.finishedWork=t.current.alternate,t.finishedLanes=e,Fi(t,Fn,Xo),Yn(t,wt()),null}function ew(t,e){var n=Oe;Oe|=1;try{return t(e)}finally{Oe=n,Oe===0&&(El=wt()+500,rg&&vi())}}function ea(t){Ks!==null&&Ks.tag===0&&!(Oe&6)&&pl();var e=Oe;Oe|=1;var n=jr.transition,r=Ue;try{if(jr.transition=null,Ue=1,t)return t()}finally{Ue=r,jr.transition=n,Oe=e,!(Oe&6)&&vi()}}function tw(){or=Za.current,rt(Za)}function Wi(t,e){t.finishedWork=null,t.finishedLanes=0;var n=t.timeoutHandle;if(n!==-1&&(t.timeoutHandle=-1,lz(n)),_t!==null)for(n=_t.return;n!==null;){var r=n;switch(Rx(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Hp();break;case 3:_l(),rt(Gn),rt(fn),Kx();break;case 5:Hx(r);break;case 4:_l();break;case 13:rt(dt);break;case 19:rt(dt);break;case 10:Nx(r.type._context);break;case 22:case 23:tw()}n=n.return}if(Rt=t,_t=t=ti(t.current,null),Yt=or=e,Tt=0,ku=null,Qx=ag=Ji=0,Fn=nu=null,Ui!==null){for(e=0;e<Ui.length;e++)if(n=Ui[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}Ui=null}return t}function Zk(t,e){do{var n=_t;try{if(Fx(),Wh.current=Qp,Zp){for(var r=ft.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Zp=!1}if(Qi=0,jt=kt=ft=null,eu=!1,_u=0,Zx.current=null,n===null||n.return===null){Tt=1,ku=e,_t=null;break}e:{var s=t,i=n.return,a=n,l=e;if(e=Yt,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=YP(i);if(f!==null){f.flags&=-257,XP(f,i,a,s,e),f.mode&1&&VP(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)){VP(s,c,e),nw();break e}l=Error(X(426))}}else if(at&&a.mode&1){var v=YP(i);if(v!==null){!(v.flags&65536)&&(v.flags|=256),XP(v,i,a,s,e),Lx(Il(l,a));break e}}s=l=Il(l,a),Tt!==4&&(Tt=2),nu===null?nu=[s]:nu.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,e&=-e,s.lanes|=e;var S=Dk(s,l,e);BP(s,S);break e;case 1:a=l;var y=s.type,b=s.stateNode;if(!(s.flags&128)&&(typeof y.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&(Js===null||!Js.has(b)))){s.flags|=65536,e&=-e,s.lanes|=e;var P=Rk(s,a,e);BP(s,P);break e}}s=s.return}while(s!==null)}eT(n)}catch(C){e=C,_t===n&&n!==null&&(_t=n=n.return);continue}break}while(!0)}function Qk(){var t=Jp.current;return Jp.current=Qp,t===null?Qp:t}function nw(){(Tt===0||Tt===3||Tt===2)&&(Tt=4),Rt===null||!(Ji&268435455)&&!(ag&268435455)||Ns(Rt,Yt)}function nf(t,e){var n=Oe;Oe|=2;var r=Qk();(Rt!==t||Yt!==e)&&(Xo=null,Wi(t,e));do try{Oz();break}catch(o){Zk(t,o)}while(!0);if(Fx(),Oe=n,Jp.current=r,_t!==null)throw Error(X(261));return Rt=null,Yt=0,Tt}function Oz(){for(;_t!==null;)Jk(_t)}function Dz(){for(;_t!==null&&!s6();)Jk(_t)}function Jk(t){var e=nT(t.alternate,t,or);t.memoizedProps=t.pendingProps,e===null?eT(t):_t=e,Zx.current=null}function eT(t){var e=t;do{var n=e.alternate;if(t=e.return,e.flags&32768){if(n=Ez(n,e),n!==null){n.flags&=32767,_t=n;return}if(t!==null)t.flags|=32768,t.subtreeFlags=0,t.deletions=null;else{Tt=6,_t=null;return}}else if(n=Iz(n,e,or),n!==null){_t=n;return}if(e=e.sibling,e!==null){_t=e;return}_t=e=t}while(e!==null);Tt===0&&(Tt=5)}function Fi(t,e,n){var r=Ue,o=jr.transition;try{jr.transition=null,Ue=1,Rz(t,e,n,r)}finally{jr.transition=o,Ue=r}return null}function Rz(t,e,n,r){do pl();while(Ks!==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(g6(t,s),t===Rt&&(_t=Rt=null,Yt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||qd||(qd=!0,rT($p,function(){return pl(),null})),s=(n.flags&15990)!==0,n.subtreeFlags&15990||s){s=jr.transition,jr.transition=null;var i=Ue;Ue=1;var a=Oe;Oe|=4,Zx.current=null,Tz(t,n),Yk(n,t),tz(gv),Np=!!fv,gv=fv=null,t.current=n,Mz(n),i6(),Oe=a,Ue=i,jr.transition=s}else t.current=n;if(qd&&(qd=!1,Ks=t,tf=o),s=t.pendingLanes,s===0&&(Js=null),c6(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(ef)throw ef=!1,t=Rv,Rv=null,t;return tf&1&&t.tag!==0&&pl(),s=t.pendingLanes,s&1?t===Lv?ru++:(ru=0,Lv=t):ru=0,vi(),null}function pl(){if(Ks!==null){var t=D2(tf),e=jr.transition,n=Ue;try{if(jr.transition=null,Ue=16>t?16:t,Ks===null)var r=!1;else{if(t=Ks,Ks=null,tf=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:tu(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(Wk(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:tu(9,s,s.return)}var S=s.sibling;if(S!==null){S.return=s.return,re=S;break e}re=s.return}}var y=t.current;for(re=y;re!==null;){i=re;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,re=b;else e:for(i=y;re!==null;){if(a=re,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:ig(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,vi(),_o&&typeof _o.onPostCommitFiberRoot=="function")try{_o.onPostCommitFiberRoot(Qf,t)}catch{}r=!0}return r}finally{Ue=n,jr.transition=e}}return!1}function lC(t,e,n){e=Il(n,e),e=Dk(t,e,1),t=Qs(t,e,1),e=bn(),t!==null&&(Xu(t,1,e),Yn(t,e))}function yt(t,e,n){if(t.tag===3)lC(t,t,n);else for(;e!==null;){if(e.tag===3){lC(e,t,n);break}else if(e.tag===1){var r=e.stateNode;if(typeof e.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Js===null||!Js.has(r))){t=Il(n,t),t=Rk(e,t,1),e=Qs(e,t,1),t=bn(),e!==null&&(Xu(e,1,t),Yn(e,t));break}}e=e.return}}function Lz(t,e,n){var r=t.pingCache;r!==null&&r.delete(e),e=bn(),t.pingedLanes|=t.suspendedLanes&n,Rt===t&&(Yt&n)===n&&(Tt===4||Tt===3&&(Yt&130023424)===Yt&&500>wt()-Jx?Wi(t,0):Qx|=n),Yn(t,e)}function tT(t,e){e===0&&(t.mode&1?(e=zd,zd<<=1,!(zd&130023424)&&(zd=4194304)):e=1);var n=bn();t=ps(t,e),t!==null&&(Xu(t,e,n),Yn(t,n))}function $z(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),tT(t,n)}function Fz(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),tT(t,n)}var nT;nT=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Gn.current)Bn=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Bn=!1,_z(t,e,n);Bn=!!(t.flags&131072)}else Bn=!1,at&&e.flags&1048576&&ik(e,Gp,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;Vh(t,e),t=e.pendingProps;var o=bl(e,fn.current);hl(e,n),o=Gx(null,e,r,t,o,n);var s=Vx();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,Kp(e)):s=!1,e.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,Bx(e),o.updater=sg,e.stateNode=o,o._reactInternals=e,Cv(e,r,t,n),e=Ev(null,e,r,!0,s,n)):(e.tag=0,at&&s&&Dx(e),vn(null,e,o,n),e=e.child),e;case 16:r=e.elementType;e:{switch(Vh(t,e),t=e.pendingProps,o=r._init,r=o(r._payload),e.type=r,o=e.tag=zz(r),t=Ur(r,t),o){case 0:e=Iv(null,e,r,t,n);break e;case 1:e=QP(null,e,r,t,n);break e;case 11:e=qP(null,e,r,t,n);break e;case 14:e=ZP(null,e,r,Ur(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:Ur(r,o),Iv(t,e,r,o,n);case 1:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Ur(r,o),QP(t,e,r,o,n);case 3:e:{if(Nk(e),t===null)throw Error(X(387));r=e.pendingProps,s=e.memoizedState,o=s.element,hk(t,e),Xp(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=Il(Error(X(423)),e),e=JP(t,e,r,n,o);break e}else if(r!==o){o=Il(Error(X(424)),e),e=JP(t,e,r,n,o);break e}else for(ar=Zs(e.stateNode.containerInfo.firstChild),cr=e,at=!0,Gr=null,n=uk(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(Pl(),r===o){e=fs(t,e,n);break e}vn(t,e,r,n)}e=e.child}return e;case 5:return pk(e),t===null&&wv(e),r=e.type,o=e.pendingProps,s=t!==null?t.memoizedProps:null,i=o.children,mv(r,o)?i=null:s!==null&&mv(r,s)&&(e.flags|=32),Fk(t,e),vn(t,e,i,n),e.child;case 6:return t===null&&wv(e),null;case 13:return zk(t,e,n);case 4:return Ux(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=Cl(e,null,r,n):vn(t,e,r,n),e.child;case 11:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Ur(r,o),qP(t,e,r,o,n);case 7:return vn(t,e,e.pendingProps,n),e.child;case 8:return vn(t,e,e.pendingProps.children,n),e.child;case 12:return vn(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,qe(Vp,r._currentValue),r._currentValue=i,s!==null)if(to(s.value,i)){if(s.children===o.children&&!Gn.current){e=fs(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=rs(-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),bv(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),bv(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}vn(t,e,o.children,n),e=e.child}return e;case 9:return o=e.type,r=e.pendingProps.children,hl(e,n),o=Dr(o),r=r(o),e.flags|=1,vn(t,e,r,n),e.child;case 14:return r=e.type,o=Ur(r,e.pendingProps),o=Ur(r.type,o),ZP(t,e,r,o,n);case 15:return Lk(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Ur(r,o),Vh(t,e),e.tag=1,Vn(r)?(t=!0,Kp(e)):t=!1,hl(e,n),Ok(e,r,o),Cv(e,r,o,n),Ev(null,e,r,!0,t,n);case 19:return Bk(t,e,n);case 22:return $k(t,e,n)}throw Error(X(156,e.tag))};function rT(t,e){return M2(t,e)}function Nz(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 Mr(t,e,n,r){return new Nz(t,e,n,r)}function rw(t){return t=t.prototype,!(!t||!t.isReactComponent)}function zz(t){if(typeof t=="function")return rw(t)?1:0;if(t!=null){if(t=t.$$typeof,t===bx)return 11;if(t===Px)return 14}return 2}function ti(t,e){var n=t.alternate;return n===null?(n=Mr(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 qh(t,e,n,r,o,s){var i=2;if(r=t,typeof t=="function")rw(t)&&(i=1);else if(typeof t=="string")i=5;else e:switch(t){case Ba:return Gi(n.children,o,s,e);case wx:i=8,o|=8;break;case YS:return t=Mr(12,n,e,o|2),t.elementType=YS,t.lanes=s,t;case XS:return t=Mr(13,n,e,o),t.elementType=XS,t.lanes=s,t;case qS:return t=Mr(19,n,e,o),t.elementType=qS,t.lanes=s,t;case p2:return lg(n,o,s,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case d2:i=10;break e;case h2:i=9;break e;case bx:i=11;break e;case Px:i=14;break e;case Ls:i=16,r=null;break e}throw Error(X(130,t==null?t:typeof t,""))}return e=Mr(i,n,e,o),e.elementType=t,e.type=r,e.lanes=s,e}function Gi(t,e,n,r){return t=Mr(7,t,r,e),t.lanes=n,t}function lg(t,e,n,r){return t=Mr(22,t,r,e),t.elementType=p2,t.lanes=n,t.stateNode={isHidden:!1},t}function ty(t,e,n){return t=Mr(6,t,null,e),t.lanes=n,t}function ny(t,e,n){return e=Mr(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function Bz(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=Lm(0),this.expirationTimes=Lm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Lm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function ow(t,e,n,r,o,s,i,a,l){return t=new Bz(t,e,n,a,l),e===1?(e=1,s===!0&&(e|=8)):e=0,s=Mr(3,null,null,e),t.current=s,s.stateNode=t,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Bx(s),t}function Uz(t,e,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:za,key:r==null?null:""+r,children:t,containerInfo:e,implementation:n}}function oT(t){if(!t)return ai;t=t._reactInternals;e:{if(ga(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 ok(t,n,e)}return e}function sT(t,e,n,r,o,s,i,a,l){return t=ow(n,r,!0,t,o,s,i,a,l),t.context=oT(null),n=t.current,r=bn(),o=ei(n),s=rs(r,o),s.callback=e??null,Qs(n,s,o),t.current.lanes=o,Xu(t,o,r),Yn(t,r),t}function cg(t,e,n,r){var o=e.current,s=bn(),i=ei(o);return n=oT(n),e.context===null?e.context=n:e.pendingContext=n,e=rs(s,i),e.payload={element:t},r=r===void 0?null:r,r!==null&&(e.callback=r),t=Qs(o,e,i),t!==null&&(Qr(t,o,i,s),Kh(t,o,i)),i}function rf(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 cC(t,e){if(t=t.memoizedState,t!==null&&t.dehydrated!==null){var n=t.retryLane;t.retryLane=n!==0&&n<e?n:e}}function sw(t,e){cC(t,e),(t=t.alternate)&&cC(t,e)}function Hz(){return null}var iT=typeof reportError=="function"?reportError:function(t){console.error(t)};function iw(t){this._internalRoot=t}ug.prototype.render=iw.prototype.render=function(t){var e=this._internalRoot;if(e===null)throw Error(X(409));cg(t,e,null,null)};ug.prototype.unmount=iw.prototype.unmount=function(){var t=this._internalRoot;if(t!==null){this._internalRoot=null;var e=t.containerInfo;ea(function(){cg(null,t,null,null)}),e[hs]=null}};function ug(t){this._internalRoot=t}ug.prototype.unstable_scheduleHydration=function(t){if(t){var e=$2();t={blockedOn:null,target:t,priority:e};for(var n=0;n<Fs.length&&e!==0&&e<Fs[n].priority;n++);Fs.splice(n,0,t),n===0&&N2(t)}};function aw(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)}function dg(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11&&(t.nodeType!==8||t.nodeValue!==" react-mount-point-unstable "))}function uC(){}function Kz(t,e,n,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=rf(i);s.call(c)}}var i=sT(e,r,t,0,null,!1,!1,"",uC);return t._reactRootContainer=i,t[hs]=i.current,xu(t.nodeType===8?t.parentNode:t),ea(),i}for(;o=t.lastChild;)t.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=rf(l);a.call(c)}}var l=ow(t,0,!1,null,null,!1,!1,"",uC);return t._reactRootContainer=l,t[hs]=l.current,xu(t.nodeType===8?t.parentNode:t),ea(function(){cg(e,l,n,r)}),l}function hg(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=rf(i);a.call(l)}}cg(e,i,t,o)}else i=Kz(n,e,t,o,r);return rf(i)}R2=function(t){switch(t.tag){case 3:var e=t.stateNode;if(e.current.memoizedState.isDehydrated){var n=$c(e.pendingLanes);n!==0&&(Ix(e,n|1),Yn(e,wt()),!(Oe&6)&&(El=wt()+500,vi()))}break;case 13:ea(function(){var r=ps(t,1);if(r!==null){var o=bn();Qr(r,t,1,o)}}),sw(t,1)}};Ex=function(t){if(t.tag===13){var e=ps(t,134217728);if(e!==null){var n=bn();Qr(e,t,134217728,n)}sw(t,134217728)}};L2=function(t){if(t.tag===13){var e=ei(t),n=ps(t,e);if(n!==null){var r=bn();Qr(n,t,e,r)}sw(t,e)}};$2=function(){return Ue};F2=function(t,e){var n=Ue;try{return Ue=t,e()}finally{Ue=n}};iv=function(t,e,n){switch(e){case"input":if(JS(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=ng(r);if(!o)throw Error(X(90));g2(r),JS(r,o)}}}break;case"textarea":y2(t,n);break;case"select":e=n.value,e!=null&&ll(t,!!n.multiple,e,!1)}};C2=ew;_2=ea;var Wz={usingClientEntryPoint:!1,Events:[Zu,Wa,ng,b2,P2,ew]},gc={findFiberByHostInstance:Bi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},Gz={bundleType:gc.bundleType,version:gc.version,rendererPackageName:gc.rendererPackageName,rendererConfig:gc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:vs.ReactCurrentDispatcher,findHostInstanceByFiber:function(t){return t=k2(t),t===null?null:t.stateNode},findFiberByHostInstance:gc.findFiberByHostInstance||Hz,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 Zd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Zd.isDisabled&&Zd.supportsFiber)try{Qf=Zd.inject(Gz),_o=Zd}catch{}}Sr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Wz;Sr.createPortal=function(t,e){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!aw(e))throw Error(X(200));return Uz(t,e,null,n)};Sr.createRoot=function(t,e){if(!aw(t))throw Error(X(299));var n=!1,r="",o=iT;return e!=null&&(e.unstable_strictMode===!0&&(n=!0),e.identifierPrefix!==void 0&&(r=e.identifierPrefix),e.onRecoverableError!==void 0&&(o=e.onRecoverableError)),e=ow(t,1,!1,null,null,n,!1,r,o),t[hs]=e.current,xu(t.nodeType===8?t.parentNode:t),new iw(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=k2(e),t=t===null?null:t.stateNode,t};Sr.flushSync=function(t){return ea(t)};Sr.hydrate=function(t,e,n){if(!dg(e))throw Error(X(200));return hg(null,t,e,!0,n)};Sr.hydrateRoot=function(t,e,n){if(!aw(t))throw Error(X(405));var r=n!=null&&n.hydratedSources||null,o=!1,s="",i=iT;if(n!=null&&(n.unstable_strictMode===!0&&(o=!0),n.identifierPrefix!==void 0&&(s=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),e=sT(e,null,t,1,n??null,o,!1,s,i),t[hs]=e.current,xu(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 ug(e)};Sr.render=function(t,e,n){if(!dg(e))throw Error(X(200));return hg(null,t,e,!1,n)};Sr.unmountComponentAtNode=function(t){if(!dg(t))throw Error(X(40));return t._reactRootContainer?(ea(function(){hg(null,null,t,!1,function(){t._reactRootContainer=null,t[hs]=null})}),!0):!1};Sr.unstable_batchedUpdates=ew;Sr.unstable_renderSubtreeIntoContainer=function(t,e,n,r){if(!dg(n))throw Error(X(200));if(t==null||t._reactInternals===void 0)throw Error(X(38));return hg(t,e,n,!1,r)};Sr.version="18.3.1-next-f1338f8080-20240426";function aT(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(aT)}catch(t){console.error(t)}}aT(),a2.exports=Sr;var li=a2.exports;const Vz=mi(li);var lT,dC=li;lT=GS.createRoot=dC.createRoot,GS.hydrateRoot=dC.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 Yz(t){const e=ae("./icons/icon/0_merged.svg",t);return{fonts:{monospace:ae("./fonts/IBMPlexMono-Medium.woff2",t),sansSerif:ae("./fonts/IBMPlexSans-Medium.woff2",t),serif:ae("./fonts/IBMPlexSerif-Medium.woff2",t),draw:ae("./fonts/Shantell_Sans-Tldrawish.woff2",t)},icons:{"align-bottom":e+"#align-bottom","align-center-horizontal":e+"#align-center-horizontal","align-center-vertical":e+"#align-center-vertical","align-left":e+"#align-left","align-right":e+"#align-right","align-top":e+"#align-top","arrow-left":e+"#arrow-left","arrowhead-arrow":e+"#arrowhead-arrow","arrowhead-bar":e+"#arrowhead-bar","arrowhead-diamond":e+"#arrowhead-diamond","arrowhead-dot":e+"#arrowhead-dot","arrowhead-none":e+"#arrowhead-none","arrowhead-square":e+"#arrowhead-square","arrowhead-triangle-inverted":e+"#arrowhead-triangle-inverted","arrowhead-triangle":e+"#arrowhead-triangle",blob:e+"#blob","bring-forward":e+"#bring-forward","bring-to-front":e+"#bring-to-front",broken:e+"#broken","check-circle":e+"#check-circle",check:e+"#check","chevron-down":e+"#chevron-down","chevron-left":e+"#chevron-left","chevron-right":e+"#chevron-right","chevron-up":e+"#chevron-up","chevrons-ne":e+"#chevrons-ne","chevrons-sw":e+"#chevrons-sw","clipboard-copied":e+"#clipboard-copied","clipboard-copy":e+"#clipboard-copy",color:e+"#color","cross-2":e+"#cross-2","cross-circle":e+"#cross-circle","dash-dashed":e+"#dash-dashed","dash-dotted":e+"#dash-dotted","dash-draw":e+"#dash-draw","dash-solid":e+"#dash-solid",disconnected:e+"#disconnected",discord:e+"#discord","distribute-horizontal":e+"#distribute-horizontal","distribute-vertical":e+"#distribute-vertical",dot:e+"#dot","dots-horizontal":e+"#dots-horizontal","dots-vertical":e+"#dots-vertical","drag-handle-dots":e+"#drag-handle-dots",duplicate:e+"#duplicate",edit:e+"#edit","external-link":e+"#external-link","fill-fill":e+"#fill-fill","fill-none":e+"#fill-none","fill-pattern":e+"#fill-pattern","fill-semi":e+"#fill-semi","fill-solid":e+"#fill-solid",follow:e+"#follow",following:e+"#following","font-draw":e+"#font-draw","font-mono":e+"#font-mono","font-sans":e+"#font-sans","font-serif":e+"#font-serif","geo-arrow-down":e+"#geo-arrow-down","geo-arrow-left":e+"#geo-arrow-left","geo-arrow-right":e+"#geo-arrow-right","geo-arrow-up":e+"#geo-arrow-up","geo-check-box":e+"#geo-check-box","geo-cloud":e+"#geo-cloud","geo-diamond":e+"#geo-diamond","geo-ellipse":e+"#geo-ellipse","geo-heart":e+"#geo-heart","geo-hexagon":e+"#geo-hexagon","geo-octagon":e+"#geo-octagon","geo-oval":e+"#geo-oval","geo-pentagon":e+"#geo-pentagon","geo-rectangle":e+"#geo-rectangle","geo-rhombus-2":e+"#geo-rhombus-2","geo-rhombus":e+"#geo-rhombus","geo-star":e+"#geo-star","geo-trapezoid":e+"#geo-trapezoid","geo-triangle":e+"#geo-triangle","geo-x-box":e+"#geo-x-box",github:e+"#github",group:e+"#group","horizontal-align-end":e+"#horizontal-align-end","horizontal-align-middle":e+"#horizontal-align-middle","horizontal-align-start":e+"#horizontal-align-start","info-circle":e+"#info-circle",leading:e+"#leading",link:e+"#link",lock:e+"#lock",menu:e+"#menu",minus:e+"#minus",mixed:e+"#mixed",pack:e+"#pack",plus:e+"#plus","question-mark-circle":e+"#question-mark-circle","question-mark":e+"#question-mark",redo:e+"#redo","reset-zoom":e+"#reset-zoom","rotate-ccw":e+"#rotate-ccw","rotate-cw":e+"#rotate-cw","send-backward":e+"#send-backward","send-to-back":e+"#send-to-back","share-1":e+"#share-1","size-extra-large":e+"#size-extra-large","size-large":e+"#size-large","size-medium":e+"#size-medium","size-small":e+"#size-small","spline-cubic":e+"#spline-cubic","spline-line":e+"#spline-line","stack-horizontal":e+"#stack-horizontal","stack-vertical":e+"#stack-vertical","status-offline":e+"#status-offline","stretch-horizontal":e+"#stretch-horizontal","stretch-vertical":e+"#stretch-vertical","text-align-center":e+"#text-align-center","text-align-left":e+"#text-align-left","text-align-right":e+"#text-align-right","toggle-off":e+"#toggle-off","toggle-on":e+"#toggle-on","tool-arrow":e+"#tool-arrow","tool-eraser":e+"#tool-eraser","tool-frame":e+"#tool-frame","tool-hand":e+"#tool-hand","tool-highlight":e+"#tool-highlight","tool-laser":e+"#tool-laser","tool-line":e+"#tool-line","tool-media":e+"#tool-media","tool-note":e+"#tool-note","tool-pencil":e+"#tool-pencil","tool-pointer":e+"#tool-pointer","tool-screenshot":e+"#tool-screenshot","tool-text":e+"#tool-text",trash:e+"#trash",twitter:e+"#twitter",undo:e+"#undo",ungroup:e+"#ungroup",unlock:e+"#unlock","vertical-align-end":e+"#vertical-align-end","vertical-align-middle":e+"#vertical-align-middle","vertical-align-start":e+"#vertical-align-start","warning-triangle":e+"#warning-triangle","zoom-in":e+"#zoom-in","zoom-out":e+"#zoom-out"},translations:{ar:ae("./translations/ar.json",t),ca:ae("./translations/ca.json",t),cs:ae("./translations/cs.json",t),da:ae("./translations/da.json",t),de:ae("./translations/de.json",t),en:ae("./translations/en.json",t),es:ae("./translations/es.json",t),fa:ae("./translations/fa.json",t),fi:ae("./translations/fi.json",t),fr:ae("./translations/fr.json",t),gl:ae("./translations/gl.json",t),he:ae("./translations/he.json",t),"hi-in":ae("./translations/hi-in.json",t),hr:ae("./translations/hr.json",t),hu:ae("./translations/hu.json",t),id:ae("./translations/id.json",t),it:ae("./translations/it.json",t),ja:ae("./translations/ja.json",t),"ko-kr":ae("./translations/ko-kr.json",t),ku:ae("./translations/ku.json",t),languages:ae("./translations/languages.json",t),main:ae("./translations/main.json",t),my:ae("./translations/my.json",t),ne:ae("./translations/ne.json",t),no:ae("./translations/no.json",t),pl:ae("./translations/pl.json",t),"pt-br":ae("./translations/pt-br.json",t),"pt-pt":ae("./translations/pt-pt.json",t),ro:ae("./translations/ro.json",t),ru:ae("./translations/ru.json",t),sl:ae("./translations/sl.json",t),sv:ae("./translations/sv.json",t),te:ae("./translations/te.json",t),th:ae("./translations/th.json",t),tr:ae("./translations/tr.json",t),uk:ae("./translations/uk.json",t),vi:ae("./translations/vi.json",t),"zh-cn":ae("./translations/zh-cn.json",t),"zh-tw":ae("./translations/zh-tw.json",t)},embedIcons:{codepen:ae("./embed-icons/codepen.png",t),codesandbox:ae("./embed-icons/codesandbox.png",t),desmos:ae("./embed-icons/desmos.png",t),excalidraw:ae("./embed-icons/excalidraw.png",t),felt:ae("./embed-icons/felt.png",t),figma:ae("./embed-icons/figma.png",t),github_gist:ae("./embed-icons/github_gist.png",t),google_calendar:ae("./embed-icons/google_calendar.png",t),google_maps:ae("./embed-icons/google_maps.png",t),google_slides:ae("./embed-icons/google_slides.png",t),observable:ae("./embed-icons/observable.png",t),replit:ae("./embed-icons/replit.png",t),scratch:ae("./embed-icons/scratch.png",t),spotify:ae("./embed-icons/spotify.png",t),tldraw:ae("./embed-icons/tldraw.png",t),val_town:ae("./embed-icons/val_town.png",t),vimeo:ae("./embed-icons/vimeo.png",t),youtube:ae("./embed-icons/youtube.png",t)}}}const ry="__TLDRAW_LIBRARY_VERSIONS__";function Xz(){if(globalThis[ry])return globalThis[ry];const t={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,ry,{value:t,writable:!1,configurable:!1,enumerable:!1}),t}function xi(t,e,n){if(!t||!e||!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=Xz();if(r.versions.push({name:t,version:e,modules:n}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,hC(r)},100)}catch{hC(r)}}function hC(t){if(!t.versions.length||t.didWarn)return;const e=t.versions.sort((a,l)=>pC(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),oy(o,a.name,new Set).add(a.version);continue}a.version===n?r.add(a.name):(r.delete(a.name),oy(o,a.name,new Set).add(a.version))}if(o.size>0){const a=[`${Ho("[tldraw]",["bold","bgRed","textWhite"])} ${Ho("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 ${Ho(`v${n}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${Ho(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(pC).map(h=>Ho(`v${h}`,h===n?["textGreen"]:["textRed"]));return` • ❌ ${Ho(l,["bold"])} (${u.join(", ")})`})];console.log(a.join(`
|
|
41
|
-
`)),t.didWarn=!0;return}const s=new Map;for(const a of e)oy(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=[`${Ho("[tldraw]",["bold","bgRed","textWhite"])} ${Ho("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` • ❌ ${Ho(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 pC(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 qz={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function Ho(t,e=[]){return`\x1B[${e.map(n=>qz[n]).join(";")}m${t}\x1B[m`}function oy(t,e,n){return t.has(e)?t.get(e):(t.set(e,n),n)}var cT="Expected a function",fC=NaN,Zz="[object Symbol]",Qz=/^\s+|\s+$/g,Jz=/^[-+]0x[0-9a-f]+$/i,e8=/^0b[01]+$/i,t8=/^0o[0-7]+$/i,n8=parseInt,r8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,o8=typeof self=="object"&&self&&self.Object===Object&&self,s8=r8||o8||Function("return this")(),i8=Object.prototype,a8=i8.toString,l8=Math.max,c8=Math.min,sy=function(){return s8.Date.now()};function u8(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(cT);e=gC(e)||0,of(n)&&(u=!!n.leading,h="maxWait"in n,s=h?l8(gC(n.maxWait)||0,e):s,p="trailing"in n?!!n.trailing:p);function f(I){var k=r,_=o;return r=o=void 0,c=I,i=t.apply(_,k),i}function g(I){return c=I,a=setTimeout(S,e),u?f(I):i}function m(I){var k=I-l,_=I-c,T=e-k;return h?c8(T,s-_):T}function v(I){var k=I-l,_=I-c;return l===void 0||k>=e||k<0||h&&_>=s}function S(){var I=sy();if(v(I))return y(I);a=setTimeout(S,m(I))}function y(I){return a=void 0,p&&r?f(I):(r=o=void 0,i)}function b(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function P(){return a===void 0?i:y(sy())}function C(){var I=sy(),k=v(I);if(r=arguments,o=this,l=I,k){if(a===void 0)return g(l);if(h)return a=setTimeout(S,e),f(l)}return a===void 0&&(a=setTimeout(S,e)),i}return C.cancel=b,C.flush=P,C}function d8(t,e,n){var r=!0,o=!0;if(typeof t!="function")throw new TypeError(cT);return of(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),u8(t,e,{leading:r,maxWait:e,trailing:o})}function of(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function h8(t){return!!t&&typeof t=="object"}function p8(t){return typeof t=="symbol"||h8(t)&&a8.call(t)==Zz}function gC(t){if(typeof t=="number")return t;if(p8(t))return fC;if(of(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=of(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=t.replace(Qz,"");var n=e8.test(t);return n||t8.test(t)?n8(t.slice(2),n?2:8):Jz.test(t)?fC:+t}var f8=d8;const uT=mi(f8);var g8=200,lw="__lodash_hash_undefined__",m8=1/0,y8="[object Function]",S8="[object GeneratorFunction]",v8=/[\\^$.*+?()[\]{}|]/g,x8=/^\[object .+?Constructor\]$/,w8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,b8=typeof self=="object"&&self&&self.Object===Object&&self,cw=w8||b8||Function("return this")();function P8(t,e){var n=t?t.length:0;return!!n&&_8(t,e,0)>-1}function C8(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 _8(t,e,n){if(e!==e)return C8(t,I8,n);for(var r=n-1,o=t.length;++r<o;)if(t[r]===e)return r;return-1}function I8(t){return t!==t}function E8(t,e){return t.has(e)}function k8(t,e){return t==null?void 0:t[e]}function T8(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function dT(t){var e=-1,n=Array(t.size);return t.forEach(function(r){n[++e]=r}),n}var M8=Array.prototype,A8=Function.prototype,hT=Object.prototype,iy=cw["__core-js_shared__"],mC=function(){var t=/[^.]+$/.exec(iy&&iy.keys&&iy.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),pT=A8.toString,uw=hT.hasOwnProperty,j8=hT.toString,O8=RegExp("^"+pT.call(uw).replace(v8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),D8=M8.splice,R8=dw(cw,"Map"),ay=dw(cw,"Set"),Tu=dw(Object,"create");function ta(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 L8(){this.__data__=Tu?Tu(null):{}}function $8(t){return this.has(t)&&delete this.__data__[t]}function F8(t){var e=this.__data__;if(Tu){var n=e[t];return n===lw?void 0:n}return uw.call(e,t)?e[t]:void 0}function N8(t){var e=this.__data__;return Tu?e[t]!==void 0:uw.call(e,t)}function z8(t,e){var n=this.__data__;return n[t]=Tu&&e===void 0?lw:e,this}ta.prototype.clear=L8;ta.prototype.delete=$8;ta.prototype.get=F8;ta.prototype.has=N8;ta.prototype.set=z8;function zl(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 B8(){this.__data__=[]}function U8(t){var e=this.__data__,n=pg(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():D8.call(e,n,1),!0}function H8(t){var e=this.__data__,n=pg(e,t);return n<0?void 0:e[n][1]}function K8(t){return pg(this.__data__,t)>-1}function W8(t,e){var n=this.__data__,r=pg(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}zl.prototype.clear=B8;zl.prototype.delete=U8;zl.prototype.get=H8;zl.prototype.has=K8;zl.prototype.set=W8;function Bl(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 G8(){this.__data__={hash:new ta,map:new(R8||zl),string:new ta}}function V8(t){return fg(this,t).delete(t)}function Y8(t){return fg(this,t).get(t)}function X8(t){return fg(this,t).has(t)}function q8(t,e){return fg(this,t).set(t,e),this}Bl.prototype.clear=G8;Bl.prototype.delete=V8;Bl.prototype.get=Y8;Bl.prototype.has=X8;Bl.prototype.set=q8;function sf(t){var e=-1,n=t?t.length:0;for(this.__data__=new Bl;++e<n;)this.add(t[e])}function Z8(t){return this.__data__.set(t,lw),this}function Q8(t){return this.__data__.has(t)}sf.prototype.add=sf.prototype.push=Z8;sf.prototype.has=Q8;function pg(t,e){for(var n=t.length;n--;)if(iB(t[n][0],e))return n;return-1}function J8(t){if(!fT(t)||rB(t))return!1;var e=aB(t)||T8(t)?O8:x8;return e.test(oB(t))}function eB(t,e,n){var r=-1,o=P8,s=t.length,i=!0,a=[],l=a;if(s>=g8){var c=tB(t);if(c)return dT(c);i=!1,o=E8,l=new sf}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 tB=ay&&1/dT(new ay([,-0]))[1]==m8?function(t){return new ay(t)}:lB;function fg(t,e){var n=t.__data__;return nB(e)?n[typeof e=="string"?"string":"hash"]:n.map}function dw(t,e){var n=k8(t,e);return J8(n)?n:void 0}function nB(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function rB(t){return!!mC&&mC in t}function oB(t){if(t!=null){try{return pT.call(t)}catch{}try{return t+""}catch{}}return""}function sB(t){return t&&t.length?eB(t):[]}function iB(t,e){return t===e||t!==t&&e!==e}function aB(t){var e=fT(t)?j8.call(t):"";return e==y8||e==S8}function fT(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function lB(){}var cB=sB;const uB=mi(cB),Nc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},dB=Nc.Good;class gT{constructor(){E(this,"startTime",0);E(this,"name","");E(this,"frames",0);E(this,"started",!1);E(this,"frame",null);E(this,"recordFrame",()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))})}start(e){this.name=e,this.frames=0,this.started=!0,this.frame!==null&&cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(this.recordFrame),this.startTime=performance.now()}stop(){this.started=!1,this.frame!==null&&cancelAnimationFrame(this.frame);const e=(performance.now()-this.startTime)/1e3,n=e===0?0:Math.floor(this.frames/e),r=n>55?Nc.Good:n>30?Nc.Mid:Nc.Poor,o=r===Nc.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${n}%c fps`,`color: white; background: ${dB};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 hw(t,e){const n=[];e:for(const r of t){for(const o of n)if(e?e(r,o):r===o)continue e;n.push(r)}return n}function ye(t){return t.filter(e=>e!=null)}function Ht(t){return t[t.length-1]}function hB(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 pB(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 mT(t){const e=(...n)=>{try{return t(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const Mu=()=>{},xn={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=mT((t,e)=>{if(!t)throw new Error(e||"Assertion Error")}),sr=mT((t,e)=>{if(t==null)throw new Error(e??"value must be defined");return t});function pw(){let t,e;const n=new Promise((r,o)=>{t=r,e=o});return Object.assign(n,{resolve:t,reject:e})}function Nv(t){return new Promise(e=>setTimeout(e,t))}function Un(...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 ko{constructor(){E(this,"items",new WeakMap)}get(e,n){return this.items.has(e)||this.items.set(e,n(e)),this.items.get(e)}}function fw(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 yC=new WeakMap;function gw(t,e){if(typeof t!="object"||t===null)return;let n=yC.get(t);n||(n={tags:{},extras:{}},yC.set(t,n)),e.tags&&(n.tags={...n.tags,...e.tags}),e.extras&&(n.extras={...n.extras,...e.extras})}async function no(t,e){return window.fetch(t,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const Au=(t,e)=>{const n=new window.Image(t,e);return n.referrerPolicy="strict-origin-when-cross-origin",n};class os{static async dataUrlToArrayBuffer(e){return no(e).then(function(n){return n.arrayBuffer()})}static async blobToDataUrl(e){return await new Promise((n,r)=>{if(e){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((n,r)=>{if(e){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsText(e)}})}}function zv(t){let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e+""}function SC(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 vC=globalThis.crypto,fB="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",gB=128;let Ni,Qa;function mB(t){!Ni||Ni.length<t?(Ni=new Uint8Array(t*gB),vC.getRandomValues(Ni),Qa=0):Qa+t>Ni.length&&(vC.getRandomValues(Ni),Qa=0),Qa+=t}function yB(t=21){mB(t-=0);let e="";for(let n=Qa-t;n<Qa;n++)e+=fB[Ni[n]&63];return e}let SB=yB;function ze(t){return SB(t)}/*!
|
|
54
|
-
* MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
|
|
55
|
-
* Copyright (c) Philip van Heemstra
|
|
56
|
-
*/function vB(t){const e=new Uint8Array(t);if(!e||!(typeof Buffer<"u"&&Buffer.isBuffer(e)||e instanceof Uint8Array)||e.length<16||!(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10))return!1;function r(s,i,a,l,c=1024){if(!i)return-1;i=new RegExp(i,"g");const u=i.source.length,h=new TextDecoder,p=s.length;if(typeof l>"u"&&(l=p),a>=p||l<=0||a>=l)return-1;s=s.subarray(a,l);let f=-1,g=0,m=0,v="";e:for(;g<s.length;){const S=g+c,y=s.subarray(g,S),b=h.decode(y,{stream:!0}),P=v+b;let C,I=-1;for(;(C=i.exec(P))!==null;){I=C.index-v.length,f=m+I;break e}g=S,m+=b.length;const k=I>-1?I+u:b.length-u;v=b.slice(k)}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 xB=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 xC(t,e){let n=0;for(;t[e+n];)n+=t[e+n]+1;return n+1}function wB(t){return new TextDecoder("ascii").decode(t.slice(0,3))==="GIF"}function bB(t){const e=new Uint8Array(t);let n,r,o=0,s=0;if(!wB(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+=xC(e,o+1)+1;break;case 33:o+=2,o+=xC(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 Bv=[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"&&(Bv=new Int32Array(Bv));const PB=(t,e)=>{let n=~~e^-1;for(let r=0;r<t.length;r++)n=Bv[(n^t[r])&255]^n>>>8;return n^-1},wC=4,bC=4;class vo{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(!vo.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=vo.getChunkType(e,n);if(i==="IDAT"&&r[i]){n+=s+wC+bC;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:n+4,size:s},n+=s+wC+bC}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 vo.readChunks(e)[n]}static setPhysChunk(e,n=1,r){let o=46,s=0;const i=vo.findChunk(e,"pHYs");i&&(o=i.start,s=i.size);const a=vo.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,PB(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 CB(t){return!t||t.length<12?!1:t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80}function _B(t){const e=new Uint8Array(t);return!CB(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const yT=Object.freeze(["image/svg+xml"]),ST=Object.freeze(["image/jpeg","image/png","image/webp"]),vT=Object.freeze(["image/gif","image/apng","image/avif"]),gg=Object.freeze([...ST,...yT,...vT]),mw=Object.freeze(["video/mp4","video/webm","video/quicktime"]),IB=[...gg,...mw].join(",");class lr{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=pw();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=Au();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 lr.usingObjectURL(e,async n=>{const r=await lr.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const n=await lr.usingObjectURL(e,lr.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(vo.isPng(r,0)){const o=vo.findChunk(r,"pHYs");if(o){const s=vo.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"?bB(await e.arrayBuffer()):e.type==="image/avif"?xB(await e.arrayBuffer()):e.type==="image/webp"?_B(await e.arrayBuffer()):e.type==="image/apng"?vB(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return vT.includes(e||"")}static isStaticImageType(e){return ST.includes(e||"")}static isVectorImageType(e){return yT.includes(e||"")}static isImageType(e){return gg.includes(e)}static async usingObjectURL(e,n){const r=URL.createObjectURL(e);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function Ie(t,e,n){return t+(e-t)*n}function io(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 kl(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 Jr(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function Hn(t,e){if(Jr(t,e))return t[e]}function PC(t){return Object.keys(t)}function ut(t){return Object.values(t)}function Xn(t){return Object.entries(t)}function xT(t){return Object.fromEntries(t)}function ou(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 Ju(t,e){const n={};for(const[r,o]of Xn(t)){const s=e(r,o);n[r]=s}return n}function wT(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 EB(t){const e=kB(t.chars),n=TB(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),o=MB(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 kB(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 TB(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 MB(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var ly=null;function yw(){return ly||(ly=EB({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Ws(t,e,n){const r=n.byChar[t],o=n.byChar[e];return Math.abs(r-o)}function Sw(t,e){const n=t[0];if(n>e.mostPositive||n<e.mostNegative)throw new Error("invalid firstChar on key");return n===e.mostPositive?Ws(n,e.firstPositive,e)+1+af(t.slice(1),"positive",e):n===e.mostNegative?Ws(n,e.firstNegative,e)+1+af(t.slice(1),"negative",e):n>=e.firstPositive?Ws(n,e.firstPositive,e)+2:Ws(n,e.firstNegative,e)+2}function af(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"?Ws(r,n.mostNegative,n)+1+af(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Ws(r,n.mostPositive,n)+1+af(t.slice(1),e,n):e==="positive"?Ws(r,n.mostNegative,n)+2:Ws(r,n.mostPositive,n)+2}function mg(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 AB(t,e,n){let[r,o]=mg(t,e,"end",n.first),s=Uv(r,o,n);s===1&&(r=r.padEnd(r.length+1,n.first),s=n.length);const i=CT(Math.floor(s/2),n);return vw(r,i,n)}function Uv(t,e,n){const[r,o]=mg(t,e,"end",n.first).sort(),s=bT(o,r,n);return jB(s,n)}function vw(t,e,n){const r=n.length,[o,s]=mg(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 bT(t,e,n){const r=n.length,[o,s]=mg(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 PT(t,e){return vw(t,e.byCode[1],e)}function Hv(t,e){return bT(t,e.byCode[1],e)}function CT(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 jB(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 OB(t){return t.firstPositive+t.byCode[0]}function DB(t,e){return Sw(t,e)===t.length}function CC(t,e){lf(t,e)}function lf(t,e){const n=ET(t,e),r=Sw(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function _T(t,e){if(!DB(t,e))throw new Error("invalid integer length: "+t)}function IT(t,e){_T(t,e);const[n,r]=kT(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=PT(r,e);return n+i}const s=LB(n,e);return TT(s,"lower",e)}function RB(t,e){_T(t,e);const[n,r]=kT(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Hv(r,e);return n+i}const s=$B(n,e);return TT(s,"upper",e)}function ET(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 kT(t,e){const n=ET(t,e),r=t.slice(n.length);return[n,r]}function LB(t,e){const n=t>=e.firstPositive,r=PT(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 $B(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 Hv(o,e)}return!n&&r?t+e.mostPositive:Hv(t,e)}function TT(t,e,n){const r=Sw(t,n),o=e==="upper"?n.byCode[n.length-1]:n.byCode[0];return t+o.repeat(r-t.length)}function MT(t,e){const n=CT(Math.floor(Math.random()*e.jitterRange),e);return vw(t,n,e)}function FB(t,e,n){const r=t.padEnd(t.length+e,n.first);return MT(r,n)}function NB(t,e,n){const r=lf(t,n),o=IT(r,n);let s=0;if(e!==null){const a=Uv(t,e,n);a<n.jitterRange+1&&(s=Math.max(s,_C(a,n)))}const i=Uv(t,o,n);return i<n.jitterRange+1&&(s=Math.max(s,_C(i,n))),s}function _C(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([o,s])=>s>n);return r?parseInt(r[0]):0}function zB(t,e,n=yw()){if(t!==null&&CC(t,n),e!==null&&CC(e,n),t===null&&e===null)return OB(n);if(t===null){const r=lf(e,n);return RB(r,n)}if(e===null){const r=lf(t,n);return IT(r,n)}if(t>=e)throw new Error(t+" >= "+e);return AB(t,e,n)}function AT(t,e,n=yw()){const r=zB(t,e,n),o=NB(r,e,n);return o?FB(r,o,n):MT(r,n)}function jT(t,e,n,r=yw()){return BB(t,e,n,r,AT,jT)}function BB(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 Ul=jT,OT="a0";function UB(t){try{AT(t,null)}catch{throw new Error("invalid index: "+t)}}function Tl(t,e,n){return Ul(t??null,e??null,n)}function cy(t,e){return Ul(t??null,null,e)}function ju(t,e){return Ul(t??null,e??null,1)[0]}function wo(t=null){return Ul(t,null,1)[0]}function HB(t=null){return Ul(null,t,1)[0]}function Ou(t,e="a1"){return[e,...Ul(e,null,t)]}function cn(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function KB(t,e){return t.id>e.id?1:-1}function xw(t){try{return localStorage.getItem(t)}catch{return null}}function ww(t,e){try{localStorage.setItem(t,e)}catch{}}function WB(){try{localStorage.clear()}catch{}}function DT(t){try{return sessionStorage.getItem(t)}catch{return null}}function bw(t,e){try{sessionStorage.setItem(t,e)}catch{}}function RT(t){try{sessionStorage.removeItem(t)}catch{}}function GB(){try{sessionStorage.clear()}catch{}}const VB=()=>typeof process<"u"&&!1,Ja=[],YB=60,Zh=Math.ceil(1e3/YB);let mc,uy=0,Kv=0;const XB=()=>{const t=Ja.splice(0,Ja.length);for(const e of t)e()};function LT(){if(mc)return;const t=Date.now(),e=t-Kv;if(uy+e<Zh){mc=requestAnimationFrame(()=>{mc=void 0,LT()});return}mc=requestAnimationFrame(()=>{mc=void 0,Kv=t,uy=Math.min(uy+e-Zh,Zh*10),XB()})}let IC=!1;function $T(t){return VB()?(t(),()=>{}):(Ja.includes(t)||(Ja.push(t),IC||(IC=!0,Kv=Date.now()-Zh-1),LT()),()=>{const e=Ja.indexOf(t);e>-1&&Ja.splice(e,1)})}class qB{constructor(){E(this,"timeouts",new Map);E(this,"intervals",new Map);E(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 ZB(t){return t!==void 0}function QB(){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 FT=QB(),nt=FT[0];FT[1];const JB=Object.getPrototypeOf(nt({}));xi("@tldraw/utils","3.3.0","esm");var yc=function(t){return t&&t.Math===Math&&t},_n=yc(typeof globalThis=="object"&&globalThis)||yc(typeof window=="object"&&window)||yc(typeof self=="object"&&self)||yc(typeof dn=="object"&&dn)||yc(typeof dn=="object"&&dn)||function(){return this}()||Function("return this")(),Pw={},In=function(t){try{return!!t()}catch{return!0}},e9=In,wi=!e9(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),t9=In,yg=!t9(function(){var t=(function(){}).bind();return typeof t!="function"||t.hasOwnProperty("prototype")}),n9=yg,Qd=Function.prototype.call,xs=n9?Qd.bind(Qd):function(){return Qd.apply(Qd,arguments)},NT={},zT={}.propertyIsEnumerable,BT=Object.getOwnPropertyDescriptor,r9=BT&&!zT.call({1:2},1);NT.f=r9?function(e){var n=BT(this,e);return!!n&&n.enumerable}:zT;var UT=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}},HT=yg,KT=Function.prototype,Wv=KT.call,o9=HT&&KT.bind.bind(Wv,Wv),Lt=HT?o9:function(t){return function(){return Wv.apply(t,arguments)}},WT=Lt,s9=WT({}.toString),i9=WT("".slice),Hl=function(t){return i9(s9(t),8,-1)},a9=Lt,l9=In,c9=Hl,dy=Object,u9=a9("".split),d9=l9(function(){return!dy("z").propertyIsEnumerable(0)})?function(t){return c9(t)==="String"?u9(t,""):dy(t)}:dy,Sg=function(t){return t==null},h9=Sg,p9=TypeError,Kl=function(t){if(h9(t))throw new p9("Can't call method on "+t);return t},f9=d9,g9=Kl,vg=function(t){return f9(g9(t))},hy=typeof document=="object"&&document.all,En=typeof hy>"u"&&hy!==void 0?function(t){return typeof t=="function"||t===hy}:function(t){return typeof t=="function"},m9=En,ma=function(t){return typeof t=="object"?t!==null:m9(t)},py=_n,y9=En,S9=function(t){return y9(t)?t:void 0},xg=function(t,e){return arguments.length<2?S9(py[t]):py[t]&&py[t][e]},v9=Lt,GT=v9({}.isPrototypeOf),x9=_n,EC=x9.navigator,kC=EC&&EC.userAgent,w9=kC?String(kC):"",VT=_n,fy=w9,TC=VT.process,MC=VT.Deno,AC=TC&&TC.versions||MC&&MC.version,jC=AC&&AC.v8,Vr,cf;jC&&(Vr=jC.split("."),cf=Vr[0]>0&&Vr[0]<4?1:+(Vr[0]+Vr[1]));!cf&&fy&&(Vr=fy.match(/Edge\/(\d+)/),(!Vr||Vr[1]>=74)&&(Vr=fy.match(/Chrome\/(\d+)/),Vr&&(cf=+Vr[1])));var b9=cf,OC=b9,P9=In,C9=_n,_9=C9.String,YT=!!Object.getOwnPropertySymbols&&!P9(function(){var t=Symbol("symbol detection");return!_9(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&OC&&OC<41}),I9=YT,XT=I9&&!Symbol.sham&&typeof Symbol.iterator=="symbol",E9=xg,k9=En,T9=GT,M9=XT,A9=Object,qT=M9?function(t){return typeof t=="symbol"}:function(t){var e=E9("Symbol");return k9(e)&&T9(e.prototype,A9(t))},j9=String,O9=function(t){try{return j9(t)}catch{return"Object"}},D9=En,R9=O9,L9=TypeError,Cw=function(t){if(D9(t))return t;throw new L9(R9(t)+" is not a function")},$9=Cw,F9=Sg,_w=function(t,e){var n=t[e];return F9(n)?void 0:$9(n)},gy=xs,my=En,yy=ma,N9=TypeError,z9=function(t,e){var n,r;if(e==="string"&&my(n=t.toString)&&!yy(r=gy(n,t))||my(n=t.valueOf)&&!yy(r=gy(n,t))||e!=="string"&&my(n=t.toString)&&!yy(r=gy(n,t)))return r;throw new N9("Can't convert object to primitive value")},ZT={exports:{}},DC=_n,B9=Object.defineProperty,Iw=function(t,e){try{B9(DC,t,{value:e,configurable:!0,writable:!0})}catch{DC[t]=e}return e},U9=_n,H9=Iw,RC="__core-js_shared__",LC=ZT.exports=U9[RC]||H9(RC,{});(LC.versions||(LC.versions=[])).push({version:"3.38.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.1/LICENSE",source:"https://github.com/zloirock/core-js"});var Ew=ZT.exports,$C=Ew,kw=function(t,e){return $C[t]||($C[t]=e||{})},K9=Kl,W9=Object,ed=function(t){return W9(K9(t))},G9=Lt,V9=ed,Y9=G9({}.hasOwnProperty),bi=Object.hasOwn||function(e,n){return Y9(V9(e),n)},X9=Lt,q9=0,Z9=Math.random(),Q9=X9(1 .toString),QT=function(t){return"Symbol("+(t===void 0?"":t)+")_"+Q9(++q9+Z9,36)},J9=_n,e7=kw,FC=bi,t7=QT,n7=YT,r7=XT,el=J9.Symbol,Sy=e7("wks"),o7=r7?el.for||el:el&&el.withoutSetter||t7,ws=function(t){return FC(Sy,t)||(Sy[t]=n7&&FC(el,t)?el[t]:o7("Symbol."+t)),Sy[t]},s7=xs,NC=ma,zC=qT,i7=_w,a7=z9,l7=ws,c7=TypeError,u7=l7("toPrimitive"),d7=function(t,e){if(!NC(t)||zC(t))return t;var n=i7(t,u7),r;if(n){if(e===void 0&&(e="default"),r=s7(n,t,e),!NC(r)||zC(r))return r;throw new c7("Can't convert object to primitive value")}return e===void 0&&(e="number"),a7(t,e)},h7=d7,p7=qT,JT=function(t){var e=h7(t,"string");return p7(e)?e:e+""},f7=_n,BC=ma,Gv=f7.document,g7=BC(Gv)&&BC(Gv.createElement),eM=function(t){return g7?Gv.createElement(t):{}},m7=wi,y7=In,S7=eM,tM=!m7&&!y7(function(){return Object.defineProperty(S7("div"),"a",{get:function(){return 7}}).a!==7}),v7=wi,x7=xs,w7=NT,b7=UT,P7=vg,C7=JT,_7=bi,I7=tM,UC=Object.getOwnPropertyDescriptor;Pw.f=v7?UC:function(e,n){if(e=P7(e),n=C7(n),I7)try{return UC(e,n)}catch{}if(_7(e,n))return b7(!x7(w7.f,e,n),e[n])};var Wl={},E7=wi,k7=In,nM=E7&&k7(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),T7=ma,M7=String,A7=TypeError,ya=function(t){if(T7(t))return t;throw new A7(M7(t)+" is not an object")},j7=wi,O7=tM,D7=nM,Jd=ya,HC=JT,R7=TypeError,vy=Object.defineProperty,L7=Object.getOwnPropertyDescriptor,xy="enumerable",wy="configurable",by="writable";Wl.f=j7?D7?function(e,n,r){if(Jd(e),n=HC(n),Jd(r),typeof e=="function"&&n==="prototype"&&"value"in r&&by in r&&!r[by]){var o=L7(e,n);o&&o[by]&&(e[n]=r.value,r={configurable:wy in r?r[wy]:o[wy],enumerable:xy in r?r[xy]:o[xy],writable:!1})}return vy(e,n,r)}:vy:function(e,n,r){if(Jd(e),n=HC(n),Jd(r),O7)try{return vy(e,n,r)}catch{}if("get"in r||"set"in r)throw new R7("Accessors not supported");return"value"in r&&(e[n]=r.value),e};var $7=wi,F7=Wl,N7=UT,Tw=$7?function(t,e,n){return F7.f(t,e,N7(1,n))}:function(t,e,n){return t[e]=n,t},rM={exports:{}},Vv=wi,z7=bi,oM=Function.prototype,B7=Vv&&Object.getOwnPropertyDescriptor,Mw=z7(oM,"name"),U7=Mw&&(function(){}).name==="something",H7=Mw&&(!Vv||Vv&&B7(oM,"name").configurable),K7={EXISTS:Mw,PROPER:U7,CONFIGURABLE:H7},W7=Lt,G7=En,Yv=Ew,V7=W7(Function.toString);G7(Yv.inspectSource)||(Yv.inspectSource=function(t){return V7(t)});var sM=Yv.inspectSource,Y7=_n,X7=En,KC=Y7.WeakMap,q7=X7(KC)&&/native code/.test(String(KC)),Z7=kw,Q7=QT,WC=Z7("keys"),iM=function(t){return WC[t]||(WC[t]=Q7(t))},Aw={},J7=q7,aM=_n,eU=ma,tU=Tw,Py=bi,Cy=Ew,nU=iM,rU=Aw,GC="Object already initialized",Xv=aM.TypeError,oU=aM.WeakMap,uf,Du,df,sU=function(t){return df(t)?Du(t):uf(t,{})},iU=function(t){return function(e){var n;if(!eU(e)||(n=Du(e)).type!==t)throw new Xv("Incompatible receiver, "+t+" required");return n}};if(J7||Cy.state){var fo=Cy.state||(Cy.state=new oU);fo.get=fo.get,fo.has=fo.has,fo.set=fo.set,uf=function(t,e){if(fo.has(t))throw new Xv(GC);return e.facade=t,fo.set(t,e),e},Du=function(t){return fo.get(t)||{}},df=function(t){return fo.has(t)}}else{var Ia=nU("state");rU[Ia]=!0,uf=function(t,e){if(Py(t,Ia))throw new Xv(GC);return e.facade=t,tU(t,Ia,e),e},Du=function(t){return Py(t,Ia)?t[Ia]:{}},df=function(t){return Py(t,Ia)}}var lM={set:uf,get:Du,has:df,enforce:sU,getterFor:iU},jw=Lt,aU=In,lU=En,eh=bi,qv=wi,cU=K7.CONFIGURABLE,uU=sM,cM=lM,dU=cM.enforce,hU=cM.get,VC=String,Qh=Object.defineProperty,pU=jw("".slice),fU=jw("".replace),gU=jw([].join),mU=qv&&!aU(function(){return Qh(function(){},"length",{value:8}).length!==8}),yU=String(String).split("String"),SU=rM.exports=function(t,e,n){pU(VC(e),0,7)==="Symbol("&&(e="["+fU(VC(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!eh(t,"name")||cU&&t.name!==e)&&(qv?Qh(t,"name",{value:e,configurable:!0}):t.name=e),mU&&n&&eh(n,"arity")&&t.length!==n.arity&&Qh(t,"length",{value:n.arity});try{n&&eh(n,"constructor")&&n.constructor?qv&&Qh(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch{}var r=dU(t);return eh(r,"source")||(r.source=gU(yU,typeof e=="string"?e:"")),t};Function.prototype.toString=SU(function(){return lU(this)&&hU(this).source||uU(this)},"toString");var vU=rM.exports,xU=En,wU=Wl,bU=vU,PU=Iw,uM=function(t,e,n,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:e;if(xU(n)&&bU(n,s,r),r.global)o?t[e]=n:PU(e,n);else{try{r.unsafe?t[e]&&(o=!0):delete t[e]}catch{}o?t[e]=n:wU.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},dM={},CU=Math.ceil,_U=Math.floor,IU=Math.trunc||function(e){var n=+e;return(n>0?_U:CU)(n)},EU=IU,Sa=function(t){var e=+t;return e!==e||e===0?0:EU(e)},kU=Sa,TU=Math.max,MU=Math.min,AU=function(t,e){var n=kU(t);return n<0?TU(n+e,0):MU(n,e)},jU=Sa,OU=Math.min,hM=function(t){var e=jU(t);return e>0?OU(e,9007199254740991):0},DU=hM,td=function(t){return DU(t.length)},RU=vg,LU=AU,$U=td,YC=function(t){return function(e,n,r){var o=RU(e),s=$U(o);if(s===0)return!t&&-1;var i=LU(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}},FU={includes:YC(!0),indexOf:YC(!1)},NU=Lt,_y=bi,zU=vg,BU=FU.indexOf,UU=Aw,XC=NU([].push),pM=function(t,e){var n=zU(t),r=0,o=[],s;for(s in n)!_y(UU,s)&&_y(n,s)&&XC(o,s);for(;e.length>r;)_y(n,s=e[r++])&&(~BU(o,s)||XC(o,s));return o},Ow=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],HU=pM,KU=Ow,WU=KU.concat("length","prototype");dM.f=Object.getOwnPropertyNames||function(e){return HU(e,WU)};var fM={};fM.f=Object.getOwnPropertySymbols;var GU=xg,VU=Lt,YU=dM,XU=fM,qU=ya,ZU=VU([].concat),QU=GU("Reflect","ownKeys")||function(e){var n=YU.f(qU(e)),r=XU.f;return r?ZU(n,r(e)):n},qC=bi,JU=QU,eH=Pw,tH=Wl,nH=function(t,e,n){for(var r=JU(e),o=tH.f,s=eH.f,i=0;i<r.length;i++){var a=r[i];!qC(t,a)&&!(n&&qC(n,a))&&o(t,a,s(e,a))}},rH=In,oH=En,sH=/#|\.prototype\./,nd=function(t,e){var n=aH[iH(t)];return n===cH?!0:n===lH?!1:oH(e)?rH(e):!!e},iH=nd.normalize=function(t){return String(t).replace(sH,".").toLowerCase()},aH=nd.data={},lH=nd.NATIVE="N",cH=nd.POLYFILL="P",uH=nd,th=_n,dH=Pw.f,hH=Tw,pH=uM,fH=Iw,gH=nH,mH=uH,Gl=function(t,e){var n=t.target,r=t.global,o=t.stat,s,i,a,l,c,u;if(r?i=th:o?i=th[n]||fH(n,{}):i=th[n]&&th[n].prototype,i)for(a in e){if(c=e[a],t.dontCallGetSet?(u=dH(i,a),l=u&&u.value):l=i[a],s=mH(r?a:n+(o?".":"#")+a,t.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;gH(c,l)}(t.sham||l&&l.sham)&&hH(c,"sham",!0),pH(i,a,c,t)}},gM={},yH=pM,SH=Ow,vH=Object.keys||function(e){return yH(e,SH)},xH=wi,wH=nM,bH=Wl,PH=ya,CH=vg,_H=vH;gM.f=xH&&!wH?Object.defineProperties:function(e,n){PH(e);for(var r=CH(n),o=_H(n),s=o.length,i=0,a;s>i;)bH.f(e,a=o[i++],r[a]);return e};var IH=xg,EH=IH("document","documentElement"),kH=ya,TH=gM,ZC=Ow,MH=Aw,AH=EH,jH=eM,OH=iM,QC=">",JC="<",Zv="prototype",Qv="script",mM=OH("IE_PROTO"),Iy=function(){},yM=function(t){return JC+Qv+QC+t+JC+"/"+Qv+QC},e_=function(t){t.write(yM("")),t.close();var e=t.parentWindow.Object;return t=null,e},DH=function(){var t=jH("iframe"),e="java"+Qv+":",n;return t.style.display="none",AH.appendChild(t),t.src=String(e),n=t.contentWindow.document,n.open(),n.write(yM("document.F=Object")),n.close(),n.F},nh,Jh=function(){try{nh=new ActiveXObject("htmlfile")}catch{}Jh=typeof document<"u"?document.domain&&nh?e_(nh):DH():e_(nh);for(var t=ZC.length;t--;)delete Jh[Zv][ZC[t]];return Jh()};MH[mM]=!0;var SM=Object.create||function(e,n){var r;return e!==null?(Iy[Zv]=kH(e),r=new Iy,Iy[Zv]=null,r[mM]=e):r=Jh(),n===void 0?r:TH.f(r,n)},RH=ws,LH=SM,$H=Wl.f,Jv=RH("unscopables"),e0=Array.prototype;e0[Jv]===void 0&&$H(e0,Jv,{configurable:!0,value:LH(null)});var Dw=function(t){e0[Jv][t]=!0},FH=Gl,NH=ed,zH=td,BH=Sa,UH=Dw;FH({target:"Array",proto:!0},{at:function(e){var n=NH(this),r=zH(n),o=BH(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:n[s]}});UH("at");var HH=_n,KH=Lt,rd=function(t,e){return KH(HH[t].prototype[e])},WH=rd;WH("Array","at");var GH=Hl,vM=Array.isArray||function(e){return GH(e)==="Array"},VH=TypeError,YH=9007199254740991,XH=function(t){if(t>YH)throw VH("Maximum allowed index exceeded");return t},qH=Hl,ZH=Lt,QH=function(t){if(qH(t)==="Function")return ZH(t)},t_=QH,JH=Cw,eK=yg,tK=t_(t_.bind),nK=function(t,e){return JH(t),e===void 0?t:eK?tK(t,e):function(){return t.apply(e,arguments)}},rK=vM,oK=td,sK=XH,iK=nK,xM=function(t,e,n,r,o,s,i,a){for(var l=o,c=0,u=i?iK(i,a):!1,h,p;c<r;)c in n&&(h=u?u(n[c],c,e):n[c],s>0&&rK(h)?(p=oK(h),l=xM(t,e,h,p,l,s-1)-1):(sK(l+1),t[l]=h),l++),c++;return l},wM=xM,aK=ws,lK=aK("toStringTag"),bM={};bM[lK]="z";var cK=String(bM)==="[object z]",uK=cK,dK=En,ep=Hl,hK=ws,pK=hK("toStringTag"),fK=Object,gK=ep(function(){return arguments}())==="Arguments",mK=function(t,e){try{return t[e]}catch{}},PM=uK?ep:function(t){var e,n,r;return t===void 0?"Undefined":t===null?"Null":typeof(n=mK(e=fK(t),pK))=="string"?n:gK?ep(e):(r=ep(e))==="Object"&&dK(e.callee)?"Arguments":r},yK=Lt,SK=In,CM=En,vK=PM,xK=xg,wK=sM,_M=function(){},IM=xK("Reflect","construct"),Rw=/^\s*(?:class|function)\b/,bK=yK(Rw.exec),PK=!Rw.test(_M),Sc=function(e){if(!CM(e))return!1;try{return IM(_M,[],e),!0}catch{return!1}},EM=function(e){if(!CM(e))return!1;switch(vK(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return PK||!!bK(Rw,wK(e))}catch{return!0}};EM.sham=!0;var CK=!IM||SK(function(){var t;return Sc(Sc.call)||!Sc(Object)||!Sc(function(){t=!0})||t})?EM:Sc,n_=vM,_K=CK,IK=ma,EK=ws,kK=EK("species"),r_=Array,TK=function(t){var e;return n_(t)&&(e=t.constructor,_K(e)&&(e===r_||n_(e.prototype))?e=void 0:IK(e)&&(e=e[kK],e===null&&(e=void 0))),e===void 0?r_:e},MK=TK,kM=function(t,e){return new(MK(t))(e===0?0:e)},AK=Gl,jK=wM,OK=Cw,DK=ed,RK=td,LK=kM;AK({target:"Array",proto:!0},{flatMap:function(e){var n=DK(this),r=RK(n),o;return OK(e),o=LK(n,0),o.length=jK(o,n,n,r,0,1,e,arguments.length>1?arguments[1]:void 0),o}});var $K=Dw;$K("flatMap");var FK=rd;FK("Array","flatMap");var NK=Gl,zK=wM,BK=ed,UK=td,HK=Sa,KK=kM;NK({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,n=BK(this),r=UK(n),o=KK(n,0);return o.length=zK(o,n,n,r,0,e===void 0?1:HK(e)),o}});var WK=Dw;WK("flat");var GK=rd;GK("Array","flat");var VK=PM,YK=String,od=function(t){if(VK(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return YK(t)},XK=Gl,qK=Lt,ZK=Kl,QK=Sa,JK=od,eW=In,tW=qK("".charAt),nW=eW(function(){return"𠮷".at(-2)!=="\uD842"});XK({target:"String",proto:!0,forced:nW},{at:function(e){var n=JK(ZK(this)),r=n.length,o=QK(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:tW(n,s)}});var rW=rd;rW("String","at");var oW=ya,TM=function(){var t=oW(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},Lw=In,sW=_n,$w=sW.RegExp,Fw=Lw(function(){var t=$w("a","y");return t.lastIndex=2,t.exec("abcd")!==null}),iW=Fw||Lw(function(){return!$w("a","y").sticky}),aW=Fw||Lw(function(){var t=$w("^r","gy");return t.lastIndex=2,t.exec("str")!==null}),lW={BROKEN_CARET:aW,MISSED_STICKY:iW,UNSUPPORTED_Y:Fw},cW=In,uW=_n,dW=uW.RegExp,hW=cW(function(){var t=dW(".","s");return!(t.dotAll&&t.test(`
|
|
68
|
-
`)&&t.flags==="s")}),pW=In,fW=_n,gW=fW.RegExp,mW=pW(function(){var t=gW("(?<a>b)","g");return t.exec("b").groups.a!=="b"||"b".replace(t,"$<a>c")!=="bc"}),tl=xs,wg=Lt,yW=od,SW=TM,vW=lW,xW=kw,wW=SM,bW=lM.get,PW=hW,CW=mW,_W=xW("native-string-replace",String.prototype.replace),hf=RegExp.prototype.exec,t0=hf,IW=wg("".charAt),EW=wg("".indexOf),kW=wg("".replace),Ey=wg("".slice),n0=function(){var t=/a/,e=/b*/g;return tl(hf,t,"a"),tl(hf,e,"a"),t.lastIndex!==0||e.lastIndex!==0}(),MM=vW.BROKEN_CARET,r0=/()??/.exec("")[1]!==void 0,TW=n0||r0||MM||PW||CW;TW&&(t0=function(e){var n=this,r=bW(n),o=yW(e),s=r.raw,i,a,l,c,u,h,p;if(s)return s.lastIndex=n.lastIndex,i=tl(t0,s,o),n.lastIndex=s.lastIndex,i;var f=r.groups,g=MM&&n.sticky,m=tl(SW,n),v=n.source,S=0,y=o;if(g&&(m=kW(m,"y",""),EW(m,"g")===-1&&(m+="g"),y=Ey(o,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&IW(o,n.lastIndex-1)!==`
|
|
69
|
-
`)&&(v="(?: "+v+")",y=" "+y,S++),a=new RegExp("^(?:"+v+")",m)),r0&&(a=new RegExp("^"+v+"$(?!\\s)",m)),n0&&(l=n.lastIndex),c=tl(hf,g?a:n,y),g?c?(c.input=Ey(c.input,S),c[0]=Ey(c[0],S),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:n0&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),r0&&c&&c.length>1&&tl(_W,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=wW(null),u=0;u<f.length;u++)p=f[u],h[p[0]]=c[p[1]];return c});var Nw=t0,MW=Gl,o_=Nw;MW({target:"RegExp",proto:!0,forced:/./.exec!==o_},{exec:o_});var AW=yg,AM=Function.prototype,s_=AM.apply,i_=AM.call,jW=typeof Reflect=="object"&&Reflect.apply||(AW?i_.bind(s_):function(){return i_.apply(s_,arguments)}),a_=xs,l_=uM,OW=Nw,c_=In,jM=ws,DW=Tw,RW=jM("species"),ky=RegExp.prototype,LW=function(t,e,n,r){var o=jM(t),s=!c_(function(){var c={};return c[o]=function(){return 7},""[t](c)!==7}),i=s&&!c_(function(){var c=!1,u=/a/;return t==="split"&&(u={},u.constructor={},u.constructor[RW]=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===OW||g===ky.exec?s&&!f?{done:!0,value:a_(a,u,h,p)}:{done:!0,value:a_(c,h,u,p)}:{done:!1}});l_(String.prototype,t,l[0]),l_(ky,o,l[1])}r&&DW(ky[o],"sham",!0)},zw=Lt,$W=Sa,FW=od,NW=Kl,zW=zw("".charAt),u_=zw("".charCodeAt),BW=zw("".slice),d_=function(t){return function(e,n){var r=FW(NW(e)),o=$W(n),s=r.length,i,a;return o<0||o>=s?t?"":void 0:(i=u_(r,o),i<55296||i>56319||o+1===s||(a=u_(r,o+1))<56320||a>57343?t?zW(r,o):i:t?BW(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},UW={codeAt:d_(!1),charAt:d_(!0)},HW=UW.charAt,KW=function(t,e,n){return e+(n?HW(t,e).length:1)},Bw=Lt,WW=ed,GW=Math.floor,Ty=Bw("".charAt),VW=Bw("".replace),My=Bw("".slice),YW=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,XW=/\$([$&'`]|\d{1,2})/g,OM=function(t,e,n,r,o,s){var i=n+t.length,a=r.length,l=XW;return o!==void 0&&(o=WW(o),l=YW),VW(s,l,function(c,u){var h;switch(Ty(u,0)){case"$":return"$";case"&":return t;case"`":return My(e,0,n);case"'":return My(e,i);case"<":h=o[My(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=GW(p/10);return f===0?c:f<=a?r[f-1]===void 0?Ty(u,1):r[f-1]+Ty(u,1):c}h=r[p-1]}return h===void 0?"":h})},h_=xs,qW=ya,ZW=En,QW=Hl,JW=Nw,eG=TypeError,tG=function(t,e){var n=t.exec;if(ZW(n)){var r=h_(n,t,e);return r!==null&&qW(r),r}if(QW(t)==="RegExp")return h_(JW,t,e);throw new eG("RegExp#exec called on incompatible receiver")},nG=jW,p_=xs,bg=Lt,rG=LW,oG=In,sG=ya,iG=En,aG=Sg,lG=Sa,cG=hM,Ea=od,uG=Kl,dG=KW,hG=_w,pG=OM,fG=tG,gG=ws,o0=gG("replace"),mG=Math.max,yG=Math.min,SG=bg([].concat),Ay=bg([].push),f_=bg("".indexOf),g_=bg("".slice),vG=function(t){return t===void 0?t:String(t)},xG=function(){return"a".replace(/./,"$0")==="$0"}(),m_=function(){return/./[o0]?/./[o0]("a","$0")==="":!1}(),wG=!oG(function(){var t=/./;return t.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(t,"$<a>")!=="7"});rG("replace",function(t,e,n){var r=m_?"$":"$0";return[function(s,i){var a=uG(this),l=aG(s)?void 0:hG(s,o0);return l?p_(l,s,a,i):p_(e,Ea(a),s,i)},function(o,s){var i=sG(this),a=Ea(o);if(typeof s=="string"&&f_(s,r)===-1&&f_(s,"$<")===-1){var l=n(e,i,a,s);if(l.done)return l.value}var c=iG(s);c||(s=Ea(s));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=fG(i,a),!(f===null||(Ay(p,f),!u));){var g=Ea(f[0]);g===""&&(i.lastIndex=dG(a,cG(i.lastIndex),h))}for(var m="",v=0,S=0;S<p.length;S++){f=p[S];for(var y=Ea(f[0]),b=mG(yG(lG(f.index),a.length),0),P=[],C,I=1;I<f.length;I++)Ay(P,vG(f[I]));var k=f.groups;if(c){var _=SG([y],P,b,a);k!==void 0&&Ay(_,k),C=Ea(nG(s,void 0,_))}else C=pG(y,a,b,P,k,s);b>=v&&(m+=g_(a,v,b)+C,v=b+y.length)}return m+g_(a,v)}]},!wG||!xG||m_);var bG=ma,PG=Hl,CG=ws,_G=CG("match"),IG=function(t){var e;return bG(t)&&((e=t[_G])!==void 0?!!e:PG(t)==="RegExp")},EG=xs,kG=bi,TG=GT,MG=TM,y_=RegExp.prototype,AG=function(t){var e=t.flags;return e===void 0&&!("flags"in y_)&&!kG(t,"flags")&&TG(y_,t)?EG(MG,t):e},jG=Gl,OG=xs,Uw=Lt,S_=Kl,DG=En,RG=Sg,LG=IG,vc=od,$G=_w,FG=AG,NG=OM,zG=ws,BG=zG("replace"),UG=TypeError,jy=Uw("".indexOf);Uw("".replace);var v_=Uw("".slice),HG=Math.max;jG({target:"String",proto:!0},{replaceAll:function(e,n){var r=S_(this),o,s,i,a,l,c,u,h,p,f,g=0,m="";if(!RG(e)){if(o=LG(e),o&&(s=vc(S_(FG(e))),!~jy(s,"g")))throw new UG("`.replaceAll` does not allow non-global regexes");if(i=$G(e,BG),i)return OG(i,e,r,n)}for(a=vc(r),l=vc(e),c=DG(n),c||(n=vc(n)),u=l.length,h=HG(1,u),p=jy(a,l);p!==-1;)f=c?vc(n(l,p,a)):NG(l,a,p,[],void 0,n),m+=v_(a,g,p)+f,g=p+u,p=p+h>a.length?-1:jy(a,l,p+h);return g<a.length&&(m+=v_(a,g)),m}});var KG=rd;KG("String","replaceAll");function DM(t){return t&&typeof t=="object"&&"parents"in t}function RM(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 pf(t,e){if(t.children.remove(e)&&t.children.isEmpty&&DM(t))for(let n=0,r=t.parents.length;n<r;n++)pf(t.parents[n],t)}function Hw(t,e){if(t.children.add(e)&&DM(t))for(let n=0,r=t.parents.length;n<r;n++)Hw(t.parents[n],t)}function LM(t,e){return t===e||Object.is(t,e)||!!(t&&e&&typeof t.equals=="function"&&t.equals(e))}function Pi(t,e){const n=Symbol.for(`com.tldraw.state/${t}`),r=globalThis;return r[n]??(r[n]=e()),r[n]}const ss=Pi("empty_array",()=>Object.freeze([])),x_=8;class ff{constructor(){E(this,"arraySize",0);E(this,"array",Array(x_));E(this,"set",null)}get isEmpty(){if(this.array)return this.arraySize===0;if(this.set)return this.set.size===0;throw new Error("no set or array")}add(e){if(this.array)return this.array.indexOf(e)!==-1?!1:this.arraySize<x_?(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 $M{constructor(e){E(this,"index",0);E(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,n,r){if(r!==void 0){if(r===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 WG{constructor(e,n){E(this,"offset",0);E(this,"maybeRemoved");this.below=e,this.child=n}}const it=Pi("capture",()=>({stack:null}));function rh(t){const e=it.stack;it.stack=null;try{return t()}finally{it.stack=e}}function FM(t){it.stack=new WG(it.stack,t),t.parentSet.clear()}function NM(){const t=it.stack;if(it.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)||pf(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)||pf(n,t.child)}}function gf(t){if(it.stack){if(it.stack.child.parentSet.has(t))return;if(it.stack.child.parentSet.add(t),it.stack.child.isActivelyListening&&Hw(t,it.stack.child),it.stack.offset<it.stack.child.parents.length){const n=it.stack.child.parents[it.stack.offset];n!==t&&(it.stack.maybeRemoved?it.stack.maybeRemoved.push(n):it.stack.maybeRemoved=[n])}it.stack.child.parents[it.stack.offset]=t,it.stack.child.parentEpochs[it.stack.offset]=t.lastChangedEpoch,it.stack.offset++}}const Gs=-1;class GG{constructor(e,n,r){E(this,"_isActivelyListening",!1);E(this,"lastTraversedEpoch",Gs);E(this,"lastReactedEpoch",Gs);E(this,"_scheduleCount",0);E(this,"parentSet",new ff);E(this,"parentEpochs",[]);E(this,"parents",[]);E(this,"_scheduleEffect");E(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=e,this.runEffect=n,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==Ln()){if(this.parents.length&&!RM(this)){this.lastReactedEpoch=Ln();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++)Hw(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,n=this.parents.length;e<n;e++)pf(this.parents[e],this)}execute(){try{FM(this);const e=Ln(),n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,n}finally{NM()}}}const Vl=Pi("EffectScheduler",()=>GG);function is(t,e,n){const r=new Vl(t,e,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function VG(t,e,n){const r=new Vl(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 YG{constructor(e){E(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(Re.globalIsReacting)for(const e of this.initialAtomValues.keys())BM(e);else this.isRoot?zM(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=Pi("transactions",()=>({globalEpoch:Gs+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:Gs+1}));function XG(){return Re.reactionEpoch}function Ln(){return Re.globalEpoch}function qG(){return Re.globalIsReacting}function Kw(t,e){e.lastTraversedEpoch!==Re.globalEpoch&&(e.lastTraversedEpoch=Re.globalEpoch,e instanceof Vl?t.add(e):e.children.visit(n=>Kw(t,n)))}function zM(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=>Kw(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 ZG(t,e){Re.currentTransaction?Re.currentTransaction.initialAtomValues.has(t)||Re.currentTransaction.initialAtomValues.set(t,e):Re.globalIsReacting?BM(t):zM([t])}function BM(t){const e=Re.cleanupReactors??(Re.cleanupReactors=new Set);t.children.visit(n=>Kw(e,n))}function QG(){Re.globalEpoch++}function JG(t){const e=new YG(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 Eo(t){return Re.currentTransaction?t():JG(t)}class eV{constructor(e,n,r){E(this,"isEqual");E(this,"computeDiff");E(this,"lastChangedEpoch",Ln());E(this,"children",new ff);E(this,"historyBuffer");this.name=e,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new $M(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return gf(this),this.current}set(e,n){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,e))??LM(this.current,e))return this.current;QG(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Ln(),n??((s=this.computeDiff)==null?void 0:s.call(this,this.current,e,this.lastChangedEpoch,Ln()))??ur),this.lastChangedEpoch=Ln();const r=this.current;return this.current=e,ZG(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var n;return gf(this),e>=this.lastChangedEpoch?ss:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const tV=Pi("Atom",()=>eV);function It(t,e,n){return new tV(t,e,n)}let w_=!1;function nV(){w_||(w_=!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 zc=Symbol.for("com.tldraw.state/UNINITIALIZED");function Vi(t){return t===zc}const s0=Pi("WithDiff",()=>class{constructor(e,n){this.value=e,this.diff=n}});function Bc(t,e){return new s0(t,e)}class rV{constructor(e,n,r){E(this,"lastChangedEpoch",Gs);E(this,"lastTraversedEpoch",Gs);E(this,"lastCheckedEpoch",Gs);E(this,"parentSet",new ff);E(this,"parents",[]);E(this,"parentEpochs",[]);E(this,"children",new ff);E(this,"historyBuffer");E(this,"state",zc);E(this,"error",null);E(this,"computeDiff");E(this,"isEqual");this.name=e,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new $M(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??LM}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var o;const n=this.lastChangedEpoch===Gs,r=Ln();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&qG()&&this.lastTraversedEpoch<XG()||!RM(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{FM(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof s0?s.value:s,a=this.state===zc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=s instanceof s0?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Ln(),l??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,Ln()))??ur)}this.lastChangedEpoch=Ln(),this.state=i}return this.error=null,this.lastCheckedEpoch=Ln(),this.state}catch(s){if(this.state!==zc&&(this.state=zc,this.lastChangedEpoch=Ln()),this.lastCheckedEpoch=Ln(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!e)throw s;return this.state}finally{NM()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{gf(this)}}getDiffSince(e){var n;return this.__unsafe__getWithoutCapture(!0),gf(this),e>=this.lastChangedEpoch?ss:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const Pg=Pi("Computed",()=>rV);function oV(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 Pg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[UM]=!0,r}function sV(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 Pg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function iV(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 Pg(String(n.name),e.bind(this),t),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:s})),s.get()};return o[UM]=!0,o}function b_(t={},e){if(e.length===2){const[n,r]=e;return iV(t,n,r)}else{const[n,r,o]=e;return o.get?(nV(),sV(t,n,r,o)):oV(t,n,r,o)}}const UM="@@__isComputedMethod__@@";function W(){if(arguments.length===1){const t=arguments[0];return(...e)=>b_(t,e)}else return typeof arguments[0]=="string"?new Pg(arguments[0],arguments[1],arguments[2]):b_(void 0,arguments)}const HM=1,aV=Pi("apiVersion",()=>HM);if(aV!==HM)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");xi("@tldraw/state","3.3.0","esm");function Cg(t,e){const n=Te.useRef(e);n.current=e;const[r,o,s]=Te.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),l=new Vl(`useStateTracking(${t})`,()=>{var u;return(u=n.current)==null?void 0:u.call(n)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[t]);return Te.useSyncExternalStore(o,s,s),Te.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const P_={apply(t,e,n){return Cg(t.displayName??t.name??"tracked(???)",()=>t.apply(e,n))}},lV=Symbol.for("react.memo"),cV=Symbol.for("react.forward_ref");function $t(t){let e=null;const n=t.$$typeof;return n===lV&&(t=t.type,e=t.compare),n===cV?w.memo(w.forwardRef(new Proxy(t.render,P_))):w.memo(new Proxy(t,P_),e)}function KM(t,e,n){return w.useState(()=>{const r=typeof e=="function"?e():e;return It(`useAtom(${t})`,r,n)})[0]}function uV(){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(()=>W(`useComputed(${t})`,e,n),r)}function ni(t,e,n=ss){w.useEffect(()=>{const r=new Vl(t,e);return r.attach(),r.execute(),()=>{r.detach()}},n)}function H(){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]:W(n,()=>{if(r.current)return t[1]();try{return t[1]()}catch{return{}}}),e);try{const{subscribe:s,getSnapshot:i}=w.useMemo(()=>({subscribe:a=>is(`useValue(${n})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return w.useSyncExternalStore(s,i,i)}finally{r.current=!1}}xi("@tldraw/state-react","3.3.0","esm");class tp{constructor(e){E(this,"nextValue");E(this,"diff");this.previousValue=e}get(){var r,o,s,i;const e=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,n=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(e===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(e,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(e),this.diff??(this.diff={}),n?(r=this.diff.removed)==null||r.delete(e):((o=this.diff).added??(o.added=new Set),this.diff.added.add(e))}add(e){var o,s,i;const n=this.previousValue.has(e);if(n)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(e))?this._add(e,n):void 0;(i=this.nextValue)!=null&&i.has(e)||this._add(e,n)}_remove(e,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(e),this.diff??(this.diff={}),n?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(e)):(o=this.diff.added)==null||o.delete(e)}remove(e){var o,s,i,a;const n=this.previousValue.has(e);if(!n)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(e))?this._remove(e,n):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(e)||this._remove(e,n)}}class _g{constructor(e,n){E(this,"createDefaultProperties");E(this,"validator");E(this,"ephemeralKeys");E(this,"ephemeralKeySet");E(this,"scope");this.typeName=e,this.createDefaultProperties=n.createDefaultProperties,this.validator=n.validator??{validate:o=>o},this.scope=n.scope??"document",this.ephemeralKeys=n.ephemeralKeys;const r=new Set;if(n.ephemeralKeys)for(const[o,s]of 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{...nt(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 _g(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 Ro(t,e){return new _g(t,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function mf(){return{added:{},updated:{},removed:{}}}function i0(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 WM(t){return Object.keys(t.added).length===0&&Object.keys(t.updated).length===0&&Object.keys(t.removed).length===0}function Ww(t){const e={added:{},removed:{},updated:{}};return su(e,t),e}function su(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 yf={exports:{}};yf.exports;(function(t,e){var n=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",p="[object Error]",f="[object Function]",g="[object GeneratorFunction]",m="[object Map]",v="[object Number]",S="[object Null]",y="[object Object]",b="[object Promise]",P="[object Proxy]",C="[object RegExp]",I="[object Set]",k="[object String]",_="[object Symbol]",T="[object Undefined]",M="[object WeakMap]",D="[object ArrayBuffer]",j="[object DataView]",O="[object Float32Array]",R="[object Float64Array]",B="[object Int8Array]",L="[object Int16Array]",G="[object Int32Array]",$="[object Uint8Array]",U="[object Uint8ClampedArray]",Y="[object Uint16Array]",te="[object Uint32Array]",de=/[\\^$.*+?()[\]{}|]/g,he=/^\[object .+?Constructor\]$/,ke=/^(?:0|[1-9]\d*)$/,se={};se[O]=se[R]=se[B]=se[L]=se[G]=se[$]=se[U]=se[Y]=se[te]=!0,se[a]=se[l]=se[D]=se[u]=se[j]=se[h]=se[p]=se[f]=se[m]=se[v]=se[y]=se[C]=se[I]=se[k]=se[M]=!1;var We=typeof dn=="object"&&dn&&dn.Object===Object&&dn,Fe=typeof self=="object"&&self&&self.Object===Object&&self,st=We||Fe||Function("return this")(),$e=e&&!e.nodeType&&e,lt=$e&&!0&&t&&!t.nodeType&&t,He=lt&<.exports===$e,er=He&&We.process,Ft=function(){try{return er&&er.binding&&er.binding("util")}catch{}}(),jn=Ft&&Ft.isTypedArray;function vt(A,F){for(var V=-1,ne=A==null?0:A.length,Je=0,Se=[];++V<ne;){var mt=A[V];F(mt,V,A)&&(Se[Je++]=mt)}return Se}function Jt(A,F){for(var V=-1,ne=F.length,Je=A.length;++V<ne;)A[Je+V]=F[V];return A}function zo(A,F){for(var V=-1,ne=A==null?0:A.length;++V<ne;)if(F(A[V],V,A))return!0;return!1}function rc(A,F){for(var V=-1,ne=Array(A);++V<A;)ne[V]=F(V);return ne}function Is(A){return function(F){return A(F)}}function pN(A,F){return A.has(F)}function fN(A,F){return A==null?void 0:A[F]}function gN(A){var F=-1,V=Array(A.size);return A.forEach(function(ne,Je){V[++F]=[Je,ne]}),V}function mN(A,F){return function(V){return A(F(V))}}function yN(A){var F=-1,V=Array(A.size);return A.forEach(function(ne){V[++F]=ne}),V}var SN=Array.prototype,vN=Function.prototype,Ed=Object.prototype,Cm=st["__core-js_shared__"],Nb=vN.toString,ho=Ed.hasOwnProperty,zb=function(){var A=/[^.]+$/.exec(Cm&&Cm.keys&&Cm.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),Bb=Ed.toString,xN=RegExp("^"+Nb.call(ho).replace(de,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ub=He?st.Buffer:void 0,kd=st.Symbol,Hb=st.Uint8Array,Kb=Ed.propertyIsEnumerable,wN=SN.splice,Mi=kd?kd.toStringTag:void 0,Wb=Object.getOwnPropertySymbols,bN=Ub?Ub.isBuffer:void 0,PN=mN(Object.keys,Object),_m=Ca(st,"DataView"),oc=Ca(st,"Map"),Im=Ca(st,"Promise"),Em=Ca(st,"Set"),km=Ca(st,"WeakMap"),sc=Ca(Object,"create"),CN=Oi(_m),_N=Oi(oc),IN=Oi(Im),EN=Oi(Em),kN=Oi(km),Gb=kd?kd.prototype:void 0,Tm=Gb?Gb.valueOf:void 0;function Ai(A){var F=-1,V=A==null?0:A.length;for(this.clear();++F<V;){var ne=A[F];this.set(ne[0],ne[1])}}function TN(){this.__data__=sc?sc(null):{},this.size=0}function MN(A){var F=this.has(A)&&delete this.__data__[A];return this.size-=F?1:0,F}function AN(A){var F=this.__data__;if(sc){var V=F[A];return V===r?void 0:V}return ho.call(F,A)?F[A]:void 0}function jN(A){var F=this.__data__;return sc?F[A]!==void 0:ho.call(F,A)}function ON(A,F){var V=this.__data__;return this.size+=this.has(A)?0:1,V[A]=sc&&F===void 0?r:F,this}Ai.prototype.clear=TN,Ai.prototype.delete=MN,Ai.prototype.get=AN,Ai.prototype.has=jN,Ai.prototype.set=ON;function Bo(A){var F=-1,V=A==null?0:A.length;for(this.clear();++F<V;){var ne=A[F];this.set(ne[0],ne[1])}}function DN(){this.__data__=[],this.size=0}function RN(A){var F=this.__data__,V=Md(F,A);if(V<0)return!1;var ne=F.length-1;return V==ne?F.pop():wN.call(F,V,1),--this.size,!0}function LN(A){var F=this.__data__,V=Md(F,A);return V<0?void 0:F[V][1]}function $N(A){return Md(this.__data__,A)>-1}function FN(A,F){var V=this.__data__,ne=Md(V,A);return ne<0?(++this.size,V.push([A,F])):V[ne][1]=F,this}Bo.prototype.clear=DN,Bo.prototype.delete=RN,Bo.prototype.get=LN,Bo.prototype.has=$N,Bo.prototype.set=FN;function ji(A){var F=-1,V=A==null?0:A.length;for(this.clear();++F<V;){var ne=A[F];this.set(ne[0],ne[1])}}function NN(){this.size=0,this.__data__={hash:new Ai,map:new(oc||Bo),string:new Ai}}function zN(A){var F=Ad(this,A).delete(A);return this.size-=F?1:0,F}function BN(A){return Ad(this,A).get(A)}function UN(A){return Ad(this,A).has(A)}function HN(A,F){var V=Ad(this,A),ne=V.size;return V.set(A,F),this.size+=V.size==ne?0:1,this}ji.prototype.clear=NN,ji.prototype.delete=zN,ji.prototype.get=BN,ji.prototype.has=UN,ji.prototype.set=HN;function Td(A){var F=-1,V=A==null?0:A.length;for(this.__data__=new ji;++F<V;)this.add(A[F])}function KN(A){return this.__data__.set(A,r),this}function WN(A){return this.__data__.has(A)}Td.prototype.add=Td.prototype.push=KN,Td.prototype.has=WN;function Es(A){var F=this.__data__=new Bo(A);this.size=F.size}function GN(){this.__data__=new Bo,this.size=0}function VN(A){var F=this.__data__,V=F.delete(A);return this.size=F.size,V}function YN(A){return this.__data__.get(A)}function XN(A){return this.__data__.has(A)}function qN(A,F){var V=this.__data__;if(V instanceof Bo){var ne=V.__data__;if(!oc||ne.length<n-1)return ne.push([A,F]),this.size=++V.size,this;V=this.__data__=new ji(ne)}return V.set(A,F),this.size=V.size,this}Es.prototype.clear=GN,Es.prototype.delete=VN,Es.prototype.get=YN,Es.prototype.has=XN,Es.prototype.set=qN;function ZN(A,F){var V=jd(A),ne=!V&&h4(A),Je=!V&&!ne&&Mm(A),Se=!V&&!ne&&!Je&&tP(A),mt=V||ne||Je||Se,At=mt?rc(A.length,String):[],Nt=At.length;for(var ct in A)ho.call(A,ct)&&!(mt&&(ct=="length"||Je&&(ct=="offset"||ct=="parent")||Se&&(ct=="buffer"||ct=="byteLength"||ct=="byteOffset")||a4(ct,Nt)))&&At.push(ct);return At}function Md(A,F){for(var V=A.length;V--;)if(Zb(A[V][0],F))return V;return-1}function QN(A,F,V){var ne=F(A);return jd(A)?ne:Jt(ne,V(A))}function ic(A){return A==null?A===void 0?T:S:Mi&&Mi in Object(A)?s4(A):d4(A)}function Vb(A){return ac(A)&&ic(A)==a}function Yb(A,F,V,ne,Je){return A===F?!0:A==null||F==null||!ac(A)&&!ac(F)?A!==A&&F!==F:JN(A,F,V,ne,Yb,Je)}function JN(A,F,V,ne,Je,Se){var mt=jd(A),At=jd(F),Nt=mt?l:ks(A),ct=At?l:ks(F);Nt=Nt==a?y:Nt,ct=ct==a?y:ct;var tr=Nt==y,zr=ct==y,en=Nt==ct;if(en&&Mm(A)){if(!Mm(F))return!1;mt=!0,tr=!1}if(en&&!tr)return Se||(Se=new Es),mt||tP(A)?Xb(A,F,V,ne,Je,Se):r4(A,F,Nt,V,ne,Je,Se);if(!(V&o)){var br=tr&&ho.call(A,"__wrapped__"),Pr=zr&&ho.call(F,"__wrapped__");if(br||Pr){var Ts=br?A.value():A,Uo=Pr?F.value():F;return Se||(Se=new Es),Je(Ts,Uo,V,ne,Se)}}return en?(Se||(Se=new Es),o4(A,F,V,ne,Je,Se)):!1}function e4(A){if(!eP(A)||c4(A))return!1;var F=Qb(A)?xN:he;return F.test(Oi(A))}function t4(A){return ac(A)&&Jb(A.length)&&!!se[ic(A)]}function n4(A){if(!u4(A))return PN(A);var F=[];for(var V in Object(A))ho.call(A,V)&&V!="constructor"&&F.push(V);return F}function Xb(A,F,V,ne,Je,Se){var mt=V&o,At=A.length,Nt=F.length;if(At!=Nt&&!(mt&&Nt>At))return!1;var ct=Se.get(A);if(ct&&Se.get(F))return ct==F;var tr=-1,zr=!0,en=V&s?new Td:void 0;for(Se.set(A,F),Se.set(F,A);++tr<At;){var br=A[tr],Pr=F[tr];if(ne)var Ts=mt?ne(Pr,br,tr,F,A,Se):ne(br,Pr,tr,A,F,Se);if(Ts!==void 0){if(Ts)continue;zr=!1;break}if(en){if(!zo(F,function(Uo,Di){if(!pN(en,Di)&&(br===Uo||Je(br,Uo,V,ne,Se)))return en.push(Di)})){zr=!1;break}}else if(!(br===Pr||Je(br,Pr,V,ne,Se))){zr=!1;break}}return Se.delete(A),Se.delete(F),zr}function r4(A,F,V,ne,Je,Se,mt){switch(V){case j:if(A.byteLength!=F.byteLength||A.byteOffset!=F.byteOffset)return!1;A=A.buffer,F=F.buffer;case D:return!(A.byteLength!=F.byteLength||!Se(new Hb(A),new Hb(F)));case u:case h:case v:return Zb(+A,+F);case p:return A.name==F.name&&A.message==F.message;case C:case k:return A==F+"";case m:var At=gN;case I:var Nt=ne&o;if(At||(At=yN),A.size!=F.size&&!Nt)return!1;var ct=mt.get(A);if(ct)return ct==F;ne|=s,mt.set(A,F);var tr=Xb(At(A),At(F),ne,Je,Se,mt);return mt.delete(A),tr;case _:if(Tm)return Tm.call(A)==Tm.call(F)}return!1}function o4(A,F,V,ne,Je,Se){var mt=V&o,At=qb(A),Nt=At.length,ct=qb(F),tr=ct.length;if(Nt!=tr&&!mt)return!1;for(var zr=Nt;zr--;){var en=At[zr];if(!(mt?en in F:ho.call(F,en)))return!1}var br=Se.get(A);if(br&&Se.get(F))return br==F;var Pr=!0;Se.set(A,F),Se.set(F,A);for(var Ts=mt;++zr<Nt;){en=At[zr];var Uo=A[en],Di=F[en];if(ne)var nP=mt?ne(Di,Uo,en,F,A,Se):ne(Uo,Di,en,A,F,Se);if(!(nP===void 0?Uo===Di||Je(Uo,Di,V,ne,Se):nP)){Pr=!1;break}Ts||(Ts=en=="constructor")}if(Pr&&!Ts){var Od=A.constructor,Dd=F.constructor;Od!=Dd&&"constructor"in A&&"constructor"in F&&!(typeof Od=="function"&&Od instanceof Od&&typeof Dd=="function"&&Dd instanceof Dd)&&(Pr=!1)}return Se.delete(A),Se.delete(F),Pr}function qb(A){return QN(A,g4,i4)}function Ad(A,F){var V=A.__data__;return l4(F)?V[typeof F=="string"?"string":"hash"]:V.map}function Ca(A,F){var V=fN(A,F);return e4(V)?V:void 0}function s4(A){var F=ho.call(A,Mi),V=A[Mi];try{A[Mi]=void 0;var ne=!0}catch{}var Je=Bb.call(A);return ne&&(F?A[Mi]=V:delete A[Mi]),Je}var i4=Wb?function(A){return A==null?[]:(A=Object(A),vt(Wb(A),function(F){return Kb.call(A,F)}))}:m4,ks=ic;(_m&&ks(new _m(new ArrayBuffer(1)))!=j||oc&&ks(new oc)!=m||Im&&ks(Im.resolve())!=b||Em&&ks(new Em)!=I||km&&ks(new km)!=M)&&(ks=function(A){var F=ic(A),V=F==y?A.constructor:void 0,ne=V?Oi(V):"";if(ne)switch(ne){case CN:return j;case _N:return m;case IN:return b;case EN:return I;case kN:return M}return F});function a4(A,F){return F=F??i,!!F&&(typeof A=="number"||ke.test(A))&&A>-1&&A%1==0&&A<F}function l4(A){var F=typeof A;return F=="string"||F=="number"||F=="symbol"||F=="boolean"?A!=="__proto__":A===null}function c4(A){return!!zb&&zb in A}function u4(A){var F=A&&A.constructor,V=typeof F=="function"&&F.prototype||Ed;return A===V}function d4(A){return Bb.call(A)}function Oi(A){if(A!=null){try{return Nb.call(A)}catch{}try{return A+""}catch{}}return""}function Zb(A,F){return A===F||A!==A&&F!==F}var h4=Vb(function(){return arguments}())?Vb:function(A){return ac(A)&&ho.call(A,"callee")&&!Kb.call(A,"callee")},jd=Array.isArray;function p4(A){return A!=null&&Jb(A.length)&&!Qb(A)}var Mm=bN||y4;function f4(A,F){return Yb(A,F)}function Qb(A){if(!eP(A))return!1;var F=ic(A);return F==f||F==g||F==c||F==P}function Jb(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function eP(A){var F=typeof A;return A!=null&&(F=="object"||F=="function")}function ac(A){return A!=null&&typeof A=="object"}var tP=jn?Is(jn):t4;function g4(A){return p4(A)?ZN(A):n4(A)}function m4(){return[]}function y4(){return!1}t.exports=f4})(yf,yf.exports);var dV=yf.exports;const hV=mi(dV);function pV(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 fV(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 C_(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 __(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 pV(Object.values(r))}class gV{constructor(e,n){E(this,"indexCache",new Map);E(this,"historyCache",new Map);this.atoms=e,this.history=n}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const n=W("filterHistory:"+e,(r,o)=>{if(Vi(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?Bc(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 W("index:"+e+":"+n,(s,i)=>{if(Vi(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 tp(s.get(f)??new Set)),m.add(g),l.set(f,m)},u=(f,g)=>{let m=l.get(f);m||(m=new tp(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],S=m[n];v!==S&&(u(v,m.id),c(S,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?Bc(h,p):s},{historyLength:100})}record(e,n=()=>({}),r="record:"+e+(n?":"+n.toString():"")){const o=this.ids(e,n,r);return W(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 W(r,()=>[...o.get()].map(s=>{const i=this.atoms.get()[s];if(!i)throw new Error("no atom found for record id: "+s);return i.get()}))}ids(e,n=()=>({}),r="ids:"+e+(n?":"+n.toString():"")){const o=this.filterHistory(e),s=()=>{o.get();const l=n();return Object.keys(l).length===0?new Set(ut(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===e?u.id:[]})):__(this,e,l)},i=l=>{const c=s(),u=fV(l,c);return u?Bc(c,u):l},a=W("ids_query:"+r,n,{isEqual:hV});return W("query:"+r,(l,c)=>{const u=a.get();if(Vi(l))return s();if(c<a.lastChangedEpoch)return i(l);const h=o.getDiffSince(c);if(h===ur)return i(l);const p=new tp(l);for(const g of h){for(const m of ut(g.added))m.typeName===e&&C_(u,m)&&p.add(m.id);for(const[m,v]of ut(g.updated))v.typeName===e&&(C_(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?Bc(f.value,f.diff):l},{historyLength:50})}exec(e,n){const r=__(this,e,n);if(r.size===0)return ss;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class mV{constructor(e){E(this,"_beforeCreateHandlers",{});E(this,"_afterCreateHandlers",{});E(this,"_beforeChangeHandlers",{});E(this,"_afterChangeHandlers",{});E(this,"_beforeDeleteHandlers",{});E(this,"_afterDeleteHandlers",{});E(this,"_operationCompleteHandlers",[]);E(this,"_isEnabled",!0);this.store=e}isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,n){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let o=e;for(const s of r)o=s(o,n);return o}return e}handleAfterCreate(e,n){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const o of r)o(e,n)}handleBeforeChange(e,n,r){if(!this._isEnabled)return n;const o=this._beforeChangeHandlers[n.typeName];if(o){let s=n;for(const i of o)s=i(e,s,r);return s}return n}handleAfterChange(e,n,r){if(!this._isEnabled)return;const o=this._afterChangeHandlers[n.typeName];if(o)for(const s of o)s(e,n,r)}handleBeforeDelete(e,n){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const o of r)if(o(e,n)===!1)return!1}return!0}handleAfterDelete(e,n){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const o of r)o(e,n)}handleOperationComplete(e){if(this._isEnabled)for(const n of this._operationCompleteHandlers)n(e)}register(e){const n=[];for(const[r,o]of Object.entries(e))o!=null&&o.beforeCreate&&n.push(this.registerBeforeCreateHandler(r,o.beforeCreate)),o!=null&&o.afterCreate&&n.push(this.registerAfterCreateHandler(r,o.afterCreate)),o!=null&&o.beforeChange&&n.push(this.registerBeforeChangeHandler(r,o.beforeChange)),o!=null&&o.afterChange&&n.push(this.registerAfterChangeHandler(r,o.afterChange)),o!=null&&o.beforeDelete&&n.push(this.registerBeforeDeleteHandler(r,o.beforeDelete)),o!=null&&o.afterDelete&&n.push(this.registerAfterDeleteHandler(r,o.afterDelete));return()=>{for(const r of n)r()}}registerBeforeCreateHandler(e,n){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(n),()=>Ri(this._beforeCreateHandlers[e],n)}registerAfterCreateHandler(e,n){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(n),()=>Ri(this._afterCreateHandlers[e],n)}registerBeforeChangeHandler(e,n){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(n),()=>Ri(this._beforeChangeHandlers[e],n)}registerAfterChangeHandler(e,n){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(n),()=>Ri(this._afterChangeHandlers[e],n)}registerBeforeDeleteHandler(e,n){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(n),()=>Ri(this._beforeDeleteHandlers[e],n)}registerAfterDeleteHandler(e,n){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(n),()=>Ri(this._afterDeleteHandlers[e],n)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Ri(this._operationCompleteHandlers,e)}}function Ri(t,e){const n=t.indexOf(e);n>=0&&t.splice(n,1)}class Gw{constructor(e){E(this,"id");E(this,"atoms",It("store_atoms",{}));E(this,"history",It("history",0,{historyLength:1e3}));E(this,"query",new gV(this.atoms,this.history));E(this,"listeners",new Set);E(this,"historyAccumulator",new SV);E(this,"historyReactor");E(this,"schema");E(this,"props");E(this,"scopedTypes");E(this,"sideEffects",new mV(this));E(this,"isMergingRemoteChanges",!1);E(this,"_integrityChecker");E(this,"_isPossiblyCorrupted",!1);E(this,"pendingAfterEvents",null);E(this,"_isInAtomicOp",!1);const{initialData:n,schema:r,id:o}=e;this.id=o??ze(),this.schema=r,this.props=e.props,n&&this.atoms.set(xT(Xn(n).map(([s,i])=>[s,It("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=VG("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=$T(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:ou(e.added,(o,s)=>this.scopedTypes[n].has(s.typeName)),updated:ou(e.updated,(o,s)=>this.scopedTypes[n].has(s[1].typeName)),removed:ou(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]=It("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(PC(this.atoms.get()))}update(e,n){const r=this.atoms.get()[e];if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])}has(e){return!!this.atoms.get()[e]}listen(e,n){this._flushHistory();const r={onHistory:e,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.listeners.add(r),this.historyReactor.scheduler.isActivelyListening||this.historyReactor.start(),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,Eo(e)}finally{this.isMergingRemoteChanges=!1}}extractingChanges(e){const n=[],r=this.historyAccumulator.addInterceptor(o=>n.push(o.changes));try{return Eo(e),Ww(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=PC(e.removed);o.length&&this.put(o),s.length&&this.remove(s)},n)}createComputedCache(e,n,r){const o=new ko;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=r?W(i.name+":equals",()=>i.get(),{isEqual:r}):i;return W(e+":"+s,()=>n(a.get()))}).get()}}}createSelectedComputedCache(e,n,r){const o=new ko;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=W(e+":"+s+":selector",()=>n(i.get()));return W(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 Eo(()=>{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 yV(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:Ww(o.map(s=>s.changes))}))}class SV{constructor(){E(this,"_history",[]);E(this,"_interceptors",new Set)}addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const n of this._interceptors)n(e)}flush(){const e=yV(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function vV(t,e,n){const r=new ko;return{get(o,s){return r.get(o,()=>(o instanceof Gw?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 fl({sequence:t,sequenceId:e,retroactive:n=!0}){const r={sequenceId:e,retroactive:n,sequence:xV(t)};return GM(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 fl({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 wV(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}=Sf(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 Sf(t){const[e,n]=t.split("/");return{sequenceId:e,version:parseInt(n)}}function I_(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 GM(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;I_(t.sequence[0].id,t.sequenceId);let e=Sf(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;I_(r,t.sequenceId);const o=Sf(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 Os=(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))(Os||{});function bV(t){if(t.schemaVersion>2||t.schemaVersion<1)return xn.err("Bad schema version");if(t.schemaVersion===2)return xn.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 xn.ok(e)}class Vw{constructor(e,n){E(this,"migrations",{});E(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}`),GM(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=wV(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 Vw(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=bV(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 xn.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 xn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))s.add(u.id)}return xn.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:Os.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"?Os.TargetVersionTooOld:Os.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:Os.TargetVersionTooOld};s=s.slice().reverse()}e=nt(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=nt(l))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:Os.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:Os.MigrationError};const o=r.value;if(o.length===0)return{type:"success",value:n};n=nt(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]=nt(c))}else if(s.scope==="store"){const i=s.up(n);i&&(n=nt(i))}else Ot(s)}catch(s){return console.error("Error migrating store",s),{type:"error",reason:Os.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?Sf(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}}xi("@tldraw/store","3.3.0","esm");function PV(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=PV(r),s=n.split(`
|
|
83
|
-
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
84
|
-
`);super(r?`At ${o}: ${s}`:s);E(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function 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 ci(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 kn{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 TV(this)}optional(){return YM(this)}refine(e){return new kn(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 CV extends kn{constructor(e){super(n=>{const r=E_.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=E_.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 vf extends kn{constructor(e,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${ci(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(!Jr(e,o))throw new Me("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Me(`Expected object, got ${ci(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(!Jr(e,i))throw new Me("Unexpected property",[i])}for(const i of Object.keys(r))if(!Jr(o,i)){s=!0;break}return s?o:r}),this.config=e,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new vf(this.config,!0)}extend(e){return new vf({...this.config,...e})}}class Ig extends kn{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 ${ci(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 ${ci(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Me(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:Jr(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(e){return new Ig(this.key,this.config,e,this.useNumberKeys)}}class _V extends kn{constructor(e,n){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${ci(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 ${ci(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!Jr(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(!Jr(o,i)){s=!0;break}return s?o:r}),this.keyValidator=e,this.valueValidator=n}}function Yw(t){return new kn(e=>{if(typeof e!==t)throw new Me(`Expected ${t}, got ${ci(e)}`);return e})}const IV=new kn(t=>t),me=Yw("string"),fe=Yw("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}`)}),xf=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}`)}),VM=fe.check(t=>{if(!Number.isInteger(t))throw new Me(`Expected an integer, got ${t}`)}),np=VM.check(t=>{if(t<0)throw new Me(`Expected a positive integer, got ${t}`)}),EV=VM.check(t=>{if(t<=0)throw new Me(`Expected a non-zero positive integer, got ${t}`)}),we=Yw("boolean");function gn(t){return new kn(e=>{if(e!==t)throw new Me(`Expected ${t}, got ${JSON.stringify(e)}`);return t})}const E_=new kn(t=>{if(!Array.isArray(t))throw new Me(`Expected an array, got ${ci(t)}`);return t});function Wt(t){return new CV(t)}function Pe(t){return new vf(t)}function a0(t){return typeof t=="object"&&t!==null&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null||Object.getPrototypeOf(t)===JB)}function l0(t){return t===null||typeof t=="number"||typeof t=="string"||typeof t=="boolean"?!0:Array.isArray(t)?t.every(l0):a0(t)?Object.values(t).every(l0):!1}const Gt=new kn(t=>{if(l0(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,Gt.validate(e[r]);continue}const o=t[r],s=e[r];if(Object.is(o,s))continue;const i=Gt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}return n?e:t}else if(a0(t)&&a0(e)){let n=!1;for(const r of Object.keys(e)){if(!Jr(t,r)){n=!0,Gt.validate(e[r]);continue}const o=t[r],s=e[r];if(Object.is(o,s))continue;const i=Gt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}for(const r of Object.keys(t))if(!Jr(e,r)){n=!0;break}return n?e:t}else return Gt.validate(e)});function wf(t,e){return new _V(t,e)}function Xw(t,e){return new Ig(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 kV(t,e){return new Ig(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 Lo(t,e){return new kn(n=>qn(t,()=>e.validate(n)),(n,r)=>qn(t,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(n,r):e.validate(r)))}function Eg(t){return new kn(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 YM(t){return new kn(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 TV(t){return new kn(e=>e===null?null:t.validate(e),(e,n)=>n===null?null:t.validateUsingKnownGoodVersion&&e!==null?t.validateUsingKnownGoodVersion(e,n):t.validate(n))}function kg(...t){return Eg(new Set(t))}function qw(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 MV=new Set(["http:","https:","mailto:"]),gr=me.check(t=>{if(t==="")return;const e=qw(t);if(!MV.has(e.protocol.toLowerCase()))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)}),AV=new Set(["http:","https:","data:","asset:"]),na=me.check(t=>{if(t==="")return;const e=qw(t);if(!AV.has(e.protocol.toLowerCase()))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});me.check(t=>{if(t==="")return;if(!qw(t).protocol.toLowerCase().match(/^https?:$/))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});const Zw=me.refine(t=>{try{return UB(t),t}catch{throw new Me(`Expected an index key, got ${JSON.stringify(t)}`)}});xi("@tldraw/validate","3.3.0","esm");function dr(t){return me.refine(e=>{if(!e.startsWith(`${t}:`))throw new Error(`${t} ID must start with "${t}:"`);return e})}const Tg=dr("asset");function Qw(t,e){return Pe({id:Tg,typeName:gn("asset"),type:gn(t),props:e,meta:Gt})}const ra=Pe({x:fe,y:fe,z:fe.optional()}),iu=Pe({x:fe,y:fe,w:fe,h:fe}),XM=fe.check(t=>{if(t<0||t>1)throw new Me("Opacity must be between 0 and 1")}),jV=me.refine(t=>{if(!t.startsWith("page:")&&!t.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return t}),_r=dr("shape");function OV(t,e,n){return Pe({id:_r,typeName:gn("shape"),x:fe,y:fe,rotation:fe,index:Zw,parentId:jV,type:gn(t),isLocked:we,opacity:XM,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}const DV=dr("binding");function RV(t,e,n){return Pe({id:DV,typeName:gn("binding"),type:gn(t),fromId:_r,toId:_r,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}Zn("com.tldraw.binding",{});xr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Yi(t){return`binding:${ze()}`}function LV(t){return Ro("binding",{scope:"document",validator:Lo("binding",Xw("type",Ju(t,(e,{props:n,meta:r})=>RV(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=IV}=n;return new Zt(e,r,o)}static defineEnum(e,n){const{defaultValue:r,values:o}=n;return new $V(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 $V extends Zt{constructor(e,n,r){super(e,n,kg(...r)),this.values=r}}const oh=Zn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),FV=xr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:oh.AddIsLocked,up:t=>{t.isLocked=!1},down:t=>{delete t.isLocked}},{id:oh.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:oh.AddMeta,up:t=>{t.meta={}}},{id:oh.AddWhite,up:t=>{},down:t=>{t.props.color==="white"&&(t.props.color="black")}}]});function nl(t){return t?t.typeName==="shape":!1}function $n(t){return t?t.startsWith("shape:"):!1}function Be(t){return`shape:${t??ze()}`}function qM(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 ao(t,e){return Ju(e,(n,r)=>`com.tldraw.shape.${t}/${r}`)}function NV(t){return Ro("shape",{scope:"document",validator:Lo("shape",Xw("type",Ju(t,(e,{props:n,meta:r})=>OV(e,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function k_(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} ${_g} migrations. Expected '${s}', got '${o.sequenceId}'`),n.push(o)):"sequence"in o?n.push(fl({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?ZM(t,r,i):i)})):n.push(fl({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(fl({sequenceId:s,retroactive:!1,sequence:[]}))}return n}function ZM(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 QM=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],bf={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 bs(t){return t.isDarkMode?bf.darkMode:bf.lightMode}const mr=Zt.defineEnum("tldraw:color",{defaultValue:"black",values:QM}),JM=Zt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:QM}),oa=Zt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),sa=Zt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),To=Zt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),eA={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Mo=Zt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),tA=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Pf=Zt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:tA}),Cf=Zt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:tA}),nA={labelColor:JM,color:mr,fill:sa,dash:oa,size:Mo,arrowheadStart:Pf,arrowheadEnd:Cf,font:To,start:ra,end:ra,bend:fe,text:me,labelPosition:fe,scale:Ct},$a=ao("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function sh(t){return ZM("shape","arrow",t)}const rA=fl({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[sh({id:$a.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"}),sh({id:$a.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)}}),sh({id:$a.AddLabelPosition,up:t=>{t.labelPosition=.5},down:t=>{delete t.labelPosition}}),{id:$a.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=Yi(),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=Yi(),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}}},sh({id:$a.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}})]}),oA={terminal:kg("start","end"),normalizedAnchor:ra,isExact:we,isPrecise:we},sA={sequence:[{dependsOn:[$a.ExtractBindings]}]},zV=Lo("camera",Pe({typeName:gn("camera"),id:dr("camera"),x:fe,y:fe,z:fe,meta:Gt})),BV=Zn("com.tldraw.camera",{AddMeta:1}),UV=xr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:BV.AddMeta,up:t=>{t.meta={}}}]}),bo=Ro("camera",{validator:zV,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),HV=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"]),iA=Eg(HV),KV=Pe({type:iA,rotation:fe}),WV=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),GV=Eg(WV),VV=new Set(["starting","paused","active","stopping"]),aA=Pe({id:me,points:Wt(ra),size:xf,color:GV,opacity:fe,state:Eg(VV),delay:fe,shrink:fe,taper:we}),Ru=dr("page"),YV=Lo("page",Pe({typeName:gn("page"),id:Ru,name:me,index:Zw,meta:Gt})),XV=Zn("com.tldraw.page",{AddMeta:1}),qV=xr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:XV.AddMeta,up:t=>{t.meta={}}}]}),yr=Ro("page",{validator:YV,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Dn(t){return yr.isId(t)}const ZV={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 lA(t){return t?ou(t,e=>ZV[e]):null}dr("instance");function QV(t){const e={};for(const[r,o]of t)e[r]=YM(o);const n=Lo("instance",Pe({typeName:gn("instance"),id:dr("instance"),currentPageId:Ru,followingUserId:me.nullable(),brush:iu.nullable(),opacityForNextShape:XM,stylesForNextShape:Pe(e),cursor:KV,scribbles:Wt(aA),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:iu,insets:Wt(we),zoomBrush:iu.nullable(),isPenMode:we,isGridMode:we,chatMessage:me,isChatting:we,highlightedUserIds:Wt(me),isFocused:we,devicePixelRatio:fe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:Wt(me),isChangingStyle:we,isReadonly:we,meta:Gt,duplicateProps:Pe({shapeIds:Wt(dr("shape")),offset:Pe({x:fe,y:fe})}).nullable()}));return Ro("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 et=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}),JV=xr({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:et.AddTransparentExportBgs,up:t=>({...t,exportBackground:!0})},{id:et.RemoveDialog,up:({dialog:t,...e})=>e},{id:et.AddToolLockMode,up:t=>({...t,isToolLocked:!1})},{id:et.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:et.AddLabelColor,up:({propsForNextShape:t,...e})=>({...e,propsForNextShape:{...t,labelColor:"black"}})},{id:et.AddFollowingUserId,up:t=>({...t,followingUserId:null})},{id:et.RemoveAlignJustify,up:t=>{let e=t.propsForNextShape.align;return e==="justify"&&(e="start"),{...t,propsForNextShape:{...t.propsForNextShape,align:e}}}},{id:et.AddZoom,up:t=>({...t,zoomBrush:null})},{id:et.AddVerticalAlign,up:t=>({...t,propsForNextShape:{...t.propsForNextShape,verticalAlign:"middle"}})},{id:et.AddScribbleDelay,up:t=>t.scribble!==null?{...t,scribble:{...t.scribble,delay:0}}:{...t}},{id:et.RemoveUserId,up:({userId:t,...e})=>e},{id:et.AddIsPenModeAndIsGridMode,up:t=>({...t,isPenMode:!1,isGridMode:!1})},{id:et.HoistOpacity,up:({propsForNextShape:{opacity:t,...e},...n})=>({...n,opacityForNextShape:Number(t??"1"),propsForNextShape:e})},{id:et.AddChat,up:t=>({...t,chatMessage:"",isChatting:!1})},{id:et.AddHighlightedUserIds,up:t=>({...t,highlightedUserIds:[]})},{id:et.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:t,...e})=>({...e,stylesForNextShape:{}})},{id:et.AddMeta,up:t=>({...t,meta:{}})},{id:et.RemoveCursorColor,up:t=>{const{color:e,...n}=t.cursor;return{...t,cursor:n}}},{id:et.AddLonelyProperties,up:t=>({...t,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:et.ReadOnlyReadonly,up:({isReadOnly:t,...e})=>({...e,isReadonly:t})},{id:et.AddHoveringCanvas,up:t=>({...t,isHoveringCanvas:null})},{id:et.AddScribbles,up:({scribble:t,...e})=>({...e,scribbles:[]})},{id:et.AddInset,up:t=>({...t,insets:[!1,!1,!1,!1]}),down:({insets:t,...e})=>({...e})},{id:et.AddDuplicateProps,up:t=>({...t,duplicateProps:null}),down:({duplicateProps:t,...e})=>({...e})},{id:et.RemoveCanMoveCamera,up:({canMoveCamera:t,...e})=>({...e}),down:t=>({...t,canMoveCamera:!0})}]}),wn="instance:instance",eY=Lo("instance_page_state",Pe({typeName:gn("instance_page_state"),id:dr("instance_page_state"),pageId:Ru,selectedShapeIds:Wt(_r),hintingShapeIds:Wt(_r),erasingShapeIds:Wt(_r),hoveredShapeId:_r.nullable(),editingShapeId:_r.nullable(),croppingShapeId:_r.nullable(),focusedGroupId:_r.nullable(),meta:Gt})),xc=Zn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),tY=xr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:xc.AddCroppingId,up(t){t.croppingShapeId=null}},{id:xc.RemoveInstanceIdAndCameraId,up(t){delete t.instanceId,delete t.cameraId}},{id:xc.AddMeta,up:t=>{t.meta={}}},{id:xc.RenameProperties,up:t=>{},down:t=>{}},{id:xc.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}}]}),Xr=Ro("instance_page_state",{validator:eY,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:{}})),nY=Lo("pointer",Pe({typeName:gn("pointer"),id:dr("pointer"),x:fe,y:fe,lastActivityTimestamp:fe,meta:Gt})),rY=Zn("com.tldraw.pointer",{AddMeta:1}),oY=xr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:rY.AddMeta,up:t=>{t.meta={}}}]}),Jw=Ro("pointer",{validator:nY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),_f=Jw.createId("pointer"),sY=Lo("instance_presence",Pe({typeName:gn("instance_presence"),id:dr("instance_presence"),userId:me,userName:me,lastActivityTimestamp:fe,followingUserId:me.nullable(),cursor:Pe({x:fe,y:fe,type:iA,rotation:fe}),color:me,camera:Pe({x:fe,y:fe,z:fe}),screenBounds:iu,selectedShapeIds:Wt(dr("shape")),currentPageId:dr("page"),brush:iu.nullable(),scribbles:Wt(aA),chatMessage:me,meta:Gt})),wc=Zn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),iY=xr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:wc.AddScribbleDelay,up:t=>{t.scribble!==null&&(t.scribble.delay=0)}},{id:wc.RemoveInstanceId,up:t=>{delete t.instanceId}},{id:wc.AddChatMessage,up:t=>{t.chatMessage=""}},{id:wc.AddMeta,up:t=>{t.meta={}}},{id:wc.RenameSelectedShapeIds,up:t=>{}}]}),aY=Ro("instance_presence",{validator:sY,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:0,followingUserId:null,color:"#FF0000",camera:{x:0,y:0,z:1},cursor:{x:0,y:0,type:"default",rotation:0},screenBounds:{x:0,y:0,w:1,h:1},selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),lY=Lo("document",Pe({typeName:gn("document"),id:gn("document:document"),gridSize:fe,name:me,meta:Gt})),T_=Zn("com.tldraw.document",{AddName:1,AddMeta:2}),cY=xr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:T_.AddName,up:t=>{t.name=""},down:t=>{delete t.name}},{id:T_.AddMeta,up:t=>{t.meta={}}}]}),e1=Ro("document",{validator:lY,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),c0=e1.createId("document");function uY(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function M_(t){t.typeName==="asset"&&("src"in t&&(t.src="<redacted>"),"src"in t.props&&(t.props.src="<redacted>"))}function dY({error:t,phase:e,record:n,recordBefore:r}){throw gw(t,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?M_(nt(r)):void 0,recordAfter:M_(nt(n))}}),t}function hY(){return[yr.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function pY(t){const e=t.query.ids("page"),n=t.query.records("instance_page_state"),r=()=>{if(!t.has(c0))return t.put([e1.create({id:c0,name:t.props.defaultName})]),r();if(!t.has(_f))return t.put([Jw.create({id:_f})]),r();const o=e.get();if(o.size===0)return t.put(hY()),r();const s=()=>[...o].map(u=>t.get(u)).sort(uY)[0].id,i=t.get(wn);if(i){if(!o.has(i.currentPageId))return t.put([{...i,currentPageId:s()}]),r()}else return t.put([t.schema.types.instance.create({id:wn,currentPageId:s(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const u of o){const h=Xr.createId(u);t.get(h)||a.add(h);const f=bo.createId(u);t.has(f)||l.add(f)}a.size>0&&t.put([...a].map(u=>Xr.create({id:u,pageId:Xr.parseId(u)}))),l.size>0&&t.put([...l].map(u=>bo.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 fY=Qw("bookmark",Pe({title:me,description:me,image:me,favicon:me,src:na.nullable()})),A_=Zn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),gY=xr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:t=>t.type==="bookmark",sequence:[{id:A_.MakeUrlsValid,up:t=>{na.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:A_.AddFavicon,up:t=>{na.isValid(t.props.favicon)||(t.props.favicon="")},down:t=>{delete t.props.favicon}}]}),mY=Qw("image",Pe({w:fe,h:fe,name:me,isAnimated:we,mimeType:me.nullable(),src:na.nullable(),fileSize:Ct.optional()})),bc=Zn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),yY=xr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:t=>t.type==="image",sequence:[{id:bc.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:bc.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:bc.MakeUrlsValid,up:t=>{na.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:bc.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:bc.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),SY=Qw("video",Pe({w:fe,h:fe,name:me,isAnimated:we,mimeType:me.nullable(),src:na.nullable(),fileSize:fe.optional()})),Pc=Zn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),vY=xr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:t=>t.type==="video",sequence:[{id:Pc.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Pc.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:Pc.MakeUrlsValid,up:t=>{na.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Pc.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Pc.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),xY=Lo("asset",Xw("type",{image:mY,video:SY,bookmark:fY})),wY=Zn("com.tldraw.asset",{AddMeta:1}),bY=xr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:wY.AddMeta,up:t=>{t.meta={}}}]}),zs=Ro("asset",{validator:xY,scope:"document"}).withDefaultProperties(()=>({meta:{}})),cA={w:Ct,h:Ct,assetId:Tg.nullable(),url:gr},j_=ao("bookmark",{NullAssetId:1,MakeUrlsValid:2}),uA={sequence:[{id:j_.NullAssetId,up:t=>{t.assetId===void 0&&(t.assetId=null)},down:"retired"},{id:j_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},dA=Pe({type:kg("free","straight"),points:Wt(ra)}),hA={color:mr,fill:sa,dash:oa,size:Mo,segments:Wt(dA),isComplete:we,isClosed:we,isPen:we,scale:Ct},O_=ao("draw",{AddInPen:1,AddScale:2}),pA={sequence:[{id:O_.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:O_.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},PY=/(^\/r\/[^/]+\/?$)/,CY=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(PY))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","")}}],fA={w:Ct,h:Ct,url:me},ih=ao("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),gA={sequence:[{id:ih.GenOriginalUrlInEmbed,up:t=>{try{const e=t.url,n=new URL(e).host.replace("www.","");let r;for(const o of CY)if(o.hostnames.includes(n))try{r=o.fromEmbedUrl(e)}catch(s){console.warn(s)}t.tmpOldUrl=t.url,t.url=r??""}catch{t.url="",t.tmpOldUrl=t.url}},down:"retired"},{id:ih.RemoveDoesResize,up:t=>{delete t.doesResize},down:"retired"},{id:ih.RemoveTmpOldUrl,up:t=>{delete t.tmpOldUrl},down:"retired"},{id:ih.RemovePermissionOverrides,up:t=>{delete t.overridePermissions},down:"retired"}]},mA={w:Ct,h:Ct,name:me},yA={sequence:[]},If=Zt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Ef=Zt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),qr=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"]}),SA={geo:qr,labelColor:JM,color:mr,fill:sa,dash:oa,size:Mo,font:To,align:If,verticalAlign:Ef,url:gr,w:Ct,h:Ct,growY:xf,text:me,scale:Ct},Ko=ao("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),vA={sequence:[{id:Ko.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Ko.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"},{id:Ko.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Ko.AddCheckBox,up:t=>{},down:"retired"},{id:Ko.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Ko.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:Ko.AddCloud,up:t=>{},down:"retired"},{id:Ko.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Ko.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},xA={},wA={sequence:[]},bA={color:mr,size:Mo,segments:Wt(dA),isComplete:we,isPen:we,scale:Ct},_Y=ao("highlight",{AddScale:1}),PA={sequence:[{id:_Y.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},IY=Pe({topLeft:ra,bottomRight:ra}),CA={w:Ct,h:Ct,playing:we,url:gr,assetId:Tg.nullable(),crop:IY.nullable(),flipX:we,flipY:we},ah=ao("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),_A={sequence:[{id:ah.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:ah.AddCropProp,up:t=>{t.crop=null},down:t=>{delete t.crop}},{id:ah.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:ah.AddFlipProps,up:t=>{t.flipX=!1,t.flipY=!1},down:t=>{delete t.flipX,delete t.flipY}}]},kf=Zt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),EY=Pe({id:me,index:Zw,x:fe,y:fe}),IA={color:mr,dash:oa,size:Mo,spline:kf,points:wf(me,EY),scale:Ct},Cc=ao("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),EA={sequence:[{id:Cc.AddSnapHandles,up:t=>{for(const e of Object.values(t.handles))e.canSnap=!0},down:"retired"},{id:Cc.RemoveExtraHandleProps,up:t=>{t.handles=xT(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:Cc.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=Ou(t.points.length);t.handles=Object.fromEntries(t.points.map((n,r)=>[e[r],{x:n.x,y:n.y}])),delete t.points}},{id:Cc.PointIndexIds,up:t=>{const e=Ou(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:Cc.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},kA={color:mr,size:Mo,font:To,fontSizeAdjustment:xf,align:If,verticalAlign:Ef,growY:xf,url:gr,text:me,scale:Ct},Li=ao("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7}),TA={sequence:[{id:Li.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Li.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Li.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:Li.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Li.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Li.AddFontSizeAdjustment,up:t=>{t.fontSizeAdjustment=0},down:t=>{delete t.fontSizeAdjustment}},{id:Li.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},u0=Zt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),MA={color:mr,size:Mo,font:To,textAlign:u0,w:Ct,text:me,scale:Ct,autoSize:we},D_=ao("text",{RemoveJustify:1,AddTextAlign:2}),AA={sequence:[{id:D_.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:D_.AddTextAlign,up:t=>{t.textAlign=t.align,delete t.align},down:t=>{t.align=t.textAlign,delete t.textAlign}}]},jA={w:Ct,h:Ct,time:fe,playing:we,url:gr,assetId:Tg.nullable()},R_=ao("video",{AddUrlProp:1,MakeUrlsValid:2}),OA={sequence:[{id:R_.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:R_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},lh=Zn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),kY=fl({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:lh.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:lh.AddInstancePresenceType,scope:"store",up(t){}},{id:lh.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match(/^(user|user_presence)$/)&&delete t[e]}},{id:lh.RemoveUserDocument,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match("user_document")&&delete t[e]}}]}),TY={arrow:{migrations:rA,props:nA},bookmark:{migrations:uA,props:cA},draw:{migrations:pA,props:hA},embed:{migrations:gA,props:fA},frame:{migrations:yA,props:mA},geo:{migrations:vA,props:SA},group:{migrations:wA,props:xA},highlight:{migrations:PA,props:bA},image:{migrations:_A,props:CA},line:{migrations:EA,props:IA},note:{migrations:TA,props:kA},text:{migrations:AA,props:MA},video:{migrations:OA,props:jA}},MY={arrow:{migrations:sA,props:oA}};function AY({shapes:t=TY,bindings:e=MY,migrations:n}={}){const r=new Map;for(const a of ut(t))for(const l of qM(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=NV(t),s=LV(e),i=QV(r);return Vw.create({asset:zs,binding:s,camera:bo,document:e1,instance:i,instance_page_state:Xr,page:yr,instance_presence:aY,pointer:Jw,shape:o},{migrations:[kY,bY,UV,cY,JV,tY,qV,iY,oY,FV,gY,yY,vY,...k_("shape",t),...k_("binding",e),...n??[]],onValidationFailure:dY,createIntegrityChecker:pY})}const Lu=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"uk",label:"Ukrainian"},{locale:"he",label:"עברית"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ku",label:"کوردی"},{locale:"ne",label:"नेपाली"},{locale:"hi-in",label:"हिन्दी"},{locale:"te",label:"తెలుగు"},{locale:"th",label:"ภาษาไทย"},{locale:"my",label:"မြန်မာစာ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function jY(){const t=typeof window<"u"?window.navigator.languages??["en"]:["en"];return OY(t)}function OY(t){for(const e of t){const n=DY(e);if(n)return n}return"en"}const L_={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function DY(t){const e=Lu.find(o=>o.locale===t.toLowerCase());if(e)return e.locale;const[n,r]=t.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Lu.find(s=>s.locale===n);if(o)return o.locale}return n in L_?L_[n]:null}xi("@tldraw/tlschema","3.3.0","esm");var DA={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})()})(DA);var RY=DA.exports;const le=mi(RY),RA="3.3.0",$_={major:"2024-09-13T14:36:29.063Z",minor:"2024-10-09T10:22:00.866Z",patch:"2024-10-09T10:22:00.866Z"},LY={error:null};class t1 extends w.Component{constructor(){super(...arguments);E(this,"state",LY)}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 $u({children:t,fallback:e,...n}){return e===null?t:d.jsx(t1,{fallback:e,...n,children:t})}const sd=w.createContext(null);function z(){const t=Te.useContext(sd);if(!t)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return t}function n1(){return Te.useContext(sd)}function $Y(){return d.jsx("div",{className:"tl-background"})}function Yl(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(Qo(e.x),Qo(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-FY(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 FY=t=>t<.5?2*t*t:-1+(4-2*t)*t;function je(t){return`${N(t.x)},${N(t.y)} `}function Nn(t,e){return`${N((t.x+e.x)/2)},${N((t.y+e.y)/2)} `}const De=Math.PI,Ze=De/2,Ne=De*2,NY=Math.sin;function Bt(t,e,n){return Math.max(e,typeof n<"u"?Math.min(t,n):t)}function ch(t,e=1e10){return t?Math.round(t*e)/e:0}function ri(t,e,n=1e-6){return Math.abs(t-e)<=n}function LA(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 oi(t){return t=t%Ne,t<0?t=t+Ne:t===0&&(t=0),t}function id(t,e){return t=oi(t),e=oi(e),t>e&&(e+=Ne),e-t}function $A(t,e){return Ne-id(t,e)}function rp(t,e){const n=(e-t)%Ne;return 2*n%Ne-n}function d0(t){return(Ne+t)%Ne}function Tf(t,e){const n=Ne/e;let r=Math.floor((d0(t)+n/2)/n)*n%Ne;return r<De&&(r+=Ne),r>De&&(r-=Ne),r}function FA(t,e){return t===e||ri(t%(Math.PI/2)-e%(Math.PI/2),0)}function zY(t){return t*De/180}function BY(t){return t*180/De}function ia(t,e,n){return new x(t.x,t.y).add(x.FromAngle(n,e))}function Oy(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=-Ze+g*m,S=r+r*Math.cos(v),y=o+o*Math.sin(v);S<i&&(i=S),y<l&&(l=y),S>a&&(a=S),y>c&&(c=y),s.push(new x(S,y))}const u=a-i,h=c-l,p=t-u,f=e-h;if(p!==0||f!==0)for(let g=0;g<s.length;g++){const m=s[g];m.x=(m.x-i)/u*t,m.y=(m.y-l)/h*e}return s}function _c(t,e,n,r){return t<r&&n<e}function Kr(t,e,n,r){const o=Math.max(t,n),s=Math.min(e,r);return o<=s?[o,s]:null}function F_(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&&F_(r,o,t)>0&&(n+=1):o.y<=t.y&&F_(r,o,t)<0&&(n-=1)}return n!==0}function N(t){return Math.round(t*1e4)/1e4}function Qo(t){return Math.round(t*100)/100}const N_=t=>Math.abs(t)<Number.MAX_SAFE_INTEGER;function Bs(t,e,n){return n<0?id(t,e):$A(t,e)}function h0(t,e,n,r){let o;if(Math.abs(t)>De){o=rp(e,r);const s=rp(r,n);return Math.abs(o)<Math.abs(s)?o/t:(t-s)/t}else{o=rp(e,r);const s=o/t;return Math.sign(o)!==Math.sign(t)?Math.abs(s)>.5?1:0:s}}function UY(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 r1(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 HY(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=id(i,a);for(let c=0;c<o;c++){const u=c/(o-1),h=i+l*u,p=ia(n,r,h);s.push(p)}return s}const Dy=({brush:t,color:e,opacity:n,className:r})=>{const o=w.useRef(null);Yl(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 z_={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Ry={duration:0,easing:Dt.easeInOutCubic},B_={CAMERA_MOVE:-10},KY=["top","right","bottom","left"],U_=0,o1=2,uh=1,H_=5,WY=128;var Ly={};const GY={},NA=On("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),bt={logPreventDefaults:On("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:On("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:On("logElementRemoves",{defaults:{all:!1}}),debugSvg:On("debugSvg",{defaults:{all:!1}}),showFps:On("showFps",{defaults:{all:!1}}),measurePerformance:On("measurePerformance",{defaults:{all:!1}}),throwToBlob:On("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:On("reconnectOnPing",{defaults:{all:!1}}),debugCursors:On("debugCursors",{defaults:{all:!1}}),forceSrgb:On("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:On("debugGeometry",{defaults:{all:!1}}),hideShapes:On("hideShapes",{defaults:{all:!1}}),editOnType:On("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const t=Element.prototype.removeChild;is("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 On(t,{defaults:e,shouldStoreForSession:n=!0}){return VY({name:t,defaults:e,shouldStoreForSession:n})}function VY(t){const e=XY(t),n=t.shouldStoreForSession?YY(t.name):null,r=It(`debug:${t.name}`,n??e);return typeof window<"u"&&(t.shouldStoreForSession&&is(`debug:${t.name}`,()=>{const o=r.get();o===e?RT(`tldraw_debug:${t.name}`):bw(`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 YY(t){try{return JSON.parse(DT(`tldraw_debug:${t}`)??"null")}catch{return null}}function $y(t){try{return t()}catch{return null}}function XY(t){switch($y(()=>Ly.TLDRAW_ENV)??$y(()=>Ly.VERCEL_PUBLIC_TLDRAW_ENV)??$y(()=>Ly.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 Mf(t){if(t instanceof HTMLElement)return t;if(t.parentElement)return Mf(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 ad(t,e){if(t.setPointerCapture(e.pointerId),bt.logPointerCaptures.get()){const n=NA.get();n.set(t,(n.get(t)??0)+1),console.warn("setPointerCapture called on element:",t,e)}}function ld(t,e){if(t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),bt.logPointerCaptures.get())){const n=NA.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 Et=t=>t.stopPropagation(),rn=(t,e,n)=>{t&&t.style.setProperty(e,n)},un=t=>Ge.isDarwin?t.metaKey:t.ctrlKey||t.metaKey;function Kn(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 zA(){const t=z();return w.useMemo(function(){let r,o;function s(m){if(!m.isKilled){if(m.button===o1){t.dispatch({type:"pointer",target:"canvas",name:"right_click",...Kn(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(ad(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Kn(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",...Kn(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,o=m.clientY,ld(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Kn(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 S,y;if(xe(m),Et(m),!((y=(S=m.dataTransfer)==null?void 0:S.files)!=null&&y.length))return;const v=Array.from(m.dataTransfer.files);await t.putExternalContent({type:"files",files:v,point:t.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function g(m){Et(m)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:h,onClick:g}},[t])}function qY(){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 BA=w.createContext(null);function ZY({container:t,children:e}){return d.jsx(BA.Provider,{value:t,children:e})}function Mt(){return sr(w.useContext(BA),"useContainer used outside of <Tldraw />")}function QY(){const t=z(),e=Mt(),n=H("isFocused",()=>t.getIsFocused(),[t]);w.useEffect(()=>{if(!e)return;function r(o){if(o.isSpecialRedispatchedEvent)return;xe(o);const s=e.querySelector(".tl-canvas");if(!s)return;const i=new DragEvent("drop",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"))&&!dh()&&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(dh()||t.menus.hasAnyOpenMenus())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(dh()||t.menus.hasAnyOpenMenus())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,dh()||t.menus.hasAnyOpenMenus())||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 JY=["input","select","button","textarea"];function dh(){const{activeElement:t}=document;return!!(t&&(t.getAttribute("contenteditable")||JY.indexOf(t.tagName.toLowerCase())>-1))}const eX=["textarea","input"];function tX(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(eX.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 nX(t,e,n){return Math.max(e,Math.min(t,n))}const Vt={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 K_(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function W_(t,e,n,r=.15){return r===0?nX(t,e,n):t<e?-K_(e-t,n-e,r)+e:t>n?+K_(t-n,n-e,r)+n:t}function rX(t,[e,n],[r,o]){const[[s,i],[a,l]]=t;return[W_(e,s,i,r),W_(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 sX(t){var e=oX(t,"string");return typeof e=="symbol"?e:String(e)}function sn(t,e,n){return e=sX(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function G_(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?G_(Object(n),!0).forEach(function(r){sn(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):G_(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const UA={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 V_(t){return t?t[0].toUpperCase()+t.slice(1):""}const iX=["enter","leave"];function aX(t=!1,e){return t&&!iX.includes(e)}function lX(t,e="",n=!1){const r=UA[t],o=r&&r[e]||e;return"on"+V_(t)+V_(o)+(aX(n,o)?"Capture":"")}const cX=["gotpointercapture","lostpointercapture"];function uX(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=cX.includes(e)?"capturecapture":"capture",o=!!~e.indexOf(r);return o&&(e=e.replace("capture","")),{device:e,capture:o,passive:n}}function dX(t,e=""){const n=UA[t],r=n&&n[e]||e;return t+r}function HA(t){return"touches"in t}function hX(t){return HA(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function pX(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 p0(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 fX(t){return pX(t).map(e=>e.identifier)}function Y_(t,e){const[n,r]=Array.from(t.touches).filter(o=>e.includes(o.identifier));return p0(n,r)}const X_=40,q_=800;function KA(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=X_,n*=X_):r===2&&(e*=q_,n*=q_),[e,n]}function gX(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 Af(t,...e){return typeof t=="function"?t(...e):t}function mX(){}function yX(...t){return t.length===0?mX:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function Z_(t,e){return Object.assign({},e,t||{})}const SX=32;class WA{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?Af(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,gX(e)),o.down=o.pressed=o.buttons%2===1||o.touches>0,s=e.timeStamp-n.timeStamp,n.timeStamp=e.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const I=n._delta.map(Math.abs);Vt.addTo(n._distance,I)}this.axisIntent&&this.axisIntent(e);const[i,a]=n._movement,[l,c]=r.threshold,{_step:u,values:h}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[I,k]=h;p[0]=u[0]!==!1?I-u[0]:0,p[1]=u[1]!==!1?k-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=Af(r.bounds,n)),this.setup&&this.setup()),n.movement=p,this.computeOffset()));const[m,v]=n.offset,[[S,y],[b,P]]=n._bounds;n.overflow=[m<S?-1:m>y?1:0,v<b?-1:v>P?1:0],n._movementBound[0]=n.overflow[0]?n._movementBound[0]===!1?n._movement[0]:n._movementBound[0]:!1,n._movementBound[1]=n.overflow[1]?n._movementBound[1]===!1?n._movement[1]:n._movementBound[1]:!1;const C=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=rX(n._bounds,n.offset,C),n.delta=Vt.sub(n.offset,f),this.computeMovement(),g&&(!n.last||s>SX)){n.delta=Vt.sub(n.offset,f);const I=n.delta.map(Math.abs);Vt.addTo(n.distance,I),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&s>0&&(n.velocity=[I[0]/s,I[1]/s],n.timeDelta=s)}}emit(){const e=this.state,n=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const o=this.handler(ht(ht(ht({},n),e),{},{[this.aliasKey]:e.values}));o!==void 0&&(e.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function vX([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 WA{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=Vt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Vt.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[hX(e)]:r.axisThreshold;n.axis=vX(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 wX=t=>t,Q_=.15,GA={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[Q_,Q_];case!1:return[0,0];default:return Vt.toVector(t)}},from(t){if(typeof t=="function")return t;if(t!=null)return Vt.toVector(t)},transform(t,e,n){const r=t||n.shared.transform;return this.hasCustomTransform=!!r,r||wX},threshold(t){return Vt.toVector(t,0)}},bX=0,cd=ht(ht({},GA),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=bX){return t},bounds(t={}){if(typeof t=="function")return s=>cd.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]]}}),ud=typeof window<"u"&&window.document&&window.document.createElement;function VA(){return ud&&"ontouchstart"in window}function PX(){return VA()||ud&&window.navigator.maxTouchPoints>1}function CX(){return ud&&"onpointerdown"in window}function _X(){return ud&&"exitPointerLock"in window.document}function IX(){try{return"constructor"in GestureEvent}catch{return!1}}const Tr={isBrowser:ud,gesture:IX(),touch:VA(),touchscreen:PX(),pointer:CX(),pointerLock:_X()},EX=250,kX=180,TX=.5,MX=50,AX=250,jX=10,J_={mouse:0,touch:0,pen:8};ht(ht({},cd),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&Tr.pointerLock,Tr.touch&&n?"touch":this.pointerLock?"mouse":Tr.pointer&&!o?"pointer":Tr.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?EX:void 0,!(!Tr.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=Vt.toVector(t,n?r:o?1:0);return this.filterTaps=n,this.tapsThreshold=r,s},swipe({velocity:t=TX,distance:e=MX,duration:n=AX}={}){return{velocity:this.transform(Vt.toVector(t)),distance:this.transform(Vt.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return kX;case!1:return 0;default:return t}},axisThreshold(t){return t?ht(ht({},J_),t):J_},keyboardDisplacement(t=jX){return t}});function YA(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 OX=30,DX=100;class RX extends WA{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=Vt.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)*OX-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=Y_(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=p0(...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=Y_(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=p0(...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=Vt.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=[-KA(e)[1]/DX*r.offset[0],0],Vt.addTo(r._movement,r._delta),YA(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 LX=ht(ht({},GA),{},{device(t,e,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!Tr.touch&&Tr.gesture)return"gesture";if(Tr.touch&&r)return"touch";if(Tr.touchscreen){if(Tr.pointer)return"pointer";if(Tr.touch)return"touch"}},bounds(t,e,{scaleBounds:n={},angleBounds:r={}}){const o=i=>{const a=Z_(Af(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=Z_(Af(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",Vt.toVector(t,this.lockDirection?[.1,3]:0)},modifierKey(t){return t===void 0?"ctrlKey":t},pinchOnWheel(t=!0){return t}});ht(ht({},cd),{},{mouseOnly:(t=!0)=>t});class $X 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=KA(e),Vt.addTo(n._movement,n._delta),YA(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 FX=cd;ht(ht({},cd),{},{mouseOnly:(t=!0)=>t});const s1=new Map,f0=new Map;function NX(t){s1.set(t.key,t.engine),f0.set(t.key,t.resolver)}const zX={key:"pinch",engine:RX,resolver:LX},BX={key:"wheel",engine:$X,resolver:FX};function UX(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 HX(t,e){if(t==null)return{};var n=UX(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 KX={target(t){if(t)return()=>"current"in t?t.current:t},enabled(t=!0){return t},window(t=Tr.isBrowser?window:void 0){return t},eventOptions({passive:t=!0,capture:e=!1}={}){return{passive:t,capture:e}},transform(t){return t}},WX=["target","eventOptions","window","enabled","transform"];function op(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]=op(t[r],o);break;case"boolean":o&&(n[r]=t[r]);break}return n}function GX(t,e,n={}){const r=t,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=HX(r,WX);if(n.shared=op({target:o,eventOptions:s,window:i,enabled:a,transform:l},KX),e){const u=f0.get(e);n[e]=op(ht({shared:n.shared},c),u)}else for(const u in c){const h=f0.get(u);h&&(n[u]=op(ht({shared:n.shared},c[u]),h))}return n}class XA{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=dX(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 VX{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 YX{constructor(e){sn(this,"gestures",new Set),sn(this,"_targetEventStore",new XA(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}}),XX(this,e)}setEventIds(e){if(HA(e))return this.touchIds=new Set(fX(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=GX(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=eI(r,a.eventOptions,!!o);if(a.enabled){const c=s1.get(i);new c(this,e,i).bind(l)}}const s=eI(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]=yX(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=uX(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function ka(t,e){t.gestures.add(e),t.gestureEventStores[e]=new XA(t,e),t.gestureTimeoutStores[e]=new VX}function XX(t,e){e.drag&&ka(t,"drag"),e.wheel&&ka(t,"wheel"),e.scroll&&ka(t,"scroll"),e.move&&ka(t,"move"),e.pinch&&ka(t,"pinch"),e.hover&&ka(t,"hover")}const eI=(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:lX(r,o,u);n&&h&&(p+="Passive"),t[p]=t[p]||[],t[p].push(s)},qX=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function ZX(t){const e={},n={},r=new Set;for(let o in t)qX.test(o)?(r.add(RegExp.lastMatch),n[o]=t[o]):e[o]=t[o];return[n,e,r]}function Ta(t,e,n,r,o,s){if(!t.has(n)||!s1.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 QX(t,e){const[n,r,o]=ZX(t),s={};return Ta(o,n,"onDrag","drag",s,e),Ta(o,n,"onWheel","wheel",s,e),Ta(o,n,"onScroll","scroll",s,e),Ta(o,n,"onPinch","pinch",s,e),Ta(o,n,"onMove","move",s,e),Ta(o,n,"onHover","hover",s,e),{handlers:s,config:e,nativeHandlers:r}}function JX(t,e={},n,r){const o=Te.useMemo(()=>new YX(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 eq(t){return t.forEach(NX),function(n,r){const{handlers:o,nativeHandlers:s,config:i}=QX(n,r||{});return JX(o,i,void 0,s)}}const tI=10,tq=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function qA(t){let{deltaY:e,deltaX:n}=t,r=0;return t.ctrlKey||t.altKey||t.metaKey?r=(Math.abs(e)>tI?tI*Math.sign(e):e)/100:t.shiftKey&&!tq&&(n=e,e=0),{x:-n,y:-e,z:-r}}const nq=eq([BX,zX]);let Ma;const rq=t=>Ma===void 0?(Ma=t,!1):t-Ma>120&&t-Ma<160?(Ma=t,!0):(Ma=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",rq(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),Et(m);const S=qA(m);if(S.x===0&&S.y===0)return;const y={type:"wheel",name:"wheel",delta:S,point:new x(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey,metaKey:m.metaKey,accelKey:un(m)};e.dispatch(y)};let s=1,i=1,a=1,l=0;const c=new x,u=new x,h=m=>{const v=t.current;r="not sure";const{event:S,origin:y,da:b}=m;S instanceof WheelEvent||(S.target===v||v!=null&&v.contains(S.target))&&(u.x=y[0],u.y=y[1],c.x=y[0],c.y=y[1],s=b[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:y[0],y:y[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey,metaKey:S.metaKey,accelKey:un(S)}))},p=m=>{if(m&&(r="zooming"),r==="zooming")return;const v=Math.abs(l-s),S=x.Dist(c,u);switch(r){case"not sure":{v>24?r="zooming":S>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:h,onPinchEnd:m=>{const v=t.current,{event:S,origin:y,offset:b}=m;if(S instanceof WheelEvent||!(S.target===v||v!=null&&v.contains(S.target)))return;const P=b[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:y[0],y:y[1],z:P},delta:{x:y[0],y:y[1]},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey,metaKey:S.metaKey,accelKey:un(S)})})},onPinch:m=>{const v=t.current,{event:S,origin:y,offset:b,da:P}=m;if(S instanceof WheelEvent||!(S.target===v||v!=null&&v.contains(S.target)))return;const C=m.type==="gesturechange"||m.type==="gestureend";l=P[0];const I=y[0]-u.x,k=y[1]-u.y;switch(u.x=y[0],u.y=y[1],p(C),r){case"zooming":{a=b[0],e.dispatch({type:"pinch",name:"pinch",point:{x:y[0],y:y[1],z:a},delta:{x:I,y:k},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey,metaKey:S.metaKey,accelKey:un(S)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:y[0],y:y[1],z:i},delta:{x:I,y:k},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey,metaKey:S.metaKey,accelKey:un(S)});break}}}}},[e,t]);nq(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 Fy(t,e,n){const r=t.getShape(e),o=t.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===n)}}function sq(t,e){const n=z();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Mf(l.currentTarget);ad(c,l);const{shape:u,handle:h}=Fy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...Kn(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}=Fy(n,t,e);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...Kn(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Mf(l.currentTarget);ld(c,l);const{shape:u,handle:h}=Fy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...Kn(l)})}}},[n,t,e])}function iq(t){const e=z();w.useLayoutEffect(()=>{const n=uT(()=>{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=aq(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 aq=t=>{let e=t.parentElement;for(;e;){if(e===document.body)return document;const{overflowY:n}=window.getComputedStyle(e);if(e.scrollHeight>e.clientHeight&&(n==="auto"||n==="scroll"||n==="overlay"))return e;e=e.parentElement}return document};class Z{constructor(e=0,n=0,r=0,o=0){E(this,"x",0);E(this,"y",0);E(this,"w",0);E(this,"h",0);this.x=e,this.y=n,this.w=r,this.h=o}get point(){return new x(this.x,this.y)}set point(e){this.x=e.x,this.y=e.y}get minX(){return this.x}set minX(e){this.x=e}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get minY(){return this.y}set minY(e){this.y=e}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get width(){return this.w}set width(e){this.w=e}get height(){return this.h}set height(e){this.h=e}get aspectRatio(){return this.width/this.height}get center(){return new x(this.midX,this.midY)}set center(e){this.minX=e.x-this.width/2,this.minY=e.y-this.height/2}get corners(){return[new x(this.minX,this.minY),new x(this.maxX,this.minY),new x(this.maxX,this.maxY),new x(this.minX,this.maxY)]}get cornersAndCenter(){return[new x(this.minX,this.minY),new x(this.maxX,this.minY),new x(this.maxX,this.maxY),new x(this.minX,this.maxY),this.center]}get sides(){const{corners:e}=this;return[[e[0],e[1]],[e[1],e[2]],[e[2],e[3]],[e[3],e[0]]]}get size(){return new x(this.w,this.h)}toFixed(){return this.x=ch(this.x),this.y=ch(this.y),this.w=ch(this.w),this.h=ch(this.h),this}setTo(e){return this.x=e.x,this.y=e.y,this.w=e.w,this.h=e.h,this}set(e=0,n=0,r=0,o=0){return this.x=e,this.y=n,this.w=r,this.h=o,this}expand(e){const n=Math.min(this.minX,e.minX),r=Math.min(this.minY,e.minY),o=Math.max(this.maxX,e.maxX),s=Math.max(this.maxY,e.maxY);return this.x=n,this.y=r,this.w=o-n,this.h=s-r,this}expandBy(e){return this.x-=e,this.y-=e,this.w+=e*2,this.h+=e*2,this}scale(e){return this.x/=e,this.y/=e,this.w/=e,this.h/=e,this}clone(){const{x:e,y:n,w:r,h:o}=this;return new Z(e,n,r,o)}translate(e){return this.x+=e.x,this.y+=e.y,this}snapToGrid(e){const n=Math.round(this.minX/e)*e,r=Math.round(this.minY/e)*e,o=Math.round(this.maxX/e)*e,s=Math.round(this.maxY/e)*e;this.minX=n,this.minY=r,this.width=Math.max(1,o-n),this.height=Math.max(1,s-r)}collides(e){return Z.Collides(this,e)}contains(e){return Z.Contains(this,e)}includes(e){return Z.Includes(this,e)}containsPoint(e,n=0){return Z.ContainsPoint(this,e,n)}getHandlePoint(e){switch(e){case"top_left":return new x(this.minX,this.minY);case"top_right":return new x(this.maxX,this.minY);case"bottom_left":return new x(this.minX,this.maxY);case"bottom_right":return new x(this.maxX,this.maxY);case"top":return new x(this.midX,this.minY);case"right":return new x(this.maxX,this.midY);case"bottom":return new x(this.midX,this.maxY);case"left":return new x(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(e,n,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:u,maxY:h}=this;switch(e){case"left":case"top_left":case"bottom_left":{l+=n;break}case"right":case"top_right":case"bottom_right":{u+=n;break}}switch(e){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{h+=r;break}}const p=(u-l)/(i-o),f=(h-c)/(a-s),g=p<0,m=f<0;if(g){const v=u;u=l,l=v}if(m){const v=h;h=c,c=v}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(h-c)}union(e){const n=Math.min(this.minX,e.x),r=Math.min(this.minY,e.y),o=Math.max(this.maxX,e.w+e.x),s=Math.max(this.maxY,e.h+e.y);return this.x=n,this.y=r,this.width=o-n,this.height=s-r,this}static From(e){return new Z(e.x,e.y,e.w,e.h)}static FromCenter(e,n){return new Z(e.x-n.x/2,e.y-n.y/2,n.x,n.y)}static FromPoints(e){if(e.length===0)return new Z;let n=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,l=e.length;a<l;a++)i=e[a],n=Math.min(i.x,n),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new Z(n,r,o-n,s-r)}static Expand(e,n){const r=Math.min(n.minX,e.minX),o=Math.min(n.minY,e.minY),s=Math.max(n.maxX,e.maxX),i=Math.max(n.maxY,e.maxY);return new Z(r,o,s-r,i-o)}static ExpandBy(e,n){return new Z(e.minX-n,e.minY-n,e.width+n*2,e.height+n*2)}static Collides(e,n){return!(e.maxX<n.minX||e.minX>n.maxX||e.maxY<n.minY||e.minY>n.maxY)}static Contains(e,n){return e.minX<n.minX&&e.minY<n.minY&&e.maxY>n.maxY&&e.maxX>n.maxX}static Includes(e,n){return Z.Collides(e,n)||Z.Contains(e,n)}static ContainsPoint(e,n,r=0){return!(n.x<e.minX-r||n.y<e.minY-r||n.x>e.maxX+r||n.y>e.maxY+r)}static Common(e){let n=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<e.length;i++){const a=e[i];n=Math.min(n,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new Z(n,r,o-n,s-r)}static Sides(e,n=0){const{corners:r}=e;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]}static Resize(e,n,r,o,s=!1){const{minX:i,minY:a,maxX:l,maxY:c}=e;let{minX:u,minY:h,maxX:p,maxY:f}=e;switch(n){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(n){case"top":case"top_left":case"top_right":{h+=o;break}case"bottom":case"bottom_left":case"bottom_right":{f+=o;break}}const g=(p-u)/(l-i),m=(f-h)/(c-a),v=g<0,S=m<0;if(s){const b=(l-i)/(c-a),P=Math.abs(p-u),C=Math.abs(f-h),I=P*(m<0?1:-1)*(1/b),k=C*(g<0?1:-1)*b,_=b<P/C;switch(n){case"top_left":{_?h=f+I:u=p+k;break}case"top_right":{_?h=f+I:p=u-k;break}case"bottom_right":{_?f=h-I:p=u-k;break}case"bottom_left":{_?f=h-I:u=p+k;break}case"bottom":case"top":{const T=(u+p)/2,M=C*b;u=T-M/2,p=T+M/2;break}case"left":case"right":{const T=(h+f)/2,M=P/b;h=T-M/2,f=T+M/2;break}}}if(v){const b=p;p=u,u=b}if(S){const b=f;f=h,h=b}const y=new Z(u,h,Math.abs(p-u),Math.abs(f-h));return{box:y,scaleX:+(y.width/e.width*(g>0?1:-1)).toFixed(5),scaleY:+(y.height/e.height*(m>0?1:-1)).toFixed(5)}}equals(e){return Z.Equals(this,e)}static Equals(e,n){return n.x===e.x&&n.y===e.y&&n.w===e.w&&n.h===e.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(e){return new Z(e.x,e.y,Math.max(1,e.w),Math.max(1,e.h))}}function lq(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 cq(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 uq(t){return t==="top_left"||t==="top_right"||t==="bottom_right"||t==="bottom_left"}class q{constructor(e,n,r,o,s,i){E(this,"a",1);E(this,"b",0);E(this,"c",0);E(this,"d",1);E(this,"e",0);E(this,"f",0);this.a=e,this.b=n,this.c=r,this.d=o,this.e=s,this.f=i}equals(e){return this===e||this.a===e.a&&this.b===e.b&&this.c===e.c&&this.d===e.d&&this.e===e.e&&this.f===e.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(e){const n=e,{a:r,b:o,c:s,d:i,e:a,f:l}=this;return this.a=r*n.a+s*n.b,this.c=r*n.c+s*n.d,this.e=r*n.e+s*n.f+a,this.b=o*n.a+i*n.b,this.d=o*n.c+i*n.d,this.f=o*n.e+i*n.f+l,this}rotate(e,n,r){return e===0?this:n===void 0?this.multiply(q.Rotate(e)):this.translate(n,r).multiply(q.Rotate(e)).translate(-n,-r)}translate(e,n){return this.multiply(q.Translate(e,n))}scale(e,n){return this.multiply(q.Scale(e,n))}invert(){const{a:e,b:n,c:r,d:o,e:s,f:i}=this,a=e*o-n*r;return this.a=o/a,this.b=n/-a,this.c=r/-a,this.d=e/a,this.e=(o*s-r*i)/-a,this.f=(n*s-e*i)/a,this}applyToPoint(e){return q.applyToPoint(this,e)}applyToPoints(e){return q.applyToPoints(this,e)}rotation(){return q.Rotation(this)}point(){return q.Point(this)}decomposed(){return q.Decompose(this)}toCssString(){return q.toCssString(this)}setTo(e){return Object.assign(this,e),this}decompose(){return q.Decompose(this)}clone(){return new q(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new q(1,0,0,1,0,0)}static Translate(e,n){return new q(1,0,0,1,e,n)}static Rotate(e,n,r){if(e===0)return q.Identity();const o=Math.cos(e),s=Math.sin(e),i=new q(o,s,-s,o,0,0);return n===void 0?i:q.Compose(q.Translate(n,r),i,q.Translate(-n,-r))}static Scale(e,n,r,o){const s=new q(e,0,0,n,0,0);return r===void 0?s:q.Compose(q.Translate(r,o),s,q.Translate(-r,-o))}static Multiply(e,n){return{a:e.a*n.a+e.c*n.b,c:e.a*n.c+e.c*n.d,e:e.a*n.e+e.c*n.f+e.e,b:e.b*n.a+e.d*n.b,d:e.b*n.c+e.d*n.d,f:e.b*n.e+e.d*n.f+e.f}}static Inverse(e){const n=e.a*e.d-e.b*e.c;return{a:e.d/n,b:e.b/-n,c:e.c/-n,d:e.a/n,e:(e.d*e.e-e.c*e.f)/-n,f:(e.b*e.e-e.a*e.f)/n}}static Absolute(e){const n=e.a*e.d-e.b*e.c;return{a:e.d/n,b:e.b/-n,c:e.c/-n,d:e.a/n,e:(e.d*e.e-e.c*e.f)/n,f:(e.b*e.e-e.a*e.f)/-n}}static Compose(...e){const n=q.Identity();for(let r=0,o=e.length;r<o;r++)n.multiply(e[r]);return n}static Point(e){return new x(e.e,e.f)}static Rotation(e){let n;if(e.a!==0||e.c!==0){const r=(e.a*e.a+e.c*e.c)**.5;n=Math.acos(e.a/r)*(e.c>0?-1:1)}else if(e.b!==0||e.d!==0){const r=(e.b*e.b+e.d*e.d)**.5;n=Ze+Math.acos(e.b/r)*(e.d>0?-1:1)}else n=0;return d0(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=Ze+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:d0(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 Ci{constructor(e){E(this,"isFilled",!1);E(this,"isClosed",!0);E(this,"isLabel",!1);E(this,"debugColor");E(this,"ignore");E(this,"_vertices");E(this,"_bounds");E(this,"_area");E(this,"_length");this.isFilled=e.isFilled,this.isClosed=e.isClosed,this.isLabel=e.isLabel??!1,this.debugColor=e.debugColor,this.ignore=e.ignore}hitTestPoint(e,n=0,r=!1){return this.isClosed&&(this.isFilled||r)&&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 ro extends Ci{constructor(n){super({...n,isClosed:!0,isFilled:!1});E(this,"children",[]);E(this,"ignoredChildren",[]);for(const r of n.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(n=>!n.isLabel).flatMap(n=>n.vertices)}nearestPoint(n){let r=1/0,o;const{children:s}=this;if(s.length===0)throw Error("no children");let i,a;for(const l of s)i=l.nearestPoint(n),a=x.Dist2(i,n),a<r&&(r=a,o=i);if(!o)throw Error("nearest point not found");return o}distanceToPoint(n,r=!1){return Math.min(...this.children.map((o,s)=>o.distanceToPoint(n,r||s>0)))}hitTestPoint(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestPoint(n,r,o))}hitTestLineSegment(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestLineSegment(n,r,o))}getArea(){return this.children[0].area}toSimpleSvgPath(){let n="";for(const o of this.children)n+=o.toSimpleSvgPath();const r=Z.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],l=i.dist(a),c=r[(o+1)%s],u=i.dist(c),h=i.clone().lrp(a,4/l),p=i,f=i.clone().lrp(c,4/u);n+=`M${h.x},${h.y} L${p.x},${p.y} L${f.x},${f.y} `}return n}getLength(){return this.children.reduce((n,r)=>r.isLabel?n:n+r.length,0)}getSvgPathData(){return this.children.map((n,r)=>n.isLabel?"":n.getSvgPathData(r===0)).join(" ")}}function dq(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 hq=$t(function({showStroke:e=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const o=z();dq(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return d.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=o.getShape(l.id);if(c.type==="group")return null;const u=o.getShapeGeometry(c),h=o.getShapePageTransform(c),p=o.getPointInShapeSpace(c,a),f=u.nearestPoint(p),g=u.distanceToPoint(p,!0),m=Math.abs(g)*s,v=g<0,{vertices:S}=u;return d.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&d.jsx("g",{stroke:u.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:d.jsx(ZA,{geometry:u})}),n&&S.map((y,b)=>d.jsx("circle",{cx:y.x,cy:y.y,r:2/s,fill:`hsl(${kl(b,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${b}`)),r&&m<150&&d.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-m/150,stroke:v?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function ZA({geometry:t}){return t instanceof ro?d.jsx(d.Fragment,{children:[...t.children,...t.ignoredChildren].map((e,n)=>d.jsx(ZA,{geometry:e},n))}):d.jsx("path",{d:t.toSimpleSvgPath()})}function QA(t){return uB(t)}function JA(){const t=z(),e=uV("userIds",()=>QA(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 H(e)}function Mg(t){const e=z();return H(`latestPresence:${t}`,()=>e.getCollaborators().find(r=>r.userId===t),[e,t])??null}const pq=$t(function(){return JA().map(n=>d.jsx(fq,{collaboratorId:n},n))}),fq=$t(function({collaboratorId:e}){const n=z(),r=Mg(e),o=mq(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(gq,{latestPresence:r})}),gq=$t(function({latestPresence:e}){const n=z(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=ot(),l=n.getZoomLevel(),c=n.getViewportPageBounds(),{userId:u,chatMessage:h,brush:p,scribbles:f,selectedShapeIds:g,userName:m,cursor:v,color:S}=e,y=!(v.x<c.minX-12/l||v.y<c.minY-16/l||v.x>c.maxX-12/l||v.y>c.maxY-16/l);return d.jsxs(d.Fragment,{children:[p&&r?d.jsx(r,{className:"tl-collaborator__brush",brush:p,color:S,opacity:.1},u+"_brush"):null,y&&s?d.jsx(s,{className:"tl-collaborator__cursor",point:v,color:S,zoom:l,name:m!=="New User"?m:null,chatMessage:h},u+"_cursor"):i?d.jsx(i,{className:"tl-collaborator__cursor-hint",point:v,color:S,zoom:l,viewport:c},u+"_cursor_hint"):null,o&&f.length?d.jsx(d.Fragment,{children:f.map(b=>d.jsx(o,{className:"tl-collaborator__scribble",scribble:b,color:S,zoom:l,opacity:b.color==="laser"?.5:.1},u+"_scribble_"+b.id))}):null,a&&g.filter(b=>!n.isShapeHidden(b)).map(b=>d.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:b,color:S,opacity:.5},u+"_"+b))]})});function nI(t,e){return e>t.options.collaboratorInactiveTimeoutMs?"inactive":e>t.options.collaboratorIdleTimeoutMs?"idle":"active"}function mq(t,e){const n=w.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,o]=w.useState(()=>nI(t,Date.now()-n.current));return w.useEffect(()=>{const s=t.timers.setInterval(()=>{o(nI(t,Date.now()-n.current))},t.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[t]),e&&(n.current=e.lastActivityTimestamp),r}const ej=w.memo(function({id:e,shape:n,util:r,index:o,backgroundIndex:s,opacity:i}){const a=z(),{ShapeErrorFallback:l}=ot(),c=w.useRef(null),u=w.useRef(null),h=w.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});ni("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 S=a.getShapePageTransform(e),y=q.toCssString(S),b=a.getShapeGeometry(g).bounds;y!==m.transform&&(rn(c.current,"transform",y),rn(u.current,"transform",y),m.transform=y);const P=Math.max(b.width,1),C=Math.max(b.height,1);(P!==m.width||C!==m.height)&&(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]),ni("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]),ni("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,draggable:!1,children:d.jsx($u,{fallback:l,onError:p,children:d.jsx(nj,{shape:n,util:r})})}),d.jsx("div",{ref:c,className:"tl-shape","data-shape-type":n.type,"data-shape-is-filled":f,draggable:!1,children:d.jsx($u,{fallback:l,onError:p,children:d.jsx(tj,{shape:n,util:r})})})]})}),tj=w.memo(function({shape:e,util:n}){return Cg("InnerShape:"+e.type,()=>n.component(n.editor.store.unsafeGetWithoutCapture(e.id)))},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta),nj=w.memo(function({shape:e,util:n}){return Cg("InnerShape:"+e.type,()=>{var r;return(r=n.backgroundComponent)==null?void 0:r.call(n,n.editor.store.unsafeGetWithoutCapture(e.id))})},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta);function yq({className:t}){const e=z(),{Background:n,SvgDefs:r,ShapeIndicators:o}=ot(),s=w.useRef(null),i=w.useRef(null),a=w.useRef(null),l=Mt();iq(s),QY(),qY(),oq(s),tX(s);const c=w.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});ni("position layers",function(){const{x:y,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 k=P<e.options.textShadowLod;l.style.setProperty("--tl-text-outline",k?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=k}const C=P>=1?kl(P,[1,8],[.125,.5],!0):kl(P,[.1,1],[-2,.125],!0),I=`scale(${N(P)}) translate(${N(y+C)}px,${N(b+C)}px)`;rn(i.current,"transform",I),rn(a.current,"transform",I)},[e,l]);const u=zA(),h=H("shapeSvgDefs",()=>{const S=new Map;for(const y of ut(e.shapeUtils)){if(!y)return;const b=y.getCanvasSvgDefs();for(const{key:P,component:C}of b)S.has(P)||S.set(P,d.jsx(C,{},P))}return[...S.values()]},[e]),p=H("debug_shapes",()=>bt.hideShapes.get(),[bt]),f=H("debug_svg",()=>bt.debugSvg.get(),[bt]),g=H("debug_geometry",()=>bt.debugGeometry.get(),[bt]),m=H("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),v=H("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(Aq,{}),d.jsx(jq,{}),r&&d.jsx(r,{})]})}),n&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(n,{})}),d.jsx(vq,{}),d.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(Lq,{}),d.jsx(Rq,{}),p?null:f?d.jsx(Eq,{}):d.jsx(Tq,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:a,className:"tl-html-layer",children:[g?d.jsx(hq,{}):null,d.jsx(Cq,{}),d.jsx(wq,{}),d.jsx(xq,{}),d.jsx(bq,{}),o&&d.jsx(o,{}),d.jsx(Mq,{}),d.jsx(Pq,{}),d.jsx(Dq,{}),d.jsx(pq,{})]})}),d.jsx($q,{})]}),d.jsx(Sq,{})]})}function Sq(){const{InFrontOfTheCanvas:t}=ot();return t?d.jsx(t,{}):null}function vq(){const t=z(),e=H("gridSize",()=>t.getDocumentSettings().gridSize,[t]),{x:n,y:r,z:o}=H("camera",()=>t.getCamera(),[t]),s=H("isGridMode",()=>t.getInstanceState().isGridMode,[t]),{Grid:i}=ot();return i&&s?d.jsx(i,{x:n,y:r,z:o,size:e}):null}function xq(){const t=z(),e=H("scribbles",()=>t.getInstanceState().scribbles,[t]),n=H("zoomLevel",()=>t.getZoomLevel(),[t]),{Scribble:r}=ot();return r&&e.length?e.map(o=>d.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:n},o.id)):null}function wq(){const t=z(),e=H("brush",()=>t.getInstanceState().brush,[t]),{Brush:n}=ot();return n&&e?d.jsx(n,{className:"tl-user-brush",brush:e}):null}function bq(){const t=z(),e=H("zoomBrush",()=>t.getInstanceState().zoomBrush,[t]),{ZoomBrush:n}=ot();return n&&e?d.jsx(n,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function Pq(){const t=z(),e=H("snapLines",()=>t.snaps.getIndicators(),[t]),n=H("zoomLevel",()=>t.getZoomLevel(),[t]),{SnapIndicator:r}=ot();return r&&e.length>0?e.map(o=>d.jsx(r,{className:"tl-user-snapline",line:o,zoom:n},o.id)):null}function Cq(){const t=z(),e=H("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(_q,{shapeId:e}):null}function _q({shapeId:t}){const e=z(),{Handles:n}=ot(),r=H("zoomLevel",()=>e.getZoomLevel(),[e]),o=H("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),s=H("handles transform",()=>e.getShapePageTransform(t),[e,t]),i=H("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=H("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(Iq,{shapeId:t,handle:l,zoom:r,isCoarse:o},l.id))})})}function Iq({shapeId:t,handle:e,zoom:n,isCoarse:r}){const o=sq(t,e.id),{Handle:s}=ot();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 Eq(){const t=z();return H("rendering shapes",()=>t.getRenderingShapes(),[t]).map(n=>d.jsxs(w.Fragment,{children:[d.jsx(ej,{...n}),d.jsx(Oq,{id:n.id,mode:"iframe"})]},n.id+"_fragment"))}function kq(){const t=z(),e=w.useRef(new Set);return ni("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 Tq(){const t=z(),e=H("rendering shapes",()=>t.getRenderingShapes(),[t]);return d.jsxs(d.Fragment,{children:[e.map(n=>d.jsx(ej,{...n},n.id+"_shape")),Ge.isSafari&&d.jsx(kq,{})]})}function Mq(){const t=z(),{ShapeIndicator:e}=ot(),n=H("hinting shape ids",()=>hw(t.getHintingShapeIds()),[t]);return!n.length||!e?null:n.map(r=>d.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function Aq(){return d.jsxs("g",{id:"cursor",children:[d.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),d.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function jq(){return d.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function Oq({id:t,mode:e}){const n=z(),[r,o]=w.useState(null),s=H("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=is("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 Dq(){const t=z(),e=H("selection rotation",()=>t.getSelectionRotation(),[t]),n=H("selection bounds",()=>t.getSelectionRotatedPageBounds(),[t]),{SelectionForeground:r}=ot();return!n||!r?null:d.jsx(r,{bounds:n,rotation:e})}function Rq(){const t=z(),e=H("selection rotation",()=>t.getSelectionRotation(),[t]),n=H("selection bounds",()=>t.getSelectionRotatedPageBounds(),[t]),{SelectionBackground:r}=ot();return!n||!r?null:d.jsx(r,{bounds:n,rotation:e})}function Lq(){const{OnTheCanvas:t}=ot();return t?d.jsx(t,{}):null}function $q(){const t=z(),e=H("camera state",()=>t.getCameraState(),[t]);return d.jsx("div",{className:le("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function Fq({className:t,zoom:e,point:n,color:r,viewport:o,opacity:s=1}){const i=w.useRef(null);return Yl(i,Bt(n.x,o.minX+5/e,o.maxX-5/e),Bt(n.y,o.minY+5/e,o.maxY-5/e),1/e,x.Angle(o.center,n)),d.jsxs("svg",{ref:i,className:le("tl-overlays__item",t),children:[d.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),d.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const rI=w.memo(function({className:e,zoom:n,point:r,color:o,name:s,chatMessage:i}){const a=w.useRef(null);return Yl(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n),r?d.jsxs("div",{ref:a,className:le("tl-overlays__item",e),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:"#cursor",color:o})}),i?d.jsxs(d.Fragment,{children:[s&&d.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),d.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&d.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function rj(){return Xl(w.useId())}function Xl(t){return t.replace(/:/g,"_")}function Nq({x:t,y:e,z:n,size:r}){const o=`grid_${rj()}`,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?kl(n,[a,l],[0,1]):1;return d.jsx("pattern",{id:`${o}_${c}`,width:h,height:h,patternUnits:"userSpaceOnUse",children:d.jsx("circle",{className:"tl-grid-dot",cx:g,cy:m,r:1,opacity:v})},u)})}),i.map(({step:a},l)=>d.jsx("rect",{width:"100%",height:"100%",fill:`url(#${o}_${a})`},l))]})}function zq({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=KY.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 Bq=({children:t})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:t}),Uq=()=>{const{Spinner:t}=ot();return d.jsx(P1,{children:t?d.jsx(t,{}):null})};function i1(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+=Nn(r,o);return e?`M${Nn(t[0],t[1])}Q${je(t[1])}${Nn(t[1],t[2])}T${s}${Nn(t[n-1],t[0])}${Nn(t[0],t[1])}Z`:`M${je(t[0])}Q${je(t[1])}${Nn(t[1],t[2])}${t.length>3?"T":""}${s}L${je(t[n-1])}`}function oI({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:i1(t.points,!1),stroke:n??`var(--color-${t.color})`,fill:"none",strokeWidth:8/e,opacity:r??t.opacity})}):null}function oj({bounds:t,rotation:e}){const n=w.useRef(null);return Yl(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 Hq({bounds:t,rotation:e}){const n=z(),r=w.useRef(null),o=H("only selected shape",()=>n.getOnlySelectedShape(),[n]),s=o?n.getShapeUtil(o).expandSelectionOutlinePx(o):0;return Yl(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 Kq=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),Wq=({shape:t,util:e})=>Cg("Indicator: "+t.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(t.id))),Gq=({editor:t,id:e})=>{const n=H("shape for indicator",()=>t.store.get(e),[t,e]),{ShapeIndicatorErrorFallback:r}=ot();return!n||n.isLocked?null:d.jsx($u,{fallback:r,onError:o=>t.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(Wq,{shape:n,util:t.getShapeUtil(n)},n.id)})},sI=w.memo(function({shapeId:e,className:n,color:r,hidden:o,opacity:s}){const i=z(),a=w.useRef(null);return ni("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(Gq,{editor:i,id:e})})})}),Vq=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),sj=w.memo(function(){const e=z(),n=w.useRef(new Set),r=H("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=H("rendering shapes",()=>e.getRenderingShapes(),[e]),{ShapeIndicator:s}=ot();return s?o.map(({id:i})=>d.jsx(s,{shapeId:i,hidden:!r.has(i)},i+"_indicator")):null});function Yq({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 Xq({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=Kr(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=Kr(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 qq({className:t,line:e,zoom:n}){return d.jsx("svg",{className:le("tl-overlays__item",t),children:e.type==="points"?d.jsx(Yq,{...e,zoom:n}):e.type==="gaps"?d.jsx(Xq,{...e,zoom:n}):null})}function a1(){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 Zq=()=>null;function ij(t,e){const n=w.useRef(t);return e(t,n.current)?n.current:(n.current=t,t)}const Qq=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:pB(t,e));function Us(t){return ij(t,Qq)}const Jq=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:wT(t,e));function dd(t){return ij(t,Jq)}const aj=w.createContext(null);function eZ({overrides:t={},children:e}){const n=dd(t),r=w.useMemo(()=>({Background:$Y,SvgDefs:Zq,Brush:Dy,ZoomBrush:Dy,CollaboratorBrush:Dy,Cursor:rI,CollaboratorCursor:rI,CollaboratorHint:Fq,CollaboratorShapeIndicator:sI,Grid:Nq,Scribble:oI,SnapIndicator:qq,Handles:Bq,Handle:zq,CollaboratorScribble:oI,ErrorFallback:cj,ShapeErrorFallback:Kq,ShapeIndicatorErrorFallback:Vq,Spinner:a1,SelectionBackground:oj,SelectionForeground:Hq,ShapeIndicators:sj,ShapeIndicator:sI,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:yq,LoadingScreen:Uq,...n}),[n]);return d.jsx(aj.Provider,{value:r,children:e})}function ot(){const t=w.useContext(aj);if(!t)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return t}const Ag={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 lj(){Ag.hardReset()}function tZ(){Ag.refreshPage()}const nZ="https://github.com/tldraw/tldraw/issues/new",cj=({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=ot().Canvas??null}catch{}const u=t instanceof Error?t.message:String(t),h=t instanceof Error?t.stack:null,p=H("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=()=>{tZ()},S=async()=>{lj()},y=new URL(nZ);return y.searchParams.set("title",u),y.searchParams.set("labels","bug"),y.searchParams.set("body",`Hey, I ran into an error while using tldraw:
|
|
93
|
-
|
|
94
|
-
\`\`\`js
|
|
95
|
-
${h??u}
|
|
96
|
-
\`\`\`
|
|
97
|
-
|
|
98
|
-
My browser: ${navigator.userAgent}`),d.jsxs("div",{ref:n,className:le("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[d.jsx("div",{className:"tl-error-boundary__overlay"}),e&&d.jsx(t1,{onError:Mu,fallback:()=>null,children:d.jsx(sd.Provider,{value:e,children:d.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?d.jsx(c,{}):null})})}),d.jsx("div",{className:le("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Are you sure?"}),d.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),d.jsx("button",{className:"tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Something's gone wrong."}),d.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",d.jsx("a",{href:y.toString(),children:"create a GitHub issue"})," or"," ",d.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&d.jsxs(d.Fragment,{children:["Message:",d.jsx("h4",{children:d.jsx("code",{children:u})}),"Stack trace:",d.jsxs("div",{className:"tl-error-boundary__content__error",children:[d.jsx("pre",{children:d.jsx("code",{children:h??u})}),d.jsx("button",{onClick:m,children:s?"Copied!":"Copy"})]})]}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),d.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[d.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),d.jsx("button",{className:"tl-error-boundary__refresh",onClick:v,children:"Refresh Page"})]})]})]})})]})},uj="TLDRAW_USER_DATA_v3",dj=Pe({id:me,name:me.nullable().optional(),locale:me.nullable().optional(),color:me.nullable().optional(),colorScheme:kg("light","dark","system").optional(),animationSpeed:fe.nullable().optional(),edgeScrollSpeed:fe.nullable().optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional(),isDynamicSizeMode:we.nullable().optional(),isPasteAtCursorMode:we.nullable().optional()}),Vo={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},l1=Math.max(...Object.values(Vo));function rZ(t){t.version<Vo.AddAnimationSpeed&&(t.user.animationSpeed=1),t.version<Vo.AddIsSnapMode&&(t.user.isSnapMode=!1),t.version<Vo.MakeFieldsNullable,t.version<Vo.AddEdgeScrollSpeed&&(t.user.edgeScrollSpeed=1),t.version<Vo.AddExcalidrawSelectMode&&(t.user.isWrapMode=!1),t.version<Vo.AllowSystemColorScheme&&(t.user.isDarkMode===!0?t.user.colorScheme="dark":t.user.isDarkMode===!1&&(t.user.colorScheme="light"),delete t.user.isDarkMode),t.version<Vo.AddDynamicSizeMode&&(t.user.isDynamicSizeMode=!1),t.version<Vo.AddPasteAtCursor&&(t.user.isPasteAtCursorMode=!1),t.version=l1}const g0=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function hj(){return g0[Math.floor(Math.random()*g0.length)]}function oZ(){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 Wo=Object.freeze({name:"New User",locale:jY(),color:hj(),edgeScrollSpeed:1,animationSpeed:oZ()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"system"});function Ny(){return{id:ze(),color:hj()}}function pj(t){if(t===null||typeof t!="object"||!("version"in t)||!("user"in t)||typeof t.version!="number")return Ny();const e=nt(t);rZ(e);try{return dj.validate(e.user)}catch{return Ny()}}function sZ(){const t=JSON.parse(xw(uj)||"null")??null;return pj(t)}const jg=It("globalUserData",null);function iZ(){ww(uj,JSON.stringify({version:l1,user:jg.get()}))}function fj(t){dj.validate(t),jg.set(t),iZ(),lZ()}const aZ=typeof process<"u"&&!1,gl=typeof BroadcastChannel<"u"&&!aZ?new BroadcastChannel("tldraw-user-sync"):null;gl==null||gl.addEventListener("message",t=>{const e=t.data;(e==null?void 0:e.type)===mj&&(e==null?void 0:e.origin)!==gj()&&jg.set(pj(e.data))});let zy=null;function gj(){return zy===null&&(zy=ze()),zy}const mj="tldraw-user-preferences-change";function lZ(){gl==null||gl.postMessage({type:mj,origin:gj(),data:{user:yj(),version:l1}})}function yj(){let t=jg.get();return t||(t=sZ(),fj(t)),t}const cZ=W("defaultLocalStorageUserPrefs",()=>yj());function Sj(t={}){return{userPreferences:t.userPreferences??cZ,setUserPreferences:t.setUserPreferences??fj}}var vj={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function o(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function s(l,c,u,h,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new o(u,h||l,p),g=n?n+c:c;return l._events[g]?l._events[g].fn?l._events[g]=[l._events[g],f]:l._events[g].push(f):(l._events[g]=f,l._eventsCount++),l}function i(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],u,h;if(this._eventsCount===0)return c;for(h in u=this._events)e.call(u,h)&&c.push(n?h.slice(1):h);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=n?n+c:c,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var p=0,f=h.length,g=new Array(f);p<f;p++)g[p]=h[p].fn;return g},a.prototype.listenerCount=function(c){var u=n?n+c:c,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,u,h,p,f,g){var m=n?n+c:c;if(!this._events[m])return!1;var v=this._events[m],S=arguments.length,y,b;if(v.fn){switch(v.once&&this.removeListener(c,v.fn,void 0,!0),S){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,u),!0;case 3:return v.fn.call(v.context,u,h),!0;case 4:return v.fn.call(v.context,u,h,p),!0;case 5:return v.fn.call(v.context,u,h,p,f),!0;case 6:return v.fn.call(v.context,u,h,p,f,g),!0}for(b=1,y=new Array(S-1);b<S;b++)y[b-1]=arguments[b];v.fn.apply(v.context,y)}else{var P=v.length,C;for(b=0;b<P;b++)switch(v[b].once&&this.removeListener(c,v[b].fn,void 0,!0),S){case 1:v[b].fn.call(v[b].context);break;case 2:v[b].fn.call(v[b].context,u);break;case 3:v[b].fn.call(v[b].context,u,h);break;case 4:v[b].fn.call(v[b].context,u,h,p);break;default:if(!y)for(C=1,y=new Array(S-1);C<S;C++)y[C-1]=arguments[C];v[b].fn.apply(v[b].context,y)}}return!0},a.prototype.on=function(c,u,h){return s(this,c,u,h,!1)},a.prototype.once=function(c,u,h){return s(this,c,u,h,!0)},a.prototype.removeListener=function(c,u,h,p){var f=n?n+c:c;if(!this._events[f])return this;if(!u)return i(this,f),this;var g=this._events[f];if(g.fn)g.fn===u&&(!p||g.once)&&(!h||g.context===h)&&i(this,f);else{for(var m=0,v=[],S=g.length;m<S;m++)(g[m].fn!==u||p&&!g[m].once||h&&g[m].context!==h)&&v.push(g[m]);v.length?this._events[f]=v.length===1?v[0]:v:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=n?n+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a})(vj);var uZ=vj.exports;const dZ=mi(uZ),ml="TLDRAW_TAB_ID_v2",as=globalThis.window;function hZ(){return as?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(as.navigator.platform)||Ge.isDarwin&&"ontouchend"in document:!1}const jf=as?as[ml]??DT(ml)??"TLDRAW_INSTANCE_STATE_V1_"+ze():"<error>";as&&(as[ml]=jf,hZ()?bw(ml,jf):RT(ml));as==null||as.addEventListener("beforeunload",()=>{bw(ml,jf)});const xj={Initial:0},Og=Math.max(...Object.values(xj));function pZ(t){t.version<xj.Initial,t.version=Og}const wj=Pe({version:fe,currentPageId:Ru.optional(),isFocusMode:we.optional(),exportBackground:we.optional(),isDebugMode:we.optional(),isToolLocked:we.optional(),isGridMode:we.optional(),pageStates:Wt(Pe({pageId:Ru,camera:Pe({x:fe,y:fe,z:fe}).optional(),selectedShapeIds:Wt(_r).optional(),focusedGroupId:_r.nullable().optional()})).optional()});function fZ(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!==Og&&(t=nt(t),pZ(t));try{return wj.validate(t)}catch(e){return console.warn(e),null}}function c1(t){const e=t.query.ids("page");return W("sessionStateSnapshot",()=>{const n=t.get(wn);if(!n)return null;const r=[...e.get()];return{version:Og,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(Xr.createId(o)),i=t.get(bo.createId(o));return{pageId:o,camera:{x:(i==null?void 0:i.x)??0,y:(i==null?void 0:i.y)??0,z:(i==null?void 0:i.z)??1},selectedShapeIds:(s==null?void 0:s.selectedShapeIds)??[],focusedGroupId:(s==null?void 0:s.focusedGroupId)??null}})}})}function m0(t,e,n){const r=fZ(e);if(!r)return;const o=lA(t.get(wn)),s=n!=null&&n.forceOverwrite?r:o,i=n!=null&&n.forceOverwrite?o:r,a=t.schema.types.instance.create({id:wn,...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=bo.createId(h.pageId),f=Xr.createId(h.pageId),g=t.get(p),m=t.get(f);t.put([bo.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)}),Xr.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 gZ(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!==wn)[0];if(!n)return null;const r={version:Og,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 wj.validate(r),r}catch{return null}}function bj(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:ou(i.value,(a,{typeName:l})=>t.scopedTypes.document.has(l))}}else r=e;const o=lA(t.get(wn)),s=Pj.get(t,c1).get();t.atomic(()=>{r.document&&t.loadStoreSnapshot(r.document),o&&t.update(wn,i=>({...i,...o})),s&&m0(t,s),r.session&&m0(t,r.session,{forceOverwrite:n==null?void 0:n.forceOverwriteSessionState})})}const Pj=new ko;function mZ(t){const n=Pj.get(t,c1).get();if(!n)throw new Error("Session state is not ready yet");return{document:t.getStoreSnapshot(),session:n}}function Cj(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 ui({children:t,className:e="",...n}){return d.jsx("svg",{...n,className:le("tl-svg-container",e),children:t})}function u1(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 hd(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 yZ(t,e,n){const r=[];let o;for(let s=0,i=n.length-1;s<i;s++)o=u1(t,e,n[s],n[s+1]),o&&r.push(o);return r.length===0?null:r}function d1(t,e,n){const r=[];let o;for(let s=1,i=n.length;s<i+1;s++)o=u1(t,e,n[s-1],n[s%n.length]),o&&r.push(o);return r.length===0?null:r}function SZ(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 y0(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=hd(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function iI(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=hd(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function hh(t,e,n){return(n.y-t.y)*(e.x-t.x)>(e.y-t.y)*(n.x-t.x)}function h1(t,e,n,r){return hh(t,n,r)!==hh(e,n,r)&&hh(t,e,n)!==hh(t,e,r)}function aI(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=By(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=By(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=u1(r,o,s,i);if(h!==null){const p=By(h);n.has(p)||n.set(p,h)}}}return n.size===0?null:vZ([...n.values()])}function By(t){return`${t.x},${t.y}`}function vZ(t){const e=x.Average(t);return t.sort((n,r)=>x.Angle(e,n)-x.Angle(e,r))}function _j(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],h1(n,r,o,s))return!0}return!1}function xZ(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],h1(n,r,o,s))return!0}return!1}class ts extends Ci{constructor(n){super({...n,isClosed:!1,isFilled:!1});E(this,"start");E(this,"end");E(this,"d");E(this,"u");E(this,"ul");const{start:r,end:o}=n;this.start=r,this.end=o,this.d=r.clone().sub(o),this.u=this.d.clone().uni(),this.ul=this.u.len()}getLength(){return this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(n){const{start:r,end:o,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 h1(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 ql extends Ci{constructor(n){super({isClosed:!1,isFilled:!1,...n});E(this,"points");E(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:n}=this;for(let r=0,o=n.length-1;r<o;r++){const s=n[r],i=n[r+1];this._segments.push(new ts({start:s,end:i}))}this.isClosed&&this._segments.push(new ts({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 ql{constructor(e){super({...e}),this.isClosed=!0}}class gs 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)]});E(this,"x");E(this,"y");E(this,"w");E(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new Z(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:n,y:r,w:o,h:s}=this;return`M${n},${r} h${o} v${s} h-${o}z`}}class eo{constructor(e){this.editor=e}canSnap(e){return!0}canScroll(e){return!1}canBind(e){return!0}canEdit(e){return!1}canResize(e){return!0}canEditInReadOnly(e){return!1}canCrop(e){return!1}canBeLaidOut(e){return!0}providesBackgroundForChildren(e){return!1}hideResizeHandles(e){return!1}hideRotateHandle(e){return!1}hideSelectionBoundsBg(e){return!1}hideSelectionBoundsFg(e){return!1}isAspectRatioLocked(e){return!1}canReceiveNewChildrenOfType(e,n){return!1}canDropShapes(e,n){return!1}expandSelectionOutlinePx(e){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(e){return{}}getHandleSnapGeometry(e){return{}}getText(e){}}E(eo,"props"),E(eo,"migrations"),E(eo,"type");function Yr(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 lI({bounds:t,className:e}){const n=z(),r=H("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}=Yr(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 sp extends eo{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const n=this.editor.getSortedChildIdsForParent(e.id);return n.length===0?new gs({width:1,height:1,isFilled:!1}):new ro({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 ql({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(ui,{id:e.id,children:d.jsx(lI,{className:"tl-group",bounds:i})})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx(lI,{className:"",bounds:n})}onChildrenChange(e){const n=this.editor.getSortedChildIdsForParent(e.id);if(n.length===0){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([e.id]);return}else if(n.length===1){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(n,e.parentId),this.editor.deleteShapes([e.id]);return}}}E(sp,"type","group"),E(sp,"props",xA),E(sp,"migrations",wA);const Ij=[sp],wZ=new Set(Ij.map(t=>t.type));function Ej(t){const e=[...Ij],n=new Set;for(const r of t){if(wZ.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 kj(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 no(o,e);return Le(a.ok),await t(a)}catch(a){return console.error(a),null}})();return n.set(o,i),i}}const Dg=kj(async t=>await os.blobToDataUrl(await t.blob())),bZ=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,PZ=/@font-face\s*{([^}]+)}/gi,Tj=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,CZ=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function _Z(t){return Array.from(t.matchAll(bZ),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function Mj(t,e){return Array.from(t.matchAll(PZ),n=>{const r=n[1],o=Array.from(r.matchAll(Tj),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(CZ),i=>(i[1]||i[2]||i[3]).toLowerCase()));return{fontFace:r,urls:o,fontFamilies:s}})}function IZ(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 Aj(t){return!(t.startsWith("-")||t.startsWith("animation")||t.startsWith("transition")||t==="cursor"||t==="pointer-events"||t==="user-select"||t==="touch-action")}function EZ(t,e){return{imports:_Z(t),fontFaces:Mj(t,e)}}function kZ(t){return Array.from(t.matchAll(Tj),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}const TZ=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 jj(t){return TZ.has(t)}var MZ=Object.create,Oj=Object.defineProperty,AZ=Object.getOwnPropertyDescriptor,jZ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Dj=t=>{throw TypeError(t)},Rj=(t,e,n)=>e in t?Oj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,OZ=t=>[,,,MZ(null)],Lj=["class","method","getter","setter","accessor","field","value","get","set"],$j=t=>t!==void 0&&typeof t!="function"?Dj("Function expected"):t,DZ=(t,e,n,r,o)=>({kind:Lj[t],name:e,metadata:r,addInitializer:s=>n._?Dj("Already initialized"):o.push($j(s||null))}),RZ=(t,e)=>Rj(e,jZ("metadata"),t[3]),LZ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},$Z=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=Lj[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,AZ(o,n)),S=r.length-1;S>=0;S--)l=DZ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,$j(i)&&(v[g]=i);return v&&Oj(o,n,v),o},ph=(t,e,n)=>Rj(t,typeof e!="symbol"?e+"":e,n),Fj,Rg;Fj=[Un];class p1{constructor(){LZ(Rg,5,this),ph(this,"fontFacesPromise",null),ph(this,"foundFontNames",new Set),ph(this,"fontFacesToEmbed",new Set),ph(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){Le(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=FZ()}onFontFamilyValue(e){Le(this.fontFacesPromise,"FontEmbedder not started");const n=IZ(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=Dg(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}}Rg=OZ();$Z(Rg,1,"onFontFamilyValue",Fj,p1);RZ(Rg,p1);async function FZ(){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(Mj(r.cssText,e.href??document.baseURI)):r instanceof CSSImportRule&&t.push(S0(r.href));else e.href&&t.push(S0(e.href))}return ye(await Promise.all(t)).flat()}const S0=kj(async t=>{const e=EZ(await t.text(),t.url),n=await Promise.all(e.imports.map(({url:r})=>S0(new URL(r,t.url).href)));return[...e.fontFaces,...ye(n).flat()]});function Nj(t){if(t.shadowRoot)return t.shadowRoot.childNodes;if(UZ(t)){const e=t.assignedNodes();if(e!=null&&e.length)return e}return t.childNodes}function*v0(t){for(const e of Nj(t))NZ(e)&&(yield e)}function Lg(t){var e;return((e=t.ownerDocument)==null?void 0:e.defaultView)??globalThis}function NZ(t){return t instanceof Lg(t).Element}function zZ(t){return t instanceof Lg(t).ShadowRoot}function BZ(t){return"getRootNode"in t&&zZ(t.getRootNode())}function UZ(t){return BZ(t)&&t instanceof Lg(t).HTMLSlotElement}function HZ(t){return t.style}function f1(t,e){return Lg(t).getComputedStyle(t,e)}const Xi={};class KZ{constructor(e){E(this,"styles",new Map);E(this,"fonts",new p1);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const n=Array.from(v0(e));for(;n.length;){const r=n.pop();n.push(...v0(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:n=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const o=n?YZ(e.tagName.toLowerCase()):Xi,s=r?((a=this.styles.get(e.parentElement))==null?void 0:a.self)??Xi:Xi,i={self:WZ(e,{defaultStyles:o,parentStyles:s}),before:cI(e,"::before"),after:cI(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=kZ(s);i.length!==0&&e.push(...i.map(async({url:a,original:l})=>{const c=await Dg(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 Nj(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 {${uI(r.before)}}
|
|
99
|
-
`),r.after&&(e+=`.${s}::after {${uI(r.after)}}
|
|
100
|
-
`)}const o=HZ(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(){VZ()}}function WZ(t,{defaultStyles:e,parentStyles:n}){return t.computedStyleMap?zj(t.computedStyleMap(),{defaultStyles:e,parentStyles:n}):g1(f1(t),{defaultStyles:e,parentStyles:n})}function cI(t,e){const n=f1(t,e),r=n.getPropertyValue("content");if(!(r===""||r==="none"))return g1(n,{defaultStyles:Xi,parentStyles:Xi})}function zj(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t.keys()){if(!Aj(o))continue;const s=t.get(o).toString();e[o]!==s&&(n[o]===s&&jj(o)||(r[o]=s))}return r}function g1(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t){if(!Aj(o))continue;const s=t.getPropertyValue(o);e[o]!==s&&(n[o]===s&&jj(o)||(r[o]=s))}return r}function uI(t){let e="";for(const[n,r]of Object.entries(t))e+=`${n}: ${r};`;return e}let yl;const dI={};function GZ(){if(!yl){const t=document.createElement("iframe");t.style.display="none",document.body.appendChild(t);const e=sr(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),yl={iframe:t,foreignObject:r,document:e}}return yl}function VZ(){yl&&(document.body.removeChild(yl.iframe),yl=void 0)}const hI={defaultStyles:Xi,parentStyles:Xi};function YZ(t){let e=dI[t];if(!e){const{foreignObject:n,document:r}=GZ(),o=r.createElement(t);n.appendChild(o),e=o.computedStyleMap?zj(o.computedStyleMap(),hI):g1(f1(o),hI),n.removeChild(o),dI[t]=e}return e}function XZ(t,e){Array.from(t.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function pI(t,e){return t.replaceWith(e),e}async function au(t,e){const n=document.createElement("img");e&&XZ(e,n),n.setAttribute("src",t??"data:"),n.setAttribute("decoding","sync"),n.setAttribute("loading","eager");try{await n.decode()}catch{}return n}async function qZ(t){try{const e=t.toDataURL();return await au(e,t)}catch{return await au(null,t)}}async function ZZ(t){try{const e=await lr.getVideoFrameAsDataUrl(t);return au(e,t)}catch(e){console.error("Could not get video frame",e)}if(t.poster){const e=await Dg(t.poster);return au(e,t)}return au(null,t)}async function Bj(t){if(t instanceof HTMLCanvasElement)return pI(t,await qZ(t));if(t instanceof HTMLVideoElement)return pI(t,await ZZ(t));if(t instanceof HTMLImageElement){const e=t.currentSrc||t.src,n=await Dg(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(v0(t),e=>Bj(e)))}function $g(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 m1=w.createContext(null);function QZ({context:t,editor:e,children:n}){return d.jsx(sd.Provider,{value:e,children:d.jsx(m1.Provider,{value:t,children:n})})}function pd(){return w.useContext(m1)}function JZ(){const t=w.useContext(m1),[e]=w.useState(pw);return w.useEffect(()=>(t==null||t.waitUntil(e),()=>{e.resolve()}),[e,t]),$g(()=>{e.resolve()})}var eQ=Object.create,Uj=Object.defineProperty,tQ=Object.getOwnPropertyDescriptor,nQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Hj=t=>{throw TypeError(t)},Kj=(t,e,n)=>e in t?Uj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,rQ=t=>[,,,eQ(null)],Wj=["class","method","getter","setter","accessor","field","value","get","set"],Gj=t=>t!==void 0&&typeof t!="function"?Hj("Function expected"):t,oQ=(t,e,n,r,o)=>({kind:Wj[t],name:e,metadata:r,addInitializer:s=>n._?Hj("Already initialized"):o.push(Gj(s||null))}),sQ=(t,e)=>Kj(e,nQ("metadata"),t[3]),iQ=(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},aQ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=Wj[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,tQ(o,n)),S=r.length-1;S>=0;S--)l=oQ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,Gj(i)&&(v[g]=i);return v&&Uj(o,n,v),o},fI=(t,e,n)=>Kj(t,typeof e!="symbol"?e+"":e,n),Vj,Fg;Vj=[Un];class y1{constructor(e){this.maxDelayTimeMs=e,iQ(Fg,5,this),fI(this,"isResolved",!1),fI(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 Nv(0)}async resolve(){const e=Nv(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}}Fg=rQ();aQ(Fg,1,"waitUntil",Vj,y1);sQ(Fg,y1);function lQ(t,e,n={}){var S,y;if(!window.document)throw Error("No document");const{scale:r=1,background:o=!1,padding:s=t.options.defaultSvgPadding,preserveAspectRatio:i}=n,a=n.darkMode??t.user.getIsDarkMode(),l=t.getShapeAndDescendantIds(e),c=t.getUnorderedRenderingShapes(!1).filter(({id:b})=>l.has(b));let u=null;if(n.bounds)u=n.bounds;else for(const{id:b}of c){const P=t.getShapeMaskedPageBounds(b);P&&(u?u.union(P):u=P.clone())}if(!u)return;const h=e.length===1&&t.isShapeOfType(t.getShape(e[0]),"frame")?e[0]:null;h||u.expandBy(s);const p=u.width*r,f=u.height*r;try{(y=(S=document.body).focus)==null||y.call(S)}catch{}const g=new y1(t.options.maxExportDelayMs),m=pw();return g.waitUntil(m),{jsx:d.jsx(cQ,{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 cQ({editor:t,preserveAspectRatio:e,scale:n,bbox:r,background:o,singleFrameShapeId:s,isDarkMode:i,renderingShapes:a,onMount:l,waitUntil:c}){const u=bs({isDarkMode:i}),[h,p]=w.useState({}),f=$g(y=>{Jr(h,y.key)||c((async()=>{const b=await y.getElement();b&&li.flushSync(()=>p(P=>({...P,[y.key]:b})))})())}),g=w.useMemo(()=>({isDarkMode:i,waitUntil:c,addExportDef:f}),[i,c,f]),[m,v]=w.useState(null),S=w.useRef(!1);return w.useLayoutEffect(()=>{if(S.current)throw new Error("SvgExport should only render once - do not use with react strict mode");S.current=!0,(async()=>{const y={},b=a.map(async({id:C,opacity:I,index:k,backgroundIndex:_})=>{var j,O;if(C===s)return[];const T=t.getShape(C);if(t.isShapeOfType(T,"group"))return[];const M=[],D=t.getShapeUtil(T);if(D.toSvg||D.toBackgroundSvg){const[R,B]=await Promise.all([(j=D.toSvg)==null?void 0:j.call(D,T,g),(O=D.toBackgroundSvg)==null?void 0:O.call(D,T,g)]),L=t.getShapePageTransform(T);let G=L.toCssString();"scale"in T.props&&T.props.scale!==1&&(G=`${G} scale(${T.props.scale}, ${T.props.scale})`);const $=t.getShapeMask(T.id),U=$?q.From(q.Inverse(L)).applyToPoints($):null,Y=`mask_${Xl(T.id)}`;U&&(y[Y]=d.jsx("clipPath",{id:Y,children:d.jsx("path",{d:`M${U.map(({x:te,y:de})=>`${te},${de}`).join("L")}Z`})})),R&&M.push({zIndex:k,element:d.jsx("g",{transform:G,opacity:I,clipPath:$?`url(#${Y})`:void 0,children:R},`fg_${T.id}`)}),B&&M.push({zIndex:_,element:d.jsx("g",{transform:G,opacity:I,clipPath:$?`url(#${Y})`:void 0,children:B},`bg_${T.id}`)})}else M.push({zIndex:k,element:d.jsx(gI,{shape:T,util:D,component:tj,className:"tl-shape",bbox:r,opacity:I},`fg_${T.id}`)}),D.backgroundComponent&&M.push({zIndex:_,element:d.jsx(gI,{shape:T,util:D,component:nj,className:"tl-shape tl-shape-background",bbox:r,opacity:I},`bg_${T.id}`)});return M}),P=(await Promise.all(b)).flat();li.flushSync(()=>{v(P.sort((C,I)=>C.zIndex-I.zIndex).map(({element:C})=>C)),p(C=>({...C,...y}))})})()},[r,t,g,a,s]),w.useEffect(()=>{m!==null&&l()},[l,m]),d.jsx(QZ,{editor:t,context:g,children:d.jsxs("svg",{preserveAspectRatio:e,direction:"ltr",width:r.width*n,height:r.height*n,viewBox:`${r.minX} ${r.minY} ${r.width} ${r.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:o?s?u.solid:u.background:"transparent"},"data-color-mode":i?"dark":"light",className:`tl-container tl-theme__force-sRGB ${i?"tl-theme__dark":"tl-theme__light"}`,children:[d.jsx("defs",{children:Object.entries(h).map(([y,b])=>d.jsx(w.Fragment,{children:b},y))}),m]})})}function gI({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(t1,{fallback:()=>null,children:d.jsx("foreignObject",{x:o.minX,y:o.minY,width:o.w,height:o.h,className:"tl-shape-foreign-object",children:d.jsx("div",{className:n,"data-shape-type":t.type,style:{clipPath:i.getShapeClipPath(t.id),transform:a.toCssString(),width:c,height:u,opacity:s},children:d.jsx(r,{shape:t,util:e})})})})}async function uQ(t,e,n={}){const r=lQ(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=lT(s);try{li.flushSync(()=>{i.render(r.jsx)}),await r.exportDelay.resolve();const a=s.firstElementChild;return Le(a instanceof SVGSVGElement,"Expected an SVG element"),await dQ(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{i.unmount(),o.removeChild(s)},0)}}async function dQ(t){const e=[...t.querySelectorAll("foreignObject.tl-shape-foreign-object > *")];if(!e.length)return;const n=new KZ(t);try{n.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(s=>Bj(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 Wr={menus:It("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()}}},x0=new qB,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"};function mI(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 pQ{constructor(e){E(this,"map");this.map=new Map(e)}get(e){return this.map.get(e)}getAsKnownValue(e){const n=this.get(e);if(n&&n.type!=="mixed")return n.value}get size(){return this.map.size}equals(e){if(this.size!==e.size)return!1;const n=new Set;for(const[r,o]of this){if(!mI(o,e.get(r)))return!1;n.add(r)}for(const[r,o]of e)if(!n.has(r)&&!mI(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 w0 extends pQ{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 fQ(t,e,n){return no(t).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:n})})}const gQ="https://cdn.tldraw.com";function Vs(){return`${gQ}/${RA}`}function mQ(t){switch(t.type){case"shapes":return`s${t.shapeIds.map(n=>Uy(n.slice(6))).join(".")}`;case"page":return"p"+Uy(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+="."+Uy(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=>Be(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 Uy(t){return encodeURIComponent(t).replace(/\./g,"%2E")}function SQ(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 fh(t,e,n){if(n.length===0)return[];const r=new Map;for(const s of ye(n.map(i=>t.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:ye(t.getSortedChildIdsForParent(i).map(a=>t.getShape(a))),moving:new Set}),r.get(i).moving.add(s)}const o=[];switch(e){case"toBack":{r.forEach(({moving:s,children:i})=>vQ(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>xQ(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>wQ(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>bQ(s,i,o));break}}return o}function vQ(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=Tl(o,s,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function xQ(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=Tl(o,s,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function wQ(t,e,n){var s;const r=e.length;if(t.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=t.has(e[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:l}=o;Tl(e[i].index,(s=e[i+1])==null?void 0:s.index,i-l).forEach((c,u)=>n.push({...e[l+u],index:c})),o={name:"skipping"};break}}}}function bQ(t,e,n){var s;const r=e.length;if(t.size===r)return;let o={name:"skipping"};for(let i=r-1;i>-1;i--){const a=t.has(e[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;Tl((s=e[i-1])==null?void 0:s.index,e[i].index,o.selectIndex-i).forEach((l,c)=>{n.push({...e[i+c+1],index:l})}),o={name:"skipping"};break}}}}function Yj({editor:t,ids:e}){const n=ye(e.map(i=>t.getShape(i))),r=t.getShapesSharedRotation(e),o=t.getShapesRotatedPageBounds(e);if(!o)return null;const s=o.center.clone().rotWith(o.point,r);return{pageCenter:s,initialCursorAngle:s.angle(t.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:n.map(i=>({shape:i,initialPagePoint:t.getShapePageTransform(i.id).point()}))}}function ip({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=$n(l.parentId)?e.getShapePageTransform(l.parentId):q.Identity(),h=x.RotWith(c,o??s,t),p=q.applyToPoint(q.Inverse(u),h),f=oi(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 PQ=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 W("arrowBindingsIndex",(s,i)=>{if(Vi(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(y=>y.id!==f.id);m!=null&&m.length?c.set(f.fromId,m):c.delete(f.fromId);const v=c.get(f.toId),S=v==null?void 0:v.filter(y=>y.id!==f.id);S!=null&&S.length?c.set(f.toId,S):c.delete(f.toId)}function h(f){c??(c=new Map(a));let g=c.get(f);return g?g===a.get(f)&&(g=g.slice(0),c.set(f,g)):(g=[],c.set(f,g)),g}function p(f){h(f.fromId).push(f),h(f.toId).push(f)}for(const f of l){for(const g of 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 CQ(t,e,n){const r=t.getShapeMaskedPageBounds(e);return r===void 0?!0:!n.includes(r)}const _Q=t=>{function e(n){const r=n.getCurrentPageShapeIds(),o=n.getViewportPageBounds(),s=new Set;return r.forEach(i=>{CQ(n,i,o)&&s.add(i)}),s}return W("getCulledShapes",n=>{if(Vi(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})},IQ=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 W("parentsToChildrenWithIndexes",(o,s)=>{if(Vi(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))nl(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(nl(g)&&nl(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))nl(f)&&(l(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const h of c){const p=ye(h.map(f=>t.get(f)));p.sort(cn),h.splice(0,h.length,...p.map(f=>f.id))}return a??o})},Hy=(t,e,n)=>{for(;!Dn(n.parentId);){const r=t.get(n.parentId);if(!r)return!1;n=r}return n.parentId===e},EQ=(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=>Hy(t,s,t.get(i))))}return W("_shapeIdsInCurrentPage",(s,i)=>{if(Vi(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 tp(s);for(const h of l){for(const p of Object.values(h.added))nl(p)&&Hy(t,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))nl(f)&&(Hy(t,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(h.removed))$n(p)&&c.remove(p)}const u=c.get();return u?Bc(u.value,u.diff):s})};var kQ=Object.create,Xj=Object.defineProperty,TQ=Object.getOwnPropertyDescriptor,MQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),qj=t=>{throw TypeError(t)},Zj=(t,e,n)=>e in t?Xj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,AQ=t=>[,,,kQ(null)],Qj=["class","method","getter","setter","accessor","field","value","get","set"],Jj=t=>t!==void 0&&typeof t!="function"?qj("Function expected"):t,jQ=(t,e,n,r,o)=>({kind:Qj[t],name:e,metadata:r,addInitializer:s=>n._?qj("Already initialized"):o.push(Jj(s||null))}),OQ=(t,e)=>Zj(e,MQ("metadata"),t[3]),DQ=(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},eO=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=Qj[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,TQ(o,n)),S=r.length-1;S>=0;S--)l=jQ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,Jj(i)&&(v[g]=i);return v&&Xj(o,n,v),o},Aa=(t,e,n)=>Zj(t,typeof e!="symbol"?e+"":e,n),tO,nO,fd;const RQ=40;nO=[Un],tO=[Un];class Ng{constructor(e){this.editor=e,DQ(fd,5,this),Aa(this,"_clickId",""),Aa(this,"_clickTimeout"),Aa(this,"_clickScreenPoint"),Aa(this,"_previousScreenPoint"),Aa(this,"_clickState","idle"),Aa(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)>RQ**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"}}fd=AQ();eO(fd,1,"_getClickTimeout",nO,Ng);eO(fd,1,"cancelDoubleClickTimeout",tO,Ng);OQ(fd,Ng);class LQ{constructor(e){E(this,"_isEdgeScrolling",!1);E(this,"_edgeScrollDuration",-1);this.editor=e}updateEdgeScrolling(e){const{editor:n}=this,r=this.getEdgeScroll();if(r.x===0&&r.y===0)this._isEdgeScrolling&&(this._isEdgeScrolling=!1,this._edgeScrollDuration=0);else if(this._isEdgeScrolling||(this._isEdgeScrolling=!0,this._edgeScrollDuration=0),this._edgeScrollDuration+=e,this._edgeScrollDuration>n.options.edgeScrollDelay){const o=n.options.edgeScrollEaseDuration>0?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 $Q{constructor(e,n){E(this,"disposeSideEffectListener");this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(o,s)=>{o.isFocused!==s.isFocused&&this.updateContainerClass()});const r=e.getInstanceState().isFocused;n!==r&&e.updateInstanceState({isFocused:!!n}),this.updateContainerClass()}updateContainerClass(){const e=this.editor.getContainer();this.editor.getInstanceState().isFocused?e.classList.add("tl-container__focused"):e.classList.remove("tl-container__focused")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var e;(e=this.disposeSideEffectListener)==null||e.call(this)}}function Ic(t){return NQ}class FQ{constructor(){E(this,"length",0);E(this,"head",null);E(this,"tail",this)}push(e){return new S1(e,this)}toArray(){return ss}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const NQ=new FQ;class S1{constructor(e,n){E(this,"length");this.head=e,this.tail=n,this.length=n.length+1}push(e){return new S1(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 zQ{constructor(e){E(this,"store");E(this,"dispose");E(this,"state","recording");E(this,"pendingDiff",new UQ);E(this,"stacks",It("HistoryManager.stacks",{undos:Ic(),redos:Ic()},{isEqual:(e,n)=>e.undos===n.undos&&e.redos===n.redos}));E(this,"annotateError");E(this,"_isInBatch",!1);this.store=e.store,this.annotateError=e.annotateError??Mu,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:Ic()}));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=BQ[n.history]);try{if(this._isInBatch)return Eo(e),this;this._isInBatch=!0;try{Eo(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=WM(a),c=i0(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":su(c,[i0(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=mf();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")su(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=mf();return su(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:n.push({type:"diff",diff:o}),redos:i})),this}_mark(e){Eo(()=>{this.flushPendingDiff(),this.stacks.update(({undos:n,redos:r})=>({undos:n.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:Ic(),redos:Ic()}),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 BQ={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class UQ{constructor(){E(this,"diff",mf());E(this,"isEmptyAtom",It("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=mf(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){su(this.diff,[e]),this.isEmptyAtom.set(WM(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class HQ{constructor(e){E(this,"scribbleItems",new Map);E(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 KQ=Object.create,rO=Object.defineProperty,WQ=Object.getOwnPropertyDescriptor,GQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),oO=t=>{throw TypeError(t)},sO=(t,e,n)=>e in t?rO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,VQ=t=>[,,,KQ(null)],iO=["class","method","getter","setter","accessor","field","value","get","set"],aO=t=>t!==void 0&&typeof t!="function"?oO("Function expected"):t,YQ=(t,e,n,r,o)=>({kind:iO[t],name:e,metadata:r,addInitializer:s=>n._?oO("Already initialized"):o.push(aO(s||null))}),XQ=(t,e)=>sO(e,GQ("metadata"),t[3]),qQ=(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},zg=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=iO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,WQ(o,n)),S=r.length-1;S>=0;S--)l=YQ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,aO(i)&&(v[g]=i);return v&&rO(o,n,v),o},ZQ=(t,e,n)=>sO(t,e+"",n),lO,cO,uO,dO,va;const pe=t=>Math.round(t*10**8)/10**8;function Yo(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)&&Kr(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=Yo(t,l,n,r,Kr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function QQ(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=[W],uO=[W],cO=[W],lO=[W];class Zl{constructor(e){this.manager=e,qQ(va,5,this),ZQ(this,"editor"),this.editor=e.editor}getSnapPointsCache(){const{editor:e}=this;return e.store.createComputedCache("snapPoints",n=>{const r=e.getShapePageTransform(n.id);if(!r)return;const s=e.getShapeUtil(n).getBoundsSnapGeometry(n).points??e.getShapeGeometry(n).bounds.cornersAndCenter;if(!(!r||!s))return s.map((i,a)=>{const{x:l,y:c}=q.applyToPoint(r,i);return{x:l,y:c,id:`${n.id}:${a}`}})})}getSnapPoints(e){return this.getSnapPointsCache().get(e)??[]}getSnappablePoints(){const e=this.getSnapPointsCache(),n=this.manager.getSnappableShapes(),r=[];for(const o of n){const s=e.get(o);s&&r.push(...s)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:sr(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&&_c(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:Kr(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&&_c(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:Kr(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)})}return{horizontal:e,vertical:n}}snapTranslateShapes({lockedAxis:e,initialSelectionPageBounds:n,initialSelectionSnapPoints:r,dragDelta:o}){var v,S;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=n.clone().translate(o),l=r.map(({x:y,y:b},P)=>({id:"selection:"+P,x:y+o.x,y:b+o.y})),c=i,u=[],h=[],p=new x(s,s);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const f=new x(e==="x"?0:((v=u[0])==null?void 0:v.nudge)??0,e==="y"?0:((S=h[0])==null?void 0:S.nudge)??0);p.x=0,p.y=0,u.length=0,h.length=0,l.forEach(y=>{y.x+=f.x,y.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const g=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),m=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...m,...g]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:n,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var 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=cq(u)),c<0&&(u=lq(u)),s&&(a.center=e.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",f=yI(u,a),g=this.getSnappablePoints(),m=[],v=[],S=new x(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:f});const y=new x(h?0:((k=m[0])==null?void 0:k.nudge)??0,p?0:((_=v[0])==null?void 0:_.nudge)??0);if(o&&uq(u)&&y.len()!==0){const T=m.length&&v.length?Math.abs(y.x)<Math.abs(y.y)?"x":"y":m.length?"x":"y",M=e.aspectRatio;T==="x"?(v.length=0,y.y=y.x/M,(u==="bottom_left"||u==="top_right")&&(y.y=-y.y)):(m.length=0,y.x=y.y*M,(u==="bottom_left"||u==="top_right")&&(y.x=-y.x))}const b=x.Add(n,y),{box:P}=Z.Resize(e,r,s?b.x*2:b.x,s?b.y*2:b.y,o);s&&(P.center=e.center);const C=yI("any",P);m.length=0,v.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:C});const I=this.getPointSnapLines({nearestSnapsX:m,nearestSnapsY:v});return this.manager.setIndicators([...I]),{nudge:y}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:n,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of e)for(const a of n){const l=x.Sub(i,a),c=Math.abs(l.x),u=Math.abs(l.y);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(!_c(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 S={type:"gap_center",gap:a,nudge:c},y=r.find(({type:P})=>P==="gap_center"),b=y&&Kr(a.breadthIntersection[0],a.breadthIntersection[1],y.gap.breadthIntersection[0],y.gap.breadthIntersection[1]);y&&y.gap.length>a.length&&b?r[r.indexOf(y)]=S:(!y||!b)&&r.push(S)}const h=a.startNode.pageBounds.minX-a.length,p=e.maxX,f=h-p;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(!_c(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 S={type:"gap_center",gap:a,nudge:c},y=o.find(({type:P})=>P==="gap_center"),b=y&&_c(y.gap.breadthIntersection[0],y.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);y&&y.gap.length>a.length&&b?o[o.indexOf(y)]=S:(!y||!b)&&o.push(S);continue}const h=a.startNode.pageBounds.minY-a.length,p=e.maxY,f=h-p;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:hw(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=Kr(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:ze(),gaps:[...Yo(s,h.id,m,"backward",v),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:g},...Yo(s,p.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Kr(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},...Yo(s,p.id,f,"forward",m)]:[...Yo(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=Kr(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:ze(),gaps:[...Yo(o,h.id,m,"backward",v),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:g},...Yo(o,l.gap.endNode.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Kr(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},...Yo(o,p.id,f,"forward",m)]:[...Yo(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 QQ(a),a}}va=VQ();zg(va,1,"getSnapPointsCache",dO,Zl);zg(va,1,"getSnappablePoints",uO,Zl);zg(va,1,"getSnappableGapNodes",cO,Zl);zg(va,1,"getVisibleGaps",lO,Zl);XQ(va,Zl);function yI(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 JQ=Object.create,hO=Object.defineProperty,eJ=Object.getOwnPropertyDescriptor,tJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),pO=t=>{throw TypeError(t)},fO=(t,e,n)=>e in t?hO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nJ=t=>[,,,JQ(null)],gO=["class","method","getter","setter","accessor","field","value","get","set"],mO=t=>t!==void 0&&typeof t!="function"?pO("Function expected"):t,rJ=(t,e,n,r,o)=>({kind:gO[t],name:e,metadata:r,addInitializer:s=>n._?pO("Already initialized"):o.push(mO(s||null))}),oJ=(t,e)=>fO(e,tJ("metadata"),t[3]),sJ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},iJ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=gO[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,eJ(o,n)),S=r.length-1;S>=0;S--)l=rJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,mO(i)&&(v[g]=i);return v&&hO(o,n,v),o},aJ=(t,e,n)=>fO(t,e+"",n),yO,Bg;const lJ=()=>null,cJ=()=>[];yO=[W];class v1{constructor(e){this.manager=e,sJ(Bg,5,this),aJ(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):lJ,s=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):cJ;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=sr(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=sr(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=sr(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=sr(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}}Bg=nJ();iJ(Bg,1,"getSnapGeometryCache",yO,v1);oJ(Bg,v1);var uJ=Object.create,SO=Object.defineProperty,dJ=Object.getOwnPropertyDescriptor,hJ=(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,pJ=t=>[,,,uJ(null)],wO=["class","method","getter","setter","accessor","field","value","get","set"],bO=t=>t!==void 0&&typeof t!="function"?vO("Function expected"):t,fJ=(t,e,n,r,o)=>({kind:wO[t],name:e,metadata:r,addInitializer:s=>n._?vO("Already initialized"):o.push(bO(s||null))}),gJ=(t,e)=>xO(e,hJ("metadata"),t[3]),mJ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},x1=(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,dJ(o,n)),S=r.length-1;S>=0;S--)l=fJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,bO(i)&&(v[g]=i);return v&&SO(o,n,v),o},Ky=(t,e,n)=>xO(t,typeof e!="symbol"?e+"":e,n),PO,CO,_O,Ql;_O=[W],CO=[W],PO=[W];class gd{constructor(e){this.editor=e,mJ(Ql,5,this),Ky(this,"shapeBounds"),Ky(this,"handles"),Ky(this,"_snapIndicators",It("snapLines",void 0)),this.shapeBounds=new Zl(this),this.handles=new v1(this)}getIndicators(){return this._snapIndicators.get()??ss}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($n(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())}}Ql=pJ();x1(Ql,1,"getSnapThreshold",_O,gd);x1(Ql,1,"getSnappableShapes",CO,gd);x1(Ql,1,"getCurrentCommonAncestor",PO,gd);gJ(Ql,gd);const yJ=/\r?\n|\r/g;function SI(t){return t.replace(yJ,`
|
|
102
|
-
`).split(`
|
|
103
|
-
`).map(e=>e||" ").join(`
|
|
104
|
-
`)}const SJ={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},vJ=/\s/;class xJ{constructor(e){E(this,"baseElm");this.editor=e;const n=this.editor.getContainer(),r=document.createElement("div");r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,n.appendChild(r),this.baseElm=r,e.disposables.add(()=>{r.remove()})}measureText(e,n){var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-style",n.fontStyle),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("font-size",n.fontSize+"px"),r.style.setProperty("line-height",n.lineHeight*n.fontSize+"px"),r.style.setProperty("max-width",n.maxWidth===null?null:n.maxWidth+"px"),r.style.setProperty("min-width",n.minWidth===null?null:n.minWidth+"px"),r.style.setProperty("padding",n.padding),r.style.setProperty("overflow-wrap",n.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=SI(e);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}}measureElementTextNodeSpans(e,{shouldTruncateToFirstLine:n=!1}={}){const r=[],o=e.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,l=e.childNodes[0];let c=0,u=null,h=null,p=0,f=0,g=!1;for(const m of e.childNodes)if(m.nodeType===Node.TEXT_NODE)for(const v of m.textContent??""){a.setStart(l,c),a.setEnd(l,c+v.length);const S=a.getClientRects(),y=S[S.length-1],b=y.top+i,P=y.left+s,C=y.right+s,I=P<f,k=vJ.test(v);if(k!==h||b!==p||!u){if(u){if(n&&b!==p){g=!0;break}r.push(u)}u={box:{x:P,y:b,w:y.width,h:y.height},text:v},f=P}else I&&(u.box.x=P),u.box.w=I?u.box.w+y.width:C-u.box.x,u.text+=v;v===`
|
|
105
|
-
`&&(f=0),h=k,p=b,c+=v.length}return u&&r.push(u),{spans:r,didTruncate:g}}measureTextSpans(e,n){var c;if(e==="")return[];const r=(c=this.baseElm)==null?void 0:c.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(n.width-n.padding*2);r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("width",`${o}px`),r.style.setProperty("height","min-content"),r.style.setProperty("font-size",`${n.fontSize}px`),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("line-height",`${n.lineHeight*n.fontSize}px`),r.style.setProperty("text-align",SJ[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=SI(e);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(n.overflow==="truncate-ellipsis"&&l){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}px`),r.textContent=i;const h=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,p=h[h.length-1];return h.push({text:"…",box:{x:Math.min(p.box.x+p.box.w,n.width-n.padding-u),y:p.box.y,w:u,h:p.box.h}}),h}return r.remove(),a}}var 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},AO=(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)),S=r.length-1;S>=0;S--)l=_J(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,MO(i)&&(v[g]=i);return v&&IO(o,n,v),o},gh=(t,e,n)=>kO(t,typeof e!="symbol"?e+"":e,n),jO,OO,md;const vI=(typeof process<"u",$T);OO=[Un],jO=[Un];class Ug{constructor(e){this.editor=e,EJ(md,5,this),gh(this,"cancelRaf"),gh(this,"isPaused",!0),gh(this,"now",0),gh(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=vI(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=vI(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)}}md=CJ();AO(md,1,"tick",OO,Ug);AO(md,1,"dispose",jO,Ug);IJ(md,Ug);var kJ=Object.create,DO=Object.defineProperty,TJ=Object.getOwnPropertyDescriptor,MJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),RO=t=>{throw TypeError(t)},LO=(t,e,n)=>e in t?DO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,AJ=t=>[,,,kJ(null)],$O=["class","method","getter","setter","accessor","field","value","get","set"],FO=t=>t!==void 0&&typeof t!="function"?RO("Function expected"):t,jJ=(t,e,n,r,o)=>({kind:$O[t],name:e,metadata:r,addInitializer:s=>n._?RO("Already initialized"):o.push(FO(s||null))}),OJ=(t,e)=>LO(e,MJ("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},$r=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=$O[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,TJ(o,n)),S=r.length-1;S>=0;S--)l=jJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,FO(i)&&(v[g]=i);return v&&DO(o,n,v),o},RJ=(t,e,n)=>LO(t,e+"",n),NO,zO,BO,UO,HO,KO,WO,GO,VO,YO,XO,qO,Tn;qO=[W],XO=[W],YO=[W],VO=[W],GO=[W],WO=[W],KO=[W],HO=[W],UO=[W],BO=[W],zO=[W],NO=[W];class Qn{constructor(e,n){if(this.user=e,this.inferDarkMode=n,DJ(Tn,5,this),RJ(this,"systemColorScheme",It("systemColorScheme","light")),typeof window>"u"||!("matchMedia"in window))return;const r=window.matchMedia("(prefers-color-scheme: dark)");r!=null&&r.matches&&this.systemColorScheme.set("dark"),r==null||r.addEventListener("change",o=>{o.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")})}updateUserPreferences(e){this.user.setUserPreferences({...this.user.userPreferences.get(),...e})}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme){case"dark":return!0;case"light":return!1;case"system":return this.systemColorScheme.get()==="dark";default:return this.inferDarkMode?this.systemColorScheme.get()==="dark":!1}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??Wo.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??Wo.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??Wo.name}getLocale(){return this.user.userPreferences.get().locale??Wo.locale}getColor(){return this.user.userPreferences.get().color??Wo.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??Wo.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??Wo.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??Wo.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??Wo.isPasteAtCursorMode}}Tn=AJ();$r(Tn,1,"getUserPreferences",qO,Qn);$r(Tn,1,"getIsDarkMode",XO,Qn);$r(Tn,1,"getEdgeScrollSpeed",YO,Qn);$r(Tn,1,"getAnimationSpeed",VO,Qn);$r(Tn,1,"getId",GO,Qn);$r(Tn,1,"getName",WO,Qn);$r(Tn,1,"getLocale",KO,Qn);$r(Tn,1,"getColor",HO,Qn);$r(Tn,1,"getIsSnapMode",UO,Qn);$r(Tn,1,"getIsWrapMode",BO,Qn);$r(Tn,1,"getIsDynamicResizeMode",zO,Qn);$r(Tn,1,"getIsPasteAtCursorMode",NO,Qn);OJ(Tn,Qn);const LJ={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"},$J=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class ie{constructor(e,n){E(this,"performanceTracker");E(this,"id");E(this,"type");E(this,"shapeType");E(this,"initial");E(this,"children");E(this,"isLockable");E(this,"parent");E(this,"_path");E(this,"_current");E(this,"_isActive");E(this,"_currentToolIdMask",It("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=It("toolIsActive"+this.id,!1),this._current=It("toolState"+this.id,void 0),this._path=W("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 gT}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=LJ[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()&&$J.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)}}E(ie,"id"),E(ie,"initial"),E(ie,"children"),E(ie,"isLockable",!0);class b0 extends ie{static children(){return[]}onKeyDown(e){var n;switch(e.code){case"KeyZ":{if(!(e.shiftKey||e.ctrlKey)){const r=this.getCurrent();r&&((n=r.getCurrent())==null?void 0:n.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...e,onInteractionEnd:r.id})}break}}}}E(b0,"id","root"),E(b0,"initial","");var FJ=Object.create,ZO=Object.defineProperty,NJ=Object.getOwnPropertyDescriptor,QO=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),JO=t=>{throw TypeError(t)},eD=(t,e,n)=>e in t?ZO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zJ=t=>[,,,FJ((t==null?void 0:t[QO("metadata")])??null)],tD=["class","method","getter","setter","accessor","field","value","get","set"],nD=t=>t!==void 0&&typeof t!="function"?JO("Function expected"):t,BJ=(t,e,n,r,o)=>({kind:tD[t],name:e,metadata:r,addInitializer:s=>n._?JO("Already initialized"):o.push(nD(s||null))}),UJ=(t,e)=>eD(e,QO("metadata"),t[3]),HJ=(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},ee=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=tD[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,NJ(o,n)),S=r.length-1;S>=0;S--)l=BJ(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,nD(i)&&(v[g]=i);return v&&ZO(o,n,v),o},ue=(t,e,n)=>eD(t,typeof e!="symbol"?e+"":e,n),rD,oD,sD,iD,aD,lD,cD,uD,dD,hD,pD,fD,gD,mD,yD,SD,vD,xD,wD,bD,PD,CD,_D,ID,ED,kD,TD,MD,AD,jD,OD,DD,RD,LD,$D,FD,ND,zD,BD,UD,HD,KD,WD,GD,VD,YD,XD,qD,ZD,QD,JD,eR,tR,nR,rR,oR,sR,iR,aR,lR,cR,uR,dR,hR,pR,fR,gR,mR,yR,SR,vR,xR,P0,J;class Q extends(P0=dZ,xR=[W],vR=[W],SR=[W],yR=[W],mR=[W],gR=[W],fR=[W],pR=[W],hR=[W],dR=[W],uR=[W],cR=[W],lR=[W],aR=[W],iR=[W],sR=[W],oR=[W],rR=[W],nR=[W],tR=[W],eR=[W],JD=[W],QD=[W],ZD=[W],qD=[W],XD=[W],YD=[W],VD=[W],GD=[W],WD=[W],KD=[W],HD=[W],UD=[W],BD=[W],zD=[W],ND=[W],FD=[W],$D=[W],LD=[W],RD=[W],DD=[W],OD=[W],jD=[W],AD=[W],MD=[W],TD=[W],kD=[W],ED=[W],ID=[W],_D=[W],CD=[W],PD=[W],bD=[W],wD=[W],xD=[W],vD=[W],SD=[W],yD=[W],mD=[W],gD=[W],fD=[W],pD=[W],hD=[W],dD=[W],uD=[W({isEqual:(e,n)=>e.equals(n)})],cD=[W],lD=[W],aD=[W],iD=[Un],sD=[Un],oD=[Un],rD=[Un],P0){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 T;super(),HJ(J,5,this),ue(this,"_isShapeHiddenPredicate"),ue(this,"options"),ue(this,"contextId",ze()),ue(this,"store"),ue(this,"root"),ue(this,"disposables",new Set),ue(this,"isDisposed",!1),ue(this,"_tickManager"),ue(this,"snaps"),ue(this,"timers",x0.forContext(this.contextId)),ue(this,"user"),ue(this,"textMeasure"),ue(this,"environment",Ge),ue(this,"scribbles"),ue(this,"sideEffects"),ue(this,"edgeScrollManager"),ue(this,"focusManager"),ue(this,"getContainer"),ue(this,"shapeUtils"),ue(this,"styleProps"),ue(this,"bindingUtils"),ue(this,"history"),ue(this,"_shouldIgnoreShapeLock",!1),ue(this,"_crashingError",null),ue(this,"_isChangingStyleTimeout",-1),ue(this,"menus",Wr.forContext(this.contextId)),ue(this,"_cameraOptions",It("camera options",z_)),ue(this,"_viewportAnimation",null),ue(this,"_willSetInitialBounds",!0),ue(this,"_isLockedOnFollowingUser",It("isLockedOnFollowingUser",!1)),ue(this,"_cameraState",It("camera state","idle")),ue(this,"_cameraStateTimeoutRemaining",0),ue(this,"_currentPageShapeIds"),ue(this,"_parentIdsToChildIds"),ue(this,"animatingShapes",new Map),ue(this,"externalAssetContentHandlers",{file:null,url:null}),ue(this,"temporaryAssetPreview",new Map),ue(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null}),ue(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}),ue(this,"_clickManager",new Ng(this)),ue(this,"_prevCursor","default"),ue(this,"_shiftKeyTimeout",-1),ue(this,"_altKeyTimeout",-1),ue(this,"_ctrlKeyTimeout",-1),ue(this,"_metaKeyTimeout",-1),ue(this,"_restoreToolId","select"),ue(this,"_pinchStart",1),ue(this,"_didPinch",!1),ue(this,"_selectedShapeIdsAtPointerDown",[]),ue(this,"_longPressTimeout",-1),ue(this,"capturedPointerId",null),ue(this,"performanceTracker"),ue(this,"performanceTrackerTimeout",-1),ue(this,"_pendingEventsForNextTick",[]),this._isShapeHiddenPredicate=p,this.options={...hQ,...h},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new zQ({store:e,annotateError:M=>{this.annotateError(M,{origin:"history.batch",willCrashApp:!0}),this.crash(M)}}),this.snaps=new gd(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...z_,...a}),this.user=new Qn(n??Sj(),u??!1),this.getContainer=i,this.textMeasure=new xJ(this),this._tickManager=new Ug(this);class f extends b0{}E(f,"initial",l??""),this.root=new f(this),this.root.children={};const g=Ej(r),m={},v={},S=new Map;for(const M of g){const D=new M(this);m[M.type]=D;const j=qM(M.props??{});v[M.type]=j;for(const O of j.keys())if(!S.has(O.id))S.set(O.id,O);else if(S.get(O.id)!==O)throw Error(`Multiple style props with id "${O.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=m,this.styleProps=v;const y=Cj(o),b={};for(const M of y){const D=new M(this);b[M.type]=D}this.bindingUtils=b;for(const M of[...s]){if(Jr(this.root.children,M.id))throw Error(`Can't override tool with id "${M.id}"`);this.root.children[M.id]=new M(this,this.root)}this.scribbles=new HQ(this);const P=(M,D)=>{let j=null;const O=M.selectedShapeIds.filter(L=>!D.has(L));O.length!==M.selectedShapeIds.length&&(j||(j={...M}),j.selectedShapeIds=O);const R=M.erasingShapeIds.filter(L=>!D.has(L));R.length!==M.erasingShapeIds.length&&(j||(j={...M}),j.erasingShapeIds=R),M.hoveredShapeId&&D.has(M.hoveredShapeId)&&(j||(j={...M}),j.hoveredShapeId=null),M.editingShapeId&&D.has(M.editingShapeId)&&(j||(j={...M}),j.editingShapeId=null);const B=M.hintingShapeIds.filter(L=>!D.has(L));return B.length!==M.hintingShapeIds.length&&(j||(j={...M}),j.hintingShapeIds=B),M.focusedGroupId&&D.has(M.focusedGroupId)&&(j||(j={...M}),j.focusedGroupId=null),j};this.sideEffects=this.store.sideEffects;let C=new Map;const I=new Set,k=new Set;let _=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var M,D,j,O;I.clear();for(const R of k){k.delete(R);const B=this.getShape(R);if(!B)continue;const L=this.getShapeUtil(B),G=(M=L.onChildrenChange)==null?void 0:M.call(L,B);G!=null&&G.length&&this.updateShapes(G)}if(_.size){const R=_;_=new Set;for(const B of R){const L=this.getBindingUtil(B);(D=L.onOperationComplete)==null||D.call(L)}}if(C.size){const R=C;C=new Map;for(const B of R.values())(O=(j=this.getBindingUtil(B.binding)).onAfterDelete)==null||O.call(j,B)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(M,D)=>{var j,O,R,B;for(const L of this.getBindingsInvolvingShape(D))_.add(L.type),L.fromId===D.id&&((O=(j=this.getBindingUtil(L)).onAfterChangeFromShape)==null||O.call(j,{binding:L,shapeBefore:M,shapeAfter:D})),L.toId===D.id&&((B=(R=this.getBindingUtil(L)).onAfterChangeToShape)==null||B.call(R,{binding:L,shapeBefore:M,shapeAfter:D}));if(M.parentId!==D.parentId){const L=G=>{var U,Y,te,de;const $=this.getShape(G);if($)for(const he of this.getBindingsInvolvingShape($))_.add(he.type),he.fromId===$.id&&((Y=(U=this.getBindingUtil(he)).onAfterChangeFromShape)==null||Y.call(U,{binding:he,shapeBefore:$,shapeAfter:$})),he.toId===$.id&&((de=(te=this.getBindingUtil(he)).onAfterChangeToShape)==null||de.call(te,{binding:he,shapeBefore:$,shapeAfter:$}))};L(D.id),this.visitDescendants(D.id,L)}if(M.parentId!==D.parentId&&Dn(D.parentId)){const L=new Set([M.id]);this.visitDescendants(M.id,G=>{L.add(G)});for(const G of this.getPageStates()){if(G.pageId===D.parentId)continue;const $=P(G,L);$&&this.store.put([$])}}M.parentId&&$n(M.parentId)&&k.add(M.parentId),D.parentId!==M.parentId&&$n(D.parentId)&&k.add(D.parentId)},beforeDelete:M=>{var R,B,L,G;if(I.has(M.id))return;M.parentId&&$n(M.parentId)&&k.add(M.parentId),I.add(M.id);const D=[];for(const $ of this.getBindingsInvolvingShape(M)){_.add($.type),D.push($.id);const U=this.getBindingUtil($);$.fromId===M.id?((R=U.onBeforeIsolateToShape)==null||R.call(U,{binding:$,removedShape:M}),(B=U.onBeforeDeleteFromShape)==null||B.call(U,{binding:$,shape:M})):((L=U.onBeforeIsolateFromShape)==null||L.call(U,{binding:$,removedShape:M}),(G=U.onBeforeDeleteToShape)==null||G.call(U,{binding:$,shape:M}))}D.length&&this.deleteBindings(D);const j=new Set([M.id]),O=ye(this.getPageStates().map($=>P($,j)));O.length&&this.store.put(O)}},binding:{beforeCreate:M=>{var j,O;const D=(O=(j=this.getBindingUtil(M)).onBeforeCreate)==null?void 0:O.call(j,{binding:M});return D||M},afterCreate:M=>{var D,j;_.add(M.type),(j=(D=this.getBindingUtil(M)).onAfterCreate)==null||j.call(D,{binding:M})},beforeChange:(M,D)=>{var O,R;const j=(R=(O=this.getBindingUtil(D)).onBeforeChange)==null?void 0:R.call(O,{bindingBefore:M,bindingAfter:D});return j||D},afterChange:(M,D)=>{var j,O;_.add(D.type),(O=(j=this.getBindingUtil(D)).onAfterChange)==null||O.call(j,{bindingBefore:M,bindingAfter:D})},beforeDelete:M=>{var D,j;(j=(D=this.getBindingUtil(M)).onBeforeDelete)==null||j.call(D,{binding:M})},afterDelete:M=>{var D,j;(j=(D=this.getBindingUtil(M)).onAfterDelete)==null||j.call(D,{binding:M}),_.add(M.type)}},page:{afterCreate:M=>{const D=bo.createId(M.id),j=Xr.createId(M.id);this.store.has(D)||this.store.put([bo.create({id:D})]),this.store.has(j)||this.store.put([Xr.create({id:j,pageId:M.id})])},afterDelete:(M,D)=>{var R,B;if(((R=this.getInstanceState())==null?void 0:R.currentPageId)===M.id){const L=(B=this.getPages().find(G=>G.id!==M.id))==null?void 0:B.id;L?this.store.put([{...this.getInstanceState(),currentPageId:L}]):D==="user"&&this.store.ensureStoreIsUsable()}const j=bo.createId(M.id),O=Xr.createId(M.id);this.store.remove([j,O])}},instance:{afterChange:(M,D,j)=>{var O;if(!this.store.has(D.currentPageId)){const R=this.store.has(M.currentPageId)?M.currentPageId:(O=this.getPages()[0])==null?void 0:O.id;R?this.store.update(D.id,B=>({...B,currentPageId:R})):j==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(M,D)=>{if((M==null?void 0:M.selectedShapeIds)!==(D==null?void 0:D.selectedShapeIds)){const j=D.selectedShapeIds.filter(R=>{var L,G;let B=(L=this.getShape(R))==null?void 0:L.parentId;for(;$n(B);){if(D.selectedShapeIds.includes(B))return!1;B=(G=this.getShape(B))==null?void 0:G.parentId}return!0});let O=null;if(j.length>0){const R=this.findCommonAncestor(ye(j.map(B=>this.getShape(B))),B=>this.isShapeOfType(B,"group"));R&&(O=R)}else D!=null&&D.focusedGroupId&&(O=D.focusedGroupId);(j.length!==D.selectedShapeIds.length||O!==D.focusedGroupId)&&this.store.put([{...D,selectedShapeIds:j,focusedGroupId:O??null}])}}}})),this._currentPageShapeIds=EQ(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=IQ(this.store),this.disposables.add(this.store.listen(M=>{this.emit("change",M)})),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 LQ(this),this.focusManager=new $Q(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 gT,(T=this.store.props.collaboration)!=null&&T.mode){const M=this.store.props.collaboration.mode;this.disposables.add(is("update collaboration mode",()=>{this.store.put([{...this.getInstanceState(),isReadonly:M.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 gw(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(c0)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(wn)}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 Xr.createId(this.getCurrentPageId())}updateCurrentPageState(e){return this._updateCurrentPageState(e),this}_updateCurrentPageState(e){this.store.update(e.id??this.getCurrentPageState().id,n=>({...n,...e}))}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:e}=this.getCurrentPageState();return ye(e.map(n=>this.store.get(n)))}setSelectedShapes(e){return this.run(()=>{const n=e.map(s=>typeof s=="string"?s:s.id),{selectedShapeIds:r}=this.getCurrentPageState(),o=new Set(r);if(n.length===o.size&&n.every(s=>o.has(s)))return null;this.store.put([{...this.getCurrentPageState(),selectedShapeIds:n}])},{history:"record-preserveRedoStack"})}isAncestorSelected(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null,r=this.getShape(n);if(!r)return!1;const o=this.getSelectedShapeIds();return!!this.findShapeAncestor(r,s=>o.includes(s.id))}select(...e){const n=typeof e[0]=="string"?e:e.map(r=>r.id);return this.setSelectedShapes(n),this}deselect(...e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=this.getSelectedShapeIds();return r.length>0&&n.length>0&&this.setSelectedShapes(r.filter(o=>!n.includes(o))),this}selectAll(){const e=this.getSortedChildIdsForParent(this.getCurrentPageId());return e.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(e)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var e;return((e=this.getOnlySelectedShape())==null?void 0:e.id)??null}getOnlySelectedShape(){const e=this.getSelectedShapes();return e.length===1?e[0]:null}getShapesPageBounds(e){const n=ye(e.map(r=>this.getShapePageBounds(r)));return n.length===0?null:Z.Common(n)}getSelectionPageBounds(){return this.getShapesPageBounds(this.getSelectedShapeIds())}getShapesSharedRotation(e){let n=!1,r=0;for(let o=0,s=e.length;o<s;o++){const i=this.getShapePageTransform(e[o]);if(i)if(n){if(i.rotation()!==r)return 0}else n=!0,r=i.rotation()}return r}getSelectionRotation(){return this.getShapesSharedRotation(this.getSelectedShapeIds())}getShapesRotatedPageBounds(e){if(e.length===0)return;const n=this.getShapesSharedRotation(e);if(n===0)return this.getShapesPageBounds(e)??void 0;if(e.length===1){const o=this.getShapeGeometry(e[0]).bounds.clone(),s=this.getShapePageTransform(e[0]);return o.point=s.applyToPoint(o.point),o}const r=Z.FromPoints(e.flatMap(o=>{const s=this.getShapePageTransform(o);return s?s.applyToPoints(this.getShapeGeometry(o).bounds.corners):[]}).map(o=>o.rot(-n)));return r.point=r.point.rot(n),r}getSelectionRotatedPageBounds(){return this.getShapesRotatedPageBounds(this.getSelectedShapeIds())}getSelectionRotatedScreenBounds(){const e=this.getSelectionRotatedPageBounds();if(!e)return;const{x:n,y:r}=this.pageToScreen(e.point),o=this.getZoomLevel();return new Z(n,r,e.width*o,e.height*o)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const e=this.getFocusedGroupId();return e?this.getShape(e):void 0}setFocusedGroup(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(n!==null){const r=this.getShape(n);if(!r)throw Error(`Editor.setFocusedGroup: Shape with id ${n} does not exist`);if(!this.isShapeOfType(r,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${r.type}`)}return n===this.getFocusedGroupId()?this:this.run(()=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:n}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const e=this.getFocusedGroup();if(e){const n=this.findShapeAncestor(e,r=>this.isShapeOfType(r,"group"));this.setFocusedGroup((n==null?void 0:n.id)??null),this.select(e.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const e=this.getEditingShapeId();return e?this.getShape(e):void 0}setEditingShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(n!==this.getEditingShapeId()){if(n){const r=this.getShape(n);if(r&&this.getShapeUtil(r).canEdit(r))return this.run(()=>{this._updateCurrentPageState({editingShapeId:n})},{history:"ignore"}),this}this.run(()=>{this._updateCurrentPageState({editingShapeId:null})},{history:"ignore"})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const e=this.getHoveredShapeId();return e?this.getShape(e):void 0}setHoveredShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;return n===this.getHoveredShapeId()?this:(this.run(()=>{this.updateCurrentPageState({hoveredShapeId:n})},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const e=this.getHintingShapeIds();return ye(e.map(n=>this.getShape(n)))}setHintingShapes(e){const n=typeof e[0]=="string"?e:e.map(r=>r.id);return this.run(()=>{this._updateCurrentPageState({hintingShapeIds:hw(n)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return ye(e.map(n=>this.getShape(n)))}setErasingShapes(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id);n.sort();const r=this.getErasingShapeIds();return this.run(()=>{if(n.length===r.length){for(let o=0;o<n.length;o++)if(n[o]!==r[o]){this._updateCurrentPageState({erasingShapeIds:n});break}}else this._updateCurrentPageState({erasingShapeIds:n})},{history:"ignore"}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;return n!==this.getCroppingShapeId()&&this.run(()=>{if(!n)this.updateCurrentPageState({croppingShapeId:null});else{const r=this.getShape(n),o=this.getShapeUtil(r);r&&o.canCrop(r)&&this.updateCurrentPageState({croppingShapeId:n})}},{history:"ignore"}),this}_unsafe_getCameraId(){return bo.createId(this.getCurrentPageId())}getCamera(){const e=this.store.get(this._unsafe_getCameraId());if(this._isLockedOnFollowingUser.get()){const n=this.getCameraForFollowing();if(n)return{...e,...n}}return e}getViewportPageBoundsForFollowing(){const e=this.getInstanceState().followingUserId;if(!e)return null;const n=this.getCollaborators().find(h=>h.userId===e);if(!n)return null;const{w:r,h:o}=n.screenBounds,{x:s,y:i,z:a}=n.camera,l=new Z(-s,-i,r/a,o/a),c=this.getViewportScreenBounds().clone(),u=c.width/c.height;return c.width=l.width,c.height=c.width/u,c.height<l.height&&(c.height=l.height,c.width=c.height*u),c.center=l.center,c}getCameraForFollowing(){const e=this.getViewportPageBoundsForFollowing();return e?{x:-e.x,y:-e.y,z:this.getViewportScreenBounds().w/e.width}:null}getZoomLevel(){return this.getCamera().z}getInitialZoom(){const e=this.getCameraOptions();if(!e.constraints||e.constraints.initialZoom==="default")return 1;const{zx:n,zy:r}=wI(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}=wI(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=nt({...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=Ht(a.zoomSteps),u=this.getViewportScreenBounds();if(a.constraints){const{constraints:h}=a,p=Math.min(h.padding.y,u.w/2),f=Math.min(h.padding.x,u.h/2),g=Z.From(a.constraints.bounds),m=(u.w-f*2)/g.w,v=(u.h-p*2)/g.h,S=this.getBaseZoom(),y=c*S,b=l*S;if(n!=null&&n.reset&&(i=this.getInitialZoom()),i<b||i>y){const{x:j,y:O,z:R}=r,B=-j+u.w/R/2,L=-O+u.h/R/2;i=Bt(i,b,y);const G=-j+u.w/i/2,$=-O+u.h/i/2;o=j+G-B,s=O+$-L}const P=f/i-g.x,C=p/i-g.y,I=(u.w-f*2)/i-g.w,k=(u.h-p*2)/i-g.h,_=P+I*h.origin.x,T=C+k*h.origin.y,M=typeof h.behavior=="string"?h.behavior:h.behavior.x,D=typeof h.behavior=="string"?h.behavior:h.behavior.y;if(n!=null&&n.reset)o=_,s=T;else{switch(M){case"fixed":{o=_;break}case"contain":{i<m?o=_:o=Bt(o,P+I,P);break}case"inside":{i<m?o=Bt(o,P,(u.w-f)/i-g.w):o=Bt(o,P+I,P);break}case"outside":{o=Bt(o,f/i-g.w,(u.w-f)/i);break}case"free":break;default:throw Ot(M)}switch(D){case"fixed":{s=T;break}case"contain":{i<v?s=T:s=Bt(s,C+k,C);break}case"inside":{i<v?s=Bt(s,C,(u.h-p)/i-g.h):s=Bt(s,C+k,C);break}case"outside":{s=Bt(s,p/i-g.h,(u.h-p)/i);break}case"free":break;default:throw Ot(D)}}}else if(i>c||i<l){const{x:h,y:p,z:f}=r;i=Bt(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:(Eo(()=>{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(wn);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:B_.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(ye(n.map(o=>this.getShapePageBounds(o))));return this.zoomToBounds(r,e),this}resetZoom(e=this.getViewportScreenCenter(),n){const{isLocked:r,constraints:o}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const s=this.getCamera(),{x:i,y:a,z:l}=s,{x:c,y:u}=e;let h=1;if(o){const p=this.getInitialZoom();l!==p&&(h=p)}return this.setCamera(new x(i+(c/h-c)-(c/l-c),a+(u/h-u)-(u/l-u),h),n),this}zoomIn(e=this.getViewportScreenCenter(),n){const{isLocked:r}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const{x:o,y:s,z:i}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const l=this.getBaseZoom();let c=Ht(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(WY,o.width*.28),i=this.getBaseZoom(),a=r.zoomSteps[0],l=Ht(r.zoomSteps);let c=Bt(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:Ry}){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(o=>o.userId===e);return r?(this.run(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const o=r.currentPageId===this.getCurrentPageId();o||this.setCurrentPage(r.currentPageId),n&&n.animation&&!o&&(n.animation=void 0),this.centerOnPoint(r.cursor,n);const{highlightedUserIds:s}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...s,e]}),this.timers.setTimeout(()=>{const i=[...this.getInstanceState().highlightedUserIds],a=i.indexOf(e);a<0||(i.splice(a,1),this.updateInstanceState({highlightedUserIds:i}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(e,n=!1){if(e instanceof HTMLElement){const a=e.getBoundingClientRect();e=new Z(a.left||a.x,a.top||a.y,Math.max(a.width,1),Math.max(a.height,1))}else e.width=Math.max(e.width,1),e.height=Math.max(e.height,1);const r=[e.minY!==0,!ri(document.body.scrollWidth,e.maxX,1),!ri(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(wn),{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(wn),{x:r,y:o,z:s=1}=this.getCamera();return new x((e.x+r)*s+n.x,(e.y+o)*s+n.y,e.z??.5)}pageToViewport(e){const{x:n,y:r,z:o=1}=this.getCamera();return new x((e.x+n)*o,(e.y+r)*o,e.z??.5)}_getCollaboratorsQuery(){return this.store.query.records("instance_presence",()=>({userId:{neq:this.user.getId()}}))}getCollaborators(){const e=this._getCollaboratorsQuery().get();return e.length?[...new Set(e.map(r=>r.userId))].sort().map(r=>e.filter(s=>s.userId===r).sort((s,i)=>i.lastActivityTimestamp-s.lastActivityTimestamp)[0]):ss}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=W("latestLeaderPresence",()=>this.getCollaborators().find(s=>s.userId===e));return Eo(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const s=is("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=Bt(c*.5,.1,.8),m=new Z(Ie(h.minX,u.minX,g),Ie(h.minY,u.minY,g),Ie(h.width,u.width,g),Ie(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(KB)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return 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=SQ(e.name??"Page 1",n.map(i=>i.name));let o=e.index;(!o||n.some(i=>i.index===o))&&(o=wo(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=ju(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){return await this.store.props.assets.upload(e,n)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",e=>this.getShapeUtil(e).getGeometry(e),(e,n)=>e.props===n.props)}getShapeGeometry(e){return this._getShapeGeometryCache().get(typeof e=="string"?e:e.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",e=>{var n,r;return(r=(n=this.getShapeUtil(e)).getHandles)==null?void 0:r.call(n,e)})}getShapeHandles(e){return this._getShapeHandlesCache().get(typeof e=="string"?e:e.id)}getShapeLocalTransform(e){const n=typeof e=="string"?e:e.id,r=this.getShape(n);if(!r)throw Error("Editor.getTransform: shape not found");return q.Identity().translate(r.x,r.y).rotate(r.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",e=>{if(Dn(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||Dn(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(Dn(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=aI(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=aI(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(Dn(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(Dn(s))return;const i=this.getShape(s);if(i)return n(i)?i:this.findShapeAncestor(i,n)}hasAncestor(e,n){const r=typeof e=="string"?e:e==null?void 0:e.id,o=r&&this.getShape(r);return o?o.parentId===n?!0:this.hasAncestor(this.getShapeParent(o),n):!1}findCommonAncestor(e,n){var l;if(e.length===0)return;const r=typeof e[0]=="string"?e:e.map(c=>c.id),o=ye(r.map(c=>this.getShape(c)));if(o.length===1){const c=o[0].parentId;return Dn(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 _Q(this)}getCulledShapes(){const e=this._notVisibleShapes().get(),n=this.getSelectedShapeIds(),r=this.getEditingShapeId(),o=new Set(e);return r&&o.delete(r),n.forEach(s=>{o.delete(s)}),o}getCurrentPageBounds(){let e;return this.getCurrentPageShapeIdsSorted().forEach(n=>{const r=this.getShapeMaskedPageBounds(n);r&&(e?e=e.expand(r):e=r.clone())}),e}getSelectedShapeAtPoint(e){const n=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(r=>r.type!=="group"&&n.includes(r.id)).reverse().find(r=>this.isPointInShape(r,e,{hitInside:!0,margin:0}))}getShapeAtPoint(e,n={}){const r=this.getZoomLevel(),o=this.getViewportPageBounds(),{filter:s,margin:i=0,hitLocked:a=!1,hitLabels:l=!1,hitInside:c=!1,hitFrameInside:u=!1}=n;let h=1/0,p=null,f=1/0,g=null;const m=(n.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(v=>{if(v.isLocked&&!a||this.isShapeHidden(v)||this.isShapeOfType(v,"group"))return!1;const S=this.getShapeMask(v);return S&&!hr(e,S)?!1:s?s(v):!0});for(let v=m.length-1;v>=0;v--){const S=m[v],y=this.getShapeGeometry(S),b=y instanceof ro,P=this.getPointInShapeSpace(S,e);if((this.isShapeOfType(S,"arrow")||this.isShapeOfType(S,"geo")&&S.props.fill==="none")&&S.props.text.trim()){for(const I of y.children)if(I.isLabel&&I.isPointInBounds(P))return S}if(this.isShapeOfType(S,"frame")){const I=y.distanceToPoint(P,c);if(Math.abs(I)<=i)return g||S;if(y.hitTestPoint(P,0,!0))return g||p||(u?S:void 0);continue}let C;if(b){let I=1/0;for(const k of y.children){if(k.isLabel&&!l)continue;const _=k.distanceToPoint(P,c);_<I&&(I=_)}C=I}else i===0&&(y.bounds.w<1||y.bounds.h<1)||y.bounds.containsPoint(P,i)?C=y.distanceToPoint(P,c):C=1/0;if(y.isClosed){if(C<=i){if(y.isFilled||b&&y.children[0].isFilled)return g||S;if(this.getShapePageBounds(S).contains(o))continue;if(Math.abs(C)<i)Math.abs(C)<f&&(f=Math.abs(C),g=S);else if(!g){const{area:I}=y;I<h&&(h=I,p=S)}}}else if(C<this.options.hitTestMargin/r)return S}return g||p||void 0}getShapesAtPoint(e,n={}){return this.getCurrentPageShapes().filter(r=>!this.isShapeHidden(r)&&this.isPointInShape(r,e,n))}isPointInShape(e,n,r={}){const{hitInside:o=!1,margin:s=0}=r,i=typeof e=="string"?e:e.id,a=this.getShapeMask(i);return a&&!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(Dn(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++)wR(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($n(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||!$n(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 Dn(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=Dn(n)?q.Identity():this.getShapePageTransform(n),a=i.rotation();let l=[];const c=ye(this.getSortedChildIdsForParent(n).map(p=>this.getShape(p)));if(r){const p=c.find(f=>f.index===r);if(p){const f=c[c.indexOf(p)+1];f?l=Tl(r,f.index,o.length):l=cy(r,o.length)}else{const f=c.sort(cn).find(g=>g.index>r);f?l=Tl(r,f.index,o.length):l=cy(r,o.length)}}else{const p=c.length&&c[c.length-1];l=p?cy(p.index,o.length):Ou(o.length)}const u=i.clone().invert(),h=ye(o.map(p=>this.getShape(p)));return this.run(()=>{for(let p=0;p<h.length;p++){const f=h[p],g=this.getShapePageTransform(f);if(!g)continue;const m=g.point();if(!m)continue;const v=u.applyToPoint(m),S=g.rotation()-a;s.push({id:f.id,type:f.type,parentId:n,x:v.x,y:v.y,rotation:S,index:l[p]})}this.updateShapes(s)},{ignoreShapeLock:!0}),this}getHighestIndexForParent(e){const n=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[n];if(!r||r.length===0)return"a1";const o=this.getShape(r[r.length-1]);return wo(o.index)}getSortedChildIdsForParent(e){const n=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[n];return r||ss}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=PQ(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)??ss;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??Yi(),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=go(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=Yj({editor:this,ids:o});return s?(ip({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=go(r,((s=o.onTranslateStart)==null?void 0:s.call(o,r))??void 0),r=go(r,{id:e.id,type:e.type,x:n.x,y:n.y}),r=go(r,((i=o.onTranslate)==null?void 0:i.call(o,e,r))??void 0),r=go(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,Be());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=xI(this,s,p=>{const f=[];for(const m of p){const v=this.getBinding(m);if(!v)continue;const S=Yi();f.push({...v,id:S,fromId:sr(a.get(v.fromId)),toId:sr(a.get(v.toId))})}const g=[];for(const m of i){const v=sr(a.get(m)),S=this.getShape(m);if(!S)continue;let y=0,b=0;if(n&&o.has(m)){const P=this.getShapeParentTransform(S),C=new x(n.x,n.y).rot(-P.rotation());y=C.x,b=C.y}g.push({shape:{...S,id:v,x:S.x+y,y:S.y+b,index:"a1",parentId:a.get(S.parentId)??S.parentId},originalShape:S})}return{shapesToCreateWithOriginals:g,bindingsToCreate:f}});l.forEach(({shape:p,originalShape:f})=>{const g=f.parentId,m=this.getSortedChildIdsForParent(g),v=m.indexOf(f.id),S=m[v+1],y=S?this.getShape(S):void 0,b=ju(f.index,y==null?void 0:y.index);p.index=b});const u=l.map(({shape:p})=>p);if(u.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){mh(this);return}if(this.createShapes(u),this.createBindings(c),this.setSelectedShapes(ye(r.map(p=>a.get(p)))),n!==void 0){const p=this.getSelectionPageBounds(),f=this.getViewportPageBounds();p&&!f.contains(p)&&this.centerOnPoint(p.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(e,n){const r=typeof e[0]=="string"?e:e.map(a=>a.id);if(r.length===0)return this;if(this.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 mh(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=fh(this,"toBack",n);return r&&this.updateShapes(r),this}sendBackward(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=fh(this,"backward",n);return r&&this.updateShapes(r),this}bringForward(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=fh(this,"forward",n);return r&&this.updateShapes(r),this}bringToFront(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=fh(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=ye(r.map(i=>this.getShape(i)));if(!o.length)return this;o=ye(o.map(i=>this.isShapeOfType(i,"group")?this.getSortedChildIdsForParent(i.id).map(a=>this.getShape(a)):i).flat());const s=Z.Common(ye(o.map(i=>this.getShapePageBounds(i)))).center;return this.run(()=>{for(const i of o){const a=this.getShapeGeometry(i).bounds,l=this.getShapePageTransform(i.id);l&&this.resizeShape(i.id,{x:n==="horizontal"?-1:1,y:n==="vertical"?-1:1},{initialBounds:a,initialPageTransform:l,initialShape:i,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(i).isAspectRatioLocked(i),scaleOrigin:s,scaleAxisRotation:0})}}),this}stackShapes(e,n,r){const o=typeof e[0]=="string"?e:e.map(m=>m.id);if(this.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((S,y)=>a[S.id][c]-a[y.id][c]);for(let S=0;S<i-1;S++){const y=s[S],b=s[S+1],P=a[y.id],I=a[b.id][c]-P[u],k=m.find(_=>_.gap===I);k?k.count++:m.push({gap:I,count:1})}let v=0;m.forEach(S=>{S.count>v&&(v=S.count,p=S.gap)}),v===1&&(p=Math.max(0,m.reduce((S,y)=>S+y.gap*y.count,0)/(i-1)))}else p=r;const f=[];let g=a[s[0].id][u];return s.forEach((m,v)=>{var C,I;if(v===0)return;const S={x:0,y:0};S[l]=g+p-a[m.id][l];const y=this.getShapeParent(m),b=y?x.Rot(S,-this.getShapePageTransform(y).decompose().rotation):S,P=(I=(C=this.getShapeUtil(m)).onTranslateStart)==null?void 0:I.call(C,m);f.push(P?{...P,[l]:m[l]+b[l]}:{id:m.id,type:m.type,[l]:m[l]+b[l]}),g+=a[m.id][h]+p}),this.updateShapes(f),this}packShapes(e,n){var I,k;const r=typeof e[0]=="string"?e:e.map(_=>_.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const o=r.map(_=>this.getShape(_)).filter(_=>_?this.getShapeUtil(_).canBeLaidOut(_):!1),s={},i={};let a,l,c=0;for(let _=0;_<o.length;_++)a=o[_],l=this.getShapePageBounds(a),s[a.id]=l,i[a.id]=l.clone(),c+=l.width*l.height;const u=Z.Common(ye(Object.values(s))),h=u.width;o.sort((_,T)=>s[T.id].height-s[_.id].height);const p=Math.max(Math.ceil(Math.sqrt(c/.95)),h),f=[new Z(u.x,u.y,p,1/0)];let g=0,m=0,v,S;for(let _=0;_<o.length;_++){a=o[_],l=i[a.id];for(let T=f.length-1;T>=0;T--)if(v=f[T],!(l.width>v.width||l.height>v.height)){l.x=v.x,l.y=v.y,m=Math.max(m,l.maxY),g=Math.max(g,l.maxX),l.width===v.width&&l.height===v.height?(S=f.pop(),T<f.length&&(f[T]=S)):l.height===v.height?(v.x+=l.width+n,v.width-=l.width+n):l.width===v.width?(v.y+=l.height+n,v.height-=l.height+n):(f.push(new Z(v.x+(l.width+n),v.y,v.width-(l.width+n),l.height)),v.y+=l.height+n,v.height-=l.height+n);break}}const y=Z.Common(Object.values(i)),b=x.Sub(u.center,y.center);let P;const C=[];for(let _=0;_<o.length;_++){a=o[_],l=s[a.id],P=i[a.id];const T=x.Sub(P.point,l.point).add(b),M=this.getShapeParentTransform(a);M&&T.rot(-M.rotation());const D={id:a.id,type:a.type,x:a.x+T.x,y:a.y+T.y},j=(k=(I=this.getShapeUtil(a)).onTranslateStart)==null?void 0:k.call(I,{...a,...D});j?C.push({...D,...j}):C.push(D)}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=ye(r.map(l=>this.getShape(l))),s=Object.fromEntries(o.map(l=>[l.id,this.getShapePageBounds(l)])),i=Z.Common(ye(Object.values(s))),a=[];return o.forEach(l=>{const c=s[l.id];if(!c)return;const u={x:0,y:0};switch(n){case"top":{u.y=i.minY-c.minY;break}case"center-vertical":{u.y=i.midY-c.minY-c.height/2;break}case"bottom":{u.y=i.maxY-c.minY-c.height;break}case"left":{u.x=i.minX-c.minX;break}case"center-horizontal":{u.x=i.midX-c.minX-c.width/2;break}case"right":{u.x=i.maxX-c.minX-c.width;break}}const h=this.getShapeParent(l),p=h?x.Rot(u,-this.getShapePageTransform(h).decompose().rotation):u;a.push(this.getChangesToTranslateShape(l,x.Add(l,p)))}),this.updateShapes(a),this}distributeShapes(e,n){const r=typeof e[0]=="string"?e:e.map(y=>y.id);if(this.getIsReadonly())return this;if(r.length<3)return this;const o=r.length,s=ye(r.map(y=>this.getShape(y))),i=Object.fromEntries(s.map(y=>[y.id,this.getShapePageBounds(y)]));let a,l,c,u,h;n==="horizontal"?(a="x",l="minX",c="maxX",u="midX",h="width"):(a="y",l="minY",c="maxY",u="midY",h="height");const p=[],f=s.sort((y,b)=>i[y.id][l]-i[b.id][l])[0],g=s.sort((y,b)=>i[b.id][c]-i[y.id][c])[0],m=i[f.id][u],v=(i[g.id][u]-m)/(o-1),S=m+v;return s.filter(y=>y!==f&&y!==g).sort((y,b)=>i[y.id][u]-i[b.id][u]).forEach((y,b)=>{const P={x:0,y:0};P[a]=S+v*b-i[y.id][h]/2-i[y.id][a];const C=this.getShapeParent(y),I=C?x.Rot(P,-this.getShapePageTransform(C).rotation()):P;p.push(this.getChangesToTranslateShape(y,x.Add(y,I)))}),this.updateShapes(p),this}stretchShapes(e,n){const r=typeof e[0]=="string"?e:e.map(l=>l.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const o=ye(r.map(l=>this.getShape(l))),s=Object.fromEntries(r.map(l=>[l,this.getShapeGeometry(l).bounds])),i=Object.fromEntries(r.map(l=>[l,this.getShapePageBounds(l)])),a=Z.Common(ye(Object.values(i)));switch(n){case"vertical":{this.run(()=>{for(const l of o){if(this.getShapePageTransform(l).rotation()%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(!FA(l,c))return this._resizeUnalignedShape(o,n,{...r,initialBounds:u,scaleOrigin:i,scaleAxisRotation:c,initialPageTransform:a,isAspectRatioLocked:h,initialShape:s});const p=this.getShapeUtil(s);if(h&&(Math.abs(n.x)>Math.abs(n.y)?n=new x(n.x,Math.sign(n.y)*Math.abs(n.x)):n=new x(Math.sign(n.x)*Math.abs(n.y),n.y)),p.onResize&&p.canResize(s)){const v=this._scalePagePoint(q.applyToPoint(a,new x(0,0)),i,n,c),S=this.getPointInParentSpace(s.id,v),y=new x(n.x,n.y),b=ri((l-c)%Math.PI,0);y.x=b?n.x:n.y,y.y=b?n.y:n.x;const P=q.applyToPoint(a,new x),{x:C,y:I}=this.getPointInParentSpace(s.id,P);let k=s;r.skipStartAndEndCallbacks||(k=go(s,((g=p.onResizeStart)==null?void 0:g.call(p,s))??void 0)),k=go(k,{id:o,type:s.type,x:S.x,y:S.y,...p.onResize({...s,x:C,y:I},{newPoint:S,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:y.x,scaleY:y.y,initialBounds:u,initialShape:s})}),r.skipStartAndEndCallbacks||(k=go(k,((m=p.onResizeEnd)==null?void 0:m.call(p,s,k))??void 0)),this.updateShapes([k])}else{const v=q.applyToPoint(a,u.center),S=this._scalePagePoint(v,i,n,c),y=this.getPointInParentSpace(s.id,v),b=this.getPointInParentSpace(s.id,S),P=x.Sub(b,y);this.updateShapes([{id:o,type:s.type,x:s.x+P.x,y:s.y+P.y}])}return this}_scalePagePoint(e,n,r,o){const s=x.RotWith(e,n,-o).sub(n),i=x.MulV(s,r);return x.Add(i,n).rotWith(n,o)}_resizeUnalignedShape(e,n,r){const{type:o}=r.initialShape,s=new x(n.x,n.y);if(Math.abs(n.x)>Math.abs(n.y)?s.x=Math.sign(n.x)*Math.abs(n.y):s.y=Math.sign(n.y)*Math.abs(n.x),this.resizeShape(e,s,{initialShape:r.initialShape,initialBounds:r.initialBounds,isAspectRatioLocked:r.isAspectRatioLocked}),Math.sign(n.x)*Math.sign(n.y)<0){let{rotation:v}=q.Decompose(r.initialPageTransform);v-=2*v,this.updateShapes([{id:e,type:o,rotation:v}])}const i=q.applyToPoint(r.initialPageTransform,r.initialBounds.center),a=this._scalePagePoint(i,r.scaleOrigin,n,r.scaleAxisRotation),l=this.getShapePageBounds(e),c=this.getShapePageTransform(e),u=l.center,h=c.point();if(!u||!h)return this;const p=x.Sub(a,u),f=x.Add(h,p),{x:g,y:m}=this.getPointInParentSpace(e,f);return this.updateShapes([{id:e,type:o,x:g,y:m}]),this}getInitialMetaForShape(e){return{}}createShape(e){return this.createShapes([e]),this}createShapes(e){if(!Array.isArray(e))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");if(this.getIsReadonly())return this;if(e.length<=0)return this;const n=this.getCurrentPageShapeIds();if(e.length+n.size>this.options.maxShapesPerPage)return mh(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:Be(),...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,$n(f))){const m=this.getPointInShapeSpace(this.getShape(f),{x:p.x??0,y:p.y??0});p.x=m.x,p.y=m.y,p.rotation=-this.getShapePageTransform(f).rotation()+(p.rotation??0)}}return p}),a=new Map,l=[],{opacityForNextShape:c}=this.getInstanceState();for(const p of i){const f=this.getShapeUtil(p);let g=p.index;if(!g){const y=p.parentId??o;a.has(y)||a.set(y,this.getHighestIndexForParent(y)),g=a.get(y),a.set(y,wo(g))}const m=f.getDefaultProps();for(const[y,b]of this.styleProps[p.type])m[b]=this.getStyleForNextShape(y);let v=this.store.schema.types.shape.create({...p,index:g,opacity:p.opacity??c,parentId:p.parentId??o,props:"props"in p?{...m,...p.props}:m});if(v.index===void 0)throw Error("no index!");const S=(h=(u=this.getShapeUtil(v)).onBeforeCreate)==null?void 0:h.call(u,v);S&&(v=S),l.push(v)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)}),this}animateShape(e,n={animation:Ry}){return this.animateShapes([e],n)}animateShapes(e,n={animation:Ry}){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:nt(g),end:go(nt(g),c)},l.push(u),this.animatingShapes.set(g.id,s))}const h=p=>{var v,S;if(i-=p,i<0){const{animatingShapes:y}=this,b=e.filter(P=>P&&y.get(P.id)===s);b.length&&this.updateShapes(b),this.off("tick",h);return}a=o(1-i/r);const{animatingShapes:f}=this,g=[];let m;for(let y=0,b=l.length;y<b;y++){const{start:P,end:C}=l[y];m=f.get(P.id),m===s&&g.push({...C,x:P.x+(C.x-P.x)*a,y:P.y+(C.y-P.y)*a,opacity:P.opacity+(C.opacity-P.opacity)*a,rotation:P.rotation+(C.rotation-P.rotation)*a,props:((S=(v=this.getShapeUtil(C)).getInterpolatedProps)==null?void 0:S.call(v,P,C,a))??C.props})}this._updateShapes(g)};return this.on("tick",h),this}groupShapes(e,n={}){var g;const{groupId:r=Be(),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=ye((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(m=>this.getShape(m))),a=i.sort(cn).map(m=>m.id),l=Z.Common(ye(i.map(m=>this.getShapePageBounds(m)))),{x:c,y:u}=l.point,h=this.findCommonAncestor(i)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const p=i.filter(m=>m.parentId===h).sort(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=ye((this._shouldIgnoreShapeLock?o:this._getUnlockedShapeIds(o)).map(l=>this.getShape(l)));if(s.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const i=new Set,a=[];return s.forEach(l=>{this.isShapeOfType(l,"group")?a.push(l):i.add(l.id)}),a.length===0?this:(this.run(()=>{let l;for(let c=0,u=a.length;c<u;c++){l=a[c];const h=this.getSortedChildIdsForParent(l.id);for(let p=0,f=h.length;p<f;p++)i.add(h[p]);this.reparentShapes(h,l.parentId,l.index)}this.deleteShapes(a.map(c=>c.id)),r&&this.select(...i)}),this)}updateShape(e){return this.updateShapes([e]),this}updateShapes(e){const n=Array(e.length);for(let r=0,o=e.length;r<o;r++){const s=e[r];if(!s)continue;const i=this.getShape(s.id);if(i){if(!this._shouldIgnoreShapeLock){if(i.isLocked){if(!(Object.hasOwn(s,"isLocked")&&!s.isLocked))continue}else if(this.isShapeOrAncestorLocked(i))continue}this.animatingShapes.delete(s.id),n.push(s)}}return this._updateShapes(n),this}_updateShapes(e){this.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=go(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 w0;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 w0;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 xI(this,r,o=>{const s=[];for(const u of o){const h=this.getBinding(u);h&&s.push(h)}const i=[],a=[];for(const u of r){const h=this.getShape(u);if(!h)continue;if(!r.has(h.parentId)){const f=this.getShapePageTransform(h.id),g=f.point();a.push({...h,x:g.x,y:g.y,rotation:f.rotation(),parentId:this.getCurrentPageId()}),i.push(h.id)}else a.push(h)}const l=[],c=new Set;for(const u of a){if(!("assetId"in u.props))continue;const h=u.props.assetId;if(!h||c.has(h))continue;c.add(h);const p=this.getAsset(h);p&&l.push(p)}return{schema:this.store.schema.serialize(),shapes:a,rootShapeIds:i,bindings:s,assets:l}})}async resolveAssetsInContent(e){if(!e)return;const n=[];return await Promise.allSettled(e.assets.map(async r=>{var o,s;if((r.type==="image"||r.type==="video")&&!((o=r.props.src)!=null&&o.startsWith("data:image"))&&!((s=r.props.src)!=null&&s.startsWith("http"))){const i=nt(r),a=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});i.props.src=await os.blobToDataUrl(await no(a).then(l=>l.blob())),n.push(i)}else n.push(r)})),e.assets=n,e}putContentOntoCurrentPage(e,n={}){var M,D;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(j=>[j.id,j])),...Object.fromEntries(e.shapes.map(j=>[j.id,j])),...Object.fromEntries(((M=e.bindings)==null?void 0:M.map(j=>[j.id,j]))??[])},schema:e.schema},f=this.store.schema.migrateStoreSnapshot(p);if(f.type==="error")throw Error("Could not put content: could not migrate content");for(const j of Object.values(f.value))switch(j.typeName){case"asset":{c.push(j);break}case"shape":{u.push(j);break}case"binding":{h.push(j);break}}const g=new Map(o?u.map(j=>[j.id,j.id]):u.map(j=>[j.id,Be()])),m=new Map(o?h.map(j=>[j.id,j.id]):h.map(j=>[j.id,Yi()]));let v=this.getCurrentPageId(),S=1/0,y=[];for(const j of this.getSelectedShapes()){if(S===0)break;const O=this.isShapeOfType(j,"frame"),R=this.getShapeAncestors(j);O&&R.push(j);const B=O?R.length+1:R.length;if(B<S)S=B,y=R,v=O?j.id:j.parentId;else if(B===S){if(y.length!==R.length)throw Error(`Ancestors: ${y.length} !== ${R.length}`);if(y.length===0){v=a;break}else{v=a;for(let L=0;L<y.length&&R[L]===y[L];L++)v=R[L].id}}}let b=!1;if(!Dn(v)){const j=this.getShape(v);if(j){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(j)))v=a;else if(l.length===1){const O=u.find(R=>R.id===l[0]);this.isShapeOfType(j,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(j==null?void 0:j.props.w)&&O.props.h===(j==null?void 0:j.props.h)&&(b=!0)}}else v=a}b||(b=g.has(v)),b&&(v=this.getShape(v).parentId);let P=this.getHighestIndexForParent(v);const C=[],I=u.map(j=>{const O=g.get(j.id),R={...j,id:O};return l.includes(j.id)&&(R.parentId=a,C.push(R)),g.has(R.parentId)?R.parentId=g.get(j.parentId):(l.push(R.id),R.index=P,P=wo(P)),R});if(I.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return mh(this),this;const k=h.map(j=>({...j,id:sr(m.get(j.id)),fromId:sr(g.get(j.fromId)),toId:sr(g.get(j.toId))})),_=[],T=[];for(const j of c)this.store.has(j.id)||((j.type==="image"||j.type==="video")&&((D=j.props.src)!=null&&D.startsWith("data:image"))&&(T.push(nt(j)),j.props.src=null),_.push(j));return Promise.allSettled(T.map(async j=>{const O=await fQ(j.props.src,j.props.name,j.props.mimeType??"image/png"),R=await this.getAssetForExternalContent({type:"file",file:O,assetId:j.id});if(!R){this.deleteAssets([j.id]);return}this.updateAssets([{...R,id:j.id}])})),this.run(()=>{_.length>0&&this.createAssets(_),this.createShapes(I),this.createBindings(k),r&&this.select(...C.map(L=>L.id)),v!==a&&this.reparentShapes(C.map(L=>L.id),v);const j=I.map(L=>this.getShape(L.id)),O=Z.Common(j.map(L=>this.getShapePageBounds(L)));if(i===void 0)if(Dn(v)){const L=this.getViewportPageBounds();s||L.includes(Z.From(O))?i=O.center:i=L.center}else{const L=this.getShape(v);i=q.applyToPoint(this.getShapePageTransform(L),this.getShapeGeometry(L).bounds.center)}if(C.length===1){const L=C[0];if(this.isShapeOfType(L,"frame"))for(;this.getShapesAtPoint(i).some(G=>this.isShapeOfType(G,"frame")&&G.props.w===L.props.w&&G.props.h===L.props.h);)i.x+=O.w+16}const R=Z.Common(ye(C.map(({id:L})=>this.getShapePageBounds(L)))).center,B=x.Sub(i,R);this.updateShapes(C.map(({id:L})=>{const G=this.getShape(L),$=this.getShapeParentTransform(L).decompose().rotation,U=x.Rot(B,-$);return{id:G.id,type:G.type,x:G.x+U.x,y:G.y+U.y}}))}),this}async getSvgElement(e,n={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id);if(r.length!==0)return uQ(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(wn),{x:l,y:c,z:u}=rh(()=>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:_f,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===B_.CAMERA_MOVE?((v=this.store.unsafeGetWithoutCapture(_f))==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 mZ(this.store)}loadSnapshot(e,n){return bj(this.store,e,n),this}_zoomToFitPageContentAt100Percent(){const e=this.getCurrentPageBounds();e&&this.zoomToBounds(e,{immediate:!0,targetZoom:this.getBaseZoom()})}_navigateToDeepLink(e){this.run(()=>{switch(e.type){case"page":{const n=this.getPage(e.pageId);n&&this.setCurrentPage(n),this._zoomToFitPageContentAt100Percent();return}case"shapes":{const n=ye(e.shapeIds.map(i=>this.getShape(i))),r={};for(const i of n){const a=this.getAncestorPageId(i);a&&(r[a]??(r[a]=[]),r[a].push(i))}const[o,s]=Object.entries(r).sort(([i,a],[l,c])=>c.length-a.length)[0]??["",[]];if(!o||!s.length)this._zoomToFitPageContentAt100Percent();else{this.setCurrentPage(o);const i=Z.Common(s.map(a=>this.getShapePageBounds(a)));this.zoomToBounds(i,{immediate:!0,targetZoom:this.getBaseZoom()})}return}case"viewport":{if(e.pageId){if(!this.getPage(e.pageId)){this._zoomToFitPageContentAt100Percent();return}this.setCurrentPage(e.pageId)}this.zoomToBounds(e.bounds,{immediate:!0,inset:0});return}default: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",mQ((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=W("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=fw(i=>i(),(e==null?void 0:e.debounceMs)??500),s=is("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.shiftKey=!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(wn),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}=rh(()=>this.getCamera()),{panSpeed:S,zoomSpeed:y}=l;this._setCamera(new x(g+u*S/v-p/v+p/(c*y),m+h*S/v-f/v+f/(c*y),c*y),{immediate:!0});return}case"pinch_end":{if(!n.isPinching)return this;n.isPinching=!1;const{_selectedShapeIdsAtPointerDown:c}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,c.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(c)}));return}}}case"wheel":{if(l.isLocked)return;if(this._updateInputsFromEvent(e),!this.menus.hasAnyOpenMenus()){const{panSpeed:c,zoomSpeed:u,wheelBehavior:h}=l;if(h!=="none"){this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:p,y:f,z:g}=rh(()=>this.getCamera()),{x:m,y:v,z:S=0}=e.delta;let y=h;switch(n.ctrlKey&&(y=h==="pan"?"zoom":"pan"),y){case"zoom":{const{x:b,y:P}=this.inputs.currentScreenPoint;let C=S;h==="zoom"&&(Math.abs(v)>10?C=10*Math.sign(v)/100:C=v/100);const I=g+(C??0)*u*g;this._setCamera(new x(p+(b/I-b)-(b/g-b),f+(P/I-P)-(P/g-P),I),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new x(p+m*c/g,f+v*c/g,g),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}}break}case"pointer":{if(n.isPinching)return;this._updateInputsFromEvent(e);const{isPen:c}=e,{isPenMode:u}=i;switch(e.name){case"pointer_down":{if(u&&!c)return;if(this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{this.dispatch({...e,point:this.inputs.currentScreenPoint,name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),e.button===U_&&(this.capturedPointerId=e.pointerId),n.buttons.add(e.button),n.isPointing=!0,n.isDragging=!1,!u&&c&&this.updateInstanceState({isPenMode:!0}),e.button===H_?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===uh&&(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}=rh(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:g,previousScreenPoint:m}=this.inputs,{panSpeed:v}=l,S=x.Sub(g,m);this.setCamera(new x(h+S.x*v/f,p+S.y*v/f,f),{immediate:!0}),this.maybeTrackPerformance("Panning");return}n.isPointing&&!n.isDragging&&x.Dist2(o,s)*this.getZoomLevel()>(i.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/f&&(n.isDragging=!0,clearTimeout(this._longPressTimeout));break}case"pointer_up":{if(n.isDragging=!1,n.isPointing=!1,clearTimeout(this._longPressTimeout),n.buttons.delete(e.button),this.menus.hasAnyOpenMenus()||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 U_:{this.setCursor({type:"grab",rotation:0});break}case uh: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===H_&&(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(uh)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===uh?e.name="middle_click":e.button===o1&&(e.name="right_click");const{isPenMode:c}=this.store.unsafeGetWithoutCapture(wn);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=zJ(P0);ee(J,1,"getIsShapeHiddenCache",xR,Q);ee(J,1,"getCanUndo",vR,Q);ee(J,1,"getCanRedo",SR,Q);ee(J,1,"getPath",yR,Q);ee(J,1,"getCurrentTool",mR,Q);ee(J,1,"getCurrentToolId",gR,Q);ee(J,1,"getDocumentSettings",fR,Q);ee(J,1,"getInstanceState",pR,Q);ee(J,1,"getOpenMenus",hR,Q);ee(J,1,"getIsMenuOpen",dR,Q);ee(J,1,"getPageStates",uR,Q);ee(J,1,"_getPageStatesQuery",cR,Q);ee(J,1,"getCurrentPageState",lR,Q);ee(J,1,"_getCurrentPageStateId",aR,Q);ee(J,1,"getSelectedShapeIds",iR,Q);ee(J,1,"getSelectedShapes",sR,Q);ee(J,1,"getOnlySelectedShapeId",oR,Q);ee(J,1,"getOnlySelectedShape",rR,Q);ee(J,1,"getSelectionPageBounds",nR,Q);ee(J,1,"getSelectionRotation",tR,Q);ee(J,1,"getSelectionRotatedPageBounds",eR,Q);ee(J,1,"getSelectionRotatedScreenBounds",JD,Q);ee(J,1,"getFocusedGroupId",QD,Q);ee(J,1,"getFocusedGroup",ZD,Q);ee(J,1,"getEditingShapeId",qD,Q);ee(J,1,"getEditingShape",XD,Q);ee(J,1,"getHoveredShapeId",YD,Q);ee(J,1,"getHoveredShape",VD,Q);ee(J,1,"getHintingShapeIds",GD,Q);ee(J,1,"getHintingShape",WD,Q);ee(J,1,"getErasingShapeIds",KD,Q);ee(J,1,"getErasingShapes",HD,Q);ee(J,1,"_unsafe_getCameraId",UD,Q);ee(J,1,"getCamera",BD,Q);ee(J,1,"getViewportPageBoundsForFollowing",zD,Q);ee(J,1,"getCameraForFollowing",ND,Q);ee(J,1,"getZoomLevel",FD,Q);ee(J,1,"getViewportScreenBounds",$D,Q);ee(J,1,"getViewportScreenCenter",LD,Q);ee(J,1,"getViewportPageBounds",RD,Q);ee(J,1,"_getCollaboratorsQuery",DD,Q);ee(J,1,"getCollaborators",OD,Q);ee(J,1,"getCollaboratorsOnCurrentPage",jD,Q);ee(J,1,"getRenderingShapes",AD,Q);ee(J,1,"_getAllPagesQuery",MD,Q);ee(J,1,"getPages",TD,Q);ee(J,1,"getCurrentPageId",kD,Q);ee(J,1,"getCurrentPageShapeIdsSorted",ED,Q);ee(J,1,"_getAllAssetsQuery",ID,Q);ee(J,1,"_getShapeGeometryCache",_D,Q);ee(J,1,"_getShapeHandlesCache",CD,Q);ee(J,1,"_getShapePageTransformCache",PD,Q);ee(J,1,"_getShapePageBoundsCache",bD,Q);ee(J,1,"_getShapeClipPathCache",wD,Q);ee(J,1,"_getShapeMaskCache",xD,Q);ee(J,1,"_getShapeMaskedPageBoundsCache",vD,Q);ee(J,1,"_notVisibleShapes",SD,Q);ee(J,1,"getCulledShapes",yD,Q);ee(J,1,"getCurrentPageBounds",mD,Q);ee(J,1,"getCurrentPageShapes",gD,Q);ee(J,1,"getCurrentPageShapesSorted",fD,Q);ee(J,1,"getCurrentPageRenderingShapesSorted",pD,Q);ee(J,1,"_getBindingsIndexCache",hD,Q);ee(J,1,"_getSelectionSharedStyles",dD,Q);ee(J,1,"getSharedStyles",uD,Q);ee(J,1,"getSharedOpacity",cD,Q);ee(J,1,"getIsFocused",lD,Q);ee(J,1,"getIsReadonly",aD,Q);ee(J,1,"_setShiftKeyTimeout",iD,Q);ee(J,1,"_setAltKeyTimeout",sD,Q);ee(J,1,"_setCtrlKeyTimeout",oD,Q);ee(J,1,"_setMetaKeyTimeout",rD,Q);UJ(J,Q);function mh(t,e=t.getCurrentPageId()){const n=t.getPage(e).name;t.emit("max-shapes",{name:n,pageId:e,count:t.options.maxShapesPerPage})}function go(t,e){if(!e)return t;let n=null;const r=Object.entries(e);for(let o=0,s=r.length;o<s;o++){const[i,a]=r[o];if(a!==void 0&&!(i==="id"||i==="type"||i==="typeName")&&a!==t[i]){if(n||(n={...t}),i==="props"||i==="meta"){n[i]={...t[i]};for(const[l,c]of Object.entries(a))c!==void 0&&(n[i][l]=c);continue}n[i]=a}}return n||t}function wR(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++)wR(t,o[s],n)}function xI(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=xn.ok(n(s))}catch(a){r=xn.err(a)}});t.store.applyDiff(i0(o))},{history:"ignore"}),r.ok)return r.value;throw r.error}function wI(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 yd(){const t=z(),e=pd();return H("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'/>",PI="<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'/>",yh='<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 As(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 KJ=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],WJ={none:()=>"none","ew-resize":(t,e,n)=>As(PI,t,0,e,n),"ns-resize":(t,e,n)=>As(PI,t,90,e,n),"nesw-resize":(t,e,n)=>As(bI,t,0,e,n),"nwse-resize":(t,e,n)=>As(bI,t,90,e,n),"nwse-rotate":(t,e,n)=>As(yh,t,0,e,n),"nesw-rotate":(t,e,n)=>As(yh,t,90,e,n),"senw-rotate":(t,e,n)=>As(yh,t,180,e,n),"swne-rotate":(t,e,n)=>As(yh,t,270,e,n)};function nr(t,e=0,n="black"){return WJ[t](BY(e),!1,n)}function GJ(){const t=z(),e=Mt(),n=yd();ni("useCursor",()=>{const{type:r,rotation:o}=t.getInstanceState().cursor;if(KJ.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 VJ(){const t=z(),e=Mt(),n=yd(),r=H(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 YJ(){const[t,e]=w.useState(0);w.useEffect(()=>e(n=>n+1),[])}const XJ=t=>t.props.src,qJ={upload:(t,e)=>os.blobToDataUrl(e)};function ZJ(t){return"schema"in t&&t.schema?t.schema:AY({shapes:"shapeUtils"in t&&t.shapeUtils?CI(Ej(t.shapeUtils)):void 0,bindings:"bindingUtils"in t&&t.bindingUtils?CI(Cj(t.bindingUtils)):void 0,migrations:"migrations"in t?t.migrations:void 0})}function Fu({initialData:t,defaultName:e="",id:n,assets:r=qJ,onMount:o,collaboration:s,...i}={}){const a=ZJ(i),l=new Gw({id:n,schema:a,initialData:t,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??XJ},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");bj(l,i.snapshot)}return l}function CI(t){return Object.fromEntries(t.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}const QJ=(t,e)=>e.some(n=>t instanceof n);let _I,II;function JJ(){return _I||(_I=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function eee(){return II||(II=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const bR=new WeakMap,C0=new WeakMap,PR=new WeakMap,Wy=new WeakMap,w1=new WeakMap;function tee(t){const e=new Promise((n,r)=>{const o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{n(ls(t.result)),o()},i=()=>{r(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return e.then(n=>{n instanceof IDBCursor&&bR.set(n,t)}).catch(()=>{}),w1.set(e,t),e}function nee(t){if(C0.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)});C0.set(t,e)}let _0={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return C0.get(t);if(e==="objectStoreNames")return t.objectStoreNames||PR.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return ls(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 ree(t){_0=t(_0)}function oee(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...n){const r=t.call(Gy(this),e,...n);return PR.set(r,e.sort?e.sort():[e]),ls(r)}:eee().includes(t)?function(...e){return t.apply(Gy(this),e),ls(bR.get(this))}:function(...e){return ls(t.apply(Gy(this),e))}}function see(t){return typeof t=="function"?oee(t):(t instanceof IDBTransaction&&nee(t),QJ(t,JJ())?new Proxy(t,_0):t)}function ls(t){if(t instanceof IDBRequest)return tee(t);if(Wy.has(t))return Wy.get(t);const e=see(t);return e!==t&&(Wy.set(t,e),w1.set(e,t)),e}const Gy=t=>w1.get(t);function CR(t,e,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(t,e),a=ls(i);return r&&i.addEventListener("upgradeneeded",l=>{r(ls(i.result),l.oldVersion,l.newVersion,ls(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 _R(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);return e&&n.addEventListener("blocked",r=>e(r.oldVersion,r)),ls(n).then(()=>{})}const iee=["get","getKey","getAll","getAllKeys","count"],aee=["put","add","delete","clear"],Vy=new Map;function EI(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(Vy.get(e))return Vy.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,o=aee.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(o||iee.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 Vy.set(e,s),s}ree(t=>({...t,get:(e,n,r)=>EI(e,n)||t.get(e,n,r),has:(e,n)=>!!EI(e,n)||t.has(e,n)}));const lee="TLDRAW_DOCUMENT_v2",cee="TLDRAW_ASSET_STORE_v1",IR="TLDRAW_DB_NAME_INDEX_v2",_e={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function ER(t){const e=lee+t;return dee(e),await CR(e,4,{upgrade(n){n.objectStoreNames.contains(_e.Records)||n.createObjectStore(_e.Records),n.objectStoreNames.contains(_e.Schema)||n.createObjectStore(_e.Schema),n.objectStoreNames.contains(_e.SessionState)||n.createObjectStore(_e.SessionState),n.objectStoreNames.contains(_e.Assets)||n.createObjectStore(_e.Assets)}})}async function uee(t){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(p=>p.name):b1(),n=cee+t;if(!e.find(p=>p===n))return;const o=await CR(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 ER(t),u=c.transaction([_e.Assets],"readwrite"),h=u.objectStore(_e.Assets);for(const[p,f]of l)h.put(f,p);await u.done,o.close(),c.close(),await _R(n)}const du=class du{constructor(e){E(this,"getDbPromise");E(this,"isClosed",!1);E(this,"pendingTransactionSet",new Set);du.connectedInstances.add(this),this.getDbPromise=(async()=>(await uee(e),await ER(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Mu)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),du.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",[_e.Records,_e.Schema,_e.SessionState],async n=>{var l,c;const r=n.objectStore(_e.Records),o=n.objectStore(_e.Schema),s=n.objectStore(_e.SessionState);let i=e?(l=await s.get(e))==null?void 0:l.snapshot:null;return i||(i=(c=(await s.getAll()).sort((h,p)=>h.updatedAt-p.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await o.get(_e.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:n,sessionId:r,sessionStateSnapshot:o}){await this.tx("readwrite",[_e.Records,_e.Schema,_e.SessionState],async s=>{const i=s.objectStore(_e.Records),a=s.objectStore(_e.Schema),l=s.objectStore(_e.SessionState);for(const[c,u]of Object.entries(n.added))await i.put(u,c);for(const[c,u]of Object.values(n.updated))await i.put(u,u.id);for(const c of Object.keys(n.removed))await i.delete(c);a.put(e.serialize(),_e.Schema),o&&r?l.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:e,snapshot:n,sessionId:r,sessionStateSnapshot:o}){await this.tx("readwrite",[_e.Records,_e.Schema,_e.SessionState],async s=>{const i=s.objectStore(_e.Records),a=s.objectStore(_e.Schema),l=s.objectStore(_e.SessionState);await i.clear();for(const[c,u]of Object.entries(n))await i.put(u,c);a.put(e.serialize(),_e.Schema),o&&r?l.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[_e.SessionState],async e=>{const n=e.objectStore(_e.SessionState),r=(await n.getAll()).sort((s,i)=>s.updatedAt-i.updatedAt);if(r.length<10){await e.done;return}const o=r.slice(0,r.length-10);for(const{id:s}of o)await n.delete(s)})}async getAsset(e){return await this.tx("readonly",[_e.Assets],async n=>await n.objectStore(_e.Assets).get(e))}async storeAsset(e,n){await this.tx("readwrite",[_e.Assets],async r=>{await r.objectStore(_e.Assets).put(n,e)})}};E(du,"connectedInstances",new Set);let Of=du;function b1(){const t=JSON.parse(xw(IR)||"[]")??[];return Array.isArray(t)?t:[]}function dee(t){const e=new Set(b1());e.add(t),ww(IR,JSON.stringify([...e]))}function hee(){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 pee(){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 fee=350,gee=1e4,kI=Symbol("UPDATE_INSTANCE_STATE"),mee=t=>t;class yee{constructor(e){E(this,"onmessage")}postMessage(e){}close(){}}const See=typeof BroadcastChannel>"u"?yee:BroadcastChannel;class vee{constructor(e,{persistenceKey:n,sessionId:r=jf,onLoad:o,onLoadError:s},i=new See(`tldraw-tab-sync-${n}`)){E(this,"disposables",new Set);E(this,"diffQueue",[]);E(this,"didDispose",!1);E(this,"shouldDoFullDBWrite",!0);E(this,"isReloading",!1);E(this,"persistenceKey");E(this,"sessionId");E(this,"serializedSchema");E(this,"isDebugging",!1);E(this,"documentTypes");E(this,"$sessionStateSnapshot");E(this,"db");E(this,"initTime",Date.now());E(this,"isPersisting",!1);E(this,"didLastWriteError",!1);E(this,"scheduledPersistTimeout",null);this.store=e,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=n,this.sessionId=r,this.db=new Of(n),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=c1(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(mee({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),pee();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const o=Object.fromEntries(r.records.map(a=>[a.id,a])),s=r.sessionStateSnapshot??gZ(o),i=this.store.schema.migrateStoreSnapshot({store:o,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(i.type==="error"){console.error("failed to migrate store",i),n(new Error(`Failed to migrate store: ${i.reason}`));return}this.store.mergeRemoteChanges(()=>{this.store.put(Object.values(i.value).filter(a=>this.documentTypes.has(a.typeName)),"initialize")}),s&&m0(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"),Eo(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(s.changes),this.store.ensureStoreIsUsable()})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),e(this)}catch(o){if(this.debug("error loading data from store",o),this.didDispose)return;n(o);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(e=>e())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?gee:fee))}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=Ww(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),hee(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function kR(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 xee(t){const[e,n]=kR({status:"loading"});return t=dd(t),w.useEffect(()=>{const{persistenceKey:r,sessionId:o,...s}=t;if(!r){n({status:"not-synced",store:Fu(s)});return}n({status:"loading"});const i=new ko,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=Fu({...s,assets:a});let c=!1;const u=new vee(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 wee(){const t=z(),e=Mt();w.useEffect(()=>{const n=s=>e.style.setProperty("--tl-zoom",s.toString()),r=fw(n,100),o=new Vl("useZoomCss",()=>{t.getCurrentPageShapeIds().size<300?n(t.getZoomLevel()):r(t.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[t,e])}function I0(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 bee(t){const e=atob(t),n=I0(e);return crypto.subtle.importKey("spki",new Uint8Array(n),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const Pee=5,Uc={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},Cee=Math.max(...Object.values(Uc)),Hc={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},_ee=Object.keys(Hc).length,Yy="sales@tldraw.com",Iee=`${Vs()}/watermarks/watermark-track.svg`;class Hg{constructor(e,n,r){E(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");E(this,"isDevelopment");E(this,"isTest");E(this,"isCryptoAvailable");E(this,"state",It("license state","pending"));E(this,"verbose",!0);this.isTest=!1,this.isDevelopment=this.getIsDevelopment(r),this.publicKey=n||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,this.getLicenseFromKey(e).then(o=>{const s=Eee(o);!this.isDevelopment&&s&&no(Iee),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 bee(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(I0(atob(r))),new Uint8Array(I0(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>_ee&&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[Hc.ID],hosts:l[Hc.HOSTS],flags:l[Hc.FLAGS],expiryDate:l[Hc.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,Uc.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,Uc.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,Uc.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,Uc.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()+Pee+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 ${Yy} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const n=this.getExpirationDateWithGracePeriod(e),r={major:new Date($_.major),minor:new Date($_.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 ${Yy} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${Yy} if you would like to use tldraw on other domains.`]),e.license.flags>=Cee*2&&this.outputMessages(["This tldraw license contains some unknown flags.","You may want to update tldraw packages to a newer version to get access to new functionality."])}outputMessages(e){if(!this.isTest&&this.verbose){this.outputDelimiter();for(const n of e)console.log(`%c${n}`,"color: white; background: crimson; padding: 2px; border-radius: 3px;");this.outputDelimiter()}}outputDelimiter(){console.log("%c-------------------------------------------------------------------","color: white; background: crimson; padding: 2px; border-radius: 3px;")}}E(Hg,"className","tl-watermark_SEE-LICENSE");function Eee(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 TR=w.createContext({}),kee=()=>w.useContext(TR);function Tee({licenseKey:t,children:e}){const[n]=w.useState(()=>new Hg(t));return d.jsx(TR.Provider,{value:n,children:e})}function _i(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 Mee='<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>',Aee='<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 jee(t){return H("watermarkState",()=>t.state.get(),[t])}const Oee=`data:image/svg+xml;utf8,${encodeURIComponent(Mee)}`,Dee=`data:image/svg+xml;utf8,${encodeURIComponent(Aee)}`,Ree=w.memo(function(){const e=kee(),n=z(),r=H("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),o=jee(e);return["licensed-with-watermark","unlicensed"].includes(o)?d.jsxs(d.Fragment,{children:[d.jsx($ee,{}),d.jsx(Lee,{src:r?Dee:Oee})]}):null}),Lee=w.memo(function({src:e}){const n=z(),r=H("debug mode",()=>n.getInstanceState().isDebugMode,[n]),o=H("is menu open",()=>n.menus.hasAnyOpenMenus(),[n]),s=H("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),i=zA(),a=w.useRef(null);_i(a);const l=`url('${e}') center 100% / 100% no-repeat`,c="https://tldraw.dev";return d.jsx("div",{ref:a,className:Hg.className,"data-debug":r,"data-menu":o,"data-mobile":s,draggable:!1,...i,children:Ge.isWebview?d.jsx("a",{draggable:!1,role:"button",onPointerDown:u=>{Et(u),xe(u)},onClick:()=>Ag.openWindow(c,"_blank"),style:{mask:l,WebkitMask:l}}):d.jsx("a",{href:c,target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:u=>{Et(u)},style:{mask:l,WebkitMask:l}})})}),$ee=w.memo(function(){const e=Hg.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
|
-
|
|
152
|
-
.${e}[data-menu='true'] {
|
|
153
|
-
pointer-events: none;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
.${e}[data-debug='true'] {
|
|
157
|
-
bottom: 46px;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
.${e}[data-mobile='true'] {
|
|
161
|
-
border-radius: 4px 0px 0px 4px;
|
|
162
|
-
right: -2px;
|
|
163
|
-
width: 8px;
|
|
164
|
-
height: 48px;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
.${e}[data-mobile='true'] > a {
|
|
168
|
-
width: 8px;
|
|
169
|
-
height: 32px;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
@media (hover: hover) {
|
|
173
|
-
.${e} > a {
|
|
174
|
-
pointer-events: none;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
.${e}:hover {
|
|
178
|
-
background-color: var(--color-background);
|
|
179
|
-
transition: background-color 0.2s ease-in-out;
|
|
180
|
-
transition-delay: 0.32s;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
.${e}:hover > a {
|
|
184
|
-
animation: delayed_link 0.2s forwards ease-in-out;
|
|
185
|
-
animation-delay: 0.32s;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
@keyframes delayed_link {
|
|
191
|
-
0% {
|
|
192
|
-
cursor: inherit;
|
|
193
|
-
opacity: .38;
|
|
194
|
-
pointer-events: none;
|
|
195
|
-
}
|
|
196
|
-
100% {
|
|
197
|
-
cursor: pointer;
|
|
198
|
-
opacity: 1;
|
|
199
|
-
pointer-events: all;
|
|
200
|
-
}
|
|
201
|
-
}`;return d.jsx("style",{children:n})}),Fee=[],Nee=[],zee=[],Bee="tl-container",Uee=w.memo(function({store:e,components:n,className:r,user:o,...s}){const[i,a]=w.useState(null),l=w.useMemo(()=>o??Sj(),[o]),c=(n==null?void 0:n.ErrorFallback)===void 0?cj:n==null?void 0:n.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??Fee,bindingUtils:s.bindingUtils??Nee,tools:s.tools??zee,components:n};return d.jsx("div",{ref:a,"data-tldraw":RA,draggable:!1,className:le(`${Bee} tl-theme__light`,r),onPointerDown:Et,tabIndex:-1,children:d.jsx($u,{fallback:c,onError:h=>gw(h,{tags:{origin:"react.tldraw-before-app"}}),children:i&&d.jsx(Tee,{licenseKey:s.licenseKey,children:d.jsx(ZY,{container:i,children:d.jsx(eZ,{overrides:n,children:e?e instanceof Gw?d.jsx(AR,{...u,store:e,user:l}):d.jsx(MR,{...u,store:e,user:l}):d.jsx(Hee,{...u,store:e,user:l})})})})})})});function Hee(t){const{defaultName:e,snapshot:n,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:l,assets:c}=t,u=xee({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:n,assets:c});return d.jsx(MR,{...t,store:u,user:l})}const MR=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}=ot();switch(e.status){case"error":throw e.error;case"loading":return s?d.jsx(s,{}):null}return d.jsx(AR,{...r,store:e.store,user:n})}),Xy=()=>document.location.search.includes("tldraw_preserve_focus");function AR({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}=ot(),v=Mt(),[S,y]=kR(null),b=w.useRef(null),P=dd(f===!0?{}:f),C=w.useRef({autoFocus:l&&!Xy(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P});w.useLayoutEffect(()=>{C.current={autoFocus:l&&!Xy(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P}},[l,c,a,u,P]),w.useLayoutEffect(()=>{const{autoFocus:_,inferDarkMode:T,initialState:M,cameraOptions:D,deepLinks:j}=C.current,O=new Q({store:n,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>v,user:i,initialState:M,autoFocus:_,inferDarkMode:T,cameraOptions:D,options:h,licenseKey:p,isShapeHidden:g});return O.updateViewportScreenBounds(b.current??v),j&&(j!=null&&j.getUrl?O.navigateToDeepLink({...j,url:j.getUrl(O)}):O.navigateToDeepLink(j)),y(O),()=>{O.dispose()}},[s,v,h,o,n,r,i,y,p,g]),w.useLayoutEffect(()=>{if(S&&P)return S.registerDeepLinkListener(P)},[S,P]),w.useLayoutEffect(()=>{S&&u&&S.setCameraOptions(u)},[S,u]);const I=w.useSyncExternalStore(w.useCallback(_=>S?(S.on("crash",_),()=>S.off("crash",_)):()=>{},[S]),()=>(S==null?void 0:S.getCrashingError())??null);w.useEffect(function(){if(!S)return;function T(){S&&S.focus()}function M(){S&&S.blur()}if(l&&Xy())return S.getContainer().addEventListener("pointerdown",T),document.body.addEventListener("pointerdown",M),()=>{var D;(D=S.getContainer())==null||D.removeEventListener("pointerdown",T),document.body.removeEventListener("pointerdown",M)}},[S,l]);const{Canvas:k}=ot();return S?d.jsx($u,{fallback:m,onError:_=>S.annotateError(_,{origin:"react.tldraw",willCrashApp:!0}),children:I?d.jsx(Wee,{crashingError:I}):d.jsx(sd.Provider,{value:S,children:d.jsxs(Kee,{onMount:t,children:[e??(k?d.jsx(k,{}):null),d.jsx(Ree,{})]})})}):d.jsx("div",{className:"tl-canvas",ref:b})}function Kee({children:t,onMount:e}){return wee(),GJ(),VJ(),YJ(),OR(n=>{const r=n.store.props.onMount(n),o=e==null?void 0:e(n);return()=>{r==null||r(),o==null||o()}}),t}function Wee({crashingError:t}){throw t}function P1({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function jR({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function OR(t){const e=z(),n=$g(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 si({children:t,className:e="",...n}){return d.jsx("div",{...n,className:le("tl-html-container",e),children:t})}class ap{constructor(e){this.editor=e}}E(ap,"props"),E(ap,"migrations"),E(ap,"type");function Kg(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 Jl extends eo{getGeometry(e){return new gs({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,n){return Kg(e,n)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,n,r){return{...n.props,w:Ie(e.props.w,n.props.w,r),h:Ie(e.props.h,n.props.h,r)}}}var IS;let Gee=(IS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(IS,"id","idle"),IS);var ES;let Vee=(ES=class extends ie{constructor(){super(...arguments);E(this,"wasFocusedOnEnter",!1)}onEnter(){this.wasFocusedOnEnter=!this.editor.menus.hasAnyOpenMenus()}onPointerMove(n){if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=Be(),i=this.editor.markHistoryStoppingPoint(`creating_box:${s}`);this.editor.createShapes([{id:s,type:o,x:r.x,y:r.y,props:{w:1,h:1}}]).select(s);const a=this.parent;this.editor.setCurrentTool("select.resizing",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:i,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?l=>{var c;return(c=a.onCreate)==null?void 0:c.call(a,l)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:n}=this.editor.inputs;if(!this.wasFocusedOnEnter)return;const r=this.parent.shapeType,o=Be();this.editor.markHistoryStoppingPoint(`creating_box:${o}`),this.editor.createShapes([{id:o,type:r,x:n.x,y:n.y}]);const s=this.editor.getShape(o);if(!s){this.cancel();return}let{w:i,h:a}=s.props;const l=new x(i/2,a/2),c=this.editor.getShapeParentTransform(s);c&&l.rot(-c.rotation());let u=1;this.editor.user.getIsDynamicResizeMode()&&(u=1/this.editor.getZoomLevel(),i*=u,a*=u,l.mul(u));const h=nt(s);h.x=s.x-l.x,h.y=s.y-l.y,h.props.w=i,h.props.h=a,"scale"in s.props&&(h.props.scale=u),this.editor.updateShape(h),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},E(ES,"id","pointing"),ES);class E0 extends ie{static children(){return[Gee,Vee]}}E(E0,"id","box"),E(E0,"initial","idle");function Yee(t,e,n){const r=w.useRef(!1),o=w.useCallback(i=>{r.current=i,i?Wr.addOpenMenu(t):Wr.deleteOpenMenu(t),e==null||e(i)},[t,e]),s=H("is menu open",()=>Wr.getOpenMenus().includes(t),[t]);return w.useEffect(()=>(r.current&&(n==null||n("open-menu"),Wr.addOpenMenu(t)),()=>{r.current&&(Wr.deleteOpenMenu(t),Wr.getOpenMenus().forEach(i=>{i.startsWith(t)&&(n==null||n("close-menu"),Wr.deleteOpenMenu(i))}),r.current=!1)}),[t,n]),[s,o]}function Wg(t){const e=z();return H("isEditing",()=>e.getEditingShapeId()===t,[e,t])}function yo(t){const e=z();return w.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===o1){e.dispatch({type:"pointer",target:"selection",handle:t,name:"right_click",...Kn(c)});return}if(c.button!==0)return;const u=Mf(c.currentTarget);function h(){u.removeEventListener("pointerup",h),ld(u,c)}ad(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:t,...Kn(c)}),Et(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,...Kn(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:t,...Kn(c)})}}},[e,t])}function Xee(t){const[e,n]=w.useState(()=>({store:Fu(t),opts:t}));if(!wT(e.opts,t)){const r={store:Fu(t),opts:t};return n(r),r.store}return e.store}const qee=20,Zee=8;function C1(t,e=qee){return Math.max(Zee,Math.ceil(t/e))}class rl extends Ci{constructor(n){super({...n,isFilled:!1,isClosed:!1});E(this,"_center");E(this,"radius");E(this,"start");E(this,"end");E(this,"largeArcFlag");E(this,"sweepFlag");E(this,"measure");E(this,"angleStart");E(this,"angleEnd");const{center:r,sweepFlag:o,largeArcFlag:s,start:i,end:a}=n;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=x.Angle(r,i),this.angleEnd=x.Angle(r,a),this.radius=x.Dist(r,i),this.measure=UY(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=h0(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=hd(n,r,o,s);return c===null?!1:c.some(u=>{const h=h0(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=C1(Math.abs(o));l<c+1;l++){const u=l/c*r,h=i+u;a.push(ia(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 _1 extends Ci{constructor(n){super({isClosed:!0,...n});E(this,"_center");E(this,"radius");E(this,"x");E(this,"y");this.config=n;const{x:r=0,y:o=0,radius:s}=n;this.x=r,this.y=o,this._center=new x(s+r,s+o),this.radius=s}getBounds(){return new Z(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,o=Ne*r,s=[];for(let i=0,a=C1(o);i<a;i++){const l=i/a*Ne;s.push(ia(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 hd(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 ql{constructor(n){const{start:r,cp1:o,cp2:s,end:i}=n;super({...n,points:[r,i]});E(this,"a");E(this,"b");E(this,"c");E(this,"d");this.a=r,this.b=o,this.c=s,this.d=i}getVertices(){const n=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;n.push(new x((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*o.x+3*(1-c)*(c*c)*s.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*o.y+3*(1-c)*(c*c)*s.y+c*c*c*i.y))}return n}midPoint(){return 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 Qee extends Ci{constructor(n){super({...n,isClosed:!1,isFilled:!1});E(this,"points");E(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?n[0]:n[i-1],l=n[i],c=n[i+1],u=i===o?c:n[i+2],h=l,p=i===0?a:new x(l.x+(c.x-a.x)/6*s,l.y+(c.y-a.y)/6*s),f=i===o?c:new x(c.x-(u.x-l.x)/6*s,c.y-(u.y-l.y)/6*s),g=c;this._segments.push(new 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 Jee extends Ci{constructor(n){super({...n,isClosed:!0});E(this,"w");E(this,"h");E(this,"_edges");this.config=n;const{width:r,height:o}=n;this.w=r,this.h=o}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,o=n.length;r<o;r++){const s=n[r],i=n[(r+1)%o];this._edges.push(new ts({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=C1(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 S=0;S<l;S++)v[S]=new x(o+o*f,s+s*p),g=h*f+u*p,m=u*f-h*p,p=g,f=m;return v}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(n),s=x.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(o=>o.hitTestLineSegment(n,r))}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{w:n,h:r}=this,o=n/2,s=r/2,i=Math.max(0,o),a=Math.max(0,s);return LA(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 ete extends Ci{constructor(n){super({...n,isClosed:!0});E(this,"w");E(this,"h");E(this,"a");E(this,"b");E(this,"c");E(this,"d");this.config=n;const{width:r,height:o}=n;if(this.w=r,this.h=o,o>r){const s=r/2;this.a=new rl({start:new x(0,s),end:new x(r,s),center:new x(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new ts({start:new x(r,s),end:new x(r,o-s)}),this.c=new rl({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 ts({start:new x(0,o-s),end:new x(0,s)})}else{const s=o/2;this.a=new rl({start:new x(s,o),end:new x(s,0),center:new x(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new ts({start:new x(s,0),end:new x(r-s,0)}),this.c=new rl({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 ts({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 tte({shouldReload:t=!0}={}){GB();for(const e of Of.connectedInstances)await e.close();await Promise.all(b1().map(e=>_R(e))),WB(),t&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=tte);function nte(t,e="_blank"){Ag.openWindow(t,e)}xi("@tldraw/editor","3.3.0","esm");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 rte(t,e){typeof t=="function"?t(e):t!=null&&(t.current=e)}function Gg(...t){return e=>t.forEach(n=>rte(n,e))}function Qe(...t){return w.useCallback(Gg(...t),t)}function ote(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 xa(t,e=[]){let n=[];function r(s,i){const a=w.createContext(i),l=n.length;n=[...n,i];const c=h=>{var S;const{scope:p,children:f,...g}=h,m=((S=p==null?void 0:p[t])==null?void 0:S[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,ste(o,...e)]}function ste(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(s)[`__scope${c}`];return{...a,...h}},{});return w.useMemo(()=>({[`__scope${e.scopeName}`]:i}),[i])}};return n.scopeName=e.scopeName,n}var di=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{},ite=L4.useId||(()=>{}),ate=0;function cs(t){const[e,n]=w.useState(ite());return di(()=>{t||n(r=>r??String(ate++))},[t]),t||(e?`radix-${e}`:"")}function qt(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 Ii({prop:t,defaultProp:e,onChange:n=()=>{}}){const[r,o]=lte({defaultProp:e,onChange:n}),s=t!==void 0,i=s?t:r,a=qt(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 lte({defaultProp:t,onChange:e}){const n=w.useState(t),[r]=n,o=w.useRef(r),s=qt(e);return w.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),n}var aa=w.forwardRef((t,e)=>{const{children:n,...r}=t,o=w.Children.toArray(n),s=o.find(ute);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(k0,{...r,ref:e,children:w.isValidElement(i)?w.cloneElement(i,void 0,a):null})}return d.jsx(k0,{...r,ref:e,children:n})});aa.displayName="Slot";var k0=w.forwardRef((t,e)=>{const{children:n,...r}=t;if(w.isValidElement(n)){const o=hte(n);return w.cloneElement(n,{...dte(r,n.props),ref:e?Gg(e,o):o})}return w.Children.count(n)>1?w.Children.only(null):null});k0.displayName="SlotClone";var cte=({children:t})=>d.jsx(d.Fragment,{children:t});function ute(t){return w.isValidElement(t)&&t.type===cte}function dte(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 hte(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 pte=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ae=pte.reduce((t,e)=>{const n=w.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?aa: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 I1(t,e){t&&li.flushSync(()=>t.dispatchEvent(e))}function fte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(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 gte="DismissableLayer",T0="dismissableLayer.update",mte="dismissableLayer.pointerDownOutside",yte="dismissableLayer.focusOutside",TI,DR=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Sd=w.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=t,c=w.useContext(DR),[u,h]=w.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=w.useState({}),g=Qe(e,k=>h(k)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=m.indexOf(v),y=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,P=y>=S,C=vte(k=>{const _=k.target,T=[...c.branches].some(M=>M.contains(_));!P||T||(o==null||o(k),i==null||i(k),k.defaultPrevented||a==null||a())},p),I=xte(k=>{const _=k.target;[...c.branches].some(M=>M.contains(_))||(s==null||s(k),i==null||i(k),k.defaultPrevented||a==null||a())},p);return fte(k=>{y===c.layers.size-1&&(r==null||r(k),!k.defaultPrevented&&a&&(k.preventDefault(),a()))},p),w.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(TI=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),MI(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=TI)}},[u,p,n,c]),w.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),MI())},[u,c]),w.useEffect(()=>{const k=()=>f({});return document.addEventListener(T0,k),()=>document.removeEventListener(T0,k)},[]),d.jsx(Ae.div,{...l,ref:g,style:{pointerEvents:b?P?"auto":"none":void 0,...t.style},onFocusCapture:oe(t.onFocusCapture,I.onFocusCapture),onBlurCapture:oe(t.onBlurCapture,I.onBlurCapture),onPointerDownCapture:oe(t.onPointerDownCapture,C.onPointerDownCapture)})});Sd.displayName=gte;var Ste="DismissableLayerBranch",RR=w.forwardRef((t,e)=>{const n=w.useContext(DR),r=w.useRef(null),o=Qe(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})});RR.displayName=Ste;function vte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1),o=w.useRef(()=>{});return w.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){LR(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 xte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1);return w.useEffect(()=>{const o=s=>{s.target&&!r.current&&LR(yte,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 MI(){const t=new CustomEvent(T0);document.dispatchEvent(t)}function LR(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?I1(o,s):o.dispatchEvent(s)}var wte=Sd,bte=RR,qy="focusScope.autoFocusOnMount",Zy="focusScope.autoFocusOnUnmount",AI={bubbles:!1,cancelable:!0},Pte="FocusScope",Vg=w.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=t,[a,l]=w.useState(null),c=qt(o),u=qt(s),h=w.useRef(null),p=Qe(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:Ds(h.current,{select:!0})},v=function(b){if(f.paused||!a)return;const P=b.relatedTarget;P!==null&&(a.contains(P)||Ds(h.current,{select:!0}))},S=function(b){if(document.activeElement===document.body)for(const C of b)C.removedNodes.length>0&&Ds(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const y=new MutationObserver(S);return a&&y.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),y.disconnect()}}},[r,a,f.paused]),w.useEffect(()=>{if(a){OI.add(f);const m=document.activeElement;if(!a.contains(m)){const S=new CustomEvent(qy,AI);a.addEventListener(qy,c),a.dispatchEvent(S),S.defaultPrevented||(Cte(Tte($R(a)),{select:!0}),document.activeElement===m&&Ds(a))}return()=>{a.removeEventListener(qy,c),setTimeout(()=>{const S=new CustomEvent(Zy,AI);a.addEventListener(Zy,u),a.dispatchEvent(S),S.defaultPrevented||Ds(m??document.body,{select:!0}),a.removeEventListener(Zy,u),OI.remove(f)},0)}}},[a,c,u,f]);const g=w.useCallback(m=>{if(!n&&!r||f.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,S=document.activeElement;if(v&&S){const y=m.currentTarget,[b,P]=_te(y);b&&P?!m.shiftKey&&S===P?(m.preventDefault(),n&&Ds(b,{select:!0})):m.shiftKey&&S===b&&(m.preventDefault(),n&&Ds(P,{select:!0})):S===y&&m.preventDefault()}},[n,r,f.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:p,onKeyDown:g})});Vg.displayName=Pte;function Cte(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Ds(r,{select:e}),document.activeElement!==n)return}function _te(t){const e=$R(t),n=jI(e,t),r=jI(e.reverse(),t);return[n,r]}function $R(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 jI(t,e){for(const n of t)if(!Ite(n,{upTo:e}))return n}function Ite(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 Ete(t){return t instanceof HTMLInputElement&&"select"in t}function Ds(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&Ete(t)&&e&&t.select()}}var OI=kte();function kte(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=DI(t,e),t.unshift(e)},remove(e){var n;t=DI(t,e),(n=t[0])==null||n.resume()}}}function DI(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function Tte(t){return t.filter(e=>e.tagName!=="A")}var Mte="Portal",vd=w.forwardRef((t,e)=>{var a;const{container:n,...r}=t,[o,s]=w.useState(!1);di(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Vz.createPortal(d.jsx(Ae.div,{...r,ref:e}),i):null});vd.displayName=Mte;function Ate(t,e){return w.useReducer((n,r)=>e[n][r]??n,t)}var lo=t=>{const{present:e,children:n}=t,r=jte(e),o=typeof n=="function"?n({present:r.isPresent}):w.Children.only(n),s=Qe(r.ref,Ote(o));return typeof n=="function"||r.isPresent?w.cloneElement(o,{ref:s}):null};lo.displayName="Presence";function jte(t){const[e,n]=w.useState(),r=w.useRef({}),o=w.useRef(t),s=w.useRef("none"),i=t?"mounted":"unmounted",[a,l]=Ate(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=Sh(r.current);s.current=a==="mounted"?c:"none"},[a]),di(()=>{const c=r.current,u=o.current;if(u!==t){const p=s.current,f=Sh(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]),di(()=>{if(e){let c;const u=e.ownerDocument.defaultView??window,h=f=>{const m=Sh(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=Sh(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 Sh(t){return(t==null?void 0:t.animationName)||"none"}function Ote(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 Qy=0;function E1(){w.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??RI()),document.body.insertAdjacentElement("beforeend",t[1]??RI()),Qy++,()=>{Qy===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),Qy--}},[])}function RI(){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 xo=function(){return xo=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},xo.apply(this,arguments)};function FR(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 Dte(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 lp="right-scroll-bar-position",cp="width-before-scroll-bar",Rte="with-scroll-bars-hidden",Lte="--removed-body-scroll-bar-size";function Jy(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function $te(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 Fte=typeof window<"u"?w.useLayoutEffect:w.useEffect,LI=new WeakMap;function Nte(t,e){var n=$te(null,function(r){return t.forEach(function(o){return Jy(o,r)})});return Fte(function(){var r=LI.get(n);if(r){var o=new Set(r),s=new Set(t),i=n.current;o.forEach(function(a){s.has(a)||Jy(a,null)}),s.forEach(function(a){o.has(a)||Jy(a,i)})}LI.set(n,t)},[t]),n}function zte(t){return t}function Bte(t,e){e===void 0&&(e=zte);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 Ute(t){t===void 0&&(t={});var e=Bte(null);return e.options=xo({async:!0,ssr:!1},t),e}var NR=function(t){var e=t.sideCar,n=FR(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,xo({},n))};NR.isSideCarExport=!0;function Hte(t,e){return t.useMedium(e),NR}var zR=Ute(),eS=function(){},Yg=w.forwardRef(function(t,e){var n=w.useRef(null),r=w.useState({onScrollCapture:eS,onWheelCapture:eS,onTouchMoveCapture:eS}),o=r[0],s=r[1],i=t.forwardProps,a=t.children,l=t.className,c=t.removeScrollBar,u=t.enabled,h=t.shards,p=t.sideCar,f=t.noIsolation,g=t.inert,m=t.allowPinchZoom,v=t.as,S=v===void 0?"div":v,y=t.gapMode,b=FR(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),P=p,C=Nte([n,e]),I=xo(xo({},b),o);return w.createElement(w.Fragment,null,u&&w.createElement(P,{sideCar:zR,removeScrollBar:c,shards:h,noIsolation:f,inert:g,setCallbacks:s,allowPinchZoom:!!m,lockRef:n,gapMode:y}),i?w.cloneElement(w.Children.only(a),xo(xo({},I),{ref:C})):w.createElement(S,xo({},I,{className:l,ref:C}),a))});Yg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Yg.classNames={fullWidth:cp,zeroRight:lp};var Kte=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Wte(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=Kte();return e&&t.setAttribute("nonce",e),t}function Gte(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function Vte(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Yte=function(){var t=0,e=null;return{add:function(n){t==0&&(e=Wte())&&(Gte(e,n),Vte(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Xte=function(){var t=Yte();return function(e,n){w.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},BR=function(){var t=Xte(),e=function(n){var r=n.styles,o=n.dynamic;return t(r,o),null};return e},qte={left:0,top:0,right:0,gap:0},tS=function(t){return parseInt(t||"",10)||0},Zte=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[tS(n),tS(r),tS(o)]},Qte=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return qte;var e=Zte(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])}},Jte=BR(),Sl="data-scroll-locked",ene=function(t,e,n,r){var o=t.left,s=t.top,i=t.right,a=t.gap;return n===void 0&&(n="margin"),`
|
|
202
|
-
.`.concat(Rte,` {
|
|
203
|
-
overflow: hidden `).concat(r,`;
|
|
204
|
-
padding-right: `).concat(a,"px ").concat(r,`;
|
|
205
|
-
}
|
|
206
|
-
body[`).concat(Sl,`] {
|
|
207
|
-
overflow: hidden `).concat(r,`;
|
|
208
|
-
overscroll-behavior: contain;
|
|
209
|
-
`).concat([e&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
210
|
-
padding-left: `.concat(o,`px;
|
|
211
|
-
padding-top: `).concat(s,`px;
|
|
212
|
-
padding-right: `).concat(i,`px;
|
|
213
|
-
margin-left:0;
|
|
214
|
-
margin-top:0;
|
|
215
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
216
|
-
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
.`).concat(lp,` {
|
|
220
|
-
right: `).concat(a,"px ").concat(r,`;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
.`).concat(cp,` {
|
|
224
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
.`).concat(lp," .").concat(lp,` {
|
|
228
|
-
right: 0 `).concat(r,`;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
.`).concat(cp," .").concat(cp,` {
|
|
232
|
-
margin-right: 0 `).concat(r,`;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
body[`).concat(Sl,`] {
|
|
236
|
-
`).concat(Lte,": ").concat(a,`px;
|
|
237
|
-
}
|
|
238
|
-
`)},$I=function(){var t=parseInt(document.body.getAttribute(Sl)||"0",10);return isFinite(t)?t:0},tne=function(){w.useEffect(function(){return document.body.setAttribute(Sl,($I()+1).toString()),function(){var t=$I()-1;t<=0?document.body.removeAttribute(Sl):document.body.setAttribute(Sl,t.toString())}},[])},nne=function(t){var e=t.noRelative,n=t.noImportant,r=t.gapMode,o=r===void 0?"margin":r;tne();var s=w.useMemo(function(){return Qte(o)},[o]);return w.createElement(Jte,{styles:ene(s,!e,o,n?"":"!important")})},M0=!1;if(typeof window<"u")try{var vh=Object.defineProperty({},"passive",{get:function(){return M0=!0,!0}});window.addEventListener("test",vh,vh),window.removeEventListener("test",vh,vh)}catch{M0=!1}var ja=M0?{passive:!1}:!1,rne=function(t){return t.tagName==="TEXTAREA"},UR=function(t,e){if(!(t instanceof Element))return!1;var n=window.getComputedStyle(t);return n[e]!=="hidden"&&!(n.overflowY===n.overflowX&&!rne(t)&&n[e]==="visible")},one=function(t){return UR(t,"overflowY")},sne=function(t){return UR(t,"overflowX")},FI=function(t,e){var n=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=HR(t,r);if(o){var s=KR(t,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},ine=function(t){var e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;return[e,n,r]},ane=function(t){var e=t.scrollLeft,n=t.scrollWidth,r=t.clientWidth;return[e,n,r]},HR=function(t,e){return t==="v"?one(e):sne(e)},KR=function(t,e){return t==="v"?ine(e):ane(e)},lne=function(t,e){return t==="h"&&e==="rtl"?-1:1},cne=function(t,e,n,r,o){var s=lne(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=KR(t,a),g=f[0],m=f[1],v=f[2],S=m-v-s*g;(g||S)&&HR(t,a)&&(h+=S,p+=g),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(e.contains(a)||e===a));return(u&&(Math.abs(h)<1||!o)||!u&&(Math.abs(p)<1||!o))&&(c=!0),c},xh=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},NI=function(t){return[t.deltaX,t.deltaY]},zI=function(t){return t&&"current"in t?t.current:t},une=function(t,e){return t[0]===e[0]&&t[1]===e[1]},dne=function(t){return`
|
|
239
|
-
.block-interactivity-`.concat(t,` {pointer-events: none;}
|
|
240
|
-
.allow-interactivity-`).concat(t,` {pointer-events: all;}
|
|
241
|
-
`)},hne=0,Oa=[];function pne(t){var e=w.useRef([]),n=w.useRef([0,0]),r=w.useRef(),o=w.useState(hne++)[0],s=w.useState(BR)[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=Dte([t.lockRef.current],(t.shards||[]).map(zI),!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 S=xh(m),y=n.current,b="deltaX"in m?m.deltaX:y[0]-S[0],P="deltaY"in m?m.deltaY:y[1]-S[1],C,I=m.target,k=Math.abs(b)>Math.abs(P)?"h":"v";if("touches"in m&&k==="h"&&I.type==="range")return!1;var _=FI(k,I);if(!_)return!0;if(_?C=k:(C=k==="v"?"h":"v",_=FI(k,I)),!_)return!1;if(!r.current&&"changedTouches"in m&&(b||P)&&(r.current=C),!C)return!0;var T=r.current||C;return cne(T,v,m,T==="h"?b:P,!0)},[]),l=w.useCallback(function(m){var v=m;if(!(!Oa.length||Oa[Oa.length-1]!==s)){var S="deltaY"in v?NI(v):xh(v),y=e.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&une(C.delta,S)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var b=(i.current.shards||[]).map(zI).filter(Boolean).filter(function(C){return C.contains(v.target)}),P=b.length>0?a(v,b[0]):!i.current.noIsolation;P&&v.cancelable&&v.preventDefault()}}},[]),c=w.useCallback(function(m,v,S,y){var b={name:m,delta:v,target:S,should:y,shadowParent:fne(S)};e.current.push(b),setTimeout(function(){e.current=e.current.filter(function(P){return P!==b})},1)},[]),u=w.useCallback(function(m){n.current=xh(m),r.current=void 0},[]),h=w.useCallback(function(m){c(m.type,NI(m),m.target,a(m,t.lockRef.current))},[]),p=w.useCallback(function(m){c(m.type,xh(m),m.target,a(m,t.lockRef.current))},[]);w.useEffect(function(){return Oa.push(s),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,ja),document.addEventListener("touchmove",l,ja),document.addEventListener("touchstart",u,ja),function(){Oa=Oa.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,ja),document.removeEventListener("touchmove",l,ja),document.removeEventListener("touchstart",u,ja)}},[]);var f=t.removeScrollBar,g=t.inert;return w.createElement(w.Fragment,null,g?w.createElement(s,{styles:dne(o)}):null,f?w.createElement(nne,{gapMode:t.gapMode}):null)}function fne(t){for(var e=null;t!==null;)t instanceof ShadowRoot&&(e=t.host,t=t.host),t=t.parentNode;return e}const gne=Hte(zR,pne);var Xg=w.forwardRef(function(t,e){return w.createElement(Yg,xo({},t,{ref:e,sideCar:gne}))});Xg.classNames=Yg.classNames;var mne=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},Da=new WeakMap,wh=new WeakMap,bh={},nS=0,WR=function(t){return t&&(t.host||WR(t.parentNode))},yne=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=WR(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})},Sne=function(t,e,n,r){var o=yne(e,Array.isArray(t)?t:[t]);bh[n]||(bh[n]=new WeakMap);var s=bh[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=(Da.get(p)||0)+1,v=(s.get(p)||0)+1;Da.set(p,m),s.set(p,v),i.push(p),m===1&&g&&wh.set(p,!0),v===1&&p.setAttribute(n,"true"),g||p.setAttribute(r,"true")}catch(S){console.error("aria-hidden: cannot operate on ",p,S)}})};return u(e),a.clear(),nS++,function(){i.forEach(function(h){var p=Da.get(h)-1,f=s.get(h)-1;Da.set(h,p),s.set(h,f),p||(wh.has(h)||h.removeAttribute(r),wh.delete(h)),f||h.removeAttribute(n)}),nS--,nS||(Da=new WeakMap,Da=new WeakMap,wh=new WeakMap,bh={})}},k1=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),o=mne(t);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),Sne(r,o,n,"aria-hidden")):function(){return null}},T1="Dialog",[GR,Rfe]=xa(T1),[vne,co]=GR(T1),VR=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]=Ii({prop:r,defaultProp:o,onChange:s});return d.jsx(vne,{scope:e,triggerRef:a,contentRef:l,contentId:cs(),titleId:cs(),descriptionId:cs(),open:c,onOpenChange:u,onOpenToggle:w.useCallback(()=>u(h=>!h),[u]),modal:i,children:n})};VR.displayName=T1;var YR="DialogTrigger",xne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=co(YR,n),s=Qe(e,o.triggerRef);return d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":j1(o.open),...r,ref:s,onClick:oe(t.onClick,o.onOpenToggle)})});xne.displayName=YR;var M1="DialogPortal",[wne,XR]=GR(M1,{forceMount:void 0}),qR=t=>{const{__scopeDialog:e,forceMount:n,children:r,container:o}=t,s=co(M1,e);return d.jsx(wne,{scope:e,forceMount:n,children:w.Children.map(r,i=>d.jsx(lo,{present:n||s.open,children:d.jsx(vd,{asChild:!0,container:o,children:i})}))})};qR.displayName=M1;var Df="DialogOverlay",ZR=w.forwardRef((t,e)=>{const n=XR(Df,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=co(Df,t.__scopeDialog);return s.modal?d.jsx(lo,{present:r||s.open,children:d.jsx(bne,{...o,ref:e})}):null});ZR.displayName=Df;var bne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=co(Df,n);return d.jsx(Xg,{as:aa,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ae.div,{"data-state":j1(o.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),la="DialogContent",QR=w.forwardRef((t,e)=>{const n=XR(la,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=co(la,t.__scopeDialog);return d.jsx(lo,{present:r||s.open,children:s.modal?d.jsx(Pne,{...o,ref:e}):d.jsx(Cne,{...o,ref:e})})});QR.displayName=la;var Pne=w.forwardRef((t,e)=>{const n=co(la,t.__scopeDialog),r=w.useRef(null),o=Qe(e,n.contentRef,r);return w.useEffect(()=>{const s=r.current;if(s)return k1(s)},[]),d.jsx(JR,{...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())})}),Cne=w.forwardRef((t,e)=>{const n=co(la,t.__scopeDialog),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(JR,{...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()}})}),JR=w.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=t,a=co(la,n),l=w.useRef(null),c=Qe(e,l);return E1(),d.jsxs(d.Fragment,{children:[d.jsx(Vg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Sd,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":j1(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(Ine,{titleId:a.titleId}),d.jsx(kne,{contentRef:l,descriptionId:a.descriptionId})]})]})}),A1="DialogTitle",e3=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=co(A1,n);return d.jsx(Ae.h2,{id:o.titleId,...r,ref:e})});e3.displayName=A1;var t3="DialogDescription",_ne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=co(t3,n);return d.jsx(Ae.p,{id:o.descriptionId,...r,ref:e})});_ne.displayName=t3;var n3="DialogClose",r3=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=co(n3,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});r3.displayName=n3;function j1(t){return t?"open":"closed"}var o3="DialogTitleWarning",[Lfe,s3]=ote(o3,{contentName:la,titleName:A1,docsSlug:"dialog"}),Ine=({titleId:t})=>{const e=s3(o3),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
242
|
-
|
|
243
|
-
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
244
|
-
|
|
245
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return w.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},Ene="DialogDescriptionWarning",kne=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${s3(Ene).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},Tne=VR,Mne=qR,Ane=ZR,jne=QR;const i3=()=>{},a3=w.createContext(null);function One({onEvent:t,children:e}){return d.jsx(a3.Provider,{value:t??i3,children:e})}function Qt(){return w.useContext(a3)??i3}const l3=w.createContext(null);function Dne({context:t,children:e}){const n=Qt(),r=KM("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}),Wr.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}),Wr.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}),Wr.deleteOpenMenu(i.id,t)}),r.set([]))}}),[n,r,t]);return d.jsx(l3.Provider,{value:o,children:e})}function wa(){const t=w.useContext(l3);if(!t)throw new Error("useDialogs must be used within a DialogsProvider");return t}const Rne=({id:t,component:e,onClose:n})=>{const{removeDialog:r}=wa(),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(Tne,{onOpenChange:s,defaultOpen:!0,children:d.jsx(Mne,{container:o,children:d.jsx(Ane,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:d.jsx(jne,{dir:"ltr",className:"tlui-dialog__content",children:d.jsx(e,{onClose:()=>s(!1)})})})})})},Lne=w.memo(function(){const{dialogs:e}=wa();return H("dialogs",()=>e.get(),[e]).map(r=>d.jsx(Rne,{...r},r.id))});function O1(t,e=[]){let n=[];function r(s,i){const a=w.createContext(i),l=n.length;n=[...n,i];function c(h){const{scope:p,children:f,...g}=h,m=(p==null?void 0:p[t][l])||a,v=w.useMemo(()=>g,Object.values(g));return d.jsx(m.Provider,{value:v,children:f})}function u(h,p){const f=(p==null?void 0:p[t][l])||a,g=w.useContext(f);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return c.displayName=s+"Provider",[c,u]}const o=()=>{const s=n.map(i=>w.createContext(i));return function(a){const l=(a==null?void 0:a[t])||s;return w.useMemo(()=>({[`__scope${t}`]:{...a,[t]:l}}),[a,l])}};return o.scopeName=t,[r,$ne(o,...e)]}function $ne(...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 qg(t){const e=t+"CollectionProvider",[n,r]=O1(e),[o,s]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:g,children:m}=f,v=Te.useRef(null),S=Te.useRef(new Map).current;return d.jsx(o,{scope:g,itemMap:S,collectionRef:v,children:m})};i.displayName=e;const a=t+"CollectionSlot",l=Te.forwardRef((f,g)=>{const{scope:m,children:v}=f,S=s(a,m),y=Qe(g,S.collectionRef);return d.jsx(aa,{ref:y,children:v})});l.displayName=a;const c=t+"CollectionItemSlot",u="data-radix-collection-item",h=Te.forwardRef((f,g)=>{const{scope:m,children:v,...S}=f,y=Te.useRef(null),b=Qe(g,y),P=s(c,m);return Te.useEffect(()=>(P.itemMap.set(y,{ref:y,...S}),()=>void P.itemMap.delete(y))),d.jsx(aa,{[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 S=Array.from(v.querySelectorAll(`[${u}]`));return Array.from(g.itemMap.values()).sort((P,C)=>S.indexOf(P.ref.current)-S.indexOf(C.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},p,r]}var Fne="VisuallyHidden",D1=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}}));D1.displayName=Fne;var R1="ToastProvider",[L1,Nne,zne]=qg("Toast"),[c3,$fe]=xa("Toast",[zne]),[Bne,Zg]=c3(R1),u3=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 \`${R1}\`. Expected non-empty \`string\`.`),d.jsx(L1.Provider,{scope:e,children:d.jsx(Bne,{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})})};u3.displayName=R1;var d3="ToastViewport",Une=["F8"],A0="toast.viewportPause",j0="toast.viewportResume",h3=w.forwardRef((t,e)=>{const{__scopeToast:n,hotkey:r=Une,label:o="Notifications ({hotkey})",...s}=t,i=Zg(d3,n),a=Nne(n),l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),h=w.useRef(null),p=Qe(e,h,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=i.toastCount>0;w.useEffect(()=>{const v=S=>{var b;r.length!==0&&r.every(P=>S[P]||S.code===P)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r]),w.useEffect(()=>{const v=l.current,S=h.current;if(g&&v&&S){const y=()=>{if(!i.isClosePausedRef.current){const I=new CustomEvent(A0);S.dispatchEvent(I),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const I=new CustomEvent(j0);S.dispatchEvent(I),i.isClosePausedRef.current=!1}},P=I=>{!v.contains(I.relatedTarget)&&b()},C=()=>{v.contains(document.activeElement)||b()};return v.addEventListener("focusin",y),v.addEventListener("focusout",P),v.addEventListener("pointermove",y),v.addEventListener("pointerleave",C),window.addEventListener("blur",y),window.addEventListener("focus",b),()=>{v.removeEventListener("focusin",y),v.removeEventListener("focusout",P),v.removeEventListener("pointermove",y),v.removeEventListener("pointerleave",C),window.removeEventListener("blur",y),window.removeEventListener("focus",b)}}},[g,i.isClosePausedRef]);const m=w.useCallback(({tabbingDirection:v})=>{const y=a().map(b=>{const P=b.ref.current,C=[P,...tre(P)];return v==="forwards"?C:C.reverse()});return(v==="forwards"?y.reverse():y).flat()},[a]);return w.useEffect(()=>{const v=h.current;if(v){const S=y=>{var C,I,k;const b=y.altKey||y.ctrlKey||y.metaKey;if(y.key==="Tab"&&!b){const _=document.activeElement,T=y.shiftKey;if(y.target===v&&T){(C=c.current)==null||C.focus();return}const j=m({tabbingDirection:T?"backwards":"forwards"}),O=j.findIndex(R=>R===_);rS(j.slice(O+1))?y.preventDefault():T?(I=c.current)==null||I.focus():(k=u.current)==null||k.focus()}};return v.addEventListener("keydown",S),()=>v.removeEventListener("keydown",S)}},[a,m]),d.jsxs(bte,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&d.jsx(O0,{ref:c,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"forwards"});rS(v)}}),d.jsx(L1.Slot,{scope:n,children:d.jsx(Ae.ol,{tabIndex:-1,...s,ref:p})}),g&&d.jsx(O0,{ref:u,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"backwards"});rS(v)}})]})});h3.displayName=d3;var p3="ToastFocusProxy",O0=w.forwardRef((t,e)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=t,s=Zg(p3,n);return d.jsx(D1,{"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()}})});O0.displayName=p3;var Qg="Toast",Hne="toast.swipeStart",Kne="toast.swipeMove",Wne="toast.swipeCancel",Gne="toast.swipeEnd",f3=w.forwardRef((t,e)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=t,[a=!0,l]=Ii({prop:r,defaultProp:o,onChange:s});return d.jsx(lo,{present:n||a,children:d.jsx(Xne,{open:a,...i,ref:e,onClose:()=>l(!1),onPause:qt(t.onPause),onResume:qt(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)})})})});f3.displayName=Qg;var[Vne,Yne]=c3(Qg,{onClose(){}}),Xne=w.forwardRef((t,e)=>{const{__scopeToast:n,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:p,onSwipeEnd:f,...g}=t,m=Zg(Qg,n),[v,S]=w.useState(null),y=Qe(e,R=>S(R)),b=w.useRef(null),P=w.useRef(null),C=o||m.duration,I=w.useRef(0),k=w.useRef(C),_=w.useRef(0),{onToastAdd:T,onToastRemove:M}=m,D=qt(()=>{var B;(v==null?void 0:v.contains(document.activeElement))&&((B=m.viewport)==null||B.focus()),i()}),j=w.useCallback(R=>{!R||R===1/0||(window.clearTimeout(_.current),I.current=new Date().getTime(),_.current=window.setTimeout(D,R))},[D]);w.useEffect(()=>{const R=m.viewport;if(R){const B=()=>{j(k.current),c==null||c()},L=()=>{const G=new Date().getTime()-I.current;k.current=k.current-G,window.clearTimeout(_.current),l==null||l()};return R.addEventListener(A0,L),R.addEventListener(j0,B),()=>{R.removeEventListener(A0,L),R.removeEventListener(j0,B)}}},[m.viewport,C,l,c,j]),w.useEffect(()=>{s&&!m.isClosePausedRef.current&&j(C)},[s,C,m.isClosePausedRef,j]),w.useEffect(()=>(T(),()=>M()),[T,M]);const O=w.useMemo(()=>v?w3(v):null,[v]);return m.viewport?d.jsxs(d.Fragment,{children:[O&&d.jsx(qne,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:O}),d.jsx(Vne,{scope:n,onClose:D,children:li.createPortal(d.jsx(L1.ItemSlot,{scope:n,children:d.jsx(wte,{asChild:!0,onEscapeKeyDown:oe(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||D(),m.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(Ae.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":m.swipeDirection,...g,ref:y,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:oe(t.onKeyDown,R=>{R.key==="Escape"&&(a==null||a(R.nativeEvent),R.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,D()))}),onPointerDown:oe(t.onPointerDown,R=>{R.button===0&&(b.current={x:R.clientX,y:R.clientY})}),onPointerMove:oe(t.onPointerMove,R=>{if(!b.current)return;const B=R.clientX-b.current.x,L=R.clientY-b.current.y,G=!!P.current,$=["left","right"].includes(m.swipeDirection),U=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,Y=$?U(0,B):0,te=$?0:U(0,L),de=R.pointerType==="touch"?10:2,he={x:Y,y:te},ke={originalEvent:R,delta:he};G?(P.current=he,Ph(Kne,h,ke,{discrete:!1})):BI(he,m.swipeDirection,de)?(P.current=he,Ph(Hne,u,ke,{discrete:!1}),R.target.setPointerCapture(R.pointerId)):(Math.abs(B)>de||Math.abs(L)>de)&&(b.current=null)}),onPointerUp:oe(t.onPointerUp,R=>{const B=P.current,L=R.target;if(L.hasPointerCapture(R.pointerId)&&L.releasePointerCapture(R.pointerId),P.current=null,b.current=null,B){const G=R.currentTarget,$={originalEvent:R,delta:B};BI(B,m.swipeDirection,m.swipeThreshold)?Ph(Gne,f,$,{discrete:!0}):Ph(Wne,p,$,{discrete:!0}),G.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),qne=t=>{const{__scopeToast:e,children:n,...r}=t,o=Zg(Qg,e),[s,i]=w.useState(!1),[a,l]=w.useState(!1);return Jne(()=>i(!0)),w.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(vd,{asChild:!0,children:d.jsx(D1,{...r,children:s&&d.jsxs(d.Fragment,{children:[o.label," ",n]})})})},Zne="ToastTitle",g3=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});g3.displayName=Zne;var Qne="ToastDescription",m3=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});m3.displayName=Qne;var y3="ToastAction",S3=w.forwardRef((t,e)=>{const{altText:n,...r}=t;return n.trim()?d.jsx(x3,{altText:n,asChild:!0,children:d.jsx($1,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${y3}\`. Expected non-empty \`string\`.`),null)});S3.displayName=y3;var v3="ToastClose",$1=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t,o=Yne(v3,n);return d.jsx(x3,{asChild:!0,children:d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,o.onClose)})})});$1.displayName=v3;var x3=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 w3(t){const e=[];return Array.from(t.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),ere(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(...w3(r))}}),e}function Ph(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?I1(o,s):o.dispatchEvent(s)}var BI=(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 Jne(t=()=>{}){const e=qt(t);di(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[e])}function ere(t){return t.nodeType===t.ELEMENT_NODE}function tre(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 rS(t){const e=document.activeElement;return t.some(n=>n===e?!0:(n.focus(),document.activeElement!==e))}var nre=f3,rre=g3,ore=m3,sre=S3,UI=$1;const b3=w.createContext(null);function ire({children:t}){const e=KM("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(u3,{children:d.jsx(b3.Provider,{value:n,children:t})})}function $o(){const t=w.useContext(b3);if(!t)throw new Error("useToasts must be used within a ToastsProvider");return t}const P3=w.createContext(null);function are({assetUrls:t,children:e}){return w.useEffect(()=>{for(const n of Object.values(t.icons)){const r=Au();r.src=n,r.decode()}for(const n of Object.values(t.embedIcons)){const r=Au();r.src=n,r.decode()}},[t]),d.jsx(P3.Provider,{value:t,children:e})}function F1(){const t=w.useContext(P3);if(!t)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return t}const D0={"action.convert-to-bookmark":"Convert to Bookmark","action.convert-to-embed":"Convert to Embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","action.export-as-json.short":"JSON","action.export-as-json":"Export as JSON","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-json.short":"JSON","action.export-all-as-json":"Export as JSON","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.fork-project-on-tldraw":"Fork project on tldraw","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.paste-error-title":"Pasting failed","action.paste-error-description":"Could not paste due to missing clipboard permissions. Please enable the permissions and try again.","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-paste-at-cursor.menu":"Paste at cursor","action.toggle-paste-at-cursor":"Toggle paste at cursor","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.size-too-big":"File size is too big","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","theme.dark":"Dark","theme.light":"Light","theme.system":"System","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","fill-style.fill":"Fill","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","tool.pointer-down":"Pointer down","menu.title":"Menu","menu.theme":"Theme","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.help":"Help","menu.view":"View","context-menu.edit":"Edit","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy editor link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","document-name-menu.copy-link":"Copy link","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About tldraw","help-menu.docs":"Documentation & API","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","help-menu.terms":"Terms of service","help-menu.privacy":"Privacy policy","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},lre=new Set(["ar","fa","he","ur","ku"]),Ra={locale:"en",label:"English",messages:D0,dir:"ltr"};async function cre(t,e){if(!(await no(e.translations.en)).ok)return console.warn("No main translations found."),Ra;if(t==="en")return Ra;const r=Lu.find(a=>a.locale===t);if(!r)return console.warn(`No translation found for locale ${t}`),Ra;const s=await(await no(e.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${t}`),Ra;const i=[];for(const a in Ra.messages)s[a]||i.push(a);return i.length>0,{locale:t,label:r.label,dir:lre.has(r.locale)?"rtl":"ltr",messages:{...Ra.messages,...s}}}const C3=w.createContext(null);function _3(){const t=w.useContext(C3);if(!t)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return t}function ure({overrides:t,locale:e,children:n}){const r=F1(),[o,s]=w.useState(()=>t&&t.en?{locale:"en",label:"English",dir:"ltr",messages:{...D0,...t.en}}:{locale:"en",label:"English",dir:"ltr",messages:D0});return w.useEffect(()=>{let i=!1;async function a(){const l=await cre(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(C3.Provider,{value:o,children:n})}function Ce(){const t=_3();return w.useCallback(function(n){return t.messages[n]??n},[t])}const ce=w.forwardRef(function({children:e,disabled:n,type:r,...o},s){return d.jsx("button",{ref:s,type:"button",draggable:!1,disabled:n,...o,className:le("tlui-button",`tlui-button__${r}`,o.className),children:e})});function Pt({children:t}){return d.jsx("span",{className:"tlui-button__label",children:t})}const Ao=w.memo(function({small:e,invertIcon:n,icon:r,color:o,className:s,...i}){const a=F1(),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}})}),dre=4e3,hre={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function pre({toast:t}){const{removeToast:e}=$o(),n=Ce(),r=i=>{i||e(t.id)},o=t.actions&&t.actions.length>0,s=t.icon||t.severity&&hre[t.severity];return d.jsxs(nre,{onOpenChange:r,className:"tlui-toast__container",duration:t.keepOpen?1/0:dre,"data-severity":t.severity,children:[s&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(Ao,{icon:s})}),d.jsxs("div",{className:"tlui-toast__main",children:[d.jsxs("div",{className:"tlui-toast__content",children:[t.title&&d.jsx(rre,{className:"tlui-toast__title",children:t.title}),t.description&&d.jsx(ore,{className:"tlui-toast__description",children:t.description})]}),t.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[t.actions.map((i,a)=>d.jsx(sre,{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(UI,{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(UI,{asChild:!0,children:d.jsx(ce,{type:"normal",className:"tlui-toast__close",children:d.jsx(Pt,{children:t.closeLabel??n("toast.close")})})})]})}const fre=w.memo(function(){const{toasts:e}=$o(),n=H("toasts",()=>e.get(),[]);return d.jsxs(d.Fragment,{children:[n.map(r=>d.jsx(pre,{toast:r},r.id)),d.jsx(h3,{className:"tlui-toast__viewport"})]})});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=I3(t,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=t.getShapeUtil(s),l=ye(i.map(c=>t.getShape(c)));(o=a.onDragShapesOut)==null||o.call(a,s,l)}}function I3(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(_j(u,h))continue}else if(xZ(u,h))continue;a.push(l)}}return a}function Rf(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}),E3(t)}const gre=16;function E3(t){const e=t.getSelectionPageBounds(),n=t.getViewportPageBounds();if(e&&!n.contains(e)){const r=e.clone().expandBy(gre/t.getZoomLevel()).expand(n),o=n.clone().translate({x:(r.center.x-n.center.x)*2,y:(r.center.y-n.center.y)*2});t.zoomToBounds(o,{animation:{duration:t.options.animationMediumMs},inset:0})}}function mre(t,e){const n=ye(e.map(o=>t.getShape(o)).filter(o=>o&&t.isShapeOfType(o,"frame")));if(!n.length)return;const r=[];t.run(()=>{n.map(o=>{const s=t.getSortedChildIdsForParent(o.id);s.length&&(t.reparentShapes(s,o.parentId,o.index),r.push(...s))}),t.setSelectedShapes(r),t.deleteShapes(e)})}const yre=50;function Sre(t,e,n={}){const r=t.getShape(e);if(!r)return;const o=t.getSortedChildIdsForParent(r.id),s=ye(o.map(f=>t.getShape(f)));if(!s.length)return;const i=Z.FromPoints(s.flatMap(f=>{const g=t.getShapeGeometry(f.id);return t.getShapeLocalTransform(f).applyToPoints(g.vertices)})),{padding:a=yre}=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)})}function be({icon:t,small:e,invertIcon:n}){return d.jsx(Ao,{className:"tlui-button__icon",icon:t,small:e,invertIcon:n})}function Jg({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__header",t),children:e})}function em({className:t,children:e}){return d.jsx(e3,{dir:"ltr",className:le("tlui-dialog__header__title",t),children:e})}function tm(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(r3,{"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 Nu({className:t,children:e,style:n}){return d.jsx("div",{className:le("tlui-dialog__body",t),style:n,children:e})}function N1({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__footer",t),children:e})}const nm=w.forwardRef(function({className:e,label:n,icon:r,iconLeft:o,autoSelect:s=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:p,onBlur:f,shouldManuallyMaintainScrollPositionWhenFocused:g=!1,children:m,value:v},S){const y=n1(),b=w.useRef(null);w.useImperativeHandle(S,()=>b.current);const P=Ce(),C=w.useRef(a??""),I=w.useRef(a??""),[k,_]=w.useState(!1),T=w.useCallback(O=>{_(!0);const R=O.currentTarget;I.current=R.value,y?y.timers.requestAnimationFrame(()=>{s&&R.select()}):x0.requestAnimationFrame("anon",()=>{s&&R.select()}),p==null||p()},[s,y,p]),M=w.useCallback(O=>{const R=O.currentTarget.value;I.current=R,u==null||u(R)},[u]),D=w.useCallback(O=>{switch(O.key){case"Enter":{O.currentTarget.blur(),Et(O),c==null||c(O.currentTarget.value);break}case"Escape":{O.currentTarget.value=C.current,h==null||h(O.currentTarget.value),O.currentTarget.blur(),Et(O);break}}},[c,h]),j=w.useCallback(O=>{_(!1);const R=O.currentTarget.value;f==null||f(R)},[f]);return w.useEffect(()=>{if(!Ge.isIos)return;const O=window.visualViewport;if(k&&g&&O){const R=()=>{var B;(B=b.current)==null||B.scrollIntoView({block:"center"})};return O.addEventListener("resize",R),O.addEventListener("scroll",R),y?y.timers.requestAnimationFrame(()=>{var B;(B=b.current)==null||B.scrollIntoView({block:"center"})}):x0.requestAnimationFrame("anon",()=>{var B;(B=b.current)==null||B.scrollIntoView({block:"center"})}),()=>{O.removeEventListener("resize",R),O.removeEventListener("scroll",R)}}},[k,y,g]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,n&&d.jsx("label",{children:P(n)}),o&&d.jsx(Ao,{icon:o,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:le("tlui-input",e),type:"text",defaultValue:a,onKeyUp:D,onChange:M,onFocus:T,onBlur:j,autoFocus:i,placeholder:l,value:v}),r&&d.jsx(Ao,{icon:r,small:!!n})]})});function HI(t){return gr.isValid(t)?{isValid:!0,hasProtocol:!0}:gr.isValid("https://"+t)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const vre=$t(function({onClose:e}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(xre,{onClose:e,selectedShape:r}):null}),xre=$t(function({onClose:e,selectedShape:n}){const r=z(),o=Ce(),s=w.useRef(null);w.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var g;return(g=s.current)==null?void 0:g.focus()})},[r]);const i=w.useRef(n.props.url),[a,l]=w.useState(()=>{const g=HI(n.props.url),m=g.isValid===!0?g.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:m,safe:m,valid:!0}}),c=w.useCallback(g=>{const m=g.replace(/https?:\/\/(https?:\/\/)/,(y,b)=>b),v=HI(m),S=v.isValid===!0?v.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:S,valid:v.isValid})},[]),u=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(r.updateShapes([{id:g.id,type:g.type,props:{url:""}}]),e())},[r,e]),h=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(g&&"url"in g.props&&g.props.url!==a.safe&&r.updateShapes([{id:g.id,type:g.type,props:{url:a.safe}}]),e())},[r,e,a]),p=w.useCallback(()=>{e()},[e]);if(!n)return e(),null;const f=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(Jg,{children:[d.jsx(em,{children:o("edit-link-dialog.title")}),d.jsx(tm,{})]}),d.jsx(Nu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(nm,{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(N1,{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 wre={};const KI=/(^\/r\/[^/]+\/?$)/,z1=[{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(KI))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(KI))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=${wre.NEXT_PUBLIC_GC_API_KEY}¢er=${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","")}}],bre={"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},Pre=z1.map(t=>t.type);function Cre(t){return Pre.includes(t)}function _re(t){return"icon"in t}function k3(){return z().getShapeUtil("embed")}function B1(){const t=k3();return e=>t?t.getEmbedDefinition(e):void 0}function Ire(){const t=k3();return t?t.getEmbedDefinitions():[]}const T3=$t(function({onClose:e}){const n=z(),r=Ce(),o=F1(),[s,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[h,p]=w.useState(!1),f=w.useRef(-1),g=Ire(),m=B1();return d.jsxs(d.Fragment,{children:[d.jsxs(Jg,{children:[d.jsx(em,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),d.jsx(tm,{})]}),s?d.jsxs(d.Fragment,{children:[d.jsxs(Nu,{className:"tlui-embed-dialog__enter",children:[d.jsx(nm,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:v=>{l(v);const S=m(a);u(S&&S.definition.type===s.type?S:null),p(!1),clearTimeout(f.current),f.current=n.timers.setTimeout(()=>p(!S),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(Ao,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(N1,{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(Nu,{className:"tlui-embed-dialog__list",children:g.map(v=>{const S=Cre(v.type)?o.embedIcons[v.type]:_re(v)?v.icon:void 0;return d.jsxs(ce,{type:"menu",onClick:()=>i(v),children:[d.jsx(Pt,{children:v.title}),S&&d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${S})`}})]},v.type)})})})]})});var U1={exports:{}};U1.exports;(function(t){var e=function(){var n=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(l,c){if(!s[l]){s[l]={};for(var u=0;u<l.length;u++)s[l][l.charAt(u)]=u}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return n(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),h=0,p=c.length;h<p;h++){var f=c.charCodeAt(h);u[h*2]=f>>>8,u[h*2+1]=f%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var p=[];return c.forEach(function(f){p.push(n(f))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return o.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(o,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return n(c)})},_compress:function(l,c,u){if(l==null)return"";var h,p,f={},g={},m="",v="",S="",y=2,b=3,P=2,C=[],I=0,k=0,_;for(_=0;_<l.length;_+=1)if(m=l.charAt(_),Object.prototype.hasOwnProperty.call(f,m)||(f[m]=b++,g[m]=!0),v=S+m,Object.prototype.hasOwnProperty.call(f,v))S=v;else{if(Object.prototype.hasOwnProperty.call(g,S)){if(S.charCodeAt(0)<256){for(h=0;h<P;h++)I=I<<1,k==c-1?(k=0,C.push(u(I)),I=0):k++;for(p=S.charCodeAt(0),h=0;h<8;h++)I=I<<1|p&1,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=p>>1}else{for(p=1,h=0;h<P;h++)I=I<<1|p,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=0;for(p=S.charCodeAt(0),h=0;h<16;h++)I=I<<1|p&1,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=p>>1}y--,y==0&&(y=Math.pow(2,P),P++),delete g[S]}else for(p=f[S],h=0;h<P;h++)I=I<<1|p&1,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=p>>1;y--,y==0&&(y=Math.pow(2,P),P++),f[v]=b++,S=String(m)}if(S!==""){if(Object.prototype.hasOwnProperty.call(g,S)){if(S.charCodeAt(0)<256){for(h=0;h<P;h++)I=I<<1,k==c-1?(k=0,C.push(u(I)),I=0):k++;for(p=S.charCodeAt(0),h=0;h<8;h++)I=I<<1|p&1,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=p>>1}else{for(p=1,h=0;h<P;h++)I=I<<1|p,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=0;for(p=S.charCodeAt(0),h=0;h<16;h++)I=I<<1|p&1,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=p>>1}y--,y==0&&(y=Math.pow(2,P),P++),delete g[S]}else for(p=f[S],h=0;h<P;h++)I=I<<1|p&1,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=p>>1;y--,y==0&&(y=Math.pow(2,P),P++)}for(p=2,h=0;h<P;h++)I=I<<1|p&1,k==c-1?(k=0,C.push(u(I)),I=0):k++,p=p>>1;for(;;)if(I=I<<1,k==c-1){C.push(u(I));break}else k++;return C.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],p=4,f=4,g=3,m="",v=[],S,y,b,P,C,I,k,_={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)h[S]=S;for(b=0,C=Math.pow(2,2),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;switch(b){case 0:for(b=0,C=Math.pow(2,8),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;k=n(b);break;case 1:for(b=0,C=Math.pow(2,16),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;k=n(b);break;case 2:return""}for(h[3]=k,y=k,v.push(k);;){if(_.index>l)return"";for(b=0,C=Math.pow(2,g),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;switch(k=b){case 0:for(b=0,C=Math.pow(2,8),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;h[f++]=n(b),k=f-1,p--;break;case 1:for(b=0,C=Math.pow(2,16),I=1;I!=C;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*I,I<<=1;h[f++]=n(b),k=f-1,p--;break;case 2:return v.join("")}if(p==0&&(p=Math.pow(2,g),g++),h[k])m=h[k];else if(k===f)m=y+y.charAt(0);else return null;v.push(m),h[f++]=y+m.charAt(0),p--,y=m,p==0&&(p=Math.pow(2,g),g++)}}};return a}();t!=null?t.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})})(U1);var Ere=U1.exports;const M3=mi(Ere);async function kre(t,e,n){var S,y,b;const{elements:r,files:o}=e,s={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:t.store.schema.serialize()},i=new Map,a=new Map,l=t.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(P=>{if(c.set(P.id,Be()),P.boundElements!==null)for(const C of P.boundElements)C.type==="text"&&h.add(C.id)});let p=OT;for(const P of r){if(h.has(P.id))continue;const C=c.get(P.id),I={id:C,typeName:"shape",parentId:l,index:p,x:P.x,y:P.y,rotation:0,isLocked:P.locked,opacity:Tre(P.opacity),meta:{}};switch(P.angle!==0&&a.set(C,P.angle),P.groupIds&&P.groupIds.length>0?i.has(P.groupIds[0])?(S=i.get(P.groupIds[0]))==null||S.push(C):i.set(P.groupIds[0],[C]):u.push(C),P.type){case"rectangle":case"ellipse":case"diamond":{let k="",_="middle";if(P.boundElements!==null){for(const M of P.boundElements)if(M.type==="text"){const D=r.find(j=>j.id===M.id);D&&(k=D.text,_=Rre[D.textAlign])}}const T=P.backgroundColor==="transparent"?P.strokeColor:P.backgroundColor;s.shapes.push({...I,type:"geo",props:{geo:P.type,url:P.link??"",w:P.width,h:P.height,size:Ch[P.strokeWidth]??"draw",color:Ec[T]??"black",text:k,align:_,dash:_h(P),fill:Fre(P)}});break}case"freedraw":{s.shapes.push({...I,type:"draw",props:{dash:_h(P),size:Ch[P.strokeWidth],color:Ec[P.strokeColor]??"black",segments:[{type:"free",points:P.points.map(([k,_,T=.5])=>({x:k,y:_,z:T}))}]}});break}case"line":{if(P.points.slice().length<2)break;const _=Ou(P.points.length);s.shapes.push({...I,type:"line",props:{dash:_h(P),size:Ch[P.strokeWidth],color:Ec[P.strokeColor]??"black",spline:P.roundness?"cubic":"line",points:{...Object.fromEntries(P.points.map(([T,M],D)=>{const j=_[D];return[j,{id:j,index:j,x:T,y:M}]}))}}});break}case"arrow":{let k="";if(P.boundElements!==null){for(const j of P.boundElements)if(j.type==="text"){const O=r.find(R=>R.id===j.id);O&&(k=O.text)}}const _=P.points[0],T=P.points[P.points.length-1],M=c.get((y=P.startBinding)==null?void 0:y.elementId),D=c.get((b=P.endBinding)==null?void 0:b.elementId);s.shapes.push({...I,type:"arrow",props:{text:k,bend:$re(P,_,T),dash:_h(P),size:Ch[P.strokeWidth]??"m",color:Ec[P.strokeColor]??"black",start:{x:_[0],y:_[1]},end:{x:T[0],y:T[1]},arrowheadEnd:WI[P.endArrowhead]??"none",arrowheadStart:WI[P.startArrowhead]??"none"}}),M&&s.bindings.push({id:Yi(),typeName:"binding",type:"arrow",fromId:C,toId:M,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),D&&s.bindings.push({id:Yi(),typeName:"binding",type:"arrow",fromId:C,toId:D,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:k,scale:_}=Are(P.fontSize);s.shapes.push({...I,type:"text",props:{size:k,scale:_,font:jre[P.fontFamily]??"draw",color:Ec[P.strokeColor]??"black",text:P.text,textAlign:Lre[P.textAlign]}});break}case"image":{const k=o[P.fileId];if(!k)break;const _=zs.createId();s.assets.push({id:_,typeName:"asset",type:"image",props:{w:P.width,h:P.height,fileSize:k.size,name:P.id??"Untitled",isAnimated:!1,mimeType:k.mimeType,src:k.dataURL},meta:{}}),s.shapes.push({...I,type:"image",props:{w:P.width,h:P.height,assetId:_}})}}p=wo(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&&$n(C.parentId)&&u.push(C.parentId)}for(const[P,C]of a)t.select(P),t.rotateShapesBy([P],C);const g=ye(u.map(P=>t.getShape(P))),m=Z.Common(g.map(P=>t.getShapePageBounds(P))),v=t.getViewportPageBounds().center;t.updateShapes(g.map(P=>{const C={x:(P.x??0)-(m.x+m.w/2),y:(P.y??0)-(m.y+m.h/2)};return{id:P.id,type:P.type,x:v.x+C.x,y:v.y+C.y}})),t.setSelectedShapes(u)}const Tre=t=>{const e=t/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},Ch={1:"s",2:"m",3:"l",4:"xl"},Mre={16:"s",20:"m",28:"l",36:"xl"};function Are(t){const e=Mre[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 jre={1:"draw",2:"sans",3:"mono"},Ec={"#ffffff":"grey","#000000":"black","#343a40":"black","#495057":"grey","#c92a2a":"red","#a61e4d":"light-red","#862e9c":"violet","#5f3dc4":"light-violet","#364fc7":"blue","#1864ab":"light-blue","#0b7285":"light-green","#087f5b":"light-green","#2b8a3e":"green","#5c940d":"light-green","#e67700":"yellow","#d9480f":"orange","#ced4da":"grey","#868e96":"grey","#fa5252":"light-red","#e64980":"red","#be4bdb":"light-violet","#7950f2":"violet","#4c6ef5":"blue","#228be6":"light-blue","#15aabf":"light-green","#12b886":"green","#40c057":"green","#82c91e":"light-green","#fab005":"yellow","#fd7e14":"orange","#212529":"grey"},Ore={solid:"draw",dashed:"dashed",dotted:"dotted"},Dre={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Rre={left:"start",center:"middle",right:"end"},Lre={left:"start",center:"middle",right:"end"},WI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function $re(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 _h=t=>{let e=Ore[t.strokeStyle]??"draw";return e==="draw"&&t.roughness===0&&(e="solid"),e},Fre=t=>t.backgroundColor==="transparent"?"none":Dre[t.fillStyle]??"solid";async function Nre(t,e,n,r){const s=(await Promise.all(e.map(async i=>await(await no(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"files",files:s,point:n,ignoreParent:!1,sources:r}),e.forEach(i=>URL.revokeObjectURL(i))}function zre(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 R0(t,e,n,r){return t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"url",point:n,url:e,sources:r})}function Bre(t){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t.trim(),e.body.textContent||e.body.innerText||""}const Ure=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},Hre=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 QA(e)},Kre=t=>/^<svg/.test(t),Wre=["input","select","textarea"];function oS(t){const{activeElement:e}=document;return t.menus.hasAnyOpenMenus()||e&&(e.getAttribute("contenteditable")||Wre.indexOf(e.tagName.toLowerCase())>-1)}const Gre=t=>t.types.find(e=>e.match(/^image\//)),sS=(t,e,n,r)=>{const o=Hre(e);if(o)for(const s of o)R0(t,s,n);else Ure(e)?R0(t,e,n):Kre(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}))},Vre=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}}j3(t,r,n)},A3=async(t,e,n)=>{const r=[];for(const o of e){if(Gre(o))for(const s of o.types)s.match(/^image\//)&&r.push({type:"blob",source:o.getType(s)});o.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const s=await o.getType("text/html");return await os.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await os.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await os.blobToText(s)})()})}return await j3(t,r,n)};async function j3(t,e,n){const r=e.filter(s=>(s.type==="file"||s.type==="blob")&&s.source!==null);if(r.length){if(r.length>t.options.maxFilesAtOnce)throw Error("Too many files");const i=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await Nre(t,i,n)}const o=await Promise.all(e.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=M3.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"){zre(t,s.data,n);return}for(const s of o)if(s.type==="excalidraw"){kre(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");sS(t,c,n,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){sS(t,Bre(s.data),n,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){R0(t,s.data,n,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){sS(t,s.data,n,o);return}}const Lf=async t=>{var r;const e=await t.resolveAssetsInContent(t.getContentFromCurrentPage(t.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=M3.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(ZB);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 Yre(){const t=z(),e=Qt(),n=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Lf(t),e("copy",{source:i}))},[t,e]),r=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Lf(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?(A3(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 Xre(){const t=z(),e=Qt(),n=H("editor.isFocused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!n)return;const r=async l=>{t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||oS(t)||(xe(l),await Lf(t),e("copy",{source:"kbd"}))};async function o(l){t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||oS(t)||(xe(l),await Lf(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,t.timers.requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){Et(l);return}if(t.getEditingShapeId()!==null||oS(t))return;let c,u=!1;t.inputs.shiftKey&&(u=!0),t.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=t.inputs.currentPagePoint),l.clipboardData&&!t.inputs.shiftKey?Vre(t,l.clipboardData,c):navigator.clipboard.read().then(h=>{Array.isArray(h)&&h[0]instanceof ClipboardItem&&A3(t,h,c)}),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])}/*!
|
|
246
|
-
* canvas-size
|
|
247
|
-
* v1.2.6
|
|
248
|
-
* https://github.com/jhildenbiddle/canvas-size
|
|
249
|
-
* (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
|
|
250
|
-
* MIT license
|
|
251
|
-
*/function qre(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 GI(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?GI(Object(n),!0).forEach(function(r){Zre(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):GI(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Zre(t,e,n){return e=ioe(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Qre(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 Jre(t,e){if(t==null)return{};var n=Qre(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 VI(t,e){return toe(t)||qre(t,e)||O3(t,e)||ooe()}function Ih(t){return eoe(t)||noe(t)||O3(t)||roe()}function eoe(t){if(Array.isArray(t))return L0(t)}function toe(t){if(Array.isArray(t))return t}function noe(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function O3(t,e){if(t){if(typeof t=="string")return L0(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 L0(t,e)}}function L0(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 roe(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
252
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ooe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
253
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function soe(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 ioe(t){var e=soe(t,"string");return typeof e=="symbol"?e:String(e)}function lu(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&&lu(t)):h?t.onSuccess(n,r,p):(t.onError(n,r,p),t.sizes.length&&lu(t)),h}var iS={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]},aoe=["onError","onSuccess"],ol={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},kc={};function aS(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||ol.min,i=t.step||ol.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 Eh(t){var e=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),o=t.onError,s=t.onSuccess,i=Jre(t,aoe),a=null;if(!e)return!1;if(t.useWorker&&n){var l=`
|
|
254
|
-
var canvasTest = `.concat(lu.toString(),`;
|
|
255
|
-
onmessage = function(e) {
|
|
256
|
-
canvasTest(e.data);
|
|
257
|
-
};
|
|
258
|
-
`),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(h){var p=h.data,f=p.width,g=p.height,m=p.benchmark,v=p.isTestPass;v?(kc[r].onSuccess(f,g,m),delete kc[r]):kc[r].onError(f,g,m)}}if(t.usePromise)return new Promise(function(h,p){var f=rr(rr({},t),{},{onError:function(S,y,b){var P;if(t.sizes.length===0)P=!0;else{var C=t.sizes.slice(-1),I=VI(C,1),k=VI(I[0],2),_=k[0],T=k[1];P=S===_&&y===T}o(S,y,b),P&&p({width:S,height:y,benchmark:b})},onSuccess:function(S,y,b){s(S,y,b),h({width:S,height:y,benchmark:b})}});if(a){var g=f.onError,m=f.onSuccess;kc[r]={onError:g,onSuccess:m},a.postMessage(i)}else lu(f)});if(a)kc[r]={onError:o,onSuccess:s},a.postMessage(i);else return lu(t)}var lS={maxArea:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=aS({width:e.max,height:e.max,min:e.min,step:e.step,sizes:Ih(iS.area)}),r=rr(rr(rr({},ol),e),{},{sizes:n});return Eh(r)},maxHeight:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=aS({width:1,height:e.max,min:e.min,step:e.step,sizes:Ih(iS.height)}),r=rr(rr(rr({},ol),e),{},{sizes:n});return Eh(r)},maxWidth:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=aS({width:e.max,height:1,min:e.min,step:e.step,sizes:Ih(iS.width)}),r=rr(rr(rr({},ol),e),{},{sizes:n});return Eh(r)},test:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=rr(rr({},ol),e);return n.sizes=Ih(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),Eh(n)}};let cS=null;function loe(){return cS||(cS=coe()),cS}async function coe(){const t=await lS.maxWidth({usePromise:!0}),e=await lS.maxHeight({usePromise:!0}),n=await lS.maxArea({usePromise:!0});return{maxWidth:t.width,maxHeight:e.height,maxArea:n.width*n.height}}const YI=8192,uoe=4096*4096;async function doe(t,e){if(t<=YI&&e<=YI&&t*e<=uoe)return[t,e];const{maxWidth:n,maxHeight:r,maxArea:o}=await loe(),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 D3(t,e,n){const{type:r,quality:o,scale:s,width:i,height:a}=n;let[l,c]=await doe(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,h=await os.blobToDataUrl(new Blob([e],{type:"image/svg+xml"})),p=await new Promise(g=>{const m=Au();m.crossOrigin="anonymous",m.onload=async()=>{Ge.isSafari&&await Nv(250);const v=document.createElement("canvas"),S=v.getContext("2d");v.width=l,v.height=c,S.imageSmoothingEnabled=!0,S.imageSmoothingQuality="high",S.drawImage(m,0,0,l,c),URL.revokeObjectURL(h),g(v)},m.onerror=()=>{g(null)},m.src=h});if(!p)return null;const f=await new Promise(g=>p.toBlob(m=>{(!m||bt.throwToBlob.get())&&g(null),g(m)},"image/"+r,o));if(!f)return null;if(r==="png"){const g=new DataView(await f.arrayBuffer());return vo.setPhysChunk(g,u,{type:"image/"+r})}else return f}async function R3(t,e,n){const r=await t.getSvgString(e!=null&&e.length?e:[...t.getCurrentPageShapeIds()],{scale:1,background:t.getInstanceState().exportBackground,...n});if(!r)throw new Error("Could not construct SVG.");return r}async function $0(t,e,n,r={}){var o;switch(n){case"svg":return(o=await R3(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 L3({editor:t,ids:e,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await $0(t,e,"svg",r)],{type:"text/plain"});case"json":return new Blob([await $0(t,e,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await R3(t,e,r);if(!o)throw new Error("Could not construct image.");const s=await D3(t,o.svg,{type:n,quality:1,scale:2,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:Ot(n)}}const hoe={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function poe(t,e,n,r={}){return{blobPromise:L3({editor:t,ids:e,format:n,opts:r}),mimeType:hoe[n]}}function foe(t,e,n="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=poe(t,e,n,r);return o.catch(i=>{console.error(i)}),window.navigator.clipboard.write([new ClipboardItem({[s]:o})]).catch(i=>(console.error(i),o.then(a=>window.navigator.clipboard.write([new ClipboardItem({[s]:a})]))))}switch(n){case"json":case"svg":return goe(async()=>$0(t,e,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Ot(n)}}async function goe(t){var e,n;await((n=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:n.call(e,await t()))}function moe(){const t=z(),{addToast:e}=$o(),n=Ce();return w.useCallback((r,o="svg")=>{foe(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 yoe(t,e,n="png",r,o={}){if(!r&&(r=`shapes at ${XI()}`,e.length===1)){const a=t.getShape(e[0]);t.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${Xl(a.id)} at ${XI()}`}r+=`.${n}`;const s=await L3({editor:t,ids:e,format:n,opts:o}),i=new File([s],r,{type:s.type});Soe(i)}function XI(){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 Soe(t){const e=document.createElement("a"),n=URL.createObjectURL(t);e.href=n,e.download=t.name,e.click(),URL.revokeObjectURL(n)}function voe(){const t=z(),{addToast:e}=$o(),n=Ce();return w.useCallback((r,o="png",s)=>{yoe(t,r,o,s,{scale:1,background:t.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),e({id:"export-fail",title:n("toast.error.export-fail.title"),description:n("toast.error.export-fail.desc"),severity:"error"})})},[t,e,n])}async function xoe(t,e,n){const r=ye(e.map(a=>{const l=t.getShape(a);if(!(!l||t.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||t.isShapeOfType(a,"image"))return}const o=[];if(n!==void 0){const a=r.map(l=>({shape:l,bounds:t.getShapeMaskedPageBounds(l).clone().expandBy(n)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){o[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of o)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||o.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Z.Common(r.map(l=>t.getShapeMaskedPageBounds(l)));o.push({shapes:r,bounds:a})}const s=t.options.flattenImageBoundsPadding;for(const a of o){n!==void 0&&a.bounds.expandBy(-n);const l=await t.getSvgString(a.shapes,{padding:s});if(!(l!=null&&l.svg))continue;const c=new Blob([l.svg],{type:"image/svg+xml"}),u=await t.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});u&&(a.asset=u)}const i=[];return Eo(()=>{for(const a of o){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=t.findCommonAncestor(u)??t.getCurrentPageId();if(!h)continue;let p="a1";for(const S of u)if(S.parentId===h){S.index>p&&(p=S.index);break}let f,g,m;if($n(h)){const S=t.getShape(h);if(!S)continue;const y=t.getPointInShapeSpace(S,{x:c.x,y:c.y});m=t.getShapePageTransform(h).rotation(),y.sub(new x(s,s).rot(-m)),f=y.x,g=y.y}else f=c.x-s,g=c.y-s,m=0;t.deleteShapes(u),t.createAssets([{...l,id:l.id}]);const v=Be();t.createShape({id:v,type:"image",index:p,parentId:h,x:f,y:g,rotation:-m,props:{assetId:l.id,w:c.w+s*2,h:c.h+s*2}}),i.push(v)}}),i}const $3=Te.createContext([]);function F3(){const t=z(),e=w.useRef(),n=Us(Te.useContext($3));return w.useEffect(()=>{const r=window.document.createElement("input");r.type="file",r.accept=(n==null?void 0:n.join(","))??IB,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 rm(){return z().store.props.collaboration!==void 0}function woe(){const t=z();return H("sync status",()=>{var e;return(e=t.store.props.collaboration)!=null&&e.status?t.store.props.collaboration.status.get():null},[t])}function boe(){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=(S,y)=>{S&&(S.innerHTML=""),y&&document.head.contains(y)&&document.head.removeChild(y),S&&document.body.contains(S)&&document.body.removeChild(S)};i(e.current,n.current),e.current=o,n.current=s;const a=`tl-print-surface-${ze()}`;o.className=a,s.innerHTML=`
|
|
259
|
-
.${a} {
|
|
260
|
-
display: none;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
.${a} svg {
|
|
264
|
-
max-width: 100%;
|
|
265
|
-
height: 100%;
|
|
266
|
-
display: block;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
@media print {
|
|
270
|
-
html, body {
|
|
271
|
-
min-height: 100%;
|
|
272
|
-
height: 100%;
|
|
273
|
-
margin: 0;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
body {
|
|
277
|
-
position: relative;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
body > * {
|
|
281
|
-
display: none;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
.tldraw__editor {
|
|
285
|
-
display: none;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
.${a} {
|
|
289
|
-
display: block !important;
|
|
290
|
-
background: white;
|
|
291
|
-
min-height: 100%;
|
|
292
|
-
height: 100%;
|
|
293
|
-
max-width: 100%;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.${a}__item {
|
|
297
|
-
padding: 10mm;
|
|
298
|
-
display: flex;
|
|
299
|
-
min-height: 100%;
|
|
300
|
-
flex-direction: column;
|
|
301
|
-
page-break-after: always;
|
|
302
|
-
position: relative;
|
|
303
|
-
overflow: hidden;
|
|
304
|
-
height: 100%;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
.${a}__item__main {
|
|
308
|
-
flex: 1;
|
|
309
|
-
display: flex;
|
|
310
|
-
align-items: center;
|
|
311
|
-
justify-content: center;
|
|
312
|
-
max-height: 100%;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
.${a}__item__header {
|
|
316
|
-
display: none;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
.${a}__item__footer {
|
|
320
|
-
display: none;
|
|
321
|
-
text-align: right;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
.${a}__item__footer__hide {
|
|
325
|
-
display: none;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
`;const l=()=>{document.head.appendChild(s),document.body.appendChild(o)},c=()=>{t.once("tick",()=>{i(o,s)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(S,y,b){try{o.innerHTML+=`<div class="${a}__item">
|
|
332
|
-
<div class="${a}__item__header">
|
|
333
|
-
${S.replace(/</g,"<").replace(/>/g,">")}
|
|
334
|
-
</div>
|
|
335
|
-
<div class="${a}__item__main">
|
|
336
|
-
${b}
|
|
337
|
-
</div>
|
|
338
|
-
<div class="${a}__item__footer ${a}__item__footer__${y?"":"hide"}">
|
|
339
|
-
${y??""}
|
|
340
|
-
</div>
|
|
341
|
-
</div>`}catch(P){console.error(P)}}function h(){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 S=await t.getSvgString(p,v);if(S){const y=g.find(b=>b.id===f);u(`tldraw — ${y==null?void 0:y.name}`,null,S.svg),h()}}else{const S=t.getCurrentPage(),y=await t.getSvgString(t.getSortedChildIdsForParent(S.id),v);y&&(u(`tldraw — ${S.name}`,null,y.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[t])}const N3=w.createContext(null);function Poe(t){return Object.fromEntries(t.map(e=>[e.id,e]))}function La(t,e){if(t.getSelectedShapes().length===0)return t.getDocumentSettings().name||e}function Coe({overrides:t,children:e}){const n=z(),r=rm(),{addDialog:o,clearDialogs:s}=wa(),{clearToasts:i,addToast:a}=$o(),l=Ce(),c=F3(),u=boe(),{cut:h,copy:p,paste:f}=Yre(),g=moe(),m=voe(),v=l("document.default-name"),S=B1(),y=Qt(),b=w.useMemo(()=>{function P(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function C(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}const I=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(_){C()&&(P()||(y("edit-link",{source:_}),n.markHistoryStoppingPoint("edit-link"),o({component:vre})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(_){y("insert-embed",{source:_}),o({component:T3})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(_){y("insert-media",{source:_}),c()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(_){y("undo",{source:_}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(_){y("redo",{source:_}),n.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(_){let T=n.getSelectedShapeIds();T.length===0&&(T=Array.from(n.getCurrentPageShapeIds().values())),T.length!==0&&(y("export-as",{format:"svg",source:_}),m(T,"svg",La(n,v)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(_){let T=n.getSelectedShapeIds();T.length===0&&(T=Array.from(n.getCurrentPageShapeIds().values())),T.length!==0&&(y("export-as",{format:"png",source:_}),m(T,"png",La(n,v)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(_){let T=n.getSelectedShapeIds();T.length===0&&(T=Array.from(n.getCurrentPageShapeIds().values())),T.length!==0&&(y("export-as",{format:"json",source:_}),m(T,"json",La(n,v)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(_){let T=n.getSelectedShapeIds();T.length===0&&(T=Array.from(n.getCurrentPageShapeIds().values())),T.length!==0&&(y("export-all-as",{format:"svg",source:_}),m(Array.from(n.getCurrentPageShapeIds()),"svg",La(n,v)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(_){const T=Array.from(n.getCurrentPageShapeIds().values());T.length!==0&&(y("export-all-as",{format:"png",source:_}),m(T,"png",La(n,v)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(_){const T=Array.from(n.getCurrentPageShapeIds().values());T.length!==0&&(y("export-all-as",{format:"json",source:_}),m(T,"json",La(n,v)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(_){let T=n.getSelectedShapeIds();T.length===0&&(T=Array.from(n.getCurrentPageShapeIds().values())),T.length!==0&&(y("copy-as",{format:"svg",source:_}),g(T,"svg"))}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,onSelect(_){let T=n.getSelectedShapeIds();T.length===0&&(T=Array.from(n.getCurrentPageShapeIds().values())),T.length!==0&&(y("copy-as",{format:"png",source:_}),g(T,"png"))}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(_){let T=n.getSelectedShapeIds();T.length===0&&(T=Array.from(n.getCurrentPageShapeIds().values())),T.length!==0&&(y("copy-as",{format:"json",source:_}),g(T,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(_){if(!C()||P())return;y("toggle-auto-size",{source:_}),n.markHistoryStoppingPoint("toggling auto size");const T=n.getSelectedShapes().filter(M=>n.isShapeOfType(M,"text")&&M.props.autoSize===!1);n.updateShapes(T.map(M=>({id:M.id,type:M.type,props:{...M.props,w:8,autoSize:!0}}))),Ye(n,T.map(M=>M.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(_){y("open-embed-link",{source:_});const T=n.getSelectedShapeIds(),M="No embed shapes selected";if(T.length!==1){console.error(M);return}const D=n.getShape(T[0]);if(!D||!n.isShapeOfType(D,"embed")){console.error(M);return}nte(D.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(_){var T,M;if(((T=n.root.getCurrent())==null?void 0:T.id)!=="zoom"&&(y("zoom-tool",{source:_}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const D=n.root.getCurrent();D&&((M=D.getCurrent())==null?void 0:M.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:D.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(_){C()&&(P()||n.run(()=>{y("convert-to-bookmark",{source:_});const T=n.getSelectedShapes(),M=[],D=[];for(const j of T){if(!j||!n.isShapeOfType(j,"embed")||!j.props.url)continue;const O=new x(j.x,j.y);O.rot(-j.rotation),O.add(new x(j.props.w/2-300/2,j.props.h/2-320/2)),O.rot(j.rotation);const R={id:Be(),type:"bookmark",rotation:j.rotation,x:O.x,y:O.y,opacity:1,props:{url:j.props.url}};M.push(R),D.push(j.id)}n.markHistoryStoppingPoint("convert shapes to bookmark"),n.deleteShapes(D),n.createShapes(M)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(_){C()&&(P()||(y("convert-to-embed",{source:_}),n.run(()=>{const T=n.getSelectedShapeIds(),M=ye(T.map(O=>n.getShape(O))),D=[],j=[];for(const O of M){if(!n.isShapeOfType(O,"bookmark"))continue;const{url:R}=O.props,B=S(R);if(!B||!B.definition)continue;const{width:L,height:G}=B.definition,$=new x(O.x,O.y);$.rot(-O.rotation),$.add(new x(O.props.w/2-L/2,O.props.h/2-G/2)),$.rot(O.rotation);const U={id:Be(),type:"embed",x:$.x,y:$.y,rotation:O.rotation,props:{url:R,w:L,h:G}};D.push(U),j.push(O.id)}n.markHistoryStoppingPoint("convert shapes to embed"),n.deleteShapes(j),n.createShapes(D)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(_){if(!C()||P())return;y("duplicate-shapes",{source:_});const T=n.getInstanceState();let M,D;if(T.duplicateProps)M=T.duplicateProps.shapeIds,D=T.duplicateProps.offset;else{M=n.getSelectedShapeIds();const j=Z.Common(ye(M.map(O=>n.getShapePageBounds(O))));D=n.getCameraOptions().isLocked?{x:n.options.adjacentShapeMargin,y:n.options.adjacentShapeMargin}:{x:j.width+n.options.adjacentShapeMargin,y:0}}n.markHistoryStoppingPoint("duplicate shapes"),n.duplicateShapes(M,D),T.duplicateProps&&n.updateInstanceState({duplicateProps:{...T.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(_){C()&&(P()||(y("ungroup-shapes",{source:_}),n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(_){if(!C()||P())return;y("group-shapes",{source:_});const T=n.getOnlySelectedShape();T&&n.isShapeOfType(T,"group")?(n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())):(n.markHistoryStoppingPoint("group"),n.groupShapes(n.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(_){if(!C())return;y("remove-frame",{source:_});const T=n.getSelectedShapes();T.length>0&&T.every(M=>n.isShapeOfType(M,"frame"))&&(n.markHistoryStoppingPoint("remove-frame"),mre(n,T.map(M=>M.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(_){if(!C())return;y("fit-frame-to-content",{source:_});const T=n.getOnlySelectedShape();T&&n.isShapeOfType(T,"frame")&&(n.markHistoryStoppingPoint("fit-frame-to-content"),Sre(n,T.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"left",source:_}),n.markHistoryStoppingPoint("align left");const T=n.getSelectedShapeIds();n.alignShapes(T,"left"),Ye(n,T)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"center-horizontal",source:_}),n.markHistoryStoppingPoint("align center horizontal");const T=n.getSelectedShapeIds();n.alignShapes(T,"center-horizontal"),Ye(n,T)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"right",source:_}),n.markHistoryStoppingPoint("align right");const T=n.getSelectedShapeIds();n.alignShapes(T,"right"),Ye(n,T)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"center-vertical",source:_}),n.markHistoryStoppingPoint("align center vertical");const T=n.getSelectedShapeIds();n.alignShapes(T,"center-vertical"),Ye(n,T)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"top",source:_}),n.markHistoryStoppingPoint("align top");const T=n.getSelectedShapeIds();n.alignShapes(T,"top"),Ye(n,T)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(_){if(!C()||P())return;y("align-shapes",{operation:"bottom",source:_}),n.markHistoryStoppingPoint("align bottom");const T=n.getSelectedShapeIds();n.alignShapes(T,"bottom"),Ye(n,T)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(_){if(!C()||P())return;y("distribute-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("distribute horizontal");const T=n.getSelectedShapeIds();n.distributeShapes(T,"horizontal"),Ye(n,T)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(_){if(!C()||P())return;y("distribute-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("distribute vertical");const T=n.getSelectedShapeIds();n.distributeShapes(T,"vertical"),Ye(n,T)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(_){if(!C()||P())return;y("stretch-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("stretch horizontal");const T=n.getSelectedShapeIds();n.stretchShapes(T,"horizontal"),Ye(n,T)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(_){if(!C()||P())return;y("stretch-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("stretch vertical");const T=n.getSelectedShapeIds();n.stretchShapes(T,"vertical"),Ye(n,T)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(_){if(!C()||P())return;y("flip-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("flip horizontal");const T=n.getSelectedShapeIds();n.flipShapes(T,"horizontal"),Ye(n,T)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(_){if(!C()||P())return;y("flip-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("flip vertical");const T=n.getSelectedShapeIds();n.flipShapes(T,"vertical"),Ye(n,T)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(_){if(!C()||P())return;y("pack-shapes",{source:_}),n.markHistoryStoppingPoint("pack");const T=n.getSelectedShapeIds();n.packShapes(T,n.options.adjacentShapeMargin),Ye(n,T)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(_){if(!C()||P())return;y("stack-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("stack-vertical");const T=n.getSelectedShapeIds();n.stackShapes(T,"vertical",16),Ye(n,T)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(_){if(!C()||P())return;y("stack-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("stack-horizontal");const T=n.getSelectedShapeIds();n.stackShapes(T,"horizontal",16),Ye(n,T)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"toFront",source:_}),n.markHistoryStoppingPoint("bring to front"),n.bringToFront(n.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"forward",source:_}),n.markHistoryStoppingPoint("bring forward"),n.bringForward(n.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"backward",source:_}),n.markHistoryStoppingPoint("send backward"),n.sendBackward(n.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(_){C()&&(P()||(y("reorder-shapes",{operation:"toBack",source:_}),n.markHistoryStoppingPoint("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(_){C()&&(P()||(n.markHistoryStoppingPoint("cut"),h(_)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(_){C()&&(P()||p(_))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(_){var T;(T=navigator.clipboard)==null||T.read().then(M=>{f(M,_,_==="context-menu"?n.inputs.currentPagePoint:void 0)}).catch(()=>{a({title:l("action.paste-error-title"),description:l("action.paste-error-description"),severity:"error"})})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(_){n.run(()=>{P()||(y("select-all-shapes",{source:_}),n.markHistoryStoppingPoint("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(_){C()&&(P()||(y("select-none-shapes",{source:_}),n.markHistoryStoppingPoint("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(_){C()&&(P()||(y("delete-shapes",{source:_}),n.markHistoryStoppingPoint("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(_){if(!C()||P())return;y("rotate-cw",{source:_}),n.markHistoryStoppingPoint("rotate-cw");const T=n.getSelectionRotation()%(Ze/2),M=ri(T,0)||ri(T,Ze/2),D=n.getSelectedShapeIds();n.rotateShapesBy(D,Ze/2-(M?0:T)),Ye(n,D)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(_){if(!C()||P())return;y("rotate-ccw",{source:_}),n.markHistoryStoppingPoint("rotate-ccw");const T=n.getSelectionRotation()%(Ze/2),M=ri(T,0),D=n.getSelectedShapeIds();n.rotateShapesBy(D,M?-(Ze/2):-T),Ye(n,D)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(_){y("zoom-in",{source:_}),n.zoomIn(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(_){y("zoom-out",{source:_}),n.zoomOut(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(_){y("reset-zoom",{source:_}),n.resetZoom(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(_){y("zoom-to-fit",{source:_}),n.zoomToFit({animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(_){C()&&(P()||(y("zoom-to-selection",{source:_}),n.zoomToSelection({animation:{duration:n.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(_){y("toggle-snap-mode",{source:_}),n.user.updateUserPreferences({isSnapMode:!n.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(_){const T=n.user.getIsDarkMode()?"light":"dark";y("color-scheme",{source:_,value:T}),n.user.updateUserPreferences({colorScheme:T})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(_){y("toggle-wrap-mode",{source:_}),n.user.updateUserPreferences({isWrapMode:!n.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-dynamic-size-mode",label:{default:"action.toggle-dynamic-size-mode",menu:"action.toggle-dynamic-size-mode.menu"},readonlyOk:!1,onSelect(_){y("toggle-dynamic-size-mode",{source:_}),n.user.updateUserPreferences({isDynamicSizeMode:!n.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-paste-at-cursor",label:{default:"action.toggle-paste-at-cursor",menu:"action.toggle-paste-at-cursor.menu"},readonlyOk:!1,onSelect(_){y("toggle-paste-at-cursor",{source:_}),n.user.updateUserPreferences({isPasteAtCursorMode:!n.user.getIsPasteAtCursorMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(_){y("toggle-reduce-motion",{source:_}),n.user.updateUserPreferences({animationSpeed:n.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(_){y("toggle-edge-scrolling",{source:_}),n.user.updateUserPreferences({edgeScrollSpeed:n.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(_){y("toggle-transparent",{source:_}),n.updateInstanceState({exportBackground:!n.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(_){y("toggle-tool-lock",{source:_}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(_){y("unlock-all",{source:_});const T=[];for(const M of n.getCurrentPageShapes())M.isLocked&&T.push({id:M.id,type:M.type,isLocked:!1});T.length>0&&n.updateShapes(T)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(_){n.timers.requestAnimationFrame(()=>{n.run(()=>{y("toggle-focus-mode",{source:_}),s(),i(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(_){y("toggle-grid-mode",{source:_}),n.updateInstanceState({isGridMode:!n.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(_){y("toggle-debug-mode",{source:_}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(_){y("print",{source:_}),u()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(_){y("exit-pen-mode",{source:_}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(_){y("stop-following",{source:_}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(_){y("zoom-to-content",{source:_});const T=n.getSelectionPageBounds()??n.getCurrentPageBounds();T&&n.zoomToBounds(T,{targetZoom:Math.min(1,n.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(_){n.markHistoryStoppingPoint("locking"),y("toggle-lock",{source:_}),n.toggleLock(n.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(_){const T=yr.createId(),M=n.getSelectedShapeIds();n.run(()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.createPage({name:l("page-menu.new-page-initial-name"),id:T}),n.moveShapesToPage(M,T)}),y("move-to-new-page",{source:_})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(_){const T=mr;n.run(()=>{n.markHistoryStoppingPoint("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(T,"white"),n.setStyleForNextShapes(T,"white")}),y("set-style",{source:_,id:T.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(_){const T=sa;n.run(()=>{n.markHistoryStoppingPoint("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(T,"fill"),n.setStyleForNextShapes(T,"fill")}),y("set-style",{source:_,id:T.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async _=>{const T=n.getSelectedShapeIds();if(T.length===0)return;n.markHistoryStoppingPoint("flattening to image"),y("flatten-to-image",{source:_});const M=await xoe(n,T,n.options.flattenImageBoundsExpand);M!=null&&M.length&&n.setSelectedShapes(M)}}];r&&I.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(_){y("open-cursor-chat",{source:_}),!n.getInstanceState().isCoarsePointer&&n.timers.requestAnimationFrame(()=>{n.updateInstanceState({isChatting:!0})})}});const k=Poe(I);return t?t(n,k,void 0):k},[n,y,t,o,a,c,m,g,h,p,f,s,i,u,l,v,r,S]);return d.jsx(N3.Provider,{value:b,children:e})}function ba(){const t=w.useContext(N3);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function zu(t,e){return t?typeof t=="string"?t:e?t[e]??t.default:void 0:void 0}var _oe=w.createContext(void 0);function H1(t){const e=w.useContext(_oe);return t||e||"ltr"}const Ioe=["top","right","bottom","left"],hi=Math.min,ir=Math.max,$f=Math.round,kh=Math.floor,pi=t=>({x:t,y:t}),Eoe={left:"right",right:"left",bottom:"top",top:"bottom"},koe={start:"end",end:"start"};function F0(t,e,n){return ir(t,hi(e,n))}function ms(t,e){return typeof t=="function"?t(e):t}function ys(t){return t.split("-")[0]}function ec(t){return t.split("-")[1]}function K1(t){return t==="x"?"y":"x"}function W1(t){return t==="y"?"height":"width"}function fi(t){return["top","bottom"].includes(ys(t))?"y":"x"}function G1(t){return K1(fi(t))}function Toe(t,e,n){n===void 0&&(n=!1);const r=ec(t),o=G1(t),s=W1(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=Ff(i)),[i,Ff(i)]}function Moe(t){const e=Ff(t);return[N0(t),e,N0(e)]}function N0(t){return t.replace(/start|end/g,e=>koe[e])}function Aoe(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 joe(t,e,n,r){const o=ec(t);let s=Aoe(ys(t),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),e&&(s=s.concat(s.map(N0)))),s}function Ff(t){return t.replace(/left|right|bottom|top/g,e=>Eoe[e])}function Ooe(t){return{top:0,right:0,bottom:0,left:0,...t}}function z3(t){return typeof t!="number"?Ooe(t):{top:t,right:t,bottom:t,left:t}}function Nf(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 qI(t,e,n){let{reference:r,floating:o}=t;const s=fi(e),i=G1(e),a=W1(i),l=ys(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(ec(e)){case"start":f[i]-=p*(n&&c?-1:1);break;case"end":f[i]+=p*(n&&c?-1:1);break}return f}const Doe=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}=qI(c,r,l),p=r,f={},g=0;for(let m=0;m<a.length;m++){const{name:v,fn:S}=a[m],{x:y,y:b,data:P,reset:C}=await S({x:u,y:h,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:t,floating:e}});u=y??u,h=b??h,f={...f,[v]:{...f[v],...P}},C&&g<=50&&(g++,typeof C=="object"&&(C.placement&&(p=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:t,floating:e,strategy:o}):C.rects),{x:u,y:h}=qI(c,p,l)),m=-1)}return{x:u,y:h,placement:p,strategy:o,middlewareData:f}};async function Bu(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}=ms(e,t),g=z3(f),v=a[p?h==="floating"?"reference":"floating":h],S=Nf(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),y=h==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),P=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Nf(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:y,offsetParent:b,strategy:l}):y);return{top:(S.top-C.top+g.top)/P.y,bottom:(C.bottom-S.bottom+g.bottom)/P.y,left:(S.left-C.left+g.left)/P.x,right:(C.right-S.right+g.right)/P.x}}const Roe=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}=ms(t,e)||{};if(c==null)return{};const h=z3(u),p={x:n,y:r},f=G1(o),g=W1(f),m=await i.getDimensions(c),v=f==="y",S=v?"top":"left",y=v?"bottom":"right",b=v?"clientHeight":"clientWidth",P=s.reference[g]+s.reference[f]-p[f]-s.floating[g],C=p[f]-s.reference[f],I=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let k=I?I[b]:0;(!k||!await(i.isElement==null?void 0:i.isElement(I)))&&(k=a.floating[b]||s.floating[g]);const _=P/2-C/2,T=k/2-m[g]/2-1,M=hi(h[S],T),D=hi(h[y],T),j=M,O=k-m[g]-D,R=k/2-m[g]/2+_,B=F0(j,R,O),L=!l.arrow&&ec(o)!=null&&R!==B&&s.reference[g]/2-(R<j?M:D)-m[g]/2<0,G=L?R<j?R-j:R-O:0;return{[f]:p[f]+G,data:{[f]:B,centerOffset:R-B-G,...L&&{alignmentOffset:G}},reset:L}}}),Loe=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}=ms(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const S=ys(o),y=fi(a),b=ys(a)===a,P=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(b||!m?[Ff(a)]:Moe(a)),I=g!=="none";!p&&I&&C.push(...joe(a,m,g,P));const k=[a,...C],_=await Bu(e,v),T=[];let M=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&T.push(_[S]),h){const R=Toe(o,i,P);T.push(_[R[0]],_[R[1]])}if(M=[...M,{placement:o,overflows:T}],!T.every(R=>R<=0)){var D,j;const R=(((D=s.flip)==null?void 0:D.index)||0)+1,B=k[R];if(B)return{data:{index:R,overflows:M},reset:{placement:B}};let L=(j=M.filter(G=>G.overflows[0]<=0).sort((G,$)=>G.overflows[1]-$.overflows[1])[0])==null?void 0:j.placement;if(!L)switch(f){case"bestFit":{var O;const G=(O=M.filter($=>{if(I){const U=fi($.placement);return U===y||U==="y"}return!0}).map($=>[$.placement,$.overflows.filter(U=>U>0).reduce((U,Y)=>U+Y,0)]).sort(($,U)=>$[1]-U[1])[0])==null?void 0:O[0];G&&(L=G);break}case"initialPlacement":L=a;break}if(o!==L)return{reset:{placement:L}}}return{}}}};function ZI(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function QI(t){return Ioe.some(e=>t[e]>=0)}const $oe=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...o}=ms(t,e);switch(r){case"referenceHidden":{const s=await Bu(e,{...o,elementContext:"reference"}),i=ZI(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:QI(i)}}}case"escaped":{const s=await Bu(e,{...o,altBoundary:!0}),i=ZI(s,n.floating);return{data:{escapedOffsets:i,escaped:QI(i)}}}default:return{}}}}};async function Foe(t,e){const{placement:n,platform:r,elements:o}=t,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=ys(n),a=ec(n),l=fi(n)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,h=ms(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 Noe=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 Foe(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}}}}},zoe=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:o}=e,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x:S,y}=v;return{x:S,y}}},...l}=ms(t,e),c={x:n,y:r},u=await Bu(e,l),h=fi(ys(o)),p=K1(h);let f=c[p],g=c[h];if(s){const v=p==="y"?"top":"left",S=p==="y"?"bottom":"right",y=f+u[v],b=f-u[S];f=F0(y,f,b)}if(i){const v=h==="y"?"top":"left",S=h==="y"?"bottom":"right",y=g+u[v],b=g-u[S];g=F0(y,g,b)}const m=a.fn({...e,[p]:f,[h]:g});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[p]:s,[h]:i}}}}}},Boe=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}=ms(t,e),u={x:n,y:r},h=fi(o),p=K1(h);let f=u[p],g=u[h];const m=ms(a,e),v=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const b=p==="y"?"height":"width",P=s.reference[p]-s.floating[b]+v.mainAxis,C=s.reference[p]+s.reference[b]-v.mainAxis;f<P?f=P:f>C&&(f=C)}if(c){var S,y;const b=p==="y"?"width":"height",P=["top","left"].includes(ys(o)),C=s.reference[h]-s.floating[b]+(P&&((S=i.offset)==null?void 0:S[h])||0)+(P?0:v.crossAxis),I=s.reference[h]+s.reference[b]+(P?0:((y=i.offset)==null?void 0:y[h])||0)-(P?v.crossAxis:0);g<C?g=C:g>I&&(g=I)}return{[p]:f,[h]:g}}}},Uoe=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}=ms(t,e),u=await Bu(e,c),h=ys(o),p=ec(o),f=fi(o)==="y",{width:g,height:m}=s.floating;let v,S;h==="top"||h==="bottom"?(v=h,S=p===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(S=h,v=p==="end"?"top":"bottom");const y=m-u.top-u.bottom,b=g-u.left-u.right,P=hi(m-u[v],y),C=hi(g-u[S],b),I=!e.middlewareData.shift;let k=P,_=C;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(_=b),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(k=y),I&&!p){const M=ir(u.left,0),D=ir(u.right,0),j=ir(u.top,0),O=ir(u.bottom,0);f?_=g-2*(M!==0||D!==0?M+D:ir(u.left,u.right)):k=m-2*(j!==0||O!==0?j+O:ir(u.top,u.bottom))}await l({...e,availableWidth:_,availableHeight:k});const T=await i.getDimensions(a.floating);return g!==T.width||m!==T.height?{reset:{rects:!0}}:{}}}};function om(){return typeof window<"u"}function tc(t){return B3(t)?(t.nodeName||"").toLowerCase():"#document"}function pr(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Fo(t){var e;return(e=(B3(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function B3(t){return om()?t instanceof Node||t instanceof pr(t).Node:!1}function oo(t){return om()?t instanceof Element||t instanceof pr(t).Element:!1}function jo(t){return om()?t instanceof HTMLElement||t instanceof pr(t).HTMLElement:!1}function JI(t){return!om()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof pr(t).ShadowRoot}function xd(t){const{overflow:e,overflowX:n,overflowY:r,display:o}=so(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!["inline","contents"].includes(o)}function Hoe(t){return["table","td","th"].includes(tc(t))}function sm(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function V1(t){const e=Y1(),n=oo(t)?so(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 Koe(t){let e=gi(t);for(;jo(e)&&!Ml(e);){if(V1(e))return e;if(sm(e))return null;e=gi(e)}return null}function Y1(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Ml(t){return["html","body","#document"].includes(tc(t))}function so(t){return pr(t).getComputedStyle(t)}function im(t){return oo(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function gi(t){if(tc(t)==="html")return t;const e=t.assignedSlot||t.parentNode||JI(t)&&t.host||Fo(t);return JI(e)?e.host:e}function U3(t){const e=gi(t);return Ml(e)?t.ownerDocument?t.ownerDocument.body:t.body:jo(e)&&xd(e)?e:U3(e)}function Uu(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const o=U3(t),s=o===((r=t.ownerDocument)==null?void 0:r.body),i=pr(o);if(s){const a=z0(i);return e.concat(i,i.visualViewport||[],xd(o)?o:[],a&&n?Uu(a):[])}return e.concat(o,Uu(o,[],n))}function z0(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function H3(t){const e=so(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const o=jo(t),s=o?t.offsetWidth:n,i=o?t.offsetHeight:r,a=$f(n)!==s||$f(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function X1(t){return oo(t)?t:t.contextElement}function vl(t){const e=X1(t);if(!jo(e))return pi(1);const n=e.getBoundingClientRect(),{width:r,height:o,$:s}=H3(e);let i=(s?$f(n.width):n.width)/r,a=(s?$f(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Woe=pi(0);function K3(t){const e=pr(t);return!Y1()||!e.visualViewport?Woe:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Goe(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==pr(t)?!1:e}function ca(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=X1(t);let i=pi(1);e&&(r?oo(r)&&(i=vl(r)):i=vl(t));const a=Goe(s,n,r)?K3(s):pi(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&&oo(r)?pr(r):r;let g=p,m=z0(g);for(;m&&r&&f!==g;){const v=vl(m),S=m.getBoundingClientRect(),y=so(m),b=S.left+(m.clientLeft+parseFloat(y.paddingLeft))*v.x,P=S.top+(m.clientTop+parseFloat(y.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,h*=v.y,l+=b,c+=P,g=pr(m),m=z0(g)}}return Nf({width:u,height:h,x:l,y:c})}function Voe(t){let{elements:e,rect:n,offsetParent:r,strategy:o}=t;const s=o==="fixed",i=Fo(r),a=e?sm(e.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=pi(1);const u=pi(0),h=jo(r);if((h||!h&&!s)&&((tc(r)!=="body"||xd(i))&&(l=im(r)),jo(r))){const p=ca(r);c=vl(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x,y:n.y*c.y-l.scrollTop*c.y+u.y}}function Yoe(t){return Array.from(t.getClientRects())}function B0(t,e){const n=im(t).scrollLeft;return e?e.left+n:ca(Fo(t)).left+n}function Xoe(t){const e=Fo(t),n=im(t),r=t.ownerDocument.body,o=ir(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),s=ir(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+B0(t);const a=-n.scrollTop;return so(r).direction==="rtl"&&(i+=ir(e.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function qoe(t,e){const n=pr(t),r=Fo(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=Y1();(!c||c&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function Zoe(t,e){const n=ca(t,!0,e==="fixed"),r=n.top+t.clientTop,o=n.left+t.clientLeft,s=jo(t)?vl(t):pi(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 eE(t,e,n){let r;if(e==="viewport")r=qoe(t,n);else if(e==="document")r=Xoe(Fo(t));else if(oo(e))r=Zoe(e,n);else{const o=K3(t);r={...e,x:e.x-o.x,y:e.y-o.y}}return Nf(r)}function W3(t,e){const n=gi(t);return n===e||!oo(n)||Ml(n)?!1:so(n).position==="fixed"||W3(n,e)}function Qoe(t,e){const n=e.get(t);if(n)return n;let r=Uu(t,[],!1).filter(a=>oo(a)&&tc(a)!=="body"),o=null;const s=so(t).position==="fixed";let i=s?gi(t):t;for(;oo(i)&&!Ml(i);){const a=so(i),l=V1(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||xd(i)&&!l&&W3(t,i))?r=r.filter(u=>u!==i):o=a,i=gi(i)}return e.set(t,r),r}function Joe(t){let{element:e,boundary:n,rootBoundary:r,strategy:o}=t;const i=[...n==="clippingAncestors"?sm(e)?[]:Qoe(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=eE(e,u,o);return c.top=ir(h.top,c.top),c.right=hi(h.right,c.right),c.bottom=hi(h.bottom,c.bottom),c.left=ir(h.left,c.left),c},eE(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function ese(t){const{width:e,height:n}=H3(t);return{width:e,height:n}}function tse(t,e,n){const r=jo(e),o=Fo(e),s=n==="fixed",i=ca(t,!0,s,e);let a={scrollLeft:0,scrollTop:0};const l=pi(0);if(r||!r&&!s)if((tc(e)!=="body"||xd(o))&&(a=im(e)),r){const f=ca(e,!0,s,e);l.x=f.x+e.clientLeft,l.y=f.y+e.clientTop}else o&&(l.x=B0(o));let c=0,u=0;if(o&&!r&&!s){const f=o.getBoundingClientRect();u=f.top+a.scrollTop,c=f.left+a.scrollLeft-B0(o,f)}const h=i.left+a.scrollLeft-l.x-c,p=i.top+a.scrollTop-l.y-u;return{x:h,y:p,width:i.width,height:i.height}}function uS(t){return so(t).position==="static"}function tE(t,e){if(!jo(t)||so(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Fo(t)===n&&(n=n.ownerDocument.body),n}function G3(t,e){const n=pr(t);if(sm(t))return n;if(!jo(t)){let o=gi(t);for(;o&&!Ml(o);){if(oo(o)&&!uS(o))return o;o=gi(o)}return n}let r=tE(t,e);for(;r&&Hoe(r)&&uS(r);)r=tE(r,e);return r&&Ml(r)&&uS(r)&&!V1(r)?n:r||Koe(t)||n}const nse=async function(t){const e=this.getOffsetParent||G3,n=this.getDimensions,r=await n(t.floating);return{reference:tse(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function rse(t){return so(t).direction==="rtl"}const ose={convertOffsetParentRelativeRectToViewportRelativeRect:Voe,getDocumentElement:Fo,getClippingRect:Joe,getOffsetParent:G3,getElementRects:nse,getClientRects:Yoe,getDimensions:ese,getScale:vl,isElement:oo,isRTL:rse};function sse(t,e){let n=null,r;const o=Fo(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=kh(u),g=kh(o.clientWidth-(c+h)),m=kh(o.clientHeight-(u+p)),v=kh(c),y={rootMargin:-f+"px "+-g+"px "+-m+"px "+-v+"px",threshold:ir(0,hi(1,l))||1};let b=!0;function P(C){const I=C[0].intersectionRatio;if(I!==l){if(!b)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}b=!1}try{n=new IntersectionObserver(P,{...y,root:o.ownerDocument})}catch{n=new IntersectionObserver(P,y)}n.observe(t)}return i(!0),s}function ise(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=X1(t),u=o||s?[...c?Uu(c):[],...Uu(e)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",n,{passive:!0}),s&&S.addEventListener("resize",n)});const h=c&&a?sse(c,n):null;let p=-1,f=null;i&&(f=new ResizeObserver(S=>{let[y]=S;y&&y.target===c&&f&&(f.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=f)==null||b.observe(e)})),n()}),c&&!l&&f.observe(c),f.observe(e));let g,m=l?ca(t):null;l&&v();function v(){const S=ca(t);m&&(S.x!==m.x||S.y!==m.y||S.width!==m.width||S.height!==m.height)&&n(),m=S,g=requestAnimationFrame(v)}return n(),()=>{var S;u.forEach(y=>{o&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),h==null||h(),(S=f)==null||S.disconnect(),f=null,l&&cancelAnimationFrame(g)}}const ase=Noe,lse=zoe,cse=Loe,use=Uoe,dse=$oe,nE=Roe,hse=Boe,pse=(t,e,n)=>{const r=new Map,o={platform:ose,...n},s={...o.platform,_c:r};return Doe(t,e,{...o,platform:s})};var up=typeof document<"u"?w.useLayoutEffect:w.useEffect;function zf(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(!zf(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)&&!zf(t[s],e[s]))return!1}return!0}return t!==t&&e!==e}function V3(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function rE(t,e){const n=V3(t);return Math.round(e*n)/n}function dS(t){const e=w.useRef(t);return up(()=>{e.current=t}),e}function fse(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);zf(p,r)||f(r);const[g,m]=w.useState(null),[v,S]=w.useState(null),y=w.useCallback($=>{$!==I.current&&(I.current=$,m($))},[]),b=w.useCallback($=>{$!==k.current&&(k.current=$,S($))},[]),P=s||g,C=i||v,I=w.useRef(null),k=w.useRef(null),_=w.useRef(u),T=l!=null,M=dS(l),D=dS(o),j=dS(c),O=w.useCallback(()=>{if(!I.current||!k.current)return;const $={placement:e,strategy:n,middleware:p};D.current&&($.platform=D.current),pse(I.current,k.current,$).then(U=>{const Y={...U,isPositioned:j.current!==!1};R.current&&!zf(_.current,Y)&&(_.current=Y,li.flushSync(()=>{h(Y)}))})},[p,e,n,D,j]);up(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,h($=>({...$,isPositioned:!1})))},[c]);const R=w.useRef(!1);up(()=>(R.current=!0,()=>{R.current=!1}),[]),up(()=>{if(P&&(I.current=P),C&&(k.current=C),P&&C){if(M.current)return M.current(P,C,O);O()}},[P,C,O,M,T]);const B=w.useMemo(()=>({reference:I,floating:k,setReference:y,setFloating:b}),[y,b]),L=w.useMemo(()=>({reference:P,floating:C}),[P,C]),G=w.useMemo(()=>{const $={position:n,left:0,top:0};if(!L.floating)return $;const U=rE(L.floating,u.x),Y=rE(L.floating,u.y);return a?{...$,transform:"translate("+U+"px, "+Y+"px)",...V3(L.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:Y}},[n,a,L.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:O,refs:B,elements:L,floatingStyles:G}),[u,O,B,L,G])}const gse=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?nE({element:r.current,padding:o}).fn(n):{}:r?nE({element:r,padding:o}).fn(n):{}}}},mse=(t,e)=>({...ase(t),options:[t,e]}),yse=(t,e)=>({...lse(t),options:[t,e]}),Sse=(t,e)=>({...hse(t),options:[t,e]}),vse=(t,e)=>({...cse(t),options:[t,e]}),xse=(t,e)=>({...use(t),options:[t,e]}),wse=(t,e)=>({...dse(t),options:[t,e]}),bse=(t,e)=>({...gse(t),options:[t,e]});var Pse="Arrow",Y3=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"})})});Y3.displayName=Pse;var Cse=Y3;function X3(t){const[e,n]=w.useState(void 0);return di(()=>{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 q1="Popper",[q3,am]=O1(q1),[_se,Z3]=q3(q1),Q3=t=>{const{__scopePopper:e,children:n}=t,[r,o]=w.useState(null);return d.jsx(_se,{scope:e,anchor:r,onAnchorChange:o,children:n})};Q3.displayName=q1;var J3="PopperAnchor",eL=w.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...o}=t,s=Z3(J3,n),i=w.useRef(null),a=Qe(e,i);return w.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(Ae.div,{...o,ref:a})});eL.displayName=J3;var Z1="PopperContent",[Ise,Ese]=q3(Z1),tL=w.forwardRef((t,e)=>{var Fe,st,$e,lt,He,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=Z3(Z1,n),[S,y]=w.useState(null),b=Qe(e,Ft=>y(Ft)),[P,C]=w.useState(null),I=X3(P),k=(I==null?void 0:I.width)??0,_=(I==null?void 0:I.height)??0,T=r+(s!=="center"?"-"+s:""),M=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(c)?c:[c],j=D.length>0,O={padding:M,boundary:D.filter(Tse),altBoundary:j},{refs:R,floatingStyles:B,placement:L,isPositioned:G,middlewareData:$}=fse({strategy:"fixed",placement:T,whileElementsMounted:(...Ft)=>ise(...Ft,{animationFrame:f==="always"}),elements:{reference:v.anchor},middleware:[mse({mainAxis:o+_,alignmentAxis:i}),l&&yse({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Sse():void 0,...O}),l&&vse({...O}),xse({...O,apply:({elements:Ft,rects:jn,availableWidth:vt,availableHeight:Jt})=>{const{width:zo,height:rc}=jn.reference,Is=Ft.floating.style;Is.setProperty("--radix-popper-available-width",`${vt}px`),Is.setProperty("--radix-popper-available-height",`${Jt}px`),Is.setProperty("--radix-popper-anchor-width",`${zo}px`),Is.setProperty("--radix-popper-anchor-height",`${rc}px`)}}),P&&bse({element:P,padding:a}),Mse({arrowWidth:k,arrowHeight:_}),p&&wse({strategy:"referenceHidden",...O})]}),[U,Y]=oL(L),te=qt(g);di(()=>{G&&(te==null||te())},[G,te]);const de=(Fe=$.arrow)==null?void 0:Fe.x,he=(st=$.arrow)==null?void 0:st.y,ke=(($e=$.arrow)==null?void 0:$e.centerOffset)!==0,[se,We]=w.useState();return di(()=>{S&&We(window.getComputedStyle(S).zIndex)},[S]),d.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...B,transform:G?B.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:se,"--radix-popper-transform-origin":[(lt=$.transformOrigin)==null?void 0:lt.x,(He=$.transformOrigin)==null?void 0:He.y].join(" "),...((er=$.hide)==null?void 0:er.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(Ise,{scope:n,placedSide:U,onArrowChange:C,arrowX:de,arrowY:he,shouldHideArrow:ke,children:d.jsx(Ae.div,{"data-side":U,"data-align":Y,...m,ref:b,style:{...m.style,animation:G?void 0:"none"}})})})});tL.displayName=Z1;var nL="PopperArrow",kse={top:"bottom",right:"left",bottom:"top",left:"right"},rL=w.forwardRef(function(e,n){const{__scopePopper:r,...o}=e,s=Ese(nL,r),i=kse[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(Cse,{...o,ref:n,style:{...o.style,display:"block"}})})});rL.displayName=nL;function Tse(t){return t!==null}var Mse=t=>({name:"transformOrigin",options:t,fn(e){var v,S,y;const{placement:n,rects:r,middlewareData:o}=e,i=((v=o.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:t.arrowWidth,l=i?0:t.arrowHeight,[c,u]=oL(n),h={start:"0%",center:"50%",end:"100%"}[u],p=(((S=o.arrow)==null?void 0:S.x)??0)+a/2,f=(((y=o.arrow)==null?void 0:y.y)??0)+l/2;let g="",m="";return c==="bottom"?(g=i?h:`${p}px`,m=`${-l}px`):c==="top"?(g=i?h:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,m=i?h:`${f}px`):c==="left"&&(g=`${r.floating.width+l}px`,m=i?h:`${f}px`),{data:{x:g,y:m}}}});function oL(t){const[e,n="center"]=t.split("-");return[e,n]}var Q1=Q3,J1=eL,sL=tL,iL=rL,hS="rovingFocusGroup.onEntryFocus",Ase={bubbles:!1,cancelable:!0},lm="RovingFocusGroup",[U0,aL,jse]=qg(lm),[Ose,lL]=O1(lm,[jse]),[Dse,Rse]=Ose(lm),cL=w.forwardRef((t,e)=>d.jsx(U0.Provider,{scope:t.__scopeRovingFocusGroup,children:d.jsx(U0.Slot,{scope:t.__scopeRovingFocusGroup,children:d.jsx(Lse,{...t,ref:e})})}));cL.displayName=lm;var Lse=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=Qe(e,p),g=H1(s),[m=null,v]=Ii({prop:i,defaultProp:a,onChange:l}),[S,y]=w.useState(!1),b=qt(c),P=aL(n),C=w.useRef(!1),[I,k]=w.useState(0);return w.useEffect(()=>{const _=p.current;if(_)return _.addEventListener(hS,b),()=>_.removeEventListener(hS,b)},[b]),d.jsx(Dse,{scope:n,orientation:r,dir:g,loop:o,currentTabStopId:m,onItemFocus:w.useCallback(_=>v(_),[v]),onItemShiftTab:w.useCallback(()=>y(!0),[]),onFocusableItemAdd:w.useCallback(()=>k(_=>_+1),[]),onFocusableItemRemove:w.useCallback(()=>k(_=>_-1),[]),children:d.jsx(Ae.div,{tabIndex:S||I===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...t.style},onMouseDown:oe(t.onMouseDown,()=>{C.current=!0}),onFocus:oe(t.onFocus,_=>{const T=!C.current;if(_.target===_.currentTarget&&T&&!S){const M=new CustomEvent(hS,Ase);if(_.currentTarget.dispatchEvent(M),!M.defaultPrevented){const D=P().filter(L=>L.focusable),j=D.find(L=>L.active),O=D.find(L=>L.id===m),B=[j,O,...D].filter(Boolean).map(L=>L.ref.current);hL(B,u)}}C.current=!1}),onBlur:oe(t.onBlur,()=>y(!1))})})}),uL="RovingFocusGroupItem",dL=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,...i}=t,a=cs(),l=s||a,c=Rse(uL,n),u=c.currentTabStopId===l,h=aL(n),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return w.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),d.jsx(U0.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=Nse(g,c.orientation,c.dir);if(m!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(y=>y.focusable).map(y=>y.ref.current);if(m==="last")S.reverse();else if(m==="prev"||m==="next"){m==="prev"&&S.reverse();const y=S.indexOf(g.currentTarget);S=c.loop?zse(S,y+1):S.slice(y+1)}setTimeout(()=>hL(S))}})})})});dL.displayName=uL;var $se={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Fse(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function Nse(t,e,n){const r=Fse(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return $se[r]}function hL(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function zse(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var Bse=cL,Use=dL,H0=["Enter"," "],Hse=["ArrowDown","PageUp","Home"],pL=["ArrowUp","PageDown","End"],Kse=[...Hse,...pL],Wse={ltr:[...H0,"ArrowRight"],rtl:[...H0,"ArrowLeft"]},Gse={ltr:["ArrowLeft"],rtl:["ArrowRight"]},wd="Menu",[Hu,Vse,Yse]=qg(wd),[Pa,cm]=xa(wd,[Yse,am,lL]),bd=am(),fL=lL(),[gL,Ei]=Pa(wd),[Xse,Pd]=Pa(wd),mL=t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=t,a=bd(e),[l,c]=w.useState(null),u=w.useRef(!1),h=qt(s),p=H1(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(Q1,{...a,children:d.jsx(gL,{scope:e,open:n,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(Xse,{scope:e,onClose:w.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};mL.displayName=wd;var qse="MenuAnchor",eb=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=bd(n);return d.jsx(J1,{...o,...r,ref:e})});eb.displayName=qse;var tb="MenuPortal",[Zse,yL]=Pa(tb,{forceMount:void 0}),SL=t=>{const{__scopeMenu:e,forceMount:n,children:r,container:o}=t,s=Ei(tb,e);return d.jsx(Zse,{scope:e,forceMount:n,children:d.jsx(lo,{present:n||s.open,children:d.jsx(vd,{asChild:!0,container:o,children:r})})})};SL.displayName=tb;var Or="MenuContent",[Qse,nb]=Pa(Or),vL=w.forwardRef((t,e)=>{const n=yL(Or,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=Ei(Or,t.__scopeMenu),i=Pd(Or,t.__scopeMenu);return d.jsx(Hu.Provider,{scope:t.__scopeMenu,children:d.jsx(lo,{present:r||s.open,children:d.jsx(Hu.Slot,{scope:t.__scopeMenu,children:i.modal?d.jsx(Jse,{...o,ref:e}):d.jsx(eie,{...o,ref:e})})})})}),Jse=w.forwardRef((t,e)=>{const n=Ei(Or,t.__scopeMenu),r=w.useRef(null),o=Qe(e,r);return w.useEffect(()=>{const s=r.current;if(s)return k1(s)},[]),d.jsx(rb,{...t,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:oe(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),eie=w.forwardRef((t,e)=>{const n=Ei(Or,t.__scopeMenu);return d.jsx(rb,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),rb=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=Ei(Or,n),S=Pd(Or,n),y=bd(n),b=fL(n),P=Vse(n),[C,I]=w.useState(null),k=w.useRef(null),_=Qe(e,k,v.onContentChange),T=w.useRef(0),M=w.useRef(""),D=w.useRef(0),j=w.useRef(null),O=w.useRef("right"),R=w.useRef(0),B=g?Xg:w.Fragment,L=g?{as:aa,allowPinchZoom:!0}:void 0,G=U=>{var Fe,st;const Y=M.current+U,te=P().filter($e=>!$e.disabled),de=document.activeElement,he=(Fe=te.find($e=>$e.ref.current===de))==null?void 0:Fe.textValue,ke=te.map($e=>$e.textValue),se=hie(ke,Y,he),We=(st=te.find($e=>$e.textValue===se))==null?void 0:st.ref.current;(function $e(lt){M.current=lt,window.clearTimeout(T.current),lt!==""&&(T.current=window.setTimeout(()=>$e(""),1e3))})(Y),We&&setTimeout(()=>We.focus())};w.useEffect(()=>()=>window.clearTimeout(T.current),[]),E1();const $=w.useCallback(U=>{var te,de;return O.current===((te=j.current)==null?void 0:te.side)&&fie(U,(de=j.current)==null?void 0:de.area)},[]);return d.jsx(Qse,{scope:n,searchRef:M,onItemEnter:w.useCallback(U=>{$(U)&&U.preventDefault()},[$]),onItemLeave:w.useCallback(U=>{var Y;$(U)||((Y=k.current)==null||Y.focus(),I(null))},[$]),onTriggerLeave:w.useCallback(U=>{$(U)&&U.preventDefault()},[$]),pointerGraceTimerRef:D,onPointerGraceIntentChange:w.useCallback(U=>{j.current=U},[]),children:d.jsx(B,{...L,children:d.jsx(Vg,{asChild:!0,trapped:o,onMountAutoFocus:oe(s,U=>{var Y;U.preventDefault(),(Y=k.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(Sd,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:d.jsx(Bse,{asChild:!0,...b,dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:I,onEntryFocus:oe(l,U=>{S.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(sL,{role:"menu","aria-orientation":"vertical","data-state":LL(v.open),"data-radix-menu-content":"",dir:S.dir,...y,...m,ref:_,style:{outline:"none",...m.style},onKeyDown:oe(m.onKeyDown,U=>{const te=U.target.closest("[data-radix-menu-content]")===U.currentTarget,de=U.ctrlKey||U.altKey||U.metaKey,he=U.key.length===1;te&&(U.key==="Tab"&&U.preventDefault(),!de&&he&&G(U.key));const ke=k.current;if(U.target!==ke||!Kse.includes(U.key))return;U.preventDefault();const We=P().filter(Fe=>!Fe.disabled).map(Fe=>Fe.ref.current);pL.includes(U.key)&&We.reverse(),uie(We)}),onBlur:oe(t.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(T.current),M.current="")}),onPointerMove:oe(t.onPointerMove,Ku(U=>{const Y=U.target,te=R.current!==U.clientX;if(U.currentTarget.contains(Y)&&te){const de=U.clientX>R.current?"right":"left";O.current=de,R.current=U.clientX}}))})})})})})})});vL.displayName=Or;var tie="MenuGroup",ob=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"group",...r,ref:e})});ob.displayName=tie;var nie="MenuLabel",xL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});xL.displayName=nie;var Bf="MenuItem",oE="menu.itemSelect",um=w.forwardRef((t,e)=>{const{disabled:n=!1,onSelect:r,...o}=t,s=w.useRef(null),i=Pd(Bf,t.__scopeMenu),a=nb(Bf,t.__scopeMenu),l=Qe(e,s),c=w.useRef(!1),u=()=>{const h=s.current;if(!n&&h){const p=new CustomEvent(oE,{bubbles:!0,cancelable:!0});h.addEventListener(oE,f=>r==null?void 0:r(f),{once:!0}),I1(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(wL,{...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===" "||H0.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});um.displayName=Bf;var wL=w.forwardRef((t,e)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=t,i=nb(Bf,n),a=fL(n),l=w.useRef(null),c=Qe(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(Hu.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:d.jsx(Use,{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,Ku(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:oe(t.onPointerLeave,Ku(g=>i.onItemLeave(g))),onFocus:oe(t.onFocus,()=>h(!0)),onBlur:oe(t.onBlur,()=>h(!1))})})})}),rie="MenuCheckboxItem",bL=w.forwardRef((t,e)=>{const{checked:n=!1,onCheckedChange:r,...o}=t;return d.jsx(EL,{scope:t.__scopeMenu,checked:n,children:d.jsx(um,{role:"menuitemcheckbox","aria-checked":Uf(n)?"mixed":n,...o,ref:e,"data-state":ab(n),onSelect:oe(o.onSelect,()=>r==null?void 0:r(Uf(n)?!0:!n),{checkForDefaultPrevented:!1})})})});bL.displayName=rie;var PL="MenuRadioGroup",[oie,sie]=Pa(PL,{value:void 0,onValueChange:()=>{}}),CL=w.forwardRef((t,e)=>{const{value:n,onValueChange:r,...o}=t,s=qt(r);return d.jsx(oie,{scope:t.__scopeMenu,value:n,onValueChange:s,children:d.jsx(ob,{...o,ref:e})})});CL.displayName=PL;var _L="MenuRadioItem",IL=w.forwardRef((t,e)=>{const{value:n,...r}=t,o=sie(_L,t.__scopeMenu),s=n===o.value;return d.jsx(EL,{scope:t.__scopeMenu,checked:s,children:d.jsx(um,{role:"menuitemradio","aria-checked":s,...r,ref:e,"data-state":ab(s),onSelect:oe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});IL.displayName=_L;var sb="MenuItemIndicator",[EL,iie]=Pa(sb,{checked:!1}),kL=w.forwardRef((t,e)=>{const{__scopeMenu:n,forceMount:r,...o}=t,s=iie(sb,n);return d.jsx(lo,{present:r||Uf(s.checked)||s.checked===!0,children:d.jsx(Ae.span,{...o,ref:e,"data-state":ab(s.checked)})})});kL.displayName=sb;var aie="MenuSeparator",TL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});TL.displayName=aie;var lie="MenuArrow",ML=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=bd(n);return d.jsx(iL,{...o,...r,ref:e})});ML.displayName=lie;var ib="MenuSub",[cie,AL]=Pa(ib),jL=t=>{const{__scopeMenu:e,children:n,open:r=!1,onOpenChange:o}=t,s=Ei(ib,e),i=bd(e),[a,l]=w.useState(null),[c,u]=w.useState(null),h=qt(o);return w.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),d.jsx(Q1,{...i,children:d.jsx(gL,{scope:e,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(cie,{scope:e,contentId:cs(),triggerId:cs(),trigger:a,onTriggerChange:l,children:n})})})};jL.displayName=ib;var Kc="MenuSubTrigger",OL=w.forwardRef((t,e)=>{const n=Ei(Kc,t.__scopeMenu),r=Pd(Kc,t.__scopeMenu),o=AL(Kc,t.__scopeMenu),s=nb(Kc,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(eb,{asChild:!0,...c,children:d.jsx(wL,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":LL(n.open),...t,ref:Gg(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,Ku(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,Ku(h=>{var f,g;u();const p=(f=n.content)==null?void 0:f.getBoundingClientRect();if(p){const m=(g=n.content)==null?void 0:g.dataset.side,v=m==="right",S=v?-5:5,y=p[v?"left":"right"],b=p[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+S,y:h.clientY},{x:y,y:p.top},{x:b,y:p.top},{x:b,y:p.bottom},{x:y,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:oe(t.onKeyDown,h=>{var f;const p=s.searchRef.current!=="";t.disabled||p&&h.key===" "||Wse[r.dir].includes(h.key)&&(n.onOpenChange(!0),(f=n.content)==null||f.focus(),h.preventDefault())})})})});OL.displayName=Kc;var DL="MenuSubContent",RL=w.forwardRef((t,e)=>{const n=yL(Or,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=Ei(Or,t.__scopeMenu),i=Pd(Or,t.__scopeMenu),a=AL(DL,t.__scopeMenu),l=w.useRef(null),c=Qe(e,l);return d.jsx(Hu.Provider,{scope:t.__scopeMenu,children:d.jsx(lo,{present:r||s.open,children:d.jsx(Hu.Slot,{scope:t.__scopeMenu,children:d.jsx(rb,{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=Gse[i.dir].includes(u.key);h&&p&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),u.preventDefault())})})})})})});RL.displayName=DL;function LL(t){return t?"open":"closed"}function Uf(t){return t==="indeterminate"}function ab(t){return Uf(t)?"indeterminate":t?"checked":"unchecked"}function uie(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}function die(t,e){return t.map((n,r)=>t[(e+r)%t.length])}function hie(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=die(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 pie(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 fie(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return pie(n,e)}function Ku(t){return e=>e.pointerType==="mouse"?t(e):void 0}var $L=mL,FL=eb,NL=SL,zL=vL,BL=ob,UL=xL,HL=um,KL=bL,WL=CL,GL=IL,VL=kL,YL=TL,XL=ML,qL=jL,ZL=OL,QL=RL,lb="ContextMenu",[gie,Ffe]=xa(lb,[cm]),mn=cm(),[mie,JL]=gie(lb),e$=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,dir:o,modal:s=!0}=t,[i,a]=w.useState(!1),l=mn(e),c=qt(r),u=w.useCallback(h=>{a(h),c(h)},[c]);return d.jsx(mie,{scope:e,open:i,onOpenChange:u,modal:s,children:d.jsx($L,{...l,dir:o,open:i,onOpenChange:u,modal:s,children:n})})};e$.displayName=lb;var t$="ContextMenuTrigger",n$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,disabled:r=!1,...o}=t,s=JL(t$,n),i=mn(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(FL,{...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,Th(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?t.onPointerMove:oe(t.onPointerMove,Th(u)),onPointerCancel:r?t.onPointerCancel:oe(t.onPointerCancel,Th(u)),onPointerUp:r?t.onPointerUp:oe(t.onPointerUp,Th(u))})]})});n$.displayName=t$;var yie="ContextMenuPortal",cb=t=>{const{__scopeContextMenu:e,...n}=t,r=mn(e);return d.jsx(NL,{...r,...n})};cb.displayName=yie;var r$="ContextMenuContent",o$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=JL(r$,n),s=mn(n),i=w.useRef(!1);return d.jsx(zL,{...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)"}})});o$.displayName=r$;var Sie="ContextMenuGroup",s$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(BL,{...o,...r,ref:e})});s$.displayName=Sie;var vie="ContextMenuLabel",xie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(UL,{...o,...r,ref:e})});xie.displayName=vie;var wie="ContextMenuItem",i$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(HL,{...o,...r,ref:e})});i$.displayName=wie;var bie="ContextMenuCheckboxItem",a$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(KL,{...o,...r,ref:e})});a$.displayName=bie;var Pie="ContextMenuRadioGroup",Cie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(WL,{...o,...r,ref:e})});Cie.displayName=Pie;var _ie="ContextMenuRadioItem",Iie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(GL,{...o,...r,ref:e})});Iie.displayName=_ie;var Eie="ContextMenuItemIndicator",kie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(VL,{...o,...r,ref:e})});kie.displayName=Eie;var Tie="ContextMenuSeparator",Mie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(YL,{...o,...r,ref:e})});Mie.displayName=Tie;var Aie="ContextMenuArrow",jie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(XL,{...o,...r,ref:e})});jie.displayName=Aie;var Oie="ContextMenuSub",l$=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,open:o,defaultOpen:s}=t,i=mn(e),[a,l]=Ii({prop:o,defaultProp:s,onChange:r});return d.jsx(qL,{...i,open:a,onOpenChange:l,children:n})};l$.displayName=Oie;var Die="ContextMenuSubTrigger",c$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(ZL,{...o,...r,ref:e})});c$.displayName=Die;var Rie="ContextMenuSubContent",u$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(QL,{...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)"}})});u$.displayName=Rie;function Th(t){return e=>e.pointerType!=="mouse"?t(e):void 0}var Lie=e$,$ie=n$,Fie=cb,Nie=o$,zie=a$,ub="DropdownMenu",[Bie,Nfe]=xa(ub,[cm]),yn=cm(),[Uie,d$]=Bie(ub),h$=t=>{const{__scopeDropdownMenu:e,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=t,l=yn(e),c=w.useRef(null),[u=!1,h]=Ii({prop:o,defaultProp:s,onChange:i});return d.jsx(Uie,{scope:e,triggerId:cs(),triggerRef:c,contentId:cs(),open:u,onOpenChange:h,onOpenToggle:w.useCallback(()=>h(p=>!p),[h]),modal:a,children:d.jsx($L,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:n})})};h$.displayName=ub;var p$="DropdownMenuTrigger",f$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=t,s=d$(p$,n),i=yn(n);return d.jsx(FL,{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:Gg(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())})})})});f$.displayName=p$;var Hie="DropdownMenuPortal",g$=t=>{const{__scopeDropdownMenu:e,...n}=t,r=yn(e);return d.jsx(NL,{...r,...n})};g$.displayName=Hie;var m$="DropdownMenuContent",y$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=d$(m$,n),s=yn(n),i=w.useRef(!1);return d.jsx(zL,{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)"}})});y$.displayName=m$;var Kie="DropdownMenuGroup",S$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(BL,{...o,...r,ref:e})});S$.displayName=Kie;var Wie="DropdownMenuLabel",Gie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(UL,{...o,...r,ref:e})});Gie.displayName=Wie;var Vie="DropdownMenuItem",v$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(HL,{...o,...r,ref:e})});v$.displayName=Vie;var Yie="DropdownMenuCheckboxItem",x$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(KL,{...o,...r,ref:e})});x$.displayName=Yie;var Xie="DropdownMenuRadioGroup",qie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(WL,{...o,...r,ref:e})});qie.displayName=Xie;var Zie="DropdownMenuRadioItem",Qie=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(GL,{...o,...r,ref:e})});Qie.displayName=Zie;var Jie="DropdownMenuItemIndicator",eae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(VL,{...o,...r,ref:e})});eae.displayName=Jie;var tae="DropdownMenuSeparator",nae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(YL,{...o,...r,ref:e})});nae.displayName=tae;var rae="DropdownMenuArrow",oae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(XL,{...o,...r,ref:e})});oae.displayName=rae;var sae=t=>{const{__scopeDropdownMenu:e,children:n,open:r,onOpenChange:o,defaultOpen:s}=t,i=yn(e),[a=!1,l]=Ii({prop:r,defaultProp:s,onChange:o});return d.jsx(qL,{...i,open:a,onOpenChange:l,children:n})},iae="DropdownMenuSubTrigger",w$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(ZL,{...o,...r,ref:e})});w$.displayName=iae;var aae="DropdownMenuSubContent",b$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(QL,{...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)"}})});b$.displayName=aae;var db=h$,hb=f$,dm=g$,pb=y$,lae=S$,cae=v$,uae=x$,dae=sae,hae=w$,pae=b$;function Ps(){const t=n1();return H("isReadonlyMode",()=>!!(t!=null&&t.getIsReadonly()),[t])}const pS=[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 P$=Te.createContext(null);function fae({forceMobile:t=!1,children:e}){const n=z(),r=H("breakpoint",()=>{const{width:o}=n.getViewportScreenBounds(),s=t?St.MOBILE_SM:pS.length-1;for(let i=0;i<s;i++)if(o>pS[i]&&o<=pS[i+1])return i;return s},[n]);return d.jsx(P$.Provider,{value:r,children:e})}function Mn(){const t=w.useContext(P$);if(t===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return t}const gae=Ge.isDarwin?"⌘":"Ctrl",mae=Ge.isDarwin?"⌥":"Alt";function C$(t){return t===","?[","]:t.split(",")[0].split("").map(e=>{const n=e.replace(/\$/g,gae).replace(/\?/g,mae).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function K0(t){return"— "+C$(t).join(" ")}function cu({children:t,visibleOnMobileLayout:e=!1}){const n=Mn();return!e&&n<St.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:C$(t).map((r,o)=>d.jsx("span",{children:r},o))})}const _$=w.createContext(null);function hm(){const t=w.useContext(_$);if(!t)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return t}function Lr({type:t,sourceId:e,children:n}){return d.jsx(_$.Provider,{value:{type:t,sourceId:e},children:n})}function pm({id:t,kbd:e,label:n,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=hm(),u=Ps(),h=Ce();if(u&&!r)return null;const p=zu(n,l),f=p?h(p):void 0;switch(l){case"menu":return d.jsxs(uae,{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(Ao,{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(cu,{children:e})]});case"context-menu":return d.jsxs(zie,{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(Ao,{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(cu,{children:e})]},t);default:return null}}function uo({actionId:t="",...e}){const r=ba()[t];return r?d.jsx(pm,{...r,...e}):null}function yae(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 Cs(t,e){const n=n1(),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 Yee(n?`${t}-${n.contextId}`:t,r,s)}function ua({id:t,children:e,modal:n=!1,debugOpen:r=!1}){const[o,s]=Cs(t);return d.jsx(db,{open:r||o,dir:"ltr",modal:n,onOpenChange:s,children:e})}function da({children:t,...e}){return d.jsx(hb,{dir:"ltr",asChild:!0,onTouchEnd:n=>xe(n),...e,children:t})}function ha({className:t,side:e="bottom",align:n="start",sideOffset:r=8,alignOffset:o=8,children:s}){const i=Mt();return d.jsx(dm,{container:i,children:d.jsx(pb,{className:le("tlui-menu",t),side:e,sideOffset:r,align:n,alignOffset:o,collisionPadding:4,children:s})})}function Sae({id:t,children:e}){const[n,r]=Cs(t);return d.jsx(dae,{open:n,onOpenChange:r,children:e})}function vae({id:t,label:e,title:n,disabled:r}){return d.jsx(hae,{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 xae({id:t,alignOffset:e=-1,sideOffset:n=-4,size:r="small",children:o}){const s=Mt();return d.jsx(dm,{container:s,children:d.jsx(pae,{"data-testid":t,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:n,collisionPadding:4,"data-size":r,children:o})})}function wae({children:t}){return d.jsx(lae,{dir:"ltr",className:"tlui-menu__group",children:t})}function Wu({noClose:t,children:e}){return d.jsx(cae,{dir:"ltr",asChild:!0,onClick:t?xe:void 0,children:e})}function Kt({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}=hm(),p=Ce(),[f,g]=w.useState(!1);if(Ps()&&!n)return null;const v=zu(s,u),S=o?K0(o):void 0,y=v?p(v):void 0,b=y&&S?`${y} ${S}`:y;switch(u){case"menu":return d.jsx(Wu,{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:y}),o&&d.jsx(cu,{children:o})]})});case"context-menu":return t?null:d.jsxs(i$,{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:y}),o&&d.jsx(cu,{children:o}),e&&d.jsx(yae,{})]});case"panel":return d.jsxs(ce,{"data-testid":`${h}.${r}`,type:"menu",title:b,disabled:t,onClick:()=>a(h),children:[d.jsx(Pt,{children:y}),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:y}),d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:d.jsx(cu,{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:y})]});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(Wu,{"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 K({actionId:t="",...e}){const r=ba()[t];return r?d.jsx(Kt,{...r,...e}):null}const I$=w.createContext(null);function bae({overrides:t,children:e}){const n=z(),r=Qt(),{addDialog:o}=wa(),s=F3(),i=w.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){if(n.isIn("select")){const u=n.root.getCurrent();u.exit({},u.id),u.enter({},u.id)}n.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){n.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){n.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){n.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...qr.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){n.run(()=>{n.setStyleForNextShapes(qr,c),n.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){n.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){n.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){n.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){n.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){s(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){n.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){n.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(c){o({component:T3}),r("select-tool",{source:c,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){n.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}}];a.push();const l=Object.fromEntries(a.map(c=>[c.id,c]));return t?t(n,l,{insertMedia:s}):l},[t,n,r,s,o]);return d.jsx(I$.Provider,{value:i,children:e})}function fb(){const t=w.useContext(I$);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Rn({toolId:t="",...e}){const r=fb()[t];return r?d.jsx(Kt,{...r,...e}):null}function Pae({children:t}){const e=z();return H("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:Cae}=Math,xl=Cae+1e-4;function E$(t,e={}){const{size:n=16,smoothing:r=.5}=e;if(t.length===0||n<=0)return{left:[],right:[]};const o=t[0],s=t[t.length-1],i=s.runningLength,a=Math.pow(n*r,2),l=[],c=[];let u=t[0].vector,h=t[0].point,p=h,f=h,g=p,m=!1,v;for(let S=0;S<t.length;S++){v=t[S];const{point:y,vector:b}=t[S],P=v.vector.dpr(u),C=(S<t.length-1?t[S+1]:t[S]).vector,I=S<t.length-1?C.dpr(v.vector):1,k=P<0&&!m,_=I!==null&&I<.2;if(k||_){if(I>-.62&&i-v.runningLength>v.radius){const M=u.clone().mul(v.radius);u.clone().cpr(C)<0?(f=x.Add(y,M),g=x.Sub(y,M)):(f=x.Sub(y,M),g=x.Add(y,M)),l.push(f),c.push(g)}else{const M=u.clone().mul(v.radius).per(),D=x.Sub(v.input,M);for(let j=1/13,O=0;O<1;O+=j)f=x.RotWith(D,v.input,xl*O),l.push(f),g=x.RotWith(D,v.input,xl+xl*-O),c.push(g)}h=f,p=g,_&&(m=!0);continue}if(m=!1,v===o||v===s){const M=x.Per(b).mul(v.radius);l.push(x.Sub(y,M)),c.push(x.Add(y,M));continue}const T=x.Lrp(C,b,I).per().mul(v.radius);f=x.Sub(y,T),(S<=1||x.Dist2(h,f)>a)&&(l.push(f),h=f),g=x.Add(y,T),(S<=1||x.Dist2(p,g)>a)&&(c.push(g),p=g),u=b}return{left:l,right:c}}function gb(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}=E$(t,e),m=l.point,v=t.length>1?t[t.length-1].point:x.AddXY(l.point,1,1);if(t.length===1&&(!(h||p)||s)){const P=x.Add(m,x.Sub(m,v).uni().per().mul(-l.radius)),C=[];for(let I=1/13,k=I;k<=1;k+=I)C.push(x.RotWith(P,m,xl*2*k));return C}const S=[];if(!(h||p&&t.length===1))if(i)for(let P=1/8,C=P;C<=1;C+=P){const I=x.RotWith(g[0],m,xl*C);S.push(I)}else{const P=x.Sub(f[0],g[0]),C=x.Mul(P,.5),I=x.Mul(P,.51);S.push(x.Sub(m,C),x.Sub(m,I),x.Add(m,I),x.Add(m,C))}const y=[],b=c.vector.clone().per().neg();if(p||h&&t.length===1)y.push(v);else if(a){const P=x.Add(v,x.Mul(b,c.radius));for(let C=1/29,I=C;I<1;I+=C)y.push(x.RotWith(P,v,xl*3*I))}else y.push(x.Add(v,x.Mul(b,c.radius)),x.Add(v,x.Mul(b,c.radius*.99)),x.Sub(v,x.Mul(b,c.radius*.99)),x.Sub(v,x.Mul(b,c.radius)));return f.concat(y,g.reverse(),S)}const _ae=.025,Iae=.01;function Oo(t,e={}){var v;const{streamline:n=.5,size:r=16,simulatePressure:o=!1}=e;if(t.length===0)return[];const s=.15+(1-n)*.85;let i=t.map(x.From),a=0;if(!o){let S=i[0];for(;S&&!(S.z>=_ae);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=Iae);)i.pop(),S=i[i.length-1]}if(i.length===0)return[{point:x.From(t[0]),input:x.From(t[0]),pressure:o?.5:.15,vector:new x(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(x.Dist2(l,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(x.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=e.last||!e.simulatePressure||i.length>1&&x.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&e.simulatePressure){const S=i[1];i=i.slice(0,-1);for(let y=1;y<5;y++){const b=x.Lrp(i[0],S,y/4);b.z=(i[0].z+(S.z-i[0].z))*y/4,i.push(b)}}const h=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new x(1,1),distance:0,runningLength:0,radius:1}];let p=0,f=h[0],g,m;u&&n>0&&i.push(i[i.length-1].clone());for(let S=1,y=i.length;S<y;S++)g=!s||e.last&&S===y-1?i[S].clone():i[S].clone().lrp(f.point,1-s),!f.point.equals(g)&&(m=x.Dist(g,f.point),p+=m,!(S<4&&p<r)&&(f={input:i[S],point:g,pressure:o?.5:i[S].z,vector:x.Sub(f.point,g).uni(),distance:m,runningLength:p,radius:1},h.push(f)));if((v=h[1])!=null&&v.vector&&(h[0].vector=h[1].vector.clone()),p<1){const S=Math.max(.5,...h.map(y=>y.pressure));h.forEach(y=>y.pressure=S)}return h}const{min:js}=Math,fS=.275;function fm(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((S,y)=>Math.max(S,y.pressure),.5);return t.forEach(S=>{S.pressure=v,S.radius=n*s(.5-r*(.5-S.pressure))}),t}else{let v;for(let S=0,y=t.length;S<y&&(f=t[S],!(f.runningLength>n*5));S++){const b=js(1,f.distance/n);if(o){const P=js(1,1-b);v=js(1,p+(P-p)*(b*fS))}else v=js(1,p+(f.pressure-p)*.5);p=p+(v-p)*.5}for(let S=0;S<t.length;S++){if(f=t[S],r){let{pressure:y}=f;const b=js(1,f.distance/n);if(o){const P=js(1,1-b);y=js(1,p+(P-p)*(b*fS))}else y=js(1,p+(y-p)*(b*fS));f.radius=n*s(.5-r*(.5-y)),p=y}else f.radius=n/2;h===void 0&&(h=f.radius)}}const g=i.taper===!1?0:i.taper===!0?Math.max(n,u):i.taper,m=a.taper===!1?0:a.taper===!0?Math.max(n,u):a.taper;if(g||m)for(let v=0;v<t.length;v++){f=t[v];const{runningLength:S}=f,y=S<g?l(S/g):1,b=u-S<m?c((u-S)/m):1;f.radius=Math.max(.01,f.radius*Math.min(y,b))}return t}function Eae(t,e={}){return gb(fm(Oo(t,e),e),e)}function sE({scribble:t,zoom:e,color:n,opacity:r,className:o}){if(!t.points.length)return null;const s=Eae(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=i1(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 kae=({bounds:t,rotation:e})=>{const n=z();return H("should display",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[n])?d.jsx(oj,{bounds:t,rotation:e}):null};function Tae({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:`
|
|
342
|
-
${N(0-s)},${N(t)}
|
|
343
|
-
${N(0-s)},${N(0-s)}
|
|
344
|
-
${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:`
|
|
345
|
-
${N(e-t)},${N(0-s)}
|
|
346
|
-
${N(e+s)},${N(0-s)}
|
|
347
|
-
${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:`
|
|
348
|
-
${N(e+s)},${N(n-t)}
|
|
349
|
-
${N(e+s)},${N(n+s)}
|
|
350
|
-
${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:`
|
|
351
|
-
${N(0+t)},${N(n+s)}
|
|
352
|
-
${N(0-s)},${N(n+s)}
|
|
353
|
-
${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 Mae=$t(function({bounds:e,rotation:n}){const r=z(),o=w.useRef(null),s=Ps(),i=yo("top"),a=yo("right"),l=yo("bottom"),c=yo("left"),u=yo("top_left"),h=yo("top_right"),p=yo("bottom_right"),f=yo("bottom_left"),g=!r.menus.hasAnyOpenMenus()&&r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,v=r.getOnlySelectedShape(),S=v&&r.isShapeOrAncestorLocked(v),y=v?r.getShapeUtil(v).expandSelectionOutlinePx(v):0;if(Yl(o,e==null?void 0:e.x,e==null?void 0:e.y,1,r.getSelectionRotation(),{x:-y,y:-y}),v&&r.isShapeHidden(v)||!e)return null;e=e.clone().expandBy(y).zeroFix();const b=r.getZoomLevel(),P=r.getInstanceState().isChangingStyle,C=e.width,I=e.height,k=8/b,_=C<k*2,T=I<k*2,M=C<k*4,D=I<k*4,j=C<k*5,O=I<k*5,R=m?1.75:1,B=6/b*R,L=(M?B/2:B)*(R*.75),G=(D?B/2:B)*(R*.75),$=(v?!r.getShapeUtil(v).hideSelectionBoundsFg(v):!0)&&!P;let U=$&&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.isIn("select.resizing")&&v&&r.isShapeOfType(v,"text");v&&U&&Ge.isFirefox&&r.isShapeOfType(v,"embed")&&(U=!1);const Y=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!P&&!s,te=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!P&&!s,de=!m&&!(_||T)&&(te||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!S,he=m&&(!M||!D)&&(te||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!S,ke=te&&(v?r.getShapeUtil(v).canResize(v)&&!r.getShapeUtil(v).hideResizeHandles(v):!0)&&!Y&&!S,se=_||T,We=_&&T,Fe=j||O,st=ke||Y,$e=!de,lt=!te||!he,He=!te||!st,er=!te||!st||se,Ft=!te||!st||se,jn=!te||!st||We&&!Y;let vt=!0,Jt=!0;if(Y)vt=Fe,Jt=Fe;else if(ke){vt=se||We||m;const Is=m&&v&&v.type==="text";Jt=vt&&!Is}const zo=Math.min(24/b,I-G*3),rc=te&&m&&v&&r.isShapeOfType(v,"text")&&zo*b>=4;return d.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsxs("g",{ref:o,children:[U&&d.jsx("rect",{className:"tl-selection__fg__outline",width:N(C),height:N(I)}),d.jsx(Mh,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:B,corner:"top_left_rotate",cursor:g?nr("nwse-rotate",n):void 0,isHidden:$e}),d.jsx(Mh,{"data-testid":"selection.rotate.top-right",cx:C+B*3,cy:0,targetSize:B,corner:"top_right_rotate",cursor:g?nr("nesw-rotate",n):void 0,isHidden:$e}),d.jsx(Mh,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:I+B*3,targetSize:B,corner:"bottom_left_rotate",cursor:g?nr("swne-rotate",n):void 0,isHidden:$e}),d.jsx(Mh,{"data-testid":"selection.rotate.bottom-right",cx:C+B*3,cy:I+B*3,targetSize:B,corner:"bottom_right_rotate",cursor:g?nr("senw-rotate",n):void 0,isHidden:$e}),d.jsx(jae,{"data-testid":"selection.rotate.mobile",cx:M?-B*1.5:C/2,cy:M?I/2:-B*1.5,size:k,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-(D?G*2:G)),width:N(C),height:N(Math.max(1,G*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-(M?0:L)),y:0,height:N(I),width:N(Math.max(1,L*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(I-(D?0:G)),width:N(C),height:N(Math.max(1,G*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-(M?L*2:L)),y:0,height:N(I),width:N(Math.max(1,L*2)),style:g?{cursor:nr("ew-resize",n)}:void 0,...c}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":He}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:N(0-(M?L*2:L*1.5)),y:N(0-(D?G*2:G*1.5)),width:N(L*3),height:N(G*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-(M?0:L*1.5)),y:N(0-(D?G*2:G*1.5)),width:N(L*3),height:N(G*3),style:g?{cursor:nr("nesw-resize",n)}:void 0,...h}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":jn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:N(C-(M?L:L*1.5)),y:N(I-(D?G:G*1.5)),width:N(L*3),height:N(G*3),style:g?{cursor:nr("nwse-resize",n)}:void 0,...p}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Ft}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:N(0-(M?L*3:L*1.5)),y:N(I-(D?0:G*1.5)),width:N(L*3),height:N(G*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":He}),"aria-label":"top_left handle",x:N(0-k/2),y:N(0-k/2),width:N(k),height:N(k)}),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-k/2),y:N(0-k/2),width:N(k),height:N(k)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:le("tl-corner-handle",{"tl-hidden":jn}),"aria-label":"bottom_right handle",x:N(C-k/2),y:N(I-k/2),width:N(k),height:N(k)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:le("tl-corner-handle",{"tl-hidden":Ft}),"aria-label":"bottom_left handle",x:N(0-k/2),y:N(I-k/2),width:N(k),height:N(k)})]}),rc&&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-k/4),y:N(I/2-zo/2),rx:k/4,width:N(k/2),height:N(zo)}),d.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:k/4,x:N(C-k/4),y:N(I/2-zo/2),width:N(k/2),height:N(zo)})]}),Y&&d.jsx(Tae,{size:k,width:C,height:I,hideAlternateHandles:Fe})]})})}),Mh=function({cx:e,cy:n,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=yo(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})},Aae=Math.sqrt(Math.PI),jae=function({cx:e,cy:n,size:r,isHidden:o,"data-testid":s}){const i=yo("mobile_rotate"),a=z(),l=H("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/Aae})]})};function Oae(){const t=z();return H("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(sj,{}):null}function W0(t,e,n){const{arrowheadStart:r,arrowheadEnd:o}=e.props,s=sl(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=Hf(t,e,"start"),h=Hf(t,e,"end"),p=t.getShapePageTransform(e);iE(a,s.start,p,h),iE(i,s.end,p,u);let f=0,g=0,m=0,v=0,S=il*e.props.scale;const y=u&&h&&u.shape===h.shape,b=u&&h?mb(t,u.shape.id,h.shape.id):"safe";b==="safe"&&u&&h&&!y&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(il*e.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(il*e.props.scale))));const P=x.Sub(a,i),C=x.Len(P)?P.uni():x.From(P),I=!x.Equals(C,c);y||(b!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(m=Co[e.props.size]/2+("size"in u.shape.props?Co[u.shape.props.size]/2:0),f=(Kf+m)*e.props.scale,S+=m*e.props.scale),b!=="end-contains-start"&&h&&o!=="none"&&!h.isExact&&(v=Co[e.props.size]/2+("size"in h.shape.props?Co[h.shape.props.size]/2:0),g=(Kf+v)*e.props.scale,S+=v*e.props.scale));const k=i.clone().add(C.clone().mul(f*(I?-1:1))),_=a.clone().sub(C.clone().mul(g*(I?-1:1)));x.DistMin(k,_,S)&&(f!==0&&g!==0?(f*=-1.5,g*=-1.5):f!==0?f*=-1:g!==0&&(g*=-1)),i.add(C.clone().mul(f*(I?-1:1))),a.sub(C.clone().mul(g*(I?-1:1))),I?(u&&h&&a.setTo(x.Add(i,C.clone().mul(-il*e.props.scale))),l.setTo(x.Med(s.start,s.end))):l.setTo(x.Med(i,a));const T=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:T>0,length:T}}function iE(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?d1:yZ)(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 Dae(t,e,n){const{arrowheadEnd:r,arrowheadStart:o}=e.props,s=e.props.bend;if(Math.abs(s)>Math.abs(e.props.bend*(Nae*e.props.scale)))return W0(t,e,n);const i=sl(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=Hf(t,e,"start"),p=Hf(t,e,"end"),f=i.start.clone(),g=i.end.clone(),m=u.clone();if(x.Equals(f,g))return{bindings:n,isStraight:!0,start:{handle:f,point:f,arrowhead:e.props.arrowheadStart},end:{handle:g,point:g,arrowhead:e.props.arrowheadEnd},middle:m,isValid:!1,length:0};const v=e.props.bend<0,S=v?id:$A,y=aE(f,g,m),b=x.Angle(y.center,f),P=x.Angle(y.center,g),C=S(b,P);if(y.length===0||y.size===0||!N_(y.length)||!N_(y.size))return W0(t,e,n);const I=f.clone(),k=g.clone(),_=m.clone(),T=t.getShapePageTransform(e);let M=0,D=0,j=il*e.props.scale;if(h&&!h.isExact){const Y=q.applyToPoint(T,I),te=q.applyToPoint(T,y.center),de=q.applyToPoint(T,k),he=q.Inverse(h.transform),ke=q.applyToPoint(he,Y),se=q.applyToPoint(he,te),We=q.applyToPoint(he,de),{isClosed:Fe}=h,st=Fe?y0:iI;let $e,lt=st(se,y.radius,h.outline);if(lt){const He=se.angle(ke),er=se.angle(We),Ft=S(He,er);lt=lt.filter(vt=>S(He,se.angle(vt))<=Ft);const jn=Ft*.25;lt.sort(Fe?(vt,Jt)=>Math.abs(S(He,se.angle(vt))-jn)<Math.abs(S(He,se.angle(Jt))-jn)?-1:1:(vt,Jt)=>S(He,se.angle(vt))<S(He,se.angle(Jt))?-1:1),$e=lt[0]??(Fe?void 0:ke)}else $e=Fe?void 0:ke;if($e&&(I.setTo(t.getPointInShapeSpace(e,q.applyToPoint(h.transform,$e))),h.didIntersect=!0,o!=="none")){const He=Co[e.props.size]/2+("size"in h.shape.props?Co[h.shape.props.size]/2:0);M=(Kf+He)*e.props.scale,j+=He*e.props.scale}}if(p&&!p.isExact){const Y=q.applyToPoint(T,I),te=q.applyToPoint(T,k),de=q.applyToPoint(T,y.center),he=q.Inverse(p.transform),ke=q.applyToPoint(he,Y),se=q.applyToPoint(he,de),We=q.applyToPoint(he,te),Fe=p.isClosed,st=Fe?y0:iI;let $e,lt=st(se,y.radius,p.outline);if(lt){const He=se.angle(ke),er=se.angle(We),Ft=S(He,er),jn=Ft*.75;lt=lt.filter(vt=>S(He,se.angle(vt))<=Ft),lt.sort(Fe?(vt,Jt)=>Math.abs(S(He,se.angle(vt))-jn)<Math.abs(S(He,se.angle(Jt))-jn)?-1:1:(vt,Jt)=>S(He,se.angle(vt))<S(He,se.angle(Jt))?-1:1),lt[0]?$e=lt[0]:$e=Fe?void 0:We}else $e=Fe?void 0:We;if($e&&(k.setTo(t.getPointInShapeSpace(e,q.applyToPoint(p.transform,$e))),p.didIntersect=!0,r!=="none")){const He=Co[e.props.size]/2+("size"in p.shape.props?Co[p.shape.props.size]/2:0);D=(Kf+He)*e.props.scale,j+=He*e.props.scale}}let O=x.Angle(y.center,I),R=x.Angle(y.center,k),B=S(O,R),L=B*y.radius;const G=I.clone(),$=k.clone();if(M!==0&&G.setTo(y.center).add(x.FromAngle(O+B*(M/L*(v?1:-1))).mul(y.radius)),D!==0&&$.setTo(y.center).add(x.FromAngle(R+B*(D/L*(v?-1:1))).mul(y.radius)),x.DistMin(G,$,j)&&(M!==0&&D!==0?(M*=-1.5,D*=-1.5):M!==0?M*=-2:D!==0&&(D*=-2)),M!==0&&I.setTo(y.center).add(x.FromAngle(O+B*(M/L*(v?1:-1))).mul(y.radius)),D!==0&&k.setTo(y.center).add(x.FromAngle(R+B*(D/L*(v?-1:1))).mul(y.radius)),h&&p&&!h.isExact&&!p.isExact){O=x.Angle(y.center,I),R=x.Angle(y.center,k),B=S(O,R),L=B*y.radius;const Y=mb(t,h.shape.id,p.shape.id);Y==="double-bound"&&L<30?(I.setTo(f),k.setTo(g),_.setTo(m)):Y==="safe"&&(h&&!h.didIntersect&&I.setTo(f),(p&&!p.didIntersect||S(b,O)>S(b,R))&&k.setTo(y.center).add(x.FromAngle(O+B*(Math.min(.9,il*e.props.scale/L)*(v?1:-1))).mul(y.radius)))}Rae(y.center,y.radius,I,k,_,C,v),I.equals(k)&&(I.setTo(_.clone().addXY(1,1)),k.setTo(_.clone().subXY(1,1))),f.setTo(I),g.setTo(k),m.setTo(_);const U=aE(f,g,m);return{bindings:n,isStraight:!1,start:{point:f,handle:i.start,arrowhead:e.props.arrowheadStart},end:{point:g,handle:i.end,arrowhead:e.props.arrowheadEnd},middle:m,handleArc:y,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function aE(t,e,n){const r=r1(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 Rae(t,e,n,r,o,s,i){const a=x.Angle(t,n),l=x.Angle(t,r);let c=id(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 Lae=8;function $ae(t){return Math.abs(t.props.bend)<Lae*t.props.scale}function Hf(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 ro?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function lE(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 zn(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 Fae=vV("arrow info",(t,e)=>{const n=zn(t,e);return $ae(e)?W0(t,e,n):Dae(t,e,n)});function Po(t,e){const n=typeof e=="string"?e:e.id;return Fae.get(t,n)}function sl(t,e,n){var a,l;const r=t.getShapePageTransform(e),o=mb(t,(a=n.start)==null?void 0:a.toId,(l=n.end)==null?void 0:l.toId),s=n.start?lE(t,r,n.start,o==="double-bound"||o==="start-contains-end"):x.From(e.props.start),i=n.end?lE(t,r,n.end,o==="double-bound"||o==="end-contains-start"):x.From(e.props.end);return{start:s,end:i}}function Tc(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 dp(t,e,n){const r=t.getBindingsFromShape(e,"arrow").filter(o=>o.props.terminal===n);t.deleteBindings(r)}const il=10,Kf=10,Nae=10,Co={s:2,m:3.5,l:5,xl:10};function mb(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 hp extends ap{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const n=this.editor.getShape(e.fromId);n&&gS(this.editor,n)}onAfterChange({bindingAfter:e}){const n=this.editor.getShape(e.fromId);n&&gS(this.editor,n)}onAfterChangeFromShape({shapeAfter:e}){gS(this.editor,e)}onAfterChangeToShape({binding:e}){k$(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const n=this.editor.getShape(e.fromId);n&&Wf({editor:this.editor,arrow:n,terminal:e.props.terminal})}}E(hp,"type","arrow"),E(hp,"props",oA),E(hp,"migrations",sA);function k$(t,e){var v;const n=t.getShape(e);if(!n)return;const r=zn(t,n),{start:o,end:s}=r,i=o?t.getShape(o.toId):void 0,a=s?t.getShape(s.toId):void 0,l=t.getAncestorPageId(n);if(!l)return;let c;if(i&&a)c=t.findCommonAncestor([i,a])??l;else if(i||a){const S=(v=i||a)==null?void 0:v.parentId;S&&S===n.parentId?c=n.parentId:c=l}else return;c&&c!==n.parentId&&t.reparentShapes([e],c);const u=t.getShape(e);if(!u)throw Error("no reparented arrow");const h=t.getShapeNearestSibling(u,i),p=t.getShapeNearestSibling(u,a);let f;if(h&&p)f=h.index>p.index?h:p;else if(h&&!p)f=h;else if(p&&!h)f=p;else return;let g;const m=t.getSortedChildIdsForParent(f.parentId).map(S=>t.getShape(S)).filter(S=>S.index>f.index);if(m.length){const S=m.find(y=>y.type!=="arrow");if(u.index>f.index&&(!S||u.index<S.index))return;g=ju(f.index,m[0].index)}else g=wo(f.index);g!==u.index&&t.updateShapes([{id:e,type:"arrow",index:g}])}function gS(t,e){const n=zn(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)&&Wf({editor:t,arrow:e,terminal:r,unbind:!0})}k$(t,e.id)}function Wf({editor:t,arrow:e,terminal:n,unbind:r=!1,useHandle:o=!1}){const s=Po(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=hd(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);ri(m,c.props.bend)||(c.props.bend=m)}t.updateShape(c),r&&dp(t,e,n)}const T$=[hp],pn={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},hn={s:2,m:3.5,l:5,xl:10},Al={s:18,m:24,l:36,xl:44},us={s:18,m:22,l:26,xl:32},zae={s:18,m:20,l:24,xl:28},Ss={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},Bae=20,Gf=4.25,Ir=16;function Uae(t,e){const n=t.w/e.w,r=t.h/e.h;return n<=1&&r<=1?t:n>r?{w:t.w/n,h:t.h/n}:{w:t.w/r,h:t.h/r}}/*!
|
|
354
|
-
* MIT License
|
|
355
|
-
* Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
|
|
356
|
-
* Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
|
|
357
|
-
*/const al=" ",Sn=class Sn{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)||Sn.insertTextFirefox(e,n),o===r.body?e.blur():o instanceof HTMLElement&&o!==e&&o.focus()}static set(e,n){e.select(),Sn.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=Sn.getSelection(e);Sn.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 Sn.insert(e,l),e.selectionStart=i,o+=l.length-a,l})}static findLineEnd(e,n){const r=e.lastIndexOf(`
|
|
358
|
-
`,n-1)+1;return e.charAt(r)!==" "?n:r+1}static indent(e){var a;const{selectionStart:n,selectionEnd:r,value:o}=e,s=o.slice(n,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const l=o.lastIndexOf(`
|
|
359
|
-
`,n-1)+1,c=e.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${al}`),h=u.length-c.length;e.setSelectionRange(l,r-1),Sn.insert(e,u),e.setSelectionRange(n+1,r+h)}else Sn.insert(e,al)}static unindent(e){const{selectionStart:n,selectionEnd:r,value:o}=e,s=o.lastIndexOf(`
|
|
360
|
-
`,n-1)+1,i=Sn.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),Sn.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=Ah(e)??0,s=Ah(e)??0,i=r.slice(o,s),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
|
|
361
|
-
`,o-1)+1,u=r.slice(c,s-1),p=u.replace(/^|\n/g,`$&${al}`).length-u.length;n&&n.setBaseAndExtent(e,o+1,e,s+p)}else{const c=window.getSelection();e.innerText=r.slice(0,o)+al+r.slice(o),c==null||c.setBaseAndExtent(e,o+1,e,o+2)}}static unindentCE(e){const n=window.getSelection(),r=e.innerText,o=Ah(e)??0,s=Ah(e)??0,i=r.lastIndexOf(`
|
|
362
|
-
`,o-1)+1,a=Sn.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(Sn.fixNewLines,`
|
|
363
|
-
`)}static normalizeTextForDom(e){return e.replace(Sn.fixNewLines,`
|
|
364
|
-
`).split(`
|
|
365
|
-
`).map(n=>n||" ").join(`
|
|
366
|
-
`)}};E(Sn,"fixNewLines",/\r?\n|\r/g);let jl=Sn;function Ah(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 Hae=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function M$(t){return Hae.test(t)}function Kae(t){return t.replace(/\t/g,al)}function Wae(t){const e=t.split(`
|
|
367
|
-
`);for(;e[0]&&e[0].trim().length===0;)e.shift();let n=1/0;for(const r of e)if(r.trim().length>0){const o=r.length-r.trimStart().length;n=Math.min(n,o)}return e.map(r=>r.slice(n)).join(`
|
|
368
|
-
`)}const A$={"&":"&",""":'"',"'":"'",""":'"',"&":"&","'":"'","–":"–","—":"—","‘":"‘","’":"’","“":"“","”":"”","…":"…"},Gae=new RegExp(Object.keys(A$).join("|"),"g");function Vae(t){return t.replace(Gae,e=>A$[e])}function Yae(t){return t.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function Xae(t){return Yae(Wae(Kae(t)))}function qae(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=SC(await a.arrayBuffer());l=l??zs.createId(h);const p=await cE(a,l,c,u);if(isFinite(e)){const f={w:p.props.w,h:p.props.h},g=Uae(f,{w:e,h:e});f!==g&&lr.isStaticImageType(a.type)&&(p.props.w=g.w,p.props.h=g.h)}return p.props.src=await t.uploadAsset(p,a),zs.create(p)}),t.registerExternalAssetHandler("url",async({url:a})=>{var c,u,h,p,f;let l;try{const m=await(await no(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:zs.createId(zv(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");uE(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=Be(),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=SC(await f.arrayBuffer()),S=zs.createId(v),y=await cE(f,S,g,m);let b;g&&(b=t.createTemporaryAssetPreview(S,f)),h.push(y),p.push({asset:y,file:f,temporaryAssetPreview:b})}Promise.allSettled(p.map(async f=>{try{const g=await t.getAssetForExternalContent({type:"file",file:f.file});if(!g)throw Error("Could not create an asset");t.updateAssets([{...g,id:f.asset.id}])}catch(g){s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(g);return}})),uE(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=Xae(l),p=t.getOnlySelectedShape();if(p&&"text"in p.props){t.updateShapes([{id:p.id,type:p.type,props:{text:h}}]);return}let f,g,m,v="middle";const S=h.split(`
|
|
369
|
-
`).length>1,y=M$(h);S&&(v=S?y?"end":"start":"middle");const b=t.textMeasure.measureText(h,{...pn,fontFamily:Ss[u.font],fontSize:Al[u.size],maxWidth:null}),P=Math.min(S?t.getViewportPageBounds().width*.9:920,Math.max(200,t.getViewportPageBounds().width*.9));if(b.w>P){const C=t.textMeasure.measureText(h,{...pn,fontFamily:Ss[u.font],fontSize:Al[u.size],maxWidth:P});f=C.w,g=C.h,m=!1,v=y?"end":"start"}else f=b.w,g=b.h,m=!0;c.y-g/2<t.getViewportPageBounds().minY+40&&(c.y=t.getViewportPageBounds().minY+40+g/2),t.createShapes([{id:Be(),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=zs.createId(zv(l)),f=Zae(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 cE(t,e,n,r){let o=t.type;t.type==="video/quicktime"&&(o="video/mp4");const s=n?await lr.getImageSize(t):await lr.getVideoSize(t),i=await lr.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 uE(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:Be(),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:Be(),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)),j$(t,n)}),o.map(s=>s.id)}function j$(t,e){const n=t.getViewportPageBounds();let r=t.getSelectionPageBounds();if(r){const o=r.center.sub(e);t.updateShapes(t.getSelectedShapes().map(s=>{const i=t.getShapeParentTransform(s).decompose().rotation,a=x.Rot(o,-i);return{id:s.id,type:s.type,x:s.x-a.x,y:s.y-a.y}}))}r=t.getSelectionPageBounds(),r&&!n.contains(r)&&t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})}function Zae(t,e,n){const r={id:Be(),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),j$(t,n)}),t.getShape(r.id)}var kS;let Qae=(kS=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}))}}},E(kS,"id","idle"),kS);var TS;let Jae=(TS=class extends ie{constructor(){super(...arguments);E(this,"shape");E(this,"markId","");E(this,"preciseTimeout",-1);E(this,"didTimeout",!1)}onEnter(){this.markId="",this.didTimeout=!1;const n=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.canBindShapes({fromShape:"arrow",toShape:r,binding:"arrow"}),margin:0,hitInside:!0,renderingOnly:!0});n?this.editor.setHintingShapes([n.id]):this.createArrowShape(),this.startPreciseTimeout()}onExit(){this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()}onPointerMove(){if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:{id:"end",type:"vertex",index:"a3",x:0,y:0},isCreating:!0,creatingMarkId:this.markId||void 0,onInteractionEnd:"arrow"})}}onPointerUp(){this.cancel()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u;const{originPagePoint:n}=this.editor.inputs,r=Be();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`),this.editor.createShape({id:r,type:"arrow",x:n.x,y:n.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=s.find(h=>h.id==="start"),c=(u=i.onHandleDrag)==null?void 0:u.call(i,o,{handle:{...l,x:0,y:0},isPrecise:!0,initial:a});c&&this.editor.updateShapes([c]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var o,s;const n=this.shape;if(!n)throw Error("expected shape");const r=this.editor.getShapeHandles(n);if(!r)throw Error("expected handles for arrow");{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=r.find(u=>u.id==="start"),c=(o=i.onHandleDrag)==null?void 0:o.call(i,n,{handle:{...l,x:0,y:0},isPrecise:this.didTimeout,initial:a});c&&this.editor.updateShapes([c])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint),c=r.find(h=>h.id==="end"),u=(s=i.onHandleDrag)==null?void 0:s.call(i,this.editor.getShape(n),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(n.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},E(TS,"id","pointing"),TS);class G0 extends ie{constructor(){super(...arguments);E(this,"shapeType","arrow")}static children(){return[Qae,Jae]}}E(G0,"id","arrow"),E(G0,"initial","idle");class yb extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"initialShape");E(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");E(this,"util",this.editor.getShapeUtil(this.shapeType));E(this,"isPen",!1);E(this,"isPenOrStylus",!1);E(this,"segmentMode","free");E(this,"didJustShiftClickToExtendPreviousShapeLine",!1);E(this,"pagePointWhereCurrentSegmentChanged",{});E(this,"pagePointWhereNextSegmentChanged",null);E(this,"lastRecordedPoint",{});E(this,"mergeNextPoint",!1);E(this,"currentLineLength",0);E(this,"canDraw",!1);E(this,"markId",null)}onEnter(n){this.markId=null,this.info=n,this.canDraw=!this.editor.menus.hasAnyOpenMenus(),this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.canDraw&&this.startShape()}onPointerMove(){const{inputs:n}=this.editor;if(this.isPen&&!n.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&n.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(this.isPenOrStylus?x.Dist(n.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=n.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape())}onKeyDown(n){if(n.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()}onKeyUp(n){if(n.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()}onExit(){this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()}canClose(){return this.shapeType!=="highlight"}getIsClosed(n,r,o){if(!this.canClose())return!1;const s=hn[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=Ht(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=Ht(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<hn[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=Be();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=Ht(l);if(!v)throw Error("Expected a previous segment!");const S=Ht(v.points);if(!S)throw Error("Expected a previous last point!");let y;const b=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(v.type==="straight"){this.currentLineLength+=x.Dist(S,b),y={type:"straight",points:[{...S},b]};const C=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=q.applyToPoint(C,S)}else y={type:"straight",points:[b,f]};const P={id:o,type:this.shapeType,props:{segments:[...l,y]}};this.canClose()&&(P.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([P])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:g}=this;if(g===null)throw Error("We should have a point where the segment changed");if(x.Dist2(g,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const v=l.slice(),S=v[v.length-1],y=Ht(S.points);if(!y)throw Error("No previous point!");const b={type:"free",points:[...x.PointsBetween(y,f,6).map(I=>({x:Qo(I.x),y:Qo(I.y),z:Qo(I.z)}))]},P=[...v,b];this.currentLineLength<hn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(P));const C={id:o,type:this.shapeType,props:{segments:P}};this.canClose()&&(C.props.isClosed=this.getIsClosed(P,s,i)),this.editor.updateShapes([C])}break}case"straight":{const g=l.slice(),m=g[g.length-1],{pagePointWhereCurrentSegmentChanged:v}=this,{ctrlKey:S,currentPagePoint:y}=this.editor.inputs;if(!v)throw Error("We should have a point where the segment changed");let b,P=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(P=!S,this.didJustShiftClickToExtendPreviousShapeLine=!1):P=!S;let C=this.editor.getPointInShapeSpace(a,y).toFixed().toJson(),I=!1,k;if((this.editor.user.getIsSnapMode()?!S:S)&&g.length>2){let M,D=8/this.editor.getZoomLevel();for(let j=0,O=l.length-2;j<O;j++){const R=l[j];if(!R)break;if(R.type==="free")continue;const B=R.points[0],L=Ht(R.points);if(!(B&&L))continue;const G=x.NearestPointOnLineSegment(B,L,C);if(x.DistMin(G,C,D)){M=G.toFixed().toJson(),D=x.Dist(G,C),k=R;break}}M&&(I=!0,C=M)}if(I&&k){const M=this.editor.getShapePageTransform(a),D=k.points[0],j=Ht(k.points);if(!j)throw Error("Expected a last point!");const O=q.applyToPoint(M,D),R=q.applyToPoint(M,j),B=q.applyToPoint(M,C);this.editor.snaps.setIndicators([{id:ze(),type:"points",points:[O,B,R]}])}else{if(this.editor.snaps.clearIndicators(),P){const M=x.Angle(v,y),j=Tf(M,24)-M;b=x.RotWith(y,v,j)}else b=y;C=this.editor.getPointInShapeSpace(a,b).toFixed().toJson()}this.currentLineLength+=x.Dist(m.points[0],C),g[g.length-1]={...m,type:"straight",points:[m.points[0],C]};const T={id:o,type:this.shapeType,props:{segments:g}};this.canClose()&&(T.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([T]);break}case"free":{const g=l.slice(),m=g[g.length-1],v=[...m.points];if(v.length&&this.mergeNextPoint){const{z:y}=v[v.length-1];v[v.length-1]={x:f.x,y:f.y,z:y?Math.max(y,f.z):f.z}}else this.currentLineLength+=x.Dist(v[v.length-1],f),v.push(f);g[g.length-1]={...m,points:v},this.currentLineLength<hn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(g));const S={id:o,type:this.shapeType,props:{segments:g}};if(this.canClose()&&(S.props.isClosed=this.getIsClosed(g,s,i)),this.editor.updateShapes([S]),v.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const y=Be(),b=this.editor.getShape(o).props;this.editor.createShapes([{id:y,type:this.shapeType,x:Qo(r.currentPagePoint.x),y:Qo(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=nt(this.editor.getShape(y)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(n){let r=0;for(const o of n)for(let s=0;s<o.points.length-1;s++){const i=o.points[s],a=o.points[s+1];r+=x.Dist2(a,i)}return Math.sqrt(r)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:n}=this;n&&(this.editor.updateShapes([{id:n.id,type:n.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}E(yb,"id","drawing");var MS;let O$=(MS=class extends ie{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(MS,"id","idle"),MS);class pp extends ie{constructor(){super(...arguments);E(this,"shapeType","draw")}static children(){return[O$,yb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}E(pp,"id","draw"),E(pp,"initial","idle"),E(pp,"isLockable",!1);class V0 extends E0{constructor(){super(...arguments);E(this,"shapeType","frame")}onCreate(n){if(!n)return;const r=this.editor.getShapePageBounds(n),o=[],s=this.editor.getShapeAncestors(n).map(i=>i.id);this.editor.getSortedChildIdsForParent(n.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===n.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&ele(a,s,n)&&o.push(a.id)}),this.editor.reparentShapes(o,n.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")}}E(V0,"id","frame"),E(V0,"initial","idle");function ele(t,e,n){return e.includes(t.id)?!1:t.parentId===n.parentId}var AS;let tle=(AS=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")}},E(AS,"id","idle"),AS);var jS;let nle=(jS=class extends ie{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=Be(),o=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`);this.editor.createShapes([{id:r,type:"geo",x:n.x,y:n.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(qr),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=Be();this.editor.markHistoryStoppingPoint(`creating_geo:${n}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,o=this.editor.getStyleForNextShape(qr),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(qr),scale:r,...s}}]);const i=this.editor.getShape(n);if(!i)return;const{w:a,h:l}=i.props,c=new x(a/2,l/2).mul(r),u=this.editor.getShapeParentTransform(i);u&&c.rot(-u.rotation()),this.editor.select(n),this.editor.updateShape({id:i.id,type:"geo",x:i.x-c.x,y:i.y-c.y,props:{geo:this.editor.getStyleForNextShape(qr),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},E(jS,"id","pointing"),jS);class Y0 extends ie{constructor(){super(...arguments);E(this,"shapeType","geo")}static children(){return[tle,nle]}}E(Y0,"id","geo"),E(Y0,"initial","idle");class fp extends ie{constructor(){super(...arguments);E(this,"shapeType","highlight")}static children(){return[O$,yb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}E(fp,"id","highlight"),E(fp,"initial","idle"),E(fp,"isLockable",!1);var OS;let rle=(OS=class extends ie{constructor(){super(...arguments);E(this,"shapeId","")}onEnter(n){this.shapeId=n.shapeId,this.editor.setCursor({type:"cross",rotation:0})}onPointerDown(){this.parent.transition("pointing",{shapeId:this.shapeId})}onCancel(){this.editor.setCurrentTool("select")}},E(OS,"id","idle"),OS);const dE=2;var DS;let ole=(DS=class extends ie{constructor(){super(...arguments);E(this,"shape",{});E(this,"markId")}onEnter(n){const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=n.shapeId&&this.editor.getShape(n.shapeId);if(s&&r.shiftKey){this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${s.id}`),this.shape=s;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(f=>f.type==="vertex").sort(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=nt(this.shape.props.points);if(x.DistMin(l,c,dE)||x.DistMin(h,l,dE))p[l.id]={id:l.id,index:l.index,x:h.x,y:h.y};else{const f=wo(l.index);p[f]={id:f,index:f,x:h.x,y:h.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:p}}])}else{const i=Be();this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${i}`),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(i),this.shape=this.editor.getShape(i)}}onPointerMove(){if(this.shape&&this.editor.inputs.isDragging){const n=this.editor.getShapeHandles(this.shape);if(!n)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Ht(n);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,creatingMarkId:this.markId,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators()}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}},E(DS,"id","pointing"),DS);class X0 extends ie{constructor(){super(...arguments);E(this,"shapeType","line")}static children(){return[rle,ole]}}E(X0,"id","line"),E(X0,"initial","idle");var RS;let sle=(RS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(RS,"id","idle"),RS);const ile=0,Ke=200,gm=new x(Ke/2,Ke/2),D$=10,ale=t=>[[["a1"],new x(Ke*.5,Ke*-.5-t.options.adjacentShapeMargin)],[["a2"],new x(Ke*1.5+t.options.adjacentShapeMargin,Ke*.5)],[["a3"],new x(Ke*.5,Ke*1.5+t.options.adjacentShapeMargin)],[["a4"],new x(Ke*-.5-t.options.adjacentShapeMargin,Ke*.5)]];function lle(t,e){if(e===1)return ale(t);const n=Ke*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 R$(t,e,n,r,o,s){return Object.fromEntries(lle(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 L$(t,e,n,r){const o=new Set(t.getSelectedShapeIds()),s=(Ke+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(R$(t,h.point(),e,u.props.growY,r,n))))}const l=a.length;let c;for(const[u,h]of i)for(let p=0;p<l;p++)c=a[p],c&&(x.Dist2(h,c)>s||t.isPointInShape(u,c)&&(a[p]=void 0));return ye(a)}function $$(t,e,n,r,o=!1){let s;const i=t.getCurrentPageShapesSorted(),a=(Ke+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=Be();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(gm.clone().mul(c.props.scale),r)));t.updateShape({id:l,type:"note",x:u.x,y:u.y}),s=t.getShape(l)}return E3(t),s}var LS;let cle=(LS=class extends ie{constructor(){super(...arguments);E(this,"dragged",!1);E(this,"info",{});E(this,"wasFocusedOnEnter",!1);E(this,"markId","");E(this,"shape",{})}onEnter(){const{editor:n}=this;if(this.wasFocusedOnEnter=!n.menus.hasAnyOpenMenus(),this.wasFocusedOnEnter){const r=Be();this.markId=n.markHistoryStoppingPoint(`creating_note:${r}`);const o=this.editor.inputs.originPagePoint.clone(),s=hE(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=pE(this.editor,r,o)}}onPointerMove(n){if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=Be(),o=this.editor.inputs.originPagePoint.clone(),s=hE(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=pE(this.editor,r,o)}this.editor.setCurrentTool("select.translating",{...n,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,creatingMarkId:this.markId,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}}onPointerUp(){this.complete()}onInterrupt(){this.cancel()}onComplete(){this.complete()}onCancel(){this.cancel()}complete(){this.wasFocusedOnEnter&&(this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):(this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape",{...this.info,target:"shape",shape:this.shape})))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}},E(LS,"id","pointing"),LS);function hE(t,e,n){let r=D$/t.getZoomLevel(),o;for(const s of L$(t,0,n,0)){const i=x.Sub(e,s),a=i.len();a<r&&(r=a,o=i)}return o}function pE(t,e,n){t.createShape({id:e,type:"note",x:n.x,y:n.y,props:{scale:t.user.getIsDynamicResizeMode()?1/t.getZoomLevel():1}}).select(e);const r=t.getShape(e),o=t.getShapeGeometry(r).bounds;return t.updateShapes([{id:e,type:"note",x:r.x-o.width/2,y:r.y-o.height/2}]),t.getShape(e)}class q0 extends ie{constructor(){super(...arguments);E(this,"shapeType","note")}static children(){return[sle,cle]}}E(q0,"id","note"),E(q0,"initial","idle");function ule(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 ns=uT(ule,32);var $S;let dle=($S=class extends ie{onPointerMove(e){switch(e.target){case"shape":case"canvas":ns(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){ns.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")}},E($S,"id","idle"),$S);var FS;let hle=(FS=class extends ie{constructor(){super(...arguments);E(this,"shape");E(this,"markId","");E(this,"enterTime",0)}onEnter(){this.enterTime=Date.now()}onExit(){this.editor.setHintingShapes([])}onPointerMove(n){if(Date.now()-this.enterTime<150)return;const{editor:r}=this,{isPointing:o}=r.inputs;if(!o)return;const{originPagePoint:s,currentPagePoint:i}=r.inputs,a=Math.abs(s.x-i.x),c=Math.sqrt(r.getInstanceState().isCoarsePointer?r.options.coarseDragDistanceSquared:r.options.dragDistanceSquared)*6/r.getZoomLevel();if(a>c){const u=Be();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=Be(),{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,$n(i.parentId)){const c=this.editor.getShapeParentTransform(i);l.rot(-c.rotation())}return this.editor.updateShape({...i,x:i.x+l.x,y:i.y+l.y}),i}},E(FS,"id","pointing"),FS);class Z0 extends ie{constructor(){super(...arguments);E(this,"shapeType","text")}static children(){return[dle,hle]}}E(Z0,"id","text"),E(Z0,"initial","idle");const ple=[Z0,pp,Y0,q0,X0,V0,G0,fp];function Fr(){return bs({isDarkMode:yd()})}function mm(t){return{key:`${To.id}:${t}`,async getElement(){const e=fle(t);if(!e)return null;const n=e.$$_url,r=e.$$_fontface;if(!n||!r)return null;const o=await(await no(n)).blob(),s=await os.blobToDataUrl(o),i=r.replace(n,s);return d.jsx("style",{children:i})}}}function fle(t){const e=eA[t];for(const n of document.fonts)if(e.includes(n.family))return n;return null}function Sb(t){return{key:`${To.id}:${t}`,async getElement(){return t!=="pattern"?null:d.jsx(gle,{})}}}function gle(){const t=Fr(),e=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:"hash_pattern_mask",children:[d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),d.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[d.jsx("line",{x1:e*1,y1:e*3,x2:e*3,y2:e*1}),d.jsx("line",{x1:e*5,y1:e*7,x2:e*7,y2:e*5}),d.jsx("line",{x1:e*9,y1:e*11,x2:e*11,y2:e*9})]})]}),d.jsx("pattern",{id:Vf(1,t.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:t.solid,mask:"url(#hash_pattern_mask)"})})]})}function vb(){return{key:`${To.id}:pattern`,component:vle}}const Wc=8,fE=(t,e,n)=>new Promise((r,o)=>{const s=Wc*e*t,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?bf.darkMode.solid:bf.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)})}),gE=(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 mS=null;function mle(){return mS||(mS={white:gE([1,1],t=>{t.fillStyle="#f8f9fa",t.fillRect(0,0,1,1)}),black:gE([1,1],t=>{t.fillStyle="#212529",t.fillRect(0,0,1,1)})}),mS}function F$(t){return Math.ceil(Math.log2(Math.max(1,t)))}function Vf(t,e){const n=F$(t);return`tldraw_hash_pattern_${e}_${n}`}function N$(t){const e=[],r=F$(t);for(let o=0;o<=r;o++)e.push(Math.pow(2,o));return e}function yle(t){const e=mle();return N$(t).flatMap(n=>[{zoom:n,url:e.white,theme:"light"},{zoom:n,url:e.black,theme:"dark"}])}function Sle(){const t=z(),e=H("devicePixelRatio",()=>t.getInstanceState().devicePixelRatio,[t]),n=H("maxZoom",()=>Math.ceil(Ht(t.getCameraOptions().zoomSteps)),[t]),[r,o]=w.useState(!1),[s,i]=w.useState(()=>yle(n));return w.useEffect(()=>{const l=Promise.all(N$(n).flatMap(u=>[fE(e,u,!1).then(h=>({zoom:u,theme:"light",url:URL.createObjectURL(h)})),fE(e,u,!0).then(h=>({zoom:u,theme:"dark",url:URL.createObjectURL(h)}))]));let c=!1;return l.then(u=>{c||(i(u),o(!0))}),()=>{c=!0,o(!1),l.then(u=>{for(const{url:h}of u)URL.revokeObjectURL(h)})}},[e,n]),{defs:d.jsx(d.Fragment,{children:s.map(l=>{const c=Vf(l.zoom,l.theme);return d.jsx("pattern",{id:c,width:Wc,height:Wc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:l.url,width:Wc,height:Wc})},c)})}),isReady:r}}function vle(){const t=z(),e=w.useRef(null),{defs:n,isReady:r}=Sle();return w.useEffect(()=>{if(r&&Ge.isSafari){const o=z$(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 z$(t){return t.classList.contains("tl-html-layer")?t:t.parentElement?z$(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(xle,{theme:e,color:r,fill:o,d:n,scale:s})}});function xle({d:t,color:e,theme:n}){const r=z(),o=pd(),s=H("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:n[e].pattern,d:t}),d.jsx("path",{fill:o?`url(#${Vf(1,n.id)})`:i?n[e].semi:`url(#${Vf(s,n.id)})`,d:t})]})}function wle(t){return t.replace(/\s/g," ")}function Q0(t,e,n){const{padding:r=0}=n;if(e.length===0)return null;const o=Z.From(e[0].box);for(const{box:c}of e)o.union(c);const s=r+(n.offsetX??0),i=(n.offsetY??0)+n.fontSize/2+(n.verticalTextAlign==="start"?r:n.verticalTextAlign==="end"?n.height-r-o.height:(Math.ceil(n.height)-o.height)/2);let a=null;const l=[];for(const{text:c,box:u}of e)a!==null&&u.y>a&&l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
|
|
370
|
-
`},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,unicodeBidi:"plaintext",children:wle(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 ble(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 Ple(t){return t==="start-legacy"||t==="middle-legacy"||t==="end-legacy"}function ym({fontSize:t,font:e,align:n,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:l=!0}){const c=z(),u=Fr(),h={fontSize:t,fontFamily:eA[e],textAlign:n,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:pn.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=ble(n,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const g=Q0(c,p,h);let m=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,m=Q0(c,p,h)),d.jsxs(d.Fragment,{children:[m,g]})}const Cle=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:Et,onContextMenu:e?Et:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:xe})});function _le(t,e,n){const r=z(),o=w.useRef(null),s=H("isEditing",()=>r.getEditingShapeId()===t,[r]),i=H("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);w.useEffect(()=>{function u({shapeId:h}){var p;h===t&&((p=o.current)==null||p.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,t,s]),w.useEffect(()=>{var u,h,p,f;s&&(document.activeElement!==o.current&&((u=o.current)==null||u.focus()),r.getInstanceState().isCoarsePointer&&((h=o.current)==null||h.select()),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=jl.normalizeText(u.currentTarget.value);const p=h.replace(/\t/g,al);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({...Kn(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(t)}),Et(u)},[r,t]);return{rInput:o,handleFocus:Mu,handleBlur:Mu,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:Et,isEmpty:n.trim().length===0,isEditing:s,isEditingAnything:i}}const Sm=Te.memo(function({id:e,type:n,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:f,classNamePrefix:g,style:m,textWidth:v,textHeight:S}){const{rInput:y,isEmpty:b,isEditing:P,isEditingAnything:C,...I}=_le(e,n,r),[k,_]=w.useState(r);w.useEffect(()=>{P||_(r)},[P,r]);const T=jl.normalizeTextForDom(r),M=T.length>0,D=Ple(l);if(!P&&!M)return null;const j=g||"tl-text";return d.jsx("div",{className:`${j}-label tl-text-wrapper`,"data-font":s,"data-align":l,"data-hastext":!b,"data-isediting":P,"data-iseditinganything":C,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||D?"center":l,alignItems:c==="middle"?"center":c,padding:p,...m},children:d.jsxs("div",{className:`${j}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(v||0),color:o,width:v?Math.ceil(v):void 0,height:S?Math.ceil(S):void 0},children:[d.jsx("div",{className:`${j} tl-text tl-text-content`,dir:"auto",children:T.split(`
|
|
371
|
-
`).map((O,R)=>d.jsx("div",{dir:"auto",children:O},R))}),(C||h)&&d.jsx(Cle,{ref:y,text:r,isEditing:P,...I,handleKeyDown:f??I.handleKeyDown},k)]})})}),Ile=new ko;function Ele(t){return Ile.get(t,()=>t.store.createComputedCache("arrowLabelSize",e=>{const n=Po(t,e);let r=0,o=0;const s=n.isStraight?new ts({start:x.From(n.start.point),end:x.From(n.end.point)}):new rl({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=J0(e),{w:l,h:c}=t.textMeasure.measureText(e.props.text,{...pn,fontFamily:Ss[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,{...pn,fontFamily:Ss[e.props.font],fontSize:a,maxWidth:r});r=h,o=p}}return new x(r,o).addScalar(Gf*2*e.props.scale)}))}function xb(t,e){return e.props.text.trim()===""?new x(0,0).addScalar(Gf*2*e.props.scale):Ele(t).get(e.id)??new x(0,0)}function B$(t){const e=hn[t.props.size];return(Bae+(e-hn.s)*2+(e===hn.xl?20:0))*t.props.scale}function kle(t,e,n){const r=xb(t,e),o=B$(e),s=x.Nudge(n.start.point,n.end.point,o),i=x.Nudge(n.end.point,n.start.point,o),a=d1(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 Tle(t,e,n){const r=xb(t,e),o=B$(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=ia(n.bodyArc.center,n.bodyArc.radius,a),u=ia(n.bodyArc.center,n.bodyArc.radius,l),h=[],p=yE(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=yE(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 k of[...p??[],...f??[],c,u])h.push(new _1({x:k.x-3,y:k.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const g=(p&&SE(n.start.point,p))??n.middle,m=(f&&SE(n.end.point,f))??n.middle,v=x.Angle(n.bodyArc.center,n.start.point),S=x.Angle(n.bodyArc.center,n.end.point),y=x.Angle(n.bodyArc.center,g),b=x.Angle(n.bodyArc.center,m);if(Bs(v,y,s)>Bs(v,b,s))return{start:.5,end:.5,dbg:h};const P=Bs(v,S,s),C=Bs(v,y,s)/P,I=Bs(v,b,s)/P;return{start:C,end:I,dbg:h}}function gp(t,e){let n;const r=[],o=Po(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=kle(t,e,o),l=mE(t,e,a,s);n=x.Lrp(o.start.point,o.end.point,l)}else{const a=Tle(t,e,o);a.dbg&&r.push(...a.dbg);const l=mE(t,e,a,s),c=Mle(x.Angle(o.bodyArc.center,o.start.point),x.Angle(o.bodyArc.center,o.end.point),Math.sign(e.props.bend),l);n=ia(o.bodyArc.center,o.bodyArc.radius,c)}const i=xb(t,e);return{box:Z.FromCenter(n,i),debugGeom:r}}function mE(t,e,n,r){const{hasEndArrowhead:o,hasEndBinding:s,hasStartBinding:i,hasStartArrowhead:a}=r,l=W$(t,e);let c=Bt(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 yE(t,e,n,r,o,s){const i=y0(t,e,s),a=Bs(n,r,o);return i==null?void 0:i.filter(l=>{const c=Bs(n,x.Angle(t,l),o);return c>=0&&c<=a})}function SE(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 Mle(t,e,n,r){const o=Bs(t,e,n);return t+o*r*n*-1}function J0(t){return zae[t.props.size]*t.props.scale}function Ale(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=SZ(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 jle({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 Ole({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 Dle({point:t,int:e}){const n=x.Sub(e,t).div(2),r=x.Add(t,x.Rot(n,Ze)),o=x.Sub(t,x.Rot(n,Ze));return`M ${r.x} ${r.y} L ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function Rle({point:t,int:e}){const n=x.Lrp(t,e,.45),r=x.Dist(n,t);return`M ${n.x-r},${n.y}
|
|
372
|
-
a ${r},${r} 0 1,0 ${r*2},0
|
|
373
|
-
a ${r},${r} 0 1,0 -${r*2},0 `}function Lle({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 $le({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,Ze)),s=x.Sub(e,x.Rot(r,Ze)),i=x.Add(n,x.Rot(r,Ze)),a=x.Sub(n,x.Rot(r,Ze));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function Fle({int:t,point:e}){const n=x.Sub(t,e).div(2),r=x.Add(e,x.Rot(n,Ze)),o=x.Sub(e,x.Rot(n,Ze));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function Yf(t,e,n){const r=e==="end"?t.end.arrowhead:t.start.arrowhead;if(r==="none")return;const o=Ale(t,e,n);if(o){switch(r){case"bar":return Fle(o);case"square":return $le(o);case"diamond":return Lle(o);case"dot":return Rle(o);case"inverted":return Dle(o);case"arrow":return jle(o);case"triangle":return Ole(o)}return""}}function Nle(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 U$(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 H$(t,e){return`M${t.x},${t.y}L${e.x},${e.y}`}function zle(t){return H$(t.start.handle,t.end.handle)}function K$(t){return H$(t.start.point,t.end.point)}class mp extends eo{constructor(){super(...arguments);E(this,"_resizeInitialBindings",new ko)}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=zn(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=Po(this.editor,n),o=[],s=r.isStraight?new ts({start:x.From(r.start.point),end:x.From(r.end.point)}):new rl({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=gp(this.editor,n);o.push(...a.debugGeom),i=new gs({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new ro({children:[...i?[s,i]:[s],...o]})}getHandles(n){const r=Po(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=zn(this.editor,n);if(s==="middle"){const{start:I,end:k}=sl(this.editor,n,i),_=x.Sub(k,I),T=x.Per(_),M=x.Med(k,I),D=x.Sub(M,T),j=x.Add(M,T),O=x.NearestPointOnLineSegment(D,j,r,!1);let R=x.Dist(O,M);return x.Clockwise(O,k,M)&&(R*=-1),{id:n.id,type:n.type,props:{bend:R}}}const a={id:n.id,type:"arrow",props:{}},l=i[s],u=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return dp(this.editor,n,s),a.props[s]={x:r.x,y:r.y},a;const h=this.editor.getShapePageTransform(n.id).applyToPoint(r),p=this.editor.getShapeAtPoint(h,{hitInside:!0,hitFrameInside:!0,margin:0,filter:I=>!I.isLocked&&this.editor.canBindShapes({fromShape:n,toShape:I,binding:"arrow"})});if(!p)return dp(this.editor,n,s),a.props[s]={x:r.x,y:r.y},a;const f=this.editor.getShapeGeometry(p),g=Z.ZeroFix(f.bounds),v=this.editor.getShapePageTransform(a.id).applyToPoint(r),S=this.editor.getPointInShapeSpace(p,v);let y=o;y||(!l||l&&p.id!==l.toId)&&(y=this.editor.inputs.pointerVelocity.len()<.5),o||(f.isClosed||(y=!0),u&&p.id===u.toId&&u.props.isPrecise&&(y=!0));const b={x:(S.x-g.minX)/g.width,y:(S.y-g.minY)/g.height};y&&x.Dist(S,g.center)<Math.max(4,Math.min(Math.min(g.width,g.height)*.15,16))/this.editor.getZoomLevel()&&(b.x=.5,b.y=.5);const P={terminal:s,normalizedAnchor:b,isPrecise:y,isExact:this.editor.inputs.altKey};Tc(this.editor,n,p.id,P),this.editor.setHintingShapes([p.id]);const C=zn(this.editor,n);return C.start&&C.end&&C.start.toId===C.end.toId&&x.Equals(C.start.props.normalizedAnchor,C.end.props.normalizedAnchor)&&Tc(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=zn(this.editor,n),o=sl(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)))){xE.set(n,{pagePosition:s.applyToPoint(n),terminalBindings:Ju(o,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:s.applyToPoint(l)}:null})}),r.start&&(Wf({editor:this.editor,arrow:n,terminal:"start",useHandle:!0}),n=this.editor.getShape(n.id)),r.end&&Wf({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=xE.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};Tc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else dp(this.editor,r,a.binding.props.terminal)}}onResize(n,r){const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(n,()=>zn(this.editor,n)),a=sl(this.editor,n,i),{start:l,end:c}=nt(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&&Tc(this.editor,n,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&g&&Tc(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=Fr(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),i=Po(this.editor,n);if(!(i!=null&&i.isValid))return null;const a=gp(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(ui,{id:n.id,style:{minWidth:50,minHeight:50},children:d.jsx(vE,{shape:n,shouldDisplayHandles:s&&(o==null?void 0:o.id)===n.id})}),u&&d.jsx(Sm,{id:n.id,classNamePrefix:"tl-arrow",type:"arrow",font:n.props.font,fontSize:J0(n),lineHeight:pn.lineHeight,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:r[n.props.labelColor].solid,textWidth:a.box.w-Gf*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=Wg(n.id),o=Po(this.editor,n);if(!o)return null;const{start:s,end:i}=sl(this.editor,n,o==null?void 0:o.bindings),a=this.editor.getShapeGeometry(n),l=a.bounds,c=n.props.text.trim()?a.children[1]:null;if(x.Equals(s,i))return null;const u=hn[n.props.size]*n.props.scale,h=o.start.arrowhead&&Yf(o,"start",u),p=o.end.arrowhead&&Yf(o,"end",u),f=o.isStraight?K$(o):U$(o),g=h&&o.start.arrowhead!=="arrow"||p&&o.end.arrowhead!=="arrow"||!!c,m=Xl(n.id+"_clip");if(r&&c)return d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5*n.props.scale,ry:3.5*n.props.scale});const v=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),S=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow");return d.jsxs("g",{children:[g&&d.jsx("defs",{children:d.jsx(G$,{hasText:n.props.text.trim().length>0,bounds:l,labelBounds:c?c.getBounds():new Z(0,0,0,0),as:v&&h?h:"",ae:S&&p?p:""})}),d.jsxs("g",{style:{clipPath:g?`url(#${m})`:void 0,WebkitClipPath:g?`url(#${m})`:void 0},children:[g&&d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.width+200,height:l.height+200,opacity:0}),d.jsx("path",{d:f})]}),h&&d.jsx("path",{d:h}),p&&d.jsx("path",{d:p}),c&&d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5,ry:3.5})]})}onEditEnd(n){const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])}toSvg(n,r){r.addExportDef(Sb(n.props.fill)),n.props.text&&r.addExportDef(mm(n.props.font));const o=bs(r),s=1/n.props.scale;return d.jsxs("g",{transform:`scale(${s})`,children:[d.jsx(vE,{shape:n,shouldDisplayHandles:!1}),d.jsx(ym,{fontSize:J0(n),font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:o[n.props.labelColor].solid,bounds:gp(this.editor,n).box.clone().expandBy(-Gf*n.props.scale),padding:0})]})}getCanvasSvgDefs(){return[vb(),{key:"arrow:dot",component:Ble},{key:"arrow:cross",component:Ule}]}getInterpolatedProps(n,r,o){return{...o>.5?r.props:n.props,scale:Ie(n.props.scale,r.props.scale,o),start:{x:Ie(n.props.start.x,r.props.start.x,o),y:Ie(n.props.start.y,r.props.start.y,o)},end:{x:Ie(n.props.end.x,r.props.end.x,o),y:Ie(n.props.end.y,r.props.end.y,o)},bend:Ie(n.props.bend,r.props.bend,o),labelPosition:Ie(n.props.labelPosition,r.props.labelPosition,o)}}}E(mp,"type","arrow"),E(mp,"props",nA),E(mp,"migrations",rA);function W$(t,e){const n=Po(t,e);return n.isStraight?x.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const vE=$t(function({shape:e,shouldDisplayHandles:n}){const r=z(),o=Fr(),s=Po(r,e),i=Z.ZeroFix(r.getShapeGeometry(e).bounds),a=zn(r,e),l=H("force solid",()=>r.getZoomLevel()<.2,[r]);if(!(s!=null&&s.isValid))return null;const c=hn[e.props.size]*e.props.scale,u=s.start.arrowhead&&Yf(s,"start",c),h=s.end.arrowhead&&Yf(s,"end",c),p=s.isStraight?K$(s):U$(s);let f=null;if(n){const P=2/r.getZoomLevel(),{strokeDasharray:C,strokeDashoffset:I}=Yr(W$(r,e),P,{end:"skip",start:"skip",lengthRatio:2.5});f=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?zle(s):Nle(s),strokeDasharray:C,strokeDashoffset:I,strokeWidth:P,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:g,strokeDashoffset:m}=Yr(s.isStraight?s.length:Math.abs(s.bodyArc.length),c,{style:e.props.dash,forceSolid:l}),v=gp(r,e),S=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),y=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),b=Xl(e.id+"_clip");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:b,children:d.jsx(G$,{hasText:e.props.text.trim().length>0,bounds:i,labelBounds:v.box,as:S&&u?u:"",ae:y&&h?h:""})})}),d.jsxs("g",{fill:"none",stroke:o[e.props.color].solid,strokeWidth:c,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[f,d.jsxs("g",{style:{clipPath:`url(#${b})`,WebkitClipPath:`url(#${b})`},children:[d.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),d.jsx("path",{d:p,strokeDasharray:g,strokeDashoffset:m})]}),u&&S&&e.props.fill!=="none"&&d.jsx(on,{theme:o,d:u,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),h&&y&&e.props.fill!=="none"&&d.jsx(on,{theme:o,d:h,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),u&&d.jsx("path",{d:u}),h&&d.jsx("path",{d:h})]})]})});function G$({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 xE=new WeakMap;function Ble(){return d.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:d.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function Ule(){return d.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[d.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),d.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const wE="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 Ol({url:t,zoomLevel:e}){return d.jsx("a",{className:le("tl-hyperlink-button",{"tl-hyperlink-button__hidden":e<.32}),href:t,target:"_blank",rel:"noopener noreferrer",onPointerDown:Et,onPointerUp:Et,title:t,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${wE}") center 100% / 100% no-repeat`,WebkitMask:`url("${wE}") center 100% / 100% no-repeat`}})})}const bE="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",Hle=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function Xf(t){return Hle.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 Kle=300,V$=320,Wle=46,Gle=101;class yp extends Jl{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:Kle,h:V$,assetId:null}}component(e){return d.jsx(Vle,{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 PE(this.editor,e)}onBeforeUpdate(e,n){if(e.props.url!==n.props.url)if(gr.isValid(n.props.url))Xle(this.editor,n);else return{...n,props:{...n.props,url:e.props.url}};if(e.props.assetId!==n.props.assetId)return PE(this.editor,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:Ie(e.props.w,n.props.w,r),h:Ie(e.props.h,n.props.h,r)}}}E(yp,"type","bookmark"),E(yp,"props",cA),E(yp,"migrations",uA);function Vle({shape:t,util:e}){const n=t.props.assetId?e.editor.getAsset(t.props.assetId):null,r=!!pd()&&Ge.isSafari,o=e.editor.getShapePageTransform(t).rotation(),s=Yle(t),[i,a]=w.useState(!0),l=()=>a(!1);return d.jsx(si,{children:d.jsxs("div",{className:le("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:Xf(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(Ol,{url:t.props.url,zoomLevel:e.editor.getZoomLevel()})]}),d.jsxs("div",{className:"tl-bookmark__copy_container",children:[n!=null&&n.props.title?d.jsx("h2",{className:"tl-bookmark__heading",children:Vae(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:Et,onPointerUp:Et,onClick:Et,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("${bE}") center 100% / 100% no-repeat`,WebkitMask:`url("${bE}") center 100% / 100% no-repeat`}}),d.jsx("span",{children:s})]})]})]})})}function PE(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):null;let r=V$;return n&&(n.props.image||(n.props.title?r=Gle:r=Wle)),{...e,props:{...e.props,h:r}}}const Yle=t=>{try{return new URL(t.props.url).hostname.replace(/^www\./,"")}catch{return t.props.url}};function Xle(t,e){const{url:n}=e.props,r=zs.createId(zv(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}}]),qle(t,e))}const qle=fw(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 pa(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+=Nn(r,o);return e?`M${Nn(t[0].point,t[1].point)}Q${je(t[1].point)}${Nn(t[1].point,t[2].point)}T${s}${Nn(t[n-1].point,t[0].point)}${Nn(t[0].point,t[1].point)}Z`:`M${je(t[0].point)}Q${je(t[1].point)}${Nn(t[1].point,t[2].point)}${t.length>3?"T":""}${s}L${je(t[n-1].point)}`}function Zle(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=Oo(t,e);fm(i,e);const a=Qle(i);let l="";for(const c of a)l+=ece(c,e);return l}function Qle(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(yS(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(yS(n)),n=[a];continue}}return n.push(t[t.length-1]),e.push(yS(n)),e}function yS(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 Jle(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 ece(t,e={}){if(t.length===0)return"";if(t.length===1)return Jle(t[0].point.x,t[0].point.y,t[0].radius);const{left:n,right:r}=E$(t,e);r.reverse();let o=`M${je(n[0])}T`;for(let s=1;s<n.length;s++)o+=Nn(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+=Nn(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 Y$=(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=Ie(c.z,a[u].z,n)),{x:Ie(c.x,a[u].x,n),y:Ie(c.y,a[u].y,n),z:h}})}]},tce=t=>t*.65+NY(t*De/2)*.35,nce=t=>({size:t,thinning:.5,streamline:kl(t,[9,16],[.64,.74],!0),smoothing:.62,easing:Dt.easeOutSine,simulatePressure:!0}),rce=t=>({size:1+t*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:tce}),CE=t=>({size:t,thinning:0,streamline:kl(t,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:Dt.linear}),oce=t=>({size:t,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Dt.linear});function wb({strokeWidth:t,showAsComplete:e}){return{size:1+t,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:Dt.easeOutSine,last:e}}function ex(t,e,n,r){const o=t.isComplete||n;return r?t.isPen?{...oce(e),last:o}:{...CE(e),last:o}:t.dash==="draw"?t.isPen?{...rce(e),last:o}:{...nce(e),last:o}:{...CE(e),last:o}}function Dl(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 sce(t,e,n){return{draw:"none",solid:"none",dotted:`${n} ${e*2}`,dashed:`${e*2} ${e*2}`}[t.props.dash]}class Sp extends eo{hideResizeHandles(e){return SS(e)}hideRotateHandle(e){return SS(e)}hideSelectionBoundsFg(e){return SS(e)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(e){const n=Dl(e.props.segments),r=(hn[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 _1({x:-r,y:-r,radius:r,isFilled:!0})}const o=Oo(n,ex(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 ql({points:o})}component(e){return d.jsx(ui,{id:e.id,children:d.jsx(_E,{shape:e})})}indicator(e){var u;const n=Dl(e.props.segments);let r=(hn[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+=io(e.id)()*(r/6));const i=e.props.isComplete||((u=Ht(e.props.segments))==null?void 0:u.type)==="straight",a=ex(e.props,r,i,!0),l=Oo(n,a),c=l.length>1?pa(l,e.props.isClosed):X$(n[0],r);return d.jsx("path",{d:c})}toSvg(e,n){n.addExportDef(Sb(e.props.fill));const r=1/e.props.scale;return d.jsx("g",{transform:`scale(${r})`,children:d.jsx(_E,{shape:e,zoomOverride:1})})}getCanvasSvgDefs(){return[vb()]}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:Qo(r*a),y:Qo(o*l),z:c}))});return{props:{segments:s}}}expandSelectionOutlinePx(e){const n=e.props.dash==="draw"?1.6:1;return hn[e.props.size]*n/2*e.props.scale}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,segments:Y$(e.props.segments,n.props.segments,r),scale:Ie(e.props.scale,n.props.scale,r)}}}E(Sp,"type","draw"),E(Sp,"props",hA),E(Sp,"migrations",pA);function X$(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 SS(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function _E({shape:t,zoomOverride:e}){var f;const n=Fr(),r=z(),o=Dl(t.props.segments),s=t.props.isComplete||((f=Ht(t.props.segments))==null?void 0:f.type)==="straight";let i=(hn[t.props.size]+1)*t.props.scale;const a=H("force solid",()=>{const g=e??r.getZoomLevel();return g<.5&&g<1.5/i},[r,i,e]),l=H("dot adjustment",()=>(e??r.getZoomLevel())<.2?0:.1,[r,e]);!a&&!t.props.isPen&&t.props.dash==="draw"&&o.length===1&&(i+=io(t.id)()*(i/6));const c=ex(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:pa(Oo(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:Zle(o,c),strokeLinecap:"round",fill:n[t.props.color].solid})]});const u=Oo(o,c),h=u.length<2,p=h?X$(o[0],0):pa(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":sce(t,i,l),strokeDashoffset:"0"})]})}function ice(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function ace(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(q$(o.hostnames,r)){const s=o.fromEmbedUrl(e);if(s)return{definition:o,url:s,embedUrl:e}}}const lce=t=>t.split("*").map(e=>ice(e)).join(".+"),q$=(t,e)=>!!t.find(n=>{const r=new RegExp(lce(n));return e.match(r)});function cce(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(q$(o.hostnames,r)){const s=o.toEmbedUrl(e);if(s)return{definition:o,embedUrl:s,url:e}}}function uce(t,e){try{return cce(t,e)??ace(t,e)}catch{return}}const dce=t=>Object.entries(t).filter(([e,n])=>n).map(([e])=>e).join(" ");class vp extends Jl{constructor(){super(...arguments);E(this,"embedDefinitions",z1)}setEmbedDefinitions(n){this.embedDefinitions=n}getEmbedDefinitions(){return this.embedDefinitions}getEmbedDefinition(n){return uce(this.embedDefinitions,n)}getText(n){return n.props.url}hideSelectionBoundsFg(n){return!this.canResize(n)}canEdit(){return!0}canResize(n){var r,o;return!!((o=(r=this.getEmbedDefinition(n.props.url))==null?void 0:r.definition)!=null&&o.doesResize)}canEditInReadOnly(){return!0}getDefaultProps(){return{w:300,h:300,url:""}}isAspectRatioLocked(n){const r=this.getEmbedDefinition(n.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1}onResize(n,r){const o=this.isAspectRatioLocked(n),s=this.getEmbedDefinition(n.props.url);let i=(s==null?void 0:s.definition.minWidth)??200,a=(s==null?void 0:s.definition.minHeight)??200;if(o){const l=n.props.w/n.props.h;l>1?i*=l:a/=l}return Kg(n,r,{minWidth:i,minHeight:a})}component(n){const r=pd(),{w:o,h:s,url:i}=n.props,a=Wg(n.id),l=this.getEmbedDefinition(i),c=H("is hovering",()=>{const{editingShapeId:g,hoveredShapeId:m}=this.editor.getCurrentPageState();if(g&&m!==g){const v=this.editor.getShape(g);if(v&&this.editor.isShapeOfType(v,"embed"))return!0}return!1},[]),u=this.editor.getShapePageTransform(n).rotation();if(r)return d.jsx(si,{className:"tl-embed-container",id:n.id,children:d.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:Xf(u),borderRadius:(l==null?void 0:l.definition.overrideOutlineRadius)??8,background:(l==null?void 0:l.definition.backgroundColor)??"var(--color-background)",width:o,height:s}})});const h=a||c;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(l==null?void 0:l.definition.type)==="tldraw")return null;if((l==null?void 0:l.definition.type)==="github_gist"){const g=l.url.split("/").pop();if(!g)throw Error("No gist id!");return d.jsx(si,{className:"tl-embed-container",id:n.id,children:d.jsx(hce,{id:g,width:N(o),height:N(s),isInteractive:h,pageRotation:u})})}const f=dce({...bre,...(l==null?void 0:l.definition.overridePermissions)??{}});return d.jsx(si,{className:"tl-embed-container",id:n.id,children:l!=null&&l.definition?d.jsx("iframe",{className:"tl-embed",sandbox:f,src:l.embedUrl,width:N(o),height:N(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:h?"auto":"none",zIndex:h?"":"-1",boxShadow:Xf(u),borderRadius:(l==null?void 0:l.definition.overrideOutlineRadius)??8,background:l==null?void 0:l.definition.backgroundColor}}):null})}indicator(n){const r=this.getEmbedDefinition(n.props.url);return d.jsx("rect",{width:N(n.props.w),height:N(n.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}getInterpolatedProps(n,r,o){return{...o>.5?r.props:n.props,w:Ie(n.props.w,r.props.w,o),h:Ie(n.props.h,r.props.h,o)}}}E(vp,"type","embed"),E(vp,"props",fA),E(vp,"migrations",gA);function hce({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:Xf(i)},srcDoc:`
|
|
374
|
-
<html>
|
|
375
|
-
<head>
|
|
376
|
-
<base target="_blank">
|
|
377
|
-
</head>
|
|
378
|
-
<body>
|
|
379
|
-
<script src=${`https://gist.github.com/${t}.js${e?`?file=${e}`:""}`}><\/script>
|
|
380
|
-
<style type="text/css">
|
|
381
|
-
* { margin: 0px; }
|
|
382
|
-
table { height: 100%; background-color: red; }
|
|
383
|
-
.gist { background-color: none; height: 100%; }
|
|
384
|
-
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
385
|
-
</style>
|
|
386
|
-
</body>
|
|
387
|
-
</html>`})}const pce=w.forwardRef(({id:t,name:e,isEditing:n},r)=>{const o=z(),s=w.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Et(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}),Z$(e,"Frame")+""]})}),fce=function({id:e,name:n,width:r,height:o}){const s=z(),i=H("shape rotation",()=>oi(s.getShapePageTransform(e).rotation()),[s,e]),a=Wg(e),l=w.useRef(null),c=w.useCallback(g=>{const m=Kn(g);g.preventDefault(),s.getEditingShapeId()!==e&&s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(e),...m})},[s,e]);w.useEffect(()=>{const g=l.current;g&&a&&(g.focus(),g.select())},[l,a]);const h=((i+Math.PI/4)*(2/Math.PI)+4)%4,p=["top","left","bottom","right"][Math.floor(h)];let f;switch(p){case"top":f="";break;case"right":f=`translate(${N(r)}px, 0px) rotate(90deg)`;break;case"bottom":f=`translate(${N(r)}px, ${N(o)}px) rotate(180deg)`;break;case"left":f=`translate(0px, ${N(o)}px) rotate(270deg)`;break}return d.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(p==="top"||p==="bottom"?r:o)}px + var(--space-5))`,bottom:"100%",transform:`${f} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:c,children:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(pce,{ref:l,id:e,name:n,isEditing:a})})})};function Z$(t,e){return t.match(/^\s*$/)?e:t}class xp extends Jl{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){return new gs({width:e.props.w,height:e.props.h,isFilled:!1})}getText(e){return e.props.name}component(e){const n=this.editor.getShapeGeometry(e).bounds,r=Fr(),o=H("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(ui,{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(fce,{id:e.id,name:e.props.name,width:n.width,height:n.height})]})}toSvg(e,n){const r=bs({isDarkMode:n.isDarkMode}),i=((oi(this.editor.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,a=Math.floor(i);let l;switch(a){case 0:l="";break;case 3:l=`translate(${N(e.props.w)}, 0) rotate(90)`;break;case 2:l=`translate(${N(e.props.w)}, ${N(e.props.h)}) rotate(180)`;break;case 1:l=`translate(0, ${N(e.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}const c={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:e.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",fill:r.text},u=this.editor.textMeasure.measureTextSpans(Z$(e.props.name,"Frame")+"",c),h=u[0],p=Ht(u),f=p.box.w+p.box.x-h.box.x,g=Q0(this.editor,u,{offsetY:-c.height-2,...c});return d.jsxs(d.Fragment,{children:[d.jsx("rect",{width:e.props.w,height:e.props.h,fill:r.solid,stroke:r.black.solid,strokeWidth:1,rx:1,ry:1}),d.jsxs("g",{transform:l,children:[d.jsx("rect",{x:-8,y:-c.height-4,width:f+16,height:c.height,fill:r.background,rx:4,ry:4}),g]})]})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx("rect",{width:N(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 Kg(e,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:Ie(e.props.w,n.props.w,r),h:Ie(e.props.h,n.props.h,r)}}}E(xp,"type","frame"),E(xp,"props",mA),E(xp,"migrations",yA);function IE(t,e){return t>e?(De*(e/2)+(t-e))*2:(De*(t/2)+(e-t))*2}function Q$(t,e){return bb(t,e).map((n,r)=>n.getSvgPathData(r===0)).join(" ")+" Z"}function gce(t,e,n,r){const o=t/4,s=e/4,i=io(r),a=n*.75,l=y=>y.addXY(i()*a,i()*a),c=new x(t/2,e),u=new x(0,s*1.2),h=new x(t/2,s*.9),p=new x(t,s*1.2),f=l(new x(t/2,e)),g=l(new x(0,s*1.2)),m=l(new x(t/2,s*.9)),v=l(new x(t,s*1.2));return[new 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((y,b)=>y.getSvgPathData(b===0)).join(" ")+" Z"}function bb(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 mce(t){return{size:1+t,thinning:.25,end:{taper:t},start:{taper:t},streamline:0,smoothing:1,simulatePressure:!1}}function yce(t,e,n,r){const o=io(t),s=e/2,i=n/2,a=LA(s,i),l=[],c=Ne*o(),u=Ne+Ze/2+Math.abs(o())*Ze,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 Oo(l,mce(r))}function Sce(t,e,n,r){return pa(yce(t,e,n,r))}function tx(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 nx(t,e,n,r,o){const s=[],i=io(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 vce(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(ia(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 xce={s:50,m:70,l:100,xl:130},wce=.2;function vm(t,e,n,r,o){const s=io(n),i=IE(t,e),a=Math.max(Math.ceil(i/xce[r]),6,Math.ceil(i/Math.min(t,e))),l=i/a*wce,c=Math.max(t-l*2,1),u=Math.max(e-l*2,1),p=IE(c,u)/a,f=(t-c)/2,g=(e-u)/2,m=vce(c,u,a).map(P=>P.addXY(f,g)),v=t<20?0:l*.3,S=e<20?0:l*.3,y=m.slice(0);for(let P=0;P<Math.floor(a/2);P++)y[P]=x.AddXY(y[P],s()*v*o,s()*S*o),y[a-P-1]=x.AddXY(y[a-P-1],s()*v*o,s()*S*o);const b=[];for(let P=0;P<y.length;P++){const C=P===y.length-1?0:P+1,I=y[P],k=y[C],_=m[P],T=m[C],M=x.Dist(_,T),D=p-M,O=x.Dist(I,k)/M,R=(Math.max(f,g)+D)*O,B=x.Lrp(_,T,.5).add(x.Sub(T,_).uni().per().mul(R));B.x<0?B.x=0:B.x>t&&(B.x=t),B.y<0?B.y=0:B.y>e&&(B.y=e);const L=r1(I,k,B),G=x.Dist(L||x.Average([I,k]),I);b.push({leftPoint:I,rightPoint:k,arcPoint:B,center:L,radius:G})}return b}function bce(t,e,n,r,o){const s=[],i=vm(t,e,n,r,o);for(const{center:a,radius:l,leftPoint:c,rightPoint:u}of i)s.push(...HY(c,u,a,l,10));return s}function rx(t,e,n,r,o){const s=vm(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 Pce={s:.5,m:.7,l:.9,xl:1.6};function Cce(t,e,n,r,o){const s=io(n),i=Pce[r]*o,a=vm(t,e,n,r,o),u=a.reduce((g,m)=>g+x.Dist2(m.leftPoint,m.rightPoint),0)/a.length>(i*15)**2?g=>x.AddXY(g,s()*i*2,s()*i*2):g=>g;let h=`M${a[0].leftPoint.toFixed()}`,p=u(a[0].leftPoint),f=`M${p.toFixed()}`;for(const{leftPoint:g,center:m,rightPoint:v,radius:S,arcPoint:y}of a){if(m===null){h+=` L${v.toFixed()}`;const _=u(v);f+=` L${_.toFixed()}`,p=_;continue}const b=x.Clockwise(g,v,m)?"0":"1";h+=` A${N(S)},${N(S)} 0 ${b},1 ${v.toFixed()}`;const P=u(v),C=u(y),I=r1(p,P,C);if(!I){f+=` L${P.toFixed()}`,p=P;continue}const k=Math.abs(x.Dist(I,p));f+=` A${N(k)},${N(k)} 0 ${b},1 ${P.toFixed()}`,p=P}return h+f+" Z"}function ox(t,e){switch(t.geo){case"x-box":return _ce(t.w,t.h,e,t.dash);case"check-box":return Ice(t.w,t.h);default:return}}function _ce(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 Ice(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 EE({shape:t,shouldScale:e,forceSolid:n}){const r=e?t.props.scale:1,o=z(),s=Fr(),{id:i,props:a}=t,{w:l,color:c,fill:u,dash:h,growY:p,size:f,scale:g}=a,m=hn[f]*r,v=a.h+p;switch(a.geo){case"cloud":if(h==="solid"){const S=rx(l,v,i,f,g);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"})]})}else if(h==="draw"){const S=Cce(l,v,i,f,g);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"})]})}else{const S=rx(l,v,i,f,g),y=vm(l,v,i,f,g);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("g",{strokeWidth:m,stroke:s[c].solid,fill:"none",pointerEvents:"all",children:y.map(({leftPoint:b,rightPoint:P,center:C,radius:I},k)=>{const _=C?I*oi(oi(x.Angle(C,P))-oi(x.Angle(C,b))):x.Dist(b,P),{strokeDasharray:T,strokeDashoffset:M}=Yr(_,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("path",{d:C?`M${b.x},${b.y}A${I},${I},0,0,1,${P.x},${P.y}`:`M${b.x},${b.y}L${P.x},${P.y}`,strokeDasharray:T,strokeDashoffset:M},k)})})]})}case"ellipse":{const S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=S.length,{strokeDasharray:P,strokeDashoffset:C}=Yr(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:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,strokeWidth:m,fill:"none",stroke:s[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else{const P=(e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t)).getSvgPathData(!0);return d.jsxs(d.Fragment,{children:[d.jsx(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 S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=S.getLength(),{strokeDasharray:P,strokeDashoffset:C}=Yr(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:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,strokeWidth:m,fill:"none",stroke:s[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:s[c].solid,strokeWidth:m,fill:"none"})]})}case"heart":if(h==="dashed"||h==="dotted"||h==="solid"){const S=Q$(l,v),y=bb(l,v);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:S,color:c,fill:u,scale:r}),y.map((b,P)=>{const{strokeDasharray:C,strokeDashoffset:I}=Yr(b.length,m,{style:h,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsx("path",{d:b.getSvgPathData(),strokeWidth:m,fill:"none",stroke:s[c].solid,strokeDasharray:C,strokeDashoffset:I,pointerEvents:"all"},`curve_${P}`)})]})}else{const S=gce(l,v,m,t.id);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"})]})}default:{const S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S instanceof ro?S.children[0].vertices:S.vertices,b=ox(t.props,m);if(h==="solid"){let P="M"+y[0]+"L"+y.slice(1)+"Z";if(b)for(const[C,I]of b)P+=`M${C.x},${C.y}L${I.x},${I.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(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"+y[0]+"L"+y.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(y.length)).map((C,I)=>{const k=x.ToFixed(y[I]),_=x.ToFixed(y[(I+1)%y.length]),T=x.Dist(k,_),{strokeDasharray:M,strokeDashoffset:D}=Yr(T,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("line",{x1:k.x,y1:k.y,x2:_.x,y2:_.y,strokeDasharray:M,strokeDashoffset:D},I)}),b&&b.map(([C,I],k)=>{const _=x.Dist(C,I),{strokeDasharray:T,strokeDashoffset:M}=Yr(_,m,{style:h,start:"skip",end:"skip",snap:h==="dotted"?4:void 0,forceSolid:n});return d.jsx("path",{d:`M${C.x},${C.y}L${I.x},${I.y}`,stroke:s[c].solid,strokeWidth:m,fill:"none",strokeDasharray:T,strokeDashoffset:M},`line_fg_${k}`)})]})]})}else if(h==="draw"){let P=tx(nx(i,y,m/3,m*2,2));if(b)for(const[I,k]of b)P+=`M${I.toFixed()}L${k.toFixed()}`;const C=tx(nx(i,y,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 kE=17*3;class wp extends Jl{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:bce(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:Oy(n,r,5),isFilled:i});break}case"hexagon":{a=new xt({points:Oy(n,r,6),isFilled:i});break}case"octagon":{a=new xt({points:Oy(n,r,8),isFilled:i});break}case"ellipse":{a=new Jee({width:n,height:r,isFilled:i});break}case"oval":{a=new ete({width:n,height:r,isFilled:i});break}case"star":{const y=Ne/5/2,b=Math.floor(5/4)*2,P=5*2-b,C=0,I=Math.floor(5/2)*2,k=Math.cos(-Ze+b*y)*n/2,_=Math.cos(-Ze+P*y)*n/2,T=Math.sin(-Ze+C*y)*r/2,M=Math.sin(-Ze+I*y)*r/2,D=n-Math.abs(k-_),j=r-Math.abs(M-T),O=n/2+_-(n/2-k),R=r/2+T-(r/2-M),B=1,L=(n-O)/2,G=(r-R)/2,$=(n+D)/2,U=(r+j)/2,Y=$*B/2,te=U*B/2;a=new xt({points:Array.from(Array(5*2)).map((de,he)=>{const ke=-Ze+he*y;return new x(L+(he%2?Y:$)*Math.cos(ke),G+(he%2?te:U)*Math.sin(ke))}),isFilled:i});break}case"rhombus":{const S=Math.min(n*.38,r*.38);a=new xt({points:[new x(S,0),new x(n,0),new x(n-S,r),new x(0,r)],isFilled:i});break}case"rhombus-2":{const S=Math.min(n*.38,r*.38);a=new xt({points:[new x(0,0),new x(n-S,0),new x(n,r),new x(S,r)],isFilled:i});break}case"trapezoid":{const S=Math.min(n*.38,r*.38);a=new xt({points:[new x(S,0),new x(n-S,0),new x(n,r),new x(0,r)],isFilled:i});break}case"arrow-right":{const S=Math.min(n,r)*.38,y=r*.16;a=new xt({points:[new x(0,y),new x(n-S,y),new x(n-S,0),new x(n,r/2),new x(n-S,r),new x(n-S,r-y),new x(0,r-y)],isFilled:i});break}case"arrow-left":{const S=Math.min(n,r)*.38,y=r*.16;a=new xt({points:[new x(S,0),new x(S,y),new x(n,y),new x(n,r-y),new x(S,r-y),new x(S,r),new x(0,r/2)],isFilled:i});break}case"arrow-up":{const S=n*.16,y=Math.min(n,r)*.38;a=new xt({points:[new x(n/2,0),new x(n,y),new x(n-S,y),new x(n-S,r),new x(S,r),new x(S,y),new x(0,y)],isFilled:i});break}case"arrow-down":{const S=n*.16,y=Math.min(n,r)*.38;a=new xt({points:[new x(S,0),new x(n-S,0),new x(n-S,r-y),new x(n,r-y),new x(n/2,r),new x(0,r-y),new x(S,r-y)],isFilled:i});break}case"check-box":case"x-box":case"rectangle":{a=new gs({width:n,height:r,isFilled:i});break}case"heart":{const y=bb(n,r).reduce((b,P)=>(b.push(...P.vertices),b),[]);a=new xt({points:y,isFilled:i});break}default:Ot(e.props.geo)}const l=jh(this.editor,e),c=n/e.props.scale,u=r/e.props.scale,h=Math.min(100,c/2),p=Math.min(us[e.props.size]*pn.lineHeight+Ir*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=ox(e.props,hn[e.props.size]*e.props.scale),v=m?m.map(S=>new ql({points:S})):[];return new ro({children:[a,new gs({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=Fr(),{editor:p}=this,f=H("isGeoOnlySelected",()=>e.id===p.getOnlySelectedShapeId(),[]),m=p.getEditingShapeId()!==null||e.props.text,v=H("force solid",()=>p.getZoomLevel()<.2,[p]);return d.jsxs(d.Fragment,{children:[d.jsx(ui,{id:n,children:d.jsx(EE,{shape:e,shouldScale:!0,forceSolid:v})}),m&&d.jsx(si,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+o.growY},children:d.jsx(Sm,{id:n,type:r,font:i,fontSize:us[c]*e.props.scale,lineHeight:pn.lineHeight,padding:Ir*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(Ol,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(e){const{id:n,props:r}=e,{w:o,size:s}=r,i=r.h+r.growY,a=hn[s],l=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?d.jsx("path",{d:Sce(n,o,i,a)}):d.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:Q$(o,i)});case"oval":return d.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:rx(o,i,n,s,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),u=c instanceof ro?c.children[0].vertices:c.vertices;let h;if(r.dash==="draw"){const f=nx(n,u,0,a*2*e.props.scale,1);h=tx(f)}else h="M"+u[0]+"L"+u.slice(1)+"Z";const p=ox(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(Sb(o.fill));let s;if(o.text){n.addExportDef(mm(o.font));const i=bs(n),a=new Z(0,0,o.w,o.h+o.growY);s=d.jsx(ym,{fontSize:us[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(EE,{shouldScale:!1,shape:r,forceSolid:!1}),s]})}getCanvasSvgDefs(){return[vb()]}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=kE;if(e.props.text.trim()){let P=Math.max(Math.abs(u),g),C=Math.max(Math.abs(h),g);P<g&&C===g&&(P=g),P===g&&C<g&&(C=g);const I=jh(this.editor,{...e,props:{...e.props,w:P*e.props.scale,h:C*e.props.scale}}),k=Math.max(Math.abs(u),I.w)*Math.sign(u),_=Math.max(Math.abs(h),I.h)*Math.sign(h);p=Math.abs(k)-Math.abs(u),f=Math.abs(_)-Math.abs(h),u=k,h=_}const m=u*e.props.scale,v=h*e.props.scale,S=new x(0,0);o<0&&(S.x+=m),(n==="left"||n==="top_left"||n==="bottom_left")&&(S.x+=o<0?p:-p),s<0&&(S.y+=v),(n==="top"||n==="top_left"||n==="top_right")&&(S.y+=s<0?f:-f);const{x:y,y:b}=S.rot(e.rotation).add(r);return{x:y,y:b,props:{w:Math.max(Math.abs(m),1),h:Math.max(Math.abs(v),1),growY:0}}}onBeforeCreate(e){if(!e.props.text)return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const n=e.props.h/e.props.scale,r=jh(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=jh(this.editor,n);if(!r&&o&&o.length===1){let u=Math.max(s,l.w),h=Math.max(i,l.h);const p=kE;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:Ie(e.props.w,n.props.w,r),h:Ie(e.props.h,n.props.h,r),scale:Ie(e.props.scale,n.props.scale,r)}}}E(wp,"type","geo"),E(wp,"props",SA),E(wp,"migrations",vA);function jh(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",{...pn,fontFamily:Ss[r],fontSize:us[o],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=t.textMeasure.measureText(n,{...pn,fontFamily:Ss[r],fontSize:us[o],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[o]),Math.ceil(s/e.props.scale-Ir*2))});return{w:l.w+Ir*2,h:l.h+Ir*2}}function Ece(){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)},[]),H(bt.forceSrgb)||!t?"srgb":"p3"}const TE=.35,ME=.82;class bp extends eo{hideResizeHandles(e){return Oh(e)}hideRotateHandle(e){return Oh(e)}hideSelectionBoundsFg(e){return Oh(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(e){const n=zi(e);if(Oh(e))return new _1({x:-n/2,y:-n/2,radius:n/2,isFilled:!0});const{strokePoints:r,sw:o}=AE(e,n,!0),s=wb({strokeWidth:o,showAsComplete:!0});return fm(r,s),new xt({points:gb(r,s),isFilled:!0})}component(e){const n=vS(this.editor,e),r=zi(e);return d.jsx(ui,{id:e.id,children:d.jsx(Dh,{shape:e,forceSolid:n,strokeWidth:r,opacity:TE})})}backgroundComponent(e){const n=vS(this.editor,e),r=zi(e);return d.jsx(ui,{id:e.id,children:d.jsx(Dh,{shape:e,forceSolid:n,strokeWidth:r,opacity:ME})})}indicator(e){const n=vS(this.editor,e),r=zi(e),{strokePoints:o,sw:s}=AE(e,r,n),i=Dl(e.props.segments);let a;return o.length<2?a=Tce(i[0],s):a=pa(o,!1),d.jsx("path",{d:a})}toSvg(e){const n=zi(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(Dh,{forceSolid:r,strokeWidth:n,shape:e,opacity:TE})})}toBackgroundSvg(e){const n=zi(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(Dh,{forceSolid:r,strokeWidth:n,shape:e,opacity:ME})})}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:Y$(e.props.segments,n.props.segments,r),scale:Ie(e.props.scale,n.props.scale,r)}}}E(bp,"type","highlight"),E(bp,"props",bA),E(bp,"migrations",PA);function kce(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 Tce(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 AE(t,e,n){var l;const r=Dl(t.props.segments),o=t.props.isComplete||((l=Ht(t.props.segments))==null?void 0:l.type)==="straight";let s=e;!n&&!t.props.isPen&&r.length===1&&(s+=io(t.id)()*(e/6));const i=wb({strokeWidth:s,showAsComplete:o});return{strokePoints:Oo(r,i),sw:s}}function zi(t){return Al[t.props.size]*1.12*t.props.scale}function Oh(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function Dh({strokeWidth:t,forceSolid:e,shape:n,opacity:r}){var p;const o=Fr(),s=Dl(n.props.segments);let i=t;!e&&!n.props.isPen&&s.length===1&&(i+=io(n.id)()*(i/6));const a=wb({strokeWidth:i,showAsComplete:n.props.isComplete||((p=Ht(n.props.segments))==null?void 0:p.type)==="straight"}),l=Oo(s,a),c=l.length>1?pa(l,!1):kce(n.props.segments[0].points[0]),u=Ece(),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 vS(t,e){return H("forceSolid",()=>{const n=zi(e),r=t.getZoomLevel();return n/r<1.5},[t])}function J$(){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 e5(t){const{shapeId:e,assetId:n,width:r}=t,o=z(),[s,i]=w.useState(null),[a,l]=w.useState(!1),c=!!pd(),u=n?o.getAsset(n):null,p=o.getCulledShapes().has(e),f=w.useRef(!1),g=JZ();w.useEffect(()=>{s&&(f.current=!0)},[s]);const m=u&&"w"in u.props?r/u.props.w:1,v=H("zoom level",()=>o.getZoomLevel()*m,[o,m]);return w.useEffect(()=>{s&&(f.current=!0)},[s]),w.useEffect(()=>{if(!c&&p)return;if(n&&!(u!=null&&u.props.src)){const b=o.getTemporaryAssetPreview(n);if(b){i(b),l(!0),g();return}}let S=!1;async function y(){const b=await o.resolveAssetUrl(n,{screenScale:v,shouldResolveToOriginal:c});S||(i(b),l(!1),g())}if(f.current){const b=o.timers.setTimeout(y,500);return()=>{clearTimeout(b),S=!0}}else return y(),()=>{S=!0}},[n,u==null?void 0:u.props.src,p,v,o,c,g]),{asset:u,url:s,isPlaceholder:a}}function t5(){const[t,e]=w.useState(!1);return w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{e(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),t}async function Mce(t){const n=await(await no(t)).blob();return os.blobToDataUrl(n)}class Pp extends Jl{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=Kg(e,n);const{flipX:o,flipY:s}=n.initialShape.props,{scaleX:i,scaleY:a,mode:l}=n;if(r={...r,props:{...r.props,flipX:i<0!==o,flipY:a<0!==s}},!e.props.crop)return r;const c=l==="scale_shape"&&i===-1||l==="resize_bounds"&&o!==r.props.flipX,u=l==="scale_shape"&&a===-1||l==="resize_bounds"&&s!==r.props.flipY,{topLeft:h,bottomRight:p}=e.props.crop;return r.props.crop={topLeft:{x:c?1-p.x:h.x,y:u?1-p.y:h.y},bottomRight:{x:c?1-h.x:p.x,y:u?1-h.y:p.y}},r}isAnimated(e){const n=e.props.assetId?this.editor.getAsset(e.props.assetId):void 0;return n?"mimeType"in n.props&&lr.isAnimatedImageType(n==null?void 0:n.props.mimeType)||"isAnimated"in n.props&&n.props.isAnimated:!1}component(e){var S;const n=this.editor.getCroppingShapeId()===e.id,r=t5(),[o,s]=w.useState(""),[i,a]=w.useState(null),l=e.id===this.editor.getOnlySelectedShapeId(),{asset:c,url:u}=e5({shapeId:e.id,assetId:e.props.assetId,width:e.props.w});if(w.useEffect(()=>{if(u&&this.isAnimated(e)){let y=!1;const b=Au();return b.onload=()=>{if(y)return;const P=document.createElement("canvas");P.width=b.width,P.height=b.height;const C=P.getContext("2d");C&&(C.drawImage(b,0,0),s(P.toDataURL()),a(u))},b.crossOrigin="anonymous",b.src=u,()=>{y=!0}}},[r,u,e]),(c==null?void 0:c.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const h=l&&n&&this.editor.isIn("select.crop"),p=r&&(((S=c==null?void 0:c.props.mimeType)==null?void 0:S.includes("video"))||this.isAnimated(e)),f=jE(e),g=u===i?null:u,m=p?o:i;if(!u&&!(c!=null&&c.props.src))return d.jsxs(si,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,color:"var(--color-text-3)",backgroundColor:"var(--color-low)",border:"1px solid var(--color-low-border)"},children:[d.jsx("div",{className:le("tl-image-container",c&&"tl-image-container-loading"),style:f,children:c?null:d.jsx(J$,{})}),"url"in e.props&&e.props.url&&d.jsx(Ol,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]});const v=this.isAnimated(e)?"anonymous":void 0;return d.jsxs(d.Fragment,{children:[h&&m&&d.jsx("div",{style:f,children:d.jsx("img",{className:"tl-image",style:{...Mc(e),opacity:.1},crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),d.jsxs(si,{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:Mc(e),crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},m),g&&d.jsx("img",{className:"tl-image",style:Mc(e),crossOrigin:v,src:g,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>a(g)},g)]}),e.props.url&&d.jsx(Ol,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]})]})}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});if(!r)return null;(r.startsWith("blob:")||r.startsWith("http")||r.startsWith("/")||r.startsWith("./"))&&(r=await Mce(r)||"");const o=jE(e),s=e.props.crop;if(o.transform&&s){const{transform:i,width:a,height:l}=o,c=(s.bottomRight.x-s.topLeft.x)*a,u=(s.bottomRight.y-s.topLeft.y)*l,h=[new x(0,0),new x(c,0),new x(c,u),new x(0,u)],p=`cropClipPath_${Xl(e.id)}`,f=Mc(e,{width:a,height:l});return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:p,children:d.jsx("polygon",{points:h.map(g=>`${g.x},${g.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${p})`,children:d.jsx("image",{href:r,width:a,height:l,style:f?{...f,transform:`${i} ${f.transform}`}:{transform:i}})})]})}else return d.jsx("image",{href:r,width:e.props.w,height:e.props.h,style:Mc(e,{width:e.props.w,height:e.props.h})})}onDoubleClickEdge(e){const n=e.props;if(!n||this.editor.getCroppingShapeId()!==e.id)return;const r=nt(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:Ie(a.x,c.x,r),y:Ie(a.y,c.y,r)},bottomRight:{x:Ie(l.x,u.x,r),y:Ie(l.y,u.y,r)}}}return{...r>.5?n.props:e.props,w:Ie(e.props.w,n.props.w,r),h:Ie(e.props.h,n.props.h,r),crop:o(e,n)}}}E(Pp,"type","image"),E(Pp,"props",CA),E(Pp,"migrations",_A);function jE(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 Mc(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 n5(t){return{size:t,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function r5(t,e,n){const r=e.vertices,o=n5(n);return Oo(r,o)}function Ace(t,e,n){const r=n5(n);return gb(fm(r5(t,e,n),r),r)}function jce(t,e,n){const r=Ace(t,e,n);return i1(r)}function Oce(t,e,n){if(t.props.dash==="draw"){const r=r5(t,e,n);return pa(r)}return e.getSvgPathData()}function o5(t,e,n){let r=`M ${je(e[0])}L`,o=`M ${je(e[0])}L`;const s=n/3,i=n*2,a=io(t);let l=e[0],c,u=e[0],h;const p=e.length;for(let f=0,g=p-1;f<g;f++){c=e[f+1],h=x.AddXY(e[f+1],a()*s,a()*s);const m=x.Sub(c,l),v=x.Len(m),S=x.Div(m,v).mul(Math.min(v/4,i)),y=x.Add(l,S),b=x.Add(c,S.neg()),P=x.Sub(h,u),C=x.Len(P),I=x.Div(P,C).mul(Math.min(C/4,i)),k=x.Add(u,I),_=x.Add(h,I.neg());f===g-1?(r+=`${je(y)}L ${je(c)}`,o+=`${je(k)}L ${je(h)}`):(r+=`${je(y)}L ${je(b)}Q ${je(c)}`,o+=`${je(k)}L ${je(_)}Q ${je(h)}`,l=c,u=h)}return[r,r+o]}const Dce=new ko;class Cp extends eo{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,n]=Ou(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 Vc(e)}getHandles(e){return Dce.get(e.props,()=>{const n=Vc(e),r=Gc(e),o=r.map(s=>({...s,id:s.index,type:"vertex",canSnap:!0}));for(let s=0;s<r.length-1;s++){const i=ju(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:Ju(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{...e,props:{...e.props,points:{...e.props.points,[n.id]:{id:n.id,index:n.index,x:n.x,y:n.y}}}}}component(e){return d.jsx(ui,{id:e.id,children:d.jsx(OE,{shape:e})})}indicator(e){const n=Co[e.props.size]*e.props.scale,r=Vc(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]=o5(e.id,i,n);s=a}}else s=Oce(e,r,n);return d.jsx("path",{d:s})}toSvg(e){return d.jsx(OE,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const n=Gc(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=Vc(e).segments.filter((i,a)=>a!==o-1&&a!==o);return s.length?new ro({children:s}):null}}}getInterpolatedProps(e,n,r){const o=Gc(e),s=Gc(n),i=[],a=[];let l=OT;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=wo(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=wo(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:Ie(c.x,h.x,r),y:Ie(c.y,h.y,r)}]})),scale:Ie(e.props.scale,n.props.scale,r)}}}E(Cp,"type","line"),E(Cp,"props",IA),E(Cp,"migrations",EA);function Gc(t){return Object.values(t.props.points).sort(cn)}function Vc(t){const e=Gc(t).map(x.From);switch(t.props.spline){case"cubic":return new Qee({points:e});case"line":return new ql({points:e})}}function OE({shape:t,shouldScale:e=!1,forceSolid:n=!1}){const r=Fr(),o=Vc(t),{dash:s,color:i,size:a}=t.props,l=1/t.props.scale,c=e?l:1,u=Co[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"}:Yr(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]=o5(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}=Yr(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:jce(t,o,u),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${c})`})}}class _p extends eo{canEdit(){return!0}hideResizeHandles(){return!0}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(e){const{labelHeight:n,labelWidth:r}=s5(this.editor,e),{scale:o}=e.props,s=n*o,i=r*o,a=Ke*o,l=Rh(e);return new ro({children:[new gs({width:a,height:l,isFilled:!0}),new gs({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=Rh(e),i=Ke*n,a=ile/o*n;return o*n<.5?[{id:"bottom",index:"a3",type:"clone",x:i/2,y:s+a}]:[{id:"top",index:"a1",type:"clone",x:i/2,y:-a},{id:"right",index:"a2",type:"clone",x:i+a,y:s/2},{id:"bottom",index:"a3",type:"clone",x:i/2,y:s+a},{id:"left",index:"a4",type:"clone",x:-a,y:s/2}]}getText(e){return e.props.text}component(e){const{id:n,type:r,props:{scale:o,color:s,font:i,size:a,align:l,text:c,verticalAlign:u,fontSizeAdjustment:h}}=e,p=$ce(n),f=Fr(),g=Ke*o,m=Rh(e),v=H("shape rotation",()=>{var b;return((b=this.editor.getShapePageTransform(n))==null?void 0:b.rotation())??0},[this.editor]),S=H("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),y=e.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:n,className:"tl-note__container",style:{width:g,height:m,backgroundColor:f[s].note.fill,borderBottom:S?`${3*o}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:S?"none":Fce(e.id,v,o)},children:d.jsx(Sm,{id:n,type:r,font:i,fontSize:(h||us[a])*o,lineHeight:pn.lineHeight,align:l,verticalAlign:u,text:c,isNote:!0,isSelected:y,labelColor:f[s].note.text,wrap:!0,padding:16*o,onKeyDown:p})}),"url"in e.props&&e.props.url&&d.jsx(Ol,{url:e.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(e){const{scale:n}=e.props;return d.jsx("rect",{rx:n,width:N(Ke*n),height:N(Rh(e))})}toSvg(e,n){e.props.text&&n.addExportDef(mm(e.props.font));const r=bs({isDarkMode:n.isDarkMode}),o=Nce(e);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:Ke-10,height:o.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:Ke,height:o.h,fill:r[e.props.color].note.fill}),d.jsx(ym,{fontSize:e.props.fontSizeAdjustment||us[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 DE(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 DE(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:Ie(e.props.scale,n.props.scale,r)}}}E(_p,"type","note"),E(_p,"props",kA),E(_p,"migrations",TA);function DE(t,e){const{labelHeight:n,fontSizeAdjustment:r}=s5(t,e),o=Math.max(0,n-Ke);if(o!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:o,fontSizeAdjustment:r}}}function Rce(t,e){const{text:n}=e.props;if(!n)return{labelHeight:us[e.props.size]*pn.lineHeight+Ir*2,labelWidth:100,fontSizeAdjustment:0};const r=us[e.props.size];let o=0,s=0,i=Ke,a=Ke;const l=1;do{o=Math.min(r,r-s);const c=t.textMeasure.measureText(n,{...pn,fontFamily:Ss[e.props.font],fontSize:o,maxWidth:Ke-Ir*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Ir*2,a=c.w+Ir*2,o<=14){const u=t.textMeasure.measureText(n,{...pn,fontFamily:Ss[e.props.font],fontSize:o,maxWidth:Ke-Ir*2-l});i=u.h+Ir*2,a=u.w+Ir*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const Lce=new ko;function s5(t,e){return Lce.get(e,()=>Rce(t,e))}function $ce(t){const e=z(),n=_3();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"||M$(o.props.text)),u=(Ke+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(gm.clone().mul(o.props.scale)).rot(l).add(a.point()),p=$$(e,o,h,l);p&&(e.markHistoryStoppingPoint("editing adjacent shape"),Rf(e,p,!0))}},[t,e,n.dir])}function Rh(t){return(Ke+t.props.growY)*t.props.scale}function Fce(t,e,n){const r=io(t),o=Math.abs(r())+.5,s=Math.cos(e),i=5*n,a=4*n,l=6*n,c=7*n;return`0px ${i-o}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
388
|
-
0px ${(a+o*c)*Math.max(0,s)}px ${l+o*c}px -${a+o*l}px rgba(15, 23, 31, ${(.3+o*.1).toFixed(2)}),
|
|
389
|
-
0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+s)/2)).toFixed(2)})`}function Nce(t){return new Z(0,0,Ke,Ke+t.props.growY)}function zce(t,{initialBounds:e,scaleX:n,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new x(0,0);n<0&&(i.x=-(e.width*s)),r<0&&(i.y=-(e.height*s));const{x:a,y:l}=x.Add(o,i.rot(t.rotation));return{x:a,y:l,props:{scale:s*t.props.scale}}}const Bce=new ko;class Ip extends eo{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return Bce.get(e.props,n=>RE(this.editor,n))}getGeometry(e){const{scale:n}=e.props,{width:r,height:o}=this.getMinDimensions(e);return new gs({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=Fr(),f=Uce(n);return d.jsx(Sm,{id:n,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:Al[o],lineHeight:pn.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(mm(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=bs(n);return d.jsx(ym,{fontSize:Al[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,...zce(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=RE(this.editor,n.props),a=s.width*e.props.scale,l=s.height*e.props.scale,c=i.width*n.props.scale,u=i.height*n.props.scale;let h;switch(n.props.textAlign){case"middle":{h=new x((c-a)/2,o?0:(u-l)/2);break}case"end":{h=new x(c-a,o?0:(u-l)/2);break}default:{if(o)break;h=new x(0,(u-l)/2);break}}if(h){h.rot(n.rotation);const{x:p,y:f}=n;return{...n,x:p-h.x,y:f-h.y,props:{...n.props,w:c}}}else return{...n,props:{...n.props,w:c}}}}E(Ip,"type","text"),E(Ip,"props",MA),E(Ip,"migrations",AA);function RE(t,e){const{font:n,text:r,autoSize:o,size:s,w:i}=e,a=o?16:Math.max(16,i),l=Al[s],c=o?null:Math.floor(Math.max(a,i)),u=t.textMeasure.measureText(r,{...pn,fontFamily:Ss[n],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function Uce(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?jl.unindent(n.currentTarget):jl.indent(n.currentTarget);break}}},[e,t])}class Ep extends Jl{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){const{editor:n}=this,r=n.getShapeGeometry(e).bounds.w*n.getZoomLevel()>=110,{asset:o,url:s}=e5({shapeId:e.id,assetId:e.props.assetId,width:e.props.w}),i=Wg(e.id),a=t5(),{Spinner:l}=ot(),c=w.useRef(null),[u,h]=w.useState(!1),[p,f]=w.useState(!1);w.useEffect(()=>{const m=()=>f(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",m),()=>document.removeEventListener("fullscreenchange",m)});const g=w.useCallback(m=>{m.currentTarget&&h(!0)},[]);return w.useEffect(()=>{const m=c.current;m&&i&&document.activeElement!==m&&m.focus()},[i,u]),w.useEffect(()=>{if(a){const m=c.current;if(!m)return;m.pause(),m.currentTime=0}},[c,a]),d.jsxs(d.Fragment,{children:[d.jsx(si,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:o?"transparent":"var(--color-low)",border:o?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:o?l&&!o.props.src?d.jsx(l,{}):s?d.jsxs(d.Fragment,{children:[d.jsx("video",{ref:c,style:i?{pointerEvents:"all"}:u?void 0:{display:"none"},className:le("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":p}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:i&&r,onLoadedData:g,hidden:!u,children:d.jsx("source",{src:s})}),!u&&l&&d.jsx(l,{})]}):null:d.jsx(J$,{})})})}),"url"in e.props&&e.props.url&&d.jsx(Ol,{url:e.props.url,zoomLevel:n.getZoomLevel()})]})}indicator(e){return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){const n=await Hce(this.editor,e);return n?d.jsx("image",{href:n,width:e.props.w,height:e.props.h}):null}}E(Ep,"type","video"),E(Ep,"props",jA),E(Ep,"migrations",OA);async function Hce(t,e){const n=await t.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});if(!n)return null;const r=await lr.loadVideo(n);return lr.getVideoFrameAsDataUrl(r,0)}const i5=[Ip,yp,Sp,wp,_p,Cp,xp,mp,bp,vp,Pp,Ep];function Kce(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 a5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"scribbleId","id");E(this,"markId","");E(this,"excludedShapeIds",new Set)}onEnter(n){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>{if(this.editor.isShapeOrAncestorLocked(s))return!0;if(this.editor.isShapeOfType(s,"group")||this.editor.isShapeOfType(s,"frame")){const i=this.editor.getPointInShapeSpace(s,r);return this.editor.getShapeGeometry(s).bounds.containsPoint(i)}return!1}).map(s=>s.id));const o=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=o.id,this.update()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}update(){const{editor:n,excludedShapeIds:r}=this,o=n.getErasingShapeIds(),s=n.getZoomLevel(),i=n.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=n;this.pushPointToScribble();const c=new Set(o),u=this.editor.options.hitTestMargin/s;for(const h of i){if(n.isShapeOfType(h,"group"))continue;const p=n.getShapeMask(h.id);if(p&&!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),S=m.applyToPoint(a),{bounds:y}=f;y.minX-u>Math.max(v.x,S.x)||y.minY-u>Math.max(v.y,S.y)||y.maxX+u<Math.min(v.x,S.x)||y.maxY+u<Math.min(v.y,S.y)||f.hitTestLineSegment(v,S,u)&&c.add(n.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),n.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.setErasingShapes([]),n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}E(a5,"id","erasing");var NS;let Wce=(NS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},E(NS,"id","idle"),NS);var zS;let Gce=(zS=class extends ie{onEnter(){const e=this.editor.getZoomLevel(),n=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,o=new Set,s=o.size;for(let i=n.length,a=i-1;a>=0;a--){const l=n[a];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,r,{hitInside:!1,margin:this.editor.options.hitTestMargin/e})){const c=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(c,"frame")&&o.size>s)break;o.add(c.id)}}this.editor.setErasingShapes([...o])}onLongPress(e){this.startErasing(e)}onPointerMove(e){this.editor.inputs.isDragging&&this.startErasing(e)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}startErasing(e){this.parent.transition("erasing",e)}complete(){const e=this.editor.getErasingShapeIds();e.length&&(this.editor.markHistoryStoppingPoint("erase end"),this.editor.deleteShapes(e)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},E(zS,"id","pointing"),zS);class kp extends ie{static children(){return[Wce,Gce,a5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}E(kp,"id","eraser"),E(kp,"initial","idle"),E(kp,"isLockable",!1);class l5 extends ie{constructor(){super(...arguments);E(this,"initialCamera",new x)}onEnter(){this.initialCamera=x.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:o,originScreenPoint:s}=r.inputs,i=x.Sub(o,s).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,o=Math.min(r.len(),2);o>.1&&this.editor.slideCamera({speed:o,direction:r}),this.parent.transition("idle")}}E(l5,"id","dragging");var BS;let Vce=(BS=class extends ie{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},E(BS,"id","idle"),BS);var US;let Yce=(US=class extends ie{onEnter(){this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})}onLongPress(){this.startDragging()}onPointerMove(){this.editor.inputs.isDragging&&this.startDragging()}startDragging(){this.parent.transition("dragging")}onPointerUp(){this.complete()}onCancel(){this.complete()}onComplete(){this.complete()}onInterrupt(){this.complete()}complete(){this.parent.transition("idle")}},E(US,"id","pointing"),US);class Tp extends ie{static children(){return[Vce,Yce,l5]}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}})}}}E(Tp,"id","hand"),E(Tp,"initial","idle"),E(Tp,"isLockable",!1);var HS;let Xce=(HS=class extends ie{onPointerDown(e){this.parent.transition("lasering",e)}},E(HS,"id","idle"),HS);class c5 extends ie{constructor(){super(...arguments);E(this,"scribbleId","id")}onEnter(){const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:this.editor.options.laserDelayMs,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.pushPointToScribble()}onPointerUp(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onCancel(){this.cancel()}onComplete(){this.complete()}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}E(c5,"id","lasering");class Mp extends ie{static children(){return[Xce,c5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}E(Mp,"id","laser"),E(Mp,"initial","idle"),E(Mp,"isLockable",!1);class u5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"initialSelectedShapeIds",[]);E(this,"excludedShapeIds",new Set);E(this,"isWrapMode",!1);E(this,"initialStartShape",null)}onEnter(n){const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",n);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>this.editor.isShapeOfType(s,"group")||this.editor.isShapeOrAncestorLocked(s)).map(s=>s.id)),this.info=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(o)[0],this.hitTestShapes()}onExit(){this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(n){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",n)}onKeyDown(n){this.editor.inputs.altKey?this.parent.transition("scribble_brushing",n):this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:n,excludedShapeIds:r,isWrapMode:o}=this,{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=n,c=new Set(a?this.initialSelectedShapeIds:[]),u=o?!l:l,h=Z.FromPoints([s,i]),{corners:p}=h;let f,g,m,v,S,y;const b=n.getCurrentPageRenderingShapesSorted(),P=n.getCurrentPageId();e:for(let k=0,_=b.length;k<_;k++){if(m=b[k],r.has(m.id)||c.has(m.id)||(v=n.getShapePageBounds(m),!v))continue e;if(h.contains(v)){this.handleHit(m,i,P,c,p);continue e}if(u||n.isShapeOfType(m,"frame"))continue e;if(h.collides(v)){if(S=n.getShapePageTransform(m),!S)continue e;y=S.clone().invert().applyToPoints(p);const T=n.getShapeGeometry(m);t:for(let M=0;M<4;M++)if(f=y[M],g=y[(M+1)%4],T.hitTestLineSegment(f,g,0)){this.handleHit(m,i,P,c,p);break t}}}n.getInstanceState().isCoarsePointer;const C=n.getInstanceState().brush;(!C||!h.equals(C))&&n.updateInstanceState({brush:{...h.toJson()}});const I=n.getSelectedShapeIds();(I.length!==c.size||I.some(k=>!c.has(k)))&&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&&!_j(l,i)&&!hr(r,l)||s.add(a.id)}}E(u5,"id","brushing");const Rl={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 d5 extends ie{constructor(){super(...arguments);E(this,"info",{})}updateCursor(){const n=this.editor.getSelectedShapes(),r=Rl[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")}}E(d5,"id","pointing_resize_handle");const Cr=8;class Pb extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"markId","");E(this,"snapshot",{})}onEnter(n){this.info=n,this.markId=this.editor.markHistoryStoppingPoint("cropping"),this.snapshot=this.createSnapshot(),this.updateShapes()}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=Rl[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=nt(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<Cr)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/g,g*(u.bottomRight.y-u.topLeft.y)<Cr?(u.topLeft.y=u.bottomRight.y-Cr/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<Cr)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/g),g*(u.bottomRight.y-u.topLeft.y)<Cr&&(u.bottomRight.y=u.topLeft.y+Cr/g);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<Cr)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<Cr?(u.topLeft.x=u.bottomRight.x-Cr/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<Cr)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<Cr&&(u.bottomRight.x=u.topLeft.x+Cr/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}}}E(Pb,"id","cropping");function h5(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 p5(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=nt(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 KS;let qce=(KS=class extends ie{onEnter(){this.editor.setCursor({type:"default",rotation:0});const e=this.editor.getOnlySelectedShape();e&&this.editor.setCroppingShape(e.id)}onExit(){this.editor.setCursor({type:"default",rotation:0})}onCancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}onPointerDown(e){var n;if(!this.editor.menus.hasAnyOpenMenus()){if(e.accelKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{const r=h5(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=p5(this.editor,s,o);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},E(KS,"id","idle"),KS);class f5 extends ie{onCancel(){this.editor.setCurrentTool("select.crop.idle",{})}onPointerMove(e){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",e)}onPointerUp(e){this.editor.setCurrentTool("select.crop.idle",e)}}E(f5,"id","pointing_crop");class Cb extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=Rl[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"))}}E(Cb,"id","pointing_crop_handle");class g5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"markId","");E(this,"snapshot",{})}onEnter(n){this.info=n,this.snapshot=this.createSnapshot(),this.markId=this.editor.markHistoryStoppingPoint("translating_crop"),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onKeyDown(n){switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}}onKeyUp(n){switch(n.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const n=this.snapshot.shape;if(!n)return;const{originPagePoint:r,currentPagePoint:o}=this.editor.inputs,s=o.clone().sub(r),i=p5(this.editor,n,s);i&&this.editor.updateShapes([i])}}E(g5,"id","translating_crop");class sx extends ie{constructor(){super(...arguments);E(this,"markId","");E(this,"didExit",!1)}static children(){return[qce,g5,f5,Cb,Pb]}onEnter(){this.didExit=!1,this.markId=this.editor.markHistoryStoppingPoint("crop")}onExit(){this.didExit||(this.didExit=!0,this.editor.squashToMark(this.markId))}onCancel(){this.didExit||(this.didExit=!0,this.editor.bailToMark(this.markId))}}E(sx,"id","crop"),E(sx,"initial","idle");class m5 extends ie{constructor(){super(...arguments);E(this,"shapeId","");E(this,"initialHandle",{});E(this,"initialAdjacentHandle",null);E(this,"initialPagePoint",{});E(this,"markId","");E(this,"initialPageTransform");E(this,"initialPageRotation");E(this,"info",{});E(this,"isPrecise",!1);E(this,"isPreciseId",null);E(this,"pointingId",null);E(this,"exactTimeout",-1)}onEnter(n){const{shape:r,isCreating:o,creatingMarkId:s,handle:i}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId="",o)if(s)this.markId=s;else{const c=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);c&&(this.markId=c)}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");if(this.initialHandle=nt(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=nt(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=zn(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 k;const{editor:n,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:h,shiftKey:p,ctrlKey:f,altKey:g,pointerVelocity:m}}=n,v=this.info.shape,S=n.getShape(r);if(!S)return;const y=n.getShapeUtil(S);let b=h.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const _=x.Angle(a,b),M=Tf(_,24)-_;b=x.RotWith(b,a,M)}n.snaps.clearIndicators();let P={...s,x:b.x,y:b.y};if(s.canSnap&&(c?!f:f)){if(!n.getShapePageTransform(S.id))throw Error("Expected a page transform");const T=u.handles.snapHandle({currentShapeId:r,handle:P});T&&(T.nudge.rot(-n.getShapeParentTransform(S).rotation()),b.add(T.nudge),P={...s,x:b.x,y:b.y})}const C=(k=y.onHandleDrag)==null?void 0:k.call(y,S,{handle:P,isPrecise:this.isPrecise||g,initial:v}),I={id:S.id,type:S.type,...C};if(s.type==="vertex"&&this.editor.isShapeOfType(S,"arrow")){const _=zn(n,S)[s.id];_?l[0]!==_.toId&&(n.setHintingShapes([_.toId]),this.pointingId=_.toId,this.isPrecise=m.len()<.5||g,this.isPreciseId=this.isPrecise?_.toId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&n.updateShapes([I])}}E(m5,"id","dragging_handle");function y5(t){return t.isLabel?[t]:t instanceof ro?t.children.filter(e=>e.isLabel):[]}class S5 extends ie{constructor(){super(...arguments);E(this,"hitShapeForPointerUp",null);E(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"),ns(this.editor),this.editor.select(r)}onExit(){var s;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),ns.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":{ns(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=y5(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),ns(this.editor)}}onComplete(n){this.parent.transition("idle",n)}onCancel(n){this.parent.transition("idle",n)}}E(S5,"id","editing_shape");function LE(t){const e=t.getOnlySelectedShape();return!!(e&&!t.isShapeOrAncestorLocked(e)&&t.getShapeUtil(e).canCrop(e))}function qf(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($n(c)){const u=t.getShape(c);t.isPointInShape(u,r,{margin:0,hitInside:!0})||t.setFocusedGroup(null)}}}}const Zce=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var WS;let Qce=(WS=class extends ie{onEnter(){this.parent.setCurrentToolIdMask(void 0),ns(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){ns.cancel()}onPointerMove(){ns(this.editor)}onPointerDown(e){if(this.editor.menus.hasAnyOpenMenus())return;const n=e.ctrlKey&&LE(this.editor);switch(e.target){case"canvas":{const r=h5(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))&&$E(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(n)this.parent.transition("crop.pointing_crop_handle",e);else{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")){qf(this.editor,e);return}else{const c=this.editor.getShape(a.parentId);if(c&&this.editor.isShapeOfType(c,"group")&&!(l&&c.id===l)){qf(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:!1,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))&&$E(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()&&!Zce.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}LE(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"),Rf(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())return;this.editor.markHistoryStoppingPoint("creating text shape");const n=Be(),{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*tue:s:r?Jce:eue,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))}},E(WS,"id","idle"),WS);const Jce=10,eue=1,tue=5;function $E(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 v5 extends ie{constructor(){super(...arguments);E(this,"shapeId","");E(this,"markId","");E(this,"wasAlreadySelected",!1);E(this,"didDrag",!1);E(this,"didCtrlOnEnter",!1);E(this,"info",{});E(this,"_labelDragOffset",new x(0,0))}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(n){const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.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=Po(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=h0(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")}}E(v5,"id","pointing_arrow_label");class x5 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){qf(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}E(x5,"id","pointing_canvas");class w5 extends ie{constructor(){super(...arguments);E(this,"didCtrlOnEnter",!1);E(this,"info",{})}onEnter(n){this.info=n,this.didCtrlOnEnter=n.accelKey;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const o=zn(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=FE(o,n,r,!1);if(s){Rf(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=FE(n,r,o,!0);if(s){const i=n.getPointInParentSpace(s,n.inputs.originPagePoint).sub(x.Rot(gm.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:()=>{Rf(n,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}E(w5,"id","pointing_handle");function FE(t,e,n,r){const o=t.getShapePageTransform(e.id),s=o.point(),i=o.rotation(),l=R$(t,s,i,e.props.growY,0,e.props.scale)[n.index];if(l)return $$(t,e,l,i,r)}class b5 extends ie{constructor(){super(...arguments);E(this,"info",{})}updateCursor(){this.editor.setCursor({type:Rl[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")}}E(b5,"id","pointing_rotate_handle");class P5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n}onPointerUp(n){qf(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")}}E(P5,"id","pointing_selection");class C5 extends ie{constructor(){super(...arguments);E(this,"hitShape",{});E(this,"hitShapeForPointerUp",{});E(this,"isDoubleClick",!1);E(this,"didCtrlOnEnter",!1);E(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=y5(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")}}E(C5,"id","pointing_shape");class _5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"markId","");E(this,"didHoldCommand",!1);E(this,"creationCursorOffset",{x:0,y:0});E(this,"snapshot",{})}onEnter(n){const{isCreating:r=!1,creatingMarkId:o,creationCursorOffset:s={x:0,y:0}}=n;if(this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=s,this.snapshot=this._createSnapshot(),this.markId="",r)if(o)this.markId=o;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("starting resizing");r&&this.editor.setCursor({type:"cross",rotation:0}),this.handleResizeStart(),this.updateShapes()}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var n,r;if(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 _=[...s.values()][0];this.editor.isShapeOfType(_.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),g=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:_}=this.editor.getDocumentSettings();f.snapToGrid(_)}const m=this.info.handle,v=NE(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%Ze===0){const{nudge:_}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:x.Sub(f,g),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:NE(m,c),isAspectRatioLocked:h,isResizingFromCenter:n});f.add(_)}const y=x.RotWith(n?i.center:i.getHandlePoint(v),i.point,c),b=x.Sub(f,y).rot(-c),P=x.Sub(g,y).rot(-c),C=x.DivV(b,P);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const I=m==="top"||m==="bottom",k=m==="left"||m==="right";h?k?C.y=Math.abs(C.x):I?C.x=Math.abs(C.y):Math.abs(C.x)>Math.abs(C.y)?C.y=Math.abs(C.x)*(C.y<0?-1:1):C.x=Math.abs(C.y)*(C.x<0?-1:1):(I&&(C.x=1),k&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:c});for(const _ of s.keys()){const T=s.get(_);this.editor.resizeShape(_,C,{initialShape:T.shape,initialBounds:T.bounds,initialPageTransform:T.pageTransform,dragHandle:m,mode:l.length===1&&_===l[0]?"resize_bounds":"scale_shape",scaleOrigin:y,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:_,children:T}of o){if(!T.length)continue;const M=s.get(_).shape,D=this.editor.getShape(_);if(!(M&&D))continue;const j=D.x-M.x,O=D.y-M.y,R=new x(j,O).rot(-M.rotation);if(R.x!==0||R.y!==0)for(const B of T)this.editor.updateShape({id:B.id,type:B.type,x:B.x-R.x,y:B.y-R.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:_}of o)if(_.length)for(const T of _)this.editor.updateShape({id:T.id,type:T.type,x:T.x,y:T.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==o&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==o&&(i.type="nwse-resize");break}}i.rotation=s,this.editor.setCursor(i)}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()}_createSnapshot(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=x.Sub(o,i),l=new Map,c=[];n.forEach(h=>{const p=this.editor.getShape(h);if(p){if(p.type==="frame"&&c.push({id:h,children:ye(this.editor.getSortedChildIdsForParent(p).map(f=>this.editor.getShape(f)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&n.length===1)return;this.editor.visitDescendants(p.id,f=>{const g=this.editor.getShape(f);if(g&&(l.set(g.id,this._createShapeSnapshot(g)),this.editor.isShapeOfType(g,"frame")))return!1})}});const u=![...l.values()].some(h=>!FA(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}}_createShapeSnapshot(n){const r=this.editor.getShapePageTransform(n),o=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:q.Decompose(r).rotation,isAspectRatioLocked:o.isAspectRatioLocked(n)}}}E(_5,"id","resizing");const xS=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function NE(t,e){e=e%Ne;const n=Math.round(e/(De/4)),r=xS.indexOf(t);return xS[(r+n)%xS.length]}const zE=Math.PI/180;class I5 extends ie{constructor(){super(...arguments);E(this,"snapshot",{});E(this,"info",{});E(this,"markId","")}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=Yj({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});ip({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:Rl[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});ip({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:Rl[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(){ip({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=Tf(h,24);else if(n&&(h=Math.round(h/zE)*zE,this.editor.getInstanceState().isCoarsePointer)){const p=Tf(h,4),f=rp(h,p);Math.abs(f)<zY(5)&&(h=p)}return h-l}}E(I5,"id","rotating");class E5 extends ie{constructor(){super(...arguments);E(this,"hits",new Set);E(this,"size",0);E(this,"scribbleId","id");E(this,"initialSelectedShapeIds",new Set);E(this,"newlySelectedShapeIds",new Set)}onEnter(){this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const n=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=n.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.updateScribbleSelection(!0)}onPointerUp(){this.complete()}onKeyDown(){this.updateScribbleSelection(!1)}onKeyUp(){this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")}onCancel(){this.cancel()}onComplete(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}updateScribbleSelection(n){const{editor:r}=this,o=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const h=o;let p,f,g,m;const v=0;for(let b=0,P=h.length;b<P;b++){if(p=h[b],r.isShapeOfType(p,"group")||c.has(p.id)||r.isShapeOrAncestorLocked(p)||(f=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&f.bounds.containsPoint(r.getPointInShapeSpace(p,i))))continue;const C=r.getShapePageTransform(p);if(!f||!C)continue;const I=C.clone().invert();g=I.applyToPoint(a),m=I.applyToPoint(l);const{bounds:k}=f;if(!(k.minX-v>Math.max(g.x,m.x)||k.minY-v>Math.max(g.y,m.y)||k.maxX+v<Math.min(g.x,m.x)||k.maxY+v<Math.min(g.y,m.y))&&f.hitTestLineSegment(g,m,v)){const _=this.editor.getOutermostSelectableShape(p),T=this.editor.getShapeMask(_.id);if(T&&d1(a,l,T)!==null&&!hr(l,T))continue;c.add(_.id)}}const S=r.getSelectedShapeIds(),y=new Set(s?[...c,...u]:[...c]);(S.length!==y.size||S.some(b=>!y.has(b)))&&this.editor.setSelectedShapes(Array.from(y))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}E(E5,"id","scribble_brushing");var nue=Object.create,k5=Object.defineProperty,rue=Object.getOwnPropertyDescriptor,oue=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),T5=t=>{throw TypeError(t)},M5=(t,e,n)=>e in t?k5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,sue=t=>[,,,nue(null)],A5=["class","method","getter","setter","accessor","field","value","get","set"],j5=t=>t!==void 0&&typeof t!="function"?T5("Function expected"):t,iue=(t,e,n,r,o)=>({kind:A5[t],name:e,metadata:r,addInitializer:s=>n._?T5("Already initialized"):o.push(j5(s||null))}),aue=(t,e)=>M5(e,oue("metadata"),t[3]),lue=(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},cue=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=A5[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,rue(o,n)),S=r.length-1;S>=0;S--)l=iue(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,j5(i)&&(v[g]=i);return v&&k5(o,n,v),o},wS=(t,e,n)=>M5(t,typeof e!="symbol"?e+"":e,n),O5,xm;const uue=20,due=100;O5=[Un];class _b{constructor(e){this.editor=e,lue(xm,5,this),wS(this,"prevDroppingShapeId",null),wS(this,"droppingNodeTimer",null),wS(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,uue,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,due,n))}setDragTimer(e,n,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.run(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,e,r)}),this.droppingNodeTimer=null},n)}handleDrag(e,n,r){var l,c,u,h,p;n=ye(n.map(f=>this.editor.getShape(f.id)));const o=((l=this.editor.getDroppingOverShape(e,n))==null?void 0:l.id)??null;if(o===this.prevDroppingShapeId){this.hintParents(n);return}const{prevDroppingShapeId:s}=this,i=s&&this.editor.getShape(s),a=o&&this.editor.getShape(o);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,n)),a&&((p=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(h,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=o}hintParents(e){const n=new Map;for(const o of e){const s=this.editor.findShapeAncestor(o,i=>i.type!=="group");s&&(n.has(s.id)||n.set(s.id,[]),n.get(s.id).push(o.id))}const r=[];for(const[o,s]of n){const i=this.editor.getShape(o);i&&I3(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()}}xm=sue();cue(xm,1,"dispose",O5,_b);aue(xm,_b);var hue=Object.create,D5=Object.defineProperty,pue=Object.getOwnPropertyDescriptor,R5=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),L5=t=>{throw TypeError(t)},$5=(t,e,n)=>e in t?D5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fue=t=>[,,,hue((t==null?void 0:t[R5("metadata")])??null)],F5=["class","method","getter","setter","accessor","field","value","get","set"],N5=t=>t!==void 0&&typeof t!="function"?L5("Function expected"):t,gue=(t,e,n,r,o)=>({kind:F5[t],name:e,metadata:r,addInitializer:s=>n._?L5("Already initialized"):o.push(N5(s||null))}),mue=(t,e)=>$5(e,R5("metadata"),t[3]),yue=(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},Sue=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=F5[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,pue(o,n)),S=r.length-1;S>=0;S--)l=gue(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,N5(i)&&(v[g]=i);return v&&D5(o,n,v),o},Rs=(t,e,n)=>$5(t,typeof e!="symbol"?e+"":e,n),z5,ix,wm;class bm extends(ix=ie,z5=[Un],ix){constructor(){super(...arguments),yue(wm,5,this),Rs(this,"info",{}),Rs(this,"selectionSnapshot",{}),Rs(this,"snapshot",{}),Rs(this,"markId",""),Rs(this,"isCloning",!1),Rs(this,"isCreating",!1),Rs(this,"dragAndDropManager",new _b(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=BE(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=BE(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),vue({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=Dn(o.parentId)?null:q.Inverse(e.getShapePageTransform(o.parentId));r.parentTransform=s})}}wm=fue(ix);Sue(wm,1,"updateParentTransforms",z5,bm);mue(wm,bm);Rs(bm,"id","translating");function BE(t){var h;const e=[],n=[],r=t.getSelectedShapeIds(),o=ye(r.map(p=>{const f=t.getShape(p);if(!f)return null;e.push(f);const g=t.getShapePageTransform(p),m=g.point(),v=g.rotation();n.push(m);const S=yr.isId(f.parentId)?null:q.Inverse(t.getShapePageTransform(f.parentId));return{shape:f,pagePoint:m,pageRotation:v,parentTransform:S}})),s=t.getOnlySelectedShape();let i=[];if(s)i=t.snaps.shapeBounds.getSnapPoints(s.id);else{const p=t.getSelectionPageBounds();p&&(i=p.cornersAndCenter.map((f,g)=>({id:"selection:"+g,x:f.x,y:f.y})))}let a,l;const{originPagePoint:c}=t.inputs,u=o.filter(p=>t.isShapeOfType(p.shape,"note")&&t.isPointInShape(p.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const p=t.getCurrentPageShapesSorted();l=(h=u.map(f=>({snapshot:f,index:p.findIndex(g=>g.id===f.shape.id)})).sort((f,g)=>g.index-f.index)[0])==null?void 0:h.snapshot}return l&&(a=L$(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 vue({editor:t,snapshot:e}){const{inputs:n}=t,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=e,c=t.getInstanceState().isGridMode,u=t.getDocumentSettings().gridSize,h=x.Sub(n.currentPagePoint,n.originPagePoint),p=t.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;if(p==="x"?h.x=0:p==="y"&&(h.y=0),t.snaps.clearIndicators(),(t.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey)&&t.inputs.pointerVelocity.len()<.5){const{nudge:v}=t.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:s,lockedAxis:p,initialSelectionSnapPoints:i});h.add(v)}else if(r&&o){const{scale:v}=r.shape.props,S=r.pagePoint.clone().add(h).add(gm.clone().mul(v).rot(r.pageRotation));let y=D$/t.getZoomLevel(),b=new x(0,0);for(const P of o){const C=x.Sub(S,P),I=C.len();I<y&&(y=I,b=C)}h.sub(b)}const g=x.Add(l,h);c&&!n.ctrlKey&&g.snapToGrid(u);const m=x.Sub(g,l);t.updateShapes(ye(a.map(({shape:v,pagePoint:S,parentTransform:y})=>{const b=x.Add(S,m),P=y?q.applyToPoint(y,b):b;return{id:v.id,type:v.type,x:P.x,y:P.y}})))}class Ap extends ie{constructor(){super(...arguments);E(this,"reactor")}static children(){return[sx,Pb,Qce,x5,C5,bm,u5,E5,Cb,P5,d5,S5,_5,I5,b5,v5,w5,m5]}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=is("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){typeof process<"u",console.error(n)}})}onExit(){var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}E(Ap,"id","select"),E(Ap,"initial","idle"),E(Ap,"isLockable",!1);class B5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n}onPointerDown(){this.parent.transition("pointing",this.info)}}E(B5,"id","idle");class U5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n}onPointerUp(){this.complete()}onPointerMove(){this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{animation:{duration:220}}):this.editor.zoomIn(n,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}E(U5,"id","pointing");class H5 extends ie{constructor(){super(...arguments);E(this,"info",{});E(this,"zoomBrush",new Z)}onEnter(n){this.info=n,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Z.FromPoints([n,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:n}=this,r=8/this.editor.getZoomLevel();if(n.width<r&&n.height<r){const o=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(o,{animation:{duration:220}}):this.editor.zoomIn(o,{animation:{duration:220}})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:o,animation:{duration:220}})}this.parent.transition("idle",this.info)}}E(H5,"id","zoom_brushing");class jp extends ie{constructor(){super(...arguments);E(this,"info",{})}static children(){return[B5,H5,U5]}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)}onKeyDown(){this.updateCursor()}onKeyUp(n){this.updateCursor(),n.code==="KeyZ"&&this.complete()}onInterrupt(){this.complete()}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}E(jp,"id","zoom"),E(jp,"initial","idle"),E(jp,"isLockable",!1);const xue=[kp,Tp,Mp,jp,Ap];function wue(){const t=z(),e=H("follow",()=>t.getInstanceState().followingUserId,[t]);return e?d.jsx(bue,{userId:e}):null}function bue({userId:t}){const e=Mg(t);return e?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let ax={fonts:{draw:`${Vs()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${Vs()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${Vs()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${Vs()}/fonts/IBMPlexMono-Medium.woff2`}};function K5(t){return w.useMemo(()=>t?{fonts:{...ax.fonts,...t==null?void 0:t.fonts}}:ax,[t])}const Pue=["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 Ac={...ax,icons:Object.fromEntries(Pue.map(t=>[t,`${Vs()}/icons/icon/0_merged.svg#${t}`])),translations:Object.fromEntries(Lu.map(t=>[t.locale,`${Vs()}/translations/${t.locale}.json`])),embedIcons:Object.fromEntries(z1.map(t=>[t.type,`${Vs()}/embed-icons/${t.type}.png`]))};function Cue(t){return t?{fonts:Object.assign({...Ac.fonts},{...t==null?void 0:t.fonts}),icons:Object.assign({...Ac.icons},{...t==null?void 0:t.icons}),embedIcons:Object.assign({...Ac.embedIcons},{...t==null?void 0:t.embedIcons}),translations:Object.assign({...Ac.translations},{...t==null?void 0:t.translations})}:Ac}function _ue(){const{addToast:t,removeToast:e,clearToasts:n}=$o(),{addDialog:r,clearDialogs:o,removeDialog:s}=wa(),a=Mn()<St.TABLET_SM,l=Ce();return w.useMemo(()=>({addToast:t,removeToast:e,clearToasts:n,addDialog:r,removeDialog:s,clearDialogs:o,msg:l,isMobile:a}),[r,t,o,n,l,s,e,a])}function Iue(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)=>{for(const s of t)s.actions&&(o=s.actions(r,o,e));return o},tools:(r,o,s)=>{for(const i of t)i.tools&&(o=i.tools(r,o,{...e,...s}));return o},translations:n}}function W5(t){return w.useMemo(()=>t,t)}function Eue(t){const e=W5(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 kue(t){const e=_ue(),n=W5(t==null?[]:Array.isArray(t)?t:[t]);return w.useMemo(()=>Iue(n,e),[n,e])}var Ib="Popover",[G5,oge]=xa(Ib,[am]),Cd=am(),[Tue,ki]=G5(Ib),V5=t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=t,a=Cd(e),l=w.useRef(null),[c,u]=w.useState(!1),[h=!1,p]=Ii({prop:r,defaultProp:o,onChange:s});return d.jsx(Q1,{...a,children:d.jsx(Tue,{scope:e,contentId:cs(),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})})};V5.displayName=Ib;var Y5="PopoverAnchor",Mue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=ki(Y5,n),s=Cd(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=o;return w.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(J1,{...s,...r,ref:e})});Mue.displayName=Y5;var X5="PopoverTrigger",q5=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=ki(X5,n),s=Cd(n),i=Qe(e,o.triggerRef),a=d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":tF(o.open),...r,ref:i,onClick:oe(t.onClick,o.onOpenToggle)});return o.hasCustomAnchor?a:d.jsx(J1,{asChild:!0,...s,children:a})});q5.displayName=X5;var Eb="PopoverPortal",[Aue,jue]=G5(Eb,{forceMount:void 0}),Z5=t=>{const{__scopePopover:e,forceMount:n,children:r,container:o}=t,s=ki(Eb,e);return d.jsx(Aue,{scope:e,forceMount:n,children:d.jsx(lo,{present:n||s.open,children:d.jsx(vd,{asChild:!0,container:o,children:r})})})};Z5.displayName=Eb;var Ll="PopoverContent",Q5=w.forwardRef((t,e)=>{const n=jue(Ll,t.__scopePopover),{forceMount:r=n.forceMount,...o}=t,s=ki(Ll,t.__scopePopover);return d.jsx(lo,{present:r||s.open,children:s.modal?d.jsx(Oue,{...o,ref:e}):d.jsx(Due,{...o,ref:e})})});Q5.displayName=Ll;var Oue=w.forwardRef((t,e)=>{const n=ki(Ll,t.__scopePopover),r=w.useRef(null),o=Qe(e,r),s=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return k1(i)},[]),d.jsx(Xg,{as:aa,allowPinchZoom:!0,children:d.jsx(J5,{...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})})})}),Due=w.forwardRef((t,e)=>{const n=ki(Ll,t.__scopePopover),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(J5,{...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()}})}),J5=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=ki(Ll,n),f=Cd(n);return E1(),d.jsx(Vg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Sd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:d.jsx(sL,{"data-state":tF(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)"}})})})}),eF="PopoverClose",Rue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=ki(eF,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});Rue.displayName=eF;var Lue="PopoverArrow",$ue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Cd(n);return d.jsx(iL,{...o,...r,ref:e})});$ue.displayName=Lue;function tF(t){return t?"open":"closed"}var kb=V5,Tb=q5,Mb=Z5,Ab=Q5;function jb({id:t,children:e,onOpenChange:n,open:r}){const[o,s]=Cs(t,n);return d.jsx(kb,{onOpenChange:s,open:r||o,children:d.jsx("div",{className:"tlui-popover",children:e})})}function Ob({children:t}){return d.jsx(Tb,{asChild:!0,dir:"ltr",children:t})}function Db({side:t,children:e,align:n="center",sideOffset:r=8,alignOffset:o=0,disableEscapeKeyDown:s=!1}){const i=Mt();return d.jsx(Mb,{container:i,children:d.jsx(Ab,{className:"tlui-popover__content",side:t,sideOffset:r,align:n,alignOffset:o,dir:"ltr",onEscapeKeyDown:a=>s&&a.preventDefault(),children:e})})}function Fue(t){return t.getSelectedShapeIds().map(r=>t.getShape(r)).filter(r=>{if(!r)return!1;if(t.isShapeOfType(r,"arrow")){const o=zn(t,r);if(o.start||o.end)return!1}return!0})}const nF=()=>{const t=z();return H("threeStackableItems",()=>Fue(t).length>2,[t])},_s=()=>{const t=z();return H("isInSelectState",()=>t.isIn("select"),[t])},rF=()=>{const t=z();return H("allow group",()=>{const e=t.getSelectedShapes();if(e.length<2)return!1;for(const n of e)if(t.isShapeOfType(n,"arrow")){const r=zn(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])},oF=()=>{const t=z();return H("allowUngroup",()=>t.getSelectedShapeIds().some(e=>{var n;return((n=t.getShape(e))==null?void 0:n.type)==="group"}),[t])},Nue=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function sF(t,e){const n=z();return H("selectedShapes",()=>n.getSelectedShapes().length>=t,[n,t,e])}function An(t,e){const n=z();return H("selectedShapes",()=>{const r=n.getSelectedShapes().filter(o=>!n.isShapeOrAncestorLocked(o)).length;return t===void 0?r:r>=t},[n])}function zue(){const t=z();return H("showAutoSizeToggle",()=>{const e=t.getSelectedShapes();return e.length===1&&t.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[t])}function iF(){const t=z();return H("hasLinkShapeSelected",()=>{const e=t.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[t])}function Bue(){const t=z();return H("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 aF(){const t=z();return H("useCanRedo",()=>t.getCanRedo(),[t])}function lF(){const t=z();return H("useCanUndo",()=>t.getCanUndo(),[t])}function Uue(){return d.jsxs(d.Fragment,{children:[d.jsx(Hue,{}),d.jsx(Kue,{}),d.jsx(Wue,{}),d.jsx(Gue,{}),d.jsx(Vue,{}),d.jsx(que,{}),d.jsx(Zue,{}),d.jsx(Que,{})]})}function Hue(){const t=An(2),e=_s(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(K,{actionId:"align-left",disabled:!n}),d.jsx(K,{actionId:"align-center-horizontal",disabled:!n}),d.jsx(K,{actionId:"align-right",disabled:!n}),d.jsx(K,{actionId:"stretch-horizontal",disabled:!n}),d.jsx(K,{actionId:"align-top",disabled:!n}),d.jsx(K,{actionId:"align-center-vertical",disabled:!n}),d.jsx(K,{actionId:"align-bottom",disabled:!n}),d.jsx(K,{actionId:"stretch-vertical",disabled:!n})]})}function Kue(){const t=An(3),e=_s(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(K,{actionId:"distribute-horizontal",disabled:!n}),d.jsx(K,{actionId:"distribute-vertical",disabled:!n})]})}function Wue(){const t=nF(),e=_s(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(K,{actionId:"stack-horizontal",disabled:!n}),d.jsx(K,{actionId:"stack-vertical",disabled:!n})]})}function Gue(){const t=An(1),e=_s(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(K,{actionId:"send-to-back",disabled:!n}),d.jsx(K,{actionId:"send-backward",disabled:!n}),d.jsx(K,{actionId:"bring-forward",disabled:!n}),d.jsx(K,{actionId:"bring-to-front",disabled:!n})]})}function Vue(){return Mn()<St.TABLET_SM?d.jsx(Yue,{}):d.jsx(Xue,{})}function Yue(){const t=z(),e=H("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(K,{actionId:"zoom-to-100",disabled:e})}function Xue(){const t=An(1),e=_s(),n=t&&e;return d.jsx(K,{actionId:"rotate-ccw",disabled:!n})}function que(){const t=An(1),e=_s(),n=t&&e;return d.jsx(K,{actionId:"rotate-cw",disabled:!n})}function Zue(){const t=iF(),e=_s(),n=t&&e;return d.jsx(K,{actionId:"edit-link",disabled:!n})}function Que(){const t=rF(),e=oF();return t?d.jsx(UE,{}):e?d.jsx(Jue,{}):d.jsx(UE,{})}function UE(){const t=An(2),e=_s(),n=t&&e;return d.jsx(K,{actionId:"group",disabled:!n})}function Jue(){return d.jsx(K,{actionId:"ungroup"})}const ede=w.memo(function({children:e}){const n=Ce(),r=Mn(),o=Ps(),s=w.useRef(null);_i(s);const i=z(),a=H("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),l=e??d.jsx(Uue,{});if(!(o&&!a))return d.jsxs(jb,{id:"actions-menu",children:[d.jsx(Ob,{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(Db,{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(Lr,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function ve({id:t,label:e,children:n}){const{type:r,sourceId:o}=hm(),s=Ce(),i=zu(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(wae,{"data-testid":`${o}-group.${t}`,children:n});case"context-menu":return d.jsx(s$,{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}=hm(),a=Mt(),l=Ce(),c=n?typeof n=="string"?n:n[s]??n.default:void 0,u=c?l(c):void 0;switch(s){case"menu":return d.jsxs(Sae,{id:`${i}-sub.${t}`,children:[d.jsx(vae,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:e,label:u,title:u}),d.jsx(xae,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return e?null:d.jsxs(tde,{id:`${i}-sub.${t}`,children:[d.jsx(c$,{dir:"ltr",disabled:e,asChild:!0,children:d.jsxs(ce,{"data-testid":`${i}-sub-trigger.${t}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[d.jsx(Pt,{children:u}),d.jsx(be,{icon:"chevron-right",small:!0})]})}),d.jsx(cb,{container:a,children:d.jsx(u$,{"data-testid":`${i}-sub-content.${t}`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:o})})]});default:return o}}function tde({id:t,children:e}){const[n,r]=Cs(t);return d.jsx(l$,{open:n,onOpenChange:r,children:e})}function cF(){return zue()?d.jsx(K,{actionId:"toggle-auto-size"}):null}function uF(){return iF()?d.jsx(K,{actionId:"edit-link"}):null}function nde(){return An(1)?d.jsx(K,{actionId:"duplicate"}):null}function dF(){const t=z();return H("should display flatten option",()=>{if(t.getSelectedShapeIds().length===0)return!1;const r=t.getOnlySelectedShape();return!(r&&t.isShapeOfType(r,"image"))},[t])?d.jsx(K,{actionId:"flatten-to-image"}):null}function hF(){return rF()?d.jsx(K,{actionId:"group"}):null}function pF(){return oF()?d.jsx(K,{actionId:"ungroup"}):null}function fF(){const t=z();return H("allow unframe",()=>{const n=t.getSelectedShapes();return n.length===0?!1:n.every(r=>t.isShapeOfType(r,"frame"))},[t])?d.jsx(K,{actionId:"remove-frame"}):null}function gF(){const t=z();return H("allow fit frame to content",()=>{const n=t.getOnlySelectedShape();return n?t.isShapeOfType(n,"frame")&&t.getSortedChildIdsForParent(n).length>0:!1},[t])?d.jsx(K,{actionId:"fit-frame-to-content"}):null}function mF(){const t=z();return H("selected shapes",()=>t.getSelectedShapes().length>0,[t])?d.jsx(K,{actionId:"toggle-lock"}):null}function Rb(){const t=z(),e=H("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(uo,{actionId:"toggle-transparent",checked:e,toggle:!0})}function rde(){const t=z(),e=H("any shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(K,{actionId:"unlock-all",disabled:!e})}function yF(){const t=z(),e=H("zoomed to 100",()=>t.getZoomLevel()===1,[t]);return d.jsx(K,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function SF(){const t=z(),e=H("has shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(K,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function vF(){const t=z(),e=H("has shapes",()=>t.getSelectedShapeIds().length>0,[t]);return d.jsx(K,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function xF(){return d.jsxs(ve,{id:"clipboard",children:[d.jsx(sde,{}),d.jsx(ide,{}),d.jsx(ade,{}),d.jsx(nde,{}),d.jsx(lde,{})]})}function ode(){var n;const t=z(),e=H("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(K,{actionId:"copy-as-svg"}),!!((n=window.navigator.clipboard)!=null&&n.write)&&d.jsx(K,{actionId:"copy-as-png"}),d.jsx(K,{actionId:"copy-as-json"})]}),d.jsx(ve,{id:"copy-as-bg",children:d.jsx(Rb,{})})]})}function sde(){const t=An(1);return d.jsx(K,{actionId:"cut",disabled:!t})}function ide(){const t=sF(1);return d.jsx(K,{actionId:"copy",disabled:!t})}function ade(){const t=Nue;return d.jsx(K,{actionId:"paste",disabled:!t})}function wF(){const t=z();return H("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(K,{actionId:"export-as-svg"}),d.jsx(K,{actionId:"export-as-png"}),d.jsx(K,{actionId:"export-as-json"})]}),d.jsx(ve,{id:"export-as-bg",children:d.jsx(Rb,{})})]})]}):null}function bF(){const t=z(),e=H("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(K,{actionId:"select-all",disabled:!e})}function lde(){const t=An(1);return d.jsx(K,{actionId:"delete",disabled:!t})}function cde(){return sF(1)?d.jsxs(Jn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(hF,{}),d.jsx(pF,{}),d.jsx(dF,{}),d.jsx(uF,{}),d.jsx(gF,{}),d.jsx(fF,{}),d.jsx(CF,{}),d.jsx(PF,{}),d.jsx(cF,{}),d.jsx(mF,{})]}):null}function ude(){const t=An(2),e=Bue();return t||e?d.jsxs(Jn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[t&&d.jsxs(ve,{id:"align",children:[d.jsx(K,{actionId:"align-left"}),d.jsx(K,{actionId:"align-center-horizontal"}),d.jsx(K,{actionId:"align-right"}),d.jsx(K,{actionId:"align-top"}),d.jsx(K,{actionId:"align-center-vertical"}),d.jsx(K,{actionId:"align-bottom"})]}),d.jsx(dde,{}),t&&d.jsxs(ve,{id:"stretch",children:[d.jsx(K,{actionId:"stretch-horizontal"}),d.jsx(K,{actionId:"stretch-vertical"})]}),(t||e)&&d.jsxs(ve,{id:"flip",children:[d.jsx(K,{actionId:"flip-horizontal"}),d.jsx(K,{actionId:"flip-vertical"})]}),d.jsx(hde,{})]}):null}function dde(){return An(3)?d.jsxs(ve,{id:"distribute",children:[d.jsx(K,{actionId:"distribute-horizontal"}),d.jsx(K,{actionId:"distribute-vertical"})]}):null}function hde(){const t=An(2),e=nF();return t?d.jsxs(ve,{id:"order",children:[d.jsx(K,{actionId:"pack"}),e&&d.jsx(K,{actionId:"stack-horizontal"}),e&&d.jsx(K,{actionId:"stack-vertical"})]}):null}function pde(){return An(1)?d.jsx(Jn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(ve,{id:"reorder",children:[d.jsx(K,{actionId:"bring-to-front"}),d.jsx(K,{actionId:"bring-forward"}),d.jsx(K,{actionId:"send-backward"}),d.jsx(K,{actionId:"send-to-back"})]})}):null}function fde(){const t=z(),e=H("pages",()=>t.getPages(),[t]),n=H("current page id",()=>t.getCurrentPageId(),[t]),{addToast:r}=$o(),o=Qt();return An(1)?d.jsxs(Jn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ve,{id:"pages",children:e.map(i=>d.jsx(Kt,{id:i.id,disabled:n===i.id,label:i.name,onSelect:()=>{t.markHistoryStoppingPoint("move_shapes_to_page"),t.moveShapesToPage(t.getSelectedShapeIds(),i.id);const a=t.getPage(i.id);a&&r({title:"Changed Page",description:`Moved to ${a.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{t.markHistoryStoppingPoint("change-page"),t.setCurrentPage(n)}}]}),o("move-to-page",{source:"context-menu"})}},i.id))}),d.jsx(ve,{id:"new-page",children:d.jsx(K,{actionId:"move-to-new-page"})})]}):null}function PF(){const t=z();return H("oneEmbedSelected",()=>{const n=t.getOnlySelectedShape();return n?!!(t.isShapeOfType(n,"embed")&&n.props.url&&!t.isShapeOrAncestorLocked(n)):!1},[t])?d.jsx(K,{actionId:"convert-to-bookmark"}):null}function CF(){const t=z(),e=B1();return H("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(K,{actionId:"convert-to-embed"}):null}function gde(){const t=z(),e=H("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(uo,{actionId:"toggle-snap-mode",checked:e})}function mde(){const t=z(),e=H("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(uo,{actionId:"toggle-tool-lock",checked:e})}function yde(){const t=z(),e=H("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(uo,{actionId:"toggle-grid",checked:e})}function Sde(){const t=z(),e=H("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(uo,{actionId:"toggle-wrap-mode",checked:e})}function vde(){const t=z(),e=H("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(uo,{actionId:"toggle-focus-mode",checked:e})}function xde(){const t=z(),e=H("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(uo,{actionId:"toggle-edge-scrolling",checked:e===1})}function wde(){const t=z(),e=H("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(uo,{actionId:"toggle-reduce-motion",checked:e===0})}function bde(){const t=z(),e=H("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(uo,{actionId:"toggle-debug-mode",checked:e})}function Pde(){const t=z(),e=H("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(uo,{actionId:"toggle-dynamic-size-mode",checked:e})}function Cde(){const t=z(),e=H("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(uo,{actionId:"toggle-paste-at-cursor",checked:e})}function _de(){const t=z();return H("show cursor chat",()=>t.getCurrentToolId()==="select"&&!t.getInstanceState().isCoarsePointer,[t])?d.jsx(K,{actionId:"open-cursor-chat"}):null}function Ide(){const t=z(),e=rm(),n=H("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]),r=H("isSinglePageMode",()=>t.options.maxPages<=1,[t]);return n?d.jsxs(d.Fragment,{children:[e&&d.jsx(_de,{}),d.jsxs(ve,{id:"modify",children:[d.jsx(cde,{}),d.jsx(ude,{}),d.jsx(pde,{}),!r&&d.jsx(fde,{})]}),d.jsx(xF,{}),d.jsx(wF,{}),d.jsx(ve,{id:"select-all",children:d.jsx(bF,{})})]}):null}const Ede=w.memo(function({children:e,disabled:n=!1}){const r=z(),{Canvas:o}=ot(),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]=Cs("context menu",s),c=e??d.jsx(Ide,{});return d.jsxs(Lie,{dir:"ltr",onOpenChange:l,modal:!1,children:[d.jsx($ie,{onContextMenu:void 0,dir:"ltr",disabled:n,children:o?d.jsx(o,{}):null}),a&&d.jsx(Fie,{container:i,children:d.jsx(Nie,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:xe,children:d.jsx(Lr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),kde=2e3,Tde=5e3,Mde=$t(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?Tde:kde;o.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},l)}return()=>{clearTimeout(o.current)}},[e,r,n]),n?d.jsx(jde,{value:s,setValue:i,chatMessage:r}):r.trim()?d.jsx(Ade,{chatMessage:r}):null});function _F(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 Ade=({chatMessage:t})=>{const e=z(),n=w.useRef(null);return _F(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:t})},jde=$t(function({chatMessage:e,value:n,setValue:r}){const o=z(),s=Ce(),i=w.useRef(null),a=e||s("cursor-chat.type-to-chat");_F(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 lx({checked:t}){return d.jsx(Ao,{icon:t?"check":"none",className:"tlui-button__icon",small:!0})}function Ode(){const t=z(),{addToast:e}=$o(),{addDialog:n}=wa(),[r,o]=Te.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"items",children:[d.jsx(Kt,{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(Kt,{id:"show-dialog",label:"Show dialog",onSelect:()=>{n({component:({onClose:s})=>d.jsx(Lde,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),d.jsx(Kt,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>$de(t,100)}),d.jsx(Kt,{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(Kt,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),d.jsx(Kt,{id:"hard-reset",onSelect:lj,label:"Hard reset"})]}),d.jsxs(ve,{id:"flags",children:[d.jsx(Dde,{}),d.jsx(Rde,{})]})]})}function Dde(){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(IF,{flag:e},e.name))})}):null}function Rde(){const t=Object.values(GY);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(IF,{flag:e},e.name))})}):null}function Lde({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(Jg,{children:[d.jsx(em,{children:t}),d.jsx(tm,{})]}),d.jsx(Nu,{style:{maxWidth:350},children:e}),d.jsxs(N1,{className:"tlui-dialog__footer__actions",children:[o&&d.jsxs(ce,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(lx,{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 IF=$t(function({flag:e,onChange:n}){const r=e.get();return d.jsx(pm,{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 HE=0;function $de(t,e){const n=Array(e),r=Math.floor(Math.sqrt(e));for(let o=0;o<e;o++)HE++,n[o]={id:Be("box"+HE),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};t.run(()=>{t.createShapes(n).setSelectedShapes(n.map(o=>o.id))})}function Fde({children:t}){const e=t??d.jsx(Ode,{});return d.jsxs(ua,{id:"debug",children:[d.jsx(da,{children:d.jsx(ce,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(ha,{side:"top",align:"end",alignOffset:0,children:d.jsx(Lr,{type:"menu",sourceId:"debug-panel",children:e})})]})}const Nde=w.memo(function(){const{DebugMenu:e}=Ti(),n=w.useRef(null);return _i(n),d.jsxs("div",{ref:n,className:"tlui-debug-panel",children:[d.jsx(Bde,{}),d.jsx(Ude,{}),e&&d.jsx(e,{})]})});function zde(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 Bde=$t(function(){zde();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 Ude(){const t=z(),e=H("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 Hde=w.memo(function(){const e=Mn(),n=w.useRef(null);_i(n);const{MainMenu:r,QuickActions:o,ActionsMenu:s,PageMenu:i}=Ti(),a=z(),l=H("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 Kde(){const t=z(),e=ba(),[n,r]=w.useState(!1),o=w.useRef(!1);return ni("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(K,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Wde(){const t=z();return H("is pen mode",()=>t.getInstanceState().isPenMode,[t])?d.jsx(K,{actionId:"exit-pen-mode"}):null}function Gde(){const t=z(),e=ba();return H("is following user",()=>!!t.getInstanceState().followingUserId,[t])?d.jsx(Kt,{...e["stop-following"]}):null}function Vde(){return d.jsxs(d.Fragment,{children:[d.jsx(Wde,{}),d.jsx(Kde,{}),d.jsx(Gde,{})]})}function Yde({children:t}){const e=t??d.jsx(Vde,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(Lr,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function Xde(){const t=rm();return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(K,{actionId:"toggle-tool-lock"}),d.jsx(K,{actionId:"insert-media"}),d.jsx(Rn,{toolId:"select"}),d.jsx(Rn,{toolId:"draw"}),d.jsx(Rn,{toolId:"eraser"}),d.jsx(Rn,{toolId:"hand"}),d.jsx(Rn,{toolId:"rectangle"}),d.jsx(Rn,{toolId:"ellipse"}),d.jsx(Rn,{toolId:"arrow"}),d.jsx(Rn,{toolId:"line"}),d.jsx(Rn,{toolId:"text"}),d.jsx(Rn,{toolId:"frame"}),d.jsx(Rn,{toolId:"note"}),d.jsx(Rn,{toolId:"laser"}),d.jsx(Kt,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),d.jsxs(ve,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(K,{actionId:"toggle-dark-mode"}),d.jsx(K,{actionId:"toggle-focus-mode"}),d.jsx(K,{actionId:"toggle-grid"})]}),d.jsxs(ve,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(K,{actionId:"undo"}),d.jsx(K,{actionId:"redo"}),d.jsx(K,{actionId:"cut"}),d.jsx(K,{actionId:"copy"}),d.jsx(K,{actionId:"paste"}),d.jsx(K,{actionId:"select-all"}),d.jsx(K,{actionId:"delete"}),d.jsx(K,{actionId:"duplicate"})]}),d.jsxs(ve,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(K,{actionId:"zoom-in"}),d.jsx(K,{actionId:"zoom-out"}),d.jsx(K,{actionId:"zoom-to-100"}),d.jsx(K,{actionId:"zoom-to-fit"}),d.jsx(K,{actionId:"zoom-to-selection"})]}),d.jsxs(ve,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(K,{actionId:"bring-to-front"}),d.jsx(K,{actionId:"bring-forward"}),d.jsx(K,{actionId:"send-backward"}),d.jsx(K,{actionId:"send-to-back"}),d.jsx(K,{actionId:"group"}),d.jsx(K,{actionId:"ungroup"}),d.jsx(K,{actionId:"flip-horizontal"}),d.jsx(K,{actionId:"flip-vertical"}),d.jsx(K,{actionId:"align-top"}),d.jsx(K,{actionId:"align-center-vertical"}),d.jsx(K,{actionId:"align-bottom"}),d.jsx(K,{actionId:"align-left"}),d.jsx(K,{actionId:"align-center-horizontal"}),d.jsx(K,{actionId:"align-right"})]}),t&&d.jsx(ve,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:d.jsx(K,{actionId:"open-cursor-chat"})})]})}const qde=w.memo(function({children:e}){const n=Ce(),r=Mn(),o=e??d.jsx(Xde,{});return d.jsxs(d.Fragment,{children:[d.jsxs(Jg,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(em,{children:n("shortcuts-dialog.title")}),d.jsx(tm,{})]}),d.jsx(Nu,{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(Lr,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})}),Zde=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Qde(){const t=z(),e=Qt(),n=H("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:"languages",children:Zde.map(({colorScheme:r,label:o})=>d.jsx(pm,{id:`color-scheme-${r}`,label:o,checked:r===n,onSelect:()=>{t.user.updateUserPreferences({colorScheme:r}),e("color-scheme",{source:"menu",value:r})}},r))})})}function EF(){const t=z(),e=Qt(),n=H("locale",()=>t.user.getLocale(),[t]);return d.jsx(Jn,{id:"help menu language",label:"menu.language",children:d.jsx(ve,{id:"languages",children:Lu.map(({locale:r,label:o})=>d.jsx(pm,{id:`language-${r}`,title:r,label:o,checked:r===n,onSelect:()=>{t.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})})}function Jde(){return d.jsxs(d.Fragment,{children:[d.jsx(EF,{}),d.jsx(kF,{})]})}function kF(){const{KeyboardShortcutsDialog:t}=Ti(),{addDialog:e}=wa(),n=w.useCallback(()=>{t&&e({component:t})},[e,t]);return t?d.jsx(Kt,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:n}):null}function ehe(){return d.jsxs(d.Fragment,{children:[d.jsx(nhe,{}),d.jsx(ihe,{}),d.jsx(the,{}),d.jsx(ahe,{}),d.jsx(lhe,{})]})}function the(){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(K,{actionId:"export-all-as-svg"}),d.jsx(K,{actionId:"export-all-as-png"}),d.jsx(K,{actionId:"export-all-as-json"})]}),d.jsx(ve,{id:"export-all-as-bg",children:d.jsx(Rb,{})})]})}function nhe(){const t=z(),e=H("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]);return d.jsxs(Jn,{id:"edit",label:"menu.edit",disabled:!e,children:[d.jsx(she,{}),d.jsx(xF,{}),d.jsx(wF,{}),d.jsx(rhe,{}),d.jsx(ohe,{}),d.jsx(ve,{id:"select-all",children:d.jsx(bF,{})})]})}function rhe(){return d.jsxs(ve,{id:"misc",children:[d.jsx(hF,{}),d.jsx(pF,{}),d.jsx(uF,{}),d.jsx(cF,{}),d.jsx(fF,{}),d.jsx(gF,{}),d.jsx(CF,{}),d.jsx(PF,{}),d.jsx(dF,{})]})}function ohe(){return d.jsxs(ve,{id:"lock",children:[d.jsx(mF,{}),d.jsx(rde,{})]})}function she(){const t=lF(),e=aF();return d.jsxs(ve,{id:"undo-redo",children:[d.jsx(K,{actionId:"undo",disabled:!t}),d.jsx(K,{actionId:"redo",disabled:!e})]})}function ihe(){return d.jsx(Jn,{id:"view",label:"menu.view",children:d.jsxs(ve,{id:"view-actions",children:[d.jsx(K,{actionId:"zoom-in"}),d.jsx(K,{actionId:"zoom-out"}),d.jsx(yF,{}),d.jsx(SF,{}),d.jsx(vF,{})]})})}function ahe(){return d.jsxs(ve,{id:"extras",children:[d.jsx(K,{actionId:"insert-embed"}),d.jsx(K,{actionId:"insert-media"})]})}function lhe(){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(gde,{}),d.jsx(mde,{}),d.jsx(yde,{}),d.jsx(Sde,{}),d.jsx(vde,{}),d.jsx(xde,{}),d.jsx(wde,{}),d.jsx(Pde,{}),d.jsx(Cde,{}),d.jsx(bde,{})]}),d.jsx(ve,{id:"color-scheme",children:d.jsx(Qde,{})})]}),d.jsx(EF,{}),d.jsx(kF,{})]})}const che=w.memo(function({children:e}){const n=Mt(),[r,o]=Cs("main menu"),s=Ce(),i=e??d.jsx(ehe,{});return d.jsxs(db,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(hb,{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(dm,{container:n,children:d.jsx(pb,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(Lr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),bS={};function jc(t){if(bS[t])return bS[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 bS[t]=a,a}const Op=10,TF=4*6*Op+12+4*12;function Fa(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 Na(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 uhe(t,e,n){const r=Op;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 Fa(t,{center:e.center,radius:n,numArcSegments:Op*4}),Op*4*6;let s=0;return Na(t,s,o.minX,o.minY,o.w,o.h),s+=12,Na(t,s,o.minX,e.minY,o.w,n),s+=12,Na(t,s,o.maxX,o.minY,n,o.h),s+=12,Na(t,s,o.minX,o.maxY,o.w,n),s+=12,Na(t,s,e.minX,o.minY,n,o.h),s+=12,Fa(t,{numArcSegments:r,offset:s,center:o.point,radius:n,startAngle:De,endAngle:De*1.5}),s+=r*6,Fa(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,Fa(t,{numArcSegments:r,offset:s,center:x.Add(o.point,o.size),radius:n,startAngle:0,endAngle:Ze}),s+=r*6,Fa(t,{numArcSegments:r,offset:s,center:x.Add(o.point,new x(0,o.h)),radius:n,startAngle:Ze,endAngle:De}),TF}function dhe(t){if(!t)throw new Error("Canvas element not found");const e=t.getContext("webgl2",{premultipliedAlpha:!1});if(!e)throw new Error("Failed to get webgl2 context");const n=`#version 300 es
|
|
390
|
-
precision mediump float;
|
|
391
|
-
|
|
392
|
-
in vec2 shapeVertexPosition;
|
|
393
|
-
|
|
394
|
-
uniform vec4 canvasPageBounds;
|
|
395
|
-
|
|
396
|
-
// taken (with thanks) from
|
|
397
|
-
// https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
|
|
398
|
-
void main() {
|
|
399
|
-
// convert the position from pixels to 0.0 to 1.0
|
|
400
|
-
vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
|
|
401
|
-
|
|
402
|
-
// convert from 0->1 to 0->2
|
|
403
|
-
vec2 zeroToTwo = zeroToOne * 2.0;
|
|
404
|
-
|
|
405
|
-
// convert from 0->2 to -1->+1 (clipspace)
|
|
406
|
-
vec2 clipSpace = zeroToTwo - 1.0;
|
|
407
|
-
|
|
408
|
-
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
409
|
-
}`,r=e.createShader(e.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const o=`#version 300 es
|
|
410
|
-
precision mediump float;
|
|
411
|
-
|
|
412
|
-
uniform vec4 fillColor;
|
|
413
|
-
out vec4 outputColor;
|
|
414
|
-
|
|
415
|
-
void main() {
|
|
416
|
-
outputColor = fillColor;
|
|
417
|
-
}`,s=e.createShader(e.FRAGMENT_SHADER);if(!s)throw new Error("Failed to create fragment shader");if(e.shaderSource(s,o),e.compileShader(s),!e.getShaderParameter(s,e.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=e.createProgram();if(!i)throw new Error("Failed to create program");if(e.attachShader(i,r),e.attachShader(i,s),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(i);const a=e.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(i,"canvasPageBounds"),c=e.getUniformLocation(i,"fillColor");if(!e.createBuffer())throw new Error("Failed to create buffer");if(!e.createBuffer())throw new Error("Failed to create buffer");return{context:e,selectedShapes:Lh(e,1024),unselectedShapes:Lh(e,4096),viewport:Lh(e,TF),collaborators:Lh(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 Lh(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(e)}}function KE(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 hhe=Object.create,MF=Object.defineProperty,phe=Object.getOwnPropertyDescriptor,fhe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),AF=t=>{throw TypeError(t)},jF=(t,e,n)=>e in t?MF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ghe=t=>[,,,hhe(null)],OF=["class","method","getter","setter","accessor","field","value","get","set"],DF=t=>t!==void 0&&typeof t!="function"?AF("Function expected"):t,mhe=(t,e,n,r,o)=>({kind:OF[t],name:e,metadata:r,addInitializer:s=>n._?AF("Already initialized"):o.push(DF(s||null))}),yhe=(t,e)=>jF(e,fhe("metadata"),t[3]),She=(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},No=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,g=OF[u+5],m=t[f]||(t[f]=[]),v=(o=o.prototype,phe(o,n)),S=r.length-1;S>=0;S--)l=mhe(u,n,a={},t[3],m),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[g],l),a._=1,DF(i)&&(v[g]=i);return v&&MF(o,n,v),o},Go=(t,e,n)=>jF(t,typeof e!="symbol"?e+"":e,n),RF,LF,$F,FF,NF,zF,BF,UF,HF,KF,wr;KF=[Un],HF=[W],UF=[W],BF=[W],zF=[W],NF=[W],FF=[W],$F=[W],LF=[W],RF=[Un];class Nr{constructor(e,n,r){this.editor=e,this.elem=n,this.container=r,She(wr,5,this),Go(this,"disposables",[]),Go(this,"gl"),Go(this,"shapeGeometryCache"),Go(this,"colors"),Go(this,"id",ze()),Go(this,"canvasBoundingClientRect",It("canvasBoundingClientRect",new Z)),Go(this,"originPagePoint",new x),Go(this,"originPageCenter",new x),Go(this,"isInViewport",!1),this.gl=dhe(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 Na(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),is("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:jc(e.getPropertyValue("--color-text-3").trim()),selectFill:jc(e.getPropertyValue("--color-selected").trim()),viewportFill:jc(e.getPropertyValue("--color-muted-1").trim()),background:jc(e.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const e=this.editor.getViewportPageBounds(),n=this.editor.getCurrentPageBounds();return n?Z.Expand(n,e):e}getContentScreenBounds(){const e=this.getContentPageBounds(),n=this.editor.pageToScreen(e.point),r=this.editor.pageToScreen(new x(e.maxX,e.maxY));return new Z(n.x,n.y,r.x-n.x,r.y-n.y)}_getCanvasBoundingRect(){const{x:e,y:n,width:r,height:o}=this.elem.getBoundingClientRect();return new Z(e,n,r,o)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const e=new ResizeObserver(()=>{const n=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(n)});return e.observe(this.elem),e.observe(this.container),()=>e.disconnect()}getCanvasSize(){const e=this.canvasBoundingClientRect.get(),n=this.getDpr();return new x(e.width*n,e.height*n)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const e=this.getCanvasScreenBounds(),n=this.getContentPageBounds(),r=e.width/e.height;let o=n.width,s=o/r;s<n.height&&(s=n.height,o=s*r);const i=new Z(0,0,o,s);return i.center=n.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:e,y:n,w:r,h:o}=this.getCanvasPageBounds();return new Float32Array([e,n,r,o])}getMinimapPagePoint(e,n){const r=this.getCanvasPageBounds(),o=this.getCanvasScreenBounds();let s=e-o.x,i=n-o.y;return s*=r.width/o.width,i*=r.height/o.height,s+=r.minX,i+=r.minY,new x(s,i,1)}minimapScreenPointToPagePoint(e,n,r=!1,o=!1){const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(e,n);if(o){const c=this.editor.getCurrentPageBounds()??new Z,u=c.minX-i.width/2,h=c.maxX+i.width/2,p=c.minY-i.height/2,f=c.maxY+i.height/2,g=Math.max(0,u+i.width-a),m=Math.max(0,-(h-i.width-a)),v=Math.max(0,p+i.height-l),S=Math.max(0,-(f-i.height-l));a+=(g-m)/2,l+=(v-S)/2,a=Bt(a,u,h),l=Bt(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)?(KE(this.gl.selectedShapes,s,h),s+=p):(KE(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=uhe(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)Fa(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(jc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}wr=ghe();No(wr,1,"close",KF,Nr);No(wr,1,"getDpr",HF,Nr);No(wr,1,"getContentPageBounds",UF,Nr);No(wr,1,"getContentScreenBounds",BF,Nr);No(wr,1,"getCanvasSize",zF,Nr);No(wr,1,"getCanvasClientPosition",NF,Nr);No(wr,1,"getCanvasPageBounds",FF,Nr);No(wr,1,"getZoom",$F,Nr);No(wr,1,"getCanvasPageBoundsArray",LF,Nr);No(wr,1,"render",RF,Nr);yhe(wr,Nr);function vhe(){const t=z(),e=Mt(),n=w.useRef(null),r=w.useRef(!1),o=w.useRef();w.useEffect(()=>{try{const u=new Nr(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(ad(h,u),!t.getCurrentPageShapeIds().size)return;r.current=!0,o.current.isInViewport=!1;const p=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=t.getViewportPageBounds(),g=o.current.getContentPageBounds();if(new Z(g.x-f.width/2,g.y-f.height/2,g.width+f.width,g.height+f.height).containsPoint(p)&&!f.containsPoint(p)){o.current.isInViewport=f.containsPoint(p);const S=x.Sub(f.center,f.point),y=x.Add(p,S);o.current.originPagePoint.setTo(y),o.current.originPageCenter.setTo(p),t.centerOnPoint(p,{animation:{duration:t.options.animationMediumMs}})}else{const S=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.isInViewport=f.containsPoint(S),o.current.originPagePoint.setTo(S),o.current.originPageCenter.setTo(f.center)}function v(S){h&&ld(h,S),r.current=!1,document.body.removeEventListener("pointerup",v)}document.body.addEventListener("pointerup",v)},[t]),a=w.useCallback(u=>{if(!o.current)return;const h=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(o.current.isInViewport){const m=o.current.originPagePoint.clone().sub(o.current.originPageCenter);t.centerOnPoint(x.Sub(h,m));return}t.centerOnPoint(h)}const p=o.current.getMinimapPagePoint(u.clientX,u.clientY),f=t.pageToScreen(p),g={type:"pointer",target:"canvas",name:"pointer_move",...Kn(u),point:f,isPen:t.getInstanceState().isPenMode};t.dispatch(g)},[t]),l=w.useCallback(u=>{const h=qA(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=yd();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 xhe(t,e){const[n,r]=Te.useState(e);Te.useLayoutEffect(()=>{const s=xw(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 ww(t,JSON.stringify(a)),a})},[t]);return[n,o]}const whe=w.memo(function(){const e=ba(),n=Ce(),r=Mn(),o=w.useRef(null);_i(o);const[s,i]=xhe("minimap",!0),a=w.useCallback(()=>{i(u=>!u)},[i]),{ZoomMenu:l,Minimap:c}=Ti();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(zu(e["zoom-out"].label))} ${K0(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(zu(e["zoom-in"].label))} ${K0(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,{})]})}),bhe=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(nm,{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})},cx=(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=wo(a.index):!a&&l?s=HB(i[0].index):s=ju(a.index,l.index),s!==i[n].index&&(t.markHistoryStoppingPoint("moving page"),t.updatePage({id:e,index:s}),o("move-page",{source:"page-menu"}))},WE=$t(function({index:e,listSize:n,item:r,onRename:o}){const s=z(),i=Ce(),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(()=>{cx(s,r.id,e,e-1,l)},[s,r,e,l]),h=w.useCallback(()=>{cx(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(ua,{id:`page item submenu ${e}`,children:[d.jsx(da,{children:d.jsx(ce,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical"})})}),d.jsx(ha,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(Lr,{type:"menu",sourceId:"page-menu",children:[d.jsxs(ve,{id:"modify",children:[o&&d.jsx(Kt,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),d.jsx(Kt,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=s.options.maxPages}),e>0&&d.jsx(Kt,{id:"move-up",onSelect:u,label:"page-menu.submenu.move-up"}),e<n-1&&d.jsx(Kt,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:h})]}),n>1&&d.jsx(ve,{id:"delete",children:d.jsx(Kt,{id:"delete",onSelect:p,label:"page-menu.submenu.delete"})})]})})]})}),Phe=w.memo(function(){const e=z(),n=Qt(),r=Ce(),o=Mn(),s=w.useCallback(()=>S(!1),[]),[i,a]=Cs("page-menu",s),l=36,c=w.useRef(null),u=H("pages",()=>e.getPages(),[e]),h=H("currentPage",()=>e.getCurrentPage(),[e]),p=H("currentPageId",()=>e.getCurrentPageId(),[e]),f=Ps(),g=H("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),m=H("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[v,S]=w.useState(!1),y=w.useCallback(()=>{f||S(O=>!O)},[f]),b=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,C]=w.useState(Object.fromEntries(u.map((O,R)=>[O.id,{y:R*l,offsetY:0,isSelected:!1}])));w.useLayoutEffect(()=>{C(Object.fromEntries(u.map((O,R)=>[O.id,{y:R*l,offsetY:0,isSelected:!1}])))},[l,u]),w.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const O=document.querySelector(`[data-testid="page-menu-item-${p}"]`);if(O){const R=c.current;if(!R)return;const B=O.offsetTop,L=R.scrollTop;B<L&&R.scrollTo({top:B});const G=B+l,$=R.scrollTop+R.offsetHeight;G>$&&R.scrollTo({top:G-R.offsetHeight})}})},[l,p,i,e]);const I=w.useCallback(O=>{const{clientY:R,currentTarget:B}=O,{dataset:{id:L,index:G}}=B;if(!L||!G)return;const $=b.current;ad(O.currentTarget,O),$.status="pointing",$.pointing={id:L,index:+G};const Y=P[L].y;$.startY=R,$.startIndex=Math.max(0,Math.min(Math.round(Y/l),u.length-1))},[l,u.length,P]),k=w.useCallback(O=>{const R=b.current;if(R.status==="pointing"){const{clientY:B}=O,L=B-R.startY;Math.abs(L)>5&&(R.status="dragging")}if(R.status==="dragging"){const{clientY:B}=O,L=B-R.startY,G=P[R.pointing.id],{startIndex:$,pointing:U}=R,Y=G.y+L,te=Math.max(0,Math.min(Math.round(Y/l),u.length-1)),de={...P};if(de[U.id]={y:G.y,offsetY:L,isSelected:!0},te!==R.dragIndex){R.dragIndex=te;for(let he=0;he<u.length;he++){const ke=u[he];if(ke.id===R.pointing.id)continue;let{y:se}=de[ke.id];te===$?se=he*l:te<$?te<=he&&he<$?se=(he+1)*l:se=he*l:te>$&&(te>=he&&he>$?se=(he-1)*l:se=he*l),se!==de[ke.id].y&&(de[ke.id]={y:se,offsetY:0,isSelected:!0})}}C(de)}},[l,u,P]),_=w.useCallback(O=>{const R=b.current;if(R.status==="dragging"){const{id:B,index:L}=R.pointing;cx(e,B,L,R.dragIndex,n)}ld(O.currentTarget,O),R.status="idle"},[e,n]),T=w.useCallback(O=>{const R=b.current;O.key==="Escape"&&(R.status==="dragging"&&C(Object.fromEntries(u.map((B,L)=>[B.id,{y:L*l,offsetY:0,isSelected:!1}]))),R.status="idle")},[l,u]),M=w.useCallback(()=>{f||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const O=yr.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:O}),e.setCurrentPage(O),S(!0)}),n("new-page",{source:"page-menu"}))},[e,r,f,n]),D=w.useCallback(O=>{e.setCurrentPage(O),n("change-page",{source:"page-menu"})},[e,n]),j=w.useCallback((O,R)=>{e.renamePage(O,R),n("rename-page",{source:"page-menu"})},[e,n]);return d.jsxs(jb,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(Ob,{"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(Db,{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:y,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:M,children:d.jsx(be,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((O,R)=>{const B=P[O.id]??{position:R*40,offsetY:0};return v?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:O.id===h.id?888:R,transform:`translate(0px, ${B.y+B.offsetY}px)`},children:[d.jsx(ce,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:I,onPointerUp:_,onPointerMove:k,onKeyDown:T,"data-id":O.id,"data-index":R,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 L=window.prompt("Rename page",O.name);L&&L!==O.name&&j(O.id,L)},onDoubleClick:y,children:[d.jsx(lx,{checked:O.id===h.id}),d.jsx(Pt,{children:O.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:d.jsx(bhe,{id:O.id,name:O.name,isCurrentPage:O.id===h.id,onCancel:()=>{S(!1),e.menus.clearOpenMenus()}})}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":v,children:d.jsx(WE,{index:R,item:O,listSize:u.length})})]},O.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:()=>D(O.id),onDoubleClick:y,title:r("page-menu.go-to-page"),children:[d.jsx(lx,{checked:O.id===h.id}),d.jsx(Pt,{children:O.name})]}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(WE,{index:R,item:O,listSize:u.length,onRename:()=>{if(Ge.isIos){const L=window.prompt("Rename page",O.name);L&&L!==O.name&&j(O.id,L)}else S(!0),p!==O.id&&D(O.id)}})})]},O.id)})})]})})]})});function Che(){const t=z(),e=lF(),n=aF(),r=An(1),o=Ps(),s=H("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]),i=_s(),a=r&&i;if(!(o&&!s))return d.jsxs(d.Fragment,{children:[d.jsx(K,{actionId:"undo",disabled:!e}),d.jsx(K,{actionId:"redo",disabled:!n}),d.jsx(K,{actionId:"delete",disabled:!a}),d.jsx(K,{actionId:"duplicate",disabled:!a})]})}const _he=w.memo(function({children:e}){const n=e??d.jsx(Che,{});return d.jsx(Lr,{type:"small-icons",sourceId:"quick-actions",children:n})});function Ihe({userId:t}){const e=Mg(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 Ehe=$t(function({userId:e}){const n=z(),r=Ce(),o=Qt(),s=Mg(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(Ao,{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 khe({count:t}){return d.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(t)})}const The=$t(function(){const e=z(),n=Mt(),r=Ce(),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(kb,{onOpenChange:l,open:i,children:[d.jsx(Tb,{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(Mb,{container:n,children:d.jsx(Ab,{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:g0.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 Mhe(){const t=z(),e=Qt(),n=H("userName",()=>t.user.getName(),[]),r=Ce(),o=w.useRef(n),s=w.useRef(n),[i,a]=w.useState(!1),l=w.useCallback(()=>{a(p=>!p)},[]),c=w.useCallback(p=>{s.current=p,t.user.updateUserPreferences({name:p})},[t]),u=w.useCallback(()=>{o.current!==s.current&&(e("change-user-name",{source:"people-menu"}),o.current=s.current)},[e]),h=w.useCallback(()=>{a(!1),t.user.updateUserPreferences({name:o.current}),t.menus.clearOpenMenus()},[t]);return d.jsxs("div",{className:"tlui-people-menu__user",children:[d.jsx(The,{}),i?d.jsx(nm,{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"})})]})}const Ahe=$t(function({children:e}){const n=Ce(),r=Mt(),o=z(),s=JA(),i=H("user",()=>o.user.getColor(),[o]),a=H("user",()=>o.user.getName(),[o]),[l,c]=Cs("people menu");return d.jsxs(kb,{onOpenChange:c,open:l,children:[d.jsx(Tb,{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(khe,{count:s.length-5}),d.jsxs("div",{className:"tlui-people-menu__avatars",children:[s.slice(-5).map(u=>d.jsx(Ihe,{userId:u},u)),d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx(Mb,{container:r,children:d.jsx(Ab,{dir:"ltr",className:"tlui-menu",align:"end",side:"bottom",sideOffset:2,alignOffset:-5,onEscapeKeyDown:xe,children:d.jsxs("div",{className:"tlui-people-menu__wrapper",children:[d.jsx("div",{className:"tlui-people-menu__section",children:d.jsx(Mhe,{})}),s.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:s.map(u=>d.jsx(Ehe,{userId:u},u+"_presence"))}),e]})})})]})});function jhe(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(Ahe,{})})}const Ohe=Object.freeze([mr,oa,sa,Mo]);function WF(t=Ohe){const e=z();return H("getRelevantStyles",()=>{var s;const n=new w0(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 Ar={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"}]},Ki=w.memo(function(e){const{uiType:n,items:r,title:o,style:s,value:i,onValueChange:a,onHistoryMark:l,theme:c}=e,u=Ce(),h=w.useRef(!1),p=w.useRef(null),{handleButtonClick:f,handleButtonPointerDown:g,handleButtonPointerEnter:m,handleButtonPointerUp:v}=w.useMemo(()=>{const S=()=>{h.current=!1,window.removeEventListener("pointerup",S);const I=p.current;I&&["TEXTAREA","INPUT"].includes(I.nodeName)&&I.focus(),p.current=null};return{handleButtonClick:I=>{const{id:k}=I.currentTarget.dataset;i.type==="shared"&&i.value===k||(l==null||l("point picker item"),a(s,k))},handleButtonPointerDown:I=>{const{id:k}=I.currentTarget.dataset;l==null||l("point picker item"),a(s,k),h.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",S)},handleButtonPointerEnter:I=>{if(!h.current)return;const{id:k}=I.currentTarget.dataset;a(s,k)},handleButtonPointerUp:I=>{const{id:k}=I.currentTarget.dataset;i.type==="shared"&&i.value===k||a(s,k)}}},[i,l,a,s]);return d.jsx("div",{"data-testid":`style.${n}`,className:le("tlui-buttons__grid"),children:r.map(S=>d.jsx(ce,{type:"icon","data-id":S.value,"data-testid":`style.${n}.${S.value}`,"aria-label":S.value,"data-state":i.type==="shared"&&i.value===S.value?"hinted":void 0,title:o+" — "+u(`${n}-style.${S.value}`),className:le("tlui-button-grid__button"),style:s===mr?{color:c[S.value].solid}:void 0,onPointerEnter:m,onPointerDown:g,onPointerUp:v,onClick:f,children:d.jsx(be,{icon:S.icon})},S.value))})});function GF(t,[e,n]){return Math.min(n,Math.max(e,t))}function Dhe(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 VF=["PageUp","PageDown"],YF=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],XF={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},nc="Slider",[ux,Rhe,Lhe]=qg(nc),[qF,sge]=xa(nc,[Lhe]),[$he,Pm]=qF(nc),ZF=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),S=w.useRef(0),b=i==="horizontal"?Fhe:Nhe,[P=[],C]=Ii({prop:u,defaultProp:c,onChange:D=>{var O;(O=[...v.current][S.current])==null||O.focus(),h(D)}}),I=w.useRef(P);function k(D){const j=Khe(P,D);M(D,j)}function _(D){M(D,S.current)}function T(){const D=I.current[S.current];P[S.current]!==D&&p(P)}function M(D,j,{commit:O}={commit:!1}){const R=Yhe(s),B=Xhe(Math.round((D-r)/s)*s+r,R),L=GF(B,[r,o]);C((G=[])=>{const $=Uhe(G,L,j);if(Vhe($,l*s)){S.current=$.indexOf(L);const U=String($)!==String(G);return U&&O&&p($),U?$:G}else return G})}return d.jsx($he,{scope:t.__scopeSlider,name:n,disabled:a,min:r,max:o,valueIndexToChangeRef:S,thumbs:v.current,values:P,orientation:i,form:g,children:d.jsx(ux.Provider,{scope:t.__scopeSlider,children:d.jsx(ux.Slot,{scope:t.__scopeSlider,children:d.jsx(b,{"aria-disabled":a,"data-disabled":a?"":void 0,...m,ref:e,onPointerDown:oe(m.onPointerDown,()=>{a||(I.current=P)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:k,onSlideMove:a?void 0:_,onSlideEnd:a?void 0:T,onHomeKeyDown:()=>!a&&M(r,0,{commit:!0}),onEndKeyDown:()=>!a&&M(o,P.length-1,{commit:!0}),onStepKeyDown:({event:D,direction:j})=>{if(!a){const B=VF.includes(D.key)||D.shiftKey&&YF.includes(D.key)?10:1,L=S.current,G=P[L],$=s*B*j;M(G+$,L,{commit:!0})}}})})})})});ZF.displayName=nc;var[QF,JF]=qF(nc,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Fhe=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=Qe(e,b=>p(b)),g=w.useRef(),m=H1(o),v=m==="ltr",S=v&&!s||!v&&s;function y(b){const P=g.current||h.getBoundingClientRect(),C=[0,P.width],k=Lb(C,S?[n,r]:[r,n]);return g.current=P,k(b-P.left)}return d.jsx(QF,{scope:t.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width",children:d.jsx(eN,{dir:m,"data-orientation":"horizontal",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const P=y(b.clientX);i==null||i(P)},onSlideMove:b=>{const P=y(b.clientX);a==null||a(P)},onSlideEnd:()=>{g.current=void 0,l==null||l()},onStepKeyDown:b=>{const C=XF[S?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:C?-1:1})}})})}),Nhe=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=Qe(e,u),p=w.useRef(),f=!o;function g(m){const v=p.current||u.current.getBoundingClientRect(),S=[0,v.height],b=Lb(S,f?[r,n]:[n,r]);return p.current=v,b(m-v.top)}return d.jsx(QF,{scope:t.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:d.jsx(eN,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const v=g(m.clientY);s==null||s(v)},onSlideMove:m=>{const v=g(m.clientY);i==null||i(v)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:m=>{const S=XF[f?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:S?-1:1})}})})}),eN=w.forwardRef((t,e)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=t,u=Pm(nc,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()):VF.concat(YF).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))})})}),tN="SliderTrack",nN=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=Pm(tN,n);return d.jsx(Ae.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:e})});nN.displayName=tN;var dx="SliderRange",rN=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=Pm(dx,n),s=JF(dx,n),i=w.useRef(null),a=Qe(e,i),l=o.values.length,c=o.values.map(p=>sN(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+"%"}})});rN.displayName=dx;var hx="SliderThumb",oN=w.forwardRef((t,e)=>{const n=Rhe(t.__scopeSlider),[r,o]=w.useState(null),s=Qe(e,a=>o(a)),i=w.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return d.jsx(zhe,{...t,ref:s,index:i})}),zhe=w.forwardRef((t,e)=>{const{__scopeSlider:n,index:r,name:o,...s}=t,i=Pm(hx,n),a=JF(hx,n),[l,c]=w.useState(null),u=Qe(e,y=>c(y)),h=l?i.form||!!l.closest("form"):!0,p=X3(l),f=i.values[r],g=f===void 0?0:sN(f,i.min,i.max),m=Hhe(r,i.values.length),v=p==null?void 0:p[a.size],S=v?Whe(v,g,a.direction):0;return w.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${g}% + ${S}px)`},children:[d.jsx(ux.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(Bhe,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:f},r)]})});oN.displayName=hx;var Bhe=t=>{const{value:e,...n}=t,r=w.useRef(null),o=Dhe(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 Uhe(t=[],e,n){const r=[...t];return r[n]=e,r.sort((o,s)=>o-s)}function sN(t,e,n){const s=100/(n-e)*(t-e);return GF(s,[0,100])}function Hhe(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}function Khe(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 Whe(t,e,n){const r=t/2,s=Lb([0,50],[0,r]);return(r-s(e)*n)*n}function Ghe(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}function Vhe(t,e){if(e>0){const n=Ghe(t);return Math.min(...n)>=e}return!0}function Lb(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 Yhe(t){return(String(t).split(".")[1]||"").length}function Xhe(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}var qhe=ZF,Zhe=nN,Qhe=rN,Jhe=oN;const epe=w.memo(function({onHistoryMark:e,title:n,steps:r,value:o,label:s,onValueChange:i,["data-testid"]:a}){const l=Ce(),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(qhe,{"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(Zhe,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&d.jsx(Qhe,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&d.jsx(Jhe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function tpe({label:t,uiTypeA:e,uiTypeB:n,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const p=Ce(),f=w.useMemo(()=>{var m;return((m=s.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:m.icon)??"mixed"},[s,c]),g=w.useMemo(()=>{var m;return((m=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:m.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:p(t),className:"tlui-style-panel__double-select-picker-label",children:p(t)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(ua,{id:`style panel ${e} A`,children:[d.jsx(da,{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(ha,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map((m,v)=>d.jsx(Wu,{"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(ua,{id:`style panel ${n}`,children:[d.jsx(da,{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(ha,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(Wu,{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 npe=w.memo(tpe);function rpe({id:t,label:e,uiType:n,style:r,items:o,type:s,value:i,onValueChange:a}){const l=Ce(),c=z(),u=w.useMemo(()=>{var f;return(f=o.find(g=>i.type==="shared"&&g.value===i.value))==null?void 0:f.icon},[o,i]),h=i.type==="mixed"?l("style-panel.mixed"):l(`${n}-style.${i.value}`),p=e?l(e):"";return d.jsxs(ua,{id:`style panel ${t}`,children:[d.jsx(da,{children:d.jsxs(ce,{type:s,"data-testid":`style.${n}`,title:h,children:[d.jsx(Pt,{children:p}),d.jsx(be,{icon:u??"mixed"})]})}),d.jsx(ha,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>d.jsx(Wu,{children:d.jsx(ce,{type:"icon","data-testid":`style.${n}.${f.value}`,title:l(`${n}-style.${f.value}`),onClick:()=>{c.markHistoryStoppingPoint("select style dropdown item"),a(r,f.value)},children:d.jsx(be,{icon:f.icon})})},f.value))})})]})}const $b=w.memo(rpe);function ope({styles:t}){const e=yd();if(!t)return null;const n=t.get(qr),r=t.get(Cf),o=t.get(Pf),s=t.get(kf),i=t.get(To),a=n===void 0,l=r===void 0&&o===void 0,c=s===void 0,u=i===void 0,h=bs({isDarkMode:e});return d.jsxs(d.Fragment,{children:[d.jsx(spe,{theme:h,styles:t}),!u&&d.jsx(ipe,{theme:h,styles:t}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(ape,{styles:t}),d.jsx(cpe,{styles:t}),d.jsx(lpe,{styles:t})]})]})}function _d(){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 spe({styles:t,theme:e}){const n=Ce(),r=z(),o=w.useCallback(h=>r.markHistoryStoppingPoint(h),[r]),s=_d(),i=t.get(mr),a=t.get(sa),l=t.get(oa),c=t.get(Mo),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(Ki,{title:n("style-panel.color"),uiType:"color",style:mr,items:Ar.color,value:i,onValueChange:s,theme:e,onHistoryMark:o}),d.jsx(upe,{})]}),u&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:d.jsx(Ki,{title:n("style-panel.fill"),uiType:"fill",style:sa,items:Ar.fill,value:a,onValueChange:s,theme:e,onHistoryMark:o}),l===void 0?null:d.jsx(Ki,{title:n("style-panel.dash"),uiType:"dash",style:oa,items:Ar.dash,value:l,onValueChange:s,theme:e,onHistoryMark:o}),c===void 0?null:d.jsx(Ki,{title:n("style-panel.size"),uiType:"size",style:Mo,items:Ar.size,value:c,onValueChange:(h,p)=>{s(h,p);const f=r.getSelectedShapeIds();f.length>0&&Ye(r,f)},theme:e,onHistoryMark:o})]})]})}function ipe({theme:t,styles:e}){const n=Ce(),r=_d(),o=z(),s=w.useCallback(u=>o.markHistoryStoppingPoint(u),[o]),i=e.get(To),a=e.get(u0),l=e.get(If),c=e.get(Ef);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(Ki,{title:n("style-panel.font"),uiType:"font",style:To,items:Ar.font,value:i,onValueChange:r,theme:t,onHistoryMark:s}),a===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Ki,{title:n("style-panel.align"),uiType:"align",style:u0,items:Ar.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(Ki,{title:n("style-panel.align"),uiType:"align",style:If,items:Ar.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($b,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:Ef,items:Ar.verticalAlign,value:c,onValueChange:r})})]})]})}function ape({styles:t}){const e=_d(),n=t.get(qr);return n===void 0?null:d.jsx($b,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:qr,items:Ar.geo,value:n,onValueChange:e})}function lpe({styles:t}){const e=_d(),n=t.get(kf);return n===void 0?null:d.jsx($b,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:kf,items:Ar.spline,value:n,onValueChange:e})}function cpe({styles:t}){const e=_d(),n=t.get(Cf),r=t.get(Pf);return!n||!r?null:d.jsx(npe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Pf,itemsA:Ar.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Cf,itemsB:Ar.arrowheadEnd,valueB:n,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Oc=[.1,.25,.5,.75,1];function upe(){const t=z(),e=w.useCallback(a=>t.markHistoryStoppingPoint(a),[t]),n=H("opacity",()=>t.getSharedOpacity(),[t]),r=Qt(),o=Ce(),s=Te.useCallback(a=>{const l=Oc[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:Oc.indexOf(hB(Oc,a=>Math.abs(a-n.value)));return d.jsx(epe,{"data-testid":"style.opacity",value:i>=0?i:Oc.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:s,steps:Oc.length-1,title:o("style-panel.opacity"),onHistoryMark:e})}const dpe=w.memo(function({isMobile:e,children:n}){const r=z(),o=w.useRef(null);_i(o);const s=WF(),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 hpe(){const t=z(),e=Ce(),n=WF(),r=n==null?void 0:n.get(mr),o=bs({isDarkMode:t.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=H("disable style panel",()=>t.isInAny("hand","zoom","eraser","laser"),[t]),a=w.useCallback(c=>{c||t.updateInstanceState({isChangingStyle:!1})},[t]),{StylePanel:l}=Ti();return l?d.jsxs(jb,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(Ob,{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(Db,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function ppe(){return d.jsxs(d.Fragment,{children:[d.jsx(gpe,{}),d.jsx(mpe,{}),d.jsx(ype,{}),d.jsx(Spe,{}),d.jsx(vpe,{}),d.jsx(xpe,{}),d.jsx(wpe,{}),d.jsx(bpe,{}),d.jsx(Ppe,{}),d.jsx(Cpe,{}),d.jsx(Ipe,{}),d.jsx(_pe,{}),d.jsx(Tpe,{}),d.jsx(jpe,{}),d.jsx(Epe,{}),d.jsx(Ape,{}),d.jsx(Mpe,{}),d.jsx(kpe,{}),d.jsx(Ope,{}),d.jsx(Dpe,{}),d.jsx(Rpe,{}),d.jsx(Lpe,{}),d.jsx($pe,{}),d.jsx(Fpe,{}),d.jsx(Npe,{}),d.jsx(zpe,{}),d.jsx(Upe,{}),d.jsx(Bpe,{})]})}function fpe(t){var r;const e=z(),n=(r=t.meta)==null?void 0:r.geo;return H("is tool selected",()=>{const o=e.getCurrentToolId(),s=e.getSharedStyles().getAsKnownValue(qr);return n?o==="geo"&&s===n:o===t.id},[e,t.id,n])}function Ve({tool:t}){const e=fb(),n=fpe(e[t]);return d.jsx(Rn,{toolId:t,isSelected:n})}function gpe(){return d.jsx(Ve,{tool:"select"})}function mpe(){return d.jsx(Ve,{tool:"hand"})}function ype(){return d.jsx(Ve,{tool:"draw"})}function Spe(){return d.jsx(Ve,{tool:"eraser"})}function vpe(){return d.jsx(Ve,{tool:"arrow"})}function xpe(){return d.jsx(Ve,{tool:"text"})}function wpe(){return d.jsx(Ve,{tool:"note"})}function bpe(){return d.jsx(Rn,{toolId:"asset"})}function Ppe(){return d.jsx(Ve,{tool:"rectangle"})}function Cpe(){return d.jsx(Ve,{tool:"ellipse"})}function _pe(){return d.jsx(Ve,{tool:"diamond"})}function Ipe(){return d.jsx(Ve,{tool:"triangle"})}function Epe(){return d.jsx(Ve,{tool:"rhombus"})}function kpe(){return d.jsx(Ve,{tool:"heart"})}function Tpe(){return d.jsx(Ve,{tool:"hexagon"})}function Mpe(){return d.jsx(Ve,{tool:"cloud"})}function Ape(){return d.jsx(Ve,{tool:"star"})}function jpe(){return d.jsx(Ve,{tool:"oval"})}function Ope(){return d.jsx(Ve,{tool:"x-box"})}function Dpe(){return d.jsx(Ve,{tool:"check-box"})}function Rpe(){return d.jsx(Ve,{tool:"arrow-left"})}function Lpe(){return d.jsx(Ve,{tool:"arrow-up"})}function $pe(){return d.jsx(Ve,{tool:"arrow-down"})}function Fpe(){return d.jsx(Ve,{tool:"arrow-right"})}function Npe(){return d.jsx(Ve,{tool:"line"})}function zpe(){return d.jsx(Ve,{tool:"highlight"})}function Bpe(){return d.jsx(Ve,{tool:"frame"})}function Upe(){return d.jsx(Ve,{tool:"laser"})}const PS=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function CS(t,e,n,r){t.addEventListener?t.addEventListener(e,n,r):t.attachEvent&&t.attachEvent("on".concat(e),n)}function Dc(t,e,n,r){t.removeEventListener?t.removeEventListener(e,n,r):t.detachEvent&&t.detachEvent("on".concat(e),n)}function iN(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 aN(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 Hpe(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 Gu={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,"-":PS?173:189,"=":PS?61:187,";":PS?59:186,"'":222,"[":219,"]":221,"\\":220},Do={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},px={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Ut={16:!1,18:!1,17:!1,91:!1},pt={};for(let t=1;t<20;t++)Gu["f".concat(t)]=111+t;let Xe=[],uu=null,lN="all";const qo=new Map,Id=t=>Gu[t.toLowerCase()]||Do[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),Kpe=t=>Object.keys(Gu).find(e=>Gu[e]===t),Wpe=t=>Object.keys(Do).find(e=>Do[e]===t);function cN(t){lN=t||"all"}function Vu(){return lN||"all"}function Gpe(){return Xe.slice(0)}function Vpe(){return Xe.map(t=>Kpe(t)||Wpe(t)||String.fromCharCode(t))}function Ype(){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=>Id(a))})})}),t}function Xpe(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 qpe(t){return typeof t=="string"&&(t=Id(t)),Xe.indexOf(t)!==-1}function Zpe(t,e){let n,r;t||(t=Vu());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 Fb(a)}):r++;Vu()===t&&cN(e||"all")}function Qpe(t){let e=t.keyCode||t.which||t.charCode;const n=Xe.indexOf(e);if(n>=0&&Xe.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&Xe.splice(0,Xe.length),(e===93||e===224)&&(e=91),e in Ut){Ut[e]=!1;for(const r in Do)Do[r]===e&&(Wn[r]=!1)}}function uN(t){if(typeof t>"u")Object.keys(pt).forEach(o=>{Array.isArray(pt[o])&&pt[o].forEach(s=>$h(s)),delete pt[o]}),Fb(null);else if(Array.isArray(t))t.forEach(o=>{o.key&&$h(o)});else if(typeof t=="object")t.key&&$h(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=""),$h({key:t,scope:o,method:s,splitKey:"+"})}}const $h=t=>{let{key:e,scope:n,method:r,splitKey:o="+"}=t;aN(e).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Id(c);if(!pt[u])return;n||(n=Vu());const h=l>1?iN(Do,a):[],p=[];pt[u]=pt[u].filter(f=>{const m=(r?f.method===r:!0)&&f.scope===n&&Hpe(f.mods,h);return m&&p.push(f.element),!m}),p.forEach(f=>Fb(f))})};function GE(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 Ut)Object.prototype.hasOwnProperty.call(Ut,s)&&(!Ut[s]&&e.mods.indexOf(+s)>-1||Ut[s]&&e.mods.indexOf(+s)===-1)&&(o=!1);(e.mods.length===0&&!Ut[16]&&!Ut[18]&&!Ut[17]&&!Ut[91]||o||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(Xe),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function VE(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),Xe.indexOf(r)===-1&&r!==229&&Xe.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=px[a];t[a]&&Xe.indexOf(l)===-1?Xe.push(l):!t[a]&&Xe.indexOf(l)>-1?Xe.splice(Xe.indexOf(l),1):a==="metaKey"&&t[a]&&Xe.length===3&&(t.ctrlKey||t.shiftKey||t.altKey||(Xe=Xe.slice(Xe.indexOf(l))))}),r in Ut){Ut[r]=!0;for(const a in Do)Do[a]===r&&(Wn[a]=!0);if(!n)return}for(const a in Ut)Object.prototype.hasOwnProperty.call(Ut,a)&&(Ut[a]=t[px[a]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(Xe.indexOf(17)===-1&&Xe.push(17),Xe.indexOf(18)===-1&&Xe.push(18),Ut[17]=!0,Ut[18]=!0);const o=Vu();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)&&GE(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(Id(u[p]));h.sort().join("")===Xe.sort().join("")&&GE(t,l,o,e)}}function Wn(t,e,n){Xe=[];const r=aN(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&&uN(t,s);a<r.length;a++)t=r[a].split(u),o=[],t.length>1&&(o=iN(Do,t)),t=t[t.length-1],t=t==="*"?"*":Id(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(!qo.has(i)){const f=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return VE(m,i)},g=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;VE(m,i),Qpe(m)};qo.set(i,{keydownListener:f,keyupListenr:g,capture:h}),CS(i,"keydown",f,h),CS(i,"keyup",g,h)}if(!uu){const f=()=>{Xe=[]};uu={listener:f,capture:h},CS(window,"focus",f,h)}}}function Jpe(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 Fb(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}=qo.get(t)||{};r&&o&&(Dc(t,"keyup",o,s),Dc(t,"keydown",r,s),qo.delete(t))}if((e.length<=0||qo.size<=0)&&(Object.keys(qo).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=qo.get(o)||{};s&&i&&(Dc(o,"keyup",i,a),Dc(o,"keydown",s,a),qo.delete(o))}),qo.clear(),Object.keys(pt).forEach(o=>delete pt[o]),uu)){const{listener:o,capture:s}=uu;Dc(window,"focus",o,s),uu=null}}const _S={getPressedKeyString:Vpe,setScope:cN,getScope:Vu,deleteScope:Zpe,getPressedKeyCodes:Gpe,getAllKeyCodes:Ype,isPressed:qpe,filter:Xpe,trigger:Jpe,unbind:uN,keyMap:Gu,modifier:Do,modifierMap:px};for(const t in _S)Object.prototype.hasOwnProperty.call(_S,t)&&(Wn[t]=_S[t]);if(typeof window<"u"){const t=window.hotkeys;Wn.noConflict=e=>(e&&window.hotkeys===Wn&&(window.hotkeys=t),Wn),window.hotkeys=Wn}const YE=["copy","cut","paste","asset"];function efe(){const t=z(),e=Ps(),n=ba(),r=fb(),o=H("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||YE.includes(l.id)||i(XE(l.kbd),c=>{Yc(t)||(xe(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&t.getIsReadonly()||YE.includes(l.id)||i(XE(l.kbd),c=>{Yc(t)||(xe(c),l.onSelect("kbd"))});return i(",",l=>{if(Yc(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(Yc(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 XE(t){return tfe(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 tfe(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 Yc(t){return t.menus.hasAnyOpenMenus()||t.getEditingShapeId()!==null||t.getCrashingError()}const nfe=w.createContext(!1);function rfe({children:t}){const e=z(),n=rj(),r=Mn(),o=Ce(),s=Math.min(8,5+r),[i,a]=w.useState(0),l=w.useRef(null),[c,u]=w.useState(null),h=w.useMemo(()=>{const f=c?`:not([data-value="${c}"])`:"";return`
|
|
418
|
-
#${n}_main > *:nth-child(n + ${s+(c?1:2)})${f} {
|
|
419
|
-
display: none;
|
|
420
|
-
}
|
|
421
|
-
#${n}_more > *:nth-child(-n + ${s}) {
|
|
422
|
-
display: none;
|
|
423
|
-
}
|
|
424
|
-
`},[c,n,s]),p=$g(()=>{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(Yc(e))return;xe(v);const y=Array.from(((b=l.current)==null?void 0:b.children)??[]).filter(P=>!(P instanceof HTMLElement)||P.tagName.toLowerCase()!=="button"?!1:!!(P.offsetWidth||P.offsetHeight))[m];y&&y.click()});return()=>{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(Lr,{type:"toolbar",sourceId:"toolbar",children:t})}),i>s+1&&d.jsx(nfe.Provider,{value:!0,children:d.jsxs(ua,{id:"toolbar overflow",modal:!1,children:[d.jsx(da,{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(ha,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx(Lr,{type:"toolbar-overflow",sourceId:"toolbar",children:t})})})]})})]})]})}function ofe({activeToolId:t}){const e=z(),n=Mn(),r=Ce(),o=H("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),s=H("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 sfe=w.memo(function({children:e}){const n=z(),r=Mn(),o=Ps(),s=H("current tool id",()=>n.getCurrentToolId(),[n]),i=w.useRef(null);_i(i);const{ActionsMenu:a,QuickActions:l}=Ti(),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(rfe,{children:e??d.jsx(ppe,{})})]}),r<St.TABLET_SM&&!o&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(hpe,{})})]})})});function ife(){const t=Ce();return d.jsxs("div",{className:le("tlui-offline-indicator"),children:[t("status.offline"),d.jsx(Ao,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function afe({maxWidth:t=420,ignoreRightWidth:e=0,stylePanelWidth:n=148,marginBetweenZones:r=12,squeezeAmount:o=52,children:s}){const i=w.useRef(null),a=Mn(),l=w.useCallback(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),f=u.offsetWidth,g=h.offsetWidth,m=p.offsetWidth,v=c.offsetWidth-e;let S=(f-v)/2;f%2!==0&&(S-=.5);const y=g+r,b=c.offsetLeft,P=Math.min(f-m-g-2*r,t),C=Math.max(S,y)-b;p.offsetWidth>n&&a<=6?c.style.setProperty("max-width",P-o+"px"):c.style.setProperty("max-width",P+"px"),c.style.setProperty("transform",`translate(${C}px, 0px)`)},[a,e,r,t,o,n]);return w.useLayoutEffect(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),p=u.querySelector(".tlui-layout__top__right"),f=new ResizeObserver(l);return f.observe(h),f.observe(p),f.observe(u),f.observe(c),l(),()=>{f.disconnect()}},[l]),w.useLayoutEffect(()=>{l()}),d.jsx("div",{ref:i,className:"tlui-top-panel__container",children:s})}function lfe(){const t=woe()==="offline";return d.jsx(afe,{children:t&&d.jsx(ife,{})})}function cfe(){return d.jsxs(d.Fragment,{children:[d.jsx(K,{actionId:"zoom-in",noClose:!0}),d.jsx(K,{actionId:"zoom-out",noClose:!0}),d.jsx(yF,{}),d.jsx(SF,{}),d.jsx(vF,{})]})}const ufe=w.memo(function({children:e}){const n=Mt(),[r,o]=Cs("zoom menu"),s=e??d.jsx(cfe,{});return d.jsxs(db,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(hb,{asChild:!0,dir:"ltr",children:d.jsx(dfe,{})}),d.jsx(dm,{container:n,children:d.jsx(pb,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(Lr,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),dfe=w.forwardRef(function(e,n){const r=z(),o=Mn(),s=H("zoom",()=>r.getZoomLevel(),[r]),i=Ce(),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),"%"]})})}),dN=w.createContext(null);function hfe({overrides:t={},children:e}){const n=dd(t),r=rm();return d.jsx(dN.Provider,{value:w.useMemo(()=>({ContextMenu:Ede,ActionsMenu:ede,HelpMenu:null,ZoomMenu:ufe,MainMenu:che,Minimap:vhe,StylePanel:dpe,PageMenu:Phe,NavigationPanel:whe,Toolbar:sfe,KeyboardShortcutsDialog:qde,QuickActions:_he,HelperButtons:Yde,DebugPanel:Nde,DebugMenu:Fde,MenuPanel:Hde,SharePanel:r?jhe:null,CursorChatBubble:r?Mde:null,TopPanel:r?lfe:null,...n}),[n,r]),children:e})}function Ti(){const t=w.useContext(dN);if(!t)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return t}const pfe=$t(function({overrides:e,components:n,assetUrls:r,onUiEvent:o,forceMobile:s,mediaMimeTypes:i,children:a}){const l=z();return d.jsx($3.Provider,{value:i,children:d.jsx(are,{assetUrls:Cue(r),children:d.jsx(ure,{overrides:Eue(e),locale:l.user.getLocale(),children:d.jsx(One,{onEvent:o,children:d.jsx(ire,{children:d.jsx(Dne,{context:l.contextId,children:d.jsx(fae,{forceMobile:s,children:d.jsx(hfe,{overrides:n,children:d.jsx(ffe,{overrides:e,children:a})})})})})})})})})});function ffe({overrides:t,children:e}){const n=kue(t);return d.jsx(Coe,{overrides:n.actions,children:d.jsx(bae,{overrides:n.tools,children:e})})}function gfe(){const t=z(),{addToast:e}=$o();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 mfe=Te.memo(function({renderDebugMenuItems:e,children:n,hideUi:r,components:o,...s}){return d.jsx(pfe,{...s,components:o,children:d.jsx(yfe,{hideUi:r,renderDebugMenuItems:e,children:n})})}),yfe=Te.memo(function({children:e,hideUi:n,...r}){return d.jsxs(d.Fragment,{children:[e,n?null:d.jsx(Sfe,{...r})]})}),Sfe=Te.memo(function(){const e=z(),n=Ce(),r=Mn(),o=Ps(),s=H("focus",()=>e.getInstanceState().isFocusMode,[e]),i=H("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}=Ti();efe(),Xre(),gfe();const{"toggle-focus-mode":S}=ba();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:()=>S.onSelect("menu"),children:d.jsx(be,{icon:"dot"})})}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"tlui-layout__top",children:[d.jsxs("div",{className:"tlui-layout__top__left",children:[c&&d.jsx(c,{}),g&&d.jsx(g,{})]}),d.jsx("div",{className:"tlui-layout__top__center",children:l&&d.jsx(l,{})}),d.jsxs("div",{className:"tlui-layout__top__right",children:[a&&d.jsx(a,{}),u&&r>=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(fre,{}),d.jsx(Lne,{}),d.jsx(wue,{}),v&&d.jsx(v,{})]})});async function vfe(t,e){const{url:n,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=e,h={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c},p=new FontFace(t,`url(${n})`,h);return await p.load(),document.fonts.add(p),p.$$_url=n,p.$$_fontface=`
|
|
425
|
-
@font-face {
|
|
426
|
-
font-family: ${p.family};
|
|
427
|
-
font-stretch: ${p.stretch};
|
|
428
|
-
font-weight: ${p.weight};
|
|
429
|
-
font-style: ${p.style};
|
|
430
|
-
src: url("${n}") format("${u}")
|
|
431
|
-
}`,p}const Fh=(t,e)=>{const[n,r]=w.useState(2);return w.useEffect(()=>{let o=!1;return r(2),vfe(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 hN(t){const e=w.useMemo(()=>xfe(t),[t]),n=[Fh("tldraw_draw",e.draw),Fh("tldraw_serif",e.serif),Fh("tldraw_sans",e.sansSerif),Fh("tldraw_mono",e.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function wfe(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=dd(a),g=w.useMemo(()=>({Scribble:sE,ShapeIndicators:Oae,CollaboratorScribble:sE,SelectionForeground:Mae,SelectionBackground:kae,Handles:Pae,...f}),[f]),m=Us(l),v=w.useMemo(()=>[...i5,...m],[m]),S=Us(c),y=w.useMemo(()=>[...T$,...S],[S]),b=Us(u),P=w.useMemo(()=>[...xue,...ple,...b],[b]),C=Us(o??gg),I=Us(s??mw),k=w.useMemo(()=>[...C,...I],[C,I]),_=K5(p.assetUrls),{done:T,error:M}=hN(_);return M?d.jsx(jR,{children:"Could not load assets. Please refresh the page."}):T?d.jsx(Uee,{initialState:"select",...p,components:g,shapeUtils:v,bindingUtils:y,tools:P,children:d.jsxs(mfe,{...p,components:g,mediaMimeTypes:k,children:[d.jsx(bfe,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:C,acceptedVideoMimeTypes:I,onMount:i,embeds:h}),e]})}):d.jsx(P1,{children:d.jsx(a1,{})})}function bfe({maxImageDimension:t=5e3,maxAssetSize:e=10*1024*1024,acceptedImageMimeTypes:n=gg,acceptedVideoMimeTypes:r=mw,onMount:o,embeds:s}){const i=z(),a=$o(),l=Ce();OR(()=>{const h=i.getShapeUtil("embed");h&&s&&h.setEmbedDefinitions(s);const p=[];return p.push(Kce(i)),qae(i,{maxImageDimension:t,maxAssetSize:e,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:a,msg:l}),p.push(i.store.props.onMount(i)),p.push(o==null?void 0:o(i)),()=>{p.forEach(f=>f==null?void 0:f())}});const{Canvas:c}=ot(),{ContextMenu:u}=Ti();return u?d.jsx(u,{}):c?d.jsx(c,{}):null}w.memo(function(e){const[n,r]=w.useState(null),[o,s]=w.useState(null),i=Us(e.shapeUtils??[]),a=w.useMemo(()=>[...i5,...i],[i]),l=Us(e.bindingUtils??[]),c=w.useMemo(()=>[...T$,...l],[l]),u=Xee({snapshot:e.snapshot,shapeUtils:a}),h=K5(e.assetUrls),{done:p,error:f}=hN(h),{pageId:g,bounds:m,scale:v,background:S,padding:y,darkMode:b,preserveAspectRatio:P,format:C="svg",licenseKey:I}=e;return w.useLayoutEffect(()=>{if(!o||!u||!p)return;let k=!1;const _=document.createElement("div");o.appendChild(_),o.classList.add("tl-container","tl-theme__light");const T=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>_,licenseKey:I});g&&T.setCurrentPage(g);const M=T.getCurrentPageShapeIds();async function D(){const j=await T.getSvgString([...M],{bounds:m,scale:v,background:S,padding:y,darkMode:b,preserveAspectRatio:P});if(j&&!k){if(C==="svg"){if(!k){const O=new Blob([j.svg],{type:"image/svg+xml"}),R=URL.createObjectURL(O);r(R)}}else if(C==="png"){const O=await D3(T,j.svg,{type:C,quality:1,scale:2,width:j.width,height:j.height});if(O&&!k){const R=URL.createObjectURL(O);r(R)}}}T.dispose()}return D(),()=>{k=!0}},[C,o,u,a,c,g,m,v,S,y,b,P,p,f,I]),f?d.jsx(jR,{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(P1,{children:d.jsx(a1,{})})});w.memo(function({children:e}){const n=Ce(),r=Mn(),o=w.useRef(null);_i(o);const s=e??d.jsx(Jde,{});return r<St.MOBILE?null:d.jsx("div",{ref:o,className:"tlui-help-menu",children:d.jsxs(ua,{id:"help menu",children:[d.jsx(da,{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(ha,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(Lr,{type:"menu",sourceId:"help-menu",children:s})})]})})});const Pfe=1,Cfe=Pe({schemaVersion:gn(1),storeVersion:np,recordVersions:wf(me,Pe({version:np,subTypeVersions:wf(me,np).optional(),subTypeKey:me.optional()}))}),_fe=Pe({schemaVersion:gn(2),sequences:wf(me,np)}),Ife=Pe({tldrawFileFormatVersion:EV,schema:kV("schemaVersion",{1:Cfe,2:_fe}),records:Wt(Pe({id:me,typeName:me}).allowUnknownProperties())});function Efe(t){var e;try{return!!((e=t.document)!=null&&e.version)}catch{return!1}}function kfe({json:t,schema:e}){let n;try{n=Ife.validate(JSON.parse(t))}catch(s){try{if(n=JSON.parse(t),Efe(n))return xn.err({type:"v1File",data:n})}catch{}return xn.err({type:"notATldrawFile",cause:s})}if(n.tldrawFileFormatVersion>Pfe)return xn.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r,o;try{const s=Tfe(n.records);o=Object.fromEntries(s.map(i=>[i.id,i])),r=e.migrateStoreSnapshot({store:o,schema:n.schema})}catch(s){return xn.err({type:"invalidRecords",cause:s})}if(r.type==="error")return xn.err({type:"migrationFailed",reason:r.reason});try{return xn.ok(Fu({snapshot:{store:o,schema:n.schema},schema:e}))}catch(s){return xn.err({type:"invalidRecords",cause:s})}}function Tfe(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))}xi("tldraw","3.3.0","esm");function Mfe(){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=kfe({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(wfe,{assetUrls:Yz(),onMount:n,store:t})})}GS.createRoot(document.querySelector("#root")).render(d.jsx(Te.StrictMode,{children:d.jsx(Mfe,{})}));
|