@kitschpatrol/tldraw-cli 4.6.22 → 4.6.24
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 +260 -232
- package/dist/lib/index.js +259 -231
- package/dist/tldraw/assets/{index-C2Zi_I-5.css → index-CpW4rwyq.css} +1 -1
- package/dist/tldraw/assets/index-lVDXOU2B.js +425 -0
- package/dist/tldraw/index.html +2 -2
- package/dist/tldraw/translations/da.json +396 -159
- package/dist/tldraw/translations/ko-kr.json +1 -0
- package/dist/tldraw/translations/languages.json +4 -0
- package/dist/tldraw/translations/main.json +1 -0
- package/dist/tldraw/translations/so.json +397 -0
- package/package.json +14 -14
- package/readme.md +4 -4
- package/dist/tldraw/assets/index-B_dC5v5g.js +0 -425
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
var IN=Object.defineProperty;var EN=(t,e,n)=>e in t?IN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var E=(t,e,n)=>EN(t,typeof e!="symbol"?e+"":e,n);function kN(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 vi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var n2={exports:{}},Zf={},r2={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 Zu=Symbol.for("react.element"),TN=Symbol.for("react.portal"),MN=Symbol.for("react.fragment"),AN=Symbol.for("react.strict_mode"),jN=Symbol.for("react.profiler"),ON=Symbol.for("react.provider"),DN=Symbol.for("react.context"),RN=Symbol.for("react.forward_ref"),LN=Symbol.for("react.suspense"),$N=Symbol.for("react.memo"),FN=Symbol.for("react.lazy"),uP=Symbol.iterator;function NN(t){return t===null||typeof t!="object"?null:(t=uP&&t[uP]||t["@@iterator"],typeof t=="function"?t:null)}var o2={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},s2=Object.assign,i2={};function Nl(t,e,n){this.props=t,this.context=e,this.refs=i2,this.updater=n||o2}Nl.prototype.isReactComponent={};Nl.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")};Nl.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function a2(){}a2.prototype=Nl.prototype;function g0(t,e,n){this.props=t,this.context=e,this.refs=i2,this.updater=n||o2}var m0=g0.prototype=new a2;m0.constructor=g0;s2(m0,Nl.prototype);m0.isPureReactComponent=!0;var dP=Array.isArray,l2=Object.prototype.hasOwnProperty,y0={current:null},c2={key:!0,ref:!0,__self:!0,__source:!0};function u2(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)l2.call(e,r)&&!c2.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:Zu,type:t,key:s,ref:i,props:o,_owner:y0.current}}function zN(t,e){return{$$typeof:Zu,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}function S0(t){return typeof t=="object"&&t!==null&&t.$$typeof===Zu}function BN(t){var e={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(n){return e[n]})}var hP=/\/+/g;function Om(t,e){return typeof t=="object"&&t!==null&&t.key!=null?BN(""+t.key):e.toString(36)}function zh(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 Zu:case TN:i=!0}}if(i)return i=t,o=o(i),t=r===""?"."+Om(i,0):r,dP(o)?(n="",t!=null&&(n=t.replace(hP,"$&/")+"/"),zh(o,e,n,"",function(c){return c})):o!=null&&(S0(o)&&(o=zN(o,n+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(hP,"$&/")+"/")+t)),e.push(o)),1;if(i=0,r=r===""?".":r+":",dP(t))for(var a=0;a<t.length;a++){s=t[a];var l=r+Om(s,a);i+=zh(s,e,n,l,o)}else if(l=NN(t),typeof l=="function")for(t=l.call(t),a=0;!(s=t.next()).done;)s=s.value,l=r+Om(s,a++),i+=zh(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 Ld(t,e,n){if(t==null)return t;var r=[],o=0;return zh(t,r,"","",function(s){return e.call(n,s,o++)}),r}function UN(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},Bh={transition:null},HN={ReactCurrentDispatcher:Pn,ReactCurrentBatchConfig:Bh,ReactCurrentOwner:y0};function d2(){throw Error("act(...) is not supported in production builds of React.")}Ee.Children={map:Ld,forEach:function(t,e,n){Ld(t,function(){e.apply(this,arguments)},n)},count:function(t){var e=0;return Ld(t,function(){e++}),e},toArray:function(t){return Ld(t,function(e){return e})||[]},only:function(t){if(!S0(t))throw Error("React.Children.only expected to receive a single React element child.");return t}};Ee.Component=Nl;Ee.Fragment=MN;Ee.Profiler=jN;Ee.PureComponent=g0;Ee.StrictMode=AN;Ee.Suspense=LN;Ee.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=HN;Ee.act=d2;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=s2({},t.props),o=t.key,s=t.ref,i=t._owner;if(e!=null){if(e.ref!==void 0&&(s=e.ref,i=y0.current),e.key!==void 0&&(o=""+e.key),t.type&&t.type.defaultProps)var a=t.type.defaultProps;for(l in e)l2.call(e,l)&&!c2.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:Zu,type:t.type,key:o,ref:s,props:r,_owner:i}};Ee.createContext=function(t){return t={$$typeof:DN,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},t.Provider={$$typeof:ON,_context:t},t.Consumer=t};Ee.createElement=u2;Ee.createFactory=function(t){var e=u2.bind(null,t);return e.type=t,e};Ee.createRef=function(){return{current:null}};Ee.forwardRef=function(t){return{$$typeof:RN,render:t}};Ee.isValidElement=S0;Ee.lazy=function(t){return{$$typeof:FN,_payload:{_status:-1,_result:t},_init:UN}};Ee.memo=function(t,e){return{$$typeof:$N,type:t,compare:e===void 0?null:e}};Ee.startTransition=function(t){var e=Bh.transition;Bh.transition={};try{t()}finally{Bh.transition=e}};Ee.unstable_act=d2;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";r2.exports=Ee;var w=r2.exports;const Te=vi(w),KN=kN({__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 WN=w,GN=Symbol.for("react.element"),VN=Symbol.for("react.fragment"),YN=Object.prototype.hasOwnProperty,XN=WN.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,qN={key:!0,ref:!0,__self:!0,__source:!0};function h2(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)YN.call(e,r)&&!qN.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:GN,type:t,key:s,ref:i,props:o,_owner:XN.current}}Zf.Fragment=VN;Zf.jsx=h2;Zf.jsxs=h2;n2.exports=Zf;var d=n2.exports,YS={},p2={exports:{}},Sr={},f2={exports:{}},g2={};/**
|
|
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 ee=Y-1>>>1,he=$[ee];if(0<o(he,U))$[ee]=U,$[Y]=he,Y=ee;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 ee=0,he=$.length,ue=he>>>1;ee<ue;){var ke=2*(ee+1)-1,se=$[ke],We=ke+1,Fe=$[We];if(0>o(se,Y))We<he&&0>o(Fe,se)?($[ee]=Fe,$[We]=Y,ee=We):($[ee]=se,$[ke]=Y,ee=ke);else if(We<he&&0>o(Fe,Y))$[ee]=Fe,$[We]=Y,ee=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,m=!1,g=!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 P($){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 b($){if(g=!1,P($),!m)if(n(l)!==null)m=!0,L(C);else{var U=n(c);U!==null&&G(b,U.startTime-$)}}function C($,U){m=!1,g&&(g=!1,S(_),_=-1),f=!0;var Y=p;try{for(P(U),h=n(l);h!==null&&(!(h.expirationTime>U)||$&&!D());){var ee=h.callback;if(typeof ee=="function"){h.callback=null,p=h.priorityLevel;var he=ee(h.expirationTime<=U);U=t.unstable_now(),typeof he=="function"?h.callback=he:h===n(l)&&r(l),P(U)}else r(l);h=n(l)}if(h!==null)var ue=!0;else{var ke=n(c);ke!==null&&G(b,ke.startTime-U),ue=!1}return ue}finally{h=null,p=Y,f=!1}}var I=!1,k=null,_=-1,M=5,T=-1;function D(){return!(t.unstable_now()-T<M)}function A(){if(k!==null){var $=t.unstable_now();T=$;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(A)};else if(typeof MessageChannel<"u"){var R=new MessageChannel,B=R.port2;R.port1.onmessage=A,O=function(){B.postMessage(null)}}else O=function(){v(A,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(){m||f||(m=!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"):M=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 ee=t.unstable_now();switch(typeof Y=="object"&&Y!==null?(Y=Y.delay,Y=typeof Y=="number"&&0<Y?ee+Y:ee):Y=ee,$){case 1:var he=-1;break;case 2:he=250;break;case 5:he=1073741823;break;case 4:he=1e4;break;default:he=5e3}return he=Y+he,$={id:u++,callback:U,priorityLevel:$,startTime:Y,expirationTime:he,sortIndex:-1},Y>ee?($.sortIndex=Y,e(c,$),n(l)===null&&$===n(c)&&(g?(S(_),_=-1):g=!0,G(b,Y-ee))):($.sortIndex=he,e(l,$),m||f||(m=!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}}}})(g2);f2.exports=g2;var ZN=f2.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 QN=w,fr=ZN;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 m2=new Set,gu={};function ma(t,e){Pl(t,e),Pl(t+"Capture",e)}function Pl(t,e){for(gu[t]=e,t=0;t<e.length;t++)m2.add(e[t])}var gs=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),XS=Object.prototype.hasOwnProperty,JN=/^[: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]*$/,pP={},fP={};function e6(t){return XS.call(fP,t)?!0:XS.call(pP,t)?!1:JN.test(t)?fP[t]=!0:(pP[t]=!0,!1)}function t6(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 n6(t,e,n,r){if(e===null||typeof e>"u"||t6(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 v0=/[\-:]([a-z])/g;function x0(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(v0,x0);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(v0,x0);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(v0,x0);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 w0(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")&&(n6(e,n,o,r)&&(n=null),r||o===null?e6(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 Ps=QN.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,$d=Symbol.for("react.element"),Ua=Symbol.for("react.portal"),Ha=Symbol.for("react.fragment"),b0=Symbol.for("react.strict_mode"),qS=Symbol.for("react.profiler"),y2=Symbol.for("react.provider"),S2=Symbol.for("react.context"),P0=Symbol.for("react.forward_ref"),ZS=Symbol.for("react.suspense"),QS=Symbol.for("react.suspense_list"),C0=Symbol.for("react.memo"),zs=Symbol.for("react.lazy"),v2=Symbol.for("react.offscreen"),gP=Symbol.iterator;function dc(t){return t===null||typeof t!="object"?null:(t=gP&&t[gP]||t["@@iterator"],typeof t=="function"?t:null)}var gt=Object.assign,Dm;function $c(t){if(Dm===void 0)try{throw Error()}catch(n){var e=n.stack.trim().match(/\n( *(at )?)/);Dm=e&&e[1]||""}return`
|
|
34
|
-
`+Dm+t}var Rm=!1;function Lm(t,e){if(!t||Rm)return"";Rm=!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{Rm=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?$c(t):""}function r6(t){switch(t.tag){case 5:return $c(t.type);case 16:return $c("Lazy");case 13:return $c("Suspense");case 19:return $c("SuspenseList");case 0:case 2:case 15:return t=Lm(t.type,!1),t;case 11:return t=Lm(t.type.render,!1),t;case 1:return t=Lm(t.type,!0),t;default:return""}}function JS(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 Ha:return"Fragment";case Ua:return"Portal";case qS:return"Profiler";case b0:return"StrictMode";case ZS:return"Suspense";case QS:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case S2:return(t.displayName||"Context")+".Consumer";case y2:return(t._context.displayName||"Context")+".Provider";case P0:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case C0:return e=t.displayName||null,e!==null?e:JS(t.type)||"Memo";case zs:e=t._payload,t=t._init;try{return JS(t(e))}catch{}}return null}function o6(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 JS(e);case 8:return e===b0?"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 ui(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function x2(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function s6(t){var e=x2(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 Fd(t){t._valueTracker||(t._valueTracker=s6(t))}function w2(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=x2(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Rp(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 ev(t,e){var n=e.checked;return gt({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function mP(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=ui(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 b2(t,e){e=e.checked,e!=null&&w0(t,"checked",e,!1)}function tv(t,e){b2(t,e);var n=ui(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")?nv(t,e.type,n):e.hasOwnProperty("defaultValue")&&nv(t,e.type,ui(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function yP(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 nv(t,e,n){(e!=="number"||Rp(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var Fc=Array.isArray;function ul(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=""+ui(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 rv(t,e){if(e.dangerouslySetInnerHTML!=null)throw Error(X(91));return gt({},e,{value:void 0,defaultValue:void 0,children:""+t._wrapperState.initialValue})}function SP(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(Fc(n)){if(1<n.length)throw Error(X(93));n=n[0]}e=n}e==null&&(e=""),n=e}t._wrapperState={initialValue:ui(n)}}function P2(t,e){var n=ui(e.value),r=ui(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 vP(t){var e=t.textContent;e===t._wrapperState.initialValue&&e!==""&&e!==null&&(t.value=e)}function C2(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 ov(t,e){return t==null||t==="http://www.w3.org/1999/xhtml"?C2(e):t==="http://www.w3.org/2000/svg"&&e==="foreignObject"?"http://www.w3.org/1999/xhtml":t}var Nd,_2=function(t){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(e,n,r,o){MSApp.execUnsafeLocalFunction(function(){return t(e,n,r,o)})}:t}(function(t,e){if(t.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in t)t.innerHTML=e;else{for(Nd=Nd||document.createElement("div"),Nd.innerHTML="<svg>"+e.valueOf().toString()+"</svg>",e=Nd.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function mu(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Zc={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},i6=["Webkit","ms","Moz","O"];Object.keys(Zc).forEach(function(t){i6.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Zc[e]=Zc[t]})});function I2(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Zc.hasOwnProperty(t)&&Zc[t]?(""+e).trim():e+"px"}function E2(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=I2(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,o):t[n]=o}}var a6=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 sv(t,e){if(e){if(a6[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 iv(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 av=null;function _0(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var lv=null,dl=null,hl=null;function xP(t){if(t=ed(t)){if(typeof lv!="function")throw Error(X(280));var e=t.stateNode;e&&(e=ng(e),lv(t.stateNode,t.type,e))}}function k2(t){dl?hl?hl.push(t):hl=[t]:dl=t}function T2(){if(dl){var t=dl,e=hl;if(hl=dl=null,xP(t),e)for(t=0;t<e.length;t++)xP(e[t])}}function M2(t,e){return t(e)}function A2(){}var $m=!1;function j2(t,e,n){if($m)return t(e,n);$m=!0;try{return M2(t,e,n)}finally{$m=!1,(dl!==null||hl!==null)&&(A2(),T2())}}function yu(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 cv=!1;if(gs)try{var hc={};Object.defineProperty(hc,"passive",{get:function(){cv=!0}}),window.addEventListener("test",hc,hc),window.removeEventListener("test",hc,hc)}catch{cv=!1}function l6(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,Lp=null,$p=!1,uv=null,c6={onError:function(t){Qc=!0,Lp=t}};function u6(t,e,n,r,o,s,i,a,l){Qc=!1,Lp=null,l6.apply(c6,arguments)}function d6(t,e,n,r,o,s,i,a,l){if(u6.apply(this,arguments),Qc){if(Qc){var c=Lp;Qc=!1,Lp=null}else throw Error(X(198));$p||($p=!0,uv=c)}}function ya(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 O2(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 wP(t){if(ya(t)!==t)throw Error(X(188))}function h6(t){var e=t.alternate;if(!e){if(e=ya(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 wP(o),t;if(s===r)return wP(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 D2(t){return t=h6(t),t!==null?R2(t):null}function R2(t){if(t.tag===5||t.tag===6)return t;for(t=t.child;t!==null;){var e=R2(t);if(e!==null)return e;t=t.sibling}return null}var L2=fr.unstable_scheduleCallback,bP=fr.unstable_cancelCallback,p6=fr.unstable_shouldYield,f6=fr.unstable_requestPaint,wt=fr.unstable_now,g6=fr.unstable_getCurrentPriorityLevel,I0=fr.unstable_ImmediatePriority,$2=fr.unstable_UserBlockingPriority,Fp=fr.unstable_NormalPriority,m6=fr.unstable_LowPriority,F2=fr.unstable_IdlePriority,Qf=null,ko=null;function y6(t){if(ko&&typeof ko.onCommitFiberRoot=="function")try{ko.onCommitFiberRoot(Qf,t,void 0,(t.current.flags&128)===128)}catch{}}var Qr=Math.clz32?Math.clz32:x6,S6=Math.log,v6=Math.LN2;function x6(t){return t>>>=0,t===0?32:31-(S6(t)/v6|0)|0}var zd=64,Bd=4194304;function Nc(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 Np(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=Nc(a):(s&=i,s!==0&&(r=Nc(s)))}else i=n&~o,i!==0?r=Nc(i):s!==0&&(r=Nc(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-Qr(e),o=1<<n,r|=t[n],e&=~o;return r}function w6(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 b6(t,e){for(var n=t.suspendedLanes,r=t.pingedLanes,o=t.expirationTimes,s=t.pendingLanes;0<s;){var i=31-Qr(s),a=1<<i,l=o[i];l===-1?(!(a&n)||a&r)&&(o[i]=w6(a,e)):l<=e&&(t.expiredLanes|=a),s&=~a}}function dv(t){return t=t.pendingLanes&-1073741825,t!==0?t:t&1073741824?1073741824:0}function N2(){var t=zd;return zd<<=1,!(zd&4194240)&&(zd=64),t}function Fm(t){for(var e=[],n=0;31>n;n++)e.push(t);return e}function Qu(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-Qr(e),t[e]=n}function P6(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-Qr(n),s=1<<o;e[o]=0,r[o]=-1,t[o]=-1,n&=~s}}function E0(t,e){var n=t.entangledLanes|=e;for(t=t.entanglements;n;){var r=31-Qr(n),o=1<<r;o&e|t[r]&e&&(t[r]|=e),n&=~o}}var Be=0;function z2(t){return t&=-t,1<t?4<t?t&268435455?16:536870912:4:1}var B2,k0,U2,H2,K2,hv=!1,Ud=[],Qs=null,Js=null,ei=null,Su=new Map,vu=new Map,Us=[],C6="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 PP(t,e){switch(t){case"focusin":case"focusout":Qs=null;break;case"dragenter":case"dragleave":Js=null;break;case"mouseover":case"mouseout":ei=null;break;case"pointerover":case"pointerout":Su.delete(e.pointerId);break;case"gotpointercapture":case"lostpointercapture":vu.delete(e.pointerId)}}function pc(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=ed(e),e!==null&&k0(e)),t):(t.eventSystemFlags|=r,e=t.targetContainers,o!==null&&e.indexOf(o)===-1&&e.push(o),t)}function _6(t,e,n,r,o){switch(e){case"focusin":return Qs=pc(Qs,t,e,n,r,o),!0;case"dragenter":return Js=pc(Js,t,e,n,r,o),!0;case"mouseover":return ei=pc(ei,t,e,n,r,o),!0;case"pointerover":var s=o.pointerId;return Su.set(s,pc(Su.get(s)||null,t,e,n,r,o)),!0;case"gotpointercapture":return s=o.pointerId,vu.set(s,pc(vu.get(s)||null,t,e,n,r,o)),!0}return!1}function W2(t){var e=Hi(t.target);if(e!==null){var n=ya(e);if(n!==null){if(e=n.tag,e===13){if(e=O2(n),e!==null){t.blockedOn=e,K2(t.priority,function(){U2(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 Uh(t){if(t.blockedOn!==null)return!1;for(var e=t.targetContainers;0<e.length;){var n=pv(t.domEventName,t.eventSystemFlags,e[0],t.nativeEvent);if(n===null){n=t.nativeEvent;var r=new n.constructor(n.type,n);av=r,n.target.dispatchEvent(r),av=null}else return e=ed(n),e!==null&&k0(e),t.blockedOn=n,!1;e.shift()}return!0}function CP(t,e,n){Uh(t)&&n.delete(e)}function I6(){hv=!1,Qs!==null&&Uh(Qs)&&(Qs=null),Js!==null&&Uh(Js)&&(Js=null),ei!==null&&Uh(ei)&&(ei=null),Su.forEach(CP),vu.forEach(CP)}function fc(t,e){t.blockedOn===e&&(t.blockedOn=null,hv||(hv=!0,fr.unstable_scheduleCallback(fr.unstable_NormalPriority,I6)))}function xu(t){function e(o){return fc(o,t)}if(0<Ud.length){fc(Ud[0],t);for(var n=1;n<Ud.length;n++){var r=Ud[n];r.blockedOn===t&&(r.blockedOn=null)}}for(Qs!==null&&fc(Qs,t),Js!==null&&fc(Js,t),ei!==null&&fc(ei,t),Su.forEach(e),vu.forEach(e),n=0;n<Us.length;n++)r=Us[n],r.blockedOn===t&&(r.blockedOn=null);for(;0<Us.length&&(n=Us[0],n.blockedOn===null);)W2(n),n.blockedOn===null&&Us.shift()}var pl=Ps.ReactCurrentBatchConfig,zp=!0;function E6(t,e,n,r){var o=Be,s=pl.transition;pl.transition=null;try{Be=1,T0(t,e,n,r)}finally{Be=o,pl.transition=s}}function k6(t,e,n,r){var o=Be,s=pl.transition;pl.transition=null;try{Be=4,T0(t,e,n,r)}finally{Be=o,pl.transition=s}}function T0(t,e,n,r){if(zp){var o=pv(t,e,n,r);if(o===null)Ym(t,e,r,Bp,n),PP(t,r);else if(_6(o,t,e,n,r))r.stopPropagation();else if(PP(t,r),e&4&&-1<C6.indexOf(t)){for(;o!==null;){var s=ed(o);if(s!==null&&B2(s),s=pv(t,e,n,r),s===null&&Ym(t,e,r,Bp,n),s===o)break;o=s}o!==null&&r.stopPropagation()}else Ym(t,e,r,null,n)}}var Bp=null;function pv(t,e,n,r){if(Bp=null,t=_0(r),t=Hi(t),t!==null)if(e=ya(t),e===null)t=null;else if(n=e.tag,n===13){if(t=O2(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 Bp=t,null}function G2(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(g6()){case I0:return 1;case $2:return 4;case Fp:case m6:return 16;case F2:return 536870912;default:return 16}default:return 16}}var Vs=null,M0=null,Hh=null;function V2(){if(Hh)return Hh;var t,e=M0,n=e.length,r,o="value"in Vs?Vs.value:Vs.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 Hh=o.slice(t,1<r?1-r:void 0)}function Kh(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 Hd(){return!0}function _P(){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)?Hd:_P,this.isPropagationStopped=_P,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=Hd)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=Hd)},persist:function(){},isPersistent:Hd}),e}var zl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(t){return t.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},A0=vr(zl),Ju=gt({},zl,{view:0,detail:0}),T6=vr(Ju),Nm,zm,gc,Jf=gt({},Ju,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:j0,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!==gc&&(gc&&t.type==="mousemove"?(Nm=t.screenX-gc.screenX,zm=t.screenY-gc.screenY):zm=Nm=0,gc=t),Nm)},movementY:function(t){return"movementY"in t?t.movementY:zm}}),IP=vr(Jf),M6=gt({},Jf,{dataTransfer:0}),A6=vr(M6),j6=gt({},Ju,{relatedTarget:0}),Bm=vr(j6),O6=gt({},zl,{animationName:0,elapsedTime:0,pseudoElement:0}),D6=vr(O6),R6=gt({},zl,{clipboardData:function(t){return"clipboardData"in t?t.clipboardData:window.clipboardData}}),L6=vr(R6),$6=gt({},zl,{data:0}),EP=vr($6),F6={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},N6={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"},z6={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function B6(t){var e=this.nativeEvent;return e.getModifierState?e.getModifierState(t):(t=z6[t])?!!e[t]:!1}function j0(){return B6}var U6=gt({},Ju,{key:function(t){if(t.key){var e=F6[t.key]||t.key;if(e!=="Unidentified")return e}return t.type==="keypress"?(t=Kh(t),t===13?"Enter":String.fromCharCode(t)):t.type==="keydown"||t.type==="keyup"?N6[t.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:j0,charCode:function(t){return t.type==="keypress"?Kh(t):0},keyCode:function(t){return t.type==="keydown"||t.type==="keyup"?t.keyCode:0},which:function(t){return t.type==="keypress"?Kh(t):t.type==="keydown"||t.type==="keyup"?t.keyCode:0}}),H6=vr(U6),K6=gt({},Jf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),kP=vr(K6),W6=gt({},Ju,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:j0}),G6=vr(W6),V6=gt({},zl,{propertyName:0,elapsedTime:0,pseudoElement:0}),Y6=vr(V6),X6=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}),q6=vr(X6),Z6=[9,13,27,32],O0=gs&&"CompositionEvent"in window,Jc=null;gs&&"documentMode"in document&&(Jc=document.documentMode);var Q6=gs&&"TextEvent"in window&&!Jc,Y2=gs&&(!O0||Jc&&8<Jc&&11>=Jc),TP=" ",MP=!1;function X2(t,e){switch(t){case"keyup":return Z6.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function q2(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var Ka=!1;function J6(t,e){switch(t){case"compositionend":return q2(e);case"keypress":return e.which!==32?null:(MP=!0,TP);case"textInput":return t=e.data,t===TP&&MP?null:t;default:return null}}function ez(t,e){if(Ka)return t==="compositionend"||!O0&&X2(t,e)?(t=V2(),Hh=M0=Vs=null,Ka=!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 Y2&&e.locale!=="ko"?null:e.data;default:return null}}var tz={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 AP(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e==="input"?!!tz[t.type]:e==="textarea"}function Z2(t,e,n,r){k2(r),e=Up(e,"onChange"),0<e.length&&(n=new A0("onChange","change",null,n,r),t.push({event:n,listeners:e}))}var eu=null,wu=null;function nz(t){lk(t,0)}function eg(t){var e=Va(t);if(w2(e))return t}function rz(t,e){if(t==="change")return e}var Q2=!1;if(gs){var Um;if(gs){var Hm="oninput"in document;if(!Hm){var jP=document.createElement("div");jP.setAttribute("oninput","return;"),Hm=typeof jP.oninput=="function"}Um=Hm}else Um=!1;Q2=Um&&(!document.documentMode||9<document.documentMode)}function OP(){eu&&(eu.detachEvent("onpropertychange",J2),wu=eu=null)}function J2(t){if(t.propertyName==="value"&&eg(wu)){var e=[];Z2(e,wu,t,_0(t)),j2(nz,e)}}function oz(t,e,n){t==="focusin"?(OP(),eu=e,wu=n,eu.attachEvent("onpropertychange",J2)):t==="focusout"&&OP()}function sz(t){if(t==="selectionchange"||t==="keyup"||t==="keydown")return eg(wu)}function iz(t,e){if(t==="click")return eg(e)}function az(t,e){if(t==="input"||t==="change")return eg(e)}function lz(t,e){return t===e&&(t!==0||1/t===1/e)||t!==t&&e!==e}var ro=typeof Object.is=="function"?Object.is:lz;function bu(t,e){if(ro(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(!XS.call(e,o)||!ro(t[o],e[o]))return!1}return!0}function DP(t){for(;t&&t.firstChild;)t=t.firstChild;return t}function RP(t,e){var n=DP(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=DP(n)}}function ek(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?ek(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function tk(){for(var t=window,e=Rp();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Rp(t.document)}return e}function D0(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 cz(t){var e=tk(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&ek(n.ownerDocument.documentElement,n)){if(r!==null&&D0(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=RP(n,s);var i=RP(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 uz=gs&&"documentMode"in document&&11>=document.documentMode,Wa=null,fv=null,tu=null,gv=!1;function LP(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;gv||Wa==null||Wa!==Rp(r)||(r=Wa,"selectionStart"in r&&D0(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}),tu&&bu(tu,r)||(tu=r,r=Up(fv,"onSelect"),0<r.length&&(e=new A0("onSelect","select",null,e,n),t.push({event:e,listeners:r}),e.target=Wa)))}function Kd(t,e){var n={};return n[t.toLowerCase()]=e.toLowerCase(),n["Webkit"+t]="webkit"+e,n["Moz"+t]="moz"+e,n}var Ga={animationend:Kd("Animation","AnimationEnd"),animationiteration:Kd("Animation","AnimationIteration"),animationstart:Kd("Animation","AnimationStart"),transitionend:Kd("Transition","TransitionEnd")},Km={},nk={};gs&&(nk=document.createElement("div").style,"AnimationEvent"in window||(delete Ga.animationend.animation,delete Ga.animationiteration.animation,delete Ga.animationstart.animation),"TransitionEvent"in window||delete Ga.transitionend.transition);function tg(t){if(Km[t])return Km[t];if(!Ga[t])return t;var e=Ga[t],n;for(n in e)if(e.hasOwnProperty(n)&&n in nk)return Km[t]=e[n];return t}var rk=tg("animationend"),ok=tg("animationiteration"),sk=tg("animationstart"),ik=tg("transitionend"),ak=new Map,$P="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 xi(t,e){ak.set(t,e),ma(e,[t])}for(var Wm=0;Wm<$P.length;Wm++){var Gm=$P[Wm],dz=Gm.toLowerCase(),hz=Gm[0].toUpperCase()+Gm.slice(1);xi(dz,"on"+hz)}xi(rk,"onAnimationEnd");xi(ok,"onAnimationIteration");xi(sk,"onAnimationStart");xi("dblclick","onDoubleClick");xi("focusin","onFocus");xi("focusout","onBlur");xi(ik,"onTransitionEnd");Pl("onMouseEnter",["mouseout","mouseover"]);Pl("onMouseLeave",["mouseout","mouseover"]);Pl("onPointerEnter",["pointerout","pointerover"]);Pl("onPointerLeave",["pointerout","pointerover"]);ma("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));ma("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));ma("onBeforeInput",["compositionend","keypress","textInput","paste"]);ma("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));ma("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));ma("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var zc="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),pz=new Set("cancel close invalid load scroll toggle".split(" ").concat(zc));function FP(t,e,n){var r=t.type||"unknown-event";t.currentTarget=n,d6(r,e,void 0,t),t.currentTarget=null}function lk(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;FP(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;FP(o,a,c),s=l}}}if($p)throw t=uv,$p=!1,uv=null,t}function tt(t,e){var n=e[xv];n===void 0&&(n=e[xv]=new Set);var r=t+"__bubble";n.has(r)||(ck(e,t,2,!1),n.add(r))}function Vm(t,e,n){var r=0;e&&(r|=4),ck(n,t,r,e)}var Wd="_reactListening"+Math.random().toString(36).slice(2);function Pu(t){if(!t[Wd]){t[Wd]=!0,m2.forEach(function(n){n!=="selectionchange"&&(pz.has(n)||Vm(n,!1,t),Vm(n,!0,t))});var e=t.nodeType===9?t:t.ownerDocument;e===null||e[Wd]||(e[Wd]=!0,Vm("selectionchange",!1,e))}}function ck(t,e,n,r){switch(G2(e)){case 1:var o=E6;break;case 4:o=k6;break;default:o=T0}n=o.bind(null,e,n,t),o=void 0,!cv||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 Ym(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=Hi(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}j2(function(){var c=s,u=_0(n),h=[];e:{var p=ak.get(t);if(p!==void 0){var f=A0,m=t;switch(t){case"keypress":if(Kh(n)===0)break e;case"keydown":case"keyup":f=H6;break;case"focusin":m="focus",f=Bm;break;case"focusout":m="blur",f=Bm;break;case"beforeblur":case"afterblur":f=Bm;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=IP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=A6;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=G6;break;case rk:case ok:case sk:f=D6;break;case ik:f=Y6;break;case"scroll":f=T6;break;case"wheel":f=q6;break;case"copy":case"cut":case"paste":f=L6;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=kP}var g=(e&4)!==0,v=!g&&t==="scroll",S=g?p!==null?p+"Capture":null:p;g=[];for(var y=c,P;y!==null;){P=y;var b=P.stateNode;if(P.tag===5&&b!==null&&(P=b,S!==null&&(b=yu(y,S),b!=null&&g.push(Cu(y,b,P)))),v)break;y=y.return}0<g.length&&(p=new f(p,m,null,n,u),h.push({event:p,listeners:g}))}}if(!(e&7)){e:{if(p=t==="mouseover"||t==="pointerover",f=t==="mouseout"||t==="pointerout",p&&n!==av&&(m=n.relatedTarget||n.fromElement)&&(Hi(m)||m[ms]))break e;if((f||p)&&(p=u.window===u?u:(p=u.ownerDocument)?p.defaultView||p.parentWindow:window,f?(m=n.relatedTarget||n.toElement,f=c,m=m?Hi(m):null,m!==null&&(v=ya(m),m!==v||m.tag!==5&&m.tag!==6)&&(m=null)):(f=null,m=c),f!==m)){if(g=IP,b="onMouseLeave",S="onMouseEnter",y="mouse",(t==="pointerout"||t==="pointerover")&&(g=kP,b="onPointerLeave",S="onPointerEnter",y="pointer"),v=f==null?p:Va(f),P=m==null?p:Va(m),p=new g(b,y+"leave",f,n,u),p.target=v,p.relatedTarget=P,b=null,Hi(u)===c&&(g=new g(S,y+"enter",m,n,u),g.target=P,g.relatedTarget=v,b=g),v=b,f&&m)t:{for(g=f,S=m,y=0,P=g;P;P=Ea(P))y++;for(P=0,b=S;b;b=Ea(b))P++;for(;0<y-P;)g=Ea(g),y--;for(;0<P-y;)S=Ea(S),P--;for(;y--;){if(g===S||S!==null&&g===S.alternate)break t;g=Ea(g),S=Ea(S)}g=null}else g=null;f!==null&&NP(h,p,f,g,!1),m!==null&&v!==null&&NP(h,v,m,g,!0)}}e:{if(p=c?Va(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var C=rz;else if(AP(p))if(Q2)C=az;else{C=sz;var I=oz}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(C=iz);if(C&&(C=C(t,c))){Z2(h,C,n,u);break e}I&&I(t,p,c),t==="focusout"&&(I=p._wrapperState)&&I.controlled&&p.type==="number"&&nv(p,"number",p.value)}switch(I=c?Va(c):window,t){case"focusin":(AP(I)||I.contentEditable==="true")&&(Wa=I,fv=c,tu=null);break;case"focusout":tu=fv=Wa=null;break;case"mousedown":gv=!0;break;case"contextmenu":case"mouseup":case"dragend":gv=!1,LP(h,n,u);break;case"selectionchange":if(uz)break;case"keydown":case"keyup":LP(h,n,u)}var k;if(O0)e:{switch(t){case"compositionstart":var _="onCompositionStart";break e;case"compositionend":_="onCompositionEnd";break e;case"compositionupdate":_="onCompositionUpdate";break e}_=void 0}else Ka?X2(t,n)&&(_="onCompositionEnd"):t==="keydown"&&n.keyCode===229&&(_="onCompositionStart");_&&(Y2&&n.locale!=="ko"&&(Ka||_!=="onCompositionStart"?_==="onCompositionEnd"&&Ka&&(k=V2()):(Vs=u,M0="value"in Vs?Vs.value:Vs.textContent,Ka=!0)),I=Up(c,_),0<I.length&&(_=new EP(_,t,null,n,u),h.push({event:_,listeners:I}),k?_.data=k:(k=q2(n),k!==null&&(_.data=k)))),(k=Q6?J6(t,n):ez(t,n))&&(c=Up(c,"onBeforeInput"),0<c.length&&(u=new EP("onBeforeInput","beforeinput",null,n,u),h.push({event:u,listeners:c}),u.data=k))}lk(h,e)})}function Cu(t,e,n){return{instance:t,listener:e,currentTarget:n}}function Up(t,e){for(var n=e+"Capture",r=[];t!==null;){var o=t,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=yu(t,n),s!=null&&r.unshift(Cu(t,s,o)),s=yu(t,e),s!=null&&r.push(Cu(t,s,o))),t=t.return}return r}function Ea(t){if(t===null)return null;do t=t.return;while(t&&t.tag!==5);return t||null}function NP(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=yu(n,s),l!=null&&i.unshift(Cu(n,l,a))):o||(l=yu(n,s),l!=null&&i.push(Cu(n,l,a)))),n=n.return}i.length!==0&&t.push({event:e,listeners:i})}var fz=/\r\n?/g,gz=/\u0000|\uFFFD/g;function zP(t){return(typeof t=="string"?t:""+t).replace(fz,`
|
|
38
|
-
`).replace(gz,"")}function Gd(t,e,n){if(e=zP(e),zP(t)!==e&&n)throw Error(X(425))}function Hp(){}var mv=null,yv=null;function Sv(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 vv=typeof setTimeout=="function"?setTimeout:void 0,mz=typeof clearTimeout=="function"?clearTimeout:void 0,BP=typeof Promise=="function"?Promise:void 0,yz=typeof queueMicrotask=="function"?queueMicrotask:typeof BP<"u"?function(t){return BP.resolve(null).then(t).catch(Sz)}:vv;function Sz(t){setTimeout(function(){throw t})}function Xm(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),xu(e);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=o}while(n);xu(e)}function ti(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 UP(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 Bl=Math.random().toString(36).slice(2),wo="__reactFiber$"+Bl,_u="__reactProps$"+Bl,ms="__reactContainer$"+Bl,xv="__reactEvents$"+Bl,vz="__reactListeners$"+Bl,xz="__reactHandles$"+Bl;function Hi(t){var e=t[wo];if(e)return e;for(var n=t.parentNode;n;){if(e=n[ms]||n[wo]){if(n=e.alternate,e.child!==null||n!==null&&n.child!==null)for(t=UP(t);t!==null;){if(n=t[wo])return n;t=UP(t)}return e}t=n,n=t.parentNode}return null}function ed(t){return t=t[wo]||t[ms],!t||t.tag!==5&&t.tag!==6&&t.tag!==13&&t.tag!==3?null:t}function Va(t){if(t.tag===5||t.tag===6)return t.stateNode;throw Error(X(33))}function ng(t){return t[_u]||null}var wv=[],Ya=-1;function wi(t){return{current:t}}function rt(t){0>Ya||(t.current=wv[Ya],wv[Ya]=null,Ya--)}function qe(t,e){Ya++,wv[Ya]=t.current,t.current=e}var di={},fn=wi(di),Vn=wi(!1),Qi=di;function Cl(t,e){var n=t.type.contextTypes;if(!n)return di;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 Yn(t){return t=t.childContextTypes,t!=null}function Kp(){rt(Vn),rt(fn)}function HP(t,e,n){if(fn.current!==di)throw Error(X(168));qe(fn,e),qe(Vn,n)}function uk(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,o6(t)||"Unknown",o));return gt({},n,r)}function Wp(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||di,Qi=fn.current,qe(fn,t),qe(Vn,Vn.current),!0}function KP(t,e,n){var r=t.stateNode;if(!r)throw Error(X(169));n?(t=uk(t,e,Qi),r.__reactInternalMemoizedMergedChildContext=t,rt(Vn),rt(fn),qe(fn,t)):rt(Vn),qe(Vn,n)}var ns=null,rg=!1,qm=!1;function dk(t){ns===null?ns=[t]:ns.push(t)}function wz(t){rg=!0,dk(t)}function bi(){if(!qm&&ns!==null){qm=!0;var t=0,e=Be;try{var n=ns;for(Be=1;t<n.length;t++){var r=n[t];do r=r(!0);while(r!==null)}ns=null,rg=!1}catch(o){throw ns!==null&&(ns=ns.slice(t+1)),L2(I0,bi),o}finally{Be=e,qm=!1}}return null}var Xa=[],qa=0,Gp=null,Vp=0,kr=[],Tr=0,Ji=null,os=1,ss="";function Ni(t,e){Xa[qa++]=Vp,Xa[qa++]=Gp,Gp=t,Vp=e}function hk(t,e,n){kr[Tr++]=os,kr[Tr++]=ss,kr[Tr++]=Ji,Ji=t;var r=os;t=ss;var o=32-Qr(r)-1;r&=~(1<<o),n+=1;var s=32-Qr(e)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,os=1<<32-Qr(e)+o|n<<o|r,ss=s+t}else os=1<<s|n<<o|r,ss=t}function R0(t){t.return!==null&&(Ni(t,1),hk(t,1,0))}function L0(t){for(;t===Gp;)Gp=Xa[--qa],Xa[qa]=null,Vp=Xa[--qa],Xa[qa]=null;for(;t===Ji;)Ji=kr[--Tr],kr[Tr]=null,ss=kr[--Tr],kr[Tr]=null,os=kr[--Tr],kr[Tr]=null}var cr=null,ar=null,at=!1,Vr=null;function pk(t,e){var n=Ar(5,null,null,0);n.elementType="DELETED",n.stateNode=e,n.return=t,e=t.deletions,e===null?(t.deletions=[n],t.flags|=16):e.push(n)}function WP(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=ti(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=Ji!==null?{id:os,overflow:ss}:null,t.memoizedState={dehydrated:e,treeContext:n,retryLane:1073741824},n=Ar(18,null,null,0),n.stateNode=e,n.return=t,t.child=n,cr=t,ar=null,!0):!1;default:return!1}}function bv(t){return(t.mode&1)!==0&&(t.flags&128)===0}function Pv(t){if(at){var e=ar;if(e){var n=e;if(!WP(t,e)){if(bv(t))throw Error(X(418));e=ti(n.nextSibling);var r=cr;e&&WP(t,e)?pk(r,n):(t.flags=t.flags&-4097|2,at=!1,cr=t)}}else{if(bv(t))throw Error(X(418));t.flags=t.flags&-4097|2,at=!1,cr=t}}}function GP(t){for(t=t.return;t!==null&&t.tag!==5&&t.tag!==3&&t.tag!==13;)t=t.return;cr=t}function Vd(t){if(t!==cr)return!1;if(!at)return GP(t),at=!0,!1;var e;if((e=t.tag!==3)&&!(e=t.tag!==5)&&(e=t.type,e=e!=="head"&&e!=="body"&&!Sv(t.type,t.memoizedProps)),e&&(e=ar)){if(bv(t))throw fk(),Error(X(418));for(;e;)pk(t,e),e=ti(e.nextSibling)}if(GP(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=ti(t.nextSibling);break e}e--}else n!=="$"&&n!=="$!"&&n!=="$?"||e++}t=t.nextSibling}ar=null}}else ar=cr?ti(t.stateNode.nextSibling):null;return!0}function fk(){for(var t=ar;t;)t=ti(t.nextSibling)}function _l(){ar=cr=null,at=!1}function $0(t){Vr===null?Vr=[t]:Vr.push(t)}var bz=Ps.ReactCurrentBatchConfig;function mc(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 Yd(t,e){throw t=Object.prototype.toString.call(e),Error(X(31,t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t))}function VP(t){var e=t._init;return e(t._payload)}function gk(t){function e(S,y){if(t){var P=S.deletions;P===null?(S.deletions=[y],S.flags|=16):P.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=si(S,y),S.index=0,S.sibling=null,S}function s(S,y,P){return S.index=P,t?(P=S.alternate,P!==null?(P=P.index,P<y?(S.flags|=2,y):P):(S.flags|=2,y)):(S.flags|=1048576,y)}function i(S){return t&&S.alternate===null&&(S.flags|=2),S}function a(S,y,P,b){return y===null||y.tag!==6?(y=ry(P,S.mode,b),y.return=S,y):(y=o(y,P),y.return=S,y)}function l(S,y,P,b){var C=P.type;return C===Ha?u(S,y,P.props.children,b,P.key):y!==null&&(y.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===zs&&VP(C)===y.type)?(b=o(y,P.props),b.ref=mc(S,y,P),b.return=S,b):(b=Zh(P.type,P.key,P.props,null,S.mode,b),b.ref=mc(S,y,P),b.return=S,b)}function c(S,y,P,b){return y===null||y.tag!==4||y.stateNode.containerInfo!==P.containerInfo||y.stateNode.implementation!==P.implementation?(y=oy(P,S.mode,b),y.return=S,y):(y=o(y,P.children||[]),y.return=S,y)}function u(S,y,P,b,C){return y===null||y.tag!==7?(y=Yi(P,S.mode,b,C),y.return=S,y):(y=o(y,P),y.return=S,y)}function h(S,y,P){if(typeof y=="string"&&y!==""||typeof y=="number")return y=ry(""+y,S.mode,P),y.return=S,y;if(typeof y=="object"&&y!==null){switch(y.$$typeof){case $d:return P=Zh(y.type,y.key,y.props,null,S.mode,P),P.ref=mc(S,null,y),P.return=S,P;case Ua:return y=oy(y,S.mode,P),y.return=S,y;case zs:var b=y._init;return h(S,b(y._payload),P)}if(Fc(y)||dc(y))return y=Yi(y,S.mode,P,null),y.return=S,y;Yd(S,y)}return null}function p(S,y,P,b){var C=y!==null?y.key:null;if(typeof P=="string"&&P!==""||typeof P=="number")return C!==null?null:a(S,y,""+P,b);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case $d:return P.key===C?l(S,y,P,b):null;case Ua:return P.key===C?c(S,y,P,b):null;case zs:return C=P._init,p(S,y,C(P._payload),b)}if(Fc(P)||dc(P))return C!==null?null:u(S,y,P,b,null);Yd(S,P)}return null}function f(S,y,P,b,C){if(typeof b=="string"&&b!==""||typeof b=="number")return S=S.get(P)||null,a(y,S,""+b,C);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case $d:return S=S.get(b.key===null?P:b.key)||null,l(y,S,b,C);case Ua:return S=S.get(b.key===null?P:b.key)||null,c(y,S,b,C);case zs:var I=b._init;return f(S,y,P,I(b._payload),C)}if(Fc(b)||dc(b))return S=S.get(P)||null,u(y,S,b,C,null);Yd(y,b)}return null}function m(S,y,P,b){for(var C=null,I=null,k=y,_=y=0,M=null;k!==null&&_<P.length;_++){k.index>_?(M=k,k=null):M=k.sibling;var T=p(S,k,P[_],b);if(T===null){k===null&&(k=M);break}t&&k&&T.alternate===null&&e(S,k),y=s(T,y,_),I===null?C=T:I.sibling=T,I=T,k=M}if(_===P.length)return n(S,k),at&&Ni(S,_),C;if(k===null){for(;_<P.length;_++)k=h(S,P[_],b),k!==null&&(y=s(k,y,_),I===null?C=k:I.sibling=k,I=k);return at&&Ni(S,_),C}for(k=r(S,k);_<P.length;_++)M=f(k,S,_,P[_],b),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(D){return e(S,D)}),at&&Ni(S,_),C}function g(S,y,P,b){var C=dc(P);if(typeof C!="function")throw Error(X(150));if(P=C.call(P),P==null)throw Error(X(151));for(var I=C=null,k=y,_=y=0,M=null,T=P.next();k!==null&&!T.done;_++,T=P.next()){k.index>_?(M=k,k=null):M=k.sibling;var D=p(S,k,T.value,b);if(D===null){k===null&&(k=M);break}t&&k&&D.alternate===null&&e(S,k),y=s(D,y,_),I===null?C=D:I.sibling=D,I=D,k=M}if(T.done)return n(S,k),at&&Ni(S,_),C;if(k===null){for(;!T.done;_++,T=P.next())T=h(S,T.value,b),T!==null&&(y=s(T,y,_),I===null?C=T:I.sibling=T,I=T);return at&&Ni(S,_),C}for(k=r(S,k);!T.done;_++,T=P.next())T=f(k,S,_,T.value,b),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(A){return e(S,A)}),at&&Ni(S,_),C}function v(S,y,P,b){if(typeof P=="object"&&P!==null&&P.type===Ha&&P.key===null&&(P=P.props.children),typeof P=="object"&&P!==null){switch(P.$$typeof){case $d:e:{for(var C=P.key,I=y;I!==null;){if(I.key===C){if(C=P.type,C===Ha){if(I.tag===7){n(S,I.sibling),y=o(I,P.props.children),y.return=S,S=y;break e}}else if(I.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===zs&&VP(C)===I.type){n(S,I.sibling),y=o(I,P.props),y.ref=mc(S,I,P),y.return=S,S=y;break e}n(S,I);break}else e(S,I);I=I.sibling}P.type===Ha?(y=Yi(P.props.children,S.mode,b,P.key),y.return=S,S=y):(b=Zh(P.type,P.key,P.props,null,S.mode,b),b.ref=mc(S,y,P),b.return=S,S=b)}return i(S);case Ua:e:{for(I=P.key;y!==null;){if(y.key===I)if(y.tag===4&&y.stateNode.containerInfo===P.containerInfo&&y.stateNode.implementation===P.implementation){n(S,y.sibling),y=o(y,P.children||[]),y.return=S,S=y;break e}else{n(S,y);break}else e(S,y);y=y.sibling}y=oy(P,S.mode,b),y.return=S,S=y}return i(S);case zs:return I=P._init,v(S,y,I(P._payload),b)}if(Fc(P))return m(S,y,P,b);if(dc(P))return g(S,y,P,b);Yd(S,P)}return typeof P=="string"&&P!==""||typeof P=="number"?(P=""+P,y!==null&&y.tag===6?(n(S,y.sibling),y=o(y,P),y.return=S,S=y):(n(S,y),y=ry(P,S.mode,b),y.return=S,S=y),i(S)):n(S,y)}return v}var Il=gk(!0),mk=gk(!1),Yp=wi(null),Xp=null,Za=null,F0=null;function N0(){F0=Za=Xp=null}function z0(t){var e=Yp.current;rt(Yp),t._currentValue=e}function Cv(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 fl(t,e){Xp=t,F0=Za=null,t=t.dependencies,t!==null&&t.firstContext!==null&&(t.lanes&e&&(Un=!0),t.firstContext=null)}function Rr(t){var e=t._currentValue;if(F0!==t)if(t={context:t,memoizedValue:e,next:null},Za===null){if(Xp===null)throw Error(X(308));Za=t,Xp.dependencies={lanes:0,firstContext:t}}else Za=Za.next=t;return e}var Ki=null;function B0(t){Ki===null?Ki=[t]:Ki.push(t)}function yk(t,e,n,r){var o=e.interleaved;return o===null?(n.next=n,B0(e)):(n.next=o.next,o.next=n),e.interleaved=n,ys(t,r)}function ys(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 Bs=!1;function U0(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Sk(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 ls(t,e){return{eventTime:t,lane:e,tag:0,payload:null,callback:null,next:null}}function ni(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,ys(t,n)}return o=r.interleaved,o===null?(e.next=e,B0(r)):(e.next=o.next,o.next=e),r.interleaved=e,ys(t,n)}function Wh(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,E0(t,n)}}function YP(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 qp(t,e,n,r){var o=t.updateQueue;Bs=!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 m=t,g=a;switch(p=e,f=n,g.tag){case 1:if(m=g.payload,typeof m=="function"){h=m.call(f,h,p);break e}h=m;break e;case 3:m.flags=m.flags&-65537|128;case 0:if(m=g.payload,p=typeof m=="function"?m.call(f,h,p):m,p==null)break e;h=gt({},h,p);break e;case 2:Bs=!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);ta|=i,t.lanes=i,t.memoizedState=h}}function XP(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 td={},To=wi(td),Iu=wi(td),Eu=wi(td);function Wi(t){if(t===td)throw Error(X(174));return t}function H0(t,e){switch(qe(Eu,e),qe(Iu,t),qe(To,td),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:ov(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=ov(e,t)}rt(To),qe(To,e)}function El(){rt(To),rt(Iu),rt(Eu)}function vk(t){Wi(Eu.current);var e=Wi(To.current),n=ov(e,t.type);e!==n&&(qe(Iu,t),qe(To,n))}function K0(t){Iu.current===t&&(rt(To),rt(Iu))}var dt=wi(0);function Zp(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 Zm=[];function W0(){for(var t=0;t<Zm.length;t++)Zm[t]._workInProgressVersionPrimary=null;Zm.length=0}var Gh=Ps.ReactCurrentDispatcher,Qm=Ps.ReactCurrentBatchConfig,ea=0,ft=null,kt=null,jt=null,Qp=!1,nu=!1,ku=0,Pz=0;function tn(){throw Error(X(321))}function G0(t,e){if(e===null)return!1;for(var n=0;n<e.length&&n<t.length;n++)if(!ro(t[n],e[n]))return!1;return!0}function V0(t,e,n,r,o,s){if(ea=s,ft=e,e.memoizedState=null,e.updateQueue=null,e.lanes=0,Gh.current=t===null||t.memoizedState===null?Ez:kz,t=n(r,o),nu){s=0;do{if(nu=!1,ku=0,25<=s)throw Error(X(301));s+=1,jt=kt=null,e.updateQueue=null,Gh.current=Tz,t=n(r,o)}while(nu)}if(Gh.current=Jp,e=kt!==null&&kt.next!==null,ea=0,jt=kt=ft=null,Qp=!1,e)throw Error(X(300));return t}function Y0(){var t=ku!==0;return ku=0,t}function vo(){var t={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return jt===null?ft.memoizedState=jt=t:jt=jt.next=t,jt}function Lr(){if(kt===null){var t=ft.alternate;t=t!==null?t.memoizedState:null}else t=kt.next;var e=jt===null?ft.memoizedState:jt.next;if(e!==null)jt=e,kt=t;else{if(t===null)throw Error(X(310));kt=t,t={memoizedState:kt.memoizedState,baseState:kt.baseState,baseQueue:kt.baseQueue,queue:kt.queue,next:null},jt===null?ft.memoizedState=jt=t:jt=jt.next=t}return jt}function Tu(t,e){return typeof e=="function"?e(t):e}function Jm(t){var e=Lr(),n=e.queue;if(n===null)throw Error(X(311));n.lastRenderedReducer=t;var r=kt,o=r.baseQueue,s=n.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,n.pending=null}if(o!==null){s=o.next,r=r.baseState;var a=i=null,l=null,c=s;do{var u=c.lane;if((ea&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,ta|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,ro(r,e.memoizedState)||(Un=!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,ta|=s,o=o.next;while(o!==t)}else o===null&&(n.lanes=0);return[e.memoizedState,n.dispatch]}function ey(t){var e=Lr(),n=e.queue;if(n===null)throw Error(X(311));n.lastRenderedReducer=t;var r=n.dispatch,o=n.pending,s=e.memoizedState;if(o!==null){n.pending=null;var i=o=o.next;do s=t(s,i.action),i=i.next;while(i!==o);ro(s,e.memoizedState)||(Un=!0),e.memoizedState=s,e.baseQueue===null&&(e.baseState=s),n.lastRenderedState=s}return[s,r]}function xk(){}function wk(t,e){var n=ft,r=Lr(),o=e(),s=!ro(r.memoizedState,o);if(s&&(r.memoizedState=o,Un=!0),r=r.queue,X0(Ck.bind(null,n,r,t),[t]),r.getSnapshot!==e||s||jt!==null&&jt.memoizedState.tag&1){if(n.flags|=2048,Mu(9,Pk.bind(null,n,r,o,e),void 0,null),Rt===null)throw Error(X(349));ea&30||bk(n,e,o)}return o}function bk(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 Pk(t,e,n,r){e.value=n,e.getSnapshot=r,_k(e)&&Ik(t)}function Ck(t,e,n){return n(function(){_k(e)&&Ik(t)})}function _k(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!ro(t,n)}catch{return!0}}function Ik(t){var e=ys(t,1);e!==null&&Jr(e,t,1,-1)}function qP(t){var e=vo();return typeof t=="function"&&(t=t()),e.memoizedState=e.baseState=t,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Tu,lastRenderedState:t},e.queue=t,t=t.dispatch=Iz.bind(null,ft,t),[e.memoizedState,t]}function Mu(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 Ek(){return Lr().memoizedState}function Vh(t,e,n,r){var o=vo();ft.flags|=t,o.memoizedState=Mu(1|e,n,void 0,r===void 0?null:r)}function og(t,e,n,r){var o=Lr();r=r===void 0?null:r;var s=void 0;if(kt!==null){var i=kt.memoizedState;if(s=i.destroy,r!==null&&G0(r,i.deps)){o.memoizedState=Mu(e,n,s,r);return}}ft.flags|=t,o.memoizedState=Mu(1|e,n,s,r)}function ZP(t,e){return Vh(8390656,8,t,e)}function X0(t,e){return og(2048,8,t,e)}function kk(t,e){return og(4,2,t,e)}function Tk(t,e){return og(4,4,t,e)}function Mk(t,e){if(typeof e=="function")return t=t(),e(t),function(){e(null)};if(e!=null)return t=t(),e.current=t,function(){e.current=null}}function Ak(t,e,n){return n=n!=null?n.concat([t]):null,og(4,4,Mk.bind(null,e,t),n)}function q0(){}function jk(t,e){var n=Lr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&G0(e,r[1])?r[0]:(n.memoizedState=[t,e],t)}function Ok(t,e){var n=Lr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&G0(e,r[1])?r[0]:(t=t(),n.memoizedState=[t,e],t)}function Dk(t,e,n){return ea&21?(ro(n,e)||(n=N2(),ft.lanes|=n,ta|=n,t.baseState=!0),e):(t.baseState&&(t.baseState=!1,Un=!0),t.memoizedState=n)}function Cz(t,e){var n=Be;Be=n!==0&&4>n?n:4,t(!0);var r=Qm.transition;Qm.transition={};try{t(!1),e()}finally{Be=n,Qm.transition=r}}function Rk(){return Lr().memoizedState}function _z(t,e,n){var r=oi(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Lk(t))$k(e,n);else if(n=yk(t,e,n,r),n!==null){var o=bn();Jr(n,t,r,o),Fk(n,e,r)}}function Iz(t,e,n){var r=oi(t),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Lk(t))$k(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,ro(a,i)){var l=e.interleaved;l===null?(o.next=o,B0(e)):(o.next=l.next,l.next=o),e.interleaved=o;return}}catch{}finally{}n=yk(t,e,o,r),n!==null&&(o=bn(),Jr(n,t,r,o),Fk(n,e,r))}}function Lk(t){var e=t.alternate;return t===ft||e!==null&&e===ft}function $k(t,e){nu=Qp=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function Fk(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,E0(t,n)}}var Jp={readContext:Rr,useCallback:tn,useContext:tn,useEffect:tn,useImperativeHandle:tn,useInsertionEffect:tn,useLayoutEffect:tn,useMemo:tn,useReducer:tn,useRef:tn,useState:tn,useDebugValue:tn,useDeferredValue:tn,useTransition:tn,useMutableSource:tn,useSyncExternalStore:tn,useId:tn,unstable_isNewReconciler:!1},Ez={readContext:Rr,useCallback:function(t,e){return vo().memoizedState=[t,e===void 0?null:e],t},useContext:Rr,useEffect:ZP,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,Vh(4194308,4,Mk.bind(null,e,t),n)},useLayoutEffect:function(t,e){return Vh(4194308,4,t,e)},useInsertionEffect:function(t,e){return Vh(4,2,t,e)},useMemo:function(t,e){var n=vo();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=vo();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=_z.bind(null,ft,t),[r.memoizedState,t]},useRef:function(t){var e=vo();return t={current:t},e.memoizedState=t},useState:qP,useDebugValue:q0,useDeferredValue:function(t){return vo().memoizedState=t},useTransition:function(){var t=qP(!1),e=t[0];return t=Cz.bind(null,t[1]),vo().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=ft,o=vo();if(at){if(n===void 0)throw Error(X(407));n=n()}else{if(n=e(),Rt===null)throw Error(X(349));ea&30||bk(r,e,n)}o.memoizedState=n;var s={value:n,getSnapshot:e};return o.queue=s,ZP(Ck.bind(null,r,s,t),[t]),r.flags|=2048,Mu(9,Pk.bind(null,r,s,n,e),void 0,null),n},useId:function(){var t=vo(),e=Rt.identifierPrefix;if(at){var n=ss,r=os;n=(r&~(1<<32-Qr(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=ku++,0<n&&(e+="H"+n.toString(32)),e+=":"}else n=Pz++,e=":"+e+"r"+n.toString(32)+":";return t.memoizedState=e},unstable_isNewReconciler:!1},kz={readContext:Rr,useCallback:jk,useContext:Rr,useEffect:X0,useImperativeHandle:Ak,useInsertionEffect:kk,useLayoutEffect:Tk,useMemo:Ok,useReducer:Jm,useRef:Ek,useState:function(){return Jm(Tu)},useDebugValue:q0,useDeferredValue:function(t){var e=Lr();return Dk(e,kt.memoizedState,t)},useTransition:function(){var t=Jm(Tu)[0],e=Lr().memoizedState;return[t,e]},useMutableSource:xk,useSyncExternalStore:wk,useId:Rk,unstable_isNewReconciler:!1},Tz={readContext:Rr,useCallback:jk,useContext:Rr,useEffect:X0,useImperativeHandle:Ak,useInsertionEffect:kk,useLayoutEffect:Tk,useMemo:Ok,useReducer:ey,useRef:Ek,useState:function(){return ey(Tu)},useDebugValue:q0,useDeferredValue:function(t){var e=Lr();return kt===null?e.memoizedState=t:Dk(e,kt.memoizedState,t)},useTransition:function(){var t=ey(Tu)[0],e=Lr().memoizedState;return[t,e]},useMutableSource:xk,useSyncExternalStore:wk,useId:Rk,unstable_isNewReconciler:!1};function Hr(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 _v(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)?ya(t)===t:!1},enqueueSetState:function(t,e,n){t=t._reactInternals;var r=bn(),o=oi(t),s=ls(r,o);s.payload=e,n!=null&&(s.callback=n),e=ni(t,s,o),e!==null&&(Jr(e,t,o,r),Wh(e,t,o))},enqueueReplaceState:function(t,e,n){t=t._reactInternals;var r=bn(),o=oi(t),s=ls(r,o);s.tag=1,s.payload=e,n!=null&&(s.callback=n),e=ni(t,s,o),e!==null&&(Jr(e,t,o,r),Wh(e,t,o))},enqueueForceUpdate:function(t,e){t=t._reactInternals;var n=bn(),r=oi(t),o=ls(n,r);o.tag=2,e!=null&&(o.callback=e),e=ni(t,o,r),e!==null&&(Jr(e,t,r,n),Wh(e,t,r))}};function QP(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?!bu(n,r)||!bu(o,s):!0}function Nk(t,e,n){var r=!1,o=di,s=e.contextType;return typeof s=="object"&&s!==null?s=Rr(s):(o=Yn(e)?Qi:fn.current,r=e.contextTypes,s=(r=r!=null)?Cl(t,o):di),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 JP(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 Iv(t,e,n,r){var o=t.stateNode;o.props=n,o.state=t.memoizedState,o.refs={},U0(t);var s=e.contextType;typeof s=="object"&&s!==null?o.context=Rr(s):(s=Yn(e)?Qi:fn.current,o.context=Cl(t,s)),o.state=t.memoizedState,s=e.getDerivedStateFromProps,typeof s=="function"&&(_v(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),qp(t,n,o,r),o.state=t.memoizedState),typeof o.componentDidMount=="function"&&(t.flags|=4194308)}function kl(t,e){try{var n="",r=e;do n+=r6(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 ty(t,e,n){return{value:t,source:null,stack:n??null,digest:e??null}}function Ev(t,e){try{console.error(e.value)}catch(n){setTimeout(function(){throw n})}}var Mz=typeof WeakMap=="function"?WeakMap:Map;function zk(t,e,n){n=ls(-1,n),n.tag=3,n.payload={element:null};var r=e.value;return n.callback=function(){tf||(tf=!0,$v=r),Ev(t,e)},n}function Bk(t,e,n){n=ls(-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(){Ev(t,e)}}var s=t.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(n.callback=function(){Ev(t,e),typeof r!="function"&&(ri===null?ri=new Set([this]):ri.add(this));var i=e.stack;this.componentDidCatch(e.value,{componentStack:i!==null?i:""})}),n}function eC(t,e,n){var r=t.pingCache;if(r===null){r=t.pingCache=new Mz;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=Kz.bind(null,t,e,n),e.then(t,t))}function tC(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 nC(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=ls(-1,1),e.tag=2,ni(n,e,1))),n.lanes|=1),t)}var Az=Ps.ReactCurrentOwner,Un=!1;function vn(t,e,n,r){e.child=t===null?mk(e,null,n,r):Il(e,t.child,n,r)}function rC(t,e,n,r,o){n=n.render;var s=e.ref;return fl(e,o),r=V0(t,e,n,r,s,o),n=Y0(),t!==null&&!Un?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,Ss(t,e,o)):(at&&n&&R0(e),e.flags|=1,vn(t,e,r,o),e.child)}function oC(t,e,n,r,o){if(t===null){var s=n.type;return typeof s=="function"&&!ow(s)&&s.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(e.tag=15,e.type=s,Uk(t,e,s,r,o)):(t=Zh(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:bu,n(i,r)&&t.ref===e.ref)return Ss(t,e,o)}return e.flags|=1,t=si(s,r),t.ref=e.ref,t.return=e,e.child=t}function Uk(t,e,n,r,o){if(t!==null){var s=t.memoizedProps;if(bu(s,r)&&t.ref===e.ref)if(Un=!1,e.pendingProps=r=s,(t.lanes&o)!==0)t.flags&131072&&(Un=!0);else return e.lanes=t.lanes,Ss(t,e,o)}return kv(t,e,n,r,o)}function Hk(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(Ja,sr),sr|=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(Ja,sr),sr|=t,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:n,qe(Ja,sr),sr|=r}else s!==null?(r=s.baseLanes|n,e.memoizedState=null):r=n,qe(Ja,sr),sr|=r;return vn(t,e,o,n),e.child}function Kk(t,e){var n=e.ref;(t===null&&n!==null||t!==null&&t.ref!==n)&&(e.flags|=512,e.flags|=2097152)}function kv(t,e,n,r,o){var s=Yn(n)?Qi:fn.current;return s=Cl(e,s),fl(e,o),n=V0(t,e,n,r,s,o),r=Y0(),t!==null&&!Un?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~o,Ss(t,e,o)):(at&&r&&R0(e),e.flags|=1,vn(t,e,n,o),e.child)}function sC(t,e,n,r,o){if(Yn(n)){var s=!0;Wp(e)}else s=!1;if(fl(e,o),e.stateNode===null)Yh(t,e),Nk(e,n,r),Iv(e,n,r,o),r=!0;else if(t===null){var i=e.stateNode,a=e.memoizedProps;i.props=a;var l=i.context,c=n.contextType;typeof c=="object"&&c!==null?c=Rr(c):(c=Yn(n)?Qi:fn.current,c=Cl(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)&&JP(e,i,r,c),Bs=!1;var p=e.memoizedState;i.state=p,qp(e,r,i,o),l=e.memoizedState,a!==r||p!==l||Vn.current||Bs?(typeof u=="function"&&(_v(e,n,u,r),l=e.memoizedState),(a=Bs||QP(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,Sk(t,e),a=e.memoizedProps,c=e.type===e.elementType?a:Hr(e.type,a),i.props=c,h=e.pendingProps,p=i.context,l=n.contextType,typeof l=="object"&&l!==null?l=Rr(l):(l=Yn(n)?Qi:fn.current,l=Cl(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)&&JP(e,i,r,l),Bs=!1,p=e.memoizedState,i.state=p,qp(e,r,i,o);var m=e.memoizedState;a!==h||p!==m||Vn.current||Bs?(typeof f=="function"&&(_v(e,n,f,r),m=e.memoizedState),(c=Bs||QP(e,n,c,r,p,m,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,m,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,m,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=m),i.props=r,i.state=m,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 Tv(t,e,n,r,s,o)}function Tv(t,e,n,r,o,s){Kk(t,e);var i=(e.flags&128)!==0;if(!r&&!i)return o&&KP(e,n,!1),Ss(t,e,s);r=e.stateNode,Az.current=e;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,t!==null&&i?(e.child=Il(e,t.child,null,s),e.child=Il(e,null,a,s)):vn(t,e,a,s),e.memoizedState=r.state,o&&KP(e,n,!0),e.child}function Wk(t){var e=t.stateNode;e.pendingContext?HP(t,e.pendingContext,e.pendingContext!==e.context):e.context&&HP(t,e.context,!1),H0(t,e.containerInfo)}function iC(t,e,n,r,o){return _l(),$0(o),e.flags|=256,vn(t,e,n,r),e.child}var Mv={dehydrated:null,treeContext:null,retryLane:0};function Av(t){return{baseLanes:t,cachePool:null,transitions:null}}function Gk(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 Pv(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=Yi(t,r,n,null),s.return=e,t.return=e,s.sibling=t,e.child=s,e.child.memoizedState=Av(n),e.memoizedState=Mv,t):Z0(e,i));if(o=t.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return jz(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=si(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=si(a,s):(s=Yi(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?Av(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=t.childLanes&~n,e.memoizedState=Mv,r}return s=t.child,t=s.sibling,r=si(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 Z0(t,e){return e=lg({mode:"visible",children:e},t.mode,0,null),e.return=t,t.child=e}function Xd(t,e,n,r){return r!==null&&$0(r),Il(e,t.child,null,n),t=Z0(e,e.pendingProps.children),t.flags|=2,e.memoizedState=null,t}function jz(t,e,n,r,o,s,i){if(n)return e.flags&256?(e.flags&=-257,r=ty(Error(X(422))),Xd(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=Yi(s,o,i,null),s.flags|=2,r.return=e,s.return=e,r.sibling=s,e.child=r,e.mode&1&&Il(e,t.child,null,i),e.child.memoizedState=Av(i),e.memoizedState=Mv,s);if(!(e.mode&1))return Xd(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=ty(s,r,void 0),Xd(t,e,i,r)}if(a=(i&t.childLanes)!==0,Un||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,ys(t,o),Jr(r,t,o,-1))}return rw(),r=ty(Error(X(421))),Xd(t,e,i,r)}return o.data==="$?"?(e.flags|=128,e.child=t.child,e=Wz.bind(null,t),o._reactRetry=e,null):(t=s.treeContext,ar=ti(o.nextSibling),cr=e,at=!0,Vr=null,t!==null&&(kr[Tr++]=os,kr[Tr++]=ss,kr[Tr++]=Ji,os=t.id,ss=t.overflow,Ji=e),e=Z0(e,r.children),e.flags|=4096,e)}function aC(t,e,n){t.lanes|=e;var r=t.alternate;r!==null&&(r.lanes|=e),Cv(t.return,e,n)}function ny(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 Vk(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&&aC(t,n,e);else if(t.tag===19)aC(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&&Zp(t)===null&&(o=n),n=n.sibling;n=o,n===null?(o=e.child,e.child=null):(o=n.sibling,n.sibling=null),ny(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&&Zp(t)===null){e.child=o;break}t=o.sibling,o.sibling=n,n=o,o=t}ny(e,!0,n,null,s);break;case"together":ny(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function Yh(t,e){!(e.mode&1)&&t!==null&&(t.alternate=null,e.alternate=null,e.flags|=2)}function Ss(t,e,n){if(t!==null&&(e.dependencies=t.dependencies),ta|=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=si(t,t.pendingProps),e.child=n,n.return=e;t.sibling!==null;)t=t.sibling,n=n.sibling=si(t,t.pendingProps),n.return=e;n.sibling=null}return e.child}function Oz(t,e,n){switch(e.tag){case 3:Wk(e),_l();break;case 5:vk(e);break;case 1:Yn(e.type)&&Wp(e);break;case 4:H0(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,o=e.memoizedProps.value;qe(Yp,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?Gk(t,e,n):(qe(dt,dt.current&1),t=Ss(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 Vk(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,Hk(t,e,n)}return Ss(t,e,n)}var Yk,jv,Xk,qk;Yk=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}};jv=function(){};Xk=function(t,e,n,r){var o=t.memoizedProps;if(o!==r){t=e.stateNode,Wi(To.current);var s=null;switch(n){case"input":o=ev(t,o),r=ev(t,r),s=[];break;case"select":o=gt({},o,{value:void 0}),r=gt({},r,{value:void 0}),s=[];break;case"textarea":o=rv(t,o),r=rv(t,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(t.onclick=Hp)}sv(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"&&(gu.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"&&(gu.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)}};qk=function(t,e,n,r){n!==r&&(e.flags|=4)};function yc(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 Dz(t,e,n){var r=e.pendingProps;switch(L0(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 Yn(e.type)&&Kp(),nn(e),null;case 3:return r=e.stateNode,El(),rt(Vn),rt(fn),W0(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(t===null||t.child===null)&&(Vd(e)?e.flags|=4:t===null||t.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,Vr!==null&&(zv(Vr),Vr=null))),jv(t,e),nn(e),null;case 5:K0(e);var o=Wi(Eu.current);if(n=e.type,t!==null&&e.stateNode!=null)Xk(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=Wi(To.current),Vd(e)){r=e.stateNode,n=e.type;var s=e.memoizedProps;switch(r[wo]=e,r[_u]=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<zc.length;o++)tt(zc[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":mP(r,s),tt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},tt("invalid",r);break;case"textarea":SP(r,s),tt("invalid",r)}sv(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&&Gd(r.textContent,a,t),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Gd(r.textContent,a,t),o=["children",""+a]):gu.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&tt("scroll",r)}switch(n){case"input":Fd(r),yP(r,s,!0);break;case"textarea":Fd(r),vP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Hp)}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=C2(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[wo]=e,t[_u]=r,Yk(t,e,!1,!1),e.stateNode=t;e:{switch(i=iv(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<zc.length;o++)tt(zc[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":mP(t,r),o=ev(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":SP(t,r),o=rv(t,r),tt("invalid",t);break;default:o=r}sv(n,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?E2(t,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&_2(t,l)):s==="children"?typeof l=="string"?(n!=="textarea"||l!=="")&&mu(t,l):typeof l=="number"&&mu(t,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(gu.hasOwnProperty(s)?l!=null&&s==="onScroll"&&tt("scroll",t):l!=null&&w0(t,s,l,i))}switch(n){case"input":Fd(t),yP(t,r,!1);break;case"textarea":Fd(t),vP(t);break;case"option":r.value!=null&&t.setAttribute("value",""+ui(r.value));break;case"select":t.multiple=!!r.multiple,s=r.value,s!=null?ul(t,!!r.multiple,s,!1):r.defaultValue!=null&&ul(t,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(t.onclick=Hp)}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)qk(t,e,t.memoizedProps,r);else{if(typeof r!="string"&&e.stateNode===null)throw Error(X(166));if(n=Wi(Eu.current),Wi(To.current),Vd(e)){if(r=e.stateNode,n=e.memoizedProps,r[wo]=e,(s=r.nodeValue!==n)&&(t=cr,t!==null))switch(t.tag){case 3:Gd(r.nodeValue,n,(t.mode&1)!==0);break;case 5:t.memoizedProps.suppressHydrationWarning!==!0&&Gd(r.nodeValue,n,(t.mode&1)!==0)}s&&(e.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[wo]=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))fk(),_l(),e.flags|=98560,s=!1;else if(s=Vd(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[wo]=e}else _l(),!(e.flags&128)&&(e.memoizedState=null),e.flags|=4;nn(e),s=!1}else Vr!==null&&(zv(Vr),Vr=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):rw())),e.updateQueue!==null&&(e.flags|=4),nn(e),null);case 4:return El(),jv(t,e),t===null&&Pu(e.stateNode.containerInfo),nn(e),null;case 10:return z0(e.type._context),nn(e),null;case 17:return Yn(e.type)&&Kp(),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)yc(s,!1);else{if(Tt!==0||t!==null&&t.flags&128)for(t=e.child;t!==null;){if(i=Zp(t),i!==null){for(e.flags|=128,yc(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()>Tl&&(e.flags|=128,r=!0,yc(s,!1),e.lanes=4194304)}else{if(!r)if(t=Zp(i),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),yc(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!at)return nn(e),null}else 2*wt()-s.renderingStartTime>Tl&&n!==1073741824&&(e.flags|=128,r=!0,yc(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 nw(),r=e.memoizedState!==null,t!==null&&t.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?sr&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 Rz(t,e){switch(L0(e),e.tag){case 1:return Yn(e.type)&&Kp(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return El(),rt(Vn),rt(fn),W0(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return K0(e),null;case 13:if(rt(dt),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(X(340));_l()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return rt(dt),null;case 4:return El(),null;case 10:return z0(e.type._context),null;case 22:case 23:return nw(),null;case 24:return null;default:return null}}var qd=!1,ln=!1,Lz=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 Ov(t,e,n){try{n()}catch(r){yt(t,e,r)}}var lC=!1;function $z(t,e){if(mv=zp,t=tk(),D0(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(yv={focusedElem:t,selectionRange:n},zp=!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 m=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(m!==null){var g=m.memoizedProps,v=m.memoizedState,S=e.stateNode,y=S.getSnapshotBeforeUpdate(e.elementType===e.type?g:Hr(e.type,g),v);S.__reactInternalSnapshotBeforeUpdate=y}break;case 3:var P=e.stateNode.containerInfo;P.nodeType===1?P.textContent="":P.nodeType===9&&P.documentElement&&P.removeChild(P.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(X(163))}}catch(b){yt(e,e.return,b)}if(t=e.sibling,t!==null){t.return=e.return,re=t;break}re=e.return}return m=lC,lC=!1,m}function ru(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&&Ov(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 Dv(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 Zk(t){var e=t.alternate;e!==null&&(t.alternate=null,Zk(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[wo],delete e[_u],delete e[xv],delete e[vz],delete e[xz])),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 Qk(t){return t.tag===5||t.tag===3||t.tag===4}function cC(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||Qk(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 Rv(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=Hp));else if(r!==4&&(t=t.child,t!==null))for(Rv(t,e,n),t=t.sibling;t!==null;)Rv(t,e,n),t=t.sibling}function Lv(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(Lv(t,e,n),t=t.sibling;t!==null;)Lv(t,e,n),t=t.sibling}var zt=null,Kr=!1;function Os(t,e,n){for(n=n.child;n!==null;)Jk(t,e,n),n=n.sibling}function Jk(t,e,n){if(ko&&typeof ko.onCommitFiberUnmount=="function")try{ko.onCommitFiberUnmount(Qf,n)}catch{}switch(n.tag){case 5:ln||Qa(n,e);case 6:var r=zt,o=Kr;zt=null,Os(t,e,n),zt=r,Kr=o,zt!==null&&(Kr?(t=zt,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):zt.removeChild(n.stateNode));break;case 18:zt!==null&&(Kr?(t=zt,n=n.stateNode,t.nodeType===8?Xm(t.parentNode,n):t.nodeType===1&&Xm(t,n),xu(t)):Xm(zt,n.stateNode));break;case 4:r=zt,o=Kr,zt=n.stateNode.containerInfo,Kr=!0,Os(t,e,n),zt=r,Kr=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)&&Ov(n,e,i),o=o.next}while(o!==r)}Os(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)}Os(t,e,n);break;case 21:Os(t,e,n);break;case 22:n.mode&1?(ln=(r=ln)||n.memoizedState!==null,Os(t,e,n),ln=r):Os(t,e,n);break;default:Os(t,e,n)}}function uC(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new Lz),e.forEach(function(r){var o=Gz.bind(null,t,r);n.has(r)||(n.add(r),r.then(o,o))})}}function Ur(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,Kr=!1;break e;case 3:zt=a.stateNode.containerInfo,Kr=!0;break e;case 4:zt=a.stateNode.containerInfo,Kr=!0;break e}a=a.return}if(zt===null)throw Error(X(160));Jk(s,i,o),zt=null,Kr=!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;)eT(e,t),e=e.sibling}function eT(t,e){var n=t.alternate,r=t.flags;switch(t.tag){case 0:case 11:case 14:case 15:if(Ur(e,t),go(t),r&4){try{ru(3,t,t.return),ig(3,t)}catch(g){yt(t,t.return,g)}try{ru(5,t,t.return)}catch(g){yt(t,t.return,g)}}break;case 1:Ur(e,t),go(t),r&512&&n!==null&&Qa(n,n.return);break;case 5:if(Ur(e,t),go(t),r&512&&n!==null&&Qa(n,n.return),t.flags&32){var o=t.stateNode;try{mu(o,"")}catch(g){yt(t,t.return,g)}}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&&b2(o,s),iv(a,i);var c=iv(a,s);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?E2(o,h):u==="dangerouslySetInnerHTML"?_2(o,h):u==="children"?mu(o,h):w0(o,u,h,c)}switch(a){case"input":tv(o,s);break;case"textarea":P2(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?ul(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?ul(o,!!s.multiple,s.defaultValue,!0):ul(o,!!s.multiple,s.multiple?[]:"",!1))}o[_u]=s}catch(g){yt(t,t.return,g)}}break;case 6:if(Ur(e,t),go(t),r&4){if(t.stateNode===null)throw Error(X(162));o=t.stateNode,s=t.memoizedProps;try{o.nodeValue=s}catch(g){yt(t,t.return,g)}}break;case 3:if(Ur(e,t),go(t),r&4&&n!==null&&n.memoizedState.isDehydrated)try{xu(e.containerInfo)}catch(g){yt(t,t.return,g)}break;case 4:Ur(e,t),go(t);break;case 13:Ur(e,t),go(t),o=t.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(ew=wt())),r&4&&uC(t);break;case 22:if(u=n!==null&&n.memoizedState!==null,t.mode&1?(ln=(c=ln)||u,Ur(e,t),ln=c):Ur(e,t),go(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:ru(4,p,p.return);break;case 1:Qa(p,p.return);var m=p.stateNode;if(typeof m.componentWillUnmount=="function"){r=p,n=p.return;try{e=r,m.props=e.memoizedProps,m.state=e.memoizedState,m.componentWillUnmount()}catch(g){yt(r,n,g)}}break;case 5:Qa(p,p.return);break;case 22:if(p.memoizedState!==null){hC(h);continue}}f!==null?(f.return=p,re=f):hC(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=I2("display",i))}catch(g){yt(t,t.return,g)}}}else if(h.tag===6){if(u===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(g){yt(t,t.return,g)}}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:Ur(e,t),go(t),r&4&&uC(t);break;case 21:break;default:Ur(e,t),go(t)}}function go(t){var e=t.flags;if(e&2){try{e:{for(var n=t.return;n!==null;){if(Qk(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&&(mu(o,""),r.flags&=-33);var s=cC(t);Lv(t,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=cC(t);Rv(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 Fz(t,e,n){re=t,tT(t)}function tT(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||qd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||ln;a=qd;var c=ln;if(qd=i,(ln=l)&&!c)for(re=o;re!==null;)i=re,l=i.child,i.tag===22&&i.memoizedState!==null?pC(o):l!==null?(l.return=i,re=l):pC(o);for(;s!==null;)re=s,tT(s),s=s.sibling;re=o,qd=a,ln=c}dC(t)}else o.subtreeFlags&8772&&s!==null?(s.return=o,re=s):dC(t)}}function dC(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:Hr(e.type,n.memoizedProps);r.componentDidUpdate(o,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=e.updateQueue;s!==null&&XP(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}XP(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&&xu(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(X(163))}ln||e.flags&512&&Dv(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 hC(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 pC(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{Dv(e)}catch(l){yt(e,s,l)}break;case 5:var i=e.return;try{Dv(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 Nz=Math.ceil,ef=Ps.ReactCurrentDispatcher,Q0=Ps.ReactCurrentOwner,Or=Ps.ReactCurrentBatchConfig,Oe=0,Rt=null,It=null,Yt=0,sr=0,Ja=wi(0),Tt=0,Au=null,ta=0,ag=0,J0=0,ou=null,Fn=null,ew=0,Tl=1/0,es=null,tf=!1,$v=null,ri=null,Zd=!1,Ys=null,nf=0,su=0,Fv=null,Xh=-1,qh=0;function bn(){return Oe&6?wt():Xh!==-1?Xh:Xh=wt()}function oi(t){return t.mode&1?Oe&2&&Yt!==0?Yt&-Yt:bz.transition!==null?(qh===0&&(qh=N2()),qh):(t=Be,t!==0||(t=window.event,t=t===void 0?16:G2(t.type)),t):1}function Jr(t,e,n,r){if(50<su)throw su=0,Fv=null,Error(X(185));Qu(t,n,r),(!(Oe&2)||t!==Rt)&&(t===Rt&&(!(Oe&2)&&(ag|=n),Tt===4&&Hs(t,Yt)),Xn(t,r),n===1&&Oe===0&&!(e.mode&1)&&(Tl=wt()+500,rg&&bi()))}function Xn(t,e){var n=t.callbackNode;b6(t,e);var r=Np(t,t===Rt?Yt:0);if(r===0)n!==null&&bP(n),t.callbackNode=null,t.callbackPriority=0;else if(e=r&-r,t.callbackPriority!==e){if(n!=null&&bP(n),e===1)t.tag===0?wz(fC.bind(null,t)):dk(fC.bind(null,t)),yz(function(){!(Oe&6)&&bi()}),n=null;else{switch(z2(r)){case 1:n=I0;break;case 4:n=$2;break;case 16:n=Fp;break;case 536870912:n=F2;break;default:n=Fp}n=cT(n,nT.bind(null,t))}t.callbackPriority=e,t.callbackNode=n}}function nT(t,e){if(Xh=-1,qh=0,Oe&6)throw Error(X(327));var n=t.callbackNode;if(gl()&&t.callbackNode!==n)return null;var r=Np(t,t===Rt?Yt:0);if(r===0)return null;if(r&30||r&t.expiredLanes||e)e=rf(t,r);else{e=r;var o=Oe;Oe|=2;var s=oT();(Rt!==t||Yt!==e)&&(es=null,Tl=wt()+500,Vi(t,e));do try{Uz();break}catch(a){rT(t,a)}while(!0);N0(),ef.current=s,Oe=o,It!==null?e=0:(Rt=null,Yt=0,e=Tt)}if(e!==0){if(e===2&&(o=dv(t),o!==0&&(r=o,e=Nv(t,o))),e===1)throw n=Au,Vi(t,0),Hs(t,r),Xn(t,wt()),n;if(e===6)Hs(t,r);else{if(o=t.current.alternate,!(r&30)&&!zz(o)&&(e=rf(t,r),e===2&&(s=dv(t),s!==0&&(r=s,e=Nv(t,s))),e===1))throw n=Au,Vi(t,0),Hs(t,r),Xn(t,wt()),n;switch(t.finishedWork=o,t.finishedLanes=r,e){case 0:case 1:throw Error(X(345));case 2:zi(t,Fn,es);break;case 3:if(Hs(t,r),(r&130023424)===r&&(e=ew+500-wt(),10<e)){if(Np(t,0)!==0)break;if(o=t.suspendedLanes,(o&r)!==r){bn(),t.pingedLanes|=t.suspendedLanes&o;break}t.timeoutHandle=vv(zi.bind(null,t,Fn,es),e);break}zi(t,Fn,es);break;case 4:if(Hs(t,r),(r&4194240)===r)break;for(e=t.eventTimes,o=-1;0<r;){var i=31-Qr(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*Nz(r/1960))-r,10<r){t.timeoutHandle=vv(zi.bind(null,t,Fn,es),r);break}zi(t,Fn,es);break;case 5:zi(t,Fn,es);break;default:throw Error(X(329))}}}return Xn(t,wt()),t.callbackNode===n?nT.bind(null,t):null}function Nv(t,e){var n=ou;return t.current.memoizedState.isDehydrated&&(Vi(t,e).flags|=256),t=rf(t,e),t!==2&&(e=Fn,Fn=n,e!==null&&zv(e)),t}function zv(t){Fn===null?Fn=t:Fn.push.apply(Fn,t)}function zz(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(!ro(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 Hs(t,e){for(e&=~J0,e&=~ag,t.suspendedLanes|=e,t.pingedLanes&=~e,t=t.expirationTimes;0<e;){var n=31-Qr(e),r=1<<n;t[n]=-1,e&=~r}}function fC(t){if(Oe&6)throw Error(X(327));gl();var e=Np(t,0);if(!(e&1))return Xn(t,wt()),null;var n=rf(t,e);if(t.tag!==0&&n===2){var r=dv(t);r!==0&&(e=r,n=Nv(t,r))}if(n===1)throw n=Au,Vi(t,0),Hs(t,e),Xn(t,wt()),n;if(n===6)throw Error(X(345));return t.finishedWork=t.current.alternate,t.finishedLanes=e,zi(t,Fn,es),Xn(t,wt()),null}function tw(t,e){var n=Oe;Oe|=1;try{return t(e)}finally{Oe=n,Oe===0&&(Tl=wt()+500,rg&&bi())}}function na(t){Ys!==null&&Ys.tag===0&&!(Oe&6)&&gl();var e=Oe;Oe|=1;var n=Or.transition,r=Be;try{if(Or.transition=null,Be=1,t)return t()}finally{Be=r,Or.transition=n,Oe=e,!(Oe&6)&&bi()}}function nw(){sr=Ja.current,rt(Ja)}function Vi(t,e){t.finishedWork=null,t.finishedLanes=0;var n=t.timeoutHandle;if(n!==-1&&(t.timeoutHandle=-1,mz(n)),It!==null)for(n=It.return;n!==null;){var r=n;switch(L0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Kp();break;case 3:El(),rt(Vn),rt(fn),W0();break;case 5:K0(r);break;case 4:El();break;case 13:rt(dt);break;case 19:rt(dt);break;case 10:z0(r.type._context);break;case 22:case 23:nw()}n=n.return}if(Rt=t,It=t=si(t.current,null),Yt=sr=e,Tt=0,Au=null,J0=ag=ta=0,Fn=ou=null,Ki!==null){for(e=0;e<Ki.length;e++)if(n=Ki[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}Ki=null}return t}function rT(t,e){do{var n=It;try{if(N0(),Gh.current=Jp,Qp){for(var r=ft.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Qp=!1}if(ea=0,jt=kt=ft=null,nu=!1,ku=0,Q0.current=null,n===null||n.return===null){Tt=1,Au=e,It=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=tC(i);if(f!==null){f.flags&=-257,nC(f,i,a,s,e),f.mode&1&&eC(s,c,e),e=f,l=c;var m=e.updateQueue;if(m===null){var g=new Set;g.add(l),e.updateQueue=g}else m.add(l);break e}else{if(!(e&1)){eC(s,c,e),rw();break e}l=Error(X(426))}}else if(at&&a.mode&1){var v=tC(i);if(v!==null){!(v.flags&65536)&&(v.flags|=256),nC(v,i,a,s,e),$0(kl(l,a));break e}}s=l=kl(l,a),Tt!==4&&(Tt=2),ou===null?ou=[s]:ou.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,e&=-e,s.lanes|=e;var S=zk(s,l,e);YP(s,S);break e;case 1:a=l;var y=s.type,P=s.stateNode;if(!(s.flags&128)&&(typeof y.getDerivedStateFromError=="function"||P!==null&&typeof P.componentDidCatch=="function"&&(ri===null||!ri.has(P)))){s.flags|=65536,e&=-e,s.lanes|=e;var b=Bk(s,a,e);YP(s,b);break e}}s=s.return}while(s!==null)}iT(n)}catch(C){e=C,It===n&&n!==null&&(It=n=n.return);continue}break}while(!0)}function oT(){var t=ef.current;return ef.current=Jp,t===null?Jp:t}function rw(){(Tt===0||Tt===3||Tt===2)&&(Tt=4),Rt===null||!(ta&268435455)&&!(ag&268435455)||Hs(Rt,Yt)}function rf(t,e){var n=Oe;Oe|=2;var r=oT();(Rt!==t||Yt!==e)&&(es=null,Vi(t,e));do try{Bz();break}catch(o){rT(t,o)}while(!0);if(N0(),Oe=n,ef.current=r,It!==null)throw Error(X(261));return Rt=null,Yt=0,Tt}function Bz(){for(;It!==null;)sT(It)}function Uz(){for(;It!==null&&!p6();)sT(It)}function sT(t){var e=lT(t.alternate,t,sr);t.memoizedProps=t.pendingProps,e===null?iT(t):It=e,Q0.current=null}function iT(t){var e=t;do{var n=e.alternate;if(t=e.return,e.flags&32768){if(n=Rz(n,e),n!==null){n.flags&=32767,It=n;return}if(t!==null)t.flags|=32768,t.subtreeFlags=0,t.deletions=null;else{Tt=6,It=null;return}}else if(n=Dz(n,e,sr),n!==null){It=n;return}if(e=e.sibling,e!==null){It=e;return}It=e=t}while(e!==null);Tt===0&&(Tt=5)}function zi(t,e,n){var r=Be,o=Or.transition;try{Or.transition=null,Be=1,Hz(t,e,n,r)}finally{Or.transition=o,Be=r}return null}function Hz(t,e,n,r){do gl();while(Ys!==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(P6(t,s),t===Rt&&(It=Rt=null,Yt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||Zd||(Zd=!0,cT(Fp,function(){return gl(),null})),s=(n.flags&15990)!==0,n.subtreeFlags&15990||s){s=Or.transition,Or.transition=null;var i=Be;Be=1;var a=Oe;Oe|=4,Q0.current=null,$z(t,n),eT(n,t),cz(yv),zp=!!mv,yv=mv=null,t.current=n,Fz(n),f6(),Oe=a,Be=i,Or.transition=s}else t.current=n;if(Zd&&(Zd=!1,Ys=t,nf=o),s=t.pendingLanes,s===0&&(ri=null),y6(n.stateNode),Xn(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(tf)throw tf=!1,t=$v,$v=null,t;return nf&1&&t.tag!==0&&gl(),s=t.pendingLanes,s&1?t===Fv?su++:(su=0,Fv=t):su=0,bi(),null}function gl(){if(Ys!==null){var t=z2(nf),e=Or.transition,n=Be;try{if(Or.transition=null,Be=16>t?16:t,Ys===null)var r=!1;else{if(t=Ys,Ys=null,nf=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:ru(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(Zk(u),u===c){re=null;break}if(p!==null){p.return=f,re=p;break}re=f}}}var m=s.alternate;if(m!==null){var g=m.child;if(g!==null){m.child=null;do{var v=g.sibling;g.sibling=null,g=v}while(g!==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:ru(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 P=i.child;if(i.subtreeFlags&2064&&P!==null)P.return=i,re=P;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 b=a.sibling;if(b!==null){b.return=a.return,re=b;break e}re=a.return}}if(Oe=o,bi(),ko&&typeof ko.onPostCommitFiberRoot=="function")try{ko.onPostCommitFiberRoot(Qf,t)}catch{}r=!0}return r}finally{Be=n,Or.transition=e}}return!1}function gC(t,e,n){e=kl(n,e),e=zk(t,e,1),t=ni(t,e,1),e=bn(),t!==null&&(Qu(t,1,e),Xn(t,e))}function yt(t,e,n){if(t.tag===3)gC(t,t,n);else for(;e!==null;){if(e.tag===3){gC(e,t,n);break}else if(e.tag===1){var r=e.stateNode;if(typeof e.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(ri===null||!ri.has(r))){t=kl(n,t),t=Bk(e,t,1),e=ni(e,t,1),t=bn(),e!==null&&(Qu(e,1,t),Xn(e,t));break}}e=e.return}}function Kz(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()-ew?Vi(t,0):J0|=n),Xn(t,e)}function aT(t,e){e===0&&(t.mode&1?(e=Bd,Bd<<=1,!(Bd&130023424)&&(Bd=4194304)):e=1);var n=bn();t=ys(t,e),t!==null&&(Qu(t,e,n),Xn(t,n))}function Wz(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),aT(t,n)}function Gz(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),aT(t,n)}var lT;lT=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Vn.current)Un=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Un=!1,Oz(t,e,n);Un=!!(t.flags&131072)}else Un=!1,at&&e.flags&1048576&&hk(e,Vp,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;Yh(t,e),t=e.pendingProps;var o=Cl(e,fn.current);fl(e,n),o=V0(null,e,r,t,o,n);var s=Y0();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,Yn(r)?(s=!0,Wp(e)):s=!1,e.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,U0(e),o.updater=sg,e.stateNode=o,o._reactInternals=e,Iv(e,r,t,n),e=Tv(null,e,r,!0,s,n)):(e.tag=0,at&&s&&R0(e),vn(null,e,o,n),e=e.child),e;case 16:r=e.elementType;e:{switch(Yh(t,e),t=e.pendingProps,o=r._init,r=o(r._payload),e.type=r,o=e.tag=Yz(r),t=Hr(r,t),o){case 0:e=kv(null,e,r,t,n);break e;case 1:e=sC(null,e,r,t,n);break e;case 11:e=rC(null,e,r,t,n);break e;case 14:e=oC(null,e,r,Hr(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:Hr(r,o),kv(t,e,r,o,n);case 1:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Hr(r,o),sC(t,e,r,o,n);case 3:e:{if(Wk(e),t===null)throw Error(X(387));r=e.pendingProps,s=e.memoizedState,o=s.element,Sk(t,e),qp(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=kl(Error(X(423)),e),e=iC(t,e,r,n,o);break e}else if(r!==o){o=kl(Error(X(424)),e),e=iC(t,e,r,n,o);break e}else for(ar=ti(e.stateNode.containerInfo.firstChild),cr=e,at=!0,Vr=null,n=mk(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(_l(),r===o){e=Ss(t,e,n);break e}vn(t,e,r,n)}e=e.child}return e;case 5:return vk(e),t===null&&Pv(e),r=e.type,o=e.pendingProps,s=t!==null?t.memoizedProps:null,i=o.children,Sv(r,o)?i=null:s!==null&&Sv(r,s)&&(e.flags|=32),Kk(t,e),vn(t,e,i,n),e.child;case 6:return t===null&&Pv(e),null;case 13:return Gk(t,e,n);case 4:return H0(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=Il(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:Hr(r,o),rC(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(Yp,r._currentValue),r._currentValue=i,s!==null)if(ro(s.value,i)){if(s.children===o.children&&!Vn.current){e=Ss(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=ls(-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),Cv(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),Cv(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,fl(e,n),o=Rr(o),r=r(o),e.flags|=1,vn(t,e,r,n),e.child;case 14:return r=e.type,o=Hr(r,e.pendingProps),o=Hr(r.type,o),oC(t,e,r,o,n);case 15:return Uk(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,o=e.pendingProps,o=e.elementType===r?o:Hr(r,o),Yh(t,e),e.tag=1,Yn(r)?(t=!0,Wp(e)):t=!1,fl(e,n),Nk(e,r,o),Iv(e,r,o,n),Tv(null,e,r,!0,t,n);case 19:return Vk(t,e,n);case 22:return Hk(t,e,n)}throw Error(X(156,e.tag))};function cT(t,e){return L2(t,e)}function Vz(t,e,n,r){this.tag=t,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ar(t,e,n,r){return new Vz(t,e,n,r)}function ow(t){return t=t.prototype,!(!t||!t.isReactComponent)}function Yz(t){if(typeof t=="function")return ow(t)?1:0;if(t!=null){if(t=t.$$typeof,t===P0)return 11;if(t===C0)return 14}return 2}function si(t,e){var n=t.alternate;return n===null?(n=Ar(t.tag,e,t.key,t.mode),n.elementType=t.elementType,n.type=t.type,n.stateNode=t.stateNode,n.alternate=t,t.alternate=n):(n.pendingProps=e,n.type=t.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=t.flags&14680064,n.childLanes=t.childLanes,n.lanes=t.lanes,n.child=t.child,n.memoizedProps=t.memoizedProps,n.memoizedState=t.memoizedState,n.updateQueue=t.updateQueue,e=t.dependencies,n.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},n.sibling=t.sibling,n.index=t.index,n.ref=t.ref,n}function Zh(t,e,n,r,o,s){var i=2;if(r=t,typeof t=="function")ow(t)&&(i=1);else if(typeof t=="string")i=5;else e:switch(t){case Ha:return Yi(n.children,o,s,e);case b0:i=8,o|=8;break;case qS:return t=Ar(12,n,e,o|2),t.elementType=qS,t.lanes=s,t;case ZS:return t=Ar(13,n,e,o),t.elementType=ZS,t.lanes=s,t;case QS:return t=Ar(19,n,e,o),t.elementType=QS,t.lanes=s,t;case v2:return lg(n,o,s,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case y2:i=10;break e;case S2:i=9;break e;case P0:i=11;break e;case C0:i=14;break e;case zs:i=16,r=null;break e}throw Error(X(130,t==null?t:typeof t,""))}return e=Ar(i,n,e,o),e.elementType=t,e.type=r,e.lanes=s,e}function Yi(t,e,n,r){return t=Ar(7,t,r,e),t.lanes=n,t}function lg(t,e,n,r){return t=Ar(22,t,r,e),t.elementType=v2,t.lanes=n,t.stateNode={isHidden:!1},t}function ry(t,e,n){return t=Ar(6,t,null,e),t.lanes=n,t}function oy(t,e,n){return e=Ar(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function Xz(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=Fm(0),this.expirationTimes=Fm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Fm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function sw(t,e,n,r,o,s,i,a,l){return t=new Xz(t,e,n,a,l),e===1?(e=1,s===!0&&(e|=8)):e=0,s=Ar(3,null,null,e),t.current=s,s.stateNode=t,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},U0(s),t}function qz(t,e,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Ua,key:r==null?null:""+r,children:t,containerInfo:e,implementation:n}}function uT(t){if(!t)return di;t=t._reactInternals;e:{if(ya(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(Yn(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(Yn(n))return uk(t,n,e)}return e}function dT(t,e,n,r,o,s,i,a,l){return t=sw(n,r,!0,t,o,s,i,a,l),t.context=uT(null),n=t.current,r=bn(),o=oi(n),s=ls(r,o),s.callback=e??null,ni(n,s,o),t.current.lanes=o,Qu(t,o,r),Xn(t,r),t}function cg(t,e,n,r){var o=e.current,s=bn(),i=oi(o);return n=uT(n),e.context===null?e.context=n:e.pendingContext=n,e=ls(s,i),e.payload={element:t},r=r===void 0?null:r,r!==null&&(e.callback=r),t=ni(o,e,i),t!==null&&(Jr(t,o,i,s),Wh(t,o,i)),i}function of(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 mC(t,e){if(t=t.memoizedState,t!==null&&t.dehydrated!==null){var n=t.retryLane;t.retryLane=n!==0&&n<e?n:e}}function iw(t,e){mC(t,e),(t=t.alternate)&&mC(t,e)}function Zz(){return null}var hT=typeof reportError=="function"?reportError:function(t){console.error(t)};function aw(t){this._internalRoot=t}ug.prototype.render=aw.prototype.render=function(t){var e=this._internalRoot;if(e===null)throw Error(X(409));cg(t,e,null,null)};ug.prototype.unmount=aw.prototype.unmount=function(){var t=this._internalRoot;if(t!==null){this._internalRoot=null;var e=t.containerInfo;na(function(){cg(null,t,null,null)}),e[ms]=null}};function ug(t){this._internalRoot=t}ug.prototype.unstable_scheduleHydration=function(t){if(t){var e=H2();t={blockedOn:null,target:t,priority:e};for(var n=0;n<Us.length&&e!==0&&e<Us[n].priority;n++);Us.splice(n,0,t),n===0&&W2(t)}};function lw(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 yC(){}function Qz(t,e,n,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=of(i);s.call(c)}}var i=dT(e,r,t,0,null,!1,!1,"",yC);return t._reactRootContainer=i,t[ms]=i.current,Pu(t.nodeType===8?t.parentNode:t),na(),i}for(;o=t.lastChild;)t.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=of(l);a.call(c)}}var l=sw(t,0,!1,null,null,!1,!1,"",yC);return t._reactRootContainer=l,t[ms]=l.current,Pu(t.nodeType===8?t.parentNode:t),na(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=of(i);a.call(l)}}cg(e,i,t,o)}else i=Qz(n,e,t,o,r);return of(i)}B2=function(t){switch(t.tag){case 3:var e=t.stateNode;if(e.current.memoizedState.isDehydrated){var n=Nc(e.pendingLanes);n!==0&&(E0(e,n|1),Xn(e,wt()),!(Oe&6)&&(Tl=wt()+500,bi()))}break;case 13:na(function(){var r=ys(t,1);if(r!==null){var o=bn();Jr(r,t,1,o)}}),iw(t,1)}};k0=function(t){if(t.tag===13){var e=ys(t,134217728);if(e!==null){var n=bn();Jr(e,t,134217728,n)}iw(t,134217728)}};U2=function(t){if(t.tag===13){var e=oi(t),n=ys(t,e);if(n!==null){var r=bn();Jr(n,t,e,r)}iw(t,e)}};H2=function(){return Be};K2=function(t,e){var n=Be;try{return Be=t,e()}finally{Be=n}};lv=function(t,e,n){switch(e){case"input":if(tv(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));w2(r),tv(r,o)}}}break;case"textarea":P2(t,n);break;case"select":e=n.value,e!=null&&ul(t,!!n.multiple,e,!1)}};M2=tw;A2=na;var Jz={usingClientEntryPoint:!1,Events:[ed,Va,ng,k2,T2,tw]},Sc={findFiberByHostInstance:Hi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},e8={bundleType:Sc.bundleType,version:Sc.version,rendererPackageName:Sc.rendererPackageName,rendererConfig:Sc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Ps.ReactCurrentDispatcher,findHostInstanceByFiber:function(t){return t=D2(t),t===null?null:t.stateNode},findFiberByHostInstance:Sc.findFiberByHostInstance||Zz,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 Qd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Qd.isDisabled&&Qd.supportsFiber)try{Qf=Qd.inject(e8),ko=Qd}catch{}}Sr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Jz;Sr.createPortal=function(t,e){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!lw(e))throw Error(X(200));return qz(t,e,null,n)};Sr.createRoot=function(t,e){if(!lw(t))throw Error(X(299));var n=!1,r="",o=hT;return e!=null&&(e.unstable_strictMode===!0&&(n=!0),e.identifierPrefix!==void 0&&(r=e.identifierPrefix),e.onRecoverableError!==void 0&&(o=e.onRecoverableError)),e=sw(t,1,!1,null,null,n,!1,r,o),t[ms]=e.current,Pu(t.nodeType===8?t.parentNode:t),new aw(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=D2(e),t=t===null?null:t.stateNode,t};Sr.flushSync=function(t){return na(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(!lw(t))throw Error(X(405));var r=n!=null&&n.hydratedSources||null,o=!1,s="",i=hT;if(n!=null&&(n.unstable_strictMode===!0&&(o=!0),n.identifierPrefix!==void 0&&(s=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),e=dT(e,null,t,1,n??null,o,!1,s,i),t[ms]=e.current,Pu(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?(na(function(){hg(null,null,t,!1,function(){t._reactRootContainer=null,t[ms]=null})}),!0):!1};Sr.unstable_batchedUpdates=tw;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 pT(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(pT)}catch(t){console.error(t)}}pT(),p2.exports=Sr;var hi=p2.exports;const t8=vi(hi);var fT,SC=hi;fT=YS.createRoot=SC.createRoot,YS.hydrateRoot=SC.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 n8(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 sy="__TLDRAW_LIBRARY_VERSIONS__";function r8(){if(globalThis[sy])return globalThis[sy];const t={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,sy,{value:t,writable:!1,configurable:!1,enumerable:!1}),t}function Pi(t,e,n){if(!t||!e||!n)throw new Error("Missing name/version/module system in built version of tldraw library");const r=r8();if(r.versions.push({name:t,version:e,modules:n}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,vC(r)},100)}catch{vC(r)}}function vC(t){if(!t.versions.length||t.didWarn)return;const e=t.versions.sort((a,l)=>xC(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),iy(o,a.name,new Set).add(a.version);continue}a.version===n?r.add(a.name):(r.delete(a.name),iy(o,a.name,new Set).add(a.version))}if(o.size>0){const a=[`${Yo("[tldraw]",["bold","bgRed","textWhite"])} ${Yo("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 ${Yo(`v${n}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${Yo(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(xC).map(h=>Yo(`v${h}`,h===n?["textGreen"]:["textRed"]));return` • ❌ ${Yo(l,["bold"])} (${u.join(", ")})`})];console.log(a.join(`
|
|
41
|
-
`)),t.didWarn=!0;return}const s=new Map;for(const a of e)iy(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=[`${Yo("[tldraw]",["bold","bgRed","textWhite"])} ${Yo("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` • ❌ ${Yo(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 xC(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 o8={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function Yo(t,e=[]){return`\x1B[${e.map(n=>o8[n]).join(";")}m${t}\x1B[m`}function iy(t,e,n){return t.has(e)?t.get(e):(t.set(e,n),n)}var gT="Expected a function",wC=NaN,s8="[object Symbol]",i8=/^\s+|\s+$/g,a8=/^[-+]0x[0-9a-f]+$/i,l8=/^0b[01]+$/i,c8=/^0o[0-7]+$/i,u8=parseInt,d8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,h8=typeof self=="object"&&self&&self.Object===Object&&self,p8=d8||h8||Function("return this")(),f8=Object.prototype,g8=f8.toString,m8=Math.max,y8=Math.min,ay=function(){return p8.Date.now()};function S8(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(gT);e=bC(e)||0,sf(n)&&(u=!!n.leading,h="maxWait"in n,s=h?m8(bC(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 m(I){return c=I,a=setTimeout(S,e),u?f(I):i}function g(I){var k=I-l,_=I-c,M=e-k;return h?y8(M,s-_):M}function v(I){var k=I-l,_=I-c;return l===void 0||k>=e||k<0||h&&_>=s}function S(){var I=ay();if(v(I))return y(I);a=setTimeout(S,g(I))}function y(I){return a=void 0,p&&r?f(I):(r=o=void 0,i)}function P(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function b(){return a===void 0?i:y(ay())}function C(){var I=ay(),k=v(I);if(r=arguments,o=this,l=I,k){if(a===void 0)return m(l);if(h)return a=setTimeout(S,e),f(l)}return a===void 0&&(a=setTimeout(S,e)),i}return C.cancel=P,C.flush=b,C}function v8(t,e,n){var r=!0,o=!0;if(typeof t!="function")throw new TypeError(gT);return sf(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),S8(t,e,{leading:r,maxWait:e,trailing:o})}function sf(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function x8(t){return!!t&&typeof t=="object"}function w8(t){return typeof t=="symbol"||x8(t)&&g8.call(t)==s8}function bC(t){if(typeof t=="number")return t;if(w8(t))return wC;if(sf(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=sf(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=t.replace(i8,"");var n=l8.test(t);return n||c8.test(t)?u8(t.slice(2),n?2:8):a8.test(t)?wC:+t}var b8=v8;const mT=vi(b8);var P8=200,cw="__lodash_hash_undefined__",C8=1/0,_8="[object Function]",I8="[object GeneratorFunction]",E8=/[\\^$.*+?()[\]{}|]/g,k8=/^\[object .+?Constructor\]$/,T8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,M8=typeof self=="object"&&self&&self.Object===Object&&self,uw=T8||M8||Function("return this")();function A8(t,e){var n=t?t.length:0;return!!n&&O8(t,e,0)>-1}function j8(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 O8(t,e,n){if(e!==e)return j8(t,D8,n);for(var r=n-1,o=t.length;++r<o;)if(t[r]===e)return r;return-1}function D8(t){return t!==t}function R8(t,e){return t.has(e)}function L8(t,e){return t==null?void 0:t[e]}function $8(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function yT(t){var e=-1,n=Array(t.size);return t.forEach(function(r){n[++e]=r}),n}var F8=Array.prototype,N8=Function.prototype,ST=Object.prototype,ly=uw["__core-js_shared__"],PC=function(){var t=/[^.]+$/.exec(ly&&ly.keys&&ly.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),vT=N8.toString,dw=ST.hasOwnProperty,z8=ST.toString,B8=RegExp("^"+vT.call(dw).replace(E8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),U8=F8.splice,H8=hw(uw,"Map"),cy=hw(uw,"Set"),ju=hw(Object,"create");function ra(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 K8(){this.__data__=ju?ju(null):{}}function W8(t){return this.has(t)&&delete this.__data__[t]}function G8(t){var e=this.__data__;if(ju){var n=e[t];return n===cw?void 0:n}return dw.call(e,t)?e[t]:void 0}function V8(t){var e=this.__data__;return ju?e[t]!==void 0:dw.call(e,t)}function Y8(t,e){var n=this.__data__;return n[t]=ju&&e===void 0?cw:e,this}ra.prototype.clear=K8;ra.prototype.delete=W8;ra.prototype.get=G8;ra.prototype.has=V8;ra.prototype.set=Y8;function Ul(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 X8(){this.__data__=[]}function q8(t){var e=this.__data__,n=pg(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():U8.call(e,n,1),!0}function Z8(t){var e=this.__data__,n=pg(e,t);return n<0?void 0:e[n][1]}function Q8(t){return pg(this.__data__,t)>-1}function J8(t,e){var n=this.__data__,r=pg(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}Ul.prototype.clear=X8;Ul.prototype.delete=q8;Ul.prototype.get=Z8;Ul.prototype.has=Q8;Ul.prototype.set=J8;function Hl(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 e9(){this.__data__={hash:new ra,map:new(H8||Ul),string:new ra}}function t9(t){return fg(this,t).delete(t)}function n9(t){return fg(this,t).get(t)}function r9(t){return fg(this,t).has(t)}function o9(t,e){return fg(this,t).set(t,e),this}Hl.prototype.clear=e9;Hl.prototype.delete=t9;Hl.prototype.get=n9;Hl.prototype.has=r9;Hl.prototype.set=o9;function af(t){var e=-1,n=t?t.length:0;for(this.__data__=new Hl;++e<n;)this.add(t[e])}function s9(t){return this.__data__.set(t,cw),this}function i9(t){return this.__data__.has(t)}af.prototype.add=af.prototype.push=s9;af.prototype.has=i9;function pg(t,e){for(var n=t.length;n--;)if(f9(t[n][0],e))return n;return-1}function a9(t){if(!xT(t)||d9(t))return!1;var e=g9(t)||$8(t)?B8:k8;return e.test(h9(t))}function l9(t,e,n){var r=-1,o=A8,s=t.length,i=!0,a=[],l=a;if(s>=P8){var c=c9(t);if(c)return yT(c);i=!1,o=R8,l=new af}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 c9=cy&&1/yT(new cy([,-0]))[1]==C8?function(t){return new cy(t)}:m9;function fg(t,e){var n=t.__data__;return u9(e)?n[typeof e=="string"?"string":"hash"]:n.map}function hw(t,e){var n=L8(t,e);return a9(n)?n:void 0}function u9(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function d9(t){return!!PC&&PC in t}function h9(t){if(t!=null){try{return vT.call(t)}catch{}try{return t+""}catch{}}return""}function p9(t){return t&&t.length?l9(t):[]}function f9(t,e){return t===e||t!==t&&e!==e}function g9(t){var e=xT(t)?z8.call(t):"";return e==_8||e==I8}function xT(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function m9(){}var y9=p9;const S9=vi(y9),Bc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},v9=Bc.Good;class wT{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?Bc.Good:n>30?Bc.Mid:Bc.Poor,o=r===Bc.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${n}%c fps`,`color: white; background: ${v9};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 pw(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 x9(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 w9(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 bT(t){const e=(...n)=>{try{return t(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const Ou=()=>{},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=bT((t,e)=>{if(!t)throw new Error(e||"Assertion Error")}),Nn=bT((t,e)=>{if(t==null)throw new Error(e??"value must be defined");return t});function fw(){let t,e;const n=new Promise((r,o)=>{t=r,e=o});return Object.assign(n,{resolve:t,reject:e})}function Bv(t){return new Promise(e=>setTimeout(e,t))}function Hn(...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 Oo{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 gg(t,e){let n;const r=(...o)=>(n||(n={},n.promise=new Promise((s,i)=>{n.resolve=s,n.reject=i})),clearTimeout(n.timeout),n.latestArgs=o,n.timeout=setTimeout(()=>{const s=n;n=void 0;try{s.resolve(t(...s.latestArgs))}catch(i){s.reject(i)}},e),n.promise);return r.cancel=()=>{n&&clearTimeout(n.timeout)},r}const CC=new WeakMap;function gw(t,e){if(typeof t!="object"||t===null)return;let n=CC.get(t);n||(n={tags:{},extras:{}},CC.set(t,n)),e.tags&&(n.tags={...n.tags,...e.tags}),e.extras&&(n.extras={...n.extras,...e.extras})}async function oo(t,e){return window.fetch(t,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const Du=(t,e)=>{const n=new window.Image(t,e);return n.referrerPolicy="strict-origin-when-cross-origin",n};class cs{static async dataUrlToArrayBuffer(e){return oo(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 Uv(t){let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e+""}function _C(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 IC=globalThis.crypto,b9="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",P9=128;let Bi,el;function C9(t){!Bi||Bi.length<t?(Bi=new Uint8Array(t*P9),IC.getRandomValues(Bi),el=0):el+t>Bi.length&&(IC.getRandomValues(Bi),el=0),el+=t}function _9(t=21){C9(t-=0);let e="";for(let n=el-t;n<el;n++)e+=b9[Bi[n]&63];return e}let I9=_9;function ze(t){return I9(t)}/*!
|
|
54
|
-
* MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
|
|
55
|
-
* Copyright (c) Philip van Heemstra
|
|
56
|
-
*/function E9(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,m=0,g=0,v="";e:for(;m<s.length;){const S=m+c,y=s.subarray(m,S),P=h.decode(y,{stream:!0}),b=v+P;let C,I=-1;for(;(C=i.exec(b))!==null;){I=C.index-v.length,f=g+I;break e}m=S,g+=P.length;const k=I>-1?I+u:P.length-u;v=P.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 k9=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 EC(t,e){let n=0;for(;t[e+n];)n+=t[e+n]+1;return n+1}function T9(t){return new TextDecoder("ascii").decode(t.slice(0,3))==="GIF"}function M9(t){const e=new Uint8Array(t);let n,r,o=0,s=0;if(!T9(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+=EC(e,o+1)+1;break;case 33:o+=2,o+=EC(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 Hv=[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"&&(Hv=new Int32Array(Hv));const A9=(t,e)=>{let n=~~e^-1;for(let r=0;r<t.length;r++)n=Hv[(n^t[r])&255]^n>>>8;return n^-1},kC=4,TC=4;class bo{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(!bo.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=bo.getChunkType(e,n);if(i==="IDAT"&&r[i]){n+=s+kC+TC;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:n+4,size:s},n+=s+kC+TC}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 bo.readChunks(e)[n]}static setPhysChunk(e,n=1,r){let o=46,s=0;const i=bo.findChunk(e,"pHYs");i&&(o=i.start,s=i.size);const a=bo.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,A9(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 j9(t){return!t||t.length<12?!1:t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80}function O9(t){const e=new Uint8Array(t);return!j9(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const PT=Object.freeze(["image/svg+xml"]),CT=Object.freeze(["image/jpeg","image/png","image/webp"]),_T=Object.freeze(["image/gif","image/apng","image/avif"]),mg=Object.freeze([...CT,...PT,..._T]),mw=Object.freeze(["video/mp4","video/webm","video/quicktime"]),D9=[...mg,...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=fw();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=Du();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(bo.isPng(r,0)){const o=bo.findChunk(r,"pHYs");if(o){const s=bo.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"?M9(await e.arrayBuffer()):e.type==="image/avif"?k9(await e.arrayBuffer()):e.type==="image/webp"?O9(await e.arrayBuffer()):e.type==="image/apng"?E9(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return _T.includes(e||"")}static isStaticImageType(e){return CT.includes(e||"")}static isVectorImageType(e){return PT.includes(e||"")}static isImageType(e){return mg.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 lo(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 Ml(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 eo(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function Kn(t,e){if(eo(t,e))return t[e]}function MC(t){return Object.keys(t)}function ut(t){return Object.values(t)}function qn(t){return Object.entries(t)}function IT(t){return Object.fromEntries(t)}function iu(t,e){const n={};let r=!1;for(const[o,s]of qn(t))e(o,s)?n[o]=s:r=!0;return r?n:t}function nd(t,e){const n={};for(const[r,o]of qn(t)){const s=e(r,o);n[r]=s}return n}function ET(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 R9(t){const e=L9(t.chars),n=$9(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),o=F9(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 L9(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 $9(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 F9(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var uy=null;function yw(){return uy||(uy=R9({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Xs(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?Xs(n,e.firstPositive,e)+1+lf(t.slice(1),"positive",e):n===e.mostNegative?Xs(n,e.firstNegative,e)+1+lf(t.slice(1),"negative",e):n>=e.firstPositive?Xs(n,e.firstPositive,e)+2:Xs(n,e.firstNegative,e)+2}function lf(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"?Xs(r,n.mostNegative,n)+1+lf(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Xs(r,n.mostPositive,n)+1+lf(t.slice(1),e,n):e==="positive"?Xs(r,n.mostNegative,n)+2:Xs(r,n.mostPositive,n)+2}function yg(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 N9(t,e,n){let[r,o]=yg(t,e,"end",n.first),s=Kv(r,o,n);s===1&&(r=r.padEnd(r.length+1,n.first),s=n.length);const i=MT(Math.floor(s/2),n);return vw(r,i,n)}function Kv(t,e,n){const[r,o]=yg(t,e,"end",n.first).sort(),s=kT(o,r,n);return z9(s,n)}function vw(t,e,n){const r=n.length,[o,s]=yg(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 kT(t,e,n){const r=n.length,[o,s]=yg(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 TT(t,e){return vw(t,e.byCode[1],e)}function Wv(t,e){return kT(t,e.byCode[1],e)}function MT(t,e){if(t===0)return e.byCode[0];let n="";const r=e.length;for(;t>0;)n=e.byCode[t%r]+n,t=Math.floor(t/r);return n}function z9(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 B9(t){return t.firstPositive+t.byCode[0]}function U9(t,e){return Sw(t,e)===t.length}function AC(t,e){cf(t,e)}function cf(t,e){const n=OT(t,e),r=Sw(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function AT(t,e){if(!U9(t,e))throw new Error("invalid integer length: "+t)}function jT(t,e){AT(t,e);const[n,r]=DT(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=TT(r,e);return n+i}const s=K9(n,e);return RT(s,"lower",e)}function H9(t,e){AT(t,e);const[n,r]=DT(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Wv(r,e);return n+i}const s=W9(n,e);return RT(s,"upper",e)}function OT(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 DT(t,e){const n=OT(t,e),r=t.slice(n.length);return[n,r]}function K9(t,e){const n=t>=e.firstPositive,r=TT(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 W9(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 Wv(o,e)}return!n&&r?t+e.mostPositive:Wv(t,e)}function RT(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 LT(t,e){const n=MT(Math.floor(Math.random()*e.jitterRange),e);return vw(t,n,e)}function G9(t,e,n){const r=t.padEnd(t.length+e,n.first);return LT(r,n)}function V9(t,e,n){const r=cf(t,n),o=jT(r,n);let s=0;if(e!==null){const a=Kv(t,e,n);a<n.jitterRange+1&&(s=Math.max(s,jC(a,n)))}const i=Kv(t,o,n);return i<n.jitterRange+1&&(s=Math.max(s,jC(i,n))),s}function jC(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([o,s])=>s>n);return r?parseInt(r[0]):0}function Y9(t,e,n=yw()){if(t!==null&&AC(t,n),e!==null&&AC(e,n),t===null&&e===null)return B9(n);if(t===null){const r=cf(e,n);return H9(r,n)}if(e===null){const r=cf(t,n);return jT(r,n)}if(t>=e)throw new Error(t+" >= "+e);return N9(t,e,n)}function $T(t,e,n=yw()){const r=Y9(t,e,n),o=V9(r,e,n);return o?G9(r,o,n):LT(r,n)}function FT(t,e,n,r=yw()){return X9(t,e,n,r,$T,FT)}function X9(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 Kl=FT,NT="a0";function q9(t){try{$T(t,null)}catch{throw new Error("invalid index: "+t)}}function Al(t,e,n){return Kl(t??null,e??null,n)}function dy(t,e){return Kl(t??null,null,e)}function Ru(t,e){return Kl(t??null,e??null,1)[0]}function Co(t=null){return Kl(t,null,1)[0]}function Z9(t=null){return Kl(null,t,1)[0]}function Lu(t,e="a1"){return[e,...Kl(e,null,t)]}function cn(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function Q9(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 J9(){try{localStorage.clear()}catch{}}function zT(t){try{return sessionStorage.getItem(t)}catch{return null}}function bw(t,e){try{sessionStorage.setItem(t,e)}catch{}}function BT(t){try{sessionStorage.removeItem(t)}catch{}}function e7(){try{sessionStorage.clear()}catch{}}const t7=()=>typeof process<"u"&&!1,tl=[],n7=60,Qh=Math.ceil(1e3/n7);let vc,hy=0,Gv=0;const r7=()=>{const t=tl.splice(0,tl.length);for(const e of t)e()};function UT(){if(vc)return;const t=Date.now(),e=t-Gv;if(hy+e<Qh){vc=requestAnimationFrame(()=>{vc=void 0,UT()});return}vc=requestAnimationFrame(()=>{vc=void 0,Gv=t,hy=Math.min(hy+e-Qh,Qh*10),r7()})}let OC=!1;function HT(t){return t7()?(t(),()=>{}):(tl.includes(t)||(tl.push(t),OC||(OC=!0,Gv=Date.now()-Qh-1),UT()),()=>{const e=tl.indexOf(t);e>-1&&tl.splice(e,1)})}class o7{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 s7(t){return t!==void 0}function i7(){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 KT=i7(),nt=KT[0];KT[1];const a7=Object.getPrototypeOf(nt({}));Pi("@tldraw/utils","3.4.1","esm");var xc=function(t){return t&&t.Math===Math&&t},_n=xc(typeof globalThis=="object"&&globalThis)||xc(typeof window=="object"&&window)||xc(typeof self=="object"&&self)||xc(typeof dn=="object"&&dn)||xc(typeof dn=="object"&&dn)||function(){return this}()||Function("return this")(),Pw={},In=function(t){try{return!!t()}catch{return!0}},l7=In,Ci=!l7(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),c7=In,Sg=!c7(function(){var t=(function(){}).bind();return typeof t!="function"||t.hasOwnProperty("prototype")}),u7=Sg,Jd=Function.prototype.call,Cs=u7?Jd.bind(Jd):function(){return Jd.apply(Jd,arguments)},WT={},GT={}.propertyIsEnumerable,VT=Object.getOwnPropertyDescriptor,d7=VT&&!GT.call({1:2},1);WT.f=d7?function(e){var n=VT(this,e);return!!n&&n.enumerable}:GT;var YT=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}},XT=Sg,qT=Function.prototype,Vv=qT.call,h7=XT&&qT.bind.bind(Vv,Vv),Lt=XT?h7:function(t){return function(){return Vv.apply(t,arguments)}},ZT=Lt,p7=ZT({}.toString),f7=ZT("".slice),Wl=function(t){return f7(p7(t),8,-1)},g7=Lt,m7=In,y7=Wl,py=Object,S7=g7("".split),v7=m7(function(){return!py("z").propertyIsEnumerable(0)})?function(t){return y7(t)==="String"?S7(t,""):py(t)}:py,vg=function(t){return t==null},x7=vg,w7=TypeError,Gl=function(t){if(x7(t))throw new w7("Can't call method on "+t);return t},b7=v7,P7=Gl,xg=function(t){return b7(P7(t))},fy=typeof document=="object"&&document.all,En=typeof fy>"u"&&fy!==void 0?function(t){return typeof t=="function"||t===fy}:function(t){return typeof t=="function"},C7=En,Sa=function(t){return typeof t=="object"?t!==null:C7(t)},gy=_n,_7=En,I7=function(t){return _7(t)?t:void 0},wg=function(t,e){return arguments.length<2?I7(gy[t]):gy[t]&&gy[t][e]},E7=Lt,QT=E7({}.isPrototypeOf),k7=_n,DC=k7.navigator,RC=DC&&DC.userAgent,T7=RC?String(RC):"",JT=_n,my=T7,LC=JT.process,$C=JT.Deno,FC=LC&&LC.versions||$C&&$C.version,NC=FC&&FC.v8,Yr,uf;NC&&(Yr=NC.split("."),uf=Yr[0]>0&&Yr[0]<4?1:+(Yr[0]+Yr[1]));!uf&&my&&(Yr=my.match(/Edge\/(\d+)/),(!Yr||Yr[1]>=74)&&(Yr=my.match(/Chrome\/(\d+)/),Yr&&(uf=+Yr[1])));var M7=uf,zC=M7,A7=In,j7=_n,O7=j7.String,eM=!!Object.getOwnPropertySymbols&&!A7(function(){var t=Symbol("symbol detection");return!O7(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&zC&&zC<41}),D7=eM,tM=D7&&!Symbol.sham&&typeof Symbol.iterator=="symbol",R7=wg,L7=En,$7=QT,F7=tM,N7=Object,nM=F7?function(t){return typeof t=="symbol"}:function(t){var e=R7("Symbol");return L7(e)&&$7(e.prototype,N7(t))},z7=String,B7=function(t){try{return z7(t)}catch{return"Object"}},U7=En,H7=B7,K7=TypeError,Cw=function(t){if(U7(t))return t;throw new K7(H7(t)+" is not a function")},W7=Cw,G7=vg,_w=function(t,e){var n=t[e];return G7(n)?void 0:W7(n)},yy=Cs,Sy=En,vy=Sa,V7=TypeError,Y7=function(t,e){var n,r;if(e==="string"&&Sy(n=t.toString)&&!vy(r=yy(n,t))||Sy(n=t.valueOf)&&!vy(r=yy(n,t))||e!=="string"&&Sy(n=t.toString)&&!vy(r=yy(n,t)))return r;throw new V7("Can't convert object to primitive value")},rM={exports:{}},BC=_n,X7=Object.defineProperty,Iw=function(t,e){try{X7(BC,t,{value:e,configurable:!0,writable:!0})}catch{BC[t]=e}return e},q7=_n,Z7=Iw,UC="__core-js_shared__",HC=rM.exports=q7[UC]||Z7(UC,{});(HC.versions||(HC.versions=[])).push({version:"3.39.0",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.39.0/LICENSE",source:"https://github.com/zloirock/core-js"});var Ew=rM.exports,KC=Ew,kw=function(t,e){return KC[t]||(KC[t]=e||{})},Q7=Gl,J7=Object,rd=function(t){return J7(Q7(t))},eB=Lt,tB=rd,nB=eB({}.hasOwnProperty),_i=Object.hasOwn||function(e,n){return nB(tB(e),n)},rB=Lt,oB=0,sB=Math.random(),iB=rB(1 .toString),oM=function(t){return"Symbol("+(t===void 0?"":t)+")_"+iB(++oB+sB,36)},aB=_n,lB=kw,WC=_i,cB=oM,uB=eM,dB=tM,nl=aB.Symbol,xy=lB("wks"),hB=dB?nl.for||nl:nl&&nl.withoutSetter||cB,_s=function(t){return WC(xy,t)||(xy[t]=uB&&WC(nl,t)?nl[t]:hB("Symbol."+t)),xy[t]},pB=Cs,GC=Sa,VC=nM,fB=_w,gB=Y7,mB=_s,yB=TypeError,SB=mB("toPrimitive"),vB=function(t,e){if(!GC(t)||VC(t))return t;var n=fB(t,SB),r;if(n){if(e===void 0&&(e="default"),r=pB(n,t,e),!GC(r)||VC(r))return r;throw new yB("Can't convert object to primitive value")}return e===void 0&&(e="number"),gB(t,e)},xB=vB,wB=nM,sM=function(t){var e=xB(t,"string");return wB(e)?e:e+""},bB=_n,YC=Sa,Yv=bB.document,PB=YC(Yv)&&YC(Yv.createElement),iM=function(t){return PB?Yv.createElement(t):{}},CB=Ci,_B=In,IB=iM,aM=!CB&&!_B(function(){return Object.defineProperty(IB("div"),"a",{get:function(){return 7}}).a!==7}),EB=Ci,kB=Cs,TB=WT,MB=YT,AB=xg,jB=sM,OB=_i,DB=aM,XC=Object.getOwnPropertyDescriptor;Pw.f=EB?XC:function(e,n){if(e=AB(e),n=jB(n),DB)try{return XC(e,n)}catch{}if(OB(e,n))return MB(!kB(TB.f,e,n),e[n])};var Vl={},RB=Ci,LB=In,lM=RB&&LB(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),$B=Sa,FB=String,NB=TypeError,va=function(t){if($B(t))return t;throw new NB(FB(t)+" is not an object")},zB=Ci,BB=aM,UB=lM,eh=va,qC=sM,HB=TypeError,wy=Object.defineProperty,KB=Object.getOwnPropertyDescriptor,by="enumerable",Py="configurable",Cy="writable";Vl.f=zB?UB?function(e,n,r){if(eh(e),n=qC(n),eh(r),typeof e=="function"&&n==="prototype"&&"value"in r&&Cy in r&&!r[Cy]){var o=KB(e,n);o&&o[Cy]&&(e[n]=r.value,r={configurable:Py in r?r[Py]:o[Py],enumerable:by in r?r[by]:o[by],writable:!1})}return wy(e,n,r)}:wy:function(e,n,r){if(eh(e),n=qC(n),eh(r),BB)try{return wy(e,n,r)}catch{}if("get"in r||"set"in r)throw new HB("Accessors not supported");return"value"in r&&(e[n]=r.value),e};var WB=Ci,GB=Vl,VB=YT,Tw=WB?function(t,e,n){return GB.f(t,e,VB(1,n))}:function(t,e,n){return t[e]=n,t},cM={exports:{}},Xv=Ci,YB=_i,uM=Function.prototype,XB=Xv&&Object.getOwnPropertyDescriptor,Mw=YB(uM,"name"),qB=Mw&&(function(){}).name==="something",ZB=Mw&&(!Xv||Xv&&XB(uM,"name").configurable),QB={EXISTS:Mw,PROPER:qB,CONFIGURABLE:ZB},JB=Lt,eU=En,qv=Ew,tU=JB(Function.toString);eU(qv.inspectSource)||(qv.inspectSource=function(t){return tU(t)});var dM=qv.inspectSource,nU=_n,rU=En,ZC=nU.WeakMap,oU=rU(ZC)&&/native code/.test(String(ZC)),sU=kw,iU=oM,QC=sU("keys"),hM=function(t){return QC[t]||(QC[t]=iU(t))},Aw={},aU=oU,pM=_n,lU=Sa,cU=Tw,_y=_i,Iy=Ew,uU=hM,dU=Aw,JC="Object already initialized",Zv=pM.TypeError,hU=pM.WeakMap,df,$u,hf,pU=function(t){return hf(t)?$u(t):df(t,{})},fU=function(t){return function(e){var n;if(!lU(e)||(n=$u(e)).type!==t)throw new Zv("Incompatible receiver, "+t+" required");return n}};if(aU||Iy.state){var mo=Iy.state||(Iy.state=new hU);mo.get=mo.get,mo.has=mo.has,mo.set=mo.set,df=function(t,e){if(mo.has(t))throw new Zv(JC);return e.facade=t,mo.set(t,e),e},$u=function(t){return mo.get(t)||{}},hf=function(t){return mo.has(t)}}else{var ka=uU("state");dU[ka]=!0,df=function(t,e){if(_y(t,ka))throw new Zv(JC);return e.facade=t,cU(t,ka,e),e},$u=function(t){return _y(t,ka)?t[ka]:{}},hf=function(t){return _y(t,ka)}}var fM={set:df,get:$u,has:hf,enforce:pU,getterFor:fU},jw=Lt,gU=In,mU=En,th=_i,Qv=Ci,yU=QB.CONFIGURABLE,SU=dM,gM=fM,vU=gM.enforce,xU=gM.get,e_=String,Jh=Object.defineProperty,wU=jw("".slice),bU=jw("".replace),PU=jw([].join),CU=Qv&&!gU(function(){return Jh(function(){},"length",{value:8}).length!==8}),_U=String(String).split("String"),IU=cM.exports=function(t,e,n){wU(e_(e),0,7)==="Symbol("&&(e="["+bU(e_(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!th(t,"name")||yU&&t.name!==e)&&(Qv?Jh(t,"name",{value:e,configurable:!0}):t.name=e),CU&&n&&th(n,"arity")&&t.length!==n.arity&&Jh(t,"length",{value:n.arity});try{n&&th(n,"constructor")&&n.constructor?Qv&&Jh(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch{}var r=vU(t);return th(r,"source")||(r.source=PU(_U,typeof e=="string"?e:"")),t};Function.prototype.toString=IU(function(){return mU(this)&&xU(this).source||SU(this)},"toString");var EU=cM.exports,kU=En,TU=Vl,MU=EU,AU=Iw,mM=function(t,e,n,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:e;if(kU(n)&&MU(n,s,r),r.global)o?t[e]=n:AU(e,n);else{try{r.unsafe?t[e]&&(o=!0):delete t[e]}catch{}o?t[e]=n:TU.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},yM={},jU=Math.ceil,OU=Math.floor,DU=Math.trunc||function(e){var n=+e;return(n>0?OU:jU)(n)},RU=DU,xa=function(t){var e=+t;return e!==e||e===0?0:RU(e)},LU=xa,$U=Math.max,FU=Math.min,NU=function(t,e){var n=LU(t);return n<0?$U(n+e,0):FU(n,e)},zU=xa,BU=Math.min,SM=function(t){var e=zU(t);return e>0?BU(e,9007199254740991):0},UU=SM,od=function(t){return UU(t.length)},HU=xg,KU=NU,WU=od,t_=function(t){return function(e,n,r){var o=HU(e),s=WU(o);if(s===0)return!t&&-1;var i=KU(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}},GU={includes:t_(!0),indexOf:t_(!1)},VU=Lt,Ey=_i,YU=xg,XU=GU.indexOf,qU=Aw,n_=VU([].push),vM=function(t,e){var n=YU(t),r=0,o=[],s;for(s in n)!Ey(qU,s)&&Ey(n,s)&&n_(o,s);for(;e.length>r;)Ey(n,s=e[r++])&&(~XU(o,s)||n_(o,s));return o},Ow=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],ZU=vM,QU=Ow,JU=QU.concat("length","prototype");yM.f=Object.getOwnPropertyNames||function(e){return ZU(e,JU)};var xM={};xM.f=Object.getOwnPropertySymbols;var eH=wg,tH=Lt,nH=yM,rH=xM,oH=va,sH=tH([].concat),iH=eH("Reflect","ownKeys")||function(e){var n=nH.f(oH(e)),r=rH.f;return r?sH(n,r(e)):n},r_=_i,aH=iH,lH=Pw,cH=Vl,uH=function(t,e,n){for(var r=aH(e),o=cH.f,s=lH.f,i=0;i<r.length;i++){var a=r[i];!r_(t,a)&&!(n&&r_(n,a))&&o(t,a,s(e,a))}},dH=In,hH=En,pH=/#|\.prototype\./,sd=function(t,e){var n=gH[fH(t)];return n===yH?!0:n===mH?!1:hH(e)?dH(e):!!e},fH=sd.normalize=function(t){return String(t).replace(pH,".").toLowerCase()},gH=sd.data={},mH=sd.NATIVE="N",yH=sd.POLYFILL="P",SH=sd,nh=_n,vH=Pw.f,xH=Tw,wH=mM,bH=Iw,PH=uH,CH=SH,Yl=function(t,e){var n=t.target,r=t.global,o=t.stat,s,i,a,l,c,u;if(r?i=nh:o?i=nh[n]||bH(n,{}):i=nh[n]&&nh[n].prototype,i)for(a in e){if(c=e[a],t.dontCallGetSet?(u=vH(i,a),l=u&&u.value):l=i[a],s=CH(r?a:n+(o?".":"#")+a,t.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;PH(c,l)}(t.sham||l&&l.sham)&&xH(c,"sham",!0),wH(i,a,c,t)}},wM={},_H=vM,IH=Ow,EH=Object.keys||function(e){return _H(e,IH)},kH=Ci,TH=lM,MH=Vl,AH=va,jH=xg,OH=EH;wM.f=kH&&!TH?Object.defineProperties:function(e,n){AH(e);for(var r=jH(n),o=OH(n),s=o.length,i=0,a;s>i;)MH.f(e,a=o[i++],r[a]);return e};var DH=wg,RH=DH("document","documentElement"),LH=va,$H=wM,o_=Ow,FH=Aw,NH=RH,zH=iM,BH=hM,s_=">",i_="<",Jv="prototype",ex="script",bM=BH("IE_PROTO"),ky=function(){},PM=function(t){return i_+ex+s_+t+i_+"/"+ex+s_},a_=function(t){t.write(PM("")),t.close();var e=t.parentWindow.Object;return t=null,e},UH=function(){var t=zH("iframe"),e="java"+ex+":",n;return t.style.display="none",NH.appendChild(t),t.src=String(e),n=t.contentWindow.document,n.open(),n.write(PM("document.F=Object")),n.close(),n.F},rh,ep=function(){try{rh=new ActiveXObject("htmlfile")}catch{}ep=typeof document<"u"?document.domain&&rh?a_(rh):UH():a_(rh);for(var t=o_.length;t--;)delete ep[Jv][o_[t]];return ep()};FH[bM]=!0;var CM=Object.create||function(e,n){var r;return e!==null?(ky[Jv]=LH(e),r=new ky,ky[Jv]=null,r[bM]=e):r=ep(),n===void 0?r:$H.f(r,n)},HH=_s,KH=CM,WH=Vl.f,tx=HH("unscopables"),nx=Array.prototype;nx[tx]===void 0&&WH(nx,tx,{configurable:!0,value:KH(null)});var Dw=function(t){nx[tx][t]=!0},GH=Yl,VH=rd,YH=od,XH=xa,qH=Dw;GH({target:"Array",proto:!0},{at:function(e){var n=VH(this),r=YH(n),o=XH(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:n[s]}});qH("at");var ZH=_n,QH=Lt,id=function(t,e){return QH(ZH[t].prototype[e])},JH=id;JH("Array","at");var eK=Wl,_M=Array.isArray||function(e){return eK(e)==="Array"},tK=TypeError,nK=9007199254740991,rK=function(t){if(t>nK)throw tK("Maximum allowed index exceeded");return t},oK=Wl,sK=Lt,iK=function(t){if(oK(t)==="Function")return sK(t)},l_=iK,aK=Cw,lK=Sg,cK=l_(l_.bind),uK=function(t,e){return aK(t),e===void 0?t:lK?cK(t,e):function(){return t.apply(e,arguments)}},dK=_M,hK=od,pK=rK,fK=uK,IM=function(t,e,n,r,o,s,i,a){for(var l=o,c=0,u=i?fK(i,a):!1,h,p;c<r;)c in n&&(h=u?u(n[c],c,e):n[c],s>0&&dK(h)?(p=hK(h),l=IM(t,e,h,p,l,s-1)-1):(pK(l+1),t[l]=h),l++),c++;return l},EM=IM,gK=_s,mK=gK("toStringTag"),kM={};kM[mK]="z";var yK=String(kM)==="[object z]",SK=yK,vK=En,tp=Wl,xK=_s,wK=xK("toStringTag"),bK=Object,PK=tp(function(){return arguments}())==="Arguments",CK=function(t,e){try{return t[e]}catch{}},TM=SK?tp:function(t){var e,n,r;return t===void 0?"Undefined":t===null?"Null":typeof(n=CK(e=bK(t),wK))=="string"?n:PK?tp(e):(r=tp(e))==="Object"&&vK(e.callee)?"Arguments":r},_K=Lt,IK=In,MM=En,EK=TM,kK=wg,TK=dM,AM=function(){},jM=kK("Reflect","construct"),Rw=/^\s*(?:class|function)\b/,MK=_K(Rw.exec),AK=!Rw.test(AM),wc=function(e){if(!MM(e))return!1;try{return jM(AM,[],e),!0}catch{return!1}},OM=function(e){if(!MM(e))return!1;switch(EK(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return AK||!!MK(Rw,TK(e))}catch{return!0}};OM.sham=!0;var jK=!jM||IK(function(){var t;return wc(wc.call)||!wc(Object)||!wc(function(){t=!0})||t})?OM:wc,c_=_M,OK=jK,DK=Sa,RK=_s,LK=RK("species"),u_=Array,$K=function(t){var e;return c_(t)&&(e=t.constructor,OK(e)&&(e===u_||c_(e.prototype))?e=void 0:DK(e)&&(e=e[LK],e===null&&(e=void 0))),e===void 0?u_:e},FK=$K,DM=function(t,e){return new(FK(t))(e===0?0:e)},NK=Yl,zK=EM,BK=Cw,UK=rd,HK=od,KK=DM;NK({target:"Array",proto:!0},{flatMap:function(e){var n=UK(this),r=HK(n),o;return BK(e),o=KK(n,0),o.length=zK(o,n,n,r,0,1,e,arguments.length>1?arguments[1]:void 0),o}});var WK=Dw;WK("flatMap");var GK=id;GK("Array","flatMap");var VK=Yl,YK=EM,XK=rd,qK=od,ZK=xa,QK=DM;VK({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,n=XK(this),r=qK(n),o=QK(n,0);return o.length=YK(o,n,n,r,0,e===void 0?1:ZK(e)),o}});var JK=Dw;JK("flat");var eW=id;eW("Array","flat");var tW=TM,nW=String,ad=function(t){if(tW(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return nW(t)},rW=Yl,oW=Lt,sW=Gl,iW=xa,aW=ad,lW=In,cW=oW("".charAt),uW=lW(function(){return"𠮷".at(-2)!=="\uD842"});rW({target:"String",proto:!0,forced:uW},{at:function(e){var n=aW(sW(this)),r=n.length,o=iW(e),s=o>=0?o:r+o;return s<0||s>=r?void 0:cW(n,s)}});var dW=id;dW("String","at");var hW=va,RM=function(){var t=hW(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,pW=_n,$w=pW.RegExp,Fw=Lw(function(){var t=$w("a","y");return t.lastIndex=2,t.exec("abcd")!==null}),fW=Fw||Lw(function(){return!$w("a","y").sticky}),gW=Fw||Lw(function(){var t=$w("^r","gy");return t.lastIndex=2,t.exec("str")!==null}),mW={BROKEN_CARET:gW,MISSED_STICKY:fW,UNSUPPORTED_Y:Fw},yW=In,SW=_n,vW=SW.RegExp,xW=yW(function(){var t=vW(".","s");return!(t.dotAll&&t.test(`
|
|
68
|
-
`)&&t.flags==="s")}),wW=In,bW=_n,PW=bW.RegExp,CW=wW(function(){var t=PW("(?<a>b)","g");return t.exec("b").groups.a!=="b"||"b".replace(t,"$<a>c")!=="bc"}),rl=Cs,bg=Lt,_W=ad,IW=RM,EW=mW,kW=kw,TW=CM,MW=fM.get,AW=xW,jW=CW,OW=kW("native-string-replace",String.prototype.replace),pf=RegExp.prototype.exec,rx=pf,DW=bg("".charAt),RW=bg("".indexOf),LW=bg("".replace),Ty=bg("".slice),ox=function(){var t=/a/,e=/b*/g;return rl(pf,t,"a"),rl(pf,e,"a"),t.lastIndex!==0||e.lastIndex!==0}(),LM=EW.BROKEN_CARET,sx=/()??/.exec("")[1]!==void 0,$W=ox||sx||LM||AW||jW;$W&&(rx=function(e){var n=this,r=MW(n),o=_W(e),s=r.raw,i,a,l,c,u,h,p;if(s)return s.lastIndex=n.lastIndex,i=rl(rx,s,o),n.lastIndex=s.lastIndex,i;var f=r.groups,m=LM&&n.sticky,g=rl(IW,n),v=n.source,S=0,y=o;if(m&&(g=LW(g,"y",""),RW(g,"g")===-1&&(g+="g"),y=Ty(o,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&DW(o,n.lastIndex-1)!==`
|
|
69
|
-
`)&&(v="(?: "+v+")",y=" "+y,S++),a=new RegExp("^(?:"+v+")",g)),sx&&(a=new RegExp("^"+v+"$(?!\\s)",g)),ox&&(l=n.lastIndex),c=rl(pf,m?a:n,y),m?c?(c.input=Ty(c.input,S),c[0]=Ty(c[0],S),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:ox&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),sx&&c&&c.length>1&&rl(OW,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=TW(null),u=0;u<f.length;u++)p=f[u],h[p[0]]=c[p[1]];return c});var Nw=rx,FW=Yl,d_=Nw;FW({target:"RegExp",proto:!0,forced:/./.exec!==d_},{exec:d_});var NW=Sg,$M=Function.prototype,h_=$M.apply,p_=$M.call,zW=typeof Reflect=="object"&&Reflect.apply||(NW?p_.bind(h_):function(){return p_.apply(h_,arguments)}),f_=Cs,g_=mM,BW=Nw,m_=In,FM=_s,UW=Tw,HW=FM("species"),My=RegExp.prototype,KW=function(t,e,n,r){var o=FM(t),s=!m_(function(){var c={};return c[o]=function(){return 7},""[t](c)!==7}),i=s&&!m_(function(){var c=!1,u=/a/;return t==="split"&&(u={},u.constructor={},u.constructor[HW]=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 m=u.exec;return m===BW||m===My.exec?s&&!f?{done:!0,value:f_(a,u,h,p)}:{done:!0,value:f_(c,h,u,p)}:{done:!1}});g_(String.prototype,t,l[0]),g_(My,o,l[1])}r&&UW(My[o],"sham",!0)},zw=Lt,WW=xa,GW=ad,VW=Gl,YW=zw("".charAt),y_=zw("".charCodeAt),XW=zw("".slice),S_=function(t){return function(e,n){var r=GW(VW(e)),o=WW(n),s=r.length,i,a;return o<0||o>=s?t?"":void 0:(i=y_(r,o),i<55296||i>56319||o+1===s||(a=y_(r,o+1))<56320||a>57343?t?YW(r,o):i:t?XW(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},qW={codeAt:S_(!1),charAt:S_(!0)},ZW=qW.charAt,QW=function(t,e,n){return e+(n?ZW(t,e).length:1)},Bw=Lt,JW=rd,eG=Math.floor,Ay=Bw("".charAt),tG=Bw("".replace),jy=Bw("".slice),nG=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,rG=/\$([$&'`]|\d{1,2})/g,NM=function(t,e,n,r,o,s){var i=n+t.length,a=r.length,l=rG;return o!==void 0&&(o=JW(o),l=nG),tG(s,l,function(c,u){var h;switch(Ay(u,0)){case"$":return"$";case"&":return t;case"`":return jy(e,0,n);case"'":return jy(e,i);case"<":h=o[jy(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=eG(p/10);return f===0?c:f<=a?r[f-1]===void 0?Ay(u,1):r[f-1]+Ay(u,1):c}h=r[p-1]}return h===void 0?"":h})},v_=Cs,oG=va,sG=En,iG=Wl,aG=Nw,lG=TypeError,cG=function(t,e){var n=t.exec;if(sG(n)){var r=v_(n,t,e);return r!==null&&oG(r),r}if(iG(t)==="RegExp")return v_(aG,t,e);throw new lG("RegExp#exec called on incompatible receiver")},uG=zW,x_=Cs,Pg=Lt,dG=KW,hG=In,pG=va,fG=En,gG=vg,mG=xa,yG=SM,Ta=ad,SG=Gl,vG=QW,xG=_w,wG=NM,bG=cG,PG=_s,ix=PG("replace"),CG=Math.max,_G=Math.min,IG=Pg([].concat),Oy=Pg([].push),w_=Pg("".indexOf),b_=Pg("".slice),EG=function(t){return t===void 0?t:String(t)},kG=function(){return"a".replace(/./,"$0")==="$0"}(),P_=function(){return/./[ix]?/./[ix]("a","$0")==="":!1}(),TG=!hG(function(){var t=/./;return t.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(t,"$<a>")!=="7"});dG("replace",function(t,e,n){var r=P_?"$":"$0";return[function(s,i){var a=SG(this),l=gG(s)?void 0:xG(s,ix);return l?x_(l,s,a,i):x_(e,Ta(a),s,i)},function(o,s){var i=pG(this),a=Ta(o);if(typeof s=="string"&&w_(s,r)===-1&&w_(s,"$<")===-1){var l=n(e,i,a,s);if(l.done)return l.value}var c=fG(s);c||(s=Ta(s));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=bG(i,a),!(f===null||(Oy(p,f),!u));){var m=Ta(f[0]);m===""&&(i.lastIndex=vG(a,yG(i.lastIndex),h))}for(var g="",v=0,S=0;S<p.length;S++){f=p[S];for(var y=Ta(f[0]),P=CG(_G(mG(f.index),a.length),0),b=[],C,I=1;I<f.length;I++)Oy(b,EG(f[I]));var k=f.groups;if(c){var _=IG([y],b,P,a);k!==void 0&&Oy(_,k),C=Ta(uG(s,void 0,_))}else C=wG(y,a,P,b,k,s);P>=v&&(g+=b_(a,v,P)+C,v=P+y.length)}return g+b_(a,v)}]},!TG||!kG||P_);var MG=Sa,AG=Wl,jG=_s,OG=jG("match"),DG=function(t){var e;return MG(t)&&((e=t[OG])!==void 0?!!e:AG(t)==="RegExp")},RG=Cs,LG=_i,$G=QT,FG=RM,C_=RegExp.prototype,NG=function(t){var e=t.flags;return e===void 0&&!("flags"in C_)&&!LG(t,"flags")&&$G(C_,t)?RG(FG,t):e},zG=Yl,BG=Cs,Uw=Lt,__=Gl,UG=En,HG=vg,KG=DG,bc=ad,WG=_w,GG=NG,VG=NM,YG=_s,XG=YG("replace"),qG=TypeError,Dy=Uw("".indexOf);Uw("".replace);var I_=Uw("".slice),ZG=Math.max;zG({target:"String",proto:!0},{replaceAll:function(e,n){var r=__(this),o,s,i,a,l,c,u,h,p,f,m=0,g="";if(!HG(e)){if(o=KG(e),o&&(s=bc(__(GG(e))),!~Dy(s,"g")))throw new qG("`.replaceAll` does not allow non-global regexes");if(i=WG(e,XG),i)return BG(i,e,r,n)}for(a=bc(r),l=bc(e),c=UG(n),c||(n=bc(n)),u=l.length,h=ZG(1,u),p=Dy(a,l);p!==-1;)f=c?bc(n(l,p,a)):VG(l,a,p,[],void 0,n),g+=I_(a,m,p)+f,m=p+u,p=p+h>a.length?-1:Dy(a,l,p+h);return m<a.length&&(g+=I_(a,m)),g}});var QG=id;QG("String","replaceAll");function zM(t){return t&&typeof t=="object"&&"parents"in t}function BM(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 ff(t,e){if(t.children.remove(e)&&t.children.isEmpty&&zM(t))for(let n=0,r=t.parents.length;n<r;n++)ff(t.parents[n],t)}function Hw(t,e){if(t.children.add(e)&&zM(t))for(let n=0,r=t.parents.length;n<r;n++)Hw(t.parents[n],t)}function UM(t,e){return t===e||Object.is(t,e)||!!(t&&e&&typeof t.equals=="function"&&t.equals(e))}function Ii(t,e){const n=Symbol.for(`com.tldraw.state/${t}`),r=globalThis;return r[n]??(r[n]=e()),r[n]}const us=Ii("empty_array",()=>Object.freeze([])),E_=8;class gf{constructor(){E(this,"arraySize",0);E(this,"array",Array(E_));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<E_?(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 HM{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 JG{constructor(e,n){E(this,"offset",0);E(this,"maybeRemoved");this.below=e,this.child=n}}const it=Ii("capture",()=>({stack:null}));function oh(t){const e=it.stack;it.stack=null;try{return t()}finally{it.stack=e}}function KM(t){it.stack=new JG(it.stack,t),t.parentSet.clear()}function WM(){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)||ff(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)||ff(n,t.child)}}function mf(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 qs=-1;class eV{constructor(e,n,r){E(this,"_isActivelyListening",!1);E(this,"lastTraversedEpoch",qs);E(this,"lastReactedEpoch",qs);E(this,"_scheduleCount",0);E(this,"parentSet",new gf);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&&!BM(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++)ff(this.parents[e],this)}execute(){try{KM(this);const e=Ln(),n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,n}finally{WM()}}}const Xl=Ii("EffectScheduler",()=>eV);function Mo(t,e,n){const r=new Xl(t,e,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function tV(t,e,n){const r=new Xl(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 nV{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())VM(e);else this.isRoot?GM(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=Ii("transactions",()=>({globalEpoch:qs+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:qs+1}));function rV(){return Re.reactionEpoch}function Ln(){return Re.globalEpoch}function oV(){return Re.globalIsReacting}function Kw(t,e){e.lastTraversedEpoch!==Re.globalEpoch&&(e.lastTraversedEpoch=Re.globalEpoch,e instanceof Xl?t.add(e):e.children.visit(n=>Kw(t,n)))}function GM(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 sV(t,e){Re.currentTransaction?Re.currentTransaction.initialAtomValues.has(t)||Re.currentTransaction.initialAtomValues.set(t,e):Re.globalIsReacting?VM(t):GM([t])}function VM(t){const e=Re.cleanupReactors??(Re.cleanupReactors=new Set);t.children.visit(n=>Kw(e,n))}function iV(){Re.globalEpoch++}function aV(t){const e=new nV(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 Ao(t){return Re.currentTransaction?t():aV(t)}class lV{constructor(e,n,r){E(this,"isEqual");E(this,"computeDiff");E(this,"lastChangedEpoch",Ln());E(this,"children",new gf);E(this,"historyBuffer");this.name=e,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new HM(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return mf(this),this.current}set(e,n){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,e))??UM(this.current,e))return this.current;iV(),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,sV(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var n;return mf(this),e>=this.lastChangedEpoch?us:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const cV=Ii("Atom",()=>lV);function Et(t,e,n){return new cV(t,e,n)}let k_=!1;function uV(){k_||(k_=!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 Uc=Symbol.for("com.tldraw.state/UNINITIALIZED");function Xi(t){return t===Uc}const ax=Ii("WithDiff",()=>class{constructor(e,n){this.value=e,this.diff=n}});function Hc(t,e){return new ax(t,e)}class dV{constructor(e,n,r){E(this,"lastChangedEpoch",qs);E(this,"lastTraversedEpoch",qs);E(this,"lastCheckedEpoch",qs);E(this,"parentSet",new gf);E(this,"parents",[]);E(this,"parentEpochs",[]);E(this,"children",new gf);E(this,"historyBuffer");E(this,"state",Uc);E(this,"error",null);E(this,"computeDiff");E(this,"isEqual");this.name=e,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new HM(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??UM}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var o;const n=this.lastChangedEpoch===qs,r=Ln();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&oV()&&this.lastTraversedEpoch<rV()||!BM(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{KM(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof ax?s.value:s,a=this.state===Uc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=s instanceof ax?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!==Uc&&(this.state=Uc,this.lastChangedEpoch=Ln()),this.lastCheckedEpoch=Ln(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!e)throw s;return this.state}finally{WM()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{mf(this)}}getDiffSince(e){var n;return this.__unsafe__getWithoutCapture(!0),mf(this),e>=this.lastChangedEpoch?us:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const Cg=Ii("Computed",()=>dV);function hV(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 Cg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[YM]=!0,r}function pV(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 Cg(n,o.bind(this),t),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function fV(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 Cg(String(n.name),e.bind(this),t),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:s})),s.get()};return o[YM]=!0,o}function T_(t={},e){if(e.length===2){const[n,r]=e;return fV(t,n,r)}else{const[n,r,o]=e;return o.get?(uV(),pV(t,n,r,o)):hV(t,n,r,o)}}const YM="@@__isComputedMethod__@@";function W(){if(arguments.length===1){const t=arguments[0];return(...e)=>T_(t,e)}else return typeof arguments[0]=="string"?new Cg(arguments[0],arguments[1],arguments[2]):T_(void 0,arguments)}const XM=1,gV=Ii("apiVersion",()=>XM);if(gV!==XM)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");Pi("@tldraw/state","3.4.1","esm");function _g(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 Xl(`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 M_={apply(t,e,n){return _g(t.displayName??t.name??"tracked(???)",()=>t.apply(e,n))}},mV=Symbol.for("react.memo"),yV=Symbol.for("react.forward_ref");function $t(t){let e=null;const n=t.$$typeof;return n===mV&&(t=t.type,e=t.compare),n===yV?w.memo(w.forwardRef(new Proxy(t.render,M_))):w.memo(new Proxy(t,M_),e)}function qM(t,e,n){return w.useState(()=>{const r=typeof e=="function"?e():e;return Et(`useAtom(${t})`,r,n)})[0]}function SV(){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 ii(t,e,n=us){w.useEffect(()=>{const r=new Xl(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=>Mo(`useValue(${n})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return w.useSyncExternalStore(s,i,i)}finally{r.current=!1}}Pi("@tldraw/state-react","3.4.1","esm");class np{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 Ig{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 qn(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 Ig(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 zo(t,e){return new Ig(t,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function yf(){return{added:{},updated:{},removed:{}}}function lx(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 ZM(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 au(e,t),e}function au(t,e){for(const n of e){for(const[r,o]of qn(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 qn(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 qn(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 Sf={exports:{}};Sf.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]",m="[object GeneratorFunction]",g="[object Map]",v="[object Number]",S="[object Null]",y="[object Object]",P="[object Promise]",b="[object Proxy]",C="[object RegExp]",I="[object Set]",k="[object String]",_="[object Symbol]",M="[object Undefined]",T="[object WeakMap]",D="[object ArrayBuffer]",A="[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]",ee="[object Uint32Array]",he=/[\\^$.*+?()[\]{}|]/g,ue=/^\[object .+?Constructor\]$/,ke=/^(?:0|[1-9]\d*)$/,se={};se[O]=se[R]=se[B]=se[L]=se[G]=se[$]=se[U]=se[Y]=se[ee]=!0,se[a]=se[l]=se[D]=se[u]=se[A]=se[h]=se[p]=se[f]=se[g]=se[v]=se[y]=se[C]=se[I]=se[k]=se[T]=!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,Ue=lt&<.exports===$e,tr=Ue&&We.process,Ft=function(){try{return tr&&tr.binding&&tr.binding("util")}catch{}}(),jn=Ft&&Ft.isTypedArray;function vt(j,F){for(var V=-1,ne=j==null?0:j.length,Je=0,Se=[];++V<ne;){var mt=j[V];F(mt,V,j)&&(Se[Je++]=mt)}return Se}function Jt(j,F){for(var V=-1,ne=F.length,Je=j.length;++V<ne;)j[Je+V]=F[V];return j}function Wo(j,F){for(var V=-1,ne=j==null?0:j.length;++V<ne;)if(F(j[V],V,j))return!0;return!1}function ic(j,F){for(var V=-1,ne=Array(j);++V<j;)ne[V]=F(V);return ne}function Ts(j){return function(F){return j(F)}}function w4(j,F){return j.has(F)}function b4(j,F){return j==null?void 0:j[F]}function P4(j){var F=-1,V=Array(j.size);return j.forEach(function(ne,Je){V[++F]=[Je,ne]}),V}function C4(j,F){return function(V){return j(F(V))}}function _4(j){var F=-1,V=Array(j.size);return j.forEach(function(ne){V[++F]=ne}),V}var I4=Array.prototype,E4=Function.prototype,kd=Object.prototype,Im=st["__core-js_shared__"],Gb=E4.toString,fo=kd.hasOwnProperty,Vb=function(){var j=/[^.]+$/.exec(Im&&Im.keys&&Im.keys.IE_PROTO||"");return j?"Symbol(src)_1."+j:""}(),Yb=kd.toString,k4=RegExp("^"+Gb.call(fo).replace(he,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Xb=Ue?st.Buffer:void 0,Td=st.Symbol,qb=st.Uint8Array,Zb=kd.propertyIsEnumerable,T4=I4.splice,Oi=Td?Td.toStringTag:void 0,Qb=Object.getOwnPropertySymbols,M4=Xb?Xb.isBuffer:void 0,A4=C4(Object.keys,Object),Em=Ia(st,"DataView"),ac=Ia(st,"Map"),km=Ia(st,"Promise"),Tm=Ia(st,"Set"),Mm=Ia(st,"WeakMap"),lc=Ia(Object,"create"),j4=Li(Em),O4=Li(ac),D4=Li(km),R4=Li(Tm),L4=Li(Mm),Jb=Td?Td.prototype:void 0,Am=Jb?Jb.valueOf:void 0;function Di(j){var F=-1,V=j==null?0:j.length;for(this.clear();++F<V;){var ne=j[F];this.set(ne[0],ne[1])}}function $4(){this.__data__=lc?lc(null):{},this.size=0}function F4(j){var F=this.has(j)&&delete this.__data__[j];return this.size-=F?1:0,F}function N4(j){var F=this.__data__;if(lc){var V=F[j];return V===r?void 0:V}return fo.call(F,j)?F[j]:void 0}function z4(j){var F=this.__data__;return lc?F[j]!==void 0:fo.call(F,j)}function B4(j,F){var V=this.__data__;return this.size+=this.has(j)?0:1,V[j]=lc&&F===void 0?r:F,this}Di.prototype.clear=$4,Di.prototype.delete=F4,Di.prototype.get=N4,Di.prototype.has=z4,Di.prototype.set=B4;function Go(j){var F=-1,V=j==null?0:j.length;for(this.clear();++F<V;){var ne=j[F];this.set(ne[0],ne[1])}}function U4(){this.__data__=[],this.size=0}function H4(j){var F=this.__data__,V=Ad(F,j);if(V<0)return!1;var ne=F.length-1;return V==ne?F.pop():T4.call(F,V,1),--this.size,!0}function K4(j){var F=this.__data__,V=Ad(F,j);return V<0?void 0:F[V][1]}function W4(j){return Ad(this.__data__,j)>-1}function G4(j,F){var V=this.__data__,ne=Ad(V,j);return ne<0?(++this.size,V.push([j,F])):V[ne][1]=F,this}Go.prototype.clear=U4,Go.prototype.delete=H4,Go.prototype.get=K4,Go.prototype.has=W4,Go.prototype.set=G4;function Ri(j){var F=-1,V=j==null?0:j.length;for(this.clear();++F<V;){var ne=j[F];this.set(ne[0],ne[1])}}function V4(){this.size=0,this.__data__={hash:new Di,map:new(ac||Go),string:new Di}}function Y4(j){var F=jd(this,j).delete(j);return this.size-=F?1:0,F}function X4(j){return jd(this,j).get(j)}function q4(j){return jd(this,j).has(j)}function Z4(j,F){var V=jd(this,j),ne=V.size;return V.set(j,F),this.size+=V.size==ne?0:1,this}Ri.prototype.clear=V4,Ri.prototype.delete=Y4,Ri.prototype.get=X4,Ri.prototype.has=q4,Ri.prototype.set=Z4;function Md(j){var F=-1,V=j==null?0:j.length;for(this.__data__=new Ri;++F<V;)this.add(j[F])}function Q4(j){return this.__data__.set(j,r),this}function J4(j){return this.__data__.has(j)}Md.prototype.add=Md.prototype.push=Q4,Md.prototype.has=J4;function Ms(j){var F=this.__data__=new Go(j);this.size=F.size}function eN(){this.__data__=new Go,this.size=0}function tN(j){var F=this.__data__,V=F.delete(j);return this.size=F.size,V}function nN(j){return this.__data__.get(j)}function rN(j){return this.__data__.has(j)}function oN(j,F){var V=this.__data__;if(V instanceof Go){var ne=V.__data__;if(!ac||ne.length<n-1)return ne.push([j,F]),this.size=++V.size,this;V=this.__data__=new Ri(ne)}return V.set(j,F),this.size=V.size,this}Ms.prototype.clear=eN,Ms.prototype.delete=tN,Ms.prototype.get=nN,Ms.prototype.has=rN,Ms.prototype.set=oN;function sN(j,F){var V=Od(j),ne=!V&&xN(j),Je=!V&&!ne&&jm(j),Se=!V&&!ne&&!Je&&lP(j),mt=V||ne||Je||Se,At=mt?ic(j.length,String):[],Nt=At.length;for(var ct in j)fo.call(j,ct)&&!(mt&&(ct=="length"||Je&&(ct=="offset"||ct=="parent")||Se&&(ct=="buffer"||ct=="byteLength"||ct=="byteOffset")||gN(ct,Nt)))&&At.push(ct);return At}function Ad(j,F){for(var V=j.length;V--;)if(oP(j[V][0],F))return V;return-1}function iN(j,F,V){var ne=F(j);return Od(j)?ne:Jt(ne,V(j))}function cc(j){return j==null?j===void 0?M:S:Oi&&Oi in Object(j)?pN(j):vN(j)}function eP(j){return uc(j)&&cc(j)==a}function tP(j,F,V,ne,Je){return j===F?!0:j==null||F==null||!uc(j)&&!uc(F)?j!==j&&F!==F:aN(j,F,V,ne,tP,Je)}function aN(j,F,V,ne,Je,Se){var mt=Od(j),At=Od(F),Nt=mt?l:As(j),ct=At?l:As(F);Nt=Nt==a?y:Nt,ct=ct==a?y:ct;var nr=Nt==y,Br=ct==y,en=Nt==ct;if(en&&jm(j)){if(!jm(F))return!1;mt=!0,nr=!1}if(en&&!nr)return Se||(Se=new Ms),mt||lP(j)?nP(j,F,V,ne,Je,Se):dN(j,F,Nt,V,ne,Je,Se);if(!(V&o)){var Pr=nr&&fo.call(j,"__wrapped__"),Cr=Br&&fo.call(F,"__wrapped__");if(Pr||Cr){var js=Pr?j.value():j,Vo=Cr?F.value():F;return Se||(Se=new Ms),Je(js,Vo,V,ne,Se)}}return en?(Se||(Se=new Ms),hN(j,F,V,ne,Je,Se)):!1}function lN(j){if(!aP(j)||yN(j))return!1;var F=sP(j)?k4:ue;return F.test(Li(j))}function cN(j){return uc(j)&&iP(j.length)&&!!se[cc(j)]}function uN(j){if(!SN(j))return A4(j);var F=[];for(var V in Object(j))fo.call(j,V)&&V!="constructor"&&F.push(V);return F}function nP(j,F,V,ne,Je,Se){var mt=V&o,At=j.length,Nt=F.length;if(At!=Nt&&!(mt&&Nt>At))return!1;var ct=Se.get(j);if(ct&&Se.get(F))return ct==F;var nr=-1,Br=!0,en=V&s?new Md:void 0;for(Se.set(j,F),Se.set(F,j);++nr<At;){var Pr=j[nr],Cr=F[nr];if(ne)var js=mt?ne(Cr,Pr,nr,F,j,Se):ne(Pr,Cr,nr,j,F,Se);if(js!==void 0){if(js)continue;Br=!1;break}if(en){if(!Wo(F,function(Vo,$i){if(!w4(en,$i)&&(Pr===Vo||Je(Pr,Vo,V,ne,Se)))return en.push($i)})){Br=!1;break}}else if(!(Pr===Cr||Je(Pr,Cr,V,ne,Se))){Br=!1;break}}return Se.delete(j),Se.delete(F),Br}function dN(j,F,V,ne,Je,Se,mt){switch(V){case A:if(j.byteLength!=F.byteLength||j.byteOffset!=F.byteOffset)return!1;j=j.buffer,F=F.buffer;case D:return!(j.byteLength!=F.byteLength||!Se(new qb(j),new qb(F)));case u:case h:case v:return oP(+j,+F);case p:return j.name==F.name&&j.message==F.message;case C:case k:return j==F+"";case g:var At=P4;case I:var Nt=ne&o;if(At||(At=_4),j.size!=F.size&&!Nt)return!1;var ct=mt.get(j);if(ct)return ct==F;ne|=s,mt.set(j,F);var nr=nP(At(j),At(F),ne,Je,Se,mt);return mt.delete(j),nr;case _:if(Am)return Am.call(j)==Am.call(F)}return!1}function hN(j,F,V,ne,Je,Se){var mt=V&o,At=rP(j),Nt=At.length,ct=rP(F),nr=ct.length;if(Nt!=nr&&!mt)return!1;for(var Br=Nt;Br--;){var en=At[Br];if(!(mt?en in F:fo.call(F,en)))return!1}var Pr=Se.get(j);if(Pr&&Se.get(F))return Pr==F;var Cr=!0;Se.set(j,F),Se.set(F,j);for(var js=mt;++Br<Nt;){en=At[Br];var Vo=j[en],$i=F[en];if(ne)var cP=mt?ne($i,Vo,en,F,j,Se):ne(Vo,$i,en,j,F,Se);if(!(cP===void 0?Vo===$i||Je(Vo,$i,V,ne,Se):cP)){Cr=!1;break}js||(js=en=="constructor")}if(Cr&&!js){var Dd=j.constructor,Rd=F.constructor;Dd!=Rd&&"constructor"in j&&"constructor"in F&&!(typeof Dd=="function"&&Dd instanceof Dd&&typeof Rd=="function"&&Rd instanceof Rd)&&(Cr=!1)}return Se.delete(j),Se.delete(F),Cr}function rP(j){return iN(j,PN,fN)}function jd(j,F){var V=j.__data__;return mN(F)?V[typeof F=="string"?"string":"hash"]:V.map}function Ia(j,F){var V=b4(j,F);return lN(V)?V:void 0}function pN(j){var F=fo.call(j,Oi),V=j[Oi];try{j[Oi]=void 0;var ne=!0}catch{}var Je=Yb.call(j);return ne&&(F?j[Oi]=V:delete j[Oi]),Je}var fN=Qb?function(j){return j==null?[]:(j=Object(j),vt(Qb(j),function(F){return Zb.call(j,F)}))}:CN,As=cc;(Em&&As(new Em(new ArrayBuffer(1)))!=A||ac&&As(new ac)!=g||km&&As(km.resolve())!=P||Tm&&As(new Tm)!=I||Mm&&As(new Mm)!=T)&&(As=function(j){var F=cc(j),V=F==y?j.constructor:void 0,ne=V?Li(V):"";if(ne)switch(ne){case j4:return A;case O4:return g;case D4:return P;case R4:return I;case L4:return T}return F});function gN(j,F){return F=F??i,!!F&&(typeof j=="number"||ke.test(j))&&j>-1&&j%1==0&&j<F}function mN(j){var F=typeof j;return F=="string"||F=="number"||F=="symbol"||F=="boolean"?j!=="__proto__":j===null}function yN(j){return!!Vb&&Vb in j}function SN(j){var F=j&&j.constructor,V=typeof F=="function"&&F.prototype||kd;return j===V}function vN(j){return Yb.call(j)}function Li(j){if(j!=null){try{return Gb.call(j)}catch{}try{return j+""}catch{}}return""}function oP(j,F){return j===F||j!==j&&F!==F}var xN=eP(function(){return arguments}())?eP:function(j){return uc(j)&&fo.call(j,"callee")&&!Zb.call(j,"callee")},Od=Array.isArray;function wN(j){return j!=null&&iP(j.length)&&!sP(j)}var jm=M4||_N;function bN(j,F){return tP(j,F)}function sP(j){if(!aP(j))return!1;var F=cc(j);return F==f||F==m||F==c||F==b}function iP(j){return typeof j=="number"&&j>-1&&j%1==0&&j<=i}function aP(j){var F=typeof j;return j!=null&&(F=="object"||F=="function")}function uc(j){return j!=null&&typeof j=="object"}var lP=jn?Ts(jn):cN;function PN(j){return wN(j)?sN(j):uN(j)}function CN(){return[]}function _N(){return!1}t.exports=bN})(Sf,Sf.exports);var vV=Sf.exports;const QM=vi(vV);function xV(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 wV(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 A_(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 j_(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 xV(Object.values(r))}class bV{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(Xi(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?Hc(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(Xi(s))return o();const a=r.getDiffSince(i);if(a===ur)return o();const l=new Map,c=(f,m)=>{let g=l.get(f);g||(g=new np(s.get(f)??new Set)),g.add(m),l.set(f,g)},u=(f,m)=>{let g=l.get(f);g||(g=new np(s.get(f)??new Set)),g.remove(m),l.set(f,g)};for(const f of a){for(const m of ut(f.added))if(m.typeName===e){const g=m[n];c(g,m.id)}for(const[m,g]of ut(f.updated))if(g.typeName===e){const v=m[n],S=g[n];v!==S&&(u(v,g.id),c(S,g.id))}for(const m of ut(f.removed))if(m.typeName===e){const g=m[n];u(g,m.id)}}let h,p;for(const[f,m]of l){const g=m.get();g&&(h||(h=new Map(s)),p||(p=new Map),g.value.size===0?h.delete(f):h.set(f,g.value),p.set(f,g.diff))}return h&&p?Hc(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:[]})):j_(this,e,l)},i=l=>{const c=s(),u=wV(l,c);return u?Hc(c,u):l},a=W("ids_query:"+r,n,{isEqual:QM});return W("query:"+r,(l,c)=>{const u=a.get();if(Xi(l))return s();if(c<a.lastChangedEpoch)return i(l);const h=o.getDiffSince(c);if(h===ur)return i(l);const p=new np(l);for(const m of h){for(const g of ut(m.added))g.typeName===e&&A_(u,g)&&p.add(g.id);for(const[g,v]of ut(m.updated))v.typeName===e&&(A_(u,v)?p.add(v.id):p.remove(v.id));for(const g of ut(m.removed))g.typeName===e&&p.remove(g.id)}const f=p.get();return f?Hc(f.value,f.diff):l},{historyLength:50})}exec(e,n){const r=j_(this,e,n);if(r.size===0)return us;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class PV{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),()=>Fi(this._beforeCreateHandlers[e],n)}registerAfterCreateHandler(e,n){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(n),()=>Fi(this._afterCreateHandlers[e],n)}registerBeforeChangeHandler(e,n){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(n),()=>Fi(this._beforeChangeHandlers[e],n)}registerAfterChangeHandler(e,n){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(n),()=>Fi(this._afterChangeHandlers[e],n)}registerBeforeDeleteHandler(e,n){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(n),()=>Fi(this._beforeDeleteHandlers[e],n)}registerAfterDeleteHandler(e,n){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(n),()=>Fi(this._afterDeleteHandlers[e],n)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Fi(this._operationCompleteHandlers,e)}}function Fi(t,e){const n=t.indexOf(e);n>=0&&t.splice(n,1)}class Gw{constructor(e){E(this,"id");E(this,"atoms",Et("store_atoms",{}));E(this,"history",Et("history",0,{historyLength:1e3}));E(this,"query",new bV(this.atoms,this.history));E(this,"listeners",new Set);E(this,"historyAccumulator",new _V);E(this,"historyReactor");E(this,"schema");E(this,"props");E(this,"scopedTypes");E(this,"sideEffects",new PV(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(IT(qn(n).map(([s,i])=>[s,Et("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=tV("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=HT(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:iu(e.added,(o,s)=>this.scopedTypes[n].has(s.typeName)),updated:iu(e.updated,(o,s)=>this.scopedTypes[n].has(s[1].typeName)),removed:iu(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 g=p.__unsafe__getWithoutCapture();r[a.id]=[f,g],this.addDiffForAfterEvent(f,g)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),o[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...s}),i[a.id]=Et("atom:"+a.id,a)}i&&this.atoms.set(i),l&&this.updateHistory({added:o,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const n=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const s of e){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&n.add(s)}let o;this.atoms.update(s=>{let i;for(const a of e){if(n.has(a)||!(a in s))continue;i||(i={...s}),o||(o={}),delete i[a];const l=s[a].get();o[a]=l,this.addDiffForAfterEvent(l,null)}return i??s}),o&&this.updateHistory({added:{},updated:{},removed:o})})}get(e){var n;return(n=this.atoms.get()[e])==null?void 0:n.get()}unsafeGetWithoutCapture(e){var n;return(n=this.atoms.__unsafe__getWithoutCapture()[e])==null?void 0:n.__unsafe__getWithoutCapture()}serialize(e="document"){const n={};for(const[r,o]of qn(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(MC(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,Ao(e)}finally{this.isMergingRemoteChanges=!1}}extractingChanges(e){const n=[],r=this.historyAccumulator.addInterceptor(o=>n.push(o.changes));try{return Ao(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,Kn(c,h))||(u||(u={...c}),u[h]=p);u&&o.push(u)}else o.push(a)}const s=MC(e.removed);o.length&&this.put(o),s.length&&this.remove(s)},n)}createComputedCache(e,n,r){const o=new Oo;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 Oo;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 Ao(()=>{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 CV(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 _V{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=CV(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function IV(t,e,n){const r=new Oo;return{get(o,s){return r.get(o,()=>(o instanceof Gw?o:o.store).createComputedCache(t,l=>e(o,l),n)).get(s)}}}function EV(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 ml({sequence:t,sequenceId:e,retroactive:n=!0}){const r={sequenceId:e,retroactive:n,sequence:EV(t)};return JM(r),r}function Qn(t,e){return Object.fromEntries(qn(e).map(([n,r])=>[n,`${t}/${r}`]))}function xr(t){const e=t.sequenceId;return ml({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 kV(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}=vf(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 vf(t){const[e,n]=t.split("/");return{sequenceId:e,version:parseInt(n)}}function O_(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 JM(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;O_(t.sequence[0].id,t.sequenceId);let e=vf(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;O_(r,t.sequenceId);const o=vf(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 $s=(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))($s||{});function TV(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}`),JM(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=kV(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=Kn(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=TV(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:$s.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"?$s.TargetVersionTooOld:$s.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:$s.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:$s.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:$s.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:$s.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?vf(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=Kn(this.types,e);return Le(n,"record type does not exists"),n}}Pi("@tldraw/store","3.4.1","esm");function MV(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=MV(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 Zn(t,e){try{return e()}catch(n){throw n instanceof Me?new Me(n.rawMessage,[t,...n.path]):new Me(n.toString(),[t])}}function pi(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 LV(this)}optional(){return tA(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=>(Zn(`(check ${e})`,()=>n(r)),r)):this.refine(r=>(e(r),r))}}class AV extends kn{constructor(e){super(n=>{const r=D_.validate(n);for(let o=0;o<r.length;o++)Zn(o,()=>e.validate(r[o]));return r},(n,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const o=D_.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,Zn(i,()=>e.validate(a));continue}if(Object.is(n[i],a))continue;const l=Zn(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 xf extends kn{constructor(e,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${pi(r)}`);for(const[o,s]of Object.entries(e))Zn(o,()=>{s.validate(Kn(r,o))});if(!n){for(const o of Object.keys(r))if(!eo(e,o))throw new Me("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Me(`Expected object, got ${pi(o)}`);let s=!1;for(const[i,a]of Object.entries(e)){const l=Kn(r,i),c=Kn(o,i);if(Object.is(l,c))continue;const u=Zn(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(!eo(e,i))throw new Me("Unexpected property",[i])}for(const i of Object.keys(r))if(!eo(o,i)){s=!0;break}return s?o:r}),this.config=e,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new xf(this.config,!0)}extend(e){return new xf({...this.config,...e})}}class Eg 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):Zn(`(${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):Kn(s,e)!==Kn(i,e)?Zn(`(${e} = ${l})`,()=>a.validate(i)):Zn(`(${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 ${pi(e)}`,[])}getMatchingSchemaAndVariant(e){const n=Kn(e,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new Me(`Expected a string for key "${this.key}", got ${pi(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Me(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:eo(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(e){return new Eg(this.key,this.config,e,this.useNumberKeys)}}class jV extends kn{constructor(e,n){super(r=>{if(typeof r!="object"||r===null)throw new Me(`Expected object, got ${pi(r)}`);for(const[o,s]of Object.entries(r))Zn(o,()=>{e.validate(o),n.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Me(`Expected object, got ${pi(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!eo(r,i)){s=!0,Zn(i,()=>{e.validate(i),n.validate(a)});continue}const l=Kn(r,i),c=a;if(Object.is(l,c))continue;const u=Zn(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(s=!0)}for(const i of Object.keys(r))if(!eo(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 ${pi(e)}`);return e})}const OV=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}`)}),wf=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}`)}),eA=fe.check(t=>{if(!Number.isInteger(t))throw new Me(`Expected an integer, got ${t}`)}),rp=eA.check(t=>{if(t<0)throw new Me(`Expected a positive integer, got ${t}`)}),DV=eA.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 D_=new kn(t=>{if(!Array.isArray(t))throw new Me(`Expected an array, got ${pi(t)}`);return t});function Wt(t){return new AV(t)}function Pe(t){return new xf(t)}function cx(t){return typeof t=="object"&&t!==null&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null||Object.getPrototypeOf(t)===a7)}function ux(t){return t===null||typeof t=="number"||typeof t=="string"||typeof t=="boolean"?!0:Array.isArray(t)?t.every(ux):cx(t)?Object.values(t).every(ux):!1}const Gt=new kn(t=>{if(ux(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(cx(t)&&cx(e)){let n=!1;for(const r of Object.keys(e)){if(!eo(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(!eo(e,r)){n=!0;break}return n?e:t}else return Gt.validate(e)});function bf(t,e){return new jV(t,e)}function Xw(t,e){return new Eg(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 RV(t,e){return new Eg(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 Bo(t,e){return new kn(n=>Zn(t,()=>e.validate(n)),(n,r)=>Zn(t,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(n,r):e.validate(r)))}function kg(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 tA(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 LV(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 Tg(...t){return kg(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 $V=new Set(["http:","https:","mailto:"]),gr=me.check(t=>{if(t==="")return;const e=qw(t);if(!$V.has(e.protocol.toLowerCase()))throw new Me(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)}),FV=new Set(["http:","https:","data:","asset:"]),oa=me.check(t=>{if(t==="")return;const e=qw(t);if(!FV.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 q9(t),t}catch{throw new Me(`Expected an index key, got ${JSON.stringify(t)}`)}});Pi("@tldraw/validate","3.4.1","esm");function dr(t){return me.refine(e=>{if(!e.startsWith(`${t}:`))throw new Error(`${t} ID must start with "${t}:"`);return e})}const Mg=dr("asset");function Qw(t,e){return Pe({id:Mg,typeName:gn("asset"),type:gn(t),props:e,meta:Gt})}const sa=Pe({x:fe,y:fe,z:fe.optional()}),lu=Pe({x:fe,y:fe,w:fe,h:fe}),nA=fe.check(t=>{if(t<0||t>1)throw new Me("Opacity must be between 0 and 1")}),NV=me.refine(t=>{if(!t.startsWith("page:")&&!t.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return t}),Ir=dr("shape");function zV(t,e,n){return Pe({id:Ir,typeName:gn("shape"),x:fe,y:fe,rotation:fe,index:Zw,parentId:NV,type:gn(t),isLocked:we,opacity:nA,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}const BV=dr("binding");function UV(t,e,n){return Pe({id:BV,typeName:gn("binding"),type:gn(t),fromId:Ir,toId:Ir,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}Qn("com.tldraw.binding",{});xr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function qi(t){return`binding:${ze()}`}function HV(t){return zo("binding",{scope:"document",validator:Bo("binding",Xw("type",nd(t,(e,{props:n,meta:r})=>UV(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=OV}=n;return new Zt(e,r,o)}static defineEnum(e,n){const{defaultValue:r,values:o}=n;return new KV(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 KV extends Zt{constructor(e,n,r){super(e,n,Tg(...r)),this.values=r}}const sh=Qn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),WV=xr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:sh.AddIsLocked,up:t=>{t.isLocked=!1},down:t=>{delete t.isLocked}},{id:sh.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:sh.AddMeta,up:t=>{t.meta={}}},{id:sh.AddWhite,up:t=>{},down:t=>{t.props.color==="white"&&(t.props.color="black")}}]});function ol(t){return t?t.typeName==="shape":!1}function $n(t){return t?t.startsWith("shape:"):!1}function Ke(t){return`shape:${t??ze()}`}function rA(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 co(t,e){return nd(e,(n,r)=>`com.tldraw.shape.${t}/${r}`)}function GV(t){return zo("shape",{scope:"document",validator:Bo("shape",Xw("type",nd(t,(e,{props:n,meta:r})=>zV(e,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function R_(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} ${Ig} migrations. Expected '${s}', got '${o.sequenceId}'`),n.push(o)):"sequence"in o?n.push(ml({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?oA(t,r,i):i)})):n.push(ml({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(ml({sequenceId:s,retroactive:!1,sequence:[]}))}return n}function oA(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 sA=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],Pf={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 Is(t){return t.isDarkMode?Pf.darkMode:Pf.lightMode}const mr=Zt.defineEnum("tldraw:color",{defaultValue:"black",values:sA}),Jw=Zt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:sA}),ia=Zt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),aa=Zt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Do=Zt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),iA={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Ro=Zt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),aA=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Cf=Zt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:aA}),_f=Zt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:aA}),lA={labelColor:Jw,color:mr,fill:aa,dash:ia,size:Ro,arrowheadStart:Cf,arrowheadEnd:_f,font:Do,start:sa,end:sa,bend:fe,text:me,labelPosition:fe,scale:Ct},Na=co("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function ih(t){return oA("shape","arrow",t)}const cA=ml({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[ih({id:Na.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"}),ih({id:Na.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)}}),ih({id:Na.AddLabelPosition,up:t=>{t.labelPosition=.5},down:t=>{delete t.labelPosition}}),{id:Na.ExtractBindings,scope:"store",up:t=>{const e=Object.values(t).filter(n=>n.typeName==="shape"&&n.type==="arrow");for(const n of e){const{start:r,end:o}=n.props;if(r.type==="binding"){const s=qi(),i={typeName:"binding",id:s,type:"arrow",fromId:n.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};t[s]=i,n.props.start={x:0,y:0}}else delete n.props.start.type;if(o.type==="binding"){const s=qi(),i={typeName:"binding",id:s,type:"arrow",fromId:n.id,toId:o.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:o.normalizedAnchor,isExact:o.isExact,isPrecise:o.isPrecise}};t[s]=i,n.props.end={x:0,y:0}}else delete n.props.end.type}}},ih({id:Na.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}})]}),uA={terminal:Tg("start","end"),normalizedAnchor:sa,isExact:we,isPrecise:we},dA={sequence:[{dependsOn:[Na.ExtractBindings]}]},VV=Bo("camera",Pe({typeName:gn("camera"),id:dr("camera"),x:fe,y:fe,z:fe,meta:Gt})),YV=Qn("com.tldraw.camera",{AddMeta:1}),XV=xr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:YV.AddMeta,up:t=>{t.meta={}}}]}),_o=zo("camera",{validator:VV,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),qV=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"]),hA=kg(qV),ZV=Pe({type:hA,rotation:fe}),QV=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),JV=kg(QV),eY=new Set(["starting","paused","active","stopping"]),pA=Pe({id:me,points:Wt(sa),size:wf,color:JV,opacity:fe,state:kg(eY),delay:fe,shrink:fe,taper:we}),Fu=dr("page"),tY=Bo("page",Pe({typeName:gn("page"),id:Fu,name:me,index:Zw,meta:Gt})),nY=Qn("com.tldraw.page",{AddMeta:1}),rY=xr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:nY.AddMeta,up:t=>{t.meta={}}}]}),yr=zo("page",{validator:tY,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Dn(t){return yr.isId(t)}const oY={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 fA(t){return t?iu(t,e=>oY[e]):null}dr("instance");function sY(t){const e={};for(const[r,o]of t)e[r]=tA(o);const n=Bo("instance",Pe({typeName:gn("instance"),id:dr("instance"),currentPageId:Fu,followingUserId:me.nullable(),brush:lu.nullable(),opacityForNextShape:nA,stylesForNextShape:Pe(e),cursor:ZV,scribbles:Wt(pA),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:lu,insets:Wt(we),zoomBrush:lu.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 zo("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=Qn("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}),iY=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",aY=Bo("instance_page_state",Pe({typeName:gn("instance_page_state"),id:dr("instance_page_state"),pageId:Fu,selectedShapeIds:Wt(Ir),hintingShapeIds:Wt(Ir),erasingShapeIds:Wt(Ir),hoveredShapeId:Ir.nullable(),editingShapeId:Ir.nullable(),croppingShapeId:Ir.nullable(),focusedGroupId:Ir.nullable(),meta:Gt})),Pc=Qn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),lY=xr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Pc.AddCroppingId,up(t){t.croppingShapeId=null}},{id:Pc.RemoveInstanceIdAndCameraId,up(t){delete t.instanceId,delete t.cameraId}},{id:Pc.AddMeta,up:t=>{t.meta={}}},{id:Pc.RenameProperties,up:t=>{},down:t=>{}},{id:Pc.RenamePropertiesAgain,up:t=>{t.selectedShapeIds=t.selectedIds,delete t.selectedIds,t.hintingShapeIds=t.hintingIds,delete t.hintingIds,t.erasingShapeIds=t.erasingIds,delete t.erasingIds,t.hoveredShapeId=t.hoveredId,delete t.hoveredId,t.editingShapeId=t.editingId,delete t.editingId,t.croppingShapeId=t.croppingShapeId??t.croppingId??null,delete t.croppingId,t.focusedGroupId=t.focusLayerId,delete t.focusLayerId},down:t=>{t.selectedIds=t.selectedShapeIds,delete t.selectedShapeIds,t.hintingIds=t.hintingShapeIds,delete t.hintingShapeIds,t.erasingIds=t.erasingShapeIds,delete t.erasingShapeIds,t.hoveredId=t.hoveredShapeId,delete t.hoveredShapeId,t.editingId=t.editingShapeId,delete t.editingShapeId,t.croppingId=t.croppingShapeId,delete t.croppingShapeId,t.focusLayerId=t.focusedGroupId,delete t.focusedGroupId}}]}),qr=zo("instance_page_state",{validator:aY,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:{}})),cY=Bo("pointer",Pe({typeName:gn("pointer"),id:dr("pointer"),x:fe,y:fe,lastActivityTimestamp:fe,meta:Gt})),uY=Qn("com.tldraw.pointer",{AddMeta:1}),dY=xr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:uY.AddMeta,up:t=>{t.meta={}}}]}),e1=zo("pointer",{validator:cY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),If=e1.createId("pointer"),hY=Bo("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:hA,rotation:fe}),color:me,camera:Pe({x:fe,y:fe,z:fe}),screenBounds:lu,selectedShapeIds:Wt(dr("shape")),currentPageId:dr("page"),brush:lu.nullable(),scribbles:Wt(pA),chatMessage:me,meta:Gt})),Cc=Qn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),pY=xr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Cc.AddScribbleDelay,up:t=>{t.scribble!==null&&(t.scribble.delay=0)}},{id:Cc.RemoveInstanceId,up:t=>{delete t.instanceId}},{id:Cc.AddChatMessage,up:t=>{t.chatMessage=""}},{id:Cc.AddMeta,up:t=>{t.meta={}}},{id:Cc.RenameSelectedShapeIds,up:t=>{}}]}),fY=zo("instance_presence",{validator:hY,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:{}})),gY=Bo("document",Pe({typeName:gn("document"),id:gn("document:document"),gridSize:fe,name:me,meta:Gt})),L_=Qn("com.tldraw.document",{AddName:1,AddMeta:2}),mY=xr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:L_.AddName,up:t=>{t.name=""},down:t=>{delete t.name}},{id:L_.AddMeta,up:t=>{t.meta={}}}]}),t1=zo("document",{validator:gY,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),dx=t1.createId("document");function yY(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function $_(t){t.typeName==="asset"&&("src"in t&&(t.src="<redacted>"),"src"in t.props&&(t.props.src="<redacted>"))}function SY({error:t,phase:e,record:n,recordBefore:r}){throw gw(t,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?$_(nt(r)):void 0,recordAfter:$_(nt(n))}}),t}function vY(){return[yr.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function xY(t){const e=t.query.ids("page"),n=t.query.records("instance_page_state"),r=()=>{if(!t.has(dx))return t.put([t1.create({id:dx,name:t.props.defaultName})]),r();if(!t.has(If))return t.put([e1.create({id:If})]),r();const o=e.get();if(o.size===0)return t.put(vY()),r();const s=()=>[...o].map(u=>t.get(u)).sort(yY)[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=qr.createId(u);t.get(h)||a.add(h);const f=_o.createId(u);t.has(f)||l.add(f)}a.size>0&&t.put([...a].map(u=>qr.create({id:u,pageId:qr.parseId(u)}))),l.size>0&&t.put([...l].map(u=>_o.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(m=>t.has(m));if(h.length!==u.selectedShapeIds.length)return t.put([{...u,selectedShapeIds:h}]),r();const p=u.hintingShapeIds.filter(m=>t.has(m));if(p.length!==u.hintingShapeIds.length)return t.put([{...u,hintingShapeIds:p}]),r();const f=u.erasingShapeIds.filter(m=>t.has(m));if(f.length!==u.erasingShapeIds.length)return t.put([{...u,erasingShapeIds:f}]),r()}};return r}const wY=Qw("bookmark",Pe({title:me,description:me,image:me,favicon:me,src:oa.nullable()})),F_=Qn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),bY=xr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:t=>t.type==="bookmark",sequence:[{id:F_.MakeUrlsValid,up:t=>{oa.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:F_.AddFavicon,up:t=>{oa.isValid(t.props.favicon)||(t.props.favicon="")},down:t=>{delete t.props.favicon}}]}),PY=Qw("image",Pe({w:fe,h:fe,name:me,isAnimated:we,mimeType:me.nullable(),src:oa.nullable(),fileSize:Ct.optional()})),_c=Qn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),CY=xr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:t=>t.type==="image",sequence:[{id:_c.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:_c.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:_c.MakeUrlsValid,up:t=>{oa.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:_c.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:_c.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),_Y=Qw("video",Pe({w:fe,h:fe,name:me,isAnimated:we,mimeType:me.nullable(),src:oa.nullable(),fileSize:fe.optional()})),Ic=Qn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),IY=xr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:t=>t.type==="video",sequence:[{id:Ic.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Ic.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:Ic.MakeUrlsValid,up:t=>{oa.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Ic.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Ic.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),EY=Bo("asset",Xw("type",{image:PY,video:_Y,bookmark:wY})),kY=Qn("com.tldraw.asset",{AddMeta:1}),TY=xr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:kY.AddMeta,up:t=>{t.meta={}}}]}),Ks=zo("asset",{validator:EY,scope:"document"}).withDefaultProperties(()=>({meta:{}})),gA={w:Ct,h:Ct,assetId:Mg.nullable(),url:gr},N_=co("bookmark",{NullAssetId:1,MakeUrlsValid:2}),mA={sequence:[{id:N_.NullAssetId,up:t=>{t.assetId===void 0&&(t.assetId=null)},down:"retired"},{id:N_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},yA=Pe({type:Tg("free","straight"),points:Wt(sa)}),SA={color:mr,fill:aa,dash:ia,size:Ro,segments:Wt(yA),isComplete:we,isClosed:we,isPen:we,scale:Ct},z_=co("draw",{AddInPen:1,AddScale:2}),vA={sequence:[{id:z_.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:z_.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},MY=/(^\/r\/[^/]+\/?$)/,AY=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(MY))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","")}}],xA={w:Ct,h:Ct,url:me},ah=co("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),wA={sequence:[{id:ah.GenOriginalUrlInEmbed,up:t=>{try{const e=t.url,n=new URL(e).host.replace("www.","");let r;for(const o of AY)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:ah.RemoveDoesResize,up:t=>{delete t.doesResize},down:"retired"},{id:ah.RemoveTmpOldUrl,up:t=>{delete t.tmpOldUrl},down:"retired"},{id:ah.RemovePermissionOverrides,up:t=>{delete t.overridePermissions},down:"retired"}]},bA={w:Ct,h:Ct,name:me},PA={sequence:[]},Ef=Zt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),kf=Zt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Zr=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"]}),CA={geo:Zr,labelColor:Jw,color:mr,fill:aa,dash:ia,size:Ro,font:Do,align:Ef,verticalAlign:kf,url:gr,w:Ct,h:Ct,growY:wf,text:me,scale:Ct},Xo=co("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),_A={sequence:[{id:Xo.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Xo.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"},{id:Xo.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Xo.AddCheckBox,up:t=>{},down:"retired"},{id:Xo.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Xo.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:Xo.AddCloud,up:t=>{},down:"retired"},{id:Xo.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Xo.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},IA={},EA={sequence:[]},kA={color:mr,size:Ro,segments:Wt(yA),isComplete:we,isPen:we,scale:Ct},jY=co("highlight",{AddScale:1}),TA={sequence:[{id:jY.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},OY=Pe({topLeft:sa,bottomRight:sa}),MA={w:Ct,h:Ct,playing:we,url:gr,assetId:Mg.nullable(),crop:OY.nullable(),flipX:we,flipY:we},lh=co("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),AA={sequence:[{id:lh.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:lh.AddCropProp,up:t=>{t.crop=null},down:t=>{delete t.crop}},{id:lh.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:lh.AddFlipProps,up:t=>{t.flipX=!1,t.flipY=!1},down:t=>{delete t.flipX,delete t.flipY}}]},Tf=Zt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),DY=Pe({id:me,index:Zw,x:fe,y:fe}),jA={color:mr,dash:ia,size:Ro,spline:Tf,points:bf(me,DY),scale:Ct},Ec=co("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),OA={sequence:[{id:Ec.AddSnapHandles,up:t=>{for(const e of Object.values(t.handles))e.canSnap=!0},down:"retired"},{id:Ec.RemoveExtraHandleProps,up:t=>{t.handles=IT(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:Ec.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=Lu(t.points.length);t.handles=Object.fromEntries(t.points.map((n,r)=>[e[r],{x:n.x,y:n.y}])),delete t.points}},{id:Ec.PointIndexIds,up:t=>{const e=Lu(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:Ec.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},DA={color:mr,labelColor:Jw,size:Ro,font:Do,fontSizeAdjustment:wf,align:Ef,verticalAlign:kf,growY:wf,url:gr,text:me,scale:Ct},Ds=co("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8}),RA={sequence:[{id:Ds.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Ds.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Ds.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:Ds.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Ds.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Ds.AddFontSizeAdjustment,up:t=>{t.fontSizeAdjustment=0},down:t=>{delete t.fontSizeAdjustment}},{id:Ds.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}},{id:Ds.AddLabelColor,up:t=>{t.labelColor="black"},down:t=>{delete t.labelColor}}]},hx=Zt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),LA={color:mr,size:Ro,font:Do,textAlign:hx,w:Ct,text:me,scale:Ct,autoSize:we},B_=co("text",{RemoveJustify:1,AddTextAlign:2}),$A={sequence:[{id:B_.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:B_.AddTextAlign,up:t=>{t.textAlign=t.align,delete t.align},down:t=>{t.align=t.textAlign,delete t.textAlign}}]},FA={w:Ct,h:Ct,time:fe,playing:we,url:gr,assetId:Mg.nullable()},U_=co("video",{AddUrlProp:1,MakeUrlsValid:2}),NA={sequence:[{id:U_.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:U_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},ch=Qn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),RY=ml({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:ch.RemoveCodeAndIconShapeTypes,scope:"store",up:t=>{for(const[e,n]of qn(t))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete t[e]}},{id:ch.AddInstancePresenceType,scope:"store",up(t){}},{id:ch.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:t=>{for(const[e,n]of qn(t))n.typeName.match(/^(user|user_presence)$/)&&delete t[e]}},{id:ch.RemoveUserDocument,scope:"store",up:t=>{for(const[e,n]of qn(t))n.typeName.match("user_document")&&delete t[e]}}]}),LY={arrow:{migrations:cA,props:lA},bookmark:{migrations:mA,props:gA},draw:{migrations:vA,props:SA},embed:{migrations:wA,props:xA},frame:{migrations:PA,props:bA},geo:{migrations:_A,props:CA},group:{migrations:EA,props:IA},highlight:{migrations:TA,props:kA},image:{migrations:AA,props:MA},line:{migrations:OA,props:jA},note:{migrations:RA,props:DA},text:{migrations:$A,props:LA},video:{migrations:NA,props:FA}},$Y={arrow:{migrations:dA,props:uA}};function FY({shapes:t=LY,bindings:e=$Y,migrations:n}={}){const r=new Map;for(const a of ut(t))for(const l of rA(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=GV(t),s=HV(e),i=sY(r);return Vw.create({asset:Ks,binding:s,camera:_o,document:t1,instance:i,instance_page_state:qr,page:yr,instance_presence:fY,pointer:e1,shape:o},{migrations:[RY,TY,XV,mY,iY,lY,rY,pY,dY,WV,bY,CY,IY,...R_("shape",t),...R_("binding",e),...n??[]],onValidationFailure:SY,createIntegrityChecker:xY})}const Nu=[{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 NY(){const t=typeof window<"u"?window.navigator.languages??["en"]:["en"];return zY(t)}function zY(t){for(const e of t){const n=BY(e);if(n)return n}return"en"}const H_={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function BY(t){const e=Nu.find(o=>o.locale===t.toLowerCase());if(e)return e.locale;const[n,r]=t.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Nu.find(s=>s.locale===n);if(o)return o.locale}return n in H_?H_[n]:null}Pi("@tldraw/tlschema","3.4.1","esm");var zA={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})()})(zA);var UY=zA.exports;const le=vi(UY),BA="3.4.1",K_={major:"2024-09-13T14:36:29.063Z",minor:"2024-10-24T14:44:00.648Z",patch:"2024-11-04T14:53:50.127Z"},HY={error:null};class n1 extends w.Component{constructor(){super(...arguments);E(this,"state",HY)}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 zu({children:t,fallback:e,...n}){return e===null?t:d.jsx(n1,{fallback:e,...n,children:t})}function r1(t,e){return Ag(`${t}_${e}`)}function ql(t){return Ag(`${w.useId()}${t??""}`)}function to(t){const e=Nn(w.useContext(UA));return Ag(`${e}_${t}`)}function Ag(t){return t.replace(/:/g,"_")}const UA=w.createContext(null);function KY({children:t}){const e=ql();return d.jsx(UA.Provider,{value:e,children:t})}const o1=w.createContext(null);function z(){const t=Te.useContext(o1);if(!t)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return t}function s1(){return Te.useContext(o1)}function i1({editor:t,children:e}){return d.jsx(o1.Provider,{value:t,children:d.jsx(KY,{children:e})})}function WY(){return d.jsx("div",{className:"tl-background"})}function Zl(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(rs(e.x),rs(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-GY(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 GY=t=>t<.5?2*t*t:-1+(4-2*t)*t;function je(t){return`${N(t.x)},${N(t.y)} `}function zn(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,VY=Math.sin;function Bt(t,e,n){return Math.max(e,typeof n<"u"?Math.min(t,n):t)}function uh(t,e=1e10){return t?Math.round(t*e)/e:0}function ai(t,e,n=1e-6){return Math.abs(t-e)<=n}function HA(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 li(t){return t=t%Ne,t<0?t=t+Ne:t===0&&(t=0),t}function ld(t,e){return t=li(t),e=li(e),t>e&&(e+=Ne),e-t}function KA(t,e){return Ne-ld(t,e)}function op(t,e){const n=(e-t)%Ne;return 2*n%Ne-n}function px(t){return(Ne+t)%Ne}function Mf(t,e){const n=Ne/e;let r=Math.floor((px(t)+n/2)/n)*n%Ne;return r<De&&(r+=Ne),r>De&&(r-=Ne),r}function WA(t,e){return t===e||ai(t%(Math.PI/2)-e%(Math.PI/2),0)}function YY(t){return t*De/180}function XY(t){return t*180/De}function la(t,e,n){return new x(t.x,t.y).add(x.FromAngle(n,e))}function Ry(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 m=0;m<n;m++){const g=Ne/n,v=-Ze+m*g,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 m=0;m<s.length;m++){const g=s[m];g.x=(g.x-i)/u*t,g.y=(g.y-l)/h*e}return s}function kc(t,e,n,r){return t<r&&n<e}function Wr(t,e,n,r){const o=Math.max(t,n),s=Math.min(e,r);return o<=s?[o,s]:null}function W_(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&&W_(r,o,t)>0&&(n+=1):o.y<=t.y&&W_(r,o,t)<0&&(n-=1)}return n!==0}function N(t){return Math.round(t*1e4)/1e4}function rs(t){return Math.round(t*100)/100}const G_=t=>Math.abs(t)<Number.MAX_SAFE_INTEGER;function Ws(t,e,n){return n<0?ld(t,e):KA(t,e)}function fx(t,e,n,r){let o;if(Math.abs(t)>De){o=op(e,r);const s=op(r,n);return Math.abs(o)<Math.abs(s)?o/t:(t-s)/t}else{o=op(e,r);const s=o/t;return Math.sign(o)!==Math.sign(t)?Math.abs(s)>.5?1:0:s}}function qY(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 a1(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 ZY(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=ld(i,a);for(let c=0;c<o;c++){const u=c/(o-1),h=i+l*u,p=la(n,r,h);s.push(p)}return s}const Ly=({brush:t,color:e,opacity:n,className:r})=>{const o=w.useRef(null);Zl(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 V_={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},$y={duration:0,easing:Dt.easeInOutCubic},Y_={CAMERA_MOVE:-10},QY=["top","right","bottom","left"],X_=0,l1=2,dh=1,q_=5,JY=128;var Fy={};const eX={},GA=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;Mo("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 tX({name:t,defaults:e,shouldStoreForSession:n})}function tX(t){const e=rX(t),n=t.shouldStoreForSession?nX(t.name):null,r=Et(`debug:${t.name}`,n??e);return typeof window<"u"&&(t.shouldStoreForSession&&Mo(`debug:${t.name}`,()=>{const o=r.get();o===e?BT(`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 nX(t){try{return JSON.parse(zT(`tldraw_debug:${t}`)??"null")}catch{return null}}function Ny(t){try{return t()}catch{return null}}function rX(t){switch(Ny(()=>Fy.TLDRAW_ENV)??Ny(()=>Fy.VERCEL_PUBLIC_TLDRAW_ENV)??Ny(()=>Fy.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 Af(t){if(t instanceof HTMLElement)return t;if(t.parentElement)return Af(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 cd(t,e){if(t.setPointerCapture(e.pointerId),bt.logPointerCaptures.get()){const n=GA.get();n.set(t,(n.get(t)??0)+1),console.warn("setPointerCapture called on element:",t,e)}}function ud(t,e){if(t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),bt.logPointerCaptures.get())){const n=GA.get();n.get(t)===1?n.delete(t):n.has(t)?n.set(t,n.get(t)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",t,e)}}const _t=t=>t.stopPropagation(),rn=(t,e,n)=>{t&&t.style.setProperty(e,n)},un=t=>Ge.isDarwin?t.metaKey:t.ctrlKey||t.metaKey;function Wn(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 c1(){const t=z();return w.useMemo(function(){let r,o;function s(g){if(!g.isKilled){if(g.button===l1){t.dispatch({type:"pointer",target:"canvas",name:"right_click",...Wn(g)});return}g.button!==0&&g.button!==1&&g.button!==5||(cd(g.currentTarget,g),t.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Wn(g)}))}}function i(g){g.isKilled||g.clientX===r&&g.clientY===o||(r=g.clientX,o=g.clientY,t.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...Wn(g)}))}function a(g){g.isKilled||g.button!==0&&g.button!==1&&g.button!==2&&g.button!==5||(r=g.clientX,o=g.clientY,ud(g.currentTarget,g),t.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Wn(g)}))}function l(g){if(g.isKilled||t.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const v=g.pointerType==="mouse"||g.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!0:null})}function c(g){if(g.isKilled||t.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const v=g.pointerType==="mouse"||g.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!1:null})}function u(g){g.isKilled=!0,xe(g)}function h(g){g.isKilled=!0,g.target instanceof HTMLElement&&g.target.tagName!=="A"&&g.target.tagName!=="TEXTAREA"&&!(t.getEditingShape()&&g.target.className.includes("tl-text-content"))&&xe(g)}function p(g){xe(g)}async function f(g){var S,y;if(xe(g),_t(g),!((y=(S=g.dataTransfer)==null?void 0:S.files)!=null&&y.length))return;const v=Array.from(g.dataTransfer.files);await t.putExternalContent({type:"files",files:v,point:t.screenToPage({x:g.clientX,y:g.clientY}),ignoreParent:!1})}function m(g){_t(g)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:h,onClick:m}},[t])}function oX(){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 VA=w.createContext(null);function sX({container:t,children:e}){return d.jsx(VA.Provider,{value:t,children:e})}function Mt(){return Nn(w.useContext(VA),"useContainer used outside of <Tldraw />")}function iX(){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),_t(o);const s=e.querySelector(".tl-canvas");if(!s)return;const i=new DragEvent(o.type,o);i.isSpecialRedispatchedEvent=!0,s.dispatchEvent(i)}return e.addEventListener("dragover",r),e.addEventListener("drop",r),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",r)}},[e]),w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=l=>{l.type==="change"&&o()};i.addEventListener?i.addEventListener("change",o):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",o):i.removeListener&&i.removeListener(a)},t.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{r==null||r()}},[t]),w.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(t.isIn("zoom")||!t.getPath().endsWith(".idle"))&&!hh(t)&&xe(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){xe(a);return}break}case"Tab":{if(hh(t))return;break}case",":return;case"Escape":{if((t.getEditingShape()||t.getSelectedShapeIds().length>0)&&xe(a),t.menus.getOpenMenus().length>0)return;t.inputs.keys.has("Escape")||(t.inputs.keys.add("Escape"),t.cancel(),e.focus());return}default:if(hh(t))return}const l={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,metaKey:a.metaKey,accelKey:un(a)};t.dispatch(l)},o=a=>{if(a.isKilled||(a.isKilled=!0,hh(t))||a.key===",")return;const l={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,metaKey:a.metaKey,accelKey:un(a)};t.dispatch(l)};function s(a){var l,c;if(e.contains(a.target)){const u=a.touches[0].pageX,h=a.touches[0].radiusX||0;(u-h<10||u+h>t.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),xe(a))}}const i=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&xe(a)};return e.addEventListener("touchstart",s,{passive:!1}),e.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",xe),document.addEventListener("gesturechange",xe),document.addEventListener("gestureend",xe),e.addEventListener("keydown",r),e.addEventListener("keyup",o),()=>{e.removeEventListener("touchstart",s),e.removeEventListener("wheel",i),document.removeEventListener("gesturestart",xe),document.removeEventListener("gesturechange",xe),document.removeEventListener("gestureend",xe),e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}},[t,e,n])}const aX=["input","select","button","textarea"];function hh(t){const{activeElement:e}=document;return t.menus.hasOpenMenus()||e&&(e.getAttribute("contenteditable")||aX.indexOf(e.tagName.toLowerCase())>-1)}const lX=["textarea","input"];function cX(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(lX.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 uX(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 Z_(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function Q_(t,e,n,r=.15){return r===0?uX(t,e,n):t<e?-Z_(e-t,n-e,r)+e:t>n?+Z_(t-n,n-e,r)+n:t}function dX(t,[e,n],[r,o]){const[[s,i],[a,l]]=t;return[Q_(e,s,i,r),Q_(n,a,l,o)]}function hX(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 pX(t){var e=hX(t,"string");return typeof e=="symbol"?e:String(e)}function sn(t,e,n){return e=pX(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function J_(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?J_(Object(n),!0).forEach(function(r){sn(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):J_(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const YA={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 eI(t){return t?t[0].toUpperCase()+t.slice(1):""}const fX=["enter","leave"];function gX(t=!1,e){return t&&!fX.includes(e)}function mX(t,e="",n=!1){const r=YA[t],o=r&&r[e]||e;return"on"+eI(t)+eI(o)+(gX(n,o)?"Capture":"")}const yX=["gotpointercapture","lostpointercapture"];function SX(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=yX.includes(e)?"capturecapture":"capture",o=!!~e.indexOf(r);return o&&(e=e.replace("capture","")),{device:e,capture:o,passive:n}}function vX(t,e=""){const n=YA[t],r=n&&n[e]||e;return t+r}function XA(t){return"touches"in t}function xX(t){return XA(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function wX(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 gx(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 bX(t){return wX(t).map(e=>e.identifier)}function tI(t,e){const[n,r]=Array.from(t.touches).filter(o=>e.includes(o.identifier));return gx(n,r)}const nI=40,rI=800;function qA(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=nI,n*=nI):r===2&&(e*=rI,n*=rI),[e,n]}function PX(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 jf(t,...e){return typeof t=="function"?t(...e):t}function CX(){}function _X(...t){return t.length===0?CX:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function oI(t,e){return Object.assign({},e,t||{})}const IX=32;class ZA{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?jf(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,PX(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,m=n._active&&!n._blocked||n.active;m&&(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=jf(r.bounds,n)),this.setup&&this.setup()),n.movement=p,this.computeOffset()));const[g,v]=n.offset,[[S,y],[P,b]]=n._bounds;n.overflow=[g<S?-1:g>y?1:0,v<P?-1:v>b?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=dX(n._bounds,n.offset,C),n.delta=Vt.sub(n.offset,f),this.computeMovement(),m&&(!n.last||s>IX)){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 EX([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 kX extends ZA{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[xX(e)]:r.axisThreshold;n.axis=EX(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 TX=t=>t,sI=.15,QA={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[sI,sI];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||TX},threshold(t){return Vt.toVector(t,0)}},MX=0,dd=ht(ht({},QA),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=MX){return t},bounds(t={}){if(typeof t=="function")return s=>dd.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]]}}),hd=typeof window<"u"&&window.document&&window.document.createElement;function JA(){return hd&&"ontouchstart"in window}function AX(){return JA()||hd&&window.navigator.maxTouchPoints>1}function jX(){return hd&&"onpointerdown"in window}function OX(){return hd&&"exitPointerLock"in window.document}function DX(){try{return"constructor"in GestureEvent}catch{return!1}}const Mr={isBrowser:hd,gesture:DX(),touch:JA(),touchscreen:AX(),pointer:jX(),pointerLock:OX()},RX=250,LX=180,$X=.5,FX=50,NX=250,zX=10,iI={mouse:0,touch:0,pen:8};ht(ht({},dd),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&Mr.pointerLock,Mr.touch&&n?"touch":this.pointerLock?"mouse":Mr.pointer&&!o?"pointer":Mr.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?RX:void 0,!(!Mr.touchscreen||n===!1))return t||(n!==void 0?"y":void 0)},pointerCapture(t,e,{pointer:{capture:n=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&n},threshold(t,e,{filterTaps:n=!1,tapsThreshold:r=3,axis:o=void 0}){const s=Vt.toVector(t,n?r:o?1:0);return this.filterTaps=n,this.tapsThreshold=r,s},swipe({velocity:t=$X,distance:e=FX,duration:n=NX}={}){return{velocity:this.transform(Vt.toVector(t)),distance:this.transform(Vt.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return LX;case!1:return 0;default:return t}},axisThreshold(t){return t?ht(ht({},iI),t):iI},keyboardDisplacement(t=zX){return t}});function ej(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 BX=30,UX=100;class HX extends ZA{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)*BX-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=tI(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=gx(...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=tI(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=gx(...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=[-qA(e)[1]/UX*r.offset[0],0],Vt.addTo(r._movement,r._delta),ej(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 KX=ht(ht({},QA),{},{device(t,e,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!Mr.touch&&Mr.gesture)return"gesture";if(Mr.touch&&r)return"touch";if(Mr.touchscreen){if(Mr.pointer)return"pointer";if(Mr.touch)return"touch"}},bounds(t,e,{scaleBounds:n={},angleBounds:r={}}){const o=i=>{const a=oI(jf(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=oI(jf(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({},dd),{},{mouseOnly:(t=!0)=>t});class WX extends kX{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=qA(e),Vt.addTo(n._movement,n._delta),ej(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 GX=dd;ht(ht({},dd),{},{mouseOnly:(t=!0)=>t});const u1=new Map,mx=new Map;function VX(t){u1.set(t.key,t.engine),mx.set(t.key,t.resolver)}const YX={key:"pinch",engine:HX,resolver:KX},XX={key:"wheel",engine:WX,resolver:GX};function qX(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 ZX(t,e){if(t==null)return{};var n=qX(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 QX={target(t){if(t)return()=>"current"in t?t.current:t},enabled(t=!0){return t},window(t=Mr.isBrowser?window:void 0){return t},eventOptions({passive:t=!0,capture:e=!1}={}){return{passive:t,capture:e}},transform(t){return t}},JX=["target","eventOptions","window","enabled","transform"];function sp(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]=sp(t[r],o);break;case"boolean":o&&(n[r]=t[r]);break}return n}function eq(t,e,n={}){const r=t,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=ZX(r,JX);if(n.shared=sp({target:o,eventOptions:s,window:i,enabled:a,transform:l},QX),e){const u=mx.get(e);n[e]=sp(ht({shared:n.shared},c),u)}else for(const u in c){const h=mx.get(u);h&&(n[u]=sp(ht({shared:n.shared},c[u]),h))}return n}class tj{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=vX(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 tq{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 nq{constructor(e){sn(this,"gestures",new Set),sn(this,"_targetEventStore",new tj(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}}),rq(this,e)}setEventIds(e){if(XA(e))return this.touchIds=new Set(bX(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=eq(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=aI(r,a.eventOptions,!!o);if(a.enabled){const c=u1.get(i);new c(this,e,i).bind(l)}}const s=aI(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]=_X(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=SX(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function Ma(t,e){t.gestures.add(e),t.gestureEventStores[e]=new tj(t,e),t.gestureTimeoutStores[e]=new tq}function rq(t,e){e.drag&&Ma(t,"drag"),e.wheel&&Ma(t,"wheel"),e.scroll&&Ma(t,"scroll"),e.move&&Ma(t,"move"),e.pinch&&Ma(t,"pinch"),e.hover&&Ma(t,"hover")}const aI=(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:mX(r,o,u);n&&h&&(p+="Passive"),t[p]=t[p]||[],t[p].push(s)},oq=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function sq(t){const e={},n={},r=new Set;for(let o in t)oq.test(o)?(r.add(RegExp.lastMatch),n[o]=t[o]):e[o]=t[o];return[n,e,r]}function Aa(t,e,n,r,o,s){if(!t.has(n)||!u1.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 iq(t,e){const[n,r,o]=sq(t),s={};return Aa(o,n,"onDrag","drag",s,e),Aa(o,n,"onWheel","wheel",s,e),Aa(o,n,"onScroll","scroll",s,e),Aa(o,n,"onPinch","pinch",s,e),Aa(o,n,"onMove","move",s,e),Aa(o,n,"onHover","hover",s,e),{handlers:s,config:e,nativeHandlers:r}}function aq(t,e={},n,r){const o=Te.useMemo(()=>new nq(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 lq(t){return t.forEach(VX),function(n,r){const{handlers:o,nativeHandlers:s,config:i}=iq(n,r||{});return aq(o,i,void 0,s)}}const lI=10,cq=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function nj(t){let{deltaY:e,deltaX:n}=t,r=0;return t.ctrlKey||t.altKey||t.metaKey?r=(Math.abs(e)>lI?lI*Math.sign(e):e)/100:t.shiftKey&&!cq&&(n=e,e=0),{x:-n,y:-e,z:-r}}const uq=lq([XX,YX]);let ja;const dq=t=>ja===void 0?(ja=t,!1):t-ja>120&&t-ja<160?(ja=t,!0):(ja=t,!1);function hq(t){const e=z(),n=w.useMemo(()=>{let r="not sure";const o=({event:g})=>{if(!e.getInstanceState().isFocused||(r="not sure",dq(Date.now())))return;const v=e.getEditingShapeId();if(v){const P=e.getShape(v);if(P&&e.getShapeUtil(P).canScroll(P)){const C=e.getShapePageBounds(v);if(C!=null&&C.containsPoint(e.inputs.currentPagePoint))return}}xe(g),_t(g);const S=nj(g);if(S.x===0&&S.y===0)return;const y={type:"wheel",name:"wheel",delta:S,point:new x(g.clientX,g.clientY),shiftKey:g.shiftKey,altKey:g.altKey,ctrlKey:g.metaKey||g.ctrlKey,metaKey:g.metaKey,accelKey:un(g)};e.dispatch(y)};let s=1,i=1,a=1,l=0;const c=new x,u=new x,h=g=>{const v=t.current;r="not sure";const{event:S,origin:y,da:P}=g;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=P[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=g=>{if(g&&(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:g=>{const v=t.current,{event:S,origin:y,offset:P}=g;if(S instanceof WheelEvent||!(S.target===v||v!=null&&v.contains(S.target)))return;const b=P[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:y[0],y:y[1],z:b},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:g=>{const v=t.current,{event:S,origin:y,offset:P,da:b}=g;if(S instanceof WheelEvent||!(S.target===v||v!=null&&v.contains(S.target)))return;const C=g.type==="gesturechange"||g.type==="gestureend";l=b[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=P[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]);uq(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 zy(t,e,n){const r=t.getShape(e),o=t.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===n)}}function pq(t,e){const n=z();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Af(l.currentTarget);cd(c,l);const{shape:u,handle:h}=zy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...Wn(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}=zy(n,t,e);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...Wn(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Af(l.currentTarget);ud(c,l);const{shape:u,handle:h}=zy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...Wn(l)})}}},[n,t,e])}function fq(t){const e=z();w.useLayoutEffect(()=>{const n=mT(()=>{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=gq(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 gq=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=uh(this.x),this.y=uh(this.y),this.w=uh(this.w),this.h=uh(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),m=p<0,g=f<0;if(m){const v=u;u=l,l=v}if(g){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 m=(p-u)/(l-i),g=(f-h)/(c-a),v=m<0,S=g<0;if(s){const P=(l-i)/(c-a),b=Math.abs(p-u),C=Math.abs(f-h),I=b*(g<0?1:-1)*(1/P),k=C*(m<0?1:-1)*P,_=P<b/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 M=(u+p)/2,T=C*P;u=M-T/2,p=M+T/2;break}case"left":case"right":{const M=(h+f)/2,T=b/P;h=M-T/2,f=M+T/2;break}}}if(v){const P=p;p=u,u=P}if(S){const P=f;f=h,h=P}const y=new Z(u,h,Math.abs(p-u),Math.abs(f-h));return{box:y,scaleX:+(y.width/e.width*(m>0?1:-1)).toFixed(5),scaleY:+(y.height/e.height*(g>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 mq(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 yq(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 Sq(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 px(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:px(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 Ei{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 so extends Ei{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 vq(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 xq=$t(function({showStroke:e=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const o=z();vq(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),m=u.distanceToPoint(p,!0),g=Math.abs(m)*s,v=m<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(rj,{geometry:u})}),n&&S.map((y,P)=>d.jsx("circle",{cx:y.x,cy:y.y,r:2/s,fill:`hsl(${Ml(P,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${P}`)),r&&g<150&&d.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-g/150,stroke:v?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function rj({geometry:t}){return t instanceof so?d.jsx(d.Fragment,{children:[...t.children,...t.ignoredChildren].map((e,n)=>d.jsx(rj,{geometry:e},n))}):d.jsx("path",{d:t.toSimpleSvgPath()})}function oj(t){return S9(t)}function sj(){const t=z(),e=SV("userIds",()=>oj(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 jg(t){const e=z();return H(`latestPresence:${t}`,()=>e.getCollaborators().find(r=>r.userId===t),[e,t])??null}const wq=$t(function(){return sj().map(n=>d.jsx(bq,{collaboratorId:n},n))}),bq=$t(function({collaboratorId:e}){const n=z(),r=jg(e),o=Cq(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(Pq,{latestPresence:r})}),Pq=$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:m,userName:g,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:g!=="New User"?g: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(P=>d.jsx(o,{className:"tl-collaborator__scribble",scribble:P,color:S,zoom:l,opacity:P.color==="laser"?.5:.1},u+"_scribble_"+P.id))}):null,a&&m.filter(P=>!n.isShapeHidden(P)).map(P=>d.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:P,color:S,opacity:.5},u+"_"+P))]})});function cI(t,e){return e>t.options.collaboratorInactiveTimeoutMs?"inactive":e>t.options.collaboratorIdleTimeoutMs?"idle":"active"}function Cq(t,e){const n=w.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,o]=w.useState(()=>cI(t,Date.now()-n.current));return w.useEffect(()=>{const s=t.timers.setInterval(()=>{o(cI(t,Date.now()-n.current))},t.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[t]),e&&(n.current=e.lastActivityTimestamp),r}function _q(){const t=z(),e=H("is menu open",()=>t.menus.hasAnyOpenMenus(),[t]),[n,r]=w.useState(!1),o=e||n,s=c1(),i=w.useRef({isDown:!1,isDragging:!1,start:new x}),a=w.useCallback(u=>{u.button===0&&(r(!0),i.current={isDown:!0,isDragging:!1,start:new x(u.clientX,u.clientY)}),t.menus.clearOpenMenus()},[t]),l=w.useCallback(u=>{var h,p,f;if(i.current.isDown){if(i.current.isDragging){(h=s.onPointerMove)==null||h.call(s,u);return}if(x.Dist2(i.current.start,new x(u.clientX,u.clientY))>t.options.dragDistanceSquared){i.current={...i.current,isDown:!0,isDragging:!0};const{x:m,y:g}=i.current.start;(p=s.onPointerDown)==null||p.call(s,{...u,clientX:m,clientY:g,button:0}),(f=s.onPointerMove)==null||f.call(s,u)}}},[s,t]),c=w.useCallback(u=>{var h;(h=s.onPointerUp)==null||h.call(s,u),r(!1),i.current={isDown:!1,isDragging:!1,start:new x(u.clientX,u.clientY)}},[s]);return o&&d.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...s,onPointerDown:a,onPointerMove:l,onPointerUp:c})}const ij=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});ii("set shape stuff",()=>{const m=a.getShape(e);if(!m)return;const g=h.current,v=a.getShapeClipPath(e)??"none";v!==g.clipPath&&(rn(c.current,"clip-path",v),rn(u.current,"clip-path",v),g.clipPath=v);const S=a.getShapePageTransform(e),y=q.toCssString(S),P=a.getShapeGeometry(m).bounds;y!==g.transform&&(rn(c.current,"transform",y),rn(u.current,"transform",y),g.transform=y);const b=Math.max(P.width,1),C=Math.max(P.height,1);(b!==g.width||C!==g.height)&&(rn(c.current,"width",b+"px"),rn(c.current,"height",C+"px"),rn(u.current,"width",b+"px"),rn(u.current,"height",C+"px"),g.width=b,g.height=C)},[a]),ii("set opacity and z-index",()=>{const m=c.current,g=u.current;rn(m,"opacity",i),rn(g,"opacity",i),rn(m,"z-index",o),rn(g,"z-index",s)},[i,o,s]),ii("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(m=>a.annotateError(m,{origin:"shape",willCrashApp:!1}),[a]);if(!n)return null;const f="fill"in n.props&&n.props.fill!=="none";return d.jsxs(d.Fragment,{children:[r.backgroundComponent&&d.jsx("div",{ref:u,className:"tl-shape tl-shape-background","data-shape-type":n.type,"data-shape-id":n.id,draggable:!1,children:d.jsx(zu,{fallback:l,onError:p,children:d.jsx(lj,{shape:n,util:r})})}),d.jsx("div",{ref:c,className:"tl-shape","data-shape-type":n.type,"data-shape-is-filled":f,"data-shape-id":n.id,draggable:!1,children:d.jsx(zu,{fallback:l,onError:p,children:d.jsx(aj,{shape:n,util:r})})})]})}),aj=w.memo(function({shape:e,util:n}){return _g("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),lj=w.memo(function({shape:e,util:n}){return _g("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 Iq({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();fq(s),iX(),oX(),hq(s),cX(s);const c=w.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});ii("position layers",function(){const{x:y,y:P,z:b}=e.getCamera();if(c.current.allowTextOutline&&Ge.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&b<e.options.textShadowLod!==c.current.lodDisableTextOutline){const k=b<e.options.textShadowLod;l.style.setProperty("--tl-text-outline",k?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=k}const C=b>=1?Ml(b,[1,8],[.125,.5],!0):Ml(b,[.1,1],[-2,.125],!0),I=`scale(${N(b)}) translate(${N(y+C)}px,${N(P+C)}px)`;rn(i.current,"transform",I),rn(a.current,"transform",I)},[e,l]);const u=c1(),h=H("shapeSvgDefs",()=>{const S=new Map;for(const y of ut(e.shapeUtils)){if(!y)return;const P=y.getCanvasSvgDefs();for(const{key:b,component:C}of P)S.has(b)||S.set(b,d.jsx(C,{},b))}return[...S.values()]},[e]),p=H("debug_shapes",()=>bt.hideShapes.get(),[bt]),f=H("debug_svg",()=>bt.debugSvg.get(),[bt]),m=H("debug_geometry",()=>bt.debugGeometry.get(),[bt]),g=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":g,"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(zq,{}),d.jsx(Bq,{}),r&&d.jsx(r,{})]})}),n&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(n,{})}),d.jsx(kq,{}),d.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(Wq,{}),d.jsx(Kq,{}),p?null:f?d.jsx(Lq,{}):d.jsx(Fq,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:a,className:"tl-html-layer",children:[m?d.jsx(xq,{}):null,d.jsx(Oq,{}),d.jsx(Mq,{}),d.jsx(Tq,{}),d.jsx(Aq,{}),o&&d.jsx(o,{}),d.jsx(Nq,{}),d.jsx(jq,{}),d.jsx(Hq,{}),d.jsx(wq,{})]})}),d.jsx(Gq,{})]}),d.jsx(_q,{}),d.jsx(Eq,{})]})}function Eq(){const{InFrontOfTheCanvas:t}=ot();return t?d.jsx(t,{}):null}function kq(){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 Tq(){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 Mq(){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 Aq(){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 jq(){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 Oq(){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(Dq,{shapeId:e}):null}function Dq({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(Rq,{shapeId:t,handle:l,zoom:r,isCoarse:o},l.id))})})}function Rq({shapeId:t,handle:e,zoom:n,isCoarse:r}){const o=pq(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 Lq(){const t=z();return H("rendering shapes",()=>t.getRenderingShapes(),[t]).map(n=>d.jsxs(w.Fragment,{children:[d.jsx(ij,{...n}),d.jsx(Uq,{id:n.id,mode:"iframe"})]},n.id+"_fragment"))}function $q(){const t=z(),e=w.useRef(new Set);return ii("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 Fq(){const t=z(),e=H("rendering shapes",()=>t.getRenderingShapes(),[t]);return d.jsxs(d.Fragment,{children:[e.map(n=>d.jsx(ij,{...n},n.id+"_shape")),Ge.isSafari&&d.jsx($q,{})]})}function Nq(){const t=z(),{ShapeIndicator:e}=ot(),n=H("hinting shape ids",()=>pw(t.getHintingShapeIds()),[t]);return!n.length||!e?null:n.map(r=>d.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function zq(){return d.jsxs("g",{id:to("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 Bq(){const t=to("cursor_hint");return d.jsx("path",{id:t,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function Uq({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=Mo("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 Hq(){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 Kq(){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 Wq(){const{OnTheCanvas:t}=ot();return t?d.jsx(t,{}):null}function Gq(){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 Vq({className:t,zoom:e,point:n,color:r,viewport:o,opacity:s=1}){const i=w.useRef(null);Zl(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));const a=to("cursor_hint");return d.jsxs("svg",{ref:i,className:le("tl-overlays__item",t),children:[d.jsx("use",{href:`#${a}`,color:r,strokeWidth:3,stroke:"var(--color-background)"}),d.jsx("use",{href:`#${a}`,color:r,opacity:s})]})}const uI=w.memo(function({className:e,zoom:n,point:r,color:o,name:s,chatMessage:i}){const a=w.useRef(null);Zl(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n);const l=to("cursor");return r?d.jsxs("div",{ref:a,className:le("tl-overlays__item",e),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:`#${l}`,color:o})}),i?d.jsxs(d.Fragment,{children:[s&&d.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),d.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&d.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function Yq({x:t,y:e,z:n,size:r}){const o=ql("grid"),s=z(),{gridSteps:i}=s.options;return d.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[d.jsx("defs",{children:i.map(({min:a,mid:l,step:c},u)=>{const h=c*r*n,p=.5+t*n,f=.5+e*n,m=p>0?p%h:h+p%h,g=f>0?f%h:h+f%h,v=n<l?Ml(n,[a,l],[0,1]):1;return d.jsx("pattern",{id:r1(o,`${c}`),width:h,height:h,patternUnits:"userSpaceOnUse",children:d.jsx("circle",{className:"tl-grid-dot",cx:m,cy:g,r:1,opacity:v})},u)})}),i.map(({step:a},l)=>d.jsx("rect",{width:"100%",height:"100%",fill:`url(#${o}_${a})`},l))]})}function Xq({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=QY.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 qq=({children:t})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:t}),Zq=()=>{const{Spinner:t}=ot();return d.jsx(k1,{children:t?d.jsx(t,{}):null})};function d1(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+=zn(r,o);return e?`M${zn(t[0],t[1])}Q${je(t[1])}${zn(t[1],t[2])}T${s}${zn(t[n-1],t[0])}${zn(t[0],t[1])}Z`:`M${je(t[0])}Q${je(t[1])}${zn(t[1],t[2])}${t.length>3?"T":""}${s}L${je(t[n-1])}`}function dI({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:d1(t.points,!1),stroke:n??`var(--color-${t.color})`,fill:"none",strokeWidth:8/e,opacity:r??t.opacity})}):null}function cj({bounds:t,rotation:e}){const n=w.useRef(null);return Zl(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 Qq({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 Zl(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 Jq=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),eZ=({shape:t,util:e})=>_g("Indicator: "+t.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(t.id))),tZ=({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(zu,{fallback:r,onError:o=>t.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(eZ,{shape:n,util:t.getShapeUtil(n)},n.id)})},hI=w.memo(function({shapeId:e,className:n,color:r,hidden:o,opacity:s}){const i=z(),a=w.useRef(null);return ii("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(tZ,{editor:i,id:e})})})}),nZ=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),uj=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 rZ({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 oZ({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=Wr(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=Wr(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 sZ({className:t,line:e,zoom:n}){return d.jsx("svg",{className:le("tl-overlays__item",t),children:e.type==="points"?d.jsx(rZ,{...e,zoom:n}):e.type==="gaps"?d.jsx(oZ,{...e,zoom:n}):null})}function h1(){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 iZ=()=>null;function dj(t,e){const n=w.useRef(t);return e(t,n.current)?n.current:(n.current=t,t)}const aZ=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:w9(t,e));function Gs(t){return dj(t,aZ)}const lZ=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:ET(t,e));function Ql(t){return dj(t,lZ)}const hj=w.createContext(null);function cZ({overrides:t={},children:e}){const n=Ql(t),r=w.useMemo(()=>({Background:WY,SvgDefs:iZ,Brush:Ly,ZoomBrush:Ly,CollaboratorBrush:Ly,Cursor:uI,CollaboratorCursor:uI,CollaboratorHint:Vq,CollaboratorShapeIndicator:hI,Grid:Yq,Scribble:dI,SnapIndicator:sZ,Handles:qq,Handle:Xq,CollaboratorScribble:dI,ErrorFallback:fj,ShapeErrorFallback:Jq,ShapeIndicatorErrorFallback:nZ,Spinner:h1,SelectionBackground:cj,SelectionForeground:Qq,ShapeIndicators:uj,ShapeIndicator:hI,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:Iq,LoadingScreen:Zq,...n}),[n]);return d.jsx(hj.Provider,{value:r,children:e})}function ot(){const t=w.useContext(hj);if(!t)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return t}const Og={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 pj(){Og.hardReset()}function uZ(){Og.refreshPage()}const dZ="https://github.com/tldraw/tldraw/issues/new",fj=({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,m]=w.useState(null);w.useLayoutEffect(()=>{var C;p!==null&&m(p);let P=(C=n.current)==null?void 0:C.parentElement,b=!1;for(;P;){if(P.classList.contains("tl-theme__dark")||P.classList.contains("tl-theme__light")){b=!0;break}P=P.parentElement}if(b){m(null);return}typeof window<"u"&&"matchMedia"in window&&m(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),w.useEffect(()=>{if(s){const P=e==null?void 0:e.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(P)}},[s,e]);const g=()=>{const P=document.createElement("textarea");P.value=h??u,document.body.appendChild(P),P.select(),document.execCommand("copy"),P.remove(),i(!0)},v=()=>{uZ()},S=async()=>{pj()},y=new URL(dZ);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(n1,{onError:Ou,fallback:()=>null,children:d.jsx(i1,{editor:e,children:d.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?d.jsx(c,{}):null})})}),d.jsx("div",{className:le("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Are you sure?"}),d.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),d.jsx("button",{className:"tl-error-boundary__reset",onClick: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:g,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"})]})]})]})})]})},gj="TLDRAW_USER_DATA_v3",mj=Pe({id:me,name:me.nullable().optional(),color:me.nullable().optional(),locale:me.nullable().optional(),animationSpeed:fe.nullable().optional(),edgeScrollSpeed:fe.nullable().optional(),colorScheme:Tg("light","dark","system").optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional(),isDynamicSizeMode:we.nullable().optional(),isPasteAtCursorMode:we.nullable().optional()}),Qo={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},p1=Math.max(...Object.values(Qo));function hZ(t){t.version<Qo.AddAnimationSpeed&&(t.user.animationSpeed=1),t.version<Qo.AddIsSnapMode&&(t.user.isSnapMode=!1),t.version<Qo.MakeFieldsNullable,t.version<Qo.AddEdgeScrollSpeed&&(t.user.edgeScrollSpeed=1),t.version<Qo.AddExcalidrawSelectMode&&(t.user.isWrapMode=!1),t.version<Qo.AllowSystemColorScheme&&(t.user.isDarkMode===!0?t.user.colorScheme="dark":t.user.isDarkMode===!1&&(t.user.colorScheme="light"),delete t.user.isDarkMode),t.version<Qo.AddDynamicSizeMode&&(t.user.isDynamicSizeMode=!1),t.version<Qo.AddPasteAtCursor&&(t.user.isPasteAtCursorMode=!1),t.version=p1}const yx=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function yj(){return yx[Math.floor(Math.random()*yx.length)]}function pZ(){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 qo=Object.freeze({name:"New User",locale:NY(),color:yj(),edgeScrollSpeed:1,animationSpeed:pZ()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"system"});function By(){return{id:ze(),color:yj()}}function Sj(t){if(t===null||typeof t!="object"||!("version"in t)||!("user"in t)||typeof t.version!="number")return By();const e=nt(t);hZ(e);try{return mj.validate(e.user)}catch{return By()}}function fZ(){const t=JSON.parse(xw(gj)||"null")??null;return Sj(t)}const Dg=Et("globalUserData",null);function gZ(){ww(gj,JSON.stringify({version:p1,user:Dg.get()}))}function vj(t){mj.validate(t),Dg.set(t),gZ(),yZ()}const mZ=typeof process<"u"&&!1,yl=typeof BroadcastChannel<"u"&&!mZ?new BroadcastChannel("tldraw-user-sync"):null;yl==null||yl.addEventListener("message",t=>{const e=t.data;(e==null?void 0:e.type)===wj&&(e==null?void 0:e.origin)!==xj()&&Dg.set(Sj(e.data))});let Uy=null;function xj(){return Uy===null&&(Uy=ze()),Uy}const wj="tldraw-user-preferences-change";function yZ(){yl==null||yl.postMessage({type:wj,origin:xj(),data:{user:bj(),version:p1}})}function bj(){let t=Dg.get();return t||(t=fZ(),vj(t)),t}const SZ=W("defaultLocalStorageUserPrefs",()=>bj());function Pj(t={}){return{userPreferences:t.userPreferences??SZ,setUserPreferences:t.setUserPreferences??vj}}var Cj={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function o(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function s(l,c,u,h,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new o(u,h||l,p),m=n?n+c:c;return l._events[m]?l._events[m].fn?l._events[m]=[l._events[m],f]:l._events[m].push(f):(l._events[m]=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,m=new Array(f);p<f;p++)m[p]=h[p].fn;return m},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,m){var g=n?n+c:c;if(!this._events[g])return!1;var v=this._events[g],S=arguments.length,y,P;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,m),!0}for(P=1,y=new Array(S-1);P<S;P++)y[P-1]=arguments[P];v.fn.apply(v.context,y)}else{var b=v.length,C;for(P=0;P<b;P++)switch(v[P].once&&this.removeListener(c,v[P].fn,void 0,!0),S){case 1:v[P].fn.call(v[P].context);break;case 2:v[P].fn.call(v[P].context,u);break;case 3:v[P].fn.call(v[P].context,u,h);break;case 4:v[P].fn.call(v[P].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[P].fn.apply(v[P].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 m=this._events[f];if(m.fn)m.fn===u&&(!p||m.once)&&(!h||m.context===h)&&i(this,f);else{for(var g=0,v=[],S=m.length;g<S;g++)(m[g].fn!==u||p&&!m[g].once||h&&m[g].context!==h)&&v.push(m[g]);v.length?this._events[f]=v.length===1?v[0]:v:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=n?n+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a})(Cj);var vZ=Cj.exports;const xZ=vi(vZ),Sl="TLDRAW_TAB_ID_v2",ds=globalThis.window;function wZ(){return ds?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(ds.navigator.platform)||Ge.isDarwin&&"ontouchend"in document:!1}const Of=ds?ds[Sl]??zT(Sl)??"TLDRAW_INSTANCE_STATE_V1_"+ze():"<error>";ds&&(ds[Sl]=Of,wZ()?bw(Sl,Of):BT(Sl));ds==null||ds.addEventListener("beforeunload",()=>{bw(Sl,Of)});const _j={Initial:0},Rg=Math.max(...Object.values(_j));function bZ(t){t.version<_j.Initial,t.version=Rg}const Ij=Pe({version:fe,currentPageId:Fu.optional(),isFocusMode:we.optional(),exportBackground:we.optional(),isDebugMode:we.optional(),isToolLocked:we.optional(),isGridMode:we.optional(),pageStates:Wt(Pe({pageId:Fu,camera:Pe({x:fe,y:fe,z:fe}).optional(),selectedShapeIds:Wt(Ir).optional(),focusedGroupId:Ir.nullable().optional()})).optional()});function PZ(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!==Rg&&(t=nt(t),bZ(t));try{return Ij.validate(t)}catch(e){return console.warn(e),null}}function f1(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:Rg,currentPageId:n.currentPageId,exportBackground:n.exportBackground,isFocusMode:n.isFocusMode,isDebugMode:n.isDebugMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,pageStates:r.map(o=>{const s=t.get(qr.createId(o)),i=t.get(_o.createId(o));return{pageId:o,camera:{x:(i==null?void 0:i.x)??0,y:(i==null?void 0:i.y)??0,z:(i==null?void 0:i.z)??1},selectedShapeIds:(s==null?void 0:s.selectedShapeIds)??[],focusedGroupId:(s==null?void 0:s.focusedGroupId)??null}})}},{isEqual:QM})}function Sx(t,e,n){const r=PZ(e);if(!r)return;const o=fA(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=_o.createId(h.pageId),f=qr.createId(h.pageId),m=t.get(p),g=t.get(f);t.put([_o.create({id:p,x:((l=h.camera)==null?void 0:l.x)??(m==null?void 0:m.x),y:((c=h.camera)==null?void 0:c.y)??(m==null?void 0:m.y),z:((u=h.camera)==null?void 0:u.z)??(m==null?void 0:m.z)}),qr.create({id:f,pageId:h.pageId,selectedShapeIds:h.selectedShapeIds??(g==null?void 0:g.selectedShapeIds),focusedGroupId:h.focusedGroupId??(g==null?void 0:g.focusedGroupId)})])}t.put([a]),t.ensureStoreIsUsable()})}function CZ(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:Rg,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 Ij.validate(r),r}catch{return null}}function Ej(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:iu(i.value,(a,{typeName:l})=>t.scopedTypes.document.has(l))}}else r=e;const o=fA(t.get(wn)),s=kj.get(t,f1).get();t.atomic(()=>{r.document&&t.loadStoreSnapshot(r.document),o&&t.update(wn,i=>({...i,...o})),s&&Sx(t,s),r.session&&Sx(t,r.session,{forceOverwrite:n==null?void 0:n.forceOverwriteSessionState})})}const kj=new Oo;function _Z(t){const n=kj.get(t,f1).get();if(!n)throw new Error("Session state is not ready yet");return{document:t.getStoreSnapshot(),session:n}}function Tj(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 fi({children:t,className:e="",...n}){return d.jsx("svg",{...n,className:le("tl-svg-container",e),children:t})}function g1(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,m=h/p;if(0<=f&&f<=1&&0<=m&&m<=1)return x.AddXY(t,f*l,f*c)}return null}function pd(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 IZ(t,e,n){const r=[];let o;for(let s=0,i=n.length-1;s<i;s++)o=g1(t,e,n[s],n[s+1]),o&&r.push(o);return r.length===0?null:r}function m1(t,e,n){const r=[];let o;for(let s=1,i=n.length;s<i+1;s++)o=g1(t,e,n[s-1],n[s%n.length]),o&&r.push(o);return r.length===0?null:r}function EZ(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 vx(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=pd(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function pI(t,e,n){const r=[];let o,s,i;for(let a=1,l=n.length;a<l;a++)o=n[a-1],s=n[a],i=pd(o,s,t,e),i&&r.push(...i);return r.length===0?null:r}function ph(t,e,n){return(n.y-t.y)*(e.x-t.x)>(e.y-t.y)*(n.x-t.x)}function y1(t,e,n,r){return ph(t,n,r)!==ph(e,n,r)&&ph(t,e,n)!==ph(t,e,r)}function fI(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=Hy(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=Hy(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=g1(r,o,s,i);if(h!==null){const p=Hy(h);n.has(p)||n.set(p,h)}}}return n.size===0?null:kZ([...n.values()])}function Hy(t){return`${t.x},${t.y}`}function kZ(t){const e=x.Average(t);return t.sort((n,r)=>x.Angle(e,n)-x.Angle(e,r))}function Mj(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],y1(n,r,o,s))return!0}return!1}function TZ(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],y1(n,r,o,s))return!0}return!1}class is extends Ei{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 y1(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 Jl extends Ei{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 is({start:s,end:i}))}this.isClosed&&this._segments.push(new is({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 Jl{constructor(e){super({...e}),this.isClosed=!0}}class vs 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 no{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(no,"props"),E(no,"migrations"),E(no,"type");function Xr(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,m=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,m+=u/2):s==="skip"&&(t-=u,m-=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?(m=u/2,f=(t-h*u)/h):f=(t-h*u)/Math.max(1,h-1)),{strokeDasharray:[u,f].join(" "),strokeDashoffset:m.toString()}}function gI({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}=Xr(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 ip extends no{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const n=this.editor.getSortedChildIdsForParent(e.id);return n.length===0?new vs({width:1,height:1,isFilled:!1}):new so({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 Jl({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(fi,{children:d.jsx(gI,{className:"tl-group",bounds:i})})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx(gI,{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(ip,"type","group"),E(ip,"props",IA),E(ip,"migrations",EA);const Aj=[ip],MZ=new Set(Aj.map(t=>t.type));function jj(t){const e=[...Aj],n=new Set;for(const r of t){if(MZ.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 Oj(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 oo(o,e);return Le(a.ok),await t(a)}catch(a){return console.error(a),null}})();return n.set(o,i),i}}const Lg=Oj(async t=>await cs.blobToDataUrl(await t.blob())),AZ=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,jZ=/@font-face\s*{([^}]+)}/gi,Dj=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,OZ=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function DZ(t){return Array.from(t.matchAll(AZ),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function Rj(t,e){return Array.from(t.matchAll(jZ),n=>{const r=n[1],o=Array.from(r.matchAll(Dj),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(OZ),i=>(i[1]||i[2]||i[3]).toLowerCase()));return{fontFace:r,urls:o,fontFamilies:s}})}function RZ(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 Lj(t){return!(t.startsWith("-")||t.startsWith("animation")||t.startsWith("transition")||t==="cursor"||t==="pointer-events"||t==="user-select"||t==="touch-action")}function LZ(t,e){return{imports:DZ(t),fontFaces:Rj(t,e)}}function $Z(t){return Array.from(t.matchAll(Dj),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}const FZ=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 $j(t){return FZ.has(t)}var NZ=Object.create,Fj=Object.defineProperty,zZ=Object.getOwnPropertyDescriptor,BZ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Nj=t=>{throw TypeError(t)},zj=(t,e,n)=>e in t?Fj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,UZ=t=>[,,,NZ(null)],Bj=["class","method","getter","setter","accessor","field","value","get","set"],Uj=t=>t!==void 0&&typeof t!="function"?Nj("Function expected"):t,HZ=(t,e,n,r,o)=>({kind:Bj[t],name:e,metadata:r,addInitializer:s=>n._?Nj("Already initialized"):o.push(Uj(s||null))}),KZ=(t,e)=>zj(e,BZ("metadata"),t[3]),WZ=(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},GZ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=Bj[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,zZ(o,n)),S=r.length-1;S>=0;S--)l=HZ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,Uj(i)&&(v[m]=i);return v&&Fj(o,n,v),o},fh=(t,e,n)=>zj(t,typeof e!="symbol"?e+"":e,n),Hj,$g;Hj=[Hn];class S1{constructor(){WZ($g,5,this),fh(this,"fontFacesPromise",null),fh(this,"foundFontNames",new Set),fh(this,"fontFacesToEmbed",new Set),fh(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){Le(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=VZ()}onFontFamilyValue(e){Le(this.fontFacesPromise,"FontEmbedder not started");const n=RZ(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=Lg(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}}$g=UZ();GZ($g,1,"onFontFamilyValue",Hj,S1);KZ($g,S1);async function VZ(){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(Rj(r.cssText,e.href??document.baseURI)):r instanceof CSSImportRule&&t.push(xx(r.href));else e.href&&t.push(xx(e.href))}return ye(await Promise.all(t)).flat()}const xx=Oj(async t=>{const e=LZ(await t.text(),t.url),n=await Promise.all(e.imports.map(({url:r})=>xx(new URL(r,t.url).href)));return[...e.fontFaces,...ye(n).flat()]});function Kj(t){if(t.shadowRoot)return t.shadowRoot.childNodes;if(ZZ(t)){const e=t.assignedNodes();if(e!=null&&e.length)return e}return t.childNodes}function*wx(t){for(const e of Kj(t))YZ(e)&&(yield e)}function Fg(t){var e;return((e=t.ownerDocument)==null?void 0:e.defaultView)??globalThis}function YZ(t){return t instanceof Fg(t).Element}function XZ(t){return t instanceof Fg(t).ShadowRoot}function qZ(t){return"getRootNode"in t&&XZ(t.getRootNode())}function ZZ(t){return qZ(t)&&t instanceof Fg(t).HTMLSlotElement}function QZ(t){return t.style}function v1(t,e){return Fg(t).getComputedStyle(t,e)}const Zi={};class JZ{constructor(e){E(this,"styles",new Map);E(this,"fonts",new S1);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const n=Array.from(wx(e));for(;n.length;){const r=n.pop();n.push(...wx(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:n=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const o=n?rQ(e.tagName.toLowerCase()):Zi,s=r?((a=this.styles.get(e.parentElement))==null?void 0:a.self)??Zi:Zi,i={self:eQ(e,{defaultStyles:o,parentStyles:s}),before:mI(e,"::before"),after:mI(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=$Z(s);i.length!==0&&e.push(...i.map(async({url:a,original:l})=>{const c=await Lg(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 Kj(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 {${yI(r.before)}}
|
|
99
|
-
`),r.after&&(e+=`.${s}::after {${yI(r.after)}}
|
|
100
|
-
`)}const o=QZ(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(){nQ()}}function eQ(t,{defaultStyles:e,parentStyles:n}){return t.computedStyleMap?Wj(t.computedStyleMap(),{defaultStyles:e,parentStyles:n}):x1(v1(t),{defaultStyles:e,parentStyles:n})}function mI(t,e){const n=v1(t,e),r=n.getPropertyValue("content");if(!(r===""||r==="none"))return x1(n,{defaultStyles:Zi,parentStyles:Zi})}function Wj(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t.keys()){if(!Lj(o))continue;const s=t.get(o).toString();e[o]!==s&&(n[o]===s&&$j(o)||(r[o]=s))}return r}function x1(t,{defaultStyles:e,parentStyles:n}){const r={};for(const o of t){if(!Lj(o))continue;const s=t.getPropertyValue(o);e[o]!==s&&(n[o]===s&&$j(o)||(r[o]=s))}return r}function yI(t){let e="";for(const[n,r]of Object.entries(t))e+=`${n}: ${r};`;return e}let vl;const SI={};function tQ(){if(!vl){const t=document.createElement("iframe");t.style.display="none",document.body.appendChild(t);const e=Nn(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),vl={iframe:t,foreignObject:r,document:e}}return vl}function nQ(){vl&&(document.body.removeChild(vl.iframe),vl=void 0)}const vI={defaultStyles:Zi,parentStyles:Zi};function rQ(t){let e=SI[t];if(!e){const{foreignObject:n,document:r}=tQ(),o=r.createElement(t);n.appendChild(o),e=o.computedStyleMap?Wj(o.computedStyleMap(),vI):x1(v1(o),vI),n.removeChild(o),SI[t]=e}return e}function oQ(t,e){Array.from(t.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function xI(t,e){return t.replaceWith(e),e}async function cu(t,e){const n=document.createElement("img");e&&oQ(e,n),n.setAttribute("src",t??"data:"),n.setAttribute("decoding","sync"),n.setAttribute("loading","eager");try{await n.decode()}catch{}return n}async function sQ(t){try{const e=t.toDataURL();return await cu(e,t)}catch{return await cu(null,t)}}async function iQ(t){try{const e=await lr.getVideoFrameAsDataUrl(t);return cu(e,t)}catch(e){console.error("Could not get video frame",e)}if(t.poster){const e=await Lg(t.poster);return cu(e,t)}return cu(null,t)}async function Gj(t){if(t instanceof HTMLCanvasElement)return xI(t,await sQ(t));if(t instanceof HTMLVideoElement)return xI(t,await iQ(t));if(t instanceof HTMLImageElement){const e=t.currentSrc||t.src,n=await Lg(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(wx(t),e=>Gj(e)))}function Ng(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 w1=w.createContext(null);function aQ({context:t,editor:e,children:n}){return d.jsx(i1,{editor:e,children:d.jsx(w1.Provider,{value:t,children:n})})}function fd(){return w.useContext(w1)}function lQ(){const t=w.useContext(w1),[e]=w.useState(fw);return w.useEffect(()=>(t==null||t.waitUntil(e),()=>{e.resolve()}),[e,t]),Ng(()=>{e.resolve()})}var cQ=Object.create,Vj=Object.defineProperty,uQ=Object.getOwnPropertyDescriptor,dQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Yj=t=>{throw TypeError(t)},Xj=(t,e,n)=>e in t?Vj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,hQ=t=>[,,,cQ(null)],qj=["class","method","getter","setter","accessor","field","value","get","set"],Zj=t=>t!==void 0&&typeof t!="function"?Yj("Function expected"):t,pQ=(t,e,n,r,o)=>({kind:qj[t],name:e,metadata:r,addInitializer:s=>n._?Yj("Already initialized"):o.push(Zj(s||null))}),fQ=(t,e)=>Xj(e,dQ("metadata"),t[3]),gQ=(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},mQ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=qj[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,uQ(o,n)),S=r.length-1;S>=0;S--)l=pQ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,Zj(i)&&(v[m]=i);return v&&Vj(o,n,v),o},wI=(t,e,n)=>Xj(t,typeof e!="symbol"?e+"":e,n),Qj,zg;Qj=[Hn];class b1{constructor(e){this.maxDelayTimeMs=e,gQ(zg,5,this),wI(this,"isResolved",!1),wI(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 Bv(0)}async resolve(){const e=Bv(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}}zg=hQ();mQ(zg,1,"waitUntil",Qj,b1);fQ(zg,b1);function yQ(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:P})=>l.has(P));let u=null;if(n.bounds)u=n.bounds;else for(const{id:P}of c){const b=t.getShapeMaskedPageBounds(P);b&&(u?u.union(b):u=b.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 m=new b1(t.options.maxExportDelayMs),g=fw();return m.waitUntil(g),{jsx:d.jsx(SQ,{editor:t,preserveAspectRatio:i,scale:r,bbox:u,background:o,singleFrameShapeId:h,isDarkMode:a,renderingShapes:c,onMount:g.resolve,waitUntil:m.waitUntil}),width:p,height:f,exportDelay:m}}function SQ({editor:t,preserveAspectRatio:e,scale:n,bbox:r,background:o,singleFrameShapeId:s,isDarkMode:i,renderingShapes:a,onMount:l,waitUntil:c}){const u=ql(),h=Is({isDarkMode:i}),[p,f]=w.useState({}),m=Ng(P=>{eo(p,P.key)||c((async()=>{const b=await P.getElement();b&&hi.flushSync(()=>f(C=>({...C,[P.key]:b})))})())}),g=w.useMemo(()=>({isDarkMode:i,waitUntil:c,addExportDef:m}),[i,c,m]),[v,S]=w.useState(null),y=w.useRef(!1);return w.useLayoutEffect(()=>{if(y.current)throw new Error("SvgExport should only render once - do not use with react strict mode");y.current=!0,(async()=>{const P={},b=a.map(async({id:I,opacity:k,index:_,backgroundIndex:M})=>{var O,R;if(I===s)return[];const T=t.getShape(I);if(t.isShapeOfType(T,"group"))return[];const D=[],A=t.getShapeUtil(T);if(A.toSvg||A.toBackgroundSvg){const[B,L]=await Promise.all([(O=A.toSvg)==null?void 0:O.call(A,T,g),(R=A.toBackgroundSvg)==null?void 0:R.call(A,T,g)]),G=t.getShapePageTransform(T);let $=G.toCssString();"scale"in T.props&&T.props.scale!==1&&($=`${$} scale(${T.props.scale}, ${T.props.scale})`);const U=t.getShapeMask(T.id),Y=U?q.From(q.Inverse(G)).applyToPoints(U):null,ee=r1(u,T.id);Y&&(P[ee]=d.jsx("clipPath",{id:ee,children:d.jsx("path",{d:`M${Y.map(({x:he,y:ue})=>`${he},${ue}`).join("L")}Z`})})),B&&D.push({zIndex:_,element:d.jsx("g",{transform:$,opacity:k,clipPath:U?`url(#${ee})`:void 0,children:B},`fg_${T.id}`)}),L&&D.push({zIndex:M,element:d.jsx("g",{transform:$,opacity:k,clipPath:U?`url(#${ee})`:void 0,children:L},`bg_${T.id}`)})}else D.push({zIndex:_,element:d.jsx(bI,{shape:T,util:A,component:aj,className:"tl-shape",bbox:r,opacity:k},`fg_${T.id}`)}),A.backgroundComponent&&D.push({zIndex:M,element:d.jsx(bI,{shape:T,util:A,component:lj,className:"tl-shape tl-shape-background",bbox:r,opacity:k},`bg_${T.id}`)});return D}),C=(await Promise.all(b)).flat();hi.flushSync(()=>{S(C.sort((I,k)=>I.zIndex-k.zIndex).map(({element:I})=>I)),f(I=>({...I,...P}))})})()},[r,t,g,u,a,s]),w.useEffect(()=>{v!==null&&l()},[l,v]),d.jsx(aQ,{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?h.solid:h.background:"transparent"},"data-color-mode":i?"dark":"light",className:`tl-container tl-theme__force-sRGB ${i?"tl-theme__dark":"tl-theme__light"}`,children:[d.jsx("defs",{children:Object.entries(p).map(([P,b])=>d.jsx(w.Fragment,{children:b},P))}),v]})})}function bI({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(n1,{fallback:()=>null,children:d.jsx("foreignObject",{x:o.minX,y:o.minY,width:o.w,height:o.h,className:"tl-shape-foreign-object",children:d.jsx("div",{className:n,"data-shape-type":t.type,style:{clipPath:i.getShapeClipPath(t.id),transform:a.toCssString(),width:c,height:u,opacity:s},children:d.jsx(r,{shape:t,util:e})})})})}let vQ=1;async function xQ(t,e,n={}){const r=yQ(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=fT(s,{identifierPrefix:`export_${vQ++}_`});try{hi.flushSync(()=>{i.render(r.jsx)}),await r.exportDelay.resolve();const a=s.firstElementChild;return Le(a instanceof SVGSVGElement,"Expected an SVG element"),await wQ(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{i.unmount(),o.removeChild(s)},0)}}async function wQ(t){const e=[...t.querySelectorAll("foreignObject.tl-shape-foreign-object > *")];if(!e.length)return;const n=new JZ(t);try{n.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(s=>Gj(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 Gr={menus:Et("open menus",[]),getOpenMenus(t){return t?this.menus.get().filter(e=>e.endsWith("-"+t)):this.menus.get()},addOpenMenu(t,e=""){const n=e?`${t}-${e}`:t,r=new Set(this.menus.get());r.has(n)||(r.add(n),this.menus.set([...r]))},deleteOpenMenu(t,e=""){const n=e?`${t}-${e}`:t,r=new Set(this.menus.get());r.has(n)&&(r.delete(n),this.menus.set([...r]))},clearOpenMenus(t){this.menus.set(t?this.menus.get().filter(e=>!e.endsWith("-"+t)):[])},_hiddenMenus:[],hideOpenMenus(t){if(this._hiddenMenus=[...this.getOpenMenus(t)],this._hiddenMenus.length!==0)for(const e of this._hiddenMenus)this.deleteOpenMenu(e,t)},showOpenMenus(t){if(this._hiddenMenus.length!==0){for(const e of this._hiddenMenus)this.addOpenMenu(e,t);this._hiddenMenus=[]}},isMenuOpen(t,e){return this.getOpenMenus(e).includes(t)},hasOpenMenus(t){return this.getOpenMenus(t).length>0},hasAnyOpenMenus(){return this.getOpenMenus().length>0},forContext(t){return{getOpenMenus:()=>this.getOpenMenus(t),addOpenMenu:e=>this.addOpenMenu(e,t),deleteOpenMenu:e=>this.deleteOpenMenu(e,t),clearOpenMenus:()=>this.clearOpenMenus(t),isMenuOpen:e=>this.isMenuOpen(e,t),hasOpenMenus:()=>this.hasOpenMenus(t),hasAnyOpenMenus:()=>this.hasAnyOpenMenus()}}},bx=new o7,bQ={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 PI(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(!PI(o,e.get(r)))return!1;n.add(r)}for(const[r,o]of e)if(!n.has(r)&&!PI(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 Px 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 CQ(t,e,n){return oo(t).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:n})})}const _Q="https://cdn.tldraw.com";function Zs(){return`${_Q}/${BA}`}function IQ(t){switch(t.type){case"shapes":return`s${t.shapeIds.map(n=>Ky(n.slice(6))).join(".")}`;case"page":return"p"+Ky(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+="."+Ky(yr.parseId(n))),r}default:Ot(t)}}function EQ(t){switch(t[0]){case"s":return{type:"shapes",shapeIds:t.slice(1).split(".").filter(Boolean).map(r=>Ke(decodeURIComponent(r)))};case"p":return{type:"page",pageId:yr.createId(decodeURIComponent(t.slice(1)))};case"v":{const[n,r,o,s,i]=t.slice(1).split(".");return{type:"viewport",bounds:new Z(Number(n),Number(r),Number(o),Number(s)),pageId:i?yr.createId(decodeURIComponent(i)):void 0}}default:throw Error("Invalid deep link string")}}function Ky(t){return encodeURIComponent(t).replace(/\./g,"%2E")}function kQ(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 gh(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})=>TQ(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>MQ(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>AQ(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>jQ(s,i,o));break}}return o}function TQ(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=Al(o,s,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function MQ(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=Al(o,s,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function AQ(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;Al(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 jQ(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;Al((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 Jj({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 ap({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=li(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,m;const c=e.getShape(l.id);if(!c)return;const u=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const g=(p=u.onRotateStart)==null?void 0:p.call(u,l);g&&a.push(g)}const h=(f=u.onRotate)==null?void 0:f.call(u,l,c);if(h&&a.push(h),r==="end"||r==="one-off"){const g=(m=u.onRotateEnd)==null?void 0:m.call(u,l,c);g&&a.push(g)}}),a.length>0&&e.updateShapes(a)}const OQ=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(Xi(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 m=c.get(f.fromId),g=m==null?void 0:m.filter(y=>y.id!==f.id);g!=null&&g.length?c.set(f.fromId,g):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 m=c.get(f);return m?m===a.get(f)&&(m=m.slice(0),c.set(f,m)):(m=[],c.set(f,m)),m}function p(f){h(f.fromId).push(f),h(f.toId).push(f)}for(const f of l){for(const m of ut(f.added))p(m);for(const[m,g]of ut(f.updated))u(m),p(g);for(const m of ut(f.removed))u(m)}return c??a})};function DQ(t,e,n){const r=t.getShapeMaskedPageBounds(e);return r===void 0?!0:!n.includes(r)}const RQ=t=>{function e(n){const r=n.getCurrentPageShapeIds(),o=n.getViewportPageBounds(),s=new Set;return r.forEach(i=>{DQ(n,i,o)&&s.add(i)}),s}return W("getCulledShapes",n=>{if(Xi(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})},LQ=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(Xi(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))ol(f)&&(l(f.parentId),a[f.parentId].push(f.id),c.add(a[f.parentId]));for(const[f,m]of Object.values(u.updated))if(ol(m)&&ol(f)){if(f.parentId!==m.parentId)l(f.parentId),l(m.parentId),a[f.parentId].splice(a[f.parentId].indexOf(m.id),1),a[m.parentId].push(m.id),c.add(a[m.parentId]);else if(f.index!==m.index){l(m.parentId);const g=a[m.parentId].indexOf(m.id);a[m.parentId][g]=m.id,c.add(a[m.parentId])}}for(const f of Object.values(u.removed))ol(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})},Wy=(t,e,n)=>{for(;!Dn(n.parentId);){const r=t.get(n.parentId);if(!r)return!1;n=r}return n.parentId===e},$Q=(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=>Wy(t,s,t.get(i))))}return W("_shapeIdsInCurrentPage",(s,i)=>{if(Xi(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 np(s);for(const h of l){for(const p of Object.values(h.added))ol(p)&&Wy(t,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))ol(f)&&(Wy(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?Hc(u.value,u.diff):s})};var FQ=Object.create,eO=Object.defineProperty,NQ=Object.getOwnPropertyDescriptor,zQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),tO=t=>{throw TypeError(t)},nO=(t,e,n)=>e in t?eO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,BQ=t=>[,,,FQ(null)],rO=["class","method","getter","setter","accessor","field","value","get","set"],oO=t=>t!==void 0&&typeof t!="function"?tO("Function expected"):t,UQ=(t,e,n,r,o)=>({kind:rO[t],name:e,metadata:r,addInitializer:s=>n._?tO("Already initialized"):o.push(oO(s||null))}),HQ=(t,e)=>nO(e,zQ("metadata"),t[3]),KQ=(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},sO=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=rO[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,NQ(o,n)),S=r.length-1;S>=0;S--)l=UQ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,oO(i)&&(v[m]=i);return v&&eO(o,n,v),o},Oa=(t,e,n)=>nO(t,typeof e!="symbol"?e+"":e,n),iO,aO,gd;const WQ=40;aO=[Hn],iO=[Hn];class Bg{constructor(e){this.editor=e,KQ(gd,5,this),Oa(this,"_clickId",""),Oa(this,"_clickTimeout"),Oa(this,"_clickScreenPoint"),Oa(this,"_previousScreenPoint"),Oa(this,"_clickState","idle"),Oa(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)>WQ**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"}}gd=BQ();sO(gd,1,"_getClickTimeout",aO,Bg);sO(gd,1,"cancelDoubleClickTimeout",iO,Bg);HQ(gd,Bg);class GQ{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 VQ{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 Tc(t){return XQ}class YQ{constructor(){E(this,"length",0);E(this,"head",null);E(this,"tail",this)}push(e){return new P1(e,this)}toArray(){return us}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const XQ=new YQ;class P1{constructor(e,n){E(this,"length");this.head=e,this.tail=n,this.length=n.length+1}push(e){return new P1(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 qQ{constructor(e){E(this,"store");E(this,"dispose");E(this,"state","recording");E(this,"pendingDiff",new QQ);E(this,"stacks",Et("HistoryManager.stacks",{undos:Tc(),redos:Tc()},{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??Ou,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:Tc()}));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=ZQ[n.history]);try{if(this._isInBatch)return Ao(e),this;this._isInBatch=!0;try{Ao(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=ZM(a),c=lx(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":au(c,[lx(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=yf();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")au(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=yf();return au(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:n.push({type:"diff",diff:o}),redos:i})),this}_mark(e){Ao(()=>{this.flushPendingDiff(),this.stacks.update(({undos:n,redos:r})=>({undos:n.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:Tc(),redos:Tc()}),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 ZQ={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class QQ{constructor(){E(this,"diff",yf());E(this,"isEmptyAtom",Et("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=yf(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){au(this.diff,[e]),this.isEmptyAtom.set(ZM(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class JQ{constructor(e){E(this,"scribbleItems",new Map);E(this,"state","paused");this.editor=e}addScribble(e,n=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 eJ=Object.create,lO=Object.defineProperty,tJ=Object.getOwnPropertyDescriptor,nJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),cO=t=>{throw TypeError(t)},uO=(t,e,n)=>e in t?lO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,rJ=t=>[,,,eJ(null)],dO=["class","method","getter","setter","accessor","field","value","get","set"],hO=t=>t!==void 0&&typeof t!="function"?cO("Function expected"):t,oJ=(t,e,n,r,o)=>({kind:dO[t],name:e,metadata:r,addInitializer:s=>n._?cO("Already initialized"):o.push(hO(s||null))}),sJ=(t,e)=>uO(e,nJ("metadata"),t[3]),iJ=(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},Ug=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=dO[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,tJ(o,n)),S=r.length-1;S>=0;S--)l=oJ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,hO(i)&&(v[m]=i);return v&&lO(o,n,v),o},aJ=(t,e,n)=>uO(t,e+"",n),pO,fO,gO,mO,wa;const pe=t=>Math.round(t*10**8)/10**8;function Jo(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)&&Wr(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=Jo(t,l,n,r,Wr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function lJ(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}}}}mO=[W],gO=[W],fO=[W],pO=[W];class ec{constructor(e){this.manager=e,iJ(wa,5,this),aJ(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:Nn(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&&kc(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:Wr(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&&kc(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:Wr(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:P},b)=>({id:"selection:"+b,x:y+o.x,y:P+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 m=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),g=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...g,...m]),{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=yq(u)),c<0&&(u=mq(u)),s&&(a.center=e.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",f=CI(u,a),m=this.getSnappablePoints(),g=[],v=[],S=new x(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:g,nearestSnapsY:v,otherNodeSnapPoints:m,selectionSnapPoints:f});const y=new x(h?0:((k=g[0])==null?void 0:k.nudge)??0,p?0:((_=v[0])==null?void 0:_.nudge)??0);if(o&&Sq(u)&&y.len()!==0){const M=g.length&&v.length?Math.abs(y.x)<Math.abs(y.y)?"x":"y":g.length?"x":"y",T=e.aspectRatio;M==="x"?(v.length=0,y.y=y.x/T,(u==="bottom_left"||u==="top_right")&&(y.y=-y.y)):(g.length=0,y.x=y.y*T,(u==="bottom_left"||u==="top_right")&&(y.x=-y.x))}const P=x.Add(n,y),{box:b}=Z.Resize(e,r,s?P.x*2:P.x,s?P.y*2:P.y,o);s&&(b.center=e.center);const C=CI("any",b);g.length=0,v.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:g,nearestSnapsY:v,otherNodeSnapPoints:m,selectionSnapPoints:C});const I=this.getPointSnapLines({nearestSnapsX:g,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(!kc(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:b})=>b==="gap_center"),P=y&&Wr(a.breadthIntersection[0],a.breadthIntersection[1],y.gap.breadthIntersection[0],y.gap.breadthIntersection[1]);y&&y.gap.length>a.length&&P?r[r.indexOf(y)]=S:(!y||!P)&&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 m=a.endNode.pageBounds.maxX+a.length,g=e.minX,v=m-g;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(!kc(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:b})=>b==="gap_center"),P=y&&kc(y.gap.breadthIntersection[0],y.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);y&&y.gap.length>a.length&&P?o[o.indexOf(y)]=S:(!y||!P)&&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 m=a.endNode.pageBounds.maxY+a.length,g=e.minY,v=m-g;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:pw(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:m}}=l;switch(l.type){case"gap_center":{const g=(f-e.width)/2,v=Wr(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:ze(),gaps:[...Jo(s,h.id,g,"backward",v),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:m},...Jo(s,p.id,g,"forward",v)]});break}case"gap_duplicate":{const g=Wr(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:m},...Jo(s,p.id,f,"forward",g)]:[...Jo(s,h.id,f,"backward",g),{startEdge:u,endEdge:m},{startEdge:m.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:m}}=l;switch(l.type){case"gap_center":{const g=(f-e.height)/2,v=Wr(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:ze(),gaps:[...Jo(o,h.id,g,"backward",v),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:m},...Jo(o,l.gap.endNode.id,g,"forward",v)]});break}case"gap_duplicate":{const g=Wr(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:m},...Jo(o,p.id,f,"forward",g)]:[...Jo(o,h.id,f,"backward",g),{startEdge:u,endEdge:m},{startEdge:m.map(v=>v.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return lJ(a),a}}wa=rJ();Ug(wa,1,"getSnapPointsCache",mO,ec);Ug(wa,1,"getSnappablePoints",gO,ec);Ug(wa,1,"getSnappableGapNodes",fO,ec);Ug(wa,1,"getVisibleGaps",pO,ec);sJ(wa,ec);function CI(t,e){const{minX:n,maxX:r,minY:o,maxY:s}=e,i=[];switch(t){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:n,y:o})}switch(t){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:o})}switch(t){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:s})}switch(t){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:n,y:s})}return i}var cJ=Object.create,yO=Object.defineProperty,uJ=Object.getOwnPropertyDescriptor,dJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),SO=t=>{throw TypeError(t)},vO=(t,e,n)=>e in t?yO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,hJ=t=>[,,,cJ(null)],xO=["class","method","getter","setter","accessor","field","value","get","set"],wO=t=>t!==void 0&&typeof t!="function"?SO("Function expected"):t,pJ=(t,e,n,r,o)=>({kind:xO[t],name:e,metadata:r,addInitializer:s=>n._?SO("Already initialized"):o.push(wO(s||null))}),fJ=(t,e)=>vO(e,dJ("metadata"),t[3]),gJ=(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},mJ=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=xO[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,uJ(o,n)),S=r.length-1;S>=0;S--)l=pJ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,wO(i)&&(v[m]=i);return v&&yO(o,n,v),o},yJ=(t,e,n)=>vO(t,e+"",n),bO,Hg;const SJ=()=>null,vJ=()=>[];bO=[W];class C1{constructor(e){this.manager=e,gJ(Hg,5,this),yJ(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):SJ,s=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):vJ;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=Nn(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=Nn(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=Nn(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),f=u.nearestPoint(p),m=h.applyToPoint(f);x.DistMin(r,m,a)&&(a=x.Dist(r,m),l=m)}return l||null}snapHandle({currentShapeId:e,handle:n}){const o=Nn(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}}Hg=hJ();mJ(Hg,1,"getSnapGeometryCache",bO,C1);fJ(Hg,C1);var xJ=Object.create,PO=Object.defineProperty,wJ=Object.getOwnPropertyDescriptor,bJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),CO=t=>{throw TypeError(t)},_O=(t,e,n)=>e in t?PO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,PJ=t=>[,,,xJ(null)],IO=["class","method","getter","setter","accessor","field","value","get","set"],EO=t=>t!==void 0&&typeof t!="function"?CO("Function expected"):t,CJ=(t,e,n,r,o)=>({kind:IO[t],name:e,metadata:r,addInitializer:s=>n._?CO("Already initialized"):o.push(EO(s||null))}),_J=(t,e)=>_O(e,bJ("metadata"),t[3]),IJ=(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},_1=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=IO[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,wJ(o,n)),S=r.length-1;S>=0;S--)l=CJ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,EO(i)&&(v[m]=i);return v&&PO(o,n,v),o},Gy=(t,e,n)=>_O(t,typeof e!="symbol"?e+"":e,n),kO,TO,MO,tc;MO=[W],TO=[W],kO=[W];class md{constructor(e){this.editor=e,IJ(tc,5,this),Gy(this,"shapeBounds"),Gy(this,"handles"),Gy(this,"_snapIndicators",Et("snapLines",void 0)),this.shapeBounds=new ec(this),this.handles=new C1(this)}getIndicators(){return this._snapIndicators.get()??us}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())}}tc=PJ();_1(tc,1,"getSnapThreshold",MO,md);_1(tc,1,"getSnappableShapes",TO,md);_1(tc,1,"getCurrentCommonAncestor",kO,md);_J(tc,md);const EJ=/\r?\n|\r/g;function _I(t){return t.replace(EJ,`
|
|
102
|
-
`).split(`
|
|
103
|
-
`).map(e=>e||" ").join(`
|
|
104
|
-
`)}const kJ={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},TJ=/\s/;class MJ{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=_I(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,m=!1;for(const g of e.childNodes)if(g.nodeType===Node.TEXT_NODE)for(const v of g.textContent??""){a.setStart(l,c),a.setEnd(l,c+v.length);const S=a.getClientRects(),y=S[S.length-1],P=y.top+i,b=y.left+s,C=y.right+s,I=b<f,k=TJ.test(v);if(k!==h||P!==p||!u){if(u){if(n&&P!==p){m=!0;break}r.push(u)}u={box:{x:b,y:P,w:y.width,h:y.height},text:v},f=b}else I&&(u.box.x=b),u.box.w=I?u.box.w+y.width:C-u.box.x,u.text+=v;v===`
|
|
105
|
-
`&&(f=0),h=k,p=P,c+=v.length}return u&&r.push(u),{spans:r,didTruncate:m}}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",kJ[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=_I(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 AJ=Object.create,AO=Object.defineProperty,jJ=Object.getOwnPropertyDescriptor,OJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),jO=t=>{throw TypeError(t)},OO=(t,e,n)=>e in t?AO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,DJ=t=>[,,,AJ(null)],DO=["class","method","getter","setter","accessor","field","value","get","set"],RO=t=>t!==void 0&&typeof t!="function"?jO("Function expected"):t,RJ=(t,e,n,r,o)=>({kind:DO[t],name:e,metadata:r,addInitializer:s=>n._?jO("Already initialized"):o.push(RO(s||null))}),LJ=(t,e)=>OO(e,OJ("metadata"),t[3]),$J=(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},LO=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=DO[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,jJ(o,n)),S=r.length-1;S>=0;S--)l=RJ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,RO(i)&&(v[m]=i);return v&&AO(o,n,v),o},mh=(t,e,n)=>OO(t,typeof e!="symbol"?e+"":e,n),$O,FO,yd;const II=(typeof process<"u",HT);FO=[Hn],$O=[Hn];class Kg{constructor(e){this.editor=e,$J(yd,5,this),mh(this,"cancelRaf"),mh(this,"isPaused",!0),mh(this,"now",0),mh(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=II(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=II(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)}}yd=DJ();LO(yd,1,"tick",FO,Kg);LO(yd,1,"dispose",$O,Kg);LJ(yd,Kg);var FJ=Object.create,NO=Object.defineProperty,NJ=Object.getOwnPropertyDescriptor,zJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),zO=t=>{throw TypeError(t)},BO=(t,e,n)=>e in t?NO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,BJ=t=>[,,,FJ(null)],UO=["class","method","getter","setter","accessor","field","value","get","set"],HO=t=>t!==void 0&&typeof t!="function"?zO("Function expected"):t,UJ=(t,e,n,r,o)=>({kind:UO[t],name:e,metadata:r,addInitializer:s=>n._?zO("Already initialized"):o.push(HO(s||null))}),HJ=(t,e)=>BO(e,zJ("metadata"),t[3]),KJ=(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},Fr=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=UO[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,NJ(o,n)),S=r.length-1;S>=0;S--)l=UJ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,HO(i)&&(v[m]=i);return v&&NO(o,n,v),o},WJ=(t,e,n)=>BO(t,e+"",n),KO,WO,GO,VO,YO,XO,qO,ZO,QO,JO,eD,tD,Tn;tD=[W],eD=[W],JO=[W],QO=[W],ZO=[W],qO=[W],XO=[W],YO=[W],VO=[W],GO=[W],WO=[W],KO=[W];class Jn{constructor(e,n){if(this.user=e,this.inferDarkMode=n,KJ(Tn,5,this),WJ(this,"systemColorScheme",Et("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??qo.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??qo.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??qo.name}getLocale(){return this.user.userPreferences.get().locale??qo.locale}getColor(){return this.user.userPreferences.get().color??qo.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??qo.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??qo.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??qo.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??qo.isPasteAtCursorMode}}Tn=BJ();Fr(Tn,1,"getUserPreferences",tD,Jn);Fr(Tn,1,"getIsDarkMode",eD,Jn);Fr(Tn,1,"getEdgeScrollSpeed",JO,Jn);Fr(Tn,1,"getAnimationSpeed",QO,Jn);Fr(Tn,1,"getId",ZO,Jn);Fr(Tn,1,"getName",qO,Jn);Fr(Tn,1,"getLocale",XO,Jn);Fr(Tn,1,"getColor",YO,Jn);Fr(Tn,1,"getIsSnapMode",VO,Jn);Fr(Tn,1,"getIsWrapMode",GO,Jn);Fr(Tn,1,"getIsDynamicResizeMode",WO,Jn);Fr(Tn,1,"getIsPasteAtCursorMode",KO,Jn);HJ(Tn,Jn);const GJ={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"},VJ=["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",Et("curent tool id mask",void 0));this.editor=e;const{id:r,children:o,initial:s,isLockable:i}=this.constructor;this.id=r,this._isActive=Et("toolIsActive"+this.id,!1),this._current=Et("toolState"+this.id,void 0),this._path=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 wT}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=GJ[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()&&VJ.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 Cx 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(Cx,"id","root"),E(Cx,"initial","");var YJ=Object.create,nD=Object.defineProperty,XJ=Object.getOwnPropertyDescriptor,rD=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),oD=t=>{throw TypeError(t)},sD=(t,e,n)=>e in t?nD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,qJ=t=>[,,,YJ((t==null?void 0:t[rD("metadata")])??null)],iD=["class","method","getter","setter","accessor","field","value","get","set"],aD=t=>t!==void 0&&typeof t!="function"?oD("Function expected"):t,ZJ=(t,e,n,r,o)=>({kind:iD[t],name:e,metadata:r,addInitializer:s=>n._?oD("Already initialized"):o.push(aD(s||null))}),QJ=(t,e)=>sD(e,rD("metadata"),t[3]),JJ=(t,e,n,r)=>{for(var o=0,s=t[e>>1],i=s&&s.length;o<i;o++)s[o].call(n);return r},te=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=iD[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,XJ(o,n)),S=r.length-1;S>=0;S--)l=ZJ(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,aD(i)&&(v[m]=i);return v&&nD(o,n,v),o},de=(t,e,n)=>sD(t,typeof e!="symbol"?e+"":e,n),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,wR,bR,PR,CR,_R,_x,J;class Q extends(_x=xZ,_R=[W],CR=[W],PR=[W],bR=[W],wR=[W],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({isEqual:(e,n)=>e.equals(n)})],fD=[W],pD=[W],hD=[W],dD=[Hn],uD=[Hn],cD=[Hn],lD=[Hn],_x){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 M;super(),JJ(J,5,this),de(this,"_isShapeHiddenPredicate"),de(this,"options"),de(this,"contextId",ze()),de(this,"store"),de(this,"root"),de(this,"disposables",new Set),de(this,"isDisposed",!1),de(this,"_tickManager"),de(this,"snaps"),de(this,"timers",bx.forContext(this.contextId)),de(this,"user"),de(this,"textMeasure"),de(this,"environment",Ge),de(this,"scribbles"),de(this,"sideEffects"),de(this,"edgeScrollManager"),de(this,"focusManager"),de(this,"getContainer"),de(this,"shapeUtils"),de(this,"styleProps"),de(this,"bindingUtils"),de(this,"history"),de(this,"_shouldIgnoreShapeLock",!1),de(this,"_crashingError",null),de(this,"_isChangingStyleTimeout",-1),de(this,"menus",Gr.forContext(this.contextId)),de(this,"_cameraOptions",Et("camera options",V_)),de(this,"_viewportAnimation",null),de(this,"_willSetInitialBounds",!0),de(this,"_isLockedOnFollowingUser",Et("isLockedOnFollowingUser",!1)),de(this,"_cameraState",Et("camera state","idle")),de(this,"_cameraStateTimeoutRemaining",0),de(this,"_currentPageShapeIds"),de(this,"_parentIdsToChildIds"),de(this,"animatingShapes",new Map),de(this,"externalAssetContentHandlers",{file:null,url:null}),de(this,"temporaryAssetPreview",new Map),de(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null}),de(this,"inputs",{originPagePoint:new x,originScreenPoint:new x,previousPagePoint:new x,previousScreenPoint:new x,currentPagePoint:new x,currentScreenPoint:new x,keys:new Set,buttons:new Set,isPen:!1,shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,isSpacebarPanning:!1,pointerVelocity:new x}),de(this,"_clickManager",new Bg(this)),de(this,"_prevCursor","default"),de(this,"_shiftKeyTimeout",-1),de(this,"_altKeyTimeout",-1),de(this,"_ctrlKeyTimeout",-1),de(this,"_metaKeyTimeout",-1),de(this,"_restoreToolId","select"),de(this,"_pinchStart",1),de(this,"_didPinch",!1),de(this,"_selectedShapeIdsAtPointerDown",[]),de(this,"_longPressTimeout",-1),de(this,"capturedPointerId",null),de(this,"performanceTracker"),de(this,"performanceTrackerTimeout",-1),de(this,"_pendingEventsForNextTick",[]),this._isShapeHiddenPredicate=p,this.options={...bQ,...h},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new qQ({store:e,annotateError:T=>{this.annotateError(T,{origin:"history.batch",willCrashApp:!0}),this.crash(T)}}),this.snaps=new md(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...V_,...a}),this.user=new Jn(n??Pj(),u??!1),this.getContainer=i,this.textMeasure=new MJ(this),this._tickManager=new Kg(this);class f extends Cx{}E(f,"initial",l??""),this.root=new f(this),this.root.children={};const m=jj(r),g={},v={},S=new Map;for(const T of m){const D=new T(this);g[T.type]=D;const A=rA(T.props??{});v[T.type]=A;for(const O of A.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=g,this.styleProps=v;const y=Tj(o),P={};for(const T of y){const D=new T(this);P[T.type]=D}this.bindingUtils=P;for(const T of[...s]){if(eo(this.root.children,T.id))throw Error(`Can't override tool with id "${T.id}"`);this.root.children[T.id]=new T(this,this.root)}this.scribbles=new JQ(this);const b=(T,D)=>{let A=null;const O=T.selectedShapeIds.filter(L=>!D.has(L));O.length!==T.selectedShapeIds.length&&(A||(A={...T}),A.selectedShapeIds=O);const R=T.erasingShapeIds.filter(L=>!D.has(L));R.length!==T.erasingShapeIds.length&&(A||(A={...T}),A.erasingShapeIds=R),T.hoveredShapeId&&D.has(T.hoveredShapeId)&&(A||(A={...T}),A.hoveredShapeId=null),T.editingShapeId&&D.has(T.editingShapeId)&&(A||(A={...T}),A.editingShapeId=null);const B=T.hintingShapeIds.filter(L=>!D.has(L));return B.length!==T.hintingShapeIds.length&&(A||(A={...T}),A.hintingShapeIds=B),T.focusedGroupId&&D.has(T.focusedGroupId)&&(A||(A={...T}),A.focusedGroupId=null),A};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 T,D,A,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=(T=L.onChildrenChange)==null?void 0:T.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=(A=this.getBindingUtil(B.binding)).onAfterDelete)==null||O.call(A,B)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(T,D)=>{var A,O,R,B;for(const L of this.getBindingsInvolvingShape(D))_.add(L.type),L.fromId===D.id&&((O=(A=this.getBindingUtil(L)).onAfterChangeFromShape)==null||O.call(A,{binding:L,shapeBefore:T,shapeAfter:D})),L.toId===D.id&&((B=(R=this.getBindingUtil(L)).onAfterChangeToShape)==null||B.call(R,{binding:L,shapeBefore:T,shapeAfter:D}));if(T.parentId!==D.parentId){const L=G=>{var U,Y,ee,he;const $=this.getShape(G);if($)for(const ue of this.getBindingsInvolvingShape($))_.add(ue.type),ue.fromId===$.id&&((Y=(U=this.getBindingUtil(ue)).onAfterChangeFromShape)==null||Y.call(U,{binding:ue,shapeBefore:$,shapeAfter:$})),ue.toId===$.id&&((he=(ee=this.getBindingUtil(ue)).onAfterChangeToShape)==null||he.call(ee,{binding:ue,shapeBefore:$,shapeAfter:$}))};L(D.id),this.visitDescendants(D.id,L)}if(T.parentId!==D.parentId&&Dn(D.parentId)){const L=new Set([T.id]);this.visitDescendants(T.id,G=>{L.add(G)});for(const G of this.getPageStates()){if(G.pageId===D.parentId)continue;const $=b(G,L);$&&this.store.put([$])}}T.parentId&&$n(T.parentId)&&k.add(T.parentId),D.parentId!==T.parentId&&$n(D.parentId)&&k.add(D.parentId)},beforeDelete:T=>{var R,B,L,G;if(I.has(T.id))return;T.parentId&&$n(T.parentId)&&k.add(T.parentId),I.add(T.id);const D=[];for(const $ of this.getBindingsInvolvingShape(T)){_.add($.type),D.push($.id);const U=this.getBindingUtil($);$.fromId===T.id?((R=U.onBeforeIsolateToShape)==null||R.call(U,{binding:$,removedShape:T}),(B=U.onBeforeDeleteFromShape)==null||B.call(U,{binding:$,shape:T})):((L=U.onBeforeIsolateFromShape)==null||L.call(U,{binding:$,removedShape:T}),(G=U.onBeforeDeleteToShape)==null||G.call(U,{binding:$,shape:T}))}D.length&&this.deleteBindings(D);const A=new Set([T.id]),O=ye(this.getPageStates().map($=>b($,A)));O.length&&this.store.put(O)}},binding:{beforeCreate:T=>{var A,O;const D=(O=(A=this.getBindingUtil(T)).onBeforeCreate)==null?void 0:O.call(A,{binding:T});return D||T},afterCreate:T=>{var D,A;_.add(T.type),(A=(D=this.getBindingUtil(T)).onAfterCreate)==null||A.call(D,{binding:T})},beforeChange:(T,D)=>{var O,R;const A=(R=(O=this.getBindingUtil(D)).onBeforeChange)==null?void 0:R.call(O,{bindingBefore:T,bindingAfter:D});return A||D},afterChange:(T,D)=>{var A,O;_.add(D.type),(O=(A=this.getBindingUtil(D)).onAfterChange)==null||O.call(A,{bindingBefore:T,bindingAfter:D})},beforeDelete:T=>{var D,A;(A=(D=this.getBindingUtil(T)).onBeforeDelete)==null||A.call(D,{binding:T})},afterDelete:T=>{var D,A;(A=(D=this.getBindingUtil(T)).onAfterDelete)==null||A.call(D,{binding:T}),_.add(T.type)}},page:{afterCreate:T=>{const D=_o.createId(T.id),A=qr.createId(T.id);this.store.has(D)||this.store.put([_o.create({id:D})]),this.store.has(A)||this.store.put([qr.create({id:A,pageId:T.id})])},afterDelete:(T,D)=>{var R,B;if(((R=this.getInstanceState())==null?void 0:R.currentPageId)===T.id){const L=(B=this.getPages().find(G=>G.id!==T.id))==null?void 0:B.id;L?this.store.put([{...this.getInstanceState(),currentPageId:L}]):D==="user"&&this.store.ensureStoreIsUsable()}const A=_o.createId(T.id),O=qr.createId(T.id);this.store.remove([A,O])}},instance:{afterChange:(T,D,A)=>{var O;if(!this.store.has(D.currentPageId)){const R=this.store.has(T.currentPageId)?T.currentPageId:(O=this.getPages()[0])==null?void 0:O.id;R?this.store.update(D.id,B=>({...B,currentPageId:R})):A==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(T,D)=>{if((T==null?void 0:T.selectedShapeIds)!==(D==null?void 0:D.selectedShapeIds)){const A=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(A.length>0){const R=this.findCommonAncestor(ye(A.map(B=>this.getShape(B))),B=>this.isShapeOfType(B,"group"));R&&(O=R)}else D!=null&&D.focusedGroupId&&(O=D.focusedGroupId);(A.length!==D.selectedShapeIds.length||O!==D.focusedGroupId)&&this.store.put([{...D,selectedShapeIds:A,focusedGroupId:O??null}])}}}})),this._currentPageShapeIds=$Q(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=LQ(this.store),this.disposables.add(this.store.listen(T=>{this.emit("change",T)})),this.disposables.add(this.history.dispose),this.run(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})},{history:"ignore"}),l&&this.root.children[l]===void 0)throw Error(`No state found for initialState "${l}".`);if(this.root.enter(void 0,"initial"),this.edgeScrollManager=new GQ(this),this.focusManager=new VQ(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 wT,(M=this.store.props.collaboration)!=null&&M.mode){const T=this.store.props.collaboration.mode;this.disposables.add(Mo("update collaboration mode",()=>{this.store.put([{...this.getInstanceState(),isReadonly:T.get()==="readonly"}])}))}}getIsShapeHiddenCache(){return this._isShapeHiddenPredicate?this.store.createComputedCache("isShapeHidden",e=>this.findShapeAncestor(e,r=>this.isShapeHidden(r))?!0:this._isShapeHiddenPredicate(e,this)??!1):null}isShapeHidden(e){return this._isShapeHiddenPredicate?!!this.getIsShapeHiddenCache().get(typeof e=="string"?e:e.id):!1}dispose(){this.disposables.forEach(e=>e()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(e){const n=typeof e=="string"?e:e.type,r=Kn(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=Kn(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(dx)}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 qr.createId(this.getCurrentPageId())}updateCurrentPageState(e){return this._updateCurrentPageState(e),this}_updateCurrentPageState(e){this.store.update(e.id??this.getCurrentPageState().id,n=>({...n,...e}))}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:e}=this.getCurrentPageState();return 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:pw(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 _o.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}=kI(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}=kI(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),m=Z.From(a.constraints.bounds),g=(u.w-f*2)/m.w,v=(u.h-p*2)/m.h,S=this.getBaseZoom(),y=c*S,P=l*S;if(n!=null&&n.reset&&(i=this.getInitialZoom()),i<P||i>y){const{x:A,y:O,z:R}=r,B=-A+u.w/R/2,L=-O+u.h/R/2;i=Bt(i,P,y);const G=-A+u.w/i/2,$=-O+u.h/i/2;o=A+G-B,s=O+$-L}const b=f/i-m.x,C=p/i-m.y,I=(u.w-f*2)/i-m.w,k=(u.h-p*2)/i-m.h,_=b+I*h.origin.x,M=C+k*h.origin.y,T=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=M;else{switch(T){case"fixed":{o=_;break}case"contain":{i<g?o=_:o=Bt(o,b+I,b);break}case"inside":{i<g?o=Bt(o,b,(u.w-f)/i-m.w):o=Bt(o,b+I,b);break}case"outside":{o=Bt(o,f/i-m.w,(u.w-f)/i);break}case"free":break;default:throw Ot(T)}switch(D){case"fixed":{s=M;break}case"contain":{i<v?s=M:s=Bt(s,C+k,C);break}case"inside":{i<v?s=Bt(s,C,(u.h-p)/i-m.h):s=Bt(s,C+k,C);break}case"outside":{s=Bt(s,p/i-m.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:(Ao(()=>{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:Y_.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(JY,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:$y}){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:m}=this.getCamera(),g=x.Mul(i,l*h/m);l*=1-s,l<a?c():this._setCamera(new x(p+g.x,f+g.y,m))};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,!ai(document.body.scrollWidth,e.maxX,1),!ai(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]):us}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 Ao(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const s=Mo("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 m=Bt(c*.5,.1,.8),g=new Z(Ie(h.minX,u.minX,m),Ie(h.minY,u.minY,m),Ie(h.width,u.width,m),Ie(h.height,u.height,m)),v=new x(-g.x,-g.y,this.getViewportScreenBounds().width/g.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 m=this.getSortedChildIdsForParent(l);if(!m.length)return;let g=null;f.providesBackgroundForChildren(h)&&(g=o,o=r,r+=this.options.maxShapesPerPage);for(const v of m)i(v,c,u||p);g!==null&&(o=g)},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(Q9)}_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=kQ(e.name??"Page 1",n.map(i=>i.name));let o=e.index;(!o||n.some(i=>i.index===o))&&(o=Co(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=Ru(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=fI(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=fI(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 RQ(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,m=null;const g=(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=g.length-1;v>=0;v--){const S=g[v],y=this.getShapeGeometry(S),P=y instanceof so,b=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(b))return S}if(this.isShapeOfType(S,"frame")){const I=y.distanceToPoint(b,c);if(Math.abs(I)<=i)return m||S;if(y.hitTestPoint(b,0,!0))return m||p||(u?S:void 0);continue}let C;if(P){let I=1/0;for(const k of y.children){if(k.isLabel&&!l)continue;const _=k.distanceToPoint(b,c);_<I&&(I=_)}C=I}else i===0&&(y.bounds.w<1||y.bounds.h<1)||y.bounds.containsPoint(b,i)?C=y.distanceToPoint(b,c):C=1/0;if(y.isClosed){if(C<=i){if(y.isFilled||P&&y.children[0].isFilled)return m||S;if(this.getShapePageBounds(S).contains(o))continue;if(Math.abs(C)<i)Math.abs(C)<f&&(f=Math.abs(C),m=S);else if(!m){const{area:I}=y;I<h&&(h=I,p=S)}}}else if(C<this.options.hitTestMargin/r)return S}return m||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++)IR(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=Al(r,f.index,o.length):l=dy(r,o.length)}else{const f=c.sort(cn).find(m=>m.index>r);f?l=Al(r,f.index,o.length):l=dy(r,o.length)}}else{const p=c.length&&c[c.length-1];l=p?dy(p.index,o.length):Lu(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],m=this.getShapePageTransform(f);if(!m)continue;const g=m.point();if(!g)continue;const v=u.applyToPoint(g),S=m.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 Co(o.index)}getSortedChildIdsForParent(e){const n=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[n];return r||us}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=OQ(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)??us;return n?o.filter(s=>s.type===n):o}createBindings(e){const n=[];for(const r of e){const o=this.getShape(r.fromId),s=this.getShape(r.toId);if(!o||!s||!this.canBindShapes({fromShape:o,toShape:s,binding:r}))continue;const a=this.getBindingUtil(r.type).getDefaultProps(),l=this.store.schema.types.binding.create({...r,id:r.id??qi(),props:{...a,...r.props}});n.push(l)}return this.store.put(n),this}createBinding(e){return this.createBindings([e])}updateBindings(e){const n=[];for(const r of e){if(!r)continue;const o=this.getBinding(r.id);if(!o)continue;const s=yo(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=Jj({editor:this,ids:o});return s?(ap({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=yo(r,((s=o.onTranslateStart)==null?void 0:s.call(o,r))??void 0),r=yo(r,{id:e.id,type:e.type,x:n.x,y:n.y}),r=yo(r,((i=o.onTranslate)==null?void 0:i.call(o,e,r))??void 0),r=yo(r,((a=o.onTranslateEnd)==null?void 0:a.call(o,e,r))??void 0),r}nudgeShapes(e,n){const r=typeof e[0]=="string"?e:e.map(s=>s.id);if(r.length<=0)return this;const o=[];for(const s of r){const i=this.getShape(s),a=x.From(n),l=this.getShapeParentTransform(i);l&&a.rot(-l.rotation()),o.push(this.getChangesToTranslateShape(i,a.add(i)))}return this.updateShapes(o),this}duplicateShapes(e,n){return this.run(()=>{const r=typeof e[0]=="string"?e:e.map(p=>p.id);if(r.length<=0)return this;const o=new Set(r),s=this.getShapeAndDescendantIds(r),i=[...s].reverse(),a=new Map;for(const p of s)a.set(p,Ke());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=EI(this,s,p=>{const f=[];for(const g of p){const v=this.getBinding(g);if(!v)continue;const S=qi();f.push({...v,id:S,fromId:Nn(a.get(v.fromId)),toId:Nn(a.get(v.toId))})}const m=[];for(const g of i){const v=Nn(a.get(g)),S=this.getShape(g);if(!S)continue;let y=0,P=0;if(n&&o.has(g)){const b=this.getShapeParentTransform(S),C=new x(n.x,n.y).rot(-b.rotation());y=C.x,P=C.y}m.push({shape:{...S,id:v,x:S.x+y,y:S.y+P,index:"a1",parentId:a.get(S.parentId)??S.parentId},originalShape:S})}return{shapesToCreateWithOriginals:m,bindingsToCreate:f}});l.forEach(({shape:p,originalShape:f})=>{const m=f.parentId,g=this.getSortedChildIdsForParent(m),v=g.indexOf(f.id),S=g[v+1],y=S?this.getShape(S):void 0,P=Ru(f.index,y==null?void 0:y.index);p.index=P});const u=l.map(({shape:p})=>p);if(u.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){yh(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 yh(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=gh(this,"toBack",n);return r&&this.updateShapes(r),this}sendBackward(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=gh(this,"backward",n);return r&&this.updateShapes(r),this}bringForward(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=gh(this,"forward",n);return r&&this.updateShapes(r),this}bringToFront(e){const n=typeof e[0]=="string"?e:e.map(o=>o.id),r=gh(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(g=>g.id);if(this.getIsReadonly())return this;const s=o.map(g=>this.getShape(g)).filter(g=>g?this.getShapeUtil(g).canBeLaidOut(g):!1),i=s.length;if(r===0&&i<3||i<2)return this;const a=Object.fromEntries(s.map(g=>[g.id,this.getShapePageBounds(g)]));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 g=[];s.sort((S,y)=>a[S.id][c]-a[y.id][c]);for(let S=0;S<i-1;S++){const y=s[S],P=s[S+1],b=a[y.id],I=a[P.id][c]-b[u],k=g.find(_=>_.gap===I);k?k.count++:g.push({gap:I,count:1})}let v=0;g.forEach(S=>{S.count>v&&(v=S.count,p=S.gap)}),v===1&&(p=Math.max(0,g.reduce((S,y)=>S+y.gap*y.count,0)/(i-1)))}else p=r;const f=[];let m=a[s[0].id][u];return s.forEach((g,v)=>{var C,I;if(v===0)return;const S={x:0,y:0};S[l]=m+p-a[g.id][l];const y=this.getShapeParent(g),P=y?x.Rot(S,-this.getShapePageTransform(y).decompose().rotation):S,b=(I=(C=this.getShapeUtil(g)).onTranslateStart)==null?void 0:I.call(C,g);f.push(b?{...b,[l]:g[l]+P[l]}:{id:g.id,type:g.type,[l]:g[l]+P[l]}),m+=a[g.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((_,M)=>s[M.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 m=0,g=0,v,S;for(let _=0;_<o.length;_++){a=o[_],l=i[a.id];for(let M=f.length-1;M>=0;M--)if(v=f[M],!(l.width>v.width||l.height>v.height)){l.x=v.x,l.y=v.y,g=Math.max(g,l.maxY),m=Math.max(m,l.maxX),l.width===v.width&&l.height===v.height?(S=f.pop(),M<f.length&&(f[M]=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)),P=x.Sub(u.center,y.center);let b;const C=[];for(let _=0;_<o.length;_++){a=o[_],l=s[a.id],b=i[a.id];const M=x.Sub(b.point,l.point).add(P),T=this.getShapeParentTransform(a);T&&M.rot(-T.rotation());const D={id:a.id,type:a.type,x:a.x+M.x,y:a.y+M.y},A=(k=(I=this.getShapeUtil(a)).onTranslateStart)==null?void 0:k.call(I,{...a,...D});A?C.push({...D,...A}):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,P)=>i[y.id][l]-i[P.id][l])[0],m=s.sort((y,P)=>i[P.id][c]-i[y.id][c])[0],g=i[f.id][u],v=(i[m.id][u]-g)/(o-1),S=g+v;return s.filter(y=>y!==f&&y!==m).sort((y,P)=>i[y.id][u]-i[P.id][u]).forEach((y,P)=>{const b={x:0,y:0};b[a]=S+v*P-i[y.id][h]/2-i[y.id][a];const C=this.getShapeParent(y),I=C?x.Rot(b,-this.getShapePageTransform(C).rotation()):b;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:m,y:g}=x.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:m,y:g}]);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:m,y:g}=x.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:m,y:g}]);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,m,g;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(!WA(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),P=ai((l-c)%Math.PI,0);y.x=P?n.x:n.y,y.y=P?n.y:n.x;const b=q.applyToPoint(a,new x),{x:C,y:I}=this.getPointInParentSpace(s.id,b);let k=s;r.skipStartAndEndCallbacks||(k=yo(s,((m=p.onResizeStart)==null?void 0:m.call(p,s))??void 0)),k=yo(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=yo(k,((g=p.onResizeEnd)==null?void 0:g.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),P=this.getPointInParentSpace(s.id,S),b=x.Sub(P,y);this.updateShapes([{id:o,type:s.type,x:s.x+b.x,y:s.y+b.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:m,y:g}=this.getPointInParentSpace(e,f);return this.updateShapes([{id:e,type:o,x:m,y:g}]),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 yh(this),this;const o=this.getFocusedGroupId();return this.run(()=>{var u,h;const s=this.getCurrentPageShapesSorted(),i=e.map(p=>{if(p.id||(p={id:Ke(),...p}),!p.parentId||!(this.store.has(p.parentId)||e.some(f=>f.id===p.parentId))){let f=this.getFocusedGroupId();for(let g=s.length-1;g>=0;g--){const v=s[g];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 m=p.parentId;if(f===p.id&&(f=o),f!==m&&(p={...p},p.parentId=f,$n(f))){const g=this.getPointInShapeSpace(this.getShape(f),{x:p.x??0,y:p.y??0});p.x=g.x,p.y=g.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 m=p.index;if(!m){const y=p.parentId??o;a.has(y)||a.set(y,this.getHighestIndexForParent(y)),m=a.get(y),a.set(y,Co(m))}const g=f.getDefaultProps();for(const[y,P]of this.styleProps[p.type])g[P]=this.getStyleForNextShape(y);let v=this.store.schema.types.shape.create({...p,index:m,opacity:p.opacity??c,parentId:p.parentId??o,props:"props"in p?{...g,...p.props}:g});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:$y}){return this.animateShapes([e],n)}animateShapes(e,n={animation:$y}){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 m=this.getShape(c.id);m&&(u={start:nt(m),end:yo(nt(m),c)},l.push(u),this.animatingShapes.set(m.id,s))}const h=p=>{var v,S;if(i-=p,i<0){const{animatingShapes:y}=this,P=e.filter(b=>b&&y.get(b.id)===s);P.length&&this.updateShapes(P),this.off("tick",h);return}a=o(1-i/r);const{animatingShapes:f}=this,m=[];let g;for(let y=0,P=l.length;y<P;y++){const{start:b,end:C}=l[y];g=f.get(b.id),g===s&&m.push({...C,x:b.x+(C.x-b.x)*a,y:b.y+(C.y-b.y)*a,opacity:b.opacity+(C.opacity-b.opacity)*a,rotation:b.rotation+(C.rotation-b.rotation)*a,props:((S=(v=this.getShapeUtil(C)).getInterpolatedProps)==null?void 0:S.call(v,b,C,a))??C.props})}this._updateShapes(m)};return this.on("tick",h),this}groupShapes(e,n={}){var m;const{groupId:r=Ke(),select:o=!0}=n;if(!Array.isArray(e))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getIsReadonly())return this;const s=typeof e[0]=="string"?e:e.map(g=>g.id);if(s.length<=1)return this;const i=ye((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(g=>this.getShape(g))),a=i.sort(cn).map(g=>g.id),l=Z.Common(ye(i.map(g=>this.getShapePageBounds(g)))),{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(g=>g.parentId===h).sort(cn),f=(m=p[p.length-1])==null?void 0:m.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=yo(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,Kn(e.props,o))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),n=new Px;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 Kn(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),n=new Px;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 EI(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),m=f.point();a.push({...h,x:m.x,y:m.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 cs.blobToDataUrl(await oo(a).then(l=>l.blob())),n.push(i)}else n.push(r)})),e.assets=n,e}putContentOntoCurrentPage(e,n={}){var T,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(A=>[A.id,A])),...Object.fromEntries(e.shapes.map(A=>[A.id,A])),...Object.fromEntries(((T=e.bindings)==null?void 0:T.map(A=>[A.id,A]))??[])},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 A of Object.values(f.value))switch(A.typeName){case"asset":{c.push(A);break}case"shape":{u.push(A);break}case"binding":{h.push(A);break}}const m=new Map(o?u.map(A=>[A.id,A.id]):u.map(A=>[A.id,Ke()])),g=new Map(o?h.map(A=>[A.id,A.id]):h.map(A=>[A.id,qi()]));let v=this.getCurrentPageId(),S=1/0,y=[];for(const A of this.getSelectedShapes()){if(S===0)break;const O=this.isShapeOfType(A,"frame"),R=this.getShapeAncestors(A);O&&R.push(A);const B=O?R.length+1:R.length;if(B<S)S=B,y=R,v=O?A.id:A.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 P=!1;if(!Dn(v)){const A=this.getShape(v);if(A){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(A)))v=a;else if(l.length===1){const O=u.find(R=>R.id===l[0]);this.isShapeOfType(A,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(A==null?void 0:A.props.w)&&O.props.h===(A==null?void 0:A.props.h)&&(P=!0)}}else v=a}P||(P=m.has(v)),P&&(v=this.getShape(v).parentId);let b=this.getHighestIndexForParent(v);const C=[],I=u.map(A=>{const O=m.get(A.id),R={...A,id:O};return l.includes(A.id)&&(R.parentId=a,C.push(R)),m.has(R.parentId)?R.parentId=m.get(A.parentId):(l.push(R.id),R.index=b,b=Co(b)),R});if(I.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return yh(this),this;const k=h.map(A=>({...A,id:Nn(g.get(A.id)),fromId:Nn(m.get(A.fromId)),toId:Nn(m.get(A.toId))})),_=[],M=[];for(const A of c)this.store.has(A.id)||((A.type==="image"||A.type==="video")&&((D=A.props.src)!=null&&D.startsWith("data:image"))&&(M.push(nt(A)),A.props.src=null),_.push(A));return Promise.allSettled(M.map(async A=>{const O=await CQ(A.props.src,A.props.name,A.props.mimeType??"image/png"),R=await this.getAssetForExternalContent({type:"file",file:O,assetId:A.id});if(!R){this.deleteAssets([A.id]);return}this.updateAssets([{...R,id:A.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 A=I.map(L=>this.getShape(L.id)),O=Z.Common(A.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 xQ(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}=oh(()=>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 m=h/u-l,g=p/u-c;isFinite(m)&&isFinite(g)&&i.set(m,g,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:If,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===Y_.CAMERA_MOVE?((v=this.store.unsafeGetWithoutCapture(If))==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 _Z(this.store)}loadSnapshot(e,n){return Ej(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(EQ(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",IQ((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=gg(i=>i(),(e==null?void 0:e.debounceMs)??500),s=Mo("update url on state change",()=>r(new URL(n.get()),this),{scheduleEffect:o});return()=>{s(),o.cancel()}}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_setShiftKeyTimeout(){this.inputs.shiftKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Shift",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),code:"ShiftLeft"})}_setAltKeyTimeout(){this.inputs.altKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Alt",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),code:"AltLeft"})}_setCtrlKeyTimeout(){this.inputs.ctrlKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Ctrl",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),code:"ControlLeft"})}_setMetaKeyTimeout(){this.inputs.metaKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Meta",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,metaKey:this.inputs.metaKey,accelKey:un(this.inputs),code:"MetaLeft"})}dispatch(e){return this._pendingEventsForNextTick.push(e),e.type==="pointer"&&e.name==="pointer_move"||e.type==="wheel"||e.type==="pinch"||this._flushEventsForTick(0),this}_flushEventsForTick(e){this.run(()=>{if(this._pendingEventsForNextTick.length>0){const n=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const r of n)this._flushEventForTick(r)}e>0&&this.root.handleEvent({type:"misc",name:"tick",elapsed:e}),this.scribbles.tick(e)})}_flushEventForTick(e){if(this.getCrashingError())return this;const{inputs:n}=this,{type:r}=e;if(e.type==="misc"){(e.name==="cancel"||e.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}))),this.root.handleEvent(e);return}e.shiftKey?(clearTimeout(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,n.shiftKey=!0):!e.shiftKey&&n.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),e.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,n.altKey=!0):!e.altKey&&n.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),e.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,n.ctrlKey=!0):!e.ctrlKey&&n.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150)),e.metaKey?(clearTimeout(this._metaKeyTimeout),this._metaKeyTimeout=-1,n.metaKey=!0):!e.metaKey&&n.metaKey&&this._metaKeyTimeout===-1&&(this._metaKeyTimeout=this.timers.setTimeout(this._setMetaKeyTimeout,150));const{originPagePoint:o,currentPagePoint:s}=n;n.isPointing||(n.isDragging=!1);const i=this.store.unsafeGetWithoutCapture(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:m,y:g,z:v}=oh(()=>this.getCamera()),{panSpeed:S,zoomSpeed:y}=l;this._setCamera(new x(m+u*S/v-p/v+p/(c*y),g+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;this._updateInputsFromEvent(e);const{panSpeed:c,zoomSpeed:u,wheelBehavior:h}=l;if(h!=="none"){this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:p,y:f,z:m}=oh(()=>this.getCamera()),{x:g,y:v,z:S=0}=e.delta;let y=h;switch(n.ctrlKey&&(y=h==="pan"?"zoom":"pan"),y){case"zoom":{const{x:P,y:b}=this.inputs.currentScreenPoint;let C=S;h==="zoom"&&(Math.abs(v)>10?C=10*Math.sign(v)/100:C=v/100);const I=m+(C??0)*u*m;this._setCamera(new x(p+(P/I-P)-(P/m-P),f+(b/I-b)-(b/m-b),I),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new x(p+g*c/m,f+v*c/m,m),{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===X_&&(this.capturedPointerId=e.pointerId),n.buttons.add(e.button),n.isPointing=!0,n.isDragging=!1,!u&&c&&this.updateInstanceState({isPenMode:!0}),e.button===q_?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===dh&&(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}=oh(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:m,previousScreenPoint:g}=this.inputs,{panSpeed:v}=l,S=x.Sub(m,g);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),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 X_:{this.setCursor({type:"grab",rotation:0});break}case dh: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===q_&&(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(dh)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===dh?e.name="middle_click":e.button===l1&&(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=qJ(_x);te(J,1,"getIsShapeHiddenCache",_R,Q);te(J,1,"getCanUndo",CR,Q);te(J,1,"getCanRedo",PR,Q);te(J,1,"getPath",bR,Q);te(J,1,"getCurrentTool",wR,Q);te(J,1,"getCurrentToolId",xR,Q);te(J,1,"getDocumentSettings",vR,Q);te(J,1,"getInstanceState",SR,Q);te(J,1,"getOpenMenus",yR,Q);te(J,1,"getIsMenuOpen",mR,Q);te(J,1,"getPageStates",gR,Q);te(J,1,"_getPageStatesQuery",fR,Q);te(J,1,"getCurrentPageState",pR,Q);te(J,1,"_getCurrentPageStateId",hR,Q);te(J,1,"getSelectedShapeIds",dR,Q);te(J,1,"getSelectedShapes",uR,Q);te(J,1,"getOnlySelectedShapeId",cR,Q);te(J,1,"getOnlySelectedShape",lR,Q);te(J,1,"getSelectionPageBounds",aR,Q);te(J,1,"getSelectionRotation",iR,Q);te(J,1,"getSelectionRotatedPageBounds",sR,Q);te(J,1,"getSelectionRotatedScreenBounds",oR,Q);te(J,1,"getFocusedGroupId",rR,Q);te(J,1,"getFocusedGroup",nR,Q);te(J,1,"getEditingShapeId",tR,Q);te(J,1,"getEditingShape",eR,Q);te(J,1,"getHoveredShapeId",JD,Q);te(J,1,"getHoveredShape",QD,Q);te(J,1,"getHintingShapeIds",ZD,Q);te(J,1,"getHintingShape",qD,Q);te(J,1,"getErasingShapeIds",XD,Q);te(J,1,"getErasingShapes",YD,Q);te(J,1,"_unsafe_getCameraId",VD,Q);te(J,1,"getCamera",GD,Q);te(J,1,"getViewportPageBoundsForFollowing",WD,Q);te(J,1,"getCameraForFollowing",KD,Q);te(J,1,"getZoomLevel",HD,Q);te(J,1,"getViewportScreenBounds",UD,Q);te(J,1,"getViewportScreenCenter",BD,Q);te(J,1,"getViewportPageBounds",zD,Q);te(J,1,"_getCollaboratorsQuery",ND,Q);te(J,1,"getCollaborators",FD,Q);te(J,1,"getCollaboratorsOnCurrentPage",$D,Q);te(J,1,"getRenderingShapes",LD,Q);te(J,1,"_getAllPagesQuery",RD,Q);te(J,1,"getPages",DD,Q);te(J,1,"getCurrentPageId",OD,Q);te(J,1,"getCurrentPageShapeIdsSorted",jD,Q);te(J,1,"_getAllAssetsQuery",AD,Q);te(J,1,"_getShapeGeometryCache",MD,Q);te(J,1,"_getShapeHandlesCache",TD,Q);te(J,1,"_getShapePageTransformCache",kD,Q);te(J,1,"_getShapePageBoundsCache",ED,Q);te(J,1,"_getShapeClipPathCache",ID,Q);te(J,1,"_getShapeMaskCache",_D,Q);te(J,1,"_getShapeMaskedPageBoundsCache",CD,Q);te(J,1,"_notVisibleShapes",PD,Q);te(J,1,"getCulledShapes",bD,Q);te(J,1,"getCurrentPageBounds",wD,Q);te(J,1,"getCurrentPageShapes",xD,Q);te(J,1,"getCurrentPageShapesSorted",vD,Q);te(J,1,"getCurrentPageRenderingShapesSorted",SD,Q);te(J,1,"_getBindingsIndexCache",yD,Q);te(J,1,"_getSelectionSharedStyles",mD,Q);te(J,1,"getSharedStyles",gD,Q);te(J,1,"getSharedOpacity",fD,Q);te(J,1,"getIsFocused",pD,Q);te(J,1,"getIsReadonly",hD,Q);te(J,1,"_setShiftKeyTimeout",dD,Q);te(J,1,"_setAltKeyTimeout",uD,Q);te(J,1,"_setCtrlKeyTimeout",cD,Q);te(J,1,"_setMetaKeyTimeout",lD,Q);QJ(J,Q);function yh(t,e=t.getCurrentPageId()){const n=t.getPage(e).name;t.emit("max-shapes",{name:n,pageId:e,count:t.options.maxShapesPerPage})}function yo(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 IR(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++)IR(t,o[s],n)}function EI(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(lx(o))},{history:"ignore"}),r.ok)return r.value;throw r.error}function kI(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 Sd(){const t=z(),e=fd();return H("isDarkMode",()=>(e==null?void 0:e.isDarkMode)??t.user.getIsDarkMode(),[e,t])}const TI="<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'/>",MI="<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'/>",Sh='<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 Rs(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 eee=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],tee={none:()=>"none","ew-resize":(t,e,n)=>Rs(MI,t,0,e,n),"ns-resize":(t,e,n)=>Rs(MI,t,90,e,n),"nesw-resize":(t,e,n)=>Rs(TI,t,0,e,n),"nwse-resize":(t,e,n)=>Rs(TI,t,90,e,n),"nwse-rotate":(t,e,n)=>Rs(Sh,t,0,e,n),"nesw-rotate":(t,e,n)=>Rs(Sh,t,90,e,n),"senw-rotate":(t,e,n)=>Rs(Sh,t,180,e,n),"swne-rotate":(t,e,n)=>Rs(Sh,t,270,e,n)};function rr(t,e=0,n="black"){return tee[t](XY(e),!1,n)}function nee(){const t=z(),e=Mt(),n=Sd();ii("useCursor",()=>{const{type:r,rotation:o}=t.getInstanceState().cursor;if(eee.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",rr(r,o,n?"white":"black"))},[t,e,n])}function ree(){const t=z(),e=Mt(),n=Sd(),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 oee(){const[t,e]=w.useState(0);w.useEffect(()=>e(n=>n+1),[])}const see=t=>t.props.src,iee={upload:(t,e)=>cs.blobToDataUrl(e)};function aee(t){return"schema"in t&&t.schema?t.schema:FY({shapes:"shapeUtils"in t&&t.shapeUtils?AI(jj(t.shapeUtils)):void 0,bindings:"bindingUtils"in t&&t.bindingUtils?AI(Tj(t.bindingUtils)):void 0,migrations:"migrations"in t?t.migrations:void 0})}function Bu({initialData:t,defaultName:e="",id:n,assets:r=iee,onMount:o,collaboration:s,...i}={}){const a=aee(i),l=new Gw({id:n,schema:a,initialData:t,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??see},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");Ej(l,i.snapshot)}return l}function AI(t){return Object.fromEntries(t.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}const lee=(t,e)=>e.some(n=>t instanceof n);let jI,OI;function cee(){return jI||(jI=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function uee(){return OI||(OI=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const ER=new WeakMap,Ix=new WeakMap,kR=new WeakMap,Vy=new WeakMap,I1=new WeakMap;function dee(t){const e=new Promise((n,r)=>{const o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{n(hs(t.result)),o()},i=()=>{r(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return e.then(n=>{n instanceof IDBCursor&&ER.set(n,t)}).catch(()=>{}),I1.set(e,t),e}function hee(t){if(Ix.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)});Ix.set(t,e)}let Ex={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return Ix.get(t);if(e==="objectStoreNames")return t.objectStoreNames||kR.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return hs(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 pee(t){Ex=t(Ex)}function fee(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...n){const r=t.call(Yy(this),e,...n);return kR.set(r,e.sort?e.sort():[e]),hs(r)}:uee().includes(t)?function(...e){return t.apply(Yy(this),e),hs(ER.get(this))}:function(...e){return hs(t.apply(Yy(this),e))}}function gee(t){return typeof t=="function"?fee(t):(t instanceof IDBTransaction&&hee(t),lee(t,cee())?new Proxy(t,Ex):t)}function hs(t){if(t instanceof IDBRequest)return dee(t);if(Vy.has(t))return Vy.get(t);const e=gee(t);return e!==t&&(Vy.set(t,e),I1.set(e,t)),e}const Yy=t=>I1.get(t);function TR(t,e,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(t,e),a=hs(i);return r&&i.addEventListener("upgradeneeded",l=>{r(hs(i.result),l.oldVersion,l.newVersion,hs(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 MR(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);return e&&n.addEventListener("blocked",r=>e(r.oldVersion,r)),hs(n).then(()=>{})}const mee=["get","getKey","getAll","getAllKeys","count"],yee=["put","add","delete","clear"],Xy=new Map;function DI(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(Xy.get(e))return Xy.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,o=yee.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(o||mee.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 Xy.set(e,s),s}pee(t=>({...t,get:(e,n,r)=>DI(e,n)||t.get(e,n,r),has:(e,n)=>!!DI(e,n)||t.has(e,n)}));const See="TLDRAW_DOCUMENT_v2",vee="TLDRAW_ASSET_STORE_v1",AR="TLDRAW_DB_NAME_INDEX_v2",_e={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function jR(t){const e=See+t;return wee(e),await TR(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 xee(t){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(p=>p.name):E1(),n=vee+t;if(!e.find(p=>p===n))return;const o=await TR(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 jR(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 MR(n)}const fu=class fu{constructor(e){E(this,"getDbPromise");E(this,"isClosed",!1);E(this,"pendingTransactionSet",new Set);fu.connectedInstances.add(this),this.getDbPromise=(async()=>(await xee(e),await jR(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Ou)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),fu.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(fu,"connectedInstances",new Set);let Df=fu;function E1(){const t=JSON.parse(xw(AR)||"[]")??[];return Array.isArray(t)?t:[]}function wee(t){const e=new Set(E1());e.add(t),ww(AR,JSON.stringify([...e]))}function bee(){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 Cee=350,_ee=1e4,RI=Symbol("UPDATE_INSTANCE_STATE"),Iee=t=>t;class Eee{constructor(e){E(this,"onmessage")}postMessage(e){}close(){}}const kee=typeof BroadcastChannel>"u"?Eee:BroadcastChannel;class Tee{constructor(e,{persistenceKey:n,sessionId:r=Of,onLoad:o,onLoadError:s},i=new kee(`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 Df(n),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=f1(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(Iee({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(RI),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??CZ(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&&Sx(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"),Ao(()=>{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?_ee:Cee))}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!==RI));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),bee(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function OR(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 Mee(t){const[e,n]=OR({status:"loading"});return t=Ql(t),w.useEffect(()=>{const{persistenceKey:r,sessionId:o,...s}=t;if(!r){n({status:"not-synced",store:Bu(s)});return}n({status:"loading"});const i=new Oo,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=Bu({...s,assets:a});let c=!1;const u=new Tee(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 Aee(){const t=z(),e=Mt();w.useEffect(()=>{const n=s=>e.style.setProperty("--tl-zoom",s.toString()),r=gg(n,100),o=new Xl("useZoomCss",()=>{t.getCurrentPageShapeIds().size<300?n(t.getZoomLevel()):r(t.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[t,e])}function kx(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 jee(t){const e=atob(t),n=kx(e);return crypto.subtle.importKey("spki",new Uint8Array(n),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const Oee=5,Kc={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},Dee=Math.max(...Object.values(Kc)),Wc={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},Ree=Object.keys(Wc).length,qy="sales@tldraw.com",Lee=`${Zs()}/watermarks/watermark-track.svg`;class Wg{constructor(e,n,r){E(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");E(this,"isDevelopment");E(this,"isTest");E(this,"isCryptoAvailable");E(this,"state",Et("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=$ee(o);!this.isDevelopment&&s&&oo(Lee),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 jee(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(kx(atob(r))),new Uint8Array(kx(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>Ree&&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[Wc.ID],hosts:l[Wc.HOSTS],flags:l[Wc.FLAGS],expiryDate:l[Wc.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,Kc.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,Kc.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,Kc.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,Kc.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()+Oee+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 ${qy} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const n=this.getExpirationDateWithGracePeriod(e),r={major:new Date(K_.major),minor:new Date(K_.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 ${qy} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${qy} if you would like to use tldraw on other domains.`]),e.license.flags>=Dee*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(Wg,"className","tl-watermark_SEE-LICENSE");function $ee(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 DR=w.createContext({}),Fee=()=>w.useContext(DR);function Nee({licenseKey:t,children:e}){const[n]=w.useState(()=>new Wg(t));return d.jsx(DR.Provider,{value:n,children:e})}function ki(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 zee='<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>',Bee='<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 Uee(t){return H("watermarkState",()=>t.state.get(),[t])}const Hee=`data:image/svg+xml;utf8,${encodeURIComponent(zee)}`,Kee=`data:image/svg+xml;utf8,${encodeURIComponent(Bee)}`,Wee=w.memo(function(){const e=Fee(),n=z(),r=H("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),o=Uee(e);return["licensed-with-watermark","unlicensed"].includes(o)?d.jsxs(d.Fragment,{children:[d.jsx(Vee,{}),d.jsx(Gee,{src:r?Kee:Hee})]}):null}),Gee=w.memo(function({src:e}){const n=z(),r=H("debug mode",()=>n.getInstanceState().isDebugMode,[n]),o=H("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),s=c1(),i=w.useRef(null);ki(i);const a=`url('${e}') center 100% / 100% no-repeat`,l="https://tldraw.dev";return d.jsx("div",{ref:i,className:Wg.className,"data-debug":r,"data-mobile":o,draggable:!1,...s,children:Ge.isWebview?d.jsx("a",{draggable:!1,role:"button",onPointerDown:c=>{_t(c),xe(c)},onClick:()=>Og.openWindow(l,"_blank"),style:{mask:a,WebkitMask:a}}):d.jsx("a",{href:l,target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:c=>{_t(c)},style:{mask:a,WebkitMask:a}})})}),Vee=w.memo(function(){const e=Wg.className,n=`/* ------------------- SEE LICENSE -------------------
|
|
114
|
-
The tldraw watermark is part of tldraw's license. It is shown for unlicensed
|
|
115
|
-
or "licensed-with-watermark" users. By using this library, you agree to
|
|
116
|
-
preserve the watermark's behavior, keeping it visible, unobscured, and
|
|
117
|
-
available to user-interaction.
|
|
118
|
-
|
|
119
|
-
To remove the watermark, please purchase a license at tldraw.dev.
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
.${e} {
|
|
123
|
-
position: absolute;
|
|
124
|
-
bottom: var(--space-2);
|
|
125
|
-
right: var(--space-2);
|
|
126
|
-
width: 96px;
|
|
127
|
-
height: 32px;
|
|
128
|
-
display: flex;
|
|
129
|
-
align-items: center;
|
|
130
|
-
justify-content: center;
|
|
131
|
-
z-index: var(--layer-watermark) !important;
|
|
132
|
-
background-color: color-mix(in srgb, var(--color-background) 62%, transparent);
|
|
133
|
-
opacity: 1;
|
|
134
|
-
border-radius: 5px;
|
|
135
|
-
pointer-events: all;
|
|
136
|
-
padding: 2px;
|
|
137
|
-
box-sizing: content-box;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
.${e} > a {
|
|
141
|
-
position: absolute;
|
|
142
|
-
width: 96px;
|
|
143
|
-
height: 32px;
|
|
144
|
-
pointer-events: all;
|
|
145
|
-
cursor: inherit;
|
|
146
|
-
color: var(--color-text);
|
|
147
|
-
opacity: .38;
|
|
148
|
-
background-color: currentColor;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.${e}[data-debug='true'] {
|
|
152
|
-
bottom: 46px;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
.${e}[data-mobile='true'] {
|
|
156
|
-
border-radius: 4px 0px 0px 4px;
|
|
157
|
-
right: -2px;
|
|
158
|
-
width: 8px;
|
|
159
|
-
height: 48px;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
.${e}[data-mobile='true'] > a {
|
|
163
|
-
width: 8px;
|
|
164
|
-
height: 32px;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@media (hover: hover) {
|
|
168
|
-
.${e} > a {
|
|
169
|
-
pointer-events: none;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
.${e}:hover {
|
|
173
|
-
background-color: var(--color-background);
|
|
174
|
-
transition: background-color 0.2s ease-in-out;
|
|
175
|
-
transition-delay: 0.32s;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
.${e}:hover > a {
|
|
179
|
-
animation: delayed_link 0.2s forwards ease-in-out;
|
|
180
|
-
animation-delay: 0.32s;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
@keyframes delayed_link {
|
|
185
|
-
0% {
|
|
186
|
-
cursor: inherit;
|
|
187
|
-
opacity: .38;
|
|
188
|
-
pointer-events: none;
|
|
189
|
-
}
|
|
190
|
-
100% {
|
|
191
|
-
cursor: pointer;
|
|
192
|
-
opacity: 1;
|
|
193
|
-
pointer-events: all;
|
|
194
|
-
}
|
|
195
|
-
}`;return d.jsx("style",{children:n})}),Yee=[],Xee=[],qee=[],Zee="tl-container",Qee=w.memo(function({store:e,components:n,className:r,user:o,options:s,...i}){const[a,l]=w.useState(null),c=w.useMemo(()=>o??Pj(),[o]),u=(n==null?void 0:n.ErrorFallback)===void 0?fj:n==null?void 0:n.ErrorFallback,h={...i,shapeUtils:i.shapeUtils??Yee,bindingUtils:i.bindingUtils??Xee,tools:i.tools??qee,components:n,options:Ql(s)};return d.jsx("div",{ref:l,"data-tldraw":BA,draggable:!1,className:le(`${Zee} tl-theme__light`,r),onPointerDown:_t,tabIndex:-1,children:d.jsx(zu,{fallback:u,onError:p=>gw(p,{tags:{origin:"react.tldraw-before-app"}}),children:a&&d.jsx(Nee,{licenseKey:i.licenseKey,children:d.jsx(sX,{container:a,children:d.jsx(cZ,{overrides:n,children:e?e instanceof Gw?d.jsx(LR,{...h,store:e,user:c}):d.jsx(RR,{...h,store:e,user:c}):d.jsx(Jee,{...h,store:e,user:c})})})})})})});function Jee(t){const{defaultName:e,snapshot:n,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:l,assets:c}=t,u=Mee({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:n,assets:c});return d.jsx(RR,{...t,store:u,user:l})}const RR=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(LR,{...r,store:e.store,user:n})}),Zy=()=>document.location.search.includes("tldraw_preserve_focus");function LR({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:m}){const{ErrorFallback:g}=ot(),v=Mt(),[S,y]=OR(null),P=w.useRef(null),b=Ql(f===!0?{}:f),C=w.useRef({autoFocus:l&&!Zy(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:b});w.useLayoutEffect(()=>{C.current={autoFocus:l&&!Zy(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:b}},[l,c,a,u,b]),w.useLayoutEffect(()=>{const{autoFocus:_,inferDarkMode:M,initialState:T,cameraOptions:D,deepLinks:A}=C.current,O=new Q({store:n,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>v,user:i,initialState:T,autoFocus:_,inferDarkMode:M,cameraOptions:D,options:h,licenseKey:p,isShapeHidden:m});return O.updateViewportScreenBounds(P.current??v),A&&(A!=null&&A.getUrl?O.navigateToDeepLink({...A,url:A.getUrl(O)}):O.navigateToDeepLink(A)),y(O),()=>{O.dispose()}},[s,v,h,o,n,r,i,y,p,m]),w.useLayoutEffect(()=>{if(S&&b)return S.registerDeepLinkListener(b)},[S,b]),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 M(){S&&S.focus()}function T(){S&&S.blur()}if(l&&Zy())return S.getContainer().addEventListener("pointerdown",M),document.body.addEventListener("pointerdown",T),()=>{var D;(D=S.getContainer())==null||D.removeEventListener("pointerdown",M),document.body.removeEventListener("pointerdown",T)}},[S,l]);const{Canvas:k}=ot();return S?d.jsx(zu,{fallback:g,onError:_=>S.annotateError(_,{origin:"react.tldraw",willCrashApp:!0}),children:I?d.jsx(tte,{crashingError:I}):d.jsx(i1,{editor:S,children:d.jsxs(ete,{onMount:t,children:[e??(k?d.jsx(k,{}):null),d.jsx(Wee,{})]})})}):d.jsx("div",{className:"tl-canvas",ref:P})}function ete({children:t,onMount:e}){return Aee(),nee(),ree(),oee(),FR(n=>{const r=n.store.props.onMount(n),o=e==null?void 0:e(n);return()=>{r==null||r(),o==null||o()}}),t}function tte({crashingError:t}){throw t}function k1({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function $R({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function FR(t){const e=z(),n=Ng(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 ci({children:t,className:e="",...n}){return d.jsx("div",{...n,className:le("tl-html-container",e),children:t})}class lp{constructor(e){this.editor=e}}E(lp,"props"),E(lp,"migrations"),E(lp,"type");function Gg(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:m,y:g}=f.rot(t.rotation).add(r);return{...t,x:m,y:g,props:{w:Math.min(l,h),h:Math.min(u,p)}}}class nc extends no{getGeometry(e){return new vs({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,n){return Gg(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 kS;let nte=(kS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(kS,"id","idle"),kS);var TS;let rte=(TS=class extends ie{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=this.parent.shapeType,o=Ke(),s=this.editor.markHistoryStoppingPoint(`creating_box:${o}`);this.editor.createShapes([{id:o,type:r,x:n.x,y:n.y,props:{w:1,h:1}}]).select(o);const i=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:s,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:i.onCreate?a=>{var l;return(l=i.onCreate)==null?void 0:l.call(i,a)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,n=this.parent.shapeType,r=Ke();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:n,x:e.x,y:e.y}]);const o=this.editor.getShape(r);if(!o){this.cancel();return}let{w:s,h:i}=o.props;const a=new x(s/2,i/2),l=this.editor.getShapeParentTransform(o);l&&a.rot(-l.rotation());let c=1;this.editor.user.getIsDynamicResizeMode()&&(c=1/this.editor.getZoomLevel(),s*=c,i*=c,a.mul(c));const u=nt(o);u.x=o.x-a.x,u.y=o.y-a.y,u.props.w=s,u.props.h=i,"scale"in o.props&&(u.props.scale=c),this.editor.updateShape(u),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},E(TS,"id","pointing"),TS);class Tx extends ie{static children(){return[nte,rte]}}E(Tx,"id","box"),E(Tx,"initial","idle");function ote(t,e,n){const r=w.useRef(!1),o=w.useCallback(i=>{r.current=i,i?Gr.addOpenMenu(t):Gr.deleteOpenMenu(t),e==null||e(i)},[t,e]),s=H("is menu open",()=>Gr.getOpenMenus().includes(t),[t]);return w.useEffect(()=>(r.current&&(n==null||n("open-menu"),Gr.addOpenMenu(t)),()=>{r.current&&(Gr.deleteOpenMenu(t),Gr.getOpenMenus().forEach(i=>{i.startsWith(t)&&(n==null||n("close-menu"),Gr.deleteOpenMenu(i))}),r.current=!1)}),[t,n]),[s,o]}function Vg(t){const e=z();return H("isEditing",()=>e.getEditingShapeId()===t,[e,t])}function xo(t){const e=z();return w.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===l1){e.dispatch({type:"pointer",target:"selection",handle:t,name:"right_click",...Wn(c)});return}if(c.button!==0)return;const u=Af(c.currentTarget);function h(){u.removeEventListener("pointerup",h),ud(u,c)}cd(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:t,...Wn(c)}),_t(c)};let s,i;function a(c){c.isKilled||c.button===0&&(c.clientX===s&&c.clientY===i||(s=c.clientX,i=c.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:t,...Wn(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:t,...Wn(c)})}}},[e,t])}function ste(t){const[e,n]=w.useState(()=>({store:Bu(t),opts:t}));if(!ET(e.opts,t)){const r={store:Bu(t),opts:t};return n(r),r.store}return e.store}const ite=20,ate=8;function T1(t,e=ite){return Math.max(ate,Math.ceil(t/e))}class sl extends Ei{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=qY(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=fx(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,m;for(const g of[l,c,h])m=x.Dist2(n,g),m<f&&(p=g,f=m);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=pd(n,r,o,s);return c===null?!1:c.some(u=>{const h=fx(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=T1(Math.abs(o));l<c+1;l++){const u=l/c*r,h=i+u;a.push(la(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 M1 extends Ei{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=T1(o);i<a;i++){const l=i/a*Ne;s.push(la(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 pd(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 Jl{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 lte extends Ei{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),m=c;this._segments.push(new an({start:h,cp1:p,cp2:f,end:m}))}}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 cte extends Ei{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 is({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=T1(a),c=Ne/l,u=Math.cos(c),h=Math.sin(c);let p=0,f=1,m=0,g=1;const v=Array(l);for(let S=0;S<l;S++)v[S]=new x(o+o*f,s+s*p),m=h*f+u*p,g=u*f-h*p,p=m,f=g;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 HA(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 ute extends Ei{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 sl({start:new x(0,s),end:new x(r,s),center:new x(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new is({start:new x(r,s),end:new x(r,o-s)}),this.c=new sl({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 is({start:new x(0,o-s),end:new x(0,s)})}else{const s=o/2;this.a=new sl({start:new x(s,o),end:new x(s,0),center:new x(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new is({start:new x(s,0),end:new x(r-s,0)}),this.c=new sl({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 is({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 dte({shouldReload:t=!0}={}){e7();for(const e of Df.connectedInstances)await e.close();await Promise.all(E1().map(e=>MR(e))),J9(),t&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=dte);function hte(t,e="_blank"){Og.openWindow(t,e)}Pi("@tldraw/editor","3.4.1","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 pte(t,e){typeof t=="function"?t(e):t!=null&&(t.current=e)}function Yg(...t){return e=>t.forEach(n=>pte(n,e))}function Qe(...t){return w.useCallback(Yg(...t),t)}function fte(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 ba(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,...m}=h,g=((S=p==null?void 0:p[t])==null?void 0:S[l])||a,v=w.useMemo(()=>m,Object.values(m));return d.jsx(g.Provider,{value:v,children:f})};c.displayName=s+"Provider";function u(h,p){var g;const f=((g=p==null?void 0:p[t])==null?void 0:g[l])||a,m=w.useContext(f);if(m)return m;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,gte(o,...e)]}function gte(...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 gi=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{},mte=KN.useId||(()=>{}),yte=0;function ps(t){const[e,n]=w.useState(mte());return gi(()=>{t||n(r=>r??String(yte++))},[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 Ti({prop:t,defaultProp:e,onChange:n=()=>{}}){const[r,o]=Ste({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 Ste({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 ca=w.forwardRef((t,e)=>{const{children:n,...r}=t,o=w.Children.toArray(n),s=o.find(xte);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(Mx,{...r,ref:e,children:w.isValidElement(i)?w.cloneElement(i,void 0,a):null})}return d.jsx(Mx,{...r,ref:e,children:n})});ca.displayName="Slot";var Mx=w.forwardRef((t,e)=>{const{children:n,...r}=t;if(w.isValidElement(n)){const o=bte(n);return w.cloneElement(n,{...wte(r,n.props),ref:e?Yg(e,o):o})}return w.Children.count(n)>1?w.Children.only(null):null});Mx.displayName="SlotClone";var vte=({children:t})=>d.jsx(d.Fragment,{children:t});function xte(t){return w.isValidElement(t)&&t.type===vte}function wte(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 bte(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?ca: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 A1(t,e){t&&hi.flushSync(()=>t.dispatchEvent(e))}function Cte(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 _te="DismissableLayer",Ax="dismissableLayer.update",Ite="dismissableLayer.pointerDownOutside",Ete="dismissableLayer.focusOutside",LI,NR=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),vd=w.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=t,c=w.useContext(NR),[u,h]=w.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=w.useState({}),m=Qe(e,k=>h(k)),g=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=g.indexOf(v),y=u?g.indexOf(u):-1,P=c.layersWithOutsidePointerEventsDisabled.size>0,b=y>=S,C=Tte(k=>{const _=k.target,M=[...c.branches].some(T=>T.contains(_));!b||M||(o==null||o(k),i==null||i(k),k.defaultPrevented||a==null||a())},p),I=Mte(k=>{const _=k.target;[...c.branches].some(T=>T.contains(_))||(s==null||s(k),i==null||i(k),k.defaultPrevented||a==null||a())},p);return Cte(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&&(LI=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),$I(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=LI)}},[u,p,n,c]),w.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),$I())},[u,c]),w.useEffect(()=>{const k=()=>f({});return document.addEventListener(Ax,k),()=>document.removeEventListener(Ax,k)},[]),d.jsx(Ae.div,{...l,ref:m,style:{pointerEvents:P?b?"auto":"none":void 0,...t.style},onFocusCapture:oe(t.onFocusCapture,I.onFocusCapture),onBlurCapture:oe(t.onBlurCapture,I.onBlurCapture),onPointerDownCapture:oe(t.onPointerDownCapture,C.onPointerDownCapture)})});vd.displayName=_te;var kte="DismissableLayerBranch",zR=w.forwardRef((t,e)=>{const n=w.useContext(NR),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})});zR.displayName=kte;function Tte(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(){BR(Ite,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 Mte(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&&BR(Ete,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 $I(){const t=new CustomEvent(Ax);document.dispatchEvent(t)}function BR(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?A1(o,s):o.dispatchEvent(s)}var Ate=vd,jte=zR,Qy="focusScope.autoFocusOnMount",Jy="focusScope.autoFocusOnUnmount",FI={bubbles:!1,cancelable:!0},Ote="FocusScope",Xg=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,g=>l(g)),f=w.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;w.useEffect(()=>{if(r){let g=function(P){if(f.paused||!a)return;const b=P.target;a.contains(b)?h.current=b:Fs(h.current,{select:!0})},v=function(P){if(f.paused||!a)return;const b=P.relatedTarget;b!==null&&(a.contains(b)||Fs(h.current,{select:!0}))},S=function(P){if(document.activeElement===document.body)for(const C of P)C.removedNodes.length>0&&Fs(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",v);const y=new MutationObserver(S);return a&&y.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",v),y.disconnect()}}},[r,a,f.paused]),w.useEffect(()=>{if(a){zI.add(f);const g=document.activeElement;if(!a.contains(g)){const S=new CustomEvent(Qy,FI);a.addEventListener(Qy,c),a.dispatchEvent(S),S.defaultPrevented||(Dte(Nte(UR(a)),{select:!0}),document.activeElement===g&&Fs(a))}return()=>{a.removeEventListener(Qy,c),setTimeout(()=>{const S=new CustomEvent(Jy,FI);a.addEventListener(Jy,u),a.dispatchEvent(S),S.defaultPrevented||Fs(g??document.body,{select:!0}),a.removeEventListener(Jy,u),zI.remove(f)},0)}}},[a,c,u,f]);const m=w.useCallback(g=>{if(!n&&!r||f.paused)return;const v=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,S=document.activeElement;if(v&&S){const y=g.currentTarget,[P,b]=Rte(y);P&&b?!g.shiftKey&&S===b?(g.preventDefault(),n&&Fs(P,{select:!0})):g.shiftKey&&S===P&&(g.preventDefault(),n&&Fs(b,{select:!0})):S===y&&g.preventDefault()}},[n,r,f.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:p,onKeyDown:m})});Xg.displayName=Ote;function Dte(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Fs(r,{select:e}),document.activeElement!==n)return}function Rte(t){const e=UR(t),n=NI(e,t),r=NI(e.reverse(),t);return[n,r]}function UR(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 NI(t,e){for(const n of t)if(!Lte(n,{upTo:e}))return n}function Lte(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 $te(t){return t instanceof HTMLInputElement&&"select"in t}function Fs(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&$te(t)&&e&&t.select()}}var zI=Fte();function Fte(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=BI(t,e),t.unshift(e)},remove(e){var n;t=BI(t,e),(n=t[0])==null||n.resume()}}}function BI(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function Nte(t){return t.filter(e=>e.tagName!=="A")}var zte="Portal",xd=w.forwardRef((t,e)=>{var a;const{container:n,...r}=t,[o,s]=w.useState(!1);gi(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?t8.createPortal(d.jsx(Ae.div,{...r,ref:e}),i):null});xd.displayName=zte;function Bte(t,e){return w.useReducer((n,r)=>e[n][r]??n,t)}var uo=t=>{const{present:e,children:n}=t,r=Ute(e),o=typeof n=="function"?n({present:r.isPresent}):w.Children.only(n),s=Qe(r.ref,Hte(o));return typeof n=="function"||r.isPresent?w.cloneElement(o,{ref:s}):null};uo.displayName="Presence";function Ute(t){const[e,n]=w.useState(),r=w.useRef({}),o=w.useRef(t),s=w.useRef("none"),i=t?"mounted":"unmounted",[a,l]=Bte(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=vh(r.current);s.current=a==="mounted"?c:"none"},[a]),gi(()=>{const c=r.current,u=o.current;if(u!==t){const p=s.current,f=vh(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]),gi(()=>{if(e){let c;const u=e.ownerDocument.defaultView??window,h=f=>{const g=vh(r.current).includes(f.animationName);if(f.target===e&&g&&(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=vh(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 vh(t){return(t==null?void 0:t.animationName)||"none"}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 eS=0;function j1(){w.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??UI()),document.body.insertAdjacentElement("beforeend",t[1]??UI()),eS++,()=>{eS===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),eS--}},[])}function UI(){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 Po=function(){return Po=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},Po.apply(this,arguments)};function HR(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 Kte(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 cp="right-scroll-bar-position",up="width-before-scroll-bar",Wte="with-scroll-bars-hidden",Gte="--removed-body-scroll-bar-size";function tS(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function Vte(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 Yte=typeof window<"u"?w.useLayoutEffect:w.useEffect,HI=new WeakMap;function Xte(t,e){var n=Vte(null,function(r){return t.forEach(function(o){return tS(o,r)})});return Yte(function(){var r=HI.get(n);if(r){var o=new Set(r),s=new Set(t),i=n.current;o.forEach(function(a){s.has(a)||tS(a,null)}),s.forEach(function(a){o.has(a)||tS(a,i)})}HI.set(n,t)},[t]),n}function qte(t){return t}function Zte(t,e){e===void 0&&(e=qte);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 Qte(t){t===void 0&&(t={});var e=Zte(null);return e.options=Po({async:!0,ssr:!1},t),e}var KR=function(t){var e=t.sideCar,n=HR(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,Po({},n))};KR.isSideCarExport=!0;function Jte(t,e){return t.useMedium(e),KR}var WR=Qte(),nS=function(){},qg=w.forwardRef(function(t,e){var n=w.useRef(null),r=w.useState({onScrollCapture:nS,onWheelCapture:nS,onTouchMoveCapture:nS}),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,m=t.inert,g=t.allowPinchZoom,v=t.as,S=v===void 0?"div":v,y=t.gapMode,P=HR(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),b=p,C=Xte([n,e]),I=Po(Po({},P),o);return w.createElement(w.Fragment,null,u&&w.createElement(b,{sideCar:WR,removeScrollBar:c,shards:h,noIsolation:f,inert:m,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:y}),i?w.cloneElement(w.Children.only(a),Po(Po({},I),{ref:C})):w.createElement(S,Po({},I,{className:l,ref:C}),a))});qg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};qg.classNames={fullWidth:up,zeroRight:cp};var ene=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function tne(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=ene();return e&&t.setAttribute("nonce",e),t}function nne(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function rne(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var one=function(){var t=0,e=null;return{add:function(n){t==0&&(e=tne())&&(nne(e,n),rne(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},sne=function(){var t=one();return function(e,n){w.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},GR=function(){var t=sne(),e=function(n){var r=n.styles,o=n.dynamic;return t(r,o),null};return e},ine={left:0,top:0,right:0,gap:0},rS=function(t){return parseInt(t||"",10)||0},ane=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[rS(n),rS(r),rS(o)]},lne=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return ine;var e=ane(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])}},cne=GR(),xl="data-scroll-locked",une=function(t,e,n,r){var o=t.left,s=t.top,i=t.right,a=t.gap;return n===void 0&&(n="margin"),`
|
|
196
|
-
.`.concat(Wte,` {
|
|
197
|
-
overflow: hidden `).concat(r,`;
|
|
198
|
-
padding-right: `).concat(a,"px ").concat(r,`;
|
|
199
|
-
}
|
|
200
|
-
body[`).concat(xl,`] {
|
|
201
|
-
overflow: hidden `).concat(r,`;
|
|
202
|
-
overscroll-behavior: contain;
|
|
203
|
-
`).concat([e&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
204
|
-
padding-left: `.concat(o,`px;
|
|
205
|
-
padding-top: `).concat(s,`px;
|
|
206
|
-
padding-right: `).concat(i,`px;
|
|
207
|
-
margin-left:0;
|
|
208
|
-
margin-top:0;
|
|
209
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
210
|
-
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
.`).concat(cp,` {
|
|
214
|
-
right: `).concat(a,"px ").concat(r,`;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
.`).concat(up,` {
|
|
218
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
.`).concat(cp," .").concat(cp,` {
|
|
222
|
-
right: 0 `).concat(r,`;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
.`).concat(up," .").concat(up,` {
|
|
226
|
-
margin-right: 0 `).concat(r,`;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
body[`).concat(xl,`] {
|
|
230
|
-
`).concat(Gte,": ").concat(a,`px;
|
|
231
|
-
}
|
|
232
|
-
`)},KI=function(){var t=parseInt(document.body.getAttribute(xl)||"0",10);return isFinite(t)?t:0},dne=function(){w.useEffect(function(){return document.body.setAttribute(xl,(KI()+1).toString()),function(){var t=KI()-1;t<=0?document.body.removeAttribute(xl):document.body.setAttribute(xl,t.toString())}},[])},hne=function(t){var e=t.noRelative,n=t.noImportant,r=t.gapMode,o=r===void 0?"margin":r;dne();var s=w.useMemo(function(){return lne(o)},[o]);return w.createElement(cne,{styles:une(s,!e,o,n?"":"!important")})},jx=!1;if(typeof window<"u")try{var xh=Object.defineProperty({},"passive",{get:function(){return jx=!0,!0}});window.addEventListener("test",xh,xh),window.removeEventListener("test",xh,xh)}catch{jx=!1}var Da=jx?{passive:!1}:!1,pne=function(t){return t.tagName==="TEXTAREA"},VR=function(t,e){if(!(t instanceof Element))return!1;var n=window.getComputedStyle(t);return n[e]!=="hidden"&&!(n.overflowY===n.overflowX&&!pne(t)&&n[e]==="visible")},fne=function(t){return VR(t,"overflowY")},gne=function(t){return VR(t,"overflowX")},WI=function(t,e){var n=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=YR(t,r);if(o){var s=XR(t,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},mne=function(t){var e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;return[e,n,r]},yne=function(t){var e=t.scrollLeft,n=t.scrollWidth,r=t.clientWidth;return[e,n,r]},YR=function(t,e){return t==="v"?fne(e):gne(e)},XR=function(t,e){return t==="v"?mne(e):yne(e)},Sne=function(t,e){return t==="h"&&e==="rtl"?-1:1},vne=function(t,e,n,r,o){var s=Sne(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=XR(t,a),m=f[0],g=f[1],v=f[2],S=g-v-s*m;(m||S)&&YR(t,a)&&(h+=S,p+=m),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},wh=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},GI=function(t){return[t.deltaX,t.deltaY]},VI=function(t){return t&&"current"in t?t.current:t},xne=function(t,e){return t[0]===e[0]&&t[1]===e[1]},wne=function(t){return`
|
|
233
|
-
.block-interactivity-`.concat(t,` {pointer-events: none;}
|
|
234
|
-
.allow-interactivity-`).concat(t,` {pointer-events: all;}
|
|
235
|
-
`)},bne=0,Ra=[];function Pne(t){var e=w.useRef([]),n=w.useRef([0,0]),r=w.useRef(),o=w.useState(bne++)[0],s=w.useState(GR)[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 g=Kte([t.lockRef.current],(t.shards||[]).map(VI),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[t.inert,t.lockRef.current,t.shards]);var a=w.useCallback(function(g,v){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var S=wh(g),y=n.current,P="deltaX"in g?g.deltaX:y[0]-S[0],b="deltaY"in g?g.deltaY:y[1]-S[1],C,I=g.target,k=Math.abs(P)>Math.abs(b)?"h":"v";if("touches"in g&&k==="h"&&I.type==="range")return!1;var _=WI(k,I);if(!_)return!0;if(_?C=k:(C=k==="v"?"h":"v",_=WI(k,I)),!_)return!1;if(!r.current&&"changedTouches"in g&&(P||b)&&(r.current=C),!C)return!0;var M=r.current||C;return vne(M,v,g,M==="h"?P:b,!0)},[]),l=w.useCallback(function(g){var v=g;if(!(!Ra.length||Ra[Ra.length-1]!==s)){var S="deltaY"in v?GI(v):wh(v),y=e.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&xne(C.delta,S)})[0];if(y&&y.should){v.cancelable&&v.preventDefault();return}if(!y){var P=(i.current.shards||[]).map(VI).filter(Boolean).filter(function(C){return C.contains(v.target)}),b=P.length>0?a(v,P[0]):!i.current.noIsolation;b&&v.cancelable&&v.preventDefault()}}},[]),c=w.useCallback(function(g,v,S,y){var P={name:g,delta:v,target:S,should:y,shadowParent:Cne(S)};e.current.push(P),setTimeout(function(){e.current=e.current.filter(function(b){return b!==P})},1)},[]),u=w.useCallback(function(g){n.current=wh(g),r.current=void 0},[]),h=w.useCallback(function(g){c(g.type,GI(g),g.target,a(g,t.lockRef.current))},[]),p=w.useCallback(function(g){c(g.type,wh(g),g.target,a(g,t.lockRef.current))},[]);w.useEffect(function(){return Ra.push(s),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,Da),document.addEventListener("touchmove",l,Da),document.addEventListener("touchstart",u,Da),function(){Ra=Ra.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,Da),document.removeEventListener("touchmove",l,Da),document.removeEventListener("touchstart",u,Da)}},[]);var f=t.removeScrollBar,m=t.inert;return w.createElement(w.Fragment,null,m?w.createElement(s,{styles:wne(o)}):null,f?w.createElement(hne,{gapMode:t.gapMode}):null)}function Cne(t){for(var e=null;t!==null;)t instanceof ShadowRoot&&(e=t.host,t=t.host),t=t.parentNode;return e}const _ne=Jte(WR,Pne);var Zg=w.forwardRef(function(t,e){return w.createElement(qg,Po({},t,{ref:e,sideCar:_ne}))});Zg.classNames=qg.classNames;var Ine=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},La=new WeakMap,bh=new WeakMap,Ph={},oS=0,qR=function(t){return t&&(t.host||qR(t.parentNode))},Ene=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=qR(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})},kne=function(t,e,n,r){var o=Ene(e,Array.isArray(t)?t:[t]);Ph[n]||(Ph[n]=new WeakMap);var s=Ph[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),m=f!==null&&f!=="false",g=(La.get(p)||0)+1,v=(s.get(p)||0)+1;La.set(p,g),s.set(p,v),i.push(p),g===1&&m&&bh.set(p,!0),v===1&&p.setAttribute(n,"true"),m||p.setAttribute(r,"true")}catch(S){console.error("aria-hidden: cannot operate on ",p,S)}})};return u(e),a.clear(),oS++,function(){i.forEach(function(h){var p=La.get(h)-1,f=s.get(h)-1;La.set(h,p),s.set(h,f),p||(bh.has(h)||h.removeAttribute(r),bh.delete(h)),f||h.removeAttribute(n)}),oS--,oS||(La=new WeakMap,La=new WeakMap,bh=new WeakMap,Ph={})}},O1=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),o=Ine(t);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),kne(r,o,n,"aria-hidden")):function(){return null}},D1="Dialog",[ZR,Zfe]=ba(D1),[Tne,ho]=ZR(D1),QR=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]=Ti({prop:r,defaultProp:o,onChange:s});return d.jsx(Tne,{scope:e,triggerRef:a,contentRef:l,contentId:ps(),titleId:ps(),descriptionId:ps(),open:c,onOpenChange:u,onOpenToggle:w.useCallback(()=>u(h=>!h),[u]),modal:i,children:n})};QR.displayName=D1;var JR="DialogTrigger",Mne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=ho(JR,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":$1(o.open),...r,ref:s,onClick:oe(t.onClick,o.onOpenToggle)})});Mne.displayName=JR;var R1="DialogPortal",[Ane,e3]=ZR(R1,{forceMount:void 0}),t3=t=>{const{__scopeDialog:e,forceMount:n,children:r,container:o}=t,s=ho(R1,e);return d.jsx(Ane,{scope:e,forceMount:n,children:w.Children.map(r,i=>d.jsx(uo,{present:n||s.open,children:d.jsx(xd,{asChild:!0,container:o,children:i})}))})};t3.displayName=R1;var Rf="DialogOverlay",n3=w.forwardRef((t,e)=>{const n=e3(Rf,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=ho(Rf,t.__scopeDialog);return s.modal?d.jsx(uo,{present:r||s.open,children:d.jsx(jne,{...o,ref:e})}):null});n3.displayName=Rf;var jne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=ho(Rf,n);return d.jsx(Zg,{as:ca,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ae.div,{"data-state":$1(o.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),ua="DialogContent",r3=w.forwardRef((t,e)=>{const n=e3(ua,t.__scopeDialog),{forceMount:r=n.forceMount,...o}=t,s=ho(ua,t.__scopeDialog);return d.jsx(uo,{present:r||s.open,children:s.modal?d.jsx(One,{...o,ref:e}):d.jsx(Dne,{...o,ref:e})})});r3.displayName=ua;var One=w.forwardRef((t,e)=>{const n=ho(ua,t.__scopeDialog),r=w.useRef(null),o=Qe(e,n.contentRef,r);return w.useEffect(()=>{const s=r.current;if(s)return O1(s)},[]),d.jsx(o3,{...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())})}),Dne=w.forwardRef((t,e)=>{const n=ho(ua,t.__scopeDialog),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(o3,{...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()}})}),o3=w.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=t,a=ho(ua,n),l=w.useRef(null),c=Qe(e,l);return j1(),d.jsxs(d.Fragment,{children:[d.jsx(Xg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(vd,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":$1(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(Lne,{titleId:a.titleId}),d.jsx(Fne,{contentRef:l,descriptionId:a.descriptionId})]})]})}),L1="DialogTitle",s3=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=ho(L1,n);return d.jsx(Ae.h2,{id:o.titleId,...r,ref:e})});s3.displayName=L1;var i3="DialogDescription",Rne=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=ho(i3,n);return d.jsx(Ae.p,{id:o.descriptionId,...r,ref:e})});Rne.displayName=i3;var a3="DialogClose",l3=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,o=ho(a3,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});l3.displayName=a3;function $1(t){return t?"open":"closed"}var c3="DialogTitleWarning",[Qfe,u3]=fte(c3,{contentName:ua,titleName:L1,docsSlug:"dialog"}),Lne=({titleId:t})=>{const e=u3(c3),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
236
|
-
|
|
237
|
-
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
238
|
-
|
|
239
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return w.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},$ne="DialogDescriptionWarning",Fne=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${u3($ne).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},Nne=QR,zne=t3,Bne=n3,Une=r3;const d3=()=>{},h3=w.createContext(null);function Hne({onEvent:t,children:e}){return d.jsx(h3.Provider,{value:t??d3,children:e})}function Qt(){return w.useContext(h3)??d3}const p3=w.createContext(null);function Kne({context:t,children:e}){const n=Qt(),r=qM("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}),Gr.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}),Gr.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}),Gr.deleteOpenMenu(i.id,t)}),r.set([]))}}),[n,r,t]);return d.jsx(p3.Provider,{value:o,children:e})}function Pa(){const t=w.useContext(p3);if(!t)throw new Error("useDialogs must be used within a DialogsProvider");return t}const Wne=({id:t,component:e,onClose:n})=>{const{removeDialog:r}=Pa(),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(Nne,{onOpenChange:s,defaultOpen:!0,children:d.jsx(zne,{container:o,children:d.jsx(Bne,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:d.jsx(Une,{dir:"ltr",className:"tlui-dialog__content","aria-describedby":void 0,children:d.jsx(e,{onClose:()=>s(!1)})})})})})},Gne=w.memo(function(){const{dialogs:e}=Pa();return H("dialogs",()=>e.get(),[e]).map(r=>d.jsx(Wne,{...r},r.id))});function F1(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,...m}=h,g=(p==null?void 0:p[t][l])||a,v=w.useMemo(()=>m,Object.values(m));return d.jsx(g.Provider,{value:v,children:f})}function u(h,p){const f=(p==null?void 0:p[t][l])||a,m=w.useContext(f);if(m)return m;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,Vne(o,...e)]}function Vne(...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]=F1(e),[o,s]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:m,children:g}=f,v=Te.useRef(null),S=Te.useRef(new Map).current;return d.jsx(o,{scope:m,itemMap:S,collectionRef:v,children:g})};i.displayName=e;const a=t+"CollectionSlot",l=Te.forwardRef((f,m)=>{const{scope:g,children:v}=f,S=s(a,g),y=Qe(m,S.collectionRef);return d.jsx(ca,{ref:y,children:v})});l.displayName=a;const c=t+"CollectionItemSlot",u="data-radix-collection-item",h=Te.forwardRef((f,m)=>{const{scope:g,children:v,...S}=f,y=Te.useRef(null),P=Qe(m,y),b=s(c,g);return Te.useEffect(()=>(b.itemMap.set(y,{ref:y,...S}),()=>void b.itemMap.delete(y))),d.jsx(ca,{[u]:"",ref:P,children:v})});h.displayName=c;function p(f){const m=s(t+"CollectionConsumer",f);return Te.useCallback(()=>{const v=m.collectionRef.current;if(!v)return[];const S=Array.from(v.querySelectorAll(`[${u}]`));return Array.from(m.itemMap.values()).sort((b,C)=>S.indexOf(b.ref.current)-S.indexOf(C.ref.current))},[m.collectionRef,m.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},p,r]}var Yne="VisuallyHidden",N1=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}}));N1.displayName=Yne;var z1="ToastProvider",[B1,Xne,qne]=Qg("Toast"),[f3,Jfe]=ba("Toast",[qne]),[Zne,Jg]=f3(z1),g3=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 \`${z1}\`. Expected non-empty \`string\`.`),d.jsx(B1.Provider,{scope:e,children:d.jsx(Zne,{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})})};g3.displayName=z1;var m3="ToastViewport",Qne=["F8"],Ox="toast.viewportPause",Dx="toast.viewportResume",y3=w.forwardRef((t,e)=>{const{__scopeToast:n,hotkey:r=Qne,label:o="Notifications ({hotkey})",...s}=t,i=Jg(m3,n),a=Xne(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,""),m=i.toastCount>0;w.useEffect(()=>{const v=S=>{var P;r.length!==0&&r.every(b=>S[b]||S.code===b)&&((P=h.current)==null||P.focus())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r]),w.useEffect(()=>{const v=l.current,S=h.current;if(m&&v&&S){const y=()=>{if(!i.isClosePausedRef.current){const I=new CustomEvent(Ox);S.dispatchEvent(I),i.isClosePausedRef.current=!0}},P=()=>{if(i.isClosePausedRef.current){const I=new CustomEvent(Dx);S.dispatchEvent(I),i.isClosePausedRef.current=!1}},b=I=>{!v.contains(I.relatedTarget)&&P()},C=()=>{v.contains(document.activeElement)||P()};return v.addEventListener("focusin",y),v.addEventListener("focusout",b),v.addEventListener("pointermove",y),v.addEventListener("pointerleave",C),window.addEventListener("blur",y),window.addEventListener("focus",P),()=>{v.removeEventListener("focusin",y),v.removeEventListener("focusout",b),v.removeEventListener("pointermove",y),v.removeEventListener("pointerleave",C),window.removeEventListener("blur",y),window.removeEventListener("focus",P)}}},[m,i.isClosePausedRef]);const g=w.useCallback(({tabbingDirection:v})=>{const y=a().map(P=>{const b=P.ref.current,C=[b,...dre(b)];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 P=y.altKey||y.ctrlKey||y.metaKey;if(y.key==="Tab"&&!P){const _=document.activeElement,M=y.shiftKey;if(y.target===v&&M){(C=c.current)==null||C.focus();return}const A=g({tabbingDirection:M?"backwards":"forwards"}),O=A.findIndex(R=>R===_);sS(A.slice(O+1))?y.preventDefault():M?(I=c.current)==null||I.focus():(k=u.current)==null||k.focus()}};return v.addEventListener("keydown",S),()=>v.removeEventListener("keydown",S)}},[a,g]),d.jsxs(jte,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:m?void 0:"none"},children:[m&&d.jsx(Rx,{ref:c,onFocusFromOutsideViewport:()=>{const v=g({tabbingDirection:"forwards"});sS(v)}}),d.jsx(B1.Slot,{scope:n,children:d.jsx(Ae.ol,{tabIndex:-1,...s,ref:p})}),m&&d.jsx(Rx,{ref:u,onFocusFromOutsideViewport:()=>{const v=g({tabbingDirection:"backwards"});sS(v)}})]})});y3.displayName=m3;var S3="ToastFocusProxy",Rx=w.forwardRef((t,e)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=t,s=Jg(S3,n);return d.jsx(N1,{"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()}})});Rx.displayName=S3;var em="Toast",Jne="toast.swipeStart",ere="toast.swipeMove",tre="toast.swipeCancel",nre="toast.swipeEnd",v3=w.forwardRef((t,e)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=t,[a=!0,l]=Ti({prop:r,defaultProp:o,onChange:s});return d.jsx(uo,{present:n||a,children:d.jsx(sre,{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)})})})});v3.displayName=em;var[rre,ore]=f3(em,{onClose(){}}),sre=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,...m}=t,g=Jg(em,n),[v,S]=w.useState(null),y=Qe(e,R=>S(R)),P=w.useRef(null),b=w.useRef(null),C=o||g.duration,I=w.useRef(0),k=w.useRef(C),_=w.useRef(0),{onToastAdd:M,onToastRemove:T}=g,D=qt(()=>{var B;(v==null?void 0:v.contains(document.activeElement))&&((B=g.viewport)==null||B.focus()),i()}),A=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=g.viewport;if(R){const B=()=>{A(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(Ox,L),R.addEventListener(Dx,B),()=>{R.removeEventListener(Ox,L),R.removeEventListener(Dx,B)}}},[g.viewport,C,l,c,A]),w.useEffect(()=>{s&&!g.isClosePausedRef.current&&A(C)},[s,C,g.isClosePausedRef,A]),w.useEffect(()=>(M(),()=>T()),[M,T]);const O=w.useMemo(()=>v?I3(v):null,[v]);return g.viewport?d.jsxs(d.Fragment,{children:[O&&d.jsx(ire,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:O}),d.jsx(rre,{scope:n,onClose:D,children:hi.createPortal(d.jsx(B1.ItemSlot,{scope:n,children:d.jsx(Ate,{asChild:!0,onEscapeKeyDown:oe(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||D(),g.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":g.swipeDirection,...m,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||(g.isFocusedToastEscapeKeyDownRef.current=!0,D()))}),onPointerDown:oe(t.onPointerDown,R=>{R.button===0&&(P.current={x:R.clientX,y:R.clientY})}),onPointerMove:oe(t.onPointerMove,R=>{if(!P.current)return;const B=R.clientX-P.current.x,L=R.clientY-P.current.y,G=!!b.current,$=["left","right"].includes(g.swipeDirection),U=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,Y=$?U(0,B):0,ee=$?0:U(0,L),he=R.pointerType==="touch"?10:2,ue={x:Y,y:ee},ke={originalEvent:R,delta:ue};G?(b.current=ue,Ch(ere,h,ke,{discrete:!1})):YI(ue,g.swipeDirection,he)?(b.current=ue,Ch(Jne,u,ke,{discrete:!1}),R.target.setPointerCapture(R.pointerId)):(Math.abs(B)>he||Math.abs(L)>he)&&(P.current=null)}),onPointerUp:oe(t.onPointerUp,R=>{const B=b.current,L=R.target;if(L.hasPointerCapture(R.pointerId)&&L.releasePointerCapture(R.pointerId),b.current=null,P.current=null,B){const G=R.currentTarget,$={originalEvent:R,delta:B};YI(B,g.swipeDirection,g.swipeThreshold)?Ch(nre,f,$,{discrete:!0}):Ch(tre,p,$,{discrete:!0}),G.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})})}),g.viewport)})]}):null}),ire=t=>{const{__scopeToast:e,children:n,...r}=t,o=Jg(em,e),[s,i]=w.useState(!1),[a,l]=w.useState(!1);return cre(()=>i(!0)),w.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(xd,{asChild:!0,children:d.jsx(N1,{...r,children:s&&d.jsxs(d.Fragment,{children:[o.label," ",n]})})})},are="ToastTitle",x3=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});x3.displayName=are;var lre="ToastDescription",w3=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});w3.displayName=lre;var b3="ToastAction",P3=w.forwardRef((t,e)=>{const{altText:n,...r}=t;return n.trim()?d.jsx(_3,{altText:n,asChild:!0,children:d.jsx(U1,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${b3}\`. Expected non-empty \`string\`.`),null)});P3.displayName=b3;var C3="ToastClose",U1=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t,o=ore(C3,n);return d.jsx(_3,{asChild:!0,children:d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,o.onClose)})})});U1.displayName=C3;var _3=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 I3(t){const e=[];return Array.from(t.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),ure(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",s=r.dataset.radixToastAnnounceExclude==="";if(!o)if(s){const i=r.dataset.radixToastAnnounceAlt;i&&e.push(i)}else e.push(...I3(r))}}),e}function Ch(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?A1(o,s):o.dispatchEvent(s)}var YI=(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 cre(t=()=>{}){const e=qt(t);gi(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[e])}function ure(t){return t.nodeType===t.ELEMENT_NODE}function dre(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function sS(t){const e=document.activeElement;return t.some(n=>n===e?!0:(n.focus(),document.activeElement!==e))}var hre=v3,pre=x3,fre=w3,gre=P3,XI=U1;const E3=w.createContext(null);function mre({children:t}){const e=qM("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(g3,{children:d.jsx(E3.Provider,{value:n,children:t})})}function Uo(){const t=w.useContext(E3);if(!t)throw new Error("useToasts must be used within a ToastsProvider");return t}const k3=w.createContext(null);function yre({assetUrls:t,children:e}){return w.useEffect(()=>{for(const n of Object.values(t.icons)){const r=Du();r.src=n,r.decode()}for(const n of Object.values(t.embedIcons)){const r=Du();r.src=n,r.decode()}},[t]),d.jsx(k3.Provider,{value:t,children:e})}function H1(){const t=w.useContext(k3);if(!t)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return t}const Lx={"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.label-align":"Label align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},Sre=new Set(["ar","fa","he","ur","ku"]),$a={locale:"en",label:"English",messages:Lx,dir:"ltr"};async function vre(t,e){if(!(await oo(e.translations.en)).ok)return console.warn("No main translations found."),$a;if(t==="en")return $a;const r=Nu.find(a=>a.locale===t);if(!r)return console.warn(`No translation found for locale ${t}`),$a;const s=await(await oo(e.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${t}`),$a;const i=[];for(const a in $a.messages)s[a]||i.push(a);return i.length>0,{locale:t,label:r.label,dir:Sre.has(r.locale)?"rtl":"ltr",messages:{...$a.messages,...s}}}const T3=w.createContext(null);function M3(){const t=w.useContext(T3);if(!t)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return t}function xre({overrides:t,locale:e,children:n}){const r=H1(),[o,s]=w.useState(()=>t&&t.en?{locale:"en",label:"English",dir:"ltr",messages:{...Lx,...t.en}}:{locale:"en",label:"English",dir:"ltr",messages:Lx});return w.useEffect(()=>{let i=!1;async function a(){const l=await vre(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(T3.Provider,{value:o,children:n})}function Ce(){const t=M3();return w.useCallback(function(n){return t.messages[n]??n},[t])}const ce=w.forwardRef(function({children:e,type:n,...r},o){return d.jsx("button",{ref:o,type:"button",draggable:!1,...r,className:le("tlui-button",`tlui-button__${n}`,r.className),children:e})});function Pt({children:t}){return d.jsx("span",{className:"tlui-button__label",children:t})}const Lo=w.memo(function({small:e,invertIcon:n,icon:r,color:o,className:s,...i}){const a=H1(),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}})}),wre=4e3,bre={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function Pre({toast:t}){const{removeToast:e}=Uo(),n=Ce(),r=i=>{i||e(t.id)},o=t.actions&&t.actions.length>0,s=t.icon||t.severity&&bre[t.severity];return d.jsxs(hre,{onOpenChange:r,className:"tlui-toast__container",duration:t.keepOpen?1/0:wre,"data-severity":t.severity,children:[s&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(Lo,{icon:s})}),d.jsxs("div",{className:"tlui-toast__main",children:[d.jsxs("div",{className:"tlui-toast__content",children:[t.title&&d.jsx(pre,{className:"tlui-toast__title",children:t.title}),t.description&&d.jsx(fre,{className:"tlui-toast__description",children:t.description})]}),t.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[t.actions.map((i,a)=>d.jsx(gre,{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(XI,{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(XI,{asChild:!0,children:d.jsx(ce,{type:"normal",className:"tlui-toast__close",children:d.jsx(Pt,{children:t.closeLabel??n("toast.close")})})})]})}const Cre=w.memo(function(){const{toasts:e}=Uo(),n=H("toasts",()=>e.get(),[]);return d.jsxs(d.Fragment,{children:[n.map(r=>d.jsx(Pre,{toast:r},r.id)),d.jsx(y3,{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=A3(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 A3(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(Mj(u,h))continue}else if(TZ(u,h))continue;a.push(l)}}return a}function Lf(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}),j3(t)}const _re=16;function j3(t){const e=t.getSelectionPageBounds(),n=t.getViewportPageBounds();if(e&&!n.contains(e)){const r=e.clone().expandBy(_re/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 Ire(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 Ere=50;function kre(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 m=t.getShapeGeometry(f.id);return t.getShapeLocalTransform(f).applyToPoints(m.vertices)})),{padding:a=Ere}=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(m=>{const g=t.getShape(m);return{id:g.id,type:g.type,x:g.x+u,y:g.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(Lo,{className:"tlui-button__icon",icon:t,small:e,invertIcon:n})}function tm({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__header",t),children:e})}function nm({className:t,children:e}){return d.jsx(s3,{dir:"ltr",className:le("tlui-dialog__header__title",t),children:e})}function rm(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(l3,{"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 Uu({className:t,children:e,style:n}){return d.jsx("div",{className:le("tlui-dialog__body",t),style:n,children:e})}function K1({className:t,children:e}){return d.jsx("div",{className:le("tlui-dialog__footer",t),children:e})}const om=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:m=!1,children:g,value:v},S){const y=s1(),P=w.useRef(null);w.useImperativeHandle(S,()=>P.current);const b=Ce(),C=w.useRef(a??""),I=w.useRef(a??""),[k,_]=w.useState(!1),M=w.useCallback(O=>{_(!0);const R=O.currentTarget;I.current=R.value,y?y.timers.requestAnimationFrame(()=>{s&&R.select()}):bx.requestAnimationFrame("anon",()=>{s&&R.select()}),p==null||p()},[s,y,p]),T=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(),_t(O),c==null||c(O.currentTarget.value);break}case"Escape":{O.currentTarget.value=C.current,h==null||h(O.currentTarget.value),O.currentTarget.blur(),_t(O);break}}},[c,h]),A=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&&m&&O){const R=()=>{var B;(B=P.current)==null||B.scrollIntoView({block:"center"})};return O.addEventListener("resize",R),O.addEventListener("scroll",R),y?y.timers.requestAnimationFrame(()=>{var B;(B=P.current)==null||B.scrollIntoView({block:"center"})}):bx.requestAnimationFrame("anon",()=>{var B;(B=P.current)==null||B.scrollIntoView({block:"center"})}),()=>{O.removeEventListener("resize",R),O.removeEventListener("scroll",R)}}},[k,y,m]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[g,n&&d.jsx("label",{children:b(n)}),o&&d.jsx(Lo,{icon:o,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:P,className:le("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:D,onChange:T,onFocus:M,onBlur:A,autoFocus:i,placeholder:l,value:v}),r&&d.jsx(Lo,{icon:r,small:!!n})]})});function qI(t){return gr.isValid(t)?{isValid:!0,hasProtocol:!0}:gr.isValid("https://"+t)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Tre=$t(function({onClose:e}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(Mre,{onClose:e,selectedShape:r}):null}),Mre=$t(function({onClose:e,selectedShape:n}){const r=z(),o=Ce(),s=w.useRef(null);w.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var m;return(m=s.current)==null?void 0:m.focus()})},[r]);const i=w.useRef(n.props.url),[a,l]=w.useState(()=>{const m=qI(n.props.url),g=m.isValid===!0?m.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:g,safe:g,valid:!0}}),c=w.useCallback(m=>{const g=m.replace(/https?:\/\/(https?:\/\/)/,(y,P)=>P),v=qI(g),S=v.isValid===!0?v.hasProtocol?g:"https://"+g:"https://";l({actual:g,safe:S,valid:v.isValid})},[]),u=w.useCallback(()=>{const m=r.getOnlySelectedShape();m&&(r.updateShapes([{id:m.id,type:m.type,props:{url:""}}]),e())},[r,e]),h=w.useCallback(()=>{const m=r.getOnlySelectedShape();m&&(m&&"url"in m.props&&m.props.url!==a.safe&&r.updateShapes([{id:m.id,type:m.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(tm,{children:[d.jsx(nm,{children:o("edit-link-dialog.title")}),d.jsx(rm,{})]}),d.jsx(Uu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(om,{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(K1,{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 Are={};const ZI=/(^\/r\/[^/]+\/?$)/,W1=[{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(ZI))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(ZI))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=${Are.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","")}}],jre={"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},Ore=W1.map(t=>t.type);function Dre(t){return Ore.includes(t)}function Rre(t){return"icon"in t}function O3(){return z().getShapeUtil("embed")}function G1(){const t=O3();return e=>t?t.getEmbedDefinition(e):void 0}function Lre(){const t=O3();return t?t.getEmbedDefinitions():[]}const D3=$t(function({onClose:e}){const n=z(),r=Ce(),o=H1(),[s,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[h,p]=w.useState(!1),f=w.useRef(-1),m=Lre(),g=G1();return d.jsxs(d.Fragment,{children:[d.jsxs(tm,{children:[d.jsx(nm,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),d.jsx(rm,{})]}),s?d.jsxs(d.Fragment,{children:[d.jsxs(Uu,{className:"tlui-embed-dialog__enter",children:[d.jsx(om,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:v=>{l(v);const S=g(v);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(Lo,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(K1,{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(Uu,{className:"tlui-embed-dialog__list",children:m.map(v=>{const S=Dre(v.type)?o.embedIcons[v.type]:Rre(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 V1={exports:{}};V1.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={},m={},g="",v="",S="",y=2,P=3,b=2,C=[],I=0,k=0,_;for(_=0;_<l.length;_+=1)if(g=l.charAt(_),Object.prototype.hasOwnProperty.call(f,g)||(f[g]=P++,m[g]=!0),v=S+g,Object.prototype.hasOwnProperty.call(f,v))S=v;else{if(Object.prototype.hasOwnProperty.call(m,S)){if(S.charCodeAt(0)<256){for(h=0;h<b;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<b;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,b),b++),delete m[S]}else for(p=f[S],h=0;h<b;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,b),b++),f[v]=P++,S=String(g)}if(S!==""){if(Object.prototype.hasOwnProperty.call(m,S)){if(S.charCodeAt(0)<256){for(h=0;h<b;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<b;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,b),b++),delete m[S]}else for(p=f[S],h=0;h<b;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,b),b++)}for(p=2,h=0;h<b;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,m=3,g="",v=[],S,y,P,b,C,I,k,_={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)h[S]=S;for(P=0,C=Math.pow(2,2),I=1;I!=C;)b=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),P|=(b>0?1:0)*I,I<<=1;switch(P){case 0:for(P=0,C=Math.pow(2,8),I=1;I!=C;)b=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),P|=(b>0?1:0)*I,I<<=1;k=n(P);break;case 1:for(P=0,C=Math.pow(2,16),I=1;I!=C;)b=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),P|=(b>0?1:0)*I,I<<=1;k=n(P);break;case 2:return""}for(h[3]=k,y=k,v.push(k);;){if(_.index>l)return"";for(P=0,C=Math.pow(2,m),I=1;I!=C;)b=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),P|=(b>0?1:0)*I,I<<=1;switch(k=P){case 0:for(P=0,C=Math.pow(2,8),I=1;I!=C;)b=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),P|=(b>0?1:0)*I,I<<=1;h[f++]=n(P),k=f-1,p--;break;case 1:for(P=0,C=Math.pow(2,16),I=1;I!=C;)b=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),P|=(b>0?1:0)*I,I<<=1;h[f++]=n(P),k=f-1,p--;break;case 2:return v.join("")}if(p==0&&(p=Math.pow(2,m),m++),h[k])g=h[k];else if(k===f)g=y+y.charAt(0);else return null;v.push(g),h[f++]=y+g.charAt(0),p--,y=g,p==0&&(p=Math.pow(2,m),m++)}}};return a}();t!=null?t.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})})(V1);var $re=V1.exports;const R3=vi($re);async function Fre(t,e,n){var S,y,P;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(b=>{if(c.set(b.id,Ke()),b.boundElements!==null)for(const C of b.boundElements)C.type==="text"&&h.add(C.id)});let p=NT;for(const b of r){if(h.has(b.id))continue;const C=c.get(b.id),I={id:C,typeName:"shape",parentId:l,index:p,x:b.x,y:b.y,rotation:0,isLocked:b.locked,opacity:Nre(b.opacity),meta:{}};switch(b.angle!==0&&a.set(C,b.angle),b.groupIds&&b.groupIds.length>0?i.has(b.groupIds[0])?(S=i.get(b.groupIds[0]))==null||S.push(C):i.set(b.groupIds[0],[C]):u.push(C),b.type){case"rectangle":case"ellipse":case"diamond":{let k="",_="middle";if(b.boundElements!==null){for(const T of b.boundElements)if(T.type==="text"){const D=r.find(A=>A.id===T.id);D&&(k=D.text,_=Gre[D.textAlign])}}const M=b.backgroundColor==="transparent"?b.strokeColor:b.backgroundColor;s.shapes.push({...I,type:"geo",props:{geo:b.type,url:b.link??"",w:b.width,h:b.height,size:_h[b.strokeWidth]??"draw",color:Mc[M]??"black",text:k,align:_,dash:Ih(b),fill:Xre(b)}});break}case"freedraw":{s.shapes.push({...I,type:"draw",props:{dash:Ih(b),size:_h[b.strokeWidth],color:Mc[b.strokeColor]??"black",segments:[{type:"free",points:b.points.map(([k,_,M=.5])=>({x:k,y:_,z:M}))}]}});break}case"line":{if(b.points.slice().length<2)break;const _=Lu(b.points.length);s.shapes.push({...I,type:"line",props:{dash:Ih(b),size:_h[b.strokeWidth],color:Mc[b.strokeColor]??"black",spline:b.roundness?"cubic":"line",points:{...Object.fromEntries(b.points.map(([M,T],D)=>{const A=_[D];return[A,{id:A,index:A,x:M,y:T}]}))}}});break}case"arrow":{let k="";if(b.boundElements!==null){for(const A of b.boundElements)if(A.type==="text"){const O=r.find(R=>R.id===A.id);O&&(k=O.text)}}const _=b.points[0],M=b.points[b.points.length-1],T=c.get((y=b.startBinding)==null?void 0:y.elementId),D=c.get((P=b.endBinding)==null?void 0:P.elementId);s.shapes.push({...I,type:"arrow",props:{text:k,bend:Yre(b,_,M),dash:Ih(b),size:_h[b.strokeWidth]??"m",color:Mc[b.strokeColor]??"black",start:{x:_[0],y:_[1]},end:{x:M[0],y:M[1]},arrowheadEnd:QI[b.endArrowhead]??"none",arrowheadStart:QI[b.startArrowhead]??"none"}}),T&&s.bindings.push({id:qi(),typeName:"binding",type:"arrow",fromId:C,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),D&&s.bindings.push({id:qi(),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:_}=Bre(b.fontSize);s.shapes.push({...I,type:"text",props:{size:k,scale:_,font:Ure[b.fontFamily]??"draw",color:Mc[b.strokeColor]??"black",text:b.text,textAlign:Vre[b.textAlign]}});break}case"image":{const k=o[b.fileId];if(!k)break;const _=Ks.createId();s.assets.push({id:_,typeName:"asset",type:"image",props:{w:b.width,h:b.height,fileSize:k.size,name:b.id??"Untitled",isAnimated:!1,mimeType:k.mimeType,src:k.dataURL},meta:{}}),s.shapes.push({...I,type:"image",props:{w:b.width,h:b.height,assetId:_}})}}p=Co(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 b of i.values())if(b.length>1){t.groupShapes(b);const C=t.getShape(b[0]);C!=null&&C.parentId&&$n(C.parentId)&&u.push(C.parentId)}for(const[b,C]of a)t.select(b),t.rotateShapesBy([b],C);const m=ye(u.map(b=>t.getShape(b))),g=Z.Common(m.map(b=>t.getShapePageBounds(b))),v=t.getViewportPageBounds().center;t.updateShapes(m.map(b=>{const C={x:(b.x??0)-(g.x+g.w/2),y:(b.y??0)-(g.y+g.h/2)};return{id:b.id,type:b.type,x:v.x+C.x,y:v.y+C.y}})),t.setSelectedShapes(u)}const Nre=t=>{const e=t/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},_h={1:"s",2:"m",3:"l",4:"xl"},zre={16:"s",20:"m",28:"l",36:"xl"};function Bre(t){const e=zre[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 Ure={1:"draw",2:"sans",3:"mono"},Hre={gray:["#f8f9fa","#e9ecef","#ced4da","#868e96","#343a40"],red:["#fff5f5","#ffc9c9","#ff8787","#fa5252","#e03131"],pink:["#fff0f6","#fcc2d7","#f783ac","#e64980","#c2255c"],grape:["#f8f0fc","#eebefa","#da77f2","#be4bdb","#9c36b5"],violet:["#f3f0ff","#d0bfff","#9775fa","#7950f2","#6741d9"],indigo:["#edf2ff","#bac8ff","#748ffc","#4c6ef5","#3b5bdb"],blue:["#e7f5ff","#a5d8ff","#4dabf7","#228be6","#1971c2"],cyan:["#e3fafc","#99e9f2","#3bc9db","#15aabf","#0c8599"],teal:["#e6fcf5","#96f2d7","#38d9a9","#12b886","#099268"],green:["#ebfbee","#b2f2bb","#69db7c","#40c057","#2f9e44"],lime:["#f4fce3","#d8f5a2","#a9e34b","#82c91e","#66a80f"],yellow:["#fff9db","#ffec99","#ffd43b","#fab005","#f08c00"],orange:["#fff4e6","#ffd8a8","#ffa94d","#fd7e14","#e8590c"]};function So(t,e,n){const r=[0,1,2,3,4].map(o=>Hre[t][o]);return Object.fromEntries(r.map((o,s)=>[o,s<3?e:n]))}const Mc={...So("gray","grey","black"),...So("red","light-red","red"),...So("pink","light-red","red"),...So("grape","light-violet","violet"),...So("blue","light-blue","blue"),...So("cyan","light-blue","blue"),...So("teal","light-green","green"),...So("green","light-green","green"),...So("yellow","yellow","orange"),...So("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},Kre={solid:"draw",dashed:"dashed",dotted:"dotted"},Wre={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Gre={left:"start",center:"middle",right:"end"},Vre={left:"start",center:"middle",right:"end"},QI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Yre(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 Ih=t=>{let e=Kre[t.strokeStyle]??"draw";return e==="draw"&&t.roughness===0&&(e="solid"),e},Xre=t=>t.backgroundColor==="transparent"?"none":Wre[t.fillStyle]??"solid";async function qre(t,e,n,r){const s=(await Promise.all(e.map(async i=>await(await oo(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 $x(t,e,n,r){return t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"url",point:n,url:e,sources:r})}function Qre(t){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t.trim(),e.body.textContent||e.body.innerText||""}const Jre=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},eoe=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 oj(e)},toe=t=>/^<svg/.test(t),noe=["input","select","textarea"];function iS(t){const{activeElement:e}=document;return t.menus.hasAnyOpenMenus()||e&&(e.getAttribute("contenteditable")||noe.indexOf(e.tagName.toLowerCase())>-1)}const roe=t=>t.types.find(e=>e.match(/^image\//)),aS=(t,e,n,r)=>{const o=eoe(e);if(o)for(const s of o)$x(t,s,n);else Jre(e)?$x(t,e,n):toe(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}))},ooe=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}}$3(t,r,n)},L3=async(t,e,n)=>{const r=[];for(const o of e){if(roe(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 cs.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await cs.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await cs.blobToText(s)})()})}return await $3(t,r,n)};async function $3(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 qre(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=R3.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"){Fre(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");aS(t,c,n,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){aS(t,Qre(s.data),n,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){$x(t,s.data,n,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){aS(t,s.data,n,o);return}}const $f=async t=>{var r;const e=await t.resolveAssetsInContent(t.getContentFromCurrentPage(t.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=R3.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(s7);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 soe(){const t=z(),e=Qt(),n=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await $f(t),e("copy",{source:i}))},[t,e]),r=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await $f(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?(L3(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 ioe(){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||iS(t)||(xe(l),await $f(t),e("copy",{source:"kbd"}))};async function o(l){t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||iS(t)||(xe(l),await $f(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){_t(l);return}if(t.getEditingShapeId()!==null||iS(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?ooe(t,l.clipboardData,c):navigator.clipboard.read().then(h=>{Array.isArray(h)&&h[0]instanceof ClipboardItem&&L3(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])}/*!
|
|
240
|
-
* canvas-size
|
|
241
|
-
* v1.2.6
|
|
242
|
-
* https://github.com/jhildenbiddle/canvas-size
|
|
243
|
-
* (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
|
|
244
|
-
* MIT license
|
|
245
|
-
*/function aoe(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 JI(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 or(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?JI(Object(n),!0).forEach(function(r){loe(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):JI(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function loe(t,e,n){return e=yoe(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function coe(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 uoe(t,e){if(t==null)return{};var n=coe(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 eE(t,e){return hoe(t)||aoe(t,e)||F3(t,e)||goe()}function Eh(t){return doe(t)||poe(t)||F3(t)||foe()}function doe(t){if(Array.isArray(t))return Fx(t)}function hoe(t){if(Array.isArray(t))return t}function poe(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function F3(t,e){if(t){if(typeof t=="string")return Fx(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 Fx(t,e)}}function Fx(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 foe(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
246
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function goe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
247
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function moe(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 yoe(t){var e=moe(t,"string");return typeof e=="symbol"?e:String(e)}function uu(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&&uu(t)):h?t.onSuccess(n,r,p):(t.onError(n,r,p),t.sizes.length&&uu(t)),h}var lS={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]},Soe=["onError","onSuccess"],il={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},Ac={};function cS(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||il.min,i=t.step||il.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 kh(t){var e=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),o=t.onError,s=t.onSuccess,i=uoe(t,Soe),a=null;if(!e)return!1;if(t.useWorker&&n){var l=`
|
|
248
|
-
var canvasTest = `.concat(uu.toString(),`;
|
|
249
|
-
onmessage = function(e) {
|
|
250
|
-
canvasTest(e.data);
|
|
251
|
-
};
|
|
252
|
-
`),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(h){var p=h.data,f=p.width,m=p.height,g=p.benchmark,v=p.isTestPass;v?(Ac[r].onSuccess(f,m,g),delete Ac[r]):Ac[r].onError(f,m,g)}}if(t.usePromise)return new Promise(function(h,p){var f=or(or({},t),{},{onError:function(S,y,P){var b;if(t.sizes.length===0)b=!0;else{var C=t.sizes.slice(-1),I=eE(C,1),k=eE(I[0],2),_=k[0],M=k[1];b=S===_&&y===M}o(S,y,P),b&&p({width:S,height:y,benchmark:P})},onSuccess:function(S,y,P){s(S,y,P),h({width:S,height:y,benchmark:P})}});if(a){var m=f.onError,g=f.onSuccess;Ac[r]={onError:m,onSuccess:g},a.postMessage(i)}else uu(f)});if(a)Ac[r]={onError:o,onSuccess:s},a.postMessage(i);else return uu(t)}var uS={maxArea:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=cS({width:e.max,height:e.max,min:e.min,step:e.step,sizes:Eh(lS.area)}),r=or(or(or({},il),e),{},{sizes:n});return kh(r)},maxHeight:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=cS({width:1,height:e.max,min:e.min,step:e.step,sizes:Eh(lS.height)}),r=or(or(or({},il),e),{},{sizes:n});return kh(r)},maxWidth:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=cS({width:e.max,height:1,min:e.min,step:e.step,sizes:Eh(lS.width)}),r=or(or(or({},il),e),{},{sizes:n});return kh(r)},test:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=or(or({},il),e);return n.sizes=Eh(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),kh(n)}};let dS=null;function voe(){return dS||(dS=xoe()),dS}async function xoe(){const t=await uS.maxWidth({usePromise:!0}),e=await uS.maxHeight({usePromise:!0}),n=await uS.maxArea({usePromise:!0});return{maxWidth:t.width,maxHeight:e.height,maxArea:n.width*n.height}}const tE=8192,woe=4096*4096;async function boe(t,e){if(t<=tE&&e<=tE&&t*e<=woe)return[t,e];const{maxWidth:n,maxHeight:r,maxArea:o}=await voe(),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 N3(t,e,n){const{type:r,quality:o,scale:s,width:i,height:a}=n;let[l,c]=await boe(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,h=await cs.blobToDataUrl(new Blob([e],{type:"image/svg+xml"})),p=await new Promise(m=>{const g=Du();g.crossOrigin="anonymous",g.onload=async()=>{Ge.isSafari&&await Bv(250);const v=document.createElement("canvas"),S=v.getContext("2d");v.width=l,v.height=c,S.imageSmoothingEnabled=!0,S.imageSmoothingQuality="high",S.drawImage(g,0,0,l,c),URL.revokeObjectURL(h),m(v)},g.onerror=()=>{m(null)},g.src=h});if(!p)return null;const f=await new Promise(m=>p.toBlob(g=>{(!g||bt.throwToBlob.get())&&m(null),m(g)},"image/"+r,o));if(!f)return null;if(r==="png"){const m=new DataView(await f.arrayBuffer());return bo.setPhysChunk(m,u,{type:"image/"+r})}else return f}async function z3(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 Nx(t,e,n,r={}){var o;switch(n){case"svg":return(o=await z3(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 B3({editor:t,ids:e,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await Nx(t,e,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Nx(t,e,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await z3(t,e,r);if(!o)throw new Error("Could not construct image.");const s=await N3(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 Poe={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function Coe(t,e,n,r={}){return{blobPromise:B3({editor:t,ids:e,format:n,opts:r}),mimeType:Poe[n]}}function _oe(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}=Coe(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 Ioe(async()=>Nx(t,e,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Ot(n)}}async function Ioe(t){var e,n;await((n=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:n.call(e,await t()))}function Eoe(){const t=z(),{addToast:e}=Uo(),n=Ce();return w.useCallback((r,o="svg")=>{_oe(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 koe(t,e,n="png",r,o={}){if(!r&&(r=`shapes at ${nE()}`,e.length===1)){const a=t.getShape(e[0]);t.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${Ag(a.id)} at ${nE()}`}r+=`.${n}`;const s=await B3({editor:t,ids:e,format:n,opts:o}),i=new File([s],r,{type:s.type});Toe(i)}function nE(){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 Toe(t){const e=document.createElement("a"),n=URL.createObjectURL(t);e.href=n,e.download=t.name,e.click(),URL.revokeObjectURL(n)}function Moe(){const t=z(),{addToast:e}=Uo(),n=Ce();return w.useCallback((r,o="png",s)=>{koe(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 Aoe(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 Ao(()=>{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,m,g;if($n(h)){const S=t.getShape(h);if(!S)continue;const y=t.getPointInShapeSpace(S,{x:c.x,y:c.y});g=t.getShapePageTransform(h).rotation(),y.sub(new x(s,s).rot(-g)),f=y.x,m=y.y}else f=c.x-s,m=c.y-s,g=0;t.deleteShapes(u),t.createAssets([{...l,id:l.id}]);const v=Ke();t.createShape({id:v,type:"image",index:p,parentId:h,x:f,y:m,rotation:-g,props:{assetId:l.id,w:c.w+s*2,h:c.h+s*2}}),i.push(v)}}),i}const U3=Te.createContext([]);function H3(){const t=z(),e=w.useRef(),n=Gs(Te.useContext(U3));return w.useEffect(()=>{const r=window.document.createElement("input");r.type="file",r.accept=(n==null?void 0:n.join(","))??D9,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 sm(){return z().store.props.collaboration!==void 0}function joe(){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 Ooe(){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=`
|
|
253
|
-
.${a} {
|
|
254
|
-
display: none;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
.${a} svg {
|
|
258
|
-
max-width: 100%;
|
|
259
|
-
height: 100%;
|
|
260
|
-
display: block;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
@media print {
|
|
264
|
-
html, body {
|
|
265
|
-
min-height: 100%;
|
|
266
|
-
height: 100%;
|
|
267
|
-
margin: 0;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
body {
|
|
271
|
-
position: relative;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
body > * {
|
|
275
|
-
display: none;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
.tldraw__editor {
|
|
279
|
-
display: none;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
.${a} {
|
|
283
|
-
display: block !important;
|
|
284
|
-
background: white;
|
|
285
|
-
min-height: 100%;
|
|
286
|
-
height: 100%;
|
|
287
|
-
max-width: 100%;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
.${a}__item {
|
|
291
|
-
padding: 10mm;
|
|
292
|
-
display: flex;
|
|
293
|
-
min-height: 100%;
|
|
294
|
-
flex-direction: column;
|
|
295
|
-
page-break-after: always;
|
|
296
|
-
position: relative;
|
|
297
|
-
overflow: hidden;
|
|
298
|
-
height: 100%;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
.${a}__item__main {
|
|
302
|
-
flex: 1;
|
|
303
|
-
display: flex;
|
|
304
|
-
align-items: center;
|
|
305
|
-
justify-content: center;
|
|
306
|
-
max-height: 100%;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
.${a}__item__header {
|
|
310
|
-
display: none;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
.${a}__item__footer {
|
|
314
|
-
display: none;
|
|
315
|
-
text-align: right;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
.${a}__item__footer__hide {
|
|
319
|
-
display: none;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
`;const l=()=>{document.head.appendChild(s),document.body.appendChild(o)},c=()=>{t.once("tick",()=>{i(o,s)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(S,y,P){try{o.innerHTML+=`<div class="${a}__item">
|
|
326
|
-
<div class="${a}__item__header">
|
|
327
|
-
${S.replace(/</g,"<").replace(/>/g,">")}
|
|
328
|
-
</div>
|
|
329
|
-
<div class="${a}__item__main">
|
|
330
|
-
${P}
|
|
331
|
-
</div>
|
|
332
|
-
<div class="${a}__item__footer ${a}__item__footer__${y?"":"hide"}">
|
|
333
|
-
${y??""}
|
|
334
|
-
</div>
|
|
335
|
-
</div>`}catch(b){console.error(b)}}function h(){Ge.isChromeForIos?(l(),window.print()):Ge.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=t.getSelectedShapeIds(),f=t.getCurrentPageId(),m=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=m.find(P=>P.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 K3=w.createContext(null);function Doe(t){return Object.fromEntries(t.map(e=>[e.id,e]))}function Fa(t,e){if(t.getSelectedShapes().length===0)return t.getDocumentSettings().name||e}function Roe({overrides:t,children:e}){const n=z(),r=sm(),{addDialog:o,clearDialogs:s}=Pa(),{clearToasts:i,addToast:a}=Uo(),l=Ce(),c=H3(),u=Ooe(),{cut:h,copy:p,paste:f}=soe(),m=Eoe(),g=Moe(),v=l("document.default-name"),S=G1(),y=Qt(),P=w.useMemo(()=>{function b(){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()&&(b()||(y("edit-link",{source:_}),n.markHistoryStoppingPoint("edit-link"),o({component:Tre})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(_){y("insert-embed",{source:_}),o({component:D3})}},{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 M=n.getSelectedShapeIds();M.length===0&&(M=Array.from(n.getCurrentPageShapeIds().values())),M.length!==0&&(y("export-as",{format:"svg",source:_}),g(M,"svg",Fa(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 M=n.getSelectedShapeIds();M.length===0&&(M=Array.from(n.getCurrentPageShapeIds().values())),M.length!==0&&(y("export-as",{format:"png",source:_}),g(M,"png",Fa(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 M=n.getSelectedShapeIds();M.length===0&&(M=Array.from(n.getCurrentPageShapeIds().values())),M.length!==0&&(y("export-as",{format:"json",source:_}),g(M,"json",Fa(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 M=n.getSelectedShapeIds();M.length===0&&(M=Array.from(n.getCurrentPageShapeIds().values())),M.length!==0&&(y("export-all-as",{format:"svg",source:_}),g(Array.from(n.getCurrentPageShapeIds()),"svg",Fa(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 M=Array.from(n.getCurrentPageShapeIds().values());M.length!==0&&(y("export-all-as",{format:"png",source:_}),g(M,"png",Fa(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 M=Array.from(n.getCurrentPageShapeIds().values());M.length!==0&&(y("export-all-as",{format:"json",source:_}),g(M,"json",Fa(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 M=n.getSelectedShapeIds();M.length===0&&(M=Array.from(n.getCurrentPageShapeIds().values())),M.length!==0&&(y("copy-as",{format:"svg",source:_}),m(M,"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 M=n.getSelectedShapeIds();M.length===0&&(M=Array.from(n.getCurrentPageShapeIds().values())),M.length!==0&&(y("copy-as",{format:"png",source:_}),m(M,"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 M=n.getSelectedShapeIds();M.length===0&&(M=Array.from(n.getCurrentPageShapeIds().values())),M.length!==0&&(y("copy-as",{format:"json",source:_}),m(M,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(_){if(!C()||b())return;y("toggle-auto-size",{source:_}),n.markHistoryStoppingPoint("toggling auto size");const M=n.getSelectedShapes().filter(T=>n.isShapeOfType(T,"text")&&T.props.autoSize===!1);n.updateShapes(M.map(T=>({id:T.id,type:T.type,props:{...T.props,w:8,autoSize:!0}}))),Ye(n,M.map(T=>T.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(_){y("open-embed-link",{source:_});const M=n.getSelectedShapeIds(),T="No embed shapes selected";if(M.length!==1){console.error(T);return}const D=n.getShape(M[0]);if(!D||!n.isShapeOfType(D,"embed")){console.error(T);return}hte(D.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(_){var M,T;if(((M=n.root.getCurrent())==null?void 0:M.id)!=="zoom"&&(y("zoom-tool",{source:_}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const D=n.root.getCurrent();D&&((T=D.getCurrent())==null?void 0:T.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:D.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(_){C()&&(b()||n.run(()=>{y("convert-to-bookmark",{source:_});const M=n.getSelectedShapes(),T=[],D=[];for(const A of M){if(!A||!n.isShapeOfType(A,"embed")||!A.props.url)continue;const O=new x(A.x,A.y);O.rot(-A.rotation),O.add(new x(A.props.w/2-300/2,A.props.h/2-320/2)),O.rot(A.rotation);const R={id:Ke(),type:"bookmark",rotation:A.rotation,x:O.x,y:O.y,opacity:1,props:{url:A.props.url}};T.push(R),D.push(A.id)}n.markHistoryStoppingPoint("convert shapes to bookmark"),n.deleteShapes(D),n.createShapes(T)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(_){C()&&(b()||(y("convert-to-embed",{source:_}),n.run(()=>{const M=n.getSelectedShapeIds(),T=ye(M.map(O=>n.getShape(O))),D=[],A=[];for(const O of T){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:Ke(),type:"embed",x:$.x,y:$.y,rotation:O.rotation,props:{url:R,w:L,h:G}};D.push(U),A.push(O.id)}n.markHistoryStoppingPoint("convert shapes to embed"),n.deleteShapes(A),n.createShapes(D)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(_){if(!C()||b())return;y("duplicate-shapes",{source:_});const M=n.getInstanceState();let T,D;if(M.duplicateProps)T=M.duplicateProps.shapeIds,D=M.duplicateProps.offset;else{T=n.getSelectedShapeIds();const A=Z.Common(ye(T.map(O=>n.getShapePageBounds(O))));D=n.getCameraOptions().isLocked?{x:n.options.adjacentShapeMargin,y:n.options.adjacentShapeMargin}:{x:A.width+n.options.adjacentShapeMargin,y:0}}n.markHistoryStoppingPoint("duplicate shapes"),n.duplicateShapes(T,D),M.duplicateProps&&n.updateInstanceState({duplicateProps:{...M.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(_){C()&&(b()||(y("ungroup-shapes",{source:_}),n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(_){if(!C()||b())return;y("group-shapes",{source:_});const M=n.getOnlySelectedShape();M&&n.isShapeOfType(M,"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 M=n.getSelectedShapes();M.length>0&&M.every(T=>n.isShapeOfType(T,"frame"))&&(n.markHistoryStoppingPoint("remove-frame"),Ire(n,M.map(T=>T.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(_){if(!C())return;y("fit-frame-to-content",{source:_});const M=n.getOnlySelectedShape();M&&n.isShapeOfType(M,"frame")&&(n.markHistoryStoppingPoint("fit-frame-to-content"),kre(n,M.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(_){if(!C()||b())return;y("align-shapes",{operation:"left",source:_}),n.markHistoryStoppingPoint("align left");const M=n.getSelectedShapeIds();n.alignShapes(M,"left"),Ye(n,M)}},{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()||b())return;y("align-shapes",{operation:"center-horizontal",source:_}),n.markHistoryStoppingPoint("align center horizontal");const M=n.getSelectedShapeIds();n.alignShapes(M,"center-horizontal"),Ye(n,M)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(_){if(!C()||b())return;y("align-shapes",{operation:"right",source:_}),n.markHistoryStoppingPoint("align right");const M=n.getSelectedShapeIds();n.alignShapes(M,"right"),Ye(n,M)}},{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()||b())return;y("align-shapes",{operation:"center-vertical",source:_}),n.markHistoryStoppingPoint("align center vertical");const M=n.getSelectedShapeIds();n.alignShapes(M,"center-vertical"),Ye(n,M)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(_){if(!C()||b())return;y("align-shapes",{operation:"top",source:_}),n.markHistoryStoppingPoint("align top");const M=n.getSelectedShapeIds();n.alignShapes(M,"top"),Ye(n,M)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(_){if(!C()||b())return;y("align-shapes",{operation:"bottom",source:_}),n.markHistoryStoppingPoint("align bottom");const M=n.getSelectedShapeIds();n.alignShapes(M,"bottom"),Ye(n,M)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(_){if(!C()||b())return;y("distribute-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("distribute horizontal");const M=n.getSelectedShapeIds();n.distributeShapes(M,"horizontal"),Ye(n,M)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(_){if(!C()||b())return;y("distribute-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("distribute vertical");const M=n.getSelectedShapeIds();n.distributeShapes(M,"vertical"),Ye(n,M)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(_){if(!C()||b())return;y("stretch-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("stretch horizontal");const M=n.getSelectedShapeIds();n.stretchShapes(M,"horizontal"),Ye(n,M)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(_){if(!C()||b())return;y("stretch-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("stretch vertical");const M=n.getSelectedShapeIds();n.stretchShapes(M,"vertical"),Ye(n,M)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(_){if(!C()||b())return;y("flip-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("flip horizontal");const M=n.getSelectedShapeIds();n.flipShapes(M,"horizontal"),Ye(n,M)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(_){if(!C()||b())return;y("flip-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("flip vertical");const M=n.getSelectedShapeIds();n.flipShapes(M,"vertical"),Ye(n,M)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(_){if(!C()||b())return;y("pack-shapes",{source:_}),n.markHistoryStoppingPoint("pack");const M=n.getSelectedShapeIds();n.packShapes(M,n.options.adjacentShapeMargin),Ye(n,M)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(_){if(!C()||b())return;y("stack-shapes",{operation:"vertical",source:_}),n.markHistoryStoppingPoint("stack-vertical");const M=n.getSelectedShapeIds();n.stackShapes(M,"vertical",16),Ye(n,M)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(_){if(!C()||b())return;y("stack-shapes",{operation:"horizontal",source:_}),n.markHistoryStoppingPoint("stack-horizontal");const M=n.getSelectedShapeIds();n.stackShapes(M,"horizontal",16),Ye(n,M)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(_){C()&&(b()||(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()&&(b()||(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()&&(b()||(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()&&(b()||(y("reorder-shapes",{operation:"toBack",source:_}),n.markHistoryStoppingPoint("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(_){C()&&(b()||(n.markHistoryStoppingPoint("cut"),h(_)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(_){C()&&(b()||p(_))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(_){var M;(M=navigator.clipboard)==null||M.read().then(T=>{f(T,_,_==="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(()=>{b()||(y("select-all-shapes",{source:_}),n.markHistoryStoppingPoint("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(_){C()&&(b()||(y("select-none-shapes",{source:_}),n.markHistoryStoppingPoint("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(_){C()&&(b()||(y("delete-shapes",{source:_}),n.markHistoryStoppingPoint("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(_){if(!C()||b())return;y("rotate-cw",{source:_}),n.markHistoryStoppingPoint("rotate-cw");const M=n.getSelectionRotation()%(Ze/2),T=ai(M,0)||ai(M,Ze/2),D=n.getSelectedShapeIds();n.rotateShapesBy(D,Ze/2-(T?0:M)),Ye(n,D)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(_){if(!C()||b())return;y("rotate-ccw",{source:_}),n.markHistoryStoppingPoint("rotate-ccw");const M=n.getSelectionRotation()%(Ze/2),T=ai(M,0),D=n.getSelectedShapeIds();n.rotateShapesBy(D,T?-(Ze/2):-M),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()&&(b()||(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 M=n.user.getIsDarkMode()?"light":"dark";y("color-scheme",{source:_,value:M}),n.user.updateUserPreferences({colorScheme:M})},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 M=[];for(const T of n.getCurrentPageShapes())T.isLocked&&M.push({id:T.id,type:T.type,isLocked:!1});M.length>0&&n.updateShapes(M)}},{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 M=n.getSelectionPageBounds()??n.getCurrentPageBounds();M&&n.zoomToBounds(M,{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 M=yr.createId(),T=n.getSelectedShapeIds();n.run(()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.createPage({name:l("page-menu.new-page-initial-name"),id:M}),n.moveShapesToPage(T,M)}),y("move-to-new-page",{source:_})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(_){const M=mr;n.run(()=>{n.markHistoryStoppingPoint("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(M,"white"),n.setStyleForNextShapes(M,"white")}),y("set-style",{source:_,id:M.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(_){const M=aa;n.run(()=>{n.markHistoryStoppingPoint("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(M,"fill"),n.setStyleForNextShapes(M,"fill")}),y("set-style",{source:_,id:M.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async _=>{const M=n.getSelectedShapeIds();if(M.length===0)return;n.markHistoryStoppingPoint("flattening to image"),y("flatten-to-image",{source:_});const T=await Aoe(n,M,n.options.flattenImageBoundsExpand);T!=null&&T.length&&n.setSelectedShapes(T)}}];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=Doe(I);return t?t(n,k,void 0):k},[n,y,t,o,a,c,g,m,h,p,f,s,i,u,l,v,r,S]);return d.jsx(K3.Provider,{value:P,children:e})}function Ca(){const t=w.useContext(K3);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Hu(t,e){return t?typeof t=="string"?t:e?t[e]??t.default:void 0:void 0}var Loe=w.createContext(void 0);function Y1(t){const e=w.useContext(Loe);return t||e||"ltr"}const $oe=["top","right","bottom","left"],mi=Math.min,ir=Math.max,Ff=Math.round,Th=Math.floor,jo=t=>({x:t,y:t}),Foe={left:"right",right:"left",bottom:"top",top:"bottom"},Noe={start:"end",end:"start"};function zx(t,e,n){return ir(t,mi(e,n))}function xs(t,e){return typeof t=="function"?t(e):t}function ws(t){return t.split("-")[0]}function rc(t){return t.split("-")[1]}function X1(t){return t==="x"?"y":"x"}function q1(t){return t==="y"?"height":"width"}function yi(t){return["top","bottom"].includes(ws(t))?"y":"x"}function Z1(t){return X1(yi(t))}function zoe(t,e,n){n===void 0&&(n=!1);const r=rc(t),o=Z1(t),s=q1(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=Nf(i)),[i,Nf(i)]}function Boe(t){const e=Nf(t);return[Bx(t),e,Bx(e)]}function Bx(t){return t.replace(/start|end/g,e=>Noe[e])}function Uoe(t,e,n){const r=["left","right"],o=["right","left"],s=["top","bottom"],i=["bottom","top"];switch(t){case"top":case"bottom":return n?e?o:r:e?r:o;case"left":case"right":return e?s:i;default:return[]}}function Hoe(t,e,n,r){const o=rc(t);let s=Uoe(ws(t),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),e&&(s=s.concat(s.map(Bx)))),s}function Nf(t){return t.replace(/left|right|bottom|top/g,e=>Foe[e])}function Koe(t){return{top:0,right:0,bottom:0,left:0,...t}}function W3(t){return typeof t!="number"?Koe(t):{top:t,right:t,bottom:t,left:t}}function zf(t){const{x:e,y:n,width:r,height:o}=t;return{width:r,height:o,top:n,left:e,right:e+r,bottom:n+o,x:e,y:n}}function rE(t,e,n){let{reference:r,floating:o}=t;const s=yi(e),i=Z1(e),a=q1(i),l=ws(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(rc(e)){case"start":f[i]-=p*(n&&c?-1:1);break;case"end":f[i]+=p*(n&&c?-1:1);break}return f}const Woe=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}=rE(c,r,l),p=r,f={},m=0;for(let g=0;g<a.length;g++){const{name:v,fn:S}=a[g],{x:y,y:P,data:b,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=P??h,f={...f,[v]:{...f[v],...b}},C&&m<=50&&(m++,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}=rE(c,p,l)),g=-1)}return{x:u,y:h,placement:p,strategy:o,middlewareData:f}};async function Ku(t,e){var n;e===void 0&&(e={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:p=!1,padding:f=0}=xs(e,t),m=W3(f),v=a[p?h==="floating"?"reference":"floating":h],S=zf(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(v)))==null||n?v:v.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),y=h==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,P=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),b=await(s.isElement==null?void 0:s.isElement(P))?await(s.getScale==null?void 0:s.getScale(P))||{x:1,y:1}:{x:1,y:1},C=zf(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:y,offsetParent:P,strategy:l}):y);return{top:(S.top-C.top+m.top)/b.y,bottom:(C.bottom-S.bottom+m.bottom)/b.y,left:(S.left-C.left+m.left)/b.x,right:(C.right-S.right+m.right)/b.x}}const Goe=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=e,{element:c,padding:u=0}=xs(t,e)||{};if(c==null)return{};const h=W3(u),p={x:n,y:r},f=Z1(o),m=q1(f),g=await i.getDimensions(c),v=f==="y",S=v?"top":"left",y=v?"bottom":"right",P=v?"clientHeight":"clientWidth",b=s.reference[m]+s.reference[f]-p[f]-s.floating[m],C=p[f]-s.reference[f],I=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let k=I?I[P]:0;(!k||!await(i.isElement==null?void 0:i.isElement(I)))&&(k=a.floating[P]||s.floating[m]);const _=b/2-C/2,M=k/2-g[m]/2-1,T=mi(h[S],M),D=mi(h[y],M),A=T,O=k-g[m]-D,R=k/2-g[m]/2+_,B=zx(A,R,O),L=!l.arrow&&rc(o)!=null&&R!==B&&s.reference[m]/2-(R<A?T:D)-g[m]/2<0,G=L?R<A?R-A:R-O:0;return{[f]:p[f]+G,data:{[f]:B,centerOffset:R-B-G,...L&&{alignmentOffset:G}},reset:L}}}),Voe=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:m="none",flipAlignment:g=!0,...v}=xs(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const S=ws(o),y=yi(a),P=ws(a)===a,b=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(P||!g?[Nf(a)]:Boe(a)),I=m!=="none";!p&&I&&C.push(...Hoe(a,g,m,b));const k=[a,...C],_=await Ku(e,v),M=[];let T=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&M.push(_[S]),h){const R=zoe(o,i,b);M.push(_[R[0]],_[R[1]])}if(T=[...T,{placement:o,overflows:M}],!M.every(R=>R<=0)){var D,A;const R=(((D=s.flip)==null?void 0:D.index)||0)+1,B=k[R];if(B)return{data:{index:R,overflows:T},reset:{placement:B}};let L=(A=T.filter(G=>G.overflows[0]<=0).sort((G,$)=>G.overflows[1]-$.overflows[1])[0])==null?void 0:A.placement;if(!L)switch(f){case"bestFit":{var O;const G=(O=T.filter($=>{if(I){const U=yi($.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 oE(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function sE(t){return $oe.some(e=>t[e]>=0)}const Yoe=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...o}=xs(t,e);switch(r){case"referenceHidden":{const s=await Ku(e,{...o,elementContext:"reference"}),i=oE(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:sE(i)}}}case"escaped":{const s=await Ku(e,{...o,altBoundary:!0}),i=oE(s,n.floating);return{data:{escapedOffsets:i,escaped:sE(i)}}}default:return{}}}}};async function Xoe(t,e){const{placement:n,platform:r,elements:o}=t,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=ws(n),a=rc(n),l=yi(n)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,h=xs(e,t);let{mainAxis:p,crossAxis:f,alignmentAxis:m}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof m=="number"&&(f=a==="end"?m*-1:m),l?{x:f*u,y:p*c}:{x:p*c,y:f*u}}const qoe=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 Xoe(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}=xs(t,e),c={x:n,y:r},u=await Ku(e,l),h=yi(ws(o)),p=X1(h);let f=c[p],m=c[h];if(s){const v=p==="y"?"top":"left",S=p==="y"?"bottom":"right",y=f+u[v],P=f-u[S];f=zx(y,f,P)}if(i){const v=h==="y"?"top":"left",S=h==="y"?"bottom":"right",y=m+u[v],P=m-u[S];m=zx(y,m,P)}const g=a.fn({...e,[p]:f,[h]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:s,[h]:i}}}}}},Qoe=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}=xs(t,e),u={x:n,y:r},h=yi(o),p=X1(h);let f=u[p],m=u[h];const g=xs(a,e),v=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const P=p==="y"?"height":"width",b=s.reference[p]-s.floating[P]+v.mainAxis,C=s.reference[p]+s.reference[P]-v.mainAxis;f<b?f=b:f>C&&(f=C)}if(c){var S,y;const P=p==="y"?"width":"height",b=["top","left"].includes(ws(o)),C=s.reference[h]-s.floating[P]+(b&&((S=i.offset)==null?void 0:S[h])||0)+(b?0:v.crossAxis),I=s.reference[h]+s.reference[P]+(b?0:((y=i.offset)==null?void 0:y[h])||0)-(b?v.crossAxis:0);m<C?m=C:m>I&&(m=I)}return{[p]:f,[h]:m}}}},Joe=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}=xs(t,e),u=await Ku(e,c),h=ws(o),p=rc(o),f=yi(o)==="y",{width:m,height:g}=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=g-u.top-u.bottom,P=m-u.left-u.right,b=mi(g-u[v],y),C=mi(m-u[S],P),I=!e.middlewareData.shift;let k=b,_=C;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(_=P),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(k=y),I&&!p){const T=ir(u.left,0),D=ir(u.right,0),A=ir(u.top,0),O=ir(u.bottom,0);f?_=m-2*(T!==0||D!==0?T+D:ir(u.left,u.right)):k=g-2*(A!==0||O!==0?A+O:ir(u.top,u.bottom))}await l({...e,availableWidth:_,availableHeight:k});const M=await i.getDimensions(a.floating);return m!==M.width||g!==M.height?{reset:{rects:!0}}:{}}}};function im(){return typeof window<"u"}function oc(t){return G3(t)?(t.nodeName||"").toLowerCase():"#document"}function pr(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Ho(t){var e;return(e=(G3(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function G3(t){return im()?t instanceof Node||t instanceof pr(t).Node:!1}function io(t){return im()?t instanceof Element||t instanceof pr(t).Element:!1}function $o(t){return im()?t instanceof HTMLElement||t instanceof pr(t).HTMLElement:!1}function iE(t){return!im()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof pr(t).ShadowRoot}function wd(t){const{overflow:e,overflowX:n,overflowY:r,display:o}=ao(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!["inline","contents"].includes(o)}function ese(t){return["table","td","th"].includes(oc(t))}function am(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function Q1(t){const e=J1(),n=io(t)?ao(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 tse(t){let e=Si(t);for(;$o(e)&&!jl(e);){if(Q1(e))return e;if(am(e))return null;e=Si(e)}return null}function J1(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function jl(t){return["html","body","#document"].includes(oc(t))}function ao(t){return pr(t).getComputedStyle(t)}function lm(t){return io(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function Si(t){if(oc(t)==="html")return t;const e=t.assignedSlot||t.parentNode||iE(t)&&t.host||Ho(t);return iE(e)?e.host:e}function V3(t){const e=Si(t);return jl(e)?t.ownerDocument?t.ownerDocument.body:t.body:$o(e)&&wd(e)?e:V3(e)}function Wu(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const o=V3(t),s=o===((r=t.ownerDocument)==null?void 0:r.body),i=pr(o);if(s){const a=Ux(i);return e.concat(i,i.visualViewport||[],wd(o)?o:[],a&&n?Wu(a):[])}return e.concat(o,Wu(o,[],n))}function Ux(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Y3(t){const e=ao(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const o=$o(t),s=o?t.offsetWidth:n,i=o?t.offsetHeight:r,a=Ff(n)!==s||Ff(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function eb(t){return io(t)?t:t.contextElement}function wl(t){const e=eb(t);if(!$o(e))return jo(1);const n=e.getBoundingClientRect(),{width:r,height:o,$:s}=Y3(e);let i=(s?Ff(n.width):n.width)/r,a=(s?Ff(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const nse=jo(0);function X3(t){const e=pr(t);return!J1()||!e.visualViewport?nse:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function rse(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==pr(t)?!1:e}function da(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=eb(t);let i=jo(1);e&&(r?io(r)&&(i=wl(r)):i=wl(t));const a=rse(s,n,r)?X3(s):jo(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&&io(r)?pr(r):r;let m=p,g=Ux(m);for(;g&&r&&f!==m;){const v=wl(g),S=g.getBoundingClientRect(),y=ao(g),P=S.left+(g.clientLeft+parseFloat(y.paddingLeft))*v.x,b=S.top+(g.clientTop+parseFloat(y.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,h*=v.y,l+=P,c+=b,m=pr(g),g=Ux(m)}}return zf({width:u,height:h,x:l,y:c})}function tb(t,e){const n=lm(t).scrollLeft;return e?e.left+n:da(Ho(t)).left+n}function q3(t,e,n){n===void 0&&(n=!1);const r=t.getBoundingClientRect(),o=r.left+e.scrollLeft-(n?0:tb(t,r)),s=r.top+e.scrollTop;return{x:o,y:s}}function ose(t){let{elements:e,rect:n,offsetParent:r,strategy:o}=t;const s=o==="fixed",i=Ho(r),a=e?am(e.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=jo(1);const u=jo(0),h=$o(r);if((h||!h&&!s)&&((oc(r)!=="body"||wd(i))&&(l=lm(r)),$o(r))){const f=da(r);c=wl(r),u.x=f.x+r.clientLeft,u.y=f.y+r.clientTop}const p=i&&!h&&!s?q3(i,l,!0):jo(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+p.x,y:n.y*c.y-l.scrollTop*c.y+u.y+p.y}}function sse(t){return Array.from(t.getClientRects())}function ise(t){const e=Ho(t),n=lm(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+tb(t);const a=-n.scrollTop;return ao(r).direction==="rtl"&&(i+=ir(e.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function ase(t,e){const n=pr(t),r=Ho(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=J1();(!c||c&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function lse(t,e){const n=da(t,!0,e==="fixed"),r=n.top+t.clientTop,o=n.left+t.clientLeft,s=$o(t)?wl(t):jo(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 aE(t,e,n){let r;if(e==="viewport")r=ase(t,n);else if(e==="document")r=ise(Ho(t));else if(io(e))r=lse(e,n);else{const o=X3(t);r={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return zf(r)}function Z3(t,e){const n=Si(t);return n===e||!io(n)||jl(n)?!1:ao(n).position==="fixed"||Z3(n,e)}function cse(t,e){const n=e.get(t);if(n)return n;let r=Wu(t,[],!1).filter(a=>io(a)&&oc(a)!=="body"),o=null;const s=ao(t).position==="fixed";let i=s?Si(t):t;for(;io(i)&&!jl(i);){const a=ao(i),l=Q1(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||wd(i)&&!l&&Z3(t,i))?r=r.filter(u=>u!==i):o=a,i=Si(i)}return e.set(t,r),r}function use(t){let{element:e,boundary:n,rootBoundary:r,strategy:o}=t;const i=[...n==="clippingAncestors"?am(e)?[]:cse(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=aE(e,u,o);return c.top=ir(h.top,c.top),c.right=mi(h.right,c.right),c.bottom=mi(h.bottom,c.bottom),c.left=ir(h.left,c.left),c},aE(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function dse(t){const{width:e,height:n}=Y3(t);return{width:e,height:n}}function hse(t,e,n){const r=$o(e),o=Ho(e),s=n==="fixed",i=da(t,!0,s,e);let a={scrollLeft:0,scrollTop:0};const l=jo(0);if(r||!r&&!s)if((oc(e)!=="body"||wd(o))&&(a=lm(e)),r){const p=da(e,!0,s,e);l.x=p.x+e.clientLeft,l.y=p.y+e.clientTop}else o&&(l.x=tb(o));const c=o&&!r&&!s?q3(o,a):jo(0),u=i.left+a.scrollLeft-l.x-c.x,h=i.top+a.scrollTop-l.y-c.y;return{x:u,y:h,width:i.width,height:i.height}}function hS(t){return ao(t).position==="static"}function lE(t,e){if(!$o(t)||ao(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Ho(t)===n&&(n=n.ownerDocument.body),n}function Q3(t,e){const n=pr(t);if(am(t))return n;if(!$o(t)){let o=Si(t);for(;o&&!jl(o);){if(io(o)&&!hS(o))return o;o=Si(o)}return n}let r=lE(t,e);for(;r&&ese(r)&&hS(r);)r=lE(r,e);return r&&jl(r)&&hS(r)&&!Q1(r)?n:r||tse(t)||n}const pse=async function(t){const e=this.getOffsetParent||Q3,n=this.getDimensions,r=await n(t.floating);return{reference:hse(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function fse(t){return ao(t).direction==="rtl"}const gse={convertOffsetParentRelativeRectToViewportRelativeRect:ose,getDocumentElement:Ho,getClippingRect:use,getOffsetParent:Q3,getElementRects:pse,getClientRects:sse,getDimensions:dse,getScale:wl,isElement:io,isRTL:fse};function mse(t,e){let n=null,r;const o=Ho(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=Th(u),m=Th(o.clientWidth-(c+h)),g=Th(o.clientHeight-(u+p)),v=Th(c),y={rootMargin:-f+"px "+-m+"px "+-g+"px "+-v+"px",threshold:ir(0,mi(1,l))||1};let P=!0;function b(C){const I=C[0].intersectionRatio;if(I!==l){if(!P)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}P=!1}try{n=new IntersectionObserver(b,{...y,root:o.ownerDocument})}catch{n=new IntersectionObserver(b,y)}n.observe(t)}return i(!0),s}function yse(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=eb(t),u=o||s?[...c?Wu(c):[],...Wu(e)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",n,{passive:!0}),s&&S.addEventListener("resize",n)});const h=c&&a?mse(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 P;(P=f)==null||P.observe(e)})),n()}),c&&!l&&f.observe(c),f.observe(e));let m,g=l?da(t):null;l&&v();function v(){const S=da(t);g&&(S.x!==g.x||S.y!==g.y||S.width!==g.width||S.height!==g.height)&&n(),g=S,m=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(m)}}const Sse=qoe,vse=Zoe,xse=Voe,wse=Joe,bse=Yoe,cE=Goe,Pse=Qoe,Cse=(t,e,n)=>{const r=new Map,o={platform:gse,...n},s={...o.platform,_c:r};return Woe(t,e,{...o,platform:s})};var dp=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Bf(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,o;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!Bf(t[r],e[r]))return!1;return!0}if(o=Object.keys(t),n=o.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&t.$$typeof)&&!Bf(t[s],e[s]))return!1}return!0}return t!==t&&e!==e}function J3(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function uE(t,e){const n=J3(t);return Math.round(e*n)/n}function pS(t){const e=w.useRef(t);return dp(()=>{e.current=t}),e}function _se(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=t,[u,h]=w.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[p,f]=w.useState(r);Bf(p,r)||f(r);const[m,g]=w.useState(null),[v,S]=w.useState(null),y=w.useCallback($=>{$!==I.current&&(I.current=$,g($))},[]),P=w.useCallback($=>{$!==k.current&&(k.current=$,S($))},[]),b=s||m,C=i||v,I=w.useRef(null),k=w.useRef(null),_=w.useRef(u),M=l!=null,T=pS(l),D=pS(o),A=pS(c),O=w.useCallback(()=>{if(!I.current||!k.current)return;const $={placement:e,strategy:n,middleware:p};D.current&&($.platform=D.current),Cse(I.current,k.current,$).then(U=>{const Y={...U,isPositioned:A.current!==!1};R.current&&!Bf(_.current,Y)&&(_.current=Y,hi.flushSync(()=>{h(Y)}))})},[p,e,n,D,A]);dp(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,h($=>({...$,isPositioned:!1})))},[c]);const R=w.useRef(!1);dp(()=>(R.current=!0,()=>{R.current=!1}),[]),dp(()=>{if(b&&(I.current=b),C&&(k.current=C),b&&C){if(T.current)return T.current(b,C,O);O()}},[b,C,O,T,M]);const B=w.useMemo(()=>({reference:I,floating:k,setReference:y,setFloating:P}),[y,P]),L=w.useMemo(()=>({reference:b,floating:C}),[b,C]),G=w.useMemo(()=>{const $={position:n,left:0,top:0};if(!L.floating)return $;const U=uE(L.floating,u.x),Y=uE(L.floating,u.y);return a?{...$,transform:"translate("+U+"px, "+Y+"px)",...J3(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 Ise=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?cE({element:r.current,padding:o}).fn(n):{}:r?cE({element:r,padding:o}).fn(n):{}}}},Ese=(t,e)=>({...Sse(t),options:[t,e]}),kse=(t,e)=>({...vse(t),options:[t,e]}),Tse=(t,e)=>({...Pse(t),options:[t,e]}),Mse=(t,e)=>({...xse(t),options:[t,e]}),Ase=(t,e)=>({...wse(t),options:[t,e]}),jse=(t,e)=>({...bse(t),options:[t,e]}),Ose=(t,e)=>({...Ise(t),options:[t,e]});var Dse="Arrow",eL=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"})})});eL.displayName=Dse;var Rse=eL;function tL(t){const[e,n]=w.useState(void 0);return gi(()=>{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 nb="Popper",[nL,cm]=F1(nb),[Lse,rL]=nL(nb),oL=t=>{const{__scopePopper:e,children:n}=t,[r,o]=w.useState(null);return d.jsx(Lse,{scope:e,anchor:r,onAnchorChange:o,children:n})};oL.displayName=nb;var sL="PopperAnchor",iL=w.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...o}=t,s=rL(sL,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})});iL.displayName=sL;var rb="PopperContent",[$se,Fse]=nL(rb),aL=w.forwardRef((t,e)=>{var Fe,st,$e,lt,Ue,tr;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:m,...g}=t,v=rL(rb,n),[S,y]=w.useState(null),P=Qe(e,Ft=>y(Ft)),[b,C]=w.useState(null),I=tL(b),k=(I==null?void 0:I.width)??0,_=(I==null?void 0:I.height)??0,M=r+(s!=="center"?"-"+s:""),T=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(c)?c:[c],A=D.length>0,O={padding:T,boundary:D.filter(zse),altBoundary:A},{refs:R,floatingStyles:B,placement:L,isPositioned:G,middlewareData:$}=_se({strategy:"fixed",placement:M,whileElementsMounted:(...Ft)=>yse(...Ft,{animationFrame:f==="always"}),elements:{reference:v.anchor},middleware:[Ese({mainAxis:o+_,alignmentAxis:i}),l&&kse({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Tse():void 0,...O}),l&&Mse({...O}),Ase({...O,apply:({elements:Ft,rects:jn,availableWidth:vt,availableHeight:Jt})=>{const{width:Wo,height:ic}=jn.reference,Ts=Ft.floating.style;Ts.setProperty("--radix-popper-available-width",`${vt}px`),Ts.setProperty("--radix-popper-available-height",`${Jt}px`),Ts.setProperty("--radix-popper-anchor-width",`${Wo}px`),Ts.setProperty("--radix-popper-anchor-height",`${ic}px`)}}),b&&Ose({element:b,padding:a}),Bse({arrowWidth:k,arrowHeight:_}),p&&jse({strategy:"referenceHidden",...O})]}),[U,Y]=uL(L),ee=qt(m);gi(()=>{G&&(ee==null||ee())},[G,ee]);const he=(Fe=$.arrow)==null?void 0:Fe.x,ue=(st=$.arrow)==null?void 0:st.y,ke=(($e=$.arrow)==null?void 0:$e.centerOffset)!==0,[se,We]=w.useState();return gi(()=>{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,(Ue=$.transformOrigin)==null?void 0:Ue.y].join(" "),...((tr=$.hide)==null?void 0:tr.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx($se,{scope:n,placedSide:U,onArrowChange:C,arrowX:he,arrowY:ue,shouldHideArrow:ke,children:d.jsx(Ae.div,{"data-side":U,"data-align":Y,...g,ref:P,style:{...g.style,animation:G?void 0:"none"}})})})});aL.displayName=rb;var lL="PopperArrow",Nse={top:"bottom",right:"left",bottom:"top",left:"right"},cL=w.forwardRef(function(e,n){const{__scopePopper:r,...o}=e,s=Fse(lL,r),i=Nse[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(Rse,{...o,ref:n,style:{...o.style,display:"block"}})})});cL.displayName=lL;function zse(t){return t!==null}var Bse=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]=uL(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 m="",g="";return c==="bottom"?(m=i?h:`${p}px`,g=`${-l}px`):c==="top"?(m=i?h:`${p}px`,g=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,g=i?h:`${f}px`):c==="left"&&(m=`${r.floating.width+l}px`,g=i?h:`${f}px`),{data:{x:m,y:g}}}});function uL(t){const[e,n="center"]=t.split("-");return[e,n]}var ob=oL,sb=iL,dL=aL,hL=cL,fS="rovingFocusGroup.onEntryFocus",Use={bubbles:!1,cancelable:!0},um="RovingFocusGroup",[Hx,pL,Hse]=Qg(um),[Kse,fL]=F1(um,[Hse]),[Wse,Gse]=Kse(um),gL=w.forwardRef((t,e)=>d.jsx(Hx.Provider,{scope:t.__scopeRovingFocusGroup,children:d.jsx(Hx.Slot,{scope:t.__scopeRovingFocusGroup,children:d.jsx(Vse,{...t,ref:e})})}));gL.displayName=um;var Vse=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),m=Y1(s),[g=null,v]=Ti({prop:i,defaultProp:a,onChange:l}),[S,y]=w.useState(!1),P=qt(c),b=pL(n),C=w.useRef(!1),[I,k]=w.useState(0);return w.useEffect(()=>{const _=p.current;if(_)return _.addEventListener(fS,P),()=>_.removeEventListener(fS,P)},[P]),d.jsx(Wse,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,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 M=!C.current;if(_.target===_.currentTarget&&M&&!S){const T=new CustomEvent(fS,Use);if(_.currentTarget.dispatchEvent(T),!T.defaultPrevented){const D=b().filter(L=>L.focusable),A=D.find(L=>L.active),O=D.find(L=>L.id===g),B=[A,O,...D].filter(Boolean).map(L=>L.ref.current);SL(B,u)}}C.current=!1}),onBlur:oe(t.onBlur,()=>y(!1))})})}),mL="RovingFocusGroupItem",yL=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,...i}=t,a=ps(),l=s||a,c=Gse(mL,n),u=c.currentTabStopId===l,h=pL(n),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return w.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),d.jsx(Hx.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,m=>{r?c.onItemFocus(l):m.preventDefault()}),onFocus:oe(t.onFocus,()=>c.onItemFocus(l)),onKeyDown:oe(t.onKeyDown,m=>{if(m.key==="Tab"&&m.shiftKey){c.onItemShiftTab();return}if(m.target!==m.currentTarget)return;const g=qse(m,c.orientation,c.dir);if(g!==void 0){if(m.metaKey||m.ctrlKey||m.altKey||m.shiftKey)return;m.preventDefault();let S=h().filter(y=>y.focusable).map(y=>y.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const y=S.indexOf(m.currentTarget);S=c.loop?Zse(S,y+1):S.slice(y+1)}setTimeout(()=>SL(S))}})})})});yL.displayName=mL;var Yse={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Xse(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function qse(t,e,n){const r=Xse(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return Yse[r]}function SL(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 Qse=gL,Jse=yL,Kx=["Enter"," "],eie=["ArrowDown","PageUp","Home"],vL=["ArrowUp","PageDown","End"],tie=[...eie,...vL],nie={ltr:[...Kx,"ArrowRight"],rtl:[...Kx,"ArrowLeft"]},rie={ltr:["ArrowLeft"],rtl:["ArrowRight"]},bd="Menu",[Gu,oie,sie]=Qg(bd),[_a,dm]=ba(bd,[sie,cm,fL]),Pd=cm(),xL=fL(),[wL,Mi]=_a(bd),[iie,Cd]=_a(bd),bL=t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=t,a=Pd(e),[l,c]=w.useState(null),u=w.useRef(!1),h=qt(s),p=Y1(o);return w.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),d.jsx(ob,{...a,children:d.jsx(wL,{scope:e,open:n,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(iie,{scope:e,onClose:w.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};bL.displayName=bd;var aie="MenuAnchor",ib=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=Pd(n);return d.jsx(sb,{...o,...r,ref:e})});ib.displayName=aie;var ab="MenuPortal",[lie,PL]=_a(ab,{forceMount:void 0}),CL=t=>{const{__scopeMenu:e,forceMount:n,children:r,container:o}=t,s=Mi(ab,e);return d.jsx(lie,{scope:e,forceMount:n,children:d.jsx(uo,{present:n||s.open,children:d.jsx(xd,{asChild:!0,container:o,children:r})})})};CL.displayName=ab;var Dr="MenuContent",[cie,lb]=_a(Dr),_L=w.forwardRef((t,e)=>{const n=PL(Dr,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=Mi(Dr,t.__scopeMenu),i=Cd(Dr,t.__scopeMenu);return d.jsx(Gu.Provider,{scope:t.__scopeMenu,children:d.jsx(uo,{present:r||s.open,children:d.jsx(Gu.Slot,{scope:t.__scopeMenu,children:i.modal?d.jsx(uie,{...o,ref:e}):d.jsx(die,{...o,ref:e})})})})}),uie=w.forwardRef((t,e)=>{const n=Mi(Dr,t.__scopeMenu),r=w.useRef(null),o=Qe(e,r);return w.useEffect(()=>{const s=r.current;if(s)return O1(s)},[]),d.jsx(cb,{...t,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:oe(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),die=w.forwardRef((t,e)=>{const n=Mi(Dr,t.__scopeMenu);return d.jsx(cb,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),cb=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:m,...g}=t,v=Mi(Dr,n),S=Cd(Dr,n),y=Pd(n),P=xL(n),b=oie(n),[C,I]=w.useState(null),k=w.useRef(null),_=Qe(e,k,v.onContentChange),M=w.useRef(0),T=w.useRef(""),D=w.useRef(0),A=w.useRef(null),O=w.useRef("right"),R=w.useRef(0),B=m?Zg:w.Fragment,L=m?{as:ca,allowPinchZoom:!0}:void 0,G=U=>{var Fe,st;const Y=T.current+U,ee=b().filter($e=>!$e.disabled),he=document.activeElement,ue=(Fe=ee.find($e=>$e.ref.current===he))==null?void 0:Fe.textValue,ke=ee.map($e=>$e.textValue),se=Pie(ke,Y,ue),We=(st=ee.find($e=>$e.textValue===se))==null?void 0:st.ref.current;(function $e(lt){T.current=lt,window.clearTimeout(M.current),lt!==""&&(M.current=window.setTimeout(()=>$e(""),1e3))})(Y),We&&setTimeout(()=>We.focus())};w.useEffect(()=>()=>window.clearTimeout(M.current),[]),j1();const $=w.useCallback(U=>{var ee,he;return O.current===((ee=A.current)==null?void 0:ee.side)&&_ie(U,(he=A.current)==null?void 0:he.area)},[]);return d.jsx(cie,{scope:n,searchRef:T,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=>{A.current=U},[]),children:d.jsx(B,{...L,children:d.jsx(Xg,{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(vd,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:d.jsx(Qse,{asChild:!0,...P,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(dL,{role:"menu","aria-orientation":"vertical","data-state":UL(v.open),"data-radix-menu-content":"",dir:S.dir,...y,...g,ref:_,style:{outline:"none",...g.style},onKeyDown:oe(g.onKeyDown,U=>{const ee=U.target.closest("[data-radix-menu-content]")===U.currentTarget,he=U.ctrlKey||U.altKey||U.metaKey,ue=U.key.length===1;ee&&(U.key==="Tab"&&U.preventDefault(),!he&&ue&&G(U.key));const ke=k.current;if(U.target!==ke||!tie.includes(U.key))return;U.preventDefault();const We=b().filter(Fe=>!Fe.disabled).map(Fe=>Fe.ref.current);vL.includes(U.key)&&We.reverse(),wie(We)}),onBlur:oe(t.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(M.current),T.current="")}),onPointerMove:oe(t.onPointerMove,Vu(U=>{const Y=U.target,ee=R.current!==U.clientX;if(U.currentTarget.contains(Y)&&ee){const he=U.clientX>R.current?"right":"left";O.current=he,R.current=U.clientX}}))})})})})})})});_L.displayName=Dr;var hie="MenuGroup",ub=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"group",...r,ref:e})});ub.displayName=hie;var pie="MenuLabel",IL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});IL.displayName=pie;var Uf="MenuItem",dE="menu.itemSelect",hm=w.forwardRef((t,e)=>{const{disabled:n=!1,onSelect:r,...o}=t,s=w.useRef(null),i=Cd(Uf,t.__scopeMenu),a=lb(Uf,t.__scopeMenu),l=Qe(e,s),c=w.useRef(!1),u=()=>{const h=s.current;if(!n&&h){const p=new CustomEvent(dE,{bubbles:!0,cancelable:!0});h.addEventListener(dE,f=>r==null?void 0:r(f),{once:!0}),A1(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(EL,{...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===" "||Kx.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});hm.displayName=Uf;var EL=w.forwardRef((t,e)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=t,i=lb(Uf,n),a=xL(n),l=w.useRef(null),c=Qe(e,l),[u,h]=w.useState(!1),[p,f]=w.useState("");return w.useEffect(()=>{const m=l.current;m&&f((m.textContent??"").trim())},[s.children]),d.jsx(Gu.ItemSlot,{scope:n,disabled:r,textValue:o??p,children:d.jsx(Jse,{asChild:!0,...a,focusable:!r,children:d.jsx(Ae.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:oe(t.onPointerMove,Vu(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:oe(t.onPointerLeave,Vu(m=>i.onItemLeave(m))),onFocus:oe(t.onFocus,()=>h(!0)),onBlur:oe(t.onBlur,()=>h(!1))})})})}),fie="MenuCheckboxItem",kL=w.forwardRef((t,e)=>{const{checked:n=!1,onCheckedChange:r,...o}=t;return d.jsx(OL,{scope:t.__scopeMenu,checked:n,children:d.jsx(hm,{role:"menuitemcheckbox","aria-checked":Hf(n)?"mixed":n,...o,ref:e,"data-state":pb(n),onSelect:oe(o.onSelect,()=>r==null?void 0:r(Hf(n)?!0:!n),{checkForDefaultPrevented:!1})})})});kL.displayName=fie;var TL="MenuRadioGroup",[gie,mie]=_a(TL,{value:void 0,onValueChange:()=>{}}),ML=w.forwardRef((t,e)=>{const{value:n,onValueChange:r,...o}=t,s=qt(r);return d.jsx(gie,{scope:t.__scopeMenu,value:n,onValueChange:s,children:d.jsx(ub,{...o,ref:e})})});ML.displayName=TL;var AL="MenuRadioItem",jL=w.forwardRef((t,e)=>{const{value:n,...r}=t,o=mie(AL,t.__scopeMenu),s=n===o.value;return d.jsx(OL,{scope:t.__scopeMenu,checked:s,children:d.jsx(hm,{role:"menuitemradio","aria-checked":s,...r,ref:e,"data-state":pb(s),onSelect:oe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});jL.displayName=AL;var db="MenuItemIndicator",[OL,yie]=_a(db,{checked:!1}),DL=w.forwardRef((t,e)=>{const{__scopeMenu:n,forceMount:r,...o}=t,s=yie(db,n);return d.jsx(uo,{present:r||Hf(s.checked)||s.checked===!0,children:d.jsx(Ae.span,{...o,ref:e,"data-state":pb(s.checked)})})});DL.displayName=db;var Sie="MenuSeparator",RL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});RL.displayName=Sie;var vie="MenuArrow",LL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,o=Pd(n);return d.jsx(hL,{...o,...r,ref:e})});LL.displayName=vie;var hb="MenuSub",[xie,$L]=_a(hb),FL=t=>{const{__scopeMenu:e,children:n,open:r=!1,onOpenChange:o}=t,s=Mi(hb,e),i=Pd(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(ob,{...i,children:d.jsx(wL,{scope:e,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(xie,{scope:e,contentId:ps(),triggerId:ps(),trigger:a,onTriggerChange:l,children:n})})})};FL.displayName=hb;var Gc="MenuSubTrigger",NL=w.forwardRef((t,e)=>{const n=Mi(Gc,t.__scopeMenu),r=Cd(Gc,t.__scopeMenu),o=$L(Gc,t.__scopeMenu),s=lb(Gc,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(ib,{asChild:!0,...c,children:d.jsx(EL,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":UL(n.open),...t,ref:Yg(e,o.onTriggerChange),onClick:h=>{var p;(p=t.onClick)==null||p.call(t,h),!(t.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:oe(t.onPointerMove,Vu(h=>{s.onItemEnter(h),!h.defaultPrevented&&!t.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:oe(t.onPointerLeave,Vu(h=>{var f,m;u();const p=(f=n.content)==null?void 0:f.getBoundingClientRect();if(p){const g=(m=n.content)==null?void 0:m.dataset.side,v=g==="right",S=v?-5:5,y=p[v?"left":"right"],P=p[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+S,y:h.clientY},{x:y,y:p.top},{x:P,y:p.top},{x:P,y:p.bottom},{x:y,y:p.bottom}],side:g}),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===" "||nie[r.dir].includes(h.key)&&(n.onOpenChange(!0),(f=n.content)==null||f.focus(),h.preventDefault())})})})});NL.displayName=Gc;var zL="MenuSubContent",BL=w.forwardRef((t,e)=>{const n=PL(Dr,t.__scopeMenu),{forceMount:r=n.forceMount,...o}=t,s=Mi(Dr,t.__scopeMenu),i=Cd(Dr,t.__scopeMenu),a=$L(zL,t.__scopeMenu),l=w.useRef(null),c=Qe(e,l);return d.jsx(Gu.Provider,{scope:t.__scopeMenu,children:d.jsx(uo,{present:r||s.open,children:d.jsx(Gu.Slot,{scope:t.__scopeMenu,children:d.jsx(cb,{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=rie[i.dir].includes(u.key);h&&p&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),u.preventDefault())})})})})})});BL.displayName=zL;function UL(t){return t?"open":"closed"}function Hf(t){return t==="indeterminate"}function pb(t){return Hf(t)?"indeterminate":t?"checked":"unchecked"}function wie(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}function bie(t,e){return t.map((n,r)=>t[(e+r)%t.length])}function Pie(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=bie(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 Cie(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 _ie(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return Cie(n,e)}function Vu(t){return e=>e.pointerType==="mouse"?t(e):void 0}var HL=bL,KL=ib,WL=CL,GL=_L,VL=ub,YL=IL,XL=hm,qL=kL,ZL=ML,QL=jL,JL=DL,e$=RL,t$=LL,n$=FL,r$=NL,o$=BL,fb="ContextMenu",[Iie,ege]=ba(fb,[dm]),mn=dm(),[Eie,s$]=Iie(fb),i$=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(Eie,{scope:e,open:i,onOpenChange:u,modal:s,children:d.jsx(HL,{...l,dir:o,open:i,onOpenChange:u,modal:s,children:n})})};i$.displayName=fb;var a$="ContextMenuTrigger",l$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,disabled:r=!1,...o}=t,s=s$(a$,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(KL,{...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,Mh(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?t.onPointerMove:oe(t.onPointerMove,Mh(u)),onPointerCancel:r?t.onPointerCancel:oe(t.onPointerCancel,Mh(u)),onPointerUp:r?t.onPointerUp:oe(t.onPointerUp,Mh(u))})]})});l$.displayName=a$;var kie="ContextMenuPortal",gb=t=>{const{__scopeContextMenu:e,...n}=t,r=mn(e);return d.jsx(WL,{...r,...n})};gb.displayName=kie;var c$="ContextMenuContent",u$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=s$(c$,n),s=mn(n),i=w.useRef(!1);return d.jsx(GL,{...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)"}})});u$.displayName=c$;var Tie="ContextMenuGroup",d$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(VL,{...o,...r,ref:e})});d$.displayName=Tie;var Mie="ContextMenuLabel",Aie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(YL,{...o,...r,ref:e})});Aie.displayName=Mie;var jie="ContextMenuItem",h$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(XL,{...o,...r,ref:e})});h$.displayName=jie;var Oie="ContextMenuCheckboxItem",p$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(qL,{...o,...r,ref:e})});p$.displayName=Oie;var Die="ContextMenuRadioGroup",Rie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(ZL,{...o,...r,ref:e})});Rie.displayName=Die;var Lie="ContextMenuRadioItem",$ie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(QL,{...o,...r,ref:e})});$ie.displayName=Lie;var Fie="ContextMenuItemIndicator",Nie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(JL,{...o,...r,ref:e})});Nie.displayName=Fie;var zie="ContextMenuSeparator",Bie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(e$,{...o,...r,ref:e})});Bie.displayName=zie;var Uie="ContextMenuArrow",Hie=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(t$,{...o,...r,ref:e})});Hie.displayName=Uie;var Kie="ContextMenuSub",f$=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,open:o,defaultOpen:s}=t,i=mn(e),[a,l]=Ti({prop:o,defaultProp:s,onChange:r});return d.jsx(n$,{...i,open:a,onOpenChange:l,children:n})};f$.displayName=Kie;var Wie="ContextMenuSubTrigger",g$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(r$,{...o,...r,ref:e})});g$.displayName=Wie;var Gie="ContextMenuSubContent",m$=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,o=mn(n);return d.jsx(o$,{...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)"}})});m$.displayName=Gie;function Mh(t){return e=>e.pointerType!=="mouse"?t(e):void 0}var Vie=i$,Yie=l$,Xie=gb,qie=u$,Zie=p$,mb="DropdownMenu",[Qie,tge]=ba(mb,[dm]),yn=dm(),[Jie,y$]=Qie(mb),S$=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]=Ti({prop:o,defaultProp:s,onChange:i});return d.jsx(Jie,{scope:e,triggerId:ps(),triggerRef:c,contentId:ps(),open:u,onOpenChange:h,onOpenToggle:w.useCallback(()=>h(p=>!p),[h]),modal:a,children:d.jsx(HL,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:n})})};S$.displayName=mb;var v$="DropdownMenuTrigger",x$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=t,s=y$(v$,n),i=yn(n);return d.jsx(KL,{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:Yg(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())})})})});x$.displayName=v$;var eae="DropdownMenuPortal",w$=t=>{const{__scopeDropdownMenu:e,...n}=t,r=yn(e);return d.jsx(WL,{...r,...n})};w$.displayName=eae;var b$="DropdownMenuContent",P$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=y$(b$,n),s=yn(n),i=w.useRef(!1);return d.jsx(GL,{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)"}})});P$.displayName=b$;var tae="DropdownMenuGroup",C$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(VL,{...o,...r,ref:e})});C$.displayName=tae;var nae="DropdownMenuLabel",rae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(YL,{...o,...r,ref:e})});rae.displayName=nae;var oae="DropdownMenuItem",_$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(XL,{...o,...r,ref:e})});_$.displayName=oae;var sae="DropdownMenuCheckboxItem",I$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(qL,{...o,...r,ref:e})});I$.displayName=sae;var iae="DropdownMenuRadioGroup",aae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(ZL,{...o,...r,ref:e})});aae.displayName=iae;var lae="DropdownMenuRadioItem",cae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(QL,{...o,...r,ref:e})});cae.displayName=lae;var uae="DropdownMenuItemIndicator",dae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(JL,{...o,...r,ref:e})});dae.displayName=uae;var hae="DropdownMenuSeparator",pae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(e$,{...o,...r,ref:e})});pae.displayName=hae;var fae="DropdownMenuArrow",gae=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(t$,{...o,...r,ref:e})});gae.displayName=fae;var mae=t=>{const{__scopeDropdownMenu:e,children:n,open:r,onOpenChange:o,defaultOpen:s}=t,i=yn(e),[a=!1,l]=Ti({prop:r,defaultProp:s,onChange:o});return d.jsx(n$,{...i,open:a,onOpenChange:l,children:n})},yae="DropdownMenuSubTrigger",E$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(r$,{...o,...r,ref:e})});E$.displayName=yae;var Sae="DropdownMenuSubContent",k$=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,o=yn(n);return d.jsx(o$,{...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)"}})});k$.displayName=Sae;var yb=S$,Sb=x$,pm=w$,vb=P$,vae=C$,xae=_$,wae=I$,bae=mae,Pae=E$,Cae=k$;function wr(){const t=s1();return H("isReadonlyMode",()=>!!(t!=null&&t.getIsReadonly()),[t])}const gS=[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 T$=Te.createContext(null);function _ae({forceMobile:t=!1,children:e}){const n=z(),r=H("breakpoint",()=>{const{width:o}=n.getViewportScreenBounds(),s=t?St.MOBILE_SM:gS.length-1;for(let i=0;i<s;i++)if(o>gS[i]&&o<=gS[i+1])return i;return s},[n]);return d.jsx(T$.Provider,{value:r,children:e})}function Mn(){const t=w.useContext(T$);if(t===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return t}const Iae=Ge.isDarwin?"⌘":"Ctrl",Eae=Ge.isDarwin?"⌥":"Alt";function M$(t){return t===","?[","]:t.split(",")[0].split("").map(e=>{const n=e.replace(/\$/g,Iae).replace(/\?/g,Eae).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function Wx(t){return"— "+M$(t).join(" ")}function du({children:t,visibleOnMobileLayout:e=!1}){const n=Mn();return!e&&n<St.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:M$(t).map((r,o)=>d.jsx("span",{children:r},o))})}const A$=w.createContext(null);function fm(){const t=w.useContext(A$);if(!t)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return t}function $r({type:t,sourceId:e,children:n}){return d.jsx(A$.Provider,{value:{type:t,sourceId:e},children:n})}function gm({id:t,kbd:e,label:n,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=fm(),u=wr(),h=Ce();if(u&&!r)return null;const p=Hu(n,l),f=p?h(p):void 0;switch(l){case"menu":return d.jsxs(wae,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:f,onSelect:m=>{o==null||o(c),xe(m)},disabled:i,checked:a,children:[d.jsx(Lo,{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(du,{children:e})]});case"context-menu":return d.jsxs(Zie,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:f,onSelect:m=>{o(c),xe(m)},disabled:i,checked:a,children:[d.jsx(Lo,{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(du,{children:e})]},t);default:return null}}function po({actionId:t="",...e}){const r=Ca()[t];return r?d.jsx(gm,{...r,...e}):null}function hE(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 Es(t,e){const n=s1(),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 ote(n?`${t}-${n.contextId}`:t,r,s)}function ha({id:t,children:e,modal:n=!1,debugOpen:r=!1}){const[o,s]=Es(t);return d.jsx(yb,{open:r||o,dir:"ltr",modal:n,onOpenChange:s,children:e})}function pa({children:t,...e}){return d.jsx(Sb,{dir:"ltr",asChild:!0,onTouchEnd:n=>xe(n),...e,children:t})}function fa({className:t,side:e="bottom",align:n="start",sideOffset:r=8,alignOffset:o=8,children:s}){const i=Mt();return d.jsx(pm,{container:i,children:d.jsx(vb,{className:le("tlui-menu",t),side:e,sideOffset:r,align:n,alignOffset:o,collisionPadding:4,children:s})})}function kae({id:t,children:e}){const[n,r]=Es(t);return d.jsx(bae,{open:n,onOpenChange:r,children:e})}function Tae({id:t,label:e,title:n,disabled:r}){return d.jsx(Pae,{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 Mae({id:t,alignOffset:e=-1,sideOffset:n=-6,size:r="small",children:o}){const s=Mt();return d.jsx(pm,{container:s,children:d.jsx(Cae,{"data-testid":t,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:n,collisionPadding:4,"data-size":r,children:o})})}function Aae({children:t}){return d.jsx(vae,{dir:"ltr",className:"tlui-menu__group",children:t})}function Yu({noClose:t,children:e}){return d.jsx(xae,{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}=fm(),p=Ce(),[f,m]=w.useState(!1);if(wr()&&!n)return null;const v=Hu(s,u),S=o?Wx(o):void 0,y=v?p(v):void 0,P=y&&S?`${y} ${S}`:y;switch(u){case"menu":return d.jsx(Yu,{children:d.jsxs(ce,{type:"menu","data-testid":`${h}.${r}`,disabled:t,title:P,onClick:b=>{l&&xe(b),f?m(!1):a(h)},children:[d.jsx(Pt,{children:y}),o&&d.jsx(du,{children:o})]})});case"context-menu":return t?null:d.jsxs(h$,{dir:"ltr",title:P,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:b=>{l&&xe(b),f?m(!1):a(h)},children:[d.jsx("span",{className:"tlui-button__label",draggable:!1,children:y}),o&&d.jsx(du,{children:o}),e&&d.jsx(hE,{})]});case"panel":return d.jsxs(ce,{"data-testid":`${h}.${r}`,type:"menu",title:P,disabled:t,onClick:()=>a(h),children:[d.jsx(Pt,{children:y}),e?d.jsx(hE,{}):i&&d.jsx(be,{icon:i})]});case"small-icons":case"icons":return d.jsx(ce,{"data-testid":`${h}.${r}`,type:"icon",title:P,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(du,{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:P,disabled:t,onTouchStart:b=>{xe(b),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:d.jsx(be,{icon:i})});case"toolbar-overflow":return d.jsx(Yu,{"aria-label":s,children:d.jsx(ce,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:P,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=Ca()[t];return r?d.jsx(Kt,{...r,...e}):null}const j$=w.createContext(null);function jae({overrides:t,children:e}){const n=z(),r=Qt(),{addDialog:o}=Pa(),s=H3(),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"})}},...[...Zr.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(Zr,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:D3}),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(j$.Provider,{value:i,children:e})}function xb(){const t=w.useContext(j$);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Rn({toolId:t="",...e}){const r=xb()[t];return r?d.jsx(Kt,{...r,...e}):null}function Oae({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:Dae}=Math,bl=Dae+1e-4;function O$(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,m=p,g=!1,v;for(let S=0;S<t.length;S++){v=t[S];const{point:y,vector:P}=t[S],b=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=b<0&&!g,_=I!==null&&I<.2;if(k||_){if(I>-.62&&i-v.runningLength>v.radius){const T=u.clone().mul(v.radius);u.clone().cpr(C)<0?(f=x.Add(y,T),m=x.Sub(y,T)):(f=x.Sub(y,T),m=x.Add(y,T)),l.push(f),c.push(m)}else{const T=u.clone().mul(v.radius).per(),D=x.Sub(v.input,T);for(let A=1/13,O=0;O<1;O+=A)f=x.RotWith(D,v.input,bl*O),l.push(f),m=x.RotWith(D,v.input,bl+bl*-O),c.push(m)}h=f,p=m,_&&(g=!0);continue}if(g=!1,v===o||v===s){const T=x.Per(P).mul(v.radius);l.push(x.Sub(y,T)),c.push(x.Add(y,T));continue}const M=x.Lrp(C,P,I).per().mul(v.radius);f=x.Sub(y,M),(S<=1||x.Dist2(h,f)>a)&&(l.push(f),h=f),m=x.Add(y,M),(S<=1||x.Dist2(p,m)>a)&&(c.push(m),p=m),u=P}return{left:l,right:c}}function wb(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:m}=O$(t,e),g=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 b=x.Add(g,x.Sub(g,v).uni().per().mul(-l.radius)),C=[];for(let I=1/13,k=I;k<=1;k+=I)C.push(x.RotWith(b,g,bl*2*k));return C}const S=[];if(!(h||p&&t.length===1))if(i)for(let b=1/8,C=b;C<=1;C+=b){const I=x.RotWith(m[0],g,bl*C);S.push(I)}else{const b=x.Sub(f[0],m[0]),C=x.Mul(b,.5),I=x.Mul(b,.51);S.push(x.Sub(g,C),x.Sub(g,I),x.Add(g,I),x.Add(g,C))}const y=[],P=c.vector.clone().per().neg();if(p||h&&t.length===1)y.push(v);else if(a){const b=x.Add(v,x.Mul(P,c.radius));for(let C=1/29,I=C;I<1;I+=C)y.push(x.RotWith(b,v,bl*3*I))}else y.push(x.Add(v,x.Mul(P,c.radius)),x.Add(v,x.Mul(P,c.radius*.99)),x.Sub(v,x.Mul(P,c.radius*.99)),x.Sub(v,x.Mul(P,c.radius)));return f.concat(y,m.reverse(),S)}const Rae=.025,Lae=.01;function Fo(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>=Rae);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=Lae);)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 P=x.Lrp(i[0],S,y/4);P.z=(i[0].z+(S.z-i[0].z))*y/4,i.push(P)}}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],m,g;u&&n>0&&i.push(i[i.length-1].clone());for(let S=1,y=i.length;S<y;S++)m=!s||e.last&&S===y-1?i[S].clone():i[S].clone().lrp(f.point,1-s),!f.point.equals(m)&&(g=x.Dist(m,f.point),p+=g,!(S<4&&p<r)&&(f={input:i[S],point:m,pressure:o?.5:i[S].z,vector:x.Sub(f.point,m).uni(),distance:g,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:Ls}=Math,mS=.275;function mm(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 P=Ls(1,f.distance/n);if(o){const b=Ls(1,1-P);v=Ls(1,p+(b-p)*(P*mS))}else v=Ls(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 P=Ls(1,f.distance/n);if(o){const b=Ls(1,1-P);y=Ls(1,p+(b-p)*(P*mS))}else y=Ls(1,p+(y-p)*(P*mS));f.radius=n*s(.5-r*(.5-y)),p=y}else f.radius=n/2;h===void 0&&(h=f.radius)}}const m=i.taper===!1?0:i.taper===!0?Math.max(n,u):i.taper,g=a.taper===!1?0:a.taper===!0?Math.max(n,u):a.taper;if(m||g)for(let v=0;v<t.length;v++){f=t[v];const{runningLength:S}=f,y=S<m?l(S/m):1,P=u-S<g?c((u-S)/g):1;f.radius=Math.max(.01,f.radius*Math.min(y,P))}return t}function $ae(t,e={}){return wb(mm(Fo(t,e),e),e)}function pE({scribble:t,zoom:e,color:n,opacity:r,className:o}){if(!t.points.length)return null;const s=$ae(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=d1(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 Fae=({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(cj,{bounds:t,rotation:e}):null};function Nae({size:t,width:e,height:n,hideAlternateHandles:r}){const o=N(t/3),s=o/2;return d.jsxs("svg",{className:"tl-overlays__item",children:[d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
336
|
-
${N(0-s)},${N(t)}
|
|
337
|
-
${N(0-s)},${N(0-s)}
|
|
338
|
-
${N(t)},${N(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(e/2-t),y1:N(0-s),x2:N(e/2+t),y2:N(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),d.jsx("polyline",{className:le("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
339
|
-
${N(e-t)},${N(0-s)}
|
|
340
|
-
${N(e+s)},${N(0-s)}
|
|
341
|
-
${N(e+s)},${N(t)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(e+s),y1:N(n/2-t),x2:N(e+s),y2:N(n/2+t),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
342
|
-
${N(e+s)},${N(n-t)}
|
|
343
|
-
${N(e+s)},${N(n+s)}
|
|
344
|
-
${N(e-t)},${N(n+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(e/2-t),y1:N(n+s),x2:N(e/2+t),y2:N(n+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),d.jsx("polyline",{className:le("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
345
|
-
${N(0+t)},${N(n+s)}
|
|
346
|
-
${N(0-s)},${N(n+s)}
|
|
347
|
-
${N(0-s)},${N(n-t)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),d.jsx("line",{className:le("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(0-s),y1:N(n/2-t),x2:N(0-s),y2:N(n/2+t),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const zae=$t(function({bounds:e,rotation:n}){const r=z(),o=w.useRef(null),s=wr(),i=xo("top"),a=xo("right"),l=xo("bottom"),c=xo("left"),u=xo("top_left"),h=xo("top_right"),p=xo("bottom_right"),f=xo("bottom_left"),m=r.getInstanceState().cursor.type==="default",g=r.getInstanceState().isCoarsePointer,v=r.getOnlySelectedShape(),S=v&&r.isShapeOrAncestorLocked(v),y=v?r.getShapeUtil(v).expandSelectionOutlinePx(v):0;if(Zl(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 P=r.getZoomLevel(),b=r.getInstanceState().isChangingStyle,C=e.width,I=e.height,k=8/P,_=C<k*2,M=I<k*2,T=C<k*4,D=I<k*4,A=C<k*5,O=I<k*5,R=g?1.75:1,B=6/P*R,L=(T?B/2:B)*(R*.75),G=(D?B/2:B)*(R*.75),$=(v?!r.getShapeUtil(v).hideSelectionBoundsFg(v):!0)&&!b;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")&&!b&&!s,ee=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!b&&!s,he=!g&&!(_||M)&&(ee||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!S,ue=g&&(!T||!D)&&(ee||Y)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!S,ke=ee&&(v?r.getShapeUtil(v).canResize(v)&&!r.getShapeUtil(v).hideResizeHandles(v):!0)&&!Y&&!S,se=_||M,We=_&&M,Fe=A||O,st=ke||Y,$e=!he,lt=!ee||!ue,Ue=!ee||!st,tr=!ee||!st||se,Ft=!ee||!st||se,jn=!ee||!st||We&&!Y;let vt=!0,Jt=!0;if(Y)vt=Fe,Jt=Fe;else if(ke){vt=se||We||g;const Ts=g&&v&&v.type==="text";Jt=vt&&!Ts}const Wo=Math.min(24/P,I-G*3),ic=ee&&g&&v&&r.isShapeOfType(v,"text")&&Wo*P>=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(Ah,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:B,corner:"top_left_rotate",cursor:m?rr("nwse-rotate",n):void 0,isHidden:$e}),d.jsx(Ah,{"data-testid":"selection.rotate.top-right",cx:C+B*3,cy:0,targetSize:B,corner:"top_right_rotate",cursor:m?rr("nesw-rotate",n):void 0,isHidden:$e}),d.jsx(Ah,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:I+B*3,targetSize:B,corner:"bottom_left_rotate",cursor:m?rr("swne-rotate",n):void 0,isHidden:$e}),d.jsx(Ah,{"data-testid":"selection.rotate.bottom-right",cx:C+B*3,cy:I+B*3,targetSize:B,corner:"bottom_right_rotate",cursor:m?rr("senw-rotate",n):void 0,isHidden:$e}),d.jsx(Uae,{"data-testid":"selection.rotate.mobile",cx:T?-B*1.5:C/2,cy:T?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:m?{cursor:rr("ns-resize",n)}:void 0,...i}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Jt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:N(C-(T?0:L)),y:0,height:N(I),width:N(Math.max(1,L*2)),style:m?{cursor:rr("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:m?{cursor:rr("ns-resize",n)}:void 0,...l}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Jt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:N(0-(T?L*2:L)),y:0,height:N(I),width:N(Math.max(1,L*2)),style:m?{cursor:rr("ew-resize",n)}:void 0,...c}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":Ue}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:N(0-(T?L*2:L*1.5)),y:N(0-(D?G*2:G*1.5)),width:N(L*3),height:N(G*3),style:m?{cursor:rr("nwse-resize",n)}:void 0,...u}),d.jsx("rect",{className:le("tl-transparent",{"tl-hidden":tr}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:N(C-(T?0:L*1.5)),y:N(0-(D?G*2:G*1.5)),width:N(L*3),height:N(G*3),style:m?{cursor:rr("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-(T?L:L*1.5)),y:N(I-(D?G:G*1.5)),width:N(L*3),height:N(G*3),style:m?{cursor:rr("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-(T?L*3:L*1.5)),y:N(I-(D?0:G*1.5)),width:N(L*3),height:N(G*3),style:m?{cursor:rr("nesw-resize",n)}:void 0,...f}),ke&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.resize.top-left",className:le("tl-corner-handle",{"tl-hidden":Ue}),"aria-label":"top_left handle",x:N(0-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":tr}),"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)})]}),ic&&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-Wo/2),rx:k/4,width:N(k/2),height:N(Wo)}),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-Wo/2),width:N(k/2),height:N(Wo)})]}),Y&&d.jsx(Nae,{size:k,width:C,height:I,hideAlternateHandles:Fe})]})})}),Ah=function({cx:e,cy:n,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=xo(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})},Bae=Math.sqrt(Math.PI),Uae=function({cx:e,cy:n,size:r,isHidden:o,"data-testid":s}){const i=xo("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/Bae})]})};function Hae(){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(uj,{}):null}function Gx(t,e,n){const{arrowheadStart:r,arrowheadEnd:o}=e.props,s=al(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=Kf(t,e,"start"),h=Kf(t,e,"end"),p=t.getShapePageTransform(e);fE(a,s.start,p,h),fE(i,s.end,p,u);let f=0,m=0,g=0,v=0,S=ll*e.props.scale;const y=u&&h&&u.shape===h.shape,P=u&&h?bb(t,u.shape.id,h.shape.id):"safe";P==="safe"&&u&&h&&!y&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(ll*e.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(ll*e.props.scale))));const b=x.Sub(a,i),C=x.Len(b)?b.uni():x.From(b),I=!x.Equals(C,c);y||(P!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(g=Eo[e.props.size]/2+("size"in u.shape.props?Eo[u.shape.props.size]/2:0),f=(Wf+g)*e.props.scale,S+=g*e.props.scale),P!=="end-contains-start"&&h&&o!=="none"&&!h.isExact&&(v=Eo[e.props.size]/2+("size"in h.shape.props?Eo[h.shape.props.size]/2:0),m=(Wf+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(m*(I?-1:1)));x.DistMin(k,_,S)&&(f!==0&&m!==0?(f*=-1.5,m*=-1.5):f!==0?f*=-1:m!==0&&(m*=-1)),i.add(C.clone().mul(f*(I?-1:1))),a.sub(C.clone().mul(m*(I?-1:1))),I?(u&&h&&a.setTo(x.Add(i,C.clone().mul(-ll*e.props.scale))),l.setTo(x.Med(s.start,s.end))):l.setTo(x.Med(i,a));const M=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:M>0,length:M}}function fE(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?m1:IZ)(i,a,r.outline);let h;if(u!==null&&(h=u.sort((m,g)=>x.Dist2(m,i)-x.Dist2(g,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 Kae(t,e,n){const{arrowheadEnd:r,arrowheadStart:o}=e.props,s=e.props.bend;if(Math.abs(s)>Math.abs(e.props.bend*(Xae*e.props.scale)))return Gx(t,e,n);const i=al(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=Kf(t,e,"start"),p=Kf(t,e,"end"),f=i.start.clone(),m=i.end.clone(),g=u.clone();if(x.Equals(f,m))return{bindings:n,isStraight:!0,start:{handle:f,point:f,arrowhead:e.props.arrowheadStart},end:{handle:m,point:m,arrowhead:e.props.arrowheadEnd},middle:g,isValid:!1,length:0};const v=e.props.bend<0,S=v?ld:KA,y=gE(f,m,g),P=x.Angle(y.center,f),b=x.Angle(y.center,m),C=S(P,b);if(y.length===0||y.size===0||!G_(y.length)||!G_(y.size))return Gx(t,e,n);const I=f.clone(),k=m.clone(),_=g.clone(),M=t.getShapePageTransform(e);let T=0,D=0,A=ll*e.props.scale;if(h&&!h.isExact){const Y=q.applyToPoint(M,I),ee=q.applyToPoint(M,y.center),he=q.applyToPoint(M,k),ue=q.Inverse(h.transform),ke=q.applyToPoint(ue,Y),se=q.applyToPoint(ue,ee),We=q.applyToPoint(ue,he),{isClosed:Fe}=h,st=Fe?vx:pI;let $e,lt=st(se,y.radius,h.outline);if(lt){const Ue=se.angle(ke),tr=se.angle(We),Ft=S(Ue,tr);lt=lt.filter(vt=>S(Ue,se.angle(vt))<=Ft);const jn=Ft*.25;lt.sort(Fe?(vt,Jt)=>Math.abs(S(Ue,se.angle(vt))-jn)<Math.abs(S(Ue,se.angle(Jt))-jn)?-1:1:(vt,Jt)=>S(Ue,se.angle(vt))<S(Ue,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 Ue=Eo[e.props.size]/2+("size"in h.shape.props?Eo[h.shape.props.size]/2:0);T=(Wf+Ue)*e.props.scale,A+=Ue*e.props.scale}}if(p&&!p.isExact){const Y=q.applyToPoint(M,I),ee=q.applyToPoint(M,k),he=q.applyToPoint(M,y.center),ue=q.Inverse(p.transform),ke=q.applyToPoint(ue,Y),se=q.applyToPoint(ue,he),We=q.applyToPoint(ue,ee),Fe=p.isClosed,st=Fe?vx:pI;let $e,lt=st(se,y.radius,p.outline);if(lt){const Ue=se.angle(ke),tr=se.angle(We),Ft=S(Ue,tr),jn=Ft*.75;lt=lt.filter(vt=>S(Ue,se.angle(vt))<=Ft),lt.sort(Fe?(vt,Jt)=>Math.abs(S(Ue,se.angle(vt))-jn)<Math.abs(S(Ue,se.angle(Jt))-jn)?-1:1:(vt,Jt)=>S(Ue,se.angle(vt))<S(Ue,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 Ue=Eo[e.props.size]/2+("size"in p.shape.props?Eo[p.shape.props.size]/2:0);D=(Wf+Ue)*e.props.scale,A+=Ue*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(T!==0&&G.setTo(y.center).add(x.FromAngle(O+B*(T/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,$,A)&&(T!==0&&D!==0?(T*=-1.5,D*=-1.5):T!==0?T*=-2:D!==0&&(D*=-2)),T!==0&&I.setTo(y.center).add(x.FromAngle(O+B*(T/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=bb(t,h.shape.id,p.shape.id);Y==="double-bound"&&L<30?(I.setTo(f),k.setTo(m),_.setTo(g)):Y==="safe"&&(h&&!h.didIntersect&&I.setTo(f),(p&&!p.didIntersect||S(P,O)>S(P,R))&&k.setTo(y.center).add(x.FromAngle(O+B*(Math.min(.9,ll*e.props.scale/L)*(v?1:-1))).mul(y.radius)))}Wae(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),m.setTo(k),g.setTo(_);const U=gE(f,m,g);return{bindings:n,isStraight:!1,start:{point:f,handle:i.start,arrowhead:e.props.arrowheadStart},end:{point:m,handle:i.end,arrowhead:e.props.arrowheadEnd},middle:g,handleArc:y,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function gE(t,e,n){const r=a1(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 Wae(t,e,n,r,o,s,i){const a=x.Angle(t,n),l=x.Angle(t,r);let c=ld(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 Gae=8;function Vae(t){return Math.abs(t.props.bend)<Gae*t.props.scale}function Kf(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 so?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function mE(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 Bn(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 Yae=IV("arrow info",(t,e)=>{const n=Bn(t,e);return Vae(e)?Gx(t,e,n):Kae(t,e,n)});function Io(t,e){const n=typeof e=="string"?e:e.id;return Yae.get(t,n)}function al(t,e,n){var a,l;const r=t.getShapePageTransform(e),o=bb(t,(a=n.start)==null?void 0:a.toId,(l=n.end)==null?void 0:l.toId),s=n.start?mE(t,r,n.start,o==="double-bound"||o==="start-contains-end"):x.From(e.props.start),i=n.end?mE(t,r,n.end,o==="double-bound"||o==="end-contains-start"):x.From(e.props.end);return{start:s,end:i}}function jc(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 hp(t,e,n){const r=t.getBindingsFromShape(e,"arrow").filter(o=>o.props.terminal===n);t.deleteBindings(r)}const ll=10,Wf=10,Xae=10,Eo={s:2,m:3.5,l:5,xl:10};function bb(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 pp extends lp{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const n=this.editor.getShape(e.fromId);n&&yS(this.editor,n)}onAfterChange({bindingAfter:e}){const n=this.editor.getShape(e.fromId);n&&yS(this.editor,n)}onAfterChangeFromShape({shapeAfter:e}){yS(this.editor,e)}onAfterChangeToShape({binding:e}){D$(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const n=this.editor.getShape(e.fromId);n&&Gf({editor:this.editor,arrow:n,terminal:e.props.terminal})}}E(pp,"type","arrow"),E(pp,"props",uA),E(pp,"migrations",dA);function D$(t,e){var v;const n=t.getShape(e);if(!n)return;const r=Bn(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 m;const g=t.getSortedChildIdsForParent(f.parentId).map(S=>t.getShape(S)).filter(S=>S.index>f.index);if(g.length){const S=g.find(y=>y.type!=="arrow");if(u.index>f.index&&(!S||u.index<S.index))return;m=Ru(f.index,g[0].index)}else m=Co(f.index);m!==u.index&&t.updateShapes([{id:e,type:"arrow",index:m}])}function yS(t,e){const n=Bn(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)&&Gf({editor:t,arrow:e,terminal:r,unbind:!0})}D$(t,e.id)}function Gf({editor:t,arrow:e,terminal:n,unbind:r=!1,useHandle:o=!1}){const s=Io(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)),m=pd(s.handleArc.center,x.Add(p,f),s.handleArc.center,s.handleArc.radius);Le((m==null?void 0:m.length)===1);const g=x.Dist(p,m[0])*Math.sign(e.props.bend);ai(g,c.props.bend)||(c.props.bend=g)}t.updateShape(c),r&&hp(t,e,n)}const R$=[pp],pn={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},hn={s:2,m:3.5,l:5,xl:10},Ol={s:18,m:24,l:36,xl:44},fs={s:18,m:22,l:26,xl:32},qae={s:18,m:20,l:24,xl:28},bs={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},Zae=20,Vf=4.25,Er=16;function Qae(t,e){const n=t.w/e.w,r=t.h/e.h;return n<=1&&r<=1?t:n>r?{w:t.w/n,h:t.h/n}:{w:t.w/r,h:t.h/r}}/*!
|
|
348
|
-
* MIT License
|
|
349
|
-
* Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
|
|
350
|
-
* Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
|
|
351
|
-
*/const cl=" ",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(`
|
|
352
|
-
`,n-1)+1;return e.charAt(r)!==" "?n:r+1}static indent(e){var a;const{selectionStart:n,selectionEnd:r,value:o}=e,s=o.slice(n,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const l=o.lastIndexOf(`
|
|
353
|
-
`,n-1)+1,c=e.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${cl}`),h=u.length-c.length;e.setSelectionRange(l,r-1),Sn.insert(e,u),e.setSelectionRange(n+1,r+h)}else Sn.insert(e,cl)}static unindent(e){const{selectionStart:n,selectionEnd:r,value:o}=e,s=o.lastIndexOf(`
|
|
354
|
-
`,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=jh(e)??0,s=jh(e)??0,i=r.slice(o,s),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
|
|
355
|
-
`,o-1)+1,u=r.slice(c,s-1),p=u.replace(/^|\n/g,`$&${cl}`).length-u.length;n&&n.setBaseAndExtent(e,o+1,e,s+p)}else{const c=window.getSelection();e.innerText=r.slice(0,o)+cl+r.slice(o),c==null||c.setBaseAndExtent(e,o+1,e,o+2)}}static unindentCE(e){const n=window.getSelection(),r=e.innerText,o=jh(e)??0,s=jh(e)??0,i=r.lastIndexOf(`
|
|
356
|
-
`,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,`
|
|
357
|
-
`)}static normalizeTextForDom(e){return e.replace(Sn.fixNewLines,`
|
|
358
|
-
`).split(`
|
|
359
|
-
`).map(n=>n||" ").join(`
|
|
360
|
-
`)}};E(Sn,"fixNewLines",/\r?\n|\r/g);let Dl=Sn;function jh(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 Jae=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function L$(t){return Jae.test(t)}function ele(t){return t.replace(/\t/g,cl)}function tle(t){const e=t.split(`
|
|
361
|
-
`);for(;e[0]&&e[0].trim().length===0;)e.shift();let n=1/0;for(const r of e)if(r.trim().length>0){const o=r.length-r.trimStart().length;n=Math.min(n,o)}return e.map(r=>r.slice(n)).join(`
|
|
362
|
-
`)}const $$={"&":"&",""":'"',"'":"'",""":'"',"&":"&","'":"'","–":"–","—":"—","‘":"‘","’":"’","“":"“","”":"”","…":"…"},nle=new RegExp(Object.keys($$).join("|"),"g");function rle(t){return t.replace(nle,e=>$$[e])}function ole(t){return t.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function sle(t){return ole(tle(ele(t)))}function ile(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=_C(await a.arrayBuffer());l=l??Ks.createId(h);const p=await yE(a,l,c,u);if(isFinite(e)){const f={w:p.props.w,h:p.props.h},m=Qae(f,{w:e,h:e});f!==m&&lr.isStaticImageType(a.type)&&(p.props.w=m.w,p.props.h=m.h)}return p.props.src=await t.uploadAsset(p,a),Ks.create(p)}),t.registerExternalAssetHandler("url",async({url:a})=>{var c,u,h,p,f;let l;try{const g=await(await oo(a,{method:"GET",mode:"no-cors"})).text(),v=new DOMParser().parseFromString(g,"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(m){console.error(m),s.addToast({title:i("assets.url.failed"),severity:"error"}),l={image:"",favicon:"",title:"",description:""}}return{id:Ks.createId(Uv(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 m=u.getBoundingClientRect();document.body.removeChild(u),h=m.width,p=m.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");SE(t,[f],c)}),t.registerExternalContentHandler("embed",({point:a,url:l,embed:c})=>{const u=a??(t.inputs.shiftKey?t.inputs.currentPagePoint:t.getViewportPageBounds().center),{width:h,height:p}=c,f=Ke(),m={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([m]).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 m=r.includes(f.type),g=o.includes(f.type),v=_C(await f.arrayBuffer()),S=Ks.createId(v),y=await yE(f,S,m,g);let P;m&&(P=t.createTemporaryAssetPreview(S,f)),h.push(y),p.push({asset:y,file:f,temporaryAssetPreview:P})}Promise.allSettled(p.map(async f=>{try{const m=await t.getAssetForExternalContent({type:"file",file:f.file});if(!m)throw Error("Could not create an asset");t.updateAssets([{...m,id:f.asset.id}])}catch(m){s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(m);return}})),SE(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=sle(l),p=t.getOnlySelectedShape();if(p&&"text"in p.props){t.updateShapes([{id:p.id,type:p.type,props:{text:h}}]);return}let f,m,g,v="middle";const S=h.split(`
|
|
363
|
-
`).length>1,y=L$(h);S&&(v=S?y?"end":"start":"middle");const P=t.textMeasure.measureText(h,{...pn,fontFamily:bs[u.font],fontSize:Ol[u.size],maxWidth:null}),b=Math.min(S?t.getViewportPageBounds().width*.9:920,Math.max(200,t.getViewportPageBounds().width*.9));if(P.w>b){const C=t.textMeasure.measureText(h,{...pn,fontFamily:bs[u.font],fontSize:Ol[u.size],maxWidth:b});f=C.w,m=C.h,g=!1,v=y?"end":"start"}else f=P.w,m=P.h,g=!0;c.y-m/2<t.getViewportPageBounds().minY+40&&(c.y=t.getViewportPageBounds().minY+40+m/2),t.createShapes([{id:Ke(),type:"text",x:c.x-f/2,y:c.y-m/2,props:{text:h,textAlign:v,autoSize:g,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=Ks.createId(Uv(l)),f=ale(t,l,h);let m=t.getAsset(p),g=!1;if(!m){g=!0;try{const v=await t.getAssetForExternalContent({type:"url",url:l});if(!v)throw Error("Could not create an asset");m=v}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}t.run(()=>{g&&t.createAssets([m]),t.updateShapes([{id:f.id,type:f.type,props:{assetId:m.id}}])})})}async function yE(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 SE(t,e,n){if(!e.length)return[];const r=x.From(n),o=[];for(let s=0;s<e.length;s++){const i=e[s];switch(i.type){case"image":{o.push({id:Ke(),type:"image",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w;break}case"video":o.push({id:Ke(),type:"video",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w}}return t.run(()=>{const s=e.filter(i=>!t.getAsset(i.id));s.length&&t.createAssets(s),t.createShapes(o).select(...o.map(i=>i.id)),F$(t,n)}),o.map(s=>s.id)}function F$(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 ale(t,e,n){const r={id:Ke(),type:"bookmark",x:n.x-150,y:n.y-160,opacity:1,props:{assetId:null,url:e}};return t.run(()=>{t.createShapes([r]).select(r.id),F$(t,n)}),t.getShape(r.id)}var MS;let lle=(MS=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(MS,"id","idle"),MS);var AS;let cle=(AS=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=Ke();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(AS,"id","pointing"),AS);class Vx extends ie{constructor(){super(...arguments);E(this,"shapeType","arrow")}static children(){return[lle,cle]}}E(Vx,"id","arrow"),E(Vx,"initial","idle");class Pb 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,"markId",null)}onEnter(n){this.markId=null,this.info=n,this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.startShape()}onPointerMove(){const{inputs:n}=this.editor;if(this.isPen&&!n.isPen&&this.markId){this.editor.bailToMark(this.markId),this.startShape();return}this.isPenOrStylus?x.Dist(n.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=n.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape()}onKeyDown(n){if(n.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()}onKeyUp(n){if(n.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()}onExit(){this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()}canClose(){return this.shapeType!=="highlight"}getIsClosed(n,r,o){if(!this.canClose())return!1;const s=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 m=[...a.props.segments,p];this.currentLineLength<hn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(m));const g={id:a.id,type:this.shapeType,props:{segments:m}};this.canClose()&&(g.props.isClosed=this.getIsClosed(m,a.props.size,a.props.scale)),this.editor.updateShapes([g]);return}}this.pagePointWhereCurrentSegmentChanged=n.clone();const i=Ke();this.editor.createShapes([{id:i,type:this.shapeType,x:n.x,y:n.y,props:{isPen:this.isPenOrStylus,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+s.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(i)}updateDrawingShape(){const{initialShape:n}=this,{inputs:r}=this.editor;if(!n)return;const{id:o,props:{size:s,scale:i}}=n,a=this.editor.getShape(o);if(!a)return;const{segments:l}=a.props,{x:c,y:u,z:h}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),p=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,f={x:c,y:u,z:p};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:m}=this;if(m===null)throw Error("We should have a point where the segment changed");if(x.Dist2(m,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 P=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(v.type==="straight"){this.currentLineLength+=x.Dist(S,P),y={type:"straight",points:[{...S},P]};const C=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=q.applyToPoint(C,S)}else y={type:"straight",points:[P,f]};const b={id:o,type:this.shapeType,props:{segments:[...l,y]}};this.canClose()&&(b.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([b])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:m}=this;if(m===null)throw Error("We should have a point where the segment changed");if(x.Dist2(m,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 P={type:"free",points:[...x.PointsBetween(y,f,6).map(I=>({x:rs(I.x),y:rs(I.y),z:rs(I.z)}))]},b=[...v,P];this.currentLineLength<hn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(b));const C={id:o,type:this.shapeType,props:{segments:b}};this.canClose()&&(C.props.isClosed=this.getIsClosed(b,s,i)),this.editor.updateShapes([C])}break}case"straight":{const m=l.slice(),g=m[m.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 P,b=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(b=!S,this.didJustShiftClickToExtendPreviousShapeLine=!1):b=!S;let C=this.editor.getPointInShapeSpace(a,y).toFixed().toJson(),I=!1,k;if((this.editor.user.getIsSnapMode()?!S:S)&&m.length>2){let T,D=8/this.editor.getZoomLevel();for(let A=0,O=l.length-2;A<O;A++){const R=l[A];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)){T=G.toFixed().toJson(),D=x.Dist(G,C),k=R;break}}T&&(I=!0,C=T)}if(I&&k){const T=this.editor.getShapePageTransform(a),D=k.points[0],A=Ht(k.points);if(!A)throw Error("Expected a last point!");const O=q.applyToPoint(T,D),R=q.applyToPoint(T,A),B=q.applyToPoint(T,C);this.editor.snaps.setIndicators([{id:ze(),type:"points",points:[O,B,R]}])}else{if(this.editor.snaps.clearIndicators(),b){const T=x.Angle(v,y),A=Mf(T,24)-T;P=x.RotWith(y,v,A)}else P=y;C=this.editor.getPointInShapeSpace(a,P).toFixed().toJson()}this.currentLineLength+=x.Dist(g.points[0],C),m[m.length-1]={...g,type:"straight",points:[g.points[0],C]};const M={id:o,type:this.shapeType,props:{segments:m}};this.canClose()&&(M.props.isClosed=this.getIsClosed(l,s,i)),this.editor.updateShapes([M]);break}case"free":{const m=l.slice(),g=m[m.length-1],v=[...g.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);m[m.length-1]={...g,points:v},this.currentLineLength<hn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(m));const S={id:o,type:this.shapeType,props:{segments:m}};if(this.canClose()&&(S.props.isClosed=this.getIsClosed(m,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=Ke(),P=this.editor.getShape(o).props;this.editor.createShapes([{id:y,type:this.shapeType,x:rs(r.currentPagePoint.x),y:rs(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:P.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(){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(Pb,"id","drawing");var jS;let N$=(jS=class extends ie{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E(jS,"id","idle"),jS);class fp extends ie{constructor(){super(...arguments);E(this,"shapeType","draw")}static children(){return[N$,Pb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}E(fp,"id","draw"),E(fp,"initial","idle"),E(fp,"isLockable",!1);class Yx extends Tx{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)&&ule(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(Yx,"id","frame"),E(Yx,"initial","idle");function ule(t,e,n){return e.includes(t.id)?!1:t.parentId===n.parentId}var OS;let dle=(OS=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(OS,"id","idle"),OS);var DS;let hle=(DS=class extends ie{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=Ke(),o=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`);this.editor.createShapes([{id:r,type:"geo",x:n.x,y:n.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(Zr),scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]).select(r).setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,n=Ke();this.editor.markHistoryStoppingPoint(`creating_geo:${n}`);const r=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,o=this.editor.getStyleForNextShape(Zr),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(Zr),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(Zr),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},E(DS,"id","pointing"),DS);class Xx extends ie{constructor(){super(...arguments);E(this,"shapeType","geo")}static children(){return[dle,hle]}}E(Xx,"id","geo"),E(Xx,"initial","idle");class gp extends ie{constructor(){super(...arguments);E(this,"shapeType","highlight")}static children(){return[N$,Pb]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}E(gp,"id","highlight"),E(gp,"initial","idle"),E(gp,"isLockable",!1);var RS;let ple=(RS=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(RS,"id","idle"),RS);const vE=2;var LS;let fle=(LS=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,vE)||x.DistMin(h,l,vE))p[l.id]={id:l.id,index:l.index,x:h.x,y:h.y};else{const f=Co(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=Ke();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(LS,"id","pointing"),LS);class qx extends ie{constructor(){super(...arguments);E(this,"shapeType","line")}static children(){return[ple,fle]}}E(qx,"id","line"),E(qx,"initial","idle");var $S;let gle=($S=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},E($S,"id","idle"),$S);const mle=0,He=200,ym=new x(He/2,He/2),z$=10,yle=t=>[[["a1"],new x(He*.5,He*-.5-t.options.adjacentShapeMargin)],[["a2"],new x(He*1.5+t.options.adjacentShapeMargin,He*.5)],[["a3"],new x(He*.5,He*1.5+t.options.adjacentShapeMargin)],[["a4"],new x(He*-.5-t.options.adjacentShapeMargin,He*.5)]];function Sle(t,e){if(e===1)return yle(t);const n=He*e,r=t.options.adjacentShapeMargin*e;return[[["a1"],new x(n*.5,n*-.5-r)],[["a2"],new x(n*1.5+r,n*.5)],[["a3"],new x(n*.5,n*1.5+r)],[["a4"],new x(n*-.5-r,n*.5)]]}function B$(t,e,n,r,o,s){return Object.fromEntries(Sle(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 U$(t,e,n,r){const o=new Set(t.getSelectedShapeIds()),s=(He+t.options.adjacentShapeMargin+r)**2,i=new Map,a=[];for(const u of t.getCurrentPageShapes()){if(!t.isShapeOfType(u,"note")||n!==u.props.scale||o.has(u.id))continue;const h=t.getShapePageTransform(u.id);e===h.rotation()&&(i.set(u,t.getShapePageBounds(u).center),a.push(...Object.values(B$(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 H$(t,e,n,r,o=!1){let s;const i=t.getCurrentPageShapesSorted(),a=(He+t.options.adjacentShapeMargin**2)**e.props.scale;for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="note"&&c.id!==e.id){const u=t.getShapePageBounds(c);if(u&&x.Dist2(u.center,n)<a&&t.isPointInShape(c,n)){s=c;break}}}if(t.complete(),!s||o){t.markHistoryStoppingPoint("creating note shape");const l=Ke();t.createShape({id:l,type:"note",x:n.x,y:n.y,rotation:r,opacity:e.opacity,props:{...e.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const c=t.getShape(l);if(!c)return;const u=t.getPointInParentSpace(c,x.Sub(n,x.Rot(ym.clone().mul(c.props.scale),r)));t.updateShape({id:l,type:"note",x:u.x,y:u.y}),s=t.getShape(l)}return j3(t),s}var FS;let vle=(FS=class extends ie{constructor(){super(...arguments);E(this,"dragged",!1);E(this,"info",{});E(this,"markId","");E(this,"shape",{})}onEnter(){const{editor:n}=this,r=Ke();this.markId=n.markHistoryStoppingPoint(`creating_note:${r}`);const o=this.editor.inputs.originPagePoint.clone(),s=xle(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=wle(this.editor,r,o)}onPointerMove(n){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.translating",{...n,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,creatingMarkId:this.markId,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}onPointerUp(){this.complete()}onInterrupt(){this.cancel()}onComplete(){this.complete()}onCancel(){this.cancel()}complete(){this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):(this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape",{...this.info,target:"shape",shape:this.shape}))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}},E(FS,"id","pointing"),FS);function xle(t,e,n){let r=z$/t.getZoomLevel(),o;for(const s of U$(t,0,n,0)){const i=x.Sub(e,s),a=i.len();a<r&&(r=a,o=i)}return o}function wle(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 Zx extends ie{constructor(){super(...arguments);E(this,"shapeType","note")}static children(){return[gle,vle]}}E(Zx,"id","note"),E(Zx,"initial","idle");function ble(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 as=mT(ble,32);var NS;let Ple=(NS=class extends ie{onPointerMove(e){switch(e.target){case"shape":case"canvas":as(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){as.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(NS,"id","idle"),NS);var zS;let Cle=(zS=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=Ke();this.markId=r.markHistoryStoppingPoint(`creating_text:${u}`);const h=this.createTextShape(u,s,!1,a);if(!h){this.cancel();return}this.shape=r.getShape(h),r.select(u),r.setCurrentTool("select.resizing",{...n,target:"selection",handle:"right",isCreating:!0,creatingMarkId:this.markId,creationCursorOffset:{x:a,y:1},onInteractionEnd:"text",onCreate:()=>{r.setEditingShape(h.id)}})}}onPointerUp(){this.complete()}onComplete(){this.cancel()}onCancel(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.editor.markHistoryStoppingPoint("creating text shape");const n=Ke(),{originPagePoint:r}=this.editor.inputs;this.createTextShape(n,r,!0,20)&&(this.editor.select(n),this.editor.setEditingShape(n))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(n,r,o,s){this.editor.createShape({id:n,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:o,w:s,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const i=this.editor.getShape(n);if(!i){this.cancel();return}const a=this.editor.getShapePageBounds(i),l=new x;if(o)switch(i.props.textAlign){case"start":{l.x=0;break}case"middle":{l.x=-a.width/2;break}case"end":{l.x=-a.width;break}}else l.x=0;if(l.y=-a.height/2,$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(zS,"id","pointing"),zS);class Qx extends ie{constructor(){super(...arguments);E(this,"shapeType","text")}static children(){return[Ple,Cle]}}E(Qx,"id","text"),E(Qx,"initial","idle");const _le=[Qx,fp,Xx,Zx,qx,Yx,Vx,gp];function Nr(){return Is({isDarkMode:Sd()})}function Sm(t){return{key:`${Do.id}:${t}`,async getElement(){const e=Ile(t);if(!e)return null;const n=e.$$_url,r=e.$$_fontface;if(!n||!r)return null;const o=await(await oo(n)).blob(),s=await cs.blobToDataUrl(o),i=r.replace(n,s);return d.jsx("style",{children:i})}}}function Ile(t){const e=iA[t];for(const n of document.fonts)if(e.includes(n.family))return n;return null}function Cb(t){return{key:`${Do.id}:${t}`,async getElement(){return t!=="pattern"?null:d.jsx(Ele,{})}}}function Ele(){const t=Ib(),e=ql(),n=Nr(),r=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:e,children:[d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),d.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[d.jsx("line",{x1:r*1,y1:r*3,x2:r*3,y2:r*1}),d.jsx("line",{x1:r*5,y1:r*7,x2:r*7,y2:r*5}),d.jsx("line",{x1:r*9,y1:r*11,x2:r*11,y2:r*9})]})]}),d.jsx("pattern",{id:t(1,n.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:n.solid,mask:`url(#${e})`})})]})}function _b(){return{key:`${Do.id}:pattern`,component:Ale}}const Vc=8,xE=(t,e,n)=>new Promise((r,o)=>{const s=Vc*e*t,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?Pf.darkMode.solid:Pf.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)})}),wE=(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 SS=null;function kle(){return SS||(SS={white:wE([1,1],t=>{t.fillStyle="#f8f9fa",t.fillRect(0,0,1,1)}),black:wE([1,1],t=>{t.fillStyle="#212529",t.fillRect(0,0,1,1)})}),SS}function K$(t){return Math.ceil(Math.log2(Math.max(1,t)))}function Ib(){const t=to("hash_pattern");return w.useCallback((e,n)=>{const r=K$(e);return r1(t,`${n}_${r}`)},[t])}function W$(t){const e=[],r=K$(t);for(let o=0;o<=r;o++)e.push(Math.pow(2,o));return e}function Tle(t){const e=kle();return W$(t).flatMap(n=>[{zoom:n,url:e.white,theme:"light"},{zoom:n,url:e.black,theme:"dark"}])}function Mle(){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(()=>Tle(n)),a=Ib();return w.useEffect(()=>{const c=Promise.all(W$(n).flatMap(h=>[xE(e,h,!1).then(p=>({zoom:h,theme:"light",url:URL.createObjectURL(p)})),xE(e,h,!0).then(p=>({zoom:h,theme:"dark",url:URL.createObjectURL(p)}))]));let u=!1;return c.then(h=>{u||(i(h),o(!0))}),()=>{u=!0,o(!1),c.then(h=>{for(const{url:p}of h)URL.revokeObjectURL(p)})}},[e,n]),{defs:d.jsx(d.Fragment,{children:s.map(c=>{const u=a(c.zoom,c.theme);return d.jsx("pattern",{id:u,width:Vc,height:Vc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:c.url,width:Vc,height:Vc})},u)})}),isReady:r}}function Ale(){const t=z(),e=w.useRef(null),{defs:n,isReady:r}=Mle();return w.useEffect(()=>{if(r&&Ge.isSafari){const o=G$(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 G$(t){return t.classList.contains("tl-html-layer")?t:t.parentElement?G$(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(jle,{theme:e,color:r,fill:o,d:n,scale:s})}});function jle({d:t,color:e,theme:n}){const r=z(),o=fd(),s=H("zoomLevel",()=>r.getZoomLevel(),[r]),i=Ib(),a=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:n[e].pattern,d:t}),d.jsx("path",{fill:o?`url(#${i(1,n.id)})`:a?n[e].semi:`url(#${i(s,n.id)})`,d:t})]})}function Ole(t){return t.replace(/\s/g," ")}function Jx(t,e,n){const{padding:r=0}=n;if(e.length===0)return null;const o=Z.From(e[0].box);for(const{box:c}of e)o.union(c);const s=r+(n.offsetX??0),i=(n.offsetY??0)+n.fontSize/2+(n.verticalTextAlign==="start"?r:n.verticalTextAlign==="end"?n.height-r-o.height:(Math.ceil(n.height)-o.height)/2);let a=null;const l=[];for(const{text:c,box:u}of e)a!==null&&u.y>a&&l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
|
|
364
|
-
`},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,unicodeBidi:"plaintext",children:Ole(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 Dle(t,e,n,r){if((t==="start-legacy"||t==="end-legacy")&&n.length!==0){const o=Z.From(n[0].box);for(const{box:s}of n)o.union(s);if(t==="start-legacy")return(r-2*e-o.width)/2;if(t==="end-legacy")return-(r-2*e-o.width)/2}}function Rle(t){return t==="start-legacy"||t==="middle-legacy"||t==="end-legacy"}function vm({fontSize:t,font:e,align:n,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:l=!0}){const c=z(),u=Nr(),h={fontSize:t,fontFamily:iA[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=Dle(n,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const m=Jx(c,p,h);let g=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,g=Jx(c,p,h)),d.jsxs(d.Fragment,{children:[g,m]})}const Lle=w.forwardRef(function({isEditing:e,text:n,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){return d.jsx("textarea",{ref:c,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!e,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:n,onFocus:r,onChange:o,onKeyDown:s,onBlur:i,onTouchEnd:_t,onContextMenu:e?_t:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:xe})});function $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(h){var p;h.shapeId===t&&((p=o.current)==null||p.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,t,s]),w.useEffect(()=>{var u,h,p,f;s&&(document.activeElement!==o.current&&((u=o.current)==null||u.focus()),r.getInstanceState().isCoarsePointer&&((h=o.current)==null||h.select()),Ge.isSafari&&((p=o.current)==null||p.blur(),(f=o.current)==null||f.focus()))},[r,s]);const a=w.useCallback(u=>{if(r.getEditingShapeId()===t)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&r.complete();break}}},[r,t]),l=w.useCallback(u=>{if(r.getEditingShapeId()!==t)return;let h=Dl.normalizeText(u.currentTarget.value);const p=h.replace(/\t/g,cl);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({...Wn(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(t)}),_t(u)},[r,t]);return{rInput:o,handleFocus:Ou,handleBlur:Ou,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:_t,isEmpty:n.trim().length===0,isEditing:s,isEditingAnything:i}}const xm=Te.memo(function({shapeId:e,type:n,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:f,classNamePrefix:m,style:g,textWidth:v,textHeight:S}){const{rInput:y,isEmpty:P,isEditing:b,isEditingAnything:C,...I}=$le(e,n,r),[k,_]=w.useState(r);w.useEffect(()=>{b||_(r)},[b,r]);const M=Dl.normalizeTextForDom(r),T=M.length>0,D=Rle(l);if(!b&&!T)return null;const A=m||"tl-text";return d.jsx("div",{className:`${A}-label tl-text-wrapper`,"data-font":s,"data-align":l,"data-hastext":!P,"data-isediting":b,"data-iseditinganything":C,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||D?"center":l,alignItems:c==="middle"?"center":c,padding:p,...g},children:d.jsxs("div",{className:`${A}-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:`${A} tl-text tl-text-content`,dir:"auto",children:M.split(`
|
|
365
|
-
`).map((O,R)=>d.jsx("div",{dir:"auto",children:O},R))}),(C||h)&&d.jsx(Lle,{ref:y,text:r,isEditing:b,...I,handleKeyDown:f??I.handleKeyDown},k)]})})}),Fle=new Oo;function Nle(t){return Fle.get(t,()=>t.store.createComputedCache("arrowLabelSize",e=>{const n=Io(t,e);let r=0,o=0;const s=n.isStraight?new is({start:x.From(n.start.point),end:x.From(n.end.point)}):new sl({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=e0(e),{w:l,h:c}=t.textMeasure.measureText(e.props.text,{...pn,fontFamily:bs[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:bs[e.props.font],fontSize:a,maxWidth:r});r=h,o=p}}return new x(r,o).addScalar(Vf*2*e.props.scale)}))}function Eb(t,e){return e.props.text.trim()===""?new x(0,0).addScalar(Vf*2*e.props.scale):Nle(t).get(e.id)??new x(0,0)}function V$(t){const e=hn[t.props.size];return(Zae+(e-hn.s)*2+(e===hn.xl?20:0))*t.props.scale}function zle(t,e,n){const r=Eb(t,e),o=V$(e),s=x.Nudge(n.start.point,n.end.point,o),i=x.Nudge(n.end.point,n.start.point,o),a=m1(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 Ble(t,e,n){const r=Eb(t,e),o=V$(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=la(n.bodyArc.center,n.bodyArc.radius,a),u=la(n.bodyArc.center,n.bodyArc.radius,l),h=[],p=PE(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=PE(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 M1({x:k.x-3,y:k.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const m=(p&&CE(n.start.point,p))??n.middle,g=(f&&CE(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,m),P=x.Angle(n.bodyArc.center,g);if(Ws(v,y,s)>Ws(v,P,s))return{start:.5,end:.5,dbg:h};const b=Ws(v,S,s),C=Ws(v,y,s)/b,I=Ws(v,P,s)/b;return{start:C,end:I,dbg:h}}function mp(t,e){let n;const r=[],o=Io(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=zle(t,e,o),l=bE(t,e,a,s);n=x.Lrp(o.start.point,o.end.point,l)}else{const a=Ble(t,e,o);a.dbg&&r.push(...a.dbg);const l=bE(t,e,a,s),c=Ule(x.Angle(o.bodyArc.center,o.start.point),x.Angle(o.bodyArc.center,o.end.point),Math.sign(e.props.bend),l);n=la(o.bodyArc.center,o.bodyArc.radius,c)}const i=Eb(t,e);return{box:Z.FromCenter(n,i),debugGeom:r}}function bE(t,e,n,r){const{hasEndArrowhead:o,hasEndBinding:s,hasStartBinding:i,hasStartArrowhead:a}=r,l=Z$(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 PE(t,e,n,r,o,s){const i=vx(t,e,s),a=Ws(n,r,o);return i==null?void 0:i.filter(l=>{const c=Ws(n,x.Angle(t,l),o);return c>=0&&c<=a})}function CE(t,e){let n=null,r=-1/0;for(const o of e){const s=x.Dist2(t,o);s>r&&(n=o,r=s)}return n}function Ule(t,e,n,r){const o=Ws(t,e,n);return t+o*r*n*-1}function e0(t){return qae[t.props.size]*t.props.scale}function Hle(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=EZ(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 Kle({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 Wle({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 Gle({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 Vle({point:t,int:e}){const n=x.Lrp(t,e,.45),r=x.Dist(n,t);return`M ${n.x-r},${n.y}
|
|
366
|
-
a ${r},${r} 0 1,0 ${r*2},0
|
|
367
|
-
a ${r},${r} 0 1,0 -${r*2},0 `}function Yle({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 Xle({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 qle({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=Hle(t,e,n);if(o){switch(r){case"bar":return qle(o);case"square":return Xle(o);case"diamond":return Yle(o);case"dot":return Vle(o);case"inverted":return Gle(o);case"arrow":return Kle(o);case"triangle":return Wle(o)}return""}}function Zle(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 Y$(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 X$(t,e){return`M${t.x},${t.y}L${e.x},${e.y}`}function Qle(t){return X$(t.start.handle,t.end.handle)}function q$(t){return X$(t.start.point,t.end.point)}class yp extends no{constructor(){super(...arguments);E(this,"_resizeInitialBindings",new Oo)}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=Bn(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=Io(this.editor,n),o=[],s=r.isStraight?new is({start:x.From(r.start.point),end:x.From(r.end.point)}):new sl({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=mp(this.editor,n);o.push(...a.debugGeom),i=new vs({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new so({children:[...i?[s,i]:[s],...o]})}getHandles(n){const r=Io(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=Bn(this.editor,n);if(s==="middle"){const{start:I,end:k}=al(this.editor,n,i),_=x.Sub(k,I),M=x.Per(_),T=x.Med(k,I),D=x.Sub(T,M),A=x.Add(T,M),O=x.NearestPointOnLineSegment(D,A,r,!1);let R=x.Dist(O,T);return x.Clockwise(O,k,T)&&(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 hp(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 hp(this.editor,n,s),a.props[s]={x:r.x,y:r.y},a;const f=this.editor.getShapeGeometry(p),m=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 P={x:(S.x-m.minX)/m.width,y:(S.y-m.minY)/m.height};y&&x.Dist(S,m.center)<Math.max(4,Math.min(Math.min(m.width,m.height)*.15,16))/this.editor.getZoomLevel()&&(P.x=.5,P.y=.5);const b={terminal:s,normalizedAnchor:P,isPrecise:y,isExact:this.editor.inputs.altKey};jc(this.editor,n,p.id,b),this.editor.setHintingShapes([p.id]);const C=Bn(this.editor,n);return C.start&&C.end&&C.start.toId===C.end.toId&&x.Equals(C.start.props.normalizedAnchor,C.end.props.normalizedAnchor)&&jc(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=Bn(this.editor,n),o=al(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)))){IE.set(n,{pagePosition:s.applyToPoint(n),terminalBindings:nd(o,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:s.applyToPoint(l)}:null})}),r.start&&(Gf({editor:this.editor,arrow:n,terminal:"start",useHandle:!0}),n=this.editor.getShape(n.id)),r.end&&Gf({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=IE.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};jc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else hp(this.editor,r,a.binding.props.terminal)}}onResize(n,r){const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(n,()=>Bn(this.editor,n)),a=al(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,m=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),m&&(m.x=1-m.x)):o>=0&&s<0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.y=1-f.y),m&&(m.y=1-m.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),m&&(m.x=1-m.x,m.y=1-m.y)),i.start&&f&&jc(this.editor,n,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&m&&jc(this.editor,n,i.end.toId,{...i.end.props,normalizedAnchor:m.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=Nr(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),i=Io(this.editor,n);if(!(i!=null&&i.isValid))return null;const a=mp(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(fi,{style:{minWidth:50,minHeight:50},children:d.jsx(_E,{shape:n,shouldDisplayHandles:s&&(o==null?void 0:o.id)===n.id})}),u&&d.jsx(xm,{shapeId:n.id,classNamePrefix:"tl-arrow",type:"arrow",font:n.props.font,fontSize:e0(n),lineHeight:pn.lineHeight,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:r[n.props.labelColor].solid,textWidth:a.box.w-Vf*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=Vg(n.id),o=to(n.id+"_clip"),s=Io(this.editor,n);if(!s)return null;const{start:i,end:a}=al(this.editor,n,s==null?void 0:s.bindings),l=this.editor.getShapeGeometry(n),c=l.bounds,u=n.props.text.trim()?l.children[1]:null;if(x.Equals(i,a))return null;const h=hn[n.props.size]*n.props.scale,p=s.start.arrowhead&&Yf(s,"start",h),f=s.end.arrowhead&&Yf(s,"end",h),m=s.isStraight?q$(s):Y$(s),g=p&&s.start.arrowhead!=="arrow"||f&&s.end.arrowhead!=="arrow"||!!u;if(r&&u)return d.jsx("rect",{x:N(u.x),y:N(u.y),width:u.w,height:u.h,rx:3.5*n.props.scale,ry:3.5*n.props.scale});const v=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),S=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow");return d.jsxs("g",{children:[g&&d.jsx("defs",{children:d.jsx(Q$,{hasText:n.props.text.trim().length>0,bounds:c,labelBounds:u?u.getBounds():new Z(0,0,0,0),as:v&&p?p:"",ae:S&&f?f:""})}),d.jsxs("g",{style:{clipPath:g?`url(#${o})`:void 0,WebkitClipPath:g?`url(#${o})`:void 0},children:[g&&d.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),d.jsx("path",{d:m})]}),p&&d.jsx("path",{d:p}),f&&d.jsx("path",{d:f}),u&&d.jsx("rect",{x:N(u.x),y:N(u.y),width:u.w,height:u.h,rx:3.5,ry:3.5})]})}onEditEnd(n){const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])}toSvg(n,r){r.addExportDef(Cb(n.props.fill)),n.props.text&&r.addExportDef(Sm(n.props.font));const o=Is(r),s=1/n.props.scale;return d.jsxs("g",{transform:`scale(${s})`,children:[d.jsx(_E,{shape:n,shouldDisplayHandles:!1}),d.jsx(vm,{fontSize:e0(n),font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:o[n.props.labelColor].solid,bounds:mp(this.editor,n).box.clone().expandBy(-Vf*n.props.scale),padding:0})]})}getCanvasSvgDefs(){return[_b(),{key:"arrow:dot",component:Jle},{key:"arrow:cross",component:ece}]}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(yp,"type","arrow"),E(yp,"props",lA),E(yp,"migrations",cA);function Z$(t,e){const n=Io(t,e);return n.isStraight?x.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const _E=$t(function({shape:e,shouldDisplayHandles:n}){const r=z(),o=Nr(),s=Io(r,e),i=Z.ZeroFix(r.getShapeGeometry(e).bounds),a=Bn(r,e),l=H("force solid",()=>r.getZoomLevel()<.2,[r]),c=to(e.id+"_clip"),u=to("arrowhead-dot"),h=to("arrowhead-cross");if(!(s!=null&&s.isValid))return null;const p=hn[e.props.size]*e.props.scale,f=s.start.arrowhead&&Yf(s,"start",p),m=s.end.arrowhead&&Yf(s,"end",p),g=s.isStraight?q$(s):Y$(s);let v=null;if(n){const I=2/r.getZoomLevel(),{strokeDasharray:k,strokeDashoffset:_}=Xr(Z$(r,e),I,{end:"skip",start:"skip",lengthRatio:2.5});v=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?Qle(s):Zle(s),strokeDasharray:k,strokeDashoffset:_,strokeWidth:I,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?`url(#${h})`:`url(#${u})`:"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?`url(#${h})`:`url(#${u})`:"",opacity:.16}):null}const{strokeDasharray:S,strokeDashoffset:y}=Xr(s.isStraight?s.length:Math.abs(s.bodyArc.length),p,{style:e.props.dash,forceSolid:l}),P=mp(r,e),b=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),C=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:c,children:d.jsx(Q$,{hasText:e.props.text.trim().length>0,bounds:i,labelBounds:P.box,as:b&&f?f:"",ae:C&&m?m:""})})}),d.jsxs("g",{fill:"none",stroke:o[e.props.color].solid,strokeWidth:p,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[v,d.jsxs("g",{style:{clipPath:`url(#${c})`,WebkitClipPath:`url(#${c})`},children:[d.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),d.jsx("path",{d:g,strokeDasharray:S,strokeDashoffset:y})]}),f&&b&&e.props.fill!=="none"&&d.jsx(on,{theme:o,d:f,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),m&&C&&e.props.fill!=="none"&&d.jsx(on,{theme:o,d:m,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),f&&d.jsx("path",{d:f}),m&&d.jsx("path",{d:m})]})]})});function Q$({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 IE=new WeakMap;function Jle(){const t=to("arrowhead-dot");return d.jsx("marker",{id:t,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:d.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function ece(){const t=to("arrowhead-cross");return d.jsxs("marker",{id:t,className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[d.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),d.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const EE="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 Rl({url:t}){const e=z(),n=H("zoomLevel",()=>e.getZoomLevel()<.32,[e]);return d.jsx("a",{className:le("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n}),href:t,target:"_blank",rel:"noopener noreferrer",onPointerDown:_t,onPointerUp:_t,title:t,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${EE}") center 100% / 100% no-repeat`,WebkitMask:`url("${EE}") center 100% / 100% no-repeat`}})})}const kE="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",tce=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function Xf(t){return tce.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 nce=300,J$=320,rce=46,oce=101;class Sp extends nc{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:nce,h:J$,assetId:null}}component(e){return d.jsx(sce,{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 TE(this.editor,e)}onBeforeUpdate(e,n){if(e.props.url!==n.props.url)if(gr.isValid(n.props.url))ace(this.editor,n);else return{...n,props:{...n.props,url:e.props.url}};if(e.props.assetId!==n.props.assetId)return TE(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(Sp,"type","bookmark"),E(Sp,"props",gA),E(Sp,"migrations",mA);function sce({shape:t,util:e}){const n=t.props.assetId?e.editor.getAsset(t.props.assetId):null,r=!!fd()&&Ge.isSafari,o=e.editor.getShapePageTransform(t).rotation(),s=ice(t),[i,a]=w.useState(!0),l=()=>a(!1);return d.jsx(ci,{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(Rl,{url:t.props.url})]}),d.jsxs("div",{className:"tl-bookmark__copy_container",children:[n!=null&&n.props.title?d.jsx("h2",{className:"tl-bookmark__heading",children:rle(n.props.title)}):null,n!=null&&n.props.description&&(n!=null&&n.props.image)?d.jsx("p",{className:"tl-bookmark__description",children:n.props.description}):null,d.jsxs("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:_t,onPointerUp:_t,onClick:_t,children:[i&&(n!=null&&n.props.favicon)?d.jsx("img",{className:"tl-bookmark__favicon",src:n==null?void 0:n.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",onError:l,alt:`favicon of ${s}`}):d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${kE}") center 100% / 100% no-repeat`,WebkitMask:`url("${kE}") center 100% / 100% no-repeat`}}),d.jsx("span",{children:s})]})]})]})})}function TE(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):null;let r=J$;return n&&(n.props.image||(n.props.title?r=oce:r=rce)),{...e,props:{...e.props,h:r}}}const ice=t=>{try{return new URL(t.props.url).hostname.replace(/^www\./,"")}catch{return t.props.url}};function ace(t,e){const{url:n}=e.props,r=Ks.createId(Uv(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}}]),lce(t,e))}const lce=gg(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 ga(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+=zn(r,o);return e?`M${zn(t[0].point,t[1].point)}Q${je(t[1].point)}${zn(t[1].point,t[2].point)}T${s}${zn(t[n-1].point,t[0].point)}${zn(t[0].point,t[1].point)}Z`:`M${je(t[0].point)}Q${je(t[1].point)}${zn(t[1].point,t[2].point)}${t.length>3?"T":""}${s}L${je(t[n-1].point)}`}function cce(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=Fo(t,e);mm(i,e);const a=uce(i);let l="";for(const c of a)l+=hce(c,e);return l}function uce(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(vS(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(vS(n)),n=[a];continue}}return n.push(t[t.length-1]),e.push(vS(n)),e}function vS(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 dce(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 hce(t,e={}){if(t.length===0)return"";if(t.length===1)return dce(t[0].point.x,t[0].point.y,t[0].radius);const{left:n,right:r}=O$(t,e);r.reverse();let o=`M${je(n[0])}T`;for(let s=1;s<n.length;s++)o+=zn(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+=zn(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 e5=(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}})}]},pce=t=>t*.65+VY(t*De/2)*.35,fce=t=>({size:t,thinning:.5,streamline:Ml(t,[9,16],[.64,.74],!0),smoothing:.62,easing:Dt.easeOutSine,simulatePressure:!0}),gce=t=>({size:1+t*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:pce}),ME=t=>({size:t,thinning:0,streamline:Ml(t,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:Dt.linear}),mce=t=>({size:t,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Dt.linear});function kb({strokeWidth:t,showAsComplete:e}){return{size:1+t,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:Dt.easeOutSine,last:e}}function t0(t,e,n,r){const o=t.isComplete||n;return r?t.isPen?{...mce(e),last:o}:{...ME(e),last:o}:t.dash==="draw"?t.isPen?{...gce(e),last:o}:{...fce(e),last:o}:{...ME(e),last:o}}function Ll(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 yce(t,e,n){return{draw:"none",solid:"none",dotted:`${n} ${e*2}`,dashed:`${e*2} ${e*2}`}[t.props.dash]}class vp extends no{hideResizeHandles(e){return xS(e)}hideRotateHandle(e){return xS(e)}hideSelectionBoundsFg(e){return xS(e)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(e){const n=Ll(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 M1({x:-r,y:-r,radius:r,isFilled:!0})}const o=Fo(n,t0(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 Jl({points:o})}component(e){return d.jsx(fi,{children:d.jsx(AE,{shape:e})})}indicator(e){var u;const n=Ll(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+=lo(e.id)()*(r/6));const i=e.props.isComplete||((u=Ht(e.props.segments))==null?void 0:u.type)==="straight",a=t0(e.props,r,i,!0),l=Fo(n,a),c=l.length>1?ga(l,e.props.isClosed):t5(n[0],r);return d.jsx("path",{d:c})}toSvg(e,n){n.addExportDef(Cb(e.props.fill));const r=1/e.props.scale;return d.jsx("g",{transform:`scale(${r})`,children:d.jsx(AE,{shape:e,zoomOverride:1})})}getCanvasSvgDefs(){return[_b()]}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:rs(r*a),y:rs(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:e5(e.props.segments,n.props.segments,r),scale:Ie(e.props.scale,n.props.scale,r)}}}E(vp,"type","draw"),E(vp,"props",SA),E(vp,"migrations",vA);function t5(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 xS(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function AE({shape:t,zoomOverride:e}){var f;const n=Nr(),r=z(),o=Ll(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 m=e??r.getZoomLevel();return m<.5&&m<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+=lo(t.id)()*(i/6));const c=t0(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:ga(Fo(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:cce(o,c),strokeLinecap:"round",fill:n[t.props.color].solid})]});const u=Fo(o,c),h=u.length<2,p=h?t5(o[0],0):ga(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":yce(t,i,l),strokeDashoffset:"0"})]})}function Sce(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function vce(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(n5(o.hostnames,r)){const s=o.fromEmbedUrl(e);if(s)return{definition:o,url:s,embedUrl:e}}}const xce=t=>t.split("*").map(e=>Sce(e)).join(".+"),n5=(t,e)=>!!t.find(n=>{const r=new RegExp(xce(n));return e.match(r)});function wce(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const o of t)if(n5(o.hostnames,r)){const s=o.toEmbedUrl(e);if(s)return{definition:o,embedUrl:s,url:e}}}function bce(t,e){try{return wce(t,e)??vce(t,e)}catch{return}}const Pce=t=>Object.entries(t).filter(([e,n])=>n).map(([e])=>e).join(" ");class xp extends nc{constructor(){super(...arguments);E(this,"embedDefinitions",W1)}setEmbedDefinitions(n){this.embedDefinitions=n}getEmbedDefinitions(){return this.embedDefinitions}getEmbedDefinition(n){return bce(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 Gg(n,r,{minWidth:i,minHeight:a})}component(n){const r=fd(),{w:o,h:s,url:i}=n.props,a=Vg(n.id),l=this.getEmbedDefinition(i),c=H("is hovering",()=>{const{editingShapeId:m,hoveredShapeId:g}=this.editor.getCurrentPageState();if(m&&g!==m){const v=this.editor.getShape(m);if(v&&this.editor.isShapeOfType(v,"embed"))return!0}return!1},[]),u=this.editor.getShapePageTransform(n).rotation();if(r)return d.jsx(ci,{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 m=l.url.split("/").pop();if(!m)throw Error("No gist id!");return d.jsx(ci,{className:"tl-embed-container",id:n.id,children:d.jsx(Cce,{id:m,width:N(o),height:N(s),isInteractive:h,pageRotation:u})})}const f=Pce({...jre,...(l==null?void 0:l.definition.overridePermissions)??{}});return d.jsx(ci,{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(xp,"type","embed"),E(xp,"props",xA),E(xp,"migrations",wA);function Cce({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:`
|
|
368
|
-
<html>
|
|
369
|
-
<head>
|
|
370
|
-
<base target="_blank">
|
|
371
|
-
</head>
|
|
372
|
-
<body>
|
|
373
|
-
<script src=${`https://gist.github.com/${t}.js${e?`?file=${e}`:""}`}><\/script>
|
|
374
|
-
<style type="text/css">
|
|
375
|
-
* { margin: 0px; }
|
|
376
|
-
table { height: 100%; background-color: red; }
|
|
377
|
-
.gist { background-color: none; height: 100%; }
|
|
378
|
-
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
379
|
-
</style>
|
|
380
|
-
</body>
|
|
381
|
-
</html>`})}const _ce=w.forwardRef(({id:t,name:e,isEditing:n},r)=>{const o=z(),s=w.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(_t(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=w.useCallback(l=>{const c=o.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==h&&o.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,o]),a=w.useCallback(l=>{const c=o.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value;u!==h&&o.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,o]);return d.jsxs("div",{className:`tl-frame-label ${n?"tl-frame-label__editing":""}`,children:[d.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:n?void 0:"none"},value:e,autoFocus:!0,onKeyDown:s,onBlur:i,onChange:a}),r5(e,"Frame")+""]})}),Ice=function({id:e,name:n,width:r,height:o}){const s=z(),i=H("shape rotation",()=>li(s.getShapePageTransform(e).rotation()),[s,e]),a=Vg(e),l=w.useRef(null),c=w.useCallback(m=>{const g=Wn(m);m.preventDefault(),s.getEditingShapeId()!==e&&s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(e),...g})},[s,e]);w.useEffect(()=>{const m=l.current;m&&a&&(m.focus(),m.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(_ce,{ref:l,id:e,name:n,isEditing:a})})})};function r5(t,e){return t.match(/^\s*$/)?e:t}class wp extends nc{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){return new vs({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=Nr(),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(fi,{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(Ice,{id:e.id,name:e.props.name,width:n.width,height:n.height})]})}toSvg(e,n){const r=Is({isDarkMode:n.isDarkMode}),i=((li(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(r5(e.props.name,"Frame")+"",c),h=u[0],p=Ht(u),f=p.box.w+p.box.x-h.box.x,m=Jx(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}),m]})]})}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 Gg(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(wp,"type","frame"),E(wp,"props",bA),E(wp,"migrations",PA);function jE(t,e){return t>e?(De*(e/2)+(t-e))*2:(De*(t/2)+(e-t))*2}function o5(t,e){return Tb(t,e).map((n,r)=>n.getSvgPathData(r===0)).join(" ")+" Z"}function Ece(t,e,n,r){const o=t/4,s=e/4,i=lo(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)),m=l(new x(0,s*1.2)),g=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:m}),new an({start:m,cp1:new x(0,-s*.32),cp2:new x(o*1.85,-s*.32),end:g}),new an({start:g,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,P)=>y.getSvgPathData(P===0)).join(" ")+" Z"}function Tb(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 kce(t){return{size:1+t,thinning:.25,end:{taper:t},start:{taper:t},streamline:0,smoothing:1,simulatePressure:!1}}function Tce(t,e,n,r){const o=lo(t),s=e/2,i=n/2,a=HA(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),m=c+f*u,g=Math.cos(m),v=Math.sin(m);l.push(new x(s*g+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 Fo(l,kce(r))}function Mce(t,e,n,r){return ga(Tce(t,e,n,r))}function n0(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 r0(t,e,n,r,o){const s=[],i=lo(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),m=x.Div(p,f).mul(Math.min(f/4,r));s.push(x.Add(a,m),x.Add(l,m.neg()),l),a=l}return s}function Ace(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(la(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 jce={s:50,m:70,l:100,xl:130},Oce=.2;function wm(t,e,n,r,o){const s=lo(n),i=jE(t,e),a=Math.max(Math.ceil(i/jce[r]),6,Math.ceil(i/Math.min(t,e))),l=i/a*Oce,c=Math.max(t-l*2,1),u=Math.max(e-l*2,1),p=jE(c,u)/a,f=(t-c)/2,m=(e-u)/2,g=Ace(c,u,a).map(b=>b.addXY(f,m)),v=t<20?0:l*.3,S=e<20?0:l*.3,y=g.slice(0);for(let b=0;b<Math.floor(a/2);b++)y[b]=x.AddXY(y[b],s()*v*o,s()*S*o),y[a-b-1]=x.AddXY(y[a-b-1],s()*v*o,s()*S*o);const P=[];for(let b=0;b<y.length;b++){const C=b===y.length-1?0:b+1,I=y[b],k=y[C],_=g[b],M=g[C],T=x.Dist(_,M),D=p-T,O=x.Dist(I,k)/T,R=(Math.max(f,m)+D)*O,B=x.Lrp(_,M,.5).add(x.Sub(M,_).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=a1(I,k,B),G=x.Dist(L||x.Average([I,k]),I);P.push({leftPoint:I,rightPoint:k,arcPoint:B,center:L,radius:G})}return P}function Dce(t,e,n,r,o){const s=[],i=wm(t,e,n,r,o);for(const{center:a,radius:l,leftPoint:c,rightPoint:u}of i)s.push(...ZY(c,u,a,l,10));return s}function o0(t,e,n,r,o){const s=wm(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 Rce={s:.5,m:.7,l:.9,xl:1.6};function Lce(t,e,n,r,o){const s=lo(n),i=Rce[r]*o,a=wm(t,e,n,r,o),u=a.reduce((m,g)=>m+x.Dist2(g.leftPoint,g.rightPoint),0)/a.length>(i*15)**2?m=>x.AddXY(m,s()*i*2,s()*i*2):m=>m;let h=`M${a[0].leftPoint.toFixed()}`,p=u(a[0].leftPoint),f=`M${p.toFixed()}`;for(const{leftPoint:m,center:g,rightPoint:v,radius:S,arcPoint:y}of a){if(g===null){h+=` L${v.toFixed()}`;const _=u(v);f+=` L${_.toFixed()}`,p=_;continue}const P=x.Clockwise(m,v,g)?"0":"1";h+=` A${N(S)},${N(S)} 0 ${P},1 ${v.toFixed()}`;const b=u(v),C=u(y),I=a1(p,b,C);if(!I){f+=` L${b.toFixed()}`,p=b;continue}const k=Math.abs(x.Dist(I,p));f+=` A${N(k)},${N(k)} 0 ${P},1 ${b.toFixed()}`,p=b}return h+f+" Z"}function s0(t,e){switch(t.geo){case"x-box":return $ce(t.w,t.h,e,t.dash);case"check-box":return Fce(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 Fce(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 OE({shape:t,shouldScale:e,forceSolid:n}){const r=e?t.props.scale:1,o=z(),s=Nr(),{id:i,props:a}=t,{w:l,color:c,fill:u,dash:h,growY:p,size:f,scale:m}=a,g=hn[f]*r,v=a.h+p;switch(a.geo){case"cloud":if(h==="solid"){const S=o0(l,v,i,f,m);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:g,fill:"none"})]})}else if(h==="draw"){const S=Lce(l,v,i,f,m);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:g,fill:"none"})]})}else{const S=o0(l,v,i,f,m),y=wm(l,v,i,f,m);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:S,color:c,fill:u,scale:r}),d.jsx("g",{strokeWidth:g,stroke:s[c].solid,fill:"none",pointerEvents:"all",children:y.map(({leftPoint:P,rightPoint:b,center:C,radius:I},k)=>{const _=C?I*li(li(x.Angle(C,b))-li(x.Angle(C,P))):x.Dist(P,b),{strokeDasharray:M,strokeDashoffset:T}=Xr(_,g,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("path",{d:C?`M${P.x},${P.y}A${I},${I},0,0,1,${b.x},${b.y}`:`M${P.x},${P.y}L${b.x},${b.y}`,strokeDasharray:M,strokeDashoffset:T},k)})})]})}case"ellipse":{const S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const P=S.length,{strokeDasharray:b,strokeDashoffset:C}=Xr(P<64?P*2:P,g,{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:g,fill:"none",stroke:s[c].solid,strokeDasharray:b,strokeDashoffset:C})]})}else{const b=(e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t)).getSvgPathData(!0);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:b,color:c,fill:u,scale:r}),d.jsx("path",{d:b,stroke:s[c].solid,strokeWidth:g,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 P=S.getLength(),{strokeDasharray:b,strokeDashoffset:C}=Xr(P<64?P*2:P,g,{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:g,fill:"none",stroke:s[c].solid,strokeDasharray:b,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:g,fill:"none"})]})}case"heart":if(h==="dashed"||h==="dotted"||h==="solid"){const S=o5(l,v),y=Tb(l,v);return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:S,color:c,fill:u,scale:r}),y.map((P,b)=>{const{strokeDasharray:C,strokeDashoffset:I}=Xr(P.length,g,{style:h,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsx("path",{d:P.getSvgPathData(),strokeWidth:g,fill:"none",stroke:s[c].solid,strokeDasharray:C,strokeDashoffset:I,pointerEvents:"all"},`curve_${b}`)})]})}else{const S=Ece(l,v,g,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:g,fill:"none"})]})}default:{const S=e?o.getShapeGeometry(t):o.getShapeUtil(t).getGeometry(t),y=S instanceof so?S.children[0].vertices:S.vertices,P=s0(t.props,g);if(h==="solid"){let b="M"+y[0]+"L"+y.slice(1)+"Z";if(P)for(const[C,I]of P)b+=`M${C.x},${C.y}L${I.x},${I.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:b,color:c,fill:u,scale:r}),d.jsx("path",{d:b,stroke:s[c].solid,strokeWidth:g,fill:"none"})]})}else if(h==="dashed"||h==="dotted"){const b="M"+y[0]+"L"+y.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(on,{theme:s,d:b,color:c,fill:u,scale:r}),d.jsxs("g",{strokeWidth:g,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]),M=x.Dist(k,_),{strokeDasharray:T,strokeDashoffset:D}=Xr(M,g,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("line",{x1:k.x,y1:k.y,x2:_.x,y2:_.y,strokeDasharray:T,strokeDashoffset:D},I)}),P&&P.map(([C,I],k)=>{const _=x.Dist(C,I),{strokeDasharray:M,strokeDashoffset:T}=Xr(_,g,{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:g,fill:"none",strokeDasharray:M,strokeDashoffset:T},`line_fg_${k}`)})]})]})}else if(h==="draw"){let b=n0(r0(i,y,g/3,g*2,2));if(P)for(const[I,k]of P)b+=`M${I.toFixed()}L${k.toFixed()}`;const C=n0(r0(i,y,0,g*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:b,stroke:s[c].solid,strokeWidth:g,fill:"none"})]})}}}}const DE=17*3;class bp extends nc{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:Dce(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:Ry(n,r,5),isFilled:i});break}case"hexagon":{a=new xt({points:Ry(n,r,6),isFilled:i});break}case"octagon":{a=new xt({points:Ry(n,r,8),isFilled:i});break}case"ellipse":{a=new cte({width:n,height:r,isFilled:i});break}case"oval":{a=new ute({width:n,height:r,isFilled:i});break}case"star":{const y=Ne/5/2,P=Math.floor(5/4)*2,b=5*2-P,C=0,I=Math.floor(5/2)*2,k=Math.cos(-Ze+P*y)*n/2,_=Math.cos(-Ze+b*y)*n/2,M=Math.sin(-Ze+C*y)*r/2,T=Math.sin(-Ze+I*y)*r/2,D=n-Math.abs(k-_),A=r-Math.abs(T-M),O=n/2+_-(n/2-k),R=r/2+M-(r/2-T),B=1,L=(n-O)/2,G=(r-R)/2,$=(n+D)/2,U=(r+A)/2,Y=$*B/2,ee=U*B/2;a=new xt({points:Array.from(Array(5*2)).map((he,ue)=>{const ke=-Ze+ue*y;return new x(L+(ue%2?Y:$)*Math.cos(ke),G+(ue%2?ee: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 vs({width:n,height:r,isFilled:i});break}case"heart":{const y=Tb(n,r).reduce((P,b)=>(P.push(...b.vertices),P),[]);a=new xt({points:y,isFilled:i});break}default:Ot(e.props.geo)}const l=Oh(this.editor,e),c=n/e.props.scale,u=r/e.props.scale,h=Math.min(100,c/2),p=Math.min(fs[e.props.size]*pn.lineHeight+Er*2,u/2),f=Math.min(c,Math.max(l.w,Math.min(h,Math.max(1,c-8)))),m=Math.min(u,Math.max(l.h,Math.min(p,Math.max(1,u-8)))),g=s0(e.props,hn[e.props.size]*e.props.scale),v=g?g.map(S=>new Jl({points:S})):[];return new so({children:[a,new vs({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-m)*e.props.scale:(u-m)/2*e.props.scale,width:f*e.props.scale,height:m*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=Nr(),{editor:p}=this,f=H("isGeoOnlySelected",()=>e.id===p.getOnlySelectedShapeId(),[]),g=p.getEditingShapeId()!==null||e.props.text,v=H("force solid",()=>p.getZoomLevel()<.2,[p]);return d.jsxs(d.Fragment,{children:[d.jsx(fi,{children:d.jsx(OE,{shape:e,shouldScale:!0,forceSolid:v})}),g&&d.jsx(ci,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+o.growY},children:d.jsx(xm,{shapeId:n,type:r,font:i,fontSize:fs[c]*e.props.scale,lineHeight:pn.lineHeight,padding:Er*e.props.scale,fill:s,align:a,verticalAlign:l,text:u,isSelected:f,labelColor:h[o.labelColor].solid,wrap:!0})}),e.props.url&&d.jsx(Rl,{url:e.props.url})]})}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:Mce(n,o,i,a)}):d.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:o5(o,i)});case"oval":return d.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:o0(o,i,n,s,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),u=c instanceof so?c.children[0].vertices:c.vertices;let h;if(r.dash==="draw"){const f=r0(n,u,0,a*2*e.props.scale,1);h=n0(f)}else h="M"+u[0]+"L"+u.slice(1)+"Z";const p=s0(e.props,a);if(p)for(const[f,m]of p)h+=`M${f.x},${f.y}L${m.x},${m.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(Cb(o.fill));let s;if(o.text){n.addExportDef(Sm(o.font));const i=Is(n),a=new Z(0,0,o.w,o.h+o.growY);s=d.jsx(vm,{fontSize:fs[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(OE,{shouldScale:!1,shape:r,forceSolid:!1}),s]})}getCanvasSvgDefs(){return[_b()]}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 m=DE;if(e.props.text.trim()){let b=Math.max(Math.abs(u),m),C=Math.max(Math.abs(h),m);b<m&&C===m&&(b=m),b===m&&C<m&&(C=m);const I=Oh(this.editor,{...e,props:{...e.props,w:b*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 g=u*e.props.scale,v=h*e.props.scale,S=new x(0,0);o<0&&(S.x+=g),(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:P}=S.rot(e.rotation).add(r);return{x:y,y:P,props:{w:Math.max(Math.abs(g),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=Oh(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=Oh(this.editor,n);if(!r&&o&&o.length===1){let u=Math.max(s,l.w),h=Math.max(i,l.h);const p=DE;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(bp,"type","geo"),E(bp,"props",CA),E(bp,"migrations",_A);function Oh(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:bs[r],fontSize:fs[o],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=t.textMeasure.measureText(n,{...pn,fontFamily:bs[r],fontSize:fs[o],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[o]),Math.ceil(s/e.props.scale-Er*2))});return{w:l.w+Er*2,h:l.h+Er*2}}function Nce(){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 RE=.35,LE=.82;class Pp extends no{hideResizeHandles(e){return Dh(e)}hideRotateHandle(e){return Dh(e)}hideSelectionBoundsFg(e){return Dh(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(e){const n=Ui(e);if(Dh(e))return new M1({x:-n/2,y:-n/2,radius:n/2,isFilled:!0});const{strokePoints:r,sw:o}=$E(e,n,!0),s=kb({strokeWidth:o,showAsComplete:!0});return mm(r,s),new xt({points:wb(r,s),isFilled:!0})}component(e){const n=wS(this.editor,e),r=Ui(e);return d.jsx(fi,{children:d.jsx(Rh,{shape:e,forceSolid:n,strokeWidth:r,opacity:RE})})}backgroundComponent(e){const n=wS(this.editor,e),r=Ui(e);return d.jsx(fi,{children:d.jsx(Rh,{shape:e,forceSolid:n,strokeWidth:r,opacity:LE})})}indicator(e){const n=wS(this.editor,e),r=Ui(e),{strokePoints:o,sw:s}=$E(e,r,n),i=Ll(e.props.segments);let a;return o.length<2?a=Bce(i[0],s):a=ga(o,!1),d.jsx("path",{d:a})}toSvg(e){const n=Ui(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(Rh,{forceSolid:r,strokeWidth:n,shape:e,opacity:RE})})}toBackgroundSvg(e){const n=Ui(e),r=n<1.5,o=1/e.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(Rh,{forceSolid:r,strokeWidth:n,shape:e,opacity:LE})})}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:e5(e.props.segments,n.props.segments,r),scale:Ie(e.props.scale,n.props.scale,r)}}}E(Pp,"type","highlight"),E(Pp,"props",kA),E(Pp,"migrations",TA);function zce(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 Bce(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 $E(t,e,n){var l;const r=Ll(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+=lo(t.id)()*(e/6));const i=kb({strokeWidth:s,showAsComplete:o});return{strokePoints:Fo(r,i),sw:s}}function Ui(t){return Ol[t.props.size]*1.12*t.props.scale}function Dh(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function Rh({strokeWidth:t,forceSolid:e,shape:n,opacity:r}){var p;const o=Nr(),s=Ll(n.props.segments);let i=t;!e&&!n.props.isPen&&s.length===1&&(i+=lo(n.id)()*(i/6));const a=kb({strokeWidth:i,showAsComplete:n.props.isComplete||((p=Ht(n.props.segments))==null?void 0:p.type)==="straight"}),l=Fo(s,a),c=l.length>1?ga(l,!1):zce(n.props.segments[0].points[0]),u=Nce(),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 wS(t,e){return H("forceSolid",()=>{const n=Ui(e),r=t.getZoomLevel();return n/r<1.5},[t])}function s5(){return d.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),d.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),d.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function i5({shapeId:t,assetId:e}){const n=z(),r=!!fd(),o=lQ(),[s,i]=w.useState(()=>({asset:e?n.getAsset(e)??null:null,url:null})),a=w.useRef(!1),l=w.useRef(null);return w.useEffect(()=>{if(!e)return;let c=!1,u;const h=Mo("update state",()=>{if(!r&&n.getCulledShapes().has(t))return;const p=n.getAsset(e);if(!p)return;const f=n.getShape(t);if(!f)return;if(!p.props.src){const g=n.getTemporaryAssetPreview(p.id);if(g){l.current!==g&&(l.current=g,i(v=>({...v,isPlaceholder:!0,url:g})),o());return}}const m=n.getZoomLevel()*(f.props.w/p.props.w);a.current?(FE(n,e,m,r,g=>{c||l.current!==g&&(l.current=g,i(()=>({asset:p,url:g})))}),u=FE.cancel):a5(n,e,m,r,g=>{c||(a.current=!0,l.current=g,i(()=>({asset:p,url:g})))})});return()=>{h(),u==null||u(),c=!0}},[n,e,r,o,t]),s}function a5(t,e,n,r,o){t.resolveAssetUrl(e,{screenScale:n,shouldResolveToOriginal:r}).then(s=>{o(s)})}const FE=gg(a5,500);function l5(){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 Uce(t){const n=await(await oo(t)).blob();return cs.blobToDataUrl(n)}class Cp extends nc{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=Gg(e,n);const{flipX:o,flipY:s}=n.initialShape.props,{scaleX:i,scaleY:a,mode:l}=n;if(r={...r,props:{...r.props,flipX:i<0!==o,flipY:a<0!==s}},!e.props.crop)return r;const c=l==="scale_shape"&&i===-1||l==="resize_bounds"&&o!==r.props.flipX,u=l==="scale_shape"&&a===-1||l==="resize_bounds"&&s!==r.props.flipY,{topLeft:h,bottomRight:p}=e.props.crop;return r.props.crop={topLeft:{x:c?1-p.x:h.x,y:u?1-p.y:h.y},bottomRight:{x:c?1-h.x:p.x,y:u?1-h.y:p.y}},r}component(e){return d.jsx(Hce,{shape:e})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){if(!e.props.assetId||!this.editor.getAsset(e.props.assetId))return null;let r=await this.editor.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});return r?((r.startsWith("blob:")||r.startsWith("http")||r.startsWith("/")||r.startsWith("./"))&&(r=await Uce(r)||""),d.jsx(Wce,{shape:e,src:r})):null}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,m;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=((m=i.props.crop)==null?void 0:m.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(Cp,"type","image"),E(Cp,"props",MA),E(Cp,"migrations",AA);const Hce=w.memo(function({shape:e}){var S;const n=z(),{asset:r,url:o}=i5({shapeId:e.id,assetId:e.props.assetId}),s=l5(),[i,a]=w.useState(""),[l,c]=w.useState(null),u=Kce(n,e);w.useEffect(()=>{if(o&&u){let y=!1;const P=Du();return P.onload=()=>{if(y)return;const b=document.createElement("canvas");b.width=P.width,b.height=P.height;const C=b.getContext("2d");C&&(C.drawImage(P,0,0),a(b.toDataURL()),c(o))},P.crossOrigin="anonymous",P.src=o,()=>{y=!0}}},[n,u,s,o]);const h=H("show crop preview",()=>e.id===n.getOnlySelectedShapeId()&&n.getCroppingShapeId()===e.id&&n.isIn("select.crop"),[n,e.id]),p=s&&(((S=r==null?void 0:r.props.mimeType)==null?void 0:S.includes("video"))||u),f=c5(e),m=o===l?null:o,g=p?i:l;if(!o&&!(r!=null&&r.props.src))return d.jsxs(ci,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,color:"var(--color-text-3)",backgroundColor:"var(--color-low)",border:"1px solid var(--color-low-border)"},children:[d.jsx("div",{className:le("tl-image-container",r&&"tl-image-container-loading"),style:f,children:r?null:d.jsx(s5,{})}),"url"in e.props&&e.props.url&&d.jsx(Rl,{url:e.props.url})]});const v=u?"anonymous":void 0;return d.jsxs(d.Fragment,{children:[h&&g&&d.jsx("div",{style:f,children:d.jsx("img",{className:"tl-image",style:{...hu(e),opacity:.1},crossOrigin:v,src:g,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),d.jsxs(ci,{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:[g&&d.jsx("img",{className:"tl-image",style:hu(e),crossOrigin:v,src:g,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},g),m&&d.jsx("img",{className:"tl-image",style:hu(e),crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>c(m)},m)]}),e.props.url&&d.jsx(Rl,{url:e.props.url})]})]})});function Kce(t,e){const n=e.props.assetId?t.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}function c5(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 hu(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 Wce({shape:t,src:e}){const n=ql(),r=c5(t),o=t.props.crop;if(r.transform&&o){const{transform:s,width:i,height:a}=r,l=(o.bottomRight.x-o.topLeft.x)*i,c=(o.bottomRight.y-o.topLeft.y)*a,u=[new x(0,0),new x(l,0),new x(l,c),new x(0,c)],h=hu(t,{width:i,height:a});return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:n,children:d.jsx("polygon",{points:u.map(p=>`${p.x},${p.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${n})`,children:d.jsx("image",{href:e,width:i,height:a,style:h?{...h,transform:`${s} ${h.transform}`}:{transform:s}})})]})}else return d.jsx("image",{href:e,width:t.props.w,height:t.props.h,style:hu(t,{width:t.props.w,height:t.props.h})})}function u5(t){return{size:t,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function d5(t,e,n){const r=e.vertices,o=u5(n);return Fo(r,o)}function Gce(t,e,n){const r=u5(n);return wb(mm(d5(t,e,n),r),r)}function Vce(t,e,n){const r=Gce(t,e,n);return d1(r)}function Yce(t,e,n){if(t.props.dash==="draw"){const r=d5(t,e,n);return ga(r)}return e.getSvgPathData()}function h5(t,e,n){let r=`M ${je(e[0])}L`,o=`M ${je(e[0])}L`;const s=n/3,i=n*2,a=lo(t);let l=e[0],c,u=e[0],h;const p=e.length;for(let f=0,m=p-1;f<m;f++){c=e[f+1],h=x.AddXY(e[f+1],a()*s,a()*s);const g=x.Sub(c,l),v=x.Len(g),S=x.Div(g,v).mul(Math.min(v/4,i)),y=x.Add(l,S),P=x.Add(c,S.neg()),b=x.Sub(h,u),C=x.Len(b),I=x.Div(b,C).mul(Math.min(C/4,i)),k=x.Add(u,I),_=x.Add(h,I.neg());f===m-1?(r+=`${je(y)}L ${je(c)}`,o+=`${je(k)}L ${je(h)}`):(r+=`${je(y)}L ${je(P)}Q ${je(c)}`,o+=`${je(k)}L ${je(_)}Q ${je(h)}`,l=c,u=h)}return[r,r+o]}const Xce=new Oo;class _p extends no{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,n]=Lu(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 Xc(e)}getHandles(e){return Xce.get(e.props,()=>{const n=Xc(e),r=Yc(e),o=r.map(s=>({...s,id:s.index,type:"vertex",canSnap:!0}));for(let s=0;s<r.length-1;s++){const i=Ru(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:nd(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(fi,{children:d.jsx(NE,{shape:e})})}indicator(e){const n=Eo[e.props.size]*e.props.scale,r=Xc(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]=h5(e.id,i,n);s=a}}else s=Yce(e,r,n);return d.jsx("path",{d:s})}toSvg(e){return d.jsx(NE,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const n=Yc(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=Xc(e).segments.filter((i,a)=>a!==o-1&&a!==o);return s.length?new so({children:s}):null}}}getInterpolatedProps(e,n,r){const o=Yc(e),s=Yc(n),i=[],a=[];let l=NT;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=Co(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=Co(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(_p,"type","line"),E(_p,"props",jA),E(_p,"migrations",OA);function Yc(t){return Object.values(t.props.points).sort(cn)}function Xc(t){const e=Yc(t).map(x.From);switch(t.props.spline){case"cubic":return new lte({points:e});case"line":return new Jl({points:e})}}function NE({shape:t,shouldScale:e=!1,forceSolid:n=!1}){const r=Nr(),o=Xc(t),{dash:s,color:i,size:a}=t.props,l=1/t.props.scale,c=e?l:1,u=Eo[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:m}=n?{strokeDasharray:"none",strokeDashoffset:"none"}:Xr(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:m,d:h.getSvgPathData(!0),fill:"none"},p)})});if(s==="draw"){const h=o.points,[p,f]=h5(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:m,strokeDashoffset:g}=Xr(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:m,strokeDashoffset:g,d:p.getSvgPathData(),fill:"none"},f)})});if(s==="draw")return d.jsx("path",{d:Vce(t,o,u),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${c})`})}}class Ip extends no{canEdit(){return!0}hideResizeHandles(){return!0}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(e){const{labelHeight:n,labelWidth:r}=p5(this.editor,e),{scale:o}=e.props,s=n*o,i=r*o,a=He*o,l=Lh(e);return new so({children:[new vs({width:a,height:l,isFilled:!0}),new vs({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=Lh(e),i=He*n,a=mle/o*n;return o*n<.5?[{id:"bottom",index:"a3",type:"clone",x:i/2,y:s+a}]:[{id:"top",index:"a1",type:"clone",x:i/2,y:-a},{id:"right",index:"a2",type:"clone",x:i+a,y:s/2},{id:"bottom",index:"a3",type:"clone",x:i/2,y:s+a},{id:"left",index:"a4",type:"clone",x:-a,y:s/2}]}getText(e){return e.props.text}component(e){const{id:n,type:r,props:{labelColor:o,scale:s,color:i,font:a,size:l,align:c,text:u,verticalAlign:h,fontSizeAdjustment:p}}=e,f=Qce(n),m=Nr(),g=He*s,v=Lh(e),S=H("shape rotation",()=>{var b;return((b=this.editor.getShapePageTransform(n))==null?void 0:b.rotation())??0},[this.editor]),y=H("zoom",()=>this.editor.getZoomLevel()<.35/s,[s,this.editor]),P=e.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:n,className:"tl-note__container",style:{width:g,height:v,backgroundColor:m[i].note.fill,borderBottom:y?`${3*s}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:y?"none":Jce(e.id,S,s)},children:d.jsx(xm,{shapeId:n,type:r,font:a,fontSize:(p||fs[l])*s,lineHeight:pn.lineHeight,align:c,verticalAlign:h,text:u,isNote:!0,isSelected:P,labelColor:o==="black"?m[i].note.text:m[o].fill,wrap:!0,padding:16*s,onKeyDown:f})}),"url"in e.props&&e.props.url&&d.jsx(Rl,{url:e.props.url})]})}indicator(e){const{scale:n}=e.props;return d.jsx("rect",{rx:n,width:N(He*n),height:N(Lh(e))})}toSvg(e,n){e.props.text&&n.addExportDef(Sm(e.props.font));const r=Is({isDarkMode:n.isDarkMode}),o=eue(e);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:He-10,height:o.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:He,height:o.h,fill:r[e.props.color].note.fill}),d.jsx(vm,{fontSize:e.props.fontSizeAdjustment||fs[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 zE(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 zE(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(Ip,"type","note"),E(Ip,"props",DA),E(Ip,"migrations",RA);function zE(t,e){const{labelHeight:n,fontSizeAdjustment:r}=p5(t,e),o=Math.max(0,n-He);if(o!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:o,fontSizeAdjustment:r}}}function qce(t,e){const{text:n}=e.props;if(!n)return{labelHeight:fs[e.props.size]*pn.lineHeight+Er*2,labelWidth:100,fontSizeAdjustment:0};const r=fs[e.props.size];let o=0,s=0,i=He,a=He;const l=1;do{o=Math.min(r,r-s);const c=t.textMeasure.measureText(n,{...pn,fontFamily:bs[e.props.font],fontSize:o,maxWidth:He-Er*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Er*2,a=c.w+Er*2,o<=14){const u=t.textMeasure.measureText(n,{...pn,fontFamily:bs[e.props.font],fontSize:o,maxWidth:He-Er*2-l});i=u.h+Er*2,a=u.w+Er*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const Zce=new Oo;function p5(t,e){return Zce.get(e,()=>qce(t,e))}function Qce(t){const e=z(),n=M3();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"||L$(o.props.text)),u=(He+e.options.adjacentShapeMargin+(i&&!r.shiftKey?o.props.growY:0))*o.props.scale,h=new x(s?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(ym.clone().mul(o.props.scale)).rot(l).add(a.point()),p=H$(e,o,h,l);p&&(e.markHistoryStoppingPoint("editing adjacent shape"),Lf(e,p,!0))}},[t,e,n.dir])}function Lh(t){return(He+t.props.growY)*t.props.scale}function Jce(t,e,n){const r=lo(t),o=Math.abs(r())+.5,s=Math.cos(e),i=5*n,a=4*n,l=6*n,c=7*n;return`0px ${i-o}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
382
|
-
0px ${(a+o*c)*Math.max(0,s)}px ${l+o*c}px -${a+o*l}px rgba(15, 23, 31, ${(.3+o*.1).toFixed(2)}),
|
|
383
|
-
0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+s)/2)).toFixed(2)})`}function eue(t){return new Z(0,0,He,He+t.props.growY)}function tue(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 nue=new Oo;class Ep extends no{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return nue.get(e.props,n=>BE(this.editor,n))}getGeometry(e){const{scale:n}=e.props,{width:r,height:o}=this.getMinDimensions(e);return new vs({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=Nr(),f=rue(n);return d.jsx(xm,{shapeId:n,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:Ol[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(Sm(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=Is(n);return d.jsx(vm,{fontSize:Ol[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,...tue(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=BE(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(Ep,"type","text"),E(Ep,"props",LA),E(Ep,"migrations",$A);function BE(t,e){const{font:n,text:r,autoSize:o,size:s,w:i}=e,a=o?16:Math.max(16,i),l=Ol[s],c=o?null:Math.floor(Math.max(a,i)),u=t.textMeasure.measureText(r,{...pn,fontFamily:bs[n],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function rue(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?Dl.unindent(n.currentTarget):Dl.indent(n.currentTarget);break}}},[e,t])}class kp extends nc{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){const{asset:n,url:r}=i5({shapeId:e.id,assetId:e.props.assetId});return d.jsx(oue,{editor:this.editor,shape:e,asset:n,url:r})}indicator(e){return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){const n=await sue(this.editor,e);return n?d.jsx("image",{href:n,width:e.props.w,height:e.props.h}):null}}E(kp,"type","video"),E(kp,"props",FA),E(kp,"migrations",NA);const oue=w.memo(function({editor:e,shape:n,asset:r,url:o}){const s=e.getShapeGeometry(n).bounds.w*e.getZoomLevel()>=110,i=Vg(n.id),a=l5(),{Spinner:l}=ot(),c=w.useRef(null),[u,h]=w.useState(!1),[p,f]=w.useState(!1);w.useEffect(()=>{const g=()=>f(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",g),()=>document.removeEventListener("fullscreenchange",g)});const m=w.useCallback(g=>{g.currentTarget&&h(!0)},[]);return w.useEffect(()=>{const g=c.current;g&&i&&document.activeElement!==g&&g.focus()},[i,u]),w.useEffect(()=>{if(a){const g=c.current;if(!g)return;g.pause(),g.currentTime=0}},[c,a]),d.jsxs(d.Fragment,{children:[d.jsx(ci,{id:n.id,style:{color:"var(--color-text-3)",backgroundColor:r?"transparent":"var(--color-low)",border:r?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:r?l&&!r.props.src?d.jsx(l,{}):o?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-${n.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&&s,onLoadedData:m,hidden:!u,children:d.jsx("source",{src:o})}),!u&&l&&d.jsx(l,{})]}):null:d.jsx(s5,{})})})}),"url"in n.props&&n.props.url&&d.jsx(Rl,{url:n.props.url})]})});async function sue(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 f5=[Ep,Sp,vp,bp,Ip,_p,wp,yp,Pp,xp,Cp,kp];function iue(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 g5 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),m=n.getShapePageTransform(h);if(!f||!m)continue;const g=m.clone().invert(),v=g.applyToPoint(l),S=g.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(g5,"id","erasing");var BS;let aue=(BS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},E(BS,"id","idle"),BS);var US;let lue=(US=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(US,"id","pointing"),US);class Tp extends ie{static children(){return[aue,lue,g5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}E(Tp,"id","eraser"),E(Tp,"initial","idle"),E(Tp,"isLockable",!1);class m5 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(m5,"id","dragging");var HS;let cue=(HS=class extends ie{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},E(HS,"id","idle"),HS);var KS;let uue=(KS=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(KS,"id","pointing"),KS);class Mp extends ie{static children(){return[cue,uue,m5]}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(Mp,"id","hand"),E(Mp,"initial","idle"),E(Mp,"isLockable",!1);var WS;let due=(WS=class extends ie{onPointerDown(e){this.parent.transition("lasering",e)}},E(WS,"id","idle"),WS);class y5 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(y5,"id","lasering");class Ap extends ie{static children(){return[due,y5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}E(Ap,"id","laser"),E(Ap,"initial","idle"),E(Ap,"isLockable",!1);class S5 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,m,g,v,S,y;const P=n.getCurrentPageRenderingShapesSorted(),b=n.getCurrentPageId();e:for(let k=0,_=P.length;k<_;k++){if(g=P[k],r.has(g.id)||c.has(g.id)||(v=n.getShapePageBounds(g),!v))continue e;if(h.contains(v)){this.handleHit(g,i,b,c,p);continue e}if(u||n.isShapeOfType(g,"frame"))continue e;if(h.collides(v)){if(S=n.getShapePageTransform(g),!S)continue e;y=S.clone().invert().applyToPoints(p);const M=n.getShapeGeometry(g);t:for(let T=0;T<4;T++)if(f=y[T],m=y[(T+1)%4],M.hitTestLineSegment(f,m,0)){this.handleHit(g,i,b,c,p);break t}}}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&&!Mj(l,i)&&!hr(r,l)||s.add(a.id)}}E(S5,"id","brushing");const $l={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 v5 extends ie{constructor(){super(...arguments);E(this,"info",{})}updateCursor(){const n=this.editor.getSelectedShapes(),r=$l[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(v5,"id","pointing_resize_handle");const _r=8;class Mb 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=$l[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,m=1/(c.bottomRight.y-c.topLeft.y)*s.h;let g=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(m<_r)break;g=!0,u.topLeft.y=u.topLeft.y+l.y/m,m*(u.bottomRight.y-u.topLeft.y)<_r?(u.topLeft.y=u.bottomRight.y-_r/m,p.y=(u.topLeft.y-c.topLeft.y)*m):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-c.topLeft.y)*m):p.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(m<_r)break;g=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/m),m*(u.bottomRight.y-u.topLeft.y)<_r&&(u.bottomRight.y=u.topLeft.y+_r/m);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<_r)break;g=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<_r?(u.topLeft.x=u.bottomRight.x-_r/f,p.x=(u.topLeft.x-c.topLeft.x)*f):u.topLeft.x<=0?(u.topLeft.x=0,p.x=(u.topLeft.x-c.topLeft.x)*f):p.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(f<_r)break;g=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<_r&&(u.bottomRight.x=u.topLeft.x+_r/f);break}}if(!g)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)*m}};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(Mb,"id","cropping");function x5(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 w5(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 GS;let hue=(GS=class extends ie{onEnter(){this.editor.setCursor({type:"default",rotation:0});const e=this.editor.getOnlySelectedShape();e&&this.editor.setCroppingShape(e.id)}onExit(){this.editor.setCursor({type:"default",rotation:0})}onCancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}onPointerDown(e){var n;if(e.accelKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{const r=x5(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=w5(this.editor,s,o);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},E(GS,"id","idle"),GS);class b5 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(b5,"id","pointing_crop");class Ab 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=$l[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(Ab,"id","pointing_crop_handle");class P5 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=w5(this.editor,n,s);i&&this.editor.updateShapes([i])}}E(P5,"id","translating_crop");class i0 extends ie{constructor(){super(...arguments);E(this,"markId","");E(this,"didExit",!1)}static children(){return[hue,P5,b5,Ab,Mb]}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(i0,"id","crop"),E(i0,"initial","idle");class C5 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=Bn(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:m,pointerVelocity:g}}=n,v=this.info.shape,S=n.getShape(r);if(!S)return;const y=n.getShapeUtil(S);let P=h.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const _=x.Angle(a,P),T=Mf(_,24)-_;P=x.RotWith(P,a,T)}n.snaps.clearIndicators();let b={...s,x:P.x,y:P.y};if(s.canSnap&&(c?!f:f)){if(!n.getShapePageTransform(S.id))throw Error("Expected a page transform");const M=u.handles.snapHandle({currentShapeId:r,handle:b});M&&(M.nudge.rot(-n.getShapeParentTransform(S).rotation()),P.add(M.nudge),b={...s,x:P.x,y:P.y})}const C=(k=y.onHandleDrag)==null?void 0:k.call(y,S,{handle:b,isPrecise:this.isPrecise||m,initial:v}),I={id:S.id,type:S.type,...C};if(s.type==="vertex"&&this.editor.isShapeOfType(S,"arrow")){const _=Bn(n,S)[s.id];_?l[0]!==_.toId&&(n.setHintingShapes([_.toId]),this.pointingId=_.toId,this.isPrecise=g.len()<.5||m,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(C5,"id","dragging_handle");function _5(t){return t.isLabel?[t]:t instanceof so?t.children.filter(e=>e.isLabel):[]}class I5 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"),as(this.editor),this.editor.select(r)}onExit(){var s;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),as.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":{as(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=_5(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),as(this.editor)}}onComplete(n){this.parent.transition("idle",n)}onCancel(n){this.parent.transition("idle",n)}}E(I5,"id","editing_shape");function UE(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 pue=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var VS;let fue=(VS=class extends ie{onEnter(){this.parent.setCurrentToolIdMask(void 0),as(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){as.cancel()}onPointerMove(){as(this.editor)}onPointerDown(e){const n=e.ctrlKey&&UE(this.editor);switch(e.target){case"canvas":{const r=x5(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))&&HE(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))&&HE(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()&&!pue.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}UE(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"),Lf(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=Ke(),{x:r,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:n,type:"text",x:r,y:o,props:{text:"",autoSize:!0}}]);const s=this.editor.getShape(n);if(!s)return;const i=this.editor.getShapeUtil(s);this.editor.getIsReadonly()&&!i.canEditInReadOnly(s)||(this.editor.setEditingShape(n),this.editor.select(n),this.parent.transition("editing_shape",e))}nudgeSelectedShapes(e=!1){const{editor:{inputs:{keys:n}}}=this,r=n.has("ShiftLeft"),o=new x(0,0);if(n.has("ArrowLeft")&&(o.x-=1),n.has("ArrowRight")&&(o.x+=1),n.has("ArrowUp")&&(o.y-=1),n.has("ArrowDown")&&(o.y+=1),o.equals(new x(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:s}=this.editor.getDocumentSettings(),i=this.editor.getInstanceState().isGridMode?r?s*yue:s:r?gue:mue,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(VS,"id","idle"),VS);const gue=10,mue=1,yue=5;function HE(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 E5 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=Io(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=fx(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(E5,"id","pointing_arrow_label");class k5 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(k5,"id","pointing_canvas");class T5 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=Bn(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=KE(o,n,r,!1);if(s){Lf(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=KE(n,r,o,!0);if(s){const i=n.getPointInParentSpace(s,n.inputs.originPagePoint).sub(x.Rot(ym.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:()=>{Lf(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(T5,"id","pointing_handle");function KE(t,e,n,r){const o=t.getShapePageTransform(e.id),s=o.point(),i=o.rotation(),l=B$(t,s,i,e.props.growY,0,e.props.scale)[n.index];if(l)return H$(t,e,l,i,r)}class M5 extends ie{constructor(){super(...arguments);E(this,"info",{})}updateCursor(){this.editor.setCursor({type:$l[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(M5,"id","pointing_rotate_handle");class A5 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(A5,"id","pointing_selection");class j5 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=_5(p),m=f.length===1?f[0]:void 0;if(m){const g=this.editor.getPointInShapeSpace(c,i);if(m.bounds.containsPoint(g,0)&&m.hitTestPoint(g)){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(m=>m.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(j5,"id","pointing_shape");class O5 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),m=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:_}=this.editor.getDocumentSettings();f.snapToGrid(_)}const g=this.info.handle,v=WE(g,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,m),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:WE(g,c),isAspectRatioLocked:h,isResizingFromCenter:n});f.add(_)}const y=x.RotWith(n?i.center:i.getHandlePoint(v),i.point,c),P=x.Sub(f,y).rot(-c),b=x.Sub(m,y).rot(-c),C=x.DivV(P,b);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const I=g==="top"||g==="bottom",k=g==="left"||g==="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:g,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:c});for(const _ of s.keys()){const M=s.get(_);this.editor.resizeShape(_,C,{initialShape:M.shape,initialBounds:M.bounds,initialPageTransform:M.pageTransform,dragHandle:g,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:M}of o){if(!M.length)continue;const T=s.get(_).shape,D=this.editor.getShape(_);if(!(T&&D))continue;const A=D.x-T.x,O=D.y-T.y,R=new x(A,O).rot(-T.rotation);if(R.x!==0||R.y!==0)for(const B of M)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 M of _)this.editor.updateShape({id:M.id,type:M.type,x:M.x,y:M.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 m=this.editor.getShape(f);if(m&&(l.set(m.id,this._createShapeSnapshot(m)),this.editor.isShapeOfType(m,"frame")))return!1})}});const u=![...l.values()].some(h=>!WA(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(O5,"id","resizing");const bS=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function WE(t,e){e=e%Ne;const n=Math.round(e/(De/4)),r=bS.indexOf(t);return bS[(r+n)%bS.length]}const GE=Math.PI/180;class D5 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=Jj({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});ap({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:$l[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});ap({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:$l[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(){ap({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=Mf(h,24);else if(n&&(h=Math.round(h/GE)*GE,this.editor.getInstanceState().isCoarsePointer)){const p=Mf(h,4),f=op(h,p);Math.abs(f)<YY(5)&&(h=p)}return h-l}}E(D5,"id","rotating");class R5 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,m,g;const v=0;for(let P=0,b=h.length;P<b;P++){if(p=h[P],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();m=I.applyToPoint(a),g=I.applyToPoint(l);const{bounds:k}=f;if(!(k.minX-v>Math.max(m.x,g.x)||k.minY-v>Math.max(m.y,g.y)||k.maxX+v<Math.min(m.x,g.x)||k.maxY+v<Math.min(m.y,g.y))&&f.hitTestLineSegment(m,g,v)){const _=this.editor.getOutermostSelectableShape(p),M=this.editor.getShapeMask(_.id);if(M&&m1(a,l,M)!==null&&!hr(l,M))continue;c.add(_.id)}}const S=r.getSelectedShapeIds(),y=new Set(s?[...c,...u]:[...c]);(S.length!==y.size||S.some(P=>!y.has(P)))&&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(R5,"id","scribble_brushing");var Sue=Object.create,L5=Object.defineProperty,vue=Object.getOwnPropertyDescriptor,xue=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),$5=t=>{throw TypeError(t)},F5=(t,e,n)=>e in t?L5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,wue=t=>[,,,Sue(null)],N5=["class","method","getter","setter","accessor","field","value","get","set"],z5=t=>t!==void 0&&typeof t!="function"?$5("Function expected"):t,bue=(t,e,n,r,o)=>({kind:N5[t],name:e,metadata:r,addInitializer:s=>n._?$5("Already initialized"):o.push(z5(s||null))}),Pue=(t,e)=>F5(e,xue("metadata"),t[3]),Cue=(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},_ue=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=N5[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,vue(o,n)),S=r.length-1;S>=0;S--)l=bue(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,z5(i)&&(v[m]=i);return v&&L5(o,n,v),o},PS=(t,e,n)=>F5(t,typeof e!="symbol"?e+"":e,n),B5,bm;const Iue=20,Eue=100;B5=[Hn];class jb{constructor(e){this.editor=e,Cue(bm,5,this),PS(this,"prevDroppingShapeId",null),PS(this,"droppingNodeTimer",null),PS(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,Iue,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Eue,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&&A3(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()}}bm=wue();_ue(bm,1,"dispose",B5,jb);Pue(bm,jb);var kue=Object.create,U5=Object.defineProperty,Tue=Object.getOwnPropertyDescriptor,H5=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),K5=t=>{throw TypeError(t)},W5=(t,e,n)=>e in t?U5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Mue=t=>[,,,kue((t==null?void 0:t[H5("metadata")])??null)],G5=["class","method","getter","setter","accessor","field","value","get","set"],V5=t=>t!==void 0&&typeof t!="function"?K5("Function expected"):t,Aue=(t,e,n,r,o)=>({kind:G5[t],name:e,metadata:r,addInitializer:s=>n._?K5("Already initialized"):o.push(V5(s||null))}),jue=(t,e)=>W5(e,H5("metadata"),t[3]),Oue=(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},Due=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=G5[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,Tue(o,n)),S=r.length-1;S>=0;S--)l=Aue(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,V5(i)&&(v[m]=i);return v&&U5(o,n,v),o},Ns=(t,e,n)=>W5(t,typeof e!="symbol"?e+"":e,n),Y5,a0,Pm;class Cm extends(a0=ie,Y5=[Hn],a0){constructor(){super(...arguments),Oue(Pm,5,this),Ns(this,"info",{}),Ns(this,"selectionSnapshot",{}),Ns(this,"snapshot",{}),Ns(this,"markId",""),Ns(this,"isCloning",!1),Ns(this,"isCreating",!1),Ns(this,"dragAndDropManager",new jb(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=VE(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=VE(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),Rue({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})}}Pm=Mue(a0);Due(Pm,1,"updateParentTransforms",Y5,Cm);jue(Pm,Cm);Ns(Cm,"id","translating");function VE(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 m=t.getShapePageTransform(p),g=m.point(),v=m.rotation();n.push(g);const S=yr.isId(f.parentId)?null:q.Inverse(t.getShapePageTransform(f.parentId));return{shape:f,pagePoint:g,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,m)=>({id:"selection:"+m,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(m=>m.id===f.shape.id)})).sort((f,m)=>m.index-f.index)[0])==null?void 0:h.snapshot}return l&&(a=U$(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 Rue({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(ym.clone().mul(v).rot(r.pageRotation));let y=z$/t.getZoomLevel(),P=new x(0,0);for(const b of o){const C=x.Sub(S,b),I=C.len();I<y&&(y=I,P=C)}h.sub(P)}const m=x.Add(l,h);c&&!n.ctrlKey&&m.snapToGrid(u);const g=x.Sub(m,l);t.updateShapes(ye(a.map(({shape:v,pagePoint:S,parentTransform:y})=>{const P=x.Add(S,g),b=y?q.applyToPoint(y,P):P;return{id:v.id,type:v.type,x:b.x,y:b.y}})))}class jp extends ie{constructor(){super(...arguments);E(this,"reactor")}static children(){return[i0,Mb,fue,k5,j5,Cm,S5,R5,Ab,A5,v5,I5,O5,D5,M5,E5,T5,C5]}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=Mo("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(jp,"id","select"),E(jp,"initial","idle"),E(jp,"isLockable",!1);class X5 extends ie{constructor(){super(...arguments);E(this,"info",{})}onEnter(n){this.info=n}onPointerDown(){this.parent.transition("pointing",this.info)}}E(X5,"id","idle");class q5 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(q5,"id","pointing");class Z5 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(Z5,"id","zoom_brushing");class Op extends ie{constructor(){super(...arguments);E(this,"info",{})}static children(){return[X5,Z5,q5]}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(Op,"id","zoom"),E(Op,"initial","idle"),E(Op,"isLockable",!1);const Lue=[Tp,Mp,Ap,Op,jp];function $ue(){const t=z(),e=H("follow",()=>t.getInstanceState().followingUserId,[t]);return e?d.jsx(Fue,{userId:e}):null}function Fue({userId:t}){const e=jg(t);return e?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let l0={fonts:{draw:`${Zs()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${Zs()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${Zs()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${Zs()}/fonts/IBMPlexMono-Medium.woff2`}};function Q5(t){return w.useMemo(()=>t?{fonts:{...l0.fonts,...t==null?void 0:t.fonts}}:l0,[t])}const Nue=["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 Oc={...l0,icons:Object.fromEntries(Nue.map(t=>[t,`${Zs()}/icons/icon/0_merged.svg#${t}`])),translations:Object.fromEntries(Nu.map(t=>[t.locale,`${Zs()}/translations/${t.locale}.json`])),embedIcons:Object.fromEntries(W1.map(t=>[t.type,`${Zs()}/embed-icons/${t.type}.png`]))};function zue(t){return t?{fonts:Object.assign({...Oc.fonts},{...t==null?void 0:t.fonts}),icons:Object.assign({...Oc.icons},{...t==null?void 0:t.icons}),embedIcons:Object.assign({...Oc.embedIcons},{...t==null?void 0:t.embedIcons}),translations:Object.assign({...Oc.translations},{...t==null?void 0:t.translations})}:Oc}function Bue(){const{addToast:t,removeToast:e,clearToasts:n}=Uo(),{addDialog:r,clearDialogs:o,removeDialog:s}=Pa(),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 Uue(t,e){const n={};for(const r of t)if(r.translations)for(const[o,s]of qn(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 J5(t){return w.useMemo(()=>t,t)}function Hue(t){const e=J5(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 qn(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return n},[e])}function Kue(t){const e=Bue(),n=J5(t==null?[]:Array.isArray(t)?t:[t]);return w.useMemo(()=>Uue(n,e),[n,e])}var Ob="Popover",[eF,xge]=ba(Ob,[cm]),_d=cm(),[Wue,Ai]=eF(Ob),tF=t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=t,a=_d(e),l=w.useRef(null),[c,u]=w.useState(!1),[h=!1,p]=Ti({prop:r,defaultProp:o,onChange:s});return d.jsx(ob,{...a,children:d.jsx(Wue,{scope:e,contentId:ps(),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})})};tF.displayName=Ob;var nF="PopoverAnchor",Gue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Ai(nF,n),s=_d(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=o;return w.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(sb,{...s,...r,ref:e})});Gue.displayName=nF;var rF="PopoverTrigger",oF=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Ai(rF,n),s=_d(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":cF(o.open),...r,ref:i,onClick:oe(t.onClick,o.onOpenToggle)});return o.hasCustomAnchor?a:d.jsx(sb,{asChild:!0,...s,children:a})});oF.displayName=rF;var Db="PopoverPortal",[Vue,Yue]=eF(Db,{forceMount:void 0}),sF=t=>{const{__scopePopover:e,forceMount:n,children:r,container:o}=t,s=Ai(Db,e);return d.jsx(Vue,{scope:e,forceMount:n,children:d.jsx(uo,{present:n||s.open,children:d.jsx(xd,{asChild:!0,container:o,children:r})})})};sF.displayName=Db;var Fl="PopoverContent",iF=w.forwardRef((t,e)=>{const n=Yue(Fl,t.__scopePopover),{forceMount:r=n.forceMount,...o}=t,s=Ai(Fl,t.__scopePopover);return d.jsx(uo,{present:r||s.open,children:s.modal?d.jsx(Xue,{...o,ref:e}):d.jsx(que,{...o,ref:e})})});iF.displayName=Fl;var Xue=w.forwardRef((t,e)=>{const n=Ai(Fl,t.__scopePopover),r=w.useRef(null),o=Qe(e,r),s=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return O1(i)},[]),d.jsx(Zg,{as:ca,allowPinchZoom:!0,children:d.jsx(aF,{...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})})})}),que=w.forwardRef((t,e)=>{const n=Ai(Fl,t.__scopePopover),r=w.useRef(!1),o=w.useRef(!1);return d.jsx(aF,{...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()}})}),aF=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=Ai(Fl,n),f=_d(n);return j1(),d.jsx(Xg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(vd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:d.jsx(dL,{"data-state":cF(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)"}})})})}),lF="PopoverClose",Zue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=Ai(lF,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});Zue.displayName=lF;var Que="PopoverArrow",Jue=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,o=_d(n);return d.jsx(hL,{...o,...r,ref:e})});Jue.displayName=Que;function cF(t){return t?"open":"closed"}var Rb=tF,Lb=oF,$b=sF,Fb=iF;function Nb({id:t,children:e,onOpenChange:n,open:r}){const[o,s]=Es(t,n);return d.jsx(Rb,{onOpenChange:s,open:r||o,children:d.jsx("div",{className:"tlui-popover",children:e})})}function zb({children:t}){return d.jsx(Lb,{asChild:!0,dir:"ltr",children:t})}function Bb({side:t,children:e,align:n="center",sideOffset:r=8,alignOffset:o=0,disableEscapeKeyDown:s=!1}){const i=Mt();return d.jsx($b,{container:i,children:d.jsx(Fb,{className:"tlui-popover__content",side:t,sideOffset:r,align:n,alignOffset:o,dir:"ltr",onEscapeKeyDown:a=>s&&a.preventDefault(),children:e})})}function ede(t){return t.getSelectedShapeIds().map(r=>t.getShape(r)).filter(r=>{if(!r)return!1;if(t.isShapeOfType(r,"arrow")){const o=Bn(t,r);if(o.start||o.end)return!1}return!0})}const uF=()=>{const t=z();return H("threeStackableItems",()=>ede(t).length>2,[t])},ks=()=>{const t=z();return H("isInSelectState",()=>t.isIn("select"),[t])},dF=()=>{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=Bn(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])},hF=()=>{const t=z();return H("allowUngroup",()=>t.getSelectedShapeIds().some(e=>{var n;return((n=t.getShape(e))==null?void 0:n.type)==="group"}),[t])},tde=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function pF(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 nde(){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 fF(){const t=z();return H("hasLinkShapeSelected",()=>{const e=t.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[t])}function rde(){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 gF(){const t=z();return H("useCanRedo",()=>t.getCanRedo(),[t])}function mF(){const t=z();return H("useCanUndo",()=>t.getCanUndo(),[t])}function ode(){return d.jsxs(d.Fragment,{children:[d.jsx(sde,{}),d.jsx(ide,{}),d.jsx(ade,{}),d.jsx(lde,{}),d.jsx(cde,{}),d.jsx(hde,{}),d.jsx(pde,{}),d.jsx(fde,{})]})}function sde(){const t=An(2),e=ks(),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 ide(){const t=An(3),e=ks(),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 ade(){const t=uF(),e=ks(),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 lde(){const t=An(1),e=ks(),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 cde(){return Mn()<St.TABLET_SM?d.jsx(ude,{}):d.jsx(dde,{})}function ude(){const t=z(),e=H("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(K,{actionId:"zoom-to-100",disabled:e})}function dde(){const t=An(1),e=ks(),n=t&&e;return d.jsx(K,{actionId:"rotate-ccw",disabled:!n})}function hde(){const t=An(1),e=ks(),n=t&&e;return d.jsx(K,{actionId:"rotate-cw",disabled:!n})}function pde(){const t=fF(),e=ks(),n=t&&e;return d.jsx(K,{actionId:"edit-link",disabled:!n})}function fde(){const t=dF(),e=hF();return t?d.jsx(YE,{}):e?d.jsx(gde,{}):d.jsx(YE,{})}function YE(){const t=An(2),e=ks(),n=t&&e;return d.jsx(K,{actionId:"group",disabled:!n})}function gde(){return d.jsx(K,{actionId:"ungroup"})}const mde=w.memo(function({children:e}){const n=Ce(),r=Mn(),o=wr(),s=w.useRef(null);ki(s);const i=z(),a=H("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),l=e??d.jsx(ode,{});if(!(o&&!a))return d.jsxs(Nb,{id:"actions-menu",children:[d.jsx(zb,{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(Bb,{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($r,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function ve({id:t,label:e,children:n}){const{type:r,sourceId:o}=fm(),s=Ce(),i=Hu(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(Aae,{"data-testid":`${o}-group.${t}`,children:n});case"context-menu":return d.jsx(d$,{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 er({id:t,disabled:e=!1,label:n,size:r="small",children:o}){const{type:s,sourceId:i}=fm(),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(kae,{id:`${i}-sub.${t}`,children:[d.jsx(Tae,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:e,label:u,title:u}),d.jsx(Mae,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return e?null:d.jsxs(yde,{id:`${i}-sub.${t}`,children:[d.jsx(g$,{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(gb,{container:a,children:d.jsx(m$,{"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 yde({id:t,children:e}){const[n,r]=Es(t);return d.jsx(f$,{open:n,onOpenChange:r,children:e})}function yF(){return nde()?d.jsx(K,{actionId:"toggle-auto-size"}):null}function SF(){return fF()?d.jsx(K,{actionId:"edit-link"}):null}function Sde(){return An(1)?d.jsx(K,{actionId:"duplicate"}):null}function vF(){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 xF(){return dF()?d.jsx(K,{actionId:"group"}):null}function wF(){return hF()?d.jsx(K,{actionId:"ungroup"}):null}function bF(){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 PF(){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 CF(){const t=z();return H("selected shapes",()=>t.getSelectedShapes().length>0,[t])?d.jsx(K,{actionId:"toggle-lock"}):null}function Ub(){const t=z(),e=H("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(po,{actionId:"toggle-transparent",checked:e,toggle:!0})}function vde(){const t=z(),e=H("any shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(K,{actionId:"unlock-all",disabled:!e})}function _F(){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 IF(){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 EF(){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 kF(){return d.jsxs(ve,{id:"clipboard",children:[d.jsx(wde,{}),d.jsx(bde,{}),d.jsx(Pde,{}),d.jsx(Sde,{}),d.jsx(Cde,{})]})}function xde(){var n;const t=z(),e=H("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsxs(er,{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(Ub,{})})]})}function wde(){const t=An(1);return d.jsx(K,{actionId:"cut",disabled:!t})}function bde(){const t=pF(1);return d.jsx(K,{actionId:"copy",disabled:!t})}function Pde(){const t=tde;return d.jsx(K,{actionId:"paste",disabled:!t})}function TF(){const t=z();return H("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t])?d.jsxs(ve,{id:"conversions",children:[d.jsx(xde,{}),d.jsxs(er,{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(Ub,{})})]})]}):null}function MF(){const t=z(),e=H("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(K,{actionId:"select-all",disabled:!e})}function Cde(){const t=An(1);return d.jsx(K,{actionId:"delete",disabled:!t})}function _de(){const t=wr();return!pF(1)||t?null:d.jsxs(er,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(xF,{}),d.jsx(wF,{}),d.jsx(vF,{}),d.jsx(SF,{}),d.jsx(PF,{}),d.jsx(bF,{}),d.jsx(jF,{}),d.jsx(AF,{}),d.jsx(yF,{}),d.jsx(CF,{})]})}function Ide(){const t=An(2),e=rde();return wr()||!(t||e)?null:d.jsxs(er,{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(Ede,{}),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(kde,{})]})}function Ede(){return An(3)?d.jsxs(ve,{id:"distribute",children:[d.jsx(K,{actionId:"distribute-horizontal"}),d.jsx(K,{actionId:"distribute-vertical"})]}):null}function kde(){const t=An(2),e=uF();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 Tde(){const t=wr(),e=An(1);return t||!e?null:d.jsx(er,{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"})]})})}function Mde(){const t=z(),e=H("pages",()=>t.getPages(),[t]),n=H("current page id",()=>t.getCurrentPageId(),[t]),{addToast:r}=Uo(),o=Qt(),s=wr();return!An(1)||s?null:d.jsxs(er,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ve,{id:"pages",children:e.map(a=>d.jsx(Kt,{id:a.id,disabled:n===a.id,label:a.name.length>30?`${a.name.slice(0,30)}…`:a.name,onSelect:()=>{t.markHistoryStoppingPoint("move_shapes_to_page"),t.moveShapesToPage(t.getSelectedShapeIds(),a.id);const l=t.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{t.markHistoryStoppingPoint("change-page"),t.setCurrentPage(n)}}]}),o("move-to-page",{source:"context-menu"})}},a.id))}),d.jsx(ve,{id:"new-page",children:d.jsx(K,{actionId:"move-to-new-page"})})]})}function AF(){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 jF(){const t=z(),e=G1();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 Ade(){const t=z(),e=H("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(po,{actionId:"toggle-snap-mode",checked:e})}function jde(){const t=z(),e=H("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(po,{actionId:"toggle-tool-lock",checked:e})}function Ode(){const t=z(),e=H("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(po,{actionId:"toggle-grid",checked:e})}function Dde(){const t=z(),e=H("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(po,{actionId:"toggle-wrap-mode",checked:e})}function Rde(){const t=z(),e=H("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(po,{actionId:"toggle-focus-mode",checked:e})}function Lde(){const t=z(),e=H("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(po,{actionId:"toggle-edge-scrolling",checked:e===1})}function $de(){const t=z(),e=H("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(po,{actionId:"toggle-reduce-motion",checked:e===0})}function Fde(){const t=z(),e=H("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(po,{actionId:"toggle-debug-mode",checked:e})}function Nde(){const t=z(),e=H("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(po,{actionId:"toggle-dynamic-size-mode",checked:e})}function zde(){const t=z(),e=H("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(po,{actionId:"toggle-paste-at-cursor",checked:e})}function Bde(){const t=z();return H("show cursor chat",()=>t.getCurrentToolId()==="select"&&!t.getInstanceState().isCoarsePointer,[t])?d.jsx(K,{actionId:"open-cursor-chat"}):null}function Ude(){const t=z(),e=sm(),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(Bde,{}),d.jsxs(ve,{id:"modify",children:[d.jsx(_de,{}),d.jsx(Ide,{}),d.jsx(Tde,{}),!r&&d.jsx(Mde,{})]}),d.jsx(kF,{}),d.jsx(TF,{}),d.jsx(ve,{id:"select-all",children:d.jsx(MF,{})})]}):null}const Hde=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(m=>h.includes(m))){const m=f.filter(g=>r.isShapeOrAncestorLocked(g));m.length&&r.select(...m.map(g=>g.id))}}}else{const h=r.getOnlySelectedShape();h&&r.isShapeOrAncestorLocked(h)&&r.setSelectedShapes([])}},[r]),i=Mt(),[a,l]=Es("context menu",s),c=e??d.jsx(Ude,{});return d.jsxs(Vie,{dir:"ltr",onOpenChange:l,modal:!1,children:[d.jsx(Yie,{onContextMenu:void 0,dir:"ltr",disabled:n,children:o?d.jsx(o,{}):null}),a&&d.jsx(Xie,{container:i,children:d.jsx(qie,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:xe,children:d.jsx($r,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),Kde=2e3,Wde=5e3,Gde=$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?Wde: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(Yde,{value:s,setValue:i,chatMessage:r}):r.trim()?d.jsx(Vde,{chatMessage:r}):null});function OF(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 Vde=({chatMessage:t})=>{const e=z(),n=w.useRef(null);return OF(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:t})},Yde=$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");OF(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:m}=f;switch(p.key){case"Enter":{if(xe(p),p.stopPropagation(),!m){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 c0({checked:t}){return d.jsx(Lo,{icon:t?"check":"none",className:"tlui-button__icon",small:!0})}function Xde(){const t=z(),{addToast:e}=Uo(),{addDialog:n}=Pa(),[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(Qde,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),d.jsx(Kt,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>Jde(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:pj,label:"Hard reset"})]}),d.jsxs(ve,{id:"flags",children:[d.jsx(qde,{}),d.jsx(Zde,{})]})]})}function qde(){const t=Object.values(bt);return t.length?d.jsx(er,{id:"debug flags",label:"Debug Flags",children:d.jsx(ve,{id:"debug flags",children:t.map(e=>d.jsx(DF,{flag:e},e.name))})}):null}function Zde(){const t=Object.values(eX);return t.length?d.jsx(er,{id:"feature flags",label:"Feature Flags",children:d.jsx(ve,{id:"feature flags",children:t.map(e=>d.jsx(DF,{flag:e},e.name))})}):null}function Qde({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(tm,{children:[d.jsx(nm,{children:t}),d.jsx(rm,{})]}),d.jsx(Uu,{style:{maxWidth:350},children:e}),d.jsxs(K1,{className:"tlui-dialog__footer__actions",children:[o&&d.jsxs(ce,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(c0,{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 DF=$t(function({flag:e,onChange:n}){const r=e.get();return d.jsx(gm,{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 XE=0;function Jde(t,e){const n=Array(e),r=Math.floor(Math.sqrt(e));for(let o=0;o<e;o++)XE++,n[o]={id:Ke("box"+XE),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};t.run(()=>{t.createShapes(n).setSelectedShapes(n.map(o=>o.id))})}function ehe({children:t}){const e=t??d.jsx(Xde,{});return d.jsxs(ha,{id:"debug",children:[d.jsx(pa,{children:d.jsx(ce,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(fa,{side:"top",align:"end",alignOffset:0,children:d.jsx($r,{type:"menu",sourceId:"debug-panel",children:e})})]})}const the=w.memo(function(){const{DebugMenu:e}=ji(),n=w.useRef(null);return ki(n),d.jsxs("div",{ref:n,className:"tlui-debug-panel",children:[d.jsx(rhe,{}),d.jsx(ohe,{}),e&&d.jsx(e,{})]})});function nhe(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 rhe=$t(function(){nhe();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 ohe(){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 she=w.memo(function(){const e=Mn(),n=w.useRef(null);ki(n);const{MainMenu:r,QuickActions:o,ActionsMenu:s,PageMenu:i}=ji(),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 ihe(){const t=z(),e=Ca(),[n,r]=w.useState(!1),o=w.useRef(!1);return ii("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 ahe(){const t=z();return H("is pen mode",()=>t.getInstanceState().isPenMode,[t])?d.jsx(K,{actionId:"exit-pen-mode"}):null}function lhe(){const t=z(),e=Ca();return H("is following user",()=>!!t.getInstanceState().followingUserId,[t])?d.jsx(Kt,{...e["stop-following"]}):null}function che(){return d.jsxs(d.Fragment,{children:[d.jsx(ahe,{}),d.jsx(ihe,{}),d.jsx(lhe,{})]})}function uhe({children:t}){const e=t??d.jsx(che,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx($r,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function dhe(){const t=sm();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 hhe=w.memo(function({children:e}){const n=Ce(),r=Mn(),o=e??d.jsx(dhe,{});return d.jsxs(d.Fragment,{children:[d.jsxs(tm,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(nm,{children:n("shortcuts-dialog.title")}),d.jsx(rm,{})]}),d.jsx(Uu,{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($r,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})}),phe=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function fhe(){const t=z(),e=Qt(),n=H("colorScheme",()=>t.user.getUserPreferences().colorScheme??(t.user.getIsDarkMode()?"dark":"light"),[t]);return d.jsx(er,{id:"help menu color-scheme",label:"menu.theme",children:d.jsx(ve,{id:"theme",children:phe.map(({colorScheme:r,label:o})=>d.jsx(gm,{id:`color-scheme-${r}`,label:o,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({colorScheme:r}),e("color-scheme",{source:"menu",value:r})}},r))})})}function RF(){const t=z(),e=Qt(),n=H("locale",()=>t.user.getLocale(),[t]);return d.jsx(er,{id:"help menu language",label:"menu.language",children:d.jsx(ve,{id:"languages",children:Nu.map(({locale:r,label:o})=>d.jsx(gm,{id:`language-${r}`,title:r,label:o,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})})}function ghe(){return d.jsxs(d.Fragment,{children:[d.jsx(RF,{}),d.jsx(LF,{})]})}function LF(){const{KeyboardShortcutsDialog:t}=ji(),{addDialog:e}=Pa(),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 mhe(){return d.jsxs(d.Fragment,{children:[d.jsx(She,{}),d.jsx(bhe,{}),d.jsx(yhe,{}),d.jsx(Phe,{}),d.jsx(Che,{})]})}function yhe(){return d.jsxs(er,{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(Ub,{})})]})}function She(){const t=z(),e=H("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]);return d.jsxs(er,{id:"edit",label:"menu.edit",disabled:!e,children:[d.jsx(whe,{}),d.jsx(kF,{}),d.jsx(TF,{}),d.jsx(vhe,{}),d.jsx(xhe,{}),d.jsx(ve,{id:"select-all",children:d.jsx(MF,{})})]})}function vhe(){return d.jsxs(ve,{id:"misc",children:[d.jsx(xF,{}),d.jsx(wF,{}),d.jsx(SF,{}),d.jsx(yF,{}),d.jsx(bF,{}),d.jsx(PF,{}),d.jsx(jF,{}),d.jsx(AF,{}),d.jsx(vF,{})]})}function xhe(){return d.jsxs(ve,{id:"lock",children:[d.jsx(CF,{}),d.jsx(vde,{})]})}function whe(){const t=mF(),e=gF();return d.jsxs(ve,{id:"undo-redo",children:[d.jsx(K,{actionId:"undo",disabled:!t}),d.jsx(K,{actionId:"redo",disabled:!e})]})}function bhe(){return d.jsx(er,{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(_F,{}),d.jsx(IF,{}),d.jsx(EF,{})]})})}function Phe(){return d.jsxs(ve,{id:"extras",children:[d.jsx(K,{actionId:"insert-embed"}),d.jsx(K,{actionId:"insert-media"})]})}function Che(){return d.jsxs(ve,{id:"preferences",children:[d.jsxs(er,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ve,{id:"preferences-actions",children:[d.jsx(Ade,{}),d.jsx(jde,{}),d.jsx(Ode,{}),d.jsx(Dde,{}),d.jsx(Rde,{}),d.jsx(Lde,{}),d.jsx($de,{}),d.jsx(Nde,{}),d.jsx(zde,{}),d.jsx(Fde,{})]}),d.jsx(ve,{id:"color-scheme",children:d.jsx(fhe,{})})]}),d.jsx(RF,{}),d.jsx(LF,{})]})}const _he=w.memo(function({children:e}){const n=Mt(),[r,o]=Es("main menu"),s=Ce(),i=e??d.jsx(mhe,{});return d.jsxs(yb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(Sb,{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(pm,{container:n,children:d.jsx(vb,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx($r,{type:"menu",sourceId:"main-menu",children:i})})})]})}),CS={};function Dc(t){if(CS[t])return CS[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 CS[t]=a,a}const Dp=10,$F=4*6*Dp+12+4*12;function za(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 Ba(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 Ihe(t,e,n){const r=Dp;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 za(t,{center:e.center,radius:n,numArcSegments:Dp*4}),Dp*4*6;let s=0;return Ba(t,s,o.minX,o.minY,o.w,o.h),s+=12,Ba(t,s,o.minX,e.minY,o.w,n),s+=12,Ba(t,s,o.maxX,o.minY,n,o.h),s+=12,Ba(t,s,o.minX,o.maxY,o.w,n),s+=12,Ba(t,s,e.minX,o.minY,n,o.h),s+=12,za(t,{numArcSegments:r,offset:s,center:o.point,radius:n,startAngle:De,endAngle:De*1.5}),s+=r*6,za(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,za(t,{numArcSegments:r,offset:s,center:x.Add(o.point,o.size),radius:n,startAngle:0,endAngle:Ze}),s+=r*6,za(t,{numArcSegments:r,offset:s,center:x.Add(o.point,new x(0,o.h)),radius:n,startAngle:Ze,endAngle:De}),$F}function Ehe(t){if(!t)throw new Error("Canvas element not found");const e=t.getContext("webgl2",{premultipliedAlpha:!1});if(!e)throw new Error("Failed to get webgl2 context");const n=`#version 300 es
|
|
384
|
-
precision mediump float;
|
|
385
|
-
|
|
386
|
-
in vec2 shapeVertexPosition;
|
|
387
|
-
|
|
388
|
-
uniform vec4 canvasPageBounds;
|
|
389
|
-
|
|
390
|
-
// taken (with thanks) from
|
|
391
|
-
// https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
|
|
392
|
-
void main() {
|
|
393
|
-
// convert the position from pixels to 0.0 to 1.0
|
|
394
|
-
vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
|
|
395
|
-
|
|
396
|
-
// convert from 0->1 to 0->2
|
|
397
|
-
vec2 zeroToTwo = zeroToOne * 2.0;
|
|
398
|
-
|
|
399
|
-
// convert from 0->2 to -1->+1 (clipspace)
|
|
400
|
-
vec2 clipSpace = zeroToTwo - 1.0;
|
|
401
|
-
|
|
402
|
-
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
403
|
-
}`,r=e.createShader(e.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const o=`#version 300 es
|
|
404
|
-
precision mediump float;
|
|
405
|
-
|
|
406
|
-
uniform vec4 fillColor;
|
|
407
|
-
out vec4 outputColor;
|
|
408
|
-
|
|
409
|
-
void main() {
|
|
410
|
-
outputColor = fillColor;
|
|
411
|
-
}`,s=e.createShader(e.FRAGMENT_SHADER);if(!s)throw new Error("Failed to create fragment shader");if(e.shaderSource(s,o),e.compileShader(s),!e.getShaderParameter(s,e.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=e.createProgram();if(!i)throw new Error("Failed to create program");if(e.attachShader(i,r),e.attachShader(i,s),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(i);const a=e.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(i,"canvasPageBounds"),c=e.getUniformLocation(i,"fillColor");if(!e.createBuffer())throw new Error("Failed to create buffer");if(!e.createBuffer())throw new Error("Failed to create buffer");return{context:e,selectedShapes:$h(e,1024),unselectedShapes:$h(e,4096),viewport:$h(e,$F),collaborators:$h(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 $h(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(e)}}function qE(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 khe=Object.create,FF=Object.defineProperty,The=Object.getOwnPropertyDescriptor,Mhe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),NF=t=>{throw TypeError(t)},zF=(t,e,n)=>e in t?FF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ahe=t=>[,,,khe(null)],BF=["class","method","getter","setter","accessor","field","value","get","set"],UF=t=>t!==void 0&&typeof t!="function"?NF("Function expected"):t,jhe=(t,e,n,r,o)=>({kind:BF[t],name:e,metadata:r,addInitializer:s=>n._?NF("Already initialized"):o.push(UF(s||null))}),Ohe=(t,e)=>zF(e,Mhe("metadata"),t[3]),Dhe=(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},Ko=(t,e,n,r,o,s)=>{for(var i,a,l,c,u=e&7,h=!!(e&8),p=!!(e&16),f=2,m=BF[u+5],g=t[f]||(t[f]=[]),v=(o=o.prototype,The(o,n)),S=r.length-1;S>=0;S--)l=jhe(u,n,a={},t[3],g),l.static=h,l.private=p,c=l.access={has:y=>n in y},c.get=y=>y[n],i=(0,r[S])(v[m],l),a._=1,UF(i)&&(v[m]=i);return v&&FF(o,n,v),o},Zo=(t,e,n)=>zF(t,typeof e!="symbol"?e+"":e,n),HF,KF,WF,GF,VF,YF,XF,qF,ZF,QF,br;QF=[Hn],ZF=[W],qF=[W],XF=[W],YF=[W],VF=[W],GF=[W],WF=[W],KF=[W],HF=[Hn];class zr{constructor(e,n,r){this.editor=e,this.elem=n,this.container=r,Dhe(br,5,this),Zo(this,"disposables",[]),Zo(this,"gl"),Zo(this,"shapeGeometryCache"),Zo(this,"colors"),Zo(this,"id",ze()),Zo(this,"canvasBoundingClientRect",Et("canvasBoundingClientRect",new Z)),Zo(this,"originPagePoint",new x),Zo(this,"originPageCenter",new x),Zo(this,"isInViewport",!1),this.gl=Ehe(n),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",o=>{const s=e.getShapeMaskedPageBounds(o.id);if(!s)return null;const i=new Float32Array(12);return Ba(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),Mo("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Dc(e.getPropertyValue("--color-text-3").trim()),selectFill:Dc(e.getPropertyValue("--color-selected").trim()),viewportFill:Dc(e.getPropertyValue("--color-muted-1").trim()),background:Dc(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,m=Math.max(0,u+i.width-a),g=Math.max(0,-(h-i.width-a)),v=Math.max(0,p+i.height-l),S=Math.max(0,-(f-i.height-l));a+=(m-g)/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)?(qE(this.gl.selectedShapes,s,h),s+=p):(qE(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=Ihe(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)za(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(Dc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}br=Ahe();Ko(br,1,"close",QF,zr);Ko(br,1,"getDpr",ZF,zr);Ko(br,1,"getContentPageBounds",qF,zr);Ko(br,1,"getContentScreenBounds",XF,zr);Ko(br,1,"getCanvasSize",YF,zr);Ko(br,1,"getCanvasClientPosition",VF,zr);Ko(br,1,"getCanvasPageBounds",GF,zr);Ko(br,1,"getZoom",WF,zr);Ko(br,1,"getCanvasPageBoundsArray",KF,zr);Ko(br,1,"render",HF,zr);Ohe(br,zr);function Rhe(){const t=z(),e=Mt(),n=w.useRef(null),r=w.useRef(!1),o=w.useRef();w.useEffect(()=>{try{const u=new zr(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(cd(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(),m=o.current.getContentPageBounds();if(new Z(m.x-f.width/2,m.y-f.height/2,m.width+f.width,m.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&&ud(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 g=o.current.originPagePoint.clone().sub(o.current.originPageCenter);t.centerOnPoint(x.Sub(h,g));return}t.centerOnPoint(h)}const p=o.current.getMinimapPagePoint(u.clientX,u.clientY),f=t.pageToScreen(p),m={type:"pointer",target:"canvas",name:"pointer_move",...Wn(u),point:f,isPen:t.getInstanceState().isPenMode};t.dispatch(m)},[t]),l=w.useCallback(u=>{const h=nj(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=Sd();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 Lhe(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 $he=w.memo(function(){const e=Ca(),n=Ce(),r=Mn(),o=w.useRef(null);ki(o);const[s,i]=Lhe("minimap",!0),a=w.useCallback(()=>{i(u=>!u)},[i]),{ZoomMenu:l,Minimap:c}=ji();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(Hu(e["zoom-out"].label))} ${Wx(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(Hu(e["zoom-in"].label))} ${Wx(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,{})]})}),Fhe=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(om,{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})},u0=(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=Co(a.index):!a&&l?s=Z9(i[0].index):s=Ru(a.index,l.index),s!==i[n].index&&(t.markHistoryStoppingPoint("moving page"),t.updatePage({id:e,index:s}),o("move-page",{source:"page-menu"}))},ZE=$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(()=>{u0(s,r.id,e,e-1,l)},[s,r,e,l]),h=w.useCallback(()=>{u0(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(ha,{id:`page item submenu ${e}`,children:[d.jsx(pa,{children:d.jsx(ce,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical"})})}),d.jsx(fa,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs($r,{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"})})]})})]})}),Nhe=w.memo(function(){const e=z(),n=Qt(),r=Ce(),o=Mn(),s=w.useCallback(()=>S(!1),[]),[i,a]=Es("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=wr(),m=H("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),g=H("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[v,S]=w.useState(!1),y=w.useCallback(()=>{f||S(O=>!O)},[f]),P=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[b,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 $=P.current;cd(O.currentTarget,O),$.status="pointing",$.pointing={id:L,index:+G};const Y=b[L].y;$.startY=R,$.startIndex=Math.max(0,Math.min(Math.round(Y/l),u.length-1))},[l,u.length,b]),k=w.useCallback(O=>{const R=P.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=b[R.pointing.id],{startIndex:$,pointing:U}=R,Y=G.y+L,ee=Math.max(0,Math.min(Math.round(Y/l),u.length-1)),he={...b};if(he[U.id]={y:G.y,offsetY:L,isSelected:!0},ee!==R.dragIndex){R.dragIndex=ee;for(let ue=0;ue<u.length;ue++){const ke=u[ue];if(ke.id===R.pointing.id)continue;let{y:se}=he[ke.id];ee===$?se=ue*l:ee<$?ee<=ue&&ue<$?se=(ue+1)*l:se=ue*l:ee>$&&(ee>=ue&&ue>$?se=(ue-1)*l:se=ue*l),se!==he[ke.id].y&&(he[ke.id]={y:se,offsetY:0,isSelected:!0})}}C(he)}},[l,u,b]),_=w.useCallback(O=>{const R=P.current;if(R.status==="dragging"){const{id:B,index:L}=R.pointing;u0(e,B,L,R.dragIndex,n)}ud(O.currentTarget,O),R.status="idle"},[e,n]),M=w.useCallback(O=>{const R=P.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]),T=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]),A=w.useCallback((O,R)=>{e.renamePage(O,R),n("rename-page",{source:"page-menu"})},[e,n]);return d.jsxs(Nb,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(zb,{"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(Bb,{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(m?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:m,onClick:T,children:d.jsx(be,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((O,R)=>{const B=b[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:M,"data-id":O.id,"data-index":R,children:d.jsx(be,{icon:"drag-handle-dots"})}),o<St.TABLET_SM&&g?d.jsxs(ce,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const L=window.prompt("Rename page",O.name);L&&L!==O.name&&A(O.id,L)},onDoubleClick:y,children:[d.jsx(c0,{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(Fhe,{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(ZE,{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(c0,{checked:O.id===h.id}),d.jsx(Pt,{children:O.name})]}),!f&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(ZE,{index:R,item:O,listSize:u.length,onRename:()=>{if(Ge.isIos){const L=window.prompt("Rename page",O.name);L&&L!==O.name&&A(O.id,L)}else S(!0),p!==O.id&&D(O.id)}})})]},O.id)})})]})})]})});function zhe(){const t=z(),e=mF(),n=gF(),r=An(1),o=wr(),s=H("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]),i=ks(),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 Bhe=w.memo(function({children:e}){const n=e??d.jsx(zhe,{});return d.jsx($r,{type:"small-icons",sourceId:"quick-actions",children:n})});function Uhe({userId:t}){const e=jg(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 Hhe=$t(function({userId:e}){const n=z(),r=Ce(),o=Qt(),s=jg(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(Lo,{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 Whe=$t(function(){const e=z(),n=Mt(),r=Ce(),o=Qt(),s=w.useRef(!1),[i,a]=w.useState(!1),l=w.useCallback(g=>{a(g)},[]),c=e.user.getColor(),u=w.useCallback(g=>{e.user.updateUserPreferences({color:g}),o("set-color",{source:"people-menu"})},[e,o]),{handleButtonClick:h,handleButtonPointerDown:p,handleButtonPointerEnter:f,handleButtonPointerUp:m}=Te.useMemo(()=>{const g=()=>{s.current=!1,window.removeEventListener("pointerup",g)};return{handleButtonClick:b=>{const{id:C}=b.currentTarget.dataset;C&&c!==C&&u(C)},handleButtonPointerDown:b=>{const{id:C}=b.currentTarget.dataset;C&&(u(C),s.current=!0,window.addEventListener("pointerup",g))},handleButtonPointerEnter:b=>{if(!s.current)return;const{id:C}=b.currentTarget.dataset;C&&u(C)},handleButtonPointerUp:b=>{const{id:C}=b.currentTarget.dataset;C&&u(C)}}},[c,u]);return d.jsxs(Rb,{onOpenChange:l,open:i,children:[d.jsx(Lb,{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($b,{container:n,children:d.jsx(Fb,{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:yx.map(g=>d.jsx(ce,{type:"icon","data-id":g,"data-testid":g,"aria-label":g,"data-state":c===g?"hinted":void 0,title:g,className:"tlui-button-grid__button",style:{color:g},onPointerEnter:f,onPointerDown:p,onPointerUp:m,onClick:h,children:d.jsx(be,{icon:"color"})},g))})})})]})});function Ghe(){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(Whe,{}),i?d.jsx(om,{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 Vhe=$t(function({children:e}){const n=Ce(),r=Mt(),o=z(),s=sj(),i=H("user",()=>o.user.getColor(),[o]),a=H("user",()=>o.user.getName(),[o]),[l,c]=Es("people menu");return d.jsxs(Rb,{onOpenChange:c,open:l,children:[d.jsx(Lb,{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(Uhe,{userId:u},u)),d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx($b,{container:r,children:d.jsx(Fb,{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(Ghe,{})}),s.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:s.map(u=>d.jsx(Hhe,{userId:u},u+"_presence"))}),e]})})})]})});function Yhe(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(Vhe,{})})}const Xhe=Object.freeze([mr,ia,aa,Ro]);function JF(t=Xhe){const e=z();return H("getRelevantStyles",()=>{var s;const n=new Px(e.getSharedStyles()),r=!!((s=e.root.getCurrent())!=null&&s.shapeType),o=e.isIn("select")&&e.getSelectedShapeIds().length>0;if(n.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const i of t)n.applyValue(i,e.getStyleForNextShape(i));return r||o||n.size>0?n:null},[e])}const jr={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},Gi=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:m,handleButtonPointerEnter:g,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:g,onPointerDown:m,onPointerUp:v,onClick:f,children:d.jsx(be,{icon:S.icon})},S.value))})});function e4(t,[e,n]){return Math.min(n,Math.max(e,t))}function qhe(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 t4=["PageUp","PageDown"],n4=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],r4={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},sc="Slider",[d0,Zhe,Qhe]=Qg(sc),[o4,wge]=ba(sc,[Qhe]),[Jhe,_m]=o4(sc),s4=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:m,...g}=t,v=w.useRef(new Set),S=w.useRef(0),P=i==="horizontal"?epe:tpe,[b=[],C]=Ti({prop:u,defaultProp:c,onChange:D=>{var O;(O=[...v.current][S.current])==null||O.focus(),h(D)}}),I=w.useRef(b);function k(D){const A=ipe(b,D);T(D,A)}function _(D){T(D,S.current)}function M(){const D=I.current[S.current];b[S.current]!==D&&p(b)}function T(D,A,{commit:O}={commit:!1}){const R=upe(s),B=dpe(Math.round((D-r)/s)*s+r,R),L=e4(B,[r,o]);C((G=[])=>{const $=ope(G,L,A);if(cpe($,l*s)){S.current=$.indexOf(L);const U=String($)!==String(G);return U&&O&&p($),U?$:G}else return G})}return d.jsx(Jhe,{scope:t.__scopeSlider,name:n,disabled:a,min:r,max:o,valueIndexToChangeRef:S,thumbs:v.current,values:b,orientation:i,form:m,children:d.jsx(d0.Provider,{scope:t.__scopeSlider,children:d.jsx(d0.Slot,{scope:t.__scopeSlider,children:d.jsx(P,{"aria-disabled":a,"data-disabled":a?"":void 0,...g,ref:e,onPointerDown:oe(g.onPointerDown,()=>{a||(I.current=b)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:k,onSlideMove:a?void 0:_,onSlideEnd:a?void 0:M,onHomeKeyDown:()=>!a&&T(r,0,{commit:!0}),onEndKeyDown:()=>!a&&T(o,b.length-1,{commit:!0}),onStepKeyDown:({event:D,direction:A})=>{if(!a){const B=t4.includes(D.key)||D.shiftKey&&n4.includes(D.key)?10:1,L=S.current,G=b[L],$=s*B*A;T(G+$,L,{commit:!0})}}})})})})});s4.displayName=sc;var[i4,a4]=o4(sc,{startEdge:"left",endEdge:"right",size:"width",direction:1}),epe=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,P=>p(P)),m=w.useRef(),g=Y1(o),v=g==="ltr",S=v&&!s||!v&&s;function y(P){const b=m.current||h.getBoundingClientRect(),C=[0,b.width],k=Hb(C,S?[n,r]:[r,n]);return m.current=b,k(P-b.left)}return d.jsx(i4,{scope:t.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width",children:d.jsx(l4,{dir:g,"data-orientation":"horizontal",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:P=>{const b=y(P.clientX);i==null||i(b)},onSlideMove:P=>{const b=y(P.clientX);a==null||a(b)},onSlideEnd:()=>{m.current=void 0,l==null||l()},onStepKeyDown:P=>{const C=r4[S?"from-left":"from-right"].includes(P.key);c==null||c({event:P,direction:C?-1:1})}})})}),tpe=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 m(g){const v=p.current||u.current.getBoundingClientRect(),S=[0,v.height],P=Hb(S,f?[r,n]:[n,r]);return p.current=v,P(g-v.top)}return d.jsx(i4,{scope:t.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:d.jsx(l4,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:g=>{const v=m(g.clientY);s==null||s(v)},onSlideMove:g=>{const v=m(g.clientY);i==null||i(v)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:g=>{const S=r4[f?"from-bottom":"from-top"].includes(g.key);l==null||l({event:g,direction:S?-1:1})}})})}),l4=w.forwardRef((t,e)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=t,u=_m(sc,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()):t4.concat(n4).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))})})}),c4="SliderTrack",u4=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=_m(c4,n);return d.jsx(Ae.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:e})});u4.displayName=c4;var h0="SliderRange",d4=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,o=_m(h0,n),s=a4(h0,n),i=w.useRef(null),a=Qe(e,i),l=o.values.length,c=o.values.map(p=>p4(p,o.min,o.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(Ae.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:a,style:{...t.style,[s.startEdge]:u+"%",[s.endEdge]:h+"%"}})});d4.displayName=h0;var p0="SliderThumb",h4=w.forwardRef((t,e)=>{const n=Zhe(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(npe,{...t,ref:s,index:i})}),npe=w.forwardRef((t,e)=>{const{__scopeSlider:n,index:r,name:o,...s}=t,i=_m(p0,n),a=a4(p0,n),[l,c]=w.useState(null),u=Qe(e,y=>c(y)),h=l?i.form||!!l.closest("form"):!0,p=tL(l),f=i.values[r],m=f===void 0?0:p4(f,i.min,i.max),g=spe(r,i.values.length),v=p==null?void 0:p[a.size],S=v?ape(v,m,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(${m}% + ${S}px)`},children:[d.jsx(d0.ItemSlot,{scope:t.__scopeSlider,children:d.jsx(Ae.span,{role:"slider","aria-label":t["aria-label"]||g,"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(rpe,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:f},r)]})});h4.displayName=p0;var rpe=t=>{const{value:e,...n}=t,r=w.useRef(null),o=qhe(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 ope(t=[],e,n){const r=[...t];return r[n]=e,r.sort((o,s)=>o-s)}function p4(t,e,n){const s=100/(n-e)*(t-e);return e4(s,[0,100])}function spe(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}function ipe(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 ape(t,e,n){const r=t/2,s=Hb([0,50],[0,r]);return(r-s(e)*n)*n}function lpe(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}function cpe(t,e){if(e>0){const n=lpe(t);return Math.min(...n)>=e}return!0}function Hb(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 upe(t){return(String(t).split(".")[1]||"").length}function dpe(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}var hpe=s4,ppe=u4,fpe=d4,gpe=h4;const mpe=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(hpe,{"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(ppe,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&d.jsx(fpe,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&d.jsx(gpe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function ype({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 g;return((g=s.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:g.icon)??"mixed"},[s,c]),m=w.useMemo(()=>{var g;return((g=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:g.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(ha,{id:`style panel ${e} A`,children:[d.jsx(pa,{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(fa,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map((g,v)=>d.jsx(Yu,{"data-testid":`style.${e}.${g.value}`,children:d.jsx(ce,{type:"icon",onClick:()=>h(a,g.value),title:`${p(r)} — ${p(`${e}-style.${g.value}`)}`,children:d.jsx(be,{icon:g.icon,invertIcon:!0})},g.value)},v))})})]}),d.jsxs(ha,{id:`style panel ${n}`,children:[d.jsx(pa,{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:m,small:!0})})}),d.jsx(fa,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(g=>d.jsx(Yu,{children:d.jsx(ce,{type:"icon",title:`${p(o)} — ${p(`${n}-style.${g.value}`)}`,"data-testid":`style.${n}.${g.value}`,onClick:()=>h(l,g.value),children:d.jsx(be,{icon:g.icon})})},g.value))})})]})]})]})}const Spe=w.memo(ype);function vpe({id:t,label:e,uiType:n,stylePanelType:r,style:o,items:s,type:i,value:a,onValueChange:l}){const c=Ce(),u=z(),h=w.useMemo(()=>{var g;return(g=s.find(v=>a.type==="shared"&&v.value===a.value))==null?void 0:g.icon},[s,a]),p=c(`style-panel.${r}`),f=a.type==="mixed"?c("style-panel.mixed"):p+" — "+c(`${n}-style.${a.value}`),m=e?c(e):"";return d.jsxs(ha,{id:`style panel ${t}`,children:[d.jsx(pa,{children:d.jsxs(ce,{type:i,"data-testid":`style.${n}`,title:f,children:[m&&d.jsx(Pt,{children:m}),d.jsx(be,{icon:h??"mixed"})]})}),d.jsx(fa,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map(g=>d.jsx(Yu,{children:d.jsx(ce,{type:"icon","data-testid":`style.${n}.${g.value}`,title:p+" — "+c(`${n}-style.${g.value}`),onClick:()=>{u.markHistoryStoppingPoint("select style dropdown item"),l(o,g.value)},children:d.jsx(be,{icon:g.icon})})},g.value))})})]})}const Kb=w.memo(vpe);function xpe({styles:t}){const e=Sd();if(!t)return null;const n=t.get(Zr),r=t.get(_f),o=t.get(Cf),s=t.get(Tf),i=t.get(Do),a=n===void 0,l=r===void 0&&o===void 0,c=s===void 0,u=i===void 0,h=Is({isDarkMode:e});return d.jsxs(d.Fragment,{children:[d.jsx(wpe,{theme:h,styles:t}),!u&&d.jsx(bpe,{theme:h,styles:t}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(Ppe,{styles:t}),d.jsx(_pe,{styles:t}),d.jsx(Cpe,{styles:t})]})]})}function Id(){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 wpe({styles:t,theme:e}){const n=Ce(),r=z(),o=w.useCallback(h=>r.markHistoryStoppingPoint(h),[r]),s=Id(),i=t.get(mr),a=t.get(aa),l=t.get(ia),c=t.get(Ro),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(Gi,{title:n("style-panel.color"),uiType:"color",style:mr,items:jr.color,value:i,onValueChange:s,theme:e,onHistoryMark:o}),d.jsx(Ipe,{})]}),u&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:d.jsx(Gi,{title:n("style-panel.fill"),uiType:"fill",style:aa,items:jr.fill,value:a,onValueChange:s,theme:e,onHistoryMark:o}),l===void 0?null:d.jsx(Gi,{title:n("style-panel.dash"),uiType:"dash",style:ia,items:jr.dash,value:l,onValueChange:s,theme:e,onHistoryMark:o}),c===void 0?null:d.jsx(Gi,{title:n("style-panel.size"),uiType:"size",style:Ro,items:jr.size,value:c,onValueChange:(h,p)=>{s(h,p);const f=r.getSelectedShapeIds();f.length>0&&Ye(r,f)},theme:e,onHistoryMark:o})]})]})}function bpe({theme:t,styles:e}){const n=Ce(),r=Id(),o=z(),s=w.useCallback(u=>o.markHistoryStoppingPoint(u),[o]),i=e.get(Do),a=e.get(hx),l=e.get(Ef),c=e.get(kf);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(Gi,{title:n("style-panel.font"),uiType:"font",style:Do,items:jr.font,value:i,onValueChange:r,theme:t,onHistoryMark:s}),a===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Gi,{title:n("style-panel.align"),uiType:"align",style:hx,items:jr.textAlign,value:a,onValueChange:r,theme:t,onHistoryMark:s}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(ce,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})})})]}),l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Gi,{title:n("style-panel.label-align"),uiType:"align",style:Ef,items:jr.horizontalAlign,value:l,onValueChange:r,theme:t,onHistoryMark:s}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?d.jsx(ce,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})}):d.jsx(Kb,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:kf,items:jr.verticalAlign,value:c,onValueChange:r})})]})]})}function Ppe({styles:t}){const e=Id(),n=t.get(Zr);return n===void 0?null:d.jsx(Kb,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:Zr,items:jr.geo,value:n,onValueChange:e})}function Cpe({styles:t}){const e=Id(),n=t.get(Tf);return n===void 0?null:d.jsx(Kb,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:Tf,items:jr.spline,value:n,onValueChange:e})}function _pe({styles:t}){const e=Id(),n=t.get(_f),r=t.get(Cf);return!n||!r?null:d.jsx(Spe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Cf,itemsA:jr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:_f,itemsB:jr.arrowheadEnd,valueB:n,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Rc=[.1,.25,.5,.75,1];function Ipe(){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=Rc[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:Rc.indexOf(x9(Rc,a=>Math.abs(a-n.value)));return d.jsx(mpe,{"data-testid":"style.opacity",value:i>=0?i:Rc.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:s,steps:Rc.length-1,title:o("style-panel.opacity"),onHistoryMark:e})}const Epe=w.memo(function({isMobile:e,children:n}){const r=z(),o=w.useRef(null);ki(o);const s=JF(),i=w.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=n??d.jsx(xpe,{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 kpe(){const t=z(),e=Ce(),n=JF(),r=n==null?void 0:n.get(mr),o=Is({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}=ji();return l?d.jsxs(Nb,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(zb,{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(Bb,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function Tpe(){return d.jsxs(d.Fragment,{children:[d.jsx(Ape,{}),d.jsx(jpe,{}),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,{}),d.jsx(Wpe,{}),d.jsx(Ype,{}),d.jsx(Hpe,{}),d.jsx(Vpe,{}),d.jsx(Gpe,{}),d.jsx(Kpe,{}),d.jsx(Xpe,{}),d.jsx(qpe,{}),d.jsx(Zpe,{}),d.jsx(Qpe,{}),d.jsx(Jpe,{}),d.jsx(efe,{}),d.jsx(tfe,{}),d.jsx(nfe,{}),d.jsx(ofe,{}),d.jsx(rfe,{})]})}function Mpe(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(Zr);return n?o==="geo"&&s===n:o===t.id},[e,t.id,n])}function Ve({tool:t}){const e=xb(),n=Mpe(e[t]);return d.jsx(Rn,{toolId:t,isSelected:n})}function Ape(){return d.jsx(Ve,{tool:"select"})}function jpe(){return d.jsx(Ve,{tool:"hand"})}function Ope(){return d.jsx(Ve,{tool:"draw"})}function Dpe(){return d.jsx(Ve,{tool:"eraser"})}function Rpe(){return d.jsx(Ve,{tool:"arrow"})}function Lpe(){return d.jsx(Ve,{tool:"text"})}function $pe(){return d.jsx(Ve,{tool:"note"})}function Fpe(){return d.jsx(Rn,{toolId:"asset"})}function Npe(){return d.jsx(Ve,{tool:"rectangle"})}function zpe(){return d.jsx(Ve,{tool:"ellipse"})}function Bpe(){return d.jsx(Ve,{tool:"diamond"})}function Upe(){return d.jsx(Ve,{tool:"triangle"})}function Hpe(){return d.jsx(Ve,{tool:"rhombus"})}function Kpe(){return d.jsx(Ve,{tool:"heart"})}function Wpe(){return d.jsx(Ve,{tool:"hexagon"})}function Gpe(){return d.jsx(Ve,{tool:"cloud"})}function Vpe(){return d.jsx(Ve,{tool:"star"})}function Ype(){return d.jsx(Ve,{tool:"oval"})}function Xpe(){return d.jsx(Ve,{tool:"x-box"})}function qpe(){return d.jsx(Ve,{tool:"check-box"})}function Zpe(){return d.jsx(Ve,{tool:"arrow-left"})}function Qpe(){return d.jsx(Ve,{tool:"arrow-up"})}function Jpe(){return d.jsx(Ve,{tool:"arrow-down"})}function efe(){return d.jsx(Ve,{tool:"arrow-right"})}function tfe(){return d.jsx(Ve,{tool:"line"})}function nfe(){return d.jsx(Ve,{tool:"highlight"})}function rfe(){return d.jsx(Ve,{tool:"frame"})}function ofe(){return d.jsx(Ve,{tool:"laser"})}const _S=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function IS(t,e,n,r){t.addEventListener?t.addEventListener(e,n,r):t.attachEvent&&t.attachEvent("on".concat(e),n)}function Lc(t,e,n,r){t.removeEventListener?t.removeEventListener(e,n,r):t.detachEvent&&t.detachEvent("on".concat(e),n)}function f4(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 g4(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function sfe(t,e){const n=t.length>=e.length?t:e,r=t.length>=e.length?e:t;let o=!0;for(let s=0;s<n.length;s++)r.indexOf(n[s])===-1&&(o=!1);return o}const Xu={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,"-":_S?173:189,"=":_S?61:187,";":_S?59:186,"'":222,"[":219,"]":221,"\\":220},No={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},f0={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++)Xu["f".concat(t)]=111+t;let Xe=[],pu=null,m4="all";const ts=new Map,Ed=t=>Xu[t.toLowerCase()]||No[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),ife=t=>Object.keys(Xu).find(e=>Xu[e]===t),afe=t=>Object.keys(No).find(e=>No[e]===t);function y4(t){m4=t||"all"}function qu(){return m4||"all"}function lfe(){return Xe.slice(0)}function cfe(){return Xe.map(t=>ife(t)||afe(t)||String.fromCharCode(t))}function ufe(){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=>Ed(a))})})}),t}function dfe(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 hfe(t){return typeof t=="string"&&(t=Ed(t)),Xe.indexOf(t)!==-1}function pfe(t,e){let n,r;t||(t=qu());for(const o in pt)if(Object.prototype.hasOwnProperty.call(pt,o))for(n=pt[o],r=0;r<n.length;)n[r].scope===t?n.splice(r,1).forEach(i=>{let{element:a}=i;return Wb(a)}):r++;qu()===t&&y4(e||"all")}function ffe(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 No)No[r]===e&&(Gn[r]=!1)}}function S4(t){if(typeof t>"u")Object.keys(pt).forEach(o=>{Array.isArray(pt[o])&&pt[o].forEach(s=>Fh(s)),delete pt[o]}),Wb(null);else if(Array.isArray(t))t.forEach(o=>{o.key&&Fh(o)});else if(typeof t=="object")t.key&&Fh(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=""),Fh({key:t,scope:o,method:s,splitKey:"+"})}}const Fh=t=>{let{key:e,scope:n,method:r,splitKey:o="+"}=t;g4(e).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Ed(c);if(!pt[u])return;n||(n=qu());const h=l>1?f4(No,a):[],p=[];pt[u]=pt[u].filter(f=>{const g=(r?f.method===r:!0)&&f.scope===n&&sfe(f.mods,h);return g&&p.push(f.element),!g}),p.forEach(f=>Wb(f))})};function QE(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 JE(t,e){const n=pt["*"];let r=t.keyCode||t.which||t.charCode;if(!Gn.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=f0[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 No)No[a]===r&&(Gn[a]=!0);if(!n)return}for(const a in Ut)Object.prototype.hasOwnProperty.call(Ut,a)&&(Ut[a]=t[f0[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=qu();if(n)for(let a=0;a<n.length;a++)n[a].scope===o&&(t.type==="keydown"&&n[a].keydown||t.type==="keyup"&&n[a].keyup)&&QE(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(Ed(u[p]));h.sort().join("")===Xe.sort().join("")&&QE(t,l,o,e)}}function Gn(t,e,n){Xe=[];const r=g4(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&&S4(t,s);a<r.length;a++)t=r[a].split(u),o=[],t.length>1&&(o=f4(No,t)),t=t[t.length-1],t=t==="*"?"*":Ed(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(!ts.has(i)){const f=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return JE(g,i)},m=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;JE(g,i),ffe(g)};ts.set(i,{keydownListener:f,keyupListenr:m,capture:h}),IS(i,"keydown",f,h),IS(i,"keyup",m,h)}if(!pu){const f=()=>{Xe=[]};pu={listener:f,capture:h},IS(window,"focus",f,h)}}}function gfe(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 Wb(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}=ts.get(t)||{};r&&o&&(Lc(t,"keyup",o,s),Lc(t,"keydown",r,s),ts.delete(t))}if((e.length<=0||ts.size<=0)&&(Object.keys(ts).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=ts.get(o)||{};s&&i&&(Lc(o,"keyup",i,a),Lc(o,"keydown",s,a),ts.delete(o))}),ts.clear(),Object.keys(pt).forEach(o=>delete pt[o]),pu)){const{listener:o,capture:s}=pu;Lc(window,"focus",o,s),pu=null}}const ES={getPressedKeyString:cfe,setScope:y4,getScope:qu,deleteScope:pfe,getPressedKeyCodes:lfe,getAllKeyCodes:ufe,isPressed:hfe,filter:dfe,trigger:gfe,unbind:S4,keyMap:Xu,modifier:No,modifierMap:f0};for(const t in ES)Object.prototype.hasOwnProperty.call(ES,t)&&(Gn[t]=ES[t]);if(typeof window<"u"){const t=window.hotkeys;Gn.noConflict=e=>(e&&window.hotkeys===Gn&&(window.hotkeys=t),Gn),window.hotkeys=Gn}const e2=["copy","cut","paste","asset"];function mfe(){const t=z(),e=wr(),n=Ca(),r=xb(),o=H("is focused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!o)return;const s=new Array,i=(l,c)=>{Gn(l,{element:document.body},c),s.push(()=>{Gn.unbind(l,c)})},a=(l,c)=>{Gn(l,{element:document.body,keyup:!0,keydown:!1},c),s.push(()=>{Gn.unbind(l,c)})};for(const l of Object.values(n))l.kbd&&(e&&!l.readonlyOk||e2.includes(l.id)||i(t2(l.kbd),c=>{qc(t)||(xe(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&t.getIsReadonly()||e2.includes(l.id)||i(t2(l.kbd),c=>{qc(t)||(xe(c),l.onSelect("kbd"))});return i(",",l=>{if(qc(t)||t.inputs.keys.has("Comma"))return;xe(l),t.focus(),t.inputs.keys.add("Comma");const{x:c,y:u,z:h}=t.inputs.currentPagePoint,p=t.pageToScreen({x:c,y:u}),f={type:"pointer",name:"pointer_down",point:{x:p.x,y:p.y,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(f)}),a(",",l=>{if(qc(t)||!t.inputs.keys.has("Comma"))return;t.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=t.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(p)}),()=>{s.forEach(l=>l())}},[n,r,e,t,o])}function t2(t){return yfe(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 yfe(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function qc(t){return t.menus.hasAnyOpenMenus()||t.getEditingShapeId()!==null||t.getCrashingError()}const Sfe=w.createContext(!1);function vfe({children:t}){const e=z(),n=ql(),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`
|
|
412
|
-
#${n}_main > *:nth-child(n + ${s+(c?1:2)})${f} {
|
|
413
|
-
display: none;
|
|
414
|
-
}
|
|
415
|
-
#${n}_more > *:nth-child(-n + ${s}) {
|
|
416
|
-
display: none;
|
|
417
|
-
}
|
|
418
|
-
`},[c,n,s]),p=Ng(()=>{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 g=Array.from(l.current.children).findIndex(v=>v.getAttribute("aria-checked")==="true");g!==-1&&g>=s&&u(f[g].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[m,g]of f)Gn(m,v=>{var P;if(qc(e))return;xe(v);const y=Array.from(((P=l.current)==null?void 0:P.children)??[]).filter(b=>!(b instanceof HTMLElement)||b.tagName.toLowerCase()!=="button"?!1:!!(b.offsetWidth||b.offsetHeight))[g];y&&y.click()});return()=>{Gn.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($r,{type:"toolbar",sourceId:"toolbar",children:t})}),i>s+1&&d.jsx(Sfe.Provider,{value:!0,children:d.jsxs(ha,{id:"toolbar overflow",modal:!1,children:[d.jsx(pa,{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(fa,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx($r,{type:"toolbar-overflow",sourceId:"toolbar",children:t})})})]})})]})]})}function xfe({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 wfe=w.memo(function({children:e}){const n=z(),r=Mn(),o=wr(),s=H("current tool id",()=>n.getCurrentToolId(),[n]),i=w.useRef(null);ki(i);const{ActionsMenu:a,QuickActions:l}=ji(),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(xfe,{activeToolId:s})]}),d.jsx(vfe,{children:e??d.jsx(Tpe,{})})]}),r<St.TABLET_SM&&!o&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(kpe,{})})]})})});function bfe(){const t=Ce();return d.jsxs("div",{className:le("tlui-offline-indicator"),children:[t("status.offline"),d.jsx(Lo,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function Pfe({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,m=h.offsetWidth,g=p.offsetWidth,v=c.offsetWidth-e;let S=(f-v)/2;f%2!==0&&(S-=.5);const y=m+r,P=c.offsetLeft,b=Math.min(f-g-m-2*r,t),C=Math.max(S,y)-P;p.offsetWidth>n&&a<=6?c.style.setProperty("max-width",b-o+"px"):c.style.setProperty("max-width",b+"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 Cfe(){const t=joe()==="offline";return d.jsx(Pfe,{children:t&&d.jsx(bfe,{})})}function _fe(){return d.jsxs(d.Fragment,{children:[d.jsx(K,{actionId:"zoom-in",noClose:!0}),d.jsx(K,{actionId:"zoom-out",noClose:!0}),d.jsx(_F,{}),d.jsx(IF,{}),d.jsx(EF,{})]})}const Ife=w.memo(function({children:e}){const n=Mt(),[r,o]=Es("zoom menu"),s=e??d.jsx(_fe,{});return d.jsxs(yb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(Sb,{asChild:!0,dir:"ltr",children:d.jsx(Efe,{})}),d.jsx(pm,{container:n,children:d.jsx(vb,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx($r,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),Efe=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),"%"]})})}),v4=w.createContext(null);function kfe({overrides:t={},children:e}){const n=Ql(t),r=sm();return d.jsx(v4.Provider,{value:w.useMemo(()=>({ContextMenu:Hde,ActionsMenu:mde,HelpMenu:null,ZoomMenu:Ife,MainMenu:_he,Minimap:Rhe,StylePanel:Epe,PageMenu:Nhe,NavigationPanel:$he,Toolbar:wfe,KeyboardShortcutsDialog:hhe,QuickActions:Bhe,HelperButtons:uhe,DebugPanel:the,DebugMenu:ehe,MenuPanel:she,SharePanel:r?Yhe:null,CursorChatBubble:r?Gde:null,TopPanel:r?Cfe:null,...n}),[n,r]),children:e})}function ji(){const t=w.useContext(v4);if(!t)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return t}const Tfe=$t(function({overrides:e,components:n,assetUrls:r,onUiEvent:o,forceMobile:s,mediaMimeTypes:i,children:a}){const l=z();return d.jsx(U3.Provider,{value:i,children:d.jsx(yre,{assetUrls:zue(r),children:d.jsx(xre,{overrides:Hue(e),locale:l.user.getLocale(),children:d.jsx(Hne,{onEvent:o,children:d.jsx(mre,{children:d.jsx(Kne,{context:l.contextId,children:d.jsx(_ae,{forceMobile:s,children:d.jsx(kfe,{overrides:n,children:d.jsx(Mfe,{overrides:e,children:a})})})})})})})})})});function Mfe({overrides:t,children:e}){const n=Kue(t);return d.jsx(Roe,{overrides:n.actions,children:d.jsx(jae,{overrides:n.tools,children:e})})}function Afe(){const t=z(),{addToast:e}=Uo();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 jfe=Te.memo(function({renderDebugMenuItems:e,children:n,hideUi:r,components:o,...s}){return d.jsx(Tfe,{...s,components:o,children:d.jsx(Ofe,{hideUi:r,renderDebugMenuItems:e,children:n})})}),Ofe=Te.memo(function({children:e,hideUi:n,...r}){return d.jsxs(d.Fragment,{children:[e,n?null:d.jsx(Dfe,{...r})]})}),Dfe=Te.memo(function(){const e=z(),n=Ce(),r=Mn(),o=wr(),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:m,DebugPanel:g,CursorChatBubble:v}=ji();mfe(),ioe(),Afe();const{"toggle-focus-mode":S}=Ca();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,{}),m&&d.jsx(m,{})]}),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&&g&&d.jsx(g,{})]})]}),d.jsx(Cre,{}),d.jsx(Gne,{}),d.jsx($ue,{}),v&&d.jsx(v,{})]})});async function Rfe(t,e){const{url:n,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=e,h={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c},p=new FontFace(t,`url(${n})`,h);return await p.load(),document.fonts.add(p),p.$$_url=n,p.$$_fontface=`
|
|
419
|
-
@font-face {
|
|
420
|
-
font-family: ${p.family};
|
|
421
|
-
font-stretch: ${p.stretch};
|
|
422
|
-
font-weight: ${p.weight};
|
|
423
|
-
font-style: ${p.style};
|
|
424
|
-
src: url("${n}") format("${u}")
|
|
425
|
-
}`,p}const Nh=(t,e)=>{const[n,r]=w.useState(2);return w.useEffect(()=>{let o=!1;return r(2),Rfe(t,e).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[t,e]),n};function Lfe(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 x4(t){const e=w.useMemo(()=>Lfe(t),[t]),n=[Nh("tldraw_draw",e.draw),Nh("tldraw_serif",e.serif),Nh("tldraw_sans",e.sansSerif),Nh("tldraw_mono",e.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function $fe(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=Ql(a),m=w.useMemo(()=>({Scribble:pE,ShapeIndicators:Hae,CollaboratorScribble:pE,SelectionForeground:zae,SelectionBackground:Fae,Handles:Oae,...f}),[f]),g=Gs(l),v=w.useMemo(()=>[...f5,...g],[g]),S=Gs(c),y=w.useMemo(()=>[...R$,...S],[S]),P=Gs(u),b=w.useMemo(()=>[...Lue,..._le,...P],[P]),C=Gs(o??mg),I=Gs(s??mw),k=w.useMemo(()=>[...C,...I],[C,I]),_=Q5(p.assetUrls),{done:M,error:T}=x4(_);return T?d.jsx($R,{children:"Could not load assets. Please refresh the page."}):M?d.jsx(Qee,{initialState:"select",...p,components:m,shapeUtils:v,bindingUtils:y,tools:b,children:d.jsxs(jfe,{...p,components:m,mediaMimeTypes:k,children:[d.jsx(Ffe,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:C,acceptedVideoMimeTypes:I,onMount:i,embeds:h}),e]})}):d.jsx(k1,{children:d.jsx(h1,{})})}function Ffe({maxImageDimension:t=5e3,maxAssetSize:e=10*1024*1024,acceptedImageMimeTypes:n=mg,acceptedVideoMimeTypes:r=mw,onMount:o,embeds:s}){const i=z(),a=Uo(),l=Ce();FR(()=>{const h=i.getShapeUtil("embed");h&&s&&h.setEmbedDefinitions(s);const p=[];return p.push(iue(i)),ile(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}=ji();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=Gs(e.shapeUtils??[]),a=w.useMemo(()=>[...f5,...i],[i]),l=Gs(e.bindingUtils??[]),c=w.useMemo(()=>[...R$,...l],[l]),u=ste({snapshot:e.snapshot,shapeUtils:a}),h=Q5(e.assetUrls),{done:p,error:f}=x4(h),{pageId:m,bounds:g,scale:v,background:S,padding:y,darkMode:P,preserveAspectRatio:b,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 M=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>_,licenseKey:I});m&&M.setCurrentPage(m);const T=M.getCurrentPageShapeIds();async function D(){const A=await M.getSvgString([...T],{bounds:g,scale:v,background:S,padding:y,darkMode:P,preserveAspectRatio:b});if(A&&!k){if(C==="svg"){if(!k){const O=new Blob([A.svg],{type:"image/svg+xml"}),R=URL.createObjectURL(O);r(R)}}else if(C==="png"){const O=await N3(M,A.svg,{type:C,quality:1,scale:2,width:A.width,height:A.height});if(O&&!k){const R=URL.createObjectURL(O);r(R)}}}M.dispose()}return D(),()=>{k=!0}},[C,o,u,a,c,m,g,v,S,y,P,b,p,f,I]),f?d.jsx($R,{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(k1,{children:d.jsx(h1,{})})});w.memo(function({children:e}){const n=Ce(),r=Mn(),o=w.useRef(null);ki(o);const s=e??d.jsx(ghe,{});return r<St.MOBILE?null:d.jsx("div",{ref:o,className:"tlui-help-menu",children:d.jsxs(ha,{id:"help menu",children:[d.jsx(pa,{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(fa,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx($r,{type:"menu",sourceId:"help-menu",children:s})})]})})});const Nfe=1,zfe=Pe({schemaVersion:gn(1),storeVersion:rp,recordVersions:bf(me,Pe({version:rp,subTypeVersions:bf(me,rp).optional(),subTypeKey:me.optional()}))}),Bfe=Pe({schemaVersion:gn(2),sequences:bf(me,rp)}),Ufe=Pe({tldrawFileFormatVersion:DV,schema:RV("schemaVersion",{1:zfe,2:Bfe}),records:Wt(Pe({id:me,typeName:me}).allowUnknownProperties())});function Hfe(t){var e;try{return!!((e=t.document)!=null&&e.version)}catch{return!1}}function Kfe({json:t,schema:e}){let n;try{n=Ufe.validate(JSON.parse(t))}catch(s){try{if(n=JSON.parse(t),Hfe(n))return xn.err({type:"v1File",data:n})}catch{}return xn.err({type:"notATldrawFile",cause:s})}if(n.tldrawFileFormatVersion>Nfe)return xn.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r,o;try{const s=Wfe(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(Bu({snapshot:{store:o,schema:n.schema},schema:e}))}catch(s){return xn.err({type:"invalidRecords",cause:s})}}function Wfe(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))}Pi("tldraw","3.4.1","esm");function Gfe(){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($fe,{assetUrls:n8(),onMount:n,store:t})})}YS.createRoot(document.querySelector("#root")).render(d.jsx(Te.StrictMode,{children:d.jsx(Gfe,{})}));
|