@kitschpatrol/tldraw-cli 4.6.27 → 4.6.29
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 +511 -203
- package/dist/.DS_Store +0 -0
- package/dist/lib/index.js +509 -201
- package/dist/lib/inline/get-image.d.ts +1 -1
- package/dist/lib/tldraw-to-image.d.ts +1 -1
- package/dist/tldraw/assets/index-B6B9QXXc.js +425 -0
- package/dist/tldraw/index.html +1 -1
- package/package.json +5 -5
- package/readme.md +20 -16
- package/dist/tldraw/assets/index-D-73B8sU.js +0 -425
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
var D4=Object.defineProperty;var R4=(t,e,n)=>e in t?D4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var I=(t,e,n)=>R4(t,typeof e!="symbol"?e+"":e,n);function L4(t,e){for(var n=0;n<e.length;n++){const r=e[n];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in t)){const o=Object.getOwnPropertyDescriptor(r,s);o&&Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:()=>r[s]})}}}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 s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();var dn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u2={exports:{}},Jp={},d2={exports:{}},Ie={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var Qu=Symbol.for("react.element"),$4=Symbol.for("react.portal"),F4=Symbol.for("react.fragment"),N4=Symbol.for("react.strict_mode"),z4=Symbol.for("react.profiler"),B4=Symbol.for("react.provider"),U4=Symbol.for("react.context"),H4=Symbol.for("react.forward_ref"),K4=Symbol.for("react.suspense"),W4=Symbol.for("react.memo"),G4=Symbol.for("react.lazy"),pP=Symbol.iterator;function V4(t){return t===null||typeof t!="object"?null:(t=pP&&t[pP]||t["@@iterator"],typeof t=="function"?t:null)}var h2={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},f2=Object.assign,p2={};function Bl(t,e,n){this.props=t,this.context=e,this.refs=p2,this.updater=n||h2}Bl.prototype.isReactComponent={};Bl.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")};Bl.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function g2(){}g2.prototype=Bl.prototype;function Sw(t,e,n){this.props=t,this.context=e,this.refs=p2,this.updater=n||h2}var vw=Sw.prototype=new g2;vw.constructor=Sw;f2(vw,Bl.prototype);vw.isPureReactComponent=!0;var gP=Array.isArray,m2=Object.prototype.hasOwnProperty,xw={current:null},y2={key:!0,ref:!0,__self:!0,__source:!0};function S2(t,e,n){var r,s={},o=null,i=null;if(e!=null)for(r in e.ref!==void 0&&(i=e.ref),e.key!==void 0&&(o=""+e.key),e)m2.call(e,r)&&!y2.hasOwnProperty(r)&&(s[r]=e[r]);var a=arguments.length-2;if(a===1)s.children=n;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];s.children=l}if(t&&t.defaultProps)for(r in a=t.defaultProps,a)s[r]===void 0&&(s[r]=a[r]);return{$$typeof:Qu,type:t,key:o,ref:i,props:s,_owner:xw.current}}function Y4(t,e){return{$$typeof:Qu,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}function ww(t){return typeof t=="object"&&t!==null&&t.$$typeof===Qu}function X4(t){var e={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(n){return e[n]})}var mP=/\/+/g;function Lm(t,e){return typeof t=="object"&&t!==null&&t.key!=null?X4(""+t.key):e.toString(36)}function Hh(t,e,n,r,s){var o=typeof t;(o==="undefined"||o==="boolean")&&(t=null);var i=!1;if(t===null)i=!0;else switch(o){case"string":case"number":i=!0;break;case"object":switch(t.$$typeof){case Qu:case $4:i=!0}}if(i)return i=t,s=s(i),t=r===""?"."+Lm(i,0):r,gP(s)?(n="",t!=null&&(n=t.replace(mP,"$&/")+"/"),Hh(s,e,n,"",function(c){return c})):s!=null&&(ww(s)&&(s=Y4(s,n+(!s.key||i&&i.key===s.key?"":(""+s.key).replace(mP,"$&/")+"/")+t)),e.push(s)),1;if(i=0,r=r===""?".":r+":",gP(t))for(var a=0;a<t.length;a++){o=t[a];var l=r+Lm(o,a);i+=Hh(o,e,n,l,s)}else if(l=V4(t),typeof l=="function")for(t=l.call(t),a=0;!(o=t.next()).done;)o=o.value,l=r+Lm(o,a++),i+=Hh(o,e,n,l,s);else if(o==="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 Fd(t,e,n){if(t==null)return t;var r=[],s=0;return Hh(t,r,"","",function(o){return e.call(n,o,s++)}),r}function q4(t){if(t._status===-1){var e=t._result;e=e(),e.then(function(n){(t._status===0||t._status===-1)&&(t._status=1,t._result=n)},function(n){(t._status===0||t._status===-1)&&(t._status=2,t._result=n)}),t._status===-1&&(t._status=0,t._result=e)}if(t._status===1)return t._result.default;throw t._result}var Cn={current:null},Kh={transition:null},Z4={ReactCurrentDispatcher:Cn,ReactCurrentBatchConfig:Kh,ReactCurrentOwner:xw};function v2(){throw Error("act(...) is not supported in production builds of React.")}Ie.Children={map:Fd,forEach:function(t,e,n){Fd(t,function(){e.apply(this,arguments)},n)},count:function(t){var e=0;return Fd(t,function(){e++}),e},toArray:function(t){return Fd(t,function(e){return e})||[]},only:function(t){if(!ww(t))throw Error("React.Children.only expected to receive a single React element child.");return t}};Ie.Component=Bl;Ie.Fragment=F4;Ie.Profiler=z4;Ie.PureComponent=Sw;Ie.StrictMode=N4;Ie.Suspense=K4;Ie.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Z4;Ie.act=v2;Ie.cloneElement=function(t,e,n){if(t==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+t+".");var r=f2({},t.props),s=t.key,o=t.ref,i=t._owner;if(e!=null){if(e.ref!==void 0&&(o=e.ref,i=xw.current),e.key!==void 0&&(s=""+e.key),t.type&&t.type.defaultProps)var a=t.type.defaultProps;for(l in e)m2.call(e,l)&&!y2.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:Qu,type:t.type,key:s,ref:o,props:r,_owner:i}};Ie.createContext=function(t){return t={$$typeof:U4,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},t.Provider={$$typeof:B4,_context:t},t.Consumer=t};Ie.createElement=S2;Ie.createFactory=function(t){var e=S2.bind(null,t);return e.type=t,e};Ie.createRef=function(){return{current:null}};Ie.forwardRef=function(t){return{$$typeof:H4,render:t}};Ie.isValidElement=ww;Ie.lazy=function(t){return{$$typeof:G4,_payload:{_status:-1,_result:t},_init:q4}};Ie.memo=function(t,e){return{$$typeof:W4,type:t,compare:e===void 0?null:e}};Ie.startTransition=function(t){var e=Kh.transition;Kh.transition={};try{t()}finally{Kh.transition=e}};Ie.unstable_act=v2;Ie.useCallback=function(t,e){return Cn.current.useCallback(t,e)};Ie.useContext=function(t){return Cn.current.useContext(t)};Ie.useDebugValue=function(){};Ie.useDeferredValue=function(t){return Cn.current.useDeferredValue(t)};Ie.useEffect=function(t,e){return Cn.current.useEffect(t,e)};Ie.useId=function(){return Cn.current.useId()};Ie.useImperativeHandle=function(t,e,n){return Cn.current.useImperativeHandle(t,e,n)};Ie.useInsertionEffect=function(t,e){return Cn.current.useInsertionEffect(t,e)};Ie.useLayoutEffect=function(t,e){return Cn.current.useLayoutEffect(t,e)};Ie.useMemo=function(t,e){return Cn.current.useMemo(t,e)};Ie.useReducer=function(t,e,n){return Cn.current.useReducer(t,e,n)};Ie.useRef=function(t){return Cn.current.useRef(t)};Ie.useState=function(t){return Cn.current.useState(t)};Ie.useSyncExternalStore=function(t,e,n){return Cn.current.useSyncExternalStore(t,e,n)};Ie.useTransition=function(){return Cn.current.useTransition()};Ie.version="18.3.1";d2.exports=Ie;var w=d2.exports;const ke=wi(w),Q4=L4({__proto__:null,default:ke},[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 J4=w,e6=Symbol.for("react.element"),t6=Symbol.for("react.fragment"),n6=Object.prototype.hasOwnProperty,r6=J4.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s6={key:!0,ref:!0,__self:!0,__source:!0};function x2(t,e,n){var r,s={},o=null,i=null;n!==void 0&&(o=""+n),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(i=e.ref);for(r in e)n6.call(e,r)&&!s6.hasOwnProperty(r)&&(s[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)s[r]===void 0&&(s[r]=e[r]);return{$$typeof:e6,type:t,key:o,ref:i,props:s,_owner:r6.current}}Jp.Fragment=t6;Jp.jsx=x2;Jp.jsxs=x2;u2.exports=Jp;var d=u2.exports,qS={},w2={exports:{}},Sr={},b2={exports:{}},P2={};/**
|
|
18
|
+
* @license React
|
|
19
|
+
* scheduler.production.min.js
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the MIT license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*/(function(t){function e(R,H){var X=R.length;R.push(H);e:for(;0<X;){var te=X-1>>>1,le=R[te];if(0<s(le,H))R[te]=H,R[X]=le,X=te;else break e}}function n(R){return R.length===0?null:R[0]}function r(R){if(R.length===0)return null;var H=R[0],X=R.pop();if(X!==H){R[0]=X;e:for(var te=0,le=R.length,de=le>>>1;te<de;){var Me=2*(te+1)-1,oe=R[Me],Ue=Me+1,Ne=R[Ue];if(0>s(oe,X))Ue<le&&0>s(Ne,oe)?(R[te]=Ne,R[Ue]=X,te=Ue):(R[te]=oe,R[Me]=X,te=Me);else if(Ue<le&&0>s(Ne,X))R[te]=Ne,R[Ue]=X,te=Ue;else break e}}return H}function s(R,H){var X=R.sortIndex-H.sortIndex;return X!==0?X:R.id-H.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;t.unstable_now=function(){return o.now()}}else{var i=Date,a=i.now();t.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,h=null,f=3,p=!1,g=!1,m=!1,v=typeof setTimeout=="function"?setTimeout:null,y=typeof clearTimeout=="function"?clearTimeout:null,S=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function b(R){for(var H=n(c);H!==null;){if(H.callback===null)r(c);else if(H.startTime<=R)r(c),H.sortIndex=H.expirationTime,e(l,H);else break;H=n(c)}}function P(R){if(m=!1,b(R),!g)if(n(l)!==null)g=!0,B(C);else{var H=n(c);H!==null&&K(P,H.startTime-R)}}function C(R,H){g=!1,m&&(m=!1,y(k),k=-1),p=!0;var X=f;try{for(b(H),h=n(l);h!==null&&(!(h.expirationTime>H)||R&&!j());){var te=h.callback;if(typeof te=="function"){h.callback=null,f=h.priorityLevel;var le=te(h.expirationTime<=H);H=t.unstable_now(),typeof le=="function"?h.callback=le:h===n(l)&&r(l),b(H)}else r(l);h=n(l)}if(h!==null)var de=!0;else{var Me=n(c);Me!==null&&K(P,Me.startTime-H),de=!1}return de}finally{h=null,f=X,p=!1}}var _=!1,E=null,k=-1,D=5,T=-1;function j(){return!(t.unstable_now()-T<D)}function L(){if(E!==null){var R=t.unstable_now();T=R;var H=!0;try{H=E(!0,R)}finally{H?M():(_=!1,E=null)}}else _=!1}var M;if(typeof S=="function")M=function(){S(L)};else if(typeof MessageChannel<"u"){var O=new MessageChannel,F=O.port2;O.port1.onmessage=L,M=function(){F.postMessage(null)}}else M=function(){v(L,0)};function B(R){E=R,_||(_=!0,M())}function K(R,H){k=v(function(){R(t.unstable_now())},H)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(R){R.callback=null},t.unstable_continueExecution=function(){g||p||(g=!0,B(C))},t.unstable_forceFrameRate=function(R){0>R||125<R?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):D=0<R?Math.floor(1e3/R):5},t.unstable_getCurrentPriorityLevel=function(){return f},t.unstable_getFirstCallbackNode=function(){return n(l)},t.unstable_next=function(R){switch(f){case 1:case 2:case 3:var H=3;break;default:H=f}var X=f;f=H;try{return R()}finally{f=X}},t.unstable_pauseExecution=function(){},t.unstable_requestPaint=function(){},t.unstable_runWithPriority=function(R,H){switch(R){case 1:case 2:case 3:case 4:case 5:break;default:R=3}var X=f;f=R;try{return H()}finally{f=X}},t.unstable_scheduleCallback=function(R,H,X){var te=t.unstable_now();switch(typeof X=="object"&&X!==null?(X=X.delay,X=typeof X=="number"&&0<X?te+X:te):X=te,R){case 1:var le=-1;break;case 2:le=250;break;case 5:le=1073741823;break;case 4:le=1e4;break;default:le=5e3}return le=X+le,R={id:u++,callback:H,priorityLevel:R,startTime:X,expirationTime:le,sortIndex:-1},X>te?(R.sortIndex=X,e(c,R),n(l)===null&&R===n(c)&&(m?(y(k),k=-1):m=!0,K(P,X-te))):(R.sortIndex=le,e(l,R),g||p||(g=!0,B(C))),R},t.unstable_shouldYield=j,t.unstable_wrapCallback=function(R){var H=f;return function(){var X=f;f=H;try{return R.apply(this,arguments)}finally{f=X}}}})(P2);b2.exports=P2;var o6=b2.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 i6=w,pr=o6;function Y(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 C2=new Set,yu={};function xa(t,e){_l(t,e),_l(t+"Capture",e)}function _l(t,e){for(yu[t]=e,t=0;t<e.length;t++)C2.add(e[t])}var So=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ZS=Object.prototype.hasOwnProperty,a6=/^[: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]*$/,yP={},SP={};function l6(t){return ZS.call(SP,t)?!0:ZS.call(yP,t)?!1:a6.test(t)?SP[t]=!0:(yP[t]=!0,!1)}function c6(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 u6(t,e,n,r){if(e===null||typeof e>"u"||c6(t,e,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function _n(t,e,n,r,s,o,i){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=r,this.attributeNamespace=s,this.mustUseProperty=n,this.propertyName=t,this.type=e,this.sanitizeURL=o,this.removeEmptyString=i}var Xt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){Xt[t]=new _n(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];Xt[e]=new _n(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){Xt[t]=new _n(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){Xt[t]=new _n(t,2,!1,t,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(t){Xt[t]=new _n(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){Xt[t]=new _n(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){Xt[t]=new _n(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){Xt[t]=new _n(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){Xt[t]=new _n(t,5,!1,t.toLowerCase(),null,!1,!1)});var bw=/[\-:]([a-z])/g;function Pw(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(bw,Pw);Xt[e]=new _n(e,1,!1,t,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(t){var e=t.replace(bw,Pw);Xt[e]=new _n(e,1,!1,t,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(t){var e=t.replace(bw,Pw);Xt[e]=new _n(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){Xt[t]=new _n(t,1,!1,t.toLowerCase(),null,!1,!1)});Xt.xlinkHref=new _n("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){Xt[t]=new _n(t,1,!1,t.toLowerCase(),null,!0,!0)});function Cw(t,e,n,r){var s=Xt.hasOwnProperty(e)?Xt[e]:null;(s!==null?s.type!==0:r||!(2<e.length)||e[0]!=="o"&&e[0]!=="O"||e[1]!=="n"&&e[1]!=="N")&&(u6(e,n,s,r)&&(n=null),r||s===null?l6(e)&&(n===null?t.removeAttribute(e):t.setAttribute(e,""+n)):s.mustUseProperty?t[s.propertyName]=n===null?s.type===3?!1:"":n:(e=s.attributeName,r=s.attributeNamespace,n===null?t.removeAttribute(e):(s=s.type,n=s===3||s===4&&n===!0?"":""+n,r?t.setAttributeNS(r,e,n):t.setAttribute(e,n))))}var _o=i6.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Nd=Symbol.for("react.element"),Wa=Symbol.for("react.portal"),Ga=Symbol.for("react.fragment"),_w=Symbol.for("react.strict_mode"),QS=Symbol.for("react.profiler"),_2=Symbol.for("react.provider"),I2=Symbol.for("react.context"),Iw=Symbol.for("react.forward_ref"),JS=Symbol.for("react.suspense"),ev=Symbol.for("react.suspense_list"),Ew=Symbol.for("react.memo"),Ko=Symbol.for("react.lazy"),E2=Symbol.for("react.offscreen"),vP=Symbol.iterator;function fc(t){return t===null||typeof t!="object"?null:(t=vP&&t[vP]||t["@@iterator"],typeof t=="function"?t:null)}var gt=Object.assign,$m;function Fc(t){if($m===void 0)try{throw Error()}catch(n){var e=n.stack.trim().match(/\n( *(at )?)/);$m=e&&e[1]||""}return`
|
|
34
|
+
`+$m+t}var Fm=!1;function Nm(t,e){if(!t||Fm)return"";Fm=!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 s=c.stack.split(`
|
|
35
|
+
`),o=r.stack.split(`
|
|
36
|
+
`),i=s.length-1,a=o.length-1;1<=i&&0<=a&&s[i]!==o[a];)a--;for(;1<=i&&0<=a;i--,a--)if(s[i]!==o[a]){if(i!==1||a!==1)do if(i--,a--,0>a||s[i]!==o[a]){var l=`
|
|
37
|
+
`+s[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{Fm=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?Fc(t):""}function d6(t){switch(t.tag){case 5:return Fc(t.type);case 16:return Fc("Lazy");case 13:return Fc("Suspense");case 19:return Fc("SuspenseList");case 0:case 2:case 15:return t=Nm(t.type,!1),t;case 11:return t=Nm(t.type.render,!1),t;case 1:return t=Nm(t.type,!0),t;default:return""}}function tv(t){if(t==null)return null;if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case Ga:return"Fragment";case Wa:return"Portal";case QS:return"Profiler";case _w:return"StrictMode";case JS:return"Suspense";case ev:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case I2:return(t.displayName||"Context")+".Consumer";case _2:return(t._context.displayName||"Context")+".Provider";case Iw:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Ew:return e=t.displayName||null,e!==null?e:tv(t.type)||"Memo";case Ko:e=t._payload,t=t._init;try{return tv(t(e))}catch{}}return null}function h6(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 tv(e);case 8:return e===_w?"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 fi(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function k2(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function f6(t){var e=k2(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 s=n.get,o=n.set;return Object.defineProperty(t,e,{configurable:!0,get:function(){return s.call(this)},set:function(i){r=""+i,o.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 zd(t){t._valueTracker||(t._valueTracker=f6(t))}function T2(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=k2(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Nf(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 nv(t,e){var n=e.checked;return gt({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function xP(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=fi(e.value!=null?e.value:n),t._wrapperState={initialChecked:r,initialValue:n,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function M2(t,e){e=e.checked,e!=null&&Cw(t,"checked",e,!1)}function rv(t,e){M2(t,e);var n=fi(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")?sv(t,e.type,n):e.hasOwnProperty("defaultValue")&&sv(t,e.type,fi(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function wP(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 sv(t,e,n){(e!=="number"||Nf(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var Nc=Array.isArray;function hl(t,e,n,r){if(t=t.options,e){e={};for(var s=0;s<n.length;s++)e["$"+n[s]]=!0;for(n=0;n<t.length;n++)s=e.hasOwnProperty("$"+t[n].value),t[n].selected!==s&&(t[n].selected=s),s&&r&&(t[n].defaultSelected=!0)}else{for(n=""+fi(n),e=null,s=0;s<t.length;s++){if(t[s].value===n){t[s].selected=!0,r&&(t[s].defaultSelected=!0);return}e!==null||t[s].disabled||(e=t[s])}e!==null&&(e.selected=!0)}}function ov(t,e){if(e.dangerouslySetInnerHTML!=null)throw Error(Y(91));return gt({},e,{value:void 0,defaultValue:void 0,children:""+t._wrapperState.initialValue})}function bP(t,e){var n=e.value;if(n==null){if(n=e.children,e=e.defaultValue,n!=null){if(e!=null)throw Error(Y(92));if(Nc(n)){if(1<n.length)throw Error(Y(93));n=n[0]}e=n}e==null&&(e=""),n=e}t._wrapperState={initialValue:fi(n)}}function A2(t,e){var n=fi(e.value),r=fi(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 PP(t){var e=t.textContent;e===t._wrapperState.initialValue&&e!==""&&e!==null&&(t.value=e)}function j2(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 iv(t,e){return t==null||t==="http://www.w3.org/1999/xhtml"?j2(e):t==="http://www.w3.org/2000/svg"&&e==="foreignObject"?"http://www.w3.org/1999/xhtml":t}var Bd,O2=function(t){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(e,n,r,s){MSApp.execUnsafeLocalFunction(function(){return t(e,n,r,s)})}:t}(function(t,e){if(t.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in t)t.innerHTML=e;else{for(Bd=Bd||document.createElement("div"),Bd.innerHTML="<svg>"+e.valueOf().toString()+"</svg>",e=Bd.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function Su(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Qc={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},p6=["Webkit","ms","Moz","O"];Object.keys(Qc).forEach(function(t){p6.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Qc[e]=Qc[t]})});function D2(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Qc.hasOwnProperty(t)&&Qc[t]?(""+e).trim():e+"px"}function R2(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,s=D2(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,s):t[n]=s}}var g6=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 av(t,e){if(e){if(g6[t]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(Y(137,t));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(Y(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(Y(61))}if(e.style!=null&&typeof e.style!="object")throw Error(Y(62))}}function lv(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 cv=null;function kw(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var uv=null,fl=null,pl=null;function CP(t){if(t=td(t)){if(typeof uv!="function")throw Error(Y(280));var e=t.stateNode;e&&(e=sg(e),uv(t.stateNode,t.type,e))}}function L2(t){fl?pl?pl.push(t):pl=[t]:fl=t}function $2(){if(fl){var t=fl,e=pl;if(pl=fl=null,CP(t),e)for(t=0;t<e.length;t++)CP(e[t])}}function F2(t,e){return t(e)}function N2(){}var zm=!1;function z2(t,e,n){if(zm)return t(e,n);zm=!0;try{return F2(t,e,n)}finally{zm=!1,(fl!==null||pl!==null)&&(N2(),$2())}}function vu(t,e){var n=t.stateNode;if(n===null)return null;var r=sg(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(Y(231,e,typeof n));return n}var dv=!1;if(So)try{var pc={};Object.defineProperty(pc,"passive",{get:function(){dv=!0}}),window.addEventListener("test",pc,pc),window.removeEventListener("test",pc,pc)}catch{dv=!1}function m6(t,e,n,r,s,o,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{e.apply(n,c)}catch(u){this.onError(u)}}var Jc=!1,zf=null,Bf=!1,hv=null,y6={onError:function(t){Jc=!0,zf=t}};function S6(t,e,n,r,s,o,i,a,l){Jc=!1,zf=null,m6.apply(y6,arguments)}function v6(t,e,n,r,s,o,i,a,l){if(S6.apply(this,arguments),Jc){if(Jc){var c=zf;Jc=!1,zf=null}else throw Error(Y(198));Bf||(Bf=!0,hv=c)}}function wa(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 B2(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 _P(t){if(wa(t)!==t)throw Error(Y(188))}function x6(t){var e=t.alternate;if(!e){if(e=wa(t),e===null)throw Error(Y(188));return e!==t?null:t}for(var n=t,r=e;;){var s=n.return;if(s===null)break;var o=s.alternate;if(o===null){if(r=s.return,r!==null){n=r;continue}break}if(s.child===o.child){for(o=s.child;o;){if(o===n)return _P(s),t;if(o===r)return _P(s),e;o=o.sibling}throw Error(Y(188))}if(n.return!==r.return)n=s,r=o;else{for(var i=!1,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){for(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)throw Error(Y(189))}}if(n.alternate!==r)throw Error(Y(190))}if(n.tag!==3)throw Error(Y(188));return n.stateNode.current===n?t:e}function U2(t){return t=x6(t),t!==null?H2(t):null}function H2(t){if(t.tag===5||t.tag===6)return t;for(t=t.child;t!==null;){var e=H2(t);if(e!==null)return e;t=t.sibling}return null}var K2=pr.unstable_scheduleCallback,IP=pr.unstable_cancelCallback,w6=pr.unstable_shouldYield,b6=pr.unstable_requestPaint,xt=pr.unstable_now,P6=pr.unstable_getCurrentPriorityLevel,Tw=pr.unstable_ImmediatePriority,W2=pr.unstable_UserBlockingPriority,Uf=pr.unstable_NormalPriority,C6=pr.unstable_LowPriority,G2=pr.unstable_IdlePriority,eg=null,Ts=null;function _6(t){if(Ts&&typeof Ts.onCommitFiberRoot=="function")try{Ts.onCommitFiberRoot(eg,t,void 0,(t.current.flags&128)===128)}catch{}}var es=Math.clz32?Math.clz32:k6,I6=Math.log,E6=Math.LN2;function k6(t){return t>>>=0,t===0?32:31-(I6(t)/E6|0)|0}var Ud=64,Hd=4194304;function zc(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 Hf(t,e){var n=t.pendingLanes;if(n===0)return 0;var r=0,s=t.suspendedLanes,o=t.pingedLanes,i=n&268435455;if(i!==0){var a=i&~s;a!==0?r=zc(a):(o&=i,o!==0&&(r=zc(o)))}else i=n&~s,i!==0?r=zc(i):o!==0&&(r=zc(o));if(r===0)return 0;if(e!==0&&e!==r&&!(e&s)&&(s=r&-r,o=e&-e,s>=o||s===16&&(o&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-es(e),s=1<<n,r|=t[n],e&=~s;return r}function T6(t,e){switch(t){case 1:case 2:case 4:return e+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function M6(t,e){for(var n=t.suspendedLanes,r=t.pingedLanes,s=t.expirationTimes,o=t.pendingLanes;0<o;){var i=31-es(o),a=1<<i,l=s[i];l===-1?(!(a&n)||a&r)&&(s[i]=T6(a,e)):l<=e&&(t.expiredLanes|=a),o&=~a}}function fv(t){return t=t.pendingLanes&-1073741825,t!==0?t:t&1073741824?1073741824:0}function V2(){var t=Ud;return Ud<<=1,!(Ud&4194240)&&(Ud=64),t}function Bm(t){for(var e=[],n=0;31>n;n++)e.push(t);return e}function Ju(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-es(e),t[e]=n}function A6(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 s=31-es(n),o=1<<s;e[s]=0,r[s]=-1,t[s]=-1,n&=~o}}function Mw(t,e){var n=t.entangledLanes|=e;for(t=t.entanglements;n;){var r=31-es(n),s=1<<r;s&e|t[r]&e&&(t[r]|=e),n&=~s}}var Be=0;function Y2(t){return t&=-t,1<t?4<t?t&268435455?16:536870912:4:1}var X2,Aw,q2,Z2,Q2,pv=!1,Kd=[],ni=null,ri=null,si=null,xu=new Map,wu=new Map,Go=[],j6="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 EP(t,e){switch(t){case"focusin":case"focusout":ni=null;break;case"dragenter":case"dragleave":ri=null;break;case"mouseover":case"mouseout":si=null;break;case"pointerover":case"pointerout":xu.delete(e.pointerId);break;case"gotpointercapture":case"lostpointercapture":wu.delete(e.pointerId)}}function gc(t,e,n,r,s,o){return t===null||t.nativeEvent!==o?(t={blockedOn:e,domEventName:n,eventSystemFlags:r,nativeEvent:o,targetContainers:[s]},e!==null&&(e=td(e),e!==null&&Aw(e)),t):(t.eventSystemFlags|=r,e=t.targetContainers,s!==null&&e.indexOf(s)===-1&&e.push(s),t)}function O6(t,e,n,r,s){switch(e){case"focusin":return ni=gc(ni,t,e,n,r,s),!0;case"dragenter":return ri=gc(ri,t,e,n,r,s),!0;case"mouseover":return si=gc(si,t,e,n,r,s),!0;case"pointerover":var o=s.pointerId;return xu.set(o,gc(xu.get(o)||null,t,e,n,r,s)),!0;case"gotpointercapture":return o=s.pointerId,wu.set(o,gc(wu.get(o)||null,t,e,n,r,s)),!0}return!1}function J2(t){var e=Gi(t.target);if(e!==null){var n=wa(e);if(n!==null){if(e=n.tag,e===13){if(e=B2(n),e!==null){t.blockedOn=e,Q2(t.priority,function(){q2(n)});return}}else if(e===3&&n.stateNode.current.memoizedState.isDehydrated){t.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}t.blockedOn=null}function Wh(t){if(t.blockedOn!==null)return!1;for(var e=t.targetContainers;0<e.length;){var n=gv(t.domEventName,t.eventSystemFlags,e[0],t.nativeEvent);if(n===null){n=t.nativeEvent;var r=new n.constructor(n.type,n);cv=r,n.target.dispatchEvent(r),cv=null}else return e=td(n),e!==null&&Aw(e),t.blockedOn=n,!1;e.shift()}return!0}function kP(t,e,n){Wh(t)&&n.delete(e)}function D6(){pv=!1,ni!==null&&Wh(ni)&&(ni=null),ri!==null&&Wh(ri)&&(ri=null),si!==null&&Wh(si)&&(si=null),xu.forEach(kP),wu.forEach(kP)}function mc(t,e){t.blockedOn===e&&(t.blockedOn=null,pv||(pv=!0,pr.unstable_scheduleCallback(pr.unstable_NormalPriority,D6)))}function bu(t){function e(s){return mc(s,t)}if(0<Kd.length){mc(Kd[0],t);for(var n=1;n<Kd.length;n++){var r=Kd[n];r.blockedOn===t&&(r.blockedOn=null)}}for(ni!==null&&mc(ni,t),ri!==null&&mc(ri,t),si!==null&&mc(si,t),xu.forEach(e),wu.forEach(e),n=0;n<Go.length;n++)r=Go[n],r.blockedOn===t&&(r.blockedOn=null);for(;0<Go.length&&(n=Go[0],n.blockedOn===null);)J2(n),n.blockedOn===null&&Go.shift()}var gl=_o.ReactCurrentBatchConfig,Kf=!0;function R6(t,e,n,r){var s=Be,o=gl.transition;gl.transition=null;try{Be=1,jw(t,e,n,r)}finally{Be=s,gl.transition=o}}function L6(t,e,n,r){var s=Be,o=gl.transition;gl.transition=null;try{Be=4,jw(t,e,n,r)}finally{Be=s,gl.transition=o}}function jw(t,e,n,r){if(Kf){var s=gv(t,e,n,r);if(s===null)Zm(t,e,r,Wf,n),EP(t,r);else if(O6(s,t,e,n,r))r.stopPropagation();else if(EP(t,r),e&4&&-1<j6.indexOf(t)){for(;s!==null;){var o=td(s);if(o!==null&&X2(o),o=gv(t,e,n,r),o===null&&Zm(t,e,r,Wf,n),o===s)break;s=o}s!==null&&r.stopPropagation()}else Zm(t,e,r,null,n)}}var Wf=null;function gv(t,e,n,r){if(Wf=null,t=kw(r),t=Gi(t),t!==null)if(e=wa(t),e===null)t=null;else if(n=e.tag,n===13){if(t=B2(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 Wf=t,null}function ek(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(P6()){case Tw:return 1;case W2:return 4;case Uf:case C6:return 16;case G2:return 536870912;default:return 16}default:return 16}}var Zo=null,Ow=null,Gh=null;function tk(){if(Gh)return Gh;var t,e=Ow,n=e.length,r,s="value"in Zo?Zo.value:Zo.textContent,o=s.length;for(t=0;t<n&&e[t]===s[t];t++);var i=n-t;for(r=1;r<=i&&e[n-r]===s[o-r];r++);return Gh=s.slice(t,1<r?1-r:void 0)}function Vh(t){var e=t.keyCode;return"charCode"in t?(t=t.charCode,t===0&&e===13&&(t=13)):t=e,t===10&&(t=13),32<=t||t===13?t:0}function Wd(){return!0}function TP(){return!1}function vr(t){function e(n,r,s,o,i){this._reactName=n,this._targetInst=s,this.type=r,this.nativeEvent=o,this.target=i,this.currentTarget=null;for(var a in t)t.hasOwnProperty(a)&&(n=t[a],this[a]=n?n(o):o[a]);return this.isDefaultPrevented=(o.defaultPrevented!=null?o.defaultPrevented:o.returnValue===!1)?Wd:TP,this.isPropagationStopped=TP,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=Wd)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=Wd)},persist:function(){},isPersistent:Wd}),e}var Ul={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(t){return t.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Dw=vr(Ul),ed=gt({},Ul,{view:0,detail:0}),$6=vr(ed),Um,Hm,yc,tg=gt({},ed,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Rw,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!==yc&&(yc&&t.type==="mousemove"?(Um=t.screenX-yc.screenX,Hm=t.screenY-yc.screenY):Hm=Um=0,yc=t),Um)},movementY:function(t){return"movementY"in t?t.movementY:Hm}}),MP=vr(tg),F6=gt({},tg,{dataTransfer:0}),N6=vr(F6),z6=gt({},ed,{relatedTarget:0}),Km=vr(z6),B6=gt({},Ul,{animationName:0,elapsedTime:0,pseudoElement:0}),U6=vr(B6),H6=gt({},Ul,{clipboardData:function(t){return"clipboardData"in t?t.clipboardData:window.clipboardData}}),K6=vr(H6),W6=gt({},Ul,{data:0}),AP=vr(W6),G6={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},V6={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},Y6={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function X6(t){var e=this.nativeEvent;return e.getModifierState?e.getModifierState(t):(t=Y6[t])?!!e[t]:!1}function Rw(){return X6}var q6=gt({},ed,{key:function(t){if(t.key){var e=G6[t.key]||t.key;if(e!=="Unidentified")return e}return t.type==="keypress"?(t=Vh(t),t===13?"Enter":String.fromCharCode(t)):t.type==="keydown"||t.type==="keyup"?V6[t.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Rw,charCode:function(t){return t.type==="keypress"?Vh(t):0},keyCode:function(t){return t.type==="keydown"||t.type==="keyup"?t.keyCode:0},which:function(t){return t.type==="keypress"?Vh(t):t.type==="keydown"||t.type==="keyup"?t.keyCode:0}}),Z6=vr(q6),Q6=gt({},tg,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),jP=vr(Q6),J6=gt({},ed,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Rw}),ez=vr(J6),tz=gt({},Ul,{propertyName:0,elapsedTime:0,pseudoElement:0}),nz=vr(tz),rz=gt({},tg,{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}),sz=vr(rz),oz=[9,13,27,32],Lw=So&&"CompositionEvent"in window,eu=null;So&&"documentMode"in document&&(eu=document.documentMode);var iz=So&&"TextEvent"in window&&!eu,nk=So&&(!Lw||eu&&8<eu&&11>=eu),OP=" ",DP=!1;function rk(t,e){switch(t){case"keyup":return oz.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function sk(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var Va=!1;function az(t,e){switch(t){case"compositionend":return sk(e);case"keypress":return e.which!==32?null:(DP=!0,OP);case"textInput":return t=e.data,t===OP&&DP?null:t;default:return null}}function lz(t,e){if(Va)return t==="compositionend"||!Lw&&rk(t,e)?(t=tk(),Gh=Ow=Zo=null,Va=!1,t):null;switch(t){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1<e.char.length)return e.char;if(e.which)return String.fromCharCode(e.which)}return null;case"compositionend":return nk&&e.locale!=="ko"?null:e.data;default:return null}}var cz={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 RP(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e==="input"?!!cz[t.type]:e==="textarea"}function ok(t,e,n,r){L2(r),e=Gf(e,"onChange"),0<e.length&&(n=new Dw("onChange","change",null,n,r),t.push({event:n,listeners:e}))}var tu=null,Pu=null;function uz(t){mk(t,0)}function ng(t){var e=qa(t);if(T2(e))return t}function dz(t,e){if(t==="change")return e}var ik=!1;if(So){var Wm;if(So){var Gm="oninput"in document;if(!Gm){var LP=document.createElement("div");LP.setAttribute("oninput","return;"),Gm=typeof LP.oninput=="function"}Wm=Gm}else Wm=!1;ik=Wm&&(!document.documentMode||9<document.documentMode)}function $P(){tu&&(tu.detachEvent("onpropertychange",ak),Pu=tu=null)}function ak(t){if(t.propertyName==="value"&&ng(Pu)){var e=[];ok(e,Pu,t,kw(t)),z2(uz,e)}}function hz(t,e,n){t==="focusin"?($P(),tu=e,Pu=n,tu.attachEvent("onpropertychange",ak)):t==="focusout"&&$P()}function fz(t){if(t==="selectionchange"||t==="keyup"||t==="keydown")return ng(Pu)}function pz(t,e){if(t==="click")return ng(e)}function gz(t,e){if(t==="input"||t==="change")return ng(e)}function mz(t,e){return t===e&&(t!==0||1/t===1/e)||t!==t&&e!==e}var os=typeof Object.is=="function"?Object.is:mz;function Cu(t,e){if(os(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 s=n[r];if(!ZS.call(e,s)||!os(t[s],e[s]))return!1}return!0}function FP(t){for(;t&&t.firstChild;)t=t.firstChild;return t}function NP(t,e){var n=FP(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=FP(n)}}function lk(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?lk(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function ck(){for(var t=window,e=Nf();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Nf(t.document)}return e}function $w(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 yz(t){var e=ck(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&lk(n.ownerDocument.documentElement,n)){if(r!==null&&$w(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 s=n.textContent.length,o=Math.min(r.start,s);r=r.end===void 0?o:Math.min(r.end,s),!t.extend&&o>r&&(s=r,r=o,o=s),s=NP(n,o);var i=NP(n,r);s&&i&&(t.rangeCount!==1||t.anchorNode!==s.node||t.anchorOffset!==s.offset||t.focusNode!==i.node||t.focusOffset!==i.offset)&&(e=e.createRange(),e.setStart(s.node,s.offset),t.removeAllRanges(),o>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 Sz=So&&"documentMode"in document&&11>=document.documentMode,Ya=null,mv=null,nu=null,yv=!1;function zP(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;yv||Ya==null||Ya!==Nf(r)||(r=Ya,"selectionStart"in r&&$w(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}),nu&&Cu(nu,r)||(nu=r,r=Gf(mv,"onSelect"),0<r.length&&(e=new Dw("onSelect","select",null,e,n),t.push({event:e,listeners:r}),e.target=Ya)))}function Gd(t,e){var n={};return n[t.toLowerCase()]=e.toLowerCase(),n["Webkit"+t]="webkit"+e,n["Moz"+t]="moz"+e,n}var Xa={animationend:Gd("Animation","AnimationEnd"),animationiteration:Gd("Animation","AnimationIteration"),animationstart:Gd("Animation","AnimationStart"),transitionend:Gd("Transition","TransitionEnd")},Vm={},uk={};So&&(uk=document.createElement("div").style,"AnimationEvent"in window||(delete Xa.animationend.animation,delete Xa.animationiteration.animation,delete Xa.animationstart.animation),"TransitionEvent"in window||delete Xa.transitionend.transition);function rg(t){if(Vm[t])return Vm[t];if(!Xa[t])return t;var e=Xa[t],n;for(n in e)if(e.hasOwnProperty(n)&&n in uk)return Vm[t]=e[n];return t}var dk=rg("animationend"),hk=rg("animationiteration"),fk=rg("animationstart"),pk=rg("transitionend"),gk=new Map,BP="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function bi(t,e){gk.set(t,e),xa(e,[t])}for(var Ym=0;Ym<BP.length;Ym++){var Xm=BP[Ym],vz=Xm.toLowerCase(),xz=Xm[0].toUpperCase()+Xm.slice(1);bi(vz,"on"+xz)}bi(dk,"onAnimationEnd");bi(hk,"onAnimationIteration");bi(fk,"onAnimationStart");bi("dblclick","onDoubleClick");bi("focusin","onFocus");bi("focusout","onBlur");bi(pk,"onTransitionEnd");_l("onMouseEnter",["mouseout","mouseover"]);_l("onMouseLeave",["mouseout","mouseover"]);_l("onPointerEnter",["pointerout","pointerover"]);_l("onPointerLeave",["pointerout","pointerover"]);xa("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));xa("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));xa("onBeforeInput",["compositionend","keypress","textInput","paste"]);xa("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));xa("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));xa("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Bc="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(" "),wz=new Set("cancel close invalid load scroll toggle".split(" ").concat(Bc));function UP(t,e,n){var r=t.type||"unknown-event";t.currentTarget=n,v6(r,e,void 0,t),t.currentTarget=null}function mk(t,e){e=(e&4)!==0;for(var n=0;n<t.length;n++){var r=t[n],s=r.event;r=r.listeners;e:{var o=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!==o&&s.isPropagationStopped())break e;UP(s,a,c),o=l}else for(i=0;i<r.length;i++){if(a=r[i],l=a.instance,c=a.currentTarget,a=a.listener,l!==o&&s.isPropagationStopped())break e;UP(s,a,c),o=l}}}if(Bf)throw t=hv,Bf=!1,hv=null,t}function tt(t,e){var n=e[bv];n===void 0&&(n=e[bv]=new Set);var r=t+"__bubble";n.has(r)||(yk(e,t,2,!1),n.add(r))}function qm(t,e,n){var r=0;e&&(r|=4),yk(n,t,r,e)}var Vd="_reactListening"+Math.random().toString(36).slice(2);function _u(t){if(!t[Vd]){t[Vd]=!0,C2.forEach(function(n){n!=="selectionchange"&&(wz.has(n)||qm(n,!1,t),qm(n,!0,t))});var e=t.nodeType===9?t:t.ownerDocument;e===null||e[Vd]||(e[Vd]=!0,qm("selectionchange",!1,e))}}function yk(t,e,n,r){switch(ek(e)){case 1:var s=R6;break;case 4:s=L6;break;default:s=jw}n=s.bind(null,e,n,t),s=void 0,!dv||e!=="touchstart"&&e!=="touchmove"&&e!=="wheel"||(s=!0),r?s!==void 0?t.addEventListener(e,n,{capture:!0,passive:s}):t.addEventListener(e,n,!0):s!==void 0?t.addEventListener(e,n,{passive:s}):t.addEventListener(e,n,!1)}function Zm(t,e,n,r,s){var o=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===s||a.nodeType===8&&a.parentNode===s)break;if(i===4)for(i=r.return;i!==null;){var l=i.tag;if((l===3||l===4)&&(l=i.stateNode.containerInfo,l===s||l.nodeType===8&&l.parentNode===s))return;i=i.return}for(;a!==null;){if(i=Gi(a),i===null)return;if(l=i.tag,l===5||l===6){r=o=i;continue e}a=a.parentNode}}r=r.return}z2(function(){var c=o,u=kw(n),h=[];e:{var f=gk.get(t);if(f!==void 0){var p=Dw,g=t;switch(t){case"keypress":if(Vh(n)===0)break e;case"keydown":case"keyup":p=Z6;break;case"focusin":g="focus",p=Km;break;case"focusout":g="blur",p=Km;break;case"beforeblur":case"afterblur":p=Km;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":p=MP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=N6;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=ez;break;case dk:case hk:case fk:p=U6;break;case pk:p=nz;break;case"scroll":p=$6;break;case"wheel":p=sz;break;case"copy":case"cut":case"paste":p=K6;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=jP}var m=(e&4)!==0,v=!m&&t==="scroll",y=m?f!==null?f+"Capture":null:f;m=[];for(var S=c,b;S!==null;){b=S;var P=b.stateNode;if(b.tag===5&&P!==null&&(b=P,y!==null&&(P=vu(S,y),P!=null&&m.push(Iu(S,P,b)))),v)break;S=S.return}0<m.length&&(f=new p(f,g,null,n,u),h.push({event:f,listeners:m}))}}if(!(e&7)){e:{if(f=t==="mouseover"||t==="pointerover",p=t==="mouseout"||t==="pointerout",f&&n!==cv&&(g=n.relatedTarget||n.fromElement)&&(Gi(g)||g[vo]))break e;if((p||f)&&(f=u.window===u?u:(f=u.ownerDocument)?f.defaultView||f.parentWindow:window,p?(g=n.relatedTarget||n.toElement,p=c,g=g?Gi(g):null,g!==null&&(v=wa(g),g!==v||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=c),p!==g)){if(m=MP,P="onMouseLeave",y="onMouseEnter",S="mouse",(t==="pointerout"||t==="pointerover")&&(m=jP,P="onPointerLeave",y="onPointerEnter",S="pointer"),v=p==null?f:qa(p),b=g==null?f:qa(g),f=new m(P,S+"leave",p,n,u),f.target=v,f.relatedTarget=b,P=null,Gi(u)===c&&(m=new m(y,S+"enter",g,n,u),m.target=b,m.relatedTarget=v,P=m),v=P,p&&g)t:{for(m=p,y=g,S=0,b=m;b;b=Ta(b))S++;for(b=0,P=y;P;P=Ta(P))b++;for(;0<S-b;)m=Ta(m),S--;for(;0<b-S;)y=Ta(y),b--;for(;S--;){if(m===y||y!==null&&m===y.alternate)break t;m=Ta(m),y=Ta(y)}m=null}else m=null;p!==null&&HP(h,f,p,m,!1),g!==null&&v!==null&&HP(h,v,g,m,!0)}}e:{if(f=c?qa(c):window,p=f.nodeName&&f.nodeName.toLowerCase(),p==="select"||p==="input"&&f.type==="file")var C=dz;else if(RP(f))if(ik)C=gz;else{C=fz;var _=hz}else(p=f.nodeName)&&p.toLowerCase()==="input"&&(f.type==="checkbox"||f.type==="radio")&&(C=pz);if(C&&(C=C(t,c))){ok(h,C,n,u);break e}_&&_(t,f,c),t==="focusout"&&(_=f._wrapperState)&&_.controlled&&f.type==="number"&&sv(f,"number",f.value)}switch(_=c?qa(c):window,t){case"focusin":(RP(_)||_.contentEditable==="true")&&(Ya=_,mv=c,nu=null);break;case"focusout":nu=mv=Ya=null;break;case"mousedown":yv=!0;break;case"contextmenu":case"mouseup":case"dragend":yv=!1,zP(h,n,u);break;case"selectionchange":if(Sz)break;case"keydown":case"keyup":zP(h,n,u)}var E;if(Lw)e:{switch(t){case"compositionstart":var k="onCompositionStart";break e;case"compositionend":k="onCompositionEnd";break e;case"compositionupdate":k="onCompositionUpdate";break e}k=void 0}else Va?rk(t,n)&&(k="onCompositionEnd"):t==="keydown"&&n.keyCode===229&&(k="onCompositionStart");k&&(nk&&n.locale!=="ko"&&(Va||k!=="onCompositionStart"?k==="onCompositionEnd"&&Va&&(E=tk()):(Zo=u,Ow="value"in Zo?Zo.value:Zo.textContent,Va=!0)),_=Gf(c,k),0<_.length&&(k=new AP(k,t,null,n,u),h.push({event:k,listeners:_}),E?k.data=E:(E=sk(n),E!==null&&(k.data=E)))),(E=iz?az(t,n):lz(t,n))&&(c=Gf(c,"onBeforeInput"),0<c.length&&(u=new AP("onBeforeInput","beforeinput",null,n,u),h.push({event:u,listeners:c}),u.data=E))}mk(h,e)})}function Iu(t,e,n){return{instance:t,listener:e,currentTarget:n}}function Gf(t,e){for(var n=e+"Capture",r=[];t!==null;){var s=t,o=s.stateNode;s.tag===5&&o!==null&&(s=o,o=vu(t,n),o!=null&&r.unshift(Iu(t,o,s)),o=vu(t,e),o!=null&&r.push(Iu(t,o,s))),t=t.return}return r}function Ta(t){if(t===null)return null;do t=t.return;while(t&&t.tag!==5);return t||null}function HP(t,e,n,r,s){for(var o=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,s?(l=vu(n,o),l!=null&&i.unshift(Iu(n,l,a))):s||(l=vu(n,o),l!=null&&i.push(Iu(n,l,a)))),n=n.return}i.length!==0&&t.push({event:e,listeners:i})}var bz=/\r\n?/g,Pz=/\u0000|\uFFFD/g;function KP(t){return(typeof t=="string"?t:""+t).replace(bz,`
|
|
38
|
+
`).replace(Pz,"")}function Yd(t,e,n){if(e=KP(e),KP(t)!==e&&n)throw Error(Y(425))}function Vf(){}var Sv=null,vv=null;function xv(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 wv=typeof setTimeout=="function"?setTimeout:void 0,Cz=typeof clearTimeout=="function"?clearTimeout:void 0,WP=typeof Promise=="function"?Promise:void 0,_z=typeof queueMicrotask=="function"?queueMicrotask:typeof WP<"u"?function(t){return WP.resolve(null).then(t).catch(Iz)}:wv;function Iz(t){setTimeout(function(){throw t})}function Qm(t,e){var n=e,r=0;do{var s=n.nextSibling;if(t.removeChild(n),s&&s.nodeType===8)if(n=s.data,n==="/$"){if(r===0){t.removeChild(s),bu(e);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=s}while(n);bu(e)}function oi(t){for(;t!=null;t=t.nextSibling){var e=t.nodeType;if(e===1||e===3)break;if(e===8){if(e=t.data,e==="$"||e==="$!"||e==="$?")break;if(e==="/$")return null}}return t}function GP(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 Hl=Math.random().toString(36).slice(2),bs="__reactFiber$"+Hl,Eu="__reactProps$"+Hl,vo="__reactContainer$"+Hl,bv="__reactEvents$"+Hl,Ez="__reactListeners$"+Hl,kz="__reactHandles$"+Hl;function Gi(t){var e=t[bs];if(e)return e;for(var n=t.parentNode;n;){if(e=n[vo]||n[bs]){if(n=e.alternate,e.child!==null||n!==null&&n.child!==null)for(t=GP(t);t!==null;){if(n=t[bs])return n;t=GP(t)}return e}t=n,n=t.parentNode}return null}function td(t){return t=t[bs]||t[vo],!t||t.tag!==5&&t.tag!==6&&t.tag!==13&&t.tag!==3?null:t}function qa(t){if(t.tag===5||t.tag===6)return t.stateNode;throw Error(Y(33))}function sg(t){return t[Eu]||null}var Pv=[],Za=-1;function Pi(t){return{current:t}}function rt(t){0>Za||(t.current=Pv[Za],Pv[Za]=null,Za--)}function qe(t,e){Za++,Pv[Za]=t.current,t.current=e}var pi={},gn=Pi(pi),Gn=Pi(!1),na=pi;function Il(t,e){var n=t.type.contextTypes;if(!n)return pi;var r=t.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var s={},o;for(o in n)s[o]=e[o];return r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=e,t.__reactInternalMemoizedMaskedChildContext=s),s}function Vn(t){return t=t.childContextTypes,t!=null}function Yf(){rt(Gn),rt(gn)}function VP(t,e,n){if(gn.current!==pi)throw Error(Y(168));qe(gn,e),qe(Gn,n)}function Sk(t,e,n){var r=t.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var s in r)if(!(s in e))throw Error(Y(108,h6(t)||"Unknown",s));return gt({},n,r)}function Xf(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||pi,na=gn.current,qe(gn,t),qe(Gn,Gn.current),!0}function YP(t,e,n){var r=t.stateNode;if(!r)throw Error(Y(169));n?(t=Sk(t,e,na),r.__reactInternalMemoizedMergedChildContext=t,rt(Gn),rt(gn),qe(gn,t)):rt(Gn),qe(Gn,n)}var oo=null,og=!1,Jm=!1;function vk(t){oo===null?oo=[t]:oo.push(t)}function Tz(t){og=!0,vk(t)}function Ci(){if(!Jm&&oo!==null){Jm=!0;var t=0,e=Be;try{var n=oo;for(Be=1;t<n.length;t++){var r=n[t];do r=r(!0);while(r!==null)}oo=null,og=!1}catch(s){throw oo!==null&&(oo=oo.slice(t+1)),K2(Tw,Ci),s}finally{Be=e,Jm=!1}}return null}var Qa=[],Ja=0,qf=null,Zf=0,kr=[],Tr=0,ra=null,ao=1,lo="";function Ui(t,e){Qa[Ja++]=Zf,Qa[Ja++]=qf,qf=t,Zf=e}function xk(t,e,n){kr[Tr++]=ao,kr[Tr++]=lo,kr[Tr++]=ra,ra=t;var r=ao;t=lo;var s=32-es(r)-1;r&=~(1<<s),n+=1;var o=32-es(e)+s;if(30<o){var i=s-s%5;o=(r&(1<<i)-1).toString(32),r>>=i,s-=i,ao=1<<32-es(e)+s|n<<s|r,lo=o+t}else ao=1<<o|n<<s|r,lo=t}function Fw(t){t.return!==null&&(Ui(t,1),xk(t,1,0))}function Nw(t){for(;t===qf;)qf=Qa[--Ja],Qa[Ja]=null,Zf=Qa[--Ja],Qa[Ja]=null;for(;t===ra;)ra=kr[--Tr],kr[Tr]=null,lo=kr[--Tr],kr[Tr]=null,ao=kr[--Tr],kr[Tr]=null}var cr=null,ir=null,at=!1,Yr=null;function wk(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 XP(t,e){switch(t.tag){case 5:var n=t.type;return e=e.nodeType!==1||n.toLowerCase()!==e.nodeName.toLowerCase()?null:e,e!==null?(t.stateNode=e,cr=t,ir=oi(e.firstChild),!0):!1;case 6:return e=t.pendingProps===""||e.nodeType!==3?null:e,e!==null?(t.stateNode=e,cr=t,ir=null,!0):!1;case 13:return e=e.nodeType!==8?null:e,e!==null?(n=ra!==null?{id:ao,overflow:lo}:null,t.memoizedState={dehydrated:e,treeContext:n,retryLane:1073741824},n=Ar(18,null,null,0),n.stateNode=e,n.return=t,t.child=n,cr=t,ir=null,!0):!1;default:return!1}}function Cv(t){return(t.mode&1)!==0&&(t.flags&128)===0}function _v(t){if(at){var e=ir;if(e){var n=e;if(!XP(t,e)){if(Cv(t))throw Error(Y(418));e=oi(n.nextSibling);var r=cr;e&&XP(t,e)?wk(r,n):(t.flags=t.flags&-4097|2,at=!1,cr=t)}}else{if(Cv(t))throw Error(Y(418));t.flags=t.flags&-4097|2,at=!1,cr=t}}}function qP(t){for(t=t.return;t!==null&&t.tag!==5&&t.tag!==3&&t.tag!==13;)t=t.return;cr=t}function Xd(t){if(t!==cr)return!1;if(!at)return qP(t),at=!0,!1;var e;if((e=t.tag!==3)&&!(e=t.tag!==5)&&(e=t.type,e=e!=="head"&&e!=="body"&&!xv(t.type,t.memoizedProps)),e&&(e=ir)){if(Cv(t))throw bk(),Error(Y(418));for(;e;)wk(t,e),e=oi(e.nextSibling)}if(qP(t),t.tag===13){if(t=t.memoizedState,t=t!==null?t.dehydrated:null,!t)throw Error(Y(317));e:{for(t=t.nextSibling,e=0;t;){if(t.nodeType===8){var n=t.data;if(n==="/$"){if(e===0){ir=oi(t.nextSibling);break e}e--}else n!=="$"&&n!=="$!"&&n!=="$?"||e++}t=t.nextSibling}ir=null}}else ir=cr?oi(t.stateNode.nextSibling):null;return!0}function bk(){for(var t=ir;t;)t=oi(t.nextSibling)}function El(){ir=cr=null,at=!1}function zw(t){Yr===null?Yr=[t]:Yr.push(t)}var Mz=_o.ReactCurrentBatchConfig;function Sc(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(Y(309));var r=n.stateNode}if(!r)throw Error(Y(147,t));var s=r,o=""+t;return e!==null&&e.ref!==null&&typeof e.ref=="function"&&e.ref._stringRef===o?e.ref:(e=function(i){var a=s.refs;i===null?delete a[o]:a[o]=i},e._stringRef=o,e)}if(typeof t!="string")throw Error(Y(284));if(!n._owner)throw Error(Y(290,t))}return t}function qd(t,e){throw t=Object.prototype.toString.call(e),Error(Y(31,t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t))}function ZP(t){var e=t._init;return e(t._payload)}function Pk(t){function e(y,S){if(t){var b=y.deletions;b===null?(y.deletions=[S],y.flags|=16):b.push(S)}}function n(y,S){if(!t)return null;for(;S!==null;)e(y,S),S=S.sibling;return null}function r(y,S){for(y=new Map;S!==null;)S.key!==null?y.set(S.key,S):y.set(S.index,S),S=S.sibling;return y}function s(y,S){return y=ci(y,S),y.index=0,y.sibling=null,y}function o(y,S,b){return y.index=b,t?(b=y.alternate,b!==null?(b=b.index,b<S?(y.flags|=2,S):b):(y.flags|=2,S)):(y.flags|=1048576,S)}function i(y){return t&&y.alternate===null&&(y.flags|=2),y}function a(y,S,b,P){return S===null||S.tag!==6?(S=iy(b,y.mode,P),S.return=y,S):(S=s(S,b),S.return=y,S)}function l(y,S,b,P){var C=b.type;return C===Ga?u(y,S,b.props.children,P,b.key):S!==null&&(S.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Ko&&ZP(C)===S.type)?(P=s(S,b.props),P.ref=Sc(y,S,b),P.return=y,P):(P=ef(b.type,b.key,b.props,null,y.mode,P),P.ref=Sc(y,S,b),P.return=y,P)}function c(y,S,b,P){return S===null||S.tag!==4||S.stateNode.containerInfo!==b.containerInfo||S.stateNode.implementation!==b.implementation?(S=ay(b,y.mode,P),S.return=y,S):(S=s(S,b.children||[]),S.return=y,S)}function u(y,S,b,P,C){return S===null||S.tag!==7?(S=Zi(b,y.mode,P,C),S.return=y,S):(S=s(S,b),S.return=y,S)}function h(y,S,b){if(typeof S=="string"&&S!==""||typeof S=="number")return S=iy(""+S,y.mode,b),S.return=y,S;if(typeof S=="object"&&S!==null){switch(S.$$typeof){case Nd:return b=ef(S.type,S.key,S.props,null,y.mode,b),b.ref=Sc(y,null,S),b.return=y,b;case Wa:return S=ay(S,y.mode,b),S.return=y,S;case Ko:var P=S._init;return h(y,P(S._payload),b)}if(Nc(S)||fc(S))return S=Zi(S,y.mode,b,null),S.return=y,S;qd(y,S)}return null}function f(y,S,b,P){var C=S!==null?S.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return C!==null?null:a(y,S,""+b,P);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case Nd:return b.key===C?l(y,S,b,P):null;case Wa:return b.key===C?c(y,S,b,P):null;case Ko:return C=b._init,f(y,S,C(b._payload),P)}if(Nc(b)||fc(b))return C!==null?null:u(y,S,b,P,null);qd(y,b)}return null}function p(y,S,b,P,C){if(typeof P=="string"&&P!==""||typeof P=="number")return y=y.get(b)||null,a(S,y,""+P,C);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case Nd:return y=y.get(P.key===null?b:P.key)||null,l(S,y,P,C);case Wa:return y=y.get(P.key===null?b:P.key)||null,c(S,y,P,C);case Ko:var _=P._init;return p(y,S,b,_(P._payload),C)}if(Nc(P)||fc(P))return y=y.get(b)||null,u(S,y,P,C,null);qd(S,P)}return null}function g(y,S,b,P){for(var C=null,_=null,E=S,k=S=0,D=null;E!==null&&k<b.length;k++){E.index>k?(D=E,E=null):D=E.sibling;var T=f(y,E,b[k],P);if(T===null){E===null&&(E=D);break}t&&E&&T.alternate===null&&e(y,E),S=o(T,S,k),_===null?C=T:_.sibling=T,_=T,E=D}if(k===b.length)return n(y,E),at&&Ui(y,k),C;if(E===null){for(;k<b.length;k++)E=h(y,b[k],P),E!==null&&(S=o(E,S,k),_===null?C=E:_.sibling=E,_=E);return at&&Ui(y,k),C}for(E=r(y,E);k<b.length;k++)D=p(E,y,k,b[k],P),D!==null&&(t&&D.alternate!==null&&E.delete(D.key===null?k:D.key),S=o(D,S,k),_===null?C=D:_.sibling=D,_=D);return t&&E.forEach(function(j){return e(y,j)}),at&&Ui(y,k),C}function m(y,S,b,P){var C=fc(b);if(typeof C!="function")throw Error(Y(150));if(b=C.call(b),b==null)throw Error(Y(151));for(var _=C=null,E=S,k=S=0,D=null,T=b.next();E!==null&&!T.done;k++,T=b.next()){E.index>k?(D=E,E=null):D=E.sibling;var j=f(y,E,T.value,P);if(j===null){E===null&&(E=D);break}t&&E&&j.alternate===null&&e(y,E),S=o(j,S,k),_===null?C=j:_.sibling=j,_=j,E=D}if(T.done)return n(y,E),at&&Ui(y,k),C;if(E===null){for(;!T.done;k++,T=b.next())T=h(y,T.value,P),T!==null&&(S=o(T,S,k),_===null?C=T:_.sibling=T,_=T);return at&&Ui(y,k),C}for(E=r(y,E);!T.done;k++,T=b.next())T=p(E,y,k,T.value,P),T!==null&&(t&&T.alternate!==null&&E.delete(T.key===null?k:T.key),S=o(T,S,k),_===null?C=T:_.sibling=T,_=T);return t&&E.forEach(function(L){return e(y,L)}),at&&Ui(y,k),C}function v(y,S,b,P){if(typeof b=="object"&&b!==null&&b.type===Ga&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case Nd:e:{for(var C=b.key,_=S;_!==null;){if(_.key===C){if(C=b.type,C===Ga){if(_.tag===7){n(y,_.sibling),S=s(_,b.props.children),S.return=y,y=S;break e}}else if(_.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===Ko&&ZP(C)===_.type){n(y,_.sibling),S=s(_,b.props),S.ref=Sc(y,_,b),S.return=y,y=S;break e}n(y,_);break}else e(y,_);_=_.sibling}b.type===Ga?(S=Zi(b.props.children,y.mode,P,b.key),S.return=y,y=S):(P=ef(b.type,b.key,b.props,null,y.mode,P),P.ref=Sc(y,S,b),P.return=y,y=P)}return i(y);case Wa:e:{for(_=b.key;S!==null;){if(S.key===_)if(S.tag===4&&S.stateNode.containerInfo===b.containerInfo&&S.stateNode.implementation===b.implementation){n(y,S.sibling),S=s(S,b.children||[]),S.return=y,y=S;break e}else{n(y,S);break}else e(y,S);S=S.sibling}S=ay(b,y.mode,P),S.return=y,y=S}return i(y);case Ko:return _=b._init,v(y,S,_(b._payload),P)}if(Nc(b))return g(y,S,b,P);if(fc(b))return m(y,S,b,P);qd(y,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,S!==null&&S.tag===6?(n(y,S.sibling),S=s(S,b),S.return=y,y=S):(n(y,S),S=iy(b,y.mode,P),S.return=y,y=S),i(y)):n(y,S)}return v}var kl=Pk(!0),Ck=Pk(!1),Qf=Pi(null),Jf=null,el=null,Bw=null;function Uw(){Bw=el=Jf=null}function Hw(t){var e=Qf.current;rt(Qf),t._currentValue=e}function Iv(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 ml(t,e){Jf=t,Bw=el=null,t=t.dependencies,t!==null&&t.firstContext!==null&&(t.lanes&e&&(Hn=!0),t.firstContext=null)}function Rr(t){var e=t._currentValue;if(Bw!==t)if(t={context:t,memoizedValue:e,next:null},el===null){if(Jf===null)throw Error(Y(308));el=t,Jf.dependencies={lanes:0,firstContext:t}}else el=el.next=t;return e}var Vi=null;function Kw(t){Vi===null?Vi=[t]:Vi.push(t)}function _k(t,e,n,r){var s=e.interleaved;return s===null?(n.next=n,Kw(e)):(n.next=s.next,s.next=n),e.interleaved=n,xo(t,r)}function xo(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 Wo=!1;function Ww(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Ik(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 ho(t,e){return{eventTime:t,lane:e,tag:0,payload:null,callback:null,next:null}}function ii(t,e,n){var r=t.updateQueue;if(r===null)return null;if(r=r.shared,Oe&2){var s=r.pending;return s===null?e.next=e:(e.next=s.next,s.next=e),r.pending=e,xo(t,n)}return s=r.interleaved,s===null?(e.next=e,Kw(r)):(e.next=s.next,s.next=e),r.interleaved=e,xo(t,n)}function Yh(t,e,n){if(e=e.updateQueue,e!==null&&(e=e.shared,(n&4194240)!==0)){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,Mw(t,n)}}function QP(t,e){var n=t.updateQueue,r=t.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var s=null,o=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};o===null?s=o=i:o=o.next=i,n=n.next}while(n!==null);o===null?s=o=e:o=o.next=e}else s=o=e;n={baseState:r.baseState,firstBaseUpdate:s,lastBaseUpdate:o,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 ep(t,e,n,r){var s=t.updateQueue;Wo=!1;var o=s.firstBaseUpdate,i=s.lastBaseUpdate,a=s.shared.pending;if(a!==null){s.shared.pending=null;var l=a,c=l.next;l.next=null,i===null?o=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(o!==null){var h=s.baseState;i=0,u=c=l=null,a=o;do{var f=a.lane,p=a.eventTime;if((r&f)===f){u!==null&&(u=u.next={eventTime:p,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var g=t,m=a;switch(f=e,p=n,m.tag){case 1:if(g=m.payload,typeof g=="function"){h=g.call(p,h,f);break e}h=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=m.payload,f=typeof g=="function"?g.call(p,h,f):g,f==null)break e;h=gt({},h,f);break e;case 2:Wo=!0}}a.callback!==null&&a.lane!==0&&(t.flags|=64,f=s.effects,f===null?s.effects=[a]:f.push(a))}else p={eventTime:p,lane:f,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(c=u=p,l=h):u=u.next=p,i|=f;if(a=a.next,a===null){if(a=s.shared.pending,a===null)break;f=a,a=f.next,f.next=null,s.lastBaseUpdate=f,s.shared.pending=null}}while(!0);if(u===null&&(l=h),s.baseState=l,s.firstBaseUpdate=c,s.lastBaseUpdate=u,e=s.shared.interleaved,e!==null){s=e;do i|=s.lane,s=s.next;while(s!==e)}else o===null&&(s.shared.lanes=0);oa|=i,t.lanes=i,t.memoizedState=h}}function JP(t,e,n){if(t=e.effects,e.effects=null,t!==null)for(e=0;e<t.length;e++){var r=t[e],s=r.callback;if(s!==null){if(r.callback=null,r=n,typeof s!="function")throw Error(Y(191,s));s.call(r)}}}var nd={},Ms=Pi(nd),ku=Pi(nd),Tu=Pi(nd);function Yi(t){if(t===nd)throw Error(Y(174));return t}function Gw(t,e){switch(qe(Tu,e),qe(ku,t),qe(Ms,nd),t=e.nodeType,t){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:iv(null,"");break;default:t=t===8?e.parentNode:e,e=t.namespaceURI||null,t=t.tagName,e=iv(e,t)}rt(Ms),qe(Ms,e)}function Tl(){rt(Ms),rt(ku),rt(Tu)}function Ek(t){Yi(Tu.current);var e=Yi(Ms.current),n=iv(e,t.type);e!==n&&(qe(ku,t),qe(Ms,n))}function Vw(t){ku.current===t&&(rt(Ms),rt(ku))}var dt=Pi(0);function tp(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 ey=[];function Yw(){for(var t=0;t<ey.length;t++)ey[t]._workInProgressVersionPrimary=null;ey.length=0}var Xh=_o.ReactCurrentDispatcher,ty=_o.ReactCurrentBatchConfig,sa=0,pt=null,Et=null,jt=null,np=!1,ru=!1,Mu=0,Az=0;function tn(){throw Error(Y(321))}function Xw(t,e){if(e===null)return!1;for(var n=0;n<e.length&&n<t.length;n++)if(!os(t[n],e[n]))return!1;return!0}function qw(t,e,n,r,s,o){if(sa=o,pt=e,e.memoizedState=null,e.updateQueue=null,e.lanes=0,Xh.current=t===null||t.memoizedState===null?Rz:Lz,t=n(r,s),ru){o=0;do{if(ru=!1,Mu=0,25<=o)throw Error(Y(301));o+=1,jt=Et=null,e.updateQueue=null,Xh.current=$z,t=n(r,s)}while(ru)}if(Xh.current=rp,e=Et!==null&&Et.next!==null,sa=0,jt=Et=pt=null,np=!1,e)throw Error(Y(300));return t}function Zw(){var t=Mu!==0;return Mu=0,t}function xs(){var t={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return jt===null?pt.memoizedState=jt=t:jt=jt.next=t,jt}function Lr(){if(Et===null){var t=pt.alternate;t=t!==null?t.memoizedState:null}else t=Et.next;var e=jt===null?pt.memoizedState:jt.next;if(e!==null)jt=e,Et=t;else{if(t===null)throw Error(Y(310));Et=t,t={memoizedState:Et.memoizedState,baseState:Et.baseState,baseQueue:Et.baseQueue,queue:Et.queue,next:null},jt===null?pt.memoizedState=jt=t:jt=jt.next=t}return jt}function Au(t,e){return typeof e=="function"?e(t):e}function ny(t){var e=Lr(),n=e.queue;if(n===null)throw Error(Y(311));n.lastRenderedReducer=t;var r=Et,s=r.baseQueue,o=n.pending;if(o!==null){if(s!==null){var i=s.next;s.next=o.next,o.next=i}r.baseQueue=s=o,n.pending=null}if(s!==null){o=s.next,r=r.baseState;var a=i=null,l=null,c=o;do{var u=c.lane;if((sa&u)===u)l!==null&&(l=l.next={lane:0,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null}),r=c.hasEagerState?c.eagerState:t(r,c.action);else{var h={lane:u,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=h,i=r):l=l.next=h,pt.lanes|=u,oa|=u}c=c.next}while(c!==null&&c!==o);l===null?i=r:l.next=a,os(r,e.memoizedState)||(Hn=!0),e.memoizedState=r,e.baseState=i,e.baseQueue=l,n.lastRenderedState=r}if(t=n.interleaved,t!==null){s=t;do o=s.lane,pt.lanes|=o,oa|=o,s=s.next;while(s!==t)}else s===null&&(n.lanes=0);return[e.memoizedState,n.dispatch]}function ry(t){var e=Lr(),n=e.queue;if(n===null)throw Error(Y(311));n.lastRenderedReducer=t;var r=n.dispatch,s=n.pending,o=e.memoizedState;if(s!==null){n.pending=null;var i=s=s.next;do o=t(o,i.action),i=i.next;while(i!==s);os(o,e.memoizedState)||(Hn=!0),e.memoizedState=o,e.baseQueue===null&&(e.baseState=o),n.lastRenderedState=o}return[o,r]}function kk(){}function Tk(t,e){var n=pt,r=Lr(),s=e(),o=!os(r.memoizedState,s);if(o&&(r.memoizedState=s,Hn=!0),r=r.queue,Qw(jk.bind(null,n,r,t),[t]),r.getSnapshot!==e||o||jt!==null&&jt.memoizedState.tag&1){if(n.flags|=2048,ju(9,Ak.bind(null,n,r,s,e),void 0,null),Rt===null)throw Error(Y(349));sa&30||Mk(n,e,s)}return s}function Mk(t,e,n){t.flags|=16384,t={getSnapshot:e,value:n},e=pt.updateQueue,e===null?(e={lastEffect:null,stores:null},pt.updateQueue=e,e.stores=[t]):(n=e.stores,n===null?e.stores=[t]:n.push(t))}function Ak(t,e,n,r){e.value=n,e.getSnapshot=r,Ok(e)&&Dk(t)}function jk(t,e,n){return n(function(){Ok(e)&&Dk(t)})}function Ok(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!os(t,n)}catch{return!0}}function Dk(t){var e=xo(t,1);e!==null&&ts(e,t,1,-1)}function eC(t){var e=xs();return typeof t=="function"&&(t=t()),e.memoizedState=e.baseState=t,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Au,lastRenderedState:t},e.queue=t,t=t.dispatch=Dz.bind(null,pt,t),[e.memoizedState,t]}function ju(t,e,n,r){return t={tag:t,create:e,destroy:n,deps:r,next:null},e=pt.updateQueue,e===null?(e={lastEffect:null,stores:null},pt.updateQueue=e,e.lastEffect=t.next=t):(n=e.lastEffect,n===null?e.lastEffect=t.next=t:(r=n.next,n.next=t,t.next=r,e.lastEffect=t)),t}function Rk(){return Lr().memoizedState}function qh(t,e,n,r){var s=xs();pt.flags|=t,s.memoizedState=ju(1|e,n,void 0,r===void 0?null:r)}function ig(t,e,n,r){var s=Lr();r=r===void 0?null:r;var o=void 0;if(Et!==null){var i=Et.memoizedState;if(o=i.destroy,r!==null&&Xw(r,i.deps)){s.memoizedState=ju(e,n,o,r);return}}pt.flags|=t,s.memoizedState=ju(1|e,n,o,r)}function tC(t,e){return qh(8390656,8,t,e)}function Qw(t,e){return ig(2048,8,t,e)}function Lk(t,e){return ig(4,2,t,e)}function $k(t,e){return ig(4,4,t,e)}function Fk(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 Nk(t,e,n){return n=n!=null?n.concat([t]):null,ig(4,4,Fk.bind(null,e,t),n)}function Jw(){}function zk(t,e){var n=Lr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&Xw(e,r[1])?r[0]:(n.memoizedState=[t,e],t)}function Bk(t,e){var n=Lr();e=e===void 0?null:e;var r=n.memoizedState;return r!==null&&e!==null&&Xw(e,r[1])?r[0]:(t=t(),n.memoizedState=[t,e],t)}function Uk(t,e,n){return sa&21?(os(n,e)||(n=V2(),pt.lanes|=n,oa|=n,t.baseState=!0),e):(t.baseState&&(t.baseState=!1,Hn=!0),t.memoizedState=n)}function jz(t,e){var n=Be;Be=n!==0&&4>n?n:4,t(!0);var r=ty.transition;ty.transition={};try{t(!1),e()}finally{Be=n,ty.transition=r}}function Hk(){return Lr().memoizedState}function Oz(t,e,n){var r=li(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Kk(t))Wk(e,n);else if(n=_k(t,e,n,r),n!==null){var s=Pn();ts(n,t,r,s),Gk(n,e,r)}}function Dz(t,e,n){var r=li(t),s={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Kk(t))Wk(e,s);else{var o=t.alternate;if(t.lanes===0&&(o===null||o.lanes===0)&&(o=e.lastRenderedReducer,o!==null))try{var i=e.lastRenderedState,a=o(i,n);if(s.hasEagerState=!0,s.eagerState=a,os(a,i)){var l=e.interleaved;l===null?(s.next=s,Kw(e)):(s.next=l.next,l.next=s),e.interleaved=s;return}}catch{}finally{}n=_k(t,e,s,r),n!==null&&(s=Pn(),ts(n,t,r,s),Gk(n,e,r))}}function Kk(t){var e=t.alternate;return t===pt||e!==null&&e===pt}function Wk(t,e){ru=np=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function Gk(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,Mw(t,n)}}var rp={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},Rz={readContext:Rr,useCallback:function(t,e){return xs().memoizedState=[t,e===void 0?null:e],t},useContext:Rr,useEffect:tC,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,qh(4194308,4,Fk.bind(null,e,t),n)},useLayoutEffect:function(t,e){return qh(4194308,4,t,e)},useInsertionEffect:function(t,e){return qh(4,2,t,e)},useMemo:function(t,e){var n=xs();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=xs();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=Oz.bind(null,pt,t),[r.memoizedState,t]},useRef:function(t){var e=xs();return t={current:t},e.memoizedState=t},useState:eC,useDebugValue:Jw,useDeferredValue:function(t){return xs().memoizedState=t},useTransition:function(){var t=eC(!1),e=t[0];return t=jz.bind(null,t[1]),xs().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=pt,s=xs();if(at){if(n===void 0)throw Error(Y(407));n=n()}else{if(n=e(),Rt===null)throw Error(Y(349));sa&30||Mk(r,e,n)}s.memoizedState=n;var o={value:n,getSnapshot:e};return s.queue=o,tC(jk.bind(null,r,o,t),[t]),r.flags|=2048,ju(9,Ak.bind(null,r,o,n,e),void 0,null),n},useId:function(){var t=xs(),e=Rt.identifierPrefix;if(at){var n=lo,r=ao;n=(r&~(1<<32-es(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=Mu++,0<n&&(e+="H"+n.toString(32)),e+=":"}else n=Az++,e=":"+e+"r"+n.toString(32)+":";return t.memoizedState=e},unstable_isNewReconciler:!1},Lz={readContext:Rr,useCallback:zk,useContext:Rr,useEffect:Qw,useImperativeHandle:Nk,useInsertionEffect:Lk,useLayoutEffect:$k,useMemo:Bk,useReducer:ny,useRef:Rk,useState:function(){return ny(Au)},useDebugValue:Jw,useDeferredValue:function(t){var e=Lr();return Uk(e,Et.memoizedState,t)},useTransition:function(){var t=ny(Au)[0],e=Lr().memoizedState;return[t,e]},useMutableSource:kk,useSyncExternalStore:Tk,useId:Hk,unstable_isNewReconciler:!1},$z={readContext:Rr,useCallback:zk,useContext:Rr,useEffect:Qw,useImperativeHandle:Nk,useInsertionEffect:Lk,useLayoutEffect:$k,useMemo:Bk,useReducer:ry,useRef:Rk,useState:function(){return ry(Au)},useDebugValue:Jw,useDeferredValue:function(t){var e=Lr();return Et===null?e.memoizedState=t:Uk(e,Et.memoizedState,t)},useTransition:function(){var t=ry(Au)[0],e=Lr().memoizedState;return[t,e]},useMutableSource:kk,useSyncExternalStore:Tk,useId:Hk,unstable_isNewReconciler:!1};function Kr(t,e){if(t&&t.defaultProps){e=gt({},e),t=t.defaultProps;for(var n in t)e[n]===void 0&&(e[n]=t[n]);return e}return e}function Ev(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 ag={isMounted:function(t){return(t=t._reactInternals)?wa(t)===t:!1},enqueueSetState:function(t,e,n){t=t._reactInternals;var r=Pn(),s=li(t),o=ho(r,s);o.payload=e,n!=null&&(o.callback=n),e=ii(t,o,s),e!==null&&(ts(e,t,s,r),Yh(e,t,s))},enqueueReplaceState:function(t,e,n){t=t._reactInternals;var r=Pn(),s=li(t),o=ho(r,s);o.tag=1,o.payload=e,n!=null&&(o.callback=n),e=ii(t,o,s),e!==null&&(ts(e,t,s,r),Yh(e,t,s))},enqueueForceUpdate:function(t,e){t=t._reactInternals;var n=Pn(),r=li(t),s=ho(n,r);s.tag=2,e!=null&&(s.callback=e),e=ii(t,s,r),e!==null&&(ts(e,t,r,n),Yh(e,t,r))}};function nC(t,e,n,r,s,o,i){return t=t.stateNode,typeof t.shouldComponentUpdate=="function"?t.shouldComponentUpdate(r,o,i):e.prototype&&e.prototype.isPureReactComponent?!Cu(n,r)||!Cu(s,o):!0}function Vk(t,e,n){var r=!1,s=pi,o=e.contextType;return typeof o=="object"&&o!==null?o=Rr(o):(s=Vn(e)?na:gn.current,r=e.contextTypes,o=(r=r!=null)?Il(t,s):pi),e=new e(n,o),t.memoizedState=e.state!==null&&e.state!==void 0?e.state:null,e.updater=ag,t.stateNode=e,e._reactInternals=t,r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=s,t.__reactInternalMemoizedMaskedChildContext=o),e}function rC(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&&ag.enqueueReplaceState(e,e.state,null)}function kv(t,e,n,r){var s=t.stateNode;s.props=n,s.state=t.memoizedState,s.refs={},Ww(t);var o=e.contextType;typeof o=="object"&&o!==null?s.context=Rr(o):(o=Vn(e)?na:gn.current,s.context=Il(t,o)),s.state=t.memoizedState,o=e.getDerivedStateFromProps,typeof o=="function"&&(Ev(t,e,o,n),s.state=t.memoizedState),typeof e.getDerivedStateFromProps=="function"||typeof s.getSnapshotBeforeUpdate=="function"||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(e=s.state,typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount(),e!==s.state&&ag.enqueueReplaceState(s,s.state,null),ep(t,n,s,r),s.state=t.memoizedState),typeof s.componentDidMount=="function"&&(t.flags|=4194308)}function Ml(t,e){try{var n="",r=e;do n+=d6(r),r=r.return;while(r);var s=n}catch(o){s=`
|
|
39
|
+
Error generating stack: `+o.message+`
|
|
40
|
+
`+o.stack}return{value:t,source:e,stack:s,digest:null}}function sy(t,e,n){return{value:t,source:null,stack:n??null,digest:e??null}}function Tv(t,e){try{console.error(e.value)}catch(n){setTimeout(function(){throw n})}}var Fz=typeof WeakMap=="function"?WeakMap:Map;function Yk(t,e,n){n=ho(-1,n),n.tag=3,n.payload={element:null};var r=e.value;return n.callback=function(){op||(op=!0,Nv=r),Tv(t,e)},n}function Xk(t,e,n){n=ho(-1,n),n.tag=3;var r=t.type.getDerivedStateFromError;if(typeof r=="function"){var s=e.value;n.payload=function(){return r(s)},n.callback=function(){Tv(t,e)}}var o=t.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(n.callback=function(){Tv(t,e),typeof r!="function"&&(ai===null?ai=new Set([this]):ai.add(this));var i=e.stack;this.componentDidCatch(e.value,{componentStack:i!==null?i:""})}),n}function sC(t,e,n){var r=t.pingCache;if(r===null){r=t.pingCache=new Fz;var s=new Set;r.set(e,s)}else s=r.get(e),s===void 0&&(s=new Set,r.set(e,s));s.has(n)||(s.add(n),t=Qz.bind(null,t,e,n),e.then(t,t))}function oC(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 iC(t,e,n,r,s){return t.mode&1?(t.flags|=65536,t.lanes=s,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=ho(-1,1),e.tag=2,ii(n,e,1))),n.lanes|=1),t)}var Nz=_o.ReactCurrentOwner,Hn=!1;function xn(t,e,n,r){e.child=t===null?Ck(e,null,n,r):kl(e,t.child,n,r)}function aC(t,e,n,r,s){n=n.render;var o=e.ref;return ml(e,s),r=qw(t,e,n,r,o,s),n=Zw(),t!==null&&!Hn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~s,wo(t,e,s)):(at&&n&&Fw(e),e.flags|=1,xn(t,e,r,s),e.child)}function lC(t,e,n,r,s){if(t===null){var o=n.type;return typeof o=="function"&&!a0(o)&&o.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(e.tag=15,e.type=o,qk(t,e,o,r,s)):(t=ef(n.type,null,r,e,e.mode,s),t.ref=e.ref,t.return=e,e.child=t)}if(o=t.child,!(t.lanes&s)){var i=o.memoizedProps;if(n=n.compare,n=n!==null?n:Cu,n(i,r)&&t.ref===e.ref)return wo(t,e,s)}return e.flags|=1,t=ci(o,r),t.ref=e.ref,t.return=e,e.child=t}function qk(t,e,n,r,s){if(t!==null){var o=t.memoizedProps;if(Cu(o,r)&&t.ref===e.ref)if(Hn=!1,e.pendingProps=r=o,(t.lanes&s)!==0)t.flags&131072&&(Hn=!0);else return e.lanes=t.lanes,wo(t,e,s)}return Mv(t,e,n,r,s)}function Zk(t,e,n){var r=e.pendingProps,s=r.children,o=t!==null?t.memoizedState:null;if(r.mode==="hidden")if(!(e.mode&1))e.memoizedState={baseLanes:0,cachePool:null,transitions:null},qe(nl,sr),sr|=n;else{if(!(n&1073741824))return t=o!==null?o.baseLanes|n:n,e.lanes=e.childLanes=1073741824,e.memoizedState={baseLanes:t,cachePool:null,transitions:null},e.updateQueue=null,qe(nl,sr),sr|=t,null;e.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:n,qe(nl,sr),sr|=r}else o!==null?(r=o.baseLanes|n,e.memoizedState=null):r=n,qe(nl,sr),sr|=r;return xn(t,e,s,n),e.child}function Qk(t,e){var n=e.ref;(t===null&&n!==null||t!==null&&t.ref!==n)&&(e.flags|=512,e.flags|=2097152)}function Mv(t,e,n,r,s){var o=Vn(n)?na:gn.current;return o=Il(e,o),ml(e,s),n=qw(t,e,n,r,o,s),r=Zw(),t!==null&&!Hn?(e.updateQueue=t.updateQueue,e.flags&=-2053,t.lanes&=~s,wo(t,e,s)):(at&&r&&Fw(e),e.flags|=1,xn(t,e,n,s),e.child)}function cC(t,e,n,r,s){if(Vn(n)){var o=!0;Xf(e)}else o=!1;if(ml(e,s),e.stateNode===null)Zh(t,e),Vk(e,n,r),kv(e,n,r,s),r=!0;else if(t===null){var i=e.stateNode,a=e.memoizedProps;i.props=a;var l=i.context,c=n.contextType;typeof c=="object"&&c!==null?c=Rr(c):(c=Vn(n)?na:gn.current,c=Il(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)&&rC(e,i,r,c),Wo=!1;var f=e.memoizedState;i.state=f,ep(e,r,i,s),l=e.memoizedState,a!==r||f!==l||Gn.current||Wo?(typeof u=="function"&&(Ev(e,n,u,r),l=e.memoizedState),(a=Wo||nC(e,n,a,r,f,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,Ik(t,e),a=e.memoizedProps,c=e.type===e.elementType?a:Kr(e.type,a),i.props=c,h=e.pendingProps,f=i.context,l=n.contextType,typeof l=="object"&&l!==null?l=Rr(l):(l=Vn(n)?na:gn.current,l=Il(e,l));var p=n.getDerivedStateFromProps;(u=typeof p=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==h||f!==l)&&rC(e,i,r,l),Wo=!1,f=e.memoizedState,i.state=f,ep(e,r,i,s);var g=e.memoizedState;a!==h||f!==g||Gn.current||Wo?(typeof p=="function"&&(Ev(e,n,p,r),g=e.memoizedState),(c=Wo||nC(e,n,c,r,f,g,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,g,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,g,l)),typeof i.componentDidUpdate=="function"&&(e.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(e.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===t.memoizedProps&&f===t.memoizedState||(e.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===t.memoizedProps&&f===t.memoizedState||(e.flags|=1024),e.memoizedProps=r,e.memoizedState=g),i.props=r,i.state=g,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===t.memoizedProps&&f===t.memoizedState||(e.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===t.memoizedProps&&f===t.memoizedState||(e.flags|=1024),r=!1)}return Av(t,e,n,r,o,s)}function Av(t,e,n,r,s,o){Qk(t,e);var i=(e.flags&128)!==0;if(!r&&!i)return s&&YP(e,n,!1),wo(t,e,o);r=e.stateNode,Nz.current=e;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return e.flags|=1,t!==null&&i?(e.child=kl(e,t.child,null,o),e.child=kl(e,null,a,o)):xn(t,e,a,o),e.memoizedState=r.state,s&&YP(e,n,!0),e.child}function Jk(t){var e=t.stateNode;e.pendingContext?VP(t,e.pendingContext,e.pendingContext!==e.context):e.context&&VP(t,e.context,!1),Gw(t,e.containerInfo)}function uC(t,e,n,r,s){return El(),zw(s),e.flags|=256,xn(t,e,n,r),e.child}var jv={dehydrated:null,treeContext:null,retryLane:0};function Ov(t){return{baseLanes:t,cachePool:null,transitions:null}}function eT(t,e,n){var r=e.pendingProps,s=dt.current,o=!1,i=(e.flags&128)!==0,a;if((a=i)||(a=t!==null&&t.memoizedState===null?!1:(s&2)!==0),a?(o=!0,e.flags&=-129):(t===null||t.memoizedState!==null)&&(s|=1),qe(dt,s&1),t===null)return _v(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,o?(r=e.mode,o=e.child,i={mode:"hidden",children:i},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=i):o=ug(i,r,0,null),t=Zi(t,r,n,null),o.return=e,t.return=e,o.sibling=t,e.child=o,e.child.memoizedState=Ov(n),e.memoizedState=jv,t):e0(e,i));if(s=t.memoizedState,s!==null&&(a=s.dehydrated,a!==null))return zz(t,e,i,r,a,s,n);if(o){o=r.fallback,i=e.mode,s=t.child,a=s.sibling;var l={mode:"hidden",children:r.children};return!(i&1)&&e.child!==s?(r=e.child,r.childLanes=0,r.pendingProps=l,e.deletions=null):(r=ci(s,l),r.subtreeFlags=s.subtreeFlags&14680064),a!==null?o=ci(a,o):(o=Zi(o,i,n,null),o.flags|=2),o.return=e,r.return=e,r.sibling=o,e.child=r,r=o,o=e.child,i=t.child.memoizedState,i=i===null?Ov(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},o.memoizedState=i,o.childLanes=t.childLanes&~n,e.memoizedState=jv,r}return o=t.child,t=o.sibling,r=ci(o,{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 e0(t,e){return e=ug({mode:"visible",children:e},t.mode,0,null),e.return=t,t.child=e}function Zd(t,e,n,r){return r!==null&&zw(r),kl(e,t.child,null,n),t=e0(e,e.pendingProps.children),t.flags|=2,e.memoizedState=null,t}function zz(t,e,n,r,s,o,i){if(n)return e.flags&256?(e.flags&=-257,r=sy(Error(Y(422))),Zd(t,e,i,r)):e.memoizedState!==null?(e.child=t.child,e.flags|=128,null):(o=r.fallback,s=e.mode,r=ug({mode:"visible",children:r.children},s,0,null),o=Zi(o,s,i,null),o.flags|=2,r.return=e,o.return=e,r.sibling=o,e.child=r,e.mode&1&&kl(e,t.child,null,i),e.child.memoizedState=Ov(i),e.memoizedState=jv,o);if(!(e.mode&1))return Zd(t,e,i,null);if(s.data==="$!"){if(r=s.nextSibling&&s.nextSibling.dataset,r)var a=r.dgst;return r=a,o=Error(Y(419)),r=sy(o,r,void 0),Zd(t,e,i,r)}if(a=(i&t.childLanes)!==0,Hn||a){if(r=Rt,r!==null){switch(i&-i){case 4:s=2;break;case 16:s=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:s=32;break;case 536870912:s=268435456;break;default:s=0}s=s&(r.suspendedLanes|i)?0:s,s!==0&&s!==o.retryLane&&(o.retryLane=s,xo(t,s),ts(r,t,s,-1))}return i0(),r=sy(Error(Y(421))),Zd(t,e,i,r)}return s.data==="$?"?(e.flags|=128,e.child=t.child,e=Jz.bind(null,t),s._reactRetry=e,null):(t=o.treeContext,ir=oi(s.nextSibling),cr=e,at=!0,Yr=null,t!==null&&(kr[Tr++]=ao,kr[Tr++]=lo,kr[Tr++]=ra,ao=t.id,lo=t.overflow,ra=e),e=e0(e,r.children),e.flags|=4096,e)}function dC(t,e,n){t.lanes|=e;var r=t.alternate;r!==null&&(r.lanes|=e),Iv(t.return,e,n)}function oy(t,e,n,r,s){var o=t.memoizedState;o===null?t.memoizedState={isBackwards:e,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:s}:(o.isBackwards=e,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=s)}function tT(t,e,n){var r=e.pendingProps,s=r.revealOrder,o=r.tail;if(xn(t,e,r.children,n),r=dt.current,r&2)r=r&1|2,e.flags|=128;else{if(t!==null&&t.flags&128)e:for(t=e.child;t!==null;){if(t.tag===13)t.memoizedState!==null&&dC(t,n,e);else if(t.tag===19)dC(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(s){case"forwards":for(n=e.child,s=null;n!==null;)t=n.alternate,t!==null&&tp(t)===null&&(s=n),n=n.sibling;n=s,n===null?(s=e.child,e.child=null):(s=n.sibling,n.sibling=null),oy(e,!1,s,n,o);break;case"backwards":for(n=null,s=e.child,e.child=null;s!==null;){if(t=s.alternate,t!==null&&tp(t)===null){e.child=s;break}t=s.sibling,s.sibling=n,n=s,s=t}oy(e,!0,n,null,o);break;case"together":oy(e,!1,null,null,void 0);break;default:e.memoizedState=null}return e.child}function Zh(t,e){!(e.mode&1)&&t!==null&&(t.alternate=null,e.alternate=null,e.flags|=2)}function wo(t,e,n){if(t!==null&&(e.dependencies=t.dependencies),oa|=e.lanes,!(n&e.childLanes))return null;if(t!==null&&e.child!==t.child)throw Error(Y(153));if(e.child!==null){for(t=e.child,n=ci(t,t.pendingProps),e.child=n,n.return=e;t.sibling!==null;)t=t.sibling,n=n.sibling=ci(t,t.pendingProps),n.return=e;n.sibling=null}return e.child}function Bz(t,e,n){switch(e.tag){case 3:Jk(e),El();break;case 5:Ek(e);break;case 1:Vn(e.type)&&Xf(e);break;case 4:Gw(e,e.stateNode.containerInfo);break;case 10:var r=e.type._context,s=e.memoizedProps.value;qe(Qf,r._currentValue),r._currentValue=s;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?eT(t,e,n):(qe(dt,dt.current&1),t=wo(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 tT(t,e,n);e.flags|=128}if(s=e.memoizedState,s!==null&&(s.rendering=null,s.tail=null,s.lastEffect=null),qe(dt,dt.current),r)break;return null;case 22:case 23:return e.lanes=0,Zk(t,e,n)}return wo(t,e,n)}var nT,Dv,rT,sT;nT=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}};Dv=function(){};rT=function(t,e,n,r){var s=t.memoizedProps;if(s!==r){t=e.stateNode,Yi(Ms.current);var o=null;switch(n){case"input":s=nv(t,s),r=nv(t,r),o=[];break;case"select":s=gt({},s,{value:void 0}),r=gt({},r,{value:void 0}),o=[];break;case"textarea":s=ov(t,s),r=ov(t,r),o=[];break;default:typeof s.onClick!="function"&&typeof r.onClick=="function"&&(t.onclick=Vf)}av(n,r);var i;n=null;for(c in s)if(!r.hasOwnProperty(c)&&s.hasOwnProperty(c)&&s[c]!=null)if(c==="style"){var a=s[c];for(i in a)a.hasOwnProperty(i)&&(n||(n={}),n[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(yu.hasOwnProperty(c)?o||(o=[]):(o=o||[]).push(c,null));for(c in r){var l=r[c];if(a=s!=null?s[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||(o||(o=[]),o.push(c,n)),n=l;else c==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,a=a?a.__html:void 0,l!=null&&a!==l&&(o=o||[]).push(c,l)):c==="children"?typeof l!="string"&&typeof l!="number"||(o=o||[]).push(c,""+l):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(yu.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&tt("scroll",t),o||a===l||(o=[])):(o=o||[]).push(c,l))}n&&(o=o||[]).push("style",n);var c=o;(e.updateQueue=c)&&(e.flags|=4)}};sT=function(t,e,n,r){n!==r&&(e.flags|=4)};function vc(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 s=t.child;s!==null;)n|=s.lanes|s.childLanes,r|=s.subtreeFlags&14680064,r|=s.flags&14680064,s.return=t,s=s.sibling;else for(s=t.child;s!==null;)n|=s.lanes|s.childLanes,r|=s.subtreeFlags,r|=s.flags,s.return=t,s=s.sibling;return t.subtreeFlags|=r,t.childLanes=n,e}function Uz(t,e,n){var r=e.pendingProps;switch(Nw(e),e.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return nn(e),null;case 1:return Vn(e.type)&&Yf(),nn(e),null;case 3:return r=e.stateNode,Tl(),rt(Gn),rt(gn),Yw(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(t===null||t.child===null)&&(Xd(e)?e.flags|=4:t===null||t.memoizedState.isDehydrated&&!(e.flags&256)||(e.flags|=1024,Yr!==null&&(Uv(Yr),Yr=null))),Dv(t,e),nn(e),null;case 5:Vw(e);var s=Yi(Tu.current);if(n=e.type,t!==null&&e.stateNode!=null)rT(t,e,n,r,s),t.ref!==e.ref&&(e.flags|=512,e.flags|=2097152);else{if(!r){if(e.stateNode===null)throw Error(Y(166));return nn(e),null}if(t=Yi(Ms.current),Xd(e)){r=e.stateNode,n=e.type;var o=e.memoizedProps;switch(r[bs]=e,r[Eu]=o,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(s=0;s<Bc.length;s++)tt(Bc[s],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":xP(r,o),tt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!o.multiple},tt("invalid",r);break;case"textarea":bP(r,o),tt("invalid",r)}av(n,o),s=null;for(var i in o)if(o.hasOwnProperty(i)){var a=o[i];i==="children"?typeof a=="string"?r.textContent!==a&&(o.suppressHydrationWarning!==!0&&Yd(r.textContent,a,t),s=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(o.suppressHydrationWarning!==!0&&Yd(r.textContent,a,t),s=["children",""+a]):yu.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&tt("scroll",r)}switch(n){case"input":zd(r),wP(r,o,!0);break;case"textarea":zd(r),PP(r);break;case"select":case"option":break;default:typeof o.onClick=="function"&&(r.onclick=Vf)}r=s,e.updateQueue=r,r!==null&&(e.flags|=4)}else{i=s.nodeType===9?s:s.ownerDocument,t==="http://www.w3.org/1999/xhtml"&&(t=j2(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[bs]=e,t[Eu]=r,nT(t,e,!1,!1),e.stateNode=t;e:{switch(i=lv(n,r),n){case"dialog":tt("cancel",t),tt("close",t),s=r;break;case"iframe":case"object":case"embed":tt("load",t),s=r;break;case"video":case"audio":for(s=0;s<Bc.length;s++)tt(Bc[s],t);s=r;break;case"source":tt("error",t),s=r;break;case"img":case"image":case"link":tt("error",t),tt("load",t),s=r;break;case"details":tt("toggle",t),s=r;break;case"input":xP(t,r),s=nv(t,r),tt("invalid",t);break;case"option":s=r;break;case"select":t._wrapperState={wasMultiple:!!r.multiple},s=gt({},r,{value:void 0}),tt("invalid",t);break;case"textarea":bP(t,r),s=ov(t,r),tt("invalid",t);break;default:s=r}av(n,s),a=s;for(o in a)if(a.hasOwnProperty(o)){var l=a[o];o==="style"?R2(t,l):o==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&O2(t,l)):o==="children"?typeof l=="string"?(n!=="textarea"||l!=="")&&Su(t,l):typeof l=="number"&&Su(t,""+l):o!=="suppressContentEditableWarning"&&o!=="suppressHydrationWarning"&&o!=="autoFocus"&&(yu.hasOwnProperty(o)?l!=null&&o==="onScroll"&&tt("scroll",t):l!=null&&Cw(t,o,l,i))}switch(n){case"input":zd(t),wP(t,r,!1);break;case"textarea":zd(t),PP(t);break;case"option":r.value!=null&&t.setAttribute("value",""+fi(r.value));break;case"select":t.multiple=!!r.multiple,o=r.value,o!=null?hl(t,!!r.multiple,o,!1):r.defaultValue!=null&&hl(t,!!r.multiple,r.defaultValue,!0);break;default:typeof s.onClick=="function"&&(t.onclick=Vf)}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)sT(t,e,t.memoizedProps,r);else{if(typeof r!="string"&&e.stateNode===null)throw Error(Y(166));if(n=Yi(Tu.current),Yi(Ms.current),Xd(e)){if(r=e.stateNode,n=e.memoizedProps,r[bs]=e,(o=r.nodeValue!==n)&&(t=cr,t!==null))switch(t.tag){case 3:Yd(r.nodeValue,n,(t.mode&1)!==0);break;case 5:t.memoizedProps.suppressHydrationWarning!==!0&&Yd(r.nodeValue,n,(t.mode&1)!==0)}o&&(e.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[bs]=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&&ir!==null&&e.mode&1&&!(e.flags&128))bk(),El(),e.flags|=98560,o=!1;else if(o=Xd(e),r!==null&&r.dehydrated!==null){if(t===null){if(!o)throw Error(Y(318));if(o=e.memoizedState,o=o!==null?o.dehydrated:null,!o)throw Error(Y(317));o[bs]=e}else El(),!(e.flags&128)&&(e.memoizedState=null),e.flags|=4;nn(e),o=!1}else Yr!==null&&(Uv(Yr),Yr=null),o=!0;if(!o)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?kt===0&&(kt=3):i0())),e.updateQueue!==null&&(e.flags|=4),nn(e),null);case 4:return Tl(),Dv(t,e),t===null&&_u(e.stateNode.containerInfo),nn(e),null;case 10:return Hw(e.type._context),nn(e),null;case 17:return Vn(e.type)&&Yf(),nn(e),null;case 19:if(rt(dt),o=e.memoizedState,o===null)return nn(e),null;if(r=(e.flags&128)!==0,i=o.rendering,i===null)if(r)vc(o,!1);else{if(kt!==0||t!==null&&t.flags&128)for(t=e.child;t!==null;){if(i=tp(t),i!==null){for(e.flags|=128,vc(o,!1),r=i.updateQueue,r!==null&&(e.updateQueue=r,e.flags|=4),e.subtreeFlags=0,r=n,n=e.child;n!==null;)o=n,t=r,o.flags&=14680066,i=o.alternate,i===null?(o.childLanes=0,o.lanes=t,o.child=null,o.subtreeFlags=0,o.memoizedProps=null,o.memoizedState=null,o.updateQueue=null,o.dependencies=null,o.stateNode=null):(o.childLanes=i.childLanes,o.lanes=i.lanes,o.child=i.child,o.subtreeFlags=0,o.deletions=null,o.memoizedProps=i.memoizedProps,o.memoizedState=i.memoizedState,o.updateQueue=i.updateQueue,o.type=i.type,t=i.dependencies,o.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}o.tail!==null&&xt()>Al&&(e.flags|=128,r=!0,vc(o,!1),e.lanes=4194304)}else{if(!r)if(t=tp(i),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),vc(o,!0),o.tail===null&&o.tailMode==="hidden"&&!i.alternate&&!at)return nn(e),null}else 2*xt()-o.renderingStartTime>Al&&n!==1073741824&&(e.flags|=128,r=!0,vc(o,!1),e.lanes=4194304);o.isBackwards?(i.sibling=e.child,e.child=i):(n=o.last,n!==null?n.sibling=i:e.child=i,o.last=i)}return o.tail!==null?(e=o.tail,o.rendering=e,o.tail=e.sibling,o.renderingStartTime=xt(),e.sibling=null,n=dt.current,qe(dt,r?n&1|2:n&1),e):(nn(e),null);case 22:case 23:return o0(),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(Y(156,e.tag))}function Hz(t,e){switch(Nw(e),e.tag){case 1:return Vn(e.type)&&Yf(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return Tl(),rt(Gn),rt(gn),Yw(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Vw(e),null;case 13:if(rt(dt),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(Y(340));El()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return rt(dt),null;case 4:return Tl(),null;case 10:return Hw(e.type._context),null;case 22:case 23:return o0(),null;case 24:return null;default:return null}}var Qd=!1,ln=!1,Kz=typeof WeakSet=="function"?WeakSet:Set,re=null;function tl(t,e){var n=t.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){yt(t,e,r)}else n.current=null}function Rv(t,e,n){try{n()}catch(r){yt(t,e,r)}}var hC=!1;function Wz(t,e){if(Sv=Kf,t=ck(),$w(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 s=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var i=0,a=-1,l=-1,c=0,u=0,h=t,f=null;t:for(;;){for(var p;h!==n||s!==0&&h.nodeType!==3||(a=i+s),h!==o||r!==0&&h.nodeType!==3||(l=i+r),h.nodeType===3&&(i+=h.nodeValue.length),(p=h.firstChild)!==null;)f=h,h=p;for(;;){if(h===t)break t;if(f===n&&++c===s&&(a=i),f===o&&++u===r&&(l=i),(p=h.nextSibling)!==null)break;h=f,f=h.parentNode}h=p}n=a===-1||l===-1?null:{start:a,end:l}}else n=null}n=n||{start:0,end:0}}else n=null;for(vv={focusedElem:t,selectionRange:n},Kf=!1,re=e;re!==null;)if(e=re,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,re=t;else for(;re!==null;){e=re;try{var g=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var m=g.memoizedProps,v=g.memoizedState,y=e.stateNode,S=y.getSnapshotBeforeUpdate(e.elementType===e.type?m:Kr(e.type,m),v);y.__reactInternalSnapshotBeforeUpdate=S}break;case 3:var b=e.stateNode.containerInfo;b.nodeType===1?b.textContent="":b.nodeType===9&&b.documentElement&&b.removeChild(b.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Y(163))}}catch(P){yt(e,e.return,P)}if(t=e.sibling,t!==null){t.return=e.return,re=t;break}re=e.return}return g=hC,hC=!1,g}function su(t,e,n){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var s=r=r.next;do{if((s.tag&t)===t){var o=s.destroy;s.destroy=void 0,o!==void 0&&Rv(e,n,o)}s=s.next}while(s!==r)}}function lg(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 Lv(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 oT(t){var e=t.alternate;e!==null&&(t.alternate=null,oT(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[bs],delete e[Eu],delete e[bv],delete e[Ez],delete e[kz])),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 iT(t){return t.tag===5||t.tag===3||t.tag===4}function fC(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||iT(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 $v(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=Vf));else if(r!==4&&(t=t.child,t!==null))for($v(t,e,n),t=t.sibling;t!==null;)$v(t,e,n),t=t.sibling}function Fv(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(Fv(t,e,n),t=t.sibling;t!==null;)Fv(t,e,n),t=t.sibling}var zt=null,Wr=!1;function $o(t,e,n){for(n=n.child;n!==null;)aT(t,e,n),n=n.sibling}function aT(t,e,n){if(Ts&&typeof Ts.onCommitFiberUnmount=="function")try{Ts.onCommitFiberUnmount(eg,n)}catch{}switch(n.tag){case 5:ln||tl(n,e);case 6:var r=zt,s=Wr;zt=null,$o(t,e,n),zt=r,Wr=s,zt!==null&&(Wr?(t=zt,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):zt.removeChild(n.stateNode));break;case 18:zt!==null&&(Wr?(t=zt,n=n.stateNode,t.nodeType===8?Qm(t.parentNode,n):t.nodeType===1&&Qm(t,n),bu(t)):Qm(zt,n.stateNode));break;case 4:r=zt,s=Wr,zt=n.stateNode.containerInfo,Wr=!0,$o(t,e,n),zt=r,Wr=s;break;case 0:case 11:case 14:case 15:if(!ln&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){s=r=r.next;do{var o=s,i=o.destroy;o=o.tag,i!==void 0&&(o&2||o&4)&&Rv(n,e,i),s=s.next}while(s!==r)}$o(t,e,n);break;case 1:if(!ln&&(tl(n,e),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){yt(n,e,a)}$o(t,e,n);break;case 21:$o(t,e,n);break;case 22:n.mode&1?(ln=(r=ln)||n.memoizedState!==null,$o(t,e,n),ln=r):$o(t,e,n);break;default:$o(t,e,n)}}function pC(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new Kz),e.forEach(function(r){var s=e8.bind(null,t,r);n.has(r)||(n.add(r),r.then(s,s))})}}function Hr(t,e){var n=e.deletions;if(n!==null)for(var r=0;r<n.length;r++){var s=n[r];try{var o=t,i=e,a=i;e:for(;a!==null;){switch(a.tag){case 5:zt=a.stateNode,Wr=!1;break e;case 3:zt=a.stateNode.containerInfo,Wr=!0;break e;case 4:zt=a.stateNode.containerInfo,Wr=!0;break e}a=a.return}if(zt===null)throw Error(Y(160));aT(o,i,s),zt=null,Wr=!1;var l=s.alternate;l!==null&&(l.return=null),s.return=null}catch(c){yt(s,e,c)}}if(e.subtreeFlags&12854)for(e=e.child;e!==null;)lT(e,t),e=e.sibling}function lT(t,e){var n=t.alternate,r=t.flags;switch(t.tag){case 0:case 11:case 14:case 15:if(Hr(e,t),gs(t),r&4){try{su(3,t,t.return),lg(3,t)}catch(m){yt(t,t.return,m)}try{su(5,t,t.return)}catch(m){yt(t,t.return,m)}}break;case 1:Hr(e,t),gs(t),r&512&&n!==null&&tl(n,n.return);break;case 5:if(Hr(e,t),gs(t),r&512&&n!==null&&tl(n,n.return),t.flags&32){var s=t.stateNode;try{Su(s,"")}catch(m){yt(t,t.return,m)}}if(r&4&&(s=t.stateNode,s!=null)){var o=t.memoizedProps,i=n!==null?n.memoizedProps:o,a=t.type,l=t.updateQueue;if(t.updateQueue=null,l!==null)try{a==="input"&&o.type==="radio"&&o.name!=null&&M2(s,o),lv(a,i);var c=lv(a,o);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?R2(s,h):u==="dangerouslySetInnerHTML"?O2(s,h):u==="children"?Su(s,h):Cw(s,u,h,c)}switch(a){case"input":rv(s,o);break;case"textarea":A2(s,o);break;case"select":var f=s._wrapperState.wasMultiple;s._wrapperState.wasMultiple=!!o.multiple;var p=o.value;p!=null?hl(s,!!o.multiple,p,!1):f!==!!o.multiple&&(o.defaultValue!=null?hl(s,!!o.multiple,o.defaultValue,!0):hl(s,!!o.multiple,o.multiple?[]:"",!1))}s[Eu]=o}catch(m){yt(t,t.return,m)}}break;case 6:if(Hr(e,t),gs(t),r&4){if(t.stateNode===null)throw Error(Y(162));s=t.stateNode,o=t.memoizedProps;try{s.nodeValue=o}catch(m){yt(t,t.return,m)}}break;case 3:if(Hr(e,t),gs(t),r&4&&n!==null&&n.memoizedState.isDehydrated)try{bu(e.containerInfo)}catch(m){yt(t,t.return,m)}break;case 4:Hr(e,t),gs(t);break;case 13:Hr(e,t),gs(t),s=t.child,s.flags&8192&&(o=s.memoizedState!==null,s.stateNode.isHidden=o,!o||s.alternate!==null&&s.alternate.memoizedState!==null||(r0=xt())),r&4&&pC(t);break;case 22:if(u=n!==null&&n.memoizedState!==null,t.mode&1?(ln=(c=ln)||u,Hr(e,t),ln=c):Hr(e,t),gs(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(f=re,p=f.child,f.tag){case 0:case 11:case 14:case 15:su(4,f,f.return);break;case 1:tl(f,f.return);var g=f.stateNode;if(typeof g.componentWillUnmount=="function"){r=f,n=f.return;try{e=r,g.props=e.memoizedProps,g.state=e.memoizedState,g.componentWillUnmount()}catch(m){yt(r,n,m)}}break;case 5:tl(f,f.return);break;case 22:if(f.memoizedState!==null){mC(h);continue}}p!==null?(p.return=f,re=p):mC(h)}u=u.sibling}e:for(u=null,h=t;;){if(h.tag===5){if(u===null){u=h;try{s=h.stateNode,c?(o=s.style,typeof o.setProperty=="function"?o.setProperty("display","none","important"):o.display="none"):(a=h.stateNode,l=h.memoizedProps.style,i=l!=null&&l.hasOwnProperty("display")?l.display:null,a.style.display=D2("display",i))}catch(m){yt(t,t.return,m)}}}else if(h.tag===6){if(u===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(m){yt(t,t.return,m)}}else if((h.tag!==22&&h.tag!==23||h.memoizedState===null||h===t)&&h.child!==null){h.child.return=h,h=h.child;continue}if(h===t)break e;for(;h.sibling===null;){if(h.return===null||h.return===t)break e;u===h&&(u=null),h=h.return}u===h&&(u=null),h.sibling.return=h.return,h=h.sibling}}break;case 19:Hr(e,t),gs(t),r&4&&pC(t);break;case 21:break;default:Hr(e,t),gs(t)}}function gs(t){var e=t.flags;if(e&2){try{e:{for(var n=t.return;n!==null;){if(iT(n)){var r=n;break e}n=n.return}throw Error(Y(160))}switch(r.tag){case 5:var s=r.stateNode;r.flags&32&&(Su(s,""),r.flags&=-33);var o=fC(t);Fv(t,o,s);break;case 3:case 4:var i=r.stateNode.containerInfo,a=fC(t);$v(t,a,i);break;default:throw Error(Y(161))}}catch(l){yt(t,t.return,l)}t.flags&=-3}e&4096&&(t.flags&=-4097)}function Gz(t,e,n){re=t,cT(t)}function cT(t,e,n){for(var r=(t.mode&1)!==0;re!==null;){var s=re,o=s.child;if(s.tag===22&&r){var i=s.memoizedState!==null||Qd;if(!i){var a=s.alternate,l=a!==null&&a.memoizedState!==null||ln;a=Qd;var c=ln;if(Qd=i,(ln=l)&&!c)for(re=s;re!==null;)i=re,l=i.child,i.tag===22&&i.memoizedState!==null?yC(s):l!==null?(l.return=i,re=l):yC(s);for(;o!==null;)re=o,cT(o),o=o.sibling;re=s,Qd=a,ln=c}gC(t)}else s.subtreeFlags&8772&&o!==null?(o.return=s,re=o):gC(t)}}function gC(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||lg(5,e);break;case 1:var r=e.stateNode;if(e.flags&4&&!ln)if(n===null)r.componentDidMount();else{var s=e.elementType===e.type?n.memoizedProps:Kr(e.type,n.memoizedProps);r.componentDidUpdate(s,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var o=e.updateQueue;o!==null&&JP(e,o,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}JP(e,i,n)}break;case 5:var a=e.stateNode;if(n===null&&e.flags&4){n=a;var l=e.memoizedProps;switch(e.type){case"button":case"input":case"select":case"textarea":l.autoFocus&&n.focus();break;case"img":l.src&&(n.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(e.memoizedState===null){var c=e.alternate;if(c!==null){var u=c.memoizedState;if(u!==null){var h=u.dehydrated;h!==null&&bu(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Y(163))}ln||e.flags&512&&Lv(e)}catch(f){yt(e,e.return,f)}}if(e===t){re=null;break}if(n=e.sibling,n!==null){n.return=e.return,re=n;break}re=e.return}}function mC(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 yC(t){for(;re!==null;){var e=re;try{switch(e.tag){case 0:case 11:case 15:var n=e.return;try{lg(4,e)}catch(l){yt(e,n,l)}break;case 1:var r=e.stateNode;if(typeof r.componentDidMount=="function"){var s=e.return;try{r.componentDidMount()}catch(l){yt(e,s,l)}}var o=e.return;try{Lv(e)}catch(l){yt(e,o,l)}break;case 5:var i=e.return;try{Lv(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 Vz=Math.ceil,sp=_o.ReactCurrentDispatcher,t0=_o.ReactCurrentOwner,Or=_o.ReactCurrentBatchConfig,Oe=0,Rt=null,_t=null,Yt=0,sr=0,nl=Pi(0),kt=0,Ou=null,oa=0,cg=0,n0=0,ou=null,Nn=null,r0=0,Al=1/0,no=null,op=!1,Nv=null,ai=null,Jd=!1,Qo=null,ip=0,iu=0,zv=null,Qh=-1,Jh=0;function Pn(){return Oe&6?xt():Qh!==-1?Qh:Qh=xt()}function li(t){return t.mode&1?Oe&2&&Yt!==0?Yt&-Yt:Mz.transition!==null?(Jh===0&&(Jh=V2()),Jh):(t=Be,t!==0||(t=window.event,t=t===void 0?16:ek(t.type)),t):1}function ts(t,e,n,r){if(50<iu)throw iu=0,zv=null,Error(Y(185));Ju(t,n,r),(!(Oe&2)||t!==Rt)&&(t===Rt&&(!(Oe&2)&&(cg|=n),kt===4&&Vo(t,Yt)),Yn(t,r),n===1&&Oe===0&&!(e.mode&1)&&(Al=xt()+500,og&&Ci()))}function Yn(t,e){var n=t.callbackNode;M6(t,e);var r=Hf(t,t===Rt?Yt:0);if(r===0)n!==null&&IP(n),t.callbackNode=null,t.callbackPriority=0;else if(e=r&-r,t.callbackPriority!==e){if(n!=null&&IP(n),e===1)t.tag===0?Tz(SC.bind(null,t)):vk(SC.bind(null,t)),_z(function(){!(Oe&6)&&Ci()}),n=null;else{switch(Y2(r)){case 1:n=Tw;break;case 4:n=W2;break;case 16:n=Uf;break;case 536870912:n=G2;break;default:n=Uf}n=yT(n,uT.bind(null,t))}t.callbackPriority=e,t.callbackNode=n}}function uT(t,e){if(Qh=-1,Jh=0,Oe&6)throw Error(Y(327));var n=t.callbackNode;if(yl()&&t.callbackNode!==n)return null;var r=Hf(t,t===Rt?Yt:0);if(r===0)return null;if(r&30||r&t.expiredLanes||e)e=ap(t,r);else{e=r;var s=Oe;Oe|=2;var o=hT();(Rt!==t||Yt!==e)&&(no=null,Al=xt()+500,qi(t,e));do try{qz();break}catch(a){dT(t,a)}while(!0);Uw(),sp.current=o,Oe=s,_t!==null?e=0:(Rt=null,Yt=0,e=kt)}if(e!==0){if(e===2&&(s=fv(t),s!==0&&(r=s,e=Bv(t,s))),e===1)throw n=Ou,qi(t,0),Vo(t,r),Yn(t,xt()),n;if(e===6)Vo(t,r);else{if(s=t.current.alternate,!(r&30)&&!Yz(s)&&(e=ap(t,r),e===2&&(o=fv(t),o!==0&&(r=o,e=Bv(t,o))),e===1))throw n=Ou,qi(t,0),Vo(t,r),Yn(t,xt()),n;switch(t.finishedWork=s,t.finishedLanes=r,e){case 0:case 1:throw Error(Y(345));case 2:Hi(t,Nn,no);break;case 3:if(Vo(t,r),(r&130023424)===r&&(e=r0+500-xt(),10<e)){if(Hf(t,0)!==0)break;if(s=t.suspendedLanes,(s&r)!==r){Pn(),t.pingedLanes|=t.suspendedLanes&s;break}t.timeoutHandle=wv(Hi.bind(null,t,Nn,no),e);break}Hi(t,Nn,no);break;case 4:if(Vo(t,r),(r&4194240)===r)break;for(e=t.eventTimes,s=-1;0<r;){var i=31-es(r);o=1<<i,i=e[i],i>s&&(s=i),r&=~o}if(r=s,r=xt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Vz(r/1960))-r,10<r){t.timeoutHandle=wv(Hi.bind(null,t,Nn,no),r);break}Hi(t,Nn,no);break;case 5:Hi(t,Nn,no);break;default:throw Error(Y(329))}}}return Yn(t,xt()),t.callbackNode===n?uT.bind(null,t):null}function Bv(t,e){var n=ou;return t.current.memoizedState.isDehydrated&&(qi(t,e).flags|=256),t=ap(t,e),t!==2&&(e=Nn,Nn=n,e!==null&&Uv(e)),t}function Uv(t){Nn===null?Nn=t:Nn.push.apply(Nn,t)}function Yz(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 s=n[r],o=s.getSnapshot;s=s.value;try{if(!os(o(),s))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 Vo(t,e){for(e&=~n0,e&=~cg,t.suspendedLanes|=e,t.pingedLanes&=~e,t=t.expirationTimes;0<e;){var n=31-es(e),r=1<<n;t[n]=-1,e&=~r}}function SC(t){if(Oe&6)throw Error(Y(327));yl();var e=Hf(t,0);if(!(e&1))return Yn(t,xt()),null;var n=ap(t,e);if(t.tag!==0&&n===2){var r=fv(t);r!==0&&(e=r,n=Bv(t,r))}if(n===1)throw n=Ou,qi(t,0),Vo(t,e),Yn(t,xt()),n;if(n===6)throw Error(Y(345));return t.finishedWork=t.current.alternate,t.finishedLanes=e,Hi(t,Nn,no),Yn(t,xt()),null}function s0(t,e){var n=Oe;Oe|=1;try{return t(e)}finally{Oe=n,Oe===0&&(Al=xt()+500,og&&Ci())}}function ia(t){Qo!==null&&Qo.tag===0&&!(Oe&6)&&yl();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)&&Ci()}}function o0(){sr=nl.current,rt(nl)}function qi(t,e){t.finishedWork=null,t.finishedLanes=0;var n=t.timeoutHandle;if(n!==-1&&(t.timeoutHandle=-1,Cz(n)),_t!==null)for(n=_t.return;n!==null;){var r=n;switch(Nw(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Yf();break;case 3:Tl(),rt(Gn),rt(gn),Yw();break;case 5:Vw(r);break;case 4:Tl();break;case 13:rt(dt);break;case 19:rt(dt);break;case 10:Hw(r.type._context);break;case 22:case 23:o0()}n=n.return}if(Rt=t,_t=t=ci(t.current,null),Yt=sr=e,kt=0,Ou=null,n0=cg=oa=0,Nn=ou=null,Vi!==null){for(e=0;e<Vi.length;e++)if(n=Vi[e],r=n.interleaved,r!==null){n.interleaved=null;var s=r.next,o=n.pending;if(o!==null){var i=o.next;o.next=s,r.next=i}n.pending=r}Vi=null}return t}function dT(t,e){do{var n=_t;try{if(Uw(),Xh.current=rp,np){for(var r=pt.memoizedState;r!==null;){var s=r.queue;s!==null&&(s.pending=null),r=r.next}np=!1}if(sa=0,jt=Et=pt=null,ru=!1,Mu=0,t0.current=null,n===null||n.return===null){kt=1,Ou=e,_t=null;break}e:{var o=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 f=u.alternate;f?(u.updateQueue=f.updateQueue,u.memoizedState=f.memoizedState,u.lanes=f.lanes):(u.updateQueue=null,u.memoizedState=null)}var p=oC(i);if(p!==null){p.flags&=-257,iC(p,i,a,o,e),p.mode&1&&sC(o,c,e),e=p,l=c;var g=e.updateQueue;if(g===null){var m=new Set;m.add(l),e.updateQueue=m}else g.add(l);break e}else{if(!(e&1)){sC(o,c,e),i0();break e}l=Error(Y(426))}}else if(at&&a.mode&1){var v=oC(i);if(v!==null){!(v.flags&65536)&&(v.flags|=256),iC(v,i,a,o,e),zw(Ml(l,a));break e}}o=l=Ml(l,a),kt!==4&&(kt=2),ou===null?ou=[o]:ou.push(o),o=i;do{switch(o.tag){case 3:o.flags|=65536,e&=-e,o.lanes|=e;var y=Yk(o,l,e);QP(o,y);break e;case 1:a=l;var S=o.type,b=o.stateNode;if(!(o.flags&128)&&(typeof S.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&(ai===null||!ai.has(b)))){o.flags|=65536,e&=-e,o.lanes|=e;var P=Xk(o,a,e);QP(o,P);break e}}o=o.return}while(o!==null)}pT(n)}catch(C){e=C,_t===n&&n!==null&&(_t=n=n.return);continue}break}while(!0)}function hT(){var t=sp.current;return sp.current=rp,t===null?rp:t}function i0(){(kt===0||kt===3||kt===2)&&(kt=4),Rt===null||!(oa&268435455)&&!(cg&268435455)||Vo(Rt,Yt)}function ap(t,e){var n=Oe;Oe|=2;var r=hT();(Rt!==t||Yt!==e)&&(no=null,qi(t,e));do try{Xz();break}catch(s){dT(t,s)}while(!0);if(Uw(),Oe=n,sp.current=r,_t!==null)throw Error(Y(261));return Rt=null,Yt=0,kt}function Xz(){for(;_t!==null;)fT(_t)}function qz(){for(;_t!==null&&!w6();)fT(_t)}function fT(t){var e=mT(t.alternate,t,sr);t.memoizedProps=t.pendingProps,e===null?pT(t):_t=e,t0.current=null}function pT(t){var e=t;do{var n=e.alternate;if(t=e.return,e.flags&32768){if(n=Hz(n,e),n!==null){n.flags&=32767,_t=n;return}if(t!==null)t.flags|=32768,t.subtreeFlags=0,t.deletions=null;else{kt=6,_t=null;return}}else if(n=Uz(n,e,sr),n!==null){_t=n;return}if(e=e.sibling,e!==null){_t=e;return}_t=e=t}while(e!==null);kt===0&&(kt=5)}function Hi(t,e,n){var r=Be,s=Or.transition;try{Or.transition=null,Be=1,Zz(t,e,n,r)}finally{Or.transition=s,Be=r}return null}function Zz(t,e,n,r){do yl();while(Qo!==null);if(Oe&6)throw Error(Y(327));n=t.finishedWork;var s=t.finishedLanes;if(n===null)return null;if(t.finishedWork=null,t.finishedLanes=0,n===t.current)throw Error(Y(177));t.callbackNode=null,t.callbackPriority=0;var o=n.lanes|n.childLanes;if(A6(t,o),t===Rt&&(_t=Rt=null,Yt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||Jd||(Jd=!0,yT(Uf,function(){return yl(),null})),o=(n.flags&15990)!==0,n.subtreeFlags&15990||o){o=Or.transition,Or.transition=null;var i=Be;Be=1;var a=Oe;Oe|=4,t0.current=null,Wz(t,n),lT(n,t),yz(vv),Kf=!!Sv,vv=Sv=null,t.current=n,Gz(n),b6(),Oe=a,Be=i,Or.transition=o}else t.current=n;if(Jd&&(Jd=!1,Qo=t,ip=s),o=t.pendingLanes,o===0&&(ai=null),_6(n.stateNode),Yn(t,xt()),e!==null)for(r=t.onRecoverableError,n=0;n<e.length;n++)s=e[n],r(s.value,{componentStack:s.stack,digest:s.digest});if(op)throw op=!1,t=Nv,Nv=null,t;return ip&1&&t.tag!==0&&yl(),o=t.pendingLanes,o&1?t===zv?iu++:(iu=0,zv=t):iu=0,Ci(),null}function yl(){if(Qo!==null){var t=Y2(ip),e=Or.transition,n=Be;try{if(Or.transition=null,Be=16>t?16:t,Qo===null)var r=!1;else{if(t=Qo,Qo=null,ip=0,Oe&6)throw Error(Y(331));var s=Oe;for(Oe|=4,re=t.current;re!==null;){var o=re,i=o.child;if(re.flags&16){var a=o.deletions;if(a!==null){for(var l=0;l<a.length;l++){var c=a[l];for(re=c;re!==null;){var u=re;switch(u.tag){case 0:case 11:case 15:su(8,u,o)}var h=u.child;if(h!==null)h.return=u,re=h;else for(;re!==null;){u=re;var f=u.sibling,p=u.return;if(oT(u),u===c){re=null;break}if(f!==null){f.return=p,re=f;break}re=p}}}var g=o.alternate;if(g!==null){var m=g.child;if(m!==null){g.child=null;do{var v=m.sibling;m.sibling=null,m=v}while(m!==null)}}re=o}}if(o.subtreeFlags&2064&&i!==null)i.return=o,re=i;else e:for(;re!==null;){if(o=re,o.flags&2048)switch(o.tag){case 0:case 11:case 15:su(9,o,o.return)}var y=o.sibling;if(y!==null){y.return=o.return,re=y;break e}re=o.return}}var S=t.current;for(re=S;re!==null;){i=re;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,re=b;else e:for(i=S;re!==null;){if(a=re,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:lg(9,a)}}catch(C){yt(a,a.return,C)}if(a===i){re=null;break e}var P=a.sibling;if(P!==null){P.return=a.return,re=P;break e}re=a.return}}if(Oe=s,Ci(),Ts&&typeof Ts.onPostCommitFiberRoot=="function")try{Ts.onPostCommitFiberRoot(eg,t)}catch{}r=!0}return r}finally{Be=n,Or.transition=e}}return!1}function vC(t,e,n){e=Ml(n,e),e=Yk(t,e,1),t=ii(t,e,1),e=Pn(),t!==null&&(Ju(t,1,e),Yn(t,e))}function yt(t,e,n){if(t.tag===3)vC(t,t,n);else for(;e!==null;){if(e.tag===3){vC(e,t,n);break}else if(e.tag===1){var r=e.stateNode;if(typeof e.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(ai===null||!ai.has(r))){t=Ml(n,t),t=Xk(e,t,1),e=ii(e,t,1),t=Pn(),e!==null&&(Ju(e,1,t),Yn(e,t));break}}e=e.return}}function Qz(t,e,n){var r=t.pingCache;r!==null&&r.delete(e),e=Pn(),t.pingedLanes|=t.suspendedLanes&n,Rt===t&&(Yt&n)===n&&(kt===4||kt===3&&(Yt&130023424)===Yt&&500>xt()-r0?qi(t,0):n0|=n),Yn(t,e)}function gT(t,e){e===0&&(t.mode&1?(e=Hd,Hd<<=1,!(Hd&130023424)&&(Hd=4194304)):e=1);var n=Pn();t=xo(t,e),t!==null&&(Ju(t,e,n),Yn(t,n))}function Jz(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),gT(t,n)}function e8(t,e){var n=0;switch(t.tag){case 13:var r=t.stateNode,s=t.memoizedState;s!==null&&(n=s.retryLane);break;case 19:r=t.stateNode;break;default:throw Error(Y(314))}r!==null&&r.delete(e),gT(t,n)}var mT;mT=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||Gn.current)Hn=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return Hn=!1,Bz(t,e,n);Hn=!!(t.flags&131072)}else Hn=!1,at&&e.flags&1048576&&xk(e,Zf,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;Zh(t,e),t=e.pendingProps;var s=Il(e,gn.current);ml(e,n),s=qw(null,e,r,t,s,n);var o=Zw();return e.flags|=1,typeof s=="object"&&s!==null&&typeof s.render=="function"&&s.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,Vn(r)?(o=!0,Xf(e)):o=!1,e.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,Ww(e),s.updater=ag,e.stateNode=s,s._reactInternals=e,kv(e,r,t,n),e=Av(null,e,r,!0,o,n)):(e.tag=0,at&&o&&Fw(e),xn(null,e,s,n),e=e.child),e;case 16:r=e.elementType;e:{switch(Zh(t,e),t=e.pendingProps,s=r._init,r=s(r._payload),e.type=r,s=e.tag=n8(r),t=Kr(r,t),s){case 0:e=Mv(null,e,r,t,n);break e;case 1:e=cC(null,e,r,t,n);break e;case 11:e=aC(null,e,r,t,n);break e;case 14:e=lC(null,e,r,Kr(r.type,t),n);break e}throw Error(Y(306,r,""))}return e;case 0:return r=e.type,s=e.pendingProps,s=e.elementType===r?s:Kr(r,s),Mv(t,e,r,s,n);case 1:return r=e.type,s=e.pendingProps,s=e.elementType===r?s:Kr(r,s),cC(t,e,r,s,n);case 3:e:{if(Jk(e),t===null)throw Error(Y(387));r=e.pendingProps,o=e.memoizedState,s=o.element,Ik(t,e),ep(e,r,null,n);var i=e.memoizedState;if(r=i.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},e.updateQueue.baseState=o,e.memoizedState=o,e.flags&256){s=Ml(Error(Y(423)),e),e=uC(t,e,r,n,s);break e}else if(r!==s){s=Ml(Error(Y(424)),e),e=uC(t,e,r,n,s);break e}else for(ir=oi(e.stateNode.containerInfo.firstChild),cr=e,at=!0,Yr=null,n=Ck(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(El(),r===s){e=wo(t,e,n);break e}xn(t,e,r,n)}e=e.child}return e;case 5:return Ek(e),t===null&&_v(e),r=e.type,s=e.pendingProps,o=t!==null?t.memoizedProps:null,i=s.children,xv(r,s)?i=null:o!==null&&xv(r,o)&&(e.flags|=32),Qk(t,e),xn(t,e,i,n),e.child;case 6:return t===null&&_v(e),null;case 13:return eT(t,e,n);case 4:return Gw(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=kl(e,null,r,n):xn(t,e,r,n),e.child;case 11:return r=e.type,s=e.pendingProps,s=e.elementType===r?s:Kr(r,s),aC(t,e,r,s,n);case 7:return xn(t,e,e.pendingProps,n),e.child;case 8:return xn(t,e,e.pendingProps.children,n),e.child;case 12:return xn(t,e,e.pendingProps.children,n),e.child;case 10:e:{if(r=e.type._context,s=e.pendingProps,o=e.memoizedProps,i=s.value,qe(Qf,r._currentValue),r._currentValue=i,o!==null)if(os(o.value,i)){if(o.children===s.children&&!Gn.current){e=wo(t,e,n);break e}}else for(o=e.child,o!==null&&(o.return=e);o!==null;){var a=o.dependencies;if(a!==null){i=o.child;for(var l=a.firstContext;l!==null;){if(l.context===r){if(o.tag===1){l=ho(-1,n&-n),l.tag=2;var c=o.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}}o.lanes|=n,l=o.alternate,l!==null&&(l.lanes|=n),Iv(o.return,n,e),a.lanes|=n;break}l=l.next}}else if(o.tag===10)i=o.type===e.type?null:o.child;else if(o.tag===18){if(i=o.return,i===null)throw Error(Y(341));i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),Iv(i,n,e),i=o.sibling}else i=o.child;if(i!==null)i.return=o;else for(i=o;i!==null;){if(i===e){i=null;break}if(o=i.sibling,o!==null){o.return=i.return,i=o;break}i=i.return}o=i}xn(t,e,s.children,n),e=e.child}return e;case 9:return s=e.type,r=e.pendingProps.children,ml(e,n),s=Rr(s),r=r(s),e.flags|=1,xn(t,e,r,n),e.child;case 14:return r=e.type,s=Kr(r,e.pendingProps),s=Kr(r.type,s),lC(t,e,r,s,n);case 15:return qk(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,s=e.pendingProps,s=e.elementType===r?s:Kr(r,s),Zh(t,e),e.tag=1,Vn(r)?(t=!0,Xf(e)):t=!1,ml(e,n),Vk(e,r,s),kv(e,r,s,n),Av(null,e,r,!0,t,n);case 19:return tT(t,e,n);case 22:return Zk(t,e,n)}throw Error(Y(156,e.tag))};function yT(t,e){return K2(t,e)}function t8(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 t8(t,e,n,r)}function a0(t){return t=t.prototype,!(!t||!t.isReactComponent)}function n8(t){if(typeof t=="function")return a0(t)?1:0;if(t!=null){if(t=t.$$typeof,t===Iw)return 11;if(t===Ew)return 14}return 2}function ci(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 ef(t,e,n,r,s,o){var i=2;if(r=t,typeof t=="function")a0(t)&&(i=1);else if(typeof t=="string")i=5;else e:switch(t){case Ga:return Zi(n.children,s,o,e);case _w:i=8,s|=8;break;case QS:return t=Ar(12,n,e,s|2),t.elementType=QS,t.lanes=o,t;case JS:return t=Ar(13,n,e,s),t.elementType=JS,t.lanes=o,t;case ev:return t=Ar(19,n,e,s),t.elementType=ev,t.lanes=o,t;case E2:return ug(n,s,o,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case _2:i=10;break e;case I2:i=9;break e;case Iw:i=11;break e;case Ew:i=14;break e;case Ko:i=16,r=null;break e}throw Error(Y(130,t==null?t:typeof t,""))}return e=Ar(i,n,e,s),e.elementType=t,e.type=r,e.lanes=o,e}function Zi(t,e,n,r){return t=Ar(7,t,r,e),t.lanes=n,t}function ug(t,e,n,r){return t=Ar(22,t,r,e),t.elementType=E2,t.lanes=n,t.stateNode={isHidden:!1},t}function iy(t,e,n){return t=Ar(6,t,null,e),t.lanes=n,t}function ay(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 r8(t,e,n,r,s){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=Bm(0),this.expirationTimes=Bm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Bm(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function l0(t,e,n,r,s,o,i,a,l){return t=new r8(t,e,n,a,l),e===1?(e=1,o===!0&&(e|=8)):e=0,o=Ar(3,null,null,e),t.current=o,o.stateNode=t,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ww(o),t}function s8(t,e,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Wa,key:r==null?null:""+r,children:t,containerInfo:e,implementation:n}}function ST(t){if(!t)return pi;t=t._reactInternals;e:{if(wa(t)!==t||t.tag!==1)throw Error(Y(170));var e=t;do{switch(e.tag){case 3:e=e.stateNode.context;break e;case 1:if(Vn(e.type)){e=e.stateNode.__reactInternalMemoizedMergedChildContext;break e}}e=e.return}while(e!==null);throw Error(Y(171))}if(t.tag===1){var n=t.type;if(Vn(n))return Sk(t,n,e)}return e}function vT(t,e,n,r,s,o,i,a,l){return t=l0(n,r,!0,t,s,o,i,a,l),t.context=ST(null),n=t.current,r=Pn(),s=li(n),o=ho(r,s),o.callback=e??null,ii(n,o,s),t.current.lanes=s,Ju(t,s,r),Yn(t,r),t}function dg(t,e,n,r){var s=e.current,o=Pn(),i=li(s);return n=ST(n),e.context===null?e.context=n:e.pendingContext=n,e=ho(o,i),e.payload={element:t},r=r===void 0?null:r,r!==null&&(e.callback=r),t=ii(s,e,i),t!==null&&(ts(t,s,i,o),Yh(t,s,i)),i}function lp(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 xC(t,e){if(t=t.memoizedState,t!==null&&t.dehydrated!==null){var n=t.retryLane;t.retryLane=n!==0&&n<e?n:e}}function c0(t,e){xC(t,e),(t=t.alternate)&&xC(t,e)}function o8(){return null}var xT=typeof reportError=="function"?reportError:function(t){console.error(t)};function u0(t){this._internalRoot=t}hg.prototype.render=u0.prototype.render=function(t){var e=this._internalRoot;if(e===null)throw Error(Y(409));dg(t,e,null,null)};hg.prototype.unmount=u0.prototype.unmount=function(){var t=this._internalRoot;if(t!==null){this._internalRoot=null;var e=t.containerInfo;ia(function(){dg(null,t,null,null)}),e[vo]=null}};function hg(t){this._internalRoot=t}hg.prototype.unstable_scheduleHydration=function(t){if(t){var e=Z2();t={blockedOn:null,target:t,priority:e};for(var n=0;n<Go.length&&e!==0&&e<Go[n].priority;n++);Go.splice(n,0,t),n===0&&J2(t)}};function d0(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)}function fg(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11&&(t.nodeType!==8||t.nodeValue!==" react-mount-point-unstable "))}function wC(){}function i8(t,e,n,r,s){if(s){if(typeof r=="function"){var o=r;r=function(){var c=lp(i);o.call(c)}}var i=vT(e,r,t,0,null,!1,!1,"",wC);return t._reactRootContainer=i,t[vo]=i.current,_u(t.nodeType===8?t.parentNode:t),ia(),i}for(;s=t.lastChild;)t.removeChild(s);if(typeof r=="function"){var a=r;r=function(){var c=lp(l);a.call(c)}}var l=l0(t,0,!1,null,null,!1,!1,"",wC);return t._reactRootContainer=l,t[vo]=l.current,_u(t.nodeType===8?t.parentNode:t),ia(function(){dg(e,l,n,r)}),l}function pg(t,e,n,r,s){var o=n._reactRootContainer;if(o){var i=o;if(typeof s=="function"){var a=s;s=function(){var l=lp(i);a.call(l)}}dg(e,i,t,s)}else i=i8(n,e,t,s,r);return lp(i)}X2=function(t){switch(t.tag){case 3:var e=t.stateNode;if(e.current.memoizedState.isDehydrated){var n=zc(e.pendingLanes);n!==0&&(Mw(e,n|1),Yn(e,xt()),!(Oe&6)&&(Al=xt()+500,Ci()))}break;case 13:ia(function(){var r=xo(t,1);if(r!==null){var s=Pn();ts(r,t,1,s)}}),c0(t,1)}};Aw=function(t){if(t.tag===13){var e=xo(t,134217728);if(e!==null){var n=Pn();ts(e,t,134217728,n)}c0(t,134217728)}};q2=function(t){if(t.tag===13){var e=li(t),n=xo(t,e);if(n!==null){var r=Pn();ts(n,t,e,r)}c0(t,e)}};Z2=function(){return Be};Q2=function(t,e){var n=Be;try{return Be=t,e()}finally{Be=n}};uv=function(t,e,n){switch(e){case"input":if(rv(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 s=sg(r);if(!s)throw Error(Y(90));T2(r),rv(r,s)}}}break;case"textarea":A2(t,n);break;case"select":e=n.value,e!=null&&hl(t,!!n.multiple,e,!1)}};F2=s0;N2=ia;var a8={usingClientEntryPoint:!1,Events:[td,qa,sg,L2,$2,s0]},xc={findFiberByHostInstance:Gi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},l8={bundleType:xc.bundleType,version:xc.version,rendererPackageName:xc.rendererPackageName,rendererConfig:xc.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:_o.ReactCurrentDispatcher,findHostInstanceByFiber:function(t){return t=U2(t),t===null?null:t.stateNode},findFiberByHostInstance:xc.findFiberByHostInstance||o8,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 eh=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!eh.isDisabled&&eh.supportsFiber)try{eg=eh.inject(l8),Ts=eh}catch{}}Sr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=a8;Sr.createPortal=function(t,e){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!d0(e))throw Error(Y(200));return s8(t,e,null,n)};Sr.createRoot=function(t,e){if(!d0(t))throw Error(Y(299));var n=!1,r="",s=xT;return e!=null&&(e.unstable_strictMode===!0&&(n=!0),e.identifierPrefix!==void 0&&(r=e.identifierPrefix),e.onRecoverableError!==void 0&&(s=e.onRecoverableError)),e=l0(t,1,!1,null,null,n,!1,r,s),t[vo]=e.current,_u(t.nodeType===8?t.parentNode:t),new u0(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(Y(188)):(t=Object.keys(t).join(","),Error(Y(268,t)));return t=U2(e),t=t===null?null:t.stateNode,t};Sr.flushSync=function(t){return ia(t)};Sr.hydrate=function(t,e,n){if(!fg(e))throw Error(Y(200));return pg(null,t,e,!0,n)};Sr.hydrateRoot=function(t,e,n){if(!d0(t))throw Error(Y(405));var r=n!=null&&n.hydratedSources||null,s=!1,o="",i=xT;if(n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(o=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),e=vT(e,null,t,1,n??null,s,!1,o,i),t[vo]=e.current,_u(t),r)for(t=0;t<r.length;t++)n=r[t],s=n._getVersion,s=s(n._source),e.mutableSourceEagerHydrationData==null?e.mutableSourceEagerHydrationData=[n,s]:e.mutableSourceEagerHydrationData.push(n,s);return new hg(e)};Sr.render=function(t,e,n){if(!fg(e))throw Error(Y(200));return pg(null,t,e,!1,n)};Sr.unmountComponentAtNode=function(t){if(!fg(t))throw Error(Y(40));return t._reactRootContainer?(ia(function(){pg(null,null,t,!1,function(){t._reactRootContainer=null,t[vo]=null})}),!0):!1};Sr.unstable_batchedUpdates=s0;Sr.unstable_renderSubtreeIntoContainer=function(t,e,n,r){if(!fg(n))throw Error(Y(200));if(t==null||t._reactInternals===void 0)throw Error(Y(38));return pg(t,e,n,!1,r)};Sr.version="18.3.1-next-f1338f8080-20240426";function wT(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(wT)}catch(t){console.error(t)}}wT(),w2.exports=Sr;var ba=w2.exports;const c8=wi(ba);var bT,bC=ba;bT=qS.createRoot=bC.createRoot,qS.hydrateRoot=bC.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 u8(t){const e=ae("./icons/icon/0_merged.svg",t);return{fonts:{monospace:ae("./fonts/IBMPlexMono-Medium.woff2",t),sansSerif:ae("./fonts/IBMPlexSans-Medium.woff2",t),serif:ae("./fonts/IBMPlexSerif-Medium.woff2",t),draw:ae("./fonts/Shantell_Sans-Tldrawish.woff2",t)},icons:{"align-bottom":e+"#align-bottom","align-center-horizontal":e+"#align-center-horizontal","align-center-vertical":e+"#align-center-vertical","align-left":e+"#align-left","align-right":e+"#align-right","align-top":e+"#align-top","arrow-left":e+"#arrow-left","arrowhead-arrow":e+"#arrowhead-arrow","arrowhead-bar":e+"#arrowhead-bar","arrowhead-diamond":e+"#arrowhead-diamond","arrowhead-dot":e+"#arrowhead-dot","arrowhead-none":e+"#arrowhead-none","arrowhead-square":e+"#arrowhead-square","arrowhead-triangle-inverted":e+"#arrowhead-triangle-inverted","arrowhead-triangle":e+"#arrowhead-triangle",blob:e+"#blob","bring-forward":e+"#bring-forward","bring-to-front":e+"#bring-to-front",broken:e+"#broken","check-circle":e+"#check-circle",check:e+"#check","chevron-down":e+"#chevron-down","chevron-left":e+"#chevron-left","chevron-right":e+"#chevron-right","chevron-up":e+"#chevron-up","chevrons-ne":e+"#chevrons-ne","chevrons-sw":e+"#chevrons-sw","clipboard-copied":e+"#clipboard-copied","clipboard-copy":e+"#clipboard-copy",color:e+"#color","cross-2":e+"#cross-2","cross-circle":e+"#cross-circle","dash-dashed":e+"#dash-dashed","dash-dotted":e+"#dash-dotted","dash-draw":e+"#dash-draw","dash-solid":e+"#dash-solid",disconnected:e+"#disconnected",discord:e+"#discord","distribute-horizontal":e+"#distribute-horizontal","distribute-vertical":e+"#distribute-vertical",dot:e+"#dot","dots-horizontal":e+"#dots-horizontal","dots-vertical":e+"#dots-vertical","drag-handle-dots":e+"#drag-handle-dots",duplicate:e+"#duplicate",edit:e+"#edit","external-link":e+"#external-link","fill-fill":e+"#fill-fill","fill-none":e+"#fill-none","fill-pattern":e+"#fill-pattern","fill-semi":e+"#fill-semi","fill-solid":e+"#fill-solid",follow:e+"#follow",following:e+"#following","font-draw":e+"#font-draw","font-mono":e+"#font-mono","font-sans":e+"#font-sans","font-serif":e+"#font-serif","geo-arrow-down":e+"#geo-arrow-down","geo-arrow-left":e+"#geo-arrow-left","geo-arrow-right":e+"#geo-arrow-right","geo-arrow-up":e+"#geo-arrow-up","geo-check-box":e+"#geo-check-box","geo-cloud":e+"#geo-cloud","geo-diamond":e+"#geo-diamond","geo-ellipse":e+"#geo-ellipse","geo-heart":e+"#geo-heart","geo-hexagon":e+"#geo-hexagon","geo-octagon":e+"#geo-octagon","geo-oval":e+"#geo-oval","geo-pentagon":e+"#geo-pentagon","geo-rectangle":e+"#geo-rectangle","geo-rhombus-2":e+"#geo-rhombus-2","geo-rhombus":e+"#geo-rhombus","geo-star":e+"#geo-star","geo-trapezoid":e+"#geo-trapezoid","geo-triangle":e+"#geo-triangle","geo-x-box":e+"#geo-x-box",github:e+"#github",group:e+"#group","horizontal-align-end":e+"#horizontal-align-end","horizontal-align-middle":e+"#horizontal-align-middle","horizontal-align-start":e+"#horizontal-align-start","info-circle":e+"#info-circle",leading:e+"#leading",link:e+"#link",lock:e+"#lock",menu:e+"#menu",minus:e+"#minus",mixed:e+"#mixed",pack:e+"#pack",plus:e+"#plus","question-mark-circle":e+"#question-mark-circle","question-mark":e+"#question-mark",redo:e+"#redo","reset-zoom":e+"#reset-zoom","rotate-ccw":e+"#rotate-ccw","rotate-cw":e+"#rotate-cw","send-backward":e+"#send-backward","send-to-back":e+"#send-to-back","share-1":e+"#share-1","size-extra-large":e+"#size-extra-large","size-large":e+"#size-large","size-medium":e+"#size-medium","size-small":e+"#size-small","spline-cubic":e+"#spline-cubic","spline-line":e+"#spline-line","stack-horizontal":e+"#stack-horizontal","stack-vertical":e+"#stack-vertical","status-offline":e+"#status-offline","stretch-horizontal":e+"#stretch-horizontal","stretch-vertical":e+"#stretch-vertical","text-align-center":e+"#text-align-center","text-align-left":e+"#text-align-left","text-align-right":e+"#text-align-right","toggle-off":e+"#toggle-off","toggle-on":e+"#toggle-on","tool-arrow":e+"#tool-arrow","tool-eraser":e+"#tool-eraser","tool-frame":e+"#tool-frame","tool-hand":e+"#tool-hand","tool-highlight":e+"#tool-highlight","tool-laser":e+"#tool-laser","tool-line":e+"#tool-line","tool-media":e+"#tool-media","tool-note":e+"#tool-note","tool-pencil":e+"#tool-pencil","tool-pointer":e+"#tool-pointer","tool-screenshot":e+"#tool-screenshot","tool-text":e+"#tool-text",trash:e+"#trash",twitter:e+"#twitter",undo:e+"#undo",ungroup:e+"#ungroup",unlock:e+"#unlock","vertical-align-end":e+"#vertical-align-end","vertical-align-middle":e+"#vertical-align-middle","vertical-align-start":e+"#vertical-align-start","warning-triangle":e+"#warning-triangle","zoom-in":e+"#zoom-in","zoom-out":e+"#zoom-out"},translations:{ar:ae("./translations/ar.json",t),ca:ae("./translations/ca.json",t),cs:ae("./translations/cs.json",t),da:ae("./translations/da.json",t),de:ae("./translations/de.json",t),en:ae("./translations/en.json",t),es:ae("./translations/es.json",t),fa:ae("./translations/fa.json",t),fi:ae("./translations/fi.json",t),fr:ae("./translations/fr.json",t),gl:ae("./translations/gl.json",t),he:ae("./translations/he.json",t),"hi-in":ae("./translations/hi-in.json",t),hr:ae("./translations/hr.json",t),hu:ae("./translations/hu.json",t),id:ae("./translations/id.json",t),it:ae("./translations/it.json",t),ja:ae("./translations/ja.json",t),"ko-kr":ae("./translations/ko-kr.json",t),ku:ae("./translations/ku.json",t),languages:ae("./translations/languages.json",t),main:ae("./translations/main.json",t),my:ae("./translations/my.json",t),ne:ae("./translations/ne.json",t),no:ae("./translations/no.json",t),pl:ae("./translations/pl.json",t),"pt-br":ae("./translations/pt-br.json",t),"pt-pt":ae("./translations/pt-pt.json",t),ro:ae("./translations/ro.json",t),ru:ae("./translations/ru.json",t),sl:ae("./translations/sl.json",t),so:ae("./translations/so.json",t),sv:ae("./translations/sv.json",t),te:ae("./translations/te.json",t),th:ae("./translations/th.json",t),tr:ae("./translations/tr.json",t),uk:ae("./translations/uk.json",t),vi:ae("./translations/vi.json",t),"zh-cn":ae("./translations/zh-cn.json",t),"zh-tw":ae("./translations/zh-tw.json",t)},embedIcons:{codepen:ae("./embed-icons/codepen.png",t),codesandbox:ae("./embed-icons/codesandbox.png",t),desmos:ae("./embed-icons/desmos.png",t),excalidraw:ae("./embed-icons/excalidraw.png",t),felt:ae("./embed-icons/felt.png",t),figma:ae("./embed-icons/figma.png",t),github_gist:ae("./embed-icons/github_gist.png",t),google_calendar:ae("./embed-icons/google_calendar.png",t),google_maps:ae("./embed-icons/google_maps.png",t),google_slides:ae("./embed-icons/google_slides.png",t),observable:ae("./embed-icons/observable.png",t),replit:ae("./embed-icons/replit.png",t),scratch:ae("./embed-icons/scratch.png",t),spotify:ae("./embed-icons/spotify.png",t),tldraw:ae("./embed-icons/tldraw.png",t),val_town:ae("./embed-icons/val_town.png",t),vimeo:ae("./embed-icons/vimeo.png",t),youtube:ae("./embed-icons/youtube.png",t)}}}const ly="__TLDRAW_LIBRARY_VERSIONS__";function d8(){if(globalThis[ly])return globalThis[ly];const t={versions:[],didWarn:!1,scheduledNotice:null};return Object.defineProperty(globalThis,ly,{value:t,writable:!1,configurable:!1,enumerable:!1}),t}function _i(t,e,n){if(!t)throw new Error("Missing name/version/module system in built version of tldraw library");const r=d8();if(r.versions.push({name:t,version:e,modules:n}),!r.scheduledNotice)try{r.scheduledNotice=setTimeout(()=>{r.scheduledNotice=null,PC(r)},100)}catch{PC(r)}}function PC(t){if(!t.versions.length||t.didWarn)return;const e=t.versions.sort((a,l)=>CC(a.version,l.version)),n=e[e.length-1].version,r=new Set,s=new Map;for(const a of e){if(s.has(a.name)){r.delete(a.name),cy(s,a.name,new Set).add(a.version);continue}a.version===n?r.add(a.name):(r.delete(a.name),cy(s,a.name,new Set).add(a.version))}if(s.size>0){const a=[`${Zs("[tldraw]",["bold","bgRed","textWhite"])} ${Zs("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 ${Zs(`v${n}`,["bold","textBlue"])}. The following libraries are on the latest version:`,...Array.from(r,l=>` • ✅ ${Zs(l,["bold"])}`),"","The following libraries are not on the latest version, or have multiple versions installed:",...Array.from(s,([l,c])=>{const u=Array.from(c).sort(CC).map(h=>Zs(`v${h}`,h===n?["textGreen"]:["textRed"]));return` • ❌ ${Zs(l,["bold"])} (${u.join(", ")})`})];console.log(a.join(`
|
|
41
|
+
`)),t.didWarn=!0;return}const o=new Map;for(const a of e)cy(o,a.name,{version:a.version,modules:[]}).modules.push(a.modules);const i=new Map;for(const[a,l]of o)l.modules.length>1&&i.set(a,l);if(i.size>0){const a=[`${Zs("[tldraw]",["bold","bgRed","textWhite"])} ${Zs("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,f)=>h==="esm"?` ${f+1}. ES Modules`:` ${f+1}. CommonJS`).join(`
|
|
42
|
+
`);return` • ❌ ${Zs(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 CC(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 h8={bold:"1",textBlue:"94",textRed:"31",textGreen:"32",bgRed:"41",textWhite:"97"};function Zs(t,e=[]){return`\x1B[${e.map(n=>h8[n]).join(";")}m${t}\x1B[m`}function cy(t,e,n){return t.has(e)?t.get(e):(t.set(e,n),n)}var PT="Expected a function",_C=NaN,f8="[object Symbol]",p8=/^\s+|\s+$/g,g8=/^[-+]0x[0-9a-f]+$/i,m8=/^0b[01]+$/i,y8=/^0o[0-7]+$/i,S8=parseInt,v8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,x8=typeof self=="object"&&self&&self.Object===Object&&self,w8=v8||x8||Function("return this")(),b8=Object.prototype,P8=b8.toString,C8=Math.max,_8=Math.min,uy=function(){return w8.Date.now()};function I8(t,e,n){var r,s,o,i,a,l,c=0,u=!1,h=!1,f=!0;if(typeof t!="function")throw new TypeError(PT);e=IC(e)||0,cp(n)&&(u=!!n.leading,h="maxWait"in n,o=h?C8(IC(n.maxWait)||0,e):o,f="trailing"in n?!!n.trailing:f);function p(_){var E=r,k=s;return r=s=void 0,c=_,i=t.apply(k,E),i}function g(_){return c=_,a=setTimeout(y,e),u?p(_):i}function m(_){var E=_-l,k=_-c,D=e-E;return h?_8(D,o-k):D}function v(_){var E=_-l,k=_-c;return l===void 0||E>=e||E<0||h&&k>=o}function y(){var _=uy();if(v(_))return S(_);a=setTimeout(y,m(_))}function S(_){return a=void 0,f&&r?p(_):(r=s=void 0,i)}function b(){a!==void 0&&clearTimeout(a),c=0,r=l=s=a=void 0}function P(){return a===void 0?i:S(uy())}function C(){var _=uy(),E=v(_);if(r=arguments,s=this,l=_,E){if(a===void 0)return g(l);if(h)return a=setTimeout(y,e),p(l)}return a===void 0&&(a=setTimeout(y,e)),i}return C.cancel=b,C.flush=P,C}function E8(t,e,n){var r=!0,s=!0;if(typeof t!="function")throw new TypeError(PT);return cp(n)&&(r="leading"in n?!!n.leading:r,s="trailing"in n?!!n.trailing:s),I8(t,e,{leading:r,maxWait:e,trailing:s})}function cp(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function k8(t){return!!t&&typeof t=="object"}function T8(t){return typeof t=="symbol"||k8(t)&&P8.call(t)==f8}function IC(t){if(typeof t=="number")return t;if(T8(t))return _C;if(cp(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=cp(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=t.replace(p8,"");var n=m8.test(t);return n||y8.test(t)?S8(t.slice(2),n?2:8):g8.test(t)?_C:+t}var M8=E8;const CT=wi(M8);var A8=200,h0="__lodash_hash_undefined__",j8=1/0,O8="[object Function]",D8="[object GeneratorFunction]",R8=/[\\^$.*+?()[\]{}|]/g,L8=/^\[object .+?Constructor\]$/,$8=typeof dn=="object"&&dn&&dn.Object===Object&&dn,F8=typeof self=="object"&&self&&self.Object===Object&&self,f0=$8||F8||Function("return this")();function N8(t,e){var n=t?t.length:0;return!!n&&B8(t,e,0)>-1}function z8(t,e,n,r){for(var s=t.length,o=n+-1;++o<s;)if(e(t[o],o,t))return o;return-1}function B8(t,e,n){if(e!==e)return z8(t,U8,n);for(var r=n-1,s=t.length;++r<s;)if(t[r]===e)return r;return-1}function U8(t){return t!==t}function H8(t,e){return t.has(e)}function K8(t,e){return t==null?void 0:t[e]}function W8(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function _T(t){var e=-1,n=Array(t.size);return t.forEach(function(r){n[++e]=r}),n}var G8=Array.prototype,V8=Function.prototype,IT=Object.prototype,dy=f0["__core-js_shared__"],EC=function(){var t=/[^.]+$/.exec(dy&&dy.keys&&dy.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),ET=V8.toString,p0=IT.hasOwnProperty,Y8=IT.toString,X8=RegExp("^"+ET.call(p0).replace(R8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),q8=G8.splice,Z8=g0(f0,"Map"),hy=g0(f0,"Set"),Du=g0(Object,"create");function aa(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 Q8(){this.__data__=Du?Du(null):{}}function J8(t){return this.has(t)&&delete this.__data__[t]}function e9(t){var e=this.__data__;if(Du){var n=e[t];return n===h0?void 0:n}return p0.call(e,t)?e[t]:void 0}function t9(t){var e=this.__data__;return Du?e[t]!==void 0:p0.call(e,t)}function n9(t,e){var n=this.__data__;return n[t]=Du&&e===void 0?h0:e,this}aa.prototype.clear=Q8;aa.prototype.delete=J8;aa.prototype.get=e9;aa.prototype.has=t9;aa.prototype.set=n9;function Kl(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 r9(){this.__data__=[]}function s9(t){var e=this.__data__,n=gg(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():q8.call(e,n,1),!0}function o9(t){var e=this.__data__,n=gg(e,t);return n<0?void 0:e[n][1]}function i9(t){return gg(this.__data__,t)>-1}function a9(t,e){var n=this.__data__,r=gg(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}Kl.prototype.clear=r9;Kl.prototype.delete=s9;Kl.prototype.get=o9;Kl.prototype.has=i9;Kl.prototype.set=a9;function Wl(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function l9(){this.__data__={hash:new aa,map:new(Z8||Kl),string:new aa}}function c9(t){return mg(this,t).delete(t)}function u9(t){return mg(this,t).get(t)}function d9(t){return mg(this,t).has(t)}function h9(t,e){return mg(this,t).set(t,e),this}Wl.prototype.clear=l9;Wl.prototype.delete=c9;Wl.prototype.get=u9;Wl.prototype.has=d9;Wl.prototype.set=h9;function up(t){var e=-1,n=t?t.length:0;for(this.__data__=new Wl;++e<n;)this.add(t[e])}function f9(t){return this.__data__.set(t,h0),this}function p9(t){return this.__data__.has(t)}up.prototype.add=up.prototype.push=f9;up.prototype.has=p9;function gg(t,e){for(var n=t.length;n--;)if(b9(t[n][0],e))return n;return-1}function g9(t){if(!kT(t)||v9(t))return!1;var e=P9(t)||W8(t)?X8:L8;return e.test(x9(t))}function m9(t,e,n){var r=-1,s=N8,o=t.length,i=!0,a=[],l=a;if(o>=A8){var c=y9(t);if(c)return _T(c);i=!1,s=H8,l=new up}else l=a;e:for(;++r<o;){var u=t[r],h=u;if(u=u!==0?u:0,i&&h===h){for(var f=l.length;f--;)if(l[f]===h)continue e;a.push(u)}else s(l,h,n)||(l!==a&&l.push(h),a.push(u))}return a}var y9=hy&&1/_T(new hy([,-0]))[1]==j8?function(t){return new hy(t)}:C9;function mg(t,e){var n=t.__data__;return S9(e)?n[typeof e=="string"?"string":"hash"]:n.map}function g0(t,e){var n=K8(t,e);return g9(n)?n:void 0}function S9(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function v9(t){return!!EC&&EC in t}function x9(t){if(t!=null){try{return ET.call(t)}catch{}try{return t+""}catch{}}return""}function w9(t){return t&&t.length?m9(t):[]}function b9(t,e){return t===e||t!==t&&e!==e}function P9(t){var e=kT(t)?Y8.call(t):"";return e==O8||e==D8}function kT(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function C9(){}var _9=w9;const I9=wi(_9);function TT(t){const e=(...n)=>{try{return t(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,e),r}};return e}const Ru=()=>{},wn={ok(t){return{ok:!0,value:t}},err(t){return{ok:!1,error:t}}};function Ot(t,e){const n=e&&t&&typeof t=="object"&&e in t?t[e]:t;throw new Error(`Unknown switch case ${n}`)}const Le=TT((t,e)=>{if(!t)throw new Error(e||"Assertion Error")}),zn=TT((t,e)=>{if(t==null)throw new Error(e??"value must be defined");return t});function m0(){let t,e;const n=new Promise((r,s)=>{t=r,e=s});return Object.assign(n,{resolve:t,reject:e})}function Hv(t){return new Promise(e=>setTimeout(e,t))}const Uc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},E9=Uc.Good;class MT{constructor(){I(this,"startTime",0);I(this,"name","");I(this,"frames",0);I(this,"started",!1);I(this,"frame",null);I(this,"recordFrame",()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))})}start(e){this.name=e,this.frames=0,this.started=!0,this.frame!==null&&cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(this.recordFrame),this.startTime=performance.now()}stop(){this.started=!1,this.frame!==null&&cancelAnimationFrame(this.frame);const e=(performance.now()-this.startTime)/1e3,n=e===0?0:Math.floor(this.frames/e),r=n>55?Uc.Good:n>30?Uc.Mid:Uc.Poor,s=r===Uc.Mid?"black":"white",o=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${o} %c${n}%c fps`,`color: white; background: ${E9};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${r};color: ${s};`,"font-weight: normal")}isStarted(){return this.started}}function y0(t,e){const n=[];e:for(const r of t){for(const s of n)if(e?e(r,s):r===s)continue e;n.push(r)}return n}function me(t){return t.filter(e=>e!=null)}function Ht(t){return t[t.length-1]}function k9(t,e){let n,r=1/0;for(const s of t){const o=e(s);o<r&&(n=s,r=o)}return n}function T9(t,e){let n,r=-1/0;for(const s of t){const o=e(s);o>r&&(n=s,r=o)}return n}function AT(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!Object.is(t[n],e[n]))return!1;return!0}function Kn(...t){if(t.length===2){const[e,n]=t;n.addInitializer(function(){Le(Reflect.isExtensible(this),"Cannot bind to a non-extensible class.");const s=e.bind(this),o=Reflect.defineProperty(this,n.name,{value:s,writable:!0,configurable:!0});Le(o,"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 s=r.value.bind(this);return Object.defineProperty(this,n,{value:s,configurable:!0,writable:!0}),s}}}}class Ds{constructor(){I(this,"items",new WeakMap)}get(e,n){return this.items.has(e)||this.items.set(e,n(e)),this.items.get(e)}}function yg(t,e){let n;const r=(...s)=>(n||(n={},n.promise=new Promise((o,i)=>{n.resolve=o,n.reject=i})),clearTimeout(n.timeout),n.latestArgs=s,n.timeout=setTimeout(()=>{const o=n;n=void 0;try{o.resolve(t(...o.latestArgs))}catch(i){o.reject(i)}},e),n.promise);return r.cancel=()=>{n&&clearTimeout(n.timeout)},r}const kC=new WeakMap;function S0(t,e){if(typeof t!="object"||t===null)return;let n=kC.get(t);n||(n={tags:{},extras:{}},kC.set(t,n)),e.tags&&(n.tags={...n.tags,...e.tags}),e.extras&&(n.extras={...n.extras,...e.extras})}async function Rs(t,e){return window.fetch(t,{referrerPolicy:"strict-origin-when-cross-origin",...e})}const Lu=(t,e)=>{const n=new window.Image(t,e);return n.referrerPolicy="strict-origin-when-cross-origin",n};class Zr{static async dataUrlToArrayBuffer(e){return Rs(e).then(function(n){return n.arrayBuffer()})}static async blobToDataUrl(e){return await new Promise((n,r)=>{if(e){const s=new FileReader;s.onload=()=>n(s.result),s.onerror=o=>r(o),s.onabort=o=>r(o),s.readAsDataURL(e)}})}static async blobToText(e){return await new Promise((n,r)=>{if(e){const s=new FileReader;s.onload=()=>n(s.result),s.onerror=o=>r(o),s.onabort=o=>r(o),s.readAsText(e)}})}static rewriteMimeType(e,n){return e.type===n?e:e instanceof File?new File([e],e.name,{type:n}):new Blob([e],{type:n})}}function Kv(t){let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e|=0;return e+""}function TC(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 MC=globalThis.crypto,M9="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",A9=128;let Ki,rl;function j9(t){!Ki||Ki.length<t?(Ki=new Uint8Array(t*A9),MC.getRandomValues(Ki),rl=0):rl+t>Ki.length&&(MC.getRandomValues(Ki),rl=0),rl+=t}function O9(t=21){j9(t-=0);let e="";for(let n=rl-t;n<rl;n++)e+=M9[Ki[n]&63];return e}let D9=O9;function ze(t){return D9(t)}/*!
|
|
54
|
+
* MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
|
|
55
|
+
* Copyright (c) Philip van Heemstra
|
|
56
|
+
*/function R9(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(o,i,a,l,c=1024){if(!i)return-1;i=new RegExp(i,"g");const u=i.source.length,h=new TextDecoder,f=o.length;if(typeof l>"u"&&(l=f),a>=f||l<=0||a>=l)return-1;o=o.subarray(a,l);let p=-1,g=0,m=0,v="";e:for(;g<o.length;){const y=g+c,S=o.subarray(g,y),b=h.decode(S,{stream:!0}),P=v+b;let C,_=-1;for(;(C=i.exec(P))!==null;){_=C.index-v.length,p=m+_;break e}g=y,m+=b.length;const E=_>-1?_+u:b.length-u;v=b.slice(E)}return p>=0&&(p+=a>=0?a:f+a),p}const s=r(e,"IDAT",12);return s>=12?r(e,"acTL",8,s)>=8:!1}const L9=t=>new Uint8Array(t)[3]===44;/*!
|
|
57
|
+
* MIT License
|
|
58
|
+
* Modified code originally from <https://github.com/qzb/is-animated>
|
|
59
|
+
* Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
|
|
60
|
+
*/function AC(t,e){let n=0;for(;t[e+n];)n+=t[e+n]+1;return n+1}function $9(t){return new TextDecoder("ascii").decode(t.slice(0,3))==="GIF"}function F9(t){const e=new Uint8Array(t);let n,r,s=0,o=0;if(!$9(t))return!1;for(n=e[10]&128,r=e[10]&7,s+=6,s+=7,s+=n?3*Math.pow(2,r+1):0;o<2&&s<e.length;)switch(e[s]){case 44:o+=1,n=e[s+9]&128,r=e[s+9]&7,s+=10,s+=n?3*Math.pow(2,r+1):0,s+=AC(e,s+1)+1;break;case 33:s+=2,s+=AC(e,s);break;case 59:s=e.length;break;default:s=e.length;break}return o>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 Wv=[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"&&(Wv=new Int32Array(Wv));const N9=(t,e)=>{let n=-1;for(let r=0;r<t.length;r++)n=Wv[(n^t[r])&255]^n>>>8;return n^-1},jC=4,OC=4;class Ps{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(!Ps.isPng(e,n))throw new Error("Not a PNG");for(n+=8;n<=e.buffer.byteLength;){const s=n,o=e.getInt32(n);n+=4;const i=Ps.getChunkType(e,n);if(i==="IDAT"&&r[i]){n+=o+jC+OC;continue}if(i==="IEND")break;r[i]={start:s,dataOffset:n+4,size:o},n+=o+jC+OC}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 Ps.readChunks(e)[n]}static setPhysChunk(e,n=1,r){let s=46,o=0;const i=Ps.findChunk(e,"pHYs");i&&(s=i.start,o=i.size);const a=Ps.findChunk(e,"IDAT");a&&(s=a.start,o=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,N9(h));const f=e.buffer.slice(0,s),p=e.buffer.slice(s+o);return new Blob([f,l,p],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 z9(t){return!t||t.length<12?!1:t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80}function B9(t){const e=new Uint8Array(t);return!z9(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const jT=Object.freeze(["image/svg+xml"]),OT=Object.freeze(["image/jpeg","image/png","image/webp"]),DT=Object.freeze(["image/gif","image/apng","image/avif"]),Sg=Object.freeze([...OT,...jT,...DT]),v0=Object.freeze(["video/mp4","video/webm","video/quicktime"]),U9=[...Sg,...v0].join(",");class ar{static loadVideo(e){return new Promise((n,r)=>{const s=document.createElement("video");s.onloadeddata=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load video"))},s.crossOrigin="anonymous",s.src=e})}static async getVideoFrameAsDataUrl(e,n=0){const r=m0();let s=!1;const o=()=>{if(!s)if(e.readyState>=e.HAVE_METADATA)s=!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",o),e.addEventListener("loadeddata",o),e.addEventListener("canplay",o),e.addEventListener("seeked",o),e.addEventListener("error",i),e.addEventListener("stalled",i),o();try{return await r}finally{e.removeEventListener("loadedmetadata",o),e.removeEventListener("loadeddata",o),e.removeEventListener("canplay",o),e.removeEventListener("seeked",o),e.removeEventListener("error",i),e.removeEventListener("stalled",i)}}static loadImage(e){return new Promise((n,r)=>{const s=Lu();s.onload=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load image"))},s.crossOrigin="anonymous",s.referrerPolicy="strict-origin-when-cross-origin",s.src=e})}static async getVideoSize(e){return ar.usingObjectURL(e,async n=>{const r=await ar.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const n=await ar.usingObjectURL(e,ar.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(Ps.isPng(r,0)){const s=Ps.findChunk(r,"pHYs");if(s){const o=Ps.parsePhys(r,s.dataOffset);if(o.unit===0&&o.ppux===o.ppuy){const i=Math.max(o.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"?F9(await e.arrayBuffer()):e.type==="image/avif"?L9(await e.arrayBuffer()):e.type==="image/webp"?B9(await e.arrayBuffer()):e.type==="image/apng"?R9(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return DT.includes(e||"")}static isStaticImageType(e){return OT.includes(e||"")}static isVectorImageType(e){return jT.includes(e||"")}static isImageType(e){return Sg.includes(e)}static async usingObjectURL(e,n){const r=URL.createObjectURL(e);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function _e(t,e,n){return t+(e-t)*n}function cs(t=""){let e=0,n=0,r=0,s=0;function o(){const i=e^e<<11;return e=n,n=r,r=s,s^=(s>>>19^i^i>>>8)>>>0,s/4294967296*2}for(let i=0;i<t.length+64;i++)e^=t.charCodeAt(i)|0,o();return o}function jl(t,e,n,r=!1){const[s,o]=e,[i,a]=n,l=i+(t-s)/(o-s)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function ns(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function hn(t,e){if(ns(t,e))return t[e]}function DC(t){return Object.keys(t)}function ut(t){return Object.values(t)}function Xn(t){return Object.entries(t)}function x0(t){return Object.fromEntries(t)}function au(t,e){const n={};let r=!1;for(const[s,o]of Xn(t))e(s,o)?n[s]=o:r=!0;return r?n:t}function rd(t,e){const n={};for(const[r,s]of Xn(t)){const o=e(r,s);n[r]=o}return n}function RT(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 s of n)if(!r.has(s)||!Object.is(t[s],e[s]))return!1;return!0}function H9(t){const e=K9(t.chars),n=W9(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),s=G9(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:s}}function K9(t){const e={},n={},r=t.length;for(let s=0;s<r;s++){const o=t[s];e[s]=o,n[o]=s}return{byCode:e,byChar:n,length:r}}function W9(t,e,n,r){const s=t.byChar[e],o=t.byChar[n],i=t.byChar[r];if(s===void 0||o===void 0||i===void 0)throw new Error("invalid charSet");if(o-s<3)throw new Error("mostPositive must be at least 3 characters away from neutral");if(s-i<3)throw new Error("mostNegative must be at least 3 characters away from neutral");return{firstPositive:t.byCode[s],mostPositive:t.byCode[o],firstNegative:t.byCode[s-1],mostNegative:t.byCode[i]}}function G9(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var fy=null;function w0(){return fy||(fy=H9({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Jo(t,e,n){const r=n.byChar[t],s=n.byChar[e];return Math.abs(r-s)}function b0(t,e){const n=t[0];if(n>e.mostPositive||n<e.mostNegative)throw new Error("invalid firstChar on key");return n===e.mostPositive?Jo(n,e.firstPositive,e)+1+dp(t.slice(1),"positive",e):n===e.mostNegative?Jo(n,e.firstNegative,e)+1+dp(t.slice(1),"negative",e):n>=e.firstPositive?Jo(n,e.firstPositive,e)+2:Jo(n,e.firstNegative,e)+2}function dp(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"?Jo(r,n.mostNegative,n)+1+dp(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Jo(r,n.mostPositive,n)+1+dp(t.slice(1),e,n):e==="positive"?Jo(r,n.mostNegative,n)+2:Jo(r,n.mostPositive,n)+2}function vg(t,e,n,r,s){const o=Math.max(t.length,e.length);return n==="start"?[t.padStart(o,r),e.padStart(o,r)]:[t.padEnd(o,r),e.padEnd(o,r)]}function V9(t,e,n){let[r,s]=vg(t,e,"end",n.first),o=Gv(r,s,n);o===1&&(r=r.padEnd(r.length+1,n.first),o=n.length);const i=FT(Math.floor(o/2),n);return P0(r,i,n)}function Gv(t,e,n){const[r,s]=vg(t,e,"end",n.first).sort(),o=LT(s,r,n);return Y9(o,n)}function P0(t,e,n){const r=n.length,[s,o]=vg(t,e,"start",n.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){const c=n.byChar[s[l]],u=n.byChar[o[l]],h=c+u+a;a=Math.floor(h/r);const f=h%r;i.unshift(n.byCode[f])}return a>0&&i.unshift(n.byCode[a]),i.join("")}function LT(t,e,n){const r=n.length,[s,o]=vg(t,e,"start",n.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){let c=n.byChar[s[l]];const u=n.byChar[o[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 $T(t,e){return P0(t,e.byCode[1],e)}function Vv(t,e){return LT(t,e.byCode[1],e)}function FT(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 Y9(t,e){let n=0;const r=t.length,s=e.length;for(let o=0;o<r;o++)n+=e.byChar[t[o]]*Math.pow(s,r-o-1);return n}function X9(t){return t.firstPositive+t.byCode[0]}function q9(t,e){return b0(t,e)===t.length}function RC(t,e){hp(t,e)}function hp(t,e){const n=BT(t,e),r=b0(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function NT(t,e){if(!q9(t,e))throw new Error("invalid integer length: "+t)}function zT(t,e){NT(t,e);const[n,r]=UT(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=$T(r,e);return n+i}const o=Q9(n,e);return HT(o,"lower",e)}function Z9(t,e){NT(t,e);const[n,r]=UT(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Vv(r,e);return n+i}const o=J9(n,e);return HT(o,"upper",e)}function BT(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 UT(t,e){const n=BT(t,e),r=t.slice(n.length);return[n,r]}function Q9(t,e){const n=t>=e.firstPositive,r=$T(t,e),s=t[t.length-1]===e.mostPositive,o=r[r.length-1]===e.mostPositive;return n&&o?r+e.mostNegative:!n&&s?t.slice(0,t.length-1):r}function J9(t,e){const n=t>=e.firstPositive,r=t[t.length-1]===e.mostNegative;if(n&&r){const s=t.slice(0,t.length-1);return Vv(s,e)}return!n&&r?t+e.mostPositive:Vv(t,e)}function HT(t,e,n){const r=b0(t,n),s=e==="upper"?n.byCode[n.length-1]:n.byCode[0];return t+s.repeat(r-t.length)}function KT(t,e){const n=FT(Math.floor(Math.random()*e.jitterRange),e);return P0(t,n,e)}function eB(t,e,n){const r=t.padEnd(t.length+e,n.first);return KT(r,n)}function tB(t,e,n){const r=hp(t,n),s=zT(r,n);let o=0;if(e!==null){const a=Gv(t,e,n);a<n.jitterRange+1&&(o=Math.max(o,LC(a,n)))}const i=Gv(t,s,n);return i<n.jitterRange+1&&(o=Math.max(o,LC(i,n))),o}function LC(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([s,o])=>o>n);return r?parseInt(r[0]):0}function nB(t,e,n=w0()){if(t!==null&&RC(t,n),e!==null&&RC(e,n),t===null&&e===null)return X9(n);if(t===null){const r=hp(e,n);return Z9(r,n)}if(e===null){const r=hp(t,n);return zT(r,n)}if(t>=e)throw new Error(t+" >= "+e);return V9(t,e,n)}function WT(t,e,n=w0()){const r=nB(t,e,n),s=tB(r,e,n);return s?eB(r,s,n):KT(r,n)}function GT(t,e,n,r=w0()){return rB(t,e,n,r,WT,GT)}function rB(t,e,n,r,s,o){if(n===0)return[];if(n===1)return[s(t,e,r)];if(e==null){let l=s(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=s(l,e,r),c.push(l);return c}if(t==null){let l=s(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=s(t,l,r),c.push(l);return c.reverse(),c}const i=Math.floor(n/2),a=s(t,e,r);return[...o(t,a,i,r),a,...o(a,e,n-i-1,r)]}const Gl=GT,VT="a0";function sB(t){try{WT(t,null)}catch{throw new Error("invalid index: "+t)}}function Ol(t,e,n){return Gl(t??null,e??null,n)}function py(t,e){return Gl(t??null,null,e)}function $u(t,e){return Gl(t??null,e??null,1)[0]}function _s(t=null){return Gl(t,null,1)[0]}function oB(t=null){return Gl(null,t,1)[0]}function Fu(t,e="a1"){return[e,...Gl(e,null,t)]}function cn(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function iB(t,e){return t.id>e.id?1:-1}function C0(t){try{return localStorage.getItem(t)}catch{return null}}function _0(t,e){try{localStorage.setItem(t,e)}catch{}}function aB(){try{localStorage.clear()}catch{}}function YT(t){try{return sessionStorage.getItem(t)}catch{return null}}function I0(t,e){try{sessionStorage.setItem(t,e)}catch{}}function XT(t){try{sessionStorage.removeItem(t)}catch{}}function lB(){try{sessionStorage.clear()}catch{}}const sl=[],cB=60,tf=Math.ceil(1e3/cB);let wc,gy=0,Yv=0;const uB=()=>{const t=sl.splice(0,sl.length);for(const e of t)e()};function qT(){if(wc)return;const t=Date.now(),e=t-Yv;if(gy+e<tf){wc=requestAnimationFrame(()=>{wc=void 0,qT()});return}wc=requestAnimationFrame(()=>{wc=void 0,Yv=t,gy=Math.min(gy+e-tf,tf*10),uB()})}let $C=!1;function ZT(t){return sl.includes(t)||(sl.push(t),$C||($C=!0,Yv=Date.now()-tf-1),qT()),()=>{const e=sl.indexOf(t);e>-1&&sl.splice(e,1)}}class dB{constructor(){I(this,"timeouts",new Map);I(this,"intervals",new Map);I(this,"rafs",new Map);this.setTimeout=this.setTimeout.bind(this),this.setInterval=this.setInterval.bind(this),this.requestAnimationFrame=this.requestAnimationFrame.bind(this),this.dispose=this.dispose.bind(this)}setTimeout(e,n,r,...s){const o=window.setTimeout(n,r,s),i=this.timeouts.get(e)??[];return this.timeouts.set(e,[...i,o]),o}setInterval(e,n,r,...s){const o=window.setInterval(n,r,s),i=this.intervals.get(e)??[];return this.intervals.set(e,[...i,o]),o}requestAnimationFrame(e,n){const r=window.requestAnimationFrame(n),s=this.rafs.get(e)??[];return this.rafs.set(e,[...s,r]),r}dispose(e){var n,r,s;(n=this.timeouts.get(e))==null||n.forEach(o=>clearTimeout(o)),(r=this.intervals.get(e))==null||r.forEach(o=>clearInterval(o)),(s=this.rafs.get(e))==null||s.forEach(o=>cancelAnimationFrame(o)),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,...s)=>this.setTimeout(e,n,r,s),setInterval:(n,r,...s)=>this.setInterval(e,n,r,s),requestAnimationFrame:n=>this.requestAnimationFrame(e,n),dispose:()=>this.dispose(e)}}}const ge=(t,e)=>{try{return new URL(t,e)}catch{return}};function hB(t){return t!==void 0}function fB(){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 QT=fB(),nt=QT[0];QT[1];const pB=Object.getPrototypeOf(nt({}));_i("@tldraw/utils","3.7.2","esm");var bc=function(t){return t&&t.Math===Math&&t},In=bc(typeof globalThis=="object"&&globalThis)||bc(typeof window=="object"&&window)||bc(typeof self=="object"&&self)||bc(typeof dn=="object"&&dn)||bc(typeof dn=="object"&&dn)||function(){return this}()||Function("return this")(),E0={},En=function(t){try{return!!t()}catch{return!0}},gB=En,Ii=!gB(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),mB=En,xg=!mB(function(){var t=(function(){}).bind();return typeof t!="function"||t.hasOwnProperty("prototype")}),yB=xg,th=Function.prototype.call,Io=yB?th.bind(th):function(){return th.apply(th,arguments)},JT={},eM={}.propertyIsEnumerable,tM=Object.getOwnPropertyDescriptor,SB=tM&&!eM.call({1:2},1);JT.f=SB?function(e){var n=tM(this,e);return!!n&&n.enumerable}:eM;var nM=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}},rM=xg,sM=Function.prototype,Xv=sM.call,vB=rM&&sM.bind.bind(Xv,Xv),Lt=rM?vB:function(t){return function(){return Xv.apply(t,arguments)}},oM=Lt,xB=oM({}.toString),wB=oM("".slice),Vl=function(t){return wB(xB(t),8,-1)},bB=Lt,PB=En,CB=Vl,my=Object,_B=bB("".split),IB=PB(function(){return!my("z").propertyIsEnumerable(0)})?function(t){return CB(t)==="String"?_B(t,""):my(t)}:my,wg=function(t){return t==null},EB=wg,kB=TypeError,Yl=function(t){if(EB(t))throw new kB("Can't call method on "+t);return t},TB=IB,MB=Yl,bg=function(t){return TB(MB(t))},yy=typeof document=="object"&&document.all,kn=typeof yy>"u"&&yy!==void 0?function(t){return typeof t=="function"||t===yy}:function(t){return typeof t=="function"},AB=kn,Xl=function(t){return typeof t=="object"?t!==null:AB(t)},Sy=In,jB=kn,OB=function(t){return jB(t)?t:void 0},Pg=function(t,e){return arguments.length<2?OB(Sy[t]):Sy[t]&&Sy[t][e]},DB=Lt,iM=DB({}.isPrototypeOf),RB=In,FC=RB.navigator,NC=FC&&FC.userAgent,LB=NC?String(NC):"",aM=In,vy=LB,zC=aM.process,BC=aM.Deno,UC=zC&&zC.versions||BC&&BC.version,HC=UC&&UC.v8,Xr,fp;HC&&(Xr=HC.split("."),fp=Xr[0]>0&&Xr[0]<4?1:+(Xr[0]+Xr[1]));!fp&&vy&&(Xr=vy.match(/Edge\/(\d+)/),(!Xr||Xr[1]>=74)&&(Xr=vy.match(/Chrome\/(\d+)/),Xr&&(fp=+Xr[1])));var $B=fp,KC=$B,FB=En,NB=In,zB=NB.String,lM=!!Object.getOwnPropertySymbols&&!FB(function(){var t=Symbol("symbol detection");return!zB(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&KC&&KC<41}),BB=lM,cM=BB&&!Symbol.sham&&typeof Symbol.iterator=="symbol",UB=Pg,HB=kn,KB=iM,WB=cM,GB=Object,uM=WB?function(t){return typeof t=="symbol"}:function(t){var e=UB("Symbol");return HB(e)&&KB(e.prototype,GB(t))},VB=String,YB=function(t){try{return VB(t)}catch{return"Object"}},XB=kn,qB=YB,ZB=TypeError,k0=function(t){if(XB(t))return t;throw new ZB(qB(t)+" is not a function")},QB=k0,JB=wg,T0=function(t,e){var n=t[e];return JB(n)?void 0:QB(n)},xy=Io,wy=kn,by=Xl,e7=TypeError,t7=function(t,e){var n,r;if(e==="string"&&wy(n=t.toString)&&!by(r=xy(n,t))||wy(n=t.valueOf)&&!by(r=xy(n,t))||e!=="string"&&wy(n=t.toString)&&!by(r=xy(n,t)))return r;throw new e7("Can't convert object to primitive value")},dM={exports:{}},WC=In,n7=Object.defineProperty,M0=function(t,e){try{n7(WC,t,{value:e,configurable:!0,writable:!0})}catch{WC[t]=e}return e},r7=In,s7=M0,GC="__core-js_shared__",VC=dM.exports=r7[GC]||s7(GC,{});(VC.versions||(VC.versions=[])).push({version:"3.40.0",mode:"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.40.0/LICENSE",source:"https://github.com/zloirock/core-js"});var A0=dM.exports,YC=A0,j0=function(t,e){return YC[t]||(YC[t]=e||{})},o7=Yl,i7=Object,sd=function(t){return i7(o7(t))},a7=Lt,l7=sd,c7=a7({}.hasOwnProperty),Ei=Object.hasOwn||function(e,n){return c7(l7(e),n)},u7=Lt,d7=0,h7=Math.random(),f7=u7(1 .toString),hM=function(t){return"Symbol("+(t===void 0?"":t)+")_"+f7(++d7+h7,36)},p7=In,g7=j0,XC=Ei,m7=hM,y7=lM,S7=cM,ol=p7.Symbol,Py=g7("wks"),v7=S7?ol.for||ol:ol&&ol.withoutSetter||m7,Eo=function(t){return XC(Py,t)||(Py[t]=y7&&XC(ol,t)?ol[t]:v7("Symbol."+t)),Py[t]},x7=Io,qC=Xl,ZC=uM,w7=T0,b7=t7,P7=Eo,C7=TypeError,_7=P7("toPrimitive"),I7=function(t,e){if(!qC(t)||ZC(t))return t;var n=w7(t,_7),r;if(n){if(e===void 0&&(e="default"),r=x7(n,t,e),!qC(r)||ZC(r))return r;throw new C7("Can't convert object to primitive value")}return e===void 0&&(e="number"),b7(t,e)},E7=I7,k7=uM,fM=function(t){var e=E7(t,"string");return k7(e)?e:e+""},T7=In,QC=Xl,qv=T7.document,M7=QC(qv)&&QC(qv.createElement),pM=function(t){return M7?qv.createElement(t):{}},A7=Ii,j7=En,O7=pM,gM=!A7&&!j7(function(){return Object.defineProperty(O7("div"),"a",{get:function(){return 7}}).a!==7}),D7=Ii,R7=Io,L7=JT,$7=nM,F7=bg,N7=fM,z7=Ei,B7=gM,JC=Object.getOwnPropertyDescriptor;E0.f=D7?JC:function(e,n){if(e=F7(e),n=N7(n),B7)try{return JC(e,n)}catch{}if(z7(e,n))return $7(!R7(L7.f,e,n),e[n])};var ql={},U7=Ii,H7=En,mM=U7&&H7(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),K7=Xl,W7=String,G7=TypeError,Pa=function(t){if(K7(t))return t;throw new G7(W7(t)+" is not an object")},V7=Ii,Y7=gM,X7=mM,nh=Pa,e_=fM,q7=TypeError,Cy=Object.defineProperty,Z7=Object.getOwnPropertyDescriptor,_y="enumerable",Iy="configurable",Ey="writable";ql.f=V7?X7?function(e,n,r){if(nh(e),n=e_(n),nh(r),typeof e=="function"&&n==="prototype"&&"value"in r&&Ey in r&&!r[Ey]){var s=Z7(e,n);s&&s[Ey]&&(e[n]=r.value,r={configurable:Iy in r?r[Iy]:s[Iy],enumerable:_y in r?r[_y]:s[_y],writable:!1})}return Cy(e,n,r)}:Cy:function(e,n,r){if(nh(e),n=e_(n),nh(r),Y7)try{return Cy(e,n,r)}catch{}if("get"in r||"set"in r)throw new q7("Accessors not supported");return"value"in r&&(e[n]=r.value),e};var Q7=Ii,J7=ql,eU=nM,O0=Q7?function(t,e,n){return J7.f(t,e,eU(1,n))}:function(t,e,n){return t[e]=n,t},yM={exports:{}},Zv=Ii,tU=Ei,SM=Function.prototype,nU=Zv&&Object.getOwnPropertyDescriptor,rU=tU(SM,"name"),sU=rU&&(!Zv||Zv&&nU(SM,"name").configurable),oU={CONFIGURABLE:sU},iU=Lt,aU=kn,Qv=A0,lU=iU(Function.toString);aU(Qv.inspectSource)||(Qv.inspectSource=function(t){return lU(t)});var vM=Qv.inspectSource,cU=In,uU=kn,t_=cU.WeakMap,dU=uU(t_)&&/native code/.test(String(t_)),hU=j0,fU=hM,n_=hU("keys"),xM=function(t){return n_[t]||(n_[t]=fU(t))},D0={},pU=dU,wM=In,gU=O0,ky=Ei,Ty=A0,mU=xM,yU=D0,r_="Object already initialized",s_=wM.TypeError,SU=wM.WeakMap,Jv,pp,ex,vU=function(t){return ex(t)?pp(t):Jv(t,{})};if(pU||Ty.state){var ms=Ty.state||(Ty.state=new SU);ms.get=ms.get,ms.has=ms.has,ms.set=ms.set,Jv=function(t,e){if(ms.has(t))throw new s_(r_);return e.facade=t,ms.set(t,e),e},pp=function(t){return ms.get(t)||{}},ex=function(t){return ms.has(t)}}else{var Ma=mU("state");yU[Ma]=!0,Jv=function(t,e){if(ky(t,Ma))throw new s_(r_);return e.facade=t,gU(t,Ma,e),e},pp=function(t){return ky(t,Ma)?t[Ma]:{}},ex=function(t){return ky(t,Ma)}}var bM={get:pp,enforce:vU},R0=Lt,xU=En,wU=kn,rh=Ei,tx=Ii,bU=oU.CONFIGURABLE,PU=vM,PM=bM,CU=PM.enforce,_U=PM.get,o_=String,nf=Object.defineProperty,IU=R0("".slice),EU=R0("".replace),kU=R0([].join),TU=tx&&!xU(function(){return nf(function(){},"length",{value:8}).length!==8}),MU=String(String).split("String"),AU=yM.exports=function(t,e,n){IU(o_(e),0,7)==="Symbol("&&(e="["+EU(o_(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!rh(t,"name")||bU&&t.name!==e)&&(tx?nf(t,"name",{value:e,configurable:!0}):t.name=e),TU&&n&&rh(n,"arity")&&t.length!==n.arity&&nf(t,"length",{value:n.arity});try{n&&rh(n,"constructor")&&n.constructor?tx&&nf(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch{}var r=CU(t);return rh(r,"source")||(r.source=kU(MU,typeof e=="string"?e:"")),t};Function.prototype.toString=AU(function(){return wU(this)&&_U(this).source||PU(this)},"toString");var jU=yM.exports,OU=kn,DU=ql,RU=jU,LU=M0,CM=function(t,e,n,r){r||(r={});var s=r.enumerable,o=r.name!==void 0?r.name:e;if(OU(n)&&RU(n,o,r),r.global)s?t[e]=n:LU(e,n);else{try{r.unsafe?t[e]&&(s=!0):delete t[e]}catch{}s?t[e]=n:DU.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},_M={},$U=Math.ceil,FU=Math.floor,NU=Math.trunc||function(e){var n=+e;return(n>0?FU:$U)(n)},zU=NU,Ca=function(t){var e=+t;return e!==e||e===0?0:zU(e)},BU=Ca,UU=Math.max,HU=Math.min,KU=function(t,e){var n=BU(t);return n<0?UU(n+e,0):HU(n,e)},WU=Ca,GU=Math.min,IM=function(t){var e=WU(t);return e>0?GU(e,9007199254740991):0},VU=IM,od=function(t){return VU(t.length)},YU=bg,XU=KU,qU=od,ZU=function(t){return function(e,n,r){var s=YU(e),o=qU(s);if(o===0)return!t&&-1;var i=XU(r,o),a;if(t&&n!==n){for(;o>i;)if(a=s[i++],a!==a)return!0}else for(;o>i;i++)if((t||i in s)&&s[i]===n)return t||i||0;return!t&&-1}},QU={indexOf:ZU(!1)},JU=Lt,My=Ei,eH=bg,tH=QU.indexOf,nH=D0,i_=JU([].push),EM=function(t,e){var n=eH(t),r=0,s=[],o;for(o in n)!My(nH,o)&&My(n,o)&&i_(s,o);for(;e.length>r;)My(n,o=e[r++])&&(~tH(s,o)||i_(s,o));return s},L0=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],rH=EM,sH=L0,oH=sH.concat("length","prototype");_M.f=Object.getOwnPropertyNames||function(e){return rH(e,oH)};var kM={};kM.f=Object.getOwnPropertySymbols;var iH=Pg,aH=Lt,lH=_M,cH=kM,uH=Pa,dH=aH([].concat),hH=iH("Reflect","ownKeys")||function(e){var n=lH.f(uH(e)),r=cH.f;return r?dH(n,r(e)):n},a_=Ei,fH=hH,pH=E0,gH=ql,mH=function(t,e,n){for(var r=fH(e),s=gH.f,o=pH.f,i=0;i<r.length;i++){var a=r[i];!a_(t,a)&&!(n&&a_(n,a))&&s(t,a,o(e,a))}},yH=En,SH=kn,vH=/#|\.prototype\./,id=function(t,e){var n=wH[xH(t)];return n===PH?!0:n===bH?!1:SH(e)?yH(e):!!e},xH=id.normalize=function(t){return String(t).replace(vH,".").toLowerCase()},wH=id.data={},bH=id.NATIVE="N",PH=id.POLYFILL="P",CH=id,sh=In,_H=E0.f,IH=O0,EH=CM,kH=M0,TH=mH,MH=CH,Zl=function(t,e){var n=t.target,r=t.global,s=t.stat,o,i,a,l,c,u;if(r?i=sh:s?i=sh[n]||kH(n,{}):i=sh[n]&&sh[n].prototype,i)for(a in e){if(c=e[a],t.dontCallGetSet?(u=_H(i,a),l=u&&u.value):l=i[a],o=MH(r?a:n+(s?".":"#")+a,t.forced),!o&&l!==void 0){if(typeof c==typeof l)continue;TH(c,l)}(t.sham||l&&l.sham)&&IH(c,"sham",!0),EH(i,a,c,t)}},TM={},AH=EM,jH=L0,OH=Object.keys||function(e){return AH(e,jH)},DH=Ii,RH=mM,LH=ql,$H=Pa,FH=bg,NH=OH;TM.f=DH&&!RH?Object.defineProperties:function(e,n){$H(e);for(var r=FH(n),s=NH(n),o=s.length,i=0,a;o>i;)LH.f(e,a=s[i++],r[a]);return e};var zH=Pg,BH=zH("document","documentElement"),UH=Pa,HH=TM,l_=L0,KH=D0,WH=BH,GH=pM,VH=xM,c_=">",u_="<",nx="prototype",rx="script",MM=VH("IE_PROTO"),Ay=function(){},AM=function(t){return u_+rx+c_+t+u_+"/"+rx+c_},d_=function(t){t.write(AM("")),t.close();var e=t.parentWindow.Object;return t=null,e},YH=function(){var t=GH("iframe"),e="java"+rx+":",n;return t.style.display="none",WH.appendChild(t),t.src=String(e),n=t.contentWindow.document,n.open(),n.write(AM("document.F=Object")),n.close(),n.F},oh,rf=function(){try{oh=new ActiveXObject("htmlfile")}catch{}rf=typeof document<"u"?document.domain&&oh?d_(oh):YH():d_(oh);for(var t=l_.length;t--;)delete rf[nx][l_[t]];return rf()};KH[MM]=!0;var jM=Object.create||function(e,n){var r;return e!==null?(Ay[nx]=UH(e),r=new Ay,Ay[nx]=null,r[MM]=e):r=rf(),n===void 0?r:HH.f(r,n)},XH=Eo,qH=jM,ZH=ql.f,sx=XH("unscopables"),ox=Array.prototype;ox[sx]===void 0&&ZH(ox,sx,{configurable:!0,value:qH(null)});var $0=function(t){ox[sx][t]=!0},QH=Zl,JH=sd,eK=od,tK=Ca,nK=$0;QH({target:"Array",proto:!0},{at:function(e){var n=JH(this),r=eK(n),s=tK(e),o=s>=0?s:r+s;return o<0||o>=r?void 0:n[o]}});nK("at");var rK=In,sK=Lt,ad=function(t,e){return sK(rK[t].prototype[e])},oK=ad;oK("Array","at");var iK=Vl,OM=Array.isArray||function(e){return iK(e)==="Array"},aK=TypeError,lK=9007199254740991,cK=function(t){if(t>lK)throw aK("Maximum allowed index exceeded");return t},uK=Vl,dK=Lt,hK=function(t){if(uK(t)==="Function")return dK(t)},h_=hK,fK=k0,pK=xg,gK=h_(h_.bind),mK=function(t,e){return fK(t),e===void 0?t:pK?gK(t,e):function(){return t.apply(e,arguments)}},yK=OM,SK=od,vK=cK,xK=mK,DM=function(t,e,n,r,s,o,i,a){for(var l=s,c=0,u=i?xK(i,a):!1,h,f;c<r;)c in n&&(h=u?u(n[c],c,e):n[c],o>0&&yK(h)?(f=SK(h),l=DM(t,e,h,f,l,o-1)-1):(vK(l+1),t[l]=h),l++),c++;return l},RM=DM,wK=Eo,bK=wK("toStringTag"),LM={};LM[bK]="z";var PK=String(LM)==="[object z]",CK=PK,_K=kn,sf=Vl,IK=Eo,EK=IK("toStringTag"),kK=Object,TK=sf(function(){return arguments}())==="Arguments",MK=function(t,e){try{return t[e]}catch{}},$M=CK?sf:function(t){var e,n,r;return t===void 0?"Undefined":t===null?"Null":typeof(n=MK(e=kK(t),EK))=="string"?n:TK?sf(e):(r=sf(e))==="Object"&&_K(e.callee)?"Arguments":r},AK=Lt,jK=En,FM=kn,OK=$M,DK=Pg,RK=vM,NM=function(){},zM=DK("Reflect","construct"),F0=/^\s*(?:class|function)\b/,LK=AK(F0.exec),$K=!F0.test(NM),Pc=function(e){if(!FM(e))return!1;try{return zM(NM,[],e),!0}catch{return!1}},BM=function(e){if(!FM(e))return!1;switch(OK(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return $K||!!LK(F0,RK(e))}catch{return!0}};BM.sham=!0;var FK=!zM||jK(function(){var t;return Pc(Pc.call)||!Pc(Object)||!Pc(function(){t=!0})||t})?BM:Pc,f_=OM,NK=FK,zK=Xl,BK=Eo,UK=BK("species"),p_=Array,HK=function(t){var e;return f_(t)&&(e=t.constructor,NK(e)&&(e===p_||f_(e.prototype))?e=void 0:zK(e)&&(e=e[UK],e===null&&(e=void 0))),e===void 0?p_:e},KK=HK,UM=function(t,e){return new(KK(t))(e===0?0:e)},WK=Zl,GK=RM,VK=k0,YK=sd,XK=od,qK=UM;WK({target:"Array",proto:!0},{flatMap:function(e){var n=YK(this),r=XK(n),s;return VK(e),s=qK(n,0),s.length=GK(s,n,n,r,0,1,e,arguments.length>1?arguments[1]:void 0),s}});var ZK=$0;ZK("flatMap");var QK=ad;QK("Array","flatMap");var JK=Zl,eW=RM,tW=sd,nW=od,rW=Ca,sW=UM;JK({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,n=tW(this),r=nW(n),s=sW(n,0);return s.length=eW(s,n,n,r,0,e===void 0?1:rW(e)),s}});var oW=$0;oW("flat");var iW=ad;iW("Array","flat");var aW=$M,lW=String,ld=function(t){if(aW(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return lW(t)},cW=Zl,uW=Lt,dW=Yl,hW=Ca,fW=ld,pW=En,gW=uW("".charAt),mW=pW(function(){return"𠮷".at(-2)!=="\uD842"});cW({target:"String",proto:!0,forced:mW},{at:function(e){var n=fW(dW(this)),r=n.length,s=hW(e),o=s>=0?s:r+s;return o<0||o>=r?void 0:gW(n,o)}});var yW=ad;yW("String","at");var SW=Pa,HM=function(){var t=SW(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},N0=En,vW=In,z0=vW.RegExp,KM=N0(function(){var t=z0("a","y");return t.lastIndex=2,t.exec("abcd")!==null});KM||N0(function(){return!z0("a","y").sticky});var xW=KM||N0(function(){var t=z0("^r","gy");return t.lastIndex=2,t.exec("str")!==null}),wW={BROKEN_CARET:xW},bW=En,PW=In,CW=PW.RegExp,_W=bW(function(){var t=CW(".","s");return!(t.dotAll&&t.test(`
|
|
68
|
+
`)&&t.flags==="s")}),IW=En,EW=In,kW=EW.RegExp,TW=IW(function(){var t=kW("(?<a>b)","g");return t.exec("b").groups.a!=="b"||"b".replace(t,"$<a>c")!=="bc"}),il=Io,Cg=Lt,MW=ld,AW=HM,jW=wW,OW=j0,DW=jM,RW=bM.get,LW=_W,$W=TW,FW=OW("native-string-replace",String.prototype.replace),gp=RegExp.prototype.exec,ix=gp,NW=Cg("".charAt),zW=Cg("".indexOf),BW=Cg("".replace),jy=Cg("".slice),ax=function(){var t=/a/,e=/b*/g;return il(gp,t,"a"),il(gp,e,"a"),t.lastIndex!==0||e.lastIndex!==0}(),WM=jW.BROKEN_CARET,lx=/()??/.exec("")[1]!==void 0,UW=ax||lx||WM||LW||$W;UW&&(ix=function(e){var n=this,r=RW(n),s=MW(e),o=r.raw,i,a,l,c,u,h,f;if(o)return o.lastIndex=n.lastIndex,i=il(ix,o,s),n.lastIndex=o.lastIndex,i;var p=r.groups,g=WM&&n.sticky,m=il(AW,n),v=n.source,y=0,S=s;if(g&&(m=BW(m,"y",""),zW(m,"g")===-1&&(m+="g"),S=jy(s,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&NW(s,n.lastIndex-1)!==`
|
|
69
|
+
`)&&(v="(?: "+v+")",S=" "+S,y++),a=new RegExp("^(?:"+v+")",m)),lx&&(a=new RegExp("^"+v+"$(?!\\s)",m)),ax&&(l=n.lastIndex),c=il(gp,g?a:n,S),g?c?(c.input=jy(c.input,y),c[0]=jy(c[0],y),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:ax&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),lx&&c&&c.length>1&&il(FW,c[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(c[u]=void 0)}),c&&p)for(c.groups=h=DW(null),u=0;u<p.length;u++)f=p[u],h[f[0]]=c[f[1]];return c});var B0=ix,HW=Zl,g_=B0;HW({target:"RegExp",proto:!0,forced:/./.exec!==g_},{exec:g_});var KW=xg,GM=Function.prototype,m_=GM.apply,y_=GM.call,WW=typeof Reflect=="object"&&Reflect.apply||(KW?y_.bind(m_):function(){return y_.apply(m_,arguments)}),S_=Io,v_=CM,GW=B0,x_=En,VM=Eo,VW=O0,YW=VM("species"),Oy=RegExp.prototype,XW=function(t,e,n,r){var s=VM(t),o=!x_(function(){var c={};return c[s]=function(){return 7},""[t](c)!==7}),i=o&&!x_(function(){var c=!1,u=/a/;return t==="split"&&(u={},u.constructor={},u.constructor[YW]=function(){return u},u.flags="",u[s]=/./[s]),u.exec=function(){return c=!0,null},u[s](""),!c});if(!o||!i||n){var a=/./[s],l=e(s,""[t],function(c,u,h,f,p){var g=u.exec;return g===GW||g===Oy.exec?o&&!p?{done:!0,value:S_(a,u,h,f)}:{done:!0,value:S_(c,h,u,f)}:{done:!1}});v_(String.prototype,t,l[0]),v_(Oy,s,l[1])}r&&VW(Oy[s],"sham",!0)},U0=Lt,qW=Ca,ZW=ld,QW=Yl,JW=U0("".charAt),w_=U0("".charCodeAt),eG=U0("".slice),tG=function(t){return function(e,n){var r=ZW(QW(e)),s=qW(n),o=r.length,i,a;return s<0||s>=o?t?"":void 0:(i=w_(r,s),i<55296||i>56319||s+1===o||(a=w_(r,s+1))<56320||a>57343?t?JW(r,s):i:t?eG(r,s,s+2):(i-55296<<10)+(a-56320)+65536)}},nG={charAt:tG(!0)},rG=nG.charAt,sG=function(t,e,n){return e+(n?rG(t,e).length:1)},H0=Lt,oG=sd,iG=Math.floor,Dy=H0("".charAt),aG=H0("".replace),Ry=H0("".slice),lG=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,cG=/\$([$&'`]|\d{1,2})/g,YM=function(t,e,n,r,s,o){var i=n+t.length,a=r.length,l=cG;return s!==void 0&&(s=oG(s),l=lG),aG(o,l,function(c,u){var h;switch(Dy(u,0)){case"$":return"$";case"&":return t;case"`":return Ry(e,0,n);case"'":return Ry(e,i);case"<":h=s[Ry(u,1,-1)];break;default:var f=+u;if(f===0)return c;if(f>a){var p=iG(f/10);return p===0?c:p<=a?r[p-1]===void 0?Dy(u,1):r[p-1]+Dy(u,1):c}h=r[f-1]}return h===void 0?"":h})},b_=Io,uG=Pa,dG=kn,hG=Vl,fG=B0,pG=TypeError,gG=function(t,e){var n=t.exec;if(dG(n)){var r=b_(n,t,e);return r!==null&&uG(r),r}if(hG(t)==="RegExp")return b_(fG,t,e);throw new pG("RegExp#exec called on incompatible receiver")},mG=WW,P_=Io,_g=Lt,yG=XW,SG=En,vG=Pa,xG=kn,wG=wg,bG=Ca,PG=IM,Aa=ld,CG=Yl,_G=sG,IG=T0,EG=YM,kG=gG,TG=Eo,cx=TG("replace"),MG=Math.max,AG=Math.min,jG=_g([].concat),Ly=_g([].push),C_=_g("".indexOf),__=_g("".slice),OG=function(t){return t===void 0?t:String(t)},DG=function(){return"a".replace(/./,"$0")==="$0"}(),I_=function(){return/./[cx]?/./[cx]("a","$0")==="":!1}(),RG=!SG(function(){var t=/./;return t.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(t,"$<a>")!=="7"});yG("replace",function(t,e,n){var r=I_?"$":"$0";return[function(o,i){var a=CG(this),l=wG(o)?void 0:IG(o,cx);return l?P_(l,o,a,i):P_(e,Aa(a),o,i)},function(s,o){var i=vG(this),a=Aa(s);if(typeof o=="string"&&C_(o,r)===-1&&C_(o,"$<")===-1){var l=n(e,i,a,o);if(l.done)return l.value}var c=xG(o);c||(o=Aa(o));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var f=[],p;p=kG(i,a),!(p===null||(Ly(f,p),!u));){var g=Aa(p[0]);g===""&&(i.lastIndex=_G(a,PG(i.lastIndex),h))}for(var m="",v=0,y=0;y<f.length;y++){p=f[y];for(var S=Aa(p[0]),b=MG(AG(bG(p.index),a.length),0),P=[],C,_=1;_<p.length;_++)Ly(P,OG(p[_]));var E=p.groups;if(c){var k=jG([S],P,b,a);E!==void 0&&Ly(k,E),C=Aa(mG(o,void 0,k))}else C=EG(S,a,b,P,E,o);b>=v&&(m+=__(a,v,b)+C,v=b+S.length)}return m+__(a,v)}]},!RG||!DG||I_);var LG=Xl,$G=Vl,FG=Eo,NG=FG("match"),zG=function(t){var e;return LG(t)&&((e=t[NG])!==void 0?!!e:$G(t)==="RegExp")},BG=Io,UG=Ei,HG=iM,KG=HM,E_=RegExp.prototype,WG=function(t){var e=t.flags;return e===void 0&&!("flags"in E_)&&!UG(t,"flags")&&HG(E_,t)?BG(KG,t):e},GG=Zl,VG=Io,K0=Lt,k_=Yl,YG=kn,XG=wg,qG=zG,Cc=ld,ZG=T0,QG=WG,JG=YM,eV=Eo,tV=eV("replace"),nV=TypeError,$y=K0("".indexOf);K0("".replace);var T_=K0("".slice),rV=Math.max;GG({target:"String",proto:!0},{replaceAll:function(e,n){var r=k_(this),s,o,i,a,l,c,u,h,f,p,g=0,m="";if(!XG(e)){if(s=qG(e),s&&(o=Cc(k_(QG(e))),!~$y(o,"g")))throw new nV("`.replaceAll` does not allow non-global regexes");if(i=ZG(e,tV),i)return VG(i,e,r,n)}for(a=Cc(r),l=Cc(e),c=YG(n),c||(n=Cc(n)),u=l.length,h=rV(1,u),f=$y(a,l);f!==-1;)p=c?Cc(n(l,f,a)):JG(l,a,f,[],void 0,n),m+=T_(a,g,f)+p,g=f+u,f=f+h>a.length?-1:$y(a,l,f+h);return g<a.length&&(m+=T_(a,g)),m}});var sV=ad;sV("String","replaceAll");function XM(t){return t&&typeof t=="object"&&"parents"in t}function qM(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 mp(t,e){if(t.children.remove(e)&&t.children.isEmpty&&XM(t))for(let n=0,r=t.parents.length;n<r;n++)mp(t.parents[n],t)}function W0(t,e){if(t.children.add(e)&&XM(t))for(let n=0,r=t.parents.length;n<r;n++)W0(t.parents[n],t)}function ZM(t,e){return t===e||Object.is(t,e)||!!(t&&e&&typeof t.equals=="function"&&t.equals(e))}function ki(t,e){const n=Symbol.for(`com.tldraw.state/${t}`),r=globalThis;return r[n]??(r[n]=e()),r[n]}const fo=ki("empty_array",()=>Object.freeze([])),M_=8;class yp{constructor(){I(this,"arraySize",0);I(this,"array",Array(M_));I(this,"set",null)}get isEmpty(){if(this.array)return this.arraySize===0;if(this.set)return this.set.size===0;throw new Error("no set or array")}add(e){if(this.array)return this.array.indexOf(e)!==-1?!1:this.arraySize<M_?(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 QM{constructor(e){I(this,"index",0);I(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,n,r){if(r!==void 0){if(r===ur){this.clear();return}this.buffer[this.index]=[e,n,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(e){const{index:n,capacity:r,buffer:s}=this;for(let o=0;o<r;o++){const i=(n-1+r-o)%r,a=s[i];if(!a)return ur;const[l,c]=a;if(o===0&&e>=c)return[];if(l<=e&&e<c){const u=o+1,h=new Array(u);for(let f=0;f<u;f++)h[f]=s[(i+f)%r][2];return h}}return ur}}class oV{constructor(e,n){I(this,"offset",0);I(this,"maybeRemoved");this.below=e,this.child=n}}const ot=ki("capture",()=>({stack:null}));function ih(t){const e=ot.stack;ot.stack=null;try{return t()}finally{ot.stack=e}}function JM(t){ot.stack=new oV(ot.stack,t),t.parentSet.clear()}function eA(){const t=ot.stack;if(ot.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)||mp(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)||mp(n,t.child)}}function Sp(t){if(ot.stack){if(ot.stack.child.parentSet.has(t))return;if(ot.stack.child.parentSet.add(t),ot.stack.child.isActivelyListening&&W0(t,ot.stack.child),ot.stack.offset<ot.stack.child.parents.length){const n=ot.stack.child.parents[ot.stack.offset];n!==t&&(ot.stack.maybeRemoved?ot.stack.maybeRemoved.push(n):ot.stack.maybeRemoved=[n])}ot.stack.child.parents[ot.stack.offset]=t,ot.stack.child.parentEpochs[ot.stack.offset]=t.lastChangedEpoch,ot.stack.offset++}}const ei=-1;class iV{constructor(e,n,r){I(this,"_isActivelyListening",!1);I(this,"lastTraversedEpoch",ei);I(this,"lastReactedEpoch",ei);I(this,"_scheduleCount",0);I(this,"parentSet",new yp);I(this,"parentEpochs",[]);I(this,"parents",[]);I(this,"_scheduleEffect");I(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=e,this.runEffect=n,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==$n()){if(this.parents.length&&!qM(this)){this.lastReactedEpoch=$n();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let e=0,n=this.parents.length;e<n;e++)W0(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,n=this.parents.length;e<n;e++)mp(this.parents[e],this)}execute(){try{JM(this);const e=$n(),n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,n}finally{eA()}}}const Ql=ki("EffectScheduler",()=>iV);function As(t,e,n){const r=new Ql(t,e,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function aV(t,e,n){const r=new Ql(t,e,n);return{scheduler:r,start:s=>{const o=(s==null?void 0:s.force)??!1;r.attach(),o?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}class lV{constructor(e){I(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(Re.globalIsReacting)for(const e of this.initialAtomValues.keys())nA(e);else this.isRoot?tA(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=ki("transactions",()=>({globalEpoch:ei+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:ei+1}));function cV(){return Re.reactionEpoch}function $n(){return Re.globalEpoch}function uV(){return Re.globalIsReacting}function G0(t,e){e.lastTraversedEpoch!==Re.globalEpoch&&(e.lastTraversedEpoch=Re.globalEpoch,e instanceof Ql?t.add(e):e.children.visit(n=>G0(t,n)))}function tA(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 o of t)o.children.visit(i=>G0(r,i));for(const o of r)o.maybeScheduleEffect();let s=0;for(;(n=Re.cleanupReactors)!=null&&n.size;){if(s++>1e3)throw new Error("Reaction update depth limit exceeded");const o=Re.cleanupReactors;Re.cleanupReactors=null;for(const i of o)i.maybeScheduleEffect()}}finally{Re.cleanupReactors=null,Re.globalIsReacting=!1,Re.currentTransaction=e}}function dV(t,e){Re.currentTransaction?Re.currentTransaction.initialAtomValues.has(t)||Re.currentTransaction.initialAtomValues.set(t,e):Re.globalIsReacting?nA(t):tA([t])}function nA(t){const e=Re.cleanupReactors??(Re.cleanupReactors=new Set);t.children.visit(n=>G0(e,n))}function hV(){Re.globalEpoch++}function fV(t){const e=new lV(Re.currentTransaction);Re.currentTransaction=e;try{let n,r=!1;try{n=t(()=>r=!0)}catch(s){throw e.abort(),s}return r?e.abort():e.commit(),n}finally{Re.currentTransaction=Re.currentTransaction.parent}}function js(t){return Re.currentTransaction?t():fV(t)}class pV{constructor(e,n,r){I(this,"isEqual");I(this,"computeDiff");I(this,"lastChangedEpoch",$n());I(this,"children",new yp);I(this,"historyBuffer");this.name=e,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new QM(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return Sp(this),this.current}set(e,n){var s,o;if(((s=this.isEqual)==null?void 0:s.call(this,this.current,e))??ZM(this.current,e))return this.current;hV(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,$n(),n??((o=this.computeDiff)==null?void 0:o.call(this,this.current,e,this.lastChangedEpoch,$n()))??ur),this.lastChangedEpoch=$n();const r=this.current;return this.current=e,dV(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var n;return Sp(this),e>=this.lastChangedEpoch?fo:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const gV=ki("Atom",()=>pV);function It(t,e,n){return new gV(t,e,n)}let A_=!1;function mV(){A_||(A_=!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 Hc=Symbol.for("com.tldraw.state/UNINITIALIZED");function Qi(t){return t===Hc}const ux=ki("WithDiff",()=>class{constructor(e,n){this.value=e,this.diff=n}});function Kc(t,e){return new ux(t,e)}class yV{constructor(e,n,r){I(this,"lastChangedEpoch",ei);I(this,"lastTraversedEpoch",ei);I(this,"lastCheckedEpoch",ei);I(this,"parentSet",new yp);I(this,"parents",[]);I(this,"parentEpochs",[]);I(this,"children",new yp);I(this,"historyBuffer");I(this,"state",Hc);I(this,"error",null);I(this,"computeDiff");I(this,"isEqual");this.name=e,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new QM(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??ZM}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var s;const n=this.lastChangedEpoch===ei,r=$n();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&uV()&&this.lastTraversedEpoch<cV()||!qM(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{JM(this);const o=this.derive(this.state,this.lastCheckedEpoch),i=o instanceof ux?o.value:o,a=this.state===Hc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=o instanceof ux?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,$n(),l??((s=this.computeDiff)==null?void 0:s.call(this,this.state,i,this.lastCheckedEpoch,$n()))??ur)}this.lastChangedEpoch=$n(),this.state=i}return this.error=null,this.lastCheckedEpoch=$n(),this.state}catch(o){if(this.state!==Hc&&(this.state=Hc,this.lastChangedEpoch=$n()),this.lastCheckedEpoch=$n(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!e)throw o;return this.state}finally{eA()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Sp(this)}}getDiffSince(e){var n;return this.__unsafe__getWithoutCapture(!0),Sp(this),e>=this.lastChangedEpoch?fo:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const Ig=ki("Computed",()=>yV);function SV(t={},e,n,r){const s=r.value,o=Symbol.for("__@tldraw/state__computed__"+n);return r.value=function(){let i=this[o];return i||(i=new Ig(n,s.bind(this),t),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[rA]=!0,r}function vV(t={},e,n,r){const s=r.get,o=Symbol.for("__@tldraw/state__computed__"+n);return r.get=function(){let i=this[o];return i||(i=new Ig(n,s.bind(this),t),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function xV(t,e,n){Le(n.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(n.name)),s=function(){let o=this[r];return o||(o=new Ig(String(n.name),e.bind(this),t),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()};return s[rA]=!0,s}function j_(t={},e){if(e.length===2){const[n,r]=e;return xV(t,n,r)}else{const[n,r,s]=e;return s.get?(mV(),vV(t,n,r,s)):SV(t,n,r,s)}}const rA="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const t=arguments[0];return(...e)=>j_(t,e)}else return typeof arguments[0]=="string"?new Ig(arguments[0],arguments[1],arguments[2]):j_(void 0,arguments)}const sA=1,wV=ki("apiVersion",()=>sA);if(wV!==sA)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");_i("@tldraw/state","3.7.2","esm");function Eg(t,e,n=[]){const r=ke.useRef(e);r.current=e;const[s,o,i]=ke.useMemo(()=>{let a=null;const l=h=>(a=h,()=>{a=null}),c=new Ql(`useStateTracking(${t})`,()=>{var h;return(h=r.current)==null?void 0:h.call(r)},{scheduleEffect(){a==null||a()}});return[c,l,()=>c.scheduleCount]},[t,...n]);return ke.useSyncExternalStore(o,i,i),ke.useEffect(()=>(s.attach(),s.maybeScheduleEffect(),()=>{s.detach()}),[s]),s.execute()}const O_={apply(t,e,n){return Eg(t.displayName??t.name??"tracked(???)",()=>t.apply(e,n))}},bV=Symbol.for("react.memo"),PV=Symbol.for("react.forward_ref");function Zt(t){let e=null;const n=t.$$typeof;return n===bV&&(t=t.type,e=t.compare),n===PV?w.memo(w.forwardRef(new Proxy(t.render,O_))):w.memo(new Proxy(t,O_),e)}function V0(t,e,n){return w.useState(()=>{const r=typeof e=="function"?e():e;return It(`useAtom(${t})`,r,n)})[0]}function CV(){const t=arguments[0],e=arguments[1],n=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return w.useMemo(()=>G(`useComputed(${t})`,e,n),r)}function ui(t,e,n=fo){w.useEffect(()=>{const r=new Ql(t,e);return r.attach(),r.execute(),()=>{r.detach()}},n)}function U(){const t=arguments,e=t.length===3?t[2]:[t[0]],n=t.length===3?t[0]:`useValue(${t[0].name})`,r=w.useRef(!0);r.current=!0;const s=w.useMemo(()=>t.length===1?t[0]:G(n,()=>{if(r.current)return t[1]();try{return t[1]()}catch{return{}}}),e);try{const{subscribe:o,getSnapshot:i}=w.useMemo(()=>({subscribe:a=>As(`useValue(${n})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return w.useSyncExternalStore(o,i,i)}finally{r.current=!1}}_i("@tldraw/state-react","3.7.2","esm");const _V=(t,e)=>e.some(n=>t instanceof n);let D_,R_;function IV(){return D_||(D_=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function EV(){return R_||(R_=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const oA=new WeakMap,dx=new WeakMap,iA=new WeakMap,Fy=new WeakMap,Y0=new WeakMap;function kV(t){const e=new Promise((n,r)=>{const s=()=>{t.removeEventListener("success",o),t.removeEventListener("error",i)},o=()=>{n(po(t.result)),s()},i=()=>{r(t.error),s()};t.addEventListener("success",o),t.addEventListener("error",i)});return e.then(n=>{n instanceof IDBCursor&&oA.set(n,t)}).catch(()=>{}),Y0.set(e,t),e}function TV(t){if(dx.has(t))return;const e=new Promise((n,r)=>{const s=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",i),t.removeEventListener("abort",i)},o=()=>{n(),s()},i=()=>{r(t.error||new DOMException("AbortError","AbortError")),s()};t.addEventListener("complete",o),t.addEventListener("error",i),t.addEventListener("abort",i)});dx.set(t,e)}let hx={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return dx.get(t);if(e==="objectStoreNames")return t.objectStoreNames||iA.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return po(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 MV(t){hx=t(hx)}function AV(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...n){const r=t.call(Ny(this),e,...n);return iA.set(r,e.sort?e.sort():[e]),po(r)}:EV().includes(t)?function(...e){return t.apply(Ny(this),e),po(oA.get(this))}:function(...e){return po(t.apply(Ny(this),e))}}function jV(t){return typeof t=="function"?AV(t):(t instanceof IDBTransaction&&TV(t),_V(t,IV())?new Proxy(t,hx):t)}function po(t){if(t instanceof IDBRequest)return kV(t);if(Fy.has(t))return Fy.get(t);const e=jV(t);return e!==t&&(Fy.set(t,e),Y0.set(e,t)),e}const Ny=t=>Y0.get(t);function aA(t,e,{blocked:n,upgrade:r,blocking:s,terminated:o}={}){const i=indexedDB.open(t,e),a=po(i);return r&&i.addEventListener("upgradeneeded",l=>{r(po(i.result),l.oldVersion,l.newVersion,po(i.transaction),l)}),n&&i.addEventListener("blocked",l=>n(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),s&&l.addEventListener("versionchange",c=>s(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function lA(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);return e&&n.addEventListener("blocked",r=>e(r.oldVersion,r)),po(n).then(()=>{})}const OV=["get","getKey","getAll","getAllKeys","count"],DV=["put","add","delete","clear"],zy=new Map;function L_(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(zy.get(e))return zy.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,s=DV.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(s||OV.includes(n)))return;const o=async function(i,...a){const l=this.transaction(i,s?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[n](...a),s&&l.done]))[0]};return zy.set(e,o),o}MV(t=>({...t,get:(e,n,r)=>L_(e,n)||t.get(e,n,r),has:(e,n)=>!!L_(e,n)||t.has(e,n)}));const RV="TLDRAW_DOCUMENT_v2",LV="TLDRAW_ASSET_STORE_v1",cA="TLDRAW_DB_NAME_INDEX_v2",Ce={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function uA(t){const e=RV+t;return FV(e),await aA(e,4,{upgrade(n){n.objectStoreNames.contains(Ce.Records)||n.createObjectStore(Ce.Records),n.objectStoreNames.contains(Ce.Schema)||n.createObjectStore(Ce.Schema),n.objectStoreNames.contains(Ce.SessionState)||n.createObjectStore(Ce.SessionState),n.objectStoreNames.contains(Ce.Assets)||n.createObjectStore(Ce.Assets)}})}async function $V(t){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(f=>f.name):X0(),n=LV+t;if(!e.find(f=>f===n))return;const s=await aA(n,1,{upgrade(f){f.objectStoreNames.contains("assets")||f.createObjectStore("assets")}});if(!s.objectStoreNames.contains("assets"))return;const o=s.transaction(["assets"],"readonly"),i=o.objectStore("assets"),a=await i.getAllKeys(),l=await Promise.all(a.map(async f=>[f,await i.get(f)]));await o.done;const c=await uA(t),u=c.transaction([Ce.Assets],"readwrite"),h=u.objectStore(Ce.Assets);for(const[f,p]of l)h.put(p,f);await u.done,s.close(),c.close(),await lA(n)}const mu=class mu{constructor(e){I(this,"getDbPromise");I(this,"isClosed",!1);I(this,"pendingTransactionSet",new Set);mu.connectedInstances.add(this),this.getDbPromise=(async()=>(await $V(e),await uA(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Ru)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),mu.connectedInstances.delete(this))}tx(e,n,r){const s=(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(s),s.finally(()=>this.pendingTransactionSet.delete(s)),s}async load({sessionId:e}={}){return await this.tx("readonly",[Ce.Records,Ce.Schema,Ce.SessionState],async n=>{var l,c;const r=n.objectStore(Ce.Records),s=n.objectStore(Ce.Schema),o=n.objectStore(Ce.SessionState);let i=e?(l=await o.get(e))==null?void 0:l.snapshot:null;return i||(i=(c=(await o.getAll()).sort((h,f)=>h.updatedAt-f.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await s.get(Ce.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Ce.Records,Ce.Schema,Ce.SessionState],async o=>{const i=o.objectStore(Ce.Records),a=o.objectStore(Ce.Schema),l=o.objectStore(Ce.SessionState);for(const[c,u]of Object.entries(n.added))await i.put(u,c);for(const[c,u]of Object.values(n.updated))await i.put(u,u.id);for(const c of Object.keys(n.removed))await i.delete(c);a.put(e.serialize(),Ce.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:e,snapshot:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Ce.Records,Ce.Schema,Ce.SessionState],async o=>{const i=o.objectStore(Ce.Records),a=o.objectStore(Ce.Schema),l=o.objectStore(Ce.SessionState);await i.clear();for(const[c,u]of Object.entries(n))await i.put(u,c);a.put(e.serialize(),Ce.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[Ce.SessionState],async e=>{const n=e.objectStore(Ce.SessionState),r=(await n.getAll()).sort((o,i)=>o.updatedAt-i.updatedAt);if(r.length<10){await e.done;return}const s=r.slice(0,r.length-10);for(const{id:o}of s)await n.delete(o)})}async getAsset(e){return await this.tx("readonly",[Ce.Assets],async n=>await n.objectStore(Ce.Assets).get(e))}async storeAsset(e,n){await this.tx("readwrite",[Ce.Assets],async r=>{await r.objectStore(Ce.Assets).put(n,e)})}};I(mu,"connectedInstances",new Set);let vp=mu;function X0(){const t=JSON.parse(C0(cA)||"[]")??[];return Array.isArray(t)?t:[]}function FV(t){const e=new Set(X0());e.add(t),_0(cA,JSON.stringify([...e]))}class of{constructor(e){I(this,"nextValue");I(this,"diff");this.previousValue=e}get(){var r,s,o,i;const e=((s=(r=this.diff)==null?void 0:r.removed)==null?void 0:s.size)??0,n=((i=(o=this.diff)==null?void 0:o.added)==null?void 0:i.size)??0;if(!(e===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(e,n){var r,s;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):((s=this.diff).added??(s.added=new Set),this.diff.added.add(e))}add(e){var s,o,i;const n=this.previousValue.has(e);if(n)return((o=(s=this.diff)==null?void 0:s.removed)==null?void 0:o.has(e))?this._add(e,n):void 0;(i=this.nextValue)!=null&&i.has(e)||this._add(e,n)}_remove(e,n){var r,s;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)):(s=this.diff.added)==null||s.delete(e)}remove(e){var s,o,i,a;const n=this.previousValue.has(e);if(!n)return((o=(s=this.diff)==null?void 0:s.added)==null?void 0:o.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 kg{constructor(e,n){I(this,"createDefaultProperties");I(this,"validator");I(this,"ephemeralKeys");I(this,"ephemeralKeySet");I(this,"scope");this.typeName=e,this.createDefaultProperties=n.createDefaultProperties,this.validator=n.validator??{validate:s=>s},this.scope=n.scope??"document",this.ephemeralKeys=n.ephemeralKeys;const r=new Set;if(n.ephemeralKeys)for(const[s,o]of Xn(n.ephemeralKeys))o&&r.add(s);this.ephemeralKeySet=r}create(e){const n={...this.createDefaultProperties(),id:this.createId()};for(const[r,s]of Object.entries(e))s!==void 0&&(n[r]=s);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 kg(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 Hs(t,e){return new kg(t,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function xp(){return{added:{},updated:{},removed:{}}}function fx(t){const e={added:t.removed,removed:t.added,updated:{}};for(const[n,r]of Object.values(t.updated))e.updated[n.id]=[r,n];return e}function dA(t){return Object.keys(t.added).length===0&&Object.keys(t.updated).length===0&&Object.keys(t.removed).length===0}function q0(t){const e={added:{},removed:{},updated:{}};return lu(e,t),e}function lu(t,e){for(const n of e){for(const[r,s]of Xn(n.added))if(t.removed[r]){const o=t.removed[r];delete t.removed[r],o!==s&&(t.updated[r]=[o,s])}else t.added[r]=s;for(const[r,[s,o]]of Xn(n.updated)){if(t.added[r]){t.added[r]=o,delete t.updated[r],delete t.removed[r];continue}if(t.updated[r]){t.updated[r]=[t.updated[r][0],o],delete t.removed[r];continue}t.updated[r]=n.updated[r],delete t.removed[r]}for(const[r,s]of Xn(n.removed))t.added[r]?delete t.added[r]:t.updated[r]?(t.removed[r]=t.updated[r][0],delete t.updated[r]):t.removed[r]=s}}var wp={exports:{}};wp.exports;(function(t,e){var n=200,r="__lodash_hash_undefined__",s=1,o=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",f="[object Error]",p="[object Function]",g="[object GeneratorFunction]",m="[object Map]",v="[object Number]",y="[object Null]",S="[object Object]",b="[object Promise]",P="[object Proxy]",C="[object RegExp]",_="[object Set]",E="[object String]",k="[object Symbol]",D="[object Undefined]",T="[object WeakMap]",j="[object ArrayBuffer]",L="[object DataView]",M="[object Float32Array]",O="[object Float64Array]",F="[object Int8Array]",B="[object Int16Array]",K="[object Int32Array]",R="[object Uint8Array]",H="[object Uint8ClampedArray]",X="[object Uint16Array]",te="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,de=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,oe={};oe[M]=oe[O]=oe[F]=oe[B]=oe[K]=oe[R]=oe[H]=oe[X]=oe[te]=!0,oe[a]=oe[l]=oe[j]=oe[u]=oe[L]=oe[h]=oe[f]=oe[p]=oe[m]=oe[v]=oe[S]=oe[C]=oe[_]=oe[E]=oe[T]=!1;var Ue=typeof dn=="object"&&dn&&dn.Object===Object&&dn,Ne=typeof self=="object"&&self&&self.Object===Object&&self,lt=Ue||Ne||Function("return this")(),$e=e&&!e.nodeType&&e,Ye=$e&&!0&&t&&!t.nodeType&&t,We=Ye&&Ye.exports===$e,er=We&&Ue.process,$t=function(){try{return er&&er.binding&&er.binding("util")}catch{}}(),On=$t&&$t.isTypedArray;function Mt(A,$){for(var V=-1,ne=A==null?0:A.length,Je=0,Se=[];++V<ne;){var mt=A[V];$(mt,V,A)&&(Se[Je++]=mt)}return Se}function Ft(A,$){for(var V=-1,ne=$.length,Je=A.length;++V<ne;)A[Je+V]=$[V];return A}function jo(A,$){for(var V=-1,ne=A==null?0:A.length;++V<ne;)if($(A[V],V,A))return!0;return!1}function Ys(A,$){for(var V=-1,ne=Array(A);++V<A;)ne[V]=$(V);return ne}function Oo(A){return function($){return A($)}}function km(A,$){return A.has($)}function MN(A,$){return A==null?void 0:A[$]}function AN(A){var $=-1,V=Array(A.size);return A.forEach(function(ne,Je){V[++$]=[Je,ne]}),V}function jN(A,$){return function(V){return A($(V))}}function ON(A){var $=-1,V=Array(A.size);return A.forEach(function(ne){V[++$]=ne}),V}var DN=Array.prototype,RN=Function.prototype,Md=Object.prototype,Tm=lt["__core-js_shared__"],q1=RN.toString,ps=Md.hasOwnProperty,Z1=function(){var A=/[^.]+$/.exec(Tm&&Tm.keys&&Tm.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),Q1=Md.toString,LN=RegExp("^"+q1.call(ps).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),J1=We?lt.Buffer:void 0,Ad=lt.Symbol,eP=lt.Uint8Array,tP=Md.propertyIsEnumerable,$N=DN.splice,Li=Ad?Ad.toStringTag:void 0,nP=Object.getOwnPropertySymbols,FN=J1?J1.isBuffer:void 0,NN=jN(Object.keys,Object),Mm=ka(lt,"DataView"),cc=ka(lt,"Map"),Am=ka(lt,"Promise"),jm=ka(lt,"Set"),Om=ka(lt,"WeakMap"),uc=ka(Object,"create"),zN=Ni(Mm),BN=Ni(cc),UN=Ni(Am),HN=Ni(jm),KN=Ni(Om),rP=Ad?Ad.prototype:void 0,Dm=rP?rP.valueOf:void 0;function $i(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function WN(){this.__data__=uc?uc(null):{},this.size=0}function GN(A){var $=this.has(A)&&delete this.__data__[A];return this.size-=$?1:0,$}function VN(A){var $=this.__data__;if(uc){var V=$[A];return V===r?void 0:V}return ps.call($,A)?$[A]:void 0}function YN(A){var $=this.__data__;return uc?$[A]!==void 0:ps.call($,A)}function XN(A,$){var V=this.__data__;return this.size+=this.has(A)?0:1,V[A]=uc&&$===void 0?r:$,this}$i.prototype.clear=WN,$i.prototype.delete=GN,$i.prototype.get=VN,$i.prototype.has=YN,$i.prototype.set=XN;function Xs(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function qN(){this.__data__=[],this.size=0}function ZN(A){var $=this.__data__,V=Od($,A);if(V<0)return!1;var ne=$.length-1;return V==ne?$.pop():$N.call($,V,1),--this.size,!0}function QN(A){var $=this.__data__,V=Od($,A);return V<0?void 0:$[V][1]}function JN(A){return Od(this.__data__,A)>-1}function e4(A,$){var V=this.__data__,ne=Od(V,A);return ne<0?(++this.size,V.push([A,$])):V[ne][1]=$,this}Xs.prototype.clear=qN,Xs.prototype.delete=ZN,Xs.prototype.get=QN,Xs.prototype.has=JN,Xs.prototype.set=e4;function Fi(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function t4(){this.size=0,this.__data__={hash:new $i,map:new(cc||Xs),string:new $i}}function n4(A){var $=Dd(this,A).delete(A);return this.size-=$?1:0,$}function r4(A){return Dd(this,A).get(A)}function s4(A){return Dd(this,A).has(A)}function o4(A,$){var V=Dd(this,A),ne=V.size;return V.set(A,$),this.size+=V.size==ne?0:1,this}Fi.prototype.clear=t4,Fi.prototype.delete=n4,Fi.prototype.get=r4,Fi.prototype.has=s4,Fi.prototype.set=o4;function jd(A){var $=-1,V=A==null?0:A.length;for(this.__data__=new Fi;++$<V;)this.add(A[$])}function i4(A){return this.__data__.set(A,r),this}function a4(A){return this.__data__.has(A)}jd.prototype.add=jd.prototype.push=i4,jd.prototype.has=a4;function Do(A){var $=this.__data__=new Xs(A);this.size=$.size}function l4(){this.__data__=new Xs,this.size=0}function c4(A){var $=this.__data__,V=$.delete(A);return this.size=$.size,V}function u4(A){return this.__data__.get(A)}function d4(A){return this.__data__.has(A)}function h4(A,$){var V=this.__data__;if(V instanceof Xs){var ne=V.__data__;if(!cc||ne.length<n-1)return ne.push([A,$]),this.size=++V.size,this;V=this.__data__=new Fi(ne)}return V.set(A,$),this.size=V.size,this}Do.prototype.clear=l4,Do.prototype.delete=c4,Do.prototype.get=u4,Do.prototype.has=d4,Do.prototype.set=h4;function f4(A,$){var V=Rd(A),ne=!V&&k4(A),Je=!V&&!ne&&Rm(A),Se=!V&&!ne&&!Je&&hP(A),mt=V||ne||Je||Se,At=mt?Ys(A.length,String):[],Nt=At.length;for(var ct in A)ps.call(A,ct)&&!(mt&&(ct=="length"||Je&&(ct=="offset"||ct=="parent")||Se&&(ct=="buffer"||ct=="byteLength"||ct=="byteOffset")||P4(ct,Nt)))&&At.push(ct);return At}function Od(A,$){for(var V=A.length;V--;)if(lP(A[V][0],$))return V;return-1}function p4(A,$,V){var ne=$(A);return Rd(A)?ne:Ft(ne,V(A))}function dc(A){return A==null?A===void 0?D:y:Li&&Li in Object(A)?w4(A):E4(A)}function sP(A){return hc(A)&&dc(A)==a}function oP(A,$,V,ne,Je){return A===$?!0:A==null||$==null||!hc(A)&&!hc($)?A!==A&&$!==$:g4(A,$,V,ne,oP,Je)}function g4(A,$,V,ne,Je,Se){var mt=Rd(A),At=Rd($),Nt=mt?l:Ro(A),ct=At?l:Ro($);Nt=Nt==a?S:Nt,ct=ct==a?S:ct;var tr=Nt==S,Ur=ct==S,en=Nt==ct;if(en&&Rm(A)){if(!Rm($))return!1;mt=!0,tr=!1}if(en&&!tr)return Se||(Se=new Do),mt||hP(A)?iP(A,$,V,ne,Je,Se):v4(A,$,Nt,V,ne,Je,Se);if(!(V&s)){var Pr=tr&&ps.call(A,"__wrapped__"),Cr=Ur&&ps.call($,"__wrapped__");if(Pr||Cr){var Lo=Pr?A.value():A,qs=Cr?$.value():$;return Se||(Se=new Do),Je(Lo,qs,V,ne,Se)}}return en?(Se||(Se=new Do),x4(A,$,V,ne,Je,Se)):!1}function m4(A){if(!dP(A)||_4(A))return!1;var $=cP(A)?LN:de;return $.test(Ni(A))}function y4(A){return hc(A)&&uP(A.length)&&!!oe[dc(A)]}function S4(A){if(!I4(A))return NN(A);var $=[];for(var V in Object(A))ps.call(A,V)&&V!="constructor"&&$.push(V);return $}function iP(A,$,V,ne,Je,Se){var mt=V&s,At=A.length,Nt=$.length;if(At!=Nt&&!(mt&&Nt>At))return!1;var ct=Se.get(A);if(ct&&Se.get($))return ct==$;var tr=-1,Ur=!0,en=V&o?new jd:void 0;for(Se.set(A,$),Se.set($,A);++tr<At;){var Pr=A[tr],Cr=$[tr];if(ne)var Lo=mt?ne(Cr,Pr,tr,$,A,Se):ne(Pr,Cr,tr,A,$,Se);if(Lo!==void 0){if(Lo)continue;Ur=!1;break}if(en){if(!jo($,function(qs,zi){if(!km(en,zi)&&(Pr===qs||Je(Pr,qs,V,ne,Se)))return en.push(zi)})){Ur=!1;break}}else if(!(Pr===Cr||Je(Pr,Cr,V,ne,Se))){Ur=!1;break}}return Se.delete(A),Se.delete($),Ur}function v4(A,$,V,ne,Je,Se,mt){switch(V){case L:if(A.byteLength!=$.byteLength||A.byteOffset!=$.byteOffset)return!1;A=A.buffer,$=$.buffer;case j:return!(A.byteLength!=$.byteLength||!Se(new eP(A),new eP($)));case u:case h:case v:return lP(+A,+$);case f:return A.name==$.name&&A.message==$.message;case C:case E:return A==$+"";case m:var At=AN;case _:var Nt=ne&s;if(At||(At=ON),A.size!=$.size&&!Nt)return!1;var ct=mt.get(A);if(ct)return ct==$;ne|=o,mt.set(A,$);var tr=iP(At(A),At($),ne,Je,Se,mt);return mt.delete(A),tr;case k:if(Dm)return Dm.call(A)==Dm.call($)}return!1}function x4(A,$,V,ne,Je,Se){var mt=V&s,At=aP(A),Nt=At.length,ct=aP($),tr=ct.length;if(Nt!=tr&&!mt)return!1;for(var Ur=Nt;Ur--;){var en=At[Ur];if(!(mt?en in $:ps.call($,en)))return!1}var Pr=Se.get(A);if(Pr&&Se.get($))return Pr==$;var Cr=!0;Se.set(A,$),Se.set($,A);for(var Lo=mt;++Ur<Nt;){en=At[Ur];var qs=A[en],zi=$[en];if(ne)var fP=mt?ne(zi,qs,en,$,A,Se):ne(qs,zi,en,A,$,Se);if(!(fP===void 0?qs===zi||Je(qs,zi,V,ne,Se):fP)){Cr=!1;break}Lo||(Lo=en=="constructor")}if(Cr&&!Lo){var Ld=A.constructor,$d=$.constructor;Ld!=$d&&"constructor"in A&&"constructor"in $&&!(typeof Ld=="function"&&Ld instanceof Ld&&typeof $d=="function"&&$d instanceof $d)&&(Cr=!1)}return Se.delete(A),Se.delete($),Cr}function aP(A){return p4(A,A4,b4)}function Dd(A,$){var V=A.__data__;return C4($)?V[typeof $=="string"?"string":"hash"]:V.map}function ka(A,$){var V=MN(A,$);return m4(V)?V:void 0}function w4(A){var $=ps.call(A,Li),V=A[Li];try{A[Li]=void 0;var ne=!0}catch{}var Je=Q1.call(A);return ne&&($?A[Li]=V:delete A[Li]),Je}var b4=nP?function(A){return A==null?[]:(A=Object(A),Mt(nP(A),function($){return tP.call(A,$)}))}:j4,Ro=dc;(Mm&&Ro(new Mm(new ArrayBuffer(1)))!=L||cc&&Ro(new cc)!=m||Am&&Ro(Am.resolve())!=b||jm&&Ro(new jm)!=_||Om&&Ro(new Om)!=T)&&(Ro=function(A){var $=dc(A),V=$==S?A.constructor:void 0,ne=V?Ni(V):"";if(ne)switch(ne){case zN:return L;case BN:return m;case UN:return b;case HN:return _;case KN:return T}return $});function P4(A,$){return $=$??i,!!$&&(typeof A=="number"||Me.test(A))&&A>-1&&A%1==0&&A<$}function C4(A){var $=typeof A;return $=="string"||$=="number"||$=="symbol"||$=="boolean"?A!=="__proto__":A===null}function _4(A){return!!Z1&&Z1 in A}function I4(A){var $=A&&A.constructor,V=typeof $=="function"&&$.prototype||Md;return A===V}function E4(A){return Q1.call(A)}function Ni(A){if(A!=null){try{return q1.call(A)}catch{}try{return A+""}catch{}}return""}function lP(A,$){return A===$||A!==A&&$!==$}var k4=sP(function(){return arguments}())?sP:function(A){return hc(A)&&ps.call(A,"callee")&&!tP.call(A,"callee")},Rd=Array.isArray;function T4(A){return A!=null&&uP(A.length)&&!cP(A)}var Rm=FN||O4;function M4(A,$){return oP(A,$)}function cP(A){if(!dP(A))return!1;var $=dc(A);return $==p||$==g||$==c||$==P}function uP(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function dP(A){var $=typeof A;return A!=null&&($=="object"||$=="function")}function hc(A){return A!=null&&typeof A=="object"}var hP=On?Oo(On):y4;function A4(A){return T4(A)?f4(A):S4(A)}function j4(){return[]}function O4(){return!1}t.exports=M4})(wp,wp.exports);var NV=wp.exports;const hA=wi(NV);function zV(t){if(t.length===0)return new Set;const e=t[0],n=t.slice(1),r=new Set;for(const s of e)n.every(o=>o.has(s))&&r.add(s);return r}function BV(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 $_(t,e){for(const[n,r]of Object.entries(t)){const s=r,o=e[n];if("eq"in s&&o!==s.eq||"neq"in s&&o===s.neq||"gt"in s&&(typeof o!="number"||o<=s.gt))return!1}return!0}function F_(t,e,n){const r=Object.fromEntries(Object.keys(n).map(s=>[s,new Set]));for(const[s,o]of Object.entries(n))if("eq"in o){const a=t.index(e,s).get().get(o.eq);if(a)for(const l of a)r[s].add(l)}else if("neq"in o){const i=t.index(e,s);for(const[a,l]of i.get())if(a!==o.neq)for(const c of l)r[s].add(c)}else if("gt"in o){const i=t.index(e,s);for(const[a,l]of i.get())if(a>o.gt)for(const c of l)r[s].add(c)}return zV(Object.values(r))}class UV{constructor(e,n){I(this,"indexCache",new Map);I(this,"historyCache",new Map);this.atoms=e,this.history=n}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const n=G("filterHistory:"+e,(r,s)=>{if(Qi(r))return this.history.get();const o=this.history.getDiffSince(s);if(o===ur)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of o){for(const h of ut(u.added))if(h.typeName===e)if(i.removed[h.id]){const f=i.removed[h.id];delete i.removed[h.id],l--,f!==h&&(i.updated[h.id]=[f,h],c++)}else i.added[h.id]=h,a++;for(const[h,f]of ut(u.updated))f.typeName===e&&(i.added[f.id]?i.added[f.id]=f:i.updated[f.id]?i.updated[f.id]=[i.updated[f.id][0],f]:(i.updated[f.id]=[h,f],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?Kc(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 s=this.__uncached_createIndex(e,n);return this.indexCache.set(r,s),s}__uncached_createIndex(e,n){const r=this.filterHistory(e),s=()=>{r.get();const o=new Map;for(const i of ut(this.atoms.get())){const a=i.get();if(a.typeName===e){const l=a[n];o.has(l)||o.set(l,new Set),o.get(l).add(a.id)}}return o};return G("index:"+e+":"+n,(o,i)=>{if(Qi(o))return s();const a=r.getDiffSince(i);if(a===ur)return s();const l=new Map,c=(p,g)=>{let m=l.get(p);m||(m=new of(o.get(p)??new Set)),m.add(g),l.set(p,m)},u=(p,g)=>{let m=l.get(p);m||(m=new of(o.get(p)??new Set)),m.remove(g),l.set(p,m)};for(const p of a){for(const g of ut(p.added))if(g.typeName===e){const m=g[n];c(m,g.id)}for(const[g,m]of ut(p.updated))if(m.typeName===e){const v=g[n],y=m[n];v!==y&&(u(v,m.id),c(y,m.id))}for(const g of ut(p.removed))if(g.typeName===e){const m=g[n];u(m,g.id)}}let h,f;for(const[p,g]of l){const m=g.get();m&&(h||(h=new Map(o)),f||(f=new Map),m.value.size===0?h.delete(p):h.set(p,m.value),f.set(p,m.diff))}return h&&f?Kc(h,f):o},{historyLength:100})}record(e,n=()=>({}),r="record:"+e+(n?":"+n.toString():"")){const s=this.ids(e,n,r);return G(r,()=>{var o;for(const i of s.get())return(o=this.atoms.get()[i])==null?void 0:o.get()})}records(e,n=()=>({}),r="records:"+e+(n?":"+n.toString():"")){const s=this.ids(e,n,"ids:"+r);return G(r,()=>{const o=this.atoms.get();return[...s.get()].map(i=>{const a=o[i];if(!a)throw new Error("no atom found for record id: "+i);return a.get()})},{isEqual:AT})}ids(e,n=()=>({}),r="ids:"+e+(n?":"+n.toString():"")){const s=this.filterHistory(e),o=()=>{s.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:[]})):F_(this,e,l)},i=l=>{const c=o(),u=BV(l,c);return u?Kc(c,u):l},a=G("ids_query:"+r,n,{isEqual:hA});return G("query:"+r,(l,c)=>{const u=a.get();if(Qi(l))return o();if(c<a.lastChangedEpoch)return i(l);const h=s.getDiffSince(c);if(h===ur)return i(l);const f=new of(l);for(const g of h){for(const m of ut(g.added))m.typeName===e&&$_(u,m)&&f.add(m.id);for(const[m,v]of ut(g.updated))v.typeName===e&&($_(u,v)?f.add(v.id):f.remove(v.id));for(const m of ut(g.removed))m.typeName===e&&f.remove(m.id)}const p=f.get();return p?Kc(p.value,p.diff):l},{historyLength:50})}exec(e,n){const r=F_(this,e,n);if(r.size===0)return fo;const s=this.atoms.get();return[...r].map(o=>s[o].get())}}class HV{constructor(e){I(this,"_beforeCreateHandlers",{});I(this,"_afterCreateHandlers",{});I(this,"_beforeChangeHandlers",{});I(this,"_afterChangeHandlers",{});I(this,"_beforeDeleteHandlers",{});I(this,"_afterDeleteHandlers",{});I(this,"_operationCompleteHandlers",[]);I(this,"_isEnabled",!0);this.store=e}isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,n){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let s=e;for(const o of r)s=o(s,n);return s}return e}handleAfterCreate(e,n){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const s of r)s(e,n)}handleBeforeChange(e,n,r){if(!this._isEnabled)return n;const s=this._beforeChangeHandlers[n.typeName];if(s){let o=n;for(const i of s)o=i(e,o,r);return o}return n}handleAfterChange(e,n,r){if(!this._isEnabled)return;const s=this._afterChangeHandlers[n.typeName];if(s)for(const o of s)o(e,n,r)}handleBeforeDelete(e,n){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const s of r)if(s(e,n)===!1)return!1}return!0}handleAfterDelete(e,n){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const s of r)s(e,n)}handleOperationComplete(e){if(this._isEnabled)for(const n of this._operationCompleteHandlers)n(e)}register(e){const n=[];for(const[r,s]of Object.entries(e))s!=null&&s.beforeCreate&&n.push(this.registerBeforeCreateHandler(r,s.beforeCreate)),s!=null&&s.afterCreate&&n.push(this.registerAfterCreateHandler(r,s.afterCreate)),s!=null&&s.beforeChange&&n.push(this.registerBeforeChangeHandler(r,s.beforeChange)),s!=null&&s.afterChange&&n.push(this.registerAfterChangeHandler(r,s.afterChange)),s!=null&&s.beforeDelete&&n.push(this.registerBeforeDeleteHandler(r,s.beforeDelete)),s!=null&&s.afterDelete&&n.push(this.registerAfterDeleteHandler(r,s.afterDelete));return()=>{for(const r of n)r()}}registerBeforeCreateHandler(e,n){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(n),()=>Bi(this._beforeCreateHandlers[e],n)}registerAfterCreateHandler(e,n){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(n),()=>Bi(this._afterCreateHandlers[e],n)}registerBeforeChangeHandler(e,n){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(n),()=>Bi(this._beforeChangeHandlers[e],n)}registerAfterChangeHandler(e,n){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(n),()=>Bi(this._afterChangeHandlers[e],n)}registerBeforeDeleteHandler(e,n){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(n),()=>Bi(this._beforeDeleteHandlers[e],n)}registerAfterDeleteHandler(e,n){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(n),()=>Bi(this._afterDeleteHandlers[e],n)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Bi(this._operationCompleteHandlers,e)}}function Bi(t,e){const n=t.indexOf(e);n>=0&&t.splice(n,1)}class Z0{constructor(e){I(this,"id");I(this,"atoms",It("store_atoms",{}));I(this,"history",It("history",0,{historyLength:1e3}));I(this,"query",new UV(this.atoms,this.history));I(this,"listeners",new Set);I(this,"historyAccumulator",new WV);I(this,"historyReactor");I(this,"schema");I(this,"props");I(this,"scopedTypes");I(this,"sideEffects",new HV(this));I(this,"isMergingRemoteChanges",!1);I(this,"_integrityChecker");I(this,"_isPossiblyCorrupted",!1);I(this,"pendingAfterEvents",null);I(this,"_isInAtomicOp",!1);const{initialData:n,schema:r,id:s}=e;this.id=s??ze(),this.schema=r,this.props=e.props,n&&this.atoms.set(x0(Xn(n).map(([o,i])=>[o,It("atom:"+o,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=aV("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>this.cancelHistoryReactor=ZT(o)}),this.scopedTypes={document:new Set(ut(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(ut(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(ut(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}cancelHistoryReactor(){}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:n,source:r}of e){let s=null,o=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(o??(o=this.filterChangesByScope(n,"document")),!o)continue;a({changes:o,source:r})}else if(l.scope==="session"){if(s??(s=this.filterChangesByScope(n,"session")),!s)continue;a({changes:s,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:au(e.added,(s,o)=>this.scopedTypes[n].has(o.typeName)),updated:au(e.updated,(s,o)=>this.scopedTypes[n].has(o[1].typeName)),removed:au(e.removed,(s,o)=>this.scopedTypes[n].has(o.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={},s={},o=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 f=(i??o)[a.id];if(f){const p=f.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(p,a,c),this.schema.validateRecord(this,a,n??"updateRecord",p)===p)continue;f.set(a),l=!0;const m=f.__unsafe__getWithoutCapture();r[a.id]=[p,m],this.addDiffForAfterEvent(p,m)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),s[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...o}),i[a.id]=It("atom:"+a.id,a)}i&&this.atoms.set(i),l&&this.updateHistory({added:s,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const n=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const o of e){const i=this.atoms.__unsafe__getWithoutCapture()[o];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&n.add(o)}let s;this.atoms.update(o=>{let i;for(const a of e){if(n.has(a)||!(a in o))continue;i||(i={...o}),s||(s={}),delete i[a];const l=o[a].get();s[a]=l,this.addDiffForAfterEvent(l,null)}return i??o}),s&&this.updateHistory({added:{},updated:{},removed:s})})}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,s]of Xn(this.atoms.get())){const o=s.get();(e==="all"||this.scopedTypes[e].has(o.typeName))&&(n[r]=o)}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(DC(this.atoms.get()))}update(e,n){const r=this.atoms.get()[e];if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])}has(e){return!!this.atoms.get()[e]}listen(e,n){this._flushHistory();const r={onHistory:e,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.historyReactor.scheduler.isActivelyListening||(this.historyReactor.start(),this.historyReactor.scheduler.execute()),this.listeners.add(r),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,js(e)}finally{this.isMergingRemoteChanges=!1,this.ensureStoreIsUsable()}}extractingChanges(e){const n=[],r=this.historyAccumulator.addInterceptor(s=>n.push(s.changes));try{return js(e),q0(n)}finally{r()}}applyDiff(e,{runCallbacks:n=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=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){s.push(a);continue}let u=null;for(const[h,f]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(f,hn(c,h))||(u||(u={...c}),u[h]=f);u&&s.push(u)}else s.push(a)}const o=DC(e.removed);s.length&&this.put(s),o.length&&this.remove(o)},n)}createComputedCache(e,n,r){const s=new Ds;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=r?G(i.name+":equals",()=>i.get(),{isEqual:r}):i;return G(e+":"+o,()=>n(a.get()))}).get()}}}createSelectedComputedCache(e,n,r){const s=new Ds;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=G(e+":"+o+":selector",()=>n(i.get()));return G(e+":"+o,()=>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,s=this.pendingAfterEvents.get(r);s?s.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:s,after:o}of r.values())s&&o?this.sideEffects.handleAfterChange(s,o,n):s&&!o?this.sideEffects.handleAfterDelete(s,n):!s&&o&&this.sideEffects.handleAfterCreate(o,n);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(n)}}}atomic(e,n=!0){return js(()=>{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 s=e();return this.flushAtomicCallbacks(),s}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 KV(t){if(t.length===0)return[];const e=[];let n=[t[0]],r;for(let s=1,o=t.length;s<o;s++)r=t[s],n[0].source!==r.source&&(e.push(n),n=[]),n.push(r);return e.push(n),e.map(s=>({source:s[0].source,changes:q0(s.map(o=>o.changes))}))}class WV{constructor(){I(this,"_history",[]);I(this,"_interceptors",new Set)}addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const n of this._interceptors)n(e)}flush(){const e=KV(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function GV(t,e,n){const r=new Ds;return{get(s,o){return r.get(s,()=>(s instanceof Z0?s:s.store).createComputedCache(t,l=>e(s,l),n)).get(o)}}}function VV(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 s=r.dependsOn,o=e[0];o&&(e[0]={...o,dependsOn:s.concat(o.dependsOn??[])})}}return e}function Sl({sequence:t,sequenceId:e,retroactive:n=!0}){const r={sequenceId:e,retroactive:n,sequence:VV(t)};return fA(r),r}function Zn(t,e){return Object.fromEntries(Xn(e).map(([n,r])=>[n,`${t}/${r}`]))}function xr(t){const e=t.sequenceId;return Sl({sequenceId:e,retroactive:t.retroactive??!0,sequence:t.sequence.map(n=>"id"in n?{...n,scope:"record",filter:r=>{var s,o;return r.typeName===t.recordType&&(((s=n.filter)==null?void 0:s.call(n,r))??!0)&&(((o=t.filter)==null?void 0:o.call(t,r))??!0)}}:n)})}function YV(t){const e=new Map(t.map(o=>[o.id,o])),n=new Set,r=[];function s(o){Le(!n.has(o.id),`Circular dependency in migrations: ${o.id}`),n.add(o.id);const{version:i,sequenceId:a}=bp(o.id),l=e.get(`${a}/${i-1}`);if(l&&s(l),o.dependsOn)for(const c of o.dependsOn){const u=e.get(c);u&&s(u)}e.delete(o.id),r.push(o)}for(const o of e.values())s(o);return r}function bp(t){const[e,n]=t.split("/");return{sequenceId:e,version:parseInt(n)}}function N_(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 fA(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;N_(t.sequence[0].id,t.sequenceId);let e=bp(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;N_(r,t.sequenceId);const s=bp(r).version;Le(s===e+1,`Migration id numbers must increase in increments of 1, expected ${t.sequenceId}/${e+1} but got '${t.sequence[n].id}'`),e=s}}var Bo=(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))(Bo||{});function XV(t){if(t.schemaVersion>2||t.schemaVersion<1)return wn.err("Bad schema version");if(t.schemaVersion===2)return wn.ok(t);const e={schemaVersion:2,sequences:{"com.tldraw.store":t.storeVersion}};for(const[n,r]of Object.entries(t.recordVersions))if(e.sequences[`com.tldraw.${n}`]=r.version,"subTypeKey"in r)for(const[s,o]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${n}.${s}`]=o;return wn.ok(e)}class Q0{constructor(e,n){I(this,"migrations",{});I(this,"sortedMigrations");var s;this.types=e,this.options=n;for(const o of n.migrations??[])Le(!this.migrations[o.sequenceId],`Duplicate migration sequenceId ${o.sequenceId}`),fA(o),this.migrations[o.sequenceId]=o;const r=Object.values(this.migrations).flatMap(o=>o.sequence);this.sortedMigrations=YV(r);for(const o of this.sortedMigrations)if((s=o.dependsOn)!=null&&s.length)for(const i of o.dependsOn){const a=r.find(l=>l.id===i);Le(a,`Migration '${o.id}' depends on missing migration '${i}'`)}}static create(e,n){return new Q0(e,n??{})}validateRecord(e,n,r,s){try{const o=hn(this.types,n.typeName);if(!o)throw new Error(`Missing definition for record type ${n.typeName}`);return o.validate(n,s??void 0)}catch(o){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:n,phase:r,recordBefore:s,error:o});throw o}}getMigrationsSince(e){const n=XV(e);if(!n.ok)return n;const r=n.value,s=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&&s.add(i);if(s.size===0)return wn.ok([]);const o=new Set;for(const i of s){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)o.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return wn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))o.add(u.id)}return wn.ok(this.sortedMigrations.filter(({id:i})=>o.has(i)))}migratePersistedRecord(e,n,r="up"){const s=this.getMigrationsSince(n);if(!s.ok)return console.error("Error migrating record",s.error),{type:"error",reason:Bo.MigrationError};let o=s.value;if(o.length===0)return{type:"success",value:e};if(o.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?Bo.TargetVersionTooOld:Bo.TargetVersionTooNew};if(r==="down"){if(!o.every(i=>i.down))return{type:"error",reason:Bo.TargetVersionTooOld};o=o.slice().reverse()}e=nt(e);try{for(const i of o){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:Bo.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:Bo.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:n};n=nt(n);try{for(const o of s)if(o.scope==="record")for(const[i,a]of Object.entries(n)){if(!(o.filter?o.filter(a):!0))continue;const c=o.up(a);c&&(n[i]=nt(c))}else if(o.scope==="store"){const i=o.up(n);i&&(n=nt(i))}else Ot(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Bo.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?bp(n.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const n=hn(this.types,e);return Le(n,"record type does not exists"),n}}_i("@tldraw/store","3.7.2","esm");function qV(t){if(!t.length)return null;let e="";for(const n of t)typeof n=="number"?e+=`.${n}`:n.startsWith("(")?e.endsWith(")")?e=`${e.slice(0,-1)}, ${n.slice(1)}`:e+=n:e+=`.${n}`;return e=e.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),e.startsWith(".")?e.slice(1):e}class Te extends Error{constructor(n,r=[]){const s=qV(r),o=n.split(`
|
|
83
|
+
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
84
|
+
`);super(r?`At ${s}: ${o}`:o);I(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function qn(t,e){try{return e()}catch(n){throw n instanceof Te?new Te(n.rawMessage,[t,...n.path]):new Te(n.toString(),[t])}}function gi(t){if(t===null)return"null";if(Array.isArray(t))return"an array";const e=typeof t;switch(e){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${e}`;case"object":return`an ${e}`;case"undefined":return"undefined";default:Ot(e)}}class Tn{constructor(e,n){this.validationFn=e,this.validateUsingKnownGoodVersionFn=n}validate(e){return this.validationFn(e)}validateUsingKnownGoodVersion(e,n){return Object.is(e,n)?e:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(e,n):this.validate(n)}isValid(e){try{return this.validate(e),!0}catch{return!1}}nullable(){return nY(this)}optional(){return gA(this)}refine(e){return new Tn(n=>e(this.validate(n)),(n,r)=>{const s=this.validateUsingKnownGoodVersion(n,r);return Object.is(n,s)?n:e(s)})}check(e,n){return typeof e=="string"?this.refine(r=>(qn(`(check ${e})`,()=>n(r)),r)):this.refine(r=>(e(r),r))}}class ZV extends Tn{constructor(e){super(n=>{const r=z_.validate(n);for(let s=0;s<r.length;s++)qn(s,()=>e.validate(r[s]));return r},(n,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const s=z_.validate(r);let o=n.length!==s.length;for(let i=0;i<s.length;i++){const a=s[i];if(i>=n.length){o=!0,qn(i,()=>e.validate(a));continue}if(Object.is(n[i],a))continue;const l=qn(i,()=>e.validateUsingKnownGoodVersion(n[i],a));Object.is(l,n[i])||(o=!0)}return o?r:n}),this.itemValidator=e}nonEmpty(){return this.check(e=>{if(e.length===0)throw new Te("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new Te("Expected an array with length greater than 1")})}}class Pp extends Tn{constructor(e,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Te(`Expected object, got ${gi(r)}`);for(const[s,o]of Object.entries(e))qn(s,()=>{o.validate(hn(r,s))});if(!n){for(const s of Object.keys(r))if(!ns(e,s))throw new Te("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new Te(`Expected object, got ${gi(s)}`);let o=!1;for(const[i,a]of Object.entries(e)){const l=hn(r,i),c=hn(s,i);if(Object.is(l,c))continue;const u=qn(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(o=!0)}if(!n){for(const i of Object.keys(s))if(!ns(e,i))throw new Te("Unexpected property",[i])}for(const i of Object.keys(r))if(!ns(s,i)){o=!0;break}return o?s:r}),this.config=e,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new Pp(this.config,!0)}extend(e){return new Pp({...this.config,...e})}}class Tg extends Tn{constructor(e,n,r,s){super(o=>{this.expectObject(o);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(o);return i===void 0?this.unknownValueValidation(o,a):qn(`(${e} = ${a})`,()=>i.validate(o))},(o,i)=>{this.expectObject(i),this.expectObject(o);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):hn(o,e)!==hn(i,e)?qn(`(${e} = ${l})`,()=>a.validate(i)):qn(`(${e} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(o,i):a.validate(i))}),this.key=e,this.config=n,this.unknownValueValidation=r,this.useNumberKeys=s}expectObject(e){if(typeof e!="object"||e===null)throw new Te(`Expected an object, got ${gi(e)}`,[])}getMatchingSchemaAndVariant(e){const n=hn(e,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new Te(`Expected a string for key "${this.key}", got ${gi(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Te(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:ns(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(e){return new Tg(this.key,this.config,e,this.useNumberKeys)}}class QV extends Tn{constructor(e,n){super(r=>{if(typeof r!="object"||r===null)throw new Te(`Expected object, got ${gi(r)}`);for(const[s,o]of Object.entries(r))qn(s,()=>{e.validate(s),n.validate(o)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new Te(`Expected object, got ${gi(s)}`);let o=!1;for(const[i,a]of Object.entries(s)){if(!ns(r,i)){o=!0,qn(i,()=>{e.validate(i),n.validate(a)});continue}const l=hn(r,i),c=a;if(Object.is(l,c))continue;const u=qn(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(o=!0)}for(const i of Object.keys(r))if(!ns(s,i)){o=!0;break}return o?s:r}),this.keyValidator=e,this.valueValidator=n}}function J0(t){return new Tn(e=>{if(typeof e!==t)throw new Te(`Expected ${t}, got ${gi(e)}`);return e})}const JV=new Tn(t=>t),ye=J0("string"),pe=J0("number").check(t=>{if(Number.isNaN(t))throw new Te("Expected a number, got NaN");if(!Number.isFinite(t))throw new Te(`Expected a finite number, got ${t}`)}),Cp=pe.check(t=>{if(t<0)throw new Te(`Expected a positive number, got ${t}`)}),Pt=pe.check(t=>{if(t<=0)throw new Te(`Expected a non-zero positive number, got ${t}`)}),pA=pe.check(t=>{if(!Number.isInteger(t))throw new Te(`Expected an integer, got ${t}`)}),af=pA.check(t=>{if(t<0)throw new Te(`Expected a positive integer, got ${t}`)}),eY=pA.check(t=>{if(t<=0)throw new Te(`Expected a non-zero positive integer, got ${t}`)}),we=J0("boolean");function mn(t){return new Tn(e=>{if(e!==t)throw new Te(`Expected ${t}, got ${JSON.stringify(e)}`);return t})}const z_=new Tn(t=>{if(!Array.isArray(t))throw new Te(`Expected an array, got ${gi(t)}`);return t});function Wt(t){return new ZV(t)}function Pe(t){return new Pp(t)}function px(t){return typeof t=="object"&&t!==null&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null||Object.getPrototypeOf(t)===pB)}function gx(t){return t===null||typeof t=="number"||typeof t=="string"||typeof t=="boolean"?!0:Array.isArray(t)?t.every(gx):px(t)?Object.values(t).every(gx):!1}const Gt=new Tn(t=>{if(gx(t))return t;throw new Te(`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 s=t[r],o=e[r];if(Object.is(s,o))continue;const i=Gt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}return n?e:t}else if(px(t)&&px(e)){let n=!1;for(const r of Object.keys(e)){if(!ns(t,r)){n=!0,Gt.validate(e[r]);continue}const s=t[r],o=e[r];if(Object.is(s,o))continue;const i=Gt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}for(const r of Object.keys(t))if(!ns(e,r)){n=!0;break}return n?e:t}else return Gt.validate(e)});function _p(t,e){return new QV(t,e)}function eb(t,e){return new Tg(t,e,(n,r)=>{throw new Te(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!1)}function tY(t,e){return new Tg(t,e,(n,r)=>{throw new Te(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!0)}function Ks(t,e){return new Tn(n=>qn(t,()=>e.validate(n)),(n,r)=>qn(t,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(n,r):e.validate(r)))}function Mg(t){return new Tn(e=>{if(!t.has(e)){const n=Array.from(t,r=>JSON.stringify(r)).join(" or ");throw new Te(`Expected ${n}, got ${e}`)}return e})}function gA(t){return new Tn(e=>{if(e!==void 0)return t.validate(e)},(e,n)=>{if(!(e===void 0&&n===void 0)&&n!==void 0)return t.validateUsingKnownGoodVersion&&e!==void 0?t.validateUsingKnownGoodVersion(e,n):t.validate(n)})}function nY(t){return new Tn(e=>e===null?null:t.validate(e),(e,n)=>n===null?null:t.validateUsingKnownGoodVersion&&e!==null?t.validateUsingKnownGoodVersion(e,n):t.validate(n))}function Ag(...t){return Mg(new Set(t))}function tb(t){try{return new URL(t)}catch{if(t.startsWith("/")||t.startsWith("./"))try{return new URL(t,"http://example.com")}catch{throw new Te(`Expected a valid url, got ${JSON.stringify(t)}`)}throw new Te(`Expected a valid url, got ${JSON.stringify(t)}`)}}const rY=new Set(["http:","https:","mailto:"]),gr=ye.check(t=>{if(t==="")return;const e=tb(t);if(!rY.has(e.protocol.toLowerCase()))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)}),sY=new Set(["http:","https:","data:","asset:"]),la=ye.check(t=>{if(t==="")return;const e=tb(t);if(!sY.has(e.protocol.toLowerCase()))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});ye.check(t=>{if(t==="")return;if(!tb(t).protocol.toLowerCase().match(/^https?:$/))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});const nb=ye.refine(t=>{try{return sB(t),t}catch{throw new Te(`Expected an index key, got ${JSON.stringify(t)}`)}});_i("@tldraw/validate","3.7.2","esm");function dr(t){return ye.refine(e=>{if(!e.startsWith(`${t}:`))throw new Error(`${t} ID must start with "${t}:"`);return e})}const jg=dr("asset");function rb(t,e){return Pe({id:jg,typeName:mn("asset"),type:mn(t),props:e,meta:Gt})}const ca=Pe({x:pe,y:pe,z:pe.optional()}),cu=Pe({x:pe,y:pe,w:pe,h:pe}),mA=pe.check(t=>{if(t<0||t>1)throw new Te("Opacity must be between 0 and 1")}),oY=ye.refine(t=>{if(!t.startsWith("page:")&&!t.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return t}),Ir=dr("shape");function iY(t,e,n){return Pe({id:Ir,typeName:mn("shape"),x:pe,y:pe,rotation:pe,index:nb,parentId:oY,type:mn(t),isLocked:we,opacity:mA,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}const aY=dr("binding");function lY(t,e,n){return Pe({id:aY,typeName:mn("binding"),type:mn(t),fromId:Ir,toId:Ir,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}Zn("com.tldraw.binding",{});xr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Ji(t){return`binding:${ze()}`}function cY(t){return Hs("binding",{scope:"document",validator:Ks("binding",eb("type",rd(t,(e,{props:n,meta:r})=>lY(e,n,r))))}).withDefaultProperties(()=>({meta:{}}))}class Qt{constructor(e,n,r){this.id=e,this.defaultValue=n,this.type=r}static define(e,n){const{defaultValue:r,type:s=JV}=n;return new Qt(e,r,s)}static defineEnum(e,n){const{defaultValue:r,values:s}=n;return new uY(e,r,s)}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 uY extends Qt{constructor(e,n,r){super(e,n,Ag(...r)),this.values=r}}const ah=Zn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),dY=xr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:ah.AddIsLocked,up:t=>{t.isLocked=!1},down:t=>{delete t.isLocked}},{id:ah.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:ah.AddMeta,up:t=>{t.meta={}}},{id:ah.AddWhite,up:t=>{},down:t=>{t.props.color==="white"&&(t.props.color="black")}}]});function al(t){return t?t.typeName==="shape":!1}function Fn(t){return t?t.startsWith("shape:"):!1}function Ke(t){return`shape:${t??ze()}`}function yA(t){const e=new Map;for(const[n,r]of Object.entries(t))if(r instanceof Qt){if(e.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);e.set(r,n)}return e}function us(t,e){return rd(e,(n,r)=>`com.tldraw.shape.${t}/${r}`)}function hY(t){return Hs("shape",{scope:"document",validator:Ks("shape",eb("type",rd(t,(e,{props:n,meta:r})=>iY(e,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function B_(t,e){const n=[];for(const[r,{migrations:s}]of Object.entries(e)){const o=`com.tldraw.${t}.${r}`;s?"sequenceId"in s?(Le(o===s.sequenceId,`sequenceId mismatch for ${r} ${kg} migrations. Expected '${o}', got '${s.sequenceId}'`),n.push(s)):"sequence"in s?n.push(Sl({sequenceId:o,retroactive:!1,sequence:s.sequence.map(i=>"id"in i?SA(t,r,i):i)})):n.push(Sl({sequenceId:o,retroactive:!1,sequence:Object.keys(s.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${o}/${i}`,scope:"record",filter:a=>a.typeName===t&&a.type===r,up:a=>{const l=s.migrators[i].up(a);if(l)return l},down:a=>{const l=s.migrators[i].down(a);if(l)return l}}))})):n.push(Sl({sequenceId:o,retroactive:!1,sequence:[]}))}return n}function SA(t,e,n){return{id:n.id,dependsOn:n.dependsOn,scope:"record",filter:r=>r.typeName===t&&r.type===e,up:r=>{const s=n.up(r.props);s&&(r.props=s)},down:typeof n.down=="function"?r=>{const s=n.down(r.props);s&&(r.props=s)}:void 0}}const vA=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],Ip={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 ko(t){return t.isDarkMode?Ip.darkMode:Ip.lightMode}const mr=Qt.defineEnum("tldraw:color",{defaultValue:"black",values:vA}),sb=Qt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:vA}),ua=Qt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),da=Qt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Ls=Qt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),xA={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},$s=Qt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),wA=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Ep=Qt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:wA}),kp=Qt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:wA}),bA={labelColor:sb,color:mr,fill:da,dash:ua,size:$s,arrowheadStart:Ep,arrowheadEnd:kp,font:Ls,start:ca,end:ca,bend:pe,text:ye,labelPosition:pe,scale:Pt},Ua=us("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function lh(t){return SA("shape","arrow",t)}const PA=Sl({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[lh({id:Ua.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"}),lh({id:Ua.AddIsPrecise,up:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise=!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5)),e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5))},down:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise||(t.normalizedAnchor={x:.5,y:.5}),delete t.isPrecise),e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise)}}),lh({id:Ua.AddLabelPosition,up:t=>{t.labelPosition=.5},down:t=>{delete t.labelPosition}}),{id:Ua.ExtractBindings,scope:"store",up:t=>{const e=Object.values(t).filter(n=>n.typeName==="shape"&&n.type==="arrow");for(const n of e){const{start:r,end:s}=n.props;if(r.type==="binding"){const o=Ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};t[o]=i,n.props.start={x:0,y:0}}else delete n.props.start.type;if(s.type==="binding"){const o=Ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:s.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:s.normalizedAnchor,isExact:s.isExact,isPrecise:s.isPrecise}};t[o]=i,n.props.end={x:0,y:0}}else delete n.props.end.type}}},lh({id:Ua.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}})]}),CA={terminal:Ag("start","end"),normalizedAnchor:ca,isExact:we,isPrecise:we},_A={sequence:[{dependsOn:[Ua.ExtractBindings]}]},fY=Ks("camera",Pe({typeName:mn("camera"),id:dr("camera"),x:pe,y:pe,z:pe,meta:Gt})),pY=Zn("com.tldraw.camera",{AddMeta:1}),gY=xr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:pY.AddMeta,up:t=>{t.meta={}}}]}),Is=Hs("camera",{validator:fY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),mY=new Set(["none","default","pointer","cross","grab","rotate","grabbing","resize-edge","resize-corner","text","move","ew-resize","ns-resize","nesw-resize","nwse-resize","nesw-rotate","nwse-rotate","swne-rotate","senw-rotate","zoom-in","zoom-out"]),IA=Mg(mY),yY=Pe({type:IA,rotation:pe}),SY=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),vY=Mg(SY),xY=new Set(["starting","paused","active","stopping"]),EA=Pe({id:ye,points:Wt(ca),size:Cp,color:vY,opacity:pe,state:Mg(xY),delay:pe,shrink:pe,taper:we}),Nu=dr("page"),wY=Ks("page",Pe({typeName:mn("page"),id:Nu,name:ye,index:nb,meta:Gt})),bY=Zn("com.tldraw.page",{AddMeta:1}),PY=xr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:bY.AddMeta,up:t=>{t.meta={}}}]}),yr=Hs("page",{validator:wY,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Rn(t){return yr.isId(t)}const CY={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 kA(t){return t?au(t,e=>CY[e]):null}dr("instance");function _Y(t){const e={};for(const[r,s]of t)e[r]=gA(s);const n=Ks("instance",Pe({typeName:mn("instance"),id:dr("instance"),currentPageId:Nu,followingUserId:ye.nullable(),brush:cu.nullable(),opacityForNextShape:mA,stylesForNextShape:Pe(e),cursor:yY,scribbles:Wt(EA),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:cu,insets:Wt(we),zoomBrush:cu.nullable(),isPenMode:we,isGridMode:we,chatMessage:ye,isChatting:we,highlightedUserIds:Wt(ye),isFocused:we,devicePixelRatio:pe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:Wt(ye),isChangingStyle:we,isReadonly:we,meta:Gt,duplicateProps:Pe({shapeIds:Wt(dr("shape")),offset:Pe({x:pe,y:pe})}).nullable()}));return Hs("instance",{validator:n,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const et=Zn("com.tldraw.instance",{AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24,RemoveCanMoveCamera:25}),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})}]}),bn="instance:instance",EY=Ks("instance_page_state",Pe({typeName:mn("instance_page_state"),id:dr("instance_page_state"),pageId:Nu,selectedShapeIds:Wt(Ir),hintingShapeIds:Wt(Ir),erasingShapeIds:Wt(Ir),hoveredShapeId:Ir.nullable(),editingShapeId:Ir.nullable(),croppingShapeId:Ir.nullable(),focusedGroupId:Ir.nullable(),meta:Gt})),_c=Zn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),kY=xr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:_c.AddCroppingId,up(t){t.croppingShapeId=null}},{id:_c.RemoveInstanceIdAndCameraId,up(t){delete t.instanceId,delete t.cameraId}},{id:_c.AddMeta,up:t=>{t.meta={}}},{id:_c.RenameProperties,up:t=>{},down:t=>{}},{id:_c.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=Hs("instance_page_state",{validator:EY,scope:"session",ephemeralKeys:{pageId:!1,selectedShapeIds:!1,editingShapeId:!1,croppingShapeId:!1,meta:!1,hintingShapeIds:!0,erasingShapeIds:!0,hoveredShapeId:!0,focusedGroupId:!0}}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),TY=Ks("pointer",Pe({typeName:mn("pointer"),id:dr("pointer"),x:pe,y:pe,lastActivityTimestamp:pe,meta:Gt})),MY=Zn("com.tldraw.pointer",{AddMeta:1}),AY=xr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:MY.AddMeta,up:t=>{t.meta={}}}]}),ob=Hs("pointer",{validator:TY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Tp=ob.createId("pointer"),jY=Ks("instance_presence",Pe({typeName:mn("instance_presence"),id:dr("instance_presence"),userId:ye,userName:ye,lastActivityTimestamp:pe.nullable(),followingUserId:ye.nullable(),cursor:Pe({x:pe,y:pe,type:IA,rotation:pe}).nullable(),color:ye,camera:Pe({x:pe,y:pe,z:pe}).nullable(),screenBounds:cu.nullable(),selectedShapeIds:Wt(dr("shape")),currentPageId:dr("page"),brush:cu.nullable(),scribbles:Wt(EA),chatMessage:ye,meta:Gt})),ja=Zn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),OY=xr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:ja.AddScribbleDelay,up:t=>{t.scribble!==null&&(t.scribble.delay=0)}},{id:ja.RemoveInstanceId,up:t=>{delete t.instanceId}},{id:ja.AddChatMessage,up:t=>{t.chatMessage=""}},{id:ja.AddMeta,up:t=>{t.meta={}}},{id:ja.RenameSelectedShapeIds,up:t=>{}},{id:ja.NullableCameraCursor,up:t=>{},down:t=>{t.camera===null&&(t.camera={x:0,y:0,z:1}),t.lastActivityTimestamp===null&&(t.lastActivityTimestamp=0),t.cursor===null&&(t.cursor={type:"default",x:0,y:0,rotation:0}),t.screenBounds===null&&(t.screenBounds={x:0,y:0,w:1,h:1})}}]}),DY=Hs("instance_presence",{validator:jY,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),RY=Ks("document",Pe({typeName:mn("document"),id:mn("document:document"),gridSize:pe,name:ye,meta:Gt})),U_=Zn("com.tldraw.document",{AddName:1,AddMeta:2}),LY=xr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:U_.AddName,up:t=>{t.name=""},down:t=>{delete t.name}},{id:U_.AddMeta,up:t=>{t.meta={}}}]}),ib=Hs("document",{validator:RY,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),mx=ib.createId("document");function $Y(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function H_(t){t.typeName==="asset"&&("src"in t&&(t.src="<redacted>"),"src"in t.props&&(t.props.src="<redacted>"))}function FY({error:t,phase:e,record:n,recordBefore:r}){throw S0(t,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?H_(nt(r)):void 0,recordAfter:H_(nt(n))}}),t}function NY(){return[yr.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function zY(t){const e=t.query.ids("page"),n=t.query.records("instance_page_state"),r=()=>{if(!t.has(mx))return t.put([ib.create({id:mx,name:t.props.defaultName})]),r();if(!t.has(Tp))return t.put([ob.create({id:Tp})]),r();const s=e.get();if(s.size===0)return t.put(NY()),r();const o=()=>[...s].map(u=>t.get(u)).sort($Y)[0].id,i=t.get(bn);if(i){if(!s.has(i.currentPageId))return t.put([{...i,currentPageId:o()}]),r()}else return t.put([t.schema.types.instance.create({id:bn,currentPageId:o(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const u of s){const h=Qr.createId(u);t.get(h)||a.add(h);const p=Is.createId(u);t.has(p)||l.add(p)}a.size>0&&t.put([...a].map(u=>Qr.create({id:u,pageId:Qr.parseId(u)}))),l.size>0&&t.put([...l].map(u=>Is.create({id:u})));const c=n.get();for(const u of c){if(!s.has(u.pageId)){t.remove([u.id]);continue}if(u.croppingShapeId&&!t.has(u.croppingShapeId))return t.put([{...u,croppingShapeId:null}]),r();if(u.focusedGroupId&&!t.has(u.focusedGroupId))return t.put([{...u,focusedGroupId:null}]),r();if(u.hoveredShapeId&&!t.has(u.hoveredShapeId))return t.put([{...u,hoveredShapeId:null}]),r();const h=u.selectedShapeIds.filter(g=>t.has(g));if(h.length!==u.selectedShapeIds.length)return t.put([{...u,selectedShapeIds:h}]),r();const f=u.hintingShapeIds.filter(g=>t.has(g));if(f.length!==u.hintingShapeIds.length)return t.put([{...u,hintingShapeIds:f}]),r();const p=u.erasingShapeIds.filter(g=>t.has(g));if(p.length!==u.erasingShapeIds.length)return t.put([{...u,erasingShapeIds:p}]),r()}};return r}const BY=rb("bookmark",Pe({title:ye,description:ye,image:ye,favicon:ye,src:la.nullable()})),K_=Zn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),UY=xr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:t=>t.type==="bookmark",sequence:[{id:K_.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:K_.AddFavicon,up:t=>{la.isValid(t.props.favicon)||(t.props.favicon="")},down:t=>{delete t.props.favicon}}]}),HY=rb("image",Pe({w:pe,h:pe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:la.nullable(),fileSize:Pt.optional()})),Ic=Zn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),KY=xr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:t=>t.type==="image",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=>{la.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)}}]}),WY=rb("video",Pe({w:pe,h:pe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:la.nullable(),fileSize:pe.optional()})),Ec=Zn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),GY=xr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:t=>t.type==="video",sequence:[{id:Ec.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Ec.RenameWidthHeight,up:t=>{t.props.w=t.props.width,t.props.h=t.props.height,delete t.props.width,delete t.props.height},down:t=>{t.props.width=t.props.w,t.props.height=t.props.h,delete t.props.w,delete t.props.h}},{id:Ec.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Ec.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Ec.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),VY=Ks("asset",eb("type",{image:HY,video:WY,bookmark:BY})),YY=Zn("com.tldraw.asset",{AddMeta:1}),XY=xr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:YY.AddMeta,up:t=>{t.meta={}}}]}),Yo=Hs("asset",{validator:VY,scope:"document"}).withDefaultProperties(()=>({meta:{}})),TA={w:Pt,h:Pt,assetId:jg.nullable(),url:gr},W_=us("bookmark",{NullAssetId:1,MakeUrlsValid:2}),MA={sequence:[{id:W_.NullAssetId,up:t=>{t.assetId===void 0&&(t.assetId=null)},down:"retired"},{id:W_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},AA=Pe({type:Ag("free","straight"),points:Wt(ca)}),jA={color:mr,fill:da,dash:ua,size:$s,segments:Wt(AA),isComplete:we,isClosed:we,isPen:we,scale:Pt},G_=us("draw",{AddInPen:1,AddScale:2}),OA={sequence:[{id:G_.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:G_.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},qY=/(^\/r\/[^/]+\/?$)/,ZY=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(qY))return t}},{hostnames:["figma.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{hostnames:["google.*"],fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[s,o]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${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,s,o]=n;return`https://codepen.io/${s}/pen/${o}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/${s}`}}},{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 s of r)e.searchParams.delete(s);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","")}}],DA={w:Pt,h:Pt,url:ye},ch=us("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),RA={sequence:[{id:ch.GenOriginalUrlInEmbed,up:t=>{try{const e=t.url,n=new URL(e).host.replace("www.","");let r;for(const s of ZY)if(s.hostnames.includes(n))try{r=s.fromEmbedUrl(e)}catch(o){console.warn(o)}t.tmpOldUrl=t.url,t.url=r??""}catch{t.url="",t.tmpOldUrl=t.url}},down:"retired"},{id:ch.RemoveDoesResize,up:t=>{delete t.doesResize},down:"retired"},{id:ch.RemoveTmpOldUrl,up:t=>{delete t.tmpOldUrl},down:"retired"},{id:ch.RemovePermissionOverrides,up:t=>{delete t.overridePermissions},down:"retired"}]},LA={w:Pt,h:Pt,name:ye},$A={sequence:[]},Mp=Qt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Ap=Qt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Jr=Qt.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),FA={geo:Jr,labelColor:sb,color:mr,fill:da,dash:ua,size:$s,font:Ls,align:Mp,verticalAlign:Ap,url:gr,w:Pt,h:Pt,growY:Cp,text:ye,scale:Pt},Qs=us("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),NA={sequence:[{id:Qs.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Qs.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"},{id:Qs.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Qs.AddCheckBox,up:t=>{},down:"retired"},{id:Qs.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Qs.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:Qs.AddCloud,up:t=>{},down:"retired"},{id:Qs.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Qs.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},zA={},BA={sequence:[]},UA={color:mr,size:$s,segments:Wt(AA),isComplete:we,isPen:we,scale:Pt},QY=us("highlight",{AddScale:1}),HA={sequence:[{id:QY.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},JY=Pe({topLeft:ca,bottomRight:ca}),KA={w:Pt,h:Pt,playing:we,url:gr,assetId:jg.nullable(),crop:JY.nullable(),flipX:we,flipY:we},uh=us("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),WA={sequence:[{id:uh.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:uh.AddCropProp,up:t=>{t.crop=null},down:t=>{delete t.crop}},{id:uh.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:uh.AddFlipProps,up:t=>{t.flipX=!1,t.flipY=!1},down:t=>{delete t.flipX,delete t.flipY}}]},jp=Qt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),eX=Pe({id:ye,index:nb,x:pe,y:pe}),GA={color:mr,dash:ua,size:$s,spline:jp,points:_p(ye,eX),scale:Pt},kc=us("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),VA={sequence:[{id:kc.AddSnapHandles,up:t=>{for(const e of Object.values(t.handles))e.canSnap=!0},down:"retired"},{id:kc.RemoveExtraHandleProps,up:t=>{t.handles=x0(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 s=r===0?"start":r===e.length-1?"end":`handle:${n.index}`;return[s,{id:s,type:"vertex",canBind:!1,canSnap:!0,index:n.index,x:n.x,y:n.y}]}))}},{id:kc.HandlesToPoints,up:t=>{const e=Object.entries(t.handles).map(([n,{x:r,y:s}])=>({x:r,y:s,index:n})).sort(cn);t.points=e.map(({x:n,y:r})=>({x:n,y:r})),delete t.handles},down:t=>{const e=Fu(t.points.length);t.handles=Object.fromEntries(t.points.map((n,r)=>[e[r],{x:n.x,y:n.y}])),delete t.points}},{id:kc.PointIndexIds,up:t=>{const e=Fu(t.points.length);t.points=Object.fromEntries(t.points.map((n,r)=>{const s=e[r];return[s,{id:s,index:s,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:kc.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},YA={color:mr,labelColor:sb,size:$s,font:Ls,fontSizeAdjustment:Cp,align:Mp,verticalAlign:Ap,growY:Cp,url:gr,text:ye,scale:Pt},Fo=us("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8}),XA={sequence:[{id:Fo.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Fo.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Fo.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:Fo.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Fo.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Fo.AddFontSizeAdjustment,up:t=>{t.fontSizeAdjustment=0},down:t=>{delete t.fontSizeAdjustment}},{id:Fo.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}},{id:Fo.AddLabelColor,up:t=>{t.labelColor="black"},down:t=>{delete t.labelColor}}]},yx=Qt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),qA={color:mr,size:$s,font:Ls,textAlign:yx,w:Pt,text:ye,scale:Pt,autoSize:we},V_=us("text",{RemoveJustify:1,AddTextAlign:2}),ZA={sequence:[{id:V_.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:V_.AddTextAlign,up:t=>{t.textAlign=t.align,delete t.align},down:t=>{t.align=t.textAlign,delete t.textAlign}}]},QA={w:Pt,h:Pt,time:pe,playing:we,url:gr,assetId:jg.nullable()},Y_=us("video",{AddUrlProp:1,MakeUrlsValid:2}),JA={sequence:[{id:Y_.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Y_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},dh=Zn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),tX=Sl({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:dh.RemoveCodeAndIconShapeTypes,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete t[e]}},{id:dh.AddInstancePresenceType,scope:"store",up(t){}},{id:dh.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match(/^(user|user_presence)$/)&&delete t[e]}},{id:dh.RemoveUserDocument,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match("user_document")&&delete t[e]}}]}),nX={arrow:{migrations:PA,props:bA},bookmark:{migrations:MA,props:TA},draw:{migrations:OA,props:jA},embed:{migrations:RA,props:DA},frame:{migrations:$A,props:LA},geo:{migrations:NA,props:FA},group:{migrations:BA,props:zA},highlight:{migrations:HA,props:UA},image:{migrations:WA,props:KA},line:{migrations:VA,props:GA},note:{migrations:XA,props:YA},text:{migrations:ZA,props:qA},video:{migrations:JA,props:QA}},rX={arrow:{migrations:_A,props:CA}};function sX({shapes:t=nX,bindings:e=rX,migrations:n}={}){const r=new Map;for(const a of ut(t))for(const l of yA(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 s=hY(t),o=cY(e),i=_Y(r);return Q0.create({asset:Yo,binding:o,camera:Is,document:ib,instance:i,instance_page_state:Qr,page:yr,instance_presence:DY,pointer:ob,shape:s},{migrations:[tX,XY,gY,LY,IY,kY,PY,OY,AY,dY,UY,KY,GY,...B_("shape",t),...B_("binding",e),...n??[]],onValidationFailure:FY,createIntegrityChecker:zY})}const zu=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"so",label:"Somali"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"uk",label:"Ukrainian"},{locale:"he",label:"עברית"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ku",label:"کوردی"},{locale:"ne",label:"नेपाली"},{locale:"hi-in",label:"हिन्दी"},{locale:"te",label:"తెలుగు"},{locale:"th",label:"ภาษาไทย"},{locale:"my",label:"မြန်မာစာ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function oX(){const t=typeof window<"u"?window.navigator.languages??["en"]:["en"];return iX(t)}function iX(t){for(const e of t){const n=aX(e);if(n)return n}return"en"}const X_={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function aX(t){const e=zu.find(s=>s.locale===t.toLowerCase());if(e)return e.locale;const[n,r]=t.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=zu.find(o=>o.locale===n);if(s)return s.locale}return n in X_?X_[n]:null}_i("@tldraw/tlschema","3.7.2","esm");var ej={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 o="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(o=s(o,r(a)))}return o}function r(o){if(typeof o=="string"||typeof o=="number")return o;if(typeof o!="object")return"";if(Array.isArray(o))return n.apply(null,o);if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]"))return o.toString();var i="";for(var a in o)e.call(o,a)&&o[a]&&(i=s(i,a));return i}function s(o,i){return i?o?o+" "+i:o+i:o}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})(ej);var lX=ej.exports;const ce=wi(lX),tj="3.7.2",q_={major:"2024-09-13T14:36:29.063Z",minor:"2025-01-07T15:59:09.453Z"},cX={error:null};class ab extends w.Component{constructor(){super(...arguments);I(this,"state",cX)}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){var r,s;(s=(r=this.props).onError)==null||s.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 Bu({children:t,fallback:e,...n}){return e===null?t:d.jsx(ab,{fallback:e,...n,children:t})}function lb(t,e){return Og(`${t}_${e}`)}function Jl(t){return Og(`${w.useId()}${t??""}`)}function rs(t){const e=zn(w.useContext(nj));return Og(`${e}_${t}`)}function Og(t){return t.replace(/:/g,"_")}const nj=w.createContext(null);function uX({children:t}){const e=Jl();return d.jsx(nj.Provider,{value:e,children:t})}const cb=w.createContext(null);function z(){const t=ke.useContext(cb);if(!t)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return t}function Ti(){return ke.useContext(cb)}function ub({editor:t,children:e}){return d.jsx(cb.Provider,{value:t,children:d.jsx(uX,{children:e})})}function dX(){return d.jsx("div",{className:"tl-background"})}function ec(t,e,n,r,s,o){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})`),s!==void 0&&(a+=` rotate(${s}rad)`),o&&(a+=` translate(${o.x}px, ${o.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,s=Math.sin(e),o=Math.cos(e);return this.x=n*o-r*s,this.y=n*s+r*o,this}rotWith(e,n){if(n===0)return this;const r=this.x-e.x,s=this.y-e.y,o=Math.sin(n),i=Math.cos(n);return this.x=e.x+(r*i-s*o),this.y=e.y+(r*o+s*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),s=Math.cos(n);return new x(e.x*s-e.y*r,e.x*r+e.y*s)}static RotWith(e,n,r){const s=e.x-n.x,o=e.y-n.y,i=Math.sin(r),a=Math.cos(r);return new x(n.x+(s*a-o*i),n.y+(s*i+o*a))}static NearestPointOnLineThroughPoint(e,n,r){return x.Mul(n,x.Sub(r,e).pry(n)).add(e)}static NearestPointOnLineSegment(e,n,r,s=!0){if(x.Equals(e,r)||x.Equals(n,r))return x.From(r);const o=x.Tan(n,e),i=x.Add(e,x.Mul(o,x.Sub(r,e).pry(o)));if(s){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,s=!0){return x.Dist(r,x.NearestPointOnLineSegment(e,n,r,s))}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(io(e.x),io(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:s}=e;return{x:n,y:r,z:s}}static Average(e){const n=e.length,r=new x(0,0);if(n===0)return r;for(let s=0;s<n;s++)r.add(e[s]);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 s=[];for(let o=0;o<r;o++){const i=Dt.easeInQuad(o/(r-1)),a=x.Lrp(e,n,i);a.z=Math.min(1,.5+Math.abs(.5-hX(i))*.65),s.push(a)}return s}static SnapToGrid(e,n=8){return new x(Math.round(e.x/n)*n,Math.round(e.y/n)*n)}}const hX=t=>t<.5?2*t*t:-1+(4-2*t)*t;function je(t){return`${N(t.x)},${N(t.y)} `}function Bn(t,e){return`${N((t.x+e.x)/2)},${N((t.y+e.y)/2)} `}const De=Math.PI,Ze=De/2,Fe=De*2,fX=Math.sin;function Bt(t,e,n){return Math.max(e,typeof n<"u"?Math.min(t,n):t)}function hh(t,e=1e10){return t?Math.round(t*e)/e:0}function di(t,e,n=1e-6){return Math.abs(t-e)<=n}function rj(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 ea(t){return t=t%Fe,t<0?t=t+Fe:t===0&&(t=0),t}function cd(t,e){return t=ea(t),e=ea(e),t>e&&(e+=Fe),e-t}function sj(t,e){return Fe-cd(t,e)}function lf(t,e){const n=(e-t)%Fe;return 2*n%Fe-n}function Sx(t){return(Fe+t)%Fe}function Op(t,e){const n=Fe/e;let r=Math.floor((Sx(t)+n/2)/n)*n%Fe;return r<De&&(r+=Fe),r>De&&(r-=Fe),r}function oj(t,e){return t===e||di(t%(Math.PI/2)-e%(Math.PI/2),0)}function pX(t){return t*De/180}function gX(t){return t*180/De}function ha(t,e,n){return new x(t.x,t.y).add(x.FromAngle(n,e))}function By(t,e,n){const r=t/2,s=e/2,o=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let g=0;g<n;g++){const m=Fe/n,v=-Ze+g*m,y=r+r*Math.cos(v),S=s+s*Math.sin(v);y<i&&(i=y),S<l&&(l=S),y>a&&(a=y),S>c&&(c=S),o.push(new x(y,S))}const u=a-i,h=c-l,f=t-u,p=e-h;if(f!==0||p!==0)for(let g=0;g<o.length;g++){const m=o[g];m.x=(m.x-i)/u*t,m.y=(m.y-l)/h*e}return o}function Tc(t,e,n,r){return t<r&&n<e}function Gr(t,e,n,r){const s=Math.max(t,n),o=Math.min(e,r);return s<=o?[s,o]:null}function Z_(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,s;for(let o=0;o<e.length;o++){if(r=e[o],r.x===t.x&&r.y===t.y||(s=e[(o+1)%e.length],x.Dist(t,r)+x.Dist(t,s)===x.Dist(r,s)))return!0;r.y<=t.y?s.y>t.y&&Z_(r,s,t)>0&&(n+=1):s.y<=t.y&&Z_(r,s,t)<0&&(n-=1)}return n!==0}function N(t){return Math.round(t*1e4)/1e4}function io(t){return Math.round(t*100)/100}const Q_=t=>Math.abs(t)<Number.MAX_SAFE_INTEGER;function Xo(t,e,n){return n<0?cd(t,e):sj(t,e)}function vx(t,e,n,r){let s;if(Math.abs(t)>De){s=lf(e,r);const o=lf(r,n);return Math.abs(s)<Math.abs(o)?s/t:(t-o)/t}else{s=lf(e,r);const o=s/t;return Math.sign(s)!==Math.sign(t)?Math.abs(o)>.5?1:0:o}}function mX(t,e,n,r){const s=2*((e-t)%Fe)%Fe-(e-t)%Fe;return r?(Fe-Math.abs(s))*(n?1:-1):s}function db(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),s=((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,o=((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(s)||!Number.isFinite(o)?null:new x(s,o)}function yX(t,e,n,r,s){if(n===null)return[x.From(t),x.From(e)];const o=[],i=x.Angle(n,t),a=x.Angle(n,e),l=cd(i,a);for(let c=0;c<s;c++){const u=c/(s-1),h=i+l*u,f=ha(n,r,h);o.push(f)}return o}const Uy=({brush:t,color:e,opacity:n,className:r})=>{const s=w.useRef(null);ec(s,t.x,t.y);const o=N(Math.max(1,t.w)),i=N(Math.max(1,t.h));return d.jsx("svg",{className:"tl-overlays__item",ref:s,children:e?d.jsxs("g",{className:"tl-brush",opacity:n,children:[d.jsx("rect",{width:o,height:i,fill:e,opacity:.75}),d.jsx("rect",{width:o,height:i,fill:"none",stroke:e,opacity:.1})]}):d.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:o,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 J_={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Hy={duration:0,easing:Dt.easeInOutCubic},eI={CAMERA_MOVE:-10},SX=["top","right","bottom","left"],tI=0,hb=2,fh=1,nI=5,vX=128;var Ky={};const xX={},ij=Dn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),wt={logPreventDefaults:Dn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Dn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Dn("logElementRemoves",{defaults:{all:!1}}),debugSvg:Dn("debugSvg",{defaults:{all:!1}}),showFps:Dn("showFps",{defaults:{all:!1}}),measurePerformance:Dn("measurePerformance",{defaults:{all:!1}}),throwToBlob:Dn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Dn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Dn("debugCursors",{defaults:{all:!1}}),forceSrgb:Dn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Dn("debugGeometry",{defaults:{all:!1}}),hideShapes:Dn("hideShapes",{defaults:{all:!1}}),editOnType:Dn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const t=Element.prototype.removeChild;As("element removal logging",()=>{wt.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),t.call(this,e)}:Element.prototype.removeChild=t})}function Dn(t,{defaults:e,shouldStoreForSession:n=!0}){return wX({name:t,defaults:e,shouldStoreForSession:n})}function wX(t){const e=PX(t),n=t.shouldStoreForSession?bX(t.name):null,r=It(`debug:${t.name}`,n??e);return typeof window<"u"&&(t.shouldStoreForSession&&As(`debug:${t.name}`,()=>{const s=r.get();s===e?XT(`tldraw_debug:${t.name}`):I0(`tldraw_debug:${t.name}`,JSON.stringify(s))}),Object.defineProperty(window,`tldraw${t.name.replace(/^[a-z]/,s=>s.toUpperCase())}`,{get(){return r.get()},set(s){r.set(s)},configurable:!0})),Object.assign(r,t)}function bX(t){try{return JSON.parse(YT(`tldraw_debug:${t}`)??"null")}catch{return null}}function Wy(t){try{return t()}catch{return null}}function PX(t){switch(Wy(()=>Ky.TLDRAW_ENV)??Wy(()=>Ky.VERCEL_PUBLIC_TLDRAW_ENV)??Wy(()=>Ky.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 Dp(t){if(t instanceof HTMLElement)return t;if(t.parentElement)return Dp(t.parentElement);throw Error("Could not find a parent element of an HTML type!")}function xe(t){t.preventDefault(),wt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",t)}function ud(t,e){if(t.setPointerCapture(e.pointerId),wt.logPointerCaptures.get()){const n=ij.get();n.set(t,(n.get(t)??0)+1),console.warn("setPointerCapture called on element:",t,e)}}function dd(t,e){if(t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),wt.logPointerCaptures.get())){const n=ij.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 Ct=t=>t.stopPropagation(),rn=(t,e,n)=>{t&&t.style.setProperty(e,n)},un=t=>Ge.isDarwin?t.metaKey:t.ctrlKey||t.metaKey;function lr(t){return t.isKilled=!0,{point:{x:t.clientX,y:t.clientY,z:t.pressure},shiftKey:t.shiftKey,altKey:t.altKey,ctrlKey:t.metaKey||t.ctrlKey,metaKey:t.metaKey,accelKey:un(t),pointerId:t.pointerId,button:t.button,isPen:t.pointerType==="pen"}}function fb(){const t=z();return w.useMemo(function(){let r,s;function o(m){if(!m.isKilled){if(m.button===hb){t.dispatch({type:"pointer",target:"canvas",name:"right_click",...lr(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(ud(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...lr(m)}))}}function i(m){m.isKilled||m.clientX===r&&m.clientY===s||(r=m.clientX,s=m.clientY,t.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...lr(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,s=m.clientY,dd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...lr(m)}))}function l(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!0:null})}function c(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!1:null})}function u(m){m.isKilled=!0,xe(m)}function h(m){m.isKilled=!0,m.target instanceof HTMLElement&&m.target.tagName!=="A"&&m.target.tagName!=="TEXTAREA"&&!(t.getEditingShape()&&m.target.className.includes("tl-text-content"))&&xe(m)}function f(m){xe(m)}async function p(m){var y,S;if(xe(m),Ct(m),!((S=(y=m.dataTransfer)==null?void 0:y.files)!=null&&S.length))return;const v=Array.from(m.dataTransfer.files);await t.putExternalContent({type:"files",files:v,point:t.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function g(m){Ct(m)}return{onPointerDown:o,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:f,onDrop:p,onTouchStart:u,onTouchEnd:h,onClick:g}},[t])}function CX(){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)"),s=Ge.isFirefox&&!Ge.isAndroid&&!Ge.isIos,o=()=>{const i=s?!1:r.matches;e===i&&(e=i,t.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",o),o()),()=>{window.removeEventListener("pointerdown",n,{capture:!0}),r&&r.removeEventListener("change",o)}},[t])}const aj=w.createContext(null);function lj({container:t,children:e}){return d.jsx(aj.Provider,{value:t,children:e})}function Tt(){return zn(w.useContext(aj),"useContainer used outside of <Tldraw />")}function _X(){const t=z(),e=Tt(),n=U("isFocused",()=>t.getIsFocused(),[t]);w.useEffect(()=>{if(!e)return;function r(s){if(s.isSpecialRedispatchedEvent)return;xe(s),Ct(s);const o=e.querySelector(".tl-canvas");if(!o)return;const i=new DragEvent(s.type,s);i.isSpecialRedispatchedEvent=!0,o.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 s=()=>{r!=null&&r();const o=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(o),a=l=>{l.type==="change"&&s()};i.addEventListener?i.addEventListener("change",s):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",s):i.removeListener&&i.removeListener(a)},t.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{r==null||r()}},[t]),w.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(t.isIn("zoom")||!t.getPath().endsWith(".idle"))&&!ph(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(ph(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(ph(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)},s=a=>{if(a.isKilled||(a.isKilled=!0,ph(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 o(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",o,{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",s),()=>{e.removeEventListener("touchstart",o),e.removeEventListener("wheel",i),document.removeEventListener("gesturestart",xe),document.removeEventListener("gesturechange",xe),document.removeEventListener("gestureend",xe),e.removeEventListener("keydown",r),e.removeEventListener("keyup",s)}},[t,e,n])}const IX=["input","select","button","textarea"];function ph(t){const{activeElement:e}=document;return t.menus.hasOpenMenus()||e&&(e.getAttribute("contenteditable")||IX.indexOf(e.tagName.toLowerCase())>-1)}const EX=["textarea","input"];function kX(t){const e=z();w.useEffect(()=>{const n=t.current;if(!n)return;const r=s=>{var o;if(s instanceof PointerEvent&&s.pointerType==="pen"){s.isKilled=!0;const{target:i}=s;if(EX.includes((o=i.tagName)==null?void 0:o.toLocaleLowerCase())||e.isIn("select.editing_shape"))return;xe(s)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[e,t])}function TX(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 rI(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function sI(t,e,n,r=.15){return r===0?TX(t,e,n):t<e?-rI(e-t,n-e,r)+e:t>n?+rI(t-n,n-e,r)+n:t}function MX(t,[e,n],[r,s]){const[[o,i],[a,l]]=t;return[sI(e,o,i,r),sI(n,a,l,s)]}function AX(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);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function jX(t){var e=AX(t,"string");return typeof e=="symbol"?e:String(e)}function on(t,e,n){return e=jX(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function oI(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).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?oI(Object(n),!0).forEach(function(r){on(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):oI(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const cj={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 iI(t){return t?t[0].toUpperCase()+t.slice(1):""}const OX=["enter","leave"];function DX(t=!1,e){return t&&!OX.includes(e)}function RX(t,e="",n=!1){const r=cj[t],s=r&&r[e]||e;return"on"+iI(t)+iI(s)+(DX(n,s)?"Capture":"")}const LX=["gotpointercapture","lostpointercapture"];function $X(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=LX.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:n}}function FX(t,e=""){const n=cj[t],r=n&&n[e]||e;return t+r}function uj(t){return"touches"in t}function NX(t){return uj(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function zX(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 xx(t,e){try{const n=e.clientX-t.clientX,r=e.clientY-t.clientY,s=(e.clientX+t.clientX)/2,o=(e.clientY+t.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[s,o]}}catch{}return null}function BX(t){return zX(t).map(e=>e.identifier)}function aI(t,e){const[n,r]=Array.from(t.touches).filter(s=>e.includes(s.identifier));return xx(n,r)}const lI=40,cI=800;function dj(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=lI,n*=lI):r===2&&(e*=cI,n*=cI),[e,n]}function UX(t){const e={};if("buttons"in t&&(e.buttons=t.buttons),"shiftKey"in t){const{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o}=t;Object.assign(e,{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o})}return e}function Rp(t,...e){return typeof t=="function"?t(...e):t}function HX(){}function KX(...t){return t.length===0?HX:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function uI(t,e){return Object.assign({},e,t||{})}const WX=32;class hj{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:s}=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=s,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?Rp(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:s}=this;n.args=this.args;let o=0;if(e&&(n.event=e,r.preventDefault&&e.cancelable&&n.event.preventDefault(),n.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,UX(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-n.timeStamp,n.timeStamp=e.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const _=n._delta.map(Math.abs);Vt.addTo(n._distance,_)}this.axisIntent&&this.axisIntent(e);const[i,a]=n._movement,[l,c]=r.threshold,{_step:u,values:h}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const f=[0,0];if(r.hasCustomTransform){const[_,E]=h;f[0]=u[0]!==!1?_-u[0]:0,f[1]=u[1]!==!1?E-u[1]:0}else f[0]=u[0]!==!1?i-u[0]:0,f[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(f);const p=n.offset,g=n._active&&!n._blocked||n.active;g&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=s[this.ingKey]=n._active,e&&(n.first&&("bounds"in r&&(n._bounds=Rp(r.bounds,n)),this.setup&&this.setup()),n.movement=f,this.computeOffset()));const[m,v]=n.offset,[[y,S],[b,P]]=n._bounds;n.overflow=[m<y?-1:m>S?1:0,v<b?-1:v>P?1:0],n._movementBound[0]=n.overflow[0]?n._movementBound[0]===!1?n._movement[0]:n._movementBound[0]:!1,n._movementBound[1]=n.overflow[1]?n._movementBound[1]===!1?n._movement[1]:n._movementBound[1]:!1;const C=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=MX(n._bounds,n.offset,C),n.delta=Vt.sub(n.offset,p),this.computeMovement(),g&&(!n.last||o>WX)){n.delta=Vt.sub(n.offset,p);const _=n.delta.map(Math.abs);Vt.addTo(n.distance,_),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&o>0&&(n.velocity=[_[0]/o,_[1]/o],n.timeDelta=o)}}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 s=this.handler(ht(ht(ht({},n),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function GX([t,e],n){const r=Math.abs(t),s=Math.abs(e);if(r>s&&r>n)return"x";if(s>r&&s>n)return"y"}class VX extends hj{constructor(...e){super(...e),on(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=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 s=typeof r.axisThreshold=="object"?r.axisThreshold[NX(e)]:r.axisThreshold;n.axis=GX(n._movement,s)}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 YX=t=>t,dI=.15,fj={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[dI,dI];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||YX},threshold(t){return Vt.toVector(t,0)}},XX=0,hd=ht(ht({},fj),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=XX){return t},bounds(t={}){if(typeof t=="function")return o=>hd.bounds(t(o));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:s=1/0}=t;return[[e,n],[r,s]]}}),fd=typeof window<"u"&&window.document&&window.document.createElement;function pj(){return fd&&"ontouchstart"in window}function qX(){return pj()||fd&&window.navigator.maxTouchPoints>1}function ZX(){return fd&&"onpointerdown"in window}function QX(){return fd&&"exitPointerLock"in window.document}function JX(){try{return"constructor"in GestureEvent}catch{return!1}}const Mr={isBrowser:fd,gesture:JX(),touch:pj(),touchscreen:qX(),pointer:ZX(),pointerLock:QX()},eq=250,tq=180,nq=.5,rq=50,sq=250,oq=10,hI={mouse:0,touch:0,pen:8};ht(ht({},hd),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&Mr.pointerLock,Mr.touch&&n?"touch":this.pointerLock?"mouse":Mr.pointer&&!s?"pointer":Mr.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?eq: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:s=!0}={}}){return this.pointerButtons=r,this.keys=s,!this.pointerLock&&this.device==="pointer"&&n},threshold(t,e,{filterTaps:n=!1,tapsThreshold:r=3,axis:s=void 0}){const o=Vt.toVector(t,n?r:s?1:0);return this.filterTaps=n,this.tapsThreshold=r,o},swipe({velocity:t=nq,distance:e=rq,duration:n=sq}={}){return{velocity:this.transform(Vt.toVector(t)),distance:this.transform(Vt.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return tq;case!1:return 0;default:return t}},axisThreshold(t){return t?ht(ht({},hI),t):hI},keyboardDisplacement(t=oq){return t}});function gj(t){const[e,n]=t.overflow,[r,s]=t._delta,[o,i]=t._direction;(e<0&&r>0&&o<0||e>0&&r<0&&o>0)&&(t._movement[0]=t._movementBound[0]),(n<0&&s>0&&i<0||n>0&&s<0&&i>0)&&(t._movement[1]=t._movementBound[1])}const iq=30,aq=100;class lq extends hj{constructor(...e){super(...e),on(this,"ingKey","pinching"),on(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const e=this.state;e._touchIds=[],e.canceled=!1,e.cancel=this.cancel.bind(this),e.turns=0}computeOffset(){const{type:e,movement:n,lastOffset:r}=this.state;e==="wheel"?this.state.offset=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 s=Math.abs(n)*iq-Math.abs(r);s<0?e.axis="angle":s>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(o=>r.has(o))||r.size<2)return;this.start(e),n._touchIds=Array.from(r).slice(0,2);const s=aI(e,n._touchIds);s&&this.pinchStart(e,s)}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,s=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>s.has(i))||(r.size<2&&r.set(e.pointerId,e),n._pointerEvents.size<2))return;this.start(e);const o=xx(...Array.from(r.values()));o&&this.pinchStart(e,o)}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=aI(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=xx(...Array.from(n.values()));r&&this.pinchMove(e,r)}pinchMove(e,n){const r=this.state,s=r._values[1],o=n.angle-s;let i=0;Math.abs(o)>270&&(i+=Math.sign(o)),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=[-dj(e)[1]/aq*r.offset[0],0],Vt.addTo(r._movement,r._delta),gj(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 cq=ht(ht({},fj),{},{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 s=i=>{const a=uI(Rp(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},o=i=>{const a=uI(Rp(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[s(),o()]:i=>[s(i),o(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({},hd),{},{mouseOnly:(t=!0)=>t});class uq extends VX{constructor(...e){super(...e),on(this,"ingKey","wheeling")}wheel(e){this.state._active||this.start(e),this.wheelChange(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(e){const n=this.state;n._delta=dj(e),Vt.addTo(n._movement,n._delta),gj(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 dq=hd;ht(ht({},hd),{},{mouseOnly:(t=!0)=>t});const pb=new Map,wx=new Map;function hq(t){pb.set(t.key,t.engine),wx.set(t.key,t.resolver)}const fq={key:"pinch",engine:lq,resolver:cq},pq={key:"wheel",engine:uq,resolver:dq};function gq(t,e){if(t==null)return{};var n={},r=Object.keys(t),s,o;for(o=0;o<r.length;o++)s=r[o],!(e.indexOf(s)>=0)&&(n[s]=t[s]);return n}function mq(t,e){if(t==null)return{};var n=gq(t,e),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(s=0;s<o.length;s++)r=o[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}const yq={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}},Sq=["target","eventOptions","window","enabled","transform"];function cf(t={},e){const n={};for(const[r,s]of Object.entries(e))switch(typeof s){case"function":n[r]=s.call(n,t[r],r,t);break;case"object":n[r]=cf(t[r],s);break;case"boolean":s&&(n[r]=t[r]);break}return n}function vq(t,e,n={}){const r=t,{target:s,eventOptions:o,window:i,enabled:a,transform:l}=r,c=mq(r,Sq);if(n.shared=cf({target:s,eventOptions:o,window:i,enabled:a,transform:l},yq),e){const u=wx.get(e);n[e]=cf(ht({shared:n.shared},c),u)}else for(const u in c){const h=wx.get(u);h&&(n[u]=cf(ht({shared:n.shared},c[u]),h))}return n}class mj{constructor(e,n){on(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=n}add(e,n,r,s,o){const i=this._listeners,a=FX(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ht(ht({},l),o);e.addEventListener(a,s,c);const u=()=>{e.removeEventListener(a,s,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class xq{constructor(){on(this,"_timeouts",new Map)}add(e,n,r=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(n,r,...s))}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 wq{constructor(e){on(this,"gestures",new Set),on(this,"_targetEventStore",new mj(this)),on(this,"gestureEventStores",{}),on(this,"gestureTimeoutStores",{}),on(this,"handlers",{}),on(this,"config",{}),on(this,"pointerIds",new Set),on(this,"touchIds",new Set),on(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),bq(this,e)}setEventIds(e){if(uj(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=vq(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 s;if(!(n.target&&(s=n.target(),!s))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],l=fI(r,a.eventOptions,!!s);if(a.enabled){const c=pb.get(i);new c(this,e,i).bind(l)}}const o=fI(r,n.eventOptions,!!s);for(const i in this.nativeHandlers)o(i,"",a=>this.nativeHandlers[i](ht(ht({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const o in r)r[o]=KX(...r[o]);if(!s)return r;for(const o in r){const{device:i,capture:a,passive:l}=$X(o);this._targetEventStore.add(s,i,"",r[o],{capture:a,passive:l})}}}}function Oa(t,e){t.gestures.add(e),t.gestureEventStores[e]=new mj(t,e),t.gestureTimeoutStores[e]=new xq}function bq(t,e){e.drag&&Oa(t,"drag"),e.wheel&&Oa(t,"wheel"),e.scroll&&Oa(t,"scroll"),e.move&&Oa(t,"move"),e.pinch&&Oa(t,"pinch"),e.hover&&Oa(t,"hover")}const fI=(t,e,n)=>(r,s,o,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 f=a?r:RX(r,s,u);n&&h&&(f+="Passive"),t[f]=t[f]||[],t[f].push(o)},Pq=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Cq(t){const e={},n={},r=new Set;for(let s in t)Pq.test(s)?(r.add(RegExp.lastMatch),n[s]=t[s]):e[s]=t[s];return[n,e,r]}function Da(t,e,n,r,s,o){if(!t.has(n)||!pb.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};s[r]=l,o[r]=o[r]||{}}function _q(t,e){const[n,r,s]=Cq(t),o={};return Da(s,n,"onDrag","drag",o,e),Da(s,n,"onWheel","wheel",o,e),Da(s,n,"onScroll","scroll",o,e),Da(s,n,"onPinch","pinch",o,e),Da(s,n,"onMove","move",o,e),Da(s,n,"onHover","hover",o,e),{handlers:o,config:e,nativeHandlers:r}}function Iq(t,e={},n,r){const s=ke.useMemo(()=>new wq(t),[]);if(s.applyHandlers(t,r),s.applyConfig(e,n),ke.useEffect(s.effect.bind(s)),ke.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function Eq(t){return t.forEach(hq),function(n,r){const{handlers:s,nativeHandlers:o,config:i}=_q(n,r||{});return Iq(s,i,void 0,o)}}const pI=10,kq=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function yj(t){let{deltaY:e,deltaX:n}=t,r=0;return t.ctrlKey||t.altKey||t.metaKey?r=(Math.abs(e)>pI?pI*Math.sign(e):e)/100:t.shiftKey&&!kq&&(n=e,e=0),{x:-n,y:-e,z:-r}}const Tq=Eq([pq,fq]);let Ra;const Mq=t=>Ra===void 0?(Ra=t,!1):t-Ra>120&&t-Ra<160?(Ra=t,!0):(Ra=t,!1);function Aq(t){const e=z(),n=w.useMemo(()=>{let r="not sure";const s=({event:m})=>{if(!e.getInstanceState().isFocused||(r="not sure",Mq(Date.now())))return;const v=e.getEditingShapeId();if(v){const b=e.getShape(v);if(b&&e.getShapeUtil(b).canScroll(b)){const C=e.getShapePageBounds(v);if(C!=null&&C.containsPoint(e.inputs.currentPagePoint))return}}xe(m),Ct(m);const y=yj(m);if(y.x===0&&y.y===0)return;const S={type:"wheel",name:"wheel",delta:y,point:new x(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey,metaKey:m.metaKey,accelKey:un(m)};e.dispatch(S)};let o=1,i=1,a=1,l=0;const c=new x,u=new x,h=m=>{const v=t.current;r="not sure";const{event:y,origin:S,da:b}=m;y instanceof WheelEvent||(y.target===v||v!=null&&v.contains(y.target))&&(u.x=S[0],u.y=S[1],c.x=S[0],c.y=S[1],o=b[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:S[0],y:S[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)}))},f=m=>{if(m&&(r="zooming"),r==="zooming")return;const v=Math.abs(l-o),y=x.Dist(c,u);switch(r){case"not sure":{v>24?r="zooming":y>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:h,onPinchEnd:m=>{const v=t.current,{event:y,origin:S,offset:b}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const P=b[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:S[0],y:S[1],z:P},delta:{x:S[0],y:S[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)})})},onPinch:m=>{const v=t.current,{event:y,origin:S,offset:b,da:P}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const C=m.type==="gesturechange"||m.type==="gestureend";l=P[0];const _=S[0]-u.x,E=S[1]-u.y;switch(u.x=S[0],u.y=S[1],f(C),r){case"zooming":{a=b[0],e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:a},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:i},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}}}}},[e,t]);Tq(n,{target:t,eventOptions:{passive:!1},pinch:{from:()=>[e.getZoomLevel(),0],scaleBounds:()=>{const r=e.getBaseZoom(),s=e.getCameraOptions().zoomSteps,o=s[0]*r,i=s[s.length-1]*r;return{from:e.getZoomLevel(),max:i,min:o}}}})}function Gy(t,e,n){const r=t.getShape(e),s=t.getShapeHandles(r);return{shape:r,handle:s.find(o=>o.id===n)}}function jq(t,e){const n=z();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Dp(l.currentTarget);ud(c,l);const{shape:u,handle:h}=Gy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...lr(l)})};let s,o;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===s&&l.clientY===o)return;s=l.clientX,o=l.clientY;const{shape:c,handle:u}=Gy(n,t,e);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...lr(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Dp(l.currentTarget);dd(c,l);const{shape:u,handle:h}=Gy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...lr(l)})}}},[n,t,e])}function Oq(t){const e=z();w.useLayoutEffect(()=>{const n=CT(()=>{t.current&&e.updateViewportScreenBounds(t.current)},200,{trailing:!0}),r=e.timers.setInterval(n,1e3);window.addEventListener("resize",n);const s=new ResizeObserver(a=>{a[0].contentRect&&n()}),o=t.current;let i=null;return o&&(s.observe(o),i=Dq(o),i.addEventListener("scroll",n)),()=>{clearInterval(r),window.removeEventListener("resize",n),s.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 Dq=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,s=0){I(this,"x",0);I(this,"y",0);I(this,"w",0);I(this,"h",0);this.x=e,this.y=n,this.w=r,this.h=s}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=hh(this.x),this.y=hh(this.y),this.w=hh(this.w),this.h=hh(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,s=0){return this.x=e,this.y=n,this.w=r,this.h=s,this}expand(e){const n=Math.min(this.minX,e.minX),r=Math.min(this.minY,e.minY),s=Math.max(this.maxX,e.maxX),o=Math.max(this.maxY,e.maxY);return this.x=n,this.y=r,this.w=s-n,this.h=o-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:s}=this;return new Z(e,n,r,s)}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,s=Math.round(this.maxX/e)*e,o=Math.round(this.maxY/e)*e;this.minX=n,this.minY=r,this.width=Math.max(1,s-n),this.height=Math.max(1,o-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:s,minY:o,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 f=(u-l)/(i-s),p=(h-c)/(a-o),g=f<0,m=p<0;if(g){const v=u;u=l,l=v}if(m){const v=h;h=c,c=v}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(h-c)}union(e){const n=Math.min(this.minX,e.x),r=Math.min(this.minY,e.y),s=Math.max(this.maxX,e.w+e.x),o=Math.max(this.maxY,e.h+e.y);return this.x=n,this.y=r,this.width=s-n,this.height=o-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,s=-1/0,o=-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),s=Math.max(i.x,s),o=Math.max(i.y,o);return new Z(n,r,s-n,o-r)}static Expand(e,n){const r=Math.min(n.minX,e.minX),s=Math.min(n.minY,e.minY),o=Math.max(n.maxX,e.maxX),i=Math.max(n.maxY,e.maxY);return new Z(r,s,o-r,i-s)}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,s=-1/0,o=-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),s=Math.max(s,a.maxX),o=Math.max(o,a.maxY)}return new Z(n,r,s-n,o-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,s,o=!1){const{minX:i,minY:a,maxX:l,maxY:c}=e;let{minX:u,minY:h,maxX:f,maxY:p}=e;switch(n){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{f+=r;break}}switch(n){case"top":case"top_left":case"top_right":{h+=s;break}case"bottom":case"bottom_left":case"bottom_right":{p+=s;break}}const g=(f-u)/(l-i),m=(p-h)/(c-a),v=g<0,y=m<0;if(o){const b=(l-i)/(c-a),P=Math.abs(f-u),C=Math.abs(p-h),_=P*(m<0?1:-1)*(1/b),E=C*(g<0?1:-1)*b,k=b<P/C;switch(n){case"top_left":{k?h=p+_:u=f+E;break}case"top_right":{k?h=p+_:f=u-E;break}case"bottom_right":{k?p=h-_:f=u-E;break}case"bottom_left":{k?p=h-_:u=f+E;break}case"bottom":case"top":{const D=(u+f)/2,T=C*b;u=D-T/2,f=D+T/2;break}case"left":case"right":{const D=(h+p)/2,T=P/b;h=D-T/2,p=D+T/2;break}}}if(v){const b=f;f=u,u=b}if(y){const b=p;p=h,h=b}const S=new Z(u,h,Math.abs(f-u),Math.abs(p-h));return{box:S,scaleX:+(S.width/e.width*(g>0?1:-1)).toFixed(5),scaleY:+(S.height/e.height*(m>0?1:-1)).toFixed(5)}}equals(e){return Z.Equals(this,e)}static Equals(e,n){return n.x===e.x&&n.y===e.y&&n.w===e.w&&n.h===e.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(e){return new Z(e.x,e.y,Math.max(1,e.w),Math.max(1,e.h))}}function Rq(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 Lq(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 $q(t){return t==="top_left"||t==="top_right"||t==="bottom_right"||t==="bottom_left"}class q{constructor(e,n,r,s,o,i){I(this,"a",1);I(this,"b",0);I(this,"c",0);I(this,"d",1);I(this,"e",0);I(this,"f",0);this.a=e,this.b=n,this.c=r,this.d=s,this.e=o,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:s,c:o,d:i,e:a,f:l}=this;return this.a=r*n.a+o*n.b,this.c=r*n.c+o*n.d,this.e=r*n.e+o*n.f+a,this.b=s*n.a+i*n.b,this.d=s*n.c+i*n.d,this.f=s*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:s,e:o,f:i}=this,a=e*s-n*r;return this.a=s/a,this.b=n/-a,this.c=r/-a,this.d=e/a,this.e=(s*o-r*i)/-a,this.f=(n*o-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 s=Math.cos(e),o=Math.sin(e),i=new q(s,o,-o,s,0,0);return n===void 0?i:q.Compose(q.Translate(n,r),i,q.Translate(-n,-r))}static Scale(e,n,r,s){const o=new q(e,0,0,n,0,0);return r===void 0?o:q.Compose(q.Translate(r,s),o,q.Translate(-r,-s))}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,s=e.length;r<s;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 Sx(n)}static Decompose(e){let n,r,s;if(e.a!==0||e.c!==0){const o=(e.a*e.a+e.c*e.c)**.5;n=o,r=(e.a*e.d-e.b*e.c)/o,s=Math.acos(e.a/o)*(e.c>0?-1:1)}else if(e.b!==0||e.d!==0){const o=(e.b*e.b+e.d*e.d)**.5;n=(e.a*e.d-e.b*e.c)/o,r=o,s=Ze+Math.acos(e.b/o)*(e.d>0?-1:1)}else n=0,r=0,s=0;return{x:e.e,y:e.f,scaleX:n,scaleY:r,rotation:Sx(s)}}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 Mi{constructor(e){I(this,"isFilled",!1);I(this,"isClosed",!0);I(this,"isLabel",!1);I(this,"debugColor");I(this,"ignore");I(this,"_vertices");I(this,"_bounds");I(this,"_area");I(this,"_length");this.isFilled=e.isFilled,this.isClosed=e.isClosed,this.isLabel=e.isLabel??!1,this.debugColor=e.debugColor,this.ignore=e.ignore}hitTestPoint(e,n=0,r=!1){return this.isClosed&&(this.isFilled||r)&&hr(e,this.vertices)?!0:x.Dist2(e,this.nearestPoint(e))<=n*n}distanceToPoint(e,n=!1){return e.dist(this.nearestPoint(e))*(this.isClosed&&(this.isFilled||n)&&hr(e,this.vertices)?-1:1)}distanceToLineSegment(e,n){if(e.equals(n))return this.distanceToPoint(e);const{vertices:r}=this;let s,o=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<o&&(o=i,s=l);if(!s)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&hr(s,this.vertices)?-o:o}hitTestLineSegment(e,n,r=0){return this.distanceToLineSegment(e,n)<=r}nearestPointOnLineSegment(e,n){const{vertices:r}=this;let s,o=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<o&&(o=i,s=l);if(!s)throw Error("nearest point not found");return s}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,s=e.length;r<s;r++){const o=e[r],i=e[(r+1)%s];n+=o.x*i.y-i.x*o.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 s=1;s<r;s++)e+=`L${n[s].x},${n[s].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],s=0;for(let o=1;o<e.length;o++)n=e[o],s+=x.Dist2(r,n),r=n;return Math.sqrt(s)}}class $r extends Mi{constructor(n){super({...n,isClosed:!0,isFilled:!1});I(this,"children",[]);I(this,"ignoredChildren",[]);for(const r of n.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(n=>!n.isLabel).flatMap(n=>n.vertices)}nearestPoint(n){let r=1/0,s;const{children:o}=this;if(o.length===0)throw Error("no children");let i,a;for(const l of o)i=l.nearestPoint(n),a=x.Dist2(i,n),a<r&&(r=a,s=i);if(!s)throw Error("nearest point not found");return s}distanceToPoint(n,r=!1){return Math.min(...this.children.map((s,o)=>s.distanceToPoint(n,r||o>0)))}hitTestPoint(n,r,s){return!!this.children.filter(o=>!o.isLabel).find(o=>o.hitTestPoint(n,r,s))}hitTestLineSegment(n,r,s){return!!this.children.filter(o=>!o.isLabel).find(o=>o.hitTestLineSegment(n,r,s))}getArea(){return this.children[0].area}toSimpleSvgPath(){let n="";for(const s of this.children)n+=s.toSimpleSvgPath();const r=Z.FromPoints(this.vertices).corners;for(let s=0,o=r.length;s<o;s++){const i=r[s],a=r[(s-1+o)%o],l=i.dist(a),c=r[(s+1)%o],u=i.dist(c),h=i.clone().lrp(a,4/l),f=i,p=i.clone().lrp(c,4/u);n+=`M${h.x},${h.y} L${f.x},${f.y} L${p.x},${p.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 Fq(t=!0){const[e,n]=w.useState(0),r=z();w.useEffect(()=>{if(!t)return;const s=()=>n(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,t])}const Nq=Zt(function({showStroke:e=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const s=z();Fq(r);const o=s.getZoomLevel(),i=s.getRenderingShapes(),{inputs:{currentPagePoint:a}}=s;return d.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=s.getShape(l.id);if(c.type==="group")return null;const u=s.getShapeGeometry(c),h=s.getShapePageTransform(c),f=s.getPointInShapeSpace(c,a),p=u.nearestPoint(f),g=u.distanceToPoint(f,!0),m=Math.abs(g)*o,v=g<0,{vertices:y}=u;return d.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[e&&d.jsx("g",{stroke:u.debugColor??"red",opacity:"1",strokeWidth:2/o,fill:"none",children:d.jsx(Sj,{geometry:u})}),n&&y.map((S,b)=>d.jsx("circle",{cx:S.x,cy:S.y,r:2/o,fill:`hsl(${jl(b,[0,y.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/o},`v${b}`)),r&&m<150&&d.jsx("line",{x1:p.x,y1:p.y,x2:f.x,y2:f.y,opacity:1-m/150,stroke:v?"goldenrod":"dodgerblue",strokeWidth:2/o})]},l.id+"_outline")})})});function Sj({geometry:t}){return t instanceof $r?d.jsx(d.Fragment,{children:[...t.children,...t.ignoredChildren].map((e,n)=>d.jsx(Sj,{geometry:e},n))}):d.jsx("path",{d:t.toSimpleSvgPath()})}function vj(t){return I9(t)}function xj(){const t=z(),e=CV("userIds",()=>vj(t.getCollaborators().map(n=>n.userId)).sort(),{isEqual:(n,r)=>{var s;return n.join(",")===((s=r.join)==null?void 0:s.call(r,","))}},[t]);return U(e)}function Dg(t){const e=z();return U(`latestPresence:${t}`,()=>e.getCollaborators().find(r=>r.userId===t),[e,t])??null}const zq=Zt(function(){return xj().map(n=>d.jsx(Bq,{collaboratorId:n},n))}),Bq=Zt(function({collaboratorId:e}){const n=z(),r=Dg(e),s=Hq(n,r);if(!(r&&r.currentPageId===n.getCurrentPageId()))return null;switch(s){case"inactive":{const{followingUserId:o,highlightedUserIds:i}=n.getInstanceState();if(!(o===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:o}=n.getInstanceState();if(r.followingUserId===n.user.getId()&&!(r.chatMessage||o.includes(r.userId)))return null;break}}return d.jsx(Uq,{latestPresence:r})}),Uq=Zt(function({latestPresence:e}){const n=z(),{CollaboratorBrush:r,CollaboratorScribble:s,CollaboratorCursor:o,CollaboratorHint:i,CollaboratorShapeIndicator:a}=st(),l=n.getZoomLevel(),c=n.getViewportPageBounds(),{userId:u,chatMessage:h,brush:f,scribbles:p,selectedShapeIds:g,userName:m,cursor:v,color:y}=e;if(!v)return null;const S=!(v.x<c.minX-12/l||v.y<c.minY-16/l||v.x>c.maxX-12/l||v.y>c.maxY-16/l);return d.jsxs(d.Fragment,{children:[f&&r?d.jsx(r,{className:"tl-collaborator__brush",brush:f,color:y,opacity:.1},u+"_brush"):null,S&&o?d.jsx(o,{className:"tl-collaborator__cursor",point:v,color:y,zoom:l,name:m!=="New User"?m:null,chatMessage:h??""},u+"_cursor"):i?d.jsx(i,{className:"tl-collaborator__cursor-hint",point:v,color:y,zoom:l,viewport:c},u+"_cursor_hint"):null,s&&p.length?d.jsx(d.Fragment,{children:p.map(b=>d.jsx(s,{className:"tl-collaborator__scribble",scribble:b,color:y,zoom:l,opacity:b.color==="laser"?.5:.1},u+"_scribble_"+b.id))}):null,a&&g.filter(b=>!n.isShapeHidden(b)).map(b=>d.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:b,color:y,opacity:.5},u+"_"+b))]})});function gI(t,e){return e>t.options.collaboratorInactiveTimeoutMs?"inactive":e>t.options.collaboratorIdleTimeoutMs?"idle":"active"}function Hq(t,e){const n=w.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[r,s]=w.useState(()=>gI(t,Date.now()-n.current));return w.useEffect(()=>{const o=t.timers.setInterval(()=>{s(gI(t,Date.now()-n.current))},t.options.collaboratorCheckIntervalMs);return()=>clearInterval(o)},[t]),e&&(n.current=e.lastActivityTimestamp??1/0),r}function Kq(){const t=z(),e=U("is menu open",()=>t.menus.hasAnyOpenMenus(),[t]),[n,r]=w.useState(!1),s=e||n,o=fb(),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,f,p;if(i.current.isDown){if(i.current.isDragging){(h=o.onPointerMove)==null||h.call(o,u);return}if(x.Dist2(i.current.start,new x(u.clientX,u.clientY))>t.options.dragDistanceSquared){i.current={...i.current,isDown:!0,isDragging:!0};const{x:g,y:m}=i.current.start;(f=o.onPointerDown)==null||f.call(o,{...u,clientX:g,clientY:m,button:0}),(p=o.onPointerMove)==null||p.call(o,u)}}},[o,t]),c=w.useCallback(u=>{var h;(h=o.onPointerUp)==null||h.call(o,u),r(!1),i.current={isDown:!1,isDragging:!1,start:new x(u.clientX,u.clientY)}},[o]);return s&&d.jsx("div",{className:"tlui-menu-click-capture","data-testid":"menu-click-capture.content",...o,onPointerDown:a,onPointerMove:l,onPointerUp:c})}const wj=w.memo(function({id:e,shape:n,util:r,index:s,backgroundIndex:o,opacity:i}){const a=z(),{ShapeErrorFallback:l}=st(),c=w.useRef(null),u=w.useRef(null),h=w.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});ui("set shape stuff",()=>{const g=a.getShape(e);if(!g)return;const m=h.current,v=a.getShapeClipPath(e)??"none";v!==m.clipPath&&(rn(c.current,"clip-path",v),rn(u.current,"clip-path",v),m.clipPath=v);const y=a.getShapePageTransform(e),S=q.toCssString(y),b=a.getShapeGeometry(g).bounds;S!==m.transform&&(rn(c.current,"transform",S),rn(u.current,"transform",S),m.transform=S);const P=Math.max(b.width,1),C=Math.max(b.height,1);(P!==m.width||C!==m.height)&&(rn(c.current,"width",P+"px"),rn(c.current,"height",C+"px"),rn(u.current,"width",P+"px"),rn(u.current,"height",C+"px"),m.width=P,m.height=C)},[a]),ui("set opacity and z-index",()=>{const g=c.current,m=u.current;rn(g,"opacity",i),rn(m,"opacity",i),rn(g,"z-index",s),rn(m,"z-index",o)},[i,s,o]),ui("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 f=w.useCallback(g=>a.annotateError(g,{origin:"shape",willCrashApp:!1}),[a]);if(!n)return null;const p="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(Bu,{fallback:l,onError:f,children:d.jsx(Pj,{shape:n,util:r})})}),d.jsx("div",{ref:c,className:"tl-shape","data-shape-type":n.type,"data-shape-is-filled":p,"data-shape-id":n.id,draggable:!1,children:d.jsx(Bu,{fallback:l,onError:f,children:d.jsx(bj,{shape:n,util:r})})})]})}),bj=w.memo(function({shape:e,util:n}){return Eg("InnerShape:"+e.type,()=>n.component(n.editor.store.unsafeGetWithoutCapture(e.id)),[n,e.id])},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta&&t.util===e.util),Pj=w.memo(function({shape:e,util:n}){return Eg("InnerShape:"+e.type,()=>{var r;return(r=n.backgroundComponent)==null?void 0:r.call(n,n.editor.store.unsafeGetWithoutCapture(e.id))},[n,e.id])},(t,e)=>t.shape.props===e.shape.props&&t.shape.meta===e.shape.meta&&t.util===e.util);function Wq({className:t}){const e=z(),{Background:n,SvgDefs:r,ShapeIndicators:s}=st(),o=w.useRef(null),i=w.useRef(null),a=w.useRef(null),l=Tt();Oq(o),_X(),CX(),Aq(o),kX(o);const c=w.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});ui("position layers",function(){const{x:S,y:b,z:P}=e.getCamera();if(c.current.allowTextOutline&&Ge.isSafari&&(l.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&P<e.options.textShadowLod!==c.current.lodDisableTextOutline){const E=P<e.options.textShadowLod;l.style.setProperty("--tl-text-outline",E?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=E}const C=P>=1?jl(P,[1,8],[.125,.5],!0):jl(P,[.1,1],[-2,.125],!0),_=`scale(${N(P)}) translate(${N(S+C)}px,${N(b+C)}px)`;rn(i.current,"transform",_),rn(a.current,"transform",_)},[e,l]);const u=fb(),h=U("shapeSvgDefs",()=>{const y=new Map;for(const S of ut(e.shapeUtils)){if(!S)return;const b=S.getCanvasSvgDefs();for(const{key:P,component:C}of b)y.has(P)||y.set(P,d.jsx(C,{},P))}return[...y.values()]},[e]),f=U("debug_shapes",()=>wt.hideShapes.get(),[wt]),p=U("debug_svg",()=>wt.debugSvg.get(),[wt]),g=U("debug_geometry",()=>wt.debugGeometry.get(),[wt]),m=U("isEditingAnything",()=>e.getEditingShapeId()!==null,[e]),v=U("isSelectingAnything",()=>!!e.getSelectedShapeIds().length,[e]);return d.jsxs(d.Fragment,{children:[d.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":m,"data-isselectinganything":v,className:ce("tl-canvas",t),"data-testid":"canvas",...u,children:[d.jsx("svg",{className:"tl-svg-context",children:d.jsxs("defs",{children:[h,d.jsx(oZ,{}),d.jsx(iZ,{}),r&&d.jsx(r,{})]})}),n&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(n,{})}),d.jsx(Vq,{}),d.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(uZ,{}),d.jsx(cZ,{}),f?null:p?d.jsx(tZ,{}):d.jsx(rZ,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:a,className:"tl-html-layer",children:[g?d.jsx(Nq,{}):null,d.jsx(Qq,{}),d.jsx(Xq,{}),d.jsx(Yq,{}),d.jsx(qq,{}),s&&d.jsx(s,{}),d.jsx(sZ,{}),d.jsx(Zq,{}),d.jsx(lZ,{}),d.jsx(zq,{})]})}),d.jsx(dZ,{})]}),d.jsx(Kq,{}),d.jsx(Gq,{})]})}function Gq(){const{InFrontOfTheCanvas:t}=st();return t?d.jsx(t,{}):null}function Vq(){const t=z(),e=U("gridSize",()=>t.getDocumentSettings().gridSize,[t]),{x:n,y:r,z:s}=U("camera",()=>t.getCamera(),[t]),o=U("isGridMode",()=>t.getInstanceState().isGridMode,[t]),{Grid:i}=st();return i&&o?d.jsx(i,{x:n,y:r,z:s,size:e}):null}function Yq(){const t=z(),e=U("scribbles",()=>t.getInstanceState().scribbles,[t]),n=U("zoomLevel",()=>t.getZoomLevel(),[t]),{Scribble:r}=st();return r&&e.length?e.map(s=>d.jsx(r,{className:"tl-user-scribble",scribble:s,zoom:n},s.id)):null}function Xq(){const t=z(),e=U("brush",()=>t.getInstanceState().brush,[t]),{Brush:n}=st();return n&&e?d.jsx(n,{className:"tl-user-brush",brush:e}):null}function qq(){const t=z(),e=U("zoomBrush",()=>t.getInstanceState().zoomBrush,[t]),{ZoomBrush:n}=st();return n&&e?d.jsx(n,{className:"tl-user-brush tl-zoom-brush",brush:e}):null}function Zq(){const t=z(),e=U("snapLines",()=>t.snaps.getIndicators(),[t]),n=U("zoomLevel",()=>t.getZoomLevel(),[t]),{SnapIndicator:r}=st();return r&&e.length>0?e.map(s=>d.jsx(r,{className:"tl-user-snapline",line:s,zoom:n},s.id)):null}function Qq(){const t=z(),e=U("handles shapeIdWithHandles",()=>{const{isReadonly:n,isChangingStyle:r}=t.getInstanceState();if(n||r)return!1;const s=t.getOnlySelectedShape();return!s||!t.getShapeHandles(s)?!1:s.id},[t]);return e?d.jsx(Jq,{shapeId:e}):null}function Jq({shapeId:t}){const e=z(),{Handles:n}=st(),r=U("zoomLevel",()=>e.getZoomLevel(),[e]),s=U("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),o=U("handles transform",()=>e.getShapePageTransform(t),[e,t]),i=U("handles",()=>{const l=e.getShapeHandles(t);if(!l)return null;const c=(s?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,s,t]),a=U("isHidden",()=>e.isShapeHidden(t),[e,t]);return!n||!i||!o||a?null:d.jsx(n,{children:d.jsx("g",{transform:q.toCssString(o),children:i.map(l=>d.jsx(eZ,{shapeId:t,handle:l,zoom:r,isCoarse:s},l.id))})})}function eZ({shapeId:t,handle:e,zoom:n,isCoarse:r}){const s=jq(t,e.id),{Handle:o}=st();return o?d.jsx("g",{"aria-label":"handle",transform:`translate(${e.x}, ${e.y})`,...s,children:d.jsx(o,{shapeId:t,handle:e,zoom:n,isCoarse:r})}):null}function tZ(){const t=z();return U("rendering shapes",()=>t.getRenderingShapes(),[t]).map(n=>d.jsxs(w.Fragment,{children:[d.jsx(wj,{...n}),d.jsx(aZ,{id:n.id,mode:"iframe"})]},n.id+"_fragment"))}function nZ(){const t=z(),e=w.useRef(new Set);return ui("reflow for culled shapes",()=>{const n=t.getCulledShapes();if(e.current.size===n.size&&[...n].every(s=>e.current.has(s)))return;e.current=n;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[t]),null}function rZ(){const t=z(),e=U("rendering shapes",()=>t.getRenderingShapes(),[t]);return d.jsxs(d.Fragment,{children:[e.map(n=>d.jsx(wj,{...n},n.id+"_shape")),Ge.isSafari&&d.jsx(nZ,{})]})}function sZ(){const t=z(),{ShapeIndicator:e}=st(),n=U("hinting shape ids",()=>y0(t.getHintingShapeIds()),[t]);return!n.length||!e?null:n.map(r=>d.jsx(e,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))}function oZ(){return d.jsxs("g",{id:rs("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 iZ(){const t=rs("cursor_hint");return d.jsx("path",{id:t,fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function aZ({id:t,mode:e}){const n=z(),[r,s]=w.useState(null),o=U("is in root",()=>{const i=n.getShape(t);return(i==null?void 0:i.parentId)===n.getCurrentPageId()},[n,t]);return w.useEffect(()=>{if(!o)return;let i=null;const a=As("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 f=await n.getSvgString([t],{padding:u,background:n.getInstanceState().exportBackground});if(i!==l||!f)return;const p=`data:image/svg+xml;utf8,${encodeURIComponent(f.svg)}`;s({src:p,bounds:h})});return()=>{i=null,a()}},[n,t,o]),!o||!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 lZ(){const t=z(),e=U("selection rotation",()=>t.getSelectionRotation(),[t]),n=U("selection bounds",()=>t.getSelectionRotatedPageBounds(),[t]),{SelectionForeground:r}=st();return!n||!r?null:d.jsx(r,{bounds:n,rotation:e})}function cZ(){const t=z(),e=U("selection rotation",()=>t.getSelectionRotation(),[t]),n=U("selection bounds",()=>t.getSelectionRotatedPageBounds(),[t]),{SelectionBackground:r}=st();return!n||!r?null:d.jsx(r,{bounds:n,rotation:e})}function uZ(){const{OnTheCanvas:t}=st();return t?d.jsx(t,{}):null}function dZ(){const t=z(),e=U("camera state",()=>t.getCameraState(),[t]);return d.jsx("div",{className:ce("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":e==="idle"})})}function hZ({className:t,zoom:e,point:n,color:r,viewport:s,opacity:o=1}){const i=w.useRef(null);ec(i,Bt(n.x,s.minX+5/e,s.maxX-5/e),Bt(n.y,s.minY+5/e,s.maxY-5/e),1/e,x.Angle(s.center,n));const a=rs("cursor_hint");return d.jsxs("svg",{ref:i,className:ce("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:o})]})}const mI=w.memo(function({className:e,zoom:n,point:r,color:s,name:o,chatMessage:i}){const a=w.useRef(null);ec(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n);const l=rs("cursor");return r?d.jsxs("div",{ref:a,className:ce("tl-overlays__item",e),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:`#${l}`,color:s})}),i?d.jsxs(d.Fragment,{children:[o&&d.jsx("div",{className:"tl-nametag-title",style:{color:s},children:o}),d.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:s},children:i})]}):o&&d.jsx("div",{className:"tl-nametag",style:{backgroundColor:s},children:o})]}):null});function fZ({x:t,y:e,z:n,size:r}){const s=Jl("grid"),o=z(),{gridSteps:i}=o.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,f=.5+t*n,p=.5+e*n,g=f>0?f%h:h+f%h,m=p>0?p%h:h+p%h,v=n<l?jl(n,[a,l],[0,1]):1;return d.jsx("pattern",{id:lb(s,`${c}`),width:h,height:h,patternUnits:"userSpaceOnUse",children:d.jsx("circle",{className:"tl-grid-dot",cx:g,cy:m,r:1,opacity:v})},u)})}),i.map(({step:a},l)=>d.jsx("rect",{width:"100%",height:"100%",fill:`url(#${s}_${a})`},l))]})}function pZ({handle:t,isCoarse:e,className:n,zoom:r}){const s=z(),o=(e?s.options.coarseHandleRadius:s.options.handleRadius)/r;if(t.type==="clone"){const a=3/r,l=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,c=SX.indexOf(t.id);return d.jsxs("g",{className:ce(`tl-handle tl-handle__${t.type}`,n),children:[d.jsx("circle",{className:"tl-handle__bg",r:o}),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:ce(`tl-handle tl-handle__${t.type}`,n),children:[d.jsx("circle",{className:"tl-handle__bg",r:o}),d.jsx("circle",{className:"tl-handle__fg",r:i})]})}const gZ=({children:t})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:t}),mZ=()=>{const{Spinner:t}=st();return d.jsx(Ab,{children:t?d.jsx(t,{}):null})};function gb(t,e=!0){const n=t.length;if(n<2)return"";let r=t[0],s=t[1];if(n===2)return`M${je(r)}L${je(s)}`;let o="";for(let i=2,a=n-1;i<a;i++)r=t[i],s=t[i+1],o+=Bn(r,s);return e?`M${Bn(t[0],t[1])}Q${je(t[1])}${Bn(t[1],t[2])}T${o}${Bn(t[n-1],t[0])}${Bn(t[0],t[1])}Z`:`M${je(t[0])}Q${je(t[1])}${Bn(t[1],t[2])}${t.length>3?"T":""}${o}L${je(t[n-1])}`}function yI({scribble:t,zoom:e,color:n,opacity:r,className:s}){return t.points.length?d.jsx("svg",{className:s&&ce("tl-overlays__item",s),children:d.jsx("path",{className:"tl-scribble",d:gb(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 ec(n,t.x,t.y,1,e),w.useLayoutEffect(()=>{const r=n.current;r&&(r.style.width=N(Math.max(1,t.width))+"px",r.style.height=N(Math.max(1,t.height))+"px")},[t.width,t.height]),d.jsx("div",{ref:n,className:"tl-selection__bg",draggable:!1})}function yZ({bounds:t,rotation:e}){const n=z(),r=w.useRef(null),s=U("only selected shape",()=>n.getOnlySelectedShape(),[n]),o=s?n.getShapeUtil(s).expandSelectionOutlinePx(s):0;return ec(r,t==null?void 0:t.x,t==null?void 0:t.y,1,e,{x:-o,y:-o}),t=o instanceof Z?t.clone().expand(o).zeroFix():t.clone().expandBy(o).zeroFix(),d.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsx("rect",{className:ce("tl-selection__fg__outline"),width:N(t.width),height:N(t.height)})})}const SZ=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),vZ=({shape:t,util:e})=>Eg("Indicator: "+t.type,()=>e.indicator(e.editor.store.unsafeGetWithoutCapture(t.id))),xZ=({editor:t,id:e})=>{const n=U("shape for indicator",()=>t.store.get(e),[t,e]),{ShapeIndicatorErrorFallback:r}=st();return!n||n.isLocked?null:d.jsx(Bu,{fallback:r,onError:s=>t.annotateError(s,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(vZ,{shape:n,util:t.getShapeUtil(n)},n.id)})},SI=w.memo(function({shapeId:e,className:n,color:r,hidden:s,opacity:o}){const i=z(),a=w.useRef(null);return ui("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",s?"none":"block")},[s]),d.jsx("svg",{ref:a,className:ce("tl-overlays__item",n),children:d.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:o,children:d.jsx(xZ,{editor:i,id:e})})})}),wZ=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"}),_j=w.memo(function(){const e=z(),n=w.useRef(new Set),r=U("should display selected ids",()=>{const i=n.current,a=new Set;if(e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!e.getInstanceState().isChangingStyle){const l=e.getSelectedShapeIds();for(const c of l)a.add(c);if(e.isInAny("select.idle","select.editing_shape")){const c=e.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const u=e.getHoveredShapeId();u&&a.add(u)}}}if(i.size!==a.size)return n.current=a,a;for(const l of a)if(!i.has(l))return n.current=a,a;return i},[e]),s=U("rendering shapes",()=>e.getRenderingShapes(),[e]),{ShapeIndicator:o}=st();return o?s.map(({id:i})=>d.jsx(o,{shapeId:i,hidden:!r.has(i)},i+"_indicator")):null});function bZ({points:t,zoom:e}){const n=2.5/e,r=t.reduce((f,p)=>Math.min(f,p.x),1/0),s=t.reduce((f,p)=>Math.max(f,p.x),-1/0),o=t.reduce((f,p)=>Math.min(f,p.y),1/0),i=t.reduce((f,p)=>Math.max(f,p.y),-1/0),a=t.some(f=>f.x===r&&f.y===o);let l,c,u,h;return a?(l=r,c=o,u=s,h=i):(l=r,c=i,u=s,h=o),d.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[d.jsx("line",{x1:l,y1:c,x2:u,y2:h}),t.map((f,p)=>d.jsx("g",{transform:`translate(${f.x},${f.y})`,children:d.jsx("path",{className:"tl-snap-point",d:`M ${-n},${-n} L ${n},${n} M ${-n},${n} L ${n},${-n}`})},p))]})}function PZ({gaps:t,direction:e,zoom:n}){const r=3.5/n;let s=[-1/0,1/0],o=null;const i=e==="horizontal";for(const l of t){if(o=Gr(s[0],s[1],i?l.startEdge[0].y:l.startEdge[0].x,i?l.startEdge[1].y:l.startEdge[1].x),o)s=o;else continue;if(o=Gr(s[0],s[1],i?l.endEdge[0].y:l.endEdge[0].x,i?l.endEdge[1].y:l.endEdge[1].x),o)s=o;else continue}if(s===null)return null;const a=(s[0]+s[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 CZ({className:t,line:e,zoom:n}){return d.jsx("svg",{className:ce("tl-overlays__item",t),children:e.type==="points"?d.jsx(bZ,{...e,zoom:n}):e.type==="gaps"?d.jsx(PZ,{...e,zoom:n}):null})}function mb(){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 _Z=()=>null;function Ij(t,e){const n=w.useRef(t);return e(t,n.current)?n.current:(n.current=t,t)}const IZ=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:AT(t,e));function qo(t){return Ij(t,IZ)}const EZ=(t,e)=>(t??(t=null),e??(e=null),t===e?!0:!t||!e?!1:RT(t,e));function tc(t){return Ij(t,EZ)}const Ej=w.createContext(null);function kZ({overrides:t={},children:e}){const n=tc(t),r=w.useMemo(()=>({Background:dX,SvgDefs:_Z,Brush:Uy,ZoomBrush:Uy,CollaboratorBrush:Uy,Cursor:mI,CollaboratorCursor:mI,CollaboratorHint:hZ,CollaboratorShapeIndicator:SI,Grid:fZ,Scribble:yI,SnapIndicator:CZ,Handles:gZ,Handle:pZ,CollaboratorScribble:yI,ErrorFallback:Tj,ShapeErrorFallback:SZ,ShapeIndicatorErrorFallback:wZ,Spinner:mb,SelectionBackground:Cj,SelectionForeground:yZ,ShapeIndicators:_j,ShapeIndicator:SI,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:Wq,LoadingScreen:mZ,...n}),[n]);return d.jsx(Ej.Provider,{value:r,children:e})}function st(){const t=w.useContext(Ej);if(!t)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return t}const Rg={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 kj(){Rg.hardReset()}function TZ(){Rg.refreshPage()}const MZ="https://github.com/tldraw/tldraw/issues/new",Tj=({error:t,editor:e})=>{const n=w.useRef(null),[r,s]=w.useState(!1),[o,i]=w.useState(!1),[a,l]=w.useState(!1);let c=null;try{c=st().Canvas??null}catch{}const u=t instanceof Error?t.message:String(t),h=t instanceof Error?t.stack:null,f=U("isDarkMode",()=>{try{if(e)return e.user.getIsDarkMode()}catch{}return null},[e]),[p,g]=w.useState(null);w.useLayoutEffect(()=>{var C;f!==null&&g(f);let b=(C=n.current)==null?void 0:C.parentElement,P=!1;for(;b;){if(b.classList.contains("tl-theme__dark")||b.classList.contains("tl-theme__light")){P=!0;break}b=b.parentElement}if(P){g(null);return}typeof window<"u"&&"matchMedia"in window&&g(window.matchMedia("(prefers-color-scheme: dark)").matches)},[f]),w.useEffect(()=>{if(o){const b=e==null?void 0:e.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(b)}},[o,e]);const m=()=>{const b=document.createElement("textarea");b.value=h??u,document.body.appendChild(b),b.select(),document.execCommand("copy"),b.remove(),i(!0)},v=()=>{TZ()},y=async()=>{kj()},S=new URL(MZ);return S.searchParams.set("title",u),S.searchParams.set("labels","bug"),S.searchParams.set("body",`Hey, I ran into an error while using tldraw:
|
|
93
|
+
|
|
94
|
+
\`\`\`js
|
|
95
|
+
${h??u}
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
My browser: ${navigator.userAgent}`),d.jsxs("div",{ref:n,className:ce("tl-container tl-error-boundary",p===null?"":p?"tl-theme__dark":"tl-theme__light"),children:[d.jsx("div",{className:"tl-error-boundary__overlay"}),e&&d.jsx(ab,{onError:Ru,fallback:()=>null,children:d.jsx(ub,{editor:e,children:d.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?d.jsx(c,{}):null})})}),d.jsx("div",{className:ce("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Are you sure?"}),d.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),d.jsx("button",{className:"tl-error-boundary__reset",onClick:y,children:"Reset data"})]})]}):d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Something went wrong"}),d.jsx("p",{children:"Please refresh the page to continue."}),d.jsxs("p",{children:["If you keep seeing this screen, you can create a"," ",d.jsx("a",{href:S.toString(),children:"GitHub issue"})," or ask for help on"," ",d.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"Discord"}),". If you are still stuck, you can reset the tldraw data on your machine. This may erase the project you were working on, so try to get help first."]}),r&&d.jsxs(d.Fragment,{children:["Message:",d.jsx("h4",{children:d.jsx("code",{children:u})}),"Stack trace:",d.jsxs("div",{className:"tl-error-boundary__content__error",children:[d.jsx("pre",{children:d.jsx("code",{children:h??u})}),d.jsx("button",{onClick:m,children:o?"Copied!":"Copy"})]})]}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>s(!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"})]})]})]})})]})},Mj="TLDRAW_USER_DATA_v3",Aj=Pe({id:ye,name:ye.nullable().optional(),color:ye.nullable().optional(),locale:ye.nullable().optional(),animationSpeed:pe.nullable().optional(),edgeScrollSpeed:pe.nullable().optional(),colorScheme:Ag("light","dark","system").optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional(),isDynamicSizeMode:we.nullable().optional(),isPasteAtCursorMode:we.nullable().optional()}),eo={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7,AddPasteAtCursor:8},yb=Math.max(...Object.values(eo));function AZ(t){t.version<eo.AddAnimationSpeed&&(t.user.animationSpeed=1),t.version<eo.AddIsSnapMode&&(t.user.isSnapMode=!1),t.version<eo.MakeFieldsNullable,t.version<eo.AddEdgeScrollSpeed&&(t.user.edgeScrollSpeed=1),t.version<eo.AddExcalidrawSelectMode&&(t.user.isWrapMode=!1),t.version<eo.AllowSystemColorScheme&&(t.user.isDarkMode===!0?t.user.colorScheme="dark":t.user.isDarkMode===!1&&(t.user.colorScheme="light"),delete t.user.isDarkMode),t.version<eo.AddDynamicSizeMode&&(t.user.isDynamicSizeMode=!1),t.version<eo.AddPasteAtCursor&&(t.user.isPasteAtCursorMode=!1),t.version=yb}const bx=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function jj(){return bx[Math.floor(Math.random()*bx.length)]}function jZ(){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 vs=Object.freeze({name:"New User",locale:oX(),color:jj(),edgeScrollSpeed:1,animationSpeed:jZ()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1,isPasteAtCursorMode:!1,colorScheme:"light"});function Vy(){return{id:ze(),color:jj()}}function Oj(t){if(t===null||typeof t!="object"||!("version"in t)||!("user"in t)||typeof t.version!="number")return Vy();const e=nt(t);AZ(e);try{return Aj.validate(e.user)}catch{return Vy()}}function OZ(){const t=JSON.parse(C0(Mj)||"null")??null;return Oj(t)}const Lg=It("globalUserData",null);function DZ(){_0(Mj,JSON.stringify({version:yb,user:Lg.get()}))}function Dj(t){Aj.validate(t),Lg.set(t),DZ(),RZ()}const vl=typeof BroadcastChannel<"u"?new BroadcastChannel("tldraw-user-sync"):null;vl==null||vl.addEventListener("message",t=>{const e=t.data;(e==null?void 0:e.type)===Lj&&(e==null?void 0:e.origin)!==Rj()&&Lg.set(Oj(e.data))});let Yy=null;function Rj(){return Yy===null&&(Yy=ze()),Yy}const Lj="tldraw-user-preferences-change";function RZ(){vl==null||vl.postMessage({type:Lj,origin:Rj(),data:{user:$j(),version:yb}})}function $j(){let t=Lg.get();return t||(t=OZ(),Dj(t)),t}const LZ=G("defaultLocalStorageUserPrefs",()=>$j());function Fj(t={}){return{userPreferences:t.userPreferences??LZ,setUserPreferences:t.setUserPreferences??Dj}}var Nj={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function s(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function o(l,c,u,h,f){if(typeof u!="function")throw new TypeError("The listener must be a function");var p=new s(u,h||l,f),g=n?n+c:c;return l._events[g]?l._events[g].fn?l._events[g]=[l._events[g],p]:l._events[g].push(p):(l._events[g]=p,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 f=0,p=h.length,g=new Array(p);f<p;f++)g[f]=h[f].fn;return g},a.prototype.listenerCount=function(c){var u=n?n+c:c,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,u,h,f,p,g){var m=n?n+c:c;if(!this._events[m])return!1;var v=this._events[m],y=arguments.length,S,b;if(v.fn){switch(v.once&&this.removeListener(c,v.fn,void 0,!0),y){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,u),!0;case 3:return v.fn.call(v.context,u,h),!0;case 4:return v.fn.call(v.context,u,h,f),!0;case 5:return v.fn.call(v.context,u,h,f,p),!0;case 6:return v.fn.call(v.context,u,h,f,p,g),!0}for(b=1,S=new Array(y-1);b<y;b++)S[b-1]=arguments[b];v.fn.apply(v.context,S)}else{var P=v.length,C;for(b=0;b<P;b++)switch(v[b].once&&this.removeListener(c,v[b].fn,void 0,!0),y){case 1:v[b].fn.call(v[b].context);break;case 2:v[b].fn.call(v[b].context,u);break;case 3:v[b].fn.call(v[b].context,u,h);break;case 4:v[b].fn.call(v[b].context,u,h,f);break;default:if(!S)for(C=1,S=new Array(y-1);C<y;C++)S[C-1]=arguments[C];v[b].fn.apply(v[b].context,S)}}return!0},a.prototype.on=function(c,u,h){return o(this,c,u,h,!1)},a.prototype.once=function(c,u,h){return o(this,c,u,h,!0)},a.prototype.removeListener=function(c,u,h,f){var p=n?n+c:c;if(!this._events[p])return this;if(!u)return i(this,p),this;var g=this._events[p];if(g.fn)g.fn===u&&(!f||g.once)&&(!h||g.context===h)&&i(this,p);else{for(var m=0,v=[],y=g.length;m<y;m++)(g[m].fn!==u||f&&!g[m].once||h&&g[m].context!==h)&&v.push(g[m]);v.length?this._events[p]=v.length===1?v[0]:v:i(this,p)}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})(Nj);var $Z=Nj.exports;const FZ=wi($Z),xl="TLDRAW_TAB_ID_v2",go=globalThis.window;function NZ(){return go?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(go.navigator.platform)||Ge.isDarwin&&"ontouchend"in document:!1}const Lp=go?go[xl]??YT(xl)??"TLDRAW_INSTANCE_STATE_V1_"+ze():"<error>";go&&(go[xl]=Lp,NZ()?I0(xl,Lp):XT(xl));go==null||go.addEventListener("beforeunload",()=>{I0(xl,Lp)});const zj={Initial:0},$g=Math.max(...Object.values(zj));function zZ(t){t.version<zj.Initial,t.version=$g}const Bj=Pe({version:pe,currentPageId:Nu.optional(),isFocusMode:we.optional(),exportBackground:we.optional(),isDebugMode:we.optional(),isToolLocked:we.optional(),isGridMode:we.optional(),pageStates:Wt(Pe({pageId:Nu,camera:Pe({x:pe,y:pe,z:pe}).optional(),selectedShapeIds:Wt(Ir).optional(),focusedGroupId:Ir.nullable().optional()})).optional()});function BZ(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!==$g&&(t=nt(t),zZ(t));try{return Bj.validate(t)}catch(e){return console.warn(e),null}}function Sb(t){const e=t.query.ids("page");return G("sessionStateSnapshot",()=>{const n=t.get(bn);if(!n)return null;const r=[...e.get()];return{version:$g,currentPageId:n.currentPageId,exportBackground:n.exportBackground,isFocusMode:n.isFocusMode,isDebugMode:n.isDebugMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,pageStates:r.map(s=>{const o=t.get(Qr.createId(s)),i=t.get(Is.createId(s));return{pageId:s,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:(o==null?void 0:o.selectedShapeIds)??[],focusedGroupId:(o==null?void 0:o.focusedGroupId)??null}})}},{isEqual:hA})}function Px(t,e,n){const r=BZ(e);if(!r)return;const s=kA(t.get(bn)),o=n!=null&&n.forceOverwrite?r:s,i=n!=null&&n.forceOverwrite?s:r,a=t.schema.types.instance.create({id:bn,...s,currentPageId:r.currentPageId,isDebugMode:(o==null?void 0:o.isDebugMode)??(i==null?void 0:i.isDebugMode),isFocusMode:(o==null?void 0:o.isFocusMode)??(i==null?void 0:i.isFocusMode),isToolLocked:(o==null?void 0:o.isToolLocked)??(i==null?void 0:i.isToolLocked),isGridMode:(o==null?void 0:o.isGridMode)??(i==null?void 0:i.isGridMode),exportBackground:(o==null?void 0:o.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 f=Is.createId(h.pageId),p=Qr.createId(h.pageId),g=t.get(f),m=t.get(p);t.put([Is.create({id:f,x:((l=h.camera)==null?void 0:l.x)??(g==null?void 0:g.x),y:((c=h.camera)==null?void 0:c.y)??(g==null?void 0:g.y),z:((u=h.camera)==null?void 0:u.z)??(g==null?void 0:g.z)}),Qr.create({id:p,pageId:h.pageId,selectedShapeIds:h.selectedShapeIds??(m==null?void 0:m.selectedShapeIds),focusedGroupId:h.focusedGroupId??(m==null?void 0:m.focusedGroupId)})])}t.put([a]),t.ensureStoreIsUsable()})}function UZ(t){var s;const e=[];for(const o of Object.values(t))(s=o.typeName)!=null&&s.match(/^(instance.*|pointer|camera)$/)&&e.push(o);const n=e.filter(o=>o.typeName==="instance"&&o.id!==bn)[0];if(!n)return null;const r={version:$g,currentPageId:n.currentPageId,exportBackground:!!n.exportBackground,isFocusMode:!!n.isFocusMode,isDebugMode:!!n.isDebugMode,isToolLocked:!!n.isToolLocked,isGridMode:!1,pageStates:e.filter(o=>o.typeName==="instance_page_state"&&o.instanceId===n.id).map(o=>{const i=t[o.cameraId]??{x:0,y:0,z:1};return{pageId:o.pageId,camera:{x:i.x,y:i.y,z:i.z},selectedShapeIds:o.selectedShapeIds,focusedGroupId:o.focusedGroupId}})};try{return Bj.validate(r),r}catch{return null}}function Uj(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:au(i.value,(a,{typeName:l})=>t.scopedTypes.document.has(l))}}else r=e;const s=kA(t.get(bn)),o=Hj.get(t,Sb).get();t.atomic(()=>{r.document&&t.loadStoreSnapshot(r.document),s&&t.update(bn,i=>({...i,...s})),o&&Px(t,o),r.session&&Px(t,r.session,{forceOverwrite:n==null?void 0:n.forceOverwriteSessionState})})}const Hj=new Ds;function HZ(t){const n=Hj.get(t,Sb).get();if(!n)throw new Error("Session state is not ready yet");return{document:t.getStoreSnapshot(),session:n}}function Kj(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 mi({children:t,className:e="",...n}){return d.jsx("svg",{...n,className:ce("tl-svg-container",e),children:t})}function vb(t,e,n,r){const s=t.x-n.x,o=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*o-a*s,h=l*o-c*s,f=a*l-i*c;if(u===0||h===0||f===0)return null;if(f!==0){const p=u/f,g=h/f;if(0<=p&&p<=1&&0<=g&&g<=1)return x.AddXY(t,p*l,p*c)}return null}function pd(t,e,n,r){const s=(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y),o=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=o*o-4*s*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-o+l)/(2*s),u=(-o-l)/(2*s);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 KZ(t,e,n){const r=[];let s;for(let o=0,i=n.length-1;o<i;o++)s=vb(t,e,n[o],n[o+1]),s&&r.push(s);return r.length===0?null:r}function xb(t,e,n){const r=[];let s;for(let o=1,i=n.length;o<i+1;o++)s=vb(t,e,n[o-1],n[o%n.length]),s&&r.push(s);return r.length===0?null:r}function WZ(t,e,n,r){let s=n.x-t.x,o=n.y-t.y;const i=Math.sqrt(s*s+o*o),a=(i*i-r*r+e*e)/(2*i),l=Math.sqrt(e*e-a*a);return s/=i,o/=i,[new x(t.x+s*a-o*l,t.y+o*a+s*l),new x(t.x+s*a+o*l,t.y+o*a-s*l)]}function Cx(t,e,n){const r=[];let s,o,i;for(let a=0,l=n.length;a<l;a++)s=n[a],o=n[(a+1)%n.length],i=pd(s,o,t,e),i&&r.push(...i);return r.length===0?null:r}function vI(t,e,n){const r=[];let s,o,i;for(let a=1,l=n.length;a<l;a++)s=n[a-1],o=n[a],i=pd(s,o,t,e),i&&r.push(...i);return r.length===0?null:r}function gh(t,e,n){return(n.y-t.y)*(e.x-t.x)>(e.y-t.y)*(n.x-t.x)}function wb(t,e,n,r){return gh(t,n,r)!==gh(e,n,r)&&gh(t,e,n)!==gh(t,e,r)}function xI(t,e){const n=new Map;let r,s,o,i;for(let a=0,l=t.length;a<l;a++)if(r=t[a],hr(r,e)){const c=Xy(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=Xy(r);n.has(c)||n.set(c,r)}for(let a=0,l=t.length;a<l;a++){r=t[a],s=t[(a+1)%t.length];for(let c=0,u=e.length;c<u;c++){o=e[c],i=e[(c+1)%e.length];const h=vb(r,s,o,i);if(h!==null){const f=Xy(h);n.has(f)||n.set(f,h)}}}return n.size===0?null:GZ([...n.values()])}function Xy(t){return`${t.x},${t.y}`}function GZ(t){const e=x.Average(t);return t.sort((n,r)=>x.Angle(e,n)-x.Angle(e,r))}function bb(t,e){let n,r,s,o;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(s=e[l],o=e[(l+1)%c],wb(n,r,s,o))return!0}return!1}function VZ(t,e){let n,r,s,o;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(s=e[l-1],o=e[l],wb(n,r,s,o))return!0}return!1}class co extends Mi{constructor(n){super({...n,isClosed:!1,isFilled:!1});I(this,"start");I(this,"end");I(this,"d");I(this,"u");I(this,"ul");const{start:r,end:s}=n;this.start=r,this.end=s,this.d=r.clone().sub(s),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:s,d:o,u:i,ul:a}=this;if(o.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,s.x))return r.x<s.x?r:s;if(c>Math.max(r.x,s.x))return r.x>s.x?r:s;const u=r.y+i.y*l;return u<Math.min(r.y,s.y)?r.y<s.y?r:s:u>Math.max(r.y,s.y)?r.y>s.y?r:s:new x(c,u)}hitTestLineSegment(n,r,s=0){return wb(n,r,this.start,this.end)||this.distanceToLineSegment(n,r)<=s}getSvgPathData(n=!0){const{start:r,end:s}=this;return`${n?`M${r.toFixed()}`:""} L${s.toFixed()}`}}class nc extends Mi{constructor(n){super({isClosed:!1,isFilled:!1,...n});I(this,"points");I(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:n}=this;for(let r=0,s=n.length-1;r<s;r++){const o=n[r],i=n[r+1];this._segments.push(new co({start:o,end:i}))}this.isClosed&&this._segments.push(new co({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 s=this.points[0],o=1/0,i,a;for(let l=0;l<r.length;l++)i=r[l].nearestPoint(n),a=x.Dist2(i,n),a<o&&(s=i,o=a);if(!s)throw Error("nearest point not found");return s}hitTestLineSegment(n,r,s=0){const{segments:o}=this;for(let i=0,a=o.length;i<a;i++)if(o[i].hitTestLineSegment(n,r,s))return!0;return!1}getSvgPathData(){const{vertices:n}=this;return n.length<2?"":n.reduce((r,s,o)=>o===0?`M ${s.x} ${s.y}`:`${r} L ${s.x} ${s.y}`,"")}}class vt extends nc{constructor(e){super({...e}),this.isClosed=!0}}class Fs extends vt{constructor(n){const{x:r=0,y:s=0,width:o,height:i}=n;super({...n,points:[new x(r,s),new x(r+o,s),new x(r+o,s+i),new x(r,s+i)]});I(this,"x");I(this,"y");I(this,"w");I(this,"h");this.x=r,this.y=s,this.w=o,this.h=i}getBounds(){return new Z(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:n,y:r,w:s,h:o}=this;return`M${n},${r} h${s} v${o} h-${s}z`}}class ss{constructor(e){this.editor=e}canSnap(e){return!0}canScroll(e){return!1}canBind(e){return!0}canEdit(e){return!1}canResize(e){return!0}canEditInReadOnly(e){return!1}canCrop(e){return!1}canBeLaidOut(e){return!0}providesBackgroundForChildren(e){return!1}hideResizeHandles(e){return!1}hideRotateHandle(e){return!1}hideSelectionBoundsBg(e){return!1}hideSelectionBoundsFg(e){return!1}isAspectRatioLocked(e){return!1}canReceiveNewChildrenOfType(e,n){return!1}canDropShapes(e,n){return!1}expandSelectionOutlinePx(e){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(e){return{}}getHandleSnapGeometry(e){return{}}getText(e){}}I(ss,"props"),I(ss,"migrations"),I(ss,"type");function qr(t,e,n={}){const{closed:r=!1,snap:s=1,start:o="outset",end:i="outset",lengthRatio:a=2,style:l="dashed",forceSolid:c=!1}=n;let u=0,h=0,f=1,p=0,g=0;if(c)return{strokeDasharray:"none",strokeDashoffset:"none"};switch(l){case"dashed":{f=1,u=Math.min(e*a,t/4);break}case"dotted":{f=100,u=e/f;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(o==="outset"?(t+=u/2,g+=u/2):o==="skip"&&(t-=u,g-=u),i==="outset"?t+=u/2:i==="skip"&&(t-=u)),h=Math.floor(t/u/(2*f)),h-=h%s,h<3&&l==="dashed"?t/e<4?(u=t,h=1,p=0):(u=t*(1/3),p=t*(1/3)):(u=t/h/(2*f),r?(g=u/2,p=(t-h*u)/h):p=(t-h*u)/Math.max(1,h-1)),{strokeDasharray:[u,p].join(" "),strokeDashoffset:g.toString()}}function wI({bounds:t,className:e}){const n=z(),r=U("zoom level",()=>n.getZoomLevel(),[n]);return d.jsx("g",{className:e,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:t.sides.map((s,o)=>{const{strokeDasharray:i,strokeDashoffset:a}=qr(s[0].dist(s[1]),1/r,{style:"dashed",lengthRatio:4});return d.jsx("line",{x1:s[0].x,y1:s[0].y,x2:s[1].x,y2:s[1].y,strokeDasharray:i,strokeDashoffset:a},o)})})}class uf extends ss{hideSelectionBoundsFg(){return!0}canBind(){return!1}getDefaultProps(){return{}}getGeometry(e){const n=this.editor.getSortedChildIdsForParent(e.id);return n.length===0?new Fs({width:1,height:1,isFilled:!1}):new $r({children:n.map(r=>{const s=this.editor.getShape(r),o=this.editor.getShapeGeometry(r),i=this.editor.getShapeLocalTransform(s).applyToPoints(o.vertices);return o.isClosed?new vt({points:i,isFilled:!0}):new nc({points:i})})})}component(e){const n=this.editor.getErasingShapeIds().includes(e.id),{hintingShapeIds:r}=this.editor.getCurrentPageState(),s=r.length>0&&r.some(a=>a!==e.id&&this.editor.isShapeOfType(this.editor.getShape(a),"group")),o=this.editor.getCurrentPageState().focusedGroupId!==e.id;if(!n&&(o||s))return null;const i=this.editor.getShapeGeometry(e).bounds;return d.jsx(mi,{children:d.jsx(wI,{className:"tl-group",bounds:i})})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx(wI,{className:"",bounds:n})}onChildrenChange(e){const n=this.editor.getSortedChildIdsForParent(e.id);if(n.length===0){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([e.id]);return}else if(n.length===1){this.editor.getCurrentPageState().focusedGroupId===e.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(n,e.parentId),this.editor.deleteShapes([e.id]);return}}}I(uf,"type","group"),I(uf,"props",zA),I(uf,"migrations",BA);const Wj=[uf],YZ=new Set(Wj.map(t=>t.type));function Gj(t){const e=[...Wj],n=new Set;for(const r of t){if(YZ.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 Vj(t,e){const n=new Map;return async function(s){const o=n.get(s);if(o)return o;const i=(async()=>{try{const a=await Rs(s,e);return Le(a.ok),await t(a)}catch(a){return console.error(a),null}})();return n.set(s,i),i}}const Fg=Vj(async t=>await Zr.blobToDataUrl(await t.blob())),XZ=/@import\s+(?:"([^"]+)"|'([^']+)'|url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\))([^;]+);/gi,qZ=/@font-face\s*{([^}]+)}/gi,Yj=/url\s*\(\s*(?:"([^"]+)"|'([^']+)'|([^'")]+))\s*\)/gi,ZZ=/(?:^|;)\s*font-family\s*:\s*(?:([^'"][^;\n]+)|"([^"]+)"|'([^']+)')\s*(?:;|$)/gi;function QZ(t){return Array.from(t.matchAll(XZ),e=>({url:e[1]||e[2]||e[3]||e[4]||e[5],extras:e[6]}))}function Xj(t,e){return Array.from(t.matchAll(qZ),n=>{const r=n[1],s=Array.from(r.matchAll(Yj),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}}),o=new Set(Array.from(r.matchAll(ZZ),i=>(i[1]||i[2]||i[3]).toLowerCase()));return{fontFace:r,urls:s,fontFamilies:o}})}function JZ(t){const e=/\s*(?:([^'"][^;\n\s,]+)|"([^"]+)"|'([^']+)')\s*/gi,n=/\s*,\s*/gi,r=new Set;for(;;){const s=e.exec(t);if(!s)break;const o=s[1]||s[2]||s[3];if(r.add(o.toLowerCase()),n.lastIndex=e.lastIndex,!n.exec(t))break;e.lastIndex=n.lastIndex}return r}function qj(t){return!(t.startsWith("-")||t.startsWith("animation")||t.startsWith("transition")||t==="cursor"||t==="pointer-events"||t==="user-select"||t==="touch-action")}function eQ(t,e){return{imports:QZ(t),fontFaces:Xj(t,e)}}function tQ(t){return Array.from(t.matchAll(Yj),e=>({original:e[0],url:e[1]||e[2]||e[3]}))}const nQ=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 Zj(t){return nQ.has(t)}var rQ=Object.create,Qj=Object.defineProperty,sQ=Object.getOwnPropertyDescriptor,oQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Jj=t=>{throw TypeError(t)},eO=(t,e,n)=>e in t?Qj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,iQ=t=>[,,,rQ(null)],tO=["class","method","getter","setter","accessor","field","value","get","set"],nO=t=>t!==void 0&&typeof t!="function"?Jj("Function expected"):t,aQ=(t,e,n,r,s)=>({kind:tO[t],name:e,metadata:r,addInitializer:o=>n._?Jj("Already initialized"):s.push(nO(o||null))}),lQ=(t,e)=>eO(e,oQ("metadata"),t[3]),cQ=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},uQ=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=tO[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,sQ(s,n)),y=r.length-1;y>=0;y--)l=aQ(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,nO(i)&&(v[g]=i);return v&&Qj(s,n,v),s},mh=(t,e,n)=>eO(t,typeof e!="symbol"?e+"":e,n),rO,Ng;rO=[Kn];class Pb{constructor(){cQ(Ng,5,this),mh(this,"fontFacesPromise",null),mh(this,"foundFontNames",new Set),mh(this,"fontFacesToEmbed",new Set),mh(this,"pendingPromises",[])}startFindingCurrentDocumentFontFaces(){Le(!this.fontFacesPromise,"FontEmbedder already started"),this.fontFacesPromise=dQ()}onFontFamilyValue(e){Le(this.fontFacesPromise,"FontEmbedder not started");const n=JZ(e);for(const r of n){if(this.foundFontNames.has(r))return;this.foundFontNames.add(r),this.pendingPromises.push(this.fontFacesPromise.then(s=>{const o=s.filter(i=>i.fontFamilies.has(r));for(const i of o)if(!this.fontFacesToEmbed.has(i)){this.fontFacesToEmbed.add(i);for(const a of i.urls)!a.resolved||a.embedded||(a.embedded=Fg(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 s of n.urls){if(!s.embedded)continue;const o=await s.embedded;o&&(r=r.replace(s.original,o))}e+=r}return e}}Ng=iQ();uQ(Ng,1,"onFontFamilyValue",rO,Pb);lQ(Ng,Pb);async function dQ(){var e;const t=[];for(const n of document.styleSheets){let r;try{r=n.cssRules}catch{}if(r){for(const s of n.cssRules)if(s instanceof CSSFontFaceRule)t.push(Xj(s.cssText,n.href??document.baseURI));else if(s instanceof CSSImportRule){const o=new URL(s.href,((e=s.parentStyleSheet)==null?void 0:e.href)??document.baseURI);t.push(_x(o.href))}}else n.href&&t.push(_x(n.href))}return me(await Promise.all(t)).flat()}const _x=Vj(async t=>{const e=eQ(await t.text(),t.url),n=await Promise.all(e.imports.map(({url:r})=>_x(new URL(r,t.url).href)));return[...e.fontFaces,...me(n).flat()]});function sO(t){if(t.shadowRoot)return t.shadowRoot.childNodes;if(gQ(t)){const e=t.assignedNodes();if(e!=null&&e.length)return e}return t.childNodes}function*Ix(t){for(const e of sO(t))hQ(e)&&(yield e)}function zg(t){var e;return((e=t.ownerDocument)==null?void 0:e.defaultView)??globalThis}function hQ(t){return t instanceof zg(t).Element}function fQ(t){return t instanceof zg(t).ShadowRoot}function pQ(t){return"getRootNode"in t&&fQ(t.getRootNode())}function gQ(t){return pQ(t)&&t instanceof zg(t).HTMLSlotElement}function mQ(t){return t.style}function Cb(t,e){return zg(t).getComputedStyle(t,e)}const ta={};class yQ{constructor(e){I(this,"styles",new Map);I(this,"fonts",new Pb);this.root=e}readRootElementStyles(e){this.readElementStyles(e,{shouldRespectDefaults:!1,shouldSkipInheritedParentStyles:!1});const n=Array.from(Ix(e));for(;n.length;){const r=n.pop();n.push(...Ix(r)),this.readElementStyles(r,{shouldRespectDefaults:!0,shouldSkipInheritedParentStyles:!0})}}readElementStyles(e,{shouldRespectDefaults:n=!0,shouldSkipInheritedParentStyles:r=!0}){var a;const s=n?wQ(e.tagName.toLowerCase()):ta,o=r?((a=this.styles.get(e.parentElement))==null?void 0:a.self)??ta:ta,i={self:SQ(e,{defaultStyles:s,parentStyles:o}),before:bI(e,"::before"),after:bI(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[s,o]of Object.entries(r)){if(!o)continue;s==="font-family"&&this.fonts.onFontFamilyValue(o);const i=tQ(o);i.length!==0&&e.push(...i.map(async({url:a,original:l})=>{const c=await Fg(a)??"data:";r[s]=o.replace(l,`url("${c}")`)}))}return Promise.all(e)}unwrapCustomElements(){const e=new Set,n=(r,s)=>{if(e.has(r))return;e.add(r);const o=r.shadowRoot;if(o){const i=document.createElement("div");this.styles.set(i,this.styles.get(r)),i.setAttribute("data-tl-custom-element",r.tagName),(s??r.parentElement).appendChild(i);for(const a of o.childNodes)a instanceof Element?n(a,i):i.appendChild(a.cloneNode(!0));r.remove()}else if(s){if(r.tagName.toLowerCase()==="style")return;const i=r.cloneNode(!1);this.styles.set(i,this.styles.get(r)),s.appendChild(i);for(const a of sO(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 o=`pseudo-${ze()}`;n.classList.add(o),r.before&&(e+=`.${o}::before {${PI(r.before)}}
|
|
99
|
+
`),r.after&&(e+=`.${o}::after {${PI(r.after)}}
|
|
100
|
+
`)}const s=mQ(n);for(const[o,i]of Object.entries(r.self))i&&s.setProperty(o,i);s.fontKerning==="auto"&&(s.fontKerning="normal")}return e}async getFontFaceCss(){return await this.fonts.createCss()}dispose(){xQ()}}function SQ(t,{defaultStyles:e,parentStyles:n}){return t.computedStyleMap?oO(t.computedStyleMap(),{defaultStyles:e,parentStyles:n}):_b(Cb(t),{defaultStyles:e,parentStyles:n})}function bI(t,e){const n=Cb(t,e),r=n.getPropertyValue("content");if(!(r===""||r==="none"))return _b(n,{defaultStyles:ta,parentStyles:ta})}function oO(t,{defaultStyles:e,parentStyles:n}){const r={};for(const s of t.keys()){if(!qj(s))continue;const o=t.get(s).toString();e[s]!==o&&(n[s]===o&&Zj(s)||(r[s]=o))}return r}function _b(t,{defaultStyles:e,parentStyles:n}){const r={};for(const s of t){if(!qj(s))continue;const o=t.getPropertyValue(s);e[s]!==o&&(n[s]===o&&Zj(s)||(r[s]=o))}return r}function PI(t){let e="";for(const[n,r]of Object.entries(t))e+=`${n}: ${r};`;return e}let wl;const CI={};function vQ(){if(!wl){const t=document.createElement("iframe");t.style.display="none",document.body.appendChild(t);const e=zn(t.contentDocument,"frame must have a document"),n=document.createElementNS("http://www.w3.org/2000/svg","svg"),r=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");n.appendChild(r),e.body.appendChild(n),wl={iframe:t,foreignObject:r,document:e}}return wl}function xQ(){wl&&(document.body.removeChild(wl.iframe),wl=void 0)}const _I={defaultStyles:ta,parentStyles:ta};function wQ(t){let e=CI[t];if(!e){const{foreignObject:n,document:r}=vQ(),s=r.createElement(t);n.appendChild(s),e=s.computedStyleMap?oO(s.computedStyleMap(),_I):_b(Cb(s),_I),n.removeChild(s),CI[t]=e}return e}function bQ(t,e){Array.from(t.attributes).forEach(r=>{e.setAttribute(r.name,r.value)})}function II(t,e){return t.replaceWith(e),e}async function uu(t,e){const n=document.createElement("img");e&&bQ(e,n),n.setAttribute("src",t??"data:"),n.setAttribute("decoding","sync"),n.setAttribute("loading","eager");try{await n.decode()}catch{}return n}async function PQ(t){try{const e=t.toDataURL();return await uu(e,t)}catch{return await uu(null,t)}}async function CQ(t){try{const e=await ar.getVideoFrameAsDataUrl(t);return uu(e,t)}catch(e){console.error("Could not get video frame",e)}if(t.poster){const e=await Fg(t.poster);return uu(e,t)}return uu(null,t)}async function iO(t){if(t instanceof HTMLCanvasElement)return II(t,await PQ(t));if(t instanceof HTMLVideoElement)return II(t,await CQ(t));if(t instanceof HTMLImageElement){const e=t.currentSrc||t.src,n=await Fg(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(Ix(t),e=>iO(e)))}function Bg(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 Ib=w.createContext(null);function _Q({context:t,editor:e,children:n}){const r=e.options.exportProvider;return d.jsx(ub,{editor:e,children:d.jsx(lj,{container:e.getContainer(),children:d.jsx(Ib.Provider,{value:t,children:d.jsx(r,{children:n})})})})}function gd(){return w.useContext(Ib)}function IQ(){const t=w.useContext(Ib),[e]=w.useState(m0);return w.useEffect(()=>(t==null||t.waitUntil(e),()=>{e.resolve()}),[e,t]),Bg(()=>{e.resolve()})}var EQ=Object.create,aO=Object.defineProperty,kQ=Object.getOwnPropertyDescriptor,TQ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),lO=t=>{throw TypeError(t)},cO=(t,e,n)=>e in t?aO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,MQ=t=>[,,,EQ(null)],uO=["class","method","getter","setter","accessor","field","value","get","set"],dO=t=>t!==void 0&&typeof t!="function"?lO("Function expected"):t,AQ=(t,e,n,r,s)=>({kind:uO[t],name:e,metadata:r,addInitializer:o=>n._?lO("Already initialized"):s.push(dO(o||null))}),jQ=(t,e)=>cO(e,TQ("metadata"),t[3]),OQ=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},DQ=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=uO[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,kQ(s,n)),y=r.length-1;y>=0;y--)l=AQ(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,dO(i)&&(v[g]=i);return v&&aO(s,n,v),s},EI=(t,e,n)=>cO(t,typeof e!="symbol"?e+"":e,n),hO,Ug;hO=[Kn];class Eb{constructor(e){this.maxDelayTimeMs=e,OQ(Ug,5,this),EI(this,"isResolved",!1),EI(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 Hv(0)}async resolve(){const e=Hv(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}}Ug=MQ();DQ(Ug,1,"waitUntil",hO,Eb);jQ(Ug,Eb);function RQ(t,e,n={}){var y,S;if(!window.document)throw Error("No document");const{scale:r=1,background:s=!1,padding:o=t.options.defaultSvgPadding,preserveAspectRatio:i}=n,a=n.darkMode??t.user.getIsDarkMode(),l=t.getShapeAndDescendantIds(e),c=t.getUnorderedRenderingShapes(!1).filter(({id:b})=>l.has(b));let u=null;if(n.bounds)u=n.bounds;else for(const{id:b}of c){const P=t.getShapeMaskedPageBounds(b);P&&(u?u.union(P):u=P.clone())}if(!u)return;const h=e.length===1&&t.isShapeOfType(t.getShape(e[0]),"frame")?e[0]:null;h||u.expandBy(o);const f=u.width*r,p=u.height*r;try{(S=(y=document.body).focus)==null||S.call(y)}catch{}const g=new Eb(t.options.maxExportDelayMs),m=m0();return g.waitUntil(m),{jsx:d.jsx(LQ,{editor:t,preserveAspectRatio:i,scale:r,bbox:u,background:s,singleFrameShapeId:h,isDarkMode:a,renderingShapes:c,onMount:m.resolve,waitUntil:g.waitUntil}),width:f,height:p,exportDelay:g}}function LQ({editor:t,preserveAspectRatio:e,scale:n,bbox:r,background:s,singleFrameShapeId:o,isDarkMode:i,renderingShapes:a,onMount:l,waitUntil:c}){const u=Jl(),h=ko({isDarkMode:i}),f=V0("export state",{defsById:{},shapeElements:null}),{defsById:p,shapeElements:g}=U(f),m=Bg(S=>{f.update(b=>{if(ns(b.defsById,S.key))return b;const P=Promise.resolve(S.getElement());return c(P.then(C=>{f.update(_=>({..._,defsById:{..._.defsById,[S.key]:{pending:!1,element:C}}}))})),{...b,defsById:{...b.defsById,[S.key]:{pending:!0,element:P}}}})}),v=w.useMemo(()=>({isDarkMode:i,waitUntil:c,addExportDef:m}),[i,c,m]),y=w.useRef(!1);return w.useLayoutEffect(()=>{if(y.current)throw new Error("SvgExport should only render once - do not use with react strict mode");y.current=!0,(async()=>{const S={},b=a.map(async({id:C,opacity:_,index:E,backgroundIndex:k})=>{var L,M;if(C===o)return[];const D=t.getShape(C);if(t.isShapeOfType(D,"group"))return[];const T=[],j=t.getShapeUtil(D);if(j.toSvg||j.toBackgroundSvg){const[O,F]=await Promise.all([(L=j.toSvg)==null?void 0:L.call(j,D,v),(M=j.toBackgroundSvg)==null?void 0:M.call(j,D,v)]),B=t.getShapePageTransform(D);let K=B.toCssString(),R=1;"scale"in D.props&&D.props.scale!==1&&(R=D.props.scale,K=`${K} scale(${D.props.scale}, ${D.props.scale})`);const H=t.getShapeMask(D.id),X=H?q.From(q.Inverse(B)).applyToPoints(H):null,te=lb(u,D.id);X&&(S[te]={pending:!1,element:d.jsx("clipPath",{id:te,children:d.jsx("path",{d:`M${X.map(({x:le,y:de})=>`${le/R},${de/R}`).join("L")}Z`})})}),O&&T.push({zIndex:E,element:d.jsx("g",{transform:K,opacity:_,clipPath:H?`url(#${te})`:void 0,children:O},`fg_${D.id}`)}),F&&T.push({zIndex:k,element:d.jsx("g",{transform:K,opacity:_,clipPath:H?`url(#${te})`:void 0,children:F},`bg_${D.id}`)})}else T.push({zIndex:E,element:d.jsx(kI,{shape:D,util:j,component:bj,className:"tl-shape",bbox:r,opacity:_},`fg_${D.id}`)}),j.backgroundComponent&&T.push({zIndex:k,element:d.jsx(kI,{shape:D,util:j,component:Pj,className:"tl-shape tl-shape-background",bbox:r,opacity:_},`bg_${D.id}`)});return T}),P=(await Promise.all(b)).flat();ba.flushSync(()=>{f.update(C=>({...C,shapeElements:P.sort((_,E)=>_.zIndex-E.zIndex).map(({element:_})=>_),defsById:{...C.defsById,...S}}))})})()},[r,t,v,u,a,o,f]),w.useEffect(()=>{g!==null&&l()},[l,g]),d.jsx(_Q,{editor:t,context:v,children:d.jsxs("svg",{preserveAspectRatio:e,direction:"ltr",width:r.width*n,height:r.height*n,viewBox:`${r.minX} ${r.minY} ${r.width} ${r.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?o?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(([S,b])=>b.pending?null:d.jsx(w.Fragment,{children:b.element},S))}),g]})})}function kI({shape:t,util:e,className:n,component:r,bbox:s,opacity:o}){const i=z(),a=q.Translate(-s.minX,-s.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(ab,{fallback:()=>null,children:d.jsx("foreignObject",{x:s.minX,y:s.minY,width:s.w,height:s.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:o},children:d.jsx(r,{shape:t,util:e})})})})}let $Q=1;async function FQ(t,e,n={}){const r=RQ(t,e,n);if(!r)return;const s=t.getContainer(),o=document.createElement("div");o.className="tldraw-svg-export",o.inert=!0,o.tabIndex=-1,Object.assign(o.style,{position:"absolute",top:"0px",left:"0px",width:r.width+"px",height:r.height+"px",pointerEvents:"none",opacity:0}),s.appendChild(o);const i=bT(o,{identifierPrefix:`export_${$Q++}_`});try{await Promise.resolve(),ba.flushSync(()=>{i.render(r.jsx)}),await r.exportDelay.resolve();const a=o.firstElementChild;return Le(a instanceof SVGSVGElement,"Expected an SVG element"),await NQ(a),{svg:a,width:r.width,height:r.height}}finally{setTimeout(()=>{i.unmount(),s.removeChild(o)},0)}}async function NQ(t){const e=[...t.querySelectorAll("foreignObject.tl-shape-foreign-object > *")];if(!e.length)return;const n=new yQ(t);try{n.fonts.startFindingCurrentDocumentFontFaces(),await Promise.all(e.map(o=>iO(o)));for(const o of e)n.readRootElementStyles(o);await n.fetchResources();const r=await n.getFontFaceCss();n.unwrapCustomElements();const s=n.embedStyles();if(r||s){const o=document.createElementNS("http://www.w3.org/2000/svg","style");o.textContent=`${r}
|
|
101
|
+
${s}`,t.prepend(o)}}finally{n.dispose()}}const Vr={menus:It("open menus",[]),getOpenMenus(t){return t?this.menus.get().filter(e=>e.endsWith("-"+t)):this.menus.get()},addOpenMenu(t,e=""){const n=e?`${t}-${e}`:t,r=new Set(this.menus.get());r.has(n)||(r.add(n),this.menus.set([...r]))},deleteOpenMenu(t,e=""){const n=e?`${t}-${e}`:t,r=new Set(this.menus.get());r.has(n)&&(r.delete(n),this.menus.set([...r]))},clearOpenMenus(t){this.menus.set(t?this.menus.get().filter(e=>!e.endsWith("-"+t)):[])},_hiddenMenus:[],hideOpenMenus(t){if(this._hiddenMenus=[...this.getOpenMenus(t)],this._hiddenMenus.length!==0)for(const e of this._hiddenMenus)this.deleteOpenMenu(e,t)},showOpenMenus(t){if(this._hiddenMenus.length!==0){for(const e of this._hiddenMenus)this.addOpenMenu(e,t);this._hiddenMenus=[]}},isMenuOpen(t,e){return this.getOpenMenus(e).includes(t)},hasOpenMenus(t){return this.getOpenMenus(t).length>0},hasAnyOpenMenus(){return this.getOpenMenus().length>0},forContext(t){return{getOpenMenus:()=>this.getOpenMenus(t),addOpenMenu:e=>this.addOpenMenu(e,t),deleteOpenMenu:e=>this.deleteOpenMenu(e,t),clearOpenMenus:()=>this.clearOpenMenus(t),isMenuOpen:e=>this.isMenuOpen(e,t),hasOpenMenus:()=>this.hasOpenMenus(t),hasAnyOpenMenus:()=>this.hasAnyOpenMenus()}}},Ex=new dB,zQ={maxShapesPerPage:4e3,maxFilesAtOnce:100,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,defaultSvgPadding:32,cameraSlideFriction:.09,maxPointsPerDrawShape:500,gridSteps:[{min:-1,mid:.15,step:64},{min:.05,mid:.375,step:16},{min:.15,mid:1,step:4},{min:.7,mid:2.5,step:1}],collaboratorInactiveTimeoutMs:6e4,collaboratorIdleTimeoutMs:3e3,collaboratorCheckIntervalMs:1200,cameraMovingTimeoutMs:64,hitTestMargin:8,edgeScrollDelay:200,edgeScrollEaseDuration:200,edgeScrollSpeed:25,edgeScrollDistance:8,coarsePointerWidth:12,coarseHandleRadius:20,handleRadius:12,longPressDurationMs:500,textShadowLod:.35,adjacentShapeMargin:10,flattenImageBoundsExpand:64,flattenImageBoundsPadding:16,laserDelayMs:1200,maxExportDelayMs:5e3,temporaryAssetPreviewLifetimeMs:18e4,actionShortcutsLocation:"swap",createTextOnCanvasDoubleClick:!0,exportProvider:w.Fragment};function TI(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 BQ{constructor(e){I(this,"map");this.map=new Map(e)}get(e){return this.map.get(e)}getAsKnownValue(e){const n=this.get(e);if(n&&n.type!=="mixed")return n.value}get size(){return this.map.size}equals(e){if(this.size!==e.size)return!1;const n=new Set;for(const[r,s]of this){if(!TI(s,e.get(r)))return!1;n.add(r)}for(const[r,s]of e)if(!n.has(r)&&!TI(s,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 kx extends BQ{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 UQ(t,e,n){return Rs(t).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],e,{type:n})})}const HQ="https://cdn.tldraw.com";function ti(){return`${HQ}/${tj}`}function KQ(t){switch(t.type){case"shapes":return`s${t.shapeIds.map(n=>qy(n.slice(6))).join(".")}`;case"page":return"p"+qy(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+="."+qy(yr.parseId(n))),r}default:Ot(t)}}function WQ(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,s,o,i]=t.slice(1).split(".");return{type:"viewport",bounds:new Z(Number(n),Number(r),Number(s),Number(o)),pageId:i?yr.createId(decodeURIComponent(i)):void 0}}default:throw Error("Invalid deep link string")}}function qy(t){return encodeURIComponent(t).replace(/\./g,"%2E")}function GQ(t,e){var s;let n=t;const r=new Set(e);for(;r.has(n);)n=(s=/^.*(\d+)$/.exec(n))!=null&&s[1]?n.replace(/(\d+)(?=\D?)$/,o=>(+o+1).toString()):`${n} 1`;return n}function yh(t,e,n,r){if(n.length===0)return[];const s=new Map;for(const i of me(n.map(a=>t.getShape(a)))){const{parentId:a}=i;s.has(a)||s.set(a,{children:me(t.getSortedChildIdsForParent(a).map(l=>t.getShape(l))),moving:new Set}),s.get(a).moving.add(i)}const o=[];switch(e){case"toBack":{s.forEach(({moving:i,children:a})=>VQ(i,a,o));break}case"toFront":{s.forEach(({moving:i,children:a})=>YQ(i,a,o));break}case"forward":{s.forEach(({moving:i,children:a})=>XQ(t,i,a,o,r));break}case"backward":{s.forEach(({moving:i,children:a})=>qQ(t,i,a,o,r));break}}return o}function VQ(t,e,n){const r=e.length;if(t.size===r)return;let s,o;for(let i=0;i<r;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=Ol(s,o,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function YQ(t,e,n){const r=e.length;if(t.size===r)return;let s,o;for(let i=r-1;i>-1;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=Ol(s,o,t.size);n.push(...Array.from(t.values()).sort(cn).map((a,l)=>({...a,index:i[l]})))}}function MI(t,e){const n=t.getShapeGeometry(e),r=t.getShapePageTransform(e);return!n||!r?null:r.applyToPoints(n.vertices)}function fO(t,e){const n=Array.from(e).map(s=>{const o=MI(t,s);return o?{shape:s,vertices:o}:null}).filter(Boolean);return s=>{const o=MI(t,s);return o?n.some(i=>bb(i.vertices,o)):!1}}function XQ(t,e,n,r,s){var l;const o=fO(t,e),i=n.length;if(e.size===i)return;let a={name:"skipping"};for(let c=0;c<i;c++){const u=e.has(n[c]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(u||!(s!=null&&s.considerAllShapes)&&!o(n[c]))continue;const{selectIndex:h}=a;Ol(n[c].index,(l=n[c+1])==null?void 0:l.index,c-h).forEach((f,p)=>{const g=n[h+p];e.has(g)&&r.push({...g,index:f})}),a={name:"skipping"};break}}}}function qQ(t,e,n,r,s){var l;const o=fO(t,e),i=n.length;if(e.size===i)return;let a={name:"skipping"};for(let c=i-1;c>-1;c--){const u=e.has(n[c]);switch(a.name){case"skipping":{if(!u)continue;a={name:"selecting",selectIndex:c};break}case"selecting":{if(u||!(s!=null&&s.considerAllShapes)&&!o(n[c]))continue;Ol((l=n[c-1])==null?void 0:l.index,n[c].index,a.selectIndex-c).forEach((h,f)=>{const p=n[c+f+1];e.has(p)&&r.push({...p,index:h})}),a={name:"skipping"};break}}}}function pO({editor:t,ids:e}){const n=me(e.map(i=>t.getShape(i))),r=t.getShapesSharedRotation(e),s=t.getShapesRotatedPageBounds(e);if(!s)return null;const o=s.center.clone().rotWith(s.point,r);return{pageCenter:o,initialCursorAngle:o.angle(t.inputs.originPagePoint),initialShapesRotation:r,shapeSnapshots:n.map(i=>({shape:i,initialPagePoint:t.getShapePageTransform(i.id).point()}))}}function df({delta:t,editor:e,snapshot:n,stage:r,centerOverride:s}){const{pageCenter:o,shapeSnapshots:i}=n;e.updateShapes(i.map(({shape:l,initialPagePoint:c})=>{const u=Fn(l.parentId)?e.getShapePageTransform(l.parentId):q.Identity(),h=x.RotWith(c,s??o,t),f=q.applyToPoint(q.Inverse(u),h),p=ea(l.rotation+t);return{id:l.id,type:l.type,x:f.x,y:f.y,rotation:p}}));const a=[];i.forEach(({shape:l})=>{var f,p,g;const c=e.getShape(l.id);if(!c)return;const u=e.getShapeUtil(l);if(r==="start"||r==="one-off"){const m=(f=u.onRotateStart)==null?void 0:f.call(u,l);m&&a.push(m)}const h=(p=u.onRotate)==null?void 0:p.call(u,l,c);if(h&&a.push(h),r==="end"||r==="one-off"){const m=(g=u.onRotateEnd)==null?void 0:g.call(u,l,c);m&&a.push(m)}}),a.length>0&&e.updateShapes(a)}const ZQ=t=>{const{store:e}=t,n=e.query.filterHistory("binding"),r=e.query.records("binding");function s(){const o=r.get(),i=new Map;for(const a of o){const{fromId:l,toId:c}=a,u=i.get(l);u?u.push(a):i.set(l,[a]);const h=i.get(c);h?h.push(a):i.set(c,[a])}return i}return G("arrowBindingsIndex",(o,i)=>{if(Qi(o))return s();const a=o,l=n.getDiffSince(i);if(l===ur)return s();let c;function u(p){c??(c=new Map(a));const g=c.get(p.fromId),m=g==null?void 0:g.filter(S=>S.id!==p.id);m!=null&&m.length?c.set(p.fromId,m):c.delete(p.fromId);const v=c.get(p.toId),y=v==null?void 0:v.filter(S=>S.id!==p.id);y!=null&&y.length?c.set(p.toId,y):c.delete(p.toId)}function h(p){c??(c=new Map(a));let g=c.get(p);return g?g===a.get(p)&&(g=g.slice(0),c.set(p,g)):(g=[],c.set(p,g)),g}function f(p){h(p.fromId).push(p),h(p.toId).push(p)}for(const p of l){for(const g of ut(p.added))f(g);for(const[g,m]of ut(p.updated))u(g),f(m);for(const g of ut(p.removed))u(g)}return c??a})};function QQ(t,e,n){const r=t.getShapeMaskedPageBounds(e);return r===void 0?!0:!n.includes(r)}const JQ=t=>{function e(n){const r=n.getCurrentPageShapeIds(),s=n.getViewportPageBounds(),o=new Set;return r.forEach(i=>{QQ(n,i,s)&&o.add(i)}),o}return G("getCulledShapes",n=>{if(Qi(n))return e(t);const r=e(t);if(n.size!==r.size)return r;for(const s of n)if(!r.has(s))return r;return n})},eJ=t=>{const e=t.query.ids("shape"),n=t.query.filterHistory("shape");function r(){const s={},o=e.get(),i=Array(o.size);return o.forEach(a=>i.push(t.get(a))),i.sort(cn),i.forEach(a=>{s[a.parentId]||(s[a.parentId]=[]),s[a.parentId].push(a.id)}),s}return G("parentsToChildrenWithIndexes",(s,o)=>{if(Qi(s))return r();const i=n.getDiffSince(o);if(i===ur)return r();if(i.length===0)return s;let a=null;const l=h=>{a||(a={...s}),a[h]?a[h]===s[h]&&(a[h]=[...a[h]]):a[h]=[]},c=new Set;let u;for(let h=0,f=i.length;h<f;h++){u=i[h];for(const p of Object.values(u.added))al(p)&&(l(p.parentId),a[p.parentId].push(p.id),c.add(a[p.parentId]));for(const[p,g]of Object.values(u.updated))if(al(g)&&al(p)){if(p.parentId!==g.parentId)l(p.parentId),l(g.parentId),a[p.parentId].splice(a[p.parentId].indexOf(g.id),1),a[g.parentId].push(g.id),c.add(a[g.parentId]);else if(p.index!==g.index){l(g.parentId);const m=a[g.parentId].indexOf(g.id);a[g.parentId][m]=g.id,c.add(a[g.parentId])}}for(const p of Object.values(u.removed))al(p)&&(l(p.parentId),a[p.parentId].splice(a[p.parentId].indexOf(p.id),1))}for(const h of c){const f=me(h.map(p=>t.get(p)));f.sort(cn),h.splice(0,h.length,...f.map(p=>p.id))}return a??s})},Zy=(t,e,n)=>{for(;!Rn(n.parentId);){const r=t.get(n.parentId);if(!r)return!1;n=r}return n.parentId===e},tJ=(t,e)=>{const n=t.query.ids("shape");let r=null;function s(){const o=e();return r=o,new Set([...n.get()].filter(i=>Zy(t,o,t.get(i))))}return G("_shapeIdsInCurrentPage",(o,i)=>{if(Qi(o))return s();const a=e();if(a!==r)return s();const l=t.history.getDiffSince(i);if(l===ur)return s();const c=new of(o);for(const h of l){for(const f of Object.values(h.added))al(f)&&Zy(t,a,f)&&c.add(f.id);for(const[f,p]of Object.values(h.updated))al(p)&&(Zy(t,a,p)?c.add(p.id):c.remove(p.id));for(const f of Object.keys(h.removed))Fn(f)&&c.remove(f)}const u=c.get();return u?Kc(u.value,u.diff):o})};var nJ=Object.create,gO=Object.defineProperty,rJ=Object.getOwnPropertyDescriptor,sJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),mO=t=>{throw TypeError(t)},yO=(t,e,n)=>e in t?gO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oJ=t=>[,,,nJ(null)],SO=["class","method","getter","setter","accessor","field","value","get","set"],vO=t=>t!==void 0&&typeof t!="function"?mO("Function expected"):t,iJ=(t,e,n,r,s)=>({kind:SO[t],name:e,metadata:r,addInitializer:o=>n._?mO("Already initialized"):s.push(vO(o||null))}),aJ=(t,e)=>yO(e,sJ("metadata"),t[3]),lJ=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},xO=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=SO[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,rJ(s,n)),y=r.length-1;y>=0;y--)l=iJ(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,vO(i)&&(v[g]=i);return v&&gO(s,n,v),s},La=(t,e,n)=>yO(t,typeof e!="symbol"?e+"":e,n),wO,bO,md;const cJ=40;bO=[Kn],wO=[Kn];class Hg{constructor(e){this.editor=e,lJ(md,5,this),La(this,"_clickId",""),La(this,"_clickTimeout"),La(this,"_clickScreenPoint"),La(this,"_previousScreenPoint"),La(this,"_clickState","idle"),La(this,"lastPointerInfo",{})}_getClickTimeout(e,n=ze()){this._clickId=n,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===e&&this._clickId===n){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},e==="idle"||e==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)}get clickState(){return this._clickState}handlePointerEvent(e){switch(e.name){case"pointer_down":{if(!this._clickState)return e;switch(this._clickScreenPoint=x.From(e.point),this._previousScreenPoint&&x.Dist2(this._previousScreenPoint,this._clickScreenPoint)>cJ**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"}}md=oJ();xO(md,1,"_getClickTimeout",bO,Hg);xO(md,1,"cancelDoubleClickTimeout",wO,Hg);aJ(md,Hg);class uJ{constructor(e){I(this,"_isEdgeScrolling",!1);I(this,"_edgeScrollDuration",-1);this.editor=e}updateEdgeScrolling(e){const{editor:n}=this,r=this.getEdgeScroll();if(r.x===0&&r.y===0)this._isEdgeScrolling&&(this._isEdgeScrolling=!1,this._edgeScrollDuration=0);else if(this._isEdgeScrolling||(this._isEdgeScrolling=!0,this._edgeScrollDuration=0),this._edgeScrollDuration+=e,this._edgeScrollDuration>n.options.edgeScrollDelay){const s=n.options.edgeScrollEaseDuration>0?Dt.easeInCubic(Math.min(1,this._edgeScrollDuration/(n.options.edgeScrollDelay+n.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*s,y:r.y*s})}}getEdgeProximityFactors(e,n,r,s,o){const{editor:i}=this,a=i.options.edgeScrollDistance,l=r?i.options.coarsePointerWidth:0,c=e-l,u=e+l,h=s?0:a,f=o?n:n-a;return c<h?Math.min(1,(h-c)/a):u>f?-Math.min(1,(u-f)/a):0}getEdgeScroll(){const{editor:e}=this,{inputs:{currentScreenPoint:{x:n,y:r}}}=e,s=e.getViewportScreenBounds(),{isCoarsePointer:o,insets:[i,a,l,c]}=e.getInstanceState(),u=this.getEdgeProximityFactors(n,s.w,o,c,a),h=this.getEdgeProximityFactors(r,s.h,o,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(),s=r.w<1e3?.612:1,o=r.h<1e3?.612:1,i=n.getZoomLevel(),a=n.user.getEdgeScrollSpeed()*n.options.edgeScrollSpeed,l=a*e.x*s/i,c=a*e.y*o/i,{x:u,y:h,z:f}=n.getCamera();n.setCamera(new x(u+l,h+c,f))}}class dJ{constructor(e,n){I(this,"disposeSideEffectListener");this.editor=e,this.disposeSideEffectListener=e.sideEffects.registerAfterChangeHandler("instance",(s,o)=>{s.isFocused!==o.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 Mc(t){return fJ}class hJ{constructor(){I(this,"length",0);I(this,"head",null);I(this,"tail",this)}push(e){return new kb(e,this)}toArray(){return fo}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const fJ=new hJ;class kb{constructor(e,n){I(this,"length");this.head=e,this.tail=n,this.length=n.length+1}push(e){return new kb(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 pJ{constructor(e){I(this,"store");I(this,"dispose");I(this,"state","recording");I(this,"pendingDiff",new mJ);I(this,"stacks",It("HistoryManager.stacks",{undos:Mc(),redos:Mc()},{isEqual:(e,n)=>e.undos===n.undos&&e.redos===n.redos}));I(this,"annotateError");I(this,"_isInBatch",!1);this.store=e.store,this.annotateError=e.annotateError??Ru,this.dispose=this.store.addHistoryInterceptor((n,r)=>{if(r==="user")switch(this.state){case"recording":this.pendingDiff.apply(n.changes),this.stacks.update(({undos:s})=>({undos:s,redos:Mc()}));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=gJ[n.history]);try{if(this._isInBatch)return js(e),this;this._isInBatch=!0;try{js(e)}catch(s){throw this.annotateError(s),s}finally{this._isInBatch=!1}return this}finally{this.state=r}}_undo({pushToRedoStack:e,toMark:n=void 0}){var s;const r=this.state;this.state="paused";try{let{undos:o,redos:i}=this.stacks.get();const a=this.pendingDiff.clear(),l=dA(a),c=fx(a);e&&!l&&(i=i.push({type:"diff",diff:a}));let u=!1;if(l)for(;((s=o.head)==null?void 0:s.type)==="stop";){const h=o.head;if(o=o.tail,e&&(i=i.push(h)),h.id===n){u=!0;break}}if(!u)e:for(;o.head;){const h=o.head;switch(o=o.tail,e&&(i=i.push(h)),h.type){case"diff":lu(c,[fx(h.diff)]);break;case"stop":if(!n)break e;if(h.id===n){u=!0;break e}break;default:Ot(h)}}if(!u&&n)return this;this.store.applyDiff(c,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:o,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:s}=this.stacks.get();if(s.length===0)return this;for(;((n=s.head)==null?void 0:n.type)==="stop";)r=r.push(s.head),s=s.tail;const o=xp();for(;s.head;){const i=s.head;if(r=r.push(i),s=s.tail,i.type==="diff")lu(o,[i.diff]);else break}this.store.applyDiff(o,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:s})}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 o;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||((o=n.head)==null?void 0:o.id)!==e)return console.error("Could not find mark to squash to: ",e),this;if(r.length===0)return this;const s=xp();return lu(s,r.reverse()),this.stacks.update(({redos:i})=>({undos:n.push({type:"diff",diff:s}),redos:i})),this}_mark(e){js(()=>{this.flushPendingDiff(),this.stacks.update(({undos:n,redos:r})=>({undos:n.push({type:"stop",id:e}),redos:r}))})}clear(){this.stacks.set({undos:Mc(),redos:Mc()}),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 gJ={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class mJ{constructor(){I(this,"diff",xp());I(this,"isEmptyAtom",It("PendingDiff.isEmpty",!0))}clear(){const e=this.diff;return this.diff=xp(),this.isEmptyAtom.set(!0),e}isEmpty(){return this.isEmptyAtom.get()}apply(e){lu(this.diff,[e]),this.isEmptyAtom.set(dA(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class yJ{constructor(e){I(this,"scribbleItems",new Map);I(this,"state","paused");this.editor=e}addScribble(e,n=ze()){const r={id:n,scribble:{id:n,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...e,state:"starting"},timeoutMs:0,delayRemaining:e.delay??0,prev:null,next:null};return this.scribbleItems.set(n,r),r}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}stop(e){const n=this.scribbleItems.get(e);if(!n)throw Error(`Scribble with id ${e} not found`);return n.delayRemaining=Math.min(n.delayRemaining,200),n.scribble.state="stopping",n}addPoint(e,n,r,s=.5){const o=this.scribbleItems.get(e);if(!o)throw Error(`Scribble with id ${e} not found`);const{prev:i}=o,a={x:n,y:r,z:s};return(!i||x.Dist(i,a)>=1)&&(o.next=a),o}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:s,prev:o,next:i,scribble:a}=n;switch(a.state){case"active":{i&&i!==o?(n.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):s===0&&(a.points.length>1?a.points.shift():n.delayRemaining=a.delay);break}case"stopping":{if(n.delayRemaining===0&&s===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 SJ=Object.create,PO=Object.defineProperty,vJ=Object.getOwnPropertyDescriptor,xJ=(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,wJ=t=>[,,,SJ(null)],IO=["class","method","getter","setter","accessor","field","value","get","set"],EO=t=>t!==void 0&&typeof t!="function"?CO("Function expected"):t,bJ=(t,e,n,r,s)=>({kind:IO[t],name:e,metadata:r,addInitializer:o=>n._?CO("Already initialized"):s.push(EO(o||null))}),PJ=(t,e)=>_O(e,xJ("metadata"),t[3]),CJ=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Kg=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=IO[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,vJ(s,n)),y=r.length-1;y>=0;y--)l=bJ(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,EO(i)&&(v[g]=i);return v&&PO(s,n,v),s},_J=(t,e,n)=>_O(t,e+"",n),kO,TO,MO,AO,_a;const fe=t=>Math.round(t*10**8)/10**8;function to(t,e,n,r,s){const o=t.filter(a=>(r==="forward"?a.startNode.id===e:a.endNode.id===e)&&fe(a.length)===fe(n)&&Gr(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));if(o.length===0)return[];const i=new Set;return o.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(l)){i.add(l);const c=to(t,l,n,r,Gr(a.breadthIntersection[0],a.breadthIntersection[1],s[0],s[1]));o.push(...c)}}),o}function IJ(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 s=t[r];if(s.direction===n.direction&&n.gaps.every(o=>s.gaps.some(i=>fe(o.startEdge[0].x)===fe(i.startEdge[0].x)&&fe(o.startEdge[0].y)===fe(i.startEdge[0].y)&&fe(o.startEdge[1].x)===fe(i.startEdge[1].x)&&fe(o.startEdge[1].y)===fe(i.startEdge[1].y))&&s.gaps.some(i=>fe(o.endEdge[0].x)===fe(i.endEdge[0].x)&&fe(o.endEdge[0].y)===fe(i.endEdge[0].y)&&fe(o.endEdge[1].x)===fe(i.endEdge[1].x)&&fe(o.endEdge[1].y)===fe(i.endEdge[1].y)))){t.splice(e,1);break}}}}AO=[G],MO=[G],TO=[G],kO=[G];class rc{constructor(e){this.manager=e,CJ(_a,5,this),_J(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 o=e.getShapeUtil(n).getBoundsSnapGeometry(n).points??e.getShapeGeometry(n).bounds.cornersAndCenter;if(!(!r||!o))return o.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 s of n){const o=e.get(s);o&&r.push(...o)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),e=>({id:e,pageBounds:zn(this.editor.getShapePageBounds(e))}))}getVisibleGaps(){const e=[],n=[];let r,s;const o=this.getSnappableGapNodes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<o.length;a++){r=o[a];for(let l=a+1;l<o.length;l++)s=o[l],r.pageBounds.maxX<s.pageBounds.minX&&Tc(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)&&e.push({startNode:r,endNode:s,startEdge:[new x(r.pageBounds.maxX,r.pageBounds.minY),new x(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new x(s.pageBounds.minX,s.pageBounds.minY),new x(s.pageBounds.minX,s.pageBounds.maxY)],length:s.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Gr(r.pageBounds.minY,r.pageBounds.maxY,s.pageBounds.minY,s.pageBounds.maxY)})}const i=o.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++)s=i[l],r.pageBounds.maxY<s.pageBounds.minY&&Tc(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)&&n.push({startNode:r,endNode:s,startEdge:[new x(r.pageBounds.minX,r.pageBounds.maxY),new x(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new x(s.pageBounds.minX,s.pageBounds.minY),new x(s.pageBounds.maxX,s.pageBounds.minY)],length:s.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Gr(r.pageBounds.minX,r.pageBounds.maxX,s.pageBounds.minX,s.pageBounds.maxX)})}return{horizontal:e,vertical:n}}snapTranslateShapes({lockedAxis:e,initialSelectionPageBounds:n,initialSelectionSnapPoints:r,dragDelta:s}){var v,y;const o=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=n.clone().translate(s),l=r.map(({x:S,y:b},P)=>({id:"selection:"+P,x:S+s.x,y:b+s.y})),c=i,u=[],h=[],f=new x(o,o);this.collectPointSnaps({minOffset:f,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:f});const p=new x(e==="x"?0:((v=u[0])==null?void 0:v.nudge)??0,e==="y"?0:((y=h[0])==null?void 0:y.nudge)??0);f.x=0,f.y=0,u.length=0,h.length=0,l.forEach(S=>{S.x+=p.x,S.y+=p.y}),a.translate(p),this.collectPointSnaps({minOffset:f,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:f});const g=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),m=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...m,...g]),{nudge:p}}snapResizeShapes({initialSelectionPageBounds:e,dragDelta:n,handle:r,isAspectRatioLocked:s,isResizingFromCenter:o}){var E,k;const i=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=Z.Resize(e,r,o?n.x*2:n.x,o?n.y*2:n.y,s);let u=r;l<0&&(u=Lq(u)),c<0&&(u=Rq(u)),o&&(a.center=e.center);const h=u==="top"||u==="bottom",f=u==="left"||u==="right",p=AI(u,a),g=this.getSnappablePoints(),m=[],v=[],y=new x(i,i);this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:p});const S=new x(h?0:((E=m[0])==null?void 0:E.nudge)??0,f?0:((k=v[0])==null?void 0:k.nudge)??0);if(s&&$q(u)&&S.len()!==0){const D=m.length&&v.length?Math.abs(S.x)<Math.abs(S.y)?"x":"y":m.length?"x":"y",T=e.aspectRatio;D==="x"?(v.length=0,S.y=S.x/T,(u==="bottom_left"||u==="top_right")&&(S.y=-S.y)):(m.length=0,S.x=S.y*T,(u==="bottom_left"||u==="top_right")&&(S.x=-S.x))}const b=x.Add(n,S),{box:P}=Z.Resize(e,r,o?b.x*2:b.x,o?b.y*2:b.y,s);o&&(P.center=e.center);const C=AI("any",P);m.length=0,v.length=0,y.x=0,y.y=0,this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:v,otherNodeSnapPoints:g,selectionSnapPoints:C});const _=this.getPointSnapLines({nearestSnapsX:m,nearestSnapsY:v});return this.manager.setIndicators([..._]),{nudge:S}}collectPointSnaps({selectionSnapPoints:e,otherNodeSnapPoints:n,minOffset:r,nearestSnapsX:s,nearestSnapsY:o}){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);fe(c)<=fe(r.x)&&(fe(c)<fe(r.x)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),fe(u)<=fe(r.y)&&(fe(u)<fe(r.y)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:e,minOffset:n,nearestSnapsX:r,nearestSnapsY:s}){const{horizontal:o,vertical:i}=this.getVisibleGaps();for(const a of o){if(!Tc(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&&fe(Math.abs(c))<=fe(n.x)){fe(Math.abs(c))<fe(n.x)&&(r.length=0),n.x=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},S=r.find(({type:P})=>P==="gap_center"),b=S&&Gr(a.breadthIntersection[0],a.breadthIntersection[1],S.gap.breadthIntersection[0],S.gap.breadthIntersection[1]);S&&S.gap.length>a.length&&b?r[r.indexOf(S)]=y:(!S||!b)&&r.push(y)}const h=a.startNode.pageBounds.minX-a.length,f=e.maxX,p=h-f;fe(Math.abs(p))<=fe(n.x)&&(fe(Math.abs(p))<fe(n.x)&&(r.length=0),n.x=Math.abs(p),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:p}));const g=a.endNode.pageBounds.maxX+a.length,m=e.minX,v=g-m;fe(Math.abs(v))<=fe(n.x)&&(fe(Math.abs(v))<fe(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(!Tc(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&&fe(Math.abs(c))<=fe(n.y)){fe(Math.abs(c))<fe(n.y)&&(s.length=0),n.y=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},S=s.find(({type:P})=>P==="gap_center"),b=S&&Tc(S.gap.breadthIntersection[0],S.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);S&&S.gap.length>a.length&&b?s[s.indexOf(S)]=y:(!S||!b)&&s.push(y);continue}const h=a.startNode.pageBounds.minY-a.length,f=e.maxY,p=h-f;fe(Math.abs(p))<=fe(n.y)&&(fe(Math.abs(p))<fe(n.y)&&(s.length=0),n.y=Math.abs(p),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:p}));const g=a.endNode.pageBounds.maxY+a.length,m=e.minY,v=g-m;fe(Math.abs(v))<=fe(n.y)&&(fe(Math.abs(v))<fe(n.y)&&(s.length=0),n.y=Math.abs(v),s.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:v}))}}getPointSnapLines({nearestSnapsX:e,nearestSnapsY:n}){const r={},s={};if(e.length>0){for(const o of e)if(o.type==="points"){const i=fe(o.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(o.points)}}if(n.length>0){for(const o of n)if(o.type==="points"){const i=fe(o.points.otherPoint.y);s[i]||(s[i]=[]),s[i].push(o.points)}}return Object.values(r).concat(Object.values(s)).map(o=>({id:ze(),type:"points",points:y0(o.map(i=>x.From(i.otherPoint)).concat(o.map(i=>x.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:e,nearestSnapsX:n,nearestSnapsY:r}){const{vertical:s,horizontal:o}=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:f,length:p,endEdge:g}}=l;switch(l.type){case"gap_center":{const m=(p-e.width)/2,v=Gr(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:ze(),gaps:[...to(o,h.id,m,"backward",v),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:g},...to(o,f.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Gr(c[0],c[1],e.minY,e.maxY);a.push({type:"gaps",direction:"horizontal",id:ze(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(v=>v.clone().addXY(-h.pageBounds.width,0))},{startEdge:u,endEdge:g},...to(o,f.id,p,"forward",m)]:[...to(o,h.id,p,"backward",m),{startEdge:u,endEdge:g},{startEdge:g.map(v=>v.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:f,length:p,endEdge:g}}=l;switch(l.type){case"gap_center":{const m=(p-e.height)/2,v=Gr(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:ze(),gaps:[...to(s,h.id,m,"backward",v),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:g},...to(s,l.gap.endNode.id,m,"forward",v)]});break}case"gap_duplicate":{const m=Gr(c[0],c[1],e.minX,e.maxX);a.push({type:"gaps",direction:"vertical",id:ze(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(v=>v.clone().addXY(0,-h.pageBounds.height))},{startEdge:u,endEdge:g},...to(s,f.id,p,"forward",m)]:[...to(s,h.id,p,"backward",m),{startEdge:u,endEdge:g},{startEdge:g.map(v=>v.clone().addXY(0,f.pageBounds.height)),endEdge:i.top}]})}break}}return IJ(a),a}}_a=wJ();Kg(_a,1,"getSnapPointsCache",AO,rc);Kg(_a,1,"getSnappablePoints",MO,rc);Kg(_a,1,"getSnappableGapNodes",TO,rc);Kg(_a,1,"getVisibleGaps",kO,rc);PJ(_a,rc);function AI(t,e){const{minX:n,maxX:r,minY:s,maxY:o}=e,i=[];switch(t){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:n,y:s})}switch(t){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:s})}switch(t){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:o})}switch(t){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:n,y:o})}return i}var EJ=Object.create,jO=Object.defineProperty,kJ=Object.getOwnPropertyDescriptor,TJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),OO=t=>{throw TypeError(t)},DO=(t,e,n)=>e in t?jO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,MJ=t=>[,,,EJ(null)],RO=["class","method","getter","setter","accessor","field","value","get","set"],LO=t=>t!==void 0&&typeof t!="function"?OO("Function expected"):t,AJ=(t,e,n,r,s)=>({kind:RO[t],name:e,metadata:r,addInitializer:o=>n._?OO("Already initialized"):s.push(LO(o||null))}),jJ=(t,e)=>DO(e,TJ("metadata"),t[3]),OJ=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},DJ=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=RO[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,kJ(s,n)),y=r.length-1;y>=0;y--)l=AJ(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,LO(i)&&(v[g]=i);return v&&jO(s,n,v),s},RJ=(t,e,n)=>DO(t,e+"",n),$O,Wg;const LJ=()=>null,$J=()=>[];$O=[G];class Tb{constructor(e){this.manager=e,OJ(Wg,5,this),RJ(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),s=r.getSelfSnapOutline?r.getSelfSnapOutline.bind(r):LJ,o=r.getSelfSnapPoints?r.getSelfSnapPoints.bind(r):$J;return{outline:r.outline===void 0?e.getShapeGeometry(n):r.outline,points:r.points??[],getSelfSnapOutline:s,getSelfSnapPoints:o}})}*iterateSnapPointsInPageSpace(e,n){var s,o;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapPoints(n);if(r&&r.length){const i=zn(this.editor.getShapePageTransform(e));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const a=(o=this.getSnapGeometryCache().get(i))==null?void 0:o.points;if(!a||!a.length)continue;const l=zn(this.editor.getShapePageTransform(i));for(const c of a)yield l.applyToPoint(c)}}*iterateSnapOutlines(e,n){var s,o;const r=(s=this.getSnapGeometryCache().get(e))==null?void 0:s.getSelfSnapOutline(n);r&&(yield{shapeId:e,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===e)continue;const a=(o=this.getSnapGeometryCache().get(i))==null?void 0:o.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:e,handle:n,handleInPageSpace:r}){const s=this.manager.getSnapThreshold();let o=s,i=null;for(const c of this.iterateSnapPointsInPageSpace(e,n))x.DistMin(r,c,o)&&(o=x.Dist(r,c),i=c);if(i)return i;let a=s,l=null;for(const{shapeId:c,outline:u}of this.iterateSnapOutlines(e,n)){const h=zn(this.editor.getShapePageTransform(c)),f=this.editor.getPointInShapeSpace(c,r),p=u.nearestPoint(f),g=h.applyToPoint(p);x.DistMin(r,g,a)&&(a=x.Dist(r,g),l=g)}return l||null}snapHandle({currentShapeId:e,handle:n}){const s=zn(this.editor.getShapePageTransform(e)).applyToPoint(n),o=this.getHandleSnapPosition({currentShapeId:e,handle:n,handleInPageSpace:s});return o?(this.manager.setIndicators([{id:ze(),type:"points",points:[o]}]),{nudge:x.Sub(o,s)}):null}}Wg=MJ();DJ(Wg,1,"getSnapGeometryCache",$O,Tb);jJ(Wg,Tb);var FJ=Object.create,FO=Object.defineProperty,NJ=Object.getOwnPropertyDescriptor,zJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),NO=t=>{throw TypeError(t)},zO=(t,e,n)=>e in t?FO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,BJ=t=>[,,,FJ(null)],BO=["class","method","getter","setter","accessor","field","value","get","set"],UO=t=>t!==void 0&&typeof t!="function"?NO("Function expected"):t,UJ=(t,e,n,r,s)=>({kind:BO[t],name:e,metadata:r,addInitializer:o=>n._?NO("Already initialized"):s.push(UO(o||null))}),HJ=(t,e)=>zO(e,zJ("metadata"),t[3]),KJ=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Mb=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=BO[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,NJ(s,n)),y=r.length-1;y>=0;y--)l=UJ(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,UO(i)&&(v[g]=i);return v&&FO(s,n,v),s},Qy=(t,e,n)=>zO(t,typeof e!="symbol"?e+"":e,n),HO,KO,WO,sc;WO=[G],KO=[G],HO=[G];class yd{constructor(e){this.editor=e,KJ(sc,5,this),Qy(this,"shapeBounds"),Qy(this,"handles"),Qy(this,"_snapIndicators",It("snapLines",void 0)),this.shapeBounds=new rc(this),this.handles=new Tb(this)}getIndicators(){return this._snapIndicators.get()??fo}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(),s=new Set,o=i=>{if(Fn(i)){const l=e.getShape(i);l&&e.isShapeOfType(l,"frame")&&s.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")){o(l);continue}s.add(l)}}};return o(this.getCurrentCommonAncestor()??e.getCurrentPageId()),s}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}sc=BJ();Mb(sc,1,"getSnapThreshold",WO,yd);Mb(sc,1,"getSnappableShapes",KO,yd);Mb(sc,1,"getCurrentCommonAncestor",HO,yd);HJ(sc,yd);const WJ=/\r?\n|\r/g;function jI(t){return t.replace(WJ,`
|
|
102
|
+
`).split(`
|
|
103
|
+
`).map(e=>e||" ").join(`
|
|
104
|
+
`)}const GJ={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},VJ=/\s/;class YJ{constructor(e){I(this,"baseElem");this.editor=e,this.baseElem=document.createElement("div"),this.baseElem.classList.add("tl-text"),this.baseElem.classList.add("tl-text-measure"),this.baseElem.tabIndex=-1}measureText(e,n){const r=this.baseElem.cloneNode();this.editor.getContainer().appendChild(r),r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-style",n.fontStyle),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("font-size",n.fontSize+"px"),r.style.setProperty("line-height",n.lineHeight*n.fontSize+"px"),r.style.setProperty("max-width",n.maxWidth===null?null:n.maxWidth+"px"),r.style.setProperty("min-width",n.minWidth===null?null:n.minWidth+"px"),r.style.setProperty("padding",n.padding),r.style.setProperty("overflow-wrap",n.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=jI(e);const s=r.scrollWidth,o=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:o.width,h:o.height,scrollWidth:s}}measureElementTextNodeSpans(e,{shouldTruncateToFirstLine:n=!1}={}){const r=[],s=e.getBoundingClientRect(),o=-s.left,i=-s.top,a=new Range,l=e.childNodes[0];let c=0,u=null,h=null,f=0,p=0,g=!1;for(const m of e.childNodes)if(m.nodeType===Node.TEXT_NODE)for(const v of m.textContent??""){a.setStart(l,c),a.setEnd(l,c+v.length);const y=a.getClientRects(),S=y[y.length-1],b=S.top+i,P=S.left+o,C=S.right+o,_=P<p,E=VJ.test(v);if(E!==h||b!==f||!u){if(u){if(n&&b!==f){g=!0;break}r.push(u)}u={box:{x:P,y:b,w:S.width,h:S.height},text:v},p=P}else _&&(u.box.x=P),u.box.w=_?u.box.w+S.width:C-u.box.x,u.text+=v;v===`
|
|
105
|
+
`&&(p=0),h=E,f=b,c+=v.length}return u&&r.push(u),{spans:r,didTruncate:g}}measureTextSpans(e,n){if(e==="")return[];const r=this.baseElem.cloneNode();this.editor.getContainer().appendChild(r);const s=Math.ceil(n.width-n.padding*2);r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("width",`${s}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",GJ[n.textAlign]);const o=n.overflow==="truncate-ellipsis"||n.overflow==="truncate-clip";o&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=jI(e);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:o});if(n.overflow==="truncate-ellipsis"&&l){r.textContent="…";const c=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${s-c}px`),r.textContent=i;const u=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,h=u[u.length-1];return u.push({text:"…",box:{x:Math.min(h.box.x+h.box.w,n.width-n.padding-c),y:h.box.y,w:c,h:h.box.h}}),u}return r.remove(),a}}var XJ=Object.create,GO=Object.defineProperty,qJ=Object.getOwnPropertyDescriptor,ZJ=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),VO=t=>{throw TypeError(t)},YO=(t,e,n)=>e in t?GO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,QJ=t=>[,,,XJ(null)],XO=["class","method","getter","setter","accessor","field","value","get","set"],qO=t=>t!==void 0&&typeof t!="function"?VO("Function expected"):t,JJ=(t,e,n,r,s)=>({kind:XO[t],name:e,metadata:r,addInitializer:o=>n._?VO("Already initialized"):s.push(qO(o||null))}),eee=(t,e)=>YO(e,ZJ("metadata"),t[3]),tee=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},ZO=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=XO[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,qJ(s,n)),y=r.length-1;y>=0;y--)l=JJ(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,qO(i)&&(v[g]=i);return v&&GO(s,n,v),s},Sh=(t,e,n)=>YO(t,typeof e!="symbol"?e+"":e,n),QO,JO,Sd;const OI=ZT;JO=[Kn],QO=[Kn];class Gg{constructor(e){this.editor=e,tee(Sd,5,this),Sh(this,"cancelRaf"),Sh(this,"isPaused",!0),Sh(this,"now",0),Sh(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=OI(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=OI(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:s}}}=this;if(e===0)return;const o=x.Sub(r,n);this.prevPoint=r.clone();const i=o.len(),a=i?o.div(i):new x(0,0),l=s.clone().lrp(a.mul(i/e),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),s.equals(l)||(this.editor.inputs.pointerVelocity=l)}}Sd=QJ();ZO(Sd,1,"tick",JO,Gg);ZO(Sd,1,"dispose",QO,Gg);eee(Sd,Gg);var nee=Object.create,eD=Object.defineProperty,ree=Object.getOwnPropertyDescriptor,see=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),tD=t=>{throw TypeError(t)},nD=(t,e,n)=>e in t?eD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oee=t=>[,,,nee(null)],rD=["class","method","getter","setter","accessor","field","value","get","set"],sD=t=>t!==void 0&&typeof t!="function"?tD("Function expected"):t,iee=(t,e,n,r,s)=>({kind:rD[t],name:e,metadata:r,addInitializer:o=>n._?tD("Already initialized"):s.push(sD(o||null))}),aee=(t,e)=>nD(e,see("metadata"),t[3]),lee=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Nr=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=rD[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,ree(s,n)),y=r.length-1;y>=0;y--)l=iee(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,sD(i)&&(v[g]=i);return v&&eD(s,n,v),s},DI=(t,e,n)=>nD(t,typeof e!="symbol"?e+"":e,n),oD,iD,aD,lD,cD,uD,dD,hD,fD,pD,gD,mD,Mn;mD=[G],gD=[G],pD=[G],fD=[G],hD=[G],dD=[G],uD=[G],cD=[G],lD=[G],aD=[G],iD=[G],oD=[G];class Qn{constructor(e,n){if(this.user=e,this.inferDarkMode=n,lee(Mn,5,this),DI(this,"systemColorScheme",It("systemColorScheme","light")),DI(this,"disposables",new Set),typeof window>"u"||!("matchMedia"in window))return;const r=window.matchMedia("(prefers-color-scheme: dark)");r!=null&&r.matches&&this.systemColorScheme.set("dark");const s=o=>{o.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")};r==null||r.addEventListener("change",s),this.disposables.add(()=>r==null?void 0:r.removeEventListener("change",s))}dispose(){this.disposables.forEach(e=>e())}updateUserPreferences(e){this.user.setUserPreferences({...this.user.userPreferences.get(),...e})}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme){case"dark":return!0;case"light":return!1;case"system":return this.systemColorScheme.get()==="dark";default:return this.inferDarkMode?this.systemColorScheme.get()==="dark":!1}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??vs.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??vs.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??vs.name}getLocale(){return this.user.userPreferences.get().locale??vs.locale}getColor(){return this.user.userPreferences.get().color??vs.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??vs.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??vs.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??vs.isDynamicSizeMode}getIsPasteAtCursorMode(){return this.user.userPreferences.get().isPasteAtCursorMode??vs.isPasteAtCursorMode}}Mn=oee();Nr(Mn,1,"getUserPreferences",mD,Qn);Nr(Mn,1,"getIsDarkMode",gD,Qn);Nr(Mn,1,"getEdgeScrollSpeed",pD,Qn);Nr(Mn,1,"getAnimationSpeed",fD,Qn);Nr(Mn,1,"getId",hD,Qn);Nr(Mn,1,"getName",dD,Qn);Nr(Mn,1,"getLocale",uD,Qn);Nr(Mn,1,"getColor",cD,Qn);Nr(Mn,1,"getIsSnapMode",lD,Qn);Nr(Mn,1,"getIsWrapMode",aD,Qn);Nr(Mn,1,"getIsDynamicResizeMode",iD,Qn);Nr(Mn,1,"getIsPasteAtCursorMode",oD,Qn);aee(Mn,Qn);const cee={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"},uee=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class ie{constructor(e,n){I(this,"performanceTracker");I(this,"id");I(this,"type");I(this,"shapeType");I(this,"initial");I(this,"children");I(this,"isLockable");I(this,"parent");I(this,"_path");I(this,"_current");I(this,"_isActive");I(this,"_currentToolIdMask",It("curent tool id mask",void 0));this.editor=e;const{id:r,children:s,initial:o,isLockable:i}=this.constructor;this.id=r,this._isActive=It("toolIsActive"+this.id,!1),this._current=It("toolState"+this.id,void 0),this._path=G("toolPath"+this.id,()=>{const a=this.getCurrent();return this.id+(a?`.${a.getPath()}`:"")}),this.parent=n??{},this.parent?s&&o?(this.type="branch",this.initial=o,this.children=Object.fromEntries(s().map(a=>[a.id,new a(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",s&&o&&(this.initial=o,this.children=Object.fromEntries(s().map(a=>[a.id,new a(this.editor,this)])),this._current.set(this.children[this.initial]))),this.isLockable=i,this.performanceTracker=new MT}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}transition(e,n={}){var o;const r=e.split(".");let s=this;for(let i=0;i<r.length;i++){const a=r[i],l=s.getCurrent(),c=(o=s.children)==null?void 0:o[a];if(!c)throw Error(`${s.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(n,a),s._current.set(c),c.enter(n,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;s=c}return this}handleEvent(e){var s;const n=cee[e.name],r=this._current.__unsafe__getWithoutCapture();(s=this[n])==null||s.call(this,e),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(e)}enter(e,n){var r;if(wt.measurePerformance.get()&&uee.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 s=this.children[this.initial];this._current.set(s),s.enter(e,n)}}exit(e,n){var r,s;wt.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,e,n),this.getIsActive()||(s=this.getCurrent())==null||s.exit(e,n)}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(e){this._currentToolIdMask.set(e)}}I(ie,"id"),I(ie,"initial"),I(ie,"children"),I(ie,"isLockable",!0);class Tx extends ie{static children(){return[]}onKeyDown(e){var n;switch(e.code){case"KeyZ":{if(!(e.shiftKey||e.ctrlKey)){const r=this.getCurrent();r&&((n=r.getCurrent())==null?void 0:n.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...e,onInteractionEnd:r.id})}break}}}}I(Tx,"id","root"),I(Tx,"initial","");var dee=Object.create,yD=Object.defineProperty,hee=Object.getOwnPropertyDescriptor,SD=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),vD=t=>{throw TypeError(t)},xD=(t,e,n)=>e in t?yD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fee=t=>[,,,dee((t==null?void 0:t[SD("metadata")])??null)],wD=["class","method","getter","setter","accessor","field","value","get","set"],bD=t=>t!==void 0&&typeof t!="function"?vD("Function expected"):t,pee=(t,e,n,r,s)=>({kind:wD[t],name:e,metadata:r,addInitializer:o=>n._?vD("Already initialized"):s.push(bD(o||null))}),gee=(t,e)=>xD(e,SD("metadata"),t[3]),mee=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},ee=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=wD[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,hee(s,n)),y=r.length-1;y>=0;y--)l=pee(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,bD(i)&&(v[g]=i);return v&&yD(s,n,v),s},he=(t,e,n)=>xD(t,typeof e!="symbol"?e+"":e,n),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,sR,oR,iR,aR,lR,cR,uR,dR,hR,fR,pR,gR,mR,yR,SR,vR,xR,wR,bR,PR,CR,_R,IR,ER,kR,TR,MR,AR,jR,OR,DR,RR,LR,$R,FR,NR,zR,Mx,J;class Q extends(Mx=FZ,zR=[G],NR=[G],FR=[G],$R=[G],LR=[G],RR=[G],DR=[G],OR=[G],jR=[G],AR=[G],MR=[G],TR=[G],kR=[G],ER=[G],IR=[G],_R=[G],CR=[G],PR=[G],bR=[G],wR=[G],xR=[G],vR=[G],SR=[G],yR=[G],mR=[G],gR=[G],pR=[G],fR=[G],hR=[G],dR=[G],uR=[G],cR=[G],lR=[G],aR=[G],iR=[G],oR=[G],sR=[G],rR=[G],nR=[G],tR=[G],eR=[G],JD=[G],QD=[G],ZD=[G],qD=[G],XD=[G],YD=[G],VD=[G],GD=[G],WD=[G],KD=[G],HD=[G],UD=[G],BD=[G],zD=[G],ND=[G],FD=[G],$D=[G],LD=[G],RD=[G],DD=[G],OD=[G],jD=[G],AD=[G],MD=[G({isEqual:(e,n)=>e.equals(n)})],TD=[G],kD=[G],ED=[G],ID=[Kn],_D=[Kn],CD=[Kn],PD=[Kn],Mx){constructor({store:e,user:n,shapeUtils:r,bindingUtils:s,tools:o,getContainer:i,cameraOptions:a,initialState:l,autoFocus:c,inferDarkMode:u,options:h,isShapeHidden:f}){var D;super(),mee(J,5,this),he(this,"_isShapeHiddenPredicate"),he(this,"options"),he(this,"contextId",ze()),he(this,"store"),he(this,"root"),he(this,"disposables",new Set),he(this,"isDisposed",!1),he(this,"_tickManager"),he(this,"snaps"),he(this,"timers",Ex.forContext(this.contextId)),he(this,"user"),he(this,"textMeasure"),he(this,"environment",Ge),he(this,"scribbles"),he(this,"sideEffects"),he(this,"edgeScrollManager"),he(this,"focusManager"),he(this,"getContainer"),he(this,"shapeUtils"),he(this,"styleProps"),he(this,"bindingUtils"),he(this,"history"),he(this,"_shouldIgnoreShapeLock",!1),he(this,"_crashingError",null),he(this,"_isChangingStyleTimeout",-1),he(this,"menus",Vr.forContext(this.contextId)),he(this,"_cameraOptions",It("camera options",J_)),he(this,"_viewportAnimation",null),he(this,"_willSetInitialBounds",!0),he(this,"_isLockedOnFollowingUser",It("isLockedOnFollowingUser",!1)),he(this,"_cameraState",It("camera state","idle")),he(this,"_cameraStateTimeoutRemaining",0),he(this,"_currentPageShapeIds"),he(this,"_parentIdsToChildIds"),he(this,"animatingShapes",new Map),he(this,"externalAssetContentHandlers",{file:null,url:null}),he(this,"temporaryAssetPreview",new Map),he(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null}),he(this,"inputs",{originPagePoint:new x,originScreenPoint:new x,previousPagePoint:new x,previousScreenPoint:new x,currentPagePoint:new x,currentScreenPoint:new x,keys:new Set,buttons:new Set,isPen:!1,shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,isSpacebarPanning:!1,pointerVelocity:new x}),he(this,"_clickManager",new Hg(this)),he(this,"_prevCursor","default"),he(this,"_shiftKeyTimeout",-1),he(this,"_altKeyTimeout",-1),he(this,"_ctrlKeyTimeout",-1),he(this,"_metaKeyTimeout",-1),he(this,"_restoreToolId","select"),he(this,"_pinchStart",1),he(this,"_didPinch",!1),he(this,"_selectedShapeIdsAtPointerDown",[]),he(this,"_longPressTimeout",-1),he(this,"capturedPointerId",null),he(this,"performanceTracker"),he(this,"performanceTrackerTimeout",-1),he(this,"_pendingEventsForNextTick",[]),this._isShapeHiddenPredicate=f,this.options={...zQ,...h},this.store=e,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new pJ({store:e,annotateError:T=>{this.annotateError(T,{origin:"history.batch",willCrashApp:!0}),this.crash(T)}}),this.snaps=new yd(this),this.disposables.add(this.timers.dispose),this._cameraOptions.set({...J_,...a}),this.user=new Qn(n??Fj(),u??!1),this.disposables.add(()=>this.user.dispose()),this.getContainer=i,this.textMeasure=new YJ(this),this._tickManager=new Gg(this);class p extends Tx{}I(p,"initial",l??""),this.root=new p(this),this.root.children={};const g=Gj(r),m={},v={},y=new Map;for(const T of g){const j=new T(this);m[T.type]=j;const L=yA(T.props??{});v[T.type]=L;for(const M of L.keys())if(!y.has(M.id))y.set(M.id,M);else if(y.get(M.id)!==M)throw Error(`Multiple style props with id "${M.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=m,this.styleProps=v;const S=Kj(s),b={};for(const T of S){const j=new T(this);b[T.type]=j}this.bindingUtils=b;for(const T of[...o]){if(ns(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 yJ(this);const P=(T,j)=>{let L=null;const M=T.selectedShapeIds.filter(B=>!j.has(B));M.length!==T.selectedShapeIds.length&&(L||(L={...T}),L.selectedShapeIds=M);const O=T.erasingShapeIds.filter(B=>!j.has(B));O.length!==T.erasingShapeIds.length&&(L||(L={...T}),L.erasingShapeIds=O),T.hoveredShapeId&&j.has(T.hoveredShapeId)&&(L||(L={...T}),L.hoveredShapeId=null),T.editingShapeId&&j.has(T.editingShapeId)&&(L||(L={...T}),L.editingShapeId=null);const F=T.hintingShapeIds.filter(B=>!j.has(B));return F.length!==T.hintingShapeIds.length&&(L||(L={...T}),L.hintingShapeIds=F),T.focusedGroupId&&j.has(T.focusedGroupId)&&(L||(L={...T}),L.focusedGroupId=null),L};this.sideEffects=this.store.sideEffects;let C=new Map;const _=new Set,E=new Set;let k=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var T,j,L,M;_.clear();for(const O of E){E.delete(O);const F=this.getShape(O);if(!F)continue;const B=this.getShapeUtil(F),K=(T=B.onChildrenChange)==null?void 0:T.call(B,F);K!=null&&K.length&&this.updateShapes(K)}if(k.size){const O=k;k=new Set;for(const F of O){const B=this.getBindingUtil(F);(j=B.onOperationComplete)==null||j.call(B)}}if(C.size){const O=C;C=new Map;for(const F of O.values())(M=(L=this.getBindingUtil(F.binding)).onAfterDelete)==null||M.call(L,F)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(T,j)=>{var L,M,O,F;for(const B of this.getBindingsInvolvingShape(j))k.add(B.type),B.fromId===j.id&&((M=(L=this.getBindingUtil(B)).onAfterChangeFromShape)==null||M.call(L,{binding:B,shapeBefore:T,shapeAfter:j})),B.toId===j.id&&((F=(O=this.getBindingUtil(B)).onAfterChangeToShape)==null||F.call(O,{binding:B,shapeBefore:T,shapeAfter:j}));if(T.parentId!==j.parentId){const B=K=>{var H,X,te,le;const R=this.getShape(K);if(R)for(const de of this.getBindingsInvolvingShape(R))k.add(de.type),de.fromId===R.id&&((X=(H=this.getBindingUtil(de)).onAfterChangeFromShape)==null||X.call(H,{binding:de,shapeBefore:R,shapeAfter:R})),de.toId===R.id&&((le=(te=this.getBindingUtil(de)).onAfterChangeToShape)==null||le.call(te,{binding:de,shapeBefore:R,shapeAfter:R}))};B(j.id),this.visitDescendants(j.id,B)}if(T.parentId!==j.parentId&&Rn(j.parentId)){const B=new Set([T.id]);this.visitDescendants(T.id,K=>{B.add(K)});for(const K of this.getPageStates()){if(K.pageId===j.parentId)continue;const R=P(K,B);R&&this.store.put([R])}}T.parentId&&Fn(T.parentId)&&E.add(T.parentId),j.parentId!==T.parentId&&Fn(j.parentId)&&E.add(j.parentId)},beforeDelete:T=>{var O,F,B,K;if(_.has(T.id))return;T.parentId&&Fn(T.parentId)&&E.add(T.parentId),_.add(T.id);const j=[];for(const R of this.getBindingsInvolvingShape(T)){k.add(R.type),j.push(R.id);const H=this.getBindingUtil(R);R.fromId===T.id?((O=H.onBeforeIsolateToShape)==null||O.call(H,{binding:R,removedShape:T}),(F=H.onBeforeDeleteFromShape)==null||F.call(H,{binding:R,shape:T})):((B=H.onBeforeIsolateFromShape)==null||B.call(H,{binding:R,removedShape:T}),(K=H.onBeforeDeleteToShape)==null||K.call(H,{binding:R,shape:T}))}j.length&&this.deleteBindings(j);const L=new Set([T.id]),M=me(this.getPageStates().map(R=>P(R,L)));M.length&&this.store.put(M)}},binding:{beforeCreate:T=>{var L,M;const j=(M=(L=this.getBindingUtil(T)).onBeforeCreate)==null?void 0:M.call(L,{binding:T});return j||T},afterCreate:T=>{var j,L;k.add(T.type),(L=(j=this.getBindingUtil(T)).onAfterCreate)==null||L.call(j,{binding:T})},beforeChange:(T,j)=>{var M,O;const L=(O=(M=this.getBindingUtil(j)).onBeforeChange)==null?void 0:O.call(M,{bindingBefore:T,bindingAfter:j});return L||j},afterChange:(T,j)=>{var L,M;k.add(j.type),(M=(L=this.getBindingUtil(j)).onAfterChange)==null||M.call(L,{bindingBefore:T,bindingAfter:j})},beforeDelete:T=>{var j,L;(L=(j=this.getBindingUtil(T)).onBeforeDelete)==null||L.call(j,{binding:T})},afterDelete:T=>{var j,L;(L=(j=this.getBindingUtil(T)).onAfterDelete)==null||L.call(j,{binding:T}),k.add(T.type)}},page:{afterCreate:T=>{const j=Is.createId(T.id),L=Qr.createId(T.id);this.store.has(j)||this.store.put([Is.create({id:j})]),this.store.has(L)||this.store.put([Qr.create({id:L,pageId:T.id})])},afterDelete:(T,j)=>{var O,F;if(((O=this.getInstanceState())==null?void 0:O.currentPageId)===T.id){const B=(F=this.getPages().find(K=>K.id!==T.id))==null?void 0:F.id;B?this.store.put([{...this.getInstanceState(),currentPageId:B}]):j==="user"&&this.store.ensureStoreIsUsable()}const L=Is.createId(T.id),M=Qr.createId(T.id);this.store.remove([L,M])}},instance:{afterChange:(T,j,L)=>{var M;if(!this.store.has(j.currentPageId)){const O=this.store.has(T.currentPageId)?T.currentPageId:(M=this.getPages()[0])==null?void 0:M.id;O?this.store.update(j.id,F=>({...F,currentPageId:O})):L==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(T,j)=>{if((T==null?void 0:T.selectedShapeIds)!==(j==null?void 0:j.selectedShapeIds)){const L=j.selectedShapeIds.filter(O=>{var B,K;let F=(B=this.getShape(O))==null?void 0:B.parentId;for(;Fn(F);){if(j.selectedShapeIds.includes(F))return!1;F=(K=this.getShape(F))==null?void 0:K.parentId}return!0});let M=null;if(L.length>0){const O=this.findCommonAncestor(me(L.map(F=>this.getShape(F))),F=>this.isShapeOfType(F,"group"));O&&(M=O)}else j!=null&&j.focusedGroupId&&(M=j.focusedGroupId);(L.length!==j.selectedShapeIds.length||M!==j.focusedGroupId)&&this.store.put([{...j,selectedShapeIds:L,focusedGroupId:M??null}])}}}})),this._currentPageShapeIds=tJ(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=eJ(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 uJ(this),this.focusManager=new dJ(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 MT,(D=this.store.props.collaboration)!=null&&D.mode){const T=this.store.props.collaboration.mode;this.disposables.add(As("update collaboration mode",()=>{this.store.put([{...this.getInstanceState(),isReadonly:T.get()==="readonly"}])}))}}getIsShapeHiddenCache(){return this._isShapeHiddenPredicate?this.store.createComputedCache("isShapeHidden",e=>this.findShapeAncestor(e,r=>this.isShapeHidden(r))?!0:this._isShapeHiddenPredicate(e,this)??!1):null}isShapeHidden(e){return this._isShapeHiddenPredicate?!!this.getIsShapeHiddenCache().get(typeof e=="string"?e:e.id):!1}dispose(){this.disposables.forEach(e=>e()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(e){const n=typeof e=="string"?e:e.type,r=hn(this.shapeUtils,n);return Le(r,`No shape util found for type "${n}"`),r}getBindingUtil(e){const n=typeof e=="string"?e:e.type,r=hn(this.bindingUtils,n);return Le(r,`No binding util found for type "${n}"`),r}undo(){return this._flushEventsForTick(0),this.complete(),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.complete(),this.history.redo(),this}clearHistory(){return this.history.clear(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(e){return console.warn(typeof e=="string"?`[tldraw] \`editor.history.mark("${e}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`:"[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead."),this.history._mark(e??ze()),this}markHistoryStoppingPoint(e){const n=`[${e??"stop"}]_${ze()}`;return this.history._mark(n),n}getMarkIdMatching(e){return this.history.getMarkIdMatching(e)}squashToMark(e){return this.history.squashToMark(e),this}bail(){return this.history.bail(),this}bailToMark(e){return this.history.bailToMark(e),this}run(e,n){const r=this._shouldIgnoreShapeLock;this._shouldIgnoreShapeLock=(n==null?void 0:n.ignoreShapeLock)??r;try{this.history.batch(e,n)}finally{this._shouldIgnoreShapeLock=r}return this}batch(e,n){return this.run(e,n)}annotateError(e,{origin:n,willCrashApp:r,tags:s,extras:o}){const i=this.createErrorAnnotations(n,r);return S0(e,{tags:{...i.tags,...s},extras:{...i.extras,...o}}),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 s=n.pop();if(!s)return!0;const o=r.getCurrent();if((o==null?void 0:o.id)===s){if(n.length===0)return!0;r=o;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 s;const n=e.split(".").reverse();let r=this.root;for(;n.length>0;){const o=n.pop();if(!o)return r;const i=(s=r.children)==null?void 0:s[o];if(!i)return;r=i}return r}getDocumentSettings(){return this.store.get(mx)}updateDocumentSettings(e){return this.run(()=>{this.store.put([{...this.getDocumentSettings(),...e}])},{history:"ignore"}),this}getInstanceState(){return this.store.get(bn)}updateInstanceState(e,n){return this._updateInstanceState(e,{history:"ignore",...n}),e.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),e.isChangingStyle===!0&&(this._isChangingStyleTimeout=this.timers.setTimeout(()=>{this._updateInstanceState({isChangingStyle:!1},{history:"ignore"})},2e3))),this}_updateInstanceState(e,n){this.run(()=>{this.store.put([{...this.getInstanceState(),...e}])},n)}getOpenMenus(){return this.menus.getOpenMenus()}addOpenMenu(e){return this.menus.addOpenMenu(e),this}deleteOpenMenu(e){return this.menus.deleteOpenMenu(e),this}clearOpenMenus(){return this.menus.clearOpenMenus(),this}getIsMenuOpen(){return this.menus.hasAnyOpenMenus()}setCursor(e){return this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...e}}),this}getPageStates(){return this._getPageStatesQuery().get()}_getPageStatesQuery(){return this.store.query.records("instance_page_state")}getCurrentPageState(){return this.store.get(this._getCurrentPageStateId())}_getCurrentPageStateId(){return Qr.createId(this.getCurrentPageId())}updateCurrentPageState(e){return this._updateCurrentPageState(e),this}_updateCurrentPageState(e){this.store.update(e.id??this.getCurrentPageState().id,n=>({...n,...e}))}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:e}=this.getCurrentPageState();return me(e.map(n=>this.store.get(n)))}setSelectedShapes(e){return this.run(()=>{const n=e.map(o=>typeof o=="string"?o:o.id),{selectedShapeIds:r}=this.getCurrentPageState(),s=new Set(r);if(n.length===s.size&&n.every(o=>s.has(o)))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 s=this.getSelectedShapeIds();return!!this.findShapeAncestor(r,o=>s.includes(o.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(s=>s.id),r=this.getSelectedShapeIds();return r.length>0&&n.length>0&&this.setSelectedShapes(r.filter(s=>!n.includes(s))),this}selectAll(){const e=this.getSortedChildIdsForParent(this.getCurrentPageId());return e.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(e)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var e;return((e=this.getOnlySelectedShape())==null?void 0:e.id)??null}getOnlySelectedShape(){const e=this.getSelectedShapes();return e.length===1?e[0]:null}getShapesPageBounds(e){const n=me(e.map(r=>this.getShapePageBounds(r)));return n.length===0?null:Z.Common(n)}getSelectionPageBounds(){return this.getShapesPageBounds(this.getSelectedShapeIds())}getShapesSharedRotation(e){let n=!1,r=0;for(let s=0,o=e.length;s<o;s++){const i=this.getShapePageTransform(e[s]);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 s=this.getShapeGeometry(e[0]).bounds.clone(),o=this.getShapePageTransform(e[0]);return s.point=o.applyToPoint(s.point),s}const r=Z.FromPoints(e.flatMap(s=>{const o=this.getShapePageTransform(s);return o?o.applyToPoints(this.getShapeGeometry(s).bounds.corners):[]}).map(s=>s.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),s=this.getZoomLevel();return new Z(n,r,e.width*s,e.height*s)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const e=this.getFocusedGroupId();return e?this.getShape(e):void 0}setFocusedGroup(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(n!==null){const r=this.getShape(n);if(!r)throw Error(`Editor.setFocusedGroup: Shape with id ${n} does not exist`);if(!this.isShapeOfType(r,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${r.type}`)}return n===this.getFocusedGroupId()?this:this.run(()=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:n}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const e=this.getFocusedGroup();if(e){const n=this.findShapeAncestor(e,r=>this.isShapeOfType(r,"group"));this.setFocusedGroup((n==null?void 0:n.id)??null),this.select(e.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const e=this.getEditingShapeId();return e?this.getShape(e):void 0}setEditingShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;if(n!==this.getEditingShapeId()){if(n){const r=this.getShape(n);if(r&&this.getShapeUtil(r).canEdit(r))return this.run(()=>{this._updateCurrentPageState({editingShapeId:n})},{history:"ignore"}),this}this.run(()=>{this._updateCurrentPageState({editingShapeId:null})},{history:"ignore"})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const e=this.getHoveredShapeId();return e?this.getShape(e):void 0}setHoveredShape(e){const n=typeof e=="string"?e:(e==null?void 0:e.id)??null;return n===this.getHoveredShapeId()?this:(this.run(()=>{this.updateCurrentPageState({hoveredShapeId:n})},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const e=this.getHintingShapeIds();return me(e.map(n=>this.getShape(n)))}setHintingShapes(e){const n=typeof e[0]=="string"?e:e.map(r=>r.id);return this.run(()=>{this._updateCurrentPageState({hintingShapeIds:y0(n)})},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const e=this.getErasingShapeIds();return me(e.map(n=>this.getShape(n)))}setErasingShapes(e){const n=typeof e[0]=="string"?e:e.map(s=>s.id);n.sort();const r=this.getErasingShapeIds();return this.run(()=>{if(n.length===r.length){for(let s=0;s<n.length;s++)if(n[s]!==r[s]){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),s=this.getShapeUtil(r);r&&s.canCrop(r)&&this.updateCurrentPageState({croppingShapeId:n})}},{history:"ignore"}),this}_unsafe_getCameraId(){return Is.createId(this.getCurrentPageId())}getCamera(){const e=this.store.get(this._unsafe_getCameraId());if(this._isLockedOnFollowingUser.get()){const n=this.getCameraForFollowing();if(n)return{...e,...n}}return e}getViewportPageBoundsForFollowing(){const e=this.getInstanceState().followingUserId;if(!e)return null;const n=this.getCollaborators().find(h=>h.userId===e);if(!n||!n.camera||!n.screenBounds)return null;const{w:r,h:s}=n.screenBounds,{x:o,y:i,z:a}=n.camera,l=new Z(-o,-i,r/a,s/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}=LI(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}=LI(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:s,y:o,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,f=Math.min(h.padding.y,u.w/2),p=Math.min(h.padding.x,u.h/2),g=Z.From(a.constraints.bounds),m=(u.w-p*2)/g.w,v=(u.h-f*2)/g.h,y=this.getBaseZoom(),S=c*y,b=l*y;if(n!=null&&n.reset&&(i=this.getInitialZoom()),i<b||i>S){const{x:L,y:M,z:O}=r,F=-L+u.w/O/2,B=-M+u.h/O/2;i=Bt(i,b,S);const K=-L+u.w/i/2,R=-M+u.h/i/2;s=L+K-F,o=M+R-B}const P=p/i-g.x,C=f/i-g.y,_=(u.w-p*2)/i-g.w,E=(u.h-f*2)/i-g.h,k=P+_*h.origin.x,D=C+E*h.origin.y,T=typeof h.behavior=="string"?h.behavior:h.behavior.x,j=typeof h.behavior=="string"?h.behavior:h.behavior.y;if(n!=null&&n.reset)s=k,o=D;else{switch(T){case"fixed":{s=k;break}case"contain":{i<m?s=k:s=Bt(s,P+_,P);break}case"inside":{i<m?s=Bt(s,P,(u.w-p)/i-g.w):s=Bt(s,P+_,P);break}case"outside":{s=Bt(s,p/i-g.w,(u.w-p)/i);break}case"free":break;default:throw Ot(T)}switch(j){case"fixed":{o=D;break}case"contain":{i<v?o=D:o=Bt(o,C+E,C);break}case"inside":{i<v?o=Bt(o,C,(u.h-f)/i-g.h):o=Bt(o,C+E,C);break}case"outside":{o=Bt(o,f/i-g.h,(u.h-f)/i);break}case"free":break;default:throw Ot(j)}}}else if(i>c||i<l){const{x:h,y:f,z:p}=r;i=Bt(i,l,c),s=h+(-h+u.w/i/2)-(-h+u.w/p/2),o=f+(-f+u.h/i/2)-(-f+u.h/p/2)}}return{x:s,y:o,z:i}}_setCamera(e,n){const r=this.getCamera(),{x:s,y:o,z:i}=this.getConstrainedCamera(e,n);return r.x===s&&r.y===o&&r.z===i?this:(js(()=>{const a={...r,x:s,y:o,z:i};this.run(()=>{this.store.put([a])},{history:"ignore"});const{currentScreenPoint:l,currentPagePoint:c}=this.inputs,{screenBounds:u}=this.store.unsafeGetWithoutCapture(bn);if(l.x/i-s!==c.x||l.y/i-o!==c.y){const h={type:"pointer",target:"canvas",name:"pointer_move",point:x.AddXY(l,u.x,u.y),pointerId:eI.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 s=x.Cast(e);Number.isFinite(s.x)||(s.x=0),Number.isFinite(s.y)||(s.y=0),(s.z===void 0||!Number.isFinite(s.z))&&(e.z=this.getZoomLevel());const o=this.getConstrainedCamera(s,n);if(n!=null&&n.animation){const{width:i,height:a}=this.getViewportScreenBounds();this._animateToViewport(new Z(-o.x,-o.y,i/o.z,a/o.z),n)}else this._setCamera(o,{...n,force:!0});return this}centerOnPoint(e,n){const{isLocked:r}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const{width:s,height:o}=this.getViewportPageBounds();return this.setCamera(new x(-(e.x-s/2),-(e.y-o/2),this.getCamera().z),n),this}zoomToFit(e){const n=[...this.getCurrentPageShapeIds()];if(n.length<=0)return this;const r=Z.Common(me(n.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(r,e),this}resetZoom(e=this.getViewportScreenCenter(),n){const{isLocked:r,constraints:s}=this.getCameraOptions();if(r&&!(n!=null&&n.force))return this;const o=this.getCamera(),{x:i,y:a,z:l}=o,{x:c,y:u}=e;let h=1;if(s){const f=this.getInitialZoom();l!==f&&(h=f)}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:s,y:o,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,f=a[u]*l;if(!(f-i<=(f-h)/2)){c=f;break}}this.setCamera(new x(s+(e.x/c-e.x)-(e.x/i-e.x),o+(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:s}=this.getCameraOptions();if(s!==null&&s.length>1){const o=this.getBaseZoom(),{x:i,y:a,z:l}=this.getCamera();let c=s[0]*o;for(let u=s.length-1;u>0;u--){const h=s[u-1]*o,f=s[u]*o;if(!(f-l>=(f-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 s=this.getViewportScreenBounds(),o=(n==null?void 0:n.inset)??Math.min(vX,s.width*.28),i=this.getBaseZoom(),a=r.zoomSteps[0],l=Ht(r.zoomSteps);let c=Bt(Math.min((s.width-o)/e.w,(s.height-o)/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+(s.width-e.w*c)/2/c,-e.y+(s.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:s,start:o,end:i}=this._viewportAnimation;if(n>s){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new x(-i.x,-i.y,this.getViewportScreenBounds().width/i.width));return}const a=s-n,l=r(1-a/s),c=o.minX+(i.minX-o.minX)*l,u=o.minY+(i.minY-o.minY)*l,h=o.maxX+(i.maxX-o.maxX)*l;this._setCamera(new x(-c,-u,this.getViewportScreenBounds().width/(h-c)),{force:!0})}_animateToViewport(e,n={animation:Hy}){const{animation:r,...s}=n;if(!r)return;const{duration:o=0,easing:i=Dt.easeInOutCubic}=r,a=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),o===0||a===0?this._setCamera(new x(-e.x,-e.y,this.getViewportScreenBounds().width/e.width),{...s}):(this._viewportAnimation={elapsed:0,duration:o/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:s,friction:o=this.options.cameraSlideFriction,direction:i,speedThreshold:a=.01}=e;let l=Math.min(s,1);const c=()=>{this.off("tick",u),this.off("stop-camera-animation",c)};this.once("stop-camera-animation",c);const u=h=>{const{x:f,y:p,z:g}=this.getCamera(),m=x.Mul(i,l*h/g);l*=1-o,l<a?c():this._setCamera(new x(f+m.x,p+m.y,g))};return this.on("tick",u),this}zoomToUser(e,n={animation:{duration:500}}){const r=this.getCollaborators().find(o=>o.userId===e);if(!r)return this;const s=r.cursor;return s?(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(s,n);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,e]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],l=a.indexOf(e);l<0||(a.splice(l,1),this.updateInstanceState({highlightedUserIds:a}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(e,n=!1){if(e instanceof HTMLElement){const a=e.getBoundingClientRect();e=new Z(a.left||a.x,a.top||a.y,Math.max(a.width,1),Math.max(a.height,1))}else e.width=Math.max(e.width,1),e.height=Math.max(e.height,1);const r=[e.minY!==0,!di(document.body.scrollWidth,e.maxX,1),!di(document.body.scrollHeight,e.maxY,1),e.minX!==0],{_willSetInitialBounds:s}=this;this._willSetInitialBounds=!1;const{screenBounds:o,insets:i}=this.getInstanceState();if(e.equals(o)&&r.every((a,l)=>a===i[l]))return this;if(s)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:s}=this.getInstanceState().screenBounds;return new Z(e,n,r,s)}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:s,z:o}=this.getCamera();return new Z(-r,-s,e/o,n/o)}screenToPage(e){const{screenBounds:n}=this.store.unsafeGetWithoutCapture(bn),{x:r,y:s,z:o=1}=this.getCamera();return new x((e.x-n.x)/o-r,(e.y-n.y)/o-s,e.z??.5)}pageToScreen(e){const{screenBounds:n}=this.store.unsafeGetWithoutCapture(bn),{x:r,y:s,z:o=1}=this.getCamera();return new x((e.x+r)*o+n.x,(e.y+s)*o+n.y,e.z??.5)}pageToViewport(e){const{x:n,y:r,z:s=1}=this.getCamera();return new x((e.x+n)*s,(e.y+r)*s,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=>T9(e.filter(o=>o.userId===r),o=>o.lastActivityTimestamp??0)):fo}getCollaboratorsOnCurrentPage(){const e=this.getCurrentPageId();return this.getCollaborators().filter(n=>n.currentPageId===e)}startFollowingUser(e){this.stopFollowingUser();const n=this._getCollaboratorsQuery().get().filter(o=>o.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(o=>o.followingUserId===r))return this;const s=G("latestLeaderPresence",()=>this.getCollaborators().find(o=>o.userId===e));return js(()=>{this.updateInstanceState({followingUserId:e},{history:"ignore"});const o=As("update current page",()=>{const l=s.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=()=>{o(),this._isLockedOnFollowingUser.set(!1),this.off("frame",a),this.off("stop-following",i)},a=()=>{if(!s.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(),f=Math.abs(u.minX-h.minX)+Math.abs(u.maxX-h.maxX),p=Math.abs(u.minY-h.minY)+Math.abs(u.maxY-h.maxY);if(f<this.options.followChaseViewportSnap&&p<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const g=Bt(c*.5,.1,.8),m=new Z(_e(h.minX,u.minX,g),_e(h.minY,u.minY,g),_e(h.width,u.width,g),_e(h.height,u.height,g)),v=new x(-m.x,-m.y,this.getViewportScreenBounds().width/m.width);this.stopCameraAnimation(),this._setCamera(v)};this.once("stop-following",i),this.addListener("frame",a),a()}),this}stopFollowingUser(){return this.run(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")},{history:"ignore"}),this}getUnorderedRenderingShapes(e){const n=[];let r=this.options.maxShapesPerPage*2,s=this.options.maxShapesPerPage;const o=this.getErasingShapeIds(),i=(l,c,u)=>{const h=this.getShape(l);if(!h||this.isShapeHidden(h))return;c*=h.opacity;let f=!1;const p=this.getShapeUtil(h);e&&(f=!u&&o.includes(l),f&&(c*=.32)),n.push({id:l,shape:h,util:p,index:r,backgroundIndex:s,opacity:c}),r+=1,s+=1;const g=this.getSortedChildIdsForParent(l);if(!g.length)return;let m=null;p.providesBackgroundForChildren(h)&&(m=s,s=r,r+=this.options.maxShapesPerPage);for(const v of g)i(v,c,u||f);m!==null&&(s=m)},a=e?[this.getCurrentPage()]:this.getPages();for(const l of a)for(const c of this.getSortedChildIdsForParent(l.id))i(c,1,!1);return n}_decayCameraStateTimeout(e){this._cameraStateTimeoutRemaining-=e,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))}_tickCameraState(){this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(iB)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return Array.from(this._getAllPagesQuery().get()).sort(cn)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(e){return this.store.get(typeof e=="string"?e:e.id)}getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getCurrentPageShapeIdsSorted(){return Array.from(this.getCurrentPageShapeIds()).sort()}getPageShapeIds(e){const n=typeof e=="string"?e:e.id,r=this.store.query.exec("shape",{parentId:{eq:n}});return this.getShapeAndDescendantIds(r.map(s=>s.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=GQ(e.name??"Page 1",n.map(i=>i.name));let s=e.index;(!s||n.some(i=>i.index===s))&&(s=_s(n[n.length-1].index));const o=yr.create({meta:{},...e,name:r,index:s});this.store.put([o])}),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 s=this.getPage(n);if(s){if(n===this.getCurrentPageId()){const o=r.findIndex(a=>a.id===n),i=r[o-1]??r[o+1];this.setCurrentPage(i.id)}this.store.remove([s.id])}}),this}duplicatePage(e,n=yr.createId()){if(this.getPages().length>=this.options.maxPages)return this;const r=typeof e=="string"?e:e.id,s=this.getPage(r);if(!s)return this;const o={...this.getCamera()},i=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.run(()=>{var c;const a=this.getPages(),l=$u(s.index,(c=a[a.indexOf(s)+1])==null?void 0:c.index);if(this.createPage({name:s.name+" Copy",id:n,index:l}),this.setCurrentPage(n),this.setCamera(o),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:s=1,shouldResolveToOriginal:o=!1}=n,a=Math.max(.125,(u=>Math.pow(2,Math.ceil(Math.log2(u))))(s)),l="connection"in navigator?navigator.connection.effectiveType:null,c=this.getInstanceState().devicePixelRatio;return await this.store.props.assets.resolve(r,{screenScale:s||1,steppedScreenScale:a,dpr:c,networkEffectiveType:l,shouldResolveToOriginal:o})}async uploadAsset(e,n,r){return await this.store.props.assets.upload(e,n,r)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",e=>this.getShapeUtil(e).getGeometry(e),(e,n)=>e.props===n.props)}getShapeGeometry(e){return this._getShapeGeometryCache().get(typeof e=="string"?e:e.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",e=>{var n,r;return(r=(n=this.getShapeUtil(e)).getHandles)==null?void 0:r.call(n,e)})}getShapeHandles(e){return this._getShapeHandlesCache().get(typeof e=="string"?e:e.id)}getShapeLocalTransform(e){const n=typeof e=="string"?e:e.id,r=this.getShape(n);if(!r)throw Error("Editor.getTransform: shape not found");return q.Identity().translate(r.x,r.y).rotate(r.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",e=>{if(Rn(e.parentId))return this.getShapeLocalTransform(e);const n=this._getShapePageTransformCache().get(e.parentId)??q.Identity();return q.Compose(n,this.getShapeLocalTransform(e))})}getShapeParentTransform(e){const n=typeof e=="string"?e:e.id,r=this.getShape(n);return!r||Rn(r.parentId)?q.Identity():this._getShapePageTransformCache().get(r.parentId)??q.Identity()}getShapePageTransform(e){const n=typeof e=="string"?e:e.id;return this._getShapePageTransformCache().get(n)??q.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",e=>{const n=this._getShapePageTransformCache().get(e.id);return n?Z.FromPoints(q.applyToPoints(n,this.getShapeGeometry(e).vertices)):new Z})}getShapePageBounds(e){return this._getShapePageBoundsCache().get(typeof e=="string"?e:e.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",e=>{const n=this._getShapeMaskCache().get(e.id);if(!n)return;if(n.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const r=this._getShapePageTransformCache().get(e.id);return r?`polygon(${q.applyToPoints(q.Inverse(r),n).map(o=>`${o.x}px ${o.y}px`).join(",")})`:void 0})}getShapeClipPath(e){return this._getShapeClipPathCache().get(typeof e=="string"?e:e.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",e=>{if(Rn(e.parentId))return;const n=this.getShapeAncestors(e.id).filter(s=>this.isShapeOfType(s,"frame"));return n.length===0?void 0:n.map(s=>this._getShapePageTransformCache().get(s.id).applyToPoints(this.getShapeGeometry(s).vertices)).reduce((s,o)=>{if(!(o&&s))return;const i=xI(s,o);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:s}=n;if(s.every((i,a)=>i&&x.Equals(i,r[a])))return n.clone();const o=xI(r,s);return o?Z.FromPoints(o):void 0}return n})}getShapeAncestors(e,n=[]){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return n;const o=s.parentId;if(Rn(o))return n.reverse(),n;const i=this.store.get(o);return i?(n.push(i),this.getShapeAncestors(i,n)):n}findShapeAncestor(e,n){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return;const o=s.parentId;if(Rn(o))return;const i=this.getShape(o);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,s=r&&this.getShape(r);return s?s.parentId===n?!0:this.hasAncestor(this.getShapeParent(s),n):!1}findCommonAncestor(e,n){var l;if(e.length===0)return;const r=typeof e[0]=="string"?e:e.map(c=>c.id),s=me(r.map(c=>this.getShape(c)));if(s.length===1){const c=s[0].parentId;return Rn(c)?void 0:n?(l=this.findShapeAncestor(s[0],n))==null?void 0:l.id:c}const[o,...i]=s;let a=this.getShapeParent(o);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 JQ(this)}getCulledShapes(){const e=this._notVisibleShapes().get(),n=this.getSelectedShapeIds(),r=this.getEditingShapeId(),s=new Set(e);return r&&s.delete(r),n.forEach(o=>{s.delete(o)}),s}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(),s=this.getViewportPageBounds(),{filter:o,margin:i=0,hitLocked:a=!1,hitLabels:l=!1,hitInside:c=!1,hitFrameInside:u=!1}=n;let h=1/0,f=null,p=1/0,g=null;const m=(n.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(v=>{if(v.isLocked&&!a||this.isShapeHidden(v)||this.isShapeOfType(v,"group"))return!1;const y=this.getShapeMask(v);return y&&!hr(e,y)?!1:o?o(v):!0});for(let v=m.length-1;v>=0;v--){const y=m[v],S=this.getShapeGeometry(y),b=S instanceof $r,P=this.getPointInShapeSpace(y,e);if(this.isShapeOfType(y,"frame")||(this.isShapeOfType(y,"arrow")||this.isShapeOfType(y,"geo")&&y.props.fill==="none")&&y.props.text.trim()){for(const _ of S.children)if(_.isLabel&&_.isPointInBounds(P))return y}if(this.isShapeOfType(y,"frame")){const _=S.distanceToPoint(P,c);if(Math.abs(_)<=i)return g||y;if(S.hitTestPoint(P,0,!0))return g||f||(u?y:void 0);continue}let C;if(b){let _=1/0;for(const E of S.children){if(E.isLabel&&!l)continue;const k=E.distanceToPoint(P,c);k<_&&(_=k)}C=_}else i===0&&(S.bounds.w<1||S.bounds.h<1)||S.bounds.containsPoint(P,i)?C=S.distanceToPoint(P,c):C=1/0;if(S.isClosed){if(C<=i){if(S.isFilled||b&&S.children[0].isFilled)return g||y;if(this.getShapePageBounds(y).contains(s))continue;if(Math.abs(C)<i)Math.abs(C)<p&&(p=Math.abs(C),g=y);else if(!g){const{area:_}=S;_<h&&(h=_,f=y)}}}else if(C<this.options.hitTestMargin/r)return y}return g||f||void 0}getShapesAtPoint(e,n={}){return this.getCurrentPageShapes().filter(r=>!this.isShapeHidden(r)&&this.isPointInShape(r,e,n))}isPointInShape(e,n,r={}){const{hitInside:s=!1,margin:o=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),o,s)}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,s=this.getShape(r);if(!s)return new x(0,0);if(Rn(s.parentId))return x.From(n);const o=this.getShapePageTransform(s.parentId);return o?o.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,s=n.length;r<s;r++)BR(this,n[r],e);return e}getCurrentPageRenderingShapesSorted(){const e=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:n})=>!e.has(n)&&!this.isShapeHidden(n))}isShapeOfType(e,n){const r=typeof e=="string"?this.getShape(e):e;return r?r.type===n:!1}getShape(e){const n=typeof e=="string"?e:e.id;if(Fn(n))return this.store.get(n)}getShapeParent(e){const n=typeof e=="string"?e:e==null?void 0:e.id;if(!n)return;const r=this.getShape(n);if(!(r===void 0||!Fn(r.parentId)))return this.store.get(r.parentId)}getShapeNearestSibling(e,n){return n?n.parentId===e.parentId?n:this.findShapeAncestor(n,s=>s.parentId===e.parentId):void 0}isShapeInPage(e,n=this.getCurrentPageId()){const r=typeof e=="string"?e:e.id,s=this.getShape(r);if(!s)return!1;let o=!1;if(s.parentId===n)o=!0;else{let i=this.getShape(s.parentId);e:for(;i;){if(i.parentId===n){o=!0;break e}i=this.getShape(i.parentId)}}return o}getAncestorPageId(e){const n=typeof e=="string"?e:e==null?void 0:e.id,r=n&&this.getShape(n);if(r)return Rn(r.parentId)?r.parentId:this.getAncestorPageId(this.getShape(r.parentId))}reparentShapes(e,n,r){const s=typeof e[0]=="string"?e:e.map(f=>f.id);if(s.length===0)return this;const o=[],i=Rn(n)?q.Identity():this.getShapePageTransform(n),a=i.rotation();let l=[];const c=me(this.getSortedChildIdsForParent(n).map(f=>this.getShape(f)));if(r){const f=c.find(p=>p.index===r);if(f){const p=c[c.indexOf(f)+1];p?l=Ol(r,p.index,s.length):l=py(r,s.length)}else{const p=c.sort(cn).find(g=>g.index>r);p?l=Ol(r,p.index,s.length):l=py(r,s.length)}}else{const f=c.length&&c[c.length-1];l=f?py(f.index,s.length):Fu(s.length)}const u=i.clone().invert(),h=me(s.map(f=>this.getShape(f)));return this.run(()=>{for(let f=0;f<h.length;f++){const p=h[f],g=this.getShapePageTransform(p);if(!g)continue;const m=g.point();if(!m)continue;const v=u.applyToPoint(m),y=g.rotation()-a;o.push({id:p.id,type:p.type,parentId:n,x:v.x,y:v.y,rotation:y,index:l[f]})}this.updateShapes(o)},{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 s=this.getShape(r[r.length-1]);return _s(s.index)}getSortedChildIdsForParent(e){const n=typeof e=="string"?e:e.id,r=this._parentIdsToChildIds.get()[n];return r||fo}visitDescendants(e,n){const r=typeof e=="string"?e:e.id,s=this.getSortedChildIdsForParent(r);for(const o of s)n(o)!==!1&&this.visitDescendants(o,n);return this}getShapeAndDescendantIds(e){const n=new Set;for(const r of e.map(s=>this.getShape(s)).sort(cn))n.add(r.id),this.visitDescendants(r,s=>{n.add(s)});return n}getDroppingOverShape(e,n=[]){const r=this.getCurrentPageShapesSorted();for(let s=r.length-1;s>=0;s--){const o=r[s];if(this.isShapeHidden(o)||this.getSelectedShapeIds().includes(o.id)||!this.getShapeUtil(o).canDropShapes(o,n)||n.find(a=>a.id===o.id||this.hasAncestor(o,a.id)))continue;const i=this.getShapeMaskedPageBounds(o.id);if(i&&i.containsPoint(e)&&this.getShapeGeometry(o).hitTestPoint(this.getPointInShapeSpace(o,e),0,!0))return o}}getOutermostSelectableShape(e,n){const r=typeof e=="string"?e:e.id,s=this.getShape(r);let o=s,i=s;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))o=i;else if((a==null?void 0:a.id)===i.id)break;i=this.getShapeParent(i)}return o}_getBindingsIndexCache(){const e=ZQ(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(s=>s.fromId===r&&s.type===n)}getBindingsToShape(e,n){const r=typeof e=="string"?e:e.id;return this.getBindingsInvolvingShape(r).filter(s=>s.toId===r&&s.type===n)}getBindingsInvolvingShape(e,n){const r=typeof e=="string"?e:e.id,s=this._getBindingsIndexCache().get(r)??fo;return n?s.filter(o=>o.type===n):s}createBindings(e){const n=[];for(const r of e){const s=this.getShape(r.fromId),o=this.getShape(r.toId);if(!s||!o||!this.canBindShapes({fromShape:s,toShape:o,binding:r}))continue;const a=this.getBindingUtil(r.type).getDefaultProps(),l=this.store.schema.types.binding.create({...r,id:r.id??Ji(),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 s=this.getBinding(r.id);if(!s)continue;const o=ys(s,r);if(o===s)continue;const i=this.getShape(o.fromId),a=this.getShape(o.toId);!i||!a||this.canBindShapes({fromShape:i,toShape:a,binding:o})&&n.push(o)}return this.store.put(n),this}updateBinding(e){return this.updateBindings([e])}deleteBindings(e,{isolateShapes:n=!1}={}){const r=e.map(s=>typeof s=="string"?s:s.id);return n?this.store.atomic(()=>{var s,o;for(const i of r){const a=this.getBinding(i);if(!a)continue;const l=this.getBindingUtil(a);(s=l.onBeforeIsolateFromShape)==null||s.call(l,{binding:a,removedShape:this.getShape(a.toId)}),(o=l.onBeforeIsolateToShape)==null||o.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 s=typeof e=="string"?e:e.type,o=typeof n=="string"?n:n.type,i=typeof r=="string"?r:r.type,a={fromShapeType:s,toShapeType:o,bindingType:i};return s===o?this.getShapeUtil(s).canBind(a):this.getShapeUtil(s).canBind(a)&&this.getShapeUtil(o).canBind(a)}rotateShapesBy(e,n,r){const s=typeof e[0]=="string"?e:e.map(i=>i.id);if(s.length<=0)return this;const o=pO({editor:this,ids:s});return o?(df({delta:n,snapshot:o,editor:this,stage:"one-off",centerOverride:r==null?void 0:r.center}),this):this}getChangesToTranslateShape(e,n){var o,i,a;let r=e;const s=this.getShapeUtil(e);return r=ys(r,((o=s.onTranslateStart)==null?void 0:o.call(s,r))??void 0),r=ys(r,{id:e.id,type:e.type,x:n.x,y:n.y}),r=ys(r,((i=s.onTranslate)==null?void 0:i.call(s,e,r))??void 0),r=ys(r,((a=s.onTranslateEnd)==null?void 0:a.call(s,e,r))??void 0),r}nudgeShapes(e,n){const r=typeof e[0]=="string"?e:e.map(o=>o.id);if(r.length<=0)return this;const s=[];for(const o of r){const i=this.getShape(o),a=x.From(n),l=this.getShapeParentTransform(i);l&&a.rot(-l.rotation()),s.push(this.getChangesToTranslateShape(i,a.add(i)))}return this.updateShapes(s),this}duplicateShapes(e,n){return this.run(()=>{const r=typeof e[0]=="string"?e:e.map(f=>f.id);if(r.length<=0)return this;const s=new Set(r),o=this.getShapeAndDescendantIds(r),i=[...o].reverse(),a=new Map;for(const f of o)a.set(f,Ke());const{shapesToCreateWithOriginals:l,bindingsToCreate:c}=RI(this,o,f=>{const p=[];for(const m of f){const v=this.getBinding(m);if(!v)continue;const y=Ji();p.push({...v,id:y,fromId:zn(a.get(v.fromId)),toId:zn(a.get(v.toId))})}const g=[];for(const m of i){const v=zn(a.get(m)),y=this.getShape(m);if(!y)continue;let S=0,b=0;if(n&&s.has(m)){const P=this.getShapeParentTransform(y),C=new x(n.x,n.y).rot(-P.rotation());S=C.x,b=C.y}g.push({shape:{...y,id:v,x:y.x+S,y:y.y+b,index:"a1",parentId:a.get(y.parentId)??y.parentId},originalShape:y})}return{shapesToCreateWithOriginals:g,bindingsToCreate:p}});l.forEach(({shape:f,originalShape:p})=>{const g=p.parentId,m=this.getSortedChildIdsForParent(g),v=m.indexOf(p.id),y=m[v+1],S=y?this.getShape(y):void 0,b=$u(p.index,S==null?void 0:S.index);f.index=b});const u=l.map(({shape:f})=>f);if(u.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){vh(this);return}if(this.createShapes(u),this.createBindings(c),this.setSelectedShapes(me(r.map(f=>a.get(f)))),n!==void 0){const f=this.getSelectionPageBounds(),p=this.getViewportPageBounds();f&&!p.contains(f)&&this.centerOnPoint(f.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 s=this.getCurrentPageId();if(n===s)return this;if(!this.store.has(n))return this;const o=this.getContentFromCurrentPage(r);if(!o)return this;if(this.getPageShapeIds(n).size+o.shapes.length>this.options.maxShapesPerPage)return vh(this,n),this;const i=this.getCamera().z;return this.run(()=>{this.deleteShapes(r),this.setCurrentPage(n),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(o,{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,s=!0;const o=[];for(const i of n){const a=this.getShape(i);a&&(o.push(a),a.isLocked?s=!1:r=!1)}return this.run(()=>{s?(this.updateShapes(o.map(i=>({id:i.id,type:i.type,isLocked:!0}))),this.setSelectedShapes([])):r?this.updateShapes(o.map(i=>({id:i.id,type:i.type,isLocked:!1}))):this.updateShapes(o.map(i=>({id:i.id,type:i.type,isLocked:!0})))}),this}sendToBack(e){const n=typeof e[0]=="string"?e:e.map(s=>s.id),r=yh(this,"toBack",n,{considerAllShapes:!0});return r&&this.updateShapes(r),this}sendBackward(e,n={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id),s=yh(this,"backward",r,n);return s&&this.updateShapes(s),this}bringForward(e,n={}){const r=typeof e[0]=="string"?e:e.map(o=>o.id),s=yh(this,"forward",r,n);return s&&this.updateShapes(s),this}bringToFront(e){const n=typeof e[0]=="string"?e:e.map(s=>s.id),r=yh(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 s=me(r.map(i=>this.getShape(i)));if(!s.length)return this;s=me(s.map(i=>this.isShapeOfType(i,"group")?this.getSortedChildIdsForParent(i.id).map(a=>this.getShape(a)):i).flat());const o=Z.Common(me(s.map(i=>this.getShapePageBounds(i)))).center;return this.run(()=>{for(const i of s){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:o,scaleAxisRotation:0})}}),this}stackShapes(e,n,r){const s=typeof e[0]=="string"?e:e.map(m=>m.id);if(this.getIsReadonly())return this;const o=s.map(m=>this.getShape(m)).filter(m=>m?this.getShapeUtil(m).canBeLaidOut(m):!1),i=o.length;if(r===0&&i<3||i<2)return this;const a=Object.fromEntries(o.map(m=>[m.id,this.getShapePageBounds(m)]));let l,c,u,h;n==="horizontal"?(l="x",c="minX",u="maxX",h="width"):(l="y",c="minY",u="maxY",h="height");let f;if(r===0){const m=[];o.sort((y,S)=>a[y.id][c]-a[S.id][c]);for(let y=0;y<i-1;y++){const S=o[y],b=o[y+1],P=a[S.id],_=a[b.id][c]-P[u],E=m.find(k=>k.gap===_);E?E.count++:m.push({gap:_,count:1})}let v=0;m.forEach(y=>{y.count>v&&(v=y.count,f=y.gap)}),v===1&&(f=Math.max(0,m.reduce((y,S)=>y+S.gap*S.count,0)/(i-1)))}else f=r;const p=[];let g=a[o[0].id][u];return o.forEach((m,v)=>{var C,_;if(v===0)return;const y={x:0,y:0};y[l]=g+f-a[m.id][l];const S=this.getShapeParent(m),b=S?x.Rot(y,-this.getShapePageTransform(S).decompose().rotation):y,P=(_=(C=this.getShapeUtil(m)).onTranslateStart)==null?void 0:_.call(C,m);p.push(P?{...P,[l]:m[l]+b[l]}:{id:m.id,type:m.type,[l]:m[l]+b[l]}),g+=a[m.id][h]+f}),this.updateShapes(p),this}packShapes(e,n){var _,E;const r=typeof e[0]=="string"?e:e.map(k=>k.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const s=r.map(k=>this.getShape(k)).filter(k=>k?this.getShapeUtil(k).canBeLaidOut(k):!1),o={},i={};let a,l,c=0;for(let k=0;k<s.length;k++)a=s[k],l=this.getShapePageBounds(a),o[a.id]=l,i[a.id]=l.clone(),c+=l.width*l.height;const u=Z.Common(me(Object.values(o))),h=u.width;s.sort((k,D)=>o[D.id].height-o[k.id].height);const f=Math.max(Math.ceil(Math.sqrt(c/.95)),h),p=[new Z(u.x,u.y,f,1/0)];let g=0,m=0,v,y;for(let k=0;k<s.length;k++){a=s[k],l=i[a.id];for(let D=p.length-1;D>=0;D--)if(v=p[D],!(l.width>v.width||l.height>v.height)){l.x=v.x,l.y=v.y,m=Math.max(m,l.maxY),g=Math.max(g,l.maxX),l.width===v.width&&l.height===v.height?(y=p.pop(),D<p.length&&(p[D]=y)):l.height===v.height?(v.x+=l.width+n,v.width-=l.width+n):l.width===v.width?(v.y+=l.height+n,v.height-=l.height+n):(p.push(new Z(v.x+(l.width+n),v.y,v.width-(l.width+n),l.height)),v.y+=l.height+n,v.height-=l.height+n);break}}const S=Z.Common(Object.values(i)),b=x.Sub(u.center,S.center);let P;const C=[];for(let k=0;k<s.length;k++){a=s[k],l=o[a.id],P=i[a.id];const D=x.Sub(P.point,l.point).add(b),T=this.getShapeParentTransform(a);T&&D.rot(-T.rotation());const j={id:a.id,type:a.type,x:a.x+D.x,y:a.y+D.y},L=(E=(_=this.getShapeUtil(a)).onTranslateStart)==null?void 0:E.call(_,{...a,...j});L?C.push({...j,...L}):C.push(j)}return C.length&&this.updateShapes(C),this}alignShapes(e,n){const r=typeof e[0]=="string"?e:e.map(l=>l.id);if(this.getIsReadonly())return this;if(r.length<2)return this;const s=me(r.map(l=>this.getShape(l))),o=Object.fromEntries(s.map(l=>[l.id,this.getShapePageBounds(l)])),i=Z.Common(me(Object.values(o))),a=[];return s.forEach(l=>{const c=o[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),f=h?x.Rot(u,-this.getShapePageTransform(h).decompose().rotation):u;a.push(this.getChangesToTranslateShape(l,x.Add(l,f)))}),this.updateShapes(a),this}distributeShapes(e,n){const r=typeof e[0]=="string"?e:e.map(S=>S.id);if(this.getIsReadonly())return this;if(r.length<3)return this;const s=r.length,o=me(r.map(S=>this.getShape(S))),i=Object.fromEntries(o.map(S=>[S.id,this.getShapePageBounds(S)]));let a,l,c,u,h;n==="horizontal"?(a="x",l="minX",c="maxX",u="midX",h="width"):(a="y",l="minY",c="maxY",u="midY",h="height");const f=[],p=o.sort((S,b)=>i[S.id][l]-i[b.id][l])[0],g=o.sort((S,b)=>i[b.id][c]-i[S.id][c])[0],m=i[p.id][u],v=(i[g.id][u]-m)/(s-1),y=m+v;return o.filter(S=>S!==p&&S!==g).sort((S,b)=>i[S.id][u]-i[b.id][u]).forEach((S,b)=>{const P={x:0,y:0};P[a]=y+v*b-i[S.id][h]/2-i[S.id][a];const C=this.getShapeParent(S),_=C?x.Rot(P,-this.getShapePageTransform(C).rotation()):P;f.push(this.getChangesToTranslateShape(S,x.Add(S,_)))}),this.updateShapes(f),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 s=me(r.map(l=>this.getShape(l))),o=Object.fromEntries(r.map(l=>[l,this.getShapeGeometry(l).bounds])),i=Object.fromEntries(r.map(l=>[l,this.getShapePageBounds(l)])),a=Z.Common(me(Object.values(i)));switch(n){case"vertical":{this.run(()=>{for(const l of s){if(this.getShapePageTransform(l).rotation()%Fe)continue;const u=o[l.id],h=i[l.id],f=new x(0,a.minY-h.minY),p=this.getShapeParentTransform(l);p&&f.rot(-p.rotation());const{x:g,y:m}=x.Add(f,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:m}]);const v=new x(1,a.height/h.height);this.resizeShape(l.id,v,{initialBounds:u,scaleOrigin:new x(h.center.x,a.minY),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}case"horizontal":{this.run(()=>{for(const l of s){const c=o[l.id],u=i[l.id];if(this.getShapePageTransform(l).rotation()%Fe)continue;const f=new x(a.minX-u.minX,0),p=this.getShapeParentTransform(l);p&&f.rot(-p.rotation());const{x:g,y:m}=x.Add(f,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:m}]);const v=new x(a.width/u.width,1);this.resizeShape(l.id,v,{initialBounds:c,scaleOrigin:new x(a.minX,u.center.y),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}}return this}resizeShape(e,n,r={}){var p,g,m;const s=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 o=r.initialShape??this.getShape(s);if(!o)return this;const i=r.scaleOrigin??((p=this.getShapePageBounds(s))==null?void 0:p.center);if(!i)return this;const a=r.initialPageTransform?q.Cast(r.initialPageTransform):this.getShapePageTransform(s);if(!a)return this;const l=a.rotation();if(l==null)return this;const c=r.scaleAxisRotation??l,u=r.initialBounds??this.getShapeGeometry(s).bounds;if(!u)return this;const h=r.isAspectRatioLocked??this.getShapeUtil(o).isAspectRatioLocked(o);if(!oj(l,c))return this._resizeUnalignedShape(s,n,{...r,initialBounds:u,scaleOrigin:i,scaleAxisRotation:c,initialPageTransform:a,isAspectRatioLocked:h,initialShape:o});const f=this.getShapeUtil(o);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)),f.onResize&&f.canResize(o)){const v=this._scalePagePoint(q.applyToPoint(a,new x(0,0)),i,n,c),y=this.getPointInParentSpace(o.id,v),S=new x(n.x,n.y),b=di((l-c)%Math.PI,0);S.x=b?n.x:n.y,S.y=b?n.y:n.x;const P=q.applyToPoint(a,new x),{x:C,y:_}=this.getPointInParentSpace(o.id,P);let E=o;r.skipStartAndEndCallbacks||(E=ys(o,((g=f.onResizeStart)==null?void 0:g.call(f,o))??void 0)),E=ys(E,{id:s,type:o.type,x:y.x,y:y.y,...f.onResize({...o,x:C,y:_},{newPoint:y,handle:r.dragHandle??"bottom_right",mode:r.mode??"scale_shape",scaleX:S.x,scaleY:S.y,initialBounds:u,initialShape:o})}),r.skipStartAndEndCallbacks||(E=ys(E,((m=f.onResizeEnd)==null?void 0:m.call(f,o,E))??void 0)),this.updateShapes([E])}else{const v=q.applyToPoint(a,u.center),y=this._scalePagePoint(v,i,n,c),S=this.getPointInParentSpace(o.id,v),b=this.getPointInParentSpace(o.id,y),P=x.Sub(b,S);this.updateShapes([{id:s,type:o.type,x:o.x+P.x,y:o.y+P.y}])}return this}_scalePagePoint(e,n,r,s){const o=x.RotWith(e,n,-s).sub(n),i=x.MulV(o,r);return x.Add(i,n).rotWith(n,s)}_resizeUnalignedShape(e,n,r){const{type:s}=r.initialShape,o=new x(n.x,n.y);if(Math.abs(n.x)>Math.abs(n.y)?o.x=Math.sign(n.x)*Math.abs(n.y):o.y=Math.sign(n.y)*Math.abs(n.x),this.resizeShape(e,o,{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:s,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 f=x.Sub(a,u),p=x.Add(h,f),{x:g,y:m}=this.getPointInParentSpace(e,p);return this.updateShapes([{id:e,type:s,x:g,y:m}]),this}getInitialMetaForShape(e){return{}}createShape(e){return this.createShapes([e]),this}createShapes(e){if(!Array.isArray(e))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");if(this.getIsReadonly())return this;if(e.length<=0)return this;const n=this.getCurrentPageShapeIds();if(e.length+n.size>this.options.maxShapesPerPage)return vh(this),this;const s=this.getFocusedGroupId();return this.run(()=>{var u,h;const o=this.getCurrentPageShapesSorted(),i=e.map(f=>{if(f.id||(f={id:Ke(),...f}),!f.parentId||!(this.store.has(f.parentId)||e.some(p=>p.id===f.parentId))){let p=this.getFocusedGroupId();for(let m=o.length-1;m>=0;m--){const v=o[m];if(!this.isShapeHidden(v)&&this.getShapeUtil(v).canReceiveNewChildrenOfType(v,f.type)&&this.isPointInShape(v,{x:f.x??0,y:f.y??0},{margin:0,hitInside:!0})){p=v.id;break}}const g=f.parentId;if(p===f.id&&(p=s),p!==g&&(f={...f},f.parentId=p,Fn(p))){const m=this.getPointInShapeSpace(this.getShape(p),{x:f.x??0,y:f.y??0});f.x=m.x,f.y=m.y,f.rotation=-this.getShapePageTransform(p).rotation()+(f.rotation??0)}}return f}),a=new Map,l=[],{opacityForNextShape:c}=this.getInstanceState();for(const f of i){const p=this.getShapeUtil(f);let g=f.index;if(!g){const S=f.parentId??s;a.has(S)||a.set(S,this.getHighestIndexForParent(S)),g=a.get(S),a.set(S,_s(g))}const m=p.getDefaultProps();for(const[S,b]of this.styleProps[f.type])m[b]=this.getStyleForNextShape(S);let v=this.store.schema.types.shape.create({...f,index:g,opacity:f.opacity??c,parentId:f.parentId??s,props:"props"in f?{...m,...f.props}:m});if(v.index===void 0)throw Error("no index!");const y=(h=(u=this.getShapeUtil(v)).onBeforeCreate)==null?void 0:h.call(u,v);y&&(v=y),l.push(v)}l.forEach(f=>{f.meta={...this.getInitialMetaForShape(f),...f.meta}}),this.store.put(l)}),this}animateShape(e,n={animation:Hy}){return this.animateShapes([e],n)}animateShapes(e,n={animation:Hy}){if(!n.animation)return this;const{duration:r=500,easing:s=Dt.linear}=n.animation,o=ze();let i=r,a;const l=[];let c,u;for(let f=0,p=e.length;f<p;f++){if(c=e[f],!c)continue;const g=this.getShape(c.id);g&&(u={start:nt(g),end:ys(nt(g),c)},l.push(u),this.animatingShapes.set(g.id,o))}const h=f=>{var v,y;if(i-=f,i<0){const{animatingShapes:S}=this,b=e.filter(P=>P&&S.get(P.id)===o);b.length&&this.updateShapes(b),this.off("tick",h);return}a=s(1-i/r);const{animatingShapes:p}=this,g=[];let m;for(let S=0,b=l.length;S<b;S++){const{start:P,end:C}=l[S];m=p.get(P.id),m===o&&g.push({...C,x:P.x+(C.x-P.x)*a,y:P.y+(C.y-P.y)*a,opacity:P.opacity+(C.opacity-P.opacity)*a,rotation:P.rotation+(C.rotation-P.rotation)*a,props:((y=(v=this.getShapeUtil(C)).getInterpolatedProps)==null?void 0:y.call(v,P,C,a))??C.props})}this._updateShapes(g)};return this.on("tick",h),this}groupShapes(e,n={}){var g;const{groupId:r=Ke(),select:s=!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 o=typeof e[0]=="string"?e:e.map(m=>m.id);if(o.length<=1)return this;const i=me((this._shouldIgnoreShapeLock?o:this._getUnlockedShapeIds(o)).map(m=>this.getShape(m))),a=i.sort(cn).map(m=>m.id),l=Z.Common(me(i.map(m=>this.getShapePageBounds(m)))),{x:c,y:u}=l.point,h=this.findCommonAncestor(i)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const f=i.filter(m=>m.parentId===h).sort(cn),p=(g=f[f.length-1])==null?void 0:g.index;return this.run(()=>{this.createShapes([{id:r,type:"group",parentId:h,index:p,x:c,y:u,opacity:1,props:{}}]),this.reparentShapes(a,r),s&&this.select(r)}),this}ungroupShapes(e,n={}){if(this.getIsReadonly())return this;const{select:r=!0}=n,s=typeof e[0]=="string"?e:e.map(l=>l.id),o=me((this._shouldIgnoreShapeLock?s:this._getUnlockedShapeIds(s)).map(l=>this.getShape(l)));if(o.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const i=new Set,a=[];return o.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 f=0,p=h.length;f<p;f++)i.add(h[f]);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,s=e.length;r<s;r++){const o=e[r];if(!o)continue;const i=this.getShape(o.id);if(i){if(!this._shouldIgnoreShapeLock){if(i.isLocked){if(!(Object.hasOwn(o,"isLocked")&&!o.isLocked))continue}else if(this.isShapeOrAncestorLocked(i))continue}this.animatingShapes.delete(o.id),n.push(o)}}return this._updateShapes(n),this}_updateShapes(e){this.getIsReadonly()||this.run(()=>{var o,i;const n=[];let r,s;for(let a=0,l=e.length;a<l;a++){const c=e[a];c&&(r=this.getShape(c.id),r&&(s=ys(r,c),s!==r&&(s=((i=(o=this.getShapeUtil(r)).onBeforeUpdate)==null?void 0:i.call(o,r,s))??s,n.push(s))))}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(o=>o.id),r=this._shouldIgnoreShapeLock?n:this._getUnlockedShapeIds(n);if(r.length===0)return this;const s=new Set(r);for(const o of r)this.visitDescendants(o,i=>{s.add(i)});return this.run(()=>this.store.remove([...s]))}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 s=0,o=r.length;s<o;s++)this._extractSharedStyles(this.getShape(r[s]),n)}else for(const[r,s]of this.styleProps[e.type])n.applyValue(r,hn(e.props,s))}_getSelectionSharedStyles(){const e=this.getSelectedShapes(),n=new kx;for(const r of e)this._extractSharedStyles(r,n);return n}getStyleForNextShape(e){const n=this.getInstanceState().stylesForNextShape[e.id];return n===void 0?e.defaultValue:n}getShapeStyleIfExists(e,n){const r=this.styleProps[e.type].get(n);if(r!==void 0)return hn(e.props,r)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const e=this.root.getCurrent(),n=new kx;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=s=>{const o=this.getShape(s);if(o)if(this.isShapeOfType(o,"group"))for(const i of this.getSortedChildIdsForParent(o.id))n(i);else e.push(o)};for(const s of this.getSelectedShapeIds())n(s);let r=null;for(const s of e)if(r===null)r=s.opacity;else if(r!==s.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=[],s=o=>{if(this.isShapeOfType(o,"group")){const i=this.getSortedChildIdsForParent(o);for(const a of i)s(this.getShape(a))}else r.push(o)};for(const o of n)s(o);this.updateShapes(r.map(o=>({id:o.id,type:o.type,opacity:e})))}return this}setStyleForNextShapes(e,n,r){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[e.id]:n}},r),this}setStyleForSelectedShapes(e,n){const r=this.getSelectedShapes();if(r.length>0){const s=[],o=i=>{if(this.isShapeOfType(i,"group")){const a=this.getSortedChildIdsForParent(i.id);for(const l of a)o(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}};s.push({util:a,originalShape:i,updatePartial:c})}}};for(const i of r)o(i);this.updateShapes(s.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(s=>s.id);if(!n||n.length===0)return;const r=this.getShapeAndDescendantIds(n);return RI(this,r,s=>{const o=[];for(const u of s){const h=this.getBinding(u);h&&o.push(h)}const i=[],a=[];for(const u of r){const h=this.getShape(u);if(!h)continue;if(!r.has(h.parentId)){const p=this.getShapePageTransform(h.id),g=p.point();a.push({...h,x:g.x,y:g.y,rotation:p.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 f=this.getAsset(h);f&&l.push(f)}return{schema:this.store.schema.serialize(),shapes:a,rootShapeIds:i,bindings:o,assets:l}})}async resolveAssetsInContent(e){if(!e)return;const n=[];return await Promise.allSettled(e.assets.map(async r=>{var s,o,i;if((r.type==="image"||r.type==="video")&&!((s=r.props.src)!=null&&s.startsWith("data:image"))&&!((o=r.props.src)!=null&&o.startsWith("data:video"))&&!((i=r.props.src)!=null&&i.startsWith("http"))){const a=nt(r),l=await this.store.props.assets.resolve(r,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginal:!0});a.props.src=await Zr.blobToDataUrl(await Rs(l).then(c=>c.blob())),n.push(a)}else n.push(r)})),e.assets=n,e}putContentOntoCurrentPage(e,n={}){var T,j,L;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:s=!1,preservePosition:o=!1}=n;let{point:i=void 0}=n;const a=this.getCurrentPageId(),{rootShapeIds:l}=e,c=[],u=[],h=[],f={store:{...Object.fromEntries(e.assets.map(M=>[M.id,M])),...Object.fromEntries(e.shapes.map(M=>[M.id,M])),...Object.fromEntries(((T=e.bindings)==null?void 0:T.map(M=>[M.id,M]))??[])},schema:e.schema},p=this.store.schema.migrateStoreSnapshot(f);if(p.type==="error")throw Error("Could not put content: could not migrate content");for(const M of Object.values(p.value))switch(M.typeName){case"asset":{c.push(M);break}case"shape":{u.push(M);break}case"binding":{h.push(M);break}}const g=new Map(s?u.map(M=>[M.id,M.id]):u.map(M=>[M.id,Ke()])),m=new Map(s?h.map(M=>[M.id,M.id]):h.map(M=>[M.id,Ji()]));let v=this.getCurrentPageId(),y=1/0,S=[];for(const M of this.getSelectedShapes()){if(y===0)break;const O=this.isShapeOfType(M,"frame"),F=this.getShapeAncestors(M);O&&F.push(M);const B=O?F.length+1:F.length;if(B<y)y=B,S=F,v=O?M.id:M.parentId;else if(B===y){if(S.length!==F.length)throw Error(`Ancestors: ${S.length} !== ${F.length}`);if(S.length===0){v=a;break}else{v=a;for(let K=0;K<S.length&&F[K]===S[K];K++)v=F[K].id}}}let b=!1;if(!Rn(v)){const M=this.getShape(v);if(M){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(M)))v=a;else if(l.length===1){const O=u.find(F=>F.id===l[0]);this.isShapeOfType(M,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(M==null?void 0:M.props.w)&&O.props.h===(M==null?void 0:M.props.h)&&(b=!0)}}else v=a}b||(b=g.has(v)),b&&(v=this.getShape(v).parentId);let P=this.getHighestIndexForParent(v);const C=[],_=u.map(M=>{const O=g.get(M.id),F={...M,id:O};return l.includes(M.id)&&(F.parentId=a,C.push(F)),g.has(F.parentId)?F.parentId=g.get(M.parentId):(l.push(F.id),F.index=P,P=_s(P)),F});if(_.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return vh(this),this;const E=h.map(M=>({...M,id:zn(m.get(M.id)),fromId:zn(g.get(M.fromId)),toId:zn(g.get(M.toId))})),k=[],D=[];for(const M of c)this.store.has(M.id)||((M.type==="image"&&((j=M.props.src)!=null&&j.startsWith("data:image"))||M.type==="video"&&((L=M.props.src)!=null&&L.startsWith("data:video")))&&(D.push(nt(M)),M.props.src=null),k.push(M));return Promise.allSettled(D.map(async M=>{const O=await UQ(M.props.src,M.props.name,M.props.mimeType??"image/png"),F=await this.getAssetForExternalContent({type:"file",file:O,assetId:M.id});if(!F){this.deleteAssets([M.id]);return}this.updateAssets([{...F,id:M.id}])})),this.run(()=>{k.length>0&&this.createAssets(k),this.createShapes(_),this.createBindings(E),r&&this.select(...C.map(K=>K.id)),v!==a&&this.reparentShapes(C.map(K=>K.id),v);const M=_.map(K=>this.getShape(K.id)),O=Z.Common(M.map(K=>this.getShapePageBounds(K)));if(i===void 0)if(Rn(v)){const K=this.getViewportPageBounds();o||K.includes(Z.From(O))?i=O.center:i=K.center}else{const K=this.getShape(v);i=q.applyToPoint(this.getShapePageTransform(K),this.getShapeGeometry(K).bounds.center)}if(C.length===1){const K=C[0];if(this.isShapeOfType(K,"frame"))for(;this.getShapesAtPoint(i).some(R=>this.isShapeOfType(R,"frame")&&R.props.w===K.props.w&&R.props.h===K.props.h);)i.x+=O.w+16}const F=Z.Common(me(C.map(({id:K})=>this.getShapePageBounds(K)))).center,B=x.Sub(i,F);this.updateShapes(C.map(({id:K})=>{const R=this.getShape(K),H=this.getShapeParentTransform(K).decompose().rotation,X=x.Rot(B,-H);return{id:R.id,type:R.type,x:R.x+X.x,y:R.y+X.y}}))}),this}async getSvgElement(e,n={}){const r=typeof e[0]=="string"?e:e.map(s=>s.id);if(r.length!==0)return FQ(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:s,currentScreenPoint:o,currentPagePoint:i}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(bn),{x:l,y:c,z:u}=ih(()=>this.getCamera()),h=e.point.x-a.x,f=e.point.y-a.y,p=e.point.z??.5;r.setTo(o),s.setTo(i),o.set(h,f);const g=h/u-l,m=f/u-c;isFinite(g)&&isFinite(m)&&i.set(g,m,p),this.inputs.isPen=e.type==="pointer"&&e.isPen,(e.name==="pointer_down"||this.inputs.isPinching)&&(n.set(0,0),this.inputs.originScreenPoint.setTo(o),this.inputs.originPagePoint.setTo(i)),this.run(()=>{var v;this.store.put([{id:Tp,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:e.type==="pointer"&&e.pointerId===eI.CAMERA_MOVE?((v=this.store.unsafeGetWithoutCapture(Tp))==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 HZ(this.store)}loadSnapshot(e,n){return Uj(this.store,e,n),this}_zoomToFitPageContentAt100Percent(){const e=this.getCurrentPageBounds();e&&this.zoomToBounds(e,{immediate:!0,targetZoom:this.getBaseZoom()})}_navigateToDeepLink(e){this.run(()=>{switch(e.type){case"page":{const n=this.getPage(e.pageId);n&&this.setCurrentPage(n),this._zoomToFitPageContentAt100Percent();return}case"shapes":{const n=me(e.shapeIds.map(i=>this.getShape(i))),r={};for(const i of n){const a=this.getAncestorPageId(i);a&&(r[a]??(r[a]=[]),r[a].push(i))}const[s,o]=Object.entries(r).sort(([i,a],[l,c])=>c.length-a.length)[0]??["",[]];if(!s||!o.length)this._zoomToFitPageContentAt100Percent();else{this.setCurrentPage(s);const i=Z.Common(o.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(WQ(r))}catch(s){console.warn(s),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",KQ((e==null?void 0:e.to)??{type:"viewport",pageId:this.options.maxPages===1?void 0:this.getCurrentPageId(),bounds:this.getViewportPageBounds()})),n}registerDeepLinkListener(e){if(e!=null&&e.getUrl&&!(e!=null&&e.onChange))throw Error("[tldraw:urlStateSync] If you specify getUrl, you must also specify the onChange callback.");const n=G("url with state",()=>{var l,c;const i=((l=e==null?void 0:e.getUrl)==null?void 0:l.call(e,this))??window.location.href;return this.createDeepLink({param:e==null?void 0:e.param,url:i,to:(c=e==null?void 0:e.getTarget)==null?void 0:c.call(e,this)}).toString()}),r=(e==null?void 0:e.onChange)??(()=>{var a;const i=this.createDeepLink({param:e==null?void 0:e.param,to:(a=e==null?void 0:e.getTarget)==null?void 0:a.call(e,this)});window.history.replaceState({},document.title,i.toString())}),s=yg(i=>i(),(e==null?void 0:e.debounceMs)??500),o=As("update url on state change",()=>r(new URL(n.get()),this),{scheduleEffect:s});return()=>{o(),s.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:s,currentPagePoint:o}=n;n.isPointing||(n.isDragging=!1);const i=this.store.unsafeGetWithoutCapture(bn),a=this.store.get(this._getCurrentPageStateId()),l=this._cameraOptions.__unsafe__getWithoutCapture();switch(r){case"pinch":{if(l.isLocked)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(e),e.name){case"pinch_start":{if(n.isPinching)return;n.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=[...a.selectedShapeIds]),this._didPinch=!0,n.isPinching=!0,this.interrupt());return}case"pinch":{if(!n.isPinching)return;const{point:{z:c=1},delta:{x:u,y:h}}=e,{x:f,y:p}=x.SubXY(e.point,i.screenBounds.x,i.screenBounds.y);this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:g,y:m,z:v}=ih(()=>this.getCamera()),{panSpeed:y,zoomSpeed:S}=l;this._setCamera(new x(g+u*y/v-f/v+f/(c*S),m+h*y/v-p/v+p/(c*S),c*S),{immediate:!0});return}case"pinch_end":{if(!n.isPinching)return this;n.isPinching=!1;const{_selectedShapeIdsAtPointerDown:c}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,c.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(c)}));return}}}case"wheel":{if(l.isLocked)return;this._updateInputsFromEvent(e);const{panSpeed:c,zoomSpeed:u,wheelBehavior:h}=l;if(h!=="none"){this.stopCameraAnimation(),i.followingUserId&&this.stopFollowingUser();const{x:f,y:p,z:g}=ih(()=>this.getCamera()),{x:m,y:v,z:y=0}=e.delta;let S=h;switch(n.ctrlKey&&(S=h==="pan"?"zoom":"pan"),S){case"zoom":{const{x:b,y:P}=this.inputs.currentScreenPoint;let C=y;h==="zoom"&&(Math.abs(v)>10?C=10*Math.sign(v)/100:C=v/100);const _=g+(C??0)*u*g;this._setCamera(new x(f+(b/_-b)-(b/g-b),p+(P/_-P)-(P/g-P),_),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new x(f+m*c/g,p+v*c/g,g),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}break}case"pointer":{if(n.isPinching)return;this._updateInputsFromEvent(e);const{isPen:c}=e,{isPenMode:u}=i;switch(e.name){case"pointer_down":{if(u&&!c)return;if(this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{const h=this.getViewportScreenBounds();this.dispatch({...e,point:this.inputs.originScreenPoint.clone().addXY(h.x,h.y),name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),e.button===tI&&(this.capturedPointerId=e.pointerId),n.buttons.add(e.button),n.isPointing=!0,n.isDragging=!1,!u&&c&&this.updateInstanceState({isPenMode:!0}),e.button===nI?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):e.button===fh&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!c&&u)return;const{x:h,y:f,z:p}=ih(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:g,previousScreenPoint:m}=this.inputs,{panSpeed:v}=l,y=x.Sub(g,m);this.setCamera(new x(h+y.x*v/p,f+y.y*v/p,p),{immediate:!0}),this.maybeTrackPerformance("Panning");return}n.isPointing&&!n.isDragging&&x.Dist2(s,o)*this.getZoomLevel()>(i.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/p&&(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,f=Math.min(2,h.len());switch(e.button){case tI:{this.setCursor({type:"grab",rotation:0});break}case fh:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}f>0&&this.slideCamera({speed:f,direction:h})}else e.button===nI&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(e.key==="ShiftRight"&&(e.key="ShiftLeft"),e.key==="AltRight"&&(e.key="AltLeft"),e.code==="ControlRight"&&(e.code="ControlLeft"),e.code==="MetaRight"&&(e.code="MetaLeft"),e.name){case"key_down":{if(n.keys.add(e.code),e.code==="Space"&&!e.ctrlKey&&(this.inputs.isPanning||(this._prevCursor=i.cursor.type),this.inputs.isPanning=!0,this.inputs.isSpacebarPanning=!0,clearTimeout(this._longPressTimeout),this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0})),this.inputs.isSpacebarPanning){let c;switch(e.code){case"ArrowUp":{c=new x(0,-1);break}case"ArrowRight":{c=new x(1,0);break}case"ArrowDown":{c=new x(0,1);break}case"ArrowLeft":{c=new x(-1,0);break}}if(c){const u=this.getViewportPageBounds(),h=u.clone().translate(c.mulV({x:u.w,y:u.h}));this._animateToViewport(h,{animation:{duration:320}})}}break}case"key_up":{n.keys.delete(e.code),e.code==="Space"&&(this.inputs.buttons.has(fh)||(this.inputs.isPanning=!1,this.inputs.isSpacebarPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(e.type==="pointer"){e.button===fh?e.name="middle_click":e.button===hb&&(e.name="right_click");const{isPenMode:c}=this.store.unsafeGetWithoutCapture(bn);if(e.isPen===c){const u=this._clickManager.handlePointerEvent(e);if(e.name!==u.name){this.root.handleEvent(e),this.emit("event",e),this.root.handleEvent(u),this.emit("event",u);return}}}return this.root.handleEvent(e),this.emit("event",e),e.type==="pointer"&&e.name==="pointer_down"&&this.menus.clearOpenMenus(),this}maybeTrackPerformance(e){wt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(e),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}J=fee(Mx);ee(J,1,"getIsShapeHiddenCache",zR,Q);ee(J,1,"getCanUndo",NR,Q);ee(J,1,"getCanRedo",FR,Q);ee(J,1,"getPath",$R,Q);ee(J,1,"getCurrentTool",LR,Q);ee(J,1,"getCurrentToolId",RR,Q);ee(J,1,"getDocumentSettings",DR,Q);ee(J,1,"getInstanceState",OR,Q);ee(J,1,"getOpenMenus",jR,Q);ee(J,1,"getIsMenuOpen",AR,Q);ee(J,1,"getPageStates",MR,Q);ee(J,1,"_getPageStatesQuery",TR,Q);ee(J,1,"getCurrentPageState",kR,Q);ee(J,1,"_getCurrentPageStateId",ER,Q);ee(J,1,"getSelectedShapeIds",IR,Q);ee(J,1,"getSelectedShapes",_R,Q);ee(J,1,"getOnlySelectedShapeId",CR,Q);ee(J,1,"getOnlySelectedShape",PR,Q);ee(J,1,"getSelectionPageBounds",bR,Q);ee(J,1,"getSelectionRotation",wR,Q);ee(J,1,"getSelectionRotatedPageBounds",xR,Q);ee(J,1,"getSelectionRotatedScreenBounds",vR,Q);ee(J,1,"getFocusedGroupId",SR,Q);ee(J,1,"getFocusedGroup",yR,Q);ee(J,1,"getEditingShapeId",mR,Q);ee(J,1,"getEditingShape",gR,Q);ee(J,1,"getHoveredShapeId",pR,Q);ee(J,1,"getHoveredShape",fR,Q);ee(J,1,"getHintingShapeIds",hR,Q);ee(J,1,"getHintingShape",dR,Q);ee(J,1,"getErasingShapeIds",uR,Q);ee(J,1,"getErasingShapes",cR,Q);ee(J,1,"_unsafe_getCameraId",lR,Q);ee(J,1,"getCamera",aR,Q);ee(J,1,"getViewportPageBoundsForFollowing",iR,Q);ee(J,1,"getCameraForFollowing",oR,Q);ee(J,1,"getZoomLevel",sR,Q);ee(J,1,"getViewportScreenBounds",rR,Q);ee(J,1,"getViewportScreenCenter",nR,Q);ee(J,1,"getViewportPageBounds",tR,Q);ee(J,1,"_getCollaboratorsQuery",eR,Q);ee(J,1,"getCollaborators",JD,Q);ee(J,1,"getCollaboratorsOnCurrentPage",QD,Q);ee(J,1,"getRenderingShapes",ZD,Q);ee(J,1,"_getAllPagesQuery",qD,Q);ee(J,1,"getPages",XD,Q);ee(J,1,"getCurrentPageId",YD,Q);ee(J,1,"getCurrentPageShapeIdsSorted",VD,Q);ee(J,1,"_getAllAssetsQuery",GD,Q);ee(J,1,"_getShapeGeometryCache",WD,Q);ee(J,1,"_getShapeHandlesCache",KD,Q);ee(J,1,"_getShapePageTransformCache",HD,Q);ee(J,1,"_getShapePageBoundsCache",UD,Q);ee(J,1,"_getShapeClipPathCache",BD,Q);ee(J,1,"_getShapeMaskCache",zD,Q);ee(J,1,"_getShapeMaskedPageBoundsCache",ND,Q);ee(J,1,"_notVisibleShapes",FD,Q);ee(J,1,"getCulledShapes",$D,Q);ee(J,1,"getCurrentPageBounds",LD,Q);ee(J,1,"getCurrentPageShapes",RD,Q);ee(J,1,"getCurrentPageShapesSorted",DD,Q);ee(J,1,"getCurrentPageRenderingShapesSorted",OD,Q);ee(J,1,"_getBindingsIndexCache",jD,Q);ee(J,1,"_getSelectionSharedStyles",AD,Q);ee(J,1,"getSharedStyles",MD,Q);ee(J,1,"getSharedOpacity",TD,Q);ee(J,1,"getIsFocused",kD,Q);ee(J,1,"getIsReadonly",ED,Q);ee(J,1,"_setShiftKeyTimeout",ID,Q);ee(J,1,"_setAltKeyTimeout",_D,Q);ee(J,1,"_setCtrlKeyTimeout",CD,Q);ee(J,1,"_setMetaKeyTimeout",PD,Q);gee(J,Q);function vh(t,e=t.getCurrentPageId()){const n=t.getPage(e).name;t.emit("max-shapes",{name:n,pageId:e,count:t.options.maxShapesPerPage})}function ys(t,e){if(!e)return t;let n=null;const r=Object.entries(e);for(let s=0,o=r.length;s<o;s++){const[i,a]=r[s];if(a!==void 0&&!(i==="id"||i==="type"||i==="typeName")&&a!==t[i]){if(n||(n={...t}),i==="props"||i==="meta"){n[i]={...t[i]};for(const[l,c]of Object.entries(a))n[i][l]=c;continue}n[i]=a}}return n||t}function BR(t,e,n){const r=t.getShape(e);if(!r)return;n.push(r);const s=t.getSortedChildIdsForParent(e);for(let o=0,i=s.length;o<i;o++)BR(t,s[o],n)}function RI(t,e,n){let r;if(t.run(()=>{const s=t.store.extractingChanges(()=>{const o=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){o.add(c.id);continue}(!u||!h)&&i.add(c.id)}t.deleteBindings([...i],{isolateShapes:!0});try{r=wn.ok(n(o))}catch(a){r=wn.err(a)}});t.store.applyDiff(fx(s))},{history:"ignore"}),r.ok)return r.value;throw r.error}function LI(t,e){if(!e.constraints)throw Error("Should have constraints here");const{padding:{x:n,y:r}}=e.constraints,s=t.getViewportScreenBounds(),o=Z.From(e.constraints.bounds),i=(s.w-n*2)/o.w,a=(s.h-r*2)/o.h;return{zx:i,zy:a}}function vd(){const t=z(),e=gd();return U("isDarkMode",()=>(e==null?void 0:e.isDarkMode)??t.user.getIsDarkMode(),[e,t])}const $I="<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'/>",FI="<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'/>",xh='<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 No(t,e,n,r,s,o=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: ${s};'><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>") ${o} ${i}, pointer`}const yee=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],See={none:()=>"none","ew-resize":(t,e,n)=>No(FI,t,0,e,n),"ns-resize":(t,e,n)=>No(FI,t,90,e,n),"nesw-resize":(t,e,n)=>No($I,t,0,e,n),"nwse-resize":(t,e,n)=>No($I,t,90,e,n),"nwse-rotate":(t,e,n)=>No(xh,t,0,e,n),"nesw-rotate":(t,e,n)=>No(xh,t,90,e,n),"senw-rotate":(t,e,n)=>No(xh,t,180,e,n),"swne-rotate":(t,e,n)=>No(xh,t,270,e,n)};function nr(t,e=0,n="black"){return See[t](gX(e),!1,n)}function vee(){const t=z(),e=Tt(),n=vd();ui("useCursor",()=>{const{type:r,rotation:s}=t.getInstanceState().cursor;if(yee.includes(r)){e.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}e.style.setProperty("--tl-cursor",nr(r,s,n?"white":"black"))},[t,e,n])}function xee(){const t=z(),e=Tt(),n=vd(),r=U(wt.forceSrgb);ke.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 wee(){const[t,e]=w.useState(0);w.useEffect(()=>e(n=>n+1),[])}const bee=t=>t.props.src,Pee={upload:(t,e)=>Zr.blobToDataUrl(e)};function Cee(t){return"schema"in t&&t.schema?t.schema:sX({shapes:"shapeUtils"in t&&t.shapeUtils?NI(Gj(t.shapeUtils)):void 0,bindings:"bindingUtils"in t&&t.bindingUtils?NI(Kj(t.bindingUtils)):void 0,migrations:"migrations"in t?t.migrations:void 0})}function Uu({initialData:t,defaultName:e="",id:n,assets:r=Pee,onMount:s,collaboration:o,...i}={}){const a=Cee(i),l=new Z0({id:n,schema:a,initialData:t,props:{defaultName:e,assets:{upload:r.upload,resolve:r.resolve??bee},onMount:c=>{Le(c instanceof Q),s==null||s(c)},collaboration:o}});if(i.snapshot){if(t)throw new Error("Cannot provide both initialData and snapshot");Uj(l,i.snapshot)}return l}function NI(t){return Object.fromEntries(t.map(e=>[e.type,{props:e.props,migrations:e.migrations}]))}function _ee(){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 Iee(){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 Eee=350,kee=1e4,zI=Symbol("UPDATE_INSTANCE_STATE"),Tee=t=>t;class Mee{constructor(e){I(this,"onmessage")}postMessage(e){}close(){}}const Aee=typeof BroadcastChannel>"u"?Mee:BroadcastChannel;class jee{constructor(e,{persistenceKey:n,sessionId:r=Lp,onLoad:s,onLoadError:o},i=new Aee(`tldraw-tab-sync-${n}`)){I(this,"disposables",new Set);I(this,"diffQueue",[]);I(this,"didDispose",!1);I(this,"shouldDoFullDBWrite",!0);I(this,"isReloading",!1);I(this,"persistenceKey");I(this,"sessionId");I(this,"serializedSchema");I(this,"isDebugging",!1);I(this,"documentTypes");I(this,"$sessionStateSnapshot");I(this,"db");I(this,"initTime",Date.now());I(this,"isPersisting",!1);I(this,"didLastWriteError",!1);I(this,"scheduledPersistTimeout",null);this.store=e,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=n,this.sessionId=r,this.db=new vp(n),this.disposables.add(()=>this.db.close()),this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=Sb(this.store),this.disposables.add(e.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(Tee({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(zI),this.schedulePersist()},{scope:"session"})),this.connect(s,o),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(s){n(s),Iee();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const s=Object.fromEntries(r.records.map(l=>[l.id,l])),o=r.sessionStateSnapshot??UZ(s),i=this.store.schema.migrateStoreSnapshot({store:s,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(i.type==="error"){console.error("failed to migrate store",i),n(new Error(`Failed to migrate store: ${i.reason}`));return}const a=Object.values(i.value).filter(l=>this.documentTypes.has(l.typeName));a.length>0&&this.store.mergeRemoteChanges(()=>{this.store.put(a,"initialize")}),o&&Px(this.store,o)}this.channel.onmessage=({data:s})=>{var a,l;this.debug("got message",s);const o=s,i=this.store.schema.getMigrationsSince(o.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}o.type==="diff"&&(this.debug("applying diff"),js(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(o.changes)})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),e(this)}catch(s){if(this.debug("error loading data from store",s),this.didDispose)return;n(s);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?kee:Eee))}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=q0(e.filter(r=>r!==zI));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),_ee(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function UR(t){const e=w.useRef(t),[n,r]=w.useState(t);n!==e.current&&r(e.current);const s=w.useCallback(o=>{typeof o=="function"?e.current=o(e.current):e.current=o,r(e.current)},[]);return[n,s]}function Oee(t){const[e,n]=UR({status:"loading"});return t=tc(t),w.useEffect(()=>{const{persistenceKey:r,sessionId:s,...o}=t;if(!r){n({status:"not-synced",store:Uu(o)});return}n({status:"loading"});const i=new Ds,a={upload:async(h,f)=>(await u.db.storeAsset(h.id,f),h.id),resolve:async h=>h.props.src?h.props.src.startsWith("asset:")?await i.get(h,async()=>{const f=await u.db.getAsset(h.id);return f?URL.createObjectURL(f):null}):h.props.src:null,...o.assets},l=Uu({...o,assets:a});let c=!1;const u=new jee(l,{sessionId:s,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 Dee(){const t=z(),e=Tt();w.useEffect(()=>{const n=o=>e.style.setProperty("--tl-zoom",o.toString()),r=yg(n,100),s=new Ql("useZoomCss",()=>{t.getCurrentPageShapeIds().size<300?n(t.getZoomLevel()):r(t.getZoomLevel())});return s.attach(),s.execute(),()=>{s.detach(),r.cancel()}},[t,e])}function Ax(t){const e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let r=0,s=t.length;r<s;r++)n[r]=t.charCodeAt(r);return e}function Ree(t){const e=atob(t),n=Ax(e);return crypto.subtle.importKey("spki",new Uint8Array(n),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}const Lee=5,Wc={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8},$ee=Math.max(...Object.values(Wc)),Gc={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},Fee=Object.keys(Gc).length,Jy="sales@tldraw.com",Nee=`${ti()}/watermarks/watermark-track.svg`;class Vg{constructor(e,n,r){I(this,"publicKey","MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ");I(this,"isDevelopment");I(this,"isTest");I(this,"isCryptoAvailable");I(this,"state",It("license state","pending"));I(this,"verbose",!0);this.isTest=!1,this.isDevelopment=this.getIsDevelopment(r),this.publicKey=n||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,this.getLicenseFromKey(e).then(s=>{const o=zee(s);!this.isDevelopment&&o&&Rs(Nee),o?this.state.set("unlicensed"):s.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("."),[s,o]=n.split("/");if(!s.startsWith("tldraw-"))throw new Error(`Unsupported prefix '${s}'`);const i=await Ree(this.publicKey);let a;try{a=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,new Uint8Array(Ax(atob(r))),new Uint8Array(Ax(atob(o))))}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(o))}catch{throw new Error("Could not parse object")}return l.length>Fee&&this.outputMessages(["License key contains some unknown properties.","You may want to update tldraw packages to a newer version to get access to new functionality."]),{id:l[Gc.ID],hosts:l[Gc.HOSTS],flags:l[Gc.FLAGS],expiryDate:l[Gc.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),s=new Date(r.expiryDate),o=this.isFlagEnabled(r.flags,Wc.ANNUAL_LICENSE),i=this.isFlagEnabled(r.flags,Wc.PERPETUAL_LICENSE),a={license:r,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(r),expiryDate:s,isAnnualLicense:o,isAnnualLicenseExpired:o&&this.isAnnualLicenseExpired(s),isPerpetualLicense:i,isPerpetualLicenseExpired:i&&this.isPerpetualLicenseExpired(s),isInternalLicense:this.isFlagEnabled(r.flags,Wc.INTERNAL_LICENSE),isLicensedWithWatermark:this.isFlagEnabled(r.flags,Wc.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 s=r.toLowerCase().trim();if(s===n||`www.${s}`===n||s===`www.${n}`||r==="*")return!0;if(r.includes("*")){const o=new RegExp(r.replace(/\*/g,".*?"));return o.test(n)||o.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()+Lee+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 ${Jy} if you would like to renew your license.`]),r}isPerpetualLicenseExpired(e){const n=this.getExpirationDateWithGracePeriod(e),r={major:new Date(q_.major),minor:new Date(q_.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 ${Jy} to renew.`]),!e.isDomainValid&&!e.isDevelopment&&this.outputMessages(["This tldraw license key is not valid for this domain!",`Please reach out to ${Jy} if you would like to use tldraw on other domains.`]),e.license.flags>=$ee*2&&this.outputMessages(["This tldraw license contains some unknown flags.","You may want to update tldraw packages to a newer version to get access to new functionality."])}outputMessages(e){if(!this.isTest&&this.verbose){this.outputDelimiter();for(const n of e)console.log(`%c${n}`,"color: white; background: crimson; padding: 2px; border-radius: 3px;");this.outputDelimiter()}}outputDelimiter(){console.log("%c-------------------------------------------------------------------","color: white; background: crimson; padding: 2px; border-radius: 3px;")}}I(Vg,"className","tl-watermark_SEE-LICENSE");function zee(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 HR=w.createContext({}),Bee=()=>w.useContext(HR);function Uee({licenseKey:t,children:e}){const[n]=w.useState(()=>new Vg(t));return d.jsx(HR.Provider,{value:n,children:e})}function Ai(t){if(!t)throw Error("usePassThroughWheelEvents must be passed a ref");const e=Tt();w.useEffect(()=>{function n(s){if(s.isSpecialRedispatchedEvent)return;xe(s);const o=e.querySelector(".tl-canvas");if(!o)return;const i=new WheelEvent("wheel",s);i.isSpecialRedispatchedEvent=!0,o.dispatchEvent(i)}const r=t.current;if(r)return r.addEventListener("wheel",n,{passive:!1}),()=>{r.removeEventListener("wheel",n)}},[e,t])}const Hee='<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>',Kee='<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 Wee(t){return U("watermarkState",()=>t.state.get(),[t])}const Gee=`data:image/svg+xml;utf8,${encodeURIComponent(Hee)}`,Vee=`data:image/svg+xml;utf8,${encodeURIComponent(Kee)}`,Yee=w.memo(function(){const e=Bee(),n=z(),r=U("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),s=Wee(e);return["licensed-with-watermark","unlicensed"].includes(s)?d.jsxs(d.Fragment,{children:[d.jsx(qee,{}),d.jsx(Xee,{src:r?Vee:Gee})]}):null}),Xee=w.memo(function({src:e}){const n=z(),r=U("debug mode",()=>n.getInstanceState().isDebugMode,[n]),s=U("is mobile",()=>n.getViewportScreenBounds().width<700,[n]),o=fb(),i=w.useRef(null);Ai(i);const a=`url('${e}') center 100% / 100% no-repeat`,l="https://tldraw.dev";return d.jsx("div",{ref:i,className:Vg.className,"data-debug":r,"data-mobile":s,draggable:!1,...o,children:Ge.isWebview?d.jsx("a",{draggable:!1,role:"button",onPointerDown:c=>{Ct(c),xe(c)},onClick:()=>Rg.openWindow(l,"_blank"),style:{mask:a,WebkitMask:a}}):d.jsx("a",{href:l,target:"_blank",rel:"noreferrer",draggable:!1,onPointerDown:c=>{Ct(c)},style:{mask:a,WebkitMask:a}})})}),qee=w.memo(function(){const e=Vg.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})}),Zee=[],Qee=[],Jee=[],ete="tl-container",tte=w.memo(function({store:e,components:n,className:r,user:s,options:o,...i}){const[a,l]=w.useState(null),c=w.useMemo(()=>s??Fj(),[s]),u=(n==null?void 0:n.ErrorFallback)===void 0?Tj:n==null?void 0:n.ErrorFallback,h={...i,shapeUtils:i.shapeUtils??Zee,bindingUtils:i.bindingUtils??Qee,tools:i.tools??Jee,components:n,options:tc(o)};return d.jsx("div",{ref:l,"data-tldraw":tj,draggable:!1,className:ce(`${ete} tl-theme__light`,r),onPointerDown:Ct,tabIndex:-1,children:d.jsx(Bu,{fallback:u,onError:f=>S0(f,{tags:{origin:"react.tldraw-before-app"}}),children:a&&d.jsx(Uee,{licenseKey:i.licenseKey,children:d.jsx(lj,{container:a,children:d.jsx(kZ,{overrides:n,children:e?e instanceof Z0?d.jsx(WR,{...h,store:e,user:c}):d.jsx(KR,{...h,store:e,user:c}):d.jsx(nte,{...h,store:e,user:c})})})})})})});function nte(t){const{defaultName:e,snapshot:n,initialData:r,shapeUtils:s,bindingUtils:o,persistenceKey:i,sessionId:a,user:l,assets:c,migrations:u}=t,h=Oee({shapeUtils:s,bindingUtils:o,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:n,assets:c,migrations:u});return d.jsx(KR,{...t,store:h,user:l})}const KR=w.memo(function({store:e,user:n,...r}){const s=Tt();w.useLayoutEffect(()=>{n.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,n]);const{LoadingScreen:o}=st();switch(e.status){case"error":throw e.error;case"loading":return o?d.jsx(o,{}):null}return d.jsx(WR,{...r,store:e.store,user:n})}),eS=()=>document.location.search.includes("tldraw_preserve_focus");function WR({onMount:t,children:e,store:n,tools:r,shapeUtils:s,bindingUtils:o,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:u,options:h,licenseKey:f,deepLinks:p,isShapeHidden:g}){const{ErrorFallback:m}=st(),v=Tt(),[y,S]=UR(null),b=w.useRef(null),P=tc(p===!0?{}:p),C=w.useRef({autoFocus:l&&!eS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P});w.useLayoutEffect(()=>{C.current={autoFocus:l&&!eS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P}},[l,c,a,u,P]),w.useLayoutEffect(()=>{const{autoFocus:k,inferDarkMode:D,initialState:T,cameraOptions:j,deepLinks:L}=C.current,M=new Q({store:n,shapeUtils:s,bindingUtils:o,tools:r,getContainer:()=>v,user:i,initialState:T,autoFocus:k,inferDarkMode:D,cameraOptions:j,options:h,licenseKey:f,isShapeHidden:g});return M.updateViewportScreenBounds(b.current??v),L&&(L!=null&&L.getUrl?M.navigateToDeepLink({...L,url:L.getUrl(M)}):M.navigateToDeepLink(L)),S(M),()=>{M.dispose()}},[o,v,h,s,n,r,i,S,f,g]),w.useLayoutEffect(()=>{if(y&&P)return y.registerDeepLinkListener(P)},[y,P]),w.useLayoutEffect(()=>{y&&u&&y.setCameraOptions(u)},[y,u]);const _=w.useSyncExternalStore(w.useCallback(k=>y?(y.on("crash",k),()=>y.off("crash",k)):()=>{},[y]),()=>(y==null?void 0:y.getCrashingError())??null);w.useEffect(function(){if(!y)return;function D(){y&&y.focus()}function T(){y&&y.blur()}if(l&&eS())return y.getContainer().addEventListener("pointerdown",D),document.body.addEventListener("pointerdown",T),()=>{var j;(j=y.getContainer())==null||j.removeEventListener("pointerdown",D),document.body.removeEventListener("pointerdown",T)}},[y,l]);const{Canvas:E}=st();return y?d.jsx(Bu,{fallback:m,onError:k=>y.annotateError(k,{origin:"react.tldraw",willCrashApp:!0}),children:_?d.jsx(ste,{crashingError:_}):d.jsx(ub,{editor:y,children:d.jsxs(rte,{onMount:t,children:[e??(E?d.jsx(E,{},y.contextId):null),d.jsx(Yee,{})]})})}):d.jsx("div",{className:"tl-canvas",ref:b})}function rte({children:t,onMount:e}){return Dee(),vee(),xee(),wee(),VR(n=>{const r=n.store.props.onMount(n),s=e==null?void 0:e(n);return()=>{r==null||r(),s==null||s()}}),t}function ste({crashingError:t}){throw t}function Ab({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function GR({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function VR(t){const e=z(),n=Bg(r=>{let s;return r.run(()=>{s=t==null?void 0:t(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});ke.useLayoutEffect(()=>{if(e)return n==null?void 0:n(e)},[e,n])}function hi({children:t,className:e="",...n}){return d.jsx("div",{...n,className:ce("tl-html-container",e),children:t})}class hf{constructor(e){this.editor=e}}I(hf,"props"),I(hf,"migrations"),I(hf,"type");function Yg(t,e,n={}){const{newPoint:r,handle:s,scaleX:o,scaleY:i}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let h=t.props.w*o,f=t.props.h*i;const p=new x(0,0);if(h>0){if(h<a){switch(s){case"top_left":case"left":case"bottom_left":{p.x=h-a;break}case"top":case"bottom":{p.x=(h-a)/2;break}default:p.x=0}h=a}}else if(p.x=h,h=-h,h<a){switch(s){case"top_left":case"left":case"bottom_left":{p.x=-h;break}default:p.x=-a}h=a}if(f>0){if(f<c){switch(s){case"top_left":case"top":case"top_right":{p.y=f-c;break}case"right":case"left":{p.y=(f-c)/2;break}default:p.y=0}f=c}}else if(p.y=f,f=-f,f<c){switch(s){case"top_left":case"top":case"top_right":{p.y=-f;break}default:p.y=-c}f=c}const{x:g,y:m}=p.rot(t.rotation).add(r);return{...t,x:g,y:m,props:{w:Math.min(l,h),h:Math.min(u,f)}}}class oc extends ss{getGeometry(e){return new Fs({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,n){return Yg(e,n)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,n,r){return{...n.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}var MS;let ote=(MS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(MS,"id","idle"),MS);var AS;let ite=(AS=class extends ie{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=this.parent.shapeType,s=Ke(),o=this.editor.markHistoryStoppingPoint(`creating_box:${s}`),i=is(n,this.editor);this.editor.createShapes([{id:s,type:r,x:i.x,y:i.y,props:{w:1,h:1}}]).select(s);const a=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?l=>{var c;return(c=a.onCreate)==null?void 0:c.call(a,l)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,n=this.parent.shapeType,r=Ke();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:n,x:e.x,y:e.y}]);const s=this.editor.getShape(r);if(!s){this.cancel();return}let{w:o,h:i}=s.props;const a=new x(o/2,i/2),l=this.editor.getShapeParentTransform(s);l&&a.rot(-l.rotation());let c=1;this.editor.user.getIsDynamicResizeMode()&&(c=1/this.editor.getZoomLevel(),o*=c,i*=c,a.mul(c));const u=nt(s),h=is(new x(s.x-a.x,s.y-a.y),this.editor);u.x=h.x,u.y=h.y,u.props.w=o,u.props.h=i,"scale"in s.props&&(u.props.scale=c),this.editor.updateShape(u),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},I(AS,"id","pointing"),AS);function is(t,e){const n=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return n?t.clone().snapToGrid(r):t.clone()}class jx extends ie{static children(){return[ote,ite]}}I(jx,"id","box"),I(jx,"initial","idle");function ate(t,e,n){const r=w.useRef(!1),s=w.useCallback(i=>{r.current=i,i?Vr.addOpenMenu(t):Vr.deleteOpenMenu(t),e==null||e(i)},[t,e]),o=U("is menu open",()=>Vr.getOpenMenus().includes(t),[t]);return w.useEffect(()=>(r.current&&(n==null||n("open-menu"),Vr.addOpenMenu(t)),()=>{r.current&&(Vr.deleteOpenMenu(t),Vr.getOpenMenus().forEach(i=>{i.startsWith(t)&&(n==null||n("close-menu"),Vr.deleteOpenMenu(i))}),r.current=!1)}),[t,n]),[o,s]}function Xg(t){const e=z();return U("isEditing",()=>e.getEditingShapeId()===t,[e,t])}function ws(t){const e=z();return w.useMemo(function(){const s=c=>{if(c.isKilled)return;if(c.button===hb){e.dispatch({type:"pointer",target:"selection",handle:t,name:"right_click",...lr(c)});return}if(c.button!==0)return;const u=Dp(c.currentTarget);function h(){u.removeEventListener("pointerup",h),dd(u,c)}ud(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:t,...lr(c)}),Ct(c)};let o,i;function a(c){c.isKilled||c.button===0&&(c.clientX===o&&c.clientY===i||(o=c.clientX,i=c.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:t,...lr(c)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:t,...lr(c)})}}},[e,t])}function lte(t){const[e,n]=w.useState(()=>({store:Uu(t),opts:t}));if(!RT(e.opts,t)){const r={store:Uu(t),opts:t};return n(r),r.store}return e.store}const cte=20,ute=8;function jb(t,e=cte){return Math.max(ute,Math.ceil(t/e))}class ll extends Mi{constructor(n){super({...n,isFilled:!1,isClosed:!1});I(this,"_center");I(this,"radius");I(this,"start");I(this,"end");I(this,"largeArcFlag");I(this,"sweepFlag");I(this,"measure");I(this,"angleStart");I(this,"angleEnd");const{center:r,sweepFlag:s,largeArcFlag:o,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=mX(this.angleStart,this.angleEnd,s,o),this.start=i,this.end=a,this.sweepFlag=s,this.largeArcFlag=o,this._center=r}nearestPoint(n){const{_center:r,measure:s,radius:o,angleEnd:i,angleStart:a,start:l,end:c}=this,u=vx(s,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(o));let f,p=1/0,g;for(const m of[l,c,h])g=x.Dist2(n,m),g<p&&(f=m,p=g);if(!f)throw Error("nearest point not found");return f}hitTestLineSegment(n,r){const{_center:s,radius:o,measure:i,angleStart:a,angleEnd:l}=this,c=pd(n,r,s,o);return c===null?!1:c.some(u=>{const h=vx(i,a,l,s.angle(u));return h>=0&&h<=1})}getVertices(){const{_center:n,measure:r,length:s,radius:o,angleStart:i}=this,a=[];for(let l=0,c=jb(Math.abs(s));l<c+1;l++){const u=l/c*r,h=i+u;a.push(ha(n,o,h))}return a}getSvgPathData(n=!0){const{start:r,end:s,radius:o,largeArcFlag:i,sweepFlag:a}=this;return`${n?`M${r.toFixed()}`:""} A${o} ${o} 0 ${i} ${a} ${s.toFixed()}`}getLength(){return this.measure*this.radius}}class Ob extends Mi{constructor(n){super({isClosed:!0,...n});I(this,"_center");I(this,"radius");I(this,"x");I(this,"y");this.config=n;const{x:r=0,y:s=0,radius:o}=n;this.x=r,this.y=s,this._center=new x(o+r,o+s),this.radius=o}getBounds(){return new Z(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,s=Fe*r,o=[];for(let i=0,a=jb(s);i<a;i++){const l=i/a*Fe;o.push(ha(n,r,l))}return o}nearestPoint(n){const{_center:r,radius:s}=this;return r.equals(n)?x.AddXY(r,s,0):r.clone().add(n.clone().sub(r).uni().mul(s))}hitTestLineSegment(n,r,s=0){const{_center:o,radius:i}=this;return pd(n,r,o,i+s)!==null}getSvgPathData(){const{_center:n,radius:r}=this;return`M${n.x+r},${n.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class an extends nc{constructor(n){const{start:r,cp1:s,cp2:o,end:i}=n;super({...n,points:[r,i]});I(this,"a");I(this,"b");I(this,"c");I(this,"d");this.a=r,this.b=s,this.c=o,this.d=i}getVertices(){const n=[],{a:r,b:s,c:o,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*s.x+3*(1-c)*(c*c)*o.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*s.y+3*(1-c)*(c*c)*o.y+c*c*c*i.y))}return n}midPoint(){return an.GetAtT(this,.5)}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}getSvgPathData(n=!0){const{a:r,b:s,c:o,d:i}=this;return`${n?`M ${r.toFixed()} `:""} C${s.toFixed()} ${o.toFixed()} ${i.toFixed()}`}static GetAtT(n,r){const{a:s,b:o,c:i,d:a}=n;return new x((1-r)*(1-r)*(1-r)*s.x+3*((1-r)*(1-r))*r*o.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*s.y+3*((1-r)*(1-r))*r*o.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(n=32){let r,s=this.a,o=0;for(let i=1;i<=n;i++)r=an.GetAtT(this,i/n),o+=x.Dist(s,r),s=r;return o}}class dte extends Mi{constructor(n){super({...n,isClosed:!1,isFilled:!1});I(this,"points");I(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,s=r-2,o=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===s?c:n[i+2],h=l,f=i===0?a:new x(l.x+(c.x-a.x)/6*o,l.y+(c.y-a.y)/6*o),p=i===s?c:new x(c.x-(u.x-l.x)/6*o,c.y-(u.y-l.y)/6*o),g=c;this._segments.push(new an({start:h,cp1:f,cp2:p,end:g}))}}return this._segments}getLength(){return this.segments.reduce((n,r)=>n+r.length,0)}getVertices(){const n=this.segments.reduce((r,s)=>r.concat(s.vertices),[]);return n.push(this.points[this.points.length-1]),n}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.segments.some(s=>s.hitTestLineSegment(n,r))}getSvgPathData(){let n=this.segments.reduce((r,s,o)=>r+s.getSvgPathData(o===0),"");return this.isClosed&&(n+="Z"),n}}class hte extends Mi{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(this,"_edges");this.config=n;const{width:r,height:s}=n;this.w=r,this.h=s}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,s=n.length;r<s;r++){const o=n[r],i=n[(r+1)%s];this._edges.push(new co({start:o,end:i}))}}return this._edges}getVertices(){const n=Math.max(1,this.w),r=Math.max(1,this.h),s=n/2,o=r/2,i=Math.pow(s-o,2)/Math.pow(s+o,2),a=De*(s+o)*(1+3*i/(10+Math.sqrt(4-3*i))),l=jb(a),c=Fe/l,u=Math.cos(c),h=Math.sin(c);let f=0,p=1,g=0,m=1;const v=Array(l);for(let y=0;y<l;y++)v[y]=new x(s+s*p,o+o*f),g=h*p+u*f,m=u*p-h*f,f=g,p=m;return v}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.edges)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(s=>s.hitTestLineSegment(n,r))}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{w:n,h:r}=this,s=n/2,o=r/2,i=Math.max(0,s),a=Math.max(0,o);return rj(i,a)}getSvgPathData(n=!1){const{w:r,h:s}=this,o=r/2,i=s/2,a=Math.max(0,o),l=Math.max(0,i);return`${n?`M${o-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class fte extends Mi{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(this,"a");I(this,"b");I(this,"c");I(this,"d");this.config=n;const{width:r,height:s}=n;if(this.w=r,this.h=s,s>r){const o=r/2;this.a=new ll({start:new x(0,o),end:new x(r,o),center:new x(r/2,o),sweepFlag:1,largeArcFlag:1}),this.b=new co({start:new x(r,o),end:new x(r,s-o)}),this.c=new ll({start:new x(r,s-o),end:new x(0,s-o),center:new x(r/2,s-o),sweepFlag:1,largeArcFlag:1}),this.d=new co({start:new x(0,s-o),end:new x(0,o)})}else{const o=s/2;this.a=new ll({start:new x(o,s),end:new x(o,0),center:new x(o,o),sweepFlag:1,largeArcFlag:1}),this.b=new co({start:new x(o,0),end:new x(r-o,0)}),this.c=new ll({start:new x(r-o,0),end:new x(r-o,s),center:new x(r-o,o),sweepFlag:1,largeArcFlag:1}),this.d=new co({start:new x(r-o,s),end:new x(o,s)})}}nearestPoint(n){let r,s=1/0,o,i;const{a,b:l,c,d:u}=this;for(const h of[a,l,c,u])i=h.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){const{a:s,b:o,c:i,d:a}=this;return[s,o,i,a].some(l=>l.hitTestLineSegment(n,r))}getVertices(){const{a:n,b:r,c:s,d:o}=this;return[n,r,s,o].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:s,d:o}=this;return[n,r,s,o].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function pte({shouldReload:t=!0}={}){lB();for(const e of vp.connectedInstances)await e.close();await Promise.all(X0().map(e=>lA(e))),aB(),t&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=pte);function gte(t,e="_blank"){Rg.openWindow(t,e)}_i("@tldraw/editor","3.7.2","esm");function YR(){const[t,e]=w.useState(!1);return w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{e(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),t}const XR=()=>{},qR=w.createContext(null);function mte({onEvent:t,children:e}){return d.jsx(qR.Provider,{value:t??XR,children:e})}function Jt(){return w.useContext(qR)??XR}function se(t,e,{checkForDefaultPrevented:n=!0}={}){return function(s){if(t==null||t(s),n===!1||!s.defaultPrevented)return e==null?void 0:e(s)}}function yte(t,e){const n=w.createContext(e),r=o=>{const{children:i,...a}=o,l=w.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=t+"Provider";function s(o){const i=w.useContext(n);if(i)return i;if(e!==void 0)return e;throw new Error(`\`${o}\` must be used within \`${t}\``)}return[r,s]}function Ws(t,e=[]){let n=[];function r(o,i){const a=w.createContext(i),l=n.length;n=[...n,i];const c=h=>{var y;const{scope:f,children:p,...g}=h,m=((y=f==null?void 0:f[t])==null?void 0:y[l])||a,v=w.useMemo(()=>g,Object.values(g));return d.jsx(m.Provider,{value:v,children:p})};c.displayName=o+"Provider";function u(h,f){var m;const p=((m=f==null?void 0:f[t])==null?void 0:m[l])||a,g=w.useContext(p);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${o}\``)}return[c,u]}const s=()=>{const o=n.map(i=>w.createContext(i));return function(a){const l=(a==null?void 0:a[t])||o;return w.useMemo(()=>({[`__scope${t}`]:{...a,[t]:l}}),[a,l])}};return s.scopeName=t,[r,Ste(s,...e)]}function Ste(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(o)[`__scope${c}`];return{...a,...h}},{});return w.useMemo(()=>({[`__scope${e.scopeName}`]:i}),[i])}};return n.scopeName=e.scopeName,n}function BI(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function qg(...t){return e=>{let n=!1;const r=t.map(s=>{const o=BI(s,e);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let s=0;s<r.length;s++){const o=r[s];typeof o=="function"?o():BI(t[s],null)}}}}function Qe(...t){return w.useCallback(qg(...t),t)}var fa=w.forwardRef((t,e)=>{const{children:n,...r}=t,s=w.Children.toArray(n),o=s.find(xte);if(o){const i=o.props.children,a=s.map(l=>l===o?w.Children.count(i)>1?w.Children.only(null):w.isValidElement(i)?i.props.children:null:l);return d.jsx(Ox,{...r,ref:e,children:w.isValidElement(i)?w.cloneElement(i,void 0,a):null})}return d.jsx(Ox,{...r,ref:e,children:n})});fa.displayName="Slot";var Ox=w.forwardRef((t,e)=>{const{children:n,...r}=t;if(w.isValidElement(n)){const s=bte(n);return w.cloneElement(n,{...wte(r,n.props),ref:e?qg(e,s):s})}return w.Children.count(n)>1?w.Children.only(null):null});Ox.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 s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...a)=>{o(...a),s(...a)}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"&&(n[r]=[s,o].filter(Boolean).join(" "))}return{...t,...n}}function bte(t){var r,s;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=(s=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:s.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,s)=>{const{asChild:o,...i}=r,a=o?fa:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(a,{...i,ref:s})});return n.displayName=`Primitive.${e}`,{...t,[e]:n}},{});function Db(t,e){t&&ba.flushSync(()=>t.dispatchEvent(e))}function Zg(t){const e=t+"CollectionProvider",[n,r]=Ws(e),[s,o]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=p=>{const{scope:g,children:m}=p,v=ke.useRef(null),y=ke.useRef(new Map).current;return d.jsx(s,{scope:g,itemMap:y,collectionRef:v,children:m})};i.displayName=e;const a=t+"CollectionSlot",l=ke.forwardRef((p,g)=>{const{scope:m,children:v}=p,y=o(a,m),S=Qe(g,y.collectionRef);return d.jsx(fa,{ref:S,children:v})});l.displayName=a;const c=t+"CollectionItemSlot",u="data-radix-collection-item",h=ke.forwardRef((p,g)=>{const{scope:m,children:v,...y}=p,S=ke.useRef(null),b=Qe(g,S),P=o(c,m);return ke.useEffect(()=>(P.itemMap.set(S,{ref:S,...y}),()=>void P.itemMap.delete(S))),d.jsx(fa,{[u]:"",ref:b,children:v})});h.displayName=c;function f(p){const g=o(t+"CollectionConsumer",p);return ke.useCallback(()=>{const v=g.collectionRef.current;if(!v)return[];const y=Array.from(v.querySelectorAll(`[${u}]`));return Array.from(g.itemMap.values()).sort((P,C)=>y.indexOf(P.ref.current)-y.indexOf(C.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},f,r]}var Cte=w.createContext(void 0);function Rb(t){const e=w.useContext(Cte);return t||e||"ltr"}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 _te(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t);w.useEffect(()=>{const r=s=>{s.key==="Escape"&&n(s)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var Ite="DismissableLayer",Dx="dismissableLayer.update",Ete="dismissableLayer.pointerDownOutside",kte="dismissableLayer.focusOutside",UI,ZR=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),xd=w.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:i,onDismiss:a,...l}=t,c=w.useContext(ZR),[u,h]=w.useState(null),f=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=w.useState({}),g=Qe(e,E=>h(E)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=m.indexOf(v),S=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,P=S>=y,C=Mte(E=>{const k=E.target,D=[...c.branches].some(T=>T.contains(k));!P||D||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},f),_=Ate(E=>{const k=E.target;[...c.branches].some(T=>T.contains(k))||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},f);return _te(E=>{S===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},f),w.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(UI=f.body.style.pointerEvents,f.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),HI(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(f.body.style.pointerEvents=UI)}},[u,f,n,c]),w.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),HI())},[u,c]),w.useEffect(()=>{const E=()=>p({});return document.addEventListener(Dx,E),()=>document.removeEventListener(Dx,E)},[]),d.jsx(Ae.div,{...l,ref:g,style:{pointerEvents:b?P?"auto":"none":void 0,...t.style},onFocusCapture:se(t.onFocusCapture,_.onFocusCapture),onBlurCapture:se(t.onBlurCapture,_.onBlurCapture),onPointerDownCapture:se(t.onPointerDownCapture,C.onPointerDownCapture)})});xd.displayName=Ite;var Tte="DismissableLayerBranch",QR=w.forwardRef((t,e)=>{const n=w.useContext(ZR),r=w.useRef(null),s=Qe(e,r);return w.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),d.jsx(Ae.div,{...t,ref:s})});QR.displayName=Tte;function Mte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1),s=w.useRef(()=>{});return w.useEffect(()=>{const o=a=>{if(a.target&&!r.current){let l=function(){JR(Ete,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",s.current),s.current=l,e.addEventListener("click",s.current,{once:!0})):l()}else e.removeEventListener("click",s.current);r.current=!1},i=window.setTimeout(()=>{e.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(i),e.removeEventListener("pointerdown",o),e.removeEventListener("click",s.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function Ate(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1);return w.useEffect(()=>{const s=o=>{o.target&&!r.current&&JR(kte,n,{originalEvent:o},{discrete:!1})};return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function HI(){const t=new CustomEvent(Dx);document.dispatchEvent(t)}function JR(t,e,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?Db(s,o):s.dispatchEvent(o)}var jte=xd,Ote=QR,tS=0;function Lb(){w.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??KI()),document.body.insertAdjacentElement("beforeend",t[1]??KI()),tS++,()=>{tS===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),tS--}},[])}function KI(){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 nS="focusScope.autoFocusOnMount",rS="focusScope.autoFocusOnUnmount",WI={bubbles:!1,cancelable:!0},Dte="FocusScope",Qg=w.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:o,...i}=t,[a,l]=w.useState(null),c=qt(s),u=qt(o),h=w.useRef(null),f=Qe(e,m=>l(m)),p=w.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;w.useEffect(()=>{if(r){let m=function(b){if(p.paused||!a)return;const P=b.target;a.contains(P)?h.current=P:Uo(h.current,{select:!0})},v=function(b){if(p.paused||!a)return;const P=b.relatedTarget;P!==null&&(a.contains(P)||Uo(h.current,{select:!0}))},y=function(b){if(document.activeElement===document.body)for(const C of b)C.removedNodes.length>0&&Uo(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const S=new MutationObserver(y);return a&&S.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),S.disconnect()}}},[r,a,p.paused]),w.useEffect(()=>{if(a){VI.add(p);const m=document.activeElement;if(!a.contains(m)){const y=new CustomEvent(nS,WI);a.addEventListener(nS,c),a.dispatchEvent(y),y.defaultPrevented||(Rte(zte(e3(a)),{select:!0}),document.activeElement===m&&Uo(a))}return()=>{a.removeEventListener(nS,c),setTimeout(()=>{const y=new CustomEvent(rS,WI);a.addEventListener(rS,u),a.dispatchEvent(y),y.defaultPrevented||Uo(m??document.body,{select:!0}),a.removeEventListener(rS,u),VI.remove(p)},0)}}},[a,c,u,p]);const g=w.useCallback(m=>{if(!n&&!r||p.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,y=document.activeElement;if(v&&y){const S=m.currentTarget,[b,P]=Lte(S);b&&P?!m.shiftKey&&y===P?(m.preventDefault(),n&&Uo(b,{select:!0})):m.shiftKey&&y===b&&(m.preventDefault(),n&&Uo(P,{select:!0})):y===S&&m.preventDefault()}},[n,r,p.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:f,onKeyDown:g})});Qg.displayName=Dte;function Rte(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Uo(r,{select:e}),document.activeElement!==n)return}function Lte(t){const e=e3(t),n=GI(e,t),r=GI(e.reverse(),t);return[n,r]}function e3(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function GI(t,e){for(const n of t)if(!$te(n,{upTo:e}))return n}function $te(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 Fte(t){return t instanceof HTMLInputElement&&"select"in t}function Uo(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&Fte(t)&&e&&t.select()}}var VI=Nte();function Nte(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=YI(t,e),t.unshift(e)},remove(e){var n;t=YI(t,e),(n=t[0])==null||n.resume()}}}function YI(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function zte(t){return t.filter(e=>e.tagName!=="A")}var yi=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{},Bte=Q4.useId||(()=>{}),Ute=0;function mo(t){const[e,n]=w.useState(Bte());return yi(()=>{n(r=>r??String(Ute++))},[t]),t||(e?`radix-${e}`:"")}const Hte=["top","right","bottom","left"],Si=Math.min,or=Math.max,$p=Math.round,wh=Math.floor,Os=t=>({x:t,y:t}),Kte={left:"right",right:"left",bottom:"top",top:"bottom"},Wte={start:"end",end:"start"};function Rx(t,e,n){return or(t,Si(e,n))}function bo(t,e){return typeof t=="function"?t(e):t}function Po(t){return t.split("-")[0]}function ic(t){return t.split("-")[1]}function $b(t){return t==="x"?"y":"x"}function Fb(t){return t==="y"?"height":"width"}function vi(t){return["top","bottom"].includes(Po(t))?"y":"x"}function Nb(t){return $b(vi(t))}function Gte(t,e,n){n===void 0&&(n=!1);const r=ic(t),s=Nb(t),o=Fb(s);let i=s==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(i=Fp(i)),[i,Fp(i)]}function Vte(t){const e=Fp(t);return[Lx(t),e,Lx(e)]}function Lx(t){return t.replace(/start|end/g,e=>Wte[e])}function Yte(t,e,n){const r=["left","right"],s=["right","left"],o=["top","bottom"],i=["bottom","top"];switch(t){case"top":case"bottom":return n?e?s:r:e?r:s;case"left":case"right":return e?o:i;default:return[]}}function Xte(t,e,n,r){const s=ic(t);let o=Yte(Po(t),n==="start",r);return s&&(o=o.map(i=>i+"-"+s),e&&(o=o.concat(o.map(Lx)))),o}function Fp(t){return t.replace(/left|right|bottom|top/g,e=>Kte[e])}function qte(t){return{top:0,right:0,bottom:0,left:0,...t}}function t3(t){return typeof t!="number"?qte(t):{top:t,right:t,bottom:t,left:t}}function Np(t){const{x:e,y:n,width:r,height:s}=t;return{width:r,height:s,top:n,left:e,right:e+r,bottom:n+s,x:e,y:n}}function XI(t,e,n){let{reference:r,floating:s}=t;const o=vi(e),i=Nb(e),a=Fb(i),l=Po(e),c=o==="y",u=r.x+r.width/2-s.width/2,h=r.y+r.height/2-s.height/2,f=r[a]/2-s[a]/2;let p;switch(l){case"top":p={x:u,y:r.y-s.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:h};break;case"left":p={x:r.x-s.width,y:h};break;default:p={x:r.x,y:r.y}}switch(ic(e)){case"start":p[i]-=f*(n&&c?-1:1);break;case"end":p[i]+=f*(n&&c?-1:1);break}return p}const Zte=async(t,e,n)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:i}=n,a=o.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(e));let c=await i.getElementRects({reference:t,floating:e,strategy:s}),{x:u,y:h}=XI(c,r,l),f=r,p={},g=0;for(let m=0;m<a.length;m++){const{name:v,fn:y}=a[m],{x:S,y:b,data:P,reset:C}=await y({x:u,y:h,initialPlacement:r,placement:f,strategy:s,middlewareData:p,rects:c,platform:i,elements:{reference:t,floating:e}});u=S??u,h=b??h,p={...p,[v]:{...p[v],...P}},C&&g<=50&&(g++,typeof C=="object"&&(C.placement&&(f=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:t,floating:e,strategy:s}):C.rects),{x:u,y:h}=XI(c,f,l)),m=-1)}return{x:u,y:h,placement:f,strategy:s,middlewareData:p}};async function Hu(t,e){var n;e===void 0&&(e={});const{x:r,y:s,platform:o,rects:i,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:f=!1,padding:p=0}=bo(e,t),g=t3(p),v=a[f?h==="floating"?"reference":"floating":h],y=Np(await o.getClippingRect({element:(n=await(o.isElement==null?void 0:o.isElement(v)))==null||n?v:v.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),S=h==="floating"?{x:r,y:s,width:i.floating.width,height:i.floating.height}:i.reference,b=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),P=await(o.isElement==null?void 0:o.isElement(b))?await(o.getScale==null?void 0:o.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Np(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:S,offsetParent:b,strategy:l}):S);return{top:(y.top-C.top+g.top)/P.y,bottom:(C.bottom-y.bottom+g.bottom)/P.y,left:(y.left-C.left+g.left)/P.x,right:(C.right-y.right+g.right)/P.x}}const Qte=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:s,rects:o,platform:i,elements:a,middlewareData:l}=e,{element:c,padding:u=0}=bo(t,e)||{};if(c==null)return{};const h=t3(u),f={x:n,y:r},p=Nb(s),g=Fb(p),m=await i.getDimensions(c),v=p==="y",y=v?"top":"left",S=v?"bottom":"right",b=v?"clientHeight":"clientWidth",P=o.reference[g]+o.reference[p]-f[p]-o.floating[g],C=f[p]-o.reference[p],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=_?_[b]:0;(!E||!await(i.isElement==null?void 0:i.isElement(_)))&&(E=a.floating[b]||o.floating[g]);const k=P/2-C/2,D=E/2-m[g]/2-1,T=Si(h[y],D),j=Si(h[S],D),L=T,M=E-m[g]-j,O=E/2-m[g]/2+k,F=Rx(L,O,M),B=!l.arrow&&ic(s)!=null&&O!==F&&o.reference[g]/2-(O<L?T:j)-m[g]/2<0,K=B?O<L?O-L:O-M:0;return{[p]:f[p]+K,data:{[p]:F,centerOffset:O-F-K,...B&&{alignmentOffset:K}},reset:B}}}),Jte=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:s,middlewareData:o,rects:i,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:h=!0,fallbackPlacements:f,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:m=!0,...v}=bo(t,e);if((n=o.arrow)!=null&&n.alignmentOffset)return{};const y=Po(s),S=vi(a),b=Po(a)===a,P=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=f||(b||!m?[Fp(a)]:Vte(a)),_=g!=="none";!f&&_&&C.push(...Xte(a,m,g,P));const E=[a,...C],k=await Hu(e,v),D=[];let T=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&D.push(k[y]),h){const O=Gte(s,i,P);D.push(k[O[0]],k[O[1]])}if(T=[...T,{placement:s,overflows:D}],!D.every(O=>O<=0)){var j,L;const O=(((j=o.flip)==null?void 0:j.index)||0)+1,F=E[O];if(F)return{data:{index:O,overflows:T},reset:{placement:F}};let B=(L=T.filter(K=>K.overflows[0]<=0).sort((K,R)=>K.overflows[1]-R.overflows[1])[0])==null?void 0:L.placement;if(!B)switch(p){case"bestFit":{var M;const K=(M=T.filter(R=>{if(_){const H=vi(R.placement);return H===S||H==="y"}return!0}).map(R=>[R.placement,R.overflows.filter(H=>H>0).reduce((H,X)=>H+X,0)]).sort((R,H)=>R[1]-H[1])[0])==null?void 0:M[0];K&&(B=K);break}case"initialPlacement":B=a;break}if(s!==B)return{reset:{placement:B}}}return{}}}};function qI(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function ZI(t){return Hte.some(e=>t[e]>=0)}const ene=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...s}=bo(t,e);switch(r){case"referenceHidden":{const o=await Hu(e,{...s,elementContext:"reference"}),i=qI(o,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:ZI(i)}}}case"escaped":{const o=await Hu(e,{...s,altBoundary:!0}),i=qI(o,n.floating);return{data:{escapedOffsets:i,escaped:ZI(i)}}}default:return{}}}}};async function tne(t,e){const{placement:n,platform:r,elements:s}=t,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),i=Po(n),a=ic(n),l=vi(n)==="y",c=["left","top"].includes(i)?-1:1,u=o&&l?-1:1,h=bo(e,t);let{mainAxis:f,crossAxis:p,alignmentAxis:g}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof g=="number"&&(p=a==="end"?g*-1:g),l?{x:p*u,y:f*c}:{x:f*c,y:p*u}}const nne=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:s,y:o,placement:i,middlewareData:a}=e,l=await tne(e,t);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:o+l.y,data:{...l,placement:i}}}}},rne=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:s}=e,{mainAxis:o=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x:y,y:S}=v;return{x:y,y:S}}},...l}=bo(t,e),c={x:n,y:r},u=await Hu(e,l),h=vi(Po(s)),f=$b(h);let p=c[f],g=c[h];if(o){const v=f==="y"?"top":"left",y=f==="y"?"bottom":"right",S=p+u[v],b=p-u[y];p=Rx(S,p,b)}if(i){const v=h==="y"?"top":"left",y=h==="y"?"bottom":"right",S=g+u[v],b=g-u[y];g=Rx(S,g,b)}const m=a.fn({...e,[f]:p,[h]:g});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[f]:o,[h]:i}}}}}},sne=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:s,rects:o,middlewareData:i}=e,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=bo(t,e),u={x:n,y:r},h=vi(s),f=$b(h);let p=u[f],g=u[h];const m=bo(a,e),v=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const b=f==="y"?"height":"width",P=o.reference[f]-o.floating[b]+v.mainAxis,C=o.reference[f]+o.reference[b]-v.mainAxis;p<P?p=P:p>C&&(p=C)}if(c){var y,S;const b=f==="y"?"width":"height",P=["top","left"].includes(Po(s)),C=o.reference[h]-o.floating[b]+(P&&((y=i.offset)==null?void 0:y[h])||0)+(P?0:v.crossAxis),_=o.reference[h]+o.reference[b]+(P?0:((S=i.offset)==null?void 0:S[h])||0)-(P?v.crossAxis:0);g<C?g=C:g>_&&(g=_)}return{[f]:p,[h]:g}}}},one=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,r;const{placement:s,rects:o,platform:i,elements:a}=e,{apply:l=()=>{},...c}=bo(t,e),u=await Hu(e,c),h=Po(s),f=ic(s),p=vi(s)==="y",{width:g,height:m}=o.floating;let v,y;h==="top"||h==="bottom"?(v=h,y=f===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=h,v=f==="end"?"top":"bottom");const S=m-u.top-u.bottom,b=g-u.left-u.right,P=Si(m-u[v],S),C=Si(g-u[y],b),_=!e.middlewareData.shift;let E=P,k=C;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(k=b),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(E=S),_&&!f){const T=or(u.left,0),j=or(u.right,0),L=or(u.top,0),M=or(u.bottom,0);p?k=g-2*(T!==0||j!==0?T+j:or(u.left,u.right)):E=m-2*(L!==0||M!==0?L+M:or(u.top,u.bottom))}await l({...e,availableWidth:k,availableHeight:E});const D=await i.getDimensions(a.floating);return g!==D.width||m!==D.height?{reset:{rects:!0}}:{}}}};function Jg(){return typeof window<"u"}function ac(t){return n3(t)?(t.nodeName||"").toLowerCase():"#document"}function fr(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Gs(t){var e;return(e=(n3(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function n3(t){return Jg()?t instanceof Node||t instanceof fr(t).Node:!1}function as(t){return Jg()?t instanceof Element||t instanceof fr(t).Element:!1}function Ns(t){return Jg()?t instanceof HTMLElement||t instanceof fr(t).HTMLElement:!1}function QI(t){return!Jg()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof fr(t).ShadowRoot}function wd(t){const{overflow:e,overflowX:n,overflowY:r,display:s}=ls(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!["inline","contents"].includes(s)}function ine(t){return["table","td","th"].includes(ac(t))}function em(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function zb(t){const e=Bb(),n=as(t)?ls(t):t;return["transform","translate","scale","rotate","perspective"].some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function ane(t){let e=xi(t);for(;Ns(e)&&!Dl(e);){if(zb(e))return e;if(em(e))return null;e=xi(e)}return null}function Bb(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Dl(t){return["html","body","#document"].includes(ac(t))}function ls(t){return fr(t).getComputedStyle(t)}function tm(t){return as(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function xi(t){if(ac(t)==="html")return t;const e=t.assignedSlot||t.parentNode||QI(t)&&t.host||Gs(t);return QI(e)?e.host:e}function r3(t){const e=xi(t);return Dl(e)?t.ownerDocument?t.ownerDocument.body:t.body:Ns(e)&&wd(e)?e:r3(e)}function Ku(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const s=r3(t),o=s===((r=t.ownerDocument)==null?void 0:r.body),i=fr(s);if(o){const a=$x(i);return e.concat(i,i.visualViewport||[],wd(s)?s:[],a&&n?Ku(a):[])}return e.concat(s,Ku(s,[],n))}function $x(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function s3(t){const e=ls(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=Ns(t),o=s?t.offsetWidth:n,i=s?t.offsetHeight:r,a=$p(n)!==o||$p(r)!==i;return a&&(n=o,r=i),{width:n,height:r,$:a}}function Ub(t){return as(t)?t:t.contextElement}function bl(t){const e=Ub(t);if(!Ns(e))return Os(1);const n=e.getBoundingClientRect(),{width:r,height:s,$:o}=s3(e);let i=(o?$p(n.width):n.width)/r,a=(o?$p(n.height):n.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const lne=Os(0);function o3(t){const e=fr(t);return!Bb()||!e.visualViewport?lne:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function cne(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==fr(t)?!1:e}function pa(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const s=t.getBoundingClientRect(),o=Ub(t);let i=Os(1);e&&(r?as(r)&&(i=bl(r)):i=bl(t));const a=cne(o,n,r)?o3(o):Os(0);let l=(s.left+a.x)/i.x,c=(s.top+a.y)/i.y,u=s.width/i.x,h=s.height/i.y;if(o){const f=fr(o),p=r&&as(r)?fr(r):r;let g=f,m=$x(g);for(;m&&r&&p!==g;){const v=bl(m),y=m.getBoundingClientRect(),S=ls(m),b=y.left+(m.clientLeft+parseFloat(S.paddingLeft))*v.x,P=y.top+(m.clientTop+parseFloat(S.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,h*=v.y,l+=b,c+=P,g=fr(m),m=$x(g)}}return Np({width:u,height:h,x:l,y:c})}function Hb(t,e){const n=tm(t).scrollLeft;return e?e.left+n:pa(Gs(t)).left+n}function i3(t,e,n){n===void 0&&(n=!1);const r=t.getBoundingClientRect(),s=r.left+e.scrollLeft-(n?0:Hb(t,r)),o=r.top+e.scrollTop;return{x:s,y:o}}function une(t){let{elements:e,rect:n,offsetParent:r,strategy:s}=t;const o=s==="fixed",i=Gs(r),a=e?em(e.floating):!1;if(r===i||a&&o)return n;let l={scrollLeft:0,scrollTop:0},c=Os(1);const u=Os(0),h=Ns(r);if((h||!h&&!o)&&((ac(r)!=="body"||wd(i))&&(l=tm(r)),Ns(r))){const p=pa(r);c=bl(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const f=i&&!h&&!o?i3(i,l,!0):Os(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+f.x,y:n.y*c.y-l.scrollTop*c.y+u.y+f.y}}function dne(t){return Array.from(t.getClientRects())}function hne(t){const e=Gs(t),n=tm(t),r=t.ownerDocument.body,s=or(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),o=or(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Hb(t);const a=-n.scrollTop;return ls(r).direction==="rtl"&&(i+=or(e.clientWidth,r.clientWidth)-s),{width:s,height:o,x:i,y:a}}function fne(t,e){const n=fr(t),r=Gs(t),s=n.visualViewport;let o=r.clientWidth,i=r.clientHeight,a=0,l=0;if(s){o=s.width,i=s.height;const c=Bb();(!c||c&&e==="fixed")&&(a=s.offsetLeft,l=s.offsetTop)}return{width:o,height:i,x:a,y:l}}function pne(t,e){const n=pa(t,!0,e==="fixed"),r=n.top+t.clientTop,s=n.left+t.clientLeft,o=Ns(t)?bl(t):Os(1),i=t.clientWidth*o.x,a=t.clientHeight*o.y,l=s*o.x,c=r*o.y;return{width:i,height:a,x:l,y:c}}function JI(t,e,n){let r;if(e==="viewport")r=fne(t,n);else if(e==="document")r=hne(Gs(t));else if(as(e))r=pne(e,n);else{const s=o3(t);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return Np(r)}function a3(t,e){const n=xi(t);return n===e||!as(n)||Dl(n)?!1:ls(n).position==="fixed"||a3(n,e)}function gne(t,e){const n=e.get(t);if(n)return n;let r=Ku(t,[],!1).filter(a=>as(a)&&ac(a)!=="body"),s=null;const o=ls(t).position==="fixed";let i=o?xi(t):t;for(;as(i)&&!Dl(i);){const a=ls(i),l=zb(i);!l&&a.position==="fixed"&&(s=null),(o?!l&&!s:!l&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||wd(i)&&!l&&a3(t,i))?r=r.filter(u=>u!==i):s=a,i=xi(i)}return e.set(t,r),r}function mne(t){let{element:e,boundary:n,rootBoundary:r,strategy:s}=t;const i=[...n==="clippingAncestors"?em(e)?[]:gne(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=JI(e,u,s);return c.top=or(h.top,c.top),c.right=Si(h.right,c.right),c.bottom=Si(h.bottom,c.bottom),c.left=or(h.left,c.left),c},JI(e,a,s));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function yne(t){const{width:e,height:n}=s3(t);return{width:e,height:n}}function Sne(t,e,n){const r=Ns(e),s=Gs(e),o=n==="fixed",i=pa(t,!0,o,e);let a={scrollLeft:0,scrollTop:0};const l=Os(0);if(r||!r&&!o)if((ac(e)!=="body"||wd(s))&&(a=tm(e)),r){const f=pa(e,!0,o,e);l.x=f.x+e.clientLeft,l.y=f.y+e.clientTop}else s&&(l.x=Hb(s));const c=s&&!r&&!o?i3(s,a):Os(0),u=i.left+a.scrollLeft-l.x-c.x,h=i.top+a.scrollTop-l.y-c.y;return{x:u,y:h,width:i.width,height:i.height}}function sS(t){return ls(t).position==="static"}function eE(t,e){if(!Ns(t)||ls(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Gs(t)===n&&(n=n.ownerDocument.body),n}function l3(t,e){const n=fr(t);if(em(t))return n;if(!Ns(t)){let s=xi(t);for(;s&&!Dl(s);){if(as(s)&&!sS(s))return s;s=xi(s)}return n}let r=eE(t,e);for(;r&&ine(r)&&sS(r);)r=eE(r,e);return r&&Dl(r)&&sS(r)&&!zb(r)?n:r||ane(t)||n}const vne=async function(t){const e=this.getOffsetParent||l3,n=this.getDimensions,r=await n(t.floating);return{reference:Sne(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function xne(t){return ls(t).direction==="rtl"}const wne={convertOffsetParentRelativeRectToViewportRelativeRect:une,getDocumentElement:Gs,getClippingRect:mne,getOffsetParent:l3,getElementRects:vne,getClientRects:dne,getDimensions:yne,getScale:bl,isElement:as,isRTL:xne};function c3(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function bne(t,e){let n=null,r;const s=Gs(t);function o(){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),o();const c=t.getBoundingClientRect(),{left:u,top:h,width:f,height:p}=c;if(a||e(),!f||!p)return;const g=wh(h),m=wh(s.clientWidth-(u+f)),v=wh(s.clientHeight-(h+p)),y=wh(u),b={rootMargin:-g+"px "+-m+"px "+-v+"px "+-y+"px",threshold:or(0,Si(1,l))||1};let P=!0;function C(_){const E=_[0].intersectionRatio;if(E!==l){if(!P)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!c3(c,t.getBoundingClientRect())&&i(),P=!1}try{n=new IntersectionObserver(C,{...b,root:s.ownerDocument})}catch{n=new IntersectionObserver(C,b)}n.observe(t)}return i(!0),o}function Pne(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Ub(t),u=s||o?[...c?Ku(c):[],...Ku(e)]:[];u.forEach(y=>{s&&y.addEventListener("scroll",n,{passive:!0}),o&&y.addEventListener("resize",n)});const h=c&&a?bne(c,n):null;let f=-1,p=null;i&&(p=new ResizeObserver(y=>{let[S]=y;S&&S.target===c&&p&&(p.unobserve(e),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var b;(b=p)==null||b.observe(e)})),n()}),c&&!l&&p.observe(c),p.observe(e));let g,m=l?pa(t):null;l&&v();function v(){const y=pa(t);m&&!c3(m,y)&&n(),m=y,g=requestAnimationFrame(v)}return n(),()=>{var y;u.forEach(S=>{s&&S.removeEventListener("scroll",n),o&&S.removeEventListener("resize",n)}),h==null||h(),(y=p)==null||y.disconnect(),p=null,l&&cancelAnimationFrame(g)}}const Cne=nne,_ne=rne,Ine=Jte,Ene=one,kne=ene,tE=Qte,Tne=sne,Mne=(t,e,n)=>{const r=new Map,s={platform:wne,...n},o={...s.platform,_c:r};return Zte(t,e,{...s,platform:o})};var ff=typeof document<"u"?w.useLayoutEffect:w.useEffect;function zp(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,s;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(!zp(t[r],e[r]))return!1;return!0}if(s=Object.keys(t),n=s.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&t.$$typeof)&&!zp(t[o],e[o]))return!1}return!0}return t!==t&&e!==e}function u3(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function nE(t,e){const n=u3(t);return Math.round(e*n)/n}function oS(t){const e=w.useRef(t);return ff(()=>{e.current=t}),e}function Ane(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,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}),[f,p]=w.useState(r);zp(f,r)||p(r);const[g,m]=w.useState(null),[v,y]=w.useState(null),S=w.useCallback(R=>{R!==_.current&&(_.current=R,m(R))},[]),b=w.useCallback(R=>{R!==E.current&&(E.current=R,y(R))},[]),P=o||g,C=i||v,_=w.useRef(null),E=w.useRef(null),k=w.useRef(u),D=l!=null,T=oS(l),j=oS(s),L=oS(c),M=w.useCallback(()=>{if(!_.current||!E.current)return;const R={placement:e,strategy:n,middleware:f};j.current&&(R.platform=j.current),Mne(_.current,E.current,R).then(H=>{const X={...H,isPositioned:L.current!==!1};O.current&&!zp(k.current,X)&&(k.current=X,ba.flushSync(()=>{h(X)}))})},[f,e,n,j,L]);ff(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,h(R=>({...R,isPositioned:!1})))},[c]);const O=w.useRef(!1);ff(()=>(O.current=!0,()=>{O.current=!1}),[]),ff(()=>{if(P&&(_.current=P),C&&(E.current=C),P&&C){if(T.current)return T.current(P,C,M);M()}},[P,C,M,T,D]);const F=w.useMemo(()=>({reference:_,floating:E,setReference:S,setFloating:b}),[S,b]),B=w.useMemo(()=>({reference:P,floating:C}),[P,C]),K=w.useMemo(()=>{const R={position:n,left:0,top:0};if(!B.floating)return R;const H=nE(B.floating,u.x),X=nE(B.floating,u.y);return a?{...R,transform:"translate("+H+"px, "+X+"px)",...u3(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:X}},[n,a,B.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:M,refs:F,elements:B,floatingStyles:K}),[u,M,F,B,K])}const jne=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:s}=typeof t=="function"?t(n):t;return r&&e(r)?r.current!=null?tE({element:r.current,padding:s}).fn(n):{}:r?tE({element:r,padding:s}).fn(n):{}}}},One=(t,e)=>({...Cne(t),options:[t,e]}),Dne=(t,e)=>({..._ne(t),options:[t,e]}),Rne=(t,e)=>({...Tne(t),options:[t,e]}),Lne=(t,e)=>({...Ine(t),options:[t,e]}),$ne=(t,e)=>({...Ene(t),options:[t,e]}),Fne=(t,e)=>({...kne(t),options:[t,e]}),Nne=(t,e)=>({...jne(t),options:[t,e]});var zne="Arrow",d3=w.forwardRef((t,e)=>{const{children:n,width:r=10,height:s=5,...o}=t;return d.jsx(Ae.svg,{...o,ref:e,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});d3.displayName=zne;var Bne=d3;function h3(t){const[e,n]=w.useState(void 0);return yi(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const o=s[0];let i,a;if("borderBoxSize"in o){const l=o.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 Kb="Popper",[f3,nm]=Ws(Kb),[Une,p3]=f3(Kb),g3=t=>{const{__scopePopper:e,children:n}=t,[r,s]=w.useState(null);return d.jsx(Une,{scope:e,anchor:r,onAnchorChange:s,children:n})};g3.displayName=Kb;var m3="PopperAnchor",y3=w.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...s}=t,o=p3(m3,n),i=w.useRef(null),a=Qe(e,i);return w.useEffect(()=>{o.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(Ae.div,{...s,ref:a})});y3.displayName=m3;var Wb="PopperContent",[Hne,Kne]=f3(Wb),S3=w.forwardRef((t,e)=>{var Ne,lt,$e,Ye,We,er;const{__scopePopper:n,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:f=!1,updatePositionStrategy:p="optimized",onPlaced:g,...m}=t,v=p3(Wb,n),[y,S]=w.useState(null),b=Qe(e,$t=>S($t)),[P,C]=w.useState(null),_=h3(P),E=(_==null?void 0:_.width)??0,k=(_==null?void 0:_.height)??0,D=r+(o!=="center"?"-"+o:""),T=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},j=Array.isArray(c)?c:[c],L=j.length>0,M={padding:T,boundary:j.filter(Gne),altBoundary:L},{refs:O,floatingStyles:F,placement:B,isPositioned:K,middlewareData:R}=Ane({strategy:"fixed",placement:D,whileElementsMounted:(...$t)=>Pne(...$t,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[One({mainAxis:s+k,alignmentAxis:i}),l&&Dne({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Rne():void 0,...M}),l&&Lne({...M}),$ne({...M,apply:({elements:$t,rects:On,availableWidth:Mt,availableHeight:Ft})=>{const{width:jo,height:Ys}=On.reference,Oo=$t.floating.style;Oo.setProperty("--radix-popper-available-width",`${Mt}px`),Oo.setProperty("--radix-popper-available-height",`${Ft}px`),Oo.setProperty("--radix-popper-anchor-width",`${jo}px`),Oo.setProperty("--radix-popper-anchor-height",`${Ys}px`)}}),P&&Nne({element:P,padding:a}),Vne({arrowWidth:E,arrowHeight:k}),f&&Fne({strategy:"referenceHidden",...M})]}),[H,X]=w3(B),te=qt(g);yi(()=>{K&&(te==null||te())},[K,te]);const le=(Ne=R.arrow)==null?void 0:Ne.x,de=(lt=R.arrow)==null?void 0:lt.y,Me=(($e=R.arrow)==null?void 0:$e.centerOffset)!==0,[oe,Ue]=w.useState();return yi(()=>{y&&Ue(window.getComputedStyle(y).zIndex)},[y]),d.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...F,transform:K?F.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:oe,"--radix-popper-transform-origin":[(Ye=R.transformOrigin)==null?void 0:Ye.x,(We=R.transformOrigin)==null?void 0:We.y].join(" "),...((er=R.hide)==null?void 0:er.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(Hne,{scope:n,placedSide:H,onArrowChange:C,arrowX:le,arrowY:de,shouldHideArrow:Me,children:d.jsx(Ae.div,{"data-side":H,"data-align":X,...m,ref:b,style:{...m.style,animation:K?void 0:"none"}})})})});S3.displayName=Wb;var v3="PopperArrow",Wne={top:"bottom",right:"left",bottom:"top",left:"right"},x3=w.forwardRef(function(e,n){const{__scopePopper:r,...s}=e,o=Kne(v3,r),i=Wne[o.placedSide];return d.jsx("span",{ref:o.onArrowChange,style:{position:"absolute",left:o.arrowX,top:o.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[o.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[o.placedSide],visibility:o.shouldHideArrow?"hidden":void 0},children:d.jsx(Bne,{...s,ref:n,style:{...s.style,display:"block"}})})});x3.displayName=v3;function Gne(t){return t!==null}var Vne=t=>({name:"transformOrigin",options:t,fn(e){var v,y,S;const{placement:n,rects:r,middlewareData:s}=e,i=((v=s.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:t.arrowWidth,l=i?0:t.arrowHeight,[c,u]=w3(n),h={start:"0%",center:"50%",end:"100%"}[u],f=(((y=s.arrow)==null?void 0:y.x)??0)+a/2,p=(((S=s.arrow)==null?void 0:S.y)??0)+l/2;let g="",m="";return c==="bottom"?(g=i?h:`${f}px`,m=`${-l}px`):c==="top"?(g=i?h:`${f}px`,m=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,m=i?h:`${p}px`):c==="left"&&(g=`${r.floating.width+l}px`,m=i?h:`${p}px`),{data:{x:g,y:m}}}});function w3(t){const[e,n="center"]=t.split("-");return[e,n]}var Gb=g3,Vb=y3,b3=S3,P3=x3,Yne="Portal",bd=w.forwardRef((t,e)=>{var a;const{container:n,...r}=t,[s,o]=w.useState(!1);yi(()=>o(!0),[]);const i=n||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?c8.createPortal(d.jsx(Ae.div,{...r,ref:e}),i):null});bd.displayName=Yne;function Xne(t,e){return w.useReducer((n,r)=>e[n][r]??n,t)}var ds=t=>{const{present:e,children:n}=t,r=qne(e),s=typeof n=="function"?n({present:r.isPresent}):w.Children.only(n),o=Qe(r.ref,Zne(s));return typeof n=="function"||r.isPresent?w.cloneElement(s,{ref:o}):null};ds.displayName="Presence";function qne(t){const[e,n]=w.useState(),r=w.useRef({}),s=w.useRef(t),o=w.useRef("none"),i=t?"mounted":"unmounted",[a,l]=Xne(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=bh(r.current);o.current=a==="mounted"?c:"none"},[a]),yi(()=>{const c=r.current,u=s.current;if(u!==t){const f=o.current,p=bh(c);t?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&f!==p?"ANIMATION_OUT":"UNMOUNT"),s.current=t}},[t,l]),yi(()=>{if(e){let c;const u=e.ownerDocument.defaultView??window,h=p=>{const m=bh(r.current).includes(p.animationName);if(p.target===e&&m&&(l("ANIMATION_END"),!s.current)){const v=e.style.animationFillMode;e.style.animationFillMode="forwards",c=u.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=v)})}},f=p=>{p.target===e&&(o.current=bh(r.current))};return e.addEventListener("animationstart",f),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{u.clearTimeout(c),e.removeEventListener("animationstart",f),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 bh(t){return(t==null?void 0:t.animationName)||"none"}function Zne(t){var r,s;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=(s=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:s.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}function ji({prop:t,defaultProp:e,onChange:n=()=>{}}){const[r,s]=Qne({defaultProp:e,onChange:n}),o=t!==void 0,i=o?t:r,a=qt(n),l=w.useCallback(c=>{if(o){const h=typeof c=="function"?c(t):c;h!==t&&a(h)}else s(c)},[o,t,s,a]);return[i,l]}function Qne({defaultProp:t,onChange:e}){const n=w.useState(t),[r]=n,s=w.useRef(r),o=qt(e);return w.useEffect(()=>{s.current!==r&&(o(r),s.current=r)},[r,s,o]),n}var iS="rovingFocusGroup.onEntryFocus",Jne={bubbles:!1,cancelable:!0},rm="RovingFocusGroup",[Fx,C3,ere]=Zg(rm),[tre,_3]=Ws(rm,[ere]),[nre,rre]=tre(rm),I3=w.forwardRef((t,e)=>d.jsx(Fx.Provider,{scope:t.__scopeRovingFocusGroup,children:d.jsx(Fx.Slot,{scope:t.__scopeRovingFocusGroup,children:d.jsx(sre,{...t,ref:e})})}));I3.displayName=rm;var sre=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:s=!1,dir:o,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=t,f=w.useRef(null),p=Qe(e,f),g=Rb(o),[m=null,v]=ji({prop:i,defaultProp:a,onChange:l}),[y,S]=w.useState(!1),b=qt(c),P=C3(n),C=w.useRef(!1),[_,E]=w.useState(0);return w.useEffect(()=>{const k=f.current;if(k)return k.addEventListener(iS,b),()=>k.removeEventListener(iS,b)},[b]),d.jsx(nre,{scope:n,orientation:r,dir:g,loop:s,currentTabStopId:m,onItemFocus:w.useCallback(k=>v(k),[v]),onItemShiftTab:w.useCallback(()=>S(!0),[]),onFocusableItemAdd:w.useCallback(()=>E(k=>k+1),[]),onFocusableItemRemove:w.useCallback(()=>E(k=>k-1),[]),children:d.jsx(Ae.div,{tabIndex:y||_===0?-1:0,"data-orientation":r,...h,ref:p,style:{outline:"none",...t.style},onMouseDown:se(t.onMouseDown,()=>{C.current=!0}),onFocus:se(t.onFocus,k=>{const D=!C.current;if(k.target===k.currentTarget&&D&&!y){const T=new CustomEvent(iS,Jne);if(k.currentTarget.dispatchEvent(T),!T.defaultPrevented){const j=P().filter(B=>B.focusable),L=j.find(B=>B.active),M=j.find(B=>B.id===m),F=[L,M,...j].filter(Boolean).map(B=>B.ref.current);T3(F,u)}}C.current=!1}),onBlur:se(t.onBlur,()=>S(!1))})})}),E3="RovingFocusGroupItem",k3=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:s=!1,tabStopId:o,...i}=t,a=mo(),l=o||a,c=rre(E3,n),u=c.currentTabStopId===l,h=C3(n),{onFocusableItemAdd:f,onFocusableItemRemove:p}=c;return w.useEffect(()=>{if(r)return f(),()=>p()},[r,f,p]),d.jsx(Fx.ItemSlot,{scope:n,id:l,focusable:r,active:s,children:d.jsx(Ae.span,{tabIndex:u?0:-1,"data-orientation":c.orientation,...i,ref:e,onMouseDown:se(t.onMouseDown,g=>{r?c.onItemFocus(l):g.preventDefault()}),onFocus:se(t.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(t.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){c.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const m=are(g,c.orientation,c.dir);if(m!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let y=h().filter(S=>S.focusable).map(S=>S.ref.current);if(m==="last")y.reverse();else if(m==="prev"||m==="next"){m==="prev"&&y.reverse();const S=y.indexOf(g.currentTarget);y=c.loop?lre(y,S+1):y.slice(S+1)}setTimeout(()=>T3(y))}})})})});k3.displayName=E3;var ore={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ire(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function are(t,e,n){const r=ire(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ore[r]}function T3(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function lre(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var cre=I3,ure=k3,dre=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},$a=new WeakMap,Ph=new WeakMap,Ch={},aS=0,M3=function(t){return t&&(t.host||M3(t.parentNode))},hre=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=M3(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})},fre=function(t,e,n,r){var s=hre(e,Array.isArray(t)?t:[t]);Ch[n]||(Ch[n]=new WeakMap);var o=Ch[n],i=[],a=new Set,l=new Set(s),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};s.forEach(c);var u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(f){if(a.has(f))u(f);else try{var p=f.getAttribute(r),g=p!==null&&p!=="false",m=($a.get(f)||0)+1,v=(o.get(f)||0)+1;$a.set(f,m),o.set(f,v),i.push(f),m===1&&g&&Ph.set(f,!0),v===1&&f.setAttribute(n,"true"),g||f.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",f,y)}})};return u(e),a.clear(),aS++,function(){i.forEach(function(h){var f=$a.get(h)-1,p=o.get(h)-1;$a.set(h,f),o.set(h,p),f||(Ph.has(h)||h.removeAttribute(r),Ph.delete(h)),p||h.removeAttribute(n)}),aS--,aS||($a=new WeakMap,$a=new WeakMap,Ph=new WeakMap,Ch={})}},Yb=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),s=dre(t);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),fre(r,s,n,"aria-hidden")):function(){return null}},Cs=function(){return Cs=Object.assign||function(e){for(var n,r=1,s=arguments.length;r<s;r++){n=arguments[r];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Cs.apply(this,arguments)};function A3(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 s=0,r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(n[r[s]]=t[r[s]]);return n}function pre(t,e,n){if(n||arguments.length===2)for(var r=0,s=e.length,o;r<s;r++)(o||!(r in e))&&(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}var pf="right-scroll-bar-position",gf="width-before-scroll-bar",gre="with-scroll-bars-hidden",mre="--removed-body-scroll-bar-size";function lS(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function yre(t,e){var n=w.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var s=n.value;s!==r&&(n.value=r,n.callback(r,s))}}}})[0];return n.callback=e,n.facade}var Sre=typeof window<"u"?w.useLayoutEffect:w.useEffect,rE=new WeakMap;function vre(t,e){var n=yre(null,function(r){return t.forEach(function(s){return lS(s,r)})});return Sre(function(){var r=rE.get(n);if(r){var s=new Set(r),o=new Set(t),i=n.current;s.forEach(function(a){o.has(a)||lS(a,null)}),o.forEach(function(a){s.has(a)||lS(a,i)})}rE.set(n,t)},[t]),n}function xre(t){return t}function wre(t,e){e===void 0&&(e=xre);var n=[],r=!1,s={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(o){var i=e(o,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(o){for(r=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(a){return o(a)},filter:function(){return n}}},assignMedium:function(o){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(o),i=n}var l=function(){var u=i;i=[],u.forEach(o)},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 s}function bre(t){t===void 0&&(t={});var e=wre(null);return e.options=Cs({async:!0,ssr:!1},t),e}var j3=function(t){var e=t.sideCar,n=A3(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,Cs({},n))};j3.isSideCarExport=!0;function Pre(t,e){return t.useMedium(e),j3}var O3=bre(),cS=function(){},sm=w.forwardRef(function(t,e){var n=w.useRef(null),r=w.useState({onScrollCapture:cS,onWheelCapture:cS,onTouchMoveCapture:cS}),s=r[0],o=r[1],i=t.forwardProps,a=t.children,l=t.className,c=t.removeScrollBar,u=t.enabled,h=t.shards,f=t.sideCar,p=t.noIsolation,g=t.inert,m=t.allowPinchZoom,v=t.as,y=v===void 0?"div":v,S=t.gapMode,b=A3(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),P=f,C=vre([n,e]),_=Cs(Cs({},b),s);return w.createElement(w.Fragment,null,u&&w.createElement(P,{sideCar:O3,removeScrollBar:c,shards:h,noIsolation:p,inert:g,setCallbacks:o,allowPinchZoom:!!m,lockRef:n,gapMode:S}),i?w.cloneElement(w.Children.only(a),Cs(Cs({},_),{ref:C})):w.createElement(y,Cs({},_,{className:l,ref:C}),a))});sm.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};sm.classNames={fullWidth:gf,zeroRight:pf};var Cre=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function _re(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=Cre();return e&&t.setAttribute("nonce",e),t}function Ire(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function Ere(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var kre=function(){var t=0,e=null;return{add:function(n){t==0&&(e=_re())&&(Ire(e,n),Ere(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Tre=function(){var t=kre();return function(e,n){w.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},D3=function(){var t=Tre(),e=function(n){var r=n.styles,s=n.dynamic;return t(r,s),null};return e},Mre={left:0,top:0,right:0,gap:0},uS=function(t){return parseInt(t||"",10)||0},Are=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],s=e[t==="padding"?"paddingRight":"marginRight"];return[uS(n),uS(r),uS(s)]},jre=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return Mre;var e=Are(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])}},Ore=D3(),Pl="data-scroll-locked",Dre=function(t,e,n,r){var s=t.left,o=t.top,i=t.right,a=t.gap;return n===void 0&&(n="margin"),`
|
|
196
|
+
.`.concat(gre,` {
|
|
197
|
+
overflow: hidden `).concat(r,`;
|
|
198
|
+
padding-right: `).concat(a,"px ").concat(r,`;
|
|
199
|
+
}
|
|
200
|
+
body[`).concat(Pl,`] {
|
|
201
|
+
overflow: hidden `).concat(r,`;
|
|
202
|
+
overscroll-behavior: contain;
|
|
203
|
+
`).concat([e&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
204
|
+
padding-left: `.concat(s,`px;
|
|
205
|
+
padding-top: `).concat(o,`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(pf,` {
|
|
214
|
+
right: `).concat(a,"px ").concat(r,`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.`).concat(gf,` {
|
|
218
|
+
margin-right: `).concat(a,"px ").concat(r,`;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.`).concat(pf," .").concat(pf,` {
|
|
222
|
+
right: 0 `).concat(r,`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.`).concat(gf," .").concat(gf,` {
|
|
226
|
+
margin-right: 0 `).concat(r,`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
body[`).concat(Pl,`] {
|
|
230
|
+
`).concat(mre,": ").concat(a,`px;
|
|
231
|
+
}
|
|
232
|
+
`)},sE=function(){var t=parseInt(document.body.getAttribute(Pl)||"0",10);return isFinite(t)?t:0},Rre=function(){w.useEffect(function(){return document.body.setAttribute(Pl,(sE()+1).toString()),function(){var t=sE()-1;t<=0?document.body.removeAttribute(Pl):document.body.setAttribute(Pl,t.toString())}},[])},Lre=function(t){var e=t.noRelative,n=t.noImportant,r=t.gapMode,s=r===void 0?"margin":r;Rre();var o=w.useMemo(function(){return jre(s)},[s]);return w.createElement(Ore,{styles:Dre(o,!e,s,n?"":"!important")})},Nx=!1;if(typeof window<"u")try{var _h=Object.defineProperty({},"passive",{get:function(){return Nx=!0,!0}});window.addEventListener("test",_h,_h),window.removeEventListener("test",_h,_h)}catch{Nx=!1}var Fa=Nx?{passive:!1}:!1,$re=function(t){return t.tagName==="TEXTAREA"},R3=function(t,e){if(!(t instanceof Element))return!1;var n=window.getComputedStyle(t);return n[e]!=="hidden"&&!(n.overflowY===n.overflowX&&!$re(t)&&n[e]==="visible")},Fre=function(t){return R3(t,"overflowY")},Nre=function(t){return R3(t,"overflowX")},oE=function(t,e){var n=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var s=L3(t,r);if(s){var o=$3(t,r),i=o[1],a=o[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},zre=function(t){var e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;return[e,n,r]},Bre=function(t){var e=t.scrollLeft,n=t.scrollWidth,r=t.clientWidth;return[e,n,r]},L3=function(t,e){return t==="v"?Fre(e):Nre(e)},$3=function(t,e){return t==="v"?zre(e):Bre(e)},Ure=function(t,e){return t==="h"&&e==="rtl"?-1:1},Hre=function(t,e,n,r,s){var o=Ure(t,window.getComputedStyle(e).direction),i=o*r,a=n.target,l=e.contains(a),c=!1,u=i>0,h=0,f=0;do{var p=$3(t,a),g=p[0],m=p[1],v=p[2],y=m-v-o*g;(g||y)&&L3(t,a)&&(h+=y,f+=g),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(e.contains(a)||e===a));return(u&&Math.abs(h)<1||!u&&Math.abs(f)<1)&&(c=!0),c},Ih=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},iE=function(t){return[t.deltaX,t.deltaY]},aE=function(t){return t&&"current"in t?t.current:t},Kre=function(t,e){return t[0]===e[0]&&t[1]===e[1]},Wre=function(t){return`
|
|
233
|
+
.block-interactivity-`.concat(t,` {pointer-events: none;}
|
|
234
|
+
.allow-interactivity-`).concat(t,` {pointer-events: all;}
|
|
235
|
+
`)},Gre=0,Na=[];function Vre(t){var e=w.useRef([]),n=w.useRef([0,0]),r=w.useRef(),s=w.useState(Gre++)[0],o=w.useState(D3)[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(s));var m=pre([t.lockRef.current],(t.shards||[]).map(aE),!0).filter(Boolean);return m.forEach(function(v){return v.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),m.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(s))})}}},[t.inert,t.lockRef.current,t.shards]);var a=w.useCallback(function(m,v){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var y=Ih(m),S=n.current,b="deltaX"in m?m.deltaX:S[0]-y[0],P="deltaY"in m?m.deltaY:S[1]-y[1],C,_=m.target,E=Math.abs(b)>Math.abs(P)?"h":"v";if("touches"in m&&E==="h"&&_.type==="range")return!1;var k=oE(E,_);if(!k)return!0;if(k?C=E:(C=E==="v"?"h":"v",k=oE(E,_)),!k)return!1;if(!r.current&&"changedTouches"in m&&(b||P)&&(r.current=C),!C)return!0;var D=r.current||C;return Hre(D,v,m,D==="h"?b:P)},[]),l=w.useCallback(function(m){var v=m;if(!(!Na.length||Na[Na.length-1]!==o)){var y="deltaY"in v?iE(v):Ih(v),S=e.current.filter(function(C){return C.name===v.type&&(C.target===v.target||v.target===C.shadowParent)&&Kre(C.delta,y)})[0];if(S&&S.should){v.cancelable&&v.preventDefault();return}if(!S){var b=(i.current.shards||[]).map(aE).filter(Boolean).filter(function(C){return C.contains(v.target)}),P=b.length>0?a(v,b[0]):!i.current.noIsolation;P&&v.cancelable&&v.preventDefault()}}},[]),c=w.useCallback(function(m,v,y,S){var b={name:m,delta:v,target:y,should:S,shadowParent:Yre(y)};e.current.push(b),setTimeout(function(){e.current=e.current.filter(function(P){return P!==b})},1)},[]),u=w.useCallback(function(m){n.current=Ih(m),r.current=void 0},[]),h=w.useCallback(function(m){c(m.type,iE(m),m.target,a(m,t.lockRef.current))},[]),f=w.useCallback(function(m){c(m.type,Ih(m),m.target,a(m,t.lockRef.current))},[]);w.useEffect(function(){return Na.push(o),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:f}),document.addEventListener("wheel",l,Fa),document.addEventListener("touchmove",l,Fa),document.addEventListener("touchstart",u,Fa),function(){Na=Na.filter(function(m){return m!==o}),document.removeEventListener("wheel",l,Fa),document.removeEventListener("touchmove",l,Fa),document.removeEventListener("touchstart",u,Fa)}},[]);var p=t.removeScrollBar,g=t.inert;return w.createElement(w.Fragment,null,g?w.createElement(o,{styles:Wre(s)}):null,p?w.createElement(Lre,{gapMode:t.gapMode}):null)}function Yre(t){for(var e=null;t!==null;)t instanceof ShadowRoot&&(e=t.host,t=t.host),t=t.parentNode;return e}const Xre=Pre(O3,Vre);var om=w.forwardRef(function(t,e){return w.createElement(sm,Cs({},t,{ref:e,sideCar:Xre}))});om.classNames=sm.classNames;var zx=["Enter"," "],qre=["ArrowDown","PageUp","Home"],F3=["ArrowUp","PageDown","End"],Zre=[...qre,...F3],Qre={ltr:[...zx,"ArrowRight"],rtl:[...zx,"ArrowLeft"]},Jre={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Pd="Menu",[Wu,ese,tse]=Zg(Pd),[Ia,im]=Ws(Pd,[tse,nm,_3]),Cd=nm(),N3=_3(),[z3,Oi]=Ia(Pd),[nse,_d]=Ia(Pd),B3=t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:s,onOpenChange:o,modal:i=!0}=t,a=Cd(e),[l,c]=w.useState(null),u=w.useRef(!1),h=qt(o),f=Rb(s);return w.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),d.jsx(Gb,{...a,children:d.jsx(z3,{scope:e,open:n,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(nse,{scope:e,onClose:w.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:f,modal:i,children:r})})})};B3.displayName=Pd;var rse="MenuAnchor",Xb=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,s=Cd(n);return d.jsx(Vb,{...s,...r,ref:e})});Xb.displayName=rse;var qb="MenuPortal",[sse,U3]=Ia(qb,{forceMount:void 0}),H3=t=>{const{__scopeMenu:e,forceMount:n,children:r,container:s}=t,o=Oi(qb,e);return d.jsx(sse,{scope:e,forceMount:n,children:d.jsx(ds,{present:n||o.open,children:d.jsx(bd,{asChild:!0,container:s,children:r})})})};H3.displayName=qb;var Dr="MenuContent",[ose,Zb]=Ia(Dr),K3=w.forwardRef((t,e)=>{const n=U3(Dr,t.__scopeMenu),{forceMount:r=n.forceMount,...s}=t,o=Oi(Dr,t.__scopeMenu),i=_d(Dr,t.__scopeMenu);return d.jsx(Wu.Provider,{scope:t.__scopeMenu,children:d.jsx(ds,{present:r||o.open,children:d.jsx(Wu.Slot,{scope:t.__scopeMenu,children:i.modal?d.jsx(ise,{...s,ref:e}):d.jsx(ase,{...s,ref:e})})})})}),ise=w.forwardRef((t,e)=>{const n=Oi(Dr,t.__scopeMenu),r=w.useRef(null),s=Qe(e,r);return w.useEffect(()=>{const o=r.current;if(o)return Yb(o)},[]),d.jsx(Qb,{...t,ref:s,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:se(t.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),ase=w.forwardRef((t,e)=>{const n=Oi(Dr,t.__scopeMenu);return d.jsx(Qb,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Qb=w.forwardRef((t,e)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:s,onOpenAutoFocus:o,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:f,onDismiss:p,disableOutsideScroll:g,...m}=t,v=Oi(Dr,n),y=_d(Dr,n),S=Cd(n),b=N3(n),P=ese(n),[C,_]=w.useState(null),E=w.useRef(null),k=Qe(e,E,v.onContentChange),D=w.useRef(0),T=w.useRef(""),j=w.useRef(0),L=w.useRef(null),M=w.useRef("right"),O=w.useRef(0),F=g?om:w.Fragment,B=g?{as:fa,allowPinchZoom:!0}:void 0,K=H=>{var Ne,lt;const X=T.current+H,te=P().filter($e=>!$e.disabled),le=document.activeElement,de=(Ne=te.find($e=>$e.ref.current===le))==null?void 0:Ne.textValue,Me=te.map($e=>$e.textValue),oe=vse(Me,X,de),Ue=(lt=te.find($e=>$e.textValue===oe))==null?void 0:lt.ref.current;(function $e(Ye){T.current=Ye,window.clearTimeout(D.current),Ye!==""&&(D.current=window.setTimeout(()=>$e(""),1e3))})(X),Ue&&setTimeout(()=>Ue.focus())};w.useEffect(()=>()=>window.clearTimeout(D.current),[]),Lb();const R=w.useCallback(H=>{var te,le;return M.current===((te=L.current)==null?void 0:te.side)&&wse(H,(le=L.current)==null?void 0:le.area)},[]);return d.jsx(ose,{scope:n,searchRef:T,onItemEnter:w.useCallback(H=>{R(H)&&H.preventDefault()},[R]),onItemLeave:w.useCallback(H=>{var X;R(H)||((X=E.current)==null||X.focus(),_(null))},[R]),onTriggerLeave:w.useCallback(H=>{R(H)&&H.preventDefault()},[R]),pointerGraceTimerRef:j,onPointerGraceIntentChange:w.useCallback(H=>{L.current=H},[]),children:d.jsx(F,{...B,children:d.jsx(Qg,{asChild:!0,trapped:s,onMountAutoFocus:se(o,H=>{var X;H.preventDefault(),(X=E.current)==null||X.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(xd,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:f,onDismiss:p,children:d.jsx(cre,{asChild:!0,...b,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:_,onEntryFocus:se(l,H=>{y.isUsingKeyboardRef.current||H.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(b3,{role:"menu","aria-orientation":"vertical","data-state":aL(v.open),"data-radix-menu-content":"",dir:y.dir,...S,...m,ref:k,style:{outline:"none",...m.style},onKeyDown:se(m.onKeyDown,H=>{const te=H.target.closest("[data-radix-menu-content]")===H.currentTarget,le=H.ctrlKey||H.altKey||H.metaKey,de=H.key.length===1;te&&(H.key==="Tab"&&H.preventDefault(),!le&&de&&K(H.key));const Me=E.current;if(H.target!==Me||!Zre.includes(H.key))return;H.preventDefault();const Ue=P().filter(Ne=>!Ne.disabled).map(Ne=>Ne.ref.current);F3.includes(H.key)&&Ue.reverse(),yse(Ue)}),onBlur:se(t.onBlur,H=>{H.currentTarget.contains(H.target)||(window.clearTimeout(D.current),T.current="")}),onPointerMove:se(t.onPointerMove,Gu(H=>{const X=H.target,te=O.current!==H.clientX;if(H.currentTarget.contains(X)&&te){const le=H.clientX>O.current?"right":"left";M.current=le,O.current=H.clientX}}))})})})})})})});K3.displayName=Dr;var lse="MenuGroup",Jb=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"group",...r,ref:e})});Jb.displayName=lse;var cse="MenuLabel",W3=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});W3.displayName=cse;var Bp="MenuItem",lE="menu.itemSelect",am=w.forwardRef((t,e)=>{const{disabled:n=!1,onSelect:r,...s}=t,o=w.useRef(null),i=_d(Bp,t.__scopeMenu),a=Zb(Bp,t.__scopeMenu),l=Qe(e,o),c=w.useRef(!1),u=()=>{const h=o.current;if(!n&&h){const f=new CustomEvent(lE,{bubbles:!0,cancelable:!0});h.addEventListener(lE,p=>r==null?void 0:r(p),{once:!0}),Db(h,f),f.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(G3,{...s,ref:l,disabled:n,onClick:se(t.onClick,u),onPointerDown:h=>{var f;(f=t.onPointerDown)==null||f.call(t,h),c.current=!0},onPointerUp:se(t.onPointerUp,h=>{var f;c.current||(f=h.currentTarget)==null||f.click()}),onKeyDown:se(t.onKeyDown,h=>{const f=a.searchRef.current!=="";n||f&&h.key===" "||zx.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});am.displayName=Bp;var G3=w.forwardRef((t,e)=>{const{__scopeMenu:n,disabled:r=!1,textValue:s,...o}=t,i=Zb(Bp,n),a=N3(n),l=w.useRef(null),c=Qe(e,l),[u,h]=w.useState(!1),[f,p]=w.useState("");return w.useEffect(()=>{const g=l.current;g&&p((g.textContent??"").trim())},[o.children]),d.jsx(Wu.ItemSlot,{scope:n,disabled:r,textValue:s??f,children:d.jsx(ure,{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,...o,ref:c,onPointerMove:se(t.onPointerMove,Gu(g=>{r?i.onItemLeave(g):(i.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:se(t.onPointerLeave,Gu(g=>i.onItemLeave(g))),onFocus:se(t.onFocus,()=>h(!0)),onBlur:se(t.onBlur,()=>h(!1))})})})}),use="MenuCheckboxItem",V3=w.forwardRef((t,e)=>{const{checked:n=!1,onCheckedChange:r,...s}=t;return d.jsx(Q3,{scope:t.__scopeMenu,checked:n,children:d.jsx(am,{role:"menuitemcheckbox","aria-checked":Up(n)?"mixed":n,...s,ref:e,"data-state":n1(n),onSelect:se(s.onSelect,()=>r==null?void 0:r(Up(n)?!0:!n),{checkForDefaultPrevented:!1})})})});V3.displayName=use;var Y3="MenuRadioGroup",[dse,hse]=Ia(Y3,{value:void 0,onValueChange:()=>{}}),X3=w.forwardRef((t,e)=>{const{value:n,onValueChange:r,...s}=t,o=qt(r);return d.jsx(dse,{scope:t.__scopeMenu,value:n,onValueChange:o,children:d.jsx(Jb,{...s,ref:e})})});X3.displayName=Y3;var q3="MenuRadioItem",Z3=w.forwardRef((t,e)=>{const{value:n,...r}=t,s=hse(q3,t.__scopeMenu),o=n===s.value;return d.jsx(Q3,{scope:t.__scopeMenu,checked:o,children:d.jsx(am,{role:"menuitemradio","aria-checked":o,...r,ref:e,"data-state":n1(o),onSelect:se(r.onSelect,()=>{var i;return(i=s.onValueChange)==null?void 0:i.call(s,n)},{checkForDefaultPrevented:!1})})})});Z3.displayName=q3;var e1="MenuItemIndicator",[Q3,fse]=Ia(e1,{checked:!1}),J3=w.forwardRef((t,e)=>{const{__scopeMenu:n,forceMount:r,...s}=t,o=fse(e1,n);return d.jsx(ds,{present:r||Up(o.checked)||o.checked===!0,children:d.jsx(Ae.span,{...s,ref:e,"data-state":n1(o.checked)})})});J3.displayName=e1;var pse="MenuSeparator",eL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t;return d.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:e})});eL.displayName=pse;var gse="MenuArrow",tL=w.forwardRef((t,e)=>{const{__scopeMenu:n,...r}=t,s=Cd(n);return d.jsx(P3,{...s,...r,ref:e})});tL.displayName=gse;var t1="MenuSub",[mse,nL]=Ia(t1),rL=t=>{const{__scopeMenu:e,children:n,open:r=!1,onOpenChange:s}=t,o=Oi(t1,e),i=Cd(e),[a,l]=w.useState(null),[c,u]=w.useState(null),h=qt(s);return w.useEffect(()=>(o.open===!1&&h(!1),()=>h(!1)),[o.open,h]),d.jsx(Gb,{...i,children:d.jsx(z3,{scope:e,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(mse,{scope:e,contentId:mo(),triggerId:mo(),trigger:a,onTriggerChange:l,children:n})})})};rL.displayName=t1;var Vc="MenuSubTrigger",sL=w.forwardRef((t,e)=>{const n=Oi(Vc,t.__scopeMenu),r=_d(Vc,t.__scopeMenu),s=nL(Vc,t.__scopeMenu),o=Zb(Vc,t.__scopeMenu),i=w.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=o,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(Xb,{asChild:!0,...c,children:d.jsx(G3,{id:s.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":s.contentId,"data-state":aL(n.open),...t,ref:qg(e,s.onTriggerChange),onClick:h=>{var f;(f=t.onClick)==null||f.call(t,h),!(t.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:se(t.onPointerMove,Gu(h=>{o.onItemEnter(h),!h.defaultPrevented&&!t.disabled&&!n.open&&!i.current&&(o.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:se(t.onPointerLeave,Gu(h=>{var p,g;u();const f=(p=n.content)==null?void 0:p.getBoundingClientRect();if(f){const m=(g=n.content)==null?void 0:g.dataset.side,v=m==="right",y=v?-5:5,S=f[v?"left":"right"],b=f[v?"right":"left"];o.onPointerGraceIntentChange({area:[{x:h.clientX+y,y:h.clientY},{x:S,y:f.top},{x:b,y:f.top},{x:b,y:f.bottom},{x:S,y:f.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>o.onPointerGraceIntentChange(null),300)}else{if(o.onTriggerLeave(h),h.defaultPrevented)return;o.onPointerGraceIntentChange(null)}})),onKeyDown:se(t.onKeyDown,h=>{var p;const f=o.searchRef.current!=="";t.disabled||f&&h.key===" "||Qre[r.dir].includes(h.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),h.preventDefault())})})})});sL.displayName=Vc;var oL="MenuSubContent",iL=w.forwardRef((t,e)=>{const n=U3(Dr,t.__scopeMenu),{forceMount:r=n.forceMount,...s}=t,o=Oi(Dr,t.__scopeMenu),i=_d(Dr,t.__scopeMenu),a=nL(oL,t.__scopeMenu),l=w.useRef(null),c=Qe(e,l);return d.jsx(Wu.Provider,{scope:t.__scopeMenu,children:d.jsx(ds,{present:r||o.open,children:d.jsx(Wu.Slot,{scope:t.__scopeMenu,children:d.jsx(Qb,{id:a.contentId,"aria-labelledby":a.triggerId,...s,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:se(t.onFocusOutside,u=>{u.target!==a.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:se(t.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:se(t.onKeyDown,u=>{var p;const h=u.currentTarget.contains(u.target),f=Jre[i.dir].includes(u.key);h&&f&&(o.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});iL.displayName=oL;function aL(t){return t?"open":"closed"}function Up(t){return t==="indeterminate"}function n1(t){return Up(t)?"indeterminate":t?"checked":"unchecked"}function yse(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}function Sse(t,e){return t.map((n,r)=>t[(e+r)%t.length])}function vse(t,e,n){const s=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,o=n?t.indexOf(n):-1;let i=Sse(t,Math.max(o,0));s.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(s.toLowerCase()));return l!==n?l:void 0}function xse(t,e){const{x:n,y:r}=t;let s=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const a=e[o].x,l=e[o].y,c=e[i].x,u=e[i].y;l>r!=u>r&&n<(c-a)*(r-l)/(u-l)+a&&(s=!s)}return s}function wse(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return xse(n,e)}function Gu(t){return e=>e.pointerType==="mouse"?t(e):void 0}var lL=B3,cL=Xb,uL=H3,dL=K3,hL=Jb,fL=W3,pL=am,gL=V3,mL=X3,yL=Z3,SL=J3,vL=eL,xL=tL,wL=rL,bL=sL,PL=iL,r1="ContextMenu",[bse,age]=Ws(r1,[im]),yn=im(),[Pse,CL]=bse(r1),_L=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,dir:s,modal:o=!0}=t,[i,a]=w.useState(!1),l=yn(e),c=qt(r),u=w.useCallback(h=>{a(h),c(h)},[c]);return d.jsx(Pse,{scope:e,open:i,onOpenChange:u,modal:o,children:d.jsx(lL,{...l,dir:s,open:i,onOpenChange:u,modal:o,children:n})})};_L.displayName=r1;var IL="ContextMenuTrigger",EL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,disabled:r=!1,...s}=t,o=CL(IL,n),i=yn(n),a=w.useRef({x:0,y:0}),l=w.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=w.useRef(0),u=w.useCallback(()=>window.clearTimeout(c.current),[]),h=f=>{a.current={x:f.clientX,y:f.clientY},o.onOpenChange(!0)};return w.useEffect(()=>u,[u]),w.useEffect(()=>void(r&&u()),[r,u]),d.jsxs(d.Fragment,{children:[d.jsx(cL,{...i,virtualRef:l}),d.jsx(Ae.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...s,ref:e,style:{WebkitTouchCallout:"none",...t.style},onContextMenu:r?t.onContextMenu:se(t.onContextMenu,f=>{u(),h(f),f.preventDefault()}),onPointerDown:r?t.onPointerDown:se(t.onPointerDown,Eh(f=>{u(),c.current=window.setTimeout(()=>h(f),700)})),onPointerMove:r?t.onPointerMove:se(t.onPointerMove,Eh(u)),onPointerCancel:r?t.onPointerCancel:se(t.onPointerCancel,Eh(u)),onPointerUp:r?t.onPointerUp:se(t.onPointerUp,Eh(u))})]})});EL.displayName=IL;var Cse="ContextMenuPortal",s1=t=>{const{__scopeContextMenu:e,...n}=t,r=yn(e);return d.jsx(uL,{...r,...n})};s1.displayName=Cse;var kL="ContextMenuContent",TL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=CL(kL,n),o=yn(n),i=w.useRef(!1);return d.jsx(dL,{...o,...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&&!s.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)"}})});TL.displayName=kL;var _se="ContextMenuGroup",ML=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(hL,{...s,...r,ref:e})});ML.displayName=_se;var Ise="ContextMenuLabel",Ese=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(fL,{...s,...r,ref:e})});Ese.displayName=Ise;var kse="ContextMenuItem",AL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(pL,{...s,...r,ref:e})});AL.displayName=kse;var Tse="ContextMenuCheckboxItem",jL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(gL,{...s,...r,ref:e})});jL.displayName=Tse;var Mse="ContextMenuRadioGroup",Ase=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(mL,{...s,...r,ref:e})});Ase.displayName=Mse;var jse="ContextMenuRadioItem",Ose=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(yL,{...s,...r,ref:e})});Ose.displayName=jse;var Dse="ContextMenuItemIndicator",Rse=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(SL,{...s,...r,ref:e})});Rse.displayName=Dse;var Lse="ContextMenuSeparator",$se=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(vL,{...s,...r,ref:e})});$se.displayName=Lse;var Fse="ContextMenuArrow",Nse=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(xL,{...s,...r,ref:e})});Nse.displayName=Fse;var zse="ContextMenuSub",OL=t=>{const{__scopeContextMenu:e,children:n,onOpenChange:r,open:s,defaultOpen:o}=t,i=yn(e),[a,l]=ji({prop:s,defaultProp:o,onChange:r});return d.jsx(wL,{...i,open:a,onOpenChange:l,children:n})};OL.displayName=zse;var Bse="ContextMenuSubTrigger",DL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(bL,{...s,...r,ref:e})});DL.displayName=Bse;var Use="ContextMenuSubContent",RL=w.forwardRef((t,e)=>{const{__scopeContextMenu:n,...r}=t,s=yn(n);return d.jsx(PL,{...s,...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)"}})});RL.displayName=Use;function Eh(t){return e=>e.pointerType!=="mouse"?t(e):void 0}var Hse=_L,Kse=EL,Wse=s1,Gse=TL,Vse=jL,o1="DropdownMenu",[Yse,lge]=Ws(o1,[im]),Sn=im(),[Xse,LL]=Yse(o1),$L=t=>{const{__scopeDropdownMenu:e,children:n,dir:r,open:s,defaultOpen:o,onOpenChange:i,modal:a=!0}=t,l=Sn(e),c=w.useRef(null),[u=!1,h]=ji({prop:s,defaultProp:o,onChange:i});return d.jsx(Xse,{scope:e,triggerId:mo(),triggerRef:c,contentId:mo(),open:u,onOpenChange:h,onOpenToggle:w.useCallback(()=>h(f=>!f),[h]),modal:a,children:d.jsx(lL,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:n})})};$L.displayName=o1;var FL="DropdownMenuTrigger",NL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...s}=t,o=LL(FL,n),i=Sn(n);return d.jsx(cL,{asChild:!0,...i,children:d.jsx(Ae.button,{type:"button",id:o.triggerId,"aria-haspopup":"menu","aria-expanded":o.open,"aria-controls":o.open?o.contentId:void 0,"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...s,ref:qg(e,o.triggerRef),onPointerDown:se(t.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(o.onOpenToggle(),o.open||a.preventDefault())}),onKeyDown:se(t.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&o.onOpenToggle(),a.key==="ArrowDown"&&o.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});NL.displayName=FL;var qse="DropdownMenuPortal",zL=t=>{const{__scopeDropdownMenu:e,...n}=t,r=Sn(e);return d.jsx(uL,{...r,...n})};zL.displayName=qse;var BL="DropdownMenuContent",UL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=LL(BL,n),o=Sn(n),i=w.useRef(!1);return d.jsx(dL,{id:s.contentId,"aria-labelledby":s.triggerId,...o,...r,ref:e,onCloseAutoFocus:se(t.onCloseAutoFocus,a=>{var l;i.current||(l=s.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:se(t.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!s.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)"}})});UL.displayName=BL;var Zse="DropdownMenuGroup",HL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(hL,{...s,...r,ref:e})});HL.displayName=Zse;var Qse="DropdownMenuLabel",Jse=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(fL,{...s,...r,ref:e})});Jse.displayName=Qse;var eoe="DropdownMenuItem",KL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(pL,{...s,...r,ref:e})});KL.displayName=eoe;var toe="DropdownMenuCheckboxItem",WL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(gL,{...s,...r,ref:e})});WL.displayName=toe;var noe="DropdownMenuRadioGroup",roe=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(mL,{...s,...r,ref:e})});roe.displayName=noe;var soe="DropdownMenuRadioItem",ooe=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(yL,{...s,...r,ref:e})});ooe.displayName=soe;var ioe="DropdownMenuItemIndicator",aoe=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(SL,{...s,...r,ref:e})});aoe.displayName=ioe;var loe="DropdownMenuSeparator",coe=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(vL,{...s,...r,ref:e})});coe.displayName=loe;var uoe="DropdownMenuArrow",doe=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(xL,{...s,...r,ref:e})});doe.displayName=uoe;var hoe=t=>{const{__scopeDropdownMenu:e,children:n,open:r,onOpenChange:s,defaultOpen:o}=t,i=Sn(e),[a=!1,l]=ji({prop:r,defaultProp:o,onChange:s});return d.jsx(wL,{...i,open:a,onOpenChange:l,children:n})},foe="DropdownMenuSubTrigger",GL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(bL,{...s,...r,ref:e})});GL.displayName=foe;var poe="DropdownMenuSubContent",VL=w.forwardRef((t,e)=>{const{__scopeDropdownMenu:n,...r}=t,s=Sn(n);return d.jsx(PL,{...s,...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)"}})});VL.displayName=poe;var i1=$L,a1=NL,lm=zL,l1=UL,goe=HL,moe=KL,yoe=WL,Soe=hoe,voe=GL,xoe=VL;function Xe(t,e){var s;const n=new Set;for(const o of e){const i=t.getShape(o);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 o of n){const i=YL(t,o);i.length&&r.set(o,i)}for(const[o,i]of r){const a=t.getShapeUtil(o),l=me(i.map(c=>t.getShape(c)));(s=a.onDragShapesOut)==null||s.call(a,o,l)}}function YL(t,e){const n=t.getSortedChildIdsForParent(e.id);if(n.length===0)return[];const r=t.getShapePageBounds(e);if(!r)return[];let s,o,i;const a=[];for(const l of n){const c=t.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}s??(s=t.getShapeGeometry(e)),o??(o=t.getShapePageTransform(e)),i??(i=o.applyToPoints(s.vertices));const u=t.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:h,isClosed:f}=t.getShapeGeometry(l);if(!h.some(p=>hr(p,u))){if(f){if(bb(u,h))continue}else if(VZ(u,h))continue;a.push(l)}}return a}function Hp(t,e,n=!1){t.select(e),t.setEditingShape(e),t.setCurrentTool("select.editing_shape",{target:"shape",shape:e}),n&&t.emit("select-all-text",{shapeId:e.id})}function woe(t,e){const n=me(e.map(s=>t.getShape(s)).filter(s=>s&&t.isShapeOfType(s,"frame")));if(!n.length)return;const r=[];t.run(()=>{n.map(s=>{const o=t.getSortedChildIdsForParent(s.id);o.length&&(t.reparentShapes(o,s.parentId,s.index),r.push(...o))}),t.setSelectedShapes(r),t.deleteShapes(e)})}const boe=50;function Poe(t,e,n={}){const r=t.getShape(e);if(!r)return;const s=t.getSortedChildIdsForParent(r.id),o=me(s.map(p=>t.getShape(p)));if(!o.length)return;const i=Z.FromPoints(o.flatMap(p=>{const g=t.getShapeGeometry(p.id);return t.getShapeLocalTransform(p).applyToPoints(g.vertices)})),{padding:a=boe}=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 f=new x(u,h).rot(r.rotation);t.run(()=>{const p=s.map(g=>{const m=t.getShape(g);return{id:m.id,type:m.type,x:m.x+u,y:m.y+h}});p.push({id:r.id,type:r.type,x:r.x-f.x,y:r.y-f.y,props:{w:l,h:c}}),t.updateShapes(p)})}const XL=w.createContext(null);function Coe({assetUrls:t,children:e}){return w.useEffect(()=>{for(const n of Object.values(t.icons)){const r=Lu();r.src=n,r.decode()}for(const n of Object.values(t.embedIcons)){const r=Lu();r.src=n,r.decode()}},[t]),d.jsx(XL.Provider,{value:t,children:e})}function c1(){const t=w.useContext(XL);if(!t)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return t}const Bx={"action.convert-to-bookmark":"Convert to Bookmark","action.convert-to-embed":"Convert to Embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","action.export-as-json.short":"JSON","action.export-as-json":"Export as JSON","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-json.short":"JSON","action.export-all-as-json":"Export as JSON","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.fork-project-on-tldraw":"Fork project on tldraw","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.paste-error-title":"Pasting failed","action.paste-error-description":"Could not paste due to missing clipboard permissions. Please enable the permissions and try again.","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-paste-at-cursor.menu":"Paste at cursor","action.toggle-paste-at-cursor":"Toggle paste at cursor","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.size-too-big":"File size is too big","assets.files.type-not-allowed":"File type is not allowed","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","theme.dark":"Dark","theme.light":"Light","theme.system":"System","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","fill-style.fill":"Fill","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","tool.pointer-down":"Pointer down","menu.title":"Menu","menu.theme":"Theme","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.help":"Help","menu.view":"View","context-menu.edit":"Edit","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy editor link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","document-name-menu.copy-link":"Copy link","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.import-tldr-file":"Import file...","help-menu.title":"Help and resources","help-menu.about":"About tldraw","help-menu.docs":"Documentation & API","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","help-menu.terms":"Terms of service","help-menu.privacy":"Privacy policy","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.label-align":"Label align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},_oe=new Set(["ar","fa","he","ur","ku"]),za={locale:"en",label:"English",messages:Bx,dir:"ltr"};async function Ioe(t,e){if(!(await Rs(e.translations.en)).ok)return console.warn("No main translations found."),za;if(t==="en")return za;const r=zu.find(i=>i.locale===t);if(!r)return console.warn(`No translation found for locale ${t}`),za;const o=await(await Rs(e.translations[r.locale])).json();if(!o)return console.warn(`No messages found for locale ${t}`),za;for(const i in za.messages)o[i];return{locale:t,label:r.label,dir:_oe.has(r.locale)?"rtl":"ltr",messages:{...za.messages,...o}}}const qL=w.createContext(null);function ZL(){const t=w.useContext(qL);if(!t)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return t}function Eoe({overrides:t,locale:e,children:n}){const r=c1(),[s,o]=w.useState(()=>t&&t.en?{locale:"en",label:"English",dir:"ltr",messages:{...Bx,...t.en}}:{locale:"en",label:"English",dir:"ltr",messages:Bx});return w.useEffect(()=>{let i=!1;async function a(){const l=await Ioe(e,r);l&&!i&&(t&&t[e]?o({...l,messages:{...l.messages,...t[e]}}):o(l))}return a(),()=>{i=!0}},[r,e,t]),d.jsx(qL.Provider,{value:s,children:n})}function Ee(){const t=ZL();return w.useCallback(function(n){return t.messages[n]??n},[t])}const ue=w.forwardRef(function({children:e,type:n,...r},s){return d.jsx("button",{ref:s,type:"button",draggable:!1,...r,className:ce("tlui-button",`tlui-button__${n}`,r.className),children:e})});function bt({children:t}){return d.jsx("span",{className:"tlui-button__label",children:t})}var u1="Dialog",[QL,cge]=Ws(u1),[koe,hs]=QL(u1),JL=t=>{const{__scopeDialog:e,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:i=!0}=t,a=w.useRef(null),l=w.useRef(null),[c=!1,u]=ji({prop:r,defaultProp:s,onChange:o});return d.jsx(koe,{scope:e,triggerRef:a,contentRef:l,contentId:mo(),titleId:mo(),descriptionId:mo(),open:c,onOpenChange:u,onOpenToggle:w.useCallback(()=>u(h=>!h),[u]),modal:i,children:n})};JL.displayName=u1;var e$="DialogTrigger",Toe=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,s=hs(e$,n),o=Qe(e,s.triggerRef);return d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":f1(s.open),...r,ref:o,onClick:se(t.onClick,s.onOpenToggle)})});Toe.displayName=e$;var d1="DialogPortal",[Moe,t$]=QL(d1,{forceMount:void 0}),n$=t=>{const{__scopeDialog:e,forceMount:n,children:r,container:s}=t,o=hs(d1,e);return d.jsx(Moe,{scope:e,forceMount:n,children:w.Children.map(r,i=>d.jsx(ds,{present:n||o.open,children:d.jsx(bd,{asChild:!0,container:s,children:i})}))})};n$.displayName=d1;var Kp="DialogOverlay",r$=w.forwardRef((t,e)=>{const n=t$(Kp,t.__scopeDialog),{forceMount:r=n.forceMount,...s}=t,o=hs(Kp,t.__scopeDialog);return o.modal?d.jsx(ds,{present:r||o.open,children:d.jsx(Aoe,{...s,ref:e})}):null});r$.displayName=Kp;var Aoe=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,s=hs(Kp,n);return d.jsx(om,{as:fa,allowPinchZoom:!0,shards:[s.contentRef],children:d.jsx(Ae.div,{"data-state":f1(s.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),ga="DialogContent",s$=w.forwardRef((t,e)=>{const n=t$(ga,t.__scopeDialog),{forceMount:r=n.forceMount,...s}=t,o=hs(ga,t.__scopeDialog);return d.jsx(ds,{present:r||o.open,children:o.modal?d.jsx(joe,{...s,ref:e}):d.jsx(Ooe,{...s,ref:e})})});s$.displayName=ga;var joe=w.forwardRef((t,e)=>{const n=hs(ga,t.__scopeDialog),r=w.useRef(null),s=Qe(e,n.contentRef,r);return w.useEffect(()=>{const o=r.current;if(o)return Yb(o)},[]),d.jsx(o$,{...t,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(t.onCloseAutoFocus,o=>{var i;o.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:se(t.onPointerDownOutside,o=>{const i=o.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&o.preventDefault()}),onFocusOutside:se(t.onFocusOutside,o=>o.preventDefault())})}),Ooe=w.forwardRef((t,e)=>{const n=hs(ga,t.__scopeDialog),r=w.useRef(!1),s=w.useRef(!1);return d.jsx(o$,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=t.onCloseAutoFocus)==null||i.call(t,o),o.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=t.onInteractOutside)==null||l.call(t,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),o$=w.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,...i}=t,a=hs(ga,n),l=w.useRef(null),c=Qe(e,l);return Lb(),d.jsxs(d.Fragment,{children:[d.jsx(Qg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:d.jsx(xd,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":f1(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(Roe,{titleId:a.titleId}),d.jsx($oe,{contentRef:l,descriptionId:a.descriptionId})]})]})}),h1="DialogTitle",i$=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,s=hs(h1,n);return d.jsx(Ae.h2,{id:s.titleId,...r,ref:e})});i$.displayName=h1;var a$="DialogDescription",Doe=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,s=hs(a$,n);return d.jsx(Ae.p,{id:s.descriptionId,...r,ref:e})});Doe.displayName=a$;var l$="DialogClose",c$=w.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,s=hs(l$,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:se(t.onClick,()=>s.onOpenChange(!1))})});c$.displayName=l$;function f1(t){return t?"open":"closed"}var u$="DialogTitleWarning",[uge,d$]=yte(u$,{contentName:ga,titleName:h1,docsSlug:"dialog"}),Roe=({titleId:t})=>{const e=d$(u$),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},Loe="DialogDescriptionWarning",$oe=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${d$(Loe).contentName}}.`;return w.useEffect(()=>{var o;const s=(o=t.current)==null?void 0:o.getAttribute("aria-describedby");e&&s&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},Foe=JL,Noe=n$,zoe=r$,Boe=s$;const zs=w.memo(function({small:e,invertIcon:n,icon:r,color:s,className:o,...i}){const a=c1(),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:ce("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":e},o)}):d.jsx("div",{...i,ref:c,className:ce("tlui-icon",{"tlui-icon__small":e},o),style:{color:s,mask:`url(${l}) center 100% / 100% no-repeat`,transform:n?"scale(-1, 1)":void 0}})});function be({icon:t,small:e,invertIcon:n}){return d.jsx(zs,{className:"tlui-button__icon",icon:t,small:e,invertIcon:n})}function cm({className:t,children:e}){return d.jsx("div",{className:ce("tlui-dialog__header",t),children:e})}function um({className:t,children:e}){return d.jsx(i$,{dir:"ltr",className:ce("tlui-dialog__header__title",t),children:e})}function dm(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(c$,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon","aria-label":"Close",onTouchEnd:t=>t.target.click(),children:d.jsx(be,{small:!0,icon:"cross-2"})})})})}function Vu({className:t,children:e,style:n}){return d.jsx("div",{className:ce("tlui-dialog__body",t),style:n,children:e})}function p1({className:t,children:e}){return d.jsx("div",{className:ce("tlui-dialog__footer",t),children:e})}const hm=w.forwardRef(function({className:e,label:n,icon:r,iconLeft:s,autoSelect:o=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:f,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:g=!1,children:m,value:v},y){const S=Ti(),b=w.useRef(null);w.useImperativeHandle(y,()=>b.current);const P=Ee(),C=w.useRef(a??""),_=w.useRef(a??""),[E,k]=w.useState(!1),D=w.useCallback(M=>{k(!0);const O=M.currentTarget;_.current=O.value,S?S.timers.requestAnimationFrame(()=>{o&&O.select()}):Ex.requestAnimationFrame("anon",()=>{o&&O.select()}),f==null||f()},[o,S,f]),T=w.useCallback(M=>{const O=M.currentTarget.value;_.current=O,u==null||u(O)},[u]),j=w.useCallback(M=>{switch(M.key){case"Enter":{M.currentTarget.blur(),Ct(M),c==null||c(M.currentTarget.value);break}case"Escape":{M.currentTarget.value=C.current,h==null||h(M.currentTarget.value),M.currentTarget.blur(),Ct(M);break}}},[c,h]),L=w.useCallback(M=>{k(!1);const O=M.currentTarget.value;p==null||p(O)},[p]);return w.useEffect(()=>{if(!Ge.isIos)return;const M=window.visualViewport;if(E&&g&&M){const O=()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})};return M.addEventListener("resize",O),M.addEventListener("scroll",O),S?S.timers.requestAnimationFrame(()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}):Ex.requestAnimationFrame("anon",()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}),()=>{M.removeEventListener("resize",O),M.removeEventListener("scroll",O)}}},[E,S,g]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,n&&d.jsx("label",{children:P(n)}),s&&d.jsx(zs,{icon:s,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:ce("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:j,onChange:T,onFocus:D,onBlur:L,autoFocus:i,placeholder:l,value:v}),r&&d.jsx(zs,{icon:r,small:!!n})]})});function cE(t){return gr.isValid(t)?{isValid:!0,hasProtocol:!0}:gr.isValid("https://"+t)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Uoe=Zt(function({onClose:e}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(Hoe,{onClose:e,selectedShape:r}):null}),Hoe=Zt(function({onClose:e,selectedShape:n}){const r=z(),s=Ee(),o=w.useRef(null);w.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var g;return(g=o.current)==null?void 0:g.focus()})},[r]);const i=w.useRef(n.props.url),[a,l]=w.useState(()=>{const g=cE(n.props.url),m=g.isValid===!0?g.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:m,safe:m,valid:!0}}),c=w.useCallback(g=>{const m=g.replace(/https?:\/\/(https?:\/\/)/,(S,b)=>b),v=cE(m),y=v.isValid===!0?v.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:y,valid:v.isValid})},[]),u=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(r.updateShapes([{id:g.id,type:g.type,props:{url:""}}]),e())},[r,e]),h=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(g&&"url"in g.props&&g.props.url!==a.safe&&r.updateShapes([{id:g.id,type:g.type,props:{url:a.safe}}]),e())},[r,e,a]),f=w.useCallback(()=>{e()},[e]);if(!n)return e(),null;const p=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(cm,{children:[d.jsx(um,{children:s("edit-link-dialog.title")}),d.jsx(dm,{})]}),d.jsx(Vu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(hm,{ref:o,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:f}),d.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),d.jsxs(p1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:f,onTouchEnd:f,children:d.jsx(bt,{children:s("edit-link-dialog.cancel")})}),p?d.jsx(ue,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(bt,{children:s("edit-link-dialog.clear")})}):d.jsx(ue,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(bt,{children:s("edit-link-dialog.save")})})]})]})});var Koe={};const uE=/(^\/r\/[^/]+\/?$)/,g1=[{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(uE))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(uE))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/embed?"))return t;if(t.includes("/maps/")){const e=t.match(/@(.*?),(.*?),(.*?)z/);let n;if(e){const[,r,s,o]=e;n=`https://${new URL(t).host.replace("www.","")}/maps/embed/v1/view?key=${Koe.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${s}&zoom=${o}`}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"),[s,o]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${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,s,o]=n;return`https://codepen.io/${s}/embed/${o}`}},fromEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/pen/${o}`}}},{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,s]=n;return`https://scratch.mit.edu/projects/embed/${s}`}},fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/${s}`}}},{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 s of r)e.searchParams.delete(s);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 s of r)e.searchParams.delete(s);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(/\/([^/]+)\/([0-9a-f]+)$/))return t.split("/").pop()?t:void 0},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))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","")}}],Woe={"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},Goe=g1.map(t=>t.type);function Voe(t){return Goe.includes(t)}function Yoe(t){return"icon"in t}function h$(){return z().getShapeUtil("embed")}function m1(){const t=h$();return e=>t?t.getEmbedDefinition(e):void 0}function Xoe(){const t=h$();return t?t.getEmbedDefinitions():[]}const f$=Zt(function({onClose:e}){const n=z(),r=Ee(),s=c1(),[o,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[h,f]=w.useState(!1),p=w.useRef(-1),g=Xoe(),m=m1();return d.jsxs(d.Fragment,{children:[d.jsxs(cm,{children:[d.jsx(um,{children:o?`${r("embed-dialog.title")} — ${o.title}`:r("embed-dialog.title")}),d.jsx(dm,{})]}),o?d.jsxs(d.Fragment,{children:[d.jsxs(Vu,{className:"tlui-embed-dialog__enter",children:[d.jsx(hm,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:v=>{l(v);const y=m(v);u(y&&y.definition.type===o.type?y:null),f(!1),clearTimeout(p.current),p.current=n.timers.setTimeout(()=>f(!y),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",o.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:o.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(zs,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(p1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(bt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(ue,{type:"normal",onClick:e,children:d.jsx(bt,{children:r("embed-dialog.cancel")})}),d.jsx(ue,{type:"primary",disabled:!c,onClick:()=>{c&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageBounds().center,embed:c.definition}),e())},children:d.jsx(bt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(Vu,{className:"tlui-embed-dialog__list",children:g.map(v=>{const y=Voe(v.type)?s.embedIcons[v.type]:Yoe(v)?v.icon:void 0;return d.jsxs(ue,{type:"menu",onClick:()=>i(v),children:[d.jsx(bt,{children:v.title}),y&&d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${y})`}})]},v.type)})})})]})});async function qoe(t,e,n){const r=me(e.map(a=>{const l=t.getShape(a);if(!(!l||t.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||t.isShapeOfType(a,"image"))return}const s=[];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){s[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of s)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||s.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Z.Common(r.map(l=>t.getShapeMaskedPageBounds(l)));s.push({shapes:r,bounds:a})}const o=t.options.flattenImageBoundsPadding;for(const a of s){n!==void 0&&a.bounds.expandBy(-n);const l=await t.getSvgString(a.shapes,{padding:o});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 js(()=>{for(const a of s){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=t.findCommonAncestor(u)??t.getCurrentPageId();if(!h)continue;let f="a1";for(const y of u)if(y.parentId===h){y.index>f&&(f=y.index);break}let p,g,m;if(Fn(h)){const y=t.getShape(h);if(!y)continue;const S=t.getPointInShapeSpace(y,{x:c.x,y:c.y});m=t.getShapePageTransform(h).rotation(),S.sub(new x(o,o).rot(-m)),p=S.x,g=S.y}else p=c.x-o,g=c.y-o,m=0;t.deleteShapes(u),t.createAssets([{...l,id:l.id}]);const v=Ke();t.createShape({id:v,type:"image",index:f,parentId:h,x:p,y:g,rotation:-m,props:{assetId:l.id,w:c.w+o*2,h:c.h+o*2}}),i.push(v)}}),i}function fm(){const t=Ti();return(t==null?void 0:t.store.props.collaboration)!==void 0}function Zoe(){const t=Ti();return U("sync status",()=>{var e;return(e=t==null?void 0:t.store.props.collaboration)!=null&&e.status?t.store.props.collaboration.status.get():null},[t])}const dS=[0,389,436,476,580,640,840,1023];var St=(t=>(t[t.ZERO=0]="ZERO",t[t.MOBILE_XXS=1]="MOBILE_XXS",t[t.MOBILE_XS=2]="MOBILE_XS",t[t.MOBILE_SM=3]="MOBILE_SM",t[t.MOBILE=4]="MOBILE",t[t.TABLET_SM=5]="TABLET_SM",t[t.TABLET=6]="TABLET",t[t.DESKTOP=7]="DESKTOP",t))(St||{});const p$=ke.createContext(null);function Qoe({forceMobile:t=!1,children:e}){const n=Ti(),r=U("breakpoint",()=>{const{width:s}=(n==null?void 0:n.getViewportScreenBounds())??{width:window.innerWidth},o=t?St.MOBILE_SM:dS.length-1;for(let i=0;i<o;i++)if(s>dS[i]&&s<=dS[i+1])return i;return o},[n]);return d.jsx(p$.Provider,{value:r,children:e})}function An(){const t=w.useContext(p$);if(t===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return t}const g$=w.createContext(null);function Joe({context:t,children:e}){const n=Jt(),r=V0("dialogs",[]),s=w.useMemo(()=>({dialogs:r,addDialog(o){const i=o.id??ze();return r.update(a=>[...a.filter(l=>l.id!==o.id),{...o,id:i}]),n("open-menu",{source:"dialog",id:i}),Vr.addOpenMenu(i,t),i},removeDialog(o){var a;const i=r.get().find(l=>l.id===o);return i&&((a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:o}),Vr.deleteOpenMenu(o,t),r.update(l=>l.filter(c=>c!==i))),o},clearDialogs(){const o=r.get();o.length!==0&&(o.forEach(i=>{var a;(a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:i.id}),Vr.deleteOpenMenu(i.id,t)}),r.set([]))}}),[n,r,t]);return d.jsx(g$.Provider,{value:s,children:e})}function Id(){const t=w.useContext(g$);if(!t)throw new Error("useDialogs must be used within a DialogsProvider");return t}var eie="VisuallyHidden",y1=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}}));y1.displayName=eie;var S1="ToastProvider",[v1,tie,nie]=Zg("Toast"),[m$,dge]=Ws("Toast",[nie]),[rie,pm]=m$(S1),y$=t=>{const{__scopeToast:e,label:n="Notification",duration:r=5e3,swipeDirection:s="right",swipeThreshold:o=50,children:i}=t,[a,l]=w.useState(null),[c,u]=w.useState(0),h=w.useRef(!1),f=w.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${S1}\`. Expected non-empty \`string\`.`),d.jsx(v1.Provider,{scope:e,children:d.jsx(rie,{scope:e,label:n,duration:r,swipeDirection:s,swipeThreshold:o,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:w.useCallback(()=>u(p=>p+1),[]),onToastRemove:w.useCallback(()=>u(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:f,children:i})})};y$.displayName=S1;var S$="ToastViewport",sie=["F8"],Ux="toast.viewportPause",Hx="toast.viewportResume",v$=w.forwardRef((t,e)=>{const{__scopeToast:n,hotkey:r=sie,label:s="Notifications ({hotkey})",...o}=t,i=pm(S$,n),a=tie(n),l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),h=w.useRef(null),f=Qe(e,h,i.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=i.toastCount>0;w.useEffect(()=>{const v=y=>{var b;r.length!==0&&r.every(P=>y[P]||y.code===P)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r]),w.useEffect(()=>{const v=l.current,y=h.current;if(g&&v&&y){const S=()=>{if(!i.isClosePausedRef.current){const _=new CustomEvent(Ux);y.dispatchEvent(_),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const _=new CustomEvent(Hx);y.dispatchEvent(_),i.isClosePausedRef.current=!1}},P=_=>{!v.contains(_.relatedTarget)&&b()},C=()=>{v.contains(document.activeElement)||b()};return v.addEventListener("focusin",S),v.addEventListener("focusout",P),v.addEventListener("pointermove",S),v.addEventListener("pointerleave",C),window.addEventListener("blur",S),window.addEventListener("focus",b),()=>{v.removeEventListener("focusin",S),v.removeEventListener("focusout",P),v.removeEventListener("pointermove",S),v.removeEventListener("pointerleave",C),window.removeEventListener("blur",S),window.removeEventListener("focus",b)}}},[g,i.isClosePausedRef]);const m=w.useCallback(({tabbingDirection:v})=>{const S=a().map(b=>{const P=b.ref.current,C=[P,...yie(P)];return v==="forwards"?C:C.reverse()});return(v==="forwards"?S.reverse():S).flat()},[a]);return w.useEffect(()=>{const v=h.current;if(v){const y=S=>{var C,_,E;const b=S.altKey||S.ctrlKey||S.metaKey;if(S.key==="Tab"&&!b){const k=document.activeElement,D=S.shiftKey;if(S.target===v&&D){(C=c.current)==null||C.focus();return}const L=m({tabbingDirection:D?"backwards":"forwards"}),M=L.findIndex(O=>O===k);hS(L.slice(M+1))?S.preventDefault():D?(_=c.current)==null||_.focus():(E=u.current)==null||E.focus()}};return v.addEventListener("keydown",y),()=>v.removeEventListener("keydown",y)}},[a,m]),d.jsxs(Ote,{ref:l,role:"region","aria-label":s.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&d.jsx(Kx,{ref:c,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"forwards"});hS(v)}}),d.jsx(v1.Slot,{scope:n,children:d.jsx(Ae.ol,{tabIndex:-1,...o,ref:f})}),g&&d.jsx(Kx,{ref:u,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"backwards"});hS(v)}})]})});v$.displayName=S$;var x$="ToastFocusProxy",Kx=w.forwardRef((t,e)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...s}=t,o=pm(x$,n);return d.jsx(y1,{"aria-hidden":!0,tabIndex:0,...s,ref:e,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=o.viewport)!=null&&c.contains(a))&&r()}})});Kx.displayName=x$;var gm="Toast",oie="toast.swipeStart",iie="toast.swipeMove",aie="toast.swipeCancel",lie="toast.swipeEnd",w$=w.forwardRef((t,e)=>{const{forceMount:n,open:r,defaultOpen:s,onOpenChange:o,...i}=t,[a=!0,l]=ji({prop:r,defaultProp:s,onChange:o});return d.jsx(ds,{present:n||a,children:d.jsx(die,{open:a,...i,ref:e,onClose:()=>l(!1),onPause:qt(t.onPause),onResume:qt(t.onResume),onSwipeStart:se(t.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:se(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:se(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:se(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)})})})});w$.displayName=gm;var[cie,uie]=m$(gm,{onClose(){}}),die=w.forwardRef((t,e)=>{const{__scopeToast:n,type:r="foreground",duration:s,open:o,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:f,onSwipeEnd:p,...g}=t,m=pm(gm,n),[v,y]=w.useState(null),S=Qe(e,O=>y(O)),b=w.useRef(null),P=w.useRef(null),C=s||m.duration,_=w.useRef(0),E=w.useRef(C),k=w.useRef(0),{onToastAdd:D,onToastRemove:T}=m,j=qt(()=>{var F;(v==null?void 0:v.contains(document.activeElement))&&((F=m.viewport)==null||F.focus()),i()}),L=w.useCallback(O=>{!O||O===1/0||(window.clearTimeout(k.current),_.current=new Date().getTime(),k.current=window.setTimeout(j,O))},[j]);w.useEffect(()=>{const O=m.viewport;if(O){const F=()=>{L(E.current),c==null||c()},B=()=>{const K=new Date().getTime()-_.current;E.current=E.current-K,window.clearTimeout(k.current),l==null||l()};return O.addEventListener(Ux,B),O.addEventListener(Hx,F),()=>{O.removeEventListener(Ux,B),O.removeEventListener(Hx,F)}}},[m.viewport,C,l,c,L]),w.useEffect(()=>{o&&!m.isClosePausedRef.current&&L(C)},[o,C,m.isClosePausedRef,L]),w.useEffect(()=>(D(),()=>T()),[D,T]);const M=w.useMemo(()=>v?k$(v):null,[v]);return m.viewport?d.jsxs(d.Fragment,{children:[M&&d.jsx(hie,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:M}),d.jsx(cie,{scope:n,onClose:j,children:ba.createPortal(d.jsx(v1.ItemSlot,{scope:n,children:d.jsx(jte,{asChild:!0,onEscapeKeyDown:se(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||j(),m.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(Ae.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":o?"open":"closed","data-swipe-direction":m.swipeDirection,...g,ref:S,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:se(t.onKeyDown,O=>{O.key==="Escape"&&(a==null||a(O.nativeEvent),O.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,j()))}),onPointerDown:se(t.onPointerDown,O=>{O.button===0&&(b.current={x:O.clientX,y:O.clientY})}),onPointerMove:se(t.onPointerMove,O=>{if(!b.current)return;const F=O.clientX-b.current.x,B=O.clientY-b.current.y,K=!!P.current,R=["left","right"].includes(m.swipeDirection),H=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,X=R?H(0,F):0,te=R?0:H(0,B),le=O.pointerType==="touch"?10:2,de={x:X,y:te},Me={originalEvent:O,delta:de};K?(P.current=de,kh(iie,h,Me,{discrete:!1})):dE(de,m.swipeDirection,le)?(P.current=de,kh(oie,u,Me,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(F)>le||Math.abs(B)>le)&&(b.current=null)}),onPointerUp:se(t.onPointerUp,O=>{const F=P.current,B=O.target;if(B.hasPointerCapture(O.pointerId)&&B.releasePointerCapture(O.pointerId),P.current=null,b.current=null,F){const K=O.currentTarget,R={originalEvent:O,delta:F};dE(F,m.swipeDirection,m.swipeThreshold)?kh(lie,p,R,{discrete:!0}):kh(aie,f,R,{discrete:!0}),K.addEventListener("click",H=>H.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),hie=t=>{const{__scopeToast:e,children:n,...r}=t,s=pm(gm,e),[o,i]=w.useState(!1),[a,l]=w.useState(!1);return gie(()=>i(!0)),w.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(bd,{asChild:!0,children:d.jsx(y1,{...r,children:o&&d.jsxs(d.Fragment,{children:[s.label," ",n]})})})},fie="ToastTitle",b$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});b$.displayName=fie;var pie="ToastDescription",P$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});P$.displayName=pie;var C$="ToastAction",_$=w.forwardRef((t,e)=>{const{altText:n,...r}=t;return n.trim()?d.jsx(E$,{altText:n,asChild:!0,children:d.jsx(x1,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${C$}\`. Expected non-empty \`string\`.`),null)});_$.displayName=C$;var I$="ToastClose",x1=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t,s=uie(I$,n);return d.jsx(E$,{asChild:!0,children:d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:se(t.onClick,s.onClose)})})});x1.displayName=I$;var E$=w.forwardRef((t,e)=>{const{__scopeToast:n,altText:r,...s}=t;return d.jsx(Ae.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:e})});function k$(t){const e=[];return Array.from(t.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),mie(r)){const s=r.ariaHidden||r.hidden||r.style.display==="none",o=r.dataset.radixToastAnnounceExclude==="";if(!s)if(o){const i=r.dataset.radixToastAnnounceAlt;i&&e.push(i)}else e.push(...k$(r))}}),e}function kh(t,e,n,{discrete:r}){const s=n.originalEvent.currentTarget,o=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?Db(s,o):s.dispatchEvent(o)}var dE=(t,e,n=0)=>{const r=Math.abs(t.x),s=Math.abs(t.y),o=r>s;return e==="left"||e==="right"?o&&r>n:!o&&s>n};function gie(t=()=>{}){const e=qt(t);yi(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[e])}function mie(t){return t.nodeType===t.ELEMENT_NODE}function yie(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function hS(t){const e=document.activeElement;return t.some(n=>n===e?!0:(n.focus(),document.activeElement!==e))}var Sie=w$,vie=b$,xie=P$,wie=_$,hE=x1;const T$=w.createContext(null);function bie({children:t}){const e=V0("toasts",[]),n=w.useMemo(()=>({toasts:e,addToast(r){const s=r.id??ze();return e.update(o=>[...o.filter(i=>i.id!==r.id),{...r,id:s}]),s},removeToast(r){return e.update(s=>s.filter(o=>o.id!==r)),r},clearToasts(){e.set([])}}),[e]);return d.jsx(y$,{children:d.jsx(T$.Provider,{value:n,children:t})})}function To(){const t=w.useContext(T$);if(!t)throw new Error("useToasts must be used within a ToastsProvider");return t}var M$={exports:{}};(function(t){var e=function(){var n=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",o={};function i(l,c){if(!o[l]){o[l]={};for(var u=0;u<l.length;u++)o[l][l.charAt(u)]=u}return o[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,f=c.length;h<f;h++){var p=c.charCodeAt(h);u[h*2]=p>>>8,u[h*2+1]=p%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 f=[];return c.forEach(function(p){f.push(n(p))}),a.decompress(f.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return s.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(s,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,f,p={},g={},m="",v="",y="",S=2,b=3,P=2,C=[],_=0,E=0,k;for(k=0;k<l.length;k+=1)if(m=l.charAt(k),Object.prototype.hasOwnProperty.call(p,m)||(p[m]=b++,g[m]=!0),v=y+m,Object.prototype.hasOwnProperty.call(p,v))y=v;else{if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(f=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}else{for(f=1,h=0;h<P;h++)_=_<<1|f,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=0;for(f=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(f=p[y],h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;S--,S==0&&(S=Math.pow(2,P),P++),p[v]=b++,y=String(m)}if(y!==""){if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(f=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}else{for(f=1,h=0;h<P;h++)_=_<<1|f,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=0;for(f=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(f=p[y],h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;S--,S==0&&(S=Math.pow(2,P),P++)}for(f=2,h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;for(;;)if(_=_<<1,E==c-1){C.push(u(_));break}else E++;return C.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],f=4,p=4,g=3,m="",v=[],y,S,b,P,C,_,E,k={val:u(0),position:c,index:1};for(y=0;y<3;y+=1)h[y]=y;for(b=0,C=Math.pow(2,2),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 2:return""}for(h[3]=E,S=E,v.push(E);;){if(k.index>l)return"";for(b=0,C=Math.pow(2,g),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(E=b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[p++]=n(b),E=p-1,f--;break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[p++]=n(b),E=p-1,f--;break;case 2:return v.join("")}if(f==0&&(f=Math.pow(2,g),g++),h[E])m=h[E];else if(E===p)m=S+S.charAt(0);else return null;v.push(m),h[p++]=S+m.charAt(0),f--,S=m,f==0&&(f=Math.pow(2,g),g++)}}};return a}();t!=null?t.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})})(M$);var Pie=M$.exports;const A$=wi(Pie),w1="web image/vnd.tldraw+png",Cie={"image/png":w1},_ie={[w1]:"image/png"};function Iie(t){return hn(Cie,t)??null}function Eie(t){return hn(_ie,t)??t}function kie(t){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(t)}function Tie(t){const e=Object.entries(t);for(const[n,r]of e)r.catch(s=>console.error(s));return navigator.clipboard.write([new ClipboardItem(t)]).catch(n=>(console.error(n),Promise.all(e.map(async([r,s])=>[r,await s])).then(r=>{const s=x0(r);return navigator.clipboard.write([new ClipboardItem(s)])})))}async function Mie(t,e,n){var y,S,b;const{elements:r,files:s}=e,o={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:t.store.schema.serialize()},i=new Map,a=new Map,l=t.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(P=>{if(c.set(P.id,Ke()),P.boundElements!==null)for(const C of P.boundElements)C.type==="text"&&h.add(C.id)});let f=VT;for(const P of r){if(h.has(P.id))continue;const C=c.get(P.id),_={id:C,typeName:"shape",parentId:l,index:f,x:P.x,y:P.y,rotation:0,isLocked:P.locked,opacity:Aie(P.opacity),meta:{}};switch(P.angle!==0&&a.set(C,P.angle),P.groupIds&&P.groupIds.length>0?i.has(P.groupIds[0])?(y=i.get(P.groupIds[0]))==null||y.push(C):i.set(P.groupIds[0],[C]):u.push(C),P.type){case"rectangle":case"ellipse":case"diamond":{let E="",k="middle";if(P.boundElements!==null){for(const T of P.boundElements)if(T.type==="text"){const j=r.find(L=>L.id===T.id);j&&(E=j.text,k=Fie[j.textAlign])}}const D=P.backgroundColor==="transparent"?P.strokeColor:P.backgroundColor;o.shapes.push({..._,type:"geo",props:{geo:P.type,url:P.link??"",w:P.width,h:P.height,size:Th[P.strokeWidth]??"draw",color:Ac[D]??"black",text:E,align:k,dash:Mh(P),fill:Bie(P)}});break}case"freedraw":{o.shapes.push({..._,type:"draw",props:{dash:Mh(P),size:Th[P.strokeWidth],color:Ac[P.strokeColor]??"black",segments:[{type:"free",points:P.points.map(([E,k,D=.5])=>({x:E,y:k,z:D}))}]}});break}case"line":{if(P.points.slice().length<2)break;const k=Fu(P.points.length);o.shapes.push({..._,type:"line",props:{dash:Mh(P),size:Th[P.strokeWidth],color:Ac[P.strokeColor]??"black",spline:P.roundness?"cubic":"line",points:{...Object.fromEntries(P.points.map(([D,T],j)=>{const L=k[j];return[L,{id:L,index:L,x:D,y:T}]}))}}});break}case"arrow":{let E="";if(P.boundElements!==null){for(const L of P.boundElements)if(L.type==="text"){const M=r.find(O=>O.id===L.id);M&&(E=M.text)}}const k=P.points[0],D=P.points[P.points.length-1],T=c.get((S=P.startBinding)==null?void 0:S.elementId),j=c.get((b=P.endBinding)==null?void 0:b.elementId);o.shapes.push({..._,type:"arrow",props:{text:E,bend:zie(P,k,D),dash:Mh(P),size:Th[P.strokeWidth]??"m",color:Ac[P.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:D[0],y:D[1]},arrowheadEnd:fE[P.endArrowhead]??"none",arrowheadStart:fE[P.startArrowhead]??"none"}}),T&&o.bindings.push({id:Ji(),typeName:"binding",type:"arrow",fromId:C,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),j&&o.bindings.push({id:Ji(),typeName:"binding",type:"arrow",fromId:C,toId:j,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:E,scale:k}=Oie(P.fontSize);o.shapes.push({..._,type:"text",props:{size:E,scale:k,font:Die[P.fontFamily]??"draw",color:Ac[P.strokeColor]??"black",text:P.text,textAlign:Nie[P.textAlign]}});break}case"image":{const E=s[P.fileId];if(!E)break;const k=Yo.createId();o.assets.push({id:k,typeName:"asset",type:"image",props:{w:P.width,h:P.height,fileSize:E.size,name:P.id??"Untitled",isAnimated:!1,mimeType:E.mimeType,src:E.dataURL},meta:{}}),o.shapes.push({..._,type:"image",props:{w:P.width,h:P.height,assetId:k}})}}f=_s(f)}const p=n??(t.inputs.shiftKey?t.inputs.currentPagePoint:void 0);t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(o,{point:p,select:!1,preserveIds:!0});for(const P of i.values())if(P.length>1){t.groupShapes(P);const C=t.getShape(P[0]);C!=null&&C.parentId&&Fn(C.parentId)&&u.push(C.parentId)}for(const[P,C]of a)t.select(P),t.rotateShapesBy([P],C);const g=me(u.map(P=>t.getShape(P))),m=Z.Common(g.map(P=>t.getShapePageBounds(P))),v=t.getViewportPageBounds().center;t.updateShapes(g.map(P=>{const C={x:(P.x??0)-(m.x+m.w/2),y:(P.y??0)-(m.y+m.h/2)};return{id:P.id,type:P.type,x:v.x+C.x,y:v.y+C.y}})),t.setSelectedShapes(u)}const Aie=t=>{const e=t/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},Th={1:"s",2:"m",3:"l",4:"xl"},jie={16:"s",20:"m",28:"l",36:"xl"};function Oie(t){const e=jie[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 Die={1:"draw",2:"sans",3:"mono"},Rie={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 Ss(t,e,n){const r=[0,1,2,3,4].map(s=>Rie[t][s]);return Object.fromEntries(r.map((s,o)=>[s,o<3?e:n]))}const Ac={...Ss("gray","grey","black"),...Ss("red","light-red","red"),...Ss("pink","light-red","red"),...Ss("grape","light-violet","violet"),...Ss("blue","light-blue","blue"),...Ss("cyan","light-blue","blue"),...Ss("teal","light-green","green"),...Ss("green","light-green","green"),...Ss("yellow","yellow","orange"),...Ss("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},Lie={solid:"draw",dashed:"dashed",dotted:"dotted"},$ie={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Fie={left:"start",center:"middle",right:"end"},Nie={left:"start",center:"middle",right:"end"},fE={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function zie(t,e,n){let r=0;if(t.points.length>2){const s=new x(e[0],e[1]),o=new x(n[0],n[1]),i=new x(t.points[1][0],t.points[1][1]),a=x.Sub(o,s),l=x.Per(a),c=x.Med(o,s),u=x.Sub(c,l),h=x.Add(c,l),f=x.NearestPointOnLineSegment(u,h,i,!1);r=x.Dist(f,c),x.Clockwise(f,o,c)&&(r*=-1)}return r}const Mh=t=>{let e=Lie[t.strokeStyle]??"draw";return e==="draw"&&t.roughness===0&&(e="solid"),e},Bie=t=>t.backgroundColor==="transparent"?"none":$ie[t.fillStyle]??"solid";async function Uie(t,e,n,r){const s=e.map(o=>o instanceof File?o:new File([o],"tldrawFile",{type:o.type}));t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"files",files:s,point:n,ignoreParent:!1,sources:r})}function Hie(t,e,n){const r=t.getSelectionPageBounds();t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(e,{point:n,select:!0});const s=t.getSelectionPageBounds();r&&s&&(r!=null&&r.collides(s))&&(t.updateInstanceState({isChangingStyle:!0}),t.timers.setTimeout(()=>{t.updateInstanceState({isChangingStyle:!1})},150))}async function Wx(t,e,n,r){return t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"url",point:n,url:e,sources:r})}const Kie=[w1,"image/png","image/jpeg","image/webp","image/svg+xml"];function Wie(t){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t.trim(),e.body.textContent||e.body.innerText||""}const Gie=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},Vie=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 vj(e)},Yie=t=>/^<svg/.test(t),Xie=["input","select","textarea"];function fS(t){const{activeElement:e}=document;return t.menus.hasAnyOpenMenus()||e&&(e.getAttribute("contenteditable")||Xie.indexOf(e.tagName.toLowerCase())>-1)}const Ah=(t,e,n,r)=>{const s=Vie(e);if(s)for(const o of s)Wx(t,o,n);else Gie(e)?Wx(t,e,n):Yie(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}))},qie=async(t,e,n)=>{if(t.getEditingShapeId()!==null)return;if(!e)throw Error("No clipboard data");const r=[];for(const s of Object.values(e.items))switch(s.kind){case"file":{r.push({type:"file",source:new Promise(o=>o(s.getAsFile()))});break}case"string":{s.type==="text/html"?r.push({type:"html",source:new Promise(o=>s.getAsString(o))}):s.type==="text/plain"?r.push({type:"text",source:new Promise(o=>s.getAsString(o))}):r.push({type:s.type,source:new Promise(o=>s.getAsString(o))});break}}O$(t,r,n)},j$=async({editor:t,clipboardItems:e,point:n,fallbackFiles:r})=>{const s=[];for(const o of e){for(const i of Kie)if(o.types.includes(i)){const a=o.getType(i).then(l=>Zr.rewriteMimeType(l,Eie(i)));s.push({type:"blob",source:a});break}o.types.includes("text/html")&&s.push({type:"html",source:(async()=>{const i=await o.getType("text/html");return await Zr.blobToText(i)})()}),o.types.includes("text/uri-list")&&s.push({type:"url",source:(async()=>{const i=await o.getType("text/uri-list");return await Zr.blobToText(i)})()}),o.types.includes("text/plain")&&s.push({type:"text",source:(async()=>{const i=await o.getType("text/plain");return await Zr.blobToText(i)})()})}return r&&s.length===1&&s[0].type==="text"&&(s.pop(),s.push(...r.map(o=>({type:"file",source:Promise.resolve(o)})))),await O$(t,s,n)};async function O$(t,e,n){const r=e.filter(o=>(o.type==="file"||o.type==="blob")&&o.source!==null);if(r.length){if(r.length>t.options.maxFilesAtOnce)throw Error("Too many files");const o=me(await Promise.all(r.map(i=>i.source)));return await Uie(t,o,n)}const s=await Promise.all(e.filter(o=>o.type!=="file").map(o=>new Promise(i=>{const a=o;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=A$.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const f=JSON.parse(h);if(f.type!=="application/tldraw"&&i({type:"error",data:f,reason:`found tldraw data comment but JSON was of a different type: ${f.type}`}),typeof f.data=="string"){i({type:"error",data:f,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:f.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 o of s)if(o.type==="tldraw"){Hie(t,o.data,n);return}for(const o of s)if(o.type==="excalidraw"){Mie(t,o.data,n);return}for(const o of s){if(o.type==="text"&&o.subtype==="html"){const a=new DOMParser().parseFromString(o.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");Ah(t,c,n,s);return}if(!s.some(c=>c.type==="text"&&c.subtype!=="html")&&o.data.trim()){Ah(t,Wie(o.data),n,s);return}}if(o.type==="text"&&o.subtype==="text"&&o.data.startsWith("<iframe ")){const a=new DOMParser().parseFromString(o.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="IFRAME"&&a.firstElementChild.hasAttribute("src")&&a.firstElementChild.getAttribute("src")!==""){const c=a.firstElementChild.getAttribute("src");Ah(t,c,n,s);return}}}for(const o of s)if(o.type==="text"&&o.subtype==="url"){Wx(t,o.data,n,s);return}for(const o of s)if(o.type==="text"&&o.subtype==="text"&&o.data.trim()){Ah(t,o.data,n,s);return}}const Wp=async t=>{var r;const e=await t.resolveAssetsInContent(t.getContentFromCurrentPage(t.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=A$.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:e}));if(!(typeof navigator>"u")){const s=e.shapes.map(o=>t.getShapeUtil(o).getText(o)).filter(hB);if((r=navigator.clipboard)!=null&&r.write){const o=new Blob([`<div data-tldraw>${n}</div>`],{type:"text/html"});let i=s.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<div data-tldraw>${n}</div>`)}};function Zie(){const t=z(),e=Jt(),n=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Wp(t),e("copy",{source:i}))},[t,e]),r=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Wp(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:i}))},[t,e]),s=w.useCallback(async function(i,a,l){t.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(j$({editor:t,clipboardItems:i,point:l}),e("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{s(c,a,l)}))},[t,e]);return{copy:n,cut:r,paste:s}}function Qie(){const t=z(),e=Jt(),n=U("editor.isFocused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!n)return;const r=async l=>{t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||fS(t)||(xe(l),await Wp(t),e("copy",{source:"kbd"}))};async function s(l){t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||fS(t)||(xe(l),await Wp(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let o=!1;const i=l=>{l.button===1&&(o=!0,t.timers.requestAnimationFrame(()=>{o=!1}))},a=l=>{var f,p;if(o){Ct(l);return}if(t.getEditingShapeId()!==null||fS(t))return;let c,u=!1;t.inputs.shiftKey&&(u=!0),t.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=t.inputs.currentPagePoint);const h=()=>{l.clipboardData&&qie(t,l.clipboardData,c)};if((f=navigator.clipboard)!=null&&f.read){const g=Array.from(((p=l.clipboardData)==null?void 0:p.files)||[]);navigator.clipboard.read().then(m=>{Array.isArray(m)&&m[0]instanceof ClipboardItem&&j$({editor:t,clipboardItems:m,point:c,fallbackFiles:g})},()=>{h()})}else h();xe(l),e("paste",{source:"kbd"})};return document.addEventListener("copy",r),document.addEventListener("cut",s),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",s),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 Jie(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,s,o,i,a=[],l=!0,c=!1;try{if(o=(n=n.call(t)).next,e===0){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=o.call(n)).done)&&(a.push(r.value),a.length!==e);l=!0);}catch(u){c=!0,s=u}finally{try{if(!l&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw s}}return a}}function pE(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),n.push.apply(n,r)}return n}function rr(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?pE(Object(n),!0).forEach(function(r){eae(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):pE(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function eae(t,e,n){return e=cae(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function tae(t,e){if(t==null)return{};var n={},r=Object.keys(t),s,o;for(o=0;o<r.length;o++)s=r[o],!(e.indexOf(s)>=0)&&(n[s]=t[s]);return n}function nae(t,e){if(t==null)return{};var n=tae(t,e),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(s=0;s<o.length;s++)r=o[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function gE(t,e){return sae(t)||Jie(t,e)||D$(t,e)||aae()}function jh(t){return rae(t)||oae(t)||D$(t)||iae()}function rae(t){if(Array.isArray(t))return Gx(t)}function sae(t){if(Array.isArray(t))return t}function oae(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function D$(t,e){if(t){if(typeof t=="string")return Gx(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 Gx(t,e)}}function Gx(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 iae(){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 aae(){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 lae(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);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function cae(t){var e=lae(t,"string");return typeof e=="symbol"?e:String(e)}function du(t){var e=t.sizes.shift(),n=Math.max(Math.ceil(e[0]),1),r=Math.max(Math.ceil(e[1]),1),s=[n-1,r-1,1,1],o=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,s),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,f=Date.now()-o;return[a,l].forEach(function(p){p.height=0,p.width=0}),i?(postMessage({width:n,height:r,benchmark:f,isTestPass:h}),!h&&t.sizes.length&&du(t)):h?t.onSuccess(n,r,f):(t.onError(n,r,f),t.sizes.length&&du(t)),h}var pS={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]},uae=["onError","onSuccess"],cl={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},jc={};function gS(t){var e=t.width===t.height,n=t.height===1,r=t.width===1,s=[];if(!t.width||!t.height)t.sizes.forEach(function(u){var h=e||n?u:1,f=e||r?u:1;s.push([h,f])});else for(var o=t.min||cl.min,i=t.step||cl.step,a=Math.max(t.width,t.height);a>=o;){var l=e||n?a:1,c=e||r?a:1;s.push([l,c]),a-=i}return s}function Oh(t){var e=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),s=t.onError,o=t.onSuccess,i=nae(t,uae),a=null;if(!e)return!1;if(t.useWorker&&n){var l=`
|
|
248
|
+
var canvasTest = `.concat(du.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 f=h.data,p=f.width,g=f.height,m=f.benchmark,v=f.isTestPass;v?(jc[r].onSuccess(p,g,m),delete jc[r]):jc[r].onError(p,g,m)}}if(t.usePromise)return new Promise(function(h,f){var p=rr(rr({},t),{},{onError:function(y,S,b){var P;if(t.sizes.length===0)P=!0;else{var C=t.sizes.slice(-1),_=gE(C,1),E=gE(_[0],2),k=E[0],D=E[1];P=y===k&&S===D}s(y,S,b),P&&f({width:y,height:S,benchmark:b})},onSuccess:function(y,S,b){o(y,S,b),h({width:y,height:S,benchmark:b})}});if(a){var g=p.onError,m=p.onSuccess;jc[r]={onError:g,onSuccess:m},a.postMessage(i)}else du(p)});if(a)jc[r]={onError:s,onSuccess:o},a.postMessage(i);else return du(t)}var mS={maxArea:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=gS({width:e.max,height:e.max,min:e.min,step:e.step,sizes:jh(pS.area)}),r=rr(rr(rr({},cl),e),{},{sizes:n});return Oh(r)},maxHeight:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=gS({width:1,height:e.max,min:e.min,step:e.step,sizes:jh(pS.height)}),r=rr(rr(rr({},cl),e),{},{sizes:n});return Oh(r)},maxWidth:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=gS({width:e.max,height:1,min:e.min,step:e.step,sizes:jh(pS.width)}),r=rr(rr(rr({},cl),e),{},{sizes:n});return Oh(r)},test:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=rr(rr({},cl),e);return n.sizes=jh(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),Oh(n)}};let yS=null;function dae(){return yS||(yS=hae()),yS}async function hae(){const t=await mS.maxWidth({usePromise:!0}),e=await mS.maxHeight({usePromise:!0}),n=await mS.maxArea({usePromise:!0});return{maxWidth:t.width,maxHeight:e.height,maxArea:n.width*n.height}}const mE=8192,fae=4096*4096;async function pae(t,e){if(t<=mE&&e<=mE&&t*e<=fae)return[t,e];const{maxWidth:n,maxHeight:r,maxArea:s}=await dae(),o=t/e;if(t>n&&(t=n,e=t/o),e>r&&(e=r,t=e*o),t*e>s){const i=Math.sqrt(s/(t*e));t*=i,e*=i}return[t,e]}async function R$(t,e,n){const{type:r,width:s,height:o,quality:i=1,pixelRatio:a=2}=n;let[l,c]=await pae(s*a,o*a);l=Math.floor(l),c=Math.floor(c);const u=l/s,h=await Zr.blobToDataUrl(new Blob([e],{type:"image/svg+xml"})),f=await new Promise(g=>{const m=Lu();m.crossOrigin="anonymous",m.onload=async()=>{Ge.isSafari&&await Hv(250);const v=document.createElement("canvas"),y=v.getContext("2d");v.width=l,v.height=c,y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.drawImage(m,0,0,l,c),URL.revokeObjectURL(h),g(v)},m.onerror=()=>{g(null)},m.src=h});if(!f)return null;const p=await new Promise(g=>f.toBlob(m=>{(!m||wt.throwToBlob.get())&&g(null),g(m)},"image/"+r,i));if(!p)return null;if(r==="png"){const g=new DataView(await p.arrayBuffer());return Ps.setPhysChunk(g,u,{type:"image/"+r})}else return p}async function L$(t,e,n){const r=await t.getSvgString(e!=null&&e.length?e:[...t.getCurrentPageShapeIds()],{scale:n.scale??1,background:t.getInstanceState().exportBackground,...n});if(!r)throw new Error("Could not construct SVG.");return r}async function Vx(t,e,n,r={}){var s;switch(n){case"svg":return(s=await L$(t,e,r))==null?void 0:s.svg;case"json":{const o=await t.resolveAssetsInContent(t.getContentFromCurrentPage(e));return JSON.stringify(o)}default:Ot(n)}}async function $$({editor:t,ids:e,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await Vx(t,e,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Vx(t,e,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const s=await L$(t,e,r);if(!s)throw new Error("Could not construct image.");const o=await R$(t,s.svg,{type:n,quality:r.quality,pixelRatio:r.pixelRatio,width:s.width,height:s.height});if(!o)throw new Error("Could not construct image.");return o}default:Ot(n)}}const gae={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function mae(t,e,n,r={}){return{blobPromise:$$({editor:t,ids:e,format:n,opts:r}),mimeType:gae[n]}}function yae(t,e,n="svg",r={}){if(!navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(navigator.clipboard.write){const{blobPromise:s,mimeType:o}=mae(t,e,n,r),i={[o]:s},a=Iie(o);return a&&kie(a)&&(i[a]=s.then(l=>Zr.rewriteMimeType(l,a))),Tie(i)}switch(n){case"json":case"svg":return Sae(async()=>Vx(t,e,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Ot(n)}}async function Sae(t){var e,n;await((n=(e=navigator.clipboard)==null?void 0:e.writeText)==null?void 0:n.call(e,await t()))}function vae(){const t=z(),{addToast:e}=To(),n=Ee();return w.useCallback((r,s="svg")=>{yae(t,r,s).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 xae(t,e,n="png",r,s={}){if(!r&&(r=`shapes at ${yE()}`,e.length===1)){const a=t.getShape(e[0]);t.isShapeOfType(a,"frame")?r=a.props.name||"frame":r=`${Og(a.id)} at ${yE()}`}r+=`.${n}`;const o=await $$({editor:t,ids:e,format:n,opts:s}),i=new File([o],r,{type:o.type});wae(i)}function yE(){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"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0"),i=String(t.getSeconds()).padStart(2,"0");return`${e}-${n}-${r} ${s}.${o}.${i}`}function wae(t){const e=document.createElement("a"),n=URL.createObjectURL(t);e.href=n,e.download=t.name,e.click(),URL.revokeObjectURL(n)}function bae(){const t=z(),{addToast:e}=To(),n=Ee();return w.useCallback((r,s="png",o)=>{xae(t,r,s,o,{scale:1,background:t.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),e({id:"export-fail",title:n("toast.error.export-fail.title"),description:n("toast.error.export-fail.desc"),severity:"error"})})},[t,e,n])}const F$=ke.createContext([]);function Pae(){const t=z(),e=w.useRef(),n=qo(ke.useContext(F$));return w.useEffect(()=>{const r=window.document.createElement("input");r.type="file",r.accept=(n==null?void 0:n.join(","))??U9,r.multiple=!0,e.current=r;async function s(o){const i=o.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",s),()=>{e.current=void 0,r.removeEventListener("change",s)}},[t,n]),w.useCallback(()=>{var r;(r=e.current)==null||r.click()},[e])}function Cae(){const t=z(),e=w.useRef(null),n=w.useRef(null);return w.useCallback(async function(){const s=document.createElement("div"),o=document.createElement("style"),i=(y,S)=>{y&&(y.innerHTML=""),S&&document.head.contains(S)&&document.head.removeChild(S),y&&document.body.contains(y)&&document.body.removeChild(y)};i(e.current,n.current),e.current=s,n.current=o;const a=`tl-print-surface-${ze()}`;s.className=a,o.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(o),document.body.appendChild(s)},c=()=>{t.once("tick",()=>{i(s,o)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(y,S,b){try{s.innerHTML+=`<div class="${a}__item">
|
|
326
|
+
<div class="${a}__item__header">
|
|
327
|
+
${y.replace(/</g,"<").replace(/>/g,">")}
|
|
328
|
+
</div>
|
|
329
|
+
<div class="${a}__item__main">
|
|
330
|
+
${b}
|
|
331
|
+
</div>
|
|
332
|
+
<div class="${a}__item__footer ${a}__item__footer__${S?"":"hide"}">
|
|
333
|
+
${S??""}
|
|
334
|
+
</div>
|
|
335
|
+
</div>`}catch(P){console.error(P)}}function h(){Ge.isChromeForIos?(l(),window.print()):Ge.isSafari?(l(),document.execCommand("print",!1)):window.print()}const f=t.getSelectedShapeIds(),p=t.getCurrentPageId(),g=t.getPages(),v={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(t.getSelectedShapeIds().length>0){const y=await t.getSvgString(f,v);if(y){const S=g.find(b=>b.id===p);u(`tldraw — ${S==null?void 0:S.name}`,null,y.svg),h()}}else{const y=t.getCurrentPage(),S=await t.getSvgString(t.getSortedChildIdsForParent(y.id),v);S&&(u(`tldraw — ${y.name}`,null,S.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[t])}function b1(){const{addToast:t,removeToast:e,clearToasts:n}=To(),{addDialog:r,clearDialogs:s,removeDialog:o}=Id(),i=Ee(),a=Pae(),l=Cae(),{cut:c,copy:u,paste:h}=Zie(),f=vae(),p=bae(),g=m1(),v=An()<St.TABLET_SM;return w.useMemo(()=>({addToast:t,removeToast:e,clearToasts:n,addDialog:r,removeDialog:o,clearDialogs:s,msg:i,isMobile:v,insertMedia:a,printSelectionOrPages:l,cut:c,copy:u,paste:h,copyAs:f,exportAs:p,getEmbedDefinition:g}),[t,e,n,r,o,s,i,v,a,l,c,u,h,f,p,g])}function _ae(t,e){const n={};for(const r of t)if(r.translations)for(const[s,o]of Xn(r.translations)){let i=n[s];i||(i=n[s]={}),Object.assign(i,o)}return{actions:(r,s,o)=>{for(const i of t)i.actions&&(s=i.actions(r,s,o));return s},tools:(r,s,o)=>{for(const i of t)i.tools&&(s=i.tools(r,s,{...e,...o}));return s},translations:n}}function N$(t){return w.useMemo(()=>t,t)}function Iae(t){const e=N$(t==null?[]:Array.isArray(t)?t:[t]);return w.useMemo(()=>{const n={};for(const r of e)if(r.translations)for(const[s,o]of Xn(r.translations)){let i=n[s];i||(i=n[s]={}),Object.assign(i,o)}return n},[e])}function Eae(t){const e=b1(),n=N$(t==null?[]:Array.isArray(t)?t:[t]);return w.useMemo(()=>_ae(n,e),[n,e])}const z$=w.createContext(null);function kae(t){return Object.fromEntries(t.map(e=>[e.id,e]))}function Ba(t,e){if(t.getSelectedShapes().length===0)return t.getDocumentSettings().name||e}function Tae({overrides:t,children:e}){const n=z(),r=fm(),s=b1(),o=Jt(),i=s.msg("document.default-name"),a=w.useMemo(()=>{function l(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function c(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}const u=[{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(f){c()&&(l()||(o("edit-link",{source:f}),n.markHistoryStoppingPoint("edit-link"),s.addDialog({component:Uoe})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(f){o("insert-embed",{source:f}),s.addDialog({component:f$})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(f){o("insert-media",{source:f}),s.insertMedia()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(f){o("undo",{source:f}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(f){o("redo",{source:f}),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(f){let p=n.getSelectedShapeIds();p.length===0&&(p=Array.from(n.getCurrentPageShapeIds().values())),p.length!==0&&(o("export-as",{format:"svg",source:f}),s.exportAs(p,"svg",Ba(n,i)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(f){let p=n.getSelectedShapeIds();p.length===0&&(p=Array.from(n.getCurrentPageShapeIds().values())),p.length!==0&&(o("export-as",{format:"png",source:f}),s.exportAs(p,"png",Ba(n,i)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(f){let p=n.getSelectedShapeIds();p.length===0&&(p=Array.from(n.getCurrentPageShapeIds().values())),p.length!==0&&(o("export-as",{format:"json",source:f}),s.exportAs(p,"json",Ba(n,i)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(f){let p=n.getSelectedShapeIds();p.length===0&&(p=Array.from(n.getCurrentPageShapeIds().values())),p.length!==0&&(o("export-all-as",{format:"svg",source:f}),s.exportAs(Array.from(n.getCurrentPageShapeIds()),"svg",Ba(n,i)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(f){const p=Array.from(n.getCurrentPageShapeIds().values());p.length!==0&&(o("export-all-as",{format:"png",source:f}),s.exportAs(p,"png",Ba(n,i)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(f){const p=Array.from(n.getCurrentPageShapeIds().values());p.length!==0&&(o("export-all-as",{format:"json",source:f}),s.exportAs(p,"json",Ba(n,i)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(f){let p=n.getSelectedShapeIds();p.length===0&&(p=Array.from(n.getCurrentPageShapeIds().values())),p.length!==0&&(o("copy-as",{format:"svg",source:f}),s.copyAs(p,"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(f){let p=n.getSelectedShapeIds();p.length===0&&(p=Array.from(n.getCurrentPageShapeIds().values())),p.length!==0&&(o("copy-as",{format:"png",source:f}),s.copyAs(p,"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(f){let p=n.getSelectedShapeIds();p.length===0&&(p=Array.from(n.getCurrentPageShapeIds().values())),p.length!==0&&(o("copy-as",{format:"json",source:f}),s.copyAs(p,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(f){if(!c()||l())return;o("toggle-auto-size",{source:f}),n.markHistoryStoppingPoint("toggling auto size");const p=n.getSelectedShapes().filter(g=>n.isShapeOfType(g,"text")&&g.props.autoSize===!1);n.updateShapes(p.map(g=>({id:g.id,type:g.type,props:{...g.props,w:8,autoSize:!0}}))),Xe(n,p.map(g=>g.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(f){o("open-embed-link",{source:f});const p=n.getSelectedShapeIds(),g="No embed shapes selected";if(p.length!==1){console.error(g);return}const m=n.getShape(p[0]);if(!m||!n.isShapeOfType(m,"embed")){console.error(g);return}gte(m.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(f){var p,g;if(((p=n.root.getCurrent())==null?void 0:p.id)!=="zoom"&&(o("zoom-tool",{source:f}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const m=n.root.getCurrent();m&&((g=m.getCurrent())==null?void 0:g.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:m.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(f){c()&&(l()||n.run(()=>{o("convert-to-bookmark",{source:f});const p=n.getSelectedShapes(),g=[],m=[];for(const v of p){if(!v||!n.isShapeOfType(v,"embed")||!v.props.url)continue;const y=new x(v.x,v.y);y.rot(-v.rotation),y.add(new x(v.props.w/2-300/2,v.props.h/2-320/2)),y.rot(v.rotation);const S={id:Ke(),type:"bookmark",rotation:v.rotation,x:y.x,y:y.y,opacity:1,props:{url:v.props.url}};g.push(S),m.push(v.id)}n.markHistoryStoppingPoint("convert shapes to bookmark"),n.deleteShapes(m),n.createShapes(g)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(f){c()&&(l()||(o("convert-to-embed",{source:f}),n.run(()=>{const p=n.getSelectedShapeIds(),g=me(p.map(y=>n.getShape(y))),m=[],v=[];for(const y of g){if(!n.isShapeOfType(y,"bookmark"))continue;const{url:S}=y.props,b=s.getEmbedDefinition(S);if(!b||!b.definition)continue;const{width:P,height:C}=b.definition,_=new x(y.x,y.y);_.rot(-y.rotation),_.add(new x(y.props.w/2-P/2,y.props.h/2-C/2)),_.rot(y.rotation);const E={id:Ke(),type:"embed",x:_.x,y:_.y,rotation:y.rotation,props:{url:S,w:P,h:C}};m.push(E),v.push(y.id)}n.markHistoryStoppingPoint("convert shapes to embed"),n.deleteShapes(v),n.createShapes(m)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(f){if(!c()||l())return;o("duplicate-shapes",{source:f});const p=n.getInstanceState();let g,m;if(p.duplicateProps)g=p.duplicateProps.shapeIds,m=p.duplicateProps.offset;else{g=n.getSelectedShapeIds();const v=Z.Common(me(g.map(y=>n.getShapePageBounds(y))));m=n.getCameraOptions().isLocked?{x:n.options.adjacentShapeMargin,y:n.options.adjacentShapeMargin}:{x:v.width+n.options.adjacentShapeMargin,y:0}}n.markHistoryStoppingPoint("duplicate shapes"),n.duplicateShapes(g,m),p.duplicateProps&&n.updateInstanceState({duplicateProps:{...p.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(f){c()&&(l()||(o("ungroup-shapes",{source:f}),n.markHistoryStoppingPoint("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(f){if(!c()||l())return;o("group-shapes",{source:f});const p=n.getOnlySelectedShape();p&&n.isShapeOfType(p,"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(f){if(!c())return;o("remove-frame",{source:f});const p=n.getSelectedShapes();p.length>0&&p.every(g=>n.isShapeOfType(g,"frame"))&&(n.markHistoryStoppingPoint("remove-frame"),woe(n,p.map(g=>g.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(f){if(!c())return;o("fit-frame-to-content",{source:f});const p=n.getOnlySelectedShape();p&&n.isShapeOfType(p,"frame")&&(n.markHistoryStoppingPoint("fit-frame-to-content"),Poe(n,p.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(f){if(!c()||l())return;o("align-shapes",{operation:"left",source:f}),n.markHistoryStoppingPoint("align left");const p=n.getSelectedShapeIds();n.alignShapes(p,"left"),Xe(n,p)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(f){if(!c()||l())return;o("align-shapes",{operation:"center-horizontal",source:f}),n.markHistoryStoppingPoint("align center horizontal");const p=n.getSelectedShapeIds();n.alignShapes(p,"center-horizontal"),Xe(n,p)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(f){if(!c()||l())return;o("align-shapes",{operation:"right",source:f}),n.markHistoryStoppingPoint("align right");const p=n.getSelectedShapeIds();n.alignShapes(p,"right"),Xe(n,p)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(f){if(!c()||l())return;o("align-shapes",{operation:"center-vertical",source:f}),n.markHistoryStoppingPoint("align center vertical");const p=n.getSelectedShapeIds();n.alignShapes(p,"center-vertical"),Xe(n,p)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(f){if(!c()||l())return;o("align-shapes",{operation:"top",source:f}),n.markHistoryStoppingPoint("align top");const p=n.getSelectedShapeIds();n.alignShapes(p,"top"),Xe(n,p)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(f){if(!c()||l())return;o("align-shapes",{operation:"bottom",source:f}),n.markHistoryStoppingPoint("align bottom");const p=n.getSelectedShapeIds();n.alignShapes(p,"bottom"),Xe(n,p)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(f){if(!c()||l())return;o("distribute-shapes",{operation:"horizontal",source:f}),n.markHistoryStoppingPoint("distribute horizontal");const p=n.getSelectedShapeIds();n.distributeShapes(p,"horizontal"),Xe(n,p)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(f){if(!c()||l())return;o("distribute-shapes",{operation:"vertical",source:f}),n.markHistoryStoppingPoint("distribute vertical");const p=n.getSelectedShapeIds();n.distributeShapes(p,"vertical"),Xe(n,p)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(f){if(!c()||l())return;o("stretch-shapes",{operation:"horizontal",source:f}),n.markHistoryStoppingPoint("stretch horizontal");const p=n.getSelectedShapeIds();n.stretchShapes(p,"horizontal"),Xe(n,p)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(f){if(!c()||l())return;o("stretch-shapes",{operation:"vertical",source:f}),n.markHistoryStoppingPoint("stretch vertical");const p=n.getSelectedShapeIds();n.stretchShapes(p,"vertical"),Xe(n,p)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(f){if(!c()||l())return;o("flip-shapes",{operation:"horizontal",source:f}),n.markHistoryStoppingPoint("flip horizontal");const p=n.getSelectedShapeIds();n.flipShapes(p,"horizontal"),Xe(n,p)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(f){if(!c()||l())return;o("flip-shapes",{operation:"vertical",source:f}),n.markHistoryStoppingPoint("flip vertical");const p=n.getSelectedShapeIds();n.flipShapes(p,"vertical"),Xe(n,p)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(f){if(!c()||l())return;o("pack-shapes",{source:f}),n.markHistoryStoppingPoint("pack");const p=n.getSelectedShapeIds();n.packShapes(p,n.options.adjacentShapeMargin),Xe(n,p)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(f){if(!c()||l())return;o("stack-shapes",{operation:"vertical",source:f}),n.markHistoryStoppingPoint("stack-vertical");const p=n.getSelectedShapeIds();n.stackShapes(p,"vertical",16),Xe(n,p)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(f){if(!c()||l())return;o("stack-shapes",{operation:"horizontal",source:f}),n.markHistoryStoppingPoint("stack-horizontal");const p=n.getSelectedShapeIds();n.stackShapes(p,"horizontal",16),Xe(n,p)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(f){c()&&(l()||(o("reorder-shapes",{operation:"toFront",source:f}),n.markHistoryStoppingPoint("bring to front"),n.bringToFront(n.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(f){c()&&(l()||(o("reorder-shapes",{operation:"forward",source:f}),n.markHistoryStoppingPoint("bring forward"),n.bringForward(n.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(f){c()&&(l()||(o("reorder-shapes",{operation:"backward",source:f}),n.markHistoryStoppingPoint("send backward"),n.sendBackward(n.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(f){c()&&(l()||(o("reorder-shapes",{operation:"toBack",source:f}),n.markHistoryStoppingPoint("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(f){c()&&(l()||(n.markHistoryStoppingPoint("cut"),s.cut(f)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(f){c()&&(l()||s.copy(f))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(f){var p;(p=navigator.clipboard)==null||p.read().then(g=>{s.paste(g,f,f==="context-menu"?n.inputs.currentPagePoint:void 0)}).catch(()=>{s.addToast({title:s.msg("action.paste-error-title"),description:s.msg("action.paste-error-description"),severity:"error"})})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(f){n.run(()=>{l()||(o("select-all-shapes",{source:f}),n.markHistoryStoppingPoint("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(f){c()&&(l()||(o("select-none-shapes",{source:f}),n.markHistoryStoppingPoint("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(f){c()&&(l()||(o("delete-shapes",{source:f}),n.markHistoryStoppingPoint("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(f){if(!c()||l())return;o("rotate-cw",{source:f}),n.markHistoryStoppingPoint("rotate-cw");const p=n.getSelectionRotation()%(Ze/2),g=di(p,0)||di(p,Ze/2),m=n.getSelectedShapeIds();n.rotateShapesBy(m,Ze/2-(g?0:p)),Xe(n,m)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(f){if(!c()||l())return;o("rotate-ccw",{source:f}),n.markHistoryStoppingPoint("rotate-ccw");const p=n.getSelectionRotation()%(Ze/2),g=di(p,0),m=n.getSelectedShapeIds();n.rotateShapesBy(m,g?-(Ze/2):-p),Xe(n,m)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(f){o("zoom-in",{source:f}),n.zoomIn(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(f){o("zoom-out",{source:f}),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(f){o("reset-zoom",{source:f}),n.resetZoom(void 0,{animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(f){o("zoom-to-fit",{source:f}),n.zoomToFit({animation:{duration:n.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(f){c()&&(l()||(o("zoom-to-selection",{source:f}),n.zoomToSelection({animation:{duration:n.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(f){o("toggle-snap-mode",{source:f}),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(f){const p=n.user.getIsDarkMode()?"light":"dark";o("color-scheme",{source:f,value:p}),n.user.updateUserPreferences({colorScheme:p})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(f){o("toggle-wrap-mode",{source:f}),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(f){o("toggle-dynamic-size-mode",{source:f}),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(f){o("toggle-paste-at-cursor",{source:f}),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(f){o("toggle-reduce-motion",{source:f}),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(f){o("toggle-edge-scrolling",{source:f}),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(f){o("toggle-transparent",{source:f}),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(f){o("toggle-tool-lock",{source:f}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(f){o("unlock-all",{source:f});const p=[];for(const g of n.getCurrentPageShapes())g.isLocked&&p.push({id:g.id,type:g.type,isLocked:!1});p.length>0&&n.updateShapes(p)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(f){n.timers.requestAnimationFrame(()=>{n.run(()=>{o("toggle-focus-mode",{source:f}),s.clearDialogs(),s.clearToasts(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(f){o("toggle-grid-mode",{source:f}),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(f){o("toggle-debug-mode",{source:f}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(f){o("print",{source:f}),s.printSelectionOrPages()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(f){o("exit-pen-mode",{source:f}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(f){o("stop-following",{source:f}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(f){o("zoom-to-content",{source:f});const p=n.getSelectionPageBounds()??n.getCurrentPageBounds();p&&n.zoomToBounds(p,{targetZoom:Math.min(1,n.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(f){n.markHistoryStoppingPoint("locking"),o("toggle-lock",{source:f}),n.toggleLock(n.getSelectedShapeIds())}},{id:"move-to-new-page",label:"context.pages.new-page",onSelect(f){const p=yr.createId(),g=n.getSelectedShapeIds();n.run(()=>{n.markHistoryStoppingPoint("move_shapes_to_page"),n.createPage({name:s.msg("page-menu.new-page-initial-name"),id:p}),n.moveShapesToPage(g,p)}),o("move-to-new-page",{source:f})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(f){const p=mr;n.run(()=>{n.markHistoryStoppingPoint("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(p,"white"),n.setStyleForNextShapes(p,"white")}),o("set-style",{source:f,id:p.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(f){const p=da;n.run(()=>{n.markHistoryStoppingPoint("change-fill"),n.isIn("select")&&n.setStyleForSelectedShapes(p,"fill"),n.setStyleForNextShapes(p,"fill")}),o("set-style",{source:f,id:p.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async f=>{const p=n.getSelectedShapeIds();if(p.length===0)return;n.markHistoryStoppingPoint("flattening to image"),o("flatten-to-image",{source:f});const g=await qoe(n,p,n.options.flattenImageBoundsExpand);g!=null&&g.length&&n.setSelectedShapes(g)}}];r&&u.push({id:"open-cursor-chat",label:"action.open-cursor-chat",readonlyOk:!0,kbd:"/",onSelect(f){o("open-cursor-chat",{source:f}),!n.getInstanceState().isCoarsePointer&&n.timers.requestAnimationFrame(()=>{n.updateInstanceState({isChatting:!0})})}});const h=kae(u);return t?t(n,h,s):h},[s,n,o,t,i,r]);return d.jsx(z$.Provider,{value:a,children:e})}function Ea(){const t=w.useContext(z$);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Yu(t,e){return t?typeof t=="string"?t:e?t[e]??t.default:void 0:void 0}function wr(){const t=Ti();return U("isReadonlyMode",()=>!!(t!=null&&t.getIsReadonly()),[t])}const Mae=Ge.isDarwin?"⌘":"Ctrl",Aae=Ge.isDarwin?"⌥":"Alt";function B$(t){return t===","?[","]:t.split(",")[0].split("").map(e=>{const n=e.replace(/\$/g,Mae).replace(/\?/g,Aae).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function Yx(t){return"— "+B$(t).join(" ")}function hu({children:t,visibleOnMobileLayout:e=!1}){const n=An();return!e&&n<St.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:B$(t).map((r,s)=>d.jsx("span",{children:r},s))})}const U$=w.createContext(null);function mm(){const t=w.useContext(U$);if(!t)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return t}function Fr({type:t,sourceId:e,children:n}){return d.jsx(U$.Provider,{value:{type:t,sourceId:e},children:n})}function ym({id:t,kbd:e,label:n,readonlyOk:r,onSelect:s,toggle:o=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=mm(),u=wr(),h=Ee();if(u&&!r)return null;const f=Yu(n,l),p=f?h(f):void 0;switch(l){case"menu":return d.jsxs(yoe,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:p,onSelect:g=>{s==null||s(c),xe(g)},disabled:i,checked:a,children:[d.jsx(zs,{small:!0,icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),e&&d.jsx(hu,{children:e})]});case"context-menu":return d.jsxs(Vse,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:p,onSelect:g=>{s(c),xe(g)},disabled:i,checked:a,children:[d.jsx(zs,{small:!0,icon:o?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),e&&d.jsx(hu,{children:e})]},t);default:return null}}function Mo(t,e){const n=Ti(),r=w.useCallback(i=>{i&&(n==null||n.complete()),e==null||e(i)},[n,e]),s=Jt(),o=w.useCallback(i=>{s(i,{source:"unknown",id:t})},[t,s]);return ate(n?`${t}-${n.contextId}`:t,r,o)}function ma({id:t,children:e,modal:n=!1,debugOpen:r=!1}){const[s,o]=Mo(t);return d.jsx(i1,{open:r||s,dir:"ltr",modal:n,onOpenChange:o,children:e})}function ya({children:t,...e}){return d.jsx(a1,{dir:"ltr",asChild:!0,onTouchEnd:n=>xe(n),...e,children:t})}function Sa({className:t,side:e="bottom",align:n="start",sideOffset:r=8,alignOffset:s=8,children:o}){const i=Tt();return d.jsx(lm,{container:i,children:d.jsx(l1,{className:ce("tlui-menu",t),side:e,sideOffset:r,align:n,alignOffset:s,collisionPadding:4,children:o})})}function jae({id:t,children:e}){const[n,r]=Mo(t);return d.jsx(Soe,{open:n,onOpenChange:r,children:e})}function Oae({id:t,label:e,title:n,disabled:r}){return d.jsx(voe,{dir:"ltr",asChild:!0,disabled:r,children:d.jsxs(ue,{"data-testid":t,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:n,children:[d.jsx(bt,{children:e}),d.jsx(be,{icon:"chevron-right",small:!0})]})})}function Dae({id:t,alignOffset:e=-1,sideOffset:n=-6,size:r="small",children:s}){const o=Tt();return d.jsx(lm,{container:o,children:d.jsx(xoe,{"data-testid":t,className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:n,collisionPadding:4,"data-size":r,children:s})})}function Rae({children:t}){return d.jsx(goe,{dir:"ltr",className:"tlui-menu__group",children:t})}function Xu({noClose:t,children:e}){return d.jsx(moe,{dir:"ltr",asChild:!0,onClick:t?xe:void 0,children:e})}function ve({id:t,label:e,children:n}){const{type:r,sourceId:s}=mm(),o=Ee(),i=Yu(e,r),a=i?o(i):void 0;switch(r){case"panel":return d.jsx("div",{className:"tlui-menu__group","data-testid":`${s}-group.${t}`,children:n});case"menu":return d.jsx(Rae,{"data-testid":`${s}-group.${t}`,children:n});case"context-menu":return d.jsx(ML,{dir:"ltr",className:"tlui-menu__group","data-testid":`${s}-group.${t}`,children:n});case"keyboard-shortcuts":return d.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${s}-group.${t}`,children:[d.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),d.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:n})]});default:return n}}function Jn({id:t,disabled:e=!1,label:n,size:r="small",children:s}){const{type:o,sourceId:i}=mm(),a=Tt(),l=Ee(),c=n?typeof n=="string"?n:n[o]??n.default:void 0,u=c?l(c):void 0;switch(o){case"menu":return d.jsxs(jae,{id:`${i}-sub.${t}`,children:[d.jsx(Oae,{id:`${i}-sub.${t}-button`,disabled:e,label:u,title:u}),d.jsx(Dae,{id:`${i}-sub.${t}-content`,size:r,children:s})]});case"context-menu":return e?null:d.jsxs(Lae,{id:`${i}-sub.${t}`,children:[d.jsx(DL,{dir:"ltr",disabled:e,asChild:!0,children:d.jsxs(ue,{"data-testid":`${i}-sub.${t}-button`,type:"menu",className:"tlui-menu__submenu__trigger",children:[d.jsx(bt,{children:u}),d.jsx(be,{icon:"chevron-right",small:!0})]})}),d.jsx(s1,{container:a,children:d.jsx(RL,{"data-testid":`${i}-sub.${t}-content`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:s})})]});default:return s}}function Lae({id:t,children:e}){const[n,r]=Mo(t);return d.jsx(OL,{open:n,onOpenChange:r,children:e})}const $ae=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function Fae(){const t=z(),e=Jt(),n=U("colorScheme",()=>t.user.getUserPreferences().colorScheme??(t.user.getIsDarkMode()?"dark":"light"),[t]);return d.jsx(Jn,{id:"help menu color-scheme",label:"menu.theme",children:d.jsx(ve,{id:"theme",children:$ae.map(({colorScheme:r,label:s})=>d.jsx(ym,{id:`color-scheme-${r}`,label:s,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({colorScheme:r}),e("color-scheme",{source:"menu",value:r})}},r))})})}const Nae=({id:t,component:e,onClose:n})=>{const{removeDialog:r}=Id(),s=Tt(),o=w.useCallback(i=>{if(!i){if(n)try{n()}catch(a){console.warn(a)}r(t)}},[t,n,r]);return d.jsx(Foe,{onOpenChange:o,defaultOpen:!0,children:d.jsx(Noe,{container:s,children:d.jsx(zoe,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&o(!1)},children:d.jsx(Boe,{dir:"ltr",className:"tlui-dialog__content","aria-describedby":void 0,children:d.jsx(e,{onClose:()=>o(!1)})})})})})},zae=w.memo(function(){const{dialogs:e}=Id();return U("dialogs",()=>e.get(),[e]).map(r=>d.jsx(Nae,{...r},r.id))}),Bae=4e3,Uae={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function Hae({toast:t}){const{removeToast:e}=To(),n=Ee(),r=i=>{i||e(t.id)},s=t.actions&&t.actions.length>0,o=t.icon||t.severity&&Uae[t.severity];return d.jsxs(Sie,{onOpenChange:r,className:"tlui-toast__container",duration:t.keepOpen?1/0:Bae,"data-severity":t.severity,children:[o&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(zs,{icon:o})}),d.jsxs("div",{className:"tlui-toast__main","data-title":!!t.title,"data-description":!!t.description,"data-actions":!!t.actions,children:[d.jsxs("div",{className:"tlui-toast__content",children:[t.title&&d.jsx(vie,{className:"tlui-toast__title",children:t.title}),t.description&&d.jsx(xie,{className:"tlui-toast__description",children:t.description})]}),t.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[t.actions.map((i,a)=>d.jsx(wie,{altText:i.label,asChild:!0,onClick:i.onClick,children:d.jsx(ue,{type:i.type,children:d.jsx(bt,{children:i.label})})},a)),d.jsx(hE,{asChild:!0,children:d.jsx(ue,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:d.jsx(bt,{children:t.closeLabel??n("toast.close")})})})]})]}),!s&&d.jsx(hE,{asChild:!0,children:d.jsx(ue,{type:"normal",className:"tlui-toast__close",children:d.jsx(bt,{children:t.closeLabel??n("toast.close")})})})]})}const Kae=w.memo(function(){const{toasts:e}=To(),n=U("toasts",()=>e.get(),[]);return d.jsxs(d.Fragment,{children:[n.map(r=>d.jsx(Hae,{toast:r},r.id)),d.jsx(v$,{className:"tlui-toast__viewport"})]})});function fs({actionId:t="",...e}){const r=Ea()[t];return r?d.jsx(ym,{...r,...e}):null}function SE(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 Kt({disabled:t=!1,spinner:e=!1,readonlyOk:n=!1,id:r,kbd:s,label:o,icon:i,onSelect:a,noClose:l,isSelected:c}){const{type:u,sourceId:h}=mm(),f=Ee(),[p,g]=w.useState(!1);if(wr()&&!n)return null;const v=Yu(o,u),y=s?Yx(s):void 0,S=v?f(v):void 0,b=S&&y?`${S} ${y}`:S;switch(u){case"menu":return d.jsx(Xu,{children:d.jsxs(ue,{type:"menu","data-testid":`${h}.${r}`,disabled:t,title:b,onClick:P=>{l&&xe(P),p?g(!1):a(h)},children:[d.jsx(bt,{children:S}),s&&d.jsx(hu,{children:s})]})});case"context-menu":return t?null:d.jsxs(AL,{dir:"ltr",title:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:P=>{l&&xe(P),p?g(!1):a(h)},children:[d.jsx("span",{className:"tlui-button__label",draggable:!1,children:S}),s&&d.jsx(hu,{children:s}),e&&d.jsx(SE,{})]});case"panel":return d.jsxs(ue,{"data-testid":`${h}.${r}`,type:"menu",title:b,disabled:t,onClick:()=>a(h),children:[d.jsx(bt,{children:S}),e?d.jsx(SE,{}):i&&d.jsx(be,{icon:i})]});case"small-icons":case"icons":return d.jsx(ue,{"data-testid":`${h}.${r}`,type:"icon",title:b,disabled:t,onClick:()=>a(h),children:d.jsx(be,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return s?d.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${h}.${r}`,children:[d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:S}),d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:d.jsx(hu,{visibleOnMobileLayout:!0,children:s})})]}):(console.warn(`Menu item '${o}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return d.jsxs(ue,{type:"low",onClick:()=>a(h),children:[d.jsx(be,{icon:i}),d.jsx(bt,{children:S})]});case"toolbar":return d.jsx(ue,{type:"tool","data-testid":`tools.${r}`,"aria-label":v,"data-value":r,onClick:()=>a("toolbar"),title:b,disabled:t,onTouchStart:P=>{xe(P),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:d.jsx(be,{icon:i})});case"toolbar-overflow":return d.jsx(Xu,{"aria-label":o,children:d.jsx(ue,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:b,disabled:t,role:"radio","aria-checked":c?"true":"false","data-value":r,children:d.jsx(be,{icon:i})})});default:throw Ot(u)}}function W({actionId:t="",...e}){const r=Ea()[t];return r?d.jsx(Kt,{...r,...e}):null}const H$=w.createContext(null);function Wae({overrides:t,children:e}){const n=z(),r=Jt(),s=b1(),o=w.useMemo(()=>{const i=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(l){if(n.isIn("select")){const c=n.root.getCurrent();c.exit({},c.id),c.enter({},c.id)}n.setCurrentTool("select"),r("select-tool",{source:l,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(l){n.setCurrentTool("hand"),r("select-tool",{source:l,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(l){n.setCurrentTool("eraser"),r("select-tool",{source:l,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(l){n.setCurrentTool("draw"),r("select-tool",{source:l,id:"draw"})}},...[...Jr.values].map(l=>({id:l,label:`tool.${l}`,meta:{geo:l},kbd:l==="rectangle"?"r":l==="ellipse"?"o":void 0,icon:"geo-"+l,onSelect(c){n.run(()=>{n.setStyleForNextShapes(Jr,l),n.setCurrentTool("geo"),r("select-tool",{source:c,id:`geo-${l}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(l){n.setCurrentTool("arrow"),r("select-tool",{source:l,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(l){n.setCurrentTool("line"),r("select-tool",{source:l,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(l){n.setCurrentTool("frame"),r("select-tool",{source:l,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(l){n.setCurrentTool("text"),r("select-tool",{source:l,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(l){s.insertMedia(),r("select-tool",{source:l,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(l){n.setCurrentTool("note"),r("select-tool",{source:l,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(l){n.setCurrentTool("laser"),r("select-tool",{source:l,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(l){s.addDialog({component:f$}),r("select-tool",{source:l,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(l){n.setCurrentTool("highlight"),r("select-tool",{source:l,id:"highlight"})}}];i.push();const a=Object.fromEntries(i.map(l=>[l.id,l]));return t?t(n,a,s):a},[t,n,r,s]);return d.jsx(H$.Provider,{value:o,children:e})}function P1(){const t=w.useContext(H$);if(!t)throw new Error("useTools must be used within a ToolProvider");return t}function Ln({toolId:t="",...e}){const r=P1()[t];return r?d.jsx(Kt,{...r,...e}):null}function Gae({children:t}){const e=z();return U("shouldDisplayHandles",()=>{if(e.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(e.isInAny("select.editing_shape")){const r=e.getOnlySelectedShape();return r&&e.isShapeOfType(r,"note")}return!1},[e])?d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:t}):null}const{PI:Vae}=Math,Cl=Vae+1e-4;function K$(t,e={}){const{size:n=16,smoothing:r=.5}=e;if(t.length===0||n<=0)return{left:[],right:[]};const s=t[0],o=t[t.length-1],i=o.runningLength,a=Math.pow(n*r,2),l=[],c=[];let u=t[0].vector,h=t[0].point,f=h,p=h,g=f,m=!1,v;for(let y=0;y<t.length;y++){v=t[y];const{point:S,vector:b}=t[y],P=v.vector.dpr(u),C=(y<t.length-1?t[y+1]:t[y]).vector,_=y<t.length-1?C.dpr(v.vector):1,E=P<0&&!m,k=_!==null&&_<.2;if(E||k){if(_>-.62&&i-v.runningLength>v.radius){const T=u.clone().mul(v.radius);u.clone().cpr(C)<0?(p=x.Add(S,T),g=x.Sub(S,T)):(p=x.Sub(S,T),g=x.Add(S,T)),l.push(p),c.push(g)}else{const T=u.clone().mul(v.radius).per(),j=x.Sub(v.input,T);for(let L=1/13,M=0;M<1;M+=L)p=x.RotWith(j,v.input,Cl*M),l.push(p),g=x.RotWith(j,v.input,Cl+Cl*-M),c.push(g)}h=p,f=g,k&&(m=!0);continue}if(m=!1,v===s||v===o){const T=x.Per(b).mul(v.radius);l.push(x.Sub(S,T)),c.push(x.Add(S,T));continue}const D=x.Lrp(C,b,_).per().mul(v.radius);p=x.Sub(S,D),(y<=1||x.Dist2(h,p)>a)&&(l.push(p),h=p),g=x.Add(S,D),(y<=1||x.Dist2(f,g)>a)&&(c.push(g),f=g),u=b}return{left:l,right:c}}function C1(t,e={}){const{size:n=16,start:r={},end:s={},last:o=!1}=e,{cap:i=!0}=r,{cap:a=!0}=s;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,f=s.taper===!1?0:s.taper===!0?Math.max(n,u):s.taper,{left:p,right:g}=K$(t,e),m=l.point,v=t.length>1?t[t.length-1].point:x.AddXY(l.point,1,1);if(t.length===1&&(!(h||f)||o)){const P=x.Add(m,x.Sub(m,v).uni().per().mul(-l.radius)),C=[];for(let _=1/13,E=_;E<=1;E+=_)C.push(x.RotWith(P,m,Cl*2*E));return C}const y=[];if(!(h||f&&t.length===1))if(i)for(let P=1/8,C=P;C<=1;C+=P){const _=x.RotWith(g[0],m,Cl*C);y.push(_)}else{const P=x.Sub(p[0],g[0]),C=x.Mul(P,.5),_=x.Mul(P,.51);y.push(x.Sub(m,C),x.Sub(m,_),x.Add(m,_),x.Add(m,C))}const S=[],b=c.vector.clone().per().neg();if(f||h&&t.length===1)S.push(v);else if(a){const P=x.Add(v,x.Mul(b,c.radius));for(let C=1/29,_=C;_<1;_+=C)S.push(x.RotWith(P,v,Cl*3*_))}else S.push(x.Add(v,x.Mul(b,c.radius)),x.Add(v,x.Mul(b,c.radius*.99)),x.Sub(v,x.Mul(b,c.radius*.99)),x.Sub(v,x.Mul(b,c.radius)));return p.concat(S,g.reverse(),y)}const Yae=.025,Xae=.01;function Bs(t,e={}){var v;const{streamline:n=.5,size:r=16,simulatePressure:s=!1}=e;if(t.length===0)return[];const o=.15+(1-n)*.85;let i=t.map(x.From),a=0;if(!s){let y=i[0];for(;y&&!(y.z>=Yae);)i.shift(),y=i[0]}if(!s){let y=i[i.length-1];for(;y&&!(y.z>=Xae);)i.pop(),y=i[i.length-1]}if(i.length===0)return[{point:x.From(t[0]),input:x.From(t[0]),pressure:s?.5:.15,vector:new x(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(x.Dist2(l,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(x.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=e.last||!e.simulatePressure||i.length>1&&x.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&e.simulatePressure){const y=i[1];i=i.slice(0,-1);for(let S=1;S<5;S++){const b=x.Lrp(i[0],y,S/4);b.z=(i[0].z+(y.z-i[0].z))*S/4,i.push(b)}}const h=[{point:i[0],input:i[0],pressure:s?.5:i[0].z,vector:new x(1,1),distance:0,runningLength:0,radius:1}];let f=0,p=h[0],g,m;u&&n>0&&i.push(i[i.length-1].clone());for(let y=1,S=i.length;y<S;y++)g=!o||e.last&&y===S-1?i[y].clone():i[y].clone().lrp(p.point,1-o),!p.point.equals(g)&&(m=x.Dist(g,p.point),f+=m,!(y<4&&f<r)&&(p={input:i[y],point:g,pressure:s?.5:i[y].z,vector:x.Sub(p.point,g).uni(),distance:m,runningLength:f,radius:1},h.push(p)));if((v=h[1])!=null&&v.vector&&(h[0].vector=h[1].vector.clone()),f<1){const y=Math.max(.5,...h.map(S=>S.pressure));h.forEach(S=>S.pressure=y)}return h}const{min:zo}=Math,SS=.275;function Sm(t,e){const{size:n=16,thinning:r=.5,simulatePressure:s=!0,easing:o=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,f=t[0].pressure,p;if(!s&&u<n){const v=t.reduce((y,S)=>Math.max(y,S.pressure),.5);return t.forEach(y=>{y.pressure=v,y.radius=n*o(.5-r*(.5-y.pressure))}),t}else{let v;for(let y=0,S=t.length;y<S&&(p=t[y],!(p.runningLength>n*5));y++){const b=zo(1,p.distance/n);if(s){const P=zo(1,1-b);v=zo(1,f+(P-f)*(b*SS))}else v=zo(1,f+(p.pressure-f)*.5);f=f+(v-f)*.5}for(let y=0;y<t.length;y++){if(p=t[y],r){let{pressure:S}=p;const b=zo(1,p.distance/n);if(s){const P=zo(1,1-b);S=zo(1,f+(P-f)*(b*SS))}else S=zo(1,f+(S-f)*(b*SS));p.radius=n*o(.5-r*(.5-S)),f=S}else p.radius=n/2;h===void 0&&(h=p.radius)}}const g=i.taper===!1?0:i.taper===!0?Math.max(n,u):i.taper,m=a.taper===!1?0:a.taper===!0?Math.max(n,u):a.taper;if(g||m)for(let v=0;v<t.length;v++){p=t[v];const{runningLength:y}=p,S=y<g?l(y/g):1,b=u-y<m?c((u-y)/m):1;p.radius=Math.max(.01,p.radius*Math.min(S,b))}return t}function qae(t,e={}){return C1(Sm(Bs(t,e),e),e)}function vE({scribble:t,zoom:e,color:n,opacity:r,className:s}){if(!t.points.length)return null;const o=qae(t.points,{size:t.size/e,start:{taper:t.taper,easing:Dt.linear},last:t.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(o.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=gb(o);return d.jsx("svg",{className:s&&ce("tl-overlays__item",s),children:d.jsx("path",{className:"tl-scribble",d:i,fill:n??`var(--color-${t.color})`,opacity:r??t.opacity})})}const Zae=({bounds:t,rotation:e})=>{const n=z();return U("should display",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[n])?d.jsx(Cj,{bounds:t,rotation:e}):null};function Qae({size:t,width:e,height:n,hideAlternateHandles:r}){const s=N(t/3),o=s/2;return d.jsxs("svg",{className:"tl-overlays__item",children:[d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
336
|
+
${N(0-o)},${N(t)}
|
|
337
|
+
${N(0-o)},${N(0-o)}
|
|
338
|
+
${N(t)},${N(0-o)}`,strokeWidth:s,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(e/2-t),y1:N(0-o),x2:N(e/2+t),y2:N(0-o),strokeWidth:s,"data-testid":"selection.crop.top","aria-label":"top handle"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
339
|
+
${N(e-t)},${N(0-o)}
|
|
340
|
+
${N(e+o)},${N(0-o)}
|
|
341
|
+
${N(e+o)},${N(t)}`,strokeWidth:s,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(e+o),y1:N(n/2-t),x2:N(e+o),y2:N(n/2+t),strokeWidth:s,"data-testid":"selection.crop.right","aria-label":"right handle"}),d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
342
|
+
${N(e+o)},${N(n-t)}
|
|
343
|
+
${N(e+o)},${N(n+o)}
|
|
344
|
+
${N(e-t)},${N(n+o)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(e/2-t),y1:N(n+o),x2:N(e/2+t),y2:N(n+o),strokeWidth:s,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
345
|
+
${N(0+t)},${N(n+o)}
|
|
346
|
+
${N(0-o)},${N(n+o)}
|
|
347
|
+
${N(0-o)},${N(n-t)}`,strokeWidth:s,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(0-o),y1:N(n/2-t),x2:N(0-o),y2:N(n/2+t),strokeWidth:s,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const Jae=Zt(function({bounds:e,rotation:n}){const r=z(),s=w.useRef(null),o=wr(),i=ws("top"),a=ws("right"),l=ws("bottom"),c=ws("left"),u=ws("top_left"),h=ws("top_right"),f=ws("bottom_right"),p=ws("bottom_left"),g=r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,v=r.getOnlySelectedShape(),y=v&&r.isShapeOrAncestorLocked(v),S=v?r.getShapeUtil(v).expandSelectionOutlinePx(v):0,b=S instanceof Z?e.clone().expand(S).zeroFix():e.clone().expandBy(S).zeroFix();if(ec(s,e==null?void 0:e.x,e==null?void 0:e.y,1,r.getSelectionRotation(),{x:b.x-e.x,y:b.y-e.y}),v&&r.isShapeHidden(v))return null;const P=r.getZoomLevel(),C=r.getInstanceState().isChangingStyle,_=b.width,E=b.height,k=8/P,D=_<k*2,T=E<k*2,j=_<k*4,L=E<k*4,M=_<k*5,O=E<k*5,F=m?1.75:1,B=6/P*F,K=(j?B/2:B)*(F*.75),R=(L?B/2:B)*(F*.75),H=(v?!r.getShapeUtil(v).hideSelectionBoundsFg(v):!0)&&!C;let X=H&&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")||H&&r.isIn("select.resizing")&&v&&r.isShapeOfType(v,"text");v&&X&&Ge.isFirefox&&r.isShapeOfType(v,"embed")&&(X=!1);const te=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!C&&!o,le=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!C&&!o,de=!m&&!(D||T)&&(le||te)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!y,Me=m&&(!j||!L)&&(le||te)&&(v?!r.getShapeUtil(v).hideRotateHandle(v):!0)&&!y,oe=le&&(v?r.getShapeUtil(v).canResize(v)&&!r.getShapeUtil(v).hideResizeHandles(v):!0)&&!te&&!y,Ue=D||T,Ne=D&&T,lt=M||O,$e=oe||te,Ye=!de,We=!le||!Me,er=!le||!$e,$t=!le||!$e||Ue,On=!le||!$e||Ue,Mt=!le||!$e||Ne&&!te;let Ft=!0,jo=!0;if(te)Ft=lt,jo=lt;else if(oe){Ft=Ue||Ne||m;const km=m&&v&&v.type==="text";jo=Ft&&!km}const Ys=Math.min(24/P,E-R*3),Oo=le&&m&&v&&r.isShapeOfType(v,"text")&&Ys*P>=4;return d.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsxs("g",{ref:s,children:[X&&d.jsx("rect",{className:"tl-selection__fg__outline",width:N(_),height:N(E)}),d.jsx(Dh,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:B,corner:"top_left_rotate",cursor:g?nr("nwse-rotate",n):void 0,isHidden:Ye}),d.jsx(Dh,{"data-testid":"selection.rotate.top-right",cx:_+B*3,cy:0,targetSize:B,corner:"top_right_rotate",cursor:g?nr("nesw-rotate",n):void 0,isHidden:Ye}),d.jsx(Dh,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:E+B*3,targetSize:B,corner:"bottom_left_rotate",cursor:g?nr("swne-rotate",n):void 0,isHidden:Ye}),d.jsx(Dh,{"data-testid":"selection.rotate.bottom-right",cx:_+B*3,cy:E+B*3,targetSize:B,corner:"bottom_right_rotate",cursor:g?nr("senw-rotate",n):void 0,isHidden:Ye}),d.jsx(tle,{"data-testid":"selection.rotate.mobile",cx:j?-B*1.5:_/2,cy:j?E/2:-B*1.5,size:k,isHidden:We}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Ft}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:N(0-(L?R*2:R)),width:N(_),height:N(Math.max(1,R*2)),style:g?{cursor:nr("ns-resize",n)}:void 0,...i}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":jo}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:N(_-(j?0:K)),y:0,height:N(E),width:N(Math.max(1,K*2)),style:g?{cursor:nr("ew-resize",n)}:void 0,...a}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Ft}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:N(E-(L?0:R)),width:N(_),height:N(Math.max(1,R*2)),style:g?{cursor:nr("ns-resize",n)}:void 0,...l}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":jo}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:N(0-(j?K*2:K)),y:0,height:N(E),width:N(Math.max(1,K*2)),style:g?{cursor:nr("ew-resize",n)}:void 0,...c}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":er}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:N(0-(j?K*2:K*1.5)),y:N(0-(L?R*2:R*1.5)),width:N(K*3),height:N(R*3),style:g?{cursor:nr("nwse-resize",n)}:void 0,...u}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":$t}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:N(_-(j?0:K*1.5)),y:N(0-(L?R*2:R*1.5)),width:N(K*3),height:N(R*3),style:g?{cursor:nr("nesw-resize",n)}:void 0,...h}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Mt}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:N(_-(j?K:K*1.5)),y:N(E-(L?R:R*1.5)),width:N(K*3),height:N(R*3),style:g?{cursor:nr("nwse-resize",n)}:void 0,...f}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":On}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:N(0-(j?K*3:K*1.5)),y:N(E-(L?0:R*1.5)),width:N(K*3),height:N(R*3),style:g?{cursor:nr("nesw-resize",n)}:void 0,...p}),oe&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.resize.top-left",className:ce("tl-corner-handle",{"tl-hidden":er}),"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:ce("tl-corner-handle",{"tl-hidden":$t}),"aria-label":"top_right handle",x:N(_-k/2),y:N(0-k/2),width:N(k),height:N(k)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ce("tl-corner-handle",{"tl-hidden":Mt}),"aria-label":"bottom_right handle",x:N(_-k/2),y:N(E-k/2),width:N(k),height:N(k)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ce("tl-corner-handle",{"tl-hidden":On}),"aria-label":"bottom_left handle",x:N(0-k/2),y:N(E-k/2),width:N(k),height:N(k)})]}),Oo&&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(E/2-Ys/2),rx:k/4,width:N(k/2),height:N(Ys)}),d.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:k/4,x:N(_-k/4),y:N(E/2-Ys/2),width:N(k/2),height:N(Ys)})]}),te&&d.jsx(Qae,{size:k,width:_,height:E,hideAlternateHandles:lt})]})})}),Dh=function({cx:e,cy:n,targetSize:r,corner:s,cursor:o,isHidden:i,"data-testid":a}){const l=ws(s);return d.jsx("rect",{className:ce("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${s} 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:o,...l})},ele=Math.sqrt(Math.PI),tle=function({cx:e,cy:n,size:r,isHidden:s,"data-testid":o}){const i=ws("mobile_rotate"),a=z(),l=U("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return d.jsxs("g",{children:[d.jsx("circle",{"data-testid":o,pointerEvents:"all",className:ce("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":s}),cx:e,cy:n,r:c,...i}),d.jsx("circle",{className:ce("tl-mobile-rotate__fg",{"tl-hidden":s}),cx:e,cy:n,r:r/ele})]})};function nle(){const t=z();return U("is in a valid select state",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle"),[t])?d.jsx(_j,{}):null}function Xx(t,e,n){const{arrowheadStart:r,arrowheadEnd:s}=e.props,o=ul(t,e,n),i=o.start.clone(),a=o.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=Gp(t,e,"start"),h=Gp(t,e,"end"),f=t.getShapePageTransform(e);xE(a,o.start,f,h),xE(i,o.end,f,u);let p=0,g=0,m=0,v=0,y=fu*e.props.scale;const S=u&&h&&u.shape===h.shape,b=u&&h?_1(t,u.shape.id,h.shape.id):"safe";b==="safe"&&u&&h&&!S&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(fu*e.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(fu*e.props.scale))));const P=x.Sub(a,i),C=x.Len(P)?P.uni():x.From(P),_=!x.Equals(C,c);S||(b!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(m=ks[e.props.size]/2+("size"in u.shape.props?ks[u.shape.props.size]/2:0),p=(Vp+m)*e.props.scale,y+=m*e.props.scale),b!=="end-contains-start"&&h&&s!=="none"&&!h.isExact&&(v=ks[e.props.size]/2+("size"in h.shape.props?ks[h.shape.props.size]/2:0),g=(Vp+v)*e.props.scale,y+=v*e.props.scale));const E=i.clone().add(C.clone().mul(p*(_?-1:1))),k=a.clone().sub(C.clone().mul(g*(_?-1:1)));x.DistMin(E,k,y)&&(p!==0&&g!==0?(p*=-1.5,g*=-1.5):p!==0?p*=-1:g!==0&&(g*=-1)),i.add(C.clone().mul(p*(_?-1:1))),a.sub(C.clone().mul(g*(_?-1:1))),_?(u&&h&&a.setTo(x.Add(i,C.clone().mul(-10*e.props.scale))),l.setTo(x.Med(o.start,o.end))):l.setTo(x.Med(i,a));const D=x.Dist(i,a);return{bindings:n,isStraight:!0,start:{handle:o.start,point:i,arrowhead:e.props.arrowheadStart},end:{handle:o.end,point:a,arrowhead:e.props.arrowheadEnd},middle:l,isValid:D>0,length:D}}function xE(t,e,n,r){if(r===void 0||r.isExact)return;const s=q.applyToPoint(n,e),o=q.applyToPoint(n,t),i=q.applyToPoint(q.Inverse(r.transform),s),a=q.applyToPoint(q.Inverse(r.transform),o),l=r.isClosed,u=(l?xb:KZ)(i,a,r.outline);let h;if(u!==null&&(h=u.sort((g,m)=>x.Dist2(g,i)-x.Dist2(m,i))[0]??(l?void 0:a)),h===void 0)return;const f=q.applyToPoint(r.transform,h),p=q.applyToPoint(q.Inverse(n),f);t.setTo(p),r.didIntersect=!0}function rle(t,e,n){const{arrowheadEnd:r,arrowheadStart:s}=e.props,o=e.props.bend;if(Math.abs(o)>Math.abs(e.props.bend*(lle*e.props.scale)))return Xx(t,e,n);const i=ul(t,e,n),a=x.Med(i.start,i.end),l=x.Sub(i.end,i.start),c=x.Len(l)?l.uni():x.From(l),u=x.Add(a,c.per().mul(-o)),h=Gp(t,e,"start"),f=Gp(t,e,"end"),p=i.start.clone(),g=i.end.clone(),m=u.clone();if(x.Equals(p,g))return{bindings:n,isStraight:!0,start:{handle:p,point:p,arrowhead:e.props.arrowheadStart},end:{handle:g,point:g,arrowhead:e.props.arrowheadEnd},middle:m,isValid:!1,length:0};const v=e.props.bend<0,y=v?cd:sj,S=wE(p,g,m),b=x.Angle(S.center,p),P=x.Angle(S.center,g),C=y(b,P);if(S.length===0||S.size===0||!Q_(S.length)||!Q_(S.size))return Xx(t,e,n);const _=p.clone(),E=g.clone(),k=m.clone(),D=t.getShapePageTransform(e);let T=0,j=0,L=fu*e.props.scale;if(h&&!h.isExact){const X=q.applyToPoint(D,_),te=q.applyToPoint(D,S.center),le=q.applyToPoint(D,E),de=q.Inverse(h.transform),Me=q.applyToPoint(de,X),oe=q.applyToPoint(de,te),Ue=q.applyToPoint(de,le),{isClosed:Ne}=h,lt=Ne?Cx:vI;let $e,Ye=lt(oe,S.radius,h.outline);if(Ye){const We=oe.angle(Me),er=oe.angle(Ue),$t=y(We,er);Ye=Ye.filter(Mt=>y(We,oe.angle(Mt))<=$t);const On=$t*.25;Ye.sort(Ne?(Mt,Ft)=>Math.abs(y(We,oe.angle(Mt))-On)<Math.abs(y(We,oe.angle(Ft))-On)?-1:1:(Mt,Ft)=>y(We,oe.angle(Mt))<y(We,oe.angle(Ft))?-1:1),$e=Ye[0]??(Ne?void 0:Me)}else $e=Ne?void 0:Me;if($e&&(_.setTo(t.getPointInShapeSpace(e,q.applyToPoint(h.transform,$e))),h.didIntersect=!0,s!=="none")){const We=ks[e.props.size]/2+("size"in h.shape.props?ks[h.shape.props.size]/2:0);T=(Vp+We)*e.props.scale,L+=We*e.props.scale}}if(f&&!f.isExact){const X=q.applyToPoint(D,_),te=q.applyToPoint(D,E),le=q.applyToPoint(D,S.center),de=q.Inverse(f.transform),Me=q.applyToPoint(de,X),oe=q.applyToPoint(de,le),Ue=q.applyToPoint(de,te),Ne=f.isClosed,lt=Ne?Cx:vI;let $e,Ye=lt(oe,S.radius,f.outline);if(Ye){const We=oe.angle(Me),er=oe.angle(Ue),$t=y(We,er),On=$t*.75;Ye=Ye.filter(Mt=>y(We,oe.angle(Mt))<=$t),Ye.sort(Ne?(Mt,Ft)=>Math.abs(y(We,oe.angle(Mt))-On)<Math.abs(y(We,oe.angle(Ft))-On)?-1:1:(Mt,Ft)=>y(We,oe.angle(Mt))<y(We,oe.angle(Ft))?-1:1),Ye[0]?$e=Ye[0]:$e=Ne?void 0:Ue}else $e=Ne?void 0:Ue;if($e&&(E.setTo(t.getPointInShapeSpace(e,q.applyToPoint(f.transform,$e))),f.didIntersect=!0,r!=="none")){const We=ks[e.props.size]/2+("size"in f.shape.props?ks[f.shape.props.size]/2:0);j=(Vp+We)*e.props.scale,L+=We*e.props.scale}}let M=x.Angle(S.center,_),O=x.Angle(S.center,E),F=y(M,O),B=F*S.radius;const K=_.clone(),R=E.clone();if(T!==0&&K.setTo(S.center).add(x.FromAngle(M+F*(T/B*(v?1:-1))).mul(S.radius)),j!==0&&R.setTo(S.center).add(x.FromAngle(O+F*(j/B*(v?-1:1))).mul(S.radius)),x.DistMin(K,R,L)&&(T!==0&&j!==0?(T*=-1.5,j*=-1.5):T!==0?T*=-2:j!==0&&(j*=-2)),T!==0&&_.setTo(S.center).add(x.FromAngle(M+F*(T/B*(v?1:-1))).mul(S.radius)),j!==0&&E.setTo(S.center).add(x.FromAngle(O+F*(j/B*(v?-1:1))).mul(S.radius)),h&&f&&!h.isExact&&!f.isExact){M=x.Angle(S.center,_),O=x.Angle(S.center,E),F=y(M,O),B=F*S.radius;const X=_1(t,h.shape.id,f.shape.id);X==="double-bound"&&B<30?(_.setTo(p),E.setTo(g),k.setTo(m)):X==="safe"&&(h&&!h.didIntersect&&_.setTo(p),(f&&!f.didIntersect||y(b,M)>y(b,O))&&E.setTo(S.center).add(x.FromAngle(M+F*(Math.min(.9,fu*e.props.scale/B)*(v?1:-1))).mul(S.radius)))}sle(S.center,S.radius,_,E,k,C,v),_.equals(E)&&(_.setTo(k.clone().addXY(1,1)),E.setTo(k.clone().subXY(1,1))),p.setTo(_),g.setTo(E),m.setTo(k);const H=wE(p,g,m);return{bindings:n,isStraight:!1,start:{point:p,handle:i.start,arrowhead:e.props.arrowheadStart},end:{point:g,handle:i.end,arrowhead:e.props.arrowheadEnd},middle:m,handleArc:S,bodyArc:H,isValid:H.length!==0&&isFinite(H.center.x)&&isFinite(H.center.y)}}function wE(t,e,n){const r=db(t,e,n)??x.Med(t,e),s=x.Dist(r,t),o=+x.Clockwise(t,n,e),i=((t.y-e.y)**2+(t.x-e.x)**2)**.5,a=((e.y-n.y)**2+(e.x-n.x)**2)**.5,l=((n.y-t.y)**2+(n.x-t.x)**2)**.5,c=Math.acos((a*a+l*l-i*i)/(2*a*l))*2,u=+(De>c),h=(Fe-c)*(o?1:-1),f=h*s;return{center:r,radius:s,size:h,length:f,largeArcFlag:u,sweepFlag:o}}function sle(t,e,n,r,s,o,i){const a=x.Angle(t,n),l=x.Angle(t,r);let c=cd(a,l);if(i||(c=Fe-c),s.setTo(t).add(x.FromAngle(a+c*(.5*(i?1:-1))).mul(e)),c>o){s.rotWith(t,De);const u=r.clone();r.setTo(n),n.setTo(u)}}const ole=8;function ile(t){return Math.abs(t.props.bend)<ole*t.props.scale}function Gp(t,e,n){const r=t.getBindingsFromShape(e,"arrow").find(l=>l.props.terminal===n);if(!r)return;const s=t.getShape(r.toId);if(!s)return;const o=t.getShapePageTransform(s),i=t.getShapeGeometry(s),a=i instanceof $r?i.children[0].vertices:i.vertices;return{shape:s,transform:o,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function bE(t,e,n,r){const s=t.getShape(n.toId);if(s){const{point:o,size:i}=t.getShapeGeometry(s).bounds,a=x.Add(o,x.MulV(n.props.isPrecise||r?n.props.normalizedAnchor:{x:.5,y:.5},i)),l=q.applyToPoint(t.getShapePageTransform(s),a);return q.applyToPoint(q.Inverse(e),l)}else return new x(0,0)}function Un(t,e){const n=t.getBindingsFromShape(e,"arrow");return{start:n.find(r=>r.props.terminal==="start"),end:n.find(r=>r.props.terminal==="end")}}const ale=GV("arrow info",(t,e)=>{const n=Un(t,e);return ile(e)?Xx(t,e,n):rle(t,e,n)});function Es(t,e){const n=typeof e=="string"?e:e.id;return ale.get(t,n)}function ul(t,e,n){var a,l;const r=t.getShapePageTransform(e),s=_1(t,(a=n.start)==null?void 0:a.toId,(l=n.end)==null?void 0:l.toId),o=n.start?bE(t,r,n.start,s==="double-bound"||s==="start-contains-end"):x.From(e.props.start),i=n.end?bE(t,r,n.end,s==="double-bound"||s==="end-contains-start"):x.From(e.props.end);return{start:o,end:i}}function Oc(t,e,n,r){const s=typeof e=="string"?e:e.id,o=typeof n=="string"?n:n.id,i=t.getBindingsFromShape(s,"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:o,props:r}):t.createBinding({type:"arrow",fromId:s,toId:o,props:r})}function mf(t,e,n){const r=t.getBindingsFromShape(e,"arrow").filter(s=>s.props.terminal===n);t.deleteBindings(r)}const fu=10,Vp=10,lle=10,ks={s:2,m:3.5,l:5,xl:10};function _1(t,e,n){if(!e||!n)return"safe";if(e===n)return"double-bound";const r=t.getShapePageBounds(e),s=t.getShapePageBounds(n);if(r&&s){if(r.contains(s))return"start-contains-end";if(s.contains(r))return"end-contains-start"}return"safe"}class yf extends hf{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:e}){const n=this.editor.getShape(e.fromId);n&&vS(this.editor,n)}onAfterChange({bindingAfter:e}){const n=this.editor.getShape(e.fromId);n&&vS(this.editor,n)}onAfterChangeFromShape({shapeAfter:e}){vS(this.editor,e)}onAfterChangeToShape({binding:e}){W$(this.editor,e.fromId)}onBeforeIsolateFromShape({binding:e}){const n=this.editor.getShape(e.fromId);n&&Yp({editor:this.editor,arrow:n,terminal:e.props.terminal})}}I(yf,"type","arrow"),I(yf,"props",CA),I(yf,"migrations",_A);function W$(t,e){var v;const n=t.getShape(e);if(!n)return;const r=Un(t,n),{start:s,end:o}=r,i=s?t.getShape(s.toId):void 0,a=o?t.getShape(o.toId):void 0,l=t.getAncestorPageId(n);if(!l)return;let c;if(i&&a)c=t.findCommonAncestor([i,a])??l;else if(i||a){const y=(v=i||a)==null?void 0:v.parentId;y&&y===n.parentId?c=n.parentId:c=l}else return;c&&c!==n.parentId&&t.reparentShapes([e],c);const u=t.getShape(e);if(!u)throw Error("no reparented arrow");const h=t.getShapeNearestSibling(u,i),f=t.getShapeNearestSibling(u,a);let p;if(h&&f)p=h.index>f.index?h:f;else if(h&&!f)p=h;else if(f&&!h)p=f;else return;let g;const m=t.getSortedChildIdsForParent(p.parentId).map(y=>t.getShape(y)).filter(y=>y.index>p.index);if(m.length){const y=m.find(S=>S.type!=="arrow");if(u.index>p.index&&(!y||u.index<y.index))return;g=$u(p.index,m[0].index)}else g=_s(p.index);g!==u.index&&t.updateShapes([{id:e,type:"arrow",index:g}])}function vS(t,e){const n=Un(t,e);for(const r of["start","end"]){const s=n[r];if(!s)continue;const o=t.getShape(s.toId),i=t.getAncestorPageId(e)===t.getAncestorPageId(o);(!o||!i)&&Yp({editor:t,arrow:e,terminal:r,unbind:!0})}W$(t,e.id)}function Yp({editor:t,arrow:e,terminal:n,unbind:r=!1,useHandle:s=!1}){const o=Es(t,e);if(!o)throw new Error("expected arrow info");const i=s?o.start.handle:o.start.point,a=s?o.end.handle:o.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(!o.isStraight){const u=n==="start"?i:o.start.handle,h=n==="end"?a:o.end.handle,f=x.Med(u,h),p=x.Sub(u,h).per().uni().mul(o.handleArc.radius*2*Math.sign(e.props.bend)),g=pd(o.handleArc.center,x.Add(f,p),o.handleArc.center,o.handleArc.radius);Le((g==null?void 0:g.length)===1);const m=x.Dist(f,g[0])*Math.sign(e.props.bend);di(m,c.props.bend)||(c.props.bend=m)}t.updateShape(c),r&&mf(t,e,n)}const G$=[yf],pn={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},fn={s:2,m:3.5,l:5,xl:10},Rl={s:18,m:24,l:36,xl:44},yo={s:18,m:22,l:26,xl:32},cle={s:18,m:20,l:24,xl:28},Co={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},ule=20,I1=4.25,Er=16;function dle(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 dl=" ",vn=class vn{static insertTextFirefox(e,n){e.setRangeText(n,e.selectionStart||0,e.selectionEnd||0,"end"),e.dispatchEvent(new InputEvent("input",{data:n,inputType:"insertText",isComposing:!1}))}static insert(e,n){const r=e.ownerDocument,s=r.activeElement;s!==e&&e.focus(),r.execCommand("insertText",!1,n)||vn.insertTextFirefox(e,n),s===r.body?e.blur():s instanceof HTMLElement&&s!==e&&s.focus()}static set(e,n){e.select(),vn.insert(e,n)}static getSelection(e){const{selectionStart:n,selectionEnd:r}=e;return e.value.slice(n||void 0,r||void 0)}static wrapSelection(e,n,r){const{selectionStart:s,selectionEnd:o}=e,i=vn.getSelection(e);vn.insert(e,n+i+(r??n)),e.selectionStart=(s||0)+n.length,e.selectionEnd=(o||0)+n.length}static replace(e,n,r){let s=0;e.value.replace(n,(...o)=>{const i=s+o[o.length-2],a=o[0].length;e.selectionStart=i,e.selectionEnd=i+a;const l=typeof r=="string"?r:r(...o);return vn.insert(e,l),e.selectionStart=i,s+=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:s}=e,o=s.slice(n,r),i=(a=/\n/g.exec(o))==null?void 0:a.length;if(i&&i>0){const l=s.lastIndexOf(`
|
|
353
|
+
`,n-1)+1,c=e.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${dl}`),h=u.length-c.length;e.setSelectionRange(l,r-1),vn.insert(e,u),e.setSelectionRange(n+1,r+h)}else vn.insert(e,dl)}static unindent(e){const{selectionStart:n,selectionEnd:r,value:s}=e,o=s.lastIndexOf(`
|
|
354
|
+
`,n-1)+1,i=vn.findLineEnd(s,r),a=e.value.slice(o,i),l=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),c=a.length-l.length;e.setSelectionRange(o,i),vn.insert(e,l);const u=/\t| {1,2}/.exec(s.slice(o,n)),h=u?u[0].length:0,f=n-h;e.setSelectionRange(n-h,Math.max(f,r-c))}static indentCE(e){var l;const n=window.getSelection(),r=e.innerText,s=Rh(e)??0,o=Rh(e)??0,i=r.slice(s,o),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
|
|
355
|
+
`,s-1)+1,u=r.slice(c,o-1),f=u.replace(/^|\n/g,`$&${dl}`).length-u.length;n&&n.setBaseAndExtent(e,s+1,e,o+f)}else{const c=window.getSelection();e.innerText=r.slice(0,s)+dl+r.slice(s),c==null||c.setBaseAndExtent(e,s+1,e,s+2)}}static unindentCE(e){const n=window.getSelection(),r=e.innerText,s=Rh(e)??0,o=Rh(e)??0,i=r.lastIndexOf(`
|
|
356
|
+
`,s-1)+1,a=vn.findLineEnd(r,o),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,s)),f=h?h[0].length:0,p=s-f;n.setBaseAndExtent(e,s-f,e,Math.max(p,o-u))}}static normalizeText(e){return e.replace(vn.fixNewLines,`
|
|
357
|
+
`)}static normalizeTextForDom(e){return e.replace(vn.fixNewLines,`
|
|
358
|
+
`).split(`
|
|
359
|
+
`).map(n=>n||" ").join(`
|
|
360
|
+
`)}};I(vn,"fixNewLines",/\r?\n|\r/g);let Ll=vn;function Rh(t){if(typeof window.getSelection>"u")return;const e=window.getSelection();if(!e)return;let n=0;if(e.rangeCount!==0){const r=e.getRangeAt(0),s=r.cloneRange();s.selectNodeContents(t),s.setEnd(r.endContainer,r.endOffset),n=s.toString().length}return n}const hle=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function V$(t){return hle.test(t)}function fle(t){return t.replace(/\t/g,dl)}function ple(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 s=r.length-r.trimStart().length;n=Math.min(n,s)}return e.map(r=>r.slice(n)).join(`
|
|
362
|
+
`)}const Y$={"&":"&",""":'"',"'":"'",""":'"',"&":"&","'":"'","–":"–","—":"—","‘":"‘","’":"’","“":"“","”":"”","…":"…"},gle=new RegExp(Object.keys(Y$).join("|"),"g");function mle(t){return t.replace(gle,e=>Y$[e])}function yle(t){return t.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function Sle(t){return yle(ple(fle(t)))}function vle(t,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:s},{toasts:o,msg:i}){t.registerExternalAssetHandler("file",async({file:a,assetId:l})=>{const c=r.includes(a.type),u=s.includes(a.type);!c&&!u&&o.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),Le(c||u,`File type not allowed: ${a.type}`),a.size>n&&o.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=TC(await a.arrayBuffer());l=l??Yo.createId(h);const f=await PE(a,l,c,u);if(isFinite(e)){const p={w:f.props.w,h:f.props.h},g=dle(p,{w:e,h:e});p!==g&&ar.isStaticImageType(a.type)&&(f.props.w=g.w,f.props.h=g.h)}return f.props.src=await t.uploadAsset(f,a),Yo.create(f)}),t.registerExternalAssetHandler("url",async({url:a})=>{var c,u,h,f,p;let l;try{const m=await(await Rs(a,{method:"GET",mode:"no-cors"})).text(),v=new DOMParser().parseFromString(m,"text/html");l={image:((c=v.head.querySelector('meta[property="og:image"]'))==null?void 0:c.getAttribute("content"))??"",favicon:((u=v.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:u.getAttribute("href"))??((h=v.head.querySelector('link[rel="icon"]'))==null?void 0:h.getAttribute("href"))??"",title:((f=v.head.querySelector('meta[property="og:title"]'))==null?void 0:f.getAttribute("content"))??a,description:((p=v.head.querySelector('meta[property="og:description"]'))==null?void 0:p.getAttribute("content"))??""},l.image.startsWith("http")||(l.image=new URL(l.image,a).href),l.favicon.startsWith("http")||(l.favicon=new URL(l.favicon,a).href)}catch(g){console.error(g),o.addToast({title:i("assets.url.failed"),severity:"error"}),l={image:"",favicon:"",title:"",description:""}}return{id:Yo.createId(Kv(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"),f=parseFloat(u.getAttribute("height")||"0");if(!(h&&f)){document.body.appendChild(u);const g=u.getBoundingClientRect();document.body.removeChild(u),h=g.width,f=g.height}const p=await t.getAssetForExternalContent({type:"file",file:new File([l],"asset.svg",{type:"image/svg+xml"})});if(!p)throw Error("Could not create an asset");CE(t,[p],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:f}=c,p=Ke(),g={id:p,type:"embed",x:u.x-(h||450)/2,y:u.y-(f||450)/2,props:{w:h,h:f,url:l}};t.createShapes([g]).select(p)}),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=[];for(const p of l){if(p.size>n){o.addToast({title:i("assets.files.size-too-big"),severity:"error"}),console.warn(`File size too big: ${(p.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`);continue}if(!p.type){o.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error("No mime type");continue}if(!r.concat(s).includes(p.type)){o.addToast({title:i("assets.files.type-not-allowed"),severity:"error"}),console.warn(`${p.name} not loaded - Mime type not allowed ${p.type}.`);continue}const g=r.includes(p.type),m=s.includes(p.type),v=TC(await p.arrayBuffer()),y=Yo.createId(v),S=await PE(p,y,g,m);let b;g&&(b=t.createTemporaryAssetPreview(y,p)),h.push({asset:S,file:p,temporaryAssetPreview:b})}const f=[];await Promise.allSettled(h.map(async p=>{try{const g=await t.getAssetForExternalContent({type:"file",file:p.file});if(!g)throw Error("Could not create an asset");const m={...g,id:p.asset.id};f.push(m),t.updateAssets([m])}catch(g){o.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(g);return}})),CE(t,f,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),f=t.getOnlySelectedShape();if(f&&"text"in f.props){t.updateShapes([{id:f.id,type:f.type,props:{text:h}}]);return}let p,g,m,v="middle";const y=h.split(`
|
|
363
|
+
`).length>1,S=V$(h);y&&(v=y?S?"end":"start":"middle");const b=t.textMeasure.measureText(h,{...pn,fontFamily:Co[u.font],fontSize:Rl[u.size],maxWidth:null}),P=Math.min(y?t.getViewportPageBounds().width*.9:920,Math.max(200,t.getViewportPageBounds().width*.9));if(b.w>P){const C=t.textMeasure.measureText(h,{...pn,fontFamily:Co[u.font],fontSize:Rl[u.size],maxWidth:P});p=C.w,g=C.h,m=!1,v=S?"end":"start"}else p=b.w,g=b.h,m=!0;c.y-g/2<t.getViewportPageBounds().minY+40&&(c.y=t.getViewportPageBounds().minY+40+g/2),t.createShapes([{id:Ke(),type:"text",x:c.x-p/2,y:c.y-g/2,props:{text:h,textAlign:v,autoSize:m,w:p}}])}),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),f=Yo.createId(Kv(l)),p=xle(t,l,h);let g=t.getAsset(f),m=!1;if(!g){m=!0;try{const v=await t.getAssetForExternalContent({type:"url",url:l});if(!v)throw Error("Could not create an asset");g=v}catch{o.addToast({title:i("assets.url.failed"),severity:"error"});return}}t.run(()=>{m&&t.createAssets([g]),t.updateShapes([{id:p.id,type:p.type,props:{assetId:g.id}}])})})}async function PE(t,e,n,r){let s=t.type;t.type==="video/quicktime"&&(s="video/mp4");const o=n?await ar.getImageSize(t):await ar.getVideoSize(t),i=await ar.isAnimated(t)||r;return{id:e,type:n?"image":"video",typeName:"asset",props:{name:t.name,src:"",w:o.w,h:o.h,fileSize:t.size,mimeType:s,isAnimated:i},meta:{}}}async function CE(t,e,n){if(!e.length)return[];const r=x.From(n),s=[];for(let o=0;o<e.length;o++){const i=e[o];switch(i.type){case"image":{s.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":s.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 o=e.filter(i=>!t.getAsset(i.id));o.length&&t.createAssets(o),t.createShapes(s).select(...s.map(i=>i.id)),X$(t,n)}),s.map(o=>o.id)}function X$(t,e){const n=t.getViewportPageBounds();let r=t.getSelectionPageBounds();if(r){const s=r.center.sub(e);t.updateShapes(t.getSelectedShapes().map(o=>{const i=t.getShapeParentTransform(o).decompose().rotation,a=x.Rot(s,-i);return{id:o.id,type:o.type,x:o.x-a.x,y:o.y-a.y}}))}if(r=t.getSelectionPageBounds(),r&&t.getInstanceState().isGridMode){const s=t.getDocumentSettings().gridSize,o=new x(r.minX,r.minY),i=o.clone().snapToGrid(s),a=x.Sub(o,i);t.updateShapes(t.getSelectedShapes().map(l=>{const c={x:l.x-a.x,y:l.y-a.y};return{id:l.id,type:l.type,x:c.x,y:c.y}}))}r=t.getSelectionPageBounds(),r&&!n.contains(r)&&t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})}function xle(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),X$(t,n)}),t.getShape(r.id)}var jS;let wle=(jS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}onKeyUp(e){var n;if(e.key==="Enter"){if(this.editor.getIsReadonly())return null;const r=this.editor.getOnlySelectedShape();r&&this.editor.getShapeUtil(r).canEdit(r)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(r.id),(n=this.editor.root.getCurrent())==null||n.transition("editing_shape",{...e,target:"shape",shape:r}))}}},I(jS,"id","idle"),jS);var OS;let ble=(OS=class extends ie{constructor(){super(...arguments);I(this,"shape");I(this,"markId","");I(this,"preciseTimeout",-1);I(this,"didTimeout",!1)}onEnter(){this.markId="",this.didTimeout=!1;const n=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.canBindShapes({fromShape:"arrow",toShape:r,binding:"arrow"}),margin:0,hitInside:!0,renderingOnly:!0});n?this.editor.setHintingShapes([n.id]):this.createArrowShape(),this.startPreciseTimeout()}onExit(){this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()}onPointerMove(){if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:{id:"end",type:"vertex",index:"a3",x:0,y:0},isCreating:!0,creatingMarkId:this.markId||void 0,onInteractionEnd:"arrow"})}}onPointerUp(){this.cancel()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var h;const{originPagePoint:n}=this.editor.inputs,r=Ke();this.markId=this.editor.markHistoryStoppingPoint(`creating_arrow:${r}`);const s=is(n,this.editor);this.editor.createShape({id:r,type:"arrow",x:s.x,y:s.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 i=this.editor.getShapeHandles(o);if(!i)throw Error("expected handles for arrow");const a=this.editor.getShapeUtil("arrow"),l=this.shape,c=i.find(f=>f.id==="start"),u=(h=a.onHandleDrag)==null?void 0:h.call(a,o,{handle:{...c,x:0,y:0},isPrecise:!0,initial:l});u&&this.editor.updateShapes([u]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,o;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=(s=i.onHandleDrag)==null?void 0:s.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=(o=i.onHandleDrag)==null?void 0:o.call(i,this.editor.getShape(n),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(n.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},I(OS,"id","pointing"),OS);class qx extends ie{constructor(){super(...arguments);I(this,"shapeType","arrow")}static children(){return[wle,ble]}}I(qx,"id","arrow"),I(qx,"initial","idle");class E1 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"initialShape");I(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");I(this,"util",this.editor.getShapeUtil(this.shapeType));I(this,"isPen",!1);I(this,"isPenOrStylus",!1);I(this,"segmentMode","free");I(this,"didJustShiftClickToExtendPreviousShapeLine",!1);I(this,"pagePointWhereCurrentSegmentChanged",{});I(this,"pagePointWhereNextSegmentChanged",null);I(this,"lastRecordedPoint",{});I(this,"mergeNextPoint",!1);I(this,"currentLineLength",0);I(this,"markId",null)}onEnter(n){this.markId=null,this.info=n,this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.startShape()}onPointerMove(){const{inputs:n}=this.editor;if(this.isPen&&!n.isPen&&this.markId){this.editor.bailToMark(this.markId),this.startShape();return}this.isPenOrStylus?x.Dist(n.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=n.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape()}onKeyDown(n){if(n.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()}onKeyUp(n){if(n.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()}onExit(){this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()}canClose(){return this.shapeType!=="highlight"}getIsClosed(n,r,s){if(!this.canClose())return!1;const o=fn[r],i=n[0].points[0],a=n[n.length-1],l=a.points[a.points.length-1];return i!==l&&this.currentLineLength>o*4*s&&x.DistMin(i,l,o*2*s)}startShape(){const{inputs:{originPagePoint:n,isPen:r}}=this.editor;this.markId=this.editor.markHistoryStoppingPoint("draw start");const{z:s=.5}=this.info.point;this.isPen=r,this.isPenOrStylus=r||s>0&&s<.5||s>.5&&s<1;const o=this.isPenOrStylus?s*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(),f={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+o.toFixed(2)},{x:u,y:h,z:+o.toFixed(2)}]},p=q.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=p,this.pagePointWhereNextSegmentChanged=null;const g=[...a.props.segments,f];this.currentLineLength<fn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(g));const m={id:a.id,type:this.shapeType,props:{segments:g}};this.canClose()&&(m.props.isClosed=this.getIsClosed(g,a.props.size,a.props.scale)),this.editor.updateShapes([m]);return}}this.pagePointWhereCurrentSegmentChanged=n.clone();const i=Ke();this.editor.createShapes([{id:i,type:this.shapeType,x:n.x,y:n.y,props:{isPen:this.isPenOrStylus,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+o.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:s,props:{size:o,scale:i}}=n,a=this.editor.getShape(s);if(!a)return;const{segments:l}=a.props,{x:c,y:u,z:h}=this.editor.getPointInShapeSpace(a,r.currentPagePoint).toFixed(),f=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,p={x:c,y:u,z:f};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:g}=this;if(g===null)throw Error("We should have a point where the segment changed");if(x.Dist2(g,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const v=Ht(l);if(!v)throw Error("Expected a previous segment!");const y=Ht(v.points);if(!y)throw Error("Expected a previous last point!");let S;const b=this.editor.getPointInShapeSpace(a,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(v.type==="straight"){this.currentLineLength+=x.Dist(y,b),S={type:"straight",points:[{...y},b]};const C=this.editor.getShapePageTransform(a);this.pagePointWhereCurrentSegmentChanged=q.applyToPoint(C,y)}else S={type:"straight",points:[b,p]};const P={id:s,type:this.shapeType,props:{segments:[...l,S]}};this.canClose()&&(P.props.isClosed=this.getIsClosed(l,o,i)),this.editor.updateShapes([P])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:g}=this;if(g===null)throw Error("We should have a point where the segment changed");if(x.Dist2(g,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const v=l.slice(),y=v[v.length-1],S=Ht(y.points);if(!S)throw Error("No previous point!");const b={type:"free",points:[...x.PointsBetween(S,p,6).map(_=>({x:io(_.x),y:io(_.y),z:io(_.z)}))]},P=[...v,b];this.currentLineLength<fn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(P));const C={id:s,type:this.shapeType,props:{segments:P}};this.canClose()&&(C.props.isClosed=this.getIsClosed(P,o,i)),this.editor.updateShapes([C])}break}case"straight":{const g=l.slice(),m=g[g.length-1],{pagePointWhereCurrentSegmentChanged:v}=this,{ctrlKey:y,currentPagePoint:S}=this.editor.inputs;if(!v)throw Error("We should have a point where the segment changed");let b,P=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(P=!y,this.didJustShiftClickToExtendPreviousShapeLine=!1):P=!y;let C=this.editor.getPointInShapeSpace(a,S).toFixed().toJson(),_=!1,E;if((this.editor.user.getIsSnapMode()?!y:y)&&g.length>2){let T,j=8/this.editor.getZoomLevel();for(let L=0,M=l.length-2;L<M;L++){const O=l[L];if(!O)break;if(O.type==="free")continue;const F=O.points[0],B=Ht(O.points);if(!(F&&B))continue;const K=x.NearestPointOnLineSegment(F,B,C);if(x.DistMin(K,C,j)){T=K.toFixed().toJson(),j=x.Dist(K,C),E=O;break}}T&&(_=!0,C=T)}if(_&&E){const T=this.editor.getShapePageTransform(a),j=E.points[0],L=Ht(E.points);if(!L)throw Error("Expected a last point!");const M=q.applyToPoint(T,j),O=q.applyToPoint(T,L),F=q.applyToPoint(T,C);this.editor.snaps.setIndicators([{id:ze(),type:"points",points:[M,F,O]}])}else{if(this.editor.snaps.clearIndicators(),P){const T=x.Angle(v,S),L=Op(T,24)-T;b=x.RotWith(S,v,L)}else b=S;C=this.editor.getPointInShapeSpace(a,b).toFixed().toJson()}this.currentLineLength+=x.Dist(m.points[0],C),g[g.length-1]={...m,type:"straight",points:[m.points[0],C]};const D={id:s,type:this.shapeType,props:{segments:g}};this.canClose()&&(D.props.isClosed=this.getIsClosed(l,o,i)),this.editor.updateShapes([D]);break}case"free":{const g=l.slice(),m=g[g.length-1],v=[...m.points];if(v.length&&this.mergeNextPoint){const{z:S}=v[v.length-1];v[v.length-1]={x:p.x,y:p.y,z:S?Math.max(S,p.z):p.z}}else this.currentLineLength+=x.Dist(v[v.length-1],p),v.push(p);g[g.length-1]={...m,points:v},this.currentLineLength<fn[a.props.size]*4&&(this.currentLineLength=this.getLineLength(g));const y={id:s,type:this.shapeType,props:{segments:g}};if(this.canClose()&&(y.props.isClosed=this.getIsClosed(g,o,i)),this.editor.updateShapes([y]),v.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:s,type:this.shapeType,props:{isComplete:!0}}]);const S=Ke(),b=this.editor.getShape(s).props;this.editor.createShapes([{id:S,type:this.shapeType,x:io(r.currentPagePoint.x),y:io(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:b.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(h*1.25).toFixed():.5}]}]}}]),this.initialShape=nt(this.editor.getShape(S)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(n){let r=0;for(const s of n)for(let o=0;o<s.points.length-1;o++){const i=s.points[o],a=s.points[o+1];r+=x.Dist2(a,i)}return Math.sqrt(r)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())}complete(){const{initialShape:n}=this;n&&(this.editor.updateShapes([{id:n.id,type:n.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}I(E1,"id","drawing");var DS;let q$=(DS=class extends ie{onPointerDown(e){this.parent.transition("drawing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(DS,"id","idle"),DS);class Sf extends ie{constructor(){super(...arguments);I(this,"shapeType","draw")}static children(){return[q$,E1]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}I(Sf,"id","draw"),I(Sf,"initial","idle"),I(Sf,"isLockable",!1);class Zx extends jx{constructor(){super(...arguments);I(this,"shapeType","frame")}onCreate(n){if(!n)return;const r=this.editor.getShapePageBounds(n),s=[],o=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)&&Ple(a,o,n)&&s.push(a.id)}),this.editor.reparentShapes(s,n.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")}}I(Zx,"id","frame"),I(Zx,"initial","idle");function Ple(t,e,n){return e.includes(t.id)?!1:t.parentId===n.parentId}var RS;let Cle=(RS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onKeyUp(e){var n;if(e.key==="Enter"){if(this.editor.getIsReadonly())return null;const r=this.editor.getOnlySelectedShape();r&&this.editor.getShapeUtil(r).canEdit(r)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(r.id),(n=this.editor.root.getCurrent())==null||n.transition("editing_shape",{...e,target:"shape",shape:r}))}}onCancel(){this.editor.setCurrentTool("select")}},I(RS,"id","idle"),RS);var LS;let _le=(LS=class extends ie{onPointerUp(){this.complete()}onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=Ke(),s=this.editor.markHistoryStoppingPoint(`creating_geo:${r}`),o=is(n,this.editor);this.editor.createShapes([{id:r,type:"geo",x:o.x,y:o.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(Jr),scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]).select(r).setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:s,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,s=this.editor.getStyleForNextShape(Jr),o=s==="star"?{w:200,h:190}:s==="cloud"?{w:300,h:180}:{w:200,h:200};this.editor.createShapes([{id:n,type:"geo",x:e.x,y:e.y,props:{geo:this.editor.getStyleForNextShape(Jr),scale:r,...o}}]);const i=this.editor.getShape(n);if(!i)return;const{w:a,h:l}=i.props,c=new x(a/2,l/2).mul(r),u=this.editor.getShapeParentTransform(i);u&&c.rot(-u.rotation());const h=is(new x(i.x-c.x,i.y-c.y),this.editor);this.editor.select(n),this.editor.updateShape({id:i.id,type:"geo",x:h.x,y:h.y,props:{geo:this.editor.getStyleForNextShape(Jr),w:a*r,h:l*r}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},I(LS,"id","pointing"),LS);class Qx extends ie{constructor(){super(...arguments);I(this,"shapeType","geo")}static children(){return[Cle,_le]}}I(Qx,"id","geo"),I(Qx,"initial","idle");class vf extends ie{constructor(){super(...arguments);I(this,"shapeType","highlight")}static children(){return[q$,E1]}onExit(){const n=this.children.drawing;n.initialShape=void 0}}I(vf,"id","highlight"),I(vf,"initial","idle"),I(vf,"isLockable",!1);var $S;let Ile=($S=class extends ie{constructor(){super(...arguments);I(this,"shapeId","")}onEnter(n){this.shapeId=n.shapeId,this.editor.setCursor({type:"cross",rotation:0})}onPointerDown(){this.parent.transition("pointing",{shapeId:this.shapeId})}onCancel(){this.editor.setCurrentTool("select")}},I($S,"id","idle"),$S);const _E=2;var FS;let Ele=(FS=class extends ie{constructor(){super(...arguments);I(this,"shape",{});I(this,"markId")}onEnter(n){const{inputs:r}=this.editor,{currentPagePoint:s}=r;this.markId=void 0;const o=n.shapeId&&this.editor.getShape(n.shapeId);if(o&&r.shiftKey){this.markId=this.editor.markHistoryStoppingPoint(`creating_line:${o.id}`),this.shape=o;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(g=>g.type==="vertex").sort(cn),l=a[a.length-1],c=a[a.length-2],u=q.applyToPoint(this.editor.getShapeParentTransform(this.shape),new x(this.shape.x,this.shape.y)),h=x.Sub(s,u).addXY(.1,.1),f=is(h,this.editor),p=nt(this.shape.props.points);if(x.DistMin(l,c,_E)||x.DistMin(f,l,_E))p[l.id]={id:l.id,index:l.index,x:f.x,y:f.y};else{const g=_s(l.index);p[g]={id:g,index:g,x:f.x,y:f.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}`);const a=is(s,this.editor);this.editor.createShapes([{id:i,type:"line",x:a.x,y:a.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(i),this.shape=this.editor.getShape(i)}}onPointerMove(){if(this.shape&&this.editor.inputs.isDragging){const n=this.editor.getShapeHandles(this.shape);if(!n)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=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()}},I(FS,"id","pointing"),FS);class Jx extends ie{constructor(){super(...arguments);I(this,"shapeType","line")}static children(){return[Ile,Ele]}}I(Jx,"id","line"),I(Jx,"initial","idle");var NS;let kle=(NS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(NS,"id","idle"),NS);const Tle=0,He=200,vm=new x(He/2,He/2),Z$=10,Mle=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 Ale(t,e){if(e===1)return Mle(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 Q$(t,e,n,r,s,o){return Object.fromEntries(Ale(t,o).map(([i,a],l)=>{const c=a.clone();return l===0&&s?c.y-=s:l===2&&r&&(c.y+=r),[i,c.rot(n).add(e)]}))}function J$(t,e,n,r){const s=new Set(t.getSelectedShapeIds()),o=(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||s.has(u.id))continue;const h=t.getShapePageTransform(u.id);e===h.rotation()&&(i.set(u,t.getShapePageBounds(u).center),a.push(...Object.values(Q$(t,h.point(),e,u.props.growY,r,n))))}const l=a.length;let c;for(const[u,h]of i)for(let f=0;f<l;f++)c=a[f],c&&(x.Dist2(h,c)>o||t.isPointInShape(u,c)&&(a[f]=void 0));return me(a)}function e5(t,e,n,r,s=!1){let o;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)){o=c;break}}}if(t.complete(),!o||s){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(vm.clone().mul(c.props.scale),r)));t.updateShape({id:l,type:"note",x:u.x,y:u.y}),o=t.getShape(l)}return Ole(t),o}const jle=16;function Ole(t){const e=t.getSelectionPageBounds(),n=t.getViewportPageBounds();if(e&&!n.contains(e)){const r=e.clone().expandBy(jle/t.getZoomLevel()).expand(n),s=n.clone().translate({x:(r.center.x-n.center.x)*2,y:(r.center.y-n.center.y)*2});t.zoomToBounds(s,{animation:{duration:t.options.animationMediumMs},inset:0})}}var zS;let Dle=(zS=class extends ie{constructor(){super(...arguments);I(this,"dragged",!1);I(this,"info",{});I(this,"markId","");I(this,"shape",{})}onEnter(){const{editor:n}=this,r=Ke();this.markId=n.markHistoryStoppingPoint(`creating_note:${r}`);const s=this.editor.inputs.originPagePoint.clone(),o=Rle(this.editor,s,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);o&&s.sub(o),this.shape=Lle(this.editor,r,s)}onPointerMove(n){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.translating",{...n,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,creatingMarkId:this.markId,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}onPointerUp(){this.complete()}onInterrupt(){this.cancel()}onComplete(){this.complete()}onCancel(){this.cancel()}complete(){this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):(this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape",{...this.info,target:"shape",shape:this.shape}))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}},I(zS,"id","pointing"),zS);function Rle(t,e,n){let r=Z$/t.getZoomLevel(),s;for(const o of J$(t,0,n,0)){const i=x.Sub(e,o),a=i.len();a<r&&(r=a,s=i)}return s}function Lle(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),s=t.getShapeGeometry(r).bounds,o=is(new x(r.x-s.width/2,r.y-s.height/2),t);return t.updateShapes([{id:e,type:"note",x:o.x,y:o.y}]),t.getShape(e)}class ew extends ie{constructor(){super(...arguments);I(this,"shapeType","note")}static children(){return[kle,Dle]}}I(ew,"id","note"),I(ew,"initial","idle");function $le(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 uo=CT($le,32);var BS;let Fle=(BS=class extends ie{onPointerMove(e){switch(e.target){case"shape":case"canvas":uo(this.editor)}}onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){uo.cancel()}onKeyDown(e){var n;if(e.key==="Enter"){if(this.editor.getIsReadonly())return null;const r=this.editor.getOnlySelectedShape();r&&this.editor.getShapeUtil(r).canEdit(r)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(r.id),(n=this.editor.root.getCurrent())==null||n.transition("editing_shape",{...e,target:"shape",shape:r}))}}onCancel(){this.editor.setCurrentTool("select")}},I(BS,"id","idle"),BS);var US;let Nle=(US=class extends ie{constructor(){super(...arguments);I(this,"shape");I(this,"markId","");I(this,"enterTime",0)}onEnter(){this.enterTime=Date.now()}onExit(){this.editor.setHintingShapes([])}onPointerMove(n){if(Date.now()-this.enterTime<150)return;const{editor:r}=this,{isPointing:s}=r.inputs;if(!s)return;const{originPagePoint:o,currentPagePoint:i}=r.inputs,a=Math.abs(o.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,o,!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,s,o){this.editor.createShape({id:n,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:s,w:o,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(s)switch(i.props.textAlign){case"start":{l.x=0;break}case"middle":{l.x=-a.width/2;break}case"end":{l.x=-a.width;break}}else l.x=0;if(l.y=-a.height/2,Fn(i.parentId)){const h=this.editor.getShapeParentTransform(i);l.rot(-h.rotation())}const c=i.x+l.x,u=i.y+l.y;if(this.editor.getInstanceState().isGridMode){const h=new x(c,u),f=is(h,this.editor),p=x.Sub(h,f);this.editor.updateShape({...i,x:c-p.x,y:u-p.y})}else this.editor.updateShape({...i,x:c,y:u});return i}},I(US,"id","pointing"),US);class tw extends ie{constructor(){super(...arguments);I(this,"shapeType","text")}static children(){return[Fle,Nle]}}I(tw,"id","text"),I(tw,"initial","idle");const zle=[tw,Sf,Qx,ew,Jx,Zx,qx,vf];function zr(){return ko({isDarkMode:vd()})}function xm(t){return{key:`${Ls.id}:${t}`,async getElement(){const e=Ble(t);if(!e)return null;const{url:n,fontFaceRule:r}=e,s=await(await Rs(n)).blob(),o=await Zr.blobToDataUrl(s),i=r.replace(n,o);return d.jsx("style",{children:i})}}}function Ble(t){const e=xA[t];for(const n of document.fonts)if(e.includes(n.family)&&"$$_url"in n&&typeof n.$$_url=="string"&&"$$_fontface"in n&&typeof n.$$_fontface=="string")return{url:n.$$_url,fontFaceRule:n.$$_fontface};return null}function k1(t){return{key:`${Ls.id}:${t}`,async getElement(){return t!=="pattern"?null:d.jsx(Ule,{})}}}function Ule(){const t=M1(),e=Jl(),n=zr(),r=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:e,children:[d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),d.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[d.jsx("line",{x1:r*1,y1:r*3,x2:r*3,y2:r*1}),d.jsx("line",{x1:r*5,y1:r*7,x2:r*7,y2:r*5}),d.jsx("line",{x1:r*9,y1:r*11,x2:r*11,y2:r*9})]})]}),d.jsx("pattern",{id:t(1,n.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:n.solid,mask:`url(#${e})`})})]})}function T1(){return{key:`${Ls.id}:pattern`,component:Gle}}const Yc=8,IE=(t,e,n)=>new Promise((r,s)=>{const o=Yc*e*t,i=document.createElement("canvas");i.width=o,i.height=o;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?Ip.darkMode.solid:Ip.lightMode.solid,a.fillRect(0,0,o,o),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||wt.throwToBlob.get()?s():r(u)})}),EE=(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 xS=null;function Hle(){return xS||(xS={white:EE([1,1],t=>{t.fillStyle="#f8f9fa",t.fillRect(0,0,1,1)}),black:EE([1,1],t=>{t.fillStyle="#212529",t.fillRect(0,0,1,1)})}),xS}function t5(t){return Math.ceil(Math.log2(Math.max(1,t)))}function M1(){const t=rs("hash_pattern");return w.useCallback((e,n)=>{const r=t5(e);return lb(t,`${n}_${r}`)},[t])}function n5(t){const e=[],r=t5(t);for(let s=0;s<=r;s++)e.push(Math.pow(2,s));return e}function Kle(t){const e=Hle();return n5(t).flatMap(n=>[{zoom:n,url:e.white,theme:"light"},{zoom:n,url:e.black,theme:"dark"}])}function Wle(){const t=z(),e=U("devicePixelRatio",()=>t.getInstanceState().devicePixelRatio,[t]),n=U("maxZoom",()=>Math.ceil(Ht(t.getCameraOptions().zoomSteps)),[t]),[r,s]=w.useState(!1),[o,i]=w.useState(()=>Kle(n)),a=M1();return w.useEffect(()=>{const c=Promise.all(n5(n).flatMap(h=>[IE(e,h,!1).then(f=>({zoom:h,theme:"light",url:URL.createObjectURL(f)})),IE(e,h,!0).then(f=>({zoom:h,theme:"dark",url:URL.createObjectURL(f)}))]));let u=!1;return c.then(h=>{u||(i(h),s(!0))}),()=>{u=!0,s(!1),c.then(h=>{for(const{url:f}of h)URL.revokeObjectURL(f)})}},[e,n]),{defs:d.jsx(d.Fragment,{children:o.map(c=>{const u=a(c.zoom,c.theme);return d.jsx("pattern",{id:u,width:Yc,height:Yc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:c.url,width:Yc,height:Yc})},u)})}),isReady:r}}function Gle(){const t=z(),e=w.useRef(null),{defs:n,isReady:r}=Wle();return w.useEffect(()=>{if(r&&Ge.isSafari){const s=r5(e.current);s&&t.timers.requestAnimationFrame(()=>{s.style.display="none",t.timers.requestAnimationFrame(()=>{s.style.display=""})})}},[t,r]),d.jsx("g",{ref:e,"data-testid":r?"ready-pattern-fill-defs":void 0,children:n})}function r5(t){return t.classList.contains("tl-html-layer")?t:t.parentElement?r5(t.parentElement):null}const sn=ke.memo(function({theme:e,d:n,color:r,fill:s,scale:o}){switch(s){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(Vle,{theme:e,color:r,fill:s,d:n,scale:o})}});function Vle({d:t,color:e,theme:n}){const r=z(),s=gd(),o=U("zoomLevel",()=>r.getZoomLevel(),[r]),i=M1(),a=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:n[e].pattern,d:t}),d.jsx("path",{fill:s?`url(#${i(1,n.id)})`:a?n[e].semi:`url(#${i(o,n.id)})`,d:t})]})}function Yle(t){return t.replace(/\s/g," ")}function nw(t,e,n){const{padding:r=0}=n;if(e.length===0)return null;const s=Z.From(e[0].box);for(const{box:c}of e)s.union(c);const o=r+(n.offsetX??0),i=(n.offsetY??0)+n.fontSize/2+(n.verticalTextAlign==="start"?r:n.verticalTextAlign==="end"?n.height-r-s.height:(Math.ceil(n.height)-s.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:o,y:u.y+i,children:`
|
|
364
|
+
`},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+o,y:u.y+i,unicodeBidi:"plaintext",children:Yle(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 Xle(t,e,n,r){if((t==="start-legacy"||t==="end-legacy")&&n.length!==0){const s=Z.From(n[0].box);for(const{box:o}of n)s.union(o);if(t==="start-legacy")return(r-2*e-s.width)/2;if(t==="end-legacy")return-(r-2*e-s.width)/2}}function qle(t){return t==="start-legacy"||t==="middle-legacy"||t==="end-legacy"}function wm({fontSize:t,font:e,align:n,verticalAlign:r,text:s,labelColor:o,bounds:i,padding:a=16,stroke:l=!0}){const c=z(),u=zr(),h={fontSize:t,fontFamily:xA[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:o,stroke:void 0,strokeWidth:void 0},f=c.textMeasure.measureTextSpans(s,h),p=Xle(n,a,f,i.width);p&&(h.offsetX=p),h.offsetX+=i.x,h.offsetY+=i.y;const g=nw(c,f,h);let m=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,m=nw(c,f,h)),d.jsxs(d.Fragment,{children:[m,g]})}const Zle=w.forwardRef(function({isEditing:e,text:n,handleFocus:r,handleChange:s,handleKeyDown:o,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:s,onKeyDown:o,onBlur:i,onTouchEnd:Ct,onContextMenu:e?Ct:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:xe})});function Qle(t,e,n){const r=z(),s=w.useRef(null),o=U("isEditing",()=>r.getEditingShapeId()===t,[r]),i=U("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);w.useEffect(()=>{function u(h){var f;h.shapeId===t&&((f=s.current)==null||f.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,t,o]),w.useEffect(()=>{var u,h,f,p;o&&(document.activeElement!==s.current&&((u=s.current)==null||u.focus()),r.getInstanceState().isCoarsePointer&&((h=s.current)==null||h.select()),Ge.isSafari&&((f=s.current)==null||f.blur(),(p=s.current)==null||p.focus()))},[r,o]);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=Ll.normalizeText(u.currentTarget.value);const f=h.replace(/\t/g,dl);if(f!==h){const p=u.currentTarget.selectionStart;u.currentTarget.value=f,u.currentTarget.selectionStart=p+(f.length-h.length),u.currentTarget.selectionEnd=p+(f.length-h.length),h=f}r.updateShape({id:t,type:e,props:{text:h}})},[r,t,e]),c=w.useCallback(u=>{r.dispatch({...lr(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(t)}),Ct(u)},[r,t]);return{rInput:s,handleFocus:Ru,handleBlur:Ru,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:Ct,isEmpty:n.trim().length===0,isEditing:o,isEditingAnything:i}}const bm=ke.memo(function({shapeId:e,type:n,text:r,labelColor:s,font:o,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:f=0,onKeyDown:p,classNamePrefix:g,style:m,textWidth:v,textHeight:y}){const{rInput:S,isEmpty:b,isEditing:P,isEditingAnything:C,..._}=Qle(e,n,r),[E,k]=w.useState(r);w.useEffect(()=>{P||k(r)},[P,r]);const D=Ll.normalizeTextForDom(r),T=D.length>0,j=qle(l);if(!P&&!T)return null;const L=g||"tl-text";return d.jsx("div",{className:`${L}-label tl-text-wrapper`,"data-font":o,"data-align":l,"data-hastext":!b,"data-isediting":P,"data-iseditinganything":C,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||j?"center":l,alignItems:c==="middle"?"center":c,padding:f,...m},children:d.jsxs("div",{className:`${L}-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:s,width:v?Math.ceil(v):void 0,height:y?Math.ceil(y):void 0},children:[d.jsx("div",{className:`${L} tl-text tl-text-content`,dir:"auto",children:D.split(`
|
|
365
|
+
`).map((M,O)=>d.jsx("div",{dir:"auto",children:M},O))}),(C||h)&&d.jsx(Zle,{ref:S,text:r,isEditing:P,..._,handleKeyDown:p??_.handleKeyDown},E)]})})}),Jle=new Ds;function ece(t){return Jle.get(t,()=>t.store.createComputedCache("arrowLabelSize",e=>{const n=Es(t,e);let r=0,s=0;const o=n.isStraight?new co({start:x.From(n.start.point),end:x.From(n.end.point)}):new ll({center:x.Cast(n.handleArc.center),start:x.Cast(n.start.point),end:x.Cast(n.end.point),sweepFlag:n.bodyArc.sweepFlag,largeArcFlag:n.bodyArc.largeArcFlag});if(e.props.text.trim()){const i=o.bounds,a=rw(e),{w:l,h:c}=t.textMeasure.measureText(e.props.text,{...pn,fontFamily:Co[e.props.font],fontSize:a,maxWidth:null});r=l,s=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:f}=t.textMeasure.measureText(e.props.text,{...pn,fontFamily:Co[e.props.font],fontSize:a,maxWidth:r});r=h,s=f}}return new x(r,s).addScalar(I1*2*e.props.scale)}))}function A1(t,e){return e.props.text.trim()===""?new x(0,0).addScalar(I1*2*e.props.scale):ece(t).get(e.id)??new x(0,0)}function s5(t){const e=fn[t.props.size];return(ule+(e-fn.s)*2+(e===fn.xl?20:0))*t.props.scale}function tce(t,e,n){const r=A1(t,e),s=s5(e),o=x.Nudge(n.start.point,n.end.point,s),i=x.Nudge(n.end.point,n.start.point,s),a=xb(o,i,Z.FromCenter(n.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;x.Dist2(l,o)>x.Dist2(c,o)&&([c,l]=a);const u=o.add(x.Sub(n.middle,l)),h=i.add(x.Sub(n.middle,c)),f=x.Dist(n.start.point,u)/n.length,p=x.Dist(n.start.point,h)/n.length;return{start:f,end:p}}function nce(t,e,n){const r=A1(t,e),s=s5(e),o=Math.sign(e.props.bend),i=s/n.handleArc.radius*o,a=x.Angle(n.bodyArc.center,n.start.point)-i,l=x.Angle(n.bodyArc.center,n.end.point)+i,c=ha(n.bodyArc.center,n.bodyArc.radius,a),u=ha(n.bodyArc.center,n.bodyArc.radius,l),h=[],f=TE(n.bodyArc.center,n.bodyArc.radius,a,l,o,Z.FromCenter(c,r).corners);h.push(new vt({points:Z.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const p=TE(n.bodyArc.center,n.bodyArc.radius,a,l,o,Z.FromCenter(u,r).corners);h.push(new vt({points:Z.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const E of[...f??[],...p??[],c,u])h.push(new Ob({x:E.x-3,y:E.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const g=(f&&ME(n.start.point,f))??n.middle,m=(p&&ME(n.end.point,p))??n.middle,v=x.Angle(n.bodyArc.center,n.start.point),y=x.Angle(n.bodyArc.center,n.end.point),S=x.Angle(n.bodyArc.center,g),b=x.Angle(n.bodyArc.center,m);if(Xo(v,S,o)>Xo(v,b,o))return{start:.5,end:.5,dbg:h};const P=Xo(v,y,o),C=Xo(v,S,o)/P,_=Xo(v,b,o)/P;return{start:C,end:_,dbg:h}}function xf(t,e){let n;const r=[],s=Es(t,e),o={hasStartBinding:!!s.bindings.start,hasEndBinding:!!s.bindings.end,hasStartArrowhead:s.start.arrowhead!=="none",hasEndArrowhead:s.end.arrowhead!=="none"};if(s.isStraight){const a=tce(t,e,s),l=kE(t,e,a,o);n=x.Lrp(s.start.point,s.end.point,l)}else{const a=nce(t,e,s);a.dbg&&r.push(...a.dbg);const l=kE(t,e,a,o),c=rce(x.Angle(s.bodyArc.center,s.start.point),x.Angle(s.bodyArc.center,s.end.point),Math.sign(e.props.bend),l);n=ha(s.bodyArc.center,s.bodyArc.radius,c)}const i=A1(t,e);return{box:Z.FromCenter(n,i),debugGeom:r}}function kE(t,e,n,r){const{hasEndArrowhead:s,hasEndBinding:o,hasStartBinding:i,hasStartArrowhead:a}=r,l=l5(t,e);let c=Bt(e.props.labelPosition,a||i?n.start:0,s||o?n.end:1);const u=Math.min(.02,500/l*.02);return c=c>=.5-u&&c<=.5+u?.5:c,c}function TE(t,e,n,r,s,o){const i=Cx(t,e,o),a=Xo(n,r,s);return i==null?void 0:i.filter(l=>{const c=Xo(n,x.Angle(t,l),s);return c>=0&&c<=a})}function ME(t,e){let n=null,r=-1/0;for(const s of e){const o=x.Dist2(t,s);o>r&&(n=s,r=o)}return n}function rce(t,e,n,r){const s=Xo(t,e,n);return t+s*r*n*-1}function rw(t){return cle[t.props.size]*t.props.scale}function sce(t,e,n){const r=e==="end"?t.end.point:t.start.point,s=e==="end"?t.start.point:t.end.point,o=t.isStraight?x.Dist(s,r):Math.abs(t.bodyArc.length),i=Math.max(Math.min(o/5,n*3),n);let a;if(t.isStraight)a=x.Nudge(r,s,i);else{const l=WZ(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 oce({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 ice({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 ace({point:t,int:e}){const n=x.Sub(e,t).div(2),r=x.Add(t,x.Rot(n,Ze)),s=x.Sub(t,x.Rot(n,Ze));return`M ${r.x} ${r.y} L ${e.x} ${e.y} L ${s.x} ${s.y} Z`}function lce({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 cce({point:t,int:e}){const n=x.Lrp(t,e,.75),r=x.RotWith(n,t,De/4),s=x.RotWith(n,t,-De/4),o=x.Lrp(r,s,.5);return o.add(x.Sub(o,t)),`M ${o.x} ${o.y} L ${s.x} ${s.y} ${t.x} ${t.y} L ${r.x} ${r.y} Z`}function uce({int:t,point:e}){const n=x.Lrp(e,t,.85),r=x.Sub(n,e).div(2),s=x.Add(e,x.Rot(r,Ze)),o=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 ${s.x} ${s.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${o.x} ${o.y} Z`}function dce({int:t,point:e}){const n=x.Sub(t,e).div(2),r=x.Add(e,x.Rot(n,Ze)),s=x.Sub(e,x.Rot(n,Ze));return`M ${r.x} ${r.y} L ${s.x} ${s.y}`}function Xp(t,e,n){const r=e==="end"?t.end.arrowhead:t.start.arrowhead;if(r==="none")return;const s=sce(t,e,n);if(s){switch(r){case"bar":return dce(s);case"square":return uce(s);case"diamond":return cce(s);case"dot":return lce(s);case"inverted":return ace(s);case"arrow":return oce(s);case"triangle":return ice(s)}return""}}function hce(t){const{start:e,end:n,handleArc:{radius:r,largeArcFlag:s,sweepFlag:o}}=t;return`M${e.handle.x},${e.handle.y} A${r} ${r} 0 ${s} ${o} ${n.handle.x},${n.handle.y}`}function o5(t){const{start:e,end:n,bodyArc:{radius:r,largeArcFlag:s,sweepFlag:o}}=t;return`M${e.point.x},${e.point.y} A${r} ${r} 0 ${s} ${o} ${n.point.x},${n.point.y}`}function i5(t,e){return`M${t.x},${t.y}L${e.x},${e.y}`}function fce(t){return i5(t.start.handle,t.end.handle)}function a5(t){return i5(t.start.point,t.end.point)}class wf extends ss{constructor(){super(...arguments);I(this,"_resizeInitialBindings",new Ds)}canEdit(){return!0}canBind({toShapeType:n}){return n!=="arrow"}canSnap(){return!1}hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsBg(){return!0}hideSelectionBoundsFg(){return!0}canBeLaidOut(n){const r=Un(this.editor,n);return!r.start&&!r.end}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{x:0,y:0},end:{x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw",scale:1}}getGeometry(n){const r=Es(this.editor,n),s=[],o=r.isStraight?new co({start:x.From(r.start.point),end:x.From(r.end.point)}):new ll({center:x.Cast(r.handleArc.center),start:x.Cast(r.start.point),end:x.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(n.props.text.trim()){const a=xf(this.editor,n);s.push(...a.debugGeom),i=new Fs({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new $r({children:[...i?[o,i]:[o],...s]})}getHandles(n){const r=Es(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:s}){const o=r.id,i=Un(this.editor,n);if(o==="middle"){const{start:_,end:E}=ul(this.editor,n,i),k=x.Sub(E,_),D=x.Per(k),T=x.Med(E,_),j=x.Sub(T,D),L=x.Add(T,D),M=x.NearestPointOnLineSegment(j,L,r,!1);let O=x.Dist(M,T);return x.Clockwise(M,E,T)&&(O*=-1),{id:n.id,type:n.type,props:{bend:O}}}const a={id:n.id,type:"arrow",props:{}},l=i[o],u=i[o==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return mf(this.editor,n,o),a.props[o]={x:r.x,y:r.y},a;const h=this.editor.getShapePageTransform(n.id).applyToPoint(r),f=this.editor.getShapeAtPoint(h,{hitInside:!0,hitFrameInside:!0,margin:0,filter:_=>!_.isLocked&&this.editor.canBindShapes({fromShape:n,toShape:_,binding:"arrow"})});if(!f){mf(this.editor,n,o);const _=is(new x(r.x,r.y),this.editor);return a.props[o]={x:_.x,y:_.y},a}const p=this.editor.getShapeGeometry(f),g=Z.ZeroFix(p.bounds),v=this.editor.getShapePageTransform(a.id).applyToPoint(r),y=this.editor.getPointInShapeSpace(f,v);let S=s;S||(!l||l&&f.id!==l.toId)&&(S=this.editor.inputs.pointerVelocity.len()<.5),s||(p.isClosed||(S=!0),u&&f.id===u.toId&&u.props.isPrecise&&(S=!0));const b={x:(y.x-g.minX)/g.width,y:(y.y-g.minY)/g.height};S&&x.Dist(y,g.center)<Math.max(4,Math.min(Math.min(g.width,g.height)*.15,16))/this.editor.getZoomLevel()&&(b.x=.5,b.y=.5);const P={terminal:o,normalizedAnchor:b,isPrecise:S,isExact:this.editor.inputs.altKey};Oc(this.editor,n,f.id,P),this.editor.setHintingShapes([f.id]);const C=Un(this.editor,n);return C.start&&C.end&&C.start.toId===C.end.toId&&x.Equals(C.start.props.normalizedAnchor,C.end.props.normalizedAnchor)&&Oc(this.editor,n,C.end.toId,{...C.end.props,normalizedAnchor:{x:C.end.props.normalizedAnchor.x+.05,y:C.end.props.normalizedAnchor.y}}),a}onTranslateStart(n){const r=Un(this.editor,n),s=ul(this.editor,n,r),o=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)))){jE.set(n,{pagePosition:o.applyToPoint(n),terminalBindings:rd(s,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:o.applyToPoint(l)}:null})}),r.start&&(Yp({editor:this.editor,arrow:n,terminal:"start",useHandle:!0}),n=this.editor.getShape(n.id)),r.end&&Yp({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 s=jE.get(n);if(!s)return;const o=this.editor.getShapePageTransform(r.id),i=x.Sub(o.applyToPoint(r),s.pagePosition);for(const a of Object.values(s.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),f={x:(h.x-u.minX)/u.width,y:(h.y-u.minY)/u.height};Oc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:f,isPrecise:!0})}else mf(this.editor,r,a.binding.props.terminal)}}onResize(n,r){const{scaleX:s,scaleY:o}=r,i=this._resizeInitialBindings.get(n,()=>Un(this.editor,n)),a=ul(this.editor,n,i),{start:l,end:c}=nt(n.props);let{bend:u}=n.props;i.start||(l.x=a.start.x*s,l.y=a.start.y*o),i.end||(c.x=a.end.x*s,c.y=a.end.y*o);const h=Math.abs(s),f=Math.abs(o),p=i!=null&&i.start?x.From(i.start.props.normalizedAnchor):null,g=i!=null&&i.end?x.From(i.end.props.normalizedAnchor):null;return s<0&&o>=0?(u!==0&&(u*=-1,u*=Math.max(h,f)),p&&(p.x=1-p.x),g&&(g.x=1-g.x)):s>=0&&o<0?(u!==0&&(u*=-1,u*=Math.max(h,f)),p&&(p.y=1-p.y),g&&(g.y=1-g.y)):s>=0&&o>=0?u!==0&&(u*=Math.max(h,f)):s<0&&o<0&&(u!==0&&(u*=Math.max(h,f)),p&&(p.x=1-p.x,p.y=1-p.y),g&&(g.x=1-g.x,g.y=1-g.y)),i.start&&p&&Oc(this.editor,n,i.start.toId,{...i.start.props,normalizedAnchor:p.toJson()}),i.end&&g&&Oc(this.editor,n,i.end.toId,{...i.end.props,normalizedAnchor:g.toJson()}),{props:{start:l,end:c,bend:u}}}onDoubleClickHandle(n,r){switch(r.id){case"start":return{id:n.id,type:n.type,props:{...n.props,arrowheadStart:n.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:n.id,type:n.type,props:{...n.props,arrowheadEnd:n.props.arrowheadEnd==="none"?"arrow":"none"}}}}component(n){const r=zr(),s=this.editor.getOnlySelectedShape(),o=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getIsReadonly(),i=Es(this.editor,n);if(!(i!=null&&i.isValid))return null;const a=xf(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(mi,{style:{minWidth:50,minHeight:50},children:d.jsx(AE,{shape:n,shouldDisplayHandles:o&&(s==null?void 0:s.id)===n.id})}),u&&d.jsx(bm,{shapeId:n.id,classNamePrefix:"tl-arrow",type:"arrow",font:n.props.font,fontSize:rw(n),lineHeight:pn.lineHeight,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:r[n.props.labelColor].solid,textWidth:a.box.w-I1*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=Xg(n.id),s=rs(n.id+"_clip"),o=Es(this.editor,n);if(!o)return null;const{start:i,end:a}=ul(this.editor,n,o==null?void 0:o.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=fn[n.props.size]*n.props.scale,f=o.start.arrowhead&&Xp(o,"start",h),p=o.end.arrowhead&&Xp(o,"end",h),g=o.isStraight?a5(o):o5(o),m=f&&o.start.arrowhead!=="arrow"||p&&o.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=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),y=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow");return d.jsxs("g",{children:[m&&d.jsx("defs",{children:d.jsx(c5,{hasText:n.props.text.trim().length>0,bounds:c,labelBounds:u?u.getBounds():new Z(0,0,0,0),as:v&&f?f:"",ae:y&&p?p:""})}),d.jsxs("g",{style:{clipPath:m?`url(#${s})`:void 0,WebkitClipPath:m?`url(#${s})`:void 0},children:[m&&d.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),d.jsx("path",{d:g})]}),f&&d.jsx("path",{d:f}),p&&d.jsx("path",{d:p}),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:s,props:{text:o}}=n;o.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:s,props:{text:o.trimEnd()}}])}toSvg(n,r){r.addExportDef(k1(n.props.fill)),n.props.text&&r.addExportDef(xm(n.props.font));const s=ko(r),o=1/n.props.scale;return d.jsxs("g",{transform:`scale(${o})`,children:[d.jsx(AE,{shape:n,shouldDisplayHandles:!1}),d.jsx(wm,{fontSize:rw(n),font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:s[n.props.labelColor].solid,bounds:xf(this.editor,n).box.clone().expandBy(-4.25*n.props.scale),padding:0})]})}getCanvasSvgDefs(){return[T1(),{key:"arrow:dot",component:pce},{key:"arrow:cross",component:gce}]}getInterpolatedProps(n,r,s){return{...s>.5?r.props:n.props,scale:_e(n.props.scale,r.props.scale,s),start:{x:_e(n.props.start.x,r.props.start.x,s),y:_e(n.props.start.y,r.props.start.y,s)},end:{x:_e(n.props.end.x,r.props.end.x,s),y:_e(n.props.end.y,r.props.end.y,s)},bend:_e(n.props.bend,r.props.bend,s),labelPosition:_e(n.props.labelPosition,r.props.labelPosition,s)}}}I(wf,"type","arrow"),I(wf,"props",bA),I(wf,"migrations",PA);function l5(t,e){const n=Es(t,e);return n.isStraight?x.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const AE=Zt(function({shape:e,shouldDisplayHandles:n}){const r=z(),s=zr(),o=Es(r,e),i=Z.ZeroFix(r.getShapeGeometry(e).bounds),a=Un(r,e),l=U("force solid",()=>r.getZoomLevel()<.2,[r]),c=rs(e.id+"_clip"),u=rs("arrowhead-dot"),h=rs("arrowhead-cross");if(!(o!=null&&o.isValid))return null;const f=fn[e.props.size]*e.props.scale,p=o.start.arrowhead&&Xp(o,"start",f),g=o.end.arrowhead&&Xp(o,"end",f),m=o.isStraight?a5(o):o5(o);let v=null;if(n){const _=2/r.getZoomLevel(),{strokeDasharray:E,strokeDashoffset:k}=qr(l5(r,e),_,{end:"skip",start:"skip",lengthRatio:2.5});v=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:o.isStraight?fce(o):hce(o),strokeDasharray:E,strokeDashoffset:k,strokeWidth:_,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?`url(#${h})`:`url(#${u})`:"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?`url(#${h})`:`url(#${u})`:"",opacity:.16}):null}const{strokeDasharray:y,strokeDashoffset:S}=qr(o.isStraight?o.length:Math.abs(o.bodyArc.length),f,{style:e.props.dash,forceSolid:l}),b=xf(r,e),P=!(o.start.arrowhead==="none"||o.start.arrowhead==="arrow"),C=!(o.end.arrowhead==="none"||o.end.arrowhead==="arrow");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:c,children:d.jsx(c5,{hasText:e.props.text.trim().length>0,bounds:i,labelBounds:b.box,as:P&&p?p:"",ae:C&&g?g:""})})}),d.jsxs("g",{fill:"none",stroke:s[e.props.color].solid,strokeWidth:f,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[v,d.jsxs("g",{style:{clipPath:`url(#${c})`,WebkitClipPath:`url(#${c})`},children:[d.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),d.jsx("path",{d:m,strokeDasharray:y,strokeDashoffset:S})]}),p&&P&&e.props.fill!=="none"&&d.jsx(sn,{theme:s,d:p,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),g&&C&&e.props.fill!=="none"&&d.jsx(sn,{theme:s,d:g,color:e.props.color,fill:e.props.fill,scale:e.props.scale}),p&&d.jsx("path",{d:p}),g&&d.jsx("path",{d:g})]})]})});function c5({hasText:t,bounds:e,labelBounds:n,as:r,ae:s}){const o=`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:`${o}${t?i:""}${r}${s}`})}const jE=new WeakMap;function pce(){const t=rs("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 gce(){const t=rs("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 OE="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 $l({url:t}){const e=z(),n=U("zoomLevel",()=>e.getZoomLevel()<.32,[e]);return d.jsx("a",{className:ce("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n}),href:t,target:"_blank",rel:"noopener noreferrer",onPointerDown:Ct,onPointerUp:Ct,title:t,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${OE}") center 100% / 100% no-repeat`,WebkitMask:`url("${OE}") center 100% / 100% no-repeat`}})})}const DE="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",mce=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function qp(t){return mce.map(n=>{const{offsetX:r,offsetY:s,blur:o,spread:i,color:a}=n,l=new x(r,s),{x:c,y:u}=l.rot(-t);return`${c}px ${u}px ${o}px ${i}px ${a}`}).join(", ")}const yce=300,u5=320,Sce=46,vce=101;class bf extends oc{canResize(){return!1}hideSelectionBoundsFg(){return!0}getText(e){return e.props.url}getDefaultProps(){return{url:"",w:yce,h:u5,assetId:null}}component(e){return d.jsx(xce,{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 RE(this.editor,e)}onBeforeUpdate(e,n){if(e.props.url!==n.props.url)if(gr.isValid(n.props.url))bce(this.editor,n);else return{...n,props:{...n.props,url:e.props.url}};if(e.props.assetId!==n.props.assetId)return RE(this.editor,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}I(bf,"type","bookmark"),I(bf,"props",TA),I(bf,"migrations",MA);function xce({shape:t,util:e}){const n=t.props.assetId?e.editor.getAsset(t.props.assetId):null,r=!!gd()&&Ge.isSafari,s=e.editor.getShapePageTransform(t).rotation(),o=wce(t),[i,a]=w.useState(!0),l=()=>a(!1);return d.jsx(hi,{children:d.jsxs("div",{className:ce("tl-bookmark__container",r&&"tl-bookmark__container--safariExport"),style:{boxShadow:r?void 0:qp(s),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($l,{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:mle(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:Ct,onPointerUp:Ct,onClick:Ct,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 ${o}`}):d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${DE}") center 100% / 100% no-repeat`,WebkitMask:`url("${DE}") center 100% / 100% no-repeat`}}),d.jsx("span",{children:o})]})]})]})})}function RE(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):null;let r=u5;return n&&(n.props.image||(n.props.title?r=vce:r=Sce)),{...e,props:{...e.props,h:r}}}const wce=t=>{try{return new URL(t.props.url).hostname.replace(/^www\./,"")}catch{return t.props.url}};function bce(t,e){const{url:n}=e.props,r=Yo.createId(Kv(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}}]),Pce(t,e))}const Pce=yg(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 va(t,e=!1){const n=t.length;if(n<2)return"";let r=t[0].point,s=t[1].point;if(n===2)return`M${je(r)}L${je(s)}`;let o="";for(let i=2,a=n-1;i<a;i++)r=t[i].point,s=t[i+1].point,o+=Bn(r,s);return e?`M${Bn(t[0].point,t[1].point)}Q${je(t[1].point)}${Bn(t[1].point,t[2].point)}T${o}${Bn(t[n-1].point,t[0].point)}${Bn(t[0].point,t[1].point)}Z`:`M${je(t[0].point)}Q${je(t[1].point)}${Bn(t[1].point,t[2].point)}${t.length>3?"T":""}${o}L${je(t[n-1].point)}`}function Cce(t,e={}){const{start:n={},end:r={}}=e,{cap:s=!0}=n,{cap:o=!0}=r;Le(!n.taper&&!r.taper,"cap taper not supported here"),Le(!n.easing&&!r.easing,"cap easing not supported here"),Le(s&&o,"cap must be true");const i=Bs(t,e);Sm(i,e);const a=_ce(i);let l="";for(const c of a)l+=Ece(c,e);return l}function _ce(t){if(t.length<=2)return[t];const e=[];let n=[t[0]],r=x.Sub(t[1].point,t[0].point).uni(),s,o,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],s=x.Sub(l.point,a.point).uni(),o=x.Dpr(r,s),r=s,o<-.8){const h={...a,point:a.input};n.push(h),e.push(wS(n)),n=[h];continue}if(n.push(a),!(o>.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(wS(n)),n=[a];continue}}return n.push(t[t.length-1]),e.push(wS(n)),e}function wS(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 s;for(;t.length>2&&(s=t[t.length-2],x.Dist2(r.point,s.point)<((r.radius+s.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 Ice(t,e,n){return"M "+t+" "+e+" m -"+n+", 0 a "+n+","+n+" 0 1,1 "+n*2+",0 a "+n+","+n+" 0 1,1 -"+n*2+",0"}function Ece(t,e={}){if(t.length===0)return"";if(t.length===1)return Ice(t[0].point.x,t[0].point.y,t[0].radius);const{left:n,right:r}=K$(t,e);r.reverse();let s=`M${je(n[0])}T`;for(let o=1;o<n.length;o++)s+=Bn(n[o-1],n[o]);{const o=t[t.length-1],i=o.radius,a=o.vector.clone().per().neg(),l=x.Add(o.point,x.Mul(a,i)),c=x.Add(o.point,x.Mul(a,-i));s+=`${je(l)}A${N(i)},${N(i)} 0 0 1 ${je(c)}T`}for(let o=1;o<r.length;o++)s+=Bn(r[o-1],r[o]);{const o=t[0],i=o.radius,a=o.vector.clone().per(),l=x.Add(o.point,x.Mul(a,i)),c=x.Add(o.point,x.Mul(a,-i));s+=`${je(l)}A${N(i)},${N(i)} 0 0 1 ${je(c)}Z`}return s}const d5=(t,e,n)=>{const r=[],s=[];t.forEach(c=>r.push(...c.points)),e.forEach(c=>s.push(...c.points));const o=Math.max(r.length,s.length),i=[],a=[];for(let c=0;c<o;c++)i.push(r[c]||r[r.length-1]),a.push(s[c]||s[s.length-1]);return[{type:"free",points:i.map((c,u)=>{let h=.5;return a[u].z!==void 0&&c.z!==void 0&&(h=_e(c.z,a[u].z,n)),{x:_e(c.x,a[u].x,n),y:_e(c.y,a[u].y,n),z:h}})}]},kce=t=>t*.65+fX(t*De/2)*.35,Tce=t=>({size:t,thinning:.5,streamline:jl(t,[9,16],[.64,.74],!0),smoothing:.62,easing:Dt.easeOutSine,simulatePressure:!0}),Mce=t=>({size:1+t*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:kce}),LE=t=>({size:t,thinning:0,streamline:jl(t,[9,16],[.64,.74],!0),smoothing:.62,simulatePressure:!1,easing:Dt.linear}),Ace=t=>({size:t,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:Dt.linear});function j1({strokeWidth:t,showAsComplete:e}){return{size:1+t,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:Dt.easeOutSine,last:e}}function sw(t,e,n,r){const s=t.isComplete||n;return r?t.isPen?{...Ace(e),last:s}:{...LE(e),last:s}:t.dash==="draw"?t.isPen?{...Mce(e),last:s}:{...Tce(e),last:s}:{...LE(e),last:s}}function Fl(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 jce(t,e,n){return{draw:"none",solid:"none",dotted:`${n} ${e*2}`,dashed:`${e*2} ${e*2}`}[t.props.dash]}class Pf extends ss{hideResizeHandles(e){return bS(e)}hideRotateHandle(e){return bS(e)}hideSelectionBoundsFg(e){return bS(e)}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(e){const n=Fl(e.props.segments),r=(fn[e.props.size]+1)*e.props.scale;if(e.props.segments.length===1){const o=Z.FromPoints(n);if(o.width<r*2&&o.height<r*2)return new Ob({x:-r,y:-r,radius:r,isFilled:!0})}const s=Bs(n,sw(e.props,r,e.props.isPen,!0)).map(o=>o.point);return e.props.isClosed?new vt({points:s,isFilled:e.props.fill!=="none"}):new nc({points:s})}component(e){return d.jsx(mi,{children:d.jsx($E,{shape:e})})}indicator(e){var u;const n=Fl(e.props.segments);let r=(fn[e.props.size]+1)*e.props.scale;const s=this.editor.getZoomLevel();!(s<.5&&s<1.5/r)&&!e.props.isPen&&e.props.dash==="draw"&&n.length===1&&(r+=cs(e.id)()*(r/6));const i=e.props.isComplete||((u=Ht(e.props.segments))==null?void 0:u.type)==="straight",a=sw(e.props,r,i,!0),l=Bs(n,a),c=l.length>1?va(l,e.props.isClosed):h5(n[0],r);return d.jsx("path",{d:c})}toSvg(e,n){n.addExportDef(k1(e.props.fill));const r=1/e.props.scale;return d.jsx("g",{transform:`scale(${r})`,children:d.jsx($E,{shape:e,zoomOverride:1})})}getCanvasSvgDefs(){return[T1()]}onResize(e,n){const{scaleX:r,scaleY:s}=n,o=[];for(const i of e.props.segments)o.push({...i,points:i.points.map(({x:a,y:l,z:c})=>({x:io(r*a),y:io(s*l),z:c}))});return{props:{segments:o}}}expandSelectionOutlinePx(e){const n=e.props.dash==="draw"?1.6:1;return fn[e.props.size]*n/2*e.props.scale}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,segments:d5(e.props.segments,n.props.segments,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(Pf,"type","draw"),I(Pf,"props",jA),I(Pf,"migrations",OA);function h5(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 bS(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function $E({shape:t,zoomOverride:e}){var p;const n=zr(),r=z(),s=Fl(t.props.segments),o=t.props.isComplete||((p=Ht(t.props.segments))==null?void 0:p.type)==="straight";let i=(fn[t.props.size]+1)*t.props.scale;const a=U("force solid",()=>{const g=e??r.getZoomLevel();return g<.5&&g<1.5/i},[r,i,e]),l=U("dot adjustment",()=>(e??r.getZoomLevel())<.2?0:.1,[r,e]);!a&&!t.props.isPen&&t.props.dash==="draw"&&s.length===1&&(i+=cs(t.id)()*(i/6));const c=sw(t.props,i,o,a);if(!a&&t.props.dash==="draw")return d.jsxs(d.Fragment,{children:[t.props.isClosed&&t.props.fill&&s.length>1?d.jsx(sn,{d:va(Bs(s,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(s,c),strokeLinecap:"round",fill:n[t.props.color].solid})]});const u=Bs(s,c),h=u.length<2,f=h?h5(s[0],0):va(u,t.props.isClosed);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{d:f,theme:n,color:t.props.color,fill:h||t.props.isClosed?t.props.fill:"none",scale:t.props.scale}),d.jsx("path",{d:f,strokeLinecap:"round",fill:h?n[t.props.color].solid:"none",stroke:n[t.props.color].solid,strokeWidth:i,strokeDasharray:h?"none":jce(t,i,l),strokeDashoffset:"0"})]})}function Oce(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Dce(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const s of t)if(f5(s.hostnames,r)){const o=s.fromEmbedUrl(e);if(o)return{definition:s,url:o,embedUrl:e}}}const Rce=t=>t.split("*").map(e=>Oce(e)).join(".+"),f5=(t,e)=>!!t.find(n=>{const r=new RegExp(Rce(n));return e.match(r)});function Lce(t,e){const n=ge(e);if(!n)return;const r=n.host.replace("www.","");for(const s of t)if(f5(s.hostnames,r)){const o=s.toEmbedUrl(e);if(o)return{definition:s,embedUrl:o,url:e}}}function $ce(t,e){try{return Lce(t,e)??Dce(t,e)}catch{return}}const Fce=t=>Object.entries(t).filter(([e,n])=>n).map(([e])=>e).join(" "),so=class so extends oc{static setEmbedDefinitions(e){so.embedDefinitions=e}getEmbedDefinitions(){return so.embedDefinitions}getEmbedDefinition(e){return $ce(so.embedDefinitions,e)}getText(e){return e.props.url}hideSelectionBoundsFg(e){return!this.canResize(e)}canEdit(){return!0}canResize(e){var n,r;return!!((r=(n=this.getEmbedDefinition(e.props.url))==null?void 0:n.definition)!=null&&r.doesResize)}canEditInReadOnly(){return!0}getDefaultProps(){return{w:300,h:300,url:""}}isAspectRatioLocked(e){const n=this.getEmbedDefinition(e.props.url);return(n==null?void 0:n.definition.isAspectRatioLocked)??!1}onResize(e,n){const r=this.isAspectRatioLocked(e),s=this.getEmbedDefinition(e.props.url);let o=(s==null?void 0:s.definition.minWidth)??200,i=(s==null?void 0:s.definition.minHeight)??200;if(r){const a=e.props.w/e.props.h;a>1?o*=a:i/=a}return Yg(e,n,{minWidth:o,minHeight:i})}component(e){const n=gd(),{w:r,h:s,url:o}=e.props,i=Xg(e.id),a=this.getEmbedDefinition(o),l=U("is hovering",()=>{const{editingShapeId:p,hoveredShapeId:g}=this.editor.getCurrentPageState();if(p&&g!==p){const m=this.editor.getShape(p);if(m&&this.editor.isShapeOfType(m,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(e).rotation();if(n)return d.jsx(hi,{className:"tl-embed-container",id:e.id,children:d.jsx("div",{className:"tl-embed",style:{border:0,boxShadow:qp(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:(a==null?void 0:a.definition.backgroundColor)??"var(--color-background)",width:r,height:s}})});const u=i||l;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const p=a.url.split("/").pop();if(!p)throw Error("No gist id!");return d.jsx(hi,{className:"tl-embed-container",id:e.id,children:d.jsx(Nce,{id:p,width:N(r),height:N(s),isInteractive:u,pageRotation:c})})}const f=Fce({...Woe,...(a==null?void 0:a.definition.overridePermissions)??{}});return d.jsx(hi,{className:"tl-embed-container",id:e.id,children:a!=null&&a.definition?d.jsx("iframe",{className:"tl-embed",sandbox:f,src:a.embedUrl,width:N(r),height:N(s),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:qp(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(e){const n=this.getEmbedDefinition(e.props.url);return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h),rx:(n==null?void 0:n.definition.overrideOutlineRadius)??8,ry:(n==null?void 0:n.definition.overrideOutlineRadius)??8})}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}};I(so,"type","embed"),I(so,"props",DA),I(so,"migrations",RA),I(so,"embedDefinitions",g1);let Zp=so;function Nce({id:t,isInteractive:e,width:n,height:r,style:s,pageRotation:o}){if(!t.match(/^[0-9a-f]+$/))throw Error("No gist id!");return d.jsx("iframe",{className:"tl-embed",draggable:!1,width:N(n),height:N(r),frameBorder:"0",scrolling:"no",referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:e?"all":"none",zIndex:e?"":"-1",boxShadow:qp(o)},srcDoc:`
|
|
368
|
+
<html>
|
|
369
|
+
<head>
|
|
370
|
+
<base target="_blank">
|
|
371
|
+
</head>
|
|
372
|
+
<body>
|
|
373
|
+
<script src=${`https://gist.github.com/${t}.js`}><\/script>
|
|
374
|
+
<style type="text/css">
|
|
375
|
+
* { margin: 0px; }
|
|
376
|
+
table { height: 100%; background-color: red; }
|
|
377
|
+
.gist { background-color: none; height: 100%; }
|
|
378
|
+
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
379
|
+
</style>
|
|
380
|
+
</body>
|
|
381
|
+
</html>`})}function ow(t,e){const s=((ea(t.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4;return Math.floor(s)}function FE(t,e,n){const r=t.textMeasure.measureTextSpans(g5(e.props.name,"Frame")+"",n),s=r[0],o=Ht(r),i=o.box.w+o.box.x-s.box.x;return{box:new Z(0,-n.height,i,n.height),spans:r}}function NE(t,e){return{fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:t.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",fill:e,offsetY:-34,offsetX:2}}function p5(t,e,n){const r=n?"":"px",s=n?"":"deg";let o;switch(e){case 0:o="";break;case 3:o=`translate(${N(t.props.w)}${r}, 0${r}) rotate(90${s})`;break;case 2:o=`translate(${N(t.props.w)}${r}, ${N(t.props.h)}${r}) rotate(180${s})`;break;case 1:o=`translate(0${r}, ${N(t.props.h)}${r}) rotate(270${s})`;break;default:throw Error("labelSide out of bounds")}return o}const zce=w.forwardRef(({id:t,name:e,isEditing:n},r)=>{const s=z(),o=w.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Ct(l),l.currentTarget.blur(),s.setEditingShape(null))},[s]),i=w.useCallback(l=>{const c=s.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==h&&s.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,s]),a=w.useCallback(l=>{const c=s.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value;u!==h&&s.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,s]);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:o,onBlur:i,onChange:a}),g5(e,"Frame")+""]})});function Bce({id:t,name:e,width:n,height:r}){const s=z(),{side:o,translation:i}=U("shape rotation",()=>{const c=s.getShape(t);if(!c)return{side:0,translation:"translate(0, 0)"};const u=ow(s,c);return{side:u,translation:p5(c,u,!1)}},[s,t]),a=w.useRef(null),l=Xg(t);return w.useEffect(()=>{const c=a.current;c&&l&&(c.focus(),c.select())},[a,l]),d.jsx("div",{className:"tl-frame-heading",style:{overflow:l?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(o===0||o===2?n:r)}px + var(--space-5))`,bottom:"100%",transform:`${i} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},children:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(zce,{ref:a,id:t,name:e,isEditing:l})})})}function g5(t,e){return t.match(/^\s*$/)?e:t}class Cf extends oc{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){const{editor:n}=this,r=n.getZoomLevel(),s=NE(e,"black"),o=FE(n,e,s),i=ow(n,e);let a,l,c,u;const{w:h,h:f}=o.box,p=Math.min(h,e.props.w*r),g=Math.min(f,e.props.h*r);switch(i){case 0:{a=-8/r,l=(-f-4)/r,c=(p+16)/r,u=f/r;break}case 1:{a=(-f-4)/r,u=(g+16)/r,l=e.props.h-u+8/r,c=f/r;break}case 2:{a=e.props.w-(p+8)/r,l=e.props.h+4/r,c=(g+16)/r,u=f/r;break}case 3:{a=e.props.w+4/r,u=(g+16)/r,l=-8/r,c=f/r;break}}return new $r({children:[new Fs({width:e.props.w,height:e.props.h,isFilled:!1}),new Fs({x:a,y:l,width:c,height:u,isFilled:!0,isLabel:!0})]})}getText(e){return e.props.name}component(e){const n=this.editor.getShapeGeometry(e).bounds,r=zr(),s=U("is creating this shape",()=>{const o=this.editor.getStateDescendant("select.resizing");if(!o||!o.getIsActive())return!1;const i=o==null?void 0:o.info;return i?i.isCreating&&this.editor.getOnlySelectedShapeId()===e.id:!1},[e.id]);return d.jsxs(d.Fragment,{children:[d.jsx(mi,{children:d.jsx("rect",{className:ce("tl-frame__body",{"tl-frame__creating":s}),width:n.width,height:n.height,fill:r.solid,stroke:r.text})}),s?null:d.jsx(Bce,{id:e.id,name:e.props.name,width:n.width,height:n.height})]})}toSvg(e,n){const r=ko({isDarkMode:n.isDarkMode}),s=ow(this.editor,e),o=p5(e,s,!0),i=NE(e,r.text),{box:a,spans:l}=FE(this.editor,e,i),c=nw(this.editor,l,i);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{width:e.props.w,height:e.props.h,fill:r.solid,stroke:r.black.solid,strokeWidth:1,rx:1,ry:1}),d.jsxs("g",{transform:o,children:[d.jsx("rect",{x:a.x-8,y:a.y-4,width:a.width+20,height:a.height,fill:r.background,rx:4,ry:4}),c]})]})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx("rect",{width:N(n.width),height:N(n.height),className:"tl-frame-indicator"})}canReceiveNewChildrenOfType(e,n){return!e.isLocked}providesBackgroundForChildren(){return!0}canDropShapes(e,n){return!e.isLocked}onDragShapesOver(e,n){n.every(r=>r.parentId===e.id)||this.editor.reparentShapes(n,e.id)}onDragShapesOut(e,n){const r=this.editor.getShape(e.parentId);r&&this.editor.isShapeOfType(r,"group")?this.editor.reparentShapes(n,r.id):this.editor.reparentShapes(n,this.editor.getCurrentPageId())}onResize(e,n){return Yg(e,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}I(Cf,"type","frame"),I(Cf,"props",LA),I(Cf,"migrations",$A);function zE(t,e){return t>e?(De*(e/2)+(t-e))*2:(De*(t/2)+(e-t))*2}function m5(t,e){return O1(t,e).map((n,r)=>n.getSvgPathData(r===0)).join(" ")+" Z"}function Uce(t,e,n,r){const s=t/4,o=e/4,i=cs(r),a=n*.75,l=S=>S.addXY(i()*a,i()*a),c=new x(t/2,e),u=new x(0,o*1.2),h=new x(t/2,o*.9),f=new x(t,o*1.2),p=l(new x(t/2,e)),g=l(new x(0,o*1.2)),m=l(new x(t/2,o*.9)),v=l(new x(t,o*1.2));return[new an({start:c,cp1:new x(s*1.5,o*3),cp2:new x(0,o*2.5),end:u}),new an({start:u,cp1:new x(0,-o*.32),cp2:new x(s*1.85,-o*.32),end:h}),new an({start:h,cp1:new x(s*2.15,-o*.32),cp2:new x(t,-o*.32),end:f}),new an({start:f,cp1:new x(t,o*2.5),cp2:new x(s*2.5,o*3),end:p}),new an({start:p,cp1:new x(s*1.5,o*3),cp2:new x(0,o*2.5),end:g}),new an({start:g,cp1:new x(0,-o*.32),cp2:new x(s*1.85,-o*.32),end:m}),new an({start:m,cp1:new x(s*2.15,-o*.32),cp2:new x(t,-o*.32),end:v}),new an({start:v,cp1:new x(t,o*2.5),cp2:new x(s*2.5,o*3),end:c})].map((S,b)=>S.getSvgPathData(b===0)).join(" ")+" Z"}function O1(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 Hce(t){return{size:1+t,thinning:.25,end:{taper:t},start:{taper:t},streamline:0,smoothing:1,simulatePressure:!1}}function Kce(t,e,n,r){const s=cs(t),o=e/2,i=n/2,a=rj(o,i),l=[],c=Fe*s(),u=Fe+Ze/2+Math.abs(s())*Ze,h=Math.max(16,a/10);for(let f=0;f<h;f++){const p=f/(h-1),g=c+p*u,m=Math.cos(g),v=Math.sin(g);l.push(new x(o*m+e*.5+.05*s(),i*v+n/2+.05*s(),Math.min(1,.5+Math.abs(.5-(s()>0?Dt.easeInOutSine(p):Dt.easeInExpo(p)))/2)))}return Bs(l,Hce(r))}function Wce(t,e,n,r){return va(Kce(t,e,n,r))}function iw(t){let e="M";const n=t.length;let r,s,o;for(let i=0,a=n;i<a;i+=3)r=t[i],s=t[i+1],o=t[i+2],e+=`${je(r)}L${je(s)}Q${je(o)}`;return e+=`${je(t[0])}`,e}function aw(t,e,n,r,s){const o=[],i=cs(t);let a=e[0],l;const c=e.length;for(let u=0,h=c*s;u<h;u++){l=x.AddXY(e[(u+1)%c],i()*n,i()*n);const f=x.Sub(l,a),p=x.Len(f),g=x.Div(f,p).mul(Math.min(p/4,r));o.push(x.Add(a,g),x.Add(l,g.neg()),l),a=l}return o}function Gce(t,e,n){const r=Math.min(t,e)/2,s=Math.max(t,e)-r*2,i=(Math.PI*(r*2)+2*s)/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(ha(h.center,r,h.startAngle+l/r)),l+=i;let f=h.type==="straight"?s:De*r;for(;l>f;)l-=f,a.push(a.shift()),f=a[0].type==="straight"?s:De*r}return c}const Vce={s:50,m:70,l:100,xl:130},Yce=.2;function Pm(t,e,n,r,s){const o=cs(n),i=zE(t,e),a=Math.max(Math.ceil(i/Vce[r]),6,Math.ceil(i/Math.min(t,e))),l=i/a*Yce,c=Math.max(t-l*2,1),u=Math.max(e-l*2,1),f=zE(c,u)/a,p=(t-c)/2,g=(e-u)/2,m=Gce(c,u,a).map(P=>P.addXY(p,g)),v=t<20?0:l*.3,y=e<20?0:l*.3,S=m.slice(0);for(let P=0;P<Math.floor(a/2);P++)S[P]=x.AddXY(S[P],o()*v*s,o()*y*s),S[a-P-1]=x.AddXY(S[a-P-1],o()*v*s,o()*y*s);const b=[];for(let P=0;P<S.length;P++){const C=P===S.length-1?0:P+1,_=S[P],E=S[C],k=m[P],D=m[C],T=x.Dist(k,D),j=f-T,M=x.Dist(_,E)/T,O=(Math.max(p,g)+j)*M,F=x.Lrp(k,D,.5).add(x.Sub(D,k).uni().per().mul(O));F.x<0?F.x=0:F.x>t&&(F.x=t),F.y<0?F.y=0:F.y>e&&(F.y=e);const B=db(_,E,F),K=x.Dist(B||x.Average([_,E]),_);b.push({leftPoint:_,rightPoint:E,arcPoint:F,center:B,radius:K})}return b}function Xce(t,e,n,r,s){const o=[],i=Pm(t,e,n,r,s);for(const{center:a,radius:l,leftPoint:c,rightPoint:u}of i)o.push(...yX(c,u,a,l,10));return o}function lw(t,e,n,r,s){const o=Pm(t,e,n,r,s);let i=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:a,rightPoint:l,radius:c,center:u}of o){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 qce={s:.5,m:.7,l:.9,xl:1.6};function Zce(t,e,n,r,s){const o=cs(n),i=qce[r]*s,a=Pm(t,e,n,r,s),u=a.reduce((g,m)=>g+x.Dist2(m.leftPoint,m.rightPoint),0)/a.length>(i*15)**2?g=>x.AddXY(g,o()*i*2,o()*i*2):g=>g;let h=`M${a[0].leftPoint.toFixed()}`,f=u(a[0].leftPoint),p=`M${f.toFixed()}`;for(const{leftPoint:g,center:m,rightPoint:v,radius:y,arcPoint:S}of a){if(m===null){h+=` L${v.toFixed()}`;const k=u(v);p+=` L${k.toFixed()}`,f=k;continue}const b=x.Clockwise(g,v,m)?"0":"1";h+=` A${N(y)},${N(y)} 0 ${b},1 ${v.toFixed()}`;const P=u(v),C=u(S),_=db(f,P,C);if(!_){p+=` L${P.toFixed()}`,f=P;continue}const E=Math.abs(x.Dist(_,f));p+=` A${N(E)},${N(E)} 0 ${b},1 ${P.toFixed()}`,f=P}return h+p+" Z"}function cw(t,e){switch(t.geo){case"x-box":return Qce(t.w,t.h,e,t.dash);case"check-box":return Jce(t.w,t.h);default:return}}function Qce(t,e,n,r){const s=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 o=a=>Math.max(0,Math.min(t,a)),i=a=>Math.max(0,Math.min(e,a));return[[new x(o(n*s),i(n*s)),new x(o(t-n*s),i(e-n*s))],[new x(o(n*s),i(e-n*s)),new x(o(t-n*s),i(n*s))]]}function Jce(t,e){const n=Math.min(t,e)*.82,r=(t-n)/2,s=(e-n)/2,o=a=>Math.max(0,Math.min(t,a)),i=a=>Math.max(0,Math.min(e,a));return[[new x(o(r+n*.25),i(s+n*.52)),new x(o(r+n*.45),i(s+n*.82))],[new x(o(r+n*.45),i(s+n*.82)),new x(o(r+n*.82),i(s+n*.22))]]}function BE({shape:t,shouldScale:e,forceSolid:n}){const r=e?t.props.scale:1,s=z(),o=zr(),{id:i,props:a}=t,{w:l,color:c,fill:u,dash:h,growY:f,size:p,scale:g}=a,m=fn[p]*r,v=a.h+f;switch(a.geo){case"cloud":if(h==="solid"){const y=lw(l,v,i,p,g);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}else if(h==="draw"){const y=Zce(l,v,i,p,g);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}else{const y=lw(l,v,i,p,g),S=Pm(l,v,i,p,g);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("g",{strokeWidth:m,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:S.map(({leftPoint:b,rightPoint:P,center:C,radius:_},E)=>{const k=C?_*ea(ea(x.Angle(C,P))-ea(x.Angle(C,b))):x.Dist(b,P),{strokeDasharray:D,strokeDashoffset:T}=qr(k,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("path",{d:C?`M${b.x},${b.y}A${_},${_},0,0,1,${P.x},${P.y}`:`M${b.x},${b.y}L${P.x},${P.y}`,strokeDasharray:D,strokeDashoffset:T},E)})})]})}case"ellipse":{const y=e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t),S=y.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=y.length,{strokeDasharray:P,strokeDashoffset:C}=qr(b<64?b*2:b,m,{style:h,snap:4,closed:!0,forceSolid:n});return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,strokeWidth:m,fill:"none",stroke:o[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else{const P=(e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t)).getSvgPathData(!0);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:P,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}}case"oval":{const y=e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t),S=y.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=y.getLength(),{strokeDasharray:P,strokeDashoffset:C}=qr(b<64?b*2:b,m,{style:h,snap:4,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,strokeWidth:m,fill:"none",stroke:o[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}case"heart":if(h==="dashed"||h==="dotted"||h==="solid"){const y=m5(l,v),S=O1(l,v);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),S.map((b,P)=>{const{strokeDasharray:C,strokeDashoffset:_}=qr(b.length,m,{style:h,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsx("path",{d:b.getSvgPathData(),strokeWidth:m,fill:"none",stroke:o[c].solid,strokeDasharray:C,strokeDashoffset:_,pointerEvents:"all"},`curve_${P}`)})]})}else{const y=Uce(l,v,m,t.id);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}default:{const y=e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t),S=y instanceof $r?y.children[0].vertices:y.vertices,b=cw(t.props,m);if(h==="solid"){let P="M"+S[0]+"L"+S.slice(1)+"Z";if(b)for(const[C,_]of b)P+=`M${C.x},${C.y}L${_.x},${_.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:P,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}else if(h==="dashed"||h==="dotted"){const P="M"+S[0]+"L"+S.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:P,color:c,fill:u,scale:r}),d.jsxs("g",{strokeWidth:m,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(S.length)).map((C,_)=>{const E=x.ToFixed(S[_]),k=x.ToFixed(S[(_+1)%S.length]),D=x.Dist(E,k),{strokeDasharray:T,strokeDashoffset:j}=qr(D,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("line",{x1:E.x,y1:E.y,x2:k.x,y2:k.y,strokeDasharray:T,strokeDashoffset:j},_)}),b&&b.map(([C,_],E)=>{const k=x.Dist(C,_),{strokeDasharray:D,strokeDashoffset:T}=qr(k,m,{style:h,start:"skip",end:"skip",snap:h==="dotted"?4:void 0,forceSolid:n});return d.jsx("path",{d:`M${C.x},${C.y}L${_.x},${_.y}`,stroke:o[c].solid,strokeWidth:m,fill:"none",strokeDasharray:D,strokeDashoffset:T},`line_fg_${E}`)})]})]})}else if(h==="draw"){let P=iw(aw(i,S,m/3,m*2,2));if(b)for(const[_,E]of b)P+=`M${_.toFixed()}L${E.toFixed()}`;const C=iw(aw(i,S,0,m*2,1));return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:C,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}}}}const UE=17*3;class _f extends oc{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),s=n/2,o=r/2,i=e.props.fill!=="none";let a;switch(e.props.geo){case"cloud":{a=new vt({points:Xce(n,r,e.id,e.props.size,e.props.scale),isFilled:i});break}case"triangle":{a=new vt({points:[new x(s,0),new x(n,r),new x(0,r)],isFilled:i});break}case"diamond":{a=new vt({points:[new x(s,0),new x(n,o),new x(s,r),new x(0,o)],isFilled:i});break}case"pentagon":{a=new vt({points:By(n,r,5),isFilled:i});break}case"hexagon":{a=new vt({points:By(n,r,6),isFilled:i});break}case"octagon":{a=new vt({points:By(n,r,8),isFilled:i});break}case"ellipse":{a=new hte({width:n,height:r,isFilled:i});break}case"oval":{a=new fte({width:n,height:r,isFilled:i});break}case"star":{const S=Fe/5/2,b=Math.floor(5/4)*2,P=5*2-b,C=0,_=Math.floor(5/2)*2,E=Math.cos(-Ze+b*S)*n/2,k=Math.cos(-Ze+P*S)*n/2,D=Math.sin(-Ze+C*S)*r/2,T=Math.sin(-Ze+_*S)*r/2,j=n-Math.abs(E-k),L=r-Math.abs(T-D),M=n/2+k-(n/2-E),O=r/2+D-(r/2-T),F=1,B=(n-M)/2,K=(r-O)/2,R=(n+j)/2,H=(r+L)/2,X=R*F/2,te=H*F/2;a=new vt({points:Array.from(Array(5*2)).map((le,de)=>{const Me=-Ze+de*S;return new x(B+(de%2?X:R)*Math.cos(Me),K+(de%2?te:H)*Math.sin(Me))}),isFilled:i});break}case"rhombus":{const y=Math.min(n*.38,r*.38);a=new vt({points:[new x(y,0),new x(n,0),new x(n-y,r),new x(0,r)],isFilled:i});break}case"rhombus-2":{const y=Math.min(n*.38,r*.38);a=new vt({points:[new x(0,0),new x(n-y,0),new x(n,r),new x(y,r)],isFilled:i});break}case"trapezoid":{const y=Math.min(n*.38,r*.38);a=new vt({points:[new x(y,0),new x(n-y,0),new x(n,r),new x(0,r)],isFilled:i});break}case"arrow-right":{const y=Math.min(n,r)*.38,S=r*.16;a=new vt({points:[new x(0,S),new x(n-y,S),new x(n-y,0),new x(n,r/2),new x(n-y,r),new x(n-y,r-S),new x(0,r-S)],isFilled:i});break}case"arrow-left":{const y=Math.min(n,r)*.38,S=r*.16;a=new vt({points:[new x(y,0),new x(y,S),new x(n,S),new x(n,r-S),new x(y,r-S),new x(y,r),new x(0,r/2)],isFilled:i});break}case"arrow-up":{const y=n*.16,S=Math.min(n,r)*.38;a=new vt({points:[new x(n/2,0),new x(n,S),new x(n-y,S),new x(n-y,r),new x(y,r),new x(y,S),new x(0,S)],isFilled:i});break}case"arrow-down":{const y=n*.16,S=Math.min(n,r)*.38;a=new vt({points:[new x(y,0),new x(n-y,0),new x(n-y,r-S),new x(n,r-S),new x(n/2,r),new x(0,r-S),new x(y,r-S)],isFilled:i});break}case"check-box":case"x-box":case"rectangle":{a=new Fs({width:n,height:r,isFilled:i});break}case"heart":{const S=O1(n,r).reduce((b,P)=>(b.push(...P.vertices),b),[]);a=new vt({points:S,isFilled:i});break}default:Ot(e.props.geo)}const l=Lh(this.editor,e),c=n/e.props.scale,u=r/e.props.scale,h=Math.min(100,c/2),f=Math.min(yo[e.props.size]*pn.lineHeight+Er*2,u/2),p=Math.min(c,Math.max(l.w,Math.min(h,Math.max(1,c-8)))),g=Math.min(u,Math.max(l.h,Math.min(f,Math.max(1,u-8)))),m=cw(e.props,fn[e.props.size]*e.props.scale),v=m?m.map(y=>new nc({points:y})):[];return new $r({children:[a,new Fs({x:e.props.align==="start"?0:e.props.align==="end"?(c-p)*e.props.scale:(c-p)/2*e.props.scale,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?(u-g)*e.props.scale:(u-g)/2*e.props.scale,width:p*e.props.scale,height:g*e.props.scale,isFilled:!0,isLabel:!0}),...v]})}getHandleSnapGeometry(e){const n=this.getGeometry(e),r=n.children[0];switch(e.props.geo){case"arrow-down":case"arrow-left":case"arrow-right":case"arrow-up":case"check-box":case"diamond":case"hexagon":case"octagon":case"pentagon":case"rectangle":case"rhombus":case"rhombus-2":case"star":case"trapezoid":case"triangle":case"x-box":return{outline:r,points:[...r.getVertices(),n.bounds.center]};case"cloud":case"ellipse":case"heart":case"oval":return{outline:r,points:[n.bounds.center]};default:Ot(e.props.geo)}}getText(e){return e.props.text}onEditEnd(e){const{id:n,type:r,props:{text:s}}=e;s.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:s.trimEnd()}}])}component(e){const{id:n,type:r,props:s}=e,{fill:o,font:i,align:a,verticalAlign:l,size:c,text:u}=s,h=zr(),{editor:f}=this,p=U("isGeoOnlySelected",()=>e.id===f.getOnlySelectedShapeId(),[]),m=f.getEditingShapeId()!==null||e.props.text,v=U("force solid",()=>f.getZoomLevel()<.2,[f]);return d.jsxs(d.Fragment,{children:[d.jsx(mi,{children:d.jsx(BE,{shape:e,shouldScale:!0,forceSolid:v})}),m&&d.jsx(hi,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+s.growY},children:d.jsx(bm,{shapeId:n,type:r,font:i,fontSize:yo[c]*e.props.scale,lineHeight:pn.lineHeight,padding:Er*e.props.scale,fill:o,align:a,verticalAlign:l,text:u,isSelected:p,labelColor:h[s.labelColor].solid,wrap:!0})}),e.props.url&&d.jsx($l,{url:e.props.url})]})}indicator(e){const{id:n,props:r}=e,{w:s,size:o}=r,i=r.h+r.growY,a=fn[o],l=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?d.jsx("path",{d:Wce(n,s,i,a)}):d.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:m5(s,i)});case"oval":return d.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:lw(s,i,n,o,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),u=c instanceof $r?c.children[0].vertices:c.vertices;let h;if(r.dash==="draw"){const p=aw(n,u,0,a*2*e.props.scale,1);h=iw(p)}else h="M"+u[0]+"L"+u.slice(1)+"Z";const f=cw(e.props,a);if(f)for(const[p,g]of f)h+=`M${p.x},${p.y}L${g.x},${g.y}`;return d.jsx("path",{d:h})}}}toSvg(e,n){const r={...e,props:{...e.props,w:e.props.w/e.props.scale,h:e.props.h/e.props.scale}},s=r.props;n.addExportDef(k1(s.fill));let o;if(s.text){n.addExportDef(xm(s.font));const i=ko(n),a=new Z(0,0,s.w,s.h+s.growY);o=d.jsx(wm,{fontSize:yo[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,text:s.text,labelColor:i[s.labelColor].solid,bounds:a,padding:16})}return d.jsxs(d.Fragment,{children:[d.jsx(BE,{shouldScale:!1,shape:r,forceSolid:!1}),o]})}getCanvasSvgDefs(){return[T1()]}onResize(e,{handle:n,newPoint:r,scaleX:s,scaleY:o,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*s,h=(l+c)*o,f=0,p=0;const g=UE;if(e.props.text.trim()){let P=Math.max(Math.abs(u),g),C=Math.max(Math.abs(h),g);P<g&&C===g&&(P=g),P===g&&C<g&&(C=g);const _=Lh(this.editor,{...e,props:{...e.props,w:P*e.props.scale,h:C*e.props.scale}}),E=Math.max(Math.abs(u),_.w)*Math.sign(u),k=Math.max(Math.abs(h),_.h)*Math.sign(h);f=Math.abs(E)-Math.abs(u),p=Math.abs(k)-Math.abs(h),u=E,h=k}const m=u*e.props.scale,v=h*e.props.scale,y=new x(0,0);s<0&&(y.x+=m),(n==="left"||n==="top_left"||n==="bottom_left")&&(y.x+=s<0?f:-f),o<0&&(y.y+=v),(n==="top"||n==="top_left"||n==="top_right")&&(y.y+=o<0?p:-p);const{x:S,y:b}=y.rot(e.rotation).add(r);return{x:S,y:b,props:{w:Math.max(Math.abs(m),1),h:Math.max(Math.abs(v),1),growY:0}}}onBeforeCreate(e){if(!e.props.text)return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const n=e.props.h/e.props.scale,r=Lh(this.editor,e).h;let s=null;if(r>n?s=r-n:e.props.growY&&(s=0),s!==null)return{...e,props:{...e.props,growY:s*e.props.scale}}}onBeforeUpdate(e,n){const r=e.props.text,s=n.props.text;if(r===s&&e.props.font===n.props.font&&e.props.size===n.props.size)return;if(r&&!s)return{...n,props:{...n.props,growY:0}};const o=e.props.w/e.props.scale,i=e.props.h/e.props.scale,a=e.props.growY/e.props.scale,l=Lh(this.editor,n);if(!r&&s&&s.length===1){let u=Math.max(o,l.w),h=Math.max(i,l.h);const f=UE;return o<f&&i<f&&(u=Math.max(u,f),h=Math.max(h,f),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>o)return{...n,props:{...n.props,w:l.w*n.props.scale}}}onDoubleClick(e){if(this.editor.inputs.altKey)switch(e.props.geo){case"rectangle":return{...e,props:{geo:"check-box"}};case"check-box":return{...e,props:{geo:"rectangle"}}}}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(_f,"type","geo"),I(_f,"props",FA),I(_f,"migrations",NA);function Lh(t,e){const{text:n,font:r,size:s,w:o}=e.props;if(!n)return{w:0,h:0};const i=t.textMeasure.measureText("w",{...pn,fontFamily:Co[r],fontSize:yo[s],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=t.textMeasure.measureText(n,{...pn,fontFamily:Co[r],fontSize:yo[s],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[s]),Math.ceil(o/e.props.scale-Er*2))});return{w:l.w+Er*2,h:l.h+Er*2}}function eue(){const[t,e]=w.useState(!1);return w.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),s=matchMedia("(color-gamut: p3)");e(r&&s.matches);const o=()=>e(r&&s.matches);return s.addEventListener("change",o),()=>s.removeEventListener("change",o)},[]),U(wt.forceSrgb)||!t?"srgb":"p3"}const HE=.35,KE=.82;class If extends ss{hideResizeHandles(e){return $h(e)}hideRotateHandle(e){return $h(e)}hideSelectionBoundsFg(e){return $h(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(e){const n=Wi(e);if($h(e))return new Ob({x:-n/2,y:-n/2,radius:n/2,isFilled:!0});const{strokePoints:r,sw:s}=WE(e,n,!0),o=j1({strokeWidth:s,showAsComplete:!0});return Sm(r,o),new vt({points:C1(r,o),isFilled:!0})}component(e){const n=PS(this.editor,e),r=Wi(e);return d.jsx(mi,{children:d.jsx(Fh,{shape:e,forceSolid:n,strokeWidth:r,opacity:HE})})}backgroundComponent(e){const n=PS(this.editor,e),r=Wi(e);return d.jsx(mi,{children:d.jsx(Fh,{shape:e,forceSolid:n,strokeWidth:r,opacity:KE})})}indicator(e){const n=PS(this.editor,e),r=Wi(e),{strokePoints:s,sw:o}=WE(e,r,n),i=Fl(e.props.segments);let a;return s.length<2?a=nue(i[0],o):a=va(s,!1),d.jsx("path",{d:a})}toSvg(e){const n=Wi(e),r=n<1.5,s=1/e.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(Fh,{forceSolid:r,strokeWidth:n,shape:e,opacity:HE})})}toBackgroundSvg(e){const n=Wi(e),r=n<1.5,s=1/e.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(Fh,{forceSolid:r,strokeWidth:n,shape:e,opacity:KE})})}onResize(e,n){const{scaleX:r,scaleY:s}=n,o=[];for(const i of e.props.segments)o.push({...i,points:i.points.map(({x:a,y:l,z:c})=>({x:r*a,y:s*l,z:c}))});return{props:{segments:o}}}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,...n.props,segments:d5(e.props.segments,n.props.segments,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(If,"type","highlight"),I(If,"props",UA),I(If,"migrations",HA);function tue(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 nue(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 WE(t,e,n){var l;const r=Fl(t.props.segments),s=t.props.isComplete||((l=Ht(t.props.segments))==null?void 0:l.type)==="straight";let o=e;!n&&!t.props.isPen&&r.length===1&&(o+=cs(t.id)()*(e/6));const i=j1({strokeWidth:o,showAsComplete:s});return{strokePoints:Bs(r,i),sw:o}}function Wi(t){return Rl[t.props.size]*1.12*t.props.scale}function $h(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function Fh({strokeWidth:t,forceSolid:e,shape:n,opacity:r}){var f;const s=zr(),o=Fl(n.props.segments);let i=t;!e&&!n.props.isPen&&o.length===1&&(i+=cs(n.id)()*(i/6));const a=j1({strokeWidth:i,showAsComplete:n.props.isComplete||((f=Ht(n.props.segments))==null?void 0:f.type)==="straight"}),l=Bs(o,a),c=l.length>1?va(l,!1):tue(n.props.segments[0].points[0]),u=eue(),h=s[n.props.color].highlight[u];return d.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function PS(t,e){return U("forceSolid",()=>{const n=Wi(e),r=t.getZoomLevel();return n/r<1.5},[t])}function y5(){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 S5({shapeId:t,assetId:e}){const n=z(),r=!!gd(),s=IQ(),o=w.useMemo(()=>yg(GE,500),[]),[i,a]=w.useState(()=>({asset:e?n.getAsset(e)??null:null,url:null})),l=w.useRef(!1),c=w.useRef(null);return w.useEffect(()=>{if(!e)return;let u=!1,h;const f=As("update state",()=>{if(!r&&n.getCulledShapes().has(t))return;const p=n.getAsset(e);if(!p)return;const g=n.getShape(t);if(!g)return;if(!p.props.src){const y=n.getTemporaryAssetPreview(p.id);if(y){c.current!==y&&(c.current=y,a(S=>({...S,isPlaceholder:!0,url:y})),s());return}}const m=n.getZoomLevel()*(g.props.w/p.props.w);function v(y,S){u||c.current!==S&&(l.current=!0,c.current=S,a({asset:y,url:S}),s())}l.current?(o(n,e,m,r,y=>v(p,y)),h=o.cancel):GE(n,e,m,r,y=>v(p,y))});return()=>{f(),h==null||h(),u=!0}},[n,e,r,s,t,o]),i}function GE(t,e,n,r,s){t.resolveAssetUrl(e,{screenScale:n,shouldResolveToOriginal:r}).then(o=>{s(o)})}async function rue(t){const n=await(await Rs(t)).blob();return Zr.blobToDataUrl(n)}class Ef extends oc{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=Yg(e,n);const{flipX:s,flipY:o}=n.initialShape.props,{scaleX:i,scaleY:a,mode:l}=n;if(r={...r,props:{...r.props,flipX:i<0!==s,flipY:a<0!==o}},!e.props.crop)return r;const c=l==="scale_shape"&&i===-1||l==="resize_bounds"&&s!==r.props.flipX,u=l==="scale_shape"&&a===-1||l==="resize_bounds"&&o!==r.props.flipY,{topLeft:h,bottomRight:f}=e.props.crop;return r.props.crop={topLeft:{x:c?1-f.x:h.x,y:u?1-f.y:h.y},bottomRight:{x:c?1-h.x:f.x,y:u?1-h.y:f.y}},r}component(e){return d.jsx(sue,{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 rue(r)||""),d.jsx(iue,{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}},s=1/(r.bottomRight.x-r.topLeft.x)*e.props.w,o=1/(r.bottomRight.y-r.topLeft.y)*e.props.h,i=new x(r.topLeft.x*s,r.topLeft.y*o).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:s,h:o}};this.editor.updateShapes([a])}getInterpolatedProps(e,n,r){function s(o,i){var h,f,p,g;if(o.props.crop===null&&i.props.crop===null)return null;const a=((h=o.props.crop)==null?void 0:h.topLeft)||{x:0,y:0},l=((f=o.props.crop)==null?void 0:f.bottomRight)||{x:1,y:1},c=((p=i.props.crop)==null?void 0:p.topLeft)||{x:0,y:0},u=((g=i.props.crop)==null?void 0:g.bottomRight)||{x:1,y:1};return{topLeft:{x:_e(a.x,c.x,r),y:_e(a.y,c.y,r)},bottomRight:{x:_e(l.x,u.x,r),y:_e(l.y,u.y,r)}}}return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r),crop:s(e,n)}}}I(Ef,"type","image"),I(Ef,"props",KA),I(Ef,"migrations",WA);const sue=w.memo(function({shape:e}){var y;const n=z(),{asset:r,url:s}=S5({shapeId:e.id,assetId:e.props.assetId}),o=YR(),[i,a]=w.useState(""),[l,c]=w.useState(null),u=oue(n,e);w.useEffect(()=>{if(s&&u){let S=!1;const b=Lu();return b.onload=()=>{if(S)return;const P=document.createElement("canvas");P.width=b.width,P.height=b.height;const C=P.getContext("2d");C&&(C.drawImage(b,0,0),a(P.toDataURL()),c(s))},b.crossOrigin="anonymous",b.src=s,()=>{S=!0}}},[n,u,o,s]);const h=U("show crop preview",()=>e.id===n.getOnlySelectedShapeId()&&n.getCroppingShapeId()===e.id&&n.isIn("select.crop"),[n,e.id]),f=o&&(((y=r==null?void 0:r.props.mimeType)==null?void 0:y.includes("video"))||u),p=v5(e),g=s===l?null:s,m=f?i:l;if(!s&&!(r!=null&&r.props.src))return d.jsxs(hi,{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:ce("tl-image-container",r&&"tl-image-container-loading"),style:p,children:r?null:d.jsx(y5,{})}),"url"in e.props&&e.props.url&&d.jsx($l,{url:e.props.url})]});const v=u?"anonymous":void 0;return d.jsxs(d.Fragment,{children:[h&&m&&d.jsx("div",{style:p,children:d.jsx("img",{className:"tl-image",style:{...pu(e),opacity:.1},crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),d.jsxs(hi,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h},children:[d.jsxs("div",{className:ce("tl-image-container"),style:p,children:[m&&d.jsx("img",{className:"tl-image",style:pu(e),crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},m),g&&d.jsx("img",{className:"tl-image",style:pu(e),crossOrigin:v,src:g,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>c(g)},g)]}),e.props.url&&d.jsx($l,{url:e.props.url})]})]})});function oue(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):void 0;return n?"mimeType"in n.props&&ar.isAnimatedImageType(n==null?void 0:n.props.mimeType)||"isAnimated"in n.props&&n.props.isAnimated:!1}function v5(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,s=1/(e.bottomRight.y-e.topLeft.y)*t.props.h,o=-n.x*r,i=-n.y*s;return{transform:`translate(${o}px, ${i}px)`,width:r,height:s}}function pu(t,e){const{flipX:n,flipY:r}=t.props;if(!n&&!r)return;const s=`scale(${n?-1:1}, ${r?-1:1})`;return{transform:`${e?`translate(${n?e.width:0}px, ${r?e.height:0}px)`:""} ${s}`,transformOrigin:e?"0 0":"center center"}}function iue({shape:t,src:e}){const n=Jl(),r=v5(t),s=t.props.crop;if(r.transform&&s){const{transform:o,width:i,height:a}=r,l=(s.bottomRight.x-s.topLeft.x)*i,c=(s.bottomRight.y-s.topLeft.y)*a,u=[new x(0,0),new x(l,0),new x(l,c),new x(0,c)],h=pu(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(f=>`${f.x},${f.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${n})`,children:d.jsx("image",{href:e,width:i,height:a,style:h?{...h,transform:`${o} ${h.transform}`}:{transform:o}})})]})}else return d.jsx("image",{href:e,width:t.props.w,height:t.props.h,style:pu(t,{width:t.props.w,height:t.props.h})})}function x5(t){return{size:t,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function w5(t,e,n){const r=e.vertices,s=x5(n);return Bs(r,s)}function aue(t,e,n){const r=x5(n);return C1(Sm(w5(t,e,n),r),r)}function lue(t,e,n){const r=aue(t,e,n);return gb(r)}function cue(t,e,n){if(t.props.dash==="draw"){const r=w5(t,e,n);return va(r)}return e.getSvgPathData()}function b5(t,e,n){let r=`M ${je(e[0])}L`,s=`M ${je(e[0])}L`;const o=n/3,i=n*2,a=cs(t);let l=e[0],c,u=e[0],h;const f=e.length;for(let p=0,g=f-1;p<g;p++){c=e[p+1],h=x.AddXY(e[p+1],a()*o,a()*o);const m=x.Sub(c,l),v=x.Len(m),y=x.Div(m,v).mul(Math.min(v/4,i)),S=x.Add(l,y),b=x.Add(c,y.neg()),P=x.Sub(h,u),C=x.Len(P),_=x.Div(P,C).mul(Math.min(C/4,i)),E=x.Add(u,_),k=x.Add(h,_.neg());p===g-1?(r+=`${je(S)}L ${je(c)}`,s+=`${je(E)}L ${je(h)}`):(r+=`${je(S)}L ${je(b)}Q ${je(c)}`,s+=`${je(E)}L ${je(k)}Q ${je(h)}`,l=c,u=h)}return[r,r+s]}const uue=new Ds;class kf extends ss{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,n]=Fu(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[e]:{id:e,index:e,x:0,y:0},[n]:{id:n,index:n,x:.1,y:.1}},scale:1}}getGeometry(e){return qc(e)}getHandles(e){return uue.get(e.props,()=>{const n=qc(e),r=Xc(e),s=r.map(o=>({...o,id:o.index,type:"vertex",canSnap:!0}));for(let o=0;o<r.length-1;o++){const i=$u(r[o].index,r[o+1].index),l=n.segments[o].midPoint();s.push({id:i,type:"create",index:i,x:l.x,y:l.y,canSnap:!0})}return s.sort(cn)})}onResize(e,n){const{scaleX:r,scaleY:s}=n;return{props:{points:rd(e.props.points,(o,{id:i,index:a,x:l,y:c})=>({id:i,index:a,x:l*r,y:c*s}))}}}onBeforeCreate(e){const{props:{points:n}}=e,r=Object.keys(n);if(r.length<2)return;const s=n[r[0]];if(r.every(i=>{const a=n[i];return a.x===s.x&&a.y===s.y})){const i=r[r.length-1];return n[i]={...n[i],x:n[i].x+.1,y:n[i].y+.1},e}}onHandleDrag(e,{handle:n}){if(n.type!=="vertex")return;const r=is(new x(n.x,n.y),this.editor);return{...e,props:{...e.props,points:{...e.props.points,[n.id]:{id:n.id,index:n.index,x:r.x,y:r.y}}}}}component(e){return d.jsx(mi,{children:d.jsx(VE,{shape:e})})}indicator(e){const n=ks[e.props.size]*e.props.scale,r=qc(e),{dash:s}=e.props;let o;if(e.props.spline==="line"){const i=r.points;if(s==="solid"||s==="dotted"||s==="dashed")o="M"+i[0]+"L"+i.slice(1);else{const[a]=b5(e.id,i,n);o=a}}else o=cue(e,r,n);return d.jsx("path",{d:o})}toSvg(e){return d.jsx(VE,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const n=Xc(e);return{points:n,getSelfSnapPoints:r=>{const s=this.getHandles(e).filter(o=>o.type==="vertex").findIndex(o=>o.id===r.id);return n.filter((o,i)=>Math.abs(i-s)>1).map(x.From)},getSelfSnapOutline:r=>{const s=this.getHandles(e).filter(i=>i.type==="vertex").findIndex(i=>i.id===r.id),o=qc(e).segments.filter((i,a)=>a!==s-1&&a!==s);return o.length?new $r({children:o}):null}}}getInterpolatedProps(e,n,r){const s=Xc(e),o=Xc(n),i=[],a=[];let l=VT;if(s.length>o.length)for(let c=0;c<s.length;c++)i[c]={...s[c]},o[c]===void 0?a[c]={...o[o.length-1],id:l}:a[c]={...o[c],id:l},l=_s(l);else if(o.length>s.length)for(let c=0;c<o.length;c++)a[c]={...o[c]},s[c]===void 0?i[c]={...s[s.length-1],id:l}:i[c]={...s[c],id:l},l=_s(l);else for(let c=0;c<o.length;c++)i[c]=s[c],a[c]=o[c];return{...r>.5?n.props:e.props,points:Object.fromEntries(i.map((c,u)=>{const h=a[u];return[c.id,{...c,x:_e(c.x,h.x,r),y:_e(c.y,h.y,r)}]})),scale:_e(e.props.scale,n.props.scale,r)}}}I(kf,"type","line"),I(kf,"props",GA),I(kf,"migrations",VA);function Xc(t){return Object.values(t.props.points).sort(cn)}function qc(t){const e=Xc(t).map(x.From);switch(t.props.spline){case"cubic":return new dte({points:e});case"line":return new nc({points:e})}}function VE({shape:t,shouldScale:e=!1,forceSolid:n=!1}){const r=zr(),s=qc(t),{dash:o,color:i,size:a}=t.props,l=1/t.props.scale,c=e?l:1,u=ks[a]*t.props.scale;if(t.props.spline==="line"){if(o==="solid"){const h=s.points,f="M"+h[0]+"L"+h.slice(1);return d.jsx("path",{d:f,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:s.segments.map((h,f)=>{const{strokeDasharray:p,strokeDashoffset:g}=n?{strokeDasharray:"none",strokeDashoffset:"none"}:qr(h.length,u,{style:o,start:f>0?"outset":"none",end:f<s.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:p,strokeDashoffset:g,d:h.getSvgPathData(!0),fill:"none"},f)})});if(o==="draw"){const h=s.points,[f,p]=b5(t.id,h,u);return d.jsx("path",{d:p,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}}if(t.props.spline==="cubic"){const h=s.getSvgPathData();if(o==="solid")return d.jsx("path",{strokeWidth:u,stroke:r[i].solid,fill:"none",d:h,transform:`scale(${c})`});if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:s.segments.map((f,p)=>{const{strokeDasharray:g,strokeDashoffset:m}=qr(f.length,u,{style:o,start:p>0?"outset":"none",end:p<s.segments.length-1?"outset":"none",forceSolid:n});return d.jsx("path",{strokeDasharray:g,strokeDashoffset:m,d:f.getSvgPathData(),fill:"none"},p)})});if(o==="draw")return d.jsx("path",{d:lue(t,s,u),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${c})`})}}class Tf extends ss{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:s}=e.props,o=n*s,i=r*s,a=He*s,l=Nh(e);return new $r({children:[new Fs({width:a,height:l,isFilled:!0}),new Fs({x:e.props.align==="start"?0:e.props.align==="end"?a-i:(a-i)/2,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?l-o:(l-o)/2,width:i,height:o,isFilled:!0,isLabel:!0})]})}getHandles(e){const{scale:n}=e.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const s=this.editor.getZoomLevel();if(s*n<.25)return[];const o=Nh(e),i=He*n,a=Tle/s*n;return s*n<.5?[{id:"bottom",index:"a3",type:"clone",x:i/2,y:o+a}]:[{id:"top",index:"a1",type:"clone",x:i/2,y:-a},{id:"right",index:"a2",type:"clone",x:i+a,y:o/2},{id:"bottom",index:"a3",type:"clone",x:i/2,y:o+a},{id:"left",index:"a4",type:"clone",x:-a,y:o/2}]}getText(e){return e.props.text}component(e){const{id:n,type:r,props:{labelColor:s,scale:o,color:i,font:a,size:l,align:c,text:u,verticalAlign:h,fontSizeAdjustment:f}}=e,p=fue(n),g=zr(),m=He*o,v=Nh(e),y=U("shape rotation",()=>{var C;return((C=this.editor.getShapePageTransform(n))==null?void 0:C.rotation())??0},[this.editor]),S=U("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),b=U("dark mode",()=>this.editor.user.getIsDarkMode(),[this.editor]),P=e.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:n,className:"tl-note__container",style:{width:m,height:v,backgroundColor:g[i].note.fill,borderBottom:S?b?`${2*o}px solid rgb(20, 20, 20)`:`${2*o}px solid rgb(144, 144, 144)`:"none",boxShadow:S?"none":pue(e.id,y,o)},children:d.jsx(bm,{shapeId:n,type:r,font:a,fontSize:(f||yo[l])*o,lineHeight:pn.lineHeight,align:c,verticalAlign:h,text:u,isNote:!0,isSelected:P,labelColor:s==="black"?g[i].note.text:g[s].fill,wrap:!0,padding:16*o,onKeyDown:p})}),"url"in e.props&&e.props.url&&d.jsx($l,{url:e.props.url})]})}indicator(e){const{scale:n}=e.props;return d.jsx("rect",{rx:n,width:N(He*n),height:N(Nh(e))})}toSvg(e,n){e.props.text&&n.addExportDef(xm(e.props.font));const r=ko({isDarkMode:n.isDarkMode}),s=gue(e);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:He-10,height:s.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:He,height:s.h,fill:r[e.props.color].note.fill}),d.jsx(wm,{fontSize:e.props.fontSizeAdjustment||yo[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:s,stroke:!1})]})}onBeforeCreate(e){return YE(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 YE(this.editor,n)}onEditEnd(e){const{id:n,type:r,props:{text:s}}=e;s.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:s.trimEnd()}}])}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,scale:_e(e.props.scale,n.props.scale,r)}}}I(Tf,"type","note"),I(Tf,"props",YA),I(Tf,"migrations",XA);function YE(t,e){const{labelHeight:n,fontSizeAdjustment:r}=P5(t,e),s=Math.max(0,n-He);if(s!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:s,fontSizeAdjustment:r}}}function due(t,e){const{text:n}=e.props;if(!n)return{labelHeight:yo[e.props.size]*pn.lineHeight+Er*2,labelWidth:100,fontSizeAdjustment:0};const r=yo[e.props.size];let s=0,o=0,i=He,a=He;const l=1;do{s=Math.min(r,r-o);const c=t.textMeasure.measureText(n,{...pn,fontFamily:Co[e.props.font],fontSize:s,maxWidth:He-Er*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Er*2,a=c.w+Er*2,s<=14){const u=t.textMeasure.measureText(n,{...pn,fontFamily:Co[e.props.font],fontSize:s,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(o++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:s}}const hue=new Ds;function P5(t,e){return hue.get(e,()=>due(t,e))}function fue(t){const e=z(),n=ZL();return w.useCallback(r=>{const s=e.getShape(t);if(!s)return;const o=r.key==="Tab",i=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(o||i){r.preventDefault();const a=e.getShapePageTransform(t),l=a.rotation(),c=!!(n.dir==="rtl"||V$(s.props.text)),u=(He+e.options.adjacentShapeMargin+(i&&!r.shiftKey?s.props.growY:0))*s.props.scale,h=new x(o?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(vm.clone().mul(s.props.scale)).rot(l).add(a.point()),f=e5(e,s,h,l);f&&(e.markHistoryStoppingPoint("editing adjacent shape"),Hp(e,f,!0))}},[t,e,n.dir])}function Nh(t){return(He+t.props.growY)*t.props.scale}function pue(t,e,n){const r=cs(t),s=Math.abs(r())+.5,o=Math.cos(e),i=5*n,a=4*n,l=6*n,c=7*n;return`0px ${i-s}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
382
|
+
0px ${(a+s*c)*Math.max(0,o)}px ${l+s*c}px -${a+s*l}px rgba(15, 23, 31, ${(.3+s*.1).toFixed(2)}),
|
|
383
|
+
0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+o)/2)).toFixed(2)})`}function gue(t){return new Z(0,0,He,He+t.props.growY)}function mue(t,{initialBounds:e,scaleX:n,scaleY:r,newPoint:s}){const o=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new x(0,0);n<0&&(i.x=-(e.width*o)),r<0&&(i.y=-(e.height*o));const{x:a,y:l}=x.Add(s,i.rot(t.rotation));return{x:a,y:l,props:{scale:o*t.props.scale}}}const yue=new Ds;class Mf extends ss{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return yue.get(e.props,n=>XE(this.editor,n))}getGeometry(e){const{scale:n}=e.props,{width:r,height:s}=this.getMinDimensions(e);return new Fs({width:r*n,height:s*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:s,text:o,color:i,scale:a,textAlign:l}}=e,{width:c,height:u}=this.getMinDimensions(e),h=e.id===this.editor.getOnlySelectedShapeId(),f=zr(),p=Sue(n);return d.jsx(bm,{shapeId:n,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:Rl[s],lineHeight:pn.lineHeight,align:l,verticalAlign:"middle",text:o,labelColor:f[i].solid,isSelected:h,textWidth:c,textHeight:u,style:{transform:`scale(${a})`,transformOrigin:"top left"},wrap:!0,onKeyDown:p})}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(xm(e.props.font));const r=this.editor.getShapeGeometry(e).bounds,s=r.width/(e.props.scale??1),o=r.height/(e.props.scale??1),i=ko(n);return d.jsx(wm,{fontSize:Rl[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,s,o),padding:0})}onResize(e,n){const{newPoint:r,initialBounds:s,initialShape:o,scaleX:i,handle:a}=n;if(n.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:e.id,type:e.type,...mue(e,n)};{const l=Math.max(1,Math.abs(s.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/o.props.scale,autoSize:!1}}}}onEditEnd(e){const{id:n,type:r,props:{text:s}}=e,o=e.props.text.trimEnd();o.length===0?this.editor.deleteShapes([e.id]):o!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:s.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,s=e.props.text!==n.props.text;if(!r&&!s)return;const o=this.getMinDimensions(e),i=XE(this.editor,n.props),a=o.width*e.props.scale,l=o.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,s?0:(u-l)/2);break}case"end":{h=new x(c-a,s?0:(u-l)/2);break}default:{if(s)break;h=new x(0,(u-l)/2);break}}if(h){h.rot(n.rotation);const{x:f,y:p}=n;return{...n,x:f-h.x,y:p-h.y,props:{...n.props,w:c}}}else return{...n,props:{...n.props,w:c}}}}I(Mf,"type","text"),I(Mf,"props",qA),I(Mf,"migrations",ZA);function XE(t,e){const{font:n,text:r,autoSize:s,size:o,w:i}=e,a=s?16:Math.max(16,i),l=Rl[o],c=s?null:Math.floor(Math.max(a,i)),u=t.textMeasure.measureText(r,{...pn,fontFamily:Co[n],fontSize:l,maxWidth:c});return s&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function Sue(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?Ll.unindent(n.currentTarget):Ll.indent(n.currentTarget);break}}},[e,t])}class Af extends oc{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){return d.jsx(vue,{shape:e})}indicator(e){return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){const n=await xue(this.editor,e);return n?d.jsx("image",{href:n,width:e.props.w,height:e.props.h}):null}}I(Af,"type","video"),I(Af,"props",QA),I(Af,"migrations",JA);const vue=w.memo(function({shape:e}){const n=z(),r=n.getShapeGeometry(e).bounds.w*n.getZoomLevel()>=110,s=Xg(e.id),o=YR(),{Spinner:i}=st(),{asset:a,url:l}=S5({shapeId:e.id,assetId:e.props.assetId}),c=w.useRef(null),[u,h]=w.useState(!1),[f,p]=w.useState(!1);w.useEffect(()=>{const m=()=>p(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",m),()=>document.removeEventListener("fullscreenchange",m)});const g=w.useCallback(m=>{m.currentTarget&&h(!0)},[]);return w.useEffect(()=>{const m=c.current;m&&s&&document.activeElement!==m&&m.focus()},[s,u]),w.useEffect(()=>{if(o){const m=c.current;if(!m)return;m.pause(),m.currentTime=0}},[c,o]),d.jsxs(d.Fragment,{children:[d.jsx(hi,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:a?i&&!a.props.src?d.jsx(i,{}):l?d.jsxs(d.Fragment,{children:[d.jsx("video",{ref:c,style:s?{pointerEvents:"all"}:u?void 0:{display:"none"},className:ce("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":f}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:s&&r,onLoadedData:g,hidden:!u,children:d.jsx("source",{src:l})}),!u&&i&&d.jsx(i,{})]}):null:d.jsx(y5,{})})})}),"url"in e.props&&e.props.url&&d.jsx($l,{url:e.props.url})]})});async function xue(t,e){const n=await t.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});if(!n)return null;const r=await ar.loadVideo(n);return ar.getVideoFrameAsDataUrl(r,0)}const C5=[Mf,bf,Pf,_f,Tf,kf,Cf,wf,If,Zp,Ef,Af];function wue(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 _5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"scribbleId","id");I(this,"markId","");I(this,"excludedShapeIds",new Set)}onEnter(n){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(o=>{if(this.editor.isShapeOrAncestorLocked(o))return!0;if(this.editor.isShapeOfType(o,"group")||this.editor.isShapeOfType(o,"frame")){const i=this.editor.getPointInShapeSpace(o,r);return this.editor.getShapeGeometry(o).bounds.containsPoint(i)}return!1}).map(o=>o.id));const s=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=s.id,this.update()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onExit(){this.editor.setErasingShapes([]),this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}update(){const{editor:n,excludedShapeIds:r}=this,s=n.getErasingShapeIds(),o=n.getZoomLevel(),i=n.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=n;this.pushPointToScribble();const c=new Set(s),u=this.editor.options.hitTestMargin/o;for(const h of i){if(n.isShapeOfType(h,"group"))continue;const f=n.getShapeMask(h.id);if(f&&!hr(a,f))continue;const p=n.getShapeGeometry(h),g=n.getShapePageTransform(h);if(!p||!g)continue;const m=g.clone().invert(),v=m.applyToPoint(l),y=m.applyToPoint(a),{bounds:S}=p;S.minX-u>Math.max(v.x,y.x)||S.minY-u>Math.max(v.y,y.y)||S.maxX+u<Math.min(v.x,y.x)||S.maxY+u<Math.min(v.y,y.y)||p.hitTestLineSegment(v,y,u)&&c.add(n.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}I(_5,"id","erasing");var HS;let bue=(HS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(HS,"id","idle"),HS);var KS;let Pue=(KS=class extends ie{onEnter(){const e=this.editor.getZoomLevel(),n=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,s=new Set,o=s.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")&&s.size>o)break;s.add(c.id)}}this.editor.setErasingShapes([...s])}onLongPress(e){this.startErasing(e)}onExit(e,n){n!=="erasing"&&this.editor.setErasingShapes([])}onPointerMove(e){this.editor.inputs.isDragging&&this.startErasing(e)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}startErasing(e){this.parent.transition("erasing",e)}complete(){const e=this.editor.getErasingShapeIds();e.length&&(this.editor.markHistoryStoppingPoint("erase end"),this.editor.deleteShapes(e)),this.parent.transition("idle")}cancel(){this.parent.transition("idle")}},I(KS,"id","pointing"),KS);class jf extends ie{static children(){return[bue,Pue,_5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(jf,"id","eraser"),I(jf,"initial","idle"),I(jf,"isLockable",!1);class I5 extends ie{constructor(){super(...arguments);I(this,"initialCamera",new x)}onEnter(){this.initialCamera=x.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:s,originScreenPoint:o}=r.inputs,i=x.Sub(s,o).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,s=Math.min(r.len(),2);s>.1&&this.editor.slideCamera({speed:s,direction:r}),this.parent.transition("idle")}}I(I5,"id","dragging");var WS;let Cue=(WS=class extends ie{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(WS,"id","idle"),WS);var GS;let _ue=(GS=class extends ie{onEnter(){this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})}onLongPress(){this.startDragging()}onPointerMove(){this.editor.inputs.isDragging&&this.startDragging()}startDragging(){this.parent.transition("dragging")}onPointerUp(){this.complete()}onCancel(){this.complete()}onComplete(){this.complete()}onInterrupt(){this.complete()}complete(){this.parent.transition("idle")}},I(GS,"id","pointing"),GS);class Of extends ie{static children(){return[Cue,_ue,I5]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomIn(n,{animation:{duration:220,easing:Dt.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomOut(n,{animation:{duration:320,easing:Dt.easeOutQuint}})}}onQuadrupleClick(e){if(e.phase==="settle"){const n=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:r}}=this.editor;n===1?this.editor.zoomToFit({animation:{duration:400,easing:Dt.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:Dt.easeOutQuint}})}}}I(Of,"id","hand"),I(Of,"initial","idle"),I(Of,"isLockable",!1);var VS;let Iue=(VS=class extends ie{onPointerDown(e){this.parent.transition("lasering",e)}},I(VS,"id","idle"),VS);class E5 extends ie{constructor(){super(...arguments);I(this,"scribbleId","id")}onEnter(){const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:this.editor.options.laserDelayMs,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.pushPointToScribble()}onPointerUp(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onCancel(){this.cancel()}onComplete(){this.complete()}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}I(E5,"id","lasering");class Df extends ie{static children(){return[Iue,E5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(Df,"id","laser"),I(Df,"initial","idle"),I(Df,"isLockable",!1);class k5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"initialSelectedShapeIds",[]);I(this,"excludedShapeIds",new Set);I(this,"isWrapMode",!1);I(this,"initialStartShape",null)}onEnter(n){const{altKey:r,currentPagePoint:s}=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(o=>this.editor.isShapeOfType(o,"group")||this.editor.isShapeOrAncestorLocked(o)).map(o=>o.id)),this.info=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(s)[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:s}=this,{inputs:{originPagePoint:o,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=n,c=new Set(a?this.initialSelectedShapeIds:[]),u=s?!l:l,h=Z.FromPoints([o,i]),{corners:f}=h;let p,g,m,v,y,S;const b=n.getCurrentPageRenderingShapesSorted(),P=n.getCurrentPageId();e:for(let E=0,k=b.length;E<k;E++){if(m=b[E],r.has(m.id)||c.has(m.id)||(v=n.getShapePageBounds(m),!v))continue e;if(h.contains(v)){this.handleHit(m,i,P,c,f);continue e}if(u||n.isShapeOfType(m,"frame"))continue e;if(h.collides(v)){if(y=n.getShapePageTransform(m),!y)continue e;S=y.clone().invert().applyToPoints(f);const D=n.getShapeGeometry(m);t:for(let T=0;T<4;T++)if(p=S[T],g=S[(T+1)%4],D.hitTestLineSegment(p,g,0)){this.handleHit(m,i,P,c,f);break t}}}const C=n.getInstanceState().brush;(!C||!h.equals(C))&&n.updateInstanceState({brush:{...h.toJson()}});const _=n.getSelectedShapeIds();(_.length!==c.size||_.some(E=>!c.has(E)))&&n.setSelectedShapes(Array.from(c))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(n,r,s,o,i){if(n.parentId===s){o.add(n.id);return}const a=this.editor.getOutermostSelectableShape(n),l=this.editor.getShapeMask(a.id);l&&!bb(l,i)&&!hr(r,l)||o.add(a.id)}}I(k5,"id","brushing");const Nl={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 T5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){const n=this.editor.getSelectedShapes(),r=Nl[this.info.handle];this.editor.setCursor({type:r,rotation:n.length===1?this.editor.getSelectionRotation():0})}onEnter(n){this.info=n,this.updateCursor()}onPointerMove(){this.editor.inputs.isDragging&&this.startResizing()}onLongPress(){this.startResizing()}startResizing(){this.editor.getIsReadonly()||this.parent.transition("resizing",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}I(T5,"id","pointing_resize_handle");const _r=8;class D1 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"snapshot",{})}onEnter(n){this.info=n,this.markId=this.editor.markHistoryStoppingPoint("cropping"),this.snapshot=this.createSnapshot(),this.updateShapes()}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=Nl[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 o=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=o.crop??this.getDefaultCrop(),u=nt(c),h=new x(n.x,n.y),f=new x(0,0),p=1/(c.bottomRight.x-c.topLeft.x)*o.w,g=1/(c.bottomRight.y-c.topLeft.y)*o.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(g<_r)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/g,g*(u.bottomRight.y-u.topLeft.y)<_r?(u.topLeft.y=u.bottomRight.y-_r/g,f.y=(u.topLeft.y-c.topLeft.y)*g):u.topLeft.y<=0?(u.topLeft.y=0,f.y=(u.topLeft.y-c.topLeft.y)*g):f.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(g<_r)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/g),g*(u.bottomRight.y-u.topLeft.y)<_r&&(u.bottomRight.y=u.topLeft.y+_r/g);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<_r)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/p,p*(u.bottomRight.x-u.topLeft.x)<_r?(u.topLeft.x=u.bottomRight.x-_r/p,f.x=(u.topLeft.x-c.topLeft.x)*p):u.topLeft.x<=0?(u.topLeft.x=0,f.x=(u.topLeft.x-c.topLeft.x)*p):f.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(p<_r)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/p),p*(u.bottomRight.x-u.topLeft.x)<_r&&(u.bottomRight.x=u.topLeft.x+_r/p);break}}if(!m)return;h.add(f.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)*p,h:(u.bottomRight.y-u.topLeft.y)*g}};this.editor.updateShapes([v]),this.updateCursor()}complete(){this.updateShapes(),Xe(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,s=this.editor.getOnlySelectedShape(),o=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(o.getHandlePoint(this.info.handle),o.point,n),a=x.Sub(r,i);return{shape:s,cursorHandleOffset:a}}}I(D1,"id","cropping");function M5(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 A5(t,e,n){if(!e)throw Error("Needs to translate a cropped shape!");const{crop:r}=e.props;if(!r)return;const s=t.inputs.shiftKey?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;s==="x"?n.x=0:s==="y"&&(n.y=0),n.rot(-e.rotation);const o=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/o)),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 YS;let Eue=(YS=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=M5(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 o;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 s=this.editor.getShapeUtil(r);if(s){if(e.target==="selection"){(o=s.onDoubleClickEdge)==null||o.call(s,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"),s=new x(0,0);if(n.has("ArrowLeft")&&(s.x+=1),n.has("ArrowRight")&&(s.x-=1),n.has("ArrowUp")&&(s.y+=1),n.has("ArrowDown")&&(s.y-=1),s.equals(new x(0,0)))return;r&&s.mul(10);const o=this.editor.getShape(this.editor.getCroppingShapeId());if(!o)return;const i=A5(this.editor,o,s);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},I(YS,"id","idle"),YS);class j5 extends ie{onCancel(){this.editor.setCurrentTool("select.crop.idle",{})}onPointerMove(e){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",e)}onPointerUp(e){this.editor.setCurrentTool("select.crop.idle",e)}}I(j5,"id","pointing_crop");class R1 extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const s=Nl[this.info.handle];this.editor.setCursor({type:s,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){this.editor.inputs.isDragging&&this.startCropping()}onLongPress(){this.startCropping()}startCropping(){this.editor.getIsReadonly()||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}onPointerUp(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}I(R1,"id","pointing_crop_handle");class O5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"snapshot",{})}onEnter(n){this.info=n,this.snapshot=this.createSnapshot(),this.markId=this.editor.markHistoryStoppingPoint("translating_crop"),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onKeyDown(n){switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}}onKeyUp(n){switch(n.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const n=this.snapshot.shape;if(!n)return;const{originPagePoint:r,currentPagePoint:s}=this.editor.inputs,o=s.clone().sub(r),i=A5(this.editor,n,o);i&&this.editor.updateShapes([i])}}I(O5,"id","translating_crop");class uw extends ie{constructor(){super(...arguments);I(this,"markId","");I(this,"didExit",!1)}static children(){return[Eue,O5,j5,R1,D1]}onEnter(){this.didExit=!1,this.markId=this.editor.markHistoryStoppingPoint("crop")}onExit(){this.didExit||(this.didExit=!0,this.editor.squashToMark(this.markId))}onCancel(){this.didExit||(this.didExit=!0,this.editor.bailToMark(this.markId))}}I(uw,"id","crop"),I(uw,"initial","idle");class D5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"initialHandle",{});I(this,"initialAdjacentHandle",null);I(this,"initialPagePoint",{});I(this,"markId","");I(this,"initialPageTransform");I(this,"initialPageRotation");I(this,"info",{});I(this,"isPrecise",!1);I(this,"isPreciseId",null);I(this,"pointingId",null);I(this,"exactTimeout",-1)}onEnter(n){const{shape:r,isCreating:s,creatingMarkId:o,handle:i}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId="",s)if(o)this.markId=o;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:s?"cross":"grabbing",rotation:0});const a=this.editor.getShapeHandles(r).sort(cn),l=a.findIndex(c=>c.id===n.handle.id);this.initialAdjacentHandle=null;for(let c=l+1;c<a.length;c++){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(!this.initialAdjacentHandle)for(let c=a.length-1;c>=0;c--){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=Un(this.editor,r)[n.handle.id];this.isPrecise=!1,c?(this.editor.setHintingShapes([c.toId]),this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.update(),this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),Xe(this.editor,[this.shapeId]);const{onInteractionEnd:n}=this.info;if(this.editor.getInstanceState().isToolLocked&&n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:n}=this.info;if(n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var E;const{editor:n,shapeId:r,initialPagePoint:s}=this,{initialHandle:o,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:h,shiftKey:f,ctrlKey:p,altKey:g,pointerVelocity:m}}=n,v=this.info.shape,y=n.getShape(r);if(!y)return;const S=n.getShapeUtil(y);let b=h.clone().sub(s).rot(-i).add(o);if(f&&a&&o.id!=="middle"){const k=x.Angle(a,b),T=Op(k,24)-k;b=x.RotWith(b,a,T)}n.snaps.clearIndicators();let P={...o,x:b.x,y:b.y};if(o.canSnap&&(c?!p:p)){if(!n.getShapePageTransform(y.id))throw Error("Expected a page transform");const D=u.handles.snapHandle({currentShapeId:r,handle:P});D&&(D.nudge.rot(-n.getShapeParentTransform(y).rotation()),b.add(D.nudge),P={...o,x:b.x,y:b.y})}const C=(E=S.onHandleDrag)==null?void 0:E.call(S,y,{handle:P,isPrecise:this.isPrecise||g,initial:v}),_={id:y.id,type:y.type,...C};if(o.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const k=Un(n,y)[o.id];k?l[0]!==k.toId&&(n.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=m.len()<.5||g,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&n.updateShapes([_])}}I(D5,"id","dragging_handle");function R5(t){return t.isLabel?[t]:t instanceof $r?t.children.filter(e=>e.isLabel):[]}class L5 extends ie{constructor(){super(...arguments);I(this,"hitShapeForPointerUp",null);I(this,"info",{})}onEnter(n){const r=this.editor.getEditingShape();if(!r)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,this.info=n,n.isCreatingTextWhileToolLocked&&this.parent.setCurrentToolIdMask("text"),uo(this.editor),this.editor.select(r)}onExit(){var o;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),uo.cancel();const r=this.editor.getShape(n),s=this.editor.getShapeUtil(r);(o=s.onEditEnd)==null||o.call(s,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":{uo(this.editor);return}}}onPointerDown(n){switch(this.hitShapeForPointerUp=null,n.target){case"shape":{const{shape:r}=n,s=this.editor.getEditingShape();if(!s)throw Error("Expected an editing shape!");const o=this.editor.getShapeUtil(r).getGeometry(r),i=R5(o),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(s,"text")&&s.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===s.id)return;this.hitShapeForPointerUp=r,this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===s.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 s=this.editor.getShapeUtil(r);if(!r.isLocked){if(this.editor.getIsReadonly()&&!s.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),uo(this.editor)}}onComplete(n){this.parent.transition("idle",n)}onCancel(n){this.parent.transition("idle",n)}}I(L5,"id","editing_shape");function qE(t){const e=t.getOnlySelectedShape();return!!(e&&!t.isShapeOrAncestorLocked(e)&&t.getShapeUtil(e).canCrop(e))}function Qp(t,e){const n=t.getSelectedShapeIds(),{currentPagePoint:r}=t.inputs,{shiftKey:s,altKey:o,accelKey:i}=e,a=s||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&&!o)t.cancelDoubleClick(),n.includes(c.id)?(t.markHistoryStoppingPoint("deselecting shape"),t.deselect(c)):(t.markHistoryStoppingPoint("shift selecting shape"),t.setSelectedShapes([...n,c.id]));else{let u;c===l||c.id===t.getFocusedGroupId()||n.includes(c.id)?u=l:u=c,u&&!n.includes(u.id)&&(t.markHistoryStoppingPoint("selecting shape"),t.select(u.id))}}else{if(a)return;{n.length>0&&(t.markHistoryStoppingPoint("selecting none"),t.selectNone());const c=t.getFocusedGroupId();if(Fn(c)){const u=t.getShape(c);t.isPointInShape(u,r,{margin:0,hitInside:!0})||t.setFocusedGroup(null)}}}}const kue=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var XS;let Tue=(XS=class extends ie{onEnter(){this.parent.setCurrentToolIdMask(void 0),uo(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){uo.cancel()}onPointerMove(){uo(this.editor)}onPointerDown(e){const n=e.ctrlKey&&qE(this.editor);switch(e.target){case"canvas":{const r=M5(this.editor);if(r&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),o=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((s.length>1||o&&!this.editor.getShapeUtil(o).hideSelectionBoundsBg(o))&&ZE(this.editor,i)){this.onPointerDown({...e,target:"selection"});return}this.parent.transition("pointing_canvas",e);break}case"shape":{const{shape:r}=e;if(this.isOverArrowLabelTest(r)){this.parent.transition("pointing_arrow_label",e);break}if(this.editor.isShapeOrAncestorLocked(r)){this.parent.transition("pointing_canvas",e);break}this.parent.transition("pointing_shape",e);break}case"handle":{if(this.editor.getIsReadonly())break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",e):this.parent.transition("pointing_handle",e);break}case"selection":{switch(e.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_rotate_handle",e);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{if(n)this.parent.transition("crop.pointing_crop_handle",e);else{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_resize_handle",e)}break}default:{const r=this.editor.getHoveredShape();if(r&&!this.editor.getSelectedShapeIds().includes(r.id)&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}this.parent.transition("pointing_selection",e)}}break}}}onDoubleClick(e){var n,r,s,o;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")){Qp(this.editor,e);return}else{const c=this.editor.getShape(a.parentId);if(c&&this.editor.isShapeOfType(c,"group")&&!(l&&c.id===l)){Qp(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]),Xe(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((s=e.shape)==null?void 0:s.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=(o=l.onDoubleClickHandle)==null?void 0:o.call(l,i,a);c?this.editor.updateShapes([c]):this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}}}onRightClick(e){switch(e.target){case"canvas":{const n=this.editor.getHoveredShape(),r=n&&!this.editor.isShapeOfType(n,"group")?n:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!0,renderingOnly:!0});if(r){this.onRightClick({...e,shape:r,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),o=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((s.length>1||o&&!this.editor.getShapeUtil(o).hideSelectionBoundsBg(o))&&ZE(this.editor,i)){this.onRightClick({...e,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:n}=this.editor.getCurrentPageState(),{shape:r}=e,s=this.editor.getOutermostSelectableShape(r,o=>!n.includes(o.id));!n.includes(s.id)&&!this.editor.findShapeAncestor(s,o=>n.includes(o.id))&&(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}}onCancel(){this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.markHistoryStoppingPoint("clearing selection"),this.editor.selectNone())}onKeyDown(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(wt.editOnType.get()&&!kue.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(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(n.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const r=this.editor.getOnlySelectedShape();if(r&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...e,target:"shape",shape:r},!0);return}qE(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"),Hp(this.editor,e,r),this.parent.transition("editing_shape",n))}isOverArrowLabelTest(e){if(!e)return!1;const n=this.editor.getPointInShapeSpace(e,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(e,"arrow")){const r=this.editor.getShapeGeometry(e).children[1];if(r&&hr(n,r.vertices))return!0}return!1}handleDoubleClickOnCanvas(e){if(this.editor.getIsReadonly()||!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");const n=Ke(),{x:r,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:n,type:"text",x:r,y:s,props:{text:"",autoSize:!0}}]);const o=this.editor.getShape(n);if(!o)return;const i=this.editor.getShapeUtil(o);this.editor.getIsReadonly()&&!i.canEditInReadOnly(o)||(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"),s=new x(0,0);if(n.has("ArrowLeft")&&(s.x-=1),n.has("ArrowRight")&&(s.x+=1),n.has("ArrowUp")&&(s.y-=1),n.has("ArrowDown")&&(s.y+=1),s.equals(new x(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:o}=this.editor.getDocumentSettings(),i=this.editor.getInstanceState().isGridMode?r?o*jue:o:r?Mue:Aue,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,s.mul(i)),Xe(this.editor,a)}canInteractWithShapeInReadOnly(e){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(e).canEditInReadOnly(e))}},I(XS,"id","idle"),XS);const Mue=10,Aue=1,jue=5;function ZE(t,e){const n=t.getSelectionRotatedPageBounds();if(!n)return!1;const r=t.getSelectionRotation();return r?hr(e,n.corners.map(s=>x.RotWith(s,n.point,r))):n.containsPoint(e)}class $5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"markId","");I(this,"wasAlreadySelected",!1);I(this,"didDrag",!1);I(this,"didCtrlOnEnter",!1);I(this,"info",{});I(this,"_labelDragOffset",new x(0,0))}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(n){const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.didCtrlOnEnter=n.accelKey,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const o=this.editor.getShapeGeometry(r).children[1];if(!o)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(o.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 s=Es(this.editor,r),o=this.editor.getShapeGeometry(r),i=o.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(x.Add(a,this._labelDragOffset));let c;if(s.isStraight){const u=x.Dist(s.start.point,s.end.point);c=1-x.Dist(s.end.point,l)/u}else{const{_center:u,measure:h,angleEnd:f,angleStart:p}=o.children[0];c=vx(h,p,f,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})}onPointerUp(){const n=this.editor.getShape(this.shapeId);n&&(this.didDrag||!this.wasAlreadySelected?this.complete():this.editor.getIsReadonly()||(this.editor.setEditingShape(n.id),this.editor.setCurrentTool("select.editing_shape")))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}I($5,"id","pointing_arrow_label");class F5 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){Qp(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}I(F5,"id","pointing_canvas");class N5 extends ie{constructor(){super(...arguments);I(this,"didCtrlOnEnter",!1);I(this,"info",{})}onEnter(n){this.info=n,this.didCtrlOnEnter=n.accelKey;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const s=Un(this.editor,r)[n.handle.id];s&&this.editor.setHintingShapes([s.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:s}=this,o=QE(s,n,r,!1);if(o){Hp(s,o,!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:s}=this.info;if(n.isShapeOfType(r,"note")){const o=QE(n,r,s,!0);if(o){const i=n.getPointInParentSpace(o,n.inputs.originPagePoint).sub(x.Rot(vm.clone().mul(r.props.scale),o.rotation));n.updateShape({...o,x:i.x,y:i.y}),n.setHoveredShape(o.id).select(o.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:n.getShape(o),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{Hp(n,o,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(N5,"id","pointing_handle");function QE(t,e,n,r){const s=t.getShapePageTransform(e.id),o=s.point(),i=s.rotation(),l=Q$(t,o,i,e.props.growY,0,e.props.scale)[n.index];if(l)return e5(t,e,l,i,r)}class z5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){this.editor.setCursor({type:Nl[this.info.handle],rotation:this.editor.getSelectionRotation()})}onEnter(n){this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.editor.inputs.isDragging&&this.startRotating()}onLongPress(){this.startRotating()}startRotating(){this.editor.getIsReadonly()||this.parent.transition("rotating",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}I(z5,"id","pointing_rotate_handle");class B5 extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerUp(n){Qp(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 o,i;const r=this.editor.getHoveredShape(),s=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(s){this.parent.transition("idle"),(i=(o=this.parent).onDoubleClick)==null||i.call(o,{...n,target:"shape",shape:this.editor.getShape(s)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(B5,"id","pointing_selection");class U5 extends ie{constructor(){super(...arguments);I(this,"hitShape",{});I(this,"hitShapeForPointerUp",{});I(this,"isDoubleClick",!1);I(this,"didCtrlOnEnter",!1);I(this,"didSelectOnEnter",!1)}onEnter(n){const r=this.editor.getSelectedShapeIds(),s=this.editor.getSelectionRotatedPageBounds(),o=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,f=>r.includes(f.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(n.shape).onClick||u.id===o||r.includes(u.id)||h||r.length>1&&(s!=null&&s.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(),s=this.editor.getFocusedGroupId(),o=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i}}=this.editor,a=n.shiftKey||n.accelKey,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/o,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 f=(u=h.onClick)==null?void 0:u.call(h,c);if(f){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([f]),this.parent.transition("idle",n);return}}if(c.id===s){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,f=>!r.includes(f.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 f=this.editor.getShapeUtil(c).getGeometry(c),p=R5(f),g=p.length===1?p[0]:void 0;if(g){const m=this.editor.getPointInShapeSpace(c,i);if(g.bounds.containsPoint(m,0)&&g.hitTestPoint(m)){this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(c.id);const v=this.editor.getShapeUtil(c);this.editor.getIsReadonly()&&!v.canEditInReadOnly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:c.id}))});return}}}this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c);else if(a){const f=this.editor.getShapeAncestors(h);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(p=>!f.find(g=>g.id===p)),h.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",n)}onDoubleClick(){this.isDoubleClick=!0}onPointerMove(n){this.editor.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",n):this.startTranslating(n))}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getIsReadonly()||(this.editor.focus(),this.parent.transition("translating",n))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(U5,"id","pointing_shape");class H5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"didHoldCommand",!1);I(this,"creationCursorOffset",{x:0,y:0});I(this,"snapshot",{})}onEnter(n){const{isCreating:r=!1,creatingMarkId:s,creationCursorOffset:o={x:0,y:0}}=n;if(this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),this.markId="",r)if(s)this.markId=s;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(Xe(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:s})=>{var a;const o=this.editor.getShapeUtil(s),i=(a=o.onResizeStart)==null?void 0:a.call(o,s);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:s})=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onResizeEnd)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:n,shiftKey:r}=this.editor.inputs,{frames:s,shapeSnapshots:o,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot;let h=r||!u;if(o.size===1){const k=[...o.values()][0];this.editor.isShapeOfType(k.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:f}=this.editor.inputs,p=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),g=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!f){const{gridSize:k}=this.editor.getDocumentSettings();p.snapToGrid(k)}const m=this.info.handle,v=JE(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!f:f)&&c%Ze===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:x.Sub(p,g),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:JE(m,c),isAspectRatioLocked:h,isResizingFromCenter:n});p.add(k)}const S=x.RotWith(n?i.center:i.getHandlePoint(v),i.point,c),b=x.Sub(p,S).rot(-c),P=x.Sub(g,S).rot(-c),C=x.DivV(b,P);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const _=m==="top"||m==="bottom",E=m==="left"||m==="right";h?E?C.y=Math.abs(C.x):_?C.x=Math.abs(C.y):Math.abs(C.x)>Math.abs(C.y)?C.y=Math.abs(C.x)*(C.y<0?-1:1):C.x=Math.abs(C.y)*(C.x<0?-1:1):(_&&(C.x=1),E&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:c});for(const k of o.keys()){const D=o.get(k);this.editor.resizeShape(k,C,{initialShape:D.shape,initialBounds:D.bounds,initialPageTransform:D.pageTransform,dragHandle:m,mode:l.length===1&&k===l[0]?"resize_bounds":"scale_shape",scaleOrigin:S,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:D}of s){if(!D.length)continue;const T=o.get(k).shape,j=this.editor.getShape(k);if(!(T&&j))continue;const L=j.x-T.x,M=j.y-T.y,O=new x(L,M).rot(-T.rotation);if(O.x!==0||O.y!==0)for(const F of D)this.editor.updateShape({id:F.id,type:F.type,x:F.x-O.x,y:F.y-O.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of s)if(k.length)for(const D of k)this.editor.updateShape({id:D.id,type:D.type,x:D.x,y:D.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:s,rotation:o}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==s&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==s&&(i.type="nwse-resize");break}}i.rotation=o,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:s}}=this.editor,o=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(o.getHandlePoint(this.info.handle),o.point,r),a=x.Sub(s,i),l=new Map,c=[];n.forEach(h=>{const f=this.editor.getShape(h);if(f){if(f.type==="frame"&&c.push({id:h,children:me(this.editor.getSortedChildIdsForParent(f).map(p=>this.editor.getShape(p)))}),l.set(f.id,this._createShapeSnapshot(f)),this.editor.isShapeOfType(f,"frame")&&n.length===1)return;this.editor.visitDescendants(f.id,p=>{const g=this.editor.getShape(p);if(g&&(l.set(g.id,this._createShapeSnapshot(g)),this.editor.isShapeOfType(g,"frame")))return!1})}});const u=![...l.values()].some(h=>!oj(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:o,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}}_createShapeSnapshot(n){const r=this.editor.getShapePageTransform(n),s=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:q.Decompose(r).rotation,isAspectRatioLocked:s.isAspectRatioLocked(n)}}}I(H5,"id","resizing");const CS=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function JE(t,e){e=e%Fe;const n=Math.round(e/(De/4)),r=CS.indexOf(t);return CS[(r+n)%CS.length]}const e2=Math.PI/180;class K5 extends ie{constructor(){super(...arguments);I(this,"snapshot",{});I(this,"info",{});I(this,"markId","")}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=pO({editor:this.editor,ids:this.editor.getSelectedShapeIds()});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const s=this._getRotationFromPointerPosition({snapToNearestDegree:!1});df({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:Nl[this.info.handle],rotation:s+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});df({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:Nl[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(){df({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Xe(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(),s=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:o,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialShapesRotation:l}=this.snapshot;if(!s)return l;const u=s.center.clone().rotWith(s.point,r).angle(i)-a;let h=l+u;if(o)h=Op(h,24);else if(n&&(h=Math.round(h/e2)*e2,this.editor.getInstanceState().isCoarsePointer)){const f=Op(h,4),p=lf(h,f);Math.abs(p)<pX(5)&&(h=f)}return h-l}}I(K5,"id","rotating");class W5 extends ie{constructor(){super(...arguments);I(this,"hits",new Set);I(this,"size",0);I(this,"scribbleId","id");I(this,"initialSelectedShapeIds",new Set);I(this,"newlySelectedShapeIds",new Set)}onEnter(){this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const n=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=n.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.updateScribbleSelection(!0)}onPointerUp(){this.complete()}onKeyDown(){this.updateScribbleSelection(!1)}onKeyUp(){this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")}onCancel(){this.cancel()}onComplete(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}updateScribbleSelection(n){const{editor:r}=this,s=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{shiftKey:o,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const h=s;let f,p,g,m;const v=0;for(let b=0,P=h.length;b<P;b++){if(f=h[b],r.isShapeOfType(f,"group")||c.has(f.id)||r.isShapeOrAncestorLocked(f)||(p=r.getShapeGeometry(f),r.isShapeOfType(f,"frame")&&p.bounds.containsPoint(r.getPointInShapeSpace(f,i))))continue;const C=r.getShapePageTransform(f);if(!p||!C)continue;const _=C.clone().invert();g=_.applyToPoint(a),m=_.applyToPoint(l);const{bounds:E}=p;if(!(E.minX-v>Math.max(g.x,m.x)||E.minY-v>Math.max(g.y,m.y)||E.maxX+v<Math.min(g.x,m.x)||E.maxY+v<Math.min(g.y,m.y))&&p.hitTestLineSegment(g,m,v)){const k=this.editor.getOutermostSelectableShape(f),D=this.editor.getShapeMask(k.id);if(D&&xb(a,l,D)!==null&&!hr(l,D))continue;c.add(k.id)}}const y=r.getSelectedShapeIds(),S=new Set(o?[...c,...u]:[...c]);(y.length!==S.size||y.some(b=>!S.has(b)))&&this.editor.setSelectedShapes(Array.from(S))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}I(W5,"id","scribble_brushing");var Oue=Object.create,G5=Object.defineProperty,Due=Object.getOwnPropertyDescriptor,Rue=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),V5=t=>{throw TypeError(t)},Y5=(t,e,n)=>e in t?G5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Lue=t=>[,,,Oue(null)],X5=["class","method","getter","setter","accessor","field","value","get","set"],q5=t=>t!==void 0&&typeof t!="function"?V5("Function expected"):t,$ue=(t,e,n,r,s)=>({kind:X5[t],name:e,metadata:r,addInitializer:o=>n._?V5("Already initialized"):s.push(q5(o||null))}),Fue=(t,e)=>Y5(e,Rue("metadata"),t[3]),Nue=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},zue=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=X5[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Due(s,n)),y=r.length-1;y>=0;y--)l=$ue(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,q5(i)&&(v[g]=i);return v&&G5(s,n,v),s},_S=(t,e,n)=>Y5(t,typeof e!="symbol"?e+"":e,n),Z5,Cm;const Bue=20,Uue=100;Z5=[Kn];class L1{constructor(e){this.editor=e,Nue(Cm,5,this),_S(this,"prevDroppingShapeId",null),_S(this,"droppingNodeTimer",null),_S(this,"first",!0),e.disposables.add(this.dispose)}updateDroppingNode(e,n){var r;this.first&&(this.editor.setHintingShapes(e.map(s=>this.editor.findShapeAncestor(s,o=>o.type!=="group")).filter(s=>s)),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,Bue,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Uue,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,f;n=me(n.map(p=>this.editor.getShape(p.id)));const s=((l=this.editor.getDroppingOverShape(e,n))==null?void 0:l.id)??null;if(s===this.prevDroppingShapeId){this.hintParents(n);return}const{prevDroppingShapeId:o}=this,i=o&&this.editor.getShape(o),a=s&&this.editor.getShape(s);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,n)),a&&((f=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||f.call(h,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=s}hintParents(e){const n=new Map;for(const s of e){const o=this.editor.findShapeAncestor(s,i=>i.type!=="group");o&&(n.has(o.id)||n.set(o.id,[]),n.get(o.id).push(s.id))}const r=[];for(const[s,o]of n){const i=this.editor.getShape(s);i&&YL(this.editor,i).length<o.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(e){var r,s;const{prevDroppingShapeId:n}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,e),n){const o=this.editor.getShape(n);if(!o)return;(s=(r=this.editor.getShapeUtil(o)).onDropShapesOver)==null||s.call(r,o,e)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}dispose(){this.clear()}}Cm=Lue();zue(Cm,1,"dispose",Z5,L1);Fue(Cm,L1);var Hue=Object.create,Q5=Object.defineProperty,Kue=Object.getOwnPropertyDescriptor,J5=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),eF=t=>{throw TypeError(t)},tF=(t,e,n)=>e in t?Q5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Wue=t=>[,,,Hue((t==null?void 0:t[J5("metadata")])??null)],nF=["class","method","getter","setter","accessor","field","value","get","set"],rF=t=>t!==void 0&&typeof t!="function"?eF("Function expected"):t,Gue=(t,e,n,r,s)=>({kind:nF[t],name:e,metadata:r,addInitializer:o=>n._?eF("Already initialized"):s.push(rF(o||null))}),Vue=(t,e)=>tF(e,J5("metadata"),t[3]),Yue=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Xue=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=nF[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Kue(s,n)),y=r.length-1;y>=0;y--)l=Gue(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,rF(i)&&(v[g]=i);return v&&Q5(s,n,v),s},Ho=(t,e,n)=>tF(t,typeof e!="symbol"?e+"":e,n),sF,dw,_m;class Im extends(dw=ie,sF=[Kn],dw){constructor(){super(...arguments),Yue(_m,5,this),Ho(this,"info",{}),Ho(this,"selectionSnapshot",{}),Ho(this,"snapshot",{}),Ho(this,"markId",""),Ho(this,"isCloning",!1),Ho(this,"isCreating",!1),Ho(this,"dragAndDropManager",new L1(this.editor))}onCreate(e){}onEnter(e){var o;const{isCreating:n=!1,creatingMarkId:r,onCreate:s=()=>{}}=e;if(!((o=this.editor.getSelectedShapeIds())!=null&&o.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=s,this.isCloning=!1,this.info=e,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=t2(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=t2(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),Xe(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 s=this.editor.getShapeUtil(r),o=(i=s.onTranslateStart)==null?void 0:i.call(s,r);o&&n.push(o)}),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(o=>this.editor.getShapePageTransform(o.id).point())),s=x.Sub(r,this.selectionSnapshot.averagePagePoint);x.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(o=>o.id),offset:{x:s.x,y:s.y}}})}const n=[];e.forEach(r=>{var a;const s=this.editor.getShape(r.id),o=this.editor.getShapeUtil(r),i=(a=o.onTranslateEnd)==null?void 0:a.call(o,r,s);i&&n.push(i)}),n.length>0&&this.editor.updateShapes(n)}updateShapes(){const{snapshot:e}=this;this.dragAndDropManager.updateDroppingNode(e.movingShapes,this.updateParentTransforms),que({editor:this.editor,snapshot:e});const{movingShapes:n}=e,r=[];n.forEach(s=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onTranslate)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateParentTransforms(){const{editor:e,snapshot:{shapeSnapshots:n}}=this;n.forEach(r=>{const s=e.getShape(r.shape.id);if(!s)return null;const o=Rn(s.parentId)?null:q.Inverse(e.getShapePageTransform(s.parentId));r.parentTransform=o})}}_m=Wue(dw);Xue(_m,1,"updateParentTransforms",sF,Im);Vue(_m,Im);Ho(Im,"id","translating");function t2(t){var h;const e=[],n=[],r=t.getSelectedShapeIds(),s=me(r.map(f=>{const p=t.getShape(f);if(!p)return null;e.push(p);const g=t.getShapePageTransform(f),m=g.point(),v=g.rotation();n.push(m);const y=yr.isId(p.parentId)?null:q.Inverse(t.getShapePageTransform(p.parentId));return{shape:p,pagePoint:m,pageRotation:v,parentTransform:y}})),o=t.getOnlySelectedShape();let i=[];if(o)i=t.snaps.shapeBounds.getSnapPoints(o.id);else{const f=t.getSelectionPageBounds();f&&(i=f.cornersAndCenter.map((p,g)=>({id:"selection:"+g,x:p.x,y:p.y})))}let a,l;const{originPagePoint:c}=t.inputs,u=s.filter(f=>t.isShapeOfType(f.shape,"note")&&t.isPointInShape(f.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const f=t.getCurrentPageShapesSorted();l=(h=u.map(p=>({snapshot:p,index:f.findIndex(g=>g.id===p.shape.id)})).sort((p,g)=>g.index-p.index)[0])==null?void 0:h.snapshot}return l&&(a=J$(t,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:x.Average(n),movingShapes:e,shapeSnapshots:s,initialPageBounds:t.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function que({editor:t,snapshot:e}){const{inputs:n}=t,{noteSnapshot:r,noteAdjacentPositions:s,initialPageBounds:o,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=e,c=t.getInstanceState().isGridMode,u=t.getDocumentSettings().gridSize,h=x.Sub(n.currentPagePoint,n.originPagePoint),f=t.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;f==="x"?h.x=0:f==="y"&&(h.y=0),t.snaps.clearIndicators();const p=t.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey;let g=!1;if(p&&t.inputs.pointerVelocity.len()<.5){const{nudge:S}=t.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:o,lockedAxis:f,initialSelectionSnapPoints:i});h.add(S)}else if(r&&s){const{scale:S}=r.shape.props,b=r.pagePoint.clone().add(h).add(vm.clone().mul(S).rot(r.pageRotation));let P=Z$/t.getZoomLevel(),C=new x(0,0);for(const _ of s){const E=x.Sub(b,_),k=E.len();k<P&&(g=!0,P=k,C=E)}h.sub(C)}const m=x.Add(l,h),v=t.snaps.getIndicators();c&&!n.ctrlKey&&!g&&v.length===0&&m.snapToGrid(u);const y=x.Sub(m,l);t.updateShapes(me(a.map(({shape:S,pagePoint:b,parentTransform:P})=>{const C=x.Add(b,y),_=P?q.applyToPoint(P,C):C;return{id:S.id,type:S.type,x:_.x,y:_.y}})))}class Rf extends ie{constructor(){super(...arguments);I(this,"reactor")}static children(){return[uw,D1,Tue,F5,U5,Im,k5,W5,R1,B5,T5,L5,H5,K5,z5,$5,N5,D5]}cleanUpDuplicateProps(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const s=new Set(r.duplicateProps.shapeIds);n.length===s.size&&n.every(o=>s.has(o))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=As("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){console.error(n)}})}onExit(){var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}I(Rf,"id","select"),I(Rf,"initial","idle"),I(Rf,"isLockable",!1);class oF extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerDown(){this.parent.transition("pointing",this.info)}}I(oF,"id","idle");class iF extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerUp(){this.complete()}onPointerMove(){this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{animation:{duration:220}}):this.editor.zoomIn(n,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}I(iF,"id","pointing");class aF extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"zoomBrush",new Z)}onEnter(n){this.info=n,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Z.FromPoints([n,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:n}=this,r=8/this.editor.getZoomLevel();if(n.width<r&&n.height<r){const s=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(s,{animation:{duration:220}}):this.editor.zoomIn(s,{animation:{duration:220}})}else{const s=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:s,animation:{duration:220}})}this.parent.transition("idle",this.info)}}I(aF,"id","zoom_brushing");class Lf extends ie{constructor(){super(...arguments);I(this,"info",{})}static children(){return[oF,aF,iF]}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)}onKeyDown(){this.updateCursor()}onKeyUp(n){this.updateCursor(),n.code==="KeyZ"&&this.complete()}onInterrupt(){this.complete()}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}I(Lf,"id","zoom"),I(Lf,"initial","idle"),I(Lf,"isLockable",!1);const Zue=[jf,Of,Df,Lf,Rf];function Que(){const t=z(),e=U("follow",()=>t.getInstanceState().followingUserId,[t]);return e?d.jsx(Jue,{userId:e}):null}function Jue({userId:t}){const e=Dg(t);return e?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let hw={fonts:{draw:`${ti()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${ti()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${ti()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${ti()}/fonts/IBMPlexMono-Medium.woff2`}};function lF(t){return w.useMemo(()=>t?{fonts:{...hw.fonts,...t==null?void 0:t.fonts}}:hw,[t])}const ede=["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 Dc={...hw,icons:Object.fromEntries(ede.map(t=>[t,`${ti()}/icons/icon/0_merged.svg#${t}`])),translations:Object.fromEntries(zu.map(t=>[t.locale,`${ti()}/translations/${t.locale}.json`])),embedIcons:Object.fromEntries(g1.map(t=>[t.type,`${ti()}/embed-icons/${t.type}.png`]))};function tde(t){return t?{fonts:Object.assign({...Dc.fonts},{...t==null?void 0:t.fonts}),icons:Object.assign({...Dc.icons},{...t==null?void 0:t.icons}),embedIcons:Object.assign({...Dc.embedIcons},{...t==null?void 0:t.embedIcons}),translations:Object.assign({...Dc.translations},{...t==null?void 0:t.translations})}:Dc}var $1="Popover",[cF,Mge]=Ws($1,[nm]),Ed=nm(),[nde,Di]=cF($1),uF=t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:i=!1}=t,a=Ed(e),l=w.useRef(null),[c,u]=w.useState(!1),[h=!1,f]=ji({prop:r,defaultProp:s,onChange:o});return d.jsx(Gb,{...a,children:d.jsx(nde,{scope:e,contentId:mo(),triggerRef:l,open:h,onOpenChange:f,onOpenToggle:w.useCallback(()=>f(p=>!p),[f]),hasCustomAnchor:c,onCustomAnchorAdd:w.useCallback(()=>u(!0),[]),onCustomAnchorRemove:w.useCallback(()=>u(!1),[]),modal:i,children:n})})};uF.displayName=$1;var dF="PopoverAnchor",rde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(dF,n),o=Ed(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=s;return w.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(Vb,{...o,...r,ref:e})});rde.displayName=dF;var hF="PopoverTrigger",fF=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(hF,n),o=Ed(n),i=Qe(e,s.triggerRef),a=d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":SF(s.open),...r,ref:i,onClick:se(t.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:d.jsx(Vb,{asChild:!0,...o,children:a})});fF.displayName=hF;var F1="PopoverPortal",[sde,ode]=cF(F1,{forceMount:void 0}),pF=t=>{const{__scopePopover:e,forceMount:n,children:r,container:s}=t,o=Di(F1,e);return d.jsx(sde,{scope:e,forceMount:n,children:d.jsx(ds,{present:n||o.open,children:d.jsx(bd,{asChild:!0,container:s,children:r})})})};pF.displayName=F1;var zl="PopoverContent",gF=w.forwardRef((t,e)=>{const n=ode(zl,t.__scopePopover),{forceMount:r=n.forceMount,...s}=t,o=Di(zl,t.__scopePopover);return d.jsx(ds,{present:r||o.open,children:o.modal?d.jsx(ide,{...s,ref:e}):d.jsx(ade,{...s,ref:e})})});gF.displayName=zl;var ide=w.forwardRef((t,e)=>{const n=Di(zl,t.__scopePopover),r=w.useRef(null),s=Qe(e,r),o=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return Yb(i)},[]),d.jsx(om,{as:fa,allowPinchZoom:!0,children:d.jsx(mF,{...t,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(t.onCloseAutoFocus,i=>{var a;i.preventDefault(),o.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:se(t.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;o.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:se(t.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),ade=w.forwardRef((t,e)=>{const n=Di(zl,t.__scopePopover),r=w.useRef(!1),s=w.useRef(!1);return d.jsx(mF,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=t.onCloseAutoFocus)==null||i.call(t,o),o.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=t.onInteractOutside)==null||l.call(t,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),mF=w.forwardRef((t,e)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=t,f=Di(zl,n),p=Ed(n);return Lb(),d.jsx(Qg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:d.jsx(xd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>f.onOpenChange(!1),children:d.jsx(b3,{"data-state":SF(f.open),role:"dialog",id:f.contentId,...p,...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)"}})})})}),yF="PopoverClose",lde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(yF,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:se(t.onClick,()=>s.onOpenChange(!1))})});lde.displayName=yF;var cde="PopoverArrow",ude=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Ed(n);return d.jsx(P3,{...s,...r,ref:e})});ude.displayName=cde;function SF(t){return t?"open":"closed"}var N1=uF,z1=fF,B1=pF,U1=gF;function H1({id:t,children:e,onOpenChange:n,open:r}){const[s,o]=Mo(t,n);return d.jsx(N1,{onOpenChange:o,open:r||s,children:d.jsx("div",{className:"tlui-popover",children:e})})}function K1({children:t}){return d.jsx(z1,{asChild:!0,dir:"ltr",children:t})}function W1({side:t,children:e,align:n="center",sideOffset:r=8,alignOffset:s=0,disableEscapeKeyDown:o=!1}){const i=Tt();return d.jsx(B1,{container:i,children:d.jsx(U1,{className:"tlui-popover__content",side:t,sideOffset:r,align:n,alignOffset:s,dir:"ltr",onEscapeKeyDown:a=>o&&a.preventDefault(),children:e})})}function dde(t){return t.getSelectedShapeIds().map(r=>t.getShape(r)).filter(r=>{if(!r)return!1;if(t.isShapeOfType(r,"arrow")){const s=Un(t,r);if(s.start||s.end)return!1}return!0})}const vF=()=>{const t=z();return U("threeStackableItems",()=>dde(t).length>2,[t])},Ao=()=>{const t=z();return U("isInSelectState",()=>t.isIn("select"),[t])},xF=()=>{const t=z();return U("allow group",()=>{const e=t.getSelectedShapes();if(e.length<2)return!1;for(const n of e)if(t.isShapeOfType(n,"arrow")){const r=Un(t,n);if(r.start&&!e.some(s=>s.id===r.start.toId)||r.end&&!e.some(s=>s.id===r.end.toId))return!1}return!0},[t])},wF=()=>{const t=z();return U("allowUngroup",()=>t.getSelectedShapeIds().some(e=>{var n;return((n=t.getShape(e))==null?void 0:n.type)==="group"}),[t])},hde=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function bF(t,e){const n=z();return U("selectedShapes",()=>n.getSelectedShapes().length>=t,[n,t,e])}function jn(t,e){const n=z();return U("selectedShapes",()=>{const r=n.getSelectedShapes().filter(s=>!n.isShapeOrAncestorLocked(s)).length;return t===void 0?r:r>=t},[n])}function fde(){const t=z();return U("showAutoSizeToggle",()=>{const e=t.getSelectedShapes();return e.length===1&&t.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[t])}function PF(){const t=z();return U("hasLinkShapeSelected",()=>{const e=t.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[t])}function pde(){const t=z();return U("onlyFlippableShape",()=>{const e=t.getOnlySelectedShape();return e&&(t.isShapeOfType(e,"group")||t.isShapeOfType(e,"image")||t.isShapeOfType(e,"arrow")||t.isShapeOfType(e,"line")||t.isShapeOfType(e,"draw"))},[t])}function CF(){const t=z();return U("useCanRedo",()=>t.getCanRedo(),[t])}function _F(){const t=z();return U("useCanUndo",()=>t.getCanUndo(),[t])}function gde(){return d.jsxs(d.Fragment,{children:[d.jsx(mde,{}),d.jsx(yde,{}),d.jsx(Sde,{}),d.jsx(vde,{}),d.jsx(xde,{}),d.jsx(Pde,{}),d.jsx(Cde,{}),d.jsx(_de,{})]})}function mde(){const t=jn(2),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"align-left",disabled:!n}),d.jsx(W,{actionId:"align-center-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-right",disabled:!n}),d.jsx(W,{actionId:"stretch-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-top",disabled:!n}),d.jsx(W,{actionId:"align-center-vertical",disabled:!n}),d.jsx(W,{actionId:"align-bottom",disabled:!n}),d.jsx(W,{actionId:"stretch-vertical",disabled:!n})]})}function yde(){const t=jn(3),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"distribute-horizontal",disabled:!n}),d.jsx(W,{actionId:"distribute-vertical",disabled:!n})]})}function Sde(){const t=vF(),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"stack-horizontal",disabled:!n}),d.jsx(W,{actionId:"stack-vertical",disabled:!n})]})}function vde(){const t=jn(1),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"send-to-back",disabled:!n}),d.jsx(W,{actionId:"send-backward",disabled:!n}),d.jsx(W,{actionId:"bring-forward",disabled:!n}),d.jsx(W,{actionId:"bring-to-front",disabled:!n})]})}function xde(){return An()<St.TABLET_SM?d.jsx(wde,{}):d.jsx(bde,{})}function wde(){const t=z(),e=U("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",disabled:e})}function bde(){const t=jn(1),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"rotate-ccw",disabled:!n})}function Pde(){const t=jn(1),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"rotate-cw",disabled:!n})}function Cde(){const t=PF(),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"edit-link",disabled:!n})}function _de(){const t=xF(),e=wF();return t?d.jsx(n2,{}):e?d.jsx(Ide,{}):d.jsx(n2,{})}function n2(){const t=jn(2),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"group",disabled:!n})}function Ide(){return d.jsx(W,{actionId:"ungroup"})}const Ede=w.memo(function({children:e}){const n=Ee(),r=An(),s=wr(),o=w.useRef(null);Ai(o);const i=z(),a=U("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),l=e??d.jsx(gde,{});if(!(s&&!a))return d.jsxs(H1,{id:"actions-menu",children:[d.jsx(K1,{children:d.jsx(ue,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(W1,{side:r>=St.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{ref:o,className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(Fr,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function IF(){return fde()?d.jsx(W,{actionId:"toggle-auto-size"}):null}function EF(){return PF()?d.jsx(W,{actionId:"edit-link"}):null}function kde(){return jn(1)?d.jsx(W,{actionId:"duplicate"}):null}function kF(){const t=z();return U("should display flatten option",()=>{if(t.getSelectedShapeIds().length===0)return!1;const r=t.getOnlySelectedShape();return!(r&&t.isShapeOfType(r,"image"))},[t])?d.jsx(W,{actionId:"flatten-to-image"}):null}function TF(){return xF()?d.jsx(W,{actionId:"group"}):null}function MF(){return wF()?d.jsx(W,{actionId:"ungroup"}):null}function AF(){const t=z();return U("allow unframe",()=>{const n=t.getSelectedShapes();return n.length===0?!1:n.every(r=>t.isShapeOfType(r,"frame"))},[t])?d.jsx(W,{actionId:"remove-frame"}):null}function jF(){const t=z();return U("allow fit frame to content",()=>{const n=t.getOnlySelectedShape();return n?t.isShapeOfType(n,"frame")&&t.getSortedChildIdsForParent(n).length>0:!1},[t])?d.jsx(W,{actionId:"fit-frame-to-content"}):null}function OF(){const t=z();return U("selected shapes",()=>t.getSelectedShapes().length>0,[t])?d.jsx(W,{actionId:"toggle-lock"}):null}function G1(){const t=z(),e=U("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(fs,{actionId:"toggle-transparent",checked:e,toggle:!0})}function Tde(){const t=z(),e=U("any shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"unlock-all",disabled:!e})}function DF(){const t=z(),e=U("zoomed to 100",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function RF(){const t=z(),e=U("has shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function LF(){const t=z(),e=U("has shapes",()=>t.getSelectedShapeIds().length>0,[t]);return d.jsx(W,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function $F(){return d.jsxs(ve,{id:"clipboard",children:[d.jsx(Ade,{}),d.jsx(jde,{}),d.jsx(Ode,{}),d.jsx(kde,{}),d.jsx(Dde,{})]})}function Mde(){var n;const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsxs(Jn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[d.jsxs(ve,{id:"copy-as-group",children:[d.jsx(W,{actionId:"copy-as-svg"}),!!((n=window.navigator.clipboard)!=null&&n.write)&&d.jsx(W,{actionId:"copy-as-png"}),d.jsx(W,{actionId:"copy-as-json"})]}),d.jsx(ve,{id:"copy-as-bg",children:d.jsx(G1,{})})]})}function Ade(){const t=jn(1);return d.jsx(W,{actionId:"cut",disabled:!t})}function jde(){const t=bF(1);return d.jsx(W,{actionId:"copy",disabled:!t})}function Ode(){const t=hde;return d.jsx(W,{actionId:"paste",disabled:!t})}function FF(){const t=z();return U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t])?d.jsxs(ve,{id:"conversions",children:[d.jsx(Mde,{}),d.jsxs(Jn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[d.jsxs(ve,{id:"export-as-group",children:[d.jsx(W,{actionId:"export-as-svg"}),d.jsx(W,{actionId:"export-as-png"}),d.jsx(W,{actionId:"export-as-json"})]}),d.jsx(ve,{id:"export-as-bg",children:d.jsx(G1,{})})]})]}):null}function NF(){const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"select-all",disabled:!e})}function Dde(){const t=jn(1);return d.jsx(W,{actionId:"delete",disabled:!t})}function Rde(){const t=wr();return!bF(1)||t?null:d.jsxs(Jn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(TF,{}),d.jsx(MF,{}),d.jsx(kF,{}),d.jsx(EF,{}),d.jsx(jF,{}),d.jsx(AF,{}),d.jsx(BF,{}),d.jsx(zF,{}),d.jsx(IF,{}),d.jsx(OF,{})]})}function Lde(){const t=jn(2),e=pde();return wr()||!(t||e)?null:d.jsxs(Jn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[t&&d.jsxs(ve,{id:"align",children:[d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"})]}),d.jsx($de,{}),t&&d.jsxs(ve,{id:"stretch",children:[d.jsx(W,{actionId:"stretch-horizontal"}),d.jsx(W,{actionId:"stretch-vertical"})]}),(t||e)&&d.jsxs(ve,{id:"flip",children:[d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"})]}),d.jsx(Fde,{})]})}function $de(){return jn(3)?d.jsxs(ve,{id:"distribute",children:[d.jsx(W,{actionId:"distribute-horizontal"}),d.jsx(W,{actionId:"distribute-vertical"})]}):null}function Fde(){const t=jn(2),e=vF();return t?d.jsxs(ve,{id:"order",children:[d.jsx(W,{actionId:"pack"}),e&&d.jsx(W,{actionId:"stack-horizontal"}),e&&d.jsx(W,{actionId:"stack-vertical"})]}):null}function Nde(){const t=wr(),e=jn(1);return t||!e?null:d.jsx(Jn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(ve,{id:"reorder",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"})]})})}function zde(){const t=z(),e=U("pages",()=>t.getPages(),[t]),n=U("current page id",()=>t.getCurrentPageId(),[t]),{addToast:r}=To(),s=Jt(),o=wr();return!jn(1)||o?null:d.jsxs(Jn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ve,{id:"pages",children:e.map(a=>d.jsx(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)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),d.jsx(ve,{id:"new-page",children:d.jsx(W,{actionId:"move-to-new-page"})})]})}function zF(){const t=z();return U("oneEmbedSelected",()=>{const n=t.getOnlySelectedShape();return n?!!(t.isShapeOfType(n,"embed")&&n.props.url&&!t.isShapeOrAncestorLocked(n)):!1},[t])?d.jsx(W,{actionId:"convert-to-bookmark"}):null}function BF(){const t=z(),e=m1();return U("oneEmbeddableBookmarkSelected",()=>{const r=t.getOnlySelectedShape();return r?!!(t.isShapeOfType(r,"bookmark")&&r.props.url&&e(r.props.url)&&!t.isShapeOrAncestorLocked(r)):!1},[t])?d.jsx(W,{actionId:"convert-to-embed"}):null}function Bde(){const t=z(),e=U("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(fs,{actionId:"toggle-snap-mode",checked:e})}function Ude(){const t=z(),e=U("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(fs,{actionId:"toggle-tool-lock",checked:e})}function Hde(){const t=z(),e=U("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(fs,{actionId:"toggle-grid",checked:e})}function Kde(){const t=z(),e=U("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(fs,{actionId:"toggle-wrap-mode",checked:e})}function Wde(){const t=z(),e=U("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(fs,{actionId:"toggle-focus-mode",checked:e})}function Gde(){const t=z(),e=U("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(fs,{actionId:"toggle-edge-scrolling",checked:e===1})}function Vde(){const t=z(),e=U("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(fs,{actionId:"toggle-reduce-motion",checked:e===0})}function Yde(){const t=z(),e=U("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(fs,{actionId:"toggle-debug-mode",checked:e})}function Xde(){const t=z(),e=U("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(fs,{actionId:"toggle-dynamic-size-mode",checked:e})}function qde(){const t=z(),e=U("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(fs,{actionId:"toggle-paste-at-cursor",checked:e})}function Zde(){const t=z();return U("show cursor chat",()=>t.getCurrentToolId()==="select"&&!t.getInstanceState().isCoarsePointer,[t])?d.jsx(W,{actionId:"open-cursor-chat"}):null}function Qde(){const t=z(),e=fm(),n=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]),r=U("isSinglePageMode",()=>t.options.maxPages<=1,[t]);return n?d.jsxs(d.Fragment,{children:[e&&d.jsx(Zde,{}),d.jsxs(ve,{id:"modify",children:[d.jsx(Rde,{}),d.jsx(Lde,{}),d.jsx(Nde,{}),!r&&d.jsx(zde,{})]}),d.jsx($F,{}),d.jsx(FF,{}),d.jsx(ve,{id:"select-all",children:d.jsx(NF,{})})]}):null}const Jde=w.memo(function({children:e,disabled:n=!1}){const r=z(),{Canvas:s}=st(),o=w.useCallback(u=>{if(u){if(r.getInstanceState().isCoarsePointer){const h=r.getSelectedShapes(),{inputs:{currentPagePoint:f}}=r,p=r.getShapesAtPoint(f);if(!r.getSelectedShapes().length||!p.some(g=>h.includes(g))){const g=p.filter(m=>r.isShapeOrAncestorLocked(m));g.length&&r.select(...g.map(m=>m.id))}}}else{const h=r.getOnlySelectedShape();h&&r.isShapeOrAncestorLocked(h)&&r.setSelectedShapes([])}},[r]),i=Tt(),[a,l]=Mo("context menu",o),c=e??d.jsx(Qde,{});return d.jsxs(Hse,{dir:"ltr",onOpenChange:l,modal:!1,children:[d.jsx(Kse,{onContextMenu:void 0,dir:"ltr",disabled:n,children:s?d.jsx(s,{}):null}),a&&d.jsx(Wse,{container:i,children:d.jsx(Gse,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:xe,children:d.jsx(Fr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),ehe=2e3,the=5e3,nhe=Zt(function(){const e=z(),{isChatting:n,chatMessage:r}=e.getInstanceState(),s=w.useRef(-1),[o,i]=w.useState("");return w.useEffect(()=>{if(!n&&r||n){const l=n?the:ehe;s.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},l)}return()=>{clearTimeout(s.current)}},[e,r,n]),n?d.jsx(she,{value:o,setValue:i,chatMessage:r}):r.trim()?d.jsx(rhe,{chatMessage:r}):null});function UF(t){const e=z();w.useLayoutEffect(()=>{var i;if(!t.current)return;const{x:r,y:s}=e.inputs.currentScreenPoint;(i=t.current)==null||i.style.setProperty("transform",`translate(${r}px, ${s}px)`);function o(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",o),()=>{window.removeEventListener("pointermove",o)}},[t,e])}const rhe=({chatMessage:t})=>{const e=z(),n=w.useRef(null);return UF(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:t})},she=Zt(function({chatMessage:e,value:n,setValue:r}){const s=z(),o=Ee(),i=w.useRef(null),a=e||o("cursor-chat.type-to-chat");UF(i),w.useLayoutEffect(()=>{const f=i.current;if(!f)return;const p=s.textMeasure.measureText(n||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});f.style.setProperty("width",p.w+"px")},[s,n,a]),w.useLayoutEffect(()=>{const f=s.timers.requestAnimationFrame(()=>{var p;(p=i.current)==null||p.focus()});return()=>{cancelAnimationFrame(f)}},[s]);const l=w.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),c=w.useCallback(f=>{const{value:p}=f.target;r(p.slice(0,64)),s.updateInstanceState({chatMessage:p})},[s,r]),u=w.useCallback(f=>{const p=i.current;if(!p)return;const{value:g}=p;switch(f.key){case"Enter":{if(xe(f),f.stopPropagation(),!g){l();return}r("");break}case"Escape":{xe(f),f.stopPropagation(),l();break}}},[l,r]),h=w.useCallback(f=>{f.stopPropagation()},[]);return d.jsx("input",{ref:i,className:"tl-cursor-chat",style:{backgroundColor:s.user.getColor()},onBlur:l,onChange:c,onKeyDown:u,onPaste:h,value:n,placeholder:a,spellCheck:!1})});function fw({checked:t}){return d.jsx(zs,{icon:t?"check":"none",className:"tlui-button__icon",small:!0})}function ohe(){const t=z(),{addToast:e}=To(),{addDialog:n}=Id(),[r,s]=ke.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:o})=>d.jsx(lhe,{displayDontShowAgain:!0,onCancel:()=>o(),onContinue:()=>o()}),onClose:()=>{}})}}),d.jsx(Kt,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>che(t,100)}),d.jsx(Kt,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const o=t.getSelectedShapes(),i=o.length===0?t.getRenderingShapes():o;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:()=>s(!0),label:"Throw error"}),d.jsx(Kt,{id:"hard-reset",onSelect:kj,label:"Hard reset"})]}),d.jsxs(ve,{id:"flags",children:[d.jsx(ihe,{}),d.jsx(ahe,{})]})]})}function ihe(){const t=Object.values(wt);return t.length?d.jsx(Jn,{id:"debug flags",label:"Debug Flags",children:d.jsx(ve,{id:"debug flags",children:t.map(e=>d.jsx(HF,{flag:e},e.name))})}):null}function ahe(){const t=Object.values(xX);return t.length?d.jsx(Jn,{id:"feature flags",label:"Feature Flags",children:d.jsx(ve,{id:"feature flags",children:t.map(e=>d.jsx(HF,{flag:e},e.name))})}):null}function lhe({title:t="title",body:e="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,onCancel:o,onContinue:i}){const[a,l]=ke.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(cm,{children:[d.jsx(um,{children:t}),d.jsx(dm,{})]}),d.jsx(Vu,{style:{maxWidth:350},children:e}),d.jsxs(p1,{className:"tlui-dialog__footer__actions",children:[s&&d.jsxs(ue,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(fw,{checked:a}),d.jsx(bt,{children:"Don’t show again"})]}),d.jsx(ue,{type:"normal",onClick:o,children:d.jsx(bt,{children:n})}),d.jsx(ue,{type:"primary",onClick:async()=>i(),children:d.jsx(bt,{children:r})})]})]})}const HF=Zt(function({flag:e,onChange:n}){const r=e.get();return d.jsx(ym,{id:e.name,title:e.name,label:e.name.replace(/([a-z0-9])([A-Z])/g,s=>`${s[0]} ${s[1].toLowerCase()}`).replace(/^[a-z]/,s=>s.toUpperCase()),checked:r,onSelect:()=>{e.set(!r),n==null||n(!r)}})});let r2=0;function che(t,e){const n=Array(e),r=Math.floor(Math.sqrt(e));for(let s=0;s<e;s++)r2++,n[s]={id:Ke("box"+r2),type:"geo",x:s%r*132,y:Math.floor(s/r)*132};t.run(()=>{t.createShapes(n).setSelectedShapes(n.map(s=>s.id))})}function uhe({children:t}){const e=t??d.jsx(ohe,{});return d.jsxs(ma,{id:"debug",children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(Sa,{side:"top",align:"end",alignOffset:0,children:d.jsx(Fr,{type:"menu",sourceId:"debug-panel",children:e})})]})}const dhe=w.memo(function(){const{DebugMenu:e}=Ri(),n=w.useRef(null);return Ai(n),d.jsxs("div",{ref:n,className:"tlui-debug-panel",children:[d.jsx(fhe,{}),d.jsx(phe,{}),e&&d.jsx(e,{})]})});function hhe(t=!0){const[e,n]=w.useState(0),r=z();w.useEffect(()=>{if(!t)return;const s=()=>n(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,t])}const fhe=Zt(function(){hhe();const e=z(),n=e.getPath(),r=e.getHoveredShape(),s=e.getOnlySelectedShape(),o=n==="select.idle"||!n.includes("select.")?r:s,i=o&&n.includes("select.")?` / ${o.type||""}${"geo"in o.props?" / "+o.props.geo:""} / [${x.ToInt(e.getPointInShapeSpace(o,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 phe(){const t=z(),e=U("show_fps",()=>wt.showFps.get(),[wt]),n=w.useRef(null);return w.useEffect(()=>{if(!e)return;const r=250;let s=0,o=-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>s&&(s=h);const f=s*.75;(h<f&&!c||h>=f&&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()}o=t.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(o)}},[e,t]),e?d.jsx("div",{ref:n}):null}const ghe=w.memo(function(){const e=An(),n=w.useRef(null);Ai(n);const{MainMenu:r,QuickActions:s,ActionsMenu:o,PageMenu:i}=Ri(),a=z(),l=U("isSinglePageMode",()=>a.options.maxPages<=1,[a]),c=a.options.actionShortcutsLocation==="menu"?!0:a.options.actionShortcutsLocation==="toolbar"?!1:e>=St.TABLET;return!r&&!i&&!c?null:d.jsx("div",{ref:n,className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[r&&d.jsx(r,{}),i&&!l&&d.jsx(i,{}),c?d.jsxs(d.Fragment,{children:[s&&d.jsx(s,{}),o&&d.jsx(o,{})]}):null]})})});function mhe(){const t=z(),e=Ea(),[n,r]=w.useState(!1),s=w.useRef(!1);return ui("toggle showback to content",()=>{const o=s.current,i=t.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===t.getCulledShapes().size),o!==a&&(r(a),s.current=a)},[t]),n?d.jsx(W,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function yhe(){const t=z();return U("is pen mode",()=>t.getInstanceState().isPenMode,[t])?d.jsx(W,{actionId:"exit-pen-mode"}):null}function She(){const t=z(),e=Ea();return U("is following user",()=>!!t.getInstanceState().followingUserId,[t])?d.jsx(Kt,{...e["stop-following"]}):null}function vhe(){return d.jsxs(d.Fragment,{children:[d.jsx(yhe,{}),d.jsx(mhe,{}),d.jsx(She,{})]})}function xhe({children:t}){const e=t??d.jsx(vhe,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(Fr,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function whe(){const t=fm();return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(W,{actionId:"toggle-tool-lock"}),d.jsx(W,{actionId:"insert-media"}),d.jsx(Ln,{toolId:"select"}),d.jsx(Ln,{toolId:"draw"}),d.jsx(Ln,{toolId:"eraser"}),d.jsx(Ln,{toolId:"hand"}),d.jsx(Ln,{toolId:"rectangle"}),d.jsx(Ln,{toolId:"ellipse"}),d.jsx(Ln,{toolId:"arrow"}),d.jsx(Ln,{toolId:"line"}),d.jsx(Ln,{toolId:"text"}),d.jsx(Ln,{toolId:"frame"}),d.jsx(Ln,{toolId:"note"}),d.jsx(Ln,{toolId:"laser"}),d.jsx(Kt,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),d.jsxs(ve,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(W,{actionId:"toggle-dark-mode"}),d.jsx(W,{actionId:"toggle-focus-mode"}),d.jsx(W,{actionId:"toggle-grid"})]}),d.jsxs(ve,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(W,{actionId:"undo"}),d.jsx(W,{actionId:"redo"}),d.jsx(W,{actionId:"cut"}),d.jsx(W,{actionId:"copy"}),d.jsx(W,{actionId:"paste"}),d.jsx(W,{actionId:"select-all"}),d.jsx(W,{actionId:"delete"}),d.jsx(W,{actionId:"duplicate"})]}),d.jsxs(ve,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx(W,{actionId:"zoom-to-100"}),d.jsx(W,{actionId:"zoom-to-fit"}),d.jsx(W,{actionId:"zoom-to-selection"})]}),d.jsxs(ve,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"}),d.jsx(W,{actionId:"group"}),d.jsx(W,{actionId:"ungroup"}),d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"}),d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"})]}),t&&d.jsx(ve,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:d.jsx(W,{actionId:"open-cursor-chat"})})]})}const bhe=w.memo(function({children:e}){const n=Ee(),r=An(),s=e??d.jsx(whe,{});return d.jsxs(d.Fragment,{children:[d.jsxs(cm,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(um,{children:n("shortcuts-dialog.title")}),d.jsx(dm,{})]}),d.jsx(Vu,{className:ce("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=St.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=St.TABLET}),children:d.jsx(Fr,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})});function KF(){const t=Ti(),e=Jt(),n=U("locale",()=>t==null?void 0:t.user.getLocale(),[t]);return t?d.jsx(Jn,{id:"help menu language",label:"menu.language",children:d.jsx(ve,{id:"languages",children:zu.map(({locale:r,label:s})=>d.jsx(ym,{id:`language-${r}`,title:r,label:s,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})}):null}function Phe(){return d.jsxs(d.Fragment,{children:[d.jsx(KF,{}),d.jsx(WF,{})]})}function WF(){const{KeyboardShortcutsDialog:t}=Ri(),{addDialog:e}=Id(),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 Che(){return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"basic",children:[d.jsx(Ihe,{}),d.jsx(Mhe,{}),d.jsx(_he,{}),d.jsx(Ahe,{})]}),d.jsx(jhe,{})]})}function _he(){return d.jsxs(Jn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[d.jsxs(ve,{id:"export-all-as-group",children:[d.jsx(W,{actionId:"export-all-as-svg"}),d.jsx(W,{actionId:"export-all-as-png"}),d.jsx(W,{actionId:"export-all-as-json"})]}),d.jsx(ve,{id:"export-all-as-bg",children:d.jsx(G1,{})})]})}function Ihe(){const t=z(),e=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]);return d.jsxs(Jn,{id:"edit",label:"menu.edit",disabled:!e,children:[d.jsx(The,{}),d.jsx($F,{}),d.jsx(FF,{}),d.jsx(Ehe,{}),d.jsx(khe,{}),d.jsx(ve,{id:"select-all",children:d.jsx(NF,{})})]})}function Ehe(){return d.jsxs(ve,{id:"misc",children:[d.jsx(TF,{}),d.jsx(MF,{}),d.jsx(EF,{}),d.jsx(IF,{}),d.jsx(AF,{}),d.jsx(jF,{}),d.jsx(BF,{}),d.jsx(zF,{}),d.jsx(kF,{})]})}function khe(){return d.jsxs(ve,{id:"lock",children:[d.jsx(OF,{}),d.jsx(Tde,{})]})}function The(){const t=_F(),e=CF();return d.jsxs(ve,{id:"undo-redo",children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}function Mhe(){return d.jsx(Jn,{id:"view",label:"menu.view",children:d.jsxs(ve,{id:"view-actions",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx(DF,{}),d.jsx(RF,{}),d.jsx(LF,{})]})})}function Ahe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"insert-embed"}),d.jsx(W,{actionId:"insert-media"})]})}function jhe(){return d.jsxs(ve,{id:"preferences",children:[d.jsxs(Jn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ve,{id:"preferences-actions",children:[d.jsx(Bde,{}),d.jsx(Ude,{}),d.jsx(Hde,{}),d.jsx(Kde,{}),d.jsx(Wde,{}),d.jsx(Gde,{}),d.jsx(Vde,{}),d.jsx(Xde,{}),d.jsx(qde,{}),d.jsx(Yde,{})]}),d.jsx(ve,{id:"color-scheme",children:d.jsx(Fae,{})})]}),d.jsx(KF,{}),d.jsx(WF,{})]})}const Ohe=w.memo(function({children:e}){const n=Tt(),[r,s]=Mo("main menu"),o=Ee(),i=e??d.jsx(Che,{});return d.jsxs(i1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(a1,{asChild:!0,dir:"ltr",children:d.jsx(ue,{type:"icon","data-testid":"main-menu.button",title:o("menu.title"),children:d.jsx(be,{icon:"menu",small:!0})})}),d.jsx(lm,{container:n,children:d.jsx(l1,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(Fr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),IS={};function Rc(t){if(IS[t])return IS[t];const n=document.createElement("canvas").getContext("2d");n.fillStyle=t,n.fillRect(0,0,1,1);const[r,s,o,i]=n.getImageData(0,0,1,1).data,a=new Float32Array([r/255,s/255,o/255,i/255]);return IS[t]=a,a}const $f=10,GF=4*6*$f+12+4*12;function Ha(t,{center:e,radius:n,numArcSegments:r=20,startAngle:s=0,endAngle:o=Fe,offset:i=0}){const a=(o-s)/r;let l=i;for(let c=s;c<o;c+=a)t[l++]=e.x,t[l++]=e.y,t[l++]=e.x+Math.cos(c)*n,t[l++]=e.y+Math.sin(c)*n,t[l++]=e.x+Math.cos(c+a)*n,t[l++]=e.y+Math.sin(c+a)*n;return t}function Ka(t,e,n,r,s,o){t[e++]=n,t[e++]=r,t[e++]=n,t[e++]=r+o,t[e++]=n+s,t[e++]=r,t[e++]=n+s,t[e++]=r,t[e++]=n,t[e++]=r+o,t[e++]=n+s,t[e++]=r+o}function Dhe(t,e,n){const r=$f;n=Math.min(n,Math.min(e.w,e.h)/2);const s=Z.ExpandBy(e,-n);if(s.w<=0||s.h<=0)return Ha(t,{center:e.center,radius:n,numArcSegments:$f*4}),$f*4*6;let o=0;return Ka(t,o,s.minX,s.minY,s.w,s.h),o+=12,Ka(t,o,s.minX,e.minY,s.w,n),o+=12,Ka(t,o,s.maxX,s.minY,n,s.h),o+=12,Ka(t,o,s.minX,s.maxY,s.w,n),o+=12,Ka(t,o,e.minX,s.minY,n,s.h),o+=12,Ha(t,{numArcSegments:r,offset:o,center:s.point,radius:n,startAngle:De,endAngle:De*1.5}),o+=r*6,Ha(t,{numArcSegments:r,offset:o,center:x.Add(s.point,new x(s.w,0)),radius:n,startAngle:De*1.5,endAngle:Fe}),o+=r*6,Ha(t,{numArcSegments:r,offset:o,center:x.Add(s.point,s.size),radius:n,startAngle:0,endAngle:Ze}),o+=r*6,Ha(t,{numArcSegments:r,offset:o,center:x.Add(s.point,new x(0,s.h)),radius:n,startAngle:Ze,endAngle:De}),GF}function Rhe(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 s=`#version 300 es
|
|
404
|
+
precision mediump float;
|
|
405
|
+
|
|
406
|
+
uniform vec4 fillColor;
|
|
407
|
+
out vec4 outputColor;
|
|
408
|
+
|
|
409
|
+
void main() {
|
|
410
|
+
outputColor = fillColor;
|
|
411
|
+
}`,o=e.createShader(e.FRAGMENT_SHADER);if(!o)throw new Error("Failed to create fragment shader");if(e.shaderSource(o,s),e.compileShader(o),!e.getShaderParameter(o,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,o),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(i);const a=e.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(i,"canvasPageBounds"),c=e.getUniformLocation(i,"fillColor");if(!e.createBuffer())throw new Error("Failed to create buffer");if(!e.createBuffer())throw new Error("Failed to create buffer");return{context:e,selectedShapes:zh(e,1024),unselectedShapes:zh(e,4096),viewport:zh(e,GF),collaborators:zh(e,1024),prepareTriangles(f,p){e.bindBuffer(e.ARRAY_BUFFER,f.buffer),e.bufferData(e.ARRAY_BUFFER,f.vertices,e.STATIC_DRAW,0,p),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(f){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,f/2),e.disable(e.BLEND)},drawTriangles(f){e.drawArrays(e.TRIANGLES,0,f/2)},setFillColor(f){e.uniform4fv(c,f)},setCanvasPageBounds(f){e.uniform4fv(l,f)}}}function zh(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(e)}}function s2(t,e,n){let r=t.vertices.length;for(;r<e+n.length;)r*=2;if(r!=t.vertices.length){const s=new Float32Array(r);s.set(t.vertices),t.vertices=s}t.vertices.set(n,e)}var Lhe=Object.create,VF=Object.defineProperty,$he=Object.getOwnPropertyDescriptor,Fhe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),YF=t=>{throw TypeError(t)},XF=(t,e,n)=>e in t?VF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nhe=t=>[,,,Lhe(null)],qF=["class","method","getter","setter","accessor","field","value","get","set"],ZF=t=>t!==void 0&&typeof t!="function"?YF("Function expected"):t,zhe=(t,e,n,r,s)=>({kind:qF[t],name:e,metadata:r,addInitializer:o=>n._?YF("Already initialized"):s.push(ZF(o||null))}),Bhe=(t,e)=>XF(e,Fhe("metadata"),t[3]),Uhe=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Vs=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=qF[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,$he(s,n)),y=r.length-1;y>=0;y--)l=zhe(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,ZF(i)&&(v[g]=i);return v&&VF(s,n,v),s},Js=(t,e,n)=>XF(t,typeof e!="symbol"?e+"":e,n),QF,JF,eN,tN,nN,rN,sN,oN,iN,aN,br;aN=[Kn],iN=[G],oN=[G],sN=[G],rN=[G],nN=[G],tN=[G],eN=[G],JF=[G],QF=[Kn];class Br{constructor(e,n,r){this.editor=e,this.elem=n,this.container=r,Uhe(br,5,this),Js(this,"disposables",[]),Js(this,"gl"),Js(this,"shapeGeometryCache"),Js(this,"colors"),Js(this,"id",ze()),Js(this,"canvasBoundingClientRect",It("canvasBoundingClientRect",new Z)),Js(this,"originPagePoint",new x),Js(this,"originPageCenter",new x),Js(this,"isInViewport",!1),this.gl=Rhe(n),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",s=>{const o=e.getShapeMaskedPageBounds(s.id);if(!o)return null;const i=new Float32Array(12);return Ka(i,0,o.x,o.y,o.w,o.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),As("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Rc(e.getPropertyValue("--color-text-3").trim()),selectFill:Rc(e.getPropertyValue("--color-selected").trim()),viewportFill:Rc(e.getPropertyValue("--color-muted-1").trim()),background:Rc(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:s}=this.elem.getBoundingClientRect();return new Z(e,n,r,s)}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 s=n.width,o=s/r;o<n.height&&(o=n.height,s=o*r);const i=new Z(0,0,s,o);return i.center=n.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:e,y:n,w:r,h:s}=this.getCanvasPageBounds();return new Float32Array([e,n,r,s])}getMinimapPagePoint(e,n){const r=this.getCanvasPageBounds(),s=this.getCanvasScreenBounds();let o=e-s.x,i=n-s.y;return o*=r.width/s.width,i*=r.height/s.height,o+=r.minX,i+=r.minY,new x(o,i,1)}minimapScreenPointToPagePoint(e,n,r=!1,s=!1){const{editor:o}=this,i=o.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(e,n);if(s){const c=this.editor.getCurrentPageBounds()??new Z,u=c.minX-i.width/2,h=c.maxX+i.width/2,f=c.minY-i.height/2,p=c.maxY+i.height/2,g=Math.max(0,u+i.width-a),m=Math.max(0,-(h-i.width-a)),v=Math.max(0,f+i.height-l),y=Math.max(0,-(p-i.height-l));a+=(g-m)/2,l+=(v-y)/2,a=Bt(a,u,h),l=Bt(l,f,p)}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()),s=this.colors;let o=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 f=h.length;r.has(u)?(s2(this.gl.selectedShapes,o,h),o+=f):(s2(this.gl.unselectedShapes,i,h),i+=f)}this.drawShapes(this.gl.unselectedShapes,i,s.shapeFill),this.drawShapes(this.gl.selectedShapes,o,s.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=Dhe(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,s=r*e.length;this.gl.collaborators.vertices.length<s&&(this.gl.collaborators.vertices=new Float32Array(s));const o=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:l}of e)l&&(Ha(o,{center:x.From(l),radius:3*a,offset:i,numArcSegments:n}),i+=r);this.gl.prepareTriangles(this.gl.collaborators,s),i=0;for(const{color:l}of e)this.gl.setFillColor(Rc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}br=Nhe();Vs(br,1,"close",aN,Br);Vs(br,1,"getDpr",iN,Br);Vs(br,1,"getContentPageBounds",oN,Br);Vs(br,1,"getContentScreenBounds",sN,Br);Vs(br,1,"getCanvasSize",rN,Br);Vs(br,1,"getCanvasClientPosition",nN,Br);Vs(br,1,"getCanvasPageBounds",tN,Br);Vs(br,1,"getZoom",eN,Br);Vs(br,1,"getCanvasPageBoundsArray",JF,Br);Vs(br,1,"render",QF,Br);Bhe(br,Br);function Hhe(){const t=z(),e=Tt(),n=w.useRef(null),r=w.useRef(!1),s=w.useRef();w.useEffect(()=>{try{const u=new Br(t,n.current,e);return s.current=u,s.current.close}catch(u){t.annotateError(u,{origin:"minimap",willCrashApp:!1}),t.timers.setTimeout(()=>{throw u})}},[t,e]);const o=w.useCallback(u=>{if(!t.getCurrentPageShapeIds().size||!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.originPagePoint.setTo(f),s.current.originPageCenter.setTo(t.getViewportPageBounds().center),t.centerOnPoint(h,{animation:{duration:t.options.animationMediumMs}})},[t]),i=w.useCallback(u=>{if(!s.current)return;const h=u.currentTarget;if(ud(h,u),!t.getCurrentPageShapeIds().size)return;r.current=!0,s.current.isInViewport=!1;const f=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=t.getViewportPageBounds(),g=s.current.getContentPageBounds();if(new Z(g.x-p.width/2,g.y-p.height/2,g.width+p.width,g.height+p.height).containsPoint(f)&&!p.containsPoint(f)){s.current.isInViewport=p.containsPoint(f);const y=x.Sub(p.center,p.point),S=x.Add(f,y);s.current.originPagePoint.setTo(S),s.current.originPageCenter.setTo(f),t.centerOnPoint(f,{animation:{duration:t.options.animationMediumMs}})}else{const y=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.isInViewport=p.containsPoint(y),s.current.originPagePoint.setTo(y),s.current.originPageCenter.setTo(p.center)}function v(y){h&&dd(h,y),r.current=!1,document.body.removeEventListener("pointerup",v)}document.body.addEventListener("pointerup",v)},[t]),a=w.useCallback(u=>{if(!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(s.current.isInViewport){const m=s.current.originPagePoint.clone().sub(s.current.originPageCenter);t.centerOnPoint(x.Sub(h,m));return}t.centerOnPoint(h)}const f=s.current.getMinimapPagePoint(u.clientX,u.clientY),p=t.pageToScreen(f),g={type:"pointer",target:"canvas",name:"pointer_move",...lr(u),point:p,isPen:t.getInstanceState().isPenMode};t.dispatch(g)},[t]),l=w.useCallback(u=>{const h=yj(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=vd();return w.useEffect(()=>{t.timers.setTimeout(()=>{var u,h;(u=s.current)==null||u.updateColors(),(h=s.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:o,onPointerMove:a,onPointerDown:i,onWheelCapture:l})})}function Khe(t,e){const[n,r]=ke.useState(e);ke.useLayoutEffect(()=>{const o=C0(t);if(o)try{r(JSON.parse(o))}catch{console.error(`Could not restore value ${t} from local storage.`)}},[t]);const s=ke.useCallback(o=>{r(i=>{const a=typeof o=="function"?o(i):o;return _0(t,JSON.stringify(a)),a})},[t]);return[n,s]}const Whe=w.memo(function(){const e=Ea(),n=Ee(),r=An(),s=w.useRef(null);Ai(s);const[o,i]=Khe("minimap",!0),a=w.useCallback(()=>{i(u=>!u)},[i]),{ZoomMenu:l,Minimap:c}=Ri();return r<St.MOBILE?null:d.jsxs("div",{ref:s,className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:l&&r<St.TABLET?d.jsx(l,{}):o?d.jsxs(d.Fragment,{children:[l&&d.jsx(l,{}),c&&d.jsx(ue,{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:o?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(Yu(e["zoom-out"].label))} ${Yx(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"minus"})}),l&&d.jsx(l,{}),d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(Yu(e["zoom-in"].label))} ${Yx(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"plus"})}),c&&d.jsx(ue,{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:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=St.TABLET&&!o&&d.jsx(c,{})]})}),Ghe=function({name:e,id:n,isCurrentPage:r,onCancel:s}){const o=z(),i=Jt(),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(()=>{l.current=o.markHistoryStoppingPoint("rename page")},[o]),u=w.useCallback(f=>{o.renamePage(n,f||"New Page"),i("rename-page",{source:"page-menu"})},[o,n,i]),h=w.useCallback(()=>{l.current&&o.bailToMark(l.current),s()},[o,s]);return d.jsx(hm,{className:"tlui-page-menu__item__input",ref:f=>a.current=f,defaultValue:e,onValueChange:u,onCancel:h,onFocus:c,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},pw=(t,e,n,r,s)=>{let o;const i=t.getPages(),a=n>r?i[r-1]:i[r],l=n>r?i[r]:i[r+1];a&&!l?o=_s(a.index):!a&&l?o=oB(i[0].index):o=$u(a.index,l.index),o!==i[n].index&&(t.markHistoryStoppingPoint("moving page"),t.updatePage({id:e,index:o}),s("move-page",{source:"page-menu"}))},o2=Zt(function({index:e,listSize:n,item:r,onRename:s}){const o=z(),i=Ee(),a=o.getPages(),l=Jt(),c=w.useCallback(()=>{o.markHistoryStoppingPoint("creating page");const p=yr.createId();o.duplicatePage(r.id,p),l("duplicate-page",{source:"page-menu"})},[o,r,l]),u=w.useCallback(()=>{pw(o,r.id,e,e-1,l)},[o,r,e,l]),h=w.useCallback(()=>{pw(o,r.id,e,e+1,l)},[o,r,e,l]),f=w.useCallback(()=>{o.markHistoryStoppingPoint("deleting page"),o.deletePage(r.id),l("delete-page",{source:"page-menu"})},[o,r,l]);return d.jsxs(ma,{id:`page item submenu ${e}`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(Sa,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(Fr,{type:"menu",sourceId:"page-menu",children:[d.jsxs(ve,{id:"modify",children:[s&&d.jsx(Kt,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),d.jsx(Kt,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=o.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:f,label:"page-menu.submenu.delete"})})]})})]})}),Vhe=w.memo(function(){const e=z(),n=Jt(),r=Ee(),s=An(),o=w.useCallback(()=>y(!1),[]),[i,a]=Mo("page-menu",o),l=36,c=w.useRef(null),u=U("pages",()=>e.getPages(),[e]),h=U("currentPage",()=>e.getCurrentPage(),[e]),f=U("currentPageId",()=>e.getCurrentPageId(),[e]),p=wr(),g=U("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),m=U("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[v,y]=w.useState(!1),S=w.useCallback(()=>{p||y(M=>!M)},[p]),b=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,C]=w.useState(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])));w.useLayoutEffect(()=>{C(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])))},[l,u]),w.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const M=document.querySelector(`[data-testid="page-menu-item-${f}"]`);if(M){const O=c.current;if(!O)return;const F=M.offsetTop,B=O.scrollTop;F<B&&O.scrollTo({top:F});const K=F+l,R=O.scrollTop+O.offsetHeight;K>R&&O.scrollTo({top:K-O.offsetHeight})}})},[l,f,i,e]);const _=w.useCallback(M=>{const{clientY:O,currentTarget:F}=M,{dataset:{id:B,index:K}}=F;if(!B||!K)return;const R=b.current;ud(M.currentTarget,M),R.status="pointing",R.pointing={id:B,index:+K};const X=P[B].y;R.startY=O,R.startIndex=Math.max(0,Math.min(Math.round(X/l),u.length-1))},[l,u.length,P]),E=w.useCallback(M=>{const O=b.current;if(O.status==="pointing"){const{clientY:F}=M,B=F-O.startY;Math.abs(B)>5&&(O.status="dragging")}if(O.status==="dragging"){const{clientY:F}=M,B=F-O.startY,K=P[O.pointing.id],{startIndex:R,pointing:H}=O,X=K.y+B,te=Math.max(0,Math.min(Math.round(X/l),u.length-1)),le={...P};if(le[H.id]={y:K.y,offsetY:B,isSelected:!0},te!==O.dragIndex){O.dragIndex=te;for(let de=0;de<u.length;de++){const Me=u[de];if(Me.id===O.pointing.id)continue;let{y:oe}=le[Me.id];te===R?oe=de*l:te<R?te<=de&&de<R?oe=(de+1)*l:oe=de*l:te>R&&(te>=de&&de>R?oe=(de-1)*l:oe=de*l),oe!==le[Me.id].y&&(le[Me.id]={y:oe,offsetY:0,isSelected:!0})}}C(le)}},[l,u,P]),k=w.useCallback(M=>{const O=b.current;if(O.status==="dragging"){const{id:F,index:B}=O.pointing;pw(e,F,B,O.dragIndex,n)}dd(M.currentTarget,M),O.status="idle"},[e,n]),D=w.useCallback(M=>{const O=b.current;M.key==="Escape"&&(O.status==="dragging"&&C(Object.fromEntries(u.map((F,B)=>[F.id,{y:B*l,offsetY:0,isSelected:!1}]))),O.status="idle")},[l,u]),T=w.useCallback(()=>{p||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const M=yr.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:M}),e.setCurrentPage(M),y(!0)}),n("new-page",{source:"page-menu"}))},[e,r,p,n]),j=w.useCallback(M=>{e.setCurrentPage(M),n("change-page",{source:"page-menu"})},[e,n]),L=w.useCallback((M,O)=>{e.renamePage(M,O),n("rename-page",{source:"page-menu"})},[e,n]);return d.jsxs(H1,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(K1,{"data-testid":"main.page-menu",children:d.jsxs(ue,{type:"menu",title:h.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[d.jsx("div",{className:"tlui-page-menu__name",children:h.name}),d.jsx(be,{icon:"chevron-down",small:!0})]})}),d.jsx(W1,{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")}),!p&&d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsx(ue,{type:"icon","data-testid":"page-menu.edit",title:r(v?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:d.jsx(be,{icon:v?"check":"edit"})}),d.jsx(ue,{type:"icon","data-testid":"page-menu.create",title:r(g?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:g,onClick:T,children:d.jsx(be,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((M,O)=>{const F=P[M.id]??{offsetY:0};return v?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:M.id===h.id?888:O,transform:`translate(0px, ${F.y+F.offsetY}px)`},children:[d.jsx(ue,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:_,onPointerUp:k,onPointerMove:E,onKeyDown:D,"data-id":M.id,"data-index":O,children:d.jsx(be,{icon:"drag-handle-dots"})}),s<St.TABLET_SM&&m?d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const B=window.prompt("Rename page",M.name);B&&B!==M.name&&L(M.id,B)},onDoubleClick:S,children:[d.jsx(fw,{checked:M.id===h.id}),d.jsx(bt,{children:M.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:d.jsx(Ghe,{id:M.id,name:M.name,isCurrentPage:M.id===h.id,onCancel:()=>{y(!1),e.menus.clearOpenMenus()}})}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":v,children:d.jsx(o2,{index:O,item:M,listSize:u.length})})]},M.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>j(M.id),onDoubleClick:S,title:r("page-menu.go-to-page"),children:[d.jsx(fw,{checked:M.id===h.id}),d.jsx(bt,{children:M.name})]}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(o2,{index:O,item:M,listSize:u.length,onRename:()=>{if(Ge.isIos){const B=window.prompt("Rename page",M.name);B&&B!==M.name&&L(M.id,B)}else y(!0),f!==M.id&&j(M.id)}})})]},M.id)})})]})})]})});function Yhe(){const t=z(),e=wr(),n=U("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]);if(!(e&&!n))return d.jsxs(d.Fragment,{children:[d.jsx(qhe,{}),d.jsx(Xhe,{})]})}function Xhe(){const t=jn(1),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"delete",disabled:!n}),d.jsx(W,{actionId:"duplicate",disabled:!n})]})}function qhe(){const t=_F(),e=CF();return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}const Zhe=w.memo(function({children:e}){const n=e??d.jsx(Yhe,{});return d.jsx(Fr,{type:"small-icons",sourceId:"quick-actions",children:n})});function Qhe({userId:t}){const e=Dg(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 Jhe=Zt(function({userId:e}){const n=z(),r=Ee(),s=Jt(),o=Dg(e),i=w.useCallback(()=>{n.getInstanceState().followingUserId===e?(n.stopFollowingUser(),s("stop-following",{source:"people-menu"})):(n.startFollowingUser(e),s("start-following",{source:"people-menu"}))},[n,e,s]),a=(o==null?void 0:o.followingUserId)===n.user.getId(),l=n.getInstanceState().followingUserId===e;return o?d.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal",children:[d.jsxs(ue,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>n.zoomToUser(e),onDoubleClick:i,children:[d.jsx(zs,{icon:"color",color:o.color}),d.jsx("div",{className:"tlui-people-menu__name",children:o.userName??"New User"})]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:i,disabled:a,"data-active":l||a,children:d.jsx(be,{icon:a?"leading":l?"following":"follow"})})]}):null});function efe({count:t}){return d.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(t)})}const tfe=Zt(function(){const e=z(),n=Tt(),r=Ee(),s=Jt(),o=w.useRef(!1),[i,a]=w.useState(!1),l=w.useCallback(m=>{a(m)},[]),c=e.user.getColor(),u=w.useCallback(m=>{e.user.updateUserPreferences({color:m}),s("set-color",{source:"people-menu"})},[e,s]),{handleButtonClick:h,handleButtonPointerDown:f,handleButtonPointerEnter:p,handleButtonPointerUp:g}=ke.useMemo(()=>{const m=()=>{o.current=!1,window.removeEventListener("pointerup",m)};return{handleButtonClick:P=>{const{id:C}=P.currentTarget.dataset;C&&c!==C&&u(C)},handleButtonPointerDown:P=>{const{id:C}=P.currentTarget.dataset;C&&(u(C),o.current=!0,window.addEventListener("pointerup",m))},handleButtonPointerEnter:P=>{if(!o.current)return;const{id:C}=P.currentTarget.dataset;C&&u(C)},handleButtonPointerUp:P=>{const{id:C}=P.currentTarget.dataset;C&&u(C)}}},[c,u]);return d.jsxs(N1,{onOpenChange:l,open:i,children:[d.jsx(z1,{dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:d.jsx(be,{icon:"color"})})}),d.jsx(B1,{container:n,children:d.jsx(U1,{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:bx.map(m=>d.jsx(ue,{type:"icon","data-id":m,"data-testid":m,"aria-label":m,"data-state":c===m?"hinted":void 0,title:m,className:"tlui-button-grid__button",style:{color:m},onPointerEnter:p,onPointerDown:f,onPointerUp:g,onClick:h,children:d.jsx(be,{icon:"color"})},m))})})})]})});function nfe(){const t=z(),e=Jt(),n=U("userName",()=>t.user.getName(),[]),r=Ee(),s=w.useRef(n),o=w.useRef(n),[i,a]=w.useState(!1),l=w.useCallback(()=>{a(f=>!f)},[]),c=w.useCallback(f=>{o.current=f,t.user.updateUserPreferences({name:f})},[t]),u=w.useCallback(()=>{s.current!==o.current&&(e("change-user-name",{source:"people-menu"}),s.current=o.current)},[e]),h=w.useCallback(()=>{a(!1),t.user.updateUserPreferences({name:s.current}),t.menus.clearOpenMenus()},[t]);return d.jsxs("div",{className:"tlui-people-menu__user",children:[d.jsx(tfe,{}),i?d.jsx(hm,{className:"tlui-people-menu__user__input",defaultValue:n,onValueChange:c,onComplete:l,onCancel:h,onBlur:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{i||a(!0)},children:n}),n==="New User"?d.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")}):null]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:d.jsx(be,{icon:i?"check":"edit"})})]})}function rfe({displayUserWhenAlone:t,children:e}){const n=Ee(),r=Tt(),s=z(),o=xj(),i=U("user",()=>s.user.getColor(),[s]),a=U("user",()=>s.user.getName(),[s]),[l,c]=Mo("people menu");return d.jsxs(N1,{onOpenChange:c,open:l,children:[d.jsx(z1,{dir:"ltr",asChild:!0,children:d.jsxs("button",{className:"tlui-people-menu__avatars-button",title:n("people-menu.title"),children:[o.length>5&&d.jsx(efe,{count:o.length-5}),d.jsxs("div",{className:"tlui-people-menu__avatars",children:[o.slice(-5).map(u=>d.jsx(Qhe,{userId:u},u)),(t||o.length>0)&&d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx(B1,{container:r,children:d.jsx(U1,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,onEscapeKeyDown:xe,children:d.jsxs("div",{className:"tlui-people-menu__wrapper",children:[d.jsx("div",{className:"tlui-people-menu__section",children:d.jsx(nfe,{})}),o.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:o.map(u=>d.jsx(Jhe,{userId:u},u+"_presence"))}),e]})})})]})}function sfe(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(rfe,{displayUserWhenAlone:!0})})}const ofe=Object.freeze([mr,ua,da,$s]);function lN(t=ofe){const e=z();return U("getRelevantStyles",()=>{var o;const n=new kx(e.getSharedStyles()),r=!!((o=e.root.getCurrent())!=null&&o.shapeType),s=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||s||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"}]},Xi=w.memo(function(e){const{uiType:n,items:r,title:s,style:o,value:i,onValueChange:a,onHistoryMark:l,theme:c}=e,u=Ee(),h=w.useRef(!1),f=w.useRef(null),{handleButtonClick:p,handleButtonPointerDown:g,handleButtonPointerEnter:m,handleButtonPointerUp:v}=w.useMemo(()=>{const y=()=>{h.current=!1,window.removeEventListener("pointerup",y);const _=f.current;_&&["TEXTAREA","INPUT"].includes(_.nodeName)&&_.focus(),f.current=null};return{handleButtonClick:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||(l==null||l("point picker item"),a(o,E))},handleButtonPointerDown:_=>{const{id:E}=_.currentTarget.dataset;l==null||l("point picker item"),a(o,E),h.current=!0,f.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:_=>{if(!h.current)return;const{id:E}=_.currentTarget.dataset;a(o,E)},handleButtonPointerUp:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||a(o,E)}}},[i,l,a,o]);return d.jsx("div",{"data-testid":`style.${n}`,className:ce("tlui-buttons__grid"),children:r.map(y=>d.jsx(ue,{type:"icon","data-id":y.value,"data-testid":`style.${n}.${y.value}`,"aria-label":y.value,"data-state":i.type==="shared"&&i.value===y.value?"hinted":void 0,title:s+" — "+u(`${n}-style.${y.value}`),className:ce("tlui-button-grid__button"),style:o===mr?{color:c[y.value].solid}:void 0,onPointerEnter:m,onPointerDown:g,onPointerUp:v,onClick:p,children:d.jsx(be,{icon:y.icon})},y.value))})});function cN(t,[e,n]){return Math.min(n,Math.max(e,t))}function ife(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 uN=["PageUp","PageDown"],dN=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],hN={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},lc="Slider",[gw,afe,lfe]=Zg(lc),[fN,Age]=Ws(lc,[lfe]),[cfe,Em]=fN(lc),pN=w.forwardRef((t,e)=>{const{name:n,min:r=0,max:s=100,step:o=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:h=()=>{},onValueCommit:f=()=>{},inverted:p=!1,form:g,...m}=t,v=w.useRef(new Set),y=w.useRef(0),b=i==="horizontal"?ufe:dfe,[P=[],C]=ji({prop:u,defaultProp:c,onChange:j=>{var M;(M=[...v.current][y.current])==null||M.focus(),h(j)}}),_=w.useRef(P);function E(j){const L=mfe(P,j);T(j,L)}function k(j){T(j,y.current)}function D(){const j=_.current[y.current];P[y.current]!==j&&f(P)}function T(j,L,{commit:M}={commit:!1}){const O=xfe(o),F=wfe(Math.round((j-r)/o)*o+r,O),B=cN(F,[r,s]);C((K=[])=>{const R=pfe(K,B,L);if(vfe(R,l*o)){y.current=R.indexOf(B);const H=String(R)!==String(K);return H&&M&&f(R),H?R:K}else return K})}return d.jsx(cfe,{scope:t.__scopeSlider,name:n,disabled:a,min:r,max:s,valueIndexToChangeRef:y,thumbs:v.current,values:P,orientation:i,form:g,children:d.jsx(gw.Provider,{scope:t.__scopeSlider,children:d.jsx(gw.Slot,{scope:t.__scopeSlider,children:d.jsx(b,{"aria-disabled":a,"data-disabled":a?"":void 0,...m,ref:e,onPointerDown:se(m.onPointerDown,()=>{a||(_.current=P)}),min:r,max:s,inverted:p,onSlideStart:a?void 0:E,onSlideMove:a?void 0:k,onSlideEnd:a?void 0:D,onHomeKeyDown:()=>!a&&T(r,0,{commit:!0}),onEndKeyDown:()=>!a&&T(s,P.length-1,{commit:!0}),onStepKeyDown:({event:j,direction:L})=>{if(!a){const F=uN.includes(j.key)||j.shiftKey&&dN.includes(j.key)?10:1,B=y.current,K=P[B],R=o*F*L;T(K+R,B,{commit:!0})}}})})})})});pN.displayName=lc;var[gN,mN]=fN(lc,{startEdge:"left",endEdge:"right",size:"width",direction:1}),ufe=w.forwardRef((t,e)=>{const{min:n,max:r,dir:s,inverted:o,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=t,[h,f]=w.useState(null),p=Qe(e,b=>f(b)),g=w.useRef(void 0),m=Rb(s),v=m==="ltr",y=v&&!o||!v&&o;function S(b){const P=g.current||h.getBoundingClientRect(),C=[0,P.width],E=V1(C,y?[n,r]:[r,n]);return g.current=P,E(b-P.left)}return d.jsx(gN,{scope:t.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:d.jsx(yN,{dir:m,"data-orientation":"horizontal",...u,ref:p,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const P=S(b.clientX);i==null||i(P)},onSlideMove:b=>{const P=S(b.clientX);a==null||a(P)},onSlideEnd:()=>{g.current=void 0,l==null||l()},onStepKeyDown:b=>{const C=hN[y?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:C?-1:1})}})})}),dfe=w.forwardRef((t,e)=>{const{min:n,max:r,inverted:s,onSlideStart:o,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=t,u=w.useRef(null),h=Qe(e,u),f=w.useRef(void 0),p=!s;function g(m){const v=f.current||u.current.getBoundingClientRect(),y=[0,v.height],b=V1(y,p?[r,n]:[n,r]);return f.current=v,b(m-v.top)}return d.jsx(gN,{scope:t.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1,children:d.jsx(yN,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const v=g(m.clientY);o==null||o(v)},onSlideMove:m=>{const v=g(m.clientY);i==null||i(v)},onSlideEnd:()=>{f.current=void 0,a==null||a()},onStepKeyDown:m=>{const y=hN[p?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:y?-1:1})}})})}),yN=w.forwardRef((t,e)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:s,onSlideEnd:o,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=t,u=Em(lc,n);return d.jsx(Ae.span,{...c,ref:e,onKeyDown:se(t.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):uN.concat(dN).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:se(t.onPointerDown,h=>{const f=h.target;f.setPointerCapture(h.pointerId),h.preventDefault(),u.thumbs.has(f)?f.focus():r(h)}),onPointerMove:se(t.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&s(h)}),onPointerUp:se(t.onPointerUp,h=>{const f=h.target;f.hasPointerCapture(h.pointerId)&&(f.releasePointerCapture(h.pointerId),o(h))})})}),SN="SliderTrack",vN=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,s=Em(SN,n);return d.jsx(Ae.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:e})});vN.displayName=SN;var mw="SliderRange",xN=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,s=Em(mw,n),o=mN(mw,n),i=w.useRef(null),a=Qe(e,i),l=s.values.length,c=s.values.map(f=>bN(f,s.min,s.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(Ae.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...t.style,[o.startEdge]:u+"%",[o.endEdge]:h+"%"}})});xN.displayName=mw;var yw="SliderThumb",wN=w.forwardRef((t,e)=>{const n=afe(t.__scopeSlider),[r,s]=w.useState(null),o=Qe(e,a=>s(a)),i=w.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return d.jsx(hfe,{...t,ref:o,index:i})}),hfe=w.forwardRef((t,e)=>{const{__scopeSlider:n,index:r,name:s,...o}=t,i=Em(yw,n),a=mN(yw,n),[l,c]=w.useState(null),u=Qe(e,S=>c(S)),h=l?i.form||!!l.closest("form"):!0,f=h3(l),p=i.values[r],g=p===void 0?0:bN(p,i.min,i.max),m=gfe(r,i.values.length),v=f==null?void 0:f[a.size],y=v?yfe(v,g,a.direction):0;return w.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${g}% + ${y}px)`},children:[d.jsx(gw.ItemSlot,{scope:t.__scopeSlider,children:d.jsx(Ae.span,{role:"slider","aria-label":t["aria-label"]||m,"aria-valuemin":i.min,"aria-valuenow":p,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...o,ref:u,style:p===void 0?{display:"none"}:t.style,onFocus:se(t.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&d.jsx(ffe,{name:s??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:p},r)]})});wN.displayName=yw;var ffe=t=>{const{value:e,...n}=t,r=w.useRef(null),s=ife(e);return w.useEffect(()=>{const o=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(s!==e&&l){const c=new Event("input",{bubbles:!0});l.call(o,e),o.dispatchEvent(c)}},[s,e]),d.jsx("input",{style:{display:"none"},...n,ref:r,defaultValue:e})};function pfe(t=[],e,n){const r=[...t];return r[n]=e,r.sort((s,o)=>s-o)}function bN(t,e,n){const o=100/(n-e)*(t-e);return cN(o,[0,100])}function gfe(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}function mfe(t,e){if(t.length===1)return 0;const n=t.map(s=>Math.abs(s-e)),r=Math.min(...n);return n.indexOf(r)}function yfe(t,e,n){const r=t/2,o=V1([0,50],[0,r]);return(r-o(e)*n)*n}function Sfe(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}function vfe(t,e){if(e>0){const n=Sfe(t);return Math.min(...n)>=e}return!0}function V1(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 xfe(t){return(String(t).split(".")[1]||"").length}function wfe(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}var bfe=pN,Pfe=vN,Cfe=xN,_fe=wN;const Ife=w.memo(function({onHistoryMark:e,title:n,steps:r,value:s,label:o,onValueChange:i,["data-testid"]:a}){const l=Ee(),c=w.useCallback(f=>{i(f[0])},[i]),u=w.useCallback(()=>{e("click slider")},[e]),h=w.useCallback(()=>{s&&i(s)},[s,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(bfe,{"data-testid":a,className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:s?[s]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:h,title:n+" — "+l(o),children:[d.jsx(Pfe,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&d.jsx(Cfe,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&d.jsx(_fe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Efe({label:t,uiTypeA:e,uiTypeB:n,labelA:r,labelB:s,itemsA:o,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const f=Ee(),p=w.useMemo(()=>{var m;return((m=o.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:m.icon)??"mixed"},[o,c]),g=w.useMemo(()=>{var m;return((m=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:m.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:f(t),className:"tlui-style-panel__double-select-picker-label",children:f(t)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(ma,{id:`style panel ${e} A`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon","data-testid":`style.${e}`,title:f(r)+" — "+(c===null||c.type==="mixed"?f("style-panel.mixed"):f(`${e}-style.${c.value}`)),children:d.jsx(be,{icon:p,small:!0,invertIcon:!0})})}),d.jsx(Sa,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map((m,v)=>d.jsx(Xu,{"data-testid":`style.${e}.${m.value}`,children:d.jsx(ue,{type:"icon",onClick:()=>h(a,m.value),title:`${f(r)} — ${f(`${e}-style.${m.value}`)}`,children:d.jsx(be,{icon:m.icon,invertIcon:!0})},m.value)},v))})})]}),d.jsxs(ma,{id:`style panel ${n}`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}`,title:f(s)+" — "+(u===null||u.type==="mixed"?f("style-panel.mixed"):f(`${n}-style.${u.value}`)),children:d.jsx(be,{icon:g,small:!0})})}),d.jsx(Sa,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(Xu,{children:d.jsx(ue,{type:"icon",title:`${f(s)} — ${f(`${n}-style.${m.value}`)}`,"data-testid":`style.${n}.${m.value}`,onClick:()=>h(l,m.value),children:d.jsx(be,{icon:m.icon})})},m.value))})})]})]})]})}const kfe=w.memo(Efe);function Tfe({id:t,label:e,uiType:n,stylePanelType:r,style:s,items:o,type:i,value:a,onValueChange:l}){const c=Ee(),u=z(),h=w.useMemo(()=>{var m;return(m=o.find(v=>a.type==="shared"&&v.value===a.value))==null?void 0:m.icon},[o,a]),f=c(`style-panel.${r}`),p=a.type==="mixed"?c("style-panel.mixed"):f+" — "+c(`${n}-style.${a.value}`),g=e?c(e):"";return d.jsxs(ma,{id:`style panel ${t}`,children:[d.jsx(ya,{children:d.jsxs(ue,{type:i,"data-testid":`style.${n}`,title:p,children:[g&&d.jsx(bt,{children:g}),d.jsx(be,{icon:h??"mixed"})]})}),d.jsx(Sa,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map(m=>d.jsx(Xu,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}.${m.value}`,title:f+" — "+c(`${n}-style.${m.value}`),onClick:()=>{u.markHistoryStoppingPoint("select style dropdown item"),l(s,m.value)},children:d.jsx(be,{icon:m.icon})})},m.value))})})]})}const Y1=w.memo(Tfe);function Mfe({styles:t}){const e=vd();if(!t)return null;const n=t.get(Jr),r=t.get(kp),s=t.get(Ep),o=t.get(jp),i=t.get(Ls),a=n===void 0,l=r===void 0&&s===void 0,c=o===void 0,u=i===void 0,h=ko({isDarkMode:e});return d.jsxs(d.Fragment,{children:[d.jsx(Afe,{theme:h,styles:t}),!u&&d.jsx(jfe,{theme:h,styles:t}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(Ofe,{styles:t}),d.jsx(Rfe,{styles:t}),d.jsx(Dfe,{styles:t})]})]})}function kd(){const t=z(),e=Jt();return ke.useMemo(()=>function(r,s){t.run(()=>{t.isIn("select")&&t.setStyleForSelectedShapes(r,s),t.setStyleForNextShapes(r,s),t.updateInstanceState({isChangingStyle:!0})}),e("set-style",{source:"style-panel",id:r.id,value:s})},[t,e])}function Afe({styles:t,theme:e}){const n=Ee(),r=z(),s=w.useCallback(h=>r.markHistoryStoppingPoint(h),[r]),o=kd(),i=t.get(mr),a=t.get(da),l=t.get(ua),c=t.get($s),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(Xi,{title:n("style-panel.color"),uiType:"color",style:mr,items:jr.color,value:i,onValueChange:o,theme:e,onHistoryMark:s}),d.jsx(Lfe,{})]}),u&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:d.jsx(Xi,{title:n("style-panel.fill"),uiType:"fill",style:da,items:jr.fill,value:a,onValueChange:o,theme:e,onHistoryMark:s}),l===void 0?null:d.jsx(Xi,{title:n("style-panel.dash"),uiType:"dash",style:ua,items:jr.dash,value:l,onValueChange:o,theme:e,onHistoryMark:s}),c===void 0?null:d.jsx(Xi,{title:n("style-panel.size"),uiType:"size",style:$s,items:jr.size,value:c,onValueChange:(h,f)=>{o(h,f);const p=r.getSelectedShapeIds();p.length>0&&Xe(r,p)},theme:e,onHistoryMark:s})]})]})}function jfe({theme:t,styles:e}){const n=Ee(),r=kd(),s=z(),o=w.useCallback(u=>s.markHistoryStoppingPoint(u),[s]),i=e.get(Ls),a=e.get(yx),l=e.get(Mp),c=e.get(Ap);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(Xi,{title:n("style-panel.font"),uiType:"font",style:Ls,items:jr.font,value:i,onValueChange:r,theme:t,onHistoryMark:o}),a===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Xi,{title:n("style-panel.align"),uiType:"align",style:yx,items:jr.textAlign,value:a,onValueChange:r,theme:t,onHistoryMark:o}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})})})]}),l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Xi,{title:n("style-panel.label-align"),uiType:"align",style:Mp,items:jr.horizontalAlign,value:l,onValueChange:r,theme:t,onHistoryMark:o}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})}):d.jsx(Y1,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:Ap,items:jr.verticalAlign,value:c,onValueChange:r})})]})]})}function Ofe({styles:t}){const e=kd(),n=t.get(Jr);return n===void 0?null:d.jsx(Y1,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:Jr,items:jr.geo,value:n,onValueChange:e})}function Dfe({styles:t}){const e=kd(),n=t.get(jp);return n===void 0?null:d.jsx(Y1,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:jp,items:jr.spline,value:n,onValueChange:e})}function Rfe({styles:t}){const e=kd(),n=t.get(kp),r=t.get(Ep);return!n||!r?null:d.jsx(kfe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Ep,itemsA:jr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:kp,itemsB:jr.arrowheadEnd,valueB:n,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Lc=[.1,.25,.5,.75,1];function Lfe(){const t=z(),e=w.useCallback(a=>t.markHistoryStoppingPoint(a),[t]),n=U("opacity",()=>t.getSharedOpacity(),[t]),r=Jt(),s=Ee(),o=ke.useCallback(a=>{const l=Lc[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:Lc.indexOf(k9(Lc,a=>Math.abs(a-n.value)));return d.jsx(Ife,{"data-testid":"style.opacity",value:i>=0?i:Lc.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:Lc.length-1,title:s("style-panel.opacity"),onHistoryMark:e})}const $fe=w.memo(function({isMobile:e,children:n}){const r=z(),s=w.useRef(null);Ai(s);const o=lN(),i=w.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=n??d.jsx(Mfe,{styles:o});return d.jsx("div",{ref:s,className:ce("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:i,children:a})});function Ffe(){const t=z(),e=Ee(),n=lN(),r=n==null?void 0:n.get(mr),s=ko({isDarkMode:t.user.getIsDarkMode()}),o=((r==null?void 0:r.type)==="shared"?s[r.value]:s.black).solid,i=U("disable style panel",()=>t.isInAny("hand","zoom","eraser","laser"),[t]),a=w.useCallback(c=>{c||t.updateInstanceState({isChangingStyle:!1})},[t]),{StylePanel:l}=Ri();return l?d.jsxs(H1,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(K1,{children:d.jsx(ue,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":o},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(W1,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function Nfe(){return d.jsxs(d.Fragment,{children:[d.jsx(Bfe,{}),d.jsx(Ufe,{}),d.jsx(Hfe,{}),d.jsx(Kfe,{}),d.jsx(Wfe,{}),d.jsx(Gfe,{}),d.jsx(Vfe,{}),d.jsx(Yfe,{}),d.jsx(Xfe,{}),d.jsx(qfe,{}),d.jsx(Qfe,{}),d.jsx(Zfe,{}),d.jsx(tpe,{}),d.jsx(spe,{}),d.jsx(Jfe,{}),d.jsx(rpe,{}),d.jsx(npe,{}),d.jsx(epe,{}),d.jsx(ope,{}),d.jsx(ipe,{}),d.jsx(ape,{}),d.jsx(lpe,{}),d.jsx(cpe,{}),d.jsx(upe,{}),d.jsx(dpe,{}),d.jsx(hpe,{}),d.jsx(ppe,{}),d.jsx(fpe,{})]})}function zfe(t){var r;const e=z(),n=(r=t.meta)==null?void 0:r.geo;return U("is tool selected",()=>{const s=e.getCurrentToolId(),o=e.getSharedStyles().getAsKnownValue(Jr);return n?s==="geo"&&o===n:s===t.id},[e,t.id,n])}function Ve({tool:t}){const e=P1(),n=zfe(e[t]);return d.jsx(Ln,{toolId:t,isSelected:n})}function Bfe(){return d.jsx(Ve,{tool:"select"})}function Ufe(){return d.jsx(Ve,{tool:"hand"})}function Hfe(){return d.jsx(Ve,{tool:"draw"})}function Kfe(){return d.jsx(Ve,{tool:"eraser"})}function Wfe(){return d.jsx(Ve,{tool:"arrow"})}function Gfe(){return d.jsx(Ve,{tool:"text"})}function Vfe(){return d.jsx(Ve,{tool:"note"})}function Yfe(){return d.jsx(Ln,{toolId:"asset"})}function Xfe(){return d.jsx(Ve,{tool:"rectangle"})}function qfe(){return d.jsx(Ve,{tool:"ellipse"})}function Zfe(){return d.jsx(Ve,{tool:"diamond"})}function Qfe(){return d.jsx(Ve,{tool:"triangle"})}function Jfe(){return d.jsx(Ve,{tool:"rhombus"})}function epe(){return d.jsx(Ve,{tool:"heart"})}function tpe(){return d.jsx(Ve,{tool:"hexagon"})}function npe(){return d.jsx(Ve,{tool:"cloud"})}function rpe(){return d.jsx(Ve,{tool:"star"})}function spe(){return d.jsx(Ve,{tool:"oval"})}function ope(){return d.jsx(Ve,{tool:"x-box"})}function ipe(){return d.jsx(Ve,{tool:"check-box"})}function ape(){return d.jsx(Ve,{tool:"arrow-left"})}function lpe(){return d.jsx(Ve,{tool:"arrow-up"})}function cpe(){return d.jsx(Ve,{tool:"arrow-down"})}function upe(){return d.jsx(Ve,{tool:"arrow-right"})}function dpe(){return d.jsx(Ve,{tool:"line"})}function hpe(){return d.jsx(Ve,{tool:"highlight"})}function fpe(){return d.jsx(Ve,{tool:"frame"})}function ppe(){return d.jsx(Ve,{tool:"laser"})}const ES=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function kS(t,e,n,r){t.addEventListener?t.addEventListener(e,n,r):t.attachEvent&&t.attachEvent("on".concat(e),n)}function $c(t,e,n,r){t.removeEventListener?t.removeEventListener(e,n,r):t.detachEvent&&t.detachEvent("on".concat(e),n)}function PN(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 CN(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 gpe(t,e){const n=t.length>=e.length?t:e,r=t.length>=e.length?e:t;let s=!0;for(let o=0;o<n.length;o++)r.indexOf(n[o])===-1&&(s=!1);return s}const qu={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,"-":ES?173:189,"=":ES?61:187,";":ES?59:186,"'":222,"[":219,"]":221,"\\":220},Us={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Ff={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},ft={};for(let t=1;t<20;t++)qu["f".concat(t)]=111+t;let it=[],gu=null,_N="all";const ro=new Map,Td=t=>qu[t.toLowerCase()]||Us[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),mpe=t=>Object.keys(qu).find(e=>qu[e]===t),ype=t=>Object.keys(Us).find(e=>Us[e]===t);function IN(t){_N=t||"all"}function Zu(){return _N||"all"}function Spe(){return it.slice(0)}function vpe(){return it.map(t=>mpe(t)||ype(t)||String.fromCharCode(t))}function xpe(){const t=[];return Object.keys(ft).forEach(e=>{ft[e].forEach(n=>{let{key:r,scope:s,mods:o,shortcut:i}=n;t.push({scope:s,shortcut:i,mods:o,keys:r.split("+").map(a=>Td(a))})})}),t}function wpe(t){const e=t.target||t.srcElement,{tagName:n}=e;let r=!0;const s=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return(e.isContentEditable||(s||n==="TEXTAREA"||n==="SELECT")&&!e.readOnly)&&(r=!1),r}function bpe(t){return typeof t=="string"&&(t=Td(t)),it.indexOf(t)!==-1}function Ppe(t,e){let n,r;t||(t=Zu());for(const s in ft)if(Object.prototype.hasOwnProperty.call(ft,s))for(n=ft[s],r=0;r<n.length;)n[r].scope===t?n.splice(r,1).forEach(i=>{let{element:a}=i;return X1(a)}):r++;Zu()===t&&IN(e||"all")}function Cpe(t){let e=t.keyCode||t.which||t.charCode;const n=it.indexOf(e);if(n>=0&&it.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&it.splice(0,it.length),(e===93||e===224)&&(e=91),e in Ut){Ut[e]=!1;for(const r in Us)Us[r]===e&&(Wn[r]=!1)}}function EN(t){if(typeof t>"u")Object.keys(ft).forEach(s=>{Array.isArray(ft[s])&&ft[s].forEach(o=>Bh(o)),delete ft[s]}),X1(null);else if(Array.isArray(t))t.forEach(s=>{s.key&&Bh(s)});else if(typeof t=="object")t.key&&Bh(t);else if(typeof t=="string"){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];let[s,o]=n;typeof s=="function"&&(o=s,s=""),Bh({key:t,scope:s,method:o,splitKey:"+"})}}const Bh=t=>{let{key:e,scope:n,method:r,splitKey:s="+"}=t;CN(e).forEach(i=>{const a=i.split(s),l=a.length,c=a[l-1],u=c==="*"?"*":Td(c);if(!ft[u])return;n||(n=Zu());const h=l>1?PN(Us,a):[],f=[];ft[u]=ft[u].filter(p=>{const m=(r?p.method===r:!0)&&p.scope===n&&gpe(p.mods,h);return m&&f.push(p.element),!m}),f.forEach(p=>X1(p))})};function i2(t,e,n,r){if(e.element!==r)return;let s;if(e.scope===n||e.scope==="all"){s=e.mods.length>0;for(const o in Ut)Object.prototype.hasOwnProperty.call(Ut,o)&&(!Ut[o]&&e.mods.indexOf(+o)>-1||Ut[o]&&e.mods.indexOf(+o)===-1)&&(s=!1);(e.mods.length===0&&!Ut[16]&&!Ut[18]&&!Ut[17]&&!Ut[91]||s||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(it),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function a2(t,e){const n=ft["*"];let r=t.keyCode||t.which||t.charCode;if(!Wn.filter.call(this,t))return;if((r===93||r===224)&&(r=91),it.indexOf(r)===-1&&r!==229&&it.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=Ff[a];t[a]&&it.indexOf(l)===-1?it.push(l):!t[a]&&it.indexOf(l)>-1?it.splice(it.indexOf(l),1):a==="metaKey"&&t[a]&&(it=it.filter(c=>c in Ff||c===r))}),r in Ut){Ut[r]=!0;for(const a in Us)Us[a]===r&&(Wn[a]=!0);if(!n)return}for(const a in Ut)Object.prototype.hasOwnProperty.call(Ut,a)&&(Ut[a]=t[Ff[a]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(it.indexOf(17)===-1&&it.push(17),it.indexOf(18)===-1&&it.push(18),Ut[17]=!0,Ut[18]=!0);const s=Zu();if(n)for(let a=0;a<n.length;a++)n[a].scope===s&&(t.type==="keydown"&&n[a].keydown||t.type==="keyup"&&n[a].keyup)&&i2(t,n[a],s,e);if(!(r in ft))return;const o=ft[r],i=o.length;for(let a=0;a<i;a++)if((t.type==="keydown"&&o[a].keydown||t.type==="keyup"&&o[a].keyup)&&o[a].key){const l=o[a],{splitKey:c}=l,u=l.key.split(c),h=[];for(let f=0;f<u.length;f++)h.push(Td(u[f]));h.sort().join("")===it.sort().join("")&&i2(t,l,s,e)}}function Wn(t,e,n){it=[];const r=CN(t);let s=[],o="all",i=document,a=0,l=!1,c=!0,u="+",h=!1,f=!1;for(n===void 0&&typeof e=="function"&&(n=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(o=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&&(f=!0)),typeof e=="string"&&(o=e),f&&EN(t,o);a<r.length;a++)t=r[a].split(u),s=[],t.length>1&&(s=PN(Us,t)),t=t[t.length-1],t=t==="*"?"*":Td(t),t in ft||(ft[t]=[]),ft[t].push({keyup:l,keydown:c,scope:o,mods:s,shortcut:r[a],method:n,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!ro.has(i)){const p=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return a2(m,i)},g=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;a2(m,i),Cpe(m)};ro.set(i,{keydownListener:p,keyupListenr:g,capture:h}),kS(i,"keydown",p,h),kS(i,"keyup",g,h)}if(!gu){const p=()=>{it=[]};gu={listener:p,capture:h},kS(window,"focus",p,h)}}}function _pe(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ft).forEach(n=>{ft[n].filter(s=>s.scope===e&&s.shortcut===t).forEach(s=>{s&&s.method&&s.method()})})}function X1(t){const e=Object.values(ft).flat();if(e.findIndex(r=>{let{element:s}=r;return s===t})<0){const{keydownListener:r,keyupListenr:s,capture:o}=ro.get(t)||{};r&&s&&($c(t,"keyup",s,o),$c(t,"keydown",r,o),ro.delete(t))}if((e.length<=0||ro.size<=0)&&(Object.keys(ro).forEach(s=>{const{keydownListener:o,keyupListenr:i,capture:a}=ro.get(s)||{};o&&i&&($c(s,"keyup",i,a),$c(s,"keydown",o,a),ro.delete(s))}),ro.clear(),Object.keys(ft).forEach(s=>delete ft[s]),gu)){const{listener:s,capture:o}=gu;$c(window,"focus",s,o),gu=null}}const TS={getPressedKeyString:vpe,setScope:IN,getScope:Zu,deleteScope:Ppe,getPressedKeyCodes:Spe,getAllKeyCodes:xpe,isPressed:bpe,filter:wpe,trigger:_pe,unbind:EN,keyMap:qu,modifier:Us,modifierMap:Ff};for(const t in TS)Object.prototype.hasOwnProperty.call(TS,t)&&(Wn[t]=TS[t]);if(typeof window<"u"){const t=window.hotkeys;Wn.noConflict=e=>(e&&window.hotkeys===Wn&&(window.hotkeys=t),Wn),window.hotkeys=Wn}const l2=["copy","cut","paste","asset"];function Ipe(){const t=z(),e=wr(),n=Ea(),r=P1(),s=U("is focused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!s)return;const o=new Array,i=(l,c)=>{Wn(l,{element:document.body},c),o.push(()=>{Wn.unbind(l,c)})},a=(l,c)=>{Wn(l,{element:document.body,keyup:!0,keydown:!1},c),o.push(()=>{Wn.unbind(l,c)})};for(const l of Object.values(n))l.kbd&&(e&&!l.readonlyOk||l2.includes(l.id)||i(c2(l.kbd),c=>{Zc(t)||(xe(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&t.getIsReadonly()||l2.includes(l.id)||i(c2(l.kbd),c=>{Zc(t)||(xe(c),l.onSelect("kbd"))});return i(",",l=>{if(Zc(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,f=t.pageToScreen({x:c,y:u}),p={type:"pointer",name:"pointer_down",point:{x:f.x,y:f.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(p)}),a(",",l=>{if(Zc(t)||!t.inputs.keys.has("Comma"))return;t.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=t.inputs.currentScreenPoint,f={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(f)}),()=>{o.forEach(l=>l())}},[n,r,e,t,s])}function c2(t){return Epe(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 Epe(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 Zc(t){return t.menus.hasAnyOpenMenus()||t.getEditingShapeId()!==null||t.getCrashingError()}const kpe=w.createContext(!1);function Tpe({children:t}){const e=z(),n=Jl(),r=An(),s=Ee(),o=Math.min(8,5+r),[i,a]=w.useState(0),l=w.useRef(null),[c,u]=w.useState(null),h=w.useMemo(()=>{const p=c?`:not([data-value="${c}"])`:"";return`
|
|
412
|
+
#${n}_main > *:nth-child(n + ${o+(c?1:2)})${p} {
|
|
413
|
+
display: none;
|
|
414
|
+
}
|
|
415
|
+
#${n}_more > *:nth-child(-n + ${o}) {
|
|
416
|
+
display: none;
|
|
417
|
+
}
|
|
418
|
+
`},[c,n,o]),f=Bg(()=>{if(!l.current)return;const p=Array.from(l.current.children);a(p.length),p.findIndex(v=>v.getAttribute("data-value")===c)<=o&&u(null);const m=Array.from(l.current.children).findIndex(v=>v.getAttribute("aria-checked")==="true");m!==-1&&m>=o&&u(p[m].getAttribute("data-value"))});return w.useLayoutEffect(()=>{f()}),w.useLayoutEffect(()=>{if(!l.current)return;const p=new MutationObserver(f);return p.observe(l.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{p.disconnect()}},[f]),w.useEffect(()=>{const p=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[g,m]of p)Wn(g,v=>{var b;if(Zc(e))return;xe(v);const S=Array.from(((b=l.current)==null?void 0:b.children)??[]).filter(P=>!(P instanceof HTMLElement)||P.tagName.toLowerCase()!=="button"?!1:!!(P.offsetWidth||P.offsetHeight))[m];S&&S.click()});return()=>{Wn.unbind("1,2,3,4,5,6,7,8,9,0")}},[e]),d.jsxs(d.Fragment,{children:[d.jsx("style",{children:h}),d.jsxs("div",{className:ce("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<St.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${n}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(Fr,{type:"toolbar",sourceId:"toolbar",children:t})}),i>o+1&&d.jsx(kpe.Provider,{value:!0,children:d.jsxs(ma,{id:"toolbar overflow",modal:!1,children:[d.jsx(ya,{children:d.jsx(ue,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:d.jsx(be,{icon:"chevron-up"})})}),d.jsx(Sa,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx(Fr,{type:"toolbar-overflow",sourceId:"toolbar",children:t})})})]})})]})]})}function Mpe({activeToolId:t}){const e=z(),n=An(),r=Ee(),s=U("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),o=U("current tool",()=>e.getCurrentTool(),[e]);return!t||!o.isLockable?null:d.jsx(ue,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ce("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<St.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!s}),children:d.jsx(be,{icon:s?"lock":"unlock",small:!0})})}const Ape=w.memo(function({children:e}){const n=z(),r=An(),s=wr(),o=U("current tool id",()=>n.getCurrentToolId(),[n]),i=w.useRef(null);Ai(i);const{ActionsMenu:a,QuickActions:l}=Ri(),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:[!s&&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(Mpe,{activeToolId:o})]}),d.jsx(Tpe,{children:e??d.jsx(Nfe,{})})]}),r<St.TABLET_SM&&!s&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(Ffe,{})})]})})});function jpe(){const t=Ee();return d.jsxs("div",{className:ce("tlui-offline-indicator"),children:[t("status.offline"),d.jsx(zs,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function Ope({maxWidth:t=420,ignoreRightWidth:e=0,stylePanelWidth:n=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:o}){const i=w.useRef(null),a=An(),l=w.useCallback(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),f=u.querySelector(".tlui-layout__top__right"),p=u.offsetWidth,g=h.offsetWidth,m=f.offsetWidth,v=c.offsetWidth-e;let y=(p-v)/2;p%2!==0&&(y-=.5);const S=g+r,b=c.offsetLeft,P=Math.min(p-m-g-2*r,t),C=Math.max(y,S)-b;f.offsetWidth>n&&a<=6?c.style.setProperty("max-width",P-s+"px"):c.style.setProperty("max-width",P+"px"),c.style.setProperty("transform",`translate(${C}px, 0px)`)},[a,e,r,t,s,n]);return w.useLayoutEffect(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),f=u.querySelector(".tlui-layout__top__right"),p=new ResizeObserver(l);return p.observe(h),p.observe(f),p.observe(u),p.observe(c),l(),()=>{p.disconnect()}},[l]),w.useLayoutEffect(()=>{l()}),d.jsx("div",{ref:i,className:"tlui-top-panel__container",children:o})}function Dpe(){const t=Zoe()==="offline";return d.jsx(Ope,{children:t&&d.jsx(jpe,{})})}function Rpe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"zoom-in",noClose:!0}),d.jsx(W,{actionId:"zoom-out",noClose:!0}),d.jsx(DF,{}),d.jsx(RF,{}),d.jsx(LF,{})]})}const Lpe=w.memo(function({children:e}){const n=Tt(),[r,s]=Mo("zoom menu"),o=e??d.jsx(Rpe,{});return d.jsxs(i1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(a1,{asChild:!0,dir:"ltr",children:d.jsx($pe,{})}),d.jsx(lm,{container:n,children:d.jsx(l1,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(Fr,{type:"menu",sourceId:"zoom-menu",children:o})})})]})}),$pe=w.forwardRef(function(e,n){const r=z(),s=An(),o=U("zoom",()=>r.getZoomLevel(),[r]),i=Ee(),a=w.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.jsx(ue,{ref:n,...e,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:s<St.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:s<St.MOBILE?null:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(o*100),"%"]})})}),kN=w.createContext(null);function Fpe({overrides:t={},children:e}){const n=tc(t),r=fm();return d.jsx(kN.Provider,{value:w.useMemo(()=>({ContextMenu:Jde,ActionsMenu:Ede,HelpMenu:null,ZoomMenu:Lpe,MainMenu:Ohe,Minimap:Hhe,StylePanel:$fe,PageMenu:Vhe,NavigationPanel:Whe,Toolbar:Ape,KeyboardShortcutsDialog:bhe,QuickActions:Zhe,HelperButtons:xhe,DebugPanel:dhe,DebugMenu:uhe,MenuPanel:ghe,SharePanel:r?sfe:null,CursorChatBubble:r?nhe:null,TopPanel:r?Dpe:null,...n}),[n,r]),children:e})}function Ri(){const t=w.useContext(kN);if(!t)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return t}const Npe=Zt(function({overrides:e,components:n,assetUrls:r,onUiEvent:s,forceMobile:o,mediaMimeTypes:i,children:a}){const l=Ti();return d.jsx(F$.Provider,{value:i,children:d.jsx(Coe,{assetUrls:tde(r),children:d.jsx(Eoe,{overrides:Iae(e),locale:(l==null?void 0:l.user.getLocale())??vs.locale,children:d.jsx(mte,{onEvent:s,children:d.jsx(bie,{children:d.jsx(Joe,{context:l==null?void 0:l.contextId,children:d.jsx(Qoe,{forceMobile:o,children:d.jsx(Fpe,{overrides:n,children:l?d.jsx(zpe,{overrides:e,children:a}):a})})})})})})})})});function zpe({overrides:t,children:e}){const n=Eae(t);return d.jsx(Tae,{overrides:n.actions,children:d.jsx(Wae,{overrides:n.tools,children:e})})}function Bpe(){const t=z(),{addToast:e}=To();w.useEffect(()=>{function n({name:r,count:s}){e({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${s}). 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 Upe=ke.memo(function({renderDebugMenuItems:e,children:n,hideUi:r,components:s,...o}){return d.jsx(Npe,{...o,components:s,children:d.jsx(Hpe,{hideUi:r,renderDebugMenuItems:e,children:n})})}),Hpe=ke.memo(function({children:e,hideUi:n,...r}){return d.jsxs(d.Fragment,{children:[e,n?null:d.jsx(Kpe,{...r})]})}),Kpe=ke.memo(function(){const e=z(),n=Ee(),r=An(),s=wr(),o=U("focus",()=>e.getInstanceState().isFocusMode,[e]),i=U("debug",()=>e.getInstanceState().isDebugMode,[e]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:h,HelpMenu:f,NavigationPanel:p,HelperButtons:g,DebugPanel:m,CursorChatBubble:v}=Ri();Ipe(),Qie(),Bpe();const{"toggle-focus-mode":y}=Ea();return d.jsxs("div",{className:ce("tlui-layout",{"tlui-layout__mobile":r<St.TABLET_SM}),"data-breakpoint":r,children:[o?d.jsx("div",{className:"tlui-layout__top",children:d.jsx(ue,{type:"icon",className:"tlui-focus-button",title:n("focus-mode.toggle-focus-mode"),onClick:()=>y.onSelect("menu"),children:d.jsx(be,{icon:"dot"})})}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"tlui-layout__top",children:[d.jsxs("div",{className:"tlui-layout__top__left",children:[c&&d.jsx(c,{}),g&&d.jsx(g,{})]}),d.jsx("div",{className:"tlui-layout__top__center",children:l&&d.jsx(l,{})}),d.jsxs("div",{className:"tlui-layout__top__right",children:[a&&d.jsx(a,{}),u&&r>=St.TABLET_SM&&!s&&d.jsx(u,{})]})]}),d.jsxs("div",{className:"tlui-layout__bottom",children:[d.jsxs("div",{className:"tlui-layout__bottom__main",children:[p&&d.jsx(p,{}),h&&d.jsx(h,{}),f&&d.jsx(f,{})]}),i&&m&&d.jsx(m,{})]})]}),d.jsx(Kae,{}),d.jsx(zae,{}),d.jsx(Que,{}),v&&d.jsx(v,{})]})});async function Wpe(t,e){const{url:n,style:r="normal",weight:s="500",display:o,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=e,h={style:r,weight:s,display:o,featureSettings:i,stretch:a,unicodeRange:l,variant:c},f=new FontFace(t,`url(${n})`,h);return await f.load(),document.fonts.add(f),f.$$_url=n,f.$$_fontface=`
|
|
419
|
+
@font-face {
|
|
420
|
+
font-family: ${f.family};
|
|
421
|
+
font-stretch: ${f.stretch};
|
|
422
|
+
font-weight: ${f.weight};
|
|
423
|
+
font-style: ${f.style};
|
|
424
|
+
src: url("${n}") format("${u}")
|
|
425
|
+
}`,f}const Uh=(t,e)=>{const[n,r]=w.useState(2);return w.useEffect(()=>{let s=!1;return r(2),Wpe(t,e).then(()=>{s||r(0)}).catch(o=>{s||(console.error(o),r(1))}),()=>{s=!0}},[t,e]),n};function Gpe(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 TN(t){const e=w.useMemo(()=>Gpe(t),[t]),n=[Uh("tldraw_draw",e.draw),Uh("tldraw_serif",e.serif),Uh("tldraw_sans",e.sansSerif),Uh("tldraw_mono",e.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function Vpe(t){const{children:e,maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:s,acceptedVideoMimeTypes:o,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:u=[],embeds:h,...f}=t,p=tc(a),g=w.useMemo(()=>({Scribble:vE,ShapeIndicators:nle,CollaboratorScribble:vE,SelectionForeground:Jae,SelectionBackground:Zae,Handles:Gae,...p}),[p]),m=qo(l),v=w.useMemo(()=>[...C5,...m],[m]),y=qo(c),S=w.useMemo(()=>[...G$,...y],[y]),b=qo(u),P=w.useMemo(()=>[...Zue,...zle,...b],[b]),C=qo(s??Sg),_=qo(o??v0),E=w.useMemo(()=>[...C,..._],[C,_]),k=lF(f.assetUrls),{done:D,error:T}=TN(k);return T?d.jsx(GR,{children:"Could not load assets. Please refresh the page."}):D?(v.find(L=>L.type==="embed")&&h&&Zp.setEmbedDefinitions(h),d.jsx(tte,{initialState:"select",...f,components:g,shapeUtils:v,bindingUtils:S,tools:P,children:d.jsxs(Upe,{...f,components:g,mediaMimeTypes:E,children:[d.jsx(Ype,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:C,acceptedVideoMimeTypes:_,onMount:i}),e]})})):d.jsx(Ab,{children:d.jsx(mb,{})})}function Ype({maxImageDimension:t=5e3,maxAssetSize:e=10*1024*1024,acceptedImageMimeTypes:n=Sg,acceptedVideoMimeTypes:r=v0,onMount:s}){const o=z(),i=To(),a=Ee();VR(()=>{const u=[];return u.push(wue(o)),vle(o,{maxImageDimension:t,maxAssetSize:e,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),u.push(o.store.props.onMount(o)),u.push(s==null?void 0:s(o)),()=>{u.forEach(h=>h==null?void 0:h())}});const{Canvas:l}=st(),{ContextMenu:c}=Ri();return c?d.jsx(c,{}):l?d.jsx(l,{}):null}w.memo(function(e){const[n,r]=w.useState(null),[s,o]=w.useState(null),i=qo(e.shapeUtils??[]),a=w.useMemo(()=>[...C5,...i],[i]),l=qo(e.bindingUtils??[]),c=w.useMemo(()=>[...G$,...l],[l]),u=lte({snapshot:e.snapshot,shapeUtils:a}),h=lF(e.assetUrls),{done:f,error:p}=TN(h),{pageId:g,bounds:m,scale:v,pixelRatio:y,background:S,padding:b,darkMode:P,preserveAspectRatio:C,format:_="svg",licenseKey:E}=e;return w.useLayoutEffect(()=>{if(!s||!u||!f)return;let k=!1;const D=document.createElement("div");s.appendChild(D),s.classList.add("tl-container","tl-theme__light");const T=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>D,licenseKey:E});g&&T.setCurrentPage(g);const j=T.getCurrentPageShapeIds();async function L(){const M=await T.getSvgString([...j],{bounds:m,scale:v,background:S,padding:b,darkMode:P,preserveAspectRatio:C});if(M&&!k){if(_==="svg"){if(!k){const O=new Blob([M.svg],{type:"image/svg+xml"}),F=URL.createObjectURL(O);r(F)}}else if(_==="png"){const O=await R$(T,M.svg,{type:_,width:M.width,height:M.height,pixelRatio:y});if(O&&!k){const F=URL.createObjectURL(O);r(F)}}}T.dispose()}return L(),()=>{k=!0}},[_,s,u,a,c,g,m,v,S,b,P,C,f,p,E,y]),p?d.jsx(GR,{children:"Could not load assets."}):f?d.jsx("div",{ref:o,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(Ab,{children:d.jsx(mb,{})})});w.memo(function({children:e}){const n=Ee(),r=An(),s=w.useRef(null);Ai(s);const o=e??d.jsx(Phe,{});return r<St.MOBILE?null:d.jsx("div",{ref:s,className:"tlui-help-menu",children:d.jsxs(ma,{id:"help menu",children:[d.jsx(ya,{children:d.jsx(ue,{type:"help",title:n("help-menu.title"),"data-testid":"help-menu.button",children:d.jsx(be,{icon:"question-mark",small:!0})})}),d.jsx(Sa,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(Fr,{type:"menu",sourceId:"help-menu",children:o})})]})})});const Xpe=1,qpe=Pe({schemaVersion:mn(1),storeVersion:af,recordVersions:_p(ye,Pe({version:af,subTypeVersions:_p(ye,af).optional(),subTypeKey:ye.optional()}))}),Zpe=Pe({schemaVersion:mn(2),sequences:_p(ye,af)}),Qpe=Pe({tldrawFileFormatVersion:eY,schema:tY("schemaVersion",{1:qpe,2:Zpe}),records:Wt(Pe({id:ye,typeName:ye}).allowUnknownProperties())});function Jpe(t){var e;try{return!!((e=t.document)!=null&&e.version)}catch{return!1}}function ege({json:t,schema:e}){let n;try{n=Qpe.validate(JSON.parse(t))}catch(o){try{if(n=JSON.parse(t),Jpe(n))return wn.err({type:"v1File",data:n})}catch{}return wn.err({type:"notATldrawFile",cause:o})}if(n.tldrawFileFormatVersion>Xpe)return wn.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r,s;try{const o=tge(n.records);s=Object.fromEntries(o.map(i=>[i.id,i])),r=e.migrateStoreSnapshot({store:s,schema:n.schema})}catch(o){return wn.err({type:"invalidRecords",cause:o})}if(r.type==="error")return wn.err({type:"migrationFailed",reason:r.reason});try{return wn.ok(Uu({snapshot:{store:s,schema:n.schema},schema:e}))}catch(o){return wn.err({type:"invalidRecords",cause:o})}}function tge(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))}_i("tldraw","3.7.2","esm");function nge(){const[t,e]=w.useState();function n(r){window.editor=r,t===void 0?fetch("/tldr-data").then(async s=>{if(!s.ok){console.log(`No tldr data to load from local endpoint (${s.status})`);return}return s.text()}).then(s=>{if(s===void 0)return;const o=ege({json:s,schema:r.store.schema});o.ok?(console.log("Loaded tldr file from local endpoint"),e(o.value)):console.error(`Couldn't parse tldr file: ${String(o.error.type)}`)}).catch(s=>{console.error("Couldn't fetch data:",s)}):(r.zoomToFit(),r.clearOpenMenus())}return d.jsx("div",{style:{inset:0,position:"fixed"},children:d.jsx(Vpe,{assetUrls:u8(),onMount:n,store:t})})}qS.createRoot(document.querySelector("#root")).render(d.jsx(ke.StrictMode,{children:d.jsx(nge,{})}));
|